forked from SaruarChy/Codeforces-Solution
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1138 A. Sushi for Two.cpp
47 lines (45 loc) · 988 Bytes
/
1138 A. Sushi for Two.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
//Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pb push_back
#define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL));
using namespace std;
int main()
{
fastread();
ll n,A;
ll a[100001];
fill(a,a+100001,1);
vector<ll>v;
cin>>n;
for(int i=0; i<n; i++){
cin>>A;
v.pb(A);
}
ll k=0,l=0,ans = 0;
for(int i=1; i<n; i++){
if(v[i] == v[i-1]){
a[k]++;
}
else{
k++;
}
}
for(int i=1; i<=k; i++){
if(a[i] == a[i-1]){
l = 2* a[i];
ans = max(ans,l);
}
else if(a[i] > a[i-1]){
l = 2* a[i-1];
ans = max(ans,l);
}
else{
l = 2* a[i];
ans = max(ans,l);
}
}
cout<<ans<<endl;
return 0;
}