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

import copy
n=int(input())
a=list(map(int,input().split()))
anslist=[]
alist=[]
for i in range(n):
    if(a[i] in alist):
        anslist.append(0)
        print(anslist[a.index(a[i])])
        continue
    else:
        alist.append(a[i])
        ans = 0
        ad=copy.copy(a)
        del(ad[i])
        adset=list(set(ad))
        for j in adset:
            if(ad.count(j)>=2):
                ans += (ad.count(j)*(ad.count(j)-1)) // 2
            else:
                continue
    anslist.append(ans)
    print(ans)

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
aset=list(set(a))
ans=0
al=[0]*200000
for i in a:
    al[i]+=1
for j in aset:
    k=al[j]
    ans+=(k*(k-1))//2
for u in a:
    print(ans-al[u]+1)
### BUGGY CODE ###

N = int(input())

def prime_factor(n):
    i = 2
    table = []
    while i * i <= n:
        while n % i == 0:
            n //= i
            table.append(i)
        i += 1
    if n > 1:
        table.append(n)
    return table

res = prime_factor(N)

import itertools

#n桁のm値のbitを生成
def bit(n, m):
    bit_list = list(itertools.product([i for i in range(m)], repeat=n))
    return bit_list

bit_list = bit(len(res), 2)
result = 10 ** 7
for b in bit_list:
    tmp1 = 1
    tmp2 = 1
    for i in range(len(res)):
        if b[i] == 0:
            tmp1 *= res[i]
        else:
            tmp2 *= res[i]
            
    result = min(result, max(len(str(tmp1)), len(str(tmp2))))
    
print(result)

### FIXED CODE ###

N = int(input())

def prime_factor(n):
    i = 2
    table = []
    while i * i <= n:
        while n % i == 0:
            n //= i
            table.append(i)
        i += 1
    if n > 1:
        table.append(n)
    return table

res = prime_factor(N)

