#include using namespace std; #define int long long templatebool chmax(T &a, const T &b) { if (abool chmin(T &a, const T &b) { if (b> n; vector a(n); deque b; b.push_front(0); for(int i = 0;i < n;i++){ cin >> a[i]; if(b.back() != a[i]){ b.push_back(a[i]); } } b.pop_front(); auto f = [](deque &q){ set st; for(int i = 0;i < q.size();i++){ if(st.find(q[i]) != st.end()){ return false; } st.insert(q[i]); } return true; }; if(f(b)){ cout << 0 << endl; }else{ int x = b.back(); b.pop_back(); if(b.front() != x){ b.push_front(x); } if(f(b)){ cout << 1 << endl; }else{ cout << -1 << endl; } } return 0; }