Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
from collections import Counter

cnt = Counter(a)
b = set(a)
c = 0
for i in b:
    c += cnt[i]*(cnt[i]-1)//2

for i in a:
    print(c-cnt[i]+1)

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

from collections import Counter

cnt = Counter(a)
b = set(a)
c = 0
for i in b:
    c += cnt[i]*(cnt[i]-1)//2

for i in a:
    print(c-cnt[i]+1)

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

from collections import Counter

cnt = Counter(a)
b = set(a)

for i in range(n):
    ans = 0
    for j in b:
        if j == a[i]:
            c = cnt[j]-1
            ans += c*(c-1)//2
        else:
            c =cnt[j]
            ans += c*(c-1)//2
    print(ans)


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

from collections import Counter

cnt = Counter(a)
b = set(a)
c = 0
for i in b:
    c += cnt[i]*(cnt[i]-1)//2

for i in a:
    print(c-cnt[i]+1)
Buggy python submission (verdict: Runtime Error):
s = input()
q = int(input())

rev = 0
head = []
tail = []

for i in range(q):
    t = input().split()
    if t[0] == "1":
        rev ^= 1
    else:
        if (int(t[1])-1)^rev == 0:
            head.append(t[2])
        else:
            tail.append(t[2])

h = "".join(head)
t = "".join(tail)

if rev == 0:
    s = s[::-1]
    print(h[::-1] + s + t)
else:
    print(t[::-1] + s + h)

Fixed submission:
s = input()

if "A" in s and "B" in s:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Time Limit Exceeded):
import collections
s = collections.deque(input())
q = int(input())

rev = 1

for i in range(q):
    t = tuple(input().split())
    if t[0] == "1":
        rev *= -1
    elif t[1] == "1":
        if rev == 1:
            s.appendleft(t[2])
        else:
            s.append(t[2])
    else:
        if rev == 1:
            s.append(t[2])
        else:
            s.appendleft(t[2])

if rev != 1:
    s.reverse()

ans = ""

for i in range(len(s)):
    ans += s.popleft()

print(ans)

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

rev = 0
head = []
tail = []

for i in range(q):
    t = input().split()
    if t[0] == "1":
        rev ^= 1
    else:
        if (int(t[1])-1)^rev == 0:
            head.append(t[2])
        else:
            tail.append(t[2])

h = "".join(head)
t = "".join(tail)

if rev == 0:
    print(h[::-1] + s + t)
else:
    s = s[::-1]
    print(t[::-1] + s + h)

Buggy python submission (verdict: Time Limit Exceeded):
import collections
s = collections.deque(input())
q = int(input())

for i in range(q):
    t = tuple(input().split())
    if t[0] == "1":
        s.reverse()
    elif t[1] == "1":
        s.appendleft(t[2])
    else:
        s.append(t[2])

ans = ""

for i in range(len(s)):
    ans += s.popleft()

print(ans)

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

rev = 0
head = []
tail = []

for i in range(q):
    t = input().split()
    if t[0] == "1":
        rev ^= 1
    else:
        if (int(t[1])-1)^rev == 0:
            head.append(t[2])
        else:
            tail.append(t[2])

h = "".join(head)
t = "".join(tail)

if rev == 0:
    print(h[::-1] + s + t)
else:
    s = s[::-1]
    print(t[::-1] + s + h)

Buggy python submission (verdict: Time Limit Exceeded):
import collections
s = collections.deque(input())
q = int(input())

for i in range(q):
    t = tuple(input().split())
    if t[0] == "1":
        s.reverse()
    elif t[1] == "1":
        s.appendleft(t[2])
    else:
        s.append(t[2])

ans = ""

for i in s:
    ans += i

print(ans)

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

rev = 0
head = []
tail = []

for i in range(q):
    t = input().split()
    if t[0] == "1":
        rev ^= 1
    else:
        if (int(t[1])-1)^rev == 0:
            head.append(t[2])
        else:
            tail.append(t[2])

h = "".join(head)
t = "".join(tail)

if rev == 0:
    print(h[::-1] + s + t)
else:
    s = s[::-1]
    print(t[::-1] + s + h)

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

