Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):

n = int(input())
a = sorted(map(int, input().split()))
b = sorted(map(int, input().split()))
c = sorted(map(int, input().split()))
ans = 0
for i in range(n):
    for j in range(n - sum(x > a[i] for x in b), n):
        ans += sum(x > b[j] for x in c)

print(ans)

Fixed submission:
from bisect import bisect_left, bisect_right

n = int(input())
a = sorted(map(int, input().split()))
b = sorted(map(int, input().split()))
c = sorted(map(int, input().split()))
ans = 0
def bin_search(x, n, flag):
    if flag == True:
        return bisect_left(x, n)
    else:
        return bisect_right(x, n)



for i in range(n):
    ans += bin_search(a, b[i], True) * (n - bin_search(c, b[i], False))

print(ans)
Buggy python submission (verdict: Runtime Error):
s = input()
t = input()
ans = s
for i in range(len(t)):
    for j in range(len(s)):
        ans = list(s)
        flag = True
        if t[i] == s[j]:
            for k in range(i + 1, len(t)):
                if t[i + k] != s[j + k] and s[j + k] != "?":
                    flag = False
                    break
                ans[j + k] = t[i + k]
            for k in range(0, i):
                if t[i + k] != s[j + k] and s[j + k] != "?":
                    flag = False
                    break
                ans[j + k] = t[i + k]

            
            if flag == True:
                for i in range(len(ans)):
                    if ans[i] == "?":
                        ans[i] = "a"

                print("".join(ans))
                exit()

print("UNRESTORABLE")

Fixed submission:
s = input()
t = input()
ans = []
if len(s) < len(t):
    print("UNRESTORABLE")
    exit()

for i in range(len(s) - len(t) + 1):
    prot = list(s)
    flag = True
    for j in range(len(t)):
        if prot[i + j] != t[j] and prot[i + j] != "?":
            flag = False
            break
        prot[i + j] = t[j]


    if flag == True:
        prot = "".join(prot).replace("?", "a")
        ans.append(prot)

if ans == []:
    print("UNRESTORABLE")
else:
    ans = sorted(ans)
    print(ans[0])
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())


for h in range(1, 3500):
    for n in range(1, 3500):
        x = 4 * h * n - N * h - N * n
        if x != 0:
            w = N * h * n / (4 * h * n - N * h - N * n)
            if int(w) == w and w > 0:
                print(h, n, int(w))
                exit()


Fixed submission:
N = int(input())


for h in range(1, 3500):
    for n in range(1, 3500):
        x = 4 * h * n - N * h - N * n
        if x != 0:
            w = N * h * n / (4 * h * n - N * h - N * n)
            if int(w) == w and w > 0:
                print(h, n, int(w))
                exit()
Buggy python submission (verdict: Runtime Error):
from math import gcd
n = int(input())

ans = 1
for i in range(n):
    t = int(input())
    ans = ans * t // gcd(ans, t)

print(ans)

Fixed submission:
from fractions import gcd
n = int(input())

ans = 1
for i in range(n):
    t = int(input())
    ans = ans * t // gcd(ans, t)

print(ans)

Buggy python submission (verdict: Runtime Error):
from fraction import gcd
n = int(input())

ans = 1
for i in range(n):
    t = int(input())
    ans = ans * t // gcd(ans, t)

print(ans)

Fixed submission:
from fractions import gcd
n = int(input())

ans = 1
for i in range(n):
    t = int(input())
    ans = ans * t // gcd(ans, t)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())

a, b = [0] * m, [0] * m
for i in range(m):
    a[i], b[i] = map(int, input().split())

for i in range(m):
    if a[i] == 1:
        for j in range(m):
            if b[i] == a[j] and b[j] == n:
                print("POSSIBLE")
                exit()
    
print("IMPOSSIBLE")


Fixed submission:
n, m = map(int, input().split())

a, b = [0] * m, [0] * m
root_i = [False] * n
root_n = [False] * n
for i in range(m):
    a[i], b[i] = map(int, input().split())

