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

A = int(input())
r = []
for i in range(A):
    r.append(int(input()))
max_r = max(r)
for i in range(A):
    if max_r == r[i]:
        r.pop(i)
        print(max(r))
        r.insert(i,max_r)
    else:
        print(max_r)

### FIXED CODE ###

A = int(input())
No1,No2 = 0,0
for i in range(A):
    B = int(input())
    if No2 < B:
        No2 = B
        if No1 < B:
            place = i
        No1,No2 = max(No1,No2),min(No1,No2)
if No1 == No2:
    for i in range(A):
        print(No1)
else:
    for i in range(place):
        print(No1)
    print(No2)
    for i in range(A-place-1):
        print(No1)
### BUGGY CODE ###

from collections import Counter
from copy import deepcopy

def main():
    n = int(input())
    A = [int(x) for x in input().split()]
    a_c = Counter(A)
    res = [int(v*(v-1)/2) for v in a_c.values()]
    cnt = sum(res)
    for a in A:
        a_c_c = deepcopy(a_c)
        ans = (cnt - (a_c_c[a]-1))
        print(ans)

if __name__ == '__main__':
    main()

### FIXED CODE ###

from collections import Counter
 
def main():
    n = int(input())
    A = [int(x) for x in input().split()]
    a_c = Counter(A)
    res = [int(v*(v-1)/2) for v in a_c.values()]
    cnt = sum(res)
    for a in A:
        ans = (cnt - (a_c[a]-1))
        print(ans)
 
if __name__ == '__main__':
    main()
### BUGGY CODE ###

n = int(input())

d = {}
for i in range(n):
    s = input()
    if s in d:
        d[s] += 1
    else:
        d[s] = 1

for i in sorted(k for k in d if d[k] == max(d.values())):
    print(i)

### FIXED CODE ###

n = int(input())

d = {}
for i in range(n):
    s = input()
    if s in d:
        d[s] += 1
    else:
        d[s] = 1

m = max(d.values())
for i in sorted(k for k in d if d[k] == m):
    print(i)
### BUGGY CODE ###

def main():
  n = int(input())
  a = list(map(int ,input().split()))
  ans = 0
  for x in range(min(a)-1, max(a)+2):
    cnt = 0
    for i in range(n):
      if abs(x-a[i]) <= 1:
        cnt += 1
    ans = max(ans, cnt)

  print(ans)
if __name__ == '__main__':
  main()

### FIXED CODE ###

def main():
  n = int(input())
  a = tuple(map(int ,input().split()))

  ans = [0]*(10**6)
  for x in a:
    ans[x-1] += 1
    ans[x] += 1
    ans[x+1] += 1
  print(max(ans))
if __name__ == '__main__':
  main()
### BUGGY CODE ###

import itertools


def main():
    N, M, R = list(map(int, input().split()))

    r = [int(a)-1 for a in input().split()]

    d = [[float('inf')]*N for _ in range(N)]

    for _ in range(M):
        a, b, c = list(map(int, input().split()))
        d[a-1][b-1] = c
        d[b-1][a-1] = c

    for a in range(N):
        d[a][a] = 0

    res = float('inf')

    for a, b, c in itertools.product(range(N), repeat=3):
        d[b][c] = min(d[b][c], d[b][a]+d[a][c])

    for perm in itertools.permutations(r):
        a = 0
        for i in range(len(perm)-1):
            a += d[perm[i]][perm[i+1]]
        res = min(a, res)

    print(res)

if __name__ == '__main__':
    main()


### FIXED CODE ###

import itertools
import sys

def readline():
    return sys.stdin.readline()

def read_int_list():
    return list(map(int, readline().split()))

def read_int():
    return int(readline())

def main():
    N, M, R = map(int, input().split())
    r = map(int, input().split())

    inf = float("inf")
    d = [[inf] * (N + 1) for _ in range(N + 1)]
    for n in range(1, N + 1):
        d[n][n] = 0

    for _ in range(M):
        a, b, c = map(int, input().split())
        d[a][b] = c
        d[b][a] = c

    for k in range(1, N + 1):
        for i in range(1, N + 1):
            for j in range(1, N + 1):
                if d[i][j] > d[i][k] + d[k][j]:
                    d[i][j] = d[i][k] + d[k][j]

    min_cost = inf
    for p in itertools.permutations(r):
        cost = 0
        for i in range(len(p) - 1):
            src, dst = p[i:i + 2]
            cost += d[src][dst]
        min_cost = min(min_cost, cost)

    print(min_cost)


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