for i in range(q):
    t = list(input().split())
    if t[0] == "1":
        s = s[::-1]
    elif t[1] == "1":
        s = t[2] + s
    else:
        s += t[2]
print(s)

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

rev = 0
head = []
tail = []

for i in range(q):
    t = input().split()
    if t[0] == "1":
        rev ^= 1
    else:
        if (int(t[1])-1)^rev == 0:
            head.append(t[2])
        else:
            tail.append(t[2])

h = "".join(head)
t = "".join(tail)

if rev == 0:
    print(h[::-1] + s + t)
else:
    s = s[::-1]
    print(t[::-1] + s + h)
Buggy python submission (verdict: Runtime Error):
x = int(input())
if x == 2:
    print(2)
    sys.exit()
elif x%2 == 0:
    x += 1

def get_prime(n):
    p = [2]
    for i in range(3, n, 2):
        if all(i%j!=0 for j in p):
            p.append(i)
    return p

p = get_prime(x)

while True:
    for prime in p:
        if x%prime == 0:
            break
    else:
        print(x)
        break
    x += 2


Fixed submission:
x = int(input())

def get_prime(n):
    p = [2]
    for i in range(3, n, 2):
        if all(i%j!=0 for j in p):
            p.append(i)
    return p

p = get_prime(x)

if x == 2:
    print(2)
else:
    if x%2 == 0:
        x += 1
    while True:
        for prime in p:
            if x%prime == 0:
                break
        else:
            print(x)
            break
        x += 2
Buggy python submission (verdict: Runtime Error):
import itertools

n = int(input())

l = list(itertools.product([0,1], repeat=n))[::-1]

A = {}
for i in range(n):
    ai = int(input())
    for j in range(ai):
        x, y = map(int, input().split())
        if i not in A:
            A[i] = []
        A[i].append((x, y))

def shoujiki(i):
    check = {}
    cnt = 0
    for j in range(n):
        check[j+1] = i[j]
    for j in range(n):
        ai = len(A[j])
        if i[j] == 1:
            for k in range(ai):
                x, y = A[j][k]
                if check[x] == y:
                    cnt += 1
                else:
                    return 0
    return cnt

mans = 0
for i in l:
    mans = max(shoujiki(i), mans)

print(mans)


Fixed submission:
import itertools

n = int(input())

l = list(itertools.product([0,1], repeat=n))[::-1]

A = {}
for i in range(n):
    ai = int(input())
    for j in range(ai):
        x, y = map(int, input().split())
        if i not in A:
            A[i] = []
        A[i].append((x, y))
    if ai == 0:
        A[i] = []


def shoujiki(i):
    check = {}
    cnt = 0
    for j in range(n):
        check[j+1] = i[j]
    for j in range(n):
        ai = len(A[j])
        if i[j] == 1:
            for k in range(ai):
                x, y = A[j][k]
                if check[x] != y:
                    return 0
    #return (check, shougen, cnt0, cnt)
    return sum(i)

mans = 0
for i in l:
    mans = max(shoujiki(i), mans)

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

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

g = a[0]

for i in range(1,n):
    g = math.gcd(g,a[i])

print(g)

Fixed submission:
from fractions import gcd

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

g = a[0]

for i in range(1,n):
    g = gcd(g,a[i])

print(g)

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

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

g = a[0]

for i in range(1,n):
    g = math.gcd(g,a[i])

print(g)

Fixed submission:
from fractions import gcd

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

g = a[0]

for i in range(1,n):
    g = gcd(g,a[i])

print(g)
Buggy python submission (verdict: Runtime Error):
a, b, k = map(int, input().split())
r = range(a,b+1)
l = list(r)


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

l = [i for i in range(a, b+1) if (i < a+k) or (i > b-k)]

print(*l, sep="\n", end="")

Buggy python submission (verdict: Runtime Error):
a, b, k = map(int, input().split())
r = range(a,b+1)
l = list(r)
ans = sorted(set(l[:k] + l[len(l)-k:]))

print(*ans, sep = "\n", end = "")

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

l = [i for i in range(a, b+1) if (i < a+k) or (i > b-k)]

print(*l, sep="\n", end="")

Buggy python submission (verdict: Runtime Error):
a, b, k = map(int, input().split())
l = list(range(a,b+1))


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

