#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*/ scanf(char *, int *);
int main(int argc, char *argv[]) {
  int a[10001] = {0, 3, 7, 17}, i = 4, n, m;
  scanf("%lli", &n);
  m = n;
  while (n-- > 3) {
    a[i] = a[i - 2] + (a[i - 1] << 1);
    a[i++] %= 12345;
  }
  printf("%lli", a[m]);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x9c80,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x9c60(%rbp),%rdi
xor    %esi,%esi
mov    $0x9c44,%edx
call   1040 <memset@plt>
movl   $0x3,-0x9c5c(%rbp)
movl   $0x7,-0x9c58(%rbp)
movl   $0x11,-0x9c54(%rbp)
movl   $0x4,-0x9c64(%rbp)
lea    0xe75(%rip),%rdi
lea    -0x9c68(%rbp),%rsi
call   1050 <scanf@plt>
mov    -0x9c68(%rbp),%eax
mov    %eax,-0x9c6c(%rbp)
mov    -0x9c68(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x9c68(%rbp)
cmp    $0x3,%eax
jle    1230 <main+0x100>
mov    -0x9c64(%rbp),%eax
sub    $0x2,%eax
cltq
mov    -0x9c60(%rbp,%rax,4),%ecx
mov    -0x9c64(%rbp),%eax
sub    $0x1,%eax
cltq
mov    -0x9c60(%rbp,%rax,4),%eax
shl    $0x1,%eax
add    %eax,%ecx
movslq -0x9c64(%rbp),%rax
mov    %ecx,-0x9c60(%rbp,%rax,4)
mov    -0x9c64(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x9c64(%rbp)
cltq
mov    %rax,-0x9c78(%rbp)
mov    -0x9c60(%rbp,%rax,4),%eax
mov    $0x3039,%ecx
cltd
idiv   %ecx
mov    -0x9c78(%rbp),%rax
mov    %edx,-0x9c60(%rbp,%rax,4)
jmp    11a3 <main+0x73>
movslq -0x9c6c(%rbp),%rax
mov    -0x9c60(%rbp,%rax,4),%esi
lea    0xdbb(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x9c80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x9c58,%rsp
lea    0x10(%rsp),%rdi
mov    $0x9c44,%edx
xor    %esi,%esi
call   1040 <memset@plt>
movabs $0x700000003,%rax
mov    %rax,0x14(%rsp)
movl   $0x11,0x1c(%rsp)
lea    0xe9a(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1050 <scanf@plt>
mov    0xc(%rsp),%r9d
cmp    $0x4,%r9d
jl     1199 <main+0x69>
lea    0x1(%r9),%r8
cmp    $0x5,%r8d
jne    11a2 <main+0x72>
mov    $0x4,%ecx
mov    $0x7,%edx
mov    $0x22,%esi
jmp    1226 <main+0xf6>
lea    -0x1(%r9),%edi
jmp    1259 <main+0x129>
lea    -0x4(%r8),%r10
and    $0xfffffffffffffffe,%r10
neg    %r10
mov    $0x4,%ecx
mov    $0x7,%edx
mov    $0x11,%esi
nopl   0x0(%rax)
lea    (%rdx,%rsi,2),%edx
movslq %edx,%rdx
imul   $0xffffffffa9e0ef8f,%rdx,%rax
shr    $0x20,%rax
add    %edx,%eax
mov    %eax,%edi
shr    $0x1f,%edi
sar    $0xd,%eax
add    %edi,%eax
imul   $0x3039,%eax,%eax
sub    %eax,%edx
mov    %edx,0x10(%rsp,%rcx,4)
lea    (%rsi,%rdx,2),%eax
movslq %eax,%rsi
imul   $0xffffffffa9e0ef8f,%rsi,%rax
shr    $0x20,%rax
add    %esi,%eax
mov    %eax,%edi
shr    $0x1f,%edi
sar    $0xd,%eax
add    %edi,%eax
imul   $0x3039,%eax,%eax
sub    %eax,%esi
mov    %esi,0x14(%rsp,%rcx,4)
lea    (%r10,%rcx,1),%rax
add    $0x2,%rax
add    $0x2,%rcx
cmp    $0x4,%rax
jne    11c0 <main+0x90>
add    %esi,%esi
mov    $0x2,%edi
test   $0x1,%r8b
je     1259 <main+0x129>
add    %edx,%esi
movslq %esi,%rax
imul   $0xffffffffa9e0ef8f,%rax,%rdx
shr    $0x20,%rdx
add    %eax,%edx
mov    %edx,%esi
shr    $0x1f,%esi
sar    $0xd,%edx
add    %esi,%edx
imul   $0x3039,%edx,%edx
sub    %edx,%eax
mov    %eax,0x10(%rsp,%rcx,4)
mov    %edi,0xc(%rsp)
movslq %r9d,%rax
mov    0x10(%rsp,%rax,4),%esi
lea    0xd95(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x9c58,%rsp
ret

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

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