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

Fixed submission:
N,K = list(map(int,input().split()))
B = K
R = N-K

MAXN = 2000+5
p = 10**9+7
MOD = p
f = [1]
for i in range(MAXN):
    f.append(f[-1] * (i+1) % MOD)
def nCr(n, r, mod=MOD):
    return f[n] * pow(f[r], mod-2, mod) * pow(f[n-r], mod-2, mod) % mod

for i in range(1,K+1):
    if (i>R+1) or (i-1>B-1):
        print(0)
    else:
        X = nCr(R+1, i, mod=p)
        Y = nCr(B-1, i-1, mod=p)
        print(X*Y%p)

Buggy submission (verdict: Runtime Error):
[N,K] = list(map(int,input().split()))
R = N-K
if N==K:
    print(1)
    for i in range(2,K+1):
        print(0)
elif K == 1:
    print(int((N-K+1)%(10**9+7)))
else:
    print(int((N-K+1)%(10**9+7)))
    for i in range(2,K+1):
        if i>R+1:
            print(0)
            continue
        C1 = 1
        bo = i-1
        shi = K-1
        while bo!=0:
            C1 *= shi/bo
            if C1 > 2*10**9+7:
                C1 = C1 - 2*10**9+7
            shi += -1
            bo += -1
        R2 = R - (i-1)
        C2 = 1
        bo = i
        shi = R2+i
        while bo!=0:
            C2 *= shi/bo
            if C2 > 2*10**9+7:
                C2 = C2 - 2*10**9+7
            shi += -1
            bo += -1
        print(int((C1*C2)%(10**9+7)))

Buggy submission (verdict: Runtime Error):
[N,K] = list(map(int,input().split()))
R = N-K
if N==K:
    print(1)
    for i in range(2,K+1):
        print(0)
elif K == 1:
    print(int((N-K+1)%(10**9+7)))
else:
    print(int((N-K+1)%(10**9+7)))
    for i in range(2,K+1):
        if i>R+1:
            print(0)
            continue
        C1 = 1
        bo = i-1
        shi = K-1
        while bo!=0:
            C1 *= shi/bo
            shi += -1
            bo += -1
        R2 = R - (i-1)
        C2 = 1
        bo = i
        shi = R2+i
        while bo!=0:
            C2 *= shi/bo
            shi += -1
            bo += -1
        print(int((C1*C2)%(10**9+7)))

Buggy submission (verdict: Runtime Error):
[N,K] = list(map(int,input().split()))
R = N-K

print(int((N-K+1)%(10**9+7)))
for i in range(2,K+1):
    if i>R+1:
        print(0)
        continue
    C1 = 1
    bo = i-1
    shi = K-1
    while bo!=0:
        C1 *= shi/bo
        shi += -1
        bo += -1
    R2 = R - (i-1)
    C2 = 1
    bo = i
    shi = R2+i
    while bo!=0:
        C2 *= shi/bo
        shi += -1
        bo += -1
    print(int((C1*C2)%(10**9+7)))

Buggy submission (verdict: Runtime Error):
[N,K] = list(map(int,input().split()))
R = N-K

print(int((N-K+1)%(10**9+7)))
for i in range(2,K+1):
    if i>R+1:
        print(0)
    C1 = 1
    bo = i-1
    shi = K-1
    while bo>0:
        C1 *= shi/bo
        shi += -1
        bo += -1
    R2 = R - (i-1)
    C2 = 1
    bo = i
    shi = R2+i
    while bo>0:
        C2 *= shi/bo
        shi += -1
        bo += -1
    print(int((C1*C2)%(10**9+7)))
Problem p03003 (python)

Fixed submission:
[N,M] = list(map(int,input().split()))
S = list(map(int,input().split()))
T = list(map(int,input().split()))

ta = [[0] * (M+1) for i in range(N+1)]
ta[0][0]=1
wa = [[0] * (M+1) for i in range(N+1)]
wa[0][:]=[1]*(M+1)
for i in range(N+1):
    wa[i][0]=1
output = 1
for i in range(1,N+1):
    for j in range(1,M+1):
        if S[i-1]==T[j-1]:
            ta[i][j]=wa[i-1][j-1]
            wa[i][j]=(wa[i-1][j]+wa[i][j-1])%(10**9+7)
        else:
            wa[i][j]=(wa[i-1][j]+wa[i][j-1]-wa[i-1][j-1]+(10**9+7))%(10**9+7)
