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

Fixed submission:
import sys
N=int(input())
a=[int(i) for i in input().split()]
a.sort()

if a[N-1]-a[0]>1:
  print("No")
  sys.exit()
if a[0]==N-1:
  print("Yes")
  sys.exit()
if a[N-1]==1:
  print("Yes")
  sys.exit()
if a[0]==a[N-1]:
  if 2*a[0]<=N:
    print("Yes")
  else:
    print("No")
  sys.exit()

count=a.index(a[N-1])
if count+1<=a[N-1] and a[N-1]<=count+int((N-count)/2):
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
import sys
N=int(input())
a=[int(i) for i in input().split()]
a.sort()

if a[N-1]-a[0]>1:
  print("No")
  sys.exit()
if a[0]==N-1:
  print("Yes")
  sys.exit()
if a[N-1]==1:
  print("Yes")
  sys.exit()
if a[0]==a[N-1]:
  if 2*a[0]<=N:
    print("Yes")
  else:
    print("No")
  sys.exit()
print(a[N])

Buggy submission (verdict: Runtime Error):
import sys
N=int(input())
a=[int(i) for i in input().split()]
a.sort()

if a[N-1]-a[0]>1:
  print("No")
  sys.exit()
if a[0]==N-1:
  print("Yes")
  sys.exit()
print(a[N])

Buggy submission (verdict: Runtime Error):
import sys
N=int(input())
a=[int(i) for i in input().split()]
a.sort()

if a[N-1]-a[0]>1:
  print("NO")
  sys.exit()
if a[N-1]>N-1:
  print("NO")
  sys.exit()
if a[0]==N-1:
  print("YES")
  sys.exit()
if a[0]==a[N-1]:
  print("YES")
  sys.exit()
print(a[N])
Problem p03721 (python)

Fixed submission:
import sys
N,K=map(int, input().split())
p=[]
for i in range (0,N):
  r=list(map(int, input().split() )) 
  p.append(r)
p.sort()
k=0
for i in range(0,N):
  k+=p[i][1]
  if k>=K:
    print(p[i][0])
    sys.exit()

Buggy submission (verdict: Runtime Error):
import sys
N,K=map(int, input().split())
p=[]
for i in range (0,N):
  r=list(map(int, input().split() )) 
  p.append(r)
p.sort()
k=0
for i in range(0,N):
  k+=p[i][0]]
  if k>=K:
    print(p[i][1])
    sys.exit()
import sys
N,K=map(int, input().split())
p=[]
for i in range (0,N):
  r=list(map(int, input().split() )) 
  p.append(r)
p.sort()
k=0
for i in range(0,N):
  k+=p[i][1]
  if k>=K:
    print(p[i][0])
    sys.exit()

Buggy submission (verdict: Runtime Error):
import sys
N,K=map(int, input().split())
p=[]
for i in range (0,N):
  r=list(map(int, input().split() )) 
  p.append(r)
p.sort()
q=[]
for i in range(0,N):
  q+=[p[i][0]]*p[i][1]
  if len(q)>K;
    print(q[K-1])
    sys.exit()
Problem p03739 (python)

Fixed submission:
# -*- coding: utf-8 -*-
# 整数の入力
n=int(input())
a=input().split()
b=a[:]
c=a[:]
# a[0]の符号をそのままにした場合の計算
counter_1=0
S=int(a[0])
for i in range(1,n):
  if S<0 and S+int(a[i])<=0:
    counter_1+=-S-int(a[i])+1
    a[i]=-S+1
  elif S>0 and S+int(a[i])>=0:
    counter_1+=S+int(a[i])+1
    a[i]=-S-1
  S+=int(a[i])
# a[0]を1に変えた場合の計算
counter_2=abs(int(b[0])-1)
b[0]=1
S=b[0]
for i in range(1,n):
  if S<0 and S+int(b[i])<=0:
    counter_2+=-S-int(b[i])+1
    b[i]=-S+1
  elif S>0 and S+int(b[i])>=0:
    counter_2+=S+int(b[i])+1
    b[i]=-S-1
  S+=int(b[i])
