Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
S = input()
N = int(input())
Q = [input().split() for _ in range(N)]
start = ''
end = ''

# Sの向きを定義1:前から0:後ろから
direct = 0
for i in range(N):
  if Q[i][0] =='1':
    direct^=1
  else:
    if direct == int(Q[i][1])-1:
      start += Q[i][2]
      print('start',start)
    else:
      end += Q[i][2]
      print('end',end)
      
ans = start[::-1]+S+end
print(ans) if direct == 0 else print(ans[::-1])

Fixed submission:
S = input()
N = int(input())
Q = [input().split() for _ in range(N)]
start = ''
end = ''

# Sの向きを定義1:前から0:後ろから
direct = 0
for i in range(N):
  if Q[i][0] =='1':
    direct^=1
  else:
    if direct == int(Q[i][1])-1:
      start += Q[i][2]
    else:
      end += Q[i][2]
      
ans = start[::-1]+S+end
print(ans) if direct == 0 else print(ans[::-1])
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**6)

# Segment Tree
class SegmentTree:
    def __init__(self, N):
        self.size = 2 ** (N-1).bit_length()# 要素数を超える最小の2べき
        self.dat = [0] * (2*self.size)
    
    def update(self,i,x):# i番目の文字がxになる
        i += self.size
        self.dat[i] = 1 << ord(x)-ord('a')
        while i > 0:# 上まで更新していく
            i >>= 1
            self.dat[i] = self.dat[i*2] | self.dat[i*2+1]

    def fold(self, l, r):
        l += self.size
        r += self.size
        vl = 0
        vr = 0
        while l < r:
            if l & 1:
                vl |= self.dat[l]
                l += 1
            if r & 1:
                r -= 1
                vr |= self.dat[r]
            l >>= 1
            r >>= 1
        # print(bin(vl | vr))
        return bin(vl | vr).count('1')

def main():
    N = int(input())
    S = list(input())
    sg = SegmentTree(N)
    for i in range(N):
        sg.update(i,S[i])
    # print(sg.dat)
    
    Q = int(input())
    for _ in range(Q):
        Query = input().split()
        if Query[0] == '1':
            sg.update(int(Query[1])-1, Query[2])
            # print(sg.dat)
        else:
            res = sg.fold(int(Query[1])-1, int(Query[2]))
            print(res)

if __name__ == "__main__":
    main()

Fixed submission:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**6)

# Segment Tree
class SegmentTree:
    def __init__(self, N):
        self.size = 2 ** (N-1).bit_length()# 要素数を超える最小の2べき
        self.dat = [0] * (2*self.size)
    
    def update(self,i,x):# i番目の文字がxになる
        i += self.size
        self.dat[i] = 1 << ord(x)-ord('a')
        while i > 0:# 上まで更新していく
            i >>= 1
            self.dat[i] = self.dat[i*2] | self.dat[i*2+1]

    def fold(self, l, r):
        l += self.size
        r += self.size
        vl = 0
        vr = 0
        while l < r:
            if l & 1:
                vl |= self.dat[l]
                l += 1
            if r & 1:
                r -= 1
                vr |= self.dat[r]
            l >>= 1
            r >>= 1
        # print(bin(vl | vr))
        return bin(vl | vr).count('1')

def main():
    N = int(input())
    S = list(input())
    sg = SegmentTree(N)
    for i in range(N):
        sg.update(i,S[i])
    
    Q = int(input())
    for _ in range(Q):
        Query = input().split()
        if Query[0] == '1':
            sg.update(int(Query[1])-1, Query[2])
        else:
            res = sg.fold(int(Query[1])-1, int(Query[2]))
            print(res)

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
N, R = map(int, input().split())
if N >= 10:
    print(R)
else:
    print(R+100*(10-K))

Fixed submission:
N,R=map(int,input().split())
print(R)if N>=10 else print(R+100*(10-N))
Buggy python submission (verdict: Runtime Error):
N=int(input())
A=list(map(int,input().split()))
flag=0
for i in range(N):
  if A[i]%2 ==0:
    if A[i]%3==0 or A[i]%5==0:
    else:
      flag=1
print(['APPROVED','DENIED'][flag])

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
flag=0
for i in range(N):
  if A[i]%2 ==0:
    if A[i]%3==0 or A[i]%5==0:
      pass
    else:
      flag=1
