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

n,a=map(int,input().split())
X=list(map(int,input().split()))
dp=[[[0]*52 for _ in range(2505)] for _ in range(52)]
ans=0
dp[0][0][0]=1
for i in range(n):
    for j in range(52+50*i):
        for k in range(51):
            ni=i+1
            nj=j+X[i]
            nk=k+1
            dp[ni][nj][nk]+=dp[i][j][k]
            dp[ni][j][k]+=dp[i][j][k]
ans=0
for i in range(1,n+1):
    ans+=dp[n][i*a][i]
print(ans)

### FIXED CODE ###

n,a=map(int,input().split())
X=list(map(int,input().split()))
dp=[[[0]*55 for _ in range(2555)] for _ in range(55)]
ans=0
dp[0][0][0]=1
for i in range(n):
    for j in range(52+50*i):
        for k in range(n):
            ni=i+1
            nj=j+X[i]
            nk=k+1
            dp[ni][nj][nk]+=dp[i][j][k]
            dp[ni][j][k]+=dp[i][j][k]
ans=0
for i in range(1,n+1):
    ans+=dp[n][i*a][i]
print(ans)
### BUGGY CODE ###

# coding: utf-8
# Here your code !
n = input()
m = [0] * n
max = [0] * n
kijun = [0] * n
rieki = [0] * n
max_rieki = 0


for i in xrange(n):
 m[i] = input()
 
 
for i in xrange(n):
 if i != n-1:    
  max[i] = m[i+1] 
  kijun[i] = m[i]
  for j in xrange(i+1,n): 
   if max[i] < m[j]:
      max[i] = m[j]
  rieki[i] = max[i] - kijun[i]
  if i == 0:
   max_rieki = rieki[0]
  if rieki[i] > max_rieki:
   max_rieki = rieki[i]

print max_rieki

### FIXED CODE ###

n = input()
m = [0] * n
max_rieki = -1000000000



for i in xrange(n):
 m[i] = input()

min_rieki = m[0]
for i in xrange(1,n): 
  if max_rieki < m[i] - min_rieki:
     max_rieki = m[i] - min_rieki
  if min_rieki > m[i]:
     min_rieki = m[i]

print max_rieki
### BUGGY CODE ###

N = int(input())

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

def check_triangle(a, b, c):
    if a < b + c and b < c + a and c < a + b:
        return True
    return False

sum = 0
for i, l_1 in enumerate(L[:-2]):
    for j, l_2 in enumerate(L[i+1:-1]):
        for l_3 in L[i + j + 2:]:
            if check_triangle(l_1, l_2, l_3):
                sum += 1

print(sum)



### FIXED CODE ###

N = int(input())

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

count = 0 
L.sort()

for i in range(N-2):
    k = i + 2
    for j in range(i+1,N):
        while (k<N and L[i] + L[j] > L[k]):
            k += 1

        if k > j:
            count += k - j - 1


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

import bisect
import copy
def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))




N=one_int()
L=many_int()

L=sorted(L)

sankaku_dict={}
search_end={}
for i in range(len(L)-1):
    for j in range(i+1, len(L)):
        #すでに探索済みか判定
        temp = str(L[i]) +","+ str(L[j])
        if temp in search_end:
            continue

        high=L[j]
        low=L[i]

        Lcopy = copy.deepcopy(L)
        Lcopy.remove(high)
        Lcopy.remove(low)
        Lcopy = sorted(Lcopy)

        #下限を取得    
        under_index = bisect.bisect_right(Lcopy,high-low)
        #上限を取得
        high_index = bisect.bisect_left(Lcopy,high+low)
        for va in Lcopy[under_index:high_index]:
            temp = sorted([high,low, va])
            temp = (temp[0]*10**8) + (temp[1]*10**4) + temp[2]
            sankaku_dict[temp]=1

# len(sankaku_dict)
print(len(sankaku_dict.keys()))

### FIXED CODE ###

import bisect
import copy
def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))


N=one_int()
L=many_int()

L=sorted(L)

