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

import sys
sys.setrecursionlimit(10010010)

def aising19_c():
    h, w = (int(x) for x in input().split())
    grid = [[s for s in str(input())] for _ in range(h)]
    visited = [[False]*w for _ in range(h)]
    ans = 0

    def dfs(x, y):
        nonlocal ans
        visited[x][y] = True
        for dx, dy in ((-1,0),(0,-1),(0,1),(1,0)):
            nx, ny = x+dx, y+dy
            if nx < 0 or h <= nx or ny < 0 or w <= ny: continue
            if grid[nx][ny] == grid[x][y]: continue
            if visited[nx][ny]: continue
            if grid[nx][ny] == '.': ans += 1
            dfs(nx, ny)

    for i in range(h):
        for j in range(w):
            if grid[i][j] == '#':
                dfs(i, j)
                visited = [[False]*w for _ in range(h)]
    print(ans)

if __name__ == '__main__':
    aising19_c()

### FIXED CODE ###

def aising19_c():
    from collections import deque

    h, w = (int(x) for x in input().split())
    color = [[s == '#' for s in str(input())] for _ in range(h)]
    used = [[False]*w for _ in range(h)]

    ans = 0
    for i in range(h):
        for j in range(w):
            if used[i][j]: continue
            bk, wt = 0, 0
            que = deque()
            used[i][j] = True
            que.append((i, j))
            while que:
                ci, cj = que.popleft()
                if color[ci][cj]: bk += 1
                else: wt += 1
                for di, dj in ((-1,0),(0,-1),(0,1),(1,0)):
                    ni, nj = ci+di, cj+dj
                    if ni < 0 or h <= ni or nj < 0 or w <= nj: continue
                    if color[ci][cj] == color[ni][nj]: continue
                    if used[ni][nj]: continue
                    used[ni][nj] = True
                    que.append((ni, nj))
            ans += bk * wt
    print(ans)

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

N, K = map(int, input().split())
a = list(map(int, input().split()))
ans = None
s = None

for i in range(0, N - K + 1):
    s = 0

    for j in range(K):
        s += a[i+j] + 1

    if ans is None or ans < s:
        ans = s

print(ans/2)

### FIXED CODE ###

N, K = map(int, input().split())
a = list(map(int, input().split()))
ans = None
s = None

for i in range(0, N - K + 1):
    s = sum(a[i:i+K]) + K if s is None else s - a[i - 1] + a[i + K - 1]

    if ans is None or ans < s:
        ans = s

print(ans/2)
### BUGGY CODE ###


def main():
    H, N = [int(x) for x in input().split()]
    magic = [list(map(int, input().split())) for _ in range(N)]
    # print(magic)
    max_a = max(a for a, _ in magic)
    dp = [float("inf") for _ in range(H + max_a)]
    dp[0] = 0

    for i in range(1, H+max_a):
        dp[i] = min(dp[i-a] + b for a, b in magic)

    ans = min(dp[H:H+max_a])
    print(ans)


if __name__ == '__main__':
    main()

### FIXED CODE ###

def main():
    H, N = [int(x) for x in input().split()]
    magic = [list(map(int, input().split())) for _ in range(N)]
    # print(magic)
    max_a = max(a for a, _ in magic)
    dp = [10**18 for _ in range(H + max_a)]
    dp[0] = 0

    for i in range(1, H+max_a):
        dp[i] = min(dp[i-a] + b for a, b in magic)

    ans = min(dp[H:H+max_a])
    print(ans)


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

n = int(input())
ans = 0
for i in range(n):
  ans += i
print(ans)

### FIXED CODE ###

