The array a with n integers is given. Let's call the sequence of one or more consecutive elements in a segment. Also let's call the segment k-good if it contains no more than k different values.

Find any longest k-good segment.

As the input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java.


-----Input-----

The first line contains two integers n, k (1 ≤ k ≤ n ≤ 5·10^5) — the number of elements in a and the parameter k.

The second line contains n integers a_{i} (0 ≤ a_{i} ≤ 10^6) — the elements of the array a.


-----Output-----

Print two integers l, r (1 ≤ l ≤ r ≤ n) — the index of the left and the index of the right ends of some k-good longest segment. If there are several longest segments you can print any of them. The elements in a are numbered from 1 to n from left to right.


-----Examples-----
Input
5 5
1 2 3 4 5

Output
1 5

Input
9 3
6 5 1 2 3 2 1 4 5

Output
3 7

Input
3 1
1 2 3

Output
1 1

Source: codeforces | Difficulty: MEDIUM_HARD
Tags: Data structures

Sorting

Amortized analysis


Solutions:
n = int(input())
index = 1
memory = set()
counter = 0
segments = [[0, 0]]
for number in input().split():
	if number not in memory:
		memory.add(number)
	else:
		counter += 1
		segments.append([segments[-1][1] + 1, index])
		memory = set()
	index += 1
segments[-1][1] = n
if counter != 0:
	print(counter)
	segments.remove([0, 0])
	print('\n'.join(('{0} {1}'.format(p, q) for (p, q) in segments)))
else:
	print(-1)


n = int(input())
a = [k for k in input().split(' ')]
answer = -1
l = []
dict = {}
i = 0
for j in range(len(a)):
	if dict.get(a[j]):
		dict = {}
		answer += 1
		l.append(i)
		l.append(j)
		i = j + 1
	else:
		dict.update({a[j]: 1})
if len(l) >= 1:
	l[len(l) - 1] = n - 1
if answer == -1:
	print(answer)
else:
	print(int(answer + 1))
	for p in l:
		print(str(p + 1) + ' ')


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = [0] * (pow(10, 6) + 5)
ans = [1, 1]
l = -1
cnt = 0
j = 0
for i in range(n):
	if b[a[i]] == 0:
		cnt += 1
	b[a[i]] += 1
	if cnt > k:
		while cnt > k:
			b[a[j]] -= 1
			if b[a[j]] == 0:
				cnt -= 1
			j += 1
	if i - j > l:
		ans = [j + 1, i + 1]
		l = i - j
print(*ans)


import os
import sys
from collections import Counter
from io import BytesIO, IOBase

def main():
	(n, k) = map(int, input().split())
	a = [int(x) for x in input().split()]
	j = 0
	z = Counter()
	ac = 0
	p = 0
	an = 0
	s = [1, n + 1]
	for i in range(n):
		if z[a[i]] == 0 and ac < k:
			ac += 1
			z[a[i]] += 1
			p += 1
		elif z[a[i]] > 0:
			z[a[i]] += 1
			p += 1
		elif z[a[i]] == 0 and ac == k:
			while j < n:
				z[a[j]] -= 1
				if z[a[j]] == 0:
					j += 1
					break
				j += 1
				p -= 1
			z[a[i]] += 1
		if p > an:
			an = p
			s = [j + 1, i + 1]
	print(*s)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


def solve(n, k, a):
	(l, r, cur, answer_l, answer_r) = (0, 0, 1, 0, 0)
	cnt = [0 for _ in range(1000010)]
	cnt[a[0]] = 1
	while r + 1 < n:
		r += 1
		cnt[a[r]] += 1
		if cnt[a[r]] == 1:
			cur += 1
		if cur > k:
			if r - l - 1 > answer_r - answer_l:
				(answer_l, answer_r) = (l, r - 1)
		while cur > k:
			cnt[a[l]] -= 1
			if cnt[a[l]] == 0:
				cur -= 1
			l += 1
	if r - l > answer_r - answer_l:
		(answer_l, answer_r) = (l, r)
	print(answer_l + 1, answer_r + 1)

def __starting_point():
	(n, k) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	solve(n, k, a)
__starting_point()


n = int(input())
a = list(map(int, input().split()))
z = []
p = set()
k1 = 1
for i in range(n):
	if a[i] in p:
		z.append((k1, i + 1))
		k1 = i + 2
		p = set()
	else:
		p.add(a[i])
if len(z) > 0:
	z[len(z) - 1] = (z[len(z) - 1][0], n)
	print(len(z))
	for k in z:
		print(k[0], k[1])
else:
	print(-1)


def add(elements, to_add):
	if to_add not in elements:
		elements[to_add] = 0
	elements[to_add] += 1

def remove(elements, to_remove):
	elements[to_remove] -= 1
	if elements[to_remove] == 0:
		del elements[to_remove]
(_, limit) = [int(i) for i in input().split()]
arr = [int(i) for i in input().split()]
longest_good = 0
good_seg = [-1, -1]
left = 0
elements = {}
for right in range(len(arr)):
	add(elements, arr[right])
	while len(elements) > limit:
		remove(elements, arr[left])
		left += 1
	if right - left + 1 > longest_good:
		longest_good = right - left + 1
		good_seg = [left + 1, right + 1]
print(good_seg[0], good_seg[1])


from sys import stdin
n = int(stdin.buffer.readline())
a = list(map(int, stdin.buffer.readline().split()))
mp = dict()
l = 0
res = list()
for i in range(n):
	if a[i] in mp:
		res.append((l + 1, i + 1))
		mp.clear()
		l = i + 1
	else:
		mp[a[i]] = 1
if len(res) == 0:
	print(-1)
	exit()
print(len(res))
for i in range(len(res)):
	if i == len(res) - 1:
		print(res[i][0], n)
	else:
		print(res[i][0], res[i][1])


s = input().split()
(n, k) = (int(s[0]), int(s[1]))
s = input().split()
a = []
for i in range(n):
	e = int(s[i])
	a.append(e)
(freq, add) = ([], [])
for i in range(10 ** 6 + 1):
	freq.append(0)
for i in range(n):
	add.append(1)
(i, j) = (0, 0)
d = 0
m = -1
(l, r) = (-1, -1)
while i <= j and j < n:
	d += freq[a[j]] == 0
	freq[a[j]] += add[j]
	add[j] = 0
	if d > k:
		freq[a[i]] = max(0, freq[a[i]] - 1)
		d -= freq[a[i]] == 0
		i += 1
	else:
		temp = j - i
		if temp > m:
			m = temp
			(l, r) = (i + 1, j + 1)
		j += 1
print(l, r)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
cur_r = 0
d = {}
cur_ans = 0
ans_1 = 0
ans_2 = 0
for cur_l in range(n):
	t = a[cur_l]
	d[t] = d.get(t, 0) + 1
	if d[t] == 1:
		cur_ans += 1
	while cur_ans > k:
		t = a[cur_r]
		d[t] -= 1
		if not d[t]:
			cur_ans -= 1
		cur_r += 1
	if cur_l - cur_r + 1 > ans:
		ans = cur_l - cur_r + 1
		ans_1 = cur_r
		ans_2 = cur_l
print(ans_1 + 1, ans_2 + 1)


import os
import sys
from io import BytesIO, IOBase
from collections import defaultdict

def main():
	(n, k) = map(int, input().split(' '))
	nums = list(map(int, input().split(' ')))
	low = 0
	(left, right) = (1, n)
	ans = 0
	dic = defaultdict(lambda : 0)
	for x in range(len(nums)):
		dic[nums[x]] += 1
		while len(dic) > k:
			if x - low > ans:
				ans = x - low
				left = low + 1
				right = x
			dic[nums[low]] -= 1
			if dic[nums[low]] == 0:
				del dic[nums[low]]
			low += 1
	if n - low > ans:
		ans = x - low
		left = low + 1
		right = n
	print(left, right)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


(n, k) = map(int, input().split())
d = dict()
lo = hi = ans1 = ans2 = 0
lst = list(map(int, input().split()))
for i in range(n):
	if lst[i] not in d:
		d[lst[i]] = 1
	else:
		d[lst[i]] += 1
	hi += 1
	if len(d) > k:
		if ans2 - ans1 <= hi - 1 - lo:
			ans2 = hi - 1
			ans1 = lo
		while len(d) == k + 1:
			d[lst[lo]] -= 1
			if d[lst[lo]] == 0:
				del d[lst[lo]]
			lo += 1
if ans2 - ans1 <= hi - 1 - lo:
	ans2 = hi
	ans1 = lo
print(ans1 + 1, ans2)


size = int(input())
(myDic, capture, limit) = ({}, [], -1)
for (x, y) in enumerate(map(int, input().split())):
	if y in myDic:
		check = x - myDic[y][-1]
		if myDic[y][-1] > limit:
			capture.append((myDic[y][-1] + 1, x + 1))
			limit = x
			del myDic[y]
		else:
			myDic[y][-1] = x
	else:
		myDic.update({y: [x]})
if capture:
	res = len(capture)
	if res == 1:
		print(res)
		print(1, size)
	else:
		print(res)
		print(1, capture[0][1])
		start = capture[0][1] + 1
		for c in range(1, res):
			print(start, capture[c][1] if c + 1 < res else size)
			start = capture[c][1] + 1
else:
	print(-1)


def main():
	(n, res) = (int(input()), [])
	(s, i, fmt) = (set(), 1, '{:n} {:n}'.format)
	for (j, a) in enumerate(input().split(), 1):
		if a in s:
			s = set()
			res.append(fmt(i, j))
			i = j + 1
		else:
			s.add(a)
	if res:
		print(len(res))
		res[-1] = res[-1].split()[0] + ' ' + str(n)
		print('\n'.join(res))
	else:
		print(-1)
main()


n = int(input())
s = input().split()
initial_pos = 0
ans = 0
ans_list = []
l = set()
for i in range(n):
	if s[i] in l:
		ans += 1
		ans_list.append([initial_pos + 1, i + 1])
		initial_pos = i + 1
		l = set()
	else:
		l.add(s[i])
if ans == 0:
	print(-1)
else:
	if not ans_list[-1][1] == n:
		ans_list[-1][1] = n
	print(ans)
	for i in ans_list:
		print(' '.join((str(e) for e in i)))


def good(nums):
	for num in nums:
		if nums[num] > 1:
			return True
	return False
n = int(input())
a = [int(i) for i in input().split()]
s = []
(l, r) = (0, 0)
nums = {}
for i in range(n):
	num = a[i]
	if num in nums:
		break
	else:
		nums[num] = True
else:
	print(-1)
	exit()
nums = {}
while r < n:
	while r < n:
		num = a[r]
		if num in nums:
			r += 1
			break
		else:
			nums[num] = True
		r += 1
	r -= 1
	s.append([l, r])
	r += 1
	l = r
	nums = {}
length = len(s)
last = s[length - 1]
for i in range(last[0], last[1] + 1):
	num = a[i]
	if num in nums:
		print(length)
		break
	else:
		nums[num] = True
else:
	s.pop()
	s[length - 2][1] = n - 1
	print(length - 1)
for st in s:
	for c in st:
		print(c + 1, end=' ')
	print()


def main():
	a = [int(x) for x in input().split()]
	g = 1
	mo = 0
	w = 1
	bigarray = [0] * 1000000
	rmo = []
	req = a[1]
	seq = [int(x) for x in input().split()]
	bigarray[seq[0]] += 1
	first = 0
	last = 0
	if a[0] == req:
		rmo = [1, a[0]]
	else:
		while first != len(seq) - 1:
			if w < req:
				if bigarray[seq[first + 1]] == 0:
					first += 1
					bigarray[seq[first]] += 1
					g = g + 1
					w = w + 1
				elif bigarray[seq[first + 1]] != 0:
					bigarray[seq[first + 1]] += 1
					first = first + 1
					g = g + 1
				if mo < g:
					mo = g
					rmo = [last + 1, first + 1]
			elif w >= req:
				if bigarray[seq[first + 1]] == 0:
					bigarray[seq[last]] -= 1
					if bigarray[seq[last]] == 0:
						w = w - 1
					if g > mo:
						mo = g
						rmo = [last + 1, first + 1]
					g = g - 1
					last = last + 1
				else:
					g = g + 1
					first += 1
					bigarray[seq[first]] += 1
					if mo < g:
						mo = g
						rmo = [last + 1, first + 1]
	for x in rmo:
		print(x, end=' ')
main()


n = int(input())
ty = list(map(int, input().split()))
num = 0
x = 1
seg = []
a = 1
dic = {}
for i in range(n):
	dic[ty[i]] = 0
dic[ty[0]] = 1
for i in range(1, n):
	jud = 0
	if dic[ty[i]] != num + 1:
		dic[ty[i]] = num + 1
	elif dic[ty[i]] == num + 1:
		jud = 1
		num += 1
		b = i + 1
		ls = [str(a), str(b)]
		seg.append(ls)
		a = i + 2
if len(seg) == 0:
	print(-1)
else:
	if jud == 0:
		seg[-1][1] = str(n)
	print(num)
	for i in range(len(seg)):
		print(' '.join(seg[i]))


n = int(input())
t = list(map(int, input().split()))
f = {}
l = []
st = 1
for j in range(n):
	if t[j] not in f:
		f[t[j]] = 1
	else:
		l.append([st, j + 1])
		f = {}
		st = j + 2
if st != n + 1:
	if len(l) > 0:
		a = l.pop()[0]
		l.append([a, n])
		print(len(l))
		for j in l:
			print(*j)
	else:
		print(-1)
else:
	print(len(l))
	for j in l:
		print(*j)


s1 = input().split()
length = int(s1[0])
max_k = int(s1[1])
s2 = input()
arr = s2.split()
start = 0
end = 0
dist = dict()
s = start
max_l = 0
for i in range(length):
	cur = arr[i]
	if cur not in dist:
		dist[cur] = 1
	else:
		dist[cur] += 1
	k = len(dist)
	l = i - s
	if k > max_k:
		to_remove = arr[s]
		if dist[to_remove] == 1:
			dist.pop(to_remove)
		else:
			dist[to_remove] -= 1
		l -= 1
		s += 1
	if l > max_l:
		start = s
		max_l = l
		end = i
print(start + 1, end + 1)


from sys import stdin
n = int(stdin.readline().strip())
a = list(map(int, stdin.readline().split()))
s = set()
flag = False
index = 1
res1 = []
res2 = []
for (i, v) in enumerate(a):
	if not v in s:
		s.add(v)
	else:
		s.clear()
		res1.append(index)
		res2.append(i + 1)
		index = i + 2
		flag = True
if flag:
	if not res2[-1] == n:
		res2[-1] = n
	print(len(res1))
	for (i, j) in zip(res1, res2):
		print(i, j)
else:
	print(-1)


from functools import cmp_to_key
from collections import deque, Counter
from heapq import heappush, heappop
from math import log, ceil
import sys
import os
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def ii():
	return int(inp())

def si():
	return str(inp())

def li(lag=0):
	l = list(map(int, inp().split()))
	if lag != 0:
		for i in range(len(l)):
			l[i] += lag
	return l

def mi(lag=0):
	matrix = list()
	for i in range(n):
		matrix.append(li(lag))
	return matrix

def lsi():
	return list(map(str, inp().split()))

def print_list(lista, space=' '):
	print(space.join(map(str, lista)))

def bisect_left(a, x):
	left = 0
	right = len(a)
	while left < right:
		mid = (left + right) // 2
		if a[mid] < x:
			left = mid + 1
		else:
			right = mid
	return left

def bisect_right(a, x):
	left = 0
	right = len(a)
	while left < right:
		mid = (left + right) // 2
		if a[mid] > x:
			right = mid
		else:
			left = mid + 1
	return left

def bisect_elements(a, x):
	return bisect_right(a, x) - bisect_left(a, x)
MOD = 10 ** 9 + 7
maxN = 5
FACT = [0] * maxN
INV_FACT = [0] * maxN

def add(x, y):
	return (x + y) % MOD

def multiply(x, y):
	return x * y % MOD

