Berland starts to seize the initiative on the war with Flatland. To drive the enemy from their native land, the berlanders need to know exactly how many more flatland soldiers are left in the enemy's reserve. Fortunately, the scouts captured an enemy in the morning, who had a secret encrypted message with the information the berlanders needed so much.

The captured enemy had an array of positive integers. Berland intelligence have long been aware of the flatland code: to convey the message, which contained a number m, the enemies use an array of integers a. The number of its subarrays, in which there are at least k equal numbers, equals m. The number k has long been known in the Berland army so General Touristov has once again asked Corporal Vasya to perform a simple task: to decipher the flatlanders' message.

Help Vasya, given an array of integers a and number k, find the number of subarrays of the array of numbers a, which has at least k equal numbers.

Subarray a[i... j] (1 ≤ i ≤ j ≤ n) of array a = (a1, a2, ..., an) is an array, made from its consecutive elements, starting from the i-th one and ending with the j-th one: a[i... j] = (ai, ai + 1, ..., aj).

Input

The first line contains two space-separated integers nk (1 ≤ k ≤ n ≤ 4·105), showing how many numbers an array has and how many equal numbers the subarrays are required to have, correspondingly.

The second line contains n space-separated integers ai (1 ≤ ai ≤ 109) — elements of the array.

Output

Print the single number — the number of such subarrays of array a, that they have at least k equal integers.

Please do not use the %lld specifier to read or write 64-bit integers in С++. In is preferred to use the cin, cout streams or the %I64d specifier.

Examples

Input
4 2
1 2 1 2
Output
3
Input
5 3
1 2 1 1 3
Output
2
Input
3 1
1 1 1
Output
6

Note

In the first sample are three subarrays, containing at least two equal numbers: (1,2,1), (2,1,2) and (1,2,1,2).

In the second sample are two subarrays, containing three equal numbers: (1,2,1,1,3) and (1,2,1,1).

In the third sample any subarray contains at least one 1 number. Overall they are 6: (1), (1), (1), (1,1), (1,1) and (1,1,1).

思路:双指针问题,和A题相似,一个指针每次递增一,另一个指针随条件改变不止一,一般是维护第一个指针的极值,然后计算数量

const int maxm = 4e5+;

int buf[maxm], n, k;
map<int, int> vis; int main() {
ios::sync_with_stdio(false), cin.tie();
cin >> n >> k;
for(int i = ; i < n; ++i)
cin >> buf[i];
LL ans = ;
int l = , r = ;
vis[buf[]]++;
while(l + k - < n) {
while(r < n) {
if(vis[buf[r]] >= k) break;
r++;
vis[buf[r]]++;
}
if(r == n) break;
ans += (LL)(n - r);
vis[buf[l]]--;
l++;
}
cout << ans << "\n";
return ;
}

Day8 - B - Non-Secret Cypher CodeForces - 190D的更多相关文章

  1. CodeForces 190D Non-Secret Cypher

    双指针. #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> ...

  2. Day8 - A - Points on Line CodeForces - 251A

    Little Petya likes points a lot. Recently his mom has presented him n points lying on the line OX. N ...

  3. [Codeforces] #603 (Div. 2) A-E题解

    [Codeforces]1263A Sweet Problem [Codeforces]1263B PIN Code [Codeforces]1263C Everyone is a Winner! [ ...

  4. CodeForces 490C Hacking Cypher

    Hacking Cypher Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Sub ...

  5. CodeForces 496B Secret Combination

    Secret Combination Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u ...

  6. Codeforces Round #279 (Div. 2) C. Hacking Cypher 前缀+后缀

    C. Hacking Cypher time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  7. Codecraft-17 and Codeforces Round #391 (Div. 1 + Div. 2, combined)D. Felicity's Big Secret Revealed

    题目连接:http://codeforces.com/contest/757/problem/D D. Felicity's Big Secret Revealed time limit per te ...

  8. Codeforces Round #279 (Div. 2) C. Hacking Cypher (大数取余)

    题目链接 C. Hacking Cyphertime limit per test1 secondmemory limit per test256 megabytesinputstandard inp ...

  9. 构造+暴力 Codeforces Round #283 (Div. 2) B. Secret Combination

    题目传送门 /* 构造+暴力:按照题目意思,只要10次加1就变回原来的数字,暴力枚举所有数字,string大法好! */ /************************************** ...

随机推荐

  1. Spring学习(五)

    自动装备 1.定义 自动装配(autowiring): 将某个Bean实例中所引用的其它的Bean自动注入到当前Bean实例中 自动装配就是指由Spring来自动地注入依赖对象,无需人工参与. 自动装 ...

  2. JVM,JRE,JDK

    JVM (Java Virtual Machine) : Java虚拟机,运行所有Java程序的假象计算机,是Java程序的运行环境,跨平台性由JVM实现. JRE (Java Runtime Env ...

  3. js中的arguments、Array.prototype.slice.call()

    类数组对象:arguments js把传入到这个函数的全部参数存储在arguments里面,其实arguments也是个对象,而且是一个特殊的对象,它的属性名是按照传入参数的序列来的,第1个参数的属性 ...

  4. spring mvc绑定参数之 类型转换 有三种方式:

    spring mvc绑定参数之类型转换有三种方式: 1.实体类中加日期格式化注解(上次做项目使用的这种.简单,但有缺点,是一种局部的处理方式,只能在本实体类中使用.方法三是全局的.) @DateTim ...

  5. Django 学习 之 模板(html)与配置静态文件

     一.模板(html) 1.模板语法之变量:语法为 {{ }} 在 Django 模板中遍历复杂数据结构的关键是句点字符, 语法:{{ var_name }} var_name 是一个变量名称,需要和 ...

  6. iOS直播集成和问题总结(阿里云直播)

    https://www.jianshu.com/p/714ce954e628 最近接手公司的直播项目,对以前遗留的问题做处理和优化, 于是顺便看了下阿里云直播的文档,在下面写下对直播的理解和遇到的问题 ...

  7. JAVA培训—线程同步--卖票问题

    线程同步方法: (1).同步代码块,格式: synchronized (同步对象){ //同步代码 } (2).同步方法,格式: 在方法前加synchronized修饰 问题: 多个人同时买票. 1. ...

  8. C语言结构体指针(指向结构体的指针)详解

    C语言结构体指针详解 一.前言 一个指向结构体的变量的指针表示的是这个结构体变量占内存中的起始位置,同样它也可以指向结构体变量数组. *a).b 等价于 a->b. "."一 ...

  9. 网络协议-dubbo协议

    Dubbo支持dubbo.rmi.hessian.http.webservice.thrift.redis等多种协议,但是Dubbo官网是推荐我们使用Dubbo协议的. 下面我们就针对Dubbo的每种 ...

  10. Python 数据的输入

    一.单个输入 a=input("输入提示语句")#默认a的类型是字符串 b=input() 二.一行输入两个/三个数据,数据之间用空格间隔开 #a,b的数据类型都是整数 a,b=m ...