Amr has got a large array of size n. Amr doesn't like large arrays so he intends to make it smaller.

Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subsegment of this array such that the beauty of it will be the same as the original array.

Help Amr by choosing the smallest subsegment possible.


-----Input-----

The first line contains one number n (1 ≤ n ≤ 10^5), the size of the array.

The second line contains n integers a_{i} (1 ≤ a_{i} ≤ 10^6), representing elements of the array.


-----Output-----

Output two integers l, r (1 ≤ l ≤ r ≤ n), the beginning and the end of the subsegment chosen respectively.

If there are several possible answers you may output any of them. 


-----Examples-----
Input
5
1 1 2 2 1

Output
1 5
Input
5
1 2 2 3 1

Output
2 3
Input
6
1 2 2 1 1 2

Output
1 5


-----Note-----

A subsegment B of an array A from l to r is an array of size r - l + 1 where B_{i} = A_{l} + i - 1 for all 1 ≤ i ≤ r - l + 1

Source: codeforces | Difficulty: EASY
Tags: Implementation


Solutions:
import math, string, itertools, fractions, heapq, collections, re, array, bisect, copy
from itertools import chain, dropwhile, permutations, combinations
from collections import defaultdict, deque

def VI():
	return list(map(int, input().split()))

def I():
	return int(input())

def LIST(n, m=None):
	return [0] * n if m is None else [[0] * m for i in range(n)]

def ELIST(n):
	return [[] for i in range(n)]

def MI(n=None, m=None):
	if n is None:
		(n, m) = VI()
	arr = LIST(n)
	for i in range(n):
		arr[i] = VI()
	return arr

def MS(n=None, m=None):
	if n is None:
		(n, m) = VI()
	arr = LIST(n)
	for i in range(n):
		arr[i] = input()
	return arr

def MIT(n=None, m=None):
	if n is None:
		(n, m) = VI()
	a = MI(n, m)
	arr = LIST(m, n)
	for (i, l) in enumerate(a):
		for (j, x) in enumerate(l):
			arr[j][i] = x
	return arr

def run(n, x, l, r):
	s = 0
	curr = 1
	for i in range(n):
		skip = (l[i] - curr) // x
		s += r[i] - curr - skip * x + 1
		curr = r[i] + 1
	print(s)

def main(info=0):
	n = I()
	a = VI()
	d = {}
	for (i, x) in enumerate(a):
		if x in d:
			(l, r, num) = d[x]
			d[x] = (l, i, num + 1)
		else:
			d[x] = (i, i, 1)
	best = (0, 10000000.0)
	bestv = None
	for (k, v) in d.items():
		(l, r, num) = v
		dist = r - l + 1
		if (num, -dist) > best:
			best = (num, -dist)
			bestv = v
	print(bestv[0] + 1, bestv[1] + 1)
main()


from collections import Counter, defaultdict
n = int(input())
a = list(map(int, input().split()))
d = Counter(a)
MAX = -float('inf')
for i in d.keys():
	MAX = max(d[i], MAX)
M = float('inf')
ind = defaultdict(list)
for i in range(n):
	if d[a[i]] == MAX:
		ind[a[i]].append(i)
for i in ind.keys():
	if ind[i][-1] - ind[i][0] < M:
		M = ind[i][-1] - ind[i][0]
		l = ind[i][0]
		r = ind[i][-1]
print(l + 1, r + 1)


from sys import stdin
n = int(stdin.readline())
ai = list(map(int, stdin.readline().split()))
d = {}
vmax = 0
for i in range(0, n):
	if ai[i] not in d:
		d[ai[i]] = list([i])
	else:
		d[ai[i]].append(i)
vmax = 0
l = 0
r = 0
k = []
for i in d.keys():
	c = len(d[i])
	if c > vmax:
		vmax = c
		k = d[i]
	elif c == vmax:
		if d[i][c - 1] - d[i][0] < k[len(k) - 1] - k[0]:
			k = d[i]
	l = k[0]
	r = k[len(k) - 1]
print(str(l + 1) + ' ' + str(r + 1))


counter = dict()
max_num = (0, 0)
n = int(input())
A = list(map(int, input().split()))
for i in range(len(A)):
	if A[i] in counter:
		counter[A[i]][0] += 1
		counter[A[i]][2] = i
	else:
		counter[A[i]] = [1, i, i]
(count, l, r) = max(list(counter.values()), key=lambda x: (x[0], -(x[2] - x[1]), -x[1]))
print(l + 1, r + 1)


n = int(input())
numbers = [int(number) for number in input().split()]
occurences = {}
for i in range(n):
	number = numbers[i]
	if number in occurences.keys():
		occurences[number][0] += 1
		occurences[number][2] = i + 1
	else:
		occurences[number] = [1, i + 1, -1]
result = [-1, -1, -1]
for number in occurences.keys():
	if occurences[number][2] == -1:
		occurences[number][2] = occurences[number][1]
	if occurences[number][0] > result[0]:
		result = occurences[number][:]
	elif occurences[number][0] == result[0]:
		r1 = occurences[number][2] - occurences[number][1]
		r2 = result[2] - result[1]
		if r2 > r1:
			result = occurences[number][:]
print(result[1], result[2])


import collections
n = int(input())
As = list(map(int, input().split()))

def solve(n, As):
	counter = collections.Counter(As)
	candidates = []
	prev_freq = 0
	for (num, freq) in counter.most_common():
		if prev_freq and prev_freq != freq:
			break
		candidates.append(num)
		prev_freq = freq
	lr = {cand: [] for cand in candidates}
	for (i, a) in enumerate(As, 1):
		if a in lr:
			lr[a].append(i)
	minspan = float('inf')
	for pos in lr.values():
		if pos[-1] - pos[0] < minspan:
			minspan = pos[-1] - pos[0]
			LR = (pos[0], pos[-1])
	return LR
print(*solve(n, As))


n = int(input())
l = list(map(int, input().split()))
f = {}
for i in l:
	try:
		f[i] += 1
	except:
		f[i] = 1
t = max(f.values())
ff = {}
for i in range(n):
	if f[l[i]] == t:
		try:
			ff[l[i]][1] = i
		except:
			ff[l[i]] = [i, 0]
ans = 10 ** 9 + 8
for i in ff.values():
	if abs(i[0] - i[1]) + 1 < ans:
		ans = abs(i[0] - i[1]) + 1
		s = i
print(s[0] + 1, s[1] + 1)


from collections import Counter
n = int(input())
l = list(map(int, input().split()))
d = Counter(l)
ma = 0
for t in d:
	ma = max(ma, d[t])
q = {}
for t in l:
	if d[t] == ma:
		q[t] = 1
occ = {}
vis = [0 for t in range(max(l) + 1)]
for i in range(n):
	if l[i] in q:
		if vis[l[i]] == 0:
			occ[l[i]] = [i, i]
			vis[l[i]] = 1
		else:
			occ[l[i]][1] = i
(a, b) = (0, 0)
cur = 2e+18
for t in occ:
	dis = occ[t][1] - occ[t][0]
	if dis < cur:
		cur = dis
		a = occ[t][0]
		b = occ[t][1]
print(a + 1, b + 1)


n = int(input())
a = [int(x) for x in input().split()]
cur = 0
d = [[0, -1, -1]] * (max(a) + 1)
for i in range(n):
	if d[a[i]][1] == -1:
		d[a[i]] = [1, i, i]
	else:
		d[a[i]][0] += 1
		d[a[i]][2] = i
maxcnt = max(d, key=lambda x: x[0])[0]
cur = 10000000001
for i in d:
	if i[0] == maxcnt and i[2] - i[1] < cur:
		cur = i[2] - i[1]
		fin = [i[1] + 1, i[2] + 1]
print(fin[0], fin[1])


n = int(input())
a = [int(x) for x in input().split()]
count = [0] * (1000000 + 1)
left = [0] * 1000001
right = [0] * 1000001
for i in range(n):
	count[a[i]] += 1
	if left[a[i]] == 0:
		left[a[i]] = i + 1
for i in range(n - 1, -1, -1):
	if right[a[i]] == 0:
		right[a[i]] = i + 1
m = 0
mi = 0
for i in range(1, 1000001):
	if count[i] > m:
		m = count[i]
		mi = i
	elif count[i] == m:
		if right[i] - left[i] < right[mi] - left[mi]:
			m = count[i]
			mi = i
print(left[mi], right[mi])