result = 10 ** 10
for i in range(1, N+1):
    if N%i == 0:
        result = min(result, max(len(str(i)), len(str(N//i))))
    if i*i > N:
        break


print(result)
### BUGGY CODE ###

s = input()
K = int(input())

l = len(s)

sub = set()

for i in range(l):
    for j in range(i+1):
        sub.add(s[j:i+1])

#print(sub)
subl = list(sub)

subl.sort()

#print(subl)

print(subl[K-1])


### FIXED CODE ###

import collections

s = input()
K = int(input())

l = len(s)
sub = set()

if l <= 50:
    for i in range(l):
        for j in range(i+1):
            sub.add(s[j:i+1])
    #print(sub)
    subl = list(sub)
    subl.sort()
    #print(subl)
    print(subl[K-1])

else:
    cl = collections.Counter(s).most_common()
    cl.sort(key=lambda x: x[0])
    #print(cl)
    d = 0
    while len(sub) < K:
        be = cl[d][0]
        for i in range(l):
            if s[i] == be:
                for j in range(K):
                    sub.add(s[i:min(i+j+1,l)])
        d += 1
    #print(sub)
    subl = list(sub)
    subl.sort()
    print(subl[K-1])
### BUGGY CODE ###

N, M =  map(int, (input().split(' ')))
A_list = []
B_list = []
money = 0
while len(A_list) < N:
    A, B =  map(int, (input().split(' ')))
    A_list.append(A)
    B_list.append(B)

while True:
    i = A_list.index(min(A_list))
    if B_list[i] < M:
        money += A_list[i] * B_list[i]
        M -= B_list[i]
    else:
        money += A_list[i] * M
        M = 0 
    A_list.pop(i)
    B_list.pop(i)
    if M == 0:
        print(money)
        exit()

### FIXED CODE ###

N, M =  map(int, (input().split(' ')))
A_B_list = []
money = 0
while len(A_B_list) < N:
    A, B =  map(int, (input().split(' ')))
    A_B_list.append([A, B])
A_B_list = sorted(A_B_list)
    

for A, B in A_B_list:
    if B < M:
        money += A * B
        M -= B
    else:
        money += A * M
        M = 0 
    if M == 0:
        print(money)
        exit()
### BUGGY CODE ###

import sys
input=sys.stdin.readline

H,W = map(int, input().split())

a = set()
i = 0
for h in range(H):
    s = list(input().strip())
    for c in s:
        if c == "#":
            a.add(i)
        i += 1
#print(a)

m = 0
for i in range(H*W):
    ni = H+W-2
    if i in a:
        ni = 0
    else:
        for j in a:
            ni = min(ni, abs(j//W-i//W) + abs(j%W -i%W))
#            print(ni, abs(j-i)//W, abs(j%W -i%W))
    m = max(m, ni)
print(m)


### FIXED CODE ###

import sys
input=sys.stdin.readline
H,W = map(int, input().split())

b = [[True]*(W+2)]
for _ in range(H):
    b.append([True] + [x == '#' for x in input().strip()] + [True])
b.append([True]*(W+2))

check = []
for i in range(1,H+1):
    for j in range(1,W+1):
        if b[i][j]:
            check.append((i,j))
t = 0
while check:
    tmp = []
    for i,j in check:
        if not b[i-1][j]:
            b[i-1][j] = True
            tmp.append((i-1,j))
        if not b[i][j-1]:
            b[i][j-1] = True
            tmp.append((i,j-1))
        if not b[i][j+1]:
            b[i][j+1] = True
            tmp.append((i,j+1))
        if not b[i+1][j]:
            b[i+1][j] = True
            tmp.append((i+1,j))
    check = tmp
    t += 1

print(t-1)
### BUGGY CODE ###

import numpy

tmp=input()
list=input().split(" ")
array=numpy.zeros(len(list),dtype=">i4")
for i in range(len(list)):
  array[i]=int(list[i])

a=int(input())#-1

for i in range(a):
  b=input().split(" ")
  array=numpy.where(array==int(b[0]),int(b[1]),array)
  sum=numpy.sum(array)
  print(sum)

### FIXED CODE ###

import numpy

tmp=input()
list=input().split(" ")
list=[int(x) for x in list]
array=numpy.array(list,dtype=">i4")
sum=numpy.sum(array)
all=numpy.zeros(100001,dtype=">i4")
for i in array:
  all[i]+=1
#for i in range(len(list)):
#  array[i]=int(list[i])

a=int(input())

for i in range(a):
  b=input().split(" ")
  b0=int(b[0])
  b1=int(b[1])
  diff=all[b0]*(b1-b0)
  sum+=diff
  all[b1]+=all[b0]
  all[b0]=0
  print(sum)
### BUGGY CODE ###

casen=0
if casen==0:
    a=[]
    c=[]
    n=int(input())
    for i in range(n):
        ai,bi=map(int,input().split())
        a.append([ai,bi])
    for i in range(n):
        ci,di=map(int,input().split())
        c.append([ci,di])
elif casen==1:
    n=3
    a=[[2,0],[3,1],[1,3]]
    c=[[4,2],[0,4],[5,5]]
elif casen==2:
    n=3
    a=[[0,0],[1,1],[5,2]]
    c=[[2,3],[3,4],[4,5]]
elif casen==3:
    n=2
    a=[[2,2],[3,3]]
    c=[[0,0],[1,1]]
elif casen==4:
    n=5
    a=[[0,0],[7,3],[2,2],[4,8],[1,6]]
    c=[[8,5],[6,9],[5,4],[9,1],[3,7]]
elif casen==5:
    n=5
    a=[[0,0],[1,1],[5,5],[6,6],[7,7]]
    c=[[2,2],[3,3],[4,4],[8,8],[9,9]]

a.sort()
c.sort()

t=[]
for ia in range(n):
    s=[]
    for ic in range(n):
        if a[ia][0]<c[ic][0] and a[ia][1]<c[ic][1]:
            s.append(ic)
    t.append([len(s),s])
#    print(s)
    
#t.sort()
#print("t: ",t)

tyn2=[]
icnt=0

#import queue
#tyn3 = queue.Queue()

from collections import deque
tyn3 = deque()

# FIFOキューの作成
#    q.put(i)
#    q.get()

def pcnt(icnt,ia,t,n,tyn3,icntmax):
#    print("icnt:",icnt," ia:",ia," n:",n," icntmax:",icntmax,",",t[ia][1],",",tyn2)
    ia1=ia
    if ia>=n-1:
        icntmax=max(icnt,icntmax)
#        print("return icnt:",icnt," icntmax:",icntmax,tyn2)
        if len(tyn3)>0:
            tyn3.pop()
        ia=ia-1
        return icntmax,ia
#    print(ia)
    icnt1=icnt
    for it in t[ia][1]:
        ia=ia1+1
        if not it in tyn3:
            icnt=icnt1+1
#            tyn3.put(it)
            tyn3.append(it)
            icntmax,ia=pcnt(icnt,ia,t,n,tyn3,icntmax)
    ia=ia+1
    icntmax,ia=pcnt(icnt,ia,t,n,tyn3,icntmax)
#    tyn2.pop(-1)
    return icntmax,ia

ia=-1    
icntmax=0
icntmax,ia=pcnt(icnt,ia,t,n,tyn3,icntmax)

print(icntmax)        
    


### FIXED CODE ###

casen=0
if casen==0:
    a=[]
    c=[]
    n=int(input())
    for i in range(n):
        ai,bi=map(int,input().split())
        a.append([ai,bi])
    for i in range(n):
        ci,di=map(int,input().split())
        c.append([ci,di])
elif casen==1:
    n=3
    a=[[2,0],[3,1],[1,3]]
    c=[[4,2],[0,4],[5,5]]
elif casen==2:
    n=3
    a=[[0,0],[1,1],[5,2]]
    c=[[2,3],[3,4],[4,5]]
elif casen==3:
    n=2
    a=[[2,2],[3,3]]
    c=[[0,0],[1,1]]
elif casen==4:
    n=5
    a=[[0,0],[7,3],[2,2],[4,8],[1,6]]
    c=[[8,5],[6,9],[5,4],[9,1],[3,7]]
elif casen==5:
    n=5
    a=[[0,0],[1,1],[5,5],[6,6],[7,7]]
    c=[[2,2],[3,3],[4,4],[8,8],[9,9]]

c.sort()
a.sort(key=lambda x:x[1])
#a.reverse()

icnt=0
ic2=0
for ic in range(len(c)):
    for ia in range(len(a)-1,-1,-1):
        if a[ia][0]<c[ic][0] and a[ia][1]<c[ic][1]:
            icnt=icnt+1
            del a[ia]
            break
        else:
            continue
        break

print(icnt)
### BUGGY CODE ###

def search(nmax, n, x):
    if n > nmax: return 0
    if x < 0: return 0
    if x == 0: return 1
    return search(nmax, n+1, x) + search(nmax, n+1, x-n)

while 1:
    n, x = map(int, raw_input().split())
    if n == 0 and x == 0: break

    num = search(n, 0, x)
    print(num)

### FIXED CODE ###

while 1:
    n, x = map(int, raw_input().split())
    if n == 0 and x == 0: break

    count = 0
    for i in range(1, n+1):
        for j in range(i+1, n+1):
            for k in range(j+1, n+1):
                if i + j + k == x:
                    count += 1

    print(count)
### BUGGY CODE ###

num = input()
numlist = input().split()

ans=1
max=10**18
overflg=False
for i in numlist:
  ans *= int(i)

if ans > max:
  print("-1")
else:
  print(ans)


### FIXED CODE ###

def keisan(numlist):
  ans=1
  if "0" in numlist:
    return "0"
  for i in numlist:
    ans *= int(i)
    if ans > max:
      return "-1"
  return ans

  
  

num = input()
numlist = input().split()

max=10**18
print(keisan(numlist))
### BUGGY CODE ###

def solve():
    N,M,S = map(int,input().split())
    UVAB = [tuple(map(int,input().split())) for i in range(M)]
    CD = [tuple(map(int,input().split())) for i in range(N)]

    es = [[] for _ in range(N)]
    for u,v,a,b in UVAB:
        u,v = u-1,v-1
        es[u].append((v,a,b))
        es[v].append((u,a,b))

    INF = float('inf')
    times = [INF] * (2501 * N)
    start = min(2500,S)*N
    times[start] = 0
    hq = [(0,start)]
    ans = [-1] * N
    ans[0] = 0
    reached = set()
    import heapq
    heapq.heapify(hq)
    while hq:
        t,v = heapq.heappop(hq)
        s,i = divmod(v,N)
        if ans[i] < 0:
            ans[i] = t
            reached.add(i)
            if len(reached) == N-1: break
        for to,a,b in es[i]:
            if a > s: continue
            nv = (s-a)*N + to
            if times[nv] <= t + b: continue
            times[nv] = t + b
            heapq.heappush(hq, (t+b, nv))
        ns = s
        nt = times[v]
        while ns <= 2500:
            ns += CD[i][0]
            nt += CD[i][1]
            nv = min(2500,ns)*N + i
            if times[nv] <= nt: continue
            times[nv] = nt
            heapq.heappush(hq, (nt, nv))
    print(*ans[1:], sep='\n')
solve()

### FIXED CODE ###

def solve():
    import sys
    input = sys.stdin.readline
    N,M,S = map(int,input().split())
    UVAB = [tuple(map(int,input().split())) for i in range(M)]
    CD = [tuple(map(int,input().split())) for i in range(N)]

    es = [[] for _ in range(N)]
    for u,v,a,b in UVAB:
        u,v = u-1,v-1
        es[u].append((v,a,b))
        es[v].append((u,a,b))

    INF = float('inf')
    times = [INF] * (2501 * N)
    start = min(2500,S)*N
    times[start] = 0
    hq = [start]
    ans = [-1] * N
    ans[0] = 0
    reached = 0
    import heapq
    heapq.heapify(hq)
    while hq:
        x = heapq.heappop(hq)
        t,v = divmod(x,N*2501)
        s,i = divmod(v,N)
        if ans[i] < 0:
            ans[i] = t
            reached += 1
            if reached == N-1: break
        for to,a,b in es[i]:
            if a > s: continue
            nv = (s-a)*N + to
            if times[nv] <= t + b: continue
            times[nv] = t + b
            heapq.heappush(hq, (t+b)*N*2501 + nv)
        ns = s
        nt = times[v]
        while ns <= 2500:
            ns += CD[i][0]
            nt += CD[i][1]
            nv = min(2500,ns)*N + i
            if times[nv] <= nt: break
            times[nv] = nt
            heapq.heappush(hq, nt*N*2501 + nv)
    print(*ans[1:], sep='\n')
solve()
### BUGGY CODE ###

import math
N=int(input())

n=math.floor(math.sqrt(N))

for n in range(1,N+1):
    ans=0
    for x in range(1,n ):
        for y in range(1, n):
            for z in range(1, n):
                if x**2+y**2+z**2+x*y+y*z+z*x==n:
                        ans+=1
    print(ans)


### FIXED CODE ###

n=int(input())
ans=[0 for _ in range(10001)]

for x in range(1,101):
  for y in range(1,101):
    for z in range(1,101):
      v=x*x+y*y+z*z+x*y+y*z+z*x
      if v<10001:
        ans[v]+=1

for i in range(n):
  print(ans[i+1])
### BUGGY CODE ###

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

INF = 10 ** 11 + 1
S = [-INF] + [int(input()) for _ in range(A)] + [INF]
T = [-INF] + [int(input()) for _ in range(B)] + [INF]
X = [int(input()) for _ in range(Q)]

def bsr(a, v, lo=0, hi=None):
	if hi == None:
		hi = len(a) - 1
	if hi < lo:
		return lo
	mi = (lo + hi) // 2
	if v < a[mi]:
		return bsr(a, v, lo, mi - 1)
	else:
		return bsr(a, v, mi + 1, hi)

#print(S)
#print(T)
#print()

for x in X:
	sr = bsr(S, x)
	sl = sr - 1
	tr = bsr(T, x)
	tl = tr - 1
	#print(sr, sl, tr, tl)
	#print(S[sr], S[sl], T[tr], T[tl])
	cost = []
	for m in [S[sr], S[sl]]:
		for n in [T[tr], T[tl]]:
			cost += [abs(x - m) + abs(m - n), abs(x - n) + abs(m - n)]
	#print(sr, sl, tr, tl, cost)
	print(min(cost))
	#break


### FIXED CODE ###

import bisect
A, B, Q = map(int, input().split())

INF = 10 ** 11 + 1
S = [-INF] + [int(input()) for _ in range(A)] + [INF]
T = [-INF] + [int(input()) for _ in range(B)] + [INF]
X = [int(input()) for _ in range(Q)]

"""
def bsr(a, v, lo=0, hi=None):
	if hi == None:
		hi = len(a) - 1
	if hi < lo:
		return lo
	mi = (lo + hi) // 2
	if v < a[mi]:
		return bsr(a, v, lo, mi - 1)
	else:
		return bsr(a, v, mi + 1, hi)
"""

def bsr(a, v):
	return bisect.bisect_right(a, v)

#print(S)
#print(T)
#print()

for x in X:
	sr = bsr(S, x)
	sl = sr - 1
	tr = bsr(T, x)
	tl = tr - 1
	#print(sr, sl, tr, tl)
	#print(S[sr], S[sl], T[tr], T[tl])
	cost = []
	for m in [S[sr], S[sl]]:
		for n in [T[tr], T[tl]]:
			cost += [abs(x - m) + abs(m - n), abs(x - n) + abs(m - n)]
	#print(sr, sl, tr, tl, cost)
	print(min(cost))
	#break
### BUGGY CODE ###

from collections import deque
def bfs(maze, visited, l,n_w):
    queue = deque(l)
    for i in queue:
        visited[i[0]][i[1]] = 0
    while queue:
        y, x = queue.popleft()
        if n_w==0:
            s=set()
            for i in visited:
                s=s|set(i)
            return(max(s))
        for j, k in ([1, 0], [-1, 0], [0, 1], [0, -1]):
            new_y, new_x = y+j, x+k
            if maze[new_y][new_x] == "." and visited[new_y][new_x] == -1:
                visited[new_y][new_x] = visited[y][x] + 1
                queue.append([new_y, new_x])
                n_w-=1

R, C = map(int, input().split())


maze = ["$"*(C+2)]+["$"+input()+"$" for i in range(R)]+["$"*(C+2)]
visited = [[-2]*(C+2)]+[[-2]+[-1]*(C)+[-2] for j in range(R)]+[[-2]*(C+2)]
l_b=[]
for i in range(R+2):
    for j in range(C+2):
        if maze[i][j]=="#":
            l_b.append([i,j])
n_w=R*C-len(l_b)

print(bfs(maze, visited,l_b,n_w))

### FIXED CODE ###

from collections import deque
def bfs(maze, visited, l,n_w):
    queue = deque(l)
    for i in queue:
        visited[i[0]][i[1]] = 0
    while queue:
        y, x = queue.popleft()
        if n_w==0:
            s=set()
            tmp=0
            for i in visited:
                if max(i)>tmp:tmp=max(i)
            return(tmp)
        for j, k in ([1, 0], [-1, 0], [0, 1], [0, -1]):
            new_y, new_x = y+j, x+k
            if maze[new_y][new_x] == "." and visited[new_y][new_x] == -1:
                visited[new_y][new_x] = visited[y][x] + 1
                queue.append([new_y, new_x])
                n_w-=1

R, C = map(int, input().split())


maze = ["$"*(C+2)]+["$"+input()+"$" for i in range(R)]+["$"*(C+2)]
visited = [[-2]*(C+2)]+[[-2]+[-1]*(C)+[-2] for j in range(R)]+[[-2]*(C+2)]
l_b=[]
for i in range(R+2):
    for j in range(C+2):
        if maze[i][j]=="#":
            l_b.append([i,j])
n_w=R*C-len(l_b)

print(bfs(maze, visited,l_b,n_w))
### BUGGY CODE ###

n,m=map(int, input().split())
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
uf=UnionFind(n)
for i in range(m):
    a,b=map(int, input().split())
    uf.union(a-1,b-1)
ans=0
for i in uf.roots():
    ans=max(ans,len(uf.members(i)))
print(ans)

### FIXED CODE ###

n,m=map(int, input().split())
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
uf=UnionFind(n)
for i in range(m):
    a,b=map(int, input().split())
    uf.union(a-1,b-1)
ans=0
for i in uf.roots():
    ans=max(ans,uf.size(i))
print(ans)
### BUGGY CODE ###

X,Y,Z,K = map(int,input().split())
l_a = [int(x) for x in input().split()]
l_b = [int(x) for x in input().split()]
l_c = [int(x) for x in input().split()]
l_a.sort(reverse = True)  
l_b.sort(reverse = True)  
l_c.sort(reverse = True)
l_d = [a + b for a in l_a for b in l_b]
l_d.sort(reverse = True)
l_d[:3000]
l_e = [ab + c for ab in l_d for c in l_c]
l_e.sort(reverse = True)
 
for i in range(K):
    print(l_e[i])

### FIXED CODE ###

X,Y,Z,K=map(int,input().split())
A=[int(x) for x in input().split()]
A.sort(reverse=True)
B=[int(x) for x in input().split()]
B.sort(reverse=True)
C=[int(x) for x in input().split()]
C.sort(reverse=True)
D=[a+b for a in A for b in B]
D.sort(reverse=True)
D=D[:3000]
E=[ab+c for ab in D for c in C]
E.sort(reverse=True)
for i in range(K):
  print(E[i])
### BUGGY CODE ###

import numpy as np


def add2(l):
    ys = np.empty(0, dtype=int)
    for i in range(len(l)):
        zs = l[i] + l[i+1:]
        ys = np.concatenate([ys, zs], 0)
    return ys


def add(n, l):
    if len(l) == 0:
        return np.empty(0)
    elif n == 1:
        return l
    elif n == 2:
        return add2(l)
    else:
        ys = add(n, l[1:])
        zs = l[0] + add(n-1, l[1:])
        return np.concatenate([ys, zs], 0)


def main():
    n, a = (int(x) for x in input().split())
    xs = np.array([int(x) for x in input().split()], dtype='int')
    tot = np.sum(xs)

    if n == 1:
        # count = len([x for x in xs if x == a])
        count = np.sum(xs == a)
    else:
        count = 0
        lop = n // 2 + 1
        for i in range(1, n//2+1):
            ys = add(i, xs)
            count += np.sum(ys == a * i)
            if n - i > i:
                zs = tot - ys
                count += np.sum(zs == a * (n - i))
        if np.sum(xs) == n * a:
            count += 1

    print(count)


if __name__ == '__main__':
    main()


### FIXED CODE ###

import numpy as np
n,avea=tuple(map(lambda x:int(x),input().split()))
x=list(map(lambda x:int(x), input().split()))
x=np.array(x)
x=x-avea
w=max(abs(min(x)),abs(max(x)))*n
dp=np.zeros((n+1,2*w+1),dtype=int)
dp[0,w]=1
for i in range(n):
    for j in range(2*w+1):
        if 0<=j-x[i]<=2*w:
            dp[i+1,j]=dp[i,j]+dp[i,j-x[i]]
        else:
            dp[i+1,j]=dp[i,j]
print(dp[n,w]-1)
### BUGGY CODE ###

S = input()
Q = int(input())
Queries = [input().split() for _ in range(Q)]

need_reverse = False

for q in Queries:
    if q[0] == "1":
        need_reverse = not need_reverse
    else:
        if q[1] == "1":
            if not need_reverse:
                S = q[2] + S
            else:
                S = S + q[2]
        else:
            if not need_reverse:
                S = S + q[2]
            else:
                S = q[2] + S

print(S if not need_reverse else S[::-1])

### FIXED CODE ###

from collections import deque

S = deque(input())
Q = int(input())

reverse = False
cnt = 0
for i in range(Q):
    inp = input().split()
    if inp[0] == "1":
        cnt += 1
        reverse = (cnt % 2 != 0)
        #S = S[::-1]
    else:
        f, c = inp[1:]
        if int(f) == 1:
            if reverse:
                S.append(c)
            else:
                S.appendleft(c)
        else:
            if reverse:
                S.appendleft(c)
            else:
                S.append(c)
S = "".join(S)
print(S[::-1] if reverse else S)
### BUGGY CODE ###

N=int(input())
A=list(map(int,input().split()))
A.sort()
L=[]
for i in range(N):
    if len(A)>=3:
        a=A.pop(0)
        b=A.pop(-1)
        if (b-a)-A[0] >= A[-1]-(a-b):
            A.append(b-a)
            A.sort()
            L.append([b,a])
        else:
            A.append(a-b)
            A.sort()
            L.append([a,b])
    elif len(A)==2:
        a = A.pop(0)
        b = A.pop(-1)
        A.append(b-a)
        L.append([b,a])
        break
    else:
        break
print(A[0])
for j in L:
    print(j[0],j[1],sep=' ')


### FIXED CODE ###

from collections import deque
N=int(input())
A=list(map(int,input().split()))
A.sort()
A=deque(A)
L=deque([])
for i in range(N):
    if len(A)>=3:
        a=A.popleft()
        b=A.pop()
        if (b-a)-A[0] >= A[-1]-(a-b):
            A.append(b-a)
            L.append([b,a])
        else:
            A.appendleft(a-b)
            L.append([a,b])
    elif len(A)==2:
        a = A.popleft()
        b = A.pop()
        A.append(b-a)
        L.append([b,a])
        break
    else:
        break
print(A[0])
for j in L:
    print(j[0],j[1],sep=' ')
### BUGGY CODE ###

from itertools import combinations

# input
s = input()
K = int(input())

# check
case = []
append = case.append
for i in range(1, K + 1):
    for c in combinations(list(s), i):
        if "".join(c) in s and "".join(c) not in case:
            append("".join(c))
case.sort(reverse=True)

print(case[-K])

### FIXED CODE ###

# input
s = input()
K = int(input())

# check
case = []
append = case.append
for i in range(1, K + 1):
    for idx in range(0, len(s) - (i - 1)):
        if s[idx:idx + i] not in case:
            append(s[idx:idx + i])
case.sort(reverse=True)

print(case[-K])