Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):

H, W, D = map(int, input().split())
A = [list(map(int, input().split())) for i in range(H)]
Q = int(input())
LR = [list(map(int, input().split())) for i in range(Q)]
d = [0] * (H*W)
num_dict = {}
y = 0
for aa in A:
    x = 0
    for a in aa:
        num_dict[a] = [x, y]
        x += 1
    y += 1

for i in range(D+1, H*W):
    d[i] = d[i-D] + abs(num_dict[i][0]-num_dict[i-D][0]) + abs(num_dict[i][1]-num_dict[i-D][1])
for l, r in LR:
    print(d[r]-d[l])


Fixed submission:

H, W, D = map(int, input().split())
A = [list(map(int, input().split())) for i in range(H)]
Q = int(input())
LR = [list(map(int, input().split())) for i in range(Q)]
d = [0] * ((H*W)+1)
num_dict = {}
y = 0
for aa in A:
    x = 0
    for a in aa:
        num_dict[a] = [x, y]
        x += 1
    y += 1

for i in range(D+1, H*W+1):
    d[i] = d[i-D] + abs(num_dict[i][0]-num_dict[i-D][0]) + abs(num_dict[i][1]-num_dict[i-D][1])
for l, r in LR:
    print(d[r]-d[l])

Buggy python submission (verdict: Time Limit Exceeded):
import numpy
H, W, D = map(int, input().split())
A = numpy.array([list(map(int, input().split())) for i in range(H)])
Q = int(input())
LR = [list(map(int, input().split())) for i in range(Q)]

num_dict = {}
y = 0
for aa in A:
    x = 0
    for a in aa:
        num_dict[a] = [x, y]
        x += 1
    y += 1

for l, r in LR:
    ans = 0
    z = l
    while z != r:
        zahyo1 = num_dict[z]
        x1, y1 = int(zahyo1[0]), int(zahyo1[1])
        zahyo2 = num_dict[z+D]
        x2, y2 = int(zahyo2[0]), int(zahyo2[1])
        ans += (abs(x1-x2)+abs(y1-y2))
        z = z + D
    print(ans)

Fixed submission:

H, W, D = map(int, input().split())
A = [list(map(int, input().split())) for i in range(H)]
Q = int(input())
LR = [list(map(int, input().split())) for i in range(Q)]
d = [0] * ((H*W)+1)
num_dict = {}
y = 0
for aa in A:
    x = 0
    for a in aa:
        num_dict[a] = [x, y]
        x += 1
    y += 1

for i in range(D+1, H*W+1):
    d[i] = d[i-D] + abs(num_dict[i][0]-num_dict[i-D][0]) + abs(num_dict[i][1]-num_dict[i-D][1])
for l, r in LR:
    print(d[r]-d[l])

Buggy python submission (verdict: Time Limit Exceeded):
import numpy
H, W, D = map(int, input().split())
A = numpy.array([list(map(int, input().split())) for i in range(H)])
Q = int(input())
LR = [list(map(int, input().split())) for i in range(Q)]


for l, r in LR:
    ans = 0
    z = l
    while z != r:
        zahyo1 = numpy.where(A==z)
        x1, y1 = int(zahyo1[0]), int(zahyo1[1])
        zahyo2 = numpy.where(A==z+D)
        x2, y2 = int(zahyo2[0]), int(zahyo2[1])
        ans += (abs(x1-x2)+abs(y1-y2))
        z = z + D
    print(ans)

Fixed submission:

H, W, D = map(int, input().split())
A = [list(map(int, input().split())) for i in range(H)]
Q = int(input())
LR = [list(map(int, input().split())) for i in range(Q)]
d = [0] * ((H*W)+1)
num_dict = {}
y = 0
for aa in A:
    x = 0
    for a in aa:
        num_dict[a] = [x, y]
        x += 1
    y += 1

for i in range(D+1, H*W+1):
    d[i] = d[i-D] + abs(num_dict[i][0]-num_dict[i-D][0]) + abs(num_dict[i][1]-num_dict[i-D][1])
