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

#!/usr/bin/env python3

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

r = []


for i in range(q):

  numbers = input().split(" ")
  b = int(numbers[0])
  c = int(numbers[1])
  s = 0

  # a.sort()
  for i in range(n):
    if a[i] == b:
      a[i] = c
    s += a[i]
  r.append(s)

for x in r:
  print(x)





### FIXED CODE ###

#!/usr/bin/env python3

def exist_or_not(list, value):
  for i in range(len(list)):
    if list[i] < value:
      continue
    elif list[i] == value:
      return i
    else:
      break
  return -1

n = int(input())
a = [0] * 100001
numbers = input().split(" ")
sum = 0
for x in numbers:
  int_x = int(x)
  a[int_x] += 1
  sum += int_x

q = int(input())

r = []
b = []
c = []



for i in range(q):
  numbers = input().split(" ")
  b.append(int(numbers[0]))
  c.append(int(numbers[1]))

for i in range(q):
  b_count = a[b[i]]
  a[c[i]] += b_count
  a[b[i]] = 0
  sum += (c[i] - b[i]) * b_count
  print(sum)
### BUGGY CODE ###

import heapq
x,y,z,k=map(int,input().split())
a=sorted([int(i) for i in input().split()],reverse=True)
b=sorted([int(i) for i in input().split()],reverse=True)
c=sorted([int(i) for i in input().split()],reverse=True)

def solve(p):
    cnt=0
    for i in range(x):
        for j in range(y):
            for k in range(z):
                if a[i]+b[j]+c[k]>=p:
                    cnt+=1
                    if cnt>=k:
                        return True
                else:
                    break
    return False

l,r=0,a[0]+b[0]+c[0]
while r>l+1:
    t=(l+r)//2
    if solve(t):
        r=t
    else:
        l=t
ans=[]
for i in range(x):
    for j in range(y):
        for m in range(z):
            if a[i]+b[j]+c[m]>=r:
                heapq.heappush(ans,-(a[i]+b[j]+c[m]))
            else:
                break
for i in range(k):
    print(-heapq.heappop(ans))


### FIXED CODE ###

import heapq
x,y,z,k=map(int,input().split())
#heapqは小さい順にしか並べられないので、-をつければ大きい順になる
a=sorted([-int(i) for i in input().split()])
b=sorted([-int(i) for i in input().split()])
c=sorted([-int(i) for i in input().split()])
check=set()
ans=[]
heapq.heappush(ans,(a[0]+b[0]+c[0],0,0,0))
check.add((0,0,0))
for i in range(k):
    h=heapq.heappop(ans)
    print(-h[0])
    if h[1]+1<x:
        if (h[1]+1,h[2],h[3]) not in check:
            heapq.heappush(ans,(a[h[1]+1]+b[h[2]]+c[h[3]],h[1]+1,h[2],h[3]))
            check.add((h[1]+1,h[2],h[3]))
    if h[2]+1<y:
        if (h[1],h[2]+1,h[3]) not in check:
            heapq.heappush(ans,(a[h[1]]+b[h[2]+1]+c[h[3]],h[1],h[2]+1,h[3]))
            check.add((h[1],h[2]+1,h[3]))
    if h[3]+1<z:
        if (h[1],h[2],h[3]+1) not in check:
            heapq.heappush(ans,(a[h[1]]+b[h[2]]+c[h[3]+1],h[1],h[2],h[3]+1))
            check.add((h[1],h[2],h[3]+1))
'''
while len(ans)!=0:
    print(heapq.heappop(ans)[0])
'''
### BUGGY CODE ###

N = int(input())
A = input().split(" ")
s = 1
for i in range(N):
  s = s*int(A[i])


if s > 10**18:
  print(-1)
else:
  print(s)

### FIXED CODE ###

N = int(input())
A = input().split(" ")
s = 1

for i in range(N):
  if int(A[i]) == 0:
    s = 0

