Harryxun/stf_run huggingface dataset:
N, M = map(int, input().split())
xrd = [[] for i in range(N)]
x = [None]*N


def check(s):
    global xrd,x
    for t, d in xrd[s]:
        if x[t] is None:
            x[t] = x[s] + d
            check(t)
        else:
            if x[t] != x[s] + d:
                print("No")
                exit()


for i in range(M):
    L, R, D = map(int, input().split())
    xrd[L-1].append([R-1, D])
    xrd[R-1].append([L-1, -D])

for i in range(N):
    if x[i] is None:
        x[i] = 0
        check(i)


print("Yes")


### FIXED CODE ###

import sys
sys.setrecursionlimit(200002)

N, M = map(int, input().split())
G = [[] for _ in range(N)]
x = [None] * N

def fail():
    print("No")
    exit()

def dfs(s):
    global x, G
    for t, d in G[s]:
        if x[t] is None:
            x[t] = x[s] + d
            dfs(t)
        else:
            if x[t] != x[s] + d:
                fail()

for _ in range(M):
    L, R, D = map(int, input().split())
    G[L-1].append([R-1,  D])
    G[R-1].append([L-1, -D])

for i in range(N):
    if x[i] is None:
        x[i] = 0
        dfs(i)

print("Yes")
n, m, q = list(map(int, input().split(' ')))

aq = [None] * q
bq = [None] * q
cq = [None] * q
dq = [None] * q
for i in range(q):
    aq[i], bq[i], cq[i], dq[i] = list(map(int, input().split(' ')))

result = 0

def dfs(i, ary):
    global result
    if i == n:
        val = 0
        for j in range(q):
            if ary[bq[j] - 1] - ary[aq[j] - 1] == cq[j]:
                val += dq[i]
        if result < val:
            result = val
    else:
        if ary == []:
            for c in range(1, m + 1):
                dfs(i + 1, [c])
        else:
            l = ary[-1]
            for c in range(l, m + 1):
                dfs(i + 1, ary + [c])

dfs(0, [])

print(result)



### FIXED CODE ###

n, m, q = list(map(int, input().split(' ')))

aq = [None] * q
bq = [None] * q
cq = [None] * q
dq = [None] * q
for i in range(q):
    aq[i], bq[i], cq[i], dq[i] = list(map(int, input().split(' ')))

result = 0

def dfs(i, ary):
    global result
    if i == n:
        val = 0
        for j in range(q):
            if ary[bq[j] - 1] - ary[aq[j] - 1] == cq[j]:
                val += dq[j]
        if result < val:
            result = val
    else:
        if ary == []:
            for c in range(1, m + 1):
                dfs(i + 1, [c])
        else:
            l = ary[-1]
            for c in range(l, m + 1):
                dfs(i + 1, ary + [c])

dfs(0, [])

print(result)
from bisect import bisect_left
n=int(input())
A=sorted(list(map(int, input())))
amax=max(A)
half=amax/2

ans=0
now=amax
for a in A:
  if abs(a-half)<=now:
    now=abs(a-half)
    ans=a
print(amax, ans)

### FIXED CODE ###


n=int(input())
A=sorted(list(map(int, input().split())))
amax=max(A)
half=amax/2

ans=0
now=amax
for a in A:
  if abs(a-half)<=now and a<amax:
    now=abs(a-half)
    ans=a
print(amax, ans)
N=int(input())
s=list(input())

#毎ステップ毎にカウントする処理→TLE
# ans=10**6
# for i in range(1,N):
#   ans=min(ans,s[:i-1].count("W")+s[i+1:].count("E"))
# print(ans)
ans=[]
ans[0]=s[1:].count("E")
tmp=ans[0]
for i in range(1:N):
  if s[i]=="E":
    tmp-=1
  if s[i-1]=="W":
    tmp+=1
  ans.append(tmp)
print(min(ans))

### FIXED CODE ###

n=int(input())
s=input()

