Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p02675 (python)

Fixed submission:
i = int(input())
i = i % 10
if i == 0:
    print('pon')
elif i == 1:
    print('pon')
elif i == 2:
    print('hon')
elif i == 3:
    print('bon')
elif i == 4:
    print('hon')
elif i == 5:
    print('hon')
elif i == 6:
    print('pon')
elif i == 7:
    print('hon')
elif i == 8:
    print('pon')
elif i == 9:
    print('hon')

Buggy submission (verdict: Runtime Error):
i = int(input())

while i != 0:
    i = i % 10
    if i == 0:
        print('pon')
    elif i == 1:
        print('pon')
    elif i == 2:
        print('hon')
    elif i == 3:
        print('bon')
    elif i == 4:
        print('hon')
    elif i == 5:
	print('hon')
    elif i == 6:
	print('pon')
    elif i == 7:
	print('hon')
    elif i == 8:
	print('pon')
    elif i == 9:
	print('hon')

    i = int(input())
Problem p02612 (python)

Fixed submission:
n = int(input())
if n % 1000 == 0:
  print("0")
  exit()
print(1000 - (n % 1000))

Buggy submission (verdict: Runtime Error):
n = int(input)
if n % 1000 == 0:
  print("0")
  exit()
print(1000 - (n % 1000))
Problem p02628 (python)

Fixed submission:
N,K = map(int,input().split())
li = [int(i) for i in input().split()]
total = 0
 
for _ in range(K):
	total += min(li)
	li.remove(min(li))
 
print(total)

Buggy submission (verdict: Runtime Error):
N,K = map(int,input().split())
li = [int(i) for i in input().split()]
total = 0

for _ in range(K):
	total += min(li)
	li = li.remove(min(li))

print(total)
Problem p02675 (python)

Fixed submission:
a = input()
 
b = a[len(a)-1]
 
if b=='3':
	print('bon')
elif b == '0' or  b == '1' or  b == '6' or b == '8':
	print('pon')
else:
	print('hon')

Buggy submission (verdict: Runtime Error):
a = input()

b = a[len(a)-1]

if b=='3':
	print('bon')
else if b == '0' or  b == '1' or  b == '6' or b == '8':
	print('pon')
else:
	print('hon')
Problem p02684 (python)

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

v = 1
s = [-1] * (n+1)
d = []
l = 0
c = 0

while s[v] == -1:
  s[v] = len(d)
  d.append(v)
  v = a[v-1]
l = s[v]
c = len(d) - s[v]

if k < l:
  print(d[k])
else:
  k -= l
  k %= c
  print(d[l+k])

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

d = [-1] * (n+1)
ls = 0
le = 0

def dfs(i, t):
  global d, ls, le
  if d[i] != -1:
    ls = i
    return False
  d[i] = t
  ret = dfs(a[i-1], t+1)
  if ret == False:
    le = i

dfs(1, 0)

#print(d)
#print(ls, le)

ans = 0
if k <= d[le] or ls == 0:
  ans = d.index(k)
else:
  ld = d[ls]
  t = (k-ld) % (d[le] - d[ls] + 1)
  t += d[ls]
  ans = d.index(t)

print(ans)

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

d = [-1] * (n+1)
ls = 0
le = 0

def dfs(i, t):
  global d, ls, le
  if d[i] != -1:
    ls = i
    return False
  d[i] = t
  ret = dfs(a[i-1], t+1)
  if ret == False:
    le = i

dfs(1, 0)

#print(d)
#print(ls, le)

ans = 0

ld = d[ls]
t = (k-ld) % (d[le] - d[ls] + 1)
t += d[ls]
ans = d.index(t)

print(ans)

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

d = [-1] * (n+1)
ls = 0
le = 0

def dfs(i, t):
  global d, ls, le
  if d[i] != -1:
    ls = i
    return False
  d[i] = t
  ret = dfs(a[i-1], t+1)
  if ret == False:
    le = i

dfs(1, 0)

#print(d)
#print(ls, le)
ld = d[ls]

ans = 0
if k <= d[le]:
  ans = d.index(k)
else:
  t = (k-ld) % (d[le] - d[ls] + 1)
  t += d[ls]
  ans = d.index(t)

print(ans)
Problem p02803 (python)

