Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import numpy as np
import itertools

h,w,k = list(map(int, input().split()))

matrix = np.empty((h,w), dtype = 'str')

for i in range(h):
    matrix[i] = list(input())

if np.count_nonzero(matrix=='#') == k:
    cnt = 1
else:
    cnt = 0

for n_row in range(h+1):
    for n_col in range(w+1):
        for r in itertools.combinations(range(h), n_row):
            for c in itertools.combinations(range(w), n_col):
                if not r and not c:
                    continue
                chg_matrix = matrix.copy()
                chg_matrix[:,c] = '&'
                chg_matrix[r,:] = '&'
                if np.count_nonzero(chg_matrix=='#') == k:
                    cnt += 1

print(cnt)

Fixed submission:
import itertools
import numpy as np

h,w,k = list(map(int, input().split()))

matrix = np.empty((h,w), dtype = 'str')

for i in range(h):
    matrix[i] = list(input())

if np.count_nonzero(matrix=='#') == k:
    cnt = 1
else:
    cnt = 0

for n_row in range(h+1):
    for n_col in range(w+1):
        for r in itertools.combinations(range(h), n_row):
            for c in itertools.combinations(range(w), n_col):
                if not r and not c:
                    continue
                chg_matrix = matrix.copy()
                chg_matrix[:,c] = '&'
                chg_matrix[r,:] = '&'
                if np.count_nonzero(chg_matrix=='#') == k:
                    cnt += 1

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

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

ans = int(a * b / math.gcd(a, b))

print(ans)


Fixed submission:
def calc_gcd(a, b):
    r = a % b
    while (r != 0):
        a = b
        b = r
        r = a % b

    return b

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

if a < b:
    tmp = a
    a = b
    b = tmp

gcd = calc_gcd(a, b)
ans = int(a * b / gcd)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
print(sum(range(n)))


Fixed submission:

n = int(input())

