#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 */
scalar_t__ calloc(int, int);
int /*<<< orphan*/ free(int *);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int n, x, c = 0, *hs = (short *)calloc(1000000, sizeof(int));
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &x);
    if (hs[x])
      hs[x]--;
    else
      c++;
    hs[x - 1]++;
  }
  printf("%d\n", c);
  free(hs);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x10(%rbp)
mov    $0xf4240,%edi
mov    $0x4,%esi
call   1050 <calloc@plt>
mov    %rax,-0x18(%rbp)
lea    0xe90(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1060 <scanf@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11f1 <main+0xb1>
lea    0xe6d(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1060 <scanf@plt>
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
cmpl   $0x0,(%rax,%rcx,4)
je     11c4 <main+0x84>
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
add    $0xffffffff,%edx
mov    %edx,(%rax,%rcx,4)
jmp    11cd <main+0x8d>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%edx
add    $0x1,%edx
mov    %edx,(%rax,%rcx,4)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1180 <main+0x40>
mov    -0x10(%rbp),%esi
lea    0xe08(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    $0xf4240,%edi
mov    $0x4,%esi
call   1050 <calloc@plt>
mov    %rax,%rbx
lea    0xe9b(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1060 <scanf@plt>
cmpl   $0x0,0xc(%rsp)
jle    11c9 <main+0x89>
xor    %ebp,%ebp
lea    0xe81(%rip),%r14
lea    0x8(%rsp),%r15
xor    %r12d,%r12d
jmp    11a4 <main+0x64>
nopl   0x0(%rax)
add    $0x1,%r12d
cltq
addl   $0x1,-0x4(%rbx,%rax,4)
add    $0x1,%ebp
cmp    0xc(%rsp),%ebp
jge    11cc <main+0x8c>
mov    %r14,%rdi
mov    %r15,%rsi
call   1060 <scanf@plt>
mov    0x8(%rsp),%eax
movslq %eax,%rcx
mov    (%rbx,%rcx,4),%edx
test   %edx,%edx
je     1190 <main+0x50>
add    $0xffffffff,%edx
mov    %edx,(%rbx,%rcx,4)
mov    0x8(%rsp),%eax
jmp    1194 <main+0x54>
xor    %r12d,%r12d
lea    0xe30(%rip),%rdi
mov    %r12d,%esi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = tail call i64 @calloc(i32 1000000, i32 4)
%6 = inttoptr i64 %5 to i32*
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%8 = load i32, i32* %1
%9 = icmp sgt i32 %8, 0
br i1 %9, label %14, label %10
10: ; preds = %28, %0
%11 = phi i32 [ 0, %0 ], [ %30, %28 ]
%12 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %11)
%13 = call i32 @free(i32* %6)
ret i32 0
14: ; preds = %0, %28
%15 = phi i32 [ %36, %28 ], [ 0, %0 ]
%16 = phi i32 [ %30, %28 ], [ 0, %0 ]
%17 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%18 = load i32, i32* %2
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i32, i32* %6, i64 %19
%21 = load i32, i32* %20
%22 = icmp eq i32 %21, 0
br i1 %22, label %26, label %23
23: ; preds = %14
%24 = add nsw i32 %21, -1
store i32 %24, i32* %20
%25 = load i32, i32* %2
br label %28
26: ; preds = %14
%27 = add nsw i32 %16, 1
br label %28
28: ; preds = %26, %23
%29 = phi i32 [ %25, %23 ], [ %18, %26 ]
%30 = phi i32 [ %16, %23 ], [ %27, %26 ]
%31 = add nsw i32 %29, -1
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i32, i32* %6, i64 %32
%34 = load i32, i32* %33
%35 = add nsw i32 %34, 1
store i32 %35, i32* %33
%36 = add nuw nsw i32 %15, 1
%37 = load i32, i32* %1
%38 = icmp slt i32 %36, %37
br i1 %38, label %14, label %10
}