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

import collections, itertools
H, W, ch, cw, dh, dw, *S = open(0).read().split()
H, W, ch, cw, dh, dw = [int(_) + 1 for _ in [H, W, ch, cw, dh, dw]]
H += 3
W += 3
S = ['#' * W] + ['#' * W] + ['##' + s + '##'
                             for s in S] + ['#' * W] + ['#' * W]
Dist = [[None] * W for _ in range(H)]
Q = collections.deque([(0, ch, cw)])
while Q:
    d, ox, oy = Q.popleft()
    if Dist[ox][oy] is not None or S[ox][oy] == '#':
        continue
    stack = [[ox, oy]]
    warp = set()
    while stack:
        x, y = stack.pop()
        if (x, y) == (dh, dw):
            print(d)
            exit()
        Dist[x][y] = d
        for dx, dy in [[-1, 0], [1, 0], [0, -1], [0, 1]]:
            nx, ny = x + dx, y + dy
            if Dist[nx][ny] is None:
                if S[nx][ny] == '.':
                    stack += [[nx, ny]]
                else:
                    warp.add((x, y))
    for x, y in warp:
        for dx, dy in itertools.product(range(-2, 3), repeat=2):
            nx, ny = x + dx, y + dy
            if Dist[nx][ny] is None:
                Q += [(d + 1, nx, ny)]
print(-1)


### FIXED CODE ###

import collections, itertools
H, W, ch, cw, dh, dw, *S = open(0).read().split()
H, W, ch, cw, dh, dw = [int(_) + 1 for _ in [H, W, ch, cw, dh, dw]]
H += 3
W += 3
S = ['#' * W] + ['#' * W] + ['##' + s + '##'
                             for s in S] + ['#' * W] + ['#' * W]
Dist = [[None] * W for _ in range(H)]
Q = collections.deque([(0, ch, cw)])
while Q:
    d, ox, oy = Q.popleft()
    if Dist[ox][oy] is not None:
        continue
    stack = [[ox, oy]]
    warp = set()
    while stack:
        x, y = stack.pop()
        if (x, y) == (dh, dw):
            print(d)
            exit()
        Dist[x][y] = d
        for dx, dy in [[-1, 0], [1, 0], [0, -1], [0, 1]]:
            nx, ny = x + dx, y + dy
            if Dist[nx][ny] is None:
                if S[nx][ny] == '.':
                    stack += [[nx, ny]]
                else:
                    warp.add((x, y))
    for x, y in warp:
        for dx, dy in itertools.product(range(-2, 3), repeat=2):
            nx, ny = x + dx, y + dy
            if Dist[nx][ny] is None and S[nx][ny] == '.':
                Q += [(d + 1, nx, ny)]
print(-1)
### BUGGY CODE ###

# -*- coding: utf-8 -*-
# 整数の入力
N, T= map(int, input().split())
t=list(map(int, input().split()))
end_t=T
for j in range (0,N):
  end_t=max(end_t, t[j]+T)
count=0
for s in range (0,end_t):#s秒時点で水で照るかっチェック
  for j in range (0,N):
    if t[j]<=s and s-T< t[j]:
      count+=1
      break
print(count)

### FIXED CODE ###

# -*- coding: utf-8 -*-
# 整数の入力
N, T= map(int, input().split())
t=list(map(int, input().split()))
count=0
for j in range (0,N-1):
  count+=min(T,t[j+1]-t[j])
print(count+T)
### BUGGY CODE ###

