#include<iostream>
#include<cstdio>
#include<algorithm>
#define int long long
using namespace std;
const int N=2e5+5;
int t[N],a[N];
signed main(){
int n;
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n;
for(int i=1;i<=n;i++)
{
cin >> a[i];
}
int maxx=0,now=0,s;
for(int i=1;i<n;i++)
{
if(a[i]==a[i+1])
{
now+=2;
t[a[i]]++;
if(t[a[i]]>1)
{
maxx=max(maxx,now-2);
for(int j=s;;j+=2)
{
t[j]--;
now-=2;
if(a[i]==a[j])
{
break;
}
}
}
if(now==2)
{
s=i;
}
i++;
}
else
{
maxx=max(maxx,now);
for(int j=s;j<=i-2;j+=2)
{
t[j]--;
}
}
}
maxx=max(maxx,now);
cout << maxx;
return 0;
}
求帮忙把WA的改过来,TLE的不用管