Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
N,T = map(int,input().split())
comp = []
for i in range(N):
    nt = [int(i) for i in input().split()]
    comp.append(nt)


cost = []
for i in range(N):
    if comp[i][1] <= T:
        temp = [comp[i][0],comp[i][1]]
        cost.append(temp)
cost = sorted(cost, key = lambda x:x[1])
print(cost[0][0])

Fixed submission:
N,Y = map(int,input().split())
ct = {}
for i in range(N):
    temp = [int(i) for i in input().split()]
    if temp[1] > Y:
        pass
    else:
        ct[temp[0]] = temp[1]

if len(ct) > 0:
    ct = sorted(ct.items(),key=lambda x: x[0])
    print(ct[0][0])
else:
    print("TLE")

Buggy python submission (verdict: Runtime Error):
N,T = map(int,input().split())
comp = []
for i in range(N):
    nt = [int(i) for i in input().split()]
    comp.append(nt)


cost = []
for i in range(N):
    if comp[i][1] <= T:
        temp = [comp[i][0],comp[i][1]]
        cost.append(temp)
cost = sorted(cost, key = lambda x:x[1])
print(cost[0][0])

Fixed submission:
N,Y = map(int,input().split())
ct = {}
for i in range(N):
    temp = [int(i) for i in input().split()]
    if temp[1] > Y:
        pass
    else:
        ct[temp[0]] = temp[1]

if len(ct) > 0:
    ct = sorted(ct.items(),key=lambda x: x[0])
    print(ct[0][0])
else:
    print("TLE")

Buggy python submission (verdict: Runtime Error):
N,T = map(int,input().split())
comp = []
for i in range(N):
    nt = [int(i) for i in input().split()]
    comp.append(nt)
print(comp)


cost = []
for i in range(N):
    if comp[i][1] <= T:
        temp = [comp[i][0],comp[i][1]]
        cost.append(temp)
cost = sorted(cost, key = lambda x:x[1])
print(cost[0][0])

Fixed submission:
N,Y = map(int,input().split())
ct = {}
for i in range(N):
    temp = [int(i) for i in input().split()]
    if temp[1] > Y:
        pass
    else:
        ct[temp[0]] = temp[1]

if len(ct) > 0:
    ct = sorted(ct.items(),key=lambda x: x[0])
    print(ct[0][0])
else:
    print("TLE")

Buggy python submission (verdict: Runtime Error):
N,T = map(int,input().split())
comp = []
for i in range(N):
    nt = [int(i) for i in input().split()]
    comp.append(nt)



cost = []
for i in range(N):
    if comp[i][1] <= T:
        temp = [comp[i][0],comp[i][1]]
        cost.append(temp)
cost.sort()
print(cost[0][1])

Fixed submission:
N,Y = map(int,input().split())
ct = {}
for i in range(N):
    temp = [int(i) for i in input().split()]
    if temp[1] > Y:
        pass
    else:
        ct[temp[0]] = temp[1]

if len(ct) > 0:
    ct = sorted(ct.items(),key=lambda x: x[0])
    print(ct[0][0])
else:
    print("TLE")
Buggy python submission (verdict: Runtime Error):
import functools
import fractions
N,X = map(int,input().split())
city = [int(c) for c in input().split()]
diff = [diff.append(city[i]-X) for i in range(N)]
print(abs(functools.reduce(fractions.gcd,diff)))

Fixed submission:
import functools
import fractions
N,X = map(int,input().split())
city = [int(c) for c in input().split()]
diff = []
for i in range(N):
    diff.append(city[i]-X)

gcd = functools.reduce(fractions.gcd,diff)
print(abs(gcd))

Buggy python submission (verdict: Runtime Error):
import functools
import math
N,X = map(int,input().split())
city = [int(c) for c in input().split()]
diff = []
for i in range(N):
    diff.append(city[i]-X)

gcd = functools.reduce(math.gcd,diff)
print(gcd)

Fixed submission:
import functools
import fractions
N,X = map(int,input().split())
city = [int(c) for c in input().split()]
diff = []
for i in range(N):
    diff.append(city[i]-X)

gcd = functools.reduce(fractions.gcd,diff)
print(abs(gcd))
Buggy python submission (verdict: Runtime Error):
import sympy
N = int(input())
sumcount = 0
for i in range(N):
    if sympy.divisor_count(i+1)==8:
        if (i+1) % 2 != 0:
            sumcount += 1
