Harryxun/stf_run huggingface dataset:
n = int(input())
s = [int(input()) for _ in range(n)]

dp = [set() for _ in range(n + 1)]
for i in range(n):
    dp[i + 1].update(dp[i])
    for x in dp[i]:
        dp[i + 1].add(x + s[i])
    dp[i + 1].add(s[i])


ans = max((x for x in dp[i + 1] if x % 10 != 0), default=0)
print(ans)


### FIXED CODE ###

def find(scores):
    for score in scores:
        if score % 10 != 0: return score
    return -1

def solve(scores):
    x = find(scores)
    if x == -1: return 0

    total = sum(scores)
    return total if total % 10 != 0 else total - x

if __name__ == '__main__':
    n = int(input())
    scores = list(sorted(int(input()) for _ in range(n)))
    print(solve(scores))
import itertools

def sign(num):
    if num < 0:
        return -1
    elif num > 0:
        return 1
    else:
        return 0

N = input()
a_i = list(map(int, input().split()))

signs = [-1,1]
a_sum = 0
changes_1 = 0
for i, a in enumerate(a_i):
    a_sum += a
    if sign(a_sum) != signs[i%2]:
        changes += abs(a_sum) + 1
        a_sum = signs[i%2]

signs = [1,-1]
a_sum = 0
changes_2 = 0
for i, a in enumerate(a_i):
    a_sum += a
    if sign(a_sum) != signs[i%2]:
        changes += abs(a_sum) + 1
        a_sum = signs[i%2]

print(min(changes_1,changes_2))

#
# for i, sum_i in enumerate(a_sum):
#     if i == 0:
#         signs = [sign(sum_i), -sign(sum_i)]
#     elif sign(sum_i) != signs[i%2]:
#         a_sum[i:] = [num + (abs(sum_i) + 1) * signs[i%2] for num in a_sum[i:]]
#         changes += abs(sum_i) + 1
#     # print(a_sum)
# print(changes)


### FIXED CODE ###

import itertools

def sign(num):
    if num < 0:
        return -1
    elif num > 0:
        return 1
    else:
        return 0

N = input()
a_i = list(map(int, input().split()))

signs = [-1,1]
a_sum = 0
changes_1 = 0
for i, a in enumerate(a_i):
    a_sum += a
    if sign(a_sum) != signs[i%2]:
        changes_1 += abs(a_sum) + 1
        a_sum = signs[i%2]

signs = [1,-1]
a_sum = 0
changes_2 = 0
for i, a in enumerate(a_i):
    a_sum += a
    if sign(a_sum) != signs[i%2]:
        changes_2 += abs(a_sum) + 1
        a_sum = signs[i%2]