for i in range(N):
  if s ==0:
    break
  if s > 10**18:
    break
  s = s*int(A[i])


if s > 10**18:
  print(-1)
else:
  print(s)
### BUGGY CODE ###

from collections import defaultdict

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


def combi(n):
    return n * (n-1) // 2


for a in A:
    d[a] += 1

ans = []
for i in range(N):
    tmp = d.copy()
    tmp[A[i]] -= 1
    ans = sum(list(map(combi, list(tmp.values()))))
    print(ans)

### FIXED CODE ###

from collections import defaultdict


def combi(n):
    if n < 2:
        return 0
    return n * (n-1) // 2


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

for a in A:
    d[a] += 1

whole = sum(list(map(combi, list(d.values()))))

diff = []
for i in range(N):
    diff.append(combi(d[A[i]]) - combi(d[A[i]] - 1))

for x in diff:
    print(whole - x)
### BUGGY CODE ###

N,M = map(int,input().split())
a = []
tmp = []
for i in range(M):
    tmp = list(map(str,input().split()))
    a.append(list(tmp))

startCheck = False
startST = []

for i in a:
    if i[0] == '1':
        startCheck = True
        startST.append(i[1])

if not startCheck:
    print('IMPOSSIBLE')
    exit()

for i in a:
    if i[0] in startST:
        if int(i[1]) == N:
            print('POSSIBLE')
            exit()

print('IMPOSSIBLE')

### FIXED CODE ###

from collections import deque

N, M = map(int, input().split())
route = []
for i in range(M):
    route.append(list(map(int,input().split())))

island_map = {}
for a,b in route:
    if a not in island_map:
        island_map[a] = [b]
    else:
        island_map[a].append(b)

first_island = deque()
first_island += island_map[1]
second_island = deque()

for i in first_island:
    if i in island_map:
        second_island += island_map[i]
    else:
        pass
    for j in second_island:
        if j == N:
            print('POSSIBLE')
            exit()

print('IMPOSSIBLE')
### BUGGY CODE ###

from functools import reduce

words = lambda t : list(map(t, input().split()))
n = int(input())
xs = words(int)

ys = []
k = 0
for x in xs:
    y = list(reversed(bin(x)))[:-2]
    ys.append(y)
    k = max(k, len(y))
#print(ys, n)

def calc (x,y):
    if i < len(y) and y[i] == "1":
        return x+1
    else:
        return x

ans = 0
for i in range(k):
    x1 = 0
    x1 = reduce(calc,ys,0)
    #print(x1,x0)
    ans += x1 * (len(ys)-x1) * (2**(i))
    ans %= 10**9 + 7
print(ans)


### FIXED CODE ###

words = lambda t : list(map(t, input().split()))
n = int(input())
xs = words(int)

ys = [0]*60
for x in xs:
    for i in range(60):
        if x == 0:
            continue
        ys[i] += x & 1
        x = x >> 1

ans = 0

for i,yi in enumerate(ys):
    ans += 2**(i) * yi * (n-yi)
    ans %= 10**9 + 7
print(ans)
### BUGGY CODE ###


x = (10**9)+7
n = int(input())
val = 0
lst = list(map(int,input().split()))
for value in lst:
    value = value%x
for i in range(n-1):
    for j in range(i+1,n):
        val += (lst[i]*lst[j])
        val = val%x
print(val)

### FIXED CODE ###

n = int(input())
arr = list(map(int,input().split()))
su = sum(arr)
c = 0
for item in arr:
  c+= item*item
