Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
R, C, K = map(int,input().split())
V = [[]for i in range(R)]
for i in range(K):
    r,c,v = map(int,input().split())
    V[r-1].append([c,v])
cost = [0]*(C+1)
for r in range(R):
    V[r].sort()
    hoge = [0,0,0,0]
    for c,v in V[r]:
        for i in range(3,0,-1):
            hoge[i] = max(cost[c]+v,hoge[i-1]+v,hoge[i])
        hoge[0] = cost[c]
        cost[c] = max(hoge)
    for i in range(1,C+1):
        cost[i] = max(cost[i],cost[i-1])

print(cost[-1]) 


Fixed submission:
R, C, K = map(int,input().split())
V = [[]for i in range(R)]
for i in range(K):
    r,c,v = map(int,input().split())
    V[r-1].append([c,v])
cost = [0]*(C+1)
for r in range(R):
    V[r].sort()
    hoge = [0,0,0,0]
    for c,v in V[r]:
        for i in range(3,0,-1):
            hoge[i] = max(cost[c]+v,hoge[i-1]+v,hoge[i])
        hoge[0] = cost[c]
        cost[c] = max(hoge)
    for i in range(1,C+1):
        cost[i] = max(cost[i],cost[i-1])

print(cost[-1])

Buggy python submission (verdict: Runtime Error):
R, C, K = map(int,input().split())
V = [[]for i in range(R)]
for i in range(K):
    r,c,v = map(int,input().split())
    V[r-1].append([c,v])
cost = [0]*C
for r in range(R):
    V[r].sort()
    hoge = [0,0,0,0]
    for c,v in V[r]:
        for i in range(3,-1,-1):
            hoge[i] = max(cost[c],hoge[i-1])
            hoge[i] += v
        hoge[0] -= v
        cost[c] = max(hoge)
    for i in range(1,C):
        cost[i] = max(cost[i],cost[i-1])

print(cost[-1][-1]) 

Fixed submission:
R, C, K = map(int,input().split())
V = [[]for i in range(R)]
for i in range(K):
    r,c,v = map(int,input().split())
    V[r-1].append([c,v])
cost = [0]*(C+1)
for r in range(R):
    V[r].sort()
    hoge = [0,0,0,0]
    for c,v in V[r]:
        for i in range(3,0,-1):
            hoge[i] = max(cost[c]+v,hoge[i-1]+v,hoge[i])
        hoge[0] = cost[c]
        cost[c] = max(hoge)
    for i in range(1,C+1):
        cost[i] = max(cost[i],cost[i-1])

print(cost[-1])

Buggy python submission (verdict: Time Limit Exceeded):
R, C, K = map(int,input().split())
M = [[0] * C for i in range(R)]
for i in range(K):
    r,c,v = map(int,input().split())
    M[r-1][c-1] = v

cost = [[[0]*4 for _ in range(C+1)] for _ in range(R+1)]
for x in range(R):
    for y in range(C):
        cost[x-1][y] = max(cost[x-1][y])
        for z in range(4):
            if z == 0:
                cost[x][y][z] = max(cost[x][y-1][z],cost[x-1][y]) 
            else:
                cost[x][y][z] = max(cost[x][y-1][z],cost[x][y-1][z-1]+M[x][y],cost[x-1][y]+M[x][y])

print(cost[-2][-2][-1])

Fixed submission:
R, C, K = map(int,input().split())
V = [[]for i in range(R)]
for i in range(K):
    r,c,v = map(int,input().split())
    V[r-1].append([c,v])
cost = [0]*(C+1)
for r in range(R):
    V[r].sort()
    hoge = [0,0,0,0]
    for c,v in V[r]:
        for i in range(3,0,-1):
            hoge[i] = max(cost[c]+v,hoge[i-1]+v,hoge[i])
        hoge[0] = cost[c]
        cost[c] = max(hoge)
    for i in range(1,C+1):
        cost[i] = max(cost[i],cost[i-1])