n = int(input())
arr = list(map(int, input().split()))
cnt = {}
for i in range(n):
	if arr[i] not in cnt:
		cnt[arr[i]] = [0, i, i]
	cnt[arr[i]][0] += 1
	cnt[arr[i]][2] = i
res = [0, 0, 0]
for (c, i, j) in cnt.values():
	if c > res[0] or (c == res[0] and j - i < res[2] - res[1]):
		res = [c, i, j]
print(res[1] + 1, res[2] + 1)


def solve():
	d1 = {}
	d2 = {}
	input()
	l = list(map(int, input().split()))
	for (idx, i) in enumerate(l):
		if i not in d1:
			d1[i] = [1, idx, idx]
		else:
			d1[i][0] += 1
			d1[i][2] = idx
	for (k, v) in d1.items():
		if v[0] in d2:
			d2[v[0]].append(k)
		else:
			d2[v[0]] = [k]
	sd2 = sorted(d2.items(), reverse=True)
	v = sd2[0][1]
	if len(v) == 1:
		print(d1[v[0]][1] + 1, d1[v[0]][2] + 1)
	else:
		shortestDistance = 10 ** 5
		leftIndex = -1
		rightIndex = -1
		for elem in v:
			if d1[elem][2] - d1[elem][1] < shortestDistance:
				shortestDistance = d1[elem][2] - d1[elem][1]
				leftIndex = d1[elem][1]
				rightIndex = d1[elem][2]
		print(leftIndex + 1, rightIndex + 1)
solve()


def main():
	n = int(input())
	a = [int(x) for x in input().split()]
	counts = {}
	left = {}
	right = {}
	maxc = 0
	maxn = -1
	for i in range(n):
		if a[i] in counts:
			counts[a[i]] += 1
			right[a[i]] = i
			if counts[a[i]] > maxc:
				maxc = counts[a[i]]
				maxn = a[i]
			elif counts[a[i]] == maxc and right[maxn] - left[maxn] > right[a[i]] - left[a[i]]:
				maxc = counts[a[i]]
				maxn = a[i]
		else:
			counts[a[i]] = 1
			left[a[i]] = i
			right[a[i]] = i
			if maxc < 1:
				maxc = counts[a[i]]
				maxn = a[i]
	print(left[maxn] + 1, right[maxn] + 1)
main()


import sys

def fastio():
	from io import StringIO
	from atexit import register
	global input
	sys.stdin = StringIO(sys.stdin.read())
	input = lambda : sys.stdin.readline().rstrip('\r\n')
	sys.stdout = StringIO()
	register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))
fastio()

def debug(*var, sep=' ', end='\n'):
	print(*var, file=sys.stderr, end=end, sep=sep)
INF = 10 ** 20
MOD = 10 ** 9 + 7
I = lambda : list(map(int, input().split()))
from math import gcd
from math import ceil
from collections import defaultdict as dd, Counter
from bisect import bisect_left as bl, bisect_right as br
(n,) = I()
a = I()
ans = INF
res = [1, 1]
m = 0
d = dd(list)
cnt = dd(int)
for i in range(n):
	cnt[a[i]] += 1
	m = max(cnt[a[i]], m)
	if d[a[i]]:
		d[a[i]][-1] = i + 1
	else:
		d[a[i]] = [i + 1, i + 1]
for i in d:
	cur = d[i][-1] - d[i][0] + 1
	if cnt[i] == m and cur < ans:
		ans = cur
		res = d[i]
print(*res)


import collections

def findsubsegment(l, nums):
	freq_map = collections.Counter(nums)
	beauty = max(freq_map.items(), key=lambda x: x[1])[1]
	keys = {}
	if beauty == 1:
		print('1 1')
		return
	for (key, val) in freq_map.items():
		if val == beauty:
			keys[key] = [l, -1]
	for (i, num) in enumerate(nums):
		if num in keys:
			if i < keys[num][0]:
				keys[num][0] = i
			keys[num][1] = i
	min_val = l
	min_range = [1, l]
	for (key, ranges) in keys.items():
		if ranges[1] - ranges[0] < min_val:
			min_val = ranges[1] - ranges[0]
			min_range = [ranges[0] + 1, ranges[1] + 1]
	print(str(min_range[0]) + ' ' + str(min_range[1]))
l = int(input())
nums = [int(x) for x in input().split(' ')]
findsubsegment(l, nums)


def bin_search(n, a):
	l = 0
	r = len(a) - 1
	while l <= r:
		m = (l + r) // 2
		if n > a[m][0]:
			l = m + 1
		if n < a[m][0]:
			r = m - 1
		if n == a[m][0]:
			return m
	return -1
n = int(input())
a = input().split()

def ke(n):
	return n[1]

def f(n):
	return abs(n[2] - n[3])
cnt = {}
mx = 0
for i in range(n):
	a[i] = int(a[i])
	if a[i] in cnt:
		cnt[a[i]][1] += 1
		cnt[a[i]][3] = i
	else:
		cnt[a[i]] = [a[i], 1, i, 0]
for m in list(cnt.values()):
	if m[1] > mx:
		mx = m[1]
v = []
for m in list(cnt.values()):
	if m[1] == mx:
		v.append(m)
v.sort(key=f)
print(v[0][2] + 1, v[0][3] + 1)


n = int(input())
arr = list(map(int, input().split()))
d = {}
for i in range(n):
	if arr[i] not in d:
		d[arr[i]] = (i, i, 1)
	else:
		x = d[arr[i]]
		y = (x[0], i, x[2] + 1)
		d[arr[i]] = y
p = 10 ** 20
r = 0
for i in d:
	m = d[i]
	if m[2] > r:
		r = m[2]
		p = m[1] - m[0]
		q = (m[0], m[1])
	elif m[2] == r and m[1] - m[0] < p:
		r = m[2]
		p = m[1] - m[0]
		q = (m[0], m[1])
print(q[0] + 1, q[1] + 1)


input()
d = {}
for (x, y) in enumerate(map(int, input().split())):
	(c, u, l) = d.get(y, (0, 0, x))
	d[y] = (c + 1, l - x, l)
(_, s, t) = max(d.values())
print(t + 1, t - s + 1)


n = int(input())
l = []
l = list(map(int, input().split()))
fr = [0] * 1000005
a = [0] * 1000005
b = [0] * 1000005
for i in range(n):
	fr[l[i]] = fr[l[i]] + 1
	if a[l[i]] == 0:
		a[l[i]] = i + 1
	b[l[i]] = i + 1
max1 = 0
min1 = 10000005
x = int()
y = int()
for i in range(1000001):
	if fr[i] > max1:
		max1 = fr[i]
		x = a[i]
		y = b[i]
		min1 = y - x + 1
	elif fr[i] == max1:
		x1 = a[i]
		y1 = b[i]
		if y1 - x1 + 1 < min1:
			min1 = y1 - x1 + 1
			x = x1
			y = y1
print(x, y, sep=' ')


import sys
input = lambda : sys.stdin.readline()
MOD = 1000000007
ii = lambda : int(input())
si = lambda : input()
dgl = lambda : list(map(int, input()))
f = lambda : list(map(int, input().split()))
il = lambda : list(map(int, input().split()))
ls = lambda : list(input())
n = ii()
l = il()
d = dict()
s1 = set()
s2 = set()
for i in l:
	d[i] = d.get(i, 0) + 1
mx = max((d[i] for i in d))
for i in d:
	if d[i] == mx:
		s1.add(i)
		s2.add(i)
d = dict()
for i in range(n):
	if len(s1) == 0:
		break
	if l[i] in s1:
		d[l[i]] = [i]
		s1.discard(l[i])
mn = 10 ** 12
for i in range(n - 1, -1, -1):
	if len(s2) == 0:
		break
	if l[i] in s2:
		mn = min(i - d[l[i]][0], mn)
		d[l[i]].append(i)
		s2.discard(l[i])
for i in d:
	if d[i][1] - d[i][0] == mn:
		print(d[i][0] + 1, d[i][1] + 1)
		break


n = int(input())
(nums, d, mx) = ([], dict(), 0)
for (i, e) in enumerate(input().split()):
	cur = d.setdefault(int(e), [0, i, i])
	cur[0] += 1
	cur[2] = i
	d[int(e)] = cur
	mx = max(mx, d[int(e)][0])
(l, r) = (0, 100000)
for i in d.keys():
	if d[i][0] == mx:
		if d[i][2] - d[i][1] < r - l:
			(r, l) = (d[i][2], d[i][1])
print(l + 1, r + 1)


