alexjercan/bugnet huggingface dataset:
Problem p02934 (Python) — buggy submission, verdict: Runtime Error

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

div = 0
for i in range(n):
    div += 1 / a[i]
print(1 / div)


Error: TypeError: unsupported operand type(s) for /: 'list' and 'int'
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02934/Python/s178492873.py", line 6, in <module>
    div += a / a[i]
TypeError: unsupported operand type(s) for /: 'list' and 'int'


Fixed submission:

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

div = 0
for i in range(n):
    div += a / a[i]
print(1 / div)
Problem p02934 (Python) — buggy submission, verdict: Runtime Error

N = input()
A = list(map(float, input().split()))

print(1 / sum(1 / x for x in A))


Error: 0

Fixed submission:

def gcd(a, b):
    mi = min(a, b)
    ma = max(a, b)
    r = ma % mi
    if r == 0:
        return mi
    gcd(mi, r)


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

Sum = sum(A)
s = []
multi = 1.0
for t in A:
    multi = int((multi * t) / gcd(int(multi), int(t)))

for a in A:
    s.append(int(multi / a))

print(multi / sum(s))
Problem p02934 (Python) — buggy submission, verdict: Runtime Error

import numpy as np

n = int(input())

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

ue = 1

for aa in a:
    ue *= aa

shita = 0

for aa in a:
    shita += ue / aa

print(ue / shita)


Error: TLE

Fixed submission:

import numpy as np

n = int(input())

a = list(map(int, input().split()))
p = np.prod(a)

top = p
under = 0

for aa in a:
    under += p / aa

print(top / under)
Problem p02934 (Python) — buggy submission, verdict: Runtime Error

import numpy as np

N = int(input())
A = [float(x) for x in input().split()]

nA = np.array(A)
print(np.reciprocal(np.sum(np.reciprocal(nA))))


Error: TLE

Fixed submission:

import numpy as np

N = int(input())
A = [float(input()) for _ in range(N)]

nA = np.array(A)
print(np.reciprocal(np.sum(np.reciprocal(nA))))
Problem p02934 (Python) — buggy submission, verdict: Runtime Error

import math

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

# num is numerator
# den is denominator
num, den = A[0], 0

for i in A:
    num = (num * i) // math.gcd(num, i)

for i in A:
    den += num // i

ans = num / den
print(ans)


Error: 0

Fixed submission:

import math

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

a = A[0]

for i in range(1, N):
    a = (a * A[i]) // math.gcd(a, A[i])

b = 0

for i in range(N):
    b += a // A[i]

print(a / b)
Problem p02934 (Python) — buggy submission, verdict: Runtime Error

