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

Fixed submission:
#!/usr/bin/env python3

import sys


# 再帰深度の制限
REC_LIMIT = 100000

# 頂点の色
UNDEF = 0
WHITE = 1
BLACK = -WHITE


# 所与のグラフが二部グラフならば，(True, color[])を返す
# さもなければ，(False, None)を返す
# 参考：『プログラミングコンテストチャレンジブック』（第2版）p.94
def is_bipartite_graph(adj_list):
    n = len(adj_list)  # 頂点数
    color = [UNDEF] * n

    # 頂点をWHITEとBLACKで塗っていく
    def dfs(v, c):
        color[v] = c
        for u in adj_list[v]:
            if color[u] == c:
                # 隣接頂点が同色で塗られていたら不可
                return False
            if color[u] == UNDEF and not dfs(u, -c):
                # 隣接頂点が未彩色なら，反対の色で塗れるか
                return False
        return True  # すべて色を塗れた
    for i in range(n):
        if color[i] == 0:
            # 未彩色なら，WHITEで塗ってみる
            if not dfs(i, WHITE):
                return (False, None)
    return (True, color)


def compute_max_additional_edges(n, m, adj_list):
    is_bi, color = is_bipartite_graph(adj_list)
    if not is_bi:
        # 二部グラフではない場合
        return n * (n - 1) // 2 - m
    else:
        # 二部グラフである場合
        w = sum(c == WHITE for c in color)
        b = sum(c == BLACK for c in color)
        return w * b - m


def main():
    # 最大再帰深度の再設定
    sys.setrecursionlimit(REC_LIMIT)
    # 入力の読み込み
    n, m = (int(x) for x in input().split())
    adj_list = [set() for _ in range(n)]
    for _ in range(m):
        a, b = (int(x) - 1 for x in input().split())
        adj_list[a].add(b)
        adj_list[b].add(a)
    res = compute_max_additional_edges(n, m, adj_list)
    print(res)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3

import sys


# 再帰深度の制限
REC_LIMIT = 10000

# 頂点の色
UNDEF = 0
WHITE = 1
BLACK = -WHITE


# 所与のグラフが二部グラフならば，(True, color[])を返す
# さもなければ，(False, None)を返す
# 参考：『プログラミングコンテストチャレンジブック』（第2版）p.94
def is_bipartite_graph(adj_list):
    n = len(adj_list)  # 頂点数
    color = [UNDEF] * n

    # 頂点をWHITEとBLACKで塗っていく
    def dfs(v, c):
        color[v] = c
        for u in adj_list[v]:
            if color[u] == c:
                # 隣接頂点が同色で塗られていたら不可
                return False
            if color[u] == UNDEF and not dfs(u, -c):
                # 隣接頂点が未彩色なら，反対の色で塗れるか
                return False
        return True  # すべて色を塗れた
    for i in range(n):
        if color[i] == 0:
            # 未彩色なら，WHITEで塗ってみる
            if not dfs(i, WHITE):
                return (False, None)
    return (True, color)


def compute_max_additional_edges(n, m, adj_list):
    is_bi, color = is_bipartite_graph(adj_list)
    if not is_bi:
        # 二部グラフではない場合
        return n * (n - 1) // 2 - m
    else:
        # 二部グラフである場合
        w = sum(c == WHITE for c in color)
        b = sum(c == BLACK for c in color)
        return w * b - m


def main():
    # 最大再帰深度の再設定
    sys.setrecursionlimit(REC_LIMIT)
    # 入力の読み込み
    n, m = (int(x) for x in input().split())
    adj_list = [set() for _ in range(n)]
    for _ in range(m):
        a, b = (int(x) - 1 for x in input().split())
        adj_list[a].add(b)
        adj_list[b].add(a)
    res = compute_max_additional_edges(n, m, adj_list)
    print(res)


if __name__ == '__main__':
    main()
Problem p03866 (python)

Fixed submission:
#!/usr/bin/env python3

import math
import itertools


INVALID = -1
INF = 10 ** 12


