#include <bits/stdc++.h>
using namespace std;
int mod = 1e9 + 7;
long long f_pow(long long a, long long b) {
  long long res = 1, temp = a;
  while (b) {
    if (b & 1) res = res * temp % mod;
    temp = temp * temp % mod;
    b >>= 1;
  }
  return res;
}
long long fra[2000005];
long long inv[2000005];
long long C(int a, int b) { return fra[a] * inv[b] % mod * inv[a - b] % mod; }
long long pre[2000005];
int main() {
  fra[0] = 1;
  for (int i = 1; i < 2000005; i++) fra[i] = fra[i - 1] * i % mod;
  inv[2000004] = f_pow(fra[2000004], mod - 2);
  for (int i = 2000003; i >= 0; i--) inv[i] = inv[i + 1] * (i + 1) % mod;
  long long n, m;
  pre[0] = 1;
  scanf("%lld %lld", &n, &m);
  for (int i = 1; i <= n; i++) {
    pre[i] = (pre[i - 1] + C(n - i, i)) % mod;
  }
  long long ans = f_pow(m, n);
  for (int i = 0; i < n; i++) {
    ans += f_pow(m, i + 1) * f_pow(2 * m - 1, n - i - 1) % mod;
  }
  printf("%lld\n", ans % mod);
}

### Prompt

Please formulate a Cpp solution 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>
using namespace std;
int mod = 1e9 + 7;
long long f_pow(long long a, long long b) {
  long long res = 1, temp = a;
  while (b) {
    if (b & 1) res = res * temp % mod;
    temp = temp * temp % mod;
    b >>= 1;
  }
  return res;
}
long long fra[2000005];
long long inv[2000005];
long long C(int a, int b) { return fra[a] * inv[b] % mod * inv[a - b] % mod; }
long long pre[2000005];
int main() {
  fra[0] = 1;
  for (int i = 1; i < 2000005; i++) fra[i] = fra[i - 1] * i % mod;
  inv[2000004] = f_pow(fra[2000004], mod - 2);
  for (int i = 2000003; i >= 0; i--) inv[i] = inv[i + 1] * (i + 1) % mod;
  long long n, m;
  pre[0] = 1;
  scanf("%lld %lld", &n, &m);
  for (int i = 1; i <= n; i++) {
    pre[i] = (pre[i - 1] + C(n - i, i)) % mod;
  }
  long long ans = f_pow(m, n);
  for (int i = 0; i < n; i++) {
    ans += f_pow(m, i + 1) * f_pow(2 * m - 1, n - i - 1) % mod;
  }
  printf("%lld\n", ans % mod);
}

```