output = wa[N][M]
print(int(output))

Buggy submission (verdict: Runtime Error):
import numpy as np
[N,M] = list(map(int,input().split()))
S = list(map(int,input().split()))
T = list(map(int,input().split()))

ta = np.zeros((N+1,M+1))
ta[0,0]=1
wa = np.zeros((N+1,M+1))
wa[0,:]=1
wa[:,0]=1
output = 1
for i in range(1,N+1):
    for j in range(1,M+1):
        if S[i-1]==T[j-1]:
            ta[i,j]=wa[i-1,j-1]
            wa[i,j]=wa[i-1,j]+wa[i,j-1]
        else:
            wa[i,j]=wa[i-1,j]+wa[i,j-1]-wa[i-1,j-1]
output = wa[N,M]%(10**9+7)
print(int(output))
Problem p03041 (python)

Fixed submission:
listNK = list(map(int,input().split()))
S = list(input())

if S[listNK[1]-1]=="A":
    S[listNK[1]-1] = "a"
if S[listNK[1]-1]=="B":
    S[listNK[1]-1] = "b"
if S[listNK[1]-1]=="C":
    S[listNK[1]-1] = "c"

output = ""
for i in range(listNK[0]):
    output = output + S[i]

print(output)

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

if S[listNK[1]-1]=="A":
    S[listNK[1]-1] = "a"
if S[listNK[1]-1]=="B":
    S[listNK[1]-1] = "b"
if S[listNK[1]-1]=="C":
    S[listNK[1]-1] = "c"

output = ""
for i in range(listNK[0]):
    output = output + S[i]

print(output)
Problem p03253 (python)

Fixed submission:
N,M = list(map(int,input().split()))

MAXN = 2*(10**5)+10
p = 10**9+7
MOD = p
f = [1]
for i in range(MAXN):
    f.append(f[-1] * (i+1) % MOD)
def nCr(n, r, mod=MOD):
    return f[n] * pow(f[r], mod-2, mod) * pow(f[n-r], mod-2, mod) % mod

def prime(X):
    pf={}
    m=X
    for i in range(2,int(m**0.5)+1):
        while m%i==0:
            pf[i]=pf.get(i,0)+1
            m//=i
    if m>1:pf[m]=1
    return pf

pf = prime(M)
powers = list(pf.values())

out = 1
for power in powers:
    out = out*nCr(power+N-1,power)%p

print(out)

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

MAXN = (10**5)+10
p = 10**9+7
MOD = p
f = [1]
for i in range(MAXN):
    f.append(f[-1] * (i+1) % MOD)
def nCr(n, r, mod=MOD):
    return f[n] * pow(f[r], mod-2, mod) * pow(f[n-r], mod-2, mod) % mod

def prime(X):
    pf={}
    m=X
    for i in range(2,int(m**0.5)+1):
        while m%i==0:
            pf[i]=pf.get(i,0)+1
            m//=i
    if m>1:pf[m]=1
    return pf

pf = prime(M)
powers = list(pf.values())

out = 1
for power in powers:
    out = out*nCr(power+N-1,power)%p

print(out)
Problem p02689 (python)

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

judge = ["ok" for i in range(n)]

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

    if high[a] < high[b]:
        judge[a] = "ng"
    elif high[a] > high[b]:
        judge[b] = "ng"
    else:
        judge[a] = "ng"
        judge[b] = "ng"

print(judge.count("ok"))

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

judge = ["ok" for i in range(n)]

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

    if high[a] < high[b]:
        judge[a] = "ng"
    elif high[a] > high[b]:
        judge[b] = "ng"
    else:
        judge[a] = "ng"
        judge[b] = "ng"

print(judge.count("ok"))
Problem p02549 (python)

Fixed submission:
# Binary Indexed Tree (Fenwick Tree)
class BIT:
  def __init__(self, n):
    self.n = n
    self.bit = [0]*(n+1)
    self.el = [0]*(n+1)
  def sum(self, i):
    s = 0
    while i > 0:
      s += self.bit[i]
      i -= i & -i
    return s
  def add(self, i, x):
    # assert i > 0
    self.el[i] += x
    while i <= self.n:
      self.bit[i] += x
      i += i & -i
  def get(self, i, j=None):
    if j is None:
      return self.el[i]
    return self.sum(j) - self.sum(i-1)