def dijkstra_dense(num_vs, adj_matrix, source, dest):
    dist = [INF for _ in range(num_vs)]
    visited = [False for _ in range(num_vs)]
    dist[source] = 0
    while True:
        u = min((j for j in range(num_vs) if not visited[j]),
                key=lambda i: dist[i], default=INVALID)
        if u == INVALID or dist[u] == INF:
            break
        visited[u] = True
        for v in range(num_vs):
            w = adj_matrix[u][v]
            if u != v and w < INF:
                new_len = dist[u] + w
                if new_len < dist[v]:
                    dist[v] = new_len
    return dist[dest]


def main():
    # 始点を頂点0、終点を頂点N + 1とする
    x0, y0, xf, yf = (int(x) for x in input().split())
    n = int(input())
    xs = [None for _ in range(n + 2)]
    ys = [None for _ in range(n + 2)]
    rs = [None for _ in range(n + 2)]
    xs[0], ys[0], rs[0] = x0, y0, 0
    xs[n + 1], ys[n + 1], rs[n + 1] = xf, yf, 0
    for i in range(1, n + 1):
        xs[i], ys[i], rs[i] = (int(z) for z in input().split())
    adj_matrix = [[INF for _ in range(n + 2)] for _ in range(n + 2)]
    for i, j in itertools.product(range(n + 2), repeat=2):
        adj_matrix[i][j] = max(0, math.hypot(xs[i] - xs[j],
                                             ys[i] - ys[j]) - (rs[i] + rs[j]))
    res = dijkstra_dense(n + 2, adj_matrix, 0, n + 1)
    print("{:.12f}".format(res))


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env pypy3

import math
import itertools


INVALID = -1
INF = 10 ** 12


def dijkstra_dense(num_vs, adj_matrix, source, dest):
    dist = [INF for _ in range(num_vs)]
    visited = [False for _ in range(num_vs)]
    dist[source] = 0
    while True:
        u = min((j for j in range(num_vs) if not visited[j]),
                key=lambda i: dist[i], default=INVALID)
        if u == INVALID or dist[u] == INF:
            break
        visited[u] = True
        for v in range(num_vs):
            w = adj_matrix[u][v]
            if u != v and w < INF:
                new_len = dist[u] + w
                if new_len < dist[v]:
                    dist[v] = new_len
    return dist[dest]


def main():
    # 始点を頂点0、終点を頂点N + 1とする
    x0, y0, xf, yf = (int(x) for x in input().split())
    n = int(input())
    xs = [None for _ in range(n + 2)]
    ys = [None for _ in range(n + 2)]
    rs = [None for _ in range(n + 2)]
    xs[0], ys[0], rs[0] = x0, y0, 0
    xs[n + 1], ys[n + 1], rs[n + 1] = xf, yf, 0
    for i in range(1, n + 1):
        xs[i], ys[i], rs[i] = (int(z) for z in input().split())
    adj_matrix = [[INF for _ in range(n + 2)] for _ in range(n + 2)]
    for i, j in itertools.product(range(n + 2), repeat=2):
        adj_matrix[i][j] = max(0, math.hypot(xs[i] - xs[j],
                                             ys[i] - ys[j]) - (rs[i] + rs[j]))
    res = dijkstra_dense(n + 2, adj_matrix, 0, n + 1)
    print("{:.12f}".format(res))


if __name__ == '__main__':
    main()
Problem p04026 (python)

Fixed submission:
#!/usr/bin/env python3

NO_SOL = (-1, -1)


# 所与の文字列の部分文字列であって、アンバランスなものを1つ探す
# 対象とするのは、"AA"および"ABA"のみ
# 結果のインデックスは0始まりである
def search_unbalanced_substr(s):
    n = len(s)
    # "AA"を探す
    for i in range(n - 1):
        if s[i] == s[i + 1]:
            return i, i + 1
    # "ABA"を探す
    for i in range(n - 2):
        if s[i] == s[i + 2]:
            return i, i + 2
    # 見つからなければ
    return NO_SOL


def main():
    ans = search_unbalanced_substr(input())
    if ans == NO_SOL:
        print(*ans)
    else:
        print(*(i + 1 for i in ans))


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env pypy3

import collections
import itertools


MAX_S = 100
NO_SOL = (-1, -1)


