Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import math

s = list(input())
k =int(input())
cnt1 = 0
cnt2 = 0
ans = 0
i = 0
j = len(s)-1
p = False
n = 0
while s[0] == s[n]:
  n += 1
  if n == len(s)-1:
    p = True
    break
if p == True:
  answer = math.floor(len(s)*k/2)
if p == False:
  t = False
  while s[0] == s[i]:
    i+= 1
  cnt1 = i 
  while s[-1] == s[j]:
    j = j-1
  cnt2 = len(s)-j-1
  if s[0] == s[-1]:
    t = True
  new_s = s[cnt1:len(s)-cnt2]
  for i in range(len(new_s)-1):
      if new_s[i] == new_s[i+1]:
        new_s[i+1] = "0"
        ans += 1
  if t == True:
    ans_2 = math.floor((cnt1+cnt2)/2)
    answer = ans*k + ans_2*(k-1) + math.floor(cnt1/2) + math.floor(cnt2/2)
  if t == False:
    answer = ans*k + math.floor(cnt1/2)*k + math.floor(cnt2/2)*k
print(answer)

Fixed submission:
import math

s = list(input())
k =int(input())
cnt1 = 0
cnt2 = 0
ans = 0
i = 0
j = len(s)-1
p = False
n = 0
if len(s) == 1:
  answer = math.floor(k/2)
else:
  while s[0] == s[n]:
    n += 1
    if n == len(s)-1:
      p = True
      break
  if p == True:
    answer = math.floor(len(s)*k/2)
  if p == False:
    t = False
    while s[0] == s[i]:
      i+= 1
    cnt1 = i 
    while s[-1] == s[j]:
      j = j-1
    cnt2 = len(s)-j-1
    if s[0] == s[-1]:
      t = True
    new_s = s[cnt1:len(s)-cnt2]
    for i in range(len(new_s)-1):
        if new_s[i] == new_s[i+1]:
          new_s[i+1] = "0"
          ans += 1
    if t == True:
      ans_2 = math.floor((cnt1+cnt2)/2)
      answer = ans*k + ans_2*(k-1) + math.floor(cnt1/2) + math.floor(cnt2/2)
    if t == False:
      answer = ans*k + math.floor(cnt1/2)*k + math.floor(cnt2/2)*k
print(answer)
Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
li = list(map(int,input().split()))	
for i in range(m):
  li.sort()
  li[-1] = li[-1]//2
print(sum(li))

Fixed submission:
import heapq

n,m = map(int,input().split())
a = list(map(int,input().split()))
a = [-x for x in a]
heapq.heapify(a) 
ans =0
for i in range(m):
  b = a[0]
  c = (-1)*b //2
  heapq.heappop(a) 
  heapq.heappush(a, c*(-1)) 
print(sum(a)*(-1))
Buggy python submission (verdict: Runtime Error):
import.math
a,b = map(int,input().split())
if b == 1:
  print("0")
else:
  print(math.ceil(b/a))

Fixed submission:
a,b = map(int,input().split())
if b == 1:
  print("0")
else:
  for i in range(100):
    if (i-1)*(a-1) + a >= b:
      print(i)
      break
Buggy python submission (verdict: Runtime Error):
n = int(input())
li = list(map(int,input().split()))	
ans_li =[]
ans_1 = 0
for i in range(n-1):
  if li[i] >= li[i+1]:
     ans_1 = ans_1 + 1
  elif li[i]<li[i+1]:
    ans_li.append(ans_1)
    ans_1 = 0
  if i == n-2:
    ans_li.append(ans_1)
print(max(ans_li))

Fixed submission:
n = int(input())
li = list(map(int,input().split()))	
if n == 1:
  print("0")
else:
  ans_li =[]
  ans_1 = 0
  for i in range(n-1):
    if li[i] >= li[i+1]:
       ans_1 = ans_1 + 1
    elif li[i]<li[i+1]:
      ans_li.append(ans_1)
      ans_1 = 0
    if i == n-2:
      ans_li.append(ans_1)
  print(max(ans_li))