print(cost[-1])
Buggy python submission (verdict: Runtime Error):
def func(N):
    return N%bin(N).count("1")

N = int(input())
X = input()

popcount = X.count("1")
X_num = int(X,2)
bi = 2**(N-1)


for i in range(N):
    if(X[i] == "0"):
        hoge = X_num+bi
        I_count = popcount + 1
    else:
        hoge = X_num-bi
        I_count = popcount - 1
    count = 1
    hoge = hoge%I_count
    while hoge != 0:
        hoge = func(hoge)
        count += 1
    print(count)
    bi >>= 1

Fixed submission:
def func(N):
    return N%bin(N).count("1")

N = int(input())
X = input()

popcount = X.count("1")
X_num = int(X,2)

O = X_num%(popcount+1)
if popcount==1:
    I = 0
else:
    I = X_num%(popcount-1)

bO = 1
bI = 1

ans= []
for i in range(N):
    if X[-1-i]=="0":
        hoge = (O + bO)%(popcount+1)
    else:
        if popcount==1:
            ans.append(0)
            continue
        hoge = (I - bI)%(popcount-1)
    count = 1
    while hoge:
        hoge = func(hoge)
        count += 1
    ans.append(count)
    bO = (bO*2)%(popcount+1)
    if popcount != 1:
        bI = (bI*2)%(popcount-1)

for i in range(N):
    print(ans[-1-i])
Buggy python submission (verdict: Runtime Error):
N = int(input())
S = list(input() for _ in range(N))
X = []
for s in S:
    l,r = 0,0
    for c in s:
        if c == ")":
            if r > 0:
                r -= 1
            else:
                l += 1
        else:
            r += 1
    X.append([l,r])
X.sort(key = lambda x:(x[0],-x[1]))
Y = 0
for a,b in X:
    if a > Y:
        print(1/0)
        quit()
    Y -= a
    Y += b

if Y:
    print(1/0)
else:
    print("Yes")     

Fixed submission:
N = int(input())
S = list(input() for _ in range(N))
X = []
for s in S:
    l,r = 0,0
    for c in s:
        if c == ")":
            if r > 0:
                r -= 1
            else:
                l += 1
        else:
            r += 1
    X.append([l,r])
X.sort(key = lambda x:x[0])
Y = []
L = 0
for p,q in X:
    if p > L:
        print("No")
        quit()
    if q >= p:
        L -= p
        L += q
    else:
        Y.append([p,q])
Y.sort(key = lambda x:-x[1])
for a,b in Y:
    if a > L:
        print("No")
        quit()
    L -= a
    L += b
if L:
    print("No")
else:
    print("Yes")
Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**9)

N = int(input())
A = list(map(int,input()))

