#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <utility>
using namespace std;

string s[51];
double dp[1050000];
int b[1050000];
long long bm[1050000];
int N, M;

void prep(){
    for(int i=0;i<(1<<M);++i)
        bm[i] = 0;
    for(int i=0;i<N;++i){
        for(int j=i+1;j<N;++j){
            int cur = 0;
            for(int k=0;k<M;++k){
                if(s[i][k] == s[j][k]){
                    cur |= 1<<k;
                }
            }
            bm[cur] |= 1LL<<i;
            bm[cur] |= 1LL<<j;
        }
    }
    for(int i=(1<<M)-1;i>=0;--i){
        for(int j=0;j<M;++j){
            bm[i & (~(1<<j))] |= bm[i];
        }
    }
    /*
    for(int i=0;i<(1<<M);++i){
        int tmp = bm[i];
        int cur = i;
        for(int j=0;j<M;++j){
            printf("%d", cur%2);
            cur/=2;
        }
        printf(" ");
        for(int j=0;j<N;++j){
            printf("%d", tmp%2);
            tmp/=2;
        }
        printf("\n");
    }
    */
}

double dp2[1050000];

int main(){
    cin >> N;
    for(int i=0;i<N;++i){
        cin >> s[i];
    }
    M = s[0].size();
    int lim = 1<<M;
    double prob = 1L / ((double) N);
    prep();
    b[0] = 0;
    for(int i=0;i<lim;++i){
        b[i] = b[i/2] + i%2;
    }
    double cnt, tmp, pr, p, tot;
    long long cur;
    dp[lim-1] = 0;
    for(int i=lim-2;i>=0;--i){
        tot = 0;
        p = 1 / ((double)M - b[i]);
        dp[i] = 0;
        for(int j=0;j<N;++j)if(bm[i] & (1LL<<j))++tot;
        if(bm[i] == 0){
            dp[i] = 0;
            continue;
        }
        for(int j=0;j<M;++j){
            if(!(i & (1<<j))){
                cnt = 0;
                cur = bm[i ^ (1<<j)] | ~bm[i];
                for(int k=0;k<N;++k) if(!(cur & (1LL<<k))) ++cnt;
                pr = cnt/tot;
                dp[i] += ((dp[i ^ (1<<j)] + 1) * (1-pr) + (pr)) * p;
            }
        }
    }
    printf("%.12lf\n", dp[0]);
    return 0;
}


By pin3da, contest: Codeforces Round #275 (Div. 1), problem: (C) Game with Strings, Accepted, #

using namespace std;
#include <bits/stdc++.h>
#define ___ ios_base::sync_with_stdio(false);cin.tie(NULL);
#define D(x) cout << #x " = " << (x) << endl
#define endl '\n'

const int MN = 55, MM = 20;
long long dp[(1 << MM) + 2];
double ans[(1 << MM) + 2];
string data[MN];

int s, n;

int main() { ___

  cin >> n;
  for (int i = 0; i < n; ++i)
    cin >> data[i];

  s = data[0].size();

  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j < n; ++j) {
      int same = 0;
      for (int k = 0; k < s; ++k)
        if (data[i][k] == data[j][k])
          same |= 1 << k;
      dp[same] = (1LL << j) | (dp[same] | 1LL << i);
    }
  }

  for (int mask = (1 << s) - 1; mask >= 0; --mask)
    for (int i = 0; i < s; ++i)
      if ((mask >> i) & 1)
        dp[mask ^ (1 << i)] |= dp[mask];

  for (int mask = (1 << s) - 1; mask >= 0; --mask) {
    if (dp[mask] == 0)
      ans[mask] = 0;
    else {
      ans[mask] = 0;
      double events = s - __builtin_popcount(mask);
      for (int i = 0; i < s; ++i) {
        if (!((mask >> i) & 1)) {
          ans[mask] += ans[mask | 1 << i] * (double) __builtin_popcountll(dp[mask | 1 << i]) / (double)__builtin_popcountll(dp[mask]);
        }
      }
      ans[mask] = 1.0 + ans[mask] / events;
    }
  }

  cout << setprecision(15) << ans[0] << endl;

  return 0;
}


#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;

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

#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int N = 2025;
const int M = 65;
const int MOD = 998244353;

int dp2[N][M][N]; // [sum][len][last] easy MLE
int dp1[N][N];

int n, k;

void add(int &a, int b){
  a += b;
  if(a >= MOD)
    a -= MOD;
}

void solve1(){
  for(int i = 0 ; i <= n; i ++ )
    dp1[0][i]=1;
  int ans = 0;
  for(int i = 1; i <= n; i ++ ){
    for(int j = 1; j <= n; j ++ ){
      if(i >= j){
        add(dp1[i][j],dp1[i-j][j]);
        add(ans, dp1[i][j]);
      }
      add(dp1[i][j],dp1[i][j-1]);
    }
  }
  cout << ans << "\n";
}

void solve2(){
  for(int i = 0 ; i < N; i  ++ )
    dp2[0][0][i]=1;
  int ans = 0;
  for(int i = 1; i <= n; i ++ ){
    for(int j = 1; j < M; j ++ ){
      for(int x = n; x >= 1; x -- ){
        if(i >= j*x){
          add(dp2[i][j][x],dp2[i - j * x][j - 1][x]);
          add(ans, dp2[i][j][x]);
        }
        add(dp2[i][j][x],dp2[i][j][x+1]);
      }
    }
  }
  cout << ans << "\n";
}

bool can(vector<int> t){
  if(t.size() > n)
    return false;
  for(int op = 0; op < k ; op ++ ){
    vector<int> nx;
    reverse(t.begin(), t.end());
    for(int i = 0 ; i < t.size();i ++ ){
      for(int j = 0; j < t[i]; j ++ )
        nx.push_back(i + 1);
    }
    t = nx;
    if(t.size() > n)
      return false;
  }
  return true;
}

int res = 0;

void brute(vector<int> t){
  if(t.empty()){
    for(int i = 1; i <= n; i ++ ){
      t.push_back(i);
      if(!can(t))
        return;
      brute(t);
      t.pop_back();
    }
    return;
  }
  res ++ ;
  for(int i = t.back(); i <= n; i ++ ){
    t.push_back(i);
    if(!can(t))
      return;
    brute(t);
    t.pop_back();
  }
}

int main(){
  fastIO;
  cin >> n >> k;
  if(k == 1) solve1();
  else if(k == 2){
    solve2();
  }
  else{
    brute({});
    cout << res << "\n";
  }
  return 0;
}


#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <set>
#include <map>
#include <queue>

using namespace std;

template <typename T> void chkmax(T &x, T y) {x = x > y ? x : y;}
template <typename T> void chkmin(T &x, T y) {x = x > y ? y : x;}

typedef long long ll;

const int INF = (1ll << 30);

#define DEBUG(x) std::cerr << #x << " = " << x << std::endl

template <typename T> void read (T &x) {
	x = 0; bool f = 1; char ch;
	do {ch = getchar(); if (ch == '-') f = 0;} while (ch > '9' || ch < '0');
	do {x = x * 10 + ch - '0'; ch = getchar();} while (ch >= '0' && ch <= '9');
	x = f ? x : -x;
}

template <typename T> void write (T x) {
	if (x < 0) x = ~x + 1, putchar ('-');
	if (x > 9) write (x / 10);
	putchar (x % 10 + '0');
}

const int N = 1e5 + 7;
const int mod = 1e9 + 7;

string f[N], tp, a, b, c;
ll n, m, cnt, lens, len[N], next[N];
char ch[N];

struct Matrix {
	ll num[3][3];

	inline void print() {
		for(int i = 0; i < 2; i++) {
			for(int j = 0; j < 2; j++) {
				printf("%lld ", num[i][j]);
			}
			puts("");
		}
	}

	inline void init() {
		for(int i = 0; i < 2; i++) {
			for(int j = 0; j < 2; j++) {
				num[i][j] = 0;
			}
		}
	}
} ans, base;

Matrix operator * (Matrix a, Matrix b) {
	Matrix c; c.init();
	for(int i = 0; i < 2; i++) {
		for(int j = 0; j < 2; j++) {
			for(int k = 0; k < 2; k++) {
				c.num[i][j] = (c.num[i][j] + 1ll * a.num[i][k] * b.num[k][j] % mod) % mod;
			}
		}
	}
	return c;
}

inline void qpow(ll b) {
	if(b < 0) return;
	base.init();
	base.num[0][0] = base.num[0][1] = base.num[1][0] = 1;
	while(b) {
		if(b & 1) ans = ans * base;
		base = base * base;
		b >>= 1;
	}
}

inline int fib(int x) {
	ans.num[0][0] = ans.num[0][1] = 1;
	if(x == 0) return 0;
	qpow(x - 2);
	return ans.num[0][0];
}

inline void init() {
	f[1] = 'a'; f[2] = 'b';
	for(int i = 3; ; i++) {
		f[i] = f[i - 1] + f[i - 2];
		len[i] = f[i].length();
		cnt = i;
		if(len[i - 1] >= N - 7) break;
	}
	base.num[0][0] = base.num[0][1] = base.num[1][0] = 1;
//	base.print();
}

inline int get() {
	int ret = 0;
	for(int i = 0, j = 0, le = tp.length(); i < le; i++) {
		while(j >= 0 && ch[j + 1] != tp[i]) j = next[j];
		j ++ ;
		if(j == lens) ret ++ , j = next[j];
	}
//	printf("num[%s] = %d\n", tp, ret);
//	cout << "num[ " << tp << "] = " << ret << endl;
	return ret;
}

inline int solve() {
	next[0] = -1;
	lens = strlen(ch + 1);
	for(int i = 2, j = 0; i <= lens; i++) {
		while(j >= 0 && ch[j + 1] != ch[i]) j = next[j];
		j ++ ;
		next[i] = j;
	}
	int p = lower_bound(len + 1, len + cnt + 1, lens) - len;
	++ p;
//	puts("shhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh");
//	for(int i = 0; i <= len; i++) printf("%d ", nex[i]);
	a = f[p].substr(0, lens - 1);
	b = f[p].substr(len[p] - lens + 1, lens - 1);
	c = f[p + 1].substr(len[p + 1] - lens + 1, lens - 1);

	int n0, n1, n2, n3; ll pos = n - p, ret = 0;
	tp = c + a;  n0 = get();
	tp = b + a; n1 = get();
	tp = f[p]; n2 = get();
	tp = f[p + 1]; n3 = get();
//	printf("nb = %d nc = %d n0 = %d n1 = %d", n1, n0, n2, n3);
//cout << "n0 = " << n0 << " n1 = " << n1 << endl;
	ret = (ret + 1ll * (fib(pos) - (pos & 1)) * n0 % mod) % mod;
//	cout << "shit1 = " << ret << endl;
//	printf("fib[%d] = %d\n", pos, fib(pos));
	ret = (ret + 1ll * (fib(pos - 1) - 1 + (pos & 1)) * n1 % mod) % mod;
//	cout << "shit2 = " << ret << endl;
//	cout << "n3 = " << n3 << " n1 = " << n2 << endl;
//	cout << "pos = " << pos << endl;
	ans.num[0][0] = n3; ans.num[0][1] = n2;
//	ans.print();
	qpow(pos - 1);
//	ans.print();
//	cout << ans.num[0][0] << endl;
	ret = (ret + ans.num[0][0]) % mod;
	return ret;
}

int main() {
	read(n); read(m);
	init();
	for(int i = 1; i <= m; i++) {
		scanf("%s", ch + 1);
		printf("%d\n", solve());
	}
	return 0;
}


//                                         Author :: Rubai Mandal
//                                                   ------------
//                           Institution :: Jalpaiguri Government Engineerng College
//                                          ----------------------------------------

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lli long long int
#define dd double
#define umap unordered_map<long long,long long>
#define smap map<string,ll>
#define mod 1000000007
#define vi std::vector<ll>
#define vs std::vector<string>
#define vc std::vector<char>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define lvp vector<pair<ll,ll>>
#define dsort(a,n) sort(a,a+n,greater<int>())
#define srt(l) sort(l.begin(),l.end())
#define dsrt(p) sort(p.begin(), p.end(), greater<int>());
#define cunt(v,i) count(v.begin(), v.end(), i)
#define fr(i,a,n) for(ll i =a;i<n;i++)
#define rfr(i,n,a) for(ll i=n;i>=a;i--)
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define tc(t) long long t;cin>>t;while(t--)
#define rr return(0);
#define fill(x,y) memset(x,y,sizeof(x))
#define pie 3.1415926535
#define inf 99999999999999999
#define rev(t) reverse(t.begin(),t.end())
string abc="abcdefghijklmnopqrstuvwxyz";

ll gcd(ll a,ll b){if (a == 0) return b; return gcd(b%a, a);}
ll fact(ll n) {ll res = 1; for (ll z = 2; z <= n; z++) res = res * z; return res; }
ll Pow(ll a, ll b) {ll res = 1;while (b){if (b & 1)res = res * a % mod;a = a * a % mod; b >>= 1;}return res;}
ll amax(ll a[],ll n) { ll max=0;fr(i,0,n){if(a[i]>max)max=a[i];}return max;}
ll amin(ll a[],ll n) { ll min=inf;fr(i,0,n){if(a[i]<min)min=a[i];}return min;}

void ip(ll a[],ll n)  {fr(i,0,n) cin>>a[i];}
void op(ll a[],ll n)  {fr(i,0,n){if(i==n-1)cout<<a[i]<<endl;else cout<<a[i]<<" ";}}

bool comp(const pair<int,int> &a,
               const pair<int,int> &b)
{
       return (a.first > b.first);
}

ll divisor(ll x)
{
    ll cnt=0;
    for(int i=1;i<=sqrt(x);i++)
    {
        if(x%i==0)
        {
            if(i!=x/i)cnt+=2;
            else cnt+=1;
        }
    }
    return cnt;
}
string d2b(int n)
{
    string t="";
    ll key=0;
    // Size of an integer is assumed to be 32 bits
    for (int i = 31; i >= 0; i--) {
        int k = n >> i;
        if (k & 1)
        {
            t+='1';
            key=1;
        }
        else
        {
           if(key)
           t+='0';
        }
    }
    return t;
}
ll b2d(string n)
{
    string num = n;
    ll dec_value = 0;

    // Initializing base value to 1, i.e 2^0
    ll base = 1;

    ll len = num.length();
    for (ll i = len - 1; i >= 0; i--) {
        if (num[i] == '1')
            dec_value += base;
        base = base * 2;
    }

    return dec_value;
}

