Harryxun/stf_run huggingface dataset:
from heapq import *
import numpy as np

class vertex:
    def __init__(self):
        self.list_adj = []  # list of [no_adjnode, a, b]

    def add_edge(self, adj):
        self.list_adj.append(adj)

n, m, s, t = map(int, input().split())
# zero start
s -= 1
t -= 1

# 
vertices = []
for i in range(n):
    v = vertex()
    vertices.append(v)

print(n, m, s, t)
# load node
for k in range(m):
    u, v, a, b = map(int, input().split())
    vertices[u-1].add_edge([v-1, a, b])
    vertices[v-1].add_edge([u-1, a, b])


#print('-----------------')

#print(n, m, s, t)
#for i in range(n):
#    print(vertices[i].list_adj)

mode = 0
# return list of [no_adj, cost]
def get_adj(v):
    res = []
    for adj in v.list_adj:
        res.append([adj[0], adj[1+mode]])
    return res

#print('show adjcent(a)')
#for k in range(n):
#    print(get_adj(vertices[k]))

mode = 1
#print('show adjcent(b)')
#for k in range(n):
#    print(get_adj(vertices[k]))

def dijkstra(s):
    inf = int(10e20)
    dist = [inf] * n
    h = []
    heappush(h, (0, s))
    while len(h) > 0:
        # pop 1 node
        dv, v = heappop(h)
        # if already decided, continue
        if dist[v] < inf:
            continue
        dist[v] = dv
        # push adjcent node
        list_adj = get_adj(vertices[v])
        for adj in list_adj:
            if dist[adj[0]] == inf:
                heappush(h, (dv + adj[1], adj[0]))
                pass
        pass
    return dist

mode = 0
dist_a = dijkstra(s)
mode = 1
dist_b = dijkstra(t)
#cost = []
#for k in range(len(dist_a)):
#    cost.append(dist_a[k] + dist_b[k])
cost = np.array(dist_a,dtype = 'int') + np.array(dist_b,dtype = 'int')
cost = np.array(cost, dtype='int')
#print(cost)

m0 = int(10e15)
for i in range(n):
    cost_available = cost[i:]
    print(m0-np.amin(cost_available))

### FIXED CODE ###

a,b = input().split()
a = int(a)
b = int(b)

if a + b == 15:
  print('+')
elif a * b == 15:
  print('*')
else:
  print('x')
A, B, C = map(int, input.split())

print(max(0, C-(A-B)))





### FIXED CODE ###

A, B, C = map(int, input().split())

print(max(0, C-(A-B)))
N, K = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
M = 10**9 + 7
A = sorted(A, key=abs, reverse=1)
# 負の数になる場合
if max(A) < 0:
    result = 1
    for i in range(K):
        result = result * A[-i-1] % M
    print(result)
    exit()

minimum_minus_id = K
minimum_plus_id = K
minus_count = 0

for i in range(K):
    if A[i] < 0:
        minus_count += 1
        minimum_minus_id = i
    else:
        minimum_plus_id = i
result = 1

if minus_count%2 == 1:
    # 一番小さい負の数を正の数にするか、一番小さい正の数を負の数にするか
    second_minus_id = N
    second_plus_id = N

    for i in range(K, N):
        if A[i] >= 0:
            second_plus_id = i
            break
    for i in range(K, N):
        if A[i] < 0:
            second_minus_id = i
            break
    if second_minus_id == N or minimum_plus_id == K:
        A[minimum_minus_id] = A[second_plus_id]
    elif second_plus_id == N:
        A[minimum_plus_id] = A[second_minus_id]
    elif minimum_minus_id == K:
        pass
    else:
        if A[minimum_minus_id] * A[second_minus_id ] > A[minimum_plus_id] * A[second_plus_id]:
            A[minimum_plus_id] = A[second_minus_id]
        else:
            A[minimum_minus_id] = A[second_plus_id]

for i in range(K):
    result = result * A[i] % M
print(result)

### FIXED CODE ###

n, k = map(int, input().split())
a_list = list(map(int, input().split()))
mod = 10**9+7
a_list.sort()
ans = 1
if k % 2 == 1 and a_list[-1] < 0:
    for i in range(k):
        ans *= a_list[n - 1 - i]
        ans %= mod
