Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())

rev_stetus = False
for _ in range(Q):
    ipt = input().split()
    if ipt[0] == "1":
        rev_stetus = not rev_stetus
    else:
        f = int(ipt[1])
        c = ipt[2]
        if rev_stetus:
            S = S + c if f == 1 else c + S
        else:
            S = c + S if f == 1 else S + c

if rev_stetus:
    print("".join(reversed(S)))
else:
    print(S)

Fixed submission:
from collections import deque

S = deque(input())
Q = int(input())

rev_stetus = False
for _ in range(Q):
    ipt = input().split()
    if ipt[0] == "1":
        rev_stetus = not rev_stetus
    else:
        f = int(ipt[1])
        c = ipt[2]
        if rev_stetus:
            if f == 1:
                S.append(c)
            else:
                S.appendleft(c)
        else:
            if f == 1:
                S.appendleft(c)
            else:
                S.append(c)

if rev_stetus:
    S.reverse()
    print("".join(S))
else:
    print("".join(S))

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

for _ in range(Q):
    ipt = input().split()
    if ipt[0] == "1":
        S = "".join(reversed(S))
    else:
        f = int(ipt[1])
        c = ipt[2]
        if f == 1:
            S = c + S
        else:
            S += c

print(S)

Fixed submission:
from collections import deque

S = deque(input())
Q = int(input())

rev_stetus = False
for _ in range(Q):
    ipt = input().split()
    if ipt[0] == "1":
        rev_stetus = not rev_stetus
    else:
        f = int(ipt[1])
        c = ipt[2]
        if rev_stetus:
            if f == 1:
                S.append(c)
            else:
                S.appendleft(c)
        else:
            if f == 1:
                S.appendleft(c)
            else:
                S.append(c)

if rev_stetus:
    S.reverse()
    print("".join(S))
else:
    print("".join(S))
Buggy python submission (verdict: Time Limit Exceeded):
N, K = (int(nk) for nk in input().split())
P = [(int(p)+1)/2 for p in input().split()]

max_ev = 0
for i in range(N-K+1):
    max_ev = max(max_ev, sum(P[i:i+K]))

print(max_ev)


Fixed submission:
N, K = (int(nk) for nk in input().split())

curr_S = 0
count = 1
max_ev = 0
index = 0
has_eval_sk = False
zero_e = []
for p_str in input().split():
    e = (int(p_str)+1) / 2
    zero_e.append(e)
    if has_eval_sk:
        curr_S += e - zero_e[index]
        max_ev = max(max_ev, curr_S)
        index += 1
    else:
        curr_S += e
        if count == K:
            max_ev = curr_S
            has_eval_sk = True
        count += 1

print(max_ev)

Buggy python submission (verdict: Time Limit Exceeded):
def expected_value(p):
    return sum([n/p for n in range(1, p+1)])

N, K = (int(nk) for nk in input().split())
P = [expected_value(int(p)) for p in input().split()]

max_ev = 0
for i in range(N-K+1):
    max_ev = max(max_ev, sum(P[i:i+K]))

print(max_ev)


Fixed submission:
N, K = (int(nk) for nk in input().split())

curr_S = 0
count = 1
max_ev = 0
index = 0
has_eval_sk = False
zero_e = []
for p_str in input().split():
    e = (int(p_str)+1) / 2
    zero_e.append(e)
    if has_eval_sk:
        curr_S += e - zero_e[index]
        max_ev = max(max_ev, curr_S)
        index += 1
    else:
        curr_S += e
        if count == K:
            max_ev = curr_S
            has_eval_sk = True
        count += 1

print(max_ev)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
P = [int(p) for p in input().split()]
# 先頭は必ずカウント
count = 1
prev_index = N
for c in range(1, N):
    if P[c] == min(P[:c+1]):
        count += 1
print(count)

Fixed submission:
N = int(input())
count = 0
min_num = N
for c in input().split():
    p = int(c)
    min_num = min(min_num, p)
    if min_num == p:
        count += 1
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
P = [int(p) for p in input().split()]
# 先頭は必ずカウント
count = 1
for c in reversed(range(1, N)):
    min_num = min(P[:c])
    if min_num >= P[c]:
        count += 1
print(count)

