#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*/ read(int, int *);
int /*<<< orphan*/ scanf(char *, int *);
int solve(int, int *, int);
int main() {
  int p, n;
  scanf("%d\n", &p);
  scanf("%d\n", &n);
  int nums[n * n];
  read(n, nums);
  printf("%d\n", solve(n, nums, p));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
mov    %rdi,-0x30(%rbp)
lea    -0x8(%rbp),%rsi
call   1060 <scanf@plt>
mov    -0x30(%rbp),%rdi
lea    -0xc(%rbp),%rsi
call   1060 <scanf@plt>
mov    -0xc(%rbp),%eax
imul   %eax,%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
lea    0xf(,%rax,4),%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rsi
sub    %rcx,%rsi
mov    %rsi,-0x28(%rbp)
mov    %rsi,%rsp
mov    %rax,-0x20(%rbp)
mov    -0xc(%rbp),%edi
call   1050 <read@plt>
mov    -0x28(%rbp),%rsi
mov    -0xc(%rbp),%edi
mov    -0x8(%rbp),%edx
call   1030 <solve@plt>
mov    %eax,%esi
lea    0xe46(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
push   %rax
lea    0xeaf(%rip),%r14
lea    -0x20(%rbp),%rsi
mov    %r14,%rdi
call   1060 <scanf@plt>
lea    -0x1c(%rbp),%rsi
mov    %r14,%rdi
call   1060 <scanf@plt>
mov    %rsp,%r15
mov    -0x1c(%rbp),%eax
imul   %eax,%eax
mov    %rsp,%rbx
lea    0xf(,%rax,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    -0x1c(%rbp),%edi
mov    %rbx,%rsi
call   1050 <read@plt>
mov    -0x1c(%rbp),%edi
mov    -0x20(%rbp),%edx
mov    %rbx,%rsi
call   1030 <solve@plt>
mov    %r14,%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    %r15,%rsp
xor    %eax,%eax
lea    -0x18(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64
store i32 0, i32* %1
%6 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* %2)
%7 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* %3)
%8 = load i32, i32* %3
%9 = load i32, i32* %3
%10 = mul nsw i32 %8, %9
%11 = zext i32 %10 to i64
%12 = call i8* @llvm.stacksave()
store i8* %12, i8** %4
%13 = alloca i32, i64 %11
store i64 %11, i64* %5
%14 = load i32, i32* %3
%15 = call i32 @read(i32 %14, i32* %13)
%16 = load i32, i32* %3
%17 = load i32, i32* %2
%18 = call i32 @solve(i32 %16, i32* %13, i32 %17)
%19 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %18)
store i32 0, i32* %1
%20 = load i8*, i8** %4
%21 = load i32, i32* %1
ret i32 %21
}

LLVM IR (-O2):
@.str = [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 ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* %1)
%6 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* %2)
%7 = load i32, i32* %2
%8 = mul nsw i32 %7, %7
%9 = zext i32 %8 to i64
%10 = call i8* @llvm.stacksave()
%11 = alloca i32, i64 %9
%12 = load i32, i32* %2
%13 = call i32 @read(i32 %12, i32* %11)
%14 = load i32, i32* %2
%15 = load i32, i32* %1
%16 = call i32 @solve(i32 %14, i32* %11, i32 %15)
%17 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %16)
ret i32 0
}