print(sumcount)

Fixed submission:
def div(num):
    counter = 0
    for i in range(num):
        if num % (i+1) == 0:
            counter += 1
    return counter
N = int(input())
sumcount = 0
for i in range(N):
    if div(i+1)==8:
        if (i+1) % 2 != 0:
            sumcount += 1
print(sumcount)
Buggy python submission (verdict: Runtime Error):
S = list(input())
K = int(input())
S = [int(i) for i in S]
if K == 1:
    print(S[0])
else:
    print(S[1])

Fixed submission:
import sys
S = list(input())
K = int(input())
S = [int(i) for i in S]
count = 0
for i in range(K):
    if S[i] is not 1:
        print(S[i])
        sys.exit()
    else:
        count+= 1
if count == K:
    print(1)

Buggy python submission (verdict: Runtime Error):
S = input().split()
K = int(input())
S = [int(i) for i in S]
if S[0] == 1:
    print(S[1])
else:
    print(S[0])

Fixed submission:
import sys
S = list(input())
K = int(input())
S = [int(i) for i in S]
count = 0
for i in range(K):
    if S[i] is not 1:
        print(S[i])
        sys.exit()
    else:
        count+= 1
if count == K:
    print(1)
Buggy python submission (verdict: Runtime Error):
vN = input()
n = int(N)
s = sum([int(i) for i in list(N)])
if n % s == 0:
    print("Yes")
else:
    print("No")

Fixed submission:
N = input()
n = int(N)
s = sum([int(i) for i in list(N)])
if n % s == 0:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Time Limit Exceeded):
A, B, K = map(int, input().split())
P = [i for i in range(A, B+1)]
if (B - A + 1) > K * 2:
    del P[K:-K]
for i in P:
    print(i)

Fixed submission:
A, B, K = map(int, input().split())
if (B - A + 1) > K * 2:
    for i in range(A, A+K):
        print(i)
    for i in range(B - K+1, B+1):
        print(i)
else:
    for i in range(A, B+1):
        print(i)
Buggy python submission (verdict: Runtime Error):
N = int(input())
maxnum = 0

if (N%(int("1" + (len(str(N)) - 1)*"0"))) == int((len(str(N)) - 1) * "9"):
    tmp = list(str(N))
    tmp = [int(item) for item in tmp]
    print(sum(tmp))
else:
    tmp = list(str(N - (N%(int("1" + (len(str(N)) - 1)*"0"))) - 1))
    tmp = [int(item) for item in tmp]
    print(sum(tmp))




Fixed submission:
N = int(input())

if N > 9:
    if (N%(int("1" + (len(str(N)) - 1)*"0"))) == int((len(str(N)) - 1) * "9"):
        tmp = list(str(N))
        tmp = [int(item) for item in tmp]
        print(sum(tmp))
    else:
        tmp = list(str(N - (N%(int("1" + (len(str(N)) - 1)*"0"))) - 1))
        tmp = [int(item) for item in tmp]
        print(sum(tmp))
else:
    print(N)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
maxnum = 0
for i in range(N, int("1" + (len(str(N))-1)*"0") - 1-1, -1):
    tmp = list(str(i))
    tmp = [int(item) for item in tmp]
    maxnum = max(sum(tmp), maxnum)

print(maxnum)

Fixed submission:
N = int(input())

if N > 9:
    if (N%(int("1" + (len(str(N)) - 1)*"0"))) == int((len(str(N)) - 1) * "9"):
        tmp = list(str(N))
        tmp = [int(item) for item in tmp]
        print(sum(tmp))
    else:
        tmp = list(str(N - (N%(int("1" + (len(str(N)) - 1)*"0"))) - 1))
        tmp = [int(item) for item in tmp]
        print(sum(tmp))
else:
    print(N)
Buggy python submission (verdict: Runtime Error):
B

