Arkady invited Anna for a dinner to a sushi restaurant. The restaurant is a bit unusual: it offers $n$ pieces of sushi aligned in a row, and a customer has to choose a continuous subsegment of these sushi to buy.

The pieces of sushi are of two types: either with tuna or with eel. Let's denote the type of the $i$-th from the left sushi as $t_i$, where $t_i = 1$ means it is with tuna, and $t_i = 2$ means it is with eel.

Arkady does not like tuna, Anna does not like eel. Arkady wants to choose such a continuous subsegment of sushi that it has equal number of sushi of each type and each half of the subsegment has only sushi of one type. For example, subsegment $[2, 2, 2, 1, 1, 1]$ is valid, but subsegment $[1, 2, 1, 2, 1, 2]$ is not, because both halves contain both types of sushi.

Find the length of the longest continuous subsegment of sushi Arkady can buy.


-----Input-----

The first line contains a single integer $n$ ($2 \le n \le 100\,000$) — the number of pieces of sushi.

The second line contains $n$ integers $t_1$, $t_2$, ..., $t_n$ ($t_i = 1$, denoting a sushi with tuna or $t_i = 2$, denoting a sushi with eel), representing the types of sushi from left to right.

It is guaranteed that there is at least one piece of sushi of each type. Note that it means that there is at least one valid continuous segment.


-----Output-----

Print a single integer — the maximum length of a valid continuous segment.


-----Examples-----
Input
7
2 2 2 1 1 2 2

Output
4

Input
6
1 2 1 2 1 2

Output
2

Input
9
2 2 1 1 1 2 2 2 2

Output
6



-----Note-----

In the first example Arkady can choose the subsegment $[2, 2, 1, 1]$ or the subsegment $[1, 1, 2, 2]$ with length $4$.

In the second example there is no way but to choose one of the subsegments $[2, 1]$ or $[1, 2]$ with length $2$.

In the third example Arkady's best choice is the subsegment $[1, 1, 1, 2, 2, 2]$.

Source: codeforces | Difficulty: EASY
Tags: Sorting

Implementation

Greedy algorithms


Solutions:
def fastio():
	import sys
	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()
MOD = 10 ** 9 + 7
I = lambda : list(map(int, input().split()))
MOD = 10 ** 9 + 7
I = lambda : list(map(int, input().split()))
(n,) = I()
l = I()
ans = 0
k = l[0]
cur = 0
i = 0
c = 0
while i < n and l[i] == k:
	cur += 1
	i += 1
k = 1 if k == 2 else 2
while i < n:
	c = 0
	while i < n and l[i] == k:
		i += 1
		c += 1
	ans = max(ans, min(cur, c))
	cur = c
	k = 1 if k == 2 else 2
print(2 * ans)


n = int(input())
ts = list(map(int, input().split(' ')))
num = []
cnt = 1
now = ts[0]
for i in range(1, n):
	if ts[i] == now:
		cnt += 1
	elif ts[i] != now:
		num.append(cnt)
		now = ts[i]
		cnt = 1
	if i == n - 1:
		num.append(cnt)
mx = 0
for i in range(len(num) - 1):
	if min(num[i], num[i + 1]) * 2 >= mx:
		mx = min(num[i], num[i + 1]) * 2
print(mx)


n = int(input())
x = [int(r) for r in input().split()]
m = 1
l = list()
for i in range(0, len(x) - 1):
	if x[i] == x[i + 1]:
		m = m + 1
	else:
		l.append(m)
		m = 1
		continue
l.append(m)
maxe = 1
for i in range(len(l) - 1):
	if l[i] <= l[i + 1] or l[i] >= l[i + 1]:
		maxe = max(min(l[i + 1], l[i]), maxe)
print(maxe * 2)


n = int(input())
a = list(map(int, input().split()))
o = []
t = []
if a[0] == 1:
	o.append(1)
	t.append(0)
else:
	o.append(0)
	t.append(1)
y = 1
while y < len(a):
	if a[y] == 1:
		if a[y - 1] == 1:
			o.append(o[y - 1] + 1)
		else:
			o.append(1)
		t.append(0)
	else:
		if a[y - 1] == 2:
			t.append(t[y - 1] + 1)
		else:
			t.append(1)
		o.append(0)
	y += 1
c1 = 0
c2 = 0
y = 1
while y < len(a):
	if o[y] != 0 and c1 == 0:
		c1 = 1
	if t[y] != 0 and c2 == 0:
		c2 = 1
	if o[y] == 0 and c1 != 0:
		o[y] = o[y - 1]
	if t[y] == 0 and c2 != 0:
		t[y] = t[y - 1]
	y += 1
y = 0
mx = 2
while y < len(a):
	mx = max(mx, min(o[y], t[y]) * 2)
	y += 1
print(mx)


n = int(input())
t = list(map(int, input().split()))
segments = []
curr = t[0]
ln = 0
for i in range(n):
	if t[i] == curr:
		ln += 1
	else:
		segments.append(ln)
		curr = t[i]
		ln = 1
segments.append(ln)
longest = 0
for i in range(0, len(segments) - 1):
	longest = max(longest, min(segments[i], segments[i + 1]))
print(longest * 2)


def solve():
	(lc, cc) = (0, 1)
	maxi = 0
	t.append(-3)
	for i in range(1, len(t)):
		if t[i] == t[i - 1]:
			cc += 1
		else:
			maxi = max(maxi, min(cc, lc))
			lc = cc
			cc = 1
	return 2 * maxi

def main():
	global n, t
	n = int(input())
	t = list(map(int, input().split()))
	print(solve())
main()


n = int(input())
cont = 1
limite = 0
anterior = 0
x = input().split(' ')
x.append('f')
for i in range(len(x) - 1):
	if x[i] == x[i + 1]:
		cont += 1
	elif anterior != 0:
		if anterior > cont:
			if limite < cont:
				limite = cont
		elif limite < anterior:
			limite = anterior
		anterior = cont
		cont = 1
	else:
		anterior = cont
		cont = 1
print(limite * 2)


input()
a = list(map(int, input().split()))
(cur_l, prev_l) = (1, 0)
cur_val = a[0]
m = 0
for v in a[1:]:
	if v == cur_val:
		cur_l += 1
	else:
		m = max(m, min(cur_l, prev_l))
		(cur_l, prev_l) = (1, cur_l)
		cur_val = v
m = max(m, min(cur_l, prev_l))
print(2 * m)


t = int(input())
a = list(map(int, input().split()))
c = 1
m = 0
m1 = 0
for i in range(1, t):
	if a[i] == a[i - 1]:
		c += 1
	else:
		m1 = c
		c = 1
	m = max(m, min(m1, c))
print(2 * m)


n = int(input())
a = [int(i) for i in input().split()]
v = []
cnt = l = 0
for i in range(n):
	if a[i] == l:
		cnt += 1
	else:
		v.append(cnt)
		l = a[i]
		cnt = 1
v.append(cnt)
ans = 0
for i in range(len(v) - 1):
	ans = max(ans, min(v[i], v[i + 1]) * 2)
print(ans)


input()
X = list(map(int, input().split()))
(Num1, Num2, i, Max) = (1, 0, 1, 0)
while i < len(X):
	while i < len(X) and X[i] == X[0]:
		Num1 += 1
		i += 1
	Max = max(Max, min(Num1, Num2) * 2)
	Num2 = 0
	while i < len(X) and X[i] != X[0]:
		Num2 += 1
		i += 1
	Max = max(Max, min(Num1, Num2) * 2)
	Num1 = 0
print(Max)


input()
a = [*map(len, input().replace(' ', '').replace('12', '1 2').replace('21', '2 1').split(' '))]
print(2 * max(map(min, zip(a, a[1:]))))


n = int(input())
a = list(map(int, input().split()))
c = 0
l = a[0]
ans = []
for i in range(n):
	if l == a[i]:
		c += 1
	else:
		ans.append(c)
		c = 1
		l = a[i]
ans.append(c)
m = 1
res = max((2 * min(i, j) for (i, j) in zip(ans[+1:], ans[:-1])))
print(res)


numsushi = int(input())
sushi = list(map(int, input().split(' ')))
count = 1
sequence = []
ans = 0
for i in range(numsushi - 1):
	if sushi[i] == sushi[i + 1]:
		count += 1
	else:
		sequence.append(count)
		count = 1
sequence.append(count)
for i in range(len(sequence) - 1):
	ans = max(ans, min(sequence[i], sequence[i + 1]))
print(ans * 2)


n = int(input())
a = list(map(int, input().split()))
cnt = 1
b = []
for i in range(1, n):
	if a[i] == a[i - 1]:
		cnt += 1
	else:
		b.append(cnt)
		cnt = 1
b.append(cnt)
ans = 0
for i in range(1, len(b)):
	ans = max(ans, min(b[i], b[i - 1]))
print(ans * 2)


n = int(input())
a = [*map(int, input().split())]
c1 = 0
c2 = 0
c = a[0]
maxx = 0
p = a[0]
for i in a:
	if i == 1:
		if c != 1:
			c1 = 0
		c1 += 1
		maxx = max(min(c1, c2), maxx)
		c = 1
	if i == 2:
		if c != 2:
			c2 = 0
		c2 += 1
		maxx = max(min(c1, c2), maxx)
		c = 2
print(maxx * 2)


a = int(input())
b = list(map(int, input().split()))
i = 0
m = 0
h = 0
d = 0
while i < a:
	i = i - d
	k = b[i]
	c = 0
	d = 0
	while i < a and k == b[i]:
		c = c + 1
		i = i + 1
	if i < a:
		p = b[i]
		while i < a and p == b[i]:
			d = d + 1
			i = i + 1
		h = 2 * min(c, d)
		if h > m:
			m = h
print(m)


n = int(input())
types = list(map(int, input().split()))
counter = []
last_type = -1
for type_ in types:
	if last_type != type_:
		last_type = type_
		counter.append(1)
	else:
		counter[-1] += 1
res = 0
for i in range(len(counter) - 1):
	res = max(res, min(counter[i], counter[i + 1]))
print(res * 2)


(n, l, x, lx, r, res) = (0, 0, 0, 0, 0, 0)
n = int(input().split()[0])
a = list(map(int, input().split()))
x = a[0]
lx = x
1 == 1
for i in range(1, n):
	x = a[i]
	if x == lx:
		if r != l:
			if 2 * min(i - r, r - l) > res:
				res = 2 * min(i - r, r - l)
			l = r
			lx = 3 - lx
			r = i
	elif r == l:
		r = i
if r != l and 2 * min(n - r, r - l) > res:
	res = 2 * min(n - r, r - l)
print(res)


import sys
from fractions import Fraction
n = int(sys.stdin.readline().strip())
s = list(map(int, sys.stdin.readline().strip().split()))
a = [0, 0, 0]
v = 1
ans = 0
for i in range(0, n):
	if s[i] == v:
		a[v] = a[v] + 1
	else:
		v = s[i]
		a[v] = 1
	ans = max([ans, min([a[1], a[2]])])
print(2 * ans)


n = input()
input_ = input().split()
input_ = list(map(int, input_))
last = input_[0]
input_.pop(0)
nums = []
count = 1
for i in input_:
	if i == last:
		count += 1
	else:
		nums.append(count)
		last = i
		count = 1
if count:
	nums.append(count)
l_ = len(nums)
max_ = 0
for i in range(l_ - 1):
	max_ = max(max_, min(nums[i], nums[i + 1]))
print(max_ * 2)


n = int(input())
a = list(map(int, input().split()))
for i in range(len(a)):
	if a[i] == 1:
		a[i] = 'a'
	else:
		a[i] = 'b'
s = a[0]
t = []
c = 0
p = ''
for i in a:
	if i == s[-1]:
		c += 1
	else:
		t.append(c)
		s += i
		c = 1
t.append(c)
m = 0
for i in range(len(t) - 1):
	if m < min(t[i], t[i + 1]):
		m = min(t[i], t[i + 1])
print(2 * m)


cnt = lambda s, x: s.count(x)
ii = lambda : int(input())
si = lambda : input()
f = lambda : map(int, input().split())
il = lambda : list(map(int, input().split()))
dgl = lambda : list(map(int, input()))
from itertools import groupby
n = ii()
l = il()
mx = 0
l = [len(list(g)) for (k, g) in groupby(l)]
for i in range(len(l) - 1):
	mx = max(mx, min(l[i], l[i + 1]))
print(mx * 2)


n = int(input())
l = list(map(int, input().split()))
cou1 = 1
cou2 = 1
ans = 0
xx = 0
for i in range(n - 1):
	if l[i] == l[i + 1] and l[i] == 1:
		cou1 += 1
	elif l[i] == l[i + 1] and l[i] == 2:
		cou2 += 1
	elif l[i] == 1 and l[i + 1] == 2:
		xx = min(cou1, cou2)
		ans = max(xx, ans)
		cou2 = 1
	elif l[i] == 2 and l[i + 1] == 1:
		xx = min(cou1, cou2)
		ans = max(xx, ans)
		cou1 = 1
xx = min(cou1, cou2)
ans = max(xx, ans)
print(ans * 2)


n = int(input())
a = list(map(int, input().split()))
t = [1]
j = 0
for i in range(1, n):
	if a[i] == a[i - 1]:
		t[j] += 1
	else:
		t.append(1)
		j += 1
maxl = 0
for i in range(1, len(t)):
	maxl = max(maxl, min(t[i], t[i - 1]))
print(maxl * 2)


n = int(input())
sushiRow = [i for i in input().split()]
(count, i, aux) = (0, 0, 0)
maxLen = 0
while i < n:
	while sushiRow[i] == sushiRow[0]:
		(count, i) = (count + 1, i + 1)
		if i >= n:
			break
	maxLen = max(maxLen, 2 * min(aux, count))
	(count, aux) = (0, count)
	if i >= n:
		break
	while sushiRow[i] != sushiRow[0]:
		(count, i) = (count + 1, i + 1)
		if i >= n:
			break
	maxLen = max(maxLen, 2 * min(aux, count))
	(count, aux) = (0, count)
print(maxLen)


n = int(input())
a = input().split()
num1 = 0
num2 = 0
ans = []
for i in range(n):
	x = int(a[i])
	if x == 1:
		if num2 == 0:
			num1 += 1
		else:
			ans.append(num2)
			num2 = 0
			num1 = 1
	elif num1 == 0:
		num2 += 1
	else:
		ans.append(num1)
		num1 = 0
		num2 = 1
if num1 == 0:
	ans.append(num2)
else:
	ans.append(num1)
Ans = 0
for i in range(len(ans) - 1):
	Ans = max(Ans, 2 * min(ans[i], ans[i + 1]))
print(Ans)


def sushiForTwo(n, arr):
	t = 0
	e = 0
	le = 0
	cL = 0
	for i in range(len(arr)):
		if arr[i] == 1 and e == 0:
			t = t + 1
			le = 1
		elif arr[i] == 2 and t == 0:
			e = e + 1
			le = 2
		elif arr[i] != le and arr[i] == 1:
			t = t + 1
		elif arr[i] != le and arr[i] == 2:
			e = e + 1
		elif le == 1:
			cL = max(cL, min(t, e))
			t = 1
			le = 2
		elif le == 2:
			cL = max(cL, min(t, e))
			e = 1
			le = 1
	cL = max(cL, min(t, e))
	return cL * 2
n = int(input())
arr = [int(c) for c in input().split()]
print(sushiForTwo(n, arr))


n = int(input())
t = list(map(int, input().split()))
ans = 0
for k in range(n - 1):
	if t[k] != t[k + 1]:
		i = k
		j = k + 1
		while i > 1 and t[i - 1] == t[i] and (j < n - 1) and (t[j + 1] == t[j]):
			i -= 1
			j += 1
		ans = max(ans, j - i + 1)
print(ans)


n = int(input())
l = list(map(int, input().split()))
a = [0, 0]
a[l[0] - 1] = 1
ans = 0
t = 0
for i in range(1, n):
	if l[i] == l[i - 1]:
		a[l[i] - 1] += 1
	else:
		t = 1
		a[l[i] - 1] = 1
	if t == 1:
		ans = max(ans, 2 * min(a))
print(ans)


n = int(input())
s = input().split()
c = 1
result = []
for i in range(1, n):
	if s[i - 1] == s[i]:
		c += 1
	else:
		result.append(c)
		c = 1
result.append(c)
ans = 0
for i in range(len(result) - 1):
	temp = min(result[i], result[i + 1])
	ans = max(ans, temp)
print(ans * 2)


def solve():
	x = [t[0]]
	v = [1]
	k = 0
	for i in range(1, len(t)):
		if t[i] == t[i - 1]:
			v[k] += 1
		else:
			k += 1
			x.append(t[i])
			v.append(1)
	maxi = 0
	for i in range(1, len(x)):
		if x[i] != x[i - 1]:
			maxi = max(maxi, min(v[i], v[i - 1]))
	return 2 * maxi

def main():
	global n, t
	n = int(input())
	t = list(map(int, input().split()))
	print(solve())
main()


n = int(input())
a = list(map(int, input().split()))
z = []
count = 0
for i in range(1, len(a)):
	if a[i - 1] == a[i]:
		count += 1
	else:
		z.append(count + 1)
		count = 0
z.append(count + 1)
m = 0
for i in range(1, len(z)):
	m = max(m, min(z[i - 1], z[i]))
print(m * 2)


from itertools import groupby
input()
ls = [len([*g]) for (k, g) in groupby(input().split())]
print(2 * max(map(min, zip(ls, ls[1:]))))


n = int(input())
t = [int(i) for i in input().split()]
a = []
c = 1
for i in range(n - 1):
	if t[i] == t[i + 1]:
		c += 1
	else:
		a.append(c)
		c = 1
a.append(c)
ans = 0
for i in range(len(a) - 1):
	if ans < min(a[i], a[i + 1]):
		ans = min(a[i], a[i + 1])
print(2 * ans)


n = int(input())
t = [*map(int, input().split())]
res = 0
l = []
i = 0
while i < n:
	j = i
	while j < n and t[j] == 1:
		j += 1
	l.append(j - i)
	i = j
	while j < n and t[j] == 2:
		j += 1
	l.append(j - i)
	i = j
for i in range(1, len(l)):
	res = max(res, 2 * min(l[i], l[i - 1]))
print(res)


a = int(input())
l = list(map(int, input().split()))
nums = [1]
sym = l[0]
for i in range(1, len(l)):
	if l[i] != sym:
		nums.append(1)
		sym = l[i]
	else:
		nums[-1] += 1
maxval = -1
for i in range(1, len(nums)):
	row = min(nums[i], nums[i - 1]) * 2
	if maxval < row:
		maxval = row
print(maxval)


def inpl():
	return list(map(int, input().split()))
N = int(input())
Su = inpl()
L = []
pre = 0
for s in Su:
	if s == pre:
		L[-1] += 1
	else:
		L.append(1)
		pre = s
print(2 * max([min(l, r) for (l, r) in zip(L, L[1:])]))


a = int(input())
b = list(map(int, input().split()))
c = []
s = 1
x = b[0]
m = 1
for i in range(1, a):
	if b[i] == x:
		s = s + 1
	else:
		c.append(s)
		s = 1
		x = b[i]
c.append(s)
for i in range(0, len(c) - 1):
	if m < c[i] and c[i] == c[i + 1]:
		m = c[i]
	elif c[i] > c[i + 1] and c[i + 1] > m:
		m = c[i + 1]
	elif c[i] < c[i + 1] and c[i] > m:
		m = c[i]
print(2 * m)


n = int(input())
susi = list(map(int, input().split()))
tun = 0
ugr = 0
last = 0
maxim = 0
for sus in susi:
	if last == 1 and sus == 2:
		ugr = 0
	if last == 2 and sus == 1:
		tun = 0
	if sus == 1:
		tun += 1
	else:
		ugr += 1
	last = sus
	maxim = max(maxim, min(tun, ugr))
print(maxim * 2)


length = int(input())
seq = list(map(int, input().split()))
maxcounter = 0
counter = 0
c1 = 1
c2 = 1
for i in range(len(seq) - 1):
	if seq[i] == seq[i + 1] == 1:
		c1 += 1
	if seq[i] == seq[i + 1] == 2:
		c2 += 1
	if seq[i] != seq[i + 1]:
		counter = min(c1, c2)
		maxcounter = max(counter, maxcounter)
		if seq[i] == 1:
			c2 = 1
		else:
			c1 = 1
counter = min(c1, c2)
maxcounter = max(counter, maxcounter)
print(maxcounter * 2)


n = int(input())
a = [int(x) for x in input().split()]
prev = 0
(one, two, ans) = [0] * 3
for i in range(n):
	if a[i] == 1 and prev == 0:
		one += 1
		prev = 1
	elif a[i] == 1 and prev == 2:
		one = 1
		prev = 1
	elif a[i] == 1 and prev == 1:
		one += 1
	elif a[i] == 2 and prev == 0:
		two += 1
		prev = 2
	elif a[i] == 2 and prev == 1:
		two = 1
		prev = 2
	elif a[i] == 2 and prev == 2:
		two += 1
	ans = max(ans, min(two, one))
print(2 * ans)


o = int(input())
a = list(map(int, input().split()))
n2 = 0
n1 = 0
nmax = 0
a.append(3)
for t in range(o):
	if a[t] == 2:
		n2 += 1
		if a[t + 1] == 1 or a[t + 1] == 3:
			n = 2 * min(n1, n2)
			n1 = 0
			if n > nmax:
				nmax = n
	if a[t] == 1:
		n1 += 1
		if a[t + 1] == 2 or a[t + 1] == 3:
			n = 2 * min(n1, n2)
			n2 = 0
			if n > nmax:
				nmax = n
print(nmax)


N = int(input())
k = []
a = list(map(int, input().split()))
c = 1
for i in range(N - 1):
	if a[i] == a[i + 1]:
		c += 1
	else:
		k.append(c)
		c = 1
k.append(c)
ans = 0
for i in range(len(k) - 1):
	ans = max(ans, min(k[i], k[i + 1]))
print(ans * 2)


n = int(input())
tp = input()
tp = tp.split()
mx = 1
t = tp[0]
tempMx = 1
for i in range(1, len(tp)):
	if tp[i] == t:
		tempMx = tempMx + 1
	else:
		temp = tempMx
		t = tp[i]
		tempMx = tempMx - 1
		for j in range(i + 1, len(tp)):
			if tempMx > 0 and tp[j] == t:
				tempMx = tempMx - 1
			else:
				break
		mx = max(temp - tempMx, mx)
		tempMx = 1
print(mx * 2)


import itertools

def main():
	n = input()
	data = [int(v) for v in input().split()]
	res = [1]
	last = data[0]
	for (i, v) in enumerate(data[1:]):
		if v == last:
			res[-1] += 1
		else:
			res.append(1)
			last = v
	ret = min(res[0], res[1])
	for (i, v) in enumerate(data):
		if i + 1 < len(res):
			ret = max(ret, min(res[i], res[i + 1]))
	print(ret * 2)
main()


n = int(input())
arr = map(int, input().split())
(pre, now, nowa, ans) = (0, 0, -1, 0)
for i in arr:
	if i != nowa:
		ans = max(ans, min(pre, now))
		nowa = i
		pre = now
		now = 1
	else:
		now += 1
ans = max(ans, min(pre, now))
print(ans * 2)


n = int(input())
List = list(map(int, input().split()))
cnt2 = 1
cnt1 = 1
maxx = 1
flag = 0
for i in range(n - 1):
	if List[i] == List[i + 1]:
		if List[i] == 1:
			cnt1 += 1
		else:
			cnt2 += 1
		if i == n - 2:
			minn = min(cnt1, cnt2)
			if minn > maxx:
				maxx = minn
	else:
		if flag != 0:
			minn = min(cnt1, cnt2)
			if minn > maxx:
				maxx = minn
		flag = 1
		if List[i] == 1:
			cnt2 = 1
		else:
			cnt1 = 1
print(2 * maxx)


x = int(input())
a = list(map(int, input().split()))
t = [2]
k = 0
k1 = 0
for i in range(x - 1):
	if a[i] == a[i + 1] and a[i] == 1:
		k = k + 1
		t.append(2 * min(k, k1))
	elif a[i] == a[i + 1] and a[i] == 2:
		k1 = k1 + 1
		t.append(2 * min(k, k1))
	elif a[i] != a[i + 1]:
		if a[i + 1] == 2:
			k1 = 1
		elif a[i + 1] == 1:
			k = 1
print(max(t))


n = int(input())
a = [int(s) for s in input().split()]
a.append(-1)
k = 1
prev = 0
cn = 0
ans = 0
for i in range(1, n + 1):
	if a[i] == a[i - 1]:
		k += 1
	else:
		ans = max(ans, min(k, prev))
		prev = k
		k = 1
print(ans * 2)


I = lambda : int(input())
IL = lambda : list(map(int, input().split()))
n = I()
T = IL()
lv = 0
TC = []
for t in T:
	if t != lv:
		TC.append(0)
	TC[-1] += 1
	lv = t
print(max((min(v1, v2) * 2 for (v1, v2) in zip(TC[:-1], TC[1:]))))


n = int(input())
a = list(map(int, input().split()))
tekushiy = 0
kolvotek = 0
kolvopred = 0
mx = 0
for element in a:
	if tekushiy == 0:
		tekushiy = element
	if tekushiy == element:
		kolvotek += 1
	else:
		tekushiy = element
		if kolvopred != 0:
			mx = max(mx, min(kolvopred, kolvotek))
		(kolvopred, kolvotek) = (kolvotek, 1)
mx = max(mx, min(kolvopred, kolvotek))
print(mx * 2)


n = int(input())
arr = list(map(int, input().split()))
var = []
(cnt, typ) = (0, arr[0])
for i in range(n):
	if arr[i] == typ:
		cnt += 1
	else:
		var.append(cnt)
		cnt = 1
		typ = arr[i]
var.append(cnt)
ans = 0
l = len(var)
for i in range(len(var) - 1):
	ans = max(ans, 2 * min(var[i], var[i + 1]))
print(ans)


n = int(input())
ti = list(map(int, input().split()))
ar = [1]
for i in range(1, n):
	if ti[i] != ti[i - 1]:
		ar += [1]
	else:
		ar[-1] += 1
ans = [min(ar[i], ar[i + 1]) * 2 for i in range(len(ar) - 1)]
print(max(ans))


k = int(input())
a = input().split()
s = [0]
for i in range(len(a) - 1):
	if a[i] != a[i + 1]:
		s.extend([i + 1])
s.extend([len(a)])
m = 0
for i in range(1, len(s) - 1):
	r = min(s[i + 1] - s[i], s[i] - s[i - 1])
	if m < r:
		m = r
print(m * 2)


input()
p = list(input().replace(' ', '').replace('12', '1 2').replace('21', '2 1').split())
print(2 * max((min(len(i), len(j)) for (i, j) in zip(p, p[1:]))))


import sys
sys.setrecursionlimit(10 ** 5 + 1)
inf = int(10 ** 20)
max_val = inf
min_val = -inf
RW = lambda : sys.stdin.readline().strip()
RI = lambda : int(RW())
RMI = lambda : [int(x) for x in sys.stdin.readline().strip().split()]
RWI = lambda : [x for x in sys.stdin.readline().strip().split()]
from itertools import groupby
lens = RI()
seq = groupby(RMI())
counts = []
for (k, g) in seq:
	counts.append(len(list(g)))
maxs = -1
for i in range(len(counts) - 1):
	maxs = max(maxs, min(counts[i], counts[i + 1]))
print(maxs * 2)


import re
input()
l = [0, *map(len, re.findall('1+|2+', input()[::2])), 0]
print(max((min(max(a, c), b) for (a, b, c) in zip(l, l[1:], l[2:]))) * 2)


n = int(input())
a = [int(x) for x in input().split()]
flag = 0
su = 0
su1 = 0
ans = 0
for i in range(n):
	if a[i] == 1:
		if flag == 2:
			ans = max(ans, min(su, su1))
			su = 0
		su = su + 1
		flag = 1
	else:
		if flag == 1:
			ans = max(ans, min(su, su1))
			su1 = 0
		su1 = su1 + 1
		flag = 2
ans = max(ans, min(su, su1))
print(2 * ans)


n = int(input())
sushis = input().split()
aux = []
cont = 0
j = 0
i = 0
while j < len(sushis):
	i = sushis[j]
	while sushis[j] == i:
		cont += 1
		j += 1
		if j == len(sushis):
			break
	aux.append(cont)
	cont = 0
s = 0
for k in range(len(aux) - 1):
	if aux[k] < aux[k + 1]:
		if aux[k] > s:
			s = aux[k]
	elif aux[k + 1] > s:
		s = aux[k + 1]
print(s * 2)


(n, count, res) = (int(input()), 0, [])
(*arr,) = map(int, input().split())
a = arr[0]
for i in arr:
	if i != a:
		res.append(count)
		count = 0
	count += 1
	a = i
res.append(count)
(arr, a) = ([], 0)
for i in res:
	arr.append(min(i, a))
	a = i
print(max(arr) * 2)


n = int(input())
p = [int(x) for x in input().split()]
dp = [i for i in range(n)]
for i in range(1, n):
	if p[i] == p[i - 1]:
		dp[i] = dp[i - 1]

def check(m):
	ln = m * 2
	for i in range(n - ln + 1):
		if dp[i + m - 1] <= i and dp[i + ln - 1] == i + m:
			return True
	return False
