#include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long LL; typedef double DB; typedef pair PII; typedef vector VI; typedef vector VPII; #define X first #define Y second #define pb push_back #define bit(n) (1 << (n)) #define count(n) (__builtin_popcount(n)) #define countl(n) (__builtin_popcountll(n)) template inline void chkmin(T &x, T y) { if (y < x) x = y; } template inline void chkmax(T &x, T y) { if (x < y) x = y; } const int MN = bit(7); int n, m; int A[MN][MN]; int L; int ans[MN][MN]; #define MOD int(1e9 + 7) void multi(int c[MN][MN], int _a[MN][MN], int _b[MN][MN]) { int a[MN][MN], b[MN][MN], i, j, k, tmp; memcpy(a, _a, sizeof a); memcpy(b, _b, sizeof b); for (i = 0; i < L; i++) { for (j = 0; j < L; j++) { tmp = 0; for (k = 0; k < L; k++) { tmp += (LL)a[i][k] * b[k][j] % MOD; tmp %= MOD; } c[i][j] = tmp; } } } bool valid(int x, int y) { for (int i = 0; i < m - 1; i++) { if (bool(x & bit(i)) != bool(x & bit(i + 1))) { if (x & bit(i)) { if (!(y & bit(i)) && (y & bit(i + 1))) return 0; } else { if (!(y & bit(i + 1)) && (y & bit(i))) return 0; } } } return 1; } int main() { while (scanf("%d%d", &n, &m) == 2) { L = bit(m); memset(A, 0, sizeof A); memset(ans, 0, sizeof ans); for (int i = 0; i < bit(m); i++) { for (int j = 0; j < bit(m); j++) { if (valid(i, j)) A[i][j] = 1; } } for (int i = 0; i < L; i++) ans[i][i] = 1; for (int b = n - 1; b; b /= 2) { if (b & 1) multi(ans, A, ans); multi(A, A, A); } int rlt = 0; for (int i = 0; i < L; i++) { for (int j = 0; j < L; j++) { rlt = (rlt + ans[i][j]) % MOD; } } printf("%d\n", rlt); } return 0; }