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

import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    sys.setrecursionlimit(10**7)
    INF = float('inf')
    MOD = 10**9 + 7
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]
    _LI = lambda : [int(x)-1 for x in sys.stdin.readline().split()]
    NI = lambda : int(sys.stdin.readline())
    SI = lambda : sys.stdin.readline().rstrip()
    DD = ((1,0),(0,1),(-1,0),(0,-1))

    H,W,K = LI()
    x1,y1,x2,y2 = _LI()

    p = [SI() for _ in range(H)]

    d = [[INF] * W for _ in range(H)]
    for i in range(4):
        d[x1][y1] = 0

    q = collections.deque()
    q.append((x1,y1))
    while q:
        x,y = q.pop()
        for dx,dy in DD:
            for n in range(1,K+1):
                nx = x + dx * n
                ny = y + dy * n
                if not(0<=nx<H and 0<=ny<W): break
                if p[nx][ny] == '@': break
                if d[nx][ny] <= d[x][y] + 1: continue
                d[nx][ny] = d[x][y] + 1
                q.append((nx,ny))
    if d[x2][y2] < float('inf'):
        print(d[x2][y2])
    else:
        print(-1)



if __name__ == '__main__':
    main()

### FIXED CODE ###

import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    sys.setrecursionlimit(10**7)
    INF = float('inf')
    MOD = 10**9 + 7
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]
    _LI = lambda : [int(x)-1 for x in sys.stdin.readline().split()]
    NI = lambda : int(sys.stdin.readline())
    SI = lambda : sys.stdin.readline().rstrip()
    DD = ((1,0),(0,1),(-1,0),(0,-1))

    H,W,K = LI()
    x1,y1,x2,y2 = _LI()

    p = [SI() for _ in range(H)]

    d = [[INF] * W for _ in range(H)]
    d[x1][y1] = 0

    q = []
    q.append((0,x1,y1))
    while q:
        n,x,y =  heapq.heappop(q)
        if d[x][y] < n: continue
        for dx,dy in DD:
            for n in range(1,K+1):
                nx = x + dx * n
                ny = y + dy * n
                if not(0<=nx<H and 0<=ny<W): break
                if p[nx][ny] == '@': break
                if d[nx][ny] < d[x][y] + 1: break
                if d[nx][ny] == d[x][y] + 1: continue
                d[nx][ny] = d[x][y] + 1
                q.append((d[nx][ny],nx,ny))
    if d[x2][y2] < INF:
        print(d[x2][y2])
    else:
        print(-1)



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

from sys import stdin

N = int(stdin.readline())
A = list(map(int,stdin.readline().split()))
A.sort()
Q = int(stdin.readline())
D = dict()
S = set(A)
sum=0
count=0

for y in range(0,N):
    sum+=A[y]
    if y>0 and A[y]!=A[y-1]:
        D[A[y-1]]=count
        count=1
    elif y==0:
        count=1
    else:
        count+=1
    if y==N-1:
        D[A[y]]=count

for u in range(0,Q):
    U= list(map(int,stdin.readline().split()))
    SS=S.copy()
    SS.add(U[0])
    if len(SS)==len(S):

        SS.add(U[1])
        if len(SS)==len(S):
            sum+=(D[U[0]])*(U[1]-U[0])

            D[U[1]]+=D[U[0]]
            D[U[0]]=0
        else:
            sum += (D[U[0]]) * (U[1] - U[0])
            D[U[1]]=D[U[0]]
            D[U[0]]=0
        S=SS

    print(sum)

### FIXED CODE ###

from sys import stdin

N = int(stdin.readline())
A = list(map(int,stdin.readline().split()))
A.sort()
Q = int(stdin.readline())
D = dict()
S = set(A)
sum=0
count=0

for y in range(0,N):
    sum+=A[y]
    if y>0 and A[y]!=A[y-1]:
        D[A[y-1]]=count
        count=1
    elif y==0:
        count=1
    else:
        count+=1
    if y==N-1:
        D[A[y]]=count

for u in range(0,Q):
    U= list(map(int,stdin.readline().split()))
    if U[0] in D:
        sum+=(D[U[0]])*(U[1]-U[0])
        if U[1] in D:
            D[U[1]]+=D[U[0]]
        else:
            D[U[1]]=D[U[0]]
        D[U[0]]=0


    print(sum)
### BUGGY CODE ###

from fractions import gcd