for i in range(m):
    if a[i] == 1:
        root_i[b[i]] = True
    elif b[i] == n:
        root_n[a[i]] = True

for i in range(n):
    if root_i[i] == True and root_n[i] == True:
        print("POSSIBLE")
        exit()
    
print("IMPOSSIBLE")
Buggy python submission (verdict: Runtime Error):
from math import gcd
n, k = map(int, input().split())
a = list(map(int, input().split()))

x = a[0]
for i in range(1, n):
    x = gcd(x, a[i])

print("POSSIBLE" if k % x == 0 and max(a) >= k else "IMPOSSIBLE")


Fixed submission:
from fractions import gcd
n, k = map(int, input().split())
a = list(map(int, input().split()))

x = a[0]
for i in range(1, n):
    x = gcd(x, a[i])

print("POSSIBLE" if k % x == 0 and max(a) >= k else "IMPOSSIBLE")
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
b = []
for i in range(n):
    if i % 2 == 0:
        b.append(a[i])
    else:
        b.insert(0, a[i])
if n % 2 == 1:
    b.reverse()

for i in range(n):
    print(b[i], end = " ")
print()

Fixed submission:
n = int(input())
a = list(map(int, input().split()))

def print_data(a, flag):
    for i in range(n - 1, -1, -2):
        print(a[i], end = " ")
    
    for i in range(0 + flag, n, 2):
        print(a[i], end = " ")
    
    print()


if n % 2 == 0:
    print_data(a, 0)
else:
    print_data(a, 1)
Buggy python submission (verdict: Runtime Error):
from collections import defaultdict

n = int(input())
a = list(map(int, input().split()))
ans = 0
cnt_free = sum(x >= 3200 for x in a)
for i in range(8):
    if sum(x >= 400 * i and x < 400 * (i + 1) for x in a) >= 1:
        ans += 1
print(max(1, ans))
print(min(8, ans + cnt_free))

Fixed submission:
r, g, b = map(int, input().split())

n = int(str(r) + str(g) + str(b))
print("YES" if n % 4 == 0 else "NO")
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = [0] * n
for i in range(n):
    s[i] = int(input())

ans = 0
for i in range(2 ** n):
    score = 0
    for j in range(n):
        if i >> j & 1:
            score += s[j]
        
    if score % 10 != 0:
        ans = max(ans, score)

print(ans)



Fixed submission:
n = int(input())
s = [0] * n
for i in range(n):
    s[i] = int(input())

ans = sum(s)
if ans % 10 != 0:
    print(ans)
else:
    s.sort()
    for i in range(n):
        if s[i] % 10 != 0:
            print(ans - s[i])
            exit()
        
    print(0)
Buggy python submission (verdict: Time Limit Exceeded):
a, b, c = map(int, input().split())
ans = 0
while a % 2 == 0 and b % 2 == 0 and c % 2 == 0:
    total = a + b + c
    a = (total - a) / 2
    b = (total - b) / 2
    c = (total - c) / 2
    ans += 1
print(ans)

Fixed submission:
a, b, c = map(int, input().split())
ans = 0
if a == b == c and a % 2 == 0:
    print(-1)
else:
    while a % 2 == 0 and b % 2 == 0 and c % 2 == 0:
        total = a + b + c
        a = (total - a) / 2
        b = (total - b) / 2
        c = (total - c) / 2
        ans += 1
    print(ans)
Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())

a = [list(input()) for _ in range(n)]
b = [list(input()) for _ in range(m)]
for i in range(n):
    for j in range(n):
        if a[i][j] == b[0][0] and i + m - 1 < n and j + m - 1 < n:
            flag = 1
            for y in range(i, i + m):
                for x in range(j, j + m):
                    if a[i + y][j + x] != b[y][x]:
                        flag = 0
                        break
                
            if flag == 1:
                print("Yes")
                exit()

print("No")


Fixed submission:
n, m = map(int, input().split())