def power(x, y):
	if y == 0:
		return 1
	elif y % 2:
		return multiply(x, power(x, y - 1))
	else:
		a = power(x, y // 2)
		return multiply(a, a)

def inverse(x):
	return power(x, MOD - 2)

def divide(x, y):
	return multiply(x, inverse(y))

def allFactorials():
	FACT[0] = 1
	for i in range(1, maxN):
		FACT[i] = multiply(i, FACT[i - 1])

def inverseFactorials():
	n = len(INV_FACT)
	INV_FACT[n - 1] = inverse(FACT[n - 1])
	for i in range(n - 2, -1, -1):
		INV_FACT[i] = multiply(INV_FACT[i + 1], i + 1)

def coeffBinom(n, k):
	if n < k:
		return 0
	return multiply(FACT[n], multiply(INV_FACT[k], INV_FACT[n - k]))

def create_graph(n, m, undirected=1, unweighted=1):
	graph = [[] for i in range(n)]
	if unweighted:
		for i in range(m):
			[x, y] = li(lag=-1)
			graph[x].append(y)
			if undirected:
				graph[y].append(x)
	else:
		for i in range(m):
			[x, y, w] = li(lag=-1)
			w += 1
			graph[x].append([y, w])
			if undirected:
				graph[y].append([x, w])
	return graph

def create_tree(n, unweighted=1):
	children = [[] for i in range(n)]
	if unweighted:
		for i in range(n - 1):
			[x, y] = li(lag=-1)
			children[x].append(y)
			children[y].append(x)
	else:
		for i in range(n - 1):
			[x, y, w] = li(lag=-1)
			w += 1
			children[x].append([y, w])
			children[y].append([x, w])
	return children

def dist(tree, n, A, B=-1):
	s = [[A, 0]]
	(massimo, massimo_nodo) = (0, 0)
	distanza = -1
	v = [-1] * n
	while s:
		(el, dis) = s.pop()
		if dis > massimo:
			massimo = dis
			massimo_nodo = el
		if el == B:
			distanza = dis
		for child in tree[el]:
			if v[child] == -1:
				v[child] = 1
				s.append([child, dis + 1])
	return (massimo, massimo_nodo, distanza)

def diameter(tree):
	(_, foglia, _) = dist(tree, n, 0)
	(diam, _, _) = dist(tree, n, foglia)
	return diam

def dfs(graph, n, A):
	v = [-1] * n
	s = [[A, 0]]
	v[A] = 0
	while s:
		(el, dis) = s.pop()
		for child in graph[el]:
			if v[child] == -1:
				v[child] = dis + 1
				s.append([child, dis + 1])
	return v

def bfs(graph, n, A):
	v = [-1] * n
	s = deque()
	s.append([A, 0])
	v[A] = 0
	while s:
		(el, dis) = s.popleft()
		for child in graph[el]:
			if v[child] == -1:
				v[child] = dis + 1
				s.append([child, dis + 1])
	return v

def parents_children_root_unrooted_tree(tree, n, root=0):
	q = deque()
	visited = [0] * n
	parent = [-1] * n
	children = [[] for i in range(n)]
	q.append(root)
	while q:
		all_done = 1
		visited[q[0]] = 1
		for child in tree[q[0]]:
			if not visited[child]:
				all_done = 0
				q.appendleft(child)
		if all_done:
			for child in tree[q[0]]:
				if parent[child] == -1:
					parent[q[0]] = child
					children[child].append(q[0])
			q.popleft()
	return (parent, children)

def all_longest_path_passing_from_node(parent, children, n):
	q = deque()
	visited = [len(children[i]) for i in range(n)]
	downwards = [[0, 0] for i in range(n)]
	upward = [1] * n
	longest_path = [1] * n
	for i in range(n):
		if not visited[i]:
			q.append(i)
			downwards[i] = [1, 0]
	while q:
		node = q.popleft()
		if parent[node] != -1:
			visited[parent[node]] -= 1
			if not visited[parent[node]]:
				q.append(parent[node])
		else:
			root = node
		for child in children[node]:
			downwards[node] = sorted([downwards[node][0], downwards[node][1], downwards[child][0] + 1], reverse=True)[0:2]
	s = [node]
	while s:
		node = s.pop()
		if parent[node] != -1:
			if downwards[parent[node]][0] == downwards[node][0] + 1:
				upward[node] = 1 + max(upward[parent[node]], downwards[parent[node]][1])
			else:
				upward[node] = 1 + max(upward[parent[node]], downwards[parent[node]][0])
		longest_path[node] = downwards[node][0] + downwards[node][1] + upward[node] - min([downwards[node][0], downwards[node][1], upward[node]]) - 1
		for child in children[node]:
			s.append(child)
	return longest_path
(n, k) = li()
a = li()
(l, r) = (0, 0)
(ml, mr) = (0, 0)
d = 0
s = dict()
while l < n:
	if d < k and r < n:
		s[a[r]] = s.get(a[r], 0) + 1
		r += 1
		d = len(s)
	elif d == k and r < n and (a[r] in s):
		s[a[r]] += 1
		r += 1
	else:
		s[a[l]] -= 1
		if s[a[l]] == 0:
			s.pop(a[l])
			d -= 1
		l += 1
	if mr - ml < r - l:
		mr = r
		ml = l
print_list([ml + 1, mr])


n = int(input())
a = [int(x) for x in input().split()]
r = []
s = set()
l = 0
for (i, x) in enumerate(a):
	if x in s:
		r.append([l + 1, i + 1])
		l = i + 1
		s = set()
	else:
		s.add(x)
if l == 0:
	print(-1)
else:
	if s:
		r[-1][1] = n
	print(len(r))
	print('\n'.join(('{0} {1}'.format(p, q) for (p, q) in r)))


n = int(input())
a = list(map(int, input().split()))
ans = []
s = set()
for i in range(len(a)):
	if a[i] in s:
		s = set()
		ans.append(i + 1)
	else:
		s.add(a[i])
if len(ans) == 0:
	print(-1)
elif len(ans) == 1:
	print(len(ans))
	print(1, len(a))
else:
	print(len(ans))
	for i in range(len(ans)):
		if i == 0:
			print(1, ans[0])
		elif i == len(ans) - 1:
			print(ans[i - 1] + 1, len(a))
		else:
			print(ans[i - 1] + 1, ans[i])


n = int(input())
l = list(map(int, input().split()))
s = set()
ans = []
for i in range(n):
	if l[i] in s:
		if ans:
			ans.append([ans[-1][1] + 1, i + 1])
		else:
			ans = [[1, i + 1]]
		s = set()
	else:
		s.add(l[i])
if ans and s:
	ans[-1][1] += len(s)
if ans:
	print(len(ans))
	for i in ans:
		print(i[0], i[1])
else:
	print(-1)


import sys
input = sys.stdin.readline
from collections import defaultdict
(n, k) = map(int, input().split())
a = list(map(int, input().split()))
cnt = defaultdict(int)
typ = 0
d = 0
ans = []
(l, r) = (0, 0)
while r < n:
	if typ <= k:
		r += 1
		aa = a[r - 1]
		if cnt[aa] == 0:
			cnt[aa] = 1
			typ += 1
		else:
			cnt[aa] += 1
		if typ <= k:
			if d < r - l:
				d = r - l
				ans = [l + 1, r]
	else:
		aa = a[l]
		if r - l > 1:
			l += 1
		else:
			break
		if cnt[aa] == 1:
			cnt[aa] -= 1
			typ -= 1
		else:
			cnt[aa] -= 1
		if typ <= k:
			if d < r - l:
				d = r - l
				ans = [l + 1, r]
print(*ans)


import sys
count = int(input())
perls = list(input().split(' '))
if len(perls) < 2:
	print('-1')
	(sys, exit())
start = 0
cur = 0
flag = 0
slide = set()
goodlist = list()
for i in perls:
	if i in slide:
		goodlist.append([start + 1, cur + 1])
		start = cur + 1
		slide.clear()
		flag = 1
	else:
		slide.add(i)
		flag = 0
	cur += 1
if len(goodlist) == 0:
	print('-1')
	sys.exit()
if flag == 0:
	goodlist[-1][1] = len(perls)
print(len(goodlist))
for i in goodlist:
	print('{} {}'.format(i[0], i[1]))


from sys import stdin
input = stdin.readline

def longestK(arr, k):
	cnt = [0] * (10 ** 6 + 1)
	cur = 0
	l = 0
	ans = 0
	al = 0
	ar = 0
	for i in range(len(arr)):
		cnt[arr[i]] += 1
		if cnt[arr[i]] == 1:
			cur += 1
		while cur > k:
			cnt[arr[l]] -= 1
			if cnt[arr[l]] == 0:
				cur -= 1
			l += 1
		if i - l + 1 > ans:
			al = l
			ar = i
			ans = i - l + 1
	print(al + 1, ar + 1)
	return ''
(a, b) = map(int, input().strip().split())
lst = list(map(int, input().strip().split()))
print(longestK(lst, b))


n = int(input())
d = {}
arr = []
p = list(map(int, input().split()))
l = 0
for i in range(n):
	try:
		d[p[i]] += 1
		arr.append([l + 1, i + 1])
		l = i + 1
		d = {}
	except:
		d[p[i]] = 1
if len(arr) != 0:
	arr[-1][1] = max(arr[-1][1], n)
if len(arr) == 0:
	print(-1)
else:
	print(len(arr))
	for i in range(len(arr)):
		print(arr[i][0], arr[i][1])


n = int(input())
arr = [int(x) for x in input().split()]
v = {}
ans = []
prev = 0
for i in range(n):
	if arr[i] in v:
		ans.append([prev + 1, i + 1])
		v = {}
		prev = i + 1
	else:
		v[arr[i]] = i
if ans:
	ans[-1][1] = n
	print(len(ans))
	for i in ans:
		print(i[0], i[1])
else:
	print('-1')


import sys
(n, m) = list(map(int, sys.stdin.readline().split()))
vis = [0] * 1000005
num = list(map(int, sys.stdin.readline().split()))
flag = 0
temp = num[0]
for i in range(n):
	if num[i] != temp:
		flag = 1
		break
if flag == 0:
	print('{0} {1}'.format(1, n))
else:
	l = 0
	r = 0
	al = 0
	ar = 0
	ans = 0
	now = 0
	for i in range(n):
		vis[num[i]] += 1
		if vis[num[i]] == 1:
			now += 1
		while now > m:
			vis[num[l]] -= 1
			if vis[num[l]] == 0:
				now -= 1
			l += 1
		if i - l + 1 > ar - al + 1:
			ar = i
			al = l
	print('{0} {1}'.format(al + 1, ar + 1))


n = int(input())
a = list(map(int, input().split()))
d = {}
k = 0
ans = []
j = 0
for i in range(n):
	if a[i] in d:
		if d[a[i]] >= j:
			ans.append([j + 1, i + 1])
			j = i + 1
			k += 1
	d[a[i]] = i
print(k if not k == 0 else -1)
for i in range(k):
	if not i == k - 1:
		print(ans[i][0], ans[i][1])
	else:
		print(ans[i][0], n)


n = int(input())
ans = list()
s = set()
for (i, x) in enumerate(map(int, input().split())):
	if not s:
		idx = i + 1
	elif x in s:
		ans.append((idx, i + 1))
		s = set()
		continue
	s.add(x)
if len(ans):
	ans[-1] = (ans[-1][0], n)
	print(len(ans))
	print('\n'.join(('%d %d' % p for p in ans)))
else:
	print(-1)


from collections import *
from math import *
from itertools import *
frq = defaultdict(int)

def I():
	return map(int, input().strip().split())
(n, k) = I()
arr = [0] + list(I())
(ans, pivot, nums) = ([0, 0], 0, 0)
(l, r) = (1, 1)
while r <= n:
	if not bool(frq[arr[r]]):
		nums += 1
	frq[arr[r]] += 1
	while nums > k:
		frq[arr[l]] -= 1
		if not bool(frq[arr[l]]):
			nums -= 1
		l += 1
	if r - l + 1 > pivot:
		pivot = r - l + 1
		ans = [l, r]
	r += 1
print(*ans)


import sys
(n, k) = map(int, sys.stdin.buffer.readline().decode('utf-8').split())
a = list(map(int, sys.stdin.buffer.readline().decode('utf-8').split()))
(ans_len, i, j) = (0, 0, 0)
(ans_i, ans_j) = (0, 0)
kind = 0
cnt = [0] * (10 ** 6 + 10)
for i in range(n):
	while j < n and kind + (1 if cnt[a[j]] == 0 else 0) <= k:
		kind += 1 if cnt[a[j]] == 0 else 0
		cnt[a[j]] += 1
		j += 1
	if ans_len < j - i:
		ans_len = j - i
		(ans_i, ans_j) = (i + 1, j)
	cnt[a[i]] -= 1
	kind -= 1 if cnt[a[i]] == 0 else 0
print(ans_i, ans_j)


n = int(input())
a = list(map(int, input().strip().split()))
i = 0
d = dict()
res = []
s = 1
while i < n:
	if a[i] in d.keys():
		res.append([s, i + 1])
		d = dict()
		s = i + 2
	else:
		d[a[i]] = 1
	i += 1
try:
	res[-1][1] = n
except:
	pass
if len(res) > 0:
	print(len(res))
	for i in res:
		print(' '.join(map(str, i)))
else:
	print(-1)


import sys
import collections
(n, a) = (int(input()), list(map(int, sys.stdin.readline().split())))
f = collections.defaultdict(int)
ans = list()
(prev, curr) = (1, 1)
for i in range(n):
	f[a[i]] += 1
	if f[a[i]] == 2:
		ans.append((prev, curr))
		for j in range(prev - 1, curr):
			f[a[j]] -= 1
		prev = curr + 1
	curr += 1
if len(ans) == 0:
	print('-1')
else:
	l = ans.pop()
	ans.append((l[0], n))
	print(len(ans))
	for (x, y) in ans:
		sys.stdout.write(str(x) + ' ' + str(y) + '\n')


import sys
n = int(input())
a = list(map(int, input().split()))
left = set()
i = 1
ans = []
for (j, x) in enumerate(a, start=1):
	if x in left:
		ans.append([i, j])
		left.clear()
		i = j + 1
	else:
		left.add(x)
if not ans:
	print(-1)
else:
	ans[-1][1] = n
	s = str(len(ans)) + '\n' + '\n'.join((' '.join((str(x), str(y))) for (x, y) in ans))
	sys.stdout.buffer.write(s.encode('utf-8'))


n = int(input())
li = list(map(int, input().split()))
s = set()
otv = []
l = 0
r = -1
for i in range(n):
	if li[i] in s:
		otv.append([l + 1, i + 1])
		s = set()
		l = i + 1
		r = 1
	else:
		s.add(li[i])
if r == -1:
	print(-1)
else:
	print(len(otv))
	otv[len(otv) - 1][1] = n
	for i in otv:
		print(*i)


import sys
n = int(sys.stdin.readline())
ans = []
s = set()
left = 1
for (i, e) in enumerate(map(int, sys.stdin.readline().split()), 1):
	if e in s:
		s = set()
		ans += [(left, i)]
		left = i + 1
	else:
		s.add(e)
if ans:
	sys.stdout.write(f'{len(ans)}\n')
	ans[-1] = (ans[-1][0], n)
	for (a, b) in ans:
		sys.stdout.write(f'{a} {b}\n')
else:
	sys.stdout.write('-1\n')


from sys import stdin, stdout
(n, k) = [int(i) for i in stdin.readline().split()]
s = [0] * (10 ** 6 + 1)
a = [int(i) for i in stdin.readline().split()]
mx = lmx = rmx = l = sm = 0
r = -1
while True:
	r += 1
	if r == n:
		(mx, lmx, rmx) = max((mx, lmx, rmx), (r - l, l, r - 1))
		break
	if not s[a[r]]:
		sm += 1
	s[a[r]] += 1
	if sm > k:
		(mx, lmx, rmx) = max((mx, lmx, rmx), (r - l, l, r - 1))
		while sm > k and l < r:
			s[a[l]] -= 1
			if not s[a[l]]:
				sm -= 1
			l += 1
	elif r == n - 1:
		(mx, lmx, rmx) = max((mx, lmx, rmx), (r - l + 1, l, r))
		break
print(lmx + 1, rmx + 1)


import sys
import collections
(n, k) = map(int, input().split())
a = list(map(int, sys.stdin.readline().split()))
ct = collections.defaultdict(int)
(l, longest, numbers) = (0, 0, 0)
for r in range(n):
	ct[a[r]] += 1
	if ct[a[r]] == 1:
		numbers += 1
	while numbers > k:
		ct[a[l]] -= 1
		if ct[a[l]] == 0:
			numbers -= 1
		l += 1
	if r - l + 1 > longest:
		longest = r - l + 1
		ans = (l + 1, r + 1)
print('%d %d' % ans)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
(slow, fast) = (0, 0)
cnt = {}
mx = -1
while fast < n:
	x = a[fast]
	cnt[x] = cnt.get(x, 0) + 1
	if len(cnt) <= k and fast - slow > mx:
		mx = fast - slow
		(l, r) = (slow + 1, fast + 1)
	elif len(cnt) > k:
		x = a[slow]
		cnt[x] -= 1
		if cnt[x] == 0:
			del cnt[x]
		slow += 1
	fast += 1
print(l, r)


(n, k) = list(map(int, input().split()))
lis = list(map(int, input().split()))
ins = [0 for i in range(10 ** 6)]
ins[lis[0]] += 1
zeroes = 10 ** 6 - 1
mL = 0
pair = [0, 0]
r = 0
for l in range(n):
	if l > 0:
		ins[lis[l - 1]] -= 1
		if ins[lis[l - 1]] == 0:
			zeroes += 1
	while 10 ** 6 - zeroes <= k and r < n - 1:
		r += 1
		ins[lis[r]] += 1
		if ins[lis[r]] == 1:
			zeroes -= 1
		if 10 ** 6 - zeroes == k + 1:
			ins[lis[r]] -= 1
			zeroes += 1
			r -= 1
			break
	if mL < r - l:
		mL = r - l
		pair = [l, r]
print(pair[0] + 1, pair[1] + 1)


import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
b = set([])
c = []
d = 1
for i in range(n):
	if a[i] in b:
		b = set([])
		c.append([d, i + 1])
		d = i + 2
	else:
		b.add(a[i])
if len(c) == 0:
	print(-1)
else:
	c[-1][-1] = n
	print(len(c))
	for i in range(len(c)):
		print(*c[i])


n = int(input())
a = list(map(int, input().split()))
sub = set()
starts = list()
starts.append(1)
for i in range(n):
	if a[i] in sub:
		sub = set()
		starts.append(i + 2)
	else:
		sub.add(a[i])
l = len(starts)
if l == 1:
	print(-1)
else:
	print(l - 1)
	for i in range(l - 2):
		print(starts[i], starts[i + 1] - 1)
	print(starts[l - 2], n)


import sys
import math
input = sys.stdin.readline
n = int(input())
arr = list(map(int, input().split()))
ans = list()
left = -1
dc = dict()
for i in range(n):
	if arr[i] in dc.keys() and dc[arr[i]] > left:
		ans.append([left + 1, i])
		dc.pop(arr[i], None)
		left = i
	else:
		dc[arr[i]] = i
if len(ans) == 0:
	print(-1)
else:
	print(len(ans))
	for i in range(len(ans)):
		if i == 0 and i == len(ans) - 1:
			print(1, n)
		elif i == 0:
			print(1, ans[i][1] + 1)
		elif i == len(ans) - 1:
			print(ans[i][0] + 1, n)
		else:
			print(ans[i][0] + 1, ans[i][1] + 1)


def main():
	(n, k) = map(int, input().split())
	myList = list(map(int, input().split()))
	i = 0
	distinct = 0
	dictOf = [0] * 1000001
	best = 0
	bestX = 0
	bestY = 0
	for j in range(n):
		dictOf[myList[j]] += 1
		if dictOf[myList[j]] == 1:
			distinct += 1
		while distinct > k:
			dictOf[myList[i]] -= 1
			if dictOf[myList[i]] == 0:
				distinct -= 1
			i += 1
		if j - i + 1 > best:
			best = j - i + 1
			bestX = i + 1
			bestY = j + 1
	print(bestX, bestY)
main()


n = int(input())
fm = 0
a = list(map(int, input().split()))
s = set()
ans = list()
for i in range(0, n):
	if a[i] in s:
		s.clear()
		ans.append(fm + 1)
		ans.append(i + 1)
		fm = i + 1
		continue
	s.add(a[i])
if len(ans) == 0:
	print(-1)
else:
	ans[-1] = n
	print(len(ans) // 2)
	for i in range(0, len(ans), 2):
		print(ans[i], ans[i + 1])


n = int(input())
lst = list(map(int, input().split()))
(d, res, result, j) = ({}, [], 0, 1)
for (i, x) in enumerate(lst):
	if d.get(x) == None:
		d[x] = 1
	else:
		result += 1
		res.append([j, i + 1])
		j = i + 2
		d = {}
if res == [] and result == 0:
	print(-1)
	from sys import exit
	exit()
if res[result - 1][1] != n:
	res[result - 1][1] = n
print(result)
for (i, x) in enumerate(res):
	print(*x)


def longest(n, k, a):
	f = [0] * 1000001
	d = 0
	r = 0
	l = 0
	ans_l = 0
	ans_r = 0
	for r in range(0, n):
		f[a[r]] += 1
		if f[a[r]] == 1:
			d += 1
		while d > k:
			f[a[l]] -= 1
			if f[a[l]] == 0:
				d -= 1
			l += 1
		if ans_r - ans_l < r - l:
			ans_r = r
			ans_l = l
	return str(ans_l + 1) + ' ' + str(ans_r + 1)
line_1 = list(map(int, input().split()))
n = line_1[0]
k = line_1[1]
line_2 = list(map(int, input().split()))
print(longest(n, k, line_2))


R = lambda : map(int, input().split())
n = int(input())
a = list(R())
s = set()
l = 0
r = []
for i in range(0, len(a)):
	if a[i] in s:
		r.append((l + 1, i + 1))
		s = set()
		l = i + 1
	else:
		s.add(a[i])
if len(s) == 0:
	print(len(r))
	for p in r:
		print(*p)
elif len(r) > 0:
	print(len(r))
	r[len(r) - 1] = (r[len(r) - 1][0], n)
	for p in r:
		print(*p)
else:
	print(-1)


n = int(input())
d = {}
s = input()
s = s.split()
start = 0
ans = []
for i in range(n):
	if s[i] not in d:
		d[s[i]] = 1
	else:
		ans.append([start + 1, i + 1])
		start = i + 1
		d = {}
if ans == []:
	print(-1)
else:
	print(len(ans))
	for i in range(len(ans)):
		if i == len(ans) - 1:
			print(ans[i][0], n)
		else:
			print(ans[i][0], ans[i][1])


(n, k) = map(int, input().split())
l = [int(i) for i in input().split()]
maxi = 0
left = -1
right = -1
ans = 0
from collections import defaultdict
d = defaultdict(int)
st = 0
end = 0
for end in range(n):
	d[l[end]] += 1
	if d[l[end]] == 1:
		ans += 1
	while ans > k:
		d[l[st]] -= 1
		if d[l[st]] == 0:
			ans -= 1
		st += 1
	if end - st + 1 > maxi:
		maxi = end - st + 1
		left = st
		right = end
print(left + 1, right + 1)


import sys
inputNum = input()
inputTypes = input().split(' ')
map1 = set()
stack2 = []
stack3 = []
for i in range(len(inputTypes)):
	if len(map1) == 0:
		map1.add(inputTypes[i])
		stack2.append(str(i + 1))
	elif inputTypes[i] in map1:
		stack2.append(str(i + 1))
		stack3.append(' '.join(stack2))
		map1.clear()
		stack2.clear()
	else:
		map1.add(inputTypes[i])
if len(stack3) == 0:
	print(-1)
	sys.exit()
if len(map1) == 0:
	print(len(stack3))
	for x in stack3:
		print(x)
else:
	print(len(stack3))
	lastitem = str(stack3[-1].split()[-1])
	for x in stack3:
		print(x.replace(lastitem, str(len(inputTypes))))


ans = []
s = set()
l = 1
n = input()
for (i, e) in enumerate(map(int, input().split()), 1):
	if e in s:
		s = set()
		ans += [(l, i)]
		l = i + 1
	else:
		s.add(e)
if ans:
	print(len(ans))
	ans[-1] = (ans[-1][0], n)
	for (a, b) in ans:
		print(a, b)
else:
	print(-1)


n = int(input())
lis = [*map(int, input().split())]
ans = []
k = 0
s = set()
for i in range(n):
	if lis[i] in s:
		ans.append([k + 1, i + 1])
		k = i + 1
		s = set()
	else:
		s.add(lis[i])
c = len(ans)
if c == 0:
	print('-1')
else:
	print(c)
	ans[-1][1] = n
	for i in ans:
		print(*i)


import sys
n = int(input())
a = list(map(int, input().split()))
ans = []
sa = sorted(a)
cmpr = {}
for i in range(0, len(a)):
	cmpr[sa[i]] = i
cid = [0 for i in range(0, n)]
id = 1
pi = 0
for i in range(0, n):
	if cid[cmpr[a[i]]] == id:
		ans.append(i + 1)
		id += 1
		continue
	cid[cmpr[a[i]]] = id
if len(ans) == 0:
	print(-1)
else:
	ans[-1] = n
	print(len(ans))
	ans = [0] + ans
	for i in range(0, len(ans) - 1):
		print(ans[i] + 1, ans[i + 1])


count = 0
N = int(input())
A = list(map(int, input().split())) + ['-1']
D = {}
Ans = []
(a, b) = (1, 1)
for val in A:
	if val in D:
		D[val] += 1
	else:
		D[val] = 1
	if D[val] % 2 == 0:
		Ans.append([str(a), str(b)])
		a = b + 1
		D = {}
	b += 1
L = len(Ans)
if L == 0:
	print(-1)
else:
	Ans[-1][1] = str(N)
	print(L)
	for val in Ans:
		print(' '.join(val))


import sys
import math
import collections
import operator as op
from collections import deque
from math import gcd, inf, sqrt, pi, cos, sin, ceil, log2, floor, log
from bisect import bisect_right, bisect_left, bisect
from functools import reduce
from sys import stdin, stdout, setrecursionlimit
setrecursionlimit(2 ** 20)

def ncr(n, r):
	r = min(r, n - r)
	numer = reduce(op.mul, range(n, n - r, -1), 1)
	denom = reduce(op.mul, range(1, r + 1), 1)
	return numer // denom

def prime_factors(n):
	i = 2
	factors = []
	while i * i <= n:
		if n % i:
			i += 1
		else:
			n //= i
			factors.append(i)
	if n > 1:
		factors.append(n)
	return list(factors)

def isPowerOfTwo(x):
	return x and (not x & x - 1)
MOD = 1000000007
PMOD = 998244353
N = 10 ** 18 + 1
LOGN = 30
alp = 'abcdefghijklmnopqrstuvwxyz'
T = 1
for _ in range(T):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().rstrip().split()))
	d = {}
	ans = []
	l = 0
	r = 0
	while l < n and r < n:
		if a[r] not in d:
			d[a[r]] = 1
			r += 1
		else:
			d[a[r]] += 1
			if d[a[r]] == 2:
				d = {}
				ans.append([l + 1, r + 1])
				r += 1
				l = r
			else:
				r += 1
	if len(ans) == 0:
		print(-1)
	else:
		ans[len(ans) - 1][1] = n
		print(len(ans))
		for i in ans:
			print(*i)


