#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<vector>
#include<queue>
#include<bitset>
#include<string>
#include<stack>
#include<set>
#include<unordered_set>
#include<map>
#include<unordered_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 y0 y12
#define y1 y22
#define INF 9876543219876543
#define PI 3.141592653589793238462643383279502884
#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()
#define SYNC ios_base::sync_with_stdio(false);cin.tie(0)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef double db;
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<int, int, int, int> iiii;
typedef tuple<ll, ll, ll> LLL;
typedef vector<iii> Viii;
typedef vector<LLL> VLLL;
typedef complex<double> base;
const 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,1,1,-1,-1 }, dy[] = { 1,0,-1,0,1,-1,1,-1 };

int d[30]={0,1,2,1,4,3,2,1,5,6,2,1,8,7,5,9,8,7,3,4,7,4,2,1,10,9,3,6,11,12};
bool chk[35000];
int main() {
	ll n;
	scanf("%lld",&n);
	ll t=(ll)sqrt(n);
	ll cnt=n-t+1;
	int ans=0;
	for(ll i=2;i<=t;i++)
	{
		if(chk[i])continue;
		int c=0;
		ll now=i;
		while(now<=n)
		{
			if(now<=t)chk[now]=1;
			c++;
			if(now>t)cnt--;
			now*=i;
		}
		ans^=d[c];
	}
	if(cnt&1)ans^=1;
	puts(ans?"Vasya":"Petya");
}


// weizards and demonstration
#include<iostream>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<map>
#include<vector>
#define ak long long int

using namespace std;

int main()
{
    ak n,x,y;
    cin>>n>>x>>y;
    ak r=(y*n)%100;

    ak ypeople = (y*n)/100;

    if(r>0)
        ypeople++;

    ak clones=ypeople-x;
    if(clones<0)
        cout<<"0"<<endl;
    else
    cout<<clones<<endl;

}


#include <iostream>
using namespace std;

int main() {
	int a, b;

	cin >> a >> b;
	for (int i = 1; i < 10; i++) {
		if (i*a % 10 == b|| i*a % 10 == 0) {
			cout << i << endl;

			return 0;
		}
	}

}


#include <iostream>
using namespace std;
int main(){
	char arr[50];
	int x,counter=0;
	cin>>x;
	for(int i=0;i<x;i++)cin>>arr[i];
	for(int i=0;i<x-1;i++){
		if(arr[i]==arr[i+1])counter++;
	}
	cout<<counter;
	return 0;

}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    long long n , c = 999999;
    cin >> n;
    vector<long long>arr(n),tmp;
    for (int x = 0; x < n; cin >> arr[x++]);
    for (int x = 1; x < n-1; x++)
    {
        for (int y = 0; y < n-1; y++)
        {
            if (y == x)
                continue;
            if (y+1 == x)
                tmp.push_back(abs(arr[y]- arr[y+2]));
            else
                tmp.push_back(abs(arr[y]-arr[y+1]));
        }
        sort(tmp.begin() , tmp.end());
        if (tmp[tmp.size()-1] < c)
            c = tmp[tmp.size()-1];
        tmp.clear();
    }
    cout << c;
    return 0;
}


#include <stdio.h>
#include <stdlib.h>

int main(void)
{
    signed long long int a, b;
    long long int s;
    scanf("%lld", &a);
    scanf("%lld", &b);
    scanf("%lli", &s);
    if (abs(a)+abs(b)>s)
    {
        printf("No");
    }
    else
    {
        if (abs((a+b)%2)==(s%2))
        {
            printf("Yes");
        }
        else
        {
            printf("No");
        }
    }
    return 0;
}


#include <iostream>
using namespace std;
int main(){
	string b;
	cin>>b;
	int s=b.size();
	for(int i=0;i<s;i=i+2)
	 for(int t=0;t<s;t=t+2)
	  if(b[i]<b[t])swap(b[i],b[t]);
	cout<<b;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;
#define int long long
const int maxN = 300*1000 + 5;
const int maxM = 1000*100 + 5;
const int inf = 10000*1000*1000LL;
vector<int> a[maxN];
int mark[maxN];
int check[maxN];
int tmp[maxN];
main()
{
    ios::sync_with_stdio(0); cin.tie(0);
    int n, m; cin >> n >> m;
    for(int i = 0; i < m; i ++)
    {
	  int d, k; cin >> d >> k; d --; k --;
	  a[d].push_back(k); a[k].push_back(d);
    }
    queue<int> q;
    for(int i = 0; i < n; i ++)
    {
	  check[i] = a[i].size();
	  if(check[i] > 1) { q.push(i); tmp[i] = 1; }
    }
    while(q.size())
    {
	  int v = q.front(); q.pop();
	  tmp[v] = 0;
	  if(check[v] <= 1) continue;
	  for(int i = 0; i < a[v].size(); i ++)
	  {
		int u = a[v][i];
		if(mark[u] == mark[v])
		{
		    check[v] --;
		    check[u] --;
		}
		else
		{
		    check[v] ++;
		    check[u] ++;
		    if(!tmp[u] && check[u] > 1) tmp[u] = 1, q.push(u);
		}
	  }
	  mark[v] = 1 - mark[v];
    }
    for(int i = 0; i < n; i ++)
	  cout << mark[i];
    cout << endl;
    return 0;
}


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

using namespace std;

ll nextPlayer(ll a, ll b)
{
    // a wins, b gets replaced
    vector<ll> p;
    p.push_back(1);
    p.push_back(2);
    p.push_back(3);

    ll res;

    for(auto x : p)
    {
        if(x != a && x != b)
        {
            res = x;
            break;
        }
    }

    return res;
}

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

    vector<ll> v;

    while(n--)
    {
        ll x;
        cin >> x;
        v.push_back(x);
    }

    ll flag = 0;
    ll p1 = 1, p2 = 2;
    ll res = 0;

    for(auto x : v)
    {
        if(flag == 0)
        {
            if(x == 1)
            {
                p2 = 3;
                flag = 1;
            }
            else
            {
                if(x == 2)
                {
                    p1 = 3;
                    flag = 1;
                }
                else
                {
                    res = 1;
                    break;
                }
            }
        }
        else
        {
            if(x != p1 && x != p2)
            {
                res = 1;
                break;
            }
            else
            {
                if(x == p1)
                {
                    p2 = nextPlayer(p1, p2);
                }
                else
                {
                    p1 = nextPlayer(p2, p1);
                }
            }
        }
    }

    if(res == 0)
    {
        cout << "YES" << endl;
    }
    else
    {
        cout << "NO" << endl;
    }

}


#include <bits/stdc++.h>

using namespace std;
typedef long long int ll;

int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n,ft=0,ans=999999;
    cin >> n;
    int a[n];
    for(int i=0 ; i<n ; i++)
        cin >> a[i];
    int f=0;
    for(int i=1 ;i<n; i++)
    {
        if(a[i]==a[i-1])
            continue;
        else
        {
            f=1;
            break;
        }
    }
    if(f==0)
    {
        cout << 0;
        return 0;
    }
    if(n==1)
    {
        cout << 0;
        return 0;
    }
    sort(a,a+n);
    for(int i=0 ; i<=a[n-1] ; i++)
    {
        vector<int> p;
        for(int j=0 ; j<n ;j++)
        {
            if(i==a[j])
                 continue;
            else
                p.push_back(abs(i-a[j]));
        }
        int flag=0;
        for(int j=1 ; j<p.size() ; j++)
        {
            if(p[j] == p[j-1])
                continue;
            else
            {
                flag=1;
                break;
            }
        }
        if(flag==0)
            ans = min(ans,p[0]);
    }
    if(ans==999999)
        {
            cout << -1;
            return 0;
        }
  cout <<ans;
    return 0;
}


#include <stdio.h>
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <sstream>

#define pb push_back
#define mp make_pair
#define PI 3.14159265358979
#define forn(i, n) for(int i = 0; i < n; ++i)
#define ALL(x) x.begin(), x.end()

typedef long long ll;
using namespace std;
typedef pair<int,int> pii;
const int INF = 2147483647;
const ll LLINF = 9223372036854775807LL;

int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
	ll n,m,k;
	cin >> n >> m >> k;
	ll ans = 0;
	if(n-1 == k && m-1 == k)
		ans = 4;
		else
		if((n < k && m < k) || k == 1 || (n%k == 0 && m%k ==0))
			ans = n*m;
			else
				{
					ll a = (n-1)/k+1;
					ll b = (m-1)/k+1;
					ans = (a*b*(m-(k*(b-1)))*(n-(k*(a-1))));
				}
	cout << ans;
}


#include<cstdlib>
#include<iostream>
#include<iomanip>
#include<stdio.h>
#include<string>
#include<string.h>

#include<vector>
#include<list>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<utility>
#include<algorithm>

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

double f1(const int &x1, const int &y1, const int &x2, const int &y2)
{
    return (double)(y1-y2)/(double)(x1-x2);
}