N = int(input())
a = [int(i) for i in input().split()]
d = {}
b = {}
for (i, f) in enumerate(a):
	if f not in d:
		d[f] = 0
		b[f] = [i, i]
	d[f] += 1
	b[f][1] = i
mn = max(d.values())
m = [0, N]
for k in d.keys():
	if d[k] != mn:
		continue
	if b[k][1] - b[k][0] < m[1] - m[0]:
		m = b[k]
print(m[0] + 1, m[1] + 1)


def cmp_to_key(mycmp):

	class K:

		def __init__(self, obj, *args):
			self.obj = obj

		def __lt__(self, other):
			return mycmp(self.obj, other.obj) < 0

		def __gt__(self, other):
			return mycmp(self.obj, other.obj) > 0

		def __eq__(self, other):
			return mycmp(self.obj, other.obj) == 0

		def __le__(self, other):
			return mycmp(self.obj, other.obj) <= 0

		def __ge__(self, other):
			return mycmp(self.obj, other.obj) >= 0

		def __ne__(self, other):
			return mycmp(self.obj, other.obj) != 0
	return K

def compare(x, y):
	if x[2] != y[2]:
		return y[2] - x[2]
	return x[1] - x[0] - (y[1] - y[0])

def main():
	n = int(input())
	d = list(map(int, input().split()))
	r = {}
	for i in range(n):
		if d[i] in r:
			r[d[i]] = [r[d[i]][0], i + 1, r[d[i]][2] + 1]
		else:
			r[d[i]] = [i + 1, i + 1, 1]
	sr = sorted(r.values(), key=cmp_to_key(compare))
	print(sr[0][0], sr[0][1])
main()


N = 1000001
l = [0] * N
r = [0] * N
num = [0] * N
n = int(input())
i = 1
for x in input().split():
	x = int(x)
	if num[x] == 0:
		l[x] = i
	r[x] = i
	num[x] = num[x] + 1
	i = i + 1
ansn = 0
for i in range(N):
	ansn = max(ansn, num[i])
ansl = 0
ansr = n
for i in range(N):
	if num[i] == ansn:
		if ansr - ansl > r[i] - l[i]:
			ansr = r[i]
			ansl = l[i]
print(ansl, ansr)


n = int(input())
al = input().split(' ')
d = {}
for i in range(n):
	j = al[i]
	if j not in d:
		d[j] = [1, i, i]
	else:
		d[j][0] += 1
		d[j][2] = i
m = max([i[0] for i in d.values()])
l = float('inf')
for i in d:
	if d[i][0] == m:
		if d[i][2] - d[i][1] < l:
			ans = d[i]
			l = d[i][2] - d[i][1]
print(ans[1] + 1, ans[2] + 1)


import sys
N = int(input())
A = list(map(int, input().split(' ')))
left_idx = {}
right_idx = {}
count = {}
for (i, e) in enumerate(A):
	if e not in count:
		count[e] = 0
	count[e] += 1
	if e not in left_idx:
		left_idx[e] = i
	if i < left_idx[e]:
		left_idx[e] = i
	if e not in right_idx:
		right_idx[e] = i
	if right_idx[e] < i:
		right_idx[e] = i
max_count = max((count[c] for c in count))
items_with_mc = [i for i in count if count[i] == max_count]
span_i = [(right_idx[i] - left_idx[i], i) for i in items_with_mc]
iwms = min(span_i)[1]
print(left_idx[iwms] + 1, right_idx[iwms] + 1)


n = int(input())
a = list(map(int, input().split()))
c = set()
b = dict()
left = dict()
right = dict()
for i in range(n):
	if a[i] not in c:
		c.add(a[i])
		b[str(a[i])] = 1
		left[str(a[i])] = i + 1
		right[str(a[i])] = i + 1
	else:
		b[str(a[i])] += 1
		right[str(a[i])] = i + 1
d = 0
for x in c:
	if b[str(x)] > d:
		f = []
		d = b[str(x)]
		f.append(x)
	elif b[str(x)] == d:
		f.append(x)
l1 = left[str(f[0])]
r1 = right[str(f[0])]
g = r1 - l1 + 1
if g == d:
	print(l1, r1)
	exit()
for j in range(1, len(f)):
	l = left[str(f[j])]
	r = right[str(f[j])]
	if r - l + 1 < g:
		g = r - l + 1
		l1 = l
		r1 = r
	if g == d:
		print(l, r)
		exit()
print(l1, r1)


n = int(input())
a = list(map(int, input().split()))
b = [0] * 1000001
visited = [False] * 1000001
l = [0] * 1000001
r = [0] * 1000001
max_b = 0
for i in a:
	b[i] += 1
	if b[i] > max_b:
		max_b = b[i]
for i in range(n):
	if b[a[i]] == max_b and (not visited[a[i]]):
		l[a[i]] = i
	visited[a[i]] = True
visited = [False] * 1000001
min_d = n + 1
min_l = 0
min_r = n
for i in range(n - 1, -1, -1):
	if b[a[i]] == max_b and (not visited[a[i]]):
		r[a[i]] = i
		if r[a[i]] - l[a[i]] + 1 < min_d:
			min_l = l[a[i]]
			min_r = r[a[i]]
			min_d = r[a[i]] - l[a[i]] + 1
	visited[a[i]] = True
print(min_l + 1, min_r + 1)


n = int(input())
a = [int(x) for x in input().split()]
d = {}
mosttimes = 0
for i in range(len(a)):
	x = a[i]
	if x in d:
		d[x][0] += 1
		d[x][2] = i
		if d[x][0] > mosttimes:
			mosttimes = d[x][0]
	else:
		d[x] = [1, i, i]
		if mosttimes == 0:
			mosttimes = 1
answerl = 0
answerr = 0
difference = float('inf')
for x in d:
	if d[x][0] == mosttimes:
		if d[x][2] - d[x][1] < difference:
			difference = d[x][2] - d[x][1]
			answerl = d[x][1]
			answerr = d[x][2]
print(str(answerl + 1) + ' ' + str(answerr + 1))


n = input()
num = list(map(int, input().split()))
arr = {}
for i in range(len(num)):
	if num[i] in arr:
		arr[num[i]][2] = i
		arr[num[i]][0] += 1
	else:
		arr[num[i]] = [1, i, i]
mxk = num[0]
for key in arr:
	if arr[mxk][0] < arr[key][0]:
		mxk = key
	elif arr[mxk][0] == arr[key][0] and arr[mxk][2] - arr[mxk][1] > arr[key][2] - arr[key][1]:
		mxk = key
print(arr[mxk][1] + 1, arr[mxk][2] + 1)


from collections import defaultdict
_ = input()
nums = list(map(int, input().split()))
freqs = defaultdict(list)
_max = -1
for (i, k) in enumerate(nums):
	freqs[k].append(i + 1)
	_max = max(_max, len(freqs[k]))
start = 1
end = len(nums)
length = end - start
for (k, v) in freqs.items():
	if len(v) == _max:
		if v[-1] - v[0] < length:
			start = v[0]
			end = v[-1]
			length = end - start
print(start, end)


N = int(input())
A = [int(x) for x in input().split()]
bucket = dict()
for (i, num) in enumerate(A):
	if num in bucket:
		bucket[num].append(i)
	else:
		bucket[num] = [i]
sorted_buckets = sorted(((-len(val), val[-1] - val[0], val) for (_, val) in bucket.items()))
print(sorted_buckets[0][2][0] + 1, sorted_buckets[0][2][-1] + 1)


n = int(input())
a = list(map(int, input().split()))
d = dict()
for (i, e) in enumerate(a):
	if e in d:
		(c, l, r) = d[e]
		d[e] = (c + 1, l, i)
	else:
		d[e] = (1, i, i)
(ans_c, ans_l, ans_r) = (0, 0, n - 1)
for (c, l, r) in d.values():
	if c > ans_c or (c == ans_c and r - l < ans_r - ans_l):
		(ans_c, ans_l, ans_r) = (c, l, r)
print(ans_l + 1, ans_r + 1)


n = int(input())
mas = list(map(int, input().split(' ')))
dic = {i: [0, -1, -1] for i in set(mas)}
ma = 0
for i in range(n):
	if dic[mas[i]][1] == -1:
		dic[mas[i]][1] = i
	dic[mas[i]][0] += 1
	dic[mas[i]][2] = i
	if dic[mas[i]][0] > ma:
		ma = dic[mas[i]][0]
mi = 9999999999
a = 0
b = 0
for i in range(n):
	if dic[mas[i]][0] == ma and dic[mas[i]][2] - dic[mas[i]][1] < mi:
		a = dic[mas[i]][1]
		b = dic[mas[i]][2]
		mi = b - a
