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

import sys
import time
sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
N = int(input())

groups = []

def dfs(s, n):
    if n == N:
        bits = [-1] * N
        for i, ss in enumerate(s):
            if bits[i] != -1:
                continue
            for ii in range(i+1, N):
                if s[ii] == ss:
                    bits[ii] = i
        if bits not in groups:
            groups.append(bits)
            print(s)
        return
    for ns in 'abcdefghijklmnopqrstuvwxyz':
        dfs(s+ns, n+1)

dfs('', 0)

### FIXED CODE ###

import sys
import time
sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
N = int(input())

def dfs(s, n, m):
    if n > N:
        print(''.join([chr(ss) for ss in s]))
        return True
    for ns in range(97, m+2):
        s[n-1] = ns
        dfs(s, n+1, max(m, ns))

s = [0] * N
dfs(s, 1, 96)
### BUGGY CODE ###

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

def comb(n, r):
    return math.factorial(n) // math.factorial(n - r)

maxi = 0
# print(n*99//100)
for i in range(n-1, n-2, -1):
    key = a[i] // 2
    ok = n
    ng = -1
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if key <= a[mid]: ok = mid
        else: ng = mid
    if ok < i: 
        if comb(a[i], a[ok]) > maxi:
            maxi = comb(a[i], a[ok])
            ans = [a[i], a[ok]]
    if ng >= 0: 
        if comb(a[i], a[ng]) > maxi:
            maxi = comb(a[i], a[ng])
            ans = [a[i], a[ng]]
print("{} {}". format(ans[0], ans[1]))

### FIXED CODE ###

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

def comb(n, r):
    return math.factorial(n) // math.factorial(n - r)

maxi = 0
i = -1
key = a[i] // 2
for j in range(n):
    if a[j] > key:
        break
# print(j, n-1)
# print(j, key, a)
if abs(a[j-1] - key) >= abs(a[j] - key) and j < n-1:
    ans = [a[i], a[j]]
else:
    ans = [a[i], a[j-1]]
# ok = n
# ng = -1
# while abs(ok - ng) > 1:
#     mid = (ok + ng) // 2
#     if key <= a[mid]: ok = mid
#     else: ng = mid
# if ok < i: 
#     if comb(a[i], a[ok]) > maxi:
#         maxi = comb(a[i], a[ok])
#         ans = [a[i], a[ok]]
# if ng >= 0: 
#     if comb(a[i], a[ng]) > maxi:
#         maxi = comb(a[i], a[ng])
#         ans = [a[i], a[ng]]
print("{} {}". format(ans[0], ans[1]))
### BUGGY CODE ###

s = input()
mod = 2019
ls = len(s)
cnt = 0
for i in range(ls-3):
    for j in range(i+3,ls):
        c = int(s[i:j+1])
        if c%mod ==0:
            cnt+=1
print(cnt)

### FIXED CODE ###

s = input()
res = 0
m = 1
p =[0]*2019
for i in map(int,s[::-1]):
    res +=i*m
    res %=2019
    p[res] +=1
    m *=10
    m %=2019