int main()
{
    int a,b;
    int x=0,y=0;
    double slope;
    string s;
    vector<int> pathx;
    vector<int> pathy;
    vector<double> dis;

    cin>>a>>b;
    cin>>s;

    if((a==0)&&(b==0))
    {
        cout<<"Yes";
        return 0;
    }

    int siz=s.size();
    for(int i=0;i<siz;i++)
    {
        if(s[i]=='U')
            y++;
        else if(s[i]=='D')
            y--;
        else if(s[i]=='R')
            x++;
        else if(s[i]=='L')
            x--;

        if((x==a)&&(y==b))
        {
            cout<<"Yes";
            return 0;
        }

        pathx.push_back(x);
        pathy.push_back(y);
    }

    slope=f1(x,y,0,0);
    for(int i=0;i<siz;i++)
    {
        if(slope==f1(a,b,pathx[i],pathy[i]))
        {
            int m;
            if((abs(a-pathx[i]))>(abs(b-pathy[i])))
                m=(abs((a-pathx[i])/x));
            else m=(abs((b-pathy[i])/y));
            pathx[i]+=m*x;
            pathy[i]+=m*y;
            if((pathx[i]==a)&&(pathy[i]==b))
            {
                cout<<"Yes";
                return 0;
            }
            if((x>0)&&(y>0))
            {
                while((a>pathx[i])||(b>pathy[i]))
                {
                    pathx[i]+=x;
                    pathy[i]+=y;
                    if((pathx[i]==a)&&(pathy[i]==b))
                    {
                        cout<<"Yes";
                        return 0;
                    }
                }
            }
            else if((x<0)&&(y<0))
            {
                while((a<pathx[i])||(b<pathy[i]))
                {
                    pathx[i]+=x;
                    pathy[i]+=y;
                    if((pathx[i]==a)&&(pathy[i]==b))
                    {
                        cout<<"Yes";
                        return 0;
                    }
                }
            }
            else if(x>0)
            {
                while((a>pathx[i])||(b<pathy[i]))
                {
                    pathx[i]+=x;
                    pathy[i]+=y;
                    if((pathx[i]==a)&&(pathy[i]==b))
                    {
                        cout<<"Yes";
                        return 0;
                    }
                }
            }
            else if(y>0)
            {
                while((a<pathx[i])||(b>pathy[i]))
                {
                    pathx[i]+=x;
                    pathy[i]+=y;
                    if((pathx[i]==a)&&(pathy[i]==b))
                    {
                        cout<<"Yes";
                        return 0;
                    }
                }
            }
        }
    }

    cout<<"No";
    return 0;
}


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

 int main() {
  int cnt=0,cpt=0;
  string s;
  cin>>s;
  for(int i=0;i<s.length();i++){
    if(s[i]=='7'){
      cnt++;
    }
    else if(s[i]=='4')
      cpt++;
  }

  //cout<<cpt<<" "<<cnt<<"\n";

  if(cpt>=cnt){
    if(cnt==cpt && cnt!=0 && cpt!=0)
      cout<<"4\n";
    else if(cpt>cnt)
      cout<<"4\n";
    else
      cout<<"-1\n";
  }
  else if(cnt>cpt)
    cout<<"7\n";

  return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef double db;
typedef string str;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<ld> vd;
typedef vector<str> vs;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define rsz resize
#define ins insert

#define mp make_pair
#define pb push_back
#define eb emplace_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound

const int MOD = 1e9+7; // 998244353; // = (119<<23)+1
const int MX = 2e5+5;
const ll INF = 1e18;
const ld PI = 4*atan((ld)1);

template<class T> bool ckmin(T& a, const T& b)
{
    return a > b ? a = b, 1 : 0;
}
template<class T> bool ckmax(T& a, const T& b)
{
    return a < b ? a = b, 1 : 0;
}
long long a[505][505];
int main()
{
    long long n,m,i,j,k,x,y,z;
    cin>>n;
    string s;
    cin>>s;
    x=0;
    for(i=0;i<s.size();i++){
        if(s[i]=='*'){
            x++;
        }
    }
    if(x<5){
        cout<<"no"<<endl;
        return 0;
    }
    for(i=0; i<s.size(); i++)
    {
        if(s[i]=='*')
        {
            for(j=1; j<=25; j++)
            {
                if(s[i]=='*' && s[i+j]=='*' && s[i+j+j]=='*' && s[i+j+j+j]=='*' && s[i+j+j+j+j]=='*'&& (i+j+j+j+j)<s.size())
                {

                        cout<<"yes"<<endl;
                        return 0;
                }
            }
        }
    }
    cout<<"no"<<endl;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
int main()
{
    //freopen("input.in","r",stdin);
    ll a,b,c=0;
    ll x,y,z,a1=0,b1=0;
    cin >> a>>b>>x>>y>>z;
    a-=x*2;
    a-=y;
    b-=y;
    b-=z*3;
    if (a<0) c+=a;
    if (b<0) c+=b;
    cout << abs(c);

    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <cstring>
#include <climits>
#include <set>
#include <cmath>
#include <stack>
#define ll long long
#define pb push_back
#define sz(a) (int)a.size()
using namespace std;
void solve(){
    int n, m, k;
    cin >> n >> m >> k;
    int all = n * m / 2;
    if (n & 1) {
        if (m / 2 <= k && k <= all && k % 2 == (m / 2) % 2) {
            cout << "YES\n";
        } else {
            cout << "NO\n";
        }
    } else if (m & 1) {
        if (k % 2 == 0 && 0 <= k && k <= all - n / 2) {
            cout << "YES\n";
        } else {
            cout << "NO\n";
        }
    } else {
        if (k % 2 == 0) cout << "YES\n";
        else cout << "NO\n";
    }
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t;
    cin >> t;
    while(t--) solve();
}


#include<bits/stdc++.h>
using namespace std;
char a,b;
bool chess[10][10];
int x,y,ans = 8;
int main() {
	cin>>a>>b;
	x=a-'a';
	y=b-'0';
	x++;
	for(int i=0; i<=9; i++) {
		for(int j=0; j<=9; j++) {
			if(i==0||i==9) {
				chess[i][j] = 1;
				continue;
			} else {
				if(j==0||j==9)chess[i][j]=1;
			}
		}
	}
	if(chess[x][y+1]==1)ans--;
	if(chess[x+1][y]==1)ans--;
	if(chess[x][y-1]==1)ans--;
	if(chess[x-1][y]==1)ans--;
	if(chess[x+1][y+1]==1)ans--;
	if(chess[x+1][y-1]==1)ans--;
	if(chess[x-1][y+1]==1)ans--;
	if(chess[x-1][y-1]==1)ans--;
	cout<<ans<<endl;
	return 0;
}


#include<iostream>
#include<math.h>
#include<sstream>
#define ll long long int
#define rep(n,i) for(int i=n-1;i>=0;i--)
using namespace std;
int main()
{
    stringstream ss;
    string s="><+-.,[]";
    int bin[]={1000,1001,1010,1011,1100,1101,1110,1111};
    string x;
    cin>>x;
    ll sum=0,c=1;
    rep(x.size(),i)
    {
        string str="";
        int f=s.find(x[i]);
        ss<<bin[f];ss>>str;ss.clear();
        rep(str.size(),j)
        {
            if(str[j]=='1')
            {
                sum+=c;
                sum%=1000003;
            }
            sum%=1000003;
            c*=2;
            c%=1000003;
        }
    }
    cout<<sum;
}


// In the Name of God :D
#include <iostream>
#include <set>
#include <iomanip>
#include <cstring>
#include <algorithm>
#include <string>
#include <fstream>
#include <cmath>
#include <deque>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include<cstdio>
#define rep(i, n) for (int i = 0, _n = (int)(n); i < _n; i++)
#define fer(i, x, n) for (int i = (int)(x), _n = (int)(n); i < _n; i++)
#define rof(i, n, x) for (int i = (int)(n), _x = (int)(x); i-- > _x; )
#define sz(x) (int((x).size()))
#define pb push_back
#define all(X) (X).begin(),(X).end()
#define X first
#define Y second
using namespace std;

typedef pair<int  ,int  > pii;
typedef   long long ll;
typedef long double ld;
const int MAXN = 1000*100+10;
const int MAXM = 1000+10;
const int MAXL=30;
const int INF=1000*1000*100+10;
const int base = 1000000000;
const int base_digits = 9;

int n,f,Gr,grund[MAXN],ans[MAXN];
bool isf[MAXM];

int Mex()
{
    for(int i=0;i<=MAXM;i++)
        if(!isf[i])
            return i;
}
int main()
{
    cin>>n;
    memset(ans,-1,sizeof ans);
    for(int i=1;i<=n;i++)
    {
        memset(isf,0,sizeof isf);

        for(int k=2;((2*i)-(k*k)+k)>0;k++)
        {
            if(((2*i)-(k*k)+k)%(2*k)!=0)
                continue;

            f=((2*i)-(k*k)+k)/(2*k);

            Gr=grund[f-1]^grund[f+k-1];

            if(Gr==0 && ans[i]==-1)
            {

                ans[i]=k;
            }
            isf[Gr]=true;
        }
        grund[i]=Mex()^grund[i-1];
    }

    cout<<ans[n];
    return 0;
}


#include<bits/stdc++.h>
using std::cin;
using std::cout;
const int maxn = 100100;
const int mod = 1e9 + 7;
typedef long long ll;
int n, m;
struct T {
	int to, nxt;
} way[maxn << 1];
int h[maxn], num;
inline void link(int x, int y) {
	way[++num] = {y, h[x]}, h[x] = num;
	way[++num] = {x, h[y]}, h[y] = num;
}
int x[maxn], y[maxn];
int val[maxn];
std::map<int, int> map;
int idx;
inline void test(int x) {
	if(1 <= x && x <= n && !map.count(x)) map[x] = ++ idx;
}
inline void upt(int x) {
	for(;x && !map.count(x);x >>= 1) {
		test(x), test(x + x), test(x + x + 1);
	}
	test(x + x), test(x + x + 1);
}
inline int chk(int x, int n) {
	for(;n > x;) n >>= 1;
	return n == x;
}
inline int insub(int x, int n) {
	if(x > n) return 0;
	if(!chk(x, n)) return insub(x + x, n) * 2 + 1;
	return insub(x + x, n) + insub(x + x + 1, n) + 1;
}
inline void dfs(int x) {
	if(x > n) return ;
	if(!map.count(x)) {
		exit(1);
	}
	if(!map.count(x << 1) && !map.count(x << 1 | 1)) {
		val[map[x]] = insub(x, n);
		return ;
	}
	dfs(x << 1);
	dfs(x << 1 | 1);
	if(map.count(x << 1))
		link(map[x], map[x << 1]);
	if(map.count(x << 1 | 1))
		link(map[x], map[x << 1 | 1]);
	val[map[x]] = 1;
}
int vis[maxn];
ll ans = 0;
inline void dfs0(int x, int start) {
	ans = (ans + (ll) start * val[x]) % mod;
	vis[x] = 1;
	for(int i = h[x];i;i = way[i].nxt) if(!vis[way[i].to]) {
		dfs0(way[i].to, start);
	}
	vis[x] = 0;
}
int main() {
	cin >> n >> m;
	upt(1);
	for(int i = 1;i <= m;++i) {
		cin >> x[i] >> y[i];
		upt(x[i]);
		upt(y[i]);
	}
	dfs(1);
	for(int i = 1;i <= m;++i) {
		link(map[x[i]], map[y[i]]);
	}
	for(int i = 1;i <= idx;++i) {
		dfs0(i, val[i]);
	}
	cout << ans << '\n';
}


#include<stdio.h>
#include<math.h>
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<queue>
#include<stack>
#include<tuple>
#include<set>
#include<utility>
#include<map>
#include <unordered_map>
#include <bitset>
using namespace std;
typedef long long ll;
int S[10];
int main() {
	int n, m, i, x;
	cin >> n >> m;
	vector<int> a, b;
	for (i = 0; i < n; i++) {
		cin >> x;
		a.push_back(x);
	}
	for (i = 0; i < m; i++) {
		cin >> x;
		S[x] = 1;
	}
	for (i = 0; i < n; i++) {
		if (S[a[i]]) {
			b.push_back(a[i]);
		}
	}
	for (i = 0; i < b.size(); i++) cout << b[i] << " ";
}


#include <iostream>

using namespace std;

int main()
{

  int x,r;

//cout<<"enter the coordinate of elephant s friends" <<endl;
    cin >>x;

        r=x%5;
        if (r==0)
        {
            cout << x/5;
        }
        else {

           cout<< x/5+1 ;
           }

    return 0;
}


#include <iostream>
//#include <math.h>
#include <stdio.h>
//#include <string.h>
//#include <stdlib.h>
//using namespace std;

/*int partition(int *a,int l,int r)
{
	int x=a[r],i=l-1,buf;
	for(int j=l;j<r;j++)
		if(a[j]<x)
		{
			i++;
			buf=a[i],a[i]=a[j],a[j]=buf;
		}
	buf=a[i+1],a[i+1]=a[r],a[r]=buf;
	return i+1;
}

void sort(int *a,int l,int r)
{
	if(l<r)
	{
		int q=partition(a,l,r);
		sort(a,l,q-1);
		sort(a,q+1,r);
	}
}*/

int main()
{
	int n;
	unsigned long long int kol=0;
	scanf("%d",&n);
	int (*a)[101];
	a=new int[n][101];

	for(int i=0;i<n;i++)
		for(int j=0;j<n;j++)
			scanf("%d",&a[i][j]);

	for(int i=0;i<n;i++)
		kol+=a[i][i]+a[n-1-i][i]+a[i][(n-1)/2]+a[(n-1)/2][i];

	std::cout<<kol-3*a[(n-1)/2][(n-1)/2];

	delete []a;
    return 0;
}


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

int main(){
	string s;
	cin>>s;
	int fzero=0,lzero=0;
	int l=s.length();
	for(int i=0; i<s.length(); i++){
		if((s[i]-'0')==0) fzero++;
		if((s[i]-'0')!=0) break;
	}
	for(int i=l-1; i>=0; i--){
		if((s[i]-'0')==0) lzero++;
		if((s[i]-'0')!=0) break;
	}
	if(fzero > lzero) {
		cout<<"NO"<<endl;
		return 0;
	}
	lzero=l-lzero-1;
	bool flag = true;
	while(fzero <= lzero){
		if(s[fzero]==s[lzero]){
			fzero++;
			lzero--;
			//cout<<fzero<<" "<<lzero<<endl;
		}
		else {
			flag=false;
			break;
		}
	}
	if(flag) cout<<"YES"<<endl;
	else cout<<"NO"<<endl;

	return 0;
}


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

int main()
{
	//while(1)
	{
	int x,y;
	cin>>x>>y;
	if(x==0 && y==0) cout<<0<<endl;
	else
	{
		if(x>=0 && y>=0)
		{
			if(x<y) cout<<(y-1)*4+2<<endl;
			else if(x==1 && y==0) cout<<0<<endl;
			else if(y==0) cout<<(x-2)*4+5<<endl;
			else cout<<(x-1)*4+1<<endl;
		}
		else if(x<=0 && y>=0)
		{
			if(y<abs(x)) cout<<abs(x+1)*4+3<<endl;
			else cout<<abs(y-1)*4+2<<endl;
		}
		else if(x<=0 && y<=0)
		{
			if(abs(x)<abs(y)) cout<<abs(y+1)*4+4<<endl;
			else cout<<abs(x+1)*4+3<<endl;
		}
		else
		{
			if(abs(x)>abs(y)) cout<<abs(x-2)*4+4<<endl;
			else cout<<abs(y+1)*4+4<<endl;
		}
	}
}
	return 0;
}


#include<bits/stdc++.h>

using namespace std;
int main(){
	int n,m,k;
	cin>>n>>m>>k;
	int a;
	m--;
	int mi=10000000;
	for(int i=0;i<n;i++){
		cin>>a;
		if(a<=k&&a){
			mi=min(mi,abs(m-i)*10);
		}
	}
	cout<<mi;
}


#include<bits/stdc++.h>
using namespace std;
//#define flg(i) cout<<"flag\n"<<i<<i;
typedef long long int ll;
#define f(i,j,k) for(ll i=j;i<ll(k);i++)
#define wch(x) cout<<(#x)<<" "<<x<<endl
#define fio ios::sync_with_stdio(0);cin.tie(NULL)
#define pb(a) push_back(a)
#define m(a) memset(a,0,sizeof(a))
#define mp(a,b) make_pair(a,b)
#define pi pair<int,int>
#define vi vector<int>
#define sec second
#define fst first
#define ti tuple<int,int,int>
#define mt(a,b,c) make_tuple(a,b,c)
#define c2(n)   (1LL*((n)*1LL*((n)-1))/2)
#define vv(type) vector<vector<type>>
//#define clc(xj,yj,xf,yf) (abs(xj-xf)+abs(yf-yj))
const int mn=INT_MIN;
const int mx=INT_MAX;
const int mod=(1e9)+7;
const double pie  = 3.141592653589793238463;
/////////////////////////////
/////////////////////////////
/////////////////////////////
const int sz=(2e5)+10;
set<ll> st;
int main()
{fio;
cout.tie(NULL);
ll n,m,k;
cin>>n>>m>>k;

ll s=1,e=n*m;
ll ans=1;
while(s<=e)
{
    ll mid=(s+e)/2;

    ll rnk=0;
    f(i,1,n+1) {
        rnk+=min((mid-1)/i,m);
        }
    if(rnk>=k) e=mid-1;
    else ans=mid,s=mid+1;
    }
cout<<ans;
}


#include<bits\stdc++.h>

using namespace std;

typedef long long INT;

typedef pair<int,int> pii;

#define NN 111111

double dp[4444][4444];

int main(){

	int i,j;

	int n,t;

	double p,pp;

	while(scanf("%d%lf%d",&n,&p,&t)==3){

		memset(dp,0,sizeof(dp));

		dp[0][0]=1;

		for(i=1;i<=t;i++){

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

				pp=(j==n)?1:(1-p);

				dp[i][j]+=dp[i-1][j]*pp;

				if(j)

					dp[i][j]+=dp[i-1][j-1]*p;

			}

		}

		double cnt=0;

		for(i=1;i<=n;i++)

			cnt+=dp[t][i]*i;

		printf("%lf\n",cnt);

	}

	return 0;

}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll ans;
int n,a,b,s;
int c[20005];
bool check(ll m){
	int sum=m/a;
	for (int i=0;i<=s;i++) c[i]=i+1;
	for (int i=1;1ll*i*b<=m&&sum<n;i++)
		for (int j=0;1ll*i*b+1ll*j*a<=m&&sum<n;j++)
			sum+=c[j],c[j]+=(j?c[j-1]:0);
	return sum>=n;
}
void calc(ll m){
	int sum=m/a;
	ans+=1ll*sum*(sum+1)/2*a;
	for (int i=0;i<=s;i++) c[i]=i+1;
	for (int i=1;1ll*i*b<=m;i++)
		for (int j=0;1ll*i*b+1ll*j*a<=m;j++){
			ans+=1ll*c[j]*(1ll*i*b+1ll*j*a);
			sum+=c[j],c[j]+=(j?c[j-1]:0);
		}
	ans-=m*(sum-n);
}
int main(){
	scanf("%d%d%d",&n,&a,&b);
	if (a>b) swap(a,b);
	n--; ans=1ll*n*(a+b);
	n--; s=sqrt(n*2)+1;
	if (!a){
		printf("%lld\n",ans);
		return 0;
	}
	ll l=0,r=1ll*n*a;
	while (l<r){
		ll mid=(l+r)/2;
		if (check(mid)) r=mid;
		else l=mid+1;
	}
	calc(l);
	printf("%lld\n",ans);
}


#include <iostream>
#include <vector>
#include <iomanip>
#include <algorithm>
#include <set>
#include <map>
#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#define FOR(x, y, z) for (int x = y; x < z; ++x)
#define FORR(x, y, z) for (int x = y; x > z; --x)
#define SORT(a) sort(a.begin(), a.end())
#define SORTR(a) sort(a.rbegin(), a.rend())
#define GET(a, n) for (int i = 0; i < n; ++i) cin >> a[i];
#define GETM(a, n, m) for (int i = 0; i < n; ++i) for (int j = 0; j < m; ++j) cin >> a[i][j];
#define PRINT(a, n) for (int i = 0; i < n; ++i) cout << a[i] << " ";
#define LL long long
#define ULL unsigned long long
#define VI vector <int>
#define VVI vector <vector<int>>
#define GETSUM(sum, n) sum = 0; for (int i = 0; i < n; ++i) { int tmp; cin >> tmp; sum += tmp; }
#define SUM(a, n, sum) sum = 0; for (int i = 0; i < n; ++i) { sum += a[i]; }
#define COUNT(a, n, t, count) count = 0; for (int i = 0; i < n; ++i) { if (a[i] == t) ++count; }

using namespace std;

int main()
{
    int a, b, c, flag = 0;
    cin >> a >> b >> c;
    if (a > b) {
        flag = 1;
        swap(a, b);
    }
    c -= b - a;
    if (0 > c || 2 * a < c || c % 2) {
        cout << "Impossible";
        return 0;
    }
    if (flag == 0)
        cout << a - c / 2 << " " << b - (a - c / 2) << " " << a - (a - c / 2);
    else
        cout << a - c / 2 << " " << a - (a - c / 2) << " " << b - (a - c / 2);
}


#include <bits/stdc++.h>

using namespace std;
int minjump(vector<char> &path, int initial, int &d, vector<int> &dp)
{
	if (initial == path.size()-1)
		return 0;
	int cost = INT_MAX;
	for (int i = 1; i <= d && i < path.size(); i++)
	{
		if (path[initial + i] == '1')
		{
			int jumpcost;
			if(dp[initial+i]==-2)continue;
			else if (dp[initial + i] != -1)
				jumpcost = 1+ dp[initial + i];
			else
			{
				jumpcost = minjump(path, initial + i, d, dp);
				if (jumpcost == -1)
					{
						dp[initial+i]=-2;
						continue;
					}
				jumpcost++;
			}
			cost = min(cost, jumpcost);
		}
	}
	if (cost == INT_MAX)
		return -1;
	return dp[initial] = cost;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, d;
	cin >> n >> d;
	vector<char> path(n);
	vector<int> dp(n, -1);
	for (int i = 0; i < n; i++)
		cin >> path[i];
	cout << minjump(path, 0, d, dp);

	return 0;
}


#include <bits/stdc++.h>

#define F first
#define S second
#define forn(i, n) for (int i = 0; i < int(n); i++)

using namespace std;

using ll = long long;
using pll = pair<ll, ll>;

int move(int s, int& d, int from, int to) {
    if (from == to)
        return 0;

    int result;
    if (d == 1) {
        if (from < to) {
            result = to - from;
        } else {
            result = s - from + s - to;
            d = -1;
        }
    } else {
        if (from < to) {
            result = from + to;
            d = 1;
        } else {
            result = from - to;
        }
    }
    return result;
}

int main() {
    ios_base::sync_with_stdio(false);
    cout << setprecision(12);
    cin.tie(nullptr);

    int s, x1, x2;
    cin >> s >> x1 >> x2;

    int t1, t2;
    cin >> t1 >> t2;

    int p, d;
    cin >> p >> d;

    int ans = abs(x2 - x1) * t2;
    int m = 0;
    m += move(s, d, p, x1);
    m += move(s, d, x1, x2);
    ans = min(ans, m * t1);
    cout << ans << endl;
}


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

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

	int n, m, n2; cin >> n >> m;
	n2 = n+1;
	while (true) {
		if (n2 % 2 != 0 && n2 % 3 != 0 && n2 % 5 != 0 && n2 % 7 != 0 || n2 == 2 || n2 == 3 || n2 == 5 || n2 == 7)
			break;
		n2++;
	}
	if (n2 == m) cout << "YES";
	else cout << "NO";
}


#include<iostream>
#include<deque>
#include<stdio.h>
#include<vector>
#include<string>
#include<algorithm>
#include<stdio.h>
#include<fstream>

using namespace std;

int main()
{
    int n;
    int sum = 0;
    cin >> n;
    int cnt1 = 0;
    int cnt2 = 0;
    int a = 0;
    for (int i = 0; i < n; i++)
    {
        cin >> a;
        if (a == 100)cnt1++;
        else cnt2++;
    }
    if (cnt1%2==0 && cnt2%2==0)cout << "YES" << endl;
    else
    if (cnt1 % 2 == 0 && cnt1>=2) cout << "YES" << endl;
    else
    cout << "NO" << endl;

return 0;
}


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

#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));
#define MOD 1000000007
#define INF LONG_LONG_MAX
#define MINF LONG_LONG_MIN

 long long  power(long long x,long long n)
 {
     long long res=1;
     while(n)
     {
         if(n&1)
         {
             res=(res*x)%MOD;
         }
         x=(x*x)%MOD;
         n>>=1;
     }
     return res;
 }

 int fact(int n)
 {
     int x=1,i;
     for(i=n;i>=2;i--)
     {
         x=x*i;
     }
     return x;
 }

 void factors(vector<pair<int,int>> &fac,int n)
 {
     int i;
     for(i=1;i<sqrt(n);i++)
     {
         if(n%i==0)
         {
              fac.pb({i,n/i});
             if((n/i)!=i)
             {
                  fac.pb({n/i,i});
             }

         }
     }
 }

int main()
{
   FAST

    int i,j,k,n,t,Minn,Maxx,ans=INT_MAX,x;
    cin>>n>>k;
    int a[n][k];
    string s;
    for(i=0;i<n;i++)
    {
        cin>>s;
        for(j=0;j<k;j++)
        {
            a[i][j]=s[j]-'0';
        }
    }
    int b[k];
    for(i=0;i<k;i++)
    {
        b[i]=i;
    }
    do{
            Maxx=INT_MIN;
            Minn=INT_MAX;
        for(i=0;i<n;i++)
        {
            x=0;
            for(j=0;j<k;j++)
            {
                x=x*10+a[i][b[j]];
            }
            Maxx=max(Maxx,x);
            Minn=min(Minn,x);
        }
        ans=min(ans,Maxx-Minn);
    }while(next_permutation(b,b+k));
    cout<<ans;
    return 0;
}


#include <iostream>

using namespace std;
int a[100];
int main()
{
    int n,j;
    cin>>n;
    for(int i=1;i<=n;i++)
    cin>>a[i];
    int ans=90;
    a[n+1]=90;
    for(int i=1;i<=n+1;i++)
    {
        if(a[i]-a[i-1]>15)
    {
        ans=a[i-1]+15;
        i=n+1;
    }
    }
    cout<<ans;
    return 0;
}


#include <bits/stdc++.h>
#define ll long long int
using namespace std;
const int N=1010;
const int MOD=(int)1e6+3;
ll n,dp[N],twoPow[2*N];

void init() {
    twoPow[0]=1;
    for(int i=1;i<=2*N;i++)
        twoPow[i]=(twoPow[i-1]*2)%MOD;
    memset(dp,-1,sizeof(dp));
}

ll cookie(ll a) {
    return (twoPow[a-1]*(twoPow[a]+1))%MOD;
}

ll solve(ll a) {
    if (a<=0)
        return 0;
    if (dp[a]!=-1)
        return dp[a];
    dp[a]=cookie(a)%MOD;
    for(int i=1;a-i>0;i++) {
        dp[a]=(dp[a]+solve(a-i)*twoPow[i-1])%MOD;
    }
    return dp[a];
}

int main() {
    init();
    cin >> n;
    cout << (twoPow[2*n]-solve(n)+MOD)%MOD << endl;
}


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

unordered_set <long long int> S;
long long int n, x, y;

void foo(long long int  v){
    if(v<=0 || v>n) return;
    v*=10;
    S.insert(v);
    foo(v+x);
    foo(v+y);
}

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

    cin>>n;

    for(int i=0; i<10; i++)
    {
        for(int j=0; j<10; j++){
            x=i;
            y=j;
            foo(x);
        }
    }
    cout<<S.size()<<"\n";

}


