#include using namespace std; int main(){ int N; cin >> N; vector A(N * 2 + 1); for (int i = 0; i <= N * 2; i++){ cin >> A[i]; } bool ok = false; for (int i = 0; i <= N * 2 - 1; i++){ if (A[i] == A[i + 1]){ ok = true; } } for (int i = 0; i <= N * 2 - 3; i++){ int x = (A[i + 1] - A[i] + 3) % 3; int y = (A[i + 2] - A[i + 1] + 3) % 3; int z = (A[i + 3] - A[i + 2] + 3) % 3; if (x == y && y == z){ ok = true; } } if (ok){ cout << 0 << endl; } else { for (int i = 0; i < 3; i++){ vector B(N * 2 + 1); for (int j = 0; j <= N * 2; j++){ B[j] = (A[j] + i) % 3; } bool ok2 = true; for (int j = 0; j <= N * 2; j++){ if (abs(B[j + 1] - B[j]) >= 2){ ok2 = false; } } if (ok2){ swap(A, B); break; } } if (A[0] == 1){ cout << 0 << endl; } else if (A[0] == 0){ if (N % 2 == 1){ cout << 1 << endl; } else { cout << 2 << endl; } } else { if (N % 2 == 0){ cout << 1 << endl; } else { cout << 2 << endl; } } } }