Fixed submission:
import queue
h, w = map(int, input().split())
m = []
for i in range(h):
  m.append(input())
#print(h, w)
#print(m)
q = queue.Queue()
a = []
def init():
  global a
  a = []
  for i in range(h):
    a.append([-1] * w)

def bfs(cx, cy):
  nxs = [1, 0, -1, 0]
  nys = [0, -1, 0, 1]
  for i in range(4):
    nx = cx + nxs[i]
    ny = cy + nys[i]
    if 0 <= nx and nx < w and 0 <= ny and ny < h and m[ny][nx] == '.' and a[ny][nx] == -1:
      a[ny][nx] = a[cy][cx] + 1
      q.put([nx, ny])
  
def check(start_x, start_y):
  if m[start_y][start_x] == '#':
    return 0
  
  global a, q
  init()
  q.put([start_x, start_y])
  a[start_y][start_x] = 0
  end_x = -1
  end_y = -1
  while not q.empty():
    cx, cy = q.get()
    bfs(cx, cy)
    end_x = cx
    end_y = cy
  return a[end_y][end_x]

ans = 0
for i in range(h * w - 1):
    start_x = i % w
    start_y = i // w
    ans = max(ans, check(start_x, start_y))
    
print(ans)

Buggy submission (verdict: Runtime Error):
import queue
h, w = map(int, input().split())
m = []
for i in range(h):
  m.append(input())
#print(h, w)
#print(m)
q = queue.Queue()
a = []
def init():
  global a, q
  q = queue.Queue()
  a = []
  for i in range(h):
    a.append([-1] * w)

def bfs(cx, cy):
  nxs = [1, 0, -1, 0]
  nys = [0, -1, 0, 1]
  for i in range(4):
    nx = cx + nxs[i]
    ny = cy + nys[i]
    if 0 <= nx and nx < w and 0 <= ny and ny < h and m[ny][nx] == '.' and a[ny][nx] == -1:
      a[ny][nx] = a[cy][cx] + 1
      q.put([nx, ny])
  
def check(start_x, start_y, end_x, end_y):
  if m[start_y][start_x] == '#' or m[end_y][end_y] == '#':
    return 0
  if start_x == end_x and start_y == end_y:
    return 0
  
  global a, q
  init()
  q.put([start_x, start_y])
  a[start_y][start_x] = 0
  while not q.empty():
    cx, cy = q.get()
    bfs(cx, cy)
  return a[end_y][end_x]

ans = 0
for start_y in range(h):
  for start_x in range(w):
    for end_y in range(h):
      for end_x in range(w):
        ans = max(ans, check(start_x, start_y, end_x, end_y))
  
print(ans)
Problem p02909 (python)

Fixed submission:
weather = {'Sunny': 'Cloudy', 'Cloudy': 'Rainy', 'Rainy': 'Sunny'}
 
today = input()
print(weather[today])

Buggy submission (verdict: Runtime Error):
import sys
 
stringCount = int(input())
targetString = input()
 
maxCount = stringCount // 2
 
for exclusionCount in range(maxCount):
    count = maxCount - exclusionCount
 
    for i in range(maxCount):
        if (i + count * 2) > stringCount:
            break
 
        word = targetString[i:count]
        end = stringCount - len(word)
        if (targetString.count(word, 0, end) > 1):
            print('{}'.format(count))
            sys.exit()
 
print('0')

Buggy submission (verdict: Runtime Error):
weather = {'Sunny': 'Cloudy', 'Cloudy': 'Rainy', 'Rainy': 'Sunny'}

in = input()
print(weather[in])
Problem p03106 (python)

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