Fixed submission:
N = int(input())
count = 0
min_num = N
for c in input().split():
    p = int(c)
    min_num = min(min_num, p)
    if min_num == p:
        count += 1
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
P = [int(p) for p in input().split()]
# 先頭は必ずカウント
count = 1
for c in range(1, N):
    is_clear = True
    for e in P[:c]:
        if P[c] > e:
            is_clear = False
            break
    if is_clear:
        count += 1
print(count)

Fixed submission:
N = int(input())
count = 0
min_num = N
for c in input().split():
    p = int(c)
    min_num = min(min_num, p)
    if min_num == p:
        count += 1
print(count)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()
ans = 0
for n in range(1000):
    num = "0"*(3-len(str(n))) + str(n)
    index = 0
    can_set = False
    for i in range(N):
        if S[i] == num[index]:
            if index == 2:
                can_set = True
                break
            index += 1
    if can_set:
        ans += 1
print(ans)

Fixed submission:
N = int(input())
S = input()
ans = 0
for n in range(1000):
    num = "0"*(3-len(str(n))) + str(n)
    index = 0
    can_set = False
    for i in range(N):
        if S[i] == num[index]:
            if index == 2:
                can_set = True
                break
            index += 1
    if can_set:
        ans += 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import itertools


N = int(input())
S = input()
A = set(itertools.combinations(S, 3))
print(len(A))

Fixed submission:
N = int(input())
S = input()
ans = 0
for n in range(1000):
    num = "0"*(3-len(str(n))) + str(n)
    index = 0
    can_set = False
    for i in range(N):
        if S[i] == num[index]:
            if index == 2:
                can_set = True
                break
            index += 1
    if can_set:
        ans += 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N, K ,Q = (int(nkq) for nkq in input().split())
A = []
score_list = [-1] + [K for _ in range(N)]
for _ in range(Q):
    A.append(int(input()))

for a in A:
    score_list = [-1] + [score_list[i]-1 if i != a else score_list[i] for i in range(1, N+1)]

for score in score_list[1:]:
    if score > 0:
        print("Yes")
    else:
        print("No")

Fixed submission:
N, K ,Q = (int(nkq) for nkq in input().split())
A = []
score_list = [-1] + [K-Q for _ in range(N)]
for _ in range(Q):
    A.append(int(input()))

for a in A:
    score_list[a] += 1

for score in score_list[1:]:
    if score > 0:
        print("Yes")
    else:
        print("No")
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
H = [-1] + [int(h) for h in input().split()]

max_count = 0
for n in range(1, N):
    count = 0
    for m in range(n, N):
        if H[m] >= H[m+1]:
            count += 1
        else:
            break
    max_count = max(max_count, count)

print(max_count)

Fixed submission:
N = int(input())
H = [-1] + [int(h) for h in input().split()]

count = 0
max_count = 0
for n in range(1, N):
    if H[n] >= H[n+1]:
        count += 1
        max_count = max(max_count, count)
    else:
        count = 0

print(max_count)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = []
for _ in range(N):
    A.append(int(input()))

for i in range(N):
    print(max(A[:i]+A[i+1:]))

Fixed submission:
N = int(input())
A = []
for _ in range(N):
    A.append(int(input()))

max_A = max(A)
semimax_A = max_A if A.count(max_A) > 1 else list(sorted(list(set(A))))[-2]
for i in range(N):
    if A[i] == max_A:
        print(semimax_A)
    else:
        print(max_A)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = []
for _ in range(N):
    A.append(int(input()))

for i in range(N):
    print(max(A[:i]+A[i+1:]))

Fixed submission:
N = int(input())
A = []
for _ in range(N):
    A.append(int(input()))

max_A = max(A)
semimax_A = max_A if A.count(max_A) > 1 else list(sorted(list(set(A))))[-2]
for i in range(N):
    if A[i] == max_A:
        print(semimax_A)
    else:
        print(max_A)
Buggy python submission (verdict: Runtime Error):
N, L = (int(nl) for nl in input().split())
tastes = [L+i-1 for i in range(1, N+1)]
min_taste = 0
min_taste_abs = 100
for taste in tastes:
    if min_taste_abs > abs(taste):
        min_taste_abs = abs(taste)
        min_taste = taste

min_taste_index = tastes.index(min_taste)
if len(tastes) == min_taste_index+1:
    print(sum(tastes[:min_taste_index]))
else:
    print(sum(tastes[:min_taste_index]+tastes[min_taste_index+1:]))