l = [i for i in range(a, b+1) if (i < a+k) or (i > b-k)]

print(*l, sep="\n", end="")

Buggy python submission (verdict: Runtime Error):
a, b, k = map(int, input().split())
l = list(range(a,b+1))
ans = sorted(set(l[:k] + l[len(l)-k:]))

print(*ans, sep = "\n", end = "")

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

l = [i for i in range(a, b+1) if (i < a+k) or (i > b-k)]

print(*l, sep="\n", end="")

Buggy python submission (verdict: Runtime Error):
a, b, k = map(int, input().split())
l = list(range(a,b+1))

ans = sorted(set(l[:k] + l[len(l)-k:]))

for i in ans:
    print(i)

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

l = [i for i in range(a, b+1) if (i < a+k) or (i > b-k)]

print(*l, sep="\n", end="")

Buggy python submission (verdict: Runtime Error):
a, b, k = map(int, input().split())
l = list(range(a,b+1))

ans = sorted(set(l[:k] + l[len(l)-k:]))

for i in ans:
    print(i)

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

l = [i for i in range(a, b+1) if (i < a+k) or (i > b-k)]

print(*l, sep="\n", end="")

Buggy python submission (verdict: Runtime Error):
s = list(map(int, input().split()))
l = list(range(s[0],s[1]+1))

ans = sorted(set(l[:s[2]] + l[len(l)-s[2]:]))

for i in ans:
    print(i)

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

l = [i for i in range(a, b+1) if (i < a+k) or (i > b-k)]

print(*l, sep="\n", end="")

Buggy python submission (verdict: Runtime Error):
s = list(map(int, input().split()))
l = list(range(s[0],s[1]+1))

ans = set(l[:s[2]] + l[len(l)-s[2]:])

for i in ans:
    print(i)

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

l = [i for i in range(a, b+1) if (i < a+k) or (i > b-k)]

