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


def calculate(n, s):
    arr = list(s)
    result = []


    for i in range(n):
        left = arr[:i]
        right = arr[i + 1:]
        res = max(left.count('W'),right.count('R'))
        result.append(res)

    if len(result) == 0:
        print(-1)
    else:
        print(min(result))

calculate(N, S)


Fixed submission:
# N = 8
# S = "WRWWRWRR"
#
# N = 2
# S = "RR"
#
# N = 3
# S = "WWW"

N = int(input())
S = input()

def calculate(n, s):
    arr = list(s)

    wNum = arr.count("W")
    RNum = arr.count("R")

    if wNum == 0 or RNum == 0:
        print(0)
        return

    leftW = 0
    rightR = RNum



    result = []
    for i in range(n):
        if arr[i] == "R":
            rightR -= 1
        if arr[i] == "W":
            leftW += 1

        result.append(max(leftW, rightR))

    print(min(result))


calculate(N, S)

Buggy python submission (verdict: Runtime Error):
def calculate(n, s):
    arr = list(S)

    RNum = arr.count("R")

    leftW = 0
    rightR = RNum

    result = []
    for i in range(n):
        if arr[i] == "R":
            rightR -= 1
        if arr[i] == "W":
            leftW += 1

        result.append(max(leftW, rightR))

    print(min(result))


calculate(N, S)


Fixed submission:
# N = 8
# S = "WRWWRWRR"
#
# N = 2
# S = "RR"
#
# N = 3
# S = "WWW"

N = int(input())
S = input()

def calculate(n, s):
    arr = list(s)

    wNum = arr.count("W")
    RNum = arr.count("R")

    if wNum == 0 or RNum == 0:
        print(0)
        return

    leftW = 0
    rightR = RNum



    result = []
    for i in range(n):
        if arr[i] == "R":
            rightR -= 1
        if arr[i] == "W":
            leftW += 1

        result.append(max(leftW, rightR))

    print(min(result))


calculate(N, S)
Buggy python submission (verdict: Runtime Error):
N = 2
ARR = [157, 193]

N = 6
ARR = [200, 180, 160, 140, 120, 100]

N = 7
ARR = [100, 130, 130, 130, 115, 115, 150]

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


# N = 5
# ARR = [157, 193, 193, 193, 191]

def prepare(n, arr):
    result = []
    for i in range(n):
        if i == 0:
            result.append(arr[0])
        else:
            if arr[i] != arr[i - 1]:
                result.append(arr[i])
    return result


def calculate(arr):
    n = len(arr)
    result = []
    for i in range(n):
        if i == n-1:
            if arr[i] > arr[i-1]:
                result.append({'type': 1, 'value': arr[i]})
            if arr[i] < arr[i-1]:
                result.append({'type': 0, 'value': arr[i]})
            continue

        if arr[i + 1] > arr[i]:
            result.append({'type': 0, 'value': arr[i]})
        if arr[i+1] < arr[i]:
            result.append({'type': 1, 'value': arr[i]})

    money = 1000
    num = 0
    history = []
    for res in result:
        type = res.get('type')
        value = res.get('value')
        if type == 0:
            num += money // value
            money -= num * value
        else:
            money += num * value
            history.append(money)
            num = 0

    print(max(history))

# arr = prepare(N, ARR)
calculate(ARR)


Fixed submission:
N = 2
ARR = [157, 193]

N = 6
ARR = [200, 180, 160, 140, 120, 100]

N = 7
ARR = [100, 130, 130, 130, 115, 115, 150]

N = int(input())
ARR = list(map(int, input().split()))
#

# N = 5
# ARR = [111, 111, 111, 111, 111]

def prepare(n,arr):
    result = []
    for i in range(n):
        if i == 0:
            result.append(arr[0])
        else:
            if arr[i] != arr[i-1]:
                result.append(arr[i])
    return result


def calculate(arr):
    n = len(arr)
    result = []
    for i in range(n):
        if i == n-1:
            if arr[i] > arr[i-1]:
                result.append({'type': 1, 'value': arr[i]})
            continue

        if i == 0:
            if arr[1] > arr[0]:
                result.append({'type': 0, 'value': arr[i]})
            continue

        if (arr[i + 1] > arr[i]) and (arr[i] < arr[i - 1]):
            result.append({'type': 0, 'value': arr[i]})

        if (arr[i + 1] < arr[i]) and (arr[i] > arr[i - 1]):
            result.append({'type': 1, 'value': arr[i]})

    money = 1000
    num = 0
    for index,res in enumerate(result):
        type = res.get('type')
        value = res.get('value')

        if index == (len(result) - 1):
            if value == 1:
                continue

        if type == 0:
            tmpNum = money // value
            num += tmpNum
            money -= value * tmpNum
        else:
            money += num * value
            num = 0

    print(money)


