An Easy Problem

View as PDF

Submit solution

Points: 12 (partial)
Time limit: 1.0s
Memory limit: 32M

Problem type
Allowed languages
C, C++, Java, Pascal

Given an array A with N non-negative integers a_i (1 \le i \le N),find the longest subsequence B, where b_i & b_{i-1} is not 0.

NOTE: & is the bitwise and operation. A subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. The two adjacent elements in the subsequence B don't have to be consecutive in the original array A.

Input Specification

The first line consists of one integer N (1 \le N \le 100\,000) The second line consists of N non-negative integers, a_i (0 \le a_i \le 10^9)

Output Specification

One integer, the longest length of the subsequence B.

Sample Input 1

1 2 3 4

Sample Output 1


Sample Input 2

1 2 1 2 1 2 1 4

Sample Output 2