def is_unbalanced(s):
    ctr = collections.Counter(s)
    total = sum(ctr.values())
    m = max(ctr.values())
    return m >= total // 2 + 1


def find_unbalanced_substr(s):
    l = len(s)
    for start, end in itertools.combinations(range(l), 2):
        if is_unbalanced(s[start:end + 1]):
            return start, end
    return NO_SOL


def main():
    s = input()
    assert len(s) <= MAX_S
    ans = find_unbalanced_substr(s)
    if ans == NO_SOL:
        print(*ans)
    else:
        print(*(x + 1 for x in ans))


if __name__ == '__main__':
    main()
Problem p02582 (python)

Fixed submission:
S = input()
a = list()
b = 0
u = 0
for i in range (len(S)):
    if S[u] == 'R':
        b = b + 1
    else:
        a.append(b)
        b = 0
    u = u + 1
a.append(b)
a.sort()
a.reverse()
print(a[0])

Buggy submission (verdict: Runtime Error):
S = input()
a = list()
b = 0
u = 0
for i in range (len(S)):
    if S[u] == 'R':
        b = b + 1
    else:
        a.append(b)
        b = 0
    u = u + 1
a.sort()
a.reverse()
print(a[0])
Problem p02536 (python)

Fixed submission:
from collections import deque
n,m = map(int,input().split())
g = [[] for _ in range(n)]
for i in range(m):
    a, b = map(int,input().split())
    g[a-1].append(b-1)
    g[b-1].append(a-1)

dist = [-1]*n
q = deque([])
cnt = 0

#連結成分のカウント

for i in range(n):
    if dist[i] != -1:
        continue
    dist[i] = 0
    q.append(i)
    while q:
        v = q.pop()
        s = g[v]
        for j in s:
            if dist[j] != -1:
                continue
            dist[j] = 0
            q.append(j)
    cnt += 1

print(cnt - 1)

Buggy submission (verdict: Runtime Error):
from collections import deque
n,m = map(int,input().split())
g = [[] for _ in range(n)]
for i in range(m):
    a, b = map(int,input().split())
    g[a-1].append(b-1)
    g[b-1].append(a-1)

checked = [False]*n
q = deque([])
cnt = 0

#連結成分のカウント

for i in range(n):
    if checked[i]:
        continue
    checked[i] = True
    q.append(i)
    while q:
        v = q.pop()
        s = g[v]
        for j in s:
            if checked[j]:
                continue
            checked[j] = True
            q.append(j)
    cnt += 1