#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 2e5 + 5;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	ll n, a, b, c;
	cin >> n >> a >> b >> c;
	if(a <= (b - c)){
		cout << n / a;
	}else{
		if(n < b){
			cout << n / a;
		}else{
			ll ans = 0;
			ans += (n - b) / (b - c);
			n -= ans * (b - c);
			ans++;
			n -= (b - c);
			ans += n / a;
			cout << ans;
		}
	}
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double dbl;
#define sqr(int) (int * int)
#define sqr3(int) (int * int * int)
#define pi M_PI
#define nl "\n"

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    int mx = max(a,b);
	int mn = min(a,b);
	int dif = abs(a-b);
	if(dif > c){
		mn += c;
		cout << mn * 2;
		return 0;
	}
	if(c+mn >= mx){
		if((c + mn + mx) % 2 == 0){
			cout << c + mn + mx;
	        return 0;
		}
		else{
			cout << c + mn + mx-1;
			return 0;
		}
	}
	cout << 0;
}


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

int main()
{
    int sum=0,add=0;
    string x;
    cin>>x;
    for(int i=0 ; i<x.size() ; i++)
    {
        if(x[i]==x[i+1]&&add<4)
        {
            add++;
        }
    else {
            sum++;
            add=0;
         }
    }
     cout<<sum<<endl;
    return 0;
}


#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
	int a,i,ans=6;
	scanf("%d",&a);
	for(i=4;i<=a;i++) ans+=i*(i-1);
	printf("%d",ans);
	return 0;
}


// Best practice

#include<bits/stdc++.h>

#define int         long long
#define pb          push_back
#define pf          emplace_front
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()
#define pii 		pair<int,int>
#define psi 		pair<string,int>
#define vi 			vector<int>
#define vpii  		vector<pii>
#define vvi 		vector<vi>
#define sz(x)	    (int)(x).size()
#define x           first
#define y           second
#define endl        '\n'
#define tezz        ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define MOD         1000000007
#define hell        998244353
#define prec(n) 	fixed<<setprecision(n)
#define in(x) 		scanf("%d", &x)
#define echo(x)		printf("%d", x)
#define inf 		(int)(1ll<<62-1)
#define ini(a, i) 	memset(a, i, sizeof(a))
#define output(x)   cout << (x ? "YES" : "NO")<<endl;
using namespace std;

#define debug(vec) cout<<(#vec)<<" : [ "; for (auto& i: vec) cout<<i<<" "; cout<< "]" << endl
#define debugp(vec) cout<<(#vec)<<" : [ "; for (auto& i: vec) cout<<"("<<i.x<<","<<i.y<<")"<<" "; cout<< "]" << endl
#define trace(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args);cout << endl; }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << "[" << *it << ": " << a << "]\t";
    err(++it, args...);
}

// const int dx[4] = { -1, 1, 0, 0};
// const int dy[4] = {0, 0, -1, 1};
// int dX[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
// int dY[] = { -1, 0, 1, -1, 1, -1, 0, 1 };

// Code from Here -------------------------------------------------------------------------------

int dis(int a, int b, int x, int y){
	return abs(a-x)+abs(b-y);
}

signed main() {
	tezz

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int x0,y0,a,b,c,d,x,y,t;
	cin >> x0 >> y0 >> a >> b >> c >> d >> x >> y >> t;
	vector<int> arr, brr;
	arr.pb(x0);
	brr.pb(y0);
	while(brr.back()<=(inf-c)/a && arr.back()<=(inf-c)/a){
		arr.pb(arr.back()*a+c);
		brr.pb(brr.back()*b+d);
	}
	// debug(arr);
	// debug(brr);
	int n=sz(arr), ans=0;
	for(int i=0; i<n; i++){
		for(int j=i; j<n; j++){
			int _1 = dis(arr[i],brr[i],arr[j],brr[j]);
			int _2 = dis(arr[i],brr[i],x,y);
			int _3 = dis(arr[j],brr[j],x,y);
			if(_1<=t-_2 || _1<=t-_3)ans=max(ans, j-i+1);
			// trace(_1, _2, _3);
		}
	}
	cout << ans << endl;

	return 0;
}


#define cy      cout<<"YES"<<endl
#define cn      cout<<"NO"<<endl
#define ll      long long
#include <bits/stdc++.h>
using namespace std;
void solve(){
    ll a,b;
    cin >>a >>b;
    if (b==1){
        cout<<(a-1)<<endl;
        return;
    }
    cout<<(a*(b-1))<<endl;
}
int main(){
//int t;
//cin >> t;
//while (t--){
  solve();
//}
return 0;
}


#include <bits/stdc++.h>
int main()
{
    int n;
    scanf("%d",&n);
    n-=10;
    if (n<=0||n>11)
    {
        printf("0");
        return 0;
    }
    if (n==10)
    {
        printf("15");
        return 0;
    }
    printf("4");
}


//By Akanesasu
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cctype>
#include<ctime>
#include<cstdlib>
#include<string>
#include<queue>
#include<cmath>
#include<set>
#include<map>
#include<bitset>
#include<vector>
#define rep(x,a,b) for (int x=int(a);x<=(int)(b);x++)
#define drp(x,a,b) for (int x=int(a);x>=(int)(b);x--)
#define cross(x,a) for (int x=hd[a];~x;x=nx[x])
#define ll long long
#define pii pair<int,int>
#define pdd pair<double,double>
#define mk(a,b) make_pair(a,b)
#define fs first
#define sc second
#define pb push_back
#define VI vector<int>
#define VS vector<string>
using namespace std;
inline ll rd(){
	ll x=0;int ch=getchar(),f=1;
	while (!isdigit(ch)&&(ch!='-')&&(ch!=EOF)) ch=getchar();
	if (ch=='-'){f=-1;ch=getchar();}
	while (isdigit(ch)){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}
	return x*f;
}
inline void rt(ll x){
	if (x<0) putchar('-'),x=-x;
	if (x>=10) rt(x/10),putchar(x%10+'0');
		else putchar(x+'0');
}
const int maxn=55,p=1000000007,inv2=500000004;
int n;
ll f[maxn][maxn][maxn],g[maxn][maxn];
//f[i][j][k]��ʾi��1 j��2 ����ȥk���ߵķ�����
void upd(ll &x,ll y){
	x=(x+y)%p;
}
void prepare(){
	f[0][0][0]=1;
	rep(k,0,n-1) rep(j,0,n) rep(i,0,n-j){
		ll &v=f[i][j][k];
		if (j){
			if (i>1) upd(v,f[i-2][j-1][k]*(i*(i-1)/2));		//2-1 2-1
			if (i&&j>1) upd(v,f[i][j-2][k]*i*(j-1));		//2-1 2-2
			if (j>2) upd(v,f[i+2][j-3][k]*((j-1)*(j-2)/2));	//2-2 2-2
			if (i) upd(v,f[i-1][j-1][k-1]*i);				//2-1
			if (j>1) upd(v,f[i+1][j-2][k-1]*(j-1));			//2-2
			upd(v,f[i][j-1][k-2]*inv2);						//Nope
		}
		else if (i){
			if (i>1) upd(v,f[i-2][j][k]*(i-1));	//1-1
			upd(v,f[i-1][j][k-1]);				//Nope
		}
	}
	ll fac=1;
	rep(k,0,n-1){
		rep(i,0,n) rep(j,0,n-i) (f[i][j][k]*=fac)%=p;
		(fac*=k+1)%=p;
	}
}
int a[maxn];
int main(){
	n=rd();
	rep(i,1,n) a[i]=rd();
	prepare();
	g[1][a[1]]=1;
	ll v;
	rep(i,1,n-1) rep(j,1,n-i) if ((v=g[i][j])){
		int n1=0,n2=0;
		rep(k,i+1,i+j) if (a[k]==2) n1++;else n2++;
		rep(k,0,n1+2*n2) upd(g[i+j][k],v*f[n1][n2][k]);
	}
	rt(g[n][0]),putchar('\n');
}


#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> veci;
typedef vector<long long> vecll;
typedef stack<int> stki;
typedef stack<long long> stkll;
typedef queue<int> qi;
typedef queue<long long> qll;
typedef deque<int> dqi;
typedef deque<long long> dqll;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
typedef priority_queue<int> pqi;
typedef priority_queue<long long> pqll;
typedef string st;

vector <string> ar;
int solved = 0;
void moveStatues(vector <pii> &v) {
    for(int i = 0;i<v.size();i++){
        v[i].first++;
    }
}

int checkOnStatue(int i,int j,vector <pii> v){
    for(int k = 0;k<v.size();k++){
        if(i==v[k].first && j == v[k].second){
            return 1;
        }
    }
    return 0;
}

int dfs (int i ,int j,vector <pii> v,vector<veci> used) {
    if(i<0 || j < 0 || j >= 8 || i >= 8 || used[i][j]) {
        return 0;
    }
    if (checkOnStatue(i,j,v)) {
        return 0;
    }
    if(i == 0 && j == 7){
        solved = 1;
        return 1;
    }
    moveStatues(v);
    if (checkOnStatue(i,j,v)) {
        return 0;
    }
    int x = 0;
    used[i][j] = 1;

    x = max(dfs(i-1,j,v,used),x);if(solved) return 1;
     x = max(dfs(i,j+1,v,used),x);if(solved) return 1;
    x = max(dfs(i,j-1,v,used),x);if(solved) return 1;
   x = max(dfs(i+1,j,v,used),x); if(solved) return 1;
    x = max(dfs(i+1,j+1,v,used),x);if(solved) return 1;
    x = max(dfs(i+1,j-1,v,used),x);if(solved) return 1;
    x = max(dfs(i-1,j+1,v,used),x);if(solved) return 1;
    x = max(dfs(i-1,j-1,v,used),x);if(solved) return 1;
    x = max(dfs(i,j,v,used),x);if(solved) return 1;
    return x;
}
int main()
{
   ios_base::sync_with_stdio(0),cin.tie(0);
   int n,m,k,r,i,j,temp,temp1,temp2,temp3,x,x1,x2,x3;
   st str;
   vector <veci> used;
   veci asd(8);
   for(i = 0;i<8;i++){
        used.push_back(asd);
   }
    vector <pii> v;
   for ( i = 0;i<8;i++) {
    cin>>str;
    ar.push_back(str);
    for(j = 0;j<8;j++) {
            if(str[j] == 'S') {
                v.push_back(make_pair(i,j));

            }
        }
   }

x = 0;
  x = dfs(7,0,v,used);
    if (x == 1) {cout<<"WIN"<<endl; return 0;}
  x =  dfs(6,0,v,used);
     if (x == 1) {cout<<"WIN"<<endl; return 0;}
  x = dfs(6,1,v,used);
      if (x == 1) {cout<<"WIN"<<endl; return 0;}
  x = dfs(7,1,v,used);
      if (x == 1) {cout<<"WIN"<<endl; return 0;}
      else {
        cout<<"LOSE"<<endl;
      }
}