Buggy python submission (verdict: Runtime Error):
n = int(input())
li = list(map(int,input().split()))	
ans_li =[]
ans_1 = 0
for i in range(n-1):
  if i == n-2:
    ans_li.append(ans_1)
    break
  elif li[i] >= li[i+1]:
     ans_1 += 1
  else:
    ans_li.append(ans_1)
print(max(ans_li))

Fixed submission:
n = int(input())
li = list(map(int,input().split()))	
if n == 1:
  print("0")
else:
  ans_li =[]
  ans_1 = 0
  for i in range(n-1):
    if li[i] >= li[i+1]:
       ans_1 = ans_1 + 1
    elif li[i]<li[i+1]:
      ans_li.append(ans_1)
      ans_1 = 0
    if i == n-2:
      ans_li.append(ans_1)
  print(max(ans_li))
Buggy python submission (verdict: Runtime Error):
from decimal import Decimal

import math
n = int(input())
li = [list(map(int, input().split())) for _ in range(n)]
p = li[0]
d = li[0][0]**2 + li[0][1]**2
for i in range(1,n):
  if (p[0]+li[i][0])**2 + (p[1]+li[i][1])**2 > d:
    p = [p[0]+li[i][0],p[1]+li[i][1]]
    d = p[0]**2 + p[1]**2
distance = p[0]**2 + p[1]**2

print(math.sqrt(distance))

