// File: vividvilla[P]hackerrank/src/grid-walking.cpp
// Function: getWays(std::vector<int, std::allocator<int>>, std::vector<int, std::allocator<int>>, int)
int getWays(vector<int> x, vector<int> d, int M) {
    int N = d.size();

    long long md[M + 1][N + 1];
    for (int i = 0; i < N; i++) {
        long long m[d[i] + 1][M + 1];
        int D = d[i];

        for (int j = 1; j <= D; j++)
            m[j][0] = 1;

        for (int n = 1; n <= M; n++) {
            for (int j = 1; j <= D; j++) {
                m[j][n] = 0;
                if (j - 1 > 0)
                    m[j][n] = (m[j][n] + m[j - 1][n - 1]) % MOD;
                if (j + 1 <= D)
                    m[j][n] = (m[j][n] + m[j + 1][n - 1]) % MOD;
            }
        }

        md[0][i + 1] = 1;
        for (int j = 1; j <= M; j++)
            md[j][i + 1] = m[x[i]][j];
    }

    long long c[M + 1][M + 1];
    for (int i = 0; i <= M; i++) {
        c[i][0] = 1;
        c[i][i] = 1;
    }
    for (int i = 1; i <= M; i++)
        for (int j = 1; j < i; j++)
        c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % MOD;

    long long mdt[M + 1][N + 1];
    for (int i = 0; i <= M; i++)
        mdt[i][1] = md[i][1];
    for (int i = 0; i <= N; i++)
        mdt[0][i] = 1;

    for (int i = 2; i <= N; i++) {
        for (int j = 1; j <= M; j++) {
            mdt[j][i] = 0;
            for (int k = 0; k <= j; k++)
                mdt[j][i] =
                    (mdt[j][i] +
                     ((c[j][j - k] *
                       ((mdt[k][i - 1] * md[j - k][i]) % MOD)) % MOD)) % MOD;
        }
    }

    return mdt[M][N];
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x120, %rsp            # imm = 0x120
movq %rsi, -0xd8(%rbp)
movq %rdi, %rax
movq -0xd8(%rbp), %rdi
movq %rax, -0xd0(%rbp)
movq %rdi, -0xc8(%rbp)
movq %rax, -0x8(%rbp)
movq %rdi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
callq 0x1c40
movl %eax, -0x18(%rbp)
movl -0x14(%rbp), %eax
incl %eax
movl %eax, %ecx
movl -0x18(%rbp), %eax
incl %eax
movq %rax, -0xc0(%rbp)
movq %rsp, %rdx
movq %rdx, -0x20(%rbp)
movq %rcx, %rdx
imulq %rax, %rdx
leaq 0xf(,%rdx,8), %rsi
andq $-0x10, %rsi
movq %rsp, %rdx
subq %rsi, %rdx
movq %rdx, -0xb8(%rbp)
movq %rdx, %rsp
movq %rcx, -0x28(%rbp)
movq %rax, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x18(%rbp), %eax
jge 0x15a7
movq -0xc8(%rbp), %rdi
movslq -0x34(%rbp), %rsi
callq 0x1c60
movq -0xc8(%rbp), %rdi
movl (%rax), %eax
incl %eax
movl %eax, %ecx
movl -0x14(%rbp), %eax
incl %eax
movq %rax, -0xe8(%rbp)
movq %rsp, %rdx
movq %rdx, -0x40(%rbp)
movq %rcx, %rdx
imulq %rax, %rdx
leaq 0xf(,%rdx,8), %rsi
andq $-0x10, %rsi
movq %rsp, %rdx
subq %rsi, %rdx
movq %rdx, -0xe0(%rbp)
movq %rdx, %rsp
movq %rcx, -0x48(%rbp)
movq %rax, -0x50(%rbp)
movslq -0x34(%rbp), %rsi
callq 0x1c60
movl (%rax), %eax
movl %eax, -0x54(%rbp)
movl $0x1, -0x58(%rbp)
movl -0x58(%rbp), %eax
cmpl -0x54(%rbp), %eax
jg 0x1386
movq -0xe0(%rbp), %rax
movq -0xe8(%rbp), %rdx
movslq -0x58(%rbp), %rcx
imulq %rdx, %rcx
movq $0x1, (%rax,%rcx,8)
movl -0x58(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
jmp 0x1355
movl $0x1, -0x5c(%rbp)
movl -0x5c(%rbp), %eax
cmpl -0x14(%rbp), %eax
jg 0x14ed
movl $0x1, -0x60(%rbp)
movl -0x60(%rbp), %eax
cmpl -0x54(%rbp), %eax
jg 0x14dd
movq -0xe0(%rbp), %rax
movq -0xe8(%rbp), %rdx
movslq -0x60(%rbp), %rcx
imulq %rdx, %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movslq -0x5c(%rbp), %rcx
movq $0x0, (%rax,%rcx,8)
movl -0x60(%rbp), %eax
subl $0x1, %eax
cmpl $0x0, %eax
jle 0x1451
movq -0xe0(%rbp), %rcx
movq -0xe8(%rbp), %rsi
movslq -0x60(%rbp), %rdx
imulq %rsi, %rdx
shlq $0x3, %rdx
movq %rcx, %rax
addq %rdx, %rax
movslq -0x5c(%rbp), %rdx
movq (%rax,%rdx,8), %rax
movl -0x60(%rbp), %edx
subl $0x1, %edx
movslq %edx, %rdx
imulq %rsi, %rdx
shlq $0x3, %rdx
addq %rdx, %rcx
movl -0x5c(%rbp), %edx
subl $0x1, %edx
movslq %edx, %rdx
addq (%rcx,%rdx,8), %rax
movl $0x3b9aca07, %ecx       # imm = 0x3B9ACA07
cqto
idivq %rcx
movq -0xe0(%rbp), %rax
movslq -0x60(%rbp), %rcx
imulq %rsi, %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movslq -0x5c(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movl -0x60(%rbp), %eax
addl $0x1, %eax
cmpl -0x54(%rbp), %eax
jg 0x14cd
movq -0xe0(%rbp), %rcx
movq -0xe8(%rbp), %rsi
movslq -0x60(%rbp), %rdx
imulq %rsi, %rdx
shlq $0x3, %rdx
movq %rcx, %rax
addq %rdx, %rax
movslq -0x5c(%rbp), %rdx
movq (%rax,%rdx,8), %rax
movl -0x60(%rbp), %edx
addl $0x1, %edx
movslq %edx, %rdx
imulq %rsi, %rdx
shlq $0x3, %rdx
addq %rdx, %rcx
movl -0x5c(%rbp), %edx
subl $0x1, %edx
movslq %edx, %rdx
addq (%rcx,%rdx,8), %rax
movl $0x3b9aca07, %ecx       # imm = 0x3B9ACA07
cqto
idivq %rcx
movq -0xe0(%rbp), %rax
movslq -0x60(%rbp), %rcx
imulq %rsi, %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movslq -0x5c(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
jmp 0x14cf
movl -0x60(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x60(%rbp)
jmp 0x13a0
jmp 0x14df
movl -0x5c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5c(%rbp)
jmp 0x138d
movq -0xb8(%rbp), %rax
movq -0xc0(%rbp), %rcx
imulq $0x0, %rcx, %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movl -0x34(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq $0x1, (%rax,%rcx,8)
movl $0x1, -0x64(%rbp)
movl -0x64(%rbp), %eax
cmpl -0x14(%rbp), %eax
jg 0x1592
movq -0xd0(%rbp), %rdi
movslq -0x34(%rbp), %rsi
callq 0x1c60
movq -0xe8(%rbp), %rdi
movq -0xe0(%rbp), %rcx
movq -0xc0(%rbp), %rsi
movq %rax, %rdx
movq -0xb8(%rbp), %rax
movslq (%rdx), %rdx
imulq %rdi, %rdx
shlq $0x3, %rdx
addq %rdx, %rcx
movslq -0x64(%rbp), %rdx
movq (%rcx,%rdx,8), %rdx
movslq -0x64(%rbp), %rcx
imulq %rsi, %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movl -0x34(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq %rdx, (%rax,%rcx,8)
movl -0x64(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x64(%rbp)
jmp 0x151e
movq -0x40(%rbp), %rax
movq %rax, %rsp
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x12d9
movl -0x14(%rbp), %eax
incl %eax
movq %rax, -0xf8(%rbp)
movq %rax, %rcx
movq %rax, %rdx
imulq %rdx, %rdx
leaq 0xf(,%rdx,8), %rsi
andq $-0x10, %rsi
movq %rsp, %rdx
subq %rsi, %rdx
movq %rdx, -0xf0(%rbp)
movq %rdx, %rsp
movq %rcx, -0x70(%rbp)
movq %rax, -0x78(%rbp)
movl $0x0, -0x7c(%rbp)
movl -0x7c(%rbp), %eax
cmpl -0x14(%rbp), %eax
jg 0x1634
movq -0xf0(%rbp), %rax
movq -0xf8(%rbp), %rdx
movslq -0x7c(%rbp), %rcx
imulq %rdx, %rcx
movq $0x1, (%rax,%rcx,8)
movslq -0x7c(%rbp), %rcx
imulq %rdx, %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movslq -0x7c(%rbp), %rcx
movq $0x1, (%rax,%rcx,8)
movl -0x7c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x7c(%rbp)
jmp 0x15e8
movl $0x1, -0x80(%rbp)
movl -0x80(%rbp), %eax
cmpl -0x14(%rbp), %eax
jg 0x1703
movl $0x1, -0x84(%rbp)
movl -0x84(%rbp), %eax
cmpl -0x80(%rbp), %eax
jge 0x16f3
movq -0xf0(%rbp), %rcx
movq -0xf8(%rbp), %rsi
movl -0x80(%rbp), %eax
subl $0x1, %eax
movslq %eax, %rdx
imulq %rsi, %rdx
shlq $0x3, %rdx
movq %rcx, %rax
addq %rdx, %rax
movl -0x84(%rbp), %edx
subl $0x1, %edx
movslq %edx, %rdx
movq (%rax,%rdx,8), %rax
movl -0x80(%rbp), %edx
subl $0x1, %edx
movslq %edx, %rdx
imulq %rsi, %rdx
shlq $0x3, %rdx
addq %rdx, %rcx
movslq -0x84(%rbp), %rdx
addq (%rcx,%rdx,8), %rax
movl $0x3b9aca07, %ecx       # imm = 0x3B9ACA07
cqto
idivq %rcx
movq -0xf0(%rbp), %rax
movslq -0x80(%rbp), %rcx
imulq %rsi, %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movslq -0x84(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movl -0x84(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x84(%rbp)
jmp 0x1651
jmp 0x16f5
movl -0x80(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x80(%rbp)
jmp 0x163b
movl -0x14(%rbp), %eax
incl %eax
movl %eax, %ecx
movl -0x18(%rbp), %eax
incl %eax
movq %rax, -0x108(%rbp)
movq %rcx, %rdx
imulq %rax, %rdx
leaq 0xf(,%rdx,8), %rsi
andq $-0x10, %rsi
movq %rsp, %rdx
subq %rsi, %rdx
movq %rdx, -0x100(%rbp)
movq %rdx, %rsp
movq %rcx, -0x90(%rbp)
movq %rax, -0x98(%rbp)
movl $0x0, -0x9c(%rbp)
movl -0x9c(%rbp), %eax
cmpl -0x14(%rbp), %eax
jg 0x17a9
movq -0x100(%rbp), %rax
movq -0x108(%rbp), %rsi
movq -0xb8(%rbp), %rcx
movq -0xc0(%rbp), %rdi
movslq -0x9c(%rbp), %rdx
imulq %rdi, %rdx
movq 0x8(%rcx,%rdx,8), %rdx
movslq -0x9c(%rbp), %rcx
imulq %rsi, %rcx
movq %rdx, 0x8(%rax,%rcx,8)
movl -0x9c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x9c(%rbp)
jmp 0x1751
movl $0x0, -0xa0(%rbp)
movl -0xa0(%rbp), %eax
cmpl -0x18(%rbp), %eax
jg 0x17f7
movq -0x100(%rbp), %rax
movq -0x108(%rbp), %rcx
imulq $0x0, %rcx, %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movslq -0xa0(%rbp), %rcx
movq $0x1, (%rax,%rcx,8)
movl -0xa0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xa0(%rbp)
jmp 0x17b3
movl $0x2, -0xa4(%rbp)
movl -0xa4(%rbp), %eax
cmpl -0x18(%rbp), %eax
jg 0x19d2
movl $0x1, -0xa8(%rbp)
movl -0xa8(%rbp), %eax
cmpl -0x14(%rbp), %eax
jg 0x19bc
movq -0x100(%rbp), %rax
movq -0x108(%rbp), %rdx
movslq -0xa8(%rbp), %rcx
imulq %rdx, %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movslq -0xa4(%rbp), %rcx
movq $0x0, (%rax,%rcx,8)
movl $0x0, -0xac(%rbp)
movl -0xac(%rbp), %eax
cmpl -0xa8(%rbp), %eax
jg 0x19a6
movq -0x100(%rbp), %rax
movq -0x108(%rbp), %rsi
movq -0xb8(%rbp), %rcx
movq -0xc0(%rbp), %rdi
movq -0xf0(%rbp), %rdx
movq -0xf8(%rbp), %r9
movslq -0xa8(%rbp), %r10
imulq %rsi, %r10
shlq $0x3, %r10
movq %rax, %r8
addq %r10, %r8
movslq -0xa4(%rbp), %r10
movq (%r8,%r10,8), %r8
movq %r8, -0x110(%rbp)
movslq -0xa8(%rbp), %r8
imulq %r9, %r8
shlq $0x3, %r8
addq %r8, %rdx
movl -0xa8(%rbp), %r8d
subl -0xac(%rbp), %r8d
movslq %r8d, %r8
movq (%rdx,%r8,8), %rdx
movq %rdx, -0x118(%rbp)
movslq -0xac(%rbp), %rdx
imulq %rsi, %rdx
shlq $0x3, %rdx
addq %rdx, %rax
movl -0xa4(%rbp), %edx
subl $0x1, %edx
movslq %edx, %rdx
movq (%rax,%rdx,8), %rax
movl -0xa8(%rbp), %edx
subl -0xac(%rbp), %edx
movslq %edx, %rdx
imulq %rdi, %rdx
shlq $0x3, %rdx
addq %rdx, %rcx
movslq -0xa4(%rbp), %rdx
imulq (%rcx,%rdx,8), %rax
movl $0x3b9aca07, %ecx       # imm = 0x3B9ACA07
cqto
idivq %rcx
movq -0x118(%rbp), %rax
imulq %rdx, %rax
movl $0x3b9aca07, %ecx       # imm = 0x3B9ACA07
cqto
idivq %rcx
movq -0x110(%rbp), %rax
addq %rdx, %rax
movl $0x3b9aca07, %ecx       # imm = 0x3B9ACA07
cqto
idivq %rcx
movq -0x100(%rbp), %rax
movslq -0xa8(%rbp), %rcx
imulq %rsi, %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movslq -0xa4(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movl -0xac(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xac(%rbp)
jmp 0x1862
jmp 0x19a8
movl -0xa8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xa8(%rbp)
jmp 0x181a
jmp 0x19be
movl -0xa4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xa4(%rbp)
jmp 0x1801
movq -0x100(%rbp), %rax
movq -0x108(%rbp), %rdx
movslq -0x14(%rbp), %rcx
imulq %rdx, %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movslq -0x18(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq -0x20(%rbp), %rcx
movq %rcx, %rsp
movq %rbp, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)