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

Fixed submission:
N,M = map(int,input().split())
path = [[] for _ in range(N)]
save = []
for _ in range(M):
    a,b = map(int,input().split())
    save.append([a-1,b-1])
    path[b-1].append(a-1)
    path[a-1].append(b-1)


def dfs(now):
    global cnt
    if not 0 in vis: 
        cnt += 1
        return None
    for new in path[now]:
        if vis[new] == 0:
            vis[new] = 1
            dfs(new)
cnt = 0
for i in range(M):
    vis  = [0 for _ in range(N)]
    a = save[i][0]
    b = save[i][1]
    path[a].remove(b)
    path[b].remove(a)
    vis[0] = 1
    dfs(0)
    path[a].append(b)
    path[b].append(a)
print(M-cnt)

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


def dfs(now):
    if not 0 in vis: 
        cnt += 1
        return None
    for new in path[now]:
        if vis[new] == 0:
            vis[new] = 1
            dfs(new)
cnt = 0
for i in range(M):
    vis  = [0 for _ in range(N)]
    a = save[i][0]
    b = save[i][1]
    path[a].remove(b)
    path[b].remove(a)
    vis[0] = 1
    dfs(0)
    path[a].append(b)
    path[b].append(a)
print(M-cnt)
Problem p03605 (python)

Fixed submission:
s=input()
for x in s:
  if x == '9':
    print("Yes")
    exit()
print("No")

Buggy submission (verdict: Runtime Error):
#include <stdio.h>
#include <string.h>
#include <math.h>

int main(void){
        char s[1000000];
        scanf("%s", s);
        for (int i = 0; i < strlen(s); i++) {
                if (s[i]=='9') {
                        printf("Yes\n");
                        return 0;
                }
        }
        printf("No\n");
        return 0;
}
Problem p03633 (python)

Fixed submission:
N = int(input())
L = []
for _ in range(N):
    L.append(int(input()))
def lcm(x, y):
    if x > y:
        x,y = y,x
    if x == 0:
        return y
    r = y % x
    return lcm(r,x)
def gcd(x,y):   
    return   x*y // lcm(x,y)

ans = L[0]
for x in L:
    ans = gcd(ans,x)
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
L = []
for _ in range(N):
    L.append(int(input()))
def lcm(x, y):
    if x > y:
        x,y = y,x
    if x == 0:
        return y
    r = y % x
    return lcm(r,x)
def gcd(x,y):   
    return   x*y // lcm(x,y)

ans = gcd(L[1],L[0])
for x in L:
    ans = gcd(ans,x)
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
L = []
for _ in range(N):
    L.append(int(input()))
def lcm(x, y):
    if x > y:
        x,y = y,x
    if x == 0:
        return y
    r = y % x
    return lcm(r,x)
def gcd(x,y):   
    return   x*y // lcm(x,y)

ans = gcd(L[1],L[2])
for x in L:
    ans = gcd(ans,x)
print(ans)
Problem p03637 (python)

Fixed submission:
N = int(input())
L = list(map(int,input().split()))
one = list(filter(lambda x:x%2!=0,L))
two = list(filter(lambda x:x%4!=0 and x%2==0,L))
four = list(filter(lambda x:x%4==0,L))
if len(one) - len(four) == 1 :
    if len(two) >=1 :
        print("No")
    else:
        print("Yes")
elif len(one) <= len(four):
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
N = int(input())
L = list(map(int,input().split()))
one = list(filter(lambda x:x%2!=0,L))
two = list(filter(lambda x:x%4!=0 and x%2==0,L))
four = list(filter(lambda x:x%4==0,L))
if len(one) - len(four) == 1 :
    if len(two) >=1 :
        print("No")
    else:
        print("Yes")
elif len(one) =< len(four):
    print("Yes")
else:
    print("No")
Problem p03658 (python)

Fixed submission:

N ,K = map(int,input().split())
L = list(map(int,input().split()))
L = sorted(L)[::-1]
ans = 0
for i in range(K):
    ans = ans + L[i]
print(ans)

Buggy submission (verdict: Runtime Error):
x , y = map(int,input().split())
if x % 3 == 0 or y % 3 == 0 or (x+y) % 3 ==0:
    print("Possible")
else:
    print("Impossible")
