Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
ta_c,ao_c,num = map(int,input().split())

if num <= ta_c:
    print(ta_o-num,ao_c):
elif ta_c < num <= ta_c + ao_c:
    ao_c = ta_c+ao_c - num
    ta_c = 0
    print(ta_c,ao_c)
else;
    ta_c, ao_c = 0,0
    print(ta_c,ao_c)

Fixed submission:
ta_c,ao_c,num = map(int,input().split())

if num <= ta_c:
    print(ta_c-num,ao_c)
elif ta_c < num <= ta_c + ao_c:
    ao_c = ta_c+ao_c - num
    ta_c = 0
    print(ta_c,ao_c)
else:
    ta_c, ao_c = 0,0
    print(ta_c,ao_c)

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

ta_c,ao_c,num = map(int,input().split())

for _ in [0]*num:
    if ta_c > 0:
        ta_c -=1
    elif ao_c >0:
        ao_c -=1

print(ta_c,ao_c)

Fixed submission:
ta_c,ao_c,num = map(int,input().split())

if num <= ta_c:
    print(ta_c-num,ao_c)
elif ta_c < num <= ta_c + ao_c:
    ao_c = ta_c+ao_c - num
    ta_c = 0
    print(ta_c,ao_c)
else:
    ta_c, ao_c = 0,0
    print(ta_c,ao_c)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

ta_c,ao_c,num = map(int,input().split())

for i in range(num):
    if ta_c > 0:
        ta_c -=1
    elif ao_c >0:
        ao_c -=1

print(ta_c,ao_c)

Fixed submission:
ta_c,ao_c,num = map(int,input().split())

if num <= ta_c:
    print(ta_c-num,ao_c)
elif ta_c < num <= ta_c + ao_c:
    ao_c = ta_c+ao_c - num
    ta_c = 0
    print(ta_c,ao_c)
else:
    ta_c, ao_c = 0,0
    print(ta_c,ao_c)

Buggy python submission (verdict: Time Limit Exceeded):
ta_c,ao_c,num = map(int,input().split())
 
for i in range(num):
    if ta_c > 0:
        ta_c -=1
    elif ao_c >0:
        ao_c -=1
 
print("{} {}".format(ta_c,ao_c))

Fixed submission:
ta_c,ao_c,num = map(int,input().split())

if num <= ta_c:
    print(ta_c-num,ao_c)
elif ta_c < num <= ta_c + ao_c:
    ao_c = ta_c+ao_c - num
    ta_c = 0
    print(ta_c,ao_c)
else:
    ta_c, ao_c = 0,0
    print(ta_c,ao_c)

Buggy python submission (verdict: Time Limit Exceeded):
ta_c,ao_c,num = map(int,input().split())

for i in range(num):
    if ta_c > 0:
        ta_c -=1
    elif ao_c >0:
        ao_c -=1

print("{} {}".format(ta_c,ao_c))


Fixed submission:
ta_c,ao_c,num = map(int,input().split())

if num <= ta_c:
    print(ta_c-num,ao_c)
elif ta_c < num <= ta_c + ao_c:
    ao_c = ta_c+ao_c - num
    ta_c = 0
    print(ta_c,ao_c)
else:
    ta_c, ao_c = 0,0
    print(ta_c,ao_c)
Buggy python submission (verdict: Runtime Error):
A, V = map(int, input().split())
B, W = map(int, input().split())
T = int(input())

A_sum = A + V * T
B_sum = B + W * T

if B > A:
    if A_sum >= B_sum:
        print('YES')
    else:
        print('NO')

else:
    if A_sum <= B_sum
        print('YES')
    else:
        print('NO')


Fixed submission:
A, V = map(int, input().split())
B, W = map(int, input().split())
T = int(input())


if A < B:
    A_sum = A + (V * T)
    B_sum = B + (W * T)
    if A_sum >= B_sum:
        print('YES')
    else:
        print('NO')

else:
    A_sum = A - (V * T)
    B_sum = B - (W * T)
    if A_sum <= B_sum:
        print('YES')
    else:
        print('NO')
Buggy python submission (verdict: Runtime Error):
T = list(map(str, input()))
count = 0
ans = []

if T[0] == '?':
    T.pop(0)
    if T[1] == 'D' or T[1] == '?':
        ans.append('P')
        T.insert(0, 'P')
    else:
        ans.append('D')
        T.insert(0, 'D')
