Problem: Everyone knows what the Fibonacci sequence is. This sequence can be defined by the recurrence relation: 

F1 = 1, F2 = 2, Fi = Fi - 1 + Fi - 2 (i > 2).

We'll define a new number sequence Ai(k) by the formula: 

Ai(k) = Fi × ik (i ≥ 1).

In this problem, your task is to calculate the following sum: A1(k) + A2(k) + ... + An(k). The answer can be very large, so print it modulo 1000000007 (109 + 7).

Input

The first line contains two space-separated integers n, k (1 ≤ n ≤ 1017; 1 ≤ k ≤ 40).

Output

Print a single integer — the sum of the first n elements of the sequence Ai(k) modulo 1000000007 (109 + 7).

Examples

Input

1 1


Output

1


Input

4 1


Output

34


Input

5 2


Output

316


Input

7 4


Output

73825

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
const int MOD = (int)1e9 + 7;
const int INF = (int)1e9;
const long long LINF = (long long)1e18;
const long double PI = acos((long double)-1);
const long double EPS = 1e-9;
inline long long gcd(long long a, long long b) {
  long long r;
  while (b) {
    r = a % b;
    a = b;
    b = r;
  }
  return a;
}
inline long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
inline long long fpow(long long n, long long k, int p = MOD) {
  long long r = 1;
  for (; k; k >>= 1) {
    if (k & 1) r = r * n % p;
    n = n * n % p;
  }
  return r;
}
template <class T>
inline int chkmin(T& a, const T& val) {
  return val < a ? a = val, 1 : 0;
}
template <class T>
inline int chkmax(T& a, const T& val) {
  return a < val ? a = val, 1 : 0;
}
inline long long isqrt(long long k) {
  long long r = sqrt(k) + 1;
  while (r * r > k) r--;
  return r;
}
inline long long icbrt(long long k) {
  long long r = cbrt(k) + 1;
  while (r * r * r > k) r--;
  return r;
}
inline void addmod(int& a, int val, int p = MOD) {
  if ((a = (a + val)) >= p) a -= p;
}
inline void submod(int& a, int val, int p = MOD) {
  if ((a = (a - val)) < 0) a += p;
}
inline int mult(int a, int b, int p = MOD) { return (long long)a * b % p; }
inline int inv(int a, int p = MOD) { return fpow(a, p - 2, p); }
struct matrix {
  static const int MAXN = 2;
  static const int MOD = (int)1e9 + 7;
  int x[MAXN][MAXN];
  matrix() { memset(x, 0, sizeof(x)); }
  matrix unit() {
    matrix res;
    for (int i = 0; i < MAXN; i++) res.x[i][i] = 1;
    return res;
  }
  matrix operator+(matrix A) {
    matrix res;
    for (int i = 0; i < MAXN; i++)
      for (int j = 0; j < MAXN; j++) {
        res.x[i][j] = x[i][j] + A.x[i][j];
        if (res.x[i][j] >= MOD) res.x[i][j] -= MOD;
      }
    return res;
  }
  matrix operator*(matrix A) {
    matrix res;
    for (int i = 0; i < MAXN; i++)
      for (int k = 0; k < MAXN; k++)
        for (int j = 0; j < MAXN; j++) {
          res.x[i][j] = (res.x[i][j] + (long long)x[i][k] * A.x[k][j]) % MOD;
        }
    return res;
  }
  matrix operator^(long long k) {
    if (!k) return unit();
    matrix res, tmp;
    for (int i = 0; i < MAXN; i++)
      for (int j = 0; j < MAXN; j++) {
        res.x[i][j] = tmp.x[i][j] = x[i][j];
      }
    k--;
    while (k) {
      if (k & 1) res = res * tmp;
      tmp = tmp * tmp;
      k >>= 1;
    }
    return res;
  }
  friend matrix sumpower(matrix A, long long k) {
    if (k == 1) return A;
    vector<int> bit;
    while (k) {
      bit.push_back(k & 1);
      k >>= 1;
    }
    matrix res = A, tmp = A;
    for (int i = bit.size() - 2; i >= 0; i--) {
      res = res + (res * tmp);
      tmp = tmp * tmp;
      if (bit[i] & 1) {
        tmp = tmp * A;
        res = res + tmp;
      }
    }
    return res;
  }
} A;
const int maxk = 40 + 10;
long long n;
int k;
int c[maxk][maxk];
int f[maxk];
int calc(int k) {
  if (!k) {
    matrix B = A ^ (n + 2);
    int res = B.x[0][0];
    submod(res, 2);
    return res;
  }
  int& res = f[k];
  if (~res) return res;
  res = 0;
  for (int i = (0); i < (k); i++) {
    int tmp = fpow(MOD - 1, k - i);
    submod(tmp, fpow(MOD - 2, k - i));
    tmp = mult(tmp, c[i][k]);
    submod(res, mult(tmp, calc(i)));
  }
  matrix B = A ^ (n + 2);
  int tmp = B.x[0][0];
  tmp = mult(tmp, fpow(n % MOD, k));
  submod(tmp, fpow(MOD - 1, k));
  addmod(res, tmp);
  tmp = fpow(n % MOD, k);
  submod(tmp, fpow((n - 1) % MOD, k));
  B = A ^ (n + 1);
  tmp = mult(tmp, B.x[0][0]);
  submod(res, tmp);
  return res;
}
void solve() {
  for (int i = (0); i < (maxk); i++) c[0][i] = 1;
  for (int i = (1); i < (maxk); i++)
    for (int j = (1); j < (maxk); j++)
      c[i][j] = (c[i][j - 1] + c[i - 1][j - 1]) % MOD;
  A.x[0][0] = A.x[0][1] = A.x[1][0] = 1;
  cin >> n >> k;
  memset(f, -1, sizeof(f));
  cout << calc(k) << "\n";
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  solve();
  return 0;
}