#include using namespace std; #define REP(i, s) for (int i = 0; i < s; ++i) #define ALL(v) (v).begin(), (v).end() #define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl #define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i) #define DEBUG #define int long long #define INF 1e18 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; } template ostream& operator << (ostream &s, pair P) { return s << '<' << P.first << ", " << P.second << '>'; } template ostream& operator << (ostream &s, vector P) { for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; } template ostream& operator << (ostream &s, vector > P) { for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; } template ostream& operator << (ostream &s, set P) { EACH(it, P) { s << "<" << *it << "> "; } return s << endl; } template ostream& operator << (ostream &s, map P) { EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; } templatevoid show(vectorv){for (int i = 0; i < v.size(); i++){cerr<> n; vector a(n); REP(i,n){ cin >> a[i]; } map mp; vector b; b.push_back(a[0]); for (int i = 1; i < n; i++) { if(a[i] !=a[i-1]){ b.push_back(a[i]); } } //show(b); bool flag = true; int idx = 0; //cerr << b.size() << endl; for (int i = 0; i < b.size(); i++) { //cerr << mp[b[i]]; if (mp[b[i]] > 0) { flag = false; idx = i; break; } mp[b[i]]++; } if(flag){ cout << 0 << endl; } else{ // cerr << idx << endl; for (int i = idx; i < b.size(); i++) { if(b[i] !=b[0]){ cout << -1 << endl; return 0; } } cout << 1 << endl; } return 0; }