(l, r) = (1, n // 2)
res = 2
while l <= r:
	m = (r - l) // 2 + l
	if check(m):
		res = m * 2
		l = m + 1
	else:
		r = m - 1
print(res)


n = int(input())
a = list(map(int, input().split()))
l = a[0]
m = 0
cc = 1
lc = 0
for i in range(1, n):
	if a[i] == l:
		cc += 1
	else:
		m = max(min(lc, cc), m)
		lc = cc
		cc = 1
		l = a[i]
m = max(min(lc, cc), m)
print(2 * m)


def koto_ghor(List, k):
	val = List[k]
	cn = 0
	for i in range(k, len(List)):
		if List[i] == val:
			cn += 1
		else:
			break
	return cn
n = int(input())
li = list(map(int, input().split()))
li2 = []
i = 0
while i < n:
	tp = koto_ghor(li, i)
	li2.append(tp)
	i += tp
ln = len(li2)
mx = 0
for i in range(ln - 1):
	tmx = min(li2[i], li2[i + 1]) * 2
	if tmx > mx:
		mx = tmx
print(mx)


from itertools import groupby
n = input()
consecutive_len = [len([*g]) for (k, g) in groupby(input().split())]
ans = 2 * max(map(min, zip(consecutive_len, consecutive_len[1:])))
print(ans)


n = int(input())
arr = list(map(int, input().split()))
count = 0
cur = 0
ans = 2
prev = -1
for i in range(n):
	if arr[i] != cur:
		prev = i - count
		count = 1
		cur = arr[i]
	else:
		count += 1
		al = i - prev + 1
		mi = min(count, al - count)
		ans = max(ans, mi * 2)
print(ans)


n = int(input())
l = []
maxlen = 0
breakpts = []
l = [int(num) for num in input().split()]
for x in range(1, len(l)):
	if l[x] != l[x - 1]:
		breakpts.append(x)
for point in breakpts:
	pt = point
	(c1, c2) = (0, 0)
	if l[pt] == 2:
		(k1, k2) = (1, 2)
	else:
		(k1, k2) = (2, 1)
	(i, j) = (pt - 1, pt)
	while l[i] == k1 and l[j] == k2:
		c1 += 1
		c2 += 1
		if i == 0 or j == len(l) - 1:
			break
		i -= 1
		j += 1
	maxlen = max(maxlen, c1 + c2)
print(maxlen)


n = int(input())
l = list(map(int, input().split()))
c = 1
d = []
for i in range(n - 1):
	if l[i] == l[i + 1]:
		c += 1
		if i == n - 2:
			a = [l[i], c]
			d.append(a)
	elif l[i] != l[i + 1]:
		a = [l[i], c]
		d.append(a)
		c = 1
if l[-1] != l[-2]:
	a = [l[-1], 1]
	d.append(a)
p = []
for i in range(len(d) - 1):
	if d[i][0] == 2 and d[i + 1][0] == 1:
		r = min(d[i][1], d[i + 1][1])
		p.append(r)
	else:
		r = min(d[i][1], d[i + 1][1])
		p.append(r)
r = l.count(1)
u = l.count(2)
if len(p) > 0:
	print(max(p) * 2)
elif n == 2 and (1 in l and 2 in l):
	print(2)
elif r == len(l) or u == len(l):
	print('0')


n = int(input())
l = list(map(int, input().strip().split()))
m = []
cur = 1
last = l[0]
for i in range(1, n):
	if l[i] != last:
		m.append(cur)
		cur = 1
		last = l[i]
	else:
		cur += 1
m.append(cur)
mx = 0
for i in range(len(m) - 1):
	mx = max(mx, min(m[i], m[i + 1]))
print(mx * 2)


numero_de_pecas = int(input())
tipos_de_sushi = list(map(int, input().split()))
tipo_um = 0
tipo_dois = 0
acumulador = 0
tamanho_max = 0
if tipos_de_sushi[0] == 1:
	tipo_um += 1
else:
	tipo_dois += 1
for i in range(numero_de_pecas - 1):
	i = i + 1
	if tipos_de_sushi[i] != tipos_de_sushi[i - 1]:
		acumulador += 1
	if acumulador == 2:
		tamanho_max = max(tamanho_max, min(tipo_um, tipo_dois))
		if tipos_de_sushi[i] == 1:
			tipo_um = 0
		else:
			tipo_dois = 0
		acumulador = 1
	if tipos_de_sushi[i] == 1:
		tipo_um += 1
	else:
		tipo_dois += 1
tamanho_max = max(tamanho_max, min(tipo_um, tipo_dois))
print(tamanho_max * 2)


(n, c, z, m, k) = (int(input()), 1, [], 0, 0)
a = [int(i) for i in input().split()]
for i in range(n - 1):
	if a[i] == a[i + 1]:
		c += 1
	else:
		z.append(c)
		c = 1
z.append(c)
for i in range(len(z) - 1):
	k = min(z[i], z[i + 1])
	m = k if k > m else m
print(m * 2)


n = int(input())
a = list(map(int, input().split()))
k = a[0]
b = [0]
for i in range(1, len(a)):
	if a[i] != k:
		k = a[i]
		b.append(i)
b.append(len(a))
if len(b) == 2:
	print(0)
else:
	i = 1
	ans = 0
	while i < len(b) - 1:
		(p, l) = (b[i + 1] - b[i], b[i] - b[i - 1])
		if p == l:
			ans = max(ans, b[i + 1] - b[i - 1])
		else:
			ans = max(ans, min(p, l) * 2)
		i += 1
	print(ans)


n = int(input())
sushi = list(map(int, input().split()))
sequences = [1] * n
indexes = [0]
for i in range(1, n):
	if sushi[i] == sushi[i - 1]:
		sequences[i] = sequences[i - 1] + 1
	if sequences[i] == 1:
		indexes.append(i)
m = 2
for i in range(len(indexes) - 1):
	value1 = max(sequences[indexes[i]:indexes[i + 1]])
	if i <= len(indexes) - 3:
		value2 = max(sequences[indexes[i + 1]:indexes[i + 2]])
	else:
		value2 = max(sequences[indexes[i + 1]:])
	value3 = min(value1, value2)
	m = max(m, 2 * value3)
print(m)


n = int(input())
a = list(map(int, input().split()))
t = 0
u = 0
ans = 0
if a[0] == 1:
	t += 1
else:
	u += 1
for i in range(1, len(a)):
	if a[i] == 1:
		if a[i] == a[i - 1]:
			t += 1
		else:
			t = 1
	elif a[i] == a[i - 1]:
		u += 1
	else:
		u = 1
	ans = max(ans, min(u, t))
print(ans * 2)


def main():
	global visited, adj, sets
	n = get_int()
	li = get_list()
	res = [0]
	ele = li[0]
	for i in li:
		if i == ele:
			res[-1] += 1
		else:
			ele = i
			res.append(1)
	maxi = 0
	for i in range(1, len(res)):
		maxi = max(maxi, min(res[i - 1], res[i]))
	print(2 * maxi)
import sys
out = []
get_int = lambda : int(input())
get_list = lambda : list(map(int, input().split()))
main()
print(*out, sep='\n')


n = int(input())
a = list(map(int, input().split()))
cnt = [0] * 2
ans = 0
i = 0
j = 0
while i < n:
	while j < n and a[j] == a[i]:
		cnt[a[j] - 1] += 1
		j += 1
	if cnt[0] > 0 and cnt[1] > 0:
		ans = max(ans, 2 * min(cnt[0], cnt[1]))
	i = j
	if j < n:
		cnt[a[j] - 1] = 0
print(ans)


two = 0
one = 0
n = int(input())
p = list(map(int, input().split()))
a = []
for i in range(n):
	if p[i] == 1:
		one += 1
		if two > 0:
			a.append(two)
			two = 0
	else:
		two += 1
		if one > 0:
			a.append(one)
			one = 0
a.append(max(one, two))
max1 = 0
for i in range(len(a) - 1):
	max1 = max(max1, min(a[i], a[i + 1]))
print(2 * max1)


n = int(input())
m = list(map(int, input().split()))
m.append(3)
cp = 0
c = 0
s = 1
r = 0
for x in range(n + 1):
	if m[x] == s:
		c = c + 1
	else:
		r = max(r, min(cp, c) * 2)
		cp = c
		c = 1
		s = m[x]
print(r)


n = int(input())
arr = [int(x) for x in input().split()]
one = []
two = []
c = 0
i = 0
while i < n:
	x = arr[i]
	c = 0
	while i < n and arr[i] == x:
		c += 1
		i += 1
	if x == 1:
		one.append(c)
		two.append(0)
	else:
		one.append(0)
		two.append(c)
ans = 0
for i in range(len(one) - 1):
	temp1 = min(one[i], two[i + 1])
	temp2 = min(two[i], one[i + 1])
	ans = max(2 * max(temp1, temp2), ans)
print(ans)


import sys

class ASushiForTwo:

	def solve(self):
		n = int(input())
		a = [int(_) for _ in input().split()]
		ans = 0
		(i, j) = (0, 0)
		while i < n:
			j = i
			while j < n and a[j] == a[i]:
				j += 1
			l = j - i
			while j < n and a[j] != a[i]:
				j += 1
			r = j - i - l
			ans = max(ans, 2 * min(l, r))
			i += l
		print(ans)
solver = ASushiForTwo()
input = sys.stdin.readline
solver.solve()


n = int(input())
row = list(input().replace(' ', ''))
counter1 = 0
counter2 = 0
sume = 0
hsum = 0
typee = row[0]
for aa in range(0, len(row)):
	c = row[aa]
	if c != typee:
		if typee == '1':
			if counter2 != 0:
				if counter2 > counter1:
					sume = counter1 * 2
				else:
					sume = counter2 * 2
				if sume > hsum:
					hsum = sume
				counter2 = 0
		if typee == '2':
			if counter1 != 0:
				if counter2 > counter1:
					sume = counter1 * 2
				else:
					sume = counter2 * 2
				if sume > hsum:
					hsum = sume
				counter1 = 0
	typee = c
	if typee == '1':
		counter1 += 1
	else:
		counter2 += 1
	if aa == len(row) - 1:
		if typee == '1':
			if counter2 != 0:
				if counter2 > counter1:
					sume = counter1 * 2
				else:
					sume = counter2 * 2
				if sume > hsum:
					hsum = sume
				counter2 = 0
		if typee == '2':
			if counter1 != 0:
				if counter2 > counter1:
					sume = counter1 * 2
				else:
					sume = counter2 * 2
				if sume > hsum:
					hsum = sume
				counter1 = 0
print(hsum)


n = int(input())
a = list(map(int, input().split()))
l = []
count = 1
for i in range(1, n):
	if a[i] == a[i - 1]:
		count += 1
	else:
		l.append(count)
		count = 1
l.append(count)
m = -10000
for i in range(1, len(l)):
	a = min(l[i], l[i - 1])
	m = max(m, 2 * a)
print(m)


n = int(input())
a = []
a = input().split()
a = [int(i) for i in a]
b = []
ans = 0
l = 0
c = 0
for i in range(n):
	if a[i] == a[l]:
		c += 1
	else:
		b.append(c)
		c = 1
		l = i
b.append(c)
for i in range(len(b) - 1):
	ans = max(ans, min(b[i], b[i + 1]))
print(ans * 2)


n = int(input())
sushi = list(map(int, input().split(' ')))
series = [1]
sercount = 0
src = sushi[0]
for i in range(1, n):
	if src != sushi[i]:
		sercount += 1
		src = sushi[i]
		series.append(0)
	series[sercount] += 1
maxsuc = 0
for i in range(len(series) - 1):
	maxsuc = max(maxsuc, min(series[i], series[i + 1]))
print(maxsuc * 2)


numOfSushi = input()
sushiList = []
sushiList = input().split()
sushiList = [int(s, 10) for s in sushiList]
tuna = 0
eel = 0
prev = -1
curMax = 0
for sushi in sushiList:
	if prev != -1 and prev != sushi:
		curMax = max(curMax, 2 * min(tuna, eel))
		if sushi == 1:
			tuna = 0
		elif sushi == 2:
			eel = 0
	if sushi == 1:
		tuna += 1
	elif sushi == 2:
		eel += 1
	prev = sushi
curMax = max(curMax, 2 * min(tuna, eel))
print(curMax)


import os
import re
import sys
from bisect import bisect, bisect_left, insort, insort_left
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from io import BytesIO, IOBase
from itertools import accumulate, combinations, combinations_with_replacement, groupby, permutations, product
from math import acos, asin, atan, ceil, cos, degrees, factorial, hypot, log2, pi, radians, sin, sqrt, tan
from operator import itemgetter, mul
from string import ascii_lowercase, ascii_uppercase, digits

def inp():
	return int(input())

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

def instr():
	s = input()
	return list(s[:len(s)])

def invr():
	return map(int, input().split())

def main():
	n = inp()
	a = inlist()
	first = 1
	sec = 1
	res = 0
	for i in range(1, n):
		if a[i - 1] == a[i]:
			first += 1
		else:
			for j in range(i + 1, n):
				if a[j - 1] == a[j]:
					sec += 1
				else:
					break
			res = max(res, min(first, sec) * 2)
			first = 1
			sec = 1
	print(res)
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))

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


n = int(input())
a = input().split()
l = []
prev = a[0]
cur1 = 0
cur2 = 0
max1 = 0
max2 = 0
for i in range(n):
	if a[i] != prev:
		l.append(cur1)
		cur1 = 0
	cur1 += 1
	prev = a[i]
l.append(cur1)
for i in range(len(l) - 1):
	if min(max1, max2) < min(int(l[i]), int(l[i + 1])):
		max1 = int(l[i])
		max2 = int(l[i + 1])
print(min(max1, max2) * 2)


n = int(input())
a = list(map(int, input().split()))
b = []
c = []
t = -1
for i in range(n):
	if a[i] == 1:
		t = i
	b.append(t)
t = -1
for i in range(n):
	if a[i] == 2:
		t = i
	c.append(t)
ans = 0
for i in range(n):
	if b[i] == -1 or c[i] == -1:
		continue
	ans = max(ans, min(c[i] - b[c[i]], b[i] - c[b[i]]))
print(ans * 2)


n = int(input())
l = [int(x) for x in input().split()]
g = [1] * n
j = 0
for i in range(1, n):
	if l[i] == l[i - 1]:
		g[j] += 1
	else:
		j += 1
ans = 0
for k in range(j):
	ans = max(ans, min(g[k], g[k + 1]))
print(ans * 2)


x = int(input())
a = [int(i) for i in input().split()]
check = [0, 2, 1]
podryad = [0, 0, 0]
max_of_this = 0
last = a[0]
a.insert(x, check[a[x - 1]])
for i in a:
	if last != i:
		if podryad[i] >= podryad[check[i]]:
			max_of_this = max(max_of_this, podryad[check[i]])
		elif podryad[i] < podryad[check[i]]:
			max_of_this = max(max_of_this, podryad[i])
		podryad[i] = 1
		last = i
	else:
		podryad[i] += 1
print(max_of_this * 2)


n = int(input())
(*sushi,) = map(int, input().split())
l = []
old = sushi[0]
count = 1
for i in sushi[1:]:
	if old == i:
		count += 1
	else:
		l.append(count)
		old = i
		count = 1
l.append(count)
print(max(map(min, zip(l, l[1:]))) * 2)


def solution():
	N = int(input())
	sushies = list()
	x = str(input())
	x = x.split()
	for i in range(N):
		sushies.append(x[i])
	temp = list()
	for i in range(N):
		if len(temp) == 0:
			temp.append((sushies[i], 1))
		elif temp[len(temp) - 1][0] == sushies[i]:
			temp[len(temp) - 1] = (sushies[i], temp[len(temp) - 1][1] + 1)
		elif temp[len(temp) - 1][0] != sushies[i]:
			temp.append((sushies[i], 1))
	max = 0
	for i in range(len(temp) - 1):
		if max < min(temp[i][1], temp[i + 1][1]):
			max = min(temp[i][1], temp[i + 1][1])
	print(2 * max)
solution()


n = int(input())
line = input().split()
arr = []
for i in range(n):
	arr.append(int(line[i]))
(count1, count2) = (1, 1)
ans = []
for i in range(1, n):
	if i == n - 1:
		if arr[i] == arr[i - 1]:
			if arr[i] == 1:
				count1 += 1
			else:
				count2 += 1
		ans.append(max(count1, count2))
	elif arr[i] == arr[i - 1]:
		if arr[i] == 1:
			count1 += 1
		else:
			count2 += 1
	elif arr[i] != arr[i - 1]:
		ans.append(max(count1, count2))
		(count1, count2) = (1, 1)
mini = -1
for i in range(1, len(ans)):
	if min(ans[i], ans[i - 1]) > mini:
		mini = min(ans[i], ans[i - 1])
if mini == -1:
	print(2)
else:
	print(2 * mini)


n = int(input())
l = list(map(int, input().split()))
ans = 1
(flag1, flag2) = (0, 0)
(prev1, prev2) = (0, 0)
for i in range(n):
	if l[i] == 1:
		flag1 += 1
		if flag2 != 0:
			prev2 = flag2
			flag2 = 0
	else:
		flag2 += 1
		if flag1 != 0:
			prev1 = flag1
			flag1 = 0
	if flag1 <= prev2:
		ans = max(ans, flag1)
	if flag2 <= prev1:
		ans = max(ans, flag2)
print(ans * 2)


n = int(input())
l = list(map(int, input().split()))
tag = l[0]
co = 0
prev_count = 0
final = 0
for i in range(n):
	if l[i] == tag:
		co += 1
	else:
		final = max(final, min(prev_count, co))
		prev_count = co
		co = 1
		tag = l[i]
final = max(final, min(prev_count, co))
print(final * 2)


(n, sushi) = (int(input()), ''.join(input().split()))
(MaxLen, curLen, nextLen) = (0, 1, 0)
for i in range(n):
	if i != n - 1 and sushi[i] == sushi[i + 1]:
		curLen += 1
	else:
		MaxLen = max(MaxLen, min(curLen, nextLen))
		nextLen = curLen
		curLen = 1
print(MaxLen * 2)


input()
s = list(map(len, list(input().replace(' ', '').replace('12', '1 2').replace('21', '2 1').split())))
print(2 * max(map(min, zip(s, s[1:]))))


n = int(input())
a = list(map(int, input().split()))
g = [0]
last = a[0]
for i in range(n):
	if a[i] == last:
		g[-1] += 1
	else:
		g.append(1)
	last = a[i]
ans = 0
for i in range(1, len(g)):
	ans = max(ans, min(g[i], g[i - 1]))
print(2 * ans)


n = int(input())
t = list(map(int, input().split()))
t2 = []
result = 0
cur = 1
for i in range(n - 1):
	if t[i] == t[i + 1]:
		cur += 1
	else:
		t2.append((t[i], cur))
		cur = 1
t2.append((t[-1], cur))
for i in range(len(t2) - 1):
	result = max(result, min(t2[i][1], t2[i + 1][1]))
print(result * 2)


n = int(input())
z = list(input().split())
s = 1
z1 = []
z.append('0')
for i in range(0, n):
	if z[i] == z[i + 1]:
		s += 1
	else:
		z1.append(s)
		s = 1
mx = 0
for i in range(len(z1) - 1):
	if z1[i] <= z1[i + 1]:
		if z1[i] * 2 >= mx:
			mx = z1[i] * 2
	elif z1[i + 1] * 2 >= mx:
		mx = z1[i + 1] * 2
print(mx)


from sys import stdin, stdout
n = int(stdin.readline().strip())
ls = list(map(int, stdin.readline().strip().split()))
ans = a = b = 0
flag = 0
for i in range(n):
	if ls[i] == 1:
		if flag != 1:
			a = 0
		a += 1
		flag = 1
	else:
		if flag != 2:
			b = 0
		b += 1
		flag = 2
	ans = max(ans, min(a, b))
stdout.write('%d\n' % (ans * 2))


n = int(input())
mas = list(map(int, input().split()))
m = 0
for i in range(len(mas) - 1):
	if mas[i] != mas[i + 1]:
		k = i
		f = i + 1
		s = 2
		while k >= 0 and f < n and (mas[k] != mas[f]) and (mas[k] == mas[i]) and (mas[f] == mas[i + 1]):
			k -= 1
			f += 1
			s += 2
		s -= 2
		k += 1
		f -= 1
		if m < s:
			m = s
print(m)


def main():
	n = int(input())
	nums = list(map(int, input().split()))
	pre = []
	st = 0
	for ed in range(n):
		while nums[st] != nums[ed]:
			st += 1
		pre.append(st - 1)
	ans = 0
	for i in range(n):
		if pre[i] != -1:
			ans = max(ans, min(i - pre[i], pre[i] - pre[pre[i]]))
	print(ans + ans)
main()


q = int(input())
a = list(map(int, input().split()))
z = [[a[0], 0]]
for w in a:
	if w == z[-1][0]:
		z[-1][1] += 1
	else:
		z += [[w, 1]]
z = [w[1] for w in z]
z = [min(z[w - 1], z[w]) for w in range(1, len(z))]
print(max(z) * 2)


n = int(input())
string = input().split()
ans = 1
for i in range(n - 1):
	if n - 1 - i < ans:
		break
	if string[i] == '1' and string[i + 1] == '2':
		l = i - 1
		r = i + 1 + 1
		len_ = 1
		while l >= 0 and r <= n - 1:
			if string[l] == '1' and string[r] == '2':
				len_ += 1
				l -= 1
				r += 1
			else:
				break
		ans = max(ans, len_)
	elif string[i] == '2' and string[i + 1] == '1':
		l = i - 1
		r = i + 1 + 1
		len_ = 1
		while l >= 0 and r <= n - 1:
			if string[l] == '2' and string[r] == '1':
				len_ += 1
				l -= 1
				r += 1
			else:
				break
		ans = max(ans, len_)
print(ans * 2)


n = int(input())
l = list(map(int, input().split()))
b = 1
e = []
for i in range(len(l) - 1):
	if l[i] == l[i + 1]:
		b += 1
	else:
		e.append(b)
		b = 1
e.append(b)
h = 0
for j in range(len(e) - 1):
	h = max(h, min(e[j], e[j + 1]))
print(2 * h)


n = int(input())
sushi = list(map(int, input().split()))
res = 0
u = 0
t = 0
current = ''
for i in sushi:
	if i == 1:
		if current != 'u':
			res = max(res, min(u, t))
			current = 'u'
			u = 1
		else:
			u += 1
	if i == 2:
		if current != 't':
			res = max(res, min(u, t))
			current = 't'
			t = 1
		else:
			t += 1
res = max(res, min(u, t))
print(res * 2)


n = int(input())
a = list(map(len, input().replace(' ', '').replace('12', '1 2').replace('21', '2 1').split()))
k = 0
for i in range(0, len(a) - 1):
	k = max(k, min(a[i], a[i + 1]))
print(2 * k)


n = int(input())
a = list(map(int, input().split()))
max = 0
i = 0
while i < n:
	ct1 = 0
	for j in range(i, n):
		if a[j] != a[i]:
			break
		ct1 += 1
	ct2 = 0
	for j in range(i + ct1, n):
		if a[j] == a[i]:
			break
		ct2 += 1
	if min(ct1, ct2) > max:
		max = min(ct1, ct2)
	i += ct1
print(2 * max)


n = int(input())
a = list(map(int, input().split()))
result1 = []
counter = 0
for i in range(len(a)):
	if i == len(a) - 1:
		if a[-2] == a[-1]:
			result1.append(counter + 1)
		else:
			result1.append(1)
		break
	if a[i] == a[i + 1]:
		counter += 1
	else:
		result1.append(counter + 1)
		counter = 0
print(2 * max([min(result1[i], result1[i + 1]) for i in range(len(result1) - 1)]))


n = int(input(''))
s = list(map(int, input('').split()))
ans = 0
for i in range(len(s) - 1):
	if s[i] * s[i + 1] == 2:
		j = 1
		while i - j >= 0 and i + 1 + j < n:
			if s[i - j] == s[i - j + 1] and s[i + 1 + j] == s[i + j]:
				j += 1
			else:
				break
		ans = max(ans, j)
print(ans * 2)


def dodai(l, r, i):
	ans = 0
	while l <= r:
		mid = (l + r) // 2
		if mid <= i:
			if tong[i] - tong[mid - 1] == (i - mid + 1) * int(a[i]):
				r = mid - 1
				ans = max(ans, i - mid + 1)
			else:
				l = mid + 1
		elif tong[mid] - tong[i] == (mid - i) * int(a[i + 1]):
			l = mid + 1
			ans = max(ans, mid - i)
		else:
			r = mid - 1
	return ans
tong = [0]
(n, a) = (int(input()), input().split())
daymax = 0
a.insert(0, 0)
for i in range(1, n + 1, 1):
	tong.append(tong[i - 1] + int(a[i]))
for i in range(1, n, 1):
	if a[i] != a[i + 1]:
		daymax = max(daymax, 2 * min(dodai(1, i, i), dodai(i + 1, n, i)))
print(daymax)


input()
a = b = l = r = 0
for x in input().split():
	if x == '1':
		a *= l == x
		a += 1
	else:
		b *= l == x
		b += 1
	r = max(r, min(a, b) * 2)
	l = x
print(r)


n = int(input())
a = list(map(int, input().split()))
one = 0
two = 0

def count(x):
	global one
	global two
	if x == 1:
		one += 1
	else:
		two += 1
i = 0
m = 0
while i < n - 1:
	if a[i] == a[i + 1] and i < n - 2:
		count(a[i])
	elif a[i] == 1 and i < n - 2:
		count(a[i])
		m = max(m, 2 * min(one, two))
		two = 0
	elif a[i] == 2 and i < n - 2:
		count(a[i])
		m = max(m, 2 * min(one, two))
		one = 0
	elif i == n - 2:
		count(a[n - 2])
		count(a[n - 1])
		m = max(m, 2 * min(one, two))
	i += 1
print(m)


n = int(input())
fishes = [int(s) for s in input().split(' ')]
now_fish = None
prev_len = 0
now_len = 0
max_len = 0
for f in fishes:
	if f != now_fish:
		max_len = max(max_len, min(now_len, prev_len))
		prev_len = now_len
		now_len = 1
		now_fish = f
	else:
		now_len += 1
max_len = max(max_len, min(now_len, prev_len))
print(max_len * 2)


n = int(input())
a = list(map(int, input().split()))
cnt = [0, 0, 0]
cnt[a[0]] += 1
last = a[0]
mx = 0
for i in range(1, n):
	mx = max(mx, min(cnt[1], cnt[2]))
	if last != a[i]:
		cnt[a[i]] = 0
	cnt[a[i]] += 1
	last = a[i]
mx = max(mx, min(cnt[1], cnt[2]))
print(mx * 2)


n = int(input())
arr = list(map(int, input().split()))
cnt = 1
(p1, p2) = (0, 0)
for i in range(1, n):
	if arr[i] != arr[i - 1]:
		p1 = cnt
		cnt = 1
	else:
		cnt += 1
	p2 = max(p2, min(p1, cnt))
print(2 * p2)


n = int(input())
last_len = -1
tmp_len = 0
ans = 0
nums = list(map(int, input().split()))
for i in range(n):
	if i > 0 and nums[i] != nums[i - 1]:
		if last_len != -1:
			ans = max(ans, min(last_len, tmp_len))
		last_len = tmp_len
		tmp_len = 0
	tmp_len += 1
if last_len != -1:
	ans = max(ans, min(last_len, tmp_len))
last_len = tmp_len
print(ans * 2)


import re
input()
l = [*map(len, re.findall('1+|2+', input()[::2]))]
print(max(map(min, zip(l, l[1:]))) * 2)


import sys
input = lambda : sys.stdin.readline().strip('\r\n')
n = int(input())
a = list(map(int, input().split()))
ans = 0
prev = 0
i = 0
while i < n:
	char = 1
	j = i + 1
	while j < n and a[j] == a[j - 1]:
		char += 1
		j += 1
	ans = max(ans, 2 * min(char, prev))
	prev = char
	i = j
print(ans)


n = int(input())
a = list(map(int, input().split()))
s = [1]
la = a[0]
for i in a[1:]:
	if la == i:
		s[-1] += 1
	else:
		s.append(1)
		la = i
m = 0
for i in range(len(s) - 1):
	m = max(m, min(s[i], s[i + 1]))
print(m * 2)


n = int(input())
a = list(map(int, input().split()))
i = m = 0
j = 1
c1 = 0 if a[0] == 2 else 1
c2 = 0 if a[0] == 1 else 1
cont = 0
for i in range(1, n):
	if a[i] == 2 and a[i - 1] == 2:
		c2 += 1
	elif a[i] == 2 and a[i - 1] == 1:
		cont = c1
		c1 = 0
		c2 += 1
	elif a[i] == 1 and a[i - 1] == 1:
		c1 += 1
	elif a[i] == 1 and a[i - 1] == 2:
		cont = c2
		c2 = 0
		c1 += 1
	if a[i] == 1 and 2 * min(c1, cont) > m:
		m = 2 * min(cont, c1)
	elif a[i] == 2 and 2 * min(c2, cont) > m:
		m = 2 * min(cont, c2)
print(m)


n = int(input())
a = list(map(int, input().split(' ')))
tl1 = 0
tl2 = 0
c1 = 0
c2 = 0
mx = 0
i = 0
b = []
c = []
b.append(a[0])
c.append(1)
for i in range(1, n):
	if a[i] == a[i - 1]:
		c[len(c) - 1] += 1
	else:
		c.append(1)
		b.append(a[i])
mx = 0
for i in range(1, len(c)):
	mx = max(mx, 2 * min(c[i], c[i - 1]))
print(mx)


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

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

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

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

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def pe(s):
	return print(str(s), file=sys.stderr)

def JA(a, sep):
	return sep.join(map(str, a))

def JAA(a, s, t):
	return s.join((t.join(map(str, b)) for b in a))

def main():
	n = I()
	a = LI()
	c = -1
	t = 0
	u = []
	for k in a:
		if k == c:
			t += 1
		else:
			u.append(t)
			c = k
			t = 1
	u.append(t)
	r = 1
	for i in range(len(u) - 1):
		k = min(u[i], u[i + 1])
		if r < k:
			r = k
	return r * 2
print(main())


n = int(input())
s = map(int, input().split(' '))
s = list(s)
b = []
m = 1
for i in range(n - 1):
	if s[i] == s[i + 1]:
		m = m + 1
	else:
		b.append(m)
		m = 1
b.append(m)
c = []
for i in range(len(b)):
	if b[i] <= b[i + 1]:
		c.append(2 * b[i])
	else:
		c.append(2 * b[i + 1])
	if i == len(b) - 2:
		break
print(max(c))


n = int(input())
r = one = two = prev = 0
for i in input().split():
	if int(i) != prev:
		r = max(r, min(one, two) * 2)
		if int(i) == 1:
			one = 0
		else:
			two = 0
	if int(i) == 1:
		one += 1
	else:
		two += 1
	prev = int(i)
r = max(r, min(one, two) * 2)
print(r)


n = int(input())
t = list(map(int, input().split()))
prev = 0
total = []
prev_count = 0
for i in t:
	if i != prev:
		total.append(prev_count)
		prev_count = 1
		prev = i
	else:
		prev_count += 1
total.append(prev_count)
m = 0
for i in range(2, len(total)):
	n = min(total[i], total[i - 1])
	if n > m:
		m = n
print(m * 2)


from sys import stdin, stdout

def main():
	n = int(stdin.readline())
	x = stdin.readline().split()
	x = list(map(int, x))
	a = [0]
	for i in x:
		if i == 1:
			a.append(a[-1] + 1)
		else:
			a.append(0)
	b = [0]
	for i in x[::-1]:
		if i == 2:
			b.append(b[-1] + 1)
		else:
			b.append(0)
	b = b[::-1]
	ans = 0
	for i in range(len(a)):
		ans = max(ans, min(a[i], b[i]))
	a = [0]
	for i in x:
		if i == 2:
			a.append(a[-1] + 1)
		else:
			a.append(0)
	b = [0]
	for i in x[::-1]:
		if i == 1:
			b.append(b[-1] + 1)
		else:
			b.append(0)
	b = b[::-1]
	for i in range(len(a)):
		ans = max(ans, min(a[i], b[i]))
	print(ans * 2)
main()


n = int(input())
a = list(map(int, input().split(' ')))
l = []
counter = 1
for i in range(len(a) - 1):
	compare = abs(a[i + 1] - a[i])
	if compare == 1:
		l.append(counter)
		counter = 1
	else:
		counter += 1
l.append(counter)
m = 1
for i in range(len(l) - 1):
	if l[i + 1] - l[i] >= 0:
		if l[i] > m:
			m = l[i]
	if l[i] - l[i + 1] >= 0:
		if l[i + 1] > m:
			m = l[i + 1]
print(m * 2)


n = int(input())
arr = list(map(int, input().split()))
li = []
cnt = 1
for i in range(n - 1):
	if arr[i] != arr[i + 1]:
		li.append(cnt)
		cnt = 1
	else:
		cnt += 1
li.append(cnt)
ans = 0
nn = len(li)
if nn > 1:
	for j in range(nn - 1):
		if j + 1 <= nn - 1:
			ans = max(ans, min(li[j], li[j + 1]))
print(ans * 2)


n = int(input())
t = [int(i) for i in input().split()]
if n == 2:
	print(2)
	exit()
mas = []
count = 1
for i in range(n - 1):
	if t[i] == t[i + 1]:
		count += 1
	else:
		mas.append(count)
		count = 1
mas.append(count)
min_d = []
for i in range(len(mas) - 1):
	min_d.append(min(mas[i], mas[i + 1]))
print(max(min_d) * 2)


n = int(input())
t = list(map(int, input().split()))
i = 0
tams = []
maxi = 0
while i < n:
	j = i
	while j < n - 1 and t[j] == t[j + 1]:
		j += 1
	j += 1
	tams.append(j - i)
	i = j
for i in range(len(tams) - 1):
	tam = min(tams[i], tams[i + 1]) * 2
	if tam > maxi:
		maxi = tam
print(maxi)


n = int(input())
a = list(map(int, input().split()))
maximum = 0
temp1 = 0
temp2 = 0
for i in range(n):
	if a[i] == 1:
		if i == 0 or a[i - 1] == 1:
			temp1 += 1
		elif a[i - 1] == 2:
			maximum = max(min(temp1, temp2) * 2, maximum)
			temp1 = 1
	elif i == 0 or a[i - 1] == 2:
		temp2 += 1
	elif a[i - 1] == 1:
		maximum = max(min(temp2, temp1) * 2, maximum)
		temp2 = 1
maximum = max(min(temp2, temp1) * 2, maximum)
print(maximum)