arr = prepare(N, ARR)
calculate(arr)
Buggy python submission (verdict: Runtime Error):
import itertools
import numpy as np

H, W, K = 2, 3, 4
ARR = [
    "..#",
    "###",
]
#
# H, W, K = 6, 6, 8
# ARR = [
#     "..##..",
#     ".#..#.",
#     "#....#",
#     "######",
#     "#....#",
#     "#....#"
# ]

H, W, K = map(int, input().split())
ARR2 = np.zeros((H, W))
for i in range(H):
    s = list(input())
    for j in range(W):
        if ARR[i][j] == ".":
            ARR2[i][j] == 0
        else:
            ARR2[i][j] = 1

# ARR2 = np.zeros((H, W))
# for i in range(H):
#     for j in range(W):
#         if ARR[i][j] == ".":
#             ARR2[i][j] == 0
#         else:
#             ARR2[i][j] = 1


def calclulate(h, w, k, arr):
    result = 0
    hIndex = [i for i in range(h)]
    wIndex = [i for i in range(w)]

    for hChooseNum in range(h + 1):
        for wChooseNum in range(w + 1):
            for m in itertools.combinations(hIndex, hChooseNum):
                for n in itertools.combinations(wIndex, wChooseNum):

                    tmpArr = arr.copy()

                    for _m in m:
                        tmpArr[_m, :] = 0
                    for _n in n:
                        tmpArr[:, _n] = 0

                    if np.sum(tmpArr == 1) == k:
                        result += 1
    print(result)


calclulate(H, W, K, ARR2)


Fixed submission:
import itertools
import numpy as np

# H, W, K = 2, 3, 4
# ARR = [
#     "..#",
#     "###",
# ]
#
# H, W, K = 6, 6, 8
# ARR = [
#     "..##..",
#     ".#..#.",
#     "#....#",
#     "######",
#     "#....#",
#     "#....#"
# ]

H, W, K = map(int, input().split())
ARR2 = np.zeros((H, W))
for i in range(H):
    s = list(input())
    for j in range(W):
        if s[j] == ".":
            ARR2[i][j] == 0
        else:
            ARR2[i][j] = 1

# ARR2 = np.zeros((H, W))
# for i in range(H):
#     for j in range(W):
#         if ARR[i][j] == ".":
#             ARR2[i][j] == 0
#         else:
#             ARR2[i][j] = 1


def calclulate(h, w, k, arr):
    result = 0
    hIndex = [i for i in range(h)]
    wIndex = [i for i in range(w)]

    for hChooseNum in range(h + 1):
        for wChooseNum in range(w + 1):
            for m in itertools.combinations(hIndex, hChooseNum):
                for n in itertools.combinations(wIndex, wChooseNum):

                    tmpArr = arr.copy()

                    for _m in m:
                        tmpArr[_m, :] = 0
                    for _n in n:
                        tmpArr[:, _n] = 0

                    if np.sum(tmpArr == 1) == k:
                        result += 1
    print(result)


calclulate(H, W, K, ARR2)
Buggy python submission (verdict: Runtime Error):
N, M, K = 3, 4, 240
ARR = [60, 90, 120]
BRR = [80, 150, 80, 150]


N,M,K = 3, 4, 730
ARR = [60, 90, 120]
BRR = [80, 150, 80, 150]


N,M,K = 5, 4, 1
ARR = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000]
BRR = [1000000000, 1000000000, 1000000000, 1000000000]

N,M,K = map(int,input().split())
ARR = list(map(int,input().split()))
BRR = list(map(int,input().split()))


def calculate(n,m,k,arr,brr):
    arrIndex = 0
    brrIndex = 0

    total = 0
    result = 0

    while True:
        if (brrIndex >= m) and (arrIndex >= n):
            break

        if arrIndex >= n:
            if (total + brr[brrIndex]) <=k:
                total += brr[brrIndex]
                result += 1
                brrIndex += 1
                continue
            else:
                break

        if brrIndex >= m:
            if (total + brr[brrIndex]) <=k:
                total += brr[brrIndex]
                result += 1
                brrIndex += 1
                continue
            else:
                break

        if arr[arrIndex] < brr[brrIndex]:
            if (total + arr[arrIndex]) <= k:
                total += arr[arrIndex]
                result += 1
                arrIndex += 1
            else:
                break
        else:
            if (total + brr[brrIndex]) <=k:
                total += brr[brrIndex]
                result += 1
                brrIndex += 1
            else:
                break

    print(result)

