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

#FT0000088. Đếm chỉ số K-big (Count the Number of K-Big Indices)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Đếm chỉ số K-big (Count the Number of K-Big Indices)

Count the Number of K-Big Indices

Source: LeetCode

Version: Phuoc Hung OJ Extended

Problem Statement

Given an integer array v1,v2,…,vnv_1,v_2,\ldots,v_n and a positive integer kk, positions are numbered from 11 to nn.

An index ii is kk-big if both of the following conditions hold:

  • There are at least kk indices j<ij<i with vj<viv_j<v_i.
  • There are at least kk indices j>ij>i with vj<viv_j<v_i.

Different positions count separately, even if their values are equal. Only strictly smaller values qualify. Count all kk-big indices.

Input

The first line contains integers n,kn,k.

The second line contains exactly nn integers v1,v2,…,vnv_1,v_2,\ldots,v_n.

Output

Print one integer: the number of positions satisfying both kk-big conditions.

Subtasks

  • Subtask 1 (20 points): 1≤n≤101\le n\le 10; 1≤k≤n1\le k\le n; 1≤vi≤n1\le v_i\le n for every ii.
  • Subtask 2 (30 points): 1≤n≤20001\le n\le 2000; 1≤k≤n1\le k\le n; 1≤vi≤n1\le v_i\le n for every ii.
  • Subtask 3 (50 points): 1≤n≤1000001\le n\le 100000; 1≤k≤n1\le k\le n; 1≤vi≤n1\le v_i\le n for every ii.

Examples

Input

6 2
2 3 6 5 2 3

Output

2

Explanation

For k=2k=2, consider the two qualifying positions:

  • Position 33 has value 66. There are two smaller values 2,32,3 to its left and three 5,2,35,2,3 to its right.
  • Position 44 has value 55. It has two smaller values 2,32,3 on each side.

No other position has at least two strictly smaller values on both sides. The answer is 2.