sankaku_dict={}
count=0
for i in range(len(L)-1):
    low=L[i]
    for j in range(i+1, len(L)):
        #すでに探索済みか判定
        high = L[j]
        
        #上限を取得
        high_index = bisect.bisect_left(L[j+1:], high+low)
        count+=high_index#len(L[j+1:high_index])

# len(sankaku_dict)
print(count)
# print(len(sankaku_dict.keys()))
### BUGGY CODE ###

a, b, k = [int(i) for i in input().split()]
n = [i for i in range(a, b+1) if i<=a+(k-1) or i>=b-(k-1)]
for i in n:
  print(i)

### FIXED CODE ###

a, b, k = [int(i) for i in input().split()]
if k >= b-a+1:
  for i in range(a, b+1):
    print(i)
else:
  c = [i for i in range(a, a+k)]
  d = [i for i in range(b-(k-1), b+1)]
  e = sorted(list(set(c) | set(d)))
  for i in e:
    print(i)
### BUGGY CODE ###

from sys import stdin, setrecursionlimit


def main():
    mod = 10 ** 9 + 7
    input = stdin.buffer.readline
    s = list(input()[:-1].decode())
    s.reverse()
    n = len(s)

    p10 = [0] * n
    p10[0] = 1
    for i in range(1, n):
        p10[i] = 10 * p10[i - 1]

    dp = [0] * 13
    if s[0] == '?':
        for i in range(10):
            dp[i % 13] += 1
    else:
        dp[int(s[0]) % 13] += 1

    for i in range(1, n):
        tmp_dp = [0] * 13
        if s[i] == '?':
            for j in range(13):
                for k in range(10):
                    index = (k * p10[i] + j) % 13
                    tmp_dp[index] += dp[j]
                    tmp_dp[index] %= mod
        else:
            for j in range(13):
                index = (int(s[i]) * p10[i] + j) % 13
                tmp_dp[index] += dp[j]
                tmp_dp[index] %= mod
        dp = tmp_dp

    print(dp[5] % mod)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()


### FIXED CODE ###

from sys import stdin, setrecursionlimit


def main():
    mod = 10 ** 9 + 7
    input = stdin.buffer.readline
    s = list(input()[:-1].decode())
    n = len(s)

    dp = [0] * 13
    if s[0] == '?':
        for i in range(10):
            dp[i % 13] += 1
    else:
        dp[int(s[0]) % 13] += 1

    for i in range(1, n):
        tmp_dp = [0] * 13
        if s[i] == '?':
            for j in range(13):
                for k in range(10):
                    index = (10 * j + k) % 13
                    tmp_dp[index] += dp[j]
                    tmp_dp[index] %= mod
        else:
            for j in range(13):
                index = (10 * j + int(s[i])) % 13
                tmp_dp[index] += dp[j]
                tmp_dp[index] %= mod
        dp = tmp_dp

    print(dp[5] % mod)


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

import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
# 解説を見てしまったので、せめて再帰ではない方法で
def main():
    n = int(input())
    m = 1 << n  # 総組合せ数
    aa = LLI(n)
    dp = [0] * m
    for s in range(2, m):
        # sのうさぎたちが1グループだった場合
        value = 0
        jj = []
        for i in range(n):
            if not s & 1 << i: continue
            for j in jj:
                value += aa[i][j]
            jj.append(i)
        # 部分集合tとその補集合に分かれる場合
        # 全体集合sから始めて、「1を引く」「sと論理積をとる」を繰り返すことで
        # すべての部分集合を列挙できる
        first = [True] * m
        t = (s - 1) & s
        while first[t] and t > 0:
            value_div = dp[t] + dp[s - t]
            if value_div > value: value = value_div
            first[s - t] = False
            t = (t - 1) & s
        dp[s]=value
    print(dp[m-1])

main()


### FIXED CODE ###

def max_ten(s):
    if memo[s]!="e":
        return memo[s]
    ten = 0
    # 分けない場合の点数
    for ai, ar in enumerate(a[:-1]):
        if s >> ai & 1:
            ten += sum(ar[j] * (s >> j & 1) for j in range(1 + ai, n))
    # 分ける場合の点数
    bubun = (s - 1) & s
    while bubun > 0:
        kari = max_ten(bubun) + max_ten(bubun ^ s)
        if kari > ten:
            ten = kari
        bubun = (bubun - 1) & s
    memo[s] = ten
    return ten