a = [list(input()) for _ in range(n)]
b = [list(input()) for _ in range(m)]
for i in range(n):
    for j in range(n):
        if a[i][j] == b[0][0] and i + m - 1 < n and j + m - 1 < n:
            flag = 1
            for y in range(m):
                for x in range(m):
                    if a[i + y][j + x] != b[y][x]:
                        flag = 0
                        break
                
            if flag == 1:
                print("Yes")
                exit()

print("No")

Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())

a = [list(input()) for _ in range(n)]
b = [list(input()) for _ in range(m)]
for i in range(n):
    for j in range(n):
        if a[i][j] == b[0][0] and i + m <= n and j + m <= n:
            flag = 1
            for y in range(i, i + m):
                for x in range(j, j + m):
                    if a[i + y][j + x] != b[y][x]:
                        flag = 0
                        break
                
            if flag == 1:
                print("Yes")
                exit()

print("No")


Fixed submission:
n, m = map(int, input().split())

a = [list(input()) for _ in range(n)]
b = [list(input()) for _ in range(m)]
for i in range(n):
    for j in range(n):
        if a[i][j] == b[0][0] and i + m - 1 < n and j + m - 1 < n:
            flag = 1
            for y in range(m):
                for x in range(m):
                    if a[i + y][j + x] != b[y][x]:
                        flag = 0
                        break
                
            if flag == 1:
                print("Yes")
                exit()

print("No")
Buggy python submission (verdict: Time Limit Exceeded):
k, s = map(int, input().split())

ans = 0
for x in range(k + 1):
    for y in range(k + 1):
        for z in range(k + 1):
            if x + y + z == s:
                ans += 1
                break

print(ans)

Fixed submission:
k, s = map(int, input().split())

ans = 0
for x in range(k + 1):
    for y in range(k + 1):
        z = s - (x + y)
        if z <= k and z >= 0:
            #print(x, y, z)
            ans += 1

print(ans)
Buggy python submission (verdict: Runtime Error):
x, y = map(int, input().split())
ans = 10 ** 10
for i in range(2):
    for j in range(2):
        a = x
        b = y
        cnt = 0
        if i == 1:
            a *= -1
            cnt = 1
        if j == 1:
            b *= -1
            cnt += 1
        if a >= b:
            continue
        cnt += b - a
        a += b - a¥
        if a == b:
            ans = min(ans, cnt)

print(ans)


Fixed submission:
x, y = map(int, input().split())
ans = 10 ** 10
for i in range(2):
    for j in range(2):
        a = x
        b = y
        cnt = 0
        if i == 1:
            a *= -1
            cnt = 1
        if j == 1:
            b *= -1
            cnt += 1
        if a > b:
            continue
        cnt += b - a
        a += b - a
        #print(cnt, a, b)
        if a == b:
            ans = min(ans, cnt)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):

n = int(input())
t, a = [0] * n, [0] * n
for i in range(n):
    t[i], a[i] = map(int, input().split())
ans = a[0] + t[0]
j_pre = 1
for i in range(1, n):
    j = 1
    vote = t[i] + a[i]
    while vote * j < ans or (t[i] * j < t[i - 1] * j_pre or a[i] * j < a[i - 1] * j_pre):
        j += 1
    ans = vote * j
    j_pre = j
    #print(t[i] * j, a[i] * j)
    #print(ans)

print(ans)

Fixed submission:

n = int(input())
t, a = [0] * n, [0] * n
for i in range(n):
    t[i], a[i] = map(int, input().split())