print(min(changes_1,changes_2))
a=list(map(lambda x:x,input().split())
if(a[0]==a[1]):
       print("Yes")
else:
       print("No")

### FIXED CODE ###

a=list(map(lambda x:x,input().split()))
if(a[0]==a[1]):
       print("Yes")
else:
       print("No")
def exp(x):
  ans = 0
  for i in range(x+1):
    ans += i
  return ans / x

n, k = map(int, input().split())
p = list(map(int, input().split()))
  
sum = 0
ans = []
for i in range(k):
  sum += exp(p[i])
ans.append(sum)

for i in range(n-k+1):
  sum -= exp(p[i])
  sum += exp(p[k])
  ans.append(sum)

print(max(ans))

### FIXED CODE ###

def exp(x):
  return (1+x) / 2

n, k = map(int, input().split())
p = list(map(int, input().split()))
  
sum = 0
for i in range(k):
  sum += exp(p[i])
max = sum

for i in range(n-k):
  sum += exp(p[i+k]) - exp(p[i])
  if max < sum:
    max = sum

print(max)
# -*- coding: utf-8 -*-

import sys


lineNumber = 0
#for line in [ "2", "1000", "800", "999999999999999999999999999", "1" ]:
for line in sys.stdin.readlines():
    lineNumber += 1

    # line exception
    if lineNumber == 1:
        continue
    
    # get data
    List = map(int, line.strip().split())

    # set data
    if lineNumber % 2 == 0: a = List[0]
    else                  : b = List[0]

    # sum
    if lineNumber % 2 == 1:
        c = a + b
        if c < 10**79: print c
        else         : print "overflow"

### FIXED CODE ###

for i in range(int(raw_input())):
    x = int(raw_input())
    y = int(raw_input())
    s = str(x+y)
    if len(s) > 80:
        print "overflow"
    else :
        print s
from collections import Counter

n=int(input())
a=list(map(int,input().split()))
a_s=list(set(a))
c_l=Counter(a)

cnt=0
for i in a_s:
    cnt+=c_l[i] if c_l[i]<i else cnt+=c_l[i]-i
print(cnt)

### FIXED CODE ###

from collections import Counter

n=int(input())
a=list(map(int,input().split()))
a_s=list(set(a))
c_l=Counter(a)

cnt=0
for i in a_s:
    if c_l[i]<i:
        cnt+=c_l[i]
    else:
        cnt+=c_l[i]-i
print(cnt)
import numpy as np

n = int(input())
a = np.array(list(map(int, input().split())))

d_cumsum = np.zeros(60, dtype='i8')
for v in a:
    d_cumsum += np.array(list(map(int, list(format(v, '060b')))))

res = 0
mod = 10**9 + 7
for i, d in enumerate(reversed(d_cumsum)):
    res += (2**i * d * (n-d)) % mod
    res %= mod

print(res)

### FIXED CODE ###

from itertools import count

n = int(input())
a = list(map(int, input().split()))

d_cumsum = [0] * 60
for v in a:
    for i in count():
        d_cumsum[i] += v % 2
        v //= 2
        if v == 0:
            break

res = 0
mod = 10**9 + 7
for i, d in enumerate(d_cumsum):
    res += (2**i * d * (n-d)) % mod
    res %= mod

print(res)
a, b = (int(x) for x in input().split())
s = (a + b) % 2
t = (a + b) / 2
if s == 0:
	print(t)
	else:
	print(t + 0.5)	

### FIXED CODE ###

import math
a, b = (int(t) for t in input().split())
x = (a + b) / 2
print(math.ceil(x))
amo = []
ybt = []
 
n = int(input())
for i in range(n):
  a, y = map(input().split())
  amo.append(a)
  ybt.append(y)
  
sum = 0
for i in range(n):
  if ybt[i] == "JPY":
    sum = sum + float(amo[i])
  else:
    sum = sum + float(amo[i])* 380000
    
print(sum)

### FIXED CODE ###

amo = []
ybt = []
 
n = int(input())
for i in range(n):
  a, y = input().split()
  amo.append(a)
  ybt.append(y)
  
sum = 0
for i in range(n):
  if ybt[i] == "JPY":
    sum = sum + float(amo[i])
  else:
    sum = sum + float(amo[i])* 380000
    
print(sum)
H,W,M = map(int,input().split())
P = [0]*(H+1)
Q = [0]*(W+1)
A = []
for k in range(M):
  a,b = map(int,input().split())
  P[a] += 1
  Q[b] += 1
  A.append(a,b)
Pindex = [i for i, v in enumerate(P) if v == max(P)]
Qindex = [i for i, v in enumerate(Q) if v == max(Q)]
Pmax = P[Pindex[0]]
Qmax = Q[Qindex[0]]
ans = Pmax+Qmax-1
key = 0
for x in Pindex:
  for y in Qindex:
    if (x,y) not in A:
      ans += 1
      key = 1
      break
  if key == 1:
    break
print(ans)


### FIXED CODE ###

H,W,M = map(int,input().split())
P = [0]*(H+1)
Q = [0]*(W+1)
A = set()
for k in range(M):
    a,b = map(int,input().split())
    P[a] += 1
    Q[b] += 1
    A.add((a,b))
Pmax = max(P)
Qmax = max(Q)
Pindex = []
Qindex = []
for i in range(H+1):
    if P[i] == Pmax:
        Pindex.append(i)
for i in range(W+1):
    if Q[i] == Qmax:
        Qindex.append(i)
ans = Pmax+Qmax-1
key = 0
for x in Pindex:
  for y in Qindex:
    if (x,y) not in A:
      ans += 1
      key = 1
      break
  if key == 1:
    break
print(ans)
n = int(input())
A = list(map(int,input().split()))
A_sum = sum(A)
ans = 10**19
for i in range(n):
  x = sum(A[:i+1])
  z = abs(A_sum -2*x)
  ans = min(ans,z)
print(b)


### FIXED CODE ###

N = int(input())
A = list(map(int,input().split()))
sum_A = sum(A)
ans = 10**20
X = 0
for a in A[:-1]:
    X += a
    ans = min(ans,abs(sum_A-2*X))
print(ans)
def solution(h):
    n = len(h)
    for i in range(n):
        for j in range(i+1,i+3):
            if j < n:
                dp[j] = min(dp[j] , dp[i]+abs(h[i]-h[j]) )
    return dp[n-1]

N = int(input())
h = list(map(int,input().split()))
res = solution(h)
print(res)


### FIXED CODE ###



def solution(h):
    n = len(h)
    INF = float('inf')
    dp = [INF]*n
    dp[0] = 0
    for i in range(n):
        for j in range(i+1,i+3):
            if j < n:
                dp[j] = min(dp[j] , dp[i]+abs(h[i]-h[j]) )
    
    return dp[n-1]

N = int(input())
h = list(map(int,input().split()))
res = solution(h)
print(res)
def main(n):
    print int(raw_input())**3

main(n)

### FIXED CODE ###

def main(n):
    print int(n)**3

main(raw_input())
A = list(map(int, input().split()))
    a1, a2, a3 = A
    if a1 + a2 + a3 >= 22:
        print('bust')
    else:
        print('win')

### FIXED CODE ###

A = list(map(int, input().split()))
a1, a2, a3 = A
if a1 + a2 + a3 >= 22:
  print('bust')
else:
  print('win')
N=int(input())
A=list(map(int,input().split()))

shim0=[-1 for i in range(N)]
real_ans=0
ans1=list(set(A))
for k in range(len(ans1)):
    num_k=A.count(ans1[k])
    real_ans+=(num_k*(num_k-1))//2
    
    
for i in range(N):
    if shim0[A[i]]!=-1:
        print(shim0[A[i]])
    else:
        num=A.count(A[i])
        re_ans=real_ans-(num-1)
        shim0[A[i]]=re_ans
        print(shim0[A[i]])
        

### FIXED CODE ###

import collections

N=int(input())
A=list(map(int,input().split()))

ans=0
dic=collections.Counter(A)
keys=list(dic.keys())
values=list(dic.values())


for i in values:
    
    ans+=(i*(i-1))//2

for j in A:
    ANS=ans
    num=dic[j]
    ANS=ANS-(num-1)
    print(ANS)
a, b, c = map(int, input().split())
res = False
n = abs(b * c // (b - a))
for i in range(n -1, n + 1 + 1):
    if a * i % b == c:
        res = True

print("YES" if res == True else "NO")

### FIXED CODE ###

a, b, c = map(int, input().split())
res = False
for i in range(a, a * b + 1, a):
    if i % b == c:
        res = True

print("YES" if res == True else "NO")
a, b, k = map(int, input().split())
num_list = [i for i in range(a, b) if a % i == 0 and b % i == 0]
num_list.reverse()
print(number_list[k-1])

### FIXED CODE ###

A, B, K = map(int, input().split())
small = min(A, B)
both = [i for i in range(1, small+1)]
gcd = []

for i in both:
    if A % i == 0 and B % i == 0:
        gcd.append(i)

K -= 1
gcd.sort(reverse=True)
print(gcd[K])
N = int(input())
nums = list(map(int, input().split()))
count = 0
max_count = 0
left = 0
right = 1
while True:
    if nums[right] <= nums[right-1]:
        count +=1
        right += 1
    else:
        count = 0
        right += 1
        left = right - 1
        
    if max_count < count:
        max_count = count
    
    if right == N:
        break
    
print(max_count)

### FIXED CODE ###

N = int(input())
nums = list(map(int, input().split()))
count = 0
max_count = 0
right = 0
while True:
    if right == N-1:
        break
    
    if nums[right+1] <= nums[right]:
        count += 1    
    else:
        count = 0
        
    if max_count < count:
        max_count = count
        
    right += 1
    
print(max_count)
N=int(print())
if N % 2 == 1:
  print((N+1)/2)
else:
  print(N/2)

### FIXED CODE ###

N=int(input())
if N % 2 == 1:
  print(((N+1)/2)/N)
else:
  print((N/2)/N)
-*- coding: utf-8 -*-

import sys
import subprocess
import json
import time
import math
import re
import sqlite3

s = input()
print(s.rfind("Z") - s.find("A") + 1)




### FIXED CODE ###

s = input()
     
a = s.find("A")
b = s.rfind("Z")
     
print(b-a+1)
n = int(input())
c=0
for i in range(1,n):
  a = 0
  while a<n-i:
    a+=i
    c+=1
 
print(c)

### FIXED CODE ###

s = input()

if s[-1] == 's':
  print(s + 'es')
else:
  print(s + 's')
import sys
import math
sys.setrecursionlimit(20000000)


a,b=[int(i) for i in input().split()]

print(a*b//math.gcd(a,b))

### FIXED CODE ###

import sys
sys.setrecursionlimit(20000000)
def gcd(m, n):
    r = m % n
    return gcd(n, r) if r else n

a,b=[int(i) for i in input().split()]

print(a*b//gcd(a,b))
from sys import stdin


N, M = map(int, stdin.readline().rstrip().split())
A_list = [stdin.readline().rstrip().split() for _ in range(M)]

wa_count, ac_count = 0, 0
WA_List = {}  # {prob_id: wa_count}
AC_list = []  # [prob_id]

for i in range(M):
    if A_list[i][1] == 'AC':
        if not A_list[i][0] in AC_list:
            if A_list[i][0] in WA_List:
                wa_count += WA_List[A_list[i][0]]
            ac_count += 1
            AC_list.append(A_list[i][0])
    else:
        if A_list[i][0] in WA_List:
            WA_List[A_list[i][0]] += 1
        else:
            WA_List[A_list[i][0]] = 1

print(ac_count, wa_count)


### FIXED CODE ###

C = str(input())

print(chr(ord(C) + 1))
X=input()
L=X[::-1]
if N % 2 == 1:
    if L==X:
        N=len(X)
        a=int((N-1)/2)
        b=int((N+3)/2)
        Ya=X[0:a]
        LYa=Ya[::-1]
        Yb=X[b-1:N]
        LYb=Yb[::-1]
        if LYa ==Ya and LYb == Yb:
            print("Yes")
        else:
            print("No")
    else:
        print("No")
else:
    print("No")

### FIXED CODE ###

X=input()
L=X[::-1]
N=len(X)
if N % 2 == 1:
    if L==X:
        a=int((N-1)/2)
        b=int((N+3)/2)
        Ya=X[0:a]
        LYa=Ya[::-1]
        Yb=X[b-1:N]
        LYb=Yb[::-1]
        if LYa ==Ya and LYb == Yb:
            print("Yes")
        else:
            print("No")
    else:
        print("No")
else:
    print("No")
text = ''
while(True):
  text += input().lower()
  if text[-1] in ['.', '?', '!']:
      break

count = [0 for i in range(26)]
for c in text:
    if c < 'a'  or c > 'z':
        continue

    count[ord(c) - ord('a')] += 1

for i, c in enumerate(count):
    print('{0} : {1}'.format(chr(i + ord('a')), c))

### FIXED CODE ###

text = ''
while(True):
    try:
        text += input().lower()
    except:
        break

count = [0 for i in range(26)]
for c in text:
    if c < 'a'  or c > 'z':
        continue

    count[ord(c) - ord('a')] += 1

for i, c in enumerate(count):
    print('{0} : {1}'.format(chr(i + ord('a')), c))
N=int(input())
A=[int(i) for i in input()]
maxv=A[0]
minv=A[1]-A[0]
for i in range(N):
  maxv=max(maxv,abs(A[i]-minv))
  minv=min(minv,A[i])
print(maxv)

### FIXED CODE ###

N=int(input())
A=[int(i) for i in input().split()]
A.sort()
print(A[-1]-A[0])
from itertools import combinations, permutations
def inpl(): return list(map(int, input().split()))

N, M = inpl()
G = [[0]*(N+1) for _ in range(N+1)]

for _ in range(M):
    a, b = inpl()
    G[a][b] = 1
    G[b][a] = 1

ans = 0
for X in permutations(range(2, N+1)):
    a = 1
    for i in range(N-1):
        b = X[i]
        if G[a][b] == 0:
            break
        a = b
    else:
        ans += 1

print(ans)

### FIXED CODE ###

# -*- coding: utf-8 -*-
def inpl(): return map(int, input().split())

N, Ma, Mb = inpl()
INF = 4001

DP = [[INF]*(411) for _ in range(411)]
DP[0][0] = 0

for _ in range(N):
    DP2 = [[INF]*(411) for _ in range(411)]
    a, b, c = inpl()
    for i in range(400):
        for j in range(400):
            DP2[i][j] = min(DP[i][j], DP2[i][j])
            DP2[i+a][j+b] = min(DP[i+a][j+b], DP[i][j] + c)
    DP = DP2

x = 1
ans = INF
while Ma*x <= 400 and Mb*x <= 400:
    ans = min(ans, DP[Ma*x][Mb*x])
    
    x += 1

if ans < INF:
    print(ans)
else:
    print(-1)
def main():
    n = int(input())
    if n%2:
        print("No")
        return
    sl = [None]*n
    for i in range(n):
        height, mi = 0, 0
        for si in input():
            if si == "(":
                height += 1
                mi = min(mi, height)
            else:
                height -= 1
                mi = min(mi, height)
            
        sl[i] = [mi, height]
    sl.sort(key=lambda x: -x[0])
    slup = [si for si in sl if si[1] >= 0 and s[0] >= 0]
    sldown = [si for si in sl if si[1] < 0 or s[0] < 0]
    h = 0
    for si in slup:
        if h < 0 :
            print("No")
            return
        h += si[1]
    print(sldown)
    for si in sldown[::-1]:
        if h < 0 or h+si[0] < 0:
            print("No")
            return
        h += si[1]
    if h == 0:
        print("Yes")
    else:
        print("No")
        

if __name__ == "__main__":
    main()

### FIXED CODE ###

def main():
    n = int(input())
    if n == 0:
        print("Yes")
        return
    slup = []
    sldown = []
    for i in range(n):
        height, mi = 0, 0
        for si in input():
            if si == "(":
                height += 1
            else:
                height -= 1
                mi = min(mi, height)
        if height >= 0:
            slup.append([mi, height])
        else:
            sldown.append([mi-height, -height])

    slup.sort(reverse=True)
    sldown.sort(reverse=True)
    if sum([si[1] for si in slup]) + sum([-si[1] for si in sldown]):
        print("No")
        return
    h = 0
    for si in slup:
        if h+si[0] < 0:
            print("No")
            return
        h += si[1]
    h = 0
    for si in sldown:
        if h+si[0] < 0:
            print("No")
            return
        h += si[1]
    print("Yes")
        

if __name__ == "__main__":
    main()
r = input()
print(3 * r**2)

### FIXED CODE ###

r = int(input())
print(3 * r**2 )
n, m = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(m)]

a = [[a[i][0], a[i][1], a[i][2]*(-1)] for i in range(m)]
point = [0] + ['inf']*(n-1)

for j in range(n):
  for i in range(m):
    
    if point[a[i][1]-1] == 'inf' or point[a[i][1]-1] > point[a[i][0]-1] + a[i][2]:
      point[a[i][1]-1] = point[a[i][0]-1] + a[i][2]
    
      if j == (n-1):
        point.append('inf')
        
        
if 'inf' in point:
  print('inf')
else:
  print(-point[n-1])
  

### FIXED CODE ###

import sys
INF=float('inf')
def Bellmanford(n,edges,r):
  d=[INF]*n
  d[r]=0    
  for i in range(n):
    for (u,v,c) in edges:
      if d[u]!=INF and d[u]+c<d[v]:
        d[v]=d[u]+c
        if i==n-1 and v==n-1:
          return 'inf'   
  return (-1)*d[n-1]

N,M=map(int, sys.stdin.readline().split())
Edges=[0]*M

for i in range(M):
  a,b,c=map(int, sys.stdin.readline().split())
  Edges[i]=(a-1,b-1,-c)
    
ans=Bellmanford(N,Edges,0)
print(ans)
h, n = list(map(int, input().split()))
ab = []
for i in range(n):
    a, b = list(map(int, input().split()))
    ab.append((a, b))
ab.sort(key=lambda ab: (ab[0]/ab[1], -ab[0]), reverse=True)

import sys
sys.setrecursionlimit(1500)

mem = [-1 for i in range(h)]
def solve(h):
    best = float('inf')
    for a,b in ab:
        if h - a <= 0:
            val = b
        else:
            if mem[h - a] != -1:
                val = b + mem[h - a]
            else:
                mem[h - a] = solve(h - a)
                val = b + mem[h-a]
        if val < best:
            best = val
        else:
            break
    return best

print(solve(h))


### FIXED CODE ###

h, n = list(map(int, input().split()))
ab = []
for i in range(n):
    a, b = list(map(int, input().split()))
    ab.append((a, b))
ab.sort(key=lambda ab: (ab[0]/ab[1], -ab[0]), reverse=True)

import sys
sys.setrecursionlimit(100000000)

mem = [-1 for i in range(h)]
def solve(h):
    best = float('inf')
    for a,b in ab:
        if h - a <= 0:
            val = b
        else:
            if mem[h - a] != -1:
                val = b + mem[h - a]
            else:
                mem[h - a] = solve(h - a)
                val = b + mem[h-a]
        if val < best:
            best = val
        else:
            break
    return best

print(solve(h))
from __future__ import division, print_function
from sys import stdin

i = 1
for line in sys.stdin:
    if line != 0:
       print "Case %d: %d" % (i, line)
    else:
       break
    i += 1

### FIXED CODE ###

from __future__ import division, print_function
from sys import stdin

i = 1
for line in stdin:
    x = int(line)
    if x == 0:
       break
    print ("Case %d: %d" % (i, x))
    i += 1
nums = input().split()

if numlist[0] = "0"
print(1)

elif numlist[1] = "0"
print(2)

elif numlist[2] = "0"
print(3)

elif numlist[3] = "0"
print(4)

elif numlist[4] = "0"
print(5)


### FIXED CODE ###

# coding: utf-8
# Your code here!
x=input().split()



if(x[0]=="0"):
    print(1)
elif(x[1]=="0"):
    print(2)
elif(x[2]=="0"):
    print(3)
elif(x[3]=="0"):
    print(4)
elif(x[4]=="0"):
    print(5)
nm = input().split()

n = nm[0]
m = nm[1]

if n < m :
	print(No)
else:
	print(Yes)



### FIXED CODE ###

nm = input().split(' ')

n = int(nm[0])
m = int(nm[1])

if n > m :
	print('No')
else:
	print('Yes')
def solve(pick, idx):

    if pick == 0: return 0
    if idx >= n: return -float('inf')

    total = max(A[idx] + solve(pick-1, idx+2), solve(pick, idx+1))

    dp[(pick, idx)] = total
    return total

n = int(input())
A = list(map(int, input().split()))
dp = {}
pick = n//2

print(solve(pick, 0))

### FIXED CODE ###

import sys

sys.setrecursionlimit(10 ** 9)
def solve(pick, idx):

    if pick == 0: return 0
    if idx >= n: return -float('inf')
    if (pick, idx) in dp: return dp[pick, idx]
    if n-idx+2 < pick*2: return -float('inf')
    total = max(A[idx] + solve(pick-1, idx+2), solve(pick, idx+1))

    dp[(pick, idx)] = total
    return total

n = int(input())
A = list(map(int, input().split()))
dp = {}
pick = n//2

print(solve(pick, 0))
import sys
import time
def input():
    return sys.stdin.readline()[:-1]
h,w=map(int,input().split())
a=[list(map(int,input().split())) for i in range(h)]
b=[list(map(int,input().split())) for i in range(h)]
kata=[]
for i in range(h):
    tmp=[]
    for j in range(w):
        tmp.append(abs(a[i][j]-b[i][j]))
    kata.append(tmp)
# print(kata)
tmp=0
for i in range(h):
    tmp=max(tmp,max(kata[i]))
# print(tmp)

dp=[[[0 for i in range(tmp*(h+w)+1)] for j in range(w+1)] for k in range(h+1)]
dp[0][0][kata[0][0]]+=1
i=0
j=0
# print(dp)
while i+j!=h+w-2:
    # print(i,j)
    for k in range(tmp*(h+w)+1):
        if dp[i][j][k]!=0:
            if i+1!=h:
                dp[i+1][j][k+kata[i+1][j]]+=1
                dp[i+1][j][abs(k-kata[i+1][j])]+=1
            if j+1!=w:
                dp[i][j+1][k+kata[i][j+1]]+=1
                dp[i][j+1][abs(k-kata[i][j+1])]+=1
    i-=1
    j+=1
    if i<0:
        i=abs(i+j)+1
        j=0
    while i>=h:
        i-=1
        j+=1
    # time.sleep(1)
# print(dp[1][0])
# print(dp[0][1])
# print(dp[h-1][w-1])
for i in range(tmp*(h+w)+1):
    if dp[h-1][w-1][i]!=0:
        print(i)
        quit()

### FIXED CODE ###

import sys

input = sys.stdin.buffer.readline

h, w = map(int, input().split())
AA = [list(map(int, input().split())) for _ in range(h)]
BB = [list(map(int, input().split())) for _ in range(h)]

kouho = [[0] * (w) for _ in range(h)]
delta = abs(AA[0][0] - BB[0][0])
kouho[0][0] |= 1 << delta
for y in range(h):
    for x in range(w):
        nx = x + 1
        ny = y
        if nx < w:
            delta = abs(AA[ny][nx] - BB[ny][nx])
            temp = 0
            for i in range(1, delta + 1):
                if (kouho[y][x] >> i) % 2:
                    temp |= 1 << (delta - i)
            # print(x,y,kouho[y][x],temp,delta)
            kouho[ny][nx] |= kouho[y][x] << delta
            kouho[ny][nx] |= kouho[y][x] >> delta
            kouho[ny][nx] |= temp

        nx = x
        ny = y + 1
        if ny < h:
            delta = abs(AA[ny][nx] - BB[ny][nx])
            temp = 0
            for i in range(1, delta + 1):
                if (kouho[y][x] >> i) % 2:
                    temp |= 1 << (delta - i)
            # print(x,y,kouho[y][x],temp,delta)
            kouho[ny][nx] |= kouho[y][x] << delta
            kouho[ny][nx] |= kouho[y][x] >> delta
            kouho[ny][nx] |= temp
# print(kouho)
for i in range(81):
    if (kouho[h - 1][w - 1] >> i) % 2:
        print(i)
        exit()
N, P = map(int,input().split())
if N == 1:
    print(P)
    exit(0)

ans = 1
k = 1
while k**N <= P:
    if P%(k**N)==0:
        ans = k
    k += 1

print(ans)

### FIXED CODE ###

from collections import Counter
import math

N, P = map(int,input().split())
if N >= 41:
    print(1)
    exit(0)
if N >= P:
    print(1)
    exit(0)
if N == 1:
    print(P)
    exit(0)
if N == 2:
    M = P
    Q = []
    k = 2
    while k*k <= M:
        if M%k == 0:
            M //= k
            Q.append(k)
        else:
            k += 1
    if M > 1:
        Q.append(M)
    R = Counter(Q)
    ans = 1
    for k in R:
        if R[k] >= 2:
            ans *= k**(R[k]//2)
    print(ans)
    exit(0)

ans = 1
k = 1
while pow(k,N) <= P:
    if P%pow(k,N)==0:
        ans = k
    k += 1

print(ans)