#include //using namespace std; #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #define rep(i, j, n) for(int i = int(j); i < int(n); i++) #define REP(i, j, n) for(int i = int(j); i <= int(n); i++) #define per(i, j, n) for(int i = int(j); int(n) <= i; i--) #define ALL(a) (a).begin(),(a).end() #define revALL(a) (a).rbegin(),(a).rend() #define pb push_back #define mp std::make_pair #define mtp std::make_tuple #define ln "\n" using std::endl; using std::cin; using std::cout; #define ll long long using std::vector; using std::string; using std::upper_bound; using std::lower_bound; const ll MOD = int(1e9+7); const ll MAX = 1e6+10; const ll inf = (1ll << 60); //modpow ll modpow(ll X, ll Y, ll mod){ ll ret = 1; while(Y){ if(Y & 1){ ret *= X; ret %= mod; } X *= X; X %= mod; Y >>= 1; } return ret % mod; } //binary_indexed_tree template struct binary_indexed_tree{ int N; vector bit; binary_indexed_tree(int n):N(n){ bit.resize(N+1,0); } T addition(T a, T b){ return a+b; } void add(int x,T a){ x++; for(; x<=N; x+=(x&-x)) bit[x] = addition(bit[x], a); } T sum(int x){ x++; T ret=0; for(; x>0; x-=(x&-x)) ret = addition(ret, bit[x]); return ret; } ll lower_bound(T X){ if(sum(N-1)> N; vector P(N); rep(i,0,N) cin >> P[i]; vector> lis(2); rep(t,0,2){ vector dp(N+1,inf); dp[0] = 0; vector rev(N); rep(i,0,N){ ll idx = lower_bound(ALL(dp),P[i])-dp.begin(); rev[i] = dp[idx-1]; dp[idx] = P[i]; } ll now = dp[lower_bound(ALL(dp),inf)-dp.begin()-1]; per(i,N-1,0){ if(P[i] == now){ lis[t].pb(now); now = rev[i]; } } rep(i,0,N) P[i] = N+1-P[i]; reverse(ALL(P)); } reverse(ALL(lis[0])); vector ans; rep(i,0,lis[0].size()){ if(lis[0][i]+lis[1][i] == N+1) ans.push_back(lis[0][i]); } cout << ans.size() << ln; rep(i,0,ans.size()) cout << ans[i] << " "; cout << ln; }