Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

S = input()
n = int(input())
Q =[list(map(str, input().split())) for _ in range(n)]

flg = True
for q in Q:
    if q[0] == "1":
        flg = not flg
    else:
        if (q[1] == "1" and flg) or (q[1] == "2" and not flg):
            S = q[2] + S
        else:
            S = S + q[2]
if not flg:
    S = S[::-1]
print(S)

### FIXED CODE ###

s = input()
q = int(input())
Q = [list(map(str, input().split())) for _ in range(q)]

t = ''
for qi in Q:
  if int(qi[0]) == 1:
    s, t = t, s
  else:
    if int(qi[1])  == 1:
      t += qi[2]
    else:
      s += qi[2]
      
t = t[::-1]
t += s
print(t)
### BUGGY CODE ###

def main():
    from functools import lru_cache
    import sys
    sys.setrecursionlimit(10 ** 7)

    s = input()

    @lru_cache(maxsize=None)
    def cut(cur, t):
        if cur >= len(s):
            return 0

        ret = -1 << 30
        if t != s[cur]:
            ret = max(ret, cut(cur + 1, s[cur]) + 1)
        if t != s[cur:cur + 2]:
            ret = max(ret, cut(cur + 2, s[cur:cur + 2]) + 1)
        return ret

    ans = cut(0, '')

    print(ans)


if __name__ == '__main__':
    main()

# 一文字か二文字


### FIXED CODE ###

s = input()
n = len(s)

a = []
cont = 0
c = ''
for ss in s:
    if c != ss:
        a.append(cont)
        c = ss
        cont = 1
    else:
        cont += 1
a.append(cont)

