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

#GL0000027. Đoạn con có tổng chia hết cho d (Divisible)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Đoạn con có tổng chia hết cho d (Divisible)

Divisible

Source: Kattis

Version: Phuoc Hung OJ Extended

Problem Statement

Given an array of nn integers and a positive divisor dd, count nonempty contiguous subarrays whose sum is divisible by dd. Distinct positions represent distinct subarrays.

Input

First line contains d,nd,n; second line contains nn integers aia_i.

Output

Print the number of qualifying subarrays.

Subtasks

  • Subtask 1 (20 points): 1≤d,n≤201 \le d,n \le 20; −100≤ai≤100-100 \le a_i \le 100
  • Subtask 2 (30 points): 1≤d,n≤20001 \le d,n \le 2000; −106≤ai≤106-10^{6} \le a_i \le 10^{6}
  • Subtask 3 (50 points): 1≤d,n≤2⋅1051 \le d,n \le 2\cdot 10^{5}; −109≤ai≤109-10^{9} \le a_i \le 10^{9} (Phuoc Hung OJ version bound)

Examples

Input

3 5
1 2 3 4 5

Output

7

Explanation

There are seven qualifying index intervals, including (1,2),(1,3),(1,5),(2,4),(3,3),(3,5),(4,5)(1,2),(1,3),(1,5),(2,4),(3,3),(3,5),(4,5).