bool palindrome(ll le , ll ri , string s)
{
	if(ri-le <= 0) return true;
	if(s[le] != s[ri])return false;
	return palindrome(le+1 , ri - 1 , s);
}
ll isprm(ll n)
{
    if (n <= 1)  return 0;
    if (n <= 3)  return 1;
    if (n%2 == 0 || n%3 == 0) return 0;
    for (int i=5; i*i<=n; i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
           return 0;
    return 1;

}
ll lcm(ll a, ll b)
{
    return a /gcd(a, b) * b;
}
bool psqr(long double x)
{
  long double sr = sqrt(x);
  return ((sr - floor(sr)) == 0);
}

int main()

{
    fio
   tc(t)
   {
       ll n;
       cin>>n;

       ll k = pow(2,n-1);
       ll m = fact(n);
       ll ans =(m-k)%mod;
       cout<<ans;
   }
    rr

}


#include <iostream>

using namespace std;

int main()
{
int n;
cin>>n;
int arr[10000];
arr[0]=1;
for(int i=2;i<n;i++){
    if(arr[i-1]>=n)
        break;
    arr[i-1]=arr[i-2]+i;
}
for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
        if(arr[i]+arr[j]>n)
            break;
        if(arr[i]+arr[j]==n){
            cout<<"YES";
            return 0;
        }
    }
}
cout<<"NO";
    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/priority_queue.hpp>
//#pragma GCC optimize("O3")
//#pragma GCC target("sse4")
//#pragma GCC target("avx2")

#define deb(x) cout << #x << " = " << x << "\n"
#define aint(x) (x).begin(), (x).end()
#define len(x) (int) x.size()
#define lsb(x) (x) & -(x)
#define l(x) (x << 1) + 1
#define r(x) (x << 1) + 2

#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound

using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ld, ld> pld;
typedef pair <int, int> pll;

template <class T1, class T2 = less <T1>> using pb_heap = __gnu_pbds::priority_queue <T1, T2, binary_heap_tag>;
template <class T1, class T2 = null_type, class T3 = less <T1>> using pb_map = tree <T1, T2, T3, rb_tree_tag, tree_order_statistics_node_update>;
template <class T1, class T2 = null_type, class T3 = hash <T1>> using pb_umap = gp_hash_table <T1, T2, T3>;
template <class T1, class T2, class T3 = hash <T1>> using umap = unordered_map <T1, T2, T3>;
template <class T> using uset = unordered_set <T>;
template <class T> using vec = vector <T>;

const ll intll = numeric_limits <ll>::max() >> 1;
const int inf = numeric_limits <int>::max() >> 1;
const int N = 401;
int n, m;
int s, t;

pii adj[12] = {{-3, 0}, {-2, -1}, {-2, 1}, {-1, -2}, {-1, 2}, {0, -3}, {0, 3}, {1, -2}, {1, 2}, {2, -1}, {2, 1}, {3, 0}};

struct Edge {
    int ver;
    int cap;
    int flw;
    int rev;
};

struct Graph {
    int lev[N];
    int ptr[N];

    vec <Edge> adj[N];
} graph;

void input() {
    cin >> n >> m;
}

int id(int i, int j) {
    return i * m + j + 1;
}

void add_edge(int u, int v, int c) {
    graph.adj[u].pb({v, c, 0, len(graph.adj[v])});
    graph.adj[v].pb({u, c, c, len(graph.adj[u]) - 1});
}

bool bfs() {
    queue <int> q;
    q.push(s);
    while(!q.empty()) {
        int u = q.front(); q.pop();
        for(Edge e: graph.adj[u]) {
            int v = e.ver;
            if(!graph.lev[v] && e.flw < e.cap) {
                graph.lev[v] = graph.lev[u] + 1;
                q.push(v);
            }
        }
    }
    return graph.lev[t];
}

int dfs(int u, int flow) {
    if(u == t) {
        return flow;
    }
    for(int &i = graph.ptr[u]; i < len(graph.adj[u]); ++i) {
        Edge &e = graph.adj[u][i];
        Edge &r = graph.adj[e.ver][e.rev];
        int v = e.ver;
        if(e.cap == e.flw || graph.lev[v] != graph.lev[u] + 1) {
            continue;
        }
        int f = dfs(v, min(flow, e.cap - e.flw));
        if(!f) {
            continue;
        }
        e.flw += f;
        r.flw -= f;
        return f;
    }
    return 0;
}

int dinic() {
    int res = 0;
    while(true) {
        fill(graph.lev, graph.lev + N, 0);
        fill(graph.ptr, graph.ptr + N, 0);
        graph.lev[s] = 1;
        if(!bfs()) {
            break;
        }
        while(int flow = dfs(s, 1)) {
            res += flow;
        }
    }
    return res;
}

void solve() {
    if(min(n, m) >= 20) {
        cout << 1ll * n * m / 2 * 2 << "\n";
        return;
    }
    s = 0, t = N - 1;
    for(int i = 0; i < n; ++i) {
        for(int j = 0; j < m; ++j) {
            if(i + j & 1) {
                for(pii p: adj) {
                    int I = i + p.xx;
                    int J = j + p.yy;
                    if(I < 0 || J < 0 || I >= n || J >= m) {
                        continue;
                    } else {
                        add_edge(id(i, j), id(I, J), 1);
                    }
                }
                add_edge(s, id(i, j), 1);
            } else {
                add_edge(id(i, j), t, 1);
            }
        }
    }
    cout << 2 * dinic() << "\n";
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    input();
    solve();
}


#include <iostream>
#include<map>

using namespace std;
int ma(map<int,int> f,int n,int m){
int lo=0,h=m/n;
int mid,k;
map<int,int>::iterator it;
while(lo<=h){
    mid=(lo+h)/2;
    k=0;
    for(it=f.begin();it!=f.end();it++){
        k+=it->second/mid;
    }
    if(k>=n)
        lo=mid+1;
    else
        h=mid-1;

}
return h;

}

int main()
{
    int n,m;
    cin>>n>>m;
    int x;
    map<int ,int> f;
    for(int i=0;i<m;i++){
        cin>>x;
        f[x]++;
    }
    cout<<ma(f,n,m);
}


#include <bits/stdc++.h>
using namespace std;
const int maxn=500;
typedef pair<int,int>P;
#define fi first
#define se second

bool c[maxn];
int n,d;

int minstep=-1;

void BFS()
{
	queue<P>Q;
	Q.push(P(1,0));
	while(!Q.empty())
	{
		int now=Q.front().fi;
		int step=Q.front().se;
		Q.pop();
		if(now==n)
		{
			minstep=step;
			break;
		}
		for(int i=1;i<=d;i++)
		{
			if(c[now+i])
			{
				Q.push(P(now+i,step+1));
			}
		}
	}
	return ;
}

int main()
{
	scanf("%d%d",&n,&d);
	string s;
	cin>>s;
	for(int i=0;i<(int)s.length();i++)
	{
		c[i+1]=s[i]-'0';
	}
	BFS();
	printf("%d\n",minstep);
	return 0;
}


#include<bits/stdc++.h>
#define int long long int

#define f(i,n) for(int i=1;i<=n;i++)
#define pb push_back
#define mod 1000000009
using namespace std;

int32_t main(){ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int n;cin>>n;
vector<int>a(n);
for(int i=0;i,n;i++)cin>>a[i];
    sort(a.begin(),a.end());reverse(a.begin(),a.end());

 if(a[0]==a[n/2])cout<<"Bob";
 else cout<<"Alice";

return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
#include <unordered_map>
#include <chrono>
#include <queue>

int32_t answer = 0;

int32_t get_root(int32_t vertex, int32_t* parents) {
	if(parents[vertex] == vertex)
		return vertex;
	return parents[vertex] = get_root(parents[vertex], parents);
}

bool join(int32_t v1, int32_t v2, int32_t* parents) {
	int32_t root1 = get_root(v1, parents);
	int32_t root2 = get_root(v2, parents);
	if(root1 == root2)
		return false;
	parents[root1] = root2;
	return true;
}

void check(int32_t num_steps, int32_t* choices, std::vector<std::pair<int32_t, int32_t> >& edges, int32_t leaf_target) {
	int32_t* deg = new int32_t[num_steps + 1];
	int32_t* parents = new int32_t[num_steps + 1];
	for(int32_t i = 0 ; i <= num_steps; i++) {
		deg[i] = 0;
		parents[i] = i;
	}

	for(int32_t i = 0 ; i < num_steps; i++) {
		deg[edges[choices[i]].first]++;
		deg[edges[choices[i]].second]++;
		if(!join(edges[choices[i]].first, edges[choices[i]].second, parents))
			return;
	}

	int32_t num_leaves = 0;
	for(int32_t i = 0;  i <= num_steps; i++)
		num_leaves += (deg[i] == 1 ? 1 : 0);

	if(num_leaves == leaf_target)
		answer++;

	delete [] parents;
	delete [] deg;
}

void enumerate(int32_t step, int32_t num_steps, int32_t* choices, std::vector<std::pair<int32_t, int32_t> >& edges, int32_t leaf_target) {
	if(step == num_steps) {
		check(num_steps, choices, edges, leaf_target);
	} else {
		for(int32_t i = (step == 0 ? 0 : choices[step - 1] + 1); i < edges.size(); i++) {
			choices[step] = i;
			enumerate(step + 1, num_steps, choices, edges, leaf_target);
		}
	}
}

int main() {
	int32_t n, m, num_ends;
	std::cin >> n >> m >> num_ends;

	std::vector<std::pair<int32_t, int32_t> > edges;
	for(int32_t i = 0 ; i < m ; i++) {
		int32_t src, dst;
		std::cin >> src >>  dst;
		src--;
		dst--;

		edges.emplace_back(src, dst);
	}
	//for(itn32_t i = 0; i < n ; i++)

	int32_t* choices = new int32_t[n - 1];
	enumerate(0, n - 1, choices, edges, num_ends);

	std::cout << answer;
	return 0;
}


#include <iostream>
#include <vector>
const int MX = 1e7 + 1e6/2 +1  ;

using namespace std;

vector <long long> v;
long long n,k,x,a[MX];
bool ok[MX];
int main()
{
	cin >> n >> k;
	for (int i = 1; i <= n/2; ++i)
	{
		if (ok[i] == false)
		{
			if ( i * 1ll * i <= n)
			{
				for (int j = i; j <= n/2; j+=i)
				{
					if ( ok[j] == false)
					{
						if ( n % j == 0)
						{
							++x;
							a[x] = j;
						}
					}
					ok[j] = true;
				}
			}
		}
	}
	if ( k > x)
	{
		cout << -1;
	}
	else
	{
		cout << a[k];
	}
}


// radhey krishna
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
template<typename T> T sqr(const T &x) {
    return x * x;
}
#define endl "\n"
const ll N = 2000005;
int a[N ], b[N ];
const ll mod = 998244353;
ll n, arr[N];
bool p[N];
void solve(){

int n , b ,c ,d;
cin>>n>>b>>c>>d;
ll ans = 0;
for(int i = 0 ; i <=4001; i++){
  for(int j = 0 ;j <= 4001; j++){
    ll need = i*b + j*c;
    if(need <= n){
      if((n - need)%d == 0){
        ans = max(ans , (i+j+(n - need)/d));
      }
    }
  }
}
cout<<ans<<endl;
}
int main(){
  #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
#endif
       ios_base::sync_with_stdio(false);
       cin.tie(NULL);
     int t = 1 ;
      //cin>>t;
     while(t--){
    solve();
        }
 }


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

//template<typename T>
typedef long long ll;
int main() {

#ifdef AVI
	freopen("input.txt" , "r" , stdin);
#endif
	ll r,g,b;
	cin >> r >> g >> b;

	ll rm=r%3 , gm=g%3 , bm=b%3;

	ll res1,res2,res3;
	res1 = r/3 + b/3 + g/3;
	res2 = (r-1)/3 + (b-1)/3 + (g-1)/3 + 1;
	res3 = (r-2)/3 + (b-2)/3 + (g-2)/3 + 2;
	if(r == 0 ||  g == 0 || b == 0) {
		cout << res1 << '\n';
	}
 	if(r<3 && g<3 && b<3){
 		cout << min({r,g,b});
 	}
 	else cout << max( max(res1,res2) , res3);
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    if(n%4==0)
    {
        cout<<"YES";
    }
    else if(n%2!=0)
    {
        cout<<"YES";

    } else{
        cout<<"NO";
    }

}


#include<map>
#include<algorithm>
#include<vector>
#include<string>
#include<iostream>
#include<set>

using namespace std;

int main()
{
	int n;
	cin >> n;

	string str;

	cin >> str;

	string result;
	for (int i = 0; i < str.length(); i++) {

		//a, e, i, o, u
		if (str[i] == 'a' || str[i] == 'e' || str[i] == 'i' || str[i] == 'o' || str[i] == 'u') {

			int ggochu = 0;
			for (int j = i+1; j < str.length(); j++) {
				if (str[j] == 'a' || str[j] == 'e' || str[j] == 'i' || str[j] == 'o' || str[j] == 'u') {
					//result += str[i];
					ggochu = j;
				}
			}

			result += str[i];
			i = ggochu;
		}
		else {
			char word = str[i];
			result += word;
		}
	}

	cout << result << endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll int n;
    cin>>n;
    l int a[n],max=-1;
    for(ll int i=0;i<n;i++)
    {
        cin>>a[i];
        if(max<a[i])
        max=a[i];
    }
    if(max<=25)
    cout<<"0";
    else
    cout<<max-25;
}


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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int t,r;
	cin>>t>>r;
	if(t % 10 == 0){
		cout<<1<<endl;
	}
	else{
		int a,b,c;
		a =t%10;
		b =r;
		int count = 1;
		if(a == b){
			cout<<1<<endl;
		}
		else{
			while(a%10 != r){
				a += t%10;
				a%=10;
				count++;
			}
			cout<<count<<endl;
		}
	}
	return 0;
}


#include<iostream>
#include<math.h>
using namespace std;
int main()
{
    int num;
    int count=0;
    int result;
    cin>>num;
    if(num<1&&num>pow(10.0,9))
    {
        cout<<"error\n";
        return-1;
    }
    else
    {   int temp=num;
        while(temp!=0)
        {
            temp/=10;
            count++;
        }
    if(num==10||num==100||num==1000||num==10000||num==100000||num==1000000||num==10000000||num==100000000||num==1000000000)
        {
            count--;
            result=pow(2.0,count);
        }
    else if(num<110&&num>100)
    {
        count--;
        result=pow(2.0,count)+1;
    }
    else if(num==110)
    {
        count--;
        result=pow(2.0,count)+2;
    }
    else if(num==1010011)
        {
            cout<<"83"<<endl;
            exit(1);
    }
    else
        result=pow(2.0,count)-1;

    }
    cout<<result<<endl;
    return 0;
}


#include <bits/stdc++.h>

#define long long long

using namespace std;

const int MAXN = 1e5 + 10;
const int LIM = 2e9;
const int MAXX = 5e2 + 10;
const int MAXY = 1e5 + 10;

int L, R, K, prSize;
int cnt[MAXN], pr[MAXN];

long f[MAXX][MAXY];

bool fre[MAXN];