print(a + 1, b + 1)


n = int(input())
arr = tuple(map(int, input().split()))
d = {}
for i in arr:
	if i in d:
		d[i] += 1
	else:
		d[i] = 1
big = 0
for i in d:
	if d[i] > big:
		big = d[i]
		s = {i}
	elif d[i] == big:
		s.add(i)
small = {}
large = {}
for i in range(n):
	if arr[i] not in small:
		small[arr[i]] = i
for i in range(n - 1, -1, -1):
	if arr[i] not in large:
		large[arr[i]] = i
best = n + 1
for i in s:
	j = small[i]
	k = large[i]
	if k - j + 1 < best:
		best = k - j + 1
		ans = (j + 1, k + 1)
print(*ans)


from collections import Counter
n = int(input())
a = list(map(int, input().split()))
start = dict([])
end = dict([])
all = []
count = Counter(a)
maxx = max(list(count.values()))
for j in count:
	if count[j] == maxx:
		all.append(j)
for i in range(n):
	if a[i] not in start:
		start[a[i]] = i + 1
		end[a[i]] = i + 1
	else:
		end[a[i]] = i + 1
minn = 100000000
ele = 0
for k in all:
	if end[k] - start[k] < minn:
		minn = end[k] - start[k]
		ele = k
print(start[ele], end[ele])


n = int(input())
l = list(map(int, input().split()))
d = dict()
max1 = 0
q = 0
for i in range(n):
	d.setdefault(l[i], [0, 0, 0])
	if d[l[i]][0] == 0:
		d[l[i]][1] = i + 1
	d[l[i]][2] = i + 1
	d[l[i]][0] += 1
	if d[l[i]][0] >= max1:
		if max1 == d[l[i]][0]:
			if d[q][2] - d[q][1] > d[l[i]][2] - d[l[i]][1]:
				max1 = d[l[i]][0]
				q = l[i]
		else:
			max1 = d[l[i]][0]
			q = l[i]
print(d[q][1], d[q][2])


from sys import stdin

def main():
	n = int(stdin.readline())
	ar = list(map(int, stdin.readline().split()))
	c = [0] * (10 ** 6 + 1)
	mf = 0
	for elm in ar:
		c[elm] += 1
		if c[elm] > mf:
			mf = c[elm]
	start = 0
	end = 0
	lk = [0] * (10 ** 6 + 1)
	f = [0] * (n + 1)
	f[0] = n
	cf = 0
	ml = n + 1
	il = -1
	ir = -1
	while end < n:
		while end < n and cf < mf:
			f[lk[ar[end]]] -= 1
			lk[ar[end]] += 1
			f[lk[ar[end]]] += 1
			if lk[ar[end]] > cf:
				cf = lk[ar[end]]
			end += 1
		if cf == mf:
			if end - start < ml:
				ml = end - start
				il = start + 1
				ir = end
		while start < end and cf == mf:
			f[lk[ar[start]]] -= 1
			lk[ar[start]] -= 1
			f[lk[ar[start]]] += 1
			start += 1
			if f[cf] == 0:
				cf = cf - 1
			elif end - start < ml:
				ml = end - start
				il = start + 1
				ir = end
	print(il, ir)
main()


n = int(input())
a = list(map(int, input().split()))
(v, l, r) = ([0] * 1000001, [-1] * 1000001, [0] * 1000001)
for i in range(n):
	v[a[i]] += 1
	if l[a[i]] == -1:
		l[a[i]] = i
	r[a[i]] = i
m = max(v)
minl = 1000002
for i in range(len(v)):
	if m == v[i]:
		if minl > r[i] - l[i]:
			minl = r[i] - l[i]
			ansl = l[i]
			ansr = r[i]
print(str(ansl + 1) + ' ' + str(ansr + 1))


_ = input()
counter = dict()
num_list = list(map(int, input().split()))
for (i, num) in enumerate(num_list):
	if num not in counter:
		counter[num] = {'fr': i, 'dst': 0, 'frq': 1}
	else:
		counter[num]['frq'] += 1
		counter[num]['dst'] = i - counter[num]['fr']
sorted_list = sorted(counter.keys(), reverse=True, key=lambda a: counter.get(a)['frq'])
max_freq = counter[sorted_list[0]]['frq']
top_freq_list = list(filter(lambda a: counter.get(a)['frq'] == max_freq, sorted_list))
minimum_dst_list = sorted(top_freq_list, key=lambda a: counter.get(a)['dst'])
min_dist = counter[minimum_dst_list[0]]['dst']
min_dist_list = list(filter(lambda a: counter.get(a)['dst'] == min_dist, sorted_list))
best = min_dist_list[0]
print(counter[best]['fr'] + 1, counter[best]['fr'] + counter[best]['dst'] + 1)


class Span:

	def __init__(self, first):
		self.first = self.last = first
		self.count = 1

	def add(self, last):
		self.last = last
		self.count += 1

	def key(self):
		return (-self.count, self.last - self.first)
n = int(input())
data = list(map(int, input().split()))
span_hash = {}
for (i, x) in enumerate(data):
	if x not in span_hash:
		span_hash[x] = Span(i)
	else:
		span_hash[x].add(i)
spans = sorted(span_hash.values(), key=lambda span: span.key())
print(spans[0].first + 1, spans[0].last + 1)


from sys import stdin
from collections import Counter as counter
a = int(stdin.readline())
b = list(map(int, stdin.readline().split()))
d = counter(b)
ans = [-1] * 1000001
ans1 = [-1] * 1000001
for i in range(a):
	if ans[b[i]] == -1:
		ans[b[i]] = i
	ans1[b[i]] = i
k = sorted([[d[i], i] for i in d], reverse=True)
p = k[0][0]
i = 0
s = 0
(l, r) = (ans[k[0][1]], ans1[k[0][1]])
while i < len(k) and k[i][0] == p:
	if r - l > ans1[k[i][1]] - ans[k[i][1]]:
		(l, r) = (ans[k[i][1]], ans1[k[i][1]])
	i += 1
print(l + 1, r + 1)


n = int(input())
count = [0] * 1000001
ran = [(0, 0)] * 1000001
a = list(map(int, input().split()))
for i in range(n):
	count[a[i]] += 1
for i in range(n):
	(x, y) = ran[a[i]]
	if x == 0:
		ran[a[i]] = (i + 1, y)
	else:
		ran[a[i]] = (x, i + 1)
maxn = max(count)
minr = 900000000000
minx = 0
miny = 0
for i in range(1000001):
	if count[i] == maxn:
		(x, y) = ran[i]
		if x > y:
			y = x
		if y - x + 1 < minr:
			minx = x
			miny = y
			minr = y - x + 1
print(minx, miny)


n = int(input())
a = list(map(int, input().split()))
b = [0] * (max(a) + 1)
l = [-1] * (max(a) + 1)
r = [-1] * (max(a) + 1)
d = [0, 0]
for i in range(len(a)):
	b[a[i]] = b[a[i]] + 1
	if l[a[i]] == -1:
		l[a[i]] = i
	r[a[i]] = i
i = 0
min_ = len(a) + 1
max_ = b.index(max(b))
for i in range(len(b)):
	if b[i] == b[max_]:
		if r[i] - l[i] < min_:
			min_ = r[i] - l[i] + 1
			d = [l[i] + 1, r[i] + 1]
print(*d)


def amrlarge():
	n = int(input())
	arr = list(map(int, input().split()))
	sortedarr = arr.copy()
	sortedarr.sort()
	sortedindex = sorted(range(n), key=lambda k: arr[k])
	max_val = []
	freq = max_freq = 0
	minInd = maxInd = sortedindex[0]
	minSpan = n + 1
	for i in range(n - 1):
		if sortedarr[i] == sortedarr[i + 1]:
			if sortedindex[i + 1] < minInd:
				minInd = sortedindex[i + 1]
			if sortedindex[i + 1] > maxInd:
				maxInd = sortedindex[i + 1]
			freq += 1
		if sortedarr[i] != sortedarr[i + 1] or i == n - 2:
			if freq > max_freq:
				minSpan = maxInd - minInd
				lo = 1 + minInd
				hi = 1 + maxInd
				max_freq = freq
				max_val *= 0
				max_val.append(sortedarr[i])
			elif freq == max_freq and maxInd - minInd < minSpan:
				minSpan = maxInd - minInd
				lo = 1 + minInd
				hi = 1 + maxInd
				max_val *= 0
				max_val.append(sortedarr[i])
			minInd = sortedindex[i + 1]
			maxInd = sortedindex[i + 1]
			freq = 0
	print(lo, end=' ')
	print(hi)