n = int(input())
a = [list(map(int, input().split())) for _ in range(n)]
s = (1 << n) - 1
memo = ["e"] * (1 << n)
print(max_ten(s))
### BUGGY CODE ###

n, k = list(map(int, input().split(' ')))
orig_a = input()
for _ in range(k):
  s, e = list(map(int, input().split(' '))) # TLEかも
  a = orig_a[s-1:e]
  print(a.count('AC'))


### FIXED CODE ###

n, k = list(map(int, input().split(' ')))
orig_a = input()
acs = {}
for i in range(n):
  if i < 1:
    acs[i] = 0
  else:
    acs[i] = acs[i-1] + (orig_a[i-1: i+1] == 'AC')
for _ in range(k):
  s, e = list(map(int, input().split(' ')))
  print(acs[e-1] - acs[s-1])
### BUGGY CODE ###

#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10

#solve
def solve():
    n = II()
    a = LIR(n)
    n1 = 1 << n
    dp = [0] * n1
    dp[0] = 1
    q = [[0], []]
    b = [1 << i for i in range(n)]
    for i in range(n):
        t = i & 1
        t1 = t ^ 1
        i1 = i + 1
        ai = a[i]
        while q[t]:
            p = q[t].pop()
            for j in range(n):
                if ai[j]:
                    j1 = b[j]
                    if p & j1:
                        continue
                    pj1 = p | j1
                    dp[pj1] += dp[p]
                    if i1 == n: continue
                    q[t1].append(pj1)

    print(dp[-1] % mod)


    return


#main
if __name__ == '__main__':
    solve()


### FIXED CODE ###

#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10

#solve
def solve():
    n = II()
    a = LIR(n)
    n1 = 1 << n
    dp = [0] * n1
    dp[0] = 1
    b = [0]
    for i in range(n):
        b += [x + 1 for x in b]
    # print(b)
    c = [1 << i for i in range(n)]
    for i in range(n1-1):
        p = b[i]
        ap = a[p]
        for j in range(n):
            if ap[j]:
                j1 = c[j]
                if i & j1:
                    continue
                dp[i|j1] += dp[i]


    print(dp[-1] % mod)


    return


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

N = int(input())
l = list(map(int, input().split()))
d = 0
for i in range(N-1):
  if l[i] - l[i+1] >= 2:
    d = 1

for i in range(N-1):
  if l[i] - l[i+1] == 1:
    for j in range(i+1, N-1):
      if l[j] - l[j+1] == 1:
        d = 1

if d == 0:
  print("Yes")
else:
  print("No")

### FIXED CODE ###

N = int(input())
l = list(map(int, input().split()))
d = 0

for i in range(N-1):
  if l[i] - l[i+1] >= 2:
    d = 1

for i in range(N-2):
  if l[i] - l[i+1] == 1:
    for j in range(i+1, N-1):
      if l[j] - l[j+1] <= -1:
        break
      if l[j] - l[j+1] == 0:
        continue
      if l[j] - l[j+1] == 1:
        d = 1
        break

if d == 0:
  print("Yes")
else:
  print("No")
### BUGGY CODE ###

import sys
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits


def input(): return sys.stdin.readline().strip()


def INT(): return int(input())


def MAP(): return map(int, input().split())


def LIST(): return list(map(int, input().split()))


sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

n, k = MAP()

h = LIST()

dp = [INF] * n
dp[0] = 0

for i in range(n):
    for j in range(1, k+1):
        if (i < n - j):
            dp[i + j] = min(dp[i + j], dp[i] + abs(h[i + j] - h[i]))


print(dp[-1])


### FIXED CODE ###

import sys
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits


def input(): return sys.stdin.readline().strip()


def INT(): return int(input())


def MAP(): return map(int, input().split())


def LIST(): return list(map(int, input().split()))


sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

n, k = MAP()

h = LIST()

dp = [INF] * n
dp[0] = 0