Fixed submission:
N, L = (int(nl) for nl in input().split())
tastes = [L+i-1 for i in range(1, N+1)]
min_taste = 100
min_taste_abs = 100
for taste in tastes:
    if min_taste_abs >= abs(taste):
        min_taste_abs = abs(taste)
        min_taste = taste

min_taste_index = tastes.index(min_taste)
if len(tastes) == min_taste_index+1:
    print(sum(tastes[:min_taste_index]))
else:
    print(sum(tastes[:min_taste_index]+tastes[min_taste_index+1:]))

Buggy python submission (verdict: Runtime Error):
N, L = (int(nl) for nl in input().split())
tastes = [L+i-1 for i in range(1, N+1)]
min_taste = 0
min_taste_abs = 100
for taste in tastes:
    if min_taste_abs > abs(taste):
        min_taste_abs = abs(taste)
        min_taste = taste
min_taste_index = tastes.index(min_taste)
print(sum(tastes[:min_taste_index]+tastes[min_taste_index+1:]))

Fixed submission:
N, L = (int(nl) for nl in input().split())
tastes = [L+i-1 for i in range(1, N+1)]
min_taste = 100
min_taste_abs = 100
for taste in tastes:
    if min_taste_abs >= abs(taste):
        min_taste_abs = abs(taste)
        min_taste = taste

min_taste_index = tastes.index(min_taste)
if len(tastes) == min_taste_index+1:
    print(sum(tastes[:min_taste_index]))
else:
    print(sum(tastes[:min_taste_index]+tastes[min_taste_index+1:]))

Buggy python submission (verdict: Runtime Error):
N, L = (int(nl) for nl in input().split())
tastes = [L+i-1 for i in range(1, N+1)]
min_taste = 0
min_taste_abs = 100
for taste in tastes:
    if min_taste_abs > abs(taste):
        min_taste_abs = abs(taste)
        min_taste = taste

min_taste_index = tastes.index(min_taste)
print(sum(tastes[:min_taste_index]+tastes[min_taste_index+1:]))

Fixed submission:
N, L = (int(nl) for nl in input().split())
tastes = [L+i-1 for i in range(1, N+1)]
min_taste = 100
min_taste_abs = 100
for taste in tastes:
    if min_taste_abs >= abs(taste):
        min_taste_abs = abs(taste)
        min_taste = taste

min_taste_index = tastes.index(min_taste)
if len(tastes) == min_taste_index+1:
    print(sum(tastes[:min_taste_index]))
else:
    print(sum(tastes[:min_taste_index]+tastes[min_taste_index+1:]))
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
H = [int(h) for h in input().split()]
dp = [0]*N
dp[1] = abs(H[1]-H[0])
for i in range(2, N):
    dp[i] = min([dp[i-j]+abs(H[i]-H[i-j]) for j in range(1, min(K, i)+1)])
print(dp[N-1])

Fixed submission:
N, K = map(int, input().split())
H = [int(h) for h in input().split()]
dp = [0]*N
dp[1] = abs(H[1]-H[0])
for i in range(2, N):
    dp[i] = min([dp[i-j]+abs(H[i]-H[i-j]) for j in range(1, min(K, i)+1)])
print(dp[N-1])

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
H = [int(h) for h in input().split()]
INF = 10**10
dp = [INF]*N
dp[0] = 0
dp[1] = abs(H[1]-H[0])
for i in range(2, N):
    dp[i] = min([dp[i-j]+abs(H[i]-H[i-j]) for j in range(1, min(K, i)+1)])
print(dp[N-1])

Fixed submission:
N, K = map(int, input().split())
H = [int(h) for h in input().split()]
dp = [0]*N
dp[1] = abs(H[1]-H[0])
for i in range(2, N):
    dp[i] = min([dp[i-j]+abs(H[i]-H[i-j]) for j in range(1, min(K, i)+1)])
print(dp[N-1])
Buggy python submission (verdict: Time Limit Exceeded):
def search(key, L):
    inc = -1
    exc = N
    while abs(inc-exc) > 1:
        mid = (inc+exc) // 2
        if True if L[mid] <= key else False:
            inc = mid
        else:
            exc = mid
    return exc


def main():
    ans = 0
    for a in A:
        for i in range(search(a, B), N):
            ans += N - search(B[i], C)
    print(ans)


if __name__ == "__main__":
    N = int(input())
    A = [int(a) for a in input().split()]
    B = sorted([int(b) for b in input().split()])
    C = sorted([int(c) for c in input().split()])
    main()


