Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a = [int(i) for i in input().split()]
set_a = set(a)
ans = 0

for ai in set_a:
  ai_count = a.count(ai)
  if ai_count >= ai:
  	ans += ai_count - ai  
  else:
    ans += ai_count

print(ans)

Fixed submission:
from collections import Counter

N = int(input())
a = [int(i) for i in input().split()]

cnt = Counter(a)
ans = 0

for ai, num in cnt.items():
  if num >= ai:
  	ans += num - ai  
  else:
    ans += num

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a = [int(i) for i in input().split()]
set_a = set(a)
ans = 0

for ai in set_a:
  ai_count = a.count(ai)
  ans += ai_count - ai if ai_count >= ai else ai_count

print(ans)

Fixed submission:
from collections import Counter

N = int(input())
a = [int(i) for i in input().split()]

cnt = Counter(a)
ans = 0

for ai, num in cnt.items():
  if num >= ai:
  	ans += num - ai  
  else:
    ans += num

print(ans)

Buggy python submission (verdict: Runtime Error):
N = int(input())
a = [int(i) for i in input().split()]
set_a = set(a)
ans = 0

for ai in set_a:
  	ai_count = a.count(ai)
    ans += ai_count - ai if ai_count >= ai else ai_count

print(ans)

Fixed submission:
from collections import Counter

N = int(input())
a = [int(i) for i in input().split()]

cnt = Counter(a)
ans = 0

for ai, num in cnt.items():
  if num >= ai:
  	ans += num - ai  
  else:
    ans += num

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a = [int(i) for i in input().split()]
set_a = set(a)
ans = 0

for ai in set_a:
    ans += a.count(ai) - ai if a.count(ai) >= ai else a.count(ai)

print(ans)

Fixed submission:
from collections import Counter

N = int(input())
a = [int(i) for i in input().split()]

cnt = Counter(a)
ans = 0

for ai, num in cnt.items():
  if num >= ai:
  	ans += num - ai  
  else:
    ans += num

print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
n = N%10
if n == 2 or 4 or 5 or 7 or 9:
  print("hon")
elif n == 0 or 1 or 6 or 8:
  print("pon")
else n == 3:
  print("bon")


Fixed submission:
N = int(input())
n = N%10
if n == 2 or n == 4 or n ==5 or n ==7 or n == 9:
  print("hon")
elif n == 0 or n == 1 or n == 6 or n == 8:
  print("pon")
else :
  print("bon")

Buggy python submission (verdict: Runtime Error):
N = int(input())
n = N%10
if n == 2 or 4 0r 5 0r 7 or 9:
  print("hon")
if n == 0 or 1 or 6 or 8:
  print("pon")
if n == 3:
  print("bon")

Fixed submission:
N = int(input())
n = N%10
if n == 2 or n == 4 or n ==5 or n ==7 or n == 9:
  print("hon")
elif n == 0 or n == 1 or n == 6 or n == 8:
  print("pon")
else :
  print("bon")
Buggy python submission (verdict: Runtime Error):
S = input()
x == ARC
if S == ARC:
  x == ABC
print(x)

Fixed submission:
S = input()
x = "ARC"
if S == "ARC":
  x = "ABC"
print(x)
Buggy python submission (verdict: Runtime Error):
from collections import deque
N,M = map(int,input().split())
data = [[] for i in range(M)]
for i in range(M):
    a,b = map(int,input().split())
    data[a-1].append(b)
    data[b-1].append(a)

que = deque([1])
ans = [0 for i in range(M)]
while True:
    cur = que.popleft()
    for item in data[cur-1]:
        if ans[item-1] == 0:
            que.append(item)
            ans[item-1] = cur
    if len(que) == 0: break

print("yes")
for i in range(1,N): print(ans[i])

Fixed submission:
from collections import deque
N,M = map(int,input().split())
data = [[] for i in range(N)]
for i in range(M):
    a,b = map(int,input().split())
    data[a-1].append(b)
    data[b-1].append(a)

que = deque([1])
ans = [0 for i in range(N)]
while True:
    cur = que.popleft()
    for item in data[cur-1]:
        if ans[item-1] == 0:
            que.append(item)
            ans[item-1] = cur
    if len(que) == 0: break

if 0 in ans:
    print("No")
else:
    print("Yes")
    for i in range(1,N): print(ans[i])
Buggy python submission (verdict: Time Limit Exceeded):
N,M,Q = map(int,input().split())
data = [0]*Q
for i in range(Q): data[i] = list(map(int,input().split()))