for l, r in LR:
    print(d[r]-d[l])
Buggy python submission (verdict: Time Limit Exceeded):
X, Y = map(int, input().split())
Z = (10**18 // X) * X
if (X == Y) or (Y == 1):
    print(-1)
elif X < Y :
    print(X)
else:
    for i in range(Z, 0, -X):
        if i % Y != 0:
            print(i)
            break
    else:
        print(-1)

Fixed submission:
X, Y = map(int, input().split())
Z = (10**18 // X) * X
if (X == Y) or (Y == 1) or (X % Y == 0):
    print(-1)
elif X < Y:
    print(X)
else:
    for i in range(Z, 0, -X):
        if i % Y != 0:
            print(i)
            break
    else:
        print(-1)

Buggy python submission (verdict: Time Limit Exceeded):

# 最大公約数
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


# 最小公倍数
def lcm(a, b):
    return a * b // gcd(a, b)


X, Y = map(int, input().split())
cnt = 1
Z = lcm(X, Y)
if (X == Y) or (Y == 1):
    print(-1)
    exit()
else:
    if X < Y:
        print(X)
        exit()
    while True:
        if X * cnt > 10**18:
            print(-1)
            break
        if X*cnt % Z != 0:
            print(X*cnt)
            break
        cnt += 1




Fixed submission:
X, Y = map(int, input().split())
Z = (10**18 // X) * X
if (X == Y) or (Y == 1) or (X % Y == 0):
    print(-1)
elif X < Y:
    print(X)
else:
    for i in range(Z, 0, -X):
        if i % Y != 0:
            print(i)
            break
    else:
        print(-1)
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

C = [A[i]-B[i] for i in range(N)]
if 0 in C:
    print("Yes")
    exit()

Cplus = list(filter(lambda x:x>0, C))
Cminas = list(filter(lambda  x:x<0, C))

Cplus.sort(reverse=True)
pl = len(Cplus)
Cminas.sort()
ml = len(Cminas)

i = 0
j = 0
while True:
    if Cplus[i] > 0:
        if Cminas[j] <= -2:
            Cplus[i] -= 1
            Cminas[j] += 2
        else:
            j += 1
            if j >= ml:
                print("No")
                break
    else:
        i += 1
        if i >= pl:
            print("No")
            break

    if (Cplus[-1] <= 0) & (Cminas[-1] <= 0):
        print("Yes")
        break





Fixed submission:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

C = [B[i]-A[i] for i in range(N)]

P = sum(filter(lambda x: x<0, C))
M = list(filter(lambda x: x>1, C))
M = list(map(lambda x: x//2, M))

M = sum(M)
if abs(M) >= abs(P):
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
seats = [""] * N

# 準備
print(0)
seats[0] = input()
if seats[0] == "Vacant":
    exit()
print(N - 1)
seats[N - 1] = input()
if seats[N - 1] == "Vacant":
    exit()

l = 0
r = N - 1
while True:
    m = (l + r) // 2
    s = input()
    if s == "Vacant":
        exit()
    seats[m] = s

    if (seats[l] == seats[m]) & ((m - l) % 2 == 1):
        r = m - 1
    elif (seats[l] != seats[m]) & ((m-l) % 2 == 0):
        r = m - 1
    else:
        l = m + 1





Fixed submission:
N = int(input())
seats = [""] * N

# 準備
print(0)
seats[0] = input()
if seats[0] == "Vacant":
    exit()
print(N - 1)
seats[N - 1] = input()
if seats[N - 1] == "Vacant":
    exit()

l = 0
r = N - 1
while True:
    m = (l + r) // 2
    print(m)

    s = input()
    if s == "Vacant":
        exit()
    seats[m] = s

    if (seats[l] == seats[m]) & ((m - l) % 2 == 1):
        r = m
    elif (seats[l] != seats[m]) & ((m-l) % 2 == 0):
        r = m
    else:
        l = m

Buggy python submission (verdict: Runtime Error):
N = int(input())
seats = [""] * N

# 準備
print(0)
seats[0] = input()
print(N - 1)
seats[N - 1] = input()

l = 0
r = N - 1
while True:
    m = (l + r) // 2
    print("l,r =", l, r)
    print(m)
    s = input()
    if s == "Vacant":
        exit()

    if seats[l] == seats[m]:
        if (r-l) % 2 == 0:
            l = m + 1
        else:
            r = m -1
    else:
        if (r-l) % 2 == 1:
            r = m - 1
        else:
            l = m + 1





Fixed submission:
N = int(input())
seats = [""] * N

# 準備
print(0)
seats[0] = input()
if seats[0] == "Vacant":
    exit()
print(N - 1)
seats[N - 1] = input()
if seats[N - 1] == "Vacant":
    exit()

l = 0
r = N - 1
while True:
    m = (l + r) // 2
    print(m)

    s = input()
    if s == "Vacant":
        exit()
    seats[m] = s

    if (seats[l] == seats[m]) & ((m - l) % 2 == 1):
        r = m
    elif (seats[l] != seats[m]) & ((m-l) % 2 == 0):
        r = m
    else:
        l = m
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
LRD = [list(map(int, input().split())) for i in range(M)]
 
 
class WeightedUnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n + 1)
        self.weight = [0] * (n+1)
 
    # 検索
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.weight[x] += self.weight[self.par[x]]
            self.par[x] = self.find(self.par[x])
            return self.par[x]
 
    # 重さの検索
    def weighting(self, x):
        self.find(x)
        return self.weight[x]
 
    # 併合
    def union(self, x, y, w):
        w -= self.weighting(x)
        w += self.weighting(y)
        x = self.find(x)
        y = self.find(y)
 
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            w = -w
            self.weight[y] = w
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
 
    # 同じ集合に属するか
    def same(self, x, y):
        return self.find(x) == self.find(y)
 
    # 各頂点間の絶対距離
    def diff(self, x, y):
        return abs(self.weighting(x) - self.weighting(y))
 
 
wuf = WeightedUnionFind(N)
for l, r, d in LRD:
    if wuf.same(l, r):
        if wuf.diff(l, r) != d:
            print("No")
            break
    else:
        wuf.union(l, r, d)
else:
    print("Yes")

Fixed submission:
N = int(input())
A = [list(map(int, input().split())) for i in range(2)]

ans = 0
for i in range(N):
    ans = max(ans, sum(A[0][:i+1])+sum(A[1][i:]))

print(ans)
Buggy python submission (verdict: Runtime Error):
N, Y = map(int, input().split())
# x:10000円, y;5000円, z:1000円
for x in range(N+1):
    for y in range(N-x+1):# 5000円の枚数をN-(10000円の枚数)までに制限
        for z in range(N-x-y-1):
            if 10000*x + 5000*y + 1000*z == Y:
                print(x, y, z)
                exit(0)
print(-1, -1, -1)

Fixed submission:
S = input()
print("2018"+S[4::])
Buggy python submission (verdict: Runtime Error):
N, Y = map(int, input().split())
# x:10000円, y;5000円, z:1000円
for x in range(N+1):
    for y in range(N-x+1):　# 5000円の枚数をN-(10000円の枚数)までに制限
        z = N - (x + y)
        if 10000*x + 5000*y + 1000*z == Y:
            print(x, y, z)
            exit(0)
print(-1, -1, -1)

Fixed submission:
N, Y = map(int, input().split())
flg = False
for x in range(N+1):
    for y in range(N+1):
        if ((10000*x + 5000*y + (N-x-y)*1000)==Y) & (x+y<=N):
            print(x,y,(N-x-y))
            flg = True
            break
    if flg:
        break
else:
    print(-1,-1,-1)
Buggy python submission (verdict: Runtime Error):
import math
N, H = map(int, input().split())
A = []
B = []
for i in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)

amax = max(A)
# 最強の振り刀より強い攻撃力を持つものを抽出
B = list(filter(lambda x: x > amax, B))
B.sort(reverse=True)

ans = 0
while H > 0:
    # まだ投げれる
    if not B == []:
        H -= B.pop(-1)
        del B[-1]
    # もう投げれない
    else:
        ans += math.ceil(H/amax)
        break
    ans += 1

print(ans)


Fixed submission:
import math

N, H = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(N)]
zan = max(ab)
zan = zan[0]
ab.sort(reverse=True, key=lambda x:x[1])

bunnage = [ab[0][1]]
for i in range(1, N):
    bunnage.append(bunnage[i-1]+ab[i][1])

ans = []

for i in range(len(bunnage)):
    Z = max(H - bunnage[i], 0)
    zan_num = math.ceil(Z/zan)
    ans.append(i+1+zan_num)

print(min(ans))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
# C:移動時間 S:start時間 F:運行間隔 SはFで割り切れる
CSF = [list(map(int, input().split())) for i in range(N-1)]

for i in range(N-1):
    time = 0
    time += CSF[i][1]
    for j in range(i, N-1):
        start = CSF[j][1]
        while True:
            if time <= start:
                break
            else:
                start += CSF[j][2]
        time += (start - time)
        time = max(time, CSF[j][1])
        time += CSF[j][0]

    print(time)

print(0)





Fixed submission:
N = int(input())
CSF = [list(map(int, input().split())) for i in range(N-1)]

# 鉄道種類ループ
for i in range(N):
    T = 0
    # 鉄道乗り継ぎループ
    for j in range(i, N-1):
        if T < CSF[j][1]:
            T = CSF[j][1]
        else:
            if T % CSF[j][2] != 0:
                T += (CSF[j][2] - T % CSF[j][2])
        T += CSF[j][0]
    print(T)
Buggy python submission (verdict: Time Limit Exceeded):
import bisect

# ある自然数未満までのエラトステネスの篩をつくる
def mark(s, x):
    for i in range(x + x, len(s), x):
        s[i] = False


def eratosthenes(n):
    s = [True] * n
    for x in range(2, int(n ** 0.5) + 1):
        if s[x]: mark(s, x)
    return [i for i in range(0, n) if s[i] and i > 1]


primes = eratosthenes(10 ** 5+1)
like2017 = list(filter(lambda x: (x+1)/2 in primes, primes))
num_like2017 = len(like2017)

Q = int(input())
for i in range(Q):
    l, r = map(int, input().split())
    left = bisect.bisect_left(like2017, l)
    right = num_like2017 - bisect.bisect_right(like2017, r)

    print(num_like2017 - left - right)




Fixed submission:
# ある自然数未満までのエラトステネスの篩をつくる
def mark(s, x):
    for i in range(x + x, len(s), x):
        s[i] = False


def eratosthenes(n):
    s = [True] * n
    for x in range(2, int(n ** 0.5) + 1):
        if s[x]: mark(s, x)
    return s

Q = int(input())
LR = [list(map(int, input().split())) for i in range(Q)]

primes = eratosthenes(10 ** 5+1)
primes[0] = False
primes[1] = False

ruiseki = [0] * (10**5 + 1)
for i in range(3, 10**5 + 1, 2):
    if (primes[i]) and (primes[int((i+1)/2)]):
        ruiseki[i] = ruiseki[i-2] + 1
    else:
        ruiseki[i] = ruiseki[i-2]

for l, r in LR:
    print(ruiseki[r] - ruiseki[l-2])

Buggy python submission (verdict: Time Limit Exceeded):
Q = int(input())
lr = [list(map(int, input().split())) for i in range(Q)]
ok = []
for i in range(2, 50001):
    for j in range(2, int((i**0.5)+1)):
        if i%j == 0:
            break
    else:
        ok.append(i)

for l, r in lr:
    cnt = 0
    for i in range(l, r+1, 2):
        if (i in ok) and ((i+1)/2 in ok):
            cnt += 1

    print(cnt)


Fixed submission:
# ある自然数未満までのエラトステネスの篩をつくる
def mark(s, x):
    for i in range(x + x, len(s), x):
        s[i] = False


def eratosthenes(n):
    s = [True] * n
    for x in range(2, int(n ** 0.5) + 1):
        if s[x]: mark(s, x)
    return s

Q = int(input())
LR = [list(map(int, input().split())) for i in range(Q)]

primes = eratosthenes(10 ** 5+1)
primes[0] = False
primes[1] = False

ruiseki = [0] * (10**5 + 1)
for i in range(3, 10**5 + 1, 2):
    if (primes[i]) and (primes[int((i+1)/2)]):
        ruiseki[i] = ruiseki[i-2] + 1
    else:
        ruiseki[i] = ruiseki[i-2]

for l, r in LR:
    print(ruiseki[r] - ruiseki[l-2])
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
m = 0
ans = []
a = A.index(min(A))+1
b = A.index(max(A)+1)
for i in range(N-1,0,-1):
    while A[i] < A[i-1]:
        m += 1
        
        if abs(A[i]-min(A)) > abs(A[i]-max(A)):
            if min(A) > 0:
                A[i] += min(A)
                ans.append([a,i+1])
            else:
                A[i-1] += min(A)
                ans.append([a,i])

        else:
            if max(A) > 0:
                A[i] += max(A)
                ans.append([b,i+1])
            else:
                A[i-1] += max(A)
                ans.append([b,i])

print(m)
for x,y in ans:
    print(x, y)




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

key = 0
for a in A:
    if abs(a) > abs(key):
        key = a
key_i = A.index(key)

m = 0
ans = []
if key > 0:
    for i in range(N):
        if A[i] < 0:
            m += 1
            A[i] += key
            ans.append([key_i+1, i+1])

    for i in range(1, N):
        if A[i-1] > A[i]:
            A[i] += A[i-1]
            m += 1
            ans.append([i, i+1])

    print(m)
    for x, y in ans:
        print(x, y)

elif key < 0:
    for i in range(N):
        if A[i] > 0:
            m += 1
            A[i] += key
            ans.append([key_i+1, i+1])

    for i in range(N-1, 0, -1):
        if A[i-1] > A[i]:
            A[i-1] += A[i]
            m += 1
            ans.append([i+1, i])

    print(m)
    for x, y in ans:
        print(x, y)

else:
    print(0)
Buggy python submission (verdict: Runtime Error):
S = input()
C = {"a": 0, "b": 0, "c": 0}
for s in S:
    C["s"] += 1
if abs(C["a"] - C["b"]) <= 1 and abs(C["a"] - C["b"]) <= 1 and abs(C["a"] - C["b"]) <= 1:
    print("YES")
else:
    print("NO")


Fixed submission:
S = input()
C = {"a": 0, "b": 0, "c": 0}
for s in S:
    C[s] += 1
if abs(C["a"] - C["b"]) <= 1 and abs(C["b"] - C["c"]) <= 1 and abs(C["c"] - C["a"]) <= 1:
    print("YES")
else:
    print("NO")
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())))
B = np.array(list(map(int, input().split())))
C = np.array(list(map(int, input().split())))