calculate(N,M,K,ARR,BRR)

Fixed submission:
from collections import deque

N, M, K = 3, 4, 240
ARR = [60, 90, 120]
BRR = [80, 150, 80, 150]
#
# N, M, K = 3, 4, 730
# ARR = [60, 90, 120]
# BRR = [80, 150, 80, 150]

N, M, K = 5, 4, 1
ARR = [1000000000, 1000000000, 1000000000, 1000000000, 1000000000]
BRR = [1000000000, 1000000000, 1000000000, 1000000000]

N, M, K = 7, 4, 14
ARR = [1, 6, 1, 1, 1, 7, 2]
BRR = [5, 1, 5, 6, 7]


N,M,K = map(int,input().split())
ARR = list(map(int,input().split()))
BRR = list(map(int,input().split()))


def calculate(n, m, k, arr, brr):
    q = deque()

    result = []
    total = 0

    for i in range(n):
        if (total + arr[i]) > k:
            break
        total += arr[i]
        q.append(arr[i])

    result.append(len(q))

    remain = k - total

    q2 = deque(brr)
    sss = 0

    while (len(q2) > 0) and ((sss + q2[0]) <= remain):
        v = q2.popleft()
        sss += v

    result.append(len(q) + (m - len(q2)))

    while len(q) > 0:
        right = q.pop()
        remain += right

        while (len(q2) > 0) and ((sss + q2[0]) <= remain):
            v = q2.popleft()
            sss += v

        result.append(len(q) + (m - len(q2)))

    print(max(result))


calculate(N, M, K, ARR, BRR)
Buggy python submission (verdict: Time Limit Exceeded):
N = 5
ARR = [24, 11, 8, 3, 16]


N = 4
ARR = [5, 5, 5, 5]


N = 10
ARR = [33, 18, 45, 28, 8, 19, 89, 86, 2, 4]

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

def calculate(n, arr):

    prr = [0 for i in range(2000005)]

    for i in range(n):
        start = arr[i]
        #
        # if prr[start] > 0:
        #     prr[start] = 2
        #     continue

        for j in range(start, 2000005, start):
            prr[j] = prr[j] + 1


    result = 0
    for i in range(n):
        start = arr[i]
        if prr[start] == 1:
            result += 1


    print(result)

calculate(N, ARR)


Fixed submission:
N = 5
ARR = [24, 11, 8, 3, 16]

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

def calculate(n, arr):
    maxValue = max(arr) + 1
    maxValue = 1000006
    krr = [0 for i in range(maxValue)]

    for start in arr:
        if krr[start] > 0:
            krr[start] = 2
            continue

        for i in range(start, maxValue, start):
            krr[i] += 1

    result = 0
    for ar in arr:
        if krr[ar] == 1:
            result = result + 1

    print(result)


calculate(N, ARR)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
ARR = list(map(int, input().split()))


# N = 3
# ARR = [1000000000, 0, 9]
#
# N = 31
# ARR =  [4, 1, 5, 9, 2, 6, 5, 3, 5, 8, 9, 7, 9, 3, 2, 3, 8, 4, 6, 2, 6, 4, 3, 3, 8, 3, 2, 7, 9, 5, 0]

import math

def calculate(n, arr):
    res = 1
    for i in range(n):
        if arr[i] == 0:
            res = 0
            break

        if res >0 :
            a1 = math.log(res, 10)
            a2 = math.log(arr[i], 10)
            if a1 + a2 > 18:
                res = -1
                continue

        res = res * arr[i]
        if res > 1000000000000000000:
            res = -1

    return res


print(calculate(N, ARR))


Fixed submission:
N = int(input())
ARR = list(map(int, input().split()))


# N = 3
# ARR = [1000000000, 0, 9]
#
# N = 31
# ARR =  [4, 1, 5, 9, 2, 6, 5, 3, 5, 8, 9, 7, 9, 3, 2, 3, 8, 4, 6, 2, 6, 4, 3, 3, 8, 3, 2, 7, 9, 5, 0]

