Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define inf 1001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define aint(x) (x).begin(),(x).end()
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << setprecision(15) << fixed;

  char c;
  cin >> c;
  cout << (islower(c) ? 'a' : 'A') << endl;
  
}


Fixed submission:
import sys
input = lambda: sys.stdin.readline().rstrip("\r\n")

a = input()
al = [chr(i) for i in range(97, 97+26)] # 英小文字
if a in al:
    print("a")
else:
    print("A")
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = lambda: sys.stdin.readline().rstrip()

n, k = map(int, input().split())
a = [int(x) for x in input().split()]
last = [n]*n
for i in range(k):
    temp = [0]*n
    min_a = 10**10
    for j in range(n):
        b = a[j]
        min_a = min(b, min_a)
        temp[j] += 1
        for k in range(1, b + 1):
            if j + k < n:
                temp[j + k] += 1
            if j - k >= 0:
                temp[j - k] += 1
    a = temp[:]
    if min_a == n:
        print(*a)
        sys.exit()
print(*a)


Fixed submission:
import sys
input = lambda: sys.stdin.readline().rstrip()

n, k = map(int, input().split())
a = [int(x) for x in input().split()]
from itertools import accumulate
for i in range(k):
    temp = [0]*(n + 1)
    for j in range(n):
        b = a[j]
        left = max(0, j - b)
        right = min(n - 1, j + b)
        temp[left] += 1
        temp[right + 1] -= 1
    a = list(accumulate(temp))[:n]
    if min(a) == n:
        print(*a)
        sys.exit()
print(*a)

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

n, k = map(int, input().split())
a = [int(x) for x in input().split()]
last = [n]*n
for i in range(k):
    temp = [0]*n
    for j in range(n):
        b = a[j]
        temp[j] += 1
        for k in range(1, b + 1):
            if j + k < n:
                temp[j + k] += 1
            if j - k >= 0:
                temp[j - k] += 1
    a = temp[:]
    if a == last:
        print(*a)
        sys.exit()
print(*a)


Fixed submission:
import sys
input = lambda: sys.stdin.readline().rstrip()

n, k = map(int, input().split())
a = [int(x) for x in input().split()]
from itertools import accumulate
for i in range(k):
    temp = [0]*(n + 1)
    for j in range(n):
        b = a[j]
        left = max(0, j - b)
        right = min(n - 1, j + b)
        temp[left] += 1
        temp[right + 1] -= 1
    a = list(accumulate(temp))[:n]
    if min(a) == n:
        print(*a)
        sys.exit()
print(*a)
Buggy python submission (verdict: Runtime Error):
import sys
input = lambda: sys.stdin.readline().rstrip()

n = int(input())
a = [int(x) for x in input().split()]

a.sort()

if a[0] == 0:
    print(0)
else:
    m = 1
    i = 0
    while m < 10**18:
        m *= a[i]
        if m > 10**18:
            print(-1)
            sys.exit()
        i += 1
        if i == n:
            print(m)

Fixed submission:
import sys
input = sys.stdin.readline
n = int(input())
a = [int(x) for x in input().split()]
ans = 1
if 0 in a:
    print(0)
    sys.exit()
for i in a:
    ans *= i
    if ans > 10**18:
        print(-1)
        sys.exit()
print(ans)

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

n = int(input())
a = [int(x) for x in input().split()]

a.sort()

if a[0] == 0:
    print(0)
else:
    m = 1
    i = 0
    while m < 10**18:
        m *= a[i]
        if m > 10**18:
            print(-1)
            sys.exit()
        i += 1
    print(m)

Fixed submission:
import sys
input = sys.stdin.readline
n = int(input())
a = [int(x) for x in input().split()]
ans = 1
if 0 in a:
    print(0)
    sys.exit()
for i in a:
    ans *= i
    if ans > 10**18:
        print(-1)
        sys.exit()
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
input = lambda: sys.stdin.readline().rstrip()

n = int(input())
s = []
for _ in range(n):
    s.append(input())

A = []

