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

				
def factorial(number):
	if number>2:
		return number*factorial(number-1)
	elif not number==0:
		return number
	else:
		return 1
def choose2(number):
	if number>=2:
		return factorial(number)/(2*factorial(number-2))
	else:
		return 0
N = int(input())
klist = input()
k = []
for x in range(N-1):
	k.append(int(klist[:klist.index(" ")]))
	klist = klist[klist.index(" ")+1:]
k.append(int(klist))
valArr = []
occurence = []
for j in range(N):
	if len(valArr)>0:
		if not k[j] in valArr:
			valArr.append(k[j])
			occurence.append(1)
		else:
			for index in range(len(valArr)):
				if valArr[index]==k[j]:
					break;
			occurence[index]+=1
	else:
		valArr.append(k[j])
		occurence.append(1)
for ball in range(len(k)):
	ans = 0
	kArray = occurence[:len(occurence)]
	for index in range(len(valArr)):
		if valArr[index]==k[ball]:
			kArray[index]-=1
			break;
	for time in kArray:
		ans+=choose2(time)
	print(int(ans))


### FIXED CODE ###

def choose2(number):
	if number>=2:
		return (number*(number-1))/2
	else:
		return 0
N = int(input())
k = list(map(int,input().split()))
valArr = list(set(k))
occurence = []
occurenceIndex = []
mx = 0
for l in k:
	if l>mx:
		mx=l
for i in range(mx+1):
	occurence.append(0)
for j in range(N):
	occurence[k[j]]+=1
	
			
'''6*5/2
5*4/2
N*(N-1)/2
(N-2)*(N-1)/2
N*(N-1)/2*(N-2)/N
occurence = [1,2,3]
ans = 0+2*1/2+3*2/2
k val = 3
correct = 0+2*1/2+2*1/2

'''
ans = 0
for time in range(len(occurence)):
	ans+=choose2(occurence[time])
for ball in range(N):
	kans = ans-choose2(occurence[k[ball]])+choose2(occurence[k[ball]]-1)
	
	print(int(kans))
### BUGGY CODE ###

N, M, Q = map(int, raw_input().split())

train = []
for i in range(0, N):
	train.append([])
for i in range(0, M):
	L, R = map(int, raw_input().split())
	train[L-1].append(R)
for i in range(0, N):
	train[i-1].sort()

counter = []
for i in range(0, N):
	lst = []
	for j in range(0, N):
		lst.append(0)
	for j in range(0, len(train[i])):
		lst[train[i][j]-1] = lst[train[i][j]-1] + 1
	counter.append(lst)

for i in range(0, Q):
	p, q = map(int, raw_input().split())
	cnt = 0
	for j in range(p-1, q):
		for k in range(j, q):
			cnt = cnt + counter[j][k]
	print cnt


### FIXED CODE ###

N, M, Q = map(int, raw_input().split())

train = []
for i in range(0, N):
	train.append([])
for i in range(0, M):
	L, R = map(int, raw_input().split())
	train[L-1].append(R)
for i in range(0, N):
	train[i-1].sort()

counter = []
for i in range(0, N):
	lst = []
	for j in range(0, N):
		lst.append(0)
	for j in range(0, len(train[i])):
		lst[train[i][j]-1] = lst[train[i][j]-1] + 1
	for j in range(1, len(lst)):
		lst[j] = lst[j-1] + lst[j]
	counter.append(lst)
for i in range(1, N):
	for j in range(0, N):
		counter[N-1-i][j] = counter[N-1-i][j] + counter[N-i][j]

for i in range(0, Q):
	p, q = map(int, raw_input().split())
	print counter[p-1][q-1]
### BUGGY CODE ###

S=int(input())
print(sum([i for i in range(S)]))


### FIXED CODE ###