mod = 998244353
N, K = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(K)]
A.sort()
dp = BIT(N)
dp.add(1,1)
for i in range(2,N+1):
  for l,r in A:
    if i-l<=0:
      continue
    if i-r>0:
      dp.add(i,dp.get(i-r,i-l)%mod)
    else:
      dp.add(i,dp.sum(i-l)%mod)
print(dp.el[-1]%mod)

Buggy submission (verdict: Runtime Error):
# Binary Indexed Tree (Fenwick Tree)
class BIT:
  def __init__(self, n):
    self.n = n
    self.bit = [0]*(n+1)
    self.el = [0]*(n+1)
  def sum(self, i):
    s = 0
    while i > 0:
      s += self.bit[i]
      i -= i & -i
    return s
  def add(self, i, x):
    # assert i > 0
    self.el[i] += x
    while i <= self.n:
      self.bit[i] += x
      i += i & -i
  def get(self, i, j=None):
    if j is None:
      return self.el[i]
    return self.sum(j) - self.sum(i-1)

mod = 998244353
N, K = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(K)]
A.sort()
dp = BIT(N)
dp.add(1,1)
for i in range(2,N+1):
  for l,r in A:
    if i-l<=0:# Binary Indexed Tree (Fenwick Tree)
class BIT:
  def __init__(self, n):
    self.n = n
    self.bit = [0]*(n+1)
    self.el = [0]*(n+1)
  def sum(self, i):
    s = 0
    while i > 0:
      s += self.bit[i]
      i -= i & -i
    return s
  def add(self, i, x):
    # assert i > 0
    self.el[i] += x
    while i <= self.n:
      self.bit[i] += x
      i += i & -i
  def get(self, i, j=None):
    if j is None:
      return self.el[i]
    return self.sum(j) - self.sum(i-1)

mod = 998244353
N, K = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(K)]
A.sort()
dp = BIT(N)
dp.add(1,1)
for i in range(2,N+1):
  for l,r in A:
    if i-l<=0:
      continue
    if i-r>0:
      dp.add(i,dp.get(i-r,i-l)%mod)
    else:
      dp.add(i,dp.sum(i-l)%mod)
print(dp.el[-1]%mod)


      continue
    if i-r>0:
      dp.add(i,dp.get(i-r,i-l)%mod)
    else:
      dp.add(i,dp.sum(i-l)%mod)
print(dp.el[-1]%mod)
Problem p02550 (python)

Fixed submission:
N, X, M = map(int, input().split())
if M==1:
  print(0)
  exit()
lis = [0]*M
lis[0] = X
check = [-1]*M
check[X] = 0
for i in range(1,M):
  lis[i] = pow(lis[i-1],2,M)
  if check[lis[i]]>=0:
    cyc = i-check[lis[i]]
    start = check[lis[i]]
    break
  check[lis[i]] = i
from itertools import groupby, accumulate, product, permutations, combinations
cum = list(accumulate(lis))
cyc_cum = cum[-1]-cum[start]
if N-1<=start+cyc:
  ans = cum[N-1]
