PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#GL0000146. Các số nguyên kết bạn (Integers Have Friends)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

2 lộ trình

Các số nguyên kết bạn (Integers Have Friends)

Integers Have Friends

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

You are given a sequence of NN pairwise distinct positive integers A1,…,ANA_1,\ldots,A_N. A contiguous subarray [L,R][L,R] is a friend group if there exists an integer m≥2m\ge2 such that all of its elements have the same remainder modulo mm:

AL mod m=AL+1 mod m=⋯=AR mod m.A_L\bmod m=A_{L+1}\bmod m=\cdots=A_R\bmod m.

Find the maximum possible length of a friend group. A single-element interval is allowed.

Input

The first line contains NN. The second contains the NN values A1,…,ANA_1,\ldots,A_N.

Output

Print the maximum length of a friend group.

Subtasks

  • Subtask 1 (20 points): 1≤N≤301 \le N \le 30; 1≤Ai≤1041 \le A_i \le 10^4; allAidistinctall A_i distinct.
  • Subtask 2 (30 points): 1≤N≤50001 \le N \le 5000; 1≤Ai≤1091 \le A_i \le 10^9; allAidistinctall A_i distinct.
  • Subtask 3 (50 points): 1≤N≤2⋅1051 \le N \le 2\cdot 10^5; 1≤Ai≤10181 \le A_i \le 10^{18}; allAidistinctall A_i distinct.

Examples

Input

5
1 5 2 4 6

Output

3

Explanation

The last three values [2,4,6][2,4,6] have remainder 00 modulo 22. No contiguous interval of four elements has a common remainder modulo any m≥2m\ge2, so the answer is 33.