The Runic Stone Arrangement
An archaeologist discovered ancient runic stones, each with a magical frequency value. The stones must be arranged in a row such that no two adjacent stones have the same frequency.
Given an array of stone frequencies, find the length of the longest arrangement where no two adjacent stones share the same frequency. You can pick any subset of stones and arrange them in any order.
Note: You cannot use a stone more than once.
Input Format
The first line contains an integer n, the number of stones. The second line contains n space-separated integers representing the frequency of each stone.
Output Format
Print a single integer representing the maximum length of a valid arrangement.
Examples
Example 1
Example 2
Constraints
•
1 ≤ n ≤ 100000
•
1 ≤ frequency[i] ≤ 10^9
Code
Case 1
Case 2
