Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
h, w, m = map(int, input().split())
h_list = [0] * h
w_list = [0] * w
bomb = []
for i in range(m):
    h_tmp, w_tmp = map(int, input().split())
    h_list[h_tmp - 1] += 1
    w_list[w_tmp - 1] += 1
    bomb.append((h_tmp - 1, w_tmp - 1))
mh = max(h_list)
id_h = []
for i, n in enumerate(h_list):
    if n == mh:
        id_h.append(i)

mw = max(w_list)
id_w = []
for i, n in enumerate(w_list):
    if n == mw:
        id_w.append(i)

for i in id_h:
    for j in id_w:
        if not (i, j) in bomb:
            print(mh + mw)
            exit()

print(mh + mw - 1)

Fixed submission:
h, w, m = map(int, input().split())
h_list = [0] * h
w_list = [0] * w
bomb = []
for i in range(m):
    h_tmp, w_tmp = map(int, input().split())
    h_list[h_tmp - 1] += 1
    w_list[w_tmp - 1] += 1
    bomb.append((h_tmp - 1, w_tmp - 1))
bomb = set(bomb)
mh = max(h_list)
id_h = []
for i, n in enumerate(h_list):
    if n == mh:
        id_h.append(i)

mw = max(w_list)
id_w = []
for i, n in enumerate(w_list):
    if n == mw:
        id_w.append(i)

for i in id_h:
    for j in id_w:
        if not (i, j) in bomb:
            print(mh + mw)
            exit()

print(mh + mw - 1)
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
a = list(map(int, input().split()))
score = 1
for i in range(k):
    score *= a[i]
top = 0
for i in range(k, n):
    pre_score = score
    score /= a[top]
    top += 1
    score *= a[i]
    if score > pre_score:
        print("Yes")
    else:
        print("No")


Fixed submission:
n, k = map(int, input().split())
a = list(map(int, input().split()))
score = sum(a[:k])
top = 0
for i in range(k, n):
    if a[i] > a[top]:
        print("Yes")
    else:
        print("No")
    top += 1
Buggy python submission (verdict: Time Limit Exceeded):
import math
n = int(input())
for i in range(1, n+1):
    ans = 0
    for x in range(1, int(math.sqrt(n))):
        x2 = x*x
        for y in range(1, int(math.sqrt(n))):
            y2 = y*y
            xy = x * y
            tmp = x2 + y2 + xy
            if tmp >= i:
                break
            for z in range(1, int(math.sqrt(n))):
                if tmp + z*z + y*z + z*x == i:
                    ans += 1
                    break
    print(ans)


Fixed submission:
import math
n = int(input())
# ans = [0 for _ in range(n)]
ans = [0] * n

for x in range(1, int(math.sqrt(n+1))):
    x2 = x*x
    for y in range(1, int(math.sqrt(n+1))):
        y2 = y*y
        xy = x * y
        tmp = x2 + y2 + xy
        if tmp >= n:
            break
        for z in range(1, int(math.sqrt(n+1))):
            tmp2 = tmp + z*z + y*z + z*x
            if tmp2 > n:
                break
            try:
                ans[tmp2 - 1] += 1
                # print(x, y, z)
            except:
                pass
for i in range(n):
    print(ans[i])

Buggy python submission (verdict: Time Limit Exceeded):
import math
n = int(input())
for i in range(1, n+1):
    ans = 0
    for x in range(1, int(math.sqrt(n+1))):
        x2 = x*x
        for y in range(1, int(math.sqrt(n+1))):
            y2 = y*y
            xy = x * y
            for z in range(1, int(math.sqrt(n+1))):
                if x2 + y2 + z*z + xy + y*z + z*x == i:
                    ans += 1
    print(ans)


Fixed submission:
import math
n = int(input())
# ans = [0 for _ in range(n)]
ans = [0] * n

for x in range(1, int(math.sqrt(n+1))):
    x2 = x*x
    for y in range(1, int(math.sqrt(n+1))):
        y2 = y*y
        xy = x * y
        tmp = x2 + y2 + xy
        if tmp >= n:
            break
        for z in range(1, int(math.sqrt(n+1))):
            tmp2 = tmp + z*z + y*z + z*x
            if tmp2 > n:
                break
            try:
                ans[tmp2 - 1] += 1
                # print(x, y, z)
            except:
                pass
