E - Mod i Editorial /

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 500

問題文

長さ N の数列 A が与えられます。A をいくつかの連続した空でない部分列 B_1,B_2,\ldots,B_k に切り分ける方法であって、以下の条件を満たすものの個数を求めてください。

  • 全ての i\ (1 \leq i \leq k) について、B_i に含まれる要素の総和が i で割り切れる。

答えは非常に大きくなることがあるので、(10^9+7) で割ったあまりを出力してください。

制約

  • 1 \leq N \leq 3000
  • 1 \leq A_i \leq 10^{15}
  • 入力は全て整数

入力

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

N
A_1 A_2 \ldots A_N

出力

問題文中の条件を満たすような切り分け方の個数を (10^9+7) で割ったあまりを出力せよ。


入力例 1

4
1 2 3 4

出力例 1

3

以下の 3 通りの切り分け方があります。

  • (1),(2),(3),(4)
  • (1,2,3),(4)
  • (1,2,3,4)

入力例 2

5
8 6 3 3 3

出力例 2

5

入力例 3

10
791754273866483 706434917156797 714489398264550 918142301070506 559125109706263 694445720452148 648739025948445 869006293795825 718343486637033 934236559762733

出力例 3

15

入力が 32 bit 整数型に収まりきらない場合があります。

Score : 500 points

Problem Statement

Given is a sequence A of N numbers. Find the number of ways to separate A into some number of non-empty contiguous subsequence B_1, B_2, \ldots, B_k so that the following condition is satisfied:

  • For every i\ (1 \leq i \leq k), the sum of elements in B_i is divisible by i.

Since the count can be enormous, print it modulo (10^9+7).

Constraints

  • 1 \leq N \leq 3000
  • 1 \leq A_i \leq 10^{15}
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 \ldots A_N

Output

Print the number of ways to separate the sequence so that the condition in the Problem Statement is satisfied, modulo (10^9+7).


Sample Input 1

4
1 2 3 4

Sample Output 1

3

We have three ways to separate the sequence, as follows:

  • (1),(2),(3),(4)
  • (1,2,3),(4)
  • (1,2,3,4)

Sample Input 2

5
8 6 3 3 3

Sample Output 2

5

Sample Input 3

10
791754273866483 706434917156797 714489398264550 918142301070506 559125109706263 694445720452148 648739025948445 869006293795825 718343486637033 934236559762733

Sample Output 3

15

The values in input may not fit into a 32-bit integer type.