a = []
def gen_a(n,ai,cur):
    if n==0:
        for k in range(1,M+1):
            if k==10:
                k = "a"
                gen_a(1,10,str(k))
            else:
                gen_a(1,k,str(k))
    elif n==N:
        ar = list(cur)
        if ar[-1] == "a": ar[-1] = "10"
        a.append(ar)
    else:
        for k in range(ai,M+1):
            if k == 10:
                k = "a"
                gen_a(n+1,10,cur+str(k))
            else: 
                gen_a(n+1,k,cur+str(k))

gen_a(0,1,0)

ans = 0
for a_item in a:
    cnt = 0
    for d_item in data:
        nb = int(a_item[d_item[1]-1]) if a_item[d_item[1]-1] != "a" else 10
        na = int(a_item[d_item[0]-1]) if a_item[d_item[0]-1] != "a" else 10
        if nb - na == d_item[2]:
            cnt += d_item[3]
    if ans < cnt:
        ans = cnt

print(ans)

Fixed submission:
N,M,Q = map(int,input().split())
data = [0]*Q
for i in range(Q): data[i] = list(map(int,input().split()))

a = []
def gen_a(n,ai,cur):
    if n==0:
        for k in range(1,M+1):
            if k==10:
                k = "a"
                gen_a(1,10,str(k))
            else:
                gen_a(1,k,str(k))
    elif n==N:
        ar = list(cur)
        if ar[-1] == "a": ar[-1] = "10"
        a.append(ar)
    else:
        for k in range(ai,M+1):
            if k == 10:
                k = "a"
                gen_a(n+1,10,cur+str(k))
            else: 
                gen_a(n+1,k,cur+str(k))

gen_a(0,1,0)

ans = 0
for a_item in a:
    cnt = 0
    for d_item in data:
        nb = int(a_item[d_item[1]-1]) if a_item[d_item[1]-1] != "a" else 10
        na = int(a_item[d_item[0]-1]) if a_item[d_item[0]-1] != "a" else 10
        if nb - na == d_item[2]:
            cnt += d_item[3]
    if ans < cnt:
        ans = cnt

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
A,B,N = map(int,input().split())
ans = 0