else:
    ans.append(T[0])

for i in range(1, len(T)):
    if T[i] == '?':
        if ans[i - 1] == 'D':
            if len(T) % 2 == 0:
                ans.append('P')
            else:
                ans.append('D')
        else:
            ans.append('D')
    else:
        ans.append(T[i])

ans_ans = ''.join(ans);

print(ans_ans)

Fixed submission:
T = list(map(str, input()))
count = 0
ans = []




for i in range(0, len(T)):
    if T[i] == '?':
        ans.append('D')
    else:
        ans.append(T[i])


ans_ans = ''.join(ans);

print(ans_ans)

Buggy python submission (verdict: Runtime Error):
T = list(map(str, input()))
count = 0
ans = []

if T[0] == '?':
    T.pop(0)
    if T[1] == 'D' or T[1] == '?':
        ans.append('P')
        T.insert(0, 'P')
    else:
        ans.append('D')
        T.insert(0, 'D')
else:
    ans.append(T[0])

for i in range(1, len(T)):
    if T[i] == '?':
        if ans[i - 1] == 'D':
            if len(T) % 2 == 0:
                ans.append('P')
            else:
                ans.append('D')
        else:
            ans.append('D')
    else:
        ans.append(T[i])


for i in range (0, len(ans) - 1):
    if ans[i] == 'P' and ans[i + 1] == 'D':
        count += 1
    if ans[i] == 'D':
        count += 1
if ans[len(ans) - 1] == 'D':
    count += 1



print(str(count))


Fixed submission:
T = list(map(str, input()))
count = 0
ans = []




for i in range(0, len(T)):
    if T[i] == '?':
        ans.append('D')
    else:
        ans.append(T[i])


ans_ans = ''.join(ans);

print(ans_ans)
Buggy python submission (verdict: Runtime Error):
a, b, c = map(int, input().split())

d = c - a - b
 
if d > 0 and 4 * a * b < d * d
    print('Yes')
else:
    print('No')

Fixed submission:
a, b, c = map(int, input().split())

d = c - a - b
 
if d > 0 and 4 * a * b < pow(d, 2):
    print('Yes')
else:
    print('No')

Buggy python submission (verdict: Runtime Error):

a, b, c = map(int, input().split())

d = c - a - b
 
if d > 0 and 4 * a * b > d * d
    print('Yes')
else:
    print('No')

Fixed submission:
a, b, c = map(int, input().split())

d = c - a - b
 
if d > 0 and 4 * a * b < pow(d, 2):
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Time Limit Exceeded):
def cal(a):

    return ((1 + a) / 2)

N, K = map(int, input().split())
p = list(map(int, input().split()))
ans_raw = []

for i in range(0, N):
    p[i] = cal(p[i])

for i in range(0, N - K + 1):
    ans = 0
    for j in range(i, i + K):
        ans += p[j]
    ans_raw.append(ans)


print(max(ans_raw))

Fixed submission:
def cal(a):
 	return ((1 + a) / 2)
 
N, K = map(int, input().split())
p = list(map(int, input().split()))
ans_raw = []
sum_raw = []
sum_cal = 0
 
for i in range(0, N):
    p[i] = cal(p[i])


for i in range(0, N):
	sum_cal += p[i]
	sum_raw.append(sum_cal)

for i in range(0, N - K):
	ans = sum_raw[i + K] - sum_raw[i]
	ans_raw.append(ans)

ans_0 = sum_raw[K - 1]
ans_raw.append(ans_0)

print(max(ans_raw))

Buggy python submission (verdict: Time Limit Exceeded):
def cal(a):
    cal_sum = 0
    for i in range(1, a + 1):
        cal_sum += i
    return (cal_sum / a)

N, K = map(int, input().split())
p = list(map(int, input().split()))
ans_raw = []

for i in range(0, N):
    p[i] = cal(p[i])

for i in range(0, N - K + 1):
    ans = 0
    for j in range(i, i + K):
        ans += p[j]
    ans_raw.append(ans)


print(max(ans_raw))

Fixed submission:
def cal(a):
 	return ((1 + a) / 2)
 
N, K = map(int, input().split())
p = list(map(int, input().split()))
ans_raw = []
sum_raw = []
sum_cal = 0
 
for i in range(0, N):
    p[i] = cal(p[i])


for i in range(0, N):
	sum_cal += p[i]
	sum_raw.append(sum_cal)

