Codeforces Round 545 (Div. 2)
A
Sushi for Two
Codeforces
900
原题
←B →
翻译中…

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.

翻译中…

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

翻译中…

样例

Input #1
7
2 2 2 1 1 2 2
Output #1
4
InputCopy OutputCopy
Input #2
6
1 2 1 2 1 2
Output #2
2
InputCopy OutputCopy
Input #3
9
2 2 1 1 1 2 2 2 2
Output #3
6
InputCopy OutputCopy
题目信息
题号
1138A
时间限制
1 s
内存限制
256 MB
标签
二分
贪心
模拟

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。