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

#CT0000145. Đoạn có tổng cho trước (Subarrays with a Given Sum)

Bài tập này chưa được xếp vào lộ trình.

Đoạn có tổng cho trước (Subarrays with a Given Sum)

Subarrays with a Given Sum

Version: Phuoc Hung OJ Extended

Problem Statement

An observation station records an integer change over nn consecutive days. The change on day ii is aia_i: positive means an increase, negative means a decrease, and zero means no change.

For 1≤l≤r≤n1\le l\le r\le n, the sum of the contiguous interval [l,r][l,r] is al+al+1+⋯+ara_l+a_{l+1}+\cdots+a_r. Intervals with different endpoint pairs (l,r)(l,r) count as different intervals, even if their elements have identical values.

Given an integer kk, count the nonempty contiguous intervals whose sum is exactly kk.

Input

The first line contains two integers nn and kk.

The second line contains exactly nn integers a1,a2,…,ana_1,a_2,\ldots,a_n, separated by spaces.

Output

Print one integer: the number of contiguous intervals with sum kk. The answer may exceed the range of a signed 3232-bit integer.

Subtasks

  • Subtask 1 (30 points): 1≤n≤2001\le n\le 200; ∣k∣≤1012|k|\le 10^{12}; ∣ai∣≤109|a_i|\le 10^9 for every 1≤i≤n1\le i\le n.
  • Subtask 2 (30 points): 1≤n≤50001\le n\le 5000; ∣k∣≤1012|k|\le 10^{12}; ∣ai∣≤109|a_i|\le 10^9 for every 1≤i≤n1\le i\le n.
  • Subtask 3 (40 points): 1≤n≤2⋅1051\le n\le 2\cdot 10^5; ∣k∣≤1012|k|\le 10^{12}; ∣ai∣≤109|a_i|\le 10^9 for every 1≤i≤n1\le i\le n.

Examples

Example 1

Input

5 3
1 2 1 -1 2

Output

3

Explanation

The array is [1,2,1,−1,2][1,2,1,-1,2]. The valid intervals are [1,2][1,2] (1+2=31+2=3), [1,4][1,4] (1+2+1−1=31+2+1-1=3), and [2,3][2,3] (2+1=32+1=3). Thus the answer is 33.

Example 2

Input

6 0
1 -1 2 -2 3 -3

Output

6

Explanation

Prefix sums at positions 00 through 66 are 0,1,0,2,0,3,00,1,0,2,0,3,0. The value 00 occurs at four positions, 0,2,4,60,2,4,6. Choosing any two produces a zero-sum interval, so there are (42)=6\binom{4}{2}=6: [1,2][1,2], [1,4][1,4], [1,6][1,6], [3,4][3,4], [3,6][3,6], [5,6][5,6].

Example 3

Input

4 10
-1 2 -3 4

Output

0

Explanation

The only positive values are 22 and 44, whose sum is 66. No contiguous interval can reach a sum of 1010, so the answer is 00.