if n % 2:
    print(n * (n - 1) // 2)
else:
    print(n * (n // 2 - 1) + n // 2)

Buggy python submission (verdict: Runtime Error):

import numpy as np

n = int(input())
p = np.array(list(range(2, n + 1)) + [1])
mod = p - 1

print(sum(mod[:n-1]))


Fixed submission:

n = int(input())

if n % 2:
    print(n * (n - 1) // 2)
else:
    print(n * (n // 2 - 1) + n // 2)
Buggy python submission (verdict: Runtime Error):
x, n = map(int, input().split())
p = list(map(int, input().split()))

p_all = set(range(0, 102)) - set(p)
# print(p_all)

mi = float('inf')
ans = 0
for i in p_all:
    if abs(x - i) < mi:
        mi = abs(x - i)
        ans = i

print(ans)


Fixed submission:
import sys
import math

n = int(input())
a = list(map(int, input().split()))
a.sort()
limit = max(a)
dp = [True] * (limit + 1)
archives = set()
for i in a:
    if i in archives:
        dp[i] = False
        continue
    archives.add(i)
    n = 2
    while i * n <= limit:
        dp[i * n] = False
        n += 1

# print(dp)
ans = 0
for i in a:
    if dp[i] is True:
        ans += 1


print(ans)
Buggy python submission (verdict: Runtime Error):
import sys

input = sys.stdin.readline
n, k = map(int, input().split())

p = list(map(lambda x: (x + 1) / 2, map(int, input().split())))

# 1 - pi
ans = k
init = p[0]
for i in range(k, len(p)):
    if init < p[i]:
        init = p[i]
        ans = i

exp = 0
for i in range(ans - k + 1, ans + 1):
    exp += p[i]
print('{:.12f}'.format(exp))


Fixed submission:
import sys
import numpy as np

input = sys.stdin.readline
n, k = map(int, input().split())

p = list(map(lambda x: (x + 1) / 2, map(int, input().split())))
# 1 - pi
# print(p)
p_cumsum = np.cumsum(p)
# print(p_cumsum)
ans = p_cumsum[k-1]

for i in range(0, n - k):
    # print(i, i + k)
    cum = p_cumsum[i + k] - p_cumsum[i]
    ans = max(ans, cum)


print('{:.12f}'.format(ans))

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

input = sys.stdin.readline
n, k = map(int, input().split())

p = list(map(lambda x: (x + 1) / 2, map(int, input().split())))

# 1 - pi
ans = k
init = p[0]
for i in range(k, len(p)):
    print(i)
    if init < p[i]:
        init = p[i]
        ans = i

exp = 0
for i in range(ans - k + 1, ans + 1):
    exp += p[i]
print('{:.12f}'.format(exp))


Fixed submission:
import sys
import numpy as np

input = sys.stdin.readline
n, k = map(int, input().split())

p = list(map(lambda x: (x + 1) / 2, map(int, input().split())))
# 1 - pi
# print(p)
p_cumsum = np.cumsum(p)
# print(p_cumsum)
ans = p_cumsum[k-1]

for i in range(0, n - k):
    # print(i, i + k)
    cum = p_cumsum[i + k] - p_cumsum[i]
    ans = max(ans, cum)


print('{:.12f}'.format(ans))

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())

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

# 1 - pi
ans = 0
for i in range(len(p)-k + 1):
    exp = 0
    for idx in range(i, i+k):
        exp += (p[idx] + 1) / 2
    ans = max(ans, exp)

print('{:.12f}'.format(ans))


Fixed submission:
import sys
import numpy as np

input = sys.stdin.readline
n, k = map(int, input().split())

p = list(map(lambda x: (x + 1) / 2, map(int, input().split())))
# 1 - pi
# print(p)
p_cumsum = np.cumsum(p)
# print(p_cumsum)
ans = p_cumsum[k-1]

for i in range(0, n - k):
    # print(i, i + k)
    cum = p_cumsum[i + k] - p_cumsum[i]
    ans = max(ans, cum)


print('{:.12f}'.format(ans))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
p = list(map(int, input().split()))

flg_min = p[0]
ans = 1
for i in range(1, n + 1):
    temp = p[:i]
    min_temp = min(temp)
    if flg_min > min_temp:
        ans += 1
        flg_min = min_temp

print(ans)

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

flg_min = p[0]
ans = 1
for i in range(1, n):
    temp = p[i]
    if flg_min > temp:
        ans += 1
        flg_min = temp
print(ans)
Buggy python submission (verdict: Runtime Error):
from collections import deque

H, W = map(int, input().split())
maze = []
for _ in range(H):
    maze.append(list(input()))


def successors(x, y):
    locations = []
    # 下に行けるかの判定
    if (x + 1 < H) and (maze[x + 1][y] != '#'):
        locations.append((x + 1, y))
    # 上に行けるかの判定
    if (x - 1 >= 0) and (maze[x - 1][y] != '#'):
        locations.append((x - 1, y))
    # 右に行けるかの判定
    if (y + 1 < W) and (maze[x][y + 1] != '#'):
        locations.append((x, y + 1))
    # 左に行けるかの判定
    if (y - 1 >= 0) and (maze[x][y - 1] != '#'):
        locations.append((x, y - 1))
    return locations


def bfs(initial, successors):
    # goal判定はなく、一番遠いところで返す
    frontier = deque()
    frontier.append((initial, None))
    # tuple
    explored = {initial}

    while len(frontier):
        current_node = frontier.popleft()
        current_state = current_node[0]
        for child in successors(*current_state):
            if str(child) in [str(i) for i in explored]:
                continue
            explored.add(child)
            frontier.append((child, current_node))
    return current_node


def node_to_path_count(node):
    counter = 0
    while node[1] is not None:
        counter += 1
        node = node[1]
    return counter


ans = 0
for x in range(H):
    for y in range(W):
        if maze[x][y] == '.':
            solution = bfs((x, y), successors)
            counter = node_to_path_count(solution)
            if ans < counter:
                ans = counter

print(ans)

Fixed submission:
c = input()

print(chr(ord(c) + 1))
Buggy python submission (verdict: Runtime Error):
import math

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


def lcm(x, y):
    return (x * y) // math.gcd(x, y)


print(lcm(A, B))

Fixed submission:
import fractions

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


def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)


print(lcm(A, B))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

if n == 1:
    print(0)
elif n == 2:
    print(1)
else:
    print(sum(range(1, n)))

Fixed submission:
n = int(input())

if n == 1:
    print(0)
elif n == 2:
    print(1)
else:
    print((1 + n - 1) * (n - 1) // 2)
Buggy python submission (verdict: Time Limit Exceeded):
import sys

sys.setrecursionlimit(10 ** 8)
n, q = map(int, input().split())

edges = [[] for _ in range(n)]
for _ in range(n - 1):
    frm, to = map(int, input().split())
    # 0-index
    edges[frm - 1].append(to - 1)
    edges[to - 1].append(frm - 1)

scores = [0] * n
for _ in range(q):
    v, s = map(int, input().split())
    scores[v - 1] += s


def dfs(frm, cur):
    if cur > 0:
        scores[cur] += scores[frm]
    for to in edges[cur]:
        if frm != to:
            dfs(cur, to)


dfs(-1, 0)
print(" ".join([str(w) for w in scores]))

Fixed submission:
import sys

sys.setrecursionlimit(10 ** 8)
input = sys.stdin.readline
n, q = map(int, input().split())

edges = [[] for _ in range(n)]
for _ in range(n - 1):
    frm, to = map(int, input().split())
    # 0-index
    edges[frm - 1].append(to - 1)
    edges[to - 1].append(frm - 1)

scores = [0] * n
for _ in range(q):
    v, s = map(int, input().split())
    scores[v - 1] += s


def dfs(frm, cur):
    if cur > 0:
        scores[cur] += scores[frm]
    for to in edges[cur]:
        if frm != to:
            dfs(cur, to)


dfs(-1, 0)
print(" ".join([str(w) for w in scores]))
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter

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

str_count = [Counter(l) for l in strings]

ans = 0
for x in range(len(str_count)):
    for y in range(x + 1, len(str_count)):
        if str_count[x] == str_count[y]:
            ans += 1

print(ans)


Fixed submission:
from collections import Counter

N = int(input())
strings = [str(sorted(Counter(input()).items())) for _ in range(N)]

counts = Counter(strings)
ans = 0
for i in counts.values():
    ans += sum(range(i))

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

n, k = map(int, input().split())
h = list(map(int, input().split()))

dp = [float('inf')] * n

dp[0] = 0

for i in range(1, n):
    for j in range(1, k + 1):
        if i - j < 0:
            continue
        dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]))

print(dp[n - 1])


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

dp = [float('inf')] * n

dp[0] = 0

for i in range(1, n):
    for j in range(1, k+1):
        if i - j < 0:
            continue
        dp[i] = min(dp[i], dp[i-j] + abs(h[i] - h[i-j]))

print(dp[n-1])

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
h = list(map(int, input().split()))

dp = [float('inf')] * n

dp[0] = 0

for i in range(1, n):
    for j in range(1, k+1):
        if i - j < 0:
            continue
        dp[i] = min(dp[i], dp[i-j] + abs(h[i] - h[i-j]))

print(dp[n-1])


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

dp = [float('inf')] * n

dp[0] = 0

for i in range(1, n):
    for j in range(1, k+1):
        if i - j < 0:
            continue
        dp[i] = min(dp[i], dp[i-j] + abs(h[i] - h[i-j]))

print(dp[n-1])

Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
h = list(map(int, input().split()))
dp = [float('inf') for _ in range(n)]
dp[0] = 0

for i in range(1, n):
    if i- k > 0:
        s = i - k
    else:
        s = 0
    dp[i] = min(d + abs(h[i] - h) for d, h in zip(dp[s:i], h[s:i]))

print(dp[-1])

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

dp = [float('inf')] * n

dp[0] = 0

for i in range(1, n):
    for j in range(1, k+1):
        if i - j < 0:
            continue
        dp[i] = min(dp[i], dp[i-j] + abs(h[i] - h[i-j]))

print(dp[n-1])
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())

h = []
for _ in range(N):
    h.append(int(input()))

h.sort()

iter = len(h) - K

c_hmin = 99999999999999999999999999999999

for i in range(iter+1):
    cell = h[i: K + i]
    hmin = cell[-1] - cell[0]
    if c_hmin > hmin:
        c_hmin = hmin

print(c_hmin)

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

h = []
for _ in range(N):
    h.append(int(input()))

h.sort()

iter = len(h) - K

c_hmin = 99999999999999999999999999999999

for i in range(iter+1):

    hmin = h[K+i-1] - h[i]
    if c_hmin > hmin:
        c_hmin = hmin

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

N = int(input())

# ここで、七五三数とは以下の条件を満たす正の整数です。
# 十進法で表記したとき、数字 7, 5, 3 がそれぞれ 1 回以上現れ、これら以外の数字は現れない。

ans = 0
for i in range(1, N + 1):
    i = str(i)
    if ("3" in i) and ("5" in i) and ("7"in i):
        if ("1" not in i) and ("2" not in i) and ("4" not in i) and ("6" not in i) and ("8" not in i) and ("9" not in i) and ("0" not in i):
            ans += 1

print(ans)


Fixed submission:
N = int(input())

# ここで、七五三数とは以下の条件を満たす正の整数です。
# 十進法で表記したとき、数字 7, 5, 3 がそれぞれ 1 回以上現れ、これら以外の数字は現れない。


def dfs(s):
    if int(s) > N:
        return 0

    ret = 1 if all(s.count(c) > 0 for c in '753') else 0

    for c in '753':
        ret += dfs(s + c)
    return ret


print(dfs('0'))
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = [int(input()) for i in range(N)]

A.sort()
right = A[:int(len(A) / 2)]
left = A[int(len(A) / 2):]

max_list = []

if len(right) == 1:
    max_list = [left[0], right[0], left[1]]
else:

    while True:
        if right:
            max_list.append(right.pop())
        if left:
            max_list.append(left.pop())

        if len(right) == 0 and len(left) == 0:
            break

ans = 0
for i in range(len(max_list)-1):
    ans += abs(max_list[i] - max_list[i+1])

print(ans)


Fixed submission:
N = int(input())
A = [int(input()) for i in range(N)]

A.sort()

if len(A) % 2 == 1:
    order1 = [-1, -1]
    for i in range(len(A)-2):
        if i % 2 == 0:
            order1.append(2)
        else:
            order1.append(-2)

    order2 = [1, 1]
    for i in range(len(A)-2):
        if i % 2 == 0:
            order2.append(-2)
        else:
            order2.append(2)
else:
    order1 = [-1, 1]
    for i in range(len(A) - 2):
        if i % 2 == 0:
            order1.append(2)
        else:
            order1.append(-2)

    order2 = [-1, 1]
    for i in range(len(A) - 2):
        if i % 2 == 0:
            order2.append(-2)
        else:
            order2.append(2)


order1.sort()
order2.sort()

sum1 = 0
sum2 = 0
for x, y, z in zip(A, order1, order2):
    sum1 += x * y
    sum2 += x * z

print(max(sum1, sum2))
Buggy python submission (verdict: Runtime Error):
route_num, limit = map(int, input().split(' '))

costs = []
spends = []
for i in range(route_num):
    cost, spend = map(int, input().split(' '))
    costs.append(cost)
    spends.append(spend)

min_cost = 2000
for cost, spend in zip(costs, spends):
    if spend <= limit and cost < min_cost:
        min_cost = cost

if min_cost == 2000:
    print("TLE")

else:
    print(min_cost)


Fixed submission:
pattern = int(input())

if pattern == 1:
    print("Hello World")
elif pattern == 2:
    a = int(input())
    b = int(input())

    print(a + b)
Buggy python submission (verdict: Time Limit Exceeded):
count = int(input())
nums = list(map(int, input().split()))


def f(b):
    sum_num = 0
    for x, num in enumerate(nums, 1):
        sum_num += abs(num - (b + x))

    return sum_num


maximum = max(nums)

minimum = 10000000
for i in range(-1 * maximum, maximum + 1):
    calc = f(i)
    if minimum > calc:
        minimum = calc
        ans = calc

print(ans)



Fixed submission:
from statistics import median
n = int(input())
nums = list(map(int, input().split()))
bs = nums.copy()
tmp = 0

for i in range(n):
    bs[i] -= i + 1


med = median(bs)

ans = 0
for i in range(n):
    ans += abs(bs[i] - med)

print(int(ans))
Buggy python submission (verdict: Time Limit Exceeded):
import bisect

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

a.sort()
b.sort()
c.sort()

ans = 0
for l in a:
    m_idx = bisect.bisect_right(b, l)
    if m_idx == n:
        break
    for m in b[m_idx:]:
        l_idx = bisect.bisect_right(c, m)
        if l_idx == n:
            break
        ans += n - l_idx

print(ans)


Fixed submission:
import bisect

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

a.sort()
b.sort()
c.sort()


def binary_upper(k, x):
    return len(k) - bisect.bisect_right(k, x)


def binary_lower(k, x):
    return bisect.bisect_left(k, x)


ans = 0

for middle in b:
    cnt_a = binary_lower(a, middle)
    cnt_c = binary_upper(c, middle)
    ans += cnt_a * cnt_c

print(ans)

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

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

a.sort()
b.sort()
c.sort()


def binary_search(k, x):
    index = bisect.bisect_right(k, x)
    if index == len(k):
        return False
    else:
        # index + 1個している
        return index + 1


ans = 0
for up in a:
    indexed_b = binary_search(b, up)
    b_cnt = n - (indexed_b - 1)
    if b_cnt > len(b):
        break
    for middle in b[indexed_b-1:]:
        indexed_c = binary_search(c, middle)
        c_cnt = n - (indexed_c - 1)
        ans += c_cnt

print(ans)


Fixed submission:
import bisect

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

a.sort()
b.sort()
c.sort()


def binary_upper(k, x):
    return len(k) - bisect.bisect_right(k, x)


def binary_lower(k, x):
    return bisect.bisect_left(k, x)


ans = 0

for middle in b:
    cnt_a = binary_lower(a, middle)
    cnt_c = binary_upper(c, middle)
    ans += cnt_a * cnt_c

print(ans)
Buggy python submission (verdict: Runtime Error):
from collections import deque
N = int(input())


# 最大公約数
def gcd(a, b):
    while b > 0:
        a, b = b, a%b
    return a


# 最小公倍数
def lcm(a, b):
    return a*b/gcd(a, b)


array = deque()
for _ in range(N):
    array.append(int(input()))

if len(array) == 1:
    print(array[0])

while len(array) > 1:
    a = array.pop()
    b = array.pop()
    array.append(lcm(a, b))

print(int(array[0]))


Fixed submission:
from collections import deque
N = int(input())


# 最大公約数
def gcd(a, b):
    while b > 0:
        a, b = b, a%b
    return a


# 最小公倍数
def lcm(a, b):
    return a*b//gcd(a, b)


array = []
for _ in range(N):
    array.append(int(input()))

ans = array[0]
for x in array[1:]:
    ans = lcm(ans, x)


print(ans)

Buggy python submission (verdict: Runtime Error):
from functools import lru_cache
from collections import deque
N = int(input())


# 最大公約数
def gcd(a, b):
    while b > 0:
        a, b = b, a%b
    return a


# 最小公倍数
def lcm(a, b):
    return a*b/gcd(a, b)


array = deque()
for _ in range(N):
    array.append(int(input()))

#@lru_cache(maxsize = None)
#def multi_lcm():

while len(array) > 1:
    a = array.pop()
    b = array.pop()
    array.append(lcm(a, b))

print(int(array[0]))

Fixed submission:
from collections import deque
N = int(input())


# 最大公約数
def gcd(a, b):
    while b > 0:
        a, b = b, a%b
    return a


# 最小公倍数
def lcm(a, b):
    return a*b//gcd(a, b)


array = []
for _ in range(N):
    array.append(int(input()))

ans = array[0]
for x in array[1:]:
    ans = lcm(ans, x)


print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
k, s = map(int, input().split())

ans = 0
for x in range(k + 1):
  for y in range(k + 1):
    for z in range(k + 1):
      if x + y + z == s:
        ans += 1
 
print(ans)
      

Fixed submission:
# https://atcoder.jp/contests/abc051/tasks/abc051_b
k, s = map(int, input().split())
ans = 0
for x in range(k + 1):
    for y in range(k + 1):
        if 0 <= s - x - y <= k:
            ans += 1

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import math
k = int(input())

ans = 0
for i in range(1, k + 1):
    for x in range(1, k + 1):
        for z in range(1, k + 1):
            ans += math.gcd(i, math.gcd(x, z))
print(ans)

Fixed submission:
from math import gcd
k = int(input())

ans = 0
for i in range(1, k + 1):
    for x in range(1, k + 1):
        gcdix = gcd(i, x)
        for z in range(1, k + 1):
            ans += gcd(z, gcdix)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import math
k = int(input())

ans = 0
for i in range(1, k+1):
    for x in range(1, k+1):
        for z in range(1, k+1):
            ans += math.gcd(z,math.gcd(i, x))
            

print(ans)

Fixed submission:
from math import gcd
k = int(input())

ans = 0
for i in range(1, k + 1):
    for x in range(1, k + 1):
        gcdix = gcd(i, x)
        for z in range(1, k + 1):
            ans += gcd(z, gcdix)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())
t1 = 1
for i in range(q):
    t = input()
    if t == '1':
        t1 *= -1
    else:
        if t1 == 1:
            if t[2] == '1':
                s = t[4] + s
            else:
                s = s + t[4]
        else:
            if t[2] == '2':
                s = t[4] + s
            else:
                s = s + t[4]

ans = ''
if t1 == -1:
    ans = ''.join(list(reversed(s)))
else:
    ans = s

print(ans)
    

Fixed submission:
from collections import deque
s = deque(list(input()))
q = int(input())
t1 = 1
for i in range(q):
    t = input()
    if t == '1':
        t1 *= -1
    else:
        if t1 == 1:
            if t[2] == '1':
                s.appendleft(t[4])
            else:
                s.append(t[4])
        else:
            if t[2] == '2':
                s.appendleft(t[4])
            else:
                 s.append(t[4])

ans = ''
if t1 == -1:
    ans = ''.join(reversed(s))
else:
    ans = ''.join(s)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())
query = []
t1 = 1
for i in range(q):
    t = input()
    query.append(t)

for i in range(len(query)):
    t = query[i]
    if t == '1':
        t1 *= -1
    else:
        if t1 == 1:
            if t[2] == '1':
                s = t[4] + s
            else:
                s = s + t[4]
        else:
            if t[2] == '2':
                s = t[4] + s
            else:
                s = s + t[4]
        
