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]$.

Difficulty: interview

Starter code:

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


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)

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)

#!/usr/bin/pypy
# -*- coding: utf-8 -*-


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)


def __starting_point():
    main()

__starting_point()

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())
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
    else:
        if a[i] == a[i - 1]:
            u += 1
        else:
            u = 1
    ans = max(ans, min(u, t))

print(ans * 2)


n=int(input())
# =map(int,input().split())
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())
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)

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


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


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


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)


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)


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)


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)

# coding: utf-8
# Your code here!

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)

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)


# -*- coding: utf-8 -*-
# @Time    : 2019/3/8 17:05
# @Author  : LunaFire
# @Email   : gilgemesh2012@gmail.com
# @File    : A. Sushi for Two.py

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

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


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

ans = 0
for x, y in zip(box, box[1:]):
    ans = max(ans, min(x, y))

print(ans * 2)

# coding: utf-8
# author: ismdeep
# dateime: 2019-03-08 17:07:47
# filename: a.py
# blog: https://ismdeep.com
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)