Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p02856 (python)

Fixed submission:
#繰り上がりごとに各桁の総和は9減る
#9*最初の桁数+最初の総和がそれで減る
#それは順番によらない

m = int(input())
sm=  0
d = []
c = []
for i in range(m):
    di,ci = map(int, input().split( ))
    d.append(di)
    c.append(ci)
    sm += di*ci

x = sum(c)*9 + sm
y =  x%9
if y==0:
    y = 9
    
print((x-y)//9-1)

Buggy submission (verdict: Runtime Error):
#順番考えなくていいかとりあえず試す
m = int(input())
nm = [(0,0)]
for i in range(m):
    di,ci = map(int, input().split( ))
    nm.append((di,ci))
cnt = 0
tmp = 0
while nm:
    ci,di = nm.pop()
    if di>100:
        tmpy = 1
        tmpz = 1
        tmpx = ci*2
        if tmpx>=10:
            tmpx = str(tmpx)
            tmp2 = int(tmpx[0])+int(tmpx[1])
            tmpy += 1
        while tmpx != ci:
            tmpx += ci
            tmpy +=1
            tmpz +=1
            if tmpx>=10:
                tmpx = str(tmpx)
                tmp2 = int(tmpx[0])+int(tmpx[1])
                tmpy += 1
        cnt += tmpz*(di//tmpy)
        di -= (di//tmpy)*tmpy

    while di:
        cnt += 1
        #print(di,cnt)
        tmp += ci
        di-=1
        if tmp>=10:
            tmp = str(tmp)
            tmp2 = int(tmp[0])+int(tmp[1])
            cnt += 1
            #print(di,cnt)
            tmp = tmp2
print(cnt-1)

Buggy submission (verdict: Runtime Error):
#順番考えなくていいかとりあえず試す
m = int(input())
nm = []
for i in range(m):
    di,ci = map(int, input().split( ))
    nm.append((di,ci))
cnt = 0
tmp = 0
while nm:
    ci,di = nm.pop()
    if di>100:
        tmpy = 1
        tmpz = 1
        tmpx = ci*2
        if tmpx>=10:
            tmpx = str(tmpx)
            tmp2 = int(tmpx[0])+int(tmpx[1])
            tmpy += 1
        while tmpx != ci:
            tmpx += ci
            tmpy +=1
            tmpz +=1
            if tmpx>=10:
                tmpx = str(tmpx)
                tmp2 = int(tmpx[0])+int(tmpx[1])
                tmpy += 1
        cnt += tmpz*(di//tmpy)
        di -= (di//tmpy)*tmpy

    while di:
        cnt += 1
        #print(di,cnt)
        tmp += ci
        di-=1
        if tmp>=10:
            tmp = str(tmp)
            tmp2 = int(tmp[0])+int(tmp[1])
            cnt += 1
            #print(di,cnt)
            tmp = tmp2
print(cnt-1)

Buggy submission (verdict: Runtime Error):
#順番考えなくていいかとりあえず試す
m = int(input())
nm = []
for i in range(m):
    di,ci = map(int, input().split( ))
    nm.append((di,ci))
cnt = 0
tmp = 0
while nm:
    ci,di = nm.pop()
    if di>100:
        tmpy = 1
        tmpz = 1
        tmpx = ci*2
        if tmpx>=10:
            tmpx = str(tmpx)
            tmp2 = int(tmpx[0])+int(tmpx[1])
            tmpy += 1
        while tmpx != ci:
            tmpx += ci
            tmpy +=1
            tmpz +=1
            if tmpx>=10:
                tmpx = str(tmpx)
                tmp2 = int(tmpx[0])+int(tmpx[1])
                tmpy += 1
        tmp += tmpz*(di//tmpy)
        di -= (di//tmpy)*tmpy

    while di:
        cnt += 1
        #print(di,cnt)
        tmp += ci
        di-=1
        if tmp>=10:
            tmp = str(tmp)
            tmp2 = int(tmp[0])+int(tmp[1])
            cnt += 1
            #print(di,cnt)
            tmp = tmp2
print(cnt-1)
Problem p02866 (python)

Fixed submission:
import sys

n = int(input())
d = list(map(int, input().split( )))

if d[0]!= 0:
    print(0)
    sys.exit()

d.sort()
if n >=2:
    if d[1] == 0:
        print(0)
        sys.exit()

for i in range(n-1):
    if d[i]>d[i+1] or d[i]+1<d[i]:
        print(0)
        sys.exit()

m = max(d)

cnt = {i:0 for i in range(1,m+1)}

for i in range(1,n):
    cnt[d[i]] += 1
mod = 998244353

ans = 1

for i in range(2,m+1):
    ans *= pow(cnt[i-1],cnt[i],mod)
    ans %=mod

print(ans)

Buggy submission (verdict: Runtime Error):
import sys

n = int(input())
d = list(map(int, input().split( )))

if d[0]!=0:
    print(0)
    sys.exit()

d.sort()

for i in range(n-1):
    if d[i]>d[i+1] or d[i]+1<d[i]:
        print(0)
        sys.exit()

m = max(d)

cnt = {i:0 for i in range(1,m+1)}

for i in range(1,n):
    cnt[d[i]] += 1

mod = 998244353
 
ans = 1

for i in range(2,m+1):
    ans *= pow(cnt[i-1],cnt[i],mod)
    ans %=mod 

print(ans)
Problem p02889 (python)

Fixed submission:
#何とか法, AOJのgrl1c
#初め満杯
import sys
input = sys.stdin.readline
#print = sys.stdout.write

n,m,l =map(int, input().split( ))
Edge = [[] for _ in range(n)]

for i in range(m):
    a,b,c = map(int, input().split( ))
    Edge[a-1].append([b-1,c])
    Edge[b-1].append([a-1,c])

dp = [[10**10 for _ in range(n)] for __ in range(n)]

for i in range(n):
    for ed in Edge[i]:
        dp[i][ed[0]] = ed[1]

for i in range(n):
    dp[i][i] = 0

for k in range(n):
    for j in range(n):
        for i in range(n):
            dp[i][j] = min(dp[i][j],dp[i][k] + dp[k][j])

"""
以下が要点
"""
dp2 = [[10**8 for _ in range(n)] for __ in range(n)]
for j in range(n):
    for i in range(j):
        if dp[i][j] <=l:
            dp2[i][j] = 1
            dp2[j][i] = 1
for i in range(n):
    dp2[i][i] = 1
    
for k in range(n):
    for j in range(n):
        for i in range(n):
            dp2[i][j] = min(dp2[i][j],dp2[i][k] + dp2[k][j])
"""
以上
"""
q = int(input())
ans = []
for i in range(q):
    s,t = map(int, input().split( ))
    if dp2[s-1][t-1] >10**6:###
        print(-1)
    else:
        print(dp2[s-1][t-1]-1)
#print(dp)
#print(*ans)

Buggy submission (verdict: Runtime Error):
#何とか法, AOJのgrl1c
#初め満杯
import sys
input = sys.stdin.readline
#print = sys.stdout.write

n,m,l =map(int, input().split( ))
Edge = [[] for _ in range(n)]

for i in range(m):
    a,b,c = map(int, input().split( ))
    Edge[a-1].append([b-1,c])
    Edge[b-1].append([a-1,c])

dp = [[10**10 for _ in range(n)] for __ in range(n)]

for i in range(n):
    for ed in Edge[i]:
        dp[i][ed[0]] = ed[1]

for i in range(n):
    dp[i][i] = 0

for k in range(n):
    for j in range(n):
        for i in range(n):
            dp[i][j] = min(dp[i][j],dp[i][k] + dp[k][j])

"""
以下が要点
"""
dp2 = [[10**8 for _ in range(n)] for __ in range(n)]
for j in range(n):
    for i in range(j+1):###
        if dp[i][j] <=l:
            dp2[i][j] = 1
            dp2[j][i] = 1
for k in range(n):
    for j in range(n):
        for i in range(n):
            dp[i][j] = min(dp[i][j],dp[i][k] + dp[k][j])
"""
以上
"""
q = int(input())
ans = []
for i in range(q):
    s,t = map(int, input().split( ))
    if dp[s-1][t-1] >10**10:###
        print(-1)
    else:
        print(dp[s-1][t-1][0])
#print(dp)
#print(*ans)
Problem p02900 (python)

Fixed submission:
import fractions
a, b = map(int, input().split())
 
c =fractions.gcd(a,b)
c2 = c
F = []
while c2%2==0:
    c2 //= 2
if c2<c:
    F.append(2)
f = 3
while f*f<c2:
    while c2 %f ==0:
        c2//=f 
        if F:
            if F[-1]<f:
                F.append(f)
        else:
            F.append(f)
    f += 2
if c2>1:
    F.append(f)
print(len(F)+1)

Buggy submission (verdict: Runtime Error):
import fractions
a, b = map(int, input().split())

c =fractions.gcd(a,b)
c2 = c
F = []
while c2%2==0:
    c2 //= 2
if c2<c:
    F.append(2)
f = 3
while f*f<=c2:
    while c2 %f ==0:
        c2//=f 
        if F[-1]<f:
            F.append(f)
    f += 2
if c2 !=1:
  F.append(c2)
#print(F)
print(len(F)+1)
Problem p02918 (python)

Fixed submission:
#import sys
n,k = map(int, input().split( ))

s = input()

#if n ==1:
#    print(0)
#    sys.exit()

ans = n-1
tmp = 0
for i in range(n-1):
    if s[i] != s[i+1]:
        ans -= 1
        
ans += 2*k
print(min(ans,n-1))

Buggy submission (verdict: Runtime Error):
n,k = map(int, input().split( ))

s = input()

if n ==1:
    print(0)
    sys.exit()

ans = n-1
tmp = 0
for i in range(n-1):
    if s[i] != s[i+1]:
        ans -= 1
        
ans += 2*k
print(min(ans,n-1))
Problem p02920 (python)

Fixed submission:
import sys
n = int(input())
s = list(map(int, sys.stdin.readline().split()))

s.sort()#popするのでreverseしない
#print(s)
P = [s[-1]]
P_next = []

Rem = s[:-1]
Rem_next = []
for _ in range(n):
    while P:
        p = P.pop()
        P_next.append(p)
        while Rem:
            r = Rem.pop()
            if p>r:
                P_next.append(r)
                break
            Rem_next.append(r)
        """
        while p == Rem[-1]:
            r = Rem.pop()
            Rem_next.append(r)
        if Rem:
            P_next.append(Rem.pop())
        """
    P = P_next
    P_next = []
    Rem += Rem_next
    Rem_next = []
    #不自然な置き換えに見えるがlistからremoveするよりはマシか
    P.sort()
    Rem.sort()
if len(P) == 2**n:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
from math import log2
import sys
n = int(input())
s =list(map(int, input().split()))
s.sort()
s.reverse()
flag = 0
if s[0] ==s[1]:
    print("No")
    sys.exit()
for i in range(2,2**n):
    ind = int(log2(i))
    if s[i-2**ind]==s[i]:
        flag =1
        break
if flag == 0:
    print("Yes")
else:
    print("No")
Problem p02926 (python)

Fixed submission:
import math

n = int(input())
P = []
#very small でWAなので、rで割ってかけ直すのをやめてみる
#atanを使ってみる
#0またいだときがおかしいか
for i in range(n):
    x, y = map(int, input().split( ))
    rad = math.atan2(x, y)
    P.append([rad, x, y])

P.sort()
P = P + P 


x0 = 0
y0 = 0

mx = 0

for i in range(n):
    vx = 0
    vy = 0
    for j in range(n):
        vx += P[i+j][1]
        vy += P[i+j][2]
        v = vx**2 + vy**2
        mx = max(v,mx)
print(math.sqrt(mx))

Buggy submission (verdict: Runtime Error):
import math

n = int(input())
P = []
#very small でWAなので、rで割ってかけ直すのをやめてみる
#atanを使ってみる
#0またいだときがおかしいか
for i in range(n):
    x, y = map(int, input().split( ))
    rad = math.atan2(x, y)
    P.append([rad, x, y])

P.sort()
P = P + P 


x0 = 0
y0 = 0

mx = 0

for i in range(n):
    vx = 0
    vy = 0
    for j in range(n):
        vx += P[i+j][1]
        vy += P[i+j][2]
    	v = vx**2 + vy**2
    	mx = max(v,mx)
print(math.sqrt(mx))
Problem p02939 (python)

Fixed submission:
import sys
S=input()
K=1

if len(S)==1:
    print(K)
    sys.exit
elif len(S)==2:
    if S[0]==S[1]:
        print(1)
        sys.exit
    else:
        print(2)
        sys.exit
else:
    pass
l=len(S)

S1=[]
S2=[]

S1.append(1)
if S[0]!=S[1]:
    S1.append(2)
else:
    S1.append(1)
S2.append(0)
S2.append(1)
for i in range(2,l):
    if S[i]!=S[i-1]:
        S1.append(max(S1[i-1]+1,S2[i-1]+1))
    else:
        S1.append(S2[i-1]+1)
    try:
        if S2[i]==S2[i-2] and S2[i-1]==S2[i-3]:
            S2.append(S1[i-2]+1)
    except:
        S2.append(max(S1[i-2]+1,S2[i-2]+1))

print(max(S2[l-1],S1[l-1]))

Buggy submission (verdict: Runtime Error):
import sys
n,k = map(int,input().split( ))
s = input()
r0 = list(reversed(s))
r = ''.join(r0)
s = s + r
l = len(s)
S = [s[i] for i in range(l)]

literal=list(set(S))
literal.sort()

small = literal[0]

i=0
mx=0
cnt = 0
now=-1
cnd=[]
while i<l:
    if s[i] == small:
        now = i
        cnt = 1
        i += 1
        try:
            while s[i] == small:
                cnt += 1
                i += 1
            if mx < cnt:
                cnd = []
                cnd.append(now)
                now == i
                mx = cnt
            elif mx == cnt:
                cnd.append(now)
                now = i
            else:
                now = i
        except:
            pass
    i += 1
if mx*2**k>=n:
    print(small*2**k)
    sys.exit
else:
    pass
cnd_string = []
addi = n - 2**k


for i in cnd:
    cnd_string.append(s[i + mx : i + mx + addi])
cnd_string.sort()
for t in cnd_string:
    if len(t) < addi:
        cnd_string.remove(t)
print(small*2**k + cnd_string[0])

Buggy submission (verdict: Runtime Error):
n=int(input())
A=list(map(int,input().split( )))
B=list(map(int,input().split( )))
count=0
flag=True
while flag:
    flag=False
    for i in range(-1,n-1):
        tonari=B[i-1]+B[i+1]
        tmp=(B[i]-A[i])//tonari
        if tmp>0:
            B[i]-=tonari*tmp
            count+=tmp
            flag=True
if A==B:
    print(count)
else:
    print(-1)
Problem p02941 (python)

Fixed submission:
n=int(input())
A=list(map(int,input().split( )))
B=list(map(int,input().split( )))
count=0
prv_count=-1#人の見て追加

#flag=True
while count!=prv_count:
    prv_count=count
    for i in range(-1,n-1):
        tonari=B[i-1]+B[i+1]
        tmp=(B[i]-A[i])//tonari
        if tmp>0:
            B[i]-=tonari*tmp
            count+=tmp
            #flag=True
if A==B:
    print(count)
else:
    print(-1)

Buggy submission (verdict: Runtime Error):
n=int(input())
A=list(map(int,input().split( )))
B=list(map(int,input().split( )))
count=0
flag=True
while flag:
    flag=False
    for i in range(-1,n-1):
        tonari=B[i-1]+B[i+1]
        tmp=B[i]//tonari
        if tmp>0:
            B[i]-=tonari*tmp
            count+=tmp
            flag=True
if A==B:
    print(count)
else:
    print(-1)

Buggy submission (verdict: Runtime Error):
n=int(input())
A=list(map(int,input().split( )))
B=list(map(int,input().split( )))
count=0
before=0
i=-1
while True:
    before=count
    tonari=B[i-2]+B[i]
    tmp=(B[i-1]-A[i-1])//tonari
    B[i-1]-=tonari*tmp
    count+=tmp
    i+=1
    i%=n
    if before==count:
        break

if A==B:
    print(count)
else:
    print(-1)

n=int(input())
A=list(map(int,input().split( )))
B=list(map(int,input().split( )))
count=0
flag=True
while flag:
    flag=False
    for i in range(-1,n-1):
        tonari=B[i-1]+B[i+1]
        tmp=B[i]//tonari#B[i]-A[i]から変更
        if tmp>0:
            B[i]-=tonari*tmp
            count+=tmp
            flag=True
if A==B:
    print(count)
else:
    print(-1)
Problem p02945 (python)

Fixed submission:
a,b=map(int,input().split( ))
sm=a+b
sb=a-b
tms=a*b
mx=max(sm,sb,tms)
print(mx)

Buggy submission (verdict: Runtime Error):
a,b=map(int,input())
sm=a+b,
sb=a-b
tms=a*b
mx=max(sm,sb,tms)
print(mx)
Problem p02946 (python)

Fixed submission:
k,x=map(int,input().split())

ans=range(x-k+1,x+k)
print(*ans)

Buggy submission (verdict: Runtime Error):
k,x=map(int,input(),split())

ans=range(x-k+1,x+k-1)
print(*ans)
Problem p02975 (python)

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

#3つ置きに一致する
S = {}
for ai in a:
    if ai in S:
        S[ai]+=1
    else:
        S[ai] = 1
A = list(S.keys())
#print(S)
#print(A)
#print(list(S.keys()))
#print(S.values())
if len(S) ==3:
    if A[0]==A[1]^A[2] and S[A[0]]==S[A[1]] and S[A[1]] == S[A[2]]:
        print("Yes")
    else:
        print("No")##漏れ


elif len(S)==2:#一番の漏れ
    if A[0]==0 and S[A[1]] == 2*S[A[0]]:#S[A[0]]==0じゃない
        print("Yes")
    elif A[1]==0 and S[A[0]] == 2*S[A[1]]:
        print("Yes")
    else:
        print("No")


elif len(S)==1:
    if list(S.keys())==[0]:#1.dict_keys、dict_valuesはリストでない 2.keysのほう
        print("Yes")
    else:###
        print("No")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
import sys
n = int(input())
a = list(map(int, input().split( )))

#3つ置きに一致する
S = {}
for ai in a:
    if ai in S:
        S[ai]+=1
    else:
        S[ai] = 1

if len(S)>3:
    print("No")
    sys.exit()
    
if len(S) ==3:
    A = list(S.keys())
    if A[0]==A[1]^A[2] and S[A[0]]==S[A[1]] and S[A[1]] == S[A[2]]:
        print("Yes")


elif len(S)==2:
    if S[A[0]]==0 and S[A[1]] == 2*S[A[0]]:
        print("Yes")
    elif S[A[1]]==0 and S[A[0]] == 2*S[A[1]]:
        print("Yes")
    else:
        print("No")


elif len(S)==1:
    if S.values()==[0]:
        print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split( )))

#3つ置きに一致する
S = {}
for ai in a:
    if ai in S:
        S[ai]+=1
    else:
        S[ai] = 1

if len(S)>3:
    print("No")
    sys.exit()
    
if len(S) ==3:
    A = list(S.keys())
    if A[0]==A[1]^A[2] and S[A[0]]==S[A[1]] and S[A[1]] == S[A[2]]:
        print("Yes")

elif len(S) == 2:
    A = list(S.keys())
    if A[0]== 0 or  A[1]==0 and S[A[0]] == S[A[1]]:
        print("Yes")
elif len(S)==1:
    if S.values()==[0]:
        print("Yes")
else:
    print("No")
Problem p02976 (python)

Fixed submission:
#editorial参照

import sys
from collections import deque
sys.setrecursionlimit(200000)

n,m = map(int, input().split( ))
G = [[] for _ in range(n)]

for _ in range(m):
    a,b = map(int, input().split( ))
    a-=1;b-=1
    G[a].append(b)
    G[b].append(a)

if m&1:
    print(-1)
    sys.exit()

Tr = [0]*n#k木に属しているか
Q = deque()
Q.append(0)
Tr[0] = 1
TrE = [[] for _ in range(n)]
P = [-1]*n#親
Leaf = []
while Q:
    v = Q.popleft()
    leaf_v = True
    for u in G[v]:
        if not Tr[u]:
            Tr[u] = 1
            P[u]=v
            TrE[v].append(u)
            Q.append(u)
            leaf_v = False
    if leaf_v:
        Leaf.append(v)

out = [0]*n
D = set()             
for v in range(n):
    for u in G[v]:
        if (u,v) not in D and P[v]!=u and P[u]!=v:
            D.add((v,u))
            out[v]^=1
            

"""
幅優先探索で葉から辿ったところ、
すべての子を考慮する前にpのdegreeが決まってしまっている。
深さ優先探索に修正
"""
def dfs(x = 0, parent = -1):
    for y in TrE[x]:
        if y == parent:
            continue
        dfs(y,x)
        if out[y]:
            D.add((y,x))
            out[y] ^= 1
        else:
            D.add((x,y))
            out[x] ^= 1
 
dfs()

for u,v in D:
    print(u+1,v+1)

Buggy submission (verdict: Runtime Error):
#editorial参照
import sys
from collections import deque
n,m = map(int, input().split( ))
G = [[] for _ in range(n)]

for _ in range(m):
    a,b = map(int, input().split( ))
    a-=1;b-=1
    G[a].append(b)
    G[b].append(a)

if m&1:
    print(-1)
    sys.exit()

Tr = [0]*n#k木に属しているか
Q = deque()
Q.append(0)
Tr[0] = 1
TrE = [[] for _ in range(n)]
P = [-1]*n#親
Leaf = []
while Q:
    v = Q.popleft()
    leaf_v = True
    for u in G[v]:
        if not Tr[u]:
            Tr[u] = 1
            P[u]=v
            TrE[v].append(u)
            Q.append(u)
            leaf_v = False
    if leaf_v:
        Leaf.append(v)

out = [0]*n
D = set()             
for v in range(n):
    for u in G[v]:
        if (u,v) not in D and P[v]!=u and P[u]!=v:
            D.add((v,u))
            out[v]^=1
            

"""
幅優先探索で葉から辿ったところ、
すべての子を考慮する前にpのdegreeが決まってしまっている。
深さ優先探索に修正
"""
def dfs(x = 0, parent = -1):
    for y in TrE[x]:
        if y == parent:
            continue
        dfs(y,x)
        if out[y]:
            D.add((y,x))
            out[y] ^= 1
        else:
            D.add((x,y))
            out[x] ^= 1
 
dfs()

for u,v in D:
    print(u+1,v+1)
Problem p02983 (python)

Fixed submission:
l, r = map(int, input().split( ))
ans = []
if r - l>=2019:
    print(0)
else:
    for i in range(l,r):
        for j in range(i+1,r+1):
            tmp = i*j%2019
            ans.append(tmp)
    print(min(ans))

Buggy submission (verdict: Runtime Error):
l, r = map(int, input().split( ))
ans = []
if r - l>=2019:
  print(0)
else:
  for i in range(l,r):
    for j in range(i+1,r+1):
      tmp = i*j%2019
      ans.append(tmp)
      
print(min(ans))

Buggy submission (verdict: Runtime Error):
l, r = map(int, input().split( ))
ans = []
if r - l>=2019:
  print(0)
else:
  for i in range(l,r):
    for j in range(i+1,r+1):
      tmp = i*j%2019
      ans.append(tmp)
      
pritn(mimn(ans))
Problem p03027 (python)

Fixed submission:
mod = 1000003
"""
for i in range(2,57000):
    if n%i==0:
        print("nonPrime")
        exit()
print("prime")
"""
q = int(input())
fct = [0]
tmp = 1
for i in range(1,mod+3):
    tmp *=i
    tmp%=mod
    fct.append(tmp)
for i in range(q):
    x,d,n = map(int, input().split( ))
    if d%mod == 0:
        print(pow(x,n,mod))
        continue
    if n>=mod:
        print(0)
        continue
    rev_d = pow(d,mod-2,mod)
    x*=rev_d
    x%=mod
    tmp = pow(d,n,mod)
    try:
        tmp*=fct[x+n-1]
    except:
        print(0)
        continue
    if x>=2:
        tmp*=pow(fct[x-1],mod-2,mod)
    tmp%=mod
    print(tmp)

Buggy submission (verdict: Runtime Error):
mod = 1000003
"""
for i in range(2,57000):
    if n%i==0:
        print("nonPrime")
        exit()
print("prime")
"""
q = int(input())
fct = [0]
tmp = 1
for i in range(1,mod):
    tmp *=i
    tmp%=mod
    fct.append(tmp)
for i in range(q):
    x,d,n = map(int, input().split( ))
    if d%mod == 0:
        print(pow(x,mod-2,mod))
        continue
    if n>=mod:
        print(0)
        continue
    rev_d = pow(d,mod-2,mod)
    x*=rev_d
    x%=mod
    tmp = pow(d,n,mod)
    tmp*=fct[x+n-1]
    if x>=1:
        tmp*=pow(fct[x-1],mod-2,mod)
    tmp%=mod
    print(tmp)
Problem p03050 (python)

Fixed submission:
#n//m=kかつn%m=kはつまりn=k(m+1)、また、k<m

n=int(input())

sq = int(n**(1/2))+2
ans = 0
for i in range(1,sq):
    if n%i==0:
        j = n//i-1
        if j:#nが小さいと0になる？
            if n//j==n%j:#境界処理が面倒なので試す
                ans +=j

print(ans)

Buggy submission (verdict: Runtime Error):
#n//m=kかつn%m=kはつまりn=k(m+1)、また、k<m

n=int(input())
fct =[]

sq = int(n**(1/2))+2
ans = 0
for i in range(1,sq):
    if n%i==0:
        j = n//i-1
        if n//j==n%j:#境界処理が面倒なので試す
            ans +=j

print(ans)
Problem p03062 (python)

Fixed submission:
#(ai,ai+1),(ai+1,ai+2)...(aj-1,aj)に-1を掛けると
#ai,ajに-1を掛けることができる

n = int(input())
a = list(map(int, input().split()))
n=len(a)
mns = [ai for ai in a if ai<0]
pls = [ai for ai in a if ai>=0]

mns.sort()
pls.sort()
#print(mns)
#print(pls)
lm = len(mns)
m_rem = 0
if lm%2:
    if pls:
        if pls[0]<-1*mns[-1]:
            tmp = -1*mns[-1]
            mns[-1] = -1*pls[0]
            pls[0] = tmp
    m_rem = mns.pop()

print(sum(pls)-sum(mns) + m_rem)

Buggy submission (verdict: Runtime Error):
#(ai,ai+1),(ai+1,ai+2)...(aj-1,aj)に-1を掛けると
#ai,ajに-1を掛けることができる

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

mns = [ai for ai in a if ai<0]
pls = [ai for ai in a if ai>=0]

mns.sort()
pls.sort()

lm = len(mns)
m_rem = 0
if lm%2:
    if pls[0]<-1*mns[-1]:
        tmp = -1*mns[-1]
        mns[-1] = -1*pls[0]
        pls[0] = tmp
    m_rem = mns.pop()

print(sum(pls)-sum(mns) + m_rem)

Buggy submission (verdict: Runtime Error):
#(ai,ai+1),(ai+1,ai+2)...(aj-1,aj)に-1を掛けると
#ai,ajに-1を掛けることができる

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

mns = [ai for ai in a if ai<0]
pls = [ai for ai in a if ai>=0]

mns.sort()
pls.sort()

lm = len(mns)
m_rem = 0
if lm%2:
    if pls[0]<-1*mns[-1]:
        tmp = -1*mns[-1]
        mns[-1] = -1*pls[0]
        pls[0] = tmp
    m_rem = mns.pop()

print(sum(pls)-sum(mns) + m_rem)
Problem p03076 (python)

Fixed submission:
#import sys
#input=sys.stdin.read
#*x,=map(int, input().split("\n"))
x=[int(input()) for _ in range(5)]
tmp=100
for i in range(5):
    if x[i]%10:
        tmp = min(tmp,x[i]%10)
        x[i]//=10
        x[i]*= 10
        x[i]+=10
ans= sum(x)
if tmp<100:
    ans-=10
    ans+=tmp
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
input=sys.stdin.read
*x,=map(int, input().split("\n"))
tmp=100
for i in range(5):
    if x[i]%10:
        tmp = min(tmp,x[i]%10)
        x[i]//=10
        x[i]*= 10
        x[i]+=10
ans= sum(x)
if tmp<100:
    ans-=10
    ans+=tmp
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
input=sys.stdin.read
*x,=map(int, input().split("\n"))
tmp=100
for i in range(5):
    if x[i]%10:
        tmp = min(tmp,x[i]%10)
        x[i]//=10
        x[i]*= 10
        x[i]+=10
ans= sum(x)
if tmp<100:
    ans-=10
    ans+=tmp
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
input=sys.stdin.read
*x,=map(int, input().split("\n"))
tmp=100
for i in range(5):
    if x[i]%10:
        tmp = min(tmp,x[i]%10)
        x[i]//=10
        x[i]*= 10
        x[i]+=10
ans= sum(x)
if tmp<100:
    ans-=10
    ans+=tmp
print(ans)
Problem p03130 (python)

Fixed submission:
#どの 2 つの街の間も、道を何本か通ることで行き来することができる
cnts=[0]*4
for i in range(3):
    ai,bi=map(int, input().split())
    ai-=1;bi-=1
    cnts[ai]+=1;cnts[bi]+=1
for i in range(4):
    if cnts[i]>2:
        print("NO")
        exit()
print("YES")

Buggy submission (verdict: Runtime Error):
#どの 2 つの街の間も、道を何本か通ることで行き来することができる
cnts=[0]*4
for i in range(3):
    ai,bi=map(int, input().split())
    ai-=1;bi-=1
    cnts[ai]+=1;cnts[bi]+=1
for i in range(4):
    if cnts>2:
        print("NO")
        exit()
print("YES")