N=int(input())
S=str(input())

list=list(S)

kei=[]
for a in range(N-2):
    for b in range(a+1,N-1):
        if b<=a:
            continue
        for c in range(b+1,N):
            if c<=b:
                continue
            #print(a,b,c)
            retsu=''
            retsu=retsu+list[a]+list[b]+list[c]
            kei.append(retsu)
last=set(kei)
print(len(last))


### FIXED CODE ###

N=int(input())
S=str(input())

list=list(S)

count=0
for a in range(10):
    find1=S.find(str(a))
    if find1==-1:
        continue
    for b in range(10):
        find2=S[find1+1:].find(str(b))
        if find2==-1:
            continue
        for c in range(10):
            find3=S[find1+1+find2+1:].find(str(c))
            if find3==-1:
                continue
            count+=1
print(count)
### BUGGY CODE ###

from collections import deque
h,w=map(int,input().split())
ch,cw=map(int,input().split())
dh,dw=map(int,input().split())

maze = [list(input()) for i in range(h)]
ans = [[-1]*w for i in range(h)]

dx=[0,1,0,-1]
dy=[1,0,-1,0]

ans[ch-1][cw-1]=0
def bfs(ans):
  qu = deque([])
  qu.append([cw-1,ch-1])
  while qu:
    zahyou=qu.popleft()
    x=zahyou[0]
    y=zahyou[1]
    for i in range(4):
      if 0 <= x+dx[i] < w and 0 <= y+dy[i] < h:
        if maze[y+dy[i]][x+dx[i]]=="." and (ans[y+dy[i]][x+dx[i]]>ans[y][x] or ans[y+dy[i]][x+dx[i]]==-1):
          qu.appendleft([x+dx[i],y+dy[i]])
          ans[y+dy[i]][x+dx[i]] = ans[y][x]
    for i in range(x-2,x+3):
      for j in range(y-2,y+3):
        if 0<=i<w and 0<=j<h:
          if maze[j][i]=="." and (ans[j][i]>ans[y][x]+1 or ans[j][i]==-1):
            ans[j][i]=(ans[y][x]+1)
            qu.append([i,j])

bfs(ans)
print(ans[dh-1][dw-1])
  



### FIXED CODE ###

from collections import deque
h,w=map(int,input().split())
ch,cw=map(int,input().split())
dh,dw=map(int,input().split())

maze = [list(input()) for i in range(h)]
ans = [[-1]*w for i in range(h)]

dx=[0,1,0,-1]
dy=[1,0,-1,0]

ans[ch-1][cw-1]=0
def bfs(ans):
  qu = deque([])
  qu.append([cw-1,ch-1])
  while qu:
    zahyou=qu.popleft()
    x=zahyou[0]
    y=zahyou[1]
    count=0
    for i in range(4):
      if 0 <= x+dx[i] < w and 0 <= y+dy[i] < h:
        if maze[y+dy[i]][x+dx[i]]=="." and (ans[y+dy[i]][x+dx[i]]>ans[y][x] or ans[y+dy[i]][x+dx[i]]==-1):
          qu.appendleft([x+dx[i],y+dy[i]])
          ans[y+dy[i]][x+dx[i]] = ans[y][x]
          count+=1
    if count!=4:
      for i in range(x-2,x+3):
        for j in range(y-2,y+3):
          if 0<=i<w and 0<=j<h:
            if maze[j][i]=="." and (ans[j][i]>ans[y][x]+1 or ans[j][i]==-1):
              ans[j][i]=(ans[y][x]+1)
              qu.append([i,j])

bfs(ans)
print(ans[dh-1][dw-1])
### BUGGY CODE ###

N, K = map(int, input().split())
h = [int(x) for x in input().split()]

INF = float('inf')
dp = [INF for _ in range(N+10)]

# initial state
dp[0] = 0

for i in range(N):
    for j in range(1, min(K+1, len(h)-i)):
        dp[i+j] = min(dp[i] + abs(h[j+i] - h[i]), dp[i+j])

print(dp[N-1])

### FIXED CODE ###

N, K = map(int, input().split())
h = [int(x) for x in input().split()]

INF = float('inf')
dp = [INF for _ in range(N+K+10)]

# initial state
dp[0] = 0

for i in range(N):
    for j in range(1, min(K+1, len(h)-i)):
        dp[i+j] = min(dp[i] + abs(h[j+i] - h[i]), dp[i+j])

print(dp[N-1])
### BUGGY CODE ###

a, b, x = map(int, input().split())

