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

N = int(input())
V = [int(v) for v in input().split()]
how_many_replace = 0
mx_cnt = 0
for i in range(0, N, 2):
  cnt = V[0:N:2].count(V[i])
  if cnt > mx_cnt:
    mx_cnt = cnt
    mx_cnt_nm_V_135 = V[i]
how_many_replace += (len(V)/2-mx_cnt)

mx_cnt = 0
for i in range(1, N, 2):
  cnt = V[1:N:2].count(V[i])
  if cnt > mx_cnt:
    if V[i] != mx_cnt_nm_V_135:
      mx_cnt = cnt
how_many_replace += (len(V)/2-mx_cnt)

print(int(how_many_replace))

### FIXED CODE ###

n = int(input())
V = [int(v) for v in input().split()]

V1 = [V[n] for n in range(0, n, 2)] #v1, v3, v5, ...
V2 = [V[n] for n in range(1, n, 2)] #v2, v4, v6, ...

mx_V1 = max(V1)
V1_cnt = [[0, 0]] # V1に一種類しか数字が存在しなかったときのために
for i in range(1, mx_V1+1):
  V1_cnt.append([i, 0])
for v in V1:
  V1_cnt[v][1] += 1  
V1_cnt.sort(key=lambda x: x[1], reverse=True)

mx_V2 = max(V2)
V2_cnt = [[0, 0]] # V2に一種類しか数字が存在しなかったときのために
for j in range(1, mx_V2+1):
  V2_cnt.append([j, 0])
for v in V2:
  V2_cnt[v][1] += 1  
V2_cnt.sort(key=lambda x: x[1], reverse=True)

mxnum_V1_cnt = V1_cnt[0][0] #V1の中で一番出現回数多い数字
mxnum_V2_cnt = V2_cnt[0][0] #V2の中で一番出現回数多い数字
if mxnum_V1_cnt != mxnum_V2_cnt:
  ans = n - (V1_cnt[0][1] + V2_cnt[0][1])
else:
  ans = n - max(V1_cnt[0][1] + V2_cnt[1][1], V1_cnt[1][1] + V2_cnt[0][1])

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

n = int(input())
a = [list(map(int, input().split())) for _ in range(n)]

memo = [0] * (1 << n)
dp = [0] * (1 << n)

def f(s):
    if memo[s]:
        return dp[s]
    memo[s] = 1

    # 集合sを一つのグループとしたときに得られるスコア
    score = 0
    for i in range(n):
        for j in range(i+1, n):
            if ((s >> i) & 1) & ((s >> j) & 1):
                score += a[i][j]

    # sの部分集合でs自身と空集合を除いた集合を列挙(テクニックが存在)
    t = (s-1) & s   # s自身を除く (今回は関係ないがs自身を含む場合は t = s としてあげる)
    while t > 0:
        # 集合t と, 集合sから集合tを除いた集合に分けて、それぞれ再帰的にスコアを求める
        score = max(score, f(t) + f(s ^ t))
        t = (t-1) & s

    dp[s] = score
    return dp[s]

print(f((1 << n) - 1))

### FIXED CODE ###

n = int(input())
a = [list(map(int, input().split())) for _ in range(n)]

memo = [0] * (1 << n)
dp = [0] * (1 << n)

def f(s):
    if memo[s]:
        return dp[s]
    memo[s] = 1

    # 集合sを一つのグループとしたときに得られるスコア
    score = 0
    for i in range(n):
        for j in range(i+1, n):
            if ((s >> i) & 1) & ((s >> j) & 1):
                score += a[i][j]

    # sの部分集合でs自身と空集合を除いた集合を列挙(テクニックが存在)
    t = (s-1) & s   # s自身を除く (今回は関係ないがs自身を含む場合は t = s としてあげる)
    while t > 0:
        # 集合t と, 集合sから集合tを除いた集合に分けて、それぞれ再帰的にスコアを求める
        score = max(score, f(t) + f(s ^ t))
        t = (t-1) & s

    dp[s] = score
    return dp[s]

print(f((1 << n) - 1))
### BUGGY CODE ###

from collections import Counter

