#include using namespace std; using ll = long long; template using Pa = pair; template using vec = vector; template using vvec = vector>; int main(){ cin.tie(0); ios::sync_with_stdio(false); int N; cin >> N; vec A(2*N); vec> s(N); for(int i=0;i> A[i]; A[i]--; s[A[i]].insert(i); A[i+N] = A[i]; } auto check = [&](int a){ if(s[a].empty()) return true; int l = *s[a].begin(),r = *s[a].rbegin(); return r-l+1==s[a].size(); }; int cnt = 0; vec B(N); for(int i=0;i