#毎ステップ毎にカウントする処理→TLE
# ans=10**6
# for i in range(1,N):
#   ans=min(ans,s[:i-1].count("W")+s[i+1:].count("E"))
# print(ans)
ans=[]
ans.append(s[1:].count("E"))
tmp=ans[0]
for i in range(1,n):
  if s[i]=="E":
    tmp-=1
  if s[i-1]=="W":
    tmp+=1
  ans.append(tmp)
print(min(ans))
n=int(input())
l=[map(int,input().split)]
l.sort()
ans=0
for i in range(0,n-2):
  for j in range(i+1,n-1):
    for k in range(j+1,n):
      if l[k]<l[i]+l[j]:
        ans+=1
        
print(ans)        
        

### FIXED CODE ###

import bisect
n=int(input())
l=list(map(int,input().split()))
l.sort()
ans=0
for i in range(0,n-1):
  for j in range(i+1,n):
    x=l[i]+l[j]
    y=bisect.bisect_left(l,x)-1
    ans+=max((y-j),0)
    
print(ans)
def main():
  n, m = map(int, input().split())
  shops = sorted([list(map(int, input().split())) for i in range(n)])
  
  cost = 0
  got = 0
  for shop in shops:
    if got + shop[1] <= m:
      got += shop[1]
      cost += shop[0] * shop[1]
    else:
      cost += (m - got) * shop[0]
      break
  print(cost)
  

if __init__ == '__main__':
  main()

### FIXED CODE ###

n, m = map(int, input().split())
shops = sorted([list(map(int, input().split())) for i in range(n)])

def main():
  cost = 0
  got = 0
  for shop in shops:
    if got + shop[1] <= m:
      got += shop[1]
      cost += shop[0] * shop[1]
    else:
      cost += (m - got) * shop[0]
      return cost
  return cost
  
print(main())
Row = int(input())
List = []
for i in range (Row):
  List.append(int(input()))
s_l = set(List)
print(len(s_l))

### FIXED CODE ###

Row = int(input())
List = []
for i in range (Row):
  List.append(input())
s_l = set(List)
print(len(s_l))
n = int(input())
m = int(input())
print((n-1)*(m-1))

### FIXED CODE ###

n,m = map(int,input().split())
print((n-1)*(m-1))
import sys
L = int(sys.stdin.readline().rstrip())

if L == 1:
  h = int(sys.stdin.readline().rstrip())
else:
  h = list(map(int, sys.stdin.readline().rstrip().split()))

L = N
if L == 0:
  ans = 0
elif L == 1:
  ans = N - h
elif L == 2:
  ans = N - max(h)
  
else:
  grad1 = h[0] > h[1]
  p= 0
  v= 0
  if grad1:
    p += h[0]

  for n in range(2, L):
    grad2 = h[n-1] > h[n] 
    if grad1 == grad2:
      continue
    elif grad2:
      p += h[n-1]
    else:
      v += h[n-1]
    grad1 = grad2
               
  if not grad1:
    p += h[n]
 
ans = p - v
print(ans)

### FIXED CODE ###

import sys
L = int(sys.stdin.readline().rstrip())
 
h = list(map(int, sys.stdin.readline().rstrip().split()))
 
if L == 0:
  ans = 0
elif L == 1:
  ans = h[0]
elif L == 2:
  ans = max(h)
  
else:
  grad1 = h[0] > h[1]
  p= 0
  v= 0
  if grad1:
    p += h[0]
 
  for n in range(2, L):
    grad2 = h[n-1] > h[n] 
    if grad1 == grad2:
      continue
    elif grad2:
      p += h[n-1]
    else:
      v += h[n-1]
    grad1 = grad2
               
  if not grad1:
    p += h[n]
 
  ans = p - v
print(ans)
def resolve():
    N = int(input())
    num = list(range(1,N))
    ans = sum(num)
    print(ans)
resolve()

### FIXED CODE ###

def resolve():
    N = int(input())
    ans = (N-1)*N//2
    print(ans)
resolve()
n, m = list(map(int, input().split()))
city_list = [[] for i in range(n)]

for i in range(m):
    pm, ym = list(map(int, input().split()))
    city_list[pm-1].append(ym)
