An array B is called good if it satisfies the following condition.
• All elements of B are distinct
• The size of the array B is N.
You are allowed to perform the following operations on elements of B.
• In one operation you can select any index i of B and replace B[i] with either 2B[i] or 2B[i]+1.
It must be possible that after some operations on B, it becomes an anagram of set A. Let K denote the maximum value present in such a good array B. Find the minimum possible value of K for the given set A.
Notes:
• Elements in B are not required to be distinct after each operation.
• An array B is said to be an anagram of A, if A can be obtained by rearranging the elements of B.
Input Format
The first line contains an integer, N, denoting the number of elements in A.
Each line i of the N subsequent lines (where 0 ≤ i < N) contains an integer describing A[i].
Constraints
1<=N<=10^5
1<=A[i]<= 10^9
Sample Test Cases
Case 1
Input:1 3
Output:1
Explanation:
N= 1
A = [3]
Let B=[1], now after operation of type 2B[0]+1, we get 21+1=3 => B becomes , B = [3]
Hence, We can form anagram of A from B using the given operations.
Hence, minimum possible value of K is 1.
Case 2
Input:
3
1
2
3
Output:
3
Explanation:
N = 3
A = [1, 2, 3]
Let B=[1,2,3] no operation is required it is already equal to A.
Note that no maximum value less than 3 is possible here.
An array B is called good if it satisfies the following condition. • All elements of B are distinct • The size of the array B is N.
You are allowed to perform the following operations on elements of B. • In one operation you can select any index i of B and replace B[i] with either 2B[i] or 2B[i]+1. It must be possible that after some operations on B, it becomes an anagram of set A. Let K denote the maximum value present in such a good array B. Find the minimum possible value of K for the given set A. Notes: • Elements in B are not required to be distinct after each operation. • An array B is said to be an anagram of A, if A can be obtained by rearranging the elements of B.
Input Format The first line contains an integer, N, denoting the number of elements in A. Each line i of the N subsequent lines (where 0 ≤ i < N) contains an integer describing A[i]. Constraints 1<=N<=10^5 1<=A[i]<= 10^9
Sample Test Cases Case 1 Input:1 3 Output:1
Explanation: N= 1 A = [3] Let B=[1], now after operation of type 2B[0]+1, we get 21+1=3 => B becomes , B = [3] Hence, We can form anagram of A from B using the given operations. Hence, minimum possible value of K is 1.
Case 2 Input: 3 1 2 3 Output: 3 Explanation: N = 3 A = [1, 2, 3] Let B=[1,2,3] no operation is required it is already equal to A. Note that no maximum value less than 3 is possible here.