def calculate(n, arr):
    res = 1
    for i in range(n):
        if arr[i] == 0:
            res = 0
            break

        if res == -1:
            continue

        res = res * arr[i]
        if res > 1000000000000000000:
            res = -1

    return res


print(calculate(N, ARR))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
ARR = list(map(int,input().split()))

import math
# N = 2
# ARR = [1000000000, 1000000000]

def calculate(n,arr):
    res = 1
    for i in range(n):
        # a1 = math.log(arr[i],10)
        # a2 = math.log(arr[i], 10)
        # if a1 + a2 > 18:
        #     res = -1
        #     continue
        res = res * arr[i]
        if res > 1000000000000000000:
            res = -1

    return res

print(calculate(N,ARR))



Fixed submission:
N = int(input())
ARR = list(map(int, input().split()))


# N = 3
# ARR = [1000000000, 0, 9]
#
# N = 31
# ARR =  [4, 1, 5, 9, 2, 6, 5, 3, 5, 8, 9, 7, 9, 3, 2, 3, 8, 4, 6, 2, 6, 4, 3, 3, 8, 3, 2, 7, 9, 5, 0]

def calculate(n, arr):
    res = 1
    for i in range(n):
        if arr[i] == 0:
            res = 0
            break

        if res == -1:
            continue

        res = res * arr[i]
        if res > 1000000000000000000:
            res = -1

    return res


print(calculate(N, ARR))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
ARR = list(map(int,input().split()))

# N = 2
# ARR = [1000000000, 1000000000]

def calculate(n,arr):
    res = 1

    for i in range(n):
        res = res * arr[i]

    if res > 1000000000000000000:
        res = -1

    return res

print(calculate(N,ARR))



Fixed submission:
N = int(input())
ARR = list(map(int, input().split()))


# N = 3
# ARR = [1000000000, 0, 9]
#
# N = 31
# ARR =  [4, 1, 5, 9, 2, 6, 5, 3, 5, 8, 9, 7, 9, 3, 2, 3, 8, 4, 6, 2, 6, 4, 3, 3, 8, 3, 2, 7, 9, 5, 0]

def calculate(n, arr):
    res = 1
    for i in range(n):
        if arr[i] == 0:
            res = 0
            break

        if res == -1:
            continue

        res = res * arr[i]
        if res > 1000000000000000000:
            res = -1

    return res


print(calculate(N, ARR))
Buggy python submission (verdict: Runtime Error):
S = input().split()
A = int(S[0])
B = float(S[1])

from mpmath import mp
mp.dps = 50

res = mp.mpf(B*A)
print(int(res))

Fixed submission:
from decimal import *

a, b = input().split()
x = Decimal(a)
y = Decimal(b)

print(int(x*y))
Buggy python submission (verdict: Runtime Error):
# N, K = 4, 5
# ARR = [3, 2, 4, 1]

# N, K = 6, 727202214173249351
# ARR = [6, 5, 2, 5, 3, 2]


N,K = map(int,input().split())
ARR = list(map(int,input().split()))
NodeStatus = [False] * N
NodeFirstSteps = [0] * N
L = 0
OrderARR = []


def dfs(pos, arr, step):
    if NodeStatus[pos] == True:
        L = (step - NodeFirstSteps[pos])
        print(OrderARR[K % L] + 1)
        return
    OrderARR.append(pos)
    NodeStatus[pos] = True
    NodeFirstSteps[pos] = step
    dfs(arr[pos] - 1, arr, step + 1)


dfs(0, ARR, 0)


Fixed submission:
# N, K = 4, 5
# ARR = [3, 2, 4, 1]

# N, K = 6, 727202214173249351
# ARR = [6, 5, 2, 5, 3, 2]

import sys
sys.setrecursionlimit(100000000)

N,K = map(int,input().split())
ARR = list(map(int,input().split()))
NodeStatus = [False] * N
NodeFirstSteps = [0] * N
L = 0
STARTLINDEX = 0
OrderARR = []


def dfs(pos, arr, step):
    if NodeStatus[pos] == True:
        L = (step - NodeFirstSteps[pos])
        STARTLINDEX = NodeFirstSteps[pos]
        print(OrderARR[(K - STARTLINDEX) % L + STARTLINDEX] + 1)
        return

    if step == K:
        print(pos+1)
        return

    OrderARR.append(pos)
    NodeStatus[pos] = True
    NodeFirstSteps[pos] = step
    dfs(arr[pos] - 1, arr, step + 1)


dfs(0, ARR, 0)
Buggy python submission (verdict: Time Limit Exceeded):
import math

X = int(input())


