#include<bits/stdc++.h>

typedef long long ll;
typedef unsigned long long ull;

using namespace std;

const int MAXN=262144<<1;
const int P=998244353;
const int g[]={3,(P+1)/3};

int rev[MAXN],n;
ll tp[MAXN],itp[MAXN],tp2[MAXN],itp2[MAXN];
ll _G_[2][MAXN],G[MAXN],G0[MAXN],G1[MAXN],G2[MAXN],X1[MAXN],X3[MAXN],X4[MAXN],F0[MAXN],F1[MAXN],F2[MAXN];

constexpr ll Add(ll a,ll b){a+=b;return a>=P?a-P:a;}

constexpr ll Sub(ll a,ll b){a-=b;return a<0?a+P:a;}

void Inc(ll &a,ll b){a+=b;if(a>=P) a-=P;}

void Dec(ll &a,ll b){a-=b;if(a<0) a+=P;}

ll ksm(ll a,ll b)
{
	ll ret=1;
	for(;b;b>>=1,(a*=a)%=P) if(b&1) (ret*=a)%=P;
	return ret;
}

int init(int n)
{
	int tot=1,lg2=0;
	while(tot<=n) tot<<=1,lg2++;
	for(int i=0;i<tot;i++) rev[i]=(rev[i>>1]>>1)|((i&1)<<(lg2-1));
	return tot;
}

void NTT(ll *a,int n,int f)
{
	ll *ed=a+n;
	for(int i=0;i<n;i++)
		if(i>rev[i]) swap(a[i],a[rev[i]]);
	for(int i=2;i<=n;i<<=1)
		for(ll *x=a,*y=a+(i>>1);x!=ed;x+=i,y+=i)
			for(int k=0;k<(i>>1);k++)
			{
				ll u=x[k],t=y[k]*_G_[f][k*MAXN/i]%P;
				x[k]=Add(u,t);y[k]=Sub(u,t);
			}
	if(f) for(int i=0,inv=ksm(n,P-2);i<n;i++) a[i]=a[i]*inv%P;
}

void Inv(ll *a,ll *Res,int n)
{
    if(n==1) return Res[0]=ksm(a[0],P-2),void();
    Inv(a,Res,(n+1)>>1);
    int tot=init(n<<1),lst=(n+1)>>1;
    static ll t1[MAXN],t2[MAXN];
    memset(t1,0,sizeof(ll)*tot);memset(t2,0,sizeof(ll)*tot);
    for(int i=0;i<n;i++) t1[i]=a[i];
    for(int i=0;i<lst;i++) t2[i]=Res[i];
    NTT(t1,tot,0);NTT(t2,tot,0);
    for(int i=0;i<tot;i++) t1[i]=Sub(2*t2[i],t2[i]*t2[i]%P*t1[i]%P);
    NTT(t1,tot,1);
    for(int i=0;i<n;i++) Res[i]=t1[i];
}

int main()
{
	_G_[0][0]=_G_[1][0]=1;
	_G_[0][1]=ksm(g[0],(P-1)/MAXN);_G_[1][1]=ksm(g[1],(P-1)/MAXN);
	for(int i=2;i<MAXN;i++) _G_[0][i]=_G_[0][i-1]*_G_[0][1]%P,_G_[1][i]=_G_[1][i-1]*_G_[1][1]%P;
	scanf("%d",&n);G[0]=1;
	int tot=init(4*n);//notice
	for(int i=2;i<=n;i++) G[i]=Add(G[i-2],i>3?G[i-4]:0);
	for(int i=0;i<=n;i++) G0[i]=G[i]*i%P*i%P,G1[i]=G[i]*(i+1)%P*(i+1)%P,G2[i]=G[i]*(i+2)%P*(i+2)%P;
	X1[1]=1;X3[3]=1;X4[4]=1;
	NTT(G0,tot,0);NTT(G1,tot,0);NTT(G2,tot,0);NTT(X1,tot,0);NTT(X3,tot,0);NTT(X4,tot,0);
	for(int i=0;i<tot;i++) tp[i]=Sub(Add(X4[i]*G2[i]%P*G0[i]%P,1),Add(X1[i]*G0[i]%P,Add(X3[i]*G2[i]%P,X4[i]*G1[i]%P*G1[i]%P)));
	for(int i=0;i<tot;i++) tp2[i]=Sub(1,X3[i]*G2[i]%P);
	NTT(tp2,tot,1);Inv(tp2,itp2,n);
	init(4*n);NTT(itp2,tot,0);
	NTT(tp,tot,1);Inv(tp,itp,n);
	init(4*n);NTT(itp,tot,0);
	for(int i=0;i<tot;i++) F0[i]=Add(G0[i]*Sub(1,X3[i]*G2[i]%P)%P,X3[i]*G1[i]%P*G1[i]%P)*itp[i]%P;
	for(int i=0;i<tot;i++) F1[i]=Add(G1[i]*Sub(1,X1[i]*G0[i]%P)%P,X1[i]*G1[i]%P*G0[i]%P)*itp[i]%P;
	for(int i=0;i<tot;i++) F2[i]=Add(G2[i],X1[i]*F1[i]%P*G1[i]%P)*itp2[i]%P;
	NTT(F0,tot,1);NTT(F1,tot,1);NTT(F2,tot,1);
	ll Ans=Add(G[n-1],G[n-3])*(n-1)%P*(n-1)%P*n%P;
	for(int i=2;i<=n-2;i++)
	{
		Inc(Ans,G[i-1]*(i-1)%P*(i-1)%P*F0[n-i-1]%P*i%P);
		Inc(Ans,G[i-2]*(i-1)%P*(i-1)%P*F1[n-i-2]%P*i%P*2%P);
		if(i>=3&&i<=n-3) Inc(Ans,G[i-3]*(i-1)%P*(i-1)%P*F2[n-i-3]%P*i%P);
	}
	printf("%lld\n",Ans);
}


#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cmath>
#include<ctime>
#include<bitset>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<complex>
#include<iostream>
#include<algorithm>
#define N 50001
#define LL long long
#define add_edge(u,v) nxt[++cnt]=head[u],head[u]=cnt,to[cnt]=v
#define open(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout)
char ch;bool fs;void re(int& x)
{
	while(ch=getchar(),ch<33);
	if(ch=='-')fs=1,x=0;else fs=0,x=ch-48;
	while(ch=getchar(),ch>33)x=x*10+ch-48;
	if(fs)x=-x;
}
using namespace std;
const int mod=998244353;
int n;
LL ans,g[N],f0[N],f1[N],f2[N],sqr[N];
int main()
{
	re(n);
	g[0]=g[2]=1;
	for(int i=4;i<=n;++i)g[i]=(g[i-2]+g[i-4])%mod;
	for(int i=1;i<=n;++i)sqr[i]=1ll*i*i%mod;
	f0[0]=0;f1[0]=1;f2[0]=4;
	for(int i=1;i<=n;++i)
	{
		f0[i]=g[i]*sqr[i]%mod;
		f1[i]=(g[i]*sqr[i+1]+f0[i-1])%mod;
		f2[i]=(g[i]*sqr[i+2]+f1[i-1]+(i>1)*g[i-1]*sqr[i])%mod;
		for(int j=2;j<i;++j)
		{
			f0[i]+=g[j-1]*sqr[j-1]%mod*f0[i-j]%mod;
			f1[i]+=g[j-1]*sqr[j]%mod*f0[i-j]%mod;
			f2[i]+=g[j-1]*sqr[j]%mod*f1[i-j]%mod;
			f1[i]+=g[j-2]*sqr[j]%mod*f1[i-j-1]%mod;
			f0[i]+=g[j-2]*sqr[j-1]%mod*f1[i-j-1]%mod;
			f2[i]+=g[j-2]*sqr[j]%mod*f2[i-j-1]%mod;
		}
		f0[i]%=mod;f1[i]%=mod;f2[i]%=mod;
	}
	ans=sqr[n-1]*(g[n-1]+g[n-3])%mod*n%mod;
	for(int i=3;i<n;++i)
	{
		ans+=sqr[i-2]*g[i-2]%mod*f0[n-i]%mod*(i-1)%mod;
		ans+=sqr[i-2]*g[i-3]%mod*f1[n-i-1]%mod*2*(i-1)%mod;
		if(i>=4 && i+1<n)ans+=sqr[i-2]*g[i-4]%mod*f2[n-i-2]%mod*(i-1)%mod;
	}
	printf("%lld\n",ans%mod);
}


#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main(){
	int a;
	int b;
	int c;
	vector<int> vec;
	cin >> a >> b >> c;
	vec.push_back(a);
	vec.push_back(b);
	vec.push_back(c);
	sort(vec.begin(),vec.end());
	return (vec[1] - vec[0]) + (vec[2] - vec[1]);
}


#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <string>

using namespace std;

int k, c;

int main() {
	string s;
	cin >> s >> k;

	if ((k == 0) || (s.length() == 1)) {
		cout << s << endl;
		return 0;
	}

	int size = s.length() - 1;
	for (int i = 0; i < s.length(), k > 0; i++, c = i) {
		int stuff = min (i + k, size);
		for (int j = i + 1; j <= stuff; j++)
			if (s[j] > s[c]) c = j;
		k -= c - i;
		for (int j = c; j > i; j--)
			swap(s[j], s[j - 1]);
    }

	cout << s << endl;

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main(int argc, char const *argv[])
{
    int n;

    cin >> n;

    int k = n - 1;

    bool flag = false;
    for (int i = 0; i <= sqrt(k) + 2; i++)
    {
        if (k % i)
        {
            int temp = (k / i) - i - 1;
            if (temp > 0 && temp % 2 == 0)
            {
                flag = true;
                int y = temp / 2;
                printf("%d %d", i, y);
            }
        }
    }

    if (!flag)
        printf("NO");

    return 0;
}


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

using namespace std;

const int INF = 1e9 + 7;
const int MAXN = 1e6 + 7;
const double EPS = 1e-8;

struct Tree {
    int n;
    vector <int> t;
    Tree(int n) : n(n), t(2 * n, 0) {}
    void change(int v, int x) {
        v += n;
        t[v] = x;
        v /= 2;
        while (v) {
            t[v] = max(t[2 * v], t[2 * v + 1]);
            v /= 2;
        }
    }
    int get_max(int l, int r) {
        int res = 0;
        for (l += n, r += n; l <= r; l /= 2, r /= 2) {
            if (l % 2 == 1) res = max(res, t[l++]);
            if (r % 2 == 0) res = max(res, t[r--]);
        }
        return res;
    }
};

int main() {
    #ifdef MY
        freopen("input.txt", "r", stdin);
    #else
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
    #endif // MY
    int n, m;
    cin >> n >> m;
    vector <int> cnt(m, 0);
    vector <pair <int, int> > a;
    for (int i = 0; i < n; i++) {
        int l, r;
        cin >> l >> r;
        l--, r--;
        a.push_back({l, 1});
        a.push_back({r + 1, 0});
    }
    sort(a.begin(), a.end());
    int pr = 0;
    int now = 0;
    for (int i = 0; i < a.size(); i++) {
        while (a[i].first > pr) {
            cnt[pr] = now;
            pr++;
        }
        if (a[i].second) {
            now++;
        } else {
            now--;
        }
    }
    while (m > pr) {
        cnt[pr] = now;
        pr++;
    }
    vector <int> down(n, 0), up(n, 0);
    Tree t(n + 1);
    for (int i = m - 1; i >= 0; i--) {
        int val = t.get_max(0, cnt[i]) + 1;
        down[i] = val;
        t.change(cnt[i], val);
    }
    t = Tree(n + 1);
    for (int i = 0; i < m; i++) {
        int val = t.get_max(0, cnt[i]) + 1;
        //cout << val << " ";
        up[i] = val;
        t.change(cnt[i], val);
    }
    //cout << "\n";
    int res = 0;
    for (int i = 0; i < n; i++) {
        res = max(res, up[i] + down[i] - 1);
    }
    cout << res;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <iomanip>
#include <cmath>

#define elif else if

using namespace std;
typedef long long ll;
typedef long double ld;

const ll inf = 1e18 + 3, mod = 1e9 + 7;

istream& operator>>(istream& is, vector<ll> &a) {
	for (int i = 0; i < a.size(); ++i) cin >> a[i];
	return is;
}

ostream& operator<<(ostream& os, vector<ll> &a) {
	for (int i = 0; i < a.size(); ++i) cout << a[i] << ' ';
	return os;
}

void sort(vector<ll> &a) {
	sort(a.begin(), a.end());
}

ll step(ll a, ll n) {
	if (n == 1) return a % mod;
	if (n & 1) return (step(a, n - 1) * a) % mod;
	ll k = step(a, n / 2);
	return (k * k) % mod;
}

ll gcd(ll a, ll b) {
	return a > 0 ? gcd(b % a, a) : b;
}

ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}

int main() {
	int n, m;
	cin >> n >> m;
	vector<ll> from(n), to(n);
	for (int i = 0; i < n; ++i) cin >> from[i] >> to[i], --from[i], --to[i];
	sort(from);
	sort(to);
	vector<ll> a(m);
	int pf = 0, pt = 0, curr = 0;
	for (int i = 0; i < m; ++i) {
		while (pf < n && from[pf] == i) ++pf, ++curr;
		a[i] = curr;
		while (pt < n && to[pt] == i) ++pt, --curr;
	}
	if (m == 1) {
		cout << 0;
		return 0;
	}
	int check = a[0];
	bool cr = true;
	for (int i = 0; i < m; ++i)
		cr = cr && a[i] == check;
	if (cr) {
		cout << m;
		return 0;
	}
	ll prev = 0, maxx;
	for (int i = 1; i < m; ++i) {
		if (a[i] < a[i - 1]) prev += a[i - 1] - a[i];
		maxx = max(maxx, a[i] + prev);
	}
	cr = true;
	for (int i = 0; i < m - 1; ++i)
		cr = cr && maxx > a[i];
	if (cr) cout << m - 1;
	else cout << m - 1;
	system("pause");
	return 0;
}


#include <bits/stdc++.h>

#define F first
#define S second
#define pb push_back
#define ll long long
#define ld long double
#define pii pair <int, int>
#define endl '\n'
//#define int long long

using namespace std;

const int mod = 1e9 + 7;
const int N = 5e3 + 5;

int cnt[N], reversecnt[N], pref[N], suff[N], ispref[N], issuff[N], anspref[N], anssuff[N];
int dp[N];
int cursz = 0;

int bin(int x) {
    int l = 0, r = cursz - 1;
    int res = -1;
    while (l <= r) {
        int mid = (l + r) / 2;
        if (dp[mid] > x) {
            res = mid;
            r = mid - 1;
        } else l = mid + 1;
    }
    return res;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif // LOCAL
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < n; i++) {
        int l, r;
        cin >> l >> r;
        cnt[l]++;
        cnt[r + 1]--;
        if (l > 1) reversecnt[l - 1]--;
        reversecnt[r]++;
    }
    int cur = 0;
    for (int i = 1; i <= m; i++) cur += cnt[i], pref[i - 1] = cur;
    cur = 0;
    for (int i = m; i >= 1; i--) cur += reversecnt[i], suff[i - 1] += cur;
    reverse(suff, suff + m);
    for (int i = 0; i < m; i++) dp[i] = 1e9;
    dp[0] = pref[0], anspref[0] = 1, ispref[0] = 1;
    cursz = 1;
    for (int i = 1; i < m; i++) {
        if (pref[i] >= dp[cursz - 1]) {
            dp[cursz] = pref[i];
            anspref[i] = ++cursz;
            ispref[i] = 1;
            continue;
        }
        {
            int pos = bin(pref[i]);
            dp[pos] = pref[i];
            anspref[i] = cursz;
        }
    }
    for (int i = 0; i < m; i++) dp[i] = 1e9;
    dp[0] = suff[0], anssuff[0] = 1, issuff[0] = 1;
    cursz = 1;
    for (int i = 1; i < m; i++) {
        if (suff[i] >= dp[cursz - 1]) {
            dp[cursz] = suff[i];
            anssuff[i] = ++cursz;
            issuff[i] = 1;
            continue;
        }
        {
            int pos = bin(suff[i]);
            dp[pos] = suff[i];
            anssuff[i] = cursz;
        }
    }
    int res = 0;
    for (int i = 0; i < m; i++) {
        int cur = anspref[i] + anssuff[m - i - 1];
      //  cout << anspref[i] << " " << anssuff[m - i - 1] << " " << ispref[i]  << " " << issuff[m - i - 1] << endl;
        if (ispref[i] && issuff[m - i - 1]) cur--;
        res = max(res, cur);
    }
    cout << res << endl;
    return 0;
}