�����j\_������������������@���s����d�dl�Z�d�dlmZ�eee������\ZZdd��e�����D��Z	e
e��e	��Ze
e�ekr`ed���nJee���ed�d�Zd�Zx(ee
e�e��D�]Zeee�d�7�Zq�W�ee��dS�)�����N)�
itemgetterc�������������C���s���g�|�]}t�|��qS���)�int)�.0�jr���r����
ABC081C.py�
<listcomp>���s����r�������)�key)�collections�operatorr����mapr����input�split�N�KZball�dict�Counter�kind�len�print�sorted�itemsZskindZsumNum�range�ir���r���r���r����<module>���s���


Fixed submission:
import collections
from operator import itemgetter
N,K = map(int,input().split())
ball = [int(j) for j in input().split()]

kind = dict(collections.Counter(ball))

if len(kind) <= K:
    print(0)
else:
    skind = sorted(kind.items(),key=itemgetter(1))
    sumNum = 0
    for i in range(len(skind)-K):
        sumNum += skind[i][1]
    print(sumNum)

Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split())
ball = [int(j) for j in input().split()]
kind = []
for i in range(1,N+1):
    temp = ball.count(i)
    kind.append(temp)
if kind.count(0)>=N-K:
    print(0)
else:
    kind.sort()
    sumNum = 0
    for i in range(N-K):
        sumNum += kind[i]
    print(sumNum)

Fixed submission:
import collections
from operator import itemgetter
N,K = map(int,input().split())
ball = [int(j) for j in input().split()]

kind = dict(collections.Counter(ball))

if len(kind) <= K:
    print(0)
else:
    skind = sorted(kind.items(),key=itemgetter(1))
    sumNum = 0
    for i in range(len(skind)-K):
        sumNum += skind[i][1]
    print(sumNum)
Buggy python submission (verdict: Runtime Error):
ryouri = [int(input()) for i in range(5)]

order_1 = [i*0.1 - int(i*0.1) for i in ryouri]
min_v = sorted(order_1)[0]
min_id = 0
for i, v in enumerate(order_1):
    if v == min_v:
        min_id = i

goukei = 0
for i, (price, order) in enumerate(zip(ryouri, order_1)):
    if i == min_id:
        goukei = goukei + ryouri
    else:
        goukei = goukei + ryouri + 10



Fixed submission:
import math
ryouri = [int(input()) for i in range(5)]

order_1 = [(i-1)*0.1 - int((i-1)*0.1) for i in ryouri]
min_v = 999
min_id = 0
for i, v in enumerate(order_1):
    if v < min_v:
        min_v = v
        min_id = i

goukei = 0
for i, (price, order) in enumerate(zip(ryouri, order_1)):
    if i == min_id:
        goukei = goukei + price
    else:
        goukei = goukei + math.ceil(price*0.1)*10

print(goukei)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

ans = 0
for i in range(n):
    ans += i

print(ans)


Fixed submission:
n = int(input())

print(n * (n - 1) // 2)
Buggy python submission (verdict: Runtime Error):
s = input()

def solve(i):
    
    if i == 2:
        if s[i - 1] == s[i]:
            return 2
        else:
            return solve(i - 1) + 1
    if i == 1:
        if s[i - 1] == s[i]:
            return 1
        else:
            return 2
    if i == 0:
        return 1

    if s[i] != s[i - 1]:
        return solve(i - 1) + 1
    else:
        return solve(i - 3) + 2


print(solve(len(s) - 1))


Fixed submission:
import sys

sys.setrecursionlimit(2000000)

s = input()

def solve(i):
    if i == 2:
        if s[i - 1] == s[i]:
            return 2
        else:
            return solve(i - 1) + 1
    if i == 1:
        if s[i - 1] == s[i]:
            return 1
        else:
            return 2
    if i == 0:
        return 1

    if s[i] != s[i - 1]:
        return solve(i - 1) + 1
    else:
        return solve(i - 3) + 2


print(solve(len(s) - 1))

Buggy python submission (verdict: Runtime Error):
s = input()

def solve(i):
    
    if i == 2:
        if s[i - 1] == s[i]:
            return 2
        else:
            return solve(i - 1) + 1
    if i == 1:
        if s[i - 1] == s[i]:
            return 1
        else:
            return 2
    if i == 0:
        return 0

    if s[i] != s[i - 1]:
        return solve(i - 1) + 1
    else:
        return solve(i - 3) + 2


print(solve(len(s) - 1))


Fixed submission:
import sys

sys.setrecursionlimit(2000000)

s = input()

def solve(i):
    if i == 2:
        if s[i - 1] == s[i]:
            return 2
        else:
            return solve(i - 1) + 1
    if i == 1:
        if s[i - 1] == s[i]:
            return 1
        else:
            return 2
    if i == 0:
        return 1

    if s[i] != s[i - 1]:
        return solve(i - 1) + 1
    else:
        return solve(i - 3) + 2


print(solve(len(s) - 1))

Buggy python submission (verdict: Runtime Error):
s = input()

def solve(i):
    if i == 1:
        if s[i - 1] == s[i]:
            return 1
        else:
            return 2
    if i == 0:
        return 0

    if s[i] != s[i - 1]:
        return solve(i - 1) + 1
    else:
        return solve(i - 3) + 2


print(solve(len(s) - 1))


Fixed submission:
import sys

sys.setrecursionlimit(2000000)

s = input()

def solve(i):
    if i == 2:
        if s[i - 1] == s[i]:
            return 2
        else:
            return solve(i - 1) + 1
    if i == 1:
        if s[i - 1] == s[i]:
            return 1
        else:
            return 2
    if i == 0:
        return 1

    if s[i] != s[i - 1]:
        return solve(i - 1) + 1
    else:
        return solve(i - 3) + 2


print(solve(len(s) - 1))
Buggy python submission (verdict: Runtime Error):
k, x = tuple([int(i) for i in input().split(' ')])

print(" ".join([str(i) for i in range(x - k + 1, x + k)]))


Fixed submission:
n =  int(input())

s = []
for _ in range(n):
    s.append(''.join(sorted(input())))

d = {}

for e in s:
    if e in d:
        d[e] += 1
    else:
        d[e] = 1

ans = 0
for k, v in d.items():
    ans += int(v * (v - 1) / 2)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import re
q = int(input().split(' ')[1])
s = input()

for i in range(q):
    lr = [int(i) for i in input().split(' ')]
    print(len(re.findall('AC', s[lr[0] - 1:lr[1]])))


Fixed submission:
n, q = tuple(int(i) for i  in input().split(' '))
s = input()

c = [0] * (n + 1)

for i in range(n):
    c[i + 1] = c[i] + (1 if s[i:i + 2] == 'AC' else 0)

for i in range(q):
    l, r = tuple(int(i) for i  in input().split(' '))
    print(c[r - 1] - c[l - 1])
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
K = int(input())

sub = set()
for i in range(1, len(s) + 1):
    for k in range(len(s) - i + 1):
        sub.add(s[k:i + k])

print(sorted([i for i in sub])[K - 1])


Fixed submission:
s = input()
K = int(input())

sub = set()
for i in range(1, K + 1):
    for k in range(len(s) - i + 1):
        sub.add(s[k:i + k])

print(sorted([i for i in sub])[K - 1])

Buggy python submission (verdict: Runtime Error):
s = input()
K = int(input())

sub = set()
for i in range(1, len(s) + 1):
    for k in range(int(len(s) / i) + 1):
        sub.add(s[k:i + k])

print(sorted([i for i in sub])[1:][K])


Fixed submission:
s = input()
K = int(input())

sub = set()
for i in range(1, K + 1):
    for k in range(len(s) - i + 1):
        sub.add(s[k:i + k])

print(sorted([i for i in sub])[K - 1])

Buggy python submission (verdict: Runtime Error):
s = input()
K = int(input())

sub = set()
for i in range(1, len(s) + 1):
    for k in range(int(len(s) / i) + 1):
        sub.add(s[k:i + k])

print(sorted([i for i in sub][1:])[K])


Fixed submission:
s = input()
K = int(input())

sub = set()
for i in range(1, K + 1):
    for k in range(len(s) - i + 1):
        sub.add(s[k:i + k])

print(sorted([i for i in sub])[K - 1])

Buggy python submission (verdict: Runtime Error):
s = input()
K = int(input())

sub = set()
for i in range(1, len(s) + 1):
    for k in range(int(len(s) / i) + 1):
        sub.add(s[k:i + k])

print(sorted([i for i in sub][1:])[K])
print(sorted([i for i in sub][1:]))


Fixed submission:
s = input()
K = int(input())

sub = set()
for i in range(1, K + 1):
    for k in range(len(s) - i + 1):
        sub.add(s[k:i + k])

print(sorted([i for i in sub])[K - 1])
Buggy python submission (verdict: Runtime Error):
S_prime = input()
T = input()
replaced = 'UNRESTORABLE'
matched = True

if len(S_prime) < len(T):
    cout << replaced << endl;

for i in range(len(S_prime) - len(T) + 1):
    for k in range(len(T)):
        if S_prime[i + k] != T[k] and S_prime[i + k] != '?':
            matched = False
            break
        matched = True
    if matched:
        print(S_prime[0:i])
        replaced = S_prime[0:i] + T + S_prime[i + len(T):]
        break

print(replaced.replace('?', 'a'))


Fixed submission:
S_prime = input()
T = input()
ans = 'z'
matched = False

if len(S_prime) < len(T):
    print('UNRESTORABLE')
    exit()

for i in range(len(S_prime) - len(T) + 1):
    for k in range(len(T)):
        if S_prime[i + k] != T[k] and S_prime[i + k] != '?':
            break

    if k == len(T) - 1 and (S_prime[i + k] == T[k] or S_prime[i + k] == '?'):
        tmp = (S_prime[0:i] + T + S_prime[i + len(T):]).replace('?', 'a')
        if ans > tmp:
            ans = tmp
        matched = True

if matched:
    print(ans)
else:
    print('UNRESTORABLE')

Buggy python submission (verdict: Runtime Error):
from IPython import embed

S_prime = input()
T = input()
replaced = 'UNRESTORABLE'
matched = True

for i in range(len(S_prime) - len(T) + 1):
    for k in range(len(T)):
        if S_prime[i + k] != T[k] and S_prime[i + k] != '?':
            matched = False
            break
        matched = True
    if matched:
        print(S_prime[0:i])
        replaced = S_prime[0:i] + T + S_prime[i + len(T):]
        break

print(replaced.replace('?', 'a'))


Fixed submission:
S_prime = input()
T = input()
ans = 'z'
matched = False

if len(S_prime) < len(T):
    print('UNRESTORABLE')
    exit()

for i in range(len(S_prime) - len(T) + 1):
    for k in range(len(T)):
        if S_prime[i + k] != T[k] and S_prime[i + k] != '?':
            break

    if k == len(T) - 1 and (S_prime[i + k] == T[k] or S_prime[i + k] == '?'):
        tmp = (S_prime[0:i] + T + S_prime[i + len(T):]).replace('?', 'a')
        if ans > tmp:
            ans = tmp
        matched = True

if matched:
    print(ans)
else:
    print('UNRESTORABLE')
Buggy python submission (verdict: Runtime Error):
S = input()
a = [chr(i) for i in range(97, 97+26)]
for s in S:
    if s in a:
        a.remove(s)

print(a[0])


Fixed submission:
S = input()
a = [chr(i) for i in range(97, 97+26)]
for s in S:
    if s in a:
        a.remove(s)
if len(a) == 0:
    print('None')
else:
    print(a[0])
Buggy python submission (verdict: Runtime Error):
import sys
import socket
form math import pi

hostnames = ['N551J', 'F551C', 'X553M']
input_file = 'f1.in'
if socket.gethostname() in hostnames:
    sys.stdin = open(input_file)


def read_int_list():
    return list(map(int, input().split()))


def read_int():
    return int(input())


def read_str_list():
    return input().split()


def read_str():
    return input()


def solve():
    r = read_int()
    return 2 * pi * r


def main():
    res = solve()
    print(res)


if __name__ == '__main__':
    main()


Fixed submission:
import sys
import socket
from math import pi

hostnames = ['N551J', 'F551C', 'X553M']
input_file = 'a1.in'
if socket.gethostname() in hostnames:
    sys.stdin = open(input_file)


def read_int_list():
    return list(map(int, input().split()))


def read_int():
    return int(input())


def read_str_list():
    return input().split()


def read_str():
    return input()


def solve():
    r = read_int()
    return 2 * pi * r


def main():
    res = solve()
    print(res)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys
import socket

if socket.gethostname() in ['N551J', 'F551C']:
    sys.stdin = open('f1.in')


def read_int_list():
    return list(map(int, input().split()))


def read_int():
    return int(input())


def read_str_list():
    return input().split()


def read_str():
    return input()


def solve():
    n, d, a = read_int_list()
    pairs = [read_int_list() for _ in range(n)]
    pairs.sort()
    x, h = map(list, zip(*pairs))

    res = 0
    damage = 0
    q = []
    for i in range(n):
        while len(q) > 0 and q[0][0] + d < x[i]:
            y, m = q.pop(0)
            damage -= m * a
        if damage < h[i]:
            y = x[i] + d
            quotient, rest = divmod(h[i] - damage, a)
            m = quotient + (rest > 0)
            q.append((y, m))
            damage += m * a
            res += m

    return res



def main():
    res = solve()
    print(res)


if __name__ == '__main__':
    main()


Fixed submission:
import sys
import socket
from collections import deque


if socket.gethostname() in ['N551J', 'F551C']:
    in_file = 'f1.in'
    in_file = 'after_contest_01.in'
    sys.stdin = open(in_file)


def read_int_list():
    return list(map(int, input().split()))


def read_int():
    return int(input())


def read_str_list():
    return input().split()


def read_str():
    return input()


def solve():
    n, d, a = read_int_list()
    pairs = [read_int_list() for _ in range(n)]
    pairs.sort()
    x, h = map(list, zip(*pairs))

    res = 0
    damage = 0
    q = deque()
    for i in range(n):
        # print(i, damage, file=sys.stderr)
        while len(q) > 0 and q[0][0] + d < x[i]:
            y, m = q.popleft()
            damage -= m * a
        if damage < h[i]:
            y = x[i] + d
            quotient, rest = divmod(h[i] - damage, a)
            m = quotient + (rest > 0)
            q.append((y, m))
            damage += m * a
            res += m

    return res



def main():
    res = solve()
    print(res)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
    X = int(input())
    if X in [7, 5, 3]:
      print ('YES')
    else:
      print ('NO')

Fixed submission:
X = int(input())
if X in [5, 7, 3]:
  print ('YES')
else:
  print ('NO')
Buggy python submission (verdict: Runtime Error):
 import sys
import socket

if socket.gethostname() in ['N551J', 'F551C']:
    sys.stdin = open('c1.in')


def read_int_list():
    return list(map(int, input().split()))


def read_int():
    return int(input())


def read_str_list():
    return input().split()


def read_str():
    return input()


def solve():
    n = read_int()
    rows = [read_int_list() for i in range(n)]
    a, b = map(list, zip(*rows))
    res = sum(a)
    res = min(res, sum(b))
    all_values = [(a[i], i, 0) for i in range(n)]
    all_values.extend([(b[i], i, 1) for i in range(n)])
    all_values.sort()
    index_of_value = {v: i for i, v in enumerate(all_values)}
    first_values = [
        set(all_values[:n - 2]),
        set(all_values[:n - 1]),
        set(all_values[:n]),
    ]

    s = [sum([t[0] for t in v]) for v in first_values]

    for i in range(n):
        rest = []
        k = 0
        if index_of_value[(a[i], i, 0)] < n:
            k += 1
        else:
            rest.append(a[i])
        if index_of_value[(b[i], i, 1)] < n:
            k += 1
        else:
            rest.append(b[i])
        t = s[k] + sum(rest)
        res = min(res, t)
    return res


def main():
    res = solve()
    print(res)


if __name__ == '__main__':
    main()


Fixed submission:
import sys
import socket

if socket.gethostname() in ['N551J', 'F551C']:
    test_case = 'c1.in'
    sys.stdin = open(test_case)


def read_int_list():
    return list(map(int, input().split()))


def read_int():
    return int(input())


def read_str_list():
    return input().split()


def read_str():
    return input()


def solve():
    n = read_int()
    rows = [read_int_list() for i in range(n)]
    a, b = map(list, zip(*rows))
    res = sum(a)
    res = min(res, sum(b))
    all_values = [(a[i], i, 0) for i in range(n)]
    all_values.extend([(b[i], i, 1) for i in range(n)])
    all_values.sort()
    index_of_value = {v: i for i, v in enumerate(all_values)}
    first_values = [
        set(all_values[:n - 2]),
        set(all_values[:n - 1]),
        set(all_values[:n]),
    ]

    s = [sum([t[0] for t in v]) for v in first_values]
    for i in range(n):
        rest = []
        k = 0
        last = n - 2
        indices = sorted([(index_of_value[(a[i], i, 0)], a[i]),
                          (index_of_value[(b[i], i, 1)], b[i])])

        for index, value in indices:
            if index < last:
                last += 1
                k += 1
            else:
                rest.append(value)
        t = s[k] + sum(rest)
        res = min(res, t)
    return res


def main():
    res = solve()
    print(res)


if __name__ == '__main__':
    main()