Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
H,N =[int(i) for i in input().split()]
AAA = []
BBB = []
for i in range(N):
    buff = [int(i) for i in input().split()]
    AAA.append(buff[0])
    BBB.append(buff[1])

#dp[i]は体力をi減らすまでに必要な魔力の最小値
dp = [10000000000 for i in range(H+5)]
dp[0] = 0
for i in range(H+5):
    for j in range(N):
        A = AAA[j]
        B = BBB[j]
        if i-A>=0:
            dp[i]=min(dp[i],dp[i-A]+B)
        else:
            dp[i]=min(dp[i],B)

#print(dp)
print(dp[H])


Fixed submission:
H,N =[int(i) for i in input().split()]
AAA = []
BBB = []
for i in range(N):
    buff = [int(i) for i in input().split()]
    AAA.append(buff[0])
    BBB.append(buff[1])

#dp[i]は体力をi減らすまでに必要な魔力の最小値
dp = [10000000000 for i in range(H+5)]
dp[0] = 0
for i in range(H+5):
    for j in range(N):
        A = AAA[j]
        B = BBB[j]
        if i-A>=0:
            dp[i]=min(dp[i],dp[i-A]+B)
        else:
            dp[i]=min(dp[i],B)

#print(dp)
print(dp[H])
Buggy python submission (verdict: Time Limit Exceeded):
import itertools

N = int(input())
Llist  =[int(i) for i in input().split()]
comblist = list(itertools.combinations(Llist,3))
ct=0
for comb in comblist:
    a = comb[0]
    b = comb[1]
    c = comb[2]
    if a<b+c and b<c+a and c<a+b:
        ct+=1
print(ct)

Fixed submission:
import itertools
import bisect

N = int(input())
Llist  =[int(i) for i in input().split()]
Llist.sort()

#print(Llist)


ans=0
for i in range(len(Llist)):
    for j in range(i+1,len(Llist)):
        a = Llist[i]
        b = Llist[j]
        index = bisect.bisect_right(Llist,b-a)
        #print("i"+str(i)+"  a"+str(a)+"  j"+str(j)+"  b"+str(b)+"  index"+str(index))
        if i>index:
            ans+=i-index

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
A,B = [int(i) for i in input().split()]

def gcd(a,b):#a>b
    if b==0:
        return a
    else:
        return gcd(b,a%b)

def get_sieve_of_eratosthenes(n):#n以下の素数のリストを返す
    if not isinstance(n, int):
        raise TypeError('n is int type.')
    if n < 2:
        raise ValueError('n is more than 2')
    prime = [2]
    limit = int(n**0.5)
    data = [i + 1 for i in range(2, n, 2)]
    while True:
        p = data[0]
        if limit <= p:
            return prime + data
        prime.append(p)
        data = [e for e in data if e % p != 0]
    return(data)

n=gcd(A,B)
ans = 1
if n==1:
    print(1)
else:
    plist = get_sieve_of_eratosthenes(n)
    for p in plist:
        if n==1:
            break
        if n%p==0:
            n = n//p
            ans+=1
    print(ans)

Fixed submission:
A,B = [int(i) for i in input().split()]

def gcd(a,b):#a>b
    if b==0:
        return a
    else:
        return gcd(b,a%b)

def get_sieve_of_eratosthenes(n):#n以下の素数のリストを返す
    if not isinstance(n, int):
        raise TypeError('n is int type.')
    if n < 2:
        raise ValueError('n is more than 2')
    prime = [2]
    limit = int(n**0.5)
    data = [i + 1 for i in range(2, n, 2)]
    while True:
        p = data[0]
        if limit <= p:
            return prime + data
        prime.append(p)
        data = [e for e in data if e % p != 0]
    return(data)

n=gcd(A,B)
ans = 1
if n==1:
    print(1)
else:
    #plist = get_sieve_of_eratosthenes(n)
    #for p in plist:
    for p in range(2,int(n**0.5)+3):
        if n%p==0:
            ans+=1
            while n%p==0:
                n = n//p
    if n!=1:
        ans+=1
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N =int(input())
m = 0
for i in range(N):
    m += i

