#include <iostream>
#include <cstdio>

#include <utility>

#include <cassert>
#include <ctime>
#include <iomanip>

using namespace std;

const int MAXN = 1e5 + 100;

typedef long long ll;
#define tll(x) static_cast<ll>(x)

typedef pair<int, int> pii;
#define mp make_pair
#define ff first
#define ss second

int N, root;

const int MAXS = MAXN * 800;
struct PBT {
public:
  int c[MAXS][2], v[MAXS], sz[MAXS], h[MAXS];
  int NXT;
  PBT() : NXT(1) {v[0] = -1, sz[0] = 0, h[0] = 0;};
  int upd(int n) {
    if(not(0 < n)) return n;
    sz[n] = sz[c[n][0]] + sz[c[n][1]] + 1;
    h[n] = max(h[c[n][0]], h[c[n][1]]) + 1;
    assert(n != c[n][0] and n != c[n][1]);
    return n;
  }
  int gsz(int n) {
    if(n == 0) return 0;
    return gsz(c[n][0]) + gsz(c[n][1]) + 1;
  }
  void asst(int n) {assert(gsz(n) == sz[n]);}
  int nn(const int& n = -1) {
    assert(NXT < MAXS);
    if(n == 0) return 0;
    if(0 < n) {
      for(int i = 0;i < 2;i++) c[NXT][i] = c[n][i];
      v[NXT] = v[n];
    } else {
      for(int i = 0;i < 2;i++) c[NXT][i] = 0;
      v[NXT] = -1;
    }
    upd(NXT);
    return NXT++;
  }
  int nnr(const int& q) {
    int n = nn();
    v[n] = q;
    return n;
  }
  int L(int& n, int p = 0) {
    assert(c[n][1]);
    int o;
    if(p>1) o = nn(n); else o = n;
    if(p>0) n = nn(c[n][1]); else n = c[n][1];
    c[o][1] = c[n][0];
    upd(c[n][0] = o);
    return upd(n);
  }
  int R(int& n, int p = 0) {
    assert(c[n][0]);
    int o;
    if(p>1) o = nn(n); else o = n;
    if(p>0) n = nn(c[n][0]); else n = c[n][0];
    c[o][0] = c[n][1];
    upd(c[n][1] = o);
    return upd(n);
  }
  bool bal(int& n, bool p = false) {   //here, we assume that n is already a copy
    int q = NXT;
    int b = h[c[n][0]] - h[c[n][1]], s, o = n;
    if(b < -1) {
      assert(s = c[n][1]);
      if(h[c[s][1]] + 1 == h[s]) {
        L(n, p ? 1 : 0);
      } else if(h[c[s][0]] + 1 == h[s]) {
        R(c[n][1], p ? 2 : 0);
        L(n, 0);
      } else assert(false);
    }
    else if(b > 1) {
      assert(s = c[n][0]);
      if(h[c[s][0]] + 1 == h[s]) {
        R(n, p ? 1 : 0);
      } else if (h[c[s][1]] + 1 == h[s]) {
        L(c[n][0], p ? 2 : 0);
        R(n, 0);
      } else assert(false);
    }
    else return false;
    return true;
  }
  int join(int a, int b, bool p = true) {  //here we assume a and b are already copies
    if(a == 0 or b == 0) return a ? a : b;
    if(h[a] < h[b]) {
      c[b][0] = join(a, p ? nn(c[b][0]) : c[b][0], p);
      upd(b);
      bal(b, p);
      return b;
    } else {
      c[a][1] = join(p ? nn(c[a][1]) : c[a][1], b, p);
      upd(a);
      bal(a, p);
      return a;
    }
  }
  int join2(int l, int m, int r) {    //assume all are copies, merges L and R at M
    if(h[l] + 1 < h[r]) {c[r][0] = join2(l, m, nn(c[r][0])); return upd(r);}
    if(h[r] + 1 < h[l]) {c[l][1] = join2(nn(c[l][1]), m, r); return upd(l);}
    c[m][1] = r;
    c[m][0] = l;
    upd(m);
    bal(m, 1);
    return m;
  }
  pii split(int a, int k) {   //always create new nodes, assume a is NOT a copy
    if(k == 0) return mp(0, nn(a));
    assert(0 < k);
    if(sz[c[a][0]] < k) {
      pii q = split(c[a][1], k - sz[c[a][0]] - 1);
      int r = join2(nn(c[a][0]), nnr(v[a]), q.ff);
      return mp(r, q.ss);
    } else {
      pii q = split(c[a][0], k);
      int r = join2(q.ss, nnr(v[a]), nn(c[a][1]));
      return mp(q.ff, r);
    }
  }
  int get(int l, int r) {   //inclusive - exclusive
    while(not(l < N)) l -= N, r -= N;
    while(l < 0) l += N, r += N;

    if(r > N) return join(get(l, N), get(N, r));
    pii f1 = split(root, r);
    pii f2 = split(f1.ff, l);

    return f2.ss;
  }
  void fill(int n, int * a, int * t = new int(0)) {
    if(n == 0) return;
    fill(c[n][0], a, t);
    a[(*t)++] = v[n];
    fill(c[n][1], a, t);
  }
  void pout(int n = root) {
    if(n == 0) return;
    pout(c[n][0]);
    cerr << v[n] << " ";
    pout(c[n][1]);
    if(n == root) cerr << "\n\n";
  }
} pbt;

int M, S;
ll T;

int to[40][MAXN];

void gen() {
  root = 0;
  for(int i = 0;i < N;i++) root = pbt.join(root, pbt.nnr(i), 0);
  for(int i = 1;i < N;i++) {
    int a = pbt.get(i, i + M);
    int b = pbt.get(M - i, N - i);
    assert(pbt.sz[a] == M and pbt.sz[b] == N - M);
    root = pbt.join(a, b);
    //pbt.pout();
    assert(pbt.sz[root] == N);
  }
  pbt.fill(root, to[0]);
}

void run() {
  for(int i = 1;i < 40;i++) {
    for(int j = 0;j < N;j++) {
      to[i][j] = to[i-1][to[i-1][j]];
    }
  }
}

void brute() {
  int q = static_cast<int>(T%N);
  for(;q;q--,T--) {
    if(S < M) S = (S + q)%N;
    else S = (S - q + N)%N;
  }
  assert(T%N == 0);
}

void solve() {
  scanf("%d%lld", &S, &T);
  --S;
  brute();
  int k = T/N;
  for(int i = 0;1 << i < k;i++) {
    if(k&(1<<i)) S = to[i][S];
  }
  printf("%d\n", S + 1);
}

int main() {
  clock_t timer = clock();
  cerr << setprecision(6);

  scanf("%d%d", &N, &M);
  gen();
  run();
  //for(int i = 0;i < N;i++) printf("%d\n", to[0][i]);
  solve();

  cerr << "Time Elapsed: " << static_cast<double>(clock() - timer)/CLOCKS_PER_SEC << "\n";

  return 0;
}


#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
	int n;
	string s, samo("aeiouy");
	cin>>n>>s;
	for(int i = 0;i<n;i++)
	{
		for(int j = 0;j<6;j++)
		{
			if(find(samo.begin(), samo.end(), s[i]) != samo.end())
			{
				while(find(samo.begin(), samo.end(), s[++i]) != samo.end())
				{
					if(s[i-1]>=s[i])
					s.erase(s.begin()+i-1);
					else
					s.erase(s.begin()+i);
					i--;
				}
				i-=2;
			}
		}
	}
	cout<<s;
	return 0;
}


#include<iostream>
#include<cstdio>
#include<vector>
#include<set>
using namespace std;
const int arrx[] = {1,1,1,0,0,-1,-1,-1};
const int arry[] = {0,1,-1,1,-1,1,-1,0};
typedef struct Node node;
struct Node
{
    int x,y;
    Node(int x,int y):x(x),y(y){};
    bool operator < (const  Node& n)const
    {
        if(x != n.x)
            return x < n.x;
        return y < n.y;
    }
};
int main()
{
    ios::sync_with_stdio(false);
    int w1,h1,w2,h2;
    while(cin >> w1 >> h1 >> w2 >> h2)
    {
        vector<node> v;
        for(int i=1;i<=h1;++i)
            for(int j=1;j<=w1;++j)
                v.push_back(Node(i,j));
        for(int i=h1+1;i<=h1+h2;++i)
        	for(int j=1;j<=w2;++j)
        		v.push_back(Node(i,j));
        set<node> s;
        for(int i=0;i!=v.size();++i)
            s.insert(v[i]);
        int cnt = 0;
        for(int i=0;i!=v.size();++i)
        {//8个方向
            for(int j=0;j!=8;++j)
            {
                int newx = v[i].x + arrx[j];
                int newy = v[i].y + arry[j];
                s.insert(Node(newx,newy));
            }
        }
        cout<<s.size()-v.size()<<endl;
    }
}


//From 258
#include<bits/stdc++.h>
using namespace std;
const int mx=1e9;
bool prime[mx];
void SieveOfEratosthenes()
{

    memset(prime, true, sizeof(prime));

    for (int p=2; p*p<=mx; p++)
    {
        if (prime[p] == true)
        {

            for (int i=p*2; i<=mx; i += p)
                prime[i] = false;
        }
    }

}

int main()
{

SieveOfEratosthenes();
   long long  int t,x,ans,y;
    cin>>t;
    while(t--)
    {
        cin>>x>>y;
        ans=(x+y)*(x-y);
        if(prime[ans]) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;

    }

    return 0;
}


#include <iostream>
#include <string>

using namespace std;

const unsigned long long P = 31;