amrlarge()


n = int(input())
a = [int(x) for x in input().split()]
(d, mx) = (dict(), 0)
for i in range(n):
	cur = d.setdefault(a[i], [0, 0, i])
	cur[1] = -(i - cur[2])
	cur[0] += 1
	d[a[i]] = cur
	mx = max(mx, cur[0])
c = max(d.values())
print(c[2] + 1, c[2] - c[1] + 1)


input()
d = {}
for (i, a) in enumerate(map(int, input().split())):
	(c, _, l) = d.get(a, (0, 0, i))
	d[a] = (c + 1, l - i, l)
(_, h, l) = max(d.values())
print(l + 1, l - h + 1)


N = 1000001
num = {}
n = int(input())
i = 1
for x in input().split():
	x = int(x)
	if num.get(x) == None:
		num.setdefault(x, (i, i, 1))
	else:
		num[x] = (num[x][0], i, num[x][2] + 1)
	i = i + 1
ansn = 0
ansl = 0
ansr = n
for (x, (l, r, n)) in num.items():
	ansn = max(ansn, n)
for (x, (l, r, n)) in num.items():
	if n == ansn and ansr - ansl > r - l:
		ansr = r
		ansl = l
print(ansl, ansr)


from collections import defaultdict
n = int(input())
a = list(map(int, input().split()))
d = defaultdict(list)
for (i, v) in enumerate(a):
	d[v].append(i)
bestSize = -float('inf')
bestLen = float('inf')
l = r = None
for cnt in d.values():
	(i, j) = (cnt[0], cnt[-1])
	if len(cnt) > bestSize or (len(cnt) == bestSize and j - i + 1 < bestLen):
		bestSize = len(cnt)
		bestLen = j - i + 1
		(l, r) = (i, j)
print('%d %d' % (l + 1, r + 1))


n = int(input())
a = list(map(int, input().split()))
counter = {}
index = {}
beauty = 0
beauty_start = 0
beauty_end = 0
for i in range(n):
	ai = a[i]
	if ai not in counter:
		counter[ai] = 1
		index[ai] = (i, i)
	else:
		counter[ai] += 1
		index[ai] = (index[ai][0], i)
	if counter[ai] > beauty:
		beauty = counter[ai]
		beauty_start = index[ai][0]
		beauty_end = index[ai][1]
	elif counter[ai] == beauty:
		k = index[ai]
		if k[1] - k[0] < beauty_end - beauty_start:
			beauty_start = k[0]
			beauty_end = k[1]
print(beauty_start + 1, beauty_end + 1)


def main():
	M = 1000005
	n = int(input())
	a = [int(x) for x in input().split()]
	interval = [(-1, -1) for _ in range(M)]
	count = [0 for _ in range(M)]
	for i in range(len(a)):
		x = a[i]
		count[x] += 1
		if interval[x][0] == -1:
			interval[x] = (i, i)
		else:
			interval[x] = (interval[x][0], i)
	beauty = max(count)
	(left, right) = (-1, M)
	for x in range(M):
		if count[x] == beauty and interval[x][1] - interval[x][0] < right - left:
			(left, right) = (interval[x][0], interval[x][1])
	print('{0} {1}'.format(left + 1, right + 1))
main()


def f():
	input()
	a = list(map(int, input().split(' ')))
	f = (10 ** 6 + 1) * [0]
	l = (10 ** 6 + 1) * [0]
	c = (10 ** 6 + 1) * [0]
	for i in range(len(a) - 1, -1, -1):
		f[a[i]] = i
	for i in range(len(a)):
		l[a[i]] = i
		c[a[i]] += 1
	m = max(c)
	m = min([i for i in range(len(a)) if c[a[i]] == m], key=lambda x: l[a[x]] - f[a[x]])
	print(f[a[m]] + 1, l[a[m]] + 1)
f()


(n, a, cnt) = (int(input()), list(map(int, input().split())), {})
for i in range(n):
	if a[i] not in cnt:
		cnt[a[i]] = [0, i, i]
	cnt[a[i]][0] += 1
	cnt[a[i]][2] = i
ans = [0, 0, 0]
for (c, i, j) in cnt.values():
	if c > ans[0] or (c == ans[0] and j - i < ans[2] - ans[1]):
		ans = [c, i, j]
print(ans[1] + 1, ans[2] + 1)


num = int(input())
data = dict()
lst = input().split()
lst = list(map(int, lst))
for i in range(num):
	if lst[i] in data:
		data[lst[i]][0] += 1
		data[lst[i]][2] = i
	else:
		data[lst[i]] = [1, i, i]
m = 1
newlst = []
for n in data.keys():
	info = data[n]
	if info[0] > m:
		m = info[0]
		newlst = [info[1:]]
	elif info[0] == m:
		newlst += [info[1:]]
mn = num + 1
best = []
newlst = sorted(newlst)
for i in range(len(newlst)):
	rng = newlst[i][1] - newlst[i][0]
	if rng < mn:
		mn = rng
		best = newlst[i]
print(best[0] + 1, best[1] + 1)


n = int(input())
a = list(map(int, input().split()))
d = {}
for i in range(n):
	if str(a[i]) not in d:
		d[str(a[i])] = [1, i, i]
	else:
		d[str(a[i])][0] += 1
		d[str(a[i])][2] = max(d[str(a[i])][2], i)
res = sorted(d, key=lambda x: d[x][0], reverse=True)
maxx = d[res[0]][0]
ans = float('inf')
for i in range(len(res)):
	if d[res[i]][0] < maxx:
		break
	if ans > d[res[i]][2] - d[res[i]][1]:
		ans = d[res[i]][2] - d[res[i]][1]
		ind = [d[res[i]][1] + 1, d[res[i]][2] + 1]
print(*ind)


n = int(input())
l = list(map(int, input().split()))
l1 = {}
for i in range(n):
	if l[i] not in l1:
		l1[l[i]] = [1, i, i]
	else:
		l1[l[i]][0] = l1[l[i]][0] + 1
		l1[l[i]][2] = i
ma = 0
ma1 = 100000
ma2 = -1
for j in l1.values():
	if ma < j[0]:
		ma = j[0]
		ma1 = abs(j[1] - j[2])
		ma2 = str(j[1] + 1) + ' ' + str(j[2] + 1)
	if ma == j[0] and abs(j[1] - j[2]) < ma1:
		ma = j[0]
		ma1 = abs(j[1] - j[2])
		ma2 = str(j[1] + 1) + ' ' + str(j[2] + 1)
print(ma2)


n = int(input())
l_i = list(map(int, input().split()))
d = {}
m_b = 0
m_b_i = 0
m_l = 0
for i in range(n):
	if l_i[i] not in d:
		d[l_i[i]] = [0, i]
	d[l_i[i]][0] += 1
	if d[l_i[i]][0] > m_b:
		m_b = d[l_i[i]][0]
		m_b_i = i
		m_l = i - d[l_i[i]][1]
	elif d[l_i[i]][0] == m_b and i - d[l_i[i]][1] < m_l:
		m_b = d[l_i[i]][0]
		m_b_i = i
		m_l = i - d[l_i[i]][1]
print(d[l_i[m_b_i]][1] + 1, m_b_i + 1)


__author__ = 'artyom'

def main():
	seq = [0] * 1000001
	for i in range(1, 1000001):
		seq[i] = i
	cnt = [0] * 1000001
	fst = [-1] * 1000001
	lst = [-1] * 1000001
	n = read()
	a = read(3)
	for i in range(n):
		cnt[a[i]] += 1
		lst[a[i]] = i
		if fst[a[i]] == -1:
			fst[a[i]] = i
	seq.sort(key=lambda i: (cnt[i], fst[i] - lst[i]), reverse=True)
	return (fst[seq[0]] + 1, lst[seq[0]] + 1)

def read(mode=1, size=None):
	if mode == 0:
		return input().strip()
	if mode == 1:
		return int(input().strip())
	if mode == 2:
		return input().strip().split()
	if mode == 3:
		return list(map(int, input().strip().split()))
	a = []
	for _ in range(size):
		a.append(read(3))
	return a

def write(s='\n'):
	if s is None:
		s = ''
	if isinstance(s, tuple) or isinstance(s, list):
		s = ' '.join(map(str, s))
	s = str(s)
	print(s)
write(main())


