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

Fixed submission:
import sys


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


def unite(x, y):
    x = root(x)
    y = root(y)
    if x == y:
        return False
    else:
        if y > x:
            x, y = y, x
        parent[x] += parent[y]
        parent[y] = x
        return True


def size(node):
    return -parent[root(node)]

if __name__ == '__main__':
    input = sys.stdin.readline
    n, m = map(int, input().split())
    input_list = [list(map(int, input().split())) for _ in range(m)]
    parent = [-1] * n
    ans_list = []
    ans = int(n*(n-1)/2)
    for a, b in input_list[::-1]:
        ans_list.append(ans)
        tmp = size(a-1) * size(b-1)
        if unite(a-1, b-1):
            ans -= tmp

    for ans in ans_list[::-1]:
        print(ans)

Buggy submission (verdict: Runtime Error):
import sys


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


def unite(x, y):
    x = root(x)
    y = root(y)
    if x != y:
        parent[x] = y
        new_size = size_list[x] + size_list[y]
        size_list[x] = new_size
        size_list[y] = new_size


if __name__ == '__main__':
    input = sys.stdin.readline
    n, m = map(int, input().split())
    input_list = [list(map(int, input().split())) for _ in range(m)]
    parent = [i for i in range(n)]
    size_list = [1] * n
    ans_list = []
    ans = int(n*(n-1)/2)
    for a, b in input_list[::-1]:
        ans_list.append(ans)
        if root(a-1) != root(b-1):
            ans -= size_list[a-1] * size_list[b-1]
        unite(a-1, b-1)
    for ans in ans_list[::-1]:
        print(ans)

Buggy submission (verdict: Runtime Error):
import sys


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


def unite(x, y):
    x = root(x)
    y = root(y)
    if x != y:
        parent[x] = y
        new_size = size_list[x] + size_list[y]
        size_list[x] = new_size
        size_list[y] = new_size


if __name__ == '__main__':
    input = sys.stdin.readline
    n, m = map(int, input().split())
    input_list = [list(map(int, input().split())) for _ in range(m)]
    parent = [i for i in range(n)]
    size_list = [1] * n
    ans_list = []
    ans = int(n*(n-1)/2)
    for a, b in input_list[::-1]:
        ans_list.append(ans)
        if root(a-1) != root(b-1):
            ans -= size_list[a-1] * size_list[b-1]
            unite(a-1, b-1)
    for ans in ans_list[::-1]:
        print(ans)
Problem p02989 (python)