#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long int
#define sort(a) sort((a).begin(),(a).end());
#define rev(a) reverse((a).begin(),(a).end());
#define vec vector
#define str string
#define pb(a) push_back((a));
#define ld long double
#define sz(x) x.size()
#define MP make_pair
#define fi first
#define se second
using namespace std;
int gcd(int a, int b)
{
	if (b == 0) return a;
	return gcd(b, a%b);
}
ll fact(ll j)
{
	ll a = 1;
	for (ll i = 1; i <= j; i++)
		a *= i;
	return a;
}
ll sum2(ll c)
{
	ll s = 0;
	while (c != 0)
	{
		s += (c % 10)*(c % 10);
		c /= 10;
	}
	return s;
}
bool prime(ll a)
{
	if (a == 0 || a == 1) return false;
	for (int i = 2; i <= sqrt(a); i++)
		if (a%i == 0) return false;
	return true;
}
int main(){
	//freopen(".in","r",stdin);
    //freopen(".out","w",stdout);
	ull n;
	cin>>n;
	if(n<=127)cout<<"byte";
	else if(n<=32767)cout<<"short";
	else if(n<=2147483647)cout<<"int";
	else if(n<=9223372036854775807)cout<<"long";
	else cout<<"BigInteger";
	}
	//12


#include <iostream>
#include<math.h>
using namespace std;
int main()
{
	double n,m,k;
	cin >> n>>m>>k;
	cout <<ceil(k / (2 * m))<<" "<<ceil((k - (m * 2 * (ceil(k / (2 * m)) - 1))) / 2) << " ";
	if ((int)k % 2 == 0)
		cout << "R";
	else cout << "L";
	return 0;
}


#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
typedef long long ll;
using namespace std;

ll les;

ll rec(ll N){
	ll tmp = N;
	bool ok = 0;
	ll cnt = 1;
	while(tmp >= 10){
		if(tmp % 10 != 9) ok = 1;
		tmp = tmp/10;
		cnt++;
	}
	if(tmp != 9) ok = 1;
	if(cnt != les-1) return 0;
	ll ans = 0;

		for(int i=0;i<=4;i++){
			int j=9-i;
			//cout << j << " " << tmp << "\n";
			if(j > tmp) continue;
			if(j == tmp) ans = ans + (N - tmp * pow(10,cnt-1) ) + 1;
			else{
				ans = ans + pow(10,cnt-1);
			}
		}
		return ans;
}

int main(){
	ll N;
	cin >> N;
	ll tmp = N;
	bool ok = 0;
	ll cnt = 1;
	int lol = 0;
	while(tmp >= 10){
		if(tmp % 10 != 9) ok = 1;
		if(tmp % 10 == 9) lol++;
		tmp = tmp/10;
		cnt++;
	}
	les = cnt;
	if(tmp != 9) ok = 1;
	else lol++;
	ll ans = 0;
	if(tmp >= 5){
		for(int i=0;i<=4;i++){
			int j=9-i;
			//cout << j << " " << tmp << "\n";
			if(j > tmp) continue;
			if(i == 0 && lol == cnt) ans--;
			if(j == tmp) ans = ans + (N - tmp * pow(10,cnt-1) ) + 1;
			else{
				ans = ans + pow(10,cnt-1);
			}
		}
		//if(!ok) ans--;
		cout << ans  << "\n";
	}
	else{
		if(N <= 4){
			cout<< N * (N-1) / 2 << "\n";
			return 0;
		}
		else{
			for(int i=0;i<=tmp;i++){
				for(int j=i;j<=tmp;j++){
					if(i == tmp && j == tmp) {
					//	cout << ans << " " << "\n";
						ans += rec(N - tmp * pow(10,cnt-1)) ;
					}
					else if(j == tmp){
						ans = ans + (N - tmp * pow(10,cnt-1)) + 1;
					}
					else if(i == j){
						ans = ans + pow(10,cnt-1)/2;
					}
					else
					{
						ans = ans + pow(10,cnt-1) ;
					}
				//	cout << lol << " "<< cnt-1 << "\n";
					if(i == 0 && (j != tmp || lol >= (cnt-1)  )) ans--;
				//	cout << i << " " << j << " " << ans << "\n";
				}
			}
		}
		cout << ans << "\n";
	}
}


#include <bits/stdc++.h>
using namespace std;
int a,b,c,d,e,f;
int main()
{
	cin >> a >> b >> c >> d >> e >> f;
	printf("%d\n",(a + b + c) * (a + b + c) - a * a - c * c - e * e);
    return 0;
}


/**********************************************************
 *     Code written by Akikaze                            *
 *     Duy-Bach Le, #Team4T's Chief Executor              *
 *     #Team4T Tertiary Flagship - Oblivion               *
 *                                                        *
 *     Written by a random fan of momocashew and Chiho    *
 *                                                        *
 *     Arigatougozaimasu, imouto-chan.                    *
 **********************************************************/

/************** [OPTIMIZATION PROTOCOL] **************/
#pragma comment(linker, "/stack:225450978")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
/*****************************************************/

/************** [LIBRARY PROTOCOL] **************/
#include <bits/stdc++.h>
using namespace std;
/************************************************/

/************** [LEGENDS/CONSTANTS] **************/
#define endl '\n'
#define i64 long long
#define ld long double
#define rsz resize
#define pub push_back
#define mp make_pair
#define fi first
#define se second
typedef vector<i64> vi;
typedef vector<ld> vd;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef pair<i64, i64> pii;
typedef pair<i64, pii> pip;
typedef pair<pii, i64> ppi;
const long long Mod = 1000000007LL, INF = 1e9, LINF = 1e18;
const long double Pi = 3.141592653589793116, EPS = 1e-9, Gold = ((1+sqrt(5))/2);
long long keymod[] = {1000000007LL, 1000000009LL, 1000000021LL, 1000000033LL};
long long keyCount = sizeof(keymod) / sizeof(long long);
/*************************************************/

/************** [BITWISE FUNCTIONS] **************/
template<class T> int getbit(T s, int i) { return (s >> i) & 1; }
template<class T> T onbit(T s, int i) { return s | (T(1) << i); }
template<class T> T offbit(T s, int i) { return s & (~(T(1) << i)); }
template<class T> int cntbit(T s) { return __builtin_popcountll(s); }
/*************************************************/

/************** [MASTER CONTROLS - PHASE 1] **************/
auto TimeStart = chrono::steady_clock::now();
auto TimeEnd = chrono::steady_clock::now();
#define OImode 227420978
#define MultiTest 227420978

#undef OImode // Switch this off if submitting OI problems.
#undef MultiTest // Switch this off if submitting multi-test problems.

void ControlIO(int argc, char* argv[]);
void TimerStart();
void TimerStop();
void Exit();
/*********************************************************/

/************** [GLOBAL VARIABLES] **************/
i64 n, m;
/************************************************/

/************** [FUNCTIONS] **************/
i64 modPow(i64 a, i64 b, i64 M) {
	if (b == 0) return 1;
	i64 tmp = modPow(a, b/2, M);
	if (b % 2 == 0) return ((tmp * tmp) % M);
	return ((((tmp * tmp) % M) * a) % M);
}

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

void Solve() {
	i64 A = (modPow(3, n, m) + m - 1) % m;
	cout << A;
}
/*****************************************/

/************** [MAIN] **************/
int main(int argc, char* argv[]) {
	ControlIO(argc, argv);
	ios_base::sync_with_stdio(0); cin.tie(NULL);
	#ifndef MultiTest
		Input(); TimerStart();
		Solve(); TimerStop();
	#else
		int T; cin >> T; TimerStart();
		while(T--) {Input(); Solve();}
		TimerStop();
	#endif
	return 0;
}
/************************************/

/************** [MASTER CONTROLS - PHASE 2] **************/
void ControlIO(int argc, char* argv[]) {
	#ifdef Akikaze
	time_t t = time(0);
	tm* now = localtime(&t);
	cout << "Source code by #Team4T-Akikaze.\n";
	cout << "Current time: ";
	cout << (now->tm_year + 1900) << '-'
	     << (now->tm_mon + 1) << '-'
	     <<  now->tm_mday << " | "
	     <<  now->tm_hour << ":"
	     <<  now->tm_min << ":"
	     <<  now->tm_sec
	     << "\n\n";
	if (argc > 1) assert(freopen(argv[1], "r", stdin));
	if (argc > 2) assert(freopen(argv[2], "w", stdout));
	#elif OImode
	freopen("FILENAME.INP", "r", stdin);
	freopen("FILENAME.OUT", "w", stdout);
	#endif
}

void TimerStart() {
	#ifdef Akikaze
	TimeStart = chrono::steady_clock::now();
	#endif
}

void TimerStop() {
	#ifdef Akikaze
	TimeEnd = chrono::steady_clock::now();
	auto ElapsedTime = TimeEnd - TimeStart;
	cout << "\n\nTime elapsed: " << chrono::duration<double>(ElapsedTime).count() << " seconds.\n";
	#endif
}

void Exit() {
	TimerStop(); exit(0);
}
/*********************************************************/