# a[0]を-1に変えた場合の計算
counter_3=abs(int(c[0])+1)
c[0]=-1
S=c[0]
for i in range(1,n):
  if S<0 and S+int(c[i])<=0:
    counter_3+=-S-int(c[i])+1
    c[i]=-S+1
  elif S>0 and S+int(c[i])>=0:
    counter_3+=S+int(c[i])+1
    c[i]=-S-1
  S+=int(c[i])
print(min(counter_1,counter_2,counter_3))

Buggy submission (verdict: Runtime Error):
import sys
# -*- coding: utf-8 -*-
# 整数の入力
n=int(input())
a=list(map(int, input().split()))
b=a[:]
c=a[:]
# 無変更チェック
if a[0]!=0:
  S=int(a[0])
  for i in range(1,n):
    if S<0 and S+a[i]<=0:
      break
    elif S>0 and S+a[i]>=0:
      break
    S+=a[i]
    if i==n-1:
      print(0)
      sys.exit()
# a[0]を1に変えた場合の計算
counter_2=abs(b[0]-1)
b[0]=1
S=b[0]
for i in range(1,n):
  if S<0 and S+b[i]<=0:
    counter_2+=-S-b[i]+1
    b[i]=-S+1
  elif S>0 and S+b[i]>=0:
    counter_2+=S+b[i]+1
    b[i]=-S-1
  S+=b[i]
# a[0]を-1に変えた場合の計算
counter_3=abs(c[0]+1)
c[0]=-1
S=c[0]
for i in range(1,n):
  if S<0 and S+c[i]<=0:
    counter_3+=-S-c[i]+1
    c[i]=-S+1
  elif S>0 and S+c[i]>=0:
    counter_3+=S+c[i]+1
    c[i]=-S-1
  S+=c[i]
print(min(counter_1,counter_2,counter_3))

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
# 整数の入力
n=int(input())
a=input().split()
counter=0
S=a[0]
# 出力
for i in range(1,n):
  S+=a[i]
  if S<0 and S+int(a[i])<=0:
    counter+=-S-int(a[i])+1
    a[i]=-S+1
  elif S>0 and S+int(a[i])>=0:
    counter+=S+int(a[i])+1
    a[i]=-S-1
print(counter)
Problem p03760 (python)

Fixed submission:
# -*- coding: utf-8 -*-
# 整数の入力
A=input()
B=input()
ans=str()
if len(A)==len(B):
  for i in range (0,len(A)):
    ans+=A[i]+B[i]
else:
  for i in range (0,len(A)-1):
    ans+=A[i]+B[i]
  ans+=A[-1]
print(ans)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
# 整数の入力
A=input()
B=input()
ans=str()
if len(A)==len(B):
  for i in range (0,len(A)):
    ans+=A[i]+B[i]
else:
  for i in range (0,len(A)):
    ans+=A[i]+B[i]
  ans+=A[-1]
print(ans)
Problem p03773 (python)

Fixed submission:
# -*- coding: utf-8 -*-
# 整数の入力
n,m=list(map(int, input().split()))
print((n+m)%24)

Buggy submission (verdict: Runtime Error):
import math
N=int( input())
for r in range (int(math.sqrt(N)),0,-1):
  if N%r==0:
    count=1
    l=N/r
    for i in range (0,10):
      l=l/10
      if l<1:
        print(count)
        break
      count+=1
    break
Problem p03777 (python)

Fixed submission:
a,b=map(str, input().split())
if a==b:
  print("H")
else:
  print("D")

Buggy submission (verdict: Runtime Error):
import sys
N,K=map(int, input().split())
a=list(map(int, input().split()))
sum=0
for i in range(0,N):
  sum+=a[i]
if sum<K:#全部不必要
  print(N)
  sys.exit()
if sum==K:#全部必要
  print(0)
  sys.exit()
a.sort()
a.reverse()

#K未満の最大の数字のラベルはどこ？
l=N
for i in range(N-1,-1,-1):
  if a[i]<K:
    l=i
  else:
    break

