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. js 字符串相关函数

    https://www.jb51.net/article/74614.htm

  2. 了解 C++

    C++的历史 C++由C语言发展演变而来,最初被称为"带类的C" 1983年正式取名为C++ 1998年11月被国籍标准化组织(ISO)批准为国际标准 2003年10月15日发布了 ...

  3. 吴裕雄--天生自然ORACLE数据库学习笔记:数据表对象

    create table students( stuno ) not null, --学号 stuname ), --姓名 sex ), --性别 age int, --年龄 departno ) n ...

  4. 使用tag标签是SEO优化的重要性是什么?

    使用tag标签是SEO优化的重要性是什么? tag标签是一种SEO技术,在网站优化的过程中,更准确.更具体地用关键词对文章进行分类,对SEO优化具有重要的作用. 但是,很多新人站长在发表文章时不太注意 ...

  5. 02-05Android学习进度报告五

    今天主要学习了关于Android 开发的关于进度条和拖动条的知识. 主要学习了一些关于进度条的基本属性: android:max:进度条的最大值 android:progress:进度条已完成进度值 ...

  6. Manthan, Codefest 19 (open for everyone, rated, Div. 1 + Div. 2)D(树状数组)

    //树状数组中数组的特性,有更巧妙的方法.//我们知道在树状数组中,对于数组tree[i],它所维护的区间为[i−lowbit(i)+1,i]//所以对于tree[2^i],它所维护的区间就为[1,2 ...

  7. Linux centosVMware PHP动态扩展模块

    PHP动态扩展模块 /usr/local/php/bin/php -m //查看模块 下面安装一个redis的模块 cd /usr/local/src/ wget https://codeload.g ...

  8. 十八 Spring的JDBC模板:引入外部属性文件

    配置外部属性文件 配置文件里引入属性文件,两种方式 第一种: 第二种: 引入属性文件的值: 测试: <?xml version="1.0" encoding="UT ...

  9. Visual Studio C++覆盖率测试异常的解决方法

    默认的UnitTest可能出现这样的异常 经过查阅资料最终找到了解决办法 步骤如下: 在测试项目右键属性 将配置属性->链接器->调试 生成调试信息修改为如图所示,然后再进行覆盖率测试 就 ...

  10. 深入理解python(二)python基础知识之数据结构

    数据结构 Python中的内置数据结构(Built-in Data Structure):列表list.元组tuple.字典dict.集合set,这里只着重说前三个 >>> d=di ...