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. springboot devtool热部署的一个大坑

    spring.devtools.restart.poll-interval=3000ms spring.devtools.restart.quiet-period=2999ms 别问我为什么,问就是一 ...

  2. Unity3D~纹理格式

    因为之前自己从来没有好好看过这部分,一直都是用的DXT压缩图片,结果发现原来ios是不支持DXT的, 还不知道我项目那么卡是不是这部分引起的, 但愿是~这样应该就可以解决游戏在ios上只有6.8帧的问 ...

  3. windows下创建/删除服务

    windows下创建/删除服务 1.      windows下创建/删除服务 1.1.    创建服务 命令格式: sc [servername] create Servicename [Optio ...

  4. [read -p应用]插拔光模块去检查port present状态

    #!/bin/bash path="/sys/devices/platform/soc/fd880000.i2c-pld/i2c-0/i2c-4/i2c-15/15-0060" a ...

  5. postgres语句

    select DISTINCT lxbh from "20190816183245_ld_lxbh_2018" WHERE CHAR_LENGTH("lxbh" ...

  6. git add 添加错文件 撤销

    git status 先看一下add 中的文件 git reset HEAD 如果后面什么都不跟的话 就是上一次add 里面的全部撤销了 git reset HEAD XXX/XXX/XXX.java ...

  7. 吴裕雄--天生自然PYTHON爬虫:使用Scrapy抓取股票行情

    Scrapy框架它能够帮助提升爬虫的效率,从而更好地实现爬虫.Scrapy是一个为了抓取网页数据.提取结构性数据而编写的应用框架,该框架是封装的,包含request异步调度和处理.下载器(多线程的Do ...

  8. 吴裕雄 Bootstrap 前端框架开发——Bootstrap 网格系统实例:列排序

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  9. BurpSuite pro v2.0.11版

    下载地址: 链接:https://pan.baidu.com/s/1CgXgK_lV2OWjRT364hvfog 提取码:gvxy BurpSuite介绍 借用一下吾爱破解文章中的描述信息:https ...

  10. Linux centosVMware Linux集群架构LVS DR模式搭建、keepalived + LVS

    一.LVS DR模式搭建 三台机器 分发器,也叫调度器(简写为dir) davery :1.101 rs1 davery01:1.106 rs2 davery02:11.107 vip 133.200 ...