Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

int(input())
vals    = input()

vals    = vals.split()
#　数値変換
vals    = list(map(lambda v:int(v), vals))

def solve(remain, a):
    '''bは指定必須とする'''

    if len(remain) == 1:
        if (a*remain[0]) % 4 == 0:
            return True
        return False

    # len > 1の場合

    for i in range(len(remain)):
        if (a * remain[i]) % 4 == 0:
            res = solve(remain[0:i] + remain[i+1:], remain[i])
            if res == True:
                return True



for i in range(len(vals)):
    a   = vals[i]
    if solve(vals[0:i] + vals[i+1:], a) == True:
        print("Yes")
        break;
else:
    print("No")


### FIXED CODE ###


input()
vals    = input()
vals    = vals.split()
vals    = list(map(lambda v:int(v), vals))


kisu    = 0
div4    = 0
div2    = 0

for e in (vals):
    if e % 4 == 0:
        div4    += 1
    elif e % 2 == 1:
        kisu    += 1
    else:
        div2    += 1

if div4 >= kisu:
    print("Yes")
elif div4 == kisu - 1 and len(vals) == div4 + kisu:
    print("Yes")
elif div2 == len(vals):
    print("Yes")
else:
    print("No")
### BUGGY CODE ###

N, M, Q = map(int, input().split())
b = [list(map(int, input().split())) for _ in range(Q)]
ans = 0
import itertools
a = []
for i in range(1, M+1):
    for _ in range(N):
        a.append(i)
for set_A in itertools.combinations(a, N):
    A = list(set_A)
    n = 0
    for i in range(Q):
        if A[b[i][1]-1] - A[b[i][0]-1] == b[i][2]:
            n += b[i][3]
    ans = max(ans, n)
print(ans)

### FIXED CODE ###

N, M, Q = map(int, input().split())
b = [list(map(int, input().split())) for _ in range(Q)]
ans = 0

import itertools
a = range(1, M+1)
for set_A in itertools.combinations_with_replacement(a, N):
    A = list(set_A)
    n = 0
    for i in range(Q):
        if A[b[i][1]-1] - A[b[i][0]-1] == b[i][2]:
            n += b[i][3]
    ans = max(ans, n)
print(ans)
### BUGGY CODE ###

from collections import deque
import sys
import bisect
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 8)
n = int(input())
a = list(map(int, input().split()))
edges = [[] for _ in range(n)]
for _ in range(n-1):
    u, v = map(int, input().split())
    edges[u-1].append(v-1)
    edges[v-1].append(u-1)

d = [0 for _ in range(n)]
memo = [[] for _ in range(n)]
seen = [False for _ in range(n)]
que = deque()
que.append(0)
memo[0] = [a[0]]
d[0] = 1
seen[0] = True

while len(que):
    cur = que.popleft()
    for to in edges[cur]:
        if not seen[to]:
            seen[to] = True
            memo[to] = memo[cur].copy()
            if memo[cur][-1] < a[to]:
                d[to] = d[cur] + 1
                memo[to].append(a[to])
            else:
                d[to] = d[cur]
                memo[to][bisect.bisect_left(memo[to], a[to])] = a[to]
            que.append(to)

for i in range(n):
    print(d[i])

### FIXED CODE ###

import bisect
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 8)

n = int(input())
a = list(map(int, input().split()))
edges = [[] for _ in range(n)]
for _ in range(n-1):
    u, v = map(int, input().split())
    edges[u-1].append(v-1)
    edges[v-1].append(u-1)

inf = 10 ** 10
d = [inf for _ in range(n)]
dp = [inf for _ in range(n)]

def dfs(cur, prev):
    memo = bisect.bisect_left(dp, a[cur])
    memo_v = dp[memo]
    dp[memo] = a[cur]
    d[cur] = bisect.bisect_left(dp, inf)

    for to in edges[cur]:
        if to != prev:
            dfs(to, cur)

    dp[memo] = memo_v

dfs(0, -1)
for i in range(n):
    print(d[i])
### BUGGY CODE ###