/*********************************************************************************************************************************************************************************************************
 * ti;.                               .:,:i:         :,;;itt;.        fDDEDDEEEEEEKEEEEEKEEEEEEEEEEEEEEEEE###WKKKKKKKKKKKKKKKKKKKKWWWWWWWWWWWWWWWWWWW#WWWWWKKKKKEE      :,:.    f::::. .,ijLGDDDDDDDEEEEEEE*
 *ti;.                               .:,:i:          .:,;itt;:      GLDEEGEEEEEEEEEEEEEEEEEEDEEEEEEEEEEE#W#WEKKKKKKKKKKKKKKKKKKKKKKKWWWWWWWWWWWWWWWWWWWWWWKKKKKKG.     .::.      f:,...,ijLGDDDDDDDDEEEEEE *
 *ti;.                               .:,:i:            :,;;iti,    :fDDEEEEEEEEEEEEEEEKEEEEDEEEEEEEEEEEW##WEEEKKKKKKKKKKKKKKKKKKKKKWWWWWWWWWWWWWWWWWWWWWWWKKKKKKEG     .::.       .f,::,ijLGDDDDDDDDEEEEEE *
 *ti;.                               .:,:i:             .,,;iti;.  LDDEEEEEEEEEEKEEEEWEEEDDEEEEEEEEEEE#WWWEEEEEKKKKKKKKKKKKKKKKKKKKKKKKKWWWWWWWWWWWWWWWWWWWKKKKKEDj    .::.        .:L;;ijfGDDDDDDDDDEEEEE *
 *ti;.                               .:,:i:              .:,;;iii:LLDEEEEEEEEEEEKEEEEEEEEDEEEEEEEEEEEW#WWEEEEEEEKKKKKKKKKKKKKKKKKKKKKKKKKWWKWWWWWWWWWWWWWWKKKKKKKEL    .::.         .:;LijLGGDDDDDDDDEEEEE *
 *ti;.                               .:,:;:                :,;;ittfDEEEEEEEEEEEEEEEEKEEEGEEEEEEEEEEEKWWWEEEEEEEEEKKKKKKKKKKKKKKKKKKKKKKKKKKWWWWWWWWWWWWWWWKKKKKKKELj   .::.          :,;jffGGDDDDDDDDDEEEE *
 *ti;.                               .:,:i:                 .,;;tGGDEEEEEEEEEEEKEEEKEEEDEEEEEEEEEEEEWWWEEEEEEEEEEEEKKKKKKKKKKKKKKKKKKKKKKKKKKWWWWWWKWWWWWWKKKKKKKEEL   .::.          .:;itDGGDDDDDDDDDEEEE *
 *ti;.                               .:::;:                   :;ifDEEEEEEEEEEEEKEEEKEEEEEEEEEEEEEEEWWWEEEEEEEEEEEEEEKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKW#WWWKKKKKKKKEEf   .::.           :,itfGEDDDDDDDDDDDEE *
 *ti;.                               .:::;:                    :GGEEEEEEEEEEEKEKEEKEEEEEEEEEEEEEEEEWWEEEEEEEEEEEEEEEEEKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKW#WKKKKKKKKKEEDG  .::.           .,;jfLGKDLDDDDDDEEDD *
 *ti;.                               .:::;:                     fDEEEEEEKKKKKKKKKEKEEEEEEEEEEEEEEE#WEEEEEEEEEEEEEEEEEEKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKW#KKKKKKKKKKEEf .:::.           .,;tfLGDEDDDDDDDDEEE *
 *ti;.                                :::;:                    fDEEEEEEKKKKKKKKKKWKEEEEEEEEEEEEEEEWKEEEEEEEEEEEEEEEEEEEEKEKKKKKKKKKKKKKKKKKKKKKKKKKKKKW##KKKKKKKKKEEft :::.           .,;tfLGDDDKDDDDDDDDD *
 *ti;.                                .::;:                    fDEEEEEEKKKKKKKWKKKKKEEEEEEEEEEEEE#WEEWEEEEEDEEDEEEEEEEEEEEEKKKKKKKKKKKKKKKKKKKKKKKKKKKKW#WKKKKKKKKEEGG :,:.           .,;tfLGGDDDKDDDDDDDD *
 *ti;.                                .:.;:                   tGDEEEEKKKKKKKKKKKKKKKKKEEEEEEEEEEEWEEKWEEEEEEEDEEEEEEEEEEEEEEKEKKKKKKKKKKKKKKKKKKKKKKKKKKWWWKKKKKKKEEDf :::.           .,;tfLGGDDDDEDDDDDDD *
 *ti;.                                .::;:                   fDEEEEEKKKKKKKKKKKWKKKKKKKKEEEEEEEWWEEWEEEEEEEEEEEEEEEEEEEEEEEEEEKKKKKKKKKKKKKKKKKKKKKKKKKW##KKKKKKKEEEft.::.           .,;tfLGGDDDDDDEDDDDD *
 *ti;.                                .:.;:                  tGDEEEKKKKKKKKKKKKKKKKKKKKKKEKEEEEE#EEWWEEEEEEEEEEEEEEEEEEEEEEEEEEEEKKKKKKKKKKKKKKKKKKKKKKKKW#WKKKKKKEEEGD:::.           .,;tfLGGDDDDDDDEDDDD *
 *ti;.                                .:.,.                  LDEEEEKKKKKKKKKKWKWKKKKKKKKKKKKEEEKWEKW#EEEEEEEEEEEEEEEEKEEEEEEEEEEEEEEEKKKKKKKKKKKKKKKKKKKKW##KKKKKKEEEEf,,:.           .,;tfLGGDDDDDDDDEDDD *
 *ti;.                               ..:.,.                 LGDEEEEKKKKKKKKKKWKKKKKKKKKKKKKKKKKWEEW#WEEEEEEEEEEEEEEEKEEEEEEEEEEEEEEEEEEEKEKKKKKKKKKKKKKKKK##KKKKKEEEEEfi;,.           .,;tfLGGDDDDDDDDDKDD *
 *tt;.                                .:.,:                 jDEEEEKKKKKKKKKKWWKKKKKKKKKKKKKKKKKWKE#WWEEEEEEEEEEEEEEWEEEEEEEEEEEEEEEEEEEEEEEKKKKKKKKKKKKKKKKWWKKKKEEEEDfG;,:           .,;tfLGGDDDDDDDDDDKD *
 *tii,.                               .:.,.                tGDEEEEKKKKKKKKKKWWWKKKKKKKKKKKKKKKWKKWWWKEEEEEEEEEEEEEKEEEEEEEEEEEEEEEEEEEEEEEEEEEEEKKKKKKKKKKKW#KKKKEEEEDGGi;,.          .,;tfLGGDDDDDDDDDDDE *
 *ti;;,:.                             .:.,:                fDEEEEKKKKKKKKKKKWKKKKKKKKKKKKKKKKKWEK#WWKEEEEEEEEEEEEDEEEEEEEEEEEEEEGEEEEEEEEEEEEEEEEEEEKKKKKKKWWKKEEEEEEDDf;;;,.         .,;tfLGGDDDDDDDDDDDD *
 *tii;,,:..                           ...,.               ;LEEEEEKKKKKKWKKKKWKKKKKKKKKKKKKKKKKEKKW#WEEEEEEEEEEEEEjEEEEEEEEEKEEEEGEEEEEEEEEKEEEEEEEEEEEEEEEEE#WKEEEEEEDDf;;;;,:        .,itfLGGDDDDDDDDDDDD *
 *ti;,,,,,:.                          ...,.               LDEEEEKKKKKKKKKKKWWWKKKKKKKKKKKKKKKWKK#W#WEEEEEEEEEEEDDLEEEEEEEEEWEEEEDEEEEEEEEEKEEEEEEEEEEEEEEEEEWWEEEEEEEDDfj,,,,,:.      .,itfGGGDDDDDDDDDDDD *
 *tii,,,,::::.                        ...,:              .fDEEEEKKKKKKWKKKKWWWKKKKKKKKKKKKKKKEKKW#WWEEEEEEEEEEEKiKEEKEEEEEEWEEEEDEEEEEEEEEEEEEEEEEEEEEEEEEEEWWEEEEEEEDDLD:::,,,:.     .,ijfGGGDDDDDDDDDDDD *
 *ti;:::::::::..                      .:.,:              LDEEEEKKKKKKKWKKKKWWKKKKKKKKKKKKKKKKtKKWWWWKEEEEEEEEEDiiDEEEEEEEEWWEEEEEEDEEEEEEEEEEEEEEEEEEEEEEEEEEWKEEEEEDDDGL:. .:,,,:    .,ijLGGGDDDDDDDDDDDD *
 *tt;. .::::::::..                    ...,:             :fDEEEKKKKKKKKKKKKWW#KKKKKKKKKKKKKKKKfKKWWWWKEEEEEEEEDti,DEKEEEEEEWWEEEDEEEEEEEEEKEEEEEEEEEEEEEDEEEEE#WEEEEEGGDGf:.  .:,;,:.  .,ijLGGDDDDDDDDDDDDD *
 *tt;.   .:::::::..                   ...,:             GDEEEKKKKKKKKWKKKKWWWKKKWKKKKKKKWWWKDEKLWWWWKKEEEEEEDEi,LDEEEEEEEEWWEEEEEEEEEEEEEEEEEEEEEEEEEDEDEEEEEW#EEEEDDDDGf,.    :,,,:...,ijLGGGDDDDDDDDDDDD *
 *tt;.    .....::::..                 ...,:             fDEEEKKKKKKKKWKKKKWWWWKKKWKKKKKKKKKKfWKiWWW#KKEEEEEEEi;.EDfEEEDEEiWWEEEEEEEEEEEEDGKEEEEEEEEEEDEEEEEEEWWEEEEDDDGGLi.     .,;,:::,ijLGGGDDDDDDDDDDDD *
 *tt;.      ....:::::.                ...,.            iDEEEEKKKKKKKKWKKWKWWWWWKKWWWKKKKKKKKtWKt#WWWKKEEEEEDji..DDKDDEDEGiWKEEEEEEEEEEDDEjEEEEEEEEEEEDEEEEEEEKWKEEDDDDGGff.      .:,;,,;ijLGGGDDDDDDDDDDDD *
 *tt;.        ....::::..              .:.,:           .LDEEEKKKKKKKKKKKKWWWWKWWWWWWWWWWKKKKWtKKiDWWWKKKEEEEKi:..DEDDDDDDiiWKEEEEEEEEEEDDEijDEEEEEKEEEEEEEEEEEEWWEEGDDDGGLG.       .:,;;iijLGGGDDDDDDDDDDDD *
 *tt;.          .....:::..            ...,.           .fEEEEKKKKKKKKWKKKKWWWWWWWWWWWWWWKWKKKiKDiLWWWWKEEEEEi,..fD:DDDDDti;WEEEEEEEEEEKDDi:iDDEEEEWEEEEEEEEEEEE#WEEGDDDDGGG.         :,iitjLGGGDDDDDDDDDDDD *
 *tti.            .....:::..          ...,.           GDEEEKKKKKKKKKWKKKWWW#WWWWWWWWWWWKWKKjiEjitWWWKKWEEEDi...DDLDDDDji;;WEEEEEEEEEEEDEj.iDDEEEEWEEEEEEEEEEEEWWEEDDDDDDGf.          .,;tjfLGGDDDDDDDDDDDD *
 *tti.              ....::::..        ...,.           fEEEKKKKKKKKKKKKKKKW#WWWWWWWWWWWWWWWWtiEiiiWWWKKEWKEi....D.EDDDEi;.fWEEEEEEEEEEDDfL.;EDDEEEWEEEEEEEEEEEEWWEEEDDDDDGf.           :;ijfLGGDDDDDDDDDDDD *
 *tti.                ....::::..      ...,.          LDEEEKKKKKKKKKKKKKKWWWWWWWWWWWWWWWW####WKiiiWWWKKKEEK,...:E:DDDEii..GWEEEEEEEEDWDDiL.,KDDEEEWEEEEEEEEEEEEWWKEEDDDDDGf:           .,itfLGGDDDDDDDDDDDD *
 *tti.                 .....:::..     ...,.          fDEEEKKKKKKKKKWKKKKWWWWWWWWWWWWW########WLiiWWWKKKEEjD...G,DDDDi;...EWEEEEEEEEDKDEii..LDDEEEWEEEEEEEEEEEEWWWEEDDDDDGfi           .,;tfLGGGDDDDDDDDDDD *
 *tti.                   .....:::..   ...,.         iGEEEKKKKKKKKKKWKKKKWWWWWWWWWWWW###########KiWWWKKEEE,.D..D.DDDii:...KKEEEEEEEEEDDj:...tEDEEEWEEEEEEEEEEEEWWWEEEDDDDDLL           .,;tjLLGGDDDDDDDDDDD *
 *tti.                     ....::::......:.         LEEEKKKKKKKKKKWWKKKWWW#KWWWWWWWW#####W####W##KWWKKEEL..:D.jjDDi;,....KKEEEEEEEDfDDi...:iKDEEEWKEEEEEEEEEEEWWWEEEEDDDDLG           .,;tjLLGGDDDDDDDDDDD *
 *tti.                        ...::::::..,.        :GEEEKKKKKKKKKKKKWWWWW##WWWWWWWWW##WKWK#W#W####WWKEEK.....G.DDti,.....KKEEEEEEDWGDf.,...iKDEEEWWEEEEEEEEEEEW#WEEEEEDDDGL           .,;tjLLGGDDDDDDDDDDD *
 *tti.                         ....::::::,.        GDEEKKKKKKKKKKKKKWWWW###WWWWWWWWWW#WWWK###W#####WKEKK.....jDDL;;......KKEEEEEEEEEDi.f...;KDEEEWWEEEEEEEEEEEWWWWEEEEEDDGf           .,;tjLLGGDDDDDDDDDDD *
 *tti.                           ....:::,,.       .LEEEKKKKKWKKKKKWWWWWW###WWWWWWWWWW#WWKW#WW##W#WWWKEKD:....:DD:;......;KEEEEEEEKiDD..f...,KKEEEWWEEEEEEEEEEEWWWWEEEEEDDDf           .:;tjLLGGGDDDDDDDDDD *
 *tti.                             ...::,,,:.     GDEEKKKKKKKKKKKKWWWWWWW#WWWWWWWWWWW#KjKWWWWWWWWWWWWEK.j,..;fD.;.......fKEEEEEDKG:Di..,....DKEEEWWEEEEEEKEKKKWWWWEEEEEEDDf           .:;tjLLGGDDDDDDDDDDD *
 *jti.                              ...::,,,,:.  .fEEEKKKKKWKKKKKKWWWWWWW#WWWWWWWWWWK#KKKWWWWWWWWWWWWWK..f:.:G.,:.......EKEEEEEKK;:E:.......fKEEEWWKEKEKKKKKKKW#WWEEEEEEDDf:          .,;tfLLGGDDDDDDDDDDD *
 *tti.                               ...:,,,;;,: iDEEKKKKKWKKKKKKKWWWWWWW#WWWWWWWWWWK#WDKWWKKWWWWWWWWWE..;G:G..,........KKEEEEEKi.Gi..:.....tKEEKWWWKKKKKKKKKKW##WKEEEEEEDfi          .,;tfLLGGGDDDDDDDDDD *
 *tti.                               ....::,,;;;,LEEKKKKKKWKKKKKWWWWWWW###WWWWWWWWWWKWWDKWEEEWKKWWWWWKKj.:LG..;.........EKEEEEKG;.G...;.....;KKEKWWWKKKKKKKKKKW##WWKEEEEEDfL          .,;tfLGGGDDDDDDDDDDD *
 *jti.                                ...::::,;ijDEEKKKKKWKKKKKKWKWWWWW##WWWWWWWWWWWKK#KKGDGDWEEWKKWKKGE,.i;.:.........:EKEEEKE;.:L...j.....,KWEKWWWKKKKKKKKKK####WKKEEEEDLG          .,;tfLGGGGDDDDDDDDDD *
 *jti.                                ...:...,,;GEEKKKKKWWKKKKKWWWWWWWW###WWWWWWWWWKKKWWKiLGGEDEDEKGKKiEG..;...........jKEEEKK;:.G....,.....:KKEWWWWKKKKKKKWKK####WKKKKEEEGL          .,;tfLGGGGDDDDDDDDDD *
 *jti.                                ...:.  .:,GEEKKKKKWKKKKKWWWWWWWW####WWWWWWWWWKKKWWKii;fDLGDK: EEi:E:.............EKEEKK;;..L...........KKKWWWWKKKKKKKWKK####WKKKWKEEDf          .,;tfGGGGDDDDDDDDDDD *
 *jti.                                ...:.    ,EEKKKKKWWKKKKKWWWWWWWWW###WWWWWWWWKKKKfWWLt;i,. fi  EG..D:.............EKEKK;;..t....:.......KWKWWWWKKKKKKKWKK####WKKKWEEEDf:.        .,;tfGGGGDDDDDDDDDDD *
 *jti.                                ...:.    GEEKKKKKWKKKKKWWWWWWWWW####WWWWWWWKKKKKt;KKEfff     .;t.................KKKKi;:..GtGGfG.......KWWWWWWKKKKKKKWKK###WWWKKKKEEEf,,:       .,;tfGGGGDDDDDDDDDDD *
 *jti.                                ...:.    GEKKKKKWWKKKKKWWWWWWWWWW##WWWWWWWKKKKKKt;EiKKKK,   ...t................jEKKG;;..,.....,LGi....KWWWWWWKKKKKKWKKKW####WKKKKKEEL,,,:.     .,;tfGGGDDDDDDDDDDDD *
 *jti.                                ...:.  .GEEKKKKKWKKKKKWWWWWWWWWW###WWWWWWWKKKKKKtiE::tGG........................EEEj;;...,.........:D..DKWWWWWWKKKKK#KKW###W#WKKKKKEEfj:,,,:.   .,;tfGGGDDDDDDDDDDDD *
 *jti.                                ...:.   DEKKKKKWWKKKKKWWWWWWWWW####WWWWWWWKKKKKKiiE:::.::.......................EEi;;...j.....f......:iDKWWWWWWKKKKK#WW######WKKKKKEELG :,,,,:. .,;tfGGGDDDDDDDDDDDD *
 *jti.                                ...:.  fEEKKKKWWKKKKWWWWWWWWWWW###WWWWWWWWKKKKKK;tE::..........................DD;.;,.::......;........EWWWWWWWKKKKW#WW#####WWKKKWKKELG  .:,,,:::,;tfGGGDDDDDDDDDDDD *
 *jti.                                ...:. .DEKEKKKWWKKKKWWWWWWWWWWW###WWWWWWWWKKKKKE,iD::..........................D..,;.,;tLffi...........DWDWWWW#KKKWWWWW#####W#KKKWKEEGL    .:,;,,,;tfGGGDDDDDDDDDDDD *
 *jti.                                ...:. ;EEKKKKWWKKKKKWWWWWW#WWWW####WWWWWWKKKKKEL:iD:..........................j ..;..;;:.....i,........DKtWWWWWKKWWWWWW#####WWWKKKEKEDf     .:,;;;itfGGGDDDDDDDDDDDD *
 *jti.                                ...:. DEKKKKKWWKKKKWWWWWWW#WWWW####WWWWWWKKKKKEj:iG...............................:....................GKiWWWWWKKWW#WWW######WWKKKKKEEf       .,;iitfGGGDDDDDDDDDDDD *
 *jti.                                ...:.:EKKKKKWWKKKKKWWWWWWW#WWW#####WWWWWKWKKKKEi:if:.................................iEKEKKKKKKDj......DKiWWWWWKWK##WW#######WWKKK:KEEL        .:;itfGGGDDDDDDDDDDDD *
 *jji.                                ...:,DEEKKKWWWKWKKWWWWWWWWWWWW#####WWWWWWWKKKKEi:it..................................j.  KKKKKKKKKKKf..DKiWWWWWKWW##WW#######WWKKK,KEEf         .,;tfGGGDDDDDDDDDDDD *
 *jji.                                ..L:iDEEKKKWWKKKKKWWWWWWWWWWWW#####WWWWWKWKKKKKi.i;..................................  . KKKWWWWWWWWK..DGiWWWWWKK##WWW#####W#WWKKKjEKEL,        .:;tfGGGDDDDDDDDDDDD *
 *jji.                               .f:::EEEKKKWWWKKKKKWWWWWWWWWWWW#####WWWWWKWKKKKK;.i,.................................::  KKEKWWWWWWfWK..EiiWWWWWKWW#WW##########KKKD,KELj        .:;tfGGDDDDDDDDDDDDD *
 *jji.                             .t::::,DEEKKKWWKKKKWWWWWWWWW#WWWW#####WWWWKKWKKKEK;.i:.................................GDDEEEKKKWWWWWtWWD.E;iWWWWWW###WW#########WWKKK.EEDG        .:;tfGGGDDDDDDDDDDDD *
 *jji.                          . j..::::EKEKKKWWWKKKKWWWWWWWWW#WWW######WWWWKKWKKKEK;.t:.................................ELLEDDEEEWWWWEtWK,.KiiWWWWWW###W##########WWKKK:EEEG     .;tjfLLGDDDDDDDDDDDDDDD *
 *jji.                          i.::::::,EEEKKWWWKKKKKWWWWWWWWW#WWW#####WWWWWKWKKKKEE,.t..................................DfiEGDDDEEKKKttKWG.KiiWWWWW##WWW##########WWKKK:fEEL  ,fGGGDDDDDDDDEEEDDDDDDDDDD *
 *jji.                        .;:..:::::DEEEKKWWWKKKKKWWWWWWWWW#WWWW####WWWWWWWKKKKED,.t..................................ifjDDGGEGDKK.ttKKE.DiWWWWW###WW##########WWWKKK:.KELiLGGGGDDDDDDDDDDDDEEEDDDDDDD *
 *jji.                       i.:.::::::,KEEKKWWWKKKKKKWWWWWWWWW#WWWW####WWWWWWWKKKKEL:.j..................................GGf,;ifLLED .iiKKi:fWWWWWW##W#W##########WWWKKK:.KKLGGDDDDDDDDDDDDDDDDEDDEEDDDDD *
 *jji.                     .j:.::::::::EEEKKKWWWKKKKKKWWWWWWWW##WWW#####WWWWWWWKKKKKf:.f..................................:EEfftf .,. ;iE,..jWWWWWWW###W############WWKKK,:KKGDDDDDDDDDDDDDDDDDDDDDDDEDDDD *
 *jji.                    .:.::::::::,,EEEKKWWWKKKKKKKWWWWWWWW##WWW#####WWWWWWWKKKKKt..G....................................EEELL;   .j....tKWWWWWWW################WWWKKtfGKGEDDDDDDDDDDDDDDDDDDDDDDDEEDD *
 *jji.                   :...:::::::,,jEEKKWWWWKKKKKKWWWWWWWWW##KWW#####KWWWWWWKKKKEi..D....................................:jEEE.........;KKWWWWWWWW#WW##W##########WWKKDLGKEKDDDDDDDDDDDDDDDDDDDDDDDDDED *
 *jji.                  i:.::::::::,,,EEEKKWWWWKKKKKWWWWWWWWWW##WWW#####WWWWWWWKKKKKi..D......................................:::::......,KKKWWWWWWWWW#####W########WWWKKKGGKKEGGGGGGGGDDDDDDDDDDDDDDDDDDE *
 *jji.                 i..:::::::::,,tEEKKWWWWKKKKKWWWWWWWWWWW##WW######WWWWWWWKKKKKi..D......................................::::......:EKKKWWWWWWWWWWW##WW########W#WKKWGGKKGGGGGGGGGGGGGGGDDDDDDDDDDDDD *
 *jji.                .:::::::::::,,,EEEKKWWWWKKKKKWWWWWWWWWWW##WW#####WWWWWWWWKKKKKi..D....................................:::::::::..tELii;KWWWWWWWWWW##WW######WWWWWWKWGGGKGGGGGGGGGGGGGGGGGGGGGGGGGGDG *
 *jjt.                :.::::::::,,,,fEEKKWWWWKKKKKKWWWWWWWWWW###WW####WWWWWWW#WKKKKKi..D....................................:::::::.:.,;;;;;;,KKWWWWWWWWW#WW########WWWKKWGGGKGGGGGGGGGGGGGGGGGGGGGGGGGGGG *
 *jji.               ;.::::::::,,,,;EEEKWWWWWKKKKKWWWWWWWWWWWW##WW###WKWWWWWK#WKKKKKi..G......................................:::::::,;;;;:...KKKWWWWWWWWWKWW#######WWWWKKGLGKDGGGGGGLLGGGGGGGGGGGGGGGGGGG *
 *jjt.              f.:::::::::,,,,fEEKKWWWWWKKKKKWWWWWWWWWWW###WW##WKKWWWWWW#WKKKKK;.jt........i.............................:::::::;j;;....:E.KKKWWWWWWWKWW#####W#WWWWKKLLGWEEGGGGGLGGGGGGGGGGGGGGGGGGGG *
 *jjt.             ...:::::::,,,,,;DEEKWWWWWKKKKKWWWWWWWWWWWW####WWWKKKWWWWWWWWKKKKK;.E;.........t.............................:::::ii;;.....D...KKWWWWWWWKWW#####WWEWWWKKGGGEKKGGGGGLGGGGGGGGGGGGGLGGGGGG *
 *fji.             ;.:::::::,,,,,;LEEKKWWWWWKKKKKWWWWWWWWWWWW####KWKKKKWWWWWWWWKKKKKi.D;..........j.............................:::tt;,.....:.....KKWWWWWWKWWWW##WWWGWWWKKGGGGKEGGGGGGGGGGGGGGGGGGGLLGGGGL *
 *fji.            t::::::::,,,,,,;EEEKWWWWWKKKKKKKWWWWWWWWWWW##WKWKKKKKWWWWWWWWKKKKKi:D;............j...........................::LL;,.............KKWWWWWKWWWWWWWWWGWWWKKGGGGKGGGGGGGGGGGGGGGGGGGGLLGGGGL *
 *fjt:            .:::::::,,,,,,,DEEKWWWWWWKKKKKKKWWWWWWWWWWWWKKWKKKKKKWWWWK#WWKKKKWitE;........... ............................:G;;:...............KKKWWKKWWWWWWWWWGWWWKKGGGGWGGGGGGGGGGGGGGGGGGGGGGGGGGL *
 *fjji;:.       .f:::::::,,,,,,,;EEEKWWWWWWKKKKKKWWWWWWWWWWWKKKKKKKKKKKWWKWWWWWKKKKWGKD;........................................L;;..................DKKWKKWWWWWWWWWGWWWKKDGGGKDGGGGGGGGGGGGGGGGGGGGGGGGGG *
 *fjjtii;,:.     :::::::,,,,,,,;EEEKWWWWWWKKKKKKWWWWWWWWWWKKKKKKKKKKKKWWWWWW#WWKKKKWiEj;......................................:i,;....,...............;KKEKWWWWWWWWWGKWWKKDDGGDEGGGDGGGGGDGGGGGGGGGGGGGGGG *
 *fjtiiiii;;:.  j::::::,,,,,,,;;EEEKWWWWW#KKKKKWWWWWWWWWKKKKKKWKKKKKKKWWWWWWWWWKKKKWtEL;:....................................;;;:...,;j................:KEEWWWWWWWWWDDWWKKDDDDDKDDDDDDDDDDDDDDDGGGGGGGGGGG *
 *fjti;;iiii;;,:::::::,,,,,,,,;EEEKWWWWWWWKKKKWWWWWWWWKKKKKKKWKKKKKKKWWWWWWW#W#KKKKWEEii;...................................f;:....,;L...................EEKWWWWWWWWDDWWKKDDDDDKEDDDDDDDDDDDDDDDDDDDDDGGGG *
 *fjt,,,;;;;ii;f::::::,,,,,,,;;EEKWWWWWWWKKKKKWWWKWWKKKKKKKKKKKKKKKKKWWWWWWW#W#KKKKWKEij;:...............................:G;,.....,;f....................:tKKWWWWWWWDDWWKKDDDDDKKDDDDDDDDDDDDDDDDDDDDDDDDD *
 *jjt. ..:,;;;;,::::,,,,,,,,;;GEEWWWWWWWWKKKKWKKWKKKKKKKKKKKKKKKKKKKKWWWWWWW#W#KKKKWEDi;j;............................,Li;L;;;..,;;f........................KKKKWWWKDDWWKKDDDGDKKGGGGGGGGDGDDDDDDDDDDDDDDD *
 *fjt.    .:,,,:::::,,,,,,,;;;EEKWWWWWWWKKKKKKWKKKKKKKKKKKKKKKKKKKKKWKKKWKW##W#KKKKWEti;;G;........................tEEEL;;;;;;;;;;L..........................DKKKKKEDDWWKEDGftiLE;;;;itjLGGGGGGDDDDDDDDDDD *
 *fjt.       .j::::,,,,,,,;;;DEEWWWWWWWWKKKKWKKKKKKKKKKKKKKKKKKKKKKKWKKWWWK##W#KKKKKEii;;;L;...................iDEEEEEEKKi;j;;;;jD.....:......................,KKKKDGGEKKE:::::;E::::::::::,tLGGDDDDDDDDDD *
 *fjt.       .;:::,,,,,,,;;;;EEKWWWWWWWWKWKKKKKKKKKKKKKKKWKKKKKKKKKKWKKWWWW#WW#KKKKKKii;;;;f;.............:tDEEEEEKKKKKKKKEti;;;L...............................EEKf;:iKKE::::::E::::::::::::::ifDDDDDDDDD *
 *fjt:        :::,,,,,,,,;;;DEEWWWWWWWWWEKKKKKKKKKKKKKKKKKKKKKKKKKKWWKKWWWW####KKKKKEiii;;;;f,.........iDEEEEKKKKKKKKKKKKKKKf;iG......i..........................fK::::KKE::::::E::::::::::::::::,tGGDDDDD *
 *fjt:       t:::,,,,,,;;;;iDEKWWWWWWKEKKKKKKKKKKKKKKKKKKKKKKKKKKKKWWKKWWWW####WKKKKLiii;;;;;L,....,Li;EDEEEEKKKKKKKKKKKKKKKKiG......;:...........................:i:::KKE:::::,E,::::::::::::::::::iGDDDD *
 *jjt.       f::,,,,,,,;;;;GEEWWWWKEEKEKKKKKKKKKKKKKKKKWKKKKKKKKKKKWWKWWWWW###WWKKKKiii;;;;;;;G,;L;;iiEEEEEEEKKKKKKKKKKKKKWWKE......;t.........:....................j::KEE:,::,,D,,::::,,,,,,:::::::::tDDD *
 *fjt:.      ,::,,,,,,,;;;;EEWWKEEEEEEKKKKKKKKKKKKKKKKWKKKKKKKKKKKWWKKWWWWW#W#KKKKKKiiiiii;;;;;i;;iiiEEKEEKKWKKKKKKKWKKKKKWWWGi;...;t......,;;;;,....................:,EEE,,,,,,D,,,,,,,,,,,,,,,,::,::::tG *
 *fjt:.     ,::,,,,,,,;;;;DEKEEEEEEEEKKKKKKKKKKKKKKKKKKKKKKKKKKKKKWWWWWWWWW#W#KKKKKKiiiii;;i;;;;;iiiKKKEKKKKWWKWWWWWWKKKKWWWWW;;;:;L.....;;;;;;;;;....................,KEE,,,,,,E,,,,,,,,,,,,,,,,,,,,,,,,; *
 *fjt:.     f:,,,,,,,;;;;jEDEEEEEEEEEKKKKKKKKKKKKKKKKKKKKKKKKKKKKKWWWWWWWW#W##KKKKKKiiiiiiii;i;;iiiEKKKKKKKKWKWWWWWWWWKKKWWWWWKi;;i.....,jEEfGi;;;;;...................EED,,,,,,E,,,,,,,,,,,,,,,,,,,,,,,,, *
 *fjt:.    .f::,,,,,,;;jEEDEEEEEEEEEEKKKKKKKKKKKKKKKWKKKKKKKKKKKKKWWWKWWWWW###KKKKKLiiiiiiiiiiiiiiEEKKKKKKKKWWWWWWWWWWWWKWWWWWWGi;i;,..;jDDDKEGi;;;;;;:................EED,,,,,,D,,,,,,,,,,,,,,,,,,,,,,,,, *
 *fjt:.  .. ;::,,,,,;;EDDEEEEEEEEEEKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKWWKKW#WW####KWKKKiiiiiiiiiiiiijKKKKKKKKKKWWWWWWWWWWWWWWWWWWWWWt;i;;;;i;DDDDDDGi;;;;;;;;:.............EDf;,,,;,G;;;;;;;;;;;;;;;,,,,,,,,,, *
 *fjt:......:,,,,,,;LDDDEEEEEEEEEEEKKKKKKKKKKKKKKKKWKKKKKKKKKKKKKWWWWKWWWW####KKKKKiiiiiiiiiiijKEKKWKKKKKKKWWWWWWWWWWWWWWWWWWWWWWiLiii;i;DEEEEDDE;i;;;;;;;;;:..........EDi,;;;;;L;;;;;;;;;;;;;;;;;;,,,,,,, *
 *fjt:......:,,,,,;EDDDEEKEEEEEEEEEKKKKKKKKKKKKKKKWKKKKKKKKKKKKKKWWWWKKWWW##W#KWKKWEiiiiiijGKKKKKWWKKKKKKKKWWWWWWWWWWWWWWWWWWWWWWKi;iiiiDDEEEEEEDEi;;;;;;;;;;;;;,:.....ED;;;;;;;j;;;;;;;;;;;;;;;;;;;;;;;,, *
 *fjt:.....t,,,,,;DDDDEEEKEEEEEEEEKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKWWWKKKWWWW##WKWKKWKiiiKKKKKKKKKWWKKKKKKKKWWWWWWWWWWWWWWW#WWWWWWWWWiiiiifLEEEEEEEEDi;i;;;;;;;;;;;;.....DD;;;;;;;i;;;;;;;;;;;;;;;;;;;;;;;;; *
 *fjt:.....G,,,,,GDDDEEEEEEEEEEEEKKKKKKKKKKKKKKKKWKKKKKKKKKKKKKKKWWWKKKWWW###WKWKKWKitKKKKKKKKKWKKKKKKKKKKWWWWWWWWWWWWWW###WWWWWWWWEiiiiiiiEEEEEEEEDGiiii;;;;;;;;;.....GD;;;;;;;i;;;;;;;;;;;;;;;;;;;;;;;;; *
 *fjt:.....L,,,,;GDDDEEEEEEEEEEKEKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKWWWWWDGWWW###KKWWKWKKKKKKKKKKKKKKKKKKKKKKKWWWWWWWWWWWWW####WWWWWWWWWiiiiiiiiEEEEEEEEEEDi;i;;;;;;;;.....Lj;;;;;;i;iiiiii;;;;;;ii;;;;;;;;;;; *
 ***********************************************************************************************************************************************************************************************************/


