Harryxun/stf_run huggingface dataset:
MOD = 1000000007
N, K = map(int,input().split())
G = [[] for _ in range(N)]
for _ in range(N-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    G[a].append(b)
    G[b].append(a)

def dfs(K, G, now, parent):
    can_use_color_num = K-2
    if parent == -1:
        can_use_color_num = K-1
    if K < len(G[now]):
        return 0
    else:
        case_num = 1
        for e in G[now]:
            if e == parent:
                continue
            case_num *= can_use_color_num
            can_use_color_num -= 1
            case_num %= MOD
        for e in G[now]:
            if e == parent:
                continue
            case_num *= dfs(K, G, e, now)
            case_num %= MOD
        print("now:{},num:{}".format(now, case_num))
        return case_num

ans = K * dfs(K, G, 0, -1)
print(ans % MOD)

### FIXED CODE ###

MOD = 1000000007
N, K = map(int,input().split())
G = [[] for _ in range(N)]
for _ in range(N-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    G[a].append(b)
    G[b].append(a)

C = [False for _ in range(N)]
F = [0]
C[0] = True
r = K
while F:
    n = F.pop()
    if n == 0:
        c = K-1
    else:
        c = K-2
    for e in G[n]:
        if C[e]:
            continue
        C[e] = True
        r = (r * c) % MOD
        c -= 1
        F.append(e)

print(r)
N = int(input())
S,T = input().stlip

s=''

for i in range(N):
  s+=S[i]+T[i]
  
print(s)



### FIXED CODE ###

N = int(input())
S, T = input().split()
s = ""
for i in range(N):
  s += S[i] + T[i]
print(s)
N=int(input())
H=list(map(int,input().split()))
count=0
ans=[]

for i in range(1,len(H)):
    if H[-i]<=H[-i-1]:
        count+=1
    else:
        ans.append(count)
        count=0

print(max(ans))

### FIXED CODE ###

N=int(input())
H=list(map(int,input().split()))
count=0
ans=[]

for i in range(1,len(H)):
    if H[-i]<=H[-i-1]:
        count+=1
    else:
        ans.append(count)
        count=0
ans.append(count)
print(max(ans))
N,T = int(input().split())
C = 2000
for i in range(N):
  c,t = int(input().split())
  if t <= T:
    C = min(c,C)
    
if C == 2000:
  print("TLE")
else: print(C)

### FIXED CODE ###

N,T = (int(x) for x in input().split())
C = 2000
for i in range(N):
  c,t = (int(x) for x in input().split())
  if t <= T:
    C = min(c,C)
    
if C == 2000:
  print("TLE")
else: print(C)
N, M = map(int, input().split())
A = [int(input()) for _ in range(M)]

days = sum(A)

if days <= N:
    print(N-days)
else:
    print(-1)

### FIXED CODE ###

N, M = map(int, input().split())
A = list(map(int, input().split()))
 
days = sum(A)
 
if days <= N:
    print(N-days)
else:
    print(-1)
#%%
a = input()
#b = input()

#%%
#a = "12 18"
#b = "2 3 1"
#%%
A = [int(x) for x in a.split()]

import math

def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True

gcb = math.gcd(A[0], A[1])  # 最大公約数

#%%
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

so_gcb = prime_factorize(gcb)


#%%
new_num = []
for num in so_gcb:
    if num not in new_num:
        new_num.append(num)

print(len(new_num))

### FIXED CODE ###

#%%
a = input()
#b = "2 3 1"
#%%
A = [int(x) for x in a.split()]

import math

def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True

import fractions
gcb = fractions.gcd(A[0], A[1])  # 最大公約数

#%%
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

so_gcb = prime_factorize(gcb)


#%%
new_num = []
for num in so_gcb:
    if num not in new_num:
        new_num.append(num)

print(len(new_num))
from math import atan, pi
a,b,x = [int(i) for i in input().split()]




ocupado = x/(a*a)

if ocupado*2 >= b:
    sobra = b - ocupado

    #alfa = atan(sobra/ocupado)
    alfa = atan(a / (2*(b-ocupado)))
else:
    alfa = atan((2*a*ocupado) / (b*b))
print("%.10f" %(90 - alfa*180/pi))

### FIXED CODE ###

from math import atan, pi
a,b,x = [int(i) for i in input().split()]




ocupado = x/(a*a)



if ocupado == b:
    alfa = pi/2

elif ocupado*2 >= b:
    sobra = b - ocupado

    #alfa = atan(sobra/ocupado)
    alfa = atan(a / (2*(b-ocupado)))
else:
    alfa = atan((2*a*ocupado) / (b*b))
print("%.10f" %(90 - alfa*180/pi))
import math

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

print(int(a*b/math.gcd(a,b)))

### FIXED CODE ###

from fractions import gcd

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

print(int(a*b/gcd(a,b)))
#coding utf-8

a,b = map(float, input().split())
# d = list(map(int,input().split()))

x = [a*b, a/b, a+b, a-b]

print(max(x))

### FIXED CODE ###

#coding utf-8

a,b = map(int, input().split())
# d = list(map(int,input().split()))

x = [a*b, a+b, a-b]

print(max(x))
r,g,b = map(int(), input().split())
num = r*100 + g*10 + b
if num % 4 == 0:
    print("YES")
else:
    print("NO")

### FIXED CODE ###

r,g,b = map(int, input().split())
num = r*100 + g*10 + b
if num % 4 == 0:
    print("YES")
else:
    print("NO")
x,y=input.split();print('<'if x<y else '>'if x>y else'=')

### FIXED CODE ###

x,y=input().split()
print('<'if x<y else'>'if x>y else'=')
from collections import deque

H, W = map(int, input().split())
Ch, Cw = map(int, input().split())
Dh, Dw = map(int, input().split())
Ch -= 1
Cw -= 1
Dh -= 1
Dw -= 1

INF = 1e10
maze = []

dh = [-1,0,1,0]
dw = [0,1,0,-1]

for i in range(H):
    tmp = list(input())
    maze.append(tmp)

reached = [[INF]*W for _ in range(H)]

l = deque()
l.appendleft((Ch, Cw))
reached[Ch][Cw] = 0
while l:
    h, w = l.popleft()
    d = reached[h][w]
    for i in range(4):
        nh = h + dh[i]
        nw = w + dw[i]
        if not 0 <= nh <= H-1 and 0 <= nw <= W-1:
            continue
        if not maze[nh][nw] != "#":
            continue
        if not reached[nh][nw] > d:
            continue
        reached[nh][nw] = d
        l.appendleft((nh, nw))
    for i in range(-2, 3):
        for j in range(-2, 3):
            nh = h + i
            nw = w + j
            if not 0 <= nh <= H-1 and 0 <= nw <= W-1:
                continue
            if not maze[nh][nw] != "#":
                continue
            if not reached[nh][nw] > d:
                continue
            reached[nh][nw] = d + 1
            l.append((nh, nw))

ans = reached[Dh][Dw]
if ans != INF:
    print(ans)
else:
    print(-1)

    

### FIXED CODE ###

from collections import deque

H, W = map(int, input().split())
Ch, Cw = map(int, input().split())
Dh, Dw = map(int, input().split())
Ch -= 1
Cw -= 1
Dh -= 1
Dw -= 1

INF = 1e10
maze = []

dh = [-1,0,1,0]
dw = [0,1,0,-1]

for i in range(H):
    tmp = list(input())
    maze.append(tmp)

reached = [[INF]*W for _ in range(H)]

l = deque()
l.appendleft((Ch, Cw))
reached[Ch][Cw] = 0
while l:
    h, w = l.popleft()
    d = reached[h][w]
    for i in range(4):
        nh = h + dh[i]
        nw = w + dw[i]
        if not (0 <= nh <= H-1 and 0 <= nw <= W-1):
            continue
        if not maze[nh][nw] != "#":
            continue
        if not reached[nh][nw] > d:
            continue
        reached[nh][nw] = d
        l.appendleft((nh, nw))
    for i in range(-2, 3):
        for j in range(-2, 3):
            nh = h + i
            nw = w + j
            if not (0 <= nh <= H-1 and 0 <= nw <= W-1):
                continue
            if not maze[nh][nw] != "#":
                continue
            if not reached[nh][nw] > d + 1:
                continue
            reached[nh][nw] = d + 1
            l.append((nh, nw))

ans = reached[Dh][Dw]
if ans != INF:
    print(ans)
else:
    print(-1)
n = int(input())
a = list(map(int,input().split()))

a.sort()

for m in range(0,int(a[n])) :
    for j in range(0,n) :
        f[m] += m//a[j]

f.sort()

print(f[n])

### FIXED CODE ###

N = int(input())
a = [int(i) for i in input().split()]
print(sum(a)-N)
x,n = map(int,input().split())
p = input().split()
p.sort()
q = p[::-1]
a = x
b = x
for i in q:
  if a == int(i):
    a -= 1
for i in p:
  if b == int(i):
    b += 1 
if x - a <= b - x:
  print(a)
else:
  print(b)

### FIXED CODE ###

x = input()
a,b,c,d,e = map(int,x.split())
print(15 - a-b-c-d-e)
n = int(input())
a = list(map(int,input().split()))
cir = 0
sum = 0
hantei=0

lis = [1]
for i in range(n):
    cc = lis[-1] - a[i]
    cc *=2
    if cc<=0:
        hantei=1
    lis.append(cc)

p#rint(lis)



for i in range(n+1):
    tmp = a[-1-i]+cir
    sum += tmp
    #print(tmp,cir)
    if i==n:
        break
    if tmp <= lis[-1-i] and tmp+a[-2-i]>lis[-2-i]:
        if tmp%2==0:
            cir = tmp//2
        else:
            cir = tmp//2+1
    else:
        cir = tmp
if hantei==1:
    print(-1)
else:
    print(-1)


### FIXED CODE ###

n = int(input())
a = list(map(int,input().split()))
cir = 1
bsum = 1
hantei=0
asum = [0 for i in range(n+1)]
asum[0] = sum(a)
for i in range(1,n+1):
    asum[i] = asum[i-1]-a[i]
#print(asum)
swi = 0
for i in range(n):
    if swi == 1:
        #print(cir,a[i])
        cir = cir-a[i]
    if swi==0:
        if (cir-a[i])*2 < asum[i]:
            cir = (cir-a[i])*2
        else:
            cir = asum[i]
            swi = 1

    bsum += cir
    if cir<=0:
        hantei=1
        break


#print(cir,a[-1])


if hantei==1 or cir!=a[-1]:
    print(-1)
else:
    print(bsum)
N = input()
S = len(N)
f = 0
if int(N)==0:
    print("No")
else:
    for i in range(S) :
        f = f + int(N[i])

if int(N)%f==0:
    print("Yes")
else:
    print("No")


### FIXED CODE ###

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

NA = N * A
if NA > B:
    print(B)
else:
    print(NA)
#include<bits/stdc++.h>
using namespace std;
int main(){
	char c[65000];
	int i,j=0,l;
	cin>>c;
	l=strlen(c);
	for(i=0;i<l;i++){
		if(c[i]=='C'){
			j=1;
		}
		if(c[i]=='F'){
			if(j==1){
				cout<<"YES";
				return 0;
			}
		} 
	}
	cout<<"NO";
	return 0;
}

### FIXED CODE ###

s = input()
if s.count('C') == 0 or s.count('F') == 0:
    print('No')
else:
    s = s[s.find('C'):]
    if s.count('F') == 0:
        print('No')
    else:
        print('Yes')
a = int(input())
count = 0
for i in range (3):
  if str(a)[i] == '1':
    count += 1
  else:
    pass
print(count)

### FIXED CODE ###

a = int(input())
count = 0
for i in range (len(str(a))):
  if str(a)[i] == '1':
    count += 1
  else:
    pass
print(count)
c1,c2,c3=input().split()
c4,c5,c6=input().split()
c7,c8,c9=input().split()
ptint(c1+c5+c9)

### FIXED CODE ###

print(input()[0]+input()[1]+input()[2])
a,b=input().split()
a=int(a)
b=int(b)
c=list(map(int,input().split()))
c.sort()
d=sum(c)
e=0
for i in range(b):
  e=e+c[-b]
print(d-2*e)

### FIXED CODE ###

a,b=input().split()
a=int(a)
b=int(b)
c=list(map(int,input().split()))
c.sort()
d=sum(c)
e=0
if a<=b:
  print(0)
else:
  for i in range(1,b+1):
    e=e+c[-i]
  print(d-e)
print("A"+"RB"[int(input())<1200)]+"C")

### FIXED CODE ###

print("A"+"RB"[int(input())<1200]+"C")
N = int(input())

def F(x):
  if x < 10:
    return x
  return x%10 + F(x//10)

answer = 'YES' if x%F(N) == 0 else 'NO'
print(answer)

### FIXED CODE ###

N = int(input())

def F(x):
  if x < 10:
    return x
  return x%10 + F(x//10)

answer = 'Yes' if N%F(N) == 0 else 'No'
print(answer)
a = [input().split() for l in range(3)]
a = [[int(item) for item in row] for row in a]
N = int(input())
b = [input() for i in range(n)]
x = 1
for i in range(N):
  for j in range(3):
    for k in range(3):
      if a[j][k] == b[i]:
        a[j][k] = 0
for i in range(3):
  if a[i][0]*a[i][1]*a[i][2] == 0 | a[0][i]*a[1][i]*a[2][i] == 0:
    x = 0
if a[0][0]*a[1][1]*a[2][2] == 0 | a[0][2]*a[1][1]*a[2][0] == 0:
  x = 0
if x:
  print('No')
else:
  print('Yes')
  

### FIXED CODE ###

a = [input().split() for l in range(3)]
n = int(input())
b = [input() for i in range(n)]
c = [a[0][0],a[1][1],a[2][2]]
d = [a[0][2],a[1][1],a[2][0]]
tate1 = len(set(a[0]) & set(b))
tate2 = len(set(a[1]) & set(b))
tate3 = len(set(a[2]) & set(b))
yoko1 = len(set([x[0] for x in a]) & set(b))
yoko2 = len(set([x[1] for x in a]) & set(b))
yoko3 = len(set([x[2] for x in a]) & set(b))
naname1 = len(set(c) & set(b))
naname2 = len(set(d) & set(b))
bingo = [tate1,tate2,tate3,yoko1,yoko2,yoko3,naname1,naname2]
if 3 in bingo:
  print("Yes")
else:
  print("No")
A,B,C=map(str,input().split())
x=len(A)
y=len(B)
if A[x-1]==B[1] and B[y-1]==C[1]:
  print("YES")
else:
  print("NO")
  

### FIXED CODE ###

A,B,C=map(str,input().split())
x=len(A)
y=len(B)
if A[x-1]==B[0] and B[y-1]==C[0]:
  print("YES")
else:
  print("NO")
A, P = input().split()
P += A*3
pi = int(P/3)
print (pi)

### FIXED CODE ###

A, P = map(int, input().split())
P += A*3
pi = int(P/2)
print (pi)
# ABC070c
from functools import reduce
import sys
import math
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

n = int(input())


def lcm_base(a, b):
    return a * b // math.gcd(a, b)


def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)


t = [int(input()) for _ in range(n)]
print(lcm(*t))


### FIXED CODE ###

# ABC070c
from fractions import gcd
from functools import reduce
import sys
import math
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

n = int(input())


def lcm_base(a, b):
    return a * b // gcd(a, b)


def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)


def gcds(*numbers):
    return reduce(gcd, numbers)


t = [int(input()) for _ in range(n)]
print(lcm(*t))
Tmp = []
Tmp = input().rstrip().split(' ')
A = Tmp[0]
B = Tmp[1]

Ans = 0
Data = A
while Data <= B:
    A = Data // 10000
    B = Data // 1000
    D = Data // 10
    E = Data % 10
    if (A==E) and (B==D):
        Ans += 1
    
    Data += 1 

print(Ans)


### FIXED CODE ###

Tmp = []
Tmp  = input().rstrip().split(' ')

A = int(Tmp[0])
B = int(Tmp[1])

Ans = 0
Data = A
while Data <= B:
    C = Data // 10000
    D = (Data - C * 10000 )// 1000
    E = Data // 100
    F = (Data - E * 100 )// 10
    G = Data % 10
    if (C==G) and (D==F):
        Ans += 1    
    Data += 1 

print(Ans)
a = int(input())

b = list(map(int,input().split()))
d = max(b)
c = [0 for i in range(pow(10,5))]
cc = [0 for i in range(pow(10,5))]
for i in range(a):
    if i % 2 == 0:
        c[b[i]] += 1
    else:
        cc[b[i]] += 1

one = 0
onee = 0
two = 0
twoo = 0
p = 0
pp = 0
for i in range(d+1):
    if one <= c[i]:
        onee = one
        one = c[i]
        p += 1
    if two <= cc[i]:
        twoo = two
        two = cc[i]
        p += 1
    if p == 2:
        pp = 1
    else:
        pp = 0
    p = 0

t = max(one+twoo,onee+two)

if pp == 0:
    print(a-one-two)
else:
    print(a-t)

### FIXED CODE ###

from collections import Counter

a = int(input())

b = list(map(int,input().split()))
d = max(b)
c = [0 for i in range(pow(10,5)+1)]
cc = [0 for i in range(pow(10,5)+1)]
for i in range(len(b)):
    if i % 2 == 0:
        c[b[i]] += 1
    else:
        cc[b[i]] += 1
first = Counter(b[::2]).most_common(2) + [(0, 0)]
latter = Counter(b[1::2]).most_common(2) + [(0, 0)]
one = 0
onee = 0
two = 0
twoo = 0
k = 0
kk = 0
for i in range(d+1):
    if one <= c[i]:
        onee = one
        one = c[i]
        k = i
    elif onee <= c[i]:
        onee = c[i]
    if two <= cc[i]:
        twoo = two
        two = cc[i]
        kk = i
    elif twoo <= cc[i]:
        twoo = cc[i]
t = max(one+twoo,onee+two)

if k != kk:
    print(a-one-two)
else:
    print(a-t)
from math import sqrt
from collections import Counter


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

    ans = 0
    p = [0] * (10**6 + 10)
    c = Counter(A)

    for a in A:
        tmp = a * 2
        if p[tmp] == 1:
            continue
        while tmp <= 10**6:
            p[tmp] = 1
            tmp += a

    for a in A:
        if p[a] == 0 and c[a] == 1:
            ans += 1

    print(ans)


if __name__ == "__main__":
    main()


### FIXED CODE ###

from math import sqrt
from collections import Counter


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

    ans = 0
    p = [0] * (10**6 + 1)
    c = Counter(A)

    for a in c.keys():
        tmp = a * 2
        while tmp <= 10**6:
            p[tmp] = 1
            tmp += a

    for a in A:
        if p[a] == 0 and c[a] == 1:
            ans += 1

    print(ans)


if __name__ == "__main__":
    main()
import math


# Me
class Check():
    def __init__(self):
        self.now_t, self.now_x, self.now_y = 0, 0, 0

    def do(self, t, x, y):
        distance = math.sqrt((x - self.now_x) * (y - self.now_y))
        duration = t - self.now_t
        print('distance', distance)
        print('duration', duration)
        if duration < distance:
            return False

        if (t - self.now_t) % 2 != (x + y - (self.now_x + self.now_y)) % 2:
            return False
        self.now_t, self.now_x, self.now_y = t, x, y
        return True


N = int(input())
c = Check()
for i in range(N):
    a = [int(x) for x in input().split()]
    if not c.do(a[0], a[1], a[2]):
        print('NO')
        exit()
print('YES')


### FIXED CODE ###

# Me
class Check():
    def __init__(self):
        self.now_t, self.now_x, self.now_y = 0, 0, 0

    def do(self, t, x, y):
        distance = ((x - self.now_x) + (y - self.now_y))
        duration = t - self.now_t
        if duration < distance:
            return False

        if distance % 2 != duration % 2:
            return False

        self.now_t, self.now_x, self.now_y = t, x, y
        return True


N = int(input())
c = Check()
for i in range(N):
    a = [int(x) for x in input().split()]
    if not c.do(a[0], a[1], a[2]):
        print('No')
        exit()
print('Yes')
a=int(input())
b=int(input())
c=int(input())
x=int(input())
s=50*c
print(len[1 for i in range(a+1) for m in range(b+1) if 0<=x-500*i+100*m<=s ])

### FIXED CODE ###

a=int(input())
b=int(input())
c=int(input())
x=int(input())
s=50*c
print(len([1 for i in range(a+1) for m in range(b+1) if 0<=x-500*i-100*m<=s]))
import sys
N, M = map(int, input().split())
X = sorted(list(map(int,input().split())))
A = []
if M == 1:
    print(0)
    sys.exit()
for i in range(M - 1):
    dif = X[i + 1] - X[i]
    A.append(dif)
for i in range(N - 1):
    A.remove(max(A))
print(sum(A))

### FIXED CODE ###

T, X = map(int,input().split())
print(T / X)
n=int(input())

if n<100:
  print(min(n,9))
elif n<10000:
  print(min(n-90),909)
else:
  print(min(n-9090),90909)

### FIXED CODE ###

n=int(input())

if n<100:
  print(min(n,9))
elif n<10000:
  print(min(n-90,909))
else:
  print(min(n-9090,90909))
from functools import reduce
MOD = 10**9 + 7
primes = list(map(int, "2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199 211 223 227 229 233 239 241 251 257 263 269 271 277 281 283 293 307 311 313 317 331 337 347 349 353 359 367 373 379 383 389 397 401 409 419 421 431 433 439 443 449 457 461 463 467 479 487 491 499 503 509 521 523 541 547 557 563 569 571 577 587 593 599 601 607 613 617 619 631 641 643 647 653 659 661 673 677 683 691 701 709 719 727 733 739 743 751 757 761 769 773 787 797 809 811 821 823 827 829 839 853 857 859 863 877 881 883 887 907 911 919 929 937 941 947 953 967 971 977 983 991 997".split(" ")))

N = int(input())
arr = []

for p in primes:
    if p <= N:
        pow_p = p
        s = 0
        while pow_p <= N:
            s += N // pow_p
            pow_p *= p
        arr.append(s+1)

print(reduce(lambda a, b: (a * b) % MOD, arr))


### FIXED CODE ###

from functools import reduce
MOD = 10**9 + 7
primes = list(map(int, "2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199 211 223 227 229 233 239 241 251 257 263 269 271 277 281 283 293 307 311 313 317 331 337 347 349 353 359 367 373 379 383 389 397 401 409 419 421 431 433 439 443 449 457 461 463 467 479 487 491 499 503 509 521 523 541 547 557 563 569 571 577 587 593 599 601 607 613 617 619 631 641 643 647 653 659 661 673 677 683 691 701 709 719 727 733 739 743 751 757 761 769 773 787 797 809 811 821 823 827 829 839 853 857 859 863 877 881 883 887 907 911 919 929 937 941 947 953 967 971 977 983 991 997".split(" ")))

N = int(input())
arr = []

for p in primes:
    if p <= N:
        pow_p = p
        s = 0
        while pow_p <= N:
            s += N // pow_p
            pow_p *= p
        arr.append(s+1)

if N == 1:
    print(1)
else:
    print(reduce(lambda a, b: (a * b) % MOD, arr))
s=input()
N=int(input())
l=len(s)
for scope in range(1,1+l):
  for first in range(1+l-scope):
    if not s[fist:first+scope] in li:
      li.append(s[first:first+scope])
li.sort()   
print(li[N])

### FIXED CODE ###

str=input()
K=int(input())
s=set()
for scope in range(1,K+1):
    for f in range(len(str)-scope+1):
        s.add(str[f:f+scope])
print(sorted([x for x in s])[K-1])
from collections import Counter


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

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

A.sort()
B.sort()
A_cnt = Counter(A)
B_cnt = Counter(B)
if max(A_cnt.values()) > 1 or max(B_cnt.values()) > 1:
    print(0)
    exit()


a = 0
b = 0
i = 1
C = [0] * (N * M)
while i <= N * M:
    if i == A[a] and i == B[b]:
        C[i - 1] = 1
        a += 1
        b += 1
    elif i == A[a] and i != B[b]:
        C[i - 1] = M - b
        a += 1
    elif i != A[a] and i == B[b]:
        C[i - 1] = N - a
        b += 1
    else:
        C[i - 1] = (N - a) * (M - b) - (N * M - i)
    i += 1

ans = 1
mod = 10 ** 9 + 7
for c in C:
    ans = (ans * c) % mod

print(ans)


### FIXED CODE ###

from collections import Counter


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

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

A.sort()
B.sort()
A_cnt = Counter(A)
B_cnt = Counter(B)
if len(A) > 0:
    if max(A_cnt.values()) > 1:
        print(0)
        exit()
if len(B) > 0:
    if max(B_cnt.values()) > 1:
        print(0)
        exit()
if A[N - 1] != N * M or B[M - 1] != N * M:
    print(0)
    exit()

a = 0
b = 0
i = 1
C = [0] * (N * M)
while i <= N * M:
    if i == A[a] and i == B[b]:
        C[i - 1] = 1
        a += 1
        b += 1
    elif i == A[a] and i != B[b]:
        C[i - 1] = M - b
        a += 1
    elif i != A[a] and i == B[b]:
        C[i - 1] = N - a
        b += 1
    else:
        C[i - 1] = (N - a) * (M - b) - (N * M - i)
    i += 1

ans = 1
mod = 10 ** 9 + 7
for c in C:
    ans = (ans * c) % mod

print(ans)
x = int(input())


def func(p):
    q = 1
    while q <= x:
        q *= p
    return q / p


z = []
a = 2


if x = 1:
    print("1")
    exit()


while a <= x ** 0.5:
    z.append(func(a))
    a += 1

print(max(z))


### FIXED CODE ###

x = int(input())

if x == 1:
    print("1")
    exit()


def func(p):
    q = p
    while q < x:
        q *= p
        if q == x:
            return q
    if q / p == p:
        return 1
    else:
        return q // p


z = []
a = 2

while a <= x:
    z.append(func(a))
    a += 1

print(max(z))
def main():
    S  = input()
    K  = input()
    if K==1:
        print(S[0])
    elif S[0]=='1':
        print(S[1])
    else:
        print(S[0])



if __name__ == '__main__':
    main()


### FIXED CODE ###

def main():
    S  = input()
    K  = int(input())

    cnt = 0
    while cnt<len(S) and  S[cnt]=='1':
        cnt = cnt + 1
    
    if K<=cnt:
        print(S[0])
    elif cnt==len(S):
        print(S[cnt-1])
    else:
        print(S[cnt])


if __name__ == '__main__':
    main()
X = [list(map(int, input().split())) for i in range(5)]
k = int(input())
print('Yay!') if max(X) - min(X) >= k else print(':(')

### FIXED CODE ###

antenas = [int(input()) for i in range(5)]
k = int(input())
if k == 0:
    print('Yay!')
    exit()
print('Yay!') if max(antenas) - min(antenas) <= k else print(':(')