import numpy as np
N = int(input())
S = [input() for __ in range(N)]

S = np.array(S)
keys = set(S)
ans = {}
for key in keys:
    ans[key] = len(np.where(S == key)[0])
v = np.array(sorted(ans.values(),reverse = True))
k = sorted(ans.items())

keys = []
for k, val in sorted(ans.items(), key=lambda x: -x[1]):
    keys.append(k)

count = len(np.where(v == v[0])[0])
keys = keys[:count]
keys.sort()
for key in keys:
  print(key)

### FIXED CODE ###

N = int(input())
d = {}
for i in range(N):
    S = input()
    if S in d.keys():
        d[S] = d[S] + 1
    else:
        d[S] = 1
max_val = max(d.values())
max_k_ls = [kv[0] for kv in d.items() if kv[1]==max_val]
max_k_ls = sorted(max_k_ls)

print(*max_k_ls, sep="\n")
### BUGGY CODE ###

n,k=map(int,input().split())
a=[int(i) for i in input().split()]
c=1
k=min(k,40)


for j in range(k):
    b=[0 for i in range(n)]
    e=float("inf")
    for i in range(n):
        l=max(0,i-a[i])
        r=min(n-1,i+a[i])
        b[l]+=1
        if r+1<n:
            b[r+1]-=1
    for i in range(1,n):
        b[i]+=b[i-1]
        e=max(e,b[i-1])
    c+=1
    a=b
    if e==n:
        break
print(" ".join(map(str,a)))

### FIXED CODE ###

n,k=map(int,input().split())
a=[int(i) for i in input().split()]
k=min(k,41)

for j in range(k):
    b=[0 for i in range(n)]
    for i in range(n):
        l=max(0,i-a[i])
        r=min(n-1,i+a[i])
        b[l]+=1
        if r+1<n:
            b[r+1]-=1
    for i in range(1,n):
      b[i]+=b[i-1]
    a=b
print(" ".join(map(str,a)))
### BUGGY CODE ###

# -*- condig:utf-8 -*-

import sys
import collections

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

counter = [0 for _ in range(n+1)]
o = collections.defaultdict(int)
g = collections.defaultdict(list)

for i in range(n-1):
  a,b= map(int, input().split())
  g[a].append(b)
  g[b].append(a)

for i in range(q):
  p,x= map(int, input().split())
  o[p] += x


queue = [1]
parents = []
while queue:
  p = queue.pop(-1)
  parents.append(p)
  counter[p] += o[p]
  for i in g[p]:
    if not i in parents:
      queue.append(i)
      counter[i] += counter[p]
 
print(*counter[1:])

 
  


### FIXED CODE ###


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

ct = [0] * (n+1)
o = [0] * (n+1)
g = [[] for _ in range(n+1)]

for i in range(n-1):
  a,b= map(int, input().split())
  g[a].append(b)
  g[b].append(a)

for i in range(q):
  p,x= map(int, input().split())
  o[p] += x

todo = [1]
seen = [False] * (n+1)
while todo:
  p = todo.pop(-1)
  ct[p] += o[p]
  seen[p] = True
  for i in g[p]:
    if seen[i]:
      ct[p] += ct[i]
    else:
      todo.append(i)

print(*ct[1:])
### BUGGY CODE ###

N = int(input())
P = [int(i) for i in range(1,N+1)]
ans = 0
for i in range(1,N):
    ans += i%P[i]
print(ans)

### FIXED CODE ###

N = int(input())
N = N-1
ans = N*(N+1)//2
print(int(ans))
### BUGGY CODE ###

N,M,K=map(int, input().split())

MOD=998244353

def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])
            result %=MOD

    return result


ans=0

for i in range(K+1):
  temp=(M*(M-1)**(N-1-i)*cmb(N-1,i))%MOD
  ans+=temp

print(ans%MOD)

### FIXED CODE ###

N,M,K=map(int, input().split())

MOD=998244353

ans=0
temp2=1
#temp4=(M-1)**(N-1)%MOD