Fixed submission:
n = int(input())
d = list(map(int,input().split())) 
D = sorted(d)
if D[n//2-1]==D[n//2]:
    print(0)
else:
    print(D[n//2]-D[n//2-1])

Buggy submission (verdict: Runtime Error):
n = int(input())
d = list(map(int,input().split())) 
D = sorted(d)
if D[n//2-1]==D[n//2]:
    print(0)
else:
    print(D[n//2+1]-D[n//2]+1)

Buggy submission (verdict: Runtime Error):
n = int(input())
d = list(map(int,input().split())) 
D = sorted(d)
if D[n//2+1]==D[n//2]:
    print(0)
else:
    print(D[n//2+1]-D[n//2]+1)
Problem p02891 (python)

Fixed submission:
s = str(input())
k = int(input())

def main(s, k):
  separation = []
  tmp = ""
  for x in range(len(s)-1):
    tmp += s[x]
    if s[x] == s[x+1]:
      if tmp == "":
        tmp += s[x]
    else:
      separation.append(tmp)
      tmp = ""
  tmp += s[-1]
  separation.append(tmp)

  total = 0

  if len(separation) == 1:
    if (len(separation[0]) == 1):
      return k//2
    else:
      return (len(separation[0])*k)//2

  if (s[0] == s[-1]) and k>1 and len(separation)>1:
    a = len(separation[0])//2
    b = len(separation[-1])//2
    total += a
    total += b
    separation[0] += separation[-1]
    a = separation[0]
    c = (len(a)//2)*(k-1)
    total += c
    separation = separation[1:-1]

  # print(separation)

  for x in separation:
    total += (len(x)//2)*k

  return total

print(main(s,k))

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

seperation = []
tmp = ""
for x in range(len(str)-1):
  tmp += str[x]
  if str[x] == str[x+1]:
    if tmp == "":
      tmp += str[x]
  else:
    seperation.append(tmp)
    tmp = ""
tmp += str[-1]
seperation.append(tmp)

total = 0

# print(seperation)

if len(seperation) == 1:
  if (len(seperation[0]) == 1):
    return n//2

if (str[0] == str[-1]) and n>1 and len(seperation)>1:
  a = len(seperation[0])//2
  b = len(seperation[-1])//2
  # print("a,b:",a,b)
  total += a
  total += b
  seperation[0] += seperation[-1]
  a = seperation[0]
  print(a,len(a),len(a)//2, n-1)
  c = (len(a)//2)*(n-1)
  # print("c:",c)
  total += c
  seperation = seperation[1:-1]

# print(total)
# print(seperation)

for x in seperation:
  total += (len(x)//2)*n

print(total)
Problem p02951 (python)

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

ans = max(0, C-(A-B))

print(ans)

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

for i in range(N-1):
    minh = min(H[i+1:]) # i+1以降のリストをスライス
    if H[i] - minh >= 2:
        print('No')
        break
    else:
        continue
else:
    print('Yes')

"""
# よく考えたら最大だけじゃダメだった
m = H.index(max(H)) # 複数の候補がある場合は最初のインデックスを返す
print(m)
for i in range(m+1, N):
    if H[m] - H[i] >= 2:
        print('No')
        break
    else:
        continue
else:
    print('Yes')
"""
Problem p02984 (python)

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

x = 0
for i in range(N): # x_0の値を得る
    if i % 2 == 0:
        x += A[i]
    else:
        x -= A[i]

for i in range(N):
    print(x, end=' ') # x_iをprint
    x = 2 * A[i] - x # x_(i+1)を得る

Buggy submission (verdict: Runtime Error):
import numpy as np

N = int(input())
A = np.array(list(map(int, input().split())))
#print(A)

b = [0.5 for _ in range(N)]
B0 = np.diag(b)
b.pop()
B1 = np.diag(b, k=1)
B = B0 + B1
B[N-1][0] = 0.5
#print(B)

#x = np.linalg.solve(B, A)
Binv = np.linalg.inv(B)
x = np.dot(Binv, A)
x = map(int, x)
ans = ' '.join(map(str, x))
print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np

N = int(input())
A = np.array(list(map(int, input().split())))
#print(A)

b = [0.5 for _ in range(N)]
B0 = np.diag(b)
b.pop()
B1 = np.diag(b, k=1)
B = B0 + B1
B[N-1][0] = 0.5
#print(B)

x = np.linalg.solve(B, A)
x = map(int, x)
ans = ' '.join(map(str, x))
print(ans)
Problem p02990 (python)

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

MOD = 10**9 + 7

dp = [[0]*(N+1) for _ in range(N+1)]
dp[0][0] = 1
for i in range(N):
    for j in range(i+1):
        dp[i+1][j] += dp[i][j]
        dp[i+1][j+1] += dp[i][j]

for i in range(1, K+1):
    a = dp[N-K+1][i]
    b = dp[K-1][i-1]
    ans = (a * b) % MOD
    print(ans)

Buggy submission (verdict: Runtime Error):
from scipy.special import comb

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

MOD = 10**9 + 7

for i in range(1, K+1):
    a = comb(N-K+1, i)%MOD
    b = comb(K-1, i-1)%MOD
    ans = (a*b)%MOD
    print(int(ans))
Problem p03011 (python)

Fixed submission:
P, Q, R = map(int, input().split())

ans = min(P+Q, Q+R, R+P)

print(ans)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
a = [int(input()) for _ in range(M)] # a_0...a_(M-1)

def fib(x): # フィボナッチ数列
    a, b = 1, 1
    if x == 0:
        return a
    elif x == 1:
        return b
    else:
        for i in range(x-1):
            a, b = b, a + b
        return b
"""
# 再帰だとTLEとかREとかになるよ
def fib(x): # フィボナッチ数列
    if x == 0:
        return(1)
    elif x == 1:
        return(1)
    else:
        return(f(x-1) + f(x-2))
"""

ans = 0
MOD = 10**9 + 7

if M == 0:
    ans += fib(N) % MOD
    print(ans)
else:
    ans += fib((a[0]-1) - 0) % MOD # 0段目からa_0-1段目に上る(その後a_0段目を飛ばしてa_0+1段目に上る)
    for i in range(1, M): # iは1からM-1
        stair = (a[i] - 1) - (a[i-1] + 1) # 登る段数
        if stair >= 0:
            ans *= fib(stair) % MOD # a_(i-1)+1段目からa_i-1段目に上る(その後a_i段目を飛ばしてa_i+1段目に上る)
        else:
            ans = 0
            break
    ans *= fib(N - (a[M-1] + 1)) % MOD # a_M-1段目からN段目に上る
    print(ans % MOD)
Problem p02915 (python)

Fixed submission:
print((int(input()))**3)

Buggy submission (verdict: Runtime Error):
N = import()
output = N*N*N
print(output)
Problem p02933 (python)

Fixed submission:
a=int(input().split()[0])
s=input()

if a>=3200:
    output=s
else :
    output="red"

print(output)

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

if a>=3200:
    output=s
else :
    output="red"

print(output)
Problem p02987 (python)

Fixed submission:
input_data=input()
 
a=input_data[0]
b=input_data[1]
c=input_data[2]
d=input_data[3]
 
if a==b :
    if c==d and a!=c :
            output="Yes"
    else :
        output="No"
    
else :
        if a==c and b==d :
            output="Yes"
    
        elif a==d and b==c :
            output="Yes"
        
        else :
            output="No"
           
print(output)

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

n=int(n[0])
p=p.split()
p=[int(p) for p in p]

output=0
for i in range(n-2):
    if p[i]<p[i+1] and p[i+1]<p[i+2]:
        output=output+1
    elif p[i+2]<p[i+1] and p[i+1]<p[i]:
        output=output+1
    else:
        output=output+0
    
print(output)

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

n=int(n[0])
ps=ps.split()
ps=[int(ps) for ps in ps]

output=0
for i in range(n-2):
    if ps[i]<ps[i+1] and ps[i+1]<ps[i+2]:
        output=output+1
    elif ps[i+2]<ps[i+1] and ps[i+1]<ps[i]:
        output=output+1
    else:output=output+0
    
print(output)

Buggy submission (verdict: Runtime Error):
input_datainput()

a=input_data[0]
b=input_data[1]
c=input_data[2]
d=input_data[3]

if a==b :
    if c==d and a!=c :
            output="yes"
    
else :
        if a==c and b==d :
            output="yes"
    
        elif a==d and b==c :
            output="yes"
        
        else :
            output="no"
        
print(output)
Problem p03011 (python)

Fixed submission:
input_data=input()

X=input_data.split()

P=int(X[0])

Q=int(X[1])

R=int(X[2])

S=max([P,Q,R])

print(P+Q+R-S)

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

P=int(input_data[0])

Q=int(input_data[2])

R=int(input_data[4])

X=max([P,Q,R])

print(P+Q+R-X)
Problem p03207 (python)

Fixed submission:
n = int(input())
lst = []

for i in range(n):
  item = int(input())
  lst.append(item)

goods = sorted(lst, reverse=True)
goods[0] = goods[0] // 2

print(sum(goods))

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

for i in range(n):
  item = int(input())
  goods.append(item)

goods = sorted(lst, reverse=True)
goods[0] = goods[0] // 2

print(sum(goods))

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

for item in range(n):
  goods.append(item)

goods = sorted(lst, reverse=True)
goods[0] = goods[0] // 2

print(sum(goods))
Problem p03208 (python)

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

tree = [int(input()) for i in range(n)]
tree.sort()

res = (tree[i+k-1] - tree[i] for i in range(n-k+1))
print(min(res))

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

tree = [int(input()) for i in range(n)]
tree.sort()

res = (tree[i+k-1] - tree[i] for i in range(n-k+1))
print(min(res))

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

tree = [int(input()) for i in range(n)]
tree.sort()

res = (tree(i+k-1) - tree(i) for i in range(n-k+1))
print(min(res))

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

tree = [int(input()) for i in range(n)]
tree.sort()

res = (tree(i+k-1) - tree(i) for i range(n-k+1))
print(min(res))

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

tree = [int(input()) for i in range(n)]
tree.sort()

res = (tree(i+k-1) - tree(i) for i range(n-k+11)
print(min(res))
Problem p02935 (python)

Fixed submission:
N = int(input())
V = list(map(int,input().split()))
V.sort()
S = V[0]
for i in range(N):
  S = (S + V[i])/2
print(S)

Buggy submission (verdict: Runtime Error):
N = int(input())
V = list(map(int,input().split()))
ans=0
V.sort()
S=V[0]
for i in N-1:
  ans += (S + V[i])/2
  S=V[i]
print(ans)
Problem p02951 (python)

Fixed submission:
a,b,c = map(int,input().split())
ans=c-(a-b)
if ans >= 0:
  print(ans)
else:
  print(0)

Buggy submission (verdict: Runtime Error):
a,b,c = map(int,input().split())
ans=c-(a-b)
if ans => 0:
  print(ans)
else:
  print(0)
Problem p03041 (python)

Fixed submission:
n, k = (int(i) for i in input().split())  
s = input()
s_ = s[:k-1] + s[k-1].lower() + s[k:]
print(s_)

Buggy submission (verdict: Runtime Error):
n, k = (int(i) for i in input().split())  
s = input()
s_ = s[:k-1] + s[k].lower() + s[k:]
print(s_)

Buggy submission (verdict: Runtime Error):
n, k = (int(i) for i in input().split())  
s = input()
s_ = s[:k-1] + s[k].lower() + s[k:]
print(s_)
Problem p03013 (python)

Fixed submission:
n, m = map(int, input().split())
#リスト内包表記でaに入れる
a = [int(input()) for _ in range(m)]

#MODに'1000000007'を入れる
MOD = 10**9 + 7
#zに集合を作成する
z = set(a)
 
#i段目までにたどりつく方法を順に求める
x = [0 for _ in range(n + 1)]
#0段目の場合1とする
x[0] = 1
#1段目の場合は集合の中に1が含まれていないかどうか、含まれていない:1、含まれている:0
x[1] = int(1 not in z)
#2段目以降の場合
for i in range(2, n + 1):
#集合の中にiが含まれていない場合
    if i not in z:
#i段目に1段か2段で上ってきた経路数を足して、MODで割る、dp[i]に蓄積する
        x[i] = (x[i - 1] + x[i - 2]) % MOD
print(x[n])

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
#リスト内包表記でaに入れる
a = [int(input()) for _ in range(m)]

#MODに'1000000007'を入れる
MOD = 10**9 + 7
#zに集合を作成する
z = set(a)
 
#i段目までにたどりつく方法を順に求める
x = [0 for _ in range(n + 1)]
#0段目の場合1とする
x[0] = 1
#1段目の場合は集合の中に1が含まれていないかどうか、含まれていない:1、含まれている:0
x[1] = int(1 not in z)
#2段目以降の場合
for i in range(2, n + 1):
#集合の中にiが含まれていない場合
    if i not in z:
#i段目に1段か2段で上ってきた経路数を足して、MODで割る、dp[i]に蓄積する
        x[i] = (x[i - 1] + x[i - 2]) % MOD
print(x[i])

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
#リスト内包表記でaに入れる
a = [int(input()) for _ in range(m)]

#MODに'1000000007'を入れる
MOD = 10**9 + 7
#zに集合を作成する
z = set(a)
 
#i段目までにたどりつく方法を順に求める
x = [0 for _ in range(n + 1)]
#0段目の場合1とする
x[0] = 1
#1段目の場合は集合の中に1が含まれていないかどうか、含まれていない:1、含まれている:0
x[1] = int(1 not in z)
#2段目以降の場合
for i in range(2, n + 1):
  #集合の中にiが含まれていない場合
    if i not in z:
      #i段目に1段か2段で上ってきた経路数を足して、MODで割る、dp[i]に蓄積する
        x[i] = (x[i - 1] + x[i - 2]) % MOD
print(x[i])

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
#リスト内包表記でaに入れる
a = [int(input()) for _ in range(M)]

#MODに1000000007を入れる
MOD = 10**9 + 7
#Zに集合を作成する
Z = set(a)
 
#i段目までにたどりつく方法を順に求める
dp = [0 for _ in range(N + 1)]
#0段目の場合1とする
dp[0] = 1
#1段目の場合は集合の中に1が含まれていないかどうか、含まれていない:1、含まれている:0
dp[1] = int(1 not in Z)
#2段目以降の場合
for i in range(2, N + 1):
  #集合の中にiが含まれていない場合
    if i not in Z:
      #i段目に1段か2段で上ってきた経路数を足して、MODで割る、dp[i]に蓄積する
        dp[i] = (dp[i - 1] + dp[i - 2]) % MOD
#ansに答えを入れる
ans = dp[i]
print(ans)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
#リスト内包表記でaに入れる
a = [int(input()) for _ in range(M)]

#MODに1000000007を入れる
MOD = 10**9 + 7
#Zに集合を作成する
Z = set(a)
 
#i段目までにたどりつく方法を順に求める
dp = [0 for _ in range(N + 1)]
#0段目の場合1とする
dp[0] = 1
#1段目の場合は集合の中に1が含まれていないかどうか、含まれていない:1、含まれている:0
dp[1] = int(1 not in Z)
#2段目以降の場合
for i in range(2, N + 1):
  #集合の中にiが含まれていない場合
    if i not in Z:
      #i段目に1段か2段で上ってきた経路数を足して、MODで割る、dp[i]に蓄積する
        dp[i] = (dp[i - 1] + dp[i - 2]) % MOD
#ansに答えを入れる
ans = dp[i]
print(dp[i])
Problem p03036 (python)

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

for i in range(10):
 z = (r * x) - d
 x = z
 print(z)

Buggy submission (verdict: Runtime Error):
x + 1 = rx - d

r,d,x = map(int(),input().split())

for i in range(10):
 z = (r * x) - d
 print(z)
 x = z
Problem p03075 (python)

Fixed submission:
a =int(input())
b =int(input())
c =int(input())
d =int(input())
e =int(input())
k =int(input())

if e-a <= k:
   print("Yay!")
else:
   print(":(")

Buggy submission (verdict: Runtime Error):
a =input()
b =input()
c =input()
d =input()
e =input()
k =input()

if b-a and c-b and d-c and e-d <= k:
   print("Yay!")
else:
   print(":(")
Problem p03053 (python)

Fixed submission:
import sys
import numpy as np

#%% Smart Solution

input = sys.stdin.readline

H, W = map(int, input().split())

status = np.full((H, W), H*W, dtype=int)
for i in range(H):
    for j, c in enumerate(input()):
        if c == "#":
            status[i,j] = 0


for h in range(1, H):
    status[h, :] = np.minimum(status[h, :], status[h-1, :] + 1)
for h in range(0, H-1)[::-1]:
    status[h, :] = np.minimum(status[h, :], status[h+1, :] + 1)
for w in range(1, W):
    status[:, w] = np.minimum(status[:, w], status[:, w-1] + 1)
for w in range(0, W-1)[::-1]:
    status[:, w] = np.minimum(status[:, w], status[:, w+1] + 1)

print(np.max(status))

Buggy submission (verdict: Runtime Error):
import sys
import numpy as np

todo = [[], []]

input = sys.stdin.readline
H, W = map(int, input().split())
field = np.zeros((H,W), dtype=int)

for i in range(H):
    for j, c in enumerate(input()):
        if c == '#':
            field[(i,j)] = 1
            todo[0].append((i,j))

def findAdjacent(loc):
    x, y = loc[0], loc[1]
    for dx, dy in [(-1,0), (1,0), (0,-1), (0,1)]:
        if -1 < x+dx < W and -1 < y+dy < H:
            yield (x+dx, y+dy)

def colorAdjacent(loc, nxt):
    for l in findAdjacent(loc):
        if field[l] == 0:
            todo[nxt].append(l)
            field[l] += 1

ans = 0
while todo[0] or todo[1]:
    cur = ans % 2
    while todo[cur]:
        colorAdjacent(todo[cur].pop(), (cur+1)%2)
    ans += 1

print(ans-1)
Problem p03104 (python)

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

#%%
# a finction to find F(0,x)
def XOR_0_to_x(x):

    # for all even integer n, n ^ (n+1) = 1
    xor = ((x+1) // 2) % 2

    if x % 2 == 0:
        return xor ^ x

    else:
        return xor

#%%
# F(A,B) = F(0,A-1) ^ F(0,B)
ans = XOR_0_to_x(A-1) ^ XOR_0_to_x(B)

print(ans)

Buggy submission (verdict: Runtime Error):
#%%
import math
A, B = map(int, input().split())
digits = int(math.log2(B)) + 1
#%%

def counter(start, end, x):
    place = 2 ** x
    if place == 1:
        return (start - end + 1) % 2

    start_group = start // place
    end_group = end // place

    start_effective, end_effective = 0,0

    if start_group % 2 == 1:
        start_effective = ( place - start % place ) % 2
    if start_group != end_group and end_group % 2 == 1:
        end_effective = ( place - end % place +1 ) % 2

    return place * ((start_effective + end_effective) % 2)

#%%
for x in range(int(math.log2(456))+1):
    print(counter(123,456,x))

#%%
if A != B:
    ans = 0
    for x in range(digits):
        ans += counter(A,B,x)

    print(ans)

else:
    print(A)
Problem p03107 (python)

Fixed submission:
#%%
s = input()
n = len(s)

if n < 2:
    print(0)

else:
    ans, i = 0, 0
    rem = []

    while i < n:

        if not rem:

            if i+1 < n:
                if s[i] == s[i+1]:
                    rem.append(s[i])
                    i += 1

                else:
                    i += 2
                    ans += 2

            else:
                i += 1

        else:
            if rem[-1] != s[i]:
                rem.pop()
                i += 1
                ans += 2
            
            else:
                if i + 1 < n:
                    if s[i] == s[i+1]:
                        rem.append(s[i])
                        i += 1

                    else:
                        i += 2
                        ans += 2

                else:
                    i += 1
    print(ans)

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

if n < 2:
    print(0)

else:
    ans, i = 0, 0
    rem = []

    while i < n:

        if not rem:

            if i+1 < n:
                if s[i] == s[i+1]:
                    rem.append(s[i])
                    i += 1

                else:
                    i += 2
                    ans += 2

            else:
                i += 1

        else:
            if rem[-1] != s[i]:
                rem.pop()
                i += 1
                ans += 2
            
            else:
                if i + 1 < n:
                    if s[i] == s[i+1]:
                        rem.append(s[i])
                        i += 1

                    else:
                        i += 2
                        ans += 2

                else:
                    i += 1
print(ans)

Buggy submission (verdict: Runtime Error):
#%%
def c(s):
    n = len(s)

    if n < 2:
        print(0)

    else:
        ans, i = 0, 0
        rem = []

        while i < n:
            print(rem,s[0:i],s[i:])

            if not rem:

                if i+1 < n:
                    if s[i] == s[i+1]:
                        rem.append(s[i])
                        i += 1

                    else:
                        i += 2
                        ans += 2

                else:
                    i += 1

            else:
                if rem[-1] != s[i]:
                    rem.pop()
                    i += 1
                    ans += 2
                
                else:
                    if i + 1 < n:
                        if s[i] == s[i+1]:
                            rem.append(s[i])
                            i += 1

                        else:
                            i += 2
                            ans += 2

                    else:
                        i += 1
    print(ans)

#%%
s = input()

c(s)
Problem p03013 (python)

Fixed submission:
n,m = map(int,input().split())
ss = [1]*n
for i in range(0,m):
    ss[int(input())-1] = 0
if n == 0:
    print(0)
elif n == 1:
    print(1)
elif n == 2:
    if ss[0] == 0:
        print(1)
    else:
        print(2)
else:
    if ss[n-3] != 0:
        ss[n-3] = ss[n-2]+ ss[n-1]
    for i in range(n-4,-1,-1):
        if ss[i] == 0:
            continue
        ss[i] = ss[i+1] + ss[i+2]
    print((ss[0]+ss[1])%(10**9+7))

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())
ss = [1]*n
for i in range(0,m):
    ss[int(input())-1] = 0
if ss[n-3] != 0:
    ss[n-3] = ss[n-2]+ ss[n-1]
for i in range(n-4,-1,-1):
    if ss[i] == 0:
        continue
    ss[i] = ss[i+1] + ss[i+2]
print((ss[0]+ss[1])%(10**9+7))
Problem p02990 (python)

Fixed submission:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000)

N,K = map(int,input().split())
c = [[0 for _ in range(N)] for _ in range(N)]
c[0][0] = 1
for i in range(N-1):
    for j in range(N):
        if j > 0: c[i+1][j] += c[i][j-1]
        c[i+1][j] += c[i][j]
def f2(n,k):
    return c[n+k-1][k-1]%1000000007
def f(n,k):
    if n-k<0: return 0
    if n==k: return 1
    if k<1: return 0
    return f2(n-k,k)%1000000007

for i in range(1,K+1):
    blue = f(K,i)
    red = f(N-K,i-1)+2*f(N-K,i)+f(N-K,i+1)
    ans=blue*red
    print(int(ans%1000000007))

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

N,K = map(int,input().split())
c = [[0 for _ in range(N)] for _ in range(N)]
c[0][0] = 1
for i in range(N-1):
    for j in range(N):
        if j > 0: c[i+1][j] += c[i][j-1]
        c[i+1][j] += c[i][j]
def f2(n,k):
    return c[n+k-1][k-1]
def f(n,k):
    if n-k<0: return 0
    if k<1: return 0
    return f2(n-k,k)%((1e+9)+7)

for i in range(1,K+1):
    blue = f(K,i)
    red = f(N-K,i-1)+2*f(N-K,i)+f(N-K,i+1)
    ans=blue*red
    print(int(ans%(1e+9+7)))