n = int(input())
t = list(map(int, input().split()))
ans = []
if t[0] == 1:
	i = 0
	j = 0
	temp = 0
	while i < n and j < n:
		while j < n and t[j] != 2:
			j += 1
		counti = 0
		countj = 0
		while i < n and t[i] == 1:
			counti += 1
			i += 1
		while j < n and t[j] == 2:
			countj += 1
			j += 1
		k = max(countj, temp)
		ans.append(min(counti, k))
		temp = countj
		i = j
else:
	i = 0
	j = 0
	temp = 0
	while i < n and j < n:
		while j < n and t[j] != 1:
			j += 1
		counti = 0
		countj = 0
		while i < n and t[i] == 2:
			counti += 1
			i += 1
		while j < n and t[j] == 1:
			countj += 1
			j += 1
		k = max(countj, temp)
		ans.append(min(counti, k))
		temp = countj
		i = j
print(2 * max(ans))


n = int(input())
li = list(map(int, input().split()))
c1 = 0
c2 = 0
c3 = 0
c4 = 0
ans = 0
if li[0] == 2:
	c2 = 1
else:
	c1 = 1
for i in range(1, n):
	if li[i] == 2:
		if li[i - 1] == 1:
			c2 = 1
		else:
			c2 += 1
		ans = max(ans, min(c1, c2))
	else:
		if li[i - 1] == 2:
			c1 = 1
		else:
			c1 += 1
		ans = max(ans, min(c1, c2))
print(2 * ans)


n = int(input())
s = list(map(int, input().split()))
a = 0
b = 0
m = 0
for i in range(n):
	if s[i] == 1:
		a += 1
		if (i + 1 == n or s[i + 1] == 2) and b != 0:
			m = max(m, min(a, b))
			b = 0
	else:
		b += 1
		if (i + 1 == n or s[i + 1] == 1) and a != 0:
			m = max(m, min(a, b))
			a = 0
print(m * 2)


n = int(input())
m = 0
k = 1
a = [0 for i in range(n)]
a = list(map(int, input().split(' ')))
flag = True
summ = 0
for i in range(1, n):
	if a[i] != a[i - 1]:
		flag = not flag
		if flag:
			k = 0
		else:
			m = 0
	if flag:
		k += 1
	else:
		m += 1
	if 2 * min(k, m) > summ:
		summ = min(k, m) * 2
print(summ)


n = int(input())
a = input().split()
a = [int(item) for item in a]
b = []
i = 0
k = 0
kk = 0
p = 0
for i in range(n - 1):
	if a[i] != a[i + 1]:
		b.append(i + 1 - p)
		p = i + 1
if a[-1] != a[-2]:
	b.append(1)
else:
	b.append(n - p)
ans = []
for i in range(len(b) - 1):
	f = max(b[i], b[i + 1]) - abs(b[i] - b[i + 1])
	ans.append(f)
print(max(ans) * 2)


n = int(input())
arr_str = input().split()
arr_int = [int(x) for x in arr_str]
max_len = 0
len1 = 0
prev_len = 0
cur_suchi = 1
for i in range(n):
	if arr_int[i] == cur_suchi + 1:
		len1 += 1
	else:
		cur_suchi = 1 - cur_suchi
		max_len = max(max_len, min(prev_len, len1))
		prev_len = len1
		len1 = 1
max_len = max(max_len, min(prev_len, len1))
print(max_len * 2)


n = int(input())
a = [int(s) for s in input().split()]
t1 = 0
t2 = 0
max = -10 ** 10
a = [0] + a
for i in range(1, len(a)):
	if a[i] == 1 and a[i - 1] != 1:
		if min(t1, t2) > max:
			max = min(t1, t2)
		t1 = 1
	elif a[i] == 2 and a[i - 1] != 2:
		if min(t1, t2) > max:
			max = min(t1, t2)
		t2 = 1
	elif a[i] == 1 and a[i - 1] == 1:
		t1 += 1
	elif a[i] == 2 and a[i - 1] == 2:
		t2 += 1
if min(t1, t2) > max:
	max = min(t1, t2)
print(max * 2)


from sys import stdin

def solve(input_elements):
	input_len = len(input_elements)
	last_viewed_element = -1
	group_id = 0
	size_of_group = []
	for i in range(input_len):
		if i == 0:
			last_viewed_element = input_elements[i]
			size_of_group.append(1)
			continue
		if input_elements[i] == last_viewed_element:
			size_of_group[group_id] += 1
			continue
		last_viewed_element = input_elements[i]
		group_id += 1
		size_of_group.append(1)
	group_id = 0
	current_answer = 0
	for i in range(input_len):
		if i == 0:
			last_viewed_element = input_elements[i]
			continue
		if input_elements[i] == last_viewed_element:
			continue
		last_viewed_element = input_elements[i]
		group_id += 1
		current_answer = max(current_answer, min(size_of_group[group_id], size_of_group[group_id - 1]))
	return current_answer
items = list(map(lambda x: int(x), stdin.read().split()))
items.pop(0)
print(solve(items) * 2)


def solve(s):
	repeated = []
	i = 0
	count = 1
	for i in range(len(s) - 1):
		if s[i] == s[i + 1]:
			count += 1
		else:
			repeated.append(count)
			count = 1
	repeated.append(count)
	current_max = 0
	for i in range(len(repeated) - 1):
		aux = min(repeated[i], repeated[i + 1])
		if aux > current_max:
			current_max = aux
	return current_max * 2
n = input()
s = list(map(int, input().split()))
print(solve(s))


import sys
import math
get_string = lambda : sys.stdin.readline().strip()
get_int_list = lambda : list(map(int, sys.stdin.readline().strip().split()))
get_intList_from_str = lambda : list(map(int, list(sys.stdin.readline().strip())))
get_charList_from_str = lambda : list(sys.stdin.readline().strip())
get_char_list = lambda : sys.stdin.readline().strip().split()
get_int = lambda : int(sys.stdin.readline())
pt = lambda x: sys.stdout.write(str(x))
n = get_int()
lst = get_int_list()
p = 0
prev = 0
ans = 0
current = 1
while p < n:
	while p < n - 1 and lst[p] == lst[p + 1]:
		p += 1
		current += 1
	ans = max(ans, min(current, prev))
	prev = current
	p += 1
	current = 1
print(ans * 2)


n = int(input())
a = [i for i in map(int, input().split())] + [-1]
ans = 0
l = a[0]
r = a[1]
if l == r:
	lc = 0
	rc = 2
else:
	lc = rc = 1
for i in range(2, n + 1):
	if a[i] == r:
		rc += 1
	else:
		ans = max(ans, min(lc, rc))
		(l, r) = (r, a[i])
		(lc, rc) = (rc, 1)
print(ans * 2)


def max(a, b):
	if a > b:
		return a
	else:
		return b

def min(a, b):
	if a < b:
		return a
	else:
		return b
n = int(input())
s = input()
a = []
v = []
for k in s.split(' '):
	a.append(int(k))
i = 1
while i < n:
	l = 1
	while i < n and a[i] == a[i - 1]:
		l += 1
		i += 1
	i += 1
	v.append(l)
i = 1
Max = 1
while i < len(v):
	Max = max(Max, min(v[i], v[i - 1]))
	i += 1
print(Max * 2)


n = int(input())
arr = list(map(int, input().split()))
c = [0] * 1
c[0] = 1
for i in range(1, n):
	if arr[i] == arr[i - 1]:
		c[-1] += 1
	else:
		c.append(1)
ans = 0
for i in range(len(c) - 1):
	k = min(c[i], c[i + 1])
	if k > ans:
		ans = k
print(2 * ans)


n = int(input())
sushi = [int(j) for j in input().split()]
count = 1
l = []
for i in range(len(sushi)):
	try:
		if sushi[i] == sushi[i + 1]:
			count += 1
		else:
			l.append(count)
			count = 1
	except IndexError:
		l.append(count)
		break
o = []
mx = 0
for k in range(len(l)):
	try:
		if l[k + 1] > l[k]:
			mx = l[k]
			o.append(mx)
		elif l[k + 1] < l[k]:
			o.append(l[k + 1])
		else:
			o.append(l[k])
	except IndexError:
		break
print(max(o) * 2)


n = int(input())
segment = list(map(int, input().split()))
(T, E, switch, answer) = (0, 0, 0, 0)
if segment[0] == 1:
	T += 1
else:
	E += 1
for i in range(1, len(segment)):
	if segment[i - 1] != segment[i]:
		switch += 1
	if switch == 2:
		answer = max(answer, min(T, E))
		if segment[i] == 1:
			T = 0
		else:
			E = 0
		switch = 1
	if segment[i] == 1:
		T += 1
	else:
		E += 1
print(2 * max(answer, min(T, E)))


n_pieces = int(input())
sushi_array = map(int, input().split())
previous_len = 1
curr_len = 1
previous_piece = 0
max_sushi = 0
for piece in sushi_array:
	if previous_piece != piece:
		max_sushi = max(max_sushi, 2 * min(previous_len, curr_len))
		previous_len = curr_len
		curr_len = 1
		previous_piece = piece
	else:
		curr_len += 1
max_sushi = max(max_sushi, 2 * min(previous_len, curr_len))
print(max_sushi)


n = int(input())
sushi = list(map(int, input().split()))
jeden = 0
dwa = 0
liczby = []
for i in sushi:
	if i == 1:
		jeden += 1
		if dwa > 0:
			liczby.append(dwa)
		dwa = 0
	if i == 2:
		dwa += 1
		if jeden > 0:
			liczby.append(jeden)
		jeden = 0
liczby.append(max(dwa, jeden))
k = len(liczby)
wyn = 0
for i in range(1, k):
	wyn = max(wyn, min(liczby[i - 1], liczby[i]))
print(2 * wyn)


n = int(input())
num = input().split()
cnt = []
c = 1
for i in range(1, n):
	if num[i] == num[i - 1]:
		c += 1
	else:
		cnt.append(c)
		c = 1
cnt.append(c)
t = 0
for i in range(1, len(cnt)):
	s = min(cnt[i - 1], cnt[i])
	if s > t:
		t = s
print(2 * t)


a = int(input())
l = list(map(int, input().split()))
arr = []
last = 0
for i in range(1, a):
	if l[i] != l[i - 1]:
		arr.append(i - last)
		last = i
arr.append(i - last + 1)
ans = 0
for i in range(1, len(arr)):
	ans = max(ans, min(arr[i], arr[i - 1]))
print(ans * 2)


input()
a = b = 1
t = m = 0
for i in input().split():
	if i == t:
		b += 1
	else:
		m = max(min(a, b), m)
		(a, b, t) = (b, 1, i)
m = max(min(a, b), m)
print(m * 2)


import re

def cal(n, ind, s):
	co1 = co2 = 0
	Answer = AH = 0
	indh = '1'
	if ind == '1':
		indh = '2'
	i = 0
	while i < n:
		while i < n and s[i] != indh:
			i += 1
			co1 += 1
		if indh == '1':
			indh = '2'
		else:
			indh = '1'
		AH = min(co1, co2)
		if AH > Answer:
			Answer = AH
		co2 = co1
		co1 = 0
	print(Answer * 2)
n = int(input())
s = input().split()
if s[0] == '2':
	cal(n, '2', s)
else:
	cal(n, '1', s)


N = int(input())
A = list(map(int, input().split()))
ans = 0
prev = A[0]
prev_num = 0
tmp = 0
for a in A:
	if a == prev:
		tmp += 1
	else:
		prev_num = tmp
		tmp = 1
	ans = max(ans, min(tmp, prev_num))
	prev = a
print(ans * 2)


def read_tokens():
	return input().strip().split(' ')

def read_ints():
	return [int(s) for s in read_tokens()]

def compute_min_distance(a):
	n = len(a)
	count_equal = 1
	length = []
	for i in range(n - 1):
		if a[i] != a[i + 1]:
			length.append(count_equal)
			count_equal = 0
		count_equal += 1
	length.append(count_equal)
	m = len(length)
	ans = 0
	for i in range(m - 1):
		ans = max(ans, min(length[i], length[i + 1]))
	return ans * 2
(_,) = read_ints()
a = read_ints()
print(compute_min_distance(a))


n = int(input())
arr = list(map(int, input().split()))
i = 0
ans = 0
temp = []
while i < n:
	j = i
	count = 0
	while j < n and arr[j] == arr[i]:
		count += 1
		j += 1
	i = j
	temp.append(count)
if len(temp) == 1:
	print(1)
else:
	for i in range(len(temp) - 1):
		ans = max(ans, 2 * min(temp[i], temp[i + 1]))
print(ans)


n = int(int(input()) / 2)
s = input().split()
i = 1
temp = 1
c_out = []
while i < len(s):
	if s[i] == s[i - 1]:
		temp += 1
	else:
		c_out.append(temp)
		temp = 1
	i += 1
c_out.append(temp)
i = 0
maxo = 0
while i < len(c_out) - 1:
	maxo = max(maxo, 2 * min(c_out[i], c_out[i + 1]))
	i += 1
print(maxo)


n = int(input())
l = input().split()
l = [int(i) for i in l]
k = []
comp = 1
for i in range(1, n):
	if l[i] == l[i - 1]:
		comp += 1
	else:
		k += [comp]
		comp = 1
k += [comp]
maxi = min(k[0], k[1])
for i in range(1, len(k) - 1):
	if min(k[i], k[i + 1]) > maxi:
		maxi = min(k[i], k[i + 1])
print(maxi * 2)


n = int(input())
a = [int(x) for x in input().split()]
i = 0
mx = -1
c1 = 0
while i < n:
	c2 = 0
	while i < n and a[i] == 2:
		i += 1
		c2 += 1
	res = 2 * min(c1, c2)
	if res > mx:
		mx = res
	c1 = 0
	while i < n and a[i] == 1:
		i += 1
		c1 += 1
	res = 2 * min(c1, c2)
	if res > mx:
		mx = res
print(mx)


from itertools import groupby

def sushi(arr1):
	a = [len([*g]) for (k, g) in groupby(arr1.split())]
	return 2 * max(list(map(min, zip(a, a[1:]))))
n = int(input())
arr1 = input()
print(sushi(arr1))


import sys
input = sys.stdin.readline
I = lambda : list(map(int, input().split()))
for tc in range(1):
	(n,) = I()
	l = I()
	ans = 0
	x = 0
	y = 0
	f = 0
	xx = 0
	yy = 0
	for i in range(n):
		if l[i] == 1:
			if x == 0:
				yy = y
			y = 0
			x += 1
			if yy:
				ans = max(ans, min(yy, x) * 2)
		else:
			if y == 0:
				xx = x
			y += 1
			x = 0
			if xx:
				ans = max(ans, min(xx, y) * 2)
	print(ans)


input()
inputlist = map(int, input().split())
counter = {1: 0, 2: 0}
current_type = 0
_max = 0
for i in inputlist:
	if current_type == 0:
		current_type = i
	if current_type == i:
		counter[i] += 1
	elif counter[i] == 0:
		current_type = i
		counter[i] += 1
	else:
		_min = counter[1] if counter[1] < counter[2] else counter[2]
		if _max < _min * 2:
			_max = _min * 2
		counter[i] = 1
		current_type = i
_min = counter[1] if counter[1] < counter[2] else counter[2]
if _max < _min * 2:
	_max = _min * 2
print(_max)


from itertools import groupby

def solve(A, n):
	lst = []
	for (_, group) in groupby(A):
		lst.append(list(group))
	res = 0
	for i in range(1, len(lst)):
		mn = min(len(lst[i - 1]), len(lst[i]))
		res = max(2 * mn, res)
	return res
n = int(input())
arr = input().split(' ')
A = [int(n) for n in arr]
print(solve(A, n))


(s, a, b) = (1, [], [])
n = int(input())
l = list(map(int, input().split()))
for x in range(n - 1):
	if l[x] == l[x + 1] and x != n - 2:
		s += 1
	elif x == n - 2:
		if l[x] == l[x + 1]:
			a.append(s + 1)
		else:
			a.append(s)
			a.append(1)
	else:
		a.append(s)
		s = 1
for x in range(len(a) - 1):
	b.append(min(a[x], a[x + 1]))
print(2 * max(b))


from sys import stdin

def iinput():
	return int(stdin.readline())

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

def linput():
	return list(map(int, stdin.readline().split()))
n = iinput()
a = linput()
(ct, ce) = (0, 0)
mx = 0
for i in range(n):
	if a[i] == 1:
		ct += 1
	else:
		ce += 1
	if i > 0 and a[i] != a[i - 1]:
		if a[i] == 2:
			ce = 1
		else:
			ct = 1
	mx = max(mx, min(ce, ct) * 2)
print(mx)


n = int(input())
l2 = input()
l = []
i = int(0)
k = 1
t = 1
max1 = 1
max2 = 1
for i in range(0, n * 2 - 1):
	if l2[i] != ' ':
		l.append(l2[i])
for i in range(0, n - 1):
	if l[i] == l[i + 1]:
		k += 1
	else:
		g = i + 1
		for g in range(g, n - 1):
			if l[g] == l[g + 1]:
				t += 1
				if k <= t:
					max1 = k
				else:
					max1 = t
			else:
				k = 1
				t = 1
				break
			g += 1
	if max1 > max2:
		max2 = max1
	i += 1
print(int(max2 * 2))


n = int(input())
sushi = [int(x) for x in input().split(' ')]
l = list()
cnt = 1
for i in range(1, n):
	if sushi[i] == sushi[i - 1]:
		cnt += 1
	else:
		l.append(cnt)
		cnt = 1
if cnt >= 1:
	l.append(cnt)
max_l = 2
max_q = 0
for i in range(1, len(l)):
	if l[i] >= l[i - 1]:
		max_q = l[i - 1] * 2
	else:
		max_q = l[i] * 2
	if max_q > max_l:
		max_l = max_q
print(max_l)


n = int(input())
arr = list(map(int, input().split()))
groups = []
c = 1
for (i, _) in enumerate(arr[1:]):
	i += 1
	if arr[i] == arr[i - 1]:
		c += 1
	else:
		groups.append(c)
		c = 1
groups.append(c)
max = -1
for (g, _) in enumerate(groups[:-1]):
	ans = min(groups[g], groups[g + 1])
	if ans > max:
		max = ans
print(max * 2)


n = int(input())
a = list(map(int, input().split()))
b = 1
d = 1
e = []
g = []
for i in range(n - 1):
	if a[i] == a[i + 1]:
		b += 1
	else:
		e.append(b)
		b = 1
e.append(b)
h = 0
for i in range(len(e) - 1):
	h = max(h, min(e[i], e[i + 1]))
print(2 * h)


n = int(input())
t = [*map(int, input().split())]
v = [-1] + [i for (i, x, y) in zip(range(n), t, t[1:]) if x != y] + [n - 1]
v = [y - x for (x, y) in zip(v, v[1:])] + [0]
print(max(map(min, zip(v, v[1:]))) * 2)


n = int(input())
a = list(map(int, input().split()))
a.append(-1)
k = 1
pre = 0
ans = 0
for i in range(1, n + 1):
	if a[i] == a[i - 1]:
		k = k + 1
	else:
		ans = max(ans, min(k, pre))
		pre = k
		k = 1
print(ans * 2)


n = int(input())
t = list(map(int, input().split()))
l = 0
r = 0
cnt1 = 0
cnt2 = 0
tmp = 0
state = 0
ans = 0
while l < n:
	while r < n and t[l] == t[r]:
		if state == 0:
			cnt1 += 1
		else:
			cnt2 += 1
		r += 1
	if state == 0:
		ans = max(ans, 2 * min(tmp, cnt1))
		tmp = cnt1
		cnt1 = 0
		state = 1
	else:
		ans = max(ans, 2 * min(tmp, cnt2))
		tmp = cnt2
		cnt2 = 0
		state = 0
	l = r
print(ans)


num = input()
q = input()
w = q.split(' ')
leng1 = len(w)
a = w[0]
t = 0
L2 = 0
r = []
for i in range(leng1):
	if w[i] == a:
		t += 1
	else:
		r.append(t)
		t = 1
		a = w[i]
	if i == leng1 - 1:
		r.append(t)
Max = 0
for i in range(len(r) - 1):
	d = min(r[i], r[i + 1])
	if Max < d:
		Max = d
print(Max * 2)


t = int(input())
d = list(map(int, input().split()))
values = []
count = 1
for j in range(len(d) - 1):
	if d[j] == d[j + 1]:
		count += 1
	else:
		values.append(count)
		count = 1
values.append(count)
maximum = 0
for j in range(len(values) - 1):
	prv = min(values[j], values[j + 1]) * 2
	if maximum < prv:
		maximum = prv
print(maximum)


two = 0
one = 0
max = 0

def oop(a):
	global one
	global two
	if a == 1:
		one += 1
	else:
		two += 1
n = int(input())
p = list(map(int, input().split()))
for i in range(n - 1):
	if p[i] == p[i + 1] and i != n - 2:
		oop(p[i])
	elif p[i] == 2 and i != n - 2:
		if one == 0:
			oop(p[i])
		else:
			oop(p[i])
			if max < 2 * min(one, two):
				max = 2 * min(one, two)
			one = 0
	elif p[i] == 1 and i != n - 2:
		if two == 0:
			oop(p[i])
		else:
			oop(p[i])
			if max < 2 * min(one, two):
				max = 2 * min(one, two)
			two = 0
	elif i == n - 2:
		oop(p[i])
		oop(p[i + 1])
		if max < 2 * min(one, two):
			max = 2 * min(one, two)
print(max)


n = int(input())
a = list(map(int, input().split()))
c = 0
d = []
x = a[0]
for i in a:
	if i == x:
		c = c + 1
	else:
		d.append(c)
		c = 1
		if x == 2:
			x = 1
		else:
			x = 2
d.append(c)
m = 0
for i in range(len(d) - 1):
	c = min(d[i], d[i + 1])
	if c >= m:
		m = c
print(m * 2)


n = int(input())
a = list(map(int, input().split()))
prev_type = None
l_count = None
now_type = a[0]
n_count = 1
i = 1
res = 0
while i < n:
	if a[i] != now_type:
		if prev_type != None:
			res = max(res, min(l_count, n_count) * 2)
		prev_type = now_type
		l_count = n_count
		now_type = a[i]
		n_count = 1
	else:
		n_count += 1
	i += 1
res = max(res, min(l_count, n_count) * 2)
print(res)


(c1, c2, l1, l2) = (0, 0, 0, 0)
l = -1
input()
an = -1
A = list(map(int, input().split()))
for a in A:
	if a != l:
		l = a
		if a == 1:
			l2 = c2
			c2 = 0
			c1 = 1
			if an == -1:
				an = min(c1, l2) * 2
			else:
				an = max(an, min(c1, l2) * 2)
		if a == 2:
			l1 = c1
			c1 = 0
			c2 = 1
			if an == -1:
				an = min(c2, l1) * 2
			else:
				an = max(an, min(c2, l1) * 2)
	elif a == l:
		if a == 1:
			c1 += 1
			an = max(an, min(c1, l2) * 2)
		else:
			c2 += 1
			an = max(an, min(c2, l1) * 2)
print(an)


num_sushi = int(input())
sushi_list = [int(x) - 1 for x in input().split()]
record_len = 2
candid_len = [0, 0]
previous_num = sushi_list[0]
initialised = False
for x in sushi_list:
	if x != previous_num:
		previous_num = x
		if not initialised:
			initialised = True
			candid_len = [candid_len[1], 1]
		else:
			record_len = max(record_len, min(candid_len) * 2)
			candid_len = [candid_len[1], 1]
	else:
		candid_len[1] += 1
record_len = max(record_len, min(candid_len) * 2)
print(record_len)


n = int(input())
a = list(map(int, input().split()))
sol = 0
for i in range(n - 1):
	if a[i] != a[i + 1]:
		sol = max(sol, 2)
		d = 1
		while i - d >= 0 and i + 1 + d < n:
			if a[i - d] != a[i] or a[i + 1 + d] != a[i + 1]:
				break
			sol = max(sol, (d + 1) * 2)
			d += 1
print(sol)


N = int(input())
arr = list(map(int, input().split()))
narr = []
last = 0
for a in arr:
	if last != a:
		narr.append(1)
		last = a
	else:
		narr[-1] += 1
res = 0
for i in range(len(narr) - 1):
	res = max(res, min(narr[i], narr[i + 1]))
print(res * 2)


from collections import deque, Counter, OrderedDict
from heapq import nsmallest, nlargest
from math import ceil, floor, log, log2, sqrt, gcd, factorial, pow, pi
from bisect import bisect_left

def binNumber(n, size=4):
	return bin(n)[2:].zfill(size)

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

def ini():
	return int(input())

def isp():
	return map(int, input().split())

def sti():
	return str(input())

def par(a):
	print(' '.join(list(map(str, a))))

def tdl(outerListSize, innerListSize, defaultValue=0):
	return [[defaultValue] * innerListSize for i in range(outerListSize)]

def sts(s):
	s = list(s)
	s.sort()
	return ''.join(s)

class pair:

	def __init__(self, f, s):
		self.fi = f
		self.se = s

	def __lt__(self, other):
		return (self.fi, self.se) < (other.fi, other.se)

def BinarySearch(a, x):
	i = bisect_left(a, x)
	if i != len(a) and a[i] == x:
		return i
	else:
		return -1
n = ini()
a = iar()
a1s = []
a1e = []
a2s = []
a2e = []
i = 0
while i < n:
	if a[i] == 1:
		a1s.append(i)
		while i < n:
			if a[i] == 1:
				i += 1
			else:
				break
		a1e.append(i)
		continue
	if a[i] == 2:
		a2s.append(i)
		while i < n:
			if a[i] == 2:
				i += 1
			else:
				break
		a2e.append(i)
ma = -1
for i in range(len(a1s)):
	j = BinarySearch(a2e, a1s[i])
	if j != -1:
		ma = max(ma, min(a2e[j] - a2s[j], a1e[i] - a1s[i]))
for i in range(len(a1s)):
	j = BinarySearch(a2s, a1e[i])
	if j != -1:
		ma = max(ma, min(a2e[j] - a2s[j], a1e[i] - a1s[i]))
for i in range(len(a2s)):
	j = BinarySearch(a1e, a2s[i])
	if j != -1:
		ma = max(ma, min(a1e[j] - a1s[j], a2e[i] - a2s[i]))
for i in range(len(a2s)):
	j = BinarySearch(a1s, a2e[i])
	if j != -1:
		ma = max(ma, min(a1e[j] - a1s[j], a2e[i] - a2s[i]))
print(ma * 2)


import sys
from typing import NamedTuple

class Block(NamedTuple):
	number: int
	count: int
A = sys.stdin.readline()
B = list(map(int, sys.stdin.readline().split(' ')))
number = B[0]
size = 1
blocks = []
for i in range(1, len(B)):
	if B[i] == number:
		size += 1
	else:
		block = Block(number, size)
		blocks.append(block)
		size = 1
		number = B[i]
block = Block(number, size)
blocks.append(block)
ans = 2
for i in range(len(blocks) - 1):
	ans = max(ans, min(blocks[i].count, blocks[i + 1].count) * 2)
print(ans)


n = int(input())
l = list(map(int, input().split()))
c = 0
i = 0
while i < n:
	a = i
	d = 1
	while a < n - 1 and l[a] == l[a + 1]:
		d += 1
		a += 1
	b = a + 1
	e = 1
	while b < n - 1 and l[b] == l[b + 1]:
		e += 1
		b += 1
	c = max(c, min(d, e) * 2)
	i = a + 1
print(c)


n = int(input())
sushi = [int(x) for x in input().strip().split()]
i = 0
arr = []
while i < n:
	one = 0
	two = 0
	while i < n and sushi[i] == 1:
		one += 1
		i += 1
		if i == n:
			break
	while i < n and sushi[i] == 2:
		two += 1
		i += 1
		if i == n:
			break
	if one > 0:
		arr.append(one)
	if two > 0:
		arr.append(two)
res = 0
l = len(arr)
for i in range(l - 1):
	res = max(res, min(arr[i], arr[i + 1]))
print(res * 2)


b = int(input())
a = list(map(int, input().split()))
t = a[0]
ci = 1
w = [1]
for i in range(1, len(a)):
	if a[i] == t:
		ci += 1
	else:
		t = a[i]
		ci = 1
	w.append(ci)
qw = []
r = []
for i in range(1, len(w)):
	if w[i - 1] + 1 == w[i]:
		r.append(i - 1)
		w[i - 1] = -1
rt = []
for i in range(len(w)):
	if w[i] == -1:
		ert = 0
	else:
		rt.append(w[i])
for i in range(1, len(rt)):
	qw.append(2 * min(rt[i], rt[i - 1]))
qw.sort()
print(qw[-1])


n = int(input())
L = list(map(int, input().split())) + [0]
ans = 0
ans_cur = 0
cur_old = 0
cur = 1
for i in range(1, len(L)):
	if L[i] == L[i - 1]:
		cur += 1
	else:
		ans_cur = min(cur, cur_old)
		if ans_cur > ans:
			ans = ans_cur
		cur_old = cur
		cur = 1
		ans_cur = 0
print(ans * 2)


import itertools
n = int(input())
t = list(map(int, input().split()))
l = [len(list(g)) for (k, g) in itertools.groupby(t)]
print(max((2 * min(a, b) for (a, b) in zip(l, l[1:]))))


n = int(input())
num = input().split()
chain = []
flag = 1
x = 0
y1 = 0
y2 = 0
for i in range(1, n):
	if num[i] != num[i - 1]:
		y1 = y2
		y2 = i
		flag *= -1
		if flag == 1:
			chain.append(2 * min(i - y1, y1 - x))
			x = y1
			flag = -1
chain.append(2 * min(n - y2, y2 - y1))
print(max(chain))


m = int(input())
l = list(map(int, input().split()))
s = 0
a = 0
ans = 0
sm = 1
if l[0] == 1:
	s += 1
else:
	a += 1
for i in range(1, m):
	if l[i] == 1 and l[i - 1] == 1:
		s += 1
	elif l[i] == 2 and l[i - 1] == 2:
		a += 1
	elif l[i] == 2 and l[i - 1] == 1:
		a = 0
		a += 1
	else:
		s = 0
		s += 1
	ans = min(a, s)
	if 2 * ans > sm:
		sm = 2 * ans
print(sm)


sushi = input()
serial = input().split()
ways = [2]
for i in range(0, int(sushi)):
	serial[i] = int(serial[i])
else:
	for i in range(1, int(sushi) - 1):
		if serial[i] != serial[i + 1]:
			if i < int(sushi) // 2:
				x = i + 1
			else:
				x = int(sushi) - i - 1
			way = 2
			for j in range(1, x):
				if serial[i] == serial[i - j] and serial[i + 1] == serial[i + 1 + j]:
					way = way + 2
				else:
					break
			ways.append(way)
print(max(ways))


n = int(input())
a = list(map(int, input().split()))
p = 0
c = 0
m = 0
P = -1
for i in range(n):
	if P != a[i]:
		P = a[i]
		m = max(m, min(c, p) + min(c, p))
		p = c
		c = 1
	else:
		c += 1
m = max(m, min(c, p) + min(c, p))
print(m)


TN = 1

def solution():
	n = int(input())
	t = list(map(int, input().split()))
	anss = []
	cur = t[0]
	an_s = 0
	for i in range(n):
		if t[i] == cur:
			an_s += 1
		else:
			anss.append(an_s)
			cur = t[i]
			an_s = 1
	anss.append(an_s)
	ans = []
	for i in range(len(anss) - 1):
		ans.append(min(anss[i], anss[i + 1]) * 2)
	print(max(ans))
while TN != 0:
	solution()
	TN -= 1


from itertools import groupby
n = input()
l = map(int, input().split())
ans = 0
l = [(k, len(list(g))) for (k, g) in groupby(l)]
for i in range(len(l) - 1):
	ans = max(ans, min(l[i][1], l[i + 1][1]))
print(ans + ans)


arraylen = int(input())
array = list(map(int, input().split()))
cont = None
um = 0
dois = 0
resultado = 0
if array[0] == 1:
	um = 1
else:
	dois = 1
