#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef pair< int ,int > PP;
class CyclesNumber {
public :
ll G[ 310 ] [ 310 ] ;
ll MOD = 1E9 + 7 ;
ll power( ll a, ll b) {
ll res = 1 ;
ll crt = a;
while ( b > 0 ) {
if ( b % 2 == 1 ) {
res * = crt;
res % = MOD;
}
b / = 2 ;
crt * = crt;
crt % = MOD;
}
return res;
}
ll F[ 100010 ] ;
ll I[ 100010 ] ;
ll nchoosek( int a, int b) {
if ( b == 0 || a == b) return 1 ;
ll res = F[ a] * I[ b] ;
res % = MOD;
res * = I[ a - b] ;
res % = MOD;
return res;
}
void init( ) {
memset ( G, 0 , sizeof ( G) ) ;
memset ( F, 0 , sizeof ( F) ) ;
memset ( I, 0 , sizeof ( I) ) ;
F[ 0 ] = 1 ;
I[ 0 ] = 1 ;
for ( ll i = 1 ; i <= 1E5 ; i++ ) {
F[ i] = F[ i - 1 ] * i;
F[ i] % = MOD;
I[ i] = power( F[ i] , MOD - 2 ) ;
}
G[ 1 ] [ 1 ] = 1 ;
for ( int i = 2 ; i <= 300 ; i++ ) {
for ( int j = 1 ; j <= i; j++ ) {
ll res = power( j, i) ;
for ( int k = 1 ; k < j; k++ ) {
res + = MOD - ( ( nchoosek( j, k) * G[ k] [ i] ) % MOD) ;
res % = MOD;
}
G[ j] [ i] = res;
}
}
return ;
}
vector < int > getExpectation( vector < int > n, vector < int > m) {
unordered_set< int > X;
unordered_map< int , ll> Y[ 310 ] ;
for ( int i = 0 ; i < n.size ( ) ; i++ ) X.insert ( n[ i] ) ;
init( ) ;
ll A[ 100010 ] ;
ll B[ 100010 ] ;
memset ( A, 0 , sizeof ( A) ) ;
memset ( B, 0 , sizeof ( B) ) ;
A[ 0 ] = 1 ;
for ( ll i = 1 ; i <= 300 ; i++ ) {
ll sum = 0 ;
for ( ll j = 1 ; j <= 1E5 ; j++ ) {
B[ j] = ( j - 1 ) * B[ j - 1 ] ;
B[ j] % = MOD;
B[ j] + = A[ j - 1 ] ;
B[ j] % = MOD;
sum + = B[ j] * I[ j] ;
sum % = MOD;
if ( X.find ( j) ! = X.end ( ) ) Y[ i] [ j] = sum;
}
swap( A, B) ;
memset ( B, 0 , sizeof ( B) ) ;
}
vector< int > ans;
for ( int i = 0 ; i < n.size ( ) ; i++ ) {
ll N = n[ i] ;
ll M = m[ i] ;
ll res = 0 ;
for ( int a = 1 ; a <= M; a++ ) {
res + = Y[ a] [ N] * G[ a] [ M] ;
res % = MOD;
}
res * = F[ N] ;
res % = MOD;
if ( M == 0 ) res = F[ N] ;
ans.push_back ( res) ;
}
return ans;
}
} ;
I2luY2x1ZGUgPGNzdGRsaWI+CiNpbmNsdWRlIDxjY3R5cGU+CiNpbmNsdWRlIDxjc3RyaW5nPgojaW5jbHVkZSA8Y3N0ZGlvPgojaW5jbHVkZSA8Y21hdGg+CiNpbmNsdWRlIDxhbGdvcml0aG0+CiNpbmNsdWRlIDx2ZWN0b3I+CiNpbmNsdWRlIDxzdHJpbmc+CiNpbmNsdWRlIDxpb3N0cmVhbT4KI2luY2x1ZGUgPHNzdHJlYW0+CiNpbmNsdWRlIDxtYXA+CiNpbmNsdWRlIDx1bm9yZGVyZWRfbWFwPgojaW5jbHVkZSA8c2V0PgojaW5jbHVkZSA8dW5vcmRlcmVkX3NldD4KI2luY2x1ZGUgPHF1ZXVlPgojaW5jbHVkZSA8c3RhY2s+CiNpbmNsdWRlIDxmc3RyZWFtPgojaW5jbHVkZSA8bnVtZXJpYz4KI2luY2x1ZGUgPGlvbWFuaXA+Cgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKdHlwZWRlZiBsb25nIGxvbmcgbGw7CnR5cGVkZWYgcGFpcjxpbnQsaW50PiBQUDsKCmNsYXN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