ans = ''
if t1 == -1:
    ans = ''.join(list(reversed(s)))
else:
    ans = s

print(ans)
    

Fixed submission:
from collections import deque
s = deque(list(input()))
q = int(input())
t1 = 1
for i in range(q):
    t = input()
    if t == '1':
        t1 *= -1
    else:
        if t1 == 1:
            if t[2] == '1':
                s.appendleft(t[4])
            else:
                s.append(t[4])
        else:
            if t[2] == '2':
                s.appendleft(t[4])
            else:
                 s.append(t[4])

ans = ''
if t1 == -1:
    ans = ''.join(reversed(s))
else:
    ans = ''.join(s)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
p = list(map(int, input().split()))
ans = 0
for i in range(n):
    l = p[:i + 1]
    if min(l) >= p[i]:
        ans += 1

print(ans)

Fixed submission:
n = int(input())
p = list(map(int, input().split()))
ans = 0
m = p[0]
for i in range(n):
    num = p[i]
    if m >= num:
        ans += 1
    m = min(m, num)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
ans = 9999999999999
for i in range(1, n+1):
    x1 = i
    x2 = n // x1
    if x1 * x2 == n and x1 + x2 < ans:
        ans = x1-1 + x2 -1
print(ans)

Fixed submission:
import math
n = int(input())
ans = 9999999999999
for i in range(1, math.ceil(math.sqrt(n+1))):
    x1 = i
    x2 = n // x1
    if x1 * x2 == n and x1 + x2 < ans:
        ans = x1-1 + x2 -1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(input().split())

for i in range(1,n+1):
    print(a.index(str(i)) + 1, end=' ')
print()

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
ans = [0] * n
for i in range(n):
    ans[a[i]-1] = i + 1
for i in range(n):
    print(ans[i], end=' ')
print()