Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
lr = []
l1 = []
l2 = []

for i in range(m):
    l,r = map(int,input().split())
    lr.append([l,r])
for i in range(0, lr[0][1] - lr[0][0]+1):
    l1.append(lr[0][0] + i)

for i in range(1, m):
    for j in range(0, lr[i][1] - lr[i][0]+1):
        l2.append(lr[i][0]+j)
    l1 = list(set(l1) & set(l2))
    l2 = []
    
print(len(l1))


Fixed submission:
n, m = map(int, input().split())
L = []
R = []

for i in range(m):
    l,r = map(int, input().split())
    L.append(l)
    R.append(r)
if min(R) - max(L) + 1 >= 0:
    print(min(R) - max(L) + 1)
else:
    print(0)
Buggy python submission (verdict: Runtime Error):
import sys

a, b, k = map(int, input().split())
l = []

for i in range(1, max(a,b)):
    if a%i == 0 and b%i == 0:
        l.append(i)
if l == []:
    print(1)
    sys.exit()
l.sort(reverse=True)
print(l[k-1])

Fixed submission:
import sys

a, b, k = map(int, input().split())
l = []

for i in range(1, max(a,b)+1):
    if a%i == 0 and b%i == 0:
        l.append(i)
if l == []:
    print(1)
    sys.exit()
l.sort(reverse=True)
print(l[k-1])

Buggy python submission (verdict: Runtime Error):
import sys

a, b, k = map(int, input().split())
l = []

for i in range(1, max(a,b)):
    if a%i == 0 and b%i == 0:
        l.append(i)
if l == []:
  print(1)
  sys.exit()
l.sort(reverse=True)
print(l[k-1])

Fixed submission:
import sys

a, b, k = map(int, input().split())
l = []

for i in range(1, max(a,b)+1):
    if a%i == 0 and b%i == 0:
        l.append(i)
if l == []:
    print(1)
    sys.exit()
l.sort(reverse=True)
print(l[k-1])
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

count0=0
count1=0
lastElm=-1
S=[]
s=input()
for c in s:
        S.append(c)
S.pop(-1)
lenS = len(S)
if lenS==1:
        print(0)
        exit()
