C - Illuminate Buildings Editorial /

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 350

問題文

N 棟のビルが等間隔に一列に並んでいます。手前から i 番目のビルの高さは H_i です。

あなたは次の条件をともに満たすようにいくつかのビルを選んで電飾で飾ろうとしています。

  • 選んだビルたちは高さが等しい
  • 選んだビルたちは等間隔に並んでいる

最大でいくつのビルを選ぶことができますか? なお、ちょうど 1 つのビルを選んだときは条件を満たすとみなします。

制約

  • 1 \leq N \leq 3000
  • 1 \leq H_i \leq 3000
  • 入力は全て整数である

入力

入力は以下の形式で標準入力から与えられる。

N
H_1 \ldots H_N

出力

答えを出力せよ。


入力例 1

8
5 7 5 7 7 5 7 7

出力例 1

3

手前から 2,5,8 番目のビルを選ぶと条件を満たします。


入力例 2

10
100 200 300 400 500 600 700 800 900 1000

出力例 2

1

1つのビルを選んだときは条件を満たすとみなします。


入力例 3

32
3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 4 3 3 8 3 2 7 9 5

出力例 3

3

Score : 350 points

Problem Statement

There are N buildings arranged in a line at equal intervals. The height of the i-th building from the front is H_i.

You want to decorate some of these buildings with illuminations so that both of the following conditions are satisfied:

  • The chosen buildings all have the same height.
  • The chosen buildings are arranged at equal intervals.

What is the maximum number of buildings you can choose? If you choose exactly one building, it is considered to satisfy the conditions.

Constraints

  • 1 \leq N \leq 3000
  • 1 \leq H_i \leq 3000
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

N
H_1 \ldots H_N

Output

Print the answer.


Sample Input 1

8
5 7 5 7 7 5 7 7

Sample Output 1

3

Choosing the 2nd, 5th, and 8th buildings from the front satisfies the conditions.


Sample Input 2

10
100 200 300 400 500 600 700 800 900 1000

Sample Output 2

1

Choosing just one building is considered to satisfy the conditions.


Sample Input 3

32
3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 4 3 3 8 3 2 7 9 5

Sample Output 3

3