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

#GL0000030. Phần dư của tổng bằng độ dài (Rem of Sum is Num)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Phần dư của tổng bằng độ dài (Rem of Sum is Num)

Rem of Sum is Num

Source: AtCoder

Version: Phuoc Hung OJ Extended

Problem Statement

Given NN positive integers and modulus KK, count nonempty contiguous subarrays [l,r][l,r] whose sum modulo KK equals their length r−l+1r-l+1. Different locations count separately.

Input

First line: N,KN,K. Second line: NN integers AiA_i.

Output

Print the number of qualifying subarrays.

Subtasks

  • Subtask 1 (20 points): 1≤N≤201 \le N \le 20; 1≤K≤201 \le K \le 20; 1≤Ai≤1001 \le A_i \le 100
  • Subtask 2 (30 points): 1≤N≤20001 \le N \le 2000; 1≤K≤1051 \le K \le 10^{5}; 1≤Ai≤1061 \le A_i \le 10^{6}
  • Subtask 3 (50 points): 1≤N≤2⋅1051 \le N \le 2\cdot 10^{5}; 1≤K≤1091 \le K \le 10^{9}; 1≤Ai≤1091 \le A_i \le 10^{9}

Examples

Input

5 4
1 4 2 3 5

Output

4

Explanation

The four valid subarrays are (1)(1), (4,2)(4,2), (1,4,2)(1,4,2) and (5)(5). A qualifying length must be smaller than KK.