Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
n, x = map(int, input().split())
l = list(map(int, input().split()))

d = 0
count = 0
i = 1
while d <= x:
    d = d + l[i - 1]
    count += 1
    if i <= n - 1
        i += 1

print(count)

Fixed submission:
import itertools
import math
n, x = map(int, input().split())
l = list(map(int, input().split()))

d = 0
count = 0
i = 1
while d <= x and i <= n:
    d = d + l[i - 1]
    count += 1
    i += 1
if d <= x:
    count += 1

print(count)

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

d = 0
count = 0
i = 1
while d <= x:
    d = d + l[i - 1]
    count += 1
    i += 1

print(count)

Fixed submission:
import itertools
import math
n, x = map(int, input().split())
l = list(map(int, input().split()))

d = 0
count = 0
i = 1
while d <= x and i <= n:
    d = d + l[i - 1]
    count += 1
    i += 1
if d <= x:
    count += 1

print(count)

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

d = 0
count = 0
i = 2
while d <= x:
    d = d + l[i - 2]
    count += 1
    i += 1

print(count)

Fixed submission:
import itertools
import math
n, x = map(int, input().split())
l = list(map(int, input().split()))

d = 0
count = 0
i = 1
while d <= x and i <= n:
    d = d + l[i - 1]
    count += 1
    i += 1
if d <= x:
    count += 1

print(count)
Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
a = []
for _ in range(m):
    a.append(int(input()))

dp = [0] * (n+5)
dp[0] = 1
for i in range(n):
    dp[i] %= 1000000007
    if i+1 not in a:
        dp[i+1] += dp[i]
    if i+2 not in a:
        dp[i+2] += dp[i]
print(dp[n] % 1000000007)

Fixed submission:
n, m = map(int, input().split())
a = set()
for _ in range(m):
    a.add(int(input()))

dp = [0] * (n+5)
dp[0] = 1
for i in range(n):
    dp[i] %= 1000000007
    if i+1 not in a:
        dp[i+1] += dp[i]
    if i+2 not in a:
        dp[i+2] += dp[i]
print(dp[n] % 1000000007)
Buggy python submission (verdict: Time Limit Exceeded):
import itertools
import math
import fractions
import functools
import copy
n, m = map(int, input().split())
lr = []
for i in range(m):
    l, r = map(int, input().split())
    lr.append([l,r])

result = list(range(lr[0][0],lr[0][1]+1))

for i in range(len(result)):
    for pair in lr:
        if not(pair[0] <= result[i] and pair[1] >= result[i]):
            result[i] = -1

print(len(result)-result.count(-1))



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

lr = []
for i in range(m):
    l = list(map(int, input().split()))
    lr.append(l)

count = 0
minimum = 0
maxmum = 10**9
for i in range(m):
    minimum = max(minimum, lr[i][0])
    maxmum = min(maxmum, lr[i][1])

if(maxmum >= minimum):
    print(maxmum - minimum + 1)
else:
    print(0)
Buggy python submission (verdict: Runtime Error):
b = input()
if b ='A': print('T')
if b = 'T': print('A')
if b = 'C': print('G')
if b = 'G': print('C')

Fixed submission:
b = input()
if b =='A': print('T')
if b == 'T': print('A')
if b == 'C': print('G')
if b == 'G': print('C')
Buggy python submission (verdict: Runtime Error):
s = input()
temp = []
count = 0
for i in range(len(s)):
    if s[i] == 'A' or s[i] == 'C' or s[i] == 'G' or s[i] == 'T':
        count += 1
    else:
        temp.append(count)
        count = 0
print(max(temp))

Fixed submission:
s = input()
temp = []
maximum = 0
count =0
for i in range(len(s)):
    if s[i] == 'A' or s[i] == 'C' or s[i] == 'G' or s[i] == 'T':
            count +=1
            maximum = max(maximum,count)
    else:
        count = 0

print(maximum)
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    # n = int(input())
    n, q = map(int, input().split())
    # a = list(map(int, input().split()))
    s = input()
    # h = [int(input()) for _ in rane(n)]
    lr = []
    for i in range(q):
        l, r = list(map(int, input().split()))
        lr.append([l-1, r-1])

    count = [0] * (10 ** 6)
    for i in range(1, n):
        if s[i-1] == "A" and s[i] == "C":
            count[i] = 1

    for i in range(q):
        print(sum(count[lr[i][0]+1:lr[i][1]+1]))


if __name__ == '__main__':
    main()