print(['APPROVED','DENIED'][flag])
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
d={}
for i in range(N):
  tmp = input()
  if tmp in d:
    d[tmp] += 1
  else:
    d[tmp] = 1

a = d.items()
b = d.values()
max_k_list = [kv[0] for kv in a if kv[1] == max(b)]
[print(i) for i in sorted(max_k_list)]

Fixed submission:
N=int(input())
d={}
for i in range(N):
  tmp = input()
  if tmp in d:
    d[tmp] += 1
  else:
    d[tmp] = 1

max_v=max(d.values())
ans=list(filter(lambda x: x[1] == max_v, d.items()))
[print(i[0]) for i in sorted(ans)]

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A = [input() for x in range(N)]
max=-1
ans=[]
for a in set(A):
  tmp = A.count(a)
  if tmp>max:
    max=tmp
    ans=[a]
  elif tmp==max:
    ans.append(a)

[print(i) for i in sorted(ans)]

Fixed submission:
N=int(input())
d={}
for i in range(N):
  tmp = input()
  if tmp in d:
    d[tmp] += 1
  else:
    d[tmp] = 1

max_v=max(d.values())
ans=list(filter(lambda x: x[1] == max_v, d.items()))
[print(i[0]) for i in sorted(ans)]
Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split())
p = list(map(int,input().split()))
max_l = [0]*K
for i in range(N):
  tmp_l = p[i:i+K]
  if sum(tmp_l) > sum(max_l):
    max_l = tmp_l
print(sum([(n+1)/2 for n in max_l]))

                          

Fixed submission:
N,K = map(int,input().split())
p = list(map(int,input().split()))
max_l = 0
point = sum(p[:K])
index = 0

for i in range(1,N-K+1):
  point -= (p[i-1] - p[i+K-1])
  if point > max_l:
    max_l = point
    index = i
print(sum([(n+1)/2 for n in p[index:index+K]]))
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right
from itertools import accumulate

sys.setrecursionlimit(10**6)
INF = 10**12
m = 10**9 + 7

def main():
    N = input()
    l = len(N)
    K = int(input())

    ans = 0
    # 最上位K桁が0の場合
    # l-K_C_K * 9^K
    if K == 1:
        ans += (l-1) * 9
    elif K == 2:
        ans += (l-1) * (l-2) * 81 // 2
    else:
        ans += (l-1) * (l-2) * (l-3) * 729 // 6

    if K == 1:
        # 最上位の数以外0
        ans += int(N[0])
    elif K == 2:
        # 最上位1桁が0ではなく,残りl-1桁中1桁だけ0以外（Nより大きくならないように注意）
        ans += int(N[0]) * (l-1) * 9 - (9 - int(N[1]))
    else:
        # 最上位1桁が0ではなく,残りl-1桁中2桁だけ0以外（Nより大きくならないように注意）
        ans += int(N[0]) * (l-1) * (l-2) * 81 // 2 - (99 - int(N[1:3]))
    print(ans)

if __name__ == "__main__":
    main()


Fixed submission:
#!/usr/bin/env python3

def main():
    N = input()
    l = len(N)
    K = int(input())

    ans = 0
    # 最上位K桁が0の場合
    # l-K_C_K * 9^K
    if K == 1:
        ans += (l-1) * 9
    elif K == 2:
        ans += (l-1) * (l-2) * 81 // 2
    else:
        ans += (l-1) * (l-2) * (l-3) * 729 // 6

    if K == 1:
        # 最上位の数以外0
        ans += int(N[0])
    elif K == 2:
        # 最上位1桁が0ではなく,残りl-1桁中1桁だけ0以外（Nより大きくならないように注意）
        if l >= 2:
            # ans += int(N[0]) * (l-1) * 9 - (9 - int(N[1]))
            for a in range(1,int(N[0])+1):
                for b in range(l-1):
                    for p in range(1,10):
                        tmp = a * 10**(l-1) + p * 10**b
                        if tmp <= int(N):
                            ans += 1
    else:
        # 最上位1桁が0ではなく,残りl-1桁中2桁だけ0以外（Nより大きくならないように注意）
        if l >= 3:
            NN = int(N)
            N0 = int(N[0])
            L = 10**(l-1)

            ans += (N0-1) * (l-1) * (l-2) * 81 // 2

            for p in range(1,10):
                for q in range(1,10):
                    for b in range(l-1):
                        for c in range(b+1,l-1):
                            tmp = N0 * L + p * 10**b + q * 10**c
                            if tmp <= NN:
                                ans += 1
                            else:
                                break
    print(ans)

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
H,N=map(int,input().split())
print('NYoe s'[H<=sum(list(map(int,input().split())))::2])