for i in range(1, arraylen):
	if array[i - 1] != array[i]:
		if cont == None:
			cont = False
		else:
			cont = True
	if cont == True:
		resultado = max(resultado, min(dois, um))
		if array[i] == 1:
			um = 0
		else:
			dois = 0
		cont = False
	if array[i] == 1:
		um += 1
	else:
		dois += 1
resultado = max(resultado, min(dois, um)) * 2
print(resultado)


x = int(input())
l = list(map(int, input().split()))
L = []
m = []
c = 1
for i in range(0, len(l) - 1):
	if l[i] == l[i + 1]:
		c += 1
	else:
		L.append(c)
		c = 1
L.append(c)
for i in range(0, len(L) - 1):
	if L[i] < L[i + 1]:
		m.append(L[i])
	else:
		m.append(L[i + 1])
print(2 * max(m))


n = int(input())
t = list(map(int, input().split()))
ones = 0
twos = 0
max = 0
for (i, sushi) in enumerate(t):
	if i > 0 and t[i - 1] == 1 and (t[i] == 2):
		if min(ones, twos) * 2 > max:
			max = min(ones, twos) * 2
		twos = 0
	elif i > 0 and t[i - 1] == 2 and (t[i] == 1):
		if min(ones, twos) * 2 > max:
			max = min(ones, twos) * 2
		ones = 0
	if sushi == 1:
		ones += 1
	else:
		twos += 1
if min(ones, twos) * 2 > max:
	max = min(ones, twos) * 2
print(max)


def main():
	n = int(input())
	types = input().strip().split(' ')
	freq = []
	counter = 1
	for i in range(1, n):
		if types[i - 1] == types[i]:
			counter += 1
		else:
			freq.append(counter)
			counter = 1
			continue
	freq.append(counter)
	max_len = 0
	for i in range(1, len(freq)):
		min_val = min(freq[i - 1], freq[i])
		if min_val * 2 > max_len:
			max_len = min_val * 2
	print(max_len)
main()


n = int(input())
t = list(map(int, input().split()))
f = 0
counter = 1
final = 0
for i in range(0, n - 1):
	if t[i] == t[i + 1]:
		counter += 1
	elif t[i] != t[i + 1]:
		final = max(final, min(f, counter))
		f = counter
		counter = 1
print(max(final, min(f, counter)) * 2)


n = int(input())
sushi = [int(x) for x in input().split()]
sushi.append(3)
tot = []
counter = 1
for i in range(1, n + 1):
	if sushi[i] == sushi[i - 1]:
		counter += 1
	else:
		tot.append(counter)
		counter = 1
answer = 0
for i in range(1, len(tot)):
	answer = max(answer, min(tot[i], tot[i - 1]) * 2)
print(answer)


PIEZAS = list(map(int, input().split()))
ARREGLODETIPOS = list(map(int, input().split()))
if ARREGLODETIPOS[PIEZAS[0] - 1] == 1:
	ARREGLODETIPOS.append(2)
elif ARREGLODETIPOS[PIEZAS[0] - 1] == 2:
	ARREGLODETIPOS.append(1)
cont1 = 0
cont2 = 0
arreglorepetidos = []
arregloacomodado = []
cont1 = 1
cont2 = 1
for i in range(PIEZAS[0]):
	if ARREGLODETIPOS[i] == 1:
		if ARREGLODETIPOS[i + 1] == 1:
			cont1 += 1
		elif ARREGLODETIPOS[i + 1] == 2:
			arreglorepetidos.append(cont1)
			cont1 = 1
			cont2 = 1
	elif ARREGLODETIPOS[i] == 2:
		if ARREGLODETIPOS[i + 1] == 2:
			cont2 += 1
		elif ARREGLODETIPOS[i + 1] == 1:
			arreglorepetidos.append(cont2)
			cont1 = 1
			cont2 = 1
for m in range(len(arreglorepetidos) - 1):
	if arreglorepetidos[m] <= arreglorepetidos[m + 1]:
		arregloacomodado.append(arreglorepetidos[m] * 2)
	else:
		arregloacomodado.append(arreglorepetidos[m + 1] * 2)
arregloacomodado.sort(reverse=True)
print(arregloacomodado[0])


n = int(input())
s = input()
a = list(map(len, s.replace('1 2', '1*2').replace('2 1', '2*1').replace(' ', '').split('*')))
n2 = len(a)
mx = -1
for i in range(1, n2):
	if min(a[i - 1], a[i]) > mx:
		mx = min(a[i - 1], a[i])
print(mx * 2)


n = int(input())
l = list(map(int, input().split()))
l.append(0)
(a, b, ans) = (0, 0, 0)
for i in range(n):
	a += 1
	if l[i] != l[i + 1]:
		ans = max(ans, min(a, b))
		b = a
		a = 0
print(2 * ans)


def a(inp):
	ranges = []
	curr = inp[0]
	start = 0
	end = 0
	for (index, i) in enumerate(inp[1:]):
		if curr == i:
			end = index + 1
		else:
			ranges.append(end - start + 1)
			curr = i
			start = index + 1
			end = index + 1
	ranges.append(end - start + 1)
	print(2 * max([min(a, b) for (a, b) in zip(ranges, ranges[1:])]))
n = int(input())
t = list(map(int, input().split()))
a(t)


size = int(input())

def segment(array):
	aux = []
	el = int(array[0])
	count = 0
	for i in range(len(array)):
		if int(array[i]) == el:
			count += 1
		else:
			aux.append(count)
			count = 1
			el = int(array[i])
	aux.append(count)
	return aux

def maxx(array):
	max_ = 0
	for i in range(1, len(array)):
		max_ = max(max_, min(array[i - 1], array[i]))
	return 2 * max_
segments = input().split()
aux = segment(segments)
print(maxx(aux))


n = int(input())
mas = input().split(' ')
t = 1
u = 1
rez = 0
for i in range(len(mas) - 1):
	if mas[i] == mas[i + 1] and mas[i] == '1':
		t += 1
	if mas[i] == mas[i + 1] and mas[i] == '2':
		u += 1
	if mas[i] != mas[i + 1] and mas[i] == '1':
		u = 1
	if mas[i] != mas[i + 1] and mas[i] == '2':
		t = 1
	rez = max(rez, 2 * min(u, t))
print(rez)


n = input()
x = list(map(str, input().split()))
counteur = 1
listlen = []
for i in range(0, len(x) - 1):
	if x[i + 1] == x[i]:
		counteur += 1
	else:
		listlen.append(counteur)
		counteur = 1
listlen.append(counteur)
lismax = []
for i in range(len(listlen) - 1):
	Emin = listlen[i]
	if Emin < listlen[i + 1]:
		lismax.append(Emin)
	else:
		lismax.append(listlen[i + 1])
print(max(lismax) * 2)


N = int(input().strip())
nums = [int(i) for i in input().strip().split()]
left_num = nums[0]
left_count = 1
ans = 0
prev = 0
num_dict = {1: 0, 2: 0}
num_dict[left_num] += 1
for i in range(1, N):
	if nums[i] == left_num:
		num_dict[left_num] += 1
	else:
		num_dict[nums[i]] = 1
		left_num = nums[i]
	result = min(num_dict[1], num_dict[2]) * 2
	if result > ans:
		ans = result
print(ans)


x = int(input())
a = list(map(int, input().split())) + [0]
m = n = p = 0
for i in range(x):
	m += 1
	if a[i] != a[i + 1]:
		p = max(p, min(m, n))
		n = m
		m = 0
print(2 * p)


from sys import stdin
n = int(stdin.readline().strip())
s = list(map(int, stdin.readline().strip().split()))
s1 = []
x = 1
for i in range(1, n):
	if s[i] != s[i - 1]:
		s1.append(x)
		x = 1
	else:
		x += 1
s1.append(x)
ans = 0
for i in range(1, len(s1)):
	ans = max(ans, min(s1[i], s1[i - 1]) * 2)
print(ans)


n = int(input())
l = list(map(int, input().split()))
i = 0
z = l[0]
prev = 0
for i in range(n):
	if l[i] != z:
		break
	else:
		prev += 1
maxi = 0
while i < n:
	count = 0
	z = l[i]
	for j in range(i, n):
		if l[j] != z:
			break
		else:
			count += 1
	if l[j] != z:
		i = j
	else:
		i = j + 1
	maxi = max(maxi, min(count, prev))
	prev = count
print(2 * maxi)


def solve(arr):
	count_list = []
	cont = 1
	for i in range(1, len(arr)):
		if arr[i] == arr[i - 1]:
			cont += 1
		else:
			count_list.append(cont)
			cont = 1
	count_list.append(cont)
	ans = 0
	for i in range(1, len(count_list)):
		ans = max(ans, min(count_list[i - 1], count_list[i]) * 2)
	return ans
n = input()
arr = input().split(' ')
print(solve(arr))


from collections import deque as de
import math
from collections import Counter as cnt
from functools import reduce
from typing import MutableMapping
from itertools import groupby as gb
from fractions import Fraction as fr

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))

class My_stack:

	def __init__(self):
		self.data = []

	def my_push(self, x):
		return self.data.append(x)

	def my_pop(self):
		return self.data.pop()

	def my_peak(self):
		return self.data[-1]

	def my_contains(self, x):
		return self.data.count(x)

	def my_show_all(self):
		return self.data

	def isEmpty(self):
		return len(self.data) == 0
arrStack = My_stack()

def decimalToBinary(n):
	return bin(n).replace('0b', '')

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

def get_prime_factors(number):
	prime_factors = []
	while number % 2 == 0:
		prime_factors.append(2)
		number = number / 2
	for i in range(3, int(math.sqrt(number)) + 1, 2):
		while number % i == 0:
			prime_factors.append(int(i))
			number = number / i
	if number > 2:
		prime_factors.append(int(number))
	return prime_factors

def get_frequency(list):
	dic = {}
	for ele in list:
		if ele in dic:
			dic[ele] += 1
		else:
			dic[ele] = 1
	return dic

def Log2(x):
	return math.log10(x) / math.log10(2)

def isPowerOfTwo(n):
	return math.ceil(Log2(n)) == math.floor(Log2(n))

def ceildiv(x, y):
	return (x + y - 1) // y
n = int(input())
t = list(map(int, input().split()))
grouping = []
curr = 1
lastcheck = 1
for i in range(1, n):
	if t[i] != t[i - 1]:
		grouping.append(curr)
		curr = 1
		if i == n - 1:
			lastchekcheck = 0
	else:
		curr += 1
if lastcheck:
	grouping.append(curr)
maxlen = 0
for i in range(1, len(grouping)):
	if min(grouping[i], grouping[i - 1]) * 2 > maxlen:
		maxlen = 2 * min(grouping[i], grouping[i - 1])
print(maxlen)


(n, a) = (int(input()), input().split())
k = m = 0
b = []
for i in a:
	if i != k:
		b.append(m)
		m = 1
	else:
		m += 1
	k = i
b.append(m)
print(max([min(i) for i in zip(b[1:], b[2:])]) * 2)


(n, s) = (int(input()), '')
l = input().split()
for i in l:
	s += i
(k, count_1, count_2, j) = ([], 0, 0, [])
for i in range(n):
	count_2 = count_1 = 0
	if s:
		for p in s:
			if p == '1':
				count_1 += 1
			else:
				break
		for q in s:
			if q == '2':
				count_2 += 1
			else:
				break
		if count_2 > 0 and count_1 > 0:
			k.append(count_2)
			k.append(count_1)
			s = s[count_1 + count_2:]
		elif count_1 > 0:
			k.append(count_1)
			s = s[count_1:]
		elif count_2 > 0:
			k.append(count_2)
			s = s[count_2:]
	else:
		break
for f in range(len(k) - 1):
	j.append(min(k[f], k[f + 1]))
print(2 * max(j))


def main():
	tuna = 0
	eel = 0
	max_len = 0
	n = int(input())
	sushi = list(map(int, input().split()))
	curr = sushi[0]
	for i in range(n):
		if sushi[i] == curr:
			if sushi[i] == 1:
				tuna += 1
			else:
				eel += 1
		else:
			if tuna > 0 and eel > 0:
				max_len = max(max_len, 2 * min(eel, tuna))
				if curr == 1:
					eel = 0
				else:
					tuna = 0
			curr = sushi[i]
			if curr == 1:
				tuna += 1
			else:
				eel += 1
	if tuna > 0 and eel > 0:
		max_len = max(max_len, 2 * min(eel, tuna))
	print(max_len)
main()


from collections import defaultdict
qtd = int(input())
sushi = list(map(int, input().split()))
sushi.append(0)
(pecas, atual, sequencia) = (list(), sushi[0], 0)
for peca in sushi:
	if atual != peca:
		pecas.append(sequencia)
		atual = peca
		sequencia = 0
	sequencia += 1
res = 0
for i in range(1, len(pecas)):
	valor = 2 * min(pecas[i - 1], pecas[i])
	if valor > res:
		res = valor
print(res)


length = int(input())
nums = list(map(int, input().split(' ')))
seq = []
count = 1
for (i, n) in enumerate(nums):
	if i == 0:
		continue
	if nums[i - 1] == n:
		count += 1
	else:
		seq.append(count)
		count = 1
seq.append(count)
minVal = 0
for (i, s) in enumerate(seq):
	if i == 0:
		continue
	t = min(seq[i - 1], s)
	if t > minVal:
		minVal = t
print(minVal * 2)


n = int(input())
t = map(lambda x: int(x) - 1, input().split())
counts = [0, 0]
best = 0
phase = 0
for i in t:
	if i != phase:
		phase = i
		if counts[i] != 0:
			best = max(best, min(counts))
			counts[i] = 0
	counts[i] += 1
best = max(best, min(counts))
print(2 * best)


n = int(input())
t = list(map(int, input().split()))
ls = []
temp = 1
for i in range(1, n):
	if t[i] == t[i - 1]:
		temp += 1
	else:
		ls.append(temp)
		temp = 1
ls.append(temp)
ans = 0
for i in range(len(ls) - 1):
	ans = max(ans, 2 * min(ls[i], ls[i + 1]))
print(ans)


n = int(input())
arr = list(map(int, input().split()))
ans = 0
prev = -1
curr = 1
for i in range(1, n):
	if arr[i] == arr[i - 1]:
		curr += 1
	else:
		ans = max(ans, min(curr, prev) << 1)
		prev = curr
		curr = 1
ans = max(ans, min(curr, prev) << 1)
print(ans)


amount = int(input())
array = [int(s) for s in input().split()]
curr = 0
pred = 0
ans = -1
i = 1
while i < len(array):
	if array[i] == array[i - 1]:
		curr += 1
	else:
		pred = curr
		curr = 0
	i += 1
	ans = max(min(pred, curr), ans)
if ans == 0 and (sum(array) == amount or sum(array) == 2 * amount):
	print(0)
else:
	print((ans + 1) * 2)


n = int(input())
lst = list(map(int, input().split()))
lst.append(0)
(a, b, c, l, s) = (0, 0, 0, [0], [])
for i in range(n + 1):
	if lst[i] == 1:
		a = a + 1
		if lst[i] == 1 and lst[i + 1] != 1:
			l.append(min(a, b) * 2)
			b = 0
	elif lst[i] == 2:
		b = b + 1
		if lst[i] == 2 and lst[i + 1] != 2:
			l.append(min(a, b) * 2)
			a = 0
print(max(l))


n = int(input())
l = list()
last_ch = ''
for ch in input().split():
	if last_ch == '' or last_ch != ch:
		l.append(1)
		last_ch = ch
	else:
		l[-1] += 1
max_len = 0
for idx in range(1, len(l)):
	if l[idx - 1] > max_len and l[idx] > max_len:
		max_len = min(l[idx - 1], l[idx])
print(max_len * 2)


N = int(input())
leng = 1
max_leng = 1
last_type_leng = 1
max_now = 1
A = list(map(int, input().split()))
last_one = A[0]
for i in range(1, N):
	if A[i] == last_one:
		leng += 1
		last_one = A[i]
		if last_type_leng > leng:
			max_now = leng * 2
		else:
			max_now = last_type_leng * 2
	else:
		last_type_leng = leng
		leng = 1
		last_one = A[i]
		if last_type_leng > leng:
			max_now = leng * 2
		else:
			max_now = last_type_leng * 2
	if max_now > max_leng:
		max_leng = max_now
print(max_leng)


n = int(input())
li = list(map(int, input().split()))
arr = []
k = 1
for i in range(1, n):
	if li[i] == li[i - 1]:
		k += 1
	else:
		arr.append(k)
		k = 1
arr.append(k)
h = len(arr)
if h > 1:
	minm = []
	for i in range(h - 1):
		minm.append(min(arr[i], arr[i + 1]))
	print(2 * max(minm))
else:
	print('0')


n = int(input())
t = list(map(int, input().split()))
b = [0, 0, 0]
ot = 0
if n == 2:
	print(2)
else:
	b[t[0]] += 1
	for i in range(1, n):
		if t[i - 1] != t[i]:
			b[t[i]] = 0
		b[t[i]] += 1
		ot = max(ot, min(b[1], b[2]) * 2)
	print(ot)


n = int(input())
t = list(map(int, input().split()))
last = t[0]
best = 1
cslice = 1
lslice = 1
for cur in t[1:]:
	if cur == last:
		cslice += 1
	else:
		best = max(best, min(cslice, lslice))
		lslice = cslice
		cslice = 1
	last = cur
best = max(best, min(cslice, lslice))
print(2 * best)


def solve(a, n):
	new = []
	i = 0
	while i < n:
		cnt = 0
		if a[i] == 1:
			while i < n and a[i] == 1:
				i += 1
				cnt += 1
			new.append(cnt)
		else:
			while i < n and a[i] == 2:
				i += 1
				cnt += 1
			new.append(cnt)
	mx = 0
	for i in range(1, len(new)):
		mx = max(2 * min(new[i], new[i - 1]), mx)
	return mx
n = int(input())
a = list(map(int, input().split()))
print(solve(a, n))


n = int(input())
arr = list(map(int, input().split()))
ans = []
i = 0
c = 0
pre = -1
while i < n:
	if i == 0:
		pre = arr[i]
		c += 1
	elif pre == arr[i]:
		c += 1
	else:
		ans.append([pre, c])
		pre = arr[i]
		c = 1
	i += 1
ans.append([pre, c])
aa = 0
for i in range(len(ans) - 1):
	aa = max(aa, 2 * min(ans[i][1], ans[i + 1][1]))
print(aa)


from sys import stdin, stdout
INF = 100000000000.0
import bisect

def get_int():
	return int(stdin.readline().strip())

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

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

def get_string():
	return stdin.readline().strip()

def op(c):
	return stdout.write(c)
n = get_int()
arr = get_array()
(c1, c2) = (0, 0)
ans = 0
last = 9
for i in range(n):
	if arr[i] != last:
		if arr[i] == 1:
			c1 = 1
		else:
			c2 = 1
		last = arr[i]
	elif arr[i] == 1:
		c1 += 1
	else:
		c2 += 1
	ans = max(ans, min(c1, c2) * 2)
print(ans)


n = int(input())
a = list(map(int, input().split()))
ans = 0
for i in range(n - 1):
	count = 0
	left = a[i]
	right = a[i + 1]
	for x in range(i + 1):
		if left == right:
			break
		if i - x < 0 or i + x + 1 >= n:
			break
		if a[i - x] != left or a[i + x + 1] != right:
			break
		count += 2
	ans = max(ans, count)
print(ans)


n = int(input())
arr = list(map(int, input().split()))
res = []
cnt = x = 0
for i in range(n):
	if x == arr[i]:
		cnt += 1
	else:
		res.append(cnt)
		x = arr[i]
		cnt = 1
res.append(cnt)
ans = 0
for i in range(len(res) - 1):
	ans = max(min(res[i], res[i + 1]) * 2, ans)
print(ans)


n = int(input())
t = list(map(int, input().split()))
count = 0
freq = [0] * 100010
value = t[0]
for i in range(n):
	if value == t[i]:
		freq[count] += 1
	else:
		value = t[i]
		count += 1
		freq[count] = 1
n_max = 0
for i in range(1, count + 1):
	n_min = min(freq[i], freq[i - 1])
	n_max = max(n_max, n_min)
print(n_max * 2)


from collections import Counter

def main():
	n = int(input())
	t = list(map(int, input().split()))
	counter = Counter()
	counter[t[0]] = 1
	ret = 0
	for i in range(1, n):
		if t[i] == t[i - 1]:
			counter[t[i]] += 1
		else:
			counter[t[i]] = 1
		ret = max(ret, min(counter[1], counter[2]) * 2)
	print(ret)

def __starting_point():
	main()
__starting_point()


def ans(arr):
	cnt = 1
	ans = 0
	cnt1 = 1
	i = 1
	while i < n:
		if arr[i] == arr[i - 1]:
			cnt += 1
		else:
			cnt1 = cnt
			cnt = 1
		ans = max(ans, min(cnt, cnt1))
		i += 1
	return ans * 2
n = int(input())
t = list(map(int, input().strip().split()))
print(ans(t))


n = int(input())
count1 = 2
count = 2
ar = list(map(str, input().split()))
string = ''.join(ar)
i = 0
while i < n:
	right = 1
	left = 1
	try:
		if ar[i] == '2' and ar[i + 1] == '1':
			while True:
				if i + 1 + right > n - 1:
					break
				elif ar[i + 1 + right] == '1':
					right += 1
				else:
					break
			while True:
				if i - left < 0:
					break
				elif ar[i - left] == '2':
					left += 1
				else:
					break
			count1 = 2 * min(left, right)
			if count < count1:
				count = count1
		elif ar[i] == '1' and ar[i + 1] == '2':
			while True:
				if i + 1 + right > n - 1:
					break
				elif ar[i + 1 + right] == '2':
					right += 1
				else:
					break
			while True:
				if i - left < 0:
					break
				elif ar[i - left] == '1':
					left += 1
				else:
					break
			count1 = 2 * min(left, right)
			if count < count1:
				count = count1
		i += right
	except IndexError:
		break
print(count)


def find(n, arr):
	prev = arr[0]
	half = 1
	prev_half = 0
	ans = 0
	for i in range(1, n):
		if arr[i] == prev:
			half += 1
		else:
			prev_half = half
			prev = arr[i]
			half = 1
		ans = max(ans, min(half, prev_half))
	print(ans * 2)

def test(n, a):
	arr = [int(x) for x in a.split(' ')]
	find(int(n), arr)
l1 = input()
l2 = input()
test(l1, l2)


__author__ = 'NIORLYS'
records = []
n = int(input())
t = list(map(int, input().split()))
max_length = 0
i = 0
key = t[i]
count = 1
while True:
	i += 1
	if i > n - 1:
		records.append(count)
		break
	if t[i] != key:
		records.append(count)
		count = 1
		key = t[i]
	else:
		count += 1
for j in range(len(records) - 1):
	max_length = max(min(records[j], records[j + 1]), max_length)
print(max_length * 2)


import sys
lines = sys.stdin.read().splitlines()
n = int(lines[0])
sushi = [int(x) for x in lines[1].split(' ')]
counts = []
cur = sushi[0]
count = 1
for i in range(1, len(sushi)):
	if sushi[i] != cur:
		counts.append(count)
		cur = sushi[i]
		count = 1
	else:
		count += 1
counts.append(count)
maxCount = 0
for i in range(0, len(counts) - 1):
	if min(counts[i], counts[i + 1]) > maxCount:
		maxCount = min(counts[i], counts[i + 1])
print(maxCount * 2)


n = int(input())
sushi = list(map(int, input().split()))
t = 0
e = 0
f = 0
prev = 0
mx = 0
for i in sushi:
	if i == 1:
		if prev == i:
			t += 1
		else:
			prev = i
			m = min(t, e)
			mx = max(mx, m)
			if t != 0:
				t = 0
			t += 1
	elif prev == i:
		e += 1
	else:
		prev = i
		m = min(t, e)
		mx = max(mx, m)
		if e != 0:
			e = 0
		e += 1
m = min(t, e)
mx = max(mx, m)
print(2 * mx)


n = int(input())
a = list(map(int, input().split()))
c = []
(p, q) = (0, 0)
for i in range(n):
	if a[i] == 1:
		p += 1
		if q > 0:
			c.append(q)
			q = 0
	elif a[i] == 2:
		q += 1
		if p > 0:
			c.append(p)
			p = 0
c.append(max(p, q))
r = 0
for i in range(len(c) - 1):
	r = max(r, min(c[i], c[i + 1]))
print(r * 2)


n = int(input())
l = [int(i) for i in input().split()]
ones = []
twos = []
grps = []
i = 0
maxi = 0
while i < n:
	if l[i] == 1:
		c = 0
		while i < n and l[i] == 1:
			i += 1
			c += 1
		grps.append([c, 1])
	else:
		c = 0
		while i < n and l[i] == 2:
			i += 1
			c += 1
		grps.append([c, 2])
for i in range(1, len(grps)):
	if grps[i][1] != grps[i - 1][1]:
		maxi = max(maxi, 2 * min(grps[i][0], grps[i - 1][0]))
print(maxi)


n = int(input())
ts = list(map(int, input().split()))
counts = []
count = 0
counting = 0
for i in range(n):
	t = ts[i]
	if count == 0:
		count += 1
		counting = t
	elif t == counting:
		count += 1
	else:
		counts.append(count)
		count = 1
		counting = t
	if i == n - 1:
		counts.append(count)
streaks = [min(counts[i], counts[i + 1]) for i in range(len(counts) - 1)]
print(max(streaks) * 2)


n = int(input())
a = list(map(int, input().split()))
box = []
num = a[0]
count = 1
for i in range(1, n):
	if a[i] == num:
		count += 1
	else:
		num = a[i]
		box.append(count)
		count = 1
box.append(count)
if len(box) == 1:
	print(0)
	exit()
ans = 0
for (x, y) in zip(box, box[1:]):
	ans = max(ans, min(x, y))
print(ans * 2)


n = int(input())
a = list(map(int, input().split()))
o = []
i = 0
j = 0
c = 0
while j < n:
	if a[i] == a[j]:
		c = c + 1
		j = j + 1
	else:
		i = j
		o.append(c)
		c = 0
o.append(c)
j = 0
m = 0
p = 0
for j in range(1, len(o)):
	i = j - 1
	p = min(o[i], o[j])
	if m < p:
		m = p
print(2 * m)


n = int(input())
a = list(map(int, input().split()))
c = [1]
ans = []
for i in range(1, n):
	if a[i] == 1 and a[i - 1] == 1 or (a[i] == 2 and a[i - 1] == 2):
		c[len(c) - 1] += 1
	else:
		c.append(1)
for i in range(len(c) - 1):
	ans.append(min(c[i], c[i + 1]))
print(2 * max(ans))


n = int(input())
arr = list(map(int, input().split()))
aux = []
ct = 0
(i, j) = (0, 0)
while j < len(arr):
	i = arr[j]
	while arr[j] == i:
		ct += 1
		j += 1
		if j == len(arr):
			break
	aux.append(ct)
	ct = 0
s = 0
for k in range(len(aux) - 1):
	if aux[k] < aux[k + 1]:
		if aux[k] > s:
			s = aux[k]
	elif aux[k + 1] > s:
		s = aux[k + 1]
print(s * 2)


n = int(input())
t = [int(x) for x in input().split()]
ans = 0
pt = nw = 0
pr = t[0]
for i in range(n):
	k = t[i]
	if k != pr:
		ans = max(ans, min(pt, nw))
		pt = nw
		nw = 1
		pr = k
	else:
		nw += 1
ans = max(ans, min(pt, nw))
print(ans * 2)


(n, a) = (int(input()), [int(b) for b in input().split()])
(q, b, c, mas) = (0, 0, 0, [])
for i in a:
	if i == c:
		q += 1
	if i != c:
		mas.append(min(q, b))
		b = q
		q = 1
		c = i
mas.append(min(q, b))
print(max(mas) * 2)


n = int(input())
s = input().split()
K = []
k = 1
for i in range(n):
	if i + 1 < n and s[i] == s[i + 1]:
		k = k + 1
	else:
		K.append(k)
		k = 1
j = []
for i in range(len(K)):
	if i + 1 < len(K):
		j.append(min(K[i], K[i + 1]))
print(2 * max(j))


def funcao(lista):
	res = []
	i = 0
	j = 0
	while True:
		if j == len(lista) - 1:
			res.append(j - i + 1)
			break
		j += 1
		if int(lista[j]) != int(lista[i]):
			res.append(j - i)
			i = j
	return res
input()
lista = input().split()
res = funcao(lista)
maior = 1
i = 0
while i < len(res) - 1:
	menor = min(int(res[i]), int(res[i + 1]))
	maior = max(maior, menor)
	i += 1
print(maior * 2)


n = int(input())
ls = list(map(int, input().split()))
count = 0
(p1, p2) = (0, 0)
ar = []
cnt = 0
if ls[-1] == 1:
	ls.append(0)
else:
	ls.append(1)
for i in range(1, n + 1):
	if ls[i] == ls[i - 1]:
		cnt += 1
	else:
		ar.append(cnt)
		cnt = 0
mx = 0
for j in range(1, len(ar)):
	k = min(ar[j], ar[j - 1])
	if k > mx:
		mx = k
print((mx + 1) * 2)


k = int(input())
a = list(map(int, input().split()))
v = [0]
for i in range(len(a) - 1):
	if a[i] != a[i + 1]:
		v.append(i + 1)
v.append(len(a))
ans = 0
for i in range(1, len(v) - 1):
	ans = max(ans, min(v[i] - v[i - 1], v[i + 1] - v[i]))
print(ans * 2)


n = int(input())
a = [int(i) for i in input().split()]
b = []
cnt = 1
for i in range(1, len(a)):
	if a[i] == a[i - 1]:
		cnt += 1
	else:
		b.append(cnt)
		cnt = 1
b.append(cnt)
maxx = 0
for i in range(1, len(b)):
	maxx = max(maxx, min(b[i], b[i - 1]))
print(maxx * 2)


n = int(input())
arr = [int(i) for i in input().split()]
l = []
(c1, c2) = (0, 0)
for i in range(n):
	if arr[i] == 1:
		if c2 != 0:
			l.append(c2)
		c2 = 0
		c1 += 1
	else:
		if c1 != 0:
			l.append(c1)
		c1 = 0
		c2 += 1
if arr[-1] == 2:
	l.append(c2)
if arr[-1] == 1:
	l.append(c1)
le = len(l)
ans = 0
for i in range(1, le):
	x = 2 * min(l[i - 1], l[i])
	if x > ans:
		ans = x
print(ans)


n = int(input())
l = list(map(int, input().split()))
count = 0
count1 = 0
ans = 0
x = 0
y = 0
l1 = []
l2 = []
for i in range(n):
	if l[i] == 1:
		count1 = 0
		count += 1
		l1.append(count)
		l2.append(y)
		x = l1[i]
	elif l[i] == 2:
		count = 0
		count1 += 1
		l2.append(count1)
		l1.append(x)
		y = l2[i]
	ans = max(ans, 2 * min(l1[i], l2[i]))
print(ans)


from __future__ import print_function
import sys

class SushiCount:

	def __init__(self):
		self.eel = 0
		self.tuna = 0
		self.TUNA_VALUE = 1
		self.EEL_VALUE = 2
		self.eel_turn = False
		self.max_order = 0

	def eat(self, sushi):
		if self.eel == 0 and self.tuna == 0:
			if sushi == self.EEL_VALUE:
				self.eel_turn = True
				self.eel += 1
			else:
				self.eel_turn = False
				self.tuna += 1
		elif self.eel_turn:
			if sushi == self.EEL_VALUE:
				self.eel += 1
			elif self.tuna == 0:
				self.eel_turn = False
				self.tuna += 1
			else:
				self.check_out()
				self.tuna = 0
				self.eel_turn = False
				self.eat(sushi)
		elif sushi == self.TUNA_VALUE:
			self.tuna += 1
		elif self.eel == 0:
			self.eel_turn = True
			self.eel += 1
		else:
			self.check_out()
			self.eel = 0
			self.eel_turn = True
			self.eat(sushi)

	def check_out(self):
		order_count = min(self.eel, self.tuna)
		if order_count > self.max_order:
			self.max_order = order_count