Fixed submission:
import itertools
import math

n, q = map(int, input().split())
s = input()
lr = []
for i in range(q):
    li , ri = list(map(int, input().split()))
    lr.append([li-1,ri-1])

his = [0]*n
count = 0
for i in range(1,n):
    if s[i-1] == 'A' and s[i] == 'C':
        count += 1
        his[i] = count
    else:
        his[i] = his[i-1]

for i in range(q):
    print(his[lr[i][1]] - his[lr[i][0]])
Buggy python submission (verdict: Time Limit Exceeded):
import itertools
import math
import fractions
import functools
import copy

n, k = map(int, input().split())
h = []
for i in range(n):
    h.append(int(input()))

h.sort()
minimum = 10**10
for i in range(n-k+1):
    minimum = min(minimum,max(h[i:i+k])-min(h[i:i+k]))

print(minimum)

Fixed submission:
import itertools
import math
import fractions
import functools
n, k = map(int, input().split())
h = []
for i in range(n):
    h.append(int(input()))

h.sort()
subs = []
for i in range(1,n):
    subs.append(h[i]-h[i-1])

amount = [0]*(n)
sums = 0
for i in range(0,len(subs)):
    sums += subs[i]
    amount[i+1] = sums


minimum = 10**10
for i in range(k-1,n):
    minimum = min(minimum,amount[i]-amount[i-k+1])

print(minimum)

Buggy python submission (verdict: Time Limit Exceeded):
import itertools
import math
import fractions
import functools
n, k = map(int, input().split())
h = []
for i in range(n):
    h.append(int(input()))

h.sort()
subs = []
for i in range(1,n):
    subs.append(h[i]-h[i-1])

minimum = 10**10
for i in range(len(subs)-1):
    minimum = min(minimum,sum(subs[i:k+i-1]))


print(minimum)


Fixed submission:
import itertools
import math
import fractions
import functools
n, k = map(int, input().split())
h = []
for i in range(n):
    h.append(int(input()))

h.sort()
subs = []
for i in range(1,n):
    subs.append(h[i]-h[i-1])

amount = [0]*(n)
sums = 0
for i in range(0,len(subs)):
    sums += subs[i]
    amount[i+1] = sums


minimum = 10**10
for i in range(k-1,n):
    minimum = min(minimum,amount[i]-amount[i-k+1])

print(minimum)

Buggy python submission (verdict: Time Limit Exceeded):
import itertools
import math
import fractions
import functools
n, k = map(int, input().split())
h = []
for i in range(n):
    h.append(int(input()))

h.sort()
subs = []
for i in range(1,n):
    subs.append(h[i]-h[i-1])


sums = []

for i in range(len(subs)-1):
    sums.append(sum(subs[i:k+i-1]))


print(min(sums))


Fixed submission:
import itertools
import math
import fractions
import functools
n, k = map(int, input().split())
h = []
for i in range(n):
    h.append(int(input()))

h.sort()
subs = []
for i in range(1,n):
    subs.append(h[i]-h[i-1])

amount = [0]*(n)
sums = 0
for i in range(0,len(subs)):
    sums += subs[i]
    amount[i+1] = sums


minimum = 10**10
for i in range(k-1,n):
    minimum = min(minimum,amount[i]-amount[i-k+1])

print(minimum)
Buggy python submission (verdict: Runtime Error):
def main():
    n = int(input())
    # n, k = map(int, input().split())
    v = list(map(int, input().split()))
    # s = input()

    even = [0] * (10 ** 5)
    odd = [0] * (10 ** 5)

    for i in range(n):
        if i % 2 == 0:
            even[v[i]] += 1
        else:
            odd[v[i]] += 1

    max_even = even.index(max(even))
    max_odd = odd.index(max(odd))

    if max_even == max_odd:
        even[max_even] = 0
        odd[max_odd] = 0
        if max(even) < max(odd):
            max_odd = odd.index(max(odd))
        else:
            max_even = even.index(max(even))
    ans = 0
    for i in range(n):
        if i % 2 == 0 and max_even != v[i]:
            ans += 1
        if i % 2 != 0 and max_odd != v[i]:
            ans += 1

    print(ans)


if __name__ == '__main__':
    main()


Fixed submission:
import itertools
import math
import fractions
import functools
l = [0]*(10**5+10)
r = [0]*(10**5+10)

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

for i in range(n):
    if i % 2 == 0:
        l[v[i]] += 1
    else:
        r[v[i]] += 1