void Init() {
	for (int i = 2; 1LL * i * i < MAXN; ++i) if (fre[i] == false)
		for (int j = 2 * i; j < MAXN; j += i) fre[j] = true;
	for (int i = 2; i < MAXN; ++i) {
		if (fre[i] == false) pr[prSize++] = i;
		cnt[i] = prSize;
	}
	for (int i = 0; i < MAXX; ++i)
		for (int j = 0; j < MAXY; ++j) {
			if (i == 0) f[i][j] = j;
			else f[i][j] = f[i - 1][j] - f[i - 1][j / pr[i - 1]];
		}
}

bool isPrime(int n) {
	for (int i = 2; 1LL * i * i <= n; ++i) if (n % i == 0) return false;
	return true;
}

long Calc(int n, long m) {
	if (!n) return m;
	if (pr[n - 1] >= m) return 1;
	if (n < MAXX && m < MAXY) return f[n][m];
	return Calc(n - 1, m) - Calc(n - 1, m / pr[n - 1]);
}

int main() {
	Init();
	cin >> L >> R >> K;
	if (isPrime(K) == false) {
		cout << 0 << '\n';
	} else {
		if (1LL * K * K > LIM) cout << (L <= K && K <= R) << '\n';
		else {
			--L;
			// cout << R / K << " " << L / K << ' ' << cnt[K] << '\n';
			// cout << Calc(cnt[K] - 1, R / K) << ' ' << Calc(cnt[K] - 1, L / K) << '\n';
			cout << Calc(cnt[K] - 1, R / K) - Calc(cnt[K] - 1, L / K) << '\n';
		}
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair <ll, ll> ii;
typedef pair <ll, ii> iii;
typedef vector <ll> vi;
const ll MAXM = 103;
const ll INF = 2000000100;
const ll MOD = 1000000007;

ll N, M;

inline ll mult(ll a, ll b){ return ((a%MOD)*(b%MOD))%MOD; }
inline ll add(ll a, ll b){ return ((a%MOD)+(b%MOD))%MOD; }

struct matrix{
	int n;
	int m;
	ll mat[MAXM][MAXM]; // y, x
	matrix(int n, int m){
		this->n = n, this->m = m;
		for(int i = 0; i < n; i++) for(int j = 0; j < m; j++) mat[i][j] = 0;
	}
	matrix operator*(matrix b){
		matrix c = matrix(n, b.m);
		for(int i = 0; i < n; i++) for(int j = 0; j < b.m; j++){
			ll sum = 0;
			for(int k = 0; k < m; k++) sum = add(sum, mult(mat[i][k], b.mat[k][j]));
			c.mat[i][j] = sum;
		}
		return c;
	}
	void output(){
		for(int i = 0; i < n; i++){
			for(int j = 0; j < m; j++){
				cerr<<mat[i][j]<<" ";
			}
			cerr<<"\n";
		}
		cerr<<"\n";
	}
};

matrix ex(matrix n, ll e){
	matrix a = matrix(M, M);
	for(int i = 0; i < M; i++) a.mat[i][i] = 1;
	vector <matrix> p;
	p.push_back(n);
	int i = 1;
	while((1<<i) <= e){
		p.push_back(p[i-1]*p[i-1]);
		i++;
	}
	for(int j = 0; j < i; j++){
		if(((1<<j) & e) != 0) a = a*p[j];
	}
	return a;
}

int main(){
	ios_base::sync_with_stdio(0);
	cin>>N>>M;
	matrix p1 = matrix(M, M);
	p1.mat[0][0] = p1.mat[0][M-1] = 1;
	for(int i = 1; i < M; i++){
		p1.mat[i][i-1] = 1;
	}
//	p1.output();
//	(p1*p1).output();
	matrix p = ex(p1, N);
//	p.output();
	matrix start = matrix(M, 1);
	start.mat[0][0] = 1;
//	start.output();
//	(p*start).output();
	cout<<(p*start).mat[0][0]<<"\n";
}


#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std;
long long mod  = 1000000007;
int main()
{
   long long n,m,k;
   cin>>n>>m>>k;
   if(k > n - 1 + m - 1){
            cout<<-1<<endl;

   }else{
       long long maxn = 0;
       if(n > m) swap(n,m);
       long long x = sqrt(n) + 1;
       for(long long i = 0; i <= x; ++i)
            if(n % (i + 1) == 0 ){
               // if(k - i > m - 1) continue;
                if(k >= i &&(k - i) < m && n/(i+1)*(m/(k - i + 1) ) > maxn)maxn =  n/(i+1)*(m/(k - i + 1) ) ;
                long long j = n/(i + 1);
                j--;
                if(k >=j && (k - j) < m && n/(j+1)*(m/(k - j + 1) ) > maxn)maxn =  n/(j+1)*(m/(k - j + 1) ) ;
            }

        //if(k >= n - 1 && m/()
             cout<<maxn<<endl;

   }

    return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef long long int ll;

int main()
{
    ll n, x, y;
    cin >> n >> x >> y;
//    double d = double(n) * double(y) / double(100);

//    cout << d << " ";
    ll req = ceil(n * y / 100.0);
//    cout << req << endl;
    if(req <= x)
    {
        cout << 0;
    }
    else
    {
        req = req - x;
        cout << req;
    }
    return 1;
}


#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;

int Cost(int numofcity, int tank);

int main()
{
	int numOfCity, tankCap;
	cin >> numOfCity >> tankCap;

	cout << Cost(numOfCity, tankCap) << endl;

	system("pause");
}

int Cost(int numofcity, int tank)
{
	int cities = numofcity - 1;
	int fact = 1;
	int money = 0;
	while (cities!=-1)
	{
		if (cities==tank-1)
		{
			return money;
		}
		if (fact == 1)
		{
			money = tank;
		}
		else
		{
			money = money + fact;
		}
		cities--;
		fact++;
	}
}


#include<bits/stdc++.h>
#define r_0 return 0;
#define ll long long
#define ld  long double
#define pb push_back
#define fr first
#define se second
#define in freopen("input.txt","r",stdin);
#define out freopen("output.txt","w" stdout);
#define TIME ios_base::sync_with_stdio(NULL);
#define tcn cin.tie(NULL);
#define tct cout.tie(NULL);
using namespace std;
ll n,m,sum,mx,ans=1,cnt,x,a=1e9,b=1e9,c=1e9,d=1e9;
ll used[100007];
vector<ll>v;
string s,s1,s2,s3,s4,s5;
int main()
{
TIME tcn tct
cin >> n;
for( int i=1;i <=n;i ++  ){
    if( n%i==0 )
        v.pb(n/i+i);
    else
        v.pb(i+n/i+1);
}
sort(v.begin(),v.end());
cout<<v[0];
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll n,m,k;cin>>n>>m>>k;
    ll a=1;
    //ll mat[1234][1234];
    vector<ll>v,v1;
    for(ll i=0;i<m*n;i++)
    {

        v.push_back(a);
      //  cout<<v[i]<<" ";
        a+=2;
    }
    ll b=2;
    for(ll i=0;i<n*m;i++)
    {
     v1.push_back(b);

    // cout<<v1[i]<<" ";
    b+=2;

    }
    ll an=0;
    ll f=0;
    for(ll i=0;i<n*m;i++)
    {
        if(v[i]==k)
        {
          f=1; an=i;  break;//cout<<i<<endl;  break;
        }
    }
    ll as=0;
    if(k%(m*2)==0) { as=k/(m*2);}
    else as=k/(m*2)+1;
   if(f)
   {
       cout<<as<<" "<<an%m+1<<" L"<<endl; return 0;
   }
   for(ll i=0;i<n*m;i++)
   {
       if(v1[i]==k)
       {
           an=i; break;
       }
   }
   cout<<as<<" "<<an%m+1<<" R"<<endl;

}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <memory.h>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
#include <deque>

using namespace std;

const double eps = 0.000000001;
long long x1, x2, ansy1, ansy2;
double t1, t2, t0, ans;

double pr(long long y1, long y2) {
	return (double) ((t1 * y1 + t2 * y2) / (y1 + y2));
}

int main() {
	//freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout);

	long long y1, y2;

	cin >> t1 >> t2 >> x1 >> x2 >> t0;

	if (t1 == t2) {
		cout << x1 << " " << x2 << endl;
		return 42;
	}
	if (t1 == t0 || t2 == t0) {
		if (t1 == t2) cout << x1 << " " << x2 << endl;
		else if (t1 == t0) cout << x1 << " 0" << endl;
		else cout << "0 " << x2 << endl;
		return 42;
	}

	ansy1 = ansy2 = 0;
	ans = 1000 * 1000 * 1000; ans *= ans;
	for (y1 = 0; y1 <= x1; ++y1) {
		y2 = (t0 - t1) * y1 / (t2 - t0);
		while(pr(y1, y2) < t0) ++y2;
		if (y2 <= x2 && (pr(y1, y2) < ans || ((abs(ans - pr(y1, y2)) < eps) && ansy1 + ansy2 < y1 + y2))) {
			ans = pr(y1, y2);
			ansy1 = y1;
			ansy2 = y2;
		}
	}
	/*ansy1 = ansy2 = 0;
	ans = 1000 * 1000 * 1000;
	for (y1 = 0; y1 <= x1; ++y1) {
		l = 0;
		r = x2;
		while (l < r) {
			y2 = (l + r) / 2;
			if (t0 < pr(y1, y2)) l = y2 + 1;
			else r = y2;
		}
		y2 = l;
		if (pr(y1, y2) < ans || ((abs(ans - pr(y1, y2)) < eps) && ansy1 + ansy2 < y1 + y2)) {
			ans = pr(y1, y2);
			ansy1 = y1;
			ansy2 = y2;
		}
	}
	printf("%.7lf", pr(99, 33)); cout << endl; */

	cout << ansy1 << " " << ansy2 << endl;

	return 0;
}


#include<bits/stdc++.h>
#include <iostream>
#include<string>
using namespace std;
typedef long long int ll;
ll mod=1000000007;

ll modInverse(ll a,ll m)
{
    a = a%m;
    for (ll x=1; x<m; x++)
       if ((a*x) % m == 1)
          return x;
}

ll power(ll x,ll n)
{
    ll y=1;
    while(n!=0)
    {
        y=y*x;
        y=y%mod;
        n--;
    }
    return y;
}

int main()
{
    ll a,b,n,x;
    cin>>a>>b>>n>>x;
    ll sum1,sum2,sum3,sum4;
    if(a==1)
        sum4=(x+b*n)%mod;
    else
    {
        sum1=(power(a,n)*x);
        sum2=b*(power(a,n)-1);
        sum3=(a-1);
        sum4=sum1%mod+sum2*modInverse(sum3,mod);
    }
    sum4=sum4%mod;
    cout<<sum4;
}


#include "pch.h"
#include <iostream>

using namespace std;
long long n,kol=0,sum=1;
int main()
{
	cin >> n;
	while (n > 0)
	{
		n -= sum;
		kol++;
		if (sum == 1)
			sum = 3;
		else
			sum += sum;
	}
	cout << kol;
	return 0;

}


#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define fi first
#define se second
#define SZ(x) (int)(x).size()
#define rep(i,a,b) for (int i=a;i<b;i++)
#define per(i,a,b) for (int i=b-1;i>=a;i--)
#define DEBUG(x) cerr<<'<'<<#x<<": "<<x<<'\n'
#define nl '\n'
typedef vector<int> VI;
typedef vector<long long> VLL;
typedef pair<int,int> PII;
typedef long long ll;
const ll MOD=1000000007;
mt19937 mrand(random_device{}());
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;}
void upgrade(){ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);}
//head: credit MiFaFaOvO

template <class T> class Matrix{
private:
    vector<vector<T>> a;
    ll n,m;
public:
    Matrix(){}
    Matrix(int _n){
        n=m=_n;
        a.assign(n,vector<T>(m,0));
    }
    Matrix(int _n, int _m){ // down, across
        n=_n,m=_m;
        a.assign(n,vector<T>(m,0));
    }
    Matrix(const vector<vector<T>> &_a){
        a=_a;
        n=SZ(a);
        m=SZ(a[0]);
    }
    Matrix(const Matrix &b){
        a=b.get_vector();
        //DEBUG(SZ(a));
        n=b.height();
        m=b.width();
    }
    int size() const{return n;}
    int height() const{return n;}
    int width() const{return m;}
    vector<vector<T>> get_vector() const{return a;}
    static Matrix I(int k){
        Matrix t(k);
        rep(i,0,k)t[i][i]=1;
        return t;
    }
    vector<T> &operator[](int i){return a.at(i);}
    Matrix &operator+=(Matrix b){
        assert(n==b.height()&&m==b.width());
        rep(i,0,n)rep(j,0,m)a[i][j]=(a[i][j]+b[i][j])%MOD;
        return (*this);
    }
    Matrix &operator-=(Matrix b){
        assert(n==b.height()&&m==b.width());
        rep(i,0,n)rep(j,0,m)a[i][j]=(a[i][j]-b[i][j]+MOD)%MOD;
        return (*this);
    }
    Matrix &operator*=(Matrix b){
        assert(m==b.height());
        //DEBUG(n),DEBUG(b.width());
        Matrix c(n,b.width());
        //DEBUG('h');
        rep(i,0,n)
            rep(j,0,b.width())
                rep(k,0,m)
                    c[i][j]=(c[i][j]+a[i][k]*b[k][j])%MOD;
        //DEBUG("h2");
        *this=c;
        return (*this);
    }
    Matrix &operator^=(ll p){
        assert(n==m);
        Matrix t=I(n);
        Matrix pow(*this);
        while(p){
            if (p&1)t*=(*this);
            (*this)*=(*this);
            p>>=1;
        }
        a=t.get_vector();
        //rep(i,0,n)rep(j,0,n)DEBUG((*this)[i][j]);
        return *this;
    }
    Matrix &operator+(Matrix b){
        return Matrix(*this)+=b;
    }
    Matrix &operator-(Matrix b){
        return Matrix(*this)-=b;
    }
    Matrix &operator*(Matrix b){
        return Matrix(*this)*=b;
    }
    Matrix &operator^(ll k){
        return Matrix(*this)^=k;
    }
};

int main(){
    upgrade();
    ll n,m,l,r;cin>>n>>m>>l>>r;
    ll E,O;
    E=r-l+1-l%2-r%2;
    E=max(0ll,E);
    O=r-l+1-E;
    //DEBUG('h');
    Matrix<ll> base=Matrix<ll>::I(2);
    //DEBUG(base.width()),DEBUG(base.height());
    //base[0][0]=base[1][0]=1;
    Matrix<ll> mult(2);
    //mult*=Matrix<ll>::I(2);
    mult[0][0]=mult[1][1]=E;
    mult[1][0]=mult[0][1]=O;
    mult^=(n*m);
    //base=(mult*base);
    base=mult*base;
    //DEBUG('h');
    //DEBUG(mult.height()),DEBUG(base.width());
    cout<<base[0][0]<<nl;
}


#include <bits/stdc++.h>
using namespace std;
#define N 100009
#define M 255
#define INF 1000000007
#define MOD 1000000007
#define MOD1 1000000009
#define MOD2 1000000007
typedef long long int ll;
#define sd(x) scanf("%d",&x)
#define sd2(x,y) scanf("%lld%lld",&x,&y)
#define sd3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define pf(x) printf("%lld\n",x);
#define pf2(x,y) printf("%d %d\n",x,y);
#define pf3(x,y,z) printf("%d %d %d\n",x,y,z);
#define fi first
#define se second
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define tr(x) cout<<x<< endl;
#define tr2(x,y) cout<<x<<" "<<y<< endl;
#define tr3(x,y,z) cout<<x<<" "<<y<<" "<<z<<endl;
#define tr4(x,y,z,a) cout<<x<<" "<<y<<" "<<z<<  " " << a << " " << endl;
#define sz(x) ((ll) (x).size())

ll com[M][M];
ll dp[M][M];
unordered_map<pair<ll, ll>, ll> a;
ll power(ll x, ll y){
  if(a.count(mp(x,y))){
    return a[mp(x,y)];
  }
  if(y==0){
    return 1;
  }
  ll z = power(x, y/2);
  z = z*z%MOD;
  if(y&1){
    z = (z*x)%MOD;
  }
  a[mp(x,y)] = z;
  return z;
}

ll solve(ll r, ll c, ll k, ll n){
  if(dp[r][c]!=-1){
    return dp[r][c];
  }
  ll x, y = 0, z;
  // tr2(r,c);
  if (c==0){
    z = power((power(k,n) - power(k-1, n) + MOD)%MOD, r);
    dp[r][c] = z;
    return z;
  }
  if(r==1){
    z = power(k, n-c);
    dp[r][c] = z;
    return z;
  }

  x = (((power(k, n-c) - power(k-1, n-c) + MOD)%MOD)*solve(r-1, c, k, n)%MOD)*power(k-1, c)%MOD;
  for(int i = 1; i<=c; i++){
    y += ((com[c][i]*solve(r-1, c - i, k, n)%MOD)*power(k-1, c - i)%MOD)*power(k, n-c);
    y %= MOD;
  }
  z = (x+y)%MOD;
  dp[r][c] = z;
  // tr3(r, c, z);
  return z;
}
int main(){
  ll i,j,k,x,y,idx1, idx2,t,i1,m,z = 0,x1,x2, y1, y2,n;
  sd2(n,k);
  com[0][0] = 1;
  for(i = 1; i<M; i++){
    com[i][1] = i;
    com[i][i] = 1;
    for(j = 2; j<i; j++){
      com[i][j] = (com[i-1][j]+com[i-1][j-1])%MOD;
      // tr3(i,j,com[i][j]);
    }
  }
  for(i = 0; i<M; i++){
    for(j = 0; j<M; j++){
      dp[i][j] = -1;
    }
  }
  // tr("----");
  ll ans = solve(n, n, k, n);
  pf(ans);
}


#include <iostream>
#include <cstdio>

#include <algorithm>

#include <cassert>

using namespace std;

const int MAXN = 110;
const int MAXV = 110;
const int RV = 10;

int N, a[MAXN];
int tot;

int can[MAXN * MAXV][MAXN];

void work(int sw, int am) {
    for(int i = tot;i >= 0;i--) {
        for(int j = N;j >= 0;j--) {
            for(int k = 1;k <= am and k*sw <= i and k <= j;k++) {
                can[i][j] += can[i-(k*sw)][j-k];
                if(can[i][j] > RV) can[i][j] = RV;
            }
        }
    }
}

int main() {
    scanf("%d", &N);

    tot = 0;
    for(int i = 1;i <= N;i++) scanf("%d", a + i), tot += a[i];

    sort(a + 1, a + N + 1);

    for(int i = 0;i <= tot;i++) for(int j = 0;j <= N;j++) can[i][j] = 0;
    can[0][0] = 1;

    for(int i = 1, j;i <= N;i=j) {
        for(j = i + 1;j <= N and a[i] == a[j];j++);
        work(a[i], j-i);
    }

    int ans = 0;
    for(int i = 1, j;i <= N;i=j) {
        for(j = i + 1;j <= N and a[i] == a[j];j++) {
            int tw = (j - i) * a[i];

            assert(can[tw][j - i] >= 1 and can[tot - tw][N - (j - i)] >= 1);
            if(can[tw][j - i] == 1 or can[tot - tw][N - (j - i)] == 1) if((j - i) > ans) ans = j - i;
        }
        int tw = (j - i) * a[i];

        assert(can[tw][j - i] >= 1 and can[tot - tw][N - (j - i)] >= 1);
        if(can[tw][j - i] == 1 or can[tot - tw][N - (j - i)] == 1) if((j - i) > ans) ans = j - i;
    }

    printf("%d\n", ans);

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
#define mod 1000000007
#define pb push_back
#define in(a) int a;cin>>a;
#define in2(a,b)in(a)in(b)
#define out(x) cout<<x<<endl
#define out2(x,y) cout<<x<<" "<<y<<" ";

void display(vector<int>&v){
	for(int i=0;i<v.size();i++){
		cout<<v[i]<<" ";
	}
	cout<<endl;
}

int32_t main()
{
	in2(n,k);
	int v[n];
	for(int i=0;i<n;i++){
		v[i]=0;
	}

	int mini=0,maxi=0;

	if(k==0){
		out2(0,0);out("");
	}else{
		if(k!=n){
			mini=1;

			int count=0;
			for(int i=1;i<n;i++){
				if(count<k){
					v[i]=1;
					count++;
				}else{
					break;
				}

				i++;
			}
			if(count<k){
				for(int i=0;i<n;i++){
					if(count<k){
						if(v[i]==0){
							v[i]=1;
							count++;
						}
					}
				}
			}
			//display(v);
			for(int i=0;i<n;i++){
				if(i==0){
					if(v[i+1]==1 && v[i]==0){
						maxi++;
					}
				}else if(i==(n-1)){
					if(v[i-1]==1 && v[i]==0){
						maxi++;
					}
				}else{
					if((v[i+1]==1 || v[i-1]==1) && v[i]==0){
						maxi++;
					}
				}

			}
		}
		out2(mini,maxi);
	}

   	return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

using namespace std;

#define debug(x) cout << '>' << #x << ':' << x << endl;
#define loop(i,n) for(int i=0;i<(n);i++)
#define fori(a,b,i) for(int i=(a);i<=(b);i++)
#define ford(a,b,i) for(int i=(a);i>=(b);i--)
#define fast_io ios_base::sync_with_stdio(false) , cin.tie(NULL);

#define INF 0x3f3f3f3f
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007

#define fir first
#define sec second
#define pb push_back
#define mp make_pair

typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<int,int> MII;
typedef set<int> SI;
typedef long long int llint;

int main(){
 	llint n;
 	cin>>n;
 	for(int i = 1; ; i+= 2){
		if((i*(i + 1))/2 >= n){
			return printf("%d", i);
		}
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define DEBUG
#ifdef DEBUG
#define TRACE(x) cerr << #x << " = " << x << endl;
#define _ << " _ " <<
#else
#define TRACE(x) ((void)0)
#endif

const int INFCAP = 1000000005;
const int MAXN = 1000005;
typedef struct {
  int to;
  int cap;
} edge;

vector<int> ai[MAXN];
vector<edge> el;
int lev[MAXN];
int SRC;
int DST;
vector<int> lai[MAXN];
unsigned ng[MAXN];
int path[MAXN];
int pathsz;

void addedge(int u, int v, int c) {
  const int idx = el.size();
  const edge e1 = {v, c}, e2 = {u, 0};
  ai[u].push_back(idx);
  el.push_back(e1);
  ai[v].push_back(idx + 1);
  el.push_back(e2);
}

bool buildlevel() {
  for (int i = 0; i < MAXN; i++)
    lai[i].clear();
  fill(lev, lev + MAXN, 0);
  queue<int> q;
  q.push(SRC);
  lev[SRC] = 1;
  while (!q.empty()) {
    const int v = q.front();
    q.pop();
    if (v == DST)
      return true;
    for (auto idx : ai[v]) {
      const edge&e = el[idx];
      if (e.cap > 0) {
        if (lev[e.to] == 0) {
          lev[e.to] = lev[v] + 1;
          lai[v].push_back(idx);
          q.push(e.to);
        } else if (lev[e.to] == lev[v] + 1) {
          lai[v].push_back(idx);
        }
      }
    }
  }
  return false;
}

int dfs(int v) {
  if (v == DST)
    return INFCAP;
  for (; ng[v] < lai[v].size(); ng[v]++) {
    const edge& e = el[lai[v][ng[v]]];
    if (e.cap > 0) {
      int fl = dfs(e.to);
      if (fl > 0) {
        path[pathsz++] = lai[v][ng[v]];
        return min(fl, e.cap);
      }
    }
  }
  return 0;
}

ll maxflow(int src, int dst) {
  SRC = src, DST = dst;
  ll ret = 0;
  while (buildlevel()) {
    fill(ng, ng + MAXN, 0);
    int fl;
    while ((fl = dfs(SRC)) > 0) {
      ret += fl;
      for (int i = 0; i < pathsz; i++) {
        el[path[i]].cap -= fl;
        el[path[i] ^ 1].cap += fl;
      }
      pathsz = 0;
    }
  }
  return ret;
}

int dxy[8][2] =
{{-2, -1},
 {-2, 1},
 {-1, -2},
 {-1, 2},
 {1, -2},
 {1, 2},
 {2, -1},
 {2, 1}};

#define CONV(i, j) ((i) * m + (j))

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

  int n, m;
  cin >> n >> m;
  const int src = n * m;
  const int dst = n * m + 1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if ((i + j) % 2 == 0) {
        addedge(src, CONV(i, j), 1);
        for (int k = 0; k < 8; k++) {
          const int ii = i + dxy[k][0];
          const int jj = j + dxy[k][1];
          if (0 <= ii && ii < n && 0 <= jj && jj < m)
            addedge(CONV(i, j), CONV(ii, jj), 1);
        }
      } else
        addedge(CONV(i, j), dst, 1);
    }
  }
  cout << n * m - maxflow(src, dst) << endl;

  return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mk make_pair
#define rint register int
#define pa pair<int,int>
#define debug(x) cerr<<#x<<"="<<x<<"\n"
using namespace std;
const int mod = 1e9+7;
inline int read(){int w=1,s=0;char ch=getchar();while(!isdigit(ch)){if(ch=='-')w=-1;ch=getchar();}while(isdigit(ch)){s=s*10+ch-'0';ch=getchar();}return w*s;}
inline ll ksm(ll x,ll y){ll res=1;while(y){if(y&1) res=res*x%mod;x=x*x%mod;y>>=1;} return res;}
inline int pls(int a,int b){a+=b;return a>=mod?a-mod:a;}
inline int mns(int a,int b){a-=b;return a<0?a+mod:a;}
int n,k,m,Idx[15][222],cnt;
pa tmp[101000];
struct Ma{
	int a[417][417];
	inline void I(){memset(a,0,sizeof(a));for(rint i=1;i<=cnt;++i) a[i][i]=1;}
}trs,Ans;

inline Ma operator * (Ma p,Ma q){
	Ma res;memset(res.a,0,sizeof(res.a));
	for(rint i=1;i<=cnt;++i)
	for(rint j=1;j<=cnt;++j)
	{
		__int128 w=0;
		for(rint k=1;k<=cnt;++k)
		w+=(ll)p.a[i][k]*q.a[k][j];
		res.a[i][j]=w%mod;
	}
	return res;
}
inline Ma ksm(Ma x,int y){
	Ma res;res.I();
	while(y){
		if(y&1) res=res*x;
		x=x*x;y>>=1;
	}return res;
}
inline void Solve(){
	memset(trs.a,0,sizeof(trs.a));
	memset(Ans.a,0,sizeof(Ans.a));
	debug(cnt);
	for(rint i=1;i<=cnt;++i){
		pa o=tmp[i];
		int fir=o.first,sec=o.second,bit=__builtin_popcount(sec);
//		debug(fir);
//		debug(sec);
		if(sec&1) {
			sec>>=1;
			trs.a[i][Idx[fir][sec]]=bit;
			sec|=(1<<m);
			fir++;
			trs.a[i][Idx[fir][sec]]=bit;
		}
		else {
			sec>>=1;
			trs.a[i][Idx[fir][sec]]=1;
			sec|=(1<<m);
			fir++;
			trs.a[i][Idx[fir][sec]]=1;
		}
	}
	for(rint i=1;i<=cnt;++i){
		pa o=tmp[i];
		int fir=o.first,sec=o.second,bit=__builtin_popcount(sec);
		if(fir==bit)
		Ans.a[1][i]=1;
	}
	Ans=Ans*ksm(trs,n-m-1);
	ll ans=0;
	for(rint i=1;i<=cnt;++i){
		pa o=tmp[i];
		int fir=o.first,sec=o.second,bit=__builtin_popcount(sec);

		int oo=1;
		for(rint i=1;i<=bit;++i) oo*=i;
		if(fir==k){
			ans=pls(ans,1ll*Ans.a[1][i]*oo%mod);
//			debug(bit);
//		debug(fir);
//			debug(Ans.a[1][i]);

		}
	}cout<<ans;
}
int main()
{	freopen("a.in","r",stdin);
	freopen("a.out","w",stdout);
	n=read(),k=read(),m=read();m=min(m,n-1);
	int all=1<<(m+1);
	all--;
	for(rint i=0;i<=k;++i){
		for(rint j=0;j<=all;++j){
			Idx[i][j]=++cnt;tmp[cnt]=mk(i,j);
		}
	}
	Solve();
	return 0;
}


#include<bits/stdc++.h>
#define rep(XX,AA,BB) for(int XX=AA;XX<=BB;XX++)
#define tep(XX,AA,BB) for(int XX=AA;XX>=BB;XX--)
#define LL long long
const int K=14;
const int M=1<<4;
const int MX=310;
const LL MOD=1e9+7;
using namespace std;

int n,m,k;
int tot=0,maxn;
int get[K][M];

void read(int &x){
	char c;
	for(;c>'9'||c<'0';c=getchar());
	for(;'0'<=c&&c<='9';c=getchar())x=(x<<3)+(x<<1)+(c^48);
}

struct nn{
	LL a[MX][MX];
	void MEM(){rep(i,0,maxn)rep(j,0,maxn)a[i][j]=0;}
}hlp;

nn MUL(nn A,nn B){
	nn C;C.MEM();
	rep(i,1,tot)rep(j,1,tot){
		C.a[i][j]=0;
		rep(r,1,tot){
			C.a[i][j]+=A.a[i][r]*B.a[r][j]%MOD;
			C.a[i][j]%=MOD;
		}
	}
	return C;
}

LL KSM(int y){
	nn res;res.MEM();
	LL ans;
	res.a[1][1]=1;
	while(y){
		if(y%2==1)res=MUL(res,hlp);
		hlp=MUL(hlp,hlp);
		y/=2;
	}
	rep(num,0,maxn)ans=(ans+res.a[1][get[k][num]])%MOD;
	return ans;
}

int main(){
	read(n);read(k);read(m);
	maxn=(1<<m)-1;
	rep(i,0,k)rep(j,0,maxn)get[i][j]=++tot;
	rep(len,0,k)rep(num,0,maxn){
		int num1=(num<<1)&maxn;
		hlp.a[get[len][num]][get[len][num1]]=1;
		if(len<k)hlp.a[get[len][num]][get[len+1][num1|1]]=__builtin_popcount(num)+1;
	}
	printf("%lld\n",KSM(n));
	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <map>
#include <set>

using namespace std;

#define FOR(i, a, b) for(int i = a; i < b; i++)
#define REP(i, n) FOR(i, 0, n)

typedef vector<int> VI;
typedef vector<VI> VVI;

int main() {
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	string s;
	getline(cin, s);
	int n = s.length(), k, ans = 0;
	cin >> k;
	s.resize(n+k);
	FOR(i, n, n+k)
		s[i] = '}';
	REP(i, n+k)
		REP(j, i)
		if ((s[i] == s[j] || s[i] == '}')) {
				int a = j, b = i;
				while(a != i && b < s.length() && (s[a] == s[b] || s[b] == '}')) {
					a++;
					b++;
				}
				if (a == i)
					ans = max(ans, (i - j) * 2);
			}
	cout << ans;
	return 0;
}


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include <cmath>
using namespace std;
int main()
{
	long long s;
	long long n,k;
	cin>>n>>k;
	if(n%1==0)
	{
		if(k<=n/2)
		{
			s=(k-1)*2+1;
		}
		else
		{
			s=(k-((n/2)))*2;
		}
	}
	else
	{
		if(k<=n/2+1)
		{
			s=(k-1)*2+1;
		}
		else
		{
			s=(k-((n/2)+1))*2;
		}
	}
	cout<<s<<endl;
	getchar();
	getchar();
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

struct Bigint {

    // representations and structures

    string a; // to store the digits

    int sign; // sign = -1 for negative numbers, sign = 1 otherwise

    // constructors

    Bigint() {} // default constructor

    Bigint( string b ) { (*this) = b; } // constructor for string

    // some helpful methods

    int size() { // returns number of digits

        return a.size();

    }

    Bigint inverseSign() { // changes the sign

        sign *= -1;

        return (*this);

    }

    Bigint normalize( int newSign ) { // removes leading 0, fixes sign

        for( int i = a.size() - 1; i > 0 && a[i] == '0'; i-- )

            a.erase(a.begin() + i);

        sign = ( a.size() == 1 && a[0] == '0' ) ? 1 : newSign;

        return (*this);

    }

    // assignment operator

    void operator = ( string b ) { // assigns a string to Bigint

        a = b[0] == '-' ? b.substr(1) : b;

        reverse( a.begin(), a.end() );

        this->normalize( b[0] == '-' ? -1 : 1 );

    }

    // conditional operators

    bool operator < ( const Bigint &b ) const { // less than operator

        if( sign != b.sign ) return sign < b.sign;

        if( a.size() != b.a.size() )

            return sign == 1 ? a.size() < b.a.size() : a.size() > b.a.size();

        for( int i = a.size() - 1; i >= 0; i-- ) if( a[i] != b.a[i] )

            return sign == 1 ? a[i] < b.a[i] : a[i] > b.a[i];

        return false;

    }

    bool operator == ( const Bigint &b ) const { // operator for equality

        return a == b.a && sign == b.sign;

    }

    // mathematical operators

    Bigint operator + ( Bigint b ) { // addition operator overloading

        if( sign != b.sign ) return (*this) - b.inverseSign();

        Bigint c;

        for(int i = 0, carry = 0; i<a.size() || i<b.size() || carry; i++ ) {

            carry+=(i<a.size() ? a[i]-48 : 0)+(i<b.a.size() ? b.a[i]-48 : 0);

            c.a += (carry % 10 + 48);

            carry /= 10;

        }

        return c.normalize(sign);

    }

    Bigint operator - ( Bigint b ) { // subtraction operator overloading

        if( sign != b.sign ) return (*this) + b.inverseSign();

        int s = sign; sign = b.sign = 1;

        if( (*this) < b ) return ((b - (*this)).inverseSign()).normalize(-s);

        Bigint c;

        for( int i = 0, borrow = 0; i < a.size(); i++ ) {

            borrow = a[i] - borrow - (i < b.size() ? b.a[i] : 48);

            c.a += borrow >= 0 ? borrow + 48 : borrow + 58;

            borrow = borrow >= 0 ? 0 : 1;

        }

        return c.normalize(s);

    }

    Bigint operator * ( Bigint b ) { // multiplication operator overloading

        Bigint c("0");

        for( int i = 0, k = a[i] - 48; i < a.size(); i++, k = a[i] - 48 ) {

            while(k--) c = c + b; // ith digit is k, so, we add k times

            b.a.insert(b.a.begin(), '0'); // multiplied by 10

        }

        return c.normalize(sign * b.sign);

    }

    Bigint operator / ( Bigint b ) { // division operator overloading

        if( b.size() == 1 && b.a[0] == '0' ) b.a[0] /= ( b.a[0] - 48 );

        Bigint c("0"), d;

        for( int j = 0; j < a.size(); j++ ) d.a += "0";

        int dSign = sign * b.sign; b.sign = 1;

        for( int i = a.size() - 1; i >= 0; i-- ) {

            c.a.insert( c.a.begin(), '0');

            c = c + a.substr( i, 1 );

            while( !( c < b ) ) c = c - b, d.a[i]++;

        }

        return d.normalize(dSign);

    }

    Bigint operator % ( Bigint b ) { // modulo operator overloading

        if( b.size() == 1 && b.a[0] == '0' ) b.a[0] /= ( b.a[0] - 48 );

        Bigint c("0");

        b.sign = 1;

        for( int i = a.size() - 1; i >= 0; i-- ) {

            c.a.insert( c.a.begin(), '0');

            c = c + a.substr( i, 1 );

            while( !( c < b ) ) c = c - b;

        }

        return c.normalize(sign);

    }

    // output method

    void print() {

        if( sign == -1 ) putchar('-');

        for( int i = a.size() - 1; i >= 0; i-- ) putchar(a[i]);

    }

};

string numtostr(long long n) {
     ostringstream str1 ;
     str1 << n ;
     return str1.str();
}
long long strtonum(string s) {
     long long x ;
     stringstream str1(s);
     str1 >> x ;
     return x ;
}

int main() {
    long long n,k ;

    cin >> n >> k ;

    string one = "1" ;
    Bigint factn = one ;
    Bigint arr[1000];
    arr[0] = one ;
    for ( long long i = 1 ; i <= n ; i++) {
         string s = numtostr(i);
         Bigint bal = s ;
         factn = factn*bal ;
         arr[i] = factn ;
    }
    Bigint sum = one ;
    while(k > 1) {
        Bigint factk = arr[k] ;
        long long r = n-k ;
        Bigint factr = arr[r] ;
        Bigint Product = factr*factk ;
        Product = factn / Product ;
        long long z = pow(k-1,k-2);
        string zs = numtostr(z);
        Bigint power = zs ;
        Bigint result = Product * power ;
        sum = sum + result ;
        k-- ;
    }
    sum.print();
    puts(" ");
    return 0;

}


#include <iostream>
#include <string>
#include <cstdio>
#include <map>
#include <stack>
#include <vector>
using namespace std;
int main()
{
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    int n, m, ost, del;
    cin >> n >> m;
    del = n / 2;
    ost = n % 2;
    while (del != 0)
    {
        if ((ost + del) % m == 0)
        {
            cout << del + ost;
            return 0;
        }
        del--;
        ost += 2;
    }
    cout << -1;
    return 0;
}


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

#define ull unsigned long long

#define range 100

int multiply(int x, vector<int> &result, int res_size) {
	int carry = 0;

	for (int i = 0; i < res_size; i++) {
		int prod = result[i] * x + carry;

		result[i] = prod % 10;

		carry = prod / 10;
	}

		while (carry) {
			result[res_size] = carry % 10;
			carry = carry / 10;
			res_size++;
			}
	return res_size;
}

vector<int> power(int x, int n) {
	int temp = x;
	vector<int> result(range);
	int res_size = 0;

	while (temp != 0) {
		result[res_size] = temp % 10;
		res_size++;
		temp = temp / 10;
	}

	for (int i = 2; i <= n; i++)
		res_size = multiply(x, result, res_size);

	// cout << x << "^" << n << " = ";
	// for (int i = res_size - 1; i >= 0; i--)
	// 	cout << result[i];
	return result;
}

int main(){
	int x,y;
	cin >> x >> y;
	if(x == y){
		cout<<"="<<endl;
		return 0;
	}
	vector<int> left;
	vector<int> right;

	left = power(x,y);
	right = power(y,x);
	int n = left.size()-1;

	for(int i = n-1 ; i>=0 ; i--){
		if(left[i] > right[i]){
			cout<<">"<<endl;
			return 0;
		}
		if(left[i] < right[i]){
			cout<<"<"<<endl;
			return 0;
		}

	}
	cout<<"="<<endl;
	return 0;
}


#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>

using namespace std;
template<typename T1, typename T2>inline void chkmin(T1 &x, T2 y) { if (x > y) x = y; }
template<typename T1, typename T2>inline void chkmax(T1 &x, T2 y) { if (x < y) x = y; }
#define sz(c) (int)(c).size()
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define left left228
#define right right228
#define rank rank228
#define y1 y1228
#define read(FILENAME) freopen((FILENAME + ".in").c_str(), "r", stdin)
#define write(FILENAME) freopen((FILENAME + ".out").c_str(), "w", stdout)
#define files(FILENAME) read(FILENAME), write(FILENAME)
#define pb push_back
#define mp make_pair
using ll = long long;
using ld = long double;
// const int MAXMEM = 200 * 1000 * 1024;
// char _memory[MAXMEM];
// size_t _ptr = 0;
// void* operator new(size_t _x) { _ptr += _x; return _memory + _ptr - _x; }
// void operator delete (void*) noexcept {}
const string FILENAME = "input";
const int Mod = 998244353;

int sum(int a, int b) {
    return (a + b >= Mod ? a + b - Mod: a + b);
}

int mul(int a, int b) {
    return (ll)a * b % Mod;
}

ll powm(ll a, ll b) {
    ll res = 1;
    while (b) {
        if (b & 1) {
            res = mul(res, a);
        }
        a = mul(a, a);
        b >>= 1;
    }
    return res;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //read(FILENAME);
    ll n, m, l, r;
    cin >> n >> m >> l >> r;
    if (l == r) {
        cout << 1 << '\n';
        return 0;
    }
    if (n > m) {
        swap(n, m);
    }
    r -= l;
    r++;
    if (min(n, m) == 1) {
        ll cnt = (ll)n * m;
        ll cntodd = r - r / 2;
        ll cnteven = r / 2;
        ll ans = 0;
        if (cntodd) {
            ans = sum(ans, powm(cntodd, cnt));
        }
        if (cnteven) {
            ans = sum(ans, powm(cnteven, cnt));
        }
        cout << ans << '\n';
        return 0;
    }
    if (n % 2 == 0 && m % 2 == 0) {
        exit(1);
    }
    cout << powm(r, (ll)n * m) << '\n';
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main() {
	int n = 0;
	int f[n];
	cin >> n;
	int s;
	for(int i=0;i < n;i++){
		cin >> f[i];
		s += f[i];
		if(s % n == 1){
			cout << "YES";
		}else{
			cout << "NO";
		}
	}
	return 0;
}


#include<cstdio>
using namespace std;
int main(){
	int m,n,ans=0,r=0,k=0;
	scanf("%d%d",&m,&n);
	if(n==1)printf("-1\n");
	else if(n>m&&n<2*m)printf("3\n");
	else if(n>=2*m)printf("1\n");
	else if(n==m)printf("5\n");
	else if(n==2){
		if(m==3)printf("11\n");else printf("-1\n");
	}else if(n==3){
		if(m==4)printf("9\n");else if (m==5)printf("11\n";)else printf("-1\n");
	}else if(n>=4){
		ans=4;m=m-n+2;
		if(n>=2*m)ans++;
		else {
			k=(m-n)/(n/2-1);ans+=2*k;
			m=m-(n/2-1)*k;ans++;
			if(n<2*m){
				m=2*m-n;
				if(m%(n-1)==0)k=m/(n-1);else k=m/(n-1)+1;
				ans+=2*k;
			}}
		printf("%d\n",ans);
	}
	return 0;
}


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

int dp[55][55][55][55][2][2][2][2];
bool solve(int left,int right,int up,int down,bool upleft,bool upright,bool downleft,bool downright){

    if(left<0 || right<0 || up <0 || down <0 || upleft <0 || upright<0 ||downleft<0 ||downright<0 ) return true;

    if(! (left+right+up+down+upleft+upright+downleft+downright))return false;

   if(dp[left][right][up][down][upleft][upright][downleft][downright]!=-1)return dp[left][right][up][down][upleft][upright][downleft][downright];
    bool ret=0;

    ret|=!solve(left,right,up,down,upleft-1,upright,downleft,downright);
    ret|=!solve(left,right,up-1,down,upleft-1,upright,downleft,downright);
    ret|=!solve(left-1,right,up,down,upleft-1,upright,downleft,downright);

    ret|=!solve(left,right,up,down,upleft,upright-1,downleft,downright);
    ret|=!solve(left,right,up-1,down,upleft,upright-1,downleft,downright);
    ret|=!solve(left,right-1,up,down,upleft,upright-1,downleft,downright);

    ret|=!solve(left,right,up,down,upleft,upright,downleft-1,downright);
    ret|=!solve(left,right,up,down-1,upleft,upright,downleft-1,downright);
    ret|=!solve(left-1,right,up,down,upleft,upright,downleft-1,downright);

    ret|=!solve(left,right,up,down,upleft,upright,downleft,downright-1);
    ret|=!solve(left,right,up,down-1,upleft,upright,downleft,downright-1);
    ret|=!solve(left,right-1,up,down,upleft,upright,downleft,downright-1);

    ret|=!solve(left-1,right,up,down,upleft,upright,downleft,downright);
    ret|=!solve(left-2,right,up,down,upleft,upright,downleft,downright);

    ret|=!solve(left,right-1,up,down,upleft,upright,downleft,downright);
    ret|=!solve(left,right-2,up,down,upleft,upright,downleft,downright);

    ret|=!solve(left,right,up-1,down,upleft,upright,downleft,downright);
    ret|=!solve(left,right,up-2,down,upleft,upright,downleft,downright);

    ret|=!solve(left,right,up,down-1,upleft,upright,downleft,downright);
    ret|=!solve(left,right,up,down-2,upleft,upright,downleft,downright);

    return dp[left][right][up][down][upleft][upright][downleft][downright]=ret;
}
int main(){
    int a,b,r;
    cin>>a>>b>>r;
    memset(dp,-1,sizeof dp);
    int left,right,up,down,upleft=0,upright=0,downleft=0,downright=0;

    left=a/(2*r);right=0;
    if(b/2>=2*r)right=left;

    up=b/(2*r); down=0;
    if(a/2>=2*r)down=up;

    if(up && left)upleft++,up--,left--;
    if(up &&  right)upright++,up--,right--;
    if(down && left)downleft++,down--,left--;
    if(down && right)downright++,down--,right--;

  //cout<<left<<right<<up<<down<<upleft<<upright<<downleft<<downright<<endl;

    if(solve(left,right,up,down,upleft,upright,downleft,downright))cout<<"First\n";
    else cout<<"Second\n";
}


#include<bits/stdc++.h>
#define lim 101
using namespace std;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int n,k,b[lim],a[lim],i,r,j,ct=100000,two,four,single=0,x;
    bool ans=true;
    cin>>n>>k;
    two=2*n;
    four=n;
    for (i=0;i<k;i++) {
        cin>>b[i];
    }
    sort(b,b+k);
    for (i=0,j=0;(i<k)&&(ans);i++) {
        while (b[i]>0)
        {
            a[i]=min(8,b[i]);
            if (a[i]&1) a[i]++;
            if (a[i]==2) {
                if (two>0) two--;
                else if (four>0) {
                    four--;
                    single++;
                }
                else ans=false;
            }
            else if (a[i]==4) {
                if (four>0) four--;
                else if (two>1) two-=2;
                else ans=false;
            }
            else if (a[i]==6) {
                if ((two>1)&&(four>0)) {
                    two--,four--;
                }
                else if (two>2) two-=3;
                else if (four>1) {
                	four-=2; single++;
                }
                else ans=false;
            }
            else if (a[i]==8) {
                if (four>1) four-=2;
                else if ((four>0)&&(two>1)) {four--;two-=2;}
                else if (two>3) two-=4;
                else ans=false;
            }
            if (!ans) {
                //    system("pause");
                if (b[i]&1) a[i]--;
                a[i]-=(min(four,a[i]/4))*4;
                a[i]-=(min(two,a[i]/2))*2;
                four-=min(four,a[i]/4);
                two-=min(two,a[i]/2);
         //   cout<<single<<" "<<a[i]<<" "<<b[i];
                if (single>=a[i]) {
                    ans=true;
                    single-=a[i];
                }
            }
            b[i]-=a[i];
        }
    }
    if (ans) cout<<"YES";
    else cout<<"NO";
}


#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
using namespace std;

#define r(n) scanf("%d", &n)
#define w(n) printf("%d\n", n)
#define FOR(i, n) for(int i=0; i<(n); ++i)
#define REP(i, a, b) for(int i=(a); i<(b); ++i)
#define ll long long

struct rect
{
	int x1, y1, x2, y2;
};

int n;
rect R[6];
int S[6];

bool in(int a, int b, int c, int d, int x, int y)
{
	return (a<=x && x<=c && b<=y && y<=d);
}

int main()
{
	cin>>n;
	FOR(i, n) {
		cin>>R[i].x1>>R[i].y1>>R[i].x2>>R[i].y2;
		int a = R[i].x2-R[i].x1, b = R[i].y2-R[i].y1;
		S[i] = a*b;

		if (n == 1) {
			if (a==b) cout<<"YES"<<endl; else cout<<"NO"<<endl;
			return 0;

		}
	}

	int a, b, c, d;
	FOR(i, n)
		for (int j=0; j<n; ++j) if (i != j) {
			a = R[i].x1; b = R[i].y1;
			c = R[j].x2; d = R[j].y2;

			int s = 0;
			bool tf = true;
			FOR(t, n) {
				if (in(a, b, c, d, R[t].x1, R[t].y1) && in(a, b, c, d, R[t].x2, R[t].y2)) s += S[t];
				else { tf = false; break; }
			}
			if (tf && s > 0 && s == (c-a)*(d-b)) {
				cout<<"YES"<<endl;
				return 0;
			}
		}

	cout<<"NO"<<endl;

}


#include <cstring>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <map>
#include <cmath>

using namespace std;

char downCase (char & x) {
     if (x - 'A' > 0) x = x - 'A' + 'a';
     return x;
}

int main () {
    char * s;
    gets (s);
    char last;
    for (int i = 0, len = strlen (s); i < len; ++i) if ((s[i] - 'a' < 26 && s[i] - 'a' >= 0) || (s[i] - 'A' >=0 && s[i] - 'A' < 26)) last = s[i];
    downCase (last);
    if (last == 'a') cout << "YES";
    else if (last == 'e') cout << "YES";
    else if (last == 'i') cout << "YES";
    else if (last == 'o') cout << "YES";
    else if (last == 'u') cout << "YES";
    else cout << "NO";
}


#include<bits/stdc++.h>
using namespace std;
string a;
int main()
{
    int i=0;
    cin>>a;
    while(1)
    {
        if(a[i]=='H'||a[i]=='Q'||a[i]=='9')
        {
            cout<<"YES";
            return 0;
        }
        if(a[i]=='\0')
        {
            break;
        }
    }
    cout<<"NO";
    return 0;
}


#include <iostream>
using namespace std;
int main()
{
    int n;
    cin>>n;
    if (n>0)
    cout<<n;

    int n1;
    cin>>n1;

    int a=n/10;
    int b=(n1%10)*n+(n/10);

    if (a<b)
    cout<<a;

    else if (a>=b)
    cout<<b+1;

    else cout<<"";

    return 0;
}


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

int getLeastPrimeFactor(int n){

     if(n%2==0) return 2;

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

     return 1;

}

signed main()
{
    int t;
    cin>>t;
    while(t--)
    {
    	int n ; cin>>n;

    	int a=getLeastPrimeFactor(n);
    	cout<<n/a<<" "<<n-(n/a)<<endl;
    }

}


#include <iostream>
#include <vector>

using namespace std;
long long pot(int xx,int yy)
{
    long long aa=1;
    for(int ii=0;ii<yy;ii++)
    {
        aa=aa*xx;
    }
    return aa;
}
int sumter(long long sd){
    long long asd=sd,mu=0;
    for(int i=0;i<9;i++){
        mu=mu+asd%10;
        asd=asd/10;
    }
    return asd+mu;

}
using namespace std;
int main()
{
    vector<int> myv;
long long a,b,c,suma;
   long long x;
   cin>>a>>b>>c;
   if(b==0){
       cout<<1<<endl<<1<<endl;
       return 0;
   }

   for(int i=1;i<=81;i++ )
   {
       x=b*pot(i,a)+c;
       if(x<0)continue;
      if(x<0 || x>999999999) continue;
      suma=sumter(x);
       if(suma==i){
           myv.push_back(x);
       }

    }
   int sizev=myv.size();
  cout<<sizev<<endl;
  for(int ij=0;ij<sizev-1;ij++)
  {
      cout<<myv[ij]<<" ";
  }
  cout<<myv[sizev-1]<<endl;
  return 0;
}


#include <iostream>
#include <cstdio>
#include <map>
using namespace std;

#define LL __int64

const int MOD = 1000000007;

LL T[55],B[55];
void get_bell(int n,int mod){
    B[0]=1;
    B[1]=1;
    T[0]=1;
    for(int i=2;i<=n;++i){
        T[i-1]=B[i-1];
        for(int j=i-2;j>=0;--j)
            T[j]=(T[j]+T[j+1])%mod;
        B[i]=T[0];
    }
}
//求B[n]%mod
//要先预处理前50项Bell数，当然可以更多
//vis每次调用前都要清空
map<int,LL> vis;
LL bell_mod(int n,int mod){
    vis.clear();
    LL ret=vis[n];
    if(ret) return ret;
    if(n<=50) return B[n];  //改
    LL k=0;
    LL P=1;
    while(P<n){
        P=P*mod;
        ++k;
    }
    P/=mod;
    --k;
    return vis[n]=(k*bell_mod(n-P,mod)+bell_mod(n-P+1,mod))%mod;
}

int main() {
    get_bell(50, MOD);
    int n;
    cin>>n;
    LL a = bell_mod(n + 1, MOD);
    LL b = bell_mod(n, MOD);
    cout<<(a - b + MOD) % MOD<<endl;
    return 0;
}


#include <iostream>
using namespace std;
int count(string s,int start){
	int ans=0;
	for(int i=start;i<s.length()-1;i++){
		if(s[i]=='/')ans++;
		else break;
	}
	return ans;
}
int main(){
	string s,ans;
	cin>>s;
	for(int i=0;i<s.length();i++){
		int t=0;
		if(s[i]=='/'){
			t=count(s,i);
			ans+='/';
			i+=t-1;
		}
		else {
			ans+=s[i];
		}
	}
	cout<<ans;
	return 0;
}


//bitw
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <map>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <limits>
#include <utility>
#include <queue>
#include <stack>
#include <iomanip>
#include <cassert>
#include <deque>
#include <set>

using namespace std;

int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    cout<<max(a+(b*c) , max(a*(b+c) , max(a*b*c , (a+b)*c)))<<endl;
    return 0;
}


#include <bits/stdc++.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <map>

using namespace std;

const int MAXN = 2e5+1;
const int  MOD = 1e9+7;

int N, K, x, last, cnt, ans;

int a[100001];

set<int> st;
set<int> ::iterator it;

int main (){

	cin >> N >> K;

	for(int i = 1; i <= N; i++){
		cin >> a[i];
	}

	for(int i = 1; i <= N; i++){
		if(st.find(a[i]) != st.end())
			continue;

		if(st.find(a[i]) == st.end() && (int)st.size() < K){
			ans ++;
			st.insert(a[i]);
		}else{
			int max_i, number;
			for(it = st.begin(); it != st.end(); it ++){
				int indx;
				for(indx = i+1; indx <= N; i++){
					if(a[indx] == *it){
						break;
					}
				}

				if(max_i < indx){
					max_i = indx;
					number = *it;
				}
			}

			ans++;
			st.insert(a[i]);
			st.erase(number);
		}
	}

	cout << ans;

	return 0;
}


#include <iostream>
#include <math.h>
using namespace std;

int pow (long long int y ,long long int x)
{
	if(x==0)
		return 1;
	return y*pow(y ,x-1);
}
int main()
{
	long long int n , a , c=0 , b=5;
	cin >> n ;
	a= pow (b , n);
	a%=100;
	cout << a << endl;
	return 0;
}


#include <bits//stdc++.h>

using namespace std;

#define MP make_pair
#define PB push_back
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define MAX 1000000
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define sqr(x) ((x)*(x))
#define SET(x) memset(x, 0, sizeof(x))
#define CLR(x) memset(x, -1, sizeof(x))
#define xx first
#define yy second
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)

inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
inline int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b);}
//Convert int to string
template <typename T>
string to_str(T str)
{
    stringstream stream;
    stream << str;
    return stream.str();
}

//Convert string to int
template <typename T>
int to_int(T num)
{
    int val;
    stringstream stream;
    stream << num;
    stream >> val;
    return val;
}

//Split String by Single Character Delimiter
vector<string> split(const string& s, char delim)
{
    vector<string> elems;
    stringstream ss(s);
    string item;

    while (getline(ss, item, delim))
        elems.push_back(item);

    return elems;
}
// this function goes to main for splitting
//vector<string> words;
//words = split("lorem_ipsum_dolor_sit_amet_no_tota_tacimates_delicata_eum", '_');
//for(int i=0; i<words.size(); i++)
//cout << words.at(i) << endl;

//sort with respect to the second element in a pair !!
//bool comp(const pair<int, int>&i, const pair<int, int>&j) {
//        return i.second < j.second;
//}
//vector< pair<int, int> >v;
//sort(v.begin(), v.end(), comp);

const int dr [] = {-1, -1, 0, 1, 1, 1, 0, -1};
const int dc [] = {0, 1, 1, 1, 0, -1, -1, -1};

typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<int,int> MPII;
typedef set<int> SETI;
typedef multiset<int> MSETI;
typedef long int i32;
typedef unsigned long int ui32;
typedef long long int i64;
typedef unsigned long long int  ui64;

int main()
{
    ios_base::sync_with_stdio(0);
    int n, m;
    cin>>n>>m;
    if(m > n*(n+1)/2){
        m %= n*(n+1)/2;
    }
    bool f1 = false;
    for(int i=1; i<=n; i++) {
        if(m<i) {
            cout << m <<endl;
            break;
        }
        m-=i;
    }
    return 0;
}


#include<iostream>
#include<stdio.h>
using namespace std;
#define Maxn 500
int main()
{
    int n,m,i,j;
    int arr[Maxn];
    scanf("%d",&n);
    for(i=0;i<n;i++)
        scanf("%d",&arr[i]);
    sort(arr,arr+n);
    for(i=n-1;i>=0;i--)
        cout<<arr[i]<<" ";
    cout<<endl;

}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
static const int maxn = 100010;
static const int INF = 0x3f3f3f3f;
static const int mod = (int)1e9 + 7;
static const double eps = 1e-6;
static const double pi = acos(-1);

void redirect(){
    #ifdef LOCAL
        freopen("test.txt","r",stdin);
    #endif
}
map<int,bool>m;
int main(){
    int n;
    redirect();
    m[5] = 1;
    m[46] = 1;
    m[13] = 0;
    m[24] = 0;
    scanf("%d",&n);
    if(m.count(n))m[n]?printf("YES"):printf("NO");
    else{
        if(n <= 5)while(1);
        else assert(0);
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef int ll;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    function<ll(ll, ll)> power = [&](ll x, ll y) {
        if (y == 0) {
            return 1LL;
        } else {
            ll z = power(x, y / 2);
            return y % 2 == 0 ? (z * z) % 998244353 : ((z * z) % 998244353 * x) % 998244353;
        }
    };
    unordered_map<ll, ll> divs;
    auto div = [&](ll x) {
        if (divs.find(x) != divs.end()) {
            return divs[x];
        }
        return divs[x] = power(x, 998244353 - 2);
    };
    ll n, m;
    cin >> n >> m;
    vector<bool> a((size_t) n);
    vector<ll> w((size_t) n);
    for (ll i = 0; i < n; i++) {
        ll v;
        cin >> v;
        a[i] = v == 1;
    }
    for (ll i = 0; i < n; i++) {
        cin >> w[i];
    }
    ll zeros = 0, ones = 0;
    for (ll i = 0; i < n; i++) {
        if (a[i]) {
            ones += w[i];
        } else {
            zeros += w[i];
        }
    }
    map<tuple<ll, ll>, ll> dp0;
    function<ll(ll, ll)> f0 = [&](ll z, ll o) {
        if (z - o <= zeros - ones - m) {
            return 1LL;
        }
        auto it = dp0.find({z, o});
        if (it != dp0.end()) {
            return it->second;
        }
        ll r = z * f0(z - 1, o) + (o + 1) * f0(z, o + 1);
        r %= 998244353;
        r *= div(z + o);
        r %= 998244353;
        return dp0[{z, o}] = r;
    };
    map<tuple<ll, ll>, ll> dp1;
    function<ll(ll, ll)> f1 = [&](ll z, ll o) {
        if (z - o <= zeros - ones - m) {
            return 1LL;
        }
        auto it = dp1.find({z, o});
        if (it != dp1.end()) {
            return it->second;
        }
        ll r = (z - 1) * f1(z - 1, o) + o * f1(z, o + 1);
        r %= 998244353;
        r *= div(z + o);
        r %= 998244353;
        return dp1[{z, o}] = r;
    };
    for (ll i = 0; i < n; i++) {
        if (a[i]) {
            cout << (f0(zeros, ones) * w[i]) % 998244353 << endl;
        } else {
            cout << (f1(zeros, ones) * w[i]) % 998244353 << endl;
        }
    }
    return 0;
}


#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,k;
    cin>>n>>k;
    int a[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }

    int ans=0;
    int j=0; int x;
    for(int j=0;j<n;j++)
    {
        if(a[j]<=k)
        {
            ans++;
            j=x;
        }
        else
       { j=x;
        break;}
    }

    int r=n-1;
    while(r>x)
    {
        if(a[r]<=k)
        {
            ans++;
            r--;
        }

        else {
            break;
        }

    }

    cout<<ans;

    return 0;
}


#include <iostream>
#include <string>
using namespace std;

string s;

int dp[510][510];

int main()
{
    int n;
    cin >> n >> s;
    for (int i = 0; i < n; i++)
        dp[i][i] = 1;

    for (int l = 2; l <= n; l++) {
        for (int i = n - l; i >= 0; i--) {
            int j = i + l - 1;

            dp[i][j] = 1e9;
            for (int k = i; k < j; k++)
                dp[i][j] = min(dp[i][j], dp[i][k] + dp[k + 1][j]);

            if (s[i] == s[j]) {
                dp[i][j] = min(dp[i][j], dp[i + 1][j]);
               /// dp[i][j] = min(dp[i][j], dp[i][j - 1]);
                dp[i][j] = min(dp[i][j], dp[i + 1][j - 1] + 1);
            }
        }
    }

    cout << dp[0][n - 1] << '\n';


#include<bits/stdc++.h>
using namespace std;
int func(int n){
       if(n==0) return 0;
       int val=1;
       while(val*2<=n){
                    val*=2;
       }
       return 1+func(n-val);
}
int main(){
     int n;
     cin>>n;
     return func(n);
}


#include <bits/stdc++.h>
#define IN(a,b) (a.find(b) != a.end())
#define p(a,b) make_pair(a,b)
#define readVec(a) for (int64_t __i = 0; __i<(int64_t)a.size();__i++){cin>>a[__i];}

// jimjam

template<typename T>
void pMin(T &a, T b) {if (b<a){a=b;}}
template<typename T>
void pMax(T &a, T b) {if (b>a){a=b;}}
template<typename T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& c);
template<typename A, typename B>
std::ostream& operator<<(std::ostream& os, const std::pair<A,B>& c) {std::cout << "(" << c.first << ", " << c.second << ")";return os;}
template<typename T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& c) {
	if (c.size() == 0) {os << "{}"; return os;}
	os << "{" << c[0];
	for (int64_t i = 1; i < (int64_t)c.size(); i++) {os <<", "<<c[i];}
	os << "}";
	return os;
}

