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

#coding:utf-8

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

count = 0
r, g, b = 0, 0, 0

for k,i in enumerate(s):
    if i == 'R':
        r += 1
    elif i == 'G':
        g += 1
    elif i == 'B':
        b += 1

count = r * g * b

for i in range(n-2):
    si = s[i]
    for j in range(i+1,n-1):
        sj = s[j]
        if si == sj:
            continue
        c_set = {'R','G','B'}
        c_set = c_set - {si,sj}
        nk = 2 * j - i
        if not nk < n:
            continue
        if s[nk] in c_set:
            count -= 1

print("{}".format(count))

### FIXED CODE ###

#coding:utf-8

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

count = 0
r, g, b = 0, 0, 0

for i in s:
    if i == 'R':
        r += 1
    elif i == 'G':
        g += 1
    elif i == 'B':
        b += 1

count = r * g * b

for i in range(n-2):
    si = s[i]
    for j in range(i+1,n-1):
        sj = s[j]
        nk = 2 * j - i
        if not nk < n:
            break
        snk = s[nk]
        if {si, sj, snk} == {'R','G','B'}:
            count -= 1

print("{}".format(count))
### BUGGY CODE ###


import sys


def max_sum_seq(lis):
    m = 0
    lis = compress(lis)
    l = len(lis)
    for n in range(1, l+1):
        for s in every_slice(lis, n):
            sm = sum(s)
            if sm > m:
                m = sm
    return m

def every_slice(lis, n):
    l = len(lis)
    for i in range(l-n+1):
        yield lis[i:i+n]

def compress(tmp_lst):
    lim = len(tmp_lst)
    lst = []
    index = 0
    while index < lim:
        tmp = tmp_lst[index]
        index += 1
        while tmp > 0 and index < lim and tmp * tmp_lst[index] > 0:
            tmp += tmp_lst[index]
            index += 1
        lst.append(tmp)
    return lst


while True:
    n = int(sys.stdin.readline())
    if n == 0:
        break
    lis = []
    for i in range(n):
        lis.append(int(sys.stdin.readline()))
    print max_sum_seq(lis)

### FIXED CODE ###


import sys


def max_sum_seq(lis):
    m = 0
    lis = compress(lis)
    l = len(lis)

    max_val = lis[0]
    for i in xrange(0, l):
        for j in xrange(i, l):
            if j == i:
                tmp_val = lis[j]
            else:
                tmp_val = tmp_val + lis[j]
            max_val = max(max_val, tmp_val)
    return max_val

def compress(tmp_lst):
    lim = len(tmp_lst)
    lst = []
    index = 0
    while index < lim:
        tmp = tmp_lst[index]
        index += 1
        while tmp > 0 and index < lim and tmp * tmp_lst[index] > 0:
            tmp += tmp_lst[index]
            index += 1
        lst.append(tmp)
    return lst


while True:
    n = int(sys.stdin.readline())
    if n == 0:
        break
    lis = []
    for i in range(n):
        lis.append(int(sys.stdin.readline()))
    print max_sum_seq(lis)
### BUGGY CODE ###