n = int(input())
cnt = 0
gems = list(map(int, input().split()))
pearls = set()
for i in range(n):
	if gems[i] not in pearls:
		pearls.add(gems[i])
	else:
		cnt += 1
		pearls = set()
if cnt:
	print(cnt)
	first = 0
	second = 0
	pearls = set()
	for i in range(n):
		if gems[i] not in pearls:
			pearls.add(gems[i])
		else:
			if second:
				print(first + 1, second + 1)
				first = second + 1
			second = i
			pearls = set()
	print(first + 1, n)
else:
	print('-1')


n = int(input())
a = list(map(int, input().split()))
m = {}
start = 0
count = 0
x = []
y = []
for i in range(n):
	num = a[i]
	if num in m:
		count += 1
		x.append(start + 1)
		y.append(i + 1)
		start = i + 1
		m = {}
	else:
		m[num] = 1
if len(x) == 0:
	print(-1)
else:
	print(len(x))
	y[len(y) - 1] = n
	for i in range(len(x)):
		print(x[i], y[i])


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from collections import defaultdict
(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
c = defaultdict(int)
(l, longest, numbers) = (0, 0, 0)
for r in range(n):
	c[arr[r]] += 1
	if c[arr[r]] == 1:
		numbers += 1
	while numbers > k:
		c[arr[l]] -= 1
		if c[arr[l]] == 0:
			numbers -= 1
		l += 1
	if r - l + 1 > longest:
		longest = r - l + 1
		ans = (l + 1, r + 1)
print('%d %d' % ans)


n = int(input())
data = list(map(int, input().split()))
answer = []
start = 1
finish = 1
help_set = set()
for i in range(n):
	if data[i] in help_set:
		answer.append([start, finish])
		help_set = set()
		start = finish + 1
		finish += 1
	else:
		finish += 1
		help_set.add(data[i])
if len(answer) == 0:
	print(-1)
elif n == 1:
	print(1)
	print(1, 1)
else:
	answer[-1][-1] = n
	print(len(answer))
	for i in range(len(answer)):
		print(*answer[i])


n = int(input())
a = list(map(int, input().split()))
ans = []
s = set()
flag = False
l = 0
for i in range(n):
	if a[i] in s:
		ans.append([l + 1, i + 1])
		l = i + 1
		s = set()
		flag = True
	else:
		s.add(a[i])
if flag == False:
	print(-1)
else:
	print(len(ans))
	ans[len(ans) - 1][1] = n
	for i in ans:
		print(*i)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
cnt = [0] * 1000001
t = 0
left = 0
right = -1
l = 0
r = 0
while r < n:
	if cnt[a[r]] > 0:
		cnt[a[r]] += 1
		r += 1
	elif t < k:
		cnt[a[r]] = 1
		t += 1
		r += 1
	else:
		if r - l > right - left + 1:
			left = l
			right = r - 1
		cnt[a[l]] -= 1
		if cnt[a[l]] == 0:
			t -= 1
		l += 1
if r - l > right - left + 1:
	left = l
	right = r - 1
print(left + 1, right + 1)


n = int(input())
a = list(map(int, input().split()))
if len(set(a)) == n:
	print(-1)
else:
	ls = []
	b = set()
	l = 1
	b.add(a[0])
	for i in range(1, n):
		if a[i] not in b:
			b.add(a[i])
		else:
			ls.append([l, i + 1])
			l = i + 2
			b = set()
	if ls[-1][1] != n:
		ls[-1][1] = n
	print(len(ls))
	for i in range(len(ls)):
		print(*ls[i])


(n, k) = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
(l, r) = (0, 0)
hsh = [0] * 1000005
idx = [1, 1]
hsh[a[0]] = 1
(cnt, ans) = (1, -1)
while r < n - 1 and l <= r:
	if hsh[a[r + 1]] == 0 and cnt < k:
		r += 1
		hsh[a[r]] += 1
		cnt += 1
		if r - l > ans:
			idx = [l + 1, r + 1]
			ans = r - l
	elif hsh[a[r + 1]] == 0 and cnt == k:
		while cnt == k:
			if hsh[a[l]] == 1:
				cnt -= 1
				hsh[a[l]] -= 1
				l += 1
				break
			else:
				hsh[a[l]] -= 1
				l += 1
		r += 1
		hsh[a[r]] += 1
		cnt += 1
		if r - l > ans:
			idx = [l + 1, r + 1]
			ans = r - l
	elif hsh[a[r + 1]] != 0:
		r += 1
		hsh[a[r]] += 1
		if r - l > ans:
			idx = [l + 1, r + 1]
			ans = r - l
print(*idx)


n = input()
p = input()
n = n.split(' ')
k = int(n[1])
n = int(n[0])
p = p.split(' ')
p = [int(q) for q in p]
cnt = [0 for i in range(0, int(1000000.0 + 1))]
curcnt = 0
l = 0
r = -1
maxlen = -1
maxl = 0
maxr = 0
while r < n - 1 and l <= n:
	while r < n - 1 and curcnt + (cnt[p[r + 1]] == 0) <= k:
		curcnt = curcnt + (cnt[p[r + 1]] == 0)
		cnt[p[r + 1]] += 1
		r += 1
	if maxlen < r - l:
		maxlen = r - l
		maxr = r
		maxl = l
	cnt[p[l]] -= 1
	curcnt -= cnt[p[l]] == 0
	l += 1
print(str(maxl + 1) + ' ' + str(maxr + 1))


def main():
	(n, k) = map(int, input().split())
	element_count = [0] * 1000001
	count = 0
	a = list(map(int, input().split()))
	s = 0
	res = 0
	for t in range(n):
		element_count[a[t]] += 1
		if element_count[a[t]] == 1:
			count += 1
		while count > k:
			element_count[a[s]] -= 1
			if element_count[a[s]] == 0:
				count -= 1
			s += 1
		if t - s + 1 > res:
			res = t - s + 1
			l = s
			r = t
	print(l + 1, r + 1)

def __starting_point():
	main()
__starting_point()


import math
import sys
input = sys.stdin.readline
n = int(input())
l = list(map(int, input().split()))
s = set(l)
if len(s) == n:
	print(-1)
	exit()
visited = set()
start = 1
ans = []
for i in range(n):
	x = l[i]
	if x in visited:
		visited = set()
		ans.append((start, i + 1))
		start = i + 2
	else:
		visited.add(x)
if start <= n:
	st = ans[-1][0]
	en = n
	ans.pop()
	ans.append((st, en))
sys.stdout.write(str(len(ans)) + '\n')
for i in ans:
	sys.stdout.write(str(i[0]) + ' ' + str(i[1]) + '\n')


import re
import sys
exit = sys.exit
from bisect import bisect_left as bsl, bisect_right as bsr
from collections import Counter, defaultdict as ddict, deque
from functools import lru_cache
cache = lru_cache(None)
from heapq import *
from itertools import *
from math import inf
from pprint import pprint as pp
enum = enumerate
ri = lambda : int(rln())
ris = lambda : list(map(int, rfs()))
rln = sys.stdin.readline
rl = lambda : rln().rstrip('\n')
rfs = lambda : rln().split()
cat = ''.join
catn = '\n'.join
mod = 1000000007
d4 = [(0, -1), (1, 0), (0, 1), (-1, 0)]
d8 = [(-1, -1), (0, -1), (1, -1), (-1, 0), (1, 0), (-1, 1), (0, 1), (1, 1)]
(n, k) = ris()
a = ris()
beg = end = i = 0
occ = ddict(int)
for j in range(n):
	occ[a[j]] += 1
	while len(occ) > k:
		occ[a[i]] -= 1
		if occ[a[i]] == 0:
			del occ[a[i]]
		i += 1
	if end - beg < j - i:
		(beg, end) = (i, j)
print(beg + 1, end + 1)


n = int(input())
ar = list(map(int, input().split()))
s = set()
ans = []
p = 1
for i in range(len(ar)):
	if ar[i] not in s:
		s.add(ar[i])
	else:
		ans.append([p, i + 1])
		p = i + 2
		s.clear()
if len(ans) != 0 and len(s):
	ans[-1] = [ans[-1][0], len(ar)]
if len(ans):
	print(len(ans))
	for i in ans:
		print(i[0], i[1])
else:
	print(-1)


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from functools import cmp_to_key
from heapq import *
from math import gcd, factorial, floor, ceil, sqrt
from copy import deepcopy
from collections import deque
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
from types import GeneratorType

def iterative(f, stack=[]):

	def wrapped_func(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		to = f(*args, **kwargs)
		while True:
			if type(to) is GeneratorType:
				stack.append(to)
				to = next(to)
				continue
			stack.pop()
			if not stack:
				break
			to = stack[-1].send(to)
		return to
	return wrapped_func

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def testcase(t):
	for pp in range(t):
		solve(pp)

def google(p):
	print('Case #' + str(p) + ': ', end='')

def lcm(a, b):
	return a * b // gcd(a, b)

def power(x, y, p):
	y %= p - 1
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True
inf = pow(10, 20)
mod = 10 ** 9 + 7

def solve(case):
	n = int(inp())
	a = lis()
	have = {}
	ans = []
	prev = 0
	for i in range(n):
		if a[i] not in have:
			have[a[i]] = 1
		else:
			ans.append((prev, i))
			have = {}
			prev = i + 1
	if len(ans) == 0:
		print(-1)
		return
	print(len(ans))
	for i in range(len(ans)):
		if i == len(ans) - 1:
			print(ans[i][0] + 1, n)
			continue
		print(ans[i][0] + 1, ans[i][1] + 1)
testcase(1)


(n, k) = map(int, input().split())
a = [*map(int, input().split())]
from collections import defaultdict
d = defaultdict(int)
l = 0
r = 1
ans = (0, 0)
for i in a:
	d[i] += 1
	if len(d) <= k:
		ans = (l, r) if ans[1] - ans[0] < r - l else ans
	else:
		while len(d) > k:
			d[a[l]] -= 1
			if d[a[l]] == 0:
				del d[a[l]]
			l += 1
	r += 1
ans = (ans[0] + 1, ans[1])
print(*ans)


import sys
sys.setrecursionlimit(10 ** 6)

def get_array():
	return list(map(int, sys.stdin.readline().split()))

def get_ints():
	return map(int, sys.stdin.readline().split())

def input():
	return sys.stdin.readline().strip('\n')
n = int(input())
l = get_array()
n = len(l)
ans = []
(i, j) = (0, 0)
while i < n:
	s = set()
	while j < n and l[j] not in s:
		s.add(l[j])
		j += 1
	if j == n:
		break
	ans.append([i, j])
	j += 1
	i = j
if len(ans) == 0:
	print(-1)
else:
	print(len(ans))
	ans[-1][-1] = max(n - 1, ans[-1][-1])
	for i in ans:
		print(i[0] + 1, i[1] + 1)


import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))
if len(set(A)) == N:
	print(-1)