ans = a[0] + t[0]
j_pre = 1
for i in range(1, n):
    j = max(-(-(t[i - 1] * j_pre) // t[i]), -(-(a[i - 1] * j_pre) // a[i]) )
    ans = (t[i] + a[i]) * j
    j_pre = j
    #print(t[i] * j, a[i] * j)
    #print(ans)

print(ans)
Buggy python submission (verdict: Runtime Error):
from collections import defaultdict

data = defaultdict()
for i in range(3):
    s = input()
    data[chr(ord("a") + i)] = s
cnt = defaultdict(int)
turn = "a"
while 1:
    if cnt[turn] == len(data[chr(ord(turn))]):
        ans = ord(turn) - (ord("a") - ord("A"))
        break

    cnt[turn] += 1
    turn = data[chr(ord(turn))][cnt[turn]]
print(chr(ans))

Fixed submission:
from collections import defaultdict

data = defaultdict()
cnt = defaultdict(int)
for i in range(3):
    s = input()
    data[chr(ord("a") + i)] = s

turn = "a"
while 1:
    cnt[turn] += 1
    if cnt[turn] > len(data[turn]):
        ans = ord(turn) - (ord("a") - ord("A"))
        break

    turn = data[turn][cnt[turn] - 1]
print(chr(ans))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
C = input()

C = C.lstrip('R')

count = 0
while True:

    try:
        base_index = C[::-1].index('RW')
        target_index = C.index('W')
        base_index = len(C) - base_index - 1

        C = C[:target_index] + 'R' + C[target_index+1:base_index] + 'W' + C[base_index+1:]
        count += 1
    except ValueError:
        break

print(count)


Fixed submission:
N = int(input())
C = list(input())

l = 0
r = N - 1
count = 0
while l < r:
    if C[l] == 'R' and C[r] == 'W':
        l += 1
        r -= 1
    elif C[l] == 'R' and C[r] == 'R':
        l += 1
    elif C[r] == 'W' and C[r] == 'W':
        r -= 1
    elif C[l] == 'W' and C[r] == 'R':
        l += 1
        r -= 1
        count += 1

print(count)
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
A = list(map(int, input().split()))

tmp = 1
for j in range(K):
    tmp *= A[j]
for i in range(1, N-K+1):
    ans = 1
    for j in range(K):
        ans *= A[i+j]
    # print(tmp, ans)
    if tmp < ans:
        print('Yes')
    else:
        print('No')
    tmp = ans


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

for i in range(N-K):
    if A[i] < A[i+K]:
        print('Yes')
    else:
        print('No')

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
A = list(map(int, input().split()))

tmp = []
for i in range(0, N-K+1):
    res = 1
    for j in range(K):
        res *= A[i+j]
    tmp.append(res)

for i in range(len(tmp) - 1):
    if tmp[i] - tmp[i+1] < 0:
        print('Yes')
    else:
        print('No')



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

for i in range(N-K):
    if A[i] < A[i+K]:
        print('Yes')
    else:
        print('No')
Buggy python submission (verdict: Time Limit Exceeded):
import math
N = int(input())


def calc(n):
    for x in range(1, math.ceil(math.sqrt(n))):
        if x ** 2 > n:
            return 0
        for y in range(1, x+1):
            if y ** 2 + x * y > n:
                break
            for z in range(1, y+1):
                ans = x ** 2 + y ** 2 + z ** 2 + x * y + y*z + z*x
                # print(x, y, z, ans)
                if ans == n:
                    set_num = len({x, y, z})
                    if set_num == 1:
                        return 1
                    elif set_num == 2:
                        return 3
                    else:
                        return 6
                if ans > n:
                    break
    return 0

# print(calc(17))
for n in range(1, N + 1):
    res = calc(n)
    print(res)


Fixed submission:
import math
N = int(input())

res = [0 for i in range(10 ** 4)]
for x in range(1, math.ceil(math.sqrt(10 ** 4))):
    for y in range(1, math.ceil(math.sqrt(10 ** 4))):
        for z in range(1, math.ceil(math.sqrt(10 ** 4))):
            ans = x ** 2 + y ** 2 + z ** 2 + x * y + y * z + z * x
            if ans <= 10 ** 4:
                res[ans - 1] += 1

for n in range(N):
    print(res[n])

Buggy python submission (verdict: Time Limit Exceeded):
import math
N = int(input())


def calc(n):
    for x in range(1, math.ceil(math.sqrt(n))):
        for y in range(1, x+1):
            for z in range(1, y+1):
                ans = x ** 2 + y ** 2 + z ** 2 + x*y + y*z + z*x
                # print(x, y, z, ans)
                if ans == n:
                    if len({x, y, z}) == 1:
                        return 1
                    elif len({x, y, z}) == 2:
                        return 3
                    else:
                        return 6
                if ans > n:
                    break
    return 0

# print(calc(17))
for n in range(1, N + 1):
    res = calc(n)
    print(res)


Fixed submission:
import math
N = int(input())

res = [0 for i in range(10 ** 4)]
for x in range(1, math.ceil(math.sqrt(10 ** 4))):
    for y in range(1, math.ceil(math.sqrt(10 ** 4))):
        for z in range(1, math.ceil(math.sqrt(10 ** 4))):
            ans = x ** 2 + y ** 2 + z ** 2 + x * y + y * z + z * x
            if ans <= 10 ** 4:
                res[ans - 1] += 1

for n in range(N):
    print(res[n])
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
B = [list(map(int, input().split())) for _ in range(Q)]

A_counter = Counter(A)
for b in B:
    cnt = A_counter[b[0]]
    A_counter[b[1]] += cnt
    del A_counter[b[0]]
    print(sum([num * cnt for num, cnt in A_counter.items()]))


Fixed submission:
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
B = [list(map(int, input().split())) for _ in range(Q)]

res = sum(A)
A_counter = Counter(A)
for i, j in B:
    if i not in A_counter:
        A_counter[i] = 0
    if j not in A_counter:
        A_counter[j] = 0

    res += (j - i) * A_counter[i]
    print(res)
    
    A_counter[j] += A_counter[i]
    A_counter[i] = 0

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = input()
Q = int(input())
B = [input().split() for _ in range(Q)]

for b in B:
    A = A.replace(b[0], b[1])
    print(sum([int(a) for a in A.split(' ')]))



Fixed submission:
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
B = [list(map(int, input().split())) for _ in range(Q)]

res = sum(A)
A_counter = Counter(A)
for i, j in B:
    if i not in A_counter:
        A_counter[i] = 0
    if j not in A_counter:
        A_counter[j] = 0

    res += (j - i) * A_counter[i]
    print(res)
    
    A_counter[j] += A_counter[i]
    A_counter[i] = 0
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter

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

A_sort = sorted(set(A))
A_counter = Counter(A)
# print(A_sort)

res = 0
# res_list = []
for i in range(len(A_sort)):
    # print(A_sort[i], A_sort_tmp)
    if A_counter[A_sort[i]] >= 2:
        continue

    A_sort_tmp = A_sort[:i]
    for j in range(len(A_sort_tmp)):
        if A_sort[i] % A_sort_tmp[j] == 0:
            break
    else:
        res += 1
        # res_list.append(i + 1)

print(res)
# print(res_list)


Fixed submission:
from collections import defaultdict

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

bool_list = [True] * (10 ** 6 + 1)

duplicate_dic = defaultdict(int)
for a in A:
    duplicate_dic[a] += 1
    if duplicate_dic[a] > 1:
        bool_list[a] = False

for a in A_sort:
    for i in range(2*a, 10 ** 6 + 1, a):
        bool_list[i] = False

print(sum([1 for a in A_sort if bool_list[a]]))

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter

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

A_sort = sorted(A)
A_counter = Counter(A)
# print(A_sort)

res = 0
# res_list = []
for i in range(len(A_sort)):
    A_sort_tmp = A_sort[:i]

    if A_counter[A_sort[i]] >= 2:
        continue

    for j in range(len(A_sort_tmp)):
        if A_sort[i] % A_sort_tmp[j] == 0:
            break
    else:
        res += 1
        # res_list.append(i + 1)

print(res)
# print(res_list)


Fixed submission:
from collections import defaultdict

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

bool_list = [True] * (10 ** 6 + 1)

duplicate_dic = defaultdict(int)
for a in A:
    duplicate_dic[a] += 1
    if duplicate_dic[a] > 1:
        bool_list[a] = False

for a in A_sort:
    for i in range(2*a, 10 ** 6 + 1, a):
        bool_list[i] = False

print(sum([1 for a in A_sort if bool_list[a]]))

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter

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

A_sort = sorted(A)
A_counter = Counter(A)

res = 0
# res_list = []
for i in range(len(A_sort)):
    count = 0
    A_sort_tmp = A_sort[:i]

    if A_counter[A_sort[i]] >= 2:
        continue

    for j in range(len(A_sort_tmp)):
        if A_sort[i] % A_sort_tmp[j] != 0:
            count += 1

    if count == len(A_sort_tmp):
        res += 1
        # res_list.append(i + 1)

print(res)
# print(res_list)


Fixed submission:
from collections import defaultdict

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

bool_list = [True] * (10 ** 6 + 1)

duplicate_dic = defaultdict(int)
for a in A:
    duplicate_dic[a] += 1
    if duplicate_dic[a] > 1:
        bool_list[a] = False

for a in A_sort:
    for i in range(2*a, 10 ** 6 + 1, a):
        bool_list[i] = False

print(sum([1 for a in A_sort if bool_list[a]]))
Buggy python submission (verdict: Runtime Error):
A, V = map(int, input().split())
B, W = map(int, input().split())
T = int(input())

if A - B == 0 and V != W:
    print('NO')
    exit()

if ((B - A) / (V - W)).is_integer() and ((B - A) / (V - W)) > 0:
    print('YES')
else:
    print('NO')


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

if V == W:
    print('NO')
    exit()

if 0 <= (abs(B - A) / (V - W)) <= T:
    print('YES')
else:
    print('NO')
Buggy python submission (verdict: Runtime Error):
import numpy as np
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import shortest_path

N, M = map(int, input().split())
edge = np.array([input().split() + ['1'] for _ in range(M)], dtype=np.int64).T
graph = csr_matrix((edge[2], (edge[:2] - 1)), (N, N))

path = list(shortest_path(graph, method='D', directed=False)[0][1:])
judge = 'Yes' if all([p > 0 for p in path]) else 'No'

if judge == 'Yes':
    print(judge)
    for p in path:
        print(int(p))
else:
    print(judge)


Fixed submission:
from collections import deque

N, M = map(int, input().split())
arr = [[] for n in range(N)]
que = deque([1])

for m in range(M):
    a, b = map(int, input().split())
    arr[a - 1].append(b)
    arr[b - 1].append(a)

dist = [-1] * N
dist[0] = 0
arr2 = [0] * (N - 1)

print("Yes")
while que:
    c = que.popleft()
    for i in arr[c - 1]:
        if dist[i - 1] != -1:
            continue

        dist[i - 1] = 0
        arr2[i - 2] = c
        que.append(i)

for i in arr2:
    print(i)
Buggy python submission (verdict: Time Limit Exceeded):
K = int(input())


def gcd(a, b):
  while b != 0:
    a, b = b, a % b
  return a


result = 0
for i in range(1, K + 1):
    for j in range(1, K + 1):
        for k in range(1, K + 1):
            if i == j == k:
                result += i
            elif i == j:
                result += gcd(i, k)
            elif j == k:
                result += gcd(i, k)
            else:
                result += gcd(gcd(i, j), k)

print(result)


Fixed submission:
K = int(input())


def gcd(a, b):
    while b != 0:
        a, b = b, a % b
    return a


result = 0
for i in range(1, K + 1):
    for j in range(1, i + 1):
        for k in range(1, j + 1):
            if i == j == k:
                result += i
            elif i == j:
                result += gcd(i, k) * 3
            elif j == k:
                result += gcd(i, k) * 3
            else:
                result += gcd(gcd(i, j), k) * 6

print(result)