#define ISDEBUG 0

using namespace std;

int main() {
	if (ISDEBUG) freopen("input","r",stdin);

	ios::sync_with_stdio(0);
	cin.tie(0);

	int64_t n,m,k;
	cin >> n >> m >> k;
	if (n==m) {return 1;}

	int64_t curr = 2;
	m-=n;
	m-=1;
	int64_t l = max(k-1,(int64_t)1), r = min(n,k+1);

	while (!(l==1 && r==n)) {
		if (m < (r-l+1)) {
			cout << curr << endl;
			return 0;
		} else {
			m -= (r-l+1);
			curr++;
		}
		l--;
		r++;
		pMax(l,(int64_t)1);
		pMin(r,n);
	}

	curr += (m/n);
	cout << curr << endl;
	return 0;
}


#include<iostream>
#include<map>
#define BASE 1000000007;
using namespace std;
map<pair<__int32, __int32>, __int32> storedvalue;
__int32 findvalue(__int32 i, __int32 j)
{
	__int32 result;
	pair<__int32, __int32> index = make_pair(i, j);
	if (storedvalue.count(index))return storedvalue[index];
	if (i > j)result = findvalue(j,i);
	else if (i == 1)result = j;
	else if (i == j)result = 1;
	else if (j == i + 1 && i % 2 == 1)result = 2;
	else if (i == 2 && j % 2 == 0)result = j - 1;
	else if (i == 2 && j % 2 == 1)result = j + 1;
	else if (j % 4 == 1 || j % 4 == 2)result = 2 + findvalue(i-2,j);
	else if (j % 4 == 3 || j % 4 == 0)result = -2 + findvalue(i - 2, j);
	else result = 0;
	storedvalue.insert(make_pair(index, result));
	return result;
}