for i, j in enumerate(s):
    min_val = 10**10
    val = 0
   
    for k in j:
        if k == "(":
            val += 1
        else:
            val -= 1
        min_val = min(min_val, val)
    A.append([min_val, i])
A.sort()
A = A[::-1]
val = 0
for i, j in A:
    for k in list(s[j]):
        if k == "(":
            val += 1
        else:
            val -= 1
            if val < 0:
                print("No")
                sys.exit()
ans = "Yes" if val == 0 else "No"
print(ans)


Fixed submission:
import sys
input = sys.stdin.readline

s = input().rstrip()
t = input().rstrip()

if s == t[:len(t) - 1]:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

mod = 998244353

n, m, k = [int(x) for x in input().split()]

def make_tables(n, mod = 998244353):
    fac = [1, 1] # 階乗テーブル
    finv = [1, 1] #逆元の階乗テーブル
    inv = [0, 1] #逆元テーブル

    for i in range(2, n + 1):
        fac.append((fac[-1] * i) % mod)
        inv.append((mod -inv[mod % i] * (mod // i)) % mod)
        finv.append((finv[-1] * inv[-1]) % mod)
    return fac, finv

def nCk(n, k, mod = 998244353):
    k = min(k, n-k)
    return fac[n] * finv[k] * finv[n-k] % mod

fac, finv = make_tables(n)
cal = m
ans = 0
for i in range(n - 1 - k):
    cal *= m - 1
    cal %= mod
ans += cal * nCk(n - 1, k)
ans %= mod
for i in range(1, k + 1):
    cal *= (m - 1)
    ans += cal * nCk(n - 1, k - i)
    ans %= mod
print(ans)


Fixed submission:
import sys
input = sys.stdin.readline

mod = 998244353

n, m, k = [int(x) for x in input().split()]

def make_tables(n, mod = 998244353):
    fac = [1, 1] # 階乗テーブル
    finv = [1, 1] #逆元の階乗テーブル
    inv = [0, 1] #逆元テーブル

    for i in range(2, n + 1):
        fac.append((fac[-1] * i) % mod)
        inv.append((mod -inv[mod % i] * (mod // i)) % mod)
        finv.append((finv[-1] * inv[-1]) % mod)
    return fac, finv

def nCk(n, k, mod = 998244353):
    k = min(k, n-k)
    return fac[n] * finv[k] * finv[n-k] % mod

fac, finv = make_tables(n)
cal = m
ans = 0
for i in range(n - 1 - k):
    cal *= m - 1
    cal %= mod
ans += cal * nCk(n - 1, k)
ans %= mod
for i in range(1, k + 1):
    cal *= (m - 1)
    cal %= mod
    ans += cal * nCk(n - 1, k - i)
    ans %= mod
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = lambda: sys.stdin.readline().rstrip()
 
x=int(input())
a=1
while True:
    for b in range(a + 1):
        if a**5+b**5==x:
            print(a,-b)
            sys.exit()
        elif a**5-b**5==x:
            print(a,b)
            sys.exit()
        else:
            a+=1



Fixed submission:
import sys
input = sys.stdin.readline

x = int(input())
a = 1
while True:
    for b in range(0, a):
        if a**5 - b**5 == x:
            print(a, b)
            sys.exit()
        if a**5 + b**5 == x:
            print(a, -b)
            sys.exit()
    a += 1
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

n, m, q = [int(x) for x in input().split()]
abcd = [[int(x) for x in input().split()] for _ in range(q)]
all_pattern = []
start = '1'
def dfs(s):
    last_s = int(s[-1])
    next_s = [str(x) for x in range(last_s, m + 1)]
    for i in next_s:
        t = s + i
        if len(t) == n + 1:
            all_pattern.append(t[1:])
        else:
            dfs(t)
dfs(start)
ans = 0
for pattern in all_pattern:
    res = 0
    for i in range(q):
        a, b, c, d = abcd[i]
        if int(pattern[b - 1]) - int(pattern[a - 1]) == c:
            res += d
    ans = max(ans, res)
print(ans)

    





Fixed submission:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

n, m, q = [int(x) for x in input().split()]
abcd = [[int(x) for x in input().split()] for _ in range(q)]
all_pattern = []
start = ['1']

def dfs(s):
    last_s = int(s[-1])
    next_s = [str(x) for x in range(last_s, m + 1)]
    for i in next_s:
        t = s[:]
        t.append(i)
        if len(t) == n + 1:
            all_pattern.append(t[1:])
        else:
            dfs(t)
dfs(start)
ans = 0
for pattern in all_pattern:
    res = 0
    for i in range(q):
        a, b, c, d = abcd[i]
        if int(pattern[b - 1]) - int(pattern[a - 1]) == c:
            res += d
    ans = max(ans, res)
#print(all_pattern)
print(ans)

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

n, m, q = [int(x) for x in input().split()]
abcd = [[int(x) for x in input().split()] for _ in range(q)]
all_pattern = []
start = '1'
def dfs(s):
    last_s = int(s[-1])
    next_s = [str(x) for x in range(last_s, m + 1)]
    for i in next_s:
        t = s + i
        if len(t) == n + 1:
            all_pattern.append(t[1:])
        else:
            dfs(t)
dfs(start)
ans = 0
for pattern in all_pattern:
    res = 0
    for i in range(q):
        a, b, c, d = abcd[i]
        if int(pattern[b - 1]) - int(pattern[a - 1]) == c:
            res += d
    ans = max(ans, res)
print(ans)

    





Fixed submission:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

n, m, q = [int(x) for x in input().split()]
abcd = [[int(x) for x in input().split()] for _ in range(q)]
all_pattern = []
start = ['1']

def dfs(s):
    last_s = int(s[-1])
    next_s = [str(x) for x in range(last_s, m + 1)]
    for i in next_s:
        t = s[:]
        t.append(i)
        if len(t) == n + 1:
            all_pattern.append(t[1:])
        else:
            dfs(t)
dfs(start)
ans = 0
for pattern in all_pattern:
    res = 0
    for i in range(q):
        a, b, c, d = abcd[i]
        if int(pattern[b - 1]) - int(pattern[a - 1]) == c:
            res += d
    ans = max(ans, res)
#print(all_pattern)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

a, b, n = [int(x) for x in input().split()]

i = 0
ans = 0
flag = 0

while i <= n:
    x = (a*i//b) - (a*(i//b))
    if x > 0:
        flag = 1
    if flag and x == 0:
        print(ans)
        sys.exit()
    ans = max(ans, x)
    i += 1
print(ans)

Fixed submission:
import sys
input = sys.stdin.readline

a, b, n = [int(x) for x in input().split()]

if n >= b - 1:
    print((a*(b - 1)//b) - (a*((b - 1)//b)))
else:
    print((a*n//b) - (a*(n//b)))
Buggy python submission (verdict: Runtime Error):
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i = 0; i < (ll)(n); i++)
#define inf 1001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(x) (x).begin(),(x).end()
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << setprecision(15) << fixed;

  ll n; cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];

  map<tuple<ll, ll, ll>, ll> dp;
  dp[{0, 0, 0}] = 0;

  for (ll i = 1; i < n + 1; i++) {
    ll maxj = (i % 2 == 0)? i/2 : i/2 + 1;
    ll minj = ((n - 1) % 2 == 0)? n/2 - (n - i)/2 : n/2 - ((n - i)/2 + 1);
    for (ll j = minj; j < maxj + 1; j++) {
      dp[{i, j, 0}] = -inf;
      if (dp.count(make_tuple(i - 1, j, 0))) chmax(dp[{i, j, 0}], dp[{i - 1, j, 0}]);
      if (dp.count(make_tuple(i - 1, j, 1))) chmax(dp[{i, j, 0}], dp[{i - 1, j, 1}]);
      dp[{i, j, 1}] = -inf;
      if (dp.count(make_tuple(i - 1, j - 1, 0))) chmax(dp[{i, j, 1}], dp[{i - 1, j - 1, 0}] + a[i - 1]);
    }
  }
  cout << max(dp[{n, n/2, 0}], dp[{n, n/2, 1}]) << endl;
}


Fixed submission:
import sys
input = lambda: sys.stdin.readline().rstrip("\r\n")

def solve():
    n = int(input())
    a = [int(x) for x in input().split()]

    from collections import defaultdict

    dp = defaultdict(lambda : -float('inf'))
    dp[(0, 0, 0)] = 0

    for i in range(1, n + 1):
        max_j = i//2 if i % 2 == 0 else i//2 + 1
        min_j = n//2 - (n - i)//2 if (n - i) % 2 == 0 else n//2 - ((n - i)//2 + 1)
        for j in range(min_j, max_j + 1):
            dp[(i, j, 0)] = max(dp[(i - 1, j, 0)], dp[(i - 1, j, 1)])
            dp[(i, j, 1)] = dp[(i - 1, j - 1, 0)] + a[i - 1]
    print(max(dp[(n, n//2, 0)], dp[(n, n//2, 1)]))
solve()
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

n, X, Y = [int(x) for x in input().split()]

ans = [0] * (n) # 1 ~ n - 1

g = [x for x in range(1, n + 1)]
g_2 = [x for x in range(1, n + 1)]
g_2[Y - 1] = X + 1
for i in range(Y, n):
    if i < n:
        g_2[i] -= (Y - X - 1)
# print(g)
# print(g_2)

for i in range(X):
    for j in range(i + 1, n):
        # print(g_2[j], g[i])
        b = min(g_2[j] - g[i], g[X - 1] - g[i] + g_2[Y - 1] - g[X - 1] + abs(g[Y - 1] - g[j]))
        ans[b] += 1

for i in range(X, n):
    for j in range(i + 1, n):
        # print(g[j], g[i])
        a = min(g[j] - g[i], g[i] - 2 * g[X - 1] + g_2[j])
        ans[a] += 1

for i in ans[1:]:
    print(i)


Fixed submission:
import sys
input = sys.stdin.readline

s = input().rstrip()

if s[2] == s[3] and s[4] == s[5]:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

n, x, y = [int(x) for x in input().split()]

edge = [[] for _ in range(n)]

for i in range(n - 1):
    edge[i].append([1, i + 1])
    edge[i + 1].append([1, i])

edge[x - 1].append([1, y - 1])
edge[y - 1].append([1, x - 1])

import heapq
def dijkstra_heap(s):
    #始点sから各頂点への最短距離
    d = [float("inf")] * n
    used = [True] * n #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for e in edge[s]:
        heapq.heappush(edgelist,e)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge[1]]:
            continue
        v = minedge[1]
        d[v] = minedge[0]
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,[e[0]+d[v],e[1]])
    return d

d = dijkstra_heap(0)
# print(d)

ans = [0] * (n)
# print(edge)
for i in range(n):
    d = dijkstra_heap(i)
    # print(d)
    for j in d:
        if j != float("inf"):
            ans[j] += 1

for i in range(n):
    ans[i] //= 2

for i in ans[1:]:
    print(i)

Fixed submission:
import sys
input = sys.stdin.readline

n, x, y = [int(x) for x in input().split()]

g = [[] for _ in range(n)]

for i in range(n - 1):
    g[i].append(i + 1)
    g[i + 1].append(i)

g[x - 1].append(y - 1)
g[y - 1].append(x - 1)

from collections import deque

def bfs(u):
    d = [-1]*n
    d[u] = 0
    queue = deque([u])
    while queue:
        v = queue.popleft()
        for i in g[v]:
            if d[i] < 0:
                d[i] = d[v] + 1
                queue.append(i)
    return d

ans = [0] * n

for i in range(n):
    d = bfs(i)
    for j in d:
        ans[j] += 1

for i in ans[1:]:
    print(i // 2)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

h, w, K = [int(x) for x in input().split()]
s = [input().rstrip() for _ in range(h)]

ans = h + w - 2
for i in range(2 ** (h - 1)):
    new_s = []
    cnt = 0
    i_bin = bin(i)[2:].zfill(h - 1)
    add = []
    for j in range(h - 1):
        if i_bin[j] == "1":
            cnt += 1
            add.append(s[j])
            new_s.append(add)
            add = []
        else:
            add.append(s[j])
        if j == h - 2:
            add.append(s[-1])
            new_s.append(add)
    if h == 1:
        new_s = [s]
    total = [0] * len(new_s) # ブロックごとに、切った後~進んだ分の増えたホワイトチョコの個数を管理
    for k in range(w):
        tmp_list = [0]*len(new_s) # ブロックごとに、1つ進めて増えるホワイトチョコを管理
        flag = 0
        for l in range(len(new_s)):
            tmp = sum([int(new_s[l][x][k]) for x in range(len(new_s[l]))])
            if tmp > K:
                flag = 1
                break
            tmp_list[l] = tmp
            total[l] += tmp
        if flag:
            break
        for m in total: # 1つでもKを越えていたら直前で切る
            if m > K:
                cnt += 1
                total = tmp_list
                break
    if not flag:
        ans = min(ans, cnt)
print(ans)






Fixed submission:
import sys
input = sys.stdin.readline

h, w, K = [int(x) for x in input().split()]
s = [input().rstrip() for _ in range(h)]
# print(s)
# print(len(s[1]))

# ans = h + w - 2
ans = h + w - 2
for i in range(2 ** (h - 1)):
    new_s = []
    cnt = 0
    i_bin = bin(i)[2:].zfill(h - 1)
    add = []
    for j in range(h - 1):
        if i_bin[j] == "1":
            cnt += 1
            add.append(s[j])
            new_s.append(add)
            add = []
        else:
            add.append(s[j])
        if j == h - 2:
            add.append(s[-1])
            new_s.append(add)
    if h == 1:
        new_s = [s]
    #print(len(new_s))
    total = [0] * len(new_s)
    #print(new_s)
    for k in range(w):
        # print(k)
        tmp_list = [0]*len(new_s)
        #print(total)
        flag = 0
        for l in range(len(new_s)):
            tmp = sum([int(new_s[l][x][k]) for x in range(len(new_s[l]))])
            # tmp_list[l] = tmp
            # print(tmp)
            if tmp > K:
                cnt = 10**18
                flag = 1
                break
            tmp_list[l] = tmp
            total[l] += tmp
        if flag:
            break
        for m in total:
            flag_2 = 1
            if m > K:
                cnt += 1
                total = tmp_list
                flag_2 = 0
                break
        # if flag_2:
        #     for m in total:
        #         if m == K and k != w - 1:
        #             cnt += 1
        #             total = [0]*len(new_s)
        #             break
    if not flag:
        #print(cnt)
        ans = min(ans, cnt)
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

H, W = [int(x) for x in input().split()]

d = [[-1] * W for _ in range(H)]
def dfs(x, y):
    stack = [(x, y)]
    d[x][y] = 1
    while stack:
        x, y = stack.pop()
        next_ = [(x + 1, y + 1), (x + 1, y - 1), (x - 1, y + 1), (x - 1, y - 1)]
        for i in next_:
            nx, ny = i
            if 0 <= nx < H and 0 <= ny < W and d[nx][ny] < 0:
                stack.append((nx, ny))
                d[nx][ny] = 1
    return d

d = dfs(0, 0)
cnt = 0
for i in d:
    for j in i:
        if j == 1:
            cnt += 1

print(cnt)

Fixed submission:
import sys
input = sys.stdin.readline

H, W = [int(x) for x in input().split()]
ans = 0

if H == 1 and W == 1:
    print(1)
    sys.exit()

if H == 1 or W == 1:
    print(1)
    sys.exit()

# type2
b = H // 2

# type1
a = H - b

ans += b * (W // 2)
ans += a * (W - (W // 2))

print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readlinH, W = [int(x) for x in input().split()]

a, b, c = [int(x) for x in input().split()]

if a ** (1 / 2) + b ** (1 / 2) < c ** (1 / 2):
    print("Yes")
else:
    print("No")

Fixed submission:
import sys
input = sys.stdin.readline
import math
a, b, c = [int(x) for x in input().split()]

c -= (a + b)
if c <= 0:
    print("No")
    sys.exit()

c = c ** 2 - 4 * a * b

if c > 0:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
from collections import deque

S = input().rstrip()
Q = int(input())
Query = []

flag = 0

for _ in range(Q):
    Query.append(input().rstrip().split())

for i in Query:
    if i[0] == "1":
        flag += 1
    elif i[1] == "1":
        if flag % 2 == 0:
            S = i[2] + S
        else:
            S += i[2]
    else:
        if flag % 2 == 0:
            S += i[2]
        else:
            S = i[2] + S
if flag % 2 == 0:
    print(S)
else:
    print(S[::-1])

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

S = deque(list(input().rstrip()))
Q = int(input())
Query = []

flag = 0

for _ in range(Q):
    Query.append(input().rstrip().split())

for i in Query:
    if i[0] == "1":
        flag += 1
    elif i[1] == "1":
        if flag % 2 == 0:
            S.appendleft(i[2])
        else:
            S.append(i[2])
    else:
        if flag % 2 == 0:
            S.append(i[2])
        else:
            S.appendleft(i[2])
if flag % 2 == 0:
    print("".join(list(S)))
else:
    print("".join(list(S))[::-1])

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
from collections import deque

S = input().rstrip()
Q = int(input())
Query = []

for _ in range(Q):
    Query.append(input().rstrip().split())

for i in Query:
    if i[0] == "1":
        S = S[::-1]
    elif i[1] == "1":
        S = i[2] + S
    else:
        S += i[2]
print(S)

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

S = deque(list(input().rstrip()))
Q = int(input())
Query = []

flag = 0

for _ in range(Q):
    Query.append(input().rstrip().split())

for i in Query:
    if i[0] == "1":
        flag += 1
    elif i[1] == "1":
        if flag % 2 == 0:
            S.appendleft(i[2])
        else:
            S.append(i[2])
    else:
        if flag % 2 == 0:
            S.append(i[2])
        else:
            S.appendleft(i[2])
if flag % 2 == 0:
    print("".join(list(S)))
else:
    print("".join(list(S))[::-1])
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

n, p = [int(x) for x in input().split()]
s = input().rstrip()[::-1]
ans = 0
if p == 2:
    for i in range(n):
        if s[i] % 2 == 0:
            ans += (n - i + 1)
    print(ans)
    sys.exit()
if p == 5:
    for i in range(n):
        if s[i] == 0 or s[i] == 5:
            ans += (n - i + 1)
    print(ans)
    sys.exit()
t = [0, int(s[0]) % p]
mul = 10
for i in range(1, n):
    t.append((t[-1] + int(s[i])*mul) % p)
    mul *= 10
    mul %= p
from collections import Counter
c = Counter(t)
for i in c.keys():
    ans += c[i]*(c[i] - 1) // 2
print(ans)



Fixed submission:
import sys
input = sys.stdin.readline

n, p = [int(x) for x in input().split()]
s = input().rstrip()[::-1]
ans = 0
if p == 2:
    for i in range(n):
        if int(s[i]) % 2 == 0:
            ans += (n - i)
    print(ans)
    sys.exit()
if p == 5:
    for i in range(n):
        if int(s[i]) == 0 or int(s[i]) == 5:
            ans += (n - i)
    print(ans)
    sys.exit()
t = [0, int(s[0]) % p]
mul = 10
for i in range(1, n):
    t.append((t[-1] + int(s[i])*mul) % p)
    mul *= 10
    mul %= p
from collections import Counter
c = Counter(t)
for i in c.keys():
    ans += c[i]*(c[i] - 1) // 2
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

N, R = [int(x) for x in input().split()]

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

Fixed submission:
import sys
input = sys.stdin.readline

N, R = [int(x) for x in input().split()]

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