#include<bits/stdc++.h>
#define N 1500
#define M 100000
#define reg register
#define inl inline
#define int long long
using namespace std;
const int Mod=1e9+7;
int n,m,A,B,T,P,p[M+5],sum[N+5],f[N+5][N+5],a[N+5][N+5],b[N+5][N+5],fac[M+5],inv[M+5];
inl int Pow(reg int x,reg int y)
{
	reg int res=1;
	for(;y;y>>=1,x=x*x%Mod) if(y&1) res=res*x%Mod;
	return res;
}
inl int C(reg int x,reg int y)
{
	return x>=y?fac[x]*inv[x-y]%Mod*inv[y]%Mod:0;
}
inl void Init()
{
	fac[0]=1;
	for(reg int i=1;i<=M;i++) fac[i]=fac[i-1]*i%Mod;
	inv[M]=Pow(fac[M],Mod-2);
	for(reg int i=M-1;i>=0;i--) inv[i]=inv[i+1]*(i+1)%Mod;
}
signed main()
{
	Init();
	scanf("%lld %lld",&n,&m);
	scanf("%lld %lld",&A,&B);
	scanf("%lld",&T);
	P=A*Pow(B,Mod-2)%Mod;
	for(reg int i=0;i<=T;i++) p[i]=C(T,i)*Pow(P,i)%Mod*Pow(1-P+Mod,T-i)%Mod;
	for(reg int i=1;i<=m;i++) sum[i]=(sum[i-1]+p[i-1])%Mod;
	f[0][m]=a[0][m]=1;
	for(reg int i=1;i<=n;i++)
	{
		for(reg int j=1;j<=m;j++)
		{
			f[i][j]=((a[i-1][m]-a[i-1][m-j]+Mod)*sum[j]-b[i-1][j]+Mod)%Mod*p[m-j]%Mod;
			a[i][j]=(a[i][j-1]+f[i][j])%Mod;
			b[i][j]=(b[i][j-1]+p[j-1]*a[i][j-1])%Mod;
		}
	}
	printf("%lld\n",a[n][m]);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main() {

long long int n,m,i,r=5,t,sum=0;
cin>>n>>m;

    if(m>n)
{
  for(i=1;i<=n;i++)
  {
    if(i%5==0)
    {
      r+=5;
    }
    t=(m-r+i);
    if(t>=0)
    {t=t/5+1;
    sum+=t;}
  }
}
else
{
   for(i=1;i<=m;i++)
  {
    if(i%5==0)
    {
      r+=5;
    }
    t=(n-r+i);
    if(t>=0)
    {
       t=t/5+1;
    sum+=t;
    }
  }

}

cout<<sum;
	return 0;
}


#include<bits/stdc++.h>

using namespace std;
double dp[1005][1005][2];
double explore(int w,int b,int c)
{
	if(w==0)
		return 0.0;
	if(b==0)
		return 1.0-(double)c;
	if(dp[w][b][c]>=0)
		return dp[w][b][c];
	if(c==0)
		return dp[w][b][c]=(double)w/double(b+w)+(double)b/double(b+w)*explore(w,b-1,1);
	if(b>=2)
		return dp[w][b][c]=(double)b/double(b+w)*(double)(b-1)/double(b+w-1)*explore(w,b-2,0)+(double)b/double(b+w)*(double)(w)/double(b+w-1)*explore(w-1,b-1,0);
	return dp[w][b][c]=(double)b/double(b+w)*(double)(w)/double(b+w-1)*explore(w-1,b-1,0);
}

int main()
{
	int a,b;
	cin>>a>>b;
	memset(dp,-1.0,sizeof(dp));
	cout<<fixed<<setprecision(10)<<explore(a,b,0);
}


#include <algorithm>
#include <assert.h>
#include <iostream>
#include <string.h>
#include <memory.h>
#include <stdio.h>
#include <complex>
#include <cstdlib>
#include <sstream>
#include <cstring>
#include <fstream>
#include <iomanip>
#include <vector>
#include <string>
#include <bitset>
#include <cstdio>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <deque>
typedef long long ll;
using namespace std;
int n;

const int N = 100+10;
char str[2][N];

// 00,01,10,11
//1110,1011,0111,1101
int st[]={14,11,7,13};
int getState(int x, int idx){
    return (st[x]&3) | (str[0][idx]<<1 | str[1][idx]);
}
bool can (int idx,int x, int prv){
    int cur = str[0][idx]<<1 | str[1][idx];
    int u = prv<<2 | cur;

    if(u&st[x])
        return false;
    return true;
}

int dp[N][4];
int calc(int idx,int prv){
    if(idx==n)
        return 0;
    int &ret=dp[idx][prv];
    if(ret!=-1)
        return ret;
    ret = calc(idx+1,str[0][idx]<<1 | str[1][idx]);
    for(int i=0;i<4;++i)
        if(can(idx,i,prv))
            ret = max(calc(idx+1,getState(i,idx))+1, ret);
    return ret;
}

int main(){

    memset(dp,-1,sizeof dp);
    scanf("%s",str[0]);
    scanf("%s",str[1]);

    n = strlen(str[0]);

    for(int i=0;i<n;++i)
        for(int j=0;j<2;++j)
            if(str[j][i]=='0')
                str[j][i]=0;
            else str[j][i]=1;

    int ans = calc(0,3);
    printf("%d\n",ans);
    return 0;

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll dl=2e5+10;
vector<ll>vec(dl,0), v1,v2(2e5+10,0);
void fun(ll a, ll b)
{
    ll nom=0;
    while(a>1)
    {

        {
            if(a%v1[nom]==0)
            {
                a/=v1[nom];
                v2[v1[nom]]+=b;
            }
            else
            nom++;
        }
        if(vec[a]==0)
        {
            v2[a]+=b;
            return;
        }

    }
}
int main()
{
    ll a, s, d, i, j;
    cin>>a;
    for(i=2;i<dl-10;i++)
    {
        if(vec[i]==0)
        {
            v1.push_back(i);
            for(j=i*i;j<dl;j+=i)
            {
                vec[j]=1;
            }
        }
    }
    for(i=a*2-1;i>a;i--)
    {
        fun(i,1);
    }
    for(i=1;i<a;i++)
    {
        fun(i,-1);
    }/*
    for(i=0;i<8;i++)
    {
        cout<<v2[i]<<" ";
    }*/
    ll otv=1;
    ll mo=1e9+7;
    ll asd=min(v2.size(),v1.size());
    for(i=0;i<asd;i++)
    {
        ll sum=1;
        if(v2[v1[i]]>0){
                for(j=0;j<v2[v1[i]];j++)
                {
                    sum*=v1[i];
                    sum=sum%mo;
                }
                otv=otv*sum;
        otv=otv%mo;}
    }
    cout<<(otv*2-a)%mo;

}


#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
#define fi first
#define se second
#define pb push_back
#define pbb pop_back
#define make_pair mp
#define all(x) x.begin(), x.end()
#define uniq(x) x.erase(unique(x.begin(),x.end()),x.end())
#define mem(array, value) memset(array, value, sizeof(array))
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a/__gcd(a,b))*b
#define line cout << "==========" << endl
#define mod 1000000007
#define SIZE 1000001

int rev(int n)
{
    int r = 0;
    while (n){
        r = r*10+n%10;
        n/=10;
    }
    return r;
}

int main ()
{
    int h, m;
    char ch;
    cin >> h >> ch >> m;
    if (h >= 0 && h <= 4){
        if (h*10 > m){
            cout << "0" << h << ":" << h*10 << endl;
        }
        else {
            h++;
            cout << "0" << h << ":" << h*10 << endl;
        }
    }
    else if (h == 5){
        if (h*10 > m){
            cout << "0" << h << ":" << h*10 << endl;
        }
        else {
            cout << "10:01\n";
        }
    }
    else if (h >= 6 && h <= 9){
        cout << "10:01\n";
    }
    else if (h == 10){
        if(m == 0){
            cout << "10:01\n";
        }
        else {
            h++;
            cout << h << ":" << rev(h) << endl;
        }
    }
    else if (h>=11 && h <= 14){
        if (rev(h) > m){
            cout << h << ":" << rev(h) << endl;
        }
        else {
            h++;
            cout << h << ":" << rev(h) << endl;
        }
    }
    else if (h == 15){
        if (rev(h) > m){
            cout << h << ":" << rev(h) << endl;
        }
        else {
            cout << "20:02\n";
        }
    }
    else if (h >= 16 && h <= 19){
        cout << "20:02\n";
    }
    else if (h == 20){
        if (m < 2){
            cout << "20:02\n";
        }
        else {
            h++;
            cout << h << ":" << rev(h) << endl;
        }
    }
    else if (h >= 21 && h <= 23){
        if (rev(h) > m){
            cout << h << ":" << rev(h) << endl;
        }
        else {
            h++;
            if (h == 24){
                cout << "00:00\n";
            }
            else {
                cout << h << ":" << rev(h) << endl;
            }
        }
    }
    return 0;
}


#include<bits/stdc++.h>
#include<cmath>
#define ll long long
#define fr first
#define sc second
#define mod 1000000007
#define pii pair<int,int>
#define pdd pair<double,double>
#define mp make_pair
using namespace std;

struct pt{
    double x,y,z;
    void read(){
        cin>>x>>y>>z;
    }
    double dis(pt d){
        return (x - d.x)*(x - d.x) + (y - d.y)*(y - d.y) + (z - d.z)*(z - d.z);
    }
};
int a[6];
pt eyee;
pt s;
pt c[6];

int main(){

    eyee.read();
    s.read();

    for(int i=0 ; i<6 ; i++)cin>>a[i];

    int res =0 ;

    if(eyee.y < 0)res += a[0];
    if(eyee.y > s.y)res += a[1];
    if(eyee.z < 0)res += a[2];
    if(eyee.z > s.z)res += a[3];
    if(eyee.x < 0)res += a[4];
    if(eyee.x > s.x)res += a[5];

    cout<<res;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

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

#define pb push_back
#define mp make_pair

int n, T;
int a[100];
int cnt[301];
const int INF = 1000000000;
int ans = 0;

vector<int> foo(int sz, int low, int high){
    vector<int> d;
    for(int i = 0; i <= sz; i++) d.pb(INF);
    d[0] = -INF;
    for(int i = 0; i < sz; i++){
        int t = i % n;
        if(a[t] < low || a[t] > high) continue;
        int j = int(upper_bound(d.begin(), d.end(), a[t]) - d.begin());
        if(d[j - 1] <= a[t] && a[t] <= d[j])
            d[j] = a[t];
    }
    return d;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin >> n >> T;
    for(int i = 0; i < n; i++) cin >> a[i];
    if(T <= 2 * n){
        vector<int> tmp = foo(n * T, 0, 300);
        for(int i = 1; i < tmp.size(); i++){
            if(tmp[i] == INF){
                cout << i - 1 << endl;
                exit(0);
            }
        }
        cout << n * T << endl;
        exit(0);
    }
    for(int i = 0; i < n; i++) cnt[a[i]]++;
    for(int i = 1; i <= 300; i++){
        vector<int> tmp1 = foo(n * n, 0, i);
        vector<int> tmp2 = foo(n * n, i, 300);
        int len1 = n * n, len2 = n * n;
        for(int j = 1; j < tmp1.size(); j++){
            if(tmp1[j] == INF){
                len1 = j - 1;
                break;
            }
        }
        for(int j = 1; j < tmp2.size(); j++){
            if(tmp2[j] == INF){
                len2 = j - 1;
                break;
            }
        }
        ans = max(ans, len1 + (T - 2 * n) * cnt[i] + len2);
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

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

  int n,i,j,s,ix,k,ij;
  char a[20];
  char x;

  scanf("%s %d",&a,&k);
  n=strlen(a);
  for(i=0;i<n-1;i++){
    if(k>0){
      x=a[i+1];
      ix=i+1;
      for(j=i+2;j<n;j++){
        if(j-i<=k){
          if(a[j]>x){
            x=a[j];
            ix=j;
          }
        } else j=n;
      }
      if(x>a[i])
        for(ij=ix;ij>i;ij--){
          swap(a[ij-1],a[ij]);
          k--;
        }
    } else i=n;
  }

  printf("%s\n",a);
  return 0;
}


#include<cstring>
#include<iostream>
using namespace std;
string a, b;
int main() {
	cin >> a >> b;
	cout << (a == b ? a : "1");
	return 0;
}


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


#include <bits/stdc++.h>
using namespace std;
int main() {
	long n,k,x,a[200][2]={0},s=0;
	cin >> n >> k;
	for (long i=0;i<n;i++) {
		cin >> x;
		a[i%k][x]++;
	}
	for (long i=0;i<k;i++)
		s+=min(a[i][1],a[i][2]);
	cout << s;
}


#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

inline ll read(){
    char ch=getchar();ll x=0,f=1;
    while(ch<'0' || ch>'9') {
       if(ch=='-') f=-1;
      	  ch=getchar();
    }
    while(ch<='9' && ch>='0') {
       x=x*10+ch-'0';
       ch=getchar();
    }
    return x*f;
}

ll f[50][50];

int main(){
    int n=read(),h=read();
    for(int i=0;i<=n;i++){
        f[i][0]=1;
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            for(int k=0;k<j;k++){
                f[i][j]+=(f[i-1][k]*f[i-1][j-k-1]);
            }
        }
    }
    cout<<(f[n][n]-f[h-1][n]);

    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <string>
#include <sstream>
#include <cmath>
#include <stdio.h>
#include <iomanip>
#include <queue>
#include <map>

#define pb push_back
#define mp make_pair
#define f1 first
#define f2 second
#define X first
#define Y second

using namespace std;

typedef long long LL;
typedef pair <int, int> PII;
typedef vector <int> VINT;

const int maxn = 1000 * 100 + 5;
const int mod = 1000 * 1000 * 1000 + 7;

VINT adj[maxn], adjr[maxn];
int mark[maxn], ans[maxn];
int st[maxn];

void dfs1(int x)
{
	mark[x] = 1;
	ans[x]++;
//	if (st[x] == 2)
//		return;
	for (int i = 0; i < (int)adj[x].size(); i++)
	{
		int u = adj[x][i];
		if (!mark[u])
			dfs1(u);
	}
}
void dfs2(int x)
{
	mark[x] = 1;
	ans[x]++;
	if (st[x] == 1)
		return;
	for (int i = 0; i < (int)adjr[x].size(); i++)
	{
		int u = adjr[x][i];
		if (!mark[u])
			dfs2(u);
	}
}

int main()
{
	ios_base::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	for (int i = 0; i < n; i++)
		cin >> st[i];
	for (int i = 0; i < m; i++)
	{
		int u, v;
		cin >> u >> v;
		u--; v--;
		adj[u].pb(v);
		adjr[v].pb(u);
	}
	for (int i = 0; i < n; i++)
		if (!mark[i] && st[i] == 1)
			dfs1(i);
	for (int i = 0; i < n; i++)
		mark[i] = 0;
	for (int i = 0; i < n; i++)
		if (!mark[i] && st[i] == 2)
			dfs2(i);
	for (int i = 0; i < n; i++)
		if (ans[i] == 2)
			cout << 1 << endl;
		else
			cout << 0 << endl;
	return 0;
}


#include <memory.h>
#include <cstdio>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <algorithm>

using namespace std;

const int MAXN = 1500 + 100;

vector<int> edges[MAXN];
int d[MAXN];
bool mark[MAXN];

int Ox, Oy;

int VP(int x1, int y1, int x2, int y2) {
	return (long long)x1 * (long long)y2 - (long long)x2 * (long long)y1 > 0LL ? 1 : -1;
}

struct Point {
public:
	int x, y, id;
	Point() {}

	Point(int id, int x, int y) {
		this->id = id;
		this->x = x;
		this->y = y;
	}

	bool operator < (const Point &P) const {
		return VP(this->x - Ox, this->y - Oy, P.x - Ox, P.y - Oy) < 0;
	}
};

vector<Point> points;
int ans[MAXN];

void join(int u, Point p) {
	ans[p.id] = u;
}

void solve(int u, vector< Point > points, Point P, bool b = false) {
	for (int i = 0; i < points.size(); i++) {
		if (points[i].y < points[0].y || (points[i].y == points[0].y && points[i].x < points[0].x)) {
			swap(points[i], points[0]);
		}
	}

	mark[u] = true;

	int it = 0;
	join(u, points[it]);
	Point T = points[it];
	points.erase(points.begin() + it);

	if (points.size() == 0) return;

	Ox = T.x;
	Oy = T.y;
	sort(points.begin(), points.end());

	int tot = 0;
	for (int i = 0; i < edges[u].size(); i++) {
		int v = edges[u][i];
		if (mark[v]) continue;
		vector<Point> tmp;
		int t = 0;
		for (int j = tot; j < points.size(); j++) {
			tmp.push_back(points[j]);
			t++;
			if (t == d[v]) break;
		}
		tot += t;
		solve(v, tmp, T, true);
	}
}

void dfs(int u) {
	mark[u] = true;
	d[u] = 1;

	for (int i = 0; i < edges[u].size(); i++) {
		int v = edges[u][i];
		if (!mark[v]) {
			dfs(v);
			d[u] += d[v];
		}
	}
}

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

	for (int i = 0; i < n - 1; i++) {
		int a, b;
		scanf("%d%d", &a, &b);
		a--;b--;
		edges[a].push_back(b);
		edges[b].push_back(a);
	}

	memset(d, 0, sizeof(d));
	memset(mark, false, sizeof(mark));
	dfs(0);

	for (int i = 0; i < n; i++) {
		int x, y;
		scanf("%d%d", &x, &y);
		points.push_back(Point(i, x, y));
	}

	memset(mark, false, sizeof(mark));
	solve(0, points, Point());

	for (int i = 0; i < n; i++) printf("%d ", ans[i] + 1);
	printf("\n");

//	system("pause");
	return 0;
}


/**
 * Problem: No name
 * Judge: CodeForces
 * Date: current_date
 * URL: http://codeforces.com
 * Solved by: hopkins
 */

/** Libr@ries **/
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>

/** System_Win_32 **/
#if ( WIN32 || __WIN32_ )
#define lld I64d
#endif
/** System **/
#define _ ios_base::sync_with_stdio(0);cin.tie(0);

/** Utilities **/
#define forit(i,v  )  for(__typeof((v).begin()) i = (v).begin(); i != (v).end(); i++)
#define fori( i,a,b)  for (int i = (int)(a); i < (int)(b); i++)
#define forn( i, n )  fori( i, 0, n )
#define zeros( a )    memset(a, 0,sizeof(a))
#define null( a )     memset(a,-1,sizeof(a))
#define all( a )      (a).begin() , (a).end()
#define sqr( a )      ( (a)*(a) )
#define sz( a )       (a).size()
#define pb            push_back
#define mp            make_pair
#define F             first
#define S             second
#define PI            2*acos(0.0)
#define oo            0x7FFFFFFF
using namespace std;
typedef long long LL;

// const long long mod = (long long)(1e9) + 7LL;
const long long mod = 1000000007LL;

long long fmod(long long a, long long b){
    if (b == 0) {
        return 1LL;
    }
    if (b & 1LL) {
        return (a * fmod(a, b - 1LL)) % mod;
    } else {
        long long x = fmod(a, b >> 1LL);
        return (x * x) % mod;
    }
    return 0;
}

int main(int argc, char const *argv[])
{
    long long x, k;
    cin >> x >> k;

    if (x == 0LL) {
        cout << "0\n";
        return 0;
    }

    long long base = fmod(2LL, k);

    // long long sup = ((x % mod) * base) % mod;
    // long long inf = (((x-1LL + mod) % mod) * base) % mod;
    // long long sum = (sup + inf) % mod;
    // long long ans = (((sum + 1LL) >> 1LL) + 1LL) % mod;

    // cout << sup << " " << inf << endl;

    // cout << base << '\n';
    x = x % mod;
    long long ans = ((base * (x + x - 1LL + mod)%mod) + 1LL) % mod;
    cout << ans << '\n';
    return 0;
}


//I_F_A
#include "bits/stdc++.h"
using namespace std;

void func(long long n){

	long long f = n/12;
	long long i = n%12;

	cout << f << " " << i << endl;
}

int main(){

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	long long n;
	cin >> n;

	if(n%3 == 2LL){

		n = n / 3 + 1;
	}
	else{

		n = n / 3;
	}

	func(n);
}


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

int r = 1000;
for(int i=0;i<=4;i++)
{
if(a[i]==a[i+1])
{
if(i<3 && a[i]==a[i+2])
r = min(r,sum-3*a[i]);
else
{r = min(r,sum-2*a[i]);}
}
}
r=min(r,sum);
cout<<r<<endl;
}


//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//#include<bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <queue>
#include <deque>
#include <iterator>
#include <bitset>
#include <assert.h>
#include <new>
#include <sstream>
#include <time.h>

//using    namespace __gnu_pbds;
using namespace std;

/*** Optimization ***/
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")

/*** Typedef ***/
typedef long long ll;
typedef unsigned long long ull;

/*** Input ***/
#define sci1(a) scanf("%d",&a)
#define sci2(a,b) scanf("%d %d",&a,&b)
#define scln1(a) scanf("%lld",&a)
#define scln2(a,b) scanf("%lld %lld",&a,&b)
#define scln3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)

/*** Output ***/
#define pf1(a) printf("%d\n",a)
#define pf2(a,b) printf("%d %d\n",a,b)
#define pfln1(a) printf("%lld\n",a)
#define pfln2(a,b) printf("%lld %lld\n",a,b)

/*** Loops ***/
#define foR0(num) for(ll i = 0; i < num; i++)
#define foR1(num) for(ll i = 1; i <= num; i++)
#define foRev(num) for(ll i = num - 1; i >= 0; i--)
#define forIn(arr, num) for(ll i = 0; i < num; i++) cin>>arr[i];
#define forIn1(arr, num) for(ll i = 1; i <= num; i++) cin>>arr[i];
#define vpnt(ans) for(ll i = 0; i < ans.size(); i++) cout << ans[i] << (i + 1 < ans.size() ? ' ' : '\n');
#define apnt(arr, num) for(ll i = 0; i < num; i++) cout << arr[i] << (i + 1 < num ? ' ' : '\n');

/*** Define Values ***/

#define    ff              first
#define    ss              second
#define    re              return
#define    MP              make_pair
#define    pb              push_back
#define    SZ(x)           ((int) (x).size())

#define    EPS             10E-10
#define    mxx             100005
#define    MOD             1000000007
#define    iseq(a,b)       (fabs(a-b)<EPS)
#define    PI              3.141592653589793238462643

#define    gcd(a, b)       __gcd(a,b)
#define    min3(a,b,c)     min(a,min(b,c))
#define    max3(a,b,c)     max(a,max(b,c))
#define    lcm(a, b)       ((a)*(b)/gcd(a,b))
#define    min4(a,b,c,d)   min(d,min(a,min(b,c)))
#define    max4(a,b,c,d)   max(d,max(a,max(b,c)))
#define    input           freopen("input.txt","rt", stdin)
#define    output          freopen("output.txt","wt", stdout)

#define    all(v)          v.begin(),v.end()
#define    mem(nam,val)    memset(nam, val, sizeof(nam))
#define    Unique(X)       (X).resize(unique(all(X))-(X).begin())
#define    get_pos(c,x)    (lower_bound(c.begin(),c.end(),x)-c.begin())
#define    IOS             ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

/*** STLs ***/
typedef vector <ll> vll;
typedef set <ll> sll;
typedef multiset <ll> msll;
typedef queue <ll> qll;
typedef stack <ll> stll;
typedef map <ll, ll> mll;
typedef pair <ll, ll> pll;
typedef vector <pair <ll , ll> > vpll;

/*** BitWise Operations
///int Set(int N,int pos){return N=N | (1<<pos);}
///int reset(int N,int pos){return N= N & ~(1<<pos);}
///bool check(int N,int pos){return (bool)(N & (1<<pos));}
***/

/*** Grids
///const int fx[] = {+1,-1,+0,+0};
///const int fy[] = {+0,+0,+1,-1};
///const int fx[] = {+0,+0,+1,-1,-1,+1,-1,+1}; ///King's move
///const int fy[] = {-1,+1,+0,+0,+1,+1,-1,-1}; ///king's Move
///const int fx[] = {-2,-2,-1,-1,+1,+1,+2,+2}; ///knight's move
///const int fy[] = {-1,+1,-2,+2,-2,+2,-1,+1}; ///knight's move
***/

/*** Functions
///typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
///ll toint(string s){ll n=0,k=1;for(int i=s.size()-1; i>=0; i--){n += ((s[i]-'0')*k);k*=10;}return n;}
///string tostring(ll x){string s="";while(x){s += (x%10)+'0';x/=10;}reverse(s.begin(),s.end());return s;}
///bool sortinrev(const pair<ll,ll> &a,const pair<ll,ll> &b)return (a.first > b.first);
///priority_queue< pll ,vector<pll>,greater<pll> >p;
///cout<<*X.find_by_order(0)<<endl;
///cout<<X.order_of_key(-5)<<endl;
***/

/*** Some Prints ***/
#define en cout << '\n';
#define no cout << "NO" << '\n'
#define yes cout << "YES" << '\n'

ll A[1000005];
ll B[1000005];
ll fac[1000005];

void fact(ll m)
{
    fac[0]=1;
    for(ll i=1;i<=250005;i++)
    {
        fac[i]=(i*fac[i-1])%m;
    }
}

int main()
{
    IOS;
    ll tst=1;
   // cin>>tst;
    for(ll tt=1;tt<=tst;tt++)
    {
        //code
        ll n,m;
        cin>>n>>m;
        fact(m);
        ll res=(fac[n]*n)%m;
        for(ll i=1;i<n;i++)
        {
            ll dif=i+1;
            dif=fac[dif];
            dif=(dif*(n-i))%m;
            ll val=(dif*fac[n-i])%m;
           // val=(val*fac[n-i]);
            res=(res+val)%m;
        }
        cout<<res<<endl;

    }

    return 0;
}


#include <bits/stdc++.h>
#define op cin.tie(0);ios_base::sync_with_stdio(0);
using namespace std;
int n;

bool lucky(int x)
{
    while(x)
    {
        if(x%10!= 4 && x%10!=7)
            return false;

        x/=10;

    }
    return true;
}

int main()
{
    op

    cin>>n;
    for(int i=1;i<=n;i++)
    {
        if(n%i==0)
        {
            if(lucky(i))
            {
                cout<<"YES";
                return 0;
            }

        }
    }

    cout<<"NO";
    return 0;
}


#include <iostream>
#include <cmath>

using namespace std;

int main() {
    long long n;
    cin >> n;
    cout << ((n % 2 == 0) ? (long long)pow(2, n / 2) : 0);
}


#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")

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

inline int read()
{
	int sum=0,ff=1; char ch=getchar();
	while(!isdigit(ch))
	{
		if(ch=='-') ff=-1;
		ch=getchar();
	}
	while(isdigit(ch))
		sum=sum*10+(ch^48),ch=getchar();
	return sum*ff;
}

const int N=255;
const int mo=1e9+7;

int n,m,f[N][N],jc[N],inv[N],I[N],II[N],ans;

inline int ksm(int x,int y)
{
	int ret=1ll;
	while(y)
	{
		if(y&1) ret=ret*x%mo;
		x=x*x%mo;
		y>>=1ll;
	}
	return ret;
}

inline int C(int x,int y)
{
	return jc[x]%mo*inv[y]%mo*inv[x-y]%mo;
}

signed main()
{
	n=read();
	m=read();
	jc[0]=inv[0]=1;
	for ( int i=1;i<=n;i++ ) jc[i]=jc[i-1]*i%mo;
	for ( int i=1;i<=n;i++ ) inv[i]=ksm(jc[i],mo-2)%mo;
	f[0][n]=1;
	I[0]=1;
	for ( int i=1;i<=n;i++ ) I[i]=I[i-1]*m%mo;
	II[0]=1;
	for ( int i=1;i<=n;i++ ) II[i]=II[i-1]*(m-1)%mo;
	for ( register int i=1;i<=n;i++ )
		for ( register int j=0;j<=n;j++ )
		{
			f[i][j]=(f[i][j]+f[i-1][j]*II[j]%mo*(I[n-j]%mo-II[n-j]%mo)%mo)%mo;
			for ( register int k=1;k<=n-j;k++ )
				f[i][j]=(f[i][j]+f[i-1][k+j]*C(k+j,k)%mo*I[n-j-k]%mo*II[j]%mo)%mo;
		}
	printf("%lld\n",(f[n][0]+mo)%mo);
	return 0;
}


#include <iostream>

using namespace std;

typedef long long ll;
typedef pair < ll, ll > pll;

ll m;
pll res;

inline ll pow3(ll x) {
  return x * x * x;
}

void solve(ll m, ll step, ll subs) {
  if(m == 0) {
    res = max(res, make_pair(step, subs));
  } else {
    ll x = 1;
    while(pow3(x + 1) <= m)
      x++;
    solve(m - pow3(x), step + 1, subs + pow3(x));

    if(x >= 1)
      solve(pow3(x) - pow3(x - 1) - 1, step + 1, subs + pow3(x - 1));
  }
}

int main()
{
  ios::sync_with_stdio(false);

  cin >> m;
  solve(m, 0, 0);

  cout << res.first << ' ' << res.second << '\n';
  return 0;
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int mod = 1e9 + 7;
int dx[] = { 0, 0, 1, -1, 1, -1, 1, -1 };
int dy[] = { 1, -1, 0, 0, -1, 1, 1, -1 };
void file()
{
	//#ifndef ONLINE_JUDGE
		// freopen("output.txt", "w", stdout);
	//#endif  !ONLINEJUDGE
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}
int main() {
	file();
	ll a, b;
	cin >> a >> b;
	int cnt = 0;
	for (int i = 0; (1LL << i)>>1 <= b; i++) {
		for (int j = 0; j < i-1; j++) {
			long long x = (1LL << i) - 1;
			long long y = (1LL <<j) ;
			x -= y;
			cnt += x >= a && x <= b;
		}
	}
	cout << cnt;

	return 0;
}


#include<bits/stdc++.h>

using namespace std;
#define pb push_back
#define ll long long

const int maxN =2001;
const ll mod = 1e9+7;
ll res=0;
ll dp[maxN][maxN];
vector<int> num[maxN];

int main()
{
  for(int i=1;i<maxN;i++) for(int j=i;j<maxN;j+=i) num[j].pb(i);
  for(int i=1;i<maxN;i++) dp[1][i]=1;
  for(int i=2;i<maxN;i++) for(int j=1;j<maxN;j++) for(int k=0;k<num[j].size();k++) dp[i][j]=(dp[i][j]%mod+ dp[i-1][num[j][k]]%mod)%mod;
  int n,k;
  cin>>n>>k;
  for(int i=1;i<=n;i++) res=(res+dp[k][i])%mod;
  cout<<res;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	int jishu=1,ge=0;
	getline(cin,s);
	for(int i=0;i<=s.size();i++)
	{
		for(int j=i+1;j<=s.size();j++)
		{
			if(s[j]==s[i])
			jishu+=1;
			else
			{
				if(jishu%2==0)
				ge+=1;
				i=j;
				jishu=1;
			}
		}
	}
	cout<<ge;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main() {
#ifndef ONLINE_JUDGE
  freopen("in.in", "r", stdin);
  freopen("out.out", "w", stdout);
#endif
  int a,b;
  int cnt=0;
  cin>>a>>b;
  	while(1){
  		if(a>=b){
  			a-=2;
  			b+=1;
  		}
  		else {
  			a+=1;
  			b-=2;
  		}
  		if(a<=0 or b<=0){
      		if(a>=0 and b>=0) cnt++;

     		break;
    	}
    	cnt++;
  	}
    cout<<cnt<<endl;
  	return 0;
}


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

int n,m,a;

int main()
{
    int kmin, kmax;

    scanf("%d",&n);
    scanf("%d",&m);

    int cnt = 0,mx=0;

    for (int i=0; i<n; i++){
        scanf("%d",&a);
        cnt += a;
        if(a > mx) mx = a;
    }

    kmin = ceil((float)(cnt+m)/n);
    if(kmin<=mx) kmin = mx;
    kmax = m + mx;

    cout << kmin << " " << kmax << endl;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,m,c,min=INT_MAX;
	cin>>n>>m;
	int f[m];
	for(int i=0;i<m;i++)
	cin>>f[i];
	sort(f,f+m);
		for(int i=0;i<=m-n;i++)
	{	c=f[n-1+i]-f[i];
		if(c<min)
		min=c;
	}
	cout<<min;
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <set>
#include <unordered_map>
#include <vector>
#include <queue>
#include <algorithm>
#define forr(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
#define forn(i,n) forr(i,0,n)
#define rforr(i,a,b) for(ll i = ll(a); i > ll(b); --i)
#define rforn(i,n) rforr(i,n,0)

typedef unsigned long long ull;
typedef long long ll;

using namespace std;

const ll INF = (1<<30);

unordered_map <ll, ll> M;

ll logdiez(ll n){
	ll res = 0;
	for(;n>0;n/=10)
		res++;
	return res - 1;
}

ll potdiez(ll e){
	ll res = 1;
	for(;e>0;e--)
		res*=10;
	return res;
}

bool valid(ll n, int dig){
	ll cant = logdiez(n) + 1;
	if(dig != cant or cant < 2)
		return true;

	ll segdig = (n%potdiez(cant-1) - n%potdiez(cant-2)) / potdiez(cant-2);
	return segdig != 0;
}

ll f(ll n){

	if(M.count(n))
		return M[n];

	if(n <= 0)
		return INF;

	double sq = sqrt(n);
	forr(i, sq-1, sq+2){
		if(i*i == n)
			return M[n] = 0;
	}

	ll mejor = INF;
	for(int i = 1; i <= logdiez(n) + 1; i++){
		if(valid(n, i)){
			ll nuevo = (n/potdiez(i)) * potdiez(i-1) + n%potdiez(i-1);
			mejor  = min(mejor, 1 + f(nuevo));
		}
	}

	if(mejor < INF)
		return M[n] = mejor;

	return M[n] = INF;
}

int main(){
	//~ freopen("input.in", "r", stdin);
	ll N;
	scanf("%I64d", &N);

	if(f(N) < INF)
		printf("%I64d\n", f(N));
	else
		printf("-1\n");

	return 0;
}


#include <iostream>
#include <math.h>
using namespace std;
int main(){
long long r,x,y,x1,y1;
cin >>r>>x>>y>>x1>>y1;
long double s=0,n=sqrt(pow(x1-x,2)+pow(y1-y,2));

while(n>=2*r){
        n=n-2*r;
    s++;
}
if(n!=0){
    s++;
}

cout <<s;
}