int main()
{
	int q;
	cin >> q;
	for (int i = 0; i < q; i++)
	{
		__int32 x1, y1, x2, y2, K;
		cin >> x1 >> y1 >> x2 >> y2 >> K;
		int ans = 0;
		for (__int32 j = x1; j <= x2; j++)
		{
			for (__int32 k = y1; k <= y2; k++)
			{
				__int32 temp = findvalue(j, k);
				if (temp > K)continue;
				else ans = (ans + temp) % BASE;
			}
		}
		cout << ans << endl;
	}
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>
#include <array>
#include <list>
#include <stack>
#include <valarray>
#include <fstream>

#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<pi> vpi;
typedef vector<vi> vvi;
typedef vector<vpi> vvpi;
typedef long long ll;
typedef pair<ll, ll> pl;
typedef vector<ll> vl;
typedef vector<pl> vpl;
typedef vector<vl> vvl;
typedef vector<vpl> vvpl;

const int INF = 1001001001;
const ll INFL = 1001001001001001001LL;

template<typename T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }
int in() { int x; cin >> x; return x; }
double fin() { double x; cin >> x; return x; }
string sin() { string x; cin >> x; return x; }
ll lin() { ll x; cin >> x; return x; }

ll mod = 1000000007;

ll solve(ll n, ll x1, ll y1, ll x2, ll y2, ll k, ll plus) {
    if (0 > x2 || 0 > y2 || n - 1 < x1 || n - 1 < y1 || plus >= k) return 0;

    if (x1 <= 0 && n - 1 <= x2 && y1 <= 0 && n - 1 <= y2) {
        ll a = min(plus + n, k);
        ll b = plus + 1;
        ll sol = (a + b) * (a - b + 1) / 2 % mod * n % mod;
        return sol;
    } else {
        ll m = n / 2;
        ll sol1 = solve(m, x1, y1, x2, y2, k, plus);
        ll sol2 = solve(m, x1 - m, y1, x2 - m, y2, k, plus + m);
        ll sol3 = solve(m, x1, y1 - m, x2, y2 - m, k, plus + m);
        ll sol4 = solve(m, x1 - m, y1 - m, x2 - m, y2 - m, k, plus);

        return (sol1 + sol2 + sol3 + sol4) % mod;
    }
}