int main() {
	freopen("input.txt", "r", stdin)
	int n;
	string s1, s2;
	cin >> n >> s1 >> s2;
	n--;
	for(int i = 0; i < n; i++) {
	    if (s2[i] == 'N') {
	    	s2[i] = 'S';
	    } else if (s2[i] == 'S') {
	    	s2[i] = 'N';
	    } else if (s2[i] == 'W') {
	     	s2[i] = 'E';
	    } else if (s2[i]=='E') {
	    	s2[i] = 'W';
	    }

	}

	unsigned long long pow = 1;
	unsigned long long h1, h2;
	for (int i = n - 1; i >= 0; i--) {
		h1 = h1 + (s1[i]) * pow;
		h2 = h2 * P + s2[i];
		if (h1 == h2)
		{
			cout << "NO" << endl;
			return 0;
		}
		pow *= P;
	}
	cout << "YES" << endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define long long long
#define endl "\n"

int main() {

    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    long int n, L;
    cin>>n>>L;

    vector<long int> powers(1e8);
    powers[0] = 1;
    for(long int i = 1; i < powers.size(); i++)
        powers[i] = powers[i-1] * 2;

    vector<long int> c(n);
    for (long int i = 0; i < n; i++)
         cin>>c[i];

    for (long int i = 0; i < n - 1; i++)
        c[i + 1] = min(c[i + 1], 2 * c[i]);

    long int ans = LONG_MAX;
    long int sum = 0;

    for (long int i = n - 1; i >= 0; i--) {
        long int need = L / powers[i];
        sum += need * c[i];
        L -= need  * powers[i];
        ans = min(ans, sum + (L > 0) * c[i]);
    }

  cout <<ans<< endl;
  return 0;
}


#include <iostream>
#include <vector>
using namespace std;
int max(int a, int b ){
  return (a>b)?a:b;
}
int main(){
  int n,m;
  cin >> n >> m;
  vector<vector<int> > score(n+1,vector<int>(m+1,0));
  for(int i = 1 ; i <= m ; i++)
    score[0][i]=i-1;
  for(int i = 1 ; i <=n ; i++)
    score[i][0]=i-1;
  for(int i = 1 ; i <= n ; i++){
    for(int j = 1 ; j <= m ; j++){
      score[i][j]=max(score[i-1][j],score[i][j-1]);
    }
  }
  cout << score[n][m]  <<  " " <<  n+m-1-score[n][m] << endl;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    int minutes,hours;
    scanf("%d:%d",& hours,minutes);
    while(1)
    {
        minutes++;
        if(minutes%60==0)
        {
            hours++;
            minutes = minutes % 60;
        }
        hours %= 24;
        if ((hours % 10 == minutes / 10)  &&  (hours/10 == minutes%10 ))
        {
            printf("%02d:%02d" ,hours , minutes);
            break;
        }
    }
    return 0;
}


// THIS IS ABU-HIJLEH ... DONT TRY TO UNDERSTAND MY SOLUTION ... I DONT UNDERSTAND IT :D
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <stdio.h>
typedef long long ll;
using namespace std ;
int main (){
ll a  , b ;
cin >> a >> b ;
int out = 0  ;
int s = b;
int lol=0;string a7aa = to_string(a);
 ll q = pow(10,b*1.0);
 if(q>a)
 {
	cout << a7aa.length()-1;
	return 0;
 }

while(s!=0&&a>9)
{
	if(a%10==0)
	{
		s--;
		lol++;
		//cout << lol << endl;
	}
	else
	{
		out++;
		//cout << out << endl;
	}
	a/=10;
}

if(s!=0&&a<9)
{
	cout << a7aa.length()-1 ;
}else
cout << out;
return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long
#define pb push_back
#define pi 3.14159265
#define M 1000000007
#define MM 998244353
#define arrinput for(int i=0; i<n; i++) cin>>arr[i];
#define arrsum for(int i=0; i<n; i++) sum+=arr[i];
#define for0(i,n) for(int i=0; i<n; i++)
#define for1(i,n) for(int i=1; i<=n; i++)
#define forr(i,n) for(int i=n-1; i>=0; i--)
#define all(v) (v).begin(),(v).end()
#define vsort sort(v.begin(), v.end());
#define vsortdesc sort(v.begin(), v.end(), greater<int>());

/*
int isprime(int n){
    if(n<2 || (!(n&1) && n!=2))
        return 0;
    for(int i=3; i*i<=n; i+=2){
        if(!(n%i))
            return 0;
    }
    return 1;
}

int iscomp(int n){
    for(int i=2;i<=sqrt(n);i++){
        if(n%i==0){
        return 1;}
    }
    return 0;
}

int pw(int a,int b,int p){
    if(b==0)return 1;
    int t=pw(a,b/2,p);
    if(b%2)return (((a*t)%p)*t)%p;
    else return ((t*t)%p);
}

int fact(int a){
    if((a==1)||(a==0))
    return 1;
    else
    return a*fact(a-1);
}*/

int mini(int a[], int n){
   sort(a,a+n);
   return a[0];
}

signed main() {
    IOS

    int n,k,s=0,i;
    cin>>n>>k;
    int b[k],a;
    memset(b,0,sizeof(b));
    for0(i,n){
        cin>>a;
        a=a%k;
        b[a]++;
    }
    for0(i,k)
    s+=b[i]/2;
    for(i=1;i<(k+1)/2;i++){
        s+=(min(b[i],b[k-i-1]))/2;
    }
    if(k%2==0)
    cout<<s*2;
    else
    cout<<s;

    return 0;
}


    #include<bits/stdc++.h>
    using namespace std;
    long long int MOD=1e9+7;
   	//#define MOD 1e9+7
   	//#define ll long long int
    long long int fun(int base, int exp) {
    long long int res=1;
    while(exp>0) {
       if(exp%2==1) res=(res*base)%MOD;
       base=(base*base)%MOD;
       exp/=2;
    }
    return res%MOD;
}
	vector<int>adj[1002];
    int main()
    {
    	ios::sync_with_stdio(false);
    	cin.tie(0);
    	cout.tie(0);
    	long long int n,m;
    	cin>>n>>m;
    	vector<int>a(1e8,0);
    	a[n]=1;
    	bitset<1001>b(m);
    	if(n>1000)
    		cout<<m;
    	else
    	{
    		long long int ans=0;
    		for(int i=0;i<n;i++)
    		{
    			ans+=b[i]*pow(2,i);
    		}
    		cout<<ans;
    	}
    }


#include <map>
#include <cmath>
#include <queue>
#include <stack>
#include <cctype>
#include <cstdio>
#include <vector>
#include <string>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>

using namespace std ;

#define pb push_back
#define del( a ) memset( a , 0 , sizeof ( a ) )
#define loop( i , n ) for( int i=0 ; i<n ; i++ )

char s[1000000009];
int main()
{
    long long x , len ;
    int i ;
    scanf ("%I64d",&x);
    sprintf (s,"%I64d",x);
    len=strlen (s);
    for ( i=1 ; i<=x ; i++ )
    {
        if ( x % i == 0 && len== i )
        {
            printf ("%d\n",i);
            return 0;
        }
    }
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstdio>
#include <cmath>
#include <deque>
#include <set>

using namespace std;

#define MAXN 1024*1024
#define PI acos(-1)
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define sz(a) (int)(a.size())
#define all(a) a.begin(), a.end()
#define R(a) ((a)%mod)

#define ll long long
#define pii pair<int,int>
#define pdd pair<double,double>
#define vi vector<int>
#define vvi vector< vi >

int main (int argc, char const *argv[])
{
  ios_base::sync_with_stdio(0); cin.tie(0);
  long long int n,g=0,r=0,y=0,b=0,j;
  string s;
  cin >> s;
  n = s.size();
  int flag = 0;
  for(int i = 0; i < n; ++i){
    if(s[i] == '!') flag = 1;
  }
    int now=0;
  if(flag == 0){
    cout << "0 0 0 0" << endl;
    return 0;
  }
  else{
    for(int i = 0; i < n; ++i){
      j = 4;
      if(now > 0){
        j =4*now;
        i--;
      }
      if(s[i] == '!'){
        if(i+j < n  && s[i+j] == 'Y'){
          ++y;
          s[i] = 'Y';
        }
        else if(i+j < n  && s[i+j] == 'G'){
          ++g;
          s[i] = 'G';
        }
        else if(i+j < n  && s[i+j] == 'B'){
          ++b;
          s[i] = 'B';
        }
        else if(i+j < n  && s[i+j] == 'R'){
          ++r;
          s[i] = 'R';
        }
        else now++;
      }
      for(int i = n-1; i >= 0; --i){
        j = 4;
        if(now > 0){
          ++i;
          j=4*now;
        }
        if(s[i] == '!'){
          if(i-j < n  && s[i-j] == 'Y'){
            ++y;
            s[i] = 'Y';
            now = 0;
          }
          else if(i-j < n  && s[i-j] == 'G'){
           ++g;
           s[i] = 'G';
           now = 0;
          }
          else if(i-j < n  && s[i-j] == 'B'){
            ++b;
            s[i] = 'B';
            now= 0;
          }
          else if(i-j < n  && s[i-j] == 'R'){
           ++r;
           s[i] = 'R';
           now = 0;
          }
          else ++now;
        }
      }
    }
    //cout << s << endl;
    cout << r << " " << b << " " << y << " "<< g << endl;
  }
}


#include <iostream>
using namespace std;

int main() {
	//freopen ("f.in", "r", stdin);
	//freopen ("f.out", "w", stdout);
	int n, a;
	while (true) {
	cin >> n >> a;
	cout << (a%2?a/2+1:n/2-a/2);
	}
	return 0;
}


#include <iostream>

using namespace std;

int main(){
	int count, number;
	cin >> count;
	cin >> number;
	int seconds = 0;
	if (number % 2 == 0) {
		seconds = (count - number) / 2;
	}
	else {
		seconds = (number - 1) / 2;
	}
	seconds++;
	cout << seconds;
	return 1;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int x=1234567;
const int y=123456;
const int z=1234;
int n;
int main() {
	cin>>n;
	for(int a=0; a*x<=n; a++)
		for(int b=0; a*x+b*y<=n; b++)
			if((n-a*x-b*y)%z==0)
				return printf("YES");
	return printf("NO");
}


#include <bits/stdc++.h>
#define ll long long int
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    vector<int>v;
    ll A,B,C,D,count=0,i,j,k,temp;

    cin>>A>>B>>C>>D;

    for(i=A;i<=B;i++){
        for(j=B;j<=C;j++){
        	v.push_back(i+j);
        }
    }
    sort(v.begin(),v.end());
    j=C;
    i=0;
    while(i<v.size() && j<=D){
        if(v[i]<=j){
            i++;
        }
        else{
            count+=v.size()-i;
            j++;
        }
    }

    cout<<count;
	return 0;
}


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

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

string add(string &s, int a){
	int used[26] = {}, n = s.length();
	REP(i,a){
		used[s[n-1-i] - 'a'] = 1;
	}
	REP(i,26){
		if (!used[i]){
			s += ('a' + i);
			a--;
		}
		if (a == 0) break;
	}
	return s;
}

int main() {
	ll a, b, l, r;
	cin >> a >> b >> l >> r;
	l--;
	r--;
	if (r - l + 1 > 2 * (a + b)){
		if (a <= b)	cout << a + 1 << endl;
		else cout << 2 * a - b << endl;
		return 0;
	}
	if (l / (a + b) > 1){
		int x = l / (a + b) - 2;
		l -= x * (a + b);
		r -= x * (a + b);
	}
	int ans = 10000;
	for (char c1 = 'a'; c1 <= 'z'; c1++){
		for (char c2 = 'a'; c2 <= 'z'; c2++){
			for (char c3 = 'a'; c3 <= 'z'; c3++){
				for (char c4 = 'a'; c4 <= 'z'; c4++){
					string s;
					REP(i,a) s += ('a' + i);
					REP(i,b) s += c1;
					s = add(s, a);
					REP(i,b) s += c2;
					s = add(s, a);
					REP(i,b) s += c3;
					s = add(s, a);
					REP(i,b) s += c4;
					s = add(s, a);
					set<char> st;
					// cout << s << endl;
					FOR(i,l,r) st.insert(s[i]);
					ans = min(ans, (int)st.size());
				}
			}
		}
	}
	cout << ans << endl;
	return 0;
}


#include <algorithm>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <iomanip>
#include <stdio.h>
#include <string>
#include <queue>
#include <cmath>
#include <stack>
#include <map>
#include <set>
#define M 1001000
#define LL __int64
#define INF 0x3f3f3f3f

using namespace std;

int main()
{
    int n, a, b, c;
    int a1, b1, c1;
    int i;
    int dp[5000];
    while(cin >>n>>a>>b>>c)
    {
        a1 = max(a,max(b, c));
        c1 = min(a,min(b, c));
        b1 = a+b+c-a1-c1;
        memset(dp , 0 , sizeof(dp));
        dp[0] = 1;
        for(i = 0; i <= n; i++)
        {
            if(dp[i]!=0)
            {
                dp[i+a1] = max(dp[i]+1, dp[i+a1]);
                dp[i+b1] = max(dp[i]+1, dp[i+b1]);
                dp[i+c1] = max(dp[i]+1, dp[i+c1]);
            }
        }
        cout <<dp[n]-1<<endl;
    }
    return 0;
}


#include<iostream>
using namespace std;
const int n=3;
int main()
{
	void  display(char pass[n][n]  );
	char pass[n][n]={{'.','.','.'},
	                 {'.','.','.'},
	                 {'.','.','.'}};
	display(pass);
	int r,c;char ch;

	do{
	cout<<" enter row & coloum";
	cin>>r;cin>>c;
	pass[r-1][c-1]='x';
	cout<<"enter y to repet";
	cin>>ch;
	}while(ch=='y');
	display(pass);
	if(pass[1][0]=='x'|pass[1][2]=='x'|pass[1][1]=='x')
	{ cout<<"NO";}
	else
	    cout<<"YES";

}
  void display(char pass[n][n]  )
    {
         cout<<"\n";
        for(int row =0;row<3;row++){

            cout<<"";{
            for(int column =0;column<3;column++)
                cout<<pass[row][column] << " ";
                }
        cout<<"\n";
      cout<<"\n";

    }

}


#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef pair<int,int> pii;
typedef pair<lli,lli> pll;
template<typename T>
int sz(const T &a){return (int)a.size();}
struct node{
    node* left,*right;
    lli data;
    node(int a){
        left=NULL,right=NULL,data=a;
    }
    void go(){
        if(data>=2){
            node *te= new node(data/2);
            node *te2= new node(data/2);
            if(left)left->right=te;
            if(right)right->left=te2;
            te->left=left,te->right=this;
            te2->left=this,te2->right=right;
            left=te,right=te2;
            data%=2;
            right->go(),left->go();
        }
    }
};
node te(0);
int main(){
    cin.tie(NULL);
    ios_base::sync_with_stdio(false);
    lli n,l,r;
    cin>>n>>l>>r;
    l-=1,r-=1;
    node* a=&te;
    a->data=n;
    a->go();
    while(a->left)a=a->left;
    for(int i=0;i<l;i++){
        a=a->right;
    }
    int am=0;
    for(int i=l;i<=r;i++){
        if(a->data==1)am++;
        a=a->right;
    }
    printf("%d\n",am);
    return 0;
}


#include <iostream>

using namespace std;
int add(int a){
	a = (a*(a+1))/2;
	return a;
}
int main(){
	int a;cin>>a;
	int b=0,d;
	int i=1;
	b += add(i);
	bool val=true;
	while(val){
		d = b + add(i+1);
		if(d<a){
			i++;
			b += add(i);
		}
		else if(d>a){
			val = false;
		}
	}
	cout<<i;
	return 0;
}


#include <bits/stdc++.h>
using namespace::std;

int main()
{
    long width = 0;
    long height = 0;
    long r = 0;
    cin >> width >> height;

    while(width > 0 && height > 0)
    {
        ++r;
        long subtraction = width - height;
        if(subtraction > height)
        {
            width = subtraction;
        }
        else
        {
            long temp = height;
            height = subtraction;
            width = temp;
        }
    }

    std::cout << r << std::endl;
    return 0;
}


#include <cassert>
#include <cstdio>
#include <ctime>
#include <cstdlib>
#include <climits>
#include <cstddef>
#include <cctype>
#include <cmath>
#include <cstring>
#include <fstream>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <iterator>
#include <numeric>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <bitset>
#include <list>
#include <string>
#include <functional>
#include <utility>
using namespace std;
typedef long long llint;
vector<int> f(const std::string& s) {
    vector<int> ret(s.size() + 1, 0);
    for (auto i = 0; i < s.size(); ++i) {
        ret[i + 1] = ret[i] + (s[i] == 'A' ? 1 : 0);
    }
    return ret;
}
vector<int> g(const std::string& s) {
    vector<int> ret(s.size() + 1, 0);
    for (auto i = 0; i < s.size(); ++i) {
        if (s[i] == 'A') {
            ret[i + 1] = ret[i] + 1;
        }
    }
    return ret;
}
int main() {
    string s, t;
    int q;
    cin >> s >> t >> q;
    auto sa = f(s);
    auto ta = f(t);
    auto se = g(s);
    auto te = g(t);
    while (q--) {
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        int x = b - a + 1 - (sa[b] - sa[a - 1]);
        int y = d - c + 1 - (ta[d] - ta[c - 1]);
        if (x > y) {
            cout << 0;
        } else {
            if ((y - x) % 2 != 0) {
                cout << 0;
            } else {
                int zs = min(b - a + 1, se[b]), zt = min(d - c + 1, te[d]);
                int z = (y - x) / 2;
                if (zs >= zt) {
                    cout << (z > 0 ? 1 : (zs % 3 == zt % 3 ? 1 : 0));
                } else {
                    cout << 0;
                }
            }
        }
    }
    cout << endl;
    return 0;
}


#include <iostream>
using namespace std;
typedef long long LL;

const int MOD=1000000007;

LL fac[1100000],inv[1100000],f[1100];
LL ret=0;
int n,m,k,i,j;

LL pow(int a,int n){
        if (!n) return 1LL;
        LL ret=pow(a,n/2);
        ret=ret*ret%MOD;
        if (n%2) ret=ret*a%MOD;
        return ret;
}

LL com(int n,int m){
        return fac[n]*inv[m]%MOD*inv[n-m]%MOD;
}

LL calc(int x){
        if (f[x]!=-1) return f[x];
        LL ret=0,F=1;
        for(int i=x;i;i--){
                ret+=pow(i,n)*com(x,i)%MOD*F;
                ret%=MOD;
                F=-F;
        }
        if (ret<0) ret+=MOD;
        f[x]=ret;
        return ret;
}

int main(){
        cin>>n>>m>>k;
        if (m==1) cout<<pow(k,n)<<endl,return 0;
        fac[0]=inv[0]=1;
        for(i=1;i<=k;i++) fac[i]=fac[i-1]*i%MOD,inv[i]=inv[i-1]*pow(i,MOD-2)%MOD;
        for(i=0;i<=n;i++) f[i]=-1;
        for(i=0;i<=k&&i<=n;i++)for(j=0;i+j+j<=k&&i+j<=n;j++){
                LL tmp=calc(i+j);
                //cout<<i<<' '<<j<<' '<<ret<<endl;
                ret+=tmp*tmp%MOD*com(k,i)%MOD*com(k-i,j)%MOD*com(k-i-j,j)%MOD*pow(i,n*(m-2))%MOD;
                //cout<<i<<' '<<j<<' '<<ret<<endl<<endl;
                ret%=MOD;
        }
        cout<<ret;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi 2*acos(0.0)
#define f first
#define s second
#define pb push_back
#define gap ' '
#define fastio {ios_base::sync_with_stdio(false);cin.tie(NULL);}
#define mod 1000000007
#define INF 1e18+100
string cmp[1000005];
void Make()
{
    for(int i=0;i<=999999;i++)
    {
        int I=i;
        for(int j=0;j<6;j++)
        {
            cmp[i]+=(I%10)+'0';
            I/=10;
        }
    }
}
int main()
{
    fastio;
    Make();
    string s;
    cin>>s;
    int res=0;
    for(int i=0;i<=999999;i++)
    {
        int sum=0;
        for(int j=0;j<3;i++)
        {
            sum+=(cmp[i][j]-'0');
        }
        for(int j=3;j<6;j++)
        {
            sum-=(cmp[i][j]-'0');
        }
        if(!sum){
            int tmp=0;
            for(int j=0;j<6;j++) if(s[i]!=cmp[i][j]) tmp++;
            res=min(res,tmp);
        }
    }
    cout<<res<<endl;
}


#include <iostream>
#include <cstring>

using namespace std;
int a[105];
int main()
{
    while(1){
        int temp,sum = 0;
        memset(a,0,sizeof(a));
        for(int i = 1;i <= 5;i ++){
            cin>>temp;
            sum += temp;
            a[temp]++;
        }
        for(int i = 100;i >= 0;i --){
            if(a[i] >= 3){
                sum -= i*3;
                break;
            }
            if(a[i] == 2){
                sum -= i*2;
                break;
            }
        }
        cout<<sum<<endl;
    }
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <utility>
#include <cmath>

//#define abs(x) ( (x) > 0 ? (x) : -(x))

using namespace std;

int main ()
{
	int x, y;
	int ok = 0;
	int c = 0;
	cin >> x >> y;
	if ((x == 0) || (y == 0)){	cout << "black";return 0;}
	if ((x < 0) && (y < 0)) {x = abs(x); y = abs(y); }
	if ((x < 0) || (y < 0)){ ok = 1; x = abs(x); y = abs(y);}
	x = abs(x);
	y = abs(y);
	c = max (x, y);
	if (ok == 0) {
		if ((c % 2) == 1){	cout << "white";return 0;}
		else		{	cout << "black";return 0;}
	}
	else if (ok == 1) {
		for (;;);
		if ((c % 2) == 0){	cout << "white";return 0;}
		else		{	cout << "black";return 0;}
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;
int n,d,c=1;
int temp=5;
int main()
{
    cin>>n>>d;
    int t[n];
    for(int i=1;i<=n;i++) {
            cin>>t[i];
    temp+=t[i];
  if(i!=n) {temp+=10;
     c+=2;}
     if(i=n||temp<d){
        int diff=d-temp;
    while(diff>=5){
            c++;
            diff-=5;
        }
     }

    }
    if(temp<=d) cout<<c;
    else cout<<"-1";
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
 int songs=0,time=0,stop=0,jokes=0;
 int duration=0;
 cin>>songs>>time;
 for(int i=0; i<songs; i++)
 {
 cin>>duration;
 time=time-duration;
 stop=time;
 do{
    time=time-5;
    jokes++;
 }while(stop-10==time || time!=0);
 }
 if(time<0 || jokes<0){
  cout<<-1;
 }
 else{
    cout<<jokes;
 }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
typedef pair<ll,ll> pll;
typedef double ld;

ld revs,a,b,c,d,C,totdist;
const ld pi=atan(1)*4;

int n,r,v,s,f;

ld distcovered(ld t) {
	return max(r*(t+sin(t)),r*(t-sin(t)));
}

int main() {
	cout << fixed << setprecision(8);
	cin >> n >> r >> v;
	for (int c=0;c<n;c++) {
		//cin >> s >> f;
		scanf("%d%d",&s,&f);

		a=f-s;
		a=a/2;

		ld up,low;
		low=0;up=a/r+2*pi;
		for (int c=0;c<200;c++) {
			ld mid=(low+up)/2;
			b=distcovered(mid);
			if (b == a) break;
			else if (b>a) up=mid;
			else low=mid;
		}
		ld mid=(low+up)/2;

		ld speed=(ld)v/r;
		ld time=mid/speed*2;
		//cout << time << endl;
		printf("%.8f",time);

		//totdist
	}
	return 0;
}


#include <iostream>
using namespace std;
int main()
{
	int x, y;
	cin >> x >> y;
	int resX = x;
	int resY = y;
	if (y - x == 1 || x - y == 1)
	{
		cout << "Yes";
		return 0;
	}
	while (true)
	{
		while (resX > resY)
		{
			if ((resX == 5 && resY == 2) || (resX == 4 && resY == 3) || (resX == 3 && resY == 4))
			{
				cout << "Yes" << endl;
				return 0;
			}
			resX--;
			resY++;
			//cout << "ResX: " << resX << " ResY: " << resY << endl;
		}
		//cout << "----" << endl;
		x -= 2;
		resX = x;
		resY = y;
		if (resX < 0 || resY < 0)
		{
			cout << "No" << endl;
			return 0;
		}

	}
}


#include<bits/stdc++.h>

using namespace std;
int main()
{
    int n,r;
    cin>>n;
    string a=" ";
    if(n==0)
    {
        cout<<"O-|-OOOO";
        return 0;
    }
    while(n)
    {
        r=n%10;
        if(r==5)
        {
            cout<<"-O|-OOOO"<<endl;
        }
       else  if(r<5)
        {
                int b=5-r;
                a="O-|";
                while(r--)
                {
                    a+='O';
                }
                if(b)
                {
                    a+='-';
                    b--;
                    while(b--)
                    {
                       a+='O' ;
                    }
                }
             cout<<a<<endl;
        }
        else if(r>5)
        {
                int s=n-5;
                int r=5-s;
                string  str="-O|";
                while(s--)
                {
                    str+='O';
                }
                if(r)
                {
                       str+='-';
                       r--;
                       while(r--)
                       {
                           str+='O';
                       }
                }
                cout<<str<<endl;
        }

        n=n/10;
    }
    return 0;
}


#include <bits/stdc++.h>
const int inf = 0x3f3f3f3f;
int l, mxc, mxx;
char ch[53];
int f[53][53][511][2];
int dp(int pos, int c, int x, int delta) {
    if (pos == l) return c ? inf : 0;
    if (c > mxc || c < -mxc || x > mxx || x < -mxx) return inf;
    if (!(~f[pos][c + mxc][x + mxx][(delta == 1)])) f[pos][c + mxc][x + mxx][(delta == 1)] = min(dp(pos, c, x + delta, delta) + l - pos, min(dp(pos + 1, c * 10 + ch[pos + 1] - x, x, 1), dp(pos + 1, c * 10 + ch[pos + 1] - x, x, -1)));
    return f[pos][c + mxc][x + mxx][(delta == 1)];
}
int main() {
    scanf("%s", ch + 2), l = strlen(ch + 2) + 1, ch[1] = 0, mxx = 5 * l, mxc = mxx / 10 + 1;
    for (int i = 2; i <= l; ++i) ch[i] ^= 48;
    memset(f, -1, sizeof(f)), printf("%d", dp(0, 0, 0, 1));
}


#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <cmath>
#include <algorithm>
#include <cassert>
#include <time.h>
#include <random>
#include <string>
#include <numeric>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef string str;

#define pb push_back
#define ppp pop_back
#define pii pair<int,int>
#define fi first
#define se second
#define stie std::tie
#define vec vector
#define forn(i, l, r) for (int i=l; i<=r; i++)
#define forb(i, r, l) for (int i=r; i>=l; i--)
#define emp empty
#define beg begin
#define ins insert
#define cle clear
#define era erase
#define que queue
#define pque priority_queue
#define mset multiset
#define deq deque
#define sta stack
#define con const
#define rsz resize
#define ass assign
#define lowb lower_bound
#define uppb upper_bound

template <class T> void mini(T& a, T b) { a = min(a, b); }
template <class T> void maxi(T& a, T b) { a = max(a, b); }
template <class T> T gcd(T a, T b) { return b == 0 ? a : gcd(b, a % b); }
template <class T1, class T2>
ostream& operator<<(ostream& os, pair<T1, T2> const& a) { return os << "[" << a.first << ", " << a.second << "]"; }
template <class Ch, class Tr, class Container>
basic_ostream<Ch, Tr>& operator<<(basic_ostream<Ch, Tr>& os, Container const& a) { os << "{ "; for (auto& i : a) os << i << " "; return os << "}"; }
template <class T> void out(T a) { cout << a << endl; }
template <class T, class... Args> void out(T a, Args... args) { cout << a << " "; out(args...); }
template <class T> void out( std::initializer_list<T> a) { for (auto i : a) { cout << i << " "; } cout << endl; }
template <class T> void out(vector<vector<T>> a) { for (vector<T> i : a) out(i); }
template <class T> void out_(T a[], int l, int r) { for (int i = l; i <= r; i++) cout << a[i] << " "; cout << endl; }
void out() { cout << "OK" << endl; }
template <class T> void sort(vector<T>& a) { sort(a.begin(), a.end()); }
template <class T> void rever(vector<T>& a) { reverse(a.begin(), a.end()); }
template <class T> void uniq(vector<T>& a) { sort(a); a.erase(unique(a.begin(), a.end()), a.end()); }
template <class T> vector<T> set_int(vector<T> a, vector<T> b) { sort(a); sort(b); vector<T> res;
set_intersection(a.begin(), a.end(), b.begin(), b.end(), back_inserter(res)); return res; }
clock_t start_time; void start_timer() { start_time = clock(); }
double get_time() { return (double)(clock() - start_time) / CLOCKS_PER_SEC; }
#if __SIZEOF_INT128__ >= 16
typedef __int128 LL;
istream& operator>>(istream& in, __int128& a) { int64_t b; in >> b; a = b; return in; }
ostream& operator<<(ostream& out, const __int128 a) {
    unsigned __int128 b = a < 0 ? -a : a; char buf[128]; char* c = end(buf); do { --c; *c = "0123456789"[b % 10]; b /= 10; } while (b);
    if (a < 0) { --c; *c = '-'; } int64_t len = end(buf) - c; out.rdbuf()->sputn(c, len); return out;
}
#endif

template<int m>
struct mint {
    int x = 0;
    mint(int64_t a = 0) { if (a < 0) a = a % m + m; if (a >= m) a %= m; x = static_cast<int>(a); }
    friend istream& operator>>(istream& in, mint& a) { int64_t y; in >> y; a = y; return in; }
    friend ostream& operator<<(ostream& out, mint a) { return out << a.x; }
    explicit operator int() const { return x; }
    static int mod_inv(int a, int mod = m) {
        // https://en.wikipedia.org/wiki/Extended_Euclidean_algorithm#Example
        int g = mod, r = a, z = 0, y = 1;
        while (r != 0) { int q = g / r; g %= r; swap(g, r); z -= q * y; swap(z, y); }
        return z < 0 ? z + mod : z;
    }
    mint inv() const { return mod_inv(x, m); }
    friend mint binpow(mint a, int64_t b) { mint res = 1; while (b) { if (b & 1) res *= a; b >>= 1; a *= a; } return res; }
    mint pow(int64_t b) const { return binpow(*this, b); }
    mint operator-() const { return x ? m - x : 0; }
    mint& operator+=(const mint& a) { x += a.x; if (x >= m) x -= m; return *this; }
    mint& operator-=(const mint& a) { x -= a.x; if (x < 0) x += m; return *this; }
    static unsigned fast_mod(uint64_t x, unsigned mod = m) {
        return x % mod;
    }
    mint& operator*=(const mint& a) { x = fast_mod((uint64_t) x * a.x); return *this; }
    mint& operator/=(const mint& a) { return *this *= a.inv(); }
    friend mint operator+(mint a, const mint& b) { return a += b; }
    friend mint operator-(mint a, const mint& b) { return a -= b; }
    friend mint operator*(mint a, const mint& b) { return a *= b; }
    friend mint operator/(mint a, const mint& b) { return a /= b; }
    mint& operator++() { x = x == m - 1 ? 0 : x + 1; return *this; }
    mint& operator--() { x = x == 0 ? m - 1 : x - 1; return *this; }
    mint operator++(int) { mint a = *this; ++*this; return a; }
    mint operator--(int) { mint a = *this; --*this; return a; }
    bool operator==(const mint& a) const { return x == a.x; }
    bool operator!=(const mint& a) const { return x != a.x; }
};

con int mod = 998244353;

#define mi mint<mod>

con int N = 405;
con int K = 26;

mi dp[N][N][N][3][3];
int c[K];

void Solve() {
    int n;
    cin >> n;
    forn(i, 0, K-1) {
        cin >> c[i];
    }
    mi ans = mi(26) * mi(26) * mi(25).pow(n - 2);
    /*
    dp[1][1][0][2][0] = 1;
    dp[1][0][1][2][1] = 1;
    dp[1][0][0][2][2] = K - 2;
    */

    dp[2][2][0][0][0]= 1;
    dp[2][1][1][0][1] = 1;
    dp[2][1][1][1][0] = 1;
    dp[2][0][2][1][1] = 1;
    dp[2][1][0][2][0] = K - 2;
    dp[2][1][0][0][2] = K - 2;
    dp[2][0][1][2][1] = K - 2;
    dp[2][0][1][1][2] = K - 2;
    dp[2][0][0][2][2] = (K - 2) * (K - 2);

    forn(i, 2, n) {
        forn(a, 0, n) {
            forn(b, 0, n) {
                forn(x, 0, 2) {
                    forn(y, 0, 2) {
                        mi cur = dp[i - 1][a][b][x][y];
                        if (x != 0) {
                            dp[i][a + 1][b][y][0] += cur;
                        }
                        if (x != 1) {
                            dp[i][a][b + 1][y][1] += cur;
                        }
                        if (x == 2) {
                            dp[i][a][b][y][2] += cur * mi(K - 3);
                        }
                        else {
                            dp[i][a][b][y][2] += cur * mi(K - 2);
                        }
                    }
                }
            }
        }
    }
    forn(i, 0, K-1) {
        mi cur = 0;
        forn(a, 0, n) {
            forn(b, 0, n) {
                forn(x, 0, 2) {
                    forn(y, 0, 2) {
                        if (a > c[i]) {
                            cur += dp[n][a][b][x][y];
                        }
                    }
                }
            }
        }
        ans -= cur;
    }
    forn(i, 0, K-1) {
        forn(j, i+1, K-1) {
            mi cur = 0;
            forn(a, 0, n) {
                forn(b, 0, n) {
                    forn(x, 0, 2) {
                        forn(y, 0, 2) {
                            if (a > c[i] && b > c[j]) {
                                cur += dp[n][a][b][x][y];
                            }
                        }
                    }
                }
            }
            ans += cur;
        }
    }
    out(ans);
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef LOCAL
    freopen("usr/share/man/man1/input.txt", "r", stdin);
#endif
    start_timer();
    Solve();
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
long long a,b,mod,d[40001],cnt,sum[2505][55];
long long t[2505][55];
int main()
{
	scanf("%lld%lld",&a,&mod);
	if(a>40)
	{
		for(int i=1;i<=1000000000;i++)
		{
			a++;
			a=a*2;
			a%=mod;
		}
		printf("%lld",a);
		return 0;
	}
	if(a==2||a==1)
	{
		printf("0\n");
		return 0;
	}
	d[1]=1;
	d[2]=1;
	cnt=2;
	long long ls=0;
	for(int i=3;i<=a;i++)
	{
		for(int j=1;j<=i;j++)
		{
			for(int k=1;k<=cnt;k++)
			{
				t[j][k+j-1]=d[k];
			}
		}
		for(int j=1;j<=cnt+i-1;j++)
		{
			d[j]=0;
			for(int k=1;k<=i;k++)
			{
				d[j]+=t[k][j];
				d[j]%=mod;
			}
//			cout<<d[j]<<" ";
		}
		cnt=cnt+i-1;
		memset(sum,0,sizeof(sum));
		for(int j=i;j>=1;j--)
		{
			for(int k=1;k<=cnt;k++)
			{
				sum[j][k]=sum[j][k-1]+sum[j+1][k]-sum[j+1][k-1]+t[j][k];
				sum[j][k]%=mod;
			}
		}
		long long ann=ls*i%mod;
		for(int j=1;j<i;j++)
		{
			for(int k=1;k<=cnt;k++)
			{
//				cout<<t[j][k]<<" ";
				ann+=sum[j+1][k-1]*t[j][k]%mod;
				ann%=mod;
			}
//			cout<<ann<<"\n";
		}
		ls=ann;
	}
	cout<<ls<<" ";
	printf("%lld",(ls%mod+mod)%mod);
	return 0;
}#include<bits/stdc++.h>
using namespace std;
long long a,b,mod,d[40001],cnt,sum[2505][55];
long long t[2505][55];
int main()
{
	scanf("%lld%lld",&a,&mod);
	if(a>40)
	{
		for(int i=1;i<=1000000000;i++)
		{
			a++;
			a=a*2;
			a%=mod;
		}
		printf("%lld",a);
		return 0;
	}
	if(a==2||a==1)
	{
		printf("0\n");
		return 0;
	}
	d[1]=1;
	d[2]=1;
	cnt=2;
	long long ls=0;
	for(int i=3;i<=a;i++)
	{
		for(int j=1;j<=i;j++)
		{
			for(int k=1;k<=cnt;k++)
			{
				t[j][k+j-1]=d[k];
			}
		}
		for(int j=1;j<=cnt+i-1;j++)
		{
			d[j]=0;
			for(int k=1;k<=i;k++)
			{
				d[j]+=t[k][j];
				d[j]%=mod;
			}
//			cout<<d[j]<<" ";
		}
		cnt=cnt+i-1;
		memset(sum,0,sizeof(sum));
		for(int j=i;j>=1;j--)
		{
			for(int k=1;k<=cnt;k++)
			{
				sum[j][k]=sum[j][k-1]+sum[j+1][k]-sum[j+1][k-1]+t[j][k];
				sum[j][k]%=mod;
			}
		}
		long long ann=ls*i%mod;
		for(int j=1;j<i;j++)
		{
			for(int k=1;k<=cnt;k++)
			{
//				cout<<t[j][k]<<" ";
				ann+=sum[j+1][k-1]*t[j][k]%mod;
				ann%=mod;
			}
//			cout<<ann<<"\n";
		}
		ls=ann;
	}
	cout<<ls<<" ";
	printf("%lld",(ls%mod+mod)%mod);
	return 0;
}


#include <bits/stdc++.h>
#define maxn 20010
using namespace std;
int n, mod, w[2][2 * maxn + 5], s[2][2 * maxn + 5], ans[55];
int main()
{
	cin >> n >> mod;
	w[0][maxn] = s[0][maxn] = 1;
	for (int i = maxn; i <= 2 * maxn; i ++ ) s[0][i] = 1;
	for (int i = 1; i <= n; i ++ )
	{
		int curs = 1, I = i & 1, J = I ^ 1;
		memset(w[I], 0, sizeof(w[I])), memset(s[I], 0, sizeof(s[I]));
		for (int u = i * (i - 1) / 2, j = -u + B; j <= u + B; j ++ ) w[I][j] = curs, curs = (0ll + curs - s[J][j] + s[J][j - i] + s[J][j + i] - s[J][j] + 2ll * mod) % mod;
		for (int j = B - i * (i - 1) / 2, v = (i + 2) * (i + 1) / 2 + B;j <= v; j ++ ) s[I][j] = (s[I][j - 1] + w[I][j]) % mod;
		for (int j = 1; j < i; j ++ ) ans[i] = (ans[i] + 1ll * (s[J][(i + 1) * i / 2 + B] - s[J][j + B] + mod) % mod * (i - j)) % mod;
	}
	for (int i = 2; i <= n; i ++ ) ans[i] = (ans[i] + 1ll * i * ans[i - 1]) % mod;
	cout << ans[n] << endl;
}


#include<bits/stdc++.h>
using namespace std;
int f[int(4e6) + 1];
long long g[int(4e6) + 1];
int main() {
    int n, m;
    cin >> n >> m;
    f[1] = 1
    for (int i = 2; i <= n; i++) {
        f[i] = ((f[i - 1] << 1) + g[i]) % m;
        if (i == 2) f[i] = 2;
        if (f[i] < 0) f[i] += m;
        for (int k = 2; k * i <= n; k++) {
            g[k * i] += f[i] - f[i - 1];
        }
    }
    cout << f[n] << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int M=998244353,B=720720;
int g[B], ng[B];
long long result;
long long s;
int n,a,x,y,k,MOD;

int main () {
    cin>>n>>a>>x>>y>>k>>MOD;
	for(int i=0;i<(1<<k);i++) {
		int sum=0,mul=1;
		for(int j=0;j<k;j++) {
			if((i>>j)&1) sum++;
			else mul = (1ll*mul*(n-1))%M;
		}
		s = (s+sum*mul)%M;
	}
	for(int i=0;i<n;i++) {
		if(i) a=(1ll*a*x+y)%MOD;
		result = (result + 1ll*s*(a-(a%B)))M;
		g[a%B]++;
	}
	for(int i=0;i<B;i++) if(g[i]) {
		result = (result + 1ll*g[i]*i)%M;
	}
	for(int i=2;i<=k;i++) {
		result = (result*n)%M;
		memset(ng,0,sizeof(ng));
		for(int j=0;j<B;j++) {
			new_g[j%i] = (new_g[j%i]+g[j])%M;
			new_g[j] = (1ll*new_g[j] + 1ll*g[j]*(n-1))%M;
		}
		for(int j=0;j<B;j++) {
			result = (result + 1ll*new_g[j]*j)%M;
		}
		memcpy(g,ng,sizeof(ng));
	}
	printf("%lld\n", result);
}


//Author = Anirudh Srikanth (yeetholmes619) [B20CS006]

#include<bits/stdc++.h>
#define curtime             chrono::high_resolution_clock::now()
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#define timedif(start,end)  chrono::duration_cast<chrono::nanoseconds>(end - start).count()
using namespace std;
#define RESET   "\033[0m"
#define BR   "\033[1m\033[31m"      /* Bold Red */
#define BG   "\033[1m\033[32m"      /* Bold Green */
#define BB    "\033[1m\033[34m"      /* Bold Blue */
#define ll long long
#define ld long double
#define INF 1000000007
#define pb push_back
#define pf push_front
#define fu(i,n) for(int i = 0; i < n; i++)
#define fu1(i,n) for(int i = 1; i <= n; i++)
#define fd(i,n) for(int i = n-1; i > -1; i--)
#define fd1(i,n) for(int i = n ; i >= 1; i--)
#define vi vector<int>
#define vs vector<string>
#define pi pair<int,int>
#define umap unordered_map
#define cinarr(a) for(auto &zz:a)cin>>zz
#define mp make_pair
#define allvec(v) v.begin(), v.end()
/**
 * I/O
 **/
#define int long long
#define output(value) cout << value << "\n"
#define error(errorString) cout << BR << errorString << RESET<< "\n"
#define info(infoString) cout << BB << infoString << RESET << "\n"
#define success(successString) cout << BB << successString << RESET << "\n"
#define allarr(a,n) a, a+n
#define MOD 1000000007
// precedence order :- double > float > long long int > long int > int > char
// remember that boolean arrays and variables if uninitialized are given false
//Check if constraints are correct
// for single arrays declare them as long long int
//overflow must be taken care of!! use strings when big
//	0 < |int| < 1e9
//	0 < |long int| < 1e12
//	0 < |long long int| < 1e18
//when you are working with stacks, remember to take care of stacks of 0 size
//when you see a problem, and you know how you would tackle it in the real world, but don't know how
//you would do it in code, go step by step, in each step try to be concious of what you want to do
//and once you have done so, review through and remember what data structure would be perfect
//when we pass an array in a function the pointer is passed but when we pass a vector, a copy is passed
template<class T>
void take(vector<T> &v, int &n){
        cin>>n;
        v.resize(n);
        cinarr(v);
}
template<class T>
void take(vector<vector<T>> &v, int &n, int &m ){
        cin>>n>>m;
        v.resize(n,vector<T>(m));
        for(int i =0 ;i < n; i++){
                for(int j = 0; j < m; j++){
                        cin>>v[i][j];
                }
        }
}

//\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\DEBUG/\/\/\/\/\/\/\/\/\/\/\/\///\/\/
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n"<<RESET;}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifdef DEBUG
#define debug(x...) cerr <<BR<< "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

//\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\///\/\/\/\/\/\/
//\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\GLOBAL VARIABLES/\/\/\/\/\/\/\/\/\/\/\/\///\/\/
string decimalToBinary(int n)
{
    //finding the binary form of the number and
    //converting it to string.
    string s = bitset<64> (n).to_string();

    //Finding the first occurrence of "1"
    //to strip off the leading zeroes.
    const auto loc1 = s.find('1');

    if(loc1 != string::npos)
        return s.substr(loc1);

    return "0";
}
int x,y;
//\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\///\/\/\/\/\/\/
void take(){
        cin>>x>>y;
}

void solve(){
        take();
        string a = decimalToBinary(x);
        string b = decimalToBinary(y);
        if(a == b){
                cout<<"YES\n";
                return;
        }
        while(a.back() == '0') a.pop_back();
        if(b.size() < a.size()){
                cout<<"NO\n";
                return;
        }
        int ind = -1;
        for(int i = 0; i < b.size()-a.size()+1; i++){
                string temp = "";
                bool is = true;
                for(int j = i; j < i+a.size(); j++){
                        if(b[j] != a[j-i]){
                                is = false;
                                break;
                        }
                }
                if(is){
                        for(int j = 0; j < i; j++){
                                if(b[j] == '0'){
                                        cout<<"NO\n";
                                        return;
                                }
                        }
                        for(int j = i+a.size(); j < b.size(); j++){
                                if(b[j] == '0'){
                                        cout<<"NO\n";
                                        return;
                                }
                        }
                        cout<<"YES\n";
                        return;
                }
        }
        reverse(a);

        for(int i = 0; i < b.size()-a.size()+1; i++){
                string temp = "";
                bool is = true;
                for(int j = i; j < i+a.size(); j++){
                        if(b[j] != a[j-i]){
                                is = false;
                                break;
                        }
                }
                if(is){
                        for(int j = 0; j < i; j++){
                                if(b[j] == '0'){
                                        cout<<"NO\n";
                                        return;
                                }
                        }
                        for(int j = i+a.size(); j < b.size(); j++){
                                if(b[j] == '0'){
                                        cout<<"NO\n";
                                        return;
                                }
                        }
                        cout<<"YES\n";
                        return;
                }
        }
        cout<<"NO\n";
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    auto time0 = curtime;
	ll t = 1;
	for(int i = 1 ; i <= t; i++) {
		//cout << "Case #" << i << ": ";
		solve();
	}
    //cerr<<"Execution Time: "<<timedif(time0,curtime)*1e-9<<" sec\n";
}


#include<bits/stdc++.h>
//#define ll long long
//#define int long long
//#define endl "\n"
#define xiayang cout<<"嘴硬"<<endl;
#define FAST std::ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
//const int inf = 0x3f3f3f3f3f3f3f3f;
//const int maxn = 2e5+10;
using namespace std;
struct node{
	int len,b[20],ans;
	int vis[10];
}st;
int t,n,m,a;
int b[maxn];
signed main(){
	FAST
//	cin>>t;
	t=1;
	while(t--){
		cin>>n>>a;
		memset(b,0,sizeof(b));
		int maxx=0,m=0;
		while(a){
			m++;
			b[m]=a%10;
			maxx=max(maxx,b[m]);
			a/=10;
		}
		for(int i=0;i<=9;i++)st.vis[i]=0;
		for(int i=0;i<=19;i++)st.b[i]=b[i],st.vis[b[i]]=1;
		st.len=m,st.ans=0;
		if(n==m)cout<<"0"<<endl;
		else if(m>n||maxx<=1)cout<<"-1"<<endl;
		else{
			queue<node>que;
			que.push(st);
			while(!que.empty()){
				int lk[10],cnt=0;
				node nw = que.front();
				que.pop();
//				for(int i=1;i<=19;i++)cout<<nw.b[i];
//				cout<<endl;
				if(nw.len==n){
					cout<<nw.ans<<endl;
					break;
				}
				for(int i=9;i>=2;i--){
					if(nw.vis[i]==1)lk[++cnt]=i;
				}
				for(int i=1;i<=min(cnt,5);i++){
					node tn;
					tn.ans=nw.ans+1;
					for(int j=2;j<=9;j++)tn.vis[j]=0;
					int ml=0;
					tn.b[0]=0;
					for(int j=1;j<=19;j++){
						tn.b[j]=tn.b[j-1]/10+nw.b[j]*lk[i];
						tn.b[j-1]%=10;
						tn.vis[tn.b[j]%10]=1;
						if(tn.b[j]%10!=0)ml=j;
					}
//						cout<<endl<<endl;
					tn.len=ml;
					que.push(tn);
				}
			}
		}
	}
}


#include<iostream>
#include<algorithm>
#include<vector>
#include<unordered_map>
#include<queue>
using namespace std;
typedef unsigned long long ULL;
typedef pair<ULL,int> pr;

const int MAX_N=2e5+5;
int n,m,T;
queue<pr> Q;
bool boo[10];
unordered_map<ULL,int> ump;

int BFS(int x)
{
    int res=-1,s,si;
    ULL xi,xx,xxx,t;
    pr pi;
    boo[0]=boo[1]=true;
    Q.push({x,0});
    ULL Sum=0;
    ump.clear();
    while(!Q.empty()){
        ++Sum;
        pi=Q.front();   Q.pop();
        xx=xxx=pi.first;
        s=pi.second;
        // cout<<">>>  "<<xx<<"  "<<s<<endl;
        for(int i=2;i<10;++i)
            boo[i]=false;
        while(xxx){
            t=xxx%10;
            if(!boo[t]){
                boo[t]=true;
                // xi=xx*t;
                // Q.push({xi,s+1});
                // si=0;
                // while(xi){
                //     ++si;
                //     xi/=10;
                // }
                // if(si==n){
                //     res=s+1;
                //     break;
                // }
            }
            xxx/=10;
        }
        int ll=10;
        // if(Sum<=100000){
        //     ll=10;
        // }
        for(int i=9;i>1&≪--i)
        {
            if(boo[i]&&ll){
                --ll;
                t=i;
                xi=xx*t;
                // if(ump.find(xi)!=ump.end()){
                if(ump[xi])
                    // cout<<">>>>>> "<<xi<<endl;
                    continue;
                }
                ump[xi]=1;
                Q.push({xi,s+1});
                si=0;
                while(xi){
                    ++si;
                    xi/=10;
                }
                if(si==n){
                    xi=xx*t;
                    // cout<<">>>>>>>>>>>>>>>>>>  xi "<<xx<<" "<<xi<<endl;
                    res=s+1;
                    break;
                }
                // break;
            }
        }
        if(res>0){
            break;
        }
    }
    // cout<<">>>>>>> Sum "<<Sum<<endl;

    return res;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    ULL x;
    int res=0,xi,s=0;
    cin>>n>>x;
    if(x==1){
        res=-1;
    }else{
        xi=x;   s=0;
        while(xi){
            ++s;
            xi/=10;
        }
        if(s==n){
            res=0;
        }else if(s>n){
            res=-1;
        }else{
            res=BFS(x);
        }
    }
    // cout<<"<<<<<< ";
    cout<<res<<endl;

    return 0;
}


#include<bits/stdc++.h>

#define endl '\n'
#define fi first
#define se second
#define pb push_back
#define bit(s, i) (s & (1<<i))
#define int long
using namespace std;

const int N = 5e3 + 5;
const int M = 1;
const int K = 1;
const int mod = 1e9+7;
const int inf = 2e9;
const long long Inf = 2e18;

typedef long long ll;
typedef pair < int, int > ii;

long long t[2], dp[N], h, s, p[2];

int main() {
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    // freopen("trash.inp","r",stdin);
    // freopen("trash.out","w",stdout);

    for(int i=0;i<2;++i) cin >> p[i] >> t[i];
    cin >> h >> s;

    memset(dp, 0x3f, sizeof dp);
    dp[0] = 0;
    long long res = Inf;
    for(int i=0;i<h;++i)
    for(int k=0;k<2;++k) {
        for(int j=1;j<=h-i;++j) {
            int e = (1ll * t[k] * j) / t[1 - k];
            long long nw = min(h, i + 1ll * (p[k] - s) * j + 1ll * (p[1 - k] - s) * e);
            if(nw == h) res = min(res,  dp[i] + t[k] * j);
            if(e) {
                nw = min(h,
                i + 1ll * (p[k] - s) * (j - 1) + 1ll * (p[1 - k] - s) * (e - 1) + p[0] + p[1] - s);
                dp[nw] = min(dp[nw], dp[i] + t[k] * j);
            }
            res = min(res, dp[h]);
        }
    }
    cout << res;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second
ll n;
ll mod;
typedef vector<ll> poly;
const int mb=18;//can change !!!!
ll roots[1<<mb];
int rev[1<<mb];
ll pw(ll x,ll y){
	if(y==0) return 1;
	if(y%2) return x*pw(x,y-1)%mod;
	ll res=pw(x,y/2);
	return res*res%mod;
}
void operator<<(ostream& out,poly y){
	for(auto c:y) out << c << ' ';
}
poly operator+(poly x,poly y){
	int n=max(x.size(),y.size());
	x.resize(n);y.resize(n);
	for(int i=0; i<n ;i++){
		x[i]+=y[i];
		if(x[i]>=mod) x[i]-=mod;
	}
	return x;
}
poly operator-(poly x,poly y){
	int n=max(x.size(),y.size());
	x.resize(n);y.resize(n);
	for(int i=0; i<n ;i++){
		x[i]+=mod-y[i];
		if(x[i]>=mod) x[i]-=mod;
	}
	return x;
}

void pre(){
	roots[0]=1;
	while(true){
		ll x=rand()%(mod-1)+1;
		ll sex=pw(x,(mod-1)/262144);
		ll ch=pw(sex,1<<17);
		if(ch==1) continue;
		else{
			roots[1]=sex;
			break;
		}
	}
	//roots[1]=pw(15311432,1<<(23-mb));
	for(int i=1; i<(1<<mb) ;i++) roots[i]=roots[i-1]*roots[1]%mod;
}
void fft(poly &p){
	int n=p.size();
	roots[0]=1;
	int m=(1<<mb)/n;
	for(int i=1; i<n ;i++){
		rev[i]=rev[i/2]/2+((i&1)*n/2);
		if(i<rev[i]) swap(p[i],p[rev[i]]);
	}
	for(int k=1; k<n ;k*=2){
        for(int i=0; i<n ;i+=2*k){
            int cur=0,step=n/(2*k);
            for(int j=0; j<k;j++,cur+=step){
                ll x=p[i+j];
                ll y=p[i+j+k]*roots[cur*m]%mod;
                p[i+j]=(x+y>=mod?x+y-mod:x+y);
				p[i+j+k]=(x>=y?x-y:x+mod-y);
            }
        }
    }
}
poly operator*(poly x,poly y){
	int n=1;
	while(n<x.size()+y.size()-1) n*=2;
	x.resize(n,0);y.resize(n,0);
	fft(x);fft(y);
	for(int i=0; i<n ;i++) x[i]=x[i]*y[i]%mod;
	reverse(x.begin()+1,x.end());
	fft(x);
	ll inv=pw(n,mod-2);
	for(int i=0; i<n ;i++) x[i]=x[i]*inv%mod;
	while(x.size()>1 && x.back()==0) x.pop_back();
	return x;
}
ll C[5001][5001];
ll dp[5001][5001];
ll f[5001],inf[5001];
ll g[5001][5001];
ll pb[5001];
int main(){
	ios::sync_with_stdio(false);cin.tie(0);
	cin >> n >> mod;pre();
	C[0][0]=1;
	dp[0][0]=1;
	f[0]=1;inf[0]=1;
	pb[0]=1;
	for(int i=1; i<=n ;i++){
		C[i][0]=1;
		f[i]=f[i-1]*i%mod;
		inf[i]=pw(f[i],mod-2);
		pb[i]=pb[i-1]*(n-1)%mod;
		for(int j=1; j<=i ;j++){
			C[i][j]=(C[i-1][j-1]+C[i-1][j])%mod;
			dp[i][j]=(dp[i-1][j-1]+dp[i-1][j]*2*j+dp[i-1][j+1]*j*(j+1))%mod;
			//cout << dp[i][j] << ' ';
		}
		//cout << endl;
	}
	//cout << roots[1] << endl;
	poly bad(n+1);
	for(int i=0; i<=n ;i++){
		bad[i]=inf[i];
		if(i%2==1) bad[i]=mod-bad[i];
	}
	for(int i=0; i<=n ;i++){
		poly sex(n-i+1);
		for(int j=i; j<=n ;j++){
			sex[j-i]=dp[j][j-i]*inf[j]%mod;
		}
		auto funny=bad*sex;
		bad.pop_back();
		//cout << bad[0] << ' ' << bad[1] << ' ' << sex[0] << ' ' << sex[1] << endl;
		for(int j=i; j<=n ;j++){
			g[j][j-i]=funny[j-i]*f[j]%mod;
		}
	}
	ll ans=0;
	for(int i=1; i<=n ;i++){
		ll pa=1;
		for(int j=0; j<=i ;j++){//ways to have i chains and j singletons
			ll ways=g[n-j][i-j]*C[n][j]%mod;
			ll love=pa*pb[i-j]%mod;pa=pa*(n-i)%mod;
			//cout << i << ' ' << j << ' ' << ways << ' ' << love << endl;
			ans=(ans+ways*love)%mod;
		}
	}
	cout << ans << '\n';
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> Poly;
const int N = 1 << 20;
int n, G, mod, r[N], Inv[N]; Poly f, g, vf, T, P, ans;
vector<int> factor;
inline int add(int x, int y) { return x + y >= mod ? x + y - mod : x + y; }
inline int dec(int x, int y) { return x - y < 0 ? x - y + mod : x - y; }
inline int mul(int x, int y) { return (ll)x * y % mod; }
inline int qpow(int a, int b) {
	int ans = 1;
	for (; b; b >>= 1, a = mul(a, a)) if (b & 1) ans = mul(ans, a);
	return ans;
}
inline void NTT(Poly &A, int len, int type){
	for (int i = 0; i < len; ++ i) if(i < r[i]) swap(A[i], A[r[i]]);
	for (int mid = 1; mid < len; mid <<= 1) {
		int Wn = qpow(G, (mod - 1) / (mid << 1));
		if (type < 0) Wn = qpow(Wn, mod - 2);
		for (int j = 0; j < len; j += (mid << 1))
			for (int k = 0, w = 1; k < mid; ++ k, w = mul(w, Wn)) {
				int x = A[j + k], y = mul(w, A[j + k + mid]);
				A[j + k] = add(x, y), A[j + k + mid] = dec(x, y);
			}
	}
	if (type > 0) return;
	for (int i = 0; i < len; ++ i) A[i] = mul(A[i], Inv[len]);
}
inline void init_rev(int len) {
	for (int i = 0; i < len; ++ i) r[i] = r[i >> 1] >> 1 | ((i & 1) * (len >> 1));
}
inline Poly operator + (const Poly&a, const Poly&b) {
	Poly c = a; c.resize(max(a.size(), b.size()));
	for (int i = 0; i < b.size(); ++ i) c[i] = add(c[i], b[i]);
	return c;
}
inline Poly operator - (const Poly&a, const Poly&b) {
	Poly c = a; c.resize(max(a.size(), b.size()));
	for (int i = 0; i < b.size(); ++ i) c[i] = dec(c[i], b[i]);
	return c;
}
inline Poly operator * (Poly a, Poly b) {
	int n = a.size(), m = b.size(), l = 1;
	while (l < n + m - 1) l <<= 1;
	init_rev(l);
	a.resize(l), NTT(a, l, 1);
	b.resize(l), NTT(b, l, 1);
	for (int i = 0; i < l; ++ i) a[i] = mul(a[i], b[i]);
	NTT(a, l, -1);
	a.resize(n + m - 1);
	return a;
}
inline Poly operator * (Poly a, int b) {
	for (int i = 0; i < a.size(); ++ i) a[i] = mul(a[i], b);
	return a;
}
inline Poly Deriv(Poly a) {
	for (int i = 0; i + 1 < a.size(); ++ i) a[i] = mul(a[i + 1], i + 1);
	return a.pop_back(), a;
}
inline Poly Integ(Poly a) {
	a.emplace_back(0);
	for (int i = a.size() - 1; i; -- i) a[i] = mul(a[i - 1], Inv[i]);
	return a[0] = 0, a;
}
inline Poly Polyinv(const Poly&a, int lim) {
	Poly c, b(1, qpow(a[0], mod - 2));
	for (int l = 4; (l >> 2) < lim; l <<= 1) {
		init_rev(l);
		c = a, c.resize(l >> 1);
		c.resize(l), NTT(c, l, 1);
		b.resize(l), NTT(b, l, 1);
		for (int i = 0; i < l; ++ i) b[i] = mul(b[i], dec(2, mul(b[i], c[i])));
		NTT(b, l, -1), b.resize(l >> 1);
	}
	return b.resize(lim), b;
}
inline Poly Polyinv(const Poly&a) { return Polyinv(a, a.size()); }
inline Poly Polyln(Poly a, int lim) {
	a = Integ(Deriv(a) * Polyinv(a, lim));
	return a.resize(lim), a;
}
inline Poly Polyln(const Poly&a) { return Polyln(a, a.size()); }
inline Poly Polyexp(const Poly&a, int lim) {
	Poly c, b(1, 1); int n = a.size();
	for (int i = 2; (i >> 1) < lim; i <<= 1) {
		c = Polyln(b, i);
		for (int j = 0; j < i; ++ j) c[j] = dec(j < n ? a[j] : 0, c[j]);
		c[0] = add(c[0], 1);
		b = b * c, b.resize(i);
	}
	return b.resize(lim), b;
}
inline Poly Polyexp(const Poly&a) { return Polyexp(a, a.size()); }
inline void precalc() {
	Inv[0] = Inv[1] = 1;
	for (int i = 2; i < N; ++ i) Inv[i] = mul(mod - mod / i, Inv[mod % i]);
}
Poly exp_f0, fef, xfef, exp_xfef;
inline Poly Newton_Method_f(int len) {
	if (len == 1) { vector<int> f(2); f[0] = 0, f[1] = 1; return f; }
	Poly f = Newton_Method_f(len + 1 >> 1);
	exp_f0 = Polyexp(f, len), fef = f * exp_f0; xfef.resize(len);
	for (int i = 1; i < len; ++ i) xfef[i] = fef[i - 1]; xfef[0] = 0;
	exp_xfef = Polyexp(xfef, len), xfef = exp_xfef + fef;
	for (int i = len - 1; i; -- i) xfef[i] = xfef[i - 1]; xfef[0] = 0;
	for (int i = len - 1; i; -- i) exp_xfef[i] = exp_xfef[i - 1]; exp_xfef[0] = 1;
	exp_xfef = exp_xfef * (fef + exp_f0), exp_xfef.resize(len);
	for (int i = len - 1; i; -- i) exp_xfef[i] = exp_xfef[i - 1]; exp_xfef[0] = mod - 1;
	f = f - (xfef - f) * Polyinv(exp_xfef);
	return f.resize(len), f;
}
int main() {
	scanf("%d%d", &n, &mod);
	int phi = mod - 1;
	for (int i = 2; i * i <= phi; ++ i)
		if (phi % i == 0) {
			while (phi % i == 0) phi /= i;
			factor.emplace_back(i);
		}
	if (phi > 1) factor.emplace_back(phi);
	for (int i = 1; ; ++ i) {
		if (__gcd(i, mod) != 1) continue;
		int flag = true;
		for (auto x : factor)
			if (qpow(i, (mod - 1) / x) == 1) {
				flag = false; break;
			}
		if (flag) { G = i; break; }
	}
	precalc();
	f = Newton_Method_f(100000), f.resize(n + 1);
	vf = Polyexp(f);
	for (int i = vf.size() - 1; i; -- i) vf[i] = vf[i - 1];
	vf[0] = 0;
	g = f - f * vf, g.resize(n + 1);
	P = vf + f - g;
	T = P * g + P, T.resize(n + 1);
	T[0] = 1, vf[0] = 1;
	for (int i = 1; i <= n; ++ i) {
		if (T[i]) T[i] = mod - T[i];
		if (vf[i]) vf[i] = mod - vf[i];
	}
	T = Polyln(T), vf = Polyln(vf);
	for (int i = 1; i <= n; ++ i) {
		if (T[i]) T[i] = mod - T[i];
		if (vf[i]) vf[i] = mod - vf[i];
	}
	ans = Polyexp(T - vf - f + g);
	for (int i = 1, fac = 1; i <= n; ++ i) fac = mul(fac, i);
	printf("%d\n", mul(ans[n], fac));
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")

// #pragma GCC optimize "trapv"

#define int long long
#define ll long long
#define mod 1000000007
#define mod2 998244353
#define min3(a, b, c) (min(min((a), (b)), (c)))
#define max3(a, b, c) (max(max((a), (b)), (c)))

#define pb push_back
#define ppb               pop_back
#define pf                push_front
#define ppf               pop_front
#define pi_solve_it 3.1415927
// long double pi_val = acos(-1.0);

#define vi vector<long long>
#define vll vector<long long>
#define vint vector<int>
#define pii pair<long long, long long>
#define pint pair<int, int>
#define F first
#define S second
#define mem1(a)           memset(a,-1,sizeof(a))
#define mem0(a)           memset(a,0,sizeof(a))

//#define SET

#ifdef SET
// header files for policy based data structuans in g++
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>     // Including tree_order_statistics_node_update
#include <ext/rope>
using namespace __gnu_pbds;
using namespace __gnu_cxx;
// ordered_Set - same as set but aintows
               //order_of_key (k) : Number of items strictly smainter than k    O(logn)
               //find_by_order(k) : K-th element in a set (counting from zero).  O(logn)
// change less<long long> to less_equal<long long> to have a ordered set behaving as multi set but in this case erase operation does not work ans neither does the upper bound
typedef tree<long long, null_type, less<long long>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
typedef tree<long long, null_type, less_equal<long long>, rb_tree_tag, tree_order_statistics_node_update> indexed_multi_set;
#endif

long long power(  long long x,
                            long long        y, long long   p)
{
    long long ans = 1;

    x = x % p;

    while (y > 0)
    {
        if (y & 1)
            ans = (ans * x) % p;
        y = y >> 1;
        x = (x * x) % p;
        //cout<<ans<<"\n";
    }
    return ans;
}

int gcd(int x, int y) { return !y ? x : gcd(y, x % y); }
int lcm(int x, int y) { return x / gcd(x, y) * y; }

int32_t main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    auto time = clock();
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    long long t;
    //cin>>t;

    t=1;

    for(int tt=1;tt<=t;tt++)
    {
        //cout<<"Case #"<<tt<<": ";
        int n,m;
        cin>>n>>m;
        int ans = 0;
        int val = 1;
        int prev = m%mod2;

        for (int i = 2; i <= n; ++i)
        {
            if(prime[i]==1 && val<=m)
            {
                val*=i;
            }
            //cout<<power(m,i,mod2)<<" V:"<<val<<endl;
            int res = prev * ((m/val)%mod2);
            ans = (ans+power(m,i,mod2)-res)%mod2;
            ans = (ans+mod2)%mod2;
            //cout<<ans<<endl;
            prev = (prev * ((m/val)%mod2))%mod2;
        }
        cout<<ans<<endl;
    }

    #ifndef ONLINE_JUDGE
    cout << setprecision(3)<<double(clock() - time) / CLOCKS_PER_SEC << "\n";
    #endif
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define ff first
#define ss second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
using namespace std;
const int nMax = 1e6;
const ll MOD = 998244353;
void solve(){
	ll n, m; cin>>n>>m;
	ll ans = 0, temp = 1, num = 1 ,pwr = 1;
	for(int i = 1; i <= n; i++){
		if(__gcd(i, num) == 1)
			num *= i;
		temp = (m / num) % MOD * temp%MOD;
		pwr = m%MOD * pwr%MOD;
		ans = (ans + pwr - temp + MOD)%MOD;
	}
	ans %= MOD;
	cout<<ans<<'\n';
}
int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int T = 1;//cin >> T;
    while(T--){
        solve();
    }
    return 0;
}


#include<iostream>
using namespace std;
int main()
{
	int a[3],x,n;
    cin>>num;
    cin>>x;
    int n=0;
    for(int i=0;i<num;i++)
    {
        cin>>a[i];
    }
    if(x==1){
        if(a[0]!=0)
        {
            n=a[0];
            if(a[n]!=0)
                cout<<"YES";
            else ocut<<"NO";
        }
        else
            cout<<"NO";
    }
    else if(x==2){
        if(a[1]!=0){
            n=a[1];
            if(a[n]!=0)
            cout<<"YES";
            else cou<<"NO";
        }
        else
            cout<<"NO";
    }
    else {
        if(a[2]!=0)
        {	n=a[2];
         	if(a[n]!=0)
            cout<<"YES";
         	else cot<<"NO";
        }else
            cout<<"NO";
    }
    return 0;
}


// LUOGU_RID: 90796814
#include <bits/stdc++.h>
using namespace std;
const int MAXL=1e+1;
int t,x,v[MAXL];
int main()
{
  cin>>t;
  for(int i=1;i<=t;i++){
    cin>>x;
    cin>>v[1]>>v[2]>>v[3];
    if(v[x]==0 || v[v[x]]==0){
      cout<<"NO"<<endl;
    }else{
      cout<<"YES"<<endl;
  return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <fstream>
#include <algorithm>
#include <climits>
#include <cstdlib>
#include <cstdio>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <bitset>
#include <deque>
#include <queue>
#include <tuple>
#include <cmath>
#include <cctype>
#include <stack>
#include <cassert>
#include <iomanip>
#include <complex>
using namespace std;
using ll = long long;
using cd = complex<long double>;
ll MOD = 998244353;

int n, k, f;

void fft(vector<cd>& p, bool invert) {
    ll n = p.size();
    vector<int> rev(n); rev[0] = 0;
    for (int i = 1; i < n; i++) {
        rev[i] = (rev[i>>1]>>1) + (i%2 ? n/2 : 0);
        if (i < rev[i]) swap(p[i], p[rev[i]]);
    }
    vector<cd> w(n);
    for (int i = 0; i < n; i++) w[i] = polar(1.0, ll(2*i)*M_PI / n * (invert ? -1 : 1));
    for (int len = 1; len < n; len *= 2) {
        int m = n / len / 2;
        for (int i = 0; i < n; i += 2*len) {
            for (int j = 0; j < len; j++) {
                cd even = p[i+j], odd = p[i+j+len];
                p[i+j] = even + w[m*j]*odd;
                p[i+j+len] = even - w[m*j]*odd;
            }
        }
    }
    if (invert)
        for (cd& x : p) x /= n;
}
vector<ll> conv_mod(const vector<ll> a, const vector<ll> b) {
    int d = a.size()+b.size()-1;
    int n2 = 1; while (n2 <= d) n2 *= 2;
    ll M = sqrt(MOD);
    vector<cd> inf(n2), ins(n2), outf(n2), outs(n2);
    for (int i = 0; i < a.size(); i++) inf[i] = cd(a[i]/M, a[i]%M);
    for (int i = 0; i < b.size(); i++) ins[i] = cd(b[i]/M, b[i]%M);
    fft(inf, false); fft(ins, false);
    //cout << "debugging inf, ins" << endl;
    //for (int i = 0; i < n2; i++) cout << inf[i] << " "; cout << endl;
    //for (int i = 0; i < n2; i++) cout << ins[i] << " "; cout << endl;
    for (int i = 0; i < n2; i++) {
        int j = n2-i;
        outf[i] = (inf[i] + conj(inf[j]))*ins[i] / cd(2);
        outs[i] = (inf[i] - conj(inf[j]))*ins[i] / cd(2) / cd(0, 1);
    }
    fft(outf, true); fft(outs, true);
    //cout << "debugging outf, outs" << endl;
    //for (int i = 0; i < n2; i++) cout << outf[i] << " "; cout << endl;
    //for (int i = 0; i < n2; i++) cout << outs[i] << " "; cout << endl;
    vector<ll> res(d+1);
    for (int i = 0; i <= d; i++) {
        ll a = llround(outf[i].real()), c = llround(outs[i].imag());
        ll b = llround(outf[i].imag() + outs[i].real());
        res[i] = ((a%MOD*M + b)%MOD*M + c)%MOD;
    }
    return res;
}

vector<ll> naive_mult(vector<ll> a, vector<ll> b) {
    vector<ll> res(a.size()-1+b.size()-1+1, 0);
    for (int i = 0; i < a.size(); i++) {
        for (int j = 0; j < b.size(); j++) {
            res[i+j] = (res[i+j] + a[i]*b[j]) % MOD;
        }
    }
    return res;
}

int main() {
    cin >> n >> k >> f;
    vector<ll> p(k+1, 1);
    for (int i = 2; i <= n; i++) {
        vector<ll> v = conv_mod(p, p);
        ll rs = 0;
        for (int i = v.size()-1; i >= 0; i--) {
            if (i <= k) p[i] = (ll(k+1-i)*v[i] + rs) % MOD;
            rs = (rs + v[i]) % MOD;
        }
    }
    p = conv_mod(p, p);
    cout << (f < p.size() ? p[f] : 0) << endl;

    //cout << "debugging conv_mod" << endl;
    //vector<ll> a{1, 2}, b{2, 3};
    //vector<ll> res = conv_mod(a, b);
    //for (int i = 0; i < res.size(); i++) cout << res[i] << " "; cout << endl;

}


using namespace std;
#define ll long long
#define bug(x) cout<<#x<<"=="<<x<<endl;
#define ull unsigned long long
#define lb long double
#define rg register int

#define fp(i,a,b) for(register int i=a,I=b+1;i<I;++i)
#define fd(i,a,b) for(register int i=a,I=b-1;i>I;--i)
inline char gc()
{
    static char buf[1000000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,1000000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline ll read()
{
    char c=gc();
    ll su=0,f=1;
    for (; c<'0'||c>'9'; c=gc()) if (c=='-') f=-1;
    for (; c>='0'&&c<='9'; c=gc()) su=su*10+c-'0';
    return su*f;
}
inline void write(ll x)
{
    if (x<0)
    {
        putchar('-');
        write(-x);
        return;
    }
    if (x>=10) write(x/10);
    putchar(x%10+'0');
}
inline void writesp(ll x)
{
    write(x),putchar(' ');
}
inline void writeln(ll x)
{
    write(x);
    putchar('\n');
}
const int maxn=4e6+10;
const int N = 2e7+10;
const ll mod=998244353;
const ll P=998244353;

///#define int long long
const int g=3;
inline int power(int a, int b){
    int res = 1;
    for(; b; b>>=1, a=1ll*a*a%mod)
        if(b&1)
            res=1ll*res*a%mod;
    return res;
}

void ntt(int *a, int n, int flag){
    for(int i=(n>>1), j=1; j<n; j++){
        if(i<j) swap(a[i], a[j]);
        int k = (n>>1);
        while(i&k){i^=k; k>>=1;}
        i^=k;
    }
    for(int k=2; k<=n; k<<=1){
        int rt = power(g, (mod-1)/k);
        if(flag == -1)
            rt = power(rt, mod-2);
        for(int i=0; i<n; i+=k){
            int del = 1;
            for(int j=i; j<i+k/2; j++){
                int u = a[j], v = 1ll * del * a[j+k/2] % mod;
                a[j] = (u + v) % mod;
                a[j+k/2] = (u - v + mod) % mod;
                del = 1ll * del * rt % mod;
            }
        }
    }
    if(flag == -1){
        int inv = power(n, mod-2);
        for(int i=0; i<n; i++)
            a[i] = 1ll * a[i] * inv % mod;
    }
}
//空间记得开两倍两倍两倍
void mul(int *a, int n){
    int m;
    for(m = n<<1, n=1; n<=m; n<<=1);
    ntt(a, n, 1);
    for(int i=0; i<n; i++)
        a[i] = 1ll * a[i] * a[i] % mod;
    ntt(a, n, -1);
}
int dp[30][maxn]={0};
signed main() {
    int n = read();
    int k = read();
    int f = read();
    for (int i = 0; i <= k; i++) {
        dp[n][i] = 1;
    }
    for (int i = n - 1; i >= 1; i--) {
        mul(dp[i + 1], k);
        ll sum = 0;
        for (int j = 2 * k; j >= 0; j--) {
            sum = (sum + dp[i + 1][j]) % mod;
            if (j <= k) {
                dp[i][j] = (sum%mod+(1LL*dp[i + 1][j]) * (k - j) % mod)%mod;
            }
        }
    }
    mul(dp[1], k);
    writeln(dp[1][f]);
}


#include<bits/stdc++.h>
using namespace std;

void solve()
{
    int n;
    cin>>n;
    map<int,int> m;
    for(int i=1;i*i<=n;i++)
    {
        int j=i*i;
        int k=j*i

        if(j<=n)
        m[j]++;
        if(k<=n)
        m[k]++;
    }
     cout<<m.size()<<endl;
}

int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main() {
	int n;
	cin>>n;
	for (int t=0;t<n;t++){
		long long int m;
		cin>>m;
		int count =1;
		for (long long int j = 1;j<=100000;j++) {
			if (j*j <=m ){
				count++;
			} else {
				break;
			}
		}
		for (long long int j = 1; j<=1000;j++) {
			long long int ss= sqrt(j*j*j);
			if (j*j*j <=m &&ss*ss!=j*j*j)
				count++;
			}
		}
		cout<<count<<endl;
	}
	return 0;
}

				/*
				 *
5
2
7
32073
32073
22718
				 * /


#include<bits/stdc++.h>
using namespace std;
long long m,n;
int main(){
    cin>>n>>>m;
    if(m!=1) cout<<(m/2+1)*n;
    else
        {
            cout<<(n/2);
        }

    return 0;
}


#include <iostream>
using namespace std;
int main()
{
    long long n,m;
    cin>>n>>m;
    long long answer = (m != 1) ? ((m-1)*n) : (n-1)
    cout<<answer;

}


#include<bits/stdc++.h>
using namespace std;

int main(){
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        vector<int>arr(n);
        for(int i=0;i<n;i++){
            cin>>arr[i];
        }
    }
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vb = vector<bool>;
using vvb = vector<vb>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vc = vector<char>;
using vvc = vector<vc>;
using vs = vector<string>;
const ll mod = 1e9 + 7,inf = 1e18;
#define pb push_back
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
void setIO()
{
    fast;
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
}
vl fact(2e5 + 5,1);
ll binPow(ll a,ll b)
{
    if (b == 0)return 1;
    if (b == 1)return a;
    ll ret = binPow(a,b/2);
    if (b%2 == 0)return (ret * ret)%mod;
    return ((ret * ret)%mod * a)%mod;
}
ll inv(ll a)
{
    return (binPow(a,mod - 2)%mod + mod)%mod;
}
ll binom(ll a,ll b)
{
    return (((fact[a] * inv(fact[b]))%mod * inv(fact[a - b]))%mod + mod)%mod;
}
int main()
{
    setIO();

    for (int i = 2;i<=2e5;i++)fact[i] = (fact[i - 1] * 1ll * i)%mod;

    int t;
    cin>>t;
    while (t--){
        ll n,k;
        cin>>n>>k;

        ll val = 0;

        if (k == 0){
            cout<<1<<'\n';
            continue;
        }

       val=binPow(2,n-1);

        vvl dp(k,vl(2));

        //dp[i][0]: LHS == RHS at ith bit
        //dp[i][1]: LHS > RHS at ith bit

        for (int i = 0;i<k;i++){
            if (i == 0){

                dp[i][1] = (n%2 == 0 ? 1 : 0);

                //if n is even => LHS = 1 and RHS = 0

                dp[i][0] = (n%2 == 1 ? 1 : 0) + val;

                //if n is odd => LHS = 1 and RHS = 1
                //Choose an even number of 1's and at least one 0

                dp[i][0] %= mod;
                dp[i][1] %= mod;
            }
            else{

                dp[i][1] = ((n%2 == 0 ? 1 : 0) * (binPow(2,n * i)%mod))%mod;

                dp[i][0] =

                (((n%2 == 1 ? 1 : 0) + val)%mod * ((dp[i - 1][0]%mod + dp[i - 1][1])%mod)%mod)%mod;

                dp[i][0] %= mod;
                dp[i][1] %= mod;
            }
        }
        ll ans = (dp[k - 1][0] + dp[k - 1][1]%mod)%mod;
        if (ans < 0)ans += mod;
        cout<<ans<<'\n';
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define int LL
const int maxn = 2e5+5;
const int mo = 1e9+7;
int readint(){
	int x=0,f=1;char s=getchar();
	#define sc (s=getchar())
	while(s<'0'||s>'9'){
		if(s=='-')
			f=-1;
		sc;
	}
	while(s>='0'&&s<='9'){
		x=(x<<3)+(x<<1)+(s^48);
		sc;
	}
	#undef sc
	return x*f;
}
int fac[maxn],inv[maxn];
void init(int n){
	fac[0]=inv[0]=inv[1]=1;
	for(int i=1;i<=n;i++)
		fac[i]=1ll*fac[i-1]*i%mo;
	for(int i=2;i<=n;i++)
		inv[i]=1ll*(mo-mo/i)*inv[mo%i]%mo;
	for(int i=2;i<=n;i++)
		inv[i]=1ll*inv[i-1]*inv[i]%mo;
}
int C(int n,int m){
	if(n<=0||m<=0||n<m)
		return 1;
	return 1ll*fac[n]*inv[n-m]%mo*inv[m]%mo;
}
int qkpow(int a,int b){
	int ans=1;
	while(b){
		if(b&1)
			ans=1ll*ans*a%mo;
		b>>=1;
		a=1ll*a*a%mo;
	}
	return ans;
}
int main (){
	init(maxn-5);
	int t=readint();
	while(t--){
		int n=readint(),k=readint();
		int sum=0,ans=0;
		for(int i=0;i<n;i+=2){//Ä³Ò»Î»ÏàµÈµÄ·½°¸Êý
			sum=(0ll+sum+C(n,i))%mo;
		}
//		cout<<sum<<endl;
		if(n&1)
			ans=(0ll+ans+qkpow(sum+1,k))%mo;
		else{
			for(int i=0;i<k;i++)
				ans=(0ll+ans+qkpow(sum,i)*qkpow(qkpow(2,n),k-i-1)%mo)%mo;
			ans=(0ll+ans+qkpow(sum,k))%mo;
		}
		printf("%d\n",ans);
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#pragma GCC target("avx2")
#pragma GCC optimize("Ofast")
#pramga GCC optimize("unroll-loops")
#define MAX_N (int) (4e2 + 7)
#define int long long

int f[MAX_N][MAX_N];
int C[MAX_N][MAX_N];
int POW[MAX_N];

signed main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout.tie(0);
    int n , M; cin >> n >> M;
    for (int i = 0 ; i <= n ; i ++) {
        C[i][i] = 1;
        C[i][0] = 1;
    }
    POW[0] = 1;
    for (int i = 1 ; i <= n ; i++) {
        (POW[i] = POW[i - 1]*2)%=M;
        for (int j = 1 ; j <= i ; j++) {
            (C[i][j] = C[i - 1][j] + C[i - 1][j - 1])%=M;
        }
    }
    f[0][0] = 1;
    for (int i = 0 ; i < n ; i++) {
        for (int j = 0 ; j < n ; j++) {
            for (int k = 1 ; k <= n ; k++) {
                if (i + k + 1 <= n + 1 && j + k <= n)
                (f[i + k + 1][j + k] += f[i][j]*POW[k - 1]%M*C[j + k][k]%M)%=M;
            }
        }
    }
    int ans = 0;
    for (int i = 0 ; i <= n ; i++) {
        (ans += f[n + 1][i])%=M;
    }
    cout << ans;
    return 0;
}


#include <bits/stdc++.h>

#define ll long long
#define pb push_back
#define sz(x) (int) x.size()
#define all(x) x.begin(), x.end()
#define f first
#define s second
#define pl pair<ll, ll>
#define pi pair<int, int>
//~ #define int ll

using namespace std;
int n, m;
int inv[405], f[405], choose[405][405], pow2[405];
int dp[405][405];
int binpow(int a,int b) {
	int res = 1;
	for(; b; b >>= 1, a = (a * 1ll * a) % m) {
		if(b & 1) res = (res * 1ll * a) % m;
	}
	return res;
}
void calc() {
	f[0] = pow2[0] = 1;
	for(int i = 1; i <= n; i++) {
		f[i] = (f[i - 1] * 1ll * i) % m;
		inv[i] = binpow(f[i],m - 2);
		pow2[i] = pow2[i - 1] * 2 % m;
	}
	for(int i = 0; i <= n; i++) {
		for(int j = 0; j <= i; j++) {
			choose[i][j] = ((f[i] * inv[j] % m) * inv[i - j]) % m;
		}
	}
}
signed main() {
	ios_base::sync_with_stdio(0), cin.tie(0);
	cin >> n >> m;
	calc();
	dp[0][0] = 1;
	for(int i = 0; i < n; i++) {
		for(int j = 0; j <= i; j++) {
			for(int k = 1; k + i <= n; k++) {
				dp[i + k + 1][j + k] += ((dp[i][j] * pow2[k - 1] % m) * choose[j + k][k] % m);
				dp[i + k + 1][j + k] %= m;
			}
		}
	}
	int ans = 0;
	for(int i = 0; i <= N; i++) {
		ans = (ans + dp[n][i]) % m;
	}
	cout << ans;
}


#include<bits/stdc++.h>
#define N 1000010
#define int long long
#define mod 1000000007
#define LL long long
#define rep(i,l,r) for(int i=l;i<=r;i++)
#define drep(i,r,l) for(int i=r;i>=l;i--)
using namespace std;
int n;
LL poww(LL x,LL y) {
	LL res=1;
	while(y) {
		if(y&1) res=res*x%mod;
		x=x*x%mod;
		y>>=1;
	}
	return res;
}
signed main() {
	scanf("%lld",&n);
	rintf("%lld",6ll*poww(4ll,(poww(2ll,n)-2ll+mod)%mod)%mod);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long

int k;
ll mod =1e9+7;
ll ans;

ll pow2_(ll x, ll p)
{
    if (p==0) return 1LL;

    ll hf = pow_(x, p/2);
    if (p&1)return hf*hf*x;
    return hf*hf;
}

ll pow_(ll x, ll p)
{
    if (p==0) return 1LL;

    ll hf = pow_(x, p/2);
    if (p&1)return hf*hf%mod*x%mod;
    return hf*hf%mod;
}

int main()
{
    scanf("%d", &k);
    ans= pow_(4, pow2_(2,1LL*k)-2);
    ans*=6LL;
    printf("%lld\n", ans%mod);

    return 0;
}


#include <bits/stdc++.h>
#define lld long long
using namespace std;
const lld mod1 = 998244353;
const lld mod2 = 1e9 + 7;
lld ans;
lld n;
lld cnt1;
vector < lld > val[7];
lld sum[7];
void dfs1 (lld k1, lld k2) {
	if (k1 == 7) return;
	val[k1].push_back((cnt1 - k2 + mod1) % mod1);
	sum[k1] += (cnt1 - k2 + mod1) % mod1;
	++ cnt1;
	for (lld i = 0; i <= 9; ++ i)
		dfs1 (k1 + 1, k2 * 10 + i);
}
inline bool check(lld x) { return x * 1000000 + 999999 <= n && x * 10000000 > n; }
lld cnt2;
lld poww[7] = { 1, 10, 100, 1000, 10000, 100000, 1000000 };
void dfs2(lld k1, lld k2) {
	if (k2 > n) return;
	if (check(k2)) {
		for (lld i = 0; i <= 6; ++ i) {
			lld offset = ((cnt2 + 1 - (k2 * poww[i])) % mod1 + mod1) % mod1;
			lld pos = lower_bound(val[i].begin(), val[i].end(), mod1 - offset) - val[i].begin();
			ans = (ans + (sum[i] + offset * val[i].size() - mod1 * (val[i].size() - pos))) %= mod2;
		}
		cnt2 += cnt1;
	} else {
		++ cnt2;
		ans = (ans + ((cnt2 - k2) % mod1 + mod1) % mod1) %= mod2;
		for (lld i = (!k1); i <= 9; ++ i)
			dfs2(k1 + 1, k2 * 10 + i);
	}
}
int main() {
	scanf("%lld", & n);
	dfs1 (0, 0);
	for (lld i = 0; i <= 6; ++ i) sort(val[i].begin(), val[i].end());
	cnt2 = -1;
	dfs2 (0, 0);
	printf("%lld\n", ans);
}


#include<iostream>
#include<cstring>
#include<map>
#include<assert.h>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<vector>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
mt19937 mrand(random_device{}());
const ll mod=1000000007;
const ll mod2=998244353;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

VI pos[10];
int cnt;
ll pw[15],s[15];
ll cnt2,n;
int ans;
int query(int fixpre,ll val) {
	ll ans=0;
	rep(d,0,7) {
		ll offset=(val-fixpre*pw[d])%mod2;
		if (offset<0) offset+=mod2;
		int p=lower_bound(all(pos[d]),mod2-offset)-pos[d].begin();
		ans=(ans+s[d]+offset*SZ(pos[d])-mod2*(SZ(pos[d])-p))%mod;
	}
	return ans;
}

void dfs(int val,int d) {
	int x=(cnt-val+mod2)%mod2;
	pos[d].pb(x); cnt++;
	s[d]+=x;
	if (d==6) return;
	rep(i,0,10) dfs(val*10+i,d+1);
}

void dfs2(ll val) {
	if (val*1000000+999999<=n&&val*10000000>n) {
		ans=(ans+query(val,cnt2+1))%mod;
		cnt2+=cnt;
	} else {
		cnt2++;
		ans=(ans+((cnt2-val)%mod2+mod2)%mod2)%mod;
		rep(i,val?0:1,10) {
			if (val*10+i<=n) dfs2(val*10+i);
		}
	}
}

int main() {
	dfs(0,0);
	rep(i,0,7) sort(all(pos[i]));
	pw[0]=1;
	rep(i,1,13) pw[i]=pw[i-1]*10;
	scanf("%lld",&n);
	cnt2=-1;
	dfs2(0);
	printf("%d\n",ans);
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define endl '\n'
#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int main()
{
    optimize();
    ll t;
    cin>>t;
    while(t--)
    {
        ll a,b,c,d;
        cin>>a>>b>>c>>d;
        ll k=0,h=0;
        if(a==0 && b==0 && c==0 && d==0)
            cout<< "0"<<endl;
       else if(a==0 && b==1 && c==1 && d==0)
            cout<< "2"<<endl;
      else if(a==1 && b==0 && c==0 && d==1)
            cout<< "1"<<endl;
       else if(a==1 && b==1 && c==0 && d==0)
            cout<< "1"<<endl;
            else if(a==0 && b==0 && c==1 && d==1)
            cout<< "1"<<endl;
       else if(a==1 && b==1 && c==1 && d==1)
            cout<< "2"<<endl;
    }
}#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define endl '\n'
#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int main()
{
    optimize();
    ll t;
    cin>>t;
    while(t--)
    {
        ll a,b,c,d;
        cin>>a>>b>>c>>d;
        ll k=0,h=0;
        if(a==0 && b==0 && c==0 && d==0)
            cout<< "0"<<endl;
       else if(a==0 && b==1 && c==1 && d==0)
            cout<< "2"<<endl;
      else if(a==1 && b==0 && c==0 && d==1)
            cout<< "1"<<endl;
       else if(a==1 && b==1 && c==0 && d==0)
            cout<< "1"<<endl;
            else if(a==0 && b==0 && c==1 && d==1)
            cout<< "1"<<endl;
       else if(a==1 && b==1 && c==1 && d==1)
            cout<< "2"<<endl;
    }
}


<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup />
</Project>


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
bool h_v(ll n, ll m, ll k){
    ll kprima=(m*n)/2-k;
    return (k%n)%2==0;
}
bool v_v(ll n, ll m, ll k){
    ll kprima=(m*n)/2-k;
    if(k%n != 0){
        return false;
    }
    else{
        if((k/n)%2 == 0){
            return false;
        }
        else{
            return true;
        }
    }
}
bool h_h(ll n, ll m, ll k){
    ll kprima=(m*n)/2-k;
    if(kprima%m != 0){
        return false;
    }
    else{
        if((kprima/m)%2 == 0){
            return false;
        }
        else{
            return true;
        }
    }
}
bool v_h(ll n, ll m, ll k){
    ll kprima=(m*n)/2-k;
    return (kprima%m)%2==0;
}
bool func_aux(ll n, ll m, ll k){
    ll bandera=false;
    if(n%2 == 0){
        bandera = h_v(n,m,k) || v_v(n,m,k);
    }
    if(m%2 == 0){
        bandera = bandera || h_h(n,m,k) || v_h(n,m,k);
    }
    return bandera;
}
bool neq1(ll n, ll m, ll k){
    ll kprima=(m*n)/2-k;
    return kprima==0;
}
bool meq1(ll n, ll m, ll k){
    return k==0;
}
bool keq0(ll n, ll m, llk){
    return n%2 == 0;
}
bool kprimaeq0(ll n, ll m, ll k){
    return m%2 == 0;
}
bool func(ll n, ll m, ll k){
    ll kprima=(m*n)/2-k;
    if(n==1){
        return neq1(n,m,k);
    }
    else{
        if(m==1){
            return meq1(n,m,k);
        }
        else{
            if(k==0){
                return keq0(n,m,k);
            }
            else{
                if(kprima==0){
                    return kprimaeq0(n,m,k);
                }
                else{
                    return func_aux(n,m,k);
                }
            }
        }
    }
}

int main()
{
    ios::sync_with_stdio(false), cin.tie(nullptr);
    ll m, n, k, t;
    cin>>t;
    for(int j=0;j<t;j++)
        {
            cin>>n;
            cin>>m;
            cin>>k;
            if(func(n,m,k))
            {
            cout<<"YES"<<endl;
            }
            else
            {
            cout<<"NO"<<endl;
            }
        }

    return 0;
}


#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <iomanip>
#include <queue>
#include <time.h>
#include <bitset>
#include <unordered_map>

using namespace std;

#define ll long long
#define ull unsigned long long
#define ft first
#define sc second
#define add push_back
#define all(v) v.begin(),v.end()
#define mpr make_pair
#define sz(v) v.size()
#define vi vector<int>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define FOR(i,a,b) for(ll i = (a); i < (b); i++)
#define FORD(i,a,b) for(ll i = (a); i >= (b); i--)
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

const ll MOD = 998244353;
const ll INF = 1e16;
const int N = 200005;

int main()
{

    fastio;

    int tt;
    cin>>tt;

    while(tt--)
    {
        int n,m,k;
        cin>>n>>m>>k;
        if(k % 2 != 0)
        {
            bool check = false;
            if((2*k) % m == 0 and m >= 2 and (n-((2*k)/m)) % 2 == 0)
            {
                check = true;
            }
            if(check)
            {
                cout<<"YES"<<endl;
            }
            else
            {
                cout<<"NO"<<endl;
            }
            continue;
        }
        else
        {
            bool check = false;
            if((2*k) % m == 0 and m >= 2 and (n-((2*k)/m)) % 2 == 0)
            {
                check = true;
            }
            if((k % n) % 2 == 0 and n % 2 == 0)
            {
                check = true;
            }
            if(check)
            {
                cout<<"YES"<<endl;
            }
            else
            {
                cout<<"NO"<<endl;
            }
            continue;
        }
    }

    return 0;
}

/*

░▒▒▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▒▒░
▒▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▒
▓▓▓▒░░▒▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
▓▓▓▓▒░░░▒▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▒▒░░▒▓▓▓▓▓▓▓
▓▓▓▓▓▒░░░░░▒▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▒▒░░░░▒▓▓▓▓▓▓▓
▓▓▓▓▓▓▓▒░░░░░▒▓▓▓▓▓▓▓▓▓▓▓▒░░░░░░░░░▒▓▓▓▓▓▓
▓▓▓▓▓▓▓▓▒░░░░░░▒▓▓▓▓▓▓▓▓▓▓▓▒▒░░░░░░▒▓▓▓▓▓▓
▓▓▓▓▓▓▓▓▓▒░░░░░░░▒▓▓▓▓▓▓▓▓▓▓▓▓▒░░░▒▓▓▓▓▓▓▓
▓▓▓▓▓▓▓▓▓▓▒░░░░░░░░░▒▓▓▓▓▓▓▓▓▓▓▒░▒▓▓▓▓▓▓▓▓
▓▓▓▓▓▓▓▓▓▓▓▓▒░░░░░░░░░░▒▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
▓▓▓▓▓▓▓▓▓▓▓▓▓▓▒░░░░░░░░░░░▒▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▒░░░░░░░░░░░▒▓▓▓▓▓▓▓▓▓▓▓▓▓
▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▒░░░░░░░░░░░░▒▓▓▓▓▓▓▓▓▓▓
▓▓▓▓▓▓▓▒░░▒▓▓▓▓▓▓▓▓▓▓▒░░░░░░░░░░░░▒▓▓▓▓▓▓▓
▓▓▓▓▓▓▒░░░░░▒▓▓▓▓▓▓▓▓▓▒░░░░░░░░░░░░░▒▓▓▓▓▓
▓▓▓▓▓▒░░░░░░░░▒▓▓▓▓▓▓▓▓▓▒░░░░░░░░░░░░░▒▓▓▓
▓▓▓▓▒░░░░░░░░░░░▒▓▓▓▓▓▓▓▓▓▒░░░░░░░░░░░░▒▓▓
▓▓▓▓▓▒░░░░░░░░▒▓▓▓▓▓▓▓▓▓▓▓▓▓▒░░░░░░░░░▒▓▓▓
▓▓▓▓▓▓▒░░░░▒▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▒░░░░░▒▓▓▓▓
▒▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▒
░▒▒▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▒▒░

*/#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <iomanip>
#include <queue>
#include <time.h>
#include <bitset>
#include <unordered_map>

using namespace std;

#define ll long long
#define ull unsigned long long
#define ft first
#define sc second
#define add push_back
#define all(v) v.begin(),v.end()
#define mpr make_pair
#define sz(v) v.size()
#define vi vector<int>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define FOR(i,a,b) for(ll i = (a); i < (b); i++)
#define FORD(i,a,b) for(ll i = (a); i >= (b); i--)
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

const ll MOD = 998244353;
const ll INF = 1e16;
const int N = 200005;

int main()
{

    fastio;

    int tt;
    cin>>tt;

    while(tt--)
    {
        int n,m,k;
        cin>>n>>m>>k;
        if(k % 2 != 0)
        {
            bool check = false;
            if((2*k) % m == 0 and m >= 2 and (n-((2*k)/m)) % 2 == 0)
            {
                check = true;
            }
            if(check)
            {
                cout<<"YES"<<endl;
            }
            else
            {
                cout<<"NO"<<endl;
            }
            continue;
        }
        else
        {
            bool check = false;
            if((2*k) % m == 0 and m >= 2 and (n-((2*k)/m)) % 2 == 0)
            {
                check = true;
            }
            if((k % n) % 2 == 0 and n % 2 == 0)
            {
                check = true;
            }
            if(check)
            {
                cout<<"YES"<<endl;
            }
            else
            {
                cout<<"NO"<<endl;
            }
            continue;
        }
    }

    return 0;
}

/*

░▒▒▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▒▒░
▒▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▒
▓▓▓▒░░▒▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
▓▓▓▓▒░░░▒▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▒▒░░▒▓▓▓▓▓▓▓
▓▓▓▓▓▒░░░░░▒▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▒▒░░░░▒▓▓▓▓▓▓▓
▓▓▓▓▓▓▓▒░░░░░▒▓▓▓▓▓▓▓▓▓▓▓▒░░░░░░░░░▒▓▓▓▓▓▓
▓▓▓▓▓▓▓▓▒░░░░░░▒▓▓▓▓▓▓▓▓▓▓▓▒▒░░░░░░▒▓▓▓▓▓▓
▓▓▓▓▓▓▓▓▓▒░░░░░░░▒▓▓▓▓▓▓▓▓▓▓▓▓▒░░░▒▓▓▓▓▓▓▓
▓▓▓▓▓▓▓▓▓▓▒░░░░░░░░░▒▓▓▓▓▓▓▓▓▓▓▒░▒▓▓▓▓▓▓▓▓
▓▓▓▓▓▓▓▓▓▓▓▓▒░░░░░░░░░░▒▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
▓▓▓▓▓▓▓▓▓▓▓▓▓▓▒░░░░░░░░░░░▒▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▒░░░░░░░░░░░▒▓▓▓▓▓▓▓▓▓▓▓▓▓
▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▒░░░░░░░░░░░░▒▓▓▓▓▓▓▓▓▓▓
▓▓▓▓▓▓▓▒░░▒▓▓▓▓▓▓▓▓▓▓▒░░░░░░░░░░░░▒▓▓▓▓▓▓▓
▓▓▓▓▓▓▒░░░░░▒▓▓▓▓▓▓▓▓▓▒░░░░░░░░░░░░░▒▓▓▓▓▓
▓▓▓▓▓▒░░░░░░░░▒▓▓▓▓▓▓▓▓▓▒░░░░░░░░░░░░░▒▓▓▓
▓▓▓▓▒░░░░░░░░░░░▒▓▓▓▓▓▓▓▓▓▒░░░░░░░░░░░░▒▓▓
▓▓▓▓▓▒░░░░░░░░▒▓▓▓▓▓▓▓▓▓▓▓▓▓▒░░░░░░░░░▒▓▓▓
▓▓▓▓▓▓▒░░░░▒▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▒░░░░░▒▓▓▓▓
▒▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▒
░▒▒▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▒▒░

*/


#include<bits/stdc++.h>
#define fi first
#define se second
#define LSON t << 1, l, mid
#define RSON t<< 1 | 1, mid + 1, r
#ifdef FEIFEI
#define Debug printf
#else
#define endl '\n'
#define Debug(...)
#endif

using namespace std;
typedef long long LL;
typedef pair<int, int> P;

const int maxn = 1e6 + 5;
const int mod  = 998244353;

void add(int &x, int y) {
    x += y;
    if(x >= mod) x -= mod;
}

int mask[11], sp[11];
int dp[2][1024];
void solve()
{
    int n, m, u, v, w;
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        cin >> u >> v;
        mask[u] |= 1 << v;
        mask[v] |= 1 << u;
    }

    for (int i = 0; i < 10; i++) sp[i] = (1 << i) - 1;

    u = 0;
    dp[u][0] = 1;
    for (int i = 0; i < n; i++) {
        v = u ^ 1;
        memset(dp[v], 0, sizeof(dp[v]));
        for (int j = 0; j < 1024; j++) {
            if (!dp[u][j]) continue;
            for (int x = 0; x < 10; x++) {
                w = j & mask[x];
                if (!(w & sp[x])) upd(dp[v][w | (1 << x)], dp[u][j]);
            }
        }

        u ^= 1;
    }

    int ans = 0;
    for (int i = 0; i < 1024; i++) upd(ans, dp[u][i]);
    cout << ans << endl;
}

int main()
{
#ifdef FEIFEI
    freopen("input.txt", "r", stdin);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);

    int pT = 1;
    //cin >> pT;
    while (pT--) {
        solve();
    }

    Debug("Time: %.3lfs\n", (double)clock() / CLOCKS_PER_SEC);
    return 0;
}


#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <iomanip>
#include<set>
#include <climits>
#include <bits/stdc++.h>
#define int long long

using namespace std;

main()
{
    vector<int> p = {1200, 1400, 1600, 1900, 2100, 2300, 2400, 2600, 3000};
    int r;
    cin>>r;
    int res, w=1000000;
    for(auto o: p)
    {
        if(o>r)
        {
            res=o;
            break;
        }
    }
    cout<<o;
}


#include<bits/stdc++.h>
using namespace std;
int r;
int main()
{
	cin>>r;
	if(r<0) cout<0;
	else if(r<1200) cout<<1200;
	else if(r<1400) cout<<1400;
	else if(r<1600) cout<<1600;
	else if(r<1900) cout<<1900;
	else if(r<2100) cout<<2100;
	else if(r<2300) cout<<2300;
	else if(r<2400) cout<<2400;
	else if(r<2600) cout<<2600;
	else if(r<3000) cout<<3000;
	return 0;
}


#include<bits/stdc++.h
using namespace std;
int main()
{
    int n;
    cin>>n;
    string s;
    for(int i=0;i<n;i++)
    cin>>s;
    cout<<"YES";
}


#include<bits/stdc++.h>
using namespace std;
string const t[]={"","","","the","","buffy","slayer","vampire"};
string s;
int main(){
    cin>>s;
    if(t[s.size()]=="")
        cout<<"none\n",exit(0);
    for(int i=0;i<s.size();i++)
        s[i]=(s[i]-97+t[i]-97)%26+97;
    cout<<s<<"\n";
}


n = int(input())
cnt = 0
for i in range(n):
    s = input()
    if "minos" in s:
        cnt+=1
if cnt==n: print("YES")
else: print("NO")


#include <bits/stdc++.h>
using namespace std;
int main()
{
   ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n>>m;
	a[1]=1;
	sum[1]=1;
	for(ll i=2;i<=n;i++){
		a[i]=sum[i-1];
		for(ll l=2,r;l<=i;l=r+1){
				r=min(i,i/(i/l));
			a[i]+=(r-l+1)*a[i/l];
			a[i]%=m;
			}
		sum[i]=(sum[i-1]+a[i])%m;
		}
	cout<<a[n]%m<<endl;
	return 0;
}