def main():
    k = int(input())
    s = input()
    n = len(s)

    def cmb1(n, r, mod):
        if ( r<0 or r>n ):
            return 0
        r = min(r, n-r)
        return g1[n] * g2[r] * g2[n-r] % mod

    mod = 10**9+7 #出力の制限
    N = 2*10**6+5
    g1 = [1, 1] # 元テーブル
    g2 = [1, 1] #逆元テーブル
    inverse = [0, 1] #逆元テーブル計算用テーブル

    for i in range( 2, N + 1 ):
        g1.append( ( g1[-1] * i ) % mod )
        inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
        g2.append( (g2[-1] * inverse[-1]) % mod )

    def power(a, n, mod):
        bi=str(format(n,"b")) #2進数
        res=1
        for i in range(len(bi)):
            res=(res*res) %mod
            if bi[i]=="1":
                res=(res*a) %mod
        return res

    ans = 0
    for i in range(k+1):
        ans += power(25, i, mod)*cmb1(i+n-1, n-1, mod)*power(26, k-i, mod)
    print(ans%mod)

if __name__ == '__main__':
    main()


### FIXED CODE ###

def main():
    k = int(input())
    s = input()
    n = len(s)

    def cmb1(n, r, mod):
        if ( r<0 or r>n ):
            return 0
        r = min(r, n-r)
        return g1[n] * g2[r] * g2[n-r] % mod

    mod = 10**9+7
    N = 2*10**6
    fac = [1]*(N+1)
    finv = [1]*(N+1)
    for i in range(N):
        fac[i+1] = fac[i] * (i+1) % mod
    finv[-1] = pow(fac[-1], mod-2, mod)
    for i in reversed(range(N)):
        finv[i] = finv[i+1] * (i+1) % mod

    def cmb1(n, r, mod):
        if r <0 or r > n:
            return 0
        r = min(r, n-r)
        return fac[n] * finv[r] * finv[n-r] % mod

    def power(a, n, mod):
        bi=str(format(n,"b")) #2進数
        res=1
        for i in range(len(bi)):
            res=(res*res) %mod
            if bi[i]=="1":
                res=(res*a) %mod
        return res

    ans = 0
    for i in range(k+1):
        temp = power(25, i, mod)
        temp *= cmb1(i+n-1, n-1, mod)
        temp %= mod
        temp *= power(26, k-i, mod)
        temp %= mod
        ans += temp
    print(ans%mod)

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

x, k, d = map(int, input().split())
x = abs(x)
if x > k*d:
    print(x-k*d)
else:
    flag = 0
    for i in range(1,k+1):
        p = x-i*d
        c = k-i
        if p <= 0:
            if c%2 != 0:
                print(abs(d+p))
                flag = 1
                break
            elif c%2 == 0:
                print(abs(p))
                flag = 1
                break
        
        if flag == 0:
            i2 = k+1-i
            p2 = x-i2*d
            if p2 > 0:
                if i%2 != 0:
                    print(abs(d-p2))
                    break
                elif i%2 == 0:
                    print(abs(p2))
                    break


### FIXED CODE ###

x, k, d = map(int, input().split())
x = abs(x)
if x > k*d:
    print(x-k*d)
else:
    p = x//d
    c = k-p
    if p == 0 or p==1:
          for i in range(1,k+1):
            p2 = x-i*d
            c = k-i
            if p2 <= 0:
                if c%2 != 0:
                    print(abs(d+p2))
                    break
                elif c%2 == 0:
                    print(abs(p2))
                    break
    elif (c%2 == 0):
        print(abs(x-p*d))
    else:
        print(abs(d-abs(x-p*d)))
### BUGGY CODE ###

def isprime(n):
    p = 3
    while p * p <= n:
        if n % p == 0: return False
        p += 2
    return True

while True:
    try:
        n = int(input())
    except:
        break

    count = int(n >= 2)
    for p in range(3,n + 1,2):
        if isprime(p): count += 1
    print(count)

### FIXED CODE ###

a = [True for i in range(1000000)]
i = 3
while i * i < 1000000:
    for j in range(3 * i, 1000000, 2 * i): a[j] = False
    i += 2

while True:
    try:
        n = int(input())
    except:
        break

    count = int(n >= 2) + sum(a[i] for i in range(3, n + 1, 2))
    print(count)
### BUGGY CODE ###

import queue

H,W=map(int,input().split())
C=[int(i)-1 for i in input().split()]
D=[int(i)-1 for i in input().split()]

c=[]
for i in [0]*H:
    c.append(input())
    
    
dicA=[(-1,0),(1,0),(0,1),(0,-1),(0,0)]
dicB=[]
for i in range(-2,3):
    for j in range(-2,3):
        if i!=0 or j!=0:
            dicB.append((i,j))
    
vis=[[-1]*W for _ in [0]*H]

q=queue.Queue()
q.put((C[1],C[0]))
res=-1
mag=0
pre=[]

while 1:
    while not q.empty():
        x,y=q.get()
        if (x,y) in pre:
                pre.remove((x,y))
        for dx,dy in dicA:
            nx,ny=x+dx,y+dy
            if (nx,ny)==(D[1],D[0]):
                res=vis[ny][nx]
            if 0<=nx<=W-1 and 0<=ny<=H-1:
                if vis[ny][nx]<0 and c[ny][nx]!='#':
                    q.put((nx,ny))
                    vis[ny][nx]=mag
        for dx,dy in dicB:
            nx,ny=x+dx,y+dy
            if 0<=nx<=W-1 and 0<=ny<=H-1:
                if vis[ny][nx]<0 and c[ny][nx]=='.':
                    if not (nx,ny) in pre:
                        pre.append((nx,ny))
    if res>-1:
        break
    if pre:
        mag+=1
        for i in pre:
            q.put(i)
        pre=[]
    else:
        break

                
print(res)

### FIXED CODE ###

from collections import deque

H,W=map(int,input().split())
sy,sx=[int(i)-1 for i in input().split()]
gy,gx=[int(i)-1 for i in input().split()]

c=[]
for i in [0]*H:
    c.append(input())

dic=[]
for i in range(-2,3):
    for j in range(-2,3):
        if i!=0 or j!=0:
            dic.append((i,j))
    
INF=10**9
vis=[[INF]*W for _ in [0]*H]

q=deque()
q.appendleft((sx,sy))
vis[sy][sx]=0
res=-1
while q:
    x,y=q.popleft()
    if (x,y)==(gx,gy):
        res=vis[y][x]
    for dx,dy in dic:
        nx,ny=x+dx,y+dy
        if 0<=nx<=W-1 and 0<=ny<=H-1:
            if vis[ny][nx]>vis[y][x] and c[ny][nx]!='#':
                if dx**2+dy**2<2:
                    vis[ny][nx]=vis[y][x]
                    q.appendleft((nx,ny))
                else:
                    vis[ny][nx]=vis[y][x]+1
                    q.append((nx,ny))
        if res>-1:
            break
    if res>-1:
            break
                
print(res)
### BUGGY CODE ###

[n, k] = [int(x) for x in input().split()]
num_list = [x for x in input().split()]
for i in range(0, k):
    max_count, max_num = 0, ""
    for x in num_list:
        if num_list.count(x) > max_count:
            max_count = num_list.count(x)
            max_num = x
    else:
        num_list = [x for x in num_list if not x == max_num]
print(len(num_list))


### FIXED CODE ###

[n, k] = [int(x) for x in input().split()]
num_list = [int(x) for x in input().split()]
num_dict = {}
for num in num_list:
    num_dict[num] = num_dict.get(num, 0) + 1
sorted_count = sorted(num_dict.values())
if len(sorted_count) - k > 0:
    print(sum(sorted_count[:len(sorted_count)-k]))
else:
    print(0)
### BUGGY CODE ###

import sys