import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
count = {}
first = {}
last = {}
for i in range(n):
	if a[i] not in count.keys():
		count[a[i]] = 0
		first[a[i]] = i
	count[a[i]] += 1
	last[a[i]] = i
maxCount = 0
target = []
for key in count.keys():
	if count[key] > maxCount:
		maxCount = count[key]
		target = [key]
	elif count[key] == maxCount:
		target.append(key)
ans = 999999999
output = ''
for t in target:
	if last[t] - first[t] < ans:
		ans = last[t] - first[t]
		output = str(first[t] + 1) + ' ' + str(last[t] + 1)
print(output)


from collections import defaultdict
N = int(input())
A = [int(x) for x in input().split()]
bucket = defaultdict(list)
for (i, num) in enumerate(A):
	bucket[num].append(i)
sorted_buckets = sorted(list(bucket.values()), key=lambda val: (-len(val), val[-1] - val[0]))
print(sorted_buckets[0][0] + 1, sorted_buckets[0][-1] + 1)


n = int(input())
a = list(map(int, input().split()))
lr = {}
for i in range(n):
	(c, l, r) = lr.setdefault(a[i], (1, i, i))
	if r != i:
		lr[a[i]] = (c + 1, l, i)
mc = max((c for (c, l, r) in lr.values()))
(x, l, r) = min(((r - l + 1, l, r) for (c, l, r) in lr.values() if c == mc))
print(l + 1, r + 1)


N = int(input())
A = [int(x) for x in input().split()]
bucket = dict()
for (i, num) in enumerate(A):
	if num in bucket:
		bucket[num].append(i)
	else:
		bucket[num] = [i]
sorted_buckets = sorted(bucket.values(), key=lambda val: (-len(val), val[-1] - val[0]))
print(sorted_buckets[0][0] + 1, sorted_buckets[0][-1] + 1)


n = int(input())
i = 0
l = [int(1000000000.0)] * int(1000000.0 + 1)
r = [-1] * int(1000000.0 + 1)
c = [0] * int(1000000.0 + 1)
for x in map(int, input().split()):
	l[x] = min(l[x], i)
	r[x] = max(r[x], i)
	c[x] += 1
	i += 1
res = (0, int(1000000000.0), 0)
for i in range(1, int(1000000.0 + 1)):
	res = min(res, (-c[i], r[i] - l[i], i))
print(l[res[2]] + 1, r[res[2]] + 1)


n = int(input())
a = [int(i) for i in input().split()]
x = 1000000 + 1
m = 0
c = [0] * x
l = [-1] * x
r = [-1] * x
oo = -1
rr = -1
ll = -1
for i in range(len(a)):
	c[a[i]] += 1
	if c[a[i]] > m:
		m = c[a[i]]
	if l[a[i]] == -1:
		l[a[i]] = i
	r[a[i]] = i
for i in range(x):
	if m == c[i]:
		o = r[i] - l[i]
		if oo == -1 or o < oo:
			oo = o
			rr = r[i]
			ll = l[i]
print(ll + 1, rr + 1)


import math, sys
from collections import defaultdict, deque
import bisect as bi

def yes():
	print('YES')

def no():
	print('NO')

def I():
	return int(sys.stdin.readline())

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

def Sn():
	return sys.stdin.readline().strip()

def Pr(x):
	sys.stdout.write(str(x) + '\n')

def dict(a):
	d = {}
	for x in a:
		if d.get(x, -1) != -1:
			d[x] += 1
		else:
			d[x] = 1
	return d

def find_gte(a, x):
	i = bi.bisect_left(a, x)
	if i != len(a):
		return i
	else:
		return -1

def main():
	try:
		n = I()
		l = list(In())
		d = defaultdict(list)
		ma = 0
		for i in range(n):
			d[l[i]].append(i + 1)
			ma = max(len(d[l[i]]), ma)
		if ma == 1:
			print(1, 1)
			return
		dist = P
		ele = -1
		for x in d:
			if len(d[x]) == ma:
				if d[x][-1] - d[x][0] + 1 < dist:
					dist = d[x][-1] - d[x][0] + 1
					ele = x
		print(d[ele][0], d[ele][-1])
	except:
		pass
M = 998244353
P = 1000000007
for _ in range(1):
	main()


n = int(input())
li = list(map(int, input().split()))
s = set(li)
dic = {}
dic2 = {}
(l, r, diff) = (0, 0, 0)
min = n
for i in s:
	dic.setdefault(i, 0)
	dic2.setdefault(i, [])
for i in range(n):
	dic[li[i]] += 1
	dic2[li[i]].append(i)
ma = max(dic.values())
for i in li:
	if dic[i] == ma:
		diff = dic2[i][-1] - dic2[i][0]
		if diff < min:
			l = dic2[i][0]
			r = dic2[i][-1]
			min = diff
print(l + 1, r + 1)


mm = 0
mmi = []
f = [0] * (10 ** 6 + 5)
g = [[] for _ in range(10 ** 6 + 5)]
x = int(input())
l = list(map(int, input().split(' ')))
for i in range(x):
	f[l[i]] += 1
	g[l[i]].append(i + 1)
	if f[l[i]] > mm:
		mm = f[l[i]]
		mmi = [l[i]]
	elif f[l[i]] == mm:
		mmi.append(l[i])
a1 = 0
a2 = 0
minn = 1000000000
for i in mmi:
	if g[i][-1] - g[i][0] < minn:
		minn = g[i][-1] - g[i][0]
		a1 = g[i][0]
		a2 = g[i][-1]
print(a1, a2)


n = int(input())
a = {}
max_dict = {}
array = list(map(int, input().split()))
for i in array:
	a[i] = [-1, -1]
	max_dict[i] = 0
for i in range(n):
	value = array[i]
	if a[value][0] == -1:
		a[value][0] = i
		a[value][1] = i
	else:
		a[value][1] = i
		max_dict[value] += 1
difference = 999999999999
maximum = 0
value = 0
for i in a:
	if max_dict[i] > maximum:
		maximum = max_dict[i]
		difference = a[i][1] - a[i][0]
		value = i
	elif max_dict[i] == maximum:
		d = a[i][1] - a[i][0]
		if d < difference:
			difference = d
			value = i
print(a[value][0] + 1, a[value][1] + 1)


__author__ = 'huash06'
import datetime
import sys
import math
import collections
__author__ = 'huash06'
import os
import sys
import functools
import collections
import itertools
N = int(input())
nums = [int(x) for x in input().split()]
count = collections.defaultdict(int)
left = {}
right = {}
for (i, num) in enumerate(nums):
	count[num] += 1
	if num not in left:
		left[num] = i
		right[num] = i
	else:
		right[num] = i
beauty = max(count.values())
res = len(nums)
l = 1
r = len(nums)
for v in filter(lambda x: count[x] == beauty, count.keys()):
	if right[v] - left[v] < res:
		res = right[v] - left[v] + 1
		l = left[v] + 1
		r = right[v] + 1
print(l, r)


n = int(input())
a = [int(x) for x in input().split()]
d = dict()
mx = 0
for i in range(n):
	cur = d.setdefault(a[i], [0, i, i])
	cur[0] += 1
	cur[2] = i
	d[a[i]] = cur
	mx = max(mx, cur[0])
ans = [0, 9999999]
for i in d.keys():
	if d[i][0] == mx:
		ans = ans if d[i][2] - d[i][1] > ans[1] - ans[0] else [d[i][1], d[i][2]]
print(ans[0] + 1, ans[1] + 1)


I = lambda : map(int, input().split())
n = int(input())
l = list(I())
d = dict()
for i in range(n):
	if l[i] not in d:
		d[l[i]] = [1, i, i]
	else:
		d[l[i]][0] += 1
		d[l[i]][2] = i
a = list(d.values())
a.sort(reverse=True)
z = a[0][0]
total = 10 ** 9
for i in range(len(a)):
	if a[i][0] == z:
		xs = a[i][1]
		ys = a[i][2]
		if ys - xs < total:
			x = xs
			y = ys
			total = ys - xs
print(x + 1, end=' ')
print(y + 1)


n = int(input())
li = list(map(int, input().split()))
dic = {}
for i in range(n):
	if li[i] in dic:
		dic[li[i]][0] += 1
		dic[li[i]][2] = i
	else:
		dic[li[i]] = [1, i, i]
l = list(dic.values())
l.sort(reverse=True)
m = 0
d = n + 1
for i in l:
	if i[0] >= m:
		m = i[0]
		if i[2] - i[1] < d:
			p1 = i[1]
			p2 = i[2]
			d = i[2] - i[1]
	else:
		break