#include <bits/stdc++.h>

#define rep(i,n) for(i=1;i<=n;i++)
#define Rep(i,n) for(i=0;i<n;i++)
#define For(i,a,b) for(i=a;i<=b;i++)

#define pb(x) push_back(x)
#define sz(x) x.size()

#define mem(ara,val) memset(ara,val,sizeof(ara))
#define eps 1e-9

#define si(x) scanf("%d",&x)
#define sii(x,y) scanf("%d %d",&x,&y)
#define siii(x,y,z) scanf("%d %d %d",&x,&y,&z)
#define sl(x) scanf("%lld",&x)
#define sll(x,y) scanf("%lld %lld",&x,&y)
#define slll(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)
#define ss(ch) scanf("%s",ch)
#define pi(x) printf("%d",x)
#define pii(x,y) printf("%d %d",x,y)
#define piii(x,y,z) printf("%d %d %d",x,y,z)
#define pl(x) printf("%lld",x)
#define pll(x,y) printf("%lld %lld",x,y)
#define plll(x,y,z) printf("%lld %lld %lld",x,y,z)
#define ps(ch) printf("%s",ch)
#define Afridi 0
#define NL printf("\n")
#define SP printf(" ")
#define loj(x) printf("Case %d:",x)
#define Loj(x) printf("Case %lld:",x)
#define debug(str,x) cout << str << " " << x << endl;
#define Max 1000000
#define INF INT_MAX

typedef long long LL;
typedef unsigned long long ULL;

using namespace std;

int main()
{
    LL n,k,i;
    vector <LL> v;
    sll(n,k);
    if(k == 1)
    {
        for(i=1;i<=n;i++)
        {
            if(i != 1)SP;
            printf("%lld",i);
        }
        NL;
    }
    else
    {
        LL cur = n;
        LL baki = k-1;
        LL tot = 0;
        while(1)
        {
            if(baki == 0)
            {
                for(i=tot+1;i<=n;i++)v.pb(1);
                break;
            }

            LL run = cur-1;
            if(baki < run)
            {
                for(i=1;i<=run;i++)
                {
                    if(i + baki == cur)v.pb(2);
                    else v.pb(1);
                }
                tot += cur;
                baki = 0;
            }
            else
            {
                v.pb(2);
                tot += 2;
                baki -= run;
                cur -= 2;
            }
        }
        LL len = sz(v);
        LL c = 0,flag = 1;
        /*Rep(i,len)
        {
            printf("%lld ",v[i]);
        }
        NL;*/
        Rep(i,len)
        {
            LL my = v[i];
            LL mn = c+1;
            LL mx = mn + my - 1;
            for(LL j=mx;j>=mn;j--)
            {
                if(flag != 1)SP;
                printf("%lld",j);
                flag = 0;
            }
            c = mx;
        }
    }
    return Afridi;
}


#include<bits/stdc++.h>
#define rg register
#define i60 long long
#define int long long
#define fp( i , x , y ) for( rg int i=(x); i<=(y); ++i )
#define fq( i , x , y ) for( rg int i=(y); i>=(x); --i )
using namespace std ;
const int N = 100 , K = 1e4+10 , hgs = 1e9+7 ;
int qpow( int A , int B ) {
  int C=1 ;
  for( ; B ; B>>=1 , A=1ll*A*A%hgs )
    if( B&1 ) C = 1ll*A*C%hgs ;
  return C ;
}
struct node { int val , tot ; } ; vector <node> a ;
int f[K][N] , ans = 1 , fac[N] , inv[N] , k ;
void upd( int &x , int y ) {
  x = (x+y) % hgs ;
}
void prep( ) {
  inv[0] = 1 ;
  fq( i , 1 , 100 ) inv[i] = qpow( i , hgs-2 ) ;
}
void solve( int v , int cnt ) {
 if( n == 1 ) cout << "Now : " << v << endl ;
  fp( j , 0 , cnt-1 ) f[0][j] = 0 ;
  f[0][cnt] = 1 ;
  fp( i , 1 , k ) {
    fp( j , 0 , cnt ) {
      int t = 0 ;
      fp( j2 , j , cnt )
        upd( t , 1ll * f[i-1][j2] * inv[j2+1] % hgs ) ,
    //  cout << i << " " << j << " " << t << " " << inv[j2+1] << endl ;
       f[i][j] = t ;
	}
  }
  int tans = 0 ;
  fp( j , 0 , cnt ) {
 // cout << cnt << "  to : " << j << " " << f[k][j] << endl;
    upd( tans , 1ll * qpow( v%hgs , j ) * f[k][j] % hgs ) ;
  }
  ans = 1ll * ans * tans % hgs ;
}
 signed main( ) {
  i60 n ;
  cin >> n >> k ;
  prep( ) ;
  for( int i=2 ; 1ll*i*i <= n ; ++i ) {
    if( n%i ) continue ;
    int tot = 0 ;
	while( n%i == 0 ) n /= i , tot ++ ;
	a.push_back( (node) { i , tot } ) ;
  }
  if( n > 1 )
    a.push_back( (node){ n%hgs , 1 } ) ;
  int l = a.size()-1 ;
  fp( i , 0 , l )
    solve( a[i].val , a[i].tot ) ;
  cout << ans << '\n' ;
  return 0 ;
}


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

using namespace std;
long long n;
const long long MOD=1e9+7;
long long a[1100];
int f[1100];
inline long long extend_gcd(long long a,long long b,long long &x,long long &y)
{
    if(a==0&&b==0)
        return -1ll;
    if(b==0)
    {
        x=1ll;
        y=0ll;
        return a;
    }
    long long d=extend_gcd(b,a%b,y,x);
    y-=a/b*x;
    return d;
}
inline long long ny(long long a,long long n)
{
    long long x,y,d=extend_gcd(a,n,x,y);
    if(d==1)
        {
                    if(x%n<=0)return x%n+n;
                    else return x%n;
                 }
    else
        return -1ll;
}
long long prime[1000010];
int pnum;
bool vis[50001000];
void getprime()
{
	pnum=0;
	long long gg=n;
	for(long long i=2;i<=10000000;i++)
	{
		if(!vis[i])
		{
			prime[++pnum]=i;
			while(gg%i==0) gg/=i;
		}
		for(int j=1;j<=pnum&&i*prime[j]<=10000000;j++)
		{
			vis[i*prime[j]]=1;
			if(i%prime[j]==0) break;
		}
	}
	if(gg>10000000)
	{
		prime[++pnum]=gg;
	}
}
long long dp[10100][20][100];
long long pow(long long x,long long y)
{
	long long re=1LL;
	while(y--)
	{
		re=re*x%MOD;
	}
	return re;
}
long long ans=0LL;
int num=0;
int K;
void getans(int x,long long now,int value)
{
	if(x==num)
	{
		ans=(ans+value*now%MOD)%MOD;
		return ;
	}
	for(int i=0;i<=f[x];i++)
	{
		getans(x+1,now*pow(a[x],i)%MOD,value*dp[K][x][i]%MOD);
	}
}
int main()
{
//	freopen("a.in", "r", stdin);
//	freopen("a.out", "w", stdout);

	scanf("%I64d",&n);
	scanf("%d",&K);
	getprime();
	for(int i=1;i<=pnum;i++)
	{
		if(n%prime[i]==0)
		{
			a[num]=prime[i];
			long long gg=n;
			f[num]=0;
			while(gg%prime[i]==0)
			f[num]++,gg/=prime[i];
			num++;
		}
	}
	for(int i=0;i<num;i++)
	{
		dp[0][i][f[i]]=1;
		for(int j=0;j<K;j++)
		{
			for(int k=f[i];k>=0;k--)
			{
				for(int l=k;l>=0;l--)
				{
					dp[j+1][i][l]=(dp[j+1][i][l]+dp[j][i][k]*ny(k+1,MOD)%MOD)%MOD;
				}
			}
		}
	}
	getans(0,1,1);
	printf("%I64d\n",ans);

	fclose(stdin);
	fclose(stdout);
	return 0;
}


//Undoubtedly Lucky Numbers
#include <cstdio>
#include <iostream>
#include <set>
using namespace std;
int n;
set<int> nums;

inline void dfs_buton(int num,int a,int b)
{
	if(num<=n)nums.insert(num);
	else return;
	dfs_buton(num*10+a,a,b);
	dfs_buton(num*10+b,a,b);
}
inline void dfs_shonton(int num,int a)
{
	if(num<=n)nums.insert(num);
	else return;
	dfs_shonton(num*10+a,a);
	for(int i=0;i<10;i++)
		dfs_buton(num*10+i,a,i);
}

