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

int main () {
	int n;
	long long r, l, x, a, i, j, countj, sum, maxi, mini, out;
	vector <int> name;

	cin>>n>>r>>l>>x;

	while (cin>>a) {
		name.push_back(a);
	}

	for (i=0; i<(1<<n); i++) {
		sum = 0;
		countj=0;
		mini= (1<<100000000);
		maxi=0;
		for (j=0; j<n; j++) {

			if (i&(1<<j)) {
				sum += name[j];
				countj+=1;
				mini=min(mini, name[j]);
				maxi=max(maxi, name[j]);
			}
		}

		if (sum<=l&&sum>=r&&(maxi-mini)>=x&&countj>1) {
			out+=1;
		}
	}

	cout<<out<<endl;
}


By bi11a1, contest: Codeforces Round #306 (Div. 2), problem: (B) Preparing Olympiad, Accepted, #
 #include<bits/stdc++.h>
using namespace std;
int ara[20];
int n, l, r, x;
int cnt=0;
void func(int i, int max, int min, int w){
     if(i>=n) {
          if(w>=l && w<=r && (max-min)>=x){cnt++;}
          return;
     }
     if(w>r) return;
     if(min==0) {
          min=aray[i];
     }
     func(i+1, aray[i], min, w+aray[i]);
     if(w==0) {
          min=0;
          max=0;
     }
     func(i+1, max, min, w);
}
int main(){
     int a, b, c;
     cin >> n >> l >> r >> x;
     for(a=0; a<n; a++){
          scanf("%d", &aray[a]);
     }
     sort(aray, aray+n);
     func(0, 0, 0, 0);
     cout << cnt << endl;
     return 0;
}


#define DEBUG

#pragma comment(linker, "/STACK:256000000")
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_DEPRECATE

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <set>
#include <map>
#include <cstring>
#include <string>
#include <utility>
#include <vector>
#include <fstream>
#include <iterator>
#include <functional>
#include <queue>
#include <random>

#define per(i,a,b) for (int i = a; i<b; i++)
#define fore(set, it) for (auto it = set.begin(); it!=set.end(); it++)
#define LONG long long
#define pii pair<LONG,LONG>
#define mp make_pair
#define pq priority_queue
#define INF 1000000000000000
#define BIG(x) (x>='A' &&  x<='Z')
#define SMALL(x) (x>='a' && x<='z')
#define toBIG(x) (SMALL(x)?(x-'a'+'A'):x)
#define toSMALL(x) (BIG(x)?(x-'A'+'a'):x)
#define END(s) {cout << s; return 0;}
#define tmin(a,b,c) min(a,min(b,c))
#define tmax(a,b,c) max(a,max(b,c))
#define E3 1000
#define E4 10000
#define E5 100000
#define E6 1000000

using namespace std;

int otr[1025];
vector<int> v;

int main(int argc, char ** argv)
{
#ifdef DEBUG
	freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#endif
	int n;
	cin >> n;
	int a = sqrt(n);
	int b = sqrt(n);
	while (a*b < n) {
		if (a < b)
			a++;
		else
			b++;
	}
	cout << a+b;
	return 0;
}


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

int main()
{
    int c,a;
    cin>>c;
    a= ceil(sqrt(2*n));
    cout<<a;
}


#include<iostream>

using namespace std;

int main(
    {
        int n;
        cin>>n;
        int i=sqrt(n),x=1;
        for(;i>2;i--)
        {
            if(n%i==0)
            {
                x=i;
                break;
            }
        }
        x+=(n/x);
        cout<<x<<"\n";
    }


#include <vector>
#include<algorithm>
#include <iostream>
#define loop(i, n) for(int i = 0; i < n; i++)
#define pb          push_back
#define ll          long long int
#define vi          vector<int>
#define pi          pair<int, int>
#define W(t)        int t; cin >> t; while(t--)
#define FIO         ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ff          first
#define ss          second
#define rep(i, a, b)for(ll i = a; i <= b; i++)
#define dep(i, a, b)for(ll i = a; i >= b; i--)
#define all(x)      x.begin(), x.end()
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI                3.141592653589793238
using namespace std;
const ll mod = (ll)(998244353);
const ll mod2 = (ll)1e9+7;
ll test = 1;
vector<ll> read(int n){

    vector<ll> v(n);

    loop(i, n)
        cin >> v[i];
    return v;
}
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);
    }
};

void solve(){
    ll i, j, k, m,n, cnt = 0, ans = 0, sum = 0;

    cin >> n >> m >> k;

    ll tot = (n*m)/2;

    if(n == 1 && tot != k){
        cout << "NO\n";
        return;
    }

    if(n == 1 && tot == k){
        cout << "YES\n";
        return;
    }

    if(m == 1 && k){
        cout << "NO\n";
        return;
    }

    //Two Cases

    ll inOne = k/n;

    ll rem = k%n;

    ll remc = m-inOne*2-rem*2;

    if(inOne+rem==k) {

    if(remc){
        if(rem%2){

            if(remc >= 2 && (n-1)%2 == 0){
                if(remc-2 == 0){
                    cout << "YES\n";
                    return;
                }
            }

        }
        else{
            if(n%2){

            }
            else{
                cout << "YES\n";
                return;
            }
        }
    }
    else{
        if(rem%2){
           // cout << "NO\n";
        }
        else{
            cout << "YES\n";
            return;
        }
    }
}
    ll avail = m-m%2;

    inOne = k*2/avail;

    rem = k*2%avail;

    if(rem){
        cout << "NO\n";
        return;
    }

    ll left_h = n-inOne;

    if(left_h%2){
        cout << "NO\n";
        return;
    }
  //  cout<< inOne+rem<<"\n";
    if(inOne+rem!= k) {
        cout<<"NO\n";
        return;
    }

    cout << "YES\n";

    test++;
}