for i in range(n):
    print(ans[i])

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
for i in range(1, n+1):
    ans = 0
    for x in range(1, n+1):
        x2 = x*x
        for y in range(1, n+1):
            y2 = y*y
            xy = x * y
            for z in range(1, n+1):
                if x2 + y2 + z*z + xy + y*z + z*x == i:
                    ans += 1
    print(ans)

Fixed submission:
import math
n = int(input())
# ans = [0 for _ in range(n)]
ans = [0] * n

for x in range(1, int(math.sqrt(n+1))):
    x2 = x*x
    for y in range(1, int(math.sqrt(n+1))):
        y2 = y*y
        xy = x * y
        tmp = x2 + y2 + xy
        if tmp >= n:
            break
        for z in range(1, int(math.sqrt(n+1))):
            tmp2 = tmp + z*z + y*z + z*x
            if tmp2 > n:
                break
            try:
                ans[tmp2 - 1] += 1
                # print(x, y, z)
            except:
                pass
for i in range(n):
    print(ans[i])
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
ans = 1
for i in range(n):
    ans *= a[i]
if ans > pow(10, 18):
    print("-1")
else:
    print(ans)


Fixed submission:

n = int(input())
a = list(map(int, input().split()))
ans = 1
a.sort()
if a[0] == 0:
    print(0)
    exit()

for i in range(n):
    ans *= a[i]
    if ans > pow(10, 18):
        print(-1)
        exit()
else:
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
ans = 1
for i in range(n):
    ans *= a[i]
if ans > 10**18:
    print("-1")
else:
    print(ans)

Fixed submission:

n = int(input())
a = list(map(int, input().split()))
ans = 1
a.sort()
if a[0] == 0:
    print(0)
    exit()

for i in range(n):
    ans *= a[i]
    if ans > pow(10, 18):
        print(-1)
        exit()
else:
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
# from scipy.special import comb
n, a, b = map(int, input().split())
mod = 10 ** 9 + 7
all = (2**n - 1)%mod

def comb(n, r):
  c = 1
  m = 1
  r = min(n-r, r)
  for i in range(r):
    c = c * (n - i) % mod
    m = m * (i + 1) % mod
  return c * pow(m, mod-2, mod) % mod

nca = comb(n, a)
ncb = comb(n, b)
all -= nca + ncb
print(all%mod)


Fixed submission:
n, a, b = map(int, input().split())
mod = pow(10, 9) + 7
all = pow(2, n, mod) - 1

def comb(n, r):
  c = 1
  m = 1
  r = min(n-r, r)
  for i in range(r):
    c = c * (n - i) % mod
    m = m * (i + 1) % mod
  return c * pow(m, mod-2, mod) % mod

nca = comb(n, a)
ncb = comb(n, b)
all -= nca + ncb
print(all%mod)

Buggy python submission (verdict: Time Limit Exceeded):
# from scipy.special import comb
n, a, b = map(int, input().split())
mod = 10 ** 9 + 7
all = (2**n - 1)%mod

c = 1
m = 1
a = min(n-a, a)
for i in range(a):
    c = c*(n-i)%mod
    m = m*(i+1)%mod

nca = c*pow(m, mod-2, mod)%mod

c = 1
m = 1
a = min(n-b, b)
for i in range(b):
    c = c*(n-i)%mod
    m = m*(i+1)%mod

ncb = c*pow(m, mod-2, mod)%mod    

# nca = comb(n, a, exact=True)
# ncb = comb(n, b, exact=True)
all -= nca + ncb
print(all%mod)


Fixed submission:
n, a, b = map(int, input().split())
mod = pow(10, 9) + 7
all = pow(2, n, mod) - 1

def comb(n, r):
  c = 1
  m = 1
  r = min(n-r, r)
  for i in range(r):
    c = c * (n - i) % mod
    m = m * (i + 1) % mod
  return c * pow(m, mod-2, mod) % mod

nca = comb(n, a)
ncb = comb(n, b)
all -= nca + ncb
print(all%mod)

Buggy python submission (verdict: Runtime Error):
from scipy.special import comb
n, a, b = map(int, input().split())
all = (2**n - 1)
nca = comb(n, a, exact=True)
ncb = comb(n, b, exact=True)
all -= nca + ncb
print(all%1000000007)