from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    n = int(input())
    a = list(map(int, input().split()))

    num = 1
    for ai in a:
        num *= ai

    den = sum([num // a[i] for i in range(n)])

    print(num / den)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()


Error: TLE

Fixed submission:

from sys import stdin, setrecursionlimit
import numpy as np


def main():
    input = stdin.buffer.readline
    n = int(input())
    a = list(map(int, input().split()))

    num = np.prod(a)

    den = sum([num // a[i] for i in range(n)])

    print(num / den)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()
Problem p02935 (Python) — buggy submission, verdict: Runtime Error

import heapq
import math


def solve(n, v):
    heapq.heapify(v)

    while len(v) != 1:
        x = heapq.heappop(v)
        y = heapq.heappop(v)
        z = (x + y) / 2
        heapq.heappush(v, z)

    return v[0]


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

print(solve(n, v))


Error: TypeError: object of type 'int' has no len()
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02935/Python/s983148308.py", line 21, in <module>
    print(solve(n, v))
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02935/Python/s983148308.py", line 9, in solve
    while len(nn) != 1:
TypeError: object of type 'int' has no len()


Fixed submission:

import heapq
import math


def solve(n, v):
    heapq.heapify(v)
    nn = math.ceil(n / 2)

    while len(nn) != 1:
        x = heapq.heappop(v)
        y = heapq.heappop(v)
        z = (x + y) / 2
        heapq.heappush(v, z)

    return v[0]


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

print(solve(n, v))
Problem p02935 (Python) — buggy submission, verdict: Time Limit Exceeded

def sort_index(a):
    for i in range(len(a)):
        for j in range(i + 1, len(a)):
            if a[i] > a[j]:
                a[i], a[j] = a[j], a[i]
    return a


def get_answer(n, a):
    n = int(n)
    a = [int(v) for v in a.split(" ")]
    a = sort_index(a)
    v_max = 0
    v = a[0]
    for i in range(1, len(a)):
        v = (v + a[i]) / 2
    if v > v_max:
        v_max = v
    return v_max


if __name__ == "__main__":
    input1 = input()
    input2 = input()
    print(get_answer(input1, input2))


Error: TLE

Fixed submission:

import numpy as np


def get_answer(n, a):
    n = int(n)
    a = [int(v) for v in a.split(" ")]
    indexes_all = create_index(n)
    v_max = -1
    for indexes in indexes_all:
        v = a[indexes[0]]
        for i in range(1, len(indexes)):
            v = (v + a[indexes[i]]) / 2
        if v > v_max:
            v_max = v
    return v_max


def create_index(n):
    ret_all = []
    index_queue = np.arange(0, n)
    ret = []
    search_index(index_queue, ret_all, ret, n)
    return ret_all


def search_index(index_q, ret_all, ret, n):
    if n <= 0:
        ret_all.append(list(ret))
        return
    for i in range(n):
        index = index_q[i]
        index_q = np.delete(index_q, i)
        ret.append(index)
        search_index(index_q, ret_all, ret, n - 1)
        index_q = np.insert(index_q, i, index)
        ret.pop()


if __name__ == "__main__":
    input1 = input()
    input2 = input()
    print(get_answer(input1, input2))
Problem p02935 (Python) — buggy submission, verdict: Time Limit Exceeded

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

v.sort(reverse=True)

while len(v) > 1:
    v = v[:-2] + [(v[-1] + v[-2]) / 2]

print(v[0])


Error: TLE

Fixed submission:

from itertools import combinations

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

ans = 0


def dfs(v):
    if len(v) == 2:
        global ans
        ans = max((v[0] + v[1]) / 2, ans)
        return

    for vv in combinations(v, 2):
        v_alche = v[:]
        v_alche.remove(vv[0])
        v_alche.remove(vv[1])
        v_alche.append((vv[0] + vv[1]) / 2)
        dfs(v_alche)


dfs(values)
print(ans)
Problem p02935 (Python) — buggy submission, verdict: Time Limit Exceeded

# -*- coding: utf-8 -*-
from decimal import Decimal
from itertools import permutations

# 整数の入力
N = int(input())

# スペース区切りの整数の入力
V = list(map(Decimal, input().split()))

result = 0

V = sorted(V)
result = V[0]

for value in V[1:]:
    result = (result + value) / 2


# 出力
print(result)


Error: TLE

Fixed submission:

# -*- coding: utf-8 -*-
from decimal import Decimal
from itertools import permutations

# 整数の入力
N = int(input())

# スペース区切りの整数の入力
V = list(map(Decimal, input().split()))

result = 0

for values in permutations(V, N):
    new_result = values[0]

    for value in values[1:]:
        new_result = (new_result + value) / 2

    if result < new_result:
        result = new_result

# 出力
print(result)
Problem p02936 (Python) — buggy submission, verdict: Time Limit Exceeded

import sys

input = sys.stdin.readline  # NOQA
sys.setrecursionlimit(10**7)  # NOQA


def dfs(G, v, p, counter):
    """G: graph, v: vertex, p: parent"""
    # Loop for each child
    counter_v = counter[v]
    for c in G[v]:
        if c == p:
            continue  # Avoid multiple access to parent
        counter[c] += counter_v
        dfs(G, c, v, counter)


def main():
    N, Q = map(int, input().split())
    G = [[] for _ in range(N)]
    for _ in range(N - 1):
        a, b = map(int, input().split())
        a -= 1
        b -= 1
        G[a].append(b)
        G[b].append(a)

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

    dfs(G, 0, -1, counter)
    print(*counter)


if __name__ == "__main__":
    main()


Error: TLE

Fixed submission:

import sys

input = sys.stdin.readline  # NOQA
sys.setrecursionlimit(10**7)  # NOQA


def dfs(G, v, p, counter, x):
    """G: graph, v: vertex, p: parent"""
    counter[v] += x
    # Loop for each child
    for c in G[v]:
        if c == p:
            continue  # Avoid multiple access to parent
        dfs(G, c, v, counter, x)


def calc_parent(G, v, p, parent):
    parent[v] = p
    for c in G[v]:
        if c == p:
            continue
        calc_parent(G, c, v, parent)


def main():
    N, Q = map(int, input().split())
    G = [[] for _ in range(N)]
    for _ in range(N - 1):
        a, b = map(int, input().split())
        a -= 1
        b -= 1
        G[a].append(b)
        G[b].append(a)

    parent = [-1] * N
    calc_parent(G, 0, -1, parent)
    counter = [0] * N
    for _ in range(Q):
        p, x = map(int, input().split())
        p -= 1
        dfs(G, p, parent[p], counter, x)

    print(*counter)


if __name__ == "__main__":
    main()
Problem p02936 (Python) — buggy submission, verdict: Time Limit Exceeded

def main():
    N, Q = map(int, input().split())

    values = [0] * N
    links = [[] for _ in range(N)]
    for _ in range(N - 1):
        a, b = map(int, input().split())
        links[a - 1].append(b - 1)
        links[b - 1].append(a - 1)
    for _ in range(Q):
        p, x = map(int, input().split())
        values[p - 1] += x

    s = [(0, -1)]
    while s:
        i, p = s.pop()
        for j in links[i]:
            if j == p:
                continue
            values[j] += values[i]
            s.append((j, i))
    print(*values)


main()


Error: TLE

Fixed submission:

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

values = [0] * N
links = [[] for _ in range(N)]
for _ in range(N - 1):
    a, b = map(int, input().split())
    links[a - 1].append(b - 1)
    links[b - 1].append(a - 1)
for _ in range(Q):
    p, x = map(int, input().split())
    values[p - 1] += x

s = [(0, -1)]
while s:
    i, p = s.pop(0)
    for j in links[i]:
        if j == p:
            continue
        values[j] += values[i]
        s.append((j, i))
print(*values)
Problem p02936 (Python) — buggy submission, verdict: Time Limit Exceeded

from collections import defaultdict

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

G = defaultdict(list)

for _ in range(N - 1):
    a, b = map(int, input().split())
    G[a].append(b)
    G[b].append(a)

parents = [0] * (N + 1)
values = [0] * (N + 1)
values_sum = [-1] * (N + 1)

for _ in range(Q):
    p, x = map(int, input().split())
    values[p] += x

# solve
values_sum[1] = values[1]

queue = [1]
while len(queue) > 0:
    p = queue.pop()
    for q in G[p]:
        if values_sum[q] == -1:
            values_sum[q] = values_sum[p] + values[q]
            queue.append(q)

print(*values_sum[1:])


Error: TLE

Fixed submission:

from collections import deque

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

G = dict()
for i in range(1, N + 1):
    G[i] = dict()

for _ in range(N - 1):
    a, b = map(int, input().split())
    G[a][b] = 1
    G[b][a] = 1

parents = [0] * (N + 1)
values = [0] * (N + 1)
values_sum = [-1] * (N + 1)

for _ in range(Q):
    p, x = map(int, input().split())
    values[p] += x

# solve
values_sum[1] = values[1]

queue = deque([1])
while len(queue) > 0:
    p = queue.popleft()
    for q in G[p].keys():
        if G[p][q] == 1:
            if values_sum[q] == -1:
                values_sum[q] = values_sum[p] + values[q]
                G[q][p] = 0
                queue.append(q)

print(*values_sum[1:])
Problem p02936 (Python) — buggy submission, verdict: Runtime Error

# -*- coding: utf-8 -*-

import sys


sys.setrecursionlimit(10**6)


def main():
    n, q = map(int, sys.stdin.readline().split())

    tree = [[] for x in range(n + 1)]
    data = [0 for x in range(n + 1)]

    for _ in range(n - 1):
        a, b = map(int, sys.stdin.readline().split())
        tree[a].append(b)
        tree[b].append(a)

    for _ in range(q):
        p, x = map(int, sys.stdin.readline().split())
        data[p] += x

    def dfs(p, p2, x):
        data[p] += x
        for p3 in tree[p]:
            if p3 == p2:
                continue
            dfs(p3, p, data[p])

    dfs(1, 0, 0)

    print(" ".join([str(x) for x in data[1:]]))


if __name__ == "__main__":
    main()


Error: 0

Fixed submission:

# -*- coding: utf-8 -*-

import sys


def main():
    n, q = [int(x) for x in sys.stdin.readline().rstrip().split(" ")]

    tree = {}
    data = [0 for x in range(n)]

    for _ in range(n - 1):
        a, b = [int(x) for x in sys.stdin.readline().rstrip().split(" ")]
        if a not in tree:
            tree[a] = []
        tree[a].append(b)

    for _ in range(q):
        p, x = [int(x) for x in sys.stdin.readline().rstrip().split(" ")]
        data[p - 1] += x

    def add(p, x):
        data[p - 1] += x
        if p not in tree:
            return
        for p2 in tree[p]:
            add(p2, data[p - 1])

    add(1, 0)

    print(" ".join([str(x) for x in data]))


if __name__ == "__main__":
    main()
Problem p02936 (Python) — buggy submission, verdict: Time Limit Exceeded

import sys

sys.setrecursionlimit(10**6)
INF = float("inf")
MOD = 10**9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    N, Q = map(int, input().split())

    edges = [[] for _ in range(N + 1)]
    nums = [0 for _ in range(N + 1)]
    for _ in range(N - 1):
        a, b = map(int, input().split())
        edges[a].append(b)
        edges[b].append(a)

    for _ in range(Q):
        p, x = map(int, input().split())
        nums[p] += x

    def dfs(now, parent):
        for i in edges[now]:
            if i != parent:
                nums[i] += nums[now]
                dfs(i, now)

    dfs(1, 0)
    for n in nums[1:]:
        print(n)


if __name__ == "__main__":
    main()


Error: TLE

Fixed submission:

import sys

sys.setrecursionlimit(1000000)
N, Q = map(int, input().split())
A, B = [], []

edges = [[] for _ in range(N + 1)]
nums = [0 for _ in range(N + 1)]
for _ in range(N - 1):
    a, b = map(int, input().split())
    edges[a].append(b)
    edges[b].append(a)

for _ in range(Q):
    p, x = map(int, input().split())
    nums[p] += x


def dfs(now, parent):
    for i in edges[now]:
        if i != parent:
            nums[i] += nums[now]
            dfs(i, now)


dfs(1, 0)
for n in nums[1:]:
    print(n)
Problem p02937 (Python) — buggy submission, verdict: Time Limit Exceeded

import bisect


def main():
    s = input()
    t = input()
    sletters = [0] * 26
    for i in range(len(s)):
        x = ord(s[i]) - ord("a")
        if sletters[x] == 0:
            sletters[x] = [i]
        else:
            sletters[x].append(i)

    ans = 0
    curr_index = -1
    for i in t:
        x = ord(i) - ord("a")
        if sletters[x] == 0:
            print(-1)
            return
        index = bisect.bisect(sletters[x], curr_index)
        # print(sletters[x],i,curr_index,index)
        if index == len(sletters[x]):
            ans += len(s) - curr_index
            curr_index = sletters[x][0]
            ans += curr_index
        else:
            ans += sletters[x][index] - curr_index
            curr_index = sletters[x][index]

    print(ans)


main()


Error: TLE

Fixed submission:

def main():
    s = input()
    t = input()
    sletters = set()
    for i in s:
        sletters.add(i)

    for i in t:
        if i not in sletters:
            print(-1)
            return

    i = 0
    j = 0
    ans = 0
    while i < len(s) and j < len(t):
        if s[i] == t[j]:
            j += 1
        i += 1
        ans += 1
        if i == len(s):
            i = 0

    print(ans)


main()
Problem p02937 (Python) — buggy submission, verdict: Time Limit Exceeded

# -*- coding: utf-8 -*-

from bisect import bisect_left

s = input()
t = input()

if not set(t) <= set(s):
    print(-1)
    exit()

s_dict = {}
for i in range(len(s)):
    c = s[i]
    if c not in s_dict.keys():
        s_dict[c] = [i]
    else:
        s_dict[c].append(i)

repeat = 0
s_idx = 0
for c in t:
    idx = bisect_left(s_dict[c], s_idx)
    if idx == len(s_dict[c]):
        s_idx = s_dict[c][0] + 1
        repeat += 1
    else:
        s_idx = s_dict[c][idx] + 1
else:
    ans = repeat * len(s) + s_idx

print(ans)


Error: TLE

Fixed submission:

# -*- coding: utf-8 -*-

s = input()
t = input()

if not set(t) <= set(s):
    print(-1)
    exit()

repeat = 0
s_idx = 0
for c in t:
    idx = s[s_idx:].find(c)
    if idx == -1:
        idx = s.find(c)
        repeat += 1
    else:
        idx = idx + s_idx
    s_idx = idx + 1
else:
    ans = repeat * len(s) + s_idx

print(ans)
Problem p02937 (Python) — buggy submission, verdict: Time Limit Exceeded

def main():
    s = input()
    t = input()

    if not set(t) <= set(s):
        print(-1)
        return

    s_indexes = {c: [] for c in "abcdefghijklmnopqrstuvwxyz"}
    for i, s_c in enumerate(s):
        s_indexes[s_c].append(i)
    s_pointer = {c: 0 for c in "abcdefghijklmnopqrstuvwxyz"}
    s_length = {c: len(s_indexes[c]) for c in "abcdefghijklmnopqrstuvwxyz"}

    power = 0
    last_index = -1
    for i, t_c in enumerate(t):
        if s_length[t_c] <= s_pointer[t_c]:
            # reset
            s_pointer = {c: 0 for c in "abcdefghijklmnopqrstuvwxyz"}
            power += 1
        elif s_indexes[t_c][s_pointer[t_c]] <= last_index:
            for j in range(s_pointer[t_c], s_length[t_c]):
                if last_index < s_indexes[t_c][j]:
                    s_pointer[t_c] = j
                    break
            else:
                # reset
                s_pointer = {c: 0 for c in "abcdefghijklmnopqrstuvwxyz"}
                power += 1

        last_index = s_indexes[t_c][s_pointer[t_c]]
        s_pointer[t_c] += 1

    print(len(s) * power + last_index + 1)


main()


Error: TLE

Fixed submission:

def main():
    s = input()
    t = input()

    if not set(t) <= set(s):
        print(-1)
        return

    s_indexes = {c: [] for c in "abcdefghijklmnopqrstuvwxyz"}
    for i, s_c in enumerate(s):
        s_indexes[s_c].append(i)
    s_pointer = {c: 0 for c in "abcdefghijklmnopqrstuvwxyz"}
    s_length = {c: len(s_indexes[c]) for c in "abcdefghijklmnopqrstuvwxyz"}

    power = 0
    last_index = -1
    for i, t_c in enumerate(t):
        if s_length[t_c] <= s_pointer[t_c]:
            # reset
            s_pointer = {c: 0 for c in "abcdefghijklmnopqrstuvwxyz"}
            power += 1
        elif s_indexes[t_c][s_pointer[t_c]] <= last_index:
            for i, index in enumerate(s_indexes[t_c]):
                if last_index < index:
                    s_pointer[t_c] = i
                    break
            else:
                # reset
                s_pointer = {c: 0 for c in "abcdefghijklmnopqrstuvwxyz"}
                power += 1

        last_index = s_indexes[t_c][s_pointer[t_c]]
        s_pointer[t_c] += 1

    print(len(s) * power + last_index + 1)


main()
Problem p02937 (Python) — buggy submission, verdict: Runtime Error

from collections import defaultdict
import bisect

S = input()
T = input()

d = defaultdict(list)
for i, s in enumerate(S, start=1):
    d[s].append(i)

ans = 0
i = 0

for t in T:
    if not d[t]:
        print(-1)
        exit()

    if i >= d[t][-1]:
        ans += len(S)
        i = d[t][0]
        continue

    pos = bisect.bisect_right(d[t], i)
    i = d[t][pos]

ans += i
print(ans)


Error: 0

Fixed submission:

from collections import defaultdict
import bisect

S = input()
T = input()

d = defaultdict(list)
for i, s in enumerate(S, start=1):
    d[s].append(i)

ans = 0
i = 0

for t in T:
    if not d[t]:
        print(-1)
        exit()

    if i > d[t][-1]:
        ans += len(S)
        i = 0
    pos = bisect.bisect_right(d[t], i)
    i = d[t][pos]

ans += i
print(ans)
Problem p02937 (Python) — buggy submission, verdict: Runtime Error

from bisect import bisect_left


def solve():
    S = input()
    T = input()
    if not set(T) <= set(S):
        return -1

    pos = {c: [] for c in "abcdefghijklmnopqrstuvwxyz"}
    for i, c in enumerate(S):
        pos[c].append(i)
    ans = 0
    cur_pos = 0
    for t in T:
        nxt_idx = bisect_left(pos[t], cur_pos)
        if nxt_idx == len(pos[t]):
            ans += len(S)
            cur_pos = 0
            nxt_idx = bisect_left(pos[t], cur_pos)
            cur_pos = pos[t][nxt_idx] + 1
        else:
            cur_pos = pos[t][nxt_idx] + 1

    return ans + cur_pos


print(solve())


Error: ValueError: invalid literal for int() with base 10: 'contest'
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02937/Python/s027416660.py", line 1, in <module>
    N, *A = map(int, open(0).read().split())
ValueError: invalid literal for int() with base 10: 'contest'


Fixed submission:

N, *A = map(int, open(0).read().split())

A = [0] + A
B = [0] * (N + 1)
sum_B = 0
for i in range(N, 0, -1):
    if sum(B[j] for j in range(i, N + 1, i)) % 2 != A[i]:
        B[i] = 1
        sum_B += 1
print(sum_B)
print(*[i for i, b in enumerate(B) if b])
Problem p02939 (Python) — buggy submission, verdict: Runtime Error

# https://atcoder.jp/contests/agc037/tasks/agc037_a

s = input()

ans = 0
pre = ""
cur = ""
for i in range(len(s)):
    pre += s[i]
    if pre != cur:
        ans += 1
        cur = pre
        pre = ""
print(ans)


Error: 0

Fixed submission:

# https://atcoder.jp/contests/agc037/tasks/agc037_a

s = input()

ans = 0
pre = s[0]
i = 0
while i < len(s):
    cur = s[i]
    if pre == cur:
        pre = s[i] + s[i + 1]
        i += 2
    else:
        pre = cur
        i += 1
    ans += 1
print(ans)
Problem p02939 (Python) — buggy submission, verdict: Time Limit Exceeded

s = input()

count = 0
j = 0
past_str = ""

for i in range(len(s)):
    now_str = s[j : i + 1]
    if now_str != past_str:
        count += 1
        j = i + 1
        past_str = now_str

print(count)


Error: TLE

Fixed submission:

from itertools import combinations

s = input()
n = len(s)
ap = list(range(1, n))

set_s = set()


def check(k):
    if k == 1:
        return True

    rtn = False
    for v in combinations(ap, k - 1):
        can = True
        x_past = 0
        w_past = ""

        for x in v:
            w = s[x_past:x]
            if w == w_past:
                can = False
                break
            x_past = x
            w_past = w
        w_last = s[v[-1] :]
        if w == w_last:
            can = False

        if can is True:
            rtn = True
            break

    return rtn


low = 1
high = n
while low <= high:
    mid = (low + high) // 2
    if check(mid):
        low = mid + 1
    else:
        high = mid - 1

print(min(high, low))
Problem p02939 (Python) — buggy submission, verdict: Runtime Error

from sys import stdin


def main():

    S = stdin.readline().rstrip()
    S_len = len(S)

    sum = 0
    s = S[0]
    x = 1

    while True:
        if len(s) == 1:
            if s == S[x]:
                s = s + S[x]
            else:
                sum += 1
                s = S[x]
        else:
            sum += 2
            x += 1

            if x >= S_len:
                break
            s = S[x]
        x += 1

        if x >= S_len:
            sum += 1
            break

    print(sum)


if __name__ == "__main__":
    main()


Error: 0

Fixed submission:

from sys import stdin


def main():

    S = stdin.readline().rstrip()
    S_len = len(S)

    sum = 0
    s = S[0]
    x = 1

    while True:
        if len(s) == 1:
            if s == S[x]:
                s = s + S[x]
            else:
                sum += 1
                s = S[x]
        else:
            sum += 2
            x += 1
            s = S[x]
        x += 1

        if x >= S_len:
            sum += 1
            break

    print(sum)


if __name__ == "__main__":
    main()