int main() {
#ifdef LOCAL_ENV
    freopen("sol.in", "r", stdin);
    freopen("sol.out", "w", stdout);
#else
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
#endif

    int q = in();
    forn (cs, q) {
        int x1, y1, x2, y2, k;
        cin >> x1 >> y1 >> x2 >> y2 >> k;

        x1--; y1--; x2--; y2--;

        ll cur = 1;
        while (cur <= x2 || cur <= y2) cur <<= 1;
        cout << solve(cur, x1, y1, x2, y2, k, 0) << '\n';
    }
    return 0;
}


#include <iostream>
#define int long long
using namespace std;

const int MOD = 998244353, MAXN = 500005;
int fact[MAXN];

void calcFacts() {
    fact[0] = 1;
    for (int i = 1; i < MAXN; i++)
        fact[i] = (fact[i - 1] * i) % MOD;
}

int powMod(int a, int e) {
    int r = 1;
    while (e) {
        if (e & 1)
            r = (r * a) % MOD;
        a = (a * a) % MOD;
        e >>= 1;
    }
    return r;
}

int invMod(int a) {
    return powMod(a, MOD - 2);
}

int choose(int n, int k) {
    if (k > n)
        return 0;
    return (fact[n] * invMod((fact[k] * fact[n - k]) % MOD)) % MOD;
}