S.sort()
for i in range(lenS):
        if i==0:
                count0=S.count("0")
                count1=S.count("1")
                if count0 == 0 or count1==1:
                        print(0)
                        exit()
        else:
                if lastElm == "0":
                        count0 -= 1
                elif lastElm == "1":
                        count1 -= 1

        if count0 == count1:
                print(count0*2)
                exit()
        else:
                if S[lenS//2] == "1":
                        lastElm = S[-1]
                        S.pop(-1)
                else:
                        lastElm = S[0]
                        S.pop(0)

Fixed submission:
import sys
input = sys.stdin.readline

S=[]
s=input()
for c in s:
        S.append(c)
S.pop(-1)
print(2*min(S.count("0"), S.count("1")))

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

count0=0
count1=0
lastElm=-1
S=[]
s=input()
for c in s:
        S.append(c)
S.pop(-1)
lenS = len(S)
if lenS==1:
        print(0)
        exit
S.sort()
for i in range(lenS):
        if i==0:
                count0=S.count("0")
                count1=S.count("1")
        else:
                if lastElm == "0":
                        count0 -= 1
                elif lastElm == "1":
                        count1 -= 1

        if count0 == count1:
                print(count0*2)
                exit()
        else:
                if S[lenS//2] == "1":
                        lastElm = S[-1]
                        S.pop(-1)
                else:
                        lastElm = S[0]
                        S.pop(0)

Fixed submission:
import sys
input = sys.stdin.readline

S=[]
s=input()
for c in s:
        S.append(c)
S.pop(-1)
print(2*min(S.count("0"), S.count("1")))
Buggy python submission (verdict: Runtime Error):
a

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

if m <= n:
    print(0)
else:
    x.sort()
    diff = []#i番目とi+1番目の距離
    for i in range(m-1):
        diff.append(x[i+1] - x[i])
    diff.sort(reverse=True)
    # print(diff)
    if n > 1:
        for i in range(n-1):
            diff.pop(0)
    # print(diff)
    print(sum(diff))
Buggy python submission (verdict: Time Limit Exceeded):
def f(s):
    cnt = 0
    n = len(s)
    for i in range(n-1):
        if s[i] == "B" and s[i+1] == "W":
            s[i] = "W"
            s[i+1] = "B"
            cnt += 1
    return cnt

s = list(input())
ans = 0
while True:
    tmp = f(s)
    ans += tmp
    if tmp == 0:
        break
print(ans)

Fixed submission:
def f(s):
    ret = 0
    n = len(s)
    for i in range(n):
        if s[i] == "W":
            ret += i
    return ret

s = list(input())
nW = s.count("W")
ans = 0
ans += f(s)
for i in range(1, nW):
    ans -= i
print(ans)

"""
BWBWBW
WBWBWB
WWBWBB
WWWBBB

先頭までの距離（i）- 何番目のWか+1
ni - 1~nW +1
"""
Buggy python submission (verdict: Runtime Error):
A=5*10**15
s=input()
k=int(input())
l=0

for i in range(len(s)):
        l+=int(s[i])**A
        if k<l:
                print(int(s[i]))
                exit()

Fixed submission:
s=input()
k=int(input())
for i in range(len(s)):
        if s[i] == "1" and (k-1)==i:
                print(1)
                exit()
        elif s[i] == "1" and (k-1) != i:
                continue
        else:
                print(s[i])
                exit()
Buggy python submission (verdict: Runtime Error):
n = int(input())
x = list(map(int, input().split()))

for i in range(n):
    x[i] -= i+1

x.sort()
x_ = []
b = 0
if x.count(0) <= n//2:
    for i in range(n):
        if x[i] != 0:
             x_.append(x[i])

    n_ = len(x_)
    if n_%2 == 0:
        b = x_[n_//2]
    else:
        b = x_[n_//2 + 1]

ans = 0
for i in range(n):
    ans += abs(x[i] - b)

print(ans)

Fixed submission:
import statistics
n = int(input())
x = list(map(int, input().split()))

for i in range(n):
    x[i] -= i+1

x.sort()
x_ = []
b = 0
if x.count(0) <= n//2:
    for i in range(n):
        if x[i] != 0:
             x_.append(x[i])

    b = statistics.median(x_)

ans = 0
for i in range(n):
    ans += abs(x[i] - b)

print(int(ans))
Buggy python submission (verdict: Runtime Error):
d,n=map(int, input().split())
if d == 0 and n == 100:
    print(101)
elif d == 1 and n == 100
    print(10001)
elif d == 2 and n == 100
    print(1000001)
else:
    print(100**d * n)

Fixed submission:
d,n=map(int, input().split())
if d == 0 and n == 100:
    print(101)
elif d == 1 and n == 100:
    print(10100)
elif d == 2 and n == 100:
    print(1010000)
else:
    print(100**d * n)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
ans = 0
"""
一番大きい偶数を2で割る
それ以外は3倍
を繰り返す
奇数だけになったら終了
"""
# O(n)
def f(L):
    even = []
    for l in L:
        if l%2 == 0:
            even.append(l)

    if even == []:
        return -1
    else:
        return max(even)

maxEven = f(a)
while True:
    if maxEven == -1:
        print(ans)
        exit()
    else:
        for i in range(n):
            if a[i] == maxEven:
                a[i] = a[i] // 2
            else:
                a[i] *= 3
            if a[i]%2 == 0:
                maxEven = max(maxEven, a[i])
        ans += 1

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
ans = 0
"""
一番大きい偶数を2で割る
それ以外は3倍
を繰り返す
奇数だけになったら終了
↓
各項が2で何回われるか の合計
"""
for i in range(n):
    cnt = 0
    tmp = a[i]
    while True:
        if tmp % 2 == 0:
            tmp = tmp // 2
            cnt += 1
        else:
            break
    ans += cnt
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
a, b, c, k = map(int, input().split())

for _ in range(k):
        tmpA = a
        tmpB = b
        tmpC = c
        a = tmpB + tmpC
        b = tmpA + tmpC
        c = tmpB + tmpA

ans = a - b
if ans != 10**18:
    print(ans)
else:
    print("Unfair")

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

# for _ in range(k):
#         tmpA = a
#         tmpB = b
#         tmpC = c
#         a = tmpB + tmpC
#         b = tmpA + tmpC
#         c = tmpB + tmpA
#         if a - b >= 10**18:
#             print("Unfair")
#             exit()
# 
# print(a - b)
if a-b >= 10**18 or b-a >= 10**18:
    print("Unfair")
    exit()

if k%2 == 0:
    print(a-b)
else:
    print(b-a)
Buggy python submission (verdict: Time Limit Exceeded):
x = int(input())
ans = 1

for i in range(1, x):
    for j in range(2, x):
        if i**j <= x:
            ans = max(ans, i**j)
print(ans)

Fixed submission:
x = int(input())
ans = 1

for i in range(1, 100):
    for j in range(2, 100):
        tmp = i**j
        if tmp <= x:
            ans = max(ans, tmp)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
def comb(n,k):
    nCk = 1
    MOD = 10**9+7
    # X
    for i in range(n-k+1, n+1):
        nCk *= i
        nCk %= MOD

    # Y
    for i in range(1,k+1):
        nCk *= pow(i,MOD-2,MOD)
        nCk %= MOD
    return nCk

n = int(input())
a = list(map(int, input().split()))
ai = max(a)
aj = -1
nck = 0

for i in range(n):
    tmp = comb(ai, a[i])
    if nck <= tmp:
        nck = tmp
        aj = a[i]

print(str(ai) + " " + str(aj))

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
a.sort()
ai = a[-1]
aj = a[0]
center = ai // 2
diff = 10**10
# print("-----------")
# print(center)

for i in range(n-1):
    if abs(center - a[i]) <= diff and aj < a[i]:
        diff = abs(center - a[i])
        aj = a[i]
        # print(diff)
        # print(aj)
        # print("----")


print(str(ai) + " " + str(aj))

Buggy python submission (verdict: Time Limit Exceeded):
def comb(n,k):
    nCk = 1
    MOD = 10**9+7
    # X
    for i in range(n-k+1, n+1):
        nCk *= i
        nCk %= MOD

    # Y
    for i in range(1,k+1):
        nCk *= pow(i,MOD-2,MOD)
        nCk %= MOD
    return nCk

n = int(input())
a = list(map(int, input().split()))
ai = max(a)
aj = -1
nck = 0

for i in range(n):
    tmp = comb(ai, a[i])
    if nck <= tmp:
        nck = tmp
        aj = a[i]

print(str(ai) + " " + str(aj))

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
a.sort()
ai = a[-1]
aj = a[0]
center = ai // 2
diff = 10**10
# print("-----------")
# print(center)

for i in range(n-1):
    if abs(center - a[i]) <= diff and aj < a[i]:
        diff = abs(center - a[i])
        aj = a[i]
        # print(diff)
        # print(aj)
        # print("----")


print(str(ai) + " " + str(aj))
Buggy python submission (verdict: Runtime Error):
import re
a, b = map(int, input().split())
s = input()
p1 = "\d{"+ str(a) +"}"
p2 = "\d{"+ str(b) +"}"
if s[a] == "-" and re.fullmatch(p1, s[0:a]) != None and re.fullmatch(p2, s[a+1:]) != None:
        print("Yes")
else:
        print("No")



Fixed submission:
import re
a, b = map(int, input().split())
s = input()
p1 = r"\d{"+ str(a) +"}"
p2 = r"\d{"+ str(b) +"}"
if s[a] == "-" and re.fullmatch(p1, s[0:a]) != None and re.fullmatch(p2, s[a+1:]) != None:
        print("Yes")
else:
        print("No")
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = []
for i in range(n):
    a.append(int(input()))

count = [0] * (max(a)+1)

for _a in a:
    if count[_a] == 0:
        count[_a] = 1
    elif count[_a] == 1:
        count[_a] = 0

print(sum(count))


Fixed submission:
from collections import Counter

n = int(input())
a = []
for i in range(n):
    a.append(int(input()))

# count = [0] * (max(a)+1)

c = Counter(a)
ans = 0

for _a in list(set(a)):
    if c[_a]%2 != 0:
        ans += 1

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = []
for i in range(n):
    a.append(int(input()) - 1)

hst = []
btn = 0
cnt = 0

while not btn in hst and cnt <= 10**5:
    hst.append(btn)
    btn = a[btn]
    cnt += 1
    if btn == 1:
        print(cnt)
        exit()

print(-1)

Fixed submission:
n = int(input())
a = []
for i in range(n):
    a.append(int(input()) - 1)

# if not 1 in a:
#     print(-1)

# hst = []
btn = 0
cnt = 0

while cnt <= 10**7:
    # hst.append(btn)
    btn = a[btn]
    cnt += 1
    if btn == 1:
        print(cnt)
        exit()

print(-1)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = []
for i in range(n):
    a.append(int(input()) - 1)

hst = []
btn = 0
cnt = 0

while not btn in hst and cnt <= 10**5:
    hst.append(btn)
    btn = a[btn]
    cnt += 1
    if btn == 1:
        print(cnt)
        exit()

print(-1)

Fixed submission:
n = int(input())
a = []
for i in range(n):
    a.append(int(input()) - 1)

# if not 1 in a:
#     print(-1)

# hst = []
btn = 0
cnt = 0

while cnt <= 10**7:
    # hst.append(btn)
    btn = a[btn]
    cnt += 1
    if btn == 1:
        print(cnt)
        exit()

print(-1)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = []
for i in range(n):
    a.append(int(input()) - 1)

hst = []
btn = 0
cnt = 0

while not btn in hst and cnt <= 10**7:
    hst.append(btn)
    btn = a[btn]
    cnt += 1
    if btn == 1:
        print(cnt)
        exit()

print(-1)

Fixed submission:
n = int(input())
a = []
for i in range(n):
    a.append(int(input()) - 1)

# if not 1 in a:
#     print(-1)

# hst = []
btn = 0
cnt = 0

while cnt <= 10**7:
    # hst.append(btn)
    btn = a[btn]
    cnt += 1
    if btn == 1:
        print(cnt)
        exit()

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

if m <= 2*n:
    print(m//2)
elif 2*n < m:
    while 2*n <= m:
        m -= 2
        n += 1
    # print("m: "+ str(m))
    print(n-1)

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

if m <= 2*n:
    print(m//2)
elif 2*n < m:
    print(n + math.ceil((m- 2*n)//4))

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

if m <= 2*n:
    print(m//2)
elif 2*n < m:
    while 2*n <= m:
        m -= 2
        n += 1
    # print("m: "+ str(m))
    print(n-1)

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

if m <= 2*n:
    print(m//2)
elif 2*n < m:
    print(n + math.ceil((m- 2*n)//4))
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))

ave = round(sum(a)/n)
ans = 0

for _a in a:
    ans += (_a - ave)**2

print(ans1)

Fixed submission:
"""
1 2 3 4 5
1 1 1 1 9   4 4 4 4 36=53 | 1 1 1 1 49
"""
import math
n = int(input())
a = list(map(int, input().split()))

ave1 = math.ceil(sum(a)/n)
ave2 = math.floor(sum(a)/n)
ans1 = 0
ans2 = 0

for _a in a:
    ans1 += (_a - ave1)**2

for _a in a:
    ans2 += (_a - ave2)**2

print(min(ans1, ans2))
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
d = list(map(int, input().split()))

use = [i for i in range(10)]

for _d in d:
    use.remove(_d)

ok = True

while True:
    s = list(str(n))
    for _d in d:
        if str(_d) in s:
            ok = False
            break
    
    if ok:
        print(n)
        exit()
    else:
        n += 1



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

use = [i for i in range(10)]

for _d in d:
    use.remove(_d)


while True:
    ok = True
    s = str(n)
    for i in range(len(s)):
        if int(s[i]) not in use:
            ok = False
            break

    if ok:
        print(n)
        exit()
    else:
        n += 1
Buggy python submission (verdict: Runtime Error):
x=input()
print(x+'s' if x[len(x)-1]!=s else x[0:len(x)-1]+"es")

Fixed submission:
x=input()
print(x+'s' if x[len(x)-1]!='s' else x+"es")
Buggy python submission (verdict: Time Limit Exceeded):
l=int(input())
k=list(map(int,input().split()))
s=0
mod=10**9+7
for i in range(l-1):
    for j in range(i+1,l):
        
        s=(s+(k[i]*k[j]))%mod
        
        
print(s)     

Fixed submission:
l=int(input())
k=list(map(int,input().split()))
s=0
mod=10**9+7
o=sum(k)
p=o**2

s=0
for i in k:
    s=(s+i**2)
    
print((p-s)//2%mod)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
li_a = list(map(int, input().split()))
answer = 0
mo = (10 ** 9) + 7
for idx, a in enumerate(li_a):
    answer += (a * sum(li_a[idx + 1:]))
print(answer % mo)

Fixed submission:
n = int(input())
li_a = list(map(int, input().split()))
answer = 0
su = sum(li_a)
mo = (10 ** 9) + 7
for idx, a in enumerate(li_a):
    su = su - a
    answer += (a * su)
print(answer % mo)
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())

li_a = list(map(int, input().split()))

wk = 1
li_answer = list()
for idx, v in enumerate(li_a):
    prev = wk
    if idx <= (k - 1):
        wk = wk * v
    else:
        wk = wk * v // li_a[idx - k]
        if prev >= wk:
            print('No')
        else:
            print('Yes')




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

li_a = list(map(int, input().split()))

for idx, v in enumerate(li_a):
    if idx <= (k - 1):
        pass
    else:
        if v > li_a[idx - k]:
            print('Yes')
        else:
            print('No')
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
li_a = list(map(int, input().split()))
dic_a = {}

for a in li_a:
    dic_a[a] = dic_a.get(a, 0) + 1

q = int(input())
li_bc = list()

for i in range(q):
    li_bc.append(tuple(map(int, input().split())))

for l in li_bc:
    b = l[0]
    c = l[1]
    if b in dic_a.keys():
        dic_a[c] = dic_a.get(c, 0) + dic_a.get(b, 0)
        dic_a[b] = 0
    sum = 0
    for key, val in dic_a.items():
        sum += (key * val)
    print(sum)




Fixed submission:
n = int(input())
li_a = list(map(int, input().split()))
dic_a = {}

for a in li_a:
    dic_a[a] = dic_a.get(a, 0) + 1

q = int(input())
li_bc = list()

for i in range(q):
    li_bc.append(tuple(map(int, input().split())))


answer = sum(li_a)
for l in li_bc:
    b = l[0]
    c = l[1]

    diff = (c - b) * dic_a.get(b, 0)
    if b in dic_a.keys():
        dic_a[c] = dic_a.get(c, 0) + dic_a.get(b, 0)
        dic_a[b] = 0
        answer += diff
    else:
        pass
    print(answer)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
li_a = list(map(int, input().split()))
q = int(input())
li_bc = list()

for i in range(q):
    li_bc.append(tuple(map(int, input().split())))

for l in li_bc:
    li_a = [a if a != l[0] else l[1] for a in li_a]
    print(sum(li_a))

Fixed submission:
n = int(input())
li_a = list(map(int, input().split()))
dic_a = {}

for a in li_a:
    dic_a[a] = dic_a.get(a, 0) + 1

q = int(input())
li_bc = list()

for i in range(q):
    li_bc.append(tuple(map(int, input().split())))


answer = sum(li_a)
for l in li_bc:
    b = l[0]
    c = l[1]

    diff = (c - b) * dic_a.get(b, 0)
    if b in dic_a.keys():
        dic_a[c] = dic_a.get(c, 0) + dic_a.get(b, 0)
        dic_a[b] = 0
        answer += diff
    else:
        pass
    print(answer)
Buggy python submission (verdict: Time Limit Exceeded):
import functools
n = int(input())
li_a = list(map(int, input().split()))

if 0 in li_a:
    print(0)
    exit(0)
w = functools.reduce(lambda x, y: x * y, li_a)
if w > 10 ** 18:
    print(-1)
    exit(0)
else:
    print(w)
    exit(0)


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

if 0 in li_a:
    print(0)
    exit(0)
w = li_a[0]
for a in li_a[1:]:
    w = w * a
    if w > 10 ** 18:
        print(-1)
        exit(0)
else:
    print(w)
    exit(0)
Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
li_h = list(map(int, input().split()))
li_route = list()
remove_idx_set = set()

for _ in range(m):
    a, b = map(int, input().split())

    h_a = li_h[a - 1]
    h_b = li_h[b - 1]

    if h_a <= h_b:
        if h_a in li_h:
            remove_idx_set.add(a - 1)
    if h_a >= h_b:
        if h_b in li_h:
            remove_idx_set.add(b - 1)
for s in remove_idx_set:
    li_h[s] = 0
print(len([v for v in li_h if v != 0]))


Fixed submission:
n, m = map(int, input().split())
li_h = list(map(int, input().split()))
li_route = list()
remove_idx_set = set()

for _ in range(m):
    a, b = map(int, input().split())

    h_a = li_h[a - 1]
    h_b = li_h[b - 1]

    if h_a <= h_b:
        remove_idx_set.add(a - 1)
    if h_a >= h_b:
        remove_idx_set.add(b - 1)
for s in remove_idx_set:
    li_h[s] = 0
print(len([v for v in li_h if v != 0]))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
li_a = list(map(int, input().split()))

set_a = set(li_a)

for i in range(1, n + 1):
    if i in set_a:
        print(li_a.count(i))
    else:
        print(0)


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

dic = {}
for a in li_a:
    dic[a] = dic.get(a, 0) + 1

for i in range(1, n + 1):
    print(dic.get(i, 0))
Buggy python submission (verdict: Time Limit Exceeded):
import math


def gcd(a, b, c):

    return math.gcd(math.gcd(a, b), c)


k = int(input())
answer = 0
for w_a in range(1, k + 1):
    for w_b in range(1, k + 1):
        for w_c in range(1, k + 1):
            answer += gcd(w_a, w_b, w_c)

print(answer)


Fixed submission:
import math


k = int(input())
answer = 0
for w_a in range(1, k + 1):
    for w_b in range(1, k + 1):
        w = math.gcd(w_a, w_b)
        for w_c in range(1, k + 1):
            answer += math.gcd(w, w_c)

print(answer)

Buggy python submission (verdict: Time Limit Exceeded):
import math

memo = {}


def gcd(a, b, c):

    key = ''.join(map(str, sorted([a, b, c])))
    if key in memo:
        return memo[key]
    else:
        w = math.gcd(a, b)
        ans = math.gcd(w, c)
        memo[key] = ans
        return ans


k = int(input())
answer = 0
for w_a in range(1, k + 1):
    for w_b in range(1, k + 1):
        for w_c in range(1, k + 1):
            answer += gcd(w_a, w_b, w_c)

print(answer)


Fixed submission:
import math


k = int(input())
answer = 0
for w_a in range(1, k + 1):
    for w_b in range(1, k + 1):
        w = math.gcd(w_a, w_b)
        for w_c in range(1, k + 1):
            answer += math.gcd(w, w_c)

print(answer)

Buggy python submission (verdict: Time Limit Exceeded):
import math


def gcd(a, b, c):
    w = math.gcd(a, b)
    return math.gcd(w, c)


k = int(input())
answer = 0
for w_a in range(1, k + 1):
    for w_b in range(1, k + 1):
        for w_c in range(1, k + 1):
            answer += gcd(w_a, w_b, w_c)

print(answer)


Fixed submission:
import math


k = int(input())
answer = 0
for w_a in range(1, k + 1):
    for w_b in range(1, k + 1):
        w = math.gcd(w_a, w_b)
        for w_c in range(1, k + 1):
            answer += math.gcd(w, w_c)

print(answer)
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
li_p = list(map(int, input().split()))

li_kitai = list()
for l in li_p:
    li_kitai.append(sum(range(1, l + 1)) / l)

answer = 0
memo = 0
for idx, v in enumerate(li_kitai[:len(li_kitai) - k + 1]):
    if idx == 0:
        memo = sum(li_kitai[idx:idx + k])
    else:
        memo = memo - li_kitai[idx - 1] + li_kitai[idx + (k - 1)]
    answer = max(answer, memo)

print(answer)




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

li_kitai = list()
d_kitai_memo = dict()
for l in li_p:
    if l not in d_kitai_memo:
        val = sum(range(1, l + 1)) / l
        d_kitai_memo[l] = val
        li_kitai.append(val)
    else:
        li_kitai.append(d_kitai_memo[l])

answer = 0
memo = 0
for idx, v in enumerate(li_kitai[:len(li_kitai) - k + 1]):
    if idx == 0:
        memo = sum(li_kitai[idx:idx + k])
    else:
        memo = memo - li_kitai[idx - 1] + li_kitai[idx + (k - 1)]
    answer = max(answer, memo)

print(answer)

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
li_p = list(map(int, input().split()))

li_kitai = list()
for l in li_p:
    li_kitai.append(sum(range(1, l + 1)) / l)

answer = 0

for idx, v in enumerate(li_kitai[:len(li_kitai) - k + 1]):
    answer = max(answer, sum(li_kitai[idx:idx + k]))
print(answer)




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

li_kitai = list()
d_kitai_memo = dict()
for l in li_p:
    if l not in d_kitai_memo:
        val = sum(range(1, l + 1)) / l
        d_kitai_memo[l] = val
        li_kitai.append(val)
    else:
        li_kitai.append(d_kitai_memo[l])

answer = 0
memo = 0
for idx, v in enumerate(li_kitai[:len(li_kitai) - k + 1]):
    if idx == 0:
        memo = sum(li_kitai[idx:idx + k])
    else:
        memo = memo - li_kitai[idx - 1] + li_kitai[idx + (k - 1)]
    answer = max(answer, memo)

print(answer)