# Arup Guha
# 12/15/2024
# Solution to Kattis Problem Greedily Increasing Sequence
# https://open.kattis.com/problems/greedilyincreasing

# Get input.
n = int(input())
vals = [int(x) for x in input().split()]

# Store result here.
res = []

# This is always first.
res.append(vals[0])

# Loop through rest.
for i in range(1, n):

    # Add if biggest so far.
    if vals[i] > res[-1]:
        res.append(vals[i])

# Ta da!
print(len(res))
for x in res:
    print(x, end=" ")
print()