max_l = l.index(max(l))
max_r = r.index(max(r))
count = 0

if max_l == max_r:
    for i in range(len(r)):
        if r[i] == r[max_r]:
            r[i] = 0
        if l[i] == l[max_l]:
            l[i] = 0
if max(l) > max(r):
    max_l = l.index(max(l))
else:
    max_r = r.index(max(r))

for i in range(n):
    if i % 2 == 0 and v[i] != max_l:
        count += 1
    if i % 2 != 0 and v[i] != max_r:
        count += 1
print(count)

Buggy python submission (verdict: Runtime Error):
def main():
    n = int(input())
    # n, k = map(int, input().split())
    v = list(map(int, input().split()))
    # s = input()

    even = [0] * (10 ** 5)
    odd = [0] * (10 ** 5)

    for i in range(n):
        if i % 2 == 0:
            even[v[i]] += 1
        else:
            odd[v[i]] += 1

    max_even = even.index(max(even))
    max_odd = odd.index(max(odd))

    ans = 0
    if max_even != max_odd:
        ans = n - even[max_even] - odd[max_odd]
    else:
        temp_even = even[max_even]
        temp_odd = odd[max_odd]
        even[max_even] = 0
        odd[max_odd] = 0
        max_even2 = even.index(max(even))
        max_odd2 = odd.index(max(odd))
        if even[max_even2] > odd[max_odd2]:
            ans = n - even[max_even2] - temp_odd
        else:
            ans = n - temp_even - odd[max_odd2]

    print(ans)


if __name__ == '__main__':
    main()


Fixed submission:
import itertools
import math
import fractions
import functools
l = [0]*(10**5+10)
r = [0]*(10**5+10)

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

for i in range(n):
    if i % 2 == 0:
        l[v[i]] += 1
    else:
        r[v[i]] += 1

max_l = l.index(max(l))
max_r = r.index(max(r))
count = 0

if max_l == max_r:
    for i in range(len(r)):
        if r[i] == r[max_r]:
            r[i] = 0
        if l[i] == l[max_l]:
            l[i] = 0
if max(l) > max(r):
    max_l = l.index(max(l))
else:
    max_r = r.index(max(r))

for i in range(n):
    if i % 2 == 0 and v[i] != max_l:
        count += 1
    if i % 2 != 0 and v[i] != max_r:
        count += 1
print(count)
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int,input().split())
a_list = list(map(int,input().split()))

dp = [1] * (n-k+1)

for i in range(0,k):
    dp[0] = dp[0] * a_list[i]

for j in range(1, n-k+1):
    dp[j] = dp[j-1] * a_list[k+j-1] / a_list[j-1]

for l in range(len(dp)-1):
    if dp[l] < dp[l+1]:
        print('Yes')
    else:
        print('No')

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

for i in range(0, n-k):
    if a_list[i] < a_list[k+i]:
        print('Yes')
    else:
        print('No')
Buggy python submission (verdict: Runtime Error):
n,m,k = map(int,input().split())
a_list = list(map(int,input().split()))
b_list = list(map(int,input().split()))

from itertools import accumulate
sum_a_list = list(accumulate([0] + a_list))
sum_b_list = list(accumulate([0] + b_list))

ans = 0
b_idx = 0
for a_idx in range(n+1):
    if sum_a_list[a_idx] > k:
        continue

    time_rest = k - sum_a_list[a_idx]
    b_idx = bisect.bisect_left(sum_b_list,time_rest)
    
    ans = max(ans, a_idx + b_idx)
        
print(ans)

Fixed submission:
n,m,k = map(int,input().split())
a_list = list(map(int,input().split()))
b_list = list(map(int,input().split()))

from itertools import accumulate
sum_a_list = list(accumulate([0] + a_list))
sum_b_list = list(accumulate([0] + b_list))

ans = 0
b_idx = m
for a_idx in range(n+1):
    if sum_a_list[a_idx] > k:
        continue
 
    while sum_a_list[a_idx] + sum_b_list[b_idx] > k:
        b_idx -= 1
    
    ans = max(ans, a_idx + b_idx)
        
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

def calc(b, e):
    # 等差数列の和
    cnt = e // b
    ans_tmp = (b + e) * cnt // 2
    return ans_tmp

ans = 0

