#include using i64 = long long; using l64 = long double; void DAOQI() { int n; std::cin >> n; std::vector a(n + 1); for (int i = 1; i <= n; i++) { std::cin >> a[i]; } std::vector pre(n + 1), suf(n + 1), cnt(n + 1); auto calc = [&](std::vector &vec) { std::vector dp; for (int i = 1; i <= n; i++) { if (dp.empty() || a[i] > dp.back()) { dp.push_back(a[i]); vec[i] = dp.size(); } else { int p = std::lower_bound(dp.begin(), dp.end(), a[i]) - dp.begin(); vec[i] = p + 1; dp[p] = a[i]; } } return dp.size(); }; int len = calc(pre); std::reverse(a.begin() + 1, a.end()); for (int i = 1; i <= n; i++) a[i] = -a[i]; calc(suf); std::reverse(suf.begin() + 1, suf.end()); std::reverse(a.begin() + 1, a.end()); std::vector ans; for (int i = 1; i <= n; i++) { a[i] = -a[i]; if (pre[i] + suf[i] - 1 == len) { cnt[pre[i]]++; } } for (int i = 1; i <= n; i++) { if (pre[i] + suf[i] - 1 == len && cnt[pre[i]] == 1) { ans.push_back(a[i]); } } std::cout << ans.size() << "\n"; for (int x: ans) std::cout << x << " \n"[x == ans.back()]; } signed main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); int T = 1; //std::cin >> T; while (T--) DAOQI(); return 0; }