if l==N:
  print(N)
  sys.exit()

count=N
#lまでの要素が必要か不要かチェック
for i in range(0,l):
  sum=0
  for j in range(l,N):
    if sum+a[j]<K:
      sum+=a[j]
  if sum+a[i]>=K:#必要ってことだ
    count-=1
#lからの要素は自分のことを抜かないといけないことに注意
for i in range(l,N):
  sum=0
  b=a[:]
  C=b.pop(i)
  for j in range(l-1,N-1):
    if sum+b[j]<K:
      sum+=b[j]
  if sum+C>=K:#必要ってことだ
    count-=1
print(count)
Problem p03797 (python)

Fixed submission:
S,C=map(int,input().split())
if C<2*S:
  print(int(C/2))
else:
  if (C-2*S)%4==0:
    k=(C-2*S)/4
  else:
    k=int(1+(C-2*S)/4)
  print(int((C-2*k)/2))

Buggy submission (verdict: Runtime Error):
S,C=map(int,input().split())
if C<2*S:
  print(int(C/2))
else:
  if (C-2*S)%4==0:
    k=(C-2*S)/4
  else:
    k=int(1+(C-2*S)/4)
print(int((C-2*k)/2))
Problem p03808 (python)

Fixed submission:
import sys
N=int(input())
A=list(map(int,input().split()))
total=0
for i in range(N):
  total+=A[i]
if total*2/((N+1)*N)%1!=0:
  print("NO")
  sys.exit()
times=int(total*2/((N+1)*N))
if (times-A[0]+A[N-1])/N%1!=0 or times-A[0]+A[N-1]<0:
  print("NO")
  sys.exit()
B=(times-A[0]+A[N-1])/N
for i in range(N-1):
  B+=(times-A[i+1]+A[i])/N
  if (times-A[i+1]+A[i])/N%1!=0 or times-A[i+1]+A[i]<0:
    print("NO")
    sys.exit()
if B==times:
  print("YES")
else:
  print("NO")

Buggy submission (verdict: Runtime Error):
import sys
N=int(input())
A=list(map(int,input().split()))
total=0
for i in range(N):
  total+=A[i]
if total*2/((N+1)*N)%1!=0:
  print("NO")
  sys.exit()
times=int(total*2/((N+1)*N))
if (times-A[0]+A[N-1])/N%1! or times-A[0]+A[N-1]<0=0:
  print("NO")
  sys.exit()
B=(times-A[0]+A[N-1])/N
for i in range(N-1):
  B+=(times-A[i+1]+A[i])/N
  if (times-A[i+1]+A[i])/N%1!=0 or times-A[i+1]+A[i]<0:
    print("NO")
    sys.exit()
if B==times:
  print("YES")
else:
  print("NO")
Problem p03827 (python)

Fixed submission:
N=int(input())
S=str(input())
t=[0]
s=0
for i in range(N):
  if S[i]=="I":
    s+=1
  else:
    s-=1
  t+=[s]
ans=0
for i in range(N+1):
  ans=max(ans,int(t[i]))
print(ans)

Buggy submission (verdict: Runtime Error):
N=int(input())
S=str(input())
t=[0]
s=0
for i in range(N):
if S[i]=="I":
  s+=1
else:
  s-=1
t+=[s]
ans=0
for i in range(N+1):
  ans=max(ans,int(t[i]))
print(ans)
Problem p03828 (python)

Fixed submission:
N=int(input())
R=[0]*(N-1)
for i in range(1,N+1):
  for r in range (2,N+1):
    count=0
    while i%r==0:
      i=i/r
      count+=1
    R[r-2]+=count

count=1
for r in range(N-1):
  count=count*(R[r]+1)
print(count%(10**9+7))

Buggy submission (verdict: Runtime Error):
import math
N=int(input())
M=math.factorial(N)
R=[]
for r in range (2,N+1):
  count=0
  while M%r==0:
    M=M/r
    count+=1
  R+=[count]

count=1
for r in range(N-1):
  count=count*(R[r]+1)