Fixed submission:
n, a, b = map(int, input().split())
mod = pow(10, 9) + 7
all = pow(2, n, mod) - 1

def comb(n, r):
  c = 1
  m = 1
  r = min(n-r, r)
  for i in range(r):
    c = c * (n - i) % mod
    m = m * (i + 1) % mod
  return c * pow(m, mod-2, mod) % mod

nca = comb(n, a)
ncb = comb(n, b)
all -= nca + ncb
print(all%mod)

Buggy python submission (verdict: Time Limit Exceeded):

n, a, b = map(int, input().split())
all = (2**n - 1)%1000000007
# all = 2**n - 1
# print(all)
nca = 1
n_tmp = n
for i in range(1,a+1):
    nca *= n_tmp
    nca //= i
    # nca %= 1000000007
    n_tmp -= 1
    # a -= 1
# print(nca)
ncb = 1
n_tmp = n
for i in range(1,b+1):
    ncb *= n_tmp
    ncb //= i
    # ncb %= 1000000007
    n_tmp -= 1

all -= int(nca) + int(ncb)
print(int(all%1000000007))


Fixed submission:
n, a, b = map(int, input().split())
mod = pow(10, 9) + 7
all = pow(2, n, mod) - 1

def comb(n, r):
  c = 1
  m = 1
  r = min(n-r, r)
  for i in range(r):
    c = c * (n - i) % mod
    m = m * (i + 1) % mod
  return c * pow(m, mod-2, mod) % mod

nca = comb(n, a)
ncb = comb(n, b)
all -= nca + ncb
print(all%mod)
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
h = list(map(int, input().split()))
dp = [pow(10, 9)] * n
dp[0] = 0
for i in range(n):
    for j in range(i+1, i+k+1):
        if j == n:
            break
        dp[j] = min(dp[j], dp[i] + abs(h[j] - h[i]))
print(dp[-1])

Fixed submission:
n, k = map(int, input().split())
h = list(map(int, input().split()))
dp = [pow(10, 9)] * n
dp[0] = 0
for i in range(n):
    for j in range(i+1, i+k+1):
        if j == n:
            break
        dp[j] = min(dp[j], dp[i] + abs(h[j] - h[i]))
print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
h = list(map(int, input().split()))
dp = [False] * n
for i in range(n):
    for j in range(i+1, i+k+1):
        if j == n:
            break
        if dp[j] == False:
            dp[j] = dp[i] + abs(h[j] - h[i])
        else:
            dp[j] = min(dp[j], dp[i] + abs(h[j] - h[i]))
print(dp[-1])

Fixed submission:
n, k = map(int, input().split())
h = list(map(int, input().split()))
dp = [pow(10, 9)] * n
dp[0] = 0
for i in range(n):
    for j in range(i+1, i+k+1):
        if j == n:
            break
        dp[j] = min(dp[j], dp[i] + abs(h[j] - h[i]))
print(dp[-1])
Buggy python submission (verdict: Time Limit Exceeded):
n, w = map(int, input().split())
dp = [[0] * (w+1) for _ in range(n)]
weight, value = map(int, input().split())
for i in range(weight, w+1):
    dp[0][i] = value
for i in range(n-1):
    weight, value = map(int, input().split())
    for j in range(0, w+1):
        if j < weight:
            dp[i+1][j] = dp[i][j]
        else:
            dp[i+1][j] = max(dp[i][j], dp[i][j - weight] + value)

print(dp[-1][-1])

Fixed submission:
n, w = map(int, input().split())
dp = [[0] * (w+1) for _ in range(n)]
weight, value = map(int, input().split())
for i in range(weight, w+1):
    dp[0][i] = value
for i in range(n-1):
    weight, value = map(int, input().split())
    for j in range(0, w+1):
        if j < weight:
            dp[i+1][j] = dp[i][j]
        else:
            dp[i+1][j] = max(dp[i][j], dp[i][j - weight] + value)

print(dp[-1][-1])
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))

ans = 0
for i in range(n-1):
  ans += a[i]*sum(a[i+1:])
  ans %= 10**9+7
print(ans)

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

mod = 10**9+7
nums = [0]*n
nums[0] = a[0]
for i in range(1,n): nums[i] = a[i] + nums[i-1]