else:
	S = set()
	res = []
	lt = 1
	for i in range(N):
		if A[i] in S:
			res.append([lt, i + 1])
			S = set()
			lt = i + 2
		else:
			S.add(A[i])
	res[-1][-1] = N
	print(len(res))
	for i in range(len(res)):
		res[i] = ' '.join(map(str, res[i]))
	print('\n'.join(map(str, res)))


n = int(input())
a = list(map(int, input().split()))
used = {}
(x, y) = ([], [])
for i in range(n):
	if not used:
		used[a[i]] = 1
		x.append(i)
	elif a[i] in used and used[a[i]] == 1:
		y.append(i)
		used = {}
	else:
		used[a[i]] = used.get(a[i], 0) + 1
if not y:
	print(-1)
else:
	if len(x) > len(y):
		del x[-1]
	y[-1] = n - 1
	print(len(x))
	for i in range(len(x)):
		print(x[i] + 1, y[i] + 1)


n = int(input())
a = [int(x) for x in input().split()]
(i, j) = (0, 0)
seen = set()
segments = []
while j < n:
	if a[j] in seen:
		seen = set()
		segments.append((i + 1, j + 1))
		j += 1
		i = j
	else:
		seen.add(a[j])
		j += 1
if not segments:
	print(-1)
else:
	if i < n:
		segments[-1] = (segments[-1][0], n)
	print(len(segments))
	for s in segments:
		print(s[0], s[1])