Fixed submission:
def search(key, L):
    inc = -1
    exc = N
    while abs(inc-exc) > 1:
        mid = (inc+exc) // 2
        if True if L[mid] <= key else False:
            inc = mid
        else:
            exc = mid
    return exc


def main():
    ans = 0
    for a in A:
        e = search(a, B)
        if e < N:
            ans += E[e]
    print(ans)


if __name__ == "__main__":
    N = int(input())
    A = [int(a) for a in input().split()]
    B = sorted([int(b) for b in input().split()])
    C = sorted([int(c) for c in input().split()])
    E = [0]*N
    for i in range(1, N+1):
        E[-i] = (N-search(B[N-i], C)) + E[-i+1]
    main()
Buggy python submission (verdict: Time Limit Exceeded):
N = 10**9


def f(x):
    return x


M = 10**5
arr = list(range(M))
for i in range(N):
    t = (i + i * i - i) % M  # 四則演算
    b = arr[t]  # 配列ランダムアクセス
    b = f(b)  # 関数呼び出し

# 答え
a = int(input())
print(a + a**2 + a**3)


Fixed submission:
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: map(int, read().split())
in_s = lambda: readline().rstrip().decode('utf-8')


def main():

    a = in_n()
    print(a + a**2 + a**3)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
N = 10**7


def f(x):
    return x


M = 10**5
arr = list(range(M))
for i in range(N):
    t = (i + i * i - i) % M  # 四則演算
    b = arr[t]  # 配列ランダムアクセス
    b = f(b)  # 関数呼び出し

# 答え
a = int(input())
print(a + a**2 + a**3)


Fixed submission:
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: map(int, read().split())
in_s = lambda: readline().rstrip().decode('utf-8')


def main():

    a = in_n()
    print(a + a**2 + a**3)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
N = 10**8
for i in range(N):
    b = 0

a = int(input())
print(a + a**2 + a**3)


Fixed submission:
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: map(int, read().split())
in_s = lambda: readline().rstrip().decode('utf-8')


def main():

    a = in_n()
    print(a + a**2 + a**3)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import defaultdict

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_na = lambda: map(int, read().split())
in_s = lambda: readline().rstrip().decode('utf-8')


def main():
    N = in_n()
    A = list(in_nn())
    Q = in_n()
    t = in_na()
    BC = list(zip(t, t))

    d = defaultdict(int)
    for i in range(N):
        d[A[i]] += 1

    for i in range(Q):
        b, c = BC[i]
        d[c] += d[b]
        d.pop(b)

        ans = 0
        for k, v in d.items():
            ans += k * v
        print(ans)


if __name__ == '__main__':
    main()


Fixed submission:
import sys
from collections import defaultdict

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_na = lambda: map(int, read().split())
in_s = lambda: readline().rstrip().decode('utf-8')


def main():
    N = in_n()
    A = list(in_nn())
    Q = in_n()
    t = in_na()
    BC = list(zip(t, t))

    d = defaultdict(int)
    for i in range(N):
        d[A[i]] += 1

    s = 0
    for k, v in d.items():
        s += k * v

    for i in range(Q):
        b, c = BC[i]
        s += d[b] * (c - b)
        d[c] += d[b]
        d.pop(b)

        print(s)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
s_readline = sys.stdin.readline


def solve():

    N, K = map(int, readline().split())
    A = list(map(int, readline().split()))

    #N, K = 2 * (10**5), 10000000
    #A = [0] * N

    for k in range(K):

        B = [0] * N
        for i in range(N):
            l = max(0, i - A[i])
            B[l] += 1
            r = i + A[i] + 1
            if r <= N - 1:
                B[r] += -1

        s = B[0]
        for i in range(N - 1):
            B[i + 1] += B[i]
            s += B[i + 1]

        A = B

        if s == N * N:
            print(' '.join(map(str, A)))
            exit()

    print(' '.join(map(str, A)))


if __name__ == '__main__':
    solve()


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


def solve():

    N, K = map(int, readline().split())
    A = list(map(int, readline().split()))

    #N, K = 2 * (10**5), 10000000
    #A = [0] * N

    for k in range(K):

        B = [0] * N
        for i in range(N):
            l = max(0, i - A[i])
            B[l] += 1
            r = i + A[i] + 1
            if r <= N - 1:
                B[r] += -1

        s = B[0]
        for i in range(N - 1):
            B[i + 1] += B[i]
            s += B[i + 1]

        A = B

        if s == N * N:
            print(' '.join(map(str, A)))
            exit()

    print(' '.join(map(str, A)))


