Harryxun/stf_run huggingface dataset:
(n, m) = [int(i) for i in input().split()]
A = []
B = []
for i in range(n):
    A.append([int(j) for j in input().split()])

for i in range(m):
    B.append(int(input()))

for i in range(n):
    s = 0
    for j in range(m):
        m += A[i][j] * B[j]
    print(s)

### FIXED CODE ###

(n, m) = [int(i) for i in input().split()]
 
A = []
b = []
 
for i in range(n):
    A.append([int(j) for j in input().split()])
 
for i in range(m):
    b.append(int(input()))
 
 
for i in range(n):
    c = 0 
    for j in range(m):
         c += A[i][j] * b[j]
    print(c)
n = input()
d = set()
pre = ""
for i in range(n):
    s = raw_input()
    if s in d:
        print "No"
        exit()
    if pre = "" or pre[-1] == s[0]:
        d.add(s)
        pre = d
    else:
        print "No"
        exit()
print "Yes"

### FIXED CODE ###

n = input()
d = set()
pre = ""
for i in range(n):
    s = raw_input()
    if s in d:
        print "No"
        exit()
    if pre == "" or pre[-1] == s[0]:
        d.add(s)
        pre = s
    else:
        print "No"
        exit()
print "Yes"
from fractions import gcd
import numpy as np
n=int(input())
A=list(map(int,input().split()))
B=np.array(A)
mod=10**9+7

if n==1:
    print(1)