def trial_division(n):
    f = 2
    d = {}
    while n > 1:
        if n % f == 0:
            d[f] = d.get(f,0) + 1
            n//=f
        else:
            f += 1
    return d

g = gcd(*map(int, input().split()))
ans = trial_division(g)
print(len(ans)+1)

### FIXED CODE ###

from fractions import gcd
g = gcd(*map(int, input().split()))

f = 2
d = {}
while f**2 <= g:
    if g % f:
        f += 1
    else:
        d[f] = d.get(f,0) + 1
        g//=f

if g>1:
    d[g] =d.get(g,0) + 1

print(len(d)+1)
### BUGGY CODE ###

import itertools
x,y,z,k = list(map(int, input().split())) 
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)
del a[min(k,x):]
del b[min(k,y):]
del c[min(k,z):]

ab = [i + j for (i, j) in list(itertools.product(a, b))]

ab.sort(reverse=True)
del ab[min(k,x*y):]

abc = [ij + h for (ij, h) in list(itertools.product(ab, c))]

abc.sort(reverse=True)

for g in range(k):
  print(abc[g])

### FIXED CODE ###

import heapq
x,y,z,k = list(map(int, input().split())) 
a = sorted(list(map(int, input().split())),reverse=True)
b = sorted(list(map(int, input().split())),reverse=True)
c = sorted(list(map(int, input().split())),reverse=True)

ans = []
log = set()

total = (a[0] + b[0] + c[0]) * (-1)
heapq.heappush(ans, (total, 0, 0, 0))
log.add((0, 0, 0))

for i in range(k):
  (total, aa, bb, cc) = heapq.heappop(ans)
  print(total * (-1))
  if (aa+1, bb, cc) not in log:
    if aa+1 < x:
      total = (a[aa+1] + b[bb] + c[cc]) * (-1)
      heapq.heappush(ans, (total, aa+1, bb, cc))
      log.add((aa+1, bb, cc))
  if (aa, bb+1, cc) not in log:
    if bb+1 < y:
      total = (a[aa] + b[bb+1] + c[cc]) * (-1)
      heapq.heappush(ans, (total, aa, bb+1, cc))
      log.add((aa, bb+1, cc))
  if (aa, bb, cc+1) not in log:
    if cc+1 < z:
      total = (a[aa] + b[bb] + c[cc+1]) * (-1)
      heapq.heappush(ans, (total, aa, bb, cc+1))
      log.add((aa, bb, cc+1))
### BUGGY CODE ###

n, m = map(int,input().split())
s = list(map(int, input().split()))
for i in range(m):
    idx = s.index(max(s))
    s[idx] = max(s)//2
print(sum(s))

### FIXED CODE ###

import heapq

n, m = map(int,input().split())
s = list(map(int, input().split()))
s = list(map(lambda x: x * (-1), s))
heapq.heapify(s)

for i in range(m):
    mx = heapq.heappop(s) * (-1)
    mx = mx//2
    heapq.heappush(s, mx*(-1))
    
print(sum(s)*(-1))
### BUGGY CODE ###

n, m = map(int, input().split())
alist = list(map(int, input().split()))

ca = {0: 0}
for i, a in enumerate(alist):
    ca[i+1] = sum(alist[0:i+1]) % m

c = 0
for i in range(1, n+1):
    for j in range(i, n+1):
        s = ca[j] - ca[i-1]
        if s % m == 0:
            c += 1
print(c)


### FIXED CODE ###

from collections import defaultdict

n, m = map(int, input().split())
alist = list(map(int, input().split()))

c = 0
cnt = defaultdict(int)
cnt[0] = 1
s = 0
for i in range(n):
    s += alist[i]
    c += cnt[s%m]
    cnt[s%m] += 1

print(c)
### BUGGY CODE ###

n = int(input())
a = [(int(x), int(y)) for x, y in zip(input().split(), range(n))]
a.sort(reverse=True)

dp = [[0]*(n+1) for i in range(n+1)]
for i in range(n+1):
  for j in range(n+1-i):
    if i == 0 and j == 0:
      continue
    if i == 0:
      dp[i][j] = dp[i][j-1]+a[i+j-1][0]*abs(a[i+j-1][1]-j+1)
      continue
    if j == 0:
      dp[i][j] = dp[i-1][j]+a[i+j-1][0]*(n-i-a[i+j-1][1])
      continue
    dp[i][j] = max([dp[i][j-1]+a[i+j-1][0]*abs(a[i+j-1][1]-j+1), dp[i-1][j]+a[i+j-1][0]*(n-i-a[i+j-1][1])])