print(*l, sep="\n", end="")
Buggy python submission (verdict: Runtime Error):
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "1\n",
      "1\n",
      "1\n",
      "0\n"
     ]
    }
   ],
   "source": [
    "A = int(input())\n",
    "B = int(input())\n",
    "C = int(input())\n",
    "X = int(input())\n",
    "res=0\n",
    "for  i in range(A + 1):\n",
    "    for j in range(B + 1):\n",
    "        for k in range(C + 1):\n",
    "            if 500*i + 100*j + 50*k == X:\n",
    "                res += 1\n",
    "print(res)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}


Fixed submission:
a = int(input())
b = int(input())
c = int(input())
x = int(input())
cnt = 0

for i in range(c+1):
    for j in range(b+1):
        if (x-50*i-100*j)%500==0 and ((x-50*i-100*j)/500)<=a and ((x-50*i-100*j)/500)>=0:
            cnt += 1

print(cnt)
Buggy python submission (verdict: Runtime Error):
a, b = map(int, input().split())
if a*B % 2 == 0:
  print("Even")
else:
  print("Odd")


Fixed submission:
a, b = map(int, input().split())
if a*b % 2 == 0:
  print("Even")
else:
  print("Odd")

Buggy python submission (verdict: Runtime Error):
a,b = map(int, input().split())
if (a*B)%2==0:
  print("Even")
else:
  print("Odd")

Fixed submission:
a, b = map(int, input().split())
if a*b % 2 == 0:
  print("Even")
else:
  print("Odd")

Buggy python submission (verdict: Runtime Error):
a,b = int(input())
c = a*B
if c%2==0:
  print("Even")
else:
  print("Odd")

Fixed submission:
a, b = map(int, input().split())
if a*b % 2 == 0:
  print("Even")
else:
  print("Odd")

Buggy python submission (verdict: Runtime Error):
print(b)


Fixed submission:
a, b = map(int, input().split())
if a*b % 2 == 0:
  print("Even")
else:
  print("Odd")

Buggy python submission (verdict: Runtime Error):
print(a)


Fixed submission:
a, b = map(int, input().split())
if a*b % 2 == 0:
  print("Even")
else:
  print("Odd")
Buggy python submission (verdict: Time Limit Exceeded):
k, s = map(int, input().split())
cnt = 0
for x in range(k+1):
    for y in range(k+1):
        for z in range(k+1):
            if x+y==s-z:
                cnt += 1
                break
print(cnt)

Fixed submission:
k, s = map(int, input().split())
cnt = 0
for x in range(k+1):
    for y in range(k+1):
        if 0 <= s-x-y <= k:
            cnt += 1
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
k, s = map(int, input().split())
cnt = 0
for x in range(k+1):
    for y in range(k+1):
        for z in range(k+1):
            if x+y+z==s:
                cnt += 1
print(cnt)

Fixed submission:
k, s = map(int, input().split())
cnt = 0
for x in range(k+1):
    for y in range(k+1):
        if 0 <= s-x-y <= k:
            cnt += 1
print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
h = list(map(int, input().split()))
dp = [10 ** 9] * n
dp[0] = 0
for i in range(1, n):
    for j in range(max(i - k, 0), i):
        dp[i] = min(dp[i], dp[j] + abs(h[i] - h[j]))
print(dp[-1])

Fixed submission:
n, k = map(int, input().split())
h = list(map(int, input().split()))
dp = [10 ** 9] * n
dp[0] = 0
for i in range(1, n):
    for j in range(max(i - k, 0), i):
        dp[i] = min(dp[i], dp[j] + abs(h[i] - h[j]))
print(dp[-1])
Buggy python submission (verdict: Runtime Error):
import math

n, k = map(int, input().split())
x, y, c = zip(*[map(int, input().split()) for _ in range(n)])
que = [(0, 0, 1000)]
res = 1e9
i = 0
while i < len(que):
    px, py, r = que[i]
    i += 1
    lb = [c[j] * math.hypot(max(abs(px - x[j]) - r, 0), max(abs(py - y[j]) - r, 0)) for j in range(n)]
    if 1 - sorted(lb)[k - 1] / res > 5e-7:
        dis = [c[j] * math.hypot(px - x[j], py - y[j]) for j in range(n)]
        res = min(res, sorted(dis)[k - 1])
        for dx in (-0.5, 0.5):
            for dy in (-0.5, 0.5):
                que.append((px + dx * r, py + dy * r, r / 2))
print(res)

Fixed submission:
import math

n, k = map(int, input().split())
x, y, c = zip(*[map(int, input().split()) for _ in range(n)])
que = [(0, 0, 1000)]
res = 1e9
i = 0
while i < len(que):
    px, py, r = que[i]
    i += 1
    lb = [c[j] * math.hypot(max(abs(px - x[j]) - r, 0), max(abs(py - y[j]) - r, 0)) for j in range(n)]
    if res * (1 - 5e-7) > sorted(lb)[k - 1]:
        dis = [c[j] * math.hypot(px - x[j], py - y[j]) for j in range(n)]
        res = min(res, sorted(dis)[k - 1])
        for dx in (-0.5, 0.5):
            for dy in (-0.5, 0.5):
                que.append((px + dx * r, py + dy * r, r / 2))
print(res)
Buggy python submission (verdict: Runtime Error):
import sys


def main():
    n, m = map(int, sys.stdin.readline().split())
    g = [[] for i in range(n)]
    for i in range(m):
        l, r, d = map(int, sys.stdin.readline().split())
        g[l - 1].append((r - 1, d))
        g[r - 1].append((l - 1, -d))
    dis = [0] * n
    visited = [False] * n
    for i in range(n):
        if visited[i]:
            continue
        stack = list([i])
        visited[i] = True
        while len(stack):
            v = stack[-1]
            stack.pop()
            for u, d in g[v]:
                if not visited[u]:
                    dis[u] = dis[v] + d
                    stack.append(u)
                    visited[u] = True
    for v in range(n):
        for u, d in g[v]:
            if dis[v] + d != dis[u]:
                print('No')
                return
    print('Yes')


if __name__ == '__main__':
    main()


Fixed submission:
x = int(input())
a = int(input())
b = int(input())

print((x - a) % b)

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


def main():
    n, m = map(int, input().split())
    g = [[] for i in range(n)]
    lines = sys.stdin.read().splitlines()
    for i in range(m):
        l, r, d = map(int, lines[i].split())
        g[l - 1].append((r - 1, d))
        g[r - 1].append((l - 1, -d))
    dis = [0] * n
    visited = [False] * n
    for i in range(n):
        if visited[i]:
            continue
        stack = list([i])
        visited[i] = True
        while len(stack):
            v = stack[-1]
            stack.pop()
            for u, d in g[v]:
                if not visited[u]:
                    dis[u] = dis[v] + d
                    stack.append(u)
                    visited[u] = True
    for v in range(n):
        for u, d in g[v]:
            if dis[v] + d != dis[u]:
                print('No')
                return
    print('Yes')


if __name__ == '__main__':
    main()


Fixed submission:
x = int(input())
a = int(input())
b = int(input())

print((x - a) % b)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
f = [1] * (n + 1)
for i in range(2, n + 1):
    for j in range(i, n + 1, i):
        f[j] += 1
ans = 0
for i in range(1, n + 1):
    ans += i * f[i]
print(ans)


Fixed submission:
n = int(input())
f = [1] * (n + 1)
for i in range(2, n + 1):
    for j in range(i, n + 1, i):
        f[j] += 1
ans = 0
for i in range(1, n + 1):
    ans += i * f[i]
print(ans)
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3
n = int(input())
a = list(map(int, input().split()))
if n < 30 and a[-1] > (1 << n):
    print(-1)
    exit()
for i in range(min(n, 30)):
    if a[i] > (1 << i) - 1:
        print(-1)
        exit()
s = sum(a)
ans = 1
dp = [0] * n
dp[0] = 1
for i in range(1, n):
    dp[i] = min(s, 2 * dp[i - 1])
    ans += dp[i]
    dp[i] -= a[i]
    if dp[i] < 0:
        print(-1)
        exit()
    s -= a[i]
ans += a[-1]
print(ans)


Fixed submission:
#!/usr/bin/env python3
n = int(input())
a = list(map(int, input().split()))
if n == 0:
    print([-1, 1][a[0] == 1])
    exit()
if a[0] > 0:
    print(-1)
    exit()
s = sum(a)
ans = 1
dp = [0] * (n + 1)
dp[0] = 1
for i in range(n):
    dp[i + 1] = min(s, 2 * dp[i])
    ans += dp[i + 1]
    dp[i + 1] -= a[i + 1]
    s -= a[i + 1]
    if dp[i] <= 0:
        print(-1)
        exit()
if dp[-1] < 0:
    print(-1)
    exit()
print(ans)

Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3
n = int(input())
a = list(map(int, input().split()))
if a[-1] > (1 << n):
    print(-1)
    exit()
for i in range(min(n, 30)):
    if a[i] > (1 << i) - 1:
        print(-1)
        exit()
s = sum(a)
ans = 1
dp = [0] * n
dp[0] = 1
for i in range(1, n):
    dp[i] = min(s, 2 * dp[i - 1])
    ans += dp[i]
    dp[i] -= a[i]
    s -= a[i]
ans += a[-1]
print(ans)


Fixed submission:
#!/usr/bin/env python3
n = int(input())
a = list(map(int, input().split()))
if n == 0:
    print([-1, 1][a[0] == 1])
    exit()
if a[0] > 0:
    print(-1)
    exit()
s = sum(a)
ans = 1
dp = [0] * (n + 1)
dp[0] = 1
for i in range(n):
    dp[i + 1] = min(s, 2 * dp[i])
    ans += dp[i + 1]
    dp[i + 1] -= a[i + 1]
    s -= a[i + 1]
    if dp[i] <= 0:
        print(-1)
        exit()
if dp[-1] < 0:
    print(-1)
    exit()
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
_=input()
while True:
  pass

Fixed submission:
#!/usr/bin/env python3
s, w = map(int, input().split())
print(['unsafe', 'safe'][s > w])
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3
n, k, c = map(int, input().split())
s = input()

if c == 0:
    if s.cnt("o") == k:
        print(*range(1, n + 1), sep="\n")
    exit()

left = []
i = 0
while i < n:
    if s[i] == "o":
        left.append(i)
        i += c
    i += 1

right = []
i = n - 1
while i >= 0:
    if s[i] == "o":
        right.append(i)
        i -= c
    i -= 1
right.reverse()
for i in range(len(left)):
    if left[i] == right[i]:
        print(left[i] + 1)


Fixed submission:
#!/usr/bin/env python3
n, k, c = map(int, input().split())
s = input()

if c == 0:
    if s.count("o") == k:
        for i in range(n):
            if s[i] == "o":
                print(i + 1)
    exit()

left = []
i = 0
while i < n:
    if s[i] == "o":
        left.append(i)
        i += c
    i += 1

right = []
i = n - 1
while i >= 0:
    if s[i] == "o":
        right.append(i)
        i -= c
    i -= 1
right.reverse()
for i in range(len(left)):
    if left[i] == right[i]:
        print(left[i] + 1)
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
s = input()
q = int(input())
li = ["", s]
cur = 1
for _ in range(q):
    query = input().split()
    if query[0] == "1":
        cur ^= 1
    else:
        f, c = query[1:]
        if f == "1":
            li[cur ^ 1] += c
        else:
            li[cur] += c
ans = li[0][::-1] + li[1]
if cur == 0:
    ans = ans[::-1]
print(ans)


Fixed submission:
#!/usr/bin/env python3
from collections import deque

s = input()
q = int(input())
deq = deque(s)
cur = 1
for _ in range(q):
    query = input().split()
    if query[0] == "1":
        cur ^= 1
    else:
        f, c = query[1:]
        f = int(f) - 1
        if cur ^ f:
            deq.appendleft(c)
        else:
            deq.append(c)
ans = ""
while len(deq) > 0:
    ans += deq.popleft() if cur else deq.pop()
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
s = input()
q = int(input())
li = ["", s]
cur = 1
for _ in range(q):
    query = input().split()
    if query[0] == "1":
        cur ^= 1
    else:
        f, c = query[1:]
        if f == "1":
            li[cur ^ 1] += c
        else:
            li[cur] += c
ans = li[0][::-1] + li[1]
if cur == 0:
    ans = ans[::-1]
print(ans)


Fixed submission:
#!/usr/bin/env python3
from collections import deque

s = input()
q = int(input())
deq = deque(s)
cur = 1
for _ in range(q):
    query = input().split()
    if query[0] == "1":
        cur ^= 1
    else:
        f, c = query[1:]
        f = int(f) - 1
        if cur ^ f:
            deq.appendleft(c)
        else:
            deq.append(c)
ans = ""
while len(deq) > 0:
    ans += deq.popleft() if cur else deq.pop()
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
a = [0] + list(map(int, list(input())))
n = len(a)
dp = [[10 ** 9] * 2 for _ in range(n + 1)]
dp[0][0] = 0
dp[0][1] = 1
for i in range(n):
    dp[i + 1][0] = min(dp[i][0] + a[i], dp[i][1] + 10 - a[i])
    dp[i + 1][1] = min(dp[i][0] + a[i] + 1, dp[i][1] + 10 - a[i] - 1)
print(dp[n][0])


Fixed submission:
#!/usr/bin/env python3
a = [0] + list(map(int, list(input())))
n = len(a)
dp = [[10 ** 9] * 2 for _ in range(n + 1)]
dp[0][0] = 0
dp[0][1] = 1
for i in range(n):
    dp[i + 1][0] = min(dp[i][0] + a[i], dp[i][1] + 10 - a[i])
    dp[i + 1][1] = min(dp[i][0] + a[i] + 1, dp[i][1] + 10 - a[i] - 1)
print(dp[n][0])
Buggy python submission (verdict: Time Limit Exceeded):
INF = 10**9
h, n = map(int, input().split())
a = [0] * n
b = [0] * n
for i in range(n):
    a[i], b[i] = map(int, input().split())
dp = [INF] * (h + 1)
dp[0] = 0
for i in range(n):
    for j in range(h + 1):
        m = min(h, j + a[i])
        dp[m] = min(dp[m], dp[j] + b[i])
print(dp[h])


Fixed submission:
INF = 10**9
h, n = map(int, input().split())
a = [0] * n
b = [0] * n
for i in range(n):
    a[i], b[i] = map(int, input().split())
dp = [INF] * (h + 1)
dp[0] = 0
for i in range(n):
    for j in range(h + 1):
        m = min(h, j + a[i])
        dp[m] = min(dp[m], dp[j] + b[i])
print(dp[h])