#include <bits/stdc++.h>

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    int n, pr = -1, cnt = 0;
    cin >> n;
    vector<int> v;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        if (i == 0) pr = x;
        if (pr == x) cnt++;
        else v.push_back(cnt), cnt = 1, pr = x;
    }
    v.push_back(cnt);
    int ans = 0;
    for (int i = 1; i < v.size(); i++)
        ans = max(ans, min(v[i - 1], v[i]) * 2);
    cout << ans;
    return 0;
}