#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N = 2e5+10 , OO = 0x3f3f3f3f ;
//const int mod = 1000000007;

#define clr(arr,val) memset(arr , val , sizeof (arr))
#define loop(i,n) for(int i = 0;i < int(n);i++)
#define rloop(i,n) for(int i = int(n)-1;i >= 0;i--)
#define xloop(i,a,b) for(int i = int(a);i <= int(b);i++)
#define range(vec) for(auto &x : vec) cin >> x;
#define ALL(v) ((v).begin()) , ((v).end())
#define SZ(v)  ((int)((v).size()))
int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
//int dx[]={2,1,-1,-2,-2,-1,1,2};int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction
//int dx[6]={2,1,-1,-2,-1,1};int dy[6]={0,1,1,0,-1,-1}; //Hexagonal Direction

int n , a , b , c;

int main()
{
   // startTime = (double)clock();
    #ifndef ONLINE_JUDGE
        //freopen("in.in", "r", stdin);
        //freopen("out.in", "w", stdout);
    #endif
	//ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

    int k ;
    string s;
    cin >> s >> k;

    for(int i = 0 ; i < k ; ++i) s += "?";

    int len = s.size();
    vector < int > sizes;
    for(int st = 0 ; st < len - k ; ++st){ // try all valid starts 'st' with end 'e'
        for(int e = st ; e < len ; ++e){
            string now = s.substr(st , e - st + 1);
            //cout << "string now = " << now << "\n";
            if(SZ(now) & 1)
                continue;
            int n = SZ(now) / 2;
            int sz = 0;
            for(int r = 0 ; r < n ; ++r){
                if(now[r] != now[r + n] and now[r + n] != '?')
                    break;
                sz += 2;
            }
            sizes.push_back(sz);
        }
        //for(auto x : sizes) cout << x << " ";

    }
    int mx = *max_element(sizes.begin() , sizes.end());
    printf("%d\n" , mx);

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll int
#define N 4100010
ll yu;
ll n;
ll f[N];
ll fir[N],nxt[N],val[N],cnt=0;
inline void add(ll &x,ll y)
{
	if(y<0)y+=yu;
	x+=y;
	if(x>=yu)x-=yu;
}
ll tmp=0;
ll g[N];
ll st[N],top=0;
int main()
{
	//freopen("test1.in","r",stdin);
	cin>>n>>yu;
	f[1]=1;
	ll sum=1;
	for(int i=2;i<=n;i++)
	{
		top=0;
		add(f[i],sum);
		for(int j=fir[i];j;j=nxt[j])
		{
			ll o=val[j];
			//ll o=q[i].front();
			g[o]++;
			add(tmp,f[g[o]]-f[g[o]-1]);
			st[++top]=j;
			//q[i].pop();
			//q[i+o].push(o);
		}
		while(top)
		{
			ll o=st[top--];
			if(i+val[o]<=n)nxt[o]=fir[i+val[o]];
			if(i+val[o]<=n)fir[i+val[o]]=o;
		}
		tmp+=1;
		add(f[i],tmp);
		g[i]=1;
		cnt++;
		val[cnt]=i;
		if(2*i<=n)nxt[cnt]=fir[2*i];
		if(2*i<=n)fir[2*i]=cnt;
		add(sum,f[i]);
	}
	cout<<f[n]<<endl;
	return 0;
}


#include <iostream>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <functional>
#include <unordered_map>
#include <unordered_set>

using namespace std;

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

	queue<pair<int, int>> kids;

	for (int i = 0; i < n; ++i) {
		int x;
		cin >> x;
		kids.push(make_pair(i, x));
	}

	while (kids.size() > 1) {
		pair<int, int> current = kids.front();
		kids.pop();
		current.second -= m;

		if (current.second > 0) {
			kids.push(current);
		}
	}

	cout << kids.front().first + 1;

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
bool a[1000][1000];
bool arr[1000];
int main()
{
    int x,y,a,b,q,i=1;
    cin >>x>>y>>a>>b;
    if(max(x,y)%min(x,y)==0){
        q=max(x,y);
    }
    else{
        while(true){
            if(max(x,y)*i%min(x,y)==0){
                q=max(x,y)*i;
                break;
            }
            i++;
        }
    }
    cout <<(b/q)-((a-1)/q);
    return 0;
}


#include <iostream>
#include <bits/stdc++.h>
#include<sstream>
using namespace std;
const int N = 1e5 + 7, M = 1e7, OO = 0x3f3f3f3f;
#define endl '\n'
#define  ll long long
#define loop(i,n) for(int i = 0;i < int(n);++i)
#define rloop(i,n) for(int i = int(n);i >= 0;--i)
#define range(i,a,b) for(int i = int(a);i <= int(b);i++)
#define p(a) printf("%d",a)
#define S(n) scanf("%d",&n)
int t;
bool LuckyNumber(ll int x){
        x++;
        while (x) {
            if (abs(x%10) == 8)
                return true;
            x /= 10;
        }
        return false;
}
int main () {
ll int x,cnt=1;cin>>x;
    while (!LuckyNumber(x)) {cnt++;x++;}
    cout<<cnt;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int a[110];
int main()
{
    int n,t,i;
    scanf("%d",&n);
    int k=1;
    int sum1=0;
    int sum2=0;
        int sum3=0;
    int sum4=0;
    int k1=n;
    int kkk=n/2;
    for(i=0;i<kkk;i++)
    {
        scanf("%d",&a[i]);
    }
    sort(a,a+kkk);
    for(i=1;i<=n/2;i++)
    {
        t=a[i-1];
        if(t>k)
        {
            sum1=sum1+t-k;
        }
        else if(t<k)
        {
            sum1=sum1+k-t;
        }
        k++;
        if(t>k)
        {
            sum2=sum2+t-k;
        }
        else if(t<k)
        {
            sum2=sum2+k-t;
        }
        k++;
        if(t>k1)
        {
            sum3=sum3+t-k1;
        }
        else if(t<k1)
        {
            sum3=sum3+k1-t;
        }
        k1--;
        if(t>k1)
        {
            sum4=sum4+t-k1;
        }
        else if(t<k1)
        {
            sum4=sum4+k1-t;
        }
        k1--;
    }
int kk;
kk=min(sum1,sum2);
kk=min(kk,sum3);
kk=min(kk,sum4);
printf("%d",kk);
    return 0;
}


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

int main()
{
    int N;
    cin >> N;
    char grid[N][N];
    for (int i = 0; i < N; i++)
    {
        string row;
        cin >> row;
        for (int j = 0; j < N; j++)
            grid[i][j] = row[j];
    }

    string word = "theseus";
    for (int i = 0; i < N; i++)
    {
        for (int j = 0; j < N; j++)
        {
            if (i < N - 7)
            {
                string w = "";
                for (int k = 0; k < 7; k++)
                    w += grid[i + k][j];
                if (w == word)
                {
                    cout << "YES";
                    exit(0);
                }
            }
            if (j < N - 7)
            {
                string w = "";
                for (int k = 0; k < 7; k++)
                    w += grid[i][j + k];
                if (w == word)
                {
                    cout << "YES";
                    exit(0);
                }
            }
            if (i < N - 7 && j < N - 7)
            {
                string w = "";
                for (int k = 0; k < 7; k++)
                    w += grid[i + k][j + k];
                if (w == word)
                {
                    cout << "YES";
                    exit(0);
                }
            }
        }
    }
    cout << "NO";
}


/*
    Problem: 678B. The Same Calendar

    Solution: calendar, implementation, O(n)

    Author: Dmitry Kozyrev, github: dmkz, e-mail: dmkozyrev@rambler.ru
*/

#include <iostream>
#include <vector>
#include <string>

typedef long long ll;

std::vector<int> days_per_month = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

struct Record {
    int year, month, day, id;

    Record next() const {
        Record ret = *this;
        (ret.id += 1) %= 7;
        ret.day++;
        int need_to_add = month == 1 && (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0));
        if (ret.day == days_per_month[month] + need_to_add) {
            ret.day = 0;
            ret.month++;
            if (ret.month >= 12) {
                ret.month = 0;
                ret.year++;
            }
        }
        return ret;
    }
};

int main() {
    int year; std::cin >> year;
    Record cur{year, 0, 0, 0};
    std::vector<std::string> arr;
    while (true) {
        if (cur.year - year >= (int)arr.size()) {
            if (arr.size() > 1u && arr.back() == arr.front()) {
                std::cout << cur.year - 1 << std::endl;
                return 0;
            }
            arr.push_back("");
        }
        arr[cur.year - year].push_back(char('0'+cur.id));
        cur = cur.next();
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int k,pa,pb;
int A,B;
int f[1005][1005];
const int p=1000000007;
inline int ksm(int b,int pp)
{
	pp--;
    int a=b;
    while(pp>0)
    {
    	if(pp%2==1) a=(1LL*b*a)%p;
        b=(1LL*b*b)%p;
    	pp/=2;
    }
    return a%p;
}
inline int inv(int x)
{
	return ksm(x,p-2);
}
int dp(int i,int j)
{
	if(i+j>=k) return (i+j+1LL*pa*inv(pb)%p)%p;
	if(f[i][j]!=-1) return f[i][j];
	return f[i][j]=(1LL*((1LL*pa*dp(i+1,j))%p+(1LL*pb*dp(i,i+j))%p)*inv(pb+pa))%p;
}
int main(){
	scanf("%d%d%d",&k,&pa,&pb);
	memset(f,-1,sizeof f);
	printf("%d\n",dp(1,0));
}


#include <iostream>

using namespace std;

int main()
{
    int ar[90000];
    int n,d,m,result=0,t;
    cin>>n>>d;
    for(int i=0;i<n;i++){
        cin>>ar[i];
    }
    cin>>m;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            if(ar[i]>ar[j]){
                int t=ar[i];
                ar[i]=ar[j];
                ar[j]=t;
            }
        }
    }
    t=m;
    for(int i=0;i<n;i++){
        result+=ar[i];
        t--;
        if(t==0){
            cout<<result;
            return 0;
        }

    }
    for(int i=0;i<m-n;i++){
        result-=d;
    }
    cout<<result;

}


#include <string>
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <stack>
#include<iomanip>
using namespace std;
long long MOD = 1e9 + 7;
long long phi(long long n)
{
	long long result = n;
	for (long long i = 2; i*i <= n; ++i)
		if (n % i == 0) {
			while (n % i == 0)
				n /= i;
			result -= result / i;
		}
	if (n > 1)
		result -= result / n;
	return result;
}

int main()
{
	long long n; long long k; cin >> n >> k;
	long long docnt = (k + 1) / 2;
	long long ans = n;
	for (long long i = 0; i < docnt; ++i)
	{
		if (ans == 1) { cout << "1"; return 0; }
		ans = phi(ans);
	}
	cout << ans % MOD;
}


/*
 _     _    ___  ___  __ __
| |   | |  |__ \|__ \/_ /_ |
| |__ | |__   ) |  ) || || |
| '_ \| '_ \ / /  / / | || |
| |_) | |_) / /_ / /_ | || |
|_.__/|_.__/____|____||_||_|

*/
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define INF         9223372036854775807
#define    endl        '\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)    for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define lower(u)    transform(u.begin(), u.end(), u.begin(), ::tolower);//convert string u to lowercase;
#define upper(u)    transform(u.begin(), u.end(), u.begin(), ::toupper);
using namespace std;

#define N  100005
ll expo(ll base,ll exponent,ll mod){
    ll ans=1;
    while(exponent!=0){
        if(exponent&1) ans=(ans*base)%mod;
        base=(base*base)%mod;
        exponent>>=1;
    }
    return ans%mod;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int TESTS=1;
//    cin>>TESTS;
    while(TESTS--)
    {
        ll n,ans;
        cin>>n;
        ll fac[2*n];
        fac[0]=1;
        rep(i,1,2*n)
        {
            fac[i]=(fac[i-1]*i)%hell;
        }
        ans=((2*((fac[2*n-1]*expo((fac[n]*fac[n-1])%hell,hell-2,hell))%hell))%hell-n+hell)%hell;
        cout<<ans<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define For(i,n) for(int i=0;i<n;i++)
#define MOD 1000000007
#define MAX 100005
#define endl '\n'
using namespace std;
ll power(int x,int y){
	ll res=1LL;
	while(y){
		if(y&1){
			res*=x;
		}
		x=x*x;
		y/=2;
	}
	return res;
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
	int l,r;
	cin>>l>>r;
	vector<int> two,three;
	int cnt=0;
	for(int i=0;i<=31;i++){
		two.pb(1<<i);
	}
	for(int i=0;i<=19;i++){
		three.pb(power(3LL,(ll)i));
	}
	for(int i=0;i<32;i++){
		for(int j=0;j<=19;j++){
			if(two[i]*1LL*three[j]>=l && two[i]*1LL*three[j]<=r){
				cnt++;
			}
		}
	}
	cout<<cnt<<endl;
}


/*
 * File:      main.cpp
 * Author:    Hrayr [HarHro94]
 * Problem:
 * IDE:       Visual C++ 2012
 */
#pragma comment(linker, "/STACK:66777216")
#define _CRT_SECURE_NO_WARNINGS
#include <functional>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <fstream>
#include <cassert>
#include <iomanip>
#include <cstring>
#include <cstdio>
#include <string>
#include <vector>
#include <ctime>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <map>
using namespace std;

typedef long long LL;
typedef long double LD;
#define pb push_back
#define mp make_pair
#define all(v) (v).begin(), (v).end()
#define sz(v) (int)(v).size()

/*
int [107], ans;
void rec(int cur)
{
    if (cur == n + 1)
    {
        vector<int> cnt(n + 1, 0);
        for (int i = 1; i <= n; ++i)
        {
            ++cnt[a[i]];
        }
        int sum = 0;
        for (int i = 1; i <= n; ++i)
        {
            if (cnt[i] == i)
            {
                sum += i;
            }
        }
        if (n - sum == k)
        {
            ++ans;
        }
        return;
    }
    for (int i = 1; i <= n; ++i)
    {
        a[cur] = i;
        rec(cur + 1);
    }
}
*/
/*
#define MOD 777777777LL
LL dp[600][600][600], C[600][600];
int n, k;

void calcBinomials(int n = 599)
{
    int i, j;
    for (i = 0; i <= n; ++i)
    {
        C[i][0] = 1;
    }
    for (i = 1; i <= n; ++i)
    {
        for (j = 1; j <= n; ++j)
        {
            C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % MOD;
        }
    }
}

void precalc(int n)
{
    //dp[answer][all][wrong];
    for (int i = 0; i <= n; ++i)
    {
        for (int j = 0; j <= n; ++j)
        {
            for (int k = 0; k <= n; ++k)
            {
                dp[i][j][k] = 0LL;
            }
        }
    }
    dp[0][0][0] = 1LL;
    for (int i = 1; i <= n; ++i)
    {
        for (int all = 0; all <= n; ++all)
        {
            for (int wrong = 0; wrong <= all; ++wrong)
            {
                if (all >= i) // right answer
                {
                    dp[i][all][wrong] += (C[n - all + i][i] * dp[i - 1][all - i][wrong]) % MOD;
                    if (dp[i][all][wrong] >= MOD)
                    {
                        dp[i][all][wrong] -= MOD;
                    }
                }
                for (int j = 0; j <= wrong; ++j)
                {
                    if (j == i)
                    {
                        continue;
                    }
                    dp[i][all][wrong] += (C[n - all + j][j] * dp[i - 1][all - j][wrong - j]) % MOD;
                    if (dp[i][all][wrong] >= MOD)
                    {
                        dp[i][all][wrong] -= MOD;
                    }
                }
            }
        }
    }
}
*/

int ans[600][600] =
{
    {1, 0},
    {1, 2, 1},
    {5, 32, 30, 80, 109},
    {541, 6824, 59808, 147224, 415870, 1757896, 1897056, 4898872, 7593125},
    {166257661, 776830421, 290516100, 746623577, 293783147, 33900006, 735127505, 565460332, 428982705, 472062098, 161873957, 117354594, 515619293, 578944191, 312106242, 569389279, 391464593},
    {464207287, 261086313, 584837659, 683961846, 468868529, 211593382, 736955478, 229471758, 157617135, 398169441, 360252438, 629394768, 264125799, 647490480, 342079395, 391579767, 225200475, 486011304, 513156108, 628771752, 132906648, 142138221, 20119449, 444199674, 195188679, 387329805, 44684703, 651912135, 737154512, 612549793, 519860281, 186175544, 212568440},
    {382725349, 240805271, 239509872, 581127897, 6511239, 156126222, 509425833, 672407328, 366667722, 459185405, 509737025, 554790222, 165216555, 703150560, 74806569, 398730015, 383350905, 506108358, 51326142, 298053147, 104256117, 391428765, 374020479, 206607807, 87664059, 275899176, 56407680, 551553401, 448939463, 582889860, 129676638, 226078251, 135769095, 61292868, 578972226, 190181628, 390739055, 184587732, 446575689, 732674124, 232198470, 676760679, 352474101, 611444862, 575661807, 628905585, 320813094, 522840969, 469781928, 156006018, 554473341, 239654268, 643714911, 433540170, 199307003, 496385218, 291740751, 67309914, 370826673, 202356819, 279421821, 421203111, 63744786, 520987612, 550671827},
    {642497124, 482164403, 768209115, 462063756, 154906374, 36099042, 341766705, 678182556, 621882744, 478771358, 231881111, 175889805, 243630450, 168908523, 671961765, 55761813, 652682670, 773939082, 517628076, 756201264, 124604900, 750976272, 498253248, 676047609, 137170026, 705610017, 495032139, 561797418, 703097347, 500815609, 95984586, 739707108, 265613565, 387099846, 777331779, 594676173, 591219559, 407997044, 208947235, 93337440, 478908360, 685013007, 487033953, 671903001, 39521181, 738490312, 33785059, 465470131, 310453920, 54648783, 346831137, 427694175, 474743430, 705296781, 435828036, 429824745, 663532359, 261388683, 244690731, 533997135, 596108961, 506813013, 371892402, 590145264, 104733162, 143420103, 654339672, 700348950, 685038942, 578826927, 286484229, 501639192, 434962491, 299270097, 27702486, 335375775, 111746817, 565603164, 294926121, 676063665, 735862995, 710035809, 437011960, 668528077, 138765186, 508213986, 615036450, 353784942, 624827616, 343900011, 241289776, 52410890, 72018835, 352406796, 415705878, 4802637, 376367145, 65589678, 333633477, 341834527, 303717460, 282387700, 42951006, 254706039, 423048528, 526429710, 68131467, 669954708, 12787348, 500636381, 317959019, 479433192, 657133515, 416259390, 610216692, 340129188, 44594256, 257373347, 138718678, 530767740, 292922628, 37220268, 605295159, 480722613, 458170419, 30540300, 487159055, 232966794, 149150650},
    {507720408, 412133651, 386543325, 139952108, 289303402, 102404925, 317067177, 396414708, 80515854, 663739304, 317300809, 228877044, 493725043, 715317967, 490300965, 315527373, 743539734, 488329191, 553627998, 533025234, 242583957, 706116537, 614109258, 645447222, 523195911, 492109128, 722623041, 111085128, 766395126, 654378921, 691964847, 496688157, 399056049, 654363234, 102052314, 191720088, 473910948, 259736526, 332840025, 388047555, 665791056, 627111387, 139696515, 441456687, 443032569, 283264821, 771641703, 452641455, 511306362, 117572859, 127701891, 721298331, 176520078, 357242229, 611296308, 696994956, 405628839, 429224274, 465336054, 695091546, 689828796, 574648641, 351220905, 507964023, 675326610, 517248963, 453528621, 220301928, 494463186, 681789969, 339589656, 44524053, 417125457, 339589404, 747135963, 341780733, 734158215, 396817281, 21997836, 5728464, 147611205, 456248898, 714128667, 377654949, 3862068, 128418948, 589390074, 304947090, 11703825, 228266073, 127304142, 429215724, 361541124, 521572968, 468358191, 341231688, 65323503, 613778508, 15985323, 291661029, 410970006, 591638112, 349541550, 89967528, 224922159, 361094166, 584206074, 640051812, 324264456, 652625388, 693768537, 11740617, 309238398, 211085469, 194905872, 639416484, 110110707, 296645895, 748118511, 131177718, 511142751, 775975599, 421403409, 475528473, 434685258, 1768977, 80301375, 708023862, 569195676, 56238084, 632887668, 88089750, 631539342, 396695565, 38780154, 695798271, 469819224, 439587099, 69045921, 682966116, 112310856, 64943298, 534475872, 40215357, 389728458, 286368453, 736006257, 501181650, 54829908, 603489402, 338032656, 512182818, 627500097, 462674016, 3103092, 157324491, 43978329, 596818971, 259025598, 9088632, 91991781, 577291428, 211245489, 429471231, 142626330, 172560633, 510907446, 444609585, 758102058, 375112647, 744786693, 276174402, 19259856, 233672418, 745389414, 225772848, 23385663, 324290610, 519804558, 120337812, 402578568, 360676008, 450089262, 551043738, 337388940, 512108856, 28879011, 690040638, 106017282, 558262341, 99972432, 608226003, 612152037, 42414435, 776201013, 39580443, 518796945, 494437752, 583194366, 723936555, 415359657, 309569589, 751104774, 166684527, 249229170, 353120823, 130668327, 753823584, 580966092, 561963717, 543672234, 393846327, 586278000, 327398400, 278403867, 156455586, 363920382, 190245195, 290039148, 547014447, 466218648, 146037150, 585462906, 666008595, 691786683, 374707494, 622498779, 231158277, 685740951, 115612245, 681825249, 545555745, 551718468, 277206615, 640171035, 757727334, 195193908, 658656684, 457760646, 225925875, 505761984, 18685233, 506832921, 112511021, 396846646, 290147622, 113924623, 669986155, 336008070, 63611061, 238586775, 119956662, 616557739, 772784623, 334527774, 410403148, 51933421}
};

int main()
{
#ifdef harhro94
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    /*
    calcBinomials();
    for (int i = 0; i <= 8; ++i)
    {
        int n = (1 << i);
        precalc(n);
        printf("{");
        for (int k = 0; k <= n; ++k)
        {
            if (k == n)
            {
                printf("%d}\n", dp[n][n][k]);
            }
            else
            {
                printf("%d, ", dp[n][n][k]);
            }
        }
    }
    */
    int n, k;
    scanf("%d%d", &n, &k);
    int nn;
    for (int i = 0; i <= 8; ++i)
    {
        if ((1 << i) == n)
        {
            nn = i;
        }
    }
    printf("%d\n", ans[nn][k]);

#ifdef harhro94
    cerr << fixed << setprecision(3) << "\nExecution time = " << clock() / 1000.0 << "s\n";
#endif
    return 0;
}


#include<bits/stdc++.h>
#define fastio     ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define debug(x)   cerr<<#x<<": "<<x<<endl;
#define all(x)     (x).begin() , (x).end()
#define rep(i,a,b) for(int i=a;i<b;i++)
#define endl       '\n'
#define MAX        1000000
typedef long long int ll;
using namespace std;

const ll mod = 1e9+7;
const double eps = 1e-9;

void solve(){
    ll n ,m;
    cin>>n>>m;
    if(n>m) {
        swap(n,m);
    }
    ll pairs=0;
    for(int i=1;i<=n;i++) {
        if(i<5) {
            ll find = 5 - i;
            pairs += (m-find+5)/5;
        }
        else {
            ll find=(i + 4)/5;
            find*=5;
            find=find-i;
            if(find==0)find=5;
            pairs+= (m-find+5)/5;
        }
    }
    cout<<pairs;
}

int main(){
    fastio
    int test=1;
    while(test--)
        solve();
    return 0;
}


//Lasha Bukhnikashvili
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#include<string>
#define INF 1000000001
#define Pi 3.14159265358
#define mod9 %1000000009
#define mod7 %1000000007
#define time clock()/(double)CLOCKS_PER_SEC
using namespace std;
 int a,b,l,i,j,k;
 int prime[1000001],primes[1000001];
 void MakePrime(){
      prime[0]=prime[1]=0;
      for (i=2;i<=1000000;i++){
          if (prime[i]==0){
             for (j=i*2;j<=1000000;j+=i)
                 prime[j]=1;
          };
          primes[i]+=primes[i-1]+1-prime[i];
      };
 };
 void BinarySearch(){
      int l=1,r=b-a+1,mid;
      while (l<r){
            if (r-l==1) break;
            mid=(l+r)/2;
            int stop=0;
            for (i=a;i<=b-mid+1;i++)
                if (primes[i+mid-1]-primes[i-1]<k) stop=1;
            if (stop) l=mid+1; else r=mid;
      };
      int stop=0;
      for (i=a;i<=b-l+1;i++)
          if (primes[i+l-1]-primes[i-1]<k) stop=1;
      if (stop) l=r;
      stop=0;
      for (i=a;i<=b-r+1;i++)
          if (primes[i+r-1]-primes[i-1]<k) stop=1;
      if (stop) cout<<-1; else cout<<l;
 };
int main(){
 //freopen("input.txt","r",stdin);
 //freopen("output.txt","w",stdout);
   cin>>a>>b>>k;
   MakePrime();
   BinarySearch();
 return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int n, k; cin >> n >> k;
    if (k % 2 !=0) {
        cout << k / 2 + 1;
    }
    else {
        cout << n / 2 - k / 2 + 1;
    }
}


/******In the name of ALLAH******/
#include <bits/stdc++.h>

using namespace std;

#define inf 1000000221
#define MAX 1001101
#define PI 3.14159265

struct Point
{
	long double x,y,z,t,h;
}a;

vector<Point> v;

long double dot(Point &a, Point &b , Point&c){
	long double x1 = a.x -c.x;
	long double x2 = b.x -c.x;
	long double y2 = b.y -c.y;
	long double y1 = a.y -c.y;
	long double z1 = a.z -c.z;
	long double z2 = b.z -c.z;
	long double h1 = a.h -c.h;
	long double h2 = b.h -c.h;
	long double t1 = a.t -c.t;
	long double t2 = b.t -c.t;
	return x1*x2 + y1*y2 + h1*h2 + z1*z2  + t1*t2;
}

long double as(Point &a  , Point &c){
	long double temp = sqrt(dot(a,a,c));
	return temp;
}

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int n ;
	cin>>n;
	for(int i =0 ; i < n ; i++){
		cin>>a.x>>a.y>>a.z>>a.t>>a.h;
		v.push_back(a);
	}

	if( n == 1){
		cout<<1<<endl;
		cout<<1;
		return 0;
	}
	if(n == 2){
		cout<<2<<endl;
		cout<<1<<endl;
		cout<<2;
		return 0;
	}
	long double temp,tt;

	for(int i =0 ; i < n ; i++){
		bool f =0;
		for(int j = 0 ; j < n ; j++){
			if(i == j)continue;
			for(int k = 0 ;k < n ; k ++){
				if(k == j || k == i)continue;
				temp = dot(v[j],v[k],v[i]);
				temp /= as(v[k] , v[i]);
				temp /=  as(v[j] ,v[i]);
				tt = acos(temp) * 180.0 / PI;
				if(tt < 90.0 ){
					f = 1;
					break;
				}
			}
			if(f)break;
		}
		if(f == 0){
			cout<<1<<endl;
			cout<< i + 1;
			return 0;
		}
	}
	cout<<0;

	return 0;
}


#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
#include <string>
#include <algorithm>
#include <set>
#include <queue>
using namespace std;

long long mod = 1E9 + 7;
int main()
{
	int n, a, pos;
	cin >> n >> a >> pos;
	long long ans = 1;
	int l = 0, r = n, middle = 0,cntb = 0,cntm = 0;
	while (l < r) {
		middle = (l + r) / 2;
		if (pos < middle) {
			ans = (ans * (n - a - cntb)) % mod;
			cntb++;
			r = middle;
		}
		else if (pos >= middle){
			if (pos != middle) {
				ans = (ans * (a - 1 - cntm)) % mod;
				cntm++;
			}
			l = middle + 1;
		}
	}
	for (int i = n - 1 - cntb - cntm; i >= 1; i--) {
		ans = (ans * i) % mod;
	}
	cout << ans << endl;
	return 0;
}


#include <iostream>
#include <cstring>
#include <vector>

typedef long long ll;

const ll MOD = ll(1e9) + 7;
const int ms = 51;
const int me = 22;

int n;

int a[ms];

ll fexp(ll x, ll e)
{
	ll ans = 1;
	for(; e > 0; e /= 2)
	{
		if(e & 1)
			ans = ans * x % MOD;
		x = x * x % MOD;
	}
	return ans;
}

ll fat[ms];
ll ifat[ms];
ll comb(int a, int b)
{
	if(a < b || b < 0 || a < 0)
		return 0;
	ll ans = fat[a] * ifat[b] % MOD;
	return ans * ifat[a - b] % MOD;
}

int memo[ms][me][me][2][me][me][2];
int dp(int on, std::vector<int> prv, std::vector<int> nxt)
{
	int max = prv[0];
	int min = prv[0];
	int sum = 0;
	for(int i = 0; i < 3; i++)
	{
		max = std::max(max, std::max(prv[i], nxt[i]));
		min = std::min(min, std::min(prv[i], nxt[i]));
		sum += prv[i] + nxt[i];
	}
	if(max > me || min < 0)
		return 0;
	if(on == n)
	{
		//std::cout << "on " << on << ", (" << prv[0] << ", " << prv[1] << ", " << prv[2] << ") - (" << nxt[0] << ", " << nxt[1] << ", " << nxt[2] << ")\n";
		return sum == 0;
	}
	if(sum == 0)
		return 0;
	int &ans = memo[on][prv[0]][prv[1]][prv[2]][nxt[0]][nxt[1]][nxt[2]];
	if(ans != -1)
		return ans;
	ans = 0;
	if(prv[0] + prv[1] + prv[2] == 0)
		return ans = dp(on, nxt, prv);
	//std::cout << "on " << on << ", (" << prv[0] << ", " << prv[1] << ", " << prv[2] << ") - (" << nxt[0] << ", " << nxt[1] << ", " << nxt[2] << ")\n";
	for(int i = 0; i <= a[on] && i <= prv[0]; i++)
	{
		ll cost1 = comb(prv[0], i);
		for(int j = 0; i + j <= a[on] && j <= prv[1]; j++)
		{
			ll cost2 = cost1 * comb(prv[1], j) % MOD;
			for(int k = 0; i + j + k <= a[on] && k <= prv[2]; k++)
			{
				if(i + j + k != 1)
					continue;
				ll cost3 = cost2 * comb(prv[2], k) % MOD;
				for(int ii = 0; i + j + k + ii <= a[on] && ii <= nxt[0]; ii++)
				{
					ll cost4 = cost3 * comb(nxt[0], ii) % MOD;
					for(int jj = 0; i + j + k + ii + jj <= a[on] && jj <= nxt[1]; jj++)
					{
						ll cost5 = cost4 * comb(nxt[1], jj) % MOD;
						for(int kk = 0; i + j + k + ii + jj + kk <= a[on] && kk <= nxt[2]; kk++)
						{
							ll cost6 = cost5 * comb(nxt[2], kk) % MOD;
							//std::cout << "\non " << on << ", (" << prv[0] << ", " << prv[1] << ", " << prv[2] << ") - (" << nxt[0] << ", " << nxt[1] << ", " << nxt[2] << ")\n";

							prv[0] += j - i;
							prv[1] += k - j;
							prv[2] += -k;
							nxt[0] += jj - ii;
							nxt[1] += kk - jj;
							nxt[2] += -kk;
							//std::cout << "cost is " << cost6 << ", (" << i << ", " << j << ", " << k << ", " << ii << ", " << jj << ", " << kk << ")\n";
							if(i + j + k + ii + jj + kk < a[on])
								nxt[a[on] - (i + j + k + ii + jj + kk) - 1]++;
							ans = (ans + cost6 * dp(on + 1, prv, nxt)) % MOD;
							if(i + j + k + ii + jj + kk < a[on])
								nxt[a[on] - (i + j + k + ii + jj + kk) - 1]--;
							prv[0] -= j - i;
							prv[1] -= k - j;
							prv[2] -= -k;
							nxt[0] -= jj - ii;
							nxt[1] -= kk - jj;
							nxt[2] -= -kk;
						}
					}
				}
			}
		}
	}
	//std::cout << "on " << on << ", (" << prv[0] << ", " << prv[1] << ", " << prv[2] << ") - (" << nxt[0] << ", " << nxt[1] << ", " << nxt[2] << ") ans is " << ans << "\n";
	return ans;
}

int main()
{
	fat[0] = ifat[0] = 1;
	for(int i = 1; i < ms; i++)
	{
		fat[i] = fat[i - 1] * i % MOD;
		ifat[i] = fexp(fat[i], MOD - 2);
	}
	std::cin >> n;
	for(int i = 0; i < n; i++)
		std::cin >> a[i];
	memset(memo, -1, sizeof memo);
	a[0]++;
	std::vector<int> prv, nxt;
	prv = nxt = std::vector<int>(3, 0);
	prv[0] = 1;
	std::cout << dp(0, prv, nxt) << '\n';
}


#include<iostream>
using namespace std;
long long a,b,c,d,mid,n,ans=999999999999;
int main(){
	cin>>n;
	c=0;
	d=n+2;
  for(long long i=0;i<90000000;i++)
  i++;
	while(true)
  {
		if(c+1>=d)
    break;
		mid=(c+d)/2;
		a=mid/2;
		b=mid-a;

		if(a*b>=n){
			if(ans>mid)

      ans=mid;
			d=mid;

		}

    else

    {
			c=mid;
		}
	}
	cout<<ans;
}


#include <cstdio>
#include <cstring>
#include <cstdlib>

int main(){
    int a, ta, b, tb;
    while(scanf("%d%d%d%d", &a, &ta, &b, &tb) > 0){

        char aux[10];
        scanf("%s", aux);

        char* str = strtok(aux, ":");
        int depa = atoi(str) * 60;
        str = strtok(NULL, "");
        depa += atoi(str);

        int depb = 5*60;
        while(depb < 24*60 and depb+tb <= depa) depb += b;

        int qtd = 0;
        while(depb < 24*60 and depb < depa+ta) depb += b, qtd++;

        printf("%d\n", qtd);
    }
}


#include <iostream>
#include <cmath>
using namespace std;
long long int n,county,kolvo,k,i;
int a[1000];
int main()
{
	cin >> n >> k;
	county = 2;
	while (county <= sqrt(n)) {
		if (n % county == 0) {
			n /= county;
			kolvo++;
			a[kolvo] = county;
		}
		else { county++; }
	}
	a[kolvo + 1] = n;
	kolvo++;
	if (kolvo < k) {
		cout << -1;
	}
	else {
		while (kolvo != k) {
			a[kolvo - 1] *= a[kolvo];
			kolvo --;
		}
		for (i = 1; i <= k; i++) {
			cout << a[i] << " ";

		}
	}
}


#include<stdio.h>

int max,n,i;

int enBuyuk(int x){

	max = 0;
	while(x){
		int a = x%10;
		if(a > max)
			max = a;
		x /= 10;
	}

	return max;
}

int main(){

	scanf("%d",&n);

	int s = 0;
	while(n > 0){
		n -= enBuyuk(n);
		s++;
	}

   printf("%d",s);

	return 0;
}


#include <stdio.h>
#include <stdlib.h>
#define INF 2000000000
double X1, Y1, X2, Y2;
double Xw1, Yw1,Xw2, Yw2, Xm1, Ym1, Xm2, Ym2;
double A, B, C;
double Aw, Bw, Cw;
double Am, Bm, Cm;
void ecuatie_dreapta(double x1, double y1, double x2, double y2, double &A, double &B, double &C){
	A = y1-y2;
	B = x2-x1;
	C = x1*y2 - x2*y1;
}
double semn_segment(double A, double B, double C, double x, double y){
	if(A*x + B * y + C > 0) return 1;
	if(A*x + B*y + C < 0) return -1;
	return 0;
}
int egal_drepte(double A, double B, double C, double A1, double B1, double C1){
	if(A1 * A == 0 && A1 + A != 0) return 0;
	if(B1 * B == 0 && B1 + B != 0) return 0;
	if(C1 * C == 0 && C1 + C != 0) return 0;
	double v[6]; int  nr = 0;
	if(A) v[++nr] =  A1 / A;
	if(B) v[++nr] = B1 / B;
	if(C) v[++nr] = C1 / C;
	for(int i = 1; i < nr; ++i)
		if(v[i] != v[i+1]) return 0;
	return 1;
}
int if_intersectie(double x1, double y1, double x2, double y2, double xp1,double yp1,double xp2,double yp2, int R){
	double A, B, C, Ap, Bp, Cp;
	//R = 0;
	ecuatie_dreapta(x1,y1,x2,y2,A,B,C);
	ecuatie_dreapta(xp1,yp1,xp2,yp2,Ap,Bp,Cp);
	if(egal_drepte(A , B, C, Ap, Bp, Cp))
		if(R && ((x1 <= xp1 && xp1 <= x2) || (x2 <= xp1 && xp1 <= x1)) ) return 1;
		else return 0;
	if((double)semn_segment(A, B, C, xp1, yp1) * semn_segment(A,B,C,xp2,yp2) > 0.0) return 0;
	if((double)semn_segment(Ap,Bp,Cp,x1,y1) * semn_segment(Ap,Bp,Cp,x2,y2) > 0.0) return 0;
	return 1;
}
void perpendicular(double x, double y, double &xp, double &yp){
	double A = Xm2 - Xm1, B = Ym2-Ym1, C = x*(Xm1-Xm2) + y*(Ym1-Ym2);
	yp = (Am*C - A * Cm) / (A*Bm - Am*B);
	xp = (Bm*C - B * Cm) / (B * Am - Bm*A);
}
void pcte_inters(double A1,double B1, double C1, double A2, double B2, double C2, double &xsol, double &ysol){
	ysol = (A2*C1- A1*C2) / (A1*B2 - A2*B1);
	xsol = (B2*C1 - B1*C2) / (B1 *A2 - B2*A1);
}
int main(){
	//freopen("E.in" ,"r", stdin);
	//freopen("E.out", "w", stdout);
	scanf("%lf%lf%lf%lf", &X1, &Y1, &X2, &Y2);
	scanf("%lf%lf%lf%lf", &Xw1, &Yw1, &Xw2, &Yw2);
	scanf("%lf%lf%lf%lf", &Xm1, &Ym1, &Xm2, &Ym2);
	ecuatie_dreapta(X1, Y1, X2, Y2, A, B , C);
	ecuatie_dreapta(Xw1, Yw1, Xw2, Yw2, Aw, Bw, Cw);
	ecuatie_dreapta(Xm1, Ym1, Xm2, Ym2, Am, Bm, Cm);
	if(if_intersectie(X1, Y1, X2, Y2, Xm1, Ym1, Xm2, Ym2,0)){
		printf("NO");
		return 0;
	}
	if(!if_intersectie(X1, Y1, X2, Y2, Xw1, Yw1, Xw2, Yw2,1)){
		printf("YES");
		return 0;
	}
	if((egal_drepte(A,B,C,Am,Bm,Cm) || semn_segment(Am, Bm, Cm, X1,Y1) != semn_segment(Am, Bm, Cm, X2, Y2)) || (semn_segment(Am, Bm, Cm,X1,Y1) == 0 && semn_segment(Am,Bm,Cm,X2,Y2)==0)){
		printf("NO");
		return 0;
	}
	/*else if( if_intersectie(X1, Y1, X2, Y2, Xw1, Yw1, Xw2, Yw2,1) ){
		printf("YES");
		return 0;
	}*/
	double X1perp, Y1perp;
	perpendicular(X1, Y1, X1perp, Y1perp);
	double X1prim = X1perp + (X1perp - X1), Y1prim = Y1perp + (Y1perp-Y1);
	//if(if_intersectie(X2, Y2, X1prim, Y1prim, Xw1, Yw1, Xw2, Yw2,1)) {printf("NO"); return 0;}
	//if(X2 == X1prim && Y2 == Y1prim) {printf("NO"); return 0;}

	double Aseg,Bseg,Cseg;
	ecuatie_dreapta(X1prim, Y1prim, X2, Y2, Aseg, Bseg,Cseg);
	double xinters,yinters;

	pcte_inters(Am,Bm, Cm, Aseg,Bseg, Cseg,xinters,yinters);
	if( !( ((Xm1 <= xinters && xinters <= Xm2) || (Xm2 <= xinters && xinters <= Xm1)) && ((Ym1 <= yinters && yinters <= Ym2) || (Ym2 <= yinters && yinters <= Ym1)) ) ) {printf("NO");return 0;}

	if(if_intersectie(X1, Y1, xinters,yinters, Xw1, Yw1, Xw2, Yw2,1)) {printf("NO"); return 0;}
	if(if_intersectie(X2, Y2, xinters,yinters,Xw1,Yw1,Xw2,Yw2,1)) {printf("NO"); return 0;}
	printf("YES");
	return 0;
}


#include <stdio.h>
#include <algorithm>
#include <cstring>
#include <iostream>
int n; // number of songs;
int T; // total expected length of playlist
const int max_n = 15; // max num of songs

struct song{
  int len; //(1-15)
  int genre; // 1-3
};

struct song songs[max_n];
bool song_mask[max_n];
long long int possible = 0;

int playlist[max_n];

long long int genre_possibilities;
int genre_ll;

int genre_order_plist[max_n];

void  genre_order_possibilities(int songs_so_far)
{
  for (int i = 0 ; i!= genre_ll; ++i)
    {
      //  if (songs_so_far <1 )
      //printf("(%d) i:%d. ll%d\n", songs_so_far, i, genre_ll);
      if (! song_mask[i] && ( (!songs_so_far) || songs[playlist[i]].genre != genre_order_plist[songs_so_far-1]) )
	{
	  if ( songs_so_far+1 == genre_ll)
	    {
	      genre_possibilities++;
	    }
	  else
	    {
	      song_mask[i] = true;
	      genre_order_plist[songs_so_far] = songs[playlist[i]].genre;
	      genre_order_possibilities(songs_so_far+1);
	      song_mask[i] = false;
	    }
	}
    }

}

const int tmax = 14348907;
long long int checklist [tmax];;

void count_playlist_permutations_real(int n_s)
{
  /* now playlist has playlist of desirable length, but not sure if desirable mix of genres */
  //puts("o2");

  //printf("ll:%d\n", n_s);

  genre_ll = n_s;
  genre_possibilities = 0;
  genre_order_possibilities(0);
  //possible+= genre_possibilities;

}

void count_playlist_permutations(int n_s)
{
  int ternary = 0;
  int ternary_base = 1;

  int genres[3] = {0,0,0};
  int tmp[15];
  int i;
  //puts("ordcnt");
  for (i = 0 ; i!= n_s ; ++i) {
    genres[songs[playlist[i]].genre-1]++;
    //printf("%d ",playlist[i]);
  }
  //putchar(10);

  std::sort(genres, genres+3);
  if (genres[2] > (n_s+1)/2) return;

  for (i = 0 ; i != genres[0] ; ++i)
    tmp[i] = 0;
  for (; i != genres[0] + genres[1] ; ++i)
    tmp[i] = 1;
  for (; i!= n_s ; ++i)
    tmp[i] = 2;

  for (int i = 0 ; i!= n_s ; ++i) {
    ternary += tmp[i]*ternary_base;
    ternary_base *= 3;
  }

  if (checklist[ternary] == -1)
    {
      count_playlist_permutations_real(n_s);
      checklist[ternary] = genre_possibilities;
      //printf("checklist[%d] = %ld;\n", ternary, genre_possibilities% 1000000007UL);
    }

  possible+=checklist[ternary];
  if (possible > 1000000007ULL)
    possible %= 1000000007ULL;

}

void search_pos(int len_so_far, int songs_so_far)
{
  //  int lsf = len_so_far;
  int prev_song = 0;
  if (songs_so_far)
    {
      prev_song = playlist[songs_so_far-1]+1;
    }

  for (int i = prev_song ; i!= n; ++i)
    {
      //if (! song_mask[i] && ( (!len_so_far) || songs[i].genre != songs[playlist[songs_so_far-1]].genre) )
	{
	  if ( songs[i].len+len_so_far == T)
	    {
	      playlist[songs_so_far] = i;
	      count_playlist_permutations(songs_so_far+1);
	      // possible++;
	      // if (possible == 1000000007)
	      // 	possible = 0;
	    }
	  else if ( songs[i].len+len_so_far <= T)
	    {
	      //song_mask[i] = true;
	      playlist[songs_so_far] = i;
	      search_pos(songs[i].len+len_so_far, songs_so_far+1);
	      //song_mask[i] = false;
	    }
	}
    }
}

int main(int argc, char ** argv)
{
  scanf ( "%d %d\n" , &n, &T);

  for (int i = 0 ; i!= n ; ++i)
    {
      scanf ( "%d %d\n" , & (songs [ i ] . len ) , & (songs [ i ] . genre ));
    }
  memset(checklist, 0xff, 14348907*sizeof(long long));
  checklist[14319261] = 420863916;//12420864000UL;
  checklist[1593225] = 35596800;
  checklist[530334] = 10160640;
  checklist[1591029] = 88646400;
  checklist[1593945] = 3628800;
  checklist[4781871] = 123379200;
  checklist[4779675] = 596160000;
  checklist[4773087] = 115596793;
  checklist[1591002] = 115292160;
  checklist[14347813] = 203212800;
  checklist[14345625] = 66867193;

  search_pos(0,0);
  std::cout << possible << std::endl;
  return 0;
}


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

template <typename T>

void read(T &a)
{
	T x = 0,f = 1;
	char ch = getchar();
	while (ch < '0' || ch > '9')
	{
		if (ch == '-') f = -1;
		ch = getchar();
	}
	while (ch >= '0' && ch <= '9')
	{
		x = (x << 1) + (x << 3) + (ch ^ 48);
		ch = getchar();
	}
	a = x * f;
}

template <typename T,typename... Args> void read(T &t,Args &... args) {read(t); read(args...); }

int n,a[1000005],fac[25];

signed main()
{
	fac[0] = 1;
	for (int i = 1; i <= 20; i++) fac[i] = fac[i - 1] * i;
	int t = 1;
	while (t--)
	{
		read(n);
		printf("%lld\n",fac[n] / fac[n / 2] / fac[n / 2] * fac[n / 2 - 1] * fac[n / 2 - 1] / 2);
	}
	return 0;
}


//
/*==========================================================*/
/*    Template ver 2017-0720    |    Created by JollyBee    */
/* DOMINUS pascit me, et nihil mihi deerit (Psalmorum 23:1) */
/*==========================================================*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vii;
const double EPS=(double)1e-9;
const double PI=(double)acos(-1.0);
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define FOR(i,n) for(int i=0;i<n;i++)
#define REPP(i,l,r,c) for(int i=l;i<=r;i+=c)
#define REP(i,l,r) REPP(i,l,r,1)
#define FORD(i,n) for(int i=n-1;i>=0;i--)
#define REVV(i,l,r,c) for(int i=l;i>=r;i-=c)
#define REV(i,l,r) REVV(i,l,r,1)
//random
int irand(int lo, int hi){
    return (((double)rand())/(RAND_MAX+1.0)) * (hi-lo+1) + lo;
}
//ll to string
string toString(ll x) {
    stringstream ss;
    ss << x;
    return ss.str();
}
//string to ll
ll toNumber(string S) {
    ll ret;
    sscanf(S.c_str(),"%lld",&ret);
    return ret;
}
// std::fill(start, end, value);
// for(auto it: DS){}

const int INF=(int)2e9;
const ll MOD=(ll)1e9+7;
/*==========================================================*/
/*                     END OF TEMPLATE                      */
/* DOMINUS pascit me, et nihil mihi deerit (Psalmorum 23:1) */
/*==========================================================*/

ll dat[15];

int dp[10005];
ll solve(const ll& w, const ll& summ){
    if(summ <= w) return summ;
    //do: target -= 400
    ll target = max((ll)0, w-(ll)400);
    REV(num,8,1){
        ll ret = min(dat[num], target/(ll)num);
        ret = max((ll)0, ret-100);
        dat[num] -= ret;
        target -= (ll)num * ret;
    }
    //change target
    int _w = (int)min(w, (ll)400 + target);
    //maximize
    REP(num,1,8) dat[num] = min(dat[num], (ll)1e4);
    //reset
    FOR(i,10003) dp[i] = (i==0);
    //knapsack
    REP(num,1,8) for(; dat[num] > 0; dat[num]--){
        //fill
        REV(i,_w,num) dp[i] |= dp[i-num];
    }
    //find
    int maxx = 0;
    FOR(i,10003) if(dp[i] == 1) maxx = i;
    //return
    return w - (ll)(_w-maxx);
}

int main(){
    ll summ = (ll)0;
    //input
    ll w; scanf("%lld", &w);
    REP(i,1,8) scanf("%lld", dat+i), summ += (ll)i * dat[i];
    //print
    printf("%lld\n", solve(w, summ));
    return 0;
}


/*
गिरते हैं शहसवार ही मैदान-ए-जंग में ।
वो तिफ़्ल क्या गिरे जो घुटनों के बल चले ।।
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int     long long int
#define ull     unsigned int
#define ld      long double
#define pb      push_back
#define pa      pair<int,int>
#define ppa     pair<pair<int,int>,int>
#define pap     pair<int,pair<int,int>>
#define v1d     vector<int>
#define v2d     vector<vector<int> >
#define vpa     vector<pair<int,int>>
#define M       1000000007
#define MN      LLONG_MIN
#define MX      LLONG_MAX
#define ff      first
#define ss      second
#define endl    "\n"
#define v1s     vector<string>
#define all(v)  v.begin(),v.end()
#define S(v)    sort(v.begin(),v.end())
#define RS(v)   sort(v.rbegin(),v.rend())
#define R(v)    reverse(v.begin(),v.end())
#define mxpq(T)    priority_queue <T>
#define mnpq(T)    priority_queue<T,vector<T>,greater<T>>
#define T       int tc;cin>>tc;while(tc--)
#define p2d(v)     for(auto a:v){for(auto b:a)cout<<b<<" ";cout<<endl;}
#define p1d(v)      for(auto a:v)cout<<a<<" ";cout<<endl;
#define ppd(v)      for(auto a:v)cout<<a.ff<<" "<<a.ss<<endl;
#define P1(v)       cout<<#v<<": "<<v<<endl;
#define sz(v)       (int)(v.size())
#define P2(a,b)     cout<<#a<<": "<<a<<" "<<#b<<": "<<b<<endl;
#define P3(a,b,c)   cout<<#a<<": "<<a<<" "<<#b<<": "<<b<<" "<<#c<<": "<<c<<endl;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;
#define qqq 400005
int n,m,x,y,a,b;
int fun(int k){
    if(a*k<=n&&b*k<=m)return 1;return 0;
}

void Weapons19(){
    cin>>n>>m>>x>>y>>a>>b;
    int g=__gcd(a,b);a/=g;b/=g;
    int s=1,e=1e9;
    while(s!=e){
        int k=(s+e+1)/2;
        if(fun(k))s=k;
        else e=k-1;

    }
    a*=s;b*=s;
    int x1,y1,x2,y2;
    x1=max(0ll,x-(a+1)/2);
    x2=x1+a;
    if(x2>n){
        x2=n;
        x1=n-a;
    }
    y1=max(0ll,y-(b+1)/2);
    y2=y1+b;
    if(y2>m){
        y2=m;
        y1=m-b;
    }
    cout<<x1<<" "<<y1<<" "<<x2<<" "<<y2;

}

int32_t main(){

    /*
    त्यक्तवाधर्मं च लोभं च
    मोहंचो द्यमास्थिता।
    युद्ध्यध्वमनहंकारा
    यतो धर्मस्ततो जयः।।
    */

    cout<<fixed<<setprecision(16);
    cin.sync_with_stdio(false);
    cin.tie(0);cout.tie(0);

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

    Weapons19();

}


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

using namespace std;

int n,m,k;

int main()
{
	scanf("%d%d%d",&n,&m,&k);
	if(m<n||k<n) printf("No\n");
	else printf("Yes\n");
	return 0;
 }


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int A,sum=0,B;
	cin>>A;
	B=A;

	while(1)
	{

		while(B!=0)
		{
			sum+=	B%10;
			B=B/10;
		}
		if(sum%4==0)
		{
			cout<<A;
			break;
		}
		else
		{

			A=A+1;
			B=A;
			sum=0;
		}

	}

}


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

