#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 */
double CLOCKS_PER_SEC;
scalar_t__ clock();
int /*<<< orphan*/ printf(char *, double);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  const int MOD = 1000000;
  int i, j, n, S = 0;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    int factorial = 1;
    for (j = 1; j <= i; j++) {
      factorial = (factorial * j % MOD);
    }
    S = (S + factorial) % MOD;
  }
  printf("%d\n", S);
  printf("Time used = %.2lf\n", (double)clock() / CLOCKS_PER_SEC);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0xf4240,-0x8(%rbp)
movl   $0x0,-0x18(%rbp)
lea    0xeac(%rip),%rdi
lea    -0x14(%rbp),%rsi
call   1050 <scanf@plt>
movl   $0x1,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x14(%rbp),%eax
jg     11c9 <main+0x99>
movl   $0x1,-0x1c(%rbp)
movl   $0x1,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jg     11aa <main+0x7a>
mov    -0x1c(%rbp),%eax
imul   -0x10(%rbp),%eax
mov    $0xf4240,%ecx
cltd
idiv   %ecx
mov    %edx,-0x1c(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    117e <main+0x4e>
mov    -0x18(%rbp),%eax
add    -0x1c(%rbp),%eax
mov    $0xf4240,%ecx
cltd
idiv   %ecx
mov    %edx,-0x18(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1164 <main+0x34>
cvtsi2sdl -0x18(%rbp),%xmm0
lea    0xe2e(%rip),%rdi
call   1040 <printf@plt>
mov    $0x0,%al
call   1030 <clock@plt>
cvtsi2sd %rax,%xmm0
mov    0x2dfb(%rip),%rax
divsd  (%rax),%xmm0
lea    0xe0f(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0xec4(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1050 <scanf@plt>
mov    0xc(%rsp),%r8d
test   %r8d,%r8d
jle    12d5 <main+0x1a5>
add    $0x1,%r8d
mov    $0x2,%r10d
xor    %r9d,%r9d
mov    $0x1,%r11d
xor    %edi,%edi
jmp    11a5 <main+0x75>
nopl   0x0(%rax,%rax,1)
add    %edi,%esi
movslq %esi,%rdi
imul   $0x431bde83,%rdi,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x32,%rax
add    %ecx,%eax
imul   $0xf4240,%eax,%eax
sub    %eax,%edi
lea    0x1(%r10),%eax
add    $0x1,%r11d
cmp    %r8d,%r10d
mov    %eax,%r10d
je     12cf <main+0x19f>
mov    %r9d,%edx
lea    0x1(%rdx),%r9d
mov    $0x1,%esi
mov    $0x1,%eax
cmp    $0x3,%edx
jb     1287 <main+0x157>
mov    %r11d,%edx
and    $0xfffffffc,%edx
neg    %edx
mov    $0x1,%esi
mov    $0x2,%eax
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    -0x1(%rax),%ecx
imul   %esi,%ecx
movslq %ecx,%rcx
imul   $0x431bde83,%rcx,%rsi
mov    %rsi,%rbx
shr    $0x3f,%rbx
sar    $0x32,%rsi
add    %ebx,%esi
imul   $0xf4240,%esi,%esi
sub    %esi,%ecx
imul   %eax,%ecx
movslq %ecx,%rcx
imul   $0x431bde83,%rcx,%rsi
mov    %rsi,%rbx
shr    $0x3f,%rbx
sar    $0x32,%rsi
add    %ebx,%esi
imul   $0xf4240,%esi,%esi
sub    %esi,%ecx
lea    0x1(%rax),%esi
imul   %ecx,%esi
movslq %esi,%rcx
imul   $0x431bde83,%rcx,%rsi
mov    %rsi,%rbx
shr    $0x3f,%rbx
sar    $0x32,%rsi
add    %ebx,%esi
imul   $0xf4240,%esi,%esi
sub    %esi,%ecx
lea    0x2(%rax),%esi
imul   %ecx,%esi
movslq %esi,%rsi
imul   $0x431bde83,%rsi,%rcx
mov    %rcx,%rbx
shr    $0x3f,%rbx
sar    $0x32,%rcx
add    %ebx,%ecx
imul   $0xf4240,%ecx,%ecx
sub    %ecx,%esi
mov    %eax,%ecx
add    $0x4,%eax
add    %edx,%ecx
add    $0x4,%ecx
cmp    $0x2,%ecx
jne    11e0 <main+0xb0>
add    $0xffffffff,%eax
test   $0x3,%r9b
je     1170 <main+0x40>
mov    %r11d,%edx
and    $0x3,%edx
nopw   0x0(%rax,%rax,1)
imul   %eax,%esi
movslq %esi,%rsi
imul   $0x431bde83,%rsi,%rcx
mov    %rcx,%rbx
shr    $0x3f,%rbx
sar    $0x32,%rcx
add    %ebx,%ecx
imul   $0xf4240,%ecx,%ecx
sub    %ecx,%esi
add    $0x1,%eax
add    $0xffffffff,%edx
jne    12a0 <main+0x170>
jmp    1170 <main+0x40>
cvtsi2sd %edi,%xmm0
jmp    12d9 <main+0x1a9>
xorpd  %xmm0,%xmm0
lea    0xd23(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
call   1030 <clock@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
mov    0x2ced(%rip),%rax
divsd  (%rax),%xmm0
lea    0xd01(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [4 x i8] c"%d\0A\00"
@.str.2 = [19 x i8] c"Time used = %.2lf\0A\00"
@CLOCKS_PER_SEC = global double 0.000000e+00
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
store i32 1000000, i32* %2
store i32 0, i32* %6
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %5)
store i32 1, i32* %3
br label %9
9: ; preds = %31, %0
%10 = load i32, i32* %3
%11 = load i32, i32* %5
%12 = icmp sle i32 %10, %11
br i1 %12, label %13, label %34
13: ; preds = %9
store i32 1, i32* %7
store i32 1, i32* %4
br label %14
14: ; preds = %23, %13
%15 = load i32, i32* %4
%16 = load i32, i32* %3
%17 = icmp sle i32 %15, %16
br i1 %17, label %18, label %26
18: ; preds = %14
%19 = load i32, i32* %7
%20 = load i32, i32* %4
%21 = mul nsw i32 %19, %20
%22 = srem i32 %21, 1000000
store i32 %22, i32* %7
br label %23
23: ; preds = %18
%24 = load i32, i32* %4
%25 = add nsw i32 %24, 1
store i32 %25, i32* %4
br label %14
26: ; preds = %14
%27 = load i32, i32* %6
%28 = load i32, i32* %7
%29 = add nsw i32 %27, %28
%30 = srem i32 %29, 1000000
store i32 %30, i32* %6
br label %31
31: ; preds = %26
%32 = load i32, i32* %3
%33 = add nsw i32 %32, 1
store i32 %33, i32* %3
br label %9
34: ; preds = %9
%35 = load i32, i32* %6
%36 = sitofp i32 %35 to double
%37 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double %36)
%38 = call i64 (...) @clock()
%39 = sitofp i64 %38 to double
%40 = load double, double* @CLOCKS_PER_SEC
%41 = fdiv double %39, %40
%42 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), double %41)
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [4 x i8] c"%d\0A\00"
@.str.2 = [19 x i8] c"Time used = %.2lf\0A\00"
@CLOCKS_PER_SEC = global double 0.000000e+00
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%4 = load i32, i32* %1
%5 = icmp slt i32 %4, 1
br i1 %5, label %58, label %6
6: ; preds = %0
%7 = add i32 %4, 1
br label %8
8: ; preds = %6, %49
%9 = phi i32 [ 0, %6 ], [ %55, %49 ]
%10 = phi i32 [ 2, %6 ], [ %53, %49 ]
%11 = phi i32 [ 0, %6 ], [ %52, %49 ]
%12 = add i32 %9, 1
%13 = and i32 %12, 3
%14 = icmp ult i32 %9, 3
br i1 %14, label %35, label %15
15: ; preds = %8
%16 = and i32 %12, -4
br label %17
17: ; preds = %17, %15
%18 = phi i32 [ 1, %15 ], [ %31, %17 ]
%19 = phi i32 [ 1, %15 ], [ %32, %17 ]
%20 = phi i32 [ 0, %15 ], [ %33, %17 ]
%21 = mul nsw i32 %18, %19
%22 = srem i32 %21, 1000000
%23 = add nuw nsw i32 %19, 1
%24 = mul nsw i32 %22, %23
%25 = srem i32 %24, 1000000
%26 = add nuw nsw i32 %19, 2
%27 = mul nsw i32 %25, %26
%28 = srem i32 %27, 1000000
%29 = add nuw i32 %19, 3
%30 = mul nsw i32 %28, %29
%31 = srem i32 %30, 1000000
%32 = add nuw i32 %19, 4
%33 = add i32 %20, 4
%34 = icmp eq i32 %33, %16
br i1 %34, label %35, label %17
35: ; preds = %17, %8
%36 = phi i32 [ undef, %8 ], [ %31, %17 ]
%37 = phi i32 [ 1, %8 ], [ %31, %17 ]
%38 = phi i32 [ 1, %8 ], [ %32, %17 ]
%39 = icmp eq i32 %13, 0
br i1 %39, label %49, label %40
40: ; preds = %35, %40
%41 = phi i32 [ %45, %40 ], [ %37, %35 ]
%42 = phi i32 [ %46, %40 ], [ %38, %35 ]
%43 = phi i32 [ %47, %40 ], [ 0, %35 ]
%44 = mul nsw i32 %41, %42
%45 = srem i32 %44, 1000000
%46 = add nuw i32 %42, 1
%47 = add i32 %43, 1
%48 = icmp eq i32 %47, %13
br i1 %48, label %49, label %40
49: ; preds = %40, %35
%50 = phi i32 [ %36, %35 ], [ %45, %40 ]
%51 = add nsw i32 %50, %11
%52 = srem i32 %51, 1000000
%53 = add nuw i32 %10, 1
%54 = icmp eq i32 %10, %7
%55 = add i32 %9, 1
br i1 %54, label %56, label %8
56: ; preds = %49
%57 = sitofp i32 %52 to double
br label %58
58: ; preds = %56, %0
%59 = phi double [ 0.000000e+00, %0 ], [ %57, %56 ]
%60 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), double %59)
%61 = call i64 (...) @clock()
%62 = sitofp i64 %61 to double
%63 = load double, double* @CLOCKS_PER_SEC
%64 = fdiv double %62, %63
%65 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), double %64)
ret i32 0
}