**附亲测代码**
```cpp
#include<bits/stdc++.h>
using namespace std;
int a[1000005];
int main(){
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n;
scanf("%d",&n);
for(int i=1; i<=n; i++){
scanf("%d",&a[i]);
a[i]+=a[i-1];
}
int ans=0,k;
bool f=1;
if(n%2!=0){
k=n-1;
}else{
k=n;
}
for(; k>=2; k-=2){
for(int i=1; i+k-1<=n; i++){
if(a[i+k-1]-a[i-1]==k/2){
ans=k;
f=0;
break;
}
}
if(!f){
break;
}
}
printf("%d\n",ans);
return 0;
}
```
by xuyunlong120820 @ 2024-08-29 14:01:00
nihao
by solitary_reeper @ 2024-08-30 08:14:13
hello
by Lethal_Deal @ 2024-08-30 08:15:16