ans = 0
for i in range(n-1):
  ans += a[i] * (nums[n-1]-nums[i])
  ans %= mod
print(ans)

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

ans = 0
for i in range(n-1):
  for j in range(i+1,n):
    ans += a[i]*a[j]
  ans %= 10**9+7
print(ans)

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

mod = 10**9+7
nums = [0]*n
nums[0] = a[0]
for i in range(1,n): nums[i] = a[i] + nums[i-1]

ans = 0
for i in range(n-1):
  ans += a[i] * (nums[n-1]-nums[i])
  ans %= mod
print(ans)

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

mod = 10**9+7
ans = 0
for i in range(n-1):
  ans += a[i] * sum(a[i+1:])
  ans %= mod
print(ans)

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

mod = 10**9+7
nums = [0]*n
nums[0] = a[0]
for i in range(1,n): nums[i] = a[i] + nums[i-1]

ans = 0
for i in range(n-1):
  ans += a[i] * (nums[n-1]-nums[i])
  ans %= mod
print(ans)

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

mod = 10**9+7
ans = 0
for i in range(n-1):
  for j in range(i+1,n):
    ans += a[i]*a[j]
    ans %= mod
print(ans)

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

mod = 10**9+7
nums = [0]*n
nums[0] = a[0]
for i in range(1,n): nums[i] = a[i] + nums[i-1]

ans = 0
for i in range(n-1):
  ans += a[i] * (nums[n-1]-nums[i])
  ans %= mod
print(ans)

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

mod = 10**9+7
ans = 0
for i in range(n-1):
  for j in range(i+1,n): ans += a[i]*a[j]
print(ans % mod)

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

mod = 10**9+7
nums = [0]*n
nums[0] = a[0]
for i in range(1,n): nums[i] = a[i] + nums[i-1]

ans = 0
for i in range(n-1):
  ans += a[i] * (nums[n-1]-nums[i])
  ans %= mod
print(ans)

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

mod = 10**9+7
ans = 0
for i in range(n-1):
  for j in range(i+1,n):
    ans += a[i]*a[j]
    ans %= mod
print(ans)

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

mod = 10**9+7
nums = [0]*n
nums[0] = a[0]
for i in range(1,n): nums[i] = a[i] + nums[i-1]

ans = 0
for i in range(n-1):
  ans += a[i] * (nums[n-1]-nums[i])
  ans %= mod
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int, input().split())
a = list(map(int, input().split()))

nums = [0]*n
for i in range(n-k+1):
  nums[k+i-1] = sum(a[i:k+i])

for i in range(k,n):
  if nums[i-1] < nums[i]: print("Yes")
  else: print("No")

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

nums = [0]*n
nums[k-1] = sum(a[:k])
for i in range(k,n):
  nums[i] = nums[i-1] + a[i] - a[i-k]

for i in range(k,n):
  if nums[i-1] < nums[i]: print("Yes")
  else: print("No")
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
q = int(input())

m = 10**5+1
nums = [0]*m
for i in a: nums[i] += 1

for _ in range(q):
  b,c = map(int, input().split())
  nums[c] += nums[b]
  nums[b] = 0
  ans = 0
  for i in range(1,m): ans += i*nums[i]
  print(ans)

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

ans = sum(a)
nums = [0]*(10**5+1)
for i in a: nums[i] += 1

for _ in range(q):
  b,c = map(int, input().split())
  if nums[b] > 0:
    ans -= b*nums[b]
    nums[c] += nums[b]
    ans += c*nums[b]
    print(ans)
    nums[b] = 0
  else:
    print(ans)

Buggy python submission (verdict: Runtime Error):
from collections import Counter
n = int(input())
a = Counter(list(map(int, input().split())))
q = int(input())

for _ in range(q):
  b,c = map(int, input().split())
  if b in a:
    ans = 0
    t = a.pop(b)
    if c in a:
      a[c] += t
    else:
      a[c] = t
    for x,y in a.items():
      ans += x*y
    print(ans)
  else:
    print(ans)

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

ans = sum(a)
nums = [0]*(10**5+1)
for i in a: nums[i] += 1

for _ in range(q):
  b,c = map(int, input().split())
  if nums[b] > 0:
    ans -= b*nums[b]
    nums[c] += nums[b]
    ans += c*nums[b]
    print(ans)
    nums[b] = 0
  else:
    print(ans)

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