print(count)

Buggy submission (verdict: Runtime Error):
import math
N=int(input())
N=math.factorial(N)
r=math.sqrt(N)
count=0
if r%1==0:
  count-=1
for i in range(int(r)):
  if N%(1+i)==0:
    count+=2
print(count%(10**9+7))

Buggy submission (verdict: Runtime Error):
import math
N=int(input())
N=math.factorial(N)
r=math.sqrt(N)
count=0
if r%1==0:
  count-=1
for i in range(int(r)):
  if N%(1+i)==0:
    count+=2
print(count)
Problem p04015 (python)

Fixed submission:
N,A=map(int,input().split())
x=list(map(int,input().split()))
dp=[[[0 for i in range(50*50+1)] for j in range(N+1) ]for k in range(N+1)]
dp[0][0][0]=1
for i in range(1,N+1):
  for j in range(N+1):
    for k in range(50*50+1):
      dp[i][j][k]=dp[i-1][j][k]
      if x[i-1]<= k and j>0: dp[i][j][k]+=dp[i-1][j-1][k-x[i-1]]
ans=0
for j in range(1,N+1):
  ans+=dp[N][j][j*A]
print(ans)

Buggy submission (verdict: Runtime Error):
N,A=map(int,input().split())
x=list(map(int,input().split()))
dp=[[[0 for i in range(50*50)] for j in range(N+1) ]for k in range(N+1)]
dp[0][0][0]=1
for i in range(1,N+1):
  for j in range(N+1):
    for k in range(50*50):
      dp[i][j][k]=dp[i-1][j][k]
      if x[i-1]<= k and j>0: dp[i][j][k]+=dp[i-1][j-1][k-x[i-1]]
ans=0
for j in range(1,N+1):
  ans+=dp[N][j][j*A]
print(ans)

Buggy submission (verdict: Runtime Error):
N,A=map(int,input().split())
x=list(map(int,input().split()))
dp=[[[0 for i in range(50*50)] for j in range(N+1) ]for k in range(N+1)]
dp[0][0][0]=1
for i in range(1,N+1):
  for j in range(N+1):
    for k in range(50*50):
      dp[i][j][k]=dp[i-1][j][k]
      if x[i-1]<= k and j>0: dp[i][j][k]+=dp[i-1][j-1][k-x[i-1]]
ans=0
for j in range(1,N+1):
  ans+=dp[N][j][j*A]
print(ans)
Problem p04030 (python)

Fixed submission:
s=str(input())
while "B" in s:
  if s[0] == "B":
    s=s[1:]
  s=s.replace("0B","")
  s=s.replace("1B","")
print(s)

Buggy submission (verdict: Runtime Error):
s=str(input())
while "B" in s:
  if s[0] == "B":
    del s[0]
  s=s.replace("0B","")
  s=s.replace("1B","")
print(s)
Problem p04039 (python)

Fixed submission:
N,K=map(int,input().split())
D=list(map(int,input().split()))
def solve():
  for i in range(10*N+2):
    if i>=N:
      s=str(i)
      for j in range(len(s)):
        if int(s[j]) in D: break
      else:
        print(i)
        return 0

solve()

Buggy submission (verdict: Runtime Error):
def comb(n,k,p):
  """power_funcを用いて(nCk) mod p を求める"""
  from math import factorial
  if n<0 or k<0 or n<k: return 0
  if n==0 or k==0: return 1
  a=factorial(n) %p
  b=factorial(k) 
  c=factorial(n-k) 
  return (a*power_func(b,p-2,p)*power_func(c,p-2,p))%p
 