remote@G465:~/abc/067$ vim b.py
remote@G465:~/abc/067$ cat b.py
N ,K = map(int,input().split())
L = list(map(int,input().split()))
L = sorted(L)[::-1]
ans = 0
for i in range(K):
    ans = ans + L[i]
print(ans)
Problem p03828 (python)

Fixed submission:
const = 10 ** 9 + 7
N = int(input())
TABLE = [2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,503,509,521,523,541,547,557,563,569,571,577,587,593,599,601,607,613,617,619,631,641,643,647,653,659,661,673,677,683,691,701,709,719,727,733,739,743,751,757,761,769,773,787,797,809,811,821,823,827,829,839,853,857,859,863,877,881,883,887,907,911,919,929,937,941,947,953,967,971,977,983,991,997]
T = []
ans = 1
for x in TABLE:
    L = []
    for i in range(1,N + 1):
        count = 0
        while i % x == 0:
            i /= x
            count += 1
        L.append(count)
    T.append(sum(L)+1)
#print(T)
for x in T:
    ans *= x
print(ans % const)

Buggy submission (verdict: Runtime Error):
const = 10 ** 9 + 7
N = int(input())
TABLE = [2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97]T = []
ans = 1
for x in TABLE:
    L = []
    for i in range(1,N + 1):
        count = 0
        while i % x == 0:
            i /= x
            count += 1
        L.append(count)
    T.append(sum(L)+1)
#print(T)
for x in T:
    ans *= x
print(ans % const)
Problem p03997 (python)

Fixed submission:
a = int(input())
b = int(input())
c = int(input())