p = []
def main():

    sys.setrecursionlimit(1000000)

    N = int(input())

    e = [ [] for i in range(N)]
    for i in range(N-1):
        a,b = map(int,input().split())
        a-=1
        b-=1
        e[a].append(b)
        e[b].append(a)

    col = [ -1 for i in range(N)]

    col[0] = 0

    
    def dfs(n,c,path):
        global p
        path = path + [n]
        if n == N - 1:
            p = path
        for v in e[n]:
            if col[v] == -1:
                col[v] = c + 1
                dfs(v,c+1,path)
                if p:
                    return
    dfs(0,0,[])

    if len(p) % 2 ==0:
        fn = p[len(p)//2-1]
        sn = p[len(p)//2]
    else:
        fn = p[len(p)//2]
        sn = p[len(p)//2+1]


    colfn = [ -1 for i in range(N)]
    colfn[0] = 0
    def dfs2(n,c):

        for v in e[n]:
            if v == sn:
                continue
            elif colfn[v] == -1:
                colfn[v] = c + 1
                dfs2(v,c+1)

    dfs2(0,0)

    colsn = [ -1 for i in range(N)]
    colsn[N-1] = 0
    def dfs3(n,c):

        for v in e[n]:
            if v == fn:
                continue
            elif colsn[v] == -1:
                colsn[v] = c + 1
                dfs3(v,c+1)

    dfs3(N-1,0)
    fennec = -1
    snuke = -1
    for i in range(N):
        if colsn[i] != -1:
            snuke += 1
        if colfn[i] != -1:
            fennec += 1

    if fennec > snuke:
        print("Fennec")
    else:
        print("Snuke")



if __name__ == '__main__':
    main()



### FIXED CODE ###

import sys

p = []
path = [ 0 for i in range(10**5+1)]
def main():

    sys.setrecursionlimit(1000000)

    N = int(input())

    e = [ [] for i in range(N)]
    for i in range(N-1):
        a,b = map(int,input().split())
        a-=1
        b-=1
        e[a].append(b)
        e[b].append(a)

    col = [ -1 for i in range(N)]
    col[0] = 0
    
    #def dfs(n,c,path):
    def dfs(n,c):
        global p
        #path =  path  + [n]
        #path.append(n)
        #print(path)
        if n == N - 1:
            p = path
        path[c] = n
        for v in e[n]:
            if col[v] == -1:
                col[v] = c + 1
                dfs(v,c+1)
                #dfs(v,c+1,path)
                if p:
                    return
    dfs(0,0)
    #print(p[:N+10])
    #dfs(0,0,[])

    t = col[N-1] + 1
    if t % 2 ==0:
        sn = p[t//2]
    else:
        sn = p[t//2+1]


    colfn = [ -1 for i in range(N)]
    colfn[0] = 0
    def dfs2(n,c):

        for v in e[n]:
            if v == sn:
                continue
            elif colfn[v] == -1:
                colfn[v] = c + 1
                dfs2(v,c+1)

    dfs2(0,0)

    fennec = -1
    for i in range(N):
        if colfn[i] != -1:
            fennec += 1

    snuke = N - fennec - 2
    if fennec > snuke:
        print("Fennec")
    else:
        print("Snuke")



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

import numpy as np
import copy

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

tmp_list = copy.copy(a_list)

ticket_list = np.zeros(n)

for i in range(m):
    max_value = max(tmp_list)
    max_index = tmp_list.index(max_value)
    ticket_list[max_index] += 1
    tmp_list[max_index] = a_list[max_index]//(2**(ticket_list[max_index]))

#print(ticket_list)

ans = 0
for j in range(n):
    ans += a_list[j] // (2**(ticket_list[j]))

print(str(int(ans)))

### FIXED CODE ###

#import numpy as np
import copy
import heapq

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

tmp_list = list(map(lambda x: x*(-1), a_list))
#print(tmp_list)
heapq.heapify(tmp_list)

#ticket_list = np.zeros(n)

for i in range(m):
    max_value = heapq.heappop(tmp_list)*(-1)
    heapq.heappush(tmp_list, (-1)*(max_value//2))

print(-sum(tmp_list))

#ans = 0
#for j in range(n):
#    ans += a_list[j] // (2**(ticket_list[j]))

#print(str(int(ans)))
### BUGGY CODE ###

n = int(input())
S = [str(input()) for _ in range(n)]
count = 0
for i in range(n):
    for j in range(n):
        if i<j:
            ana1 = sorted(list(S[i]))
            ana2 = sorted(list(S[j]))
            if ana1 == ana2:
                count += 1
            
print(count)

### FIXED CODE ###

import collections

# nC2を足す理由は、同一文字列からアナグラムとなっている2つの文字列を見つけないといけないから
N = int(input())
s = ["".join(sorted(input())) for _ in range(N)]
# ソートした時にそれぞれの文字がリストに分割されるからjoinで文字列に直す
c = collections.Counter(s)
ans = 0
for i in set(s):
    n = c[i]
    ans += n * (n - 1) // 2
print(ans)

# set(s)によって、同じ文字列は消去される。そしてcによって、何回その文字が出ているかを数えれる。
### BUGGY CODE ###


def merge(L1, L2):
    P = []
    for x in L1:
        P.append(x)
    for y in L2:
        P.append(y)
    P.sort(reverse=True)
    return [P[0], P[1]]


def main():
    N = int(input())
    a = list(map(int, input().split()))
    dp = [[[0, -10**20] for j in range(N+1)]for i in range(1 << N)]
    for i in range(1 << N):
        dp[i][0][0] = a[i]

    for j in range(1, N+1):
        for i in range(1 << N):
            if (i & (1 << (j-1))):
                dp[i][j] = merge(dp[i & ~(1 << (j-1))][j - 1], dp[i][j-1])
            else:
                dp[i][j] = dp[i][j-1]
    result = [0]*(1 << N)
    for k in range(1, 1 << N):
        result[k] = max(result[k-1], sum(dp[k][N]))
        print(result[k])
    return


if __name__ == "__main__":
    main()



### FIXED CODE ###

def merge(x, y, z, w):
    P = [x, y, z, w]
    P.sort()
    return P[-1], P[-2]


def main():
    N = int(input())
    a = list(map(int, input().split()))
    dp = [0]*(2*(N+1)*((1 << N)))

    def calc(i, j, k):
        return (2*N + 2) * i + (N+1)*k + j
    for i in range(1 << N):
        dp[calc(i, 0, 0)] = a[i]
    for j in range(1, N+1):
        for i in range(1 << N):
            x = calc(i, j, 0)
            y = calc(i & ~(1 << (j-1)), j - 1, 0)          
            if (i & (1 << (j-1))):
                dp[x], dp[x+N+1] = merge(dp[y], dp[y+N+1], dp[x-1], dp[x+N])
            else:
                dp[x], dp[x+N+1] = dp[x-1], dp[x+N]
    result = [0]*(1 << N)
    for k in range(1, 1 << N):
        result[k] = max(result[k-1], dp[calc(k, N, 0)]+dp[calc(k, N, 1)])
        print(result[k])
    return


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

from sys import stdin
def main():
    number = int(input())
    num_list = list(map(int, stdin.readline().split()))
    sum = 0
    for i in range(number):
        temp = num_list[i]
        for j in range(i+1, number):
            sum += temp*num_list[j]
    print(sum % (10**9 + 7))
if __name__ == '__main__':
    main()

### FIXED CODE ###

from sys import stdin
import itertools
def main():
    number = int(input())
    num_list = list(map(int, stdin.readline().split()))
    num_list_sum = sum(num_list)
    total = 0
    for i in range(number):
        num_list_sum -= num_list[i]
        total += num_list[i] * num_list_sum
    print(total % (10**9+7))
if __name__ == '__main__':
    main()
### BUGGY CODE ###

import numpy as np
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

maze = []
for i in range(H):
    maze.append(input())

INF = 10 ** 12

score = np.zeros((H, W), dtype=int)
score[:, :] = INF
score[Ch, Cw] = 0

#visited = np.zeros((H, W), dtype=bool)

candidates = deque()
candidates.append((Ch, Cw))

walk = [(0, 1), (0, -1), (-1, 0), (1, 0)]
warp = [(i, j) for i in range(-2, 3) for j in range(-2, 3) if (i, j) not in [(0, 0)] + walk]

while candidates:
    h, w = candidates.popleft()
    # move
    for dh, dw in walk:
        y = h + dh
        x = w + dw
        if y < 0 or H <= y:
            continue
        if x < 0 or W <= x:
            continue        
        if maze[y][x] == '.' and score[y, x] > score[h, w]:
            score[y, x] = score[h, w]
            candidates.appendleft((y, x))
    # warp
    #if not moved: 
    for dh, dw in warp:
        y = h + dh
        x = w + dw
        if y < 0 or H <= y:
            continue
        if x < 0 or W <= x:
            continue
        if maze[y][x] == '.' and score[y, x] > score[h, w] + 1:
            score[y, x] = score[h, w] + 1
            candidates.append((y, x))

if score[Dh, Dw] == INF:
    print(-1)
else:
    print (score[Dh, Dw])

### FIXED CODE ###

#import numpy as np
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

maze = [input() for _ in range(H)]

INF = 10 ** 12

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

score[Ch][Cw] = 0

candidates = deque()
candidates.append((Ch, Cw))

walk = [(0, 1), (0, -1), (-1, 0), (1, 0)]
warp = [(i, j) for i in range(-2, 3) for j in range(-2, 3) if (i, j) not in [(0, 0)] + walk]

while candidates:
    h, w = candidates.popleft()
    # move
    for dh, dw in walk:
        y = h + dh
        x = w + dw
        s = score[h][w]
        if y < 0 or H <= y:
            continue
        if x < 0 or W <= x:
            continue        
        if maze[y][x] == '.' and score[y][x] > s:
            score[y][x] = s
            candidates.appendleft((y, x))
    # warp
    for dh, dw in warp:
        y = h + dh
        x = w + dw
        s = score[h][w]
        if y < 0 or H <= y:
            continue
        if x < 0 or W <= x:
            continue
        if maze[y][x] == '.' and score[y][x] > s + 1:
            score[y][x] = s + 1
            candidates.append((y, x))

if score[Dh][Dw] == INF:
    print(-1)
else:
    print (score[Dh][Dw])
### BUGGY CODE ###

def bi(l,x,m):
    ok = m
    ng = -1
    while ok-ng > 1:
        mid = (ng+ok)//2
        if l[mid] < x:
            ok = mid
        else:
            ng = mid
    return ok

n = int(input())
a = [int(input()) for _ in range(n)]
t = [-1]
m = 1
for x in a:
    c = bi(t,x,m) 
    if c == m:
        t.append(x)
        m += 1
    else:
        t[c] = x
        t.sort(reverse=True) 
print(m)


### FIXED CODE ###

def bi(l,x):
    ok = len(l)
    ng = -1
    while ok-ng > 1:
        mid = (ng+ok)//2
        if l[mid] < x:
            ok = mid
        else:
            ng = mid
    return ok

n = int(input())
a = [int(input()) for _ in range(n)]
t = [-1]
m = 1
for x in a:
    c = bi(t,x) 
    if c == m:
        t.append(x)
        m += 1
    else:
        t[c] = x
print(m)
### BUGGY CODE ###

import math
k = int(input())
ans = 0

for i in range(1,k+1):
  for j in range(1,k+1):
    for k in range(1,k+1):
      ans += math.gcd(math.gcd(i,j),k)
print(ans)

### FIXED CODE ###

import math
 
K = int(input())
 
S = 0
for i in range(1,K+1):
    for j in range(1,K+1):
        s = math.gcd(i,j)
        for k in range(1,K+1):
            S += math.gcd(s,k)
 
print(S)
### BUGGY CODE ###

n, q = map(int, input().split())
s = input()

csum = [0]
rcsum = [0]
for i in range(n):
    csum.append(s[i:n].count('AC'))
    rcsum.append(s[n-i:n].count('AC'))


# print(csum)
# print(rcsum)

for _ in range(q):
    l, r = map(int, input().split())
    print(csum[l]-csum[r])
    #print('回答：', csum[l], rcsum[n-r])


### FIXED CODE ###

N, Q = map(int, input().split())
S = input()
t = [0]*(N+1)
for i in range(N):
    t[i+1] = t[i] + (1 if S[i-1:i+1] == "AC" else 0)

lr = []
for i in range(Q):
    tmp_lr = list(map(int, input().split()))
    lr.append(tmp_lr)

for l, r in lr:
    print(t[r]-t[l])
### BUGGY CODE ###

n = int(input())
p = list(map(int, input().split()))
cnt = 0
for i in range(n):
  sorted_p = sorted(p[:i+1])
  if sorted_p[0] == p[i]:
    cnt += 1
print(cnt)

### FIXED CODE ###

n = int(input())
p = list(map(int, input().split()))
cnt = 0
p_min = n+1
for i in range(n):
  if p_min > p[i]:
    cnt += 1
    p_min = p[i]
print(cnt)
### BUGGY CODE ###

import math


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


def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, (a % b))


K = int(input())
data = [k+1 for k in range(K)]
result = []
for i, d_i in enumerate(data):
    for j, d_j in enumerate(data[i:]):
        for d_k in data[i+j:]:
            result.append([d_i, d_j, d_k])

s = 0
for r in result:
    r0, r1, r2 = r
    g = gcd(r2, gcd(r0, r1))
    if r0 == r1 == r2:
        s += g
    elif r0 != r1 and r1 != r2:
        s += g * 6
    else:
        s += g * 3

print(s)


### FIXED CODE ###

import itertools
import math


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


def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, (a % b))


K = int(input())
data = [k+1 for k in range(K)]
result = list(itertools.combinations_with_replacement(data, 3))

s = 0

for r in result:
    r0, r1, r2 = r
    g0 = gcd(r0, r1)
    g = gcd(g0, r2)
    if r0 == r1 == r2:
        s += g
    elif r0 != r1 and r1 != r2:
        s += g * 6
    else:
        s += g * 3

print(s)
### BUGGY CODE ###

#!/usr/bin/env python3

import itertools
import numpy


def solve(n, a, xs0):
    xs = numpy.insert(xs0, 0, 0)
    xs.sort()
    y = max(xs.max(), a)
    dp = numpy.zeros((n + 1, n + 1, n * y + 1), numpy.int64)
    g = itertools.product(range(n + 1), range(n + 1), range(n * y + 1))
    for j, k, s in g:
        if j == k == s == 0:
            dp[j, k, s] = 1
        elif j >= 1 and s < xs[j]:
            dp[j, k, s] = dp[j - 1, k, s]
        elif j >= 1 and k >= 1 and s >= xs[j]:
            dp[j, k, s] = dp[j - 1, k, s] + dp[j - 1, k - 1, s - xs[j]]
    ans = sum(dp[n][k][k * a] for k in range(1, n + 1))
    return ans


def main():
    n, a = (int(x) for x in input().split())
    xs = numpy.fromiter((int(x) for x in input().split()), numpy.int64)
    ans = solve(n, a, xs)
    print(ans)


if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env pypy3

import itertools


def solve(n, a, xs0):
    xs = sorted(xs0)
    xs.insert(0, 0)
    y = max(a, *xs)
    dp = [[[0 for _ in range(n * y + 1)]
          for _ in range(n + 1)] for _ in range(n + 1)]
    g = itertools.product(range(n + 1), range(n + 1), range(n * y + 1))
    for j, k, s in g:
        if j == k == s == 0:
            dp[j][k][s] = 1
        elif j >= 1 and s < xs[j]:
            dp[j][k][s] = dp[j - 1][k][s]
        elif j >= 1 and k >= 1 and s >= xs[j]:
            dp[j][k][s] = dp[j - 1][k][s] + dp[j - 1][k - 1][s - xs[j]]
    ans = sum(dp[n][k][k * a] for k in range(1, n + 1))
    return ans


def main():
    n, a = (int(x) for x in input().split())
    xs = [int(x) for x in input().split()]
    ans = solve(n, a, xs)
    print(ans)


if __name__ == '__main__':
    main()