Harryxun/stf_run huggingface dataset:
n,m=map(int,input().split())
s=[list(map(int,input().split()))[1:] for i in range(m)]
p=list(map(int,input().split()))
cnt=0

for i in range(2**n):
    pattern=format(i,"b").zfill(n)
    point=0
    
    for j in range(m):
        swi=0
        for k in s[j]:
            if pattern[k-1]=="1":
              swi +=1
        if swi%2==P[j]:
          point +=1
    if point==m:
      cnt +=1
      
print(cnt)

### FIXED CODE ###

n,m=map(int,input().split())
s=[list(map(int,input().split()))[1:] for i in range(m)]
p=list(map(int,input().split()))
cnt=0

for i in range(2**n):
    pattern=format(i,"b").zfill(n)
    point=0
    
    for j in range(m):
        swi=0
        for k in s[j]:
            if pattern[k-1]=="1":
              swi +=1
        if swi%2==p[j]:
          point +=1
    if point==m:
      cnt +=1
      
print(cnt)
from collections import deque

n, m, k = map(int, input().split())
a = deque(map(int, input().split()))
b = deque(map(int, input().split()))

ans = 0
minutes = 0
while True:
    if len(a) == 0 and len(b) == 0:
        break
    elif len(a) > 0 and len(b) > 0:
        if a[0] == b[0]:
            if ans + a[0] <= k:
                if a[1] >= b[1]:
                    minutes += 1
                    ans += b.popleft()
                else:
                    minutes += 1
                    ans += a.popleft()
            else:
                break
        elif a[0] > b[0]:
            if ans + b[0] <= k:
                minutes += 1
                ans += b.popleft()
            else:
                break
        else:
            if ans + a[0] <= k:
                minutes += 1
                ans += a.popleft()
            else:
                break

    elif len(b) == 0 and (a[0] + ans) <= k:
        minutes += 1
        ans += a.popleft()
    elif len(a) == 0 and (b[0] + ans) <= k:
        minutes += 1
        ans += b.popleft()
    else:
        break

print(minutes)
# print(ans)

### FIXED CODE ###

import itertools
import sys

input = sys.stdin.readline

n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

ans = 0
a_cum = [0] + list(itertools.accumulate(a))
b_cum = [0] + list(itertools.accumulate(b))

y = m  # len(b_cum) - 1
for x in range(len(a_cum)):
    if a_cum[x] > k:
        break
    while b_cum[y] > k - a_cum[x]:
        y -= 1
    ans = max(ans, x + y)

print(ans)
# -*- coding: utf-8 -*-
A,B=map(int,input().split)
if A <= 8 and B <= 8:
  print(Yay!)
