You've got an array a, consisting of n integers: a1, a2, ..., an. Your task is to find a minimal by inclusion segment [l, r] (1 ≤ l ≤ r ≤ n) such, that among numbers al, al + 1, ..., ar there are exactly k distinct numbers.
Segment [l, r] (1 ≤ l ≤ r ≤ n; l, r are integers) of length m = r - l + 1, satisfying the given property, is called minimal by inclusion, if there is no segment [x, y] satisfying the property and less then m in length, such that 1 ≤ l ≤ x ≤ y ≤ r ≤ n. Note that the segment [l, r] doesn't have to be minimal in length among all segments, satisfying the given property.
The first line contains two space-separated integers: n and k (1 ≤ n, k ≤ 105). The second line contains n space-separated integers a1, a2, ..., an — elements of the array a (1 ≤ ai ≤ 105).
Print a space-separated pair of integers l and r (1 ≤ l ≤ r ≤ n) such, that the segment [l, r] is the answer to the problem. If the sought segment does not exist, print "-1 -1" without the quotes. If there are multiple correct answers, print any of them.
4 2 1 2 2 3
1 2
8 3 1 1 2 2 3 3 4 5
2 5
7 4 4 7 7 4 7 4 7
-1 -1
In the first sample among numbers a1 and a2 there are exactly two distinct numbers.
In the second sample segment [2, 5] is a minimal by inclusion segment with three distinct numbers, but it is not minimal in length among such segments.
In the third sample there is no segment with four distinct numbers.
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <ctime>
#include <cstdlib>
#include <stack>
#include <map>
#include <set>
#include <list>
#define MP make_pair
#define PB push_back
#define INT_INF 0x3fffffff
#define LL_INF 0x3fffffffffffffff
#define EPS 1e-12
#define MOD 1000000007
#define PI 3.14159265358979323846
#define N 300010
#define E 100010
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef unsigned int Uint;
typedef double DB;
int a[N];
int cnt;
bool vs[N];
int tot[N];
int main()
{
int n,k;
scanf("%d%d",&n,&k);
for(int i=1; i<=n; i++)
scanf("%d",a+i);
cnt=0;
memset(vs,0,sizeof(vs));
memset(tot,0,sizeof(tot));
int L=-1, R=-1, val=-1;
for(int i=1; i<=n; i++)
{
tot[a[i]]++;
if(vs[a[i]]) continue;
vs[a[i]]=1;
cnt++;
if(cnt==k)
{
R=i;
val=1;
break;
}
}
if(val==-1) printf("-1 -1\n");
else
{
for(L=1; L<=R && tot[a[L]]!=1; L++) tot[a[L]]--;
printf("%d %d\n",L,R);
}
return 0;
}