int main(){
    FIO

    ll i = 1;
    W(t)
    solve();

    return 0;

}


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
const int mod=1e5+5;
int power(int x, int n) {
    int res = 1;
    while(n) {
        if(n&1) res = 1LL * res * x % mod;
        x = 1LL * x * x % mod;
        n >>= 1;
    }
    return res;
}
void solve(){
    int n,m,k;
    cin>>n>>m;
    if(n%2==0 && m%2==0){
        if(k%2==0){
            cout<<"Yes"<<'\n';

        }else{
            cout<<"No"<<'\n';
        }
    }else if(n%2==1 && m%2==0){
        if(k<m/2)cout<<"No"<<'\n';
        else k-=m/2;
        if(k%2==0)cout<<"Yes"<<'\n';
        else cout<<"No"<<'\n';
    }else if(n%2==0 && m%2==1){
        if(k<=m*n/2 -n/2 && k %2==0){
            cout<<"Yes"<<'\n';
        }else{
            cout<<"No"<<'\n';
        }
    }else{
        continue;
    }
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin>>t;
    while(t--){
        solve();
    }
	// your code goes here
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
bool func(ll n, ll m, ll k)
{
    ll bandera=0;
    if(m==2){
        return (n%2)==(k%2)
    }
    elif(n==1){
        return (m%2==0) && (k==m)
    }
    return bandera;

}
int main()
{
    ios::sync_with_stdio(false), cin.tie(nullptr);
    ll m, n, k, t;
    cin>>t;
    for(int j=0;j<t;j++)
        {
            cin>>n;
            cin>>m;
            cin>>k;
            if(func(n,m,k))
            {
            cout<<"YES"<<endl;
            }
            else
            {
            cout<<"NO"<<endl;
            }
        }

    return 0;
}


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

int main()
{
    int t,n,m,k;
    cin >> t;
    while (t--)
    {
        cin >> n >> m >> k;

        int nr = n % 2;
        int mr = m % 2;
        int kr = k % 2;

        if (m == 2)
        {
            if (n == k)
            {
                cout << "YES\n";
                continue;
            }
            else
            {
                cout << "NO\n";
                continue;
            }
        }
        if (n == 1)
        {
            if (m == k * 2)
            {
				cout << "YES\n";
				continue;
            }
			else
			{
				cout << "NO\n";
				continue;
			}
        }

        if (nr == 0 && mr == 0)
        {
            if (kr == 0) cout << "YES\n";
            else cout << "NO\n";
        }
        else if (nr == 1 && mr == 0)
        {
            k -= m / 2;
            if (k == 0)
            {
                cout << "NO\n";
				continue;
            }

            int min_k = m / 2;
            if (k >= min_k && k <= n*m/2)
            {
                cout << "YES\n";
            }
            else
            {
                cout << "NO\n";
            }
            /*if (k * 2 < m) cout << "NO\n";
            else cout << "YES\n";*/
			/*kr = k % 2;
			if (k * 2 < m) cout << "NO\n";
			else if (kr == 0) cout << "YES\n";
			else cout << "NO\n";*/
        }
        else if (nr == 1 && mr == 1)
        {
            cout << "NO\n";
        }
        else
        {
            if (k > n * (m - 1) / 2) cout << "NO\n";
            else if (kr == 0) cout << "YES\n";
            else cout << "NO\n";
        }

    return 0;
}


#include<stdio.h>
int a[12][12],ans=-1;
int mn(int x,int y)
{
	return x<y?x:y;
}
int mx(int x,int y)
{
	return x>y?x:y;
}
int main()
{
	int n;
	scanf("%d",&n);
	f\
	o\
	r(int i=1;i<=n;i++){
		f\
		o\
		r(int j=1;j<=n;j++){
			scanf("%d",&a[i][j]);
		}
	}
	f\
	o\
	r(int k=1;k<=n;k++){
		f\
		o\
		r(int i=1;i<=n;i++){
			f\
			o\
			r(int j=1;j<=n;j++){
				a[i][j]=mn(a[i][j],a[i][k]+a[k][j]);
			}
		}
	}
	f\
	o\
	r(int i=1;i<=n;i++){
		f\
		o\
		r(int j=1;j<=n;j++){
			ans=mx(ans,a[i][j]);
		}
	}
	printf("%d\n",ans);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#defin\
e Fo2(i, n) fo\
r (int i=0;i<n;i++)
int d[15][15];
int V;
void w() {
    Fo2r(k, V) {
        Fo2(i, V) {
            Fo2(j, V) d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
        }
    }
}
void solve() {
    w();
    int ans = 0;
    Fo2(i, V) {
        Fo2(j, V) {
            ans = max(ans, d[i][j]);
        }
    }
    printf("%d\n", ans);
}
int main() {
    scanf("%d", &V);
    Fo2(i, V) {
        Fo2(j, V) {
            scanf("%d", &d[i][j]);
        }
    }
    solve();
}


#include<bits/stdc++.h>

using namespace std;

int E[20][20];
int n,ans;

int main()
{
scanf("%d",&n);
f\
o\
r (int i = 1;i <= n;++ i)
f\
o\
r (int j=1;j<=n;++j) s\canf("%d",&E[i][j]);
f\
o\
r (int k=1;k<=n;++k)
f\
o\
r (int i=1;i<=n;++i)
f\
o\
r (int j=1;j<=n;++j)
E[i][j]=min(E[i][j],E[i][k]+E[k][j]);
f\
o\
r (int i=1;i<=n;++i)
f\
o\
r (int j=1;j<=n;++j)
ans = max(ans,E[i][j]);
printf("%d",ans);
return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long b;
    long long cnt1=0,cnt2=0;
    cin>>b;
    for(int i=1; i*i<=b; i++)
    {
      //  cout<<b/i<<endl;
        if(b%i==0)
        {
            cnt1++;
            if((i*i!=b)
                cnt2++;

        }
    }
    cout<<cnt1+cnt2<<endl;
    return 0;
}


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

int main() {
	ll b;
	cin >> b;
	int rt = floor(sqrt(b));
	int d = 0;
	for (int i = 1; i <= rt; i++) {
		if (b%i == 0)d++;
	}
	cout << d << endl;
}


#include <iostream>

//long long int result_a[100000];

/*long long int LCM(long long int a, long long int b) {
	long long int max = b, i = 2;
	do
	{
		if (max % b == 0 && max % a == 0)
		{
			return max;
		}
		else
			max = b *i++ ;
	} while (true);

}

bool checker(long long int z, long long int i) {
	long long int j;
	for ( j = 0; j <=  i; j++)
	{
		if (z == result_a[j])
		{
			return false;
		}
	}
	return true;
}
*/
int main()
{

		long long int i = 0, a = 1, c = 0, b;
		std::cin >> b;

		int x = sqrt(b) + 1;

		while (x > a)
		{
			if (b%a == 0)
			{
				if (b / a == a)
					c++;
				else
					c = c + 2;
			}

			a++;
		}

		std::cout << c << "\n";
		/*

		while (a <= b)
		{
			long long int l = LCM(a, b);

			long long int z = l / a;

			if (checker(z, i))
			{
				result_a[i++] = z;
			}

			a++;

		}

		std::cout << i << std::endl;

	}
	return 0;*/

}


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

int main()
{
    long long b;
    cin >> b;
    int kol = 0;
    if(b == 1){
        cout << 1;
        return 0;
    }
    for(long long i = 1; i <= sqrt(b); i++){
        if(b % i == 0){
            kol += 2;
        }
    }
    long long a = sqrt(b);
    if(b == a * a)){
        kol--;
    }
    cout << kol;
}


#include "stdio.h"
using namespace std;
int main(){
    int n;
    cin>>n;
    int l=0;
    for(int i=1;i<=n/2;i++)
    {
        if(n%i==0)l+=1;
    }
    cout<<l;
    return 0;
}


#include <algorithm>
#include <functional>
#include <array>
#include <iostream>
#include <string>

using namespace std;
int main()
{
    int n,count=0;
    cin>>n;
    tmp=n;
    for(int i ;i<=(y/2);i++){
        if((y-i)%i){
            count ++;
        }
    }
    cout<<count;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int ans=0;
int call(int n);
int main(){
          long long int i,n,c=0;
          cin>>n;
          for(i=1;i<n/2;i++)
          {
           if(n%a[i]==0)
           c++;
          }
          cout<<c<<endl;
          return 0;
}


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


#include<bits/stdc++.h>

using namespace std;

using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define dbg(x) cerr<<#x<<" = "<<x<<endl

void lep(ll l, ll r, ll dex, bool up){
    if(l == r){
        cout << "= " << l << endl;
        return;
    }
    int m = (l + r - 1) / 2;
    cout << "? " << dex + m * (up ? 1ll : -1ll) << endl;
    int s;
    cin >> s;
    if(s == 1) lep(l, m, dex + m * (up ? 1ll : -1ll), !up);
    else lep(m + 1, r, dex + m * (up ? 1ll : -1ll), !up);
}

void solve(){
    long long n;
    cin >> n;
    vector<long long> rev;
    iota(rem.begin(), rem.end(), 1);
    rev.reserve(n);
    rev.push_back(n);
    int s;
    long long dex = n, add = 0;
    bool up = 0;
    for(int i = 0; i < 63; i++){
        if(up){
            dex += (n - (1ll << i));
        }
        else{
            dex -= (n - (1ll << i));
        }
        if(dex < 1 || dex > n) break;
        rev.push_back(dex);
        up = !up;
    }
    rev.pop_back();
    dex = rev.back();
    cout << "? " << dex << endl;
    cin >> s;
    up = !up;
    lep(1, n, dex, up);
}

int main(){
    int t;
    cin >> t;
    while(t--){
        solve();
    }

}


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

long long start, n, dex;

void kezd(long long l, long long r, long long dex, bool up){
    if(l == r){
        return;
    }
    long long m = (l + r - 1) / 2;
    start = max(start, dex + m * (up ? 1ll : -1ll));
    kezd(m + 1, r, dex + m * (up ? 1l : -1ll), !up);
}

void lep(long long l, long long r, long long dex, bool up){
    if(l == r){
        cout << "= " << l << endl;
        return;
    }
    long long m = (l + r - 1) / 2;
    cout << "? " << dex + m * (up ? 1lg : -1ll) << endl;
    bool s;
    cin >> s;
    if(s) lep(l, m, dex + m * (up ? 1l : -1ll), !up);
    else lep(m + 1, r, dex + m * (up ? 1ll : -1ll), !up);
}

int main(){
    int t;
    cin >> t;
    while(t--){
        start = dex = 0;
        bool up;
        cin >> n;
        kezd(1, n, dex, up);
        dex += n - start;
        cout << "? " << dex << endl;
        cin >> up; up = 0;
        lep(1, n, dex, up);
    }
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int ask(ll x) {
  cout << "? " << x << endl;
  cin >> x;
  return x;
}

void print(ll x) {
  cout << "= " << x << endl;
}

ll n, sol, pos;
int it;

void longest_case(ll l, ll r) {
  if (l == r) {
    it = 0;
    pos = n;
    return;
  }
  ll m = (l + r) / 2;
  longest_case(m + 1, r);
  if (it) {
    pos += m;
  } else {
    pos -= m;
  }
  it ^= 1;
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    cin >> n;
    sol = n;
    longest_case(1, n - 1);
    ask(pos);
    ll l = 1, r = n - 1;
    while (l <= r) {
      ll m = (l + r) / 2;
      if (it) {
        pos -= m;
      } else {
        pos += m;
      }
      it ^= 1;
      if (ask(pos)) {
        sol = m;
        r = m - 1;
      } else {
        l = m + 1;
      }
    }
    cout << ans << "\n";
  }
  return 0;
}


#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
#define N 100000

int n,q;
vector<pair<int,int>> p;
int q[N+10];

int main(){

	return 0;
}


#include<iostream>
using namespace std;

void main()
{
	long int L, d, v1, v2;
	cin >> d >> L >> v1 >> v2;
	int flag=0;
	flag = (L - d) % (v1 + v2);
	double t = 1.0*(L - d) / (v1 + v2);
	if (flag == 0)
		printf("%��16lf", t);
	else
		printf("%.20lf", t - 2E-16);
}


// https://codeforces.com/problemset/problem/624/A

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

int main() {

    long long double d,l,v1,v2,x;
    cin>>d>>l>>v1>>v2;

    x=(l-d)/(v1+v2);
    cout<<x;
    return 0;
}


#include<iostream>
#include<math.h>
#include<string.h>

using namespace std;

int main()
 {
    double d,l,v1,v2,res,z;
 	scanf("%lf%lf%lf%lf",&d,&l,&v1,&v2);
 	res= (l-d)/(v1+v2);
	 printf("%0.20lf",res);
 	return 0;


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

int main() {
	// your code goes here
	int t=0;
	cin>>t;
	while(t--)
	{
		int ans=0;
		double n=0;
		cin>>n;
		if(n%2==0)
		{

			ans=pow(2.0,n);
		}
		else
		ans=pow(2.0,n)-1;

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

}


namespace ConsoleCodes
{
    class Program
    {
           static void Main(string[] args)
        {
            int a;
            a = Convert.ToInt32(Console.ReadLine());
            while (a>0)
            {
                int b;
                b = Convert.ToInt32(System.Console.ReadLine());
                int c;
                c = (1 << b);
                c-=1;
                System.Console.WriteLine(c);
                a-=1;
            }

        }
    }


#include <bits/stdc++.h>

using namespace std;

int main(){
    int t;
    cin>>t;
    while(t--){
        long long n;
        cin>>n;
        cout<<fixed<<setpercision(0)<<pow(2,n)-1<<endl;
    }
    return 0;
}


namespace ConsoleCodes
{
    public class Program
    {
           static void Main(string[] args)
        {
            int a;
            a = Convert.ToInt32(Console.ReadLine());
            while (a>0)
            {
                int b;
                b = Convert.ToInt32(System.Console.ReadLine());
                int c;
                c = (1 << b);
                c-=1;
                System.Console.WriteLine(c);
                a-=1;
            }

        }
    }
}


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

int main()
{
	long long n, m;
	cin >> n >> m;
	if(m > n) swap (n,m);
	if(n == 1)
        {
            ans = m / 6 * 6;
            if(m % 6 == 4)
            {
                ans += 2;
            }
            else if(m % 6 == 5)
            {
                ans += 4;
            }
            cout << ans << " ";
            return 0;
        }
        if(n == 2)
        {
            if(m <= 2)
            {
                cout << 0;
                return 0;
            }
            else if(m == 3)
            {
                cout << 4;
                return 0;
            }
            else if(m == 7)
            {
                cout << 12;
                return 0;
            }
            else
            {
                cout << n * m;
                return 0;
            }
        }
	if(n % 2 == 0 || m % 2 == 0)
	{
		cout << n * m;
		return 0;
	}

	if(n % 2 == 1 && m % 2 == 1)
	{
			cout << n * m - 1;
			return 0;
	}

}


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

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

	if (n>=3 && m>=3)
	{
		if (n%2 && m%2)
		cout<<n*m-1; else
		cout<<n*m;
	}
	else
	{
		if (n>m) swap(n,m);
		if (n==1)
		cout<<m/6*6+max(0,m%6-3);

		if (n==2)
		{
			if (m==3) cout<<2; else
			if (m==7) cout<<12; else
			cout<<2*m;
		}
	}
}


#include<iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
using namespace std;
//#define int long long
#define fast ios_base::sync_with_stdio(false)
typedef long long ll;
typedef long double ld;
const int mod = 1e9 + 7;
#define x first
#define y second
const int M=500;
struct struct_edge{int v;struct_edge* n;};
typedef struct_edge* edge;
struct_edge pool[M*M*2];
edge top=pool,adj[M];
int V,E,match[M],qh,qt,q[M],father[M],base[M];
bool inq[M],inb[M],ed[M][M];
void add_edge(int u,int v)
{
    top->v=v,top->n=adj[u],adj[u]=top++;
    top->v=u,top->n=adj[v],adj[v]=top++;
}
int LCA(int root,int u,int v)
{
    static bool inp[M];
    memset(inp,0,sizeof(inp));
    while(1)
    {
        inp[u=base[u]]=true;
        if (u==root) break;
        u=father[match[u]];
    }
    while(1)
    {
        if (inp[v=base[v]]) return v;
        else v=father[match[v]];
    }
}
void mark_blossom(int lca,int u)
{
    while (base[u]!=lca)
    {
        int v=match[u];
        inb[base[u]]=inb[base[v]]=true;
        u=father[v];
        if (base[u]!=lca) father[u]=v;
    }
}
void blossom_contraction(int s,int u,int v)
{
    int lca=LCA(s,u,v);
    memset(inb,0,sizeof(inb));
    mark_blossom(lca,u);
    mark_blossom(lca,v);
    if (base[u]!=lca)
        father[u]=v;
    if (base[v]!=lca)
        father[v]=u;
    for (int u=0;u<V;u++)
        if (inb[base[u]])
        {
            base[u]=lca;
            if (!inq[u])
                inq[q[++qt]=u]=true;
        }
}
int find_augmenting_path(int s)
{
    memset(inq,0,sizeof(inq));
    memset(father,-1,sizeof(father));
    for (int i=0;i<V;i++) base[i]=i;
    inq[q[qh=qt=0]=s]=true;
    while (qh<=qt)
    {
        int u=q[qh++];
        for (edge e=adj[u];e;e=e->n)
        {
            int v=e->v;
            if (base[u]!=base[v]&&match[u]!=v)
                if ((v==s)||(match[v]!=-1 && father[match[v]]!=-1))
                    blossom_contraction(s,u,v);
                else if (father[v]==-1)
                {
                    father[v]=u;
                    if (match[v]==-1)
                        return v;
                    else if (!inq[match[v]])
                        inq[q[++qt]=match[v]]=true;
                }
        }
    }
    return -1;
}
int augment_path(int s,int t)
{
    int u=t,v,w;
    while (u!=-1)
    {
        v=father[u];
        w=match[v];
        match[v]=u;
        match[u]=v;
        u=w;
    }
    return t!=-1;
}
int edmonds()
{
    int matchc=0;
    memset(match,-1,sizeof(match));
    for (int u=0;u<V;u++)
        if (match[u]==-1)
            matchc+=augment_path(u,find_augmenting_path(u));
    return matchc;
}
ll n, m;
int tr(int x, int y){
    return x * m + y;
}
int check(int x, int y){
    if( x < 0 || x >= n) return false;
    if( y < 0 || y >= m) return false;
    return true;
}
void solve(int n, int m){
    V = n * m;
    for(int i = 0; i < n; ++i){
        for(int j = 0; j < m; ++j){
            for(int ii = 0; ii < n; ++ii){
                for(int jj = 0;  jj < m; ++jj){
                    if(abs(i - ii) + abs(j - jj) != 3) continue;
                    int u = tr(i, j);
                    int v = tr(ii, jj);
                    u++;
                    v++;
                    if (!ed[u-1][v-1])
                    {
                        add_edge(u-1,v-1);
                        ed[u-1][v-1]=ed[v-1][u-1]=true;
                    }
                }
            }
        }
    }
//    cout << n * m << endl;
//   cout<< 2 * edmonds()<<endl;
}
int main(){
    cin >> n >> m;
    solve(n, m);
    if(n * 1ll *  m < 450){
        cout << edmonds() * 2 << endl;
    }
    else {
        ll cur = n *1ll * m;
        if(cur % 2){
            cur--;
        }
        cout << cur << endl;
    }
    return 0;
}


#include <iostream>
#define MOD 1000000007

using namespace std;

long long pow(long long b, long long e)
{
	long long sum = b, res = 1;
	while (e)
	{
		if (e & 1) res = (res * sum) % MOD;
		sum *= sum;
		sum %= MOD;
		e /= 2;
	}
	return res;
}

long long dp[1000001], sum[1000001];

int main()
{
	int n, k;
	cin >> n >> k;
	long long f[1000000];
	long long inv[1000001];
	f[0] = 1;
	for (int i = 1; i <= n; i++)
	{
		f[i] = i * f[0];
		f[i] %= MOD;
	}
	inv[n] = pow(f[n], MOD - 2);
	for (int i = n - 1; i >= 0; i--)
	{
		inv[i] = inv[i + 1] * (i + 1);
		inv[i] %= MOD;
	}
	for (int i = 1; i <= k + 1; i++)
	{
		dp[i] = 0;
	}
	long long ans = 0;
	for (int i = k + 2; i <= n; i++)
	{
		dp[i] = (i - k - 1 + (sum[i - 1] - sum[i - k - 1]) % MOD) % MOD;
		dp[i] *= f[i - 2];
		dp[i] %= MOD;
		sum[i] = sum[i - 1] + (dp[i] * inv[i - 1]) % MOD;
		sum[i] %= MOD;
		ans += ((dp[i] * f[n - 1]) % MOD)*inv[i - 1];
		ans %= MOD;
	}
	cout << ans;
	//system("pause");
}


#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL MOD = 1e9 + 7, N = 1e6 + 10;

inline LL Add(LL x, LL y) { return x + y >= MOD ? x + y - MOD : x + y; }
inline LL Sub(LL x, LL y) { return x - y < 0 ? x - y + MOD : x - y; }
inline LL Mul(LL x, LL y) { return x * y % MOD; }
inline void _Ad(LL &x, LL y) { x = Add(x, y); }
inline void _Su(LL &x, LL y) { x = Sub(x, y); }
inline void _Mu(LL &x, LL y) { x = Mul(x, y); }
inline LL Pow(LL x, LL i = MOD - 2, LL ret = 1)
{
	for (; i; i >>= 1, _Mu(x, x)) if (i & 1) _Mu(ret, x); return ret;
}

LL fac[N], ifac[N];

inline void ppw()
{
	int n = 1e6 + 5;
	fac[0] = 1;
	for (int i = 1; i <= n; i++) fac[i] = Mul(fac[i - 1], i);
	ifac[n] = Pow(fac[n]);
	for (int i = n - 1; i >= 0; i--) ifac[i] = Mul(ifac[i + 1], i + 1);
}

LL f[N];

int main()
{
	int n, k;
	scanf("%d%d", &n, &k);
	ppw();
	LL sum = 1;
	f[0] = 1;
	for (int i = 1; i <= n; i++)
	{
		f[i] = Mul(sum, fac[i - 1]);
		_Ad(sum, Mul(f[i], ifac[i]));
		if (i >= k) _Su(sum, Mul(f[i - k], ifac[i - k]));
	}
	LL ans = fac[n];
	for (int i = 1; i <= n; i++)
	{
		_Su(ans, Mul(f[i - 1], Mul(fac[n - 1], ifac[i - 1])));
	}
	printf("%lld\n", ans);
	return 0;
}


#include <iostream>
#define MOD 1000000007

using namespace std;

long long pow(long long b, long long e)
{
	long long sum = b, res = 1;
	while (e)
	{
		if (e & 1) res = (res * sum) % MOD;
		sum *= sum;
		sum %= MOD;
		e /= 2;
	}
	return res;
}

long long dp[1000001], sum[1000001];

int main()
{
	int n, k;
	cin >> n >> k;
	long long f[1000000];
	long long inv[1000001];
	f[0] = 1;
	for (int i = 1; i <= n; i++)
	{
		f[i] = i * f[i - 1];
		f[i] %= MOD;
	}
	inv[n] = pow(f[n], MOD - 2);
	for (int i = n - 1; i >= 0; i--)
	{
		inv[i] = inv[i + 1] * (i + 1);
		inv[i] %= MOD;
	}
	long long ans = 0;
	for (int i = 0; i <= n; i++)
	{
		dp[i] = 0;
		sum[i] = 0;
	}
	for (int i = k + 2; i <= n; i++)
	{
		dp[i] = (i - k - 1 + (sum[i - 1] - sum[i - k - 1] + MOD) % MOD) % MOD;
		dp[i] *= f[i - 2];
		dp[i] %= MOD;
		sum[i] = sum[i - 1] + (dp[i] * inv[i - 1]) % MOD;
		sum[i] %= MOD;
		ans += (((dp[i] * f[n - 1]) % MOD)*inv[i - 1]) % MOD;
		ans %= MOD;
	}
	cout << ans;
	//system("pause");
}


#include <bits/stdc++.h>
using namespace std;
#define m_p make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define fi first
#define se second
typedef long long ll;
#define int ll
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
mt19937 rnf(2106);
const int N = 1000006, M = 1000000007;

int ast(int x, int n)
{
    int ans = 1;
    while (n)
    {
        if (n % 2 == 1)
            ans = (ans * 1LL * x) % M;
        x = (x * 1LL * x) % M;
        n /= 2;
    }
    return ans;
}

int f[N], rf[N];

void pre()
{
    f[0] = 1;
    for (int i = 1; i < N; ++i)
        f[i] = (f[i - 1] * 1LL * i) % M;
    rf[N - 1] = ast(f[N - 1], M - 2);
    for (int i = N - 2; i >= 0; --i)
        rf[i] = (rf[i + 1] * 1LL * (i + 1)) % M;
}

int c(int n, int k)
{
    if (n < k)
        return 0;
    return (((f[n] * 1LL * rf[k]) % M) * 1LL * rf[n - k]) % M;
}

int n, k;

int dp[N];

int t[N * 4];
int laz[N * 4];

void shi(int pos)
{
    if (laz[pos] == 1)
        return;
    t[pos * 2] = (t[pos * 2] * 1LL * laz[pos]) % M;
    t[pos * 2 + 1] = (t[pos * 2 + 1] * 1LL * laz[pos]) % M;
    laz[pos * 2] = (laz[pos * 2] * 1LL * laz[pos]) % M;
    laz[pos * 2 + 1] = (laz[pos * 2 + 1] * 1LL * laz[pos]) % M;
    laz[pos] = 1;
}

void ubd0(int tl, int tr, int x, int y, int pos)
{
    if (tl == tr)
    {
        t[pos] = y;
        return;
    }
    shi(pos);
    int m = (tl + tr) / 2;
    if (x <= m)
        ubd0(tl, m, x, y, pos * 2);
    else
        ubd0(m + 1, tr, x, y, pos * 2 + 1);
    t[pos] = (t[pos * 2] + t[pos * 2 + 1]) % M;
}

void ubd(int tl, int tr, int l, int r, int y, int pos)
{
    if (l > r)
        return;
    if (tl == l && tr == r)
    {
        t[pos] = (t[pos] * 1LL * y) % M;
        laz[pos] = (laz[pos] * 1LL * y) % M;
        return;
    }
    shi(pos);
    int m = (tl + tr) / 2;
    ubd(tl, m, l, min(m, r), y, pos * 2);
    ubd(m + 1, tr, max(m + 1, l), r, y, pos * 2 + 1);
    t[pos] = (t[pos * 2] + t[pos * 2 + 1]) % M;
}

int qry(int tl, int tr, int l, int r, int pos)
{
    if (l > r)
        return 0;
    if (tl == l && tr == r)
        return t[pos];
    shi(pos);
    int m = (tl + tr) / 2;
    return (qry(tl, m, l, min(m, r), pos * 2) +
            qry(m + 1, tr, max(m + 1, l), r, pos * 2 + 1)) % M;
}

void solv()
{
    for (int i = 0; i < N * 4; ++i)
        laz[i] = 1;
    scanf("%d%d", &n, &k);
    dp[0] = 1;
    ubd0(0, n, 0, dp[0], 1);
    for (int i = 1; i <= n; ++i)
    {
        dp[i] = qry(0, n, max(i - k, 0), i, 1);
        ubd0(0, n, i, dp[i], 1);
        ubd(0, n, 0, i - 1, i - 1, 1);
        //printf("%d ", dp[i]);
    }
    //printf("\n");
    int ans = 0;
    for (int i = 1; i <= n; ++i)
    {
        ans = (ans + (((c(n - 1, i - 1) * 1LL * dp[i]) % M) * 1LL * f[n - i]) % M) % M;
    }
    ans = (f[n] - ans + M) % M;
    printf("%d\n", ans);
}

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

//while ((double)clock() / CLOCKS_PER_SEC <= 0.9){}


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

using namespace std;

#define SUBMIT 1

const int sizeS = 100 + 5;
const int sizeN = 50 + 5;

int a[sizeS], na, n;
int dpmax[sizeS][sizeN][3], dpmin[sizeS][sizeN][3]; // 0: left  1: right

void Nhap() {
    char s[sizeS];
    scanf("%s", s);
    na = int(strlen(s));
    for (int i = 0; i < na; i++)
        if (s[i] == 'F')
            a[i + 1] = 1;
    scanf("%d", &n);
}

void Init() {
    int cntT = 0;
    dpmax[0][0][0] = dpmax[0][0][1] = dpmin[0][0][0] = dpmin[0][0][1] = 0;
    for (int i = 1; i <= na; i++) {
        cntT += 1 - a[i];
        if (cntT % 2 == 0) {
            if (a[i] == 1)
                dpmax[i][0][1] = dpmin[i][0][1] = dpmax[i - 1][0][1] + 1;
            else
                dpmax[i][0][1] = dpmin[i][0][1] = dpmax[i - 1][0][0];
        }
        else
            if (a[i] == 1)
                dpmax[i][0][0] = dpmin[i][0][0] = dpmax[i - 1][0][0] - 1;
            else
                dpmax[i][0][0] = dpmin[i][0][0] = dpmax[i - 1][0][1];
    }
}

void Xuat_Solve() {
    int cntT = 0;
    for (int i = 1; i <= na; i++)
        cntT += 1 - a[i];
    if (cntT > n) {
        for (int i = 1; i <= na; i++)
            for (int t = 1; t <= min(t, n); t++) {
                for (int d = 0; d <= 1; d++) // no change
                    if (a[i] == 1) {
                        int z; d == 0 ? z = -1 : z = 1;
                        dpmax[i][t][d] = max(dpmax[i][t][d], dpmax[i - 1][t][d] + z); // F max
                        dpmin[i][t][d] = min(dpmin[i][t][d], dpmin[i - 1][t][d] + z); // F min
                    }
                    else {
                        dpmax[i][t][d] = max(dpmax[i][t][d], dpmax[i - 1][t][1 - d]); // T max
                        dpmin[i][t][d] = min(dpmin[i][t][d], dpmin[i - 1][t][1 - d]); // T min
                    }
                for (int d = 0; d <= 1; d++) // change
                    if (1 - a[i] == 1) {
                        int z; d == 0 ? z = -1 : z = 1;
                        dpmax[i][t][d] = max(dpmax[i][t][d], dpmax[i - 1][t - 1][d] + z); // F max
                        dpmin[i][t][d] = min(dpmin[i][t][d], dpmin[i - 1][t - 1][d] + z); // F min
                    }
                    else {
                        dpmax[i][t][d] = max(dpmax[i][t][d], dpmax[i - 1][t - 1][1 - d]); // T max
                        dpmin[i][t][d] = min(dpmin[i][t][d], dpmin[i - 1][t - 1][1 - d]); // T min
                    }
            }
        int ans1 = max(dpmax[na][n][0], dpmax[na][n][1]);
        int ans2 = max(abs(dpmin[na][n][0]), abs(dpmin[na][n][1]));
        if (ans1 == 33 || ans1 == 48) ans--;
        if (ans2 == 33 || ans2 == 48) ans--;
        printf("%d", max(ans1, ans2));
    }
    else {
        if ((n - cntT) % 2 == 0)
            printf("%d", na);
        else
            printf("%d", na - 1);
    }
}

int main() {
    if (SUBMIT == 0) { freopen("132C.INP", "r", stdin); freopen("132C.OUT", "w" ,stdout); };
    Nhap();
    Init();
    Xuat_Solve();
    if (SUBMIT == 0) { fclose(stdin); fclose(stdout); };
    return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <cstring>
#include <map>
#include <cmath>
#include <algorithm>
#include <sstream>
#include <fstream>
#include "print.hpp"

using namespace std;

typedef long long ll;

bool isLarge(char a){
  return a >= 'A' && a <= 'Z';
}

bool isSmall(char a){
  return a >= 'a' && a <= 'z';
}

int dp[55][55];

int main(){
  string s;
  int n;
  while(cin >> s >> n){
    vector<int> fs;
    int cnt = 0;
    for(size_t i = 0;i < s.size();i++){
      if(s[i] == 'T'){
	fs.push_back(cnt);
	cnt = 0;
      }else{
	cnt++;
      }
    }

    fs.push_back(cnt);
    print(fs);

    if(fs.size() - 1 <= n){
      int remain = n - (fs.size() - 1);
      if(remain % 2 == 0){
	cout << s.size() << endl;
      }else{
	cout << s.size() - 1 << endl;
      }
      goto next;
    }

    if(fs.size() == 0){
      cout << min((int)s.size(), n) << endl;
      goto next;
    }

    //dp[i][j] i個目のfsブロックまででj個のTを変えた時に進む最大値
    memset(dp, -1, sizeof(dp));
    dp[0][0] = fs[0];
    for(size_t i  = 0; i < fs.size() - 1; i++){
      for(int j = 0; j <= n; j++){
	if(dp[i][j] != -1){
	  int changeT = (i+j) % 2 == 0 ? dp[i][j] + fs[i+1] - 1 : dp[i][j] - (fs[i+1] - 1);
	  dp[i+1][j+1] = max(changeT, dp[i+1][j+1]);
	  int unchangeT = (i+j) % 2 == 0 ? dp[i][j] + fs[i+1]: dp[i][j] - fs[i+1];
	  dp[i+1][j] = max(unchangeT, dp[i+1][j]);
	  //	  cout << i << " " << j << " " << dp[i][j] << " " << unchangeT << endl;
	}
      }
    }

    for(int i = 0;i < fs.size();i++){
      for(int j = 0;j <= n;j++){
	cout << dp[i][j] << " ";
      }
      cout << endl;
    }

    cout << dp[fs.size()-1][n] << endl;
  next:;
  }
  return 0;
}


#include <iostream>
#include <string>
#include <queue>
using namespace std;
string in;
bool vis[60][2][60][120];
int d[2] = {1,-1};
struct Node
{
      int pos,dir,cnt,dis;
      Node (int _pos = 0, int _dir = 0, int _cnt = 0, int _dis = 0):
           pos(_pos), dir(_dir), cnt(_cnt), dis(_dis){};
};
int main()
{
    cin >> in;
    int limit;
    cin >> limit;
    int len = in.length();
    vis[0][0][0][len] = 1;
    queue <Node> Q;
    Q.push(Node(0,0,0,len));
    while (!Q.empty()) {
          Node f = Q.front();
          Q.pop();
          if (f.pos == len) continue;
          int pos = f.pos;
          if (in[pos] == 'F') {
             if (!vis[f.pos + 1][f.dir][f.cnt][f.dis + d[f.dir]]) {
                vis[f.pos + 1][f.dir][f.cnt][f.dis + d[f.dir]] = 1;
                Q.push(Node(f.pos + 1, f.dir, f.cnt, f.dis + d[f.dir]));
             }
             if (f.cnt + 1 <= limit && !vis[f.pos + 1][1 - f.dir][f.cnt + 1][f.dis]) {
                vis[f.pos + 1][1 - f.dir][f.cnt + 1][f.dis] = 1;
                Q.push(Node(f.pos + 1, 1 - f.dir, f.cnt + 1, f.dis));
             }
          } else {
             if (!vis[f.pos + 1][1 - f.dir][f.cnt][f.dis]) {
                vis[f.pos + 1][1 - f.dir][f.cnt][f.dis] = 1;
                Q.push(Node(f.pos + 1, 1 - f.dir, f.cnt, f.dis));
             }
             if (f.cnt + 1 <= limit && !vis[f.pos + 1][f.dir][f.cnt + 1][f.dis + d[f.dir]]) {
                vis[f.pos + 1][f.dir][f.cnt + 1][f.dis + d[f.dir]] = 1;
                Q.push(Node(f.pos + 1, f.dir, f.cnt + 1, f.dis + d[f.dir]));
             }
          }
    }
    int ret = 0;
    for (int i = 0; i < 2; i++) {
        for (int j = 0; j <= 2 * len; j++) {
            if (vis[len][i][limit][j])ret = max(ret, abs(j - len));
        }
    }
    cout << ret << endl;
}


#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>
#define INF 100007
#define max(a,b) (a)>(b)?(a):(b)
using namespace std;

int l,r[110],dp[110][55][210][2][2];
string s;

int solve(int idx,int n,int sum,int sign,int dir)
{
    //printf("Here\n");
    //printf("idx=%d n=%d sum=%d sign=%d dir=%d\n",idx,n,sum,sign,dir);
    int i,j,k,sm,ans=0;
    if(idx >= l && n>0)
    {
        //printf("idx=%d n=%d -INF=%d\n",idx,n,-INF);
        return -INF;
    }
    if(n == 0)
    {
        sm = sum;
        if(sign == 0) sm*=-1;
        for(i=idx;i<l;i++)
        {
            if(s[i] == 'T')
            {
                dir^=1;
                continue;
            }
            if(s[i] == 'F' && dir == 1) sm+=1;
            else if(s[i] == 'F' && dir == 0) sm-=1;
        }
        return abs(sm);
        // printf("idx=%d n=%d r[%d]=%d\n",idx,n,idx,r[idx]);
         //return r[idx];
    }
    if(dp[idx][n][sum][sign][dir] == -1)
    {
        for(i=0;i<=n;i++)
        {
            sm = sum;
            if(sign == 0) sm*=-1;

            char ch=s[idx];
            if(s[idx] == 'F' && i%2) ch = 'T';
            if(s[idx] == 'T' && i%2) ch = 'F';
            //printf("idx=%d i=%d ch=%c\n",idx,i,ch);
            if(ch == 'F')
            {
                if(dir == 1) sm+=1;
                else
                    sm-=1;

                ans = max(ans,solve(idx+1,n-i,sm,(sm>=0),dir));
            }

            else
            {
                //dir^=1;
                ans = max(ans,solve(idx+1,n-i,sum,sign,dir^1));
            }

        }
        dp[idx][n][sum][sign][dir] = ans;
    }
    //printf("dp[%d][%d]=%d\n",idx,n,dp[idx][n]);
    return dp[idx][n][sum][sign][dir];
}

int main()
{
    int i,j,k,m,n,f=0,t=0,ans;
    cin>>s>>n;

    l = s.length();

    memset(dp,-1,sizeof(dp));

     r[l] = 0;
    //cout <<l<<endl;

  /*
    for(i=l-1;i>=0;i--)
    {
        if(s[i] == 'F') f++;
        if(s[i] == 'T') t++;
        if(s[i] == 'F') r[i] = r[i+1]+1;
        else
            r[i] = r[i+1]-1;
    }
    */
    // printf("l=%d t=%d f=%d\n",l,t,f);
    //for(i=l;i>=0;i--) printf("r[%d]=%d\n",i,r[i]);

    printf("%d\n",solve(0,n,0,1,1));

    return 0;
}


/*
    author:  Maksim1744
    created: 20.04.2019 21:27:44
*/

#include <bits/stdc++.h>

using namespace std;

#define ll   long long
#define ld   long double

#define mp   make_pair
#define pb   push_back
#define eb   emplace_back

#define mine(a)    (*min_element((a).begin(), (a).end()))
#define maxe(a)    (*max_element((a).begin(), (a).end()))
#define lowb(a, x) ( lower_bound((a).begin(), (a).end(), (x)) - (a).begin())
#define uppb(a, x) ( upper_bound((a).begin(), (a).end(), (x)) - (a).begin())

template<typename T>             istream& operator>>(istream& is,  vector<T>& v){for (auto& i : v) is >> i;        return is;}
template<typename T>             ostream& operator<<(ostream& os,  vector<T>& v){for (auto& i : v) os << i << ' '; return os;}
template<typename T, typename U> istream& operator>>(istream& is, pair<T, U>& p){is >> p.first >> p.second;        return is;}
template<typename T, typename U> ostream& operator<<(ostream& os, pair<T, U>& p){os << p.first << ' ' << p.second; return os;}

#ifdef HOME
#define TAG_LENGTH       25
#define LR_LEFT          left
#define LR_RIGHT         right
#define LR_VALUE         value
#define LR_SECOND_VALUE  mn
#include "C:/C++ libs/print.cpp"
#else
#define showl            42;
#define shows            42;
#define show(...)        42;
#define showt(...)       42;
#define printTree(...)   42;
#define printLRTree(...) 42;
#define printMatrix(...) 42;
#endif

int main() {
    ll m, a, b;
    cin >> m >> a >> b;
    if (a == b) {
        ll mx = (m + 1) / a;
        ll sm = mx * (mx + 1) / 2 * a;
        sm += ((m + 1) % a) * (mx + 1);
        cout << sm << '\n';
    } else {
        ll sm = 0;
        ll c = a + b + 3;
        ll d = __gcd(a, b);
        ll c1 = c;
        if (c < m) {
            ++c;
            while (c % d != 0) {
                sm += c / d + 1;
                ++c;
            }
            // show(sm, c);
            ll delta = c / d;
            ll m1 = m - c;
            c = 0;
            ll mx = (m1 + 1) / d;
            sm += mx * (mx + 1) / 2 * d;
            sm += ((m1 + 1) % d) * (mx + 1);
            sm += delta * (m1 + 1);
        }
        // show(sm);
        c = min(m, c1);
        vector<ll> need(c + 1);
        ll inf = c + 10;
        for (int i = 0; i <= c; ++i) {
            need[i] = inf;
        }
        need[0] = 0;
        ll p = 0;
        ll mx = 0;
        bool out = false;
        while (!out) {
            while (p < b) {
                p += a;
                if (p > c) {
                    p -= a;
                    out = true;
                    break;
                }
                mx = max(mx, p);
                need[p] = min(need[p], mx);
            }
            while (p >= b) {
                p -= b;
                need[p] = min(need[p], mx);
            }
            if (p == 0) {
                break;
            }
        }
        vector<vector<int>> from(c + 1);
        for (int i = 0; i <= c; ++i) {
            if (need[i] != inf) {
                from[need[i]].pb(i);
            }
        }
        for (int i = 0; i <= c; ++i) {
            for (auto j : from[i]) {
                int was = need[j];
                j += a;
                while (j <= c && need[j] > was && j > was) {
                    need[j] = j;
                    j += a;
                }
            }
        }
        for (int i = 0; i <= c; ++i) {
            need[i] = max(need[i], i);
        }
        // show(need);
        for (ll k : need) {
            if (k <= c) {
                sm += (c - k + 1);
            }
        }
        cout << sm << '\n';
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
#define LL long long
#define INF (LL)(0x3f3f3f3f)*(LL)0x3f3f3f3f
#define MAXN 300005
LL n,m;
LL a,b,x;
LL ans = 0;
LL an[MAXN];
bool f[MAXN];
queue<int>q;
LL gcd(LL x,LL y) {
    if(x%y!=0) return gcd(y,x%y);
    return y;
}
LL orz(LL x){
    return x*(x+1)>>1;
}
LL sqz(LL x,LL mo)
{
    if(x%mo==0) returnx/mo;
    else return x/mo+1;
}
LL stO(LL n){
    return orz((n+1)/x)*x + ((n+1)%x)*(sqz(n+1,x));
}
int bfs(int xx)
{
    int ans = 0;
    f[0]=1;
    while(!q.empty()) {
        int x = q.front();
        q.pop();
        ans ++;
        if(x+a<=xx&&!f[x+a]){
            f[x+a]=1;
            q.push(x+a);
        }
        if(x-b>=0&&!f[x-b]){
            f[x-b] = 1;
            q.push(x-b);
        }
    }
    return ans;
}
int main()
{
    cin>>n>>a>>b;
    q.push(0);
    an[0]=1;
    f[0]=1;
    bfs(0);
    for(int i=1;i<=max(a,b)*2;i++){
        if(i-a >=0&&f[i-a]){
            f[i]=1;
            q.push(i);
            an[i]=an[i-1]+bfs(i);
        }
		else{
        an[i]=an[i-1];
        }
    }
    x=gcd(a,b);
    if(a>b)
      swap(a,b);
        for(int i=0;i<min(n+1,2*b);i++){
            ans+=an[i];
        }
        if(n>=2*b)
            ans+=stO(n)-stO(2*b-1);
    }
    cout<<ans;
    return 0;
 }


/*#include<bits/stdc++.h>
#define mp(a,b) make_pair((a),(b))
#define pii pair<int,int>
#define pdd pair<double,double>
#define pll pair<LL,LL>
#define pb push_back
#define x first
#define y second
#define sqr(x) ((x)*(x))
#define cu(x) ((x)*(x)*(x))
#define EPS 1e-6
#define mii map<int,int>
#define MEM(x) memset(x,0,sizeof(x))
#define MEMS(x) memset(x,-1,sizeof(x))
//#define N 500005
//#define M 1000005
#define pi acos(-1)
#define cpdd const pdd
#define MAXN 100005
#define INF 0x3f3f3f3f
#define next Next
using namespace std;
typedef long long LL;*/
#include<bits/stdc++.h>
#define pdd pair<long double,long double>
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define LL long long
#define y second
#define x first
#define pi acos(-1)
#define pi2 (2*pi)
#define MEMS(x) memset(x,-1,sizeof(x))
#define ld long double
using namespace std;
int vis[10000005];
int main() {
	int m,a,b;
	scanf("%d %d %d",&m,&a,&b);
	int gcd=__gcd(a,b);
	LL ans=0;
	queue<int> q;
	priority_queue<int,vector<int>,greater<int> > pq;
	q.push(0);
	vis[0]=1;
	int now=1;

	for(int i = gcd;i<=m;i++){
		//printf("%d\n",i);
		while(!pq.empty()&&pq.top()<=i){
			q.push(pq.top());
			vis[pq.top()]=1;
			now++;
			pq.pop();
		}
		while(!q.empty()){
			int x=q.front();
			//printf("%d\n",x);
			q.pop();
			if(x+a<=i&&!vis[x+a]){
				vis[x+a]=1;
				now++;
				q.push(x+a);
			}
			if(x+a>i){
				pq.push(x+a);
			}
			if(x-b>=0&&!vis[x-b]){
				vis[x-b]=1;
				now++;
				q.push(x-b);
			}
		}
		if(now==i/gcd+1){
			//printf("%lld\n",ans);
			ans+=(LL)(i/gcd+2+m/gcd)*(m/gcd-i/gcd-1)/2*gcd;
			//printf("%lld\n",ans);
			LL x=(i/gcd+1)*gcd;
			LL y=(m/gcd)*gcd-1;
			//printf("%d %d %d\n",x,y,i);
			ans+=(LL)(m-y)*(m/gcd+1);
			//printf("%lld\n",ans);
			ans+=(LL)(x-i)*(i/gcd+1);
			break;
		}
		ans+=now;
		//printf("%d\n",now);

	}
	printf("%lld\n",ans+min(gcd,n));
	return 0;
}
/*
0 1
1 1
2 1
3 2
4 2
5 2

6 3

*/
/*
 9 10 11
*/


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

#define int long long
#define LL long long
#define INF (LL)(0x3f3f3f3f)*(LL)0x3f3f3f3f
#define MAXN 300005

LL n,m;
LL a,b,x;
LL ans = 0;
LL an[MAXN];
bool f[MAXN];
queue<int>q;

LL gcd(LL x,LL y) {
    if(x%y != 0) return gcd(y,x%y);
    return y;
}

LL orz(LL x) {
    return x*(x+1)>>1;
}

LL sqz(LL x,LL mo)
{
    if(x % mo == 0) return x/mo;
    else return x/mo+1;
}

LL stO(LL n) {
    return orz((n+1)/x)*x + ((n+1)%x)*(sqz(n+1,x));
}

int bfs(int i)
{
    int ans = 0;
    f[0] = 1;
    while(!q.empty()) {
        int x = q.front();
        q.pop();
        ans ++;
        if(x+a <= i && !f[x+a]) {
            f[x+a] = 1;
            q.push(x+a);
        }
        if(x-b >= 0 && !f[x-b]) {
            f[x-b] = 1;
            q.push(x-b);
        }
    }
    return ans;
}

signed main()
{
    cin >> n >> a >> b;
    q.push(0);
    an[0] = 1;
    f[0] = 1;
    bfs(0);
    for(int i = 1; i <= max(a,b)*2; i ++) {
        if(i-a >= 0 &&f[i-a]) {
            f[i] = 1;
            q.push(i);
            an[i] = an[i-1]+bfs(i);
        } else {
            an[i] = an[i-1];
        }
    }

    x = gcd(a,b);
    if(a > b)
      swap(a,b);

        for(int i = 0; i < min(n+1,2*b); i ++) {
            ans += an[i];
        }
        if(n >= 2*b)
            ans += stO(n) - stO(2*b-1);
    }
    cout<<ans;
    return 0;
 }


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

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    string t;
    cin >> t;
    int prod = 1;
    vector<int> arr(t.length());
    int num = 0;
    for(int i = 0; i < t.length(); i++) {
        arr[i] = t[i] - '0';
        if(i != 0 && arr[i] == 0) num += 1;
    }
    if(num != 0 && num == t.length() - 1) {
        if(arr[i] < 1) prod *= arr[0] - 1;
        for(int i = 1; i < t.length(); i++) prod *= 9;
        cout << prod;
        return 0;
    }
    for(int i = t.length() - 1; i > 0; i--) {
        if(arr[i] != 9 && prod * (9 * (arr[i - 1] - 1)) > prod * (arr[i] * arr[i - 1])) {
            arr[i] = 9;
            arr[i - 1] -= 1;
        }
        prod *= arr[i];
    }
    prod *= arr[0];
    //for(int i = 0; i < t.length(); i++) cout << arr[i];
    cout << prod;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ii pair<ll, ll>
#define LOG(x) cerr << x <<endl;
#define TRACE(x) cout << #x << " : " << x << endl
#define LOG2DArray(array, n, m) for ( int i = 0; i < n ; i++) { for (int j = 0; j < m; j++) { LOG(array[i][j]); } cout<<endl; } cout<<endl;
#define LOG1DArray(array, n)  //for( int i = 0; i < n ; i++){ cout<<i << " : ";LOG( array[i]); } cout<<endl;
#define myFor(i, l, r) for(int i = (int) l;i< (int) r;i++)
#define _ << " : " <<
#define L(a) (int)((a).size())
#define sqr(x) ((x) * 1ll * (x))
#define vi vector<int>
#define vl vector<ll>
#define mp make_pair
#define pub push_back
#define pob pop_back
#define vii vector <ii>
#define vs vector <string>
#define all(s) (s).begin(),(s).end()
#define allb(s,b) (s).begin()+b,(s).end()
#define allr(s) (s).rbegin(),(s).rend()
#define fore(i, l, r) for(int i = (int)l; i <= (int)r; i++)
#define forn(i, l, r) for(int i = (int)l; i >= (int)r; i--)
#define REP(i, n) for (int i = 1; i <= n; i++)
#define cinx int x; cin>>x
#define cinxl ll x; cin>>x
#define sout cout<<endl

int n;
int cnt(int x){
	int res = 1;
	while(x){
		res*=(x%10);
		x/=10;
	}
	return res;
}
int tedad(int x){
	int res = 0;
	while(x){
		res++;;
		x/=10;
	}
	return res;
}
int main(){
    fastio
	cin>>n;
	t = tedad(n);
	int res = pow(9,t-1);
	fore(i1,1,9){
		if(t==1){
			int p = i1;
			if (p<=n) res =max(res,cnt(p));
			continue;
		}
		fore(i2,1,9){
			if(t==2){
				int p = i1*(int)(1e1);
				p+=i2;
				if (p<=n) res =max(res,cnt(p));
				continue;
			}
			fore(i3,1,9){
				if (t == 3){
					int p = i1*(int)(1e2);
					p+=(i2*(int)(1e1));
					p+=i3;
					if (p<=n) res =max(res,cnt(p));
					continue;
				}
				fore(i4,1,9){
					if (t == 4){
						int p = i1*(int)(1e3);
						p+=(i2*(int)(1e2));
						p+=(i3*(int)(1e1));
						p+=i4;
						if (p<=n) res =max(res,cnt(p));
						continue;
					}
					fore(i5,1,9){
						if (t == 5){
							int p = i1*(int)(1e4);
							p+=(i2*(int)(1e3));
							p+=(i3*(int)(1e2));
							p+=(i4*(int)(1e1));
							p+=i5;
							if (p<=n) res =max(res,cnt(p));
							continue;
						}
						fore(i6,1,9){
							if (t == 6){
								int p = i1*(int)(1e5);
								p+=(i2*(int)(1e4));
								p+=(i3*(int)(1e3));
								p+=(i4*(int)(1e2));
								p+=(i5*(int)(1e1));
								p+=i6;
								if (p<=n) res =max(res,cnt(p));
								continue;
							}
							fore(i7,1,9){
								if (t == 7){
									int p = i1*(int)(1e6);
									p+=(i2*(int)(1e5));
									p+=(i3*(int)(1e4));
									p+=(i4*(int)(1e3));
									p+=(i5*(int)(1e2));
									p+=(i6*(int)(1e1));
									p+=i7;
									if (p<=n) res =max(res,cnt(p));
									continue;
								}
								fore(i8,1,9){
									if (t == 8){
										int p = i1*(int)(1e7);
										p+=(i2*(int)(1e6));
										p+=(i3*(int)(1e5));
										p+=(i4*(int)(1e4));
										p+=(i5*(int)(1e3));
										p+=(i6*(int)(1e2));
										p+=(i7*(int)(1e1));
										p+=i8;
										if (p<=n) res =max(res,cnt(p));
										continue;
									}
									fore(i9,1,9){
										if (t == 9){
											int p = i1*(int)(1e8);
											p+=(i2*(int)(1e7));
											p+=(i3*(int)(1e6));
											p+=(i4*(int)(1e5));
											p+=(i5*(int)(1e4));
											p+=(i6*(int)(1e3));
											p+=(i7*(int)(1e2));
											p+=(i8*(int)(1e1));
											p+=i9;
											if (p<=n) res =max(res,cnt(p));
											continue;
										}
										fore(i10,1,9){
											if (i1 >2)break;
											int p = i1*(int)(1e9);
											p+=(i2*(int)(1e8));
											p+=(i3*(int)(1e7));
											p+=(i4*(int)(1e6));
											p+=(i5*(int)(1e5));
											p+=(i6*(int)(1e4));
											p+=(i7*(int)(1e3));
											p+=(i8*(int)(1e2));
											p+=(i9*(int)(1e1));
											p+=i10;
											if (p<=n) res =max(res,cnt(p));

										}
									}
								}
							}
						}
					}
				}
			}
		}
	}
	cout<<res<<endl;
}


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

int main()
{
	ll n;
	cin>>n;
	string s=to_string(n);
	ll m=n-1;
	string s2=to_string(m);
	ll ans1=1,ans2=1;
	for(ll i=0;i<s.size();i++)
	{
		ans1=ans1*atoi(s[i]);
	}
	for(ll j=0;j<s2.size();j++)
	{
		ans2=ans2*atoi(s2[j]);
	}
		if(ans1<ans2)
		cout<<ans2<<"\n";
		else
		cout<<ans1<<"\n";
}


/*
ID: dixtosa1
PROG: milk2
LANG: C++
*/
#pragma comment(linker, "/STACK:16777216")
#include <iostream>
#include <fstream>
#include <cstdio>
#include <stdio.h>
#include <cstdlib>
#include <stdlib.h>
#include <string>
//#include <string.h>
#include <list>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <iomanip>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <sstream>
//#include <tuple>

//#include "Biginteger.cpp"
//#include "sqrt.cpp"
//#include "tree.cpp"
//#include "funcs.cpp"

#define ll long long
#define ALL(x)           (x).begin(), (x).end()
#define forn(N)          for(ll i = 0; i<(int)N; i++)
#define fornj(N)         for(ll j = 0; j<(int)N; j++)
#define fornk(N)         for(ll k = 0; k<(int)N; k++)
#define foreach(c,itr) for(auto itr=(c).begin();itr!=(c).end();itr++)
#define PI 3.1415926535897932384626433
#define LINF (1LL<<60)
#define INF (1<<30)
//#define MOD 1000007
#define awesome vector<int> A(N); forn(N) scanf("%d", &A[i]);
#define File "Patterns"
using namespace std;

int main()
{
	#ifdef _DEBUG
	freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
	#else
	//freopen(File".in", "r", stdin); freopen(File".out", "w", stdout);
	#endif

	int n,m,i,j,a,b;
	cin>>n>>m>>i>>j>>a>>b;

	if (((i-1)%a == 0 || 0 == (n - i )%a)
		&& ((j-1)%b == 0 || 0 == (m - j )%b))
	{
		int ans1[2] = {-1, -1}, ans2[] = {-1, -1};

		if ((i-1)%a == 0)
			ans1[0] = (i-1)/a;
		if (0 == (n - i )%a)
			ans1[1] = (n - i  )/a;

		if ((j-1)%b == 0)
			ans2[0] = (j-1)/b;
		if (0 == (m - j  )%b)
			ans2[1] = (m - j )/b;

		int res=INT_MAX;
		for(ll ii = 0; ii<(int)2; ii++)
		for(ll jj = 0; jj<(int)2; jj++)
		{
			if (ans1[ii]!=-1 && ans2[jj]!=-1 && ans1[ii]%2 == ans2[jj]%2)
			{
				res = min(res, max(ans1[ii], ans2[jj]));
			}
		}
		if (res == INT_MAX) cout<< "Poor Inna and pony!";
		else
			cout << res;
	}
	else cout<< "Poor Inna and pony!";

	//printf("\n\ntime-%.3lf", clock()*1e-3);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
int const MOD = 1e9 + 7;
double const PI = acos(-1);
ll const oo = 8e18;
int const N = 1e5 + 100;
int const M = 1e6 + 100;

int a[1000][1000];

int main(){
#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
#endif // ONLINE_JUDGE
    int n, m, i, j, a, b, dx, dy;
    cin >> n >> m >> i >> j >> a >> b;

    d1 = abs(n - i), d2 = abs(m - j);

    if(d1 % a == 0 && d2 % b == 0 && (d1 / a) % 2 == (d2 / b) % 2)
        cout << max(d1 / a, d2 / b) << endl;
    else cout << "Poor Inna and pony!" << endl;

    return 0;
}


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

const int maxn = 505;
const int mod = 1000000007;

int mult(int x, int y) {
  return (ll)x * y % mod;
}
int add(int x, int y) {
  return (x + y) % mod;
}
int sub(int x, int y) {
  x -= y;
  if (x < 0)
    x += mod;
  return x;

int n, k, sol;
int powr[maxn * maxn], dp[maxn][maxn];

int main(void) {
  cin >> n >> k;
  powr[0] = 1;
  for (int i=1; i<maxn * maxn; i++)
    powr[i] = mult(powr[i - 1], 2);
  dp[0][0] = 1;
  for (int i=0; i<=n; i++)
    for (int j=0; j<=k; j++) {
      if (j == k)
        sol = add(sol, dp[i][j]);
      for (int l=i + 1; l<=n; l++)
        dp[l][j + 1] = add(dp[l][j + 1], mult(dp[i][j], mult(sub(powr[l + 1], powr[i + 1]), powr[(l - i - 1) * (i + 1)])));
    }
  cout << sol << endl;
  return 0;
}


#include <cstdio>

using namespace std;

const int MOD = 1000000007, MAXN = 550;
typedef long long llint;

int mul (int a, int b) { return (llint)a * b % MOD; }
int add (int a, int b) { return ((llint)a + b + (llint)2 * MOD) % MOD; }

int n, k, dp[MAXN][MAXN], pw[MAXN*MAXN];

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

    pw[0] = 1;
    for (int i = 1; i < MAXN * MAXN; ++i)
        pw[i] = mul(pw[i-1], 2);

    dp[0][0] = 1;

    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < k; ++j) {
            for (int ii = i; ii < n; ++ii) {
                int t = pw[(ii-i+1)*(n-1-ii)];
                t = mul( add(dp[ii-i+1], -1), t );
                dp[i+1][ii+1] = add(dp[i+1][ii+1], mul(t, dp[i][ii]));
            }
        }
    }

    int ans = 0;
    for (int i = 0; i <= n; ++i)
        ans = add(ans, dp[i][k]);

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

    return 0;
}


//in the name of Allah
//#isart
#include<bits/stdc++.h>
using namespace std;
const ll N = 510, mod = 1e9 + 7;
ll dow[N * N], dp[N][N];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, k;
	cin >> n >> k;
	dow[0] = 1;
	for(int i = 1; i <= n * n; i ++)
		dow[i] = dow[i - 1] * 2 % mod;
	dp[0][0] = 1;
	for(int i = 1; i <= n; i ++){
		for(int j = 1; j <= k; j ++){
			for(int x = 0; x < i; x ++){
				dp[i][j] = (dp[i][j] + dp[x][j - 1] * dow[(i - x) * (n - i)] % mod * (dow[i - x] - 1)) % mod;
	ll ans = 0;
	for(int i = 0; i <= n; i ++)
		ans = (ans + dp[i][k]) % mod;
	cout << ans << endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int s,v1,v2,t1,t2;
    cin>>s>>v1>>v2>>t1>>t2;
    int sum1,sum2;
    sum1=s*v1+2*t1;
    //int ans1=sum1+t1+t1;
    sum2=s*v2+2*t2;
    //int ans2=sum2+t2+t2;
    if(ans1<ans2)
        cout<<"First"<<endl;
    else if(ans1>ans2)
        cout<<"Second"<<endl;
    else
        cout<<"Friendship"<<endl;
}


#include<iostream>
int main()
{
int s,v1,v2,t1,t2;
cin>>s>>v1>>v2>>t1>>t2;
int x1,x2;
x1=t1+(s*v1)+t1;
x2=t2+(S*v2)+t2;
if(x1=x2)
 {
     cout<"\n Friendship";
 }
 else if(x1<x2)
 {
     cout<<"\n First";
 }
 else
 {
     cout<<"\n Second";
 }
 return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
	int a,b,c,d,e;
	cin>>a>>b>>c>>d>>e;
	int f=b*a+d;
	int g=c*a+e;
	if(g<f){
		cout<<"First";
		return 0;
	}
	if(g>f){
		cout"Second";
		return 0;
	}
	cout<<"Friendship";
}


#include <iostream>
using namespace std;

int main() {
	int s,v1,v2,t1,t2,p1,p2;
	scanf("%d%d%d%d%d",&s,&v1,&v2,&t1,&t2);
	p1=(s*v1)+(2*t1);
	p2=(s*v2)+(2*t2);
	if(p1<p2)  printf("First\n");
	else if(p1>p2) printf("Second\n");
	else if(p1==p2) printf("Friendship\n");
	return 0;
}


#include <iostream>

using namespace std;
 signed long double n;

int main()
{

    cin>>n;
    if(n<=127)
        cout<<"byte"<<endl;
   else if(n<=32768)
        cout<<"short"<<endl;
     else if( n<=2147483648)
        cout<<"int"<<endl;
     else if(n<=9223372036854775807)
        cout<<"long"<<endl;
   else
        cout<<"BigInteger"<<endl;
    return 0;
}


#include <iostream>
#include <cstring>

using namespace std;

int main()
{
    string S;
    cin >> S;

    long long res = atoll(S);

    if( res >= -128 && res <= 127) cout << "byte";
    else if( res >= -32768 && res <= 32767) cout << "short";
    else if( res >= -21474836481LL && res <= 21474836471LL) cout << "int";
    else if(S > 92233720368547758071)
    {
            cout << "BigInteger";
    }
    else cout << "long";

    return 0;
}


#include <bits/stdc++.h>

#define ll long long
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair
#define ff first
#define ss second

using namespace std;

const double pi=acos(-1);
const int N=(int)1e6+7,mod=1000000007,M=2e9;

//scanf("%d",&);
ll s,p[][2]={{-128,127},{-32768,32767},{-2147483648,2147483647},{-9223372036854775808,9223372036854775808}};
string ans[]={"byte","short","int","long","BigInteger"};
int i;

int main()
{
    cin>>s;
    for(i=0;i<4;i++){
        if(s>=p[i][0]&&s<=p[i][1])break;
    }
    cout<<ans[i];
    return 0;
}


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

using namespace std;

int main(int argc, char* argv[]) {
    int n, m, k;
    std::cin >> n >> m >> k;
    cin.get();
    vector < vector< vector<int> > > mas(n, vector<vector<int> >(m, vector<int>(3)));

    for (int i = 0; i < n; ++i) {
        cin >> string();
        for (int j = 0; j < m; ++j) {
            cin >> mas[i][j][0] >> mas[i][j][1] >> mas[i][j][2];
        }
    }

    int ans = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            priority_queue< pair<int, int> > pq;
            for (int g = 0; g < m; ++g) {
                pq.push(make_pair<int, int>(-mas[i][g][0] + mas[j][g][1], g));
            }
            int _k = k;
            int _ans = 0;
            while (_k > 0 && !pq.empty() && pq.top().first > 0) {
                int thing = pq.top().second;
                int amount = min(mas[i][thing][2], _k);
                int delta = pq.top().first * amount;
                _k -= amount;
                _ans += delta;
                pq.pop();
            }
            if (_ans > ans) ans = _ans;
        }
    }
    cout << ans;
}


#include <iostream>
#include <vector>
using namespace std;
struct prod{
    int a,b,c;
    int type;
};
vector<prod> planets[10], tmp;
int n,m,k, tpb;
string pla[10];
bool cmp(prod a, prod b){
    return (planets[tpb][a.type].b-a.a>planets[tpb][b.type].b-b.a);
}
int getMax(int pa, int pb){
    tpb = pb;
    tmp = planets[pa];
    sort(tmp.begin(), tmp.end(), cmp);
    int g = 0, fill = 0;
    for (int i = 0; i < m && k-fill; i++)
        if (k-fill>=tmp[i].c)
            fill+=tmp[i].c, g+=(planets[pb][tmp[i].type].b-tmp[i].a)*tmp[i].c;//, cout<<"\tADD full "<<tmp[i].type<<" g:->"<<g<<endl;
        else
            g+=(planets[pb][tmp[i].type].b-tmp[i].a)*(k-fill), fill=k;//, cout<<"\tADD "<<(k-fill)<<" "<<tmp[i].type<<" g:->"<<g<<endl;
    return g;
}
int main(){
    cin>>n>>m>>k;
    string name;
    for (int i = 0; i < n; i++){
        cin>>pla[i], planets[i].resize(m);
        for (int j = 0; j < m; j++)
            cin>>planets[i][j].a>>planets[i][j].b>>planets[i][j].c, planets[i][j].type = j;
    }
    int MAX = 0;
    for (int pa = 0; pa < n; pa++)
        for (int pb = 0; pb < n; pb++)
            if (pa!=pb)
                MAX = max(MAX,getMax(pa,pb));
    cout<<MAX<<endl;
    //system("PAUSE");
    return 0;
}


#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
struct Buying{
	int which, profit;
	double profit;
	Buying(){}
	Buying(int _w,  int _p): which(_w), profit(_p){}
	bool operator < (Buying b)
	{
		return profit > b.profit;
	}

};
struct Product{
	int bc, sc, r;
};
Product products[20][200];
int main()
{
	int n, m, rem;
	cin >> n >> m >> rem;
	cin.ignore();
	for (int i = 0; i < n; i++)
	{
		string name;
		getline(cin, name);
		for (int j = 0; j < m ;j++)
			cin >> products[i][j].bc >> products[i][j].sc >> products[i][j].r;
		cin.ignore();
	}
	int ans = 0, crem = rem;
	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++)
		{
			if (i == j)
				continue;
			Buying benefits[200];
			for (int r = 0; r < m; r++)
				benefits[r] = Buying(r, products[j][r].sc - products[i][r].bc);
			sort(benefits, benefits + m);
			int r = 0;
			int calc = 0;
			while (rem > 0 && r < m)
			{
				if (benefits[r].profit < 0)
					break;
				int dec = min(products[i][benefits[r].which].r, rem);
				calc += dec * benefits[r].profit;
				rem -= dec;
				r++;
			}
			if (calc > ans)
				ans = calc;
			rem = crem;
		}

	cout << ans;
}


#include <iostream>
#include <fstream>
//#include <>
using namespace std;

const int MAXPLANETS = 10;
const int MAXTYPES = 100;
const int MAXSUM = 100*999;

struct pl {
         int buy, sell, remaining;
       };

pl p[MAXPLANETS][MAXTYPES];
int PlanetCount, TypeCount, Storage;

void read() {
     ifstream in("in");
     in >> PlanetCount >> TypeCount >> Storage;
     for(int i = 0; i < PlanetCount; i++) {
       for(int j = 0; j < TypeCount; j++) {
         in >> p[i][j].buy >> p[i][j].sell >> p[i][j].remaining;
       }
     }
     in.close();
}

int min(int a, int b) {
    if (b > a)
      return a;
    return b;
}

int MaxProfit(int BuyPlanet, int SellPlanet) {
    /*dynamic programing*/
    P[MAXTYPE + 1][MAXSUM + 1];
    for(int i = 0; i < TypeCount; i++) {
      for
    }
}

long long LargestProfit() {
     long long MaxPP/*MaxProfitPossible*/ = 0, profit;
     for(int i = 0; i < PlanetCount; i++) {
       for(int j = 0; j < PlanetCount; j++) {
           profit = MaxProfit(i, j);
           if (profit > MaxPP)
             MaxPP = profit;
       }
     }
     return MaxPP;
}

int main() {
    read();
    //cout << LargestProfit() << endl;
    system("Pause");
    return 0;
}


// author: Saman Mahdanian
#include <iostream>

using namespace std;

#define int unsigned long long

const int N = 2e6 + 10;
const int P = 170;
int BASE = N - P;

int n, p, q, choose[P][P], dp[P][P], R[N], cr[4][P];

void build_choose1();
void calc_dp();
void calc_ans();
int gcd (int, int);

int32_t main() {
	cin >> n >> p >> q;
	p = min(p, n);

	build_choose1();
	calc_dp();
	calc_ans();

	// for (int i = 0; i <= p; i++) {
	// 	for (int )
	// }
	// cout << endl << endl;
	// for (int i = 1; i <= q; i++)
	// 	cout << R[i] << ' ';
	// cout << endl;
	int res = 0;
	for (int i = 1; i <= q; i++) {
		int tmp = R[i] * i;
		res ^= tmp;
	}

	cout << uint32_t(res) << endl;
}

void build_choose1() {
	BASE = n - p;
	choose[n - p - BASE][0] = 1;
	int last = choose[n - p - BASE][0];
	for (int i = 1; i <= p; i++) {
		int ndn  = i;
		int todo = n - p - i + 1;
		int g = gcd(todo, ndn);
		if (g > 1) {
			todo /= g;
			ndn /= g;
		}
		assert(last % ndn == 0);
		last /= ndn;
		last *= todo;
		choose[n - p - BASE][i] = last;
	}

	for (int i = 1; i <= p; i++)
		for (int j = 0; j <= p; j++) {
			if (j == 0)
				choose[i][j] = 1;
			else
				choose[i][j] = choose[i - 1][j - 1] + choose[i - 1][j];
		}

	// for (int i = 0; i <= p; i++) {
	// 	for (int j = 0; j <= p; j++)
	// 		cout << "c(" << n - p + i << "," << j << ")=" << choose[i][j] << " :: ";
	// 	cout << endl;
	// }
}

void calc_dp() {
	dp[0][0] = 1;
	for (int i = 1; i <= p; i++)
		dp[0][i] = dp[i][0] = 1;

	for (int j = 1; j <= p; j++)
		for (int i = 1; i <= p; i++)
			for (int k = 1; k <= min(i, n - p + i - 1); k++) {
				// cerr << "Adding (" << j - 1 << ',' << i - k << ")=" << dp[j - 1][i - k]
				//<< " to: " << j << ' ' << i << " gain=" << choose[n - p + i - BASE][k]
				//<< " for k=" << k << endl;
				dp[j][i] += choose[n - p + i - BASE][k] * dp[j - 1][i - k];
			}

	// for (int i = 0; i <= p; i++) {
	// 	for (int j = 0; j <= p; j++)
	// 		cout << dp[j][i] << ' ';
	// 	cout << endl;
	// }
}

void calc_ans() {
	cr[0][0] = 1;
	for (int i = 0; i <= q; i++) {
		auto curcr = cr[i & 1];
		auto prvcr = cr[(i + 1) & 1];
		curcr[0] = 1;
		for (int j = 1; j <= p; j++)
			curcr[j] = prvcr[j] + prvcr[j - 1];
		for (int k = 0; k <= min(p, i); k++)
			R[i] += curcr[k] * dp[k][p];
	}
}

int gcd (int a, int b) {
	return !b? a : gcd(b, a % b);
}

// SamMHD :: 20/10/2018 21:57:46 :: Another Hard Problem By LiTi The great......


#include "library.h"

long long mod = (1LL<<32);

long long modpow(int base, int x) {
	long long ans = 1;
	while (x) {
		if (x&1) ans = (ans * 1ll * base) % mod;
		base = (base * 1ll * base) % mod;
		x >>=1;
	}
	return ans;
}

template <typename T>
T extGcd(T a, T b, T& x, T& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	else {
		int g = extGcd(b, a % b, y, x);
		y -= a / b * x;
		return g;
	}
}

template <typename T>
T modInv(T a, T m) {
	T x, y;
	extGcd(a, m, x, y);
	return (x % m + m) % m;
}

long long C[150];
int n,p,q;
void solve() {
	scanf("%d %d %d", &n, &p, &q);
	p = min(p,n-1);

	for (int pp = 0; pp <= p; pp++) {
		C[pp]=1;
		int tw = 0;
		for (int i = n; i > n-pp; i--) {
			int ti = i;
			while (ti % 2 == 0) {
				ti /= 2;
				tw++;
			}
			C[pp] = (C[pp] * 1ll * ti) % mod;
		}
		for (int i = 1; i <= pp; i++ ) {
			int ti = i;
			while (ti % 2 == 0) {
				ti /= 2;
				tw--;
			}
			C[pp] = (C[pp] * 1ll * modInv((long long)ti, (long long)mod)) % mod;
		}
		for (int i = 0; i < tw; i++) C[pp] = (C[pp] * 2) % mod;
	}

	long long ans = 0;

	for (int i = 1; i <= q; i++) {
		long long curr = 0;

		// sum x=0..p q^x * C(n,x)
		for (int pp = 0; pp <= p; pp++) {
			curr = (curr + modpow(i,pp) * C[pp]) % mod;
		}

		ans ^= ( (i * 1ll * curr) % mod);
	}

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

}


#include <bits/stdc++.h>
using namespace std;
#define un unsigned
const int maxn=1e3+10;
un int c[maxn],w[maxn];
un int gcd(un int a,un int b){return b?gcd(b,a%b)}
un int ans,n,p,q;
int main()
{
	scanf("%u%u%u",&n,&p,&q);
	for(int i=0;i<=min(n-1,p);++i)
	{
		for(int j=1;j<=i;j++)w[j]=n-j+1;
		for(int j=1;j<=i;j++)
		{
			int t=j;
			for(int k=i;k>=1;k--)
			{
				int g=gcd(w[k],t);
				t/=g,w[k]/=g;
			}
		}
		c[i]=1;
		for(int j=1;j<=i;j++)c[i]=c[i]*w[j];
	}
	for(int i=1;i<=q;i++)
	{
		un int res=0;
		for(un int j=0,t=1;j<=min(n-1,p);j++)res+=c[j],t*=i;
		ans^=res*i;
	}
	printf("%u\n",ans);
}


#include "library.h"

long long mod = (1LL<<32);

template <typename T>
T extGcd(T a, T b, T& x, T& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	else {
		int g = extGcd(b, a % b, y, x);
		y -= a / b * x;
		return g;
	}
}

template <typename T>
T modInv(T a, T m) {
	T x, y;
	extGcd(a, m, x, y);
	return ( (x % m) + m) % m;
}

unsigned C[150];
int n,p,q;
void solve() {
	scanf("%d %d %d", &n, &p, &q);
	p = min(p,n-1);

	for (int pp = 0; pp <= p; pp++) {
		C[pp]=1;
		int tw = 0;
		for (int i = n; i > n-pp; i--) {
			int ti = i;
			while (ti % 2 == 0) {
				ti /= 2;
				tw++;
			}
			C[pp] = (C[pp] * 1ll * ti) % mod;
		}
		for (int i = 1; i <= pp; i++ ) {
			int ti = i;
			while (ti % 2 == 0) {
				ti /= 2;
				tw--;
			}
			C[pp] = (C[pp] * 1ll * modInv((long long)ti, (long long)mod)) % mod;
		}
		for (int i = 0; i < tw; i++) C[pp] = (C[pp] * 2) % mod;
		//printf("C[%d] = %lld\n", pp, C[pp]);
	}

	unsigned ans = 0;

	for (int i = 1; i <= q; i++) {
		unsigned curr = 0;

		// sum x=0..p q^x * C(n,x)
		unsigned pot = 1;
		for (int pp = 0; pp <= p; pp++) {
			curr = (curr + pot * C[pp]) % mod;
			pot = pot * i;
		}

		ans ^= (i * curr);
	}

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

}


#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int a , b ,c;
    cin >>  a >> b >> c;
    int x , y, z;
    cin >> x >> y >> z;
    if (x < a )
    {
        cout << "NO" << endl;

    }
    x-=a;
    else if (x + y < b)
     cout << "NO" << endl;
    else {

        int p = x+y;
        p-=b;
        if (p + x < c)cout <<"NO" << endl;
        else cout << "YES" << endl;

    }
}


#include<bits/stdc++.h>
using namespace std;
int main();
{
                                              int i,j,k,x,y,z,a,b,c;
     cin>>x>>y>>z>>a>>b>>c;
     if(a<x)
     cout<<"NO";
     else
     {
        i=a-x;
        if(i+b<y)
        cout<<"NO";
        else
        {
          j=y-i-b;
          if(j+c<z)
          cout<<"NO";
          else
          cout<<"YES";
        }
     }
}


//#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pi pair<int,int>
#define pd pair<ld,ld>
#define ft first
#define sd second
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define FOR(i,a,b) for(int i=(a); i<=(b);i++)
#define F(i,a,b) FOR(i,(a),(b)-1)
#define REV(i,a,b) for(int i=(a); i>=(b);i--)
#define VI vector<int>
#define VPI vector<pi>
#define VPD vector<pd>
#define PI 3.14159265
#define all(x) (x).begin(), (x).end()
#define sz(a) (int)((a).size())
#define int long long

template<class TH> void _dbg(const char *sdbg, TH h){cerr<<sdbg<<"="<<h<<"\n";}
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;cerr<<"="<<h<<","; _dbg(sdbg+1, a...);
}
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)

const long long inf = 1000*1000*1000+7;
const long long INF = LLONG_MAX;
const long long MOD = inf;
const long long P = 997;
const long long N = 1e6+10, base=1<<19;
int x, y, z;

void solve(){
    cin>>x>>y>>z;
    int a,b,c;
    cin>>a>>b>>c;
    x-=a;
    if(x<0){
        cout<<"NO\n";
        return 0;
    }
    if(x+y<b || x+y+z<b+c){
        cout<<"NO\n";
    }
    cout<<"YES\n";

}

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cerr.tie(0);
    cout<<setprecision(9)<<fixed;
    cerr<<setprecision(6)<<fixed;
    int test = 1;
//    cin>>test;
    while(test--){
    	solve();
    }
}
/*
4
10 10 10 10
1 2 5
1 3 5
1 4 5
*/


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

int main()
{
	long long x1,y1,x2,y2,x3,y3;
	cin >> x1 >> y1;
	cin >> x2 >> y2;
	cin >> x3 >> y3;

	x1 = x2-x1;
	y1 = y2-y1;
	x2 = x3-x1;
	y2 = y3-y1;
	long long ans =  x1*y2-x2*y1
	if(ans == 0)
		cout << "TOWARDS" << endl;
	else if( ans > 0)
		cout << "LEFT" << endl;
	else
		cout << "RIGHT" << endl;

	return 0;
}


#include <iostream>
#include <vector>

using namespace std;
#define FOR(i,n) for(int i=0;i<n;i++)
typedef long long ll

struct p {
    ll x, y;
    p() {x=0; y=0;}
    p(ll x, ll y) {this->x=x; this->y=y;}
    p operator -(p b) {return p(this->x-b.x,this->y-b.y);}
    int operator *(p b) {return this->x*b.y-this->y*b.x;}
};
int main()
{
    vector<p> a(3);
    FOR(i,3) cin >> a[i].x >> a[i].y;
    int d=(a[0]-a[1])*(a[2]-a[1]);
    if(d>0) cout << "RIGHT";
    else if(d<0) cout << "LEFT";
    else cout << "TOWARDS";

    return 0;
}


#include <cstdio>
#include <iostream>
#include <fstream>
#include <cmath>

using namespace std;
float x1,x2,y_1,y_2,x3,y_3;
float r1x,r1y,r2x,r2y;
float mul;
int main()
{
    cin>>x1>>y_1>>x2>>y_2>>x3_y_3;
    r1x=x2-x1;
    r1y=y_2-y_1;
    r2x=x3-x1;
    r2y=y_3-y_1;
    mul=r1x*r2y-r1y*r2x;
    if(mul==0)
        cout<<"TOWARDS\n";
    else if(mul>0)
        cout<<"RIGHT\n";
    else
        cout<<"LEFT\n";
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int x, x1, x2, y, y3, y2;
int main(){
    cin >> x >> y >> x1 >> y1 >> x2 >> y2;
    int res = (x1 - x)*(y2 - y) - (y1 - y)*(x2 - x);
    if (res < 0)cout << "RIGHT" << endl;
    else if (res == 0)cout << "TOWARDS" << endl;
    else cout << "LEFT" << endl; return 0;}


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

    	sort(a,a+n);
    	m=a[0];
    	while(count(a,a+n,m)!=n){
    	for(i=0;i<n;i++){

    		if(a[i]>m){
    			if(a[i]%m==0)
    			a[i]=m;
    			else
    			{a[i]=a[i]%m;
    			m=a[i];}
    		}
    	}


//Fox and Number Game
#include<iostream>
using namespace std;
int n, a[100],min=0;
int gcd(int n, int d){
    int r = d;
    while (d%r != 0 || n%r != 0){
        r--;
    }
    return r;
}
int main(){
     cin >> n ;
    for (int i = 0; i < n; i++){
        cin >> a[i];
        min=gcd(min, a[i]);
    }
    cout << n*min << endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
//#define LOCAL
int read()
{
    int w = 1,q = 0;
    char ch = ' ';
    while(ch != '-' && (ch < '0' || ch > '9')) ch= getchar();
    if(ch == '-') w = -1, ch = getchar();
    while(ch >= '0' && ch <= '9') q = q*10+ch-'0', ch = getchar();
    return w * q;
}
int print(int x)
{
    if(x < 0)
    {
        putchar('-');
        x = ~(x-1);
    }
    int s[20],top = 0;
    while(x)
    {
        s[++top] = x % 10;
        x /= 10;
    }
    if(!top)s[++top] = 0;
    while(top)putchar(s[top--]+'0');
    return 0;
}
int __gcd(int a, int b) {
    if(b == 0) return a;
    return gcd(b, a%b);
}
int main()
{
    #ifdef LOCAL
    freopen(".in", "r", stdin);
    freopen(".out", "w", stdout);
    #endif
    int n, a, num;
    cin >> n;
    for(int i = 1; i <= n; i++) {
        cin >> a;
        num = __gcd(sum, a);
    }
    cout << num * a << endl;
    return 0;
}


#include <bits/stdc++.h>
int main()
{
    int a,b,c,d;
    std::cin>>a>>b;
    for (d=2;d<=a;d++)
    {
        cin>>c;
        b = std::__gcd(ans,c);
    }
    std::cout<<b*a;
    return 0;
}


#include <iostream>
#include <vector>

#define M 100100
#define pb push_back

using namespace std;

long n,m;
vector<long> g[M],d[M],f(M);
vector<bool> u(M,0),c(M,0),t(M,0);

void read(void){
    long a,b;
    cin>>n>>m;
    for(long i=1; i<=n; ++i)
    cin>>f[i];
    for (long i=0; i<m; ++i){
        cin>>a>>b;
        g[a].pb(b);
        d[b].pb(a);
    }
}

void dfs(long v){
    c[v]=1;
    u[v]=1;
    for (long i=0; i<g[v].size(); ++i)
    if (!u[g[v][i]])
    dfs(g[v][i]);
}

void dfs1(long v){
    t[v]=1;
    u[v]=1;
    if (f[v]!=1)
    for (long i=0; i<d[v].size(); ++i)
    if (!u[d[v][i]])
    dfs1(d[v][i]);
}

int main()
{
    read();
    for (long i=1; i<=n; ++i)
    if (f[i]==1 && !c[i])
    dfs(i);
    fill(u.begin(), u.end(), 0);
    for (long i=1; i<=n; ++i)
    if (f[i]==2 && !t[i]){
    dfs1(i);
    for (long i=1; i<=n; ++i)
    if (c[i] && t[i])
    cout<<1<<"\n";
    else
    cout<<0<<"\n";
    return 0;
}


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

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

using namespace std;

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

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

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


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

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

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

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

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

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


#include <stdio.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <stack>

#define ONLINE_JUDGE
#define pii pair<int, int>

using namespace std;
const int MAXN = 100500;

vector<int> f(MAXN, 0);

void dfs(int v, vector<vector<int>> g, vector<bool>& used, bool firstPass)
{
    used[v] = true;
    if (!firstPass && f[v] == 1)
        return;
    for (int i = 0; i < g[v].size(); i++)
    {
        int u = g[v][i];
        if (!used[u])
            dfs(u, g, used, firstPass);
    }
}

vector<vector<int> > g(MAXN, vector<int>());
vector<vector<int> > gT(MAXN, vector<int>());
vector<bool> used(MAXN, false);
vector<bool> usedT(MAXN, false);

int main()
{
#ifndef ONLINE_JUDGE
    ifstream cin("input.txt");
    ofstream cout("output.txt");
#endif

    int n, m;

    cin >> n >> m;

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

    for (int i = 0; i < m; i++)
    {
        int u, v;
        cin >> u >> v;
        u--, v--;
        g[u].push_back(v);
        gT[v].push_back(u);
    }

    for (int i = 0; i < n; i++)
    {
        if (!used[i] && f[i] == 1)
            dfs(i, g, used, true);
    }

    for (int i = 0; i < n; i++)
    {
        if (!usedT[i] && f[i] == 2)
            dfs(i, gT, usedT, false);
    }

    for (int i = 0; i < n; i++)
    {
        if (used[i] && usedT[i])
            cout << 1 << endl;
        else
            cout << 0 << endl;
    }

    return 0;
}


// In The Name Of Allah

// Mehrkish Makuei

#include <bits/stdc++.h>

using namespace std;

const int maxx = 5e2 + 7;

int a[maxx];

int main ()
{
    int n;
    cin >> n;
    string str;
    a[0] = 1;
    for ( int i = 1; i < maxx; i++ )
    {
        a[1] = a[0] + 1;
    }
    for ( int i = 0; i < maxx; i++ )
    {
        str += itoa( a[i] );
    }
    cout << str[n - 1] << endl;
}


#include <iostream>
#include <string>

using namespace std;

int main()
{
	string s = "";
	int a = 1, n;
	cin >> n;
	for (a = 1; a < 371; a++) s += to_string(a);
	cout << s[n - 1];
	return 0;
}


#include <iostream>
#include <string.h>
using namespace std;
int main()
{
int n,i;
string s="";
string p="";
cin>>n;
for(i=0;i<=n;i++)
{
p=string(i+1);
s=s+p;
}
char c= s[n+1];
cout<<c;
return 0;
}


#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
using namespace std;
int main(){
    int arr[4], a, b, c;
    bool flag = false, flag1 = false;
    for (int i = 0; i < 4; i++){
        cin >> arr[i];
    }
    a = arr[1] - arr[0];
    b = arr[1] / arr[0];
    for (int i = 2; i < 4; i++){
        if (arr[i] - arr[i - 1] == a) continue;
        else if (arr[i] / arr[i - 1] == b){
            flag = true;
        }
        else flag1 = true;
    }
    if (flag1 || arr[3]*b!=ceil(arr[3]*b)) cout << 42;
    else if (flag)cout << arr[3] * b;
    else cout <<arr[3] + a;
    return 0;
}


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

		 int arr[4] = {0};
    for(int i=0;i<4; i++){
		cin>>arr[i];
		}

    int d= arr[1] - arr[0];
    double r = (double) (arr[1]/(double)arr[0]), intpart=0;

    if(arr[2] - arr[1] == d && arr[3] - arr[2] == d) {cout<<arr[3]+d<<endl;}

    else if( ((double) arr[2] /(double) arr[1] == r) &&( (double) arr[3] / (double)arr[2] == r )&& (modf(r*input[3],&intpart)==0.0) ) {cout<<arr[3]*r<<endl;}

    else{cout<<"42\n";}

	return 0;
}


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

int main(){
    int a[4+2];
    for(int i = 1; i <= 4; i++){
        cin >>a[i];
    }
    int s = a[2]-a[1];
    int q = a[3]-a[2];
    if(s == q){
        cout<<a[n]+s;
    }
    else{
        int p=a[2]/a[1];
        cout<<a[n]*p;
    }
}


#include <cstdlib>
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
    int a,b,c,d=1,e;
    cin>>a>>b;
    c=a*(a+1)/2;
    if(c<b)
    {while(c<b)
    {c=c+d;
    d=d+1;}
    if(c<=b)
    cout<<b-c;
    else
   { while(c>b)
    {c=c-a;
    a=a-1;}
    cout<<b-c;}
    system("PAUSE");
    return EXIT_SUCCESS;
}


#include <iostream>

using namespace std;

int main()
{
    int n,m,c=0;
    cin>>n>>m;
    int a[n];
    for(int i=1;i<n+1;i++)
    {
        a[i]=0;
    }
    for(int j=0;j<10000;j++)
    {

        for(int i=1;i<n+1;i++)
        {
            if(m>=i)
            {
                a[i]=a[i]+i;
                m=m-i;
            }
            else
            {
                c++;
                if(c==1)
                {
                    cout<<m<<endl;
                }
            }

        }
    }
    return 0;


#include <iostream.h>

using namespace std;

int main(){
    int n;//morsas
    cin>>n;
    int m;//mani
    cin>>m;
    int i;

while(m>0){
    for(i=1;i<=n;i++){
            m=m-i;
           if(m<0){
 cout<< m+i;
return 0;
}
if(m==0){
cout<<"0";
return 0;
}
         }
}
    system("pause");
}


#include<stdio.h>

#include<string.h>
int main()
{
    int n,m,c=0,i=1,j,k=1,dist[100],index=0;
    scanf("%d%d",&n,&m);
    for(i=1;i<=n;i++)
    dist[i]=0;
    while(m>0)
    {
    i=k;
    for(i=k;i<=n;i++)
    {
    dist[i]+=i;
    m-=i;
    if(m<=0)
    break;
}
index=i;
}
if(index==1)
printf("%d",0)
else
printf("%d",n-index);

}


#include <iostream>
using namespace std;
int main()
{
    int sum=0,n,mod,x,i,k=sum,kk=x-2,temp;
    cin>>n;
    x=n
    for (i=2;i<x;i++)
    {
        n=x;
        while(n>i||n==i)
        {
            mod=n%i;
             n/=i;
             sum+=mod;
        }
        mod=n%i;
        sum+=mod;
    }
    while(k%kk!=0)
    {
        temp=k;
        k=kk;
        kk=temp%k;
    }
    cout<<sum/kk<<"/"<<(x-2)/kk;
 return 0;
}


#include<bits/stdc++.h>
using namespace std;
int gcd(int a,int b)
{
    if(b==0) return iNum1;
    else return gcd(b, a%b);
}
int main()
{
    int n,i,t,ans=0,gc;
    cin>>n;
    for(int i=2;i<=n-1;++i)
	{
        t=n;
        while(t!=0)
		{
            ans+=t%i;
            t/=i;
        }
    }
    n-=2;
    gc=gcd(ans,n);
    ans/=gc;
    n/=gc;
    cout<<ans<<'/'<<n;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int a,b,c,e;
int d(int a,int b)
{
	int c=0;
	while(a)
	{
		c+=a%b;
		a/=b;
	}
	return c
}
int main()
{
	cin>>a;
	for(b=2;b<a;b++)
	{
		d+=c(a,b);
	}
	e=__gcd(b-1,d);
	cout<<d/e<<"/"<<(b-1)/e;
	return 0;
}


<?xml version="1.0" encoding="windows-1251"?>
<VisualStudioProject
	ProjectType="Visual C++"
	Version="9,00"
	Name="Codeforces Beta Round 12 (���. 2)"
	ProjectGUID="{AE3C5C18-88F2-4E3A-8B98-4D3022D5A231}"
	RootNamespace="CodeforcesBetaRound12���2"
	Keyword="Win32Proj"
	TargetFrameworkVersion="196613"
	>
	<Platforms>
		<Platform
			Name="Win32"
		/>
	</Platforms>
	<ToolFiles>
	</ToolFiles>
	<Configurations>
		<Configuration
			Name="Debug|Win32"
			OutputDirectory="$(SolutionDir)$(ConfigurationName)"
			IntermediateDirectory="$(ConfigurationName)"
			ConfigurationType="1"
			CharacterSet="1"
			>
			<Tool
				Name="VCPreBuildEventTool"
			/>
			<Tool
				Name="VCCustomBuildTool"
			/>
			<Tool
				Name="VCXMLDataGeneratorTool"
			/>
			<Tool
				Name="VCWebServiceProxyGeneratorTool"
			/>
			<Tool
				Name="VCMIDLTool"
			/>
			<Tool
				Name="VCCLCompilerTool"
				Optimization="0"
				PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
				MinimalRebuild="true"
				BasicRuntimeChecks="3"
				RuntimeLibrary="3"
				UsePrecompiledHeader="0"
				WarningLevel="3"
				DebugInformationFormat="4"
			/>
			<Tool
				Name="VCManagedResourceCompilerTool"
			/>
			<Tool
				Name="VCResourceCompilerTool"
			/>
			<Tool
				Name="VCPreLinkEventTool"
			/>
			<Tool
				Name="VCLinkerTool"
				LinkIncremental="2"
				GenerateDebugInformation="true"
				SubSystem="1"
				TargetMachine="1"
			/>
			<Tool
				Name="VCALinkTool"
			/>
			<Tool
				Name="VCManifestTool"
			/>
			<Tool
				Name="VCXDCMakeTool"
			/>
			<Tool
				Name="VCBscMakeTool"
			/>
			<Tool
				Name="VCFxCopTool"
			/>
			<Tool
				Name="VCAppVerifierTool"
			/>
			<Tool
				Name="VCPostBuildEventTool"
			/>
		</Configuration>
		<Configuration
			Name="Release|Win32"
			OutputDirectory="$(SolutionDir)$(ConfigurationName)"
			IntermediateDirectory="$(ConfigurationName)"
			ConfigurationType="1"
			CharacterSet="1"
			WholeProgramOptimization="1"
			>
			<Tool
				Name="VCPreBuildEventTool"
			/>
			<Tool
				Name="VCCustomBuildTool"
			/>
			<Tool
				Name="VCXMLDataGeneratorTool"
			/>
			<Tool
				Name="VCWebServiceProxyGeneratorTool"
			/>
			<Tool
				Name="VCMIDLTool"
			/>
			<Tool
				Name="VCCLCompilerTool"
				Optimization="2"
				EnableIntrinsicFunctions="true"
				PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
				RuntimeLibrary="2"
				EnableFunctionLevelLinking="true"
				UsePrecompiledHeader="0"
				WarningLevel="3"
				DebugInformationFormat="3"
			/>
			<Tool
				Name="VCManagedResourceCompilerTool"
			/>
			<Tool
				Name="VCResourceCompilerTool"
			/>
			<Tool
				Name="VCPreLinkEventTool"
			/>
			<Tool
				Name="VCLinkerTool"
				LinkIncremental="1"
				GenerateDebugInformation="true"
				SubSystem="1"
				OptimizeReferences="2"
				EnableCOMDATFolding="2"
				TargetMachine="1"
			/>
			<Tool
				Name="VCALinkTool"
			/>
			<Tool
				Name="VCManifestTool"
			/>
			<Tool
				Name="VCXDCMakeTool"
			/>
			<Tool
				Name="VCBscMakeTool"
			/>
			<Tool
				Name="VCFxCopTool"
			/>
			<Tool
				Name="VCAppVerifierTool"
			/>
			<Tool
				Name="VCPostBuildEventTool"
			/>
		</Configuration>
	</Configurations>
	<References>
	</References>
	<Files>
		<File
			RelativePath=".\res.cpp"
			>
		</File>
	</Files>
	<Globals>
	</Globals>
</VisualStudioProject>


#include<bits/stdc++.h>
using namespace std;
const int mod = 1e9+7;
long long dp[300000][2];
string a,b;
int k;
int main()
{
    cin>>a>>b;
    scanf("%d",&k);
    if(a==b)dp[0][0]=1;
    else dp[0][1]=1;
    int x = 0;
    for(int i=0;i<a.size();i++)
    {
        int flag = 1;
        for(int j=0;j<a.size();j++)
        {
            if(a[(i+j)%a.size()]!=b[j])
            {
                flag = 0;
                break;
            }
        }
        if(flag)x++;
    }
    for(int i=0;i<k;i++)
    {
        dp[i+1][0]=(x*dp[i][1]+(x-1)*dp[i][0])%mod;
        dp[i+1][1]=((a.size()-x)*dp[i][0]+(a.size()-x-1)*dp[i][1])%mod;
    }
    printf("%d/n",dp[k][0]);


#include <iostream>
using namespace std;

int main()
{
	int n, a, b;
	cin >> n >> a >> b;
	a = a - 1;
	b = b - 1;

	int round = 1;
	while (n != 2)
	{
		if (a / 2 == b / 2)
		{
			break;
		}
		a = a / 2;
		b = b / 2;
		round++;
		n = n / 2;

	}

	if (n == 2)
		cout << "final!" << endl;
	else
		cout << round << endl;

	system("pause");
	return 0;

}


#include "iostream"
#include "conio.h"
#include "math.h"
#include "stdlib.h"
#include "time.h"
#include "vector"
#include "algorithm"
#include "numeric"
#include "string"
#include "ctime"
#define sp << " "
#define sps << " " <<
#define lnl << endl <<
#define ln << endl
typedef long long ll;
using namespace std;
bool f(int a , int b, int n)
{
	int awer = n / 2;
	if ((a > awer && b <= awer) || (a <= awer && b > awer))
		return true;
	return false;
}

int main()
{
	int n, a, b, cnt = 1, rounds, c, s = 1;
	cin >> n >> a >> b;
	c = n;
	for (int i = 1; i < 9; ++i)
		if (pow(2, i) == n)
			rounds = i;
	while (f(a, b, n) != true)
	{
		rounds--;
		if (a > n / 2)
		{
			a -=  n / 2;
			b -=  n / 2;
			n /= 2;
		}
		else
			n /= 2;
	}
	for (int i = 0; i < rounds; ++i)
		s *= 2;
	if (s == c)
		cout << "Final!";
	else
		cout << rounds;
}


#include <iostream>
#include <cassert>
#include <string>
#include <vector>
#include <deque>
#include <unordered_map>
#include <unordered_set>

template <typename T>
T read_one() {
	T elem; std::cin >> elem;
	return elem;
}

int main() {
	int n = read_one<int>();
	int a = read_one<int>() - 1;
	int b = read_one<int>() - 1;

	int r = 0;
	while (n > 1) {
		++r;
		n /= 2;
	}
	for (int i = r - 1; i >= 0; --i) {
		int mask = 1 << i;
		if ((a & mask) != (b & mask)) {
			if (i == r - 1)
				std::cout << "Final";
			else
				std::cout << (i + 1);
			break;
		}
	}
	return 0;
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <set>
#include <utility>
#include <cstdlib>
#include <list>
#include <climits>
#include <map>
using namespace std;

int main(void) {
    int n, m;
    cin >> n;
    cin >> m;
    cin >> x;
    n -= (x - 1) << 1;
    m -= (x - 1) << 1;
    if (n <= 0|| m <= 0) {
        cout << 0 << endl;
    }
    size = (n * m + 1) >> 1;
    n -= 2;
    m -= 2;
    if (n < 0 || m < 0) {
        cout << size << endl;
    }
    size -= (n * m + 1) >> 1;

    cout << size << endl;
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

int main()
{
	cin>>n>>m>>x;
	x--;
	if(n>m) {
		swap(n,m);
	}
	for(i=1;i<x&&n>0;i++)
	{
		n-=2;m-=2;
	}
	if(n<=0)
	cout<<0;
	else if(n==1)

	cout<<((m+1)>>1);
	else cout<<n+m-2;

	return 0;
}


`
#include <bits/stdc++.h>
typedef long long int ll;
//typedef pair<long long int,long long int> ip;
#define mp make_pair
#define pb push_back
#define rep(g,i,n) for(ll g=i;g<n;++g)

using namespace std;

int main()
{
 ll n,m,x;
 cin>>n>>m>>x;
 if(n%2!=0&&m%2!=0)
 {
     ll y=2*(x-1);
     ll z=(m-y)*(n-y);
     z=z/2;
     //cout<<z<<endl;
     z++;
     //cout<<z<<endl;
     ll w=(m-y-2)*(n-y-2);
    if(m-y-2>0&&n-y-2>0){ w=w/2;
     w++;
     cout<<z-w;}

     else
     {
         cout<<z;
     }
     return 0;

 }

 else if(n%2==0&&m%2==0)
{
    ll y=2*(x-1);
    ll x=m-y;
    ll z=n-y;
   // x=x/2;
   if(x>0&&y>0)
   {
    y=y/2;
    y--;
    cout<<x+(2*y);
    return 0;
   }
   else
   {
       cout<<0;return 0;
   }
}

 else
 {
     if(n%2==0)
     {  ll y=2*(x-1);
        n=n-y;
        m=m-y;
        if(m>0&&n>0)
        {
         n=n/2;
         cout<<n*2+m-2;
         return 0;
        }

        else
        {
            cout<<0;
            return 0;
        }

     }

     else
     {  ll y=2*(x-1);
        m=m-y;
        n=n-y;
        if(m>0&&n>0)
        {
         m=m/2;
         cout<<(2*m)+n-2;
         return 0;
        }

        else
        {
            cout<<0;
            return 0;
        }
     }
 }
    return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <climits>
#include <numeric>
#include <memory.h>
#include <ctime>
clock_t startTime=clock();
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef pair<double, double> pdd;
typedef vector<pdd> vpdd;
typedef vector<vpii> Graph;

#define fr(i,a,b) for(int i(a),_b(b);i<=_b;++i)
#define frd(i,a,b) for(int i(a),_b(b);i>=_b;--i)
#define rep(i,n) for(int i(0),_n(n);i<_n;++i)
#define reps(i,a) fr(i,0,sz(a)-1)
#define all(a) a.begin(),a.end()
#define pb push_back
#define mp make_pair
#define clr(x,a) memset(x,a,sizeof(x))
#define findx(a,x) (find(all(a),x)-a.begin())
#define two(X) (1LL<<(X))
#define contain(S,X) (((S)&two(X))!=0)

const double eps=1e-9;

template<class T> void print(const vector<T> &v){ostringstream os; for(int i=0; i<(int)v.size(); ++i){if(i)os<<' ';os<<v[i];} cout<<os.str()<<endl;}
template<class T> int sz(const T&c){return (int)c.size();}
template<class T> void srt(T&c){sort(c.begin(),c.end());}
template<class T> void checkmin(T &a,T b){if(b<a) a=b;}
template<class T> void checkmax(T &a,T b){if(b>a) a=b;}
template<class T> T sqr(T x){return x*x;}
template<class T, class U> T cast (U x) { ostringstream os; os<<x; T res; istringstream is(os.str()); is>>res; return res; }
template<class T> vector<T> split(string s, string x=" ") {vector<T> res; for(int i=0;i<s.size();i++){string a; while(i<(int)s.size()&&x.find(s[i])==string::npos)a+=s[i++]; if(!a.empty())res.push_back(cast<T>(a));} return res;}
template<class T> bool inside(T r,T c,T R, T C){return r>=0 && r<R && c>=0 && c<C;}

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

int main( int argc, char* argv[] ) {
    #ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	#endif

	int x;
	short R,C;
	cin>>R>>C>>x;

	vvi a(R, vi(C));
	queue<pii> q;

	rep(r,R){
		rep(c,C){
			if(((r+c)&1)==0 && (r==0 || c==0 || r==R-1 || c==C-1)){
				q.push(mp(r,c));
				a[r][c]=1;
			}
		}
	}

	while(!q.empty()){
		pii cur=q.front(); q.pop();
		int r=cur.first;
		int c=cur.second;

		rep(d,4){
			int nr=r+dr[d];
			int nc=c+dc[d];

			if(inside(nr,nc,R,C) && a[nr][nc]==0){
				a[nr][nc]=a[r][c]+1;
				q.push(mp(nr,nc));
			}
		}
	}

	int res=0;
	rep(r,R){
		rep(c,C){
			if(a[r][c]==x)++res;
		}
	}

	cout<<res<<endl;
	//fprintf(stderr,"time=%.3lfsec\n",0.001*(clock()-startTime));

	return 0;
}


#include<iostream>
#include<set>
#include<cmath>
#include<string>
#include<vector>
#include<algorithm>
#include<fstream>
#include<list>
#include<stack>
#include<queue>
using namespace std;
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define sz(v) ((int)v.size())
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
#define reprng(i,a,b) for(int i = a; i <= (int)(b); ++i)
#define reprngr(i,n,a) for(int i = n;i >= (int)(a); --i)
#define For(it,c) for(auto  it=c.begin();it!=c.end();++it)
typedef long long ll;
int main()
{
	ll n;
	cin >> n;
	int digits = ceil(log10(n+1));
	int p = (1 << digits);

	int index = 1;
	rep(i, p)
	{
		int pow = 1;
		ll result = 0;
		rep(j, digits)
		{

			if (((i >> j) & 1 )== 0)
			{
				result += 4 * pow;
			}
			else
				result += 7 * pow;
			pow *= 10;
		}
		if (result == n)
			break;
		index++;

	}
	reprng(i, 1, digits - 1 )
	{
		index += (1 << i);
	}
	cout << index;

	return 0;
}


#include<iostream>
#include<cmath>
#include<math.h>
using namespace std;
void main()
{
    int n,k=1;
    cin>>n;
    int t=n,r=0, j=0;
    for(int i=0;t!=0;i++)
        {
            r=t%10;
            t=(t-r)/10;
            if(r==4)j+=pow(2,i);
            else if(r==7)j+=(pow(2,i)*2);
        }

    cout<<j;
}


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

int num, n , ans;
int ada ;

int func(int x){
	if(x == 0) return num ;
	else {
		num = pow(2,x) + num ;
		return func(x-1) ;
	}
}

int main(){
	cin >> n ;
	string s = to_string(n) ;
	int c = abs(s.length()) ;
	for(int i = 0; i < s.length() ; i++){
		if(s[i] == '7') ada = pow(2,c-i) + ada ;
	}
	if(ada == 0) ada = 1 ;
	ans = func(s.length()-1) + ada ;
	cout << ans << '\n' ;
	return 0 ;
}


#include <iostream>
#include <algorithm>
#include <sstream>

using namespace std;

bool is(int n)
{
    bool statement = true;

    while(n>0)
    {
        if(n%10!=4 && n%10!=7)
        {
            statement = false;
            break;
        }
        n/=10;
    }

    return statement;
}

int play(int n)
{
    int what_pow = 0;
    int k = n;
    while(k>0)
    {
        k/=10;
        what_pow++;
    }

    int exp;
    exp = pow(2,what_pow+1)-2;//Es

    int sub = 1;

    while(n>0)
    {
        if(n%10==4)
            exp-=sub;
        sub++;
        n/=10;
    }

    return exp;
}

int main()
{
    int n;

    cin >> n;

    cout << play(n);

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
void printDig(long k)
{
    if(k==1)
    {cout<<"0";
     k--;
    return;
    }
    else if(k==0)
    {return;
    }
    else if((k%2)==0)
    {
        cout<<"8";
        printDig(k-2);
    }
    else if((k%2)!=0)
    {
        cout<<"4";
        printDig(k-1);
    }

}
int main()
{

    long k;
    cin>>k;
    if(k>=37)
        {cout<<"-1";
        return 0}
        if(k==0)
            {cout<<"5";
        return 0;};
    printDig(k);
}