#include <bits/stdc++.h>   using namespace std;   long long n, t, twoc, onec, opt, old;   int main() {     cin >> n;     cin >> t;     if (t == 1)       onec++;     else       twoc++;     old = t;     for (int i = 1; i < n; i++) {       cin >> t;       if (t == 1) {         if (old == 2)           onec = 1;         else           onec++;       } else {         if (old == 1)           twoc = 1;         else           twoc++;       }       opt = max(opt, min(onec, twoc));       old = t;     }     cout << opt * 2;     return 0;   }   