for i in range(max(0,N//B*B-1),N+1):
    cur = A*i/B//1 - A*(i/B//1)
    ans = max(ans, cur)
print(int(ans))

Fixed submission:
A,B,N = map(int,input().split())
x = max(0,N//B*B-1)
cur1 = A*x/B//1 - A*(x/B//1)
cur2 = A*N/B//1 - A*(N/B//1)
print(int(max(cur1,cur2)))
Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split())
# n1 = int((N/K + 0.5)//1)
# n2 = int((N/K - 0.5)//1)
# if (N/K - 0.5)%1 != 0: n2 += 1

# print(min(abs(n1*K-N),abs(n2*K-N)))
i = N
while i >= K//2:
    i = abs(i-K)
print(i)

Fixed submission:
N,K = map(int,input().split())
n = int((N/K + 0.5)//1)
i = abs(n*K-N)
while i >= K/2:
    i = abs(K-i)

print(i)
Buggy python submission (verdict: Runtime Error):
H,W = map(int,input().split())
s = [[] for i in range(H)]
for i in range(H): s[i] = list(input())
l = [[0]*W for i in range(H)]
r = [[0]*W for i in range(H)]
d = [[0]*W for i in range(H)]
u = [[0]*W for i in range(H)]

for h in range(H):
    for w in range(W):
        if s[h][w] == ".":
            l[h][w], d[h][w] = 1,1
            if w != 0: l[h][w] = l[h][w-1] + 1
            if h != 0: d[h][w] = d[h-1][w] + 1
    for w in range(W):
        if s[H-1-h][W-1-w] == ".":
            r[H-1-h][W-1-w] = 1
            if w != 0: r[H-1-h][W-1-w] = r[H-1-h][W-w] + 1

for h in range(H):
    for w in range(W):
        if s[H-1-h][W-1-w] == ".":
            u[H-1-h][W-1-w] = 1
            if h != 0: u[H-1-h][W-1-w] = u[H-h][W-1-w] + 1
ans = 0
for h in range(H):
    for w in range(W):
        ans = max(ans, l[h][w]+r[h][w]+u[h][w]+d[h][w]-3)

print(ans)
        

Fixed submission:
P,Q,R = map(int, input().split())
print(min(P+Q,Q+R,R+P))

Buggy python submission (verdict: Runtime Error):
N,M = map(int, input().split())
a = [0]*M
for i in range(M): a[i] = int(input())

mod = [1]*N
inv = [1]*N
inf = 10**9+7
for i in range(N-1): mod[i+1] = mod[i]*(i+2)%inf
inv[N-1] = pow(mod[N-1], inf-2, inf)
for i in range(2,N+1): inv[N-i] = inv[N-i+1]*(N-i+2)%inf

def comb(cur,ai):
    if ai - cur == 1:
        return 1
    elif ai <= cur:
        return 0
    return(comb(cur, ai-1)+comb(cur,ai-2))

cur = 1
if a[0] == 1: cur += 1
cnt = 0
for i in range(M):
    if cur == a[i]:
        cnt = 0
        break
    cnt += comb(cur,a[i])
    cur = a[i]+1

print(cnt)

Fixed submission:
P,Q,R = map(int, input().split())
print(min(P+Q,Q+R,R+P))
Buggy python submission (verdict: Runtime Error):
N,M = map(int, input().split())
a = [0]*(M+1)
for i in range(M): a[i] = int(input())
a[M] = N+1

inf = 10**9+7

def comb(cur,ai):
    if ai - cur == 1:
        return 1
    elif ai - cur == 2:
        return 2
    elif ai <= cur:
        return 0
    return((comb(cur, ai-1)+comb(cur,ai-2))%inf)

cur = 0
if a[0] == 1: cur += 2
cnt = 1
for i in range(M+1):
    if a[0] == 1 and i == 0: continue
    if cur == a[i]:
        cnt = 0
        break
    cnt *= comb(cur,a[i]-1)%inf
    cnt = cnt%inf
    cur = a[i]+1

print(cnt%inf)


Fixed submission:
N,M = map(int, input().split())
a = [-1]*(M+2)
a[M+1] = N+1
diff = 0
for i in range(1,M+2):
    if i != M+1: a[i] = int(input())
    diff = max(diff, a[i]-a[i-1])

inf = 10**9+7

dp = [0]*diff
dp[0] = 0
dp[1] = 1
for i in range(2,diff):
    dp[i] = dp[i-1] + dp[i-2]
    dp[i] = dp[i]%inf

cnt = 1
for i in range(1,M+2):
    da = a[i]-a[i-1]-1
    if da == 0:
        cnt = 0
        break
    else:
        cnt *= dp[da]
        cnt = cnt%inf

print(cnt%inf)
Buggy python submission (verdict: Runtime Error):
s = list(input())

i = 0
abc = list("ABC")

def roop(n): #n:現在地
  if n >= len(s)-2:
    return 0
  elif s[n:n+3] == abc:
    s[n] = "B"
    s[n+1] = "C"
    s[n+2] = "A"
    if n == 0: return roop(n+2)+1 
    return roop(n-1)+1
    # return roop(n-1)+1
  else:
    return roop(n+1)


print(roop(0))

Fixed submission:
s = list(input())

i = 0
bc = list("BC")

a_cnt = 0
res = 0
i = 0
while i <= len(s)-1:
  if s[i] == "A":
    a_cnt += 1
  elif s[i:i+2] == bc:
    res += a_cnt
    i += 1
  else:
    a_cnt = 0
  i += 1

print(res)

Buggy python submission (verdict: Time Limit Exceeded):
s = list(input())

i = 0
count = 0
if len(s) >=3:
  while i <= len(s)-2:
    if s[i:i+3] == list("ABC"):
      s[i] = "B"
      s[i+1] = "C"
      s[i+2] = "A"
      count += 1
      if i != 0:
        i -= 1
    else:
      i += 1

print(count)

Fixed submission:
s = list(input())

i = 0
bc = list("BC")

a_cnt = 0
res = 0
i = 0
while i <= len(s)-1:
  if s[i] == "A":
    a_cnt += 1
  elif s[i:i+2] == bc:
    res += a_cnt
    i += 1
  else:
    a_cnt = 0
  i += 1

print(res)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
sort = sorted(A)
amari = []
while len(amari) != 1:
  amari.clear()
  if 0 in sort: sort.remove(0)
  for item in sort:
    if item%sort[0] not in amari:
      amari.append(item%sort[0])
  last_sort0 = sort[0]
  sort = sorted(amari[:])
  sort.append(last_sort0)

print(last_sort0-amari[0])

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
sort = sorted(A)
# amari = []
# while len(amari) != 1:
#   amari.clear()
#   if 0 in sort: sort.remove(0)
#   for item in sort:
#     if item%sort[0] not in amari:
#       amari.append(item%sort[0])
#   last_sort0 = sort[0]
#   sort = sorted(amari[:])
#   sort.append(last_sort0)

# print(last_sort0-amari[0])

while len(sort) != 1:
  for i in range(1,len(sort)):
    sort[i] = sort[i]%sort[0]
  sort = [j for j in sorted(sort) if j != 0]

print(sort[0])
Buggy python submission (verdict: Runtime Error):
N = int(input())
data = [0]*N
for i in range(0,N): data[i] = int(input())

import math

ans = data[0]
for i in range(0,N):
    ans = ans*data[i] // math.gcd(ans,data[i])

print(ans)

Fixed submission:
N = int(input())
data = [0]*N
for i in range(0,N): data[i] = int(input())

import fractions

ans = data[0]
for i in range(0,N):
    ans = ans*data[i] // fractions.gcd(ans,data[i])

print(ans)

Buggy python submission (verdict: Runtime Error):
N = int(input())
data = [0]*N
for i in range(0,N): data[i] = int(input())

import math

ans = data[0]
for i in range(0,N):
    ans = ans*data[i]//math.gcd(ans,data[i])

print(ans)

Fixed submission:
N = int(input())
data = [0]*N
for i in range(0,N): data[i] = int(input())

import fractions

ans = data[0]
for i in range(0,N):
    ans = ans*data[i] // fractions.gcd(ans,data[i])

print(ans)
Buggy python submission (verdict: Runtime Error):
t,x=map(int,input())
print(t/x)


Fixed submission:
t,x=map(int,input().split())
print(t/x)
Buggy python submission (verdict: Runtime Error):
d=int(input())
print(" ".join(["Christmas", *["Eve"]*(25-d)]))


Fixed submission:
d=int(input())
print("Christmas"+" Eve"*(25-d))
Buggy python submission (verdict: Runtime Error):
if input()="1":
    print("Hello World")
else:
    print(int(input())+int(input()))

Fixed submission:
if input()=="1":
    print("Hello World")
else:
    print(int(input())+int(input()))
Buggy python submission (verdict: Runtime Error):
x,y=map(int,input().split())
print(">" if x>y else "<" if x<y else "=")

Fixed submission:
x,y=input().split()
print(">" if x>y else "<" if x<y else "=")
Buggy python submission (verdict: Runtime Error):
#! /usr/bin/env python3
# -*- coding:utf-8 -*-

def product_many(N):
    if 0 in N: return 0
    ans = 1
    for x in N:
        if (10 ^ 18 / ans) < x: return -1  
        ans *= x
        if ans > 10 ^ 18: return -1
    return ans

def main():
    _ = input()
    N = list(map(int, input().split()))
    print(product_many(N))

if __name__ == "__main__":
    main()


Fixed submission:
#! /usr/bin/env python3
# -*- coding:utf-8 -*-

def product_many(N):
    if 0 in N: return 0
    ans = 1
    for x in N:
        if (10 ** 18 / ans) < x: return -1
        ans *= x
        if ans > 10 ** 18: return -1
    return ans

def main():
    _ = input()
    N = list(map(int, input().split()))
    print(product_many(N))

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
#! /usr/bin/env python3
# -*- coding:utf-8 -*-

def name_count(N):
    x = N%10
    if x in [2, 4, 5, 7, 9]: return "hon"
    elif x in [0, 1,6, 8]: return "pon"
    else return "bon"

def main():
    N = int(input())
    print(name_count(N))

if __name__ == "__main__":
    main()


Fixed submission:
#! /usr/bin/env python3
# -*- coding:utf-8 -*-

def name_count(N):
    x = N%10
    if x in [2, 4, 5, 7, 9]: return "hon"
    elif x in [0, 1,6, 8]: return "pon"
    else: return "bon"

def main():
    N = int(input())
    print(name_count(N))

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
#! /usr/bin/env python3
# -*- coding:utf-8 -*-

def calc_sum_of_power(N, coord):
    spot = round(sum(coord)/N)
    return sum([(x - spot)**2 for x in coord])

def main():
    N = int(input())
    X = map(int, input().split())
    print( (n))

if __name__ == "__main__":
    try:
        assert calc_sum_of_power(2, [1, 4]) == 5
        assert calc_sum_of_power(7, [14, 14, 2, 13, 56, 2, 37]) == 2354
    except:
        import traceback
        traceback.print_exc()
        exit()
    main()


Fixed submission:
#! /usr/bin/env python3
# -*- coding:utf-8 -*-

def calc_sum_of_power(N, coord):
    spot = round(sum(coord)/N)
    return sum([(x - spot)**2 for x in coord])

def main():
    N = int(input())
    coord = list(map(int, input().split()))
    print(calc_sum_of_power(N, coord))

if __name__ == "__main__":
    try:
        assert calc_sum_of_power(2, [1, 4]) == 5
        assert calc_sum_of_power(7, [14, 14, 2, 13, 56, 2, 37]) == 2354
    except:
        import traceback
        traceback.print_exc()
        exit()
    main()
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
height = list(map(int, input().split()))
ans = 0
for i in range(n - 1):
    for j in range(i + 1 + height[i], n):
        if abs(j - i) == (height[i] + height[j]):
            ans += 1
print(ans)


Fixed submission:
from collections import defaultdict
n = int(input())
height = list(map(int, input().split()))
add_set = defaultdict(int)
ans = 0
for i in range(n):
    add_set[i + height[i] + 1] += 1
    if i + 1 - height[i] in add_set:
        ans += add_set[i + 1 - height[i]]

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from math import floor, ceil
a, b, n = map(int, input().split())
ans = 10 ** 6 * (-1)
x = 1
while x <= n:
    tmp = floor(a * x / b) - a * floor(x / b)
    ans = max(ans, tmp)
    x += ceil(b / a)
print(ans)


Fixed submission:
from math import floor
a, b, n = map(int, input().split())
x = min(b - 1, n)
ans = floor(a * x / b) - a * floor(x / b)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from math import floor, ceil
a, b, n = map(int, input().split())
ans = 10 ** 6 * (-1)
x = 1
while x <= n:
    tmp = floor(a * x / b) - a * floor(x / b)
    ans = max(ans, tmp)
    x = ceil((floor(a * x / b) + 1) * b / a)
print(ans)


Fixed submission:
from math import floor
a, b, n = map(int, input().split())
x = min(b - 1, n)
ans = floor(a * x / b) - a * floor(x / b)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
s = list(input())
ans = 0

for i in range(4, len(s) + 1):
    l = 0
    r = l + i
    while r <= len(s):
        if int(''.join(s[l:r])) % 2019 == 0:
            ans += 1
            l = r - 1
            r = l + i
        else:
            l += 1
            r += 1
print(ans)

Fixed submission:
s = input()[::-1]
sum_of_digits = 0
cnts = [0] * 2019
cnts[0] = 1

d = 1
for c in s:
    sum_of_digits += int(c) * d
    d *= 10
    d %= 2019
    sum_of_digits %= 2019
    cnts[sum_of_digits] += 1

ans = 0
for cnt in cnts:
    ans += cnt * (cnt - 1) // 2

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s = list(input())
ans = 0
for i in range(4, len(s) + 1):
    l = 0
    r = l + i
    while r <= len(s):
        if int(''.join(s[l:r])) % 2019 == 0:
            ans += 1
            l = r - 1
            r = l + i
        else:
            l += 1
            r += 1
print(ans)

Fixed submission:
s = input()[::-1]
sum_of_digits = 0
cnts = [0] * 2019
cnts[0] = 1

d = 1
for c in s:
    sum_of_digits += int(c) * d
    d *= 10
    d %= 2019
    sum_of_digits %= 2019
    cnts[sum_of_digits] += 1

ans = 0
for cnt in cnts:
    ans += cnt * (cnt - 1) // 2

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from math import gcd
from functools import reduce

def gcd_list(numbers):
    return reduce(gcd, numbers)

k = int(input())
ans = 0
for i in range(1, k + 1):
    for j in range(1, k + 1):
        for l in range(1, k + 1):
            ans += gcd_list([i, j, l])
print(ans)

Fixed submission:
from math import gcd
from functools import reduce

def gcd_list(numbers):
    return reduce(gcd, numbers)

k = int(input())
ans = 0
rev = 0
for i in range(1, k + 1):
    for j in range(i, k + 1):
        tmp = gcd(i, j)
        for l in range(j, k + 1):
            if i == j and j == l:
                ans += i
            elif i == j or j == l or l == i:
                ans += gcd(tmp, l) * 3
            else:
                ans += gcd(tmp, l) * 6
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
H, W, K = map(int, input().split())
s = []
INF = (H - 1) + (W - 1)
ans = INF

def add(col: int):
    for i in range(g):
        now[i] += c[i][col]
    for i in range(g):
        if now[i] > K:
            return False
    return True

for _ in range(H):
    s.append(list(input()))

for div in range(1 << (H - 1)):
    g = 0
    id = [0] * H
    for i in range(H):
        id[i] = g
        if div >> i & 1:
            g += 1
    g += 1
    now = [0] * g
    num = g - 1
    c = [[0 for _ in range(W)] for _ in range(H)]

    for i in range(H):
        for j in range(W):
            c[id[i]][j] += int(s[i][j])

    for j in range(W):
        if not add(j):
            num += 1
            now = [0] * g

            if not add(j):
                num = INF
                break

    ans = min(ans, num)
print(ans)

Fixed submission:
H, W, K = map(int, input().split())
s = []
INF = (H - 1) + (W - 1)
ans = INF

def add(col: int):
    for i in range(g):
        now[i] += c[i][col]
    for i in range(g):
        if now[i] > K:
            return False
    return True

for _ in range(H):
    s.append(list(input()))

for div in range(1 << (H - 1)):
    g = 0
    id = [0] * H
    for i in range(H):
        id[i] = g
        if div >> i & 1:
            g += 1
    g += 1
    
    now = [0] * g
    num = g - 1
    c = [[0 for _ in range(W)] for _ in range(H)]

    for i in range(H):
        for j in range(W):
            c[id[i]][j] += int(s[i][j])

    for j in range(W):
        if not add(j):
            num += 1
            now = [0] * g

            if not add(j):
                num = INF
                break

    ans = min(ans, num)
    
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N, A, B = map(int, input().split())
ans = 0
cnt = 0
while True:
    cnt += A
    ans += A
    if cnt >= N:
        ans -= cnt - N
        break
    cnt += B
    if cnt >= N:
        break
print(ans)

Fixed submission:
N, A, B = map(int, input().split())
ab = A + B
cnt = N // ab
remain = N - (cnt * ab)
blue = 0
if remain > A:
    blue = A
else:
    blue = remain
ans = A * cnt + blue
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N, A, B = map(int, input().split())
ans = 0
cnt = 0
while True:
    cnt += A
    ans += A
    if cnt >= N:
        ans -= cnt - N
    cnt += B
    if cnt >= N:
        break
print(ans)

Fixed submission:
N, A, B = map(int, input().split())
ab = A + B
cnt = N // ab
remain = N - (cnt * ab)
blue = 0
if remain > A:
    blue = A
else:
    blue = remain
ans = A * cnt + blue
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
P = list(map(int, input().split()))

ans = 0
for i in range(N - K + 1):
    tmp = 0
    for j in range(i, i + K):
        tmp += sum([n for n in range(1, P[j] + 1)]) / P[j]
    ans = max(ans, tmp)
print(ans)

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

s = sum(P[0:K])
m = s
id = 0
for i in range(1, N - K + 1):
    s += (P[i + K - 1] - P[i - 1])
    if s > m:
        id = i
        m = s

ans = 0
for j in range(id, id + K):
    ans += (P[j] + 1) / 2
print(ans)
Buggy python submission (verdict: Runtime Error):
 N = int(input())

def factorial(num):
    if num == 1:
        return 1
    return num * factorial(num - 1)

def count_order(group):
    numbers = [i for i in range(1, N + 1)]
    res = 1
    for i in range(len(group) - 1):
        num = group[i]
        res += numbers.index(num) * pattern[-(i + 1)]
        numbers.pop(numbers.index(num))
    return res


P = list(map(int, input().split()))
Q = list(map(int, input().split()))

pattern = [factorial(i) for i in range(1, N)]
res_p = count_order(P)
res_q = count_order(Q)

print(abs(res_p - res_q))


Fixed submission:
N = int(input())

def factorial(num):
    if num == 1:
        return 1
    return num * factorial(num - 1)

def count_order(group):
    numbers = [i for i in range(1, N + 1)]
    res = 1
    for i in range(len(group) - 1):
        num = group[i]
        res += numbers.index(num) * pattern[-(i + 1)]
        numbers.pop(numbers.index(num))
    return res


P = list(map(int, input().split()))
Q = list(map(int, input().split()))

pattern = [factorial(i) for i in range(1, N)]
res_p = count_order(P)
res_q = count_order(Q)

print(abs(res_p - res_q))