#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 *);
int main() {
  int n, m, x, y = 1;
  scanf("%d%d", &n, &m);
  x = n * 365 % 400009;
  for (int i = 0; i < m; i++) {
    for (int k = 0; k < 365; k++) {
      y = (y << 1) % 400009;
    }
  }
  int sum = (y - x) % 400009;
  if (sum < 0)
    sum += 400009;
  printf("%d\n", sum);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x14(%rbp)
lea    0xec3(%rip),%rdi
lea    -0x8(%rbp),%rsi
lea    -0xc(%rbp),%rdx
call   1040 <scanf@plt>
imul   $0x16d,-0x8(%rbp),%eax
mov    $0x61a89,%ecx
cltd
idiv   %ecx
mov    %edx,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11b5 <main+0x95>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x16d,-0x1c(%rbp)
jge    11a2 <main+0x82>
mov    -0x14(%rbp),%eax
shl    $0x1,%eax
mov    $0x61a89,%ecx
cltd
idiv   %ecx
mov    %edx,-0x14(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1176 <main+0x56>
jmp    11a7 <main+0x87>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1163 <main+0x43>
mov    -0x14(%rbp),%eax
sub    -0x10(%rbp),%eax
mov    $0x61a89,%ecx
cltd
idiv   %ecx
mov    %edx,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    11db <main+0xbb>
mov    -0x20(%rbp),%eax
add    $0x61a89,%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%esi
lea    0xe20(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
lea    0xed8(%rip),%rdi
lea    0x4(%rsp),%rsi
mov    %rsp,%rdx
call   1040 <scanf@plt>
mov    0x4(%rsp),%r8d
mov    (%rsp),%r9d
mov    $0x1,%edi
test   %r9d,%r9d
jle    1216 <main+0xf6>
xor    %edx,%edx
jmp    115c <main+0x3c>
add    $0x1,%edx
cmp    %r9d,%edx
je     1216 <main+0xf6>
mov    $0x16c,%esi
mov    %edi,%eax
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %eax,%edi
add    %eax,%edi
movslq %edi,%rdi
imul   $0xffffffffa7c4b4e5,%rdi,%rcx
shr    $0x20,%rcx
lea    (%rcx,%rax,2),%eax
mov    %eax,%ecx
shr    $0x1f,%ecx
sar    $0x12,%eax
add    %ecx,%eax
imul   $0x61a89,%eax,%eax
sub    %eax,%edi
test   %esi,%esi
je     1150 <main+0x30>
mov    %edi,%eax
add    %edi,%eax
cltq
imul   $0xffffffffa7c4b4e5,%rax,%rcx
shr    $0x20,%rcx
lea    (%rcx,%rdi,2),%ecx
mov    %ecx,%edi
shr    $0x1f,%edi
sar    $0x12,%ecx
add    %edi,%ecx
imul   $0x61a89,%ecx,%ecx
sub    %ecx,%eax
mov    %eax,%ecx
add    %eax,%ecx
movslq %ecx,%rcx
imul   $0xffffffffa7c4b4e5,%rcx,%rdi
shr    $0x20,%rdi
lea    (%rdi,%rax,2),%eax
mov    %eax,%edi
shr    $0x1f,%edi
sar    $0x12,%eax
add    %edi,%eax
imul   $0x61a89,%eax,%eax
sub    %eax,%ecx
mov    %ecx,%eax
add    %ecx,%eax
cltq
imul   $0xffffffffa7c4b4e5,%rax,%rdi
shr    $0x20,%rdi
lea    (%rdi,%rcx,2),%ecx
mov    %ecx,%edi
shr    $0x1f,%edi
sar    $0x12,%ecx
add    %edi,%ecx
imul   $0x61a89,%ecx,%ecx
sub    %ecx,%eax
add    $0xfffffffc,%esi
jmp    1170 <main+0x50>
imul   $0x16d,%r8d,%eax
cltq
imul   $0xffffffffa7c4b4e5,%rax,%rcx
shr    $0x20,%rcx
add    %eax,%ecx
mov    %ecx,%edx
shr    $0x1f,%edx
sar    $0x12,%ecx
add    %edx,%ecx
imul   $0x61a89,%ecx,%ecx
sub    %eax,%ecx
add    %edi,%ecx
movslq %ecx,%rax
imul   $0xffffffffa7c4b4e5,%rax,%rcx
shr    $0x20,%rcx
add    %eax,%ecx
mov    %ecx,%edx
shr    $0x1f,%edx
sar    $0x12,%ecx
add    %edx,%ecx
imul   $0x61a89,%ecx,%ecx
sub    %ecx,%eax
lea    0x61a89(%rax),%esi
test   %eax,%eax
cmovns %eax,%esi
lea    0xd91(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%d%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
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %1
store i32 1, i32* %5
%9 = call i32 @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32* %2, i32* %3)
%10 = load i32, i32* %2
%11 = mul nsw i32 %10, 365
%12 = srem i32 %11, 400009
store i32 %12, i32* %4
store i32 0, i32* %6
br label %13
13: ; preds = %29, %0
%14 = load i32, i32* %6
%15 = load i32, i32* %3
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %32
17: ; preds = %13
store i32 0, i32* %7
br label %18
18: ; preds = %25, %17
%19 = load i32, i32* %7
%20 = icmp slt i32 %19, 365
br i1 %20, label %21, label %28
21: ; preds = %18
%22 = load i32, i32* %5
%23 = shl i32 %22, 1
%24 = srem i32 %23, 400009
store i32 %24, i32* %5
br label %25
25: ; preds = %21
%26 = load i32, i32* %7
%27 = add nsw i32 %26, 1
store i32 %27, i32* %7
br label %18
28: ; preds = %18
br label %29
29: ; preds = %28
%30 = load i32, i32* %6
%31 = add nsw i32 %30, 1
store i32 %31, i32* %6
br label %13
32: ; preds = %13
%33 = load i32, i32* %5
%34 = load i32, i32* %4
%35 = sub nsw i32 %33, %34
%36 = srem i32 %35, 400009
store i32 %36, i32* %8
%37 = load i32, i32* %8
%38 = icmp slt i32 %37, 0
br i1 %38, label %39, label %42
39: ; preds = %32
%40 = load i32, i32* %8
%41 = add nsw i32 %40, 400009
store i32 %41, i32* %8
br label %42
42: ; preds = %39, %32
%43 = load i32, i32* %8
%44 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %43)
ret i32 0
}

LLVM IR (-O2):
@.str = [5 x i8] c"%d%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 = call i32 @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32* %1, i32* %2)
%6 = load i32, i32* %1
%7 = load i32, i32* %2
%8 = icmp sgt i32 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %0, %22
%10 = phi i32 [ %23, %22 ], [ 0, %0 ]
%11 = phi i32 [ %29, %22 ], [ 1, %0 ]
br label %25
12: ; preds = %22, %0
%13 = phi i32 [ 1, %0 ], [ %29, %22 ]
%14 = mul nsw i32 %6, 365
%15 = srem i32 %14, 400009
%16 = sub nsw i32 %13, %15
%17 = srem i32 %16, 400009
%18 = icmp slt i32 %17, 0
%19 = add nsw i32 %17, 400009
%20 = select i1 %18, i32 %19, i32 %17
%21 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %20)
ret i32 0
22: ; preds = %25
%23 = add nuw nsw i32 %10, 1
%24 = icmp eq i32 %23, %7
br i1 %24, label %12, label %9
25: ; preds = %31, %9
%26 = phi i32 [ 0, %9 ], [ %38, %31 ]
%27 = phi i32 [ %11, %9 ], [ %37, %31 ]
%28 = shl nsw i32 %27, 1
%29 = srem i32 %28, 400009
%30 = icmp eq i32 %26, 364
br i1 %30, label %22, label %31
31: ; preds = %25
%32 = shl nsw i32 %29, 1
%33 = srem i32 %32, 400009
%34 = shl nsw i32 %33, 1
%35 = srem i32 %34, 400009
%36 = shl nsw i32 %35, 1
%37 = srem i32 %36, 400009
%38 = add nuw nsw i32 %26, 4
br label %25
}