int c[11], m[11], p[11];

void as(string t)
{
	if (t[1] == 's') c[t[0] - '0'] += 1;
	else if (t[1] == 'm')m[t[0] - '0'] += 1;
	else p[t[0] - '0'] += 1;
}

int ret()
{
	int i, j;
	for (i = 1; i <= 9; ++i)
	{
		if (c[i] == 3 || m[i] == 3 || p[i] == 3) return 0;
	}
	for (i = 1; i <= 9; ++i)
	{
		if (c[i] == 2 || m[i] == 2 || p[i] == 2) return 1;
	}

	int sign, flag = 0;
	for (i = 1; i <= 7; ++i)
	{
		sign = 0;
		if (c[i]) sign++;
		if (c[i+1]) sign++;
		if (c[i+2]) sign++;

		if (sign == 3) return 0;
		else if (sign == 2) flag = 1;
	}
	for (i = 1; i <= 7; ++i)
	{
		sign = 0;
		if (m[i]) sign++;
		if (m[i + 1]) sign++;
		if (m[i + 2]) sign++;

		if (sign == 3) return 0;
		else if (sign == 2) flag = 1;
	}
	for (i = 1; i <= 7; ++i)
	{
		sign = 0;
		if (p[i]) sign++;
		if (p[i + 1]) sign++;
		if (p[i + 2]) sign++;

		if (sign == 3) return 0;
		else if (sign == 2) flag = 1;
	}
	if (flag) return 1;
	else return 2;
}