for i, hi in enumerate(h):
    if i == 0:
        continue
    s = i-k if i-k >= 0 else 0
    dp[i] = min([dpk + abs(hi-hk) for dpk, hk in zip(dp[s:i], h[s:i])])

print(dp[-1])
### BUGGY CODE ###


n, w = map(int, input().split())

#wvn = [ list( map(int,input().split()) ) for _ in range(n) ]

wvn = [ tuple( map(int,input().split())) for _ in range(n) ]

#print(wvn)

VMAX = 10**3 * (10**2)
# 1 <= vi <= 10**3
tab = [ [10**10] *(VMAX+1) for _ in range(n+1)]

#print(type(tab[0]))

for i in range(1, len(wvn)+1 ):
    
    wv = wvn[i-1]
    wi = wv[0]
    vi = wv[1]
    
    for j in range( VMAX + 1 ):

        t = tab[i-1][j]
        
        if j >= vi:
            t = min(t, tab[i-1][j-vi]+wi)

        else:
            t = min(t, wi)
        
        tab[i][j] = t

ans = 0
while tab[n][ans] <= w:
    #print( (tab[n][ans],ans) )
    ans += 1

#print("ANS")
print(ans)



def debug0():
    row1 = tab[1]
    
    print("DEBUG0--START")
    print([(i, row1[i]) for i in range(0,50,5)])
    print("DEBUG0--END")
#debug0()


def debug1():

    for i in range(n+1):
        t = tab[i][0]
        sss = set(tab[i])
        print(sss)
        for j in range( 1, len(tab[i]) ):
            v = tab[i][j]

            if not t == v:
                t = v
                print( (i,j,v) )
 #end


def debug3():
    t = -1

    for i in range( len(tab[n])-1 ):
        e = tab[n][i]

        if not t == e:
            t = e
            print( (i, e) )
            
#debug3()





def debug2():
    t = -1
    for vi in range(len(tab[0])):

        v = tab[n][vi]
        if not t == v:
            t = v
            print((t,vi))


### FIXED CODE ###


n, w = map(int, input().split())

#wvn = [ list( map(int,input().split()) ) for _ in range(n) ]

wvn = [ tuple( map(int,input().split())) for _ in range(n) ]

#print(wvn)

VMAX = 10**3 * (10**2)
# 1 <= vi <= 10**3
tab = [ [10**10] *(VMAX+1) for _ in range(n+1)]

#print(type(tab[0]))

for i in range(1, len(wvn)+1 ):
    
    wv = wvn[i-1]
    wi = wv[0]
    vi = wv[1]
    
    for j in range( VMAX + 1 ):

        t = tab[i-1][j]
        
        if j >= vi:
            t = min(t, tab[i-1][j-vi]+wi)

        else:
            t = min(t, wi)
        
        tab[i][j] = t

ans = 0
while tab[n][ans] <= w:
    #print( (tab[n][ans],ans) )
    ans += 1

#print("ANS")
print(ans)



def debug0():
    row1 = tab[1]
    
    print("DEBUG0--START")
    print([(i, row1[i]) for i in range(0,50,5)])
    print("DEBUG0--END")
#debug0()


def debug1():

    for i in range(n+1):
        t = tab[i][0]
        sss = set(tab[i])
        print(sss)
        for j in range( 1, len(tab[i]) ):
            v = tab[i][j]

            if not t == v:
                t = v
                print( (i,j,v) )
 #end


def debug3():
    t = -1

    for i in range( len(tab[n])-1 ):
        e = tab[n][i]

        if not t == e:
            t = e
            print( (i, e) )
            
#debug3()





def debug2():
    t = -1
    for vi in range(len(tab[0])):

        v = tab[n][vi]
        if not t == v:
            t = v
            print((t,vi))
### BUGGY CODE ###

import  heapq

n,m,s,t=map(int,raw_input().split())

nl=[ [ ] for j in range(n+1) ] 

for i in range(m):
	u,v,a,b=map(int,raw_input().split())
	nl[u].append( (v,a,b) )
	nl[v].append( (u,a,b) )