print(((su**2 - c)//2)%(10**9 + 7))
### BUGGY CODE ###

def yakusu(n):
    max_yakusu = int(n**0.5)
    arr = [1]

    while n > 1:
        for i in range(2,max(n+1,max_yakusu+1)):
            if n % i == 0:
                arr.append(i)
                n = int(n/i)
                break
    return arr

def gcd(x,y):
    if y == 0:
       return x
    else:
       return gcd(y, x % y)

A,B = [int(x) for x in input().split()]
koyaku = gcd(A,B)

koyaku_insu = set(yakusu(koyaku))


print(len(koyaku_insu))

### FIXED CODE ###

def prime_factorize(n):
    a = [1]
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
  
def gcd(x,y):
    if y == 0:
       return x
    else:
       return gcd(y, x % y)
 
A,B = [int(x) for x in input().split()]
koyaku = gcd(A,B)
 
koyaku_insu = list(set(prime_factorize(koyaku)))
 
 
print(len(koyaku_insu))
### BUGGY CODE ###

n = int(input())
a = list(map(int, input().split()))
mod = 1000000007
ans = 0
for i in range(60):
  x = 0
  for j in range(n):
    if (a[j] >> i) & 1:
      x += 1
  ans += x*(n-x)*(2**i)%mod
print(ans%mod)

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
mod = 1000000007
ml = len(bin(max(a)))-2
ans = 0
for i in range(ml):
  x = sum([1 for j in a if ((j>>i) & 1)])
  ans += x*(n-x)*(2**i)
  ans %= mod
print(ans)
### BUGGY CODE ###

n = int(input())
la = list(map(int, input().split()))
ans = 0
for i in range(n-1):
  for j in range(i+1, n):
    ans = (ans%(10**9+7) + la[i]*la[j]%(10**9+7))%(10**9+7)
print(ans)

### FIXED CODE ###

n = int(input())
la = list(map(int, input().split()))
MOD = (10**9+7)
ans = 0
nn = 0
for i in range(n):
  ans %= MOD
  ans += la[i]%MOD
  nn %= MOD
  nn += (la[i]**2)%MOD
ans = (ans**2-nn+10**9+7)*pow(2, -1, MOD)%MOD
print(ans)
### BUGGY CODE ###

inf = input().split()
H = int(inf[0])
W = int(inf[1])
sheet = [[] for i in range(H+2)]
score = [[] for i in range(H+2)]
m = 0
 
for h in range(H+2):
  if h==0 or h==H+1:
    a = [False]*(W+2)
    b = [(0,0)]*(W+2)
    sheet[h]=a
    score[h]=b
  else:
    line = input()
    a = []
    b = []
    a += [False]
    b += [(0,0)]
    for w in range(W):
      b+=[(0,0)]
      if line[w]=='.':
        a += [True]
      else:
        a += [False]
    a += [False]
    b += [(0,0)]
    sheet[h]=a
    score[h]=b
      
for h in range(1,H+1):
  for w in range(1,W+1):
    if sheet[h][w]:
      s = 0
      hs = 0
      ws = 0
      if sheet[h-1][w]:
        hs += score[h-1][w][0]
      else:
        i = h+1
        while sheet[i][w]:
          hs+=1
          i+=1
      if sheet[h][w-1]:
        ws += score[h][w-1][1]
      else:
        j = w+1
        while sheet[h][j]:
          ws+=1
          j+=1
      s = 1 + hs + ws
      score[h][w]=(hs, ws)
      if m < s:
        m = s
print(m)

### FIXED CODE ###

inf = input().split()
H = int(inf[0])
W = int(inf[1])
sheet = [[] for i in range(H+2)]
score = [[] for i in range(H+2)]
m = 0
 
for h in range(H+2):
  if h==0 or h==H+1:
    a = [False]*(W+2)
    b = [(0,0)]*(W+2)
    sheet[h]=a
    score[h]=b
  else:
    line = input()
    a = []
    b = []
    a += [False]
    b += [(0,0)]
    for w in range(W):
      b+=[(0,0)]
      if line[w]=='.':
        a += [True]
      else:
        a += [False]
    a += [False]
    b += [(0,0)]
    sheet[h]=a
    score[h]=b
      
for h in range(1,H+1):
  for w in range(1,W+1):
    if sheet[h][w]:
      s = 0
      hs = 0
      ws = 0
      if sheet[h-1][w]:
        hs += score[h-1][w][0]
      else:
        i = h+1
        while sheet[i][w]:
          hs+=1
          i+=1
      if sheet[h][w-1]:
        ws += score[h][w-1][1]
      else:
        j = w+1
        while sheet[h][j]:
          ws+=1
          j+=1
      s = 1 + hs + ws
      score[h][w]=(hs, ws)
      if m < s:
        m = s
print(m)
### BUGGY CODE ###

N=int(input())
s=input()
s_list=list(s)
count=0
for i in range(0,N):
  for j in range(0,len(s_list)-1):
    if s_list[j] == s_list[j+1]:
      s_list.pop(j+1)
      count=1
      break
  if count==0:
    break
print(len(s_list))

### FIXED CODE ###

N=int(input())
s=input()
s_list=list(s)
import itertools as itl
list2=[k for k, v in itl.groupby(s_list)]
print(len(list2))
### BUGGY CODE ###

N = int(input())
T = [0]
V = [0]
T.extend(list(map(int, input().split())))
V.extend(list(map(int, input().split())))
V.append(0)


Z = [0] * (len(T))
K = [[0, 0]]
for i in range(len(T)-1):
    Z[i+1] = Z[i] + T[i+1]
    K.append([Z[i], Z[i+1]])
gokei_T = sum(T)

K.append([gokei_T, gokei_T])

ans = 0
time_table = [0.5*i for i in range(2*gokei_T+1)]

for time in time_table:
    speed = 10**5
    for k, v in zip(K, V):
        if time <= k[0]:
            tmp = v + (k[0]-time)
        elif k[0] <= time <= k[1]:
            tmp = v
        elif k[1] <= time:
            tmp = v + (time - k[1])

        speed = min(speed, tmp)
    ans += 0.5 * speed

print(ans)

### FIXED CODE ###

"""
prd_xxx 様のコードを参考にさせていただきました。感謝です...！
https://beta.atcoder.jp/contests/abc076/submissions/1724160
"""

N = int(input())
T = list(map(int, input().split()))
V = list(map(int, input().split()))

maxv = [0]
# グラフを整える準備
for v, t in zip(V, T):
    # 転換地点では低い方に合わせる
    maxv[-1] = min(maxv[-1], v)
    for ti in range(t * 2):
        maxv.append(v)

T = len(maxv)
# 前からグラフを整える
for i in range(T - 1):
    maxv[i + 1] = min(maxv[i+1], maxv[i] + 0.5)

maxv[-1] = 0
# 後ろからグラフを整える
for i in reversed(range(T-1)):
    maxv[i] = min(maxv[i], maxv[i + 1] + 0.5)

ans = 0
# 台形計算
for i in range(T-1):
    ans += (maxv[i] + maxv[i+1]) * 0.25
print(ans)
### BUGGY CODE ###

n,m=map(int,input().split())
ans=0
for i in range(1,m//n +1):
	if m%i == 0 and m/i >= n:
		ans = max(ans, i)
print(ans)

### FIXED CODE ###

n,m=map(int,input().split())
m_root=int(m**0.5)
div_l=[]
ans=0

for i in range(1,m_root + 1):
    if m%i == 0:
        div_l.append(i)
        div_l.append(m//i)

if m//n in div_l:
    ans = m//n
else:
    div_l.append(m//n)
    div_l.sort()
    ans = div_l[div_l.index(m//n) - 1]
print(ans)
### BUGGY CODE ###

# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.readline
read = sys.stdin.read
from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import product#accumulate, combinations, product
#import bisect# lower_bound etc
#import numpy as np
#from copy import deepcopy
def run():
    N, M = map(int, sysread().split())
    to = [[] for _ in range(N+1)]
    AB = list(map(int, read().split()))
    A = AB[::2]
    B = AB[1::2]
    for a,b in zip(A,B):
        to[a].append(b)
        to[b].append(a)

    seen = [False] * (N+1)
    stack = []
    seen[1] = True
    heappush(stack, (0, 1, 0))# (distance, node, prev)
    mark = [0] * (N+1)
    done = [False] * (N+1)

    while True:
        try:
            dist, current, prev = heappop(stack)
        except:
            break
        seen[current] = True
        if not done[current]:
            done[current] = True
            mark[current] = str(prev)
        for next in to[current]:
            if not seen[next]:
                heappush(stack, (dist+1, next, current))

    print('Yes')
    #mark = [str(val) for val in mark]
    print('\n'.join(mark[2:]))

if __name__ == "__main__":
    run()

### FIXED CODE ###

# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.readline
read = sys.stdin.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import product#accumulate, combinations, product
#import bisect# lower_bound etc
#import numpy as np
#from copy import deepcopy
from collections import deque
def run():
    N, M = map(int, sysread().split())
    to = [[] for _ in range(N+1)]
    AB = list(map(int, read().split()))
    A = AB[::2]
    B = AB[1::2]
    for a,b in zip(A,B):
        to[a].append(b)
        to[b].append(a)

    seen = [False] * (N+1)
    queue = deque([])
    seen[1] = True
    queue.append((1, 0))# (node, prev)
    mark = [0] * (N+1)

    while queue:
        current, prev = queue.popleft()
        for next in to[current]:
            if not seen[next]:
                queue.append((next, current))
                mark[next] = current
                seen[next] = True

    print('Yes')
    mark = [str(val) for val in mark]
    print('\n'.join(mark[2:]))

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

import itertools

n = int(input())
v = list(map(int, input().split()))
c = list(map(int, input().split()))

ans = 0
for i in range(1, n+1):
    a = itertools.combinations(range(n), i)
    for j in a:
        x, y = 0, 0
        for k in j:
            x += v[k]
            y += c[k]
        ans = max(ans, x-y)
print(ans)

### FIXED CODE ###

n = int(input())
v = list(map(int, input().split()))
c = list(map(int, input().split()))

vc = []
for i, j in zip(v, c):
    vc.append(i-j)
vc = sorted(vc, reverse=True)
ans = 0
for i in vc:
    if i <= 0:
        break
    ans += i
print(ans)
### BUGGY CODE ###

Sum = input().split()

def mak(che) :
    if Sum[che] == '+' : 
        Sum.insert((che - 2), (int(Sum.pop(che - 2)) + int(Sum.pop(che - 2))))
        del Sum[che - 1]
    elif Sum[che] == '-' :
        Sum.insert((che - 2), (int(Sum.pop(che - 2)) - int(Sum.pop(che - 2))))
        del Sum[che - 1]
    elif Sum[che] == '*' : 
        Sum.insert((che - 2), (int(Sum.pop(che - 2)) * int(Sum.pop(che - 2))))
        del Sum[che - 1]
    

while ('+' in Sum) or ('-' in Sum) or ('*' in Sum) :
    for che in 2, 3 :
        mak(che)
        if len(Sum) == 3 : break
        if ('+' not in Sum) and ('-' not in Sum) and ('*' not in Sum) : break
    
print(Sum[0])

### FIXED CODE ###

Sum = input().split()
cou = 1
while len(Sum) != 1 :
    cou += 1
    if Sum[cou] == '+' :
        del Sum[cou]
        Sum.insert((cou - 2) ,int(Sum.pop(cou - 2)) + int(Sum.pop(cou - 2)))
        cou -= 2
    elif Sum[cou] == '-' :
        del Sum[cou]
        Sum.insert((cou - 2) ,int(Sum.pop(cou - 2)) - int(Sum.pop(cou - 2)))
        cou -= 2
    elif Sum[cou] == '*' :
        del Sum[cou]
        Sum.insert((cou - 2) ,int(Sum.pop(cou - 2)) * int(Sum.pop(cou - 2)))
        cou -= 2

print(Sum[0])
### BUGGY CODE ###

N ,W = map(int,input().split())
L = []
for _ in range(N):
    l = list(map(int,input().split()))
    L.append(l)
dp = [[0 for _ in range(W + 10)] for _ in range(N + 10)]
for i in range(N):
    for w in range(W+1):
        if w+L[i][0] <= W:
            dp[i+1][w+L[i][0]] =max(dp[i][w]+L[i][1], dp[i+1][w+L[i][0]])
        dp[i+1][w] = max(dp[i][w], dp[i+1][w])
ans = 0
for w in range(W+1):
    ans = max(ans,dp[N][w])
print(ans)



### FIXED CODE ###

N ,W = map(int,input().split())
L = []
for _ in range(N):
    l = list(map(int,input().split()))
    L.append(l)
dp = [[0 for _ in range(W + 10)] for _ in range(N + 10)]
for i in range(N):
    for w in range(W+1):
        if w+L[i][0] <= W:
            dp[i+1][w+L[i][0]] =max(dp[i][w]+L[i][1], dp[i+1][w+L[i][0]])
        dp[i+1][w] = max(dp[i][w], dp[i+1][w])
ans = 0
for w in range(W+1):
    ans = max(ans,dp[N][w])
print(ans)
### BUGGY CODE ###

import sys
input = sys.stdin.readline
input = sys.stdin.buffer.readline

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def LI(): return list(map(int,input().split()))
def TI(): return tuple(map(int,input().split()))
def RN(N): return [input().strip() for i in range(N)]


def main():
    N, M = MI()
    H = LI()
    H.insert(0,0)
    A = [0]*M
    B = [0]*M
    ans = 0
    for i in range(M):
        A[i], B[i]=MI()
    for i in range(1,N+1):
        #print("hi",i,H[i])
        ng = 0
        for j in range(M):
            if A[j] == i:
                if H[i]<=H[B[j]]:
                    ng += 1
                    #print(i, "no")
                    break
            if B[j] == i:
                if H[i]<=H[A[j]]:
                    ng += 1
                    break
        if ng == 0:
            ans += 1
    print(ans)


    


if __name__ == "__main__":
	main()

### FIXED CODE ###

import sys
input = sys.stdin.readline
input = sys.stdin.buffer.readline

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def LI(): return list(map(int,input().split()))
def TI(): return tuple(map(int,input().split()))
def RN(N): return [input().strip() for i in range(N)]


def main():
    N, M = MI()
    H = LI()
    H.insert(0,0)
    A = [0]*M
    B = [0]*M
    ans = 0
    for i in range(M):
        A[i], B[i]=MI()

    Hnum = [0]*(N+1)
    Hnum[0] = 1

    for i in range(M):
        if H[A[i]]>H[B[i]]:
            Hnum[B[i]]+=1
        elif H[A[i]]<H[B[i]]:
            Hnum[A[i]]+=1
        elif H[A[i]]==H[B[i]]:
            Hnum[A[i]]+=1
            Hnum[B[i]]+=1
    print(Hnum.count(0))


    """
    for i in range(1,N+1):
        ng = 0
        for j in range(M):
            if A[j] == i:
                if H[i]<=H[B[j]]:
                    ng += 1
                    break
            if B[j] == i:
                if H[i]<=H[A[j]]:
                    ng += 1
                    break
        if ng == 0:
            ans += 1
    print(ans)"""


    


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

#coding:utf-8


if __name__ == "__main__":
    N, M = map(int, input().split())
    city_list = [None] * M
    pref_dec = {}
    for m in range(M):
        p, y = map(int, input().split())
        city_list[m] = (p, y)
        if p not in pref_dec:
            pref_dec[p] = []
        pref_dec[p].append(y)

    for p in set(pref_dec.keys()):
        pref_dec[p].sort()

    for m in range(M):
        p_id = city_list[m][0]
        y_id = pref_dec[p_id].index(city_list[m][1]) + 1
        print(str(p_id).zfill(6) + str(y_id).zfill(6))


### FIXED CODE ###

#coding:utf-8
#参考：https://beta.atcoder.jp/contests/abc113/submissions/3806710


if __name__ == "__main__":
    N, M = map(int, input().split())
    city_list = []
    for i in range(M):
        p, y = map(int, input().split())
        city_list.append([i, p, y])

    city_count = {}
    order_dic = {}
    for i, p, y in sorted(city_list, key = lambda x: x[2]):
        if not p in city_count:
            city_count[p] = 0
        city_count[p] += 1
        order_dic[i, p] = city_count[p]

    for i, p, y in city_list:
        print("{:06}{:06}".format(p, order_dic[i,p]))
### BUGGY CODE ###

n,m = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
for i in range(m):
	b,c = map(int,input().split())
	cou = 0
	for i in range(len(A)):
		if A[i] < c :
			A[i] = c
			cou += 1
		else :
			break
		if cou == b:
			break
	A.sort()
print(sum(A))

### FIXED CODE ###


def test_function() :
	print(__name__) # __main__

#print("called :",test_function.__name__)
n,m = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
C=[]
for i in range(m):
	b,c = map(int,input().split())
	C.append((b,c))
C = sorted(C,key = lambda x:x[1])
before = 0

for b,c in C[::-1]:
	cou = 0  
	#print("[before]=",before)
	for i in range(len(A)-before):
		if A[before+i] < c :
			A[before+i] = c
			cou += 1
			#print("A=",A)
		else :
			before += i+1
			break
		if cou == b:
			before += i+1
			break
print(sum(A))
### BUGGY CODE ###

def combinations_count(n, r):
    return n * (n-1) // r


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

l1 = []
l2 = []
lll = []
dl = []

for i in l:
    t = l.count(i)
    temp = combinations_count(t, 2)
    if i not in dl:
        dl.append(i)
        lll.append(temp)
    l1.append(temp)
    l2.append(combinations_count(t-1, 2))

total = sum(lll)

for i in range(len(l)):
    print(total-l1[i]+l2[i])


### FIXED CODE ###

import collections

def combinations_count(n, r):
    return n * (n-1) // r


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

l1 = []
l2 = []
c = collections.Counter(l)

total = sum([combinations_count(i, 2) for i in c.values()])

for a in l:
    print(total-combinations_count(c[a], 2)+combinations_count(c[a]-1, 2))
### BUGGY CODE ###

#A問題
import collections
N=int(input())
S=str(input())
Slist=list(S)
count=0
maxn=2**N
for i in range(maxn):
    I=bin(i)
    I=I.lstrip("0b")
    Ilen=len(I)
    if Ilen<N:
        Id=N-Ilen
        j=0
        for j in range(Id):
            I="0"+I
    
    k=0
    klist=[]
    flag=0
    for k in range(N):
        if I[k]=="0":
            pass
        else:
            if Slist[k] in klist:
                flag=1
                break
            else:
                klist.append(Slist[k])
    if flag == 0 and len(klist)>0:
        count+=1
    count=count%1000000007
print(count)

### FIXED CODE ###

#A問題
import collections
N=int(input())
S=str(input())
Slist=list(S)
c = collections.Counter(Slist)
d = c.most_common()
dlen=len(d)
count=1
for i in range(dlen):
    count*=(d[i][1]+1)
count-=1
count%=1000000007
print(count)
### BUGGY CODE ###

s = str(input())
k = int(input())
s += '0'
result = []
for i in range(len(s)-1):
    for j in range(i+1, len(s)):
        if all(s[i:j] != x for x in result):
            result.append(s[i:j])
result.sort()

print(result[k-1])

### FIXED CODE ###

def main():
    s = str(input())
    s += '0'
    k = int(input())
    result = set()
    for i in range(1, 6):
        for j in range(len(s)-i):
            result.add(s[j:j+i])
    out = list(result)
    out.sort()
    print(out[k-1])
if __name__ =='__main__':
    main()