Problem:
Score : 700 points

Problem Statement

Snuke has a permutation (P_0,P_1,\cdots,P_{N-1}) of (0,1,\cdots,N-1).

Now, he will perform the following operation exactly once:

Choose K consecutive elements in P and sort them in ascending order.

Find the number of permutations that can be produced as P after the operation.

Constraints

2 \leq N \leq 200000

2 \leq K \leq N

0 \leq P_i \leq N-1

P_0,P_1,\cdots,P_{N-1} are all different.

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N K
P_0 P_1 \cdots P_{N-1}

Output

Print the number of permutations that can be produced as P after the operation.

Sample Input 1

5 3
0 2 1 4 3

Sample Output 1

2

Two permutations can be produced as P after the operation: (0,1,2,4,3) and (0,2,1,3,4).

Sample Input 2

4 4
0 1 2 3

Sample Output 2

1

Sample Input 3

10 4
2 0 1 3 7 5 4 6 8 9

Sample Output 3

6

Solution in C++14 (GCC 5.4.1) (judge verdict: Runtime Error)

#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <queue>
#include <set>
#include <math.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> Q;
const ll mod = 1000000007;
const ll INF = 1000000000000000;

ll bit[100010];
ll n, k, p[200010], ans;

ll sum(ll i)
{
	ll s = 0;
	while (i > 0)
	{
		s += bit[i];
		i -= i & -i;
	}
	return s;
}

void add(ll i, ll x)
{
	while (i <= n)
	{
		bit[i] += x;
		i += i & -i;
	}
}

ll pow_mod(ll x, ll y)
{
	ll res = 1;
	while (y > 0)
	{
		if (y % 2 == 1)
		{
			(res *= x) %= mod;
		}
		(x *= x) %= mod;
		y /= 2;
	}
	return res;
}

ll div(ll x)
{
	return pow_mod(x, mod - 2);
}



int main(void)
{
	cin >> n >> k;
	ans = 1;
	for (int i = 1; i <= n; i++)
	{
		cin >> p[i];
	}

	if (n == k)
	{
		cout << 1 << endl;
	}
	else
	{
		for (int i = 1; i <= k; i++)
		{
			add(i, 1);
		}

		for (int i = k + 1 ; i <= n; i++)
		{
			add(i, 1);
			bool jud = true;
			ll lb = -1, ub = n + 1;
			while (lb + 1 < ub)
			{
				ll mid = (lb + ub) / 2;
				if (bit[mid] > 0)
				{
					ub = mid;
				}
				else
				{
					lb = mid;
				}
			}
			if (ub != i - k)
			{
				jud = false;
			}
			lb = -1, ub = n + 1;
			while (lb + 1 < ub)
			{
				ll mid = (lb + ub) / 2;
				if (bit[mid] < k + 1)
				{
					lb = mid;
				}
				else
				{
					ub = mid;
				}
			}
			if (ub != i)
			{
				jud = false;
			}

			if (!jud)
			{
				ans++;
			}
			add(i - k, -1);
		}
		cout << ans << endl;
	}

	int www;
	cin >> www;
}