Note:even the number is 0 we also have to cout<<endl in line2.(Or it can’t ac)(puzzling)
#include <iostream>
#include <stdio.h>
#include<stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <unordered_map>
#include <set>
using namespace std;
const int MAXN = 110000;
int s1[MAXN];
int s2[MAXN];
set<int> ans;
int N;
int main() {
cin >> N;
for (int i = 0; i < N; i++) {
scanf("%d",s1+i);
s2[i]=s1[i];
}
sort(s2, s2 + N);
int max=-1;
for (int i = 0; i <N; i++)
{
if (s2[i] == s1[i]&&s1[i]>max) ans.insert(s2[i]);
if(s1[i]>max) max=s1[i];
}
cout << ans.size() << endl;
bool first = true;
for (auto &a : ans)
{
if (first) { cout << a; first = false; }
else cout <<" "<< a;
}
//if(ans.size()!=0)
cout << endl;
return 0;
}