print(p1 + 1, p2 + 1)


n = int(input())
a = list(map(int, input().split()))
c = dict()
d = set()
e = dict()
kolv = dict()
maxi = 0
ans = [0]
for i in range(n):
	if a[i] not in d:
		c[a[i]] = i
		kolv[a[i]] = 1
	else:
		kolv[a[i]] += 1
	d.add(a[i])
d = set()
for i in range(n - 1, -1, -1):
	if a[i] not in d:
		e[a[i]] = i
	d.add(a[i])
d = set()
mass = []
for i in a:
	if i not in d:
		d.add(i)
		mass.append((kolv[i], c[i] - e[i], c[i], e[i]))
print(max(mass)[2] + 1, max(mass)[3] + 1)


n = int(input())
a = [int(c) for c in input().split()]
dt = {}
for i in range(n):
	if not a[i] in dt:
		dt[a[i]] = 0
	dt[a[i]] += 1
m = max(dt.values())
mkeys = set()
for k in dt.keys():
	if dt[k] == m:
		mkeys.add(k)
mkeys2 = set(mkeys)
dt2 = {}
for i in range(n):
	if a[i] in mkeys:
		mkeys.remove(a[i])
		dt2[a[i]] = i
	if not mkeys:
		break
dt3 = {}
dt4 = {}
for i in reversed(range(n)):
	if a[i] in mkeys2:
		mkeys2.remove(a[i])
		dt3[a[i]] = i
		dt4[a[i]] = i - dt2[a[i]]
	if not mkeys2:
		break
mi = min(dt4.values())
for k in dt4.keys():
	if dt4[k] == mi:
		print(' '.join([str(dt2[k] + 1), str(dt3[k] + 1)]))
		break


n = int(input())
l = [int(i) for i in input().split()]
from collections import defaultdict
d = defaultdict(list)
for i in range(n):
	d[l[i]].append(i)
from collections import Counter
c = Counter(l)
maxf = 0
mini = 10 ** 9
for i in c:
	maxf = max(maxf, c[i])
for i in d:
	if len(d[i]) == maxf:
		if d[i][-1] - d[i][0] + 1 < mini:
			mini = d[i][-1] - d[i][0]
			a = d[i][0] + 1
			b = d[i][-1] + 1
print(a, b)


N = int(input())
A = list(map(int, input().split()))
R = [0] * 1000000
L = [0] * 1000000
Cnt = [0] * 1000000
Mx = 0
for I in range(N):
	Cnt[A[I] - 1] += 1
	R[A[I] - 1] = I
	if Cnt[A[I] - 1] == 1:
		L[A[I] - 1] = I
	Mx = max(Mx, Cnt[A[I] - 1])
Ans = N + 1
LL = RR = 0
for I in range(1000000):
	if Cnt[I] == Mx and R[I] - L[I] < Ans:
		Ans = R[I] - L[I]
		LL = L[I]
		RR = R[I]
print(LL + 1, RR + 1)


from operator import itemgetter
n = int(input())
a = list(map(int, input().split()))
c = [0] * 1000001
ar = []
for i in range(n):
	c[a[i]] += 1
	ar.append([a[i], i])
ar = sorted(ar, key=itemgetter(0, 1))
maxc = max(c)
i = 0
md = n
st = 0
en = n - 1
el = -1
while i < n:
	pvsi = i
	while i < n - 1 and ar[i][0] == ar[i + 1][0]:
		i += 1
	co = i - pvsi + 1
	le = ar[i][1] - ar[pvsi][1] + 1
	if maxc == co and md > le:
		md = le
		st = ar[pvsi][1]
		en = ar[i][1]
	i += 1
print(st + 1, en + 1)


import unittest
import sys
import re
import random
import bisect
import array

class Larray:

	def __init__(self, args):
		self.n = args[0]
		self.list = args[1]
		self.freq = {}
		for i in range(self.n):
			key = self.list[i]
			if key in self.freq:
				(it, len, min, max) = self.freq[key]
				it += 1
				if i < min:
					min = i
					len = min - max
				if i > max:
					max = i
					len = min - max
				self.freq[key] = (it, len, min, max)
			else:
				self.freq[key] = (1, 0, i, i)

	def calculate(self):
		values = sorted(self.freq.values())
		result = [values[-1][2] + 1, values[-1][3] + 1]
		return str(' '.join(map(str, result)))

def get_inputs(test_inputs=None):
	it = iter(test_inputs.split('\n')) if test_inputs else None

	def uinput():
		if it:
			return next(it)
		else:
			return sys.stdin.readline()
	num = int(uinput())
	nums = list(map(int, uinput().split()))
	return [num, nums]

def calculate(test_inputs=None):
	return Larray(get_inputs(test_inputs)).calculate()

class unitTests(unittest.TestCase):

	def test_sample_tests(self):
		test = '5\n1 1 2 2 1'
		self.assertEqual(calculate(test), '1 5')
		self.assertEqual(get_inputs(test)[0], 5)
		self.assertEqual(list(get_inputs(test)[1]), [1, 1, 2, 2, 1])
		test = '5\n1 2 2 3 1'
		self.assertEqual(calculate(test), '2 3')
		test = '6\n1 2 2 1 1 2'
		self.assertEqual(calculate(test), '2 6')
		imax = 10000
		test = str(imax)
		test += '\n' + ' '.join(map(str, range(imax)))
		self.assertEqual(calculate(test), '10000 10000')

	def test_Larray_class__basic_functions(self):
		d = Larray([5, [1, 1, 2, 2, 1]])
		self.assertEqual(d.list[0], 1)
		self.assertEqual(d.freq[1], (3, -4, 0, 4))
sys.setrecursionlimit(100000)
if sys.argv[-1] == '-ut':
	unittest.main(argv=[' '])
sys.stdout.write(calculate())


from collections import Counter
n = int(input())
a = [int(s) for s in input().split()]
occurences = Counter()
first = {}
last = {}
for (i, x) in enumerate(a):
	occurences[x] += 1
	if x not in first:
		first[x] = i + 1
	last[x] = i + 1
m = max(occurences.values())
x = min(((last[x] - first[x], first[x], last[x]) for x in occurences if occurences[x] == m))
print(x[1], x[2])


from operator import itemgetter

class CodeforcesTask558BSolution:

	def __init__(self):
		self.result = ''
		self.n = 0
		self.array = []

	def read_input(self):
		self.n = int(input())
		self.array = [int(x) for x in input().split(' ')]

	def process_task(self):
		beauty_count = [0] * 10 ** 6
		for a in self.array:
			beauty_count[a - 1] += 1
		mx_b = max(beauty_count)
		maxes = [x + 1 for x in range(10 ** 6) if mx_b == beauty_count[x]]
		mx_set = set(maxes)
		starts = {}
		stops = {}
		results = []
		for x in range(self.n):
			if len(starts) == len(mx_set):
				break
			if self.array[x] in mx_set:
				if self.array[x] not in starts:
					starts[self.array[x]] = x
		for x in range(1, self.n + 1):
			if len(stops) == len(mx_set):
				break
			if self.array[-x] in mx_set:
				if self.array[-x] not in stops:
					stops[self.array[-x]] = self.n - x
		for r in mx_set:
			results.append((starts[r], stops[r], stops[r] - starts[r]))
		results.sort(key=itemgetter(2))
		self.result = '{0} {1}'.format(results[0][0] + 1, results[0][1] + 1)

	def get_result(self):
		return self.result
Solution = CodeforcesTask558BSolution()
Solution.read_input()
Solution.process_task()
print(Solution.get_result())


import io
import os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
n = int(input())
arr = [int(z) for z in input().split()]
occ = {}
for i in range(n):
	occ[arr[i]] = []
for i in range(n):
	occ[arr[i]].append(i)
maxlen = 0
for i in occ:
	maxlen = max(maxlen, len(occ[i]))
res = []
for i in occ:
	if len(occ[i]) == maxlen:
		res.append([occ[i][-1] - occ[i][0], occ[i][0], occ[i][-1]])
res.sort()
print(res[0][1] + 1, res[0][2] + 1)


from collections import Counter