for i in range(0, N - K):
	ans = sum_raw[i + K] - sum_raw[i]
	ans_raw.append(ans)

ans_0 = sum_raw[K - 1]
ans_raw.append(ans_0)

print(max(ans_raw))

Buggy python submission (verdict: Time Limit Exceeded):
def cal(a):
    cal_sum = 0
    for i in range(1, a + 1):
        cal_sum += i
    return (cal_sum / a)


N, K = map(int, input().split())
p = list(map(int, input().split()))
ans_raw = []
index = 0

for i in range(0, N):
    p[i] = cal(p[i])



for i in range(0, N - K + 1):
    ans = 0
    for j in range(i, i + K):
        ans += p[j]
    ans_raw.append(ans)

max_raw = ans_raw[0]

for i in range(0, len(ans_raw)):
    if max_raw < ans_raw[i]:
        index = i
        max_raw = ans_raw[i]

print(max_raw)

Fixed submission:
def cal(a):
 	return ((1 + a) / 2)
 
N, K = map(int, input().split())
p = list(map(int, input().split()))
ans_raw = []
sum_raw = []
sum_cal = 0
 
for i in range(0, N):
    p[i] = cal(p[i])


for i in range(0, N):
	sum_cal += p[i]
	sum_raw.append(sum_cal)

for i in range(0, N - K):
	ans = sum_raw[i + K] - sum_raw[i]
	ans_raw.append(ans)

ans_0 = sum_raw[K - 1]
ans_raw.append(ans_0)

print(max(ans_raw))
Buggy python submission (verdict: Runtime Error):
N, X = map(int, input().split())
m = []
count = N
X_new = X

for i in range(0, N):
	m.append(input())