for _ in range(q):
  b,c = map(int, input().split())
  if b in a:
    for i in range(n):
      if a[i] == b: a[i] = c
    print(sum(a))
  else:
    print(sum(a))

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

ans = sum(a)
nums = [0]*(10**5+1)
for i in a: nums[i] += 1

for _ in range(q):
  b,c = map(int, input().split())
  if nums[b] > 0:
    ans -= b*nums[b]
    nums[c] += nums[b]
    ans += c*nums[b]
    print(ans)
    nums[b] = 0
  else:
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))

ans = 0
for i in range(n):
  for j in sorted(a):
    if a[i] % j == 0:
      if a[i] != j:
        ans += 1
        break
      else:
        if a.count(j) > 1:
          ans += 1
          break
    
print(n - ans)

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

m = max(A)+1
dp = [1]*m
for a in A:
  if dp[a-1] == 1:
    dp[a-1] = 2
    for i in range(a*2, m, a):
      dp[i-1] = 0
  elif dp[a-1] == 2:
    dp[a-1] = 0
print(sum([1 for a in A if dp[a-1]]))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))

if a.count(0) > 0:
  print(0)
  exit()
  
ans = a[0]
for i in range(1,n):
  ans *= a[i]
if ans > 10**18:
  print(-1)
else:
  print(ans)

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

if 0 in a:
  print(0)
  exit()

ans = 1
for i in a:
  ans *= i
  if ans > 10**18:
    print(-1)
    exit()
print(ans)

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

ans = a[0]
for i in range(1,n):
  ans *= a[i]
if ans > 10**18:
  print(-1)
else:
  print(ans)

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

if 0 in a:
  print(0)
  exit()

ans = 1
for i in a:
  ans *= i
  if ans > 10**18:
    print(-1)
    exit()
print(ans)

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

ans = 1
for i in a:
  ans *= i
if ans <= 10**18:
  print(ans)
else:
  print(-1)

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

if 0 in a:
  print(0)
  exit()

ans = 1
for i in a:
  ans *= i
  if ans > 10**18:
    print(-1)
    exit()
print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())

if n < 4:
  print(0)

t = int(n**0.5)+1
flag = [True]*(n+1)
flag[0] = False

for i in range(4,n+1,2):
  flag[i] = False
for i in range(3,t,2):
  for j in range(i+i, n+1, i):
    flag[j] = False

ans = 0
for i in range(2, t):
  if n%i == 0:
    for j in range(2,t+1):
      if i%j == 0:
        ans += 1
        break
    else:
      continue
    n //= i
print(ans)
    

Fixed submission:
n = int(input())

# 素因数分解
# √n+1までを対象に因数分解
# 素数のみを対象に処理しなくても2で引っかかる場合は4、6などは対象にならない。
prime = []
for i in range(2, int(n**0.5)+1): 
  cnt = 0
  while n%i == 0:
    n //= i # 割り切れる場合に最後の処理で余りが1になり、ループを抜ける
    cnt += 1
  prime.append(cnt) # 因数分解した回数を保持
  if n == 1:
    break

# 対象が素数であった場合は１を結果として保持
if n > 1:
  prime.append(1)
  
ans = 0
for x in prime:
  for i in range(1, x+1):
    if x >= i: # 素数の数をカウント
      ans += 1
      x -= i
    else:
      break
print(ans)
Buggy python submission (verdict: Runtime Error):
from collections import deque

def bfs(s):
  q = deque([s])
  d[s] = 1
  while q:
    node = q.popleft()
    for i in ab[node]:
      if d[i] == 0:
        d[i] = node + 1
        q.append(i)

n,m = map(int, input().split())
ab = [[] for _ in range(n)]
for _ in range(n):
  a,b = map(lambda x: int(x)-1, input().split())
  ab[a].append(b)
  ab[b].append(a)
  
d = [0]*n
bfs(0)
if all(d[1:]):
  print("Yes")
  print(*d[1:], sep="\n")
else: print("No")

Fixed submission:
from collections import deque

def bfs(graph, n, s):
  visited = [0]*n
  visited[s] = 1
  q = deque([s])
  while q:
    node = q.popleft()
    for i in graph[node]:
      if not visited[i]:
        visited[i] = node + 1
        q.append(i)
  return visited