Fixed submission:
H,A = map(int,input().split())
print(1 + H // A) if H % A != 0 else print(H // A)
Buggy python submission (verdict: Runtime Error):
H,N=map(int,input().split())
A=[]
for i in range(N):
  A.append(int(input()))
print('YNeos'[H<sum(A)::2])
           

Fixed submission:
H,N=map(int,input().split())
print('NYoe s'[H<=sum(list(map(int,input().split())))::2])
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3

def main():
    H, N = map(int, input().split())
    A = [None] * N
    B = [None] * N
    for i in range(N):
        A[i], B[i] = map(int, input().split())

    #1次元DPに書き換え
    INF = 10**12
    dp = [INF] * (H+1)
    dp[0] = 0
    for i in range(N):
        for j in range(H+1):
            dp[min(j+A[i],H)] = min(dp[min(j+A[i],H)],dp[j]+B[i])
    print(dp[H])

if __name__ == "__main__":
    main()


Fixed submission:
#!/usr/bin/env python3
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right

def main():
    H, N = map(int, input().split())
    A = [None] * N
    B = [None] * N
    for i in range(N):
        A[i], B[i] = map(int, input().split())

    INF = 10**12
    dp = [[INF]*(H+1) for _ in range(N+1)]
    dp[0][0] = 0
    for i in range(N):
        for j in range(H+1):
            dp[i+1][j] = min(dp[i+1][j], dp[i][j])
            dp[i+1][min(j+A[i],H)] = min(dp[i+1][min(j+A[i],H)],dp[i+1][j]+B[i])
    print(dp[N][H])

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right

def main():
    H, N = map(int, input().split())
    A = [None] * N
    B = [None] * N
    for i in range(N):
        A[i], B[i] = map(int, input().split())

    INF = 10**12
    dp = [[INF]*(H+1) for _ in range(N+1)]
    dp[0][0] = 0
    for i in range(N):
        for j in range(H+1):
            dp[i+1][j] = min(dp[i+1][j], dp[i][j])
            dp[i+1][min(j+A[i],H)] = min(dp[i+1][min(j+A[i],H)],dp[i+1][j]+B[i])
    print(dp[N][H])

if __name__ == "__main__":
    main()


Fixed submission:
#!/usr/bin/env python3
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right

def main():
    H, N = map(int, input().split())
    A = [None] * N
    B = [None] * N
    for i in range(N):
        A[i], B[i] = map(int, input().split())

    INF = 10**12
    dp = [[INF]*(H+1) for _ in range(N+1)]
    dp[0][0] = 0
    for i in range(N):
        for j in range(H+1):
            dp[i+1][j] = min(dp[i+1][j], dp[i][j])
            dp[i+1][min(j+A[i],H)] = min(dp[i+1][min(j+A[i],H)],dp[i+1][j]+B[i])
    print(dp[N][H])

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N, D, A = map(int, input().split())
    XH = [None] * N

    for i in range(N):
        XH[i] = tuple(map(int, input().split()))

    XH.sort()
    
    # 何回爆弾を当てれば倒せるか
    nums = [(XH[i][1]+A-1)//A  for i in range(N)]
    
    ans = 0
    for i in range(N):
        if nums[i] == 0:
            continue
        ans += nums[i]
        for j in range(i+1,N):
            if XH[j][0] - XH[i][0] <= 2*D:
                nums[j] = max(0,nums[j]-nums[i])
            else:
                break
    print(ans)


if __name__ == "__main__":
    main()

Fixed submission:
#!/usr/bin/env python3
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right

def main():
    N, D, A = map(int, input().split())
    XH = [None] * N
    X = [None] * N

    for i in range(N):
        XH[i] = tuple(map(int, input().split()))
        X[i] = XH[i][0]

    XH.sort()
    X.sort()
    
    ans = 0
    S = [0] * (N+1)# 与えたダメージ
    for i in range(N):
        if S[i] < XH[i][1]:
            # あと何回攻撃する？
            need = (XH[i][1]-S[i]+A-1)//A
            # 爆弾が届く範囲
            j = bisect_right(X,X[i]+2*D)
            # imos法
            S[i] += need*A
            S[j] -= need*A
            ans += need
        S[i+1] += S[i]
    print(ans)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
a,b=map(int,open(0));print(str(min(a,b))*max(a,b))


Fixed submission:
a,b=map(int,input().split());print(str(min(a,b))*max(a,b))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
P = list(map(int, input().split()))
c = 0
for i in range(N):
  flag = True
  for j in range(i):
    if P[j] < P[i]:
      flag = False
      break
  if flag:
    c += 1
print(c)

Fixed submission:
N = int(input())
P = list(map(int, input().split()))
c = 1
tmp = P[0]
for i in range(1,N):
  tmp = min(tmp,P[i-1])
  if tmp >= P[i]:
    c += 1
print(c)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
P = list(map(int, input().split()))
c = 0
for i in range(N):
  flag = True
  for j in range(i):
    if P[j] < P[i]:
      flag = False
      break
  if flag:
    c += 1
print(c)

Fixed submission:
N = int(input())
P = list(map(int, input().split()))
c = 1
tmp = P[0]
for i in range(1,N):
  tmp = min(tmp,P[i-1])
  if tmp >= P[i]:
    c += 1
print(c)
Buggy python submission (verdict: Runtime Error):
print(char(ord(input())+1))

Fixed submission:
print(chr(ord(input())+1))
Buggy python submission (verdict: Runtime Error):
S = input()
T = input()
print(T+S)

Fixed submission:
S,T = map(str,input().split())
print(T+S)
Buggy python submission (verdict: Runtime Error):
a,b = map(int,input().split())
import math
print(a*b//math.gcd(a,b))

Fixed submission:
a,b = map(int,input().split())
import fractions
print(a*b//fractions.gcd(a,b))
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3


def main():
    N = int(input())
    A = list(map(int, input().split()))
    p = 10**9 + 7

    digit_0 = [0] * 60
    digit_1 = [0] * 60

    for i in range(N):
        for j in range(60):
            if (A[i] >> j) & 1:
                digit_1[j] += 1
            else:
                digit_0[j] += 1
    
    ans = 0
    for j in range(60):
        ans += ((digit_0[j] * digit_1[j] % p) * pow(2,j,p) % p)
        ans %= p
    print(ans)

if __name__ == "__main__":
    main()


Fixed submission:
#!/usr/bin/env python3


def main():
    N = int(input())
    A = list(map(int, input().split()))
    p = 10**9 + 7

    digit_0 = [0] * 60
    digit_1 = [0] * 60

    for i in range(N):
        for j in range(60):
            if (A[i] >> j) & 1:
                digit_1[j] += 1
            else:
                digit_0[j] += 1
    
    ans = 0
    for j in range(60):
        ans += ((digit_0[j] * digit_1[j] % p) * pow(2,j,p) % p)
        ans %= p
    print(ans)

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys


def main():
    X, Y = map(int, input().split())
    if (X + Y) % 3 != 0:
        print(0)
        exit()
    n = (X+Y) // 3
    if X < 2 or Y < 2:
        print(0)
        exit()
    r = X - n

    # nCrを計算する
    a = [None] * (n+1)
    inva = [None] * (n+1)
    a[0] = 1
    inva[0] = 1
    p = 10**9 + 7

    for i in range(1, n+1):
        a[i] = i * a[i-1] % p
        inva[i] = pow(i, p-2, p) * inva[i-1] % p

    ans = (a[n] * inva[r] % p) * inva[n-r] % p
    print(ans)


if __name__ == '__main__':
    main()


Fixed submission:
#!/usr/bin/env python3
import sys


def main():
    X, Y = map(int, input().split())
    if (X + Y) % 3 != 0:
        print(0)
        exit()
    n = (X+Y) // 3
    if X < n or Y < n:
        print(0)
        exit()
    r = X - n

    # nCrを計算する
    a = [None] * (n+1)
    inva = [None] * (n+1)
    a[0] = 1
    inva[0] = 1
    p = 10**9 + 7

    for i in range(1, n+1):
        a[i] = i * a[i-1] % p
        inva[i] = pow(i, p-2, p) * inva[i-1] % p

    ans = (a[n] * inva[r] % p) * inva[n-r] % p
    print(ans)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys


def main():
    X, Y = map(int, input().split())
    if (X + Y) % 3 != 0:
        print(0)
        exit()
    n = (X+Y) // 3
    r = X - n

    # nCrを計算する
    a = [None] * (n+1)
    inva = [None] * (n+1)
    a[0] = 1
    inva[0] = 1
    p = 10**9 + 7

    for i in range(1, n+1):
        a[i] = i * a[i-1] % p
        inva[i] = pow(i, p-2, p) * inva[i-1] % p

    ans = (a[n] * inva[r] % p) * inva[n-r] % p
    print(ans)


if __name__ == '__main__':
    main()


Fixed submission:
#!/usr/bin/env python3
import sys


def main():
    X, Y = map(int, input().split())
    if (X + Y) % 3 != 0:
        print(0)
        exit()
    n = (X+Y) // 3
    if X < n or Y < n:
        print(0)
        exit()
    r = X - n

    # nCrを計算する
    a = [None] * (n+1)
    inva = [None] * (n+1)
    a[0] = 1
    inva[0] = 1
    p = 10**9 + 7

    for i in range(1, n+1):
        a[i] = i * a[i-1] % p
        inva[i] = pow(i, p-2, p) * inva[i-1] % p

    ans = (a[n] * inva[r] % p) * inva[n-r] % p
    print(ans)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
import sys
from bisect import bisect_right

def main():
    N = int(input())
    L = sorted(list(map(int, input().split())))
    ans = 0

    for i in range(N-1):
        for j in range(i+1,N):
            diff = L[j] - L[i]
            index = bisect_right(L[:i],diff)
            ans += i-index
            # print(i,j,ans)
    print(ans)

if __name__ == '__main__':
    main()


Fixed submission:
#!/usr/bin/env python3
import sys
from bisect import bisect_right

def main():
    N = int(input())
    L = sorted(list(map(int, input().split())))
    ans = 0

    for i in range(N-1):
        for j in range(i+1,N):
            diff = L[j] - L[i]
            index = bisect_right(L[:i],diff)
            ans += i-index
            # print(i,j,ans)
    print(ans)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
import sys

def main():
    N = int(input())
    L = list(map(int, input().split()))
    L.sort()
    ans = 0

    for i in range(N-2):
        for j in range(i+1,N-1):
            minA = L[j] - L[i]
            maxA = L[j] + L[i]
            for k in range(j+1,N):
                if minA < L[k] < maxA:
                    ans += 1
    print(ans)


if __name__ == '__main__':
    main()


Fixed submission:
#!/usr/bin/env python3
import sys
from bisect import bisect_right

def main():
    N = int(input())
    L = sorted(list(map(int, input().split())))
    ans = 0

    for i in range(N-1):
        for j in range(i+1,N):
            diff = L[j] - L[i]
            index = bisect_right(L[:i],diff)
            ans += i-index
            # print(i,j,ans)
    print(ans)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
S = list(input())
N = len(S)
K = int(input())
if N == 1:
    print(K//2)
    exit()

cnt = 0
tmpS = S[:]
for i in range(N-1):
    if tmpS[i] == tmpS[i+1]:
        cnt += 1
        tmpS[i+1] = '!'

if S[N-1] == S[0]:
    a = 1
    while S[a-1] == S[a] and a <= N-1:
        a += 1
    b = 1
    while S[N-b] == S[N-b-1] and b <= N-1:
        b += 1
    print(cnt*K+a//2+b//2 - (a+b)//2 * (K-1))
else:
    print(cnt*K)

Fixed submission:
S = list(input())
N = len(S)
K = int(input())
  
if len(set(S)) == 1:
  print((N*K)//2)
  exit()

ans = 0
i = 0
while i < N-1:
  if S[i] == S[i+1]:
    ans += 1
    i += 1
  i += 1

if S[0] != S[N-1]:
  print(ans*K)
  exit()

a = 1
while S[0] == S[a]:
  a += 1

b = 1
while S[N-1] == S[N-1-b]:
  b += 1
print(ans*K - (K-1)*(a//2 + b//2 - (a+b)//2))

Buggy python submission (verdict: Runtime Error):
S = list(input())
flag = False
if S[0] == S[1]:
    flag = True
N = len(S)
K = int(input())
cnt = 0

for i in range(N-1):
    if S[i] == S[i+1]:
        cnt += 1
        S[i+1] = '!'

if S[N-1] == S[0]:
    if flag:
        print(cnt*K)
    else:
        print(cnt*K+(K-1))
else:
    print(cnt*K)

Fixed submission:
S = list(input())
N = len(S)
K = int(input())
  
if len(set(S)) == 1:
  print((N*K)//2)
  exit()

ans = 0
i = 0
while i < N-1:
  if S[i] == S[i+1]:
    ans += 1
    i += 1
  i += 1

if S[0] != S[N-1]:
  print(ans*K)
  exit()

a = 1
while S[0] == S[a]:
  a += 1

b = 1
while S[N-1] == S[N-1-b]:
  b += 1
print(ans*K - (K-1)*(a//2 + b//2 - (a+b)//2))
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3
import math

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f**2 <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

def main():
    A, B = map(int, input().split())
    C = math.gcd(A,B)
    if C == 1:
        print(1)
    else:
        ans = prime_factorize(C)
        print(len(set(ans)) + 1)


if __name__ == "__main__":
    main()


Fixed submission:
#!/usr/bin/env python3
import fractions

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f**2 <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

def main():
    A, B = map(int, input().split())
    C = fractions.gcd(A,B)
    if C == 1:
        print(1)
    else:
        ans = prime_factorize(C)
        print(len(set(ans)) + 1)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
T = ['Sunny','Cloudy','Rainy']
S = input()
print(T[1]) if S == T[0] elif print(T[2]) if S == T[1] else print(T[0])

Fixed submission:
T = ['Sunny','Cloudy','Rainy']
S = input()
print(T[1]) if S == T[0] else print(T[2]) if S == T[1] else print(T[0])
Buggy python submission (verdict: Time Limit Exceeded):
import sys
from bisect import insort_right
input = sys.stdin.readline
N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
for i in range(M):
  tmp = A[-1-i]
  insort_right(A,tmp//2)
print(sum(A[:-M]))

Fixed submission:
import sys
import heapq
from bisect import insort_right
input = sys.stdin.readline
N, M = map(int, input().split())
A = list(map(int, input().split()))
A = [-a for a in A]
heapq.heapify(A)
  
for i in range(M):
  tmp = heapq.heappop(A)
  heapq.heappush(A,int(tmp/2))
print(sum([-a for a in A]))

Buggy python submission (verdict: Time Limit Exceeded):
import sys
from bisect import insort_right
input = sys.stdin.readline
N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
for i in range(M):
  tmp = A[-1-i]
  insort_right(A,tmp//2)
print(sum(A[:-M]))

Fixed submission:
import sys
import heapq
from bisect import insort_right
input = sys.stdin.readline
N, M = map(int, input().split())
A = list(map(int, input().split()))
A = [-a for a in A]
heapq.heapify(A)
  
for i in range(M):
  tmp = heapq.heappop(A)
  heapq.heappush(A,int(tmp/2))
print(sum([-a for a in A]))

Buggy python submission (verdict: Time Limit Exceeded):
import sys
from bisect import insort_right
input = sys.stdin.readline
N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
for i in range(M):
  tmp = A[-1]
  del A[-1]
  insort_right(A,tmp//2)
print(sum(A))

Fixed submission:
import sys
import heapq
from bisect import insort_right
input = sys.stdin.readline
N, M = map(int, input().split())
A = list(map(int, input().split()))
A = [-a for a in A]
heapq.heapify(A)
  
for i in range(M):
  tmp = heapq.heappop(A)
  heapq.heappush(A,int(tmp/2))
print(sum([-a for a in A]))

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

for i in range(M):
  A.sort()
  A[-1] //=2
print(sum(A))

Fixed submission:
import sys
import heapq
from bisect import insort_right
input = sys.stdin.readline
N, M = map(int, input().split())
A = list(map(int, input().split()))
A = [-a for a in A]
heapq.heapify(A)
  
for i in range(M):
  tmp = heapq.heappop(A)
  heapq.heappush(A,int(tmp/2))
print(sum([-a for a in A]))