def calculate(x):

    loop = True
    b = 0
    while loop:
        tmp1 = x + b ** 5
        a1 = math.pow(tmp1, 0.2)

        if float.is_integer(a1):
            print(int(a1), int(b))
            break

        tmp2 = x + (-1 * b) ** 5
        if tmp2 < 0:
            b = b + 1
            continue
        else:
            a2 = math.pow(tmp2, 0.2)
            if float.is_integer(a2):
                print(int(a2), int(-1*b))
                break
            b = b + 1

calculate(X)




Fixed submission:
import math

X = int(input())
# X = 33981761


def calculate(x):

    b = 0
    while True:
        tmp1 = x + b ** 5
        a1 = math.pow(tmp1, 0.2)

        if (a1 - math.floor(a1) < 1e-7):
            print(int(a1), int(b))
            break

        tmp2 = x + (-1 * b) ** 5
        if tmp2 >= 0:
            a2 = math.pow(tmp2, 0.2)
            if (a2 - math.floor(a2) < 1e-7):
                print(int(a2), int(-1 * b))
                break

        b = b + 1


calculate(X)

Buggy python submission (verdict: Runtime Error):
import math

X = int(input())


def calculate(x):

    loop = True
    b = 0
    while loop:
        tmp1 = x + b ** 5
        a1 = math.pow(tmp1, 1 / 5)

        if float.is_integer(a1):
            print(int(a1), int(b))
            break

        tmp2 = x + (-1 * b) ** 5
        a2 = math.pow(tmp2, 1 / 5)
        if float.is_integer(a2):
            print(int(a2), int(-1*b))
            break
        b = b + 1


calculate(X)


Fixed submission:
import math

X = int(input())
# X = 33981761


def calculate(x):

    b = 0
    while True:
        tmp1 = x + b ** 5
        a1 = math.pow(tmp1, 0.2)

        if (a1 - math.floor(a1) < 1e-7):
            print(int(a1), int(b))
            break

        tmp2 = x + (-1 * b) ** 5
        if tmp2 >= 0:
            a2 = math.pow(tmp2, 0.2)
            if (a2 - math.floor(a2) < 1e-7):
                print(int(a2), int(-1 * b))
                break

        b = b + 1


calculate(X)
Buggy python submission (verdict: Time Limit Exceeded):
K = int(input())

n = 1
s = 9 * 2 ** (n - 1)
while s < K:
    n = n + 1
    s = 9 * 2 ** (n - 1)

result = []


def bianli(currentIndex, currentValue, currentValueStr, maxLevel):
    if currentIndex < maxLevel:

        nextIndex = currentIndex + 1

        result.append(int(currentValueStr))

        bianli(nextIndex, currentValue, "{}{}".format(currentValueStr, currentValue), maxLevel)

        if currentValue == 0:
            nextValue = 1
            bianli(nextIndex, nextValue, "{}{}".format(currentValueStr, nextValue), maxLevel)
        elif currentValue == 9:
            nextValue = 8
            bianli(nextIndex, nextValue, "{}{}".format(currentValueStr, nextValue), maxLevel)
        else:
            nextValue = currentValue + 1
            bianli(nextIndex, nextValue, "{}{}".format(currentValueStr, nextValue), maxLevel)
            nextValue = currentValue - 1
            bianli(nextIndex, nextValue, "{}{}".format(currentValueStr, nextValue), maxLevel)

    else:
        result.append(int(currentValueStr))


bianli(1, 1,"1", n)
bianli(1, 2,"2", n)
bianli(1, 3,"3", n)
bianli(1, 4,"4", n)
bianli(1, 5,"5", n)
bianli(1, 6,"6", n)
bianli(1, 7,"7", n)
bianli(1, 8,"8", n)
bianli(1, 9,"9", n)

print(sorted(result)[K-1])


Fixed submission:
from collections import deque

K = int(input())

def calculate(n):
    q = deque()
    for i in range(1, 10):
        q.append(i)

    result = []

    while len(result) <= n:
        x = q.popleft()
        result.append(x)
        m = x % 10
        if m == 0:
            q.append(x * 10 + m)
            q.append(x*10+ m +1)
        elif m == 9:
            q.append(x*10 + m - 1)
            q.append(x * 10 + m)
        else:
            q.append(x*10 + m - 1)
            q.append(x * 10 + m)
            q.append(x*10 + m + 1)

    print(result[n-1])


calculate(K)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
ARR = [int(s) for s in input().split(" ")]
import numpy as np