print(m)

Fixed submission:
N =int(input())
print(int(N*(N-1)//2))
Buggy python submission (verdict: Runtime Error):
N = int(input())
aaa = sorted([int(i) for i in input().split()])


count0 = aaa.count(0)
countleft = aaa.count(aaa[0])
countright = aaa.count(aaa[-1])
buff1 = aaa[0]
buff2 = aaa[-1]
aaa = [i for i in aaa if i!=buff1 and i!=buff2]
buff3 = aaa[0]
countmid = aaa.count(buff3)

if count0 == N:
    print("Yes")
    exit()
elif N%3==0 and count0 == N/3 and countright == N/3*2:
    print("Yes")
    exit()
elif N%3==0 and countleft == N/3 and countright == N/3 and countmid == N/3:
    print("Yes")
    exit()
print("No")



Fixed submission:
N = int(input())
aaa = sorted([int(i) for i in input().split()])

ans = 0
for a in aaa:
    ans = ans^a
if ans==0:
    print("Yes")
else:
    print("No")

Buggy python submission (verdict: Runtime Error):
N = int(input())
aaa = sorted([int(i) for i in input().split()])
ini = aaa[0]
first = aaa[0]
for i in range(1,N):
    second = aaa[i]
    for j in range(N-1):
        next_hat = first^second
        #print(first,second,next_hat)
        if next_hat in aaa:
             aaa.remove(next_hat)
        else:
            break
        first = second
        second = next_hat
    else:
        if first&second==ini:
            print("Yes")
            exit()
print("No")


Fixed submission:
N = int(input())
aaa = sorted([int(i) for i in input().split()])

ans = 0
for a in aaa:
    ans = ans^a
if ans==0:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Time Limit Exceeded):
N,Q = [int(i) for i in input().split()]
S = str(input())
lrlist = []
for i in range(Q):
    lrlist.append([int(i)-1 for i in input().split()])

#print(S)
#print(lrlist)

Asite = []
for i in range(len(S)-1):
    if S[i]=="A" and S[i+1]=="C":
        Asite.append(i)


for l,r in lrlist:
    ans = 0
    for i in Asite:
        if l <= i and i+1 <= r:
            ans+=1
    print(ans)

Fixed submission:
N,Q = [int(i) for i in input().split()]
S = str(input())
lrlist = []
for i in range(Q):
    lrlist.append([int(i)-1 for i in input().split()])

#print(S)
#print(lrlist)

Asite = [0]
for i in range(1,len(S)):
    if S[i-1]=="A" and S[i]=="C":
        Asite.append(Asite[-1]+1)
    else:
        Asite.append(Asite[-1])


for l,r in lrlist:
    print(Asite[r]-Asite[l])

Buggy python submission (verdict: Runtime Error):
N,Q = [int(i) for i in input().split()]
S = str(input())
lrlist = []
for i in range(Q):
    lrlist.append([int(i)-1 for i in input().split()])

#print(S)
#print(lrlist)

Asite = []
for i in range(len(S)):
    if S[i]=="A" and S[i+1]=="C":
        Asite.append(i)


for l,r in lrlist:
    ans = 0
    for i in Asite:
        if l <= i and i+1 <= r:
            ans+=1
    print(ans)

Fixed submission:
N,Q = [int(i) for i in input().split()]
S = str(input())
lrlist = []
for i in range(Q):
    lrlist.append([int(i)-1 for i in input().split()])

#print(S)
#print(lrlist)

Asite = [0]
for i in range(1,len(S)):
    if S[i-1]=="A" and S[i]=="C":
        Asite.append(Asite[-1]+1)
    else:
        Asite.append(Asite[-1])


for l,r in lrlist:
    print(Asite[r]-Asite[l])

Buggy python submission (verdict: Time Limit Exceeded):
N,Q = [int(i) for i in input().split()]
S = str(input())
lrlist = []
for i in range(Q):
    lrlist.append([int(i)-1 for i in input().split()])

#print(S)
#print(lrlist)

import re
result = [i.span() for i in re.finditer("AC",S)]
#print(result)

for l,r in lrlist:
    ans = 0
    for i in result:
        if l <= i[0] and i[0]+1 <= r:
            ans+=1
    print(ans)

Fixed submission:
N,Q = [int(i) for i in input().split()]
S = str(input())
lrlist = []
for i in range(Q):
    lrlist.append([int(i)-1 for i in input().split()])

#print(S)
#print(lrlist)

Asite = [0]
for i in range(1,len(S)):
    if S[i-1]=="A" and S[i]=="C":
        Asite.append(Asite[-1]+1)
    else:
        Asite.append(Asite[-1])


for l,r in lrlist:
    print(Asite[r]-Asite[l])
Buggy python submission (verdict: Runtime Error):
import math
N = int(input())
AAA = [int(i) for i in input().split()]
BBB = [0]
for a in AAA:
    BBB.append(a+BBB[-1])
ans=[]
#print(BBB)
BBB=sorted(BBB)
#print(BBB)
prev = math.inf
buff=BBB[0]
ans=[]
for i,b in enumerate(BBB):
    #print(b,prev,buff)
    if b==prev:
        buff+=1
    else:
        if buff>=2:
            #print("append!")
            ans.append(buff)
        buff=1
        prev=b
if buff!=1:
    ans.append(buff)
#print(ans)
print(sum([(i-1)*i//2 for i in ans]))

Fixed submission:
N = int(input())
AAA = [int(i) for i in input().split()]
BBB = [0]
for a in AAA:
    BBB.append(a+BBB[-1])
ans=[]
#print(BBB)
BBB=sorted(BBB)
#print(BBB)
prev = float("inf")
buff=BBB[0]
ans=[]
for i,b in enumerate(BBB):
    #print(b,prev,buff)
    if b==prev:
        buff+=1
    else:
        if buff>=2:
            #print("append!")
            ans.append(buff)
        buff=1
        prev=b
if buff!=1:
    ans.append(buff)
#print(ans)
print(sum([(i-1)*i//2 for i in ans]))

Buggy python submission (verdict: Runtime Error):
import math
N = int(input())
AAA = [int(i) for i in input().split()]
BBB = [0]
for a in AAA:
    BBB.append(a+BBB[-1])
ans=[]
print(BBB)
BBB=sorted(BBB)
print(BBB)
prev = math.inf
buff=BBB[0]
ans=[]
for i,b in enumerate(BBB):
    #print(b,prev,buff)
    if b==prev:
        buff+=1
    else:
        if buff>=2:
            #print("append!")
            ans.append(buff)
        buff=1
        prev=b
if buff!=1:
    ans.append(buff)
#print(ans)
print(sum([(i-1)*i//2 for i in ans]))

Fixed submission:
N = int(input())
AAA = [int(i) for i in input().split()]
BBB = [0]
for a in AAA:
    BBB.append(a+BBB[-1])
ans=[]
#print(BBB)
BBB=sorted(BBB)
#print(BBB)
prev = float("inf")
buff=BBB[0]
ans=[]
for i,b in enumerate(BBB):
    #print(b,prev,buff)
    if b==prev:
        buff+=1
    else:
        if buff>=2:
            #print("append!")
            ans.append(buff)
        buff=1
        prev=b
if buff!=1:
    ans.append(buff)
#print(ans)
print(sum([(i-1)*i//2 for i in ans]))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
AAA = [int(i) for i in input().split()]
BBB = [0]
for a in AAA:
    BBB.append(a+BBB[-1])
ans=0
for i in range(N+1):
    for j in range(i+1,N+1):
        if BBB[i]==BBB[j]:
            ans+=1
print(ans)

Fixed submission:
N = int(input())
AAA = [int(i) for i in input().split()]
BBB = [0]
for a in AAA:
    BBB.append(a+BBB[-1])
ans=[]
#print(BBB)
BBB=sorted(BBB)
#print(BBB)
prev = float("inf")
buff=BBB[0]
ans=[]
for i,b in enumerate(BBB):
    #print(b,prev,buff)
    if b==prev:
        buff+=1
    else:
        if buff>=2:
            #print("append!")
            ans.append(buff)
        buff=1
        prev=b
if buff!=1:
    ans.append(buff)
#print(ans)
print(sum([(i-1)*i//2 for i in ans]))
Buggy python submission (verdict: Time Limit Exceeded):
N,K = [int(i) for i in input().split()]
AAA = [int(i) for i in input().split()]

count = [0 for i in range(200010)]
for A in AAA:
    count[A]+=1
ans=0
while sum([1 if i!=0 else 0 for i in count])>K:
    #print(count[:10])
    buff = min([i for i in count if i!=0])
    ans += buff
    count.remove(buff)
print(ans)

Fixed submission:
N,K = [int(i) for i in input().split()]
AAA = [int(i) for i in input().split()]

count = [0 for i in range(200010)]
for A in AAA:
    count[A]+=1
ans=0
count=sorted([i for i in count if i!=0])

if len(count)<=K:
    print("0")
    exit()
else:
    print(sum(count[:-K]))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
AAA = sorted([int(i) for i in input().split()])
BBB = sorted([int(i) for i in input().split()])
CCC = sorted([int(i) for i in input().split()])


def binary_search(T,SSS):#スライスの値を返す。同じ値があったら右寄りに出す
    left = 0 #SSS[left]はTより真に小さい
    right = len(SSS)-1 #SSS[right]はTと同じかそれ以上

    if T<SSS[left]:
        return 0
    if T>=SSS[right]:
        return right+1

    while True:
        mid = (left+right)//2
        #print(left,mid,right)
        #print(SSS[left],SSS[mid],SSS[right])
        #print()
        if right-left==1:
            return right
        if SSS[mid]<=T:
            left = mid
        else:
            right=mid


ans = 0
for A in AAA:
    for B in BBB[binary_search(A,BBB):]:
        ans += len(CCC)-binary_search(B,CCC)

print(ans)


Fixed submission:
N = int(input())
AAA = sorted([int(i) for i in input().split()])
BBB = sorted([int(i) for i in input().split()])
CCC = sorted([int(i) for i in input().split()])

def upper_bound(T,SSS):#スライスの値を返す。同じ値があったら右寄りに出す
    left = 0 #SSS[left]はTより真に小さい
    right = len(SSS)-1 #SSS[right]はTと同じかそれ以上

    if T<SSS[left]:
        return 0
    if T>=SSS[right]:
        return right+1

    while True:
        mid = (left+right)//2
        #print(left,mid,right)
        #print(SSS[left],SSS[mid],SSS[right])
        #print()
        if right-left==1:
            return right
        if SSS[mid]<=T:
            left = mid
        else:
            right = mid

def lower_bound(T,SSS):#スライスの値を返す。同じ値があったら左寄りに出す
    left = 0 #SSS[left]はTと同じかそれより小さい
    right = len(SSS)-1 #SSS[right]はTより真に大きい

    if T<=SSS[left]:
        return 0
    if T>SSS[right]:
        return right+1

    while True:
        mid = (left+right)//2
        #print(left,mid,right)
        #print(SSS[left],SSS[mid],SSS[right])
        #print()
        if right-left==1:
            return right
        if SSS[mid]<T:
            left = mid
        else:
            right = mid

ans=0
lenCCC = len(CCC)
for B in BBB:
    nA = lower_bound(B,AAA)
    nC = lenCCC-upper_bound(B,CCC)
    ans+=nA*nC
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = input().split()

b = []

ct = 0
for i in range(n):
    if (ct%2) ==0:
        b .append(a[i])
    else:
        b.insert(0,a[i])
    ct += 1


if((n%2)==0):
    print(" ".join([i for i in b]))
else:
    print(" ".join([i for i in b[::-1]])) 

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

b = [0]*n

if (n%2) == 0:
    for i in range(n):
        if(i<(n//2)):
            b[i] = a[n-(2*i)-1]
        else:
            b[i] = a[(i-(n//2))*2]
else:
    for i in range(n):
        if(i<(n//2)):
            b[i] = a[n-(2*i)-1]
        elif i == (n//2):
            b[i]= a[0]
        else:
            b[i] = a[(i-(n//2)-1)*2+1]


print(" ".join([i for i in b]))
Buggy python submission (verdict: Time Limit Exceeded):
import math

n=int(input())

def keta(n):
    return int(math.log10(n)+1)
def max(a,b):
    if a>b :return a
    else: return b

result=100
for i in range(1,n//2+10):
    if n%i==0 and result>max(keta(i),keta(n//i)):
        result=max(keta(i),keta(n//i))
print(result)


Fixed submission:
import math

n=int(input())

def keta(n):
    return int(math.log10(n)+1)
def max(a,b):
    if a>b :return a
    else: return b

result=100
for i in range(1,math.ceil(math.sqrt(n)+3)):
    if n%i==0 and result>max(keta(i),keta(n//i)):
        result=max(keta(i),keta(n//i))
print(result)
Buggy python submission (verdict: Runtime Error):
sx,sy,tx,ty = [int(i) for i in input().split()]
ans = ""
for i in range(ty-sy):
    ans += "U"
for i in range(tx-sx):
    ans += "R"
for i in range(ty-sy):
    ans += "D"
for i in range(tx-sx):
    ans += "L"
ans += "L"
for i in range(ty-sy+1):
    ans += "U"
for i in range(tx-sx+1):
    ans += "R"
ans += "D"
ans += "R"
for i in range(ty-sy+1):
    ans += "D"
for i in range(tx-sx+1):
    ans += "L"
ans += "U"

print(ans==ex)

Fixed submission:
sx,sy,tx,ty = [int(i) for i in input().split()]
ans = ""
for i in range(ty-sy):
    ans += "U"
for i in range(tx-sx):
    ans += "R"
for i in range(ty-sy):
    ans += "D"
for i in range(tx-sx):
    ans += "L"
ans += "L"
for i in range(ty-sy+1):
    ans += "U"
for i in range(tx-sx+1):
    ans += "R"
ans += "D"
ans += "R"
for i in range(ty-sy+1):
    ans += "D"
for i in range(tx-sx+1):
    ans += "L"
ans += "U"

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N,T = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]

maxdiff = 0
ct = 0

for i in range(N):
    for j in range(i+1,N):
        if A[j]-A[i] > maxdiff:
            maxdiff = A[j]-A[i]
            ct = 1
        elif A[j]-A[i] == maxdiff:
            ct += 1

print(ct)

Fixed submission:
N,T = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]

maxdiff = 0
ct = 0
mintmp = float("inf")
for A_i in A:
    mintmp = min(A_i,mintmp)
    diff = A_i - mintmp
    if diff > maxdiff:
        maxdiff = diff
        ct = 1
    elif diff == maxdiff:
        ct += 1
print(ct)
Buggy python submission (verdict: Time Limit Exceeded):
s = str(input())
appeared = []
buff = [0 for i in range(27)]
appeared.append(buff)
for i in s:
    buff = [j for j in appeared[-1]]
    buff[ord(i)-ord("a")] += 1
    appeared.append(buff)


for i in range(0,len(s)):
    for j in range(i+1,len(s)+1):
        buff = [sj-si for sj,si in zip(appeared[j],appeared[i])]
        if max(buff) > (j-i)/2 and j-i>=2:
            print(i+1,j)
            exit()
print("-1 -1")

Fixed submission:
s = str(input())

if len(s)==2 and s[0]==s[1]:
    print(1,2)
    exit()

for i in range(0,len(s)-2):
    buff = s[i:i+3]
    if buff[0]==buff[2]:
        print(i+1,i+3)
        exit()
    elif buff[0]==buff[1]:
        print(i+1,i+2)
        exit()
    elif buff[1]==buff[2]:
        print(i+2,i+3)
        exit()
print(-1,-1)
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = input().split(" ")

s = a[0]

for num in a[1:]:
	s ^= num

ans = [0]*n

for i, num in enumerate(a):
	ans[i] = s^num

print(*ans)

Fixed submission:
n = int(input())
aa = input().split(" ")
a = [int(c) for c in aa]

s = a[0]

for num in a[1:]:
	s ^= num

ans = [0]*n

for i, num in enumerate(a):
	ans[i] = s^num

print(*ans)

Buggy python submission (verdict: Runtime Error):
n = int(input())
a = input().split(" ")

s = a[0]

for num in a[1:]:
	s^=num

ans = [0]*n

for i, num in enumerate(a):
	ans[i] = s^num

print(*ans)


Fixed submission:
n = int(input())
aa = input().split(" ")
a = [int(c) for c in aa]

s = a[0]

for num in a[1:]:
	s ^= num

ans = [0]*n

for i, num in enumerate(a):
	ans[i] = s^num

print(*ans)
Buggy python submission (verdict: Runtime Error):
H, N = map(int,input().split())
Magic = [list(map(int, input().split())) for i in range(N)]
MAX_COST = max(Magic)[1]


dp = [float('inf')] * (H + 1)
dp[0] = 0
for h in range(H):
    for damage, cost in Magic:
        next_index = min(h + damage, H)
        dp[next_index] = min(dp[next_index], dp[h] + cost)
 
print(dp[-1])

Fixed submission:
H, N = map(int,input().split())
Magic = [list(map(int, input().split())) for i in range(N)]
MAX_COST = max(Magic)[1]

dp = [float('inf')] * (H + 1)
dp[0] = 0
for h in range(H):
    for damage, cost in Magic:
        next_index = min(h + damage, H)
        dp[next_index] = min(dp[next_index], dp[h] + cost)
 
print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
H, N = map(int,input().split())
Magic = [list(map(int, input().split())) for i in range(N)]
MAX_COST = max(Magic)[1]


dp = [float('inf')] * (H + 1)
dp[0] = 0
for h in range(H):
    for damage, cost in Magic:
        next_index = min(h + damage, H)
        dp[next_index] = min(dp[next_index], dp[h] + cost)
 
print(dp[-1])

Fixed submission:
H, N = map(int,input().split())
Magic = [list(map(int, input().split())) for i in range(N)]
MAX_COST = max(Magic)[1]

dp = [float('inf')] * (H + 1)
dp[0] = 0
for h in range(H):
    for damage, cost in Magic:
        next_index = min(h + damage, H)
        dp[next_index] = min(dp[next_index], dp[h] + cost)
 
print(dp[-1])

Buggy python submission (verdict: Runtime Error):
Magic = [list(map(int, input().split())) for i in range(N)]
MAX_COST = max(Magic)[1]


dp = [float('inf')] * (H + 1)
dp[0] = 0
for h in range(H):
    for damage, cost in Magic:
        next_index = min(h + damage, H)
        dp[next_index] = min(dp[next_index], dp[h] + cost)
 
print(dp[-1])

Fixed submission:
H, N = map(int,input().split())
Magic = [list(map(int, input().split())) for i in range(N)]
MAX_COST = max(Magic)[1]

dp = [float('inf')] * (H + 1)
dp[0] = 0
for h in range(H):
    for damage, cost in Magic:
        next_index = min(h + damage, H)
        dp[next_index] = min(dp[next_index], dp[h] + cost)
 
print(dp[-1])
Buggy python submission (verdict: Runtime Error):
x = int(input())

for i in range( -1000, 1000) :
  for j in range(-1000, 1000):
	if i**5 - j**5 == x:
      print(i,j)

Fixed submission:
x = int(input())

for i in range( -1000, 1000) :
    for j in range(-1000, 1000):
        if i**5 - j**5 == x:
            print(i,j)
            exit(0)
Buggy python submission (verdict: Runtime Error):
# D
import itertools
from scipy.special import comb
N = int(input())
ans_list = []
K = 0
for i in range(N):
    perm_list = ['a'] * (N - 1 - i)
    perm_list += ['x'] * (i)
    tmp_list = []
    al = [chr(ord('b') + j) for j in range(i)]

    K += comb(N-1, i)

    for v in itertools.permutations(perm_list, len(perm_list)):
        tmp = 'a'
        for j in range(len(perm_list)):
            tmp += v[j]
        tmp_list.append(tmp)
    tmp_list = list(set(tmp_list))
    
    n = len(tmp_list)
    for j in range(n):
        cnt = 0
        for k in range(N):
            if tmp_list[j][k] == "x":
                tmp_list[j] = tmp_list[j].replace("x", al[cnt], 1)
                cnt += 1
        ans_list.append(tmp_list[j])
ans_list.sort()
K = int(K)
for i in range(K):
    print(ans_list[i])

Fixed submission:
# D
N = int(input())

al = [chr(ord('a') + i) for i in range(26)]

def dfs(S, i):
    if len(S) == N:
        yield ''.join(S)
        return
    for j in range(i):
        for w in dfs(S + [al[j]], i):
            yield w
    for w in dfs(S + [al[i]], i + 1):
        yield w

for w in dfs([], 0):
    print(w)
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())
Query = [input() for _ in range(Q)]
flag = True
for i in range(Q):
    if Query[i][0] == "1":
        if flag:
            flag = False
        else:
            flag = True
    else:
        if Query[i][2] == '1':
            if flag:
                S = Query[i][4] + S
            else:
                S = S + Query[i][4]
        else:
            if flag:
                S = S + Query[i][4]
            else:
                S = Query[i][4] + S
if flag:
    print(S)
else:
    print(S[::-1])

Fixed submission:
S = input()
Q = int(input())
Query = [input() for _ in range(Q)]
flag = True
s = "!"
for i in range(Q):
    if Query[i][0] == "1":
        if flag:
            flag = False
        else:
            flag = True
    else:
        if Query[i][2] == '1':
            if flag:
                s = Query[i][4] + s
            else:
                s = s + Query[i][4]
        else:
            if flag:
                s = s + Query[i][4]
            else:
                s = Query[i][4] + s
ans = s.replace("!", S)
if flag:
    print(ans)
else:
    print(ans[::-1])

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())
Query = [input() for _ in range(Q)]

for i in range(Q):
    if Query[i][0] == "1":
        # 反転
        S = S[::-1]
    else:
        if Query[i][2] == '1':
            S = Query[i][4] + S
        else:
            S = S + Query[i][4]
print(S)

Fixed submission:
S = input()
Q = int(input())
Query = [input() for _ in range(Q)]
flag = True
s = "!"
for i in range(Q):
    if Query[i][0] == "1":
        if flag:
            flag = False
        else:
            flag = True
    else:
        if Query[i][2] == '1':
            if flag:
                s = Query[i][4] + s
            else:
                s = s + Query[i][4]
        else:
            if flag:
                s = s + Query[i][4]
            else:
                s = Query[i][4] + s
ans = s.replace("!", S)
if flag:
    print(ans)
else:
    print(ans[::-1])

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())
Query = [input() for _ in range(Q)]

for i in range(Q):
    if Query[i][0] == "1":
        # 反転
        S = S[::-1]
    else:
        if Query[i][2] == '1':
            S = Query[i][4] + S
        else:
            S = S + Query[i][4]
print(S)

Fixed submission:
S = input()
Q = int(input())
Query = [input() for _ in range(Q)]
flag = True
s = "!"
for i in range(Q):
    if Query[i][0] == "1":
        if flag:
            flag = False
        else:
            flag = True
    else:
        if Query[i][2] == '1':
            if flag:
                s = Query[i][4] + s
            else:
                s = s + Query[i][4]
        else:
            if flag:
                s = s + Query[i][4]
            else:
                s = Query[i][4] + s
ans = s.replace("!", S)
if flag:
    print(ans)
else:
    print(ans[::-1])