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

#GL0000156. Chia mảng thành những đoạn bằng nhau (Partitioning the Array)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Chia mảng thành những đoạn bằng nhau (Partitioning the Array)

Partitioning the Array

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

Allen has an array a1,…,ana_1,\ldots,a_n. For each positive divisor kk of nn, divide the array into n/kn/k consecutive, non-overlapping blocks of length kk.

Allen earns one point for kk if there exists an integer m≥2m\ge2 such that, after replacing every element by its remainder modulo mm, all blocks become identical at every corresponding position. Determine how many values of kk earn a point. When k=nk=n, there is only one block and the condition is automatically satisfied.

Input

The first line contains nn. The second line contains the nn integers aia_i.

Output

Print the number of positive divisors kk of nn satisfying the condition.

Subtasks

  • Subtask 1 (20 points): 1≤n≤401 \le n \le 40; 1≤ai≤n1 \le a_i \le n.
  • Subtask 2 (30 points): 1≤n≤30001 \le n \le 3000; 1≤ai≤n1 \le a_i \le n.
  • Subtask 3 (50 points): 1≤n≤2⋅1051 \le n \le 2\cdot10^5; 1≤ai≤n1 \le a_i \le n.

Examples

Input

4
1 2 1 4

Output

2

Explanation

For k=2k=2, the blocks [1,2][1,2] and [1,4][1,4] both become [1,0][1,0] modulo 22. For k=4k=4, there is only one block. For k=1k=1, the difference 2−1=12-1=1 makes every modulus at least 22 impossible. Thus the answer is 22.