print((a+b)*c//2)

Buggy submission (verdict: Runtime Error):
H, W , N = map(int,input().split())
from bisect import bisect_left
from bisect import bisect_right
matrix = []
for _ in range(N):
    x,y = map(int,input().split())
    x -= 1
    y -= 1
    matrix.append([x,y])
matrix.sort()
ans = [0 for _ in range(10)]
cand = {}
for l in matrix:
    for x_r in [-2, -1 , 0]:
        for y_r in [-2, -1 , 0]:
            nowx = l[0] + x_r
            nowy = l[1] + y_r
            if nowx < 0 or nowy < 0 or nowx + 2>= H or nowy+ 2 >= W:
                continue
            #ここで起点(左上)nowx, nowy として　 9マスに着目する
            name = str(nowx) + ' '  +str(nowy)
            if name in cand : cand[name] += 1
            else: cand[name] = 1
tmp = ((H - 2) * (W - 2))
for x in cand.values():
    ans[x] += 1
    tmp -= 1
ans[0] = tmp
for x in ans:
    print(x)
Problem p04029 (python)

Fixed submission:
N  = int(input())
ans = 0
for i in range(N+1):
  ans += i
print(ans)

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

print((1+N)(N)//2)

Buggy submission (verdict: Runtime Error):
N  = input()
ans = 0
for i in range(N+1):
  ans += i
print(ans)
Problem p04030 (python)

Fixed submission:
S = list(input())
i = 0
while 'B' in S:
    if S[i] == 'B':
        if i == 0:
            del S[0]
            i = 0
            continue
        else:
            del S[i-1]
            del S[i-1]
            i = 0
            continue
    i += 1
for x in S:
    print(x, end='')
print()

Buggy submission (verdict: Runtime Error):
S = list(input())
ans = []

for i in range(len(S)):
    if S[i] == 'B':
        if i == 0:
            pass
        else:
            del ans[-1]
        
    else:
        ans.append(S[i])

for x in ans:
    print(x,end='')
print()
Problem p04031 (python)

Fixed submission:
N = int(input())
ans = 10**10
L = list(map(int,input().split()))
for i in range(-101,101): 
  tmp = 0
  for x in L:
    tmp += (i - x) ** 2
  ans = min(ans,tmp)
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
L = list(map(int,inptu().split()))
ave = sum(L) / len(L)
if ave * 10 % 10 >= 5:
  ave = int(ave) + 1
else:
  ave = int(ave)
ans = 0
for x in L:
  ans += (x - ave) **2
print(ans)
Problem p04043 (python)

Fixed submission:
L=list(map(int,input().split()))
table=[5,5,7]
L=sorted(L)
if table == L:
  print("YES")
else:
  print("NO")

Buggy submission (verdict: Runtime Error):
N, K = map(int,input().split())
L = list(map(int,input().split()))
for i in range(N,100000):
    flag = 0
    for x in str(i):
        if int(x) in L:
            flag = 1
    if flag == 0:
        print(i)
        exit()

Buggy submission (verdict: Runtime Error):
L=list(map(int,input().split()))
table=[5,5,7]
L=soretd(L)
if table == L:
  print("YES")
else:
  print("NO")

Buggy submission (verdict: Runtime Error):
L=map(int,input().split())
table=[5,5,7]
L=soretd(L)
if table == L:
  print("YES")
else:
  print("NO")

Buggy submission (verdict: Runtime Error):
L=amp(int,input().split())
table=[5,5,7]
L=soretd(L)
if table == L:
  print("YES")
else:
  print("NO")
Problem p02801 (python)

Fixed submission:
print(chr(ord(input()[0])+1))

Buggy submission (verdict: Runtime Error):
import numpy as np
print(char(ord(input()[0])+1))
Problem p02802 (python)

Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N,M = map(int,readline().split())
PS = (line.split() for line in readlines())

ac = [False] * N
wa_cnt = [0] * N
penal = 0
for P,S in PS:
    p = int(P)-1
    if ac[p]:
        pass
    elif S == b'WA':
        wa_cnt[p] += 1
    else:
        ac[p] = True
        penal += wa_cnt[p]

ac = sum(ac)
print(ac, penal)

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

N,M = map(int,input().split())
PS = (input().split() for _ in range(N))

ac = [False] * N
wa_cnt = [0] * N
penal = 0
for P,S in PS:
    p = int(P)-1
    if ac[p]:
        pass
    elif S == b'WA':
        wa_cnt[p] += 1
    else:
        ac[p] = True
        penal += wa_cnt[p]

ac = sum(ac)
print(ac, penal)
Problem p03046 (python)

Fixed submission:
def main():
    m, k = map(int, input().split())
    maximum = 2 ** m - 1

    if k==0:
        print(" ".join(map(str, range(0, maximum+1))), end=" ")
        print(" ".join(map(str, range(maximum, -1, -1))))
        return

    if m==1:
        print(-1)
        return

    if maximum < k:
        print(-1)
        return

    others = [i for i in range(1, maximum+1) if i!=k]
    print(0, k, 0, end=" ")
    print(" ".join(map(str, others)), k, " ".join(map(str, reversed(others))))


main()

Buggy submission (verdict: Runtime Error):
def main():
    m, k = map(int, input().split())
    maximum = 2 ** m - 1

    if k==0:
        print(" ".join(map(str, range(0, maximum+1))), end=" ")
        print(" ".join(map(str, range(maximum, -1, -1))))
        return

    if m==1:
        print(-1)
        return

    if maximum < k:
        print(-1)
        return

    other_than_k = [i for i in range(1, maximum+1) if i!=k]
    print(" ".join(map(str, other_than_k[2:])), end=" ")
    print(other_than_k[0], k, other_than_k[0], other_than_k[1], k, other_than_k[1], end=" ")
    print(" ".join(reversed(map(str, other_than_k[2:]))))

main()
Problem p03081 (python)

Fixed submission:
n, q = map(int, input().split())
s = input()
tds = list(tuple(input().split()) for _ in range(q))

left = 0
right = n-1

for t, d in reversed(tds):
    if d=="L":
        if t==s[left]:
            left = left+1
            if left > n-1:
                right = 0
                left = n-1
                break
        if right < n-1 and t==s[right+1]:
            right = min(right+1, n-1)

    if d=="R":
        if t==s[right]:
            right = right-1
            if 0 > right:
                right = 0
                left = n-1
                break
        if left > 0 and t==s[left-1]:
            left = max(left-1, 0)

print(max(right - left + 1, 0))

Buggy submission (verdict: Runtime Error):
import string

n, q = map(int, input().split())
s = input()
tds = list(tuple(input().split()) for _ in range(q))

left = 0
right = n-1

for t, d in reversed(tds):
    if d=="L":
        if t==s[left]:
            left += 1
    if d=="R":
        if t==s[right]:
            right -= 1

print(right - left + 1)
Problem p03452 (python)

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

lrds = [tuple(map(int, input().split())) for _ in range(m)]

xs = [None for _ in range(n)]

ps = [[] for _ in range(n)]

for lrd in lrds:
    l, r, d = lrd
    ps[l-1].append((r-1, d))
    ps[r-1].append((l-1, -d))

not_decided = set(range(n))

def solve():
    while len(not_decided) != 0:
        t = not_decided.pop()
        xs[t] = 0

        stack = [t]
        while len(stack) != 0:
            c = stack.pop()
            for p in ps[c]:
                another, relative_position = p
                if another in not_decided:
                    xs[another] = xs[c] + relative_position
                    not_decided.remove(another)
                    stack.append(another)
                else:
                    if xs[another] != xs[c] + relative_position:
                        return False
    return True

if solve():
    print("Yes")
else:
    print("No")

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

lrds = [tuple(map(int, input().split())) for _ in range(m)]

xs = [None for _ in range(n)]

ps = [[] for _ in range(n)]

for lrd in lrds:
    l, r, d = lrd
    ps[l-1].append((r-1, d))
    ps[r-1].append((l-1, -d))

not_decided = set(range(n))

def f(t):
    for p in ps[t]:
        another, relative_position = p
        if another in not_decided:
            xs[another] = xs[t] + relative_position
            not_decided.remove(another)
            f(another)
        else:
            if xs[another] != xs[t] + relative_position:
                return False
    return True

def solve():
    while len(not_decided) != 0:
        t = not_decided.pop()
        xs[t] = 0

        if not f(t):
            return False
    return True

if solve():
    print("Yes")
else:
    print("No")

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

lrds = [tuple(map(int, input().split())) for _ in range(m)]

xs = [None for _ in range(n)]

ps = [[] for _ in range(n)]

for lrd in lrds:
    l, r, d = lrd
    ps[l-1].append((l-1, r-1, d))
    ps[r-1].append((l-1, r-1, d))

not_decided = set(range(n))

def f(t):
    for lrd in ps[t]:
        l, r, d = lrd
        if l == t:
            another = r
            position = d
        else:
            another = l
            position = -d
        if xs[another] is None:
            xs[another] = xs[t] + position
            not_decided.remove(another)
            f(another)
        else:
            if xs[another] != xs[t] + position:
                return False
    return True

def solve():
    while len(not_decided) != 0:
        t = not_decided.pop()
        xs[t] = 0

        if not f(t):
            return False
    return True

if solve():
    print("Yes")
else:
    print("No")
Problem p03662 (python)

Fixed submission:
import sys

sys.setrecursionlimit(100000000)

n = int(input())
xys = [tuple(map(int, input().split())) for _ in range(n-1)]

neighbors = [[] for _ in range(n)]

for x, y in xys:
    neighbors[x-1].append(y-1)
    neighbors[y-1].append(x-1)

froms = [-1 for _ in range(n)]

froms[0] = -2

def f(x):
    for y in neighbors[x]:
        if froms[y]==-1 :
            froms[y] = x
            f(y)

f(0)

path = [n-1]
while path[-1]!=0:
    if froms[path[-1]]==-1:
        break
    path.append(froms[path[-1]])
path.reverse()

blacks_l = path[:(len(path)+1)//2]
blacks = set(blacks_l)
whites = set(path[(len(path)+1)//2:])

def fennec(x):
    for y in neighbors[x]:
        if not y in blacks and not y in whites:
            blacks.add(y)
            fennec(y)

for b in blacks_l:
    fennec(b)

if len(blacks) > n-len(blacks):
    print('Fennec')
else:
    print('Snuke')

Buggy submission (verdict: Runtime Error):
n = int(input())
xys = [tuple(map(int, input().split())) for _ in range(n-1)]

neighbors = [[] for _ in range(n)]

for x, y in xys:
    neighbors[x-1].append(y-1)
    neighbors[y-1].append(x-1)

froms = [-1 for _ in range(n)]

froms[0] = -2

def f(x):
    for y in neighbors[x]:
        if froms[y]==-1 :
            froms[y] = x
            f(y)

f(0)

path = [n-1]
while path[-1]!=0:
    if froms[path[-1]]==-1:
        break
    path.append(froms[path[-1]])
path.reverse()

blacks_l = path[:(len(path)+1)//2]
blacks = set(blacks_l)
whites = set(path[(len(path)+1)//2:])

def fennec(x):
    for y in neighbors[x]:
        if not y in blacks and not y in whites:
            blacks.add(y)
            fennec(y)

for b in blacks_l:
    fennec(b)

if len(blacks) > n-len(blacks):
    print('Fennec')
else:
    print('Snuke')
Problem p03684 (python)

Fixed submission:
class UnionFind:
    def __init__(self, size):
        self.parents = list(range(size))

    def find(self, i):
        ret = i
        path = []
        while self.parents[ret]!=ret:
            path.append(ret)
            ret = self.parents[ret]
        for p in path:
            self.parents[p] = ret
        return ret

    def union(self, i, j):
        self.parents[self.find(i)] = j

n = int(input())
xys = [(tuple(map(int, input().split())), i) for i in range(n)]

sortx = sorted(xys, key=lambda xy: xy[0][0])
roadsx = [(sortx[i][0][0]-sortx[i-1][0][0], sortx[i][1], sortx[i-1][1]) for i in range(1, n)]
sorty = sorted(xys, key=lambda xy: xy[0][1])
roadsy = [(sorty[i][0][1]-sorty[i-1][0][1], sorty[i][1], sorty[i-1][1]) for i in range(1, n)]
roads = roadsx + roadsy
roads.sort(key=lambda x:x[0])

ctr = 1
ans = 0
uf = UnionFind(n)
for road in roads:
    if ctr >= n:
        break
    cost, i1, i2 = road
    if uf.find(i1) != uf.find(i2):
        ans += cost
        ctr += 1
        uf.union(i1, i2)

print(ans)

Buggy submission (verdict: Runtime Error):
class UnionFind:
    def __init__(self, size):
        self.parents = list(range(size))

    def find(self, i):
        ret = i
        path = []
        while self.parents[ret]!=ret:
            path.append(ret)
            ret = self.parents[ret]
        for p in path:
            self.parents[p] = ret
        return ret

    def union(self, i, j):
        self.parents[self.find(i)] = j

n = int(input())
xys = [(*map(int, input().split()), i) for i in range(n)]

sortx = sorted(xys, key=lambda xy: xy[0])
roadsx = [(sortx[i][0]-sortx[i-1][0], sortx[i][2], sortx[i-1][2]) for i in range(1, n)]
sorty = sorted(xys, key=lambda xy: xy[1])
roadsy = [(sorty[i][1]-sorty[i-1][1], sorty[i][2], sorty[i-1][2]) for i in range(1, n)]
roads = roadsx + roadsy
roads.sort(key=lambda x:x[0])

ctr = 1
ans = 0
uf = UnionFind(n)
for road in roads:
    if ctr >= n:
        break
    cost, i1, i2 = road
    if uf.find(i1) != uf.find(i2):
        ans += cost
        ctr += 1
        uf.union(i1, i2)

print(ans)
Problem p03701 (python)

Fixed submission:
n = int(input())
ss = list(map(int, (input() for _ in range(n))))

full = sum(ss)
non0s = list(s for s in ss if s%10!=0)

if full%10!=0:
    print(full)
else:
    if len(non0s)==0:
        print(0)
    else:
        print(full - min(non0s))

Buggy submission (verdict: Runtime Error):
import math

n, a, b = map(int, input().split())
hs = list(map(int, (input() for _ in range(n))))

m = sum(hs) // (a + (n-1)*b) - 10
M = sum(math.ceil(h/a) for h in hs)

def killable(p, hs, a, b):
    x = sum(max(0, math.ceil((h-p*b) / (a-b))) for h in hs)
    return x <= p

while(m+1 < M):
    c = (m+M) // 2
    if killable(c, hs, a, b):
        M = c
    else:
        m = c
print(M)

Buggy submission (verdict: Runtime Error):
import heapq
from collections import Counter
import math

n, a, b = map(int, input().split())
hs = map(int, (input() for _ in range(n)))
counter = [[-x, c] for x, c in Counter(hs).items()]

cum = 0
p = 0

heapq.heapify(counter)

def f(m, c, a, b):
    ans = 0
    ans += math.floor(m / (a + b*(c-1))) * c
    m -= math.floor(m / (a + b*(c-1))) * (a + b*(c-1))
    ans += min(math.ceil(m / b), math.ceil(m / (a + b*(c-1)))*c)
    return ans

while(True):
    x, y = heapq.heappop(counter)
    if len(counter) == 0:
        print(p + f(-x-cum, y, a, b))
        break
    v, _ = counter[0]
    if x==v:
        counter[0][1] += y
        continue
    m = math.ceil((v-x) / (a-b))
    if (-x) - (m*a + m*(y-1)*b + cum) <= 0 and (-v) - m*y*b <=0:
        print(p + f(-x-cum, y, a, b))
        break
    p += m*y
    cum += b*m*y
    heapq.heappush(counter, [x + m*(a-b), y])
Problem p03716 (python)

Fixed submission:
import heapq
n = int(input())
xs = list(map(int, input().split()))
head = [(x, x) for x in xs[:n]]
heapq.heapify(head)
body = xs[n:-n]
tail = [(-x, x) for x in xs[-n:]]
heapq.heapify(tail)

def f(heap, body, sign, initial):
    answer = [initial]
    acc = initial
    for b in body:
        heapq.heappush(heap, (sign*b, b))
        _, x = heapq.heappop(heap)
        acc = acc + b - x
        answer.append(acc)
    return answer
 
print(max(x - y for x, y in zip(
    f(head, body, 1, sum(xs[:n])),
    f(tail, body[::-1], -1, sum(xs[-n:]))[::-1])))

Buggy submission (verdict: Runtime Error):
import heapq
n = int(input())
xs = list(map(int, input().split()))
head = heapq.heapify(xs[:n])
body = xs[n:2*n]
body_and_tail = sorted(xs[n:])
sum_tail = sum(body_and_tail_list[:n])
unused_tail = heapq.heapify(body_and_tail[-n:])
ans = -1000000000000000000000
temp = sum(head) - sum_tail
for b in body:
    heapq.push(head, b)
    temp = temp - heapq.pop(head) - heapq.pop(unused_tail) + 2*b
    ans = max(ans, temp)
print(ans)
Problem p03818 (python)

Fixed submission:
from collections import Counter

_ = input()
xs = Counter(map(int, input().split()))
even = sum(1 for (k, c) in xs.items() if c%2==0)
odd = sum(1 for (k, c) in xs.items() if c%2==1)
print(odd + (even//2)*2)

Buggy submission (verdict: Runtime Error):
use std::io::stdin;

fn main(){
    let x = geti64s()[0];
    let (d, m) = (x/11, x%11);
    println!("{}", match m {
        0         => d*2,
        x if x<=6 => d*2 + 1,
        _         => d*2 + 2
    });
}

#[allow(dead_code)]
fn getline() -> String {
    let mut s = String::new();
    match stdin().read_line(&mut s){
        Ok(_) => {s.trim().to_string()}
        Err(_) => String::new()
    }
}

#[allow(dead_code)]
fn getvec() -> Vec<usize>{
    let line = getline();
    line.split_whitespace().map(|x| x.parse().unwrap()).collect()
}

#[allow(dead_code)]
fn geti64s() -> Vec<i64>{
    let line = getline();
    line.split_whitespace().map(|x| x.parse().unwrap()).collect()
}

#[allow(dead_code)]
fn getpair() -> (usize, usize){
    let nm = getvec();
    (nm[0], nm[1])
}
Problem p03856 (python)

Fixed submission:
s = input()

def solve(s):
    i = 0
    n = len(s)

    while i < n:
        if s[i:i+5] == 'dream':
            if s[i+5:i+7] != 'er':
                i += 5
            elif i+7 < n and s[i+7] == 'a':
                i += 5
            else:
                i += 7
        elif s[i:i+5] == 'erase':
            if i+5 < n and s[i+5] == 'r':
                i += 6
            else:
                i += 5
        else:
            return False
    return True

if solve(s):
    print("YES")
else:
    print('NO')

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

def solve(s):
    i = 0
    n = len(s)

    while i < n:
        if s[i:i+5] == 'dream':
            if s[i+5:i+7] != 'er':
                i += 5
            elif i+7 < n and s[i+7] == 'a':
                i += 5
            else:
                i += 7
        elif s[i:i+5] == 'erase':
            if s[i+5] == 'r':
                i += 6
            else:
                i += 5
        else:
            return False
    return True

if solve(s):
    print("Yes")
else:
    print('No')
Problem p03947 (python)

Fixed submission:
def solve(s):
    ans = 0
    while len(s)>1:
        ans += s[0]!=s[1]
        s = s[1:]
    return ans

S = input()
print(solve(S))

Buggy submission (verdict: Runtime Error):
def solve(s):
    if len(s)<=1:
        return 0
    return (s[0]!=s[1]) + solve(s[1:])

S = input()
print(solve(S))