n = int(input())
print((n-1)*n//2)
### BUGGY CODE ###

N = int(input())
S = list(input())
def cal(a, b, c):
    x = a[0]
    for bb in b:
        if bb > x:
            y = bb
            for cc in c:
                if cc > y:
                    return 1
    return 0
li = [[] for _ in range(10)]
for i, n in enumerate(S):
    num = int(n)
    li[num].append(i)
cnt = 0
for i in range(10):
    if len(li[i]) > 0:
        for j in range(10):
            if len(li[j]) > 0:
                for k in range(10):
                    if len(li[k]) > 0:
                        cnt += cal(li[i], li[j], li[k])
print(cnt)

### FIXED CODE ###

N = int(input())
S = list(input())

def cal(x, a):
    for aa in a:
        if aa > x:
            return aa
    return False

li = [[] for _ in range(10)]
for i, n in enumerate(S):
    num = int(n)
    li[num].append(i)
    
cnt = 0
flag = True
for i in range(10):
    if len(li[i]) > 0:
        for j in range(10):
            if len(li[j]) > 0:
                ret = cal(li[i][0], li[j])
                if  ret == False:
                    flag = False
                else: 
                    flag = True
                for k in range(10):
                    if len(li[k]) > 0 and flag == True:
                        ret2=cal(ret, li[k]) 
                        if  ret2 != False:
                            cnt += 1
print(cnt)
### BUGGY CODE ###

import numpy as np
from numpy.linalg import solve

n = int(input())
a = [int(i)*2 for i in input().split()]

x = []
for i in range(n-1):
    temp = [0]*n
    temp[i] = 1
    temp[i+1] = 1
    x.append(temp)

temp = [0]*n
temp[0] = 1
temp[n-1] = 1
x.append(temp)

x = np.array(x)
a = np.array(a)
#print(x)
#print(a)

y = solve(x, a)
ans = ""
for i in y:
    ans+=str(int(i))+" "

print(ans[0:len(ans)-1])



### FIXED CODE ###

n=int(input())
arr=list(map(int,input().split()))
arr2=[0]*n
for i in range(0,2*n,2):
  arr2[i//2]=arr[i%n]
ans=[0]*n
s=sum(arr)//2
cum=[0]*n
start=sum(arr2[:n//2])
cum[0]=start
l=n//2
for i in range(n):
  start=start+arr2[(i+l)%n]-arr2[i]
  cum[(i+1)%n]=start
for i in range(n):
  ans[(n-1+i*2)%n]=(s-cum[i])*2
print(*ans)
### BUGGY CODE ###

N = int(input())
length = [int(i) for i in input().split()]
pos = []

for a in range(len(length)+1):
    x = sum(length[:a])
    y = sum(length[a:])
    pos.append(max(x,y) - min(x,y))
    # print("pos " + str(a)+":",sum(length[:a]), sum(length[a:]))
# print(pos)

print(min(pos))

### FIXED CODE ###

N = int(input())
length = [int(i) for i in input().split()]
pos = []
s1 = sum(length)
s2 = 0

for a in range(len(length)):
    pos.append(max(s1,s2) - min(s1,s2))
    s1 -= length[a]
    s2 += length[a]
    # print("pos " + str(a)+":",sum(length[:a]), sum(length[a:]))
# print(pos)

print(min(pos))
### BUGGY CODE ###



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

allhiyatoi = [[] for j in range(M+1)]
for i in range(N):
    temp = list(map(int,input().split()))
    if temp[0] > M:
        continue
    allhiyatoi[temp[0]].append(temp[1])

temp = []
for i in allhiyatoi:
    temp.append(collections.deque(sorted(i)))

allhiyatoi = temp
 
reward = 0
for i in range(M+1):
    D = -1
    maxrw = -1
    for j,day in enumerate(allhiyatoi):
        if j > i:
            break
        if len(day) == 0:
            continue
        rw = max(day)
        if maxrw < rw:
            D = j
            maxrw = rw
    if D == -1:
        continue
    reward += allhiyatoi[D].pop()

print(reward)

### FIXED CODE ###

from heapq import heappush, heappop
 
N,M = map(int,input().split())

allhiyatoi = [[] for j in range(M+1)]
for i in range(N):
    temp = list(map(int,input().split()))
    if temp[0] > M:
        continue
    allhiyatoi[temp[0]].append(temp[1])
 
reward = 0
Q = []
for i in allhiyatoi:
    for j in i:
        heappush(Q,j*-1)
    if len(Q) == 0:
        continue
    reward -= (heappop(Q))

print(reward)
### BUGGY CODE ###

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

a.sort()
xy = [[] for i in range(N-1)]
cnt = 0
while len(a) > 2:
    if a[len(a)-1] > 0 and a[len(a)-2] > 0:
        n = a[0] - a[len(a)-1]
        xy[cnt] = [a[0], a[len(a)-1]]
        a = a[1:len(a) - 1]
        a.insert(0, n)
    else:
        n = a[len(a)-1] - a[0]
        xy[cnt] = [a[len(a)-1], a[0]]
        a = a[1:len(a) - 1]
        a.append(n)
    cnt += 1

m = a[1] - a[0]
xy[cnt] = [a[1], a[0]]
print(m)
for _xy in xy:
    print(str(_xy[0]) + " " + str(_xy[1]))

### FIXED CODE ###

from collections import deque

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

a.sort()

if a[0] >= 0:
    m = sum(a[1:]) - a[0]
    print(m)
    p = a.pop(0)
    while len(a) > 1:
        b = a.pop(0)
        print(*[p, b])
        p -= b
    b = a.pop()
    print(*[b, p])
elif a[-1] <= 0:
    m = -sum(a[:-1])+a[-1]
    print(m)
    p = a.pop(-1)
    while len(a) > 0:
        b = a.pop(0)
        print(*[p, b])
        p -= b
else:
    mi = list(filter(lambda x: x < 0, a))
    pl = list(filter(lambda x: x >= 0, a))
    m = -sum(mi) + sum(pl)
    print(m)
    lp = pl.pop(0)
    mi = deque(mi)
    while len(pl) > 0:
        b = pl.pop()
        c = mi.pop()
        print(*[c, b])
        c -= b
        mi.append(c)
    while len(mi) > 0:
        b = mi.pop()
        print(*[lp, b])
        lp -= b
### BUGGY CODE ###

import sys

def solve():
    N = int(input())
    S = input()
    lens = len(S)
    alp = ["a", "b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u",\
        "v","w","x","y","z"]
    
    DP = [[0 for j in range(lens)] for i in range(lens)]
    DP[lens - 2][lens - 1] = (1 if S[lens-2] == S[lens - 1] else 0)
    for i in reversed(range(lens - 1)):
        for j in reversed(range(i + 1, lens)):
            if S[i] == S[j]:
                if j == lens - 1: DP[i][j] = 1
                else: DP[i][j] = DP[i+1][j+1] + 1

    maxlength = 0
    for i in range(lens):
        for j in range(i+1, lens):
            maxlength = max(maxlength, min(DP[i][j], j - i))

    print(maxlength)
    return 0

if __name__ == "__main__":
    solve()

### FIXED CODE ###

import sys

def solve():
    N = int(input())
    S = input()
    lens = len(S)
    alp = ["a", "b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u",\
        "v","w","x","y","z"]
    
    DP = [[0 for j in range(lens)] for i in range(lens)]
    DP[lens - 2][lens - 1] = (1 if S[lens-2] == S[lens - 1] else 0)
    for i in reversed(range(lens - 1)):
        for j in reversed(range(i + 1, lens)):
            if S[i] == S[j]:
                if j == lens - 1: DP[i][j] = 1
                else: DP[i][j] = DP[i+1][j+1] + 1

    maxlength = 0
    for i in range(lens):
        for j in range(i+1, lens):
            maxlength = max(maxlength, min(DP[i][j], j - i))

    print(maxlength)
    return 0

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

from sys import stdin
input = stdin.readline


def main():
  N = int(input())
  G = [[] for _ in range(N+1)]
  for i in range(N-1):
    u, v, w = map(int, input().split())
    G[u].append((v, w))
    G[v].append((u, w))

  color = [-1 for _ in range(N+1)]
  color[1] = 0
  S = [1]
  S_append = S.append
  S_pop = S.pop
  while len(S):
    now = S[-1]
    for next_, w in G[now]:
      if color[next_] != -1:
        continue
      S_append(next_)
      color[next_] = (w % 2) ^ color[now]
      break
    else:
      S_pop()

  for i in range(1, N+1):
    print(color[i])


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

### FIXED CODE ###

import sys
from collections import defaultdict, deque

def main():
    input = sys.stdin.readline
    N = int(input())
    d = defaultdict(list)
    for _ in range(N-1):
        u, v, w = map(int, input().split())
        d[u-1].append((v-1, w))
        d[v-1].append((u-1, w))

    dist = [0] * N
    q = deque()
    q.append((0, 0))
    visited = set()

    while len(q) > 0:
        q_ = deque()
        while len(q) > 0:
            node1, cost1 = q.popleft()

            dist[node1] = cost1
            visited.add(node1)

            for node2, cost2 in d[node1]:
                if node2 in visited:
                    continue

                q_.append((node2, cost1 + cost2))

        q = q_

    for d in dist:
        print(d % 2)


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

N = int(input())
S = list(str(input()))

passwords = []
for i in range(len(S) - 2):
    for j in range(i + 1, len(S) - 1):
        for k in range(j + 1, len(S)):
            password = S[i] + S[j] + S[k]
            passwords.append(password)


# print(len(passwords))
# print(passwords)
# print(set(passwords))
print(len(list(set(passwords))))


### FIXED CODE ###

N = int(input())
S = list(str(input()))

passwords = []
for i in range(0, 10):
    for j in range(0, 10):
        for k in range(0, 10):
            password = str(i) + str(j) + str(k)
            passwords.append(password)

char_hash = {}
for i, char in enumerate(S):
    if char in char_hash.keys():
        char_hash[char].append(i)
    else:
        char_hash[char] = [i]

# print(char_hash

count = 0
for password in passwords:
    exist_keys = char_hash.keys()
    # print(password[0] in char_hash.keys())
    if not(password[0] in exist_keys):
        continue
    if not(password[1] in exist_keys):
        continue
    if not(password[2] in exist_keys):
        continue
    first_index = min(char_hash[password[0]])
    second_indexes = char_hash[password[1]]
    second_index = -1
    for index in second_indexes:
        if index <= first_index:
            continue
        else:
            second_index = index
            break
    third_indexes = char_hash[password[2]]
    third_index = -1
    for index in third_indexes:
        if index <= second_index:
            continue
        else:
            third_index = index
            break
    # print(first_index, second_index, third_index)
    if first_index < second_index and second_index < third_index:
        count += 1

print(count)
# print(len(passwords))
# print(passwords)
# print(set(passwords))
# print(len(list(set(passwords))))
### BUGGY CODE ###

from collections import defaultdict


def nC2(n):
    return n*(n-1)//2


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

h = defaultdict(int)
for a in A:
    h[a] += 1

for k in range(N):
    t = A[k]
    h[t] -= 1

    ans = 0
    for a, n in h.items():
        if n >= 2:
            ans += nC2(n)
    print(ans)

    h[t] += 1


### FIXED CODE ###

from collections import defaultdict


def nC2(n):
    if n < 2:
        return 0
    return n*(n-1)//2


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

h = defaultdict(int)
for a in A:
    h[a] += 1

total = 0
for k, v in h.items():
    total += nC2(v)

for k in range(N):
    t = A[k]
    print(total - h[t] + 1)
### BUGGY CODE ###

N = int(input())

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

P = [0] + P
     
count = 0
for i in range(1, N+1):
    #print(P[1:i+1])
    #print(len(list(set(P[1:i+1]))))
    for j in range(1, len(list(set(P[1:i+1])))+1):
        #print(i, P[i], j , P[j])
        if P[i] > P[j]:
            #print("out", i)
            break
    else:
        #print("ok", i)
        count += 1
else:
    print(count)

### FIXED CODE ###

N = int(input())

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

P = [0] + P
     
count = 0
min = 10000000000000
for i in range(1, N+1):
    if min > P[i]:
        min = P[i]
    elif min < P[i]:
        continue
    """
    for j in range(1, i+1):
        #print(i, P[i], j , P[j])
        if P[i] > P[j]:
            #print("out", i)
            break
    else:
        #print("ok", i)
        count += 1
    """
    count += 1
        
    if P[i] == 1:
        break

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

import itertools

N = int(input())

A_list = []
inp_list = list(map(int, input().split(" ")))
for i in range(N):
	A_list.append([i+1, inp_list[i]])
answer = 0
for v in itertools.combinations(A_list, 2):
	if abs(v[0][0] - v[1][0]) == (v[0][1] + v[1][1]):
		answer += 1
print(answer)

### FIXED CODE ###

N = int(input())

X1_dict = {}
X2_dict = {}
inp_list = list(map(int, input().split(" ")))
for i, a_i in enumerate(inp_list):
	X1 = i + 1 + a_i
	X2 = i + 1 - a_i
	if X1 in X1_dict.keys():
		X1_dict[X1] += 1
	else:
		X1_dict[X1] = 1
	if X2 in X2_dict.keys():
		X2_dict[X2] += 1
	else:
		X2_dict[X2] = 1

answer = 0
for key, value in X1_dict.items():
	if key in X2_dict.keys():
		answer += value * X2_dict[key]
		
print(answer)
### BUGGY CODE ###

N, Q = map(int, input().split())
S = input()
ans = []
for i in range(Q):
    l, r = map(int, input().split())
    T = S[l-1:r]
    ans.append(T.count('AC'))
print(*ans, sep='\n')

### FIXED CODE ###

N, Q = map(int, input().split())
S = input()
T = [0]*(N+1)

for i in range(1, N):
    T[i+1] = T[i] + (1 if S[i-1:i+1]=='AC' else 0)
ans = []
for _ in range(Q):
    l, r = map(int, input().split())
    ans.append(T[r] - T[l])
print(*ans, sep='\n')
### BUGGY CODE ###

class MyList(list):
    def __init__(self):
        self.__init__ = list

    def cmd(self,command):
        if command == 'deleteFirst':
            if len(self) > 0:
                self.pop(0)
        elif command == 'deleteLast':
            if len(self) > 0:
                self.pop(-1)
        else:
            ope, num = command.split()
            num = int(num)
            if ope == 'insert':
                self.insert(0,num)
            else:
                if num in self:
                    self.remove(num)


if __name__ == '__main__' :
    l = MyList()
    n = input()
    for i in range(n):
        l.cmd(raw_input())

    for i in range(len(l)-1):
        print l[i],
    print l[-1]

### FIXED CODE ###

from collections import deque

class MyList(deque):
    def __init__(self):
        self.__init__ = deque
        self.d = {'deleteFirst':self.delF, 'deleteLast':self.delL, 'insert':self.insX, 'delete':self.delX}
    def cmd(self,command):
        if ' ' in command:
            ope, num = command.split()
            num = int(num)
            self.d[ope](num)
        else:
            self.d[command]()
            
    def delF(self):
        self.popleft()

    def delL(self):
        self.pop()

    def insX(self,num):
        self.appendleft(num)

    def delX(self,num):
        if num in self:
            self.remove(num)

if __name__ == '__main__' :
    l = MyList()
    n = input()
    
    for i in range(n):
        l.cmd(raw_input())

    q = deque(l)
    for i in range(len(l)-1):
        print q.popleft(),
    print l[-1]
### BUGGY CODE ###

import sys
input = sys.stdin.readline
def main():
  n, k = map(int, input().split())
  m = n**2
  mod = 10**9+7
  dp = [[[0]*(m+1) for j in range(i+1)] for i in range(n+1)]
  dp[0][0][0] = 1
  for i in range(n):
    for j in range(i+1):
      for l in range(m+1):
        if j and l+2*(j-1) <= m:
          dp[i+1][j-1][l+2*(j-1)] += dp[i][j][l]*j**2
        if l+2*j <= m:
          dp[i+1][j][l+2*j] += dp[i][j][l]*(2*j+1)
          if l+2*(j+1) <= m: 
            dp[i+1][j+1][l+2*(j+1)] += dp[i][j][l]
  ans = dp[n][0][k]%mod
  print(ans)
if __name__ == "__main__":
  main()

### FIXED CODE ###

n, k = map(int, input().split())
m = n**2
mod = 10**9+7
dp = [[[0]*(m+1) for j in range(i+1)] for i in range(n+1)]
dp[0][0][0] = 1
for i in range(n):
  for j in range(i+1):
    for l in range(m+1):
      dp[i][j][l] %= mod
      if j and l+2*(j-1) <= m:
        dp[i+1][j-1][l+2*(j-1)] += dp[i][j][l]*j**2
      if l+2*j <= m:
        dp[i+1][j][l+2*j] += dp[i][j][l]*(2*j+1)
        if l+2*(j+1) <= m: 
          dp[i+1][j+1][l+2*(j+1)] += dp[i][j][l]
ans = dp[n][0][k]%mod
print(ans)
### BUGGY CODE ###

#!/usr/bin/python3
# -*- coding: utf-8 -*-


MOD = 10**9+7
Facts = [1]*(2*10**5+1)
for i in range(2,2*10**5+1):
  Facts[i] = (Facts[i-1]*i) % MOD

def mul(a,b):
  return (a*b) % MOD

def power(a,b):
  if   b==0   : return 1
  elif b==1   : return a % MOD
  elif b%2==0 : return power(a,b//2)**2 % MOD
  else        : return power(a,b//2)**2 * a % MOD

def div(a,b):
  return mul(a,power(b,MOD-2))


def combi(n,m,k):
  if k <= 2 or k >= n*m:
    return 1
  else:
    return div(Facts[n*m-2],(Facts[k-2]*Facts[n*m-k]))


def main():
  N,M,K = map(int, input().split())
  ans = 0
  for d in range(1,N):
    ans = (ans + d * (N-d)*M**2 * combi(N,M,K)) % MOD
  for d in range(1,M):
    ans = (ans + d * (M-d)*N**2 * combi(N,M,K)) % MOD
  return ans

if __name__ == "__main__":
  print(main())

### FIXED CODE ###

#!/usr/bin/python3
# -*- coding: utf-8 -*-


MOD = 10**9+7
Facts = [1]*(2*10**5+1)
for i in range(2,2*10**5+1):
  Facts[i] = (Facts[i-1]*i) % MOD

def mul(a,b):
  return (a*b) % MOD

def power(a,b):
  if   b==0   : return 1
  elif b==1   : return a % MOD
  elif b%2==0 : return power(a,b//2)**2 % MOD
  else        : return power(a,b//2)**2 * a % MOD

def div(a,b):
  return mul(a,power(b,MOD-2))


def combi(n,m,k):
  if k <= 2 or k >= n*m:
    return 1
  else:
    return div(Facts[n*m-2],(Facts[k-2]*Facts[n*m-k]))


def main():
  N,M,K = map(int, input().split())
  com = combi(N,M,K)
  ans = 0
  for d in range(1,N):
    ans = (ans + d * (N-d)*M**2 * com) % MOD
  for d in range(1,M):
    ans = (ans + d * (M-d)*N**2 * com) % MOD
  return ans

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

import sys
input = sys.stdin.readline
n,m = map(int, input().split())
a = [int(input()) for i in range(m)]
mod = (10**9)+7
dp = [1] + [0]*(n)
for i in range(1,n+1):
    if i in a:
        dp[i] == 0
    else:
        dp[i] = dp[i-1] + dp[i-2]
        dp[i] %= mod
print(dp[-1])

### FIXED CODE ###

import sys
input = sys.stdin.readline
n,m = map(int, input().split())
A = set()
for i in range(m):
    a = int(input())
    A.add(a)
mod = (10**9)+7
dp = [1] + [0]*(n)
for i in range(1,n+1):
    if i in A:
    #リストに対するinは激遅なのでset
        dp[i] == 0
    else:
        dp[i] = dp[i-1] + dp[i-2]
        dp[i] %= mod
print(dp[-1])
### BUGGY CODE ###

import sys
import math
a,b,c,k=map(int,input().split())
s=[]
for _ in range(a):
    s.append(1)
for _ in range(b):
    s.append(0)
for _ in range(c):
    s.append(-1)
s_s=s[:k]
print(sum(s_s))


### FIXED CODE ###

import sys
import math
a,b,c,k=map(int,input().split())
if a>k:
    print(k)
elif a+b>=k or a>=k:
    print(a)
elif c>(k-(a+b)):
    s=k-(a+b)
    print(a-1*s)
else:
    print(a-c)
### BUGGY CODE ###

N, A, *x = map(int, open(0).read().split())
dp = [[[0]*(3000) for _ in range(55)] for _ in range(55)]
dp[0][0][0] = 1

for j in range(N+1):
    for k in range(N+1):
        for s in range(N*A+1):
            if j >= 1:
                dp[j][k][s] += dp[j-1][k][s]  # 選ばない場合
                if k >= 1 and s >= x[j-1]:
                    dp[j][k][s] += dp[j-1][k-1][s-x[j-1]]  # 選ぶ場合
ans = 0
for k in range(1, N+1):
    ans += dp[N][k][k*A]
print(ans)

### FIXED CODE ###

N, A, *x = map(int, open(0).read().split())
dp = [[[0]*(3000) for _ in range(55)] for _ in range(55)]
dp[0][0][0] = 1

for j in range(N+1):
    for k in range(N+1):
        for s in range(N*A+1):
            if j >= 1:
                dp[j][k][s] += dp[j-1][k][s]  # 選ばない場合
                if k >= 1 and s >= x[j-1]:
                    dp[j][k][s] += dp[j-1][k-1][s-x[j-1]]  # 選ぶ場合
ans = 0
for k in range(1, N+1):
    ans += dp[N][k][k*A]
print(ans)
### BUGGY CODE ###

n = int(input())
a = [int(i) for i in input().split()] 
a_unique = list(set(a))
count = 0
for i in a_unique:
    check = i - a.count(i)
    if check < 0:
        count += abs(check)
    elif check > 0:
        count += i - check
print(count)

### FIXED CODE ###

n = int(input())
a = [int(i) for i in input().split()] 
count = {}
ans = 0
for i in a:
    if i not in count:
        count[i] = 1
    else:
        count[i] += 1
for i,c in count.items():
    if i > c:
        ans += c
    elif i < c:
        ans += c - i
print(ans)
### BUGGY CODE ###

n = int(input())
i = 1

while True:
    x = i
    if  x % 3 == 0:
        print(" %d" , i, end="")
        i+=1
        if i > n:
            print()
            break


### FIXED CODE ###

#
# 5d
#

def main():
    n = int(input())
    s = ""
    for i in range(1, n+1):
        x = i
        if x % 3 == 0 or x % 10 == 3:
            s += " " + str(i)
        else:
            x //= 10
            while x:
                if x % 10 == 3:
                    s += " " + str(i)
                    break
                x //= 10
    print(s)


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

l, r = map(int,input().split())

n = min(l+4048, r)

ans = 2018
tmp = 2018

for i in range(l,n+1):
    for j in range(i+1,n+1):
        tmp = (i*j) % 2019
        ans = min(ans, tmp)

print(ans)

### FIXED CODE ###

l, r = map(int,input().split())

n = min(l+2020, r)

ans = 2018

for i in range(l,n+1):
    if ans == 0:
        break
    for j in range(i+1,n+1):
        ans = min(ans, (i*j) % 2019)

print(ans)