l = []

for i in range(a, b+1):
  l.append(i)
  
co = 0

for i in range(len(l)):
  if l[i] % x == 0:
    co += 1

print(co)

### FIXED CODE ###

a, b, x = map(int, input().split())

print(b//x - (a-1)//x)
### BUGGY CODE ###

# input
N, K, C = map(int, input().split())
S = input()

# process/output
def eq(l):
    return l.count(l[0]) == len(l)

days = [0]*(N+1)

for i in range(N):
    if i+1 < N and S[i] == 'x':
        days[i+1] = days[i]
    else:
        if eq(days[max(0,i-C):i+1]):
            days[i+1] = days[i]+1
        else:
            days[i+1] = days[i]

if max(days) <= K:
    for i in range(N):
        if S[i] == 'x':
            days[i+1] = 0

    k = max(days)
    i = N
    if days[i] != k:
        i -= 1
    while k > 0:
        for j in range(max(1, i-C), i):
            if days[j] != k:
                days[j] = 0

        while days[i] in (0, k):
            i -= 1
            if i == 0:
                break

        k = days[i]
        
    # print(days)
    for k in range(1, K+1):
        if days.count(k)==1:
            print(days.index(k))


### FIXED CODE ###

# input
N, K, C = map(int, input().split())
S = input()

# process
l = [i+1 for i in range(N) if S[i] == 'o']
left = [l[0]]
right = [l[-1]]
for i in range(1, len(l)):
    if l[i] > left[-1]+C:
        left.append(l[i])
    if l[-i-1] < right[-1]-C:
        right.append(l[-i-1])

# output
# print(l)
# print(left)
# print(right)
if len(left) == K:
    for i in range(len(left)):
        if left[i] == right[-i-1]:
            print(left[i])
### BUGGY CODE ###

n = int(input())
A = [int(i) for i in input().split()]
b = []

for i in range(n):
    if i % 2 != 0:
        b = [A[i]] + b
    else:
        b += [A[i]]

if n % 2 != 0:
    b = b[n-1: : -1]

print(" ".join(map(str, b)))

### FIXED CODE ###

n = int(input())
A = [int(i) for i in input().split()]

if n % 2 != 0:
    r = A[1::2]
    l = A[::2]
else:
    r = A[::2]
    l = A[1::2]
l.reverse()
print(" ".join(map(str, l + r)))
### BUGGY CODE ###

from sys import stdin

n, k = (int(x) for x in stdin.readline().rstrip().split())
p = [int(x) for x in stdin.readline().rstrip().split()]
ev = [((i*(i+1))/2)/i for i in p]

m = 0
for i in range(n-k+1):
    a = [ev[x] for x in range(i, i+k)]
    if m < sum(a):
        m = sum(a)

print(m)

### FIXED CODE ###

from sys import stdin

n, k = (int(x) for x in stdin.readline().rstrip().split())
p = [int(x) for x in stdin.readline().rstrip().split()]
ev = [(i+1)/2 for i in p]
s = [ev[0]]
for i in range(1, n):
    s.append(s[i-1] + ev[i])

m = s[k-1]
for j in range(n-k):
    a = s[j+k] - s[j]
    if m < a:
        m = a

print(m)
### BUGGY CODE ###

N,Q = map(int,input().split())
S = input()

ans = []
for i in range(Q):
    count = 0
    l,r = map(int,input().split())
    l -= 1
    r -= 1
    last = ''
    for j in range(l,r+1):
        if S[j] == 'C' and last == 'A':
            count += 1
        last = S[j]
    ans.append(count)

for a in ans:
    print(a)


### FIXED CODE ###

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

ac = [0]*(len(S)+1)
last = ''
for i in range(len(S)):
    s = S[i]
    if s=='C' and last == 'A':
        ac[i-1] = 1
    last = s

add = [0]*(len(S)+2)
for i in range(len(ac)):
    add[i+1] = add[i] + ac[i]

for j in range(Q):
    l,r = map(int,input().split())
    l -= 1
    r -= 1
    sub = add[r] - add[l]
    ans.append(sub)

for a in ans:
    print(a)
### BUGGY CODE ###

import math

def comb(n, k, m):
  nf  = math.factorial(n)   % m
  kf  = math.factorial(k)   % m
  nkf = math.factorial(n-k) % m
  return nf * pow_mod(kf, m-2, m) * pow_mod(nkf, m-2, m) % m

def pow_mod(a, b, m):
  if b == 0:
    return 1
  elif b%2 == 0:
    return pow_mod(a, b//2, m) ** 2 % m 
  else:
    return pow_mod(a, b-1, m) * a % m

tmp = list(map(int, input().split()))
x = tmp[0]
y = tmp[1]

ans = 0
mod = 10**9 + 7

if (x + y) % 3 != 0:
  ans = 0
else:
  n = (x + y) // 3
  if min(x, y) < n:
    ans = 0
  elif min(x,y) == n:
    ans = 1
  else:
    r = min(x, y) - n
    ans = comb(n, r, mod)

print(ans)

### FIXED CODE ###

import math

def comb(n, k, m):
  f = [1] * (n+1)
  for i in range(1, n+1):
    f[i] = f[i-1] * i % m
  return f[n] * pow_mod(f[k]*f[n-k]%m, m-2, m) % m

def pow_mod(a, b, m):
  if b == 0:
    return 1
  elif b%2 == 0:
    d = pow_mod(a, b//2, m) % m
    return d * d % m 
  else:
    d = pow_mod(a, (b-1)//2, m)
    return  d * d * a % m

tmp = list(map(int, input().split()))
x = tmp[0]
y = tmp[1]

ans = 0
mod = 10**9 + 7

if (x + y) % 3 != 0:
  ans = 0
else:
  n = (x + y) // 3
  if min(x, y) < n:
    ans = 0
  elif min(x,y) == n:
    ans = 1
  else:
    r = min(x, y) - n
    ans = comb(n, r, mod)

print(ans)
### BUGGY CODE ###

import queue


def make_state(N):
    state = [[-1 for j in range(N+1)] for i in range(N+1)]
    min_state = 0
    s = min_state
    for i in range(1, N+1):
        for j in range(1, i):
            state[i][j] = s
            state[j][i] = s
            s += 1
    return state


def solve(N, A):
    state = make_state(N)
    max_state = N * (N-1) // 2
    prev_states = [[] for i in range(max_state)]
    next_states = [[] for i in range(max_state)]
    for i in range(1, N+1):
        for k in range(N-2):
            ps = state[i][A[i][k]]
            ns = state[i][A[i][k+1]]
            prev_states[ns].append(ps)
            next_states[ps].append(ns)
    
    today_states = queue.Queue()
    for s in range(max_state):
        if len(prev_states[s]) == 0:
            today_states.put(s)
    
    n_days = 0
    n_states_left = max_state
    while today_states.qsize() > 0:
        n_days += 1
        n_today_states = today_states.qsize()
        if n_today_states == 0:
            break
        for _ in range(n_today_states):
            s = today_states.get()
            n_states_left -= 1
            for ns in next_states[s]:
                prev_states[ns].remove(s)
                if len(prev_states[ns]) == 0:
                    today_states.put(ns)
    return n_days if n_states_left == 0 else -1


def main():
    N = int(input())
    A = list()
    A.append([])
    for i in range(N):
        a = list(map(int, input().strip().split()))
        A.append(a)
    print(solve(N, A))


if __name__ == "__main__":
    main()


### FIXED CODE ###

def make_state(N):
    state = [[-1 for j in range(N+1)] for i in range(N+1)]
    min_state = 0
    s = min_state
    for i in range(1, N+1):
        for j in range(1, i):
            state[i][j] = s
            state[j][i] = s
            s += 1
    return state


def solve(N, A):
    state = make_state(N)
    max_state = N * (N-1) // 2
    n_prev_states = [0 for i in range(max_state)]
    next_states = [set() for i in range(max_state)]
    for i in range(1, N+1):
        for k in range(N-2):
            ps = state[i][A[i][k]]
            ns = state[i][A[i][k+1]]
            n_prev_states[ns] += 1
            next_states[ps].add(ns)
    
    today_states = set()
    for s in range(max_state):
        if n_prev_states[s] == 0:
            today_states.add(s)
    
    n_days = 0
    n_states_left = max_state
    while len(today_states) > 0:
        n_days += 1
        if len(today_states) == 0:
            break
        n_states_left -= len(today_states)
        nextday_states = set()
        for s in today_states:
            for ns in next_states[s]:
                n_prev_states[ns] -= 1
                if n_prev_states[ns] == 0:
                    nextday_states.add(ns)
        today_states = nextday_states
    return n_days if n_states_left == 0 else -1


def main():
    N = int(input())
    A = list()
    A.append([])
    for i in range(N):
        a = list(map(int, input().strip().split()))
        A.append(a)
    print(solve(N, A))


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

R, G, B, N = map(int, input().split())

count = 0

tmp_lst = [R, G, B]
tmp_lst.sort()
X, Y, Z = tmp_lst[0], tmp_lst[1], tmp_lst[2]

x_max = int(N/X)    #   max の中では一番大きい
y_max = int(N/Y)
z_max = int(N/Z)

#print(x_max, y_max, z_max, X, Y, Z)

for z in range(z_max + 1):
    for y in range(y_max + 1):
        tmp = N - z*Z - y*Y
        if tmp < 0:
            break
        if tmp % X == 0 and tmp // X <= x_max:
#            print(tmp // X, y, z)
            count += 1

print(count)

### FIXED CODE ###

R, G, B, N = map(int, input().split())

count = 0

tmp_lst = [R, G, B]
tmp_lst.sort()
X, Y, Z = tmp_lst[0], tmp_lst[1], tmp_lst[2]

x_max = int(N/X)    #   max の中では一番大きい
y_max = int(N/Y)
z_max = int(N/Z)

#print(x_max, y_max, z_max, X, Y, Z)

for z in range(z_max + 1):
    for y in range(y_max + 1):
        tmp = N - z*Z - y*Y
        if tmp < 0:
            break
        if tmp % X == 0 and tmp // X <= x_max:
#            print(tmp // X, y, z)
            count += 1

print(count)
### BUGGY CODE ###

a,b,c,d=map(int,input().split())
while a*c!=0:
    c-=b
    if c<=0:
        print("Yes")
    else:
        a-=d
        if a<=0:
            print("No")
        else:
            continue


### FIXED CODE ###

a,b,c,d=map(int,input().split())
while a*c!=0:
    c-=b
    if c<=0:
        print("Yes")
        exit()
    else:
        a-=d
        if a<=0:
            print("No")
            exit()
### BUGGY CODE ###

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

mod = 10**9+7
ans = 0

for i in range(N-1):
    ans += A[i] * (sum(A[i+1:]))
print(ans%mod)


### FIXED CODE ###

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

mod = 10**9+7
s = sum(A)
ans = 0

for i in range(N-1):
    s -= A[i]
    ans += A[i] * s
print(ans%mod)
### BUGGY CODE ###

import bisect
n = int(input())
s = input()
R,G,B = [],[],[]
for i in range(n):
    if s[i]=='R':
        R.append(i)
    elif s[i]=='G':
        G.append(i)
    else:
        B.append(i)
if len(R)==0 or len(G)==0 or len(B)==0:
    print(0)
    exit()
cnt = 0
for r in R:
    for g in G:
        a,b = min(r,g), max(r,g)
        if 2*a-b in B:
            cnt += 1
        if 2*b-a in B:
            cnt += 1
        if (b-a)%2==0 and a+(b-a)//2 in B:
            cnt += 1
print(len(R)*len(G)*len(B)-cnt)

### FIXED CODE ###

n = int(input())
s = input()
ans = s.count('R')*s.count('G')*s.count('B')
if ans==0:
    print(ans)
else:
    for i in range(n):
        for j in range(i+1, n):
            k=2*j-i
            if k<n:
                if s[i]!=s[j] and s[j]!=s[k] and s[i]!=s[k]:
                    ans -= 1
    print(ans)
### BUGGY CODE ###

def main():
	import sys
	sys.setrecursionlimit(700000)
	N, Q = map(int, input().split())
	d = [[] for i in range(N)]

	for i in range(N-1):
		a, b = map(int, input().split())
		a -= 1
		b -= 1
		d[b].append(a)
		d[a].append(b)

	ans = [0]*N

	for i in range(Q):
		p, x = map(int, input().split())
		p -= 1
		ans[p] += x

	def dfs(cur, parent):
		for child in d[cur]:
			if child != parent:
				ans[child] += ans[cur]
				dfs(child,cur)
	dfs(0,-1) 
	print(*ans)
    
main()

### FIXED CODE ###

N, Q = map(int, input().split())
d = [0 for i in range(N)]

for i in range(N-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    d[b] = a
ans = [0 for i in range(N)]

for i in range(Q):
    p, x = map(int, input().split())
    p -= 1
    ans[p] += x

for i in range(1, N):
    ans[i] += ans[d[i]]

print(*ans)
### BUGGY CODE ###

from sys import exit
from itertools import product
import numpy as np
HWK,*sss = open(0).read().splitlines()
H,W,K = map(int, HWK.split())
sss = [list(map(int, list(ss))) for ss in sss]
sss = np.cumsum(sss, axis=0)

if H == 1 or W == 1:
    print(0--sss[-1][-1]//K)
    exit()

ans = float('inf')
for flgs in product([False, True], repeat=H-1):
    cnt = sum(flgs)
    tsss = sss[[*flgs, True]]
    tsss = np.concatenate((tsss[:1], np.diff(tsss, axis=0)), axis=0).T

    tmp = 0
    for cur in tsss:
        new = tmp + cur
        if new.max() <= K:
            tmp = new
        else:
            cnt += 1
            if cur.max() > K:
                continue
            else:
                tmp = cur
#     print(flgs)
#     print(cnt, ans, tsss)
    ans = min(ans, cnt)

print(ans)

### FIXED CODE ###

from sys import exit
from itertools import product
import numpy as np
HWK,*sss = open(0).read().splitlines()
H,W,K = map(int, HWK.split())
sss = [list(map(int, list(ss))) for ss in sss]
sss = np.cumsum(sss, axis=0)
 
if H == 1 or W == 1:
    print(0--sss[-1][-1]//K)
    exit()
 
ans = float('inf')
for flgs in product([False, True], repeat=H-1):
    cnt = sum(flgs)
    tsss = sss[[*flgs, True]]
    tsss = np.concatenate((tsss[:1], np.diff(tsss, axis=0)), axis=0).T
 
    tmp = 0
    succ = True
    for cur in tsss:
        new = tmp + cur
        if new.max() <= K:
            tmp = new
        else:
            cnt += 1
            if cur.max() > K:
                succ = False
                break
            else:
                tmp = cur
#     print(flgs)
#     print(cnt, ans, tsss)
    if succ:
        ans = min(ans, cnt)
 
print(ans)
### BUGGY CODE ###

N, M, L = map(int, input().split())
D = [[1000000000000]*N for i in range(N)]
for i in range(N):
  D[i][i] = 0
for i in range(M):
  A, B, C = map(int, input().split())
  A, B = A-1, B-1
  D[A][B] = C
  D[B][A] = C
for k in range(N):
  for i in range(N):
    for j in range(N):
      D[i][j] = min(D[i][j], D[i][k]+D[k][j])
E = [[1000000000000]*N for i in range(N)]
for i in range(N):
  E[i][i] = 0
for i in range(N):
  for j in range(N):
    if D[i][j] <= L:
      E[i][j] = 1
for k in range(N):
  for i in range(N):
    for j in range(N):
      E[i][j] = min(E[i][j], E[i][k]+E[k][j])
Q = int(input())
for i in range(Q):
  s, t = map(int, input().split())
  s, t = s-1, t-1
  if E[s][t] == 1000000000000:
    r = -1
  else:
    r = E[s][t]-1
  print(r)


### FIXED CODE ###

N, M, L = map(int, input().split())
D = [[1000000000000]*N for i in range(N)]
for i in range(N):
  D[i][i] = 0
for i in range(M):
  A, B, C = map(int, input().split())
  A, B = A-1, B-1
  D[A][B] = C
  D[B][A] = C
for k in range(N):
  for i in range(N):
    for j in range(N):
      D[i][j] = min(D[i][j], D[i][k]+D[k][j])
E = [[1000000000000]*N for i in range(N)]
for i in range(N):
  E[i][i] = 0
for i in range(N):
  for j in range(N):
    if D[i][j] <= L:
      E[i][j] = 1
for k in range(N):
  for i in range(N):
    for j in range(N):
      E[i][j] = min(E[i][j], E[i][k]+E[k][j])
Q = int(input())
for i in range(Q):
  s, t = map(int, input().split())
  s, t = s-1, t-1
  if E[s][t] == 1000000000000:
    r = -1
  else:
    r = E[s][t]-1
  print(r)
### BUGGY CODE ###

import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
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 LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    s = S()
    k = I()
    seen = set()
    min_k = []
    for i in range(len(s)):
        curS = s[i]
        for j in range(i, len(s)):
            if j > i:
                curS += s[j]
            if curS not in seen:
                seen.add(curS)
                if len(min_k) < k:
                    min_k.append(curS)
                else:
                    if curS < min_k[-1]:
                        min_k[-1] = curS
                min_k = sorted(min_k)
    print(min_k[-1])
main()


### FIXED CODE ###

import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
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 LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    s = S()
    K = I()
    subs = set()
    for j in range(1, 6):
        for i in range(len(s)):
            st = i
            en = min(st + j, len(s))
            subs.add(s[st:en])
    print(sorted(list(subs))[K-1])
main()