def dij(v,type):
	d=[ float("inf") for i  in range(n+1)]
	d[v]=0

	Q=[]
	heapq.heappush(Q,v)

	while Q:
		u=heapq.heappop(Q)
		for i in nl[u]:
			v=i[0]
			yen=i[1]
			sunuku=i[2]
			if type=="y":alt=d[u]+yen
			elif type=="s":alt=d[u]+sunuku

			if d[v]> alt:
				d[v]=alt
				heapq.heappush(Q,v)
	return d

d_y=dij(s,"y")
d_s=dij(t,"s")

val=float("inf")

A=[]
for i in range(n,0,-1):
	tmp=d_y[i]+d_s[i]
	val=min(val, tmp)
	A.append(val)

for i in reversed(A):
	print 10**15-i

### FIXED CODE ###

import heapq
 
N,M,S,T = map(int,input().split())
S,T = S-1,T-1
src = [tuple(map(int,input().split())) for i in range(M)]
 
es = [[] for i in range(N)]
for u,v,a,b in src:
    u,v = u-1,v-1
    es[u].append((v,a,b))
    es[v].append((u,a,b))
 
INF = float('inf')
cy = [INF] * N
cy[S] = 0
hq = [(0,S)]
heapq.heapify(hq)
while hq:
    cost,v = heapq.heappop(hq)
    for to,a,b in es[v]:
        if cost + a >= cy[to]: continue
        cy[to] = cost + a
        heapq.heappush(hq, (cy[to],to))
 
cs = [INF] * N
cs[T] = 0
hq = [(0,T)]
heapq.heapify(hq)
while hq:
    cost,v = heapq.heappop(hq)
    for to,a,b in es[v]:
        if cost + b >= cs[to]: continue
        cs[to] = cost + b
        heapq.heappush(hq, (cs[to],to))
 
ans = [INF]
for i in reversed(range(N)):
    tmp = cs[i] + cy[i]
    ans.append(min(ans[-1],tmp))
 
for a in reversed(ans[1:]):
    print(10**15 - a)
### BUGGY CODE ###

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

score_i = 1
for a_i in A[:K]:
    score_i *= a_i

for i in range(K, N):
    new_score_i = A[i] * score_i // A[i - K]
    if score_i < new_score_i:
        print('Yes')
    else:
        print('No')
    score_i = new_score_i


### FIXED CODE ###

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

for i in range(K, N):
    if A[i - K] < A[i]:
        print('Yes')
    else:
        print('No')
### BUGGY CODE ###

S = input()

cs = {0: 1}

result = 0

n = 0
for i in range(len(S)):
    c = S[-i-1]
    n += int(c) * (10**i)
    m = n % 2019
    if m in cs:
        result += cs[m]
        cs[m] += 1
    else:
        cs[m] = 1

print(result)

### FIXED CODE ###

S = input()

cs = {0: 1}

result = 0

n = 0
for i in range(len(S)):
    c = int(S[-i-1])
    n += c * pow(10, i, 2019)
    m = n % 2019
    if m in cs:
        result += cs[m]
        cs[m] += 1
    else:
        cs[m] = 1

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

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

res = 0
a = []
for i in p:
    a.append(i)
    if i == min(a):
        res += 1

print(res)

### FIXED CODE ###

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

res = 0
aa = p[0]
for i in p:
     if aa >= i:
         res += 1
         aa = i

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

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

cs = {}
for p, y in PY:
	if not p in cs:
		cs[p] = [y]
	else:
		cs[p] += [y]

for v in cs.values():
	v.sort()

for p, y in PY:
	print("{:06d}{:06d}".format(p, cs[p].index(y) + 1))


### FIXED CODE ###

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

cs = {}
for p, y in PY:
	if not p in cs:
		cs[p] = [y]
	else:
		cs[p] += [y]

csm = {}
for k, v in cs.items():
	v.sort()
	csm[k] = {}
	for i, p in enumerate(v):
		csm[k][p] = i + 1

for p, y in PY:
	print("{:06d}{:06d}".format(p, csm[p][y]))
### BUGGY CODE ###

