#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ printf(char *, int, ...);
int /*<<< orphan*/ putchar(char);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int n = 0, count = 0;
  scanf("%d", &n);
  int arr[n];
  while (n--) {
    int next = 0;
    scanf("%d", &next);
    if (count == 0 || arr[count - 1] < next)
      arr[count++] = next;
  }
  printf("%d\n%d", count, arr[0]);
  for (int i = 1; i < count; i++)
    printf(" %d", arr[i]);
  putchar('\n');
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
lea    0xeaf(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1050 <scanf@plt>
mov    -0x8(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x8(%rbp)
cmp    $0x0,%eax
je     11ef <main+0xbf>
movl   $0x0,-0x24(%rbp)
lea    0xe5d(%rip),%rdi
lea    -0x24(%rbp),%rsi
call   1050 <scanf@plt>
cmpl   $0x0,-0xc(%rbp)
je     11d2 <main+0xa2>
mov    -0x30(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%eax
cmp    -0x24(%rbp),%eax
jge    11ea <main+0xba>
mov    -0x30(%rbp),%rax
mov    -0x24(%rbp),%edx
mov    -0xc(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0xc(%rbp)
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
jmp    1184 <main+0x54>
mov    -0x30(%rbp),%rax
mov    -0xc(%rbp),%esi
mov    (%rax),%edx
lea    0xe01(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1240 <main+0x110>
mov    -0x30(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xddb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    120d <main+0xdd>
mov    $0xa,%edi
call   1030 <putchar@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
movl   $0x0,-0x2c(%rbp)
lea    0xeb7(%rip),%rdi
lea    -0x2c(%rbp),%rsi
call   1050 <scanf@plt>
mov    %rsp,%r12
mov    -0x2c(%rbp),%eax
mov    %rsp,%r13
lea    0xf(,%rax,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r13
mov    %r13,%rsp
subl   $0x1,-0x2c(%rbp)
jae    118b <main+0x5b>
lea    0xe83(%rip),%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1218 <main+0xe8>
xor    %ebx,%ebx
lea    0xe6f(%rip),%r14
lea    -0x30(%rbp),%r15
jmp    11b1 <main+0x81>
nopw   0x0(%rax,%rax,1)
mov    -0x30(%rbp),%ecx
lea    0x1(%rax),%ebx
mov    %ecx,0x0(%r13,%rax,4)
subl   $0x1,-0x2c(%rbp)
jb     11d6 <main+0xa6>
movl   $0x0,-0x30(%rbp)
mov    %r14,%rdi
mov    %r15,%rsi
call   1050 <scanf@plt>
movslq %ebx,%rax
test   %ebx,%ebx
je     11a0 <main+0x70>
mov    -0x30(%rbp),%ecx
cmp    %ecx,-0x4(%r13,%rax,4)
jl     11a3 <main+0x73>
jmp    11ab <main+0x7b>
mov    0x0(%r13),%edx
lea    0xe1f(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
cmp    $0x2,%ebx
jl     1218 <main+0xe8>
mov    %ebx,%r15d
mov    $0x1,%ebx
lea    0xe08(%rip),%r14
xchg   %ax,%ax
mov    0x0(%r13,%rbx,4),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1200 <main+0xd0>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %r12,%rsp
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [6 x i8] c"%d\0A%d\00"
@.str.2 = [4 x i8] c" %d\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %2
store i32 0, i32* %3
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%9 = load i32, i32* %2
%10 = zext i32 %9 to i64
%11 = call i8* @llvm.stacksave()
store i8* %11, i8** %4
%12 = alloca i32, i64 %10
store i64 %10, i64* %5
br label %13
13: ; preds = %35, %0
%14 = load i32, i32* %2
%15 = add nsw i32 %14, -1
store i32 %15, i32* %2
%16 = icmp ne i32 %14, 0
br i1 %16, label %17, label %36
17: ; preds = %13
store i32 0, i32* %6
%18 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %6)
%19 = load i32, i32* %3
%20 = icmp eq i32 %19, 0
br i1 %20, label %29, label %21
21: ; preds = %17
%22 = load i32, i32* %3
%23 = sub nsw i32 %22, 1
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i32, i32* %12, i64 %24
%26 = load i32, i32* %25
%27 = load i32, i32* %6
%28 = icmp slt i32 %26, %27
br i1 %28, label %29, label %35
29: ; preds = %21, %17
%30 = load i32, i32* %6
%31 = load i32, i32* %3
%32 = add nsw i32 %31, 1
store i32 %32, i32* %3
%33 = sext i32 %31 to i64
%34 = getelementptr inbounds i32, i32* %12, i64 %33
store i32 %30, i32* %34
br label %35
35: ; preds = %29, %21
br label %13
36: ; preds = %13
%37 = load i32, i32* %3
%38 = getelementptr inbounds i32, i32* %12, i64 0
%39 = load i32, i32* %38
%40 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %37, i32 %39)
store i32 1, i32* %7
br label %41
41: ; preds = %51, %36
%42 = load i32, i32* %7
%43 = load i32, i32* %3
%44 = icmp slt i32 %42, %43
br i1 %44, label %45, label %54
45: ; preds = %41
%46 = load i32, i32* %7
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i32, i32* %12, i64 %47
%49 = load i32, i32* %48
%50 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %49)
br label %51
51: ; preds = %45
%52 = load i32, i32* %7
%53 = add nsw i32 %52, 1
store i32 %53, i32* %7
br label %41
54: ; preds = %41
%55 = call i32 @putchar(i8 signext 10)
store i32 0, i32* %1
%56 = load i8*, i8** %4
%57 = load i32, i32* %1
ret i32 %57
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [6 x i8] c"%d\0A%d\00"
@.str.2 = [4 x i8] c" %d\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
store i32 0, i32* %1
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%5 = load i32, i32* %1
%6 = zext i32 %5 to i64
%7 = call i8* @llvm.stacksave()
%8 = alloca i32, i64 %6
%9 = load i32, i32* %1
%10 = add nsw i32 %9, -1
store i32 %10, i32* %1
%11 = icmp eq i32 %9, 0
br i1 %11, label %12, label %14
12: ; preds = %0
%13 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 0, i32 undef)
br label %45
14: ; preds = %0
%15 = bitcast i32* %2 to i8*
br label %16
16: ; preds = %14, %34
%17 = phi i32 [ 0, %14 ], [ %35, %34 ]
store i32 0, i32* %2
%18 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%19 = icmp eq i32 %17, 0
br i1 %19, label %20, label %22
20: ; preds = %16
%21 = load i32, i32* %2
br label %29
22: ; preds = %16
%23 = add nsw i32 %17, -1
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i32, i32* %8, i64 %24
%26 = load i32, i32* %25
%27 = load i32, i32* %2
%28 = icmp slt i32 %26, %27
br i1 %28, label %29, label %34
29: ; preds = %20, %22
%30 = phi i32 [ %21, %20 ], [ %27, %22 ]
%31 = add nsw i32 %17, 1
%32 = sext i32 %17 to i64
%33 = getelementptr inbounds i32, i32* %8, i64 %32
store i32 %30, i32* %33
br label %34
34: ; preds = %29, %22
%35 = phi i32 [ %31, %29 ], [ %17, %22 ]
%36 = load i32, i32* %1
%37 = add nsw i32 %36, -1
store i32 %37, i32* %1
%38 = icmp eq i32 %36, 0
br i1 %38, label %39, label %16
39: ; preds = %34
%40 = load i32, i32* %8
%41 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %35, i32 %40)
%42 = icmp sgt i32 %35, 1
br i1 %42, label %43, label %45
43: ; preds = %39
%44 = zext i32 %35 to i64
br label %47
45: ; preds = %47, %12, %39
%46 = call i32 @putchar(i8 signext 10)
ret i32 0
47: ; preds = %43, %47
%48 = phi i64 [ 1, %43 ], [ %52, %47 ]
%49 = getelementptr inbounds i32, i32* %8, i64 %48
%50 = load i32, i32* %49
%51 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %50)
%52 = add nuw nsw i64 %48, 1
%53 = icmp eq i64 %52, %44
br i1 %53, label %45, label %47
}