int main()
{
	string word1, word2, word3;
	cin >> word1 >> word2 >> word3;
	as(word1);
	as(word2);
	as(word3);

	cout << ret();
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int inf=0x3f3f3f3f;
char mp[30][30];
int n;
int a[50][26];
int dp[50][(1<<21)];
int dfs(int dep,int sta)
{
    int num=0;
    if(dp[dep][sta]!=inf /*|| dp[dep][sta]!=-inf*/)return dp[dep][sta];
    for(int i=0,k=dep;i<n;i++,k--)
    {
        if(sta>>i &1)
        {
            if(mp[k][i]=='a')num++;
            else if(mp[k][i]=='b')num--;
            break;
        }
    }
    if(dep>=2*n-2)return dp[dep][sta]=num;

    int &tmp=dp[dep][sta];
    if(dep%2!=0)
    {
        tmp=-inf;
        for(int i=0;i<26;i++)
        {
            int next=a[dep+1][i]&(sta|(sta<<1));
            if(next==0)continue;
            tmp=max(tmp,dfs(dep+1,next)+num);
        }
    }
    else
    {
        for(int i=0;i<26;i++)
        {
            int next=a[dep+1][i]&(sta|(sta<<1));
            if(next==0)continue;
            tmp=min(tmp,dfs(dep+1,next)+num);
        }
    }
    return tmp;
}

void pre()
{
    for(int i=0; i<2*n-1; i++)
    {
        int k=i;
        for(int j=0; j<n; j++)
        {
            if(k<0)break;
            a[i][mp[k][j]-'a']|=(1<<j);
            k--;
        }
    }

}
int main()
{
    while(cin>>n)
    {
        for(int i=0;i<n;i++)
        {
            cin>>mp[i];
        }
        pre();
        for(int i=0;i<2*n;i++)
            for(int j=0;j<(1<<n);j++)
            {
                dp[i][j]=inf;
            }
        int res=dfs(0,1);
        if(res>0)
        {
            puts("FIRST");
            continue;
        }
        if(res<0)
        {
            puts("SECOND");
            continue;
        }
        puts("DRAW");

    }
}


#include <bits/stdc++.h>
using namespace std;
#define sc(x) scanf("%d",&x)
#define scl(x) scanf("%lld",&x)
#define scs(x) scanf("%s",x)
#define mod 1000000007
#define ll long long
#define pb push_back
#define mp make_pair
#define pi pair<int,int>
#define pl pair<ll,ll>
int main(){
	int n,m,x,y;
	ll k;
	sc(n);
	sc(m);
	scl(k);
	sc(x);
	sc(y);
	ll mini=1ll*mod*mod,maxi=-1,ser=1,a;
	if(n==1){
		a=m;
		mini=k/a;
		k=k%a;
		if(k!=0)
		maxi=mini+1;
		else
		maxi=mini;
		if(y<=k)
		ser=maxi;
		else
		ser=mini;
		cout<<maxi<<" "<<mini<<" "<<ser;
	}
	else{
		a=k/(2*(n-1)*m);
		k-=a*(2*(n-1)*m);
		ll ans[n][m];
		for(int i=0;i<n;i++){
			for(int j=0;j<m;j++)
			ans[i][j]=0;
		}
		for(int i=0;i<n && k>0;i++){
			for(int j=0;j<m && k>0;j++){
				ans[i][j]++;
				k--;
			}
		}
		for(int i=n-2;i>=0 && k>0;i--){
			for(int j=0;j<m && k>0;j++){
				ans[i][j]++;
				k--;
			}
		}
		for(int i=1;i<=n-2;i++){
			for(int j=0;j<m;j++){
				ans[i][j]+=a*2;
			}
		}
		for(int j=0;j<m;j++){
			ans[0][j]+=a;
			ans[n-1][j]+=a;
		}
		for(int i=0;i<n;i++){
			for(int j=0;j<m;j++){
				maxi=max(maxi,ans[i][j]);
				mini=min(mini,ans[i][j]);
			}
		}
		cout<<maxi<<" "<<mini<<" "<<ans[x-1][y-1];
	}
	return 0;
}


# include <iostream>
using namespace std;
long long n,i,t,ans,a,b,j,m;
int main()
{
   cin >> n;
   m = n;
   if(n % 2 != 0)
   {
     cout << 0;
     return 0;
   }
   if(n % 4 != 0)
   {
     cout << n / 4;
     return 0;
   }
   cout << n / 4 - 1;
   return 0;
}


#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
int main() {
    long long x,y,a,b;
    cin>>x>>y>>a>>b;
    cout<<setprecision(0)<<fixed<<max(abs(a-x),abs(b-y));
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define int long long
#define double long double

const int MAXN = 1e6;
const int MOD = 1e9 + 7;

bool tree = true;
set<int> xs, ys;

int binpow(int a, int p) {
    if (p == 1)
        return a % MOD;

    if (!p)
        return 1;

    if (p & 1)
        return (binpow(a, p - 1) * a) % MOD;
    else
        return (binpow(a, p / 2) * binpow(a, p / 2)) % MOD;
}

vector<char> used(MAXN, false);

map<int, set<pair<int, int>>> x, y;
map<int, pair<int, int>> cbyid;

vector<vector<int>> g(MAXN);

void dfs(int v, int p = -1) {
    if (used[v]) {
        if (used[v] == 1) {
            tree = false;
        }
        used[v] = 2;
        return;
    }

    used[v] = true;
    auto coords = cbyid[v];
    xs.insert(coords.first);
    ys.insert(coords.second);

    for (auto i : g[v])
        if (i != p)
            dfs(i, v);

    used[v] = 2;
}

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

    int n, id = 0;
    cin >> n;

    for (int i = 0; i < n; ++i) {
        int xx, yy;
        cin >> xx >> yy;
        cbyid[id] = {xx, yy};
        x[xx].insert({yy, id});
        y[yy].insert({xx, id++});
    }

    for (auto i : y)
        for (set<pair<int, int>>::iterator j = i.second.begin(); j != (i.second.end()); ++j)
            if (next(j) != i.second.end())
                g[j->second].push_back(next(j)->second), g[next(j)->second].push_back(j->second);

     for (auto i : x)
        for (set<pair<int, int>>::iterator j = i.second.begin(); j != (i.second.end()); ++j)
            if (next(j) != i.second.end())
                g[j->second].push_back(next(j)->second), g[next(j)->second].push_back(j->second);

    int ans = 1;

    for (int i = 0; i <= id - 1; ++i) {
        dfs(i);

        //scout << xs.size() << ' ' << ys.size() << endl;

        ans *= max(1ll, (binpow(2, max(static_cast<size_t>(0), xs.size() + ys.size())) - tree)) % MOD;
        ans %= MOD;

        tree = true;
        xs.clear(), ys.clear();
    }

    cout << ans;

    return 0;
}


#include<bits/stdc++.h>

#define N 250005

#define fi first

#define sc second

using namespace std;

typedef pair<int , int> II;

int amount , moder;

int factor[N];

void prepare()
{

    factor[0] = 1;

    for(int i =1 ;i <= amount; i ++)

        factor[i] = (long long)factor[i-1]*i % moder;
}

void solve()
{

    prepare();

    int result = 0;

    for(int dist = 0 ; dist < amount; dist++){

        int choose = (long long)(amount-dist )*(amount - dist)%moder;

        int some = (long long)factor[dist+1] * factor[ amount - dist -1 ] %moder;

        result = ( result + (long long)choose*some%moder )%moder;
    }

    printf("%d", result );
}

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

    scanf("%d %d", &amount , &moder );

    solve();
}