ans = 0
for i in range(n+1):
  key = dp[n-i][i]
  if ans < key:
    ans = key

print(ans)

### FIXED CODE ###

n = int(input())
a = [(int(x), int(y)) for x, y in zip(input().split(), range(n))]
a.sort(reverse=True)

dp = [[0]*(n+1) for i in range(n+1)]
for i in range(n+1):
  for j in range(n+1-i):
    if i == 0 and j == 0:
      continue
    if i == 0:
      dp[i][j] = dp[i][j-1]+a[i+j-1][0]*abs(a[i+j-1][1]-j+1)
      continue
    if j == 0:
      dp[i][j] = dp[i-1][j]+a[i+j-1][0]*(n-i-a[i+j-1][1])
      continue
    dp[i][j] = max([dp[i][j-1]+a[i+j-1][0]*abs(a[i+j-1][1]-j+1), dp[i-1][j]+a[i+j-1][0]*(n-i-a[i+j-1][1])])

ans = 0
for i in range(n+1):
  key = dp[n-i][i]
  if ans < key:
    ans = key

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

import itertools

s = list(str(input()))
t = list(str(input()))

for i in itertools.permutations(s):
    for j in itertools.permutations(t):
        if "".join(i) < "".join(j):
            print("Yes")
            quit(0)
        else:
            continue

print("No")

### FIXED CODE ###

s = "".join(sorted(input()))
t = "".join(sorted((input()))[::-1])
if s < t:
    print("Yes")
else:
    print("No")
### BUGGY CODE ###

n = int(input())

if n % 2 == 1 or n==0:
  print(0)
else:
  total = 1
  cnt = 0
  for i in range(n, 0, -2):
    if str(i)[-1] == '0':
      cnt += 1
      e = i // 10
      total *= e
    else:
      total *= i
    if str(total)[-1] == '0':
      cnt += 1
      total = total // 10    
  print(cnt)

### FIXED CODE ###

n = int(input())

if n % 2 == 1 or n==0:
  print(0)
else:
  total = 0
  div = 5
  while True:
    total += n // (div * 2)
    div *= 5
    if div > n:
      break
  print(total)
### BUGGY CODE ###

import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


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

from collections import Counter, defaultdict
c = Counter(a)
n1, n2, n3 = c[1], c[2], c[3]
n0 = c[0]
def glist(*l, fill=None):
    if len(l)==1:
        return [fill]*l[0]
    ll = l[1:]
    return [glist(*ll) for _ in range(l[0])]

count = 0
S = sum(a)
sub = glist(n1+n2+n3+1,n2+n3+1,n3+1)
sub[0][0][0] = 0
#     for i1 in range(min(n+1, s+1)):
#         for i2 in range(min(n+1, (s-i1)//2+1)):
for i3 in range(n3+1):
    for i2 in range(n2+n3+1-i3):
        for i1 in range(n1+n2+n3 - (i2+i3) + 1):
            if i1==i2==i3==0 or i1+i2+i3>n:
                continue
#             print(i1,i2,i3)
            ans = n
            p = 0
            if i1>0:
                ans += i1 * sub[i1-1][i2][i3]
                p += i1
            if i2>0:
                ans += i2 * sub[i1+1][i2-1][i3]
                p += i2
            if i3>0:
                ans += i3 * sub[i1][i2+1][i3-1]
                p += i3
            ans = ans/p
            sub[i1][i2][i3] = ans
print(sub[n1][n2][n3])

### FIXED CODE ###

import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


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

from collections import Counter, defaultdict
c = Counter(a)
n1, n2, n3 = c[1], c[2], c[3]
n0 = c[0]
def glist(*l, fill=None):
    if len(l)==1:
        return [fill]*l[0]
    ll = l[1:]
    return [glist(*ll) for _ in range(l[0])]

count = 0
S = sum(a)
sub = glist(n1+n2+n3+1,n2+n3+1,n3+1)
sub[0][0][0] = 0
#     for i1 in range(min(n+1, s+1)):
#         for i2 in range(min(n+1, (s-i1)//2+1)):
for i3 in range(n3+1):
    for i2 in range(n2+n3+1-i3):
        for i1 in range(n1+n2+n3 - (i2+i3) + 1):
            if i1==i2==i3==0 or i1+i2+i3>n:
                continue
#             print(i1,i2,i3)
            ans = n
            p = 0
            if i1>0:
                ans += i1 * sub[i1-1][i2][i3]
                p += i1
            if i2>0:
                ans += i2 * sub[i1+1][i2-1][i3]
                p += i2
            if i3>0:
                ans += i3 * sub[i1][i2+1][i3-1]
                p += i3
            ans = ans/p
            sub[i1][i2][i3] = ans
print(sub[n1][n2][n3])
### BUGGY CODE ###

import math
from collections import Counter

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def main():
    n = int(input())
    array_s = []
    array = []
    for i in range(n):
        array_s.append(input())

    for s in array_s:
        array.append(Counter(s))

    ans = 0
    for i in range(n):
        if array:
            alphabet = array[:][0]
            num = array.count(alphabet)-1
            if num <= 0:
                pass
            elif num <= 1:
                ans += 1
            else:
                ans += combinations_count(num+1, 2)
            for j in range(num+1):
                array.remove(alphabet)
        else:
            break
    print(ans)


if __name__ == '__main__':
    main()


### FIXED CODE ###

def main():
    n = int(input())
    array_s = []
    array = []
    for i in range(n):
        array_s.append(input())

    for s in array_s:
        array.append(''.join(sorted(s)))
    array = sorted(array)
    ans = 0
    count = 1
    for i in range(n-1):
        if array[i] == array[i+1]:
            count += 1
            if i != n-2:
                continue
        ans += int(count*(count-1)/2)
        count = 1
    print(ans)


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

from collections import deque
import sys
input = sys.stdin.readline

N, M = map(int, input().split())
adj = [[] for _ in range(N + 1)]
for _ in range(M):
    L, R, D = map(int, input().split())
    adj[L].append((R, D))
    adj[R].append((L, -D))
seen = [0] * (N + 1)


def dfs(adj, seen, start):
    inf = 10 ** 10
    que = deque()
    que.append(start)
    x = [inf] * (N + 1)
    x[start] = 0
    while que:
        v = que.pop()
        seen[v] = 1
        for u, d in adj[v]:
            if seen[u] == 0:
                que.append(u)
                if x[u] == inf:
                    x[u] = x[v] + d
                else:
                    if x[u] != x[v] + d:
                        print('No')
                        sys.exit()
    return seen


for i in range(1, N + 1):
    if seen[i] == 0:
        seen = dfs(adj, seen, i)

print('Yes')



### FIXED CODE ###

from collections import deque
import sys
import time
input = sys.stdin.readline


def main():
    t1 = time.time()
    N, M = map(int, input().split())
    adj = [[] for _ in range(N + 1)]
    for _ in range(M):
        L, R, D = map(int, input().split())
        adj[L].append((R, D))
        adj[R].append((L, -D))
    seen = [0] * (N + 1)

    def dfs(adj, seen, start):
        inf = 10 ** 10
        que = deque()
        que.append(start)
        x = [inf] * (N + 1)
        x[start] = 0
        while que:
            v = que.pop()
            seen[v] = 1
            for u, d in adj[v]:
                if seen[u] == 0:
                    que.append(u)
                    if x[u] == inf:
                        x[u] = x[v] + d
                    else:
                        if x[u] != x[v] + d:
                            print('No')
                            sys.exit()
            t2 = time.time()
            if t2 - t1 > 1.8:
                print('Yes')
                sys.exit()
        return seen

    for i in range(1, N + 1):
        if seen[i] == 0:
            seen = dfs(adj, seen, i)

    print('Yes')


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

def main():
    K = int(input())
    if K%2 == 0:
        return -1
    ans = 1
    amari_reserve = 7%K
    amari = amari_reserve
    if amari_reserve == 0:
        return ans

    while True:
        ans += 1
        amari = (10*amari+7) % K
        if amari == 0:
            return ans
        if amari == amari_reserve:
            return -1


print(main())


### FIXED CODE ###

def main():
    K = int(input())
    if K%2 == 0:
        return -1
    ans = 1
    amari_reserve = 7%K
    amari = amari_reserve
    if amari_reserve == 0:
        return ans

    while (ans <= K):
        ans += 1
        amari = (10*amari+7) % K
        if amari == 0:
            return ans
        if amari == amari_reserve:
            return -1

    return -1


print(main())
### BUGGY CODE ###

N = int(input())
a = list(map(int,input().split()))
amin = min(a)
amax = max(a)
suma = []
for i in range(amin,amax+1):
    sumb = a.count(i) + a.count(i-1) + a.count(i+1)
    suma.append(sumb)
print(max(suma))

### FIXED CODE ###

import bisect
N = int(input())
a = sorted(list(map(int,input().split())))
amin = a[0]
amax = a[-1]
suma = []
for i in range(amin,amax+1):
    sumb = bisect.bisect_right(a,i+1) - bisect.bisect_left(a,i-1)
    suma.append(sumb)
print(max(suma))
### BUGGY CODE ###

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

ans = 10**6
for i in range(M):
    X, Y, C = map(int, input().split())
    if(ans > a[X-1]+b[Y-1]-C):
        ans = a[X-1]+b[Y-1]-C

for j in range(len(a)):
    for k in range(len(b)):
        if(a[j]+b[k] < ans):
            ans = a[j]+b[k]
print(ans)

### FIXED CODE ###

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

ans = min(a)+min(b)
for i in range(M):
    X, Y, C = map(int, input().split())
    if(ans > a[X-1]+b[Y-1]-C):
        ans = a[X-1]+b[Y-1]-C

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

n = int(input())
a = list(input().split())
ans = []

for i in range(1, n+1):
    ans.append(a.index(str(i))+1)

print(*ans)

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
ans = [0]*n

for i in range(n):
    ans[a[i]-1] = i+1

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

from collections import deque

H, W = map(int, input().split())
s = [list(input()) for _ in range(H)]

start_black = [[False]*W for _ in range(H)]
bl = []
for row in range(H):
    for col in range(W):
        if s[row][col] == "#":
            start_black[row][col] = True
            bl.append([row, col])

ans = 0
for b in bl:
    if start_black[b[0]][b[1]]:
        d = deque([[b[0], b[1]]])
        passed_black = 1
        passed_white = 0
        visited = [[False]*W for _ in range(H)]
        visited[b[0]][b[1]] = True
        while d:
            b_row, b_col = d.popleft()
            for new_row, new_col in [[b_row+1, b_col], [b_row-1, b_col], [b_row, b_col+1], [b_row, b_col-1]]:
                if 0 <= new_row <= H-1 and 0 <= new_col <= W-1 and s[b_row][b_col] != s[new_row][new_col] and not visited[new_row][new_col]:
                    start_black[new_row][new_col] = False
                    d.append([new_row, new_col])
                    visited[new_row][new_col] = True
                    if s[new_row][new_col] == ".":
                        passed_white += 1
                    else:
                        passed_black += 1
        ans += passed_black * passed_white

print(ans)

### FIXED CODE ###

from collections import deque

H, W = map(int, input().split())
s = [list(input()) for _ in range(H)]

visited = [[False]*W for _ in range(H)]
ans = 0

for row in range(H):
    for col in range(W):
        if not visited[row][col]:
            visited[row][col] = True
            d = deque([[row, col]])
            if s[row][col] == ".":
                passed_black, passed_white = 0, 1
            else:
                passed_black, passed_white = 1, 0

            while d:
                now_row, now_col = d.popleft()
                visited[now_row][now_col] = True
                for new_row, new_col in [[now_row+1, now_col], [now_row-1, now_col], [now_row, now_col+1], [now_row, now_col-1]]:
                    if 0 <= new_row <= H-1 and 0 <= new_col <= W-1 and s[now_row][now_col] != s[new_row][new_col] and not visited[new_row][new_col]:
                        d.append([new_row, new_col])
                        visited[new_row][new_col] = True
                        if s[new_row][new_col] == ".":
                            passed_white += 1
                        else:
                            passed_black += 1

            ans += passed_black * passed_white

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

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

d = {}
for i in range(1, 1001):
    d[i] = (i + 1) * (i / 2) / i

ans = 0
for i in range(N-K+1):
    total = 0
    for j in range(K):
        total += d[P[i+j]]
    ans = max(ans, total)

print(ans)

### FIXED CODE ###

from itertools import accumulate


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

d = {}
for i in range(1, 1001):
    d[i] = (i + 1) * (i / 2) / i

E = []
for p in P:
    E.append((p+1)/2)

cum = list(accumulate(E))
mx = 0
idx = 0
ans = 0
for i in range(N-K+1):
    if i == 0:
        mx = max(mx, cum[i+K-1])
    else:
        mx = max(mx, cum[i+K-1] - cum[i-1])