def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i:
        divisors.append(n // i)
  divisors.sort()
  return divisors

a_divs = make_divisors(a)
b_divs = make_divisors(b)

common_divs = []
for i in range(len(a_divs)):
  a_div = a_divs[i]
  if a_div in b_divs:
    common_divs.append(a_div)
print(common_divs[-k])

Buggy submission (verdict: Runtime Error):
a, b, k = map(int, input().split())
m = b if a > b else a
ans = []
for i in range(1, (m // 2)+2):
  if a % i == 0 and b % i == 0:
    ans.append(i)
print(ans[-k])

Buggy submission (verdict: Runtime Error):
a, b, k = map(int, input().split())
m = a if a > b else b
ans = []
for i in range((m // 2)+1, 0, -1):
  if a % i == 0 and b % i == 0:
    ans.append(i)
print(ans[k-1])
Problem p02641 (python)

Fixed submission:
# import numpy as np
import sys
input = sys.stdin.readline


def main():
    x, n = [int(i) for i in input().split()]
    p = set([int(i) for i in input().split()])

    ans = x
    for i in range(-1, 102):
        if i in p:
            continue

        if i <= x:
            ans = i
        else:
            if x - ans > i - x:
                ans = i
            break

    print(ans)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline


def main():
    x, n = [int(i) for i in input().split()]
    p = set([int(i) for i in input().split()])

    for i in range(1, 101):
        if i in p:
            continue

        if i <= x:
            ans = i
        elif x - ans > i - x:
            ans = i
            break

    print(ans)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline


def main():
    x, n = [int(i) for i in input().split()]
    p = set([int(i) for i in input().split()])

    for i in range(1, 101):
        if i in p:
            continue

        if i <= x:
            ans = i
        elif x - ans > i - x:
            ans = i
    else:
        print(ans)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline


def main():
    x, n = [int(i) for i in input().split()]
    p = set([int(i) for i in input().split()])

    for i in range(1, 101):
        if i in p:
            continue

        if i <= x:
            ans = i
        elif x - ans > i - x:
            ans = i
    else:
        print(ans)


if __name__ == '__m
Problem p02662 (python)

Fixed submission:
import numpy as np
import sys
input = sys.stdin.readline


def main():
    n, s = map(int, input().split())
    A = [int(i) for i in input().split()]

    MOD = 998244353

    dp = np.zeros(s + 1, dtype="int32")
    dp[0] = 1

    for a in A:
        p = (dp * 2) % MOD
        p %= MOD
        p[a:] += dp[:-a]
        dp = p % MOD

    print(dp[s])


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import numpy as np
import sys
input = sys.stdin.readline


def main():
    n, s = map(int, input().split())
    A = [int(i) for i in input().split()]

    MOD = 998244353

    dp = np.zeros(s + 1, dtype="int32")
    dp[0] = 1

    for a in A:
        p = (dp * 2) % MOD
        p %= MOD
        p[a:] += dp[:a]
        dp = p % MOD

    print(dp[s])


if __name__ == '__main__':
    main()
Problem p02678 (python)

Fixed submission:
from collections import deque as dq
import sys
input = sys.stdin.readline


def main():
    n, m = map(int, input().split())
    lst = [[] for _ in range(n + 1)]
    ans = [0] * (n + 1)
    que = dq()
    for _ in range(m):
        a, b = map(int, input().split())
        lst[a].append(b)
        lst[b].append(a)

    limit = 10 ** 5
    d = {i: limit + 1 for i in range(1, n + 1)}
    d[1] = 0
    que.append(1)
    while que:
        visit = que.popleft()
        for next_v in lst[visit]:
            if d[next_v] > d[visit] + 1:
                d[next_v] = d[visit] + 1
                que.append(next_v)
                ans[next_v] = visit

    if all([i != 0 for i in ans[2:]]):
        print('Yes')
        print(*ans[2:], sep='\n')
    else:
        print('No')


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
from collections import deque as dq
# import itertools
# import math
import networkx as nx
import sys
input = sys.stdin.readline


def main():
    n, m = map(int, input().split())
    limit = 10 ** 5
    # lst = [[] for _ in range(n + 1)]
    # ans = [0] * (n + 1)
    que = dq()
    # for _ in range(m):
    #     a, b = map(int, input().split())
    #     lst[a].append(b)
    #     lst[b].append(a)

    g = nx.Graph()
    g.add_edges_from([[i for i in input().split()] for _ in range(m)])
    # [[g.nodes[i][length] = limit ] for i in range(2, n + 1)]
    g.nodes[1]['length'] = 0
    for i in range(2, n + 1):
        g.nodes[i]['length'] = limit
        g.nodes[i]['next'] = 'Non'

    # d = {i: limit + 1 for i in range(1, n + 1)}
    # d[1] = 0
    que.append(1)
    # cnt = 1
    while que:
        visit = que.popleft()
        for next_v in g.succ[visit]:
            if g[next_v]['length'] > g[visit]['length'] + 1:
                g[next_v]['length'] = g[visit]['length'] + 1
                que.append(next_v)
                g[next_v]['next'] = visit

    if all(g.nodes[i]['next'] != 'Non' for i in range(2, n + 1)):
        print('Yes')
        for i in range(2, n + 1):
            print(g.nodes[i]['next'])
    else:
        print('No')


if __name__ == '__main__':
    main()
Problem p02683 (python)

Fixed submission:
import itertools
n, m, x = map(int, input().split())
lst = []

for i in range(n):
    lst.append([int(i) for i in input().split()])

ans_list = []

for i in range(1, n + 1):
    for j in itertools.combinations(lst, i):
        under_list = [0] * m
        money = 0
        for k in j:
            money += k[0]
            for i in range(m):
                under_list[i] += k[i + 1]
        if all([i >= x for i in under_list]):
            ans_list.append(money)

if not ans_list:
    ans = -1
else:
    ans = min(ans_list)

print(ans)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline


def main():
    n, m, x = map(int, input().split())

    MONEY = []
    UNDERSTAND = []
    for i in range(n):
        lst = [int(i) for i in input().split()]
        MONEY.append(lst[0])
        UNDERSTAND.append(lst[1:])

    ans = []
    for i in range(1 << n):
        understand = [0] * m
        money = 0
        for j in range(n):
            if (i >> j) & 1 == 0:
                continue
            money += MONEY[j]
            for k in range(m):
                understand[k] += UNDERSTAND[j][k]
        if all([i >= x for i in understand]):
            ans.append(money)

    print(min(ans))


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readlinedef


def main():
    n, m, x = map(int, input().split())

    MONEY = []
    UNDERSTAND = []
    for i in range(n):
        lst = [int(i) for i in input().split()]
        MONEY.append(lst[0])
        UNDERSTAND.append(lst[1:])

    ans = []
    for i in range(1 << n):
        understand = [0] * m
        money = 0
        for j in range(n):
            if (i >> j) & 1 == 0:
                continue
            money += MONEY[j]
            for k in range(m):
                understand[k] += UNDERSTAND[j][k]
        if all([i >= x for i in understand]):
            ans.append(money)

    print(min(ans))


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline


def main():
    n, m, x = map(int, input().split())
    lst = [[int(i) for i in input().split()] for _ in range(n)]

    ans = []
    for i in range(1 << n):
        understand = []
        money = 0
        for j in range(n):
            if (i >> j) & 1 == 0:
                continue
            money += lst[0]
            for k in range(m):
                understand[k] += lst[k + 1]
        if all([i >= x for i in understand]):
            ans.append(money)

    print(min(ans))


if __name__ == '__main__':
    main()
Problem p02686 (python)

Fixed submission:
def count_scan(s):
    max_min = 0
    compare = 0
    for c in s:
        if c == '(':
            compare += 1
        elif c == ')':
            compare -= 1
            max_min = min(max_min, compare)
    return min(max_min, compare), compare
 
 
def key(lst):
    m, c = lst
    if c > 0:
        return 1, m
    else:
        return -1, c - m
 
 
def main():
    n = int(input())
    lst = [input() for _ in range(n)]
 
    txt = 'No'
    ans = 0
    for max_min, c in sorted([count_scan(s) for s in lst],
                             reverse=True,
                             key=key):
        if max_min + ans < 0:
            break
        ans += c
    else:
        if ans == 0:
            txt = 'Yes'
 
    print(txt)
  
if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):

up_list = []
down_list = []

for _ in range(n):
    txt = input()
    min_comp = 10 ** 6
    compare = 0
    cnt = 0
    for s in txt:
        cnt += 1
        if s == '(':
            compare += 1
        else:
            compare -= 1
            min_comp = min(min_comp, compare)
    if compare > 0:
        up_list.append([compare, min(min_comp, 0)])
    else:
        down_list.append([compare, min(min_comp, 0) - compare])


up_list.sort(key=lambda x: x[1], reverse=True)
down_list.sort(key=lambda x: x[1], reverse=False)
txt = 'No'
c = 0

for t in up_list + down_list:
    if t[1] + c < 0:
        break
    else:
        c += t[0]
else:
    if c == 0:
        txt = 'Yes'

print(txt)
Problem p02692 (python)

Fixed submission:
def abc(d, down_text, up_text):
    d[down_text] -= 1
    d[up_text] += 1


def main():
    n, a, b, c = map(int, input().split())
    ans_list = []
    dct = {"A": a, "B": b, "C": c}

    abc_list = [input() for _ in range(n)]
    abc_list.append('AB')

    for i in range(n):
        # a_txt = input()
        l_txt = abc_list[i][0]
        r_txt = abc_list[i][1]

        if dct[l_txt] < dct[r_txt]:
            abc(dct, r_txt, l_txt)
            ans_list.append(l_txt)

        elif dct[l_txt] > dct[r_txt]:
            abc(dct, l_txt, r_txt)
            ans_list.append(r_txt)

        else:
            if dct[l_txt] == dct[r_txt] == 0:
                print('No')
                break
            else:
                if l_txt in abc_list[i + 1]:
                    abc(dct, r_txt, l_txt)
                    ans_list.append(l_txt)
                elif r_txt in abc_list[i + 1]:
                    abc(dct, l_txt, r_txt)
                    ans_list.append(r_txt)
    else:
        print('Yes')
        print(*ans_list, sep='\n')


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
def abc(d, down_text, up_text):
    d[down_text] -= 1
    d[up_text] += 1


def main():
    n, a, b, c = map(int, input().split())
    ans_list = []
    dct = {"A": a, "B": b, "C": c}

    b_txt = input()
    if dct[b_txt[0]] == dct[b_txt[1]]:
        print('No')
        exit()

    for _ in range(n - 1):
        a_txt = input()
        l_txt = b_txt[0]
        r_txt = b_txt[1]

        if dct[l_txt] < dct[r_txt]:
            abc(dct, r_txt, l_txt)
            ans_list.append(l_txt)

        elif dct[l_txt] > dct[r_txt]:
            abc(dct, l_txt, r_txt)
            ans_list.append(r_txt)

        else:
            if dct[l_txt] == dct[r_txt] == 0:
                print('No')
                break
            else:
                if l_txt in a_txt:
                    abc(dct, r_txt, l_txt)
                    ans_list.append(l_txt)
                else:
                    abc(dct, l_txt, r_txt)
                    ans_list.append(r_txt)
        b_txt = a_txt
    else:
        if dct[a_txt[0]] == dct[a_txt[1]] == 0:
            print('No')
            exit()
        elif dct[a_txt[0]] < dct[a_txt[1]]:
            ans_list.append(a_txt[0])
        else:
            ans_list.append(a_txt[1])
        print('Yes')
        print(*ans_list, sep='\n')


if __name__ == "__main__":
    main()
Problem p02697 (python)

Fixed submission:
def main():
    n, m = map(int, input().split())
    left = 1
    right = n
    is_shift = False
    ans = []
    while left < right:
        if right - left <= n // 2 and not is_shift and n % 2 == 0:
            left += 1
            is_shift = True
        ans.append([left, right])
        left += 1
        right -= 1

    for l in range(m):
        print(*ans[l])


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
def main():
    n, m = map(int, input().split())
    left = 1
    right = n
    is_shift = False
    ans = []
    while left < right:
        if right - left <= n // 2 and not is_shift:
            left += 1
        ans.append([left, right])
        left += 1
        right -= 1

    for l in range(m):
        print(*ans[l])


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
def main():
    n, m = map(int, input().split())
    left = 1
    right = n
    is_shift = False
    ans = []
    while left < right:
        if right - left <= n // 2 and not is_shift:
            left += 1
        ans.append([left, right])
        left += 1
        right -= 1

    print(f"{ans = }")
    for l in range(m):
        print(*ans[l])


if __name__ == "__main__":
    main()
Problem p02702 (python)

Fixed submission:
from collections import Counter
s = input()
MOD = 2019

s_len = len(s)
ref = [0] * s_len

for i in range(1, s_len + 1):
    ref[-i] = int(s[-i]) * pow(10, i, MOD) % MOD

for i in range(1, s_len):
    ref[-i - 1] += ref[-i]
    ref[-i - 1] %= MOD

ref_cnt = Counter(ref)
ans = sum(ref_cnt.values()) - len(ref_cnt)


for i in ref_cnt.values():
    ans += (i - 1) * (i - 2) // 2

if 0 in ref:
    ans += ref_cnt[0]

print(ans)

Buggy submission (verdict: Runtime Error):
s_len = len(s)
ref = [0] * s_len

for i in range(1, s_len + 1):
    ref[-i] = int(s[-i]) * pow(10, i, MOD) % MOD

for i in range(1, s_len):
    ref[-i - 1] += ref[-i]
    ref[-i - 1] %= MOD

ref_cnt = Counter(ref)
ans = sum(ref_cnt.values()) - len(ref_cnt)


for i in ref_cnt.values():
    ans += (i - 1) * (i - 2) // 2

if 0 in ref:
    ans += ref_cnt[0]

print(ans)
Problem p02706 (python)

Fixed submission:
n, m = map(int, input().split())
a = list(int(i) for i in input().split())

all_homework_day = sum(a)

if all_homework_day <= n:
    play_day = n - all_homework_day
else:
    play_day = -1

print(play_day)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
a = list(i for i in input().suplt)

all_homework_day = sum(a)

if all_homework_day <= n:
    play_day = all_homework_day
else:
    play_day = -1

print(play_day)
Problem p02732 (python)

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

# a_set = sorted(set(a))

count = [0] * (n + 1)


def f(n):
    return (n * (n - 1) // 2)


sum = 0
for i in a:
    count[i] += 1
for i in count:
    sum += f(i)

for i in a:
    print(sum - (count[i] - 1))

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

a_set = sorted(set(a))

count = [0] * n


def f(n):
    return (n * (n - 1) // 2)


sum = 0
for i in a_set:
    count[i] = a.count(i)
    sum += f(count[i])

for i in a:
    print(sum - (count[i] - 1))
Problem p02756 (python)

Fixed submission:
from collections import deque

s = deque(list(input()))
q = int(input())

rev = True

for i in range(q):
    q = list(input().split())
    if(int(q[0]) == 1):
        rev = rev ^ True
    else:
        n = int(q[1])
        if((n == 1 and rev) or (n == 2 and not rev)):
            s.appendleft(q[2])
        else:
            s.append(q[2])


txt = ''
if rev:
    txt = ''.join(s)
else:
    while not(not s):
        txt += s.pop()

print(txt)

Buggy submission (verdict: Runtime Error):
from collections import deque

s = deque(list(input()))
q = int(input())

rev = True

for i in range(q):
    q = list(input().split())
    if(int(q[0]) == 1):
        rev = rev ^ True
    else:
        n = int(q[1])
        if((n == 1 and rev) or (n == 2 and not rev)):
            s.appendleft(q[2])
        else:
            s.append(q[2])

if not rev:
    s = s[::-1]

print(''.join(s))

Buggy submission (verdict: Runtime Error):
from collections import deque

s = deque(list(input()))
q = int(input())

rev = True

for i in range(q):
    q = list(input().split())
    if(int(q[0]) == 1):
        rev = rev ^ True
    else:
        n = int(q[1])
        if((n == 1 and rev) or (n == 2 and not rev)):
            s.appendleft(0, q[2])
        else:
            s.append(q[2])

if not rev:
    s = s[::-1]

print(''.join(s))
Problem p02765 (python)

Fixed submission:
N, R = input().split()

if(int(N) >= 10):
    print(R)
else:
    print(int(R) + 100 * (10 - int(N)))

Buggy submission (verdict: Runtime Error):
if(int(N) >= 10):
    print(R)
else:
    print(int(R) + 100 * (10 - int(N)))
Problem p02767 (python)

Fixed submission:
N = int(input())
X = list(int(x) for x in input().split())
N_sum_HP = []


for p in range(min(X), max(X) + 1):
    sum_HP = 0
    for x in X:
        sum_HP += (x - p) ** 2
    N_sum_HP.append(sum_HP)
print(min(N_sum_HP))

Buggy submission (verdict: Runtime Error):
N = int(input())
X = list(int(x) for x in input().split())
N_sum_HP = []

for p in range(min(X), max(X)):
    sum_HP = 0
    for i in range(N):
        sum_HP += (X[i] - p) ** 2
    N_sum_HP.append(sum_HP)

print(min(N_sum_HP))