print(cnt - 1

Buggy submission (verdict: Runtime Error):
n, m = map(int,input().split())
M = [[0 for _ in range(n)] for i in range(n)]
for i in range(m):
    a, b = map(int,input().split())
    M[a][b] = 1
    
cnt = 0   
for i in range(n-1):
    if all(M[i][j] == 0 for j in range(1+i, n)):
        cnt += 1

print(cnt)
Problem p02555 (python)

Fixed submission:
n = int(input())
mod = 10**9 + 7
import math

def cnt(n, i):
    if i == 1:
        return 1
    else:
        l = n - 3*i
        m = i-1
        return  math.factorial(l + m)//(math.factorial(l)*math.factorial(m))
        

if n == 2 or n == 1:
    print(0)
    exit()
if n == 3:
    print(1)
    exit()
else:
    ans = 0
    iter = n // 3
    for i in range(1, iter + 1):
        if i*3 <= n:
            ans += cnt(n, i)%mod
        else:
            continue
        
print(ans % mod)

Buggy submission (verdict: Runtime Error):
s = int(input())
a = [0]*2001
a[3] = 1
for i in range(4,n+1):
    a[i] = a[i-3] + a[i-1]
mod = 10**9+7
print(a[s]%mod)

Buggy submission (verdict: Runtime Error):
n = int(input())
mod = 10**9 + 7
import math

def cnt(n, i):
    if i == 1:
        return 1
    else:
        l = n - 3*i
        m = i-1
        return  math.factorial(l + m)//(math.factorial(l)*math.factorial(m))
        

if n == 2 or n == 1:
    print(0)
if n == 3:
    print(1)
if n > 3:
    ans = 0
    iter = n // 3
    for i in range(1, iter + 1):
        if i*3 <= n:
            ans += cnt(n, i)%mod
        else:
            continue
        
print(ans % mod)
Problem p02579 (python)

Fixed submission:
from collections import deque
def solve():  
    h, w = map(int,input().split())
    ch, cw = map(int,input().split())
    Dh, Dw = map(int,input().split())
    
    M = ['##' + input() + '##' for _ in range(h)]
    for i in range(2):
        M.insert(0,'#'*(w+4))
        M.append('#'*(w+4))
    
    INF = float('inf')
    cost = [[INF for _ in range(w+4)] for _ in range(h+4)]
    cost0 = deque()
    ans = -1
    
    cost0.append((ch+1, cw+1, 0))
    cost[ch+1][cw+1] = 0
    
    move = [(1,0),(0,1),(-1,0),(0,-1)]
    warp = [(i,j) for i in range(-2,3) for j in range(-2,3) if (i,j) not in [(0,0)] + move]
    
    cost1 = deque()
    
    while cost0:
        h, w, c = cost0.popleft()
        cost1.append((h, w, c))
        
        for i,j in move:
            dh = h + i
            dw = w + j
            if M[dh][dw] == '.' and c < cost[dh][dw]: #コストが高いところから低いところに戻らないようにするため
                cost[dh][dw] = c
                cost0.appendleft((dh, dw, cost[dh][dw]))
        
        if len(cost0) == 0:
            while cost1:
                h, w, c = cost1.popleft()
                for i,j in warp:
                    dh = h + i
                    dw = w + j
                    if M[dh][dw] == '.' and c+1 < cost[dh][dw]:  #無駄なワープをなくすため
                        cost[dh][dw] = c+1
                        cost0.append((dh, dw, cost[dh][dw]))
        if cost[Dh+1][Dw+1] != INF:
            ans = cost[Dh+1][Dw+1]
    
    print(ans)

if __name__ == "__main__":
    solve()

Buggy submission (verdict: Runtime Error):
from collections import deque
h, w = map(int,input().split())
ch, cw = map(int,input().split())
dh, dw = map(int,input().split())

M = ['##' + input() + '##' for _ in range(h)]
for i in range(2):
    M.insert(0,'#'*(w+4))
    M.append('#'*(w+4))

INF = float('inf')
cost = [[INF for _ in range(w+4)] for _ in range(h+4)]
cost0 = deque()
ans = -1

cost0.append((ch+1, cw+1, 0))
cost[ch+1][cw+1] = 0

move = [(1,0),(0,1),(-1,0),(0,-1)]
warp = [(i,j) for i in range(-2,3) for j in range(-2,3) if (i,j) not in [(0,0)] + move]

cost1 = deque()

while cost0:
    h, w, c = cost0.popleft()
    cost1.append((h, w, c))
    
    for i,j in move:
        dh = h + i
        dw = w + j
        if M[dh][dw] == '.' and c < cost[dh][dw]: #コストが高いところから低いところに戻らないようにするため
            cost[dh][dw] = c
            cost0.appendleft((dh, dw, cost[dh][dw]))
    
    if len(cost0) == 0:
        while cost1:
            h, w, c = cost1.popleft()
            for i,j in warp:
                dh = h + i
                dw = w + j
                if S[dh][dw] == '.' and c+1 < cost[dh][dw]:  #無駄なワープをなくすため
                    cost[dh][dw] = c+1
                    cost0.append((dh, dw, cost[dh][dw]))
    if cost[dh+1][dw+1] != INF:
        ans = cost[dh+1][dw+1]

print(ans)
Problem p02755 (python)

Fixed submission:
a, b = map(int, input().split())
ans = -1
for i in range(1, 1250):
    if int(i/100*8) == a and int(i/10) == b:
        ans = i
        break
print(ans)

Buggy submission (verdict: Runtime Error):
A,B=map(int,input().split())
ans=-1
for i in range(1000):
  if int(i/100*8)==a and int(i/10)==b:
    ans==i
    break
print(ans)
Problem p02843 (python)

Fixed submission:
X = int(input())
dp = [0 for _ in range(X + 110)]
dp[0] = 1
for i in range(X + 1):
    if dp[i] == 0:
        continue
    dp[i + 100] = 1
    dp[i + 101] = 1
    dp[i + 102] = 1
    dp[i + 103] = 1
    dp[i + 104] = 1
    dp[i + 105] = 1
print(dp[X])

Buggy submission (verdict: Runtime Error):
x=int(input())
p=[100+i for i in range(6)]
def dp(x):
    if x<99:
        return False
    if x in p:
        return True
    else:
        if any(dp(x-i) for i in range(100,106)):
            return True
        else:
            False
print(1 if dp(x) else 0)
Problem p02854 (python)

Fixed submission:
n=int(input())
A=list(map(int,input().split()))
ans=float('INF')
sa=[0]
for i,a in enumerate(A):
    sa.append(sa[i]+a)
for i in range(n+1):
    ans=min(ans,abs(sa[i]-(sa[-1]-sa[i])))
print(ans)

Buggy submission (verdict: Runtime Error):
n=int(input())
A=list(map(int,input().split()))
m=float('INF')
sa=[]
for i,a in enumerate(A):
    sa.append(sa[i]+ai)
for i in range(n+1):
    ans=min(ans,abs(sa[i]-(sa[-1]-sa[i])))
print(ans)
Problem p02866 (python)

Fixed submission:
from collections import Counter
mod = 998244353
n = int(input())
d = list(map(int,input().split()))
if d[0] != 0:
    print(0)
    exit()

C = Counter(d)
C = dict(sorted(C.items()))

memo1 = C[1]
memo2 = 1
ans = 1

for i in range(1,n):
    if d[i] == 0:
        print(0)
        exit()

for key in C:
    if key >= 2:
        if memo2 + 1 != key: #道が途切れている場合はダメ
            print(0)
            exit()
        ans = (ans * memo1 ** C[key]) % mod #modは和について閉じているため先にわる
        memo1 = C[key]
        memo2 = key
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
d = list(map(int,input().split()))
if d[0] != 0:
    print(0)
else:
    ans = 1
    most_far = max(d)
    for i in range(most_far-1):
        ans *= d.count(most_far - (i+1))**d.count(most_far-i)
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
d = list(map(int,input().split()))
if d[0] != 0:
    print(0)
else:
    ans = 1
    for i in range(1,n):
        dp = d[i] - 1
        ans *= d.count(dp)
print(ans)
Problem p02936 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**6)
def dfs(tree, n, ans):
    for i in tree[n]:
        ans[i] += ans[n]
        tree[i].remove(n)
        dfs(tree, i, ans)
 
