Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
n = 1000000007
p = 1
for i in range(1, N + 1):
    p *= i
print(p % n)


Fixed submission:
N = int(input())
n = 1000000007
p = 1
for i in range(1, N + 1):
    p *= i
    p %= n
print(p)
Buggy python submission (verdict: Runtime Error):
N = int(input())
result = N * (N + 1) // 2
print(f'{result}')

Fixed submission:
N = int(input())
result = N * (N + 1) // 2
print('{}'.format(result))
Buggy python submission (verdict: Runtime Error):
s = input()
n = len(s)
t = s[:n // 2]
k = s[-n//2+1:]
if s == s[::-1] and t == t[::-1]:
    print('Yes')
else:
    print('No')
s = input()
n = len(s)
t = s[:n // 2]
k = s[-n//2+1:]
if s == s[::-1] and t == t[::-1]:
    print('Yes')
else:
    print('No')
提出情報

Fixed submission:
s = input()
n = len(s)
t = s[:n // 2]
k = s[-n//2+1:]
if s == s[::-1] and t == t[::-1]:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Time Limit Exceeded):

def choose(D, c, s, d, last, depth, p):
    maxpoint = -999999
    maxnum = 0
    if depth > 0 and d < D:
        for i in range(26):
            point = p
            point += s[d][i]
            point += changepoint(c, d, i, last)
            nlast = []
            nlast.extend(last)
            nlast[i] = d
            z, point = choose(D, c, s, d+1, nlast, depth-1, point)
            if point > maxpoint:
                maxpoint = point
                maxnum = i
        return maxnum, maxpoint
    return 0, p


def changepoint(c, d, num, last):
    point = 0
    for j in range(26):
        if j != num:
            point -= c[j]*(d-last[j])
    return point


def main():
    D = int(input())
    c = list(map(int, input().split()))
    s = []
    last = [-1]*26
    for _ in range(D):
        s.append(list(map(int, input().split())))
    point = 0
    for i in range(D):
        num, point = choose(D, c, s, i, last, 2, 0)
        print(num+1)


main()


Fixed submission:
def choose(D, c, s, d, last, depth, point):
    maxpoint = -999999
    maxnum = 0
    if depth > 0:
        for i in range(26):
            point = s[d][i]
            point += changepoint(c, d, i, last)
            if point >= maxpoint:
                maxpoint = point
                maxnum = i
        return maxnum, maxpoint
    return 0, 0


def changepoint(c, d, num, last):
    point = 0
    for i in range(26):
        if i == num:
            continue
        point -= c[i]*(d-last[i])
    return point


def main():
    D = int(input())
    c = list(map(int, input().split()))
    s = []
    last = [-1]*26
    for _ in range(D):
        s.append(list(map(int, input().split())))
    point = 0
    for i in range(D):
        num, point = choose(D, c, s, i, last, 1, point)
        print(num+1)


main()
Buggy python submission (verdict: Runtime Error):
from collections import Counter

N = int(input())
A = list(map(int, input().split()))
Q = int(input())
s = Counter(A)
t=[0]*(10**5+1)
for i in range(10**5+1):
    t[i] = s[i]*i
    
for i in range(Q):
    B, C = map(int, input().split())
    num = t[B]//(B)
    t[B] = 0
    t[C] += num*(C)
    print(sum(t))


Fixed submission:

def main(T):
    if T.lower() == T:
        return "a"
    else:
        return "A"


T = input()
print(main(T))
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter

N = int(input())
A = list(map(int, input().split()))
Q = int(input())
s = Counter(A)
t=[0]*(10**5+1)
for i in range(10**5+1):
    t[i] = s[i]*i

sumnum=sum(t)
for i in range(Q):
    B, C = map(int, input().split())
    num = t[B]//(B)
    t[B] = 0
    t[C] += num*(C)
    sumnum=sumnum-num*B+num*C
    print(sum(t))


Fixed submission:
from collections import Counter

N = int(input())
A = list(map(int, input().split()))
Q = int(input())
s = Counter(A)
t=[0]*(10**5+1)
for i in range(10**5+1):
    t[i] = s[i]*i

sumnum=sum(t)
for i in range(Q):
    B, C = map(int, input().split())
    num = t[B]//(B)
    t[B] = 0
    t[C] += num*(C)
    sumnum=sumnum-num*B+num*C
    print(sumnum)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter

N = int(input())
A = list(map(int, input().split()))
Q = int(input())
s = Counter(A)
t=[0]*(10**5+1)
for i in range(10**5+1):
    t[i] = s[i]*i
    
for i in range(Q):
    B, C = map(int, input().split())
    num = t[B]//(B)
    t[B] = 0
    t[C] += num*(C)
    print(sum(t))


Fixed submission:
from collections import Counter

N = int(input())
A = list(map(int, input().split()))
Q = int(input())
s = Counter(A)
t=[0]*(10**5+1)
for i in range(10**5+1):
    t[i] = s[i]*i

sumnum=sum(t)
for i in range(Q):
    B, C = map(int, input().split())
    num = t[B]//(B)
    t[B] = 0
    t[C] += num*(C)
    sumnum=sumnum-num*B+num*C
    print(sumnum)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
import numpy as np

N = int(input())
A = list(map(int, input().split()))
Q = int(input())
s = Counter(A)
t=[0]*(10**5+1)
for i in range(10**5+1):
    t[i] = s[i]*i
    
for i in range(Q):
    B, C = map(int, input().split())
    num = t[B]//(B)
    t[B] = 0
    t[C] += num*(C)
    print(sum(t))


Fixed submission:
from collections import Counter

N = int(input())
A = list(map(int, input().split()))
Q = int(input())
s = Counter(A)
t=[0]*(10**5+1)
for i in range(10**5+1):
    t[i] = s[i]*i

sumnum=sum(t)
for i in range(Q):
    B, C = map(int, input().split())
    num = t[B]//(B)
    t[B] = 0
    t[C] += num*(C)
    sumnum=sumnum-num*B+num*C
    print(sumnum)
Buggy python submission (verdict: Runtime Error):
def main(N, a):
    a.sort()
    if a[0] == 1:
        if a[1] == 1:
            return 0
        return 1
    i = 0
    while True:
        num = a[0]
        if 2 > len(a):
            return len(a)+i
        while True:
            if num == a[1]:
                a = [i for i in a if i != num]
                if 2 > len(a):
                    return len(a)+i
                num = a[0]
            else:
                break
        if num*2 > a[len(a)-1]:
            a = [i for i in a if i % num != 0]
            return len(a)+i+1
        a = [i for i in a if i % num != 0]
        i = i+1


N = int(input())
a = list(map(int, input().split()))
print(main(N, a))


Fixed submission:
import numpy as np


def main(x):
    for i in range(len(x)):
        if x[i] == 0:
            return i+1
    return 1


x = list(map(int, input().split()))
print(main(x))
Buggy python submission (verdict: Runtime Error):
import numpy as np


def main(X, N, a):
    a.append(10000000000)
    a.append(-10000000000)
    a.sort()
    maxn = a[0]-1
    for i in range(len(a)-1):

        if a[i] >= X:
            if a[i+1]-a[i] > 1:
                if X-maxn>a[i]+1-X
                maxn = a[i]+1
                break
            if X-maxn < a[i]-X:
                break
        else:
            if a[i+1]-a[i] > 1:
                if a[i+1] > X and a[i] < X:
                    maxn = X
                    break
                maxn = a[i+1]-1

    return maxn


X, N = map(int, input().split())
try:
    a = list(map(int, input().split()))
except:
    a = []
print(main(X, N, a))


Fixed submission:
import numpy as np


def main(X, N, a):
    a.append(10000000000)
    a.append(-10000000000)
    a.sort()
    maxn = a[0]-1
    for i in range(len(a)-1):

        if a[i] >= X:
            if a[i+1]-a[i] > 1:
                if X-maxn>a[i]+1-X:
                    maxn = a[i]+1
                break
            if X-maxn < a[i]-X:
                break
        else:
            if a[i+1]-a[i] > 1:
                if a[i+1] > X and a[i] < X:
                    maxn = X
                    break
                maxn = a[i+1]-1

    return maxn


X, N = map(int, input().split())
try:
    a = list(map(int, input().split()))
except:
    a = []
print(main(X, N, a))
Buggy python submission (verdict: Runtime Error):
import numpy as np


def main(A, B, V, W, T):
    if abs(B-A) <= T*(V-W):
        return "YES"
    return "NO"


A, V = map(int, input().split())
B, W = map(int, input().split())
T = int(input())
print(main(A, B, V, W, T))


Fixed submission:
import numpy as np


def main(M):
    ans = M[0:3]
    return ans


M = input()
print(main(M))
Buggy python submission (verdict: Runtime Error):
import numpy as np

def main(N, K, A):
    for _ in range(min(K, 41)):
        ne = np.zeros_like(A)
        for i in range(N):
            ne[max(0, i-A[i])] += 1
            if i+A[i]+1 < N:
                ne[i+A[i]+1] -= 1
        A = ne.cumsum()
    return A


N, K = map(int, input().split())
A = np.array(input().split(), np.int64)
ans = main(N, K, A)
print(*ans)


Fixed submission:
from numba import njit
import numpy as np


@njit
def main(N, K, A):
    for _ in range(min(K, 41)):
        ne = np.zeros_like(A)
        for i in range(N):
            ne[max(0, i-A[i])] += 1
            if i+A[i]+1 < N:
                ne[i+A[i]+1] -= 1
        A = ne.cumsum()
    return A


N, K = map(int, input().split())
A = np.array(input().split(), np.int64)
ans = main(N, K, A)
print(*ans)
Buggy python submission (verdict: Runtime Error):
import numpy as np


def count(a):
    i = 0
    while a > 0:
        i += 1
        a -= i
        if a == 0:
            break
        if a < 0:
            i -= 1
            break
    return i


def main(N):
    num = N
    ans = 0
    A = np.zeros((1000000), np.int32)
    i = 2
    last = 0
    if N == 1:
        return 0
    while True:
        if num % i == 0:
            num = num//i
            A[i] += 1
        else:
            i += 1
            if num == 1:
                break
            if i*i > num:
                last = 1
                break
    for j in range(i):
        ans += count(A[j])
    ans += last
    return ans


N = int(input())
print(main(N))


Fixed submission:
import numpy as np


def main(A, B):

    ans = A*B
    return ans


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

Buggy python submission (verdict: Runtime Error):
import numpy as np


def main(A,B):

    ans = A*B
    return ans


A,B = int(input())
print(main(A,B))


Fixed submission:
import numpy as np


def main(A, B):

    ans = A*B
    return ans


A, B = map(int, input().split())
print(main(A, B))
Buggy python submission (verdict: Runtime Error):
def main(N, A):
    num = 1
    ans = 1
    for i in range(N+1):
        num -= A[i]
        if i < N:
            num *= 2
            ans += num
        if num <= 0 and i < N:
            return -1
    eda = 0
    for i in range(N+1):
        ans -= num
        eda += A[N-i]
        num -= eda
        num = num//2
        if num <= 0:

            break
    return ans


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

print(main(N, A))


Fixed submission:
from numba import njit


@njit
def main(h, m, H, M, K):
    return max((H-h)*60+(M-m)-K, 0)


h, m, H, M, K = map(int, input().split())


print(main(h, m, H, M, K))
Buggy python submission (verdict: Runtime Error):
from numba import njit

@ngit
def main(N, A):
    num = 1
    ans = 1
    if A[N] == 0:
        return -1
    for i in range(N+1):
        num -= A[i]
        if i < N:
            num *= 2
            ans += num
        if num <= 0 and i < N:
            return -1
    eda=0
    for i in range(N+1):
        ans -= num
        eda+=A[N-i]
        num -= eda
        num = num//2
        if num <= 0:
            num += A[N-i]
            break
    return ans


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

print(main(N, A))


Fixed submission:
def main(N, A):
    num = 1
    ans = 1
    for i in range(N+1):
        num -= A[i]
        if i < N:
            num *= 2
            ans += num
        if num == 0 and i < N:
            return -1
        if num < 0:
            return -1
    eda = 0
    for i in range(N+1):
        ans -= num
        eda += A[N-i]
        num -= eda
        num = num//2
        if num <= 0:
            break
    return ans


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

print(main(N, A))
Buggy python submission (verdict: Runtime Error):
N=int(input())
if N%10==3:
  print("bon")
else if N%10==0:
  print("pon")
else if N%10==1:
  print("pon")
else if N%10==6:
  print("pon")
else if N%10==8:
  print("pon")
else:
  print("hon")

Fixed submission:
N=int(input())
for i in range(1):
  if N%10==3:
    print("bon")
    break
  if N%10==0:
    print("pon")
    break
  if N%10==1:
    print("pon")
    break
  if N%10==6:
    print("pon")
    break
  if N%10==8:
    print("pon")
    break
  print("hon")
Buggy python submission (verdict: Time Limit Exceeded):
N,M=map(int,input().split())
graph=[[] for _ in range(N)]
for i in range(M):
  a,b=map(int,input().split())
  graph[a-1].append(b-1)
  graph[b-1].append(a-1)

s=[-1]*N
d=[-1]*N

s[0]=0
d[0]=0


for i in range(N):
  finish=1
  for j in range(N):
    if d[j]==i:
      for saki in graph[j]:
        if d[saki]==-1:
          d[saki]=i+1
          s[saki]=j
          finish=0
  if finish==1:
    break

print("Yes")
for i in range(N-1):
  print(s[i+1]+1)

Fixed submission:
N,M=map(int,input().split())
graph=[[] for _ in range(N)]
for i in range(M):
  a,b=map(int,input().split())
  graph[a-1].append(b-1)
  graph[b-1].append(a-1)

s=[-1]*N
d=[-1]*N
next=[[] for _ in range(N)]
next[0].append(0)

s[0]=0
d[0]=0


for i in range(N):
  finish=1
  for j in next[i]:
    if d[j]==i:
      for saki in graph[j]:
        if d[saki]==-1:
          d[saki]=i+1
          s[saki]=j
          next[i+1].append(saki)
          finish=0
  if finish==1:
    break

print("Yes")
for i in range(N-1):
  print(s[i+1]+1)

Buggy python submission (verdict: Time Limit Exceeded):
N,M=map(int,input().split())
graph=[[] for _ in range(N)]
for i in range(M):
  a,b=map(int,input().split())
  graph[a-1].append(b-1)
  graph[b-1].append(a-1)

s=[-1]*N
d=[-1]*N

s[0]=0
d[0]=0


for i in range(N):
  finish=1
  for j in range(N):
    if d[j]==i:
      for saki in graph[j]:
        if d[saki]==-1:
          d[saki]=i+1
          s[saki]=j
          finish=0
  if finish==1:
    break

print("Yes")
for i in range(N-1):
  print(s[i+1]+1)

Fixed submission:
N,M=map(int,input().split())
graph=[[] for _ in range(N)]
for i in range(M):
  a,b=map(int,input().split())
  graph[a-1].append(b-1)
  graph[b-1].append(a-1)

s=[-1]*N
d=[-1]*N
next=[[] for _ in range(N)]
next[0].append(0)

s[0]=0
d[0]=0


for i in range(N):
  finish=1
  for j in next[i]:
    if d[j]==i:
      for saki in graph[j]:
        if d[saki]==-1:
          d[saki]=i+1
          s[saki]=j
          next[i+1].append(saki)
          finish=0
  if finish==1:
    break

print("Yes")
for i in range(N-1):
  print(s[i+1]+1)
Buggy python submission (verdict: Runtime Error):
from numba import njit
import numpy as np


def main(S, T):
    if len(T)-len(S) != 1:
        print("No")
        return
    count = 0
    for i in range(len(S)):
        if S[i] != T[i]:
            count += 1
            if count > 0:
                print("No")
                return
    print("Yes")


main(S, T)


Fixed submission:
from numba import njit
import numpy as np


def main(S, T):
    if len(T)-len(S) != 1:
        print("No")
        return
    count = 0
    for i in range(len(S)):
        if S[i] != T[i]:
            count += 1
            if count > 0:
                print("No")
                return
    print("Yes")


S = input()
T = input()
main(S, T)

Buggy python submission (verdict: Runtime Error):
from numba import njit
import numpy as np


def main(S, T):
    if len(T)-len(S) != 1:
        print("No")
        return
    count = 0
    for i in range(len(S)):
        if S[i] != T[i+count]:
            count += 1
            if count > 1:
                print("No")
                return
    print("Yes")


def cc_export():
    from numba.pycc import CC
    cc = CC('my_module')
    cc.export('main', '')(main)
    cc.compile()


if __name__ == '__main__':
    import sys
    if sys.argv[-1] == 'ONLINE_JUDGE':
        cc_export()
        exit(0)
    from my_module import main
    S = input()
    T = input()
    main(S, T)

Fixed submission:
from numba import njit
import numpy as np


def main(S, T):
    if len(T)-len(S) != 1:
        print("No")
        return
    count = 0
    for i in range(len(S)):
        if S[i] != T[i]:
            count += 1
            if count > 0:
                print("No")
                return
    print("Yes")


S = input()
T = input()
main(S, T)
Buggy python submission (verdict: Runtime Error):
N=int(input())
num=0
ans=""
for i in range(1,9):
    if 26**i > N:
        N-=1
       for j in range(i):
           ans+=chr(ord("a")+N%26)
           N//=26
       break
    else:
       N-=26**i
print(ans[::-1])


Fixed submission:
N=int(input())
num=0
ans=""
for i in range(1,99):
    if 26**i >= N:
        N-=1
        for j in range(i):
            ans+=chr(97+N%26)
            N//=26
        break
    else:
        N-=26**i
print(ans[::-1])
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int,input().split()))
for _ in range(int(input())):
    B,C=map(int,input().split())
    A=[C if i==B else i for i in A]
    print(sum(A))

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
s=sum(A)
num=[0]*100001
for i in A:
    num[i]+=1
for _ in range(int(input())):
    B,C=map(int,input().split())
    s+=(C-B)*num[B]
    num[C]+=num[B]
    num[B]=0
    print(s)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int,input().split()))
n=sum(A)
for _ in range(int(input())):
    B,C=map(int,input().split())
    n=n-A.count(B)*(B-C)
    A=[C if i==B else i for i in A]
    print(n)

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
s=sum(A)
num=[0]*100001
for i in A:
    num[i]+=1
for _ in range(int(input())):
    B,C=map(int,input().split())
    s+=(C-B)*num[B]
    num[C]+=num[B]
    num[B]=0
    print(s)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
S=input()

count=0
pin=[]*721
for p in range(N-2):
    for q in range(1,N-1):
        if p>=q:
            continue
        for r in range(2,N):
            if q>=r:
                continue
            n=int(S[p]+S[q]+S[r])
            if not n in pin:
                pin.append(n)
print(len(pin))


Fixed submission:
N=int(input())
S=input()

count=0
for p in range(10):
    s=S.find(str(p))
    if s==-1:
        continue
    for q in range(10):
        t=S.find(str(q),s+1)
        if t==-1:
            continue
        for r in range(10):
            u=S.find(str(r),t+1)
            if u!=-1:
                count+=1
print(count)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
for i in range(int(N**0.5),N+1):
    if N%i==0:
        print(len(str(i)))
        exit(0)

Fixed submission:
N=int(input())
for i in range(int(N ** 0.5 + 1),-1,-1):
    if N % i == 0:
        print(len(str(N // i)))
        exit(0)

Buggy python submission (verdict: Runtime Error):
import math
N=int(input())
for i in range(int(math.sqrt(N))-1,N+1):
    if N%i==0:
        print(len(str(i)))
        exit(0)

Fixed submission:
N=int(input())
for i in range(int(N ** 0.5 + 1),-1,-1):
    if N % i == 0:
        print(len(str(N // i)))
        exit(0)

Buggy python submission (verdict: Time Limit Exceeded):
import math
N=int(input())
for i in range(int(math.sqrt(N)),N+1):
    if N%i==0:
        print(len(str(i)))
        exit(0)

Fixed submission:
N=int(input())
for i in range(int(N ** 0.5 + 1),-1,-1):
    if N % i == 0:
        print(len(str(N // i)))
        exit(0)

Buggy python submission (verdict: Time Limit Exceeded):
import math
N=int(input())
for i in range(int(math.sqrt(N)),N+1):
    j=N//i
    if i*j==N:
        print(len(str(i)))
        exit(0)

Fixed submission:
N=int(input())
for i in range(int(N ** 0.5 + 1),-1,-1):
    if N % i == 0:
        print(len(str(N // i)))
        exit(0)
Buggy python submission (verdict: Runtime Error):
print_cnt = int(input())

result = [0] * 1000

for x in range(100):
  for y in range(100):
    for z in range(100):
      if x*y*z == 0:
        continue
      tmp = x*x + y*y + z*z + x*y + y*z + z*x
      if tmp <= 1000:
        result[tmp-1] += 1

for i in range(print_cnt):
  print(result[i])

Fixed submission:
print_cnt = int(input())

result = [0] * 10000

for x in range(100):
  for y in range(100):
    for z in range(100):
      if x*y*z == 0:
        continue
      tmp = x*x + y*y + z*z + x*y + y*z + z*x
      if tmp <= 10000:
        result[tmp-1] += 1

for i in range(print_cnt):
  print(result[i])
Buggy python submission (verdict: Time Limit Exceeded):
a = input()
#l = list(a)

q = int(input())

default_order = True
for i in range(q):
  x = input().split()
  if x[0] == "1":
    default_order = default_order ^ True
  elif x[0] == "2":
    insert_type = default_order ^ False
    if x[1] == "2":
      insert_type = not(insert_type)
    if insert_type:
      #l.insert(0,x[2])
      a = x[2] + a
    else:
      #l.append(x[2])
      a = a + x[2]
if not(default_order):
  l = list(a)
  l.reverse()
  a = ''.join(l)

#print(''.join(l))
print(a)


Fixed submission:
a = input()
l = list(a)
list_ins = [0] * 200000
ins_cnt = 0
list_app = [0] * 200000
app_cnt = 0

q = int(input())

default_order = True
for i in range(q):
  x = input().split()
  if x[0] == "1":
    default_order = default_order ^ True
  elif x[0] == "2":
    insert_type = default_order ^ False
    if x[1] == "2":
      insert_type = not(insert_type)
    if insert_type:
      list_ins[ins_cnt] = x[2]
      ins_cnt += 1
    else:
      list_app[app_cnt] = x[2]
      app_cnt += 1
ret = ""
if ins_cnt > 0:
  list_ins = list_ins[0:ins_cnt]
else:
  list_ins = []
if app_cnt > 0:
  list_app = list_app[0:app_cnt]
else:
  list_app = []
if default_order:
  list_ins.reverse()
  ret = ''.join(list_ins) + ''.join(l) + ''.join(list_app)
else:
  list_app.reverse()
  l.reverse()
  ret = ''.join(list_app) + ''.join(l) + ''.join(list_ins)

print(ret)

Buggy python submission (verdict: Time Limit Exceeded):
a = input()
l = list(a)

q = int(input())

default_order = True
for i in range(q):
  x = input().split()
  if x[0] == "1":
    default_order = default_order ^ True
  elif x[0] == "2":
    insert_type = default_order ^ False
    if x[1] == "2":
      insert_type = not(insert_type)
    if insert_type:
      l.insert(0,x[2])
    else:
      l.append(x[2])
if not(default_order):
  l.reverse()

print(''.join(l))
      

Fixed submission:
a = input()
l = list(a)
list_ins = [0] * 200000
ins_cnt = 0
list_app = [0] * 200000
app_cnt = 0

q = int(input())

default_order = True
for i in range(q):
  x = input().split()
  if x[0] == "1":
    default_order = default_order ^ True
  elif x[0] == "2":
    insert_type = default_order ^ False
    if x[1] == "2":
      insert_type = not(insert_type)
    if insert_type:
      list_ins[ins_cnt] = x[2]
      ins_cnt += 1
    else:
      list_app[app_cnt] = x[2]
      app_cnt += 1
ret = ""
if ins_cnt > 0:
  list_ins = list_ins[0:ins_cnt]
else:
  list_ins = []
if app_cnt > 0:
  list_app = list_app[0:app_cnt]
else:
  list_app = []
if default_order:
  list_ins.reverse()
  ret = ''.join(list_ins) + ''.join(l) + ''.join(list_app)
else:
  list_app.reverse()
  l.reverse()
  ret = ''.join(list_app) + ''.join(l) + ''.join(list_ins)

print(ret)