else:
    l = 0
    r = -1
    mlt1 = a_list[0] * a_list[1]
    mlt2 = a_list[-2] * a_list[-1]
    count = 0
    while True:
        if count == k:
            break
        elif count == k - 1:
            ans *= a_list[r] % mod
            ans %= mod
            break
        if mlt1 >= mlt2:
            ans *= mlt1 % mod
            l += 2
            count += 2
            if l <= n - 2:
                mlt1 = a_list[l + 1] * a_list[l]
        else:
            ans *= a_list[r] % mod
            r -= 1
            count += 1
            if r >= - n + 1:
                mlt2 = a_list[r - 1] * a_list[r]
        ans %= mod
print(ans)
N,Q=map(int,input().split())
s=["x"]+list(input())+["x"]
#print(s)
L=[]
for i in range(Q):
    t=list(input().split())
    L.append(t)
#print(L)
h=N
l=1

while abs(h-l)>2:
    Mid=(h+l)//2
    P=Mid
    for i in range(Q):
        if s[P]==L[i][0]:
            if L[i][1]=="L":
                P-=1
            else:
                P+=1
                
    if P==0:
        l=Mid
    else:
        h=Mid
#print(l,h)
for j in range(4):
    M=l-1+j
    P=M
    for i in range(Q):
        if s[P]==L[i][0]:
            #print("S",j,P,i)
            if L[i][1]=="R":
                P+=1
            else:
                P-=1
    #print("A",M,P)
    if P!=0:
        LEFT=l-1+j
        break

h=N
l=1

while abs(h-l)>2:
    Mid=(h+l)//2
    P=Mid
    for i in range(Q):
        if s[P]==L[i][0]:
            if L[i][1]=="L":
                P-=1
            else:
                P+=1
                
    if P==N+1:
        h=Mid
    else:
        l=Mid
for j in range(4):
    M=h+1-j
    P=M
    for i in range(Q):
        if s[P]==L[i][0]:
            if L[i][1]=="L":
                P-=1
            else:
                P+=1
    if P!=N+1:
        RIGHT=h+1-j
        break
        
print(max(0,RIGHT - LEFT +1))
#print(RIGHT,LEFT)

### FIXED CODE ###

N,Q=map(int,input().split())
s=["x"]+list(input())+["x"]
#print(s)
L=[]
for i in range(Q):
    t=list(input().split())
    L.append(t)
#print(L)
h=N
l=1
LEFT=-10
RIGHT=-10
while abs(h-l)>2:
    Mid=(h+l)//2
    P=Mid
    for i in range(Q):
        if s[P]==L[i][0]:
            if L[i][1]=="L":
                P-=1
            else:
                P+=1
                
    if P==0:
        l=Mid
    else:
        h=Mid
#print(l,h)
for j in range(4):
    M=l-1+j
    P=M
    for i in range(Q):
        if s[P]==L[i][0]:
            #print("S",j,P,i)
            if L[i][1]=="R":
                P+=1
            else:
                P-=1
    #print("A",M,P)
    if P!=0:
        LEFT=l-1+j
        break

h=N
l=1

while abs(h-l)>2:
    Mid=(h+l)//2
    P=Mid
    for i in range(Q):
        if s[P]==L[i][0]:
            if L[i][1]=="L":
                P-=1
            else:
                P+=1
                
    if P==N+1:
        h=Mid
    else:
        l=Mid
for j in range(4):
    M=h+1-j
    P=M
    for i in range(Q):
        if s[P]==L[i][0]:
            if L[i][1]=="L":
                P-=1
            else:
                P+=1
    if P!=N+1:
        RIGHT=h+1-j
        break
if LEFT==-10 or RIGHT==-10:
    print(0)
else:
    print(max(0,RIGHT - LEFT +1))
#print(RIGHT,LEFT)
n = int(raw_input())
deck = [i for i in range(1,2*n+1)]
m = int(raw_input())
for i in range(m):
    k = int(raw_input())
    if k == 0:
        deck1 = []
        for j in range(n):
            deck1 += deck[i]+deck[n+i]
        deck = deck1
    elif:
       deck = deck[k+1:]+deck[:k+1]