ans = 0
for a in A:
    for b in B[(np.where(B > a))]:
        ans += len(B[(np.where(b < C))])

print(ans)




Fixed submission:
import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())))
B = np.array(list(map(int, input().split())))
C = np.array(list(map(int, input().split())))
A.sort()
B.sort()
C.sort()

ans = 0
for b in B:
    AB = A.searchsorted(b, side='left')
    CB = len(B) - C.searchsorted(b, side='right')
    ans += AB * CB

print(ans)
Buggy python submission (verdict: Runtime Error):
S = list(input())
i, j = 0, len(S) - 1
ans = 0

while i != j:
    if S[i] == S[j]:
        i += 1
        j -= 1

    elif S[i] == 'x':
        i += 1
        ans += 1

    elif S[j] == 'x':
        j -= 1
        ans += 1

    else:
        print('-1')
        break

else:
    print(ans)


Fixed submission:
S = input()
S2 = "".join([s for s in S if s != "x"])

if S2 != S2[::-1]:
    print(-1)
    exit()

A = []
cnt = 0
for s in S:
    if s != "x":
        A.append(cnt)
        cnt = 0
    else:
        cnt += 1
A.append(cnt)

ans = 0
for i in range(len(A) // 2):
    ans += abs(A[i] - A[-i-1])
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):

