#include #include #include #include #include #include #include #include #include #include #include #include #define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl; #define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl; template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } using namespace std; typedef long long ll; template void print_vector(vector v, char delimiter=' '){ if(v.empty()) { cout << endl; return; } for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter; cout << v.back() << endl; } vector as_base3(int x, int n){ vector ans; for(int i = 0; i < n; i++){ ans.push_back(x%3); x /= 3; } return ans; } int f(int a, int b, int c){ if(a == b || b == c || c == a) return 0; int r = (3+b-a)%3; return r; } int calc(vector v){ if(v.size() == 1) return v[0]; int n = v.size(); vector u; for(int i = 1; i < n-1; i++){ u.push_back(f(v[i-1], v[i], v[i+1])); } return calc(u); } int solve(vector a){ int n = a.size()/2; vector b(2*n); for(int i = 0; i < 2*n; i++) b[i] = (a[i+1]-a[i]+3)%3; for(int i = 0; i < 2*n; i++){ if(b[i] == 0) return 0; } vector c; for(int i = 0; i < n; i++){ if(i%2 == 0) { c.push_back(b[0]); c.push_back(b[0]); }else{ c.push_back(3-b[0]); c.push_back(3-b[0]); } } if(b != c) return 0; if(n%4 == 1){ return b[0]; }else{ return 3-b[0]; } } void test(int n){ int mx = 1; for(int i = 0; i < n; i++) mx *= 3; for(int x = 0; x < mx; x++) { auto v = as_base3(x, n); if(calc(v) != 0) { cout << calc(v) << ' ' << solve(v) << endl; }else{ assert(solve(v) == 0); } } } int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fixed; int n; cin >> n; // test(n); vector a(2*n+1); for(int i = 0; i < 2*n+1; i++) cin >> a[i]; if(n == 1) { cout << calc(a) << endl; }else{ cout << solve(a) << endl; } }