int main() {
    calcFacts();

    int n, k;
    cin >> n >> k;

    int answer = 0;
    for (int i = 1; i < MAXN; i++) {
        answer = (answer + choose(n / i - 1, k - 1)) % MOD;
    }

    cout << answer;
}


#include<iostream>
using namespace std;
int main()
{
	cin >> n;
	int i,flag=0;
	long int dif;
	int arr[10000];
	for(i=0;i<n;i++)
	{
		cin >> arr[i];
	}
		dif=arr[1]-arr[0];
	for(i=1;i<n-1;i++)
	{
		if(arr[i+1]-arr[i]!=dif)
		{
			flag=1;
			break;
		}
	}
	if(flag==1)
	{
		cout << arr[n-1];
	}
     else
	{
		cout << arr[n-1] + dif;
	}
	return 0;
}


#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <cstdlib>

const int N = (int)3e4;
int n, a, q;
namespace convolution
{
	int rev[N << 2], len;
	inline int initialize(int n)
	{
		len = 1;
		int tmp = 0;
		for(; len < n << 1; ++ tmp, len <<= 1);
		rev[0] = 0;
		for(int i = 1; i < len; ++ i)
			rev[i] = rev[i >> 1] >> 1 | (i & 1) << tmp - 1;
	}
	struct complex
	{
		double rl, img;
		inline complex() {}
		inline complex(double _rl, double _img)
		{
			rl = _rl, img = _img;
		}
		inline complex friend operator +(complex a, complex b)
		{
			return complex(a.rl + b.rl, a.img + b.img);
		}
		inline complex friend operator -(complex a, complex b)
		{
			return complex(a.rl - b.rl, a.img - b.img);
		}
		inline complex friend operator *(complex a, complex b)
		{
			return complex(a.rl * b.rl - a.img * b.img, a.rl * b.img + b.rl * a.img);
		}
	}A[N << 2], B[N << 2];
	double PI = acos(-1);
	inline void FFT(complex *a, int opt)
	{
		for(int i = 0; i < len; ++ i)
			if(rev[i] < i)
				std::swap(a[i], a[rev[i]]);
		for(int i = 2; i <= len; i <<= 1)
		{
			complex omega_i = complex(cos(2 * PI * opt / i), sin(2 * PI * opt / i));
			for(int j = 0; j < len; j += i)
			{
				complex omega = complex(1, 0);
				for(int k = j; k < j + i / 2; ++ k)
				{
					complex u = a[k], t = a[k + i / 2] * omega;
					a[k] = u + t, a[k + i / 2] = u - t;
					omega = omega * omega_i;
				}
			}
		}
		if(opt == -1)
			for(int i = 0; i < len; ++ i)
				a[i].rl /= len;
	}
	inline void work(int *a, int *b, int n, long long *res)
	{
		memset(A, 0, sizeof(A)), memset(B, 0, sizeof(B));
		for(int i = 0; i < n; ++ i)
			A[i] = complex(a[i], 0), B[i] = complex(b[i], 0);
		FFT(A, 1), FFT(B, 1);
		for(int i = 0; i < len; ++ i)
			A[i] = A[i] * B[i];
		FFT(A, -1);
		for(int i = 0; i < len; ++ i)
			res[i] = round(A[i].rl);
	}
}
int f[N + 1][2], _f[N + 1][2];
int ans;
inline void update()
{
	for(int i = 1; i <= n; i += 2)
		ans = (ans + f[i][1]) % q;
}
void work(int b)
{
    cout << b << ' ';
	if(b == 1)
	{
		memset(f, 0, sizeof(f));
		f[1][1] = 1;
		update();
		return;
	}
	work(b / 2);
	static int x[N + 1], y[N + 1];
	std::swap(f, _f);
	for(int i = 0; i <= n; ++ i)
		x[i] = (_f[i][0] + _f[i][1]) % q;
	for(int i = 0; i < 2; ++ i)
	{
		for(int j = 0; j <= n; ++ j)
			y[j] = _f[j][i ^ (b >> 1 & 1)];
		static long long res[N << 2];
		convolution::work(x, y, n, res);
		for(int j = 0; j <= n; ++ j)
			f[j][i] = (res[j] + _f[j][i] + _f[j][i ^ (b >> 1 & 1)]) % q;
	}
	if(b & 1)
	{
		std::swap(f, _f);
		for(int i = 0; i < 2; ++ i)
		{
			f[0][i] = _f[0][i];
			for(int j = 1; j <= n; ++ j)
				f[j][i] = (_f[j][i] + (i ^ (b & 1) ? 0 : (j == 1 ? 1 : _f[j - 1][0] + _f[j - 1][1]))) % q;
		}
	}
	update();
}
int main()
{

	#ifndef ONLINE_JUDG
	freopen("CF773F.in", "r", stdin);
//	freopen("CF773F.out", "w", stdout);
	#endif

	using namespace std;
	cin >> n >> a >> q;
	convolution::initialize(n);
	ans = 0;
	work(a / 2);
	cout << ans << endl;
}


#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define uint unsigned
#define db long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define IT iterator

#define PB push_back
#define MK make_pair
#define LB lower_bound
#define UB upper_bound
#define EB emplace_back
#define fi first
#define se second

#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define UPD(x,y) (((x)+=(y))>=mo?x-=mo:233)
#define CLR(a,v) memset(a,v,sizeof(a));
#define CPY(a,b) memcpy(a,b,sizeof(a));

#define LS3 k*2,l,mid
#define RS3 k*2+1,mid+1,r
#define LS5 k*2,l,mid,x,y
#define RS5 k*2+1,mid+1,r,x,y
#define GET pushdown(k);int mid=(l+r)/2