n = int(input())
a = list(map(int, input().split()))
ans = []
(l, s) = (0, set())
for i in range(n):
	if a[i] in s:
		ans.append([l + 1, i + 1])
		l = i + 1
		s = set()
	else:
		s.add(a[i])
if not ans:
	print(-1)
else:
	ans[-1][1] = n
	print(len(ans))
	for ansi in ans:
		print(*ansi)


n = int(input())
d = {}
b = []
e = 1
a = list(map(int, input().split()))
for i in range(n):
	if a[i] in d:
		b.append([e, i + 1])
		e = i + 2
		d.clear()
	else:
		d[a[i]] = i + 1
if len(b) == 0:
	print(-1)
	exit()
print(len(b))
k = b[-1]
b[-1] = [k[0], n]
for i in b:
	print(*i)


n = int(input())
j = list(map(int, input().split()))
b = 0
e = 0
ans = []
subline = set()
while e < n:
	perl = j[e]
	if perl in subline:
		ans += [[b + 1, e + 1]]
		subline = set()
		b = e + 1
		e += 1
	else:
		subline.add(perl)
		e += 1
if len(ans) == 0:
	print(-1)
else:
	ans[-1][1] = n
	print(len(ans))
	for i in range(len(ans)):
		print(' '.join(list(map(str, ans[i]))))


