#include <iostream>
#include <cmath>
using namespace std;
int main() {
// declaration
int n,cnt=0,Current_type,lastTotal=0,current_consecutive=0,most_consecutive=0;
cin >> n; n -=1;
int ti;
cin >> ti;
Current_type = ti;
for (int i=1; i<=n ;i++) {
if (ti==Current_type) {
cnt++;
}
else {
lastTotal = cnt;
cnt=1;
Current_type=ti;
}
current_consecutive = min(cnt,lastTotal);
most_consecutive = max(most_consecutive,current_consecutive);
cin >> ti;
}
if (most_consecutive == 0) {
cout << 2 << endl;
}
else cout << most_consecutive *2<<endl;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8Y21hdGg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CmludCBtYWluKCkgewogICAgLy8gZGVjbGFyYXRpb24KICAgIGludCBuLGNudD0wLEN1cnJlbnRfdHlwZSxsYXN0VG90YWw9MCxjdXJyZW50X2NvbnNlY3V0aXZlPTAsbW9zdF9jb25zZWN1dGl2ZT0wOwogICAgY2luID4+IG47IG4gLT0xOwogICAgaW50IHRpOwogICAgY2luID4+IHRpOwogICAgQ3VycmVudF90eXBlID0gdGk7CiAgICBmb3IgKGludCBpPTE7IGk8PW4gO2krKykgewogICAgICAgIGlmICh0aT09Q3VycmVudF90eXBlKSB7CiAgICAgICAgICAgIGNudCsrOwogICAgICAgIH0KICAgICAgICBlbHNlIHsKICAgICAgICAgICAgbGFzdFRvdGFsID0gY250OwogICAgICAgICAgICBjbnQ9MTsKICAgICAgICAgICAgQ3VycmVudF90eXBlPXRpOwogICAgICAgIH0KICAgICAgICBjdXJyZW50X2NvbnNlY3V0aXZlID0gbWluKGNudCxsYXN0VG90YWwpOwogCiAgICAgICAgbW9zdF9jb25zZWN1dGl2ZSA9IG1heChtb3N0X2NvbnNlY3V0aXZlLGN1cnJlbnRfY29uc2VjdXRpdmUpOwogICAgICAgIGNpbiA+PiB0aTsKICAgIH0KICAgIGlmIChtb3N0X2NvbnNlY3V0aXZlID09IDApIHsKICAgICAgICBjb3V0IDw8IDIgPDwgZW5kbDsKICAgIH0KICAgIGVsc2UgY291dCA8PCBtb3N0X2NvbnNlY3V0aXZlICoyPDxlbmRsOwogICAgcmV0dXJuIDA7Cn0=