n = int(input())
sushi_arr = [int(x) for x in input().split()]
sushi_counter = SushiCount()
for i in range(n):
	sushi_counter.eat(sushi_arr[i])
sushi_counter.check_out()
print(sushi_counter.max_order * 2)
pass


n = int(input())
sushis = list(map(int, input().split()))
count = [1]
ans = []
for i in range(0, n - 1):
	if sushis[i] == sushis[i + 1]:
		count[-1] += 1
	else:
		count.append(1)
for i in range(len(count) - 1):
	ans.append(min(count[i], count[i + 1]))
print(2 * max(ans))


def f(n, a_arr):
	if a_arr[0] == 1:
		now_length_1 = 1
		now_length_2 = 0
	else:
		now_length_1 = 0
		now_length_2 = 1
	max_length = 1
	for i in range(1, n):
		if a_arr[i - 1] == a_arr[i]:
			if a_arr[i] == 1:
				now_length_1 += 1
			else:
				now_length_2 += 1
		elif a_arr[i] == 1:
			now_length_1 = 1
		else:
			now_length_2 = 1
		max_length = max(max_length, min(now_length_1, now_length_2))
	return max_length * 2
n = int(input())
a_arr = [*map(int, input().split())]
print(f(n, a_arr))


n = int(input())
s = input()
l = s.split()
a = []
sh = int(l[0])
i = 0
j = 0
a.append(0)
while i < n:
	aux = 0
	while i < n and int(l[i]) == sh:
		a[j] += 1
		i += 1
	if i < n:
		sh = int(l[i])
		j += 1
		a.append(0)
maxim = -1
for i in range(j):
	if 2 * min(a[i], a[i + 1]) > maxim:
		maxim = 2 * min(a[i], a[i + 1])
print(maxim)


n = int(input())
x = list(map(int, input().split()))
(current, maximum) = ([0, 0], [0, 0])
cnt = 1
for i in range(1, n):
	if x[i] == x[i - 1]:
		cnt += 1
	if x[i] != x[i - 1] or i == n - 1:
		current[0] = current[1]
		current[1] = cnt
		if min(current) > min(maximum):
			maximum = current.copy()
		cnt = 1
if min(maximum) != 0:
	print(min(maximum) * 2)
else:
	print(2)


from math import *
import math
n = int(input())
a = [int(i) for i in input().split()]
a += [-1]
ans = 0
p1 = 0
p2 = 0
cnt = 0
p = -1
for i in range(n + 1):
	if p != a[i]:
		if p == 1:
			p1 = cnt
		else:
			p2 = cnt
		cnt = 0
		p = a[i]
	ans = max(ans, min(p1, p2) * 2)
	cnt += 1
print(ans)


from sys import stdout, stdin

def is_empty(_list):
	return len(_list) == 0

def check(result, best_continuous, eel, tuna):
	if eel != tuna:
		menor = tuna if tuna < eel else eel
		best_continuous = best_continuous[0:menor] + best_continuous[-menor:len(best_continuous)]
	return best_continuous if len(best_continuous) > len(result) else result

def sushi(pieces):
	best_continuous = []
	result = []
	eel = 0
	tuna = 0
	i = 0
	while i < len(pieces):
		if eel == 0 or tuna == 0:
			best_continuous += [pieces[i]]
		elif best_continuous[-1] == pieces[i]:
			best_continuous += [pieces[i]]
		else:
			result = check(result, best_continuous, eel, tuna)
			best_continuous = best_continuous[-tuna:len(best_continuous)] if best_continuous[-1] == '1' else best_continuous[-eel:len(best_continuous)]
			if best_continuous[-1] == '1':
				eel = 0
			else:
				tuna = 0
			best_continuous += [pieces[i]]
		if pieces[i] == '1':
			tuna += 1
		else:
			eel += 1
		i += 1
	result = check(result, best_continuous, eel, tuna)
	return len(result)
n = int(stdin.readline().replace('\n', ''))
pieces = stdin.readline().replace('\n', '').split(' ')
print(sushi(pieces))


n = int(input())
f = [*map(int, input().split())]
collapsed = [1]
for i in range(1, n):
	if f[i] == f[i - 1]:
		collapsed[-1] += 1
	else:
		collapsed.append(1)
m = 0
for i in range(1, len(collapsed)):
	m = max(m, min(collapsed[i], collapsed[i - 1]))
print(m * 2)


n = int(input())
a = list(map(int, input().split()))
b = []
i = 0
while i < n:
	c = 0
	p = a[i]
	j = i
	while j < n and a[j] == a[i]:
		c = c + 1
		j = j + 1
	i = j
	b.append(c)
l = len(b)
mx = 0
for i in range(0, l - 1):
	mx = max(mx, 2 * min(b[i], b[i + 1]))
print(mx)


n = int(input())
sushi = input().split(' ')
sushi_nos = [1]
for i in range(1, len(sushi)):
	if sushi[i] == sushi[i - 1]:
		sushi_nos[-1] += 1
	else:
		sushi_nos.append(1)
max_sushi_size = 0
for i in range(1, len(sushi_nos)):
	max_sushi_size = max(max_sushi_size, min(sushi_nos[i], sushi_nos[i - 1]))
print(max_sushi_size * 2)


from sys import stdin, stdout
n = int(stdin.readline().strip())
ls = list(map(int, stdin.readline().strip().split()))
result = one_count = two_count = 0
prev_item = 0
for i in range(n):
	if ls[i] == 1:
		if prev_item != 1:
			one_count = 0
		one_count += 1
		prev_item = 1
	else:
		if prev_item != 2:
			two_count = 0
		two_count += 1
		prev_item = 2
	result = max(result, min(one_count, two_count))
stdout.write('%d\n' % (result * 2))


from itertools import groupby
n = int(input())
l = list(map(int, input().split()))
ol = []
max = 0
for (i, j) in groupby(l):
	ol.append([i, len(list(j))])
for i in range(len(ol) - 1):
	if ol[i][0] != ol[i + 1][0]:
		cl = min(ol[i][1], ol[i + 1][1]) * 2
		if cl > max:
			max = cl
print(max)


n = int(input())
arr = [int(i) for i in input().split()]
counts = []
count = 1
new_length = 1
answer = 0
for j in range(n - 1):
	if arr[j] == arr[j + 1]:
		count += 1
	else:
		counts.append(count)
		count = 1
		new_length += 1
counts.append(count)
for c in range(new_length - 1):
	answer = max(answer, min(counts[c], counts[c + 1]))
print(answer + answer)


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
import bisect
from heapq import *
from math import *
from collections import deque
from collections import Counter as counter
from itertools import combinations as comb
from itertools import permutations as permutate
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))
mod = 1000000007

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 graph(vertex):
	return [[] for i in range(0, vertex + 1)]

def zerolist(n):
	return [0] * n

def nextline():
	out('\n')

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

def printlist(a):
	for p in range(0, len(a)):
		out(str(a[p]) + ' ')

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

def power(a, b):
	ans = 1
	while b > 0:
		if b % 2 == 1:
			ans *= a
		a *= a
		b //= 2
	return ans

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

def bs(a, l, h, x):
	while l < h:
		mid = (l + h) // 2
		if a[mid] == x:
			return mid
		if a[mid] < x:
			l = mid + 1
		else:
			h = mid
	return l

def sieve(a):
	for i in range(3, 10 ** 6 + 1, 2):
		a[i] = 1
	for i in range(3, 10 ** 6 + 1, 2):
		for j in range(i * i, 10 ** 6 + 1, i):
			a[j] = 0
	a[2] = 1
	return a

def solve():
	n = int(inp())
	a = lis()
	ind = []
	for i in range(0, n - 1):
		if a[i] != a[i + 1]:
			ind.append(i)
	cnt = 0
	for i in ind:
		j = i + 1
		ans = 0
		f = a[i]
		s = a[j]
		while i >= 0 and j <= n - 1 and (a[i] != a[j]) and (a[i] == f) and (a[j] == s):
			ans += 2
			i -= 1
			j += 1
		cnt = max(ans, cnt)
	print(cnt)
testcase(1)


n = int(input())
required = list(map(int, input().split()))
arr = []
(forhelp, ones, twos) = (0, 0, 0)
for i in range(n):
	temp = required[i]
	if forhelp == 1 and temp == 2:
		arr.append(ones)
		ones = 0
	if forhelp == 2 and temp == 1:
		arr.append(twos)
		twos = 0
	if temp == 1:
		ones += 1
		forhelp = 1
	if temp == 2:
		twos += 1
		forhelp = 2
if ones > 0:
	arr.append(ones)
if twos > 0:
	arr.append(twos)
si = len(arr)
maxi = -10000
for i in range(si - 1):
	temp = 0
	if arr[i] <= arr[i + 1]:
		temp = arr[i] * 2
	elif arr[i] > arr[i + 1]:
		temp = arr[i + 1] * 2
	maxi = max(temp, maxi)
print(maxi)


n = int(input())
str = input()
aux = []
x = ''
y = ''
for i in str:
	if i == '1':
		x += i
		if y != '':
			aux.append(y)
			y = ''
	if i == '2':
		y += i
		if x != '':
			aux.append(x)
			x = ''
if y != '':
	aux.append(y)
if x != '':
	aux.append(x)
maior = 0
for i in range(len(aux) - 1):
	cont = 0
	if len(aux[i]) > len(aux[i + 1]):
		cont = len(aux[i + 1]) * 2
	if len(aux[i]) <= len(aux[i + 1]):
		cont = len(aux[i]) * 2
	if cont > maior:
		maior = cont
print(maior)


num = int(input())
y = input()
x = y.split()
x = [int(k) for k in x]
count = 1
pre = x[0]
max_count = 0
result = 0
for i in range(1, num):
	if x[i] == pre:
		count += 1
	else:
		max_count = 1
		for j in range(1, count):
			try:
				x[i] == x[i + j]
			except:
				break
			else:
				if x[i] == x[i + j]:
					max_count += 1
				else:
					break
		result = max(result, max_count)
		count = 1
	pre = x[i]
print(2 * result)


n = int(input())
seg = 0
tuna = 0
eel = 0
num = list(map(int, input().split()))
fish = 0
for i in range(n):
	if num[i] == 1 and eel == 0:
		tuna += 1
		fish = 1
	elif num[i] == 2 and tuna == 0:
		eel += 1
		fish = 2
	elif num[i] != fish:
		if num[i] == 1:
			tuna += 1
		elif num[i] == 2:
			eel += 1
	elif fish == 1:
		seg = max(seg, min(tuna, eel))
		tuna = 1
		fish = 2
	else:
		seg = max(seg, min(tuna, eel))
		eel = 1
		fish = 1
seg = max(seg, min(tuna, eel))
print(seg * 2)


n = int(input())
l = list(map(int, input().split()))
prev = 0
k = l[0]
res = 0
curr = 0
for i in range(0, n):
	if k == l[i]:
		curr += 1
	else:
		res = max(res, 2 * min(prev, curr))
		prev = curr
		k = l[i]
		curr = 1
print(max(res, 2 * min(prev, curr)))


n = int(input())
a = list(map(int, input().split()))
s = 0
m = -1
d = [0] * 2
for i in range(n):
	if m != a[i]:
		m = a[i]
		s = max(s, min(d))
		d[a[i] - 1] = 1
	else:
		d[a[i] - 1] += 1
s = max(s, min(d))
print(s * 2)


N = int(input())
arr = list(map(int, input().split()))
result = 0
t = -1
count = 0
pre_count = 0
for element in arr:
	if element == t:
		count += 1
	else:
		if count >= pre_count:
			l = 2 * pre_count
		else:
			l = 2 * count
		if l > result:
			result = l
		t = element
		pre_count = count
		count = 1
if count >= pre_count:
	l = 2 * pre_count
else:
	l = 2 * count
if l > result:
	result = l
print(result)


n = int(input())
types = list(map(int, input().split(' ')))
sums = [1]
index = 0
for i in range(1, n):
	if types[i] != types[i - 1]:
		index = index + 1
		sums.append(1)
	else:
		sums[index] = sums[index] + 1
max_count = 0
for i in range(1, len(sums)):
	max_count = max(max_count, min(sums[i], sums[i - 1]))
print(max_count * 2)


n = int(input())
l = list(map(int, input().split()))
w = []
a = 1
t = 0
ans = 0
m = 0
for i in range(n - 1):
	if l[i] == l[i + 1]:
		a += 1
	else:
		w.append(a)
		if i == n - 1:
			t = 1
		a = 1
if t == 0:
	w.append(a)
for i in range(len(w) - 1):
	ans = min(w[i], w[i + 1])
	if ans > m:
		m = ans
print(m * 2)


n = int(input())
l = list(map(int, input().split()))
l2 = []
count = 0
temp = l[0]
for x in l:
	if x == temp:
		count += 1
	else:
		l2.append(count)
		count = 1
		temp = x
l2.append(count)
n = len(l2)
m = min(l2[0], l2[1])
for i in range(1, n - 1):
	if m < min(l2[i], l2[i + 1]):
		m = min(l2[i], l2[i + 1])
print(2 * m)


import sys

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

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

def input():
	return sys.stdin.readline().strip()
n = int(input())
arr = get_array()
k = arr[0]
c1 = 1
f = 0
finalans = float('-inf')
for i in range(1, n):
	if k == arr[i]:
		c1 += 1
	else:
		f = f + 1
		k = arr[i]
		if f > 1:
			ans = min(c1, c2)
			finalans = max(ans, finalans)
		c2 = c1
		c1 = 1
if f > 1:
	ans = min(c1, c2)
	finalans = max(ans, finalans)
if float('-inf') == finalans:
	c1 = 0
	c2 = 0
	for i in arr:
		if i == 1:
			c1 += 1
		else:
			c2 += 1
	print(2 * min(c1, c2))
else:
	print(2 * finalans)


n = int(input())
t = list(map(int, input().split()))
l = 0
r = n + 1
ans = []
i = 0
j = 0
cnt = 0
while True:
	try:
		if t[j] == t[i]:
			j += 1
			cnt += 1
		else:
			ans.append((t[i], cnt))
			i = j
			cnt = 0
	except:
		ans.append((t[i], cnt))
		break

def ok(m):
	l = m // 2
	i = 0
	j = 1
	while j < len(ans):
		if ans[i][1] >= l and ans[j][1] >= l:
			return True
		else:
			i += 1
			j += 1
	return False
while r - l > 1:
	m = (r + l) // 2
	if ok(m):
		l = m
	else:
		r = m