ans = 0
minus_flg = False
for aa in a[1:]:
    if minus_flg:
        aa -= 1
        minus_flg = False
    q, r = divmod(aa, 3)
    # print(aa, ans, q, r)
    if r == 0:
        ans += q * 2
    elif r == 1:
        ans += ((aa - 1) // 3) * 2 + 1
    else:
        ans += ((aa + 1) // 3) * 2
        minus_flg = True
if minus_flg:
    ans -= 1
print(ans)
### BUGGY CODE ###

import numpy as np
N = int(input())
P = np.array(list(map(int, input().split())))

ans = 0
for i in range(N):
    if np.count_nonzero(P[:i] >= P[i]) == i:
        ans += 1
print(ans)


### FIXED CODE ###

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

ans = 0
v = P[0]
for i in P:
    if i <= v:
        ans += 1
        v = i
print(ans)
### BUGGY CODE ###

class RollingHash:
    def __init__(self,S,base,M):
        self.N=len(S)
        self.M=M
        self.H=[0]*(self.N+1)
        self.B=[0]*(self.N+1)
        self.B[0]=1
        for i in range(self.N):
            self.B[i+1]=self.B[i]*base%M
            self.H[i+1]=(self.H[i]*base+(ord(S[i])-96))%M
    def get(self,l,r):
        return (self.H[r]-self.H[l]*self.B[r-l]+self.M)%self.M
    def getall(self,L):
        arr=[]
        for i in range(L,self.N+1):
            arr.append(self.get(i-L,i))
        return arr

def Hash(S,base,M):
    H=0
    for c in S:
        H=(H*base+ord(c)-96)%M
    return H
    
import random


N=int(input())
M=2**61-1
base=random.randrange(100,M)
RH,S=[],[]
for i in range(N):
    s=input()
    S.append(s)
    RH.append(RollingHash(s,base,M))

dic={}
dic[0]=[0]*26
for k,s in enumerate(S):
    Set=set()
    l=len(s)
    for j in range(l):
        Hash=RH[k].get(j,l)
        if not Hash in dic:
            dic[Hash]=[0]*26
        for c in Set:
            dic[Hash][ord(c)-97]+=1
        Set.add(s[j])
    for c in Set:
        dic[0][ord(c)-97]+=1
ans=0
for i,s in enumerate(S):
    Hash=RH[i].get(1,len(s))
    ans+=dic[Hash][ord(s[0])-97]-1
print(ans)

### FIXED CODE ###

class RollingHash:
    def __init__(self,S,base,M):
        self.N=len(S)
        self.M=M
        self.H=[0]*(self.N+1)
        self.B=[0]*(self.N+1)
        self.B[0]=1
        for i in range(self.N):
            self.B[i+1]=self.B[i]*base%M
            self.H[i+1]=(self.H[i]*base+(ord(S[i])-96))%M
    def get(self,l,r):
        return (self.H[r]-self.H[l]*self.B[r-l]+self.M)%self.M

def main():
    import random

    N=int(input())
    M=2**61-1
    base=random.randrange(100,M)
    RH,S=[],[]
    RH,S=[None for i in range(N)],[None]*N
    for i in range(N):
        s=input()
        S[i]=s
        RH[i]=RollingHash(s,base,M)

    dic={}
    dic[0]=[0]*26
    for k,s in enumerate(S):
        Set=set()
        l=len(s)
        for j in range(l):
            Hash=RH[k].get(j,l)
            if not Hash in dic:
                dic[Hash]=[0]*26
            for c in Set:
                dic[Hash][ord(c)-97]+=1
            Set.add(s[j])
        for c in Set:
            dic[0][ord(c)-97]+=1
    ans=0
    for i,s in enumerate(S):
        Hash=RH[i].get(1,len(s))
        ans+=dic[Hash][ord(s[0])-97]-1
    print(ans)

if __name__=='__main__':
    main()
### BUGGY CODE ###

S=list(input())
l = len(S)
i = 0
j = -1
ans = 0
while i<l:
    if j==-1 and S[i] == "A":
        j=i
        i+=1
    elif j>=0 and S[i] == "A":
        i+=1
    elif j>=0:
        #"BC"が続く回数を数える
        bc = 0
        k = 0
        for c in S[i:]:
            if bc == 0 and c=="B":
                bc=1
            elif bc == 1 and c=="C":
                bc=0
                k+=1
            else:break
        if k > 0 :
            S[j+2*k-1] = "C"
            S[j+2*k:i+2*k] = ["A"]*(i-j)
            ans += (i-j)*k
            i = j+2*k-1
            j = -1
        else:
            j = -1
            i+=1
    else:
        i+=1
print(ans)

### FIXED CODE ###

S=input().replace("BC","D").replace("B","C").split("C")
ans = 0
for s in S:
    a = 0
    for c in s:
        if c == "A":a+=1
        else:ans += a
print(ans)
### BUGGY CODE ###

from collections import deque
sx,sy,tx,ty = map(int,input().split())
ans_list = []
(tx,ty) = (tx-sx,ty-sy); (sx,sy) = (0,0)
H,W = ty+3,tx+3
visited = [[0]*(tx+3) for i in range(ty+3)]
d = [[1,0],[0,1],[-1,0],[0,-1]]
(sx,sy) = (sx+1,sy+1); (tx,ty) = (tx+1,ty+1)
def bfs(si,sj,gi,gj):
    tr = [[si,sj]]
    q = deque([[si,sj,tr]])
    while q:
        i,j,tr = q.popleft()
        if (i,j) == (gi,gj):
            return tr
        for di,dj in d:
            ni = i + di; nj = j + dj
            if 0 <= ni <= H-1 and 0 <= nj <= W-1 and visited[ni][nj] == 0:
                visited[ni][nj] = 1
                ntr = tr[:]; ntr.append([ni,nj])
                q.append([ni,nj,ntr])

def change(tr):
    def func(d):
        if d == (1,0):return "U"
        if d == (-1,0):return "D"
        if d == (0,-1):return "L"
        if d == (0,1):return "R"
    for i in range(len(tr)-1):
        (ni,nj) = (tr[i+1][0],tr[i+1][1])
        (i,j) = (tr[i][0],tr[i][1])
        d = (ni-i,nj-j)
        ans_list.append(func(d))

res = []
for i in range(4):
    if i == 0:
        res += bfs(sy,sx,ty,tx)
    else:
        res = res[:-1] + bfs(sy,sx,ty,tx)
    visited = [[0]*W for i in range(H)]
    for i,j in res:
        visited[i][j] = 1
    sy,ty = ty,sy; sx,tx = tx,sx
    visited[ty][tx] = 0

change(res)
ans = "".join(ans_list)
print(ans)

### FIXED CODE ###

sx,sy,tx,ty = map(int,input().split())
(tx,ty) = (tx-sx,ty-sy)
route1 = "U"*ty + "R"*tx
route2 = "D"*ty + "L"*tx
route3 = "L" + "U"*(ty+1) + "R"*(tx+1) + "D"
route4 = "R" + "D"*(ty+1) + "L"*(tx+1) + "U"
ans = route1 + route2 + route3 + route4
print(ans)
### BUGGY CODE ###

import sys
import bisect
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

N, Q = map(int, input().split())
STX = []
for _ in range(N):
    s, t, x = map(int, input().split())
    STX.append((s, t, x))

PEOPLE = []
for i in range(Q):
    d = int(input())
    PEOPLE.append((d, i))

ans = [-1] * Q

STX.sort(key=lambda x: x[2])

for s, t, x in STX:
    if len(PEOPLE) == 0:
        break

    i = bisect.bisect_left(PEOPLE, (s - x, -1))
    j = bisect.bisect_left(PEOPLE, (t - x, -1))

    if i == j:
        continue

    use = [PEOPLE[x][1] for x in range(i, j)]

    for k in use:
        ans[k] = x

    del PEOPLE[i:j]


print("\n".join(map(str, ans)))


### FIXED CODE ###

#D in [S_i-X_i,T_i-X_i) → Xiで止まる
import sys
input = sys.stdin.readline
from heapq import heappop,heappush
from collections import defaultdict

N,Q = map(int,input().split())
task = []

STX = [[int(x) for x in input().split()] for _ in range(N)]
for s,t,x in STX:
  task.append((t-x,0,x)) # xで止まらなくなる
  task.append((s-x,1,x)) # xで止まる

for i in range(Q):
  d = int(input())
  task.append((d,2,i)) # 止まる位置を答える
answer = [-1]*Q

task.sort()

# 引っかかってる場所の管理
se = set()
se_hp = [] # heapで最小値を先頭に保つ

# 小さい時刻から順に見ていく
for a,b,c in task:
  if not b: # b == 0
    se.remove(c)
  elif b&1: # b == 1
    se.add(c)
    heappush(se_hp,c)
  else: # b == 2
    while se_hp and se_hp[0] not in se:
      heappop(se_hp)
    answer[c] = se_hp[0] if se_hp else -1

print('\n'.join(map(str,answer)))
### BUGGY CODE ###

n = int(input())
strings = []
nums = []
for i in range(n):
    string = input()
    if string not in strings:
        strings.append(string)
        nums.append(1)
    else:
        nums[strings.index(string)] += 1

l = []
Mx = max(nums)
for i in range(len(strings)):
    if nums[i] == Mx:
        l.append(strings[i])
l.sort()

for i in l:
    print(i)


### FIXED CODE ###

n = int(input())
dic = {}
for i in range(n):
    string = input()
    if string not in dic:
        dic[string] = 1
    else:
        dic[string] += 1

Mx = max(dic.values())
ans = []
for key in dic.keys():    
    if dic[key] == Mx:
        ans.append(key)
ans.sort()
for i in ans:
    print(i)
### BUGGY CODE ###

from itertools import combinations, permutations

N, A, B, C = map(int, input().split(" "))
L = [int(input()) for _ in range(N)]

def f(a):
    s, l, x = a
    return (l-1)*10+abs(s-x)
    

min_num = 10**18
for l in permutations(L):
    # print(l)
    for j1, j2, j3 in combinations(range(N), 3):
        sum_num = sum(map(f, [(sum(l[j1:j2]), j2-j1, A), (sum(l[j2:j3]), j3-j2, B), (sum(l[j3:]), N-j3, C)]))
        # if sum_num < min_num:
            # print(l)
        min_num = min(min_num, sum_num)

print(min_num)

### FIXED CODE ###

from itertools import product

N, *ABC = map(int, input().split(" "))
L = [int(input()) for _ in range(N)]

min_num = 10**18
for i in range(4**N):
    abcz = [[] for _ in range(4)]
    for j in range(N):
        abcz[i//(4**j)%4].append(L[j])
    if [] in abcz[:3]:
        continue
    # print(abcz)
    m = 0
    for l, x in zip(abcz, ABC): 
        m += 10*(len(l)-1) + abs(sum(l)-x)
    # if m < min_num:
    #     print(abcz, m)
    min_num = min(min_num, m)

print(min_num)
### BUGGY CODE ###

n = int(input())
s = input()
min_turn = n
for i in range(n):
  turn = 0
  for j in range(n):
    if j < i:
      if s[j] == 'W':
        turn += 1
    elif j > i:
      if s[j] == 'E':
        turn += 1
    if turn == min_turn:
      break
  if turn < min_turn:
    min_turn = turn
print(min_turn)

### FIXED CODE ###

n = int(input())
s = input()

w = []
for i in range(n):
  if s[i] == 'W':
    diff = 1
  else:
    diff = 0
  
  if i == 0:
    w += [diff]
  else:
    w += [w[i - 1] + diff]

min_turns = n
for i in range(n):
  if i == 0:
    turns = n - 1 - (w[n - 1] - w[i])
  elif i == n - 1:
    turns = w[i - 1]
  else:
    turns = w[i - 1] + n - (i + 1) - (w[n - 1] - w[i])
  
  if turns < min_turns:
    min_turns = turns

print(min_turns)
### BUGGY CODE ###

MOD = 10**9+7
fac = [1, 1]
f_inv = [1, 1]
inv = [0, 1]

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


def modcmb(n, r, mod):
    if n < 0 or r < 0 or r > n:
        return 0

    return fac[n] * f_inv[r] * f_inv[n-r] % mod


def f(r, c):
    return modcmb(r+c, r, MOD)


def g(x, y):
    return ((y+2) * modcmb(x+y+2, x, MOD) - (x+1)) * pow(x+1, MOD-2, MOD)


def main():
    prepare(2*10**6+10, MOD)
    r1,c1,r2,c2 = map(int, input().split())

    ans = g(r2, c2) - g(r1-1, c2) - g(r2, c1-1) + g(r1-1, c1-1)
    ans %= MOD

    print(ans)


if __name__ == "__main__":
    main()


### FIXED CODE ###

MOD = 10**9+7
fac = [1, 1]
f_inv = [1, 1]
inv = [0, 1]

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


def modcmb(n, r, mod):
    if n < 0 or r < 0 or r > n:
        return 0

    return fac[n] * f_inv[r] * f_inv[n-r] % mod


def f(r, c):
    return modcmb(r+c, r, MOD)


def main():
    prepare(2*10**6+10, MOD)
    r1,c1,r2,c2 = map(int, input().split())

    ans = 0
    for i in range(1,c2+2):
        ans += f(r2, i)
        ans %= MOD

    for i in range(1,c2+2):
        ans -= f(r1-1, i)
        ans %= MOD

    for i in range(1,c1+1):
        ans -= f(r2, i)
        ans %= MOD

    for i in range(1,c1+1):
        ans += f(r1-1, i)
        ans %= MOD

    print(ans % MOD)


if __name__ == "__main__":
    main()
### BUGGY CODE ###

def main():
    def pre(n,mod):
        a=1
        for i in range(1,n+1):
            a=(a*i)%mod
        an=a
        b=pow(a,mod-2,mod)
        bs=[1]*(n+1)
        bs[n]=b
        for i in range(n,1,-1):
            b=b*i%mod
            bs[i-1]=b
        return an,bs

    n,k=map(int,input().split())
    a=sorted(list(map(int,input().split())))
    mod=10**9+7
    an,bs=pre(n,mod)
    ans=0
    for i in range(k,n+1):
        if i==k:
            c=1
        else:
            c=(c*(i-2)*pow(i-k,mod-2,mod))%mod
        for j in range(0,n-i+1):
            ans=(ans+(a[i+j-1]-a[j])*c)%mod
    print(ans)

if __name__ == '__main__':
    main()

### FIXED CODE ###

def main():
    n,k=map(int,input().split())
    a=sorted(list(map(int,input().split())))
    mod=10**9+7
    ans=0
    for i in range(k-1,n):
        if i==k-1:
            c=1
        else:
            c=(c*i*pow(i-k+1,mod-2,mod))%mod
        ans+=(a[i]-a[n-i-1])*c
        ans%=mod
    print(ans)

if __name__ == '__main__':
    main()
### BUGGY CODE ###

S = str(input())
N = len(S)
l = 0
r = 0


follow = 0
amari = [0] * N
for i in range(N):
  Kazu = int(S[N-i-1]) * pow(10, i)
  Amari_ = (int(Kazu) + follow) % 2019
  amari[i] = Amari_
  follow = Amari_
  

from collections import Counter
c = Counter(amari).most_common()

ans = 0
for i in c:
  if i[1] != 0:
    ans += i[1] * (i[1]-1) // 2
  if i[0] == 0:
    ans += i[1]
print(ans)

### FIXED CODE ###

S = str(input())
N = len(S)

ans = 0
amari = [0] * 2019
amari[0] = 1
follow = 0
POW = 1

for i in reversed(S):
  follow += int(i) * POW
  follow %= 2019
  amari[follow] += 1
  POW *= 10
  POW %= 2019
  
print(sum( i * (i-1) // 2 for i in amari ))
### BUGGY CODE ###

N=int(input())
A=[]
for _ in range(N):
  A.append(int(input()))

index = A.index(max(A))
for i in range(N):
  if i==index:
    b=A.pop(i)
    print(max(A))
    A.insert(i,b)
  else:
      print(max(A))

### FIXED CODE ###

N=int(input())
A=[]
for _ in range(N):
  A.append(int(input()))

value=max(A)
index = A.index(max(A))
for i in range(N):
  if i==index:
    b=A.pop(i)
    print(max(A))
  else:
      print(value)
### BUGGY CODE ###

import sys
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def II(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def SI(): return input()
YN = lambda b: print('YES') if b else print('NO')
yn = lambda b: print('Yes') if b else print('No')

N, M = LI()
demands = []
for i in range(M):
    demands.append(LI())

demands = sorted(demands, key=lambda x: x[1])

counter = 0
while demands:
    demand = demands.pop(0)
    counter += 1
    deleting_bridge = demand[1]-1
    delete_flag = []
    for i, d in enumerate(demands):
        if d[0] <= deleting_bridge:
            delete_flag.append(i)
    for i in reversed(delete_flag):
        demands.pop(i)

print(counter)

### FIXED CODE ###

import sys
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def II(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def SI(): return input()
YN = lambda b: print('YES') if b else print('NO')
yn = lambda b: print('Yes') if b else print('No')

def main():
    N, M = LI()
    demands = []
    for i in range(M):
        demands.append(LI())

    demands = sorted(demands, key=lambda x: x[1])
    demands_met_flag = [False]*len(demands)

    counter = 0
    deleting_bridge = 0
    for i in range(len(demands)):
        if demands_met_flag[i] == True: continue
        if demands[i][0] <= deleting_bridge:
            demands_met_flag[i] = True
            continue
        demand = demands[i]
        demands_met_flag[i] = True
        counter += 1
        deleting_bridge = demand[1]-1

    print(counter)

main()
### BUGGY CODE ###

q=int(input())
A=[]
b=0
def f(A,b,n):
  res=0
  for a in A:
    res+=abs(a-n)
  return res+b
for _ in range(q):
  L=[int(i) for i in input().split()]
  if L[0]==1:
    A.append(L[1])
    b+=L[2]
  else:
    A.sort()
    n=A[(len(A)-1)//2]
    print(n,f(A,b,n))


### FIXED CODE ###

from heapq import heappop
from heapq import heappush
q=int(input())
L,R=[],[]
b_sum=0
l_sum,r_sum=0,0
count=0
mid=0
for _ in range(q):
  
  Q=list(map(int,input().split()))
  if Q[0]==1:
    a,b=Q[1],Q[2]
    count+=1
    b_sum+=b
    if count==1:
      mid=a
    elif count%2==0:
      if a<=mid:
        heappush(L,-a)
        l_sum+=a
        heappush(R,mid)
        r_sum+=mid
      else:
        heappush(L,-mid)
        l_sum+=mid
        heappush(R,a)
        r_sum+=a
    else:
      l,r=-heappop(L),heappop(R)
      if a<l:
        heappush(L,-a)
        l_sum+=a-l
        mid=l
        heappush(R,r)
      elif r<a:
        heappush(L,-l)
        mid=r
        heappush(R,a)
        r_sum+=a-r
      else:
        heappush(L,-l)
        mid=a
        heappush(R,r)

  else:
    if count%2==1:
      print(mid,r_sum-l_sum+b_sum)
    else:
      l=-heappop(L)
      print(l,r_sum-l_sum+b_sum)
      heappush(L,-l)
### BUGGY CODE ###

N, M = map(int, input().split())
a = [int(input()) for i in range(M)]
dp = [0] * (N+1)
for i in range(N+1):
  if i in a:
    dp[i] = 0
  elif i <= 1:
    dp[i] = 1
  else:
    dp[i] = (dp[i-1] + dp[i-2]) % (10**9+7)
print(dp[N])

### FIXED CODE ###

N, M = map(int, input().split())
b = [False] * (N+1)
for i in range(M):
  a = int(input())
  b[a] = True
dp = [0] * (N+1)

for i in range(N+1):
  if b[i]:
    dp[i] = 0
  elif i <= 1:
    dp[i] = 1
  else:
    dp[i] = (dp[i-1] + dp[i-2]) % (10**9+7)
print(dp[N])
### BUGGY CODE ###

import sys
input = sys.stdin.readline
N, M = list(map(int, input().split()))

def f(D, S, T):
    close = [[False] * N, [False] * N, [False] * N]
    Q = []
    index = 0
    Q.append((S, 0, 0))

    while len(Q) > index:
        p, c, l = Q[index]
        index += 1
        if l == 0 and p == T:
            return c
        close[l][p] = True

        l, c = (l + 1) % 3, c + (l + 1) // 3
        for n in D[p]:
            if close[l][n]:
                continue
            Q.append((n, c, l))
    return -1

if __name__ == "__main__":
    D = {n: set() for n in range(N)}
    for m in range(M):
        u, v = map(int, input().split())
        u -= 1
        v -= 1
        D[u].add(v)

    S, T = list(map(int, input().split()))
    S -= 1
    T -= 1

    print(f(D, S, T))


### FIXED CODE ###

import sys
input = sys.stdin.readline
N, M = list(map(int, input().split()))

def f(D, S, T):
    close = [[False] * N, [False] * N, [False] * N]
    Q = []
    index = 0
    Q.append((S, 0, 0))

    while len(Q) > index:
        p, c, l = Q[index]
        index += 1
        
        if close[l][p]:
            continue
        
        if l == 0 and p == T:
            return c // 3
        close[l][p] = True

        l, c = (l + 1) % 3, c + 1
        for n in D[p]:
            if close[l][n]:
                continue
            Q.append((n, c, l))
    return -1

if __name__ == "__main__":
    D = {n: set() for n in range(N)}
    for m in range(M):
        u, v = map(int, input().split())
        u -= 1
        v -= 1
        D[u].add(v)

    S, T = list(map(int, input().split()))
    S -= 1
    T -= 1

    print(f(D, S, T))
### BUGGY CODE ###

n=int(input())
a=list(map(int, input().split()))
ans =1
for i in a:
    ans *= i
if ans > 10**18:
    print(-1)
    exit()    
print(ans)

### FIXED CODE ###

n=int(input())
a=list(map(int, input().split()))
ans = 1
if a.count(0)>0:
    print(0)
    exit()
for i in range(n):
    l = len(str(ans))
    L = len(str(a[i]))
    if a[i] > 10**18:
        print(-1)
        exit()
    elif l+L > 20:
        print(-1)
        exit()
    ans *= a[i]
    if ans > 10**18:
        print(-1)
        exit()
print(ans)
### BUGGY CODE ###

S = input()
k = int(input())
A = set(S[0])
for i in range(len(S)):
	for j in range(len(S)-i+1):
		A.add(S[j:j+i+1])
A = list(A)
A.sort()
print(A[k])

### FIXED CODE ###

S = input()
k = int(input())
A = set()
for l in range(k+1):
	for i in range(len(S)-l):
			A.add(S[i:i+l+1])
A = sorted(list(A))
print(A[k-1])
### BUGGY CODE ###

B,W = map(int, input().split())
N = B+W

factorial = [1]
for i in range(N+1):
    factorial.append( factorial[-1] * (i+1))
# print(factorial)

mod = 10**9+7

de_factorial = [0] * (N+1)
de_factorial[N] = pow(  factorial[N] , mod-2, mod  )

for i in range( N, 0, -1):
    de_factorial[i-1] = de_factorial[i] * i

# print(de_factorial)

def comb(n,r):
    if n < r: return 0
    if n == r: return 1
    return (factorial[n] * de_factorial[r] * de_factorial[n-r]) % mod


p = [0] * (N+1) # Bを食べきった確率
q = [0] * (N+1) # Wを食べきった確率

for i in range(1, N+1):
    # 確率はこの表現で本当に正しいのか？
    # p[i-1] と comb(i,B)は排他事象 ではない気がする。
    # comb(i,B)でもi-1 でB食べきってしまう p[i-1] の確率が存在するので　
    p[i] = p[i-1] + comb(i-1 ,B-1) * pow(de_factorial[2], i, mod)
    q[i] = q[i-1] + comb(i-1 ,W-1) * pow(de_factorial[2], i, mod)

# print(p)
# print(q)
for i in range(1, N+1):
    tmp = 0
    tmp = ( q[i-1] + 1-p[i-1] ) * de_factorial[2] % mod
    

    print(tmp % mod)

### FIXED CODE ###

B,W = map(int, input().split())
N = B+W
mod = 10**9+7

factorial = [1]
for i in range(N+1):
    factorial.append( factorial[-1] * (i+1) % mod)
# print(factorial)



de_factorial = [0] * (N+1)
de_factorial[N] = pow(  factorial[N] , mod-2, mod  )

for i in range( N, 0, -1):
    de_factorial[i-1] = de_factorial[i] * i % mod
    
def comb(n,r):
    if n < r: return 0
    if n == r: return 1
    return (factorial[n] * de_factorial[r] * de_factorial[n-r]) % mod


p = [0] * (N+1) # Bを食べきった確率
q = [0] * (N+1) # Wを食べきった確率

de2 = de_factorial[2]
for i in range(1, N+1):
    p[i] = p[i-1] + comb(i-1 ,B-1) * de2 % mod 
    q[i] = q[i-1] + comb(i-1 ,W-1) * de2  % mod 
    de2 = de2 * de_factorial[2] % mod

    tmp = ( q[i-1] + 1-p[i-1] ) * de_factorial[2] % mod
    
    print(tmp)
### BUGGY CODE ###

#!/usr/bin python3
# -*- coding: utf-8 -*-

def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))

    for i in range(min(K,100)):
        dm = [0]*N
        for x in range(N):
            dm[max(x - A[x],0)]+=1
            if x+A[x]+1<N:
                dm[x+A[x]+1]+=-1
        for j in range(1,N):
            dm[j]=dm[j-1]+dm[j]
        A[:] = dm[:]
    print(*A)

if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin python3
# -*- coding: utf-8 -*-

def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))

    for i in range(min(K,50)):
        dm = [0]*N
        for x in range(N):
            dm[max(x - A[x],0)]+=1
            if x+A[x]+1<N:
                dm[x+A[x]+1]+=-1
        for j in range(1,N):
            dm[j]=dm[j-1]+dm[j]
        A[:] = dm[:]
    print(*A)

if __name__ == '__main__':
    main()