def solve(n, xs):
	rxs = list(reversed(xs))
	length = len(xs)
	counter = {}
	for (i, x) in enumerate(xs):
		if x in counter:
			counter[x]['cnt'] += 1
			counter[x]['last'] = i
		else:
			counter[x] = {'cnt': 0, 'first': i, 'last': i}
	ts = sorted(list(counter.items()), key=lambda t: t[1]['cnt'], reverse=True)
	maxs = []
	mv = 0
	mr = float('inf')
	rkey = 0
	for t in ts:
		(k, d) = t
		r = d['last'] - d['first']
		if mv <= d['cnt'] and mr > r:
			mv = d['cnt']
			mr = r
			rkey = k
	return (counter[rkey]['first'] + 1, counter[rkey]['last'] + 1)

def getinput():

	def getints_line():
		return list(map(int, input().split(' ')))
	n = int(input())
	xs = getints_line()
	return (n, xs)

def test():
	assert solve(5, [1, 1, 2, 2, 1]) == (1, 5)
	assert solve(5, [1, 2, 2, 3, 1]) == (2, 3)
	assert solve(6, [1, 2, 2, 1, 1, 2]) == (1, 5)

def main():
	print(' '.join(map(str, solve(*getinput()))))

def __starting_point():
	main()
__starting_point()


import os
import sys
from io import BytesIO, IOBase
mod = 10 ** 9 + 7
from collections import Counter, defaultdict

def main():
	n = int(input())
	a = list(map(int, input().split()))
	c = Counter(a)
	d = defaultdict(int)
	beauty = max(c.values())
	(l, r) = (0, 0)
	ansl = l
	ansr = n
	while r < n:
		temp = a[r]
		d[temp] += 1
		if d[temp] == beauty:
			while a[l] != temp:
				d[a[l]] -= 1
				l += 1
			if ansr - ansl > r - l:
				ansr = r
				ansl = l
		r += 1
	print(ansl + 1, ansr + 1)

def nouse0():
	a = 420
	b = 420
	print(f'i am nitish{(a + b) // 2}')

def nouse1():
	a = 420
	b = 420
	print(f'i am nitish{(a + b) // 2}')

def nouse2():
	a = 420
	b = 420
	print(f'i am nitish{(a + b) // 2}')
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')

def nouse3():
	a = 420
	b = 420
	print(f'i am nitish{(a + b) // 2}')

def nouse4():
	a = 420
	b = 420
	print(f'i am nitish{(a + b) // 2}')

def nouse5():
	a = 420
	b = 420
	print(f'i am nitish{(a + b) // 2}')
main()


from functools import cmp_to_key
_ = input()
counter = dict()
num_list = list(map(int, input().split()))
for (i, num) in enumerate(num_list):
	if num not in counter:
		counter[num] = {'fr': i, 'dst': 0, 'frq': 1}
	else:
		counter[num]['frq'] += 1
		counter[num]['dst'] = i - counter[num]['fr']

def cmp(a, b):
	a = counter.get(a)
	b = counter.get(b)
	if a['frq'] > b['frq']:
		return 1
	elif a['frq'] == b['frq']:
		if a['dst'] < b['dst']:
			return 1
	return -1
sorted_counter = sorted(counter.keys(), reverse=True, key=cmp_to_key(cmp))
best = sorted_counter[0]
print(counter[best]['fr'] + 1, counter[best]['fr'] + counter[best]['dst'] + 1)


n = int(input())
a = list(map(int, input().split()))
data = {}
for (i, ai) in enumerate(a, 1):
	if ai not in data:
		data[ai] = [1, i, i]
	else:
		data[ai][0] += 1
		data[ai][2] = i
for results in sorted(data.values(), key=lambda data: (-data[0], data[2] - data[1])):
	print(results[1], results[2])
	break


A = dict()
n = int(input())
a = input().split()
for i in range(len(a)):
	if a[i] in A:
		A[a[i]][0] += 1
		A[a[i]][2] = i
	else:
		A[a[i]] = [1, i, i]
per = 0
answer = [0] * len(A)
for j in A:
	answer[per] = A[j]
	per += 1
answer.sort(key=lambda x: (int(x[0]), -(int(x[2]) - int(x[1]))))
print(answer[-1][1] + 1, answer[-1][2] + 1)


taille = int(input())
tableausolution = input()
tabs = tableausolution.split(' ')
dico = {}
for i in range(taille):
	tabs[i] = int(tabs[i])
	try:
		dico[tabs[i]][1] = i
		dico[tabs[i]][2] += 1
	except:
		dico[tabs[i]] = [i, i, 1]
maxi = 0
maxii = 0
for i in dico.keys():
	res = dico[i]
	if res[2] > maxi:
		maxi = res[2]
		maxii = i
	elif res[2] == maxi:
		if res[1] - res[0] < dico[maxii][1] - dico[maxii][0]:
			maxi = res[2]
			maxii = i
print(dico[maxii][0] + 1, dico[maxii][1] + 1)


n = int(input())
a = [int(x) for x in input().split()]
l = [-1] * (10 ** 6 + 1)
r = [-1] * (10 ** 6 + 1)
c = [0] * (10 ** 6 + 1)
for i in range(len(a)):
	x = a[i]
	if l[x] == -1:
		l[x] = i
	r[x] = i
	c[x] += 1
m = 0
x = -1
for i in range(len(c)):
	if c[i] > m:
		m = c[i]
		x = i
	elif c[i] == m and r[i] - l[i] < r[x] - l[x]:
		x = i
print(l[x] + 1, r[x] + 1)


n = int(input())
a = [int(x) for x in input().split()]
cnt = [0] * (10 ** 6 + 1)
right = [-1] * (10 ** 6 + 1)
left = [-1] * (10 ** 6 + 1)
for x in a:
	cnt[x] += 1
for x in range(n):
	right[a[x]] = x
for x in range(n - 1, -1, -1):
	left[a[x]] = x
(ansl, ansr, ans, len) = (0, 0, 0, 0)
for x in range(10 ** 6 + 1):
	if cnt[x] > ans or (cnt[x] == ans and right[x] - left[x] + 1 < len):
		len = right[x] - left[x] + 1
		ans = cnt[x]
		ansl = left[x]
		ansr = right[x]
print(ansl + 1, ansr + 1)


from sys import *
n = int(input())
tab = list(map(int, stdin.readline().split()))
a = 1000001 * [0]
max = -1
min = 10000001
xstar = 0
b = 1000001 * [0]
c = 1000001 * [0]
for i in range(n):
	x = tab[i]
	a[x] += 1
	if b[x] == 0:
		b[x] = i + 1
	c[x] = i + 1
	if a[x] > max:
		xstar = x
		max = a[x]
		min = c[x] - b[x]
	elif a[x] == max and c[x] - b[x] < min:
		xstar = x
		max = a[x]
		min = c[x] - b[x]
print(b[xstar], c[xstar])


n = int(input())
a = list(map(int, input().split()))
l = r = None
c = 0
d = {}
for (i, e) in enumerate(a):
	if e not in d:
		d[e] = [i]
	else:
		d[e] += [i]
for v in d.values():
	lv = len(v)
	if l is None or lv > c:
		(l, r, c) = (v[0], v[-1], lv)
	elif lv == c and r - l > v[-1] - v[0]:
		(l, r) = (v[0], v[-1])
print(l + 1, r + 1)


n = int(input())
a = list(map(int, input().split()))
d = {}
for i in a:
	if i in d:
		d[i] += 1
	else:
		d[i] = 1
mm = 0
xx = 0
for (key, value) in d.items():
	if mm < value:
		mm = value
		xx = key
pos = []
for (key, value) in d.items():
	if mm == value:
		pos.append(key)
po = []
for i in range(max(a) + 10):
	po.append([])
for i in range(len(a)):
	po[a[i]].append(i)
ans = 10000000000
ii = -1
jj = -1
for i in pos:
	xx = po[i][-1] - po[i][0] + 1
	if xx < ans:
		ans = xx
		ii = po[i][-1] + 1
		jj = po[i][0] + 1
print(min(ii, jj), max(ii, jj))


n = int(input())
L = list(map(int, input().split()))
A = [0] * (10 ** 6 + 1)
B = [0] * (10 ** 6 + 1)
C = [0] * (10 ** 6 + 1)
for i in range(len(L)):
	x = L[i]
	if A[x] == 0:
		B[x] = i
	A[x] = A[x] + 1
	C[x] = i
maxi = A[0]
diff = 10 ** 6
pos = 0
for i in range(1, len(A)):
	if A[i] > maxi:
		maxi = A[i]
		diff = C[i] - B[i]
		pos = i
	elif A[i] == maxi:
		if C[i] - B[i] < diff:
			diff = C[i] - B[i]
			pos = i
print(str(B[pos] + 1) + ' ' + str(C[pos] + 1))