#include <bits/stdc++.h>
using namespace std;
int a[100][100], tp[100][100];
int ans[100][100];
int m;
int f[100];
int c[100][100];
void multi(int a[100][100], int b[100][100], int c[100][100]) {
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= m; j++) {
      tp[i][j] = 0;
      for (int k = 1; k <= m; k++)
        tp[i][j] = (tp[i][j] + (long long)a[i][k] * b[k][j]) % 1000000007;
    }
  }
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= m; j++) c[i][j] = tp[i][j];
  }
}
void pre() {
  f[0] = 1;
  for (int i = 1; i < 100; i++) f[i] = (long long)f[i - 1] * 2 % 1000000007;
  for (int i = 0; i < 100; i++) {
    for (int j = 0; j <= i; j++) {
      if (i == 0) {
        c[i][j] = 1;
        continue;
      }
      c[i][j] = c[i - 1][j - 1] + c[i - 1][j];
      if (c[i][j] >= 1000000007) c[i][j] -= 1000000007;
    }
  }
}
int main() {
  pre();
  long long n;
  int k;
  scanf("%I64d%d", &n, &k);
  m = 2 * k + 3;
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= m; j++) {
      if (i == j)
        ans[i][j] = 1;
      else
        ans[i][j] = 0;
    }
  }
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= m; j++) {
      if (j == m) {
        if (i == m)
          a[i][j] = 1;
        else
          a[i][j] = 0;
        continue;
      }
      if (i == m) {
        if (j == 1 || j == m)
          a[i][j] = 1;
        else
          a[i][j] = 0;
        continue;
      }
      if (i > k + 1) {
        if (i - j == k + 1)
          a[i][j] = 1;
        else
          a[i][j] = 0;
        continue;
      }
      int ii = k + 1 - i;
      if (j <= k + 1 && j > k - ii) {
        a[i][j] = c[ii][k + 1 - j];
        continue;
      }
      if (j <= 2 * k + 2 && j > 2 * k + 2 - ii - 1) {
        a[i][j] = (long long)c[ii][2 * k + 2 - j] * f[ii - (2 * k + 2 - j)] %
                  1000000007;
        continue;
      }
    }
  }
  long long xx = n - 1;
  while (xx) {
    if (xx & 1) multi(ans, a, ans);
    multi(a, a, a);
    xx /= 2;
  }
  int res = 0;
  for (int i = 1; i <= m; i++) {
    if (i <= k + 1)
      res += (long long)ans[m][i] * f[k + 2 - i] % 1000000007;
    else
      res += ans[m][i];
    if (res >= 1000000007) res -= 1000000007;
  }
  printf("%d\n", res);
  return 0;
}
