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

#PS0000164. Đếm đoạn tổng K có độ dài lẻ (Count Odd-Length Subarrays With Sum K)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Đếm đoạn tổng K có độ dài lẻ (Count Odd-Length Subarrays With Sum K)

Count Odd-Length Subarrays With Sum K

Source: Phước Hưng OJ

Version: Phuoc Hung OJ Extended

Problem Statement

Given an array of nn integers a1,a2,…,ana_1,a_2,\ldots,a_n, numbered from 1. A nonempty contiguous interval [l,r][l,r] contains all elements from ll through rr and has length r−l+1r-l+1. Count intervals whose sum is exactly KK and whose length is odd. Intervals with different endpoints are counted separately.

Input

The first line contains two integers n,Kn,K. The second line contains nn integers a1,a2,…,ana_1,a_2,\ldots,a_n.

Output

Print one integer: the number of qualifying intervals.

Subtasks

  • Subtask 1 (30 points): 1≤n≤2001\le n\le 200; −109≤aj≤109-10^9\le a_j\le10^9 for all 1≤j≤n1\le j\le n; −109≤K≤109-10^9\le K\le10^9.
  • Subtask 2 (30 points): 1≤n≤2000001\le n\le 200000; 0≤aj≤1090\le a_j\le10^9 for all 1≤j≤n1\le j\le n; −109≤K≤109-10^9\le K\le10^9.
  • Subtask 3 (40 points): 1≤n≤2000001\le n\le 200000; −109≤aj≤109-10^9\le a_j\le10^9 for all 1≤j≤n1\le j\le n; −109≤K≤109-10^9\le K\le10^9.

Example 1

Input

3 1
1 -1 1

Output

3

Explanation

Intervals [1,1], [3,3], [1,3] sum to 1 and have lengths 1,1,3.

Example 2

Input

4 0
0 0 0 0

Output

6

Explanation

Four intervals of length 1 and two of length 3 sum to zero; even lengths are excluded.