N, P = map(int, input().split())
S = [int(s) for s in input()]
S.reverse()

ans = 0

if P != 2 and P != 5:
    S = [(s * 10**n) % P for n, s in enumerate(S)]
    for n in range(1, N):
        S[n] = (S[n-1] + S[n]) % P

    S = Counter(S)
    for p in range(P):
        if p == 0:
            ans += S[p]
        ans += (S[p] * (S[p]-1)) // 2

else:
    for n in range(N):
        if S[n] % P == 0:
            ans += N - n

print(ans)

### FIXED CODE ###

from collections import Counter

N, P = map(int, input().split())
S = [int(s) for s in input()]
S.reverse()

ans = 0

if P != 2 and P != 5:
    prime10 = [1] * N
    for n in range(1, N):
        prime10[n] = (prime10[n-1] * 10) % P
    S = [(s * prime10[n]) % P for n, s in enumerate(S)]
    for n in range(1, N):
        S[n] = (S[n-1] + S[n]) % P

    S = Counter(S)
    for p in range(P):
        if p == 0:
            ans += S[p]
        ans += (S[p] * (S[p]-1)) // 2

else:
    for n in range(N):
        if S[n] % P == 0:
            ans += N - n

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

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

n = input()

N = 10

child_data = [[1]*len(n)]
for j in range(1, len(n)+1):
    child_fin = [0]*len(n)
    for i in range(len(n)):
        if n[i] == "L":
            child_fin[i-1] += child_data[j-1][i]
        else:
            child_fin[i+1] += child_data[j-1][i]
    child_data.append(child_fin)
    if child_fin in child_data[:-1]:
        child_last = child_data[-(j%2+1)]
        break

output = " ".join(map(str, child_last))
print(output)

### FIXED CODE ###

def main():
    s = input()

    spl = s.split("LR")

    for i, e in enumerate(spl):
        spl[i] = "R" + spl[i] + "L"

    spl[0] = spl[0][1:]
    spl[-1] = spl[-1][:-1]

    ans = []
    for es in spl:
        rl_i = es.find("RL")
        l = len(es)
        q, r = divmod(l, 2)
        for i, e in enumerate(es):
            if i == rl_i or i == rl_i + 1:
                tmp = q + r * ((i + 1) % 2)
                ans.append(tmp)
            else:
                ans.append(0)

    print(*ans)


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


import bisect

def main():
    N = int(input())
    l = []

    for i in range(N):
        a = int(input())
        if len(l) == 0 or a <= l[0]:
            l.insert(0,a)
        else:
            ind = bisect.bisect_left(l, a)
            l[ind-1] = a

    print(len(l))

if __name__ == "__main__":
    main()


### FIXED CODE ###

from collections import deque
import bisect

def main():
    N = int(input())
    l = deque([])

    for i in range(N):
        a = int(input())
        if len(l) == 0 or a <= l[0]:
            l.appendleft(a)
        else:
            ind = bisect.bisect_left(l, a)
            l[ind-1] = a

    print(len(l))

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

import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa == x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))

n,k = m()

s = [[] for i in range(n)]

sss = [[Max,Max,Max] for i in range(n)]

for i in range(k):
    u,v = m()
    u -= 1
    v -= 1
    if u not in s[v]:
        s[v].append(u)

st,g = m()
st -= 1
g -= 1
co = Max

eee = [[s,0,g,0]]
eee = cl.deque(eee)
def bfs(x,nn,now,coun):
    global eee,sss,st,co
    if min(sss[now][nn],coun) == coun:
        if nn == 0 and st == now:
            co = min(co,coun)
        else:
            sss[now][nn] = coun
            if nn == 2:
                nn = 0
                coun += 1
            else:
                nn += 1
            for i in x[now]:
                eee.append([x,nn,i,coun])
    else:
        if now == st and nn == 0:
            co = min(co,coun)

while eee:
    op = eee.popleft()
    bfs(op[0],op[1],op[2],op[3])

#dfs(s,0,g,0)
if co == Max:
    print(-1)
else:
    print(co)



### FIXED CODE ###

import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa == x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))

n,k = m()

s = [[] for i in range(n)]

sss = [[Max,Max,Max] for i in range(n)]