from sys import stdin, stdout, exit
n = int(stdin.readline())
a = [int(i) for i in stdin.readline().split()]
ans = []
s = set()
i = 0
j = -1
while True:
	j += 1
	if j == n:
		if len(ans) != 0:
			ans[-1] = (ans[-1][0], j - 1)
		break
	if a[j] in s:
		s = set()
		ans.append((i, j))
		i = j + 1
		j = i - 1
	else:
		s.add(a[j])
if len(ans) == 0:
	print(-1)
	exit(0)
stdout.write(str(len(ans)) + '\n')
for (x, y) in ans:
	stdout.write(str(x + 1) + ' ' + str(y + 1) + '\n')


from collections import Counter
n = int(input())
a = list(map(int, input().rstrip().split()))
ans = []
l = 1
i = 1
c = Counter()
while i <= n:
	x = a[i - 1]
	if c[x] == 0:
		c[x] = 1
	else:
		ans.append([l, i])
		c = Counter()
		l = i + 1
	i += 1
if len(ans) > 0:
	ans[-1][1] = n
	print(len(ans))
	for x in ans:
		print(*x)
else:
	print(-1)


from collections import Counter, OrderedDict
from itertools import permutations as perm
from fractions import Fraction
from collections import deque
from sys import stdin
from bisect import *
from heapq import *
from math import *
g = lambda : stdin.readline().strip()
gl = lambda : g().split()
gil = lambda : [int(var) for var in gl()]
gfl = lambda : [float(var) for var in gl()]
gcl = lambda : list(g())
gbs = lambda : [int(var) for var in g()]
mod = int(1000000000.0) + 7
inf = float('inf')
(n, k) = gil()
a = gil()
f = {}
r = 0
l = 0
f[a[r]] = f.get(a[r], 0) + 1
while r + 1 < n and len(f) + (int(a[r + 1] in f) ^ 1) <= k:
	r += 1
	f[a[r]] = f.get(a[r], 0) + 1
(start, ln) = (l, r - l + 1)
while r + 1 < n:
	if f[a[l]] == 1:
		del f[a[l]]
	else:
		f[a[l]] -= 1
	l += 1
	while r + 1 < n and len(f) + (int(a[r + 1] in f) ^ 1) <= k:
		r += 1
		f[a[r]] = f.get(a[r], 0) + 1
	if r - l + 1 >= ln:
		ln = r - l + 1
		start = l
print(start + 1, start + ln)


def main():
	(n, k) = map(int, input().split())
	(l, cnt) = (list(map(int, input().split())), [0] * 1000001)
	start = end = j = m = 0
	for (i, x) in enumerate(l):
		if not cnt[x]:
			k -= 1
		cnt[x] += 1
		if k < 0:
			x = l[j]
			cnt[x] -= 1
			if not cnt[x]:
				k += 1
			j += 1
		if m < i - j:
			(m, start, end) = (i - j, j, i)
	print(start + 1, end + 1)
main()


R = lambda : map(int, input().split())
(n, k) = R()
arr = list(R())
(rl, rr) = (0, 0)
l = 0
rec = {}
for (r, v) in enumerate(arr):
	rec.setdefault(v, 0)
	rec[v] += 1
	while len(rec) > k:
		rec[arr[l]] -= 1
		if not rec[arr[l]]:
			rec.pop(arr[l])
		l += 1
	if rr - rl < r - l:
		(rl, rr) = (l, r)
print(rl + 1, rr + 1)


import sys
n = int(input())
a = list(map(int, input().split()))
b = set()
beg = 1
am = 0
aml = []
for i in range(n):
	if a[i] in b:
		aml.append([beg, i + 1])
		am += 1
		b = set()
		beg = i + 2
	else:
		b.add(a[i])
if am == 0:
	print(-1)
	sys.exit(0)
if aml[am - 1][1] != n:
	aml[am - 1][1] = n
print(am)
for i in range(am):
	print(aml[i][0], aml[i][1])