#include<bits/stdc++.h>
#define x first
#define y second
#define pb push_back
using namespace std;
using DO = double;
using LL = long long;
using VI = vector<int>;
using pii = pair<int, int>;
const int mod = 1e9+7;
int power(int a, int b, int c=mod) {
	int ans=1;
	for(; b; b>>=1, a=(LL)a*a%c) {
		if(b&1) ans=(LL)ans*a%c;
	}
	return ans;
}
int a[111];
int main() {
#ifndef ONLINE_JUDGE
	freopen("in.in", "r", stdin);
	freopen("out.out", "w", stdout);
#endif
	int n, k, x;
	cin>>n>>k>>x;
	for(int i=1; i<=n; i++) scanf("%d", a+i);
	reverse(a+1, a+n+1);
	for(int i=1; i<=min(n, k); i++) a[i] = min(a[i], x);
	int ans = 0;
	for(int i=1; i<=n; i++) ans+=a[i];
	cout<<ans<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
bool check(int len,string s){
    unordered_map<string,int> u;
    for(int i=0;i<s.length() - len + 1;i++){

        u[s.substr(i,len)]++;
        // for(auto i = u.begin();i != u.end();i++){
        //     cout<<i->first<<" "<<i->second<<endl;
        // }
        if(u[s.substr(i,len)] > 1)return true;
    }

    // cout<<u.size();
    return false;

}
int main(){
    string s;
    cin>>s;
    int n = s.length();
    // unordered_map<string,int> u;
    int l = 0,r = n-1;
    int len = 0;
    int ans = 0;
    while(l <= r){
        len = (l+r)/2;
        if(check(len,s)){
            l = len + 1;
            ans = max(ans,len);
        }
        else r = len - 1;

    }

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


#include <bits/stdc++.h>

using namespace std;
typedef long long LL;
LL N = 10000001;

LL* primes = new LL[N];
LL* primecounts = new LL[N];
LL* smallprime = new LL[N];
LL* mobiusval = new LL[N];
LL* divisorcounts = new LL[N];
LL* divisortotals = new LL[N];

LL mobius(LL n, LL p)
{
    if(n==1)
        return -1;
    else
    {
        if(smallprime[n]==p)
            return 0;
        else
            return -1*mobius(n/smallprime[n], smallprime[n]);
    }
}

int main()
{

    for(LL i=0; i<N; i++)
    {
        primes[i] = 1;
        smallprime[i] = 0;
        divisorcounts[i] = 0;
    }

    primes[0] = 0;
    primes[1] = 0;
    for(LL i=2; i< 4000; i++)
    {
        LL c = 0 ;
        while(c<N)
        {
            if(i!=c)
                primes[c] = 0;
            if(smallprime[c]==0)
                smallprime[c]=i;
            c += i;
        }
    }
    for(LL i=2; i<N; i++)
    {
        if (smallprime[i]==0)
            smallprime[i] = i;
    }

    mobiusval[0] = 0;
    primecounts[0] = 0;
    for(LL i=1; i<N; i++)
    {
        primecounts[i] = primecounts[i-1]+primes[i];
        mobiusval[i] = mobius(i,10000001);
    }

    LL n;
    cin>>n;
    LL ans = 0;

    for(LL i=2; i<n+1; i++)
        ans += mobiusval[i]*(n/i)*(n/i);
    ans -= (n-1);
    ans = ans/2;

    LL m = LL( pow((n+ 0.5), 0.5) );

    for(LL i=2; i<n+1; i++)
        divisorcounts[smallprime[i]]++;

    divisortotals[0] = 0;
    for(LL i=1; i<n+1; i++)
    {
        divisortotals[i] = divisortotals[i-1]+divisorcounts[i];
    }

    LL dis3=0,dis2;
    for(LL i=m+1; i<=n; i++)
    {
        if(primes[i]==1)
        {
            dis3+=(divisortotals[i-1] - divisortotals[n/i])*divisorcounts[i];
        }
    }

    LL a = primecounts[n] - primecounts[n/2];
    dis2 = (n-1)*(n-2)/2 - dis3 - ans;
    dis3 -= ((a)*(n-1 - a) + a*(a-1)/2);
    ans += (dis2*2+dis3*3);
    cout<<ans<<endl;

    return 0;
}


#include<bits/stdc++.h>
#define INT long long
using namespace std;
const int NN = 5100;
INT dp[NN], t[2];
int p[2];
int main() {
	for(int i = 0; i < 2; i ++) cin >> p[i] >> t[i];
	int h, s;
	cin >> h >> s;
	for(int i = 1; i <= h; i ++) {
		dp[i] = 1e18;
		for(int j = 1; j <= h; j ++) {
			for(int k = 0; k < 2; k ++) {
				INT T = t[k] * j;
				if(T < t[k ^ 1]) continue;
				INT tmp = min(5000ll, (T - t[k^1]) / t[k^1]) * (p[k^1] - s);
				tmp += (j - 1) * (p[k] - s);
				tmp += (p[1] + p[0] - s);
				dp[i] = min(dp[i], T + dp[max(0ll, i - tmp)]);
			}
		}
		INT st = 0, ed = 1LL * 5001 * min(t[1], t[0]);
		while(st + 1 < ed) {
			INT md = (st + ed) >> 1;
			INT tmp = 0;
			for(int k = 0; k < 2; k ++) {
				tmp += (md / t[k]) * (p[k] - s);
			}
			if(tmp >= i) ed = md;
			else st = md;
		}
		dp[i] = min(dp[i], ed);
	}
	cout << dp[h] << endl;
}


#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <vector>
#include <string>
#include <cstdio>
#include <algorithm>
#include <set>
#include <map>
#include <math.h>
#include <cmath>
#include <queue>
#include <iomanip>
#include <bitset>
#include <unordered_map>
#include <stack>
#include <memory.h>
#include <list>
#include <numeric>
#include <functional>
#include <complex>
#include <cassert>
#include <clocale>
#include <fstream>

using namespace std;

int md = 1000000007;
//long long binpow(long long a, long long n) {
//	long long res = 1;
//	while (n) {
//		if (n & 1)
//		{
//			res = (res * a) % md;
//			//res %= md;
//		}
//		a = (a * a) % md;
//		//a %= md;
//		n >>= 1;
//	}
//	return res;// % md;
//}

//int gcd(int a, int b) {
//	return b ? gcd(b, a % b) : a;
//}
//int lcm(int a, int b) {
//	return a / gcd(a, b) * b;
//}
int gcd(int a, int b, int& x, int& y) {
	if (a == 0) {
		x = 0; y = 1;
		return b;
	}
	int x1, y1;
	int d = gcd(b % a, a, x1, y1);
	x = y1 - (b / a) * x1;
	y = x1;
	return d;
}
bool find_any_solution(int a, int b, int c, int& x0, int& y0, int& g) {
	g = gcd(abs(a), abs(b), x0, y0);
	if (c % g != 0)
		return false;
	x0 *= c / g;
	y0 *= c / g;
	if (a < 0)   x0 *= -1;
	if (b < 0)   y0 *= -1;
	return true;
}
//
//void shift_solution(int& x, int& y, int a, int b, int cnt) {
//	x += cnt * b;
//	y -= cnt * a;
//}
//
//int find_all_solutions(int a, int b, int c, int minx, int maxx, int miny, int maxy) {
//	int x, y, g;
//	if (!find_any_solution(a, b, c, x, y, g))
//		return 0;
//	a /= g;  b /= g;
//
//	int sign_a = a > 0 ? +1 : -1;
//	int sign_b = b > 0 ? +1 : -1;
//
//	shift_solution(x, y, a, b, (minx - x) / b);
//	if (x < minx)
//		shift_solution(x, y, a, b, sign_b);
//	if (x > maxx)
//		return 0;
//	int lx1 = x;
//
//	shift_solution(x, y, a, b, (maxx - x) / b);
//	if (x > maxx)
//		shift_solution(x, y, a, b, -sign_b);
//	int rx1 = x;
//
//	shift_solution(x, y, a, b, -(miny - y) / a);
//	if (y < miny)
//		shift_solution(x, y, a, b, -sign_a);
//	if (y > maxy)
//		return 0;
//	int lx2 = x;
//
//	shift_solution(x, y, a, b, -(maxy - y) / a);
//	if (y > maxy)
//		shift_solution(x, y, a, b, sign_a);
//	int rx2 = x;
//
//	if (lx2 > rx2)
//		swap(lx2, rx2);
//	int lx = max(lx1, lx2);
//	int rx = min(rx1, rx2);
//
//	return (rx - lx) / abs(b) + 1;
//}
const int mod = 998244353;

      // int md = 1000000007;
long long binpow(long long a, long long n)
{
	if (n == 0)return 1;
	if (n % 2 == 0)
	{
		long long b = (binpow(a, n / 2))%mod;
		return b * b%mod;
	}
	else
		return (binpow(a, n - 1) * a)%mod;
}

int main()
{
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#else
	//freopen("rmq.in", "r", stdin);
	//freopen("rmq.out", "w", stdout);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	cout.precision(10); cout.setf(ios::fixed);
	int n;
	cin >> n;
	vector<int > v(n);
	for (int i = 0; i < n; i++)
		cin >> v[i];
	vector<int>ans;
	bool na = false;
	int cnt = 0;
	for (int i = 0; i < n; i++)
	{
		if (v[i] == 1 && na)
		{
			if(cnt!=0)
			ans.push_back(cnt);
			cnt = 0;
		}
		if (v[i] == 1)
		{
			na = true;
			cnt = 0;
		}
		else cnt++;

	}
	if (ans.size() == 0)
	{
		if (na)
			cout << 1;
		else cout << 0;
		return 0;
	}
	long long an = 1;
	for (int i = 0; i < ans.size(); i++)
		an*= (ans[i] + 1);
	cout << an;
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
static struct IO {
	char tmp[1 << 10];
	// fast input routines - http://ideone.com/fOK6CW
	char cur;
	inline char nextChar ( )
	{
		return cur = getc (stdin);
	}
	inline char peekChar ( )
	{
		return cur;
	}
	inline operator bool ( )
	{
		return 0 != peekChar ( );
	}
	inline static bool isBlank (char c)
	{
		return (c < '-' && c);
	}
	inline bool skipBlanks ( )
	{
		while (isBlank (nextChar ( ))); return peekChar ( ) != 0;
	}
	inline IO& operator >> (char & c)
	{
		c = nextChar ( ); return *this;
	}
	inline IO& operator >> (char * buf)
	{
		if (skipBlanks ( )) {
			if (peekChar ( )) {
				*(buf++) = peekChar ( );
				while (!isBlank (nextChar ( ))) *(buf++) = peekChar ( );
			} *(buf++) = 0;
		} return *this;
	}
	inline IO& operator >> (string & s)
	{
		if (skipBlanks ( )) {
			s.clear ( ); s += peekChar ( );
			while (!isBlank (nextChar ( ))) s += peekChar ( );
		}
		return *this;
	}
	inline IO& operator >> (double & d)
	{
		if ((*this) >> tmp) sscanf (tmp, "%lf", &d); return *this;
	}
#define defineInFor(intType) \
	inline IO& operator >>(intType & n) { \
		if (skipBlanks()) { \
			int sign = +1; \
			if (peekChar() == '-') { \
				sign = -1; \
				n = nextChar() - '0'; \
			} else \
				n = peekChar() - '0'; \
			while (!isBlank(nextChar())) { \
				n += n + (n << 3) + peekChar() - 48; \
			} \
			n *= sign; \
		} \
		return *this; \
	}
	defineInFor (int)
		defineInFor (unsigned int)
		defineInFor (long long)
		defineInFor (unsigned long long)

		// fast output routines
		inline void putChar (char c)
	{
		putc (c, stdout);
	}
	inline IO& operator << (char c)
	{
		putChar (c); return *this;
	}
	inline IO& operator << (const char * s)
	{
		while (*s) putChar (*s++); return *this;
	}
	inline IO& operator << (const string & s)
	{
		for (int i = 0; i < (int) s.size ( ); ++i) putChar (s[i]); return *this;
	}
	char * toString (double d)
	{
		sprintf (tmp, "%lf%c", d, '\0'); return tmp;
	}
	inline IO& operator << (double d)
	{
		return (*this) << toString (d);
	}
#define defineOutFor(intType) \
	inline char * toString(intType n) { \
		char * p = (tmp + 30); \
		if (n) { \
			bool isNeg = 0; \
			if (n < 0) isNeg = 1, n = -n; \
			while (n) \
				*--p = (n % 10) + '0', n /= 10; \
			if (isNeg) *--p = '-'; \
		} else *--p = '0'; \
		return p; \
	} \
	inline IO& operator << (intType n) { return (*this) << toString(n); }
	defineOutFor (int)
		defineOutFor (long long)
		//defineOutFor (unsigned long long)
#define endl ('\n')
#define cout __io__
#define cin __io__
} __io__;
class TimeTracker {
	clock_t start, end;
public:
	TimeTracker ( )
	{
		start = clock ( );
	}
	~TimeTracker ( )
	{
		end = clock ( );
		fprintf (stderr, "%.3lf s\n", (double) (end - start) / CLOCKS_PER_SEC);
	}
};
template<class T> inline T mypow (T x, int n)
{
	if (n == 0)
		return 1;
	T y = 1;
	while (n > 1) {
		if (n % 2 == 0) {
			x = x*x;
			n = n / 2;
		}
		else {
			y = x*y;
			x = x*x;
			n = (n - 1) / 2;
		}
	}
	return x*y;
}
int main ( )
{
	long long nines = 9999999999LL, ans = 1LL;
	long long l, r;
	cin >> l >> r;
	TimeTracker tt;
	long long upper = mypow (10LL, (int) log10 (r) + 1);
	long long lower = mypow (10LL, (int) log10 (l) + 1);
	if (r >= upper / 2) {
		if (l <= upper / 2) {
			ans = (nines % (mypow (10LL, ((int) log10 (upper / 2) + 1))) - upper / 2)*(upper / 2);
		}
		else {
			ans = (nines % (mypow (10LL, ((int) log10 (upper / 2) + 1))) - l)*l;
		}
	}
	else {
		ans = (nines % (mypow (10LL, ((int) log10 (upper / 2) + 1))) - r)*r;
	}
	cout << ans << endl;
}


#include <cstdio>
#include <algorithm>

using namespace std;

int main() {
    long long n, m, s;
    scanf("%lld %lld %lld", &n, &m, &s);
    if (n < m)
        swap(n, m);
    if (s >= n)
        printf("%lld\n", n * m);
    else if (s >= m)
        printf("%lld\n", ((n - 1) % s + 1) * ((n - 1) / s + 1) * m);
    else
        printf("%lld\n", ((n - 1) % s + 1) * ((n - 1) / s + 1) * ((m - 1) % s + 1) * ((m - 1) / s + 1));
    return 0;
};


#include <iostream>

using namespace std;

int main()
{
    int n;
    cin >> n;
    if(n%4 == 1%4)cout <<8;
    else if(n%4 == 2%4)cout << 4;
    else if(n%4 == 3%4)cout << 2;
    else if(n == 0)cout << 1;
    else cout << 6;
    return 0;
}


/**
 * 生死の去来するは、ほうとうの傀儡たり。
 * 一線弛る時、落々磊々。
*/

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

#define inl inline
template <typename T> inl bool read (T &x) {
	x = 0; int f = 1; char c = getchar ();
	for (; c != EOF && !isdigit (c); c = getchar ())
		if (c == '-') f = -1;
	if (c == EOF) return 0;
	for (; c != EOF && isdigit (c); c = getchar ())
		x = (x<<1) + (x<<3) + (c^48);
	x *= f; return 1;
}
template <typename T, typename... Targs>
inl bool read (T &x, Targs&... args) {
	return read (x) && read (args...); }
template <typename T> void print (T x) {
	if (x < 0) putchar ('-'), x = -x;
	if (x > 9) print (x / 10);
	putchar ('0' + x % 10);
}
template <typename T, typename... Targs>
inl void print (T x, Targs... args) {
	print (x), putchar (' '), print (args...); }

#define reint register int
#define newl putchar('\n')
typedef long long ll;
// typedef unsigned long long ull;
// typedef __int128 lll;
// typedef long double llf;
typedef pair <int, int> pint;
#define fst first
#define scd second
#define all(p) begin (p), end (p)
using vint = vector <int>;

constexpr int N = 1<<19, P = 998244353,
	gen = 3, INF = 0x3f3f3f3f;
int n, k, m, _f; vint f, g;

inl ll fpow (ll a, ll b) {
	ll res = 1; a %= P;
	for (; b; b >>= 1) {
		if (b & 1) res = res * a % P;
		a = a * a % P;
	}
	return res;
}
inl void henkan (vint &f, int l) {
	static int tr[N], lst = tr[0] = 0;
	if (lst != l) { lst = l;
		for (int i = 1; i < 1<<l; ++i)
			tr[i] = tr[i>>1]>>1|((1<<l-1) * (i & 1)); }
	for (int i = 1; i < 1<<l; ++i)
		if (tr[i] < i) swap (f[tr[i]], f[i]);
}
#define clog2(x) ceil (log2 (x))
inl void NTT (vint &f, int l, bool rev) {
	f.resize (1<<l, 0); henkan (f, l);
	for (int len = 2; len <= 1<<l; len <<= 1) {
		const int w_n = fpow (gen, (P-1)/len);
		ll w = 1, g, h;
		for (int st = 0; st < 1<<l; st += len, w = 1)
			for (int i = st; i < st + len/2; ++i, (w *= w_n) %= P)
				g = f[i], h = f[i + len/2] * w % P,
				f[i] = (g + h) % P,
				f[i + len/2] = (P + g - h) % P;
	}
	if (!rev) return;
	const ll invl = fpow (1<<l, P - 2);
	for (int i = 0; i < 1<<l; ++i)
		f[i] = f[i] * invl % P;
	reverse (begin (f) + 1, end (f));
}

inl void pow2 (vint &f, int mod = INF) {
	int len = f.size () * 2 - 1, l = clog2 (len);
	NTT (f, l, 0);
	for (int i = 0; i < 1<<l; ++i)
		f[i] = (ll) f[i] * f[i] % P;
	NTT (f, l, 1);
	f.resize (mod < INF ? mod : len, 0);
}

int main () {
	/*  */
	read (n, k, m); f.resize (k + 1, 1);
	for (int i = n - 1; i; --i) {
		pow2 (f);
		ll sum = accumulate (begin (f) + k + 1, end (f), 0ll);
		for (int j = k; ~j; --j)
			_f = (sum + (k - j + 1ll) * f[j]) % P,
			sum += f[j], f[j] = _f;
		f.resize (k + 1);
	}
	pow2 (f); print (m < f.size () ? f[m] : 0);

	return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int n,m;
	cin>>n>>m;
	int a=max(n,m);
	int b=min(n,m);

	if(a==0||b==0){

		cout<<'0'<<endl;
		return 0;
	}

	if(a/b>=2){
		cout<<b<<endl;
	}
	else
	cout<<(a+b)/3<<endl;

}


/*
ID: lxc9021
PROG: runround
LANG: C++
*/
/** @author starLeo
 *  Standard C++ Header File For Contests
 */
//niubi
#include <iostream>
#include <fstream>
//#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>
#include <utility> //pair
#include <map>
//#include <set>
#include <list>
#include <deque>
#include <queue>
#include <stack>
#include <cctype>
#include <cstring>
#include <climits>
//#include <malloc.h>
using namespace std;
#define R(x) scanf("%d",&(x)) //read int
#define RS(x) scanf("%s",(x)) //read string
#define PL(x) printf("%d\n",(x)) //println int
#define REP(i,n) for(int i(0),_n(n);i<_n;++i)
#define FOR(i,l,h) for(int i(l),_h(h);i<=_h;++i)
#define FORD(i,h,l) for(int i(h),_l(l);i>=_l;--i)
#define RESET(a,b) memset((a),b,sizeof(a))
#define DEBUG(exp) (cout<<(#exp)<<" = "<<(exp)<<endl)
//#define oo (1234567890LL) // 64bits
#define oo (1<<30) // 32bits
//#define oo 9999999999.0 // Double
#define eps 1e-7
typedef long long Int;
typedef pair<int,int> pii;
typedef pair<double,double> pdd;

const int N = 33;
const int LCM = 2520;

int d[N],n;
int id[LCM+1];
Int dp[N][50][LCM+1];

Int dfs(int pos,int lcm,int sum,bool UP) {
    if(pos==-1) return sum%lcm==0? 1 : 0;
    Int& ans=dp[pos][id[lcm]][sum];
    if(UP==false && ans!=-1) return ans;
    Int ret=0;
    FOR(i,0,UP? d[pos] : 9) {
        int tlcm= i==0? lcm : lcm/__gcd(lcm,i)*i;
        int tsum= (sum*10+i)%LCM;
        ret+= dfs(pos-1,tlcm,tsum,UP&&i==d[pos]);
    }
    if(UP==false) ans=ret;
    return ret;
}

Int calc(Int x) {
    n=0;
    while(x) {
        d[n++]=x%10;
        x/=10;
    }
    return dfs(n-1,1,0,true);
}

void init() {
    int cnt=0;
    FOR(i,1,LCM) {
        if(LCM%i==0) id[i]=cnt++;
    }
    RESET(dp,-1);
}

int main() {
#ifndef StarLeo_DEBUG
//    freopen("runround.in","r",stdin);
//    freopen("runround.out","w",stdout);
#endif

    int T;
    cin>>T;
    init();
    while(T--) {
        Int a,b;
        cin>>a>>b;
        cout<< calc(b)-calc(a-1) <<endl;
    }

    return 0;
}


#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <iostream>
#include <bitset>
using namespace std;
#define N 1000005
#define ll long long
#define mod 1000000007
int fac[N],inv[N],n,m,maxn,ans;
int q_pow(int x,int n){int ret=1;for(;n;n>>=1,x=(ll)x*x%mod)if(n&1)ret=(ll)ret*x%mod;return ret;}
int C(int n,int m){return (ll)fac[n]*inv[m]%mod*inv[n-m]%mod;}
int main()
{
	scanf("%d%d%*d%*d",&n,&m);maxn=max(n,m);fac[0]=1;
	for(int i=1;i<=maxn;i++)fac[i]=fac[i-1]*(ll)i%mod;inv[maxn]=q_pow(fac[maxn],mod-2);
	for(int i=maxn;i;i--)inv[i-1]=(ll)i*inv[i]%mod;
	for(int i=1;i<n;i++)if(i<=m)
	{
		int tmp=(ll)C(m-1,i-1)*fac[n-2]%mod*inv[n-i-1]%mod*q_pow(m,n-i-1)%mod;
		if(i!=n-1)tmp=(ll)tmp*(i+1)%mod*q_pow(n,n-i-2)%mod;(ans+=tmp)%=mod;
	}
	printf("%d\n",ans);
}


#include <cstdio>
#include <algorithm>
#include <iostream>
#include <cmath>
#define maxn 200
using namespace std;
int getmaxnum(int x)//找一个数字中最大数位
{
    int max=0;
    while(x)
    {
        int s=x%10;
        if(s>max) max=s;
        x/=10;
    }
    return max;
}
int change(int x,int base)//10进制转base进制
{
    int s=0,p=1;
    while(x)
    {
        s+=x%10*p;
        x/=10;
        p*=base;
    }
    return s;
}
int main()
{
    int a,b;
    cin>>a>>b;
    int base=max(getmaxnum(a),getmaxnum(b))+1;//求基数
    int sum=change(a,base)+change(b,base);//在base进制下两数相加，求十进制结果
    int j=0;
    while(sum)//求其位数
    {
        int s=sum%base;
        sum/=base;
        j++;
    }
    cout<<j<<endl;
    return 0;
}


#include <iostream>
using namespace std;

int main()
{
	char A;
	int Num;
	cin >> A >> Num;
	if (Num % 2 == 0)
		cout << 0;
	else
		cout << 1;
	return 0;
}


#include <bits/stdc++.h>
// #include<ext/pb_ds/assoc_container.hpp>
// #include<ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace chrono;
//using namespace __gnu_pbds;

#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define rep(i,a,n) for (int i = a; i < n; ++i)
#define REP(i,k,n) for (int i = k; i <= n; ++i)
#define repr(i,k,n) for (int i = k; i >= n; --i)
#define mod 1000000007
#define mod1 998244353
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define vd(x) vector <x>
#define sz(x) ((int)(x).size())
#define ff first
#define ss second
#define nline "\n"
#define INF 1e18
#define vll vector <long long int>
#define pii pair<int,int>
#define vii vector <int>
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#ifndef ONLINE_JUDGE
#define debug(x) cerr << #x <<" "; _print(x); cerr << endl;
#else
#define debug(x);
#endif

typedef long long int ll;
typedef unsigned long long ull;
typedef long double lld;
//typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update > pbds; // find_by_order, order_of_key
// use less equal if you want to use as multiset
void _print(ll t) {cerr << t;}
void _print(int t) {cerr << t;}
void _print(string t) {cerr << t;}
void _print(char t) {cerr << t;}
void _print(lld t) {cerr << t;}
void _print(double t) {cerr << t;}
void _print(ull t) {cerr << t;}

template <class T, class V> void _print(pair <T, V> p);
template <class T> void _print(vector <T> v);
template <class T> void _print(set <T> v);
template <class T, class V> void _print(map <T, V> v);
template <class T> void _print(multiset <T> v);
template <class T, class V> void _print(pair <T, V> p) {cerr << "{"; _print(p.ff); cerr << ","; _print(p.ss); cerr << "}";}
template <class T> void _print(vector <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(set <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(multiset <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T, class V> void _print(map <T, V> v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";}

//modular template
ll mod_add(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a + b) % m) + m) % m;}
ll mod_mul(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a * b) % m) + m) % m;}
ll mod_sub(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a - b) % m) + m) % m;}

//void _print(pbds v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";}
// char alf[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',

//                 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'
//                };
// char alpha[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T'
//                  ,'U','V','W','X'.'Y','Z'};

bool chk(string x, string y)
{
  if (y.size() < x.size())
    return false;
  else
  {
    int n1 = x.size();
    int n2 = y.size();
    int diff = n2 - n1;
    for (int i = 0; i <= diff; i++)
    {
      string sa(diff - i, '1'); string sb(i, '1');
      string temp = sa + x + sb;
      if (temp == y) return true;
    }
    return false;
  }

}

void solve() {
  ll n, m;
  cin >> n >> m;
  if (n == m)
  {
    cout << "YES\n"; return;
  }
  string a;
  string b;
  while (n > 0)
  {
    a.pb(n % 2 + '0');
    n /= 2;
  }
  while (m > 0)
  {
    b.pb(m % 2 + '0');
    m /= 2;
  }
  reverse(all(a));
  reverse(all(b));
  debug(a);
  debug(b);
  string a1 = a; a1.pb('1');
  string a2 = a;
  while (!a2.empty())
  {
    if (a2.back() == '0') a2.pop_back();
    else break;
  }
  bool ans = false;
  ans = ans | chk(a2, b); debug(ans);
  ans = ans | chk(a1, b); debug(ans);
  reverse(all(a1)); reverse(all(a2));
  ans = ans | chk(a2, b); debug(ans);
  ans = ans | chk(a1, b); debug(ans);
  ans == true ? cout << "YES\n" : cout << "NO\n";

}

int main() {
#ifndef ONLINE_JUDGE
  freopen("error.txt", "w", stderr);
#endif
  fastio();
  auto start1 = high_resolution_clock::now();
  // seive();
  int tcase; tcase = 1;
  //cin >> tcase;
  rep(tc, 0, tcase) {
    debug(tc);
    //cout << "Case #" << tc + 1 << ":" << " ";
    //debug(tc);
    solve();

  }
  auto stop1 = high_resolution_clock::now();
  auto duration = duration_cast<microseconds>(stop1 - start1);
#ifndef ONLINE_JUDGE
  cerr << "Time: " << duration . count() / 1000 << endl;
#endif
  return 0;
}


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

#ifdef DEBUG
#include "/home/lucas/Topcoder/debug.h"
#define dbg(args...) do {cerr << #args << ": "; debug,args; cerr << endl;} while(0)
#else
#define dbg(args...)
#endif

#define MAX 89

ll fib[MAX];

ll n, k;
ll sol[MAX];

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

  fib[0] = fib[1] = 1;
  for(int i=2; i<MAX; i++) {
    fib[i] = fib[i-1] + fib[i-2];
  }

  while (cin >> n >> k) {
    k --;

    for(int i=1; i<=n; i++) {
      if (n-i+1 >= 1 && fib[n-i+1 - 1] <= k) {
        sol[i] = i+1;
        sol[i+1] = i;
        k -= fib[n-i+1-1];
        i++;
      } else {
        sol[i] = i;
      }
    }

    for(int i=1; i<=n; i++) {
      cout << sol[i] << " \n"[i==n];
    }

  }

  return 0;
}


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

ll solve(ll a,ull b,ll p)
{
	ll res = 1;
	a=a%p;

	while(b>0)
	{

		if(b&1)
		{
			res=(res*a)%p;
		}
		b=b>>1;
		a=((a%p)*(a%p))%p;
//		a=(a*a)%p;
	}
	return res;

}

int main()
{
	ll n,m;
	cin>>n>>m;
	ll ans = solve(3,n,m);
	if(ans==0)
	{
		cout<<m-1;
		return 0;
	}
	cout<<(ans%m)-(1%m);
	return 0;

}


#include <iostream>

using namespace std;

int main(){
    long long n, k, a, b;

	cin >> n >> k;
	if(k > (n + n-1)){
	  cout << 0;
	  return 0 ;
	}
	if(k == (n + n-1) && n > 1){
	    cout << 1;
	    return 0;
	}
	if(k<=n){
		a=abs(k-n);
		b=(n-a-1)/2;
	}else{
		a=k-n;
		b=((n-a)+1)/2;
	}
	cout<<" "<<b<<endl;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>
#define vi vector<int>
#define FOR(i,x,y) for(int i=x; i<=y; i++)

const int mod=int(1e9+7),MAXN=int(1e3+50);

int n,s[MAXN],br,raz,z[MAXN];
vi v[MAXN];
vector <pair<pii,int>> rez;

void dfs(int i, int ot)
{
    s[i]=1;
    for (auto j:v[i])
        if (j!=ot)
        {
            dfs(j,i);
            s[i]+=s[j];
        }
}

int centroid()
{
    dfs(1,-1);
    int c=1,ot=-1;
    while(1)
    {
        int br=1;
        for (auto j:v[c])
            if (j!=ot && 2*s[j]>=n)
            {
                br=0;
                ot=c;
                c=j;
                break;
            }
        if (br)
            break;
    }
    return c;
}

void dfs2(int i, int ot)
{
    br+=raz;
    z[i]=br;
    rez.pb({{i,ot},z[i]-z[ot]});
    for (auto j:v[i])
        if (j!=ot)
            dfs2(j,i);
}

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

    cin >> n;

    FOR(i,1,n-1)
    {
        int p,q;
        cin >> p >> q;
        v[p].pb(q);
        v[q].pb(p);
    }

    if (n==1)
    {
        exit(0);
    }
    if (n==2)
    {
        printf("1 2 1\n");
        exit(0);
    }

    int c=centroid();

    dfs(c,-1);

    vector<pii> v2,g1,g2;

    multiset<pair <int, vector<int> > > sv;

    for (auto i:v[c])
    {
        vector<int> vv{i};
        sv.insert({s[i],vv});
    }

    while (sv.size()>2)
    {
        auto pom1=*sv.begin();
        sv.erase(sv.begin());
        auto pom2=*sv.begin();
        sv.erase(sv.begin());

        vector<int> vu;
        for (auto i:pom1.sc)
            vu.pb(i);
        for (auto i:pom2.sc)
            vu.pb(i);

        sv.insert({pom1.fr+pom2.fr,vu});
    }

    auto a=*sv.begin();
    sv.erase(sv.begin());
    auto b=*sv.begin();
    sv.erase(sv.begin());

    z[c]=0;
    br=0;
    raz=1;
    for (auto i:a.sc)
        dfs2(i,c);

    br=0;
    raz=a.fr+1;

    for (auto i:b.sc)
        dfs2(i,c);

    for (auto i:rez)
        printf("%d %d %d\n",i.fr.fr,i.fr.sc,i.sc);

    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <bitset>
#include <stack>
#include <iomanip>
#include <cmath>
#include <functional>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <ctime>
#include <chrono>
#include <climits>
#define mp make_pair
#define pii pair<int,int>
#define all(x) x.begin(),x.end()
#define pb(x) push_back(x);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

#define MOD 998244353  //(1000*1000*1000+7)
#define inf1 2e9
#define inf2 2e18

inline int mul(int a, int b) {
	return int(a * 1ll * b % MOD);
}

inline int norm(int a) {
	if (a >= MOD)
		a -= MOD;
	if (a < 0)
		a += MOD;
	return a;
}

inline int binPow(int a, int k) {
	int ans = 1;
	while (k > 0) {
		if (k & 1)
			ans = mul(ans, a);
		a = mul(a, a);
		k >>= 1;
	}
	return ans;
}

inline int subtract(int a, int b) {
	return norm(a - b);
}

inline int sum(int a, int b) {
	return int((a + b) % MOD);
}

inline int inv(int a) {
	return binPow(a, MOD - 2);
}

ll ceil_int(ll a, ll b) {
	return a / b + (a%b != 0);
}

ll gcd(ll a, ll b) {
	if (a == 0)return b;
	return gcd(b%a, a);
}

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

int main() {

	int n, k;
	string s;
	cin >> n >> k;
	cin >> s;
	for (int i = 0; i < n; i++) {
		if (s[i] > '0' && k>0) {
			if (i > 0 || n==1) {
				s[i] = '0';
				k--;
			}
			else if(s[i]!='1'){
				s[i] = '1';
			    k--;

			}

		}
	}
	cout << s;

	return 0;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    ll a,b,c,ans2;
    cin >> a >> b >> c;

    ll d = a, e = b , f = c;

    ll ans = min(a,min(b,c));
    a -= ans , b -= ans , c -= ans;
    ans += (a/3)+(b/3)+(c/3);
    a %= 3 , b %= 3 , c %= 3;

    if(min(f,min(d,e))>0 && (a+b+c) == 4)
        ans++;
    cout << ans << endl;
}


#include<iostream>
#include<string>
using namespace std;
int main()
{
	string c;
	int flag,des,des1,len,pos;
	while(cin >> c)
	{

		flag =0;
		len = c.size ();
		des = c.find("C");
		if(des != -1)
		{
			des1 = 0;
			pos = 0;
			while((pos = c.find("ODEFORCES",pos))!= string :: npos)
			{
				des1 = pos;
				pos ++;

			}
			if(des1 + 9== len && des1 != -1 && des1 > des)
			{
				if(des != 0)
				{
					if(des1 - des == 1)
					{
						flag =1;
					}
				}
				else if(des == 0)
				{
					flag = 1;
				}
			}
		}
		des = c.find("CO");
		if(des!= -1 && flag == 0)
		{
			des1 = 0;
			pos = 0;
			while((pos = c.find("DEFORCES",pos))!= string :: npos)
			{
				des1 = pos;
				pos ++;

			}
			if(des1 + 8== len && des1 != -1 && des1 > des)
			{
				if(des != 0)
				{
					if(des1 - des == 2)
					{
						flag =1;
					}
				}
				else if(des == 0)
				{
					flag = 1;
				}
			}
		}
		des = c.find("COD");
		if(des != -1 && flag == 0)
		{
			des1 = 0;
			pos = 0;
			while((pos = c.find("EFORCES",pos))!= string :: npos)
			{
				des1 = pos;
				pos ++;

			}
			if(des1 + 7== len && des1 != -1 && des1 > des)
			{
				if(des != 0)
				{
					if(des1 - des == 3)
					{
						flag =1;
					}
				}
				else if(des == 0)
				{
					flag = 1;
				}
			}
		}
		des = c.find("CODE");
		if(des != -1 && flag == 0)
		{
			des1 = 0;
			pos = 0;
			while((pos = c.find("FORCES",pos))!= string :: npos)
			{
				des1 = pos;
				pos ++;

			}
			if(des1 + 6 == len && des1 != -1 && des1 > des)
			{
				if(des != 0)
				{
					if(des1 - des == 4)
					{
						flag =1;
					}
				}
				else if(des == 0)
				{
					flag = 1;
				}
			}
		}
		des = c.find("CODEF");
		if(des != -1&& flag == 0)
		{
			des1 = 0;
			pos = 0;
			while((pos = c.find("ORCES",pos))!= string :: npos)
			{
				des1 = pos;
				pos ++;

			}
			if(des1 + 5== len && des1 != -1 && des1 > des)
			{
				if(des != 0)
				{
					if(des1 - des == 5)
					{
						flag =1;
					}
				}
				else if(des == 0)
				{
					flag = 1;
				}
			}
		}
		des = c.find("CODEFO");
		if(des != -1&& flag == 0)
		{
			des1 = 0;
			pos = 0;
			while((pos = c.find("RCES",pos))!= string :: npos)
			{
				des1 = pos;
				pos ++;

			}
			if(des1 + 4 == len && des1 != -1 && des1 > des)
			{
				if(des != 0)
				{
					if(des1 - des == 6)
					{
						flag =1;
					}
				}
				else if(des == 0)
				{
					flag = 1;
				}
			}
		}
		des = c.find("CODEFOR");
		if(des != -1&& flag == 0)
		{
			des1 = 0;
			pos = 0;
			while((pos = c.find("CES",pos))!= string :: npos)
			{
				des1 = pos;
				pos ++;

			}
			if(des1 + 3== len && des1 != -1 && des1 > des)
			{
				if(des != 0)
				{
					if(des1 - des == 7)
					{
						flag =1;
					}
				}
				else if(des == 0)
				{
					flag = 1;
				}
			}
		}
		des = c.find("CODEFORC");
		if(des!= -1&& flag == 0)
		{
			des1 = 0;
			pos = 0;
			while((pos = c.find("ES",pos))!= string :: npos)
			{
				des1 = pos;
				pos ++;

			}
			if(des1 + 2== len && des1 != -1 && des1 > des)
			{
				if(des != 0)
				{
					if(des1 - des == 8)
					{
						flag =1;
					}
				}
				else if(des == 0)
				{
					flag = 1;
				}
			}
		}
		des = c.find("CODEFORCE");
		if(des!= -1&& flag == 0)
		{
			des1 = 0;
			pos = 0;
			while((pos = c.find("S",pos))!= string :: npos)
			{
				des1 = pos;
				pos ++;

			}
			if(des1 + 1== len && des1 != -1 && des1 > des)
			{
				if(des != 0)
				{
					if(des1 - des == 9)
					{
						flag =1;
					}
				}
				else if(des == 0)
				{
					flag = 1;
				}
			}
		}
		des = c.find("CODEFORCES");
		if(des == 0)
		{
			flag = 1;
		}
		if(flag == 1)
		{
			cout << "YES" << endl;
		}
		else
		{
			cout << "NO" << endl;
		}
	}
	return 0;
}


#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define F first
#define S second
using namespace std;
int x,y,z,xx,yy,zz,a[6],ans=0;
int main(){
    cin>>x>>y>>z;
    cin>>xx>>yy>>zz;
    for(int i=0;i<6;i++)cin>>a[i];
    if(y<0)ans+=a[0];
    else if(y>yy)ans+=a[1];
    if(z<0)ans+=a[2];
    else if(z>zz)ans+=a[3];
    if(x<0)ans+=a[4];
    else if(x>xx)ans+=a[5];
    cout<<ans;
}


#include<stdio.h>
int main()
{
	int n, k, a, t = 0, count = 0;
	scanf("%d %d", &n, &k);
	for (int i = 0; i < n && k > 0; i++) {
		scanf("%d", &a);
		t += a;
		if (t >= 8) {
			k -= 8;
			t -= 8;
		}

		else {
			k -= t;
			t -= t;
		}
		count++;
	}
	if (k > 0 && n > 0)
		printf("-1");

	else
		printf("%d", count);
}


#include <iostream>
#include <cstdio>
#include <string>
#include <string.h>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <list>
#include <cctype>
#include <algorithm>
#include <climits>
#include <queue>
#include <functional>
#include <map>
using namespace std;
typedef pair<int,int> pii;
typedef pair<pii,pii> ppi;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef vector<vii> vvii;
typedef vector<int, int> vipi;
typedef pair<pii,double> pid;
typedef pair<pii,int> piii;
typedef pair<double,double> pdd;
typedef pair<pdd,pdd> pddpdd;
typedef pair<pdd,double> pddd;
typedef pair<pddpdd,double> ppddpddd;
typedef pair<pii, pdd > ppid;
const static int INF = 1000000000;

int n,m;
int total = 0;
int p=0,v=0,p1=0,v1=0;
int sebelum=-1;
int ctr = 0;
int main(){
    scanf("%d%d",&n,&m);
    int a=n,b=m;
    while(n || m){
        if(sebelum == -1){
            sebelum = 2;
            m--;
        }else if(sebelum == 1){
            if(ctr%2){
                if(m > 0){
                    v++;
                    sebelum = 2;
                    m--;
                }else{
                    p++;
                    n--;
                }
            }else{
                if(n > 0){
                    p++;
                    n--;
                }else{
                    v++;
                    sebelum = 2;
                    m--;
                }
            }
        }else if(sebelum == 2){
            if(ctr%2){
                if(n > 0){
                    v++;
                    sebelum = 1;
                    n--;
                }else{
                    p++;
                    sebelum = 2;
                    m--;
                }
            }else{
                if(m > 0){
                    p++;
                    sebelum = 2;
                    m--;
                }else{
                    sebelum = 1;
                    v++;
                    n--;
                }
            }
        }
        ctr++;
    }
    ctr =0;
    sebelum = -1;
    while(a || b){
        if(sebelum == -1){
            sebelum = 1;
            a--;
        }else if(sebelum == 1){
            if(ctr%2){
                if(b > 0){
                    v1++;
                    sebelum = 2;
                    b--;
                }else{
                    p1++;
                    a--;
                }
            }else{
                if(a > 0){
                    p1++;
                    a--;
                }else{
                    v1++;
                    sebelum = 2;
                    b--;
                }
            }
        }else if(sebelum == 2){
            if(ctr%2){
                if(a > 0){
                    v1++;
                    sebelum = 1;
                    a--;
                }else{
                    p1++;
                    b--;
                }
            }else{
                if(b > 0){
                    p1++;
                    b--;
                }else{
                    sebelum = 1;
                    v1++;
                    a--;
                }
            }
        }
        ctr++;
    }
    if(p > p1){
        printf("%d %d\n",p,v);
    }else
        printf("%d %d\n",p1,v1);
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

map<char,int> data;

int convertion(string number,int base){
	int ans = 1*data[number[number.size()-1]];
	int pot = base;
	for (int i = number.size()-2; i >= 0; --i)
	{
		ans += pot*data[number[i]];
		pot *= base;
	}
	return ans;
}
int main(){
	data['0'] = 0;
	data['1'] = 1;
	data['2'] = 2;
	data['3'] = 3;
	data['4'] = 4;
	data['5'] = 5;
	data['6'] = 6;
	data['7'] = 7;
	data['8'] = 8;
	data['9'] = 9;
	data['A'] = 10;
	data['B'] = 11;
	data['C'] = 12;
	data['D'] = 13;
	data['E'] = 14;
	data['F'] = 15;
	data['G'] = 16;
	data['H'] = 17;
	data['I'] = 18;
	data['J'] = 19;
	data['K'] = 20;
	data['L'] = 21;
	data['M'] = 22;
	data['N'] = 23;
	data['O'] = 24;
	data['P'] = 25;
	data['Q'] = 26;
	data['R'] = 27;
	data['S'] = 28;
	data['T'] = 29;
	data['U'] = 30;
	data['V'] = 31;
	data['W'] = 32;
	data['X'] = 33;
	data['Y'] = 34;
	data['Z'] = 35;
	string x;
	int y;
	cin >> x;
	int ini = INT_MAX;
	int end = -1;
	string hour = "";
	string minute = "";
	bool sw = false;
	for (int i = 0; i < x.size(); ++i)
	{
		if(x[i]==':'){
			sw = true; continue;
		}
		if(!sw) hour += x[i];
		else minute += x[i];
	}
	for (int i = 0; i < x.size(); ++i)
		end = max(end,data[x[i]]);
	vector<int> ans;
	for (int i = end+1; i <= 60; ++i)
	{
		int h = convertion(hour,i);
		int m = convertion(minute,i);
		if(h < 24 and m < 60) ans.push_back(i);
	}

	if(ans.size() == 0) cout << 0;
	else if(ans[ans.size()-1] == 60) cout << -1;
	else{
		for (int i = 0; i < ans.size(); ++i)
			cout << ans[i] << " ";

	}
	return 0;
}


#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
const int inf = 0x3f3f3f3f;
int read()
{
	int x=0,f=1;char c;
	while((c=getchar())<'0' || c>'9') {if(c=='-') f=-1;}
	while(c>='0' && c<='9') {x=(x<<3)+(x<<1)+(c^48);c=getchar();}
	return x*f;
}
int n,m,k,ans,a[7],b[7],c[7][7],dp[20000][7][7][5];
struct node {int a[7];node() {memset(a,0,sizeof a);} };
int get(node s)
{
	int x=0;
	for(int i=1;i<=n;i++) x=x*5+s.a[i];
	return x;
}
node back(int x)
{
	node s;
	for(int i=n;i>=1;i--) s.a[i]=x%5,x/=5;
	return s;
}
int check(node s)
{
	for(int i=1;i<=n;i++)
		if(s.a[i]<a[i]) return 0;
	return 1;
}
signed main()
{
	n=read();m=read();k=1;
	for(int i=1;i<=n;i++)
		a[i]=read(),k*=5;
	for(int i=1;i<=m;i++)
		b[i]=read();
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			c[i][j]=read();
	memset(dp,0x3f,sizeof dp);
	ans=inf;dp[0][1][1][0]=0;
	for(int s=0;s<k;s++)
	{
		node t=back(s);int f=1;
		for(int i=1;i<=n;i++)
			if(t.a[i]>a[i]) f=0;
		if(!f) continue;//this state is illegal
		for(int j=1;j<=m;j++)
			for(int i=1;i<=n;i++)
				for(int r=0;r<5;r++)
				{
					if(r>b[j]) break;
					for(int f=0;f<5;f++)
					{
						if(r+f>b[j] || t.a[i]+f>a[i]) break;
						node tt=t;tt.a[i]+=f;
						int ts=get(tt),ti=i+1,tj=j,tr=r+f,ad=f?c[i][j]:0;
						if(ti>n) ti=1,tj++,tr=0;
						if(check(tt)) ans=min(ans,dp[s][i][j][r]+ad);
						if(tj<=m)
							dp[ts][ti][tj][tr]=min(dp[ts][ti][tj][tr],dp[s][i][j][r]+ad);
					}
				}
	}
	if(ans>=inf) puts("-1");
	else printf("%d\n",ans);
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n,m,k;
   // top:
    cin>>n>>m>>k;
    int x=1,y=1;
    if(k<n)
    {
        cout<<x+k<<" "<<y<<endl;//goto top;
        return 0;
    }
    if(k==(n*m)-1)
    {
        cout<<1<<" "<<2<<endl;//goto top;
        return 0;
    }
    k=k-n;
    if(k%(m-1)==0)
    {
        k=k/(m-1);
        if(k%2==0)
            y=2;
        else
            y=m;
        x=n-k;
    }
    else
    {
        int t=k%(m-1);
        if((k/(m-1))%2==0)
            y=2+t;
        else
            y=m-t;
        k=k/(m-1);
        x=n-k;
    }
    cout<<x<<" "<<y<<endl;
    //goto top;
    return 0;
}


#include<stdio.h>
int main(){
int a,b,c,n,f=0;
scanf("%d%d%d%d",&a,&b,&c,&n);
if(a>=c&&b>=c){
f=n-((a+b)-c);}
if(f>0){
    printf("%d",f);
}else
printf("-1");
return 0;}


#pragma comment(linker,"/STACK:64000000")
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <vector>
#include <queue>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#include <iterator>
#include <bitset>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
#define mp make_pair
#define pb push_back
#define eps (double)(1e-2)
#define MOD (ll)(1e9 + 7)

const int maxlen = 1e7 + 10;
const int length_double = 100;
const int base = 10;
#define PI 3.14159265358979323846
#define name "floor"

vector<int> A;
int main()
{
#ifdef _DEBUG
	freopen("input.txt", "rt", stdin);
	freopen("output.txt", "wt", stdout);
	/*#else
	freopen(name".in", "rt", stdin);
	freopen(name".out", "wt", stdout);*/
#endif
	int n;
	int i;
	scanf("%d", &n);
	for (i = 0; i < n; ++i)
	{
		int x;
		scanf("%d", &x);
		A.push_back(x);
	}
	sort(A.begin(), A.end());
	printf("%d", A[n / 2]);
	return 0;
}


#include <cstdio>
#include <algorithm>
#define MAXN 103
using namespace std;

int a[MAXN];
int main()
{
	int n;
	scanf("%d",&n);
	for(int i = 1;i <= n;i++)
		scanf("%d",&a[i]);
	sort(a + 1,a + 1 + n);
	printf("%d\n",a[(n + 1) / 2]);
	return 0;
}


 #include <bits/stdc++.h>
 using namespace std;
 int main()
 {
    int x;
    cin>>x;
    int a[x];
    for (int i = 0; i < x; ++i)
    {
        cin>>a[i];
    }
    sort(a,a+x);
    if(x==1)
    {
        cout<<a[0]<<endl;;
    }
    else
    {
       if(x%2==0)
       {
            cout<<a[x%2-1]<<endl;
       }
       else if(x==5)
       {
            cout<<a[(x%2)+1]<<endl;
       }
       else
       {
            cout<<a[x%2]<<endl;
       }
    }
    return 0 ;
 }


#include<bits/stdc++.h>

using namespace std;

int a[9];
set <int> st;
main()
{
    int n;
    cin >> n;
    for (int i=1; i<=n; i++){
        cin >> a[i];
        st.insert(a[i]);
    }
    sort(a+1,a+n+1);
    cout << a[(n+1)/2];

}


#define _CRT_SECURE_NO_WARNINGS

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

using namespace std;

int main()
{
#ifdef _DEBUG
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif
	int n; cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++)
		cin >> a[i];
	sort(a.begin(), a.end());
	cout << a[n / 2] << endl;

	return 0;
}


#include<iostream>

using namespace std;

int main(){
    int n, res = 0;
    cin >> n;
    for(int i = 0, a; i < n; i++){
        cin >> a;
        res += a;
    }
    cout << res / n;
    return 0;
}


#include <iostream>

using std::cin;
using std::cout;

int a[5];
int main()
{
	int n = 0;
	int s = 0;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		s += a[i];
	}
	cout << (s / n);
	return 0;
}