for i in range(k):
    u,v = m()
    u -= 1
    v -= 1
    if v not in s[u]:
        s[u].append(v)

st,g = m()
st -= 1
g -= 1
co = Max

eee = [[s,0,st,0]]
eee = cl.deque(eee)
def bfs(x,nn,now,coun):
    global eee,sss,g,co
    if sss[now][nn] == Max:
        if nn == 0 and g == now:
            co = min(co,coun)
        else:
            sss[now][nn] = coun
            if nn == 2:
                nn = 0
                coun += 1
            else:
                nn += 1
            for i in x[now]:
                eee.append([x,nn,i,coun])
    else:
        if now == g and nn == 0:
            co = min(co,coun)

while eee:
    op = eee.popleft()
    bfs(op[0],op[1],op[2],op[3])

#dfs(s,0,g,0)
if co == Max:
    print(-1)
else:
    print(co)
### BUGGY CODE ###

import bisect

N, M = [int(_) for _ in input().split()]
A = [int(_) for _ in input().split()]
A.sort()

for i in range(M):
    b, c = [int(_) for _ in input().split()]
    cnt = 0
    for j in range(b):
        if len(A) <= j: break
        if A[j] >= c: break
        cnt += 1
    if cnt > 0:
        # A = A[cnt:]
        idx = bisect.bisect_left(A, c)
        A = A[cnt:idx] + ([c] * cnt) + A[idx:]
        # print(A)

print(sum(A))

### FIXED CODE ###

N, M = [int(_) for _ in input().split()]
A = [int(_) for _ in input().split()]
A.sort()

BC = []
for i in range(M):
    v = [v for v in input().split()]
    BC.append((int(v[0]), int(v[1])))

BC.sort(key=lambda x: -x[1])

i = 0

fin = False
for b, c in BC:
    for _ in range(b):
        if i >= N:
            fin = True
            break

        if A[i] < c:
            A[i] = c
            i += 1
        else:
            fin = True
            break
    if fin:
        break
print(sum(A))
### BUGGY CODE ###

from itertools import permutations
import sys

N, M, R = map(int, input().split())
r = [i - 1 for i in map(int, input().split())]

d = [[float('inf') for i in range(N)] for j in range(N)]

for i in range(N):
    d[i][i] = 0
    
for i in range(M):
    a, b, c = map(int,sys.stdin.readline().split())
    d[a-1][b-1] = c
    d[b-1][a-1] = c
    
for k in range(N):
    for i in range(N):
        for j in range(N):
            if d[i][j] > d[i][k] + d[k][j]:
                d[i][j] = d[i][k] + d[k][j]

ans = 10**12

for each in permutations(r):
    t_dis = 0
    for i in range(R-1):
        t_dis += d[each[i]][each[i+1]]  
    
    ans = min(ans, t_dis)

print(ans)

### FIXED CODE ###

from collections import defaultdict
from itertools import permutations
import heapq

INF = float('inf')
N, M, R = map(int, input().split())
r = list(map(int, input().split()))
memo = [[INF for _ in range(N)] for _ in range(N)]

Adj_list = defaultdict(set)

for i in range(M):
    a, b, c = map(int, input().split())
    if memo[a-1][b-1]:
        memo[a-1][b-1] = min(memo[a-1][b-1], c)
        
    Adj_list[a-1].add((b-1, memo[a-1][b-1]))
    Adj_list[b-1].add((a-1, memo[a-1][b-1]))


def dijkstra(x, vertex):
    d = [INF] * x
    d[vertex] = 0
    hq = [(0, vertex)]
    
    while hq:
        u = heapq.heappop(hq)[1]
        for (v, c) in Adj_list[u]:
            if d[v] > d[u] + c:
                d[v] = d[u] + c
                heapq.heappush(hq, (d[u]+c, v))

    return d

ans = INF
t_dis = 0

table = {}
for i in r:
    table[i-1] = dijkstra(N, i-1)

for each in permutations(r):
    t_dis = 0
    for i in range(R-1):
        t_dis += table[each[i]-1][each[i+1]-1]
    #print(each, t_dis)
    ans = min(ans, t_dis)

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

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6) #for deep recursion

