This problem is given in two editions, which differ exclusively in the constraints on the number $n$.

You are given an array of integers $a[1], a[2], \dots, a[n].$ A block is a sequence of contiguous (consecutive) elements $a[l], a[l+1], \dots, a[r]$ ($1 \le l \le r \le n$). Thus, a block is defined by a pair of indices $(l, r)$.

Find a set of blocks $(l_1, r_1), (l_2, r_2), \dots, (l_k, r_k)$ such that:

  They do not intersect (i.e. they are disjoint). Formally, for each pair of blocks $(l_i, r_i)$ and $(l_j, r_j$) where $i \neq j$ either $r_i < l_j$ or $r_j < l_i$.  For each block the sum of its elements is the same. Formally, $$a[l_1]+a[l_1+1]+\dots+a[r_1]=a[l_2]+a[l_2+1]+\dots+a[r_2]=$$ $$\dots =$$ $$a[l_k]+a[l_k+1]+\dots+a[r_k].$$  The number of the blocks in the set is maximum. Formally, there does not exist a set of blocks $(l_1', r_1'), (l_2', r_2'), \dots, (l_{k'}', r_{k'}')$ satisfying the above two requirements with $k' > k$. 

 $\left. \begin{array}{|l|l|l|l|l|l|} \hline 4 & {1} & {2} & {2} & {1} & {5} & {3} \\ \hline \end{array} \right.$ The picture corresponds to the first example. Blue boxes illustrate blocks. 

Write a program to find such a set of blocks.


-----Input-----

The first line contains integer $n$ ($1 \le n \le 50$) — the length of the given array. The second line contains the sequence of elements $a[1], a[2], \dots, a[n]$ ($-10^5 \le a_i \le 10^5$).


-----Output-----

In the first line print the integer $k$ ($1 \le k \le n$). The following $k$ lines should contain blocks, one per line. In each line print a pair of indices $l_i, r_i$ ($1 \le l_i \le r_i \le n$) — the bounds of the $i$-th block. You can print blocks in any order. If there are multiple answers, print any of them.


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

Output
3
7 7
2 3
4 5

Input
11
-5 -4 -3 -2 -1 0 1 2 3 4 5

Output
2
3 4
1 1

Input
4
1 1 1 1

Output
4
4 4
1 1
2 2
3 3

Difficulty: introductory

Starter code:

Solutions:
n = int(input())
a = [int(x) for x in input().split()]

res = {}

for i in range(n):
  sm = 0
  for j in range(i, n):
    sm += a[j]
    if sm in res:
      res[sm].append((i, j))
    else:
      res[sm] = [(i, j)]

best = 0
bestI = -1
for key in res:
  r = -1
  cnt = 0
  for (a,b) in sorted(res[key]):
    if a > r:
      cnt += 1
      r = b
    elif b < r:
      r = b
  if cnt > best:
    best = cnt
    bestI = key

x = []
r = -1
for (a, b) in sorted(res[bestI]):
  if a > r:
    x.append(str(a+1) + " " + str(b+1))
    r = b
  elif b < r:
    r = b
    x.pop()
    x.append(str(a+1) + " " + str(b+1))
  
print(best)
print("\n".join(x))


from collections import defaultdict
n = int(input())
a = list(map(int, input().split()))

rec = defaultdict(list)
for j in range(n):
    for k in range(j, n):
        rec[sum(a[j:k + 1])].append((j, k))

ans = []
for k in rec.keys():
    tmp = []
    rec[k] = sorted(rec[k], key=lambda x: x[1])
    pre = -1
    for a, b in rec[k]:
        if pre >= a:
            continue
        else:
            tmp.append((a + 1, b + 1))
            pre = b
    if len(tmp) > len(ans):
        ans = tmp

print(len(ans))
for a, b in ans:
    print(a, b)

# alpha = "abcdefghijklmnopqrstuvwxyz"
# prime = 998244353 
INF = 100_000_000
# from heapq import heappush, heappop
from collections import defaultdict
t = 1#int(input())
# from math import sqrt


for test in range(t):
    n = int(input())
    # H, n = (map(int, input().split()))
    # a = []
    # for i in range(n):
    # l = input()
    # r = input()
    a = (list((list(map(int, input().split())))))
    pre = [0 for i in range(n+1)]

    for i in range(n):
        pre[i+1] = pre[i]+a[i]
    
    Sum = defaultdict(list)

    for i in range(n):
        for j in range(i, n):
            tmp = pre[j+1]-pre[i]
            # print(i,j,tmp)
            Sum[tmp].append((i,j))

    maxVal = 0
    maxSum = -1
    for key, val in list(Sum.items()):
        val.sort()
        tmp = 1
        cur = val[0][1]
        for i in range(1,len(val)):
            if val[i][0]>cur:
                tmp+=1
                cur = val[i][1]
            elif val[i][1]<=cur:
                cur = val[i][1]
        if maxVal < tmp:
            maxVal = tmp
            maxSum = key

    print(maxVal)
    val = Sum[maxSum]
    val.sort()
    ans = []
    ans.append(val[0])
    cur = val[0][1]
    for i in range(1,len(val)):
        if val[i][0]>cur:
            ans.append(val[i])
            cur = val[i][1]
        elif val[i][1]<=cur:
            ans.pop()
            ans.append(val[i])
            cur = val[i][1]
    for i in ans:
        print(i[0]+1, i[1]+1)





from collections import defaultdict as dd, deque
n = int(input())
A = [int(x) for x in input().split()]
cA = [0]
for a in A:
    cA.append(cA[-1] + a)

B = dd(list)

for l in range(1,n+1):
    for i in range(n-l+1):
        s = cA[i+l] - cA[i]
        B[s].append((i,i+l))

best = 0
bestb = None
for b in sorted(B, key=lambda b: len(B[b]), reverse=True):
    if best > len(B[b]):
        break
    A = sorted(B[b], key=lambda x: x[1])
    res = 0
    lr = -1
    for l,r in A:
        if lr <= l:
            lr = r
            res += 1

    if res > best:
        best = res
        bestb = b

print(best)
A = sorted(B[bestb], key=lambda x: x[1])
res = 0
lr = -1
for l,r in A:
    if lr <= l:
        lr = r
        res += 1
        print(l+1,r)


import sys
input = sys.stdin.readline

n=int(input())
A=list(map(int,input().split()))

from itertools import accumulate
SUM=list(accumulate(A))
SUM.append(0)

BLIST=[[0]*n for i in range(n)]
B2=[]

for i in range(n):
    for j in range(i,n):
        BLIST[i][j]=SUM[j]-SUM[i-1]
        B2.append(SUM[j]-SUM[i-1])

B2=set(B2)
ANS=[]
ANSLEN=0

for bsum in B2:
    i=0
    j=0
    CANDI=[]
    USED=-1

    for i in range(n):
        for j in range(USED+1,i+1):
            if BLIST[j][i]==bsum:
                CANDI.append([j+1,i+1])
                USED=i
                break

    if len(CANDI)>ANSLEN:
        ANS=CANDI
        ANSLEN=len(CANDI)

print(len(ANS))
for ans in ANS:
    print(*ans)
        
        


n = int(input())
A = list(map(int, input().split()))
if n == 1:
    print(1)
    print(1, 1)
    return
prefA = [0]
hah = {}
for i in A:
    prefA.append(prefA[-1] + i)
for i in range(n):
    for j in range(i + 1, n + 1):
        s = prefA[j] - prefA[i]
        if s not in hah:
            hah[s] = []
        hah[s].append([i + 1, j])


def lol(a):
    return a[1], a[0]


ansq = 0
bm = []
for s in hah:
    Q = hah[s]
    cnt = 0
    Q.sort(key=lol)
    ans = []
    for i in Q:
        if i[0] > cnt:
            cnt = i[1]
            ans.append(i)
    if ansq < len(ans):
        ansq = len(ans)
        bm = ans
print(ansq)
for i in bm:
    print(*i)


n = int(input())
a = [int(t) for t in input().split(' ')]

p = [0] * (n+1)
for i in range(n):
    p[i+1] = p[i] + a[i]

sums = set()
for i in range(n):
    for j in range(i+1, n+1):
        sums.add(p[j] - p[i])

INF = n+100
best_blocks = []
for s in sums:
    blocks = []
    leftmost_p = 0
    while leftmost_p < INF:
        leftmost_j = INF
        according_i = -1
        for i in range(leftmost_p, n):
            if i >= leftmost_j: break
            for j in range(i+1, n+1):
                if j >= leftmost_j: break
                if p[j] - p[i] == s and j < leftmost_j:
                    leftmost_j = j
                    according_i = i

        leftmost_p = leftmost_j
        if leftmost_j < INF:
            blocks.append((according_i+1, leftmost_j))

    if len(blocks) > len(best_blocks):
        best_blocks = blocks

print(len(best_blocks))
for b in best_blocks:
    print(*b)


def get(arr):
    r = 0
    c = 0
    for i in arr:
        if i[0] > r:
            c += 1
            r = i[1]
    return c        
    
n = int(input())
a = [int(x) for x in input().split()]
p = [0]
d = {}
for i in a:
    p.append(p[-1] + i)
for i in range(len(p)):
    for j in range(i, len(p)):
        if i != j:
            r = p[j] - p[i]
            d[r] = d.get(r, []) + [(i + 1, j)]
s = 0
for i in d:
    k = sorted(d[i], key=lambda x: x[1])
    if get(k) > s:
        s = get(k)
        ind = k
r = 0
print(s)
for i in ind:
    if i[0] > r:
        print(i[0], i[1])
        r = i[1]

def main():
    n = int(input())
    A = list(map(int, input().split()))
    if n == 1:
        print(1)
        print(1, 1)
        return
    prefA = [0]
    hah = {}
    for i in A:
        prefA.append(prefA[-1] + i)
    for i in range(n):
        for j in range(i + 1, n + 1):
            s = prefA[j] - prefA[i]
            if s not in hah:
                hah[s] = []
            hah[s].append([i + 1, j])


    def lol(a):
        return a[1], a[0]


    ansq = 0
    bm = []
    for s in hah:
        Q = hah[s]
        cnt = 0
        Q.sort(key=lol)
        ans = []
        for i in Q:
            if i[0] > cnt:
                cnt = i[1]
                ans.append(i)
        if ansq < len(ans):
            ansq = len(ans)
            bm = ans
    print(ansq)
    for i in bm:
        print(i[0], i[1])


main()

n=int(input())
arr=list(map(int,input().split()))
dict1={}
for i in range(n):
	val=0
	for j in range(i,n):
		val+=arr[j]
		try:
			dict1[val].append((i,j))
		except:
			KeyError
			dict1[val]=[(i,j)]
ans=0
ansarr=[]
for i in dict1.keys():
	if(len(dict1[i])>ans):
		arr2=[]
		for j in range(len(dict1[i])):
			arr2.append((dict1[i][j][1]-dict1[i][j][0],j))
		arr2.sort()
		temp=[]
		for j in range(len(arr2)):
			flag=0
			indexi=dict1[i][arr2[j][1]][0]
			indexj=dict1[i][arr2[j][1]][1]
			for k in range(len(temp)):
				if(temp[k][0]<=indexi<=temp[k][1] or temp[k][0]<=indexj<=temp[k][1] or indexi<=temp[k][0]<=indexj or indexi<=temp[k][1]<=indexj):
					flag=1
			if(flag==0):
				temp.append((indexi,indexj))
		if(len(temp)>ans):
			ans=len(temp)
			ansarr=temp
print(ans)
finalans=[]
for i in range(len(ansarr)):
	finalans.append(ansarr[i][0]+1)
	finalans.append(ansarr[i][1]+1)
print(*finalans)

n=int(input())
arr=list(map(int,input().split()))
dict1={}
for i in range(n):
	val=0
	for j in range(i,n):
		val+=arr[j]
		try:
			dict1[val].append((i,j))
		except:
			KeyError
			dict1[val]=[(i,j)]
ans=0
ansarr=[]
for i in list(dict1.keys()):
	#print(i,len(dict1[i]))
	if(len(dict1[i])>ans):
		arr2=[]
		for j in range(len(dict1[i])):
			count=0
			for k in range(len(dict1[i])):
				if(dict1[i][k][0]<=dict1[i][j][0]<=dict1[i][k][1] or dict1[i][k][0]<=dict1[i][j][1]<=dict1[i][k][1]  or dict1[i][j][0]<=dict1[i][k][0]<=dict1[i][j][1]  or dict1[i][j][0]<=dict1[i][k][1]<=dict1[i][j][1]):
					count+=1
			arr2.append((count,j))
		arr2.sort()
		temp=[]
		for j in range(len(arr2)):
			flag=0
			indexi=dict1[i][arr2[j][1]][0]
			indexj=dict1[i][arr2[j][1]][1]
			for k in range(len(temp)):
				if(temp[k][0]<=indexi<=temp[k][1] or temp[k][0]<=indexj<=temp[k][1] or indexi<=temp[k][0]<=indexj or indexi<=temp[k][1]<=indexj):
					flag=1
			if(flag==0):
				temp.append((indexi,indexj))
		if(len(temp)>ans):
			ans=len(temp)
			ansarr=temp
print(ans)
finalans=[]
for i in range(len(ansarr)):
	finalans.append(ansarr[i][0]+1)
	finalans.append(ansarr[i][1]+1)
print(*finalans)




n=int(input())
arr=list(map(int,input().split()))
dict1={}
for i in range(n):
	val=0
	for j in range(i,n):
		val+=arr[j]
		try:
			dict1[val].append((i,j))
		except:
			KeyError
			dict1[val]=[(i,j)]
ans=0
ansarr=[]
for i in list(dict1.keys()):
	#print(i,len(dict1[i]))
	if(len(dict1[i])>ans):
		arr2=[]
		for j in range(len(dict1[i])):
			count=0
			for k in range(len(dict1[i])):
				if(dict1[i][k][0]<=dict1[i][j][0]<=dict1[i][k][1] or dict1[i][k][0]<=dict1[i][j][1]<=dict1[i][k][1]  or dict1[i][j][0]<=dict1[i][k][0]<=dict1[i][j][1]  or dict1[i][j][0]<=dict1[i][k][1]<=dict1[i][j][1]):
					count+=1
			arr2.append((count,j))
		arr2.sort()
		temp=[]
		for j in range(len(arr2)):
			flag=0
			indexi=dict1[i][arr2[j][1]][0]
			indexj=dict1[i][arr2[j][1]][1]
			for k in range(len(temp)):
				if(temp[k][0]<=indexi<=temp[k][1] or temp[k][0]<=indexj<=temp[k][1] or indexi<=temp[k][0]<=indexj or indexi<=temp[k][1]<=indexj):
					flag=1
			if(flag==0):
				temp.append((indexi,indexj))
		if(len(temp)>ans):
			ans=len(temp)
			ansarr=temp
print(ans)
finalans=[]
for i in range(len(ansarr)):
	finalans.append(ansarr[i][0]+1)
	finalans.append(ansarr[i][1]+1)
print(*finalans)




from collections import defaultdict
n = int(input())
nums = [int(x) for x in input().split()]
mapas = [defaultdict(list) for _ in range(n)]
for i, nu in enumerate(nums):
	if i:
		mapas[i] = defaultdict(list, mapas[i-1])
	# print(mapas[i])
	mapas[i][nu] = mapas[i][nu] + [(i+1,i+1)]
	su = nu
	for j in reversed(range(1, i)):
		su += nums[j]
		# if su == -2:
		# 	print(nu, 1+j, i+1, mapas[j-1][su])
		if len(mapas[j-1][su])+1 > len(mapas[i][su]):
			mapas[i][su] = mapas[j-1][su] + [(j+1, i+1)]
	# print(su)
	if i:
		su += nums[0]
		# print(su, mapas[i])
		if len(mapas[i][su]) == 0:
			mapas[i][su] = [(1, i+1)]
	# print(mapas[i])
	# print()
	# mapas[i][su] = max(1, mapas[i][su])
mx, my = -1,-1
# print(mapas[-1])
for x, y in mapas[-1].items():
	if len(y)> my:
		mx, my = x, len(y)
# print(mx, my)
print(my)
# print(mapas[-1][mx])
for a, b in mapas[-1][mx]:
	print(a, b)

from collections import defaultdict
n = int(input())
nums = [int(x) for x in input().split()]
mapas = [defaultdict(list) for _ in range(n)]
for i, nu in enumerate(nums):
	if i:
		mapas[i] = defaultdict(list, mapas[i-1])
	# print(mapas[i])
	mapas[i][nu] = mapas[i][nu] + [(i+1,i+1)]
	su = nu
	for j in reversed(range(1, i)):
		su += nums[j]
		# if su == -2:
		# 	print(nu, 1+j, i+1, mapas[j-1][su])
		if len(mapas[j-1][su])+1 > len(mapas[i][su]):
			mapas[i][su] = mapas[j-1][su] + [(j+1, i+1)]
	# print(su)
	if i:
		su += nums[0]
		# print(su, mapas[i])
		if len(mapas[i][su]) == 0:
			mapas[i][su] = [(1, i+1)]
	# print(mapas[i])
	# print()
	# mapas[i][su] = max(1, mapas[i][su])
mx, my = -1,-1
# print(mapas[-1])
for x, y in mapas[-1].items():
	if len(y)> my:
		mx, my = x, len(y)
# print(mx, my)
print(my)
# print(mapas[-1][mx])
for a, b in mapas[-1][mx]:
	print(a, b)

n=int(input())
a=list(map(int,input().split()))
dic={}
for i in range(n):
    sm=0
    for j in range(i,n):
        sm+=a[j]
        if sm in dic:
            dic[sm].append((i,j))
        else:
            dic[sm]=[(i,j)]
ans=0
anskey=-1
for key in dic:
    cnt=0
    last=-1
    for a,b in sorted(dic[key]):
        if a>last:
            cnt+=1
            last=b
        elif b<last:
            last=b
    if cnt>ans:
        ans=cnt
        anskey=key
last=-1
tmp=[]
for a,b in sorted(dic[anskey]):
    if a>last:
        last=b
        tmp.append(str(a+1)+" "+str(b+1))
    elif b<last:
        last=b
        tmp.pop()
        tmp.append(str(a+1)+" "+str(b+1))
print(ans,'\n'.join(tmp),sep='\n')

# import time
def index(key, item, index):
    if key in index:
        index[key].add(item)
    else:
        index[key] = set([item])

def schedule(times):
    index_by_a = {}
    index_by_b = {}
    result_indexs = []
    for i in range(len(times)):
        a, b = times[i]
        index(a, i, index_by_a)
        index(b, i, index_by_b)
    b_keys = sorted(list(index_by_b.keys()))
    # a_keys = sorted(list(index_by_a.keys()))
    a_min = 0
    while 1:
        # collect pool
        pool = set()
        for k, v in index_by_a.items():
            if k >= a_min:
                pool |= v
        if not pool:
            break
        # greedy select.
        for k in (ele for ele in b_keys if ele > a_min):
            candidates = pool & index_by_b[k]
            if candidates:
                chosen = candidates.pop()
                result_indexs.append(chosen)
                a, b = times[chosen]
                a_min = b
                break
    return [times[i] for i in result_indexs]
                
def test_schedule():
    i = ((0, 4), (2, 4), (0, 2), (0, 1), (1, 2), (2, 3), (3, 4))
    result = schedule(i)
    print('len:', len(result))
    for ele in result:
        print(ele)

def solve(n, a_l):
    index_by_sum = {}
    for i in range(n):
        sum_ = 0
        for j in range(i + 1, n + 1):
            sum_ += a_l[j - 1]
            if sum_ in index_by_sum:
                index_by_sum[sum_].append((i, j))
            else:
                index_by_sum[sum_] = [(i, j)]
    result = []
    for sum_, times in index_by_sum.items():
        sub_result = schedule(times)
        if len(sub_result) > len(result):
            result = sub_result
    return result

def main():
    n = int(input())
    a_l = list(map(int, input().split()))
    # tick = time.time()
    result = solve(n, a_l)
    print(len(result))
    for a, b in result:
        print(a + 1, b)
    # tock = time.time()
    # print('T:', round(tock - tick, 5))

def __starting_point():
    main()
__starting_point()

from bisect import insort
n = int(input())
a = list(map(int,input().split()))
cm=[0]*(n+1)
for i in range(n):
    cm[i+1] = cm[i]+a[i]
d = dict()
for i in range(n):
    for j in range(i,n):
        sm = cm[j+1]-cm[i]
        if sm in d:
           insort(d[sm],(j,i))
        else:
           d[sm]=[(j,i)]
ans = 0
arr=list()
tmparr=[None]*n
for sm in d:
    ct=0
    end=-1
    for el in d[sm]:
        if el[1]>end:
           #print(ct,el)
           tmparr[ct]=el
           ct+=1
           end=el[0]
    if ct>ans:
       #print(sm)
       ans=ct
       #print(tmparr[:ans])
       arr=tmparr[:ans]
#print(d)
print(ans)
for el in arr:
    print(el[1]+1,el[0]+1)

def func(arr):
  count=0
  biggest=-1
  store=[]
  for x in range(len(arr)):
    if arr[x][0]>biggest:
      store.append(arr[x])
      biggest=arr[x][1]
      count+=1
  return count,store
def main():
  n=int(input())
  arr=input().split()
  store=[]
  for x in range(n):
    arr[x]=int(arr[x])
    total=0
    for y in range(x,-1,-1):
      total+=arr[y]
      bo=True
      for z in range(len(store)):
        if total==store[z][0]:
          bo=False
          store[z][1].append((y,x))
      if bo:
        store.append([total,[(y,x)]])
  #print(store)
  biggest=0
  big_val=[]
  for  x in range(len(store)):
    test,test_s=func(store[x][1])
    if test>biggest:
      biggest=test
      big_val=test_s
  print(biggest)
  for x in range(len(big_val)):
    print(big_val[x][0]+1,big_val[x][1]+1)
  
main()


from collections import defaultdict
from itertools import accumulate

N = int(input())
H = defaultdict(lambda: [])
A = list(map(int, input().split()))
AA = [0] + list(accumulate(A))
for i in range(1, N+1):
    for j in range(i):
        H[AA[i] - AA[j]].append((i, j)) 
ctr = 0
ans = []
for L in list(H.values()):
    if ctr >= len(L):
        continue
    L.sort()
    ansc = []
    pi = -1
    for i, j in L:
        if j >= pi:
            ansc.append((j+1, i))
            pi = i
    if ctr < len(ansc):
        ans = ansc.copy()
        ctr = len(ans)
print(ctr)
for j, i in ans:
    print(j, i)


franxx = int(input())

life = input()
life = life.split()

darling = {}

for i in range(0, franxx):
	tmp = 0
	for j in range(i, franxx):
		tmp += int(life[j])
		darling[tmp] = (franxx, 0)

for i in range(franxx, 0, -1):
	tmp = 0
	for j in range(i - 1, franxx):
		tmp += int(life[j])
		if (darling[tmp][0] > j):
			darling[tmp] = (i - 1, 1 + darling[tmp][1])


oh_pay = "I love my darling"

for i in range(0, franxx):
	tmp = 0
	for j in range(i, franxx):
		tmp += int(life[j])
		if (oh_pay == "I love my darling" or darling[tmp][1] > darling[oh_pay][1]):
			oh_pay = tmp


print(darling[oh_pay][1])
darling[oh_pay] = (franxx, 0)

for i in range(franxx, 0, -1):
	tmp = 0
	for j in range(i - 1, franxx):
		tmp += int(life[j])
		if (tmp != oh_pay):
			continue;
		if (darling[oh_pay][0] > j):
			print(i, j + 1)
			darling[oh_pay] = (i - 1, 1 + darling[oh_pay][1])

franxx = int(input())

life = input()
life = life.split()

darling = {}

for i in range(0, franxx):
	tmp = 0
	for j in range(i, franxx):
		tmp += int(life[j])
		darling[tmp] = (franxx, 0)
		
oh_pay = "I love my darling"

for i in range(franxx, 0, -1):
	tmp = 0
	for j in range(i - 1, franxx):
		tmp += int(life[j])
		if (darling[tmp][0] > j):
			darling[tmp] = (i - 1, 1 + darling[tmp][1])
			if (oh_pay == "I love my darling" or darling[tmp][1] > darling[oh_pay][1]):
				oh_pay = tmp

print(darling[oh_pay][1])
darling[oh_pay] = (franxx, 0)

for i in range(franxx, 0, -1):
	tmp = 0
	for j in range(i - 1, franxx):
		tmp += int(life[j])
		if (tmp != oh_pay):
			continue;
		if (darling[oh_pay][0] > j):
			print(i, j + 1)
			darling[oh_pay] = (i - 1, 1 + darling[oh_pay][1])

#!/bin/python3

import math
import os
import random
import re
import sys
from collections import defaultdict


def find_max_non_intersecting(segments):
    n = len(segments)

    r = -1
    result = []
    for i in range(n):
        a, b = segments[i]
        if a > r:
            result.append((a, b))
            r = b

    return result


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

    s = []
    for ai in a:
        s.append((s[-1] if s else 0) + ai)

    d = defaultdict(list)
    for j in range(n):
        for i in range(j + 1):
            d[s[j] - (s[i - 1] if i - 1 >= 0 else 0)].append((i, j))

    vals = []
    for v in d.values():
        non_inters = find_max_non_intersecting(v)
        if len(non_inters) > len(vals):
            vals = non_inters

    print(len(vals))
    for l, r in vals:
        print(l + 1, r + 1)
__starting_point()

# -*- coding: utf-8 -*-
# @Time    : 2019/3/19 23:30
# @Author  : LunaFire
# @Email   : gilgemesh2012@gmail.com
# @File    : F1. Same Sum Blocks (Easy).py

from collections import defaultdict


def main():
    n = int(input())
    a = list(map(int, input().split()))

    sum_dict = defaultdict(list)
    for r in range(n):
        tmp = 0
        for l in range(r, -1, -1):
            tmp += a[l]
            sum_dict[tmp].append((l + 1, r + 1))

    ret, blocks = 0, []
    for k, v in list(sum_dict.items()):
        right, tmp = -1, 0
        curr_list = []
        for s in v:
            if s[0] > right:
                tmp += 1
                curr_list.append(s)
                right = s[1]
        if tmp > ret:
            ret = tmp
            blocks = curr_list

    print(ret)
    for s in blocks:
        print(*s)


def __starting_point():
    main()

__starting_point()

n=int(input())

a=[int(i) for i in input().split()]

pref=[0]

d={}

for x in range(len(a)):
	pref.append(pref[x]+a[x])

for r in range(n):
	for l in range(0,r+1):
		v=pref[r+1]-pref[l]

		if(v in d):
			d[v].append([l,r])
		else:
			d[v]=[[l,r]]

maxi=-2

max_set=[]

for key in d:

	start=-1

	tmp_set=[]

	ctr=0

	for e in range(len(d[key])):

		if(d[key][e][0]>start):
			tmp_set.append(d[key][e])
			start=d[key][e][1]
			ctr+=1

	if(ctr>maxi):
		maxi=ctr
		max_set=tmp_set

print(maxi)
for w in range(maxi):
	print(max_set[w][0]+1,max_set[w][1]+1)




from itertools import accumulate

n = int(input())
arr = list(map(int, input().split()))
arr_sums = [0] + list(accumulate(arr))

blocks = {}
for i in range(1, n+1):
    for j in range(i):
        total = arr_sums[i] - arr_sums[j]
        if total not in blocks:
            blocks[total] = [(j+1, i)]
        else:
            if blocks[total][-1][1] < j+1:
                blocks[total].append((j+1, i))

max_block = sorted([(i, len(x)) for i, x in list(blocks.items())], key=lambda y: (-y[1], y[0]))
print(max_block[0][1])
for item in blocks[max_block[0][0]]:
    print(item[0], item[1])