Fixed submission:
n = int(input())
print(((n-1)*n)//2)
Buggy python submission (verdict: Runtime Error):
n,k = map(int,input().split())
li = list(map(int,input().split()))
mod = 10**9 +7
 
ans_1 = 0
ans_2 = 0
for i in range(n):
  for j in range(i+1,n):
    if li[i] > li[j]:
      ans_1+= 1
for i in range(n):
  for j in range(n):
    if li[i] > li[j]:
      ans_2 += 1
ans = k*ans_1%mod + 0.5*k%mod*(k-1)%mod*ans_2%mod
print(int(ans%mod))

Fixed submission:
m,d = map(int,input().split())
ans = 0
for i in range(1,m+1):
  for j in range(1,d+1):
    if j%10 >= 2 and j//10 >= 2 and (j%10) * (j//10) ==i:
      ans += 1
print(ans)

Buggy python submission (verdict: Runtime Error):
n,k = map(int,input().split())
li = list(map(int,input().split()))
mod = 10**9 +7

ans_1 = 0
ans_2 = 0
for i in range(n-1):
  for j in range(i+1,n):
    if li[i] > li[j]:
      ans_1+= 1
for i in range(n):
  for j in range(n):
    if li[i] < li[j]:
      ans_2 += 1
ans = k*ans_1 + 0.5*k*(k-1)%mod*ans_2
print(ans_1)
print(ans_2)
print(ans%mod)

Fixed submission:
m,d = map(int,input().split())
ans = 0
for i in range(1,m+1):
  for j in range(1,d+1):
    if j%10 >= 2 and j//10 >= 2 and (j%10) * (j//10) ==i:
      ans += 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s_li=[input() for i in range(n)]
new_li=[]
for i in range(n):
  s_li[i]=sorted(list(s_li[i]))
ans = 0
for i in range(n):
  for j in range(i+1,n):
    if s_li[i] == s_li[j]:
      ans += 1
print(ans)

Fixed submission:
n = int(input())
dic = {}
ans = 0
for i in range(n):
  li_1 = list(input())
  li_1.sort()
  word = "".join(li_1)
  if word in dic:
    dic[word] += 1
  else:
    dic[word] = 1
for key in dic:
  s = dic[key]
  ans += s*(s-1)//2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s_li=[input() for i in range(n)]
new_li=[]
for i in range(n):
  new_li.append(sorted(list(s_li[i])))
ans = 0
for i in range(n):
  for j in range(i+1,n):
    if new_li[i] == new_li[j]:
      ans += 1
print(ans)

Fixed submission:
n = int(input())
dic = {}
ans = 0
for i in range(n):
  li_1 = list(input())
  li_1.sort()
  word = "".join(li_1)
  if word in dic:
    dic[word] += 1
  else:
    dic[word] = 1
for key in dic:
  s = dic[key]
  ans += s*(s-1)//2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s_li=[input() for i in range(n)]
ans = 0
for i in range(n):
  s=list(s_li[i])
  ss=sorted(s)
  for j in range(i+1,n):
    t = list(s_li[j])
    tt = sorted(t)
    if ss == tt:
      ans+= 1
print(ans)

Fixed submission:
n = int(input())
dic = {}
ans = 0
for i in range(n):
  li_1 = list(input())
  li_1.sort()
  word = "".join(li_1)
  if word in dic:
    dic[word] += 1
  else:
    dic[word] = 1
for key in dic:
  s = dic[key]
  ans += s*(s-1)//2
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
li = []
for i in range(n):
  li.append(int(input()))

for i in range (n):
  li_2 = li[0:i]+li[i+1:n+1]
  print(max(li_2))

Fixed submission:
n = int(input())
li = []
for i in range(n):
  li.append(int(input()))
li_2 = sorted(li)
m_1 = li_2[-1]
m_2 = li_2[-2]
for i in range(n):
  if m_1 == li[i]:
    print(m_2)
  else:
    print(m_1)
Buggy python submission (verdict: Runtime Error):
a.b = map(int,input().split)
if a >=13:
  print(b)
else if 6<=a and a<=13:
  print(b//2)
else:
  print(0)

Fixed submission:
a,b = map(int,input().split())
if a >=13:
  print(b)
elif 6<=a and a<=13:
  print(b//2)
else:
  print(0)
Buggy python submission (verdict: Runtime Error):
n = int(input())
v_li = list(map(int,input().split()))
c_li = list(map(int,input().split()))
ben = []
for i in range(n):
  b = v_li[i]-c_li[i]
  ben.append(b)
ben.sort()
ben.reverse()
ans = 0
j = 0
while ben[j]>=0:
  ans+= ben[j]
  j +=1
print(ans)

Fixed submission:
n = int(input())
v_li = list(map(int,input().split()))
c_li = list(map(int,input().split()))
ben = []
for i in range(n):
  b = v_li[i]-c_li[i]
  ben.append(b)
ben.sort()
ben.reverse()
ans = 0
for i in range(n):
  if ben[i] >0:
    ans+=ben[i]
  else:
    break
print(ans)

Buggy python submission (verdict: Runtime Error):
n = int(input())
v_li = list(map(int,input().split()))
c_li = list(map(int,input().split()))
ben = []
for i in range(n):
  b = v_li[i]-c_li[i]
  ben.append(b)
ben.sort()
ben.reverse()
ans = 0
j = 0
while ben[j]>0:
  ans+= ben[j]
  j +=1
print(ans)

Fixed submission:
n = int(input())
v_li = list(map(int,input().split()))
c_li = list(map(int,input().split()))
ben = []
for i in range(n):
  b = v_li[i]-c_li[i]
  ben.append(b)
ben.sort()
ben.reverse()
ans = 0
for i in range(n):
  if ben[i] >0:
    ans+=ben[i]
  else:
    break
print(ans)
Buggy python submission (verdict: Runtime Error):
import math
n = int(input())
li=[int(input()) for i in range(n)]
print(math.ceil(n/min(li))+4)

Fixed submission:
li = []
for i in range(6):
  li.append(int(input()))
if li[4] - li[0] <= li[5]:
  print("Yay!")
else:
  print(":(")
Buggy python submission (verdict: Time Limit Exceeded):
import bisect
n,q = map(int,input().split())
s = input()
li=[]
for i in range(n-1):
  if s[i] == "A" and s[i+1] == "C":
    li.append(i)
for i in range(q):
  l,r = map(int,input().split())
  l = l-1
  r = r-1
  li_2 = li[bisect.bisect_left(li,l):bisect.bisect_right(li,r-1)]
  print(len(li_2))

Fixed submission:
n,q = map(int,input().split())
s = input()
li = [0]
t = 0
for i in range(len(s)-1):
  if s[i] == "A" and s[i+1] == "C":
    t += 1
  li.append(t)
for k in range(q):
  l,r = map(int,input().split())
  print(li[r-1] - li[l-1])
Buggy python submission (verdict: Time Limit Exceeded):
def I(): return int(input())
def MI(): return map(int,input().split())
def LI(): return list(map(int,input().split()))
n,k = MI()
h = LI()
h = h+ [float('INF')]*10000
dp = [float('INF')]*(10**5+1000)
dp[0] = 0
for i in range(n):
  for j in range(1,k+1):
    dp[i+j] = min(dp[i+j],dp[i] + abs(h[i+j] - h[i])) 
print(dp[n-1])

Fixed submission:
def I(): return int(input())
def MI(): return map(int,input().split())
def LI(): return list(map(int,input().split()))
n,k = MI()
h = LI()
h = h+ [float('INF')]*10000
dp = [float('INF')]*(10**5+1000)
dp[0] = 0
for i in range(n):
  for j in range(1,k+1):
    dp[i+j] = min(dp[i+j],dp[i] + abs(h[i+j] - h[i])) 
print(dp[n-1])
Buggy python submission (verdict: Runtime Error):
# coding: utf-8
import math

num = int(input())
total = 0

tall = list(map(int, input().split()))
for i in range(num):
    if i != num-1:
    	num1 = tall[i]
    	num2 = tall[i+1]
    if num1 > num2:
        total += num2 - num1

print(abs(total))

Fixed submission:
# coding: utf-8
import math

num = int(input())
total = 0
max = 0
tall = list(map(int, input().split()))
for i in range(num):
    if max <= tall[i]:
        max = tall[i]
    if max > tall[i]:
        total += max -tall[i]

print(total)
Buggy python submission (verdict: Time Limit Exceeded):
import math
ans = 0
num = int(input())
for i in range(1, num+1):
    for j in range(1, num+1):
        for k in range(1, num+1):
            ans += math.gcd(math.gcd(i, j),k)
print(ans)

Fixed submission:
import math
ans = 0
num = int(input())
for i in range(1, num+1):
    for j in range(1, num+1):
        for k in range(1, num+1):
            ans += math.gcd(math.gcd(i, j),k)
print(ans)
Buggy python submission (verdict: Runtime Error):
num = int(input())

number = num / 3
print(number * number * number)a

Fixed submission:
num = int(input())

number = num / 3
print(number * number * number)
Buggy python submission (verdict: Time Limit Exceeded):
num = int(input())
table = list(map(int, input().split()))
count = 0

for i in range(num):
    for j in range(i+1, num):
        if table[i] == table[j]:
            count += 1
        else:
            continue
if count == 0:
    print('YES')
else:
    print('NO')

Fixed submission:
num = int(input())
table = list(map(int, input().split()))
count = 0
list.sort(table)
if num == 2:
        if table[0] == table[1]:
            count += 1
else:
    for i in range(1, num-1):
        if num == 2:
            if table[0] == table[1]:
                count += 1
        elif table[i] == table[i+1] or table[i-1] == table[i]:
            count += 1
        else:
            continue
if count == 0:
    print('YES')
else:
    print('NO')
Buggy python submission (verdict: Time Limit Exceeded):
card_num, gate_num = map(int, input().split())
table = [0] * card_num
count = 0


for i in range(gate_num):
    start_num, end_num = map(int, input().split())
    for j in range(start_num-1, end_num):
        table[j] += 1

for l in range(card_num):
    if table[l] == gate_num:
        count += 1

print(count)

Fixed submission:
# 先頭の最大と最後尾の最小を求める
card_num, gate_num = map(int, input().split())
lmax, rmin = map(int, input().split()) # 最初の入力がlの最大とrの最小
for i in range(1, gate_num):
    l, r = map(int, input().split())
    lmax = max(lmax, l) # lmaxにlmaxとlの大きい方
    rmin = min(rmin, r) # rminにrminとrの小さい方
print(max(0, rmin-lmax+1)) # 0かrmin-lmax+1の大きい方を出力

Buggy python submission (verdict: Time Limit Exceeded):
card_num, gate_num = map(int, input().split())
table = []
count = 0
for k in range(card_num):
    table.append(0)

for i in range(gate_num):
    start_num, end_num = map(int, input().split())
    for j in range(start_num-1, end_num):
        table[j] += 1

for l in range(card_num):
    if table[l] == gate_num:
        count += 1

print(count)

Fixed submission:
# 先頭の最大と最後尾の最小を求める
card_num, gate_num = map(int, input().split())
lmax, rmin = map(int, input().split()) # 最初の入力がlの最大とrの最小
for i in range(1, gate_num):
    l, r = map(int, input().split())
    lmax = max(lmax, l) # lmaxにlmaxとlの大きい方
    rmin = min(rmin, r) # rminにrminとrの小さい方
print(max(0, rmin-lmax+1)) # 0かrmin-lmax+1の大きい方を出力
Buggy python submission (verdict: Runtime Error):
X = int(input().split())

if X >= 30:
    print("Yes")
else:
    print("No")


Fixed submission:
X = int(input())

if X >= 30:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Time Limit Exceeded):
def solve(A,N):
    if N == 1:
        return 1
    else:
        A.sort()
        cand = [A[0]]
        cand_del = [-1]
        for i in range(N):
            push = True
            for c in cand:
                if A[i] % c == 0:
                    push = False
                    break
            if push:
                cand.append(A[i])
            if i >= 1:
                if cand[-1] == A[i-1]:
                    cand_del.append(A[i])
        cand,cand_del = set(cand),set(cand_del)
        return len(cand - cand_del)

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

    print(solve(A,N))

if __name__ == "__main__":
    main()


Fixed submission:
def solve(A,N):
    A.sort()
    if N == 1:
        return 1
    elif N == 2:
        if A[1] == A[0]:
            return 0
        elif A[1] % A[0] == 0:
            return 1
        else:
            return 2
    else:
        Col = set()
        if A[0] == A[1]:
            Col.add(A[0])
        for i in range(1,N-1):
            if A[i-1] == A[i] or A[i] == A[i+1]:
                Col.add(A[i])
        if A[N-1] == A[N-2]:
            Col.add(A[N-1])

        Mul = set()
        cand = set()
        for i in range(N):
            if A[i] not in Mul:
                if A[i] not in Col:
                    cand.add(A[i])
                for d in range(1,(A[N-1]//A[i])+1):
                    Mul.add(A[i] * d)

        return len(cand)

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

    print(solve(A,N))

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
def solve(A,N,K):
    for k in range(K):
        C = [0 for _ in range(N+1)]
        #C[i]:i番目の電球を照らす電球の数
        for i in range(N):
            C[max(i-A[i],0)] += 1
            C[min(i+A[i]+1,N)] -= 1
        for i in range(1,N):
            C[i] += C[i-1]

        if C[0] == N or C[N-1] == N:
            for i in range(N):
                A[i] = N
            break
        else:
            for i in range(N):
                A[i] = C[i]
    return A

def main():
    N,K = map(int,input().split())
    A = list(map(int,input().split()))

    ans = solve(A,N,K)

    print(" ".join(map(str,ans)))

if __name__ == "__main__":
    main()


Fixed submission:
def solve(A,N,K):
    for k in range(K):
        C = [0 for _ in range(N+1)]
        #C[i]:i番目の電球を照らす電球の数
        for i in range(N):
            C[max(i-A[i],0)] += 1
            C[min(i+A[i]+1,N)] -= 1
        for i in range(1,N):
            C[i] += C[i-1]

        if C[0] == N or C[N-1] == N:
            for i in range(N):
                A[i] = N
            break
        else:
            for i in range(N):
                A[i] = C[i]
    return A

def main():
    N,K = map(int,input().split())
    A = list(map(int,input().split()))

    ans = solve(A,N,K)

    print(" ".join(map(str,ans)))

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
def DP(A,N,S,M):
    dp = [[0 for _ in range(S+1)] for _ in range(N+1)]
    dp[0][0] = 1
    #dp[i][j]:要素数i個以下,i番目までで和がjである部分集合の個数
    for i in range(1,N+1):
        for j in range(S+1):
            dp[i][j] = 2 * dp[i-1][j]
            dp[i][j] %= M
            if j - A[i-1] >= 0:
                dp[i][j] += dp[i-1][j-A[i-1]]
                dp[i][j] %= M

    return dp[N][S]

def main():
    N,S = map(int,input().split())
    A = list(map(int,input().split()))
    M = 998244353

    ans = DP(A,N,S,M)
    print(ans)

if __name__ == "__main__":
    main()


Fixed submission:
def DP(A,N,S,M):
    dp = [[0 for _ in range(S+1)] for _ in range(N+1)]
    dp[0][0] = 1
    #dp[i][j]:要素数i個以下,i番目までで和がjである部分集合の個数
    for i in range(1,N+1):
        for j in range(S+1):
            dp[i][j] = 2 * dp[i-1][j]
            dp[i][j] %= M
            if j - A[i-1] >= 0:
                dp[i][j] += dp[i-1][j-A[i-1]]
                dp[i][j] %= M

    return dp[N][S]

def main():
    N,S = map(int,input().split())
    A = list(map(int,input().split()))
    M = 998244353

    ans = DP(A,N,S,M)
    print(ans)

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
from queue import Queue

def bfs(AB,N):
    S = [None for _ in range(N+1)]
    #S[i]:部屋iにつけるべきサイン
    q = Queue()
    q.put(1)

    while not q.empty():
        p = q.get()
        for i in range(1,N+1):
            if (p,i) in AB and S[i] == None:
                q.put(i)
                S[i] = p

    can = True
    for i in range(2,N+1):
        if S[i] == None:
            can = False

    if can:
        return S[2:]
    else:
        return -1

def main():
    N,M = map(int,input().split())
    AB = [tuple(map(int,input().split())) for _ in range(M)]

    AB_ = set(AB)
    for i in range(M):
        AB_.add((AB[i][1],AB[i][0]))
    AB = AB_

    ans = bfs(AB,N)
    if ans == -1:
        print("No")
    else:
        print("Yes")
        for i in range(len(ans)):
            print(ans[i])

if __name__ == "__main__":
    main()


Fixed submission:
from queue import Queue

def bfs(AB,N):
    S = [None for _ in range(N+1)]
    #S[i]:部屋iにつけるべきサイン
    AB_N = [set() for _ in range(N+1)]
    for ab in AB:
        a,b = ab[0],ab[1]
        AB_N[a].add((a,b))

    q = Queue()
    q.put(1)

    while not q.empty():
        p = q.get()
        for ab in AB_N[p]:
            a,b = ab[0],ab[1]
            if a == p:
                if  S[b] == None:
                    q.put(b)
                    S[b] = p

    can = True
    for i in range(2,N+1):
        if S[i] == None:
            can = False

    if can:
        return S[2:]
    else:
        return -1

def main():
    N,M = map(int,input().split())
    AB = [tuple(map(int,input().split())) for _ in range(M)]

    AB_ = set(AB)
    for i in range(M):
        AB_.add((AB[i][1],AB[i][0]))
    AB = AB_

    ans = bfs(AB,N)
    if ans == -1:
        print("No")
    else:
        print("Yes")
        for i in range(len(ans)):
            print(ans[i])

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
def main():
    X = int(input())
    n_5,a = [(0,0)],1
    while a**5 <= X:
        n_5.append((a,a**5))
        n_5.append((-a,-a**5))
        a += 1
    n_5.sort()

    for a in range(len(n_5)):
        for b in range(len(n_5)):
            if n_5[a][1] - n_5[b][1] == X:
                a_ans,b_ans = n_5[a][0],n_5[b][0]
                break

    print(a_ans,b_ans)

if __name__ == "__main__":
    main()


Fixed submission:
def cal(a,b):
    return a**5-b**5

def main():
    X = int(input())
    update = True
    for i in range(10**3):
        for j in range(10**3):
            if cal(i,j) == X:
                a,b = i,j
                update = False
                break
            if cal(i,-j) == X:
                a,b = i,-j
                update = False
                break
        if not update:
            break

    print(a,b)

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
from math import gcd

def cal(A,B,x):
    return int((A*x)/B) - A*int(x/B)

def main():
    A,B,N = map(int,input().split())
    if N <= B-1:
        ans = cal(A,B,N)
    else:
        a,b = A//gcd(A,B),B//gcd(A,B)
        if N % B == 0:
            ans = cal(A,B,b*d-1)
        else:
            ans = cal(A,B,N)
    print(ans)

if __name__ == "__main__":
    main()


Fixed submission:
def cal(A,B,x):
    return int((A*x)/B) - A*int(x/B)

def main():
    A,B,N = map(int,input().split())
    if N <= B-1:
        ans = cal(A,B,N)
    else:
        ans = cal(A,B,B-1)
    print(ans)

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
N = len(S)

ans_set1 = set()
ans_set2 = set()

for i in range(N+1):
    for j in range(i+3,N+1):
        if int(S[i:j]) % 673 == 0:
            ans_set1.add((i,j))

for i,j in ans_set1:
    if int(S[i:j]) % 3 == 0:
        ans_set2.add((i,j))

print(len(ans_set2))


Fixed submission:
def cal(S):
    N = len(S)
    num,cnt = 0,0
    mod = 2019
    rem = [0 for _ in range(mod)]
    for i in range(N):
        num = (num + int(S[N-1-i]) * pow(10,i,mod)) % mod
        rem[num] += 1

    output = rem[0] * (rem[0] + 1) // 2
    for i in range(1,mod):
        output += rem[i] * (rem[i]-1) // 2

    return output

def main():
    S = input()

    print(cal(S))

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import collections

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

def comb(n):
    return n*(n-1)//2

L = collections.Counter(A)

for i in range(N):
    ans = 0
    for a in AS:
        if A[i] == a:
            ans += comb(L[a]-1)
        else:
            ans += comb(L[a])
    print(ans)


Fixed submission:
import collections

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

def comb(n):
    return n*(n-1)//2

L = collections.Counter(A)

ans_tmp = 0
for a in AS:
    ans_tmp += comb(L[a])

for i in range(N):
    ans = ans_tmp
    ans += (comb(L[A[i]]-1) - comb(L[A[i]]))

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

Q = [(P[i]+1)/2 for i in range(N)]

max = 0
for i in range(N-K+1):
    if max < sum(Q[i:K+i]):
        max = sum(Q[i:K+i])

print(max)


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

Q = [(P[i]+1)/2 for i in range(N)]

max,tmp = sum(Q[0:K]),sum(Q[0:K])
for i in range(N-K):
    tmp = tmp + Q[K+i] - Q[i]
    if max < tmp:
        max = tmp

print(max)