import math
N=int(input())
#print(sum([i for i in range(S)]))
"""
if s%2==0:
  ans=(1+s)*(s/2)
else:
  ans=(1+s)*int(s/2)+(int(s/2)+1)
"""
print(int(N*(N-1)//2))
### BUGGY CODE ###

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

for l,r in lr:
  print(s[l-1:r].count("AC"))
  

### FIXED CODE ###

N,Q = map(int,input().split())
S = input()
point = [list(map(int,input().split())) for i in range(Q)]
ac_list = [0]*(N+1)

for i in range(N):
  if S[i:i+2] == 'AC':
    ac_list[i+1] = ac_list[i] + 1
  else:
    ac_list[i+1] = ac_list[i]


for i in range(Q):
  print(ac_list[point[i][1]-1] - ac_list[point[i][0]-1])
### BUGGY CODE ###

n,m,k = map(int,input().split())
ans = 0
MOD = 10**9+7
from scipy.misc import comb
C = comb(m*n-2,k-2,exact=True)%MOD
for i in range(1,n):
    ans += (i*(n-i)*(m**2))*C
for i in range(1,m):
    ans += (i*(m-i)*(n**2))*C
print(ans%MOD)

### FIXED CODE ###

n,m,k = map(int,input().split())
ans = 0
mod = 10**9+7
max = 2*10**5
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル
for i in range( 2, max + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod
C = cmb(m*n-2,k-2,mod)
for i in range(1,n):
    ans += (i*(n-i)*(m**2))*C
for i in range(1,m):
    ans += (i*(m-i)*(n**2))*C
print(ans%mod)
### BUGGY CODE ###

N,K = map(int,input().split())
P = list(map(int,input().split()))
C = list(map(int,input().split()))
ans = 0

for i in range(N):
    p = i+1
    point = 0
    for j in range(K):
        p = P[p-1]
        point += C[p-1]
        if i == 0 and j == 0:
            ans = point
        elif ans < point:
            ans = point

print(ans)

### FIXED CODE ###

N,K = map(int,input().split())
P = [int(t) - 1 for t in input().split()]
C = list(map(int,input().split()))

ans = -1e18
for si in range(N):
    x = si
    s = []
    tot = 0
    while True:
        x = P[x]
        s.append(C[x])
        tot += C[x]
        if x == si:
            break
    l = len(s)
    t = 0
    for i in range(l):
        t += s[i]
        if i+1 > K:
            break
        now = t
        if tot > 0:
            e = (K-(i+1))//l
            now += tot*e
        if ans < now:
            ans = now
print(ans)
### BUGGY CODE ###

def main():
    n=int(input())
    a=list(map(int,input().split()))
    if 1 not in a:
        print(-1)
    else:
        ans = a.index(1)
        k = ans
        for i in range(2,n):
            a = a[k+1:]
            if i not in a:
                ans += len(a)
                print(ans)
                exit()
            else:
                k = a.index(i)
                ans += k
        print(ans)
if __name__=="__main__":
    main()

### FIXED CODE ###

def main():
    n = int(input())
    A = list(map(int, input().split()))
    i = 1
    ans = 0
    for a in A:
        if a == i:
            i += 1
        else:
            ans += 1
    # ans==nのときは Aに1がないので -1を出力.
    print(ans if ans!=n else -1)
main()
### BUGGY CODE ###

k,s =map(int,input().split())
cnt = 0
for x in range(0,s+1):
  if x>k:
    break
  for y in range(0,s+1-x):
    if y>k:
      break
    z = s-x-y
    if x<=k and y<=k and z <=k:
      cnt += 1
print(cnt)

### FIXED CODE ###

k,s =map(int,input().split())
cnt = 0
for x in range(0,s+1):
  for y in range(0,s+1-x):
    z = s-x-y
    if x<=k and y<=k and z <=k:
      cnt += 1
print(cnt)
### BUGGY CODE ###

b=[]
b.append(1)
b.append(2)
count=1
while 1:
    try:
        x=int(input())
        if x>b[count]:
            for i in range(b[count]+1,x+1):
                count1=0
                for j in range(2,i):
                    if i%j==0:
                        count1=1
                        break
                if count1==0:
                    count+=1
                    b.append(i)
            print(count)
        else:
            for i in range(count+1):
                if b[i]>x:
                    print(i-1)
                    break
                elif b[i]==x:
                    print(i)
                    break
    except EOFError:
        break

### FIXED CODE ###

str1=[0 for i in range(10**6)]
str1[0]=1
str1[1]=1
for i in range(2,(10**6)):
    if str1[i]==0:
        for j in range(2,(10**6)):
            if i*j>=len(str1):
                break
            else:
                str1[i*j]=1
            
while 1 :
    try:
        x=int(input())
        count=0
        for i in range(1,x+1):
            if str1[i]==0:
                count+=1
        print(count)
        
    except EOFError:
        break
### BUGGY CODE ###

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from copy import deepcopy

h, w = map(int, readline().split())
s = [readline().rstrip().decode() for _ in range(h)]
move = [(0, 1), (0, -1), (1, 0), (-1, 0)]
sg = []
memo = [[False] * w for _ in range(h)]
for i in range(h):
    for j in range(w):
        if s[i][j] == '.':
            sg.append((i, j))
        else:
            memo[i][j] = True
ans = 0
for ss in sg:
    for g in sg:
        q = [ss]
        cnt = 0
        dist = deepcopy(memo)
        dist[ss[0]][ss[1]] = True
        flag = False
        while q:
            cnt += 1
            qq = []
            for y, x in q:
                for dy, dx in move:
                    xx, yy = x + dx, y + dy
                    if xx < 0 or yy > h - 1 or yy < 0 or xx > w - 1:
                        continue
                    if dist[yy][xx]:
                        continue
                    dist[yy][xx] = True
                    if (yy, xx) == g:
                        flag = True
                        ans = max(ans, cnt)
                        break
                    qq.append((yy, xx))
            q = qq
print(ans)


### FIXED CODE ###

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from copy import deepcopy

h, w = map(int, readline().split())
s = [input() for i in range(h)]
q = []
start = []
dist = [[False] * w for _ in range(h)]
for i in range(h):
    for j in range(w):
        if s[i][j] != '#':
            start.append((i, j))
        else:
            dist[i][j] = True
test = [(0, 1), (0, -1), (1, 0), (-1, 0)]
ans = []
while start:
    check = deepcopy(dist)
    q = [start.pop()]
    check[list(q)[0][0]][list(q)[0][1]] = True
    cnt = -1
    while q:
        cnt += 1
        qq = []
        memo = len(q)
        memo_cnt = 0
        for y, x in q:
            for dy, dx in test:
                yy, xx = y + dy, x + dx
                if xx < 0 or yy < 0 or xx > w - 1 or yy > h - 1 or check[yy][xx]:
                    memo_cnt += 1
                    continue
                else:
                    check[yy][xx] = True
                    qq.append((yy, xx))
        q = qq
    ans.append(cnt)
else:
    print(max(ans))
### BUGGY CODE ###

a, b, k = map(int, input().split())
for _ in range(k):
    if a:
        a -= 1
    elif b:
        b -= 1
print(a, b)

### FIXED CODE ###

a, b, k = map(int, input().split())
print(max(0, a - k), max(0, b - max(0, k - a)))
### BUGGY CODE ###

from sys import stdin, stdout

int_in = lambda: int(stdin.buffer.readline())
arr_in = lambda: [int(x) for x in stdin.buffer.readline().split()]
out = lambda o: stdout.write("{}\n".format(o))

def divisors(n, items_in_a):
    i = 2
    result = set()
    while i * i <= n:
        if n % i == 0:
            opp = n // i
            if i in items_in_a or opp in items_in_a:
                return [n] # short circuit hack
            result.add(i)
            result.add(opp)
        i += 1
    return result

def solve(n, a):
    counts = {}
    for item in a:
        if item not in counts:
            counts[item] = 0
        counts[item] += 1
    if 1 in counts:
        return 1 if counts[1] == 1 else 0
    items_in_a = set(a)
    result = 0
    for item in a:
        if counts[item] == 1:
            d = divisors(item, items_in_a)
            if len(items_in_a.intersection(d)) == 0:
                result += 1
    return result


if __name__ == "__main__":
    n = int_in()
    a = arr_in()
    out(solve(n, a))

### FIXED CODE ###

from math import sqrt
from sys import stdin, stdout
out = lambda o: stdout.write("{}\n".format(o))


def solve(a):
    a.sort()
    size = a[-1] + 1

    seive = [1] * size

    seen = set()
    for item in a:
        if item in seen:
            seive[item] = 0
        seen.add(item)

    for item in a:
        for j in range(2 * item, size, item):
            seive[j] = 0

    return sum(map(lambda x: seive[x], a))


if __name__ == "__main__":
    n = int(stdin.buffer.readline())
    a = [int(x) for x in stdin.buffer.readline().split()]
    out(solve(a))
### BUGGY CODE ###

ar = list(input())
count = 0
for i in range(len(ar)):
    if ar[i] == "B":
        count += ar[i+1:len(ar)].count("W")
print(count)

### FIXED CODE ###

ar = list(input())
wc = ar.count("W")
count = 0
for i in range(len(ar)):
    if ar[i] == "B":
        count += wc
    else:
        wc -= 1
print(count)
### BUGGY CODE ###

n=int(input())
a=[]
for i in range(n):
  m=int(input())
  a.append([])
  for i in range(m):
    a[-1].append(list(map(int,input().split())))
ans=0
for i in range(2**n):
  s=bin(i)[2:].zfill(n)
  f=True
  for j,k in enumerate(a):
    for x,y in k:
      if s[x-1]!=str(y) and s[j]=="1":f=False
  if f:ans=max(ans,s.count("1"))
print(ans)

### FIXED CODE ###

n=int(input())
a=[]
for i in range(n):
  m=int(input())
  a.append([])
  for i in range(m):
    a[-1].append(list(map(int,input().split())))
ans=0
for i in range(2**n):
  s=bin(i)[2:].zfill(n)
  f=True
  for j,k in enumerate(a):
    for x,y in k:
      if s[x-1]!=str(y) and s[j]=="1":f=False
  if f:ans=max(ans,s.count("1"))
print(ans)
### BUGGY CODE ###

N, M = map(int, input().split())
ab_list = sorted([list(map(int, input().split())) for _ in range(M)])

ans = "IMPOSSIBLE"
second_island = []

for a, b in ab_list:
  if a == 1:
    second_island.append(b)
    
  if a in second_island:
    if b == N:
      ans = "POSSIBLE"
      break

print(ans)

### FIXED CODE ###

n, m = map(int, input().split())
sa = set()
sb = set()
for _ in range(m):
    a, b = map(int, input().split())
    if a == 1:
        sb.add(b)
    if b == n:
        sa.add(a)

print('POSSIBLE' if len(sa&sb) != 0 else 'IMPOSSIBLE')
### BUGGY CODE ###

def binarySearch(A, key):
    left = 0
    right = len(A)
    while left < right:
        mid = (left + right) / 2
        if A[mid] == key:
            return True
        elif key < A[mid]:
            right = mid
        else:
            left = mid+1
    return False

def main():
    n = int(raw_input())
    S = [int(_) for _ in raw_input().split()]
    q = int(raw_input())
    T = [int(_) for _ in raw_input().split()]
    Sum = 0
    for t in T:
        if binarySearch(S[:], t): Sum += 1
    print Sum
    return 0

main()

### FIXED CODE ###

n = int(raw_input())
S = map(int,raw_input().split())
q = int(raw_input())
T = map(int,raw_input().split())
 
c = 0
for t in T:
    left = 0
    right = n
    while left < right:
        mid = int((left + right)/2)
        if(S[mid] == t):
            c+=1
            break
        elif(t<S[mid]):
            right = mid
        else:
            left = mid+1
 
print c
### BUGGY CODE ###

from itertools import product
D, G = map(int, input().split())       
npcs = []
for i in range(D):
    n, c = map(int, input().split())   
    p = (i + 1) * 100
    npcs.append((n, p, c))
npcs.sort(key=lambda x: x[0])
lmaxn, lp, lc = npcs[-1]
lmaxp = lmaxn * lp + lc
lmaxp2 = (lmaxn - 1) * lp
result = sum(map(lambda x: x[0], npcs))

nps = [
[(x, p * x + (c if x == n else 0)) for x in range(n + 1)]
for n, p, c in npcs[:-1]
]
for np in product(*nps):
    sumn = sum(map(lambda x: x[0], np))
    if sumn >= result:
        continue
    sump = sum(map(lambda x: x[1], np))
    if sump >= G:
        result = sumn
    else:
        ps = G - sump
        if ps <= lmaxp:
            if ps > lmaxp2:
                sumn += lmaxn
            else:
                sumn += ps // lp
                if ps % lp != 0:
                    sumn += 1
            if sumn < result:
                result = sumn
print(result)

### FIXED CODE ###

import functools
D, G = map(int, input().split())
G = G // 100
sumn = 0
ns = [0] * (D + 1)
cs = [0] * (D + 1)
for i in range(1, D + 1):
    n, c = map(int, input().split())
    ns[i] = n
    cs[i] = c // 100
    sumn += n

minn = [0] * (D + 1)
for i in range(1, D + 1):
    minn[i] = min(ns[1:i+1])

@functools.lru_cache(maxsize=None)
def f(i, rn):
    if i == 1:
        if ns[1] < rn:
            return -1
        p = rn
        if ns[1] == rn:
            p += cs[1]
        return p
    if rn < minn[i]:
        p = 0
        for j in range(i, 0, -1):
            n = min((ns[j], rn))
            p += j * n
            if n == rn:
                break
            rn -= n
        return p
    maxp = 0
    for n in range(min((ns[i], rn)) + 1):
        p = i * n
        if n == ns[i]:
            p += cs[i]
        np = f(i - 1, rn - n)
        if np >= 0:
            p += np
            if maxp < p:
                maxp = p
    return maxp

mn = 1
mx = sumn
while mn < mx:
    x = mn + ((mx - mn) // 2)
    if G <= f(D, x):
        mx = x
    else:
        mn = x + 1
print(mn)
### BUGGY CODE ###

from collections import deque
from heapq import heappush,heappop
import re

def int_raw():
    return int(input())

def ss_raw():
    return input().split()

def ints_raw():
    return tuple(map(int, ss_raw()))

INF = 1<<29

class MedianHeap:
    def __init__(self):
        self.lupper = []
        self.rlower =[]
        self.s=0
    def push(self,a):
        L = self.lupper
        R = self.rlower
        if len(L)== 0 or a<=-L[0]:
            heappush(L,-a)
            self.s+=-L[0]-a
            if len(L)-len(R)>=2:
                heappush(R,-heappop(L))
        else:
            heappush(R,a)
            self.s+=a+L[0]
            if len(R)>len(L):
                self.s+=-L[0]-R[0]
                heappush(L,-heappop(R))

        
def main():
    Q = int_raw()
    sb = 0
    mh = MedianHeap()
    for _ in range(Q):
        cmds = tuple(map(int,input().split()))
        if cmds[0]==1:
            a,b = cmds[1:]
            sb+= b
            mh.push(a)
        else:
            print (-mh.lupper[0], mh.s+sb)
    
main()


### FIXED CODE ###

import sys
input=sys.stdin.readline
from heapq import heappush,heappop

def int_raw():
    return int(input())
 
def ss_raw():
    return input().split()
 
def ints_raw():
    return tuple(map(int, ss_raw()))

def main():
    Q = int(input())
    sb = 0
    lupper = []
    rlower = []
    s = 0
    for _ in range(Q):
        cmds = tuple(map(int,input().split()))
        if cmds[0]==1:
            _,a,b = cmds
            sb+= b
            if len(lupper)== 0 or a<=-lupper[0]:
                heappush(lupper,-a)
                s+=-lupper[0]-a
                if len(lupper)-len(rlower)>=2:
                    heappush(rlower,-heappop(lupper))
            else:
                heappush(rlower,a)
                s+=a+lupper[0]
                if len(rlower)>len(lupper):
                    s+=-lupper[0]-rlower[0]
                    heappush(lupper,-heappop(rlower))  
        else:
            print (-lupper[0], s+sb)
    
main()
### BUGGY CODE ###

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

res = s.count('R') * s.count('G') * s.count('B')

for ni,i in enumerate(s[:-2]):
    lst3 = ['R','G','B']
    lst3.remove(i)
    for nj in range(ni+1,n):
        nk = nj + (nj - ni)
        if nk < n:
            if set(lst3) == set([s[nj],s[nk]]):
                res -= 1
        else:
            break

print(res)

### FIXED CODE ###

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

res = s.count('R') * s.count('G') * s.count('B')

for i in range(n):
    for j in range(i+1, n-1):
        k = j + (j - i)
        if k < n:
            if s[i]!=s[j] and s[j]!=s[k] and s[k]!=s[i]:
                res -= 1
        else:
            break

print(res)
### BUGGY CODE ###

import numpy as np
import math
def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


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

# kごとに、
# 異なる数がいくつあるかを調べる
# (2以上要素が存在する)異なる数ごとに、
# (要素数)C2を解く。

np_A = np.array(A)

# 辞書作成
dic = {}

for k in range(N):
    before = A[:k]
    after = A[k+1:]

    before.extend(after)
    tmp_k = np.array(before)
    # print("tmp_k", tmp_k)   # k以上
    # print(np.unique(np_A))

    # 同じ組み合わせのケースを排除する。
    # (num, 要素数)の組み合わせを辞書かで作る
    # →単純にnCrなら(n, r)で保存する

    k_unique = np.unique(tmp_k)
    ans = 0

    for u in k_unique:
        count_u = np.count_nonzero(tmp_k==u)
        if count_u < 2:
            continue
        key = "{0}".format(count_u) + "2"   # key
        if key in dic.keys():
            ans += dic[key]
            continue

        # (count_u) C 2
        tmp = comb(count_u,2)
        ans += tmp
        # 値の更新
        dic[key] = tmp
    
    print(ans)


### FIXED CODE ###

import numpy as np
from collections import Counter


N = int(input())
A = list(map(int, input().split()))
c = Counter(A)
np_A = np.array(A)

# 全体を求める
tmp_all = np.array(A)
unique = np.unique(tmp_all)
# print("unique:", unique)
ans_all = 0
for u in unique:
    count_u = c[u]
    # print(f"u:{u}, count_u:{count_u}")
    if count_u < 2:
        continue
    # (count_u) C 2
    tmp = int(count_u*(count_u-1)/2)
    ans_all += tmp
# print("all", ans_all)


# kごとのケースを求めて、全体から引く
for i in A:
    print(ans_all - c[i] + 1)
### BUGGY CODE ###

def main():
    n, p = map(int, input().split())
    if n == 1:
        print(p)
    else:
        ans = 1
        if p % (2**n) == 0:
            while p % (2**n) == 0:
                ans *= 2
                p //= (2**n)
        for i in range(3, 10**6+1, 2):
            while p % (i**n) == 0:
                ans *= i
                p //= (i**n)
        print(ans)

if __name__ == "__main__":
    main()


### FIXED CODE ###

import sys
from math import log
def main():
    n, p = map(int, input().split())
    if n == 1:
        print(p)
    else:
        ans = 1
        if n > int(log(p, 2))+2:
            print("1")
            sys.exit()
        if p % (2**n) == 0:
            while p % (2**n) == 0:
                ans *= 2
                p //= (2**n)
        for i in range(3, 10**6+1, 2):
            while p % (i**n) == 0:
                ans *= i
                p //= (i**n)
        print(ans)

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

import sys
import math

k, s = map(int, input().split())

idx = 0
for x in range(k+1):
    for y in range(k+1):
        for z in range(k+1):
            if s == x+y+z:
                idx += 1
print(idx)


### FIXED CODE ###

k, s = map(int, input().split())

idx = 0


for x in range(k+1):
    for y in range(k+1):
        if 0 <= s - x - y <= k:
            idx += 1

print(idx)
### BUGGY CODE ###

import sys

s = sys.stdin.readline().rstrip()
k = int(sys.stdin.readline().rstrip())
n = len(s)

def main():
    res = set()
    for i in range(n):
        for j in range(i, n):
            res.add(s[i:j+1])
    return sorted(res)[k-1]

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

### FIXED CODE ###

#                         author:  kagemeka 
#                         created: 2019-11-07 13:42:36(JST)
import sys
# import collections
# import math
# import string
# import bisect
# import re
# import itertools
# import statistics
# import functools
# import operator

def main():
    s = sys.stdin.readline().rstrip()
    k = int(sys.stdin.readline().rstrip())
    n = len(s)
    
    substrings = []
    for i in range(1, k+1):
        for j in range(n-i+1):
            substring = s[j:j+i]
            substrings.append(substring)
    substrings = sorted(list(set(substrings)))
    print(substrings[k-1])


if __name__ == "__main__":
    # execute only if run as a script
    main()
### BUGGY CODE ###

n = int(input())
l = list(map(int,input().split()))

count = 0
for i in range(n):
    for j in range(i + 1, n):
        for k in range(j + 1, n):
            x, y, z = l[i], l[j], l[k]
            if x + y > z and x + z > y and y + z > x:
                count += 1
print(count)

### FIXED CODE ###

import bisect
n = int(input())
l = list(map(int,input().split()))
ls = sorted(l)

count = 0
for i in range(n):
    for j in range(i+1, n):
        index = bisect.bisect_left(ls[j+1:], ls[i] + ls[j])
        count += index
print(count)