def getInvs(n, MOD):
  invs = [1] * (n+1)
  for x in range(2, n+1):
    invs[x] = (-(MOD//x) * invs[MOD%x]) % MOD
  return invs

invs = getInvs(max(N+3,M-1), MOD)

Vec=[0]*N
#inv=1
#for i in range(MOD-2):
#  inv*=M-1
#  inv%=MOD

'''
for i in range(K+1):
  if i == 0:
    temp1=M
    temp1*=(M-1)**(N-1)%MOD
    temp1%=MOD
    ans+=temp1*temp2%MOD
    #print(cmb)
  else:
    temp1*=invs[M-1]%MOD
    temp2*=(N-i)*invs[i]
    temp2%=MOD
    ans+=temp1*temp2%MOD
    cmb=cmb*(N-i-1)*i*invs[i]%MOD
    #print(cmb)
'''
for i in range(N):
  if i == 0:
    temp1=M
    Vec[N-i-1]=temp1
  else:
    temp1*=(M-1)*(N-i)
    temp1*=invs[i]
    temp1%=MOD
    Vec[N-i-1]=temp1


ans=sum(Vec[:K+1])

print(ans%MOD)
### BUGGY CODE ###

n, k = map(int, input().split())
p = list(map(int, input().split()))

p1 = []
for i in p:
  p1.append((i+1) / 2)
  
ans = 0

for i in range(n-k+1):
  if sum(p1[i:i+k]) > ans:
    ans = sum(p1[i:i+k])
   
  
print("{0:.12f}".format(ans))

### FIXED CODE ###

n, k = map(int, input().split())
p = list(map(int, input().split()))
  
m = sum(p[0: k])
sump = m

for i in range(1, n-k+1):
  sump = sump - p[i-1] + p[i+k-1]
  if m < sump:
    m = sump

ans = (m + k) / 2

print(ans)
### BUGGY CODE ###

import sys
input = sys.stdin.readline
n, m = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for _ in range(m)]
BC.sort(key=lambda x: -x[1])

extend = A.extend
[extend([ls[1] for _ in range(ls[0])]) for ls in BC]
A.sort(reverse=True)

print(sum(A[:n]))

### FIXED CODE ###

import sys

input = sys.stdin.readline
n, m = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for _ in range(m)]
BC.sort(key=lambda x: -x[1])

maxi = n*2
extend = A.extend
[extend([ls[1]] * ls[0]) for ls in BC if len(A) <= maxi]
A.sort(reverse=True)

print(sum(A[:n]))
### BUGGY CODE ###

# python には結構厳しいTLE・・・python以外のお勉強時間ないよ～( ;∀;)
# . から見た # の最大距離の方が楽ではあるが・・・
H, W = list(map(int, input().split()))
L = [[j for j in input()] for i in range(H)]
blacks = [[i, j] for i in range(H) for j in range(W) if L[i][j] == "#"]
black_count = len(blacks)

cands = [[-1, 0], [1, 0], [0, -1], [0, 1]]
all_count = H * W
result = 0
while black_count < all_count:
  next_steps = list(set([(black[0]+cand[0], black[1]+cand[1]) for black in blacks for cand in cands]))
  next_blacks = [[i,j] for i, j in next_steps if i >= 0 and i < H and j >= 0 and j < W and L[i][j] == "."]
  for i, j in next_blacks:
    L[i][j] = "#"
  black_count += len(next_blacks)
  blacks = next_blacks
  result += 1

print(result)


### FIXED CODE ###

# python には結構厳しいTLE・・・python以外のお勉強時間ないよ～( ;∀;)
# . から見た # の最大距離の方が楽ではあるが・・・
# 嫌いだけど def main も使ってみた．
from collections import deque
import copy