s = list(input())
s2 = s.copy()

for i in range(len(s2)):
    if "x" in s2:
        s2.remove("x")
        
def cycle_check(S , level):
    
    # 回文になっているかどうかのみ
    if level == 1:
        for i in range(len(S)//2):
            if S[i] != S[-i-1]:
                return True
        else:
            return False
    
    # 必要なxの個数
    if level == 2:
        x_cnt = 0
        x_list = []
        for s in S:
            if s != "x":
                if x_cnt > 0:
                    x_list.append(x_cnt)
                x_list.append(0)
                x_cnt = 0
            else:
                x_cnt += 1
        
        if x_cnt > 0:
            x_list.append(x_cnt)
        
        ans = 0
        for i in range(len(x_list)//2):
            ans += abs(x_list[i]-x_list[-i-1])
            
        return ans
    
if cycle_check(s2,1):
    print(-1)

else:
    print(cycle_check(s, 2))

Fixed submission:
S = input()
S2 = "".join([s for s in S if s != "x"])

if S2 != S2[::-1]:
    print(-1)
    exit()

A = []
cnt = 0
for s in S:
    if s != "x":
        A.append(cnt)
        cnt = 0
    else:
        cnt += 1
A.append(cnt)

ans = 0
for i in range(len(A) // 2):
    ans += abs(A[i] - A[-i-1])
print(ans)
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
XY = []
YX = []
for i in range(N):
    x, y = map(int, input().split())
    XY.append([x, y, i])
    YX.append([y, x, i])
XY.sort()
YX.sort()

x_order = {}
for xo, p in enumerate(XY):
    x, y, i = p
    x_order[i] = xo

cums = [[0 for j in range(N+1)] for i in range(N+1)]
for i in range(N):
    y, x, pi = YX[i]
    xo = x_order[pi]
    for j in range(N + 1):
        cums[i + 1][j] = cums[i][j] + (1 if j > xo else 0)

ans = float('inf')

for i in range(N-1):
    for j in range(i+1, N):
        for k in range(N-1):
            for l in range(k+1, N):
                if cums[l+1][j+1] - cums[l+1][i] - cums[k][j+1] + cums[k][i] >= K:
                        ans = min(ans, (XY[j][0]-XY[i][0]) * (YX[l][0]-YX[k][0]))

print(ans)

Fixed submission:

A, B, C = map(int, input().split())

if (A==B) & (A!=C):
    print(C)
elif (A==C) & (A!=B):
    print(B)
else:
    print(A)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
D = list(map(int, input().split()))
M = int(input())
T = list(map(int, input().split()))

for i in range(M):
    if T[i] in D:
        D.remove(T[i])
    else:
        print("NO")
        break
else:
    print("YES")

Fixed submission:

from collections import Counter

N = int(input())
D = list(map(int, input().split()))
M = int(input())
T = list(map(int, input().split()))

T_cnt = list(Counter(T).items())
D_cnt = Counter(D)

for t in T_cnt:
    if D_cnt[t[0]] < t[1]:
        print("NO")
        break

else:
    print("YES")
Buggy python submission (verdict: Runtime Error):
A, B, C, D, E, F = map(int, input().split())
# A:水を100Ag　B:水を100Bg C:砂糖をCg D:砂糖をDg E:100gあたりの溶ける最大量　F:入れられる物質の質量の限界

ans_mizu = 100
ans_sato = 0

mizu = set()
for i in range(int(F/(100*max(A,B)))+1):
    for j in range(int(F/(100*min(A,B)))+1):
        if 100*A*i + 100*B*j <= F:
            mizu.add(100*A*i+100*B*j)
            
for m in mizu:
    howaryo = (m*E)//100
    for i in range(int(howaryo//C)+1):
        for j in range(int(howaryo//D)+1):
            sato = C*i + D*j
            if (m + sato <= F) & (sato <= howaryo):
                if (ans_sato/(ans_mizu+ans_sato)) < (sato/(m+sato)):
                    ans_mizu = m
                    ans_sato = sato

print(ans_mizu+ans_sato,ans_sato)

Fixed submission:

A, B, C, D, E, F = map(int, input().split())
# A:水を100Ag　B:水を100Bg C:砂糖をCg D:砂糖をDg E:100gあたりの溶ける最大量　F:入れられる物質の質量の限界

ans_mizu = 1
ans_sato = 0
pat = []
mizu = set()
for i in range(int(F/100)+1):
    for j in range(int(F/100)+1):
        if 100*A*i + 100*B*j <= F:
            mizu.add(100*A*i+100*B*j)

mizu.remove(0)

for m in mizu:
    howaryo = (m*E)//100
    for i in range(int(howaryo/C)+1):
        for j in range(int(howaryo/D)+1):
            sato = C*i + D*j
            if (m + sato <= F) & (sato <= howaryo):
                ans_sato = max(ans_sato,sato)
                
    pat.append([m+ans_sato,ans_sato])
    ans_mizu = 1
    ans_sato = 0
    
pat.sort(key = lambda x:x[1]/(x[0]+x[1]), reverse = True)
print(pat[0][0],pat[0][1])
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
Map = [list(map(int, input().split())) for i in range(N)]

INF = float('inf')
shortest = [[INF]*N for i in range(N)]

ans = 0
for k in range(N):
    for i in range(N):
        for j in range(N):
            if Map[i][k] == 0 or Map[k][j] == 0:
                continue

            if Map[i][k] + Map[k][j] < Map[i][j]:
                print(-1)
                exit()

            elif Map[i][k] + Map[k][j] == Map[i][j]:
                ans -= Map[i][j]

for m in Map:
    ans += sum(m)

print(ans // 2)

Fixed submission:
N = int(input())
Map = [list(map(int, input().split())) for i in range(N)]

ans = sum([sum(Map[i]) for i in range(N)])

for k in range(N):
    for i in range(N):
        for j in range(N):
            if Map[i][k] + Map[k][j] < Map[i][j]:
                print(-1)
                exit()

for i in range(N):
    for j in range(N):
        for k in range(N):
            if i == k or j == k:
                continue
            if Map[i][k] + Map[k][j] == Map[i][j]:
                ans -= Map[i][j]
                break

print(ans//2)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
Map = [list(map(int, input().split())) for i in range(N)]

INF = float('inf')
shortest = [[INF]*N for i in range(N)]

ans = 0
for k in range(N):
    for i in range(N):
        for j in range(N):
            if Map[i][k] + Map[k][j] < Map[i][j]:
                print(-1)
                exit()
            elif Map[i][k] + Map[k][j] == Map[i][j] and Map[i][k] > 0 and Map[k][j] > 0:
                ans -= Map[i][j]

for m in Map:
    ans += sum(m)

print(ans // 2)

Fixed submission:
N = int(input())
Map = [list(map(int, input().split())) for i in range(N)]

ans = sum([sum(Map[i]) for i in range(N)])

for k in range(N):
    for i in range(N):
        for j in range(N):
            if Map[i][k] + Map[k][j] < Map[i][j]:
                print(-1)
                exit()

for i in range(N):
    for j in range(N):
        for k in range(N):
            if i == k or j == k:
                continue
            if Map[i][k] + Map[k][j] == Map[i][j]:
                ans -= Map[i][j]
                break

print(ans//2)