def main():
    import heapq
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    if sum(A) <= K:
        print(0)
        return

    F = list(map(int, input().split()))

    A.sort()
    F.sort(reverse=True)
    q = []
    for i in range(N):
        heapq.heappush(q, (-(A[i]*F[i]), A[i], F[i]))

    k = K
    while k > 0:
        p, a, f = heapq.heappop(q)
        if p < 0:
            nextp = q[0][0]
            tmp = min(min(max((nextp-p+f-1)//f, 1), k), a)
            heapq.heappush(q, ((-(a-tmp)*f), a-tmp, f))
            k -= tmp
        else:
            break

    p, a, f = heapq.heappop(q)
    print(-p)
    return

main()

### FIXED CODE ###

N, K = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))
A.sort()
F.sort(reverse=True)

q = [0] * N
start = 0
end = 0
for i in range(N):
    q[i] = A[i] * F[i]
    end = max(end, q[i])

def check(now, K):
    cnt = 0
    for i in range(N):
        if q[i] - now > 0:
            cnt += (q[i] - now + F[i] - 1) // F[i]
            if cnt > K:
                return False
    return True

now = end // 2
while end > start + 1:
    if check(now, K):
        end = now
    else:
        start = now
    now = (start + end) // 2

if check(start, K):
    print(start)
else:
    print(end)
### BUGGY CODE ###

import sys
input = lambda: sys.stdin.readline().rstrip() 

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

    ans = 1
    for i in range(N-K+1):
        ans = max(sum(A[i:i+K]), ans)

    print((ans+K)/2)

if __name__ == '__main__':
    resolve()


### FIXED CODE ###

import sys
input = lambda: sys.stdin.readline().rstrip() 

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

    total = sum(A[0:K])
    total_max = total
    for i in range(0, N-K):
        total -= A[i]
        total += A[i+K]
        total_max = max(total, total_max)

    print((total_max+K)/2)

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

def solve():
    N, K = [int(_) for _ in raw_input().split()]
    S = raw_input()
    elms = [S[0]]
    cnts = []
    cnt = 1
    for i in range(1,N):
        if S[i] == elms[-1]:
            cnt += 1
        else:
            cnts.append(cnt)
            elms.append(S[i])
            cnt = 1
    cnts.append(cnt)
    num_elm = len(elms)
    max_cont1 = 0
    for i in range(num_elm):
        if elms[i] == '1':
            tmp = sum(cnts[i:(i+2*K+1)])
            max_cont1 = max(max_cont1, tmp)
        elif i == 0:
            tmp = sum(cnts[i:(i+2*K)])
            max_cont1 = max(max_cont1, tmp)
    print str(max_cont1)

if __name__ == '__main__':
    solve()


### FIXED CODE ###

def solve():
    N, K = [int(_) for _ in raw_input().split()]
    S = raw_input()
    elms = [S[0]]
    cnts = []
    cnt = 1
    for i in range(1,N):
        if S[i] == elms[-1]:
            cnt += 1
        else:
            cnts.append(cnt)
            elms.append(S[i])
            cnt = 1
    cnts.append(cnt)
    num_elm = len(elms)
    max_cont1 = 0
    tmp = 0
    for i in range(num_elm):
        if i == 0:
            if elms[i] == '0':
                tmp = sum(cnts[i:(i+2*K)])
                max_cont1 = max(max_cont1, tmp)
            if elms[i] == '1':
                tmp = sum(cnts[i:(i+2*K+1)])
                max_cont1 = max(max_cont1, tmp)
        elif i == 1:
            if elms[i] == '1':
                tmp -= cnts[i-1]
                if i + 2*K - 1 < num_elm:
                    tmp += cnts[i + 2*K - 1]
                if i + 2*K < num_elm:
                    tmp += cnts[i + 2*K]
                max_cont1 = max(max_cont1, tmp)
        else:
            if elms[i] == '1':
                tmp -= cnts[i - 2]
                tmp -= cnts[i - 1]
                if i + 2*K - 1 < num_elm:
                    tmp += cnts[i + 2*K - 1]
                if i + 2*K < num_elm:
                    tmp += cnts[i + 2*K]
                max_cont1 = max(max_cont1, tmp)
    print str(max_cont1)

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

import sys
import array

from operator import itemgetter

input = sys.stdin.readline

tl=200100

ft=array.array('I', [0 for _ in range(tl)])

def upd(i):
	global ft
	i+=1
	while(i<tl):
		ft[i]+=1
		i+=i&-i

def get(i):
	global ft
	i+=1
	ret=0
	while(i!=0):
	    ret+=ft[i]
	    i-=i&-i
	return ret

md = 998244353
n = int(input())

xyi = [[0]*3 for _ in range(n)]
for i in range(n):
	xyi[i][0],xyi[i][1] = [int(item) for item in input().split()]
xyi.sort(key=itemgetter(0))

for i in range(n):
	xyi[i][2]=i
xyi.sort(key=itemgetter(1))

cnt=array.array('I', [0 for _ in range(n+1)])

cnt[0]=1
for i in range(1,n+1):
	cnt[i]=cnt[i-1]*2%md

def comb(x):
	return cnt[x]-1;

ans=0

for aa in xyi:
	ix=aa[2]
	a=get(ix)
	b=get(n)-get(ix)
	c=ix-a
	d=n-ix-1-b
	exc=(comb(a+b)+comb(a+c)+comb(b+d)+comb(c+d)-comb(a)-comb(b)-comb(c)-comb(d))%md
	cur=(comb(n)-exc)%md
	ans=(ans+cur)%md
	upd(ix)

if(ans<0):ans+=md

print(ans)


### FIXED CODE ###

import sys
import array

from operator import itemgetter

def main():



	input = sys.stdin.readline


	md = 998244353
	n = int(input())
	tl=n+1
	
	ft=[0]*tl

	xy = [[0]*2 for _ in range(n)]
	for i in range(n):
		xy[i] = [int(item) for item in input().split()]
	xy.sort(key=itemgetter(0))
	yxi = [y for x, y in xy]

	*YS, = set(yxi)
	YS.sort()
	yxi= list(map({e: i for i, e in enumerate(YS)}.__getitem__, yxi))

	ct=[0]*(n+1)
	ct[0]=1
	for i in range(1,n+1):
		ct[i]=ct[i-1]*2%md

	cnt=tuple(ct)

	def upd(i):
		i+=1
		while(i<=n):
			ft[i]+=1
			i+=i&-i

	def get(i):
		i+=1
		ret=0
		while(i!=0):
		    ret+=ft[i]
		    i-=i&-i
		return ret

	def calc(get,upd):
		for i, y in enumerate(yxi):
			v = get(y); upd(y)
			p1 = cnt[v]; p0 = cnt[y - v]
			q1 = cnt[i - v]; q0 = cnt[(n - y - 1) - (i - v)]
			yield (p0 + p1 + q0 + q1 - (p0 + q1) * (p1 + q0)) % md


	print((sum(calc(get,upd))+n*cnt[n] - n)%md)

main()
### BUGGY CODE ###

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

goukei = 0

for i in range(N - 1):
    for j in range(i + 1, N):
        goukei += suji[i] * suji[j]

print(goukei % (10 ** 9 + 7))

### FIXED CODE ###

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

wa = sum(suji)
goukei = 0

for i in range(N):
    goukei += suji[i] * (wa - suji[i])
    wa -= suji[i]

print(goukei % (10 ** 9 + 7))
### BUGGY CODE ###

# Problem E - Divisible Substring

from collections import Counter

# 組み合わせ
def combinations_count(n, r):
    return n * (n - 1) // r

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

# count
if P==2 or P==5:
    ans = 0
    for i in range(N-1, -1, -1):
        s = int(S[i])
        if s%P==0:
            ans += i + 1
    # output
    print(ans)
else:
    p_nums = [0]*(N+1)
    s = ""
    for i in range(N-1, -1, -1):
        s = S[i] + s
        p_nums[N - i] = int(s)%P
    p_counter = [0]*P
    for i in range(N+1):
        p_counter[p_nums[i]] += 1
    ans = 0
    for i in range(P):
        ans += combinations_count(p_counter[i], 2)
    print(ans)


### FIXED CODE ###

# Problem E - Divisible Substring

from collections import Counter

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

# count
if P==2 or P==5:
    ans = 0
    for i in range(N-1, -1, -1):
        s = int(S[i])
        if s%P==0:
            ans += i + 1
    # output
    print(ans)
else:
    p_nums = [0]*(N+1)
    s = 0
    for i in range(N-1, -1, -1):
        s = int(S[i]) * pow(10, N - i - 1, P) + s
        p_nums[N - i] = s%P
    p_counter = [0]*P
    for i in range(N+1):
        p_counter[p_nums[i]] += 1
    ans = 0
    for i in range(P):
        ans += p_counter[i] * (p_counter[i] - 1) // 2
    print(ans)
### BUGGY CODE ###

import sys
read = sys.stdin.readline
import time
import math
import itertools as it
def inpl():
    return list(map(int, input().split()))
st = time.perf_counter()
# ------------------------------

N, K = inpl()
A = inpl()
ls = [1] * (N+10)
for i in range(K):
    ls[K-1] *= A[i]
for i in range(K, N):
    ls[i] = ls[i-1]//A[i-K] * A[i]
    if ls[i] > ls[i-1]:
        print('Yes')
    else:
        print('No')

 
    

# -----------------------------
ed = time.perf_counter()
print('time:', ed-st, file=sys.stderr)


### FIXED CODE ###

import sys
read = sys.stdin.readline
import time
import math
import itertools as it
def inpl():
    return list(map(int, input().split()))
st = time.perf_counter()
# ------------------------------

N, K = inpl()
A = inpl()
for i in range(K, N):
    if A[i] > A[i-K]:
        print('Yes')
    else:
        print('No')

# -----------------------------
ed = time.perf_counter()
print('time:', ed-st, file=sys.stderr)
### BUGGY CODE ###

from collections import deque
import copy
def bfs():
    h,w = map(int, input().split())
    maze = [list(input()) for i in range(h)]
    S, G = [], []
    for y in range(h):
        for x in range(w):
            if maze[y][x]=='.':
                S.append([y,x])
                G.append([y,x])
                maze[y][x]=float("inf")
    l = []
    for sy, sx in S:
      for gy, gx in G:
        if sy == gy and sx == gx:
          continue
        maze1 = copy.deepcopy(maze)
        maze1[sy][sx]=0
        que=deque([[sy,sx]])
        while que:
          y,x=que.popleft()
          for i,j in [(1,0),(0,1),(-1,0),(0,-1)]:
            nexty,nextx=y+i,x+j
            if nexty < 0 or nexty >= h or nextx < 0 or nextx >= w:
                continue
            dist=maze1[nexty][nextx]
            if dist!='#':
              if dist>maze1[y][x]+1:
                maze1[nexty][nextx]=maze1[y][x]+1
                if nexty == gy and nextx == gx:
                  break
                que.append([nexty,nextx])
        l.append(maze1[gy][gx])
    print(max(l))
bfs()

### FIXED CODE ###

from collections import deque
import copy
def bfs():
    h,w = map(int, input().split())
    maze = [list(input()) for i in range(h)]
    S, G = [], []
    for y in range(h):
        for x in range(w):
            if maze[y][x]=='.':
                S.append([y,x])
                G.append([y,x])
                maze[y][x]=float("inf")
            else:
                maze[y][x]=-1
    l = []
    ans = 0
    for i in range(len(S)):
        maze1 = copy.deepcopy(maze)
        maze1[S[i][0]][S[i][1]]=0
        que=deque([[S[i][0],S[i][1]]])
        while que:
          y,x=que.popleft()
          for k,m in [(1,0),(0,1),(-1,0),(0,-1)]:
            nexty,nextx=y+k,x+m
            if nexty < 0 or nexty >= h or nextx < 0 or nextx >= w:
                continue
            dist=maze1[nexty][nextx]
            if dist!=-1:
              if dist>maze1[y][x]+1:
                maze1[nexty][nextx]=maze1[y][x]+1
                que.append([nexty,nextx])
            ans = max(ans, maze1[nexty][nextx])
    print(ans)
bfs()
### BUGGY CODE ###

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

data = {}

def my_sum(d):
    retval = 0

    for i in d.keys():
        retval += d[i] * i
    return retval

for i in A:
    if i in data.keys():
        data[i] += 1
    else:
        data[i] = 1
 
for i in range(Q):
    B, C = map(int, input().split())

    if B not in data.keys():
        print(my_sum(data))
        continue
 
    if C in data.keys():
        data[C] = data[C] + data[B]
    else:
        data[C] = data[B]
    del data[B]
 
    print(my_sum(data))

### FIXED CODE ###

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

data = [0] * 100001

def my_sum(d):
    retval = 0

    for i in range(len(d)):
        if d[i] == 0:
            continue
        retval += d[i] * i
    return retval

for i in A:
    data[i] += 1

sum_val = my_sum(data)

for i in range(Q):
    B, C = map(int,input().split())

    sum_val = sum_val - (data[B] * B) + (data[B] * C)

    data[C] += data[B]
    data[B] = 0

    print(sum_val)
### BUGGY CODE ###

def getN():
    return int(input())

def getMN():
    a = input().split()
    b = [int(i) for i in a]
    return b[0],b[1]

def getlist():
    a = input().split()
    b = [int(i) for i in a]
    return b

m,n = getMN()
MOD = 1000000007
anums = getlist()
bnums = getlist()

anums.sort(reverse=True)
bnums.sort(reverse=True)
ans = 1
r_index = 0
d_index = 0
for i in range(m*n):
    ans = ans%MOD
    num = m * n - i
    #print("num = {}, ans = {}".format(num,ans))
    #print("r = {}, d = {}, i = {}".format(r_index, d_index,i))
    in_r = num in anums
    in_d = num in bnums
    if in_r:
        if in_d:
            r_index += 1
            d_index += 1
        else:
            ans = ans * d_index
            r_index += 1
    else:
        if in_d:
            ans = ans * r_index
            d_index += 1
        else:
            if r_index * d_index < i:
                import sys

                ans = 0
                break
            else:
                import sys
                #print("koko", i, file=sys.stderr)
                andayo = (ans * (r_index*d_index -i ))
                #ans = ans * (r_index*d_index -i )
                ans = andayo
                #print("ans", ans)
ans = ans%MOD

print(ans)

### FIXED CODE ###

def getN():
    return int(input())

def getMN():
    a = input().split()
    b = [int(i) for i in a]
    return b[0],b[1]

def getlist():
    a = input().split()
    b = [int(i) for i in a]
    return b

m,n = getMN()
MOD = 1000000007
anums = getlist()
bnums = getlist()

anums.sort(reverse=True)
bnums.sort(reverse=True)
ans = 1
r_index = 0
d_index = 0
flag = True
for i in range(m*n):
    ans = ans % MOD
    num = m * n - i
    if r_index == m and d_index == n:
        ans *= num
        flag = False
    if flag:

        #print("num = {}, ans = {}".format(num,ans))
        #print("r = {}, d = {}, i = {}".format(r_index, d_index,i))
        in_r = num in anums
        in_d = num in bnums
        if in_r:
            if in_d:
                r_index += 1
                d_index += 1
            else:
                ans = ans * d_index
                r_index += 1
        else:
            if in_d:
                ans = ans * r_index
                d_index += 1
            else:
                if r_index * d_index < i:
                    import sys

                    ans = 0
                    flag = False
                else:
                    import sys
                    #print("koko", i, file=sys.stderr)
                    andayo = (ans * (r_index*d_index -i ))
                    #ans = ans * (r_index*d_index -i )
                    ans = andayo
                    #print("ans", ans)
ans = ans%MOD

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

import sys

input = sys.stdin.buffer.readline

h, w = map(int, input().split())
AA = [list(map(int, input().split())) for _ in range(h)]
BB = [list(map(int, input().split())) for _ in range(h)]

kouho = [[set() for _ in range(w)] for _ in range(h)]

delta = AA[0][0] - BB[0][0]
kouho[0][0].add(delta)
kouho[0][0].add(-delta)
dx = [1, 0]
dy = [0, 1]
for y in range(h):
    for x in range(w):
        for d in range(2):
            nx = x + dx[d]
            ny = y + dy[d]
            if nx < 0 or nx >= w or ny < 0 or ny >= h:
                continue
            delta = AA[ny][nx] - BB[ny][nx]
            for num in kouho[y][x]:
                if 80 * (h + w) >= abs(num + delta):
                    kouho[ny][nx].add(abs(num + delta))
                if 80 * (h + w) >= abs(num - delta):
                    kouho[ny][nx].add(abs(num - delta))
ans = 10 ** 10
for a in kouho[h - 1][w - 1]:
    ans = min(ans, abs(a))
print(ans)


### FIXED CODE ###

import sys

input = sys.stdin.buffer.readline

h, w = map(int, input().split())
AA = [list(map(int, input().split())) for _ in range(h)]
BB = [list(map(int, input().split())) for _ in range(h)]

kouho = [[0] * (w) for _ in range(h)]
delta = abs(AA[0][0] - BB[0][0])
kouho[0][0] |= 1 << delta
for y in range(h):
    for x in range(w):
        nx = x + 1
        ny = y
        if nx < w:
            delta = abs(AA[ny][nx] - BB[ny][nx])
            temp = 0
            for i in range(1, delta + 1):
                if (kouho[y][x] >> i) & 1:
                    temp |= 1 << (delta - i)
            kouho[ny][nx] |= kouho[y][x] << delta
            kouho[ny][nx] |= kouho[y][x] >> delta
            kouho[ny][nx] |= temp

        nx = x
        ny = y + 1
        if ny < h:
            delta = abs(AA[ny][nx] - BB[ny][nx])
            temp = 0
            for i in range(1, delta + 1):
                if (kouho[y][x] >> i) & 1:
                    temp |= 1 << (delta - i)
            kouho[ny][nx] |= kouho[y][x] << delta
            kouho[ny][nx] |= kouho[y][x] >> delta
            kouho[ny][nx] |= temp
for i in range(81):
    if (kouho[h - 1][w - 1] >> i) & 1:
        print(i)
        exit()
### BUGGY CODE ###

from functools import reduce

def count_two(n):
	two_count = 0
	while n != 0 and n % 2 == 0:
		two_count += 1
		n //= 2
	return two_count

n = int(input())
a = map(int, input().split())
a_product = reduce(lambda x, y: x*y, a)
print(count_two(a_product))

### FIXED CODE ###

from functools import reduce

def count_two(n):
	two_count = 0
	while n != 0 and n % 2 == 0:
		two_count += 1
		n //= 2
	return two_count

n = int(input())
a = map(int, input().split())
a_two_count_sum = sum([count_two(ai) for ai in a])
print(a_two_count_sum)
### BUGGY CODE ###

class Process(object):
    def __init__(self, name, s):
        self.name = name
        self.s = s

    def exec(self, q):
        if self.s <= q:
            time = self.s
            self.s = 0
            return time
        else:
            time = q
            self.s = self.s - q
            return time

def execute(processes, q):
    time = 0
    completed = []
    while len(processes) != len(completed):
        for i, p in enumerate(processes):
            if not p.s == 0:
                time += p.exec(q)
                if p.s == 0:
                    completed.append((p, time))
    return completed

def run():
    n, q = list(map(int, input().split()))
    processes = []
    for _ in range(n):
        name, time = input().split()
        processes.append(Process(name, int(time)))
    completed = execute(processes, q)
    for c in completed:
        print(c[0].name, c[1])

if __name__ == '__main__':
    run()




### FIXED CODE ###

class Process(object):
    def __init__(self, name, s):
        self.name = name
        self.s = s

    def exec(self, q):
        if self.s <= q:
            time = self.s
            self.s = 0
            return time
        else:
            time = q
            self.s = self.s - q
            return time

def execute(processes, q):
    time = 0
    completed = []
    while processes:
        p = processes.pop()
        time += p.exec(q)
        if p.s == 0:
            completed.append((p, time))
        else:
            processes.insert(0, p)
    return completed

def run():
    n, q = list(map(int, input().split()))
    processes = []
    for _ in range(n):
        name, time = input().split()
        processes.append(Process(name, int(time)))
    processes.reverse()
    completed = execute(processes, q)
    for c in completed:
        print(c[0].name, c[1])

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

import sys
from collections import deque
A = deque(input())
B = int(input())
for i in range(B):
    C = sys.stdin.readline().split()
    if C[0] == "1":
        A.reverse()
    else:
        if C[1] == "1":
            A.appendleft(C[2])
        else:
            A.append(C[2])
print("".join(A))

### FIXED CODE ###

A = input()
B = int(input())
C = ""
for i in range(B):
    D = input().split()
    if D[0] == "1":
        C,A = A,C
    else:
        if D[1] == "1":
            C += D[2]
        else:
            A += D[2]
C = C[::-1]
print(C+A)
### BUGGY CODE ###

#C
S = list(str(input()))
N = len(S)
K = int(input())

cand = []
for i in range(N):
    s = S[i]
    cand.append(s)
    for j in range(K):
        if i+j+1 < N:
            s+=S[i+j+1]
            cand.append(s)
            
shin = []
for c in cand:
    if c not in shin:
        shin.append(c)
        
shin.sort()
print(shin[K-1])


### FIXED CODE ###

#C
S = list(str(input()))
N = len(S)
K = int(input())

cand = []
for i in range(N):
    s = S[i]
    cand.append(s)
    for j in range(K):
        if i+j+1 < N:
            s+=S[i+j+1]
            cand.append(s)
            
cand.sort()
old = ""
shin = []
for c in cand:
    if c != old:
        shin.append(c)
        old = c
        
shin.sort()
print(shin[K-1])
### BUGGY CODE ###

n = input()
ans = 0
while 'BW' in n:
    for i, s in enumerate(n):
        if s == 'W':
            n = n[:i] + 'B' + n[i+1:]
            n = n[1:]
            ans += i
            break
print(ans)


### FIXED CODE ###

S = [i for i in input()]
ans = 0
c = 0
'''while S[0] == 'W':
    S = S[1:]
    '''
for i,s in enumerate(S):
    if s == 'B':
        c += 1
    else:
        ans += c
print(ans)