print(p[0]+sum([i*(i-1)//2 for i in p]))
### BUGGY CODE ###

n=int(input())
list=[]
for i in range(n):
  a=input()
  if a not in list:
    list.append(a)
print(len(list))



### FIXED CODE ###

from collections import Counter
n=int(input())
list=[]
for i in range(n):
  list.append(input())
a=Counter(list)
print(len(a))
### BUGGY CODE ###

import sys
from itertools import product

read = sys.stdin.readline
X, Y, Z, K = map(int, read().split())
lst_A = sorted(map(int, read().split()), reverse=True)
lst_B = sorted(map(int, read().split()), reverse=True)
lst_C = sorted(map(int, read().split()), reverse=True)


lst_AB = sorted([a+b for a, b in product(lst_A, lst_B)], reverse=True)
lst_AB_K = lst_AB[:K]
lst_ABC = sorted([ab+c for ab, c in product(lst_AB_K, lst_C)], reverse=True)
lst_ABC_K = lst_ABC[:K]


for i in range(K):
    print(lst_ABC_K[i])


### FIXED CODE ###

import sys
from itertools import product


X, Y, Z, K = map(int, input().split())
lst_A = list(map(int, input().split()))
lst_B = list(map(int, input().split()))
lst_C = list(map(int, input().split()))
lst_A.sort(reverse=True)
lst_B.sort(reverse=True)
lst_C.sort(reverse=True)

# lst_A_K = lst_A[:K]
# lst_B_K = lst_B[:K]
lst_C_K = lst_C[:K]


lst_AB = sorted([a+b for a, b in product(lst_A, lst_B)], reverse=True)
lst_AB_K = lst_AB[:K]

lst_ABC = sorted([ab+c for ab, c in product(lst_AB_K, lst_C_K)], reverse=True)
lst_ABC_K = lst_ABC[:K]

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

from collections import defaultdict
#from functools import lru_cache
import itertools

def main():
    N = int(input())
    A = tuple(int(c) for c in input().split(' '))
    '''
    L = []
    R = []
    for i, a in enumerate(A):
        L.append(i+a)
        R.append(i-a)
    '''
    L = [i+a for i, a in enumerate(A)]
    R = [i-a for i, a in enumerate(A)]
    #print(L)
    #print(R)

    #はじめdefaultdict(list)としてiの候補を追加していったが、iとjは重複しないのでチェックが不要
    L_t = defaultdict(int)
    for i, l in enumerate(L):
        L_t[l] += 1
    R_t = defaultdict(int)
    for j, r in enumerate(R):
        R_t[r] += 1

    x_max = max(L)
    x_min = min(R)
    cnt = 0
    for x in range(x_min, x_max+1):
        l_candidate = L_t[x]
        r_candidate = R_t[x]

        cnt += l_candidate * r_candidate

    print(cnt)


if __name__ == "__main__":
    main()

### FIXED CODE ###

#解説を見て実装
from collections import Counter

def main():
    N = int(input())
    A = tuple(int(c) for c in input().split(' '))
    L = [i+a for i, a in enumerate(A)]
    R = [i-a for i, a in enumerate(A)]
    #print(L)
    #print(R)

    #はじめL_t = defaultdict(list)としてiの候補を追加していったが、iとjは重複しないのでチェックが不要
    L_t = Counter(L)
    R_t = Counter(R)
    cnt = 0
    x_candidate = set(L) & set(R)
    for x in x_candidate:
        l_candidate = L_t[x]
        r_candidate = R_t[x]
        cnt += l_candidate * r_candidate

    print(cnt)

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

N = int(input())
m = 0

for n in range(1,N):
    if n == N:
        m += 0
    else:
        m += n % (n+1)
print(m)

### FIXED CODE ###

n = int(input())
print(int((n-1)*n//2))
### BUGGY CODE ###

# -*- coding: utf-8 -*-

import sys
import copy

sys.setrecursionlimit(1000000)

# input = sys.stdin.readline

# ~~~~~~~~~~~~~~~~~~~~~_(＾～＾ ｣ ∠)_~~~~~~~~~~~~~~~~~~

R, G, B, N = map(int, input().split())

ans = 0
for r in range(3001):
    for g in range(3001):
        ball = r * R + g * G
        d = N - ball
        if d >= 0 and d % B == 0:
            ans += 1
        # elif d < 0:
        #     break

print(ans)

### FIXED CODE ###

# -*- coding: utf-8 -*-

import sys
import copy

sys.setrecursionlimit(1000000)

# input = sys.stdin.readline

# ~~~~~~~~~~~~~~~~~~~~~_(＾～＾ ｣ ∠)_~~~~~~~~~~~~~~~~~~

R, G, B, N = map(int, input().split())

ans = 0
for r in range(3001):
    for g in range(3001):
        ball = r * R + g * G
        d = N - ball
        if d >= 0 and d % B == 0:
            ans += 1
        # elif d < 0:
        #     break

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

from collections import Counter

S = input()
n = len(S)
a = [int(S)]
cnt = 0

for i in range(n):
    a.append(a[i] - int(S[i])*(10**(n-i-1)))

a = Counter(list(map(lambda x: x%2019, a)))


for k, v in a.items():
    cnt += v*(v-1)//2

print(cnt)

### FIXED CODE ###

import sys

input = sys.stdin.readline

S = input().rstrip()
n = len(S)
l = [0]*2019
d = 10

t = int(S[n-1])
l[t%2019] += 1

l[0] += 1

for i in range(n-2, -1, -1):
    t += int(S[i])*d%2019
    l[t%2019] += 1 
    d *= 10
    d %= 2019

ans = 0

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

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

# -*- coding: utf-8 -*-
"""
Created on Wed Jun 24 20:53:22 2020

@author: NEC-PCuser
"""

if __name__ == '__main__':
    K = int(input())
    n = len(input())
    mod = 10**9+7 #出力の制限
    #25 25 a 25 25 25 b 25 25  c  26 26
    cmb = 1
    ans = 0
    for i in range(0, K + 1):
        ans1 = (pow(25, i, mod) * cmb) % mod
        ans2 = pow(26, K - i, mod)
        cmb = (cmb * (n + i) // (i + 1)) 
        ans = (ans + (ans1 * ans2) % mod) % mod
    
    
    print(ans)
        

### FIXED CODE ###

n = int(input())
s = input()
 
S = len(s)
mod = 10 ** 9 + 7
 
tmp_ans = pow(26, n, mod)
div = pow(26, -1, mod)
 
ans = tmp_ans
 
for i in range(1, n+1):
    tmp_ans = (tmp_ans * 25 * div) % mod
    tmp_ans = ((tmp_ans * (S-1+i)) * pow(i, -1, mod)) % mod
    ans = (ans + tmp_ans) % mod
 
ans %= mod
 
print(ans)
### BUGGY CODE ###

#!usr/bin/env python3
import sys
import math
import string
import collections
import fractions
import random
from operator import itemgetter
import itertools
from collections import deque
import copy
import heapq
from bisect import bisect, bisect_left, bisect_right

MOD = 10 ** 9 + 7
INF = 10 ** 18
input = lambda: sys.stdin.readline().strip()

sys.setrecursionlimit(10 ** 8)

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

dp = [[INF] * (N + 10) for _ in range(N + 10)]
dp2 = [[0] * (N + 10) for _ in range(N + 10)]

for l in range(N):
    dp[l][l] = a[l]

for i in range(N - 2, -1, -1):
    for j in range(i + 1, N):
        dp2[i][j] = min(dp[i][k] + dp2[k + 1][j] + dp2[i][k] + dp[k + 1][j] for k in range(i, j))
        for val in ([dp[i][k] + dp2[k + 1][j] + dp2[i][k] + dp[k + 1][j], k] for k in range(i, j)):
            if val[0] == dp2[i][j]:
                k = val[1]
        dp[i][j] = dp[i][k] + dp[k + 1][j]
print(dp2[0][N - 1])


### FIXED CODE ###

#!usr/bin/env python3
import sys
import math
import string
import collections
import fractions
import random
from operator import itemgetter
import itertools
from collections import deque
import copy
import heapq
from bisect import bisect, bisect_left, bisect_right

MOD = 10 ** 9 + 7
INF = 10 ** 18
input = lambda: sys.stdin.readline().strip()

sys.setrecursionlimit(10 ** 8)

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

dp = [[INF] * (N + 10) for _ in range(N + 10)]
dp2 = [[0] * (N + 10) for _ in range(N + 10)]

for l in range(N):
    dp[l][l] = a[l]

for i in range(N - 2, -1, -1):
    for j in range(i + 1, N):
        dp2[i][j] = min(dp[i][k] + dp2[k + 1][j] + dp2[i][k] + dp[k + 1][j] for k in range(i, j))
        for val in ([dp[i][k] + dp2[k + 1][j] + dp2[i][k] + dp[k + 1][j], k] for k in range(i, j)):
            if val[0] == dp2[i][j]:
                k = val[1]
        dp[i][j] = dp[i][k] + dp[k + 1][j]
print(dp2[0][N - 1])
### BUGGY CODE ###

K = int(input())
x = 7
count = 1

if K%2 == 0 or K%5 == 0:
  print("-1")
  exit()
for i in range(100000):
  if x % K == 0:
    print(count)
    exit(0)
  else:
    x = 10*x + 7
    count += 1
print("-1")

### FIXED CODE ###

def calc(k):
    cur = 0
    for i in range(1, 10 ** 7):
        cur *= 10
        cur += 7
        cur %= k
        if cur == 0:
            return i

    return -1


k = int(input())
print(calc(k))
### BUGGY CODE ###

from math import ceil

def a():
    N = int(input())
    A = list(map(int,input().split()))
    INF = 10**13
    if N == 0:
        if A[0] == 1:
            return 1
        else:
            return -1

    BMAX = [INF] * (N+1)
    BMIN = [1] * (N+1)

    a = 1
    for i in range(N+1):
        BMAX[i] = min(BMAX[i] , a - A[i])
        a = BMAX[i] * 2
    BMAX[N] = 0
    BMIN[0] = 1
    BMIN[N] = 0

    for i in range(N-1,-1,-1):
        BMAX[i] = min(BMAX[i],BMAX[i+1]+A[i+1])
        BMIN[i] = max(BMIN[i],ceil((BMIN[i+1]+A[i+1])/2))

    for i in range(1,N+1):
        BMAX[i] = min(BMAX[i],BMAX[i-1]*2-A[i])
        BMIN[i] = max(BMIN[i],BMIN[i-1]-A[i])

    ans = 0
    for i in range(0,N+1):
        if BMIN[i] > BMAX[i]:
            return -1
        ans += (BMAX[i] + A[i])
    return ans

print(a())

### FIXED CODE ###

from math import ceil

def a():
    N = int(input())
    A = list(map(int,input().split()))
    INF = 10**13
    if N == 0:
        if A[0] == 1:
            return 1
        else:
            return -1

    BMAX = [INF] * (N+1)
    BMIN = [1] * (N+1)

    BMAX[0] = 1 - A[0]
    BMAX[N] = 0
    BMIN[0] = 1
    BMIN[N] = 0

    for i in range(N-1,-1,-1):
        BMAX[i] = min(BMAX[i],BMAX[i+1]+A[i+1])
        BMIN[i] = max(BMIN[i],ceil((BMIN[i+1]+A[i+1])/2))

    if BMIN[0] > BMAX[0]:
        return -1

    for i in range(1,N+1):
        BMAX[i] = min(BMAX[i],BMAX[i-1]*2-A[i])
        BMIN[i] = max(BMIN[i],BMIN[i-1]-A[i])
        if BMIN[i] > BMAX[i]:
            return -1
        
    return sum(BMAX)+sum(A)

print(a())
### BUGGY CODE ###

n,m=map(int,input().split())
r=[[] for x in range(n)]
for c in range(m):
    a,b=map(int,input().split())
    r[a-1].append(b-1)
    r[b-1].append(a-1)
s=[-1]*n
u=[0]
v=[]
k=1
for c in range(10**5):
    for d in u:
        for e in r[d]:
            if s[e]==-1:
                s[e]=d
                k+=1
                v.append(e)
    if k==n:
        break
    u=v
print('Yes')
for c in range(n-1):
    print(s[c+1]+1)

### FIXED CODE ###

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

ans_list=[-1]*n

queue=[0]

while queue:
    qi=queue.pop(0)
    for gi in g[qi]:
        if ans_list[gi]==-1:
            queue.append(gi)
            ans_list[gi]=qi

print("Yes")
for ans in ans_list[1:]:
    print(ans+1)
### BUGGY CODE ###

N,K=map(int,input().split())
Points=[[int(i) for i in input().split()] for i in range(N)]
List_x=[Points[i][0] for i in range(N)]
List_x.sort(key=lambda x:x)
List_y=[Points[i][1] for i in range(N)]
List_y.sort(key=lambda x:x)
n=0
S=[]
for x1 in range(N-1):
  for x2 in range(x1+1,N):
    for y1 in range(N-1):
      for y2 in range(y1+1,N):
        for p in Points:
          if List_x[x1]<=p[0]<=List_x[x2] and List_y[y1]<=p[1]<=List_y[y2]:
            n+=1
        if n>=K:
          x_delta=List_x[x2]-List_x[x1]
          y_delta=List_y[y2]-List_y[y1]
          S.append(x_delta*y_delta)
        n=0
print(min(S))          
          

### FIXED CODE ###

N,K=map(int,input().split())
Points=[[int(i) for i in input().split()] for i in range(N)]
List_x=[Points[i][0] for i in range(N)]
List_x.sort(key=lambda x:x)
List_y=[Points[i][1] for i in range(N)]
List_y.sort(key=lambda x:x)
n=0
Y=0
S=[]
for x1 in range(N-1):
  for x2 in range(x1+K-1,N):
    for y1 in range(N-1):
      for y2 in range(max([y1+K-1,Y]),N):
        for p in Points:
          if List_x[x1]<=p[0]<=List_x[x2] and List_y[y1]<=p[1]<=List_y[y2]:
            n+=1
          if n==K:
            x_delta=List_x[x2]-List_x[x1]
            y_delta=List_y[y2]-List_y[y1]
            S.append(x_delta*y_delta)
            break
        if n>=K:
          n=0
          Y=y2
          break  
        n=0
    Y=0    
print(min(S))
### BUGGY CODE ###

n = int(input())
l = list(map(int,input().split()))
ls = sorted(l)

count = 0
for i in range(n):
    for j in range(i + 1, n):
        x, y = ls[i], ls[j]
        tri_xy = [k for k in ls[j + 1:] if k < x + y]
        count += len(tri_xy)
print(count)

### FIXED CODE ###

import bisect
n = int(input())
l = list(map(int,input().split()))
ls = sorted(l)

count = 0
for i in range(n):
    for j in range(i+1, n):
        index = bisect.bisect_left(ls[j+1:], ls[i] + ls[j])
        count += index
print(count)
### BUGGY CODE ###

MOD=998244353
N,K=map(int,input().split())

lrlist=[]
for _ in range(K):
  l,r=map(int,input().split())
  lrlist.append((l,r))
#print(lrlist)

#A1～Aiまでの和 O(logN)
def BIT_query(idx):
  res_sum = 0
  while idx > 0:
    res_sum += BIT[idx]
    idx -= idx&(-idx)
  return res_sum
#Ai += x O(logN)
def BIT_update(idx,x):
  while idx <= N:
    BIT[idx] += x
    idx += idx&(-idx)
  return  

#初期化
BIT=[0]*(N+1)
BIT_update(1,1)

for i in range(2,N+1):
  for l,r in lrlist:
    left=i-r
    right=i-l    
    if right<1:
      continue
    elif left<1:
      left=1
    
    sum_intv=BIT_query(right)-BIT_query(left-1)
    BIT_update(i,sum_intv)
    
print((BIT_query(N)-BIT_query(N-1))%MOD)

### FIXED CODE ###

MOD=998244353
N,K=map(int,input().split())

lrlist=[]
for _ in range(K):
  l,r=map(int,input().split())
  lrlist.append((l,r))
#print(lrlist)

class SegTree:
  #init(init_val, ide_ele): 配列init_valで初期化 O(N)
  def __init__(self, init_val, segfunc, ide_ele):
    #init_val: 配列の初期値
    #segfunc: 区間にしたい操作
    #ide_ele: 単位元
    #n: 要素数
    #num: n以上の最小の2のべき乗
    #tree: セグメント木(1-index)
    n = len(init_val)
    self.segfunc = segfunc
    self.ide_ele = ide_ele
    self.num = 1 << (n - 1).bit_length()
    self.tree = [ide_ele] * 2 * self.num
    # 配列の値を葉にセット
    for i in range(n):
      self.tree[self.num + i] = init_val[i]
    # 構築していく
    for i in range(self.num - 1, 0, -1):
      self.tree[i] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1])

  #update(k, x): k番目の値をxに更新 O(logN)
  def update(self, k, x):
    #k番目の値をxに更新
    #k: index(0-index)
    #x: update value
    k += self.num
    self.tree[k] = x
    while k > 1:
      self.tree[k >> 1] = self.segfunc(self.tree[k], self.tree[k ^ 1])
      k >>= 1

  #query(l, r): 区間[l, r)をsegfuncしたものを返す O(logN)
  def query(self, l, r):
    #[l, r)のsegfuncしたものを得る
    #l: index(0-index)
    #r: index(0-index)
    res = self.ide_ele
    l += self.num
    r += self.num
    while l < r:
      if l & 1:
        res = self.segfunc(res, self.tree[l])
        l += 1
      if r & 1:
        res = self.segfunc(res, self.tree[r - 1])
      l >>= 1
      r >>= 1
    return res
  
#segfunc
def segfunc(x,y):
  return x+y #区間和
#ide_ele
ide_ele=0 #区間和

#初期化
seg=SegTree([0]*(N+1), segfunc, ide_ele)
seg.update(1,1)

for i in range(2,N+1):
  for l,r in lrlist:
    left=i-r
    right=i-l    
    if right<1:
      continue
    elif left<1:
      left=1
    
    current=seg.query(i,i+1)
    sum_intv=seg.query(left,right+1)
    seg.update(i,(current+sum_intv)%MOD)
    #print(i,left,right,current,sum_intv)
    
print(seg.query(N,N+1))
### BUGGY CODE ###

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

ans = 1
for i in range(N) :
    ans = ans * A[i]
if(ans > 10**18):
    ans = -1
print(ans)

### FIXED CODE ###

def solve(N,A) :
    ans = 1
    for i in range(N) :
        if(A[i] == 0) :
            print(0)
            return
    for i in range(N) :
        ans = ans * A[i]
        if(ans > 10**18):
            ans = -1
            break
    print(ans)
    
N = int(input())
A = list(map(int, input().split()))
solve(N,A)
### BUGGY CODE ###

N = int(input())

A = [0]*N
for i in range(N):
    A[i] = int(input())


for i in range(N):
    dammy = A[i]
    A[i]=0
    print(max(A))
    A[i] = dammy


### FIXED CODE ###

N = int(input())


A = [0]*N
for i in range(N):
    A[i] = int(input())

dammyA = sorted(A)
maxfir = dammyA[-1]
maxsec = dammyA[-2]


for i in range(N):
    if A[i]==maxfir:
        print(maxsec)
    else:
        print(maxfir)
### BUGGY CODE ###

from sys import stdin

n = int(stdin.readline().rstrip())
point = 0
for i in range(1,n+1):
    point += i%n
print(point)

### FIXED CODE ###

from sys import stdin

n = int(stdin.readline().rstrip())
point = n*(n-1)//2
print(point)
### BUGGY CODE ###

class Dictionary:
    def __init__(self):
        self.dic = []
    def insert(self, key):
        self.dic.append(key)
    def find(self, key):
        return key in self.dic

dic = Dictionary()
n = int(input())
for i in range(n):
    cmd = input().split()
    if cmd[0] == "insert":
        dic.insert(cmd[1])
    elif cmd[0] == "find":
        if dic.find(cmd[1]):
            print("yes")
        else:
            print("no")
    else:
        print("wrong command")


### FIXED CODE ###

dic = set()
n = int(input())
for i in range(n):
    cmd, val = input().split()
    if cmd == "insert":
        dic.add(val)
    elif cmd == "find":
        print("yes" if val in dic else "no")
    else:
        print("wrong command")
### BUGGY CODE ###

from scipy.sparse.csgraph import shortest_path #shortest_path(csgraph=graph)
#from scipy.sparse.csgraph import dijkstra
from scipy.sparse import csr_matrix

from collections import* #defaultdict Counter deque appendleft
from fractions import gcd
from functools import* #reduce
from itertools import* #permutations("AB",repeat=2) combinations("AB",2) product("AB",2) groupby accumulate
from operator import mul,itemgetter
from bisect import* #bisect_left bisect_right
from heapq import* #heapify heappop heappushpop
from math import factorial,pi
from copy import deepcopy
import sys
#input=sys.stdin.readline  #危険！基本オフにしろ！
sys.setrecursionlimit(10**8)


def main():
    n=int(input())
    grid=[list(map(int,input().split()))for i in range(n)]
    p=shortest_path(csgraph=csr_matrix(grid))
    q=[list(i) for i in p]
    
    if q!=grid:
        print(-1)
    else:
        for i in range(n):
            p[i][i]=float("inf")
        ans=0
        #print(p)
        for i in range(n):
            for j in range(i):
                if p[i][j]<min(p[i])+min(p[j]):
                    ans+=p[i][j]
        print(int(ans))




if __name__ == '__main__':
    main()

### FIXED CODE ###

import numpy as np
#from numpy import*
#from scipy.sparse.csgraph import shortest_path #shortest_path(csgraph=graph)
#from scipy.sparse.csgraph import dijkstra
from scipy.sparse.csgraph import floyd_warshall
from scipy.sparse import csr_matrix

from collections import* #defaultdict Counter deque appendleft
from fractions import gcd
from functools import* #reduce
from itertools import* #permutations("AB",repeat=2) combinations("AB",2) product("AB",2) groupby accumulate
from operator import mul,itemgetter
from bisect import* #bisect_left bisect_right
from heapq import* #heapify heappop heappushpop
from math import factorial,pi
from copy import deepcopy
import sys
#input=sys.stdin.readline  #危険！基本オフにしろ！
sys.setrecursionlimit(10**8)

def main():
    n=int(input())
    grid=[list(map(int,input().split()))for i in range(n)]
    p=floyd_warshall(csgraph=csr_matrix(grid))
    q=[list(i) for i in p]
    
    if q!=grid:
        print(-1)
    else:
        for i in range(n):
            p[i][i]=float("inf")
        ans=0
        for i in range(n):
            for j in range(i):
                if i==j:
                    continue
                if p[i][j]<min(np.array(p[i])+np.array(p[j])):
                    
                    ans+=p[i][j]
        print(int(ans))

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

#!/usr/bin/env python3
import sys
input = sys.stdin.readline
INF = 10**10

h, n = [int(item) for item in input().split()]
ab = []
for i in range(n):
    a, b = map(int, input().split())
    ab.append((a, b))
dp = [[INF] * (2 * 10**4) for _ in range(n + 1)]
dp[0][0] = 0
for i in range(1, n+1):
    v, w = ab[i-1]
    for j in range(2 * 10**4):
        if j < v:
            dp[i][j] = dp[i-1][j]
        elif dp[i-1][j] > dp[i][j-v] + w:
            dp[i][j] = dp[i][j-v] + w
        else:
            dp[i][j] = dp[i-1][j]
ans = min(dp[n][h:])
print(ans)

### FIXED CODE ###

#!/usr/bin/env python3
import sys
input = sys.stdin.readline
INF = 10**9

def main(): 
    h, n = [int(item) for item in input().split()]
    MAX_LEN = h + 10**4 - 2
    dp = [INF] * MAX_LEN
    dp[0] = 0
    vw = []
    for _ in range(n):
        v, w = map(int, input().split())
        vw.append((v, w))
    vw.sort(reverse=True, key=lambda x:x[0])
    for v, w in vw:
        for j in range(h):
            if dp[j] == INF:
                continue
            tmp = dp[j] + w
            if tmp < dp[j+v]:
                dp[j+v] = tmp
    print(min(dp[h:]))

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

import numpy as np
import numba
from typing import List


def solver(N: int, S: int, A) -> int:
    dp = [[0] * (S+1) for _ in range(N+1)]

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


def main():
    N, S = [int(x) for x in input().split()]
    A = [int(x) for x in input().split()]

    ans = solver(N, S, A)
    print(ans)
 
 
if __name__ == '__main__':
    import sys
    sys.setrecursionlimit(10000)
    main()

### FIXED CODE ###

import numpy as np
import numba
from typing import List


@numba.jit
def solver(N: int, S: int, A: np.array) -> int:
    dp = np.zeros((N+1, S+1), dtype=np.int64)

    dp[0,0] = 1
    MOD = 998244353
    for i in range(N):
        for j in range(S+1):
            dp[i+1, j] += 2 * dp[i, j]
            dp[i+1, j] %= MOD
            if j + A[i] <= S:
                dp[i+1, j+A[i]] += dp[i, j]
                dp[i+1, j+A[i]] %= MOD
    return dp[N,S]


def main():
    N, S = [int(x) for x in input().split()]
    A = [int(x) for x in input().split()]

    ans = solver(N, S, np.array(A))
    print(ans)
 
 
if __name__ == '__main__':
    import sys
    sys.setrecursionlimit(10000)
    main()