CF1138A.Sushi for Two

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Arkady invited Anna for a dinner to a sushi restaurant. The restaurant is a bit unusual: it offers nn 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 ii -th from the left sushi as tit_i , where ti=1t_i = 1 means it is with tuna, and ti=2t_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][2, 2, 2, 1, 1, 1] is valid, but subsegment [1,2,1,2,1,2][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.

输入格式

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

The second line contains nn integers t1t_1 , t2t_2 , ..., tnt_n ( ti=1t_i = 1 , denoting a sushi with tuna or ti=2t_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.

输出格式

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

输入输出样例

  • 输入#1

    7
    2 2 2 1 1 2 2
    

    输出#1

    4
    
  • 输入#2

    6
    1 2 1 2 1 2
    

    输出#2

    2
    
  • 输入#3

    9
    2 2 1 1 1 2 2 2 2
    

    输出#3

    6
    

说明/提示

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

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

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

首页