else:
  print(:()

### FIXED CODE ###

# -*- coding: utf-8 -*-
A,B =map(int,input().split())
if A <= 8 and B <= 8:
  print("Yay!")
else:
  print(":(")
n = int(input())
dp = [0]*n
cnt = 0
L = []
flag = True
for i in range(n):
  T = []
  N = list(map(int,input().split()))
  for j in range(n-1):
    T.append((i+1,N[j]))
  L.append(T)
while dp != [n-1]*n:
  B = [0]*n
  act = 0
  for i in range(n):
    if B[i] == 0:
      B[i] = 1
      if dp[i] != n-1:
        miru = L[i][dp[i]][1]
        if dp[miru-1] == n-1:
          flag = False
          break
        else:
          if B[miru-1] != 1:
            if L[miru-1][dp[miru-1]][1] == i+1:
              dp[i] += 1
              dp[miru-1] += 1
              B[miru-1] = 1
              act += 1
  if act == 0:
    dp = [n-1]*n
    flag = False
  if cnt >= 100000:
      dp = [n-1]*n
  cnt += 1
if flag == False:
  print(-1)
else:
  print(cnt)

### FIXED CODE ###

S = input()
T = input()
ans = 0
for i in range(3):
  if S[i] == T[i]:
    ans += 1
print(ans)
N = int(input())
li = list(map(int, input().split()))
ans = "Yes"
count = N - 1
while count >= 0:
    if li[count] - li[count-1] => 0:
        pass
    elif li[count] - li[count-1] == -1:
        li[count-1] -= 1
    else:
        ans = "No"
        break
    count -= 1
print(ans)

### FIXED CODE ###

N = int(input())
li = list(map(int, input().split()))
ans = "Yes"
count = N - 1
while count >= 1:
    if li[count] - li[count-1] >= 0:
        pass
    elif li[count] - li[count-1] == -1:
        li[count-1] -= 1
    else:
        ans = "No"
        break
    count -= 1
print(ans)
print(abs(int(input)-48))

### FIXED CODE ###

print(48-int(input()))
S = [a for a in input()]
N = [int(a) for a in S]
M = [N[i] for i in range(1,4)]
S.insert(1, '+')
S.insert(3, '+')
S.insert(5, '+')

if sum(N) == 7:
    S = S
    print(''.join(S) + '=7')
    exit()

for i in range(1, 4):
    N[i] = -N[i]

    if sum(N) == 7:
        S[2 * i - 1] = '-'
        print(''.join(S) + '=7')
        exit()

for i in range(1, 4):
    S[1], S[3], S[5] == '-', '-', '-'
    M[i] = -M[i]
    if sum(M) == 7:
        S[2 * i - 1] = '+'
        print(''.join(S) + '=7')
        exit()

### FIXED CODE ###

S = [a for a in input()]
N = [int(a) for a in S]
M = [N[0]] + [-N[i] for i in range(1,4)]

S.insert(1, '+')
S.insert(3, '+')
S.insert(5, '+')

if sum(N) == 7:
    S = S
    print(''.join(S) + '=7')
    exit()

for i in range(1, 4):
    N[i] = -N[i]
    
    if sum(N) == 7:
        
        S[2 * i - 1] = '-'
        print(''.join(S) + '=7')
        exit()
    else: N[i] = -N[i]

for i in range(1, 4):
    S[1], S[3], S[5] = '-', '-', '-'
    
    M[i] = -M[i]
    
    if sum(M) == 7:
        S[2 * i - 1] = '+'
        print(''.join(S) + '=7')
        exit()
    else:
      M[i] = -M[i]
N ,K = map(int, input().split())

S = str(input())

S = S[:K] + (S[K]).lower() + S[K+1:]

print(S)


### FIXED CODE ###

N ,K = map(int, input().split())

S = str(input())

S = S[:K-1] + (S[K-1]).lower() + S[K:]

print(S)
n, r = map(int, input())
if n >= 10:
    print(r)
else:
    print(r + 100 * (10 - n))


### FIXED CODE ###

n, r = map(int, input().split())
if n >= 10:
    print(r)
else:
    print(r + 100 * (10 - n))
n=int(input())

l=[]
for i in range(n):
  l.append(int(input()))

a=sum(l)-2*max(l)

if a<0 :
  print("Yes")
  
else:
  print("No")

### FIXED CODE ###

N = int(input())
L=[int(x) for x in input().split()]
if sum(L)-max(L) > max(L):
    print("Yes")
else:
    print("No")
s1s2s3 = map(int, input().split())
print(s1+s2+s3)

### FIXED CODE ###

print(input().count("1"))
import numpy as np

A = []
for i in range(3):
    A.append(list(map(int, input().split())))
A = np.array(A)

N = int(input())
b = np.zeros(N, dtype=np.int)
for i in range(N):
    b[i] = int(input())
# print(A)
# print(b)
# T = A[A in b]
T = np.isin(A,b)
# print(T)
ans=[0,0,0,0]
ans[0]=T.all(axis=0).all()
ans[1]=T.all(axis=1).all()
ans[2]=np.diag(T).all()
ans[3]=np.diag(T[:,[2,1,0]]).all()
# print(ans)
if any(ans):
    print('Yes')
else:
    print('No')

### FIXED CODE ###

import numpy as np

def in1d(ar1, ar2, assume_unique=False, invert=False):
    # Ravel both arrays, behavior for the first array could be different
    ar1 = np.asarray(ar1).ravel()
    ar2 = np.asarray(ar2).ravel()

    # Check if one of the arrays may contain arbitrary objects
    contains_object = ar1.dtype.hasobject or ar2.dtype.hasobject

    # This code is run when
    # a) the first condition is true, making the code significantly faster
    # b) the second condition is true (i.e. `ar1` or `ar2` may contain
    #    arbitrary objects), since then sorting is not guaranteed to work
    if len(ar2) < 10 * len(ar1) ** 0.145 or contains_object:
        if invert:
            mask = np.ones(len(ar1), dtype=bool)
            for a in ar2:
                mask &= (ar1 != a)
        else:
            mask = np.zeros(len(ar1), dtype=bool)
            for a in ar2:
                mask |= (ar1 == a)
        return mask

    # Otherwise use sorting
    if not assume_unique:
        ar1, rev_idx = np.unique(ar1, return_inverse=True)
        ar2 = np.unique(ar2)

    ar = np.concatenate((ar1, ar2))
    # We need this to be a stable sort, so always use 'mergesort'
    # here. The values from the first array should always come before
    # the values from the second array.
    order = ar.argsort(kind='mergesort')
    sar = ar[order]
    if invert:
        bool_ar = (sar[1:] != sar[:-1])
    else:
        bool_ar = (sar[1:] == sar[:-1])
    flag = np.concatenate((bool_ar, [invert]))
    ret = np.empty(ar.shape, dtype=bool)
    ret[order] = flag

    if assume_unique:
        return ret[:len(ar1)]
    else:
        return ret[rev_idx]

def isin(element, test_elements, assume_unique=False, invert=False):
    element = np.asarray(element)
    return in1d(element, test_elements, assume_unique=assume_unique,
                invert=invert).reshape(element.shape)
A = []
for i in range(3):
    A.append(list(map(int, input().split())))
A = np.array(A)

N = int(input())
b = np.zeros(N, dtype=np.int)
for i in range(N):
    b[i] = int(input())
T = isin(A,b)
ans=[0,0,0,0]
ans[0]=T.all(axis=0).any()
ans[1]=T.all(axis=1).any()
ans[2]=np.diag(T).all()
ans[3]=np.diag(T[:,[2,1,0]]).all()
if any(ans):
    print('Yes')
else:
    print('No')
n = int(input())
a = list(map(int, input().split()))

arr = [0]*(n+1)
for i in range(n):
    arr[a[i]] += 1

from scipy.misc import comb

c = [0]*(n+1)
for i in range(n+1):
    c[i] = int(comb(arr[i],2))

d = [0]*(n+1)
for i in range(n+1):
    d[i] = int(comb(arr[i]-1,2))


for k in range(n):
    ans = sum(c[:a[k]]) + sum(c[a[k]+1:]) + d[a[k]]
    print(ans)


### FIXED CODE ###

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

nums = [0] * (max(a) + 1)
for i in range(len(a)):
    nums[a[i]] += 1

from scipy.special import comb

all = 0
for i in range(len(nums)):
    all += comb(nums[i], 2, exact=True)

for k in range(n):
    print(all - (nums[a[k]] - 1))
n=int(input())
a=map(int, input().split())
a=sorted(a)[::-1]
n=int(myinput)
myinput="3 3 3 3 4 4 4 5 5 5"
a=map(int, myinput.split())
a=sorted(a)[::-1]

### FIXED CODE ###

n=int(input())
a=map(int, input().split())
a=sorted(a)[::-1]
k=-2
l=-2
for i in range(n-1):
    if (a[i]==a[i+1])&(i>k+1):
        if (k>=0):
            l=i
            break
        else:
            k=i
if l>=0:
    print(a[k]*a[l])
else:
    print(0)
import math

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


def lcm(x, y):
    return (x * y) // math.gcd(x, y)


print(lcm(a, b))


### FIXED CODE ###

import fractions

def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

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

print(lcm(a, b))
n,k = map(int,input().split())
a = list(map(int,input().split()))
l = [1,a[0]]
tp = a[0]-1
for i in range(10**18) 
  if a[tp] not in l: 
    l.append(a[tp])
    tp = a[tp] -1
  else:
    l.append(a[tp])
    break
    
last = l[-1]

loop = len(l[l.index(last):-1])
first = l.index(last)
if len(l)>k:
  print(l[k])
  exit()
k -=first
k %=loop
if k==0:
  k+=loop
print(l[k+first])

### FIXED CODE ###

n, k = map(int, input().split())
a = list(map(int, input().split()))
l = [1]

for i in range(n):
  l.append(a[l[i]-1])
p = l.index(l[n])
#print(p,l[n])
if k<=n:
  print(l[k])
else:
  x = (k-n+1)%(n-p)
  if x ==0:
    x += (n-p)
    print(l[x-1])
  else:
    print(l[x+p-1])
import numpy as np

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

t1 = np.ones(A,dtype=np.int64)
t2 = np.zeros(B,dtype=np.int64)
t = np.hstack((t1, t2))

L = len(t)

Q = N // L
R = N % L
ANS = Q*(np.sum(t))+np.sum(t[0:R])
print(ANS)

### FIXED CODE ###

a = list(map(int,input().split()))
N = a[0]
blue = a[1]
red = a[2]
ans = 0
A = blue + red
X = N // A
Y = N % A
if Y <= blue:
    ans = blue * X + Y
else:
    ans = blue * X + blue
print(ans)
inputlist=[]
while 1:
	inputnum=int(raw_input())
	if(inputnum==0):break
	inputlist.append(inputnum)
def octnpower(num):
	flag=0
	maxi=0
	maxj=0
	if(num<8):
		temp[0]=num
		return
	for i in range(1,11):
		for j in range(1,8):
			if(num>=(8**i)*j):
				flag=(8**i)*j
				maxi=i
				maxj=j
			else:
				temp[maxi]=maxj
				return octnpower(num-flag)

octdictionary={0:0,1:1,2:2,3:3,4:5,5:7,6:8,7:9}
for i in range(len(inputlist)-1):
	temp=[0]*10
	octnpower(inputlist[i])
	for i in range(len(temp)):
		temp[i]=octdictionary[temp[i]]
	temp.reverse()
	for j in range(len(temp)):
		index=j
		if(temp[j]!=0):break
	temp=temp[index:]
	ansstr=""
	for j in range(len(temp)):
		ansstr+=str(temp[i])
	print ansstr

### FIXED CODE ###

inputlist=[]
while 1:
	inputnum=int(raw_input())
	if(inputnum==0):break
	inputlist.append(inputnum)
def octnpower(num):
	flag=0
	maxi=0
	maxj=0
	if(num<8):
		temp[-1]=num
		return
	for i in range(1,11):
		for j in range(1,8):
			if(num>=(8**i)*j):
				flag=(8**i)*j
				maxi=i
				maxj=j
			else:
				temp[-maxi-1]=maxj
				return octnpower(num-flag)

octdictionary={0:0,1:1,2:2,3:3,4:5,5:7,6:8,7:9}
for i in range(len(inputlist)):
	temp=[0]*10
	octnpower(inputlist[i])
	for j in range(len(temp)):
		index=j
		if(temp[j]!=0):break
	temp=temp[index:]
	for j in range(len(temp)):
		temp[j]=octdictionary[temp[j]]
	ansstr=""
	for j in range(len(temp)):
		ansstr+=str(temp[j])
	print ansstr
N,K = map(int, input().split())
p = list(map(int, input().split()))
sump0=0
for i in range(N-2):
	sump=p[i]+p[i+1]+p[i+2]
	if sump>sump0:
	sum0=sump
    
print(sum0/2+K/2)

### FIXED CODE ###

import itertools
 
n, k = map(int, input().split())
p = list(map(int, input().split()))
acc = [0] + list(itertools.accumulate([(x+1)/2 for x in p])) # 累積和を計算
 
ans = max(acc[i]-acc[i-k] for i in range(k, n+1)) # k番目からn番目まで計算
print(ans)
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)

    val n = sc.nextInt()
    val c = sc.nextInt()
    val k = sc.nextInt()
    val t = Array(n) { sc.nextInt() }

    var ans = 0
    var waitStart = 0
    var waitPeople = 0

    for (ti in t.sorted()) {
        if (ti - waitStart > k || waitPeople == c) {
            waitPeople = 0
        }
        waitPeople++

        if (waitPeople == 1) {
            waitStart = ti
            ans++
        }
    }
    println(ans)
}


