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

#PS0000011. Đoạn con chia hết (Subarray Divisibility)

HỌC THEO LỘ TRÌNH

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

3 lộ trình

Đoạn con chia hết (Subarray Divisibility)

Source: CSES

Version: Phuoc Hung OJ Extended

Problem Statement

Given an array of nn integers, count the nonempty contiguous intervals [l,r][l,r] whose sum is a multiple of nn. Two intervals with different endpoints count separately.

Input

The first line contains nn. The second line contains nn integers a1,…,ana_1,\ldots,a_n.

Output

Print the number of intervals whose sum is divisible by nn.

Subtasks

  • Subtask 1 (20 points): 1≤n≤401\le n\le 40; −109≤ai≤109-10^9\le a_i\le10^9.
  • Subtask 2 (30 points): 1≤n≤3 0001\le n\le 3\,000; −109≤ai≤109-10^9\le a_i\le10^9.
  • Subtask 3 (50 points): 1≤n≤2⋅1051\le n\le 2\cdot10^5; −109≤ai≤109-10^9\le a_i\le10^9.

Examples

Input

5
3 1 2 7 4

Output

1

Explanation

The interval [2,4][2,4] contains 1,2,71,2,7, which sum to 1010. To see why it is the only one, take the prefix sums including the empty prefix and reduce them modulo 55. The remainders are 0,3,4,1,3,20,3,4,1,3,2. Only the remainder 33 occurs twice, at prefix lengths 11 and 44, giving the interval [2,4][2,4].