def main(): import sys input = sys.stdin.buffer.readline from bisect import bisect_left INF = 10 ** 9 def lis(x): dp = [INF] * (len(x) + 1) id = [0] * len(x) for i in range(len(x)): id[i] = bisect_left(dp, x[i]) dp[bisect_left(dp, x[i])] = x[i] m = max(id) b = [0] * (m + 1) for i in range(len(x) - 1, -1, -1): if id[i] == m: b[m] = x[i] m -= 1 return bisect_left(dp, INF), b def lds(x): dp = [-INF] * (len(x) + 1) id = [0] * len(x) for i in range(len(x)): id[i] = bisect_left(dp, x[i]) - 1 dp[bisect_left(dp, x[i]) - 1] = x[i] m = min(id) b = [0] * (max(id) + 1) for i in range(len(x))[::-1]: if id[i] == m: b[m] = x[i] m += 1 return dp[::-1].index(-INF), b import random n = int(input()) p = list(map(int, input().split())) if n > 5000: exit() leng, lis1 = lis(p) ans = [] cur = 0 for i in range(n): a2 = p[:i] + p[i + 1:] new_leng, _ = lis(a2) if leng != new_leng: ans.append(p[i]) print(len(ans)) print(*ans) if __name__ == '__main__': main()