for i in deck:
    print deck

### FIXED CODE ###

n = int(raw_input())
d = [i for i in range(1,2*n+1)]
m = int(raw_input())
for i in range(m):
    k = int(raw_input())
    if k == 0:
        for j in range(n):
            d += [d[j]]+[d[n+j]]
        d = d[2*n:]
    else:
        d = d[k:]+d[:k]
for i in d:
    print i
import math
A, B, C, D = map(int, input().split())

def multiple(X, Y, Z):
    min_z = math.ceil(X / Z)
    max_z = math.floor(Y / Z) 
    z_num = max_z - min_z + 1
    return z_num

num_c = multiple(A, B, C)
num_d = multiple(A, B, D)

lem = int((C * D) / math.gcd(C, D)) 
num_lem = multiple(A, B, lem)

print(B - A + 1 - num_c - num_d + num_lem)


### FIXED CODE ###

A, B, C, D = map(int, input().split())

def multiple(X, Y, Z):
    # 天井関数math.ceilが誤差でおかしくなってるから組み込み関数を使う
    if X % Z != 0:
        min_z = X // Z + 1
    else:
        min_z = X / Z
    max_z = Y // Z
    num_z = max_z - min_z + 1
    return int(num_z)

def gcd(X, Y):
    while Y!= 0:
        X, Y = Y, X % Y
    return X

if C == 1 or D == 1:
    print(0)
else:
    num_c = multiple(A, B, C)
    num_d = multiple(A, B, D)
    lcm = int((C * D) / gcd(C, D)) 
    num_lcm = multiple(A, B, lcm)
    print(B - A + 1 - num_c - num_d + num_lcm)
import math

n,q=map(int,input().split())
S=input()
A=[]
flag=0
for i in range(n):
    if S[i]=="A":
        flag=1
    elif S[i]=="C":
        if flag==1:
            A.append(i-1)
        flag=0
    else:
        flag=0
a=len(A)
print(A)
        
