#d2808. 最长同余子数组

最长同余子数组

Longest Congruent Subarray

Problem Description

You are given an array {A}\{A\} of length NN whose elements are pairwise distinct.

Find the longest contiguous subarray whose elements are congruent modulo some M≥2M \ge 2. Formally, find the longest A[L…R]A[L \dots R] and an M≥2M \ge 2 such that

$$A_L \equiv A_{L+1} \equiv A_{L+2} \equiv \cdots \equiv A_R \pmod M$$

(where a≡b(modM)a \equiv b \pmod M means a mod M=b mod Ma \bmod M = b \bmod M).

Output only the length of this longest contiguous congruent subarray.

Input Format

The first line contains an integer NN.

The next line contains NN integers A1,A2,…,ANA_1, A_2, \dots, A_N.

Output Format

Output one number: the length of the longest contiguous congruent subarray.

Sample Input

4
8 2 10 5

Sample Output

3

Note that 8,2,108, 2, 10 are all even, so they are congruent modulo M=2M = 2.

Constraints

  • 1≤N≤2×1031 \leq N \leq 2 \times 10^3
  • 1≤ai≤10181 \leq a_i \leq 10^{18}