q=int(input())
pn=[2]
qn=[0]*10**5
c=0
for i in range(1, 10**5+1):
    for i2 in pn:
        if i % i2 == 0:
            qn[i]=c
            break
        else:
            pn.append(i)
            qn[i]=c        
            if (i+1)/2 in pn:
                c+=1
                qn[i]=c

for _ in range(q):
    l,r = map(int, input().split())
    print(qn[r]-qn[l-1])

### FIXED CODE ###

q = int(input())
k = 10**5+1
x = [0]*k
def sieve(n):
    prime = [True] * (n+1)
    prime[0] = prime[1] = False
    for i in range(2, n+1):
        if prime[i]:
            for j in range(i*2, n+1, i):
                prime[j] = False
    return prime

p = sieve(k+1)
c = 0
for i in range(3, k):
    if p[i] and p[(i+1)//2]:
        c += 1
    x[i] = c

for _ in range(q):
    l, r = map(int, input().split())
    print(x[r] - x[l-1])
### BUGGY CODE ###

N=int(input())
S=["" for i in range(N)]

for i in range(N):
    S[i]=input()

count=0

for l in range(N):
    JUDGE=1
    for j in range(N):
        for k in range(j+1,N):
            
            if S[j][k-l]!=S[k][j-l]:
                JUDGE=0
                break
        if JUDGE==0:
            break

    if JUDGE==1:
        count+=1

print(count*N)

### FIXED CODE ###

N=int(input())
S=["" for i in range(N)]

for i in range(N):
    S[i]=input()

count=0

for l in range(N):
    JUDGE=1
    for j in range(N):
        for k in range(j+1,N):
            
            if S[j][k-l]!=S[k][j-l]:
                JUDGE=0
                break
        if JUDGE==0:
            break

    if JUDGE==1:
        count+=1

print(count*N)
### BUGGY CODE ###

N = int(input())
L = [int(li) for li in input().split(' ')]
cnt = 0

for i in range(N - 2):
    for j in range(i + 1, N - 1):
        # print('check', L[i], L[j])
        kcnt = sum([1 for li in L[j + 1:N] if li < L[i] + L[j] and L[i] < li + L[j] and L[j] < li + L[i]])
        # print('ok', [li for li in L[j + 1:N] if li < L[i] + L[j]])
        cnt += kcnt

print(cnt)


### FIXED CODE ###

import bisect

N = int(input())
L = [int(li) for li in input().split(' ')]
LMAX = 10 ** 3

L.sort()
# print(L)
ans = 0

for i in range(N - 2):
    for j in range(i + 1, N - 1):
        # 1,2番目の棒を長い順に決める
        # 3番目の棒として満たす
        lin = L[i] + L[j]

        ind = bisect.bisect_left(L, lin)
        ans += ind-j-1
print(ans)
### BUGGY CODE ###

from functools import reduce

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

cum = [0] * (n - k + 1)
for i in range(n - k + 1):
    cum[i] = reduce(lambda x, y: x * y, a[i:i + k])

for i in range(1, len(cum)):
    if cum[i] > cum[i - 1]:
        print('Yes')
    else:
        print('No')


### FIXED CODE ###

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

for i in range(k, n):
    if a[i - k] / a[i] < 1:
        print('Yes')
    else:
        print('No')
### BUGGY CODE ###

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

c = 1
for i in range(K):
    c *= A[i]

C = c
for i in range(0, N - K):
    c //= A[i]
    c *= A[K + i]

    if c > C:
        print("Yes")
    else:
        print("No")
    C = c


### FIXED CODE ###

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

for i in range(N - K):
    if A[K + i] > A[i]:
        print("Yes")
    else:
        print("No")
### BUGGY CODE ###

s = list(input())
k = int(input())
a = []

for i in range(1, len(s) + 1):
    for j in range(len(s) - i + 1):
        word = s[j:j+i]
        if word not in a:
            a.append(word)


a.sort()

print(''.join(a[k-1]))


### FIXED CODE ###

s = list(input())
k = int(input())
a = []

for i in range(1, len(s) + 1):
    if i >= k+1:
        break
    for j in range(len(s) - i + 1):
        word = s[j:j+i]
        if word not in a:
            a.append(word)


a.sort()

print(''.join(a[k-1]))