print(l // 2 * 2)


n = int(input())
arr = list(map(int, input().split()))
init = []
curr_ptr = 0
last_element = arr[0]
ctr = 0
while curr_ptr < n:
	if arr[curr_ptr] == last_element:
		ctr += 1
	else:
		init.append(ctr)
		last_element = arr[curr_ptr]
		ctr = 1
	curr_ptr += 1
init.append(ctr)
ans = 0
for i in range(1, len(init)):
	ans = max(ans, min(init[i - 1], init[i]))
print(2 * ans)


n = int(input())
a = list(map(int, input().split()))
res = 2
d = []
c = a[0]
cc = 1
for i in range(1, n):
	if c == a[i]:
		cc += 1
	else:
		d.append(cc)
		c = a[i]
		cc = 1
d.append(cc)
ma = 0
for i in range(1, len(d)):
	ma = max(ma, min(d[i], d[i - 1]))
print(ma * 2)


n = int(input())
T = [int(i) for i in input().split()]
l = len(T)
food = T[0]
count = 1
countA = []
possible = []
for a in range(1, l):
	if T[a] == food:
		count += 1
	else:
		countA.append(count)
		count = 1
		food = T[a]
countA.append(count)
for b in range(len(countA) - 1):
	if countA[b] > countA[b + 1]:
		possible.append(countA[b + 1])
	else:
		possible.append(countA[b])
print(2 * max(possible))


num = input()
sushi = input()
Ss = sushi.split(' ')
leng1 = len(Ss)
Type = Ss[0]
L1 = 0
L2 = 0
result = []
for i in range(leng1):
	if Ss[i] == Type:
		L1 += 1
	else:
		result.append(L1)
		L1 = 1
		Type = Ss[i]
	if i == leng1 - 1:
		result.append(L1)
Max = 0
for i in range(len(result) - 1):
	d = min(result[i], result[i + 1])
	if Max < d:
		Max = d
print(Max * 2)


from sys import stdin
inp = lambda : stdin.readline().strip()
n = int(inp())
a = [int(x) for x in inp().split()]
ans = 0
ones = 1
b = []
flag = False
for i in range(1, n):
	if a[i] != a[i - 1]:
		b.append(ones)
		ones = 1
	else:
		ones += 1
b.append(ones)
for i in range(1, len(b)):
	ans = max(ans, min(b[i], b[i - 1]) * 2)
print(ans)


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

def suchi(a, b):
	lengthA = 1
	lengthB = -1
	maxA = 0
	for i in range(a - 1):
		if b[i] == b[i + 1]:
			lengthA += 1
		else:
			maxA = max(maxA, min(lengthA, lengthB) * 2)
			lengthB = lengthA
			lengthA = 1
	return max(maxA, min(lengthA, lengthB) * 2)
print(suchi(a, b))


from collections import Counter, defaultdict, deque
alph = 'abcdefghijklmnopqrstuvwxyz'
import math
import sys
input = sys.stdin.readline
n = int(input())
arr = [int(x) for x in input().split()]
c = []
cnt = 0
cur = arr[0]
for el in arr:
	if el == cur:
		cnt += 1
	else:
		c.append(cnt)
		cnt = 1
		cur = el
c.append(cnt)
best = 0
for i in range(len(c) - 1):
	best = max(best, min(c[i], c[i + 1]))
print(best * 2)


n = int(input())
li = list(map(int, input().split()))
b = 1
li1 = []
for i in range(n - 1):
	if li[i] == li[i + 1]:
		b += 1
	else:
		li1.append(b)
		b = 1
li1.append(b)
h = 0
for i2 in range(len(li1) - 1):
	h = max(h, min(li1[i2], li1[i2 + 1]))
print(2 * h)


n = int(input())
d = [int(x) for x in input().split()]
d = [0] + d + [0]
n = len(d)
d1 = [i for i in range(n - 1) if d[i] != d[i + 1]]
d2 = [b - a for (a, b) in zip(d1, d1[1:])]
d1 = [min(d2[i], d2[i - 1]) for i in range(1, len(d2))]
print(max(d1) * 2)


N = int(input())
X = [int(a) for a in input().split()] + [3]
N = len(X)
pre = 0
now = 0
ma = 0
j = 9
for i in range(N):
	if X[i] != j:
		ma = max(ma, min(now, pre))
		pre = now
		now = 1
	else:
		now += 1
	j = X[i]
print(ma * 2)


n = int(input())
a = list(map(int, input().split()))
q = []
pre = a[0]
tmp = 1
for i in range(1, n):
	if pre != a[i]:
		q.append(tmp)
		tmp = 1
	else:
		tmp += 1
	pre = a[i]
q.append(tmp)
num = 0
for i in range(1, len(q)):
	num = max(num, min(q[i], q[i - 1]))
print(num * 2)


n = int(input())
arr = list(map(int, input().split(' ')))
sub_sq = []
temp = 0
curr = arr[0]
for elem in arr:
	if curr == elem:
		temp += 1
	else:
		curr = elem
		sub_sq.append(temp)
		temp = 1
if temp:
	sub_sq.append(temp)
res = 0
for i in range(len(sub_sq) - 1):
	res = max(min(sub_sq[i], sub_sq[i + 1]) * 2, res)
print(res)


n = int(input())
import sys
a = list(map(int, sys.stdin.readline().split()))
b = [0] * 100005
len = 0
b[0] = 1
for i in range(1, n):
	if a[i] == a[i - 1]:
		b[len] += 1
	else:
		len += 1
		b[len] = 1
maxd = 0
for i in range(1, n):
	if (b[i] if b[i] < b[i - 1] else b[i - 1]) * 2 > maxd:
		maxd = (b[i] if b[i] < b[i - 1] else b[i - 1]) * 2
print(maxd)


n = int(input())
t = [int(x) for x in input().split()]
start = t.index(t[0] % 2 + 1)
number = t[start]
l1 = start
l2 = 0
largest = 0
for i in range(start, n):
	if t[i] == number:
		l2 += 1
	else:
		if min(l1, l2) > largest:
			largest = min(l1, l2)
		number = number % 2 + 1
		l1 = l2
		l2 = 1
if min(l1, l2) > largest:
	largest = min(l1, l2)
print(largest * 2)


n = int(input())
t = list(map(int, input().split()))
xs = []
x = 0
cur = t[0]
for i in range(n):
	if t[i] == cur:
		x += 1
	else:
		xs.append(x)
		x = 1
		cur = t[i]
xs.append(x)
ans = []
for i in range(len(xs) - 1):
	ans.append(min(xs[i], xs[i + 1]))
print(max(ans) * 2)


def sushi(arr):
	record = []
	last_current = arr[0]
	count = 0
	for current in arr:
		if current != last_current:
			if current == 1:
				record.append(count)
			else:
				record.append(-count)
			count = 1
		else:
			count += 1
		last_current = current
	record.append(count)
	max_val = 0
	for (i, val) in enumerate(record[:-1]):
		tmp = min(abs(record[i]), abs(record[i + 1])) * 2
		if tmp > max_val:
			max_val = tmp
	return max_val
n = input()
arr = [int(x) for x in input().strip().split()]
print(sushi(arr))


n = int(input())
t = list(map(int, input().split()))
cnt = 0
arr = []
for i in range(n - 1):
	if t[i] == t[i + 1]:
		cnt += 1
	else:
		arr.append(cnt)
		cnt = 0
arr.append(cnt)
minarr = []
for i in range(len(arr) - 1):
	minarr.append(min(arr[i], arr[i + 1]))
print(2 * (max(minarr) + 1))


import math
from collections import defaultdict, Counter, deque

def primeFactor(n):
	if n % 2 == 0:
		return 2
	i = 3
	while i ** 2 <= n:
		if n % i == 0:
			return i
		i += 1
	return n

def main():
	n = int(input())
	arr = list(map(int, input().split()))
	m = 0
	one = 0
	two = 0
	i = 0
	while i < n:
		if arr[i] == 1:
			while i < n and arr[i] == 1:
				one += 1
				i += 1
			if two:
				if m < min(one, two) * 2:
					m = min(one, two) * 2
				two = 0
		if i < n and arr[i] == 2:
			while i < n and arr[i] == 2:
				two += 1
				i += 1
			if one:
				if m < min(one, two) * 2:
					m = min(one, two) * 2
				one = 0
	print(m)
t = 1
for _ in range(t):
	main()


N = int(input())
ls = list(map(int, input().split()))
i = 0
recent = ls[0]
arr = []
try:
	while True:
		cnt = 0
		while ls[i] == recent:
			cnt += 1
			i += 1
		arr.append(cnt)
		recent = ls[i]
except:
	arr.append(cnt)
arr = [min(arr[i], arr[i + 1]) for i in range(len(arr) - 1)]
print(2 * max(arr))


n = int(input())
l = list(map(int, input().split()))
st = []
for i in l:
	if len(st) == 0:
		st.append(1)
	elif x == i:
		st[-1] += 1
	elif x != i:
		st.append(1)
	x = i
if len(st) <= 1:
	print(0)
else:
	x = min(st[0], st[1])
	for i in range(1, len(st)):
		x = max(x, min(st[i - 1], st[i]))
	print(2 * x)


n = int(input())
t = [int(x) for x in input().split(' ')]
items = []
c = 1
for i in range(1, n):
	if t[i] == t[i - 1]:
		c += 1
	else:
		items.append(c)
		c = 1
items.append(c)
M = 0
for i in range(1, len(items)):
	M = max(M, min(items[i], items[i - 1]))
print(2 * M)


n = int(input())
a = [int(i) for i in input().split()]
ans = 0
for ll in range(1, 3):
	leftCnt = 0
	rightCnt = 0
	r = 1
	if ll == 1:
		r = 2
	for i in range(n):
		if a[i] == r and leftCnt == 0:
			continue
		if a[i] == ll and rightCnt > 0:
			ans = max(ans, min(leftCnt, rightCnt))
			leftCnt = 1
			rightCnt = 0
		elif a[i] == ll:
			leftCnt += 1
		else:
			rightCnt += 1
	ans = max(ans, min(leftCnt, rightCnt))
print(ans * 2)


n = int(input())
a = [int(i) for i in input().split()]
c1 = 0
c3 = 0
ma = 0
m = 0
pc1 = 0
pc3 = 0
for i in a:
	if i == 1:
		c1 += 1
		if c3 != 0:
			pc3 = c3
		c3 = 0
		ma = min(c1, pc3)
	else:
		c3 += 1
		if c1 != 0:
			pc1 = c1
		c1 = 0
		ma = min(c3, pc1)
	m = max(m, ma)
print(m * 2)


n = int(input())
t = list(map(str, input().replace(' ', '').replace('12', '1 2').replace('21', '2 1').split()))
ans = 0
for i in range(len(t) - 1):
	check = 2 * min(len(t[i]), len(t[i + 1]))
	if check > ans:
		ans = check
print(ans)


def parser():
	while 1:
		data = list(input().split(' '))
		for number in data:
			if len(number) > 0:
				yield number
input_parser = parser()

def get_word():
	global input_parser
	return next(input_parser)

def get_number():
	data = get_word()
	try:
		return int(data)
	except ValueError:
		return float(data)
N = int(100000.0 + 10)
a = [0] * N
lef = [1] * N
rit = [1] * N

def main():
	n = get_number()
	for i in range(n):
		a[i] = get_number()
	for i in range(1, n):
		if a[i] == a[i - 1]:
			lef[i] += lef[i - 1]
	for i in range(n - 1, 0, -1):
		if a[i] == a[i + 1]:
			rit[i] += rit[i + 1]
	res = 0
	for i in range(n - 1):
		if a[i] != a[i + 1]:
			res = max(res, 2 * min(lef[i], rit[i + 1]))
	print(res)
main()


n = int(input())
t = list(map(int, input().split()))
sus = []
t1 = 0
e1 = 0
pre = t[0]
i = 0
while i < n:
	if t[i] == pre and t[i] == 1:
		t1 += 1
		i += 1
	elif t[i] == pre and t[i] == 2:
		e1 += 1
		i += 1
	else:
		pre = t[i]
		if t1 > 0:
			sus.append(t1)
			t1 = 0
			e1 += 1
			i += 1
		else:
			sus.append(e1)
			e1 = 0
			t1 += 1
			i += 1
if e1 > 0:
	sus.append(e1)
if t1 > 0:
	sus.append(t1)
top = 0
for y in range(len(sus) - 1):
	if sus[y] > sus[y + 1] and sus[y + 1] * 2 > top:
		top = sus[y + 1] * 2
	elif sus[y] < sus[y + 1] and sus[y] * 2 > top:
		top = sus[y] * 2
	elif sus[y] == sus[y + 1] and sus[y] * 2 > top:
		top = sus[y] * 2
print(top)


kk = lambda : map(int, input().split())
ll = lambda : list(kk())
(n, ls, p1, p2, c, m) = (int(input()), ll(), 0, 0, 1, 0)
for l in ls:
	if l != c:
		if m < min(p1, p2):
			m = min(p1, p2)
		if l == 1:
			p1 = 1
		else:
			p2 = 1
		c = l
	elif c == 1:
		p1 += 1
	else:
		p2 += 1
if m < min(p1, p2):
	m = min(p1, p2)
print(m * 2)


n = int(input())
list = []
list2 = []
cnt = 1
list = [int(x) for x in input().split()]
for i in range(1, len(list)):
	if list[i] != list[i - 1]:
		list2.append(cnt)
		cnt = 1
	else:
		cnt += 1
list2.append(cnt)
ans = 0
if len(list2) > 1:
	for i in range(0, len(list2) - 1):
		ans = max(ans, min(list2[i], list2[i + 1]))
print(ans * 2)


n = int(input())
a = (*map(int, input().split()),)
from itertools import groupby
b = [len(list(group)) for (key, group) in groupby(a)]
print(max(map(lambda x: min(x[0], x[1]), zip(b[:-1], b[1:]))) * 2)


import sys
input = sys.stdin.buffer.readline
n = int(input())
arr = list(map(int, input().split()))
pos = []
count = 1
for i in range(n - 1):
	if arr[i] == arr[i + 1]:
		count += 1
	else:
		pos.append(count)
		count = 1
pos.append(count)
ans = 0
for i in range(len(pos) - 1):
	if ans < 2 * min(pos[i], pos[i + 1]):
		ans = 2 * min(pos[i], pos[i + 1])
print(ans)


import sys
import math
import bisect
import itertools

def main():
	n = int(input())
	A = list(map(int, input().split()))
	B = list((len(list(g)) for (k, g) in itertools.groupby(A)))
	max_val = 0
	for i in range(1, len(B)):
		val = min(B[i - 1], B[i]) * 2
		max_val = max(max_val, val)
	print(max_val)
main()


class Sushi:
	n = int(input())
	t = list(input().split(' '))
	counter = 1
	list1 = list()
	list2 = list()
	ans = 0
	for i in range(1, n):
		if t[i - 1] == t[i]:
			counter += 1
		else:
			list1.append(counter)
			counter = 1
		if i == n - 1:
			list1.append(counter)
	for i in range(len(list1) - 1):
		list2.append(min(list1[i], list1[i + 1]))
	print(max(list2) * 2)


n = int(input())
A = [int(a) for a in input().split()]
m = 0
aux = 0
twos = 0
ones = 0
longest_ones = 0
longest_twos = 0
last = -1
for a in A:
	if a == 1:
		ones += 1
		twos = 0
		if last == 2:
			longest_ones = 0
			aux = 0
		last = 1
		if ones > longest_ones:
			longest_ones = ones
		if longest_twos > 0:
			aux += 1
			if aux > m:
				m = aux
			longest_twos -= 1
	else:
		twos += 1
		ones = 0
		if last == 1:
			longest_twos = 0
			aux = 0
		last = 2
		if twos > longest_twos:
			longest_twos = twos
		if longest_ones > 0:
			aux += 1
			if aux > m:
				m = aux
			longest_ones -= 1
print(m * 2)


n = int(input())
t = [int(x) for x in input().split()]
prev = 1
temp = 1
res = 0
for i in range(1, n):
	if t[i] != t[i - 1]:
		res = max(res, min(prev, temp) * 2)
		prev = temp
		temp = 1
	else:
		temp += 1
res = max(res, min(prev, temp) * 2)
print(res)


n = int(input())
a = list(map(int, input().split()))
arr = []
(i, j) = (0, 0)
while i < n:
	c = 1
	while j != n - 1 and a[j] == a[j + 1]:
		c += 1
		j += 1
	j += 1
	i += c
	arr.append(c)
ans = 0
for i in range(len(arr) - 1):
	ans = max(ans, min(arr[i], arr[i + 1]) * 2)
print(ans)


n = int(input())
a = list(map(int, input().split()))
if n == 2 and a == [1, 1] or a == [2, 2]:
	print(0)
	exit()
i = 0
j = 0
ans = 0
s = 1
while True:
	if i >= n - 1:
		break
	j = 1
	while a[i] == a[i + 1]:
		j += 1
		i += 1
		if i >= n - 1:
			break
	if min(s, j) * 2 > ans:
		ans = min(s, j) * 2
	s = j
	i += 1
print(ans)


def sushi(s):
	first = s[0]
	last = s[0]
	result = 0
	(ones, twos) = (0, 0)
	for x in s:
		if x == '1':
			if last == '2':
				result = getResult(result, ones, twos)
				ones = 0
			ones += 1
		if x == '2':
			if last == '1':
				result = getResult(result, ones, twos)
				twos = 0
			twos += 1
		last = x
	result = getResult(result, ones, twos)
	return result

def getResult(result, ones, twos):
	m = min(ones, twos) * 2
	if m > result:
		result = m
	return result
c = input()
s = input()
l = list(s.split(' '))
print(sushi(l))


N = int(input())
A = [int(a) for a in input().split()]
Type = []
start = 0
leftType = A[0]
end = 0
while end < N:
	if A[end] == leftType:
		end += 1
	else:
		Type.append(end - start)
		(start, leftType) = (end, A[end])
Type.append(end - start)
maxLength = 0
for i in range(len(Type) - 1):
	maxLength = max(maxLength, min(Type[i], Type[i + 1]) * 2)
print(maxLength)


n = int(input())
l = list(map(int, input().split()))
o = l.count(1)
t = l.count(2)
if o == 0 or t == 0:
	print(0)
else:
	a = l[0]
	c = 0
	d = 0
	if a == 1:
		c = c + 1
	elif a == 2:
		d = d + 1
	ans = 0
	t = 0
	for i in range(1, n):
		if l[i] == l[i - 1]:
			if l[i] == 1:
				c = c + 1
			else:
				d = d + 1
		else:
			t = 1
			if l[i] == 1:
				c = 1
			else:
				d = 1
		if t == 1:
			ans = max(ans, 2 * min(c, d))
	print(ans)


n = int(input())
ln = [int(i) for i in input().split(' ')]
t = 1
ts = []
for i in range(1, len(ln)):
	if ln[i] == ln[i - 1]:
		t += 1
	else:
		ts.append(t)
		t = 1
ts.append(t)
m = 0
if len(ts) == 1:
	print(0)
else:
	for i in range(1, len(ts)):
		m = max(m, min(ts[i], ts[i - 1]) * 2)
print(m)


n = int(input())
a = [int(i) for i in input().split()]
cont = 1
result = 0
aux = []
for i in range(1, n):
	if a[i] != a[i - 1]:
		aux.append(cont)
		cont = 1
	else:
		cont += 1
aux.append(cont)
if len(aux) > 1:
	l = len(aux)
	for i in range(0, l):
		if i + 1 <= l - 1:
			result = max(result, min(aux[i], aux[i + 1]))
print(result * 2)


n = int(input())
a = list(map(int, input().split()))
(left, r) = (0, 0)
ans = 0
while r < n:
	while r < n and a[r] == a[left]:
		r += 1
	t = r
	t2 = r
	while t2 < n and a[t] == a[t2]:
		t2 += 1
	ans = max(ans, min(t2 - t, r - left) * 2)
	(left, r) = (t, t2)
print(ans)


n = int(input())
l = list(map(int, input().split()))
l.append(-1)
cnt = 1
a = []
l1 = []
l2 = []
for i in range(len(l) - 1):
	if l[i] == l[i + 1]:
		cnt = cnt + 1
	else:
		a.append(cnt)
		cnt = 1
for i in range(len(a) - 1):
	l1.append(a[i])
for i in range(1, len(a)):
	l2.append(a[i])
l3 = []
for i in range(len(l1)):
	l3.append(2 * min(l1[i], l2[i]))
print(max(l3))


n = int(input())
sushis = list(input().split())
(sum1, sum2) = (0, 0)
(locmax, max1) = (0, 0)
last = sushis[0]
if sushis[0] == '1':
	sum1 += 1
else:
	sum2 += 1
for i in sushis[1:]:
	if i == last:
		if i == '1':
			sum1 += 1
		else:
			sum2 += 1
	elif min(sum1, sum2) == 0:
		if i == '1':
			sum1 += 1
		else:
			sum2 += 1
	else:
		locmax = min(sum1, sum2) * 2
		max1 = max(max1, locmax)
		if i == '1':
			sum1 = 1
		else:
			sum2 = 1
	last = i
print(max(max1, min(sum1, sum2) * 2))


n = int(input())
array = list(map(int, input().split()))
maximum = 0
d = {1: 0, 2: 0}
last = array[0]
for item in array:
	if last != item:
		if min(d[1], d[2]) * 2 > maximum and d[1] and d[2]:
			maximum = min(d[1], d[2]) * 2
		d[item] = 0
	d[item] += 1
	last = item
if min(d[1], d[2]) * 2 > maximum:
	maximum = min(d[1], d[2]) * 2
print(maximum)


n = int(input())
arr = [int(x) for x in input().split()]
arr.append(0)
new_arr = []
cur = 1
for i in range(1, n + 1):
	if arr[i] == arr[i - 1]:
		cur += 1
	else:
		new_arr.append(cur)
		cur = 1
best_answer = 0
for i in range(len(new_arr) - 1):
	best_answer = max(best_answer, min(new_arr[i], new_arr[i + 1]))
print(2 * best_answer)


n = int(input())
a = [int(x) for x in input().split()]
b = []
k = 1
lst = a[0]
if a[0] != a[1]:
	b = [1]
for i in range(1, n):
	if lst == a[i]:
		k += 1
	else:
		b.append(k)
		lst = a[i]
		k = 1
if k == 1:
	b.append(1)
if a[n - 1] == a[n - 2]:
	b.append(k)
s = min(b[0], b[1])
for i in range(1, len(b) - 1):
	k = min(b[i], b[i + 1])
	if k > s:
		s = k
print(s * 2)


n = int(input())
t = list(map(int, input().split()))
first = 0
tokens = []
for i in range(1, n):
	if t[first] != t[i]:
		token = [t[first], i - first]
		tokens.append(token)
		first = i
tokens.append([t[first], n - first])
r = 0
for i in range(len(tokens) - 1):
	if tokens[i][0] != tokens[i + 1][0]:
		r = max(r, min(tokens[i][1], tokens[i + 1][1]))
print(r * 2)


numberSushi = int(input())
sushiRow = input().split(' ')
for i in range(numberSushi):
	sushiRow[i] = int(sushiRow[i])
sequenceSizes = [0] * (numberSushi + 2)
currentSushiType = sushiRow[0]
currentSequenceIndex = 1
for i in range(numberSushi):
	if sushiRow[i] == currentSushiType:
		sequenceSizes[currentSequenceIndex] += 1
	else:
		if currentSushiType == 1:
			currentSushiType = 2
		else:
			currentSushiType = 1
		currentSequenceIndex += 1
		sequenceSizes[currentSequenceIndex] += 1
answer = 2
i = 1
while sequenceSizes[i] != 0:
	atLeft = sequenceSizes[i - 1]
	atRight = sequenceSizes[i + 1]
	if sequenceSizes[i] >= atLeft and sequenceSizes[i] >= atRight:
		answer = max(answer, max(atLeft, atRight) * 2)
	i += 1
print(answer)


n = int(input())
a = list(map(int, input().split()))
row_1 = 0
row_2 = 0
lrow_1 = 0
lrow_2 = 0
ans = 0
for x in a:
	if x == 1:
		ans = max(ans, min(row_2, lrow_1))
		row_1 += 1
		if row_2 > 0:
			lrow_2 = row_2
		row_2 = 0
	else:
		ans = max(ans, min(lrow_2, row_1))
		if row_1 > 0:
			lrow_1 = row_1
		row_1 = 0
		row_2 += 1
ans = max(ans, min(lrow_2, row_1))
ans = max(ans, min(row_2, lrow_1))
print(ans * 2)


t = int(input())
b = list(map(int, input().split()))
m = -1
p = 1
q = 1
for j in range(t - 1):
	if b[j] == 1 and b[j + 1] == 1:
		p += 1
	elif b[j] == 2 and b[j + 1] == 2:
		q += 1
	elif b[j] == 1 and b[j + 1] == 2:
		q = 1
	else:
		p = 1
	l = min(p, q)
	if l > m:
		m = l
print(2 * m)


n = int(input())
arr = list(map(int, input().split()))
ans = [0] * n
gr = 0
last = arr[0]
for (i, val) in enumerate(arr):
	if last == val:
		ans[gr] += 1
	else:
		gr += 1
		ans[gr] = 1
		last = val
mmax = 0
for i in range(1, n):
	temp = min(ans[i], ans[i - 1])
	mmax = max(mmax, temp)
print(mmax * 2)


from sys import stdin, stdout
from itertools import combinations
from collections import defaultdict
import math

def listIn():
	return list(map(int, stdin.readline().strip().split()))

def stringListIn():
	return [x for x in stdin.readline().split()]

def intIn():
	return int(stdin.readline())

def stringIn():
	return stdin.readline().strip()
n = intIn()
t = listIn()
li = []
cnt = 1
for i in range(1, n):
	if t[i] == t[i - 1]:
		cnt += 1
	else:
		li.append(cnt)
		cnt = 1
li.append(cnt)
ans = float('-inf')
for i in range(1, len(li)):
	ans = max(ans, min(li[i], li[i - 1]))
print(ans * 2)


n = int(input())
a = [int(t) for t in input().split(' ')]
c = [0] * 3
c1 = 0
c2 = 0
c[a[0]] += 1
max_length = 1
for i in range(1, n):
	if a[i] == a[i - 1]:
		c[a[i]] += 1
	else:
		c[a[i]] = 1
	max_length = max(max_length, min(c[1], c[2]))
print(max_length * 2)


n = int(input().strip())
arr = list(map(int, input().strip().split())) + [0]
c = 0
temp = []
for i in range(n):
	if arr[i] == arr[i + 1]:
		c += 1
	else:
		temp.append(c + 1)
		c = 0
ans = []
for i in range(len(temp) - 1):
	ans.append(min(temp[i], temp[i + 1]))
print(2 * max(ans))


n = int(input())
a = list(map(int, input().split()))
i = 0
ans = 0
c1 = c2 = 0
ar = []
while i < n:
	while i < n and a[i] == 1:
		c1 += 1
		i += 1
	ar.append(c1)
	while i < n and a[i] == 2:
		c2 += 1
		i += 1
	ar.append(c2)
	c1 = c2 = 0
for i in range(len(ar) - 1):
	ans = max(ans, min(ar[i], ar[i + 1]))
print(2 * ans)


from sys import stdin
n = int(input())
last = -1
cntL = 0
cntCur = 0
best = 0
for cur in stdin.readline().split():
	if cur == last:
		cntCur += 1
		best = max(best, min(cntCur, cntL))
	else:
		(cntL, cntCur) = (cntCur, 1)
		last = cur
		best = max(best, min(cntCur, cntL))
print(best * 2)


n = int(input())
a = [int(x) for x in input().split()]
res = [1]
for i in range(1, len(a)):
	if a[i] == a[i - 1]:
		res[-1] += 1
	else:
		res.append(1)
mres = 0
for i in range(1, len(res)):
	mres = max(mres, min(res[i], res[i - 1]))
print(mres * 2)


n = input()
n = int(n)
l = list(map(int, input().split()))
sa = 1
sb = 1
d = {}
d[1] = 0
d[2] = 0
maxi = 2
for i in range(n - 1):
	if l[i] == l[i + 1] == 1:
		sa += 1
		d[1] = 1
	elif l[i] == 1 and d[1] == d[2] == 1 and (l[i] != l[i + 1] or i == n - 2):
		maxi = max(maxi, 2 * min(sa, sb))
		sb = 1
		d[2] = 0
	elif l[i] == 1 and l[i] != l[i + 1]:
		d[2] = 0
		sb = 1
	if l[i] == l[i + 1] == 2:
		sb += 1
		d[2] = 1
	elif l[i] == 2 and d[1] == d[2] == 1 and (l[i] != l[i + 1] or i == n - 2):
		maxi = max(maxi, 2 * min(sa, sb))
		sa = 1
		d[1] = 0
	elif l[i] == 2 and l[i] != l[i + 1]:
		sa = 1
		d[1] = 0
	if i == n - 2 and d[1] == d[2] == 1:
		maxi = max(maxi, 2 * min(sa, sb))
	ch = 0
print(maxi)


n = int(input())
l = list(map(int, input().strip().split()))
l.append(0)
k = l[0]
w = []
cnt1 = 0
cnt2 = 1000000.0
jk = 0
mins = 1000000.0
i = 0
while i < n:
	if k == l[i]:
		jk += 1
		while k == l[i] and i < n:
			cnt1 += 1
			i += 1
	else:
		j = l[i]
		jk += 1
		while j == l[i] and i < n:
			cnt2 += 1
			i += 1
	w.append(min(cnt1, cnt2))
	if jk % 2 != 0:
		cnt2 = 0
	else:
		cnt1 = 0
print(2 * max(w[1:]))


n = int(input())
A = [int(x) for x in input().split()]
segments = []
curr_char = A[0]
curr_len = 1
for i in range(1, n):
	if A[i] == curr_char:
		curr_len += 1
	else:
		segments.append(curr_len)
		curr_len = 1
		curr_char = A[i]
segments.append(curr_len)
print(max([2 * min(segments[i], segments[i - 1]) for i in range(1, len(segments))]))


n = int(input())
li = list(map(int, input().split()))
new1 = []
i = 0
sum1 = 0
prev = li[i]
while i < len(li):
	if prev == li[i]:
		sum1 += li[i]
	else:
		prev = li[i]
		if prev == 2:
			new1.append(sum1)
		else:
			new1.append(sum1 // 2)
		sum1 = li[i]
	i += 1
if prev == 2:
	new1.append(sum1 // 2)
else:
	new1.append(sum1)
nn = []
for i in range(0, len(new1) - 1):
	nn.append(min(new1[i + 1], new1[i]))
print(max(nn) * 2)


n = int(input())
l = list(map(int, input().split()))
best = 0
prev = 0
prev_score = 0
cur_score = 0
for i in range(n):
	if l[i] != prev:
		score = min(prev_score, cur_score)
		if score > best:
			best = score
			prev_score = cur_score
			cur_score = 1
			prev = l[i]
		else:
			prev_score = cur_score
			cur_score = 1
			prev = l[i]
	else:
		cur_score += 1
score = min(prev_score, cur_score)
if score > best:
	best = score
print(best * 2)


def main():
	n = int(input())
	ar = list(map(int, input().split(' ')))
	maxlen = 0
	two = 0
	one = 0
	i = 0
	twolen = 0
	while i < n:
		while i < n and ar[i] == 2:
			two += 1
			i += 1
		twolen = two
		while i < n and ar[i] == 1 and (two > 0):
			two -= 1
			i += 1
		len = twolen - two
		if len > maxlen:
			maxlen = len
		two = 0
		if i < n and ar[i] == 1:
			i += 1
	i = 0
	while i < n:
		while i < n and ar[i] == 1:
			one += 1
			i += 1
		twolen = one
		while i < n and ar[i] == 2 and (one > 0):
			one -= 1
			i += 1
		len = twolen - one
		if len > maxlen:
			maxlen = len
		one = 0
		if i < n and ar[i] == 2:
			i += 1
	print(maxlen * 2)
main()


import sys

class Stack:

	def __init__(self):
		self.arr = []

	def put(self, data):
		self.arr.append(data)

	def get(self):
		if len(self.arr) is 0:
			return
		return self.arr.pop()

	def size(self):
		return len(self.arr)

	def top(self):
		if len(self.arr) is 0:
			return
		return self.arr[len(self.arr) - 1]

	def empty(self):
		return len(self.arr) is 0

	def deport(self):
		x = self.arr.copy()
		return x

def ans(arr):
	count = 0
	ans2 = []
	i = 0
	while i < len(arr):
		count += 1
		if i is len(arr) - 1:
			ans2.append(count)
			count = 0
			break
		if arr[i] is not arr[i + 1]:
			ans2.append(count)
			count = 0
		i += 1
	s = Stack()
	for i in range(len(arr)):
		if s.empty():
			s.put(arr[i])
		elif s.top() is not arr[i]:
			s.put(arr[i])
	x = s.deport()
	if len(x) <= 1:
		return 0
	maxCheck = -sys.maxsize
	minCheck = sys.maxsize
	for i in range(len(x) - 1):
		a = ans2[i]
		b = ans2[i + 1]
		minCheck = min(a, b)
		maxCheck = max(maxCheck, minCheck)
	return maxCheck * 2
n = int(input())
arr = list(map(int, input().strip().split(' ')))
print(ans(arr))


n = int(input())
a = list(map(int, input().split()))
from itertools import groupby
t = [len(list(group)) for (key, group) in groupby(a)]
p = []
for i in range(len(t) - 1):
	p.append(min(t[i], t[i + 1]))
print(2 * max(p))


n = int(input())
a = [int(x) for x in input().split()]
c1 = 0
c2 = 0
ans = []
f = [a[0], 1]
ans.append(f)
j = 0
i = 1
answer = 0
while i < n:
	if a[i] == a[i - 1]:
		ans[j][1] += 1
	else:
		j += 1
		ans.append([a[i], 1])
	i += 1
for i in range(1, len(ans)):
	res = 2 * min(ans[i - 1][1], ans[i][1])
	if res > answer:
		answer = res
print(answer)


import sys
input = sys.stdin.readline

def main():
	n = int(input())
	l = list(map(int, input().split()))
	r = 0
	m = [1, 0]
	for i in range(1, n):
		if l[i] == l[i - 1]:
			m[0] += 1
		else:
			k = min(m)
			r = max(k, r)
			(m[1], m[0]) = (m[0], 1)
	k = min(m)
	r = 2 * max(k, r)
	print(r)
main()


n = int(input())
l = map(int, input().split())
ls = [[a, 1] for a in l]
i = 0
while i < len(ls) - 1:
	if ls[i][0] == ls[i + 1][0]:
		ls[i + 1][1] += ls[i][1]
		ls.pop(i)
	else:
		i += 1
if len(ls) == 1:
	print(0)
else:
	maxm = 0
	for i in range(len(ls) - 1):
		maxm = max(maxm, min(ls[i][1], ls[i + 1][1]))
	print(maxm * 2)


a = int(input())
t = input()
t = t.replace(' ', '')
t = t.replace('12', '1 2')
t = t.replace('21', '2 1')
t = t.split(' ')
t = list(map(len, t))
b = list(zip(t, t[1:]))
c = map(min, b)
print(2 * max(c))


n = int(input())
l = list(map(int, input().split()))
v = []
if l[0] == 2:
	fl = True
else:
	fl = False
s = 1
for i in range(1, n):
	if l[i] == l[i - 1]:
		s += 1
	else:
		if fl:
			v.append(s)
		else:
			v.append(-s)
		s = 1
		fl = not fl
if fl:
	v.append(s)
else:
	v.append(-s)
smax = 0
for i in range(len(v)):
	if v[i] < 0:
		if i + 1 < len(v) and v[i + 1] > 0:
			smax = max(smax, min(-v[i], v[i + 1]))
		if i - 1 >= 0 and v[i - 1] > 0:
			smax = max(smax, min(-v[i], v[i - 1]))
print(smax * 2)


n = int(input())
cl = list(map(int, input().split()))
a = 0
b = 0
mx = 0
dl = []
for i in range(n):
	if cl[i] == 1:
		if b != 0:
			dl.append(b)
			b = 0
		a += 1
	else:
		if a != 0:
			dl.append(a)
			a = 0
		b += 1
if a != 0:
	dl.append(a)
if b != 0:
	dl.append(b)
mxx = 0
for i in range(len(dl) - 1):
	mx = 2 * min(dl[i], dl[i + 1])
	if mx > mxx:
		mxx = mx
print(mxx)


n = int(input())
l = list(map(int, input().split()))
o = 0
t = 0
ans = 0
x = 0
for i in range(n - 1):
	if l[i] == 1:
		o += 1
	else:
		t += 1
	if l[i] != l[i + 1]:
		x += 1
	if x % 2 == 0 and x != 0 or i == n - 2:
		if i == n - 2:
			if l[i + 1] == 1:
				o += 1
			else:
				t += 1
		ans = max(ans, min(o, t))
		if l[i] == 2:
			o = 0
		else:
			t = 0
		x += 1
print(ans * 2)


import os
import sys
from io import BytesIO, IOBase
from collections import defaultdict, deque, Counter, OrderedDict
import threading

def main():
	n = int(input())
	t = [*map(int, input().split())]
	ans = 0
	for i in range(n - 1):
		if t[i] == 2 and t[i + 1] == 1 or (t[i] == 1 and t[i + 1] == 2):
			(x, y) = (i, i + 1)
			z = 2
			ans = max(ans, z)
			while 1:
				x -= 1
				y += 1
				if 0 <= x < n and 0 <= y < n:
					if t[x] == t[i] and t[y] == t[i + 1]:
						z += 2
						ans = max(z, ans)
					else:
						break
				else:
					break
	print(ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

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


n = int(input())
l = list(map(int, input().split()))
a = l.count(1)
b = l.count(2)
t = l[0]
c = 1
ans = []
for i in range(1, n):
	if l[i] == t:
		c += 1
	else:
		ans.append((t, c))
		t = l[i]
		c = 1
ans.append((t, c))
anss = 0
for i in range(len(ans) - 1):
	if ans[i][0] != ans[i + 1][0]:
		d = min(ans[i][1], ans[i + 1][1])
		anss = max(anss, 2 * d)
print(anss)


n = int(input())
a = list(map(int, input().split()))
prev = -1
pa = 0
pb = 0
ans = 0
for i in range(n):
	if prev != a[i]:
		if a[i] == 1:
			pa = 0
		else:
			pb = 0
	prev = a[i]
	if a[i] == 1:
		pa += 1
	elif a[i] == 2:
		pb += 1
	ans = max(ans, 2 * min(pa, pb))
print(ans)


n = int(input())
l = list(map(int, input().split()))
m = -1
x = 1
y = 1
for i in range(1, n):
	if l[i] == 1 and l[i - 1] == 1:
		x = x + 1
	elif l[i] == 2 and l[i - 1] == 2:
		y += 1
	elif l[i] == 2 and l[i - 1] == 1:
		y = 1
	else:
		x = 1
	k = min(x, y)
	m = max(m, k)
print(2 * m)


n = int(input())
s = list(map(int, input().split()))
cnt1 = 0
cnt2 = 0
max = -1
if s[0] == 1:
	cnt1 = 1
else:
	cnt2 = 1
for i in range(1, n):
	if s[i] == s[i - 1]:
		if s[i] == 1:
			cnt1 += 1
		else:
			cnt2 += 1
	elif s[i] == 1:
		cnt1 = 1
	else:
		cnt2 = 1
	if min(cnt1, cnt2) > max:
		max = min(cnt1, cnt2)
print(max * 2)


n = input()
a = input().split()
s = [1 for i in range(len(a))]
j = 0
for i in range(1, len(a)):
	if a[i] == a[i - 1]:
		s[j] += 1
	else:
		j += 1
j += 1
s = s[:j:1]
r = [1 for i in range(j - 1)]
for i in range(1, j):
	r[i - 1] = min(s[i - 1], s[i])
print(max(r) * 2)


import itertools as it
input()
a = [int(x) for x in input().split()]
b = [len(list(f)) for (m, f) in it.groupby(a)]
c = list(zip(b, b[1:]))
res = max((min(x, y) for (x, y) in c))
print(2 * res)


n = int(input())
a = [int(i) for i in input().split(' ')]
p = a[0]
c = 1
b = []
for i in range(1, n):
	if a[i] != p:
		b.append(c)
		c = 1
		p = a[i]
	else:
		c += 1
b.append(c)
ma = -99
ans = 0
for i in range(0, len(b) - 1, 1):
	ma = max(min(b[i], b[i + 1]), ma)
print(2 * ma)


userinput = int(input())
subminlen = []
newnum = [int(i) for i in input().split()]
lennum = 1
for i in range(len(newnum) - 1):
	if newnum[i] == newnum[i + 1]:
		lennum += 1
	else:
		subminlen.append(lennum)
		lennum = 1
subminlen.append(lennum)
answer = 0
for i in range(len(subminlen) - 1):
	if answer < min(subminlen[i], subminlen[i + 1]):
		answer = min(subminlen[i], subminlen[i + 1])
print(answer * 2)


n = int(input())
a = input().split(' ')
a = a[:n]
a = [int(x) for x in a]
l1 = []
l2 = []
r1 = {}
r2 = {}
if a[0] == 2:
	l2 = [1]
	l1 = [0]
else:
	l2 = [0]
	l1 = [1]
for i in range(1, n):
	if a[i] == 2:
		l1.append(0)
		l2.append(l2[i - 1] + 1)
	else:
		l2.append(0)
		l1.append(l1[i - 1] + 1)
if a[n - 1] == 2:
	r2[n - 1] = 1
	r1[n - 1] = 0
else:
	r2[n - 1] = 0
	r1[n - 1] = 1
for i in range(n - 2, -1, -1):
	if a[i] == 2:
		r1[i] = 0
		r2[i] = 1 + r2[i + 1]
	else:
		r2[i] = 0
		r1[i] = 1 + r1[i + 1]
ans = 0
for i in range(1, n):
	if a[i] != a[i - 1]:
		ans = max(ans, max(min(l1[i - 1], r2[i]), min(l2[i - 1], r1[i])))
print(ans * 2)


input()
p = list(map(len, input().replace(' ', '').replace('12', '1 2').replace('21', '2 1').split()))
d = 0
for i in range(len(p) - 1):
	d = max(d, min(p[i], p[i + 1]))
print(2 * d)


n = int(input())
t = [int(i) for i in input().split(' ')]
s = []
curr_t = t[0]
curr_n = 0
for x in t:
	if x == curr_t:
		curr_n += 1
	else:
		curr_t = x
		s.append(curr_n)
		curr_n = 1
else:
	s.append(curr_n)
max_s = 1
for i in range(1, len(s)):
	if s[i] >= s[i - 1] > max_s:
		max_s = s[i - 1]
	elif max_s < s[i] <= s[i - 1]:
		max_s = s[i]
print(max_s * 2)


from itertools import groupby
import sys
i = 0
for l in sys.stdin:
	i += 1
	if i == 1:
		n = int(l.strip())
		arr = [0] * (1 + n)
	else:
		for (i, e) in enumerate(l.strip().split()):
			arr[1 + i] = int(e)
grp_res = [len(list(y)) for (x, y) in groupby(arr)]
n = len(grp_res)
res = 0
for i in range(1, n - 1):
	res = max(res, 2 * min(grp_res[i], grp_res[i + 1]))
print(res)


n = int(input())
t = list(map(int, input().split()))
(i, j, c) = (0, 0, 2)
while j < n and t[j] == t[i]:
	j += 1
cnt = j
while j < n:
	i = j
	while j < n and t[j] == t[i]:
		j += 1
	c = max(c, 2 * min(j - i, cnt))
	cnt = j - i
print(c)


import sys

def rint():
	return map(int, sys.stdin.readline().split())
n = int(input())
t = list(rint())
cc = 1
pc = 0
ans = 0
for i in range(1, n):
	cv = t[i]
	if cv == t[i - 1]:
		cc += 1
		ans = max(ans, min(cc, pc))
	else:
		ans = max(ans, min(cc, pc))
		pc = cc
		cc = 1
		ans = max(ans, min(cc, pc))
print(ans * 2)


n = int(input())
arr = list(map(int, input().split()))
(cnt1, cnt2) = (0, 0)
ans = []
for i in range(n):
	if arr[i] == 1:
		if cnt2 != 0:
			ans.append([2, cnt2])
			cnt2 = 0
		cnt1 += 1
	else:
		if cnt1 != 0:
			ans.append([1, cnt1])
			cnt1 = 0
		cnt2 += 1
if cnt1 != 0:
	ans.append([1, cnt1])
if cnt2 != 0:
	ans.append([2, cnt2])
f = 0
for i in range(1, len(ans)):
	if ans[i][0] != ans[i - 1][0]:
		f = max(f, min(ans[i][1], ans[i - 1][1]))
print(2 * f)


n = int(input())
a = list(map(int, input().split()))
ch = a[0]
c = 0
l = []
for i in range(n):
	if ch == a[i]:
		c += 1
	else:
		ch = a[i]
		l.append(c)
		c = 1
	if i == n - 1:
		l.append(c)
fl = []
for i in range(len(l) - 1):
	fl.append(min(l[i], l[i + 1]))
print(max(fl) * 2)


n = int(input())
a = list(map(int, input().split()))
f = a[0]
ct = []
c = 0
for i in range(n):
	if a[i] == f:
		c += 1
	else:
		ct.append(c)
		f = a[i]
		c = 1
ct.append(c)
ans = 0
for i in range(len(ct) - 1):
	ans = max(ans, 2 * min(ct[i], ct[i + 1]))
print(ans)


n = int(input())
arr = list(map(int, input().split(' ')))
count_1 = 0
count_2 = 0
count = 0
max = 0
for i in range(n):
	if arr[i] == 1:
		count_1 += 1
		if count_1 <= count_2:
			count += 2
			if count > max:
				max = count
		if i + 1 < n and arr[i + 1] == 2:
			count_2 = 0
			count = 0
	else:
		count_2 += 1
		if count_2 <= count_1:
			count += 2
			if count > max:
				max = count
		if i + 1 < n and arr[i + 1] == 1:
			count_1 = 0
			count = 0
print(max)


DBG = not True
n = int(input())
t = list(map(int, input().split()))
if DBG:
	print(n)
	print(t)
last1 = 1 if t[0] == 1 else 0
last2 = 1 if t[0] == 2 else 0
mx = 0
for i in range(1, n):
	if t[i] == 1:
		if t[i - 1] == 2:
			last1 = 0
		last1 += 1
		if mx < last1 and last1 <= last2:
			mx = last1
	else:
		if t[i - 1] == 1:
			last2 = 0
		last2 += 1
		if mx < last2 and last1 >= last2:
			mx = last2
print(2 * mx)


n = int(input())
a = map(int, input().split())
sushi = list(a)
typ = sushi[0]
l1 = 1
l2 = 0
length = list()
for i in range(1, n):
	if sushi[i] == typ:
		l1 += 1
	else:
		length.append(l1)
		l1 = 1
		typ = sushi[i]
length.append(l1)
MAX = 0
for i in range(len(length) - 1):
	m = min(length[i], length[i + 1])
	if m > MAX:
		MAX = m
print(MAX * 2)


n = int(input())
arr = list(map(int, input().split()))
one = 0
two = 0
ans = 0
tmp = 0
i = 0
while i < n:
	if arr[i] == 1:
		while i < n and arr[i] == 1:
			one += 1
			i += 1
		if two > 0:
			tmp = min(one, two) * 2
			ans = max(tmp, ans)
		two = 0
	else:
		while i < n and arr[i] == 2:
			two += 1
			i += 1
		if one > 0:
			tmp = min(one, two) * 2
			ans = max(tmp, ans)
		one = 0
print(ans)


n = int(input())
s = [int(x) for x in input().split()]
p = 1
q = 0
r = 0
for i in range(n - 1):
	if s[i] == s[i + 1]:
		p += 1
	else:
		if min(p, q) > r:
			r = min(p, q)
		q = p
		p = 1
if min(p, q) > r:
	r = min(p, q)
print(2 * r)


n = int(input())
A = list(map(int, input().split()))
i = 0
k = 1
j = 1
max = 0
while A[j] == A[j - 1]:
	k += 1
	j += 1
while j < n:
	l = 1
	j += 1
	while j < n and A[j] == A[j - 1]:
		l += 1
		j += 1
	if min(k, l) > max:
		max = min(k, l)
	k = l
print(2 * max)


n = int(input())
l = [int(x) for x in input().split()]
currentflavor = l[0]
currentstreak = 0
laststreak = 0
bestval = 0
for x in l:
	if x == currentflavor:
		currentstreak += 1
	else:
		bestval = max(bestval, min(currentstreak, laststreak))
		laststreak = currentstreak
		currentstreak = 1
		currentflavor = x
bestval = max(bestval, min(currentstreak, laststreak))
print(2 * bestval)


input()
x = list(map(int, input().split())) + [0]
tmp = 1
sushi = []
listans = []
for i in range(len(x) - 1):
	if x[i + 1] == x[i]:
		tmp += 1
	else:
		sushi.append((x[i], tmp))
		tmp = 1
sushi.append((0, 0))
for i in range(len(sushi) - 1):
	listans.append(min(sushi[i][1], sushi[i + 1][1]))
print(2 * max(listans))


mi = lambda : [int(i) for i in input().split()]
n = int(input())
t = mi()
a = []
v = 0
c = 0
for i in t:
	if i == v:
		c += 1
	else:
		if c != 0:
			a.append(c)
		c = 1
		v = i
a.append(c)
r = 0
for k in range(1, len(a)):
	r = max(r, min(a[k - 1], a[k]) * 2)
print(r)


import sys

def main():
	n = int(input())
	sushi = list(map(int, sys.stdin.readline().split()))
	(debut, milieu, fin) = (0, 0, 1)
	maxLong = 0
	for i in range(1, n):
		if sushi[i] == sushi[i - 1]:
			fin += 1
		else:
			maxLong = max(maxLong, 2 * min((fin - milieu, milieu - debut)))
			debut = milieu
			milieu = fin
			fin += 1
	maxLong = max(maxLong, 2 * min((n - milieu, milieu - debut)))
	print(maxLong)
main()


n = int(input())
a = list(map(int, input().split()))
c = []
for i in range(len(a) - 1):
	if a[i] == 2 and a[i + 1] == 1:
		c.append([i, i + 1])
	elif a[i] == 1 and a[i + 1] == 2:
		c.append([i, i + 1])
l = []
for i in range(len(c)):
	left = 1
	right = 1
	for j in range(c[i][0], 0, -1):
		if a[j] == a[j - 1]:
			left += 1
		else:
			break
	for j in range(c[i][1], len(a) - 1):
		if a[j] == a[j + 1]:
			right += 1
		else:
			break
	l.append(min(left, right))
print(max(l) * 2)


n = int(input())
a = list(map(int, input().split()))
k1 = 1
m = 0
d = [0, 0]
for i in range(1, n):
	if a[i - 1] == a[i]:
		k1 += 1
	else:
		d.pop(0)
		d.append(k1)
		if min(d[0], d[1]) > m:
			m = min(d[0], d[1])
		k1 = 1
if min(d[1], k1) > m:
	m = min(d[1], k1)
print(m * 2)


n = int(input())
t = [int(i) for i in input().split()]
last = 1
count = 1
ans = 0
for i in range(n - 1):
	if t[i] == t[i + 1]:
		count += 1
	else:
		ans = max(min(last, count), ans)
		last = count
		count = 1
ans = max(min(last, count), ans)
print(ans * 2)


n = int(input())
sushis = input().split(' ')
left_length = 1
right_length = 0
counting = False
max_length = 0
for i in range(1, n):
	if sushis[i] == sushis[i - 1]:
		if counting == False:
			left_length += 1
		else:
			right_length += 1
	else:
		length = min([left_length, right_length]) * 2
		if length > max_length:
			max_length = length
		if counting == False:
			counting = True
		else:
			left_length = right_length
		right_length = 1
length = min([left_length, right_length]) * 2
if length > max_length:
	max_length = length
print(max_length)


input()
nums = list(map(int, input().split()))
last = -1
nums += [-1]
segs = []
cur_seg = 0
for (i, num) in enumerate(nums):
	if num != last:
		if cur_seg != 0:
			segs.append(cur_seg)
		cur_seg = 1
	else:
		cur_seg += 1
	last = num
answer = 0
for i in range(len(segs) - 1):
	answer = max(answer, 2 * min(segs[i], segs[i + 1]))
print(answer)


n = int(input())
a = list(map(int, input().split()))
c = []
t1 = 0
t2 = 0
for i in range(n - 1):
	if a[i] == 1:
		t1 += 1
		if a[i + 1] != a[i]:
			c.append(t1)
			t1 = 0
	else:
		t2 += 1
		if a[i + 1] != a[i]:
			c.append(t2)
			t2 = 0
c.append(max(t1 + 1, t2 + 1))
mx = 0
for i in range(len(c) - 1):
	mx = max(mx, min(c[i], c[i + 1]))
print(mx * 2)


n = int(input())
t = input().split()
flag = t[0]
count = 0
aux = []
for i in range(len(t)):
	aux.append(0)
	if flag == t[i]:
		aux[count] += 1
	else:
		count += 1
		aux[count] = 1
		flag = t[i]
l = 0
res = 0
for i in range(1, len(aux)):
	if aux[i] < aux[i - 1]:
		l = aux[i]
	else:
		l = aux[i - 1]
	if res > l:
		continue
	else:
		res = l
print(res * 2)


n = int(input())
ls = list(map(int, input().split()))
(count, maxl) = (0, 0)
(p1, p2) = (0, 0)
change = 0
for i in range(len(ls)):
	if ls[i] == 2:
		if change != 2:
			p2 = 1
			change = 2
		else:
			p2 += 1
	elif change != 1:
		p1 = 1
		change = 1
	else:
		p1 += 1
	temp = 2 * min((p1, p2))
	if temp > maxl:
		maxl = temp
print(maxl)


def function(sequence):
	list = []
	subList1 = []
	subList2 = []
	for n in sequence:
		if n == 1 and len(subList2) == 0:
			subList1.append(n)
		elif n == 2 and len(subList1) == 0:
			subList2.append(n)
		elif n == 1 and len(subList2) != 0:
			list.append(subList2)
			subList1.append(n)
			subList2 = []
		elif n == 2 and len(subList1) != 0:
			list.append(subList1)
			subList2.append(n)
			subList1 = []
	if len(subList1) != 0:
		list.append(subList1)
	elif len(subList2) != 0:
		list.append(subList2)
	greaterValue = 0
	for i in range(len(list) - 1):
		if len(list[i]) >= len(list[i + 1]) and len(list[i + 1]) > greaterValue:
			greaterValue = len(list[i + 1])
		elif len(list[i]) < len(list[i + 1]) and len(list[i]) > greaterValue:
			greaterValue = len(list[i])
	return 2 * greaterValue
n = int(input())
sequence = list(map(int, input().split()))
print(function(sequence))


c = int(input())
t = list(map(int, input().split()))
count = 0
last_seen = 0
count_for_last = 0
count_for_last_last = 0
for i in range(c):
	if last_seen == 0:
		last_seen = t[i]
		count_for_last += 1
		continue
	if last_seen == t[i]:
		count_for_last += 1
	else:
		if min(count_for_last_last, count_for_last) > count:
			count = min(count_for_last_last, count_for_last)
		count_for_last_last = count_for_last
		last_seen = t[i]
		count_for_last = 1
if min(count_for_last_last, count_for_last) > count:
	count = min(count_for_last_last, count_for_last)
print(count * 2)


import sys

class ASushiForTwo:

	def solve(self):
		n = int(input())
		a = [int(_) for _ in input().split()]
		ans = 0
		last = 0
		i = 0
		cur = 0
		while i < n and a[i] == a[0]:
			i += 1
			last += 1
		cur = 1
		for k in range(i + 1, n + 1):
			if k < n and a[k] == a[k - 1]:
				cur += 1
			else:
				ans = max(ans, 2 * min(cur, last))
				(last, cur) = (cur, 1)
		print(ans)
solver = ASushiForTwo()
input = sys.stdin.readline
solver.solve()


n = int(input())
a = list(map(int, input().split()))
c = 1
e = []
k = 0
for i in range(1, len(a)):
	if a[i] == a[i - 1]:
		c += 1
	else:
		e.append(c)
		c = 1
if c:
	e.append(c)
for i in range(len(e) - 1):
	k = max(k, 2 * min(e[i], e[i + 1]))
print(k)


n = int(input())
a = list(map(int, input().split(' ')))
m = 0
c = []
t = 1
for i in range(1, n):
	if a[i] == a[i - 1]:
		t += 1
	else:
		c.append(t)
		t = 1
	if i == n - 1:
		c.append(t)
s = list(set(a))
for i in range(1, len(c)):
	q = c[i - 1:i + 1]
	l = min(q)
	if 2 * l > m:
		m = 2 * l
print(m)


n = int(input())
t = list(map(int, input().split()))
et = 0
eu = 0
m = 0
p = []
for i in range(n):
	if t[i] == 1:
		et += 1
		if eu != 0:
			p.append(eu)
			eu = 0
	else:
		eu += 1
		if et != 0:
			p.append(et)
			et = 0
if eu != 0 or et != 0:
	p.append(max(et, eu))
for i in range(len(p) - 1):
	m = max(m, min(p[i], p[i + 1]))
print(2 * m)


n = int(input())
sushi = [int(x) for x in input().strip().split(' ')]
newList = []
prev = sushi[0]
newList.append(1)
for type in sushi[1:]:
	if prev != type:
		newList.append(1)
	else:
		newList[len(newList) - 1] += 1
	prev = type
maxSushi = 0
for (i, j) in zip(newList, newList[1:]):
	maxSushi = max(maxSushi, min(i, j))
print(maxSushi * 2)


import sys, math, queue
sys.setrecursionlimit(1000000)
n = int(input())
a = list(map(int, input().split()))
p = [0 for i in range(n)]
p[0] = 0
d = []
for i in range(1, n):
	if a[i] == a[i - 1]:
		p[i] = p[i - 1]
	else:
		p[i] = i
		d.append(i - p[i - 1])
d.append(n - p[n - 1])
ans = 0
for i in range(1, len(d)):
	ans = max(ans, 2 * min(d[i], d[i - 1]))
print(ans)


n = int(input())
a = list(map(int, input().split()))
da = {}
db = {}
b = False
ci = 0
for i in range(n):
	if a[i] == 1 and (not b):
		da[i] = i
		ci = i
		b = True
	elif a[i] == 2 and b:
		b = False
	elif a[i] == 1 and b:
		da[ci] = i
b = False
for i in range(n):
	if a[i] == 2 and (not b):
		db[i] = i
		ci = i
		b = True
	elif a[i] == 1 and b:
		b = False
	elif a[i] == 2 and b:
		db[ci] = i
m = 0
for i in da:
	if da[i] + 1 in db:
		m = max(m, 2 * min(da[i] - i + 1, db[da[i] + 1] - da[i]))
for i in db:
	if db[i] + 1 in da:
		m = max(m, 2 * min(db[i] - i + 1, da[db[i] + 1] - db[i]))
print(m)


n = int(input())
t = list(map(int, input().split()))
cnt = 1
v = []
for i in range(1, n):
	if t[i] == t[i - 1]:
		cnt += 1
	else:
		v.append(cnt)
		cnt = 1
v.append(cnt)
ans = 0
for i in range(len(v) - 1):
	ans = max(ans, min(v[i], v[i + 1]))
print(ans * 2)


n = int(input())
ar = list(map(int, input().split()))
v = list()
cur = int(-1)
ans = int(0)
cnt = int(0)
for x in ar:
	if cur == -1:
		cur = x
		cnt = 1
	elif cur == x:
		cnt += 1
	else:
		v.append(cnt)
		cnt = 1
		cur = x
v.append(cnt)
for i in range(0, len(v) - 1):
	ans = max(ans, min(v[i], v[i + 1]))
print(ans * 2)


n = int(input())
food = input().split()

def solve(s):
	res = []
	counter = 1
	for i in range(1, len(s)):
		if s[i - 1] == s[i]:
			counter += 1
		else:
			res.append(int(counter))
			counter = 1
	res.append(int(counter))
	pos = []
	for i in range(1, len(res)):
		pos.append(min(res[i], res[i - 1]))
	return max(pos) * 2
print(solve(food))


n = int(input())
t = list(map(len, input().replace(' ', '').replace('12', '1 2').replace('21', '2 1').split(' ')))
y = []
for i in range(len(t) - 1):
	if t[i] <= t[i + 1]:
		y.append(t[i])
	if t[i] >= t[i + 1]:
		y.append(t[i + 1])
print(2 * max(y))


n = int(input())
a = list(map(int, input().split()))
a.append(0)
(count, maxcount, tempmax, tempcount) = (0, 0, 0, 0)
for i in range(n):
	count += 1
	if a[i + 1] != a[i]:
		tempmax = min(tempcount, count)
		if maxcount < tempmax:
			maxcount = tempmax
		tempcount = count
		count = 0
print(2 * maxcount)


import os
import sys
from io import BytesIO, IOBase
from itertools import groupby

def main():
	n = int(input())
	a = list(map(int, input().split(' ')))
	ans = 0
	here = [[x, len(list(y))] for (x, y) in groupby(a)]
	for x in range(1, len(here)):
		ans = max(ans, min(here[x][1], here[x - 1][1]) * 2)
	print(ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

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


input()
(a, z, i, m) = (input().replace(' ', ''), 0, 1, [])
for (a, b) in zip(a, a[1:]):
	if a == b:
		i += 1
	else:
		(z, i) = (i, 1)
	m += [min(z, i)]
print(max(m) * 2)


n = int(input())
arr = [int(i) for i in input().split()]
nums = list()
is_1 = arr[0] == 1
is_2 = arr[0] == 2
counter = 0
for i in range(n):
	if is_1 and arr[i] == 1 or (is_2 and arr[i] == 2):
		counter += 1
	else:
		(is_1, is_2) = (is_2, is_1)
		nums.append(counter)
		counter = 1
nums.append(counter)
ans = 0
for i in range(1, len(nums)):
	ans = max(ans, min(nums[i], nums[i - 1]))
print(ans * 2)


n = int(input())
lst = map(int, input().split())
(cur, length, tem, ans) = (0, [], 0, 0)
for i in lst:
	if i != cur:
		cur = i
		length.append(tem)
		tem = 1
	else:
		tem += 1
length.append(tem)
for i in range(len(length) - 1):
	if ans < min(length[i], length[i + 1]):
		ans = min(length[i], length[i + 1])
print(ans * 2)


n = int(input())
t = list(map(int, input().split()))
l = []
c = 1
ans = 1
for i in range(len(t) - 1):
	if t[i] == t[i + 1]:
		c += 1
	else:
		l.append(c)
		c = 1
	if i == len(t) - 2:
		l.append(c)
for i in range(len(l) - 1):
	if min(l[i], l[i + 1]) > ans:
		ans = min(l[i], l[i + 1])
print(ans * 2)


def sushi(lst):
	(prt, t) = (0, 0)
	(pru, u) = (0, 0)
	result = 0
	for i in range(len(lst)):
		if lst[i] == 1:
			t += 1
			if u > 0:
				pru = u
				u = 0
		else:
			u += 1
			if t > 0:
				prt = t
				t = 0
		result = max(result, 2 * min(t, pru))
		result = max(result, 2 * min(u, prt))
	return result
n = int(input())
a = [int(j) for j in input().split()]
print(sushi(a))


n = int(input())
seq = input().split(' ')
maxLength = 0
lastLetter = seq[0]
lastLetterLength = 0
currentLetterLength = 1
for i in range(1, n):
	if seq[i] == lastLetter:
		currentLetterLength += 1
	elif lastLetterLength == 0:
		lastLetterLength = currentLetterLength
		currentLetterLength = 1
	else:
		maxLength = max(maxLength, min(currentLetterLength, lastLetterLength))
		lastLetterLength = currentLetterLength
		currentLetterLength = 1
	lastLetter = seq[i]
maxLength = 2 * max(maxLength, min(currentLetterLength, lastLetterLength))
print(maxLength)


n = int(input())
sushi = list(map(int, input().split()))
cur_start = -1
cur_mid = -1
cur_end = -1
i = 0
result = 0
while i < len(sushi):
	if cur_start == -1:
		cur_start = i
		cur_end = i
		left = sushi[i]
	else:
		cur_end = i
		if sushi[i] != sushi[i - 1]:
			if cur_mid == -1:
				cur_mid = i
			else:
				result = max(result, min(cur_mid - cur_start, cur_end - cur_mid) * 2)
				cur_start = cur_mid
				cur_mid = i
				cur_end = -1
	i += 1
print(max(result, min(cur_mid - cur_start, i - cur_mid) * 2))


def read_items():
	return list(map(int, input().strip().split()))
n = int(input())
t = read_items()
change_points = [-1]
for idx in range(n - 1):
	if t[idx + 1] != t[idx]:
		change_points.append(idx)
change_points.append(n - 1)
lengths = list()
for (curr, next) in zip(change_points[:-1], change_points[1:]):
	lengths.append(next - curr)
m = len(lengths)
max_len = 0
for idx in range(m - 1):
	curr_max = min(lengths[idx], lengths[idx + 1])
	if curr_max > max_len:
		max_len = curr_max
print(2 * max_len)


n = int(input())
t = input().split()
um = dois = 0
resp = 0
ult = t[0]
for e in range(n):
	if e == n - 1:
		if t[e] == '1':
			um += 1
		else:
			dois += 1
		resp = max(resp, min(um, dois))
	else:
		if t[e] != ult and um > 0 and (dois > 0):
			resp = max(resp, min(um, dois))
			if ult == '1':
				dois = 0
			else:
				um = 0
		if t[e] == '1':
			um += 1
		else:
			dois += 1
	ult = t[e]
print(resp * 2)


n = int(input())
a = list(map(int, input().split()))
i = 0
b = []
while i < n:
	if a[i] == 2:
		j = i
		two = 0
		while j < n and a[j] == 2:
			two += 1
			j += 1
		b.append(two)
		i = j
	else:
		j = i
		one = 0
		while j < n and a[j] == 1:
			one += 1
			j += 1
		b.append(one)
		i = j
ans = 0
for i in range(1, len(b)):
	ans = max(ans, min(b[i], b[i - 1]))
print(2 * ans)


n = int(input())
l = [int(num) for num in input().split()]
(m, i, p, c) = (0, 0, 0, 0)
while i < n - 1:
	if l[i] != l[i + 1]:
		(j, k, c, p) = (i - 1, i + 2, 1, 1)
		while j >= 0:
			if l[j] == l[i]:
				(c, j) = (c + 1, j - 1)
			else:
				break
		while k < n:
			if l[k] == l[i + 1]:
				(p, k) = (p + 1, k + 1)
			else:
				break
	m = max(m, min(p, c))
	i = i + 1
print(2 * m)


def main():
	n = int(input())
	t = [int(x) for x in input().split()]
	i = 0
	l1 = 1
	l2 = 1
	ans = 2
	while i < n:
		l1 = 1
		l2 = 1
		while i < n - 1 and t[i] == t[i + 1]:
			l1 += 1
			i += 1
		jump = i
		i += 1
		while i < n - 1 and t[i] == t[i + 1]:
			l2 += 1
			i += 1
		l = min(l1, l2)
		ans = max(ans, l * 2)
		i = jump + 1
	print(ans)
main()


n = int(input())
ar = list(map(int, input().split()))
rez = 0
cur = 1
prev = 0
for i in range(1, n):
	if ar[i] == ar[i - 1]:
		cur += 1
	else:
		rez = max(rez, min(prev, cur) * 2)
		prev = cur
		cur = 1
print(max(rez, min(prev, cur) * 2))


n = int(input())
l = list(map(int, input().split()))
lb = 0
cb = 1
ans = 0
for i in range(1, n):
	if l[i] == l[i - 1]:
		cb += 1
	else:
		ans = max(ans, min(cb, lb))
		lb = cb
		cb = 1
ans = max(ans, min(cb, lb))
print(ans * 2)


from itertools import groupby
input()
A = [len(list(g)) for (_, g) in groupby(input().replace(' ', ''))]
print(2 * max((min(A[i], A[i + 1]) for i in range(len(A) - 1))))


n = input()
sushi = list(map(int, input().split()))
longest = 0
tuna = 0
eel = 0
previous = 0
for s in sushi:
	if s == 1 and previous == 2:
		if min(tuna, eel) > longest:
			longest = min(tuna, eel)
		tuna = 1
	elif s == 2 and previous == 1:
		if min(tuna, eel) > longest:
			longest = min(tuna, eel)
		eel = 1
	elif s == 1:
		tuna += 1
	else:
		eel += 1
	previous = s
if min(tuna, eel) > longest:
	longest = min(tuna, eel)
print(longest * 2)


def main():
	n = int(input())
	t = list(map(int, input().split()))
	prev = 0
	count = 0
	p = 0
	ans = 0
	num = 0
	for i in range(n):
		num = t[i]
		if num == prev:
			count += 1
		else:
			p = count
			count = 1
		prev = num
		ans = max(ans, 2 * min(p, count))
	print(ans)
main()


maxn = 100100
a = [0] * maxn
cnt = [0] * 3
ans = 1
tot = 0
n = int(input())
a = list(map(int, input().split()))
a.insert(0, 0)
tot = a[1]
cnt[tot] += 1
for i in range(2, n + 1):
	if a[i] != tot:
		cnt[a[i]] = 1
		tot = a[i]
	else:
		cnt[a[i]] += 1
	ans = max(ans, min(cnt[1], cnt[2]))
print(ans * 2, end='')


n = int(input())
a = list(map(int, input().split()))
v = []
prev = 0
cnt = 0
for item in a:
	if item == prev:
		cnt += 1
	else:
		if cnt > 0:
			v.append(cnt)
		cnt = 1
	prev = item
v.append(cnt)
ans = v[0]
try:
	max_ans = min(v[0], v[1]) * 2
	for i in range(len(v) - 1):
		if max_ans < min(v[i], v[i + 1]) * 2:
			max_ans = min(v[i], v[i + 1]) * 2
	print(max_ans)
except:
	print(0)


a = int(input())
t = list(map(int, input().split()))
s = []
o = 0
tw = 0
for k in range(a):
	if t[k] == 1:
		o += 1
		if tw > 0:
			s.append([tw, 2])
			tw = 0
	elif t[k] == 2:
		tw += 1
		if o > 0:
			s.append([o, 1])
			o = 0
if o > 0:
	s.append([o, 1])
if tw > 0:
	s.append([tw, 2])
p = []
for i in range(len(s) - 1):
	if s[i][1] != s[i + 1][1]:
		p.append(min(s[i][0], s[i + 1][0]))
print(max(p) * 2)


n = int(input())
if n == 0:
	print(0)
	exit(0)
nums = input().split()
repeat = list()
prev = nums[0]
cnt = 1
for i in range(1, len(nums)):
	if prev == nums[i]:
		cnt = cnt + 1
	else:
		repeat.append(cnt)
		cnt = 1
	prev = nums[i]
repeat.append(cnt)
m = 0
for i in range(0, len(repeat) - 1):
	m = max(m, min(repeat[i], repeat[i + 1]))
print(2 * m)


n = int(input())
li = list(map(int, input().split()))
one = 1
another_one = 0
previous = 0
max_len = 0
for i in range(n):
	if previous == li[i] and i < n - 1:
		one = one + 1
	else:
		if i == n - 1 and li[i] == previous:
			one = one + 1
		if one >= another_one:
			max_len = max(max_len, another_one)
		else:
			max_len = max(max_len, one)
		previous = li[i]
		another_one = one
		one = 1
print(2 * max_len)


import sys
leng = sys.stdin.readline()
array = sys.stdin.readline().split(' ')
array = list(map(int, array))
counter = {}
prev = array[0]
i = 0
out = 0
while i < len(array):
	if array[i] == prev:
		counter[array[i]] = counter.get(array[i], 0) + 1
	else:
		length = min(counter.get(2, 0), counter.get(1, 0))
		out = max(out, length)
		counter[array[i]] = 0
		counter[array[i]] += 1
		prev = array[i]
	if i == len(array) - 1:
		length = min(counter.get(1, 0), counter.get(2, 0))
		out = max(length, out)
	i += 1
print(2 * out)


total_length = int(input())
sushi_line = input().split(' ')
current_type = sushi_line[0]
prev_type = current_type
segment_counts = [1]
count_index = 0
for i in range(1, total_length):
	current_type = sushi_line[i]
	if current_type == prev_type:
		segment_counts[count_index] += 1
	else:
		count_index += 1
		segment_counts.append(1)
		prev_type = current_type
max_segment_length = 0
for i in range(len(segment_counts) - 1):
	current_segment = 2 * min(segment_counts[i], segment_counts[i + 1])
	if current_segment > max_segment_length:
		max_segment_length = current_segment
	else:
		continue
print(max_segment_length)


def sames(arr):
	pint = arr.pop(0)
	cont = 1
	while len(arr) > 0:
		if arr[0] == pint:
			arr.pop(0)
			cont += 1
		else:
			break
	return cont

def c():
	_ = int(input())
	arr = list(map(int, input().split()))
	conts = []
	while len(arr) > 0:
		coso = sames(arr)
		conts.append(coso)
	maxi = 0
	for (index, count) in enumerate(conts):
		if index < len(conts) - 1:
			maxi = max(maxi, min(count, conts[index + 1]))
	print(maxi * 2)
c()


numero_entradas = input()
linha = input().split(' ')
tamanho_maximo = 0
for i in range(1, len(linha)):
	if linha[i - 1] != linha[i]:
		tamanho = 1
		while (i - tamanho - 1 >= 0 and i + tamanho < len(linha)) and (linha[i - tamanho - 1] == linha[i - 1] and linha[i + tamanho] == linha[i]):
			tamanho += 1
		if tamanho > tamanho_maximo:
			tamanho_maximo = tamanho
print(tamanho_maximo * 2)


f = lambda : map(int, input().split())
n = int(input())
l = list(f())
v = l[0]
s = [1]
for i in l[1:]:
	if i == v:
		s[-1] += 1
	else:
		v = i
		s.append(1)
v = 0
for i in range(len(s) - 1):
	v = max(v, min(s[i], s[i + 1]))
print(2 * v)


n = int(input())
daf = list(map(int, input().split()))
maxP = cur = 0
seq = [0, 0, 0]
for i in range(n):
	if cur != daf[i]:
		seq[daf[i]] = 1
	else:
		seq[daf[i]] += 1
	maxP = max(maxP, min(seq[1], seq[2]))
	cur = daf[i]
print(2 * maxP)


R = lambda : map(int, input().split())
n = int(input())
A = list(R()) + [0]
res = 0
c = 1
L = []
for i in range(1, n + 1):
	if A[i] != A[i - 1]:
		L.append(c)
		c = 0
	c += 1
l = len(L)
for i in range(1, l):
	res = max(res, min(L[i], L[i - 1]) * 2)
print(res)


n = int(input())
s = input().split()
a = 1
t = []
for i in range(n - 1):
	if s[i] == s[i + 1]:
		a += 1
	elif s[i] != s[i + 1]:
		t.append(a * s[i])
		a = 1
		if i == n - 2:
			t.append(s[i + 1])
	if i == n - 2 and s[i] == s[i + 1]:
		t.append(a * s[i])
z = []
for i in range(len(t) - 1):
	z.append(min(len(t[i]), len(t[i + 1])) * 2)
print(max(z))


a = int(input())
b = input().split(' ')
b = list(map(lambda x: int(x), b))
arr = []
for i in range(a):
	try:
		if b[i] != b[i - 1]:
			arr.append(1)
		else:
			arr[-1] += 1
	except:
		arr.append(1)
ans = 0
if len(arr) > 1:
	for i in range(len(arr) - 1):
		ans = max(ans, 2 * min(arr[i], arr[i + 1]))
print(ans)


n = int(input())
lst = list(map(int, input().split()))
arr = list()
ones = 0
two = 0
flag1 = 0
flag2 = 0
for i in range(n):
	if lst[i] == 1 and flag2 == 1:
		flag2 = 0
		flag1 = 1
		arr.append(two)
		two = 0
		ones += 1
	elif lst[i] == 2 and flag1 == 1:
		flag1 = 0
		flag2 = 1
		arr.append(ones)
		ones = 0
		two += 1
	elif lst[i] == 1:
		ones += 1
		flag1 = 1
	else:
		two += 1
		flag2 = 1
if flag1 == 1:
	arr.append(ones)
else:
	arr.append(two)
max_ele = 0
for i in range(1, len(arr)):
	max_ele = max(max_ele, min(arr[i], arr[i - 1]))
print(2 * max_ele)


n = int(input())
a = list(map(int, input().split()))
b = [1]
for i in range(1, n):
	if a[i] == a[i - 1]:
		b[-1] += 1
	else:
		b.append(1)
m = 0
for i in range(1, len(b)):
	if min(b[i], b[i - 1]) > m:
		m = min(b[i], b[i - 1])
print(2 * m)


from itertools import groupby
n = int(input())
sushi = list(map(int, input().split()))
grouped = [sum((1 for _ in g)) for (k, g) in groupby(sushi)]
temp = 0
max_len = 0
for i in range(len(grouped) - 1):
	if grouped[i] <= grouped[i + 1]:
		temp = grouped[i] * 2
	elif grouped[i] > grouped[i + 1]:
		temp = grouped[i + 1] * 2
	max_len = max(temp, max_len)
print(max_len)


n = int(input())
a = list(map(int, input().split()))
counter = 1
mas = [-1 for k in range(n)]
cnt = 0
for i in range(0, n):
	if i == n - 1:
		mas[cnt] = counter
		cnt += 1
		continue
	if a[i] == a[i + 1]:
		counter += 1
	else:
		mas[cnt] = counter
		cnt += 1
		counter = 1
max = -1
for k in range(0, n - 1):
	if mas[k] <= mas[k + 1]:
		if max < mas[k] * 2:
			max = mas[k] * 2
	if mas[k] >= mas[k + 1]:
		if max < mas[k + 1] * 2:
			max = mas[k + 1] * 2
print(max)


def rs():
	return input().strip()

def ri():
	return int(input())

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

def ia_to_s(a):
	return ' '.join([str(s) for s in a])

def solve(n, t):
	i = 0
	ans = 2
	while i < n:
		cl = t[i]
		j = i
		while j < n and t[j] == cl:
			j += 1
		left = j - i
		right = 0
		if j < n:
			cr = t[j]
			while j < n and t[j] == cr:
				j += 1
			right = j - i - left
		ans = max(ans, 2 * min(left, right))
		i += left
	return ans

def main():
	n = ri()
	t = ria()
	print(solve(n, t))
main()


n = int(input())
a = input().split()
x = a[0]
counter = 0
b = []
maxe = 0
for i in range(n):
	if a[i] == x:
		counter += 1
	else:
		b.append(counter)
		counter = 1
		x = a[i]
b.append(counter)
for i in range(len(b) - 1):
	maxe = max(min(b[i], b[i + 1]), maxe)
print(2 * maxe)


t = 1
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	ans = 0
	t = o = 0
	if a[0] == 1:
		o += 1
	else:
		t += 1
	for i in range(1, n):
		if a[i] == a[i - 1]:
			if a[i] == 2:
				t += 1
			else:
				o += 1
			continue
		if t > 0 and o > 0:
			ans = max(ans, min(t, o))
			if a[i] == 2:
				t = 1
			else:
				o = 1
		elif a[i] == 1:
			o += 1
		else:
			t += 1
	if t > 0 and o > 0:
		ans = max(ans, min(t, o))
	print(ans * 2)


def dcp(s):
	ans = []
	cur = 1
	s += '|'
	for i in range(1, len(s)):
		if s[i] == s[i - 1]:
			cur += 1
		else:
			ans.append(cur)
			cur = 1
	if cur > 1:
		ans.append(cur)
	return ans
n = int(input())
d = dcp(list(map(int, input().split())))
ans = 0
for i in range(1, len(d)):
	ans = max(ans, min(d[i - 1], d[i]))
print(ans * 2)


from itertools import groupby
t = input()
row = input().split()
row = [len(list(g)) for (k, g) in groupby(row)]
ans = 2 * max((min(a, b) for (a, b) in zip(row, row[1:])))
print(ans)


n = int(input())
a = [int(s) for s in input().split()]
i = 0
j = 0
cur1 = 0
cur = 0
res = 0
b = a[0]
prev = 0
while j < n and a[j] == b:
	j += 1
	cur1 += 1
	cur += 1
while i < n and j < n:
	if b == 1:
		b = 2
	else:
		b = 1
	prev = cur
	cur = 0
	while j < n and a[j] == b:
		j += 1
		cur1 += 1
		cur += 1
	if 2 * min(prev, cur) > res:
		res = 2 * min(prev, cur)
	while i < n and a[i] == 3 - b:
		i += 1
		cur1 -= 1
print(res)


n = int(input())
st = input().split(' ')
maxN = 0
temp1 = 1
temp2 = 0
for i in range(1, n):
	if st[i] == st[i - 1]:
		temp1 += 1
	else:
		maxN = max(maxN, min(temp1, temp2) * 2)
		temp2 = temp1
		temp1 = 1
maxN = max(maxN, min(temp1, temp2) * 2)
print(maxN)


n = int(input())
t = [int(i) for i in input().split()]
cur = 1
prev = 1
ans = 2
for i in range(n - 1):
	if t[i] == t[i + 1]:
		cur += 1
	else:
		ans = max(ans, 2 * min(prev, cur))
		prev = cur
		cur = 1
ans = max(ans, 2 * min(prev, cur))
print(ans)


n = int(input())
A = list(map(int, input().split()))
q = []
fl = A[0]
cnt = 0
ans = 1
for i in range(1, n):
	if A[i] == fl:
		cnt += 1
	else:
		q.append(cnt)
		cnt = 1
		fl = A[i]
q.append(cnt)
for u in range(len(q) - 1):
	ans = max(ans, min(q[u], q[u + 1]))
print(ans * 2)


from sys import stdin, stdout
N = int(input())
arr = [int(x) for x in stdin.readline().split()]
s = 0
last = arr[0]
stack = []
res = 0
for i in range(N):
	if arr[i] == last:
		if stack:
			if 2 * s + 1 <= i and stack[-(2 * s + 1)] != arr[i]:
				s += 1
			else:
				s = 0
	else:
		s = 1
	res = max(res, s * 2)
	stack.append(arr[i])
	last = arr[i]
print(res)


n = int(input())
sushi = input().replace(' ', '') + '0'
best = 1
lastchar = '0'
thisStreakLen = 1
lastStreakLen = 1
for char in sushi:
	if char == lastchar:
		thisStreakLen += 1
	else:
		lastchar = char
		segment = min(thisStreakLen, lastStreakLen) * 2
		if segment > best:
			best = segment
		lastStreakLen = thisStreakLen
		thisStreakLen = 1
print(best)


(_, ls, a, c, m) = (input(), [], 0, 0, 0)
for t in input().split():
	if a != t:
		ls.append(c)
		c = 0
	a = t
	c += 1
ls.append(c)
for i in range(1, len(ls) - 1):
	m = max(m, min(ls[i], ls[i + 1]))
print(m * 2)


input()
a = [int(i) for i in input().split()]
c = []
(i, j) = (0, 0)
while i < len(a):
	while j < len(a) and a[i] == a[j]:
		j += 1
	c.append(j - i)
	i = j
ans = 0
for i in range(1, len(c)):
	ans = max(ans, min(c[i], c[i - 1]))
print(ans * 2)


n = int(input())
a = input().split()
b = []
c = []
count = 1
for i in range(1, n):
	if a[i] == a[i - 1]:
		count += 1
	else:
		b.append(count)
		count = 1
b.append(count)
for i in range(1, len(b)):
	if b[i - 1] >= b[i]:
		c.append(2 * b[i])
	else:
		c.append(2 * b[i - 1])
print(max(c))


from sys import stdin
inp = lambda : stdin.readline().strip()
n = int(inp())
a = [int(x) for x in inp().split()]
ans = 0
cons1 = 0
cons2 = 0
sec = False
for i in range(n):
	if i > 0:
		if a[i] != a[i - 1]:
			sec = not sec
			if cons1 > 0 and cons2 > 0 and sec:
				cons2 = 0
			elif cons1 > 0 and cons2 > 0:
				cons1 = 0
	if sec:
		cons2 += 1
	else:
		cons1 += 1
	ans = max(ans, min(cons1, cons2))
print(ans * 2)


n = int(input())
(cnt1, cnt2, last) = (0, 0, 0)
l = map(int, input().split())
ans = 0
for i in l:
	if i == 1:
		if last == 1:
			cnt1 += 1
		else:
			cnt1 = 1
	elif last == 2:
		cnt2 += 1
	else:
		cnt2 = 1
	last = i
	ans = max(ans, 2 * min(cnt1, cnt2))
print(ans)


n = int(input())
arr = list(map(int, input().split()))
max = 2
i = 0
a = 1
b = 1
while i + 1 < n:
	a = 1
	while i + 1 < n and arr[i] == arr[i + 1]:
		i += 1
		a += 1
	i += 1
	if 2 * min(a, b) > max:
		max = 2 * min(a, b)
	b = 1
	while i + 1 < n and arr[i] == arr[i + 1]:
		i += 1
		b += 1
	i += 1
	if 2 * min(a, b) > max:
		max = 2 * min(a, b)
print(max)


n = int(input())
sushi = [int(i) for i in input().split(' ')]
res = 0
for i in range(1, n):
	if sushi[i] == sushi[i - 1]:
		continue
	else:
		j = 0
		while i - 1 - j >= 0 and sushi[i - 1 - j] == sushi[i - 1] and (i + j < n) and (sushi[i + j] == sushi[i]):
			j += 1
		res = max(res, j + j)
print(res)


n = int(input())
L = [int(x) for x in input().split()]
t = 1
X = []
for i in range(1, n):
	if L[i] == L[i - 1]:
		t += 1
	else:
		X.append(t)
		t = 1
X.append(t)
best = 0
for i in range(1, len(X)):
	best = max(best, min(X[i], X[i - 1]))
print(2 * best)


n = int(input())
a = list(map(int, input().split()))
(cnt1, cnt2) = (0, 0)
(prev, ans) = (0, 0)
for x in a:
	if x == 1:
		if prev != 1:
			cnt1 = 1
		else:
			cnt1 += 1
	elif prev != 2:
		cnt2 = 1
	else:
		cnt2 += 1
	ans = max(ans, min(cnt1, cnt2))
	prev = x
print(ans * 2)


n = int(input())
x = list(map(int, input().split()))
antes = 0
count = 0
l = []
for i in x:
	if i != antes:
		l.append(count)
		count = 1
		antes = i
	else:
		count += 1
l.append(count)
k = 0
for i in range(1, len(l) - 1):
	n = min(l[i], l[i + 1])
	if n > k:
		k = n
print(k * 2)


n = int(input())
k = input().split(' ')
k = list(map(int, k))
last_bank = 0
current_bank = 1
ans = 0
for x in range(1, n):
	if k[x] == k[x - 1]:
		current_bank = current_bank + 1
	else:
		ans = max(ans, min(last_bank, current_bank))
		last_bank = current_bank
		current_bank = 1
ans = max(ans, min(last_bank, current_bank))
print(ans * 2)


n = int(input())
xx = input()
x = xx.split()
d = []
g = 1
for i in range(1, n):
	if x[i] == x[i - 1]:
		g += 1
	else:
		d.append(g)
		g = 1
d.append(g)
f = len(d)
s = []
for i in range(0, f - 1):
	s.append(min(d[i], d[i + 1]))
print(max(s) * 2)


from itertools import *
numberOfSushi = int(input())
sushiTypesList = input().split()
listOfLength = [len(list(group)) for (key, group) in groupby(sushiTypesList, lambda x: x[0])]
tupleOfLength = list(zip(listOfLength, listOfLength[1:]))
print(2 * max(map(min, tupleOfLength)))


n = int(input())
arr = list(map(int, input().split()))
brr = []
count = 0
for i in range(1, n):
	if i == 1:
		if arr[i] != arr[i - 1]:
			brr.append(1)
			count = 1
		else:
			count = 2
	elif arr[i] == arr[i - 1]:
		count += 1
	elif arr[i] != arr[i - 1]:
		brr.append(count)
		count = 1
brr.append(count)
maxsum = 0
cursum = 0
for j in range(1, len(brr)):
	cursum = min(brr[j], brr[j - 1]) * 2
	maxsum = max(cursum, maxsum)
print(maxsum)


n = int(input())
t = [int(s) for s in input().split(' ')]
prev = None
num = 0
switch = 0
result = 0
for i in range(len(t)):
	if prev == t[i]:
		num += 1
	else:
		prev = t[i]
		temp = min(num, switch)
		result = max(result, temp)
		switch = num
		num = 1
temp = min(num, switch)
result = max(result, temp)
print(result * 2)


n = int(input())
arr = list(map(lambda x: int(x), input().split()))
b = []
for i in range(n):
	if arr[i] == 1:
		if len(b) == 0 or arr[i - 1] == 2:
			b.append([1, 1])
		elif b[-1][0] == 1:
			b[-1][1] += 1
	elif arr[i] == 2:
		if len(b) == 0 or arr[i - 1] == 1:
			b.append([2, 1])
		elif b[-1][0] == 2:
			b[-1][1] += 1
ans = 0
for i in range(len(b) - 1):
	ans = max(ans, min(b[i][1], b[i + 1][1]))
print(ans * 2)


n = int(input())
sushi = input().split(' ')
eel = 0
tuna = 0
size = []
valid = 0
for i in range(n - 1):
	if sushi[i] == '2':
		eel += 1
	if sushi[i] == '1':
		tuna += 1
	if sushi[i] == '2' and sushi[i] != sushi[i + 1]:
		size.append(eel)
		eel = 0
	if sushi[i] == '1' and sushi[i] != sushi[i + 1]:
		size.append(tuna)
		tuna = 0
if sushi[-1] == '2':
	eel += 1
	size.append(eel)
if sushi[-1] == '1':
	tuna += 1
	size.append(tuna)
for e in range(1, len(size)):
	if size[e] <= size[e - 1]:
		length = size[e] * 2
	elif size[e] >= size[e - 1]:
		length = size[e - 1] * 2
	if length > valid:
		valid = length
print(valid)


n = int(input())
sushi = list(map(int, input().split()))
(cnt1, cnt2) = (0, 0)
previousElement = 0
ans = 0
for i in sushi:
	if i == previousElement:
		cnt1 += 1
	else:
		cnt2 = cnt1
		cnt1 = 1
	previousElement = i
	ans = max(ans, min(cnt1, cnt2))
print(ans * 2)


n = int(input())
x = [int(x) for x in input().split()]
x.append(0)
p = q = cnt1 = cnt2 = best = 0
for i in range(n):
	if x[i] == 1:
		cnt1 += 1
		if x[i + 1] == 2:
			p = cnt1
			cnt1 = 0
	else:
		cnt2 += 1
		if x[i + 1] == 1:
			q = cnt2
			cnt2 = 0
	best = max(best, min(p, q))
	if x[i + 1] == 0:
		best = max(best, min(max(cnt1, p), max(cnt2, q)))
print(best * 2)


def main():
	n = int(input())
	sushi = input().replace(' ', '')
	lengths = []
	i = 0
	while i < n:
		try:
			j = next((index for index in range(i + 1, n) if sushi[index] != sushi[i]))
		except StopIteration:
			j = n
		lengths += [j - i]
		i = j
	possibilities = [0] * (n - 1)
	for i in range(len(lengths) - 1):
		possibilities[i] = min(lengths[i], lengths[i + 1]) * 2
	print(max(possibilities))
main()


n = int(input())
a = list(map(int, input().split()))
c = 1
res = []
for i in range(n - 1):
	if a[i] == a[i + 1]:
		c += 1
	else:
		res.append(c)
		c = 1
res.append(c)
mini = 10 ** 9
maxi = 0
for i in range(len(res) - 1):
	mini = min(res[i], res[i + 1])
	if mini > maxi:
		maxi = mini
print(maxi * 2)


from sys import exit, setrecursionlimit
setrecursionlimit(10 ** 6)
inn = lambda : input().strip()
mapp_m1 = lambda : map(lambda x: int(x) - 1, inn().split(' '))
mapp = lambda : map(int, inn().split(' '))
N = int(inn())
sushi = list(mapp())
sushi.append('dummy')
before = None
long = 0
zipp = []
for a in sushi:
	if a != before:
		zipp.append(long)
		before = a
		long = 1
	elif a == before:
		long += 1
answer = 0
for i in range(len(zipp) - 1):
	answer = max(answer, min(zipp[i], zipp[i + 1]))
print(answer * 2)


n = int(input())
s = str(input()).split()
n1 = n2 = m = 0
i = 0
while i < n:
	while i < n and int(s[i]) == 1:
		n1 += 1
		i += 1
	if min(n1, n2) > m:
		m = min(n1, n2)
	n2 = 0
	while i < n and int(s[i]) == 2:
		n2 += 1
		i += 1
	if min(n1, n2) > m:
		m = min(n1, n2)
	n1 = 0
print(2 * m)


a = int(input())
b = [int(i) for i in input().split()]
i1 = 0
i2 = 0
ans = 0
p = b[0]
flag = False
for i in range(a):
	if b[i] == p and flag:
		ans = max(ans, 2 * min(i1, i2))
		p = 3 - p
		i1 = i2
		i2 = 1
	elif b[i] != p:
		flag = True
		i2 += 1
	else:
		i1 += 1
	ans = max(ans, 2 * min(i1, i2))
print(ans)


from sys import stdin
size = int(input()) - 1
sushi = list(map(int, stdin.readline().split(' ')))
memo = 0
lista = list()
maxsum = 0
for n in range(size):
	if size == 1:
		if sushi[0] != sushi[1]:
			maxsum = 2
			break
		else:
			maxsum = 0
			break
	elif memo < size:
		suma = 0
		ana = sushi[memo]
		for m in range(size - memo):
			if sushi[memo + m + 1] == ana:
				suma += 1
			else:
				break
		lista.append(suma + 1)
		memo = memo + suma + 1
	elif sushi[size] != sushi[size - 1]:
		suma = 0
		lista.append(suma + 1)
		break
	else:
		break
for n in range(len(lista) - 1):
	if min(lista[n], lista[n + 1]) * 2 > maxsum:
		maxsum = min(lista[n], lista[n + 1]) * 2
print(maxsum)


len_ = int(input())
List = list(map(int, input().strip().split()))[0:len_]
temp = []
Highest = 0
count_2s = 0
count_1s = 0
previous = None
for i in range(0, len_):
	if List[i] == 1:
		if previous == 2:
			temp.append(count_2s)
			count_2s = 0
		count_1s += 1
		previous = 1
	elif List[i] == 2:
		if previous == 1:
			temp.append(count_1s)
			count_1s = 0
		count_2s += 1
		previous = 2
	if i == len_ - 1:
		if previous == 1:
			temp.append(count_1s)
		else:
			temp.append(count_2s)
for i in range(0, len(temp) - 1):
	if temp[i] > temp[i + 1]:
		Current = 2 * temp[i + 1]
	else:
		Current = 2 * temp[i]
	if Current > Highest:
		Highest = Current
print(Highest)


n = int(input())
t = list(map(int, input().split()))
a = list()
c = 1
for i in range(1, n):
	if t[i] == t[i - 1]:
		c += 1
	else:
		a.append(c)
		c = 1
	if i == n - 1:
		a.append(c)
m = a[0]
r = 0
for i in range(1, len(a)):
	m = min(a[i], a[i - 1])
	r = max(r, m)
if len(a) < 2:
	r = 0
print(r * 2)


n = int(input())
p = [*map(int, input().split())]
q = []
yeon = 0
cho = p[0]
for i in range(n):
	if cho == p[i]:
		yeon += 1
	else:
		q.append(yeon)
		yeon = 1
		cho = p[i]
q.append(yeon)
ans = 0
qs = len(q)
for i in range(qs - 1):
	ans = max(ans, min(q[i], q[i + 1]))
print(ans * 2)


n = int(input())
inp = list(map(int, input().split()))
dic = {1: [], 2: []}
i = 0
j = 0
while i < n:
	j = i
	while j < n and inp[j] == inp[i]:
		j += 1
	dic[inp[i]].append([i, j])
	i = j
maximum = 0
i = 0
j = 0
while i < len(dic[1]) and j < len(dic[2]):
	if dic[1][i][0] == dic[2][j][1]:
		tmp = min(dic[1][i][1] - dic[1][i][0], dic[2][j][1] - dic[2][j][0]) * 2
		maximum = tmp if tmp > maximum else maximum
	elif dic[1][i][1] == dic[2][j][0]:
		tmp = min(dic[1][i][1] - dic[1][i][0], dic[2][j][1] - dic[2][j][0]) * 2
		maximum = tmp if tmp > maximum else maximum
	if dic[1][i][0] > dic[2][j][0] and dic[1][i][1] > dic[2][j][1]:
		j += 1
	else:
		i += 1
print(maximum)


n = int(input())
t = list(map(int, input().split()))
L = []
c = 0
for (i, x) in enumerate(t):
	if i == 0 or x == t[i - 1]:
		c += 1
	else:
		L.append(c)
		c = 1
L.append(c)
ret = max([2 * min(L[i - 1], L[i]) for i in range(1, len(L))])
print(ret)


n = int(input())
a = list(map(int, input().split()))
ans = 0
i = 0
pv = 0
while i < n:
	ch1 = 1
	j = i + 1
	while j < n and a[j] == a[j - 1]:
		ch1 += 1
		j += 1
	ans = max(ans, min(pv, ch1) * 2)
	i = j
	pv = ch1
print(ans)


max_length = 0
input()
arr = list(map(int, input().split()))
p = 0
length = 0
length_arr = []
for a in arr:
	if p == 0 or p == a:
		p = a
		length = length + 1
	else:
		length_arr.append(length)
		p = a
		length = 1
length_arr.append(length)
for i in range(len(length_arr) - 1):
	l = min(length_arr[i], length_arr[i + 1])
	if l > max_length:
		max_length = l
print(2 * max_length)


N = int(input())
A = [int(i) for i in input().split()]
C = []
c = 0
t = A[0]
for i in range(len(A)):
	if A[i] == t:
		c += 1
	else:
		C.append(c)
		c = 1
		t = A[i]
C.append(c)
r = max((2 * min(i, j) for (i, j) in zip(C[+1:], C[:-1])))
print(r)


n = input()
A = [*map(int, input().split())]
prevlength = 0
length = 1
ans = 0
for i in range(1, len(A)):
	if A[i - 1] == A[i]:
		length += 1
	else:
		prevlength = length
		length = 1
	ans = max(ans, 2 * min(length, prevlength))
print(ans)


n = int(input())
t = [int(i) for i in input().split()]
i = j = 1
n = []
for k in range(len(t) - 1):
	if t[k] == t[k + 1] == t[0]:
		i += 1
	elif t[k] == t[k + 1] == t[0] % 2 + 1:
		j += 1
	else:
		n.append(min(i, j))
		if t[k + 1] == t[0]:
			i = 1
		else:
			j = 1
n.append(min(i, j))
print(2 * max(n))


N = int(input())
A = list(map(int, input().split()))
p = 0
c = A[0]
ans = 0
j = 0
for i in range(N + 1):
	if i == N or A[i] != c:
		ans = max(ans, 2 * min(p, j))
		p = j
		c = A[i] if i != N else ''
		j = 1
	else:
		j += 1
print(ans)


n = int(input())
nums = list(map(int, input().split()))
difs = []
pnt1 = 0
for i in range(n - 1):
	if nums[i] != nums[i + 1]:
		difs.append(nums[pnt1:i + 1])
		pnt1 = i + 1
difs.append(nums[pnt1:])
ans = 0
for i in range(len(difs) - 1):
	ans = max(ans, min(len(difs[i]), len(difs[i + 1])) * 2)
print(ans)


import bisect
import os
from collections import Counter
import bisect
from collections import defaultdict
import math
import random
import heapq as hq
from math import sqrt
import sys
from functools import reduce, cmp_to_key
from collections import deque
import threading
from itertools import combinations
from io import BytesIO, IOBase
from itertools import accumulate

def primeFactors(n):
	prime = set()
	while n % 2 == 0:
		prime.add(2)
		n = n // 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			prime.add(i)
			n = n // i
	if n > 2:
		prime.add(n)
	return list(prime)

def getFactors(n):
	factors = []
	i = 1
	while i <= math.sqrt(n):
		if n % i == 0:
			if n // i == i:
				factors.append(i)
			else:
				factors.append(i)
				factors.append(n // i)
		i = i + 1
	return factors

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	num = []
	for p in range(2, n + 1):
		if prime[p]:
			num.append(p)
	return num

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

def sort_dict(key_value):
	return sorted(key_value.items(), key=lambda kv: (kv[1], kv[0]))

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

def num_input():
	return map(int, input().split())

def string_list():
	return list(input())

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def binaryToDecimal(n):
	return int(n, 2)

def solve():
	n = int(input())
	arr = list_input()
	i = 0
	j = 1
	prev_1 = 1
	while j < n and arr[j] == arr[i]:
		j += 1
		prev_1 += 1
	i = j
	ans = 0
	while i < n:
		j = i + 1
		prev_2 = 1
		while j < n and arr[j] == arr[i]:
			j += 1
			prev_2 += 1
		i = j
		ans = max(ans, 2 * min(prev_2, prev_1))
		prev_1 = prev_2
	print(ans)
t = 1
for _ in range(t):
	solve()


n = int(input())
s = [int(i) for i in input().split()]
s.append(0)
d = []
c = 0
r = []
for i in range(n):
	if s[i] == s[i + 1]:
		d.append(s[i])
	else:
		d.append(s[i])
		r.append(d)
		d = []
for i in range(len(r) - 1):
	if r[i][0] != r[i + 1][0]:
		c = 2 * min(len(r[i]), len(r[i + 1]))
		d.append(c)
print(max(d))


import sys
input = sys.stdin.readline
I = lambda : list(map(int, input().split()))
(n,) = I()
l = I()
a = []
c = 1
for i in range(n - 1):
	if l[i] != l[i + 1]:
		a.append(c)
		c = 1
	else:
		c += 1
a.append(c)
an = 0
for i in range(len(a) - 1):
	an = max(an, min(a[i], a[i + 1]))
print(an * 2)


n = int(input())
sushi = list(map(int, input().split()))
cnt = cnt1 = cnt2 = cnt2_before = cnt1_before = 0
for i in sushi:
	if i == 1:
		if cnt1 == 0:
			cnt2_before = cnt2
		cnt2 = 0
		cnt1 += 1
		if min(cnt1, cnt2_before) > cnt:
			cnt = min(cnt1, cnt2_before)
	if i == 2:
		if cnt2 == 0:
			cnt1_before = cnt1
		cnt2 += 1
		if min(cnt1_before, cnt2) > cnt:
			cnt = min(cnt1_before, cnt2)
		cnt1 = 0
print(cnt * 2)


n = int(input())
tis = list(map(int, input().split()))
c = [0]
ans = 1
for i in range(1, n):
	if tis[i] != tis[i - 1]:
		c.append(i)
c.append(n)
for i in range(1, len(c) - 1):
	ans = max(ans, min(c[i] - c[i - 1], c[i + 1] - c[i]))
print(ans * 2)


answer = 0
prev_len = 0
curr_len = 0
sushi_type = '0'
n = int(input())
for a in (input() + ' 0').split(' '):
	if a == sushi_type:
		curr_len += 1
	else:
		new_answer = min(prev_len, curr_len)
		if new_answer > answer:
			answer = new_answer
		prev_len = curr_len
		curr_len = 1
		sushi_type = a
print(answer * 2)


def convert(a):
	b = []
	prev = a[0]
	c = 1
	for i in range(1, len(a)):
		if a[i] == prev:
			c += 1
		else:
			b.append(c)
			c = 1
			prev = a[i]
	b.append(c)
	return b

def calc(a):
	b = []
	for i in range(1, len(a)):
		k = min(a[i], a[i - 1]) * 2
		b.append(k)
	return max(b)
n = int(input())
a = [int(i) for i in input().split()]
a = convert(a)
print(calc(a))


num = int(input())
lst = list(map(int, input().split()))
one = 0
two = 0
ans = 0
checker = 0
if lst[0] == 1:
	one += 1
else:
	two += 1
i = 1
while i < len(lst):
	if lst[i] != lst[i - 1]:
		checker += 1
	if checker == 2:
		ans = max(ans, min(one, two))
		if lst[i] == 1:
			one = 0
		else:
			two = 0
		checker = 1
	if lst[i] == 1:
		one += 1
	else:
		two += 1
	i += 1
ans = max(ans, min(one, two))
print(ans * 2)


n = int(input())
a = list(map(int, input().split()))
ma = 0
last = 0
cur = 1
for i in range(1, len(a)):
	if a[i] == a[i - 1]:
		cur += 1
	else:
		ma = max(ma, min(last, cur))
		last = cur
		cur = 1
	ma = max(ma, min(last, cur))
print(2 * ma)


n = int(input())
l = [int(j) for j in input().split()]
k = 0
d = [0] * n
q = l[0]
for i in range(n):
	if l[i] == q:
		k += 1
	else:
		if l[-1] == 1:
			d.append(k)
		else:
			d.append(k)
		q = l[i]
		k = 1
if l[-1] == 1:
	d.append(k)
else:
	d.append(k)
t = 0
for i in range(1, len(d)):
	t = max(t, 2 * min(d[i], d[i - 1]))
print(t)


n = input()
arr = input()
arr = list(arr.split(' '))
ma = 0
a1 = 0
a2 = 0
flag1 = 0
flag2 = 0
for x in arr:
	if int(x) == 1:
		if a2:
			flag2 = a2
		a1 += 1
		ma = max(min(a1, flag2), ma)
		a2 = 0
	else:
		if a1:
			flag1 = a1
		a2 += 1
		ma = max(min(flag1, a2), ma)
		a1 = 0
print(ma * 2)


input()
m = input().replace(' ', '').replace('12', '1 2').replace('21', '2 1').split()
ans = 0
for i in range(len(m) - 1):
	ans = max(min(len(m[i]), len(m[i + 1])), ans)
print(ans * 2)


from itertools import *
n = input()
list1 = list(map(int, input().split()))
t1Count = 0
t2Count = 0
MaxList = []
if list1[0] == 1:
	t1Count += 1
else:
	t2Count += 1
for i in range(1, len(list1)):
	if list1[i] == list1[i - 1]:
		if list1[i] == 1:
			t1Count += 1
		else:
			t2Count += 1
	elif list1[i - 1] == 1:
		MaxList.append(t1Count)
		t1Count = 0
		t2Count = 1
	else:
		MaxList.append(t2Count)
		t2Count = 0
		t1Count = 1
if list1[len(list1) - 1] == 1:
	MaxList.append(t1Count)
	t1Count = 0
else:
	MaxList.append(t2Count)
	t2Count = 0
minMaxList = []
for i in range(0, len(MaxList) - 1):
	minMaxList.append(min(MaxList[i], MaxList[i + 1]))
print(2 * max(minMaxList))


input()
data = map(int, input().split())
curr = next(data)
counts = [1]
for v in data:
	if v != curr:
		counts.append(0)
		curr = v
	counts[-1] += 1
print(2 * max((min(v1, v2) for (v1, v2) in zip(counts, counts[1:]))))


def ii():
	return int(input())

def fi():
	return float(input())

def si():
	return input()

def mi():
	return map(int, input().split())

def li():
	return list(mi())

def su(n):
	s = 0
	while n != 0:
		a = n % 10
		s += a
		n //= 10
	return s
n = ii()
a = li()
c = 1
k = []
for i in range(n - 1):
	if a[i] == a[i + 1]:
		c += 1
	else:
		k.append(c)
		c = 1
k.append(c)
ans = 0
for i in range(len(k) - 1):
	ans = max(ans, min(k[i], k[i + 1]))
print(ans * 2)


def main():
	from collections import deque
	n = int(input())
	t = [int(x) for x in input().strip().split(' ')]
	segments = get_segments(t)
	half = min(segments)
	for i in range(1, len(segments)):
		(t_im1, t_i) = (segments[i - 1], segments[i])
		half = max(half, min(t_im1, t_i))
	print(half * 2)

def get_segments(t):
	from collections import deque
	segments = deque()
	curr_count = 1
	prev_sushi = t[0]
	for sushi in t[1:]:
		if sushi == prev_sushi:
			curr_count += 1
		else:
			segments.append(curr_count)
			curr_count = 1
			prev_sushi = sushi
	segments.append(curr_count)
	return segments
main()


from sys import stdin, stdout

def inp():
	return int(stdin.readline())

def minp():
	return map(int, stdin.readline().rstrip().split())

def linp():
	return list(minp())

def main():
	n = inp()
	l = linp()
	store = []
	s = 1
	for i in range(n - 1):
		if l[i] == l[i + 1]:
			s += 1
		else:
			store.append(s)
			s = 1
	if s != 0:
		store.append(s)
	m = 0
	for i in range(len(store) - 1):
		x = min(store[i], store[i + 1])
		if x > m:
			m = x
	print(2 * m)
main()


def a(inp):
	curr = inp[0]
	start = 0
	end = 0
	prev = 1
	best = 0
	for (index, i) in enumerate(inp[1:]):
		if curr == i:
			end = index + 1
		else:
			best = max(best, min(prev, end - start + 1))
			prev = end - start + 1
			curr = i
			start = index + 1
			end = index + 1
	best = max(best, min(prev, end - start + 1))
	print(2 * best)
n = int(input())
t = list(map(int, input().split()))
a(t)


num1 = int(input())
str1 = list(map(int, input().split()))
q = ''
q1 = ''
list1 = []
c = 0
ans = 0
for i in range(num1 - 1):
	if str1[i] == str1[i + 1]:
		q += str(str1[i])
	else:
		q += str(str1[i])
		list1.append(q)
		q = ''
q += str(str1[num1 - 1])
list1.append(q)
for i in range(len(list1) - 1):
	c = len(list1[i])
	q1 = ''
	q1 += list1[i]
	for k in range(len(list1)):
		if list1[i].startswith('1'):
			if list1[i + 1].startswith('2'):
				if len(list1[i + 1]) >= len(q1):
					ans = max(ans, len(q1) * 2)
				elif len(list1[k]) <= len(q1):
					ans = max(ans, len(list1[i + 1]) * 2)
				break
			else:
				q1 += list1[i + 1]
		if list1[i].startswith('2'):
			if list1[i + 1].startswith('1'):
				if len(list1[i + 1]) >= len(q1):
					ans = max(ans, len(q1) * 2)
				elif len(list1[i + 1]) <= len(q1):
					ans = max(ans, len(list1[i + 1]) * 2)
				break
		else:
			q1 += list1[i + 1]
print(ans)


n = int(input())
l = list(map(int, input().split()))
ans = 0
twos = 0
ones = 0
if l[0] == 2:
	twos = 1
else:
	ones = 1
for i in range(1, n):
	if l[i] == l[i - 1]:
		if l[i] == 1:
			ones += 1
		else:
			twos += 1
	elif min(ones, twos) == 0:
		if ones == 0:
			ones = 1
		else:
			twos = 1
		continue
	else:
		ans = max(ans, min(ones, twos))
		if l[i] == 1:
			ones = 1
		else:
			twos = 1
ans = max(ans, min(ones, twos))
print(ans * 2)


n = int(input())
inp = list(map(int, input().split()))
count = []
maxi = []
a = inp[0]
county = 0
for i in range(len(inp)):
	if a == inp[i]:
		county += 1
	else:
		count.append(county)
		county = 1
		a = inp[i]
count.append(county)
for i in range(0, len(count) - 1):
	maxi.append(min(count[i], count[i + 1]))
print(2 * max(maxi))


n = int(input())
a = list(map(int, input().split()))
a.append(5)
tmp = []
(cur, an) = (0, 0)
for i in range(n):
	if a[i] == a[i + 1]:
		cur = cur + 1
	else:
		tmp.append(cur + 1)
		cur = 0
for i in range(len(tmp) - 1):
	an = max(an, min(tmp[i], tmp[i + 1]))
print(an * 2)


n = int(input())
a = list(map(int, input().split()))
count = 1
temp = a[0]
track = []
for i in range(1, n):
	if a[i] == temp:
		count += 1
	else:
		temp = a[i]
		track.append(count)
		count = 1
track.append(count)
temp = len(track)
count = 0
for i in range(temp - 1):
	if min(track[i], track[i + 1]) * 2 > count:
		count = min(track[i], track[i + 1]) * 2
print(count)


a = input()
a = input().split()
sushi = []
for i in a:
	sushi.append(int(i))
run = []
curr = sushi[0]
tmp_run = 0
for i in range(len(sushi)):
	if sushi[i] == curr:
		tmp_run += 1
	else:
		run.append([tmp_run, curr])
		curr = sushi[i]
		tmp_run = 1
run.append([tmp_run, curr])
ans = 0
for i in range(len(run) - 1):
	ans = max(min(run[i][0], run[i + 1][0]), ans)
print(2 * ans)