def main():
  H, W = list(map(int, input().split()))
  L = [[j=="#" for j in input()] for i in range(H)]
  q = deque([(i, j) for i in range(H) for j in range(W) if L[i][j]])
  cands = [(0, -1), (0, 1), (-1, 0), (1, 0)]
  result = 0
  while True:
    nq = deque()
    while q:
      i, j = q.popleft()
      if i > 0 and not L[i-1][j]:
        L[i-1][j] = True
        nq.append((i-1, j))
      if j > 0 and not L[i][j-1]:
        L[i][j-1] = True
        nq.append((i, j-1))
      if i < H-1 and not L[i+1][j]:
        L[i+1][j] = True
        nq.append((i+1, j))
      if j < W-1 and not L[i][j+1]:
        L[i][j+1] = True
        nq.append((i, j+1))
    if nq:
      q = copy.copy(nq)
    else:
      break    
    result += 1
  print(result)

if __name__ == "__main__":
  main()
### BUGGY CODE ###

s = input()

# now = 0
# left = 0
# right = 0
ans = []
for i in range(len(s) + 1):

    left = 0
    right = 0
    # 左側
    for j in range(i, 0, -1):
        if s[j - 1] != '<':
            break
        else:
            left += 1
    # 右側
    for j in range(i, len(s)):
        if s[j] != '>':
            break
        else:
            right += 1
    ans.append(max(left, right))
# print(ans)
print(sum(ans))


### FIXED CODE ###

s = input()

# now = 0
left = 0
right = 0
ans = []
for i in range(len(s) + 1):
    if left == 0:
        # 左側
        for j in range(i - 1, -1, -1):
            if s[j] != '<':
                break
            else:
                left += 1
    else:
        if s[i - 1] == '<':
            left += 1
        else:
            left = 0
    # 右側
    if right == 0:
        for j in range(i, len(s)):
            if s[j] != '>':
                break
            else:
                right += 1
    else:
        if i == len(s):
            right = 0
        elif s[i] == '>':
            right -= 1
        else:
            right = 0
    ans.append(max(left, right))
# print(ans)
print(sum(ans))
### BUGGY CODE ###

def knapsack(weights,values,capacity,n,memo):
    if(memo[n][capacity]!=-1):
        return memo[n][capacity]
    if(n==0 or capacity==0):
        return 0
    val=0
    if(weights[n-1]<=capacity):
        memo[n][capacity]=max(values[n-1]+knapsack(weights,values,capacity-weights[n-1],n-1,memo),knapsack(weights,values,capacity,n-1,memo))
        return memo[n][capacity]
    memo[n][capacity]=knapsack(weights,values,capacity,n-1,memo)
    return memo[n][capacity]

n,capacity=map(int,input().split())
weights=[0]*n
values=[0]*n
for i in range(n):
    weights[i],values[i]=map(int,input().split())
memo=[[-1]*(capacity+1) for i in range(n+1)]
print(knapsack(weights,values,capacity,n,memo))

### FIXED CODE ###

# from sys import stdin, stdout
n,capacity=map(int,input().split())
weights=[0]*n
values=[0]*n
for i in range(n):
    weights[i],values[i]=map(int,input().split())
dp=[[0]*(capacity+1) for i in range(n+1)]
for i in range(1,n+1):
    for j in range(1,capacity+1):
        if(weights[i-1]<=j):
            dp[i][j]=max(values[i-1]+dp[i-1][j-weights[i-1]],dp[i-1][j])
        else:
            dp[i][j]=dp[i-1][j]
print(dp[n][capacity])
### BUGGY CODE ###

import numpy as np
import math

def search(min_,max_,A,B,arr):
#    print(min_,max_)
    if min_==max_:
        return min_
    mid=(max_+min_)//2
    
    tmp=arr-mid*B
    
    if len(tmp)==0:
        return search(min_,mid,A,B,arr)
    
    tmp=map(lambda x:math.ceil(x/(A-B)),tmp)
    sum_=sum(list(tmp))
    if sum_<=mid:
        return search(min_,mid,A,B,arr)
    else:
        return search(mid+1,max_,A,B,arr)
    """
    while True:
        if k<0:
            if mid==min_:
                return max_
            else:
                #failure
                return search(mid,max_,A,B,arr[:L])
        elif len(tmp)==0:
            #success
            return search(min_,mid,A,B,arr)
        x=-tmp[0]
        tmp=np.delete(tmp,0)
        k-=x//(A-B)+(x%(A-B)>0)
    """
        
    