for i in range(q):
    l,r=map(int,input().split())
    l-=1
    r-=1
    low=0
    high=a-1
    if A[0]>=l:
        cntl=0
    elif A[a-1]<l:
        print(0)
        continue
    else:
        while high-low>1:
            now=math.ceil((high+low)//2)
            if A[now]<=l:
                high=now
            else:
                low=now
        cntl=high
    low=0
    high=a-1
    if A[a-1]+1<=r:
        cntr=a-1
    elif A[0]+1>r:
        print(0)
        continue
    else:
        while high-low>1:
            now=(high+low)//2
            if A[now]+1<=r:
                low=now
            else:
                high=now
        cntr=low
    print(cntr-cntl+1)

### FIXED CODE ###

n,q=map(int,input().split())
S=input()
A=[]
flag=0
cnt=0
for i in range(n):
    if S[i]=="A":
        flag=1
    elif S[i]=="C":
        if flag==1:
            cnt+=1
        flag=0
    else:
        flag=0
    A.append(cnt)
    
for i in range(q):
    l,r=map(int,input().split())
    l-=1
    r-=1
    print(A[r]-A[l])
N=input()
if not N:
	break
a=list(map(int, input().split(" ")))
ans=1
for v in a:
	ans*=v
if 1000000000000000000 < ans:
	ans = -1
print(ans)


### FIXED CODE ###

N=input()
a=list(map(int, input().split()))
#print(a)
ans=1
for v in a:
	ans*=v
	if 1000000000000000000 < ans:
		ans = -1
		break
if any([v==0 for v in a]):
	ans=0
print(ans)
n,a,b=map(int,input().split())
ans=0
for i in range(n+1):
    if a<=sum(list(map(int,list(str(i))))<=b:
        ans+=i
print(ans)


### FIXED CODE ###

n,a,b=map(int,input().split())
ans=0
for i in range(n+1):
    if a<=sum(list(map(int,list(str(i)))))<=b:
        ans+=i
print(ans)
N,L = map(int, input().split())
S = []
for i in range(N):
  S.append(input())
S.sort()
ans = ''
for i in range(N):
  ans += ans + S[i]
print(ans)


### FIXED CODE ###

N,L = map(int, input().split())
S = []
for i in range(N):
  S.append(input())
S.sort()
ans = ''
for i in range(N):
  ans += S[i]
print(ans)
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

n=int(input())
v=lnii()
v.sort()

ans=v[0]
for i in range(1,n):
  ans=(ans+v[i])/2

print(ans

### FIXED CODE ###

n=int(input())
v=list(map(int, input().split()))
vv=sorted(v)
for i in range(n-2):
    vv[i+1] = (vv[i]+vv[i+1]) / 2
print((vv[n-2]+vv[n-1])/2)
X, A, B = map(int, input())
if A-B > X:
  print('dangerous')
  exit()
elif A-B <= 0:
  print('delicious')
  exit()
print('safe')

### FIXED CODE ###

X, A, B = map(int, input().split())
if B-A > X:
  print('dangerous')
  exit()
elif B <= A:
  print('delicious')
  exit()
print('safe')
S = str(input())
N = len(S)
B = S[:((N-1)/2)]
C = S[((N+3)/2):]
if S == S[-1]:
    if S[:((N-1)/2)] == B[-1]:
        if C[-1] == S[((N+3)/2):]:
            print("Yes")
        else:
            print("No")
    else:
            print("No")
else:
            print("No")

### FIXED CODE ###

S = str(input())
N = int(len(S))
B = S[:(N-1)//2]
C = S[(((N+3)//2)-1):]

if S == S[::-1]:
    if B == B[::-1]:
        if C[::-1] == C:
            print("Yes")
        else:
            print("No")
    else:
            print("No")
else:
            print("No")
N,S=map(int,input().split())
A=list(map(int,input().split()))
mod=998244353

dp=[[0]*(S+1) for _ in range(N)]

dp[0][0]=2
dp[0][A[0]]=1
for i in range(N-1):
    for j in range(S+1):
        dp[i+1][j]+=dp[i][j]*2
        dp[i+1][j]%=mod
        if j+A[i+1]<=S:
            dp[i+1][j+A[i+1]]+=dp[i][j]
            dp[i+1][j+A[i+1]]%=mod

print(dp[N-1][S]%mod)

### FIXED CODE ###

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

dp=[[0]*(S+1) for _ in range(N)]

dp[0][0]=2
if A[0]<=S:
  dp[0][A[0]]=1
for i in range(N-1):
    for j in range(S+1):
        dp[i+1][j]+=dp[i][j]*2
        dp[i+1][j]%=mod
        if j+A[i+1]<=S:
            dp[i+1][j+A[i+1]]+=dp[i][j]
            dp[i+1][j+A[i+1]]%=mod

print(dp[N-1][S]%mod)
A, B = map(int,input().split())

one = A/0.08
two = (A+1)/0.08
three = B/0.1
four = (B+1)/0.1

print(one, two, three, four)


if two < three or one > four:
    kai = -1
if three <= one and four >= one:
    kai = one
if one < three and four <= two:
    kai = three

print(kai)
    

### FIXED CODE ###

import math
A, B = map(int,input().split())

count = 0

for n in range(10000):
    za = n*0.08
    zb = n*0.1
    count += 1
    if A == math.floor(za) and B == math.floor(zb):
        print(n)
        break


if count == 10000:
    print(-1)
N,A,B=map(int,input().split())
rest = N-A-B
if A ==0:
    print(0)
elif N>A+B:
    answer = A + rest
    print(answer)
elif A<=N<=A+B:
    print(A)

### FIXED CODE ###

S =list(input())
if S[0] =="B" and S[1]=="B" and S[2]=="B":
    print("No")
elif S[0] =="A" and S[1]=="A" and S[2]=="A":
    print("No")
else:
    print("Yes")
import sys
n, m = map(int, input().split())
x = list(map(int, input().split()))
a = []

if m == 1:
    print(0)
    sys.exit()

#x.sort()
list.sort(x)
#print(x)

for i in range(1, m):
    a.append(x[i] - x[i-1])

list.sort(a, reverse=True)
#print(a)

count = max(x) - min(x)
for i in range(n-1):
    if len(a) == 0:
        break
    count -= a[i]

print(count)


### FIXED CODE ###

import sys
n, m = map(int, input().split())
x = list(map(int, input().split()))
a = []

if m == 1:
    print(0)
    sys.exit()

#x.sort()
list.sort(x)
#print(x)

for i in range(1, m):
    a.append(x[i] - x[i-1])

#list.sort(a, reverse=True)
a.sort()
#print(a)

count = max(x) - min(x)
for i in range(n-1):
    if len(a) == 0:
        break
    a.pop()
#    count -= a[i]

#print(count)
print(sum(a))
a,b,c = map(int,input().split())
if a == b:
    i = 1
if b == c:
    j = 1
if c == a:
    k = 1
if a == b & b == c:
    l = -1
print(3-(i+j+k+l))

### FIXED CODE ###

a,b,c = map(int,input().split())
i,j,k,l = 0,0,0,0
if a == b:
    i = 1
if b == c:
    j = 1
if c == a:
    k = 1
if a == b & b == c:
    l = -1
print(3-(i+j+k+l))
def main(li):
    count = 0
    for i in range(len(li)):
        if li[i] != i + 1:
            count += 1
    if count == 2 or count == 0:
      return True
   	else:
      return False


if __name__ == '__main__':
    li = list(map(int, input().split()))
    if main(li):
        print('YES')
    else:
        print('NO')


### FIXED CODE ###

def main(li):
    count = 0
    for i in range(len(li)):
        if li[i] != i + 1:
            count += 1
    if count in [0, 2]:
        return True
    else:
        False


if __name__ == '__main__':
    n = int(input())
    li = list(map(int, input().split()))
    if main(li):
        print('YES')
    else:
        print('NO')
a,b,c = map(int,input().split())
if a[-1:]==b[:1] and b[-1:]==c[:1]:
    print("YES")
else:
    print("NO")

### FIXED CODE ###

a,b,c = map(str,input().split())
if a[-1:]==b[:1] and b[-1:]==c[:1]:
    print("YES")
else:
    print("NO")
a=int(input())
b=input.split()
m=0
s=0
while m<a:
    s=s+int(b[m])
    m=m+1
if s<10**18:
    print(-1)
else:
    print(s)


### FIXED CODE ###

a=int(input())
b=input().split(' ')
m=0
s=1
i=0
o=0
while i<a:
    if int(b[i])==0:
        print(0)
        o=o+1
    i=i+1
while m<a and o==0:
    s=s*int(b[m])
    m=m+1
    if s>10**18 and o==0:
        print(-1)
        o=o+1
        break

if o==0:
    print(s)
import sys
s = str(input())
i = 0
while i < len(s):
    if i + 5 <= len(s) and s[i:i+5] == 'dream': #now dream or dreamer
        if i + 6 <= len(s) and s[i+5] == 'e' and s[i+6] == 'r': #now dreamer or now dream and next is erase or eraser
            if s[i+7] == 'a': #next erase or eraser, now dream
                i += 5
            else: #now dreamer
                i += 7
        else: #now dream
            i += 5
    elif i + 5 <= len(s) and s[i:i+5] == 'erase':
        if i + 5 <= len(s) and s[i+5] == 'r': #now eraser
            i += 6
        else: #now erase
            i += 5
    else:
        print('NO')
        sys.exit()
print('YES')


### FIXED CODE ###

import sys
s = str(input())
i = 0
while i < len(s):
    if i + 5 <= len(s) and s[i:i+5] == 'dream': #now dream or dreamer
        if i + 6 < len(s) and s[i+5] == 'e' and s[i+6] == 'r': #now dreamer or now dream and next is erase or eraser
            if i + 7 < len(s) and s[i+7] == 'a': #next erase or eraser, now dream
                i += 5
            else: #now dreamer
                i += 7
        else: #now dream
            i += 5
    elif i + 5 <= len(s) and s[i:i+5] == 'erase':
        if i + 5 < len(s) and s[i+5] == 'r': #now eraser
            i += 6
        else: #now erase
            i += 5
    else:
        print('NO')
        sys.exit()
print('YES')
import sys


def input():
    return sys.stdin.readline().strip()


class Combination:
    """
    O(n)の前計算を1回行うことで，O(1)でnCr mod mを求められる
    n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
    使用例：
    comb = Combination(1000000)
    print(comb(5, 3))  # 10
    """

    def __init__(self, n_max, mod=10 ** 9 + 7):
        self.mod = mod
        self.modinv = self.make_modinv_list(n_max)
        self.fac, self.facinv = self.make_factorial_list(n_max)

    def __call__(self, n, r):
        if n < r:
            return 0
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n - r] % self.mod

    def make_factorial_list(self, n):
        # 階乗のリストと階乗のmod逆元のリストを返す O(n)
        # self.make_modinv_list()が先に実行されている必要がある
        fac = [1]
        facinv = [1]
        for i in range(1, n + 1):
            fac.append(fac[i - 1] * i % self.mod)
            facinv.append(facinv[i - 1] * self.modinv[i] % self.mod)
        return fac, facinv

    def make_modinv_list(self, n):
        # 0からnまでのmod逆元のリストを返す O(n)
        modinv = [0] * (n + 1)
        modinv[1] = 1
        for i in range(2, n + 1):
            modinv[i] = self.mod - self.mod // i * modinv[self.mod % i] % self.mod
        return modinv


MOD = 10 ** 9 + 7


def main():
    L = list(input())

    def cnt(s):
        if len(s) == 1:
            if s[0] == "1":
                return 3
            else:
                return 1
        if s[0] == "0":
            return cnt(s[1:]) % MOD
        else:
            return (cnt(s[1:]) % MOD) * 2 + 3 ** (len(s) - 1) % MOD

    answer = cnt(L) % MOD

    print(answer)


if __name__ == "__main__":
    main()


### FIXED CODE ###

import sys
import queue


def input():
    return sys.stdin.readline().strip()


sys.setrecursionlimit(20000000)
MOD = 10 ** 9 + 7


def main():
    L = list(input())

    pow = [0] * (len(L) + 1)
    pow[0] = 1
    for i in range(1, len(L) + 1):
        pow[i] = pow[i - 1] * 3 % MOD
    N = len(L)
    if L[-1] == "0":
        answer = 1
    else:
        answer = 3
    for i in range(1, N):
        if L[N - i - 1] == "1":
            answer = answer * 2 + pow[i]
            answer %= MOD
        else:
            continue
    print(answer)


if __name__ == "__main__":
    main()
(N, M), *miti = [[*map(int, line.split())] for line in open(0)]

# print(miti)

A = [list() for _ in range(N+1)]
for m in miti:
    a, b = m
    A[a].append(b)
    A[b].append(a)

# print(A)

ans = [0] * (N + 1)
dist = [N] * (N + 1)


def check(p, d):
    for t in A[p]:
        if d + 1 < dist[t]:
            dist[t] = d + 1
            ans[t] = p
            check(t, d + 1)


dist[1] = 0
ans[1] = 88888
check(1, 0)

dist = dist[1:]
ans = ans[2:]
if all(d < N for d in dist):
    print("Yes")
    for a in ans:
        print(a)
else:
    print("No")

### FIXED CODE ###

(N, M), *miti = [[*map(int, line.split())] for line in open(0)]

# print(miti)

A = [list() for _ in range(N+1)]
for m in miti:
    a, b = m
    A[a].append(b)
    A[b].append(a)

# print(A)

ans = [0] * (N + 1)
dist = [N] * (N + 1)
R = [list() for _ in range(N)]

dist[1] = 0
R[0].append(1)
ans[1] = 88888
for i in range(N):
    for p in R[i]:
        for t in A[p]:
            if i + 1 < dist[t]:
                dist[t] = i + 1
                R[i+1].append(t)
                ans[t] = p

dist = dist[1:]
ans = ans[2:]
if all(d < N for d in dist):
    print("Yes")
    for a in ans:
        print(a)
else:
    print("No")
A, B, K = input().split()

A = int(A)
B = int(B)
K = int(K)

for i = 0; i < K; i++:
	if i % 2 == 0:
		B += A /2
		A /= 2
	else:
		A += B / 2
		B /= 2
print(A + " " + B)


### FIXED CODE ###

A, B, K = input().split()

A = int(A)
B = int(B)
K = int(K)

for i in range(K):
	if i % 2 == 0:
		A //= 2
		B += A 
	else:
		B //= 2
		A += B 
print(str(A) + " " + str(B))
H,W = map(int, input().split())
As = []
for i in range(H):
    As.append(list(map(int, input().split())))
diffs = []
for i in range(H):
    bs = list(map(int, input().split()))
    diffs.append([a-b for a,b in zip(As[i],bs)])
# max_d = 0
# for i in range(H):
#     for j in range(W):
#         max_d = max(max_d,abs(diffs[i][j]))

# M = max_d*(H+W)

# 左右の対称性から、がんばったら80を超えることはなくないか？
M = 160

# (i,j)において、偏りがkになることがあるか
diff_s = abs(diffs[0][0])
# 初期値
dp = [[[False]*M for i in range(W)] for j in range(H)]
dp[0][0][diff_s] = True
# もらうDP
for i in range(H):
    for j in range(W):
        # 行方向
        if i+1 < H:
            d = abs(diffs[i+1][j])
            for k in range(M):
                x = dp[i][j][k]
                if x:
                    dp[i+1][j][d+k] = x
                    dp[i+1][j][abs(d-k)] = x
        # 列方向
        if j+1 < W:
            d = abs(diffs[i][j+1])
            for k in range(M):
                x = dp[i][j][k]
                if x:                
                    dp[i][j+1][d+k] = x
                    dp[i][j+1][abs(d-k)] = x
        # print(i,j,diffs[i][j],dp)

ans = 0
for i,b in enumerate(dp[i][j]):
    if b:
        print(i)
        exit()

### FIXED CODE ###

M = 6400*4
mid = M//2
INF = 10**18

H,W = map(int, input().split())
As = []
for i in range(H):
    As.append(list(map(int, input().split())))
diffs = []
for i in range(H):
    bs = list(map(int, input().split()))
    diffs.append([abs(a-b) for a,b in zip(As[i],bs)])

# bitset高速化
# 初期値
dp = [[0]*W for j in range(H)]
dp[0][0] = 1 << (mid+diffs[0][0]) #プラスマイナス考慮して、下駄をはかせる
for i in range(H):
    for j in range(W):
        # 行方向
        if i+1 < H:
            d = diffs[i+1][j]
            dp[i+1][j] |= dp[i][j] >> d  
            dp[i+1][j] |= dp[i][j] << d  
        # 列方向
        if j+1 < W:
            d = diffs[i][j+1]
            dp[i][j+1] |= dp[i][j] >> d
            dp[i][j+1] |= dp[i][j] << d

ans = INF
for i in range(M):
    if dp[H-1][W-1] >> i & 1:
        # print(i-mid)
        ans = min(ans, abs(i-mid))
print(ans)
N, Q = map(int, input().split())
AB = [tuple(map(int, input().split())) for _ in range(N-1)]
PX = [tuple(map(int, input().split())) for _ in range(Q)]
T = [[] for _ in range(N+1)]
for a, b in AB:
    T[a].append(b)
    T[b].append(a)

C = [0 for _ in range(N+1)]
for p, x in PX:
    C[p] += x


def rec(v, p=0):
    for t in T[v]:
        if t == p:
            continue
        C[t] += C[v]
        rec(t, v)


rec(1)
print(*C[1:])


### FIXED CODE ###

from collections import deque

N, Q = map(int, input().split())
AB = [tuple(map(int, input().split())) for _ in range(N-1)]
PX = [tuple(map(int, input().split())) for _ in range(Q)]
T = [[] for _ in range(N+1)]
for a, b in AB:
    T[a].append(b)
    T[b].append(a)

C = [0 for _ in range(N+1)]
for p, x in PX:
    C[p] += x

S = deque([(1, 0)])
while S:
    v, p = S.popleft()
    for t in T[v]:
        if t == p:
            continue
        C[t] += C[v]
        S.append((t, v))

print(*C[1:])
N = int(input())

s=[]
flag = 0
for i in range(N):
  s.append(input())
num = 0

while(len(s) != 0):
  for i in range(len(s)):
    if(s[0] == s[i]):
      flag += 1
  for i in range(flag):
    s.remove(s[0])
  num += 1
print(num)

### FIXED CODE ###

import collections
N = int(input())
s=[]
for i in range(N):
  s.append(input())
c = collections.Counter(s)
 
print(len(c))