Longest increasing subsequence with a bit rule

Find the length of the longest strictly increasing subsequence of A in which every two neighbouring chosen values x and y satisfy (x AND y) × 2 < (x OR y), where AND and OR are bitwise.

Reported in: Infosys (SP / DSE · earlier papers) (memory-based)

Input

First line: N. Second line: N integers.

Output

The length of the longest such subsequence.

Constraints

1 ≤ N ≤ 2000; 0 ≤ A[i] ≤ 10^9.

Example 1

Input:
5
15 6 5 12 1

Output:
2

Example 2

Input:
4
1 2 3 4

Output:
3

Example 3

Input:
3
7 7 7

Output:
1

Hint: Use the classic O(N²) method: best[i] = 1 + the largest best[j] over j < i where A[j] < A[i] and the bit rule holds for A[j] and A[i].

All coding practice