for i in range(1, n+1):
    ans += calc(i, n//i * i)

print(ans)

Fixed submission:
n=int(input())

ans_tmp = sum(range(n+1)) * 2 -1

from itertools import accumulate
sum_list = list(accumulate(range(1, n)))

ans_tmp_2 = 0

for i in range(2, n+1//2+1):
    if n // i > 1:
        count_tmp = n // i
        ans_tmp_2 += i * sum_list[count_tmp - 1] - i

print(ans_tmp + ans_tmp_2)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

def calc(b, e):
    # 等差数列の和
    cnt = e // b
    return (b + e) * cnt // 2

ans = 0

for i in range(1, n+1):
    ans += calc(i, n//i * i)

print(ans)

Fixed submission:
n=int(input())

ans_tmp = sum(range(n+1)) * 2 -1

from itertools import accumulate
sum_list = list(accumulate(range(1, n)))

ans_tmp_2 = 0

for i in range(2, n+1//2+1):
    if n // i > 1:
        count_tmp = n // i
        ans_tmp_2 += i * sum_list[count_tmp - 1] - i

print(ans_tmp + ans_tmp_2)
Buggy python submission (verdict: Runtime Error):
x,n = map(int,input().split())

p_list = list(map(int,input().split()))
p_list = sorted(p_list)

import sys
if n == 0:
    print(x)
    sys.exit()

sa_min = 1000000
for i in range(1, 101):
    if i not in p_list:
        if sa_min > abs(i - x):
            sa_min = abs(i - x)
            ans = i
print(ans)

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

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

import sys
if n == 0:
    print(x)
else:
    sa_min = 1000000
    for i in range(-110, 210):
        if i not in p_list:
            if sa_min > abs(i - x):
                sa_min = abs(i - x)
                ans = i
    print(ans)

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

import sys
if n == 0:
    print(x)
    sys.exit()

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

sa_min = 1000000
for i in range(1, 101):
    if i not in p_list:
        if sa_min > abs(i - x):
            sa_min = abs(i - x)
            ans = i
print(ans)

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

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

import sys
if n == 0:
    print(x)
else:
    sa_min = 1000000
    for i in range(-110, 210):
        if i not in p_list:
            if sa_min > abs(i - x):
                sa_min = abs(i - x)
                ans = i
    print(ans)
Buggy python submission (verdict: Runtime Error):
# solution
k=int(input())

from collections import deque
todo = deque([i for i in range(1, 10)])
count = 0

while len(todo) > 0:
    value = todo.popleft()
    seen.append(value)
    value_digit1 = value % 10
    count += 1
    if count == k:
        print(value)
        break
    if value_digit1==0:
        todo.append(10*value)
        todo.append(10*value+1)
    elif value_digit1==9:
        todo.append(10*value+8)
        todo.append(10*value+9)
    else:
        todo.append(10*value+value_digit1-1)
        todo.append(10*value+value_digit1)
        todo.append(10*value+value_digit1+1)

Fixed submission:
# solution
k=int(input())

from collections import deque
todo = deque([i for i in range(1, 10)])
count = 0

while len(todo) > 0:
    value = todo.popleft()
    value_digit1 = value % 10
    count += 1
    if count == k:
        print(value)
        break
    if value_digit1==0:
        todo.append(10*value)
        todo.append(10*value+1)
    elif value_digit1==9:
        todo.append(10*value+8)
        todo.append(10*value+9)
    else:
        todo.append(10*value+value_digit1-1)
        todo.append(10*value+value_digit1)
        todo.append(10*value+value_digit1+1)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a_list = list(map(int,input().split()))

import collections
c = collections.Counter(a_list)

dict_items = list(c.items())

for i in range(n): # kごと
    ans_i = 0
    for j in range(len(dict_items)):
        if a_list[i] == dict_items[j][0]:
            ans_i += ((dict_items[j][1] - 1) * (dict_items[j][1] - 2)) / 2
        else:
            ans_i += ((dict_items[j][1] - 0) * (dict_items[j][1] - 1)) / 2
    print(int(ans_i))

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

import collections
c = collections.Counter(a_list)

dict_items = list(c.items())

ans_max = 0
for j in range(len(dict_items)):
    ans_max += ((dict_items[j][1] - 0) * (dict_items[j][1] - 1)) / 2
    
for i in range(n): # kごと
    tmp = c[a_list[i]]
    ans_tmp = ans_max - tmp*(tmp-1)/2 + (tmp-1)*(tmp-2)/2
    print(int(ans_tmp))
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q=int(input())

count = 1
for i in range(q):
#     print(s)
    q_y_i = input().split()
#     print(q_y_i)
#     print(count)
    if q_y_i[0] == '1':
        count +=1
    else:
        if count % 2 == 1:
            if q_y_i[1] == '1':
                s = q_y_i[2] + s
#                 print('p1')
            elif q_y_i[1] == '2':
                s = s + q_y_i[2]
#                 print('p2')
        elif count % 2 == 0:
            if q_y_i[1] == '1':
                s = s + q_y_i[2]
#                 print('p3')
            elif q_y_i[1] == '2':
                s = q_y_i[2] + s
#                 print('p4')

if count % 2 == 0:
    print(s[::-1])
else:
    print(s)

Fixed submission:
s = input()
q=int(input())

from collections import deque
d = deque()
d.append(s)

count = 1
for i in range(q):
#     print(s)
    q_y_i = input().split()
#     print(q_y_i)
#     print(count)
#     print(d)
    if q_y_i[0] == '1':
        count +=1
    else:
        if count % 2 == 1:
            if q_y_i[1] == '1':
                d.appendleft(q_y_i[2])
#                 print('p1')
#                 print(d)
            elif q_y_i[1] == '2':
                d.append(q_y_i[2])
#                 print('p2')
        elif count % 2 == 0:
            if q_y_i[1] == '1':
                d.append(q_y_i[2])
#                 print('p3')
            elif q_y_i[1] == '2':
                d.appendleft(q_y_i[2])
#                 print('p4')

ans = ''
for v in d:
    ans = ans + v
if count % 2 == 0:
    print(ans[::-1])
else:
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q=int(input())

for i in range(q):
#     print(s)
    q_y_i = input().split()
#     print(q_y_i)
    if q_y_i[0] == '1':
        s = s[::-1]
    elif q_y_i[0] == '2':
        if q_y_i[1] == '1':
            s = q_y_i[2] + s
        elif q_y_i[1] == '2':
            s = s + q_y_i[2]
            
print(s)

Fixed submission:
s = input()
q=int(input())

from collections import deque
d = deque()
d.append(s)

count = 1
for i in range(q):
#     print(s)
    q_y_i = input().split()
#     print(q_y_i)
#     print(count)
#     print(d)
    if q_y_i[0] == '1':
        count +=1
    else:
        if count % 2 == 1:
            if q_y_i[1] == '1':
                d.appendleft(q_y_i[2])
#                 print('p1')
#                 print(d)
            elif q_y_i[1] == '2':
                d.append(q_y_i[2])
#                 print('p2')
        elif count % 2 == 0:
            if q_y_i[1] == '1':
                d.append(q_y_i[2])
#                 print('p3')
            elif q_y_i[1] == '2':
                d.appendleft(q_y_i[2])
#                 print('p4')

ans = ''
for v in d:
    ans = ans + v
if count % 2 == 0:
    print(ans[::-1])
else:
    print(ans)
Buggy python submission (verdict: Runtime Error):
n,a,b = map(int,input().split())

class ModComb:
    def __init__(self, MAX, mod=10 ** 9 + 7):
        fac = [1, 1]
        finv = [1, 1]
        inv = [0, 1]
        for i in range(2, MAX):
            fac.append(fac[i - 1] * i % mod)
            inv.append(mod - inv[mod % i] * (mod // i) % mod)
            finv.append(finv[i - 1] * inv[i] % mod)
        self.fac, self.finv, self.mod = fac, finv, mod

    def nCk(self, n, k):
        if n < k or n < 0 or k < 0:
            return 0
        fac, finv, mod = self.fac, self.finv, self.mod
        return fac[n] * (finv[k] * finv[n - k] % mod) % mod


mod = 10 ** 9 + 7
mc = ModComb(1000000, mod=mod) 

minus = (mc.nCk(n, a) % mod) + (mc.nCk(n, b) % mod)

print(((2 ** (n) - 1) - minus) % mod)

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

MOD=10**9+7
def comb(n,k):
    if n<k:
        return 0
    if n<0 or k<0:
        return 0
    k=min(n-k,k)
    ans=1
    inv=[1]*(k+1)
    if k>=1:
        ans*=(n-k+1)%MOD
    for i in range(2,k+1):
        inv[i]=MOD-inv[MOD%i]*(MOD//i)%MOD
        ans=ans*(n-k+i)*inv[i]%MOD
    return ans

nCa = comb(n,a)
nCb = comb(n,b)

ans = (pow(2,n,MOD) - 1) - nCa - nCb
 
if ans < 0:
    print((ans+MOD)%MOD)
else:
    print(ans%MOD)

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

class ModComb:
    def __init__(self, MAX, mod=10 ** 9 + 7):
        fac = [1, 1]
        finv = [1, 1]
        inv = [0, 1]
        for i in range(2, MAX):
            fac.append(fac[i - 1] * i % mod)
            inv.append(mod - inv[mod % i] * (mod // i) % mod)
            finv.append(finv[i - 1] * inv[i] % mod)
        self.fac, self.finv, self.mod = fac, finv, mod

    def nCk(self, n, k):
        if n < k or n < 0 or k < 0:
            return 0
        fac, finv, mod = self.fac, self.finv, self.mod
        return fac[n] * (finv[k] * finv[n - k] % mod) % mod


mod = 10 ** 9 + 7
mc = ModComb(1000000, mod=mod) 

minus = (mc.nCk(n, a) % mod) + (mc.nCk(n, b) % mod)

print((2 ** (n) - 1) - minus)

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

MOD=10**9+7
def comb(n,k):
    if n<k:
        return 0
    if n<0 or k<0:
        return 0
    k=min(n-k,k)
    ans=1
    inv=[1]*(k+1)
    if k>=1:
        ans*=(n-k+1)%MOD
    for i in range(2,k+1):
        inv[i]=MOD-inv[MOD%i]*(MOD//i)%MOD
        ans=ans*(n-k+i)*inv[i]%MOD
    return ans

nCa = comb(n,a)
nCb = comb(n,b)

ans = (pow(2,n,MOD) - 1) - nCa - nCb
 
if ans < 0:
    print((ans+MOD)%MOD)
else:
    print(ans%MOD)
Buggy python submission (verdict: Runtime Error):
n=int(input())

def count_attack(hp):
    count = 0
    if hp == 2 or hp == 3:
        return 3
    else:
        # calculate new hp
        count += 1
        hp_child = hp //2
        count += 2 * count_attack(hp_child)
        return count

print(count_attack(n))

Fixed submission:
n=int(input())

def count_attack(hp):
    count = 0        
    if hp == 2 or hp == 3:
        return 3
    else:
        # calculate new hp
        count += 1
        hp_child = hp //2
        count += 2 * count_attack(hp_child)
        return count

if n == 1:
    print(1)
else:
    print(count_attack(n))
Buggy python submission (verdict: Time Limit Exceeded):
x,y = map(int,input().split())

def comb(n,k,p):
  """power_funcを用いて(nCk) mod p を求める"""
  from math import factorial
  if n<0 or k<0 or n<k: return 0
  if n==0 or k==0: return 1
  a=factorial(n) %p
  b=factorial(k) %p
  c=factorial(n-k) %p
  return (a*power_func(b,p-2,p)*power_func(c,p-2,p))%p
def power_func(a,b,p):
  """a^b mod p を求める"""
  if b==0: return 1
  if b%2==0:
    d=power_func(a,b//2,p)
    return d*d %p
  if b%2==1:
    return (a*power_func(a,b-1,p ))%p

if (x+y)%3!=0:
    print(0)
else:
    a = (2*x - y) // 3
    b = (2*y - x) // 3

    print(comb(a+b, a, 10**9+7))

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

class ModComb:
    def __init__(self, MAX, mod=10 ** 9 + 7):
        fac = [1, 1]
        finv = [1, 1]
        inv = [0, 1]
        for i in range(2, MAX):
            fac.append(fac[i - 1] * i % mod)
            inv.append(mod - inv[mod % i] * (mod // i) % mod)
            finv.append(finv[i - 1] * inv[i] % mod)
        self.fac, self.finv, self.mod = fac, finv, mod
 
    def nCk(self, n, k):
        if n < k or n < 0 or k < 0:
            return 0
        fac, finv, mod = self.fac, self.finv, self.mod
        return fac[n] * (finv[k] * finv[n - k] % mod) % mod

if (x+y)%3!=0:
    print(0)
else:
    a = (2*x - y) // 3
    b = (2*y - x) // 3

    mod = 10 ** 9 + 7
    mc = ModComb(1000000, mod=mod) 

    print(mc.nCk(a + b, a) % mod)
Buggy python submission (verdict: Runtime Error):
n=int(input())
a_list = list(map(int,input().split()))
ans_list = []
for i in range(n):
    ans_list.append(a_list.index(i+1) + 1)
print(*ans_list)

Fixed submission:
n=int(input())
if n % 2 == 0:
    print(0.5)
else:
    print((n+1)/2/n)