n, q = map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(n-1)]
px = [list(map(int,input().split())) for _ in range(q)]
 
g = [[] for _ in range(n)]
for i in range(n-1):
    g[ab[i][0]-1].append(ab[i][1]-1)
    g[ab[i][1]-1].append(ab[i][0]-1)
 
ans = [0]*n
for i in range(q):
    ans[px[i-1][0]-1] += px[i-1][1]
dfs(g, 0, ans)
 
print(*ans)

Buggy submission (verdict: Runtime Error):
def solve():
    def dfs(tree, n, ans):
        for i in tree[n]:
            ans[i] += ans[n]
            tree[i].remove(n)
            dfs(tree, i, ans) #再帰関数になっている。次の木の中を探索
     
    n, q = map(int,input().split())
    ab = [list(map(int,input().split())) for _ in range(n-1)]
    px = [list(map(int,input().split())) for _ in range(q)]
     
    g = [[] for _ in range(n)]
    for i in range(n-1):
        g[ab[i][0]-1].append(ab[i][1]-1)
        g[ab[i][1]-1].append(ab[i][0]-1)
    
    ans = [0]*n
    for i in range(q):
        ans[px[i-1][0]-1] += px[i-1][1]
    dfs(g, 0, ans)
     
    print(*ans)
    
if __name__ == "__main__":
    solve()

Buggy submission (verdict: Runtime Error):
def dfs(tree, n, ans):
    for i in tree[n]:
        ans[i] += ans[n]
        tree[i].remove(n)
        dfs(tree, i, ans)

