Petya and Gena love playing table tennis. A single match is played according to the following rules: a match consists of multiple sets, each set consists of multiple serves. Each serve is won by one of the players, this player scores one point. As soon as one of the players scores t points, he wins the set; then the next set starts and scores of both players are being set to 0. As soon as one of the players wins the total of s sets, he wins the match and the match is over. Here s and t are some positive integer numbers.

To spice it up, Petya and Gena choose new numbers s and t before every match. Besides, for the sake of history they keep a record of each match: that is, for each serve they write down the winner. Serve winners are recorded in the chronological order. In a record the set is over as soon as one of the players scores t points and the match is over as soon as one of the players wins s sets.

Petya and Gena have found a record of an old match. Unfortunately, the sequence of serves in the record isn't divided into sets and numbers s and t for the given match are also lost. The players now wonder what values of s and t might be. Can you determine all the possible options?


-----Input-----

The first line contains a single integer n — the length of the sequence of games (1 ≤ n ≤ 10^5).

The second line contains n space-separated integers a_{i}. If a_{i} = 1, then the i-th serve was won by Petya, if a_{i} = 2, then the i-th serve was won by Gena.

It is not guaranteed that at least one option for numbers s and t corresponds to the given record.


-----Output-----

In the first line print a single number k — the number of options for numbers s and t.

In each of the following k lines print two integers s_{i} and t_{i} — the option for numbers s and t. Print the options in the order of increasing s_{i}, and for equal s_{i} — in the order of increasing t_{i}.


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

Output
2
1 3
3 1

Input
4
1 1 1 1

Output
3
1 4
2 2
4 1

Input
4
1 2 1 2

Output
0

Input
8
2 1 2 1 1 1 1 1

Output
3
1 6
2 3
6 1

Source: codeforces | Difficulty: HARD
Tags: Sorting


Solutions:
import itertools
n = int(input())
a = [int(x) for x in input().split()]
winner = a[-1]
looser = 3 - winner
(serve_win_cnt, serve_loose_cnt, win_pos, loose_pos, result) = ([0], [0], [-1], [-1], [])
win_cnt = a.count(winner)
for i in range(n):
	if a[i] == winner:
		win_pos.append(i)
	else:
		loose_pos.append(i)
	serve_win_cnt.append(serve_win_cnt[-1] + (a[i] == winner))
	serve_loose_cnt.append(serve_loose_cnt[-1] + (a[i] == looser))
win_pos += [n * 10] * n
loose_pos += [n * 10] * n
serve_win_cnt += [0] * n
serve_loose_cnt += [0] * n
for t in itertools.chain(list(range(1, 1 + win_cnt // 2)), [win_cnt]):
	s = l = i = 0
	sw = sl = 0
	while i < n:
		xw = win_pos[serve_win_cnt[i] + t]
		xl = loose_pos[serve_loose_cnt[i] + t]
		if xw < xl:
			s += 1
		else:
			l += 1
		i = min(xw, xl) + 1
	if s > l and i <= n and (serve_win_cnt[i] == win_cnt):
		result.append((s, t))
print(len(result))
for (x, y) in sorted(result):
	print(x, y)


from itertools import chain

def main(n, a, info=False):
	winner = a[-1]
	looser = 3 - winner
	(csw, csl, pw, pl, ans) = ([0], [0], [-1], [-1], [])
	(nw, nl) = (a.count(winner), a.count(looser))
	for i in range(n):
		if a[i] == winner:
			pw.append(i)
		else:
			pl.append(i)
		csw.append(csw[-1] + int(a[i] == winner))
		csl.append(csl[-1] + int(a[i] == looser))
	pw += [n * 10] * n
	pl += [n * 10] * n
	csw += [0] * n
	csl += [0] * n
	if info:
		print('a: ', a)
		print('csw: ', csw)
		print('csl: ', csl)
		print('pw: ', pw)
		print('pl: ', pl)
	for t in chain(range(1, nw // 2 + 1), [nw]):
		s = l = i = 0
		sw = sl = 0
		while i < n:
			xw = pw[csw[i] + t]
			xl = pl[csl[i] + t]
			if xw < xl:
				s += 1
			else:
				l += 1
			i = min(xw, xl) + 1
			if info:
				print(s, t, ': ', t, i, s, l, xw, xl)
		if s > l and i <= n and (csw[i] == nw):
			ans.append((s, t))
	print(len(ans))
	for (x, y) in sorted(ans):
		print(x, y)

def main_input():
	n = int(input())
	a = [int(i) for i in input().split()]
	main(n, a)
main_input()


n = int(input())
line = input().split()
lst = []
for num in line:
	lst.append(int(num))
cnt1 = [0]
cnt2 = [0]
c1 = 0
c2 = 0
for num in lst:
	if num == 1:
		c1 += 1
		cnt1.append(c2)
	else:
		c2 += 1
		cnt2.append(c1)
w = lst[n - 1]
ans = []
c1 = len(cnt1)
c2 = len(cnt2)
for t in range(n, 0, -1):
	s1 = 0
	s2 = 0
	i1 = 0
	i2 = 0
	l = 1
	while i1 < c1 and i2 < c2:
		if i1 + t >= c1 and i2 + t >= c2:
			if l == 1 and l == w and (i1 + 1 == c1) and (s1 > s2):
				ans.append((s1, t))
			elif l == 2 and l == w and (i2 + 1 == c2) and (s2 > s1):
				ans.append((s2, t))
			break
		elif i2 + t >= c2:
			s1 += 1
			l = 1
			i1 += t
			i2 = cnt1[i1]
		elif i1 + t >= c1:
			s2 += 1
			l = 2
			i2 += t
			i1 = cnt2[i2]
		elif cnt1[i1 + t] < i2 + t:
			s1 += 1
			l = 1
			i1 += t
			i2 = cnt1[i1]
		else:
			s2 += 1
			l = 2
			i2 += t
			i1 = cnt2[i2]
ans.sort()
print(int(len(ans)))
for line in ans:
	print(str(line[0]) + ' ' + str(line[1]))