#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e9;
const long long inf64 = 1e18;
const long long MOD = inf + 7;
const long long SZ = 2;
long long add(long long a, long long b) {
  long long res = a + b;
  if (res >= MOD) return res - MOD;
  return res;
}
long long mult(long long a, long long b) {
  long long res = a;
  res *= b;
  if (res >= MOD) return res % MOD;
  return res;
}
struct matrix {
  long long arr[SZ][SZ];
  void reset() { memset(arr, 0, sizeof(arr)); }
  void makeiden() {
    reset();
    for (long long i = 0; i < SZ; i++) {
      arr[i][i] = 1;
    }
  }
  matrix operator+(const matrix &o) const {
    matrix res;
    for (long long i = 0; i < SZ; i++) {
      for (long long j = 0; j < SZ; j++) {
        res.arr[i][j] = add(arr[i][j], o.arr[i][j]);
      }
    }
    return res;
  }
  matrix operator*(const matrix &o) const {
    matrix res;
    for (long long i = 0; i < SZ; i++) {
      for (long long j = 0; j < SZ; j++) {
        res.arr[i][j] = 0;
        for (long long k = 0; k < SZ; k++) {
          res.arr[i][j] = add(res.arr[i][j], mult(arr[i][k], o.arr[k][j]));
        }
      }
    }
    return res;
  }
};
matrix power(matrix a, long long b) {
  matrix res;
  res.makeiden();
  while (b) {
    if (b & 1) {
      res = res * a;
    }
    a = a * a;
    b >>= 1;
  }
  return res;
}
long long pow(long long a, long long b, long long m) {
  long long ans = 1;
  while (b) {
    if (b & 1) ans = (ans * a) % m;
    b /= 2;
    a = (a * a) % m;
  }
  return ans;
}
long long modinv(long long k) { return pow(k, MOD - 2, MOD); }
void solve() {
  long long x, k;
  cin >> x >> k;
  long long ans;
  if (k == 0) {
    ans = (2 * x) % MOD;
  } else {
    matrix mt;
    mt.reset();
    mt.arr[0][0] = 2;
    mt.arr[0][1] = 1;
    mt.arr[1][1] = 1;
    matrix res = power(mt, k);
    long long inv = (MOD - modinv(2)) % MOD;
    ans = (res.arr[0][0] * (x % MOD)) % MOD;
    ans = (ans + (res.arr[0][1] * inv) % MOD) % MOD;
    ans = (ans * 2) % MOD;
  }
  if (x == 0) ans = 0;
  cout << ans << "\n";
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  while (t--) solve();
}