N, Q = list(map(int, input().split()))
edges = [list(map(int, input().split())) for _ in range(N-1)]
operations = [list(map(int, input().split())) for _ in range(Q)]

counts = [0] * N
for op in operations:
    p, x = op
    counts[p-1] += x
    
all_connected_vertices = {i: [] for i in range(1, 1+N)}
for a, b in edges:
    all_connected_vertices[a].append(b)
    all_connected_vertices[b].append(a)
    
def dfs(point, pre):
    connected_vertices = all_connected_vertices[point]
    for c in connected_vertices:
        if c == pre:
            continue
        counts[c-1] += counts[point-1]
        dfs(c, point)
    
dfs(1, -1)
    
print(*counts)

### FIXED CODE ###

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6) #for deep recursion

N, Q = list(map(int, input().split()))
edges = [list(map(int, input().split())) for _ in range(N-1)]
operations = [list(map(int, input().split())) for _ in range(Q)]

counts = [0] * N
for op in operations:
    p, x = op
    counts[p-1] += x
    
all_connected_vertices = {i: [] for i in range(1, 1+N)}
for a, b in edges:
    all_connected_vertices[a].append(b)
    all_connected_vertices[b].append(a)
    
def dfs(point, pre):
    connected_vertices = all_connected_vertices[point]
    for c in connected_vertices:
        if c == pre:
            continue
        counts[c-1] += counts[point-1]
        dfs(c, point)
    
dfs(1, -1)
    
print(*counts)
### BUGGY CODE ###

# question 3
N = input()
H = input().split()

# question 3
i = 0

for n in range(0, int(N)-1):
  j = 0
  
  for h in range(n, int(N)-1):
    if int(H[h]) < int(H[h+1]):
      break
    j += 1      
  
  if i < j:
    i = j
    
  if i >= int(N) - n:
    break
    
print(i)


### FIXED CODE ###

# question 3
N = input()
H = input().split()

# question 3
i = 0
res = [0]

for n in range(0, int(N)-1):
  if int(H[n]) >= int(H[n+1]):
    i += 1
  else:
    res.append(i)
    i = 0

res.append(i)
    
print(max(res))
### BUGGY CODE ###

N = int(input())
list = [int(input()) for i in range(N)]
for i in range(N):
    if list[i] == max(list):
        print(sorted(list)[-2])
    else:
        print(max(list))


### FIXED CODE ###

N = int(input())
list = [int(input()) for i in range(N)]
if sorted(list)[-1] == sorted(list)[-2]:
    list2 = [max(list)]*N
    print("\n".join(map(str,list2)))
else:
    list2 = [max(list)]*list.index(max(list))
    list2.append(sorted(list)[-2])
    list3 = [max(list)]*(N-list.index(max(list))-1)
    list2.extend(list3)
    print("\n".join(map(str,list2)))
### BUGGY CODE ###

# python3
import sys

input = sys.stdin.readline


def main():
    # 2 <= N <= pow(10,5), 1 <= K <= 100
    N, K = [int(ele) for ele in input().split()]
    h = [Node(int(ele)) for ele in input().split()]

    for idx, n in enumerate(h):
        if idx != 0:
            s = max(0, idx - K)
            n.parents = h[s:idx]

    for n in h:
        n.cal_dp()

    print(h[-1].dp_val)


class Node():

    def __init__(self, val):
        self.val = val
        self.dp_val = 1000000000000
        self.parents = []

    def cal_dp(self):
        if self.parents == []:
            self.dp_val = 0
            return

        for n in self.parents:
            self.dp_val = min(self.dp_val, abs(n.val - self.val)+n.dp_val)


if __name__ == '__main__':
    main()


### FIXED CODE ###

# python3
import sys

input = sys.stdin.readline


def main():
    # 2 <= N <= pow(10,5), 1 <= K <= 100
    N, K = [int(ele) for ele in input().split()]
    h = [Node(int(ele)) for ele in input().split()]

    for idx, n in enumerate(h):
        s = max(0, idx - K)
        n.parents = h[s:idx]
        n.cal_dp()

    print(h[-1].dp_val)


