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

Fixed submission:
import sys
readline = sys.stdin.readline

N,K = map(int,readline().split())
DIV = 998244353

L = [None] * K
R = [None] * K
for i in range(K):
  L[i],R[i] = map(int,readline().split())

dp = [0] * (N + 1)
sdp = [0] * (N + 1)
dp[1] = 1
sdp[1] = 1
  
for i in range(2, len(dp)):
  for j in range(K):
    li = max(i - R[j], 0)
    ri = i - L[j]
    if ri < 0:
      continue
    dp[i] += (sdp[ri] - sdp[li - 1])
    dp[i] %= DIV
  sdp[i] = sdp[i - 1] + dp[i]
  sdp[i] %= DIV
  
print(dp[N])

Buggy submission (verdict: Runtime Error):
import sys
readline=sys.stdin.readline

import numpy as np
from numba import njit,i8

N,K=map(int,readline().split())
DIV = 998244353
steps = []
for i in range(K):
  l,r = map(int,readline().split())
  for j in range(l, r + 1):
    steps.append(j)
    
steps = sorted(steps)
steps = np.array(steps, dtype = int)

@njit(i8(i8[:]),cache = True)
def solve(steps):
  dp = np.zeros(N, dtype = int)
  dp[0] = 1
  for i in range(len(dp)):
    for s in steps:
      if i + s >= len(dp):
        break
      dp[i + s] += dp[i]
      dp[i + s] %= DIV
      
  return dp[-1]

print(solve())
Problem p02550 (python)

Fixed submission:
import sys
readline=sys.stdin.readline

N,X,M = map(int,readline().split())
route = [X]
dic = {}
first = []
loop = []
for i in range(1, N):
  X = (X ** 2) % M
  if X in dic:
    first = route[:dic[X]]
    loop = route[dic[X]:]
    break
  route.append(X)
  dic[X] = i
  
if len(first) == 0:
  print(sum(route[:N]))
  exit(0)

if N == len(first):
  print(sum(first))
elif N < len(first):
  print(sum(first[:N]))
else:
  ans = sum(first)
  one_loop = sum(loop)
  N -= len(first)
  loop_cnt = N // len(loop)
  rest = N % len(loop)
  ans += loop_cnt * (sum(loop))
  ans += sum(loop[:rest])

  print(ans)

Buggy submission (verdict: Runtime Error):
import sys
readline=sys.stdin.readline

N,X,M = map(int,readline().split())
route = [X]
dic = {}
first = []
loop = []
for i in range(1, N):
  X = (X ** 2) % M
  if X in dic:
    first = route[:dic[X]]
    loop = route[dic[X]:]
    break
  route.append(X)
  dic[X] = i

if N == len(first):
  print(sum(first))
elif N < len(first):
  print(sum(first[:N]))
else:
  ans = sum(first)
  one_loop = sum(loop)
  N -= len(first)
  loop_cnt = N // len(loop)
  rest = N % len(loop)
  ans += loop_cnt * (sum(loop))
  ans += sum(loop[:rest])

  print(ans)

Buggy submission (verdict: Runtime Error):
import sys
readline=sys.stdin.readline

N,X,M = map(int,readline().split())
route = [X]
dic = {}
first = []
loop = []
for i in range(1, 10000):
  X = (X ** 2) % M
  if X in dic:
    first = route[:dic[X]]
    loop = route[dic[X]:]
    break
  route.append(X)
  dic[X] = i

#print(first)
#print(loop)

if N == len(first):
  print(sum(first))
elif N < len(first):
  print(sum(first[:N]))
else:
  ans = sum(first)
  one_loop = sum(loop)
  N -= len(first)
  loop_cnt = N // len(loop)
  rest = N % len(loop)
  ans += loop_cnt * (sum(loop))
  ans += sum(loop[:rest])

  print(ans)
Problem p02659 (python)

Fixed submission:
from fractions import Fraction

A,B = input().split()
#A = int(A)
#B = float(B)

from decimal import *

a = Decimal(A)
b = Decimal(B)
getcontext().prec = 28
ans = a * b
print(int(ans))

