LogiQuest

67. Subarrays with Sum K

MediumPrefix SumHash Map

Count the contiguous subarrays whose sum equals k. Values may be negative.

Input format

Line 1: n k Line 2: n integers

Output format

The number of subarrays.

Example 1

Input

3 2
1 1 1

Output

2

Example 2

Input

3 3
1 2 3

Output

2

Constraints

1 ≤ n ≤ 10⁵

Read input from standard input and print the answer to standard output. Your code is judged against 6 test cases, most of them hidden.

Loading the MyLoginn IDE…