class Node():

    def __init__(self, val):
        self.val = val
        self.dp_val = 1000000000000
        self.parents = []

    def cal_dp(self):
        if self.parents == []:
            self.dp_val = 0
            return

        for n in self.parents:
            self.dp_val = min(self.dp_val, abs(n.val - self.val)+n.dp_val)


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

numbers = input().split()
x = input().split()
y = input().split()
z = input().split()

k = int(numbers[3])


def cutting(c, k):
    del c[k::]


x.sort(reverse=True)
cutting(x, k)
y.sort(reverse=True)
cutting(y, k)
z.sort(reverse=True)
cutting(z, k)

answer = []

for i in x:
    for j in y:
        for m in z:
            price = int(i)+int(j)+int(m)
            answer.append(price)

answer.sort(reverse=True)
del answer[k::]

for l in answer:
    print(l)


### FIXED CODE ###

numbers = input().split()
x = input().split()
y = input().split()
z = input().split()

k = int(numbers[3])

answer = []
for i in x:
    for j in y:
        price = int(i)+int(j)
        answer.append(price)
answer.sort(reverse=True)
del answer[k::]
f_ans = []
for m in answer:
    for n in z:
        price = m + int(n)
        f_ans.append(price)

f_ans.sort(reverse=True)
del f_ans[k::]

for l in f_ans:
    print(l)
### BUGGY CODE ###

n, m, k = map(int, input().split())
ans = [0] * n
p = [{'T':[], 'B':[]} for _ in range(n)]
for _ in range(m):
    a, b = map(int, input().split())
    p[a-1]['T'].append(b)
    p[b-1]['T'].append(a)
    
for _ in range(k):
    c, d = map(int, input().split())
    p[c-1]['B'].append(d)
    p[d-1]['B'].append(c)

fl = []

for i, dt in enumerate(p):
    isContinue = False
    for f in fl:
        if i+1 in f:
            isContinue = True
            break
    if isContinue:
        continue
    tmp_fl = [i+1] + dt['T']
    rmn = [t for t in dt['T']]
    alr = [i+1]
    while not len(rmn) == 0:
        r = rmn.pop()
        alr.append(r)
        new_fl = p[r-1]['T']
        for nf in new_fl:
            if not nf in tmp_fl:
                tmp_fl.append(nf)
            if not nf in rmn and not nf in alr:
                rmn.append(nf)
    fl.append(tmp_fl)
    
for i, dt in enumerate(p):
    for f in fl:
        if i+1 in f:
            for s in f:
                if not s in [i+1]+ dt['T'] + dt['B']:
                    ans[i] += 1

print(' '.join(map(str, ans)))

### FIXED CODE ###

import sys
input = sys.stdin.buffer.readline
from collections import deque

def main():
    N,M,K = map(int,input().split())
    friend = [[] for _ in range(N)]
    for _ in range(M):
        a,b = map(int,input().split())
        friend[a-1].append(b-1)
        friend[b-1].append(a-1)
        
    brock = [[] for _ in range(N)]
    for _ in range(K):
        c,d = map(int,input().split())
        brock[c-1].append(d-1)
        brock[d-1].append(c-1)
        
    parent = [-1 for _ in range(N)]
    group = [0 for _ in range(N)]
    
    for i in range(N):
        put = []
        if parent[i] == -1:
            q = deque([i])
            parent[i] = i
            while q:
                now = q.pop()
                put.append(now)
                for fol in friend[now]:
                    if parent[fol] == -1:
                        parent[fol] = i
                        q.append(fol)
            l = len(put)
            for num in put:
                group[num] = l-1
                
        else:
            continue

    for i in range(N):
        group[i] -= len(friend[i])
        for dis in brock[i]:
            if parent[i] == parent[dis]:
                group[i] -= 1
    
    print(*group)
    
if __name__ == "__main__":
    main()
### BUGGY CODE ###

import sys
input = sys.stdin.readline
N, W = list(map(int, input().split()))
WV = []
for _ in range(N):
    WV.append(list(map(int, input().split())))

DP = [[0] * (W+1)]
for n in range(N):
    DP.append([0]*(W+1))