while len(A) > 1:
    if len(A) % 2 == 1:
        for i in range(len(A)-1):
            A[i] = abs(A[i]-A[i+1])
        A.pop()
    B = []
    for i in range(len(A)//2):
        B.append(abs(A[i*2]-A[i*2+1]))
    A = B[:]
if A[0] == 2:
    print(1/0)
print(A[0])


Fixed submission:
import sys
sys.setrecursionlimit(10**9)

N = int(input())
A = list(map(int,input()))
X = 2 in A

while len(A) > 1:
    if len(A) % 2 == 1:
        for i in range(len(A)-1):
            A[i] = abs(A[i]-A[i+1])
        A.pop()
    B = []
    for i in range(len(A)//2):
        B.append(abs(A[i*2]-A[i*2+1]))
    A = B[:]

if X:
    A[0] %= 2
print(A[0])
Buggy python submission (verdict: Runtime Error):
class uni:
    def __init__(self,n):
        self.n = n
        self.pare = [i for i in range(n)]

    def find(self,x):
        if self.pare[x] == x:
            return x
        else:
            self.pare[x] = self.find(self.pare[x])
            return self.pare[x]

    def union(self,x,y):
        x = self.find(x)
        y = self.find(y)
        self.pare[x] = y

    def show(self):
        return self.pare


N, M, K = map(int,input().split())
size = [0]*N
count = [0]*N
side = [[]for i in range(N)]
union = uni(N)
for i in range(M):
    a,b = map(int,input().split())
    union.union(a-1,b-1)
    count[a-1] += 1
    count[b-1] += 1
for i in range(N):
    size[union.find(i)] += 1
for i in range(K):
    c,d = map(int,input().split())
    if union.pare[c-1] == union.pare[d-1]:
        count[c-1] += 1
        count[d-1] += 1
for i in range(N):
    print(size[union.pare[i]]-count[i]-1,end=" ")
print()

Fixed submission:
class uni:
    def __init__(self,n):
        self.n = n
        self.pare = [i for i in range(n)]
        self.rank = [0]*n

    def find(self,x):
        if self.pare[x] == x:
            return x
        else:
            self.pare[x] = self.find(self.pare[x])
            return self.pare[x]

    def union(self,x,y):
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.pare[x] = y
        else:
            self.pare[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    def show(self):
        return self.pare


N, M, K = map(int,input().split())
size = [0]*N
count = [0]*N
side = [[]for i in range(N)]
union = uni(N)
for i in range(M):
    a,b = map(int,input().split())
    union.union(a-1,b-1)
    count[a-1] += 1
    count[b-1] += 1
for i in range(N):
    size[union.find(i)] += 1
for i in range(K):
    c,d = map(int,input().split())
    if union.pare[c-1] == union.pare[d-1]:
        count[c-1] += 1
        count[d-1] += 1
for i in range(N):
    print(size[union.pare[i]]-count[i]-1,end=" ")
print()
Buggy python submission (verdict: Runtime Error):
MOD = 10**9+7
r1,c1,r2,c2 = map(int,input().split())

size = 101000*2
f_list = [1]*(size)
for i in range(1,size):
    f_list[i] = (f_list[i-1]*i)%MOD

def func(r,c):
    return (f_list[r+c]*pow(f_list[r],MOD-2,MOD)*pow(f_list[c],MOD-2,MOD))

ans = func(r2+1,c2+1)-1
ans += func(r1,c1)-1
ans -= func(r2+1,c1)-1
ans -= func(r1,c2+1)-1
print(ans%MOD)



Fixed submission:
MOD = 10**9+7
r1,c1,r2,c2 = map(int,input().split())

size = 1010000*2
f_list = [1]*(size)
for i in range(1,size):
    f_list[i] = (f_list[i-1]*i)%MOD

def func(r,c):
    return (f_list[r+c]*pow(f_list[r],MOD-2,MOD)*pow(f_list[c],MOD-2,MOD))

ans = func(r2+1,c2+1)-1
ans += func(r1,c1)-1
ans -= func(r2+1,c1)-1
ans -= func(r1,c2+1)-1
print(ans%MOD)

Buggy python submission (verdict: Time Limit Exceeded):
MOD = 10**9+7
list_size = (10**6+10)*4

f_list = [1]*list_size
f_r_list = [1]*list_size

for i in range(list_size - 1):
    f_list[i+1] = ((f_list[i] * (i+2)) % MOD)

f_r_list[-1] = pow(f_list[-1], MOD - 2, MOD)

for i in range(-2, -list_size-1, -1):
    f_r_list[i] = ((f_r_list[i+1] * (list_size + 2 + i)) % MOD)



r1,c1,r2,c2 = map(int,input().split())

ans = f_list[(r2+c2)*2]*f_r_list[r2*2]*f_r_list[c2*2]
ans %= MOD
ans += f_list[(r1+c1)*2]*f_r_list[r1*2]*f_r_list[c1*2]
ans %= MOD
ans -= f_list[(r2+c1)*2]*f_r_list[r2*2]*f_r_list[c1*2]
ans %= MOD
ans -= f_list[(c2+r1)*2]*f_r_list[c2*2]*f_r_list[r1*2]
ans %= MOD

print(ans)




Fixed submission:
MOD = 10**9+7
r1,c1,r2,c2 = map(int,input().split())

size = 1010000*2
f_list = [1]*(size)
for i in range(1,size):
    f_list[i] = (f_list[i-1]*i)%MOD

def func(r,c):
    return (f_list[r+c]*pow(f_list[r],MOD-2,MOD)*pow(f_list[c],MOD-2,MOD))

ans = func(r2+1,c2+1)-1
ans += func(r1,c1)-1
ans -= func(r2+1,c1)-1
ans -= func(r1,c2+1)-1
print(ans%MOD)

Buggy python submission (verdict: Time Limit Exceeded):
MOD = 10**9+7
list_size = (10**6+10)*4

f_list = [1]*list_size
f_r_list = [1]*list_size

for i in range(list_size - 1):
    f_list[i+1] = ((f_list[i] * (i+2)) % MOD)

f_r_list[-1] = pow(f_list[-1], MOD - 2, MOD)

for i in range(-2, -list_size-1, -1):
    f_r_list[i] = ((f_r_list[i+1] * (list_size + 2 + i)) % MOD)



r1,c1,r2,c2 = map(int,input().split())

ans = f_list[(r2+c2)*2]*f_r_list[r2*2]*f_r_list[c2*2]
ans %= MOD
ans += f_list[(r1+c1-2)*2]*f_r_list[r1*2-2]*f_r_list[c1*2-2]
ans %= MOD
ans -= f_list[(r2+c1)*2]*f_r_list[r2*2]*f_r_list[c1*2]
ans %= MOD
ans -= f_list[(c2+r1)*2]*f_r_list[c2*2]*f_r_list[r1*2]
ans %= MOD

print(ans)




Fixed submission:
MOD = 10**9+7
r1,c1,r2,c2 = map(int,input().split())

size = 1010000*2
f_list = [1]*(size)
for i in range(1,size):
    f_list[i] = (f_list[i-1]*i)%MOD

def func(r,c):
    return (f_list[r+c]*pow(f_list[r],MOD-2,MOD)*pow(f_list[c],MOD-2,MOD))

ans = func(r2+1,c2+1)-1
ans += func(r1,c1)-1
ans -= func(r2+1,c1)-1
ans -= func(r1,c2+1)-1
print(ans%MOD)
Buggy python submission (verdict: Runtime Error):
H,N = map(int,input().split())
magic = list(list(map(int,input().split()))for i in range(N))

DP = [10**9]*(H+1)
DP[0] = 0
for a,b in magic:
    for i in range(a):
        DP[i] = min(DP[i],b)
    for i in range(a,H+1):
        DP[i] = min(DP[i],DP[i-a]+b)
print(DP[-1])
 

Fixed submission:
H,N = map(int,input().split())
magic = list(list(map(int,input().split()))for i in range(N))

DP = [10**9]*(H+1)
DP[0] = 0
for a,b in magic:
    for i in range(min(a,H+1)):
        DP[i] = min(DP[i],b)
    for i in range(a,H+1):
        DP[i] = min(DP[i],DP[i-a]+b)
print(DP[-1])

Buggy python submission (verdict: Runtime Error):
H,N = map(int,input().split())
magic = list(list(map(int,input().split()))for i in range(N))

DP = [10**9]*(H+1)
DP[0] = 0
for a,b in magic:
    for i in range(a):
        DP[i] = min(DP[i],b)
    for i in range(b,H+1):
        DP[i] = min(DP[i],DP[i-a]+b)
print(DP[-1])
 

Fixed submission:
H,N = map(int,input().split())
magic = list(list(map(int,input().split()))for i in range(N))

DP = [10**9]*(H+1)
DP[0] = 0
for a,b in magic:
    for i in range(min(a,H+1)):
        DP[i] = min(DP[i],b)
    for i in range(a,H+1):
        DP[i] = min(DP[i],DP[i-a]+b)
print(DP[-1])
Buggy python submission (verdict: Time Limit Exceeded):
import bisect, math
N,D,A = map(int,input().split())
enemy = list(list(map(int,input().split()))for i in range(N))
enemy.sort()

damege = [0]*N

ans = 0
p = 0
while p < N:
    if p>=1:
        damege[p] += damege[p-1]
    enemy[p][1] -= damege[p]
    if enemy[p][1] <= 0:
        p += 1 
        continue
    d = math.ceil(enemy[p][1]/A)
    ans += d
    d *= A
    r = bisect.bisect_right(enemy,[enemy[p][0]+D*2,10**9+7])
    if r!=N:
        damege[r]-=d
    damege[p] += d
    p+=1
print(ans)



Fixed submission:
import bisect, math
N,D,A = map(int,input().split())
enemy = list(list(map(int,input().split()))for i in range(N))
enemy.sort()

damege = [0]*N

ans = 0
p = 0
while p < N:
    if p>=1:
        damege[p] += damege[p-1]
    enemy[p][1] -= damege[p]
    if enemy[p][1] <= 0:
        p += 1 
        continue
    d = math.ceil(enemy[p][1]/A)
    ans += d
    d *= A
    r = bisect.bisect_right(enemy,[enemy[p][0]+D*2,10**9+7])
    if r!=N:
        damege[r]-=d
    damege[p] += d
    p+=1
print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
ans = 10**9+7
for i in range(2**N):
    card = [[],[]]
    num = []
    x = i
    for j in range(N):
        if i&1:
            num.append(B[j])
            card[(j+1)%2].append(j)
        else:
            num.append(A[j])
            card[(j)%2].append(j)
        i >>= 1
    if len(card[1]) != N//2:
        continue
    card[0].sort(key=lambda x:[num[x],x]);card[1].sort(key=lambda x:[num[x],x])
    hoge = []
    for i in range(N):
        hoge.append(card[i%2][i//2])
    flag = True
    for i in range(N-1):
        if num[hoge[i]] > num[hoge[i+1]]:
            flag = False
    if flag:
        huga = sum(abs(hoge[i]-i)for i in range(N))
        if huga % 2:
            print(1/0)
        else:
            huge //= 2
        if huga < ans:
            ans = huga
if ans >= 10**9:
    print(-1)
else:
    print(ans)

Fixed submission:
import bisect
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
ans = 10**9+7
for i in range(2**N):
    card = [[],[]]
    num = []
    iii = i
    for j in range(N):
        if i&1:
            num.append(B[j])
            card[(j+1)%2].append(j)
        else:
            num.append(A[j])
            card[(j)%2].append(j)
        i >>= 1
    if len(card[1]) != N//2:
        continue
    card[0].sort(key=lambda x:[num[x],x])
    card[1].sort(key=lambda x:[num[x],x])
    hoge = []
    for i in range(N):
        hoge.append(card[i%2][i//2])
    flag = True
    for i in range(N-1):
        if num[hoge[i]] > num[hoge[i+1]]:
            flag = False
    if flag:
        huga = []
        count = 0
        for i in range(N):
            l = bisect.bisect_left(huga,hoge[i])
            huga.insert(l,hoge[i])
            count += i-l
        if count < ans:
            ans = count
if ans >= 10**9:
    print(-1)
else:
    print(ans)
Buggy python submission (verdict: Runtime Error):
_,A = input(),list(map(int,input().split()))
for i in A:
  if i%2 == 1:
    print(2/0)
print("unrated")

Fixed submission:
def GCD(x,y):
    if y==0:
        return x
    return GCD(y,x%y)
def LCM(x,y):
    return x*y // GCD(x,y)
N, M = map(int,input().split())
A = list(map(int,input().split()))
ans = 1
for i in A:
    i //= 2
    ans = LCM(ans,i)
    if (ans//i)%2 == 0:
        print(0)
        exit()
    if ans > M:
        print(0)
        exit()
print(M//ans-M//(ans*2))

Buggy python submission (verdict: Runtime Error):
def GCD(x,y):
    if y==0:
        return x
    return GCD(y,x%y)


N, M = map(int,input().split())
A = list(map(int,input().split()))
ans = 1
for i in A:
    ans = (ans*(i//2))//GCD(ans,i)
    if ans%2 == 0:
        ans = 0
print(M//ans-M//(ans*2))

Fixed submission:
def GCD(x,y):
    if y==0:
        return x
    return GCD(y,x%y)
def LCM(x,y):
    return x*y // GCD(x,y)
N, M = map(int,input().split())
A = list(map(int,input().split()))
ans = 1
for i in A:
    i //= 2
    ans = LCM(ans,i)
    if (ans//i)%2 == 0:
        print(0)
        exit()
    if ans > M:
        print(0)
        exit()
print(M//ans-M//(ans*2))
Buggy python submission (verdict: Time Limit Exceeded):
MOD = 10**9+7

N = int(input())
A = list(map(int,input().split()))
X = [0]*60
sumA = 0
for i in A:
    for j in range(60):
        if i >> j & 1 == 1:
            X[j] += 1
    sumA += i
ans = 0
for i in range(N):
    sumA -= A[i]
    ans += sumA
    for j in range(60):
        if A[i] >> j & 1 == 1:
            X[j] -= 1
            ans += ((2**j) * (N-i-1-X[j]*2))%MOD
    ans %= MOD

print(ans)

Fixed submission:
MOD = 10**9+7

N = int(input())
A = list(map(int,input().split()))
X = [0]*60
sumA = 0
for i in A:
    for j in range(60):
        if i >> j & 1 == 1:
            X[j] += 1
    sumA += i
ans = 0
for i in range(N):
    sumA -= A[i]
    ans += sumA
    for j in range(60):
        if A[i] >> j & 1 == 1:
            X[j] -= 1
            ans += ((2**j) * (N-i-1-X[j]*2))%MOD
    ans %= MOD

print(ans)
Buggy python submission (verdict: Runtime Error):
MOD = 10**9+7

N = int(input())
A = list(map(int,input().split()))
MOD = 10**9+7
RGB = [0]*3
ans = 1
for i in A:
    count = 0
    for j in RGB:
        if i == j:
            count += 1
    RGB[RGB.index(i)] += 1
    ans = (ans * count)% MOD

print(ans)


Fixed submission:
MOD = 10**9+7

N = int(input())
A = list(map(int,input().split()))
MOD = 10**9+7
RGB = [0]*3
ans = 1
for i in A:
    count = 0
    for j in RGB:
        if i == j:
            count += 1
    if count == 0:
        print(0)
        exit()
    RGB[RGB.index(i)] += 1
    ans = (ans * count)% MOD

print(ans)
Buggy python submission (verdict: Runtime Error):
T = list(map(int,input().split()))
A = list(map(int,input().split()))
B = list(map(int,input().split()))
x = (A[0]-B[0])*T[0]
y = (B[0]-A[0])*T[0] + (B[1]-A[1])*T[1]

if x < 0:
    x *= -1
    y *= -1
if y == 0:
    print('infinity')
ans = -(-x//y)*2-1
if x%y == 0:
    ans -= 1
print(ans)

Fixed submission:
T1, T2 = map(int,input().split())
A1, A2 = map(int,input().split())
B1, B2 = map(int,input().split())

A1 *= T1
B1 *= T1
A2 *= T2
B2 *= T2

if A1+A2 > B1+B2: # Aを遅く
    A1,B1 ,A2,B2 = B1,A1 ,B2,A2

if A1+A2 == B1+B2:
    print("infinity")
    exit()

if A1 < B1:
    print(0)
    exit()

def nibu(l,r):
    if l >= r:
        return l
    c = (l+r+1)//2
    if (A1+A2)*(c-1)+A1 >= (B1+B2)*(c-1)+B1:
        return nibu(c,r)
    else:
        return(nibu(l,c-1))

ans = nibu(0,10**100)
if (A1+A2)*(ans-1)+A1 == (B1+B2)*(ans-1)+B1:
    print(ans*2-2)
else:
    print(ans*2-1)

Buggy python submission (verdict: Runtime Error):
import math
T = list(map(int,input().split()))
A = list(map(int,input().split()))
B = list(map(int,input().split()))
x = (A[0]-B[0])*T[0]
y = (B[0]-A[0])*T[0] + (B[1]-A[1])*T[1]

if x < 0:
    x *= -1
    y *= -1

ans = -(-x//y)*2-1
if x%y == 0:
    ans -= 1
print(ans)

Fixed submission:
T1, T2 = map(int,input().split())
A1, A2 = map(int,input().split())
B1, B2 = map(int,input().split())

A1 *= T1
B1 *= T1
A2 *= T2
B2 *= T2

if A1+A2 > B1+B2: # Aを遅く
    A1,B1 ,A2,B2 = B1,A1 ,B2,A2

if A1+A2 == B1+B2:
    print("infinity")
    exit()

if A1 < B1:
    print(0)
    exit()

def nibu(l,r):
    if l >= r:
        return l
    c = (l+r+1)//2
    if (A1+A2)*(c-1)+A1 >= (B1+B2)*(c-1)+B1:
        return nibu(c,r)
    else:
        return(nibu(l,c-1))

ans = nibu(0,10**100)
if (A1+A2)*(ans-1)+A1 == (B1+B2)*(ans-1)+B1:
    print(ans*2-2)
else:
    print(ans*2-1)
Buggy python submission (verdict: Time Limit Exceeded):
M = int(input())
ans = 0
hoge = 0
for _ in range(M):
    d,c = map(int,input().split())
    while c:
        if c % 2 == 1:
            hoge += d
            ans += 1
            if hoge > 9:
                hoge = (hoge%10)+1
                ans += 1
        c //= 2
        ans += c
        d = d*2
        if d > 9:
            ans += c
            d = d%10+1

print(ans-1)

Fixed submission:
M = int(input())
ans = 0
hoge = 0
for _ in range(M):
    d,c = map(int,input().split())
    while c:
        if c % 2 == 1:
            hoge += d
            ans += 1
            if hoge > 9:
                hoge = (hoge%10)+1
                ans += 1
        c //= 2
        ans += c
        d = d*2
        if d > 9:
            ans += c
            d = d%10+1

print(ans-1)
Buggy python submission (verdict: Runtime Error):
MOD = 998244353
N = int(input())
D = list(map(int,input().split()))
ans = [0]*N
for i in D:
    ans[i] += 1
ret = 1
for i in range(1,max(D)+1):
    ret *= pow(ans[i-1],ans[i],MOD)
    ret %= MOD
if ans[0] == 1:
    print(ret)
else:
    print(1/0)

Fixed submission:
MOD = 998244353
N = int(input())
D = list(map(int,input().split()))
ans = [0]*N
for i in D:
    ans[i] += 1
ret = 1
for i in range(1,max(D)+1):
    ret *= (ans[i-1] ** ans[i])%MOD
    ret %= MOD
if ans[0] == 1 and D[0] == 0:
    print(ret)
else:
    print(0)
Buggy python submission (verdict: Runtime Error):
N, K = map(int,input().split())
if (2*N)*(K+ K+2*N-1) > N*(K+2*N + K+3*N-1):
    print(-1)
else:
    print(1/0)

Fixed submission:
import math
N, K = map(int,input().split())
if (2*N)*(K+ K+2*N-1) > N*(K+2*N + K+3*N-1):
    print(-1)
    exit()
flag = [1]*(2*N)
for i in range(math.floor(N/2),N):
    a = K + i
    b = K + 2*N -1 -(i-math.floor(N/2))*2
    c = K + 3*N -1 -(i-math.floor(N/2))
    print(a,b,c)
for i in range(math.floor(N/2)):
    a = K + i
    b = K + 2*N -2 -i*2
    c = K + 3*N -1 -i-math.ceil(N/2)
    print(a,b,c)

Buggy python submission (verdict: Runtime Error):
N, K = map(int,input().split())2
if (2*N)*(K+ K+2*N-1) > N*(K+2*N + K+3*N-1):
    print(-1)
else:
    print(1/0)

Fixed submission:
import math
N, K = map(int,input().split())
if (2*N)*(K+ K+2*N-1) > N*(K+2*N + K+3*N-1):
    print(-1)
    exit()
flag = [1]*(2*N)
for i in range(math.floor(N/2),N):
    a = K + i
    b = K + 2*N -1 -(i-math.floor(N/2))*2
    c = K + 3*N -1 -(i-math.floor(N/2))
    print(a,b,c)
for i in range(math.floor(N/2)):
    a = K + i
    b = K + 2*N -2 -i*2
    c = K + 3*N -1 -i-math.ceil(N/2)
    print(a,b,c)
Buggy python submission (verdict: Runtime Error):
import math

a,b,x = map(int,input().split())

if x <= a*a*b/2:
    S = x/a
    f = 2*S/b
    print(math.degrees(math.atan(b/f)))
else:
    S = a*b- x/a
    f = 2*S/a
    print(90-math.degrees(math.atan(a/f)))

Fixed submission:
import math

a,b,x = map(int,input().split())

if x == a**2 * b:
    print(0)
    exit()

if x <= a*a*b/2:
    S = x/a
    f = 2*S/b
    print(math.degrees(math.atan(b/f)))
else:
    S = a*b- x/a
    f = 2*S/a
    print(90-math.degrees(math.atan(a/f)))
Buggy python submission (verdict: Time Limit Exceeded):
import bisect
N = int(input())
L = list(map(int,input().split()))
ans = (N*(N-1)*(N-2))//6
L.sort()
for i in range(N-1,-1,-1):
    for j in range(i-1,-1,-1):
        ans -= bisect.bisect_right(L[:j],L[i]-L[j])
print(ans)



Fixed submission:
import bisect
N = int(input())
L = list(map(int,input().split()))
ans = (N*(N-1)*(N-2))//6
L.sort()
for i in range(N-1,-1,-1):
    for j in range(i-1,-1,-1):
        ans -= bisect.bisect_right(L[:j],L[i]-L[j])
print(ans)
Buggy python submission (verdict: Runtime Error):
S = list(input())
K = int(input())
R = []
hoge = 1
for i in range(1,len(S)):
    if S[i] == S[i-1]:
        hoge += 1
    else:
        R.append(S)
        hoge = 1
R.append(hoge)
ans = 0
if len(R) == 1:
    print((R[0]*K)//2)
    exit()
if S[0] == S[-1]:
    ans += (K-1)*((R[0]+R[-1])//2) + R[0]//2 + R[-1]//2
    R[0],R[-1] = 0,0
for i in R:
    ans += (i//2)*K 
print(ans)

Fixed submission:
S = list(input())
K = int(input())
R = []
hoge = 1
for i in range(1,len(S)):
    if S[i] == S[i-1]:
        hoge += 1
    else:
        R.append(hoge)
        hoge = 1
R.append(hoge)
ans = 0
if len(R) == 1:
    print((R[0]*K)//2)
    exit()
if S[0] == S[-1]:
    ans += (K-1)*((R[0]+R[-1])//2) + R[0]//2 + R[-1]//2
    R[0],R[-1] = 0,0
for i in R:
    ans += (i//2)*K 
print(ans)