n,m = map(int, input().split())
graph = [[] for _ in range(n)]
for _ in range(m):
  a,b = map(lambda n: int(n)-1, input().split())
  graph[a].append(b)
  graph[b].append(a)
visited = bfs(graph, n, 0)[1:]
if all(visited):
  print("Yes")
  print(*visited, sep="\n")
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
n,k = map(int, input().split())
a = list(map(int, input().split()))

l = [-1]*n
t = 0
s = 1
while l[s-1] == -1:
  if t == k: break
  l[s-1] = t
  t += 1
  s = a[s-1]
else:
  p = (k - l[s-1]) % (t - l[s-1])
  ans = l.index(l[s-1] + p) + 1
print(ans)

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

zero = [-1]*N

t = 0 # テレポート回数をカウント
a = 1
while zero[a-1] == -1: # テレポートがループした場合に処理を抜ける
  if t == K: # テレポート上限回数に達した場合は処理を抜ける
    break
  zero[a-1] = t # 何番目にレポートしたかを記録
  t += 1
  a = A[a-1] # テレポート先を設定
else:
  k = (K-zero[a-1]) % (t - zero[a-1]) # テレポートの剰余を求める
  a = zero.index(zero[a-1] + k) + 1 # 
print(a)
Buggy python submission (verdict: Time Limit Exceeded):
a,b,n = map(int, input().split())

if n >= b-1:
  print(a*(b-1)//b - a*((b-1)//b))
else:
  ans = 0
  for x in range(1,n+1):
    ans = max(ans, int(a*x/b) - a*int(x/b))
  print(ans)

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

x = min(b-1, n)
print(a*x//b -a*(x//b))

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


ans = 0
for i in range(1, n+1):
  t = (a*i//b) - a*(i//b)
  ans = max(ans,t)
print(ans)

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

x = min(b-1, n)
print(a*x//b -a*(x//b))
Buggy python submission (verdict: Runtime Error):
s = input()[::-1]

counts = [0]*2019 # 剰余の余りの回数を保存
counts[0] = 1 # 0%2019を累積和として含めることを想定

num, d = 0,1　# numは余りの累積和、dはcharの桁数
'''
charに一桁ずつ取り出す。そのmod2019を考え、累積和をとる。
しかし、それぞれの数字には10の累乗がかかっているので、それについては別途dを用意してmod2019をとる
つまり、numは1桁目のmod2019、2桁目のmod2019に1桁目のmod2019を加える
'''
for char in s:
  num += int(char) * d
  num %= 2019
  d *= 10
  d %= 2019
  counts[num] += 1

ans = 0
for c in counts:
  ans += c*(c-1)//2
  
print(ans)

Fixed submission:
import collections 
s = input()

n = len(s)
m = [0]
mod = 0
ten = 1
for i in s[::-1]:
  mod += (int(i)*ten)%2019
  mod %= 2019
  m.append(mod)
  ten *= 10
  ten %= 2019

count = collections.Counter(m)
print(sum([c*(c-1)//2 for c in count.values()]))
Buggy python submission (verdict: Time Limit Exceeded):
from math import gcd
from functools import reduce
k = int(input())

l = [[a,b,c] for a in range(1,k+1) for b in range(1,k+1) for c in range(1,k+1)]
#print(sum(reduce(gcd,l)))
ans = 0
for i in l:
  ans += reduce(gcd,i)
print(ans)

Fixed submission:
from math import gcd
k = int(input())

ans = 0
for i in range(1, k+1):
  for j in range(1, k+1):
    x = gcd(i,j)
    for l in range(1,k+1):
      ans += gcd(x,l)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import combinations
n = int(input())
s = input()

l = [i for i in range(n)]
nums = list(combinations(l,3))

ans = 0
for i,j,k in nums:
  if s[i] != s[j] and s[i] != s[k] and s[j] != s[k]:
    if j-i != k-j:
      ans += 1
print(ans)

Fixed submission:
n = int(input())
s = input()

r = s.count("R")
g = s.count("G")
b = s.count("B")
rgb = r*g*b

for i in range(n):
  for j in range(i+1, n-1):
    k = 2*j-i
    
    if k >= n or s[i] == s[j] or s[j] == s[k] or s[i] == s[k]:
      continue
      
    rgb -= 1
    
print(rgb)