for n in range(N):
    for w in range(W+1):
        if w < WV[n][0]:
            DP[n+1][w] = DP[n][w]
        else:
            DP[n+1][w] = max(DP[n][w-WV[n][0]]+WV[n][1], DP[n][w])

print(DP[N][W])


### FIXED CODE ###

import sys
input = sys.stdin.readline
N, W = list(map(int, input().split()))
WV = []
for _ in range(N):
    WV.append(list(map(int, input().split())))

DP = [[0] * (W+1)]
for n in range(N):
    DP.append([0]*(W+1))


for n in range(N):
    for w in range(W+1):
        if w < WV[n][0]:
            DP[n+1][w] = DP[n][w]
        else:
            DP[n+1][w] = max(DP[n][w-WV[n][0]]+WV[n][1], DP[n][w])

print(DP[N][W])
### BUGGY CODE ###

N = int(input())
S = []
for i in range(N):
    p = input()
    if not p in S:
        S.append(p)
print(len(S))

### FIXED CODE ###

N = int(input())
S = set()
for i in range(N):
    S.add(input())
print(len(S))
### BUGGY CODE ###

import bisect
def index(a, x):
    i = bisect.bisect_left(a, x)
    if i != len(a) and a[i] == x:
        return i
    raise ValueError

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

bclist = []
for i in range(q):
    b,c  = map(int,input().split())
    bclist.append([b,c])

alist = sorted(alist)

for i in range(q):
    
    b = bclist[i][0]
    c = bclist[i][1]
    try:
        ind = index(alist,b)
        while alist[ind] == b:
            alist.remove(b)
            bisect.insort(alist, c)
            if b > c:
                ind+=1

    except:
        None
    print(sum(alist))


### FIXED CODE ###

from collections import defaultdict

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


dict_n = defaultdict(lambda:0)

for i in alist:
    dict_n[i] += 1

bclist = []
for i in range(q):
    b,c  = map(int,input().split())
    bclist.append([b,c])

sum = sum(alist)
for i in range(q):
    
    b = bclist[i][0]
    c = bclist[i][1]

    sum += dict_n[b]*c - dict_n[b]*b
    dict_n[c] += dict_n[b]
    del(dict_n[b])

    print(sum)
### BUGGY CODE ###

import sys
    
global status, d
status = {}
d=0

def mst(p1, GRAPH):
    global status
    
    edge={}
    total = 0
    mini = 0
    while True:
        status[p1]=True
        for p2 in range(len(status)):
            if status[p2]==False and GRAPH.has_key((p1,p2)):
                edge[(p1, p2)]=GRAPH[(p1, p2)]
                if mini<GRAPH[(p1,p2)]:
                    mini=GRAPH[(p1,p2)]+1
        for key, value in edge.items():
            if status[key[1]]==True:
                del edge[key]
                continue
            if value <mini:
                key0 = key
                mini = value
        if mini!=2000:
            total+=mini
            p1=key0[1]
        else:
            break
    
    return total

n = int(raw_input())
x = {}
for i in range(n):
    seq = map(int,raw_input().split())
    for j in range(n):
        tmp = seq[j]
        if tmp != -1:
            x[(i, j)]=tmp
    status[i] = False

print mst(0, x)

### FIXED CODE ###

import sys
    
global status, d
status = {}
d=0

def mst(p1, GRAPH):
    global status
    
    edge={}
    total = 0
    mini = 0
    while True:
        status[p1]=True
        for p2 in range(len(status)):
            if status[p2]==False and GRAPH.has_key((p1,p2)):
                edge[(p1, p2)]=GRAPH[(p1, p2)]
        mini=1000000
        for key, value in edge.items():
            if status[key[1]]==True:
                del edge[key]
                continue
            if value <mini:
                key0 = key
                mini = value
        if mini!=1000000:
            total+=mini
            p1=key0[1]
        else:
            break
    
    return total

n = int(raw_input())
x = {}
for i in range(n):
    seq = map(int,raw_input().split())
    for j in range(n):
        tmp = seq[j]
        if tmp != -1:
            x[(i, j)]=tmp
    status[i] = False

print mst(0, x)