else:
  ans = cyc_cum*((N-1-start)//cyc)+cum[(N-1-start)%cyc+start]
print(ans)

Buggy submission (verdict: Runtime Error):
N, X, M = map(int, input().split())
lis = [0]*M
lis[0] = X
check = [-1]*M
check[X] = 0
for i in range(1,M):
  lis[i] = pow(lis[i-1],2,M)
  if check[lis[i]]>=0:
    cyc = i-check[lis[i]]
    start = check[lis[i]]
    break
  check[lis[i]] = i
from itertools import groupby, accumulate, product, permutations, combinations
cum = list(accumulate(lis))
cyc_cum = cum[-1]-cum[start]
if N-1<=start+cyc:
  ans = cum[N-1]
else:
  ans = cyc_cum*((N-1-start)//cyc)+cum[(N-1-start)%cyc+start]
print(ans)

Buggy submission (verdict: Runtime Error):
N, X, M = map(int, input().split())
lis = [0]*M
lis[0] = X
check = [-1]*M
check[X] = 0
for i in range(1,M):
  lis[i] = pow(lis[i-1],2,M)
  if check[lis[i]]>=0:
    cyc = i-check[lis[i]]
    start = check[lis[i]]
    break
  check[lis[i]] = i
from itertools import groupby, accumulate, product, permutations, combinations
cum = list(accumulate(lis))
cyc_cum = cum[-1]-cum[start]
if N<=start:
  ans = cum[N-1]
else:
  ans = cyc_cum*((N-start)//cyc)+cum[(N-start)%cyc+start-1]
print(ans)
Problem p02551 (python)

Fixed submission:
# N: 処理する区間の長さ 0_indexed
class SegmentTree:
  def __init__(self,N):
    self.N0 = 2**(N-1).bit_length()
    self.data = [None]*(2*self.N0)
    self.INF = (-1, 2**31-1)
  # 区間[l, r+1)の値をvに書き換える
  # vは(t, value)という値にする (新しい値ほどtは大きくなる)
  def update(self, l, r, v):
    L = l + self.N0; R = r + self.N0
    while L < R:
      if R & 1:
        R -= 1
        self.data[R-1] = v
      if L & 1:
        self.data[L-1] = v
        L += 1
      L >>= 1; R >>= 1
  # a_iの現在の値を取得
  def _query(self, k):
    k += self.N0-1
    s = self.INF
    while k >= 0:
      if self.data[k]:
        s = max(s, self.data[k])
      k = (k - 1) // 2
    return s
  # これを呼び出す
  def query(self,k):
    return self._query(k)[1]

N, Q = map(int, input().split())
row = SegmentTree(N-2)
col = SegmentTree(N-2)
ans = (N-2)*(N-2)
row.update(0,N-2,(0,N-2))
col.update(0,N-2,(0,N-2))
min_row = N
min_col = N
for i in range(1,Q+1):
  t,x = map(int, input().split())
  if t==1:
    num = col.query(x-2)
    ans -= num
    if x<min_col:
      row.update(0,num,(i,x-2))
      min_col = x
  else:
    num = row.query(x-2)
    ans -= num
    if x<min_row:
      col.update(0,num,(i,x-2))
      min_row = x
print(ans)

Buggy submission (verdict: Runtime Error):
# N: 処理する区間の長さ
N, Q = map(int, input().split())
INF = 2**31

N-=1
LV = (N-1).bit_length()
N0 = 2**LV
data1 = [INF]*(2*N0)
data2 = [INF]*(2*N0)
lazy1 = [None]*(2*N0)
lazy2 = [None]*(2*N0)

# 伝搬対象の区間を求める
def gindex(l, r):
    L = (l + N0) >> 1; R = (r + N0) >> 1
    lc = 0 if l & 1 else (L & -L).bit_length()
    rc = 0 if r & 1 else (R & -R).bit_length()
    for i in range(LV):
        if rc <= i:
            yield R
        if L < R and lc <= i:
            yield L
        L >>= 1; R >>= 1

# 遅延伝搬処理
def propagates(data,lazy,*ids):
    for i in reversed(ids):
        v = lazy[i-1]
        if v is None:
            continue
        lazy[2*i-1] = data[2*i-1] = lazy[2*i] = data[2*i] = v
        lazy[i-1] = None

# 区間[l, r)をxで更新
def update(l, r, x, data,lazy):
    *ids, = gindex(l, r)
    propagates(data,lazy,*ids)

    L = N0 + l; R = N0 + r
    while L < R:
        if R & 1:
            R -= 1
            lazy[R-1] = data[R-1] = x
        if L & 1:
            lazy[L-1] = data[L-1] = x
            L += 1
        L >>= 1; R >>= 1
    for i in ids:
        data[i-1] = min(data[2*i-1], data[2*i])


ans = (N-2)*(N-2)
update(1,N-1,N-2,data1,lazy1)
update(1,N-1,N-2,data2,lazy2)
for i in range(Q):
  t,x = map(int, input().split())
  if t==1:
    ans -= data1[x-1]
    update(1,data1[x-1],x,data2,lazy2)
  else:
    ans -= data2[x-1]
    update(1,data2[x-1],x,data1,lazy1)
print(ans)
Problem p02629 (python)

Fixed submission:
N = int(input())
lis = [0,26]
num = 26
n = 1
while lis[-1]<N:
    num *= 26
    lis.append(lis[-1]+num)
    n += 1
c = N-lis[-2]-1
ans = ''
for i in range(n):
    ans = chr(c%26+ord('a')) + ans
    c //= 26
print(ans)

Buggy submission (verdict: Runtime Error):
def solve():
  N = int(input())
  k = 1
  while N>pow(26,k):
    N -= pow(26,k)
    k += 1
  ans = ''
  N -= 1
  for i in range(k,1,-1):
    ans += chr(ord('a')+N//pow(26,i-1))
    N%=pow(26,i-1)
  ans += chr(ord('a')+N%pow(26,i))
  return ans
print(solve())
Problem p02723 (python)

Fixed submission:
S = input()
ans = 'No'
if S[2]==S[3] and S[4]==S[5]:
  ans = 'Yes'
print(ans)

#print(*ans, sep='\n')

Buggy submission (verdict: Runtime Error):
N, X, Y = map(int, input().split())
ans = [0]*N

for i in range(1,N+1):
  for j in range(i+1,N+1):
    d = min(j-i,abs(i-X)+abs(j-Y)+1)
    #print(i,j,d)
    ans[d]+=1

for i in range(1,N):
	print(ans[i])
Problem p02729 (python)

Fixed submission:
N, M = map(int, input().split())

ans = N*(N-1)//2+M*(M-1)//2
print(ans)

Buggy submission (verdict: Runtime Error):
import itertools
H, W, K = map(int, input().split())

S = [0]*H
for i in range(H):
  S[i] = input()
Sdivs = []
mcnt = 1100
for b in itertools.product([0, 1], repeat=H-1):
  start = 0
  end = 1
  Sdivs=[]
  for a in b:
    if a==1:
      Sdivs.append(S[start:end])
      start = end
    end += 1
  Sdivs.append(S[start:end])
  cnt = sum(b)
  ones_cum = [0]*len(Sdivs)
  ones = [0]*len(Sdivs)
  mark1,mark2 = False,False
  ws = [0]
  for w in range(1,W):
    if mark2 == True:
      #print(mark)
      break
    for i,Sdiv in enumerate(Sdivs):
      #print(w)
      for s in Sdiv:
        ones_cum[i] += s[w-1]=='1'
        ones[i] += s[w-1]=='1'
      if ones_cum[i] > K:
        mark1 = True
        if w-1 == ws[-1]:
          mark2 = True
        ws.append(w-1)
      #print(ones_cum,ws)
    if mark1 == True:
      mark1 = False
      ones_cum = ones
    ones = [0]*len(Sdivs)
  if mark2 == True:
    continue
  cnt += len(ws)-1
  mcnt = min(mcnt,cnt)
print(mcnt)
Problem p02759 (python)

Fixed submission:
print(int((int(input())+1)/2))

Buggy submission (verdict: Runtime Error):
N, M, K = map(int, input().split())
friend = [[] for _ in range(N+1)]
block = [[] for _ in range(N+1)]

for i in range(M):
  A,B = map(int, input().split())
  friend[A].append(B)
  friend[B].append(A)

for i in range(K):
  C,D = map(int, input().split())
  block[C].append(D)
  block[D].append(C)
#print(friend)
#print(block)

#import queue
grouping = [False]*(N+1)
#print(grouping)
grouping[0] = True
group = [0]*(N+1)
g_num = 0
g_cnt = []
for i in range(1,N+1):
  cnt = 0
  if grouping[i] == True:
    continue 
  group[i] = g_num
  grouping[i] = True
  #q = queue.Queue()
  #q.put(i)
  stack = [i]
  #while not q.empty():
  while len(stack)>0:
    #print('v:',visited)
    #p = q.get()
    p = stack.pop()
    for f in friend[p]:
      #print(p,f)
      if grouping[f]==False:
        #q.put(f)
        stack.append(f)
        group[f]=g_num
        grouping[f] =True
        cnt += 1
  g_num += 1
  g_cnt.append(cnt)
  #print('g:',grouping)
ans = []
for i in range(1,N+1):
  c = g_cnt[group[i]]-len(friend[i])
  for b in block[i]:
    if group[b]==group[i]:
      c -= 1
  ans.append(c)
print(*ans)
Problem p02833 (python)

Fixed submission:
import math

N = int(input())
if N%2 == 1 or N<10:
  print(0)
  exit()
five = N//10
for i in range(int(math.log(N//10,5))):
  five += N//(10*5**(i+1))
print(five)

Buggy submission (verdict: Runtime Error):
import math

N = int(input())
if N%2 == 1:
  print(0)
  exit()
five = N//10
for i in range(int(math.log(N//10,5))):
  five += N//(10*5**(i+1))
print(five)
124999999999999995
Problem p02863 (python)

Fixed submission:
#dp[n][t]=max(dp[n-1][t],dp[n-1][t-A[n]]+B[n])
#dp[0][t]=0, dp[n][0]=0,0<=t<=T+max(B)-1, 0<=n<=N
def solve():
    N, T = map(int, input().split())
    X = [list(map(int, input().split())) for _ in range(N)]
    X.sort()
    dp = [[0]*(T+3000) for _ in range(N+1)]
    for n in range(1,N+1):
        for t in range(1,T+X[n-1][0]):
            dp[n][t]=dp[n-1][t]
            if t>=X[n-1][0]:
                dp[n][t]=max(dp[n][t],dp[n-1][t-X[n-1][0]]+X[n-1][1])
    ans = max(dp[N])
    return ans
print(solve())

Buggy submission (verdict: Runtime Error):
import numpy as np
import numba
from numba import njit, b1, i4, i8, f8

@njit((i8,i8,i8[:,:]), cache=True)
def main(N,T,A):
  dp = np.zeros(T+1,np.int64)
  for a,b in A:
    for t in range(T-1,-1,-1):
      u = min(T,t+a)
      dp[u] = max(dp[u],dp[t]+b)
  ans = dp[-1]
  return ans

N, T = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(N)]
A = np.array(sorted(A))
print(main(N,T,A))
Problem p02879 (python)

Fixed submission:
import math
A, B = map(int, input().split())
if A>9 or B>9:
  print(-1)
  exit()
print(A*B)

Buggy submission (verdict: Runtime Error):
N = int(input())
kuku = []
for i in range(1,10):
  for j in range(1,10):
    kuku.append(i*j)
if N in kuku:
  print('Yes')
else:
  print('No')
Problem p02891 (python)

Fixed submission:
S = input()
K = int(input())

if len(set(S))==1:
  ans = int(len(S)*K/2)
elif K == 1:
  ans = 0
  serial = 1
  #print(serial)
  for i in range(len(S)-1):
    if S[i] == S[i+1]:
      serial += 1
    else:
      ans += int(serial/2)
      serial = 1
  ans += int(serial/2)
else:
  #first
  first=0
  serial = 1
  for i in range(len(S)-1):
    if S[i] == S[i+1]:
      serial += 1
    else:
      first += int(serial/2)
      serial = 1
  initial = 1
  for i in range(len(S)-1,1,-1):
    if S[i]==S[i-1]:
      initial += 1
    else:
      break
  cnt = 0
  serial = initial
  #print(serial)
  for i in range(len(S)):
    if S[i] == S[i-1]:
      serial += 1
    else:
      cnt += int(serial/2)
      serial = 1
    #print(cnt)
  #last
      
  #print(cnt)
  last = 0
  serial = initial
  for i in range(len(S)):
    if S[i] == S[i-1]:
      serial += 1
    else:
      last += int(serial/2)
      serial = 1
  last += int(serial/2)
  #print(first,cnt,last)
  ans = first+(K-2)*cnt+last

print(ans)

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

cnt = 0
serial = 1
for i in range(len(S)):
  if S[i] == S[(i+1)%len(S)]:
    serial += 1
  else:
    cnt += int(serial/2)
    serial = 1
  #print(serial)
cnt += int(serial/2)
      
#print(cnt)
if S[0]==S[-1] and S[-1]!=S[-2]:
  ans = cnt*K-1
  
else:
  ans = cnt*K

print(ans)
Problem p02925 (python)

Fixed submission:
def solve():
  ans = 0
  N = int(input())
  stacks = [list(map(lambda x:int(x)-1, input().split()))[::-1] for _ in range(N)]
  lis = [0]*N
  cnt = 0
  now = 0
  flag = 0
  while cnt<N*(N-1)//2:
    while not stacks[now]:
      now = (now+1)%N
    a = stacks[now][-1]
    while not stacks[a]:
      now = (now+1)%N
      a = stacks[now][-1]
    if stacks[a][-1] == now:
      lis[now] = max(lis[now],lis[a])+1
      lis[a] = lis[now]
      stacks[a].pop(-1)
      stacks[now].pop(-1)
      cnt += 1
      flag = 0
    else:
      now = a
      flag += 1
    if flag==N:
      return -1
  ans = max(lis)
  return ans
print(solve())

Buggy submission (verdict: Runtime Error):
def solve():
  ans = 0
  N = int(input())
  stacks = [list(map(lambda x:int(x)-1, input().split()))[::-1] for _ in range(N)]
  lis = [0]*N
  cnt = 0
  now = 0
  flag = 0
  while cnt<N*(N-1)//2:
    if not stacks[now]:
      now += 1
    a = stacks[now][-1]
    if stacks[a][-1] == now:
      lis[now] = max(lis[now],lis[a])+1
      lis[a] = lis[now]
      stacks[a].pop(-1)
      stacks[now].pop(-1)
      cnt += 1
    else:
      now = a
      flag += 1
    if flag==N:
      return -1
  ans = max(lis)
  return ans
print(solve())
Problem p02933 (python)

Fixed submission:
a = int(input())
s = input()
if a>=3200:
  print(s)
else:
  print('red')

Buggy submission (verdict: Runtime Error):
N, Q = map(int, input().split())
edge = [[] for _ in range(N)]
for i in range(N-1):
    a,b = map(int, input().split())
    edge[a-1].append(b-1)
    edge[b-1].append(a-1)

ans = [0]*N
for i in range(Q):
    p, x = map(int, input().split())
    ans[p-1] += x

from collections import deque

visited = [False]*N
d = deque([0])
while len(d)>0:
    v = d.popleft()
    visited[v]= True
    for u in edge[v]:
        if visited[u]==False:
            ans[u] += ans[v]
            visited[u]=True
            d.append(u)

print(*ans, sep=' ')
Problem p03011 (python)

Fixed submission:
A, B, C = map(int, input().split())
print(A+B+C-max(A,B,C))

Buggy submission (verdict: Runtime Error):
#import numpy as np
H, W = map(int, input().split())
S = [0]*H
counth = [[0]*W for _ in range(H)]  
countw = [[0]*W for _ in range(H)]

for i in range(H):
  S[i] = input()
  
for i in range(H):
  for j in range(W):
    if S[i][j]=='.':
      if counth[i][j]==0:
        b=False
        for k,s in enumerate(S[i][j:]):
          if s=='#':
            b = True
            break
        if b==False:
          k+=1
        #print(S[i][j:],l)
        counth[i][j:j+k]=[k]*k
      if countw[i][j]==0:
        b=False
        for k in range(i,H):
          if S[k][j]=='#':
            b=True
            break
        if b==False:
          k+=1
        #print(S[i:][j],m)
        for l in range(i,k):
          #print(i,j,l)
          countw[l][j]=k
      #print(i,j,count)
#print(count)
maxim = 0
for i in range(H):
  for j in range(W):
    maxim = int(max(maxim,counth[i][j]+countw[i][j]-1))
print(maxim)
Problem p03209 (python)

Fixed submission:
N, X = map(int, input().split())

def burger(N,X):
  #print(N,X)
  if N == 0 and X == 1:
    return 1
  if X == 0:
    return 0
  twopow = pow(2,N)
  if X == 4*twopow-3:
    return 2*twopow-1
  if X > 2*twopow-2:
    return twopow + burger(N-1,X-2*twopow+1)
  elif X <= 2*twopow-2:
    return burger(N-1,X-1)

print(burger(N,X))

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

def burger(N,X):
  #print(N,X)
  if N == 0 and X == 1:
    return 1
  if X == 0:
    return 0
  twopow = pow(2,N)
  if X > 2*twopow-2:
    return twopow + burger(N-1,X-2*twopow+1)
  elif X <= 2*twopow-2:
    return burger(N-1,X-1)

print(burger(N,X))

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

def burger(N,X):
  #print(N,X)
  if N == 0 and X == 1:
    return 1
  if X == 0:
    return 0
  twopow = pow(2,N)
  if X > 2*twopow-2:
    return twopow + burger(N-1,X-2*twopow+1)
  elif X <= 2*twopow-3:
    return burger(N-1,X-1)

print(burger(N,X))

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

def burger(N,X):
  print(N,X)
  if N == 0 and X == 1:
    return 1
  if X == 0:
    return 0
  twopow = pow(2,N)
  if X > 2*twopow-2:
    return twopow + burger(N-1,X-2*twopow+1)
  elif X <= 2*twopow-3:
    return burger(N-1,X-1)

print(burger(N,X))