import numba import dataclasses import sys sys.setrecursionlimit(500005) stdin = sys.stdin ni = lambda: int(ns()) na = lambda: list(map(int, stdin.readline().split())) ns = lambda: stdin.readline().strip() @dataclasses.dataclass class State: clus: [int] val: int hidden: int def h(self): return (*self.clus, self.hidden) mod = 1000000007 @numba.njit def normalize(a: [int]) -> [int]: label = [-1] * 11 p = 0 for i in range(len(a)): if a[i] == -1: continue if label[a[i]] == -1: label[a[i]] = p p += 1 a[i] = label[a[i]] return a @numba.njit def add(s: State, dp: [int, State]): key = s.h() if key in dp: dp[key].val = (dp[key].val + s.val) % mod else: dp[key] = s @numba.njit def main(): n, m = na() initial = State([-1] * n, 1, 0) dp: [int, State] = dict() dp[initial.h()] = initial for j in range(m+1): for i in range(n): ndp = dict() for s in dp.values(): # 黒いセルを追加 nclus = [0] * n for k in range(n-1): nclus[k+1] = s.clus[k] nclus[0] = n if i > 0 and s.clus[0] != -1: for k in range(1, n): if nclus[k] == s.clus[0]: nclus[k] = n if s.clus[-1] != -1: for k in range(1, n): if nclus[k] == s.clus[-1]: nclus[k] = n normalize(nclus) ns = State(nclus, s.val, s.hidden) add(ns, ndp) nclus = [0] * n for k in range(n-1): nclus[k+1] = s.clus[k] nclus[0] = -1 nhidden = s.hidden if s.clus[-1] != -1 and all(s.clus[_] != s.clus[-1] for _ in range(n-1)): nhidden += 1 if nhidden <= 1: normalize(nclus) ns = State(nclus, s.val, nhidden) add(ns, ndp) dp = ndp ans = 0 for s in dp.values(): if s.hidden == 1 and all(_ == -1 for _ in s.clus): ans += s.val print(ans % mod) main()