#include <bits/stdc++.h>
using namespace std;
int f[100002][3], dp[100002][3];
void solve() {
int n,m=0; cin >> n;
int a[n+1];
for(int i=1;i<=n;i++) {
cin >> a[i];
f[i][a[i]]=f[i-1][a[i]]+1;
}
for(int i=n;i>=1;i--) {
dp[i][a[i]]=dp[i+1][a[i]]+1;
m=max(m,min(f[i-1][1],dp[i][2]));
m=max(m,min(f[i-1][2],dp[i][1]));
m=max(m,min(f[i][1],dp[i+1][2]));
m=max(m,min(f[i][2],dp[i+1][1]));
}
cout << 2*m;
return;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
solve();
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CmludCBmWzEwMDAwMl1bM10sIGRwWzEwMDAwMl1bM107CnZvaWQgc29sdmUoKSB7CiAgICBpbnQgbixtPTA7IGNpbiA+PiBuOwogICAgaW50IGFbbisxXTsKICAgIGZvcihpbnQgaT0xO2k8PW47aSsrKSB7CiAgICAgICAgY2luID4+IGFbaV07CiAgICAgICAgZltpXVthW2ldXT1mW2ktMV1bYVtpXV0rMTsKICAgIH0KICAgIGZvcihpbnQgaT1uO2k+PTE7aS0tKSB7CiAgICAgICAgZHBbaV1bYVtpXV09ZHBbaSsxXVthW2ldXSsxOwogICAgICAgIG09bWF4KG0sbWluKGZbaS0xXVsxXSxkcFtpXVsyXSkpOwogICAgICAgIG09bWF4KG0sbWluKGZbaS0xXVsyXSxkcFtpXVsxXSkpOwogICAgICAgIG09bWF4KG0sbWluKGZbaV1bMV0sZHBbaSsxXVsyXSkpOwogICAgICAgIG09bWF4KG0sbWluKGZbaV1bMl0sZHBbaSsxXVsxXSkpOwogICAgfQogICAgY291dCA8PCAyKm07CiAgICByZXR1cm47Cn0KaW50IG1haW4oKSB7CiAgICBpb3M6OnN5bmNfd2l0aF9zdGRpbyhmYWxzZSk7CiAgICBjaW4udGllKDApLCBjb3V0LnRpZSgwKTsKICAgIHNvbHZlKCk7CiAgICByZXR1cm4gMDsKfQ==