def calculate(n,arr):

    dict = {}
    for ar in arr:

        if dict.get(ar) == None:
            dict.__setitem__(ar,1)
        else:
            tmp = dict.get(ar)
            tmp = tmp + 1
            dict.__setitem__(ar,tmp)


    for ar in arr:
        tmp = dict.get(ar)
        dict.__setitem__(ar,tmp-1)

        vals = np.array(list(dict.values()))
        print(sum((vals * (vals-1)) // 2))

        dict.__setitem__(ar,tmp)

calculate(N,ARR)

Fixed submission:
N = int(input())
ARR = [int(s) for s in input().split(" ")]
# N = 8
# ARR = [1, 2, 1, 4, 2, 1, 4, 1]

def calculate(n,arr):

    dict = {}
    brr = {}
    for ar in arr:

        if dict.get(ar) == None:
            dict.__setitem__(ar,1)
        else:
            tmp = dict.get(ar)
            tmp = tmp + 1
            brr.__setitem__(ar,(tmp * (tmp - 1)) // 2 )
            dict.__setitem__(ar,tmp)

    sumValue = sum(brr.values())

    for ar in arr:
        tmp = dict.get(ar)

        print(sumValue - (tmp - 1))

calculate(N,ARR)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

S = input()
Q = int(input())
ARR = []

for i in range(Q):
    arr = input().split(" ")
    ARR.append(arr)


def calculate(s,q,arr):

    s = deque(list(s))

    for ar in arr:
        if int(ar[0]) == 1:
            s.reverse()
        if int(ar[0]) == 2:
            if int(ar[1]) == 1:
                s.appendleft(ar[2])
            else:
                s.append(ar[2])
    print("".join(list(s)))

calculate(S,Q,ARR)

Fixed submission:
from collections import deque

S = input()
Q = int(input())
ARR = []

for i in range(Q):
    arr = input().split(" ")
    ARR.append(arr)


def calculate(s,q,arr):
    s = deque(list(s))

    kk = 0
    for ar in arr:
        if int(ar[0]) == 1:
            kk = kk + 1
        if int(ar[0]) == 2:
            if int(ar[1]) == 1:
                if kk % 2 == 0:
                    s.appendleft(ar[2])
                else:
                    s.append(ar[2])
            else:
                if kk % 2 == 0:
                    s.append(ar[2])
                else:
                    s.appendleft(ar[2])

    if kk % 2 == 1:
        s.reverse()

    print("".join(list(s)))

calculate(S,Q,ARR)

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())
ARR = []
for i in range(Q):
    ARR.append(input().split(" "))

def calculate(s,q,arr):
    s = list(s)
    for ar in arr:
        if int(ar[0]) == 1:
            s = list(reversed(s))

        if int(ar[0]) == 2:
            if int(ar[1]) == 1:
                s.insert(0,ar[2])
            else:
                s.append(ar[2])

    print("".join(s))



calculate(S,Q,ARR)


Fixed submission:
from collections import deque

S = input()
Q = int(input())
ARR = []

for i in range(Q):
    arr = input().split(" ")
    ARR.append(arr)


def calculate(s,q,arr):
    s = deque(list(s))

    kk = 0
    for ar in arr:
        if int(ar[0]) == 1:
            kk = kk + 1
        if int(ar[0]) == 2:
            if int(ar[1]) == 1:
                if kk % 2 == 0:
                    s.appendleft(ar[2])
                else:
                    s.append(ar[2])
            else:
                if kk % 2 == 0:
                    s.append(ar[2])
                else:
                    s.appendleft(ar[2])

    if kk % 2 == 1:
        s.reverse()

    print("".join(list(s)))

calculate(S,Q,ARR)
Buggy python submission (verdict: Runtime Error):
N, X = 6, 1
ARR = [1, 6, 1, 2, 0, 4]

N, X = 3, 3
ARR = [2, 2, 2]

N, X = 5, 9
ARR = [3, 1, 4, 1, 5]

N, X = 2, 0
ARR = [5, 5]

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

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


def calculate(n, x, arr):
    result = 0
    for i in range(1, n):
        sSum = arr[i - 1] + arr[i]
        if sSum <= x:
            continue

        diff = sSum - x

        if diff <= arr[i]:
            arr[i] -= diff
            result += diff
        else:
            result += diff
            arr[i] = 0

    print(result)


calculate(N, X, ARR)


Fixed submission:
import math
N = int(input())

print(math.ceil(N/2))