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

#PS0000157. Đếm đoạn có đúng K số âm (Count Subarrays With Exactly K Negative Elements)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Đếm đoạn có đúng K số âm (Count Subarrays With Exactly K Negative Elements)

Count Subarrays With Exactly K Negative Elements

Source: Phước Hưng OJ

Version: Phuoc Hung OJ Extended

Problem Statement

Given integers a1,…,ana_1,\ldots,a_n and KK, count nonempty contiguous intervals [l,r][l,r] containing exactly KK strictly negative elements. Zero is not negative.

Input

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

Output

Print one integer: the number of qualifying intervals.

Subtasks

  • Subtask 1 (20 points): 1≤n≤5001\le n\le 500; −109≤aj≤109-10^9\le a_j\le10^9 for all 1≤j≤n1\le j\le n; 0≤K≤n0\le K\le n.
  • Subtask 2 (30 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; K=0K=0.
  • Subtask 3 (50 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; 0≤K≤n0\le K\le n.

Example 1

Input

4 1
-1 0 -2 3

Output

6

Explanation

The qualifying intervals are [1,1], [1,2], [2,3], [2,4], [3,3], [3,4]. Each contains exactly one negative number.

Example 2

Input

4 0
0 2 -1 0

Output

4

Explanation

The maximal nonnegative runs are [1,2] and [4,4], contributing 3 and 1 substrings, respectively.