#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
const int INF = 0x3f3f3f3f;
const long long INFF = 0x3f3f;
const double pi = acos(-1.0);
const double inf = 1e18;
const double eps = 1e-9;
const long long mod = 1e9 + 7;
const unsigned long long mxx = 1333331;
inline void RI(int &x) {
  char c;
  while ((c = getchar()) < '0' || c > '9')
    ;
  x = c - '0';
  while ((c = getchar()) >= '0' && c <= '9') x = (x << 3) + (x << 1) + c - '0';
}
long long a1[1000005];
long long a2[1000005];
long long qpow(long long a, int n) {
  long long ret = 1;
  while (n) {
    if (n & 1) ret = ret * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return ret;
}
int main() {
  int n, m;
  while (cin >> n >> m) {
    a1[0] = 1;
    a2[0] = 1;
    for (int i = 1; i <= n; i++) {
      a1[i] = a1[i - 1] * m % mod;
      a2[i] = a2[i - 1] * (2 * m - 1) % mod;
    }
    long long ans = qpow((long long)m, n);
    for (int i = 0; i < n; i++) {
      ans = (ans + a1[i + 1] * a2[n - i - 1] % mod) % mod;
    }
    cout << ans << endl;
  }
  return 0;
}

### Prompt

Please create a solution in Cpp to the following problem:

For a sequence a of n integers between 1 and m, inclusive, denote f(a) as the number of distinct subsequences of a (including the empty subsequence).

You are given two positive integers n and m. Let S be the set of all sequences of length n consisting of numbers from 1 to m. Compute the sum f(a) over all a in S modulo 109 + 7.

Input

The only line contains two integers n and m (1 ≤ n, m ≤ 106) — the number of elements in arrays and the upper bound for elements.

Output

Print the only integer c — the desired sum modulo 109 + 7.

Examples

Input

1 3


Output

6


Input

2 2


Output

14


Input

3 3


Output

174

### Response

```cpp
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
const int INF = 0x3f3f3f3f;
const long long INFF = 0x3f3f;
const double pi = acos(-1.0);
const double inf = 1e18;
const double eps = 1e-9;
const long long mod = 1e9 + 7;
const unsigned long long mxx = 1333331;
inline void RI(int &x) {
  char c;
  while ((c = getchar()) < '0' || c > '9')
    ;
  x = c - '0';
  while ((c = getchar()) >= '0' && c <= '9') x = (x << 3) + (x << 1) + c - '0';
}
long long a1[1000005];
long long a2[1000005];
long long qpow(long long a, int n) {
  long long ret = 1;
  while (n) {
    if (n & 1) ret = ret * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return ret;
}
int main() {
  int n, m;
  while (cin >> n >> m) {
    a1[0] = 1;
    a2[0] = 1;
    for (int i = 1; i <= n; i++) {
      a1[i] = a1[i - 1] * m % mod;
      a2[i] = a2[i - 1] * (2 * m - 1) % mod;
    }
    long long ans = qpow((long long)m, n);
    for (int i = 0; i < n; i++) {
      ans = (ans + a1[i + 1] * a2[n - i - 1] % mod) % mod;
    }
    cout << ans << endl;
  }
  return 0;
}

```