#include <bits/stdc++.h>
using namespace std;
long long N, MOD;
struct mat {
  long long m[90][90];
  void clear() { memset(m, 0, sizeof m); }
  void unit() {
    clear();
    for (long long i = 0; i < N; i++) m[i][i] = 1;
  }
  void copy(mat x) {
    for (long long i = 0; i < N; i++)
      for (long long j = 0; j < N; j++) m[i][j] = x[i][j];
  }
  long long *operator[](long long r) { return m[r]; }
};
mat operator*(mat a, mat b) {
  mat c;
  for (long long i = 0; i < N; i++)
    for (long long j = 0; j < N; j++) {
      c[i][j] = 0;
      for (long long k = 0; k < N; k++) {
        c[i][j] += (a[i][k] * b[k][j]) % MOD;
        c[i][j] %= MOD;
      }
    }
  return c;
}
mat operator+(mat a, mat b) {
  mat c;
  for (long long i = 0; i < N; i++)
    for (long long j = 0; j < N; j++) {
      c[i][j] = (a[i][j] + b[i][j]) % MOD;
    }
  return c;
}
long long n, k, y[50][50];
void yanghui_init() {
  memset(y, -1, sizeof y);
  for (long long i = 0; i <= k; i++)
    for (long long j = 0; j <= i; j++) {
      if (i == j || j == 0)
        y[i][j] = 1;
      else {
        y[i][j] = y[i - 1][j] + y[i - 1][j - 1];
      }
    }
}
int main() {
  MOD = 1e9 + 7;
  cin >> n >> k;
  N = 1 + 2 * (k + 1);
  yanghui_init();
  mat base, res;
  base[0][0] = base[0][1] = 1;
  for (long long i = 1; i <= k + 1; i++) {
    for (long long j = i; j <= k + 1; j++) {
      base[i][j] = y[k + 1 - i][j - i];
    }
    for (long long j = i + k + 1; j < N; j++) {
      base[i][j] = base[i][j - k - 1];
    }
  }
  for (long long i = k + 2; i < N; i++) {
    for (long long j = i - k - 1; j <= k + 1; j++) {
      base[i][j] = y[2 * k + 2 - i][j - (i - k - 1)];
    }
  }
  res.unit();
  long long A[N];
  A[0] = 1;
  A[k + 1] = 2;
  A[N - 1] = 1;
  for (long long i = k; i >= 1; i--) {
    A[i] = (2 * A[i + 1]) % MOD;
  }
  for (long long i = N - 2; i >= k + 2; i--) {
    A[i] = (2 * A[i + 1]) % MOD;
  }
  if (n == 0)
    cout << "0\n";
  else {
    n--;
    while (n) {
      if (n & 1LL) res = res * base;
      base = base * base;
      n /= 2;
    }
    long long ans = 0;
    for (long long i = 0; i < N; i++) {
      ans += (A[i] * res[0][i]) % MOD;
      ans %= MOD;
    }
    cout << ans << endl;
  }
  return 0;
}
