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

Fixed submission:
h,w,k=map(int,input().split())
pos=[0]*(h*w+1)
for i in range(h):
  tmp=list(map(int,input().split()))
  for j in range(w):
    pos[tmp[j]]=[i+1,j+1]
cs=[[0] for _ in range(k+1)]
for i in range(1,k+1):
  for j in range(1,(h*w-i)//k+1):
    x1,y1=pos[i+k*(j-1)][1],pos[i+k*(j-1)][0]
    x2,y2=pos[i+k*j][1],pos[i+k*j][0]
    cs[i].append(abs(y2-y1)+abs(x2-x1)+cs[i][j-1])
q=int(input())
for i in range(q):
  l,r=map(int,input().split())
  tmp=l%k
  if tmp==0:
    tmp=k
  l,r=(l-tmp)//k,(r-tmp)//k
  print(cs[tmp][r]-cs[tmp][l])

Buggy submission (verdict: Runtime Error):
h,w,k=map(int,input().split())
pos=[0]*(h*w+1)
for _ in range(h):
  tmp=list(map(int,input().split()))
  for i in range(w):
    pos[tmp[w]]=[i+1,w+1]
print(pos)h,w,k=map(int,input().split())
pos=[0]*(h*w+1)
for i in range(h):
  tmp=list(map(int,input().split()))
  for j in range(w):
    pos[tmp[j]]=[i+1,j+1]
cs=[[0] for _ in range(k+1)]
for i in range(1,k+1):
  for j in range(1,(h*w-i)//k+1):
    x1,y1=pos[i+k*(j-1)][1],pos[i+k*(j-1)][0]
    x2,y2=pos[i+k*j][1],pos[i+k*j][0]
    cs[i].append(abs(y2-y1)+abs(x2-x1)+cs[i][j-1])
q=int(input())
for i in range(q):
  l,r=map(int,input().split())
  tmp=l%k
  if tmp==0:
    tmp=k
  l,r=(l-tmp)//k,(r-tmp)//k
  print(cs[tmp][r]-cs[tmp][l])
Problem p03724 (python)

Fixed submission:
n,m=map(int,input().split())
g=[[] for _ in range(n+1)]
for _ in range(m):
  u,v=map(int,input().split())
  g[u].append(v)
  g[v].append(u)
flag=True
for i in range(1,n+1):
  if len(g[i])%2==0:
    continue
  else:
    flag=False
    break
if flag==True:
  print('YES')
else:
  print('NO')

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
g=[[]*for _ in range(n+1)]
for _ in range(m):
  u,v=map(int,input().split())
  g[u].append(v)
  g[v].append(u)
flag=True
for i in range(1,n+1):
  if g[i]%2==0:
    continue
  else:
    flag=False
    break
if flag==True:
  print('YES')
else:
  print('NO')
Problem p03774 (python)

Fixed submission:
n,m=map(int,input().split())
pos1=[list(map(int,input().split())) for _ in range(n)]
pos2=[list(map(int,input().split())) for _ in range(m)]
ans=[0]*n
for i in range(n):
  lim=10**9
  for j in range(m):
    tmp=abs(pos1[i][0]-pos2[j][0])+abs(pos1[i][1]-pos2[j][1])
    if tmp<lim:
      lim=tmp
      ans[i]=j+1
for i in range(n):
  print(ans[i])

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
pos1=[list(map(int,input().split())) for _ in range(n)]
pos2=[list(map(int,input().split())) for _ in range(m)]
ans=[0]*n
for i in range(n):
  lim=10**9
  for j in range(m):
    tmp=abs(pos1[i][0]-pos2[i][0])+abs(pos1[i][1]-pos2[i][1])
    if tmp<lim:
      tmp=lim
      ans[i]=j
for i in range(n):
  print(ans[i])
Problem p03822 (python)

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

def dfs(v):
  if len(g[v])==0:
    return 0
  dic={}
  for u in g[v]:
    tmp=dfs(u)
    if tmp not in dic:
      dic[tmp]=1
    else:
      dic[tmp]+=1
  arr=[]
  for pos in dic.keys():
    arr+=[pos]*dic[pos]
  arr=sorted(arr,reverse=True)
  return max([(i+1)+arr[i] for i in range(len(arr))])

n=int(input())
g=[[] for _ in range(n+1)]
for i in range(n-1):
  v=int(input())
  g[v].append(i+2)
print(dfs(1))

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecurtionlimit(10**9)

def dfs(v):
  if len(g[v])==0:
    return 0
  dic={}
  for u in g[v]:
    tmp=dfs(u)
    if tmp not in dic:
      dic[tmp]=1
    else:
      dic[tmp]+=1
  pos=max(dic.keys())
  return pos+dic[pos]

n=int(input())
g=[[] for _ in range(n+1)]
for i in range(n-1):
  v=int(input())
  g[v].append(i+2)
print(dfs(1))
Problem p03834 (python)

Fixed submission:
s=str(input())
s1=s[:5]
s2=s[6:13]
s3=s[14:]
print('{} {} {}'.format(s1,s2,s3))

Buggy submission (verdict: Runtime Error):
s=str(input())
s1=str[:5]
s2=str[6:13]
s3=str[14:]
print('{} {} {}'.format(s1,s2,s3))

Buggy submission (verdict: Runtime Error):
s=str(input())
s1=str[:5]
s2=str[6:12]
s3=str[14:]
print('{} {} {}'.format(s1,s2,s3))
Problem p03986 (python)

Fixed submission:
import collections

s=input()
n=len(s)
slen=collections.deque()
tlen=collections.deque()
cnt=0
ans=0
for i in range(n):
  if s[i]=='S':
    tpos=i
    break
else:
  tpos=n
for i in range(n-1,-1,-1):
  if s[i]=='T':
    spos=i
    break
else:
  spos=-1
s=s[tpos:spos+1]+'x'
for i in range(len(s)-1):
  cnt+=1
  if s[i]!=s[i+1]:
    if s[i]=='S':
      slen.append(cnt)
      cnt=0
    else:
      tlen.append(cnt)
      cnt=0
for i in range(len(slen)):
  stmp,ttmp=slen.popleft(),tlen.popleft()
  if stmp>ttmp:
    ans+=ttmp
    if len(slen)>0:
      tmp=slen.popleft()+(stmp-ttmp)
      slen.appendleft(tmp)
  else:
    ans+=stmp
print(n-ans*2)

Buggy submission (verdict: Runtime Error):
import collections

s=input()
n=len(s)
slen=collections.deque()
tlen=collections.deque()
cnt=0
ans=0
for i in range(n):
  if s[i]=='S':
    tpos=i
    break
else:
  tpos=n
for i in range(n-1,-1,-1):
  if s[i]=='T':
    spos=i
    break
else:
  spos=-1
s=s[tpos:spos+1]+'x'
for i in range(len(s)-1):
  cnt+=1
  if s[i]!=s[i+1]:
    if s[i]=='S':
      slen.append(cnt)
      cnt=0
    else:
      tlen.append(cnt)
      cnt=0
for i in range(len(slen)):
  stmp,ttmp=slen.popleft(),tlen.popleft()
  if stmp>ttmp:
    ans+=ttmp
    tmp=slen.popleft()+(stmp-ttmp)
    slen.appendleft(tmp)
  else:
    ans+=stmp
print(n-ans*2)

Buggy submission (verdict: Runtime Error):
import collections

s=input()
n=len(s)
slen=collections.deque()
tlen=collections.deque()
cnt=0
ans=0
for i in range(n):
  if s[i]=='S':
    tpos=i
    break
else:
  tpos=n
for i in range(n-1,-1,-1):
  if s[i]=='T':
    spos=i
    break
else:
  spos=-1
s=s[tpos:spos+1]+'x'
for i in range(len(s)-1):
  cnt+=1
  if s[i]!=s[i+1]:
    if s[i]=='S':
      slen.append(cnt)
      cnt=0
    else:
      tlen.append(cnt)
      cnt=0
for i in range(len(slen)):
  stmp,ttmp=slen.popleft(),tlen.popleft()
  if stmp>ttmp:
    ans+=ttmp
    tmp=stmp.popleft()+(stmp-ttmp)
    slen.appendleft(tmp)
  else:
    ans+=stmp
print(n-ans*2)
Problem p02596 (python)

Fixed submission:
K = int(input())
remainder_set = set()
sequence = 7
i = 1
for i in range(K):
    remainder = sequence%K
    #print(sequence,remainder)
    if remainder == 0:
        print(i+1)
        break
    else:
        if remainder in remainder_set:
            print(-1)
            break
        else:
            i += 1
            remainder_set.add(remainder)
            sequence = remainder*10 + 7

Buggy submission (verdict: Runtime Error):
K = int(input())
remainder_set = set()
sequence = 7
i = 1
for i in range(10**7 + 9):
    if sequence%K == 0:
        print(i+1)
        break
    else:
        if sequence%K in emainder_set:
            print(-1)
            break
        else:
            i += 1
            sequence *= 10
            sequence += 7

Buggy submission (verdict: Runtime Error):
K = int(input())

if K%2 == 0:
    print(-1)

suretu = 7
i = 1
for i in range(10**7 + 9)
    if suretu%K == 0:
        print(i)
        break
    else:
        i += 1
        suretu *= 10
        suretu += 7
Problem p02659 (python)

Fixed submission:
A,B = map(str, input().split())
A = int(A)
period_index = B.index(".")
B_after_the_decimal = int(B[period_index+1:])
B_before_the_decimal = int(B[0:period_index])

include_decimal = str(int(A*B_after_the_decimal))
include_decimal = include_decimal[:len(include_decimal)-(len(B) - period_index -1)]

if include_decimal != "":
    include_decimal = int(include_decimal)
    ans = include_decimal + A*B_before_the_decimal
else:
    ans = A*B_before_the_decimal
    
print(ans)

Buggy submission (verdict: Runtime Error):
A,B = map(str, input().split())
A = int(A)
period_index = B.index(".")
B_after_the_decimal = int(B[period_index+1:])
B_before_the_decimal = int(B[0:period_index])

include_decimal = str(int(A*B_after_the_decimal))
include_decimal = include_decimal[:len(include_decimal)-(len(B) - period_index -1)]

if include_decimal != "":
    ans = include_decimal + A*B_before_the_decimal
else:
    ans = A*B_before_the_decimal
    
print(ans)
Problem p02959 (python)

Fixed submission:
#135c
N = int(input())
list_A = list(map(int, input().split()))
list_B = list(map(int, input().split()))
 
#print("#################################################")
 
ans = 0
remaining_power = 0
 
if N>1:
    for i in range(N-1,-1,-1):
        #print(i,"… RP:",remaining_power,",A:",list_A[i+1],",B:",list_B[i])
 
        if remaining_power>list_A[i+1]:
            #余力のみで倒せる
            remaining_power=list_B[i]
            ans += list_A[i+1]
            #print("margin")
        elif remaining_power + list_B[i] > list_A[i+1]:
            #余力と勇者で倒せる
            remaining_power = list_B[i] - (list_A[i+1] - remaining_power)
            ans += list_A[i+1]
            #print("OK")
        else:
            #余力と勇者でも倒せない
            ans += remaining_power + list_B[i]
            remaining_power = 0
            #print("No")
else:
    remaining_power = list_B[0] 
            
if remaining_power > list_A[0]:
    ans += list_A[0]
else:
    ans += remaining_power
        
print(ans)

Buggy submission (verdict: Runtime Error):
#135c
N = str(input())
list_A = list(map(int, input().split()))
list_B = list(map(int, input().split()))

#print("#################################################")

ans = 0
remaining_power = 0

if N>1:
    for i in range(N-1,-1,-1):
        #print(i,"… RP:",remaining_power,",A:",list_A[i+1],",B:",list_B[i])

        if remaining_power>list_A[i+1]:
            #余力のみで倒せる
            remaining_power=list_B[i]
            ans += list_A[i+1]
            #print("margin")
        elif remaining_power + list_B[i] > list_A[i+1]:
            #余力と勇者で倒せる
            remaining_power = list_B[i] - (list_A[i+1] - remaining_power)
            ans += list_A[i+1]
            #print("OK")
        else:
            #余力と勇者でも倒せない
            ans += remaining_power + list_B[i]
            remaining_power = 0
            #print("No")
else:
    remaining_power = list_B[0] 
            
if remaining_power > list_A[0]:
    ans += list_A[0]
else:
    ans += remaining_power
        
print(ans)
Problem p03073 (python)

Fixed submission:
#124c
S = str(input())
#################01234567
ans_b_start = 0 #01010101…
ans_w_start = 0 #10101010…

for i in range(len(S)):
    if i%2==0:
        if S[i]=="0":
            ans_w_start+=1
        if S[i]=="1":
            ans_b_start+=1
    if i%2==1:
        if S[i]=="0":
            ans_b_start+=1
        if S[i]=="1":
            ans_w_start+=1
        
if ans_w_start > ans_b_start:
    print(ans_b_start)
else:
    print(ans_w_start)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
# 文字列の入力
S = str(input())

ans=0

if len(S)==1:
  ans=0
elif len(S)==2:
  if S[0]==S[1]:
    ans=1
  else:
    ans=0
else: #3枚以上はちゃんと読み込む
  strint=[]
  original_string=[]
  
  for i in range(len(S)):
    string.append(S[i])
    original_string.append(S[i])
    
  for i in range(len(S)-2):
    gramed = str(string[i])+str(string[i+1])+str(string[i+2])
    
    if gramed=="000":
      string[i+1]="1"
    if gramed=="001":
      string[i]="1"
    if gramed=="011":
      string[i+2]="0"
    if gramed=="110":
      string[i]="0"
    if gramed=="100":
      string[i+2]="1"
    if gramed=="111":
      string[i+1]="1"
  
  #print(string)
  #print(original_string)
  
  for i in range(len(S)):
    if original_string[i]!=string[i]:
      ans=ans+1
  
print(ans)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
# 文字列の入力
S = str(input())

ans=0

if len(S)==1:
  ans=0
elif len(S)==2:
  if S[0]==S[1]:
    ans=1
  else:
    ans=0
else: #3枚以上はちゃんと読み込む
  strint=[]
  original_string=[]
  
  for i in range(len(S)):
    string.append(S[i])
    original_string.append(S[i])
    
  for i in range(len(S)-2):
    gramed = str(string[i])+str(string[i+1])+str(string[i+2])
    
    if gramed=="000":
      string[i+1]="1"
    if gramed=="001":
      string[i]="1"
    if gramed=="011":
      string[i+2]="0"
    if gramed=="110":
      string[i]="0"
    if gramed=="100":
      string[i+2]="1"
    if gramed=="111":
      string[i+1]="1"
  
  print(string)
  print(original_string)
  
  for i in range(len(S)):
    if original_string[i]!=string[i]:
      ans=ans+1
  
print(ans)
Problem p03127 (python)

Fixed submission:
#118c
#最小公倍数
N = int(input())
A_list = [int(e) for e in input().split()]

#######################################
#https://note.nkmk.me/python-gcd-lcm/
#import math
import fractions
from functools import reduce

def gcd(*numbers):
    #return reduce(math.gcd, numbers)
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    #return reduce(math.gcd, numbers)
    return reduce(fractions.gcd, numbers)
#######################################

print(gcd(*A_list))

Buggy submission (verdict: Runtime Error):
#118c
N = int(input())
A_list = list(input())

import fractions #math
from functools import reduce

def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

print(gcd_list(A_list))
Problem p03265 (python)

Fixed submission:
def get_ans(x1,y1,x2,y2):
    def_x = abs(x2-x1)
    def_y = abs(y2-y1)

    if x2 < x1 and y2 <= y1:
        x3 = x2+def_y
        y3 = y2-def_x
        x4 = x1+def_y
        y4 = y1-def_x 
    elif y2 < y1 and x1 <= x2:
        x3 = x2+def_y
        y3 = y2+def_x
        x4 = x1+def_y
        y4 = y1+def_x     
    elif x2 > x1 and y1 <= y2:
        x3 = x2-def_y
        y3 = y2+def_x
        x4 = x1-def_y
        y4 = y1+def_x 
    elif y2 > y1 and x1 >= x2:
        x3 = x2-def_y
        y3 = y2-def_x
        x4 = x1-def_y
        y4 = y1-def_x

    print(x3,y3,x4,y4)
    #return x3,y3,x4,y4

x1,y1,x2,y2 = map(int, input().split())
get_ans(x1,y1,x2,y2)

Buggy submission (verdict: Runtime Error):
#108b
import math

x1,y1,x2,y2 = map(int, input().split())

#正方形なのでベクトル(x2,y2)→(x3,y3)とベクトル(x2,y2)→(x1,y1)は同じ長さで直交している。
#(x3-x2)=xA
#(y3-y2)=yA
#(x1-x2)=xB
#(y1-y2)=yB
#とする。

#・大きさ同じ
# (x3-x2)**2+(y3-y2)**2 = (x1-x2)**2+(y1-y2)**2
# xA**2 + yA**2 = xB**2 + yB**2
#・直交→内積は0
# (x3-x2)*(x1-x2) + (y3-y2)*(y1-y2) = 0
# xA * xB = yA * yB

#整理すると
#yA = xA * xB / yB
#xA**2 + yA**2 = xB**2 + yB**2
#xA**2 + (xA * xB / yB)**2 = xB**2 + yB**2
#xA**2 * {1 + (xB / yB)**2)} = xB**2 + yB**2
#xA**2 = {xB**2 + yB**2} / {1 + (xB / yB)**2}

#xA = ±sqrt({xB**2 + yB**2} / {1 + (xB / yB)**2})
#yA = xA * xB / yB

xB = x1 - x2
yB = y1 - y2

xA = math.sqrt((xB**2 + yB**2) / (1 + (xB / yB)**2))
yA = xA * xB / yB
y3 = yA + y2

xA = -1 * math.sqrt((xB**2 + yB**2) / (1 + (xB / yB)**2))
yA = xA * xB / yB
x3 = xA + x2

###############################################################
#上と同様に考える
#xA = x4-x1
#yA = y4-y1
xB = x2 - x1
yB = y2 - y1

xA = math.sqrt((xB**2 + yB**2) / (1 + (xB / yB)**2))
yA = xA * xB / yB
y4 = yA + y1

xA = -1 * math.sqrt((xB**2 + yB**2) / (1 + (xB / yB)**2))
yA = xA * xB / yB
x4 = xA + x1

print(int(x3),int(y3),int(x4),int(y4))
Problem p03329 (python)

Fixed submission:
#99c
import math

N = int(input()) #<=100000

#引き算を足し算で下から求める

#直で引き出せる一覧のsetを作る。
single_withdraw_set = set()
single_withdraw_set.add(1)
single_withdraw_set |= {6**i for i in range(1,2 + int(math.log(N,6)))}
single_withdraw_set |= {9**i for i in range(1,2 + int(math.log(N,9)))}
#print(single_withdraw_set)

#何回で引き出せるかのdict。この後の計算でマイナス値を参照するので、あらかじめ作っておく。
withdraw_dict = {int(-i):10**9+7 for i in range(1,1 + max(single_withdraw_set)) }
withdraw_dict[0] = 0

#最低の引き出し回数を1円から計算していく
for i in range(1,N+1):
    if i in single_withdraw_set:
        #1回で引き出せるsetにあるなら当然1回
        withdraw_dict[i] = 1
    else:
        #なければ (現状の値 - 1回で引き出し可能な値)の中で1番少ない値 + 1 
        withdraw_dict[i] = 1 + min([withdraw_dict[i-j] for j in single_withdraw_set])
    
    #print(i,":",withdraw_dict[i])
    
#print(withdraw_dict)
print(withdraw_dict[N])

Buggy submission (verdict: Runtime Error):
import copy
import itertools

N = int(input())
six_nines = set()

#6,9の乗数を列挙する
for i in range(1,6):
  a = 6**i
  if a <= N and a not in six_nines:
    six_nines.add(a)
    for j in range(1,N//a):
      six_nines.add(a*j)
  a = 9**i
  if a <= N and a not in six_nines:
    six_nines.add(a)
    for j in range(1,N//a):
      six_nines.add(a*j)

comb_six_nines = copy.copy(six_nines)

#6,9の乗数の和を列挙する
for comb in itertools.combinations(six_nines,2):
  if comb[0]+comb[1] <= N and comb[0]+comb[1] not in comb_six_nines:
    comb_six_nines.add(comb[0]+comb[1])

#comb_six_nines = list(comb_six_nines)
#comb_six_nines.sort(reverse=True)
#comb_six_nines.append(1)
six_nines = list(six_nines)
six_nines.sort(reverse=True)
six_nines.append(1)

#print(comb_six_nines)
print(six_nines)

#Nを列挙した中の大きい方から引いていく
ans = 0
while N != 0:
  for comb in six_nines:
    if N >= comb:
      print(N,comb)
      if N 
      N -= comb
      ans += 1

print(ans)
Problem p03785 (python)

Fixed submission:
from collections import deque

N,C,K = map(int, input().split())

T_list = list() #左がもっとも早く着いた人

for i in range(N):
    T = int(input())
    T_list.append(T)

T_list.sort(reverse=False)

waiting_deque = deque(T_list)
ans = 0

while 1:
    if len(waiting_deque) != 0:
        ans += 1
        bus_passenger = list()
        bus_passenger.append(waiting_deque.popleft())
        while 1:
            if len(waiting_deque)!=0 and len(bus_passenger) < C and bus_passenger[0] + K >= waiting_deque[0]:
                bus_passenger.append(waiting_deque.popleft())
            else:
                #print(bus_passenger)
                break
    else:
        break

print(ans)

Buggy submission (verdict: Runtime Error):
from collections import deque

N,C,K = map(int, input().split())

T_list = list() #左がもっとも早く着いた人

for i in range(N):
    T = int(input())
    T_list.append(T)

T_list.sort(reverse=False)

waiting_deque = deque(T_list)
ans = 0

while 1:
    if len(waiting_deque) != 0:
        ans += 1
        bus_passenger = list()
        bus_passenger.append(waiting_deque.popleft())
        while 1:
            if len(waiting_deque)!=0 and len(bus_passenger) < C and bus_passenger[0] + K => waiting_deque[0]:
                bus_passenger.append(waiting_deque.popleft())
            else:
                #print(bus_passenger)
                break
    else:
        break

print(ans)
Problem p02679 (python)

Fixed submission:
import sys

readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10**7)
def readstr():return readline().rstrip().decode()
def readstrs():return list(readline().decode().split())
def readint():return int(readline())
def readints():return list(map(int,readline().split()))
def printrows(x):print('\n'.join(map(str,x)))
def printline(x):print(' '.join(map(str,x)))

from math import gcd
from collections import defaultdict


n = readint()

mod = 1000000007

d = defaultdict(int)

for i in range(n):
    a,b = readints()
    g = gcd(a,b)
    if g!=0:
        a//=g
        b//=g
    if a<0:
        a*=-1
        b*=-1
    elif a==0 and b<0:
        b*=-1
    d[(a,b)]+=1

ans = 1
k = tuple(d.keys())
ans2 = 0
for x in k:
    if x[0]>0:
        if x[1]>0:
            ans *= pow(2,d[x],mod)+pow(2,d[(x[1],-x[0])],mod)-1
        elif x[1]<0:
            if d[(-x[1],x[0])]==0:
                ans *= pow(2, d[x], mod)
        else:
            ans *= pow(2,d[x],mod)+pow(2,d[(x[1],x[0])],mod)-1
    else:
        if x[1]==0:
            ans2 += d[x]
        else:
            if d[(x[1], x[0])] == 0:
                ans *= pow(2, d[x], mod)
    ans %= mod

print((ans+ans2+mod-1)%mod)

Buggy submission (verdict: Runtime Error):
import sys

readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10**7)
def readstr():return readline().rstrip().decode()
def readstrs():return list(readline().decode().split())
def readint():return int(readline())
def readints():return list(map(int,readline().split()))
def printrows(x):print('\n'.join(map(str,x)))
def printline(x):print(' '.join(map(str,x)))

from math import gcd
from collections import defaultdict


n = readint()

mod = 1000000007

d = defaultdict(int)

for i in range(n):
    a,b = readints()
    g = gcd(a,b)
    a//=g
    b//=g
    if a<0:
        a*=-1
        b*=-1
    d[(a,b)]+=1

ans = 1
k = tuple(d.keys())
for x in k:
    if x[1]>=0:
        ans *= pow(2,d[x],mod)+pow(2,d[(x[1],-x[0])],mod)-1
    else:
        if d[(-x[1],x[0])]==0:
            ans *= pow(2, d[x], mod)
    ans %= mod

print(ans-1)
Problem p02753 (python)

Fixed submission:
s = input()

if s[1]==s[2]==s[0]:
  print('No')
else:
  print('Yes')

Buggy submission (verdict: Runtime Error):
s = input()

if s[1]==s[2]==s[3]:
  print('No')
else:
  print('Yes')
Problem p02851 (python)

Fixed submission:
from collections import defaultdict
from itertools import accumulate
import bisect


n,k = map(int, input().split())

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

s = list(accumulate([0]+a))

b = [s[i]-i for i in range(n+1)]

d = defaultdict(list)

for i in range(n+1):
    d[b[i]%k].append(i)

ans = 0
for x in d.keys():
    l = d[x]
    for j in range(len(l)):
        y = l[j]
        ans += max(0,bisect.bisect_right(l,k+y-1)-j-1)

print(ans)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
from itertools import accumulate
import bisect


n,k = map(int, input().split())

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

s = list(accumulate([0]+a))

b = [(s[i]-i)%k for i in range(n+1)]

d = defaultdict(int)

# 初期化
for i in range(k-1):
    d[b[i]]+=1

ans = 0
for i in range(n):
    # 自分を除外し、k-1個先が存在すれば加える。
    d[b[i]]-=1
    if i+k-1<=n:
        d[b[i+k-1]]+=1
    ans += d[b[i]]

print(ans)
Problem p02862 (python)

Fixed submission:
def factorials(n,m):
    # 0~n!のリスト
    f = [1,1]
    for i in range(2,n+1):
        f.append(f[-1]*i%m)

    # 0~n!の逆元のリスト
    g = [1]
    for i in range(n):
        g.append(pow(f[i+1],m-2,m))

    return f,g

x,y = map(int, input().split())

m = 10**9+7

if (2*y-x)%3!=0:
    print(0)
    exit()

b = (2*y-x)//3
a = y-2*b

if a<0 or b<0:
    print(0)
    exit()

f,g = factorials(a+b,m)

nCr = f[a+b]*g[b]*g[a]

print(nCr%m)

Buggy submission (verdict: Runtime Error):
def factorials(n,m):
    # 0~n!のリスト
    f = [1,1]
    for i in range(2,n+1):
        f.append(f[-1]*i%m)

    # 0~n!の逆元のリスト
    g = [1]
    for i in range(n):
        g.append(pow(f[i+1],m-2,m))

    return f,g

x,y = map(int, input().split())

m = 10**9+7

b = (2*y-x)//3
a = y-2*b

if a+2*b!=y or 2*a+b!=x:
    print(0)
    exit()

f,g = factorials(a+b,m)

nCr = f[a+b]*g[b]*g[a]

print(nCr%m)
Problem p02948 (python)

Fixed submission:
import heapq

n,m = map(int, input().split())

c = [[]for i in range(10**5+10)]

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


h = []
heapq.heapify(h)
ans = 0

for i in range(m):
    for x in c[i+1]:
        heapq.heappush(h,x)
    if h:
        ans += heapq.heappop(h)

print(-ans)

Buggy submission (verdict: Runtime Error):
import heapq

n,m = map(int, input().split())

c = [[]for i in range(10**5)]

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


h = []
heapq.heapify(h)
ans = 0

for i in range(m):
    for x in c[i+1]:
        heapq.heappush(h,x)
    if h:
        ans += heapq.heappop(h)

print(-ans)
Problem p02916 (python)

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

count = 0
pre   = 0
for i in range(N):
	now = A[i] - 1
	count += B[now]
	if i != 0 and pre == now - 1:
		count += C[pre]
	pre = now
print(count)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))

count = 0
for i in range(N):
	# print('B:',B[A[i]-1])
	# 追加の満足度が入らない場合は除く
	if i == 0:
		count += B[A[i]-1]
	else:
		count += B[A[i]-1]
		if abs(A[i]-A[i-1]) == 1:
			# print('C:',C[A[i-1]-1])
			count += C[A[i-1]-1]
print(count)
Problem p02594 (python)

Fixed submission:
a=input()
if int(a)>=30:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
a=input()
if a>=30:
  print("Yes")
else:
  print("No")