#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(auto e : q){ if(st.find(e) != st.end()){ return false; } st.insert(e); } return true; }; if(f(b)){ cout << 0 << endl; }else{ int x = b.back(); b.pop_back(); if(b.front() != x){ b.push_front(x); } cout << (f(b) ? 1 : -1) << endl; } return 0; }