if __name__ == '__main__':
    solve()
Buggy python submission (verdict: Runtime Error):
%%cython
cdef int solve(int a, int b):
    return a*b

def main():
    a, b = map(int, input())
    print(solve(a,b))

if __name__ == '__main__':
    main()

Fixed submission:
import sys

input = lambda: sys.stdin.readline().rstrip()


def solve():
    A, B = map(int, input().split())
    print(A * B)


if __name__ == '__main__':
    solve()

Buggy python submission (verdict: Runtime Error):
cdef int solve(int a, int b):
    return a*b

def main():
    a, b = map(int, input())
    print(solve(a,b))

if __name__ == '__main__':
    main()

Fixed submission:
import sys

input = lambda: sys.stdin.readline().rstrip()


def solve():
    A, B = map(int, input().split())
    print(A * B)


if __name__ == '__main__':
    solve()
Buggy python submission (verdict: Time Limit Exceeded):
import sys
import numpy as np


def solve(N, P):
    W = N + 2
    dp = np.zeros((W, W), np.int32)
    for _ in range(4):
        dp = dp.T[::-1]
        for n in range(1, (N + 1) // 2 + 1):
            dp[n, n:-n] = n
    filled = np.zeros_like(dp)
    filled[1:-1, 1:-1] = 1
    dp = dp.ravel()
    filled = filled.ravel()
    stack = np.empty_like(dp)
    ans = 0
    for n in P:
        n -= 1
        h, w = divmod(n, N)
        v = (h + 1) * W + (w + 1)
        ans += dp[v] - 1
        filled[v] = 0
        k = min(dp[v - 1], dp[v + 1], dp[v - W], dp[v + W])
        if dp[v] == k:
            return ans
        p = 0
        stack[0] = v
        dp[v] = k
        while p >= 0:
            v = stack[p]
            p -= 1
            for dx in (-1, 1, -W, W):
                w = v + dx
                k = dp[v] + filled[w]
                if dp[w] > k:
                    dp[w] = k
                    p += 1
                    stack[p] = w
    return ans


N = int(input())
P = np.array(input().split(), np.int32)

print(solve(N, P))


Fixed submission:
import sys
import numpy as np
from numba import njit


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


@njit
def solve(N, P):
    W = N + 2
    dp = np.zeros((W, W), np.int32)
    for _ in range(4):
        dp = dp.T[::-1]
        for n in range(1, (N + 1) // 2 + 1):
            dp[n, n:-n] = n
    filled = np.zeros_like(dp)
    filled[1:-1, 1:-1] = 1
    dp = dp.ravel()
    filled = filled.ravel()
    stack = np.empty_like(dp)
    ans = 0
    for n in P:
        n -= 1
        h, w = divmod(n, N)
        v = (h + 1) * W + (w + 1)
        ans += dp[v] - 1
        filled[v] = 0
        k = min(dp[v - 1], dp[v + 1], dp[v - W], dp[v + W])
        if dp[v] == k:
            return ans
        p = 0
        stack[0] = v
        dp[v] = k
        while p >= 0:
            v = stack[p]
            p -= 1
            for dx in (-1, 1, -W, W):
                w = v + dx
                k = dp[v] + filled[w]
                if dp[w] > k:
                    dp[w] = k
                    p += 1
                    stack[p] = w
    return ans


N = int(input())
P = np.array(input().split(), np.int32)

print(solve(N, P))
Buggy python submission (verdict: Runtime Error):
import numpy as np
import math

A, B, H, M = map(int, input().split())

time = H + (M / 60.0)
a_rot = (time / 12.0) * np.pi * 2
b_rot = (M / 60.0) * np.pi * 2

rot = a_rot - b_rot
if rot < 0:
    rot = b_rot - a_rot


ans = math.sqrt(A**2 + B**2 - (2 * A * B * np.cos(rot)))

print(ans)


Fixed submission:
import numpy as np
import math

A, B, H, M = map(int, input().split())

time = H + (M / 60.0)
a_rot = (time / 12.0) * np.pi * 2
b_rot = (M / 60.0) * np.pi * 2

rot = a_rot - b_rot
if rot < 0:
    rot = b_rot - a_rot


ans = math.sqrt(A**2 + B**2 - (2 * A * B * np.cos(rot)))

print(ans)