n, q = map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(n-1)]
px = [list(map(int,input().split())) for _ in range(q)]
 
g = [[] for _ in range(n)]

for i in range(n-1):
    g[ab[i][0]-1].append(ab[i][1]-1)
    g[ab[i][1]-1].append(ab[i][0]-1)

ans = [0]*n
for i in range(q):
    ans[px[i-1][0]-1] += px[i-1][1]
dfs(g, 0, ans)

print(*ans)
Problem p02939 (python)

Fixed submission:
S=input()
cnt=0
pre=''
tmp=''
for s in S:
    tmp+=s
    if tmp!=pre:
        pre=tmp
        tmp=''
        cnt+=1
print(cnt)

Buggy submission (verdict: Runtime Error):
S=input()
l=len(S)
def solve(s,h):
    if h==1:
        return 1
    elif h==2:
        if s[0]==s[1]:
            return 1
        else:
            return 2
    else:
        if s[h-1]==s[h-2]:
            return solve(s,h-3)+2
        else:
            return solve(s,h-1)+1
print(solve(S,l))

Buggy submission (verdict: Runtime Error):
S=input()
l=len(S)
def solve(s,h):
    if h==1:
        return 1
    elif h==2:
        if s[0]==s[1]:
            return 1
        else:
            return 2
    elif h==0:
        return 0
    else:
        if s[h-1]==s[h-2]:
            return solve(s,h-3)+2
        else:
            return solve(s,h-1)+1
print(solve(S,l))

Buggy submission (verdict: Runtime Error):
S=input()
l=len(S)
def solve(s,h):
    if h==1:
        return 1
    elif h==2:
        if s[0]==s[1]:
            return 1
        else:
            return 2
    elif h==0:
        return 0
    else:
        if s[h-1]==s[h-2]:
            return solve(s,h-3)+2
        else:
            return solve(s,h-1)+1
print(solve(S,l))
Problem p03062 (python)

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

law_ans = 0
absminA = float('inf')
for a in A:
    law_ans += abs(a)
    absminA = min(absminA, abs(a))


cnt_neg = 0

for a in A:
    if a < 0:
        cnt_neg += 1

cnt_0 = A.count(0)

if cnt_0 == 0:
    if cnt_neg%2 == 0:
        print(law_ans)
    else:
        print(law_ans-2*absminA)
else:
    print(law_ans)

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

law_ans = 0
absminA = float('inf')
for a in A:
    law_ans += abs(a)
    absminA = min(absminA, abs(a))


cnt_neg = 0

for a in A:
    if a < 0:
        cnt_neg += 1

cnt_0 = A.count(0)

if cnt_0 == 0:
    if cnt_neg%2 == 0:
        print(law_ans)
    else:
        print(law_ans-2*absminA)
else:
    pritn(law_ans)

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

law_ans = 0
absminA = float('inf')
for a in A:
    law_ans += abs(a)
    absminA = min(absminA, a)


cnt_neg = 0

for a in A:
    if a < 0:
        cnt_neg += 1

cnt_0 = A.count(0)

if cnt_0 == 0:
    if cnt_neg%2 == 0:
        print(law_ans)
    else:
        print(law_ans-2*absminA)
else:
    pritn(law_ans)
Problem p03069 (python)

Fixed submission:
n = int(input())
s = input()
x = 0
y = s.count('.')
c = min(n-y, y)
for i in range(n):
    t = s[i] == '#' #＃であればｔがTrueになる
    x += t
    y -= 1 - t
    c = min(c, x+y)
print(c)

Buggy submission (verdict: Runtime Error):
from copy import *
n = int(input())
s = list(input())
S = []
l = 0
for i in range(n-1):
    if s[i] != s[i+1]:
        S.append(s[l:i+1])
        l = i+1
if S[-1][0] == s[-1]:
    S[-1] += s[l:]
else:
    S.append(s[l:])


ans = 0
m = len(S)