N,A,B=list(map(int,input().split()))
arr=[]

for i in range(N):
    h=int(input())
    arr.append(h)
arr=sorted(arr,reverse=True)
arr=np.array(arr)

max_=arr[0]//B+1
min_=arr[-1]//A

ans=search(min_,max_,A,B,arr)

print(ans)

### FIXED CODE ###

import math
"""
def search(min_,max_,A,B,arr):
#    print(min_,max_)
    if min_==max_:
        return min_
    mid=(max_+min_)//2
    
    tmp=arr-mid*B
    
    if len(tmp)==0:
        return search(min_,mid,A,B,arr)
    
    tmp=map(lambda x:math.ceil(x/(A-B)),tmp)
    sum_=sum(list(tmp))
    if sum_<=mid:
        return search(min_,mid,A,B,arr)
    else:
        return search(mid+1,max_,A,B,arr)

    while True:
        if k<0:
            if mid==min_:
                return max_
            else:
                #failure
                return search(mid,max_,A,B,arr[:L])
        elif len(tmp)==0:
            #success
            return search(min_,mid,A,B,arr)
        x=-tmp[0]
        tmp=np.delete(tmp,0)
        k-=x//(A-B)+(x%(A-B)>0)
"""
        
    
N,A,B=list(map(int,input().split()))
arr=[]

for i in range(N):
    arr.append(int(input()))

max_=max(arr)//B+1
min_=min(arr)//A

d=A-B

while min_!=max_:
    mid=(max_+min_)//2
    
    sum_=0
    for x in arr:
        sum_+=max(0,math.ceil((x-mid*B)/d))
        
    if sum_<=mid:
        max_=mid
    else:
        min_=mid+1

print(min_)
### BUGGY CODE ###

X=input()
a=list()
for i in range(len(X)):
    a.append(int(X[i:len(X)])%2019)
S=a.count(0)
for j in range(1,2018):
    b=a.count(j)
    S+=int(b*(b-1)/2)
print(S)  

### FIXED CODE ###

A=[0]*2019
s=input()
a=0
b=1
for i in range(len(s)):
    b=b%2019
    a=(a+int(s[len(s)-1-i])*b)%2019
    b=b*10
    A[a]+=1
x=A[0]
for j in range(2019):
    x+=int(A[j]*(A[j]-1)/2)
print(x)
### BUGGY CODE ###

def main():
    N = int(input())
    L = []
    for i in range(N):
        xi, li = map(int, input().split())
        s = xi - li
        f = xi + li
        L.append((s, f))
    
    L.sort(key=lambda x: x[1])

    ans = 0
    while L:
        e = L[0]
        L = [i for i in L if i[0] >= e[1]]
        ans += 1
    
    print(ans)

if __name__ == "__main__":
    main()



### FIXED CODE ###

def main():
    N = int(input())
    L = []
    for i in range(N):
        xi, li = map(int, input().split())
        s = xi - li
        f = xi + li
        L.append((f, s))
    
    L.sort()

    ans = 0
    finish = -float("inf")
    for i in L:
        if finish <= i[1]:
            ans += 1
            finish = i[0] 

    print(ans)

if __name__ == "__main__":
    main()
### BUGGY CODE ###

import numpy as np

N = int(input())
A = np.array(list(map(int, input().split())))
B = A.copy()
P = np.zeros((N), dtype='i')

INF = 10**18

ans = 0
for i in range(N):
    B[i] = INF
    P[i:] = np.arange(0, N - i)
    P[:i] = np.arange(1, i + 1)[::-1]
    # print('P', P)
    ans += np.count_nonzero(B + A[i] == P)
    # if i >= 3:
    #     break
print(ans)


### FIXED CODE ###

import sys
from collections import defaultdict

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, *A = map(int, read().split())

