#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*/ calculate(int, int, int, long long **);
int /*<<< orphan*/ printf(char *, int /*<<< orphan*/);
scalar_t__ scanf(char *, int *, int *);
int main(void) {
  long long int memoTable[20 + 1][20 + 1];
  int n, aN1, row, col;
  while (scanf("%d %d", &n, &aN1) > 0) {
    for (row = 0; row <= n; row++)
      for (col = 0; col <= n; col++)
        memoTable[row][col] = -1;
    memoTable[n][1] = (long long int)aN1;
    printf("%lld\n", calculate(1, n, n, memoTable));
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xde0,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeb7(%rip),%rdi
lea    -0xdd4(%rbp),%rsi
lea    -0xdd8(%rbp),%rdx
call   1050 <scanf@plt>
cmp    $0x0,%rax
jle    1245 <main+0x115>
movl   $0x0,-0xddc(%rbp)
mov    -0xddc(%rbp),%eax
cmp    -0xdd4(%rbp),%eax
jg     11f2 <main+0xc2>
movl   $0x0,-0xde0(%rbp)
mov    -0xde0(%rbp),%eax
cmp    -0xdd4(%rbp),%eax
jg     11d9 <main+0xa9>
movslq -0xddc(%rbp),%rcx
lea    -0xdd0(%rbp),%rax
imul   $0xa8,%rcx,%rcx
add    %rcx,%rax
movslq -0xde0(%rbp),%rcx
movq   $0xffffffffffffffff,(%rax,%rcx,8)
ff
mov    -0xde0(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xde0(%rbp)
jmp    118c <main+0x5c>
jmp    11de <main+0xae>
mov    -0xddc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xddc(%rbp)
jmp    1170 <main+0x40>
movslq -0xdd8(%rbp),%rcx
movslq -0xdd4(%rbp),%rdx
lea    -0xdd0(%rbp),%rax
imul   $0xa8,%rdx,%rdx
add    %rdx,%rax
mov    %rcx,0x8(%rax)
mov    -0xdd4(%rbp),%esi
mov    -0xdd4(%rbp),%edx
lea    -0xdd0(%rbp),%rcx
mov    $0x1,%edi
call   1040 <calculate@plt>
mov    %eax,%esi
lea    0xdcb(%rip),%rdi
call   1030 <printf@plt>
jmp    1142 <main+0x12>
xor    %eax,%eax
add    $0xde0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xdd8,%rsp
jmp    1194 <main+0x54>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movslq 0x8(%rsp),%rax
imul   $0xa8,%r13,%rcx
mov    %rax,0x18(%rsp,%rcx,1)
mov    $0x1,%edi
mov    %r13d,%esi
mov    %r13d,%edx
lea    0x10(%rsp),%rcx
call   1040 <calculate@plt>
lea    0xe79(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
lea    0xe65(%rip),%rdi
lea    0xc(%rsp),%rsi
lea    0x8(%rsp),%rdx
call   1060 <scanf@plt>
test   %rax,%rax
jle    1302 <main+0x1c2>
movslq 0xc(%rsp),%r13
test   %r13,%r13
js     1160 <main+0x20>
mov    %r13d,%eax
lea    0x8(,%rax,8),%r14
mov    %rax,%r12
add    $0x1,%r12
mov    %r12d,%ebp
and    $0x7,%ebp
cmp    $0x7,%eax
jae    11f0 <main+0xb0>
xor    %r15d,%r15d
jmp    12b0 <main+0x170>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
and    $0xfffffff8,%r12d
lea    0x10(%rsp),%rbx
xor    %r15d,%r15d
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    $0xff,%esi
mov    %r14,%rdx
call   1050 <memset@plt>
lea    0xa8(%rbx),%rdi
mov    $0xff,%esi
mov    %r14,%rdx
call   1050 <memset@plt>
lea    0x150(%rbx),%rdi
mov    $0xff,%esi
mov    %r14,%rdx
call   1050 <memset@plt>
lea    0x1f8(%rbx),%rdi
mov    $0xff,%esi
mov    %r14,%rdx
call   1050 <memset@plt>
lea    0x2a0(%rbx),%rdi
mov    $0xff,%esi
mov    %r14,%rdx
call   1050 <memset@plt>
lea    0x348(%rbx),%rdi
mov    $0xff,%esi
mov    %r14,%rdx
call   1050 <memset@plt>
lea    0x3f0(%rbx),%rdi
mov    $0xff,%esi
mov    %r14,%rdx
call   1050 <memset@plt>
lea    0x498(%rbx),%rdi
mov    $0xff,%esi
mov    %r14,%rdx
call   1050 <memset@plt>
add    $0x8,%r15
add    $0x540,%rbx
cmp    %r15,%r12
jne    1200 <main+0xc0>
test   %rbp,%rbp
je     1160 <main+0x20>
imul   $0xa8,%r15,%rax
lea    (%rsp,%rax,1),%r15
add    $0x10,%r15
imul   $0xa8,%rbp,%rbp
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    (%r15,%rbx,1),%rdi
mov    $0xff,%esi
mov    %r14,%rdx
call   1050 <memset@plt>
add    $0xa8,%rbx
cmp    %rbx,%rbp
jne    12e0 <main+0x1a0>
jmp    1160 <main+0x20>
xor    %eax,%eax
add    $0xdd8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [6 x i8] c"%d %d\00"
@.str.1 = [6 x i8] c"%lld\0A\00"
define i32 @main() {
%1 = alloca [21 x [21 x i64]]
%2 = alloca i32
%3 = alloca i32
%4 = bitcast [21 x [21 x i64]]* %1 to i8*
%5 = bitcast i32* %2 to i8*
%6 = bitcast i32* %3 to i8*
%7 = call i64 @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32* %2, i32* %3)
%8 = icmp sgt i64 %7, 0
br i1 %8, label %9, label %74
9: ; preds = %0
%10 = bitcast [21 x [21 x i64]]* %1 to i64**
br label %11
11: ; preds = %9, %65
%12 = load i32, i32* %2
%13 = icmp slt i32 %12, 0
br i1 %13, label %65, label %14
14: ; preds = %11
%15 = zext i32 %12 to i64
%16 = shl nuw nsw i64 %15, 3
%17 = add nuw nsw i64 %16, 8
%18 = add nuw i32 %12, 1
%19 = zext i32 %18 to i64
%20 = add nsw i64 %19, -1
%21 = and i64 %19, 7
%22 = icmp ult i64 %20, 7
br i1 %22, label %54, label %23
23: ; preds = %14
%24 = and i64 %19, 4294967288
br label %25
25: ; preds = %25, %23
%26 = phi i64 [ 0, %23 ], [ %51, %25 ]
%27 = phi i64 [ 0, %23 ], [ %52, %25 ]
%28 = getelementptr [21 x [21 x i64]], [21 x [21 x i64]]* %1, i64 0, i64 %26, i64 0
%29 = bitcast i64* %28 to i8*
%30 = or i64 %26, 1
%31 = getelementptr [21 x [21 x i64]], [21 x [21 x i64]]* %1, i64 0, i64 %30, i64 0
%32 = bitcast i64* %31 to i8*
%33 = or i64 %26, 2
%34 = getelementptr [21 x [21 x i64]], [21 x [21 x i64]]* %1, i64 0, i64 %33, i64 0
%35 = bitcast i64* %34 to i8*
%36 = or i64 %26, 3
%37 = getelementptr [21 x [21 x i64]], [21 x [21 x i64]]* %1, i64 0, i64 %36, i64 0
%38 = bitcast i64* %37 to i8*
%39 = or i64 %26, 4
%40 = getelementptr [21 x [21 x i64]], [21 x [21 x i64]]* %1, i64 0, i64 %39, i64 0
%41 = bitcast i64* %40 to i8*
%42 = or i64 %26, 5
%43 = getelementptr [21 x [21 x i64]], [21 x [21 x i64]]* %1, i64 0, i64 %42, i64 0
%44 = bitcast i64* %43 to i8*
%45 = or i64 %26, 6
%46 = getelementptr [21 x [21 x i64]], [21 x [21 x i64]]* %1, i64 0, i64 %45, i64 0
%47 = bitcast i64* %46 to i8*
%48 = or i64 %26, 7
%49 = getelementptr [21 x [21 x i64]], [21 x [21 x i64]]* %1, i64 0, i64 %48, i64 0
%50 = bitcast i64* %49 to i8*
%51 = add nuw nsw i64 %26, 8
%52 = add i64 %27, 8
%53 = icmp eq i64 %52, %24
br i1 %53, label %54, label %25
54: ; preds = %25, %14
%55 = phi i64 [ 0, %14 ], [ %51, %25 ]
%56 = icmp eq i64 %21, 0
br i1 %56, label %65, label %57
57: ; preds = %54, %57
%58 = phi i64 [ %62, %57 ], [ %55, %54 ]
%59 = phi i64 [ %63, %57 ], [ 0, %54 ]
%60 = getelementptr [21 x [21 x i64]], [21 x [21 x i64]]* %1, i64 0, i64 %58, i64 0
%61 = bitcast i64* %60 to i8*
%62 = add nuw nsw i64 %58, 1
%63 = add i64 %59, 1
%64 = icmp eq i64 %63, %21
br i1 %64, label %65, label %57
65: ; preds = %54, %57, %11
%66 = load i32, i32* %3
%67 = sext i32 %66 to i64
%68 = sext i32 %12 to i64
%69 = getelementptr inbounds [21 x [21 x i64]], [21 x [21 x i64]]* %1, i64 0, i64 %68, i64 1
store i64 %67, i64* %69
%70 = call i32 @calculate(i32 1, i32 %12, i32 %12, i64** %10)
%71 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %70)
%72 = call i64 @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32* %2, i32* %3)
%73 = icmp sgt i64 %72, 0
br i1 %73, label %11, label %74
74: ; preds = %65, %0
ret i32 0
}