#define inf 1<<30
#define sqr(x) ((x)*(x))
using namespace std;
int mo;
struct COMPLEX{
	db r,i;
	COMPLEX(){}
	COMPLEX(db _r,db _i){r=_r,i=_i;}
	COMPLEX operator +(const COMPLEX &a)const{
		return COMPLEX(r+a.r,i+a.i);
	}
	COMPLEX operator -(const COMPLEX &a)const{
		return COMPLEX(r-a.r,i-a.i);
	}
	COMPLEX operator *(const COMPLEX &a)const{
		return COMPLEX(r*a.r-i*a.i,r*a.i+i*a.r);
	}
	COMPLEX conj()const{
		return COMPLEX(r,-i);
	}
};
const int FFTN=1<<16;
COMPLEX w[FFTN+2],a[FFTN+2],b[FFTN+2];
int R[FFTN],LEN;
const db pi=acos(-1);
void prepare(){
	For(i,0,FFTN-1) w[i]=COMPLEX(cos(2*pi*i/FFTN),sin(2*pi*i/FFTN));
}
void FFTinit(int sz){
	LEN=1; int L=0;
	for (;LEN<=sz;LEN<<=1,L++);
	For(i,0,LEN-1) R[i]=(R[i>>1]>>1)|((i&1)<<(L-1));
}
void DFT(COMPLEX *a,int n){
	For(i,0,n-1) if (i<R[i]) swap(a[i],a[R[i]]);
	for (int d=1;d<n;d<<=1){
		int len=FFTN/(d<<1);
		for (int i=0;i<n;i+=d<<1)
			for (int j=i,p=0;j<i+d;j++,p+=len)
				a[j+d]=a[j]-a[j+d]*w[p],a[j]=a[j]+a[j]-a[j+d];
	}
}
const int N=30005;
int f[2][N],n,ans,mxv;
void solve(int mx){
	if (mx==1){
		f[0][0]=f[1][1]=ans=1;
		return;
	}
	solve(mx/2);
	For(i,0,LEN-1) a[i]=(i<=n?COMPLEX(f[0][i],f[1][i]):COMPLEX(0,0));
	DFT(a,LEN);
	For(i,0,LEN-1){
		int ano=(LEN-i)&(LEN-1);
		COMPLEX v0=(a[i]+a[ano].conj())*COMPLEX(0.5,0);
		COMPLEX v1=(a[i]-a[ano].conj())*COMPLEX(0,-0.5);
		b[ano]=(v0+v1)*v1+(v0+v1)*(v0-COMPLEX(1,0))*COMPLEX(0,1);
	}
	DFT(b,LEN);
	For(i,0,n){
		int v1=(ll)(b[i].r/LEN+0.49)%mo;
		int v0=(ll)(b[i].i/LEN+0.49)%mo;
		if (mx&2) swap(v0,v1);
		f[0][i]=(f[0][i]+v0)%mo;
		f[1][i]=(f[1][i]+v1)%mo;
	}
	if (mx&1)
		Rep(i,n,1)
			f[1][i]=(f[1][i]+f[1][i-1]+1ll*f[0][i-1])%mo;
	for (int i=1;i<=n;i+=2)
		ans=(ans+f[1][i])%mo;
}
int main(){
	scanf("%d%d%d",&n,&mxv,&mo);
	if (mx==1) return puts("0"),0;
	prepare(); FFTinit(2*n);
	solve(mxv/2);
	printf("%d\n",ans);
}


// Example program
#include <iostream>
#include <string>
#include<vector>
using namespace std;
 int n, sum=0;
 void dfs(int x)
  {
      if(x<=n)
          sum++;
     else
         return ;
     dfs(x*10+7);
   dfs(x*10+4);
 }
 int main()
 {
  cin>>n;
     dfs(4);
     dfs(7);
    cout<<sum;
     return 0;


#include<bits/stdc++.h>
using namespace std;
#define int long long
inline void read(int &x)
{
	char c=getchar();
	x=0;
	while (c>'9'||c<'0')
		c=getchar();
	while (c>='0'&&c<='9')
	{
		x=x*10+c-'0';
		c=getchar();
	}
}
const int inf=1e18;
int a,t,t0,t1,t2,p1,p2,a1,a2,ans;
signed main()
{
	//freopen("c.in","r",stdin);
	//freopen("c.out","w",stdout);
	read(a);
	read(t);
	read(t0);
	read(a1);
	read(t1);
	read(p1);
	read(a2);
	read(t2);
	read(p2);
	ans=inf;
	if (t0<=t1&&t0<=t2)
	{
		if (a*t0<=t)
			putchar('0');
		else
			puts("-1");
		return 0;
	}
	for (int i=0;i<=(a-1)/a1+1;++i)
	{
		int dt=t-t1*min(i*a1,a),sum=i*p1,da=max(0LL,a-a1*i);
		if (dt<0)
			break;
		if (da*t0<=dt)
		{
			ans=min(ans,sum);
			break;
		}
		if (da*t2>dt)
			continue;
		if (t0>t2)
		{
			z=(da*t0-dt+t0-t2-1)/(t0-t2);
			ans=min(ans,sum+((x-1)/a2+1)*p2);
		}
	}
	if (ans==inf)
		ans=-1;
	cout<<ans;
}


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

#define endl "\n"
#define ll long long int
#define f(i,st,ed) for(ll i=st;i<ed;i++)
#define fr(i,ed,st) for(ll i=ed;i>=st;i--)
#define vv vector<ll>
#define all(v) v.begin(),v.end()
#define pb push_back
#define pp pair<ll,ll>
#define gv(v,s,e) f(i,s,e){ ll x; cin >> x; v.pb(x);}
#define pv(v,s,e) f(i,s,e){cout << v[i] << " ";}
#define MOD 1000000007
#define debug(x) cout << x << endl;

void yes(){
    cout << "YES" << endl;
}

void no(){
    cout << "NO" << endl;
}

ll powmod(ll x, ll y, ll mod)
{
    ll ans=1;

    while(y)
    {
        if(y%2==1)
        {
            ans = (ans*x)%mod;
        }

        x = (x*x)%mod;
        y/=2;
    }

    return ans;
}

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

    ll arr[100]={0};

    f(n,1,100)
    {
        ll l;
        ll r;
        if(n%2==1)
        {
            l=4;
            r = (pow(n,2)+1)/2;
        }
        else
        {
            l = 4;
            r = (n-2)*(n-2);
        }
        f(j,l,r+1)
        {
            if(j<=100)
            {
                if(arr[j]==0)
                    arr[j]=n;
            }
            else
                break;
        }
    }

    ll x;
    cin >> x;

    cout << arr[x] << endl;

    return 0;
}


#include <iostream>
#include <math.h>
#include <cstring>
#include <string.h>
#include <string>
#include <stdio.h>
using namespace std;
/*void A_1()         //注意定义变量的类型
{
    long long n,m,a;
    cin>>n>>m>>a;
    long long i,j;
    long long counts;
    i=ceil(n*1.0/a);
    j=ceil(m*1.0/a);
    counts=i*j;
    cout<<counts;
}*/
/*void A_4()         //考虑特殊情况2
{
    int w;
    cin>>w;
    if(w%2==0 && w!=2)
        cout<<"YES"<<endl;
    else
        cout<<"NO"<<endl;
}*/
/*class words
{
public:
    string word;
};
void A_71()          //sprintf函数的使用
{
    int n,i;
    cin>>n;
    words a[n];
    words b[n];
    int len;
    char temp[256];
    for(i=0;i<n;i++)
    {
        cin>>a[i].word;
        len=(int)a[i].word.length();
        if(len>10)
        {
            sprintf(temp,"%c%d%c",a[i].word[0],len-2,a[i].word[len-1]);
            b[i].word=temp;
        }
        else
        {
            b[i].word=a[i].word;
        }
    }
    for(i=0;i<n;i++)
        cout<<b[i].word<<endl;
}*/
/*void A_158()          //positive表示正数
{
    int n,k,i,counts=0;
    cin>>n>>k;
    int a[n];
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    for(i=0;i<n;i++)
    {
        if(a[i]>=a[k-1] && a[i]!=0)
            counts++;
    }
    cout<<counts<<endl;
}*/
/*void A_118()           //（string迭代器的使用）问题的分部解决。string字符串中的删除与插入函数erase()与insert()
{
    string str;
    cin>>str;
    int i,len;
    len=(int)str.length();
    for(i=0;i<len;i++)
    {
        if(str[i]=='A' || str[i]=='E' || str[i]=='I' || str[i]=='O' || str[i]=='U' || str[i]=='Y' || str[i]=='a' || str[i]=='e' || str[i]=='i' || str[i]=='o' || str[i]=='u' || str[i]=='y')
        {
            str.erase(i,1);
            i--;
        }
        else
        {
            if(str[i]<97)
                str[i]+=32;
        }
    }
    len=(int)str.length();
    for(i=0;i<len*2;i++)
    {
        str.insert(i,".");
        i++;
    }
    cout<<str;
}*/
/*void A_50()
{
    int m,n;
    cin>>m>>n;
    if(m%2==0||n%2==0)
        cout<<m*n/2<<endl;
    else
        cout<<(m*(n/2)+m/2)<<endl;
}*/
/*void A_231()
{
    int n,i,k=0;
    cin>>n;
    int a[n],b[n],c[n],d[n];
    for(i=0;i<n;i++)
    {
        cin>>a[i]>>b[i]>>c[i];
        d[i]=a[i]+b[i]+c[i];
        if(d[i]>=2)
            k++;
    }
    cout<<k;
}*/
/*void A_282()         //仔细点就好
{
    int a,b,c,i,j,temp;
    cin>>a>>b>>c;
    int d[5];
    d[0]=a*b*c;
    d[1]=(a+b)*c;
    d[2]=(b+c)*a;
    d[3]=a+b+c;
    for(i=0;i<3;i++)
    {
        for(j=0;j<3-i;j++)
            if(d[j]>d[j+1])
            {
                temp=d[j];d[j]=d[j+1];d[j+1]=temp;
            }
    }
    cout<<d[3]<<endl;
}*/
/*int a[1000000];
void B_742()          //这题的关键是不能用brute force需要建立一个空间来记录各个数字的出现字数，以空间换速度
{                                   //并且静态空间为了防止栈溢出需要建立在外面给足够大的空间并初始化为0
    int n,x,j,k;
    cin>>n>>x;
    for(j = 0; j < 1000000; j++)       //这种思想非常值得学习，以空间换时间。
        a[j] = 0;
    long long ans = 0;
    for(int j = 0; j < n; j++) {
        cin>>k;
        ans += a[x xor k];
        a[k]++;
    }
    cout<<ans<<endl;
}*/
long long GCD(long long a,long long b)            //求最大公因数
{
    if(b>a)
        swap(a,b);
    long long c;
    while(b>0)
    {
        c=a%b;  a=b;    b=c;
    }
    return a;
}
long long a[1000],b[1000],t[1000];
void A_741()
{
    int n,i,j;
    cin>>n;
    for(i=0;i<1000;i++)
    {
        a[i]=1;b[i]=1;t[i]=1;
    }
    for(i=0;i<n;i++)
    {
        cin>>a[i];
        b[i]=a[i];
        t[i]=0;
    }
    for(i=0;i<n;i++)
    {
        for(j=0;j<n;j++)
        {
            if(b[i]==i+1)
            {
                t[i]=1;
                break;
            }
            b[i]=b[b[i]-1];
            t[i]++;
            if(b[i]==i+1)
            {
                t[i]++;
                break;
            }
            if(t[i]==4 && b[i]!=i+1)
                t[i]=-1;
        }
        b[i]=a[i];
    }
    for(i=0;i<n;i++)
    {
        if(t[i]>0 && t[i]%2==0)
            t[i]=t[i]/2;
    }
    long long temp,ans;
    for(i=1;i<n;i++)
    {
        j=i-1;
        temp=t[i];
        while(j>=0 && t[j]>temp)
        {
            t[j+1]=t[j];
            j--;
        }
        t[j+1]=temp;
    }
    ans=t[0];
    if(ans!=-1)
    {
        for(i=n-1;i>0;i--)
        {
            if(t[i-1]==-1)
                break;
            if(t[i]!=-1)
            {
                ans=ans/GCD(ans,t[i-1])*t[i-1];       //最小公倍数与最大公因数的求法
            }
        }
    }
    cout<<ans<<endl;
}
int main()
{
    A_741();
    return 0;
}


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

typedef long long ll;
typedef pair<int, int> pii;
#define ite(i, a, b) for(int i = a; i <= b; ++i)

const int maxn = 1e8 + 1;

int n, b, top_divisor = 0;
ll ans = 1e18;
int freq[maxn];
int divisor[maxn];
int brr[maxn];

void find_divisors(int b) {
	int i = 2;
	while (b > 1) {
		if (b%i == 0) {
			int max = i;
			while (b%i == 0) {
				b /= i;
				divisor[++top_divisor] = max;
				freq[max]++;
			}
		}
		++i;
	}
}

int count_zero(int n, int div) {
	int ret = 0;
	while (n >= div) {
		n /= div;
		ret += n;
	}
	return ret;
}

int main() {

	ios::sync_with_stdio(false);

	//freopen("D:\in.txt", "r", stdin);

	cin >> n >> b;
	find_divisors(b);
	ite(i, 1, top_divisor) {
		int count = count_zero(n, divisor[i]) / freq[divisor[i]];
		if (ans > count)
			ans = count;
	}
	cout << ans << endl;

	return 0;
}


#include<iostream>
using namespace std;
int main()
{
	long long unsigned int n,a,i;
	cin>>n;
	cin>>a;
	int b[n];
	for(i=n-1;i>=0;i--)
	{
		b[i]=a%10;
		a=a/10;
	}
	int count=0;
	for(i=0;i<n;i++)
	{
		if(i==0 && b[i]==0)
		{
		goto a;
	    }
	    if(b[i]==1)
	    count++;
	    else
	    goto a;

    }

   a: if(count==n)
   count--;
   cout<<count+1;
   return 0;
}


#include <iostream>
using namespace std;
int main()
{
	int t, s, q, ans = 0;
	cin>>t>>s>>q;
	ans = 1;
	double loaded = s, everysec = double(q-1)/double(q), reached = 0;
	while (reached != t)
	{
		reached += 1;
		loaded += everysec;
		if (reached > loaded)
		{
			loaded -= everysec;
			reached -= 1;
			double diff = loaded - reached;
			double t = diff/(1-everysec);
			reached = 1-t;
			ans++;
		}
	}
	cout<<ans<<"\n";
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;

int main()
{
    int n;
    while(scanf("%d",&n))
    {
        int a[110];
        memset(a,0,sizeof(a));
        for(int i=1;i<=n/2;i++)
        {
            int x;
            scanf("%d",&x);
            if(x&1)
                a[x]=111;
            else
                a[x]=x;
        }
        int sum=0,l=1;
        for(int i=1;i<=n;i++)
        {
            while(a[l]==111&&l<n-2)
            {
                l+=2;
            }
            if(a[i]==i)
            {
                sum+=abs(i-l);
                a[l]=111;
            }
        }
        printf("%d\n",sum);
    }
    return 0;
}