# [BZOJ2339][HNOI2011]卡农

[BZOJ2339][HNOI2011]卡农

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <stack>
#include <vector>
#include <queue>
#include <cstring>
#include <string>
#include <map>
#include <set>
using namespace std;

int x = 0, f = 1; char c = getchar();
while(!isdigit(c)){ if(c == '-') f = -1; c = getchar(); }
while(isdigit(c)){ x = x * 10 + c - '0'; c = getchar(); }
return x * f;
}

#define maxn 1000010
#define MOD 100000007
#define LL long long
int f[maxn], A[maxn];

void gcd(LL a, LL b, LL& x, LL& y) {
if(!b){ x = 1; y = 0; return ; }
gcd(b, a % b, y, x); y -= a / b * x;
return ;
}
LL Inv(LL a) {
LL x, y;
gcd(a, MOD, x, y);
x = (x % MOD + MOD) % MOD;
return (x % MOD + MOD) % MOD;
}

int main() {

int sum2 = 1;
for(int i = 1; i <= n; i++) {
sum2 <<= 1;
if(sum2 >= MOD) sum2 -= MOD;
}
A[0] = 1;
for(int i = 1; i <= m; i++) A[i] = (LL)A[i-1] * ((sum2 - i + MOD) % MOD) % MOD;
f[1] = f[2] = 0; int tmp = 2;
for(int i = 3; i <= m; i++) {
f[i] = A[i-1] - ((LL)f[i-2] * (i - 1) % MOD) * ((sum2 - i + 1 + MOD) % MOD) % MOD;
if(f[i] < 0) f[i] += MOD;
f[i] -= f[i-1];
if(f[i] < 0) f[i] += MOD;
tmp = (LL)tmp * i % MOD;
}
printf("%d\n", (LL)f[m] * Inv(tmp) % MOD);

return 0;
}