L = defaultdict(int)
R = defaultdict(int)
for i, x in enumerate(A, 1):
    l = i + x
    r = i - x
    L[l] += 1
    R[r] += 1
# print('L', L)
# print('R', R)
ans = 0
for key, l_value in L.items():
    r_value = R[key]
    ans += l_value * r_value
print(ans)
# memo = defaultdict(int)
# answer = 0
# for i, x in enumerate(A, 1):
#     answer += memo[i - x]
#     memo[x + i] += 1

# print('memo', memo)
# print(answer)
### BUGGY CODE ###

k = int(input())
a = list(map(int, input().split()))
def solve():

    if a[k-1] != 2:
        print(-1)
        return

    mi = 2
    mx = 2

    for i in range(k):
        j = k-i-1

        mx = mx + a[j] - 1

        if j == 0:
            pass
        else:
            na = a[j-1]
            # if mx < na:
            #     print(-1)
            #     return
            chk = False
            for c in range(mi, mx+1):
                if c % na == 0:
                    chk = True
            if chk == False:
                print(-1)
                return

            if mi%na != 0:
                mi = mi + (na - mi%na)

            if mx%na != 0:
                mx = mx - (mx % na)

    print(mi, mx)
solve()


### FIXED CODE ###

k = int(input())
a = list(map(int, input().split()))
def solve():

    if a[k-1] != 2:
        print(-1)
        return

    mi = 2
    mx = 2

    for i in range(k):
        j = k-i-1

        mx = mx + a[j] - 1

        if j == 0:
            pass
        else:
            na = a[j-1]
            
            if mx % na != 0 and mi % na != 0 and ((mx % na) - (mi % na)) == (mx - mi):
                print(-1)
                return

            if mi%na != 0:
                mi = mi + (na - mi%na)

            if mx%na != 0:
                mx = mx - (mx % na)

    print(mi, mx)
solve()
### BUGGY CODE ###

#-*- using:utf-8 -*-

def euclidean(a,b):
    if b == 0:
        return a
    else:
        return  euclidean(b,a%b)

def gcd(a,b):
#    print("gcd %d %d" %(a,b))
    n = 0
    if a == b:
        return a
    elif a > b:
        n = euclidean(a,b)

    elif a < b:
        n = euclidean(b,a)

    else:
        pass

    return n 

def blackboard(n,a):
    candidate = 0
    maxnum = 0
    b = list(map(int,a))


    k = n - 1
    for j in range(n):
        c = [b[p] for p in range(n)]
        del c[j]
#        print("b %s" %b)
#        print("c %s" %c)
        ml = 0
        mr = 0
        for i in range(k):
#            print("i=>%d" %i)

            ml = gcd(ml,c[i])
            mr = gcd(mr,c[k-i-1])
#            print("ml %d" %ml)
#            print("mr %d" %mr)
            if i == k-i-1:
                break
#        print("ml %d mr %d" %(ml,mr))
        candidate = gcd(ml,mr)
#        print("!!!!!!!!!!!!!!!!candidate %d max %d" %(candidate,maxnum))
        if candidate > maxnum:
            maxnum = candidate
            
#        print("maxnum %d" %maxnum)
        


    return maxnum


if __name__ == '__main__':
    n = raw_input()
    a = raw_input().split()
    global m 
    m = int(n)
    print("%d" %(blackboard(m,a)))


### FIXED CODE ###

#-*- using:utf-8 -*-
def euclidean(a,b):
    if b == 0:
        return a
    else:
        return  euclidean(b,a%b)

def gcd(a,b):
#    print("gcd %d %d" %(a,b))
    n = 0
    if a == b:
        return a
    elif a > b:
        n = euclidean(a,b)

    elif a < b:
        n = euclidean(b,a)

    else:
        pass

    return n

def blackboard(n,a):
    candidate = 0
    maxnum = 0
    b = list(map(int,a))

    left = [0] * (n+1)
    right = [0] * (n+1)
    for i in range(n):
        left[i+1] = gcd(left[i],b[i])
        right[i+1] = gcd(right[i],b[n - i -1])

    for i in range(n):
        candidate = gcd(left[i],right[n-i-1])
        if candidate > maxnum:
            maxnum = candidate

    return maxnum


if __name__ == '__main__':
    n = raw_input()
    a = raw_input().split()
    m = int(n)
    print("%d" %(blackboard(m,a)))
### BUGGY CODE ###

def topologicalsort(N,E):
    V = [0]*N
    for i in range(N):
        for y in E[i]:
            V[y] += 1
    S = [ i for i in range(N) if V[i] == 0]
    SORTED = []
    while S:
        s = S.pop(0)
        SORTED.append(s)
        for t in E[s]:
            V[t] -= 1
            if V[t] == 0:
                S.append(t)
    return SORTED
    
N, M = map( int, input().split())
E = [ [] for _ in range(N)]
for _ in range(M):
    x, y = map( int, input().split())
    x, y = x-1, y-1
    E[x].append(y)
V = topologicalsort(N, E)
ANS = [0]*N
for i in range(N):
    v = V[i]
    t = ANS[v]+1
    for e in E[v]:
        if t > ANS[e]:
            ANS[e] = t
print( max(ANS))


### FIXED CODE ###

import heapq
def topologicalsort(N,E):
    V = [0]*N
    for i in range(N):
        for y in E[i]:
            V[y] += 1
    S = [ i for i in range(N) if V[i] == 0]
    SORTED = []
    while S:
        s = S.pop(0)
        SORTED.append(s)
        for t in E[s]:
            V[t] -= 1
            if V[t] == 0:
                S.append(t)
    return SORTED
    
N, M = map( int, input().split())
E = [ [] for _ in range(N)]
for _ in range(M):
    x, y = map( int, input().split())
    x, y = x-1, y-1
    E[x].append(y)
V = topologicalsort(N, E)
ANS = [0]*N
for i in range(N):
    v = V[i]
    t = ANS[v]+1
    for e in E[v]:
        if t > ANS[e]:
            ANS[e] = t
print( max(ANS))
### BUGGY CODE ###

import math
N = int(input())
A = [int(_) for _ in input().split()]

ans = A[0]

for i in range(1, N):
    ans *= A[i]

if ans != 0:
    ans_size = int(math.log10(ans) + 1)
else:
    ans_size = 1

if ans_size >= 19 and ans - (10**18) >= 1:
    print(-1)
else:
    print(ans)


### FIXED CODE ###

import math
N = int(input())
A = [int(_) for _ in input().split()]

ans = A[0]
isOver = False

if 0 in A:
    print(0)
else:
    for i in range(1, N):
        ans *= A[i]
        ans_size = int(math.log10(ans) + 1)
        if ans_size >= 19 and ans - (10**18) >= 1:
            isOver = True
            break

    if isOver:
        print(-1)
    else:
        print(ans)
### BUGGY CODE ###

def Serch():
    unit = [2001]
    for j in Tree:
        for i in range(1, n):
            G[j][i] = int(G[j][i])
            if G[j][i] != -1 and i not in Tree:
                unit.append(G[j][i])
    for j in Tree:
        for i in range(1, n):
            if G[j][i] == min(unit) and i not in Tree:
                ans.append(int(G[j][i]))
                Tree.append(i)
                Serch()
                break


n = int(input())
G = []
for i in range(n):
    G.append(input().split())

ans = []
Tree = [0]
Serch()
print(sum(ans))

### FIXED CODE ###

n = int(input())
G = []
for i in range(n):
    G.append(input().split())
    for j in range(len(G[i])):
        G[i][j] = int(G[i][j])

ans = 0
mincost = [2001] * n
flag = [0] * n
mincost[0] = 0
while True:
    v = -1
    for j in range(n):
        if flag[j] != 1 and (v == -1 or mincost[j] < mincost[v]):
            v = j
    if v == -1:
        break
    flag[v] = 1
    ans += mincost[v]
    for j in range(n):
        if G[v][j] == -1: continue
        mincost[j] = min(mincost[j], G[v][j])

print(ans)