from collections import defaultdict
(n, k) = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
D = defaultdict(int)
l = 0
argmax = (0, 0)
for i in range(n):
	D[A[i]] += 1
	if len(D) > k:
		if argmax[1] - argmax[0] < i - 1 - l:
			argmax = (l, i - 1)
		while len(D) > k:
			D[A[l]] -= 1
			if D[A[l]] == 0:
				D.pop(A[l])
			l += 1
if argmax[1] - argmax[0] < n - 1 - l:
	argmax = (l, n - 1)
print(argmax[0] + 1, argmax[1] + 1)


length = int(input())
gems = input().split()
result = []
s = 0
dist = set()
pend_e = 0
pend_s = 0
for i in range(0, length):
	cur = gems[i]
	if cur not in dist:
		dist.add(cur)
	else:
		if pend_e != 0:
			result.append([pend_s, pend_e])
		pend_e = i + 1
		pend_s = s + 1
		s = i + 1
		dist.clear()
if s != 0 and pend_e != length + 1:
	result.append([pend_s, length])
if len(result) == 0:
	print(-1)
else:
	print(len(result))
for r in result:
	print(r[0], r[1])


num = int(input())
types = input().split()
if num != len(types):
	print(-1)
else:
	myseg = []
	myindex = []
	myset = set()
	mystr = []
	for i in range(num):
		if len(myseg) == 0:
			myseg.append(types[i])
			myset.add(types[i])
			mystr.append(str(i + 1))
		elif types[i] in myset:
			myseg.append(types[i])
			mystr.append(str(i + 1))
			myindex.append(mystr[0] + ' ' + mystr[1])
			myseg.clear()
			myset.clear()
			mystr.clear()
		else:
			myseg.append(types[i])
			myset.add(types[i])
	if len(myseg) != 0:
		if len(myindex) == 0:
			print(-1)
		else:
			oldstr = myindex[-1].split()
			newstr = oldstr[0] + ' ' + str(num)
			myindex[-1] = newstr
			print(len(myindex))
			for x in myindex:
				print(x)
	else:
		print(len(myindex))
		for x in myindex:
			print(x)


import os
import sys
from io import BytesIO, IOBase
from itertools import combinations_with_replacement, permutations
from collections import defaultdict
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
n = int(input())
arr = list(map(int, input().split()))
freq = defaultdict(int)
cur = arr[0]
ind = 1
freq[cur] += 1
last = 1
ans = []
while ind < n:
	freq[arr[ind]] += 1
	if freq[arr[ind]] == 2:
		ans.append([last, ind + 1])
		freq = defaultdict(int)
		if ind + 1 < n:
			ind += 1
			last = ind + 1
	else:
		ind += 1
if ans == []:
	print(-1)
else:
	ans[-1][1] = n
	print(len(ans))
	for i in ans:
		print(*i)


n = int(input())
A = [int(x) for x in input().split()]
s = {A[0]}
left = 1
segments = []
for i in range(1, n):
	if A[i] in s:
		segments.append((left, i + 1))
		left = i + 2
		s.clear()
	else:
		s.add(A[i])
if len(segments) == 0:
	print(-1)
else:
	segments[-1] = (segments[-1][0], n)
	print(len(segments))
	for (l, r) in segments:
		print(l, r)


import sys
from bisect import bisect_right as rb
from collections import deque
from queue import PriorityQueue
from math import *
input_ = lambda : sys.stdin.readline().strip('\r\n')
ii = lambda : int(input_())
il = lambda : list(map(int, input_().split()))
ilf = lambda : list(map(float, input_().split()))
ip = lambda : input_()
fi = lambda : float(input_())
ap = lambda ab, bc, cd: ab[bc].append(cd)
li = lambda : list(input_())
pr = lambda x: print(x)
prinT = lambda x: print(x)
f = lambda : sys.stdout.flush()
mod = 10 ** 9 + 7
(n, k) = il()
a = il()
b = [0 for i in range(10 ** 6 + 5)]
ans = []
l = -1
t = 0
j = 0
for i in range(n):
	if b[a[i]] == 0:
		t += 1
	b[a[i]] += 1
	if t > k:
		while t > k:
			b[a[j]] -= 1
			if b[a[j]] == 0:
				t -= 1
			j += 1
	if i - j > l:
		ans = [j + 1, i + 1]
		l = i - j
print(*ans)


import os
import sys
from io import BytesIO, IOBase

def main():
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	(ansl, ansr) = (0, 0)
	l = 0
	rec = {}
	for (r, v) in enumerate(arr):
		rec.setdefault(v, 0)
		rec[v] += 1
		while len(rec) > k:
			rec[arr[l]] -= 1
			if not rec[arr[l]]:
				rec.pop(arr[l])
			l += 1
		if ansr - ansl < r - l:
			(ansl, ansr) = (l, r)
	print(ansl + 1, ansr + 1)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


n = int(input())
l = list(map(int, input().split()))
L = []
d = {}
ost = -1
for i in range(n):
	e = d.get(l[i], -1)
	if e == -1:
		d[l[i]] = i
	elif e < ost:
		d[l[i]] = i
	else:
		L.append(i)
		ost = i
		d[l[i]] = -1
g = len(L)
if g == 0:
	print(-1)
	exit()
print(g)
p = 1
for i in range(g - 1):
	print(p, L[i] + 1)
	p = L[i] + 2
print(p, n)


n = int(input())
a = map(int, input().split())
st = 1
cnt = set()
answer = []
for (i, x) in enumerate(a):
	if x in cnt:
		en = i + 1
		answer.append([st, en])
		cnt = set()
		st = i + 2
	else:
		cnt.add(x)
if len(answer) == 0:
	print(-1)
else:
	print(len(answer))
	answer[-1][1] = n
	for x in answer:
		print(x[0], x[1])


import sys
import bisect
from bisect import bisect_left as lb
input_ = lambda : sys.stdin.readline().strip('\r\n')
from math import log
from math import gcd
from math import atan2, acos
from random import randint
sa = lambda : input_()
sb = lambda : int(input_())
sc = lambda : input_().split()
sd = lambda : list(map(int, input_().split()))
se = lambda : float(input_())
sf = lambda : list(input_())
flsh = lambda : sys.stdout.flush()
mod = 10 ** 9 + 7
gp = []
cost = []
dp = []
mx = []
ans1 = []
ans2 = []
special = []
specnode = []
a = 0
kthpar = []

def dfs(root, par):
	if par != -1:
		dp[root] = dp[par] + 1
	for i in range(1, 20):
		if kthpar[root][i - 1] != -1:
			kthpar[root][i] = kthpar[kthpar[root][i - 1]][i - 1]
	for child in gp[root]:
		if child == par:
			continue
		kthpar[child][0] = root
		dfs(child, root)

def hnbhai():
	(n, k) = sd()
	a = sd()
	f = [0] * (10 ** 6 + 1)
	ans = [n] * n
	i = 0
	l = 0
	d = 0
	up = -1
	while i < n:
		if i != up:
			f[a[i]] += 1
			if f[a[i]] == 1:
				d += 1
		up = i
		if d > k:
			ans[l] = i
			f[a[l]] -= 1
			if f[a[l]] == 0:
				d -= 1
			l += 1
			continue
		i += 1
	(l, r) = (0, 0)
	abe = 0
	for i in range(n):
		if ans[i] - i > abe:
			l = i + 1
			r = ans[i]
			abe = ans[i] - i
	print(l, r)
for _ in range(1):
	hnbhai()


import sys
(n, k) = map(int, input().split())
hash = [0] * 1000001
now = 0
a = list(map(int, input().split()))
ans = 0
l = 0
for r in range(n):
	hash[a[r]] += 1
	if hash[a[r]] == 1:
		now += 1
	while now > k:
		hash[a[l]] -= 1
		if hash[a[l]] == 0:
			now -= 1
		l += 1
	if r - l + 1 > ans:
		al = l
		ar = r
		ans = r - l + 1
print(al + 1, ar + 1)


import sys
n = int(sys.stdin.readline())
arr = [int(x) for x in input().split()]
sets = set()
result = []
ans = 0
l = 0
r = 0
for i in arr:
	if i in sets:
		ans = ans + 1
		sets.clear()
		result.append([l + 1, r + 1])
		l = r + 1
	else:
		sets.add(i)
	r = r + 1
if ans == 0:
	print(-1)
else:
	result[len(result) - 1] = [result[len(result) - 1][0], n]
	print(ans)
	print('\n'.join(('{0} {1}'.format(p, q) for (p, q) in result)))


pearl_count = int(input())
pearls = [int(pearl) for pearl in input().split()]
recorded = set()
intervals = []
begin = 1
for i in range(pearl_count):
	if pearls[i] in recorded:
		intervals.append([begin, i + 1])
		recorded = set()
		begin = i + 2
	else:
		recorded.add(pearls[i])
if intervals:
	intervals[-1][-1] = pearl_count
	print(len(intervals))
	[print(' '.join(map(str, interval))) for interval in intervals]
else:
	print(-1)