int main()
{
	scanf("%d",&n);
	for(int i=1;i<10;i++)dfs_shonton(i,i);
	printf("%d",nums.size());
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1000000;

ll n;
int num,m,cnt,tot,tim;
int ep[100];
int pri[N>>1],np[N+10],f[2][10000];

ll v[10000],pr[100];
struct node
{
    int bel;
    ll val;
}p[10000];
map<ll,int> ref,vis;
void dfs(int x,ll now)
{
    if(x==m+1)
    {
        v[++tot]=now,ref[now]=tot;
        return ;
    }
    for(int i=0;i<=ep[x];i++)    dfs(x+1,now),now*=pr[x];
}
bool cmp(const node &a,const node &b)
{
    return (a.bel==b.bel)?(a.val<b.val):(a.bel<b.bel);
}
int main()
{
    scanf("%lld",&n);
    int i,j,d=0;
    ll tn=sqrt(n);
    for(i=2;i<=tn;i++)
    {
        if(!np[i])  pri[++num]=i;
        for(j=1;j<=num&&i*pri[j]<=tn;j++)
        {
            np[i*pri[j]]=1;
            if(i%pri[j]==0) break;
        }
    }
    ll t=n;
    for(i=1;i<=num&&pri[i]*pri[i]<=t;i++) if(t%pri[i]==0)
    {
        pr[++m]=pri[i];
        while(t%pri[i]==0)  t/=pri[i],ep[m]++;
    }
    if(t!=1)    pr[++m]=t,ep[m]=1;
    dfs(1,1);
    for(i=2;i<=tot;i++)  if(v[i]!=2)
    {
        t=v[i]-1;
        int flag=1;
        for(j=1;j<=num&&pri[j]*pri[j]<=t;j++) if(t%pri[j]==0)
        {
            t/=pri[j];
            while(t%pri[j]==0)  t/=pri[j];
            if(t!=1)    flag=0;
            else    t=pri[j];
            break;
        }
        if(flag)
        {
            p[++cnt].val=v[i];
            if(!vis[t]) vis[t]=++tim;
            p[cnt].bel=vis[t];
        }
    }
    sort(p+1,p+cnt+1,cmp);
    f[0][1]=1;
    for(j=1;j<=cnt;j++)
    {
        if(p[j].bel!=p[j-1].bel)    d^=1,memcpy(f[d],f[d^1],sizeof(f[0][0])*(tot+1));
        for(i=1;i<=tot;i++)  if(v[i]%p[j].val==0)
            f[d][i]+=f[d^1][ref[v[i]/p[j].val]];
    }
    printf("%d",f[d][tot]);
    return 0;
}


#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<vector>
#include<queue>
#include<bitset>
#include<string>
#include<stack>
#include<set>
#include<map>
#include<cstring>
#include<complex>
#include<cmath>
#include<iomanip>
#include<numeric>
#include<algorithm>
#include<list>
#include<functional>
#include<cassert>
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define INF 987654321
#define PI 3.14159265358979323846264
#define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
#define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c))
#define MEM0(a) memset(a,0,sizeof(a));
#define MEM_1(a) memset(a,-1,sizeof(a));
#define ALL(a) a.begin(),a.end()
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef pair<double, double> Pd;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<double> Vd;
typedef vector<Pi> VPi;
typedef vector<Pll> VPll;
typedef vector<Pd> VPd;
typedef tuple<int, int, int> iii;
typedef tuple<ll, ll, ll> LLL;
typedef vector<iii> Viii;
typedef vector<LLL> VLLL;
typedef complex<double> base;
ll MOD = 1000000007;
ll POW(ll a, ll b, ll MMM = MOD) { ll ret = 1; for (; b; b >>= 1, a = (a*a) % MMM)if (b & 1)ret = (ret*a) % MMM; return ret; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { if (a == 0 || b == 0)return a + b; return a*(b / gcd(a, b)); }
int dx[] = { 0,1,0,-1 }, dy[] = { 1,0,-1,0 };
int ddx[] = { 0,0,1,1,1,-1,-1,-1 }, ddy[] = { 1,-1,1,0,-1,1,0,-1 };

int n, m, l;
char a[101], b[101], c[101];
int pi[100];
int d[100][100][100];
int go(int N, int M, int L)
{
	if (L == l)return -INF;
	if (N == n || M == m)return 0;
	int &ret = d[N][M][L];
	if (ret != -1)return ret;
	ret = 0;
	ret = max(ret, go(N + 1, M, L));
	ret = max(ret, go(N, M + 1, L));
	if (a[N] == b[M])
	{
		if (a[N] == c[L])ret = max(ret, 1 + go(N + 1, M + 1, L + 1));
		else
		{
			while (L != 0 && a[N] != c[pi[L - 1]])L = pi[L];
			if (a[N] == c[L])ret = max(ret, 1 + go(N + 1, M + 1, L + 1));
			else ret = max(ret, 1 + go(N + 1, M + 1, L));
		}
	}
	return ret;
}
void track(int N, int M, int L)
{
	if (N == n || M == m)return;
	int t1 = go(N + 1, M, L);
	int t2 = go(N, M + 1, L);
	int t3 = -INF, t4 = -INF, t5 = -INF;
	if (a[N] == b[M])
	{
		if (a[N] == c[L])t3 = 1 + go(N + 1, M + 1, L + 1);
		else
		{
			while (L != 0 && a[N] != c[pi[L - 1]])L = pi[L];
			if (a[N] == c[L])t4 = go(N + 1, M + 1, L + 1);
			else t5 = 1 + go(N + 1, M + 1, L);
		}
	}
	int MAX = max({ t1,t2,t3,t4,t5 });
	if (t1 == MAX)track(N + 1, M, L);
	else if (t2 == MAX)track(N, M + 1, L);
	else if (t3 == MAX)
	{
		printf("%c", a[N]);
		track(N + 1, M + 1, L + 1);
	}
	else if (t4 == MAX)
	{
		printf("%c", a[N]);
		track(N + 1, M + 1, 1);
	}
	else
	{
		printf("%c", a[N]);
		track(N + 1, M + 1, 0);
	}
}
int main() {
	MEM_1(d);
	scanf("%s%s%s", a, b, c);
	n = strlen(a), m = strlen(b), l = strlen(c);
	for (int i = 1, j = 0; i < l; i++)
	{
		while (j > 0 && c[i] != c[j]) j = pi[j - 1];
		if (c[i] == c[j]) pi[i] = ++j;
	}
	int t = go(0, 0, 0);
	if (t == 0)return !printf("0");
	track(0, 0, 0);
}


    #include<stdio.h>
    int main()
    {
        char a[101];
        int i,n,count=0,cnt=0;
        scanf("%d",&n);
        for(i=0;i<n;i++){
            scanf("%s",a);
        }

        for(i=0; i<n; i++)
        {

            if(a[i]=='S')while(a[i+1]=='F')
            {
                count++;
            }

            else if  (a[i]=='F')while(a[i+1]=='S')
            {
                cnt++;

            }

        }
        if(count>=cnt)
        {
            printf("YES");
        }
        else
        {
            printf("NO");
        }
        return 0;
    }


#include <bits/stdc++.h>

#define _for(i,a,b) for (int i=(a),_b_=(b);i<_b_;i++)
#define _fod(i,a,b) for (int i=(a),_b_=(b);i>_b_;i--)
#define _it(i,v) for (typeof((v).begin()) i = (v).begin(); i != (v).end(); ++i)
#define _all(v) v.begin(), v.end()
#define __(v) memset(v,0,sizeof(v))

using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
template<typename T> vector<T> &operator += (vector<T> &v, T x) {v.push_back(x);return v;}

void solve() {
	int a,b;
	cin>>a>>b;
	int c1(0),c2(0);
	while(a > 0 || b > 0){
		if(a > 0 && b > 0){
			c1++;
			a--;
			b--;
		}else{
			if(a > 1){
				c2++;
				a -= 2;
				if(a == 1) break;
			}
			if(b > 1){
				c2++;
				b -= 2;
				if(b == 1) break;
			}
		}
	}
	cout<<c1<<" "<<c2;
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    #ifdef HIEUNV
    freopen("input.txt","r",stdin);
//  freopen("output.txt","w",stdout);
    #endif
    solve();
}


#include <cstdio>
#include <iostream>
#include <cstring>
using namespace std;
#define MOD 1000000007

int dp[200][20];
int p[200];
int pp[20];

int dfs(int h,int num,bool flag){
    if(num<0) return 0;
    if(h==-1) return num==0;
    if(!flag && dp[h][num]!=-1) return dp[h][num];
    int up = flag?p[h]:9;
    int res= 0;
    for(int i=0;i<=up;i++){
        if(i==4 || i==7) res += dfs(h-1,num-1,flag&&i==up);
        else res += dfs(h-1,num,flag&&i==up);
    }
    if(!flag) dp[h][num] = res;
    return res;
}

int solve(int k,int a){
    memset(dp,-1,sizeof(dp));
    int cnt=0;
    while(k){
        p[cnt++] = k%10;
        k /= 10;
    }
    return dfs(cnt-1,a,true);
}

long long F(int n,int m){
    long long res = 1;
    for(int i=0;i<m;i++) res = (res*(n-i))%MOD;
    return res%MOD;
}

long long dfs(int p,int sum,int t,int y[],int tot){
    //cout<< p << " "<<sum <<" "<<t <<" "<<tot<<endl;
    if(sum>=t && p!=0) return 0;
    if(p==7){
        long long res = 1;
        for(int i=0;i<=tot;i++){
            //cout << "##" <<pp[i] <<" " <<y[i] <<endl;
            res = res*F(pp[i],y[i])%MOD;
        }
        return res;
    }

    long long ans = 0;
    for(int i=0;i<=tot;i++){
        //cout << "i " <<i <<endl;
        y[i]++;
        if(p==0) {
            ans += dfs(p+1,sum,i,y,tot);
            ans%=MOD;
        }else{
            ans += dfs(p+1,sum+i,t,y,tot);
            ans%=MOD;
        }
        y[i]--;
    }
    return ans;
}

int main(){
    int m;
    cin >> m;
    if(m<=7) cout<<0 <<endl;
    else{
        memset(dp,-1,sizeof(dp));
        int t = m;
        int tmp = 0;
        while(t) {
            t/=10;
            tmp++;
        }

       // cout <<"tmp:" <<tmp <<endl;
        for(int i=0;i<=tmp;i++){
            pp[i] = solve(m,i);
            if(i==0) pp[i]--;  // 0
            //cout << "i:" <<i << " " <<pp[i] <<endl;
        }

        long long ans = 0,tt=1;
        int x[10],y[10];
        int z1,z2,z3,z4,z5;
        memset(y,0,sizeof(y));
        ans = dfs(0,0,0,y,tmp);
/*
        for( x[0]=1;x[0]<=tmp;x[0]++){
            y[x[0]]++;
            for( x[1]=0;x[1]<x[0];x[1]++){

                y[x[1]]++;
                z1 = x[0]-x[1];
                for( x[2]=0;x[2]<z1;x[2]++){

                    y[x[2]]++;
                    z2 = z1-x[2];
                    for( x[3]=0;x[3]<z2;x[3]++){

                        y[x[3]]++;
                        z3 = z2-x[3];
                        for( x[4]=0;x[4]<z3;x[4]++){

                            y[x[4]]++;
                            z4 = z3 - x[4];
                            for( x[5]=0;x[5]<z4;x[5]++){

                                y[x[5]]++;
                                z5 = z4-x[5];
                                for(x[6]=0;x[6]<z5;x[6]++){

                                    y[x[6]]++;

                                    tt=1;
                                    for(int i=0;i<=tmp;i++){
                                        //printf("##: %d %d\n",pp[i],y[i]);
                                        tt = tt*F(pp[i],y[i])%MOD;
                                    }
                                    ans  = (ans+tt)%MOD;
                                    y[x[6]]--;
                                }
                                y[x[5]]--;
                            }
                            y[x[4]]--;
                        }
                        y[x[3]]--;
                    }
                    y[x[2]]--;
                }
                y[x[1]]--;
            }
            y[x[0]]--;
        }
*/
        cout << ans <<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,ans=0;
    scanf("%d",&n);
    for(int i=2; i<=n-1; i++)ans+=i*(i+1);
    printf("%d",ans);
    return 0
}


#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<math.h>
#include<string>
#include<string.h>
#include<iostream>
#include<vector>
#include<set>
#include<algorithm>
#include<time.h>
#include<queue>
#include<map>
#include<limits.h>
//#include"windows.h"

#define vi vector <int>
#define ll long long
#define ull unsigned long long
#define ld long double
#define dd double
#define am &

#define pi 3.141592653589793238462643383279
#define rad 57.295779513082323
#define sc scanf
#define pr printf
#define mp make_pair
#define poo(i,a,b) for(ll i=a;i<=b;i++)
#define oop(i,a,b) for(ll i=a;i>=b;i--)
using namespace std;
/*namespace Help
{
	ll gcd(ll a, ll b)
	{
		while (a != 0 && b != 0)
		{
			if (a > b)
				a &= b;
			else
				b %= a;
		}
		return a + b;
	}
	void Qsort(int a[], int f, int q)
	{
		int l = f, r = q, x = a[(f + q) / 2], c;

		if (f >= q) return;
		while (l <= r)
		{
			while (a[l] < x)
				l++;
			while (a[r] > x)
				r--;
			if (l <= r)
			{
				swap(a[l], a[r]);
				l++;
				r--;
			}

		}
		Qsort(a, f, r);
		Qsort(a, l, q);
	}
	void Qsort(ll a[], int f, int q)
	{
		ll l = f, r = q, x = a[(f + q) / 2], c;

		if (f >= q) return;
		while (l <= r)
		{
			while (a[l] < x)
				l++;
			while (a[r] > x)
				r--;
			if (l <= r)
			{
				swap(a[l], a[r]);
				l++;
				r--;
			}

		}
		Qsort(a, f, r);
		Qsort(a, l, q);
	}
	int binsearch(int n, int a[], int h)
	{
		int l = 0, r = h, c = n;
		while (l < r - 1)
		{
			c = (l + r) / 2;
			if (n < a[c])
				r = c;
			else l = c;
		}
		if (a[l] == n)
			return l + 1;
		else return -1;
	}
	bool isPrime(ll a)
	{
		ll i;
		if (a % 2 == 0)
			return 0;
		else
			for (i = 3; i * i <= a; i += 2)
				if (a % i == 0)
					return 0;
		return 1;
	}
};*/
/*pair<int, int> t[131073 * 2] = { {0,0} };
pair<int, int> a[131073] = { {0,0} };
int N;*/
/*void build(int tl, int tr, int v)
{
	if (tr == tl) return;
	if (tr-tl ==1)
	{
		t[v].first =  -1e9-1;
		t[v].second = +1e9+1;
	}
	else
	{
		int tm = (tl + tr) / 2;
		build(tl, tm, 2 * v + 1);
		build(tm, tr, 2 * v + 2);
		t[v].second = fmin(t[v * 2+1].second, t[v * 2 + 2].second);
		t[v].first = fmax(t[v * 2+2].first, t[v * 2 + 1].first);
	}
}*/
/*
void upd(int i, int x)
{
	int v = i + N;
	t[v].first = x;
	t[v].second = x;
	v /= 2;
	while (v > 0)
	{
		t[v].second = fmin(t[v * 2].second, t[v * 2 + 1].second);
		t[v].first = fmax(t[v * 2].first, t[v * 2 + 1].first);
		v /= 2;
	}
}
int getmi(int l, int r, int tl, int tr, int v)
{
	if (l > r)return 1e9 + 1;
	else if (l == tl && r == tr)
		return t[v].second;
	else
	{
		int tm = (tl + tr) / 2;
		int a = getmi(l, min(r, tm), tl, tm, 2 * v);
		int b = getmi(max(l, tm + 1), r, tm + 1, tr, 2 * v + 1);
		return min(a, b);
	}

}
int getma(int l, int r, int tl, int tr, int v)
{
	if (l > r)return -1e9 - 1;
	else if (l == tl && r == tr)
		return t[v].first;
	else
	{
		int tm = (tl + tr) / 2;
		int a = getma(l, min(r, tm), tl, tm, 2 * v);
		int b = getma(max(l, tm + 1), r, tm + 1, tr, 2 * v + 1);
		return max(a, b);
	}

}
void getN(int n)
{
	N = 1;
	while (N < n)N *= 2;
}
*/
int main()
{
	int a, n, m,k0,r,max=0,min=1e5,temp,ak=0;
	sc("%d%d%d",am n,am m,am r);
	for (int i = 0; i < n; i++)
	{
		sc("%d", am temp);
		if (temp < min)min = temp;
	}
	for (int i = 0; i <m; i++)
	{
		sc("%d", am temp);
		if (temp > max)max = temp;
	}
	k0 = r;
	ak = r / min;
	r %= min;
	r += ak * max;
	printf("%d", fmax(r,k0));
	return 0;
}


//#pragma comment(linker, "/stack:20000000")
#include <algorithm>
#include <iostream>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <sstream>
#include <fstream>
#include <cstdio>
#include <vector>
#include <cctype>
#include <string>
#include <stack>
#include <cmath>
#include <queue>
#include <deque>
#include <list>
#include <set>
#include <map>
using namespace std;
#define coder_shahnur() main(void)

int coder_shahnur()
{
#ifdef _SHAHNUR
	freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#endif
	int n;
	cin >> n;
	set<int> s;
	for (int i = 0; i < n; i++)
	{
		int num;
		cin >> num;
		s.insert(num);
	}
	vector<int> v(s.begin(), s.end());
	int flag = 0;
	for (int i = 0; i < v.size() - 2; i++)
	{
		if (abs(v[i + 2] - v[i]) <= 2 && abs(v[i + 1] - v[i]) <= 2 && abs(v[i + 2] - v[i + 1]) <= 2)
		{
			flag = 1;
		}
	}
	if (!flag) cout << "NO" << endl;
	else cout << "YES" << endl;
	return 0;
}


#include <iostream>
#include <algorithm>

using namespace std;

int main(){

    int v[2];

    cin >> v[0] >> v[1] >> v[2];

    sort(v, v + 3);

    if( v[0] + v[1] < v[2]){
        cout << v[2] - ( v[0] + v[1]) + 1;
    }else{
        cout << 0;
    }

}


#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
	double l,d,v,g,r,temp;
	scanf("%lf%lf%lf%lf%lf",&l,&d,&v,&g,&r);
	temp=d/v;
	while(temp>g+r)
	{
		temp-=g+r;
	}
	if(temp<g)
		printf("%.8f\n",l/v);
	else if(temp<=g+r)
		printf("%.8f\n",g+r+(l-d)/v);
	return 0;
}/*2017-07-30 20:04:19.708*/


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

int main(){
ll test,i,j,xy,count,flag=0,n,o1=0,o2=0,x,y,m,l,z,max1,x1,y1,x2,y2,z1,k,sum,f,r,ans1,min1;
string a,ans;
cin>>a>>k;
n=a.size();
while(k>0){
for(i=0;i<n;i++){
	x1=i;
	for(j=i+1;j<n && j-i<=k;j++){
		if(a[i]<a[j] ){
			//cout<<a<<" "<<k<<"\n";
		     x1=j;
		}
	}
	for(x=x1;x>i && k>0 ;x--,k--){
		swap(a[x],a[x-1]);
	}
}
}
cout<<a<<"\n";
return 0;
}


#pragma GCC optimize ("O3", "unroll-loops")
//#pragma GCC target ("avx2")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define distinct(x) sort(all(x)); x.resize(unique(all(x))-x.begin())
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define CASE(x) int x; cin >> x; while (x--)
#define CASEt(x) int x; cin >> x; for (int tc = 1; tc <= x; ++tc)
using namespace std;
using namespace __gnu_pbds;
namespace {
	const int MOD107 = 1000000007;
	const int MOD998 = 998244353;
	using ll = long long;
	using ull = unsigned long long;
	using pii = pair<int, int>;
	using pll = pair<ll, ll>;
	template <class T> using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
	template <class T> using minheap = priority_queue<T, vector<T>, greater<T>>;
	template <class T> using maxheap = priority_queue<T, vector<T>, less<T>>;
	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//	mt19937_64 rng64(chrono::steady_clock::now().time_since_epoch().count());
	template <int MODVALUE>
	struct Modular {
	private:
		long long val;

	public:
		explicit operator long long() const { return val; }

		bool operator == (const Modular& other) { return val == other.val; }
		bool operator != (const Modular& other) { return val != other.val; }
		template<class T> bool operator == (const T& other) { return *this == Modular(other); }
		template<class T> bool operator != (const T& other) { return *this != Modular(other); }
		template<class T> friend bool operator == (const T& other, const Modular& m) { return Modular(other) == m; }
		template<class T> friend bool operator != (const T& other, const Modular& m) { return Modular(other) != m; }

		bool operator <  (const Modular& other) { return val <  other.val; }
		bool operator <= (const Modular& other) { return val <= other.val; }
		bool operator >  (const Modular& other) { return val >  other.val; }
		bool operator >= (const Modular& other) { return val >= other.val; }
		template<class T> bool operator <  (const T& other) { return *this <  Modular(other); }
		template<class T> bool operator <= (const T& other) { return *this <= Modular(other); }
		template<class T> bool operator >  (const T& other) { return *this >  Modular(other); }
		template<class T> bool operator >= (const T& other) { return *this >= Modular(other); }
		template<class T> friend bool operator <  (const T& other, const Modular& m) { return Modular(other) <  m; }
		template<class T> friend bool operator <= (const T& other, const Modular& m) { return Modular(other) <= m; }
		template<class T> friend bool operator >  (const T& other, const Modular& m) { return Modular(other) >  m; }
		template<class T> friend bool operator >= (const T& other, const Modular& m) { return Modular(other) >= m; }

		Modular& operator += (const Modular& other) { val += other.val; val %= MODVALUE; return *this; }
		Modular  operator +  (const Modular& other) { Modular tmp = *this; return tmp += other; }
		template<class T> Modular& operator += (const T& other) { return *this += Modular(other); }
		template<class T> Modular  operator +  (const T& other) { return *this +  Modular(other); }
		template<class T> friend Modular operator += (const T& other, const Modular& m) { return Modular(other) += m; }
		template<class T> friend Modular operator +  (const T& other, const Modular& m) { return Modular(other) +  m; }

		Modular& operator ++()    { return *this += 1; }
		Modular  operator ++(int) { Modular tmp = *this; ++*this; return tmp; }

		Modular  operator -  () const { return Modular(-val); }
		Modular& operator -= (const Modular& other) { val -= other.val; val += MODVALUE; val %= MODVALUE; return *this;}
		Modular  operator -  (const Modular& other) { Modular tmp = *this; return tmp -= other; }
		template<class T> Modular& operator -= (const T& other) { return *this -= Modular(other); }
		template<class T> Modular  operator -  (const T& other) { return *this -  Modular(other); }
		template<class T> friend Modular operator -= (const T& other, const Modular& m) { return Modular(other) -= m; }
		template<class T> friend Modular operator -  (const T& other, const Modular& m) { return Modular(other) -  m; }

		Modular& operator --()    { return *this -= 1; }
		Modular  operator --(int) { Modular tmp = *this; --*this; return tmp; }

		Modular& operator *= (const Modular& other) { val *= other.val; val %= MODVALUE; val += MODVALUE; val %= MODVALUE; return *this; }
		Modular  operator *  (const Modular& other) { Modular tmp = *this; return tmp *= other; }
		template<class T> Modular& operator *= (const T& other) { return *this *= Modular(other); }
		template<class T> Modular  operator *  (const T& other) { return *this *  Modular(other); }
		template<class T> friend Modular operator *= (const T& other, const Modular& m) { return Modular(other) *= m; }
		template<class T> friend Modular operator *  (const T& other, const Modular& m) { return Modular(other) *  m; }

		Modular pow(long long power) const {
			Modular m = *this, ans = 1;
			while (power) {
				if (power & 1) ans *= m;
				m *= m;
				power >>= 1;
			}
			return ans;
		}
		Modular pow(const Modular& other) const { return pow(other.val); }
		Modular inv() const { return pow(MODVALUE-2); }

		Modular& operator /= (const Modular& other) { val *= other.inv().val; val %= MODVALUE; return *this; }
		Modular  operator /  (const Modular& other) { Modular tmp = *this; return tmp /= other; }
		template<class T> Modular& operator /= (const T& other) { return *this /= Modular(other); }
		template<class T> Modular  operator /  (const T& other) { return *this /  Modular(other); }
		template<class T> friend Modular operator /= (const T& other, const Modular& m) { return Modular(other) /= m; }
		template<class T> friend Modular operator /  (const T& other, const Modular& m) { return Modular(other) /  m; }

		friend istream& operator >> (istream& in, Modular& m) { in >> m.val; m.val %= MODVALUE; m.val += MODVALUE; m.val %= MODVALUE; return in; }
		friend ostream& operator << (ostream& out, const Modular& m) { return out << m.val; }

		Modular() : val(0) {}
		Modular(int val) : val((val % MODVALUE + MODVALUE) % MODVALUE) {};
		Modular(long long val) : val((val % MODVALUE + MODVALUE) % MODVALUE) {};
	};
	inline ll pow(ll b, ll p, ll mod) {
		b %= mod;
		ll ans = 1;
		for (; p > 0; p >>= 1) {
			if (p&1) {ans *= b; ans %= mod;}
			b *= b;
			b %= mod;
		}
		return ans;
	}
	inline ll max(ll a, int b) { return (a > b ? a : b); }
	inline ll max(int a, ll b) { return (a > b ? a : b); }
	inline ll min(ll a, int b) { return (a < b ? a : b); }
	inline ll min(int a, ll b) { return (a < b ? a : b); }
	template <class T> inline bool chkmin(T&x, const T& y) { return x > y ? x = y, 1 : 0; }
	template <class T> inline bool chkmax(T&x, const T& y) { return x < y ? x = y, 1 : 0; }
}
namespace IO {
	template<class T> inline void _R(T &x) {cin >> x;}
	template<class T1, class T2> inline void _R(pair<T1,T2> &x) {_R(x.first); _R(x.second);}
	template<class T> inline void _R(vector<T> &x) {for (auto& i : x) _R(i);}
	template<class T> inline void _R(deque<T> &x) {for (auto& i : x) _R(i);}
	inline void R() {}
	template<class T1, class... T2> inline void R(T1 &x, T2 &...y) { _R(x); R(y...);}

	template<class T> inline void _W(const T& x);
	template<class T1, class T2> inline void _W(const pair<T1,T2>& p);
	template<class... T> inline void _W(const vector<T...>& x);
	template<class... T> inline void _W(const deque<T...>& x);
	template<class... T> inline void _W(const forward_list<T...>& x);
	template<class... T> inline void _W(const list<T...>& x);
	template<class... T> inline void _W(const set<T...>& x);
	template<class... T> inline void _W(const multiset<T...>& x);
	template<class... T> inline void _W(const unordered_set<T...>& x);
	template<class... T> inline void _W(const unordered_multiset<T...>& x);
	template<class... T> inline void _W(const map<T...>& x);
	template<class... T> inline void _W(const multimap<T...>& x);
	template<class... T> inline void _W(const unordered_map<T...>& x);
	template<class... T> inline void _W(const unordered_multimap<T...>& x);

	template<class T> inline void _W(const ordered_set<T>& x);

	template<class Container> inline void printContainer(const Container& x) { bool isFirst = 1; for (auto i : x) { if (!isFirst) cout << ' '; isFirst = 0; _W(i); } }

	template<class T> inline void _W(const T& x) {cout << x;}
	template<class T1, class T2> inline void _W(const pair<T1,T2>& p) {_W(p.first); _W(' '); _W(p.second);}
	template<class... T> inline void _W(const vector<T...>& x) { printContainer(x); }
	template<class... T> inline void _W(const deque<T...>& x) { printContainer(x); }
	template<class... T> inline void _W(const forward_list<T...>& x) { printContainer(x); }
	template<class... T> inline void _W(const list<T...>& x) { printContainer(x); }
	template<class... T> inline void _W(const set<T...>& x) { printContainer(x); }
	template<class... T> inline void _W(const multiset<T...>& x) { printContainer(x); }
	template<class... T> inline void _W(const unordered_set<T...>& x) { printContainer(x); }
	template<class... T> inline void _W(const unordered_multiset<T...>& x) { printContainer(x); }
	template<class... T> inline void _W(const map<T...>& x) { printContainer(x); }
	template<class... T> inline void _W(const multimap<T...>& x) { printContainer(x); }
	template<class... T> inline void _W(const unordered_map<T...>& x) { printContainer(x); }
	template<class... T> inline void _W(const unordered_multimap<T...>& x) { printContainer(x); }

	template<class T> inline void _W(const ordered_set<T>& x) { printContainer(x); }

 	inline void W() {cout << '\n';}
	template<class T> inline void W(const T &x) {_W(x); W();}
	template<class T1, class... T2> inline void W(const T1 &x, const T2 &...y) { _W(x); _W(' '); W(y...);}
} using namespace IO;
namespace outputFormat{
	inline string Case(int tc) {return "Case #" + to_string(tc) + ':';}
	inline string YN(bool b) {return b ? "YES" : "NO";}
} using namespace outputFormat;
namespace std {
    template <class T1, class T2> struct hash<pair<T1,T2>> {
    	std::size_t operator()(pair<T1,T2> _) const {
        	return hash<T1>{}(_.first) ^ hash<T2>{}(_.second);
    	}
    };
}
using Mint = Modular<MOD998>;

int main() {
	int n,k,l; R(n,k,l);
	vector<vector<vector<Mint>>> dp(n * 2 + 7, vector<vector<Mint>>(n + 7, vector<Mint>(3, 0)));

	dp[0][0][0] = 1;
	for (int len = 1; len <= 2 * n + 1; len++)
		for (int left = 0; left <= n; left++)
			for (int used = 0; used <= 1; used++) {
				Mint& now = dp[len][left][used];
				int Rp = (len - left - used) / 2;

				if (left)
					now += dp[len - 1][left - 1][used];
				if (Rp)
					now += dp[len - 1][left + 1][used] * (left + 1);
				if (used && left >= k)
					now += dp[len - 1][left][used - 1];
			}

	Mint ans = dp[n * 2 + 1][0][1];

	ans *= ((Mint)2).pow(n);

	Mint fac = 1;
	for (Mint i = n + 1; i <= 2 * n + 1; i++)
		fac *= i;

	ans *= fac.inv();

	ans *= l;

	W(ans);

	return 0;
}

static auto _batch_ios = [](){
#ifndef LOCAL
	ios::sync_with_stdio(false);
	cin.tie(0);
#endif
	cout << fixed << setprecision(10);
	return 42;
}();


#include<bits/stdc++.h>
#define int long long
#define max(a,b) a>b?a:b
using namespace std;
int ans,jc[1000001];
int C(int a,int b){
	if(a<b)return 0;
	return jc[a]/jc[a-b]/jc[b];
}
void work(int a,int b,int c,int l){
	for(int i=max(0,a+b-c);i<=l;i++){
		int tmp=min(l-i,c+i-a-b);
		ans-=C(tmp+2,2);
	}
}
main(){
	jc[0]=1;
	for(int i=1;i<=1000000;i++){
		jc[i]=jc[i-1]*i;
	}
	int a,b,c,l;
	cin>>a>>b>>c>>l;
	ans+=C(l+3,3);
	work(a,b,c,l);
	work(a,c,b,l);
	work(b,c,a,l);
	cout<<ans<<endl;
}


#include<iostream>
#include<cstring>
#include<string>
using namespace std;
char a[1001],b[1001],virus[1001],ans[1001],res[1001];
int lena,lenb;
int Maxlen=0;
void DFS(int len,int apos,int bpos)
{
    //cout<<ans<<endl;
    for(int i=bpos+1;i<lenb;++i)
    {
        for(int j=apos+1;j<lena;++j)
        {
            if(b[i]==a[j])
            {
                ans[len]=b[i];
                DFS(len+1,j,i);
            }
        }
    }
    //cout<<ans<<endl;
    if(len>Maxlen && strstr(ans,virus)==NULL)
    {
        Maxlen=len;
        strcpy(res,ans);
    }
//  memset(ans,'\0',sizeof(ans));
}
int main()
{
    cin>>a>>b>>virus;
    lena=strlen(a),lenb=strlen(b);
    DFS(0,-1,-1);
    if(Maxlen)
    {
        for(int i=0;i<Maxlen;++i)
            cout<<res[i];
        cout<<endl;
    }
    else
        cout<<0<<endl;
    //system("pause");
    return 0;
}
/*
AJKEQSLOBSROFGZ
OVGURWZLWVLUXTH
OZ
*/


#include<cstring>
#include<cstdlib>
#include<algorithm>
#define N 42
using namespace std;
int res[N][N],d[N][N],a[N],b[N],ans[N][N],i,n,m,j,k;
void cheng(int a[N][N],int b[N][N]){
	int c[N][N],i,j,k;
	memset(c,120,sizeof(c));
	for(i=0;i<=2*n;++i)
		for(j=0;j<=2*n;++j)
			for(k=0;k<=2*n;++k)c[i][k]=min((long long)c[i][k],(long long)a[i][j]+b[j][k]);
	memcpy(a,c,sizeof(c));
}
int main(){
	int t=m/2;m=2;
	scanf("%d%d",&n,&m);
	for(i=1;i<=n;++i)scanf("%d",&a[i]);
	for(i=1;i<=n;++i)scanf("%d",&b[i]);
	memset(d,120,sizeof(d));
	for(i=0;i<=2*n;++i)d[i][i]=0;
	for(i=1;i<=n;++i){
		memcpy(res,d,sizeof(d));
		memset(d,120,sizeof(d));
		for(j=0;j<=2*n;++j)
			for(k=0;k<=2*n;++k){
				if(k!=0)d[j][k-1]=min(d[j][k-1],res[j][k]+b[i]);
				if(k!=2*n)d[j][k+1]=min(d[j][k+1],res[j][k]+a[i]);
			}
	}
	memset(ans,120,sizeof(ans));
	ans[0][0]=0;
	while(m){
		if(m&1)cheng(ans,d);
		cheng(d,d);
		m/=2;
	}
	printf("%d\n",ans[0][0]*t);
}


#include <bits/stdc++.h>

using namespace std;

#define x first
#define y second

int dx[]={0, 0, 1, -1};
int dy[]={1, -1, 0, 0};

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

template <class T> inline void smin(T &a, T b) {if (a>b) a=b;}
template <class T> inline void smax(T &a, T b) {if (a<b) a=b;}
#define NN 22
#define inf 0x3f3f3f3f

int N, a[NN], b[NN];
int f[NN][NN], g[NN][NN];

int calc(int g[NN][NN], int f[NN][NN], int n) {
	int i, j, k, tmp[NN][NN];

	if (n==0) {
		for (i=0; i<=N; i++) for (j=0; j<=N; j++) f[i][j]=inf;
		for (i=0; i<=N; i++) f[i][i]=0;
		return 0;
	}

	calc(g, tmp, n/2);

	for (i=0; i<=N; i++) for (j=0; j<=N; j++) {
		f[i][j]=inf;
		for (k=0; k<=N; k++) smin(f[i][j], tmp[i][k]+tmp[k][j]);
	}

	if (n%2) {
		for (i=0; i<=N; i++) for (j=0; j<=N; j++) {
			tmp[i][j]=inf;
			for (k=0; k<=N; k++) smin(tmp[i][j], f[i][k]+g[k][j]);
		}
		for (i=0; i<=N; i++) for (j=0; j<=N; j++) f[i][j]=tmp[i][j];
	}
}

int main() {

	int bit, M, i, s, deep, cnt, u, v;

	scanf("%d%d", &N, &M);
	for (i=0; i<N; i++) scanf("%d", a+i);
	for (i=0; i<N; i++) scanf("%d", b+i);

	memset(g, 0x3f, sizeof(g));

	for (bit=0; bit<(1<<N); bit++) {
		s=deep=cnt0;

		for (i=0; i<N; i++) {
			if (bit&(1<<i)) {
				s+=a[i]; deep++;
			} else {
				s+=b[i]; deep--;
			}

			smin(cnt, deep);
		}

		for (int j=-cnt; j<=N; j++) {
			u=j; v=j+deep;
			if (v<=N && v>=0) smin(g[u][v], s);
		}
	}

	calc(g, f, M);
	printf("%d\n", f[0][0]);

	return 0;
}


#include <cstdio>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <sstream>
#include <algorithm>
#include <ctime>
#include <cmath>

using namespace std;

const int nmax = 80 * 80 / 2;
const int Nm = nmax * 2 + 2;
const int Mm = 2 * nmax * 4;
const int INF = 1000000000;

class costflow {
    int s[Nm], q[Nm], pre[Nm], v[Nm]; // Ns
    int t[Mm], next[Mm], cf[Mm]; // Ms
    int w[Mm], d[Nm];
    int cnt;
    int N;

public:

    void init(int n) {
        cnt = 1;
        N = n;
        memset(s, 0, sizeof (s));
        memset(d, 0, sizeof (d));
        memset(q, 0, sizeof (q));
        memset(pre, 0, sizeof (pre));
        memset(v, 0, sizeof (v));

        memset(t, 0, sizeof (t));
        memset(cf, 0, sizeof (cf));
        memset(w, 0, sizeof (w));
        memset(next, 0, sizeof (next));
    }

    void add(int ss, int tt, int cc, int ww) {
        ++cnt;
        t[cnt] = tt;
        cf[cnt] = cc;
        w[cnt] = ww;
        next[cnt] = s[ss];
        s[ss] = cnt;
        ++cnt;
        t[cnt] = ss;
        cf[cnt] = 0;
        w[cnt] = -ww;
        next[cnt] = s[tt];
        s[tt] = cnt;
    }

    pair<int, int> getflow(int S, int T) {
        int cost = 0;
        int flow = 0;
        int i, j, head, tail;
        while (true) {
            head = 0;
            tail = 1;
            for (i = 0; i < N; i++) {
                d[i] = INF;
            }
            for (i = 0; i < N; i++) {
                v[i] = 0;
            }
            d[S] = 0;
            q[1] = S;
            while (head != tail) {
                v[i = q[head = (head + 1) % N]] = 0;
                for (j = s[i]; j != 0; j = next[j]) {
                    if (cf[j] != 0 && d[t[j]] > d[i] + w[j]) {
                        d[t[j]] = d[i] + w[j];
                        pre[t[j]] = j;
                        if (v[t[j]] == 0) {
                            v[t[j]] = 1;
                            q[tail = (tail + 1) % N] = t[j];
                        }
                    }
                }
            }
            if (d[T] == INF) {
                return make_pair(flow, cost);
            }
            cost += d[T];
            ++flow;
            for (i = T; i != S; i = t[pre[i] ^ 1]) {
                --cf[pre[i]];
                ++cf[pre[i] ^ 1];
            }
        }
    }
} network;

int a[80][80];

int main()
{
	//freopen("counter.in", "r", stdin);
	//freopen("counter.out", "w", stdout);

	string s;
	int i, j, k, n, m;

	cin >> n >> m;
	for(i = 0; i < n; i++)
		for(j = 0; j < m; j++)
			cin >> a[i][j];

	const int di[4] = {-1, 0, 1, 0};
	const int dj[4] = {0, 1, 0, -1};
	network.init(2 + n * m);
	for(i = 0; i < n; i++)
		for(j = 0; j < m; j++)
			if ((i + j) % 2 == 0)
			{
				for(int d = 0; d < 4; d++)
				{
					int ii = i + di[d];
					int jj = j + dj[d];
					if (ii < 0 || ii >= n || jj < 0 || jj >= m)
						continue;
					//cout << i << " " << j << " - " << ii << " " << jj << ": " << (a[i][j] != a[ii][jj]) << endl;
					network.add(i * m + j, ii * m + jj, 1, (a[i][j] != a[ii][jj]));
				}
				network.add(n * m, i * m + j, 1, 0);
			} else
				network.add(i * m + j, n * m + 1, 1, 0);
	cout << network.getflow(n * m, n * m + 1).second << endl;

	return 0;
}


#include<bits/stdc++.h>
#define fr(i,a,b) for(int i(a),end##i(b);i<=end##i;i++)
#define fd(i,a,b) for(int i(a),end##i(b);i>=end##i;i--)
using namespace std;
const int maxn=500+5;
int n,m,mod;
int upd(const int &x){
	if(x<0)return x+mod;
	if(x>=mod)return x-mod;
	return x;
}
void add(int &x,const int &y){
	x=upd(x+y);
}
int ksm(int x,int k){
	int ans=1;
	while(k){
		if(k&1)ans=1ll*ans*x%mod;
		x=1ll*x*x%mod;
		k>>=1;
	}
	return ans;
}
int jc[maxn],inv[maxn];
void init(int n){
	jc[0]=1;
	fr(i,1,n)jc[i]=1ll*jc[i-1]*i%mod;
	inv[n]=ksm(jc[n],mod-2);
	fd(i,n-1,0)inv[i]=1ll*inv[i+1]*(i+1)%mod;
}
int C(int n,int m){
	if(n<0||m<0||n<m)return 0;
	return 1ll*jc[n]*inv[n-m]%mod*inv[m]%mod;
}
vector<int> f,g;
int S(int n){
	return n*(n+1)/2;
}
vector<int> operator *(const vector<int> &A ,const vector<int> &B){
	vector<int> C(A.size()+B.size()-1);
	fr(i,0,A.size()-1)fr(j,0,B.size()-1)add(C[i+j],1ll*A[i]*B[j]%mod);
	return C;
}
int G(int n,int m){
	return C(m+n-1,n-1);
}
int main(){
#ifdef pig
	freopen("1439D.in","r",stdin);
	freopen("1439D.out","w",stdout);
#endif
	cin>>m>>n>>mod;
	init(m<<1);
	f.resize(n+1);g.resize(n+1);
	f[0]=1;
	fr(i,1,n){
		fr(j,0,i-1)add(f[i],1ll*f[j]*f[i-1-j]%mod*C(i-1,j)%mod);
		f[i]=1ll*f[i]*(i+1)%mod;
	}
	fr(i,1,n){
		fr(j,0,i-1)add(g[i],(2ll*f[j]*g[i-1-j]%mod*C(i-1,j)%mod*(i+1)%mod+1ll*C(i-1,j)*(S(j)+S(i-1-j))%mod*f[j]%mod*f[i-1-j]%mod)%mod);
	}
	//cout<<g[n]<<'\n';
	//fr(i,0,n)printf("%d ",g[i]);printf("\n");
	//fr(i,0,n)printf("%d ",f[i]);printf("\n");
	f[0]=0;
	fr(i,0,n)g[i]=1ll*g[i]*inv[i]%mod;
	fr(i,0,n)f[i]=1ll*f[i]*inv[i]%mod;
	int ans=0;
	fr(i,1,m-n+1){
	//printf("g:=");fr(j,0,n)printf("%d ",g[j]);printf("\n");
		//printf("%lld %d\n",1ll*g[n]*jc[n]%mod,G(i+1,m-n-i+1));
		add(ans,1ll*g[n]*G(i+1,m-n-i+1)%mod*jc[n]%mod*i%mod);
		g=g*f;g.resize(n+1);
	}
	cout<<ans;
	return 0;
}


#include <iostream>
using namespace std;

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

	string s;
	while(n >= 2)
	{
		s += (n % 2) + '0';
		n /= 2;
	}
	s += n + '0';

	int y = 1 << ((int)s.size() - 1);

	reverse(s.begin(), s.end());
	for(int i = 0; i < s.size(); i ++)
	{
		if(s[i] == '1')
			cout<< y << " ";
		y /= 2;
	}

	cout<< endl;
}


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
long long n,i=1,j=1,v<long long>;
main()
{
cin>>n;
while (n!=0)
{
 v.push_back(n%2);
 n=n/2;
 i++;
}
for (j=i; j>0; j--)
{
 if (v[j]==1)
 cout<<j<<" ";
}

cout<<endl;
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair<int, int>
#define vi vector<int>
#define pb emplace_back
#define sz(x) (int)x.size()
#define all(v) v.begin(), v.end()
#define x first
#define y second
#define rep(i, j, k) for(i=j; i<k; i++)
#define sep(i, j, k) for(i=j; i>k; i--)
const int N = 5e3+5, inf = 998244353;
int n, k, i, j;
int in[N], f[N];
inline int expo(int n, int k, int p = inf) {int r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n % p; n = n * n % p;} return r;}
inline int inv(int a, int p = inf) {return expo(a, p - 2, p);}
inline int cc(int a, int b){ if(a<b || b<0) return 0; return f[a]*in[b]%inf*in[a-b]%inf; }
void fac(){ int i; f[0] = 1; rep(i, 1, N) f[i] = f[i-1]*i%inf; in[N-1] = inv(f[N-1]); sep(i, N-1, 0) in[i-1] = i*in[i]%inf; }

int util(int num, int rem, int mx){
    if(num*mx<rem) return 0;
    int ans = 0;
    for(int j=0; j<=num; j++){
        int distribute = rem - (mx+1)*j;
        int ways = cc(num, j)*cc(num+distribute-1, num-1)%inf;
        if(j&1) ans -= ways;
        else ans += ways;
    }
    return ans%inf;
}

signed main()
{
    ios_base::sync_with_stdio(false); cin.tie(0);
    int i, j, a, b, ans = 0;
    fac();
    cin>>n>>s>>r;
    rep(i, r, s+1)
        rep(j, 1, s/i+1)
            ans += util(n-j, s-j*i, i-1)*cc(n-1, j-1)%inf*in[j]%inf;
    ans = ans%inf+inf;
    cout<<ans%inf;
}


#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <iterator>
#include <functional>
#include <complex>
#include <queue>
#include <stack>
#include <cmath>
#include <cassert>
#include <tuple>
using namespace std;
typedef long long LL;
typedef complex<double> CMP;

static const LL INF = 0x3fffffffffffffffLL;

template<typename T>
vector<T> MATMUL(const vector< vector<T> >& a, const vector<T>& v)
{
	int N = a.size();
	vector<T> u(N, INF);
	for(int i=0; i<N; ++i)
	for(int j=0; j<N; ++j)
		u[i] = min(u[i], a[i][j]+v[j]);
	return u;
}

template<typename T>
vector< vector<T> > MATMUL(const vector< vector<T> >& a, const vector< vector<T> >& b)
{
	int N = a.size();
	vector< vector<T> > c(N, vector<T>(N, INF));
	for(int i=0; i<N; ++i)
	for(int j=0; j<N; ++j)
	for(int k=0; k<N; ++k)
		c[i][j] = min(c[i][j], a[i][k]+b[k][j]);
	return c;
}

template<typename T>
vector<T> MATPOWMUL(vector< vector<T> > a, LL e, vector<T> v)
{
	for(; e; e>>=1, a=MATMUL(a,a))
		if(e&1)
			v = MATMUL(a, v);
	return v;
}

int solve(const vector<int>& a, const vector<int>& b, int n, int m)
{
	vector<vector<LL>> blk(n+1, vector<LL>(n+1, INF));

	for(int pat=0; pat<(1<<n); ++pat)
	{
		int cur=0, bot=0, cost=0;
		for(int i=0; i<n; ++i)
			if(pat & (1<<i))
				cur++, cost+=a[i];
			else
				bot=min(bot, --cur), cost+=b[i];
		blk[0-bot][cur-bot] = min(blk[0-bot][cur-bot], cost);
	}

	vector<vector<LL>> M(2*n, vector<int>(2*n, INF));
	for(int s=0; s<2*n; ++s)
		for(int bs=0; bs<=n; ++bs)
		for(int be=0; be<=n; ++be) {
			int e = s-bs+be;
			if(bs<=s && 0<=e && e<2*n)
				M[e][s] = min(M[e][s], blk[bs][be]);
		}

	vector<LL> V(2*n, INF);
	V[0] = 0;

	V = MATPOWMUL(M, m, V);
	return (int)V[0];
}

int main()
{
	for(int n,m; cin>>n>>m; )
	{
		vector<int> a(n), b(n);
		for(int& ai: a) cin>>ai;
		for(int& bi: b) cin>>bi;
		cout << solve(a, b, n, m) << endl;
	}
}


#include <iostream>
#include <map>
#include <vector>

using map_type = std::map<int, int64_t>;
using vector_type = std::vector<int>;

int count(const vector_type& arr, size_t start, size_t end) {
    int res = 0;
    for (int i = start; i <= end; ++i) {
        if (arr[i] == 0)
            res += 1;
        else
            res -= 1;
    }
    return res;
}

int solution(const vector_type& arr) {
    vector_type prefix_arr;
    prefix_arr.reserve(arr.size() + 1);
    int s = 0;
    int max = 0;
    prefix_arr.push_back(s);
    for (auto a : arr) {
        s += 1 - a;
        max += a;
        prefix_arr.push_back(s);
    }

//    int max = arr.size() - prefix_arr.back();

    int val = max;
    for (int i = 0; i < arr.size(); ++i) {
//        if (arr[i] == 0) {
            for (int j = i; j < arr.size(); ++j) {
//                if (arr[j] == 1)
//                    continue;

//                int v = max + 2 * (prefix_arr[j + 1] - prefix_arr[i]) - (j - i + 1);
                int v = max + count(arr, i, j);
                if (v > val) {
                    val = v;
                }
            }
//        }
    }
    return val;
}

int main()
{
    int n;
    std::cin >> n;
    vector_type arr;
    for (int i = 0; i < n; ++i) {
        int val;
        scanf("%d", &val);
        arr.push_back(val);
    }

    std::cout << solution(arr);

    return 0;
}


/*
ID: duongthan4
LANG: C++
TASK: test
*/
#include <iostream>
#include <vector>
#include <stack>
#include <set>
#include <map>
#include <queue>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <algorithm>
#include <bitset>
#define FOR(i,n) for (int i=0;i<n;i++)
#define FORF(i,a,n) for (int i=a;i<=n;i++)
#define FORR(i,n) for (int i=n-1;i>=0;i--)
#define RI(a) scanf("%d", &a);
#define RS(a) scanf("%s", &a);
#define RC(a) scanf("%c", &a);
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define piii pair<pair<int,int>,int>
#define INFY 1000000000
#define MAXN 100000
using namespace std;
typedef long long LL;

short f[MAXN];
vector <int> a[MAXN];
//vector <int> b[MAXN];

short r1[MAXN];
short r2[MAXN];

void com1(int k){
    if(f[k]==1) r1[k]=1;
    FOR(i, a[k].size()){
        if(r1[a[k][i]]<0) {
            r1[a[k][i]]=1;
            com1(a[k][i]);
        }
    }
}

int com2(int k){
    if(r2[k]>=0) return r2[k];
    FOR(i, a[k].size()){
        if(com2(a[k][i])==1 && f[a[k][i]]!=1) {
            r2[k]=1;
            return 1;
        }
    }
    r2[k]=0;
    return 0;
}

int main(){
    int n, m, u, v;
    RI(n);RI(m);
    FOR(i, n){
        RI(f[i]);
        r1[i] = r2[i] = -1;
        if(f[i]==2) r2[i]=1;
    }
    FOR(i, m){
        RI(u);RI(v);
        u--;v--;
        a[u].pb(v);
        //b[v].pb(u);
    }
    if(n>1000) return;
    FOR(i, n){
        com1(i);
        com2(i);
    }
    //FOR(i, n) cout<<r1[i]<<" "<<r2[i]<<endl;
    FOR(i, n){
        if(r1[i]==1 && r2[i]==1) printf("1\n");
        else printf("0\n");
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int N=1e5+5;

vector<int>a,b;
int arr[45],tmp[45];
int k,n,m;
void go(int i=0,int sum=0)
{
    if(i==k)
    {
        a.push_back(sum);
        return;
    }
    go(i+1,sum);
    go(i+1,(sum+tmp[i])%m);
}
int solve(int sum)
{
    int s=0,e=a.size()-1,mid;
    while(s<e)
    {
        mid=(s+e+1)/2;
        if(sum+a[mid]<mid) s=mid;
        else e=mid-1;
    }
    return max((sum+a[s])%m,(sum+a[a.size()-1])%m);
}
int main()
{
    cin>>n>>m;
    for(int i=0;i<n;i++) cin>>arr[i];
    int mid=(n/2);
    for(int i=0;i<=mid;i++) tmp[i]=arr[i];
    k=mid+1;
    go();
    b=a;
    a.clear();
    for(int i=mid+1;i<n;i++) tmp[i]=arr[i];
    k=n;
    go();
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    int ans=0;
    for(int i=0;i<b.size();i++)
    {
        ans=max(ans,solve(b[i]));
    }
    cout<<ans<<endl;
    return 0;
}


#include<iostream>
#include<cmath>
using namespace std;
int main ()
{
    int n,a,b; cin>>n;
    int lest;
    for(a=0;a<n;++a)
    {
        if(n%a==0)
        {
            b=n/a;
            if(a<=b){lest=a;}
            else break;
        }
    }
    cout<<lest<<" "<<n/lest;
}


#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define sz(a) a.size()
#define re return
#define all(a) a.begin(),a.end()
#define int long long
using namespace std;
const int dx[4]={-1,1,0,0};
const int dy[4]={0,0,-1,1};
int a[1000005];
int c;
void make(int x,int y,int d){
	for (int i=0;i<(1<<d);i++){
		int rlt=0;
		for (int j=0;j<d;j++){
			if (i&(1<<j))
				rlt=rlt*10+x;
			else
				rlt=rlt*10+y;
		}
		a[c++]=rlt;
	}
}
signed main()
{
	int n;
	cin>>n;
	for (int i=0;i<10;i++)
		for (int j=0;j<10;j++)
			for (int k=0;pow(10,k)<=n;k++)
				make(i,j,k);
	sort(a,a+c);
	c=unique(a,a+c)-a;
	int ans=lower_bound(a,a+c,n+1)-a;
	for (int i=0;i<c;i++)  cout<<a[i]<<'	';cout<<'\n';
	if (n!=1000000000)  ans--;
	cout<<ans;
	while (1);
	re 0;
}
//undoubtedly lucky numbers


#include<stdio.h>
#include<cstdlib>
#include<string>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<vector>
#include<math.h>
#include<iomanip>
#include<map>
using namespace std;
const long long int big= 1000000009;
#define ciofast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define pb push_back
#define sortv(v) sort(v.begin(),v.end())
#define ci1(a) cin >> a
#define ci2(a,b) cin >> a >> b
#define ci3(a,b,c) cin >> a >> b >> c
#define ci4(a,b,c,d) cin >> a >> b >> c >> d
#define c1(a) cout << a
#define c2(a,b) cout << a << " " << b
#define c3(a,b,c) cout << a <<" "<< b << " " << c
#define sp(x) setprecision(x)
#define ll long long
#define lli long long int
#define mp make_pair
typedef vector<string> vs;
typedef vector<long long int> vl;
typedef vector<pair<lli,lli> > vp;
#define r0 return 0
#define r1 return 1
#define f(i,p,n) for(i=p;i<n;i++)
#define mem(arr,x) memset(arr,x,sizeof(arr))
int main()
	{
	ciofast;
	lli n;
	ci1(n);
	vl v;
	for(int i=1;i<=99;i++)
	{
		v.pb(i);
		if(i == n)
		{
			c1(v.size());
			r0;
		}
	}
	for(int i=3;i<=9;i++)
	{
		lli copy = v.size()-1;
		for(int j=copy;j>=0;j--)
		{
			lli digits = 0;
			int x = log10(v[j]);
			digits=x+1;
			if(digits == i-1 && digits >= 2)
			{
				lli fi=0,se=0;
				lli a = pow(10,digits-1);
				lli b = pow(10,digits-2);
				fi=v[j]/a;
				se=v[j]/b;
				se=(se)%(10);
				if(fi == se)
				{
					for(int k=0;k<=9;k++)
					{
						v.pb((10*v[j])+k);
					}
				}
				else
				{
					v.pb((10*v[j])+fi);
					v.pb((10*v[j])+se);
				}
			}
			else
			{
				break;
			}
		}
	}
	v.pb(pow(10,9));
	lli count = 0;
	for(int i=0;i<v.size();i++)
	{
		if(n >= v[i])
		{
			count++;
		}
	}
	c2(count,endl);
	return 0;
	}


#include <iostream>
#include <cstdio>
#include <cstring>
#define Order(p) (p.first)
#define Pos(p) (p.second.first)
#define Value(p) (p.second.second)
#define mp make_pair
using namespace std;

typedef pair<int, pair<int, int> > pii;
const int MAX = 1000000 + 2;
bool vis[MAX];
int ans[MAX];
int top = 0;

class Treap
{
	private:
	struct node {
		pii val;
		int key;
		int size;
		node *child[2];

		int rnd() {
			static int KEY = 12345678;
			return KEY += KEY << 2 | 1;
		}

		node(pii _val, node *c) {
			val = _val;
			key = rnd();
			child[0] = child[1] = c;
			size = 1;
		}

		void rz() {
			size = child[0]->size + child[1]->size + 1;
		}
	};

	node *root, *Null;
	void rotate(node *&t, bool d);
	void _insert(node *&t, pii x);
	void _del(node *&t, pii x);
	pii _kth(node *&t, int x);

	public:
	Treap();
	void insert(pii x);
	void del(pii x);
	pii kth(int x);
	int size();
	pii Min();
} T;

void Treap::rotate(node *&t, bool d)
{
	node *p = t->child[d];
	t->child[d] = p->child[!d];
	p->child[!d] = t;
	t->rz();
	p->rz();
	t = p;
}

void Treap::_insert(node *&t, pii x)
{
	if (t == Null) {
		t = new node(x, Null);
	}
	else {
		bool d = x > t->val;
		_insert(t->child[d], x);
		if (t->child[d]->key < t->key) {
			rotate(t, d);
		}
		else {
			t->rz();
		}
	}
}

void Treap::_del(node *&t, pii x)
{
	if (t != Null) {
		if (t->val == x) {
			bool d = t->child[0]->key > t->child[1]->key;
			if (t->child[d] == Null) {
				delete t;
				t = Null;
				return;
			}
			rotate(t, d);
			_del(t->child[!d], x);
		}
		else {
			bool d = x > t->val;
			_del(t->child[d], x);
		}
		t->rz();
	}
}

pii Treap::_kth(node *&t, int x)
{
	int r = t->child[0]->size;
	if (x == r) {
		return t->val;
	}
	else if (x < r) {
		return _kth(t->child[0], x);
	}
	else {
		return _kth(t->child[1], x - r - 1);
	}
}

Treap::Treap()
{
	Null = new node(pii(0, mp(0, 0)), 0);
	Null->size = 0;
	Null->key = INT_MAX;
	Null->child[0] = Null->child[1] = Null;
	root = Null;
}

void Treap::insert(pii x)
{
	_insert(root, x);
}

void Treap::del(pii x)
{
	_del(root, x);
}

pii Treap::kth(int x)
{
	return _kth(root, x);
}

int Treap::size()
{
	return root->size;
}

pii Treap::Min()
{
	node *p = root;
	while (p->child[0] != Null) {
		p = p->child[0];
	}
	return p->val;
}

void run()
{
	memset(vis, 0, sizeof(vis));
	while (T.size()) {
		pii k = T.Min();
		ans[Pos(k)] = Value(k);
		if (~Value(k)) {
			vis[Value(k)] = true;
		}
		T.del(k);
	}
}

void print(int i)
{
	static int p = 1;
	if (~ans[i]) {
		printf("%d", ans[i]);
	}
	else {
		while (vis[p]) {
			p++;
		}
		printf("%d", p++);
	}
}

int main(void)
{
	int n, m, i, x, y;
	cin >> n >> m;
	for (i = 1; i <= n; i++) {
		T.insert(pii(i, mp(i, -1)));
	}

	while (m--) {
		scanf("%d%d", &x, &y);
		pii k = T.kth(y - 1);
		if (Value(k) == -1) {
			if (vis[x]) {	//���ڶ��γ���ĳ��ֵʱ����ֵ��Ӧ��ԭʼλ���Ѿ�ȷ�����������Ҳ�����λ�ã�ì��
				puts("-1");
				return 0;
			}
			else {
				vis[x] = true;
			}
		}
		else if (Value(k) != x) {	//��λ����ȷ��ֵ����Ϊx
			puts("-1");
			return 0;
		}
		//top--��֤�õ���Ϊ��һ��λ�ò���
		//��ȷ��Pos(k)λ��ֵΪx
		T.insert(pii(top--, mp(Pos(k), x)));
		T.del(k);	//ɾ��ԭ���
	}

	run();
	for (i = 1; i < n; i++) {
		print(i);
		putchar(' ');
	}
	print(n);
	putchar('\n');

	return 0;
}


#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;

#define Max(a,b) (((a)>(b))?(a):(b))
const int maxn=1000005;

template<typename T>
struct Myset {
    struct Node{
        int sz, hei;
        Node *son[2];
        T val;

        Node():sz(1), hei(1) { son[0]=son[1]=NULL; }
    } *root;

    Myset():root(NULL) {}

    int height(Node *&node) {
        return (NULL==node)?0:node->hei;
    }

    int size(Node *&node) {
        return (NULL==node)?0:node->sz;
    }

    void fix(Node *&node) {
        node->hei=Max(height(node->son[0]),
                    height(node->son[1]))+1;
        node->sz=size(node->son[0])+size(node->son[1])+1;
    }

    void rotate(Node *&node, int rodir) {
        Node *pivot=node->son[1-rodir];
        node->son[1-rodir]=pivot->son[rodir];
        pivot->son[rodir]=node;
        if (node==root) root=pivot;
        node=pivot;

        fix(node->son[rodir]);
        fix(node);
    }

    void balance(Node *&node) {
        int dif=height(node->son[1])-height(node->son[0]);
        if (dif<-1 || dif>1) {
            int rodir=(dif>0)?0:1, dir=1-rodir;
            if (height(node->son[dir]->son[1-dir])
                -height(node->son[dir]->son[dir])>1)
                rotate(node->son[dir], dir);
            rotate(node, rodir);
        }
    }

    void insert(T &val, Node *&node) {
        if (NULL==node) {
            node=new Node();
            node->val=val;
            return;
        }
        if (val<=node->val) insert(val, node->son[0]);
        else insert(val, node->son[1]);
        fix(node);
        // balance(node);
    }

    void erase(T &val, Node *&node) {
        if (NULL==node) return;
        if (val==node->val) {
            if (NULL==node->son[0]) {
                if (root==node) root=node=node->son[1];
                else node=node->son[1];
                return;
            } else if (NULL==node->son[1]) {
                if (root==node) root=node=node->son[0];
                else node=node->son[0];
                return;
            } else if (NULL==node->son[0] && NULL==node->son[1]) {
                node=NULL;
                return;
            }

            Node *suc=node->son[1], *sucPa=node;
            while (NULL!=suc->son[0]) { sucPa=suc; suc=suc->son[0]; }
            swap(suc->val, node->val);
            sucPa->son[0]=NULL;
            erase(val, node->son[1]);
        }
        else if (val<node->val) erase(val, node->son[0]);
        else erase(val, node->son[1]);
        fix(node);
        // balance(node);
    }

    T valAt(int rnk, Node *&node) {
        if (rnk>size(node)) return T();
        if (rnk<=size(node->son[0])) return valAt(rnk, node->son[0]);
        else if (rnk==1+size(node->son[0])) return node->val;
        else return valAt(rnk-1-size(node->son[0]), node->son[1]);
    }

    void insert(T val) { insert(val, root); }
    void erase(T val) { erase(val, root); }
    T valAt(int rnk) { return valAt(rnk, root); }
};

Myset<int> pos;
Myset<pair<int,int> > rec;
int vis[maxn], ans[maxn];

int main() {
    // freopen("in.txt", "r", stdin);

    int n, m;
    scanf("%d%d", &n, &m);
    memset(vis, 0, sizeof(vis));
    memset(ans, -1, sizeof(ans));
    for (int i=1; i<=n; ++i) pos.insert(i);

    int sum=0;
    while (m--) {
        int x, y;
        scanf("%d%d", &x, &y);
        if (!vis[x]) {
            if (y<=sum) { printf("-1\n"); return 0; }
            ans[pos.valAt(y-sum)]=x;
            rec.insert(make_pair(m,x));
            pos.erase(pos.valAt(y-sum));
            vis[x]=1;
            ++sum;
        } else {
            if (y>rec.size(rec.root) || rec.valAt(y).second!=x) {
                printf("-1\n"); return 0;
            }
            rec.erase(rec.valAt(y));
            rec.insert(make_pair(m,x));
        }
    }
    int j=1;
    for (int i=1; i<=n; ++i) {
        if (-1==ans[i]) {
            while (vis[j]) ++j;
            vis[j]=1;
            ans[i]=j;
        }
    }
    for (int i=1; i<=n; ++i) {
        if (i-1) printf(" ");
        printf("%d", ans[i]);
    }
    printf("\n");
    return 0;
}


#include <iostream>
using namespace std;

int n, m, x, y;

void init(int *itChecked, int *itDistinc, int *posIT, int lef, int rig, int k){
    itChecked[k] = 0;
    itDistinc[k] = 0;
    if (lef == rig){
        posIT[lef] = k;
        return;
    }
    init(itChecked, itDistinc, posIT, lef, (lef + rig) >> 1, k << 1);
    init(itChecked, itDistinc, posIT, ((lef + rig) >> 1) + 1, rig, (k << 1) + 1);
}

void update(int *it, int posIT, int val){
    while (posIT){
        it[posIT] += val;
        posIT >>= 1;
    }
}

int find(int *itChecked, int lef, int rig, int k, int vt){
    if (lef == rig)
        return lef;

    int mid = (rig + lef) >> 1;
    if (mid + itChecked[(k << 1) + 1] < vt)
        return find(itChecked, mid + 1, rig, (k << 1) + 1, vt);
    else
        return find(itChecked, lef, mid, k << 1, vt - itChecked[(k << 1) + 1]);
}

int get(int *it, int lef, int rig, int u, int v, int k){
    if (u > v)
        return 0;
    if (lef == u && rig == v)
        return it[k];

    int mid = (lef + rig) >> 1;
    if (v <= mid)
        return get(it, lef, mid, u, v, k << 1);
    else
    if (u > mid)
        return get(it, mid + 1, rig, u, v, (k << 1) + 1);
    else
        return get(it, lef, mid, u, mid, k << 1) + get(it, mid + 1, rig, mid + 1, v, (k << 1) + 1);
}

int main(){
    ios_base::sync_with_stdio(false);
    cin >> n >> m;
    int *itChecked = new int[5 * n];
    int *itDistinc = new int[5 * n];
    int *posIT = new int[n + 1];
    int *posElement = new int[n + 1];
    bool *exist = new bool[n + 1];
    int *res = new int[n + 1];
    for (int i = 1; i <= n; i++){
        res[i] = 0;
        exist[i] = false;
        posElement[i] = 0;
    }

    init(itChecked, itDistinc, posIT, 1, n, 1);
    for (int i = 1; i <= m; i++){
        cin >> x >> y;
        exist[x] = true;
        update(itDistinc, posIT[i], 1);
        if (posElement[x]){
            update(itDistinc, posIT[posElement[x]], -1);
            if (get(itDistinc, 1, n, posElement[x] + 1, i - 1, 1) == y - 1){
                posElement[x] = i;
                continue;
            }
            else{
                cout << -1;
                return 0;
            }
        }

        int vt = find(itChecked, 1, n, 1, y);
        if (vt + get(itChecked, 1, n, vt + 1, n, 1) != y || res[vt]){
            cout << -1;
            return 0;
        }

        res[vt] = x;
        update(itChecked, posIT[vt], 1);
        posElement[x] = i;
    }
    int j = 1;
    for (int i = 1; i <= n; i++){
        if (res[i] == 0){
            while (exist[j++]);
            res[i] = j - 1;
        }
        cout << res[i] << " ";
    }

    delete[] itChecked;
    delete[] itDistinc;
    delete[] posIT;
    delete[] posElement;
    delete[] exist;
    delete[] res;
    return 0;
}


#pragma GCC optimize("no-stack-protector,Ofast")
#include<bits/stdc++.h>
using namespace std;

unsigned int seed=880301;
int rnd(){
    return seed=(seed*880301)^7122;
}

struct node{
    node *l,*r;
    int sz,val,pri;
    int lz(){return l?l->sz:0;}
    int rz(){return r?r->sz:0;}
    void psz(){sz=lz()+rz()+1;}
    node(int v=-1):l(0),r(0),sz(1),val(v),pri(rnd()){}
} *root,pool[1000006];

pair<int,int> op[1000006];
bitset<1000006> it;
int npt=1;

node *merge(node *a,node *b){
    if(!(a&&b))return a?:b;
    if(a->pri>b->pri){
        a->r=merge(a->r,b);
        a->psz();
        return a;
    }
    else{
        b->l=merge(a,b->l);
        b->psz();
        return b;
    }
}
void split(node *now,int sz,node *&a,node *&b){
    if(!now){a=b=0; return;}
    if(now->lz()>=sz){
        b=now;
        split(now->l,sz,a,b->l);
        b->psz();
    }
    else{
        a=now;
        split(now->r,sz-1-now->lz(),a->r,b);
        a->psz();
    }
}
void gl(node *now){
    if(!now)return;
    gl(now->l);
    if(now->val!=-1)printf("%d ",now->val);
    else{
        while(it[npt])++npt;
        printf("%d ",npt);
        it[npt]=1;
    }
    gl(now->r);
}

int inp(){
    char c; int x=0;
    while((c=getchar()) && (c<'0' || c>'9'));
    while((x=c-'0',c=getchar()) && c>='0' && c<='9');
    return x;
}

int main(){
    // ios_base::sync_with_stdio(0); cin.tie(0);
    int n=inp(),m=inp();
    for(int i=1;i<=m;++i){
        op[i].first=inp();
        op[i].second=inp();
        // it[op[i].first]=1;
    }
    for(int i=1;i<=n;++i)root=merge(root,&pool[i]);

    node *a,*b,*c,*d;
    for(int i=m;i>=1;--i){
        split(root,1,a,b);
        if(a->val==-1){
            if(it[op[i].first])exit((cout<<-1<<endl,0));
            a->val=op[i].first;
            it[op[i].first]=1;
        }
        else if(a->val!=op[i].first)exit((cout<<-1<<endl,0));
        split(b,op[i].second-1,c,d);
        root=merge(c,merge(a,d));
    }
    gl(root);
}


        /*----------------------------------*\
        ******BISMILLAHIR RAHMANIR RAHIM******
        ********************
        *****************
        /*************************************/

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

#define ll long long
#define NL printf("\n")
#define xx first
#define yy second
#define gc getchar
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define scani(x) scanf("%d",&x)
#define scanl(x) scanf("%lld",&x)//scanf("%I64d",&x)
#define scand(x) scanf("%lf",&x)
#define scans(x) scanf("%s",x)
#define mem(a,b) memset(a,b,sizeof(a))
#define FOR(i,j,k) for(i=j;i<=k;i++)
#define REV(i,j,k) for(i=j;i>=k;i--)
#define READ(f) freopen(f,"r",stdin)
#define WRITE(f) freopen(f,"w",stdout)
#define cnd tree[idx]
#define lnd tree[idx*2]
#define rnd tree[(idx*2)+1]
#define lndp (idx*2),(b),((b+e)/2)
#define rndp (idx*2+1),((b+e)/2+1),(e)
#define pi 2.0*acos(0.0)
#define MOD 1000000007
#define MAX 100005
#define PRINT_CASE(x) printf("Case %d:",cs);
int scanst(char *a){

    int i=0;
    char c = 0;
    while(c < 33)
    c = gc();
    while(c > 33){
        a[i++] = c;
        c = gc();
        }
    a[i] = 0;
    return i;
}

template <typename T> bool scan(T &n)
{
    n = 0;
    bool got = false;
    bool negative = false;
    char c = gc();
    if(c==EOF)
        return false;
    while( c < '0' | c > '9'){
        if(c == '-')
        negative = true;
        c = gc();
    }
    while(c >= '0' && c <= '9')
    {
        got = true;
        n = n*10 + c-48;c = gc();
    }
    if(negative) n = ~(n-1);
        return got;
}
template <typename T> inline T GCD (T a,T b ) {a = abs(a);b = abs(b);while ( b ) { a = a % b; swap ( a, b ); } return a;}
template <typename T> inline T LCM(T x,T y){T tp = GCD(x,y);if( (x / tp) * 1. * y > 9e18) return 9e18;return (x / tp) * y;}
template <typename T> inline T BigMod(T A,T B,T M){T ret = 1;while(B){if(B & 1) ret = (ret * A) % M;A = (A * A) % M;B = B >> 1;}return ret;}
template <typename T> inline T InvMod (T A,T M){return BigMod(A,M-2,M);}
int gcdr ( int a, int b )
{
  if ( a==0 ) return b;
  return gcdr ( b%a, a );
}
/*
ll poW(ll x, ll n)
{
    if(n==0)
        return 1;
    else if(n%2==0)
        return poW(x*x,n/2);
    else
        return x*poW(x*x,((n-1)/2));
}
*/
/*
int gcdr ( int a, int b )
{
  if ( a==0 ) return b;
  return gcdr ( b%a, a );
}

const int maxx=1000000;
int status[(maxx>>5)+2];

bool check(int N,int pos)
{
    return (bool)(N & (1<<pos));
}
int Set(int N, int pos)
{
    return N=(N|(1<<pos));
}
vector<int>P_list;
void sieve()
{
    int i,j,sqrtN;
    sqrtN=int(sqrt(maxx))+1;
    P_list.push_back(2);
    for(int i=3;i<=maxx;i+=2)
    {
        if(check(status[i>>5],i&31)==0)
        {
            P_list.push_back(i);

            if(i<=sqrtN)
            for(j=i*i;j<=maxx;j+=(i<<1))
            {
                status[j>>5]=Set(status[j>>5],j & 31);
            }
        }
    }
}
*/
void FastIO()
{
    ios_base::sync_with_stdio(false);cin.tie(0);
    cout.precision(20);
}
struct s{
    int a,index;
};
bool operator< ( s A, s B)
{
    return A.a>B.a;
}
int main()
{
    FastIO();
    int a,b,c,i,j;
    s arr[5];
    while(cin>>arr[0].a>>arr[1].a>>arr[2].a)
    {
        arr[0].index=0;
        arr[1].index=1;
        arr[2].index=2;
        sort(arr,arr+3);
        ///cout<<arr[0].index<<endl;
        int ans[5][5]={0};

            while(arr[0].a)
            {
                int ok=0;
                if(arr[1].a && arr[0].a)
                {
                    arr[0].a--;
                    arr[1].a--;
                    ans[arr[0].index][arr[1].index]++;
                    ans[arr[1].index][arr[0].index]++;
                    ok=1;
                }

                if(arr[2].a && arr[0].a)
                {
                    arr[0].a--;
                    arr[2].a--;
                    ans[arr[0].index][arr[2].index]++;
                    ans[arr[2].index][arr[0].index]++;
                    ok=1;
                }
                if(!ok)
                    break;
            }
            while(arr[2].a)
            {
                    if(arr[2].a && arr[1].a){
                    arr[1].a--;
                    arr[2].a--;
                    ans[arr[1].index][arr[2].index]++;
                    ans[arr[2].index][arr[1].index]++;
                    }
            }
        ///cout<<arr[0].a<<arr[1].a<<arr[2].a<<endl;
        if(arr[1].a==0 && arr[2].a==0 && arr[0].a==0)
        {
            cout<<ans[0][1]<<" "<<ans[1][2]<<" "<<ans[0][2]<<endl;
        }
        else
        {
            cout<<"Impossible"<<endl;
        }
    }

}


#include<bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5 ;
const double eps = 1e-9 ;
const int MAX_N = 1e6 + 5 ;
const long long M = (long long)1e9+7 ;
#define     ll      long long
#define     ull     unsigned long long
int Int() {
    int x;
    scanf("%d",&x);
    return x;
}
ll Long() {
    ll x;
    scanf("%lld",&x);
    return x;
}
void Char(char* ch) {
    scanf("%s",ch);
}
template<typename t>inline t abs(t a) { if(a>=0) return a; return -a;}
template<typename t>inline t gcd(t a , t b) {return !b ? a : gcd(b , a % b);}
template<typename t>inline t lcm(t a , t b) {return a * ( b /gcd(a , b));}
template<typename T>inline T modpow(T b, T p, T Mod) {
    T res  = 1;
    while(p) {
        if(p&1) {
            res *= b ;
            res %= Mod ;
        }
        b *= b;
        b %= Mod;
        p >>= 1;
    }
    return res ;
}

template<typename T> inline T ModInv(T b, T Mod) {return modpow(b, Mod - 2, Mod );}

template<typename T> inline T pwr(T b, T p) {
    T res  = 1;
    while(p) {
        if(p&1) {
            res *= b ;
        }
        b *= b;
        p >>= 1;
    }
    return res ;
}
int e1 , e2 , d1 ;
template < typename T >inline void extgcd(T a , T b){
    if(!b) {e1 = 1 , e2 = 0 , d1 = a ; return ;}
    extgcd(b , a % b) ;
    T x1 = e2 ;
    T y1 = e1 - (a / b) * e2 ;
    e1 = x1 ;
    e2 = y1 ;
}

/*primes in range 1 - n
1 - 100(1e2) -> 25 pimes
1 - 1000(1e3) -> 168 primes
1 - 10000(1e4) -> 1229 primes
1 - 100000(1e5) -> 9592 primes
1 - 1000000(1e6) -> 78498 primes
1 - 10000000(1e7) -> 664579 primes
large primes ->
104729 1299709 15485863 179424673 2147483647 32416190071 112272535095293 48112959837082048697
*/
/*
std::vector<int> primes;
bitset < MAX_N > bs;
ll sieve_size = MAX_N ;

void sieve(ll n){
    bs.set() ;
    bs[0] = bs[1] = 1 ;
    for(ll i = 2 ; i <= n ; i++)if(bs[i]){
        for(ll j = i * i ; j <= n ; j += i) bs[j] = 0 ;
            primes.push_back((int)i);
    }
}

bool isprime(ll n){
    if(n <= sieve_size)return bs[n] ;
    for(int i = 0 ; i <= (int)primes.size() ; i++){
        if(n % primes[i] == 0)return false ;
    }
    return true ;
}

int numDiffPf[MAX_N] ;

void DiffPF(){
    for(int i = 2 ; i < MAX_N ; i++){
        if(numDiffPf[i] == 0){
            for(int j = i ; j < MAX_N ; j += i)numDiffPf[j]++;
        }
    }
}

int Phi[MAX_N] ;

void EulerPHI(){
    for(int i = 1 ; i < MAX_N ; i++)Phi[i] = i ;
        for(int i = 2 ; i < MAX_N ; i++)
            if(Phi[i] == i)
                for(int j = i ; j < MAX_N ; j += i)
                    Phi[j] = (Phi[j]/i) * (i - 1) ;
}

int F(int x){
    return 0 ;
}
pair < int , int > floydCycle(int x0){
    int tor = F(x0) , hare = F(F(x0)) ;
    while(tor != hare){tor = F(tor) , hare = F(F(hare));}
    int mu = 0 ; hare = x0 ;
    while(tor != hare){tor = F(tor) , hare = F(hare); mu++ ;}
    int lambda = 1 ; hare = F(tor) ;
    while(tor != hare){hare = F(hare) ; lambda++;}
    return {mu , lambda} ;
}
*/
template <typename T>inline vector< T > Unique(vector< T > v) {
    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()),v.end());
    return v;
}
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
///error///
#define error(args...) {vector<string>_v=split(#args,',');err(_v.begin(),args);cout<<endl;}
vector<string> split(const string &s,char c) {
    vector<string>v;
    stringstream ss(s);
    string x;
    while(getline(ss,x,c))
        v.emplace_back(x);
    return move(v);
}

void err(vector<string>::iterator it) {}
template<typename T,typename... Args>
void err(vector<string>::iterator it,T a,Args...args) {
    cout<<it->substr((*it)[0]==' ',it->length())<< " = " << a << " ";
    err(++it,args...);
}
///This DEBUGGER-tool need c++11///
#define     Int         Int()
#define     Long        Long()
#define     pii         pair<int,int>
#define     ff          first
#define     ss          second
#define     pb          push_back
#define     eb          emplace_back
#define     all(x)      x.begin(),x.end()
#define     mem(a)      memset(a,0,sizeof a)
#define     memn(a)     memset(a,-1,sizeof a)

int trafic[10005] ;

int main() {
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int t = 1 , tc = 0 ;
    while(t--) {
        double l , d , v ;
        int g , r ;
        double res = 0.0 ;
        cin >> l >> d >> v >> g >> r ;
        int i = g , limit = r ;
        while(i <= 10000){
            while(limit--){
                trafic[i]++;
                i++;
            }
            i--;
            i += (g + r) , limit = r ;
        }
        double time = d / v ;
        int f = floor(time) ;
        if(trafic[f]){
            while(trafic[f] > 0)f--;
            f++;
            time += 1.0 * (r - abs(time - f)) ;
        }
        l = l - d ;
        time += (l / v) ;
        printf("%.10f",time);
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3f
#define sp ' '
#define nl '\n'
void sc(){}template<class T,class...A>void sc(T&t,A&...a){cin>>t,sc(a...);}
void pr(){}template<class T,class...A>void pr(T t,A...a){cout<<t,pr(a...);}
#define ms(x, y) memset(x, y, sizeof(x))
#define sz(x) (int)(x.size())
#define af(x) x.begin(), x.end()
#define mp make_pair
#define pb push_back
#define f first
#define s second
const int mod = 1e9 + 7, base = 131;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
int n, ans;
string s;
queue<string> q;
int main(){
	cin.sync_with_stdio(0); cin.tie(0); cout.tie(0);
	sc(n, s);
	q.push(s);
	while(sz(q)){
		string p = q.front(); q.pop();
		ans = max(ans, n - sz(p));
		if (sz(p) == 1) continue;
		for (int i = sz(p) - 1; i; i--){
			if (p[i] - 1 == p[i - 1]){
				q.push(p.substr(0, i) + p.substr(i + 1, sz(p) - i));
				break;
			}
		}
		for (int i = 0; i < sz(p) - 1; i++){
			if (p[i] - 1 == p[i + 1]){
				q.push(p.substr(0, i) + p.substr(i + 1, sz(p) - i));
				break;
			}
		}
	}
	pr(ans);
	return 0;
}


#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
#include<queue>
#define mm(a) memset(a,0,sizeof(a))
#define sync std::ios::sync_with_stdio(false);std::cin.tie(0)
using namespace std;
typedef long long ll;
string s;
struct node{
    string s;
    int step;
}t;
queue<node>que;
int main(void)
{
    sync;
    int len,res=0;
    cin>>len>>s;
    t.step=1;
    for(int i=0;i<len;++i)
    {
        if(i==0&&s[i]-s[i+1]==1)
        {
            t.s=s;
            t.s.erase(i,1);
            que.push(t);
        }
        else if(i==len-1&&s[i]-s[i-1]==1)
        {
            t.s=s;
            t.s.erase(i,1);
            que.push(t);
        }
        else if((s[i]-s[i-1]==1||s[i]-s[i+1]==1)&&i>0&&i<len-1)
        {
            t.s=s;
            t.s.erase(i,1);
            que.push(t);
        }
    }
    while(!que.empty())
    {
        node nxt;
        t=que.front();
        que.pop();
        nxt.step=t.step+1;
        res=max(res,t.step);
        int ln=t.s.size();
        for(int i=0;i<ln;++i)
        {
            if(ln==1)
                break;
            if(i==0&&t.s[i]-t.s[i+1]==1)
            {
                nxt.s=t.s;
                nxt.s.erase(i,1);
                que.push(nxt);
            }
            else if(i==len-1&&t.s[i]-t.s[i-1]==1)
            {
                nxt.s=t.s;
                nxt.s.erase(i,1);
                que.push(nxt);
            }
            else if((t.s[i]-t.s[i-1]==1||t.s[i]-t.s[i+1]==1)&&i>0&&i<len-1)
            {
                nxt.s=t.s;
                nxt.s.erase(i,1);
                que.push(nxt);
            }
        }
    }
    cout<<res<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define pb push_back
#define mp make_pair
 #define mod 1000000007
 const int N=100005;
 const int inf=1e18;
int pow(int a,int b){
    int res=1;
    while(b>0){
        if(b&1){
        	res=res*a;
		}
        a=a*a;
        b>>=1;
    }
    return res;
}
signed main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

	int x;
	cin>>x;
	if(x<0){
		x=(x+3600000000000000000)%360;
		if(x>180){
			x=360-x;
		}else{
			x=(-1)*x;
		}
	}else{
		x=x%360;
		if(x>180){
			x=360-x;
		}else{
			x=(-1)*x;
		}
	}
		int m=abs(x);
	cout<<x<<" "<<m<<" ";

	int out=0;
	for(int y=1;y<=3;y++){
		if(min(abs(x+90*y),abs(360-x-90*y))<m){
			m=min(abs(x+90*y),abs(360-x-90*y));
			out=y;
		//	cout<<m<<" "<<out<<"\n";
		}
	}
	cout<<m

	cout<<out;

return 0;
}


#include<bits/stdc++.h>
using namespace std;
int dp[20100][20100];
typedef pair<int,int> ii;
vector<ii> bug;
int main()
{
    int n,m,c0,d0,a,b,c1,d1,j,k,i=0;
    cin>>n>>m>>c0>>d0;

    if(c0!=0)
        i=n/c0;
    for(int j=0;j<i;j++)

        bug.push_back(make_pair(c0,d0));
    for(i=0;i<m;i++)
    {
        cin>>a>>b>>c1>>d1;
        j=0;
        if(b)
            j=a/b;
        for( k=0;k<j;k++)
            bug.push_back(make_pair(c1,d1));
    }
    sort(bug.begin(),bug.end());
    k=bug.size();
    memset(dp,0,sizeof dp);
for(i=0;i<=n+1;i++)
for(j=1;j<=k+1;j++)
{
    if((i-bug[j-1].first)>=0)

    {dp[j][i]=max(dp[j-1][i-bug[j-1].first]+bug[j-1].second,dp[j][i]);
    dp[j][i]=max(dp[j][i],dp[j-1][i]);
    }
}
    cout<<dp[k+1][n]<<endl;
    return 0;

}


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

vv I, turn = {
	{2, 1, 1, 0, 1, 2},
	{1, 2, 0, 1, 1, 2},
	{1, 1, 1, 0, 1, 2},
	{1, 1, 0, 1, 1, 2},
	{0, 0, 0, 0, 1, 1},
	{0, 0, 0, 0, 0, 1}
}; //x, y, dx, dy, t, 1

int N, sx, sy, dx, dy, t;

inline int add(int a, int b){
	return (a + b >= N ? a + b - N : a + b);
}

vv operator*(vv a, vv b){
	vv r;
	r.resize(a.size());
	for(int i = 0; i < a.size(); i++){
		r[i].resize(b[0].size());
		for(int j = 0; j < b[0].size(); j++){
			for(int k = 0; k < a[0].size(); k++){
				r[i][j] = add(r[i][j], a[i][k] * b[k][j] % N);
			}
		}
	}
	return r;
}

signed main(){
	cin >> N >> sx >> sy >> dx >> dy >> t;
	while(dx < 0) sx += N;
	while(dy < 0) sy += N;
	dx %= N;
	dy %= N;
	I.resize(6);
	for(int i = 0; i < 6; i++){ I[i].resize(6); I[i][i] = 1; }
	for(int i = 0; i < 64; i++){
		if(((t) >> i) & 1){
			I = I * turn;
		}
		turn = turn * turn;
	}
	vv st = {
		{sx - 1},
		{sy - 1},
		{dx},
		{dy},
		{0},
		{1}
	};
	st = I * st;
	cout << st[0][0] + 1 << " " << st[1][0] + 1 << endl;
}


#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <iomanip>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

const double EPS = 1e-9;
const int INF = 0x7f7f7f7f;
const double PI=acos(-1.0);

#define    READ(f) 	         freopen(f, "r", stdin)
#define    WRITE(f)   	     freopen(f, "w", stdout)
#define    MP(x, y) 	     make_pair(x, y)
#define    PB(x)             push_back(x)
#define    rep(i,n)          for(int i = 1 ; i<=(n) ; i++)
#define    repI(i,n)         for(int i = 0 ; i<(n) ; i++)
#define    FOR(i,L,R) 	     for (int i = (int)(L); i <= (int)(R); i++)
#define    ROF(i,L,R) 	     for (int i = (int)(L); i >= (int)(R); i--)
#define    FOREACH(i,t)      for (typeof(t.begin()) i=t.begin(); i!=t.end(); i++)
#define    ALL(p) 	         p.begin(),p.end()
#define    ALLR(p) 	         p.rbegin(),p.rend()
#define    SET(p) 	         memset(p, -1, sizeof(p))
#define    CLR(p)            memset(p, 0, sizeof(p))
#define    MEM(p, v)         memset(p, v, sizeof(p))
#define    getI(a) 	         scanf("%d", &a)
#define    getII(a,b) 	     scanf("%d%d", &a, &b)
#define    getIII(a,b,c)     scanf("%d%d%d", &a, &b, &c)
#define    getL(a)           scanf("%lld",&a)
#define    getLL(a,b)        scanf("%lld%lld",&a,&b)
#define    getLLL(a,b,c)     scanf("%lld%lld%lld",&a,&b,&c)
#define    getC(n)           scanf("%c",&n)
#define    getF(n)           scanf("%lf",&n)
#define    getS(n)           scanf("%s",n)
#define    bitCheck(N,in)    ((bool)(N&(1<<(in))))
#define    bitOff(N,in)      (N&(~(1<<(in))))
#define    bitOn(N,in)       (N|(1<<(in)))
#define    bitFlip(a,k)      (a^(1<<(k)))
#define    bitCount(a)        __builtin_popcount(a)
#define    bitCountLL(a)      __builtin_popcountll(a)
#define    bitLeftMost(a)     (63-__builtin_clzll((a)))
#define    bitRightMost(a)    (__builtin_ctzll(a))
#define    iseq(a,b)          (fabs(a-b)<EPS)
#define    UNIQUE(V)          (V).erase(unique((V).begin(),(V).end()),(V).end())
#define    vi 	              vector < int >
#define    vii 	              vector < vector < int > >
#define    pii 	              pair< int, int >
#define    ff 	              first
#define    ss 	              second
#define    ll	              long long
#define    ull 	              unsigned long long
#define    POPCOUNT           __builtin_popcount
#define    POPCOUNTLL         __builtin_popcountll
#define    RIGHTMOST          __builtin_ctzll
#define    LEFTMOST(x)        (63-__builtin_clzll((x)))
#define    FMT(...)           (sprintf(CRTBUFF, __VA_ARGS__)?CRTBUFF:0)
char CRTBUFF[30000];

template< class T > inline T gcd(T a, T b) { return (b) == 0 ? (a) : gcd((b), ((a) % (b))); }
template< class T > inline T lcm(T a, T b) { return ((a) / gcd((a), (b)) * (b)); }
template <typename T> string NumberToString ( T Number ) { ostringstream ss; ss << Number; return ss.str(); }

#define dipta00
#ifdef dipta007
     #define debug(args...) {cerr<<"Debug: "; dbg,args; cerr<<endl;}
     #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
        template <typename Arg1>
        void __f(const char* name, Arg1&& arg1){
            cerr << name << " : " << arg1 << std::endl;
        }
        template <typename Arg1, typename... Args>
        void __f(const char* names, Arg1&& arg1, Args&&... args){
            const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
        }
#else
    #define debug(args...)  /// Just strip off all debug tokens
    #define trace(...) ///yeeeee
#endif

struct debugger{
    template<typename T> debugger& operator , (const T& v){
        cerr<<v<<" ";
        return *this;
    }
}dbg;
///****************** template ends here ****************

// g++ -g -O2 -std=gnu++11 A.cpp
// ./a.out

int main() {
    #ifdef dipta007
        //READ("in.txt");
       //WRITE("out.txt");
    #endif // dipta007
    ios_base::sync_with_stdio(0);cin.tie(0);

    int n;
    while(cin >> n)
    {
        vi v;
        FOR(i,0,n-1)
        {
            int x;
            getI(x);
            v.PB(x);
        }

        int mf = 1;
        while(v.size() != 0)
        {
            vi tmp;
            int flg = 1;
            FOR(i,0,(int)v.size()-2)
            {
                if(abs(v[i] - v[i+1]) >= 2) flg = 0;
            }

            if(!flg)
            {
                debug(v.size())
                mf = 0;
                break;
            }
            int maxy = 0, in = -1;
            FOR(i,0,(int)v.size()-1)
            {
                if(v[i] > maxy)
                {
                    maxy = v[i];
                    in = i;
                }
            }

            FOR(i,0,(int)v.size()-1)
            {
                if(i == in) continue;
                tmp.PB(v[i]);
            }

            v.clear();
            v = tmp;
        }

        if(mf) cout << FMT("YES\n");
        else cout << FMT("NO\n");
//        int max = 0;
    }

    return 0;
}


#include <bits/stdc++.h>
#define ill int long long
using namespace std;
ill n=10,i,a[15];
string s;
int main()
{
    cin>>n;
    for (i=1;i<=n;i++)
        cin>>a[i];
    while (n)
    {
        ill mx=0,j=0;
        for (i=2;i<=n;i++)
        {
            if (abs(a[i]-a[i-1])>1){cout<<"NO";return 0;}
        }
        for (i=1;i<=n;i++)
        {
            if (a[i]>mx)mx=a[i],j=i;
        }
        for (i=j;i<n;j++)
            a[i]=a[i+1];
        a[n]=mx;
        n--;

    }
    cout<<"YES";return 0;
}


#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <ctype.h>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string.h>
#include <map>

#pragma comment(linker,"/stack:64000000")

using namespace std;

int a[100500];
int res[100500];
bool vis[100500];
vector<vector<int> > l;

bool f(int v)
{
	vis[v]=true;
	bool flag=false;
	for (int i=0;i<l[v].size();i++)
	{
		if (!vis[l[v][i]])
		{
			if (a[l[v][i]]==0)
				if (f(l[v][i])) flag=true;
			if (a[l[v][i]]==2)
			{
				flag=true;
				res[l[v][i]]=true;
				f(l[v][i]);
			}
		}
		else
			flag||=res[l[v][i]];
	}
	res[v]=flag||res[v];
	return res[v];
}

int main()
{
	int n,m;
	cin >> n >> m;
	for (int i=1;i<=n;i++)
		scanf("%d",a+i);
	l.resize(n+1);
	int first,second;
	for (int i=0;i<m;i++)
	{
		scanf("%d %d",&first,&second);
		l[first].push_back(second);
	}
	memset(vis,false,sizeof(vis));
	memset(res,0,sizeof(res));
	for (int i=1;i<=n;i++)
		if (a[i]==1) f(i);
	for (int i=1;i<=n;i++)
		if (res[i]) printf("1\n");
		else printf("0\n");
	return 0;
}