else:
    g=A[0]
    l=A[0]
    for i in range(n-1):
        g=gcd(l,A[i+1])
        l*=(A[i+1]//g)
    B=B/l
    ans=int((1/B).sum())
    print(ans%mod)

### FIXED CODE ###

import sys
input = sys.stdin.readline
from fractions import gcd
n=int(input())
A=list(map(int,input().split()))
mod=10**9+7
def gyaku(a):
    return pow(a,mod-2,mod)
if n==1:
    print(1)
else:
    gya=[0]*(n)
    g=A[0]
    l=A[0]
    gya[0]=gyaku(A[0])
    for i in range(n-1):
        g=gcd(l,A[i+1])
        l*=(A[i+1]//g)
        gya[i+1]=gyaku(A[i+1])
    ans=0
    for i in range(n):
        ans+=l*gya[i]
        ans%=mod
    print(ans)
def warshall_floid(d):
    for k in range(1,n+1):
        for i in range(1,n+1):
            for j in range(1,n+1):
                d[i][j] = min(d[i][j],d[i][k]+d[k][j])
    return d

n,m,l = map(int,input().split())
d = [10**13]*(n+1) for i in range(n+1)]
for i in range(m):
    a,b,c = map(int,input().split())
    d[a][b] = c
    d[b][a] = c
for i in range(1,n+1):
    d[i][i] = 0
d = warshall_floid(d)
for i in range(1,n+1):
    for j in range(1,n+1):
        if d[i][j] <= l:
            d[i][j] = 1
        else:
            d[i][j] = 10**13
d = warshall_floid(d)
q = int(input())
for i in range(q):
    s,t = map(int,input().split())
    if d[s][t] >= 10**13:
        print(-1)
    else:
        print(d[s][t]-1)


### FIXED CODE ###

def warshall_floid(d):
    for k in range(1,n+1):
        for i in range(1,n+1):
            for j in range(1,n+1):
                d[i][j] = min(d[i][j],d[i][k]+d[k][j])
    return d

n,m,l = map(int,input().split())
d = [[10**13]*(n+1) for i in range(n+1)]
for i in range(m):
    a,b,c = map(int,input().split())
    d[a][b] = c
    d[b][a] = c
for i in range(1,n+1):
    d[i][i] = 0
d = warshall_floid(d)
for i in range(1,n+1):
    for j in range(1,n+1):
        if d[i][j] <= l:
            d[i][j] = 1
        else:
            d[i][j] = 10**13
d = warshall_floid(d)
q = int(input())
for i in range(q):
    s,t = map(int,input().split())
    if d[s][t] >= 10**13:
        print(-1)
    else:
        print(d[s][t]-1)
S = list(input())
S = sorted(S)
num = len(set(S))
newS = sorted(list(set(S)))

if num == 26:
    print('None')
else:
    for i in range(26):
        if newS[i] != chr(i+97):
            print(chr(i+97))
            break


### FIXED CODE ###

S = input()
S = sorted(list(set(S)))

n = 97
for i in range(len(S)):
    if ord(S[i]) == n:
        n += 1
    else:
        break

if n == 123:
    print('None')
else:
    print(chr(n))
from collections import deque


reverse = False

string = deque(input().rstrip())
operate_times = int(input().rstrip())

for i in range(operate_times):
    row = input().rstrip()
    if row[0]=='1':
        if reverse==True:
            reverse = False
        else:
            reverse = True
    
    if row[0]=='2':
        row = row.split()
        head_or_tail = row[1]
        add_string = row[2]

        if reverse==True:
            if head_or_tail==1:
                string.append(add_string)
            else:
                string.appendleft(add_string)
        
        else:
            if head_or_tail==2:
                string.append(add_string)
            else:
                string.appendleft(add_string)


if reverse==True:
    string = string[::-1]

print(''.join(string))


### FIXED CODE ###

from collections import deque


reverse = False

string = deque(input().rstrip())
operate_times = int(input().rstrip())

for i in range(operate_times):
    row = input().rstrip()
    if row[0]=='1':
        if reverse:
            reverse = False
        else:
            reverse = True
    
    if row[0]=='2':
        row = row.split()
        head_or_tail = int(row[1])
        add_string = row[2]

        if reverse:
            if head_or_tail==1:
                string.append(add_string)
            else:
                string.appendleft(add_string)
        
        else:
            if head_or_tail==2:
                string.append(add_string)
            else:
                string.appendleft(add_string)


answer_string = ''
if reverse:
    for _ in range(len(string)):
        right = string.pop()
        answer_string+=right
    print(answer_string)
else:
    print(''.join(string))
h,a=map(int,input().split())
count=0
while h>:
  h=h-a
  count=count+1
print(count)

### FIXED CODE ###

h,a=map(int,input().split())
count=0
while h>0:
  h=h-a
  count=count+1
print(count)
a=int(input('a'))
b=int(input('b'))
if (a*b)%2 ==0:
  print('Even')
else:
  print('Odd')
  

### FIXED CODE ###

a,b=map(int,input().split())
if (a*b)%2 ==0:
  print('Even')
else:
  print('Odd')
n,W=list(map(int,input().split()))

dp=np.zeros([n+1,W+1],dtype=int)

for i in range(1,n+1):
    w,v=list(map(int,input().split()))
    dp[i]=dp[i-1]
    dp[i][w:]=np.maximum(dp[i-1][:W-w+1]+v,dp[i-1][w:])
print(np.max(dp[n-1]))

### FIXED CODE ###

import numpy as np

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

dp=np.zeros([n+1,W+1],dtype=int)

for i in range(1,n+1):
    w,v=list(map(int,input().split()))
    dp[i]=dp[i-1]
    dp[i][w:]=np.maximum(dp[i-1][:W-w+1]+v,dp[i-1][w:])
print(np.max(dp))
#hello
#password
#input
#understandign python
#less errors
$work now please
q = int(input())
w = q / 3
print(w ** 3)

### FIXED CODE ###

def shortie(L):
    r = L/3
    return (r **3)


L =int(input())
print(shortie(L))
n=int(input);print((n-n//2)/n)

### FIXED CODE ###

n = int(input())
print((n - n//2) / n)
a,b = map(int,input().split())

def is_prime(q):
    q = abs(q)
    if q == 2: return True
    if q < 2 or q&1 == 0: return False
    return pow(2, q-1, q) == 1

def factorize(n):
    fct = []  # prime factor
    b, e = 2, 0  # base, exponent
    while b * b <= n:
        while n % b == 0:
            n = n // b
            e = e + 1
        if e > 0:
            fct.append((b, e))
        b, e = b + 1, 0
    if n > 1:
        fct.append((n, 1))
    return fct


def num(fct):
    a = 1
    for base, exponent in fct:
        a = a * base**exponent
    return a

def divisorize(fct):
    b, e = fct.pop()  # base, exponent
    pre_div = divisorize(fct) if fct else [[]]
    suf_div = [[(b, k)] for k in range(e + 1)]
    return [pre + suf for pre in pre_div for suf in suf_div]

x=[]
y=[]
z=[]

fct_a = factorize(a)
for div in divisorize(fct_a):
  x.append(num(div))

fct_b = factorize(b)
for div in divisorize(fct_b):
  y.append(num(div))

z=x+y
w=[m for m in set(z) if z.count(m) > 1]

c=0

for i in range(0,len(w)):
  if is_prime(w[i]):
    c+=1
print(c+1)

### FIXED CODE ###

import random

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

def is_prime(q,k=50):
    q = abs(q)
    #計算するまでもなく判定できるものははじく
    if q == 2: return True
    if q < 2 or q&1 == 0: return False

    #n-1=2^s*dとし（但しaは整数、dは奇数)、dを求める
    d = (q-1)>>1
    while d&1 == 0:
        d >>= 1
    
    #判定をk回繰り返す
    for i in range(k):
        a = random.randint(1,q-1)
        t = d
        y = pow(a,t,q)
        #[0,s-1]の範囲すべてをチェック
        while t != q-1 and y != 1 and y != q-1: 
            y = pow(y,2,q)
            t <<= 1
        if y != q-1 and t&1 == 0:
            return False
    return True

def factorize(n):
    fct = []  # prime factor
    b, e = 2, 0  # base, exponent
    while b * b <= n:
        while n % b == 0:
            n = n // b
            e = e + 1
        if e > 0:
            fct.append((b, e))
        b, e = b + 1, 0
    if n > 1:
        fct.append((n, 1))
    return fct


def num(fct):
    a = 1
    for base, exponent in fct:
        a = a * base**exponent
    return a

def divisorize(fct):
    b, e = fct.pop()  # base, exponent
    pre_div = divisorize(fct) if fct else [[]]
    suf_div = [[(b, k)] for k in range(e + 1)]
    return [pre + suf for pre in pre_div for suf in suf_div]

x=[]
y=[]
z=[]

if a==1:
  x.append(1)
else:
  fct_a = factorize(a)
  for div in divisorize(fct_a):
    x.append(num(div))

if b==1:
  y.append(1)
else:
  fct_b = factorize(b)
  for div in divisorize(fct_b):
    y.append(num(div))

z=x+y
w=[m for m in set(z) if z.count(m) > 1]

c=0

for i in range(0,len(w)):
  if is_prime(w[i]):
    c+=1
print(c+1)
x,y,a,b,c = map(int, input().split())
A = list(map(int, input().split())) 
B = list(map(int, input().split())) 
C = list(map(int, input().split())) 

A.sort()
B.sort()
C.sort(reverse=True)

X = A[len(A)-x:]
Y = B[len(B)-y:]


xi = 0
yi = 0
ci = 0
for ci in range(c):
    if C[ci] <= X[xi] and C[ci] <= Y[yi]:
        break
    
    if X[xi] < Y[yi]:
        if C[ci] > X[xi]:
            X[xi] = C[xi]
            xi = xi + 1
    else:
        if C[ci] > Y[yi]:
            Y[yi] = C[xi]
            yi = yi + 1

#print(X,Y)
print(sum(X)+sum(Y))

### FIXED CODE ###


x,y,a,b,c = map(int, input().split())
A = list(map(int, input().split())) 
B = list(map(int, input().split())) 
C = list(map(int, input().split())) 

A.sort()
B.sort()
C.sort(reverse=True)

X = A[len(A)-x:]
Y = B[len(B)-y:]

#print(X,Y,C)

xi = 0
yi = 0
ci = 0
for ci in range(c):
    #print(ci,xi,yi)
    if xi < len(X) and yi < len(Y):
        if C[ci] <= X[xi] and C[ci] <= Y[yi]:
            break
        
        if X[xi] < Y[yi]:
            if C[ci] > X[xi]:
                X[xi] = C[ci]
                xi = xi + 1
        else:
            if C[ci] > Y[yi]:
                Y[yi] = C[ci]
                yi = yi + 1
                
    elif xi < len(X):
        if C[ci] <= X[xi]:
            break
        
        if C[ci] > X[xi]:
            X[xi] = C[ci]
            xi = xi + 1
        
    elif yi < len(Y):
        if C[ci] <= Y[yi]:
            break
        
        if C[ci] > Y[yi]:
            Y[yi] = C[ci]
            yi = yi + 1
            
    else:
        break

print(sum(X)+sum(Y))
# -*- coding: utf-8 -*-
import numpy as np 
import math

# 入力
N = int(input())
A = input()

A = np.array(A.split()).astype('int')
ones = np.ones([N, N])
B = (A*ones)
for i in range(N):
  B[i, i] = 0
B = B[np.where(B != 0, True, False)].reshape(N, N-1)
B.sort()

def comb(n, r):
    if n < r:
        return 0
    else:
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
      
def uniq_2_comb(N, ar):
  u = np.unique(ar, return_index=True)[1]
  u = np.concatenate([u, np.array([N])])
  ans = 0
  for i in range(len(u)-1):
    n = u[i+1] - u[i]
    ans += comb(n, 2)
  return ans

ans_ar = np.apply_along_axis(lambda x : uniq_2_comb(N, x), 1, B)

for ans in ans_ar:
  print(ans)


### FIXED CODE ###

# -*- coding: utf-8 -*-
import collections
import math

# 入力
N = int(input())
A = list(input().split())

c = collections.Counter(A)

def comb(n, r):
    if n < r:
        return 0
    else:
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

comb_sum = 0
for i in c:
    comb_sum += comb(c[i], 2)
     
for a in A:
    ans = comb_sum
    if c[a] >= 2:
        ans -= (c[a] - 1)
    print(ans)
N, M = map(int, input().split())
l = [list(map(int, input().split())) for i in range(N)]
m = []
for i in range(1, l[0][0] + 1):
    m.append(l[0][i])
for i in range(1, N):
    for j in m:
        
        if l[i][1:i[0] + 1].count(j) == 0:
            m.remove(j)
            
print(len(m))

### FIXED CODE ###

n, m = map(int,input().split())

m = [0] * 30
for i in range(n):
    a = list(map(int, input().split()))
    for j in range(1, len(a)):
        m[a[j] - 1] += 1

print(m.count(n))
import numpy as np
N, M = list(map(int, input().split()))
H = list(map(int, input().split()))
G = N
lists = np.zeros(N)
for i in range(M):
    A, B = list(map(int, input().split()))
    if H[A-1] < H[B-1]:
        lists[A-1] = 1
    else:
        lists[B-1] = 1
for i in range(N):
    if lists[i] == 1:
        G -= 1
print(lists)
print(G)

### FIXED CODE ###

S = input("")
if S =="ABC":
    print("ARC")
else:
    print("ABC")
n = int(input())
bl = [int(i) for i in input().split()]
bl.reverse()

v = bl[0]

for i in range(1,n-1):
    v += min(bl[i],bl[i-1])

v += bl[n-2]

print(v)



### FIXED CODE ###

n = int(input())

print(n**3)
a,b=input().split()
a=int(a)
b=int(b)
c=list(map(int,input().split()))
c.sort()
d=sum(c)
e=0
for i in range(b):
  e=e+c[-b]
print(d-e)

### FIXED CODE ###

a,b=input().split()
a=int(a)
b=int(b)
c=list(map(int,input().split()))
c.sort()
d=sum(c)
e=0
if a<=b:
  print(0)
else:
  for i in range(1,b+1):
    e=e+c[-i]
  print(d-e)
from fractions import gcd

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

fwd = [A[0]]
for i in range(1, N):
    fwd.append(gcd(fwd[-1], A[i]))

bwd = [A[-1]]
for i in range(N-2, -1, -1):
    bwd.append(gcd(bwd[-1], A[i]))
bwd.reverse()

gmax = max(fwd[-2], bwd[1])
for i in range(1, N-1):
    gmax = max(gmax, gcd(fwd[i-1], bwd[i+1]))

print(gmax)


### FIXED CODE ###

from fractions import gcd

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

fwd = [A[0]]
for i in range(1, N):
    fwd.append(gcd(fwd[-1], A[i]))

bwd = [A[-1]]
for i in range(N-2, -1, -1):
    bwd.append(gcd(bwd[-1], A[i]))
bwd.reverse()

gmax = max(fwd[-2], bwd[1])
for i in range(1, N-1):
    gmax = max(gmax, gcd(fwd[i-1], bwd[i+1]))

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

P = [A[0]]
Q = [A[1]]
for i in range(2,N):
    if i % 2 == 0:
        P.append(P[-1] + A[i])
    else:
        Q.append(Q[-1] + A[i])

if N % 2 == 0:
    ans = max(P[-1],Q[-1])
    for i in range(N//2-1):
        ans = max(ans,P[i]+Q[-1]-Q[i])
else:
    ans = max(Q[-1],P[-1] - min(A[0::2]))
    ans = max(ans, Q[-2]-Q[0]+A[0]+A[-1])
    for i in range(N//2-1):
        ans = max(ans,P[i]+Q[-1]-Q[i])
    for i in range(N//2-1):
        ans = max(ans,P[-1]-P[i+1]+Q[i])
print(ans)

### FIXED CODE ###

from collections import defaultdict
INF = 10 ** 15
N = int(input())
A = list(map(int,input().split()))
dp_take = defaultdict(lambda: -INF)
dp_not = defaultdict(lambda: -INF)
dp_take[(0,0)] = 0
dp_not[(0,0)] = 0

for i in range(N):
    for j in range((i + 1) // 2 - 1, (i + 2) // 2 + 1):
        if j > 0:
            dp_take[(i+1, j)] = max(dp_take[(i+1, j)], dp_not[(i, j-1)] + A[i])
        dp_not[(i+1, j)] = max(dp_not[(i, j)], dp_take[(i, j)])

print(max(dp_take[(N, N//2)], dp_not[(N, N//2)]))
a, b, c, d = list(map(int, input().split()))
while True:
  c -= b
  if c <= 0:
    print('Yes')
    break
  a -= d
  if a <= 0:
    pinrt('No')
    break


### FIXED CODE ###

a, b, c, d = list(map(int, input().split()))
while True:
  c -= b
  if c <= 0:
    print('Yes')
    break
  a -= d
  if a <= 0:
    print('No')
    break
import collections

n=int(input())
b=[[0,0,0]]
a=[int(i) for i in input().split()]
for i in range(n):
    k=b[-1].index(a[i])
    c=[]
    for j in range(3):
        if j==k:
            c.append(b[-1][j]+1)
        else:
            c.append(b[-1][j])
    b.append(c)
#print(b)
x=1
for i in range(n):
    an=b[i].count(a[i])
    if an==0:
        break
    x=x*an
    x=x%1000000007

print(x)


### FIXED CODE ###

import collections

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

def my_index(l, x):
    if x in l:
        return l.index(x)
    else:
        return -1

for i in range(n):
    k=my_index(b[-1],a[i])
    if k==-1:
        print(0)
        break
    c=[]
    for j in range(3):
        if j==k:
            c.append(b[-1][j]+1)
        else:
            c.append(b[-1][j])
    b.append(c)
else:
    x=1
    for i in range(n):
        x=x*b[i].count(a[i])%1000000007
    print(x)
N, K = map(int, input().split())
print(N-k+1)

### FIXED CODE ###

n, k = map(int, input().split())
print(n - k + 1)
# -*- coding: utf-8 -*-
import sys
# ----------------------------------------------------------------
# Use Solve Function

def solve(lines):
    N,M = map(int, lines.pop(0).split(' '))
    X = list(map(int, lines.pop(0).split(' ')))
    X.sort()
    span = []
    for i in range(M-1):
        span.append( X[i+1] - X[i] )
    span.sort()
    for i in range(N-1):
        span.pop(-1)
    print(sum(span))

#
# main
#

lines = [x.strip() for x in sys.stdin.readlines()]

#
# solve !!
#
solve(lines)


### FIXED CODE ###

# -*- coding: utf-8 -*-
import sys
# ----------------------------------------------------------------
# Use Solve Function

def solve(lines):
    N,M = map(int, lines.pop(0).split(' '))
    X = list(map(int, lines.pop(0).split(' ')))
    if N >= M:
        print(0)
        sys.exit(0)
    X.sort()
    span = []
    for i in range(M-1):
        span.append( X[i+1] - X[i] )
    span.sort()
    for i in range(N-1):
        span.pop(-1)
    print(sum(span))

#
# main
#

lines = [x.strip() for x in sys.stdin.readlines()]

#
# solve !!
#
solve(lines)
num = int(input())
li = list(input())
i = int(num/2)
while(i<int((num/2)+1)):
  fi = set(li[:i])
  se = set(li[i:])
  ans = len(list(fi & se))
  if i < ans:
    i = ans
  else:
    i = i+1    
 
print(i)

### FIXED CODE ###

li = list(map(int,input().split()))
ans = [li[0]+li[1],li[0]-li[1],li[0]*li[1]]
ans.sort()
print(ans[2])
import math
def lcm(x, y):
    return (x * y) // math.gcd(x, y)

A,B,C,D = list(map(int,input().split()))
C_bai = list(range(A-(A%C)+C,B,C+1))
D_bai = list(range(A-(A%D)+D,B,D+1))
E = lcm(C,D)
CD_bai = list(range(A-(A%E)+E,B,E+1))
print(B-A+1-len(C_bai)-len(D_bai)+CD_bai)
    

### FIXED CODE ###

import math
def lcm(x, y):
    return (x * y) // math.gcd(x, y)

A,B,C,D = list(map(int,input().split()))
if A%C == 0:
    num_C_bai = (B-(B%C) - A)//C + 1
else:
    num_C_bai = ((B-(B%C) - (A-(A%C)+C)))//C + 1
    
if A%D == 0:
    num_D_bai = (B-(B%D) - A)//D + 1
else:
    num_D_bai = ((B-(B%D) - (A-(A%D)+D)))//D + 1

E = lcm(C,D)

if A%E == 0:
    num_E_bai = (B-(B%E) - A)//E + 1
else:
    num_E_bai = ((B-(B%E) - (A-(A%E)+E)))//E + 1

print(B + 1 - A - num_C_bai - num_D_bai + num_E_bai)
import numpy as np

def rain_volume(A, N):
    X = [0]*N
    X[0] = sum(A)
    for i, a in enumerate(A):
        if i%2 != 0:
            X[0] -= 2*a
    for i, a in enumerate(A):
        if i != 0:
            X[i] = 2*A[i] - X[i-1]
    return X

if __name__ == '__main__':
    N = int(input())
    A = deque(map(int, input().split(' ')))

    print(' '.join(map(str, rain_volume(A, N))))

### FIXED CODE ###

def rain_volume(A, N):
    X = [0]*N
    X[0] = sum(A)
    for i, a in enumerate(A):
        if i%2 != 0:
            X[0] -= 2*a
    for i in range(1, N):
        if i != 0:
            X[i] = 2*A[i-1] - X[i-1]
    return X

if __name__ == '__main__':
    N = int(input())
    A = list(map(int, input().split(' ')))

    print(' '.join(map(str, rain_volume(A, N))))
N = int(input())
D, X = map(int, input().split())
A = list(input() for i in range(N))
sum = 0
for i in range(N):
    B = 0
    while B * A[i] + 1 <= D:
        B += 1
        sum += 1
print(X + sum)


### FIXED CODE ###

N = int(input())
D, X = map(int, input().split())
A = list(int(input()) for i in range(N))
sum = 0
for i in range(N):
    B = 0
    while B * A[i] + 1 <= D:
        B += 1
        sum += 1
print(X + sum)
#!/usr/bin/env python3
#dp6 #Longest-Path

import sys
def LI(): return list(map(int,sys.stdin.readline().split()))
def LIR(n): return [LI() for _ in range(n)]
def g():
    def dfs(x):
        #既に最長パスがわかっている頂点はそれを返す
        if dp[x] != None:
            return dp[x]
        #移動できる頂点がないとき0
        if len(Graph[x]) == 0:
            dp[x] = 0
            return 0
        else:
            res = 0
            #移動できる頂点の中で最大パスをもつものを探す
            for y in Graph[x]:
                res = max(res,dfs(y)+1)
            dp[x] = res
            return dp[x]

    n,m = LI()
    #dpで各頂点を始点とした最大パスを管理
    dp = [None for _ in range(n)]
    Graph = [[] for _ in range(n)]
    for _ in range(m):
        x,y = LI()
        Graph[x-1].append(y-1)
    #各頂点を始点として最大パスを探す
    for i in range(n):
        dfs(i)
    print(max(dp))
if __name__ == '__main__':
    g()


### FIXED CODE ###

#!/usr/bin/env python3
#dp6 #Longest-Path

import sys
sys.setrecursionlimit(10000000)
def LI(): return list(map(int,sys.stdin.readline().split()))
def LIR(n): return [LI() for _ in range(n)]
def g():
    def dfs(x):
        #既に最長パスがわかっている頂点はそれを返す
        if dp[x] != None:
            return dp[x]
        #移動できる頂点がないとき0
        if len(Graph[x]) == 0:
            dp[x] = 0
            return 0
        else:
            res = 0
            #移動できる頂点の中で最大パスをもつものを探す
            for y in Graph[x]:
                res = max(res,dfs(y)+1)
            dp[x] = res
            return dp[x]

    n,m = LI()
    #dpで各頂点を始点とした最大パスを管理
    dp = [None for _ in range(n)]
    Graph = [[] for _ in range(n)]
    for _ in range(m):
        x,y = LI()
        Graph[x-1].append(y-1)
    #各頂点を始点として最大パスを探す
    for i in range(n):
        dfs(i)
    print(max(dp))
if __name__ == '__main__':
    g()
import sys
input = sys.stdin.readline
n, m = [int(w) for w in input().split()]
ls = [[int(w) for w in input().split()] for _ in range(n)]
lp = [[int(w) for w in input().split()] for _ in range(n)]

for a, b in ls:
    ans = -1
    dist = 10e10
    for i, (c, d) in enumerate(lp):
        d = abs(a-c) + abs(b-d)
        if d < dist:
            ans = i
            dist = d
    print(ans+1)


### FIXED CODE ###

import sys
input = sys.stdin.readline
n, m = [int(w) for w in input().split()]
ls = [[int(w) for w in input().split()] for _ in range(n)]
lp = [[int(w) for w in input().split()] for _ in range(m)]

for a, b in ls:
    ans = -1
    dist = 10e10
    for i, (c, d) in enumerate(lp):
        d = abs(a-c) + abs(b-d)
        if d < dist:
            ans = i
            dist = d
    print(ans+1)
n = int(input())
a = list(map(int, input().split()))
total_breaks = 0
position = 0
for i in range(1, n + 1):
    try:
        breaks = a[position::].index(i)
        total_breaks += breaks
        position = position + breaks + 1
    except ValueError:
        if position == 0:
            total_breaks = -1
            break
        else:
            total_breaks = total_breaks + n - position
            break
print(total_breaks)

### FIXED CODE ###

n = int(input())

ans = 0
if n % 2 != 0:
    print(0)
else:
    n //= 10
    while n > 0:
        ans += n
        n //= 5
    print(ans)
N = len(S)
zc,oc = 0,0
for i in range(N):
    if S[i]=='1':
        oc += 1
    else:
        zc += 1
print(2*min(oc,zc))

### FIXED CODE ###

S = input()
N = len(S)
zc,oc = 0,0
for i in range(N):
    if S[i]=='1':
        oc += 1
    else:
        zc += 1
print(2*min(oc,zc))
import numpy as np
import copy

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

if len(a) == 2:
    ans = max(a)
else:
    ans = 1
    a.sort()
    m = a[1]
    check = np.array([-1]*(m+1))
    
    for i in range(2, m+1):
        if check[i] == 0:
            continue
        cnt = 0
        for j in range(n):
            if a[j] % i > 0:
                cnt += 1
            if cnt >= 2:
                check[i::i] = 0
                break
            if j == n-1:
                ans = copy.deepcopy(i)

print(ans)

### FIXED CODE ###

import math

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

ar = a[::-1]
l = [0]
r = []

tmp1 = 0
tmp2 = 0
for i in range(n-1):
    tmp1 = math.gcd(tmp1, a[i])
    l.append(tmp1)
    tmp2 = math.gcd(tmp2, ar[i])
    r.append(tmp2)

r.reverse()
r.append(0)
ans = 1
for i in range(n):
    ans = max(ans, math.gcd(l[i], r[i]))
print(ans)
a,b,x=map(int,input().split())
print((x-a)%b)

### FIXED CODE ###

x=int(input())
a=int(input())
b=int(input())
print((x-a)%b)