Buggy submission (verdict: Runtime Error):
import sys
readline=sys.stdin.readline

A,B=map(int,readline().split())
print(int(A * B))
Problem p02833 (python)

Fixed submission:
N=int(input())
if N%2==1:
  print(0)
  exit(0)
  
ans=0
n=N
div=10
while n>=div:
  ans+=n//div
  div*=5
print(ans)

Buggy submission (verdict: Runtime Error):
N=int(input())
if N%2==1:
  print(0)
  exit(0)
  
ans=0
n=N
div=10
while n=>div:
  ans+=n//div
  div*=5
print(ans)
Problem p02836 (python)

Fixed submission:
S=input()
i=0
lasti=len(S)-1
ans=0
while i<lasti:
  if S[i]!=S[lasti]:
    ans+=1
  i+=1
  lasti-=1
print(ans)

Buggy submission (verdict: Runtime Error):
S=input()
ans=0
for i in range(len(S)//2):
  ans+=(S[i]!=S[-1-i]
print(ans)
Problem p02862 (python)

Fixed submission:
x,y=map(int,input().split())
a3=2*x-y
b3=2*y-x
MOD=10**9+7

def cmb(n, r, mod):
  if ( r<0 or r>n ):
    return 0
  r = min(r, n-r)
  return g1[n] * g2[r] * g2[n-r] % mod

if a3%3!=0 or b3%3!=0:
  print(0)
else:
  a=a3//3
  b=b3//3
  if a>b:
    a,b=b,a
  
  N=a+b

  g1 = [1, 1]
  g2 = [1, 1]
  inverse = [0, 1]

  for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % MOD )
    inverse.append( ( -inverse[MOD % i] * (MOD//i) ) % MOD )
    g2.append( (g2[-1] * inverse[-1]) % MOD )

  ans = cmb(N,a,MOD)
  print(ans%MOD)

Buggy submission (verdict: Runtime Error):
X,Y=map(int,input().split())

# (i+1,j+2)の移動をa回
# (i+2,j+1)の移動をb回
# X=a+2b
# Y=2a+b
# となるa,bが存在するか？
# b=(2X-Y)/3が整数となればOK

b=(2*X-Y)/3
if not float.is_integer(b):
  print(0)
  exit(0)
  
b=int(b)
a=X-2*b

# aとbの回数が決まったので、a+bCmin(a,b)をやればいい

DIV=10**9+7
from functools import reduce
def nCr(n,r,DIV):
  f=lambda x,y:x*y%DIV
  X=reduce(f,range(n-r+1,n+1))
  Y=reduce(f,range(1,r+1))
  return X*pow(Y,DIV-2,DIV)%DIV

print(nCr(a+b,min(a,b),DIV))
Problem p02863 (python)

Fixed submission:
N,T=map(int,input().split())
d=[None]*N
for i in range(N):
  a,b=map(int,input().split())
  d[i]=[a,b]

import numpy as np
d=sorted(d,key=lambda x:x[0])
dp=np.zeros(T,dtype=int)
ans=0
for i in range(len(d)):
  t=d[i][0]
  v=d[i][1]
  ans=max(ans,dp.max()+v)
  np.maximum(dp[:-t]+v,dp[t:],out=dp[t:])

print(ans)

Buggy submission (verdict: Runtime Error):
N,T=map(int,input().split())
d=[None]*N
for i in range(N):
  a,b=map(int,input().split())
  d[i]=[a,b]

d=sorted(d,key=lambda x:x[a])
dp=[-1]*(3000*2+5)
dp[0]=0
for i in range(len(d)):
  for j in range(T-1,-1,-1):
    if dp[j]!=-1:
      if dp[j]+d[i][1]>dp[j+d[i][0]]:
        dp[j+d[i][0]]=dp[j]+d[i][1]
      
print(max(dp))

Buggy submission (verdict: Runtime Error):
N,T=map(int,input().split())
d=[None]*N
for i in range(N):
  a,b=map(int,input().split())
  d[i]=[a,b]

dp=[-1]*(30*2)
dp[0]=0
for i in range(len(d)):
  for j in range(T,-1,-1):
    if dp[j]!=-1:
      if dp[j]+d[i][1]>dp[j+d[i][0]]:
        dp[j+d[i][0]]=dp[j]+d[i][1]
      
print(max(dp))
Problem p02880 (python)

Fixed submission:
N=int(input())

ans=False
for i in range(1,10):
  for j in range(1,10):
    if i*j==N:
      ans=True
      break
print(("No","Yes")[ans])

Buggy submission (verdict: Runtime Error):
N=int(input().split())

ans=False
for i in range(9):
  for j in range(9):
    if i*j==N:
      ans=True
      break
print(("No","Yes")[ans])
Problem p02881 (python)

Fixed submission:
N=int(input())
import math
SQ=int(math.sqrt(N))
minval=10**12
a=1
b=1
for i in range(1,SQ+1):
  if N%i==0:
    newa=i
    newb=N//i
    if abs(newa-newb) < minval:
      minval=abs(newa-newb)
      a=newa
      b=newb

print(a+b-2)

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

N=int(input())
datas=prime_factorize(N)
a=1
b=1
for i in range(len(data)):
  if a<b:
    a+=data[i]
  else:
    b+=data[i]

print(max(1,a-1)+max(1,b-1))
Problem p02948 (python)

Fixed submission:
n,m=map(int,input().split())
tasks=[None]*n
for i in range(n):
  a,b=map(int,input().split())
  tasks[i]=[a,b]

tasks=sorted(tasks,key=lambda x:x[0])
import heapq
que=[]
ans=0
heapq.heapify(que)
j=0
for i in range(m,-1,-1):
  left=m-i
  while j<len(tasks):
    if tasks[j][0]<=left:
      heapq.heappush(que, tasks[j][1]*(-1))
    else:
      break
    j+=1
  if len(que)>0:
    val=heapq.heappop(que)*(-1)
    ans+=val
      
print(ans)

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
w=[]
for i in range(n):
  w.append(list(map(int,input().split())))

total = 0
for i in range(m):
  max=0
  max_j=0
  max_day=0
  #残り日数 m-iより支払い日が短いもので最大の値をとる
  for j in range(len(w)):
    if w[j][0] <= m-i and w[j][1] > max: # 最大値が来たときは置き換え
      max = w[j][1]
      max_j=j
      max_day=w[j][0]
    elif w[j][0] <= m-i and w[j][1] == max:#最大値と同じ値のときは、日数が長いものを採用
      if w[j][0] > max_day:
        max = w[j][1]
        max_j=j
        max_day=w[j][0]
        
  total = total+max
  if(len(w)>0):
    w.remove(max_j)

print(total)
Problem p03045 (python)

Fixed submission:
n,m=map(int,input().split())

parent=[i for i in range(n)]
rank=[0 for i in range(n)]

def find(a):
  if parent[a]==a:
    return a
  else:
    return find(parent[a])

def union(a,b):
  ar=find(a)
  br=find(b)
  if ar==br:
    return
  if rank[a]>rank[b]:
    parent[br]=ar
  else:
    parent[ar]=br
    if rank[a]==rank[b]:
      rank[a]+=1
      
def same(a,b):
  ar=find(a)
  br=find(b)
  return ar==br

q=[None]*m

for i in range(m):
  x,y,z=map(int,input().split())
  q[i]=[x-1,y-1]

for i in range(len(q)):
  union(q[i][0],q[i][1])
  
roots=[0]*len(parent)
for i in range(len(parent)):
  roots[i]=find(i)

print(len(set(roots)))

Buggy submission (verdict: Runtime Error):
N,M=map(int,input().split())

parent=[i for i in range(N)]
depth=[0 for i in range(N)]

def root(x):
  if parent[x]==x:
    return x
  else:
    return root(parent[x])

def same(x,y):
  return root(x)==root(y)

def unite(x,y):
  rx=root(x)
  ry=root(y)
  if rx==ry:
    return
  if depth[x]<depth[y]:
    parent[rx]=ry
  else:
    parent[ry]=rx
    if depth[x]==depth[y]:
      depth[x]+=1
      
for i in range(M):
  a,b=map(int,input().split())
  a,b=a-1,b-1
  unite(a,b)
  
roots=set()
for i in range(N):
  roots.add(root(i))

print(len(roots)-1)
Problem p03053 (python)

Fixed submission:
H,W=map(int,input().split())
INF=10**4
import numpy as np
a=np.full((H,W),INF,dtype=int)
for i in range(H):
  s=input()
  for j in range(len(s)):
    if s[j]=="#":
      a[i,j]=0

for i in range(0,W-1):
  np.minimum(a[:,i]+1,a[:,i+1],out=a[:,i+1])
for i in range(W-1,0,-1):
  np.minimum(a[:,i]+1,a[:,i-1],out=a[:,i-1])
for j in range(0,H-1):
  np.minimum(a[j,]+1,a[j+1,],out=a[j+1,])
for j in range(H-1,0,-1):
  np.minimum(a[j,]+1,a[j-1,],out=a[j-1,])

print(a.max())

Buggy submission (verdict: Runtime Error):
h,w=map(int,input())
grid=[None]*h
INF=10**6
stack=[]
for i in range(h):
  s=list(input())
  for j in range(len(s)):
    if s[j]=="#":
      stack.append([i,j,0])
    s[j]=INF
  grid[i]=s
      
while stack:
  v=stack.pop()
  y=v[0]
  x=v[1]
  p=v[2]
  if p<grid[y][x]:
    grid[y][x]=p
  else:
    continue
  if y-1>=0:
    stack.append([y-1,x,p+1])
  if y+1<h:
    stack.append([y+1,x,p+1])
  if x-1>=0:
    stack.append([y,x-1,p+1])
  if x+1<w:
    stack.append([y,x+1,p+1])
    
ans=0
for i in range(len(grid)):
  ans=max(ans,max(grid[i]))
print(ans)
Problem p03634 (python)

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

Q,K=map(int,input().split())

INF=10**9+1
distFromK=[-1 for i in range(n)]

# start from K
stack=[]
stack.append([K-1,0,-1])
while stack:
  node=stack.pop()
  v=node[0]
  d=node[1]
  parent=node[2]
  if distFromK[v]==-1:
    distFromK[v]=d
  else:
    distFromK[v]=min(distFromK[v],d)
  targets=dist[v]
  for child in targets:
    if child[0]==parent or child[0]==v:
      continue
    stack.append([child[0],d+child[1],v])

for i in range(Q):
  x,y=map(int,input().split())
  print(distFromK[x-1]+distFromK[y-1])

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

import numpy as np
dist=np.full((n,n),-1,dtype=int)
for i in range(n-1):
  dist[i][i]=0
  a,b,c=map(int,input().split())
  dist[a-1][b-1]=c
  dist[b-1][a-1]=c

Q,K=map(int,input().split())
distFromK=np.full(n,-1,dtype=int)

# start from K
stack=[]
stack.append([K-1,0,-1])
while stack:
  node=stack.pop()
  num=node[0]
  d=node[1]
  parent=node[2]
  if distFromK[num]==-1:
    distFromK[num]=d
  else:
    distFromK[num]=min(d,distFromK[num])
  targets=dist[num]
  for i in range(len(targets)):
    if i==parent or i==num:
      continue
    if targets[i]==-1:
      continue
    stack.append([i,targets[i]+d,num])
    
for i in range(Q):
  x,y=map(int,input().split())
  print(distFromK[x-1]+distFromK[y-1])

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

import numpy as np
dist=np.full((n,n),-1,dtype=int)
for i in range(n-1):
  dist[i][i]=0
  a,b,c=map(int,input().split())
  dist[a-1][b-1]=c
  dist[b-1][a-1]=c

Q,K=map(int,input().split())
distFromK=np.full(n,-1,dtype=int)

# start from K
stack=[]
stack.append([K-1,0,-1])
while stack:
  node=stack.pop()
  num=node[0]
  d=node[1]
  parent=node[2]
  if distFromK[num]==-1:
    distFromK[num]=d
  else:
    distFromK[num]=np.minimum(d,distFromK[num])
  targets=dist[num]
  for i in range(len(targets)):
    if i==parent or i==num:
      continue
    if targets[i]==-1:
      continue
    stack.append([i,targets[i]+d,num])
    
for i in range(Q):
  x,y=map(int,input().split())
  print(distFromK[x-1]+distFromK[y-1])
Problem p03821 (python)

Fixed submission:
n=int(input())
a=[0]*n
b=[0]*n
for i in range(n):
  x,y=map(int,input().split())
  a[i]=x
  b[i]=y

cur=0
for j in range(n-1,-1,-1):
  if (a[j]+cur)%b[j]!=0:
    cur+=b[j]-(a[j]+cur)%b[j]

print(cur)

Buggy submission (verdict: Runtime Error):
N=int(input())
A=[0]*N
B=[0]*N
for i in range(N):
  a,b=map(int,input().split())
  A[i]=a
  B[i]=b

ans=0
for i in range(N-1,-1,-1):
  plus=0
  A[i]+=ans
  if B[i]==1:
    plus=0
  elif A[i]<B[i]:
    plus=B[i]%A[i]
  elif A[i]>B[i]:
    plus=B[i]-A[i]%B[i]
  ans+=plus
  
print(ans)
Problem p03834 (python)

Fixed submission:
print(input().replace(","," "))

Buggy submission (verdict: Runtime Error):
a,b,c=input().split()
print(a,b,c)
Problem p02793 (python)

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

mod = 1000000007

l = 1

for i in range(n):
    l = l * a[i] // gcd(l, a[i])

ans = 0
for i in range(n):
    ans += l // a[i]

print(ans % mod)

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

mod = 1000000007

l = 1

def lcm(a, b):
    return a * b // math.gcd(a, b)

for i in range(n):
    l = lcm(l, a[i])

ans = 0
for i in range(n):
    ans += l // a[i]
    ans %= mod

print(ans)
Problem p03013 (python)

Fixed submission:
n,m=map(int,input().split())
a=[]
for i in range(m):
    a.append(int(input()))

inf=1000000007

l=[1,1]
for i in range(n+2):
    l.append((l[i]+l[i+1])%inf)



if m!=0:
    k=[a[0]]
    for i in range(m-1):
        k.append(a[i+1]-a[i]-1)
    k.append(n-a[m-1])

    flag=True
    for i in range(1,len(k)):
       if k[i]==0:
            flag=False
    ans=1

    for j in range(len(k)):
        ans=(ans*l[k[j]-1])%inf

    if flag:
        print(ans%inf)
    else:
        print(0)
else:
    print(l[n])

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
a=[]
for i in range(m):
    a.append(int(input()))

inf=1000000007

l=[1,1]
for i in range(n+2):
    l.append((l[i]+l[i+1])%inf)

k=[a[0]]
for i in range(m-1):
    k.append(a[i+1]-a[i]-1)
k.append(n-a[m-1])

flag=True
for i in range(1,len(k)):
   if k[i]==0:
        flag=False
ans=1

for j in range(len(k)):
    ans=(ans*l[k[j]-1])%inf

if flag:
    print(ans%inf)
else:
    print(0)

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
a=[]
for i in range(m):
    a.append(int(input()))

inf=1000000007

l=[1,1]
for i in range(n+2):
    l.append((l[i]+l[i+1])%inf)

k=[a[0]]
for i in range(m-1):
    k.append(a[i+1]-a[i]-1)
k.append(n-a[m-1])

for i in range(1,len(k)):
   if k[i]==0:
       print(0)
       exit()
ans=1

for j in range(len(k)):
    ans=(ans*l[k[j]-1])%inf
print(ans%inf)

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split())
a=[]
for i in range(m):
    a.append(int(input()))

inf=1000000007

def fib(k):
    a, b = 1, 1
    for i in range(k):
        yield a
        a, b = b, a + b
 
l=[i for i in fib(n)]
p=[]
for i in range(n):
    if i+1 in a:
        p.append(1)
    else:
        p.append(0)

ans=1

for i in range(n-1):
   if p[i]==1 and p[i+1]==1:
       print(0)
       exit()
k=[a[0]-1]
for i in range(m-1):
    k.append(a[i+1]-a[i]-2)
k.append(n-a[m-1]-1)
print(k)
#if k[0]==0:
#   k[0]=1
for j in range(len(k)):
    if j==0:
        ans*=l[k[j]]%inf
    elif j==len(k)-1:
        ans*=l[k[j]]%inf
    else:
        ans*=l[k[j]]%inf
print(ans%inf)
Problem p02793 (python)

Fixed submission:
mod=10**9+7
n=int(input())
a=list(map(int,input().split()))

def gcd(m, n):
    while n:
        m, n = n, m % n
    return m

def lcm(a,b):
  return a*b//gcd(a,b)

L = 1
for i in range(n):
  L = lcm(L, a[i])
ans = 0
L %= mod
for i in range(n):
  ans += L * pow(a[i], mod - 2, mod)
  ans %= mod
print(ans)

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

def gcd(m, n):
    while n:
        m, n = n, m % n
    return m

def lcm(a,b):
  return a*b//gcd(a,b)

L=1
for i in range(n):
  L = lcm(l, a[i])
ans = 0
L %= mod
for i in range(n):
  ans += l * pow(a[i], mod - 2, mod)
  ans %= mod
print(ans)
Problem p02557 (python)

Fixed submission:
N, = map(int, input().split())
X = list(map(int, input().split()))
Y = list(map(int, input().split()))[::-1]
on = []
z = 0
for i in range(N):
    if not X[i]-Y[i]:
        on.append(i)
        z = X[i]
for i in range(N):
    if X[i]!=z and Y[i] != z and on:
        j = on.pop()
        Y[i], Y[j] = Y[j], Y[i]
if on:
    print("No")
else:
    print("Yes")
    print(*Y)

Buggy submission (verdict: Runtime Error):
N, = map(int, input().split())
X = list(map(int, input().split()))
Y = list(map(int, input().split()))[::-1]
z=zc=0
Z = []
for i in range(N):
    if X[i]==Y[i]:
        zc += 1
        z = Y[i]
    else:
        Z.append(Y[i])
if zc:
    if zc%2 == 0:
        Z = [z]*(zc//2)+Z+[z]*((zc+1)//2)
    else:
        2/0
for i in range(N):
    if X[i] == Z[i]:
        print("No")
        break
else:
    print("Yes")
    print(*Z)

Buggy submission (verdict: Runtime Error):
N, = map(int, input().split())
X = list(map(int, input().split()))
Y = list(map(int, input().split()))[::-1]
z=zc=0
Z = []
for i in range(N):
    if X[i]==Y[i]:
        zc += 1
        z = Y[i]
    else:
        Z.append(Y[i])
if zc:
    Z = [z]*zc//2+Z+[z]*(zc+1)//2
for i in range(N):
    if X[i] == Z[i]:
        print("No")
        break
else:
    print("Yes")
    print(*Z)
Problem p02623 (python)

Fixed submission:
N, M , K = map(int, input().split())
X = list(map(int, input().split()))
Y = list(map(int, input().split()))
t = 0
R = 0
tmp = 0
for i in range(M):
    if tmp + Y[i] > K:
        break
    R += 1
    tmp += Y[i]

sY = sum(Y)
j = M
for i in range(N):
    t += X[i]
    if t > K:
        break
    while j:
        if sY + t <= K:
            break
        j-=1
        sY -= Y[j]
    R = max(R, j+i+1)
print(R)

Buggy submission (verdict: Runtime Error):
N, M , K = map(int, input().split())
X = [0] + list(map(int, input().split()))
Y = list(map(int, input().split()))
R,sY,j= 0,sum(Y),M
for i in range(N):
    t += X[i]
    if t > K: break
    while j and sY+t > K:
        j-=1
        sY -= Y[j]
    R = max(R, j+i)
print(R)
Problem p02679 (python)

Fixed submission:
from math import gcd
def to_standard_form(a, b):
    if a == 0:
        return (0, 1)
    g = gcd(a, b)
    a //= g
    b //= g
    if a < 0:
        return (-a, -b)
    return (a, b)

N, = map(int, input().split())
d = dict()
X = []
cc = 0
for _ in range(N):
    a, b = map(int, input().split())
    if a == 0 and b==0:
        cc += 1
        continue
    f = to_standard_form(a, b)
    if f not in d:
        d[f] = 0
    d[f] += 1
    X.append(f)

vs = dict()
for a, b in X:
    f1 = (a, b)
    f2 = to_standard_form(-b, a)
    if f2 not in d:
        d[f2] = 0
    if f1 in vs or f2 in vs:
        continue
    vs[f1] = (d[f1], d[f2])

mod = 10**9+7
r = 1
for k in vs:
    a, b = vs[k]
    r = r * (pow(2, a, mod) + pow(2, b, mod)-1) % mod
print((r-1+cc)%mod)

Buggy submission (verdict: Runtime Error):
from fractions import Fraction
N, = map(int, input().split())
d = dict()
X = []
cc = 0
for _ in range(N):
    a, b = map(int, input().split())
    if a == 0 and b==0:
        cc += 1
        continue
    f = Fraction(a, b)
    if f not in d:
        d[f] = 0
    d[f] += 1
    X.append((a, b))

vs = dict()
cs = []
for a, b in X:
    f1 = Fraction(a, b)
    f2 = Fraction(b, -a)
    if f2 not in d:
        d[f2] = 0
#        cs.append(d[f1])
#        continue
    if f1 in vs or f2 in vs:
        continue
    vs[f1] = (d[f1], d[f2])
mod = 10**9+7

tmp = []
r = 1
#print(pow(2, sum(cs),mod))
r2 = 1
for k in vs:
    a, b = vs[k]
#    print((pow(2, a, mod), pow(2, b, mod)))
    r = r * (pow(2, a, mod) + pow(2, b, mod)-1) % mod
#    r2 = r2 * (pow(2, a-1, mod) + pow(2, b-1, mod)+2) % mod

print(r-1+cc)
#print(len(vs))
#print(r2)
#print(r2*pow(2, sum(cs),mod)+1)
Problem p02987 (python)

Fixed submission:
s = input().strip()
from collections import defaultdict
d = defaultdict(int)
for c in s:
    d[c] += 1
for k in d:
    if d[k] != 2:
        print("No")
        break
else:
    print("Yes")

Buggy submission (verdict: Runtime Error):

N, M = [int(x) for x in input().strip().split(" ")]

vs = set()
def dfs_w(v, d, t):
    # dfs while版 
    r = -1
    stack = [v]
    path = []
    while True:
        if len(stack) == 0:
            break
        v = stack.pop()
        if v < 0:
            path.pop()
        else:
            path.append(v)
            vs.add(v)
            for u in d[v]:
                if u == t:
                    if r != -1:
                        r = min(len(path)//3, r)
                    else:
                        r = len(path)//3
                if u in vs:
                    continue
                stack += [-v, u]
    return r

d = [set() for _ in range(3*N+1)]
for _ in range(M):
    a, b = [int(x) for x in input().strip().split(" ")]
    d[a].add(N+b)
    d[N+a].add(2*N+b)
    d[2*N+a].add(b)

s, t = [int(x) for x in input().strip().split(" ")]
print(dfs_w(s, d, t))
Problem p03013 (python)

Fixed submission:
N, M = map(int, input().split())
mod=10**9+7
dp = [1]*(N+1)
for _ in range(M):
    a, = map(int, input().split())
    dp[a] = 0
for i in range(2,N+1):
    if dp[i] != 0:
        dp[i] = (dp[i-1] + dp[i-2])%mod
print(dp[N])

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
dp = [1]*(N+1)
for _ in range(M):
    a, = map(int, input().split())
    dp[a] = 0
    A.append(a)
for i in range(2,N+1):
    if dp[i] != 0:
        dp[i] = dp[i-1] + dp[i-2]
print(dp[N])