There are n pearls in a row. Let's enumerate them with integers from 1 to n from the left to the right. The pearl number i has the type a_{i}.

Let's call a sequence of consecutive pearls a segment. Let's call a segment good if it contains two pearls of the same type.

Split the row of the pearls to the maximal number of good segments. Note that each pearl should appear in exactly one segment of the partition.

As 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 integer n (1 ≤ n ≤ 3·10^5) — the number of pearls in a row.

The second line contains n integers a_{i} (1 ≤ a_{i} ≤ 10^9) – the type of the i-th pearl.


-----Output-----

On the first line print integer k — the maximal number of segments in a partition of the row.

Each of the next k lines should contain two integers l_{j}, r_{j} (1 ≤ l_{j} ≤ r_{j} ≤ n) — the number of the leftmost and the rightmost pearls in the j-th segment.

Note you should print the correct partition of the row of the pearls, so each pearl should be in exactly one segment and all segments should contain two pearls of the same type.

If there are several optimal solutions print any of them. You can print the segments in any order.

If there are no correct partitions of the row print the number "-1".


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

Output
1
1 5

Input
5
1 2 3 4 5

Output
-1

Input
7
1 2 1 3 1 2 1

Output
2
1 3
4 7

Difficulty: MEDIUM
Tags: Greedy algorithms
Skill types: Greedy algorithms

Starter code:

Solutions:
n = int(input())
li = list(map(int, input().split()))
s = set()
ans = []
l = 0
r = -1
for i in range(n):
	if li[i] in s:
		ans.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(ans))
	ans[len(ans) - 1][1] = n
	for i in ans:
		print(*i)


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)


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 = ii()
a = il()
d = {}
ans = []
l = 1
for i in range(n):
	if d.get(a[i]):
		ans.append([l, i + 1])
		l = i + 2
		d.clear()
	else:
		d[a[i]] = True
if ans == []:
	print(-1)
	exit(0)
ans[-1] = [ans[-1][0], n]
print(len(ans))
for i in ans:
	print(*i)


n = int(input())
a = list(map(int, input().split(' ')))
ans = []
s = 0
mark = set([a[0]])
for i in range(1, n):
	if a[i] in mark:
		mark = set()
		ans.append([s + 1, i + 1])
		s = i + 1
	else:
		mark.add(a[i])
if len(ans) == 0:
	print(-1)
else:
	ans[-1][1] = n
	print(len(ans))
	for line in ans:
		print(line[0], line[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) + ' ')


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)
	return
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()


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 = 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')


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 = ii()
a = li()
seen = set()
start = 0
end = 0
res = list()
while end < n:
	if a[end] in seen:
		res.append([start + 1, end + 1])
		start = end + 1
		seen = set()
	else:
		seen.add(a[end])
	end += 1
if len(res) == 0:
	print(-1)
else:
	if start < n:
		(x, y) = res.pop()
		res.append([x, n])
	print(len(res))
	for i in range(len(res)):
		print_list(res[i])


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])


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])


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)


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)


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)


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')


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)

def __starting_point():
	main()
__starting_point()


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'))


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)
	return
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])


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)


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')


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)


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')


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)


from collections import defaultdict as dd
from sys import stdin
n = int(stdin.readline())
a = list(map(int, stdin.readline().split()))
res = list()
encntrd = dd(lambda : 0)
curst = 0
for i in range(n):
	if encntrd[a[i]]:
		res.append((curst + 1, i + 1))
		curst = i + 1
		encntrd = dd(lambda : 0)
	else:
		encntrd[a[i]] = 1
if curst == 0:
	print(-1)
else:
	res[-1] = (res[-1][0], n)
	print(len(res))
	for ele in res:
		print(ele[0], ele[1])


n = int(input())
l = list(map(int, input().split()))
a = []
s = set()
x = 1
for i in range(1, n + 1):
	if l[i - 1] not in s:
		s.add(l[i - 1])
	else:
		a.append([x, i])
		x = i + 1
		s.clear()
if a:
	a[-1][-1] = n
	print(len(a))
	for i in a:
		print(*i)
else:
	print(-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 = sb()
	a = sd()
	d = {}
	ans = []
	l = 1
	for i in range(n):
		if d.get(a[i]):
			ans.append([l, i + 1])
			l = i + 2
			d = {}
		else:
			d[a[i]] = 1
	if len(ans) == 0:
		print(-1)
		return
	ans[-1] = [ans[-1][0], n]
	print(len(ans))
	for i in ans:
		print(*i)
for _ in range(1):
	hnbhai()


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)


3
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)))


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)))


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 = 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())
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)))


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]))))


n = int(input())
data = list(map(int, input().split()))
a = 0
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)
else:
	answer[-1][-1] = n
	print(len(answer))
	for i in range(len(answer)):
		print(*answer[i])


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])


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


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])


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())
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)


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)


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())
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')


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 = ri()
a = ris()
ans = []
seen = set()
i = 0
for (j, x) in enum(a):
	if x not in seen:
		seen.add(x)
	else:
		ans.append([i, j])
		seen.clear()
		i = j + 1
if not ans:
	print(-1)
else:
	ans[-1][1] = n - 1
	print(len(ans))
	for (i, j) in ans:
		print(i + 1, j + 1)


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())
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])


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)


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)