if S[0][0] == '#':
    for i in range(m//2):
        ans += min(len(S[i*2]), len(S[i*2+1]))
else:
    for i in range(m//2 - 1):
        ans += min(len(S[i*2+1]), len(S[i*2+2]))

print(ans)

Buggy submission (verdict: Runtime Error):
 = int(input())
s = list(input())
cnt1 = 0
for i in range(n-1):
    if s[i] == '#' and s[i+1] == '.':
        cnt += 1
        s[i+1] = '#'

cnt2 = 0
for i in range(n-1):
    if s[i] == '#' and s[i+1] == '.':
        cnt2 += 1
        s[i+1] = '.'


print(min(cnt1, cnt2))
Problem p03086 (python)

Fixed submission:
S=input()
n=len(S)
ans=0
for i in range(n):
    for j in range(i,n):
        if all('ACGT'.count(c)==1 for c in S[i:j+1]):
            ans=max(ans,j-i+1)
print(ans)

Buggy submission (verdict: Runtime Error):
S=list(str(input()))
A=["A","T","G","C"]
#print(S)
cnt=0
ans=[]
for (i,s) in enumerate(S):
    if s in A:
        cnt+=1
    else:
        ans.append(cnt)
        cnt=0
print(max(ans))

Buggy submission (verdict: Runtime Error):
S=list(str(input()))
A=["A","T","G","C"]
print(S)
cnt=0
ans=[]
for (i,s) in enumerate(S):
    if s in A:
        cnt+=1
    else:
        ans.append(cnt)
        cnt=0
print(max(ans))
Problem p03150 (python)

Fixed submission:
s=input()
ans=False
for x in range(len(s)):
    for y in range(x,len(s)):
        if (s[:x]+s[y:])=='keyence':
            ans=True
if ans:
    print('YES')
else:
    print('NO')

Buggy submission (verdict: Runtime Error):
keyence
Problem p03261 (python)

Fixed submission:
n=int(input())
lw=[input() for i in range(n)]
used=set()
cond=True
last=lw[0][0]
for w in lw:
    if w in used or last !=w[0]:
        cond=False
        break
    used.add(w)
    last=w[-1]
print("Yes" if cond else "No")

Buggy submission (verdict: Runtime Error):
n=int(input())
lw=[input() for i in range(n)]
used=set()
last=lw[0][0]
for w in lw:
    if w in used or last !=w[0]:
        cond=False
        break
    used.add(w)
    last=w[-1]
print("Yes" if cond else "No")
Problem p03472 (python)

Fixed submission:
N,H=map(int,input().split())
B=[]
A=0
for _ in range(N):
    a,b=map(int,input().split())
    A=max(A,a)
    B.append(b)
B.sort(reverse=True)
ans=(H-1)//A+1
for i in range(N):
    H-=B[i]
    if H<=0:
        ans=min(ans,i+1)
        break
    ans=min(ans,(H-1)//A+1+i+1)
print(ans)

Buggy submission (verdict: Runtime Error):
N,H=map(int,input().split())
B=[]
A=0
for _ in range(N):
    a,b = map(int,input().split())
    A = max(A,a)
    B.append(b)
B = sorted(reverse=True) + [0]

i = 0
while B[i] >= A:
    i += 1
B = B[:i]

ans = 0
for i in range(len(B)):
    H -= B[i]
    ans += 1
    if H <= 0:
        print(ans)
        exit()
print(ans + (H -1)//A + 1)
Problem p03474 (python)

Fixed submission:
a,b = map(int,input().split())
s = input()
for i in range(a):
    if s[i] == '-':
        print('No')
        exit(0)
 
if s[a] != '-':
    print('No')
    exit(0)
 
for i in range(a+1,a+b):
    if s[i] == '-':
        print('No')
        exit(0)
 
print('Yes')

Buggy submission (verdict: Runtime Error):
a,b=map(int,input().split())
s=input()
f=s.index("-")
l=len(s)-s.index("-")-1
print("Yes" if a==f and b==l else "No")
Problem p03544 (python)

Fixed submission:
n=int(input())
a=[2,1]
for i in range(100):
    a.append(a[i]+a[i+1])
print(a[n])

Buggy submission (verdict: Runtime Error):
n=int(input())
a=[2,1]
for i in range(84):
    a.append(a[i]+a[i+1])
print(a[n])