def power_func(a,b,p):
  """a^b mod p を求める"""
  if b==0: return 1
  if b%2==0:
    d=power_func(a,b//2,p)
    return d*d %p
  if b%2==1:
    return (a*power_func(a,b-1,p ))%p
 
H,W,A,B=map(int, input().split())
p=10**9+7
alls=comb(H+W-2,W-1,10**9+7)
for i in range(B):
  alls-=comb(H-A-1+i,H-A-1,p)*comb(W+A-2-i,A-1,p)
 
print(alls)
Problem p04044 (python)

Fixed submission:
N,L=map(int,input().split())
S=[]
for i in range(N):
  S+=[str(input())]
S.sort()
ans=""
for i in range(N):
  ans+=S[i]
print(ans)

Buggy submission (verdict: Runtime Error):
def power_func(a,b,p):
  """a^b mod p を求める"""
  if b==0: return 1
  if b%2==0:
    d=power_func(a,b//2,p)
    return d*d %p
  if b%2==1:
    return (a*power_func(a,b-1,p ))%p

from math import factorial
H,W,A,B=map(int, input().split())
p=10**9+7
ans=0
X=[1]
Y=[1]
for i in range(H+W-2):
  fact=factorial(i+1)%p
  X+=[fact]
  Y+=[power_func( fact, p-2,p)]
for i in range(B,W):
  ans+=X[H-A-1+i]*X[A+W-2-i]*(Y[H-A-1]*Y[i]*Y[A-1]*Y[W-1-i])%p

print(ans)
Problem p02687 (python)

Fixed submission:
S = input()
if S == "ABC":
  print("ARC")
else:
  print("ABC")

Buggy submission (verdict: Runtime Error):
S = input()
if S == ABC:
  print("ARC")
else:
  print("ABC")
Problem p02574 (python)

Fixed submission:
from sys import exit

def eratosthenes(n):
    '''
    n以下の整数の素数判定/列挙 (n > 1)
    O(NloglogN)
    '''
    for i in range(2, int(n**0.5) + 1):
        if is_prime[i]:
            for j in range(i*2, n+1, i):
                is_prime[j] = False

    return [i for i in range(n+1) if is_prime[i]]


def factorization(n):
    '''
    素因数分解
    O(√N)
    '''
    res = []
    m = 2
    while m ** 2 <= n:
        if n % m == 0:
            cnt = 0
            while n % m == 0:
                cnt += 1
                n //= m
            res.append([m, cnt])
        m += 1

    if n > 1:
        res.append([n, 1])

    return res


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

is_prime = [True] * (10**6+1)
is_prime[0] = False
is_prime[1] = False
judge = [False] * (10**6+1)
l1 = eratosthenes(10**6)

flag1 = True
for v1 in a:
    for v2 in l1:
        if is_prime[v1]:
            if judge[v1]:
                flag1 = False
            else:
                judge[v1] = True
            break

        if v1 % v2 == 0:
            if judge[v2]:
                flag1 = False
            else:
                judge[v2] = True
            
            while v1 % v2 == 0:
                v1 //= v2
        
        if v1 == 1:
            break
        
if flag1:
    print('pairwise coprime')
    exit()

l2 = factorization(a[0])
for i, j in l2:
    flag2 = True
    for v in a:
        if v % i != 0:
            flag2 = False
            break
    if flag2:
        print('not coprime')
        exit()

print('setwise coprime')

Buggy submission (verdict: Runtime Error):
from sys import exit
from math import gcd

def eratosthenes(n):
    '''
    n以下の整数の素数判定/列挙 (n > 1)
    O(NloglogN)
    '''
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    min_factor = [-1] * (n+1)
    min_factor[0] = 0
    min_factor[1] = 1
    
    for i in range(2, n+1):
        if is_prime[i]:
            min_factor[i] = i
            for j in range(i*2, n+1, i):
                is_prime[j] = False
                if min_factor[j] == -1:
                    min_factor[j] = i

    return min_factor


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

l = eratosthenes(20)

flag = True
used = [False] * (20)
for v in a:
    s = set()
    while v > 1:
        if l[v] not in s:
            if used[l[v]]:
                flag = False
                break
            else:
                s.add(l[v])
                used[l[v]] = True
        
        v //= l[v]

if flag:
    print('pairwise coprime')
    exit()

g = 0
for v in a:
    g = gcd(g, v)

print('setwise coprime' if g == 1 else 'not coprime')
Problem p02586 (python)

Fixed submission:
R, C, K = map(int,input().split())
MAP = [[0 for i in range(C)] for j in range(R)]
DP = [[[0 for i in range(C+1)] for j in range(4)] for k in range(R+1)]
 
for _ in range(K):
    r, c, v = map(int,input().split())
    MAP[r-1][c-1] = v
 
for i in range(R):
    for j in range(4):
        for k in range(C):
            DP[i+1][j][k+1] = max(DP[i][3][k+1], DP[i+1][j][k])
            if j == 0:
                continue
            v = MAP[i][k]
            if v == 0:
                continue
            DP[i+1][j][k+1] = max(DP[i+1][j][k+1], max(DP[i][3][k+1], DP[i+1][j-1][k]) + v)

print(DP[R][3][C])

Buggy submission (verdict: Runtime Error):
R, C, K = map(int, input().split())
goods = [[0] * C for _ in range(R)]
for _ in range(K):
    r, c, v = map(int, input().split())
    goods[r-1][c-1] = v

dp = [[[0] * 4 for _ in range(C)] for _ in range(R)]
dp[0][0][1] = goods[0][0]
for i in range(R):
    for j in range(C):
        if i < R - 1:
            dp[i+1][j][0] = max(dp[i+1][j][0], max(dp[i][j]))
            dp[i+1][j][1] = max(dp[i+1][j][1], max(dp[i][j]) + goods[i+1][j])
        
        if j < C - 1:
            for k in range(4):
                dp[i][j+1][k] = max(dp[i][j+1][k], dp[i][j][k])
            for k in range(3):
                dp[i][j+1][k+1] = max(dp[i][j+1][k+1], dp[i][j][k] + goods[i][j+1])

print(max(dp[R-1][C-1]))R, C, K = map(int, input().split())
goods = [[0] * C for _ in range(R)]
for _ in range(K):
    r, c, v = map(int, input().split())
    goods[r-1][c-1] = v

dp = [[[0] * 4 for _ in range(C)] for _ in range(R)]
dp[0][0][1] = goods[0][0]
for i in range(R):
    for j in range(C):
        if i < R - 1:
            dp[i+1][j][0] = max(dp[i+1][j][0], max(dp[i][j]))
            dp[i+1][j][1] = max(dp[i+1][j][1], max(dp[i][j]) + goods[i+1][j])
        
        if j < C - 1:
            for k in range(4):
                dp[i][j+1][k] = max(dp[i][j+1][k], dp[i][j][k])
            for k in range(3):
                dp[i][j+1][k+1] = max(dp[i][j+1][k+1], dp[i][j][k] + goods[i][j+1])

print(max(dp[R-1][C-1]))
Problem p02609 (python)

Fixed submission:
n = int(input())
x = input()

dp = [0] * n
for i in range(1, n-1):
    tmp = i
    cnt = 0
    while tmp > 0:
        cnt += tmp % 2
        tmp //= 2
    dp[i] = dp[i%cnt] + 1

c = x.count('1')

if c == 1:
    dp_2 = [0] * n
    dp_2[0] = 1 % (c + 1)
    for i in range(1, n):
        dp_2[i] = (2 * dp_2[i-1]) % (c + 1)

    mod_2 = 0
    for i in range(n):
        if x[i] == '1':
            mod_2 = (mod_2 + dp_2[n-i-1]) % (c + 1)

    for i in range(n):
        if x[i] == '1':
            print(0)
        else:
            mod = (mod_2 + dp_2[n-i-1]) % (c + 1)
            print(dp[mod] + 1)
else:
    dp_1 = [0] * n
    dp_2 = [0] * n
    dp_1[0] = 1 % (c - 1)
    dp_2[0] = 1 % (c + 1)
    for i in range(1, n):
        dp_1[i] = (2 * dp_1[i-1]) % (c - 1)
        dp_2[i] = (2 * dp_2[i-1]) % (c + 1)

    mod_1 = 0
    mod_2 = 0
    for i in range(n):
        if x[i] == '1':
            mod_1 = (mod_1 + dp_1[n-i-1]) % (c - 1)
            mod_2 = (mod_2 + dp_2[n-i-1]) % (c + 1)

    for i in range(n):
        if x[i] == '1':
            mod = (mod_1 - dp_1[n-i-1]) % (c - 1)
            print(dp[mod] + 1)
        else:
            mod = (mod_2 + dp_2[n-i-1]) % (c + 1)
            print(dp[mod] + 1)

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

dp = [0] * n
for i in range(1, n-1):
    tmp = i
    cnt = 0
    while tmp > 0:
        cnt += tmp % 2
        tmp //= 2
    dp[i] = dp[i % cnt] + 1

c = x.count('1')

dp_1 = [0] * n
dp_2 = [0] * n
dp_1[0] = 1 % (c - 1)
dp_2[0] = 1 % (c + 1)
for i in range(1, n):
    dp_1[i] = (2 * dp_1[i-1]) % (c - 1)
    dp_2[i] = (2 * dp_2[i-1]) % (c + 1)

mod_1 = 0
mod_2 = 0
for i in range(n):
    if x[i] == '1':
        mod_1 = (mod_1 + dp_1[n-i-1]) % (c - 1)
        mod_2 = (mod_2 + dp_2[n-i-1]) % (c + 1)

for i in range(n):
    if x[i] == '1':
        mod = (mod_1 - dp_1[n-i-1]) % (c - 1)
        print(dp[mod] + 1)
    else:
        mod = (mod_2 + dp_2[n-i-1]) % (c + 1)
        print(dp[mod] + 1)
Problem p02697 (python)

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

a = 1
b = m + 1
while a < b:
  print(a, b)
  a += 1
  b -= 1

a = m + 2
b = 2 * m + 1
while a < b:
  print(a, b)
  a += 1
  b -= 1

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
i = 0
j = 0

while True:
    if n // 2 - i * 2 - 1 <= 0:
        break
    print(i + 1, n // 2 - i)
    i += 1

while True:
    if i + j == m:
        break
    print(n // 2 + j + 1, n - j)
    j += 1
Problem p02714 (python)

Fixed submission:
n = int(input())
s = input()
dp = [[0] * 7 for i in range(4001)]

for i in range(n):
    if s[i] == 'R':
        dp[i + 1][0] = dp[i][0] + 1
        dp[i + 1][1] = dp[i][1]
        dp[i + 1][2] = dp[i][2]
        dp[i + 1][3] = dp[i][1] + dp[i][3]
        dp[i + 1][4] = dp[i][4]
        dp[i + 1][5] = dp[i][2] + dp[i][5]
        dp[i + 1][6] = dp[i][6] + dp[i][4]
    elif s[i] == 'G':
        dp[i + 1][0] = dp[i][0]
        dp[i + 1][1] = dp[i][1] + 1
        dp[i + 1][2] = dp[i][2]
        dp[i + 1][3] = dp[i][0] + dp[i][3]
        dp[i + 1][4] = dp[i][2] + dp[i][4]
        dp[i + 1][5] = dp[i][5]
        dp[i + 1][6] = dp[i][6] + dp[i][5]
    else:
        dp[i + 1][0] = dp[i][0]
        dp[i + 1][1] = dp[i][1]
        dp[i + 1][2] = dp[i][2] + 1
        dp[i + 1][3] = dp[i][3]
        dp[i + 1][4] = dp[i][1] + dp[i][4]
        dp[i + 1][5] = dp[i][0] + dp[i][5]
        dp[i + 1][6] = dp[i][6] + dp[i][3]
    for j in range(1, i // 2 + 1):
        if s[i] != s[i - j] and s[i] != s[i - j * 2] and s[i - j] != s[i - 2 * j]:
            dp[i + 1][6] -= 1
print(dp[n][6])

Buggy submission (verdict: Runtime Error):
n = int(input())
s = input()
dp = [[0] * 7 for i in range(4000)]

for i in range(n):
    if s[i] == 'R':
        dp[i + 1][0] = dp[i][0] + 1
        dp[i + 1][1] = dp[i][1]
        dp[i + 1][2] = dp[i][2]
        dp[i + 1][3] = dp[i][1] + dp[i][3]
        dp[i + 1][4] = dp[i][4]
        dp[i + 1][5] = dp[i][2] + dp[i][5]
        dp[i + 1][6] = dp[i][6] + dp[i][4]
    elif s[i] == 'G':
        dp[i + 1][0] = dp[i][0]
        dp[i + 1][1] = dp[i][1] + 1
        dp[i + 1][2] = dp[i][2]
        dp[i + 1][3] = dp[i][0] + dp[i][3]
        dp[i + 1][4] = dp[i][2] + dp[i][4]
        dp[i + 1][5] = dp[i][5]
        dp[i + 1][6] = dp[i][6] + dp[i][5]
    else:
        dp[i + 1][0] = dp[i][0]
        dp[i + 1][1] = dp[i][1]
        dp[i + 1][2] = dp[i][2] + 1
        dp[i + 1][3] = dp[i][3]
        dp[i + 1][4] = dp[i][1] + dp[i][4]
        dp[i + 1][5] = dp[i][0] + dp[i][5]
        dp[i + 1][6] = dp[i][6] + dp[i][3]
    for j in range(1, i // 2 + 1):
        if s[i] != s[i - j] and s[i] != s[i - j * 2] and s[i - j] != s[i - 2 * j]:
            dp[i + 1][6] -= 1
print(dp[n][6])
Problem p02765 (python)

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

if n >= 10:
    print(r)
else:
    print(r + 100 * (10 - n))

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

if n >= 10:
    print(r)
else:
    print(r + 100 * (10 - 2n))
Problem p02768 (python)

Fixed submission:
n, a, b = map(int, input().split())
mod = 10 ** 9 + 7
max = min(n, 2 * 10 ** 5)

fac1 = [n] * (max + 1)
fac2 = [1] * (max + 1)
for i in range(2, max + 1):
    fac1[i] = fac1[i - 1] * (n - i + 1) % mod
    fac2[i] = fac2[i - 1] * i % mod
c = fac1[a] * pow(fac2[a], mod - 2, mod) % mod
d = fac1[b] * pow(fac2[b], mod - 2, mod) % mod

print((pow(2, n, mod) - c - d - 1) % mod)

Buggy submission (verdict: Runtime Error):
n, a, b = map(int, input().split())
mod = 10 ** 9 + 7
max = min(n, 2 * 10 ** 5)

fac1 = [n] * max
fac2 = [1] * max
for i in range(2, max):
    fac1[i] = fac1[i - 1] * (n - i + 1) % mod
    fac2[i] = fac2[i - 1] * i % mod
c = fac1[a] * pow(fac2[a], mod - 2, mod) % mod
d = fac1[b] * pow(fac2[b], mod - 2, mod) % mod

print((pow(2, n, mod) - c - d - 1) % mod)
Problem p02788 (python)

Fixed submission:
from math import ceil
from collections import deque
N, D, A = map(int, input().split())
Monsters = sorted([list(map(int, input().split())) for i in range(N)])
Monsters = [[x, ceil(h / A)] for x, h in Monsters]


acc_damage = 0
que = deque([])

ans = 0
for x, h in Monsters:
    while que and x > que[0][0]:
        limit, damage = que.popleft()
        acc_damage -= damage

    need = max(0, h - acc_damage)
    ans += need
    acc_damage += need

    if need:
        que.append([x + 2 * D, need])

print(ans)

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

n, d, a = map(int, input().split())
m = sorted([list(map(int, input().split())) for _ in range(n)])
m = [[x, ceil(h / A)] for x, h in m]

acc_damage = 0
que = deque()
ans = 0
for x, h in m:
    while que and x > que[0][0]:
        limit, damage = que.popleft()
        acc_damage -= damage

    need = max(0, h - acc_damage)
    ans += need
    acc_damage += need

    if need:
        que.append([x + 2 * d, need])

print(ans)