print(mx)
### BUGGY CODE ###

import random, math
random.seed()
def gen(a, b, num):
    result = set()
    while 1:
        while 1:
            v = random.randint(a, b)//2*2+1
            if v not in result:
                break
        for x in range(3, int(math.sqrt(v))+1, 2):
            if v % x == 0:
                break
        else:
            result.add(v)
            if len(result) == num:
                break
    return result
class RH():
    def __init__(self, s, base, mod):
        self.base = base
        self.mod = mod
        self.rev = pow(base, mod-2, mod)

        l = len(s)
        self.h = h = [0]*(l+1)
        tmp = 0
        for i in range(l):
            num = ord(s[i])
            tmp = (tmp*base + num) % mod
            h[i+1] = tmp
    def calc(self, l, r):
        return (self.h[r] - self.h[l] * pow(self.base, r-l, self.mod) + self.mod) % self.mod
class RRH():
    def __init__(self, s, num=10, primes=None):
        primes = primes or gen(2, 10**3, num)
        MOD = 10**9+7
        self.rhs = [RH(s, p, MOD) for p in primes]
    def calc(self, l, r):
        return [rh.calc(l, r) for rh in self.rhs]

T = input(); P = input()
primes = gen(2, 10**3, 3)
HT = RRH(T, primes=primes)
HP = RRH(P, primes=primes)

pv = HP.calc(0, len(P))
for i in range(len(T)-len(P)+1):
    if HT.calc(i, i+len(P)) == pv:
        print(i)

### FIXED CODE ###

import sys
readline = sys.stdin.readline
write = sys.stdout.write

class KMP:
    def __init__(self, W):
        L = len(W)
        T = [0] * (L+1)
        T[0] = -1
        c = 0
        for p in range(1, L):
            if W[p] == W[c]:
                T[p] = T[c]
            else:
                T[p] = c
                c = T[c]
                while c >= 0 and W[p] != W[c]:
                    c = T[c]
            c += 1
        T[L] = c
        self.T = T
        self.W = W

    def search(self, S):
        W = self.W; T = self.T
        R = []
        LS = len(S); LW = len(W)
        # S[i], W[j]
        i = j = 0
        while i < LS:
            if S[i] == W[j]:
                i += 1; j += 1
                if j == LW:
                    R.append(i-j)
                    j = T[j]
            else:
                j = T[j]
                if j < 0:
                    i += 1
                    j += 1
        return R

def solve():
    T = readline().strip()
    P = readline().strip()
    kmp = KMP(P)
    res = kmp.search(T)
    for p in res:
        write("%d\n" % p)
solve()
### BUGGY CODE ###

import math
n=int(input())
g=0
for i in range(1,n+1):
    for j in range(1,n+1):
        for h in range(1,n+1):
            d=math.gcd(i,j)
            f=math.gcd(h,d)
            g=g+f
print(g)

### FIXED CODE ###


import math
n=int(input())
g=0

for i in range(1,n+1):
    for j in range(1,n+1):
        d=math.gcd(i,j)
        for h in range(1,n+1):
            f=math.gcd(h,d)
            g=g+f
print(g)
### BUGGY CODE ###

from itertools import combinations, starmap

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

coefficient = 1  # Aの係数
result = 0
while coefficient <= N:
    for r in range(1, N+1):
        multiple_of_a = coefficient * A
        combis_sums = map(sum, combinations(x_list, r))
        for combi_sum in combis_sums:
            if combi_sum == multiple_of_a:
                result += 1
        coefficient += 1

print(result)

### FIXED CODE ###

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

max_of_a = N * A

# dp[i][j][k] := i枚目までからj枚取って、合計をkにする通り数
dp = [[[0] * (max_of_a + 1) for _ in range(N+1)]for _ in range(N+1)]
dp[0][0][0] = 1


for i in range(N+1):
    for j in range(N+1):
        for k in range(max_of_a + 1):
            if i >= 1 and x[i-1] > k:
                dp[i][j][k] = dp[i-1][j][k]
            elif i >= 1 and j >= 1 and x[i-1] <= k:
                dp[i][j][k] = dp[i-1][j][k] + dp[i-1][j-1][k - x[i-1]]

ans = 0
for j in range(1, N+1):
    # N枚(カード総数)の中から1枚以上取った時の、j枚取って合計がj*Aの所 の合計
    ans += dp[N][j][j*A]
print(ans)