### FIXED CODE ###

def main() -> None:
    n, c, k = map(int, input().split())
    t = [int(input()) for _ in range(n)]
    ans = wait_start = wait_people = 0

    for ti in sorted(t):
        if ti - wait_start > k or wait_people == c:
            wait_people = 0
        wait_people += 1

        if wait_people == 1:
            wait_start = ti
            ans += 1

    print(ans)


if __name__ == '__main__':
    main()
# encording: utf-8

n = int(input())
ns = [int(input()) for _ in range(n)]
q = int(input())
qs = [int(input()) for _ in range(n)]


def main(ns, qs):
    total = 0
    for q in qs:
        if q in ns:
            total += 1
    return total


print(main(ns, qs))

### FIXED CODE ###

# encording: utf-8

_ = int(input())
ns = [int(e) for e in input().split()]
_ = int(input())
qs = [int(e) for e in input().split()]


def main(ns, qs):
    total = 0
    for q in qs:
        if q in ns:
            total += 1
    return total


print(main(ns, qs))
import numpy as np

n = int(input())
A, B = np.zeros(n), np.zeros(n)
for i in range(n):
    a, b = map(int, input().split())
    A[i] = a
    B[i] = b

ans = 0

for i in range(n-1, -1, -1):
    if A[i] % B[i] == 0:
        pass
    else:
        temp = B[i]*((A[i]//B[i])+1) - A[i]
        ans += temp
        A += temp
print(int(ans))

### FIXED CODE ###

n = int(input())
A, B = [], []
for _ in range(n):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)
ans = 0
for i in range(n-1, -1, -1):
    if (A[i]+ans) % B[i] == 0:
        continue
    else:
        ans += B[i] - (A[i]+ans) % B[i]
print(ans)
from itertools import accumulate
import numpy as np
N, K = list(map(int, input().split()))
A = np.array(list(map(int, input().split())))
A = (A+1)/2

B = [0] + A
B = list(accumulate(B))
answer = []
for i in range(N-K):
    answer.append(B[i+K]-B[i])

print(max(answer))

### FIXED CODE ###

from itertools import accumulate
import numpy as np
N, K = list(map(int, input().split()))
A = np.array(list(map(int, input().split())))
A = (A+1)/2

B = np.insert(A,0,0)
B = list(accumulate(B))
answer = []
for i in range(N-K+1):
    answer.append(B[i+K]-B[i])

print(max(answer))
# -*- coding: utf-8 -*-


def main():
    n, m = map(int, input().split())
    graph = [[] for _ in range(n)]
    dp = dict()

    for _ in range(m):
        xi, yi = map(int, input().split())
        xi -= 1
        yi -= 1
        graph[xi].append(yi)

        dp[(xi, yi)] = 0

    def dfs(v, parent=-1, count=0):
        count += 1

        for u in graph[v]:
            if u == parent:
                continue

            dp[(v, u)] = max(dp[(v, u)], count)
            dfs(u, v, dp[(v, u)])

    for i in range(n):
        if len(graph[i]) == 0:
            continue

        dfs(i)

    print(max(dp.values()))


if __name__ == '__main__':
    main()


### FIXED CODE ###

# -*- coding: utf-8 -*-


def main():
    from sys import setrecursionlimit

    setrecursionlimit(10 ** 7)

    n, m = map(int, input().split())
    graph = [[] for _ in range(n)]
    dp = [-1 for _ in range(n)]

    for _ in range(m):
        xi, yi = map(int, input().split())
        xi -= 1
        yi -= 1
        graph[xi].append(yi)

    # See:
    # https://qiita.com/drken/items/03c7db44ccd27820ea0d#g-%E5%95%8F%E9%A1%8C---longest-path
    def rec(v):
        if dp[v] != -1:
            return dp[v]

        result = 0

        for next_v in graph[v]:
            result = max(result, rec(next_v) + 1)

        dp[v] = result

        return dp[v]

    ans = 0

    for i in range(n):
        ans = max(ans, rec(i))

    print(ans)


if __name__ == '__main__':
    main()
d = list(map(int, input().split()))
L = d[0]
R = d[1]

a = L//2019
b = L//2019
c = L%2019
d = R%2019

list = []

if b-a >= 2:
  print(0)

elif b - a == 1:
  if d - c >= 0:
    print(0)
  else:
    for i in range(c,d+2019):
      for j in range(i+1,d+2019+1):
        list.append(i*j%2019)
    print(min(list)) 

else :
  for i in range(c,d):
    for j in range(i+1,d+1):
        list.append(i*j%2019)
  print(min(list)) 

### FIXED CODE ###

d = list(map(int, input().split()))
L = d[0]
R = d[1]

a = L//2019
b = R//2019
c = L%2019
d = R%2019

list = []

if b-a >= 2:
  print(0)

elif b-a == 1:
  if d >= c:
    print(0)
  else:
    for i in range(c,d+2019):
      for j in range(i+1,d+2019+1):
        list.append(i*j%2019)
    print(min(list)) 

else :
  for i in range(c,d):
    for j in range(i+1,d+1):
        list.append(i*j%2019)
  print(min(list))
n,m = map(int,input().split())
ais = []
for _ in range(m):
    ai = int(input())
    ais.append(ai)
dp = [0]*(n+1)
dp[0]=1
if ais[0]==1:
  dp[1]=0
  ais.pop(0)
else:
  dp[1]=1
for i in range(2,n+1):
    if len(ais)>0 and ais[0]==i:
        dp[i] = 0
        ais.pop(0)
    else:
        dp[i] = dp[i-1] + dp[i-2]
print(dp[n]%1000000007)


### FIXED CODE ###

n,m = map(int,input().split())
ais = []
for _ in range(m):
    ai = int(input())
    ais.append(ai)
dp = [0]*(n+1)
dp[0]=1
if len(ais)>0 and ais[0]==1:
  dp[1]=0
  ais.pop(0)
else:
  dp[1]=1
for i in range(2,n+1):
    if len(ais)>0 and ais[0]==i:
        dp[i] = 0
        ais.pop(0)
    else:
        dp[i] = dp[i-1] + dp[i-2]
print(dp[n]%1000000007)
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
#from itertools import accumulate #list(accumulate(A))
import math

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return sorted(divisors)



X = ii()
'''
a = make_divisors(X)
ind = bisect.bisect_left(a, X**0.2)

for num in a[:ind+1]:
    for i in range(num):
        j = num - i
        if i**5 + j**5 == X:
            print(i, (-1)*j)
            exit()
'''
num = int(X**0.2)+1
for i in range(num):
    #tmp = i**5
    b = (X - i**5)**0.2
    if math.floor(b) == b:
        print(i, (-1)*int(b))
        exit()

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
#from itertools import accumulate #list(accumulate(A))

S = input()

if S == 'ABC':
    print('ARC')
else:
    print('ABC')
print([NO,YES][input().strip()[::-1]==input().strip()])

### FIXED CODE ###

print(["NO","YES"][input().strip()[::-1]==input().strip()])
import collections
s = input()
K = int(input())

abc = collections.defaultdict(list)

for i in range(len(s)):
  for j in range(1,K+1):
    if i+j < len(s):
        abc[s[i:i+j]].append(i)


abc = list(abc.items())
abc.sort(key=lambda x: x[0])


print(abc[K][0])


### FIXED CODE ###

import collections
s = input()
K = int(input())

abc = collections.defaultdict(list)

for i in range(len(s)):
  for j in range(1,K+1):
    if i+j <= len(s):
        abc[s[i:i+j]].append(i)


abc = list(abc.items())
abc.sort(key=lambda x: x[0])

print(abc[K-1][0])
import scipy.linalg as linalg

import numpy as np
n = int(input())
b = np.array(list(map(int, input().strip().split())))
b *= 2
A = np.zeros((n,n))
for i in range(n):
    if i == n - 1:
        A[i,0] = 1
        A[i,n-1] = 1
    else:
        A[i,i] = 1
        A[i,i+1] = 1

#Ainv = np.linalg.inv(A)
#x = np.dot(Ainv, b)

#x = np.linalg.solve(A, b)

LU = linalg.lu_factor(A)
x = linalg.lu_solve(LU, b)

s = str(x.astype(int))
s = s.replace(',','')
s = s.replace('[','')
s = s.replace(']','')
print(s)

### FIXED CODE ###

import numpy as np
n = int(input())
b = list(map(int, input().strip().split()))
s = sum(b)
x = np.zeros((n))

x[0] = s
k = 1
for i in range(int((n-1)/2)):
    x[0] -= 2*b[k%n]
    k += 2

for i in range(1,n):
    x[i] = 2 * b[i-1] - x[i-1]

x = (x.astype(int)).tolist()

s = str(x)
s = s.replace(',','')
s = s.replace('[','')
s = s.replace(']','')
s = s.replace('  ',' ')

print(s)
import sys
input = sys.stdin.readline


a = [list(map(int, input().split())) for _ in range(3)]
n = int(input())
b = set([int(input()) for i in range(n)])
ans = [[-1]*3 for _ in range(3)]

for i in range(3):
    for j in range(3):
        if a[i][j] in b:
            ans[i][j] = 0

for i in range(3):
    if sum(ans[i]) == 0:
        cnt = 1
        break
    elif ans[0][i] + ans[1][i] + ans[2][i] == 0:
        cnt = 1
        break

if ans[0][0] + ans[1][1] + ans[2][2] == 0:
    cnt = 1
elif ans[0][2] + ans[1][1] + ans[2][0] == 0:
    cnt = 1


if cnt == 1:
    print('Yes')
else:
    print('No')


### FIXED CODE ###

a = [list(map(int, input().split())) for _ in range(3)]
n = int(input())
b = set([int(input()) for i in range(n)])
ans = [[-1]*3 for _ in range(3)]

for i in range(3):
    for j in range(3):
        if a[i][j] in b:
            ans[i][j] = 0

cnt = 0
for i in range(3):
    if sum(ans[i]) == 0:
        cnt = 1
        break
    elif ans[0][i] + ans[1][i] + ans[2][i] == 0:
        cnt = 1
        break
    elif ans[0][0] + ans[1][1] + ans[2][2] == 0:
        cnt = 1
        break
    elif ans[0][2] + ans[1][1] + ans[2][0] == 0:
        cnt = 1
        break

if cnt == 1:
    print('Yes')
else:
    print('No')
import math


N = int(input())
list1 = list(map(int, input().split()))
list2 = list(map(int, input().split()))

def CO(l):
    n = len(l)
    if n >= 1:
        m = sorted(l)
        a = l[0]
        s = m.find(a)
        return((s+1)*math.factorial(n-1)+CO(l.pop(0)))
    else:
        return 1

print(abs(CO(list1)-CO(list2)))


### FIXED CODE ###

import math


N = int(input())
list1 = list(map(int, input().split()))
list2 = list(map(int, input().split()))

def CO(l):
    n = len(l)
    if n != 1:
        m = sorted(l)
        a = l[0]
        s = m.index(a)
        l.remove(a)
        return((s)*math.factorial(n-1)+CO(l))
    else:
        return 1

print(abs(CO(list1)-CO(list2)))