// header {{{
#include <bits/stdc++.h>
using namespace std;

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define INF         INT_MAX/3
#define LLINF       LLONG_MAX/3
#define MOD         (1000000007LL)
#define MODA(a, b)  a=((a)+(b))%MOD
#define MODP(a, b)  a=((a)*(b))%MOD
#define inc(i, l, r)   for(int i=(l);i<(r);i++)
#define dec(i, l, r)   for(int i=(r)-1;i>=(l);i--)
#define pb          push_back
#define se          second
#define fi          first
#define mset(a, b)  memset(a, b, sizeof(a))

using LL  = long long;
using G   = vector<vector<int>>;

int di[] = {0, -1, 0, 1};
int dj[] = {1, 0, -1, 0};
// }}}

int main() {
    cin.tie(0);ios::sync_with_stdio(false);
    int n;cin >> n;
    vector<int> a(n);
    for(int i=0;i<n;i++) cin >> a[i];

    map<int, queue<int>> mp;
    for(int i=0;i<n;i++){
        mp[a[i]].push(i);
    }

    vector<bool> ok(n, false);
    vector<int> ans;
    int ptr = 0;
    for(int i=n-1;i>=0;i--){
        int p = mp[a[i]].front();
        mp[a[i]].pop();

        ok[p] = true;
        if(ok[ptr]){
            for(int j=ptr+1;j<n;j++){
                if(ok[j] == false){
                    ptr = j;
                    break;
                }
            }
            if(ok[ptr]){
                ptr = n;
            }
        }

        if(ptr == n-i){
            ans.push_back(ptr);
        }
    }


    // out
    sort(ans.begin(), ans.end());
    int m = ans.size();
    for(int i=0;i<m;i++){
        cout << ans[i];
        if(i != m-1){
            cout << " ";
        }
    }
    cout << endl;

    return 0;
}


### Prompt

Please formulate a Cpp solution to the following problem:

problem

Given a sequence $ a_i $ of length $ N $. Output all integers $ K (1 \ le K \ le N) $ that satisfy the following conditions.

Condition: Well sorted $ a_1, \ cdots, a_K $ matches $ a_ {N-K + 1}, \ cdots, a_N $.





Example

Input

8
5 2 4 9 4 9 2 5


Output

1 2 4 6 7 8

### Response

```cpp
// header {{{
#include <bits/stdc++.h>
using namespace std;

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define INF         INT_MAX/3
#define LLINF       LLONG_MAX/3
#define MOD         (1000000007LL)
#define MODA(a, b)  a=((a)+(b))%MOD
#define MODP(a, b)  a=((a)*(b))%MOD
#define inc(i, l, r)   for(int i=(l);i<(r);i++)
#define dec(i, l, r)   for(int i=(r)-1;i>=(l);i--)
#define pb          push_back
#define se          second
#define fi          first
#define mset(a, b)  memset(a, b, sizeof(a))

using LL  = long long;
using G   = vector<vector<int>>;

int di[] = {0, -1, 0, 1};
int dj[] = {1, 0, -1, 0};
// }}}

int main() {
    cin.tie(0);ios::sync_with_stdio(false);
    int n;cin >> n;
    vector<int> a(n);
    for(int i=0;i<n;i++) cin >> a[i];

    map<int, queue<int>> mp;
    for(int i=0;i<n;i++){
        mp[a[i]].push(i);
    }

    vector<bool> ok(n, false);
    vector<int> ans;
    int ptr = 0;
    for(int i=n-1;i>=0;i--){
        int p = mp[a[i]].front();
        mp[a[i]].pop();

        ok[p] = true;
        if(ok[ptr]){
            for(int j=ptr+1;j<n;j++){
                if(ok[j] == false){
                    ptr = j;
                    break;
                }
            }
            if(ok[ptr]){
                ptr = n;
            }
        }

        if(ptr == n-i){
            ans.push_back(ptr);
        }
    }


    // out
    sort(ans.begin(), ans.end());
    int m = ans.size();
    for(int i=0;i<m;i++){
        cout << ans[i];
        if(i != m-1){
            cout << " ";
        }
    }
    cout << endl;

    return 0;
}


```