city_list_copied = copy.deepcopy(city_list)

for i in range(n):
    city_list_copied[i].sort()
    for j in range(len(city_list[i])):
        cindex = sum(x <= city_list[i][j] for x in city_list[i])
        print("{:0=6}{:0=6}".format(i+1, cindex))


### FIXED CODE ###

x, y = list(map(int, input().split()))
print("{} ".format(int(x+y/2)))
from math import modf

n, a, b, c, d, e = [int(input()) for _ in range(6)]
r = min([h for h in [a,b,c,d,e] if h != 1])
if 1 in [a,b,c,d,e]:
  r -= 1
dd, ii = modf(n/r)
ll = int(ii)+int(dd*10)
print(5 if ll == 0 else ll)

### FIXED CODE ###

n, a, b, c, d, e = [int(input()) for _ in range(6)]
x = min(a,b,c,d,e)
print((n+x-1)//x+4)
a = input()
b = input()
n = len(b)
x = 0
i = 0
j = 0
while (x < n * 2):
    if x % 2:
        print(b[i], end = '')
        i += 1
    else:
        print(a[j], end = '')
        j += 1
    x += 1
print('')

### FIXED CODE ###

a, b, c = input().split()
a = int(a)
b = int(b)
c = int(c)
if b - a == c - b:
    print('YES')
else:
    print('NO')
import math

data = input()
data1 = input()

data = int(data)
data = int(data1)
print (data * data1," ",data*2 + data1*2)

### FIXED CODE ###

import math


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

a = int(a)
b = int(b)
print (a * b,a*2 + b*2)
S=input()
n=len(S)
if n==2:
  if S=='hi':
    print('Yes')
  else:
    print('No')
elif n==4:
   if S=='hihi':
    print('Yes')
  else:
    print('No')
elif n==6:
  if S=='hihihi':
    print('Yes')
  else:
    print('No')
elif n==8:
   if S=='hihihihi':
    print('Yes')
  else:
    print('No')
elif n==10:
   if S=='hihihihihi':
    print('Yes')
  else:
    print('No')
else:
  print('No')

### FIXED CODE ###

S=input()
n=len(S)
if n==2:
  if S=='hi':
    print('Yes')
  else:
    print('No')
elif n==4:
  if S=='hihi':
    print('Yes')
  else:
    print('No')
elif n==6:
  if S=='hihihi':
    print('Yes')
  else:
    print('No')
elif n==8:
  if S=='hihihihi':
    print('Yes')
  else:
    print('No')
elif n==10:
  if S=='hihihihihi':
    print('Yes')
  else:
    print('No')
else:
  print('No')
from sys import stdin, gettrace
 
if not gettrace():
    def input():
        return next(stdin)[:-1]
 
 
# def input():
#    return stdin.buffer.readline()
 
def main():
    dn,w=map(int,input().split())
	li=[]
	for i in range(n):
    	temp=[int(x) for x in input().split()]
    	li.append(temp)
	dp=[[[-1,-1] for j in range(w+1)] for i in range(n)]
	dp[n-1][0]=[li[n-1][1],li[n-1][1]]
	for i in range(n-1,-1,-1):
    	for j in range(w,-1,-1):
        	if j==0:
            	dp[i][j]=li[i][1],li[i][1]
        	if i==(n-1):
            	if li[i][0]<=j:
                	dp[i][j]=li[i][1],li[i][1]
            	else:
                	dp[i][j]=0,0
        	else:
            	mx=li[i][1]
            	for k in range(i+1,n):
                	if (j-li[i][0])>=li[k][0]:
                    	val=dp[k][j-li[i][0]]
                    	mx=max(mx,val[0]+li[i][1])
            	val=dp[i+1][j]
            	overall=max(mx,val[1])
            	dp[i][j]=[mx,overall]
	print(dp[0][w][1])
 
 
if __name__ == "__main__":
    main()

### FIXED CODE ###

from sys import stdin, gettrace
import sys
sys.setrecursionlimit(1000000)
if not gettrace():
    def input():
        return next(stdin)[:-1]
 
 
# def input():
#    return stdin.buffer.readline()

def recursion(li,i,n,w,dp):
    if i==n or w==0:
        return 0
    if li[i][0]>w:
        if dp[i+1][w]==-1:
            x=recursion(li,i+1,n,w,dp)
            dp[i+1][w]=x            
        else:
            x=dp[i+1][w]
        return x
    else:
        if dp[i+1][w]==-1:
            x=recursion(li,i+1,n,w,dp)
            dp[i+1][w]=x            
        else:
            x=dp[i+1][w]
        if dp[i+1][w-li[i][0]]==-1:
            y=recursion(li,i+1,n,w-li[i][0],dp)
            dp[i+1][w-li[i][0]]=y
        else:
            y=dp[i+1][w-li[i][0]]            
        return max(li[i][1]+y,x)

def main():
    n,w=[int(x) for x in input().split()]
    li=[]
    for i in range(n):
        temp=[int(x) for x in input().split()]
        li.append(temp)
    dp=[[-1 for j in range(w+1)] for i in range(n+1)]
    print(recursion(li,0,n,w,dp))
 
 
if __name__ == "__main__":
    main()
A,B = map(int,input().split())
count = 0
for i in range(1,B):
    if count == 0 and A >= B:
        count = 1
        a = 1
        break
    if (A-1)*(i-1)+A >= B:
        a = i
        break
print(a)

### FIXED CODE ###

A, B = map(int, input().split())
cnt = 1
while A*cnt-(cnt-1) < B:
  cnt +=1
print(cnt if B > 1 else 0)
A , B = [int(i) for i in input().split()]

if B>A:    
    if (B-A)%2==0:
        print(int((B-A)/2+A)
    else:
        print("IMPOSSIBLE")
else:
    if (A-B)%2==0:
        print(int((A-B)/2+B)
    else:
        print("IMPOSSIBLE")

### FIXED CODE ###

A , B = [int(i) for i in input().split()]

if B>A:    
    if (B-A)%2==0:
        print(int((B-A)/2+A))
    else:
        print("IMPOSSIBLE")
else:
    if (A-B)%2==0:
        print(int((A-B)/2+B))
    else:
        print("IMPOSSIBLE")
def resolve():
    a, b = map(int, input().split())
    ps = primes(int(min(a, b) ** 0.5))
    ans = [pi for pi in ps if a % pi == 0 and b % pi == 0]
    print(len(ans) + 1)
    
    
if __name__ == "__main__":
    resolve()    

### FIXED CODE ###

def resolve():
    a, b = map(int, input().split())
    div_a = set(prime_factorize(a))
    div_b = set(prime_factorize(b))
    print(len(div_a & div_b) + 1)
    # print(div_a)
    # print(div_b)


def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a


if __name__ == "__main__":
    resolve()
n=int(input())
l=list(map(int,input().split()))
cnt=0
l.sort()
for i in range(0,n-1):
  cnt+=l[i]
if cnt>l[n]:
  print("Yes")
else:
  print("No")

### FIXED CODE ###

n=int(input())
l=list(map(int,input().split()))
cnt=0
l.sort()
for i in range(0,n-1):
  cnt+=l[i]
if cnt>l[n-1]:
  print("Yes")
else:
  print("No")
AtCoder, s, Contest = map(str, input().split()) 
print(f'A{s[0]}C')AtCoder, s, Contest = map(str, input().split()) 
x = s[0]
print(f'A{s}C')

### FIXED CODE ###

AtCoder, s, Contest = map(str, input().split()) 
print('A' + s[0] + 'C')
N,K = map(int, input().split())
Ds = list(map(int, input().split()))

able = []
for i in range(10):
    if i in Ds:continue
    able.append(i)
# print(able)

sN = str(N)
n = len(sN)
m = able[0] #最小


if int(sN[0]) > max(able):
    if m == 0:
        ans = str(able[1]) + str(able[0]) * n
    else:
        ans = str(able[0]) * (n+1)
    print(ans)
    exit()
prev = -1
flg = True #確定していない
ans = ""
for i,s in enumerate(sN):
    flg2 = False
    if flg:
        for j,a in enumerate(able):
            if int(s) < a:
                ans += str(a)
                flg = False
                flg2 = True
                break
            if int(s) == a:
                ans += str(a)
                flg = True
                flg2 = True
                break
        if not flg2:
            ans = ans[:-1]
            ans += str(able[prev+1]) + str(m)
            flg = False
    else:
        ans += str(m)    
    prev = j
    # print(ans)

print(ans)
"""
1333 8
0 3 4 5 6 7 8 9
"""

### FIXED CODE ###

N,K = map(int, input().split())
Ds = list(map(int, input().split()))

able = []
for i in range(10):
    if i in Ds:continue
    able.append(i)
# print(able)

sN = str(N)
n = len(sN)
m = able[0] #最小


if int(sN[0]) > max(able):
    if m == 0:
        ans = str(able[1]) + str(able[0]) * n
    else:
        ans = str(able[0]) * (n+1)
    print(ans)
    exit()
prev = -1
flg = True #確定していない
ans = ""
for i,s in enumerate(sN):
    flg2 = False
    if flg:
        for j,a in enumerate(able):
            if int(s) < a:
                ans += str(a)
                flg = False
                flg2 = True
                break
            if int(s) == a:
                ans += str(a)
                flg = True
                flg2 = True
                break
        if not flg2:
            if prev == len(able)-1:
                if m == 0:
                    ans = str(able[1]) + str(able[0]) * n
                else:
                    ans = str(able[0]) * (n+1)
                print(ans)
                exit() 
            ans = ans[:-1]
            ans += str(able[prev+1]) + str(m)
            flg = False
    else:
        ans += str(m)    
    prev = j
    # print(ans)

print(ans)
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1<<32


def solve(N: int, M: int, s: "List[int]", c: "List[int]"):
    from collections import defaultdict

    d = defaultdict(list)

    for i in range(M):
        d[s[i]].append(c[i])
        d[s[i]] = list(set(d[s[i]]))

    # print(d)

    if not all([len(v) == 1 for k, v in d.items()]):
        # print('test')
        print('-1')
        exit()

    ans = []
    for i in range(1, M+1):
        if d[i]:
            ans.append(d[i][0])
        else:
            ans.append(0)


    # print(str(int(''.join(map(str, ans)))))
    if len(str(int(''.join(map(str, ans))))) != N:
        print(-1)
    else:
        print(int(''.join(map(str, ans))))

    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    s = [int()] * (M)  # type: "List[int]"
    c = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        s[i] = int(next(tokens))
        c[i] = int(next(tokens))
    solve(N, M, s, c)

if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1<<32


def solve(N: int, M: int, s: "List[int]", c: "List[int]"):
    from collections import defaultdict

    d = defaultdict(list)

    for i in range(M):
        d[s[i]].append(c[i])
        d[s[i]] = list(set(d[s[i]]))

    if not all([len(v) == 1 for k, v in d.items()]):
        print('-1')
        exit()

    ans = []
    for i in range(1, N+1):
        if d[i]:
            ans.append(d[i][0])
        elif i == 1 and N >= 2:
            ans.append(1)
        else:
            ans.append(0)

    if len(str(int(''.join(map(str, ans))))) != N:
        print(-1)
    else:
        print(int(''.join(map(str, ans))))

    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    s = [int()] * (M)  # type: "List[int]"
    c = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        s[i] = int(next(tokens))
        c[i] = int(next(tokens))
    solve(N, M, s, c)

if __name__ == '__main__':
    main()
import sys
sys.setrecursionlimit(2000000)

N = int(input())
A = [[0]*(N)]
for _ in range(N):
    A.append([0]+list(map(int,input().split())))

#選手iにとって、選手jが何番目の相手かを逆引きするメモを用意しておく。
reverseMemo = {i:{} for i in range(1,N+1)}
for i in range(1,N+1):
    for j in range(1,N):
        a = A[i][j]
        reverseMemo[i][a] = j

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

def f(i,j,cnt):
    #iとjの試合が最速でいつできるかを返す。
    if cnt > N*N:
        print(-1)
        exit()
    if dp[i][j] == None and dp[j][i] == None:
        #iの一つ前の試合がいつおわるかを調べる。
        pre = A[i][reverseMemo[i][j]-1]
        tmp1 = f(i,pre,cnt+1)
        
        #jの一つ前の試合がいつおわるかを調べる。
        pre = A[j][reverseMemo[j][i]-1]
        tmp2 = f(j,pre,cnt+1)

        dp[i][j] = max(tmp1,tmp2)+1

    elif dp[i][j] == None and dp[j][i] != None:
        dp[i][j] = dp[j][i]
    elif dp[i][j] != None and dp[j][i] != None:
        dp[j][i] = dp[i][j]
    return dp[i][j]

ans = 0
for i in range(1,N+1):
    for j in range(1,N):
        a = A[i][j]
        ans = max(ans,f(i,a,0))
print(ans)

### FIXED CODE ###

"""
最長経路問題として解く。

各試合のノードを作成。
各試合ノードごとに、「この試合が終わったら、次はこの試合ができるようになる。」という対応関係を作っていく。
"""
def main():
    import sys
    sys.setrecursionlimit(1000000)
    input = sys.stdin.readline

    N = int(input())

    A = [[0]*(N)]
    for i in range(N):
        A.append([0]+list(map(int,input().split())))
    
    #選手iにとって、選手jが何番目の相手かを逆引きするメモを用意しておく。
    reverseMemo = [[-1]*(N+1) for _ in range(N+1)]
    for i in range(1,N+1):
        for j in range(1,N):
            a = A[i][j]
            reverseMemo[i][a] = j
    edges = {}
    for i in range(1,N+1):
        for j in range(i+1,N+1):
            match = (i,j)
            edges[match] = []
            if reverseMemo[i][j] != N-1:
                nx = A[i][reverseMemo[i][j]+1]
                edges[match].append((min(i,nx),max(i,nx)))
            if reverseMemo[j][i] != N-1:
                nx = A[j][reverseMemo[j][i]+1]
                edges[match].append((min(j,nx),max(j,nx)))
    
    del reverseMemo
    del A
    
    stepMemo = {}
    def dfs(i,j,path):
        #i,jの試合日を含めて、あと何日必要なのかを返す。
        if (i,j) not in stepMemo:
            if (i,j) in path:
                print(-1)
                exit()
            else:
                path.add((i,j))
            res = 1
            for a,b in edges[(i,j)]:
                res = max(res,dfs(a,b,path)+1)
            stepMemo[(i,j)] = res
        return stepMemo[(i,j)]

    ans = 0
    for i in range(1,N+1):
        for j in range(i+1,N+1):
            if (i,j) not in stepMemo:
                ans = max(ans,dfs(i,j,set()))
    print(ans)
main()
s = int(input())
m = s/60
h = m/60

print(h":"m":"int(s))

### FIXED CODE ###

a = int(input())
h = int(a/3600)
m=int((a%3600)/60)
s=int((a%3600)%60)

print(h,m,s,sep=":")
import sys                       
a = sys.stdin.readline().rstrip()
b = sys.stdin.readline().rstrip()
if a == b[:-1]:                  
  print "Yes"                    
else:                            
  print "No"                     
                                 

### FIXED CODE ###

import sys                       
a = sys.stdin.readline().rstrip()
b = sys.stdin.readline().rstrip()
if a == b[:-1]:                  
  print("Yes")                   
else:                            
  print("No")
n,m = map(int, raw_input().split())
n_list = [] #row major format
m_list = []
for i in range(0, n):
	n_list.append(raw_input())

for x in range(0, m):
	m_list.append(raw_input())

def match_first_rows(n_start):
	result = (-1,-1)
	first_m = m_list[0] # first row
	for x in range(n_start, n):
		n_row = n_list[x]
		if first_m in n_row: # substring matching of first m_row
			j = n_row.index(first_m)
			return (x, j)
	return (-1,-1) #return -1,-1 if none found

# given the leftmost corner of matching in matrix n, start matching each row to see if there is a potential match
# only guranteed first row match
def begin_matching(i,j):
	nx_start = i
	ny_start = j
	for x in range(0,m):
		n_row_string = n_list[nx_start+x]
		n_string = n_row_string[j:j+m] # align window
		m_string = m_list[x]
		if n_string!=m_string:
			return False
	return True

def find_m():

	found_m = False
	counter = 0
	while(counter<=n-m and not(found_m)):

		i,j = match_first_rows(counter)
		if i==-1: 
			#goes through entirety, not returning things at all
			print("No")
			found_m = True
		# found a potential starting point
		else:
			result = begin_matching(i,j)
			if result:
				print("Yes")
				found_m = True
			else:
				#do it again, but one row lower
				counter +=1 

find_m()

### FIXED CODE ###

a,b = map(int, raw_input().split())

if a==b:
	print "Draw"
else:
	if a!=1 and b!=1:
		if a<b:
			print "Bob"
		else:
			print "Alice"
	elif a==1 and b!=1:
		print "Alice"
	else:
		print "Bob"
A = [int(input()) for _ in range(5)]
cnt = 0
Max = 10
for i in range(len(A)):
    if 0 < A[i]%10 < Max:
        Max = A[i]%10
        Max_i = i
for i in range(len(A)):
    if i != Max_i:
        cnt += A[i]
    while cnt%10 != 0:
        cnt += 1
print(cnt+A[Max_i])

### FIXED CODE ###

A = [int(input()) for _ in range(5)]
cnt = 0
Max = 10
Max_i = 0
for i in range(len(A)):
    if 0 < A[i]%10 < Max:
        Max = A[i]%10
        Max_i = i
for i in range(len(A)):
    if i != Max_i:
        cnt += A[i]
    while cnt%10 != 0:
        cnt += 1
print(cnt+A[Max_i])
n, k = map(int, input().split())
p = [0] + list(map(int, input().split()))
c = [0] + list(map(int, input().split()))

maximum = max(c[1:])
if maximum < 0:
    print(maximum)
    exit()

used = [False] * (n+1)

ans = 0

for i in range(1, n+1):
    if used[i]:continue
    loop = [i]
    now = i
    while p[now] != i:
        now = p[now]
        loop.append(now)

    L = len(loop)
    S = sum(c[v] for v in loop)
    for a_ind in range(L):
        a = loop[a_ind]
        used[a] = True
        dist_ab = 0
        cost_ab = -c[a]
        for b_ind in range(a_ind, a_ind+L):
            b = loop[b_ind % L]
            cost_ab += c[b]
            max_cost = cost_ab + max(0, S) * ((k - dist_ab) // L)
            ans = max(ans, max_cost)
            dist_ab += 1
            if dist_ab > k:
                break

print(ans)

### FIXED CODE ###

x, k, d = map(int, input().split())

def sgn(x):
    if x > 0:return 1
    if x < 0:return -1
    return 0

if x > 0:
    x_greedy = x - k * d
else:
    x_greedy = x + k * d

if sgn(x) == sgn(x_greedy):
    print(abs(x_greedy))
    exit()
x_r = x % d
x_l = x_r - d

r_parity = (abs(x - x_r) // d) % 2

if k%2 == r_parity:
    print(abs(x_r))
else:
    print(abs(x_l))
M = input()
M = int(M)
print(48 - M)
hibiki@hibiki-M

### FIXED CODE ###

M = input()
M = int(M)
print(48 - M)
print()
a,b=map(int,input().split())

if (a+b) % 2 == 0:
  print((a+b)/2)
  
elif: (a+b)%2 == 1:
  print("IMPOSSIBLE")

### FIXED CODE ###

a,b=map(int,input().split())
s = int((a+b)/2)
u = (a+b)%2

if u == 0:
  print(s)
  
else: 
  print("IMPOSSIBLE")