This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "bits/stdc++.h"
using namespace std;
#ifdef N_N_C
#include "debug.h"
#else
#define cebug(...) "Arya"
#endif
#define int long long
const int N=400;
const int mod=1e9+7;
int n,dp[N][N][2],f[N],inv[N];
int powmod(int a, int k, int m){
   	int ans=1;
    while(k){
        if(k&1) ans=(ans*a)%m;
        a=(a*a)%m;
        k>>=1;
    }
    return ans;
}
int C(int n, int k){
	if(n<k) return 0;
	return f[n]*inv[k]%mod*inv[n-k]%mod;
}
int cal(int i, int task, bool ayase){
	if(i==n+1) return ((!task)&(ayase));
	if(dp[i][task][ayase]!=-1) return dp[i][task][ayase];
	if(!task) return dp[i][task][ayase]=ayase;
	if(ayase) return dp[i][task][ayase]=powmod(n-i+1,task,mod);
	dp[i][task][ayase]=0;
	for(int j=0; j<=task; j++) dp[i][task][ayase]=(dp[i][task][ayase]+((cal(i+1,task-j,j==i)*C(task,j))%mod))%mod;
	return dp[i][task][ayase];
}
void sol(){
	cin>>n;
	if(n==1){
		cout<<1;
		return;
	}
	if(n==2){
		cout<<3;
		return;
	}
	f[0]=1;
	for(int i=1; i<=350; i++) f[i]=(f[i-1]*i)%mod;
	inv[0]=1;
	for(int i=1; i<=350; i++) inv[i]=powmod(f[i],mod-2,mod);
	memset(dp,-1,sizeof(dp));
	cout<<cal(1,n,0);
}
signed main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // freopen(".inp", "r", stdin);
    // freopen(".out", "w", stdout);
    int tt=1;
    //cin>>tt; 
    while(tt--){
    	sol();
    }
    cerr << "\nTime elapsed: " << 1000.0 * clock() / CLOCKS_PER_SEC << " ms.\n";
    return 0;
}
/**  /\_/\
*   (= ._.)
*   / >💖 \>💕
**/
Compilation message (stderr)
zapina.cpp:68:9: warning: "/*" within comment [-Wcomment]
   68 | /**  /\_/\
      || # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |