#include <iostream>
#include <vector>
#include <queue>
#include <cmath>

using namespace std;

int main(){

	int r1, c1, r2, c2;
	cin >> r1 >> c1 >> r2 >> c2;

	if(r1==r2 || c1==c2){
		cout << 1 << " ";
	}else cout << 2 << " ";
	const int INF = 1e9;
	vector<vector<int> > g (9, vector<int>(9, INF));
	queue<int> Q;
	Q.push(r1);Q.push(c1);g[r1][c1] = 0;
	int res = 0;
	bool flag = 0;
	while(!Q.empty()){
		int y = Q.front();Q.pop();
		int x = Q.front();Q.pop();
		if(y==r2 && x==c2){
			cout << g[y][x] << " ";
			res=0;
			flag=1;
			break;
		}
		int i = y, j = x;
		while(i <= 8 && j <= 8){
			if(g[i][j] == INF){
				Q.push(i);Q.push(j);g[i][j]=res+1;
			}
			i++;j++;
		}
		i = y;j=x;
		while(i >= 1 && j >= 1){
			if(g[i][j] == INF){
				Q.push(i);Q.push(j);g[i][j]=res+1;
			}
			i--;j--;
		}
		i = y;j=x;
		while(i <= 8 && j >= 1){
			if(g[i][j] == INF){
				Q.push(i);Q.push(j);g[i][j]=res+1;
			}
			i++;j--;
		}
		i = y;j=x;
		while(i >= 1 && j <= 8){
			if(g[i][j] == INF){
				Q.push(i);Q.push(j);g[i][j]=res+1;
			}
			i--;j++;
		}

			res++;

	}
	res=0;
	if(!flag)cout << 0 << " ";

	if(r2 > r1 && c2 > c1){
		while(r1!=r2 || c1!=c2){
			++r1;++c1;++res;
		}
	}else{
		if(r2 > r1 && c2 < c1){
			while(r1!=r2 || c1!=c2){
			++r1;--c1;++res;
			}
		}else{
			if(r2 < r1 && c2 > c1){
			while(r1!=r2 || c1!=c2){
			--r1;++c1;++res;
			}
		}else{
			if(r2 < r1 && c2 < c1){
			while(r1!=r2 || c1!=c2){
			--r1;--c1;++res;
			}
		}
		}
		}
	}

	if(r1==r2 && c1==c2){
		cout << res;
		return 0;
	}

	if(r1==r2){
		res+=abs(c2-c1);
		cout << res;
		return 0;
	}else{
		res+=abs(r2-r1);
		cout << res;
		return 0;
	}

	return 0;
}


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

int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  int sf = 0, fs = 0, i=1;
  while (i < s.size()) {
    if (s[i - 1] != s[i]) {
      if (s[i - 1] == 'S') sf++;
      else fs++;
	  i++;
    }
  }
  if (sf > fs) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  return 0;
}


#include <iostream>
#include <cstdio>

using namespace std;
const int MAXN=100+10;
char s[MAXN];

int main()
{
    int n;
    while(scanf("%d",&n))
    {
        scanf("%s",s);
        if(s[0]=='S'&&s[n-1]=='F')
            printf("YES\n");
        else
            printf("NO\n");
    }

    //cout << "Hello world!" << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    for(int i=a; i>=1; i--)
        for(int j=b; j>=1; j--)
            for(int k=c; k>=1; k--)
            {
                for(int l=100;l>=1;l--)
                {
                    if(i*2==j&&j*2==k)
                    {
                        cout<<i+j+k<<endl;
                        return 0;
                    }
                }
            }
    cout<<"0"<<endl;
    return 0;
}


#include <cstdio>
#include <vector>
using namespace std;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef long long LL;

#define FOR(i,a,b) for(int i=a;i<int(b);i++)
#define SZ(a) ((int)(a).size())
#define MOD 998244353

struct RS {
	int wp; // with parent, take
	int nt; // with parent, do not take
	int np; // without parent
};

int N;
VVI adj;
vector<RS> rss;

void dfs(int n, int p) {
	VI& aj = adj[n];
	if (p != -1) aj.erase(find(aj.begin(), aj.end(), p));
	RS& rs = rss[n];
	if (aj.empty()) {
		rs.wp = 1;
		rs.nt = 0;
		rs.np = 1;
		return;
	}
	for (int m : aj) dfs(m, n);
	VI pfx(aj.size()), sfx(aj.size());
	pfx[0] = 1;
	FOR(i,1,aj.size()) {
		RS const& rsm = rss[aj[i-1]];
		int x = rsm.nt + rsm.np;
		x %= MOD;
		pfx[i] = int((LL(pfx[i-1])*x)%MOD);
	}
	sfx[SZ(aj)-1] = 1;
	for (int i = SZ(aj)-2; i >= 0; i--) {
		RS const& rsm = rss[aj[i+1]];
		int x = rsm.nt + rsm.np;
		x %= MOD;
		sfx[i] = int((LL(sfx[i+1])*x)%MOD);
	}
	rs.wp = 1;
	rs.nt = 0;
	LL allnp = 1;
	FOR(i,0,SZ(aj)) {
		RS const& rsm = rss[aj[i]];
		int x = rsm.nt + rsm.np;
		rs.wp = int((LL(rs.wp) * x)%MOD);
		LL nt = rsm.wp;
		nt = (nt * pfx[i]) % MOD;
		nt = (nt * sfx[i]) % MOD;
		rs.nt = int((rs.nt + nt) % MOD);
		allnp = (allnp * rsm.np) % MOD;
	}
	rs.np = (rs.nt + allnp) % MOD;
	//printf("Called %d wp=%d nt=%d np=%d\n", n+1, rs.wp, rs.nt, rs.np);
}

int main() {
	scanf("%d", &N);
	adj.resize(N);
	FOR(a,0,N-1) {
		int u, v;
		scanf("%d%d", &u, &v); --u; --v;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	rss.resize(N);
	dfs(0, -1);
	printf("%d\n", rss[0].np);
}


#include <bits/stdc++.h>
using namespace std;
vector <vector <long long> > G;
vector <long long> stopnie;
vector <vector <long long> > stany;
long long modulo = 998244353;
/*
stan 1 - jesli jest z synkiem LUB izolowany ( i kazde poddrzewo jest ok)
stan 2 - laczymy z tata, nie z jakims synkiem
stan 3 - laczy sie z ktoryms z synkow
*/
long long SzypkiePot(long long pod, long long pot, long long mod){
    if (pot == 0){return 1;}
    long long wynik = SzypkiePot(pod, pot/2, mod)%mod;
    if (pot % 2 == 0){ return (wynik*wynik)%mod;}
    else{  return (pod*((wynik*wynik)%mod))%mod; }
}
long long Odw(long long x, long long mod){ return SzypkiePot(x, mod-2, mod)%mod;}

void Licz(long long v, long long tata){
    cerr << "v  "<<v << "\n";
    long long stan2 = 1; //czyli polacze z tata
    for (auto w : G[v]){ // dla kazdego synka chce zeby albo sie izolowal albo laczyl z synem
        if (w == tata) {continue;} // jesli nie jest synem
        stan2 = ((stany[w][0] + stany[w][2])*stan2)%modulo; // domnazam na ile sposobow
        // cerr << "Domnazam "<<stany[w][0] + stany[w][2] << "\n";
         // moj synek moze albo sie laczyc z synem swoim albo byc (izolowany lub z synem)
    }
    long long stan3 = 0; // polacze z synkiem
    for (auto w : G[v]){ // wybieram syna do polaczenia
        if (w == tata){continue;}
        long long odwrotnosc_mod = Odw((stany[w][0] + stany[w][2]), modulo);
        // pozostalych laczymy jakos albo z synkami albo opcja (izoluj/synkowie)
        // cerr << "odwrotnosc " << odwrotnosc_mod << "\n";
        if (odwrotnosc_mod < 0){
            odwrotnosc_mod = (odwrotnosc_mod + modulo) % modulo;
        }
        long long sposoby_pozostalych = (stan2 * odwrotnosc_mod)%modulo; // wszystkie sposoby bez tego dolaczonego
        // cerr << "sposoby pozostalych "<<sposoby_pozostalych << "\n";
        long long polacz = (stany[w][1]*sposoby_pozostalych)%modulo; // tego w lacze z tata
        if (polacz < 0){
            polacz = (polacz + modulo)%modulo;
        }
        // cerr << "polacz = "<<polacz << "\n";
        stan3 = (stan3 + polacz)%modulo;
    }
    long long stan1 = 1;
    for (auto w : G[v]){
        if (w == tata){continue;}
        stan1 = (stan1 * stany[w][0])%modulo;
    }
    stan1 = (stan1 + stan3)%modulo;
    // cerr << "stany " << stan1 << " " << stan2 << " " << stan3 << "\n";
    stany[v]={stan1, stan2, stan3};
}
void DFS(long long v, long long tata){
    // cerr << "v "<<v << " tata " << tata << "\n";
    for (auto w : G[v]){
        if (w != tata){
            DFS(w, v);
        }
    }
    Licz(v, tata);
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    long long n;
    cin >> n;
    stopnie.resize(n);
    G.resize(n);
    stany.resize(n);
    for (long long i = 0; i < n-1; i++){
        long long u, v;
        cin >> u >> v;
        u--;
        v--;
        stopnie[u]++;
        stopnie[v]++;
        G[u].push_back(v);
        G[v].push_back(u);
    }
    DFS(0, 0);
    // for (long long i = 0; i < n; i++){
    //     cerr << "v = "<<i+1 << "\n";
    //     cerr << stany[i][0] << " " << stany[i][1] << " " << stany[i][2] << "\n";
    // }
    cout << stany[0][0]%modulo << "\n";

}


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

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

template<int m>
struct modint {

	unsigned x;

	modint() : x(0) {}

	modint(long long arg) {
		arg %= m;
		if (arg < 0) {
			x = arg + m;
		} else {
			x = arg;
		}
	}

	modint& operator+= (const modint& other) {
		x += other.x;
		if (x >= m) {
			x -= m;
		}
		return *this;
	}

	modint& operator*= (const modint& other) {
		x = (x * 1ll * other.x) % m;
		return *this;
	}

	modint& operator-= (const modint& other) {
		x += m - other.x;
		if (x >= m) {
			x -= m;
		}
		return *this;
	}

	modint operator+ (const modint& other) const {
		modint tmp = *this;
		tmp += other;
		return tmp;
	}

	modint operator- (const modint& other) const {
		modint tmp = *this;
		tmp -= other;
		return tmp;
	}

	modint operator* (const modint& other) const {
		modint tmp = *this;
		tmp *= other;
		return tmp;
	}

	explicit operator int () const {
		return x;
	}

	modint& operator++ () {
		++x;
		if (x == m) {
			x = 0;
		}
		return *this;
	}

	modint& operator-- () {
		if (x == 0) {
			x = m-1;
		} else {
			--x;
		}
		return *this;
	}

	modint operator++ (int) {
		modint tmp = *this;
		++*this;
		return tmp;
	}

	modint operator-- (int) {
		modint tmp = *this;
		--*this;
		return tmp;
	}

	bool operator== (const modint& other) const {
		return x == other.x;
	}

	bool operator!= (const modint& other) const {
		return x != other.x;
	}

	template<class T>
	modint operator^ (T arg) const {
		if (arg == 0) {
			return 1;
		}
		if (arg == 1) {
			return x;
		}
		auto t = *this ^ (arg >> 1);
		t *= t;
		if (arg & 1) {
			t *= *this;
		}
		return t;
	}

	modint inv() const {
		return *this ^ (m-2);
	}
};

const int MOD = 998244353;
typedef modint<MOD> mint;

int n;
basic_string<int> e[300005];
int ch[300005];

mint ma[300005], un[300005];
mint gore[300005], dole[300005];

void dfs1(int x, int p) {
	un[x] = 1;
	gore[x] = 1;

	basic_string<mint> z, z_pref, z_suff, gore1;

	for (int y : e[x]) {
		if (y == p)
			continue;
		dfs1(y, x);
		un[x] *= dole[y] + un[y];
		gore[x] *= dole[y] * 2 + un[y];
		// dole
		z += un[y] + dole[y];
		gore1 += gore[y];
	}

	z_pref = z;
	z_suff = z;
	int m = z.size();
	if (m > 0) {
		z_pref[0] = 1;
		for (int i=0; i<m-1; i++)
			z_pref[i+1] = z_pref[i] * z[i];
		z_suff[m-1] = 1;
		for (int i=m-1; i>0; i--)
			z_suff[i-1] = z_suff[i] * z[i];
		for (int i=0; i<m; i++)
			dole[x] += gore1[i] * z_pref[i] * z_suff[i];
	}
}

void dfs0(int x, int p) {
	un[x] = 1;
	ma[x] = 0;

	basic_string<mint> z, z_pref, z_suff, un1;

	for (int y : e[x]) {
		if (y == p)
			continue;
		dfs0(y, x);
		un[x] *= ma[y] + un[y];
		z += ma[y] + un[y];
		un1 += un[y];
	}
	z_pref = z;
	z_suff = z;
	int m = z.size();
	if (m > 0) {
		z_pref[0] = 1;
		for (int i=0; i<m-1; i++)
			z_pref[i+1] = z_pref[i] * z[i];
		z_suff[m-1] = 1;
		for (int i=m-1; i>0; i--)
			z_suff[i-1] = z_suff[i] * z[i];
		for (int i=0; i<m; i++)
			ma[x] += un1[i] * z_pref[i] * z_suff[i];
	}

}

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

	cin >> n;
	for (int i=1; i<n; i++) {
		int u, v;
		cin >> u >> v;
		e[u] += v;
		e[v] += u;
	}

	dfs1(1, 1);
	cout << (int)(dole[1] + un[1]) << '\n';
}


#include<iostream>
using namespace std;
bool isPN(int);
int main()
{
    int n;
    cin>>n;
    while(!n%10)
        n=n/10;
    return isPN(n);
}
bool isPN(int num)
{
        int o = num;
        int tmp = 0;
        while(num != 0) {
                tmp *= 10;
                tmp += num % 10;
                num /= 10;
        }
        if (tmp == o) {
                return true;
        }
        return false;
}


#include<bits/stdc++.h>
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define pb push_back
#define mk make_pair
#define endl "\n"
#define ff first
#define ss second
#define mod 1000000007
using namespace std;
bool prime[1000000001];
vector<ll>us;
ll power(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod%mod;a=a*a%mod;}return res;}
void prim(ll n)
{
    memset(prime, true, sizeof(prime));

    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
}
int main()
{
    fastio;
    ll i,j,k,n,x;
    cin>>x>>n;
    n=n%mod;
    prim(x);
    ll mx=x;
    us.clear();
    for(i=2;i<=mx;i++)
    {
        if(mx%i==0&&prime[i])
        {
            us.pb(i);
        }
    }
    ll ans=1;
    ll num=n;

    for(i=0;i<us.size();i++)
    {    num=n;
         ll po=0;
         while(num!=0)
         {
             po=po+num/us[i];
             num=num/us[i];
         }
         ans=ans*power(us[i],po)%mod;
    }
    cout<<ans%mod<<endl;
    return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>

using namespace std;

vector<int> f(12);

int fact(int n){
  if(n==1) return 1;
  if(f[n] != -1) return f[n];
  f[n] = fact(n-1)*n;
  return f[n];
}

int main(){
  for(int i=0; i<f.size(); ++i)
    f[i] = -1;

  int N;
  cin >> N;

  long long num;
  cin >> num;

  long long prod = 1;

  for(int i=0; i<N; ++i){
    int digit = num % 10;
    prod *= fact(digit);
    num /= 10;
  }

  vector<int> digits;
  while(prod%7==0){
    prod /= fact(7);
    digits.push_back(7);
  }

  while(prod%5==0){
    prod /= fact(5);
    digits.push_back(5);
  }

  while(prod%3==0){
    prod /= fact(3);
    digits.push_back(3);
  }
  while(prod%2==0){
    prod /= 2;
    digits.push_back(2);
  }

  sort(digits.begin(), digits.end());

  for(int i=digits.size()-1; i>=0; --i)
    cout << digits[i];
  cout << endl;

}


#include<bits/stdc++.h>
#define int long long int
using namespace std;
int HashArray[800003];
int32_t main(){
    int n;
    cin>>n;
    int b[n];
    for(int i=0;i<n;i++){
        cin>>b[i];
    }
    int tot = 0;
    if(n>1){
        int newarray[n];
        for(int i=0;i<n;i++){
            newarray[i] = i-b[i];
        }
        int flag = 800003;
        for(int i=0;i<flag;i++){
            HashArray[i] = 0;
        }
        int key;
        for(int i=0;i<n;i++){
            if(newarray[i]>=0){
                key = 2*newarray[i];
            }
            else{
                key = (-2)*newarray[i]+1;
            }
            HashArray[key] += b[i];
            if(HashArray[key] > tot){
                tot = HashArray[key];
            }
        }
    }
    if(n==1){
        tot = b[0];
    }
    cout<<tot;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
long bs(vector<unsigned long long>a, unsigned long long x) {
long lo = 0,
hi = a.size() - 1;
while (lo <= hi) {
long m = (lo + hi) / 2;
if (a[m] == x) {
return m+1;
} else if (x < a[m]) {
hi = m - 1;
} else if (x > a[m]) {
lo = m + 1;
}
}
return 0;
}
int main()
{
    long k;
    unsigned long long n;
    cin>>n>>k;
    std::vector<unsigned long long>a; ;
    a.push_back(k);
    for(long i=1;i<k-1;i++)
    {
        a.push_back(a[i-1]+(k-i)-1);
    }
    if(bs(a,n)==0)cout<<-1;
    else cout<<bs(a,n);
}


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

#define int long long
#define hash salam
typedef pair <int, int> pii;
const int maxn = 1005, maxs = 25005, mod = 1e9 + 7, M = 1e15 + 37, b = 17;
vector <int> compress;
int d, sz;
bool F[maxs];
int dp[52][maxs], chiz[maxs][10], hash[maxn][maxn];
unordered_map <int, pii> MM;

inline string DEC(string s) {
	int ptr = (int)s.size() - 1;
	while (s[ptr] == 0) {
		s[ptr] = 9;
		ptr--;
	}
	s[ptr]--;
	return s;
}

inline void makedp(int i, vector <int> D) {
	for (int j = 0; j < sz; j++) dp[i][j] = 0;
	for (int j = 0; j < sz; j++) {
		for (auto k: D) {
			if (!F[chiz[j][k]]) continue;
			dp[i][chiz[j][k]] += dp[i - 1][j];
			if (dp[i][chiz[j][k]] >= mod)
				dp[i][chiz[j][k]] -= mod;
		}
	}
//	for (auto d: D) cout << d << "  ";
//	cout << endl;
//	for (int j = 0; j < sz; j++) cout << i << ' ' << compress[j] << ' ' << dp[i][j] << endl;
}

inline int S(string s) {
	int ans = 0;
	for (int i = 0; i < s.size(); i++) {
		ans = (ans * 10 + s[i]) % mod;
	}
//	cout << "ALEIK" << endl;
	return ans;
}

inline int get(string s) {
//	cout << s << endl;
//	for (int i = 0; i < 2; i++) cout << (char)(s[i] + '0');
//	cout << endl;
	int ans = 0;
	dp[0][0] = 1;
	for (int i = 0; i < d; i++) {
		if (i) {
			makedp(i, {s[i - 1]});
		}
		vector <int> V;
		for (int j = 0; j < s[i]; j++) {
			V.push_back(j);
		}
		makedp(i + 1, V);
		for (int j = i + 2; j <= d; j++) makedp(j, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9});
		for (int j = 0; j < sz; j++) {
			ans += dp[d][j];
			if (ans >= mod)
				ans -= mod;
		}
	}
//	cout << "SALAM" << endl;
	makedp(d, {s[d - 1]});
	for (int i = 0; i < sz; i++) {
//		cout << "SALAM" << endl;
		ans += dp[d][i];
		if (ans >= mod)
			ans -= mod;
	}
	return (S(s) - ans + mod) % mod;
}

int32_t main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s, x, y;
	cin >> s >> x >> y;
	int n = s.size();
	d = x.size();
	for (int i = 0; i < n; i++) s[i] -= '0';
	for (int i = 0; i < d; i++) {
		x[i] -= '0';
		y[i] -= '0';
	}
	x = DEC(x);
	for (int l = 0; l < n; l++) {
		hash[l][l] = s[l] + 1;
		compress.push_back(hash[l][l]);
		MM[hash[l][l]] = pii(l, l);
		for (int r = l + 1; r < min(n, l + 25); r++) {
			hash[l][r] = (hash[l][r - 1] * b + (s[r] + 1)) % M;
			compress.push_back(hash[l][r]);
			MM[hash[l][r]] = pii(l, r);
		}
	}
	compress.push_back(0);
	sort(compress.begin(), compress.end());
	compress.resize(unique(compress.begin(), compress.end()) - compress.begin());
	sz = compress.size();
	MM[0] = pii(0, 0);
	for (int i = 0; i < sz; i++) {
		pii P = MM[compress[i]];
		int t = P.second - P.first + 1;
		if (t >= d / 2) F[i] = 0;
		else F[i] = 1;
		F[0] = 1;
		for (int j = 0; j < 10; j++) {
			int l = P.first, r = P.second;
			for (l = max(l, r - 24); l <= r + 1; l++) {
				int nh = (hash[l][r] * b + (j + 1)) % M;
				if (!i) {
					nh = j + 1;
//					cout << nh << endl;
				}
				if (MM.find(nh) != MM.end()) {
					chiz[i][j] = lower_bound(compress.begin(), compress.end(), nh) - compress.begin();
				break;
				}
			}
//			cout << compress[i] << ' ' << j << ' ' << compress[chiz[i][j]] << endl;
		}
//		cout << compress[i] << ' ' << F[i] << endl;
	}
	cout << (get(y) - get(x) + mod) % mod;
}


#include <bits/stdc++.h>
#ifdef DBP
#define deb(...) fprintf(stderr,__VA_ARGS__)
#else
#define deb(...) 0
#endif
#define fore(x,a,b) for(int x=a, qwerty=b; x<qwerty; x++)
#define ALL(a) (a).begin(),(a).end()
#define SZ(a) ((int)(a).size())
#define pb push_back
#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define fst first
#define snd second
#define mset(a,v) memset((a),(v),sizeof(a))
using namespace std;
typedef long long ll;

const ll MOD=1LL<<41;
vector<int> kmppre(string& t){
	vector<int> r(t.size()+1);r[0]=-1;
	int j=-1;
	fore(i,0,t.size()){
		while(j>=0&&t[i]!=t[j])j=r[j];
		r[i+1]=++j;
	}
	return r;
}

const int N=10005, ALPHA=2;
int n,m,nxt[ALPHA][N];
string s;
vector<int> r;
int can[N];
ll add(ll a, ll b){a+=b;if(a>=MOD)a-=MOD;return a;}
ll mult(ll a, ll b){return (a*b)%MOD;}

ll be(ll b, ll e){
    ll r=1;
    while(e)if(e&1)r=(r*b)%MOD,e^=1;else b=(b*b)%MOD,e>>=1;
    return r;
}

ll dp[N][N];
ll f(int i, int j){
    ll &v=dp[i][j];
    if(v!=-1)return v;
    if(i==0)return v=can[j];
    if(j==n)return v=0;
    v=0;
    v=add(v,f(i-1,nxt[0][j]));
    v=add(v,f(i-1,nxt[1][j]));
    return v;
}

int main(){FIN;mset(dp,-1);
    cin>>m>>s;n=SZ(s);
    r=kmppre(s);

	fore(c,'0','1'+1)fore(x,0,n){
		int j=x;
		while(j>=0&&c!=s[j])j=r[j];
		nxt[c-'0'][x]=++j;
	}

    fore(x,0,n){
        int j=x;
        can[x]=1;
        fore(y,0,n-1){
			j=nxt[s[y]-'0'][j];
			if(j==n){can[x]=0;break;}
        }
    }

    ll ans=0;
    fore(x,0,m){
        if(x+n<=m){
            ll cnt=f(x,0);
            ans=add(ans, mult(cnt,be(2,m-(x+n))));
        }else{
            int j=0;
            for(int y=n-(x+n-m); y<n; y++)j=nxt[s[y]-'0'][j];
            ll cnt=f(m-n,j);
            ans=add(ans,cnt);
        }
    }

    cout<<ans<<"\n";
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<map>
#include<set>
using namespace std;
long long ans;
int n,m;
string s;
map<string,int>Id;
set<string>P;
vector<string>S;
long long f[41][1610][41][2];
void work(int len,int A,int B,int O,char c)
{
	string str=S[A]+c;
	int toA=A;
	if(str.length()==len+1&&Id.count(str))
		toA=Id[str];
	str=S[B]+c;
	while(P.find(str)==P.end())
		str=str.substr(1,str.length()-1);
	int toB=str.length();
	int toO=O;
	if(toB==m)toO=1;
	f[len+1][toA][toB][toO]+=f[len][A][B][O];
	return ;
}
void solve(int len,int A,int B,int O)
{
	if(!f[len][A][B][O])
		return ;
	if(len==n)
	{
		if(O)ans+=f[len][A][B][O];
		else{
			string str=S[B]+S[A];
			if(str.find(s)!=string::npos)
				ans+=f[len][A][B][O];
		}
	}
	work(len,A,B,O,'0');
	work(len,A,B,O,'1');
	return ;
}
void Ins(string str)
{
	if(Id.count(str))
		return ;
	Id[str]=S.size();
	S.push_back(str);
	return ;
}
int main()
{
	cin>>n>>s;
	m=s.length();
	string str="";
	Ins(str);P.insert(str);
	for(int i=0;i<m;i++)
	{
		str+=s[i];
		P.insert(str);
	}
	for(int i=0;i<m;i++)
	{
		str="";
		for(int j=i;j<m;j++)
		{
			str+=s[j];
			Ins(str);
		}
	}
	int N=S.size();
	f[0][0][0][0]=1;
	for(int len=0;len<=n;len++)
		for(int A=0;A<N;A++)
			for(int B=0;B<=m;B++)
				for(int O=0;O<2;O++)
					solve(len,A,B,O);
	printf("%lld\n",ans);
	return 0;
}


#include <iostream>
#include <cmath>
using namespace std;
#define f(x) (c1 + c2*(x-1)*(x-1))

int n, c1, c2;
int solve(int i) {
    int t1 = ceil(n/i);
    int res = (i-1)*f(t1);
    return res + f(n-(t1*(i-1)));
}

int main() {
    char t;
    cin >> n >> c1 >> c2;
    int p = 0, r = 0, i;
    for (i = 0; i < n; i++) {
        cin >> t;
        (t == '1') ? p++ : r++;
    }

    int lo = 1, hi = p;
    while (lo < hi) {
        int p1 = (lo+hi)/3, p2 = 2*(lo+hi)/3;
        if (p1 < lo) p1 = lo;
        int s1 = solve(p1), s2 = solve(p2);
        if (s1 == s2) lo = p1, hi = p2;
        else if (s1 > s2) lo = p1+1;
        else hi = p2-1;
    }
    cout << solve(lo) << endl;
}


#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
long long n;
long long miin;
long long x,y,k,l;
long long t[100010];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin>>n>>k>>l;
    x=0;
    y=0;
    for (int i=0;i<n;i++)
    {
        char a;
        cin>>a;
        if (a=='0')
            x++;
        else
            y++;
    }
    for (int i=1;i<y+1;i++)
    {
        long long j=(n-i)%i;
        t[i]=i*k+l*(pow((n-i)/i,2)*(i-j)+pow((n-i)/i+1,2)*j);
    }
    miin=t[1];
    for (int i=2;i<y+1;i++)
        miin=min(miin,t[i]);
    cout<<miin;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long x,y,x2,y2,R;
    cin>>R>>x>>y>>x2>>y2;
    double dis=(x-x2)*(x-x2)+(y-y2)*(y-y2);
    dis=sqrt(dis);
    int ans=ceil(dis/(2.0*R));
    return ans;

}


/* LOL \(0-0\) */
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <set>
#include <cmath>
#include <cstring>
#include <stdio.h>
#include <string.h>
#include <sstream>
#include <stdlib.h>
#include <vector>
#include <iomanip>
#include <ctime>
#include <deque>
#include <bitset>
#include <functional>
#include <numeric>
#include <utility>
#include <cstdlib>
#include <cassert>

#define nl "\n"
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define p_un(a) ((void)a)
#define p_st(a) string(a)
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define naj ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define NL cout << endl;
#define sqr(x) (sqrt(x) * 1LL)
#define pcnt(i) __builtin_popcount(i)
#define lcm(a,b) (a * b) / __gcd(a, b)
#define E 2.718281828459045
#define PI 3.141592653589793
#define up_b upper_bound
#define low_b lower_bound
#define FILE_NAME "A"
#define show(x) cout << (#x) << ": " << x << endl

using namespace std;

typedef long long llong;
typedef long double ldouble;
typedef unsigned long long ullong;
typedef vector <llong> vl;
typedef vector <bool> vb;
typedef vector <char> vc;
typedef vector <int> vi;
typedef vector <string> vs;
typedef pair <llong, llong> pll;
typedef map <llong, llong> mll;
typedef set <llong> sl;
typedef set <char> sc;
typedef map <string, llong> msl;
typedef map <string, bool> msb;
typedef map <char, llong> mcl;
typedef map <string, string> mss;

const llong MXN = 1e6 + 1;
const llong MOD = 1e9 + 7;

const llong INF = 1e18;
const ldouble EPS = 1e-9;

//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[]={-1,-1,+0,+1,+1,+0}; int dy[]={-1,+1,+2,+1,-1,-2}; //Hexagonal Direction

int a[MXN], b[MXN];

main() {

    naj;
#ifdef LOL
    freopen(FILE_NAME".in", "r", stdin);
    freopen(FILE_NAME".out", "w", stdout);
#endif
    int n, m, mn = MOD, mg = MOD, ans = MOD;
    cin >> n >> m;
    for(int i = 1; i <= n; i++) {
        cin >> a[i];
        mn = min(mn, a[i]);
    }
    for(int i = 1; i <= m; i++) {
        cin >> b[i];
        mg = min(mg, b[i]);
        for(int j = 1; j <= n; j++) {
            if(b[i] == a[j]) ans = min(ans, a[j]);
        }
    }
    if(ans == MOD) cout << ans;
    else if(mn == mg) cout << mn;
    else cout << min(mn, mg) << max(mn, mg);
    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int main()
{
	int a,ta,b,tb;
	char s[10];
	scanf("%d %d",&a,&ta);
	scanf("%d %d",&b,&tb);
	scanf("%s",s);
	int Abegin = ((s[0]-'0')*10 + s[1]-'0')*60 + 10*(s[3]-'0')+s[4]-'0';
	int Aend = Abegin + ta;
	int start = 300,end = 23*60+59;
	int ans=0;

	for(int i=0;;++i)
	{
		if((Abegin<start+i*b+tb) && (Aend>start+i*b) && (start+i*b<=end) )ans++;
	}

	printf("%d\n",ans);
	return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <fstream>
#include <cstdio>
typedef long long ll;
typedef double d;
typedef unsigned long long ull;
using namespace std;
ll r1,c1,r2,c2,minn=10000000;
ll arr[9][9]= {1}, arrx[4]= {0,0,1,-1},arry[4]= {1,-1,0,0};
void king (ll y,ll x,ll counter)
{
    if(x<0||y<0||x>=8||y>=8)
        return ;
    if(r2-1==y&&c2-1==x)
        minn=min(counter,minn);
    if(arr[y][x]==1)
    {
        for(int i=0; i<4; i++)
        {
            arr[y][x]=0;
            king(y+arry[i],x+arrx[i],counter+1);
            arr[y][x]=1;
        }
        arr[y][x]=0;
    }
    return ;
}
int main()
{
    cin.tie(0);
    std::ios::sync_with_stdio(false);
    cin >> r1>>c1>>r2>>c2;
    if(r1==r2&&c1==c2)
    {
        cout << 0<< " ";
    }
    else if (c1==c2||r2==r1)
    {
        cout << 1<<" " ;
    }
    else
    {
        cout << 2 << " ";
    }
    if(r1==r2&&c1==c2)
        cout <<0<<" " ;
    else if(abs(r1-r2)==abs(c1-c2))
        cout << 1<< " " ;
    else if((r1%2&&c1%2&&r2%2==0&&c2%2==0)||(r1%2&&c1%2&&r2%2&&c2%2)||(r1%2==0&&c1%2==0&&r2%2==0&&c2%2==0)||(r1%2==0&&c1%2&&r2%2==0&& c2%2)||(r1%2&&c1%2==0&&r2%2&&c2%2==0)||(r1%2==0&&c1%2==0&&r2%2&&c2%2)||(r1%2&&c1%2==0&&r2%2&&c2%2==0)||(r2%2&&c2%2==0&&r1%2&&c1%2==0))
        cout << 2 << " " ;
    else
    {
        cout << 0 << " ";
    }

    if(abs(r1-r2)==abs(c2-c1))
    {
        cout << abs(r1-r2)<< endl;
    }
    else if(r1==r2&&c1==c2)
    {
        cout << 0<< endl;
    }
    else if(c1==c2)
    {
        cout << abs(r1-r2)<< endl;
    }
    else if(r1==r2)
    {
        cout << abs(c1-c2)<< endl;
    }
    else
    {
        ll x=c1,y=r1,counter1=0,counter2=0;
        while (abs(c2-x)!=abs(y-r2))
        {
            counter2++;
            x++;
        }
        x=c1;
        y=r1;
         while (abs(c2-x)!=abs(y-r2))
        {
            counter1++;
            x--;
        }
        cout << min(counter1+abs(r1-r2),counter2+abs(r1-r2))<< endl;
    }
    return 0;
}


//#pragma comment(linker, "/STACK:1024000000,1024000000")
/* vim: set fdm=marker */
//{{{
#define __ return
int ATTENTION() {
	/* pls IGNORE this function and go down and HACK me
	 * read this AFTER contest
	 * this function is empty and it will not be called !
	 */

	http://codeforces.com/group/Pmz2A2x7ES
	/* I created a group there.
	 * I hope with the group, people can finish
	 * past contests, which is important for
	 * increasing rating.
	 * I am still getting familiar with this function.
	 */
	 __ 0;
}
// deprecated because mac doesn't support this...
/* #include <bits/stdc++.h> */
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <iomanip>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <ctime>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int iinf = 0x7fffffff;
const ll linf = ~(1LL<<63);
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef map<ll, int> mli;
typedef map<ll, ll> mll;
template<typename T>
inline T gcd(T a, T b) {
	if(a < 0) return gcd(-a, b);
	if(b < 0) return gcd( a,-b);
	if(a < b) return gcd(b, a);
	if(b == 0) return a;
	return gcd(b, a%b);
}

ll qpow(ll a, ll n, ll mod) {
	a %= mod;
	ll ans = 1LL;
	while(n) {
		if(n & 1) ans = (ans*a % mod);
		a = (a*a % mod);
		n >>= 1;
	}
	return ans;
}

inline ll rev(ll a, ll p) {
	return qpow(a, p - 2, p);
}

#define all(v) v.begin(), v.end()
#define sz(v) v.size()
#define rep(x, st, en) for(int x = st; x < en; x++)
#define rer(x, st, en) for(int x = st; x >= en; x--)
#define pb push_back
#define mp make_pair
#define dbgm(msg, var) cerr<<#msg<<" "<<#var<<" = "<<var<<endl;
#define dbg(var) cerr<<#var<<" = "<<var<<endl;
#define X first
#define Y second
// build prefix sum
template<typename T>
inline void BPS(T* DST, T* SRC, int N, int s = 0) {
	DST[s] = SRC[s];
	rep(i, 1, N) DST[s + i] = DST[s + i - 1] + SRC[s + i];
}
inline int in() { int x; cin>>x; return x; }
#ifdef ALNDBG
namespace alndbg {
	clock_t s, e;
}
#endif

inline void tic() {
#ifdef ALNDBG
	alndbg::s = clock();
#endif
}

inline void toc() {
#ifdef ALNDBG
	alndbg::e = clock();
	cerr<<1000.0 * (alndbg::e - alndbg::s) / CLOCKS_PER_SEC<<" ms"<<endl;
#endif
}

//}}}

// -------------------- Spliters ------------------------
// BFS求最短路小心vis可能访问过
const ll mod   = 998244353ll;
const int maxn = 300005;

vector<int> E[maxn];

int n;

ll dp[maxn][3];

// dp[i][0] = sum(max(dp[sub[i]][0/1]))
// dp[i][1]

void addedge(int u, int v) {
  E[u].pb(v);
  E[v].pb(u);
}

void dfs(int u, int fa=-1) {
  dp[u][0] = 1LL;
  dp[u][1] = 1LL;
  dp[u][2] = 0;
  for(auto v : E[u]) {
    if(v == fa) continue;
    dfs(v, u);
    dp[u][1] = (dp[u][1] * ( (dp[v][0] + dp[v][2]) % mod ) % mod;
    dp[u][0] = (dp[u][0] * dp[v][0]) % mod;
  }
  for(auto v : E[u]) {
    if(v == fa) continue;
    dp[u][2] = (dp[u][2] + dp[v][1] * dp[u][1] % mod * rev(dp[v][0] + dp[v][2], mod) % mod) % mod;
  }
  dp[u][0] = (dp[u][0] + dp[u][2]) % mod;
}

void solve() {
  dfs(1);
  ll ans = dp[1][0];
  cout<<ans<<endl;
}

int main() {
  cin>>n;
  rep(i,0,n-1) {
    int u, v;
    cin>>u>>v;
    addedge(u, v);
  }
  solve();
	return 0;
}
// --USE C++11
// *-USE O2


#include <iostream>
#include <queue>
#include <cstring>
using namespace std;
struct Edge {
	int to,next;
}bus[606060];
int st[303030],z,fa[303030];
long long f[303030][3];
const int mod = 998244353;
inline void AddE(int from,int to) {
	bus[++z].next = st[from];
	st[from] = z;
	bus[z].to = to;
}
inline void dfs(int now) {
	f[now][0] = 0;//有下匹配
	f[now][1] = 0;//匹配
	f[now][2] = 1;//没有下面的空
	for (int i = st[now];i;i = bus[i].next) {
		int s = bus[i].to;
		if (s == fa[now])
			continue;
		fa[s] = now;
		dfs(s);
		f[now][1] = (f[now][1]*(f[s][2]+f[s][1]*2)%mod+(f[now][2]+f[now][0])*(f[s][0]+f[s][2]))%mod;
		f[now][0] = (f[now][0]*(f[s][2]+f[s][1]*2)%mod+f[now][2]*f[s][1])%mod;
		f[now][2] = f[now][2]*(f[s][2]+f[s][1])%mod;
	}
//	cout << now << " " << f[now][0] << " " << f[now][1] << " " << f[now][2] << endl;
}
int main() {
	ios::sync_with_stdio(false);
	int n,aa,bb;
	cin >> n;
	for (int i = 1;i < n; i++) {
		cin >> aa >> bb;
		AddE(aa,bb);
		AddE(bb,aa);
	}
	dfs(1);
	cout << f[1][2]+f[1][1] << endl;
	return 0;
}


//Thank you for supporting FastLine, (WorldWeb or james1990), (KNaga_KZ or KNaga)

#include <bits/stdc++.h>
#define off  exit( 0 )
#define cn   continue
#define rt   return
#define sc   scanf
#define pr   printf
#define pb   push_back
#define pf   push_front
#define p_f  pop_front
#define p_b  pop_back
#define ff   first
#define ss   second
#define vec  vector
#define gcd  __gcd
#define pi   acos( -1 )
#define ll   long long
#define ld   long double
#define pdd  pair < ld, ld >
#define pll  pair < ll, ll >
#define pii  pair < int, int >
#define rep( a, b, c, d )  for( int a = b; a <= c; a += d )
#define rvv( a, b, c, d )  for( int a = b; a >= c; a -= d )
#define en                 printf( "\n" )
#define sqr( a )           a * a
#define all( c )           c.begin(), c.end()
#define srt( c )           sort( all( c ) )
#define rev( c )           reverse( all( c ) )
#define srtr( c )          sort( c.rbegin(), c.rend() )
#define numcounts          __builtin_popcount
#define mxn( x, y, z )     max( x, min( y, z ) )
#define mnx( x, y, z )     min( x, max( y, z ) )
#define rep( i, x, y ) for( int i = (x); i <= (y); i ++ )
#define dep( i, x, y ) for( int i = (x); i >= (y); i -- )
#define TIME() if(QQQQ)printf("My Time: %.3lfms\n", (double)clock() / CLOCKS_PER_SEC);
bool QQQQ;
#define see(x)  if(QQQQ)cout << x << " ";
#define sees(x) if(QQQQ)cout << x << endl;
#define N       105
#define NN      10005
#define M       998244353
#define I       1000000000000000000
const int dx[ ] = { 1, -1, 0, 0 };
const int dy[ ] = { 0, 0, -1, 1 };
using namespace std;

ll ttt = 1;
ll n, ans, a[N], b[N], c[N];
vector < ll > g[N];

void dfs( ll v )
{
    a[v] = c[v] = 1;
    for( ll to: g[v] )
    {
        if( !a[to] )
        {
            dfs( to );
            b[v] = ( ((a[v] * a[to]) % M) + ((b[v] * (b[to] + c[to])) % M) ) % M;
            c[v] = (c[v] * c[to]) % M;
            a[v] = (a[v] * (b[to] + c[to])) % M;
        }
    }
    c[v] = (c[v] + b[v]) % M;
}

void solve()
{
    sc( "%I64d", &n );
    for( int i = 1; i < n; i ++ )
    {
        int x, y;
        sc( "%d%d", &x, &y );
        g[x].pb(y);
        g[y].pb(x);
    }
    dfs(1);
    ans = 1;
    for( ll i: g[1] )ans = (ans * c[i]) % M;
    ans = (ans + b[1]) % M;
    pr( "%I64d", ans );
}
int main()
{
    QQQQ = 0;
    //sc( "%I64d", &ttt );
    for( int i = 1; i <= ttt; i ++ )
        solve();
    TIME();
}

/*
1
5 5
1 2 3 4 5
3 4 5 1 2
*/


#include <string>
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>
#include <fstream>
#include <cassert>

using namespace std;

                                                                                #define int ll
const bool online_judge =
#ifdef ONLINE_JUDGE
  true
#else
  false
#endif
  ;

typedef long long ll;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;

typedef tuple<int,int> int2;
typedef tuple<int,int,int> int3;
typedef tuple<int,int,int,int> int4;

#define all(v)  (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define pb push_back
#define eb emplace_back
#define SZ(a) ((int)((a).size()))
#define rep(i,n) for(int i = 0; i < n; i++)
#define rep2(i,n) for(int i = 1; i <= n; i++)
#define rep3(i,n) for(int i = n-1; i >= 0; i--)
#define tag(i,v) rep(i,SZ(v))
#define _trace(x) #x << " = " << (x)
#define trace(x)  { if(!online_judge) cerr << _trace(x) << endl; }
#define trace2(x,y) { if(!online_judge) cerr << _trace(x) << " " << _trace(y) << endl; }
#define trace3(x,y,z) { if(!online_judge) cerr << _trace(x) << " " << _trace(y) << " " << _trace(z) << endl; }
#define tracev(x) { if(!online_judge) { cerr << #x << " = "; tag(__i, x) { cerr << x[__i] << ","; } cerr << endl; } }
#define fst get<0>
#define snd get<1>
#define thd get<2>
#define divup(x,y) ((x)/(y)+(0<((x)%(y))))
#define mp make_tuple
#define range(x,a,b) ((x) >= (a) && (x) <= (b))

const int inf = 1LL << 60;
int toInt(string s) {int res; stringstream ss; ss<<s; ss>>res; return res; }
string toString(int n) { stringstream ss; ss<<n; return ss.str(); }

int fact(int n){
  if(n <= 1)
    return n;
  return n*fact(n-1);
}

vi lucky;

void dfs(int n, int k){
  lucky.pb(n);
  if(k < 11){
    dfs(n*10+4,k+1);
    dfs(n*10+7,k+1);
  }
}

bool is_lucky(int n){
  return binary_search(all(lucky), n);
}

void run() {

  /* entry point */
  int n,k;
  cin >> n >> k;

  k--;

  if(n <= 15 && fact(n) <= k) {
    cout << -1 << endl;
    return;
  }

  vi v;
  rep(j,n)
    v.pb(j+1);

  while(k > 100000){
    int i = 0;
    while(fact(i+1) < k) i++;

    k -= fact(i);

    if(i){
      vi tmp;
      rep(j,i){
	tmp.pb(v[SZ(v)-1]);
	v.pop_back();
      }

      int tmp2 = v[SZ(v)-1];
      v.pop_back();
      sort(all(tmp));
      auto it = upper_bound(all(tmp), tmp2);
      v.pb(*it);
      tmp.erase(it);
      tmp.insert(lower_bound(all(tmp), tmp2), tmp2);

      tag(j,tmp)
	v.pb(tmp[j]);
    }
  }

  while(k--) next_permutation(all(v));

  tracev(v);

  dfs(4,0);
  dfs(7,0);
  sort(all(lucky));

  int ans = 0;
  tag(i,lucky){
    if(lucky[i] > n)
      break;
    if(is_lucky(v[lucky[i]-1]))
      ans++;
  }

  cout << ans << endl;

}

#undef int

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

  #if 0
  if(online_judge){
    freopen("input.txt", "rt", stdin);
    freopen("output.txt", "wt", stdout);
  }
  #endif

  run();

  return 0;

}


#include<bits/stdc++.h>
using namespace std;
int main(){
int n,m,a,b;
float f=b/m;
cin>>n>>m>>a>>b;
if(f>a){
    cout<<n*a;
    return 0;
} else if(m>n && b<(n*a)){
    cout<<b;
    return 0;
}
int left = (((n%m)*a) > ((n%m)*b)) ? ((n%m)*b): ((n%m)*a);
cout<<(((n/m)*b)+left);
return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (auto i = (a); i < (b); i++)

int main()
{
    int a[3],temp=0;
    FOR(i, 0, 3)
    {
        cin>>a[i];
    }
    if(a[0]==a[1] && a[1]==a[2])
    {
        cout<<"0";
        exit (1);
    }
    int k = *std::max_element(a,a+3);
    FOR(i, 0, 3)
    {
        if(k!=a[i])
            temp+=a[i];
    }
    if(temp>k)
        cout<<"0";
    else
    	cout<<(k-temp)+1;

}


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

using namespace std;

int main()
{int a,b,c;
int s=0;
int s1=0;
int s2=0;
bool ok=true;
bool ok1=true;
bool ok2=true;
scanf("%d","%d","%d",&a,&b,&c);
 while(ok==true)
 {  if ((a+b)==c){
        s=s+1;
        ok==true;
    }
    if((a+b)<c)
   {s=s+1;
    ok=true;
   }
  else{
    ok=false;
   }
 }
 while(ok1==true)
 {if((a+c)==b){
     s1=s1+1;
     ok1=true;}
     if((a+c)<b)
   {s1=s1+1;
    ok1=true;
   }
  else{
    ok1=false;
   }
 }
 while(ok2==true){
    if ((c+b)==a){
        s2=s2+1;
        ok2==true;
    }
    if((c+b)<a)
   {s2=s2+1;
    ok2=true;
   }
  else{
    ok2=false;
   }
 }
printf("%d",s+s1+s2);

    return 0;
}


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

using namespace std;
using namespace __gnu_pbds;
template <class T> using Tree = tree<T, null_type, less<T>,
    rb_tree_tag, tree_order_statistics_node_update>;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using db = double;
using str = string; // yay python!

using pi = pair<int,int>;
using pl = pair<ll,ll>;
using pd = pair<db,db>;

using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<ll>;
using vd = vector<db>;
using vs = vector<str>;
using vpi = vector<pi>;
using vpl = vector<pl>;
using vpd = vector<pd>;

#define tcT template<class T
// ^ lol this makes everything look weird but I'll try it
tcT> using V = vector<T>;
tcT, size_t SZ> using AR = array<T,SZ>;

// pairs
#define mp make_pair
#define f first
#define s second

// vectors
#define sz(x) (int)(x).size()
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define sor(x) sort(all(x))
#define rsz resize
#define ins insert
#define ft front()
#define bk back()
#define pf push_front
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound

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

const int MOD = 998244353;
const int MX = 2e5+5;
const ll INF = 1e18; // not too close to LLONG_MAX
const int IINF = 1e9;
const ld PI = acos((ld)-1);
const int xd[4] = {1,0,-1,0}, yd[4] = {0,1,0,-1}; // for every grid problem!!
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());

// helper funcs
constexpr int pct(int x) { return __builtin_popcount(x); } // # of bits set
constexpr int bits(int x) { return 31-__builtin_clz(x); } // floor(log2(x))
ll cdiv(ll a, ll b) { return a/b+((a^b)>0&&a%b); } // divide a by b rounded up
ll fdiv(ll a, ll b) { return a/b-((a^b)<0&&a%b); } // divide a by b rounded down

tcT> bool ckmin(T& a, const T& b) {
    return b < a ? a = b, 1 : 0; } // set a = min(a,b)
tcT> bool ckmax(T& a, const T& b) {
    return a < b ? a = b, 1 : 0; }

#define tcTU tcT, class U
tcTU> T fstTrue(T lo, T hi, U f) {
    hi ++; assert(lo <= hi); // assuming f is increasing
    while (lo < hi) { // find first index such that f is true
        T mid = lo+(hi-lo)/2;
        f(mid) ? hi = mid : lo = mid+1;
    }
    return lo;
}
tcTU> T lstTrue(T lo, T hi, U f) {
    lo --; assert(lo <= hi); // assuming f is decreasing
    while (lo < hi) { // find first index such that f is true
        T mid = lo+(hi-lo+1)/2;
        f(mid) ? lo = mid : hi = mid-1;
    }
    return lo;
}
tcT> void remDup(vector<T>& v) { // sort and remove duplicates
    sort(all(v)); v.erase(unique(all(v)),end(v)); }
tcTU> void erase(T& t, const U& u) { // don't erase
    auto it = t.find(u); assert(it != end(t));
    t.erase(u); } // element that doesn't exist from (multi)set

// INPUT
#define tcTUU tcT, class ...U
tcT> void re(complex<T>& c);
tcTU> void re(pair<T,U>& p);
tcT> void re(vector<T>& v);
tcT, size_t SZ> void re(AR<T,SZ>& a);

tcT> void re(T& x) { cin >> x; }
void re(db& d) { str t; re(t); d = stod(t); }
void re(ld& d) { str t; re(t); d = stold(t); }
tcTUU> void re(T& t, U&... u) { re(t); re(u...); }

tcT> void re(complex<T>& c) { T a,b; re(a,b); c = {a,b}; }
tcTU> void re(pair<T,U>& p) { re(p.f,p.s); }
tcT> void re(vector<T>& x) { trav(a,x) re(a); }
tcT, size_t SZ> void re(AR<T,SZ>& x) { trav(a,x) re(a); }

// TO_STRING
#define ts to_string
str ts(char c) { return str(1,c); }
str ts(const char* s) { return (str)s; }
str ts(str s) { return s; }
str ts(bool b) {
    #ifdef LOCAL
        return b ? "true" : "false";
    #else
        return ts((int)b);
    #endif
}
tcT> str ts(complex<T> c) {
    stringstream ss; ss << c; return ss.str(); }
str ts(vector<bool> v) {
    str res = "{"; F0R(i,sz(v)) res += char('0'+v[i]);
    res += "}"; return res; }
template<size_t SZ> str ts(bitset<SZ> b) {
    str res = ""; F0R(i,SZ) res += char('0'+b[i]);
    return res; }
tcTU> str ts(pair<T,U> p);
tcT> str ts(T v) { // containers with begin(), end()
    #ifdef LOCAL
        bool fst = 1; str res = "{";
        for (const auto& x: v) {
            if (!fst) res += ", ";
            fst = 0; res += ts(x);
        }
        res += "}"; return res;
    #else
        bool fst = 1; str res = "";
        for (const auto& x: v) {
            if (!fst) res += " ";
            fst = 0; res += ts(x);
        }
        return res;

    #endif
}
tcTU> str ts(pair<T,U> p) {
    #ifdef LOCAL
        return "("+ts(p.f)+", "+ts(p.s)+")";
    #else
        return ts(p.f)+" "+ts(p.s);
    #endif
}

// OUTPUT
tcT> void pr(T x) { cout << ts(x); }
tcTUU> void pr(const T& t, const U&... u) {
    pr(t); pr(u...); }
void ps() { pr("\n"); } // print w/ spaces
tcTUU> void ps(const T& t, const U&... u) {
    pr(t); if (sizeof...(u)) pr(" "); ps(u...); }

// DEBUG
void DBG() { cerr << "]" << endl; }
tcTUU> void DBG(const T& t, const U&... u) {
    cerr << ts(t); if (sizeof...(u)) cerr << ", ";
    DBG(u...); }
#ifdef LOCAL // compile with -DLOCAL, chk -> fake assert
    #define dbg(...) cerr << "Line(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
    #define chk(...) if (!(__VA_ARGS__)) cerr << "Line(" << __LINE__ << ") -> function(" \
         << __FUNCTION__  << ") -> CHK FAILED: (" << #__VA_ARGS__ << ")" << "\n", exit(0);
#else
    #define dbg(...) 0
    #define chk(...) 0
#endif

// FILE I/O
void setIn(str s) { freopen(s.c_str(),"r",stdin); }
void setOut(str s) { freopen(s.c_str(),"w",stdout); }
void unsyncIO() { cin.tie(0)->sync_with_stdio(0); }
void setIO(str s = "") {
    unsyncIO();
    // cin.exceptions(cin.failbit);
    // throws exception when do smth illegal
    // ex. try to read letter into int
    if (sz(s)) { setIn(s+".in"), setOut(s+".out"); } // for USACO
}

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

int main(){
    setIO();
    // you should actually read the stuff at the bottom
}

/* stuff you should look for
    * int overflow, array bounds
    * special cases (n=1?)
    * do smth instead of nothing and stay organized
    * WRITE STUFF DOWN
    * DON'T GET STUCK ON ONE APPROACH
*/


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

deque<int> s;
deque<int>::iterator it;

int main() {
    int n;
    cin>>n;
    for(int i=0; i<n; i++){
        int k=1;
        while(!s.empty()&&k==*(--s.end())){
            s.pop_back();
            k++;
        }
        //cout<<k<<endl;
        s.push_back(k);
    }
    while(!s.empty()){
        cout<<*s.front()<<" ";
        s.pop_front();
    }

    return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>

typedef long long lli;

#define forn(i, n) for (int i = 0; i < n; i++)
#define ford(i, n) for (int i = (n - 1); i >= 0; i--)
#define fore(i, a, b) for (int i = a; i < b; i++)
#define foreach(it, a) for (auto it = a.begin(); it != a.end(); it++)
#define rforeach(it, a) for (auto it = a.rbegin(); it != a.rend(); it++)
#define all(a) a.begin(), a.end()
#define scani(a) scanf("%I64d", &(a))
#define scanii(a, b) scanf("%I64d%I64d", &(a), &(b))
#define scaniii(a, b, c) scanf("%I64d%I64d%I64d", &(a), &(b), &(c))
#define sqr(x) (x) * (x)

using namespace std;

int main()
{
	lli r, x, y, x1, y1;

	scaniii(r, x, y);
	scanii(x1, y1);

	lli l2 = ((x1 - x) * (x1 - x) + (y1 - y) * (y1 - y)) / (4 * r * r);
	lli lb = 0, rb = l2;

	while (lb != rb)
	{
		lli mb = (lb + rb) / 2;

		if (l2 / mb >= mb) rb = mb;
		else lb = mb + 1;
	}

	printf("%I64d", lb);

	return 0;
}


#include <bits/stdc++.h>

#define inf 0x3f3f3f3f

#define INF 0x3f3f3f3f3f3f3f3fLL

#define mod 1000000007

#define pb push_back

#define eps 1e-8

#define bpt(x) (__builtin_popcount(x))

#define bptl(x) (__builtin_popcountll(x))

#define bit(x, y) (((x)>>(y))&1)

#define x first

#define y second

using namespace std;

typedef long long INT;

typedef double DO;

typedef vector<int> VI;

typedef pair<int, int> pii;

typedef pair<pii, int> pi3;

typedef vector<int> VI;

template<typename T, typename U> inline void smin(T &a, U b) {if (a>b) a=b;}

template<typename T, typename U> inline void smax(T &a, U b) {if (a<b) a=b;}

int power(int a, int b, int m, int ans=1) {

	for (; b; b>>=1, a=1LL*a*a%m) if (b&1) ans=1LL*ans*a%m;

	return ans;

}

#define NN 21

int a[NN],b[NN];

int dp(int r,int n){

	if(n==0) return 1;

	int ct=0;

	for(int i=0;i<=r;i++){

		if(a[i]==0||i>r) continue;

		a[i]--;

		ct=(ct+(INT)(a[i]+1)*dp(r-i,n-1)%mod)%mod;

		a[i]++;

	}

	return ct;

}

int main() {

#ifndef ONLINE_JUDGE

	freopen("in.in", "r", stdin);

	freopen("out.out", "w", stdout);

#endif

	int m;

	scanf("%d",&m);

	for(int i=1;i<=m;i++){

		int u=i;

		int num=0;

		while(u){

			if(u%10==7) num++;

			if(u%10==4) num++;

			u/=10;

		}

		a[num]++;

	}

	for(int i=0;i<=9;i++) b[i]=a[i];

	int ans=0;

	for(int i=1;i<=9;i++){

		if(b[i]==0) continue;

		for(int j=0;j<=9;j++) a[j]=b[j];

		a[i]--;

		ans=(ans+(INT)dp(i-1,6)*b[i]%mod)%mod;

	}

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

	return 0;

}


#include <cstdio>
typedef unsigned long long ull;
ull l, r, x, y, cnt;
ull gcd(ull x, ull y) { return y ? gcd(y, x % y) : x; }

int main() {
    scanf("%llu %llu %llu %llu", &l, &r, &x, &y);
    ull tmp = y / x;
    for(int i = 1; i * i <= tmp; i++) {
        if(tmp % i == 0) {
            if(gcd(i, tmp / i) == 1) {
                ull b = x * i;
                ull a = x * (tmp / i);
                if(b < l || b > r || a < l || a > r) continue;
                if(b == a) {
                    cnt++;
                }
                else {
                    cnt += 2;
                }
            }
        }
    }
    printf("%llu\n", cnt);
    return 0;
}


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

int main(){
    ll l,r,gcd,lcm;
    cin>>l>>r>>gcd>>lcm;
    ll i,k,sq=pow(lcm,0.5);
    if(gcd==lcm){
        if(gcd>=l&&lcm<=r){
            cout<<"1";
            return 0;
        }
        else{
            cout<<"0";
            return 0;
        }

    }
    if (lcm%gcd!=0){
        cout<<0;
        return 0;
    }
    sq=pow(lcm/gcd,0.5);
    set<pair<ll,ll>> s;
    for(i=l;i<=sq&&i<=r;i++){
        if((lcm/gcd)%i==0){
            if((lcm/gcd)/i<=r&&(lcm/gcd)/i>=l){
                s.insert(make_pair(i,(lcm/gcd)/i));
            }
        }
    }
    ll ans=0;
    for(auto x:s){
        if(__gcd(x.first,x.second)==1){
            ans++;
            if(x.first!=x.second)ans++;
        }
    }
    cout<<ans;
    return 0;
}


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

int  max_trois(int a,int b,int c)
{
    if ((a>b)&&(a>c)) return a;
    if ((b>a)&&(b>c)) return b;
    return c;
}
int min_deux(int a,int b)
{
    if (a>b) return b;
    return a;
}

int main()
{
    int a,b,c;
    cin >> a >> b >> c;
    if (2*max_trois(a,b,c)>a+b+c)
    {
        cout << "Impossible";
        return 0;
    }
    if ((a)&&(a%2==0)&&(a==b&&(b==c)))
    {
        cout << a/2 <<" "<< a/2 <<" "<< a/2;
                return 0;
    }
    int ab,bc,ca;
    for (ab=0;ab<=min_deux(a,b);ab++)
    {
        for (int bc=0;bc<=min_deux(b,c);bc++)
        {
            if ((ab+bc)>b)
            {
                break;
            }
            ca=a-ab;
            if(((ab+bc)==b)&&(ca==(c-bc)))
            {
                cout << ab <<" "<< bc <<" "<< ca;
                return 0;
            }

        }
    }
    cout << "Impossible";
    return 0;

}


#include<bits/stdc++.h>
using namespace std;
int n,k,tot,ans[25],sum1,sum2;
void dfs(int dep)
{
    if(sum1>k||sum2>=k) return;
    if(dep==n+1)
    {
        if(sum1==k&&sum2==k-1)
        tot++;
        return;
    }
    for(int i=1;i<=4;i++)
        if(i!=ans[dep-1])
        {
            ans[dep]=i;
            if(dep>=3)
            {
                if(ans[dep-2]<ans[dep-1]&&ans[dep]<ans[dep-1])
                    sum1++;
                if(ans[dep-2]>ans[dep-1]&&ans[dep]>ans[dep-1])
                    sum2++;
            }
            dfs(dep+1);
            if(dep>=3)
            {
                if(ans[dep-2]<ans[dep-1]&&ans[dep]<ans[dep-1])
                    sum1--;
                if(ans[dep-2]>ans[dep-1]&&ans[dep]>ans[dep-1])
                    sum2--;
            }
        }
}
int main()
{
    cin>>n>>k;
    if(6*k+1<n||2*k+1>n)
    {
        cout<<0;
        return 0;
    }
    dfs(1);
    cout<<tot;
    return 0;
}


#include<iostream>
#include<string>
#include<math.h>
#include<map>
#include<algorithm>
#include<vector>
#define ll long long
using namespace std;
string s1, s2;
map<char, char>mp;
vector<ll>luky;
ll m;
ll sum = 0;
ll lulu(int n , int i )
{

	if (i > m ) return 0;
	if (n)
	{
		luky.push_back(n);
		sum++;

	}
		lulu(n * 10 + 7, i + 1);
		lulu(n * 10 + 8, i + 1);

	return sum;
}

int main()
{
	ios::sync_with_stdio(0);
	cin >> m;
	cout << lulu(0, 0);
	return  0;
}


#include <iostream>
using namespace std;
int main()
int n;
cin>>n;
int s=2;
int p=1;
int k=1;
while(s<n)
{
   int q=p;
   p=s;
   s+=q;
   k++;
}
cout<<k;
return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int x,y,a,b;
    cin>>x>>y>>a>>b;
    queue<long long int>q1,q2;
    long long int i=1;
    long long int count =0;
    while(1)
    {
        if(x*i>=a && x*i<=b)
        {
            q1.push(x*i);
        }
        if(y*i>=a && y*i<=b)
        {
            q2.push(y*i);
        }
        if(x*i>b && y*i>b)
        {
            break;
        }
        i++;
    }
    while(q1.empty()!=1 && q2.empty()!=1)
    {
        if(q1.front() == q2.front())
        {
            count++;
            q1.pop();
            q2.pop();
        }
        else if(q1.front()>q2.front())
        {
            q2.pop();
        }
        else if(q1.front()<q2.front())
        {
            q1.pop();
        }
    }
    cout<<count<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fill fill_n
#define pb push_back
const int m=1e6+3;
ll po(int a,int b){
    if(b==0) return 1;
    ll x;
    if(b%2==0){
        x=po(a,b/2);
        x=(x%m*x%m)%m;
    }
    else{
        x=po(a,(b-1)/2);
        x=(x%m*x%m*a%m)%m;
    }
    return x%m;
}
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
     int n;cin>>n;
     cout<<po(3,n-1)%m<<"\n";

	return 0;
}


#include<iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
using namespace std;
int main()
{
    int i,j,a,b,c;
    cin>>a>>b>>c;
    for (i=0;i<=b;i++)
        for (j=b-i;j<=c;j++)
        {
            if (c-j==a-i && b==i+j) {
                          cout<<i<<" "<<j<<" "<<a-i;
                          //system("pause");
                          return 0;
                          }
            }
    cout<<"Impossible";
    //system("pause");
    return 0;
    }


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

using namespace std;

#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long
#define pii pair < int, int >
#define pll pair < long long, long long>
#define ull unsigned long long
#define vi vector <int>
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x))
#define FOR(a,b) for(int x = a;x <= b;x++)
int a[1001][1001];
int main (){
    int n;
    int qwe  =1;
    cin >>n;
    for(int i =0 ;i <= n;i++)
    {
        for(int j = i+1;j<= n;j++)
        {
            for(int k = i;k< j;k++)
            {
                a[qwe][k]=1;
            }
            qwe++;
        }
    }
   for(int i = 0;i <= n;i++)
   {
   	for(int j = 0;j <= qwe;j++)
   	{
   		a[0][i]+=a[j][i];
   	}
   }
   int s = 0;
   for(int i = 0;i <= n;i++)
   {
   	if(s < a[0][i])s=a[0][i];
   }
   cout<<s;
}


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

// use long long instead of int
// use "\n" instead of endl
// use printf and scanf instead of cout and cin

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;

#define ft first
#define sd second
#define pb push_back
#define mp make_pair
#define rep(i, a, b) for (int i = a; i < b; i++)

ll power(ll x, ll y)
{
    ll sum = 1;
    while (y--)
    {
        sum *= x;
    }
    return sum;
}

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    // ios::sync_with_stdio(0);
    // cin.tie(0);
    // cout.tie(0);
    string s;
    int k;
    cin >> s;
    int n = s.length();
    cin >> k;
    int j = 0;
    while (k > 0)
    {
        int m = min(k, n);
        int mx = 0;
        rep(i, j, m + 1)
        {
            if (s[mx] < s[i])
            {
                mx = i;
            }
        }
        for (int i = mx; i > j; i--)
        {
            char t = s[i];
            s[i] = s[i - 1];
            s[i - 1] = t;
        }
        k -= mx;
        j++;
    }
    cout << s;
}


#include<bits/stdc++.h>
#define mp make_pair
#define PII pair<int,int>
#define fi first
#define se second
using namespace std;

const int LMAX=100005;

int a,b,c,l;
long long sol,sum[LMAX];

int main()
{
    int i,kkt,aux;

    cin.sync_with_stdio(false);
    cin>>a>>b>>c>>l;
    sum[0]=1;
    for (i=1;i<LMAX;i++)//mai adunam comb(i+2,2)
        sum[i]=sum[i-1]+(1LL*(i+1)*(i+2))/2;
    sol=sum[l];//nr de moduri de a aduna maxim l la toate
    //scad nr de moduri in care o latura este >= decat celelalte
    //a+la>=b+lb+c+lc
    kkt=b+c-a;
    for (i=0;i<=l;i++)//la
        {
            //mai am voie sa cresc lb si lc cu min(aux,(l-i))
            aux=i-kkt;
            if (aux>=0)
                sol-=(1LL*(min(aux,l-i)+1)*(min(aux,l-i)+2))/2;
        }
    //b+lb>=a+la+c+lc
    kkt=a+c-b;
    for (i=0;i<=l;i++)//lb
        {
            aux=i-kkt;
            if (aux>=0)
                sol-=(1LL*(min(aux,l-i)+1)*(min(aux,l-i)+2))/2;
        }
    //c+lc>=a+la+b+lb
    kkt=a+b-c;
    for (i=0;i<=l;i++)
        {
            aux=i-kkt;
            if (aux>=0)
                sol-=(1LL*(min(aux,l-i)+1)*(min(aux,l-i)+2))/2;
        }
    cout<<sol<<"\n";
    return 0;
}


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


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

typedef long long ll;

int func1(ll x,ll r)
{
    return (r-(x*x)-x-1)/(2*x);
}

int func2(int x,int y)
{
    return x*x + 2*x*y + x + 1;
}

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

    ll r,y,i;
    while(scanf("%lld",&r)==1)
    {
        ll sq = sqrt(r);
        int f = 0;
        for(i = 0;i<=sq;i++)
        {
            y = func1(i,r);
            if(func2(i,y)==r && y!=0)
            {
                f = 1;
                break;
            }
        }
        if(f)
            printf("%lld %lld\n",i,y);
        else
            printf("NO\n");
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a[2];
    cin>>a[0]>>a[1]>>a[2];
    sort(a,a+3);
    int sum = abs(a[0]-a[1])+abs(a[1]-a[2]);
    cout<<sum<<endl;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;cin>>n;
    queue<string>Q;
    Q.push("7");
    Q.push("8");
    unsigned long long int ct=0;
    while(!Q.empty()){
        auto p=Q.front();Q.pop();
        if(p.size()>n)break;
        ct++;
        Q.push("7"+p);
        Q.push("8"+p);
    }
    cout<<ct;
    return 0;
}


#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<cstring>
#include<map>
#include<queue>
#include<stack>
#include<utility>
#include<cstdlib>
#include<string>
#include<set>
#include<limits>
#include<iomanip>
#include<fstream>
#include<sstream>
#define INF 2147483647
#define LLD int
#define clr(a) memset(a,0,sizeof(a))
#define reset(a) memset(a,-1,sizeof(a))
#define BD(i, j) (i >= 0 && i < n && j >= 0 && j < m)
#define PRINT_VAR(X) (cout << #X << " -> " << X << endl)
#define PI acos(0)
#define MAX_INT 2147483647
#define SIZE 205
#define MOD 10056
using namespace std;
int X[] = {0, 1, 0, -1};
int Y[] = {1, 0, -1, 0};
/* right, down, lft, up */
int m, n;
typedef pair<int, int> Point;
typedef pair<Point, Point> Line;

long long solve(int val, int idx, int t, bool up) {
	if (2*(m-t) + idx - 1 > n || t > m) return 0;
	if (t == m && idx == n) return 1;
	long long total = 0;
	if (idx != n-1) {
		for (int i = val+1; i <= 4; i++) {
			total += solve(i, idx+1, t, true);
		}
	}

	if (idx != 1) {
		for (int i = val-1; i > 0; i--) {
			if (up)
				total += solve(i, idx+1, t+1, false);
			else
				total += solve(i, idx+1, t, false);
		}
	}

	return total;
}

int main()
{
	int t, tc, z, x, y;
    int i, j, k, l, h;
    char ch;

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

	cin >> n >> m;
	long long res = solve(0, 0, 0, true);

	cout << res << endl;

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

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

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

    vector<int> a(n);

    int ans = 0;

    for(int &i : a) cin >> i;

    if(n<2){
        cout << ans << endl;
        return 0;
    }

    for(int i=0; i<a.size(); i++){
        vector<int> b;

        bool ok = 0;
        bool added = 0;
        int index = 0;

        for(int j=0; j<a.size()-1; j++){
            if(a[j] == x and a[j]==a[j+1]){
                ok = 1;
                added = 1;
                index = j;
                for(int k=0; k<=j; k++)
                    b.push_back(a[k]);
                b.push_back(x);
                for(int k=j+1; k<a.size(); k++)
                    b.push_back(a[k]);
            }
        }

        if(ok==0) {
            for(int j=0; j<a.size()-2; j++){
                if(a[j]==a[j+1] and a[j]==a[j+2]){
                    ok = 1;
                    index = j;
                    b = a;
                    break;
                }
            }
            if(ok==0)
                break;
        }

        //for(int j : b) cout << j << " ";
        //cout << endl;

        int final_index = index;

        while(final_index<b.size() and b[index]==b[final_index])
            final_index++;

        if(final_index==b.size() or b[final_index]!=b[index])
            final_index--;

        vector<int> c;
        ans+=(final_index-index+1);
        if(added) ans--;

        for(int j=0; j<index; j++)
            c.push_back(b[j]);
        for(int j=final_index+1; j<b.size(); j++)
            c.push_back(b[j]);

        a = c;
    }

    cout << ans << endl;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int ara[3];
cin>>ara[0]>>ara[1]>>ara[2];
sort(ara,ara+3,greater<int>());
//cin>>ara[0]>>ara[1]>>ara[2];
//cout<<ara[0]<<ara[1]<<ara[2];
if(ara[1]+ara[2]>ara[0]){cout<<0;return 1;}
int n = ara[0] - (ara[1]+ara[2]);
cout<<n+1;

}


#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(){
    string str;
    cin >> str;
    string made = str.substr(0, 1);
    bool at = false;
    for (int i = 1; i < str.length();){
        if (str.substr(i, 3) == "dot" && i + 3 != str.length()){
            made = made + ".";
            i += 3;
        }
        else if (str.substr(i, 2) == "at" && at == false && i + 2 != str.length()){
            at = true;
            made = made + "@";
            i += 2;
        }
    }
    cout << made << endl;

    return 0;
}


//
//  main.cpp
//  ioi
//
//  Created by Arkalyk Akash on 12/17/16.
//  Copyright © 2016 Arkalyk Akash. All rights reserved.
//

#include <iostream>

using namespace std;

int main() {
    int ans = 0;
    string s;
    cin >> s;
    sort(s.begin(),s.end());
    for (int  i = 0; i < s.size();i++){
        s[i] = tolower(s[i]);
        if (s[i] != s[i + 1]){
            ans++;
        }
    }
    cout << ans;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);
    cout.tie(0);
	int n;
	cin>>n;
	string s;
	cin>>s;
	if(n==1){
		cout<<0<<"\n";
		return 0;
	}
	else{
		int ans=0;
		queue<pair<string,int>> q;
		q.push(make_pair(s,0));
		while(!q.empty()){
			pair<string,int> u=q.front();
			q.pop();
			ans=max(ans,u.second);

			string t=u.first;
			//cout<<t<<endl;
			for(int i=0;i<t.size()-1;i++){
				if(abs(t[i]-t[i+1])==1){
					string ll=t;
					if(t[i+1]-t[i]==1){
						ll.erase(ll.begin()+i+1);
						q.push({ll,u.second+1});
					}
					else{
						ll.erase(ll.begin()+i);
						q.push({ll,u.second+1});
					}
					//break;
				}
			}
		}
	cout<<ans<<"\n";

	}

	return 0;
}


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

#define ll long long
#define llu unsigned long long
#define PB push_back
#define F first
#define S second
const ll MOD = 1000000007;
const ll INF = 1000000007;

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

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

string gh = "here";

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
            freopen("input.txt", "r", stdin);
            freopen("output.txt", "w", stdout);
            freopen("err.txt", "w", stderr);
    #endif

    int n;
    cin>>n;
    string s;
    cin>>s;
    vector < string > ab;
    ab.PB(s);
    int ans =-1;
    while(true){
        if(ab.empty()){
            break;
        }
        ans++;
        vector < string > ba(ab);
        ab.clear();
        int sz = ba.size();
        for(int i= 0;i<sz;i++){
            string ff = ba[i];
            int sx = ff.size();
            for(int j =0;j<sx;j++){
                if((j-1 < 0 || ff[j-1] != ff[j]-1) && (j+1 >= n || ff[j+1] != ff[j]-1))
                    continue;
                string uu;
                for(int k = 0;k<sx;k++){
                    if(k == j)
                        continue;
                    uu += ff[k];
                }
                ab.PB(uu);
            }
        }
    }
    cout<<ans;

    return 0;
}


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

pair<int, int> p[maxn];
vector<int> x, y;
set<int> sx, xy;

int main() {
	int i;
	for (i = 0; i < maxn; i++) {
		scanf("%d %d", &p[i].first, &p[i].second);
		if (sx.find(p[i].first) == sx.end()) {
			sx.insert(p[i].first);
			x.push_back(p[i].first);
		}
		if (sy.find(p[i].second) == sy.end()) {
			sy.insert(p[i].second);
			y.push_back(p[i].second);
		}
	}
	if (x.size() != 3 && y.size() != 3) {
		printf("ugly");
		return 0;
	}
	sort(x.begin(), x.end());
	sort(y.begin(), y.end());
	for (i = 0; i < maxn; i++)
		if (p[i].first == x[1] && p[i].second == y[1]) {
			printf("ugly");
			return 0;
		}
	printf("respectable");
	return 0;
}


#include <iostream>
using namespace std;
int main()
{
	int n, a, cm = 0, ce = 0;
	cin >> n;
	while (n >=0) {
		cin >> a;
		if (a % 2 == 0 && n >= a) {
			n = n - a; cm++;
		}
		else if (a % 2 != 0 && n >= a) {
			n = n - a; ce++;
		}
	}
	if (cm > ce)cout << "Mahmoud";
	else cout << "Ehab";
}


#include <iostream>
#include <cstring>
#include <sstream>
#include <bitset>
#include <cstdio>

#define FOR(i,a,b) for (int i=a;  i<=b;  i++)
#define DFU(i,a,b) for (int i=a;  i>=b;  i--)
#define SIZE(a) int(a.size())

using namespace std;

struct board
{
    long long m[11][11];
};

board matrix,c,s;
long long t,n,sx,sy,dx,dy,mang[11];

void init()
{
    memset(matrix.m,0,sizeof(matrix.m));
    FOR(i,1,4) matrix.m[5][i]=1;  matrix.m[5][5]=1;
    FOR(i,1,4) matrix.m[1][i]=1;  matrix.m[1][1]=2;
    FOR(i,1,4) matrix.m[2][i]=1;  matrix.m[2][2]=2;
    matrix.m[3][1]=1;  matrix.m[3][3]=1;
    matrix.m[4][2]=1;  matrix.m[4][4]=1;
    matrix.m[6][6]=1;  matrix.m[6][5]=1;
}

board tich(board a, board b)
{
    memset(c.m,0,sizeof(c.m));
    FOR(i,1,6) FOR(j,1,6)
        FOR(t,1,6) c.m[i][j]=(c.m[i][j]+a.m[i][t]*b.m[t][j])%n;
    return c;
}

long long get(long long x, long long y)
{
    return (x >> y) & 1;
}

void solve()
{
    int p;
    FOR(i,0,61) if (get(t,i)) p=i;
    memset(s.m,0,sizeof(s.m));
    FOR(i,1,6) s.m[i][i]=1;
    DFU(i,p,0) {
        s=tich(s,s);
        if (get(t,i)) s=tich(s,matrix);
    }
}

int main()
{
  //  freopen("test.inp","r",stdin);
    cin >>n>>sx>>sy>>dx>>dy>>t;
    sx--;  sy--;
    init();
    solve();
    long long ans=0;
    memset(mang,0,sizeof(mang));
    mang[1]=sx;  mang[2]=sy;  mang[3]=dx;  mang[4]=dy;  mang[5]=2;  mang[6]=1;
    ans=0;
    FOR(i,1,6) ans=(ans+mang[i]*s.m[i][1])%n;
    cout <<ans+1<<" ";
    ans=0;
    FOR(i,1,6) ans=(ans+mang[i]*s.m[i][2])%n;
    cout <<ans+1<<" ";
    return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <math.h>
#include <cmath>
#include <queue>
#include <iomanip>

using namespace std;
#define LL long long
#define uLL unsigned long long
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define vi vector<int>
#define vLL vector<LL>
#define vs vector<string>
#define fori(n) for(int (i)=0; (i)<n; (i)++)
const LL mod = 1000000007;

int main()
{
#ifdef _DEBUG
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    char c;
    cin >> c;
    char cur = c;
    int len = 1;
    int ans = 0;
    while (!cin.eof())
    {
        cin >> c;
        if (c == cur) len++;
        else
        {
            if (len % 2 == 0)ans++;
            len = 1;
            cur = c;
        }
    }
    cout << ans;
    return 0;
}


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

int main()
{
    long long  n;

    cin>>n;
  if(n==1)
  {
    cout<<"0 0";
    return 0;
  }

    for(long long  i=0; i<=min(1000000LL ,n); i++)
    {

        long long x = i*i;
        x+=i+1;
        if(n-x>=0){
        if((n-x)%(2*i)==0)
        {

          cout<<i<<" "<<(n-x)/2*i;
          return 0;
        }
      }
    }

    cout<<"NO"<<endl;

  return 0;
}


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

#define re return

using namespace std;

int main()
{
  int n,m,a[10],b[9], min1=3000, min2=3000,min3=3000,f=0;
  cin >> n >> m;
  for (int i = 0; i < n; i ++)
  {
    cin>> a[i];
    if (a[i]<min1 && a[i]>0)
        min1=a[i];
  }
  for (int i = 0; i < n; i ++)
  {
    cin>> b[i];
    if (b[i]<min2 && b[i]>0)
        min2=b[i];
  }
  for (int i = 0; i < n; i ++)
  {
      for (int j = 0; j < m; j++)
      {
          if (a[i]==b[j])
          {
              if (a[i]<min3)
                min3=a[i];
              f=1;
          }
      }
  }
  if (f==1)
  {
      cout << min3;
      re 0;
  }
  if (min1==min2)
  {
    cout << min1;
    re 0;
  }
  cout << min(min1,min2) << max(min1,min2);
  re 0;
}


	// Naman Shukla

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

	#define ms(s, n) memset(s, n, sizeof(s))
	#define FOR(i, a, b) for (int i = (a); i < (b); i++)
	#define FORd(i, a, b) for (int i = (a) - 1; i >= (b); i--)
	#define FORall(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
	#define sz(a) int((a).size())
	#define all(a) (a).begin(), (a).end()
	#define uni(a) (a).erase(unique(all(a)), (a).end())
	#define pb push_back
	#define pf push_front
	#define mp make_pair
	#define fi first
	#define se second
	#define prec(n) fixed<<setprecision(n)
	#define bit(n, i) (((n) >> (i)) & 1)
	#define bitcount(n) __builtin_popcount(n)
	typedef long long ll;
	typedef unsigned long long ull;
	typedef long double ld;
	typedef pair<int, int> pi;
	typedef vector<int> vi;
	typedef vector<pi> vii;
	const int MOD = (int) 1e9 + 7;
	const int INF = (int) 1e9;
	const ll LINF = (ll) 1e18;
	const ld PI = acos((ld) -1);
	const ld EPS = 1e-9;
	ll gcd(ll a, ll b) {ll r; while (b) {r = a % b; a = b; b = r;} return a;}
	ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
	ll fpow(ll n, ll k, int p = MOD) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n % p; n = n * n % p;} return r;}
	template<class T> void setmin(T& a, T val) {if (a > val) a = val;}
	template<class T> void setmax(T& a, T val) {if (a < val) a = val;}
	void addmod(int& a, int val, int p = MOD) {if ((a = (a + val)) >= p) a -= p;}
	void submod(int& a, int val, int p = MOD) {if ((a = (a - val)) < 0) a += p;}
	int mult(int a, int b, int p = MOD) {return (ll) a * b % p;}
	int inv(int a, int p = MOD) {return fpow(a, p - 2, p);}

	ll n,m,a[40];
	vector<ll>v1,v2;

	void go1(ll cur,ll val)
	{
		if(cur==n)
		{
			v1.pb(val);
			return;
		}

		go1(cur+1,val);
		val = (val+a[cur])%m;
		go1(cur+1,val);
	}

	void go2(ll cur,ll val)
	{
		val=(val+a[cur])%m;
		v2.pb(val);

		FOR(i,cur+1,n)
		go2(i,val);
	}

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

		cin>>n>>m;
		FOR(i,0,n)cin>>a[i];

		go1(0,0);

		ll ans = 0;

		FOR(i,0,v1.size())ans= max(ans,v1[i]);
		FOR(i,0,v2.size())ans= max(ans,v2[i]);

		FOR(i,0,v1.size())
		FOR(j,0,v2.size())
		ans = max(ans,(v1[i]+v2[j])%m);

		cout<<ans;
		return 0;
	}


#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#define int long long
using namespace std;
    long long powmod(long long a,long long b,long long mod) {
        if (b==0 || a==1)  {if (mod==1) return 0; else return 1; }

        if (b%2==0) { long long k=powmod(a,b/2,mod); return (k*k)%mod; }
        else {long long k=powmod(a,b/2,mod); return ( (k*k) %mod *a)% mod; }
    }
    long long gcd(long long a, long long b) {
        if (a==0) return b;
        if (b==0) return a;
        if (a>b) return gcd(a%b,b); else return gcd(b%a,a);
    }
    int prime(int p) { // 1 - простое
        for (int i=2;i*i<=p;i++) {
            if (p%i==0 && i<p) return i;
        }
        return 1;
    }
    int inv(int a, int mod) {
        return powmod(a,mod-2,mod);
    }

    void solve (int ppppppppp=1) {

         /* --------- */
       int a;
       cin>>a;
       cout << ( ( x%360 + 45 + 360 )%360-1 )/90;
         /* --------- */
           return;
    }

    signed main() {

         ios_base::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);

         cout<<fixed<<setprecision(10);
          int tututu;
          tututu=1;
       // cin>>tututu; // если нет запросов, то закоментить
          for (int qwerty=0;qwerty<tututu;qwerty++) solve();

        return 0;
    }


#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<algorithm>
#include<math.h>
#define maxn 10005
using namespace std;
int book[maxn][maxn];
int a[4][2]={{1,1},{1,-1},{-1,-1},{-1,1}};
int x,y,x1,x2;
int y11,y2,flag;
void dfs(int x0,int y0)
{
	int i,tx,ty;
	if(x0==x2&&y0==y2)
		{
			flag=1;
			return;
		}
		if(flag==1)
			return ;
		for(i=0;i<4;i++)
		{
			tx=x0+a[i][0]*x;
			ty=y0+a[i][1]*y;
			if(tx<0||ty<0||tx>x2+x||ty>y2+y)
				continue;
			if(book[tx][ty]==0)
				{
					book[tx][ty]=1;
					dfs(tx,ty);
					book[tx][ty]=0;
				}
		}
}
int main()
{
   while(scanf("%d%d%d%d",&x1,&y11,&x2,&y2)!=EOF)
   {
   	flag=0;
   	memset(book,0,sizeof(book));
   	scanf("%d%d",&x,&y);
   	book[x1][y11]=1;
   	dfs(x1,y11);
   	if(flag==1)
   		printf("YES\n");
   		else
   			printf("NO\n");
   }
   return 0;
}


#include<bits/stdc++.h>
using namespace std;
char  start[1004],ending[1004];

#define SYN ios_base::sync_with_stdio(0);cin.tie(0);
typedef long long int LL;
typedef unsigned long long int ULL;

#define debug(x)         cerr<<__LINE__<<" "<<#x<<" "<<x<<endl;
#define IMAX ((unsigned)1<<31)-1
#define eps 1e-11
#define fill(a,v) memset(a,v,sizeof (a))
#define SZ(X) ((int)X.size())
#define VI vector<int>
#define VS vector<string>
#define PB push_back
#define MSI map<string,int>
#define MSLI map<string,LLI>
#define MCI map<char,int>
#define PI acos(-1.0)
#define mk make_pair
#define pLLI pair<LLI,LLI>
#define xx first
#define yy second
#define POPCOUNT __builtin_popcountll

#define MOD 1000000007
#define RADIANS(x)       (((1.0 * x * PI) / 180.0))
#define DEGREES(x)       (((x * 180.0) / (1.0 * PI)))

///*----------------------Graph Moves----------------*/
////const int fx[]={+1,-1,+0,+0};
////const int fy[]={+0,+0,+1,-1};
////const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
////const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
////const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
////const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
///*------------------------------------------------*/

#define LLI long long int
template<typename T> inline bool isOn(T mask,T pos)
{
    return mask&(1<<pos);
}

template<typename T> inline int Off(T mask,T pos)
{
    return mask^(1<<pos);
}

template<typename T> inline int On(T mask,T pos)
{
    return mask|(1<<pos);
}

template<class T> inline int countbit(T n)
{
    return (n == 0) ? 0 : (1+countbit(n&(n-1)));
}

template<class T> string toBinary(T n)
{
    string ret="";
    while(n)
    {
        if(n%2==1) ret+='1';
        else ret+='0';
        n>>=1;
    }
    reverse(ret.begin(),ret.end());
    return ret;
}

/// String Conversion template start

template<class T> string toString(T n)
{
    ostringstream ost;
    ost << n;
    ost.flush();
    return ost.str();
}

int toInt(string s)
{
    int r = 0;
    istringstream sin(s);
    sin >> r;
    return r;
}
LLI toLInt(string s)
{
    LLI r = 0;
    istringstream sin(s);
    sin >> r;
    return r;
}
double toDouble(string s)
{
    double r = 0;
    istringstream sin(s);
    sin >> r;
    return r;
}

vector <string> token( string str,string deli )
{
    char * cstr, *p,*deli_c;
    deli_c = new char [deli.size()+1];
    cstr = new char [str.size()+1];
    strcpy(deli_c,deli.c_str());
    strcpy (cstr, str.c_str());
    VS vec;
    p=strtok(cstr,deli_c);
    while(p!=NULL)
    {
        vec.push_back( string(p));
        p=strtok(NULL,deli_c);
    }
    delete[] cstr;
    return vec;
}

/// String Conversion template End

/// Math template  start
template<class T> inline T GCD(T a,T b)
{
    if ( a < 0 ) return GCD(-a,b);
    if ( b < 0 ) return GCD(a,-b);
    return (b == 0) ? a :GCD(b,a%b);
}

template<class T > inline T LCM(T a, T b)
{
    if( a < 0 ) return LCM( -a, b);
    if( b < 0 ) return LCM(a,-b);
    return a*(b/GCD(a,b));
}

LLI fastExpo( LLI b, LLI p)
{
    LLI res=1,x=b;
    while(p)
    {
        if(p&1) res*=x;
        x*=x;
        p=p>>1;
    }
    return res;
}

/// Math template End

double dist(int x,int y,int x1,int y1)
{
    return sqrt(((x1-x)*(x1-x))+((y1-y)*(y1-y)));
}
LLI dp[19][2][2][(1<<8)][2521];
LLI k,n;
LLI mod= 2520;
LLI solve(int pos,int x,int y,int bit,int r)
{
    if(pos==n)
    {
       // cout<<s<<" s"<<endl;
        int f=1;
        int ne;
        for(int i=0;i<8;i++)
        {
            if((bit&(1<<(i))))
            {
               // if(lcm[f][i+2]==-1)
                    {f=LCM(f,i+2);
                    //  lcm[f][i+2]=f;
                    }
                  //  else
                 //       f=lcm[f][i+2];

            }
        }
     //   cout<<f<<" "<<r<<endl;
        if(r%f)
            return 0;

        return 1;
    }

    LLI &res= dp[pos][x][y][bit][r];

    if(res!=-1&&x==1&&y==1)
        return res;
   // else
        res=0;

    int low,high;
    low=0;
    high=9;
    if(x==0)
        low=start[pos]-'0';
    if(y==0)
        high=ending[pos]-'0';
        int no,nt,nth;
    for(int i=low;i<=high;i++)
    {

          res+=solve(pos+1,x|(i>start[pos]-'0'),y|(i<ending[pos]-'0'),bit|(1<<(i-2)),(r*10+i)%mod);

    //res%=mod;
    }
    //v=p;
return res;
}

int main()
{
    int t;
    SYN;
   // cin>>k;
   memset(lcm,-1,sizeof(lcm));
   memset(dp,-1,sizeof(dp));
      cin>>t;
   //scanf("%d%lld",&t,&k);
    while(t--)
    {

       cin>>start>>ending;
    // scanf("%s %s",&start,&ending);
        //sprintf(start,"%d",st);
        //s23333printf(ending,"%d",ed);
        int l1,l2;
        l1=strlen(start);
        l2=strlen(ending);
        n=19;
        int dif=(n-l1);

        {
            for(int j=l1-1;j>=0;j--)
            {
                start[j+dif]=start[j];
            }
            for(int i=0;i<dif;i++)
                start[i]='0';
        }
        dif=(n-l2);

        {
            for(int j=l2-1;j>=0;j--)
            {
                ending[j+dif]=ending[j];
            }
            for(int i=0;i<dif;i++)
                ending[i]='0';
        }
        //cout<<start<<endl;
       // cout<<ending<<endl;
       // memset(dp,-1,sizeof(dp));
       // cout<<start<<"   "<<ed<<endl;
        cout<<solve(0,0,0,0,0)<<endl;
     }
}


//#include "stdafx.h"
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <stdio.h>
#include <string>
#include <iomanip>
#include <utility>
#include <algorithm>
#include <queue>
#include <set>
#include <cmath>
#include <time.h>

typedef long long ll;
typedef long double ld;
const ll INF = 9999999999999;

#define forn(ii,kk,nn) for(ll ii = kk; ii < nn; ++ii)

using namespace std;
using namespace std;

vector<vector<int> > v;
ll n,k;

int main()
{
    //freopen("area.in","r",stdin);
     //freopen("area.out","w",stdout);
   cin >> n >> k;
   vector<ll> ans;
   ans.push_back(1);
   ll t = k;
   forn(i,0,k)
   {
       ans.push_back(ans.back()-1+k);
       k--;
   }
   forn(i,0,ans.size())
   {
       if(ans[i]==n)
       {
           cout << i << endl;
           return 0;
       }
   }

   cout << -1 << endl;
    return 0;
}


#include<bits/stdc++.h>
#include <cstring>
#include <iostream>
#define pie acos(-1)
#define si(a) scanf("%d",&a)
#define sii(a,b) scanf("%d %d",&a,&b)
#define siii(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define sl(a) scanf("%lld",&a)
#define sll(a,b) scanf("%lld %lld",&a,&b)
#define slll(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define ss(st) scanf("%s",st)
#define sch(ch) scanf("%ch",&ch)
#define ps(a) printf("%s",a)
#define newLine() printf("\n")
#define pi(a) printf("%d",a)
#define pii(a,b) printf("%d %d",a,b)
#define piii(a,b,c) printf("%d %d %d",a,b,c)
#define pl(a) printf("%lld",a)
#define pll(a,b) printf("%lld %lld",a,b)
#define plll(a,b,c) printf("%lld %lld %lld",a,b,c)
#define pd(a) printf("%lf",a)
#define pdd(a,b) printf("%lf %lf",a,b)
#define pddd(a,b,c) printf("%lf %lf %lf",a,b,c)
#define pch(c) printf("%ch",c)
#define debug1(str,a) printf("%s=%d\n",str,a)
#define debug2(str1,str2,a,b) printf("%s=%d %s=%d\n",str1,a,str2,b)
#define debug3(str1,str2,str3,a,b,c) printf("%s=%d %s=%d %s=%d\n",str1,a,str2,b,str3,c)
#define debug4(str1,str2,str3,str4,a,b,c,d) printf("%s=%d %s=%d %s=%d %s=%d\n",str1,a,str2,b,str3,c,str4,d)
#define for0(i,n) for(i=0;i<n;i++)
#define for1(i,n) for(i=1;i<=n;i++)
#define forab(i,a,b) for(i=a;i<=b;i++)
#define forstl(i, s) for (__typeof ((s).end ()) i = (s).begin (); i != (s).end (); ++i)
#define NL puts("")
#define sd(a) scanf("%lf",&a)
#define sdd(a,b) scanf("%lf %lf",&a,&b)
#define sddd(a,b,c) scanf("%lf %lf %lf",&a,&b,&c)
#define SP printf(" ")
#define LL long long int
#define ULL unsigned long long int
#define MOD 1000000007
#define pub(x) push_back(x)
#define pob(x) pop_back(x)
#define mem(ara,value) memset(ara,value,sizeof(ara))
#define INF INT_MAX
#define eps 1e-8
#define checkbit(n, pos) (n & (1<<pos))
#define setbit(n, pos) (n  (1<<pos))
#define para(a,b,ara)\
for(int i=a;i<=b;i++){\
    if(i!=0){printf(" ");}\
    cout<<ara[i];\
}\
printf("\n");
#define pvec(vec)\
for(int i=0;i<vec.size();i++){\
    if(i!=0){printf(" ");}\
    cout<<vec[i];\
}\
printf("\n");
#define ppara(n,m,ara)\
for(int i=0;i<n;i++){\
    for(int j=0;j<m;j++){\
        if(j!=0){printf(" ");}\
        cout<<ara[i][j];\
    }\
    printf("\n");\
}
#define ppstructara(n,m,ara)\
for(int i=0;i<n;i++){\
    printf("%d:\n",i);\
    for(int j=0;j<m;j++){\
        cout<<ara[i][j];printf("\n")\
    }\
}
#define ppvec(n,vec)\
for(int i=0;i<n;i++){\
    printf("%d:",i);\
    for(int j=0;j<vec[i].size();j++){\
        if(j!=0){printf(" ");}\
        cout<<vec[i][j];\
    }\
    printf("\n");\
}
#define ppstructvec(n,vec)\
for(int i=0;i<n;i++){\
    printf("%d:",i);\
    for(int j=0;j<vec[i].size();j++){\
        cout<<vec[i][j];printf("\n");\
    }\
}
#define sara(a,b,ara)\
for(int i=a;i<=b;i++){\
    scanf("%d",&ara[i]);\
}
#define pstructara(a,b,ara)\
for(int i=a;i<=b;i++){\
    cout<<ara[i];NL;\
}
#define pstructvec(vec)\
for(int i=0;i<vec.size();i++){\
    cout<<vec[i];NL;\
}
#define pstructstl(stl,x)\
for(__typeof(stl.begin()) it=stl.begin();it!=stl.end();++it){\
    x=*it;\
    cout<<x;NL;\
}\
NL;
#define pstl(stl)\
for(__typeof(stl.begin()) it=stl.begin();it!=stl.end();++it){\
    if(it!=stl.begin()){SP;}\
    pi(*it);\
}\
NL;
#define ppairvec(vec)\
for(int i=0;i<vec.size();i++){\
    cout<<vec[i].first;SP;cout<<vec[i].second;printf("\n");\
}
#define ppairara(a,b,ara)\
for(int i=a;i<=b;i++){\
    cout<<ara[i].first;SP;cout<<ara[i].second;printf("\n");\
}
#define pppairvec(n,vec)\
for(int i=0;i<n;i++){\
    printf("%d:",i);\
    for(int j=0;j<vec[i].size();j++){\
        cout<<vec[i][j].first;SP;cout<<vec[i][j].second;NL;\
    }\
}
#define pppairara(n,m,ara)\
for(int i=0;i<n;i++){\
    printf("%d:\n",i);\
    for(int j=0;j<m;j++){\
        cout<<ara[i][j].first;printf(" ");cout<<ara[i][j].second;NL;\
    }\
}
#define SZ 5*100010
//std::ostream & dump(std::ostream &os)const{
//    return os<<"l="<<l
//             <<"r="<<r
//             <<"m="<<m;
//}
//std::ostream & operator<<(ostream &os,seg &s){
//    return s.dump(os);
//}
using namespace std;
//bool status[1010];
//vector <int> prime;
//void siv(){
//    int N=1005,i,j;prime.clear();
//    int sq=sqrt(N);
//    for(i=4;i<=N;i+=2){status[i]=1};
//    for(i=3;i<=sq;i+=2){
//        if(status[i]==0){
//            for(j=i*i;j<=N;j+=i){status[j]=1;}
//        }
//    }
//    status[1]=1;
//    for1(i,N){
//        if(!status[i]){prime.pub(i);}
//    }
//}
struct trie{
    LL ara[100][2],sz;
    bool isSuffix[100];
    trie(){}
    trie(LL _sz){
        sz=_sz;
        mem(ara,-1);
        mem(isSuffix,false);
    }
    void insrt(LL root,char text[],LL pos){
        if(text[pos]=='\0'){isSuffix[root]=true;return;}
        LL bit=text[pos]-'0';
        if(ara[root][bit]!=-1){
            insrt(ara[root][bit],text,pos+1);
        }
        else{
            sz++;
            ara[root][bit]=sz-1;
            insrt(ara[root][bit],text,pos+1);
        }
    }
    void print(LL root){
        if(ara[root][0]!=-1){
            pll(ara[root][0],0LL);NL;
            print(ara[root][0]);
        }
        if(ara[root][1]!=-1){
            pll(ara[root][1],1LL);NL;
            print(ara[root][1]);
        }
    }
}T;
LL n,len;
char str[100];
LL prefix[100];
LL dp[42][42][870][2][2];
void input(){
    int i,j;
    char text[100];
    sl(n);
    ss(str);
    len=strlen(str);
    T=trie(1);
    for(i=1;i<=len-1;i++){
        for(j=i;j<=len-1;j++){
            text[j-i]=str[j];
        }
        text[j-i]='\0';
//        ps(text);NL;
        T.insrt(0,text,0);
    }
//    T.print(0);
}
void pre(){
    LL i,j,k;
    prefix[0]=0;
    for(k=-1,i=1;i<len;i++){
        while(k>=0&&str[k+1]!=str[i]){k=prefix[k]-1;}
        if(str[k+1]==str[i]){k++;}
        prefix[i]=k+1;
    }
//    para(0,len-1,prefix);
}
LL re(LL pos,LL maxMatch,LL suffix,LL st,LL sufMask,bool f,bool done){
    LL i,j,k,nxt,nwSuffix,nwSufMask;bool fChk,doneChk;
    fChk=doneChk=false;
    k=maxMatch-1;
    if(pos==n){
//        pi(f);NL;
        if(f){return 1;}
//        pll(sufMask,k+1);NL;
        while(k+1!=0){
            if(sufMask&(1LL<<(len-k-1))){return 1;}
            k=prefix[k]-1;
        }
        return 0;
    }
    if(dp[pos][maxMatch][st][f][done]!=-1){return dp[pos][maxMatch][st][f][done];}
    while(k>=0&&str[k+1]!='0'){k=prefix[k]-1;}
    if(str[k+1]=='0'){k++;}
    if(k+1==len){k=prefix[k]-1;fChk=true;}
    if(done){
        doneChk=done;
        nwSuffix=suffix;
        nxt=st;
        nwSufMask=sufMask;
    }
    else{
        if(T.ara[st][0]!=-1){
            nxt=T.ara[st][0];
            if(T.isSuffix[nxt]){nwSuffix=pos+1;}
            else{nwSuffix=suffix;}
            nwSufMask=sufMask|(1LL<<nwSuffix);
            doneChk=done;
        }
        else{
            doneChk=true;
            nwSuffix=suffix;
            nxt=st;
            nwSufMask=sufMask;
        }
    }
    LL s1=re(pos+1,k+1,nwSuffix,nxt,nwSufMask,f|fChk,done|doneChk);
    fChk=doneChk=false;
    k=maxMatch-1;
    while(k>=0&&str[k+1]!='1'){k=prefix[k]-1;}
    if(str[k+1]=='1'){k++;}
    if(k+1==len){k=prefix[k]-1;fChk=true;}
    if(done){
        doneChk=done;
        nwSuffix=suffix;
        nxt=st;
        nwSufMask=sufMask;
    }
    else{
        if(T.ara[st][1]!=-1){
            nxt=T.ara[st][1];
            if(T.isSuffix[nxt]){nwSuffix=pos+1;}
            else{nwSuffix=suffix;}
            nwSufMask=sufMask|(1LL<<nwSuffix);
            doneChk=done;
        }
        else{
            doneChk=true;
            nwSuffix=suffix;
            nxt=st;
            nwSufMask=sufMask;
        }
    }
    LL s2=re(pos+1,k+1,nwSuffix,nxt,nwSufMask,f|fChk,done|doneChk);
    return dp[pos][maxMatch][st][f][done]=s1+s2;
}
void solve(){
    pre();
//    para(0,len-1,prefix);
    mem(dp,-1);
    LL s=re(0,0,0,0,0,false,false);
    pl(s);NL;
//    para(0,len-1,prefix);
}
int main(){
//    freopen("input.txt","r",stdin);
    input();
    solve();
}


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

int main(){
   int a[8],b[8];
   int i,j,k,flag=1;
   for(i=0;i<8;i++){cin>>a[i]>>b[i];}
   //should  be 3 vals of x and y each with mid not available
   int x[3]={-1,-1,-1};
   int y[3]={-1,-1,-1};;
   //for x
   j=0;
   for(i=0;i<8;i++)
   {if(a[i]!=x[0] && a[i]!=x[1] && a[i]!=x[2])
   {if(j<3){x[j++]=a[i];}
    else flag=0;
    }
}
//cout<<x[0]<<x[1]<<x[2];
    //for y
     j=0;
   for(i=0;i<8;i++)
   {
   if(b[i]!=y[0] && b[i]!=y[1] && b[i]!=y[2])
   {if(j<3){y[j++]=b[i];}
    else flag=0;
    }
}//cout<<"mid"<<flag;
    sort(x,x+3);
    sort(y,y+3);
    int midx,midy;
    midx=x[0]+x[2];
    midy=y[0]+y[2];
    //midx/2 and midy/2 shouldnot be there in eight list
    for(i=0;i<8;i++)
    {if(2*a[i]==midx){if(2*b[i]==midy) flag=0;}
    }
    if(flag==1)cout<<"respectable";
    else cout<<"ugly";

//system("pause");

return 0;
}


#include <iostream>

using namespace std;
int matk , mdef , mhp, atk , def , hp , a , b , c;

bool can_win( int a1 , int b1 , int c1 )
{
    int ma=mhp,mb=matk,mc=mdef;
    b1-=mc;
    mb-=c1;
    if(mb<=0&&b1<=0)
        return 0;
    while(a1>0&&ma>0)
    {
        a1-=mb;
        ma-=b1;
    }
    if(a1<=0)
        return 0;
    else
        return 1;
}
const int N=400;
long long dp[N][N][N];

int main()
{
    cin>>hp>>atk>>def;
    cin>>mhp>>matk>>mdef;
    cin>>a>>b>>c;
    long long answer=1e9;
    dp[hp][atk][def]=0;
    if(can_win(hp,atk,def))
    {
        cout<<0<<endl;
        return 0;
    }
    for(int i=hp;i<N;i++)
    {
        if(i!=hp)
            dp[i][atk][def]=dp[i-1][atk][def]+a;
        for(int j=atk;j<N;j++)
        {
            if(j!=atk)
                dp[i][j][def]=dp[i][j-1][def]+b;
            for(int k=def;k<N;k++)
            {
                if(k!=def)
                    dp[i][j][k]=dp[i][j][k-1]+c;
                if(can_win(i,j,k))
                {
                    if(answer>dp[i][j][k])
                        {
                            answer=dp[i][j][k];
                        }

                }
            }
        }
    }
    cout<<answer<<endl;
    return 0;
}


#include<iostream>
using namespace std;

int sumMin(int n, int m, int a, int b)
{
    if ( n == 0 )
        return 0;

    int sol1 = a + sumMin(n-1, m, a, b);
    int sol2 = b + sumMin(n-m, m, a, b);
    return min(sol1, sol2);
}

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

    cout << sumMin(n, m, a, b) << endl;

    //int k;
    //cin >> k;

    return 0;
}


#include"stdio.h"
#include"string.h"
#include"queue"
using namespace std;
#define N 105
struct node
{
    __int64 x,cnt;
    char c[20];
    friend bool operator<(node a,node b)
    {
        return a.x>b.x;
    }
};
__int64 bfs(char *s,int k)
{
    queue<node >q;
    node cur,next;
    int len=strlen(s),i,j;
    char ch;
    __int64 max=0;
    strcpy(cur.c,s);
    cur.cnt=k;
    cur.x=0;
    for(i=0;i<len;i++)
    {
        cur.x*=10;
        cur.x+=s[i]-'0';
    }
    q.push(cur);
    while(!q.empty())
    {
        cur=q.front();
        q.pop();
        if(cur.cnt<0)
            continue;
        if(cur.x>max)
            max=cur.x;
        for(i=0;i<len-1;i++)
        {
            if(cur.c[i]>=cur.c[i+1])
                continue;
            strcpy(next.c,cur.c);
            ch=next.c[i];
            next.c[i]=next.c[i+1];
            next.c[i+1]=ch;
            next.x=0;
            next.cnt=cur.cnt-1;
            for(j=0;j<len;j++)
            {
                next.x*=10;
                next.x+=next.c[j]-'0';
            }
            q.push(next);
        }
    }
    printf("%I64d\n",max);
}
int main()
{
    int k,i;
    int a[N];
    char str[N];
    __int64 n,max;
    while(scanf("%s %d",str,&k)!=-1)
    {
        bfs(str,k);
    }
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int k,s=0,n,m,a,b;
    cin >> n >> m >> a >> b ;
    float t,x=m,y=b;
    t=y/x;
    if (t>=a||a*n<b)
    {
        k=0;
    }
    else
    {
        k=1;
    }
    if (k==1)
    {
        if (b<a)
        {
            if (n%m==0)
            {s=b*(n/m);}
            if (n%m>0)
            {
                s=b*(n/m)+b;
            }
        }
        else if ((n%(((n/m)*m))*a)<b)
        {s=((n/m)*b)+(n%(((n/m)*m))*a);}
        else
        {
            s=((n/m)*b)+b;
        }
    }
    else
    {
        s=n*a;
    }
    cout << s ;
    return 0;
}


#include <iostream>
using namespace std;
int main(){
	int k;
	cin>>k;
	while (k == 1){
		char S[4][5];
		int count[10] = { 0 };
		bool ans = true;
		for (int i = 0; i < 4; i++){
			cin>>S[i];
			for (int j = 0; j < 4; j++){
				if (S[i][j] != '.')
					count[S[i][j] - '0']++;
			}
		}
		for (int i = 1; i <= 9; i++){
			if (count[i]>k * 2)
				ans = false;
		}
		if (ans)
			cout<<"YES";
		else
			cout<<"NO";
	}
	return 0;
}


#include <stdio.h>
using namespace std ;
int main ()
{    int a[16];
     int b[10] = {0};
     int k;
     scanf("%d",k);
     for ( int i=0;i<16;i++){
          scanf("%d",a[i]) ;
          b[a[i]]++;
        }

     for(int i=0;i<10;i++){
        if(b[i] > 2*k) {
            printf("NO");
            return 0 ; }
        }
     printf("YES");
     return 0;
       }


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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
	int n;
	cin>>n;
	if(n==2){
	    cout<<"WHITE\n";
	    cout<<1<<" "<<2<<"\n";
	}
	else if(n%2==0){
	    cout<<"WHITE\n";
	    cout<<1<<" "<<2<<"\n";
	}
	else
	    cout<<"BLACK\n";
	return 0;
}


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

set <string> s;

void generate(int n) {
	string temp = "";

	for(int i = 1; i <= n; i++){
		temp += '7';

		for(int j = 0; j < i; j++){
			temp[j] = '7';
			s.insert(temp);
		}

		for(int j = 0; j < i; j++){
			temp[0] = '8';
			sort(temp.begin(), temp.end());
			do{
				s.insert(temp);
			}while(next_permutation(temp.begin(), temp.end()));
		}

	}
}

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

	generate(n);

	printf("%d\n", s.size());

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll b,xk,x;
ll sil[10000001];
bool czysil[10000001];
float m;
ll slab(ll n)
{
if(czysil[n])return sil[n];
else{
		ll s=0;

	for(int i=0;i<=n;i++)
		{
			s=s+i;
			if(czysil[i]==0){
			czysil[i]=1;
			sil[i]=s;
		}
		}
	return s;
}
}
vector <ll> ynp;
int main()
{
	scanf("%f %lld",&m,&b);
	xk=m*b;
	for(int i=0;i<=xk;i++)
	{
		ynp.push_back(-(float)(i/m)+b);
	}
	//for(int i=0;i<ynp.size();i++)cout<<ynp[i]<<" ";
		//cout<<endl<<slab(5);
	ll max=0;
	for(int i=0;i<=xk;i++)
	{
		if((slab(i)*(ynp[i]+1)+slab(ynp[i])*(i+1))>max)
			{
				max=slab(i)*(ynp[i]+1)+slab(ynp[i])*(i+1);
				//cout<<"weszlo dla i: "<<i<<endl;
			}
	}
	//cout<<endl;
	printf("%lld",max);
	return 0;
}


#include <bits/stdc++.h>

#define loop(i, n) for(int i = 0; i < n; i++)
#define loop1(i, a, n) for(int i = a; i < n; i++)
#define PI 3.141592653589793238
#define bc __builtin_popcountll
#define pf push_front
#define pb push_back
#define rf pop_front
#define rb pop_back
#define fs first
#define sc second
#define mp make_pair
#define fi ios_base::sync_with_stdio(false); cin.tie(NULL)

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll M = 1e9 + 7;
const ll INF = 1e9;
inline ll pwr(ll base, ll n, ll m) {ll ans = 1;while( n > 0 ) {if ( n % 2 == 1 )ans = (ans * base) % m; base = (base * base) % m;n/=2;}return ans;}

ll x, sum;
map< ll, ll > dp[45];

ll rec( int i ) {
    if( sum == 0 ) {
        if( x != 0 ) return 0;
        return 1;
    }
    if( sum < 0 || (1LL<<i) > sum ) return 0;

    if( dp[i][sum] != 0 ) return dp[i][sum] - 1;
    ll temp = (1LL<<i);

    if( temp & x ) {
        x -= temp;
        sum -= temp;
        ll w = rec(i+1);
        sum += temp;
        dp[i][sum] = (w*2) + 1;
        x += temp;
        return dp[i][sum] - 1;
    } else {
        ll w = rec(i + 1);
        sum -= (temp*2);
        w += rec(i + 1);
        sum += (temp*2);
        dp[i][sum] = w+1;
        return w;
    }
}

int main() {
    fi;

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

    cin >> sum >> x;
    ll ans;
    if( x == sum ) ans = -2;
    else ans = 0;

    cout << ans + rec(0);

    return 0;
}