print(N + (X - sum(m)) // min(m))

Fixed submission:
N, X = map(int, input().split())
m = []
for i in range(N):
	m.append(int(input()))
print(N + (X - int(sum(m))) // int(min(m)))
Buggy python submission (verdict: Time Limit Exceeded):
K, S = map(int, input().split())
count = 0

for i in range(0 ,K + 1):
	for j in range(0 ,K + 1):
		for k in range(0, K +1):
			if S == i + j + k:
				count += 1

print(str(count))

Fixed submission:
K, S = map(int, input().split())
count = 0

for i in range(0 ,K + 1):
	for j in range(0 ,K + 1):
		z = S - i - j
		if z >= 0 and z <= K:
			count += 1

print(str(count))

Buggy python submission (verdict: Time Limit Exceeded):
K, S = map(int, input().split())
X = []
Y = []
Z = []
count = 0

for i in range(0, K + 1):
	X.append(i)
	Y.append(i)
	Z.append(i)

for i in range(0 ,K + 1):
	for j in range(0 ,K + 1):
		for k in range(0 ,K + 1):
			if S == X[i] + Y[j] + Z[k]:
				count += 1

print(str(count))

Fixed submission:
K, S = map(int, input().split())
count = 0

for i in range(0 ,K + 1):
	for j in range(0 ,K + 1):
		z = S - i - j
		if z >= 0 and z <= K:
			count += 1

print(str(count))
Buggy python submission (verdict: Runtime Error):
#include <iostream>
using namespace std;
int main(){
    int N;
    cin >> N;
    int W[N];
    for(int i=0;i<N;i++)W[i] = 0;
    for(int i=0;i<N-1;i++){
        int A;
        cin >> A;
        W[A-1] += 1;
    }
    for(int i=0;i<N;i++){
        cout << W[i] << '\n';
    }
    return 0;
}

Fixed submission:
from math import pi
r = int(input())
print(2*r*pi)
Buggy python submission (verdict: Time Limit Exceeded):
x,y,a,b,c = map(int,input().split())
p = input().split()
p = [int(s) for s in p]
q = input().split()
q = [int(s) for s in q]
r = input().split()
r = [int(s) for s in r]
reds = sorted(p,reverse=True)
reds = reds[:x]
greens = sorted(q,reverse=True)
greens = greens[:y]
r = sorted(r,reverse=True)
while len(r) > 0 and (r[0] > reds[x-1] or r[0] > greens[y-1]):
    if(reds[x-1] > greens[y-1]):
        del greens[y-1]
        greens.insert(0,r.pop(0))
    else:
        del reds[x-1]
        reds.insert(0,r.pop(0))

print(sum(reds)+sum(greens))

Fixed submission:
x,y,a,b,c = map(int,input().split())
p = input().split()
p = [int(s) for s in p]
q = input().split()
q = [int(s) for s in q]
r = input().split()
r = [int(s) for s in r]
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
s = p[:x] + q[:y] + r
s.sort(reverse=True)
print(sum(s[:x+y]))
Buggy python submission (verdict: Runtime Error):
n=input()
if n[0]-2*n[1]<0:
  print(0)
else:
  print(n[0]-2*n[1])

Fixed submission:
s=list(map(int,input().split()))
if s[0]-2*s[1]<0:
  print(0)
else:
  print(s[0]-2*s[1])

Buggy python submission (verdict: Runtime Error):
s=list(map(int,input().split()))
if s[1]-2*s[2]<0:
  print(0)
else:
  print(s[1]-2*s[2])

Fixed submission:
s=list(map(int,input().split()))
if s[0]-2*s[1]<0:
  print(0)
else:
  print(s[0]-2*s[1])

Buggy python submission (verdict: Runtime Error):
s=input().split()
if s[1]-2*s[2]<0:
  print(0)
else:
  print(s[1]-2*s[2])

Fixed submission:
s=list(map(int,input().split()))
if s[0]-2*s[1]<0:
  print(0)
else:
  print(s[0]-2*s[1])
Buggy python submission (verdict: Runtime Error):
n=int(input())
s=list(input().split())
sum=0
i=1
str=s[0]
while i<=n-1:
  if str == s[i]:
    continue
  else:
    str=s[i]
    sum+=1
print(sum)
  
  
  

Fixed submission:
n=int(input())
s=input()
sum=1
i=1
str=s[0]
while i<=n-1:
  if str == s[i]:
    i+=1
  else:
    str=s[i]
    sum+=1
    i+=1
    
print(sum)
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import combinations
N = int(input())
A = [int(i) for i in input().split(maxsplit=N)]
sumA = 0
for a, b in combinations(A, 2):
    sumA += (a * b) % (10**9 + 7)
print(sumA % (10**9 + 7))


Fixed submission:
def resolve():
    N = int(input())
    A = [int(i) for i in input().split(maxsplit=N)]
    presum = [0 for _ in range(N + 1)]
    for i in range(N):
        presum[i + 1] = presum[i] + A[i]
    sumA = 0
    for i in range(1, N):
        sumA += (A[i] * (presum[i])) % (10**9 + 7)
    print(sumA % (10**9 + 7))


resolve()
Buggy python submission (verdict: Runtime Error):
def check(x, A, K):
    import math
    sumA = 0
    for a in A:
        if a > x:
            sumA += math.ceil(a / x) - 1
    if sumA <= K:
        return True
    else:
        return False


def resolve():
    import bisect
    N, K = [int(i) for i in input().split()]
    A = [int(i) for i in input().split()]

    ok = max(A)  # maxVal when minimize
    ng = -1  # maxVal when maximize
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if check(mid, A, K):
            ok = mid
        else:
            ng = mid
    print(ok)


resolve()

Fixed submission:
def check(x, A, K):
    import math
    sumA = 0
    for a in A:
        if a > x:
            sumA += math.ceil(a / x) - 1
    if sumA <= K:
        return True
    else:
        return False


def resolve():
    _, K = [int(i) for i in input().split()]
    A = [int(i) for i in input().split()]

    ok = max(A)  # maxVal when minimize
    ng = -1  # maxVal when maximize
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if mid > 0 and check(mid, A, K):
            ok = mid
        else:
            ng = mid
    print(ok)


resolve()
Buggy python submission (verdict: Time Limit Exceeded):
def resolve():
    from collections import deque
    N, K = [int(i) for i in input().split()]
    A = [int(i) for i in input().split()]
    sA = 1
    s = deque()
    for i in range(K):
        s.append(A[i])
        sA *= A[i]
    tmp = sA
    for i in range(K, N):
        sA //= s.popleft()
        s.append(A[i])
        sA *= A[i]
        if tmp < sA:
            print("Yes")
        else:
            print("No")
        tmp = sA


resolve()


Fixed submission:
def resolve():
    from collections import deque
    N, K = [int(i) for i in input().split()]
    A = [int(i) for i in input().split()]
    for i in range(K, N):
        if A[i - K] < A[i]:
            print("Yes")
        else:
            print("No")


resolve()

Buggy python submission (verdict: Time Limit Exceeded):
def resolve():
    N, K = [int(i) for i in input().split()]
    A = [int(i) for i in input().split()]
    tmp = -1
    for i in range(N - K + 1):
        sA = 1
        for j in range(K):
            sA *= A[i + j]
        if tmp > 0:
            if tmp < sA:
                print("Yes")
            else:
                print("No")
        tmp = sA


resolve()


Fixed submission:
def resolve():
    from collections import deque
    N, K = [int(i) for i in input().split()]
    A = [int(i) for i in input().split()]
    for i in range(K, N):
        if A[i - K] < A[i]:
            print("Yes")
        else:
            print("No")


resolve()
Buggy python submission (verdict: Runtime Error):
def resolve():
    N, M, K = [int(i) for i in input().split()]
    A = [int(i) for i in input().split()]
    B = [int(i) for i in input().split()]
    sumA = 0
    ai, bi = 0, 0
    while sumA <= K:
        if ai < N and A[ai] < B[bi] and sumA + A[ai] <= K:
            sumA += A[ai]
            ai += 1
        elif bi < M and sumA + B[bi] <= K:
            sumA += B[bi]
            bi += 1
        else:
            break
    print(ai + bi)


resolve()


Fixed submission:
def check(A, mid, K):
    return A[mid] <= K


def binMax(A, K):
    ok = -1  # maxVal when minimize
    ng = len(A)  # maxVal when maximize
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if check(A, mid, K):
            ok = mid
        else:
            ng = mid
    return ok


def resolve():
    N, M, K = [int(i) for i in input().split()]
    A = [int(i) for i in input().split()]
    B = [int(i) for i in input().split()]
    presumA = [0 for _ in range(N + 1)]
    for i in range(N):
        presumA[i + 1] = presumA[i] + A[i]
    presumB = [0 for _ in range(M + 1)]
    for i in range(M):
        presumB[i + 1] = presumB[i] + B[i]
    startA = binMax(presumA, K)
    maxA = 0
    for ai in range(startA, -1, -1):
        maxA = max(maxA, ai + binMax(presumB, K - presumA[ai]))
    print(maxA)

resolve()
Buggy python submission (verdict: Time Limit Exceeded):
def resolve():
    import itertools
    N, K = [int(i) for i in input().split()]
    A = [int(i) for i in input().split()]
    minA = 10**9
    for a in itertools.combinations(A, K):
        minA = min(minA, sum(a))
    print(minA)

resolve()


Fixed submission:
def resolve():
    N, K = [int(i) for i in input().split()]
    A = sorted([int(i) for i in input().split()])
    sumA = 0
    for a in A[:K]:
        sumA += a
    print(sumA)


resolve()
Buggy python submission (verdict: Runtime Error):
def resolve():
    # 1000000000000001
    from collections import deque
    S = "abcdefghijklmnopqrstuvwxyz"
    N = int(input())
    tmp = N
    A = deque()

    while True:
        N, a = divmod(N, 26)
        A.append(a)
        if N == 0:
            break
    print(N, a, file=sys.stderr)
    if tmp % 26 == 0:
        A.pop()
    for a in reversed(A):
        print(S[a - 1], end="")
    print()

resolve()

Fixed submission:
def resolve():
    from collections import deque
    S = "abcdefghijklmnopqrstuvwxyz"
    N = int(input())
    A = deque()
    while True:
        N -= 1
        N, a = divmod(N, 26)
        A.appendleft(a)
        if N == 0:
            break
    for a in A:
        print(S[a], end="")
    print()


resolve()
Buggy python submission (verdict: Runtime Error):
def resolve():
    N, M = [int(i) for i in input().split()]
    print(A*B)


resolve()


Fixed submission:
def resolve():
    N, M = [int(i) for i in input().split()]
    print(N*M)


resolve()
Buggy python submission (verdict: Runtime Error):
def resolve():
    N, M = [int(i) for i in input().split()]
    path = [[] for _ in range(N)]
    for _ in range(M):
        A, B = [int(i) for i in input().split()]
        path[A - 1].append(B - 1)
        path[B - 1].append(A - 1)
    visited = [-1] * N
    que = [0]
    visited[0] = 0

    while que:
        v = que.pop(0)
        print(v, path[v], file=sys.stderr)
        for nv in path[v]:
            if visited[nv] != -1:
                continue
            print(nv, visited[v] + 1, file=sys.stderr)
            visited[nv] = v + 1
            que.append(nv)

    if -1 in visited:
        print("No")
    else:
        print("Yes")
        for i in range(N - 1):
            print(visited[i + 1])


resolve()


Fixed submission:
def resolve():
    N, M = [int(i) for i in input().split()]
    path = [[] for _ in range(N)]
    for _ in range(M):
        A, B = [int(i) for i in input().split()]
        path[A - 1].append(B - 1)
        path[B - 1].append(A - 1)
    visited = [-1] * N
    que = [0]
    visited[0] = 0

    while que:
        v = que.pop(0)
        for nv in path[v]:
            if visited[nv] != -1:
                continue
            visited[nv] = v + 1
            que.append(nv)

    if -1 in visited:
        print("No")
    else:
        print("Yes")
        for i in range(N - 1):
            print(visited[i + 1])


resolve()
Buggy python submission (verdict: Runtime Error):
import numpy as np
import itertools

n, m, x = map(int, input().split())
calist = []
for i in range(n):
    ca = list(map(int, input().split()))
    calist.append(ca)

# print(n, m, x, calist)

# check
for j in range(m):
    sum = 0
    for i in range(n):
        sum += calist[i][j + 1]
    if sum < x:
        print(-1)
        exit()

calist = np.array(calist)
dp = float('inf')

for comb in range(1, m + 1):
    sc = itertools.combinations(calist, comb)
    sum = 0
    a = np.array([0 for _ in range(m)])
    for ca in sc:
        sum += ca[0]
        a += ca[1:]
    if False not in (a > x) and sum < dp:
        dp = sum

print(dp)


Fixed submission:
import unittest
from io import StringIO
import sys


def resolve():
    n, m, x = [int(i) for i in input().split()]
    cc = []
    aa = []
    for comb in range(n):
        c, *a = [int(comb) for comb in input().split()]
        cc.append(c)
        aa.append(a)

    ans = float('inf')
    for comb in range(2**n):
        sum = 0
        xx = [0] * m
        for i in range(n):
            if (comb >> i) & 1:
                sum += cc[i]
                for j in range(m):
                    xx[j] += aa[i][j]
        for tx in xx:
            if tx < x:
                break
        else:
            ans = min(ans, sum)

    if ans == float('inf'):
        print(-1)
    else:
        print(ans)


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """3 3 10
60 2 2 4
70 8 7 9
50 2 3 9"""
        output = """120"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """3 3 10
100 3 1 4
100 1 5 9
100 2 6 5"""
        output = """-1"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """8 5 22
100 3 7 5 3 1
164 4 5 2 7 8
334 7 2 7 2 9
234 4 7 2 8 2
541 5 4 3 3 6
235 4 8 6 9 7
394 3 6 1 6 2
872 8 4 3 7 2"""
        output = """1067"""
        self.assertIO(input, output)


if __name__ == "__main__":
    # unittest.main()
    resolve()
Buggy python submission (verdict: Time Limit Exceeded):
def gcd(a, b, c):
    minV = min([a, b, c])
    maxV = max([a, b, c])
    start = minV
    diff = maxV - minV
    if diff < start and diff != 0:
        start = diff
    for gcdV in range(start, 1, -1):
        if (a % gcdV == 0) and (b % gcdV == 0) and (c % gcdV == 0):
            return gcdV
    return 1


k = int(input())
sum = 0
for a in range(1, k + 1):
    for b in range(1, k + 1):
        for c in range(1, k + 1):
            sum += gcd(a, b, c)

print(sum)


Fixed submission:
import unittest
from io import StringIO
import sys
import itertools
import math


def gcd(a, b, c):
    n = 1
    if a == b:
        if b != c:
            n = 3
    else:
        if b != c:
            n = 6
        else:
            n = 3
    return math.gcd(math.gcd(a, b), c) * n


def resolve():
    K = int(input())
    T = [i for i in range(1, K + 1)]
    Tr = itertools.combinations_with_replacement(T, 3)
    sumT = 0
    for a, b, c in Tr:
        sumT += gcd(a, b, c)
    print(sumT)


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """2"""
        output = """9"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """200"""
        output = """10813692"""
        self.assertIO(input, output)

    def test_add(self):
        input = """195"""
        output = """9997134"""
        self.assertIO(input, output)


if __name__ == "__main__":
    # unittest.main()
    resolve()