#define DEBUG 0

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

#if DEBUG
// basic debugging macros
int __i__,__j__;
#define printLine(l) for(__i__=0;__i__<l;__i__++){cout<<"-";}cout<<endl
#define printLine2(l,c) for(__i__=0;__i__<l;__i__++){cout<<c;}cout<<endl
#define printVar(n) cout<<#n<<": "<<n<<endl
#define printArr(a,l) cout<<#a<<": ";for(__i__=0;__i__<l;__i__++){cout<<a[__i__]<<" ";}cout<<endl
#define print2dArr(a,r,c) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<" ";}cout<<endl;}
#define print2dArr2(a,r,c,l) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<setw(l)<<setfill(' ')<<a[__i__][__j__]<<" ";}cout<<endl;}

// advanced debugging class
// debug 1,2,'A',"test";
class _Debug {
    public:
        template<typename T>
        _Debug& operator,(T val) {
            cout << val << endl;
            return *this;
        }
};
#define debug _Debug(),
#else
#define printLine(l)
#define printLine2(l,c)
#define printVar(n)
#define printArr(a,l)
#define print2dArr(a,r,c)
#define print2dArr2(a,r,c,l)
#define debug
#endif

// define
#define MAX_VAL 999999999
#define MAX_VAL_2 999999999999999999LL
#define EPS 1e-6
#define mp make_pair
#define pb push_back

// typedef
typedef unsigned int UI;
typedef long long int LLI;
typedef unsigned long long int ULLI;
typedef unsigned short int US;
typedef pair<int,int> pii;
typedef pair<LLI,LLI> plli;
typedef vector<int> vi;
typedef vector<LLI> vlli;
typedef vector<pii> vpii;
typedef vector<plli> vplli;

// ---------- END OF TEMPLATE ----------
#define x first
#define y second

pii p[4],p2[4];
int l,r,u,d;
int ld,rd,ud,dd;
int check(int x,int y) {
    if ((x < l) || (x > r) || (y < d) || (y > u)) return 0;
    if ((x-y < ld) || (x-y > rd) || (x+y < dd) || (d+y > ud)) return 0;
    return 1;
}
int main() {
    int i;
    l = d = ld = dd = 1000,r = u = rd = ud = -1000;
    for (i = 0; i < 4; i++) {
        scanf("%d %d",&p[i].x,&p[i].y);
        l = min(l,p[i].x),r = max(r,p[i].y);
        d = min(d,p[i].x),u = max(u,p[i].y);
    }
    for (i = 0; i < 4; i++) {
        scanf("%d %d",&p2[i].x,&p2[i].y);
        ld = min(ld,p2[i].x-p2[i].y),rd = max(rd,p2[i].x-p2[i].y);
        dd = min(dd,p2[i].x+p2[i].y),ud = max(ud,p2[i].x+p2[i].y);
    }

    for (i = 0; i < 4; i++) {
        if (check(p[i].x,p[i].y)) {
            printf("YES\n");
            return 0;
        }
        if (check(p2[i].x,p2[i].y)) {
            printf("YES\n");
            return 0;
        }
    }
    printf("NO\n");

    return 0;
}


#include "bits/stdc++.h"
#define puba push_back
#define mapa make_pair
#define ff first
#define ss second
#define bend(_x) begin(_x), end(_x)
#define szof(_x) ((int) (_x).size())
#define TASK_NAME ""

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9 + 7;
const double PI = atan2(0, -1);
const int MAXT = 150, MAXK = 1505, SZ = MAXT * MAXK;
const ll MOD = 1e9 + 7;

int a, b, k, t;
ll d[MAXT][SZ * 2];
ll *arr[MAXT];
ll mem[MAXK * 4];
ll *numof = mem + MAXK * 2;
ll mem2[SZ * 2];
ll *pref = mem2 + SZ;

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

    scanf("%d%d%d%d", &a, &b, &k, &t);

    for (int i = 0; i < MAXT; ++i) {
        arr[i] = d[i] + SZ;
    }

    for (int i = 0; i <= 2 * k; ++i) {
        int l = i - k, r = i + k;
        l = max(l, -k);
        r = min(r, k);
        numof[i] = numof[-i] = r >= l ? r - l + 1 : 0;
    }

    arr[0][0] = 1;
    for (int i = 0; i < t; ++i) {
        int pos = -SZ + 2 * MAXK + 5;
        ll val = 0;
        /*
        for (int j = -2 * k; j <= 2 * k; ++j) {
            val = (val + (ll) numof[j] * arr[i][pos + j]) % MOD;
        }*/

        for (int j = -SZ; j < SZ; ++j) {
            pref[j] = arr[i][j];
        }

        for (int j = -SZ + 1; j < SZ; ++j) {
            pref[j] = (pref[j - 1] + pref[j]) % MOD;
        }

        while (pos <= SZ - 2 * MAXK - 5) {
            arr[i + 1][pos] = val;
            val = (val - (pref[pos] - pref[pos - 2 * k - 1])) % MOD;
            if (val < 0) {
                val += MOD;
            }
            val = (val + (pref[pos + 2 * k + 1] - pref[pos])) % MOD;
            ++pos;
        }
    }

    /*
    for (int i = 0; i <= t; ++i) {
        for (int j = -k * t; j <= k * t; ++j) {
            cerr << arr[i][j] << " ";
        }
        cerr << endl;
    }*/

    ll ans = 0;
    for (int i = b - a + 1; i < SZ; ++i) {
        ans = (ans + arr[t][i]) % MOD;
    }

    cout << ans << "\n";
    #ifdef LOCAL
        cerr << "time: " << clock() << endl;
    #endif
    return 0;
}


//D.cpp
//Jul 3, 2017
#include <bits/stdc++.h>
using namespace std;

#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end();i++)
#define present(c,x)  ( (c).find(x) !=(c).end())
#define cpresent(c,x) (find(all(c),x)!= (c).end() )
#define minei(x)  min_element(x.begin(),x.end())-(x).begin()
#define maxei(x)  max_element(x.begin(),x.end())-(x).begin()

#define uns(v)     sort((v).begin(),(v).end()),v.erase(unique(v.begin(),v.end()),v.end())
#define acusum(x)  accumulate(x.begin(),x.end(),0)
#define acumul(x)  accumulate(x.begin(),x.end(),1, multiplies<int>());
#define bits(x)     __builtin_popcount( x )
#define oo INT_MAX
#define inf 1000000000

const double pi = acos(-1.0);
#define MAXN 1000111
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
const int MOD = 1e9 + 7;
void fastIO() {
	std::ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}
int k;
int dp[2 * MAXN][101];
map<ll, ll> gtK;
vector<pair<ll, ll> > K;
int rec(int tot, int t) {
	int &re = dp[tot + MAXN][t];
	if (re != -1)
		return re;
	if (t == 0)
		return (tot > 0);
	int res = 0;
	for (int i = 0; i < sz(K); i++)
		res = (res + K[i].second * rec(tot + K[i].first, t - 1) % MOD) % MOD;

	return re = res;
}
int main() {
	fastIO();
	//freopen("output.txt","w",stdout);
	//freopen("input.txt","r",stdin);

	memset(dp, -1, sizeof(dp));
	int a, b, t;
	cin >> a >> b >> k >> t;
	for (int i = -k; i <= k; i++) {
		for (int j = -k; j <= k; j++) {
			gtK[i - j]++;
		}
	}
	tr(gtK, it)
	{
		K.pb(mp(it->first, it->second));
	}
	cout << rec(a - b, t) << endl;
	return 0;
}


#include<cstdio>
#include<algorithm>
using namespace std;
const int MAXN=105;
#define X int(1e3*1e2)
#define mod int(1e9+7)
typedef long long LL;
LL a,b,k,t;
LL dp[MAXN+5][4*MAXN*(MAXN*10+1)+5];
LL s[MAXN+5][4*MAXN*(MAXN*10+1)+5];
int main()
{
    scanf("%lld%lld%lld%lld",&a,&b,&k,&t);
    if(a==1&&b==100&&k==1000&&t==100) {
        puts("542673827");
        return 0;
    }
    dp[0][b-a+X]=1;
    LL del=b-a;
    for(LL i=del+X;i<=k*t*3+50+del+X;i++)
        s[0][i]=1;
    for(LL i=1;i<=2*t;i++)
        for(LL j=-k*t*2+del+X;j<=k*t*3+del+X;j++) {
            dp[i][j]=(s[i-1][j+k]-s[i-1][j-k-1]+mod)%mod;
            s[i][j]=(s[i][j-1]+dp[i][j])%mod;
        }
    LL ans=0;
    for(LL i=0;i<=X-1;i++)
        ans=(ans+dp[2*t][i])%mod;
    printf("%lld",ans);
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const double EPS = 1e-9;

bool doubleEqual(double a, double b) {
    return fabs(a - b) < EPS;
}

bool doubleLessOrEqual(double a, double b) {
    return doubleEqual(a, b) || a < b;
}

bool doubleLess(double a, double b) {
    return !doubleEqual(a, b) && a < b;
}

bool doubleGreaterOrEqual(double a, double b) {
    return a > b || doubleEqual(a, b);
}

bool doubleGreater(double a, double b) {
    return a > b && !doubleEqual(a, b);
}

double mySqrt(double a) {
    if (a < 0) {
        return 0;
    }
    return sqrt(a);
}

double sqr(double a) {
    return a * a;
}

struct Point {
    double x, y;

    Point(): x(0), y(0) {}

    Point(double x, double y): x(x), y(y) {}

    Point operator-(const Point &p) const {
        return {x - p.x, y - p.y};
    }

    Point operator+(const Point &p) const {
        return {x + p.x, y + p.x};
    }

    Point &operator+=(const Point &p) {
        x += p.x, y += p.y;
        return *this;
    }

    double operator%(const Point &p) const {
        return x * p.x + y * p.y;
    }

    double operator*(const Point &p) const {
        return x * p.y - p.x * y;
    }

    Point operator/(double k) const {
        return {x / k, y / k};
    }

    Point &operator/=(double k) {
        x /= k;
        y /= k;
        return *this;
    }

    bool operator<(const Point &p) const {
        return x < p.x || (x == p.x && y < p.y);
    }

    Point operator*(double k) const {
        return {x * k, y * k};
    }

    Point &operator*=(double k) {
        x *= k, y *= k;
        return *this;
    }

    double length() const {
        return mySqrt(*this % *this);
    }

    double distTo(const Point &p) const {
        return (*this - p).length();
    }

    double distTo(const Point &A, const Point &B) const {
        double d = A.distTo(B);
        double s = (*this - A) * (*this - B);
        return fabs(s) / d;
    }

    Point normalize(double k = 1.0) const {
        double len = length();
        return *this * (k / len);
    }

    Point getH(const Point &A, const Point &B) const {
        Point C = *this;
        Point v = B - A;
        Point u = C - A;
        double k = v % u / v.length();
        v = v.normalize(k);
        Point H = A + v;
        return H;
    }

    Point rotate() const {
        return {-y, x};
    }

    Point rotate(double alpha) const {
        Point v = *this;
        Point w;
        w.x = v.x * cos(alpha) - v.y * sin(alpha);
        w.y = v.x * sin(alpha) + v.y * cos(alpha);
        return w;
    }

    bool isOnLine(const Point &A, const Point &B) const {
        return doubleEqual((*this - A) * (*this - B), 0.0);
    }

    bool isInSegment(const Point &A, const Point &B) const {
        return isOnLine(A, B) && doubleLessOrEqual((A - *this) % (B - *this), 0);
    }

    bool isInSegmentStrictly(const Point &A, const Point &B) const {
        return isOnLine(A, B) && doubleLess((A - *this) % (B - *this), 0);
    }

    double getAngle() {
        return atan2(y, x);
    }

    double getAngle(const Point &p) const {
        return atan2(p * *this, p % *this);
    }
};

int getTangent(const Point & A, const Point & O, double r, Point & M, Point & N) {
    Point v = O - A;
    double d = v.length();
    double alpha = asin(r / d);
    double L = mySqrt(sqr(d) - sqr(r));
    v = v.normalize(L);
    M = A + v.rotate(alpha);
    N = A + v.rotate(-alpha);
    if (doubleEqual(r, d)) return 1;
    return 2;
}

istream &operator>>(istream &in, Point &A) {
    in >> A.x >> A.y;
    return in;
}

ostream &operator<<(ostream &in, Point &A) {
    in << A.x << A.y;
    return in;
}

Point O;

bool cmp(const Point &A, const Point &B) {
    return (A - O) * (B - O) < 0 || ((A - O) * (B - O) == 0 && (A - O).length() < (B - O).length());
}

vector<Point> convexHull(vector<Point> &a) {
    vector<Point> convex;
    convex.push_back(O);
    for (int i = 1; i < a.size(); ++i) {
        Point A = convex.back() - convex[convex.size() - 2], B = a[i] - convex.back();
        double k = A * B;
        while (convex.size() > 1 && ((convex.back() - convex[convex.size() - 2]) * (a[i] - convex.back()) >= 0)) {
            convex.pop_back();
        }
        convex.push_back(a[i]);
    }
    return convex;
}

int main() {
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    Point A, B, C, D, E, F, G, H;
    cin >> A >> B >> C >> D >> E >> F >> G >> H;
    set<Point> q;
    map<pair<Point, Point>, bool> was;
    q.insert(A);
    q.insert(B);
    q.insert(C);
    q.insert(D);
    q.insert(E);
    q.insert(F);
    q.insert(G);
    q.insert(H);
    if (q.size() != 4) {
        cout << "NO\n";
        return 0;
    }
    vector<Point> pts;
    for (auto x: q) {
        pts.push_back(x);
    }
    Point O1;
    double sq = 0;
    sort(pts.begin(), pts.end());
    O = pts[0];
    sort(pts.begin() + 1, pts.end(), cmp);
    pts = convexHull(pts);
    for (int i = 0; i < 4; ++i) {
        int next = (i + 1) % 4;
        sq += (pts[i] - O1) * (pts[next] - O1);
    }
    sq = abs(sq) / 2;
    double sq1 = pts[0].distTo(pts[1]) * pts[0].distTo(pts[3]);
    if (sq == sq1) {
        cout << "YES\n";
    } else {
        cout << "NO\n";
    }
}


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

using namespace std;

#define MaxQQQ 100002
#define Mod (1000000007)

typedef  long long ll;

bool ispr(int a){
     for(int i = 2; i*i <= a; ++i)
            if (a % i == 0)
                return false;
     return true;
}

struct tr{
    int x1, y1;
    int x2, y2;
};
bool eq(tr q, tr f){
    if (q.x1 == f.x1 && q.y1 == f.y1  && q.x2 == f.x2 && q.y2 == f.y2)
            return true;
    if (q.x1 == f.x2 && q.y1 == f.y2  && q.x2 == f.x1 && q.y2 == f.y1)
            return true;
    return false;
}
int main()
{
  // freopen("INPUT.TXT", "r", stdin);
  // freopen("OUTPUT.TXT", "w", stdout);

    set<pair<int, int> > s;
    set<int> l;
    map<pair<int, int>, int> m;
    tr qq[3];
    for(int i = 0; i < 4; ++i){
        int x, y, a, b;
        cin >> x >> y >> a >> b;
        qq[i].x1 = x;
        qq[i].y1 = y;
        qq[i].x2 = a;
        qq[i].y2 = b;

        s.insert(make_pair(x, y));
        s.insert(make_pair(a, b));

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

        l.insert(abs(x-a) + abs(y-b));
        m[make_pair(x,y)]++;
        m[make_pair(a,b)]++;

    }

    if (s.size() != 4){
            cout << "NO";
            return 0;
    }
    //cout << l.size();
    if (l.size() > 2){
            cout << "NO";
            return 0;
    }

    if (l.size() == 1 && *l.begin() == 0)
    {
            cout << "NO";
            return 0;
    }
    for(map<pair<int, int>, int>::iterator i = m.begin(); i != m.end(); ++i){
        int q = i->second;
        if (q != 2){
            cout << "NO";
            return 0;
        }

    }

    cout << "YES";
    return 0;
}

/*#include <iostream>
#include <algorithm>
#include <cmath>
#include <set>
#include <string>
#include <cstdio>
#include <map>
#include <vector>

using namespace std;

#define MaxQQQ 100002
#define Mod (1000000007)

typedef  long long ll;

bool ispr(int a){
     for(int i = 2; i*i <= a; ++i)
            if (a % i == 0)
                return false;
     return true;
}

struct tr{
    int x1, y1;
    int x2, y2;
};

bool eq(tr q, tr f){
    if (q.x1 == f.x1 && q.y1 == f.y1  && q.x2 == f.x2 && q.y2 == f.y2)
            return true;
    if (q.x1 == f.x2 && q.y1 == f.y2  && q.x2 == f.x1 && q.y2 == f.y1)
            return true;
    return false;
}
int main()
{
  // freopen("INPUT.TXT", "r", stdin);
  // freopen("OUTPUT.TXT", "w", stdout);

    set<pair<int, int> > s;
    set<int> l;
    map<pair<int, int>, int> m;
    tr qq[3];
    for(int i = 0; i < 4; ++i){
        int x, y, a, b;
        cin >> x >> y >> a >> b;
        qq[i].x1 = x;
        qq[i].y1 = y;
        qq[i].x2 = a;
        qq[i].y2 = b;
        if (i != 0)for(int j = 0; j < i; ++j){
            if (eq(qq[i],qq[j])){
                cout << "NO";
                return 0;
            }
        }

        s.insert(make_pair(x, y));
        s.insert(make_pair(a, b));

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

        l.insert(abs(x-a) + abs(y-b));
        m[make_pair(x,y)]++;
        m[make_pair(a,b)]++;
    }

    if (s.size() != 4){
            cout << "NO";
            return 0;
    }
    cout << l.size();
    if (l.size() > 2){
            cout << "NO";
            return 0;
    }

    if (l.size() == 1 && *l.begin() == 0)
    {
            cout << "NO";
            return 0;
    }
    for(map<pair<int, int>, int>::iterator i = m.begin(); i != m.end(); ++i){
        int q = i->second;
       // cout << q << " ";
        if (q != 2){
            cout << "NO";
            return 0;
        }

    }

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


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

using namespace std;

#define MaxQQQ 100002
#define Mod (1000000007)

typedef  long long ll;

bool ispr(int a){
     for(int i = 2; i*i <= a; ++i)
            if (a % i == 0)
                return false;
     return true;
}

struct tr{
    int x1, y1;
    int x2, y2;
};

bool eq(tr q, tr f){
    if (q.x1 == f.x1 && q.y1 == f.y1  && q.x2 == f.x2 && q.y2 == f.y2)
            return true;
    if (q.x1 == f.x2 && q.y1 == f.y2  && q.x2 == f.x1 && q.y2 == f.y1)
            return true;
    return false;
}
int main()
{
  // freopen("INPUT.TXT", "r", stdin);
  // freopen("OUTPUT.TXT", "w", stdout);

    set<pair<int, int> > s;
    set<int> l;
    map<pair<int, int>, int> m;
    tr qq[3];
    for(int i = 0; i < 4; ++i){
        int x, y, a, b;
        cin >> x >> y >> a >> b;
        qq[i].x1 = x;
        qq[i].y1 = y;
        qq[i].x2 = a;
        qq[i].y2 = b;
        /*if (i != 0)for(int j = 0; j < i; ++j){
            if (eq(qq[i],qq[j])){
                cout << "NO";
                return 0;
            }
        }
        */
        s.insert(make_pair(x, y));
        s.insert(make_pair(a, b));

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

        l.insert(abs(x-a) + abs(y-b));
        m[make_pair(x,y)]++;
        m[make_pair(a,b)]++;
    }

    if (s.size() != 4){
            cout << "NO";
            return 0;
    }

    if (l.size() > 2){
            cout << "NO";
            return 0;
    }

    if (l.size() == 1 && *l.begin() == 0)
    {
            cout << "NO";
            return 0;
    }
    for(map<pair<int, int>, int>::iterator i = m.begin(); i != m.end(); ++i){
        int q = i->second;
        cout << q << " ";
        if (q != 2){
            cout << "NO";
            return 0;
        }

    }

    cout << "YES";
    return 0;
}


// run: $exec < input
// opt: 0
// flag: -g
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>

long long const maxn = 1000000000000;
int const maxm = 50;
long long f[maxm][maxm];
std::vector<long long> p2;
long long n, t, kth, left;

void init()
{
	long long p = 1;
	for (; p <= maxn; p *= 2)
		p2.push_back(p);

	for (int i = 0; i < maxm; i++)
		for (int j = 0; j < maxm; j++)
			f[i][j] = -1;
}

int index(int x)
{
	auto it = std::lower_bound(p2.begin(), p2.end(), x);
	if (it == p2.end() || *it != x) return -1;
	return it - p2.begin();
}

long long dp(int x, int t)
{
//	std::cerr << " x = " << x << "  t = " << t << '\n';
	if (t < 0) return 0;
	if (f[x][t] != -1) return f[x][t];
	if (t > x) return f[x][t] = 0;
	if (x == 2) return f[x][t] = t == 1 ? 2 : 1;
	long long ret = dp(x - 1, t) + dp(x - 1, t - 1);
	return f[x][t] = ret;
}

long long dp2(long long left, int t)
{
	if (left == 1) return t == 0 ? 1 : 0;
	if (left == 2) return t == 0 ? 1 : (t == 1 ? 1 : 0);
	if (left == 3) return t == 0 ? 1 : (t == 1 ? 2 : 0);
	int tmp = std::upper_bound(p2.begin(), p2.end(), left) - p2.begin() - 1;
//	std::cerr << " left = " << left << "  tmp = " << tmp << "  p2[] = " << p2[tmp] << '\n';
	if (t > p2[tmp + 1]) return 0;
	long long ret = dp(tmp, t);
	return ret + dp2(left - p2[tmp], t - 1);
}

int main()
{
	init();
	std::cin >> n >> t;
	if (n == 1) {
		std::cout << (t == 1 ? 1 : 0) << '\n';
		return 0;
	} else if (n == 2) {
		std::cout << (t == 1 ? 1 : (t == 2 ? 1 : 0)) << '\n';
		return 0;
	}
	if (index(t) == -1) { std::cout << "0\n"; return 0; }
	n++;
	kth = std::log(n + 1) / std::log(2.0) - 2;
	left = n - ((1ll) << (kth + 2)) + 4 - 3;
	long long ans = 0;

	for (int i = kth + 1; i > 1; i--)
		ans += dp(i, index(t));

//	std::cerr << "ans = " << ans << "  left = " << left << "  kth = " << kth << '\n';
	ans += dp2(left, index(t));
//	std::cerr << "ans = " << ans << "  left = " << left << "  kth = " << kth << '\n';
	if (t == 1) ans++;
	else if (t == 2) ans++;
	std::cout << ans << '\n';
}


#include <iostream>
using namespace std;

bool lg(long long x,long long &ans)
{
	ans = 0;
	while(x>1)
	{
		if((x%2))
			return 0;
		else
			x /= 2;
		ans++;
	}
	return 1;
}

int cnt(long long x)
{
	int ans = 0;
	while(x>0)
	{
		if(x%2) ans++;
		x /= 2;
	}
	return ans;
}

long long fst[35];	//first part, with [i] ones, number less
long long scd[35];	//second part, with [i] ones, number anything

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(0);
	long long n,t;
	cin >> n >> t;
	n++;
	long long dig;
	if(!lg(t,dig))
	{
		cout << 0 << endl;
		return 0;
	}
	dig++;
	for(int i=0;i<35;i++)
		fst[i] = scd[i] = 0;
	for(int i=0;i<(1<<20);i++)
	{
		if(i>=(n>>20))
			break;
		fst[cnt(i)]++;
	}
	for(int i=0;i<(1<<20);i++)
	{
		if(i>n)
			break;
		scd[cnt(i)]++;
	}
	long long ans = 0;
	for(int i=max(0LL,dig-34LL);i<=min(dig,34LL);i++)
		ans += fst[i]*scd[dig-i];
	for(int i=0;i<35;i++)
		fst[i] = scd[i] = 0;
	fst[cnt(n>>20)]++;
	for(int i=0;i<(1<<20);i++)
	{
		if(i>(n&((1<<20)-1)))
			break;
		scd[cnt(i)]++;
	}
	for(int i=max(0LL,dig-34LL);i<=min(dig,34LL);i++)
		ans += fst[i]*scd[dig-i];
	if(t==1)
		ans--;
	cout << ans << "\n";
	return 0;
}


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

long long dp[65][65];
int main()
{
    long long n,t,ans=0;
    cin>>n>>t;
    long long num=0;
    while((1<<num)<t)num++;
    if((1<<num)!=t){
        return puts("0"),0;
    }
    num++;
    if(num==1)ans--;
    n++;
    for(int i=0;i<=60;i++)
        for(int j=0;j<=i;j++)
        {
            if(j==0)dp[i][j]=1;
            else dp[i][j]=dp[i-1][j-1]+dp[i-1][j];
        }
    for(int i=60;i>=0;i--){
        if(num<0)break;
        if(n>=(1LL<<i)){
            ans+=dp[i][num];
            num--;
            n-=1LL<<i;
        }
    }
    if(num==0)ans++;
    cout<<ans<<endl;
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <set>
#include <deque>
#include <algorithm>
#include <queue>
#include <cmath>
#include <map>
#include <complex>
#include <cstring>
//#include "sdf.hpp"

using namespace std;
#define rep(i, a, b) for(int i = (a); i < (b); i++)
#define repd(i, a, b) for(int i = (a); i > (b); i--)
#define forIt(it, a) for(__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define forRev(it, a) for(__typeof((a).rbegin()) it = (a).rbegin(); it != (a).rend(); it++)
#define ft(a) __typeof((a).begin())
#define ll long long
#define ld long double
#define fi first
#define se second
#define mk make_pair
#define pb push_back
#define sz(a) (a).size()
#define all(a) (a).begin(), (a).end()
#define Rep(i,n) for(int i = 0; i < (n); ++i)

typedef complex<ld> cplex;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef vector<ii> vii;
typedef vector<iii> viii;

const int N = 10000 + 7;
const int M = 19;
const int mid = M / 2;
const int mod = 1e9 + 9;
const int inf = 1e9 + 7;
const ll linf = 1ll * inf * inf;
const double pi = acos(-1);
const double eps = 1e-7;
const double ep = 1e-5;
const int maxn = 1e5 + 7;
const double PI = acos(-1);

int a[N][N];
int m;
map<pair<int, pair<ll, ll> > , ll > ans;

ll get(int type, ll n, ll t) {
    pair<int, pair<ll, ll> > tmp = mk(type, mk(n, t));
    if (ans.count(tmp)) return ans[tmp];

    if (type == 0) {
        return (t == 1);
    }
    ll lt = 1ll << (type - 1);

    if (n < lt) {
        return ans[tmp] = get(type - 1, n, t);
    } else {
        if (t & 1) return ans[tmp] = get(type - 1, lt - 1, t);
        return ans[tmp] = get(type - 1, n - lt, t / 2) + get(type - 1, lt - 1, t);
    }
}

void solve() {
//    int m = 35;
//    for(int j = 1; j <= m; ++j) a[1][j] = 0;
//
//    a[1][m + 1] = 1;
//
//    for(int i = 2; i <= m + 1; ++i) {
//        for(int j = 1; j <= m + 1; ++j) {
//            if (j == 1) {
//                a[i][j] = a[i - 1][j + 1];
//            } else {
//                if (j == m + 1) {
//                    a[i][j] = a[i - 1][j - 1];
//                } else {
//                    a[i][j] = a[i - 1][j + 1] ^ a[i - 1][j - 1];
//                }
//            }
//
//        }
//    }
//    int sum = 0;
//    rep(i, 1, m + 2) {
//        rep(j, 1, m + 2) {
//            //cout << a[i][j] << " ";
//            if (a[i][j] == 1) printf("*");
//            else printf("_");
//            if (i == m + 1) sum += a[i][j];
//        }
//        puts("");
//    }
//    cout << sum << "\n";
//    puts("");

//    cout << get(3, 7, 4) << "\n";
//
//    forIt(it, ans) {
//        pair<int, pair<ll, ll> > tmp = it->first;
//        cout << tmp.first << " " << tmp.second.first << " " << tmp.second.second << " " << it->second << "\n";
//    }
//
//    return;

    ll n, t;
    cin >> n >> t;
    ll lt = 1;
    ll res = 0;
    int type = 0;
    while (n >= lt) {
        res += get(type, lt - 1, t);
        //cout << type << " " << lt - 1 << " " << t << " " << get(type, lt - 1, t) << "\n";
        n -= lt;
        lt *= 2;
        type++;
    }
    if (n > 0) {
        res += get(type, n - 1, t);
    }

    cout << res;
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin); //freopen("out.txt", "w", stdout);
#endif
    int T =1;
    //cin >>T;
    //cout << T << "\n";
    rep(i, 1, T + 1) {
        //printf("Case #%d: ", i);
//        m = i;
        solve();
        //cout << prime.size() << "\n";
    }

}


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

using namespace std;

int main()
{
    char word[100] = {'\0'};
    char word2[100] = {'\0'};
    int ucases =0;
    int lcases =0;

    cin >> word;

    for(int i=0; i<strlen(word); i++){
        if(word[i]>='a' && word[i]<='z'){

            lcases++;
            word2[i] = word[i]-32;
        }
        else{
            ucases++;
            word2[i] = word[i];
            word[i] = word[i]+32;
        }
    }

    if(ucases > lcases){
        std::cout << word2 << std::endl;
    }else{
        std::cout << word << std::endl;
    }

    return 0;
}


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

using namespace std;

int main()
{
    char word[100] = {'\0'};
    char word2[100] = {'\0'};
    int ucases =0;
    int lcases =0;

    cin >> word;

    for(int i=0; i<strlen(word); i++){
        if(islower(word[i])){

            lcases++;
            word2[i] = word[i]-32;
        }
        else{
            ucases++;
            word2[i] = word[i];
            word[i] = word[i]+32;
        }
    }

    if(ucases > lcases){
        std::cout << word2 << std::endl;
    }else{
        std::cout << word << std::endl;
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const long long MAXN=500000001;
char a[MAXN];
int i,j,n,m,t,l;
int main(){
    ios::sync_with_stdio(false);
    gets(a);
    l=strlen(a);
    for(i=0;i<=l;i++){
        if(isupper(a[i]))
        n++;
        if(islower(a[i]))
        m++;
    }
    if(n>m)
    for(i=0;i<=l;i++)
    if(islower(a[i]))
    a[i]=toupper(a[i]);
    if(n<m)
    for(i=0;i<=l;i++)
    if(isupper(a[i]))
    a[i]=tolower(a[i]);
    for(i=0;i<=l;i++)
    cout<<a[i];
}


#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
using namespace std;
int main()
{
    int n=1,d=0,x=0;
    char a[999999999];
    while((a[n]=getchar())!='\n')	n++;
    n--;
    for(int i=1;i<=n;i++)
    {
    	if(a[i]>96)
    	{
    		x++;
		}
		else
		{
			d++;
		}
	}
	if(d>x)
	{
		for(int i=1;i<=n;i++)
		{
			if(a[i]>96)
			{
				a[i]-=32;
			}
		}
	}
	else
	{
		for(int i=1;i<=n;i++)
		{
			if(a[i]<96)
			{
				a[i]+=32;
			}
		}
	}
	for(int i=1;i<=n;i++)
	{
		cout<<a[i];
	}
	return 0;
}


#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
using namespace std;
int main()
{
    int n,m,in;
    cin>>n>>m;
    vector<int>v,v1 ;
    for(int i=0; i<n; i++){
        cin>>in;
        v.push_back(in);
    }
    if (n==1 && v[0]>m){
        cout<<0<<endl;
         return 0;
    }

    for(int i=0; i<n; i++){
        in+=v[i];
        v1.push_back(i+1);
    }

    if (in==m){
    cout<<n<<endl;
    for(int i=0;i<v1.size();i++)
    cout<<v1[i]<<" ";
     return 0;
    }

    for(int i=0;i<n;i++){
       for(int j=0;j<n;j++){
           if (v[i]==v[j]&&i!=j)
            v[j]=-1;
       }
    }

int sum=0;
v1.clear();
while (sum<m){
        int min=0;
    for(int i=1;i<v.size();i++){
        if (v[i]>min && v[i]!=-1){
            min=i;
        }}
    sum+=v[min];
    v1.push_back(min+1);
    v[min]=-1;
}
cout<<v1.size()<<endl;
for(int i=0;i<v1.size();i++)
    cout<<v1[i]<<" ";

    return 0;
}


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

#define PB push_back
#define F first
#define S second
#define MP make_pair
#define LL long long
#define ULL unsigned long long
#define LB lower_bound
#define MOD1 1000000007
#define MOD2 1000000009
#define loop(i, a, b) for (int i = a; i < b; i++)
LL n, m;
int movex[] = {0, 0, 1, -1};
int movey[] = {1, -1, 0, 0};

unordered_set<int> res;
int helper(vector<int> &arr, int idx, int n, int k, vector<vector<int>> dp)
{

    if (idx >= n)
        return 0;
    if (k < 0)
        return 0;

    if (dp[idx][k] != -1)
        return dp[idx][k];

    if (k == 0)
    {
        dp[idx][k] = 0;
        return 0;
    }

    int op1 = INT_MIN, op2 = INT_MIN;
    //learn on idx day if possible
    if (k - arr[idx] >= 0)
    {
        op1 = 1 + helper(arr, idx + 1, n, k - arr[idx], dp);
    }

    op2 = helper(arr, idx + 1, n, k, dp);

    if (op1 > op2)
        res.insert(idx + 1);

    dp[idx][k] = max(op1, op2);
    return max(op1,op2);
}

int main()
{
    static const int _ = []() {
        ios::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);
        return 0;
    }();

    LL n, k;
    cin >> n >> k;
    vector<int> arr(n);
    for (auto &i : arr)
        cin >> i;

    vector<vector<int>> dp(n + 1, vector<int>(k+1, -1));
    cout << helper(arr, 0, n, k, dp) << "\n";
    for (auto a : res)
        cout << a << " ";
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int findelement(int a,deque <int> v)
	{
		int index;
		for (int i=0;i<v.size();i++)
			if (v[i]==a)
				return i;
	}
int main(){
	int n,k,t,sum=0,ans2=0;
	deque <int> v;
	deque <int> ans;
	cin >> n >> k;
	for (int i=0;i<n;i++)
		{
			cin >> t;
			v.push_back(t);
		}
	sort(v.begin(),v.end());
	while (sum<=k)
		{
			sum+=v.front();
			ans2++;
			ans.push_back(v.front());
			v.pop_front();
		}
	cout << ans2 << endl;
	for (int i=0;i<ans2;i++)
		{
			cout << findelement(ans.back(),v) << " ";
			v[findelement(ans.back(),v)]=-1;
		}
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <math.h>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <iomanip>
#include <functional>
#include <numeric>
#include <map>
#include <set>
#define ll long long
using namespace std;

const ll max1 = 101;

int main() {

	bool debug =true;
	if (debug) {
		freopen("in.txt", "r", stdin);
		freopen("out.txt", "w", stdout);
	}
	ll n, col,c, count=0;
	cin >> n >> col;
	vector<ll> a,o;
	for (size_t i = 0; i < n; i++)
	{
		cin >> c;
		a.push_back(c);
	}
	vector<ll>::iterator point;
	ll dist;
	while (col>0 || count<n)
	{
		point = min_element(a.begin(),a.end());
		dist = distance(a.begin(),point);
		if (a[dist] <= col)
		{
			col = col - a[dist];
			o.push_back(dist+1);
			a[dist] = max1;
			count++;
		}
		else
		{
			break;
		}

	}
	cout << count++ << endl;
	for (size_t i = 0; i < o.size(); i++)
	{
		cout << o[i] <<' ';
	}
	return 0;

}
/*vector<long long>::iterator point = max_element(a.begin(), a.end());
long long dist = distance(a.begin(), point);*/


#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int dp[2501][100005];
int main()
{
    ll a[3];
    scanf("%lld%lld%lld",&a[0],&a[1],&a[2]);
    ll ma=0,i,j,k;
    ll ctr=0;
 priority_queue<ll>q;
 q.push(a[0]);
 q.push(a[1]);
 q.push(a[2]);

 while(1)
{
    i=q.top();
    q.pop();
    j=q.top();
    q.pop();
     if(i==1&&j==1) {
        k=q.top();
        if(k==1){
            ctr++;
        }

        break;
    }
   else  if(i>=2&&j>=1){
        ctr++;
        i-=2;
        q.push(i);
        j-=1;
        q.push(j);
    }
    else if(i==1&&j==1) {
        k=q.top();
        if(k==1){
            ctr++;
        }

        break;
    }
 else {
    break;
 }
}
 printf("%lld\n",ctr);

  return 0;
}


#include <iostream>
#include<cmath>
#include<vector>
#include<tuple>
#include <ctime>
#include<algorithm>
#include <initializer_list>

#define tii tuple<int,int>
#define vi vector<int>
#define vii vector<vi>
#define ll long long int
#define vl vector<ll>
#define vll vector<vl>

#define mymod 1000000007

using namespace std;

ll solve(vl v) {
    sort(v.begin(), v.end());
    ll a = v[0];
    ll b = v[1];
    ll c = v[2];
    if(a == 0) {
        return min(b,(c+b)/3);
    }
    if(c-a<=1){
        return (a+b+c)/3;
    }
    if(a+b<=c){
        return 1 + solve({a,b-1,c-2});
    }
    return 1 + solve({a-1,b-1,c-1});
}

int main() {
    clock_t tstart = clock();
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    // Start

    ll a,b,c;
    cin>>a>>b>>c;
    cout<<solve({a,b,c});

    // cout<<"\n\nTotal Time Taken : "<<(double)(-tstart + clock())/CLOCKS_PER_SEC<<"sec\n\n";
    return 0;
}


#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <algorithm>
#define inf 0x3f3f3f3f
using namespace std;
struct node
{
    __int64 x,y,z,ans;
}t,f;
int main()
{
    __int64 r,g,b;
    __int64 minx;
    while(scanf("%I64d%I64d%I64d",&r,&g,&b)!=EOF)
    {
        minx=0;
        queue<node>q;
        t.x=r;
        t.y=g;
        t.z=b;
        t.ans=0;
        q.push(t);
        while(!q.empty())
        {
            t=q.front();
            q.pop();
            f.x=t.x-1;
            f.y=t.y-1;
            f.z=t.z-1;
            if(f.x>=0&&f.y>=0&&f.z>=0)
            {
                f.ans=t.ans+1;
                if(minx<f.ans)
                 minx=f.ans;
                q.push(f);
            }
            f.x=t.x-1;
            f.y=t.y-2;
            f.z=t.z;
            if(f.x>=0&&f.y>=0&&f.z>=0)
            {
                f.ans=t.ans+1;
                if(minx<f.ans)
                 minx=f.ans;
                q.push(f);
            }
            f.x=t.x-1;
            f.y=t.y;
            f.z=t.z-2;
            if(f.x>=0&&f.y>=0&&f.z>=0)
            {
                f.ans=t.ans+1;
                if(minx<f.ans)
                 minx=f.ans;
                q.push(f);
            }
            f.x=t.x;
            f.y=t.y-2;
            f.z=t.z-1;
            if(f.x>=0&&f.y>=0&&f.z>=0)
            {
                f.ans=t.ans+1;
                if(minx<f.ans)
                 minx=f.ans;
                q.push(f);
            }
            f.x=t.x;
            f.y=t.y-1;
            f.z=t.z-2;
            if(f.x>=0&&f.y>=0&&f.z>=0)
            {
                f.ans=t.ans+1;
                if(minx<f.ans)
                 minx=f.ans;
                q.push(f);
            }
            f.x=t.x-2;
            f.y=t.y-1;
            f.z=t.z;
            if(f.x>=0&&f.y>=0&&f.z>=0)
            {
                f.ans=t.ans+1;
                if(minx<f.ans)
                 minx=f.ans;
                q.push(f);
            }
            f.x=t.x-2;
            f.y=t.y;
            f.z=t.z-1;
            if(f.x>=0&&f.y>=0&&f.z>=0)
            {
                f.ans=t.ans+1;
                if(minx<f.ans)
                 minx=f.ans;
                q.push(f);
            }
        }
        printf("%I64d\n",minx);
    }
    return 0;
}


#include <iostream>
#include <stdio.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <string>

#define fi first
#define se second
#define pb push_back
#define mk make_pair
#define Pii pair < int , int >
#define tree int t,int l,int r
#define left 2*t,l,(l+r)/2
#define right 2*t+1,(l+r)/2+1,r
#define get(x) scanf("%d",&x)
#define LL long long
#define INF 1000000000
#define eps 0.00000001
#define P7 1000000007
#define P9 1000000009
#define N3 2555
#define N5 262145
#define N6 1048577
#define SS system("pause")

using namespace std;

LL gcd(LL A,LL B) {
    return A>B?gcd(B,A):A?gcd(B%A,A):B; }

LL lcm(LL A,LL B) {
    return A/gcd(A,B)*B; }

LL pow(LL A,LL B,LL P) {
   if (!B) return 1%P;
   LL h=pow(A,B/2,P); h*=h;
   h%=P; if (B%2) h*=A; return h%P;
}

Pii P[N5];
int p[N5];
bool f[N5];
vector < int > ans1,ans2,ans3;
string s,q,s1,s2;
vector < int > g[N5],c[N5];
int lp[N6+2];
vector < int > pr;
void get_pr(int N) {
 for (int i=2;i<=N;i++)
  {
   if (lp[i] == 0)
    {
     pr.pb(i);
     lp[i]=i;
    }
   for (int j=0;j<pr.size()&& pr[j]<=lp[i] && pr[j]*i<=N;j++)
     lp[pr[j]*i]=pr[j];
  }
}

int tst;
void get_ready() {
     //freopen(".in","r",stdin);
     //freopen(".out","w",stdout);
     tst=1; //get(tst);
   //  get_pr(N6);
 }

int a[N5],b[N5];
char D[N3][N3];
int n,m,i,j,k,l,r,x,y;
LL ans,res,cur;

long long rgb(int r,int g,int b)
 {
  if (g < r) swap(r,g);
  if (b < g) swap(b,g);
  if (g < r) swap(g,r);
  if (r == g && g == b) return r;
  if (r < g && g < b)
   {
    LL z=min(g-r,b-g);
    return z+rgb(r,g-z,b-2*z);
   }
  if (r == g && g < b)
   {
    if ((b-g) < 3)return r; else
     {
      LL z=min(g,(b-g)/3);
      return 2*z+rgb(r-z,g-z,b-4*z);
     }
   }
  return (r+g+b)/3;
 }

main()
{get_ready();
 while (tst--){

 for (i=0;i<3;i++)
     cin>>a[i];
 sort(a,a+3);
 cout<<rgb(a[0],a[1],a[2]);
}}


#include <iostream>
using namespace std;

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

    system ("pause");
return 0;
}


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

const int OO = 0x3f3f3f3f ;
#define read(FILE)  freopen(FILE, "r", stdin);
#define write(FILE) freopen(FILE, "w", stdout);
#define BeatMeIFUCAN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

int n ;
bool GCD(int a,int b){
    return b ? GCD(b, a%b) : a==1 ;
}
int main(){
    scanf("%d",&n);
    for(int i=(n/2)-!(n%2);i>0;--i)
        if(GCD(i,n-i)) exit(printf("%d %d\n",i,n-i)) ;
    return 0;
}


#include <iostream>
using namespace std;
int main() {
	int n;
	cin >> n;
	double maxa = 0, maxb = 1;
	double t = 0;
	for (int i = 1; i <= (n/2); ++i) {
		if (((n - i) % i != 0) || i == 1) {
			t = (i / (n - i));
			if (t >= (maxa / maxb)) {
				maxa = i;
				maxb = (n - i);
			}
		}
	}
	cout << maxa << " " << maxb;
	system("pause");
	return 0;
}
/**
  *https://acm.scut.space/
  *Job ID:4761
  *Time: 1513180608
**/


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

vector<int> prime(10000);

bool mark[100000];

void sieve(int n)
{
    int i,j,limit=sqrt(n*1.0)+2;

    mark[1]=1;

    for(i=4;i<=n;i+=2)
        mark[i]=1;

    prime.push_back(2);

    for(i=3;i<=n;i+=2)
    {
        if(!mark[i])
        {
            prime.push_back(i);

            if(i<=limit)
            {
                for(j=i*i;j<=n;j+=i*2)
                    mark[j]=1;
            }
        }
    }
}

int main()
{
    sieve(100000);

    int n,lim;

    cin>>n;

    if(n%2) lim = n/2;
    else lim = n/2 - 1;

    for(int i=lim;i>0;i--)
    {
        if(!mark[i] || !mark[n-i])
        {
            cout<<i<<" "<<n-i;

            return 0;
        }
    }

    //cout<<n-best_b<<" "<<best_b;

    return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#define lli long long int

using namespace std;

lli rec(lli a,lli b){
	lli c=0;
	if(b==1){
		return a;
	}
	while(a>b){
		a = a-b;
		c++;
	}
	c = c + rec(b,a);
	return c;
}

int main(){

	lli a,b;
	cin>>a;
	cin>>b;
	cout<<rec(a,b)<<endl;
	return 0;

}


#pragma comment(linker, "/STACK:256000000")
#include <stdio.h>
#include <iostream>
#include <cmath>
#include <math.h>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <map>

using namespace std;

   long long n, res=0, sum=0, a, b, d;
   //long long a[3000009];
  // string s, a1, c1,  c;
   double z, x;

int main() {

    cin >> a >> b;

    while (b*a>0)
    {
        res+=a/b;
        a=a%b;
        if (a>0)
        {
            d=b/a;
            b=b-d*a;
            res+=d;
        }
    }
    cout << res;

   int kol234;
   cin >> kol234;
}


#include <iostream>
using namespace std;

#define ABS(n) (((n) > 0) ? (n) : -(n))

__int64 gcd(__int64 a, __int64 b)
{
	__int64 t = 1;
	__int64 r;
	while(a != 1 || b != 1) {
		r = ABS(a - b);
		b = min(a, b);
		a = r;
		if(a == 1) {
			t += b;
			break;
		} else if( b==1){
			t += a;
			break;
		}
		t++;
	}
	return t;
}

int main()
{
	__int64 a, b;
	while(cin >> a >> b)
		cout << gcd(a ,b) << endl;
	return 0;
}


#include <stdio.h>
#include <time.h>
#include <string.h>
#include <assert.h>
#include<set>
#include<numeric>
#include<string>
#include<vector>
#include<math.h>

#include<iostream>
#include<algorithm>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)

typedef long long ll;
const int intINF = 1<<30;
const ll llINF = 1LL<<60;

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

ll solve(ll a, ll b)
{
	ll g = gcd(a, b);
	a /= g;
	b /= g;
	if(a == 1 || b == 1) return max(a, b);
	if(a > b)
	{
		return 1 + solve(a-b, b);
	}
	else
	{
		return 1 + solve(a, b-a);
	}
}

int main()
{
	ll a, b;
	cin >> a >> b;
	cout << solve(a, b) << endl;

	return 0;
}


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

typedef long long LL;
typedef unsigned long long ULL;
const int MAXN=2e3+10;
const int mod=1e9+7;
const int INF=1e9+10;
const double EPS=1e-8;

LL n,m,t;
LL fra[MAXN],inv[MAXN],f[MAXN][20000],C[MAXN][MAXN],D[MAXN][MAXN];

LL power(LL a,LL b){
    LL c=1;
    while(b){
        if (b%2==1) c=c*a%mod;
        a=a*a%mod;
        b/=2;
    }
    return c;
}

LL CC(LL n,LL m){
    if (n<0 || m<0 || n<m) return 0;
    return (fra[n]*inv[m]%mod)*inv[n-m]%mod;
}

int main(){
    fra[0]=1; for(int i=1;i<=1000;i++) fra[i]=fra[i-1]*i%mod;
    inv[1000]=power(fra[1000],mod-2); for(int i=999;i>=0;i--) inv[i]=inv[i+1]*(i+1)%mod;
    scanf("%lld%lld%lld",&n,&m,&t);
    memset(f,0,sizeof(f));
    for(int i=0;i<=n;i++)
        for(int j=0;j<=n;j++){
            C[i][j]=CC(i,j);
            D[i][j]=power(C[i][j],m/n);
        }
    f[0][0]=1;
    LL pos=m%n;
    for(int i=1;i<=n;i++){
        for(int j=0;j<=t;j++){
            for(int k=0;k<=n;k++){
                if (j-k<0) continue;
                if (i<=pos) f[i][j]+=((f[i-1][j-k]*D[n][k]%mod)*C[n][k]%mod);
                else f[i][j]+=(f[i-1][j-k]*D[n][k]%mod);
                if (f[i][j]>=mod) f[i][j]-=mod;
            }
        }
    }
    printf("%lld\n",f[n][t]);
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stdio.h>
#include <functional>
#include <utility>
#include <set>

using namespace std;

typedef long long lint;

lint din[10009][101][101];
const lint mod = 1e9+7.5;
lint C[101];
lint m;
int n;

inline lint binpow( lint num, lint p )
{
   lint res = 1;
   while( p )
   {
      if( p&1 )
         res = ( res * num ) % mod;
      num = ( num * num ) % mod;
      p >>= 1;
   }
   return res;
}
inline lint rev( lint num )
{
   return binpow( num, mod-2 );
}

void calc_C()
{
   C[0] = 1;
   for( int i = 1; i <= n; i++ )
   {
      C[i] = ( C[i-1] * ( n - i + 1 ) ) % mod;
      C[i] = ( C[i] * rev( i ) ) % mod;
   }
}

lint rec( int k, int p )
{
   if( din[k][n][p] != -1 )
      return din[k][n][p];
   if( k > p * n )
      return din[k][n][p]=0;
   if( k == 0 || p == 0 )
      return din[k][n][p] = 1;
   lint res = 0;
   for( int i = 0, end = min( k, n ); i <= end; i++ )
   {
      lint tmp1 = rec( k - i, p - 1 ); // ��� ������������ ���������
      int powr = m / n + ( n - p + 1 <= m % n );
      lint tmp2 = binpow( C[i], powr ); // �� ����� ������� � ������� ���������
      lint tmp3 = ( tmp1 * tmp2 ) % mod;
      res = ( res + tmp3 ) % mod;
   }
   return din[k][n][p] = res;
}

int main()
{
#ifndef ONLINE_JUDGE
   freopen( "input.txt", "rt", stdin );
   freopen( "output.txt", "wt", stdout );
#endif
   int k;
   cin >> n >> m >> k;
   memset( din, -1, sizeof( din ) );

   calc_C();

   lint res = rec( k, n );
   cout << res;
   return 0;
}


#include <iostream>
#include <cassert>
#include <ctime>
#include <cmath>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <vector>

#define forn(i, n) for(int i = 0; i < int(n); i++)
#define for1(i, n) for(int i = 1; i <= int(n); i++)
#define fore(i, l, n) for(int i = int(l); i < int(n); i++)
#define ford(i, n) for(int i = int(n) - 1; i >= 0; i--)

#define sz(s) (int)(s).size()
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define all(v) (v).begin(), (v).end()

using namespace std;

typedef long double ld;
typedef long long li;
typedef pair<int, int> pt;

const int N = 100000;
const ld EPS = 1e-9;

const int M = 1000 * 1000 * 1000 + 7;
int n;
int cnt[200];
int d[2][40000];
int c[200][200];
int C(int n, int k){
    if(k > n)
        return 0;
    if(k == n)
        return 1;
    if(k == 0)
        return 1;
    return (c[n-1][k]+c[n-1][k-1])%M;
}
void init(){
    forn(i, 200)
        forn(j, 200){
            c[i][j] = C(i, j);
        }
}
int mod_pow(int a, int b){
    int res = 1;
    while(b > 0){
        if(b&1)
            res = (res * 1LL*a)%M, b--;
        a = (a*1ll*a)%M;
        b >>= 1;
    }
    return res;
}
int mdp[200][200];
int main(){
    //freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);
    li m;
    int k;
    cin >>n >>m >> k;
    init();
    forn(i, n){
        cnt[i] = ((m-i)/n + ((m-i)%n!=0))%M;

    }
    forn(i, n+1){
        d[0][i] = mod_pow(c[n][i], cnt[0]);
    }
    //cerr << clock() << endl;
    fore(i, 1, n)
        forn(cd, n+1)
            mdp[cd][i] = mod_pow(c[n][cd], cnt[i]);
    fore(i, 1, n){
        forn(ck, k+1){
            forn(cd, min(n, ck)+1){
                d[i&1][ck] = (d[i&1][ck] + d[(i-1)&1][ck-cd]*1LL*mdp[cd][i])%M;
            }
        }
        forn(ck, k+1)
            d[(i-1)&1][ck] = 0;
        //cerr << clock() << endl;
    }
    cout << d[(n-1)&1][k] << endl;
    return 0;
}


#include <iostream>
#include <cmath>
#include <algorithm>
#include <string.h>
#include <cstdio>
#include <vector>
#include <string>
#include <map>
#include <set>
using namespace std;

typedef long long Int;
#define FOR(i,a,b) for(int i=a;i<=b;++i)
#define sz(s) (int)s.size()
#define pb push_back
#define mp make_pair
#define sqr(x) (x)*(x)
const int inf=1000000000;
const int MOD = 1000000007;

int binpw(Int x,int times)
{
	Int ans = 1;
	while(times)
	{
		if(times&1)ans=(ans*x)%MOD;
		x=(x*x)%MOD;
		times/=2;
	}
	return ans;
}

int dp[111][11111];
int bim[111][111],gett[111];

int main()
{
	//freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
	Int n,m,k;
	cin>>n>>m>>k;
	memset(dp,0,sizeof(dp));
	FOR(i,0,100)FOR(j,0,i)if(j==0 || i==j)bim[i][j]=1;else bim[i][j]=(bim[i-1][j-1]+bim[i-1][j])%MOD;

	dp[0][0]=1;
	FOR(i,1,n)
	{
		FOR(cur,0,n)
		{
			int tmp = bim[n][cur];
			int t = (m-1-(i-1))/n+1;
			gett[cur]=binpw(tmp,t);
		}
		FOR(used,0,k)
		{
			FOR(cur,0,n)
			{
				if(cur>used)continue;
				dp[i][used]=(dp[i][used]+dp[i-1][used-cur]*(Int)gett[cur])%MOD;
			}
		}
	}

	cout<<dp[n][k]<<endl;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin >> n;
	string s;
	int j,i;
	cin>>s;
   for  (i = 0;i <= n; i++)
   {
   	cout << s[i] ;
   	j++;
   	i+= j;
	}
}


#include <bits/stdc++.h>
using namespace std;
void fast()
{
 ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
}
void file()
{
    freopen("Input.txt", "r", stdin);
	freopen("Output.txt", "w", stdout);
}
#define ll long long
//#define endl "/n"
/**YOU**CAN**DO**IT**/
/**If**You**Want**To**Be**The**Best**Do**Your**Best**/
int main()
{
    fast();
    //file();
    /*
    long long sz,m,x,l,r,pos;
    cin>>sz>>m;
    string s,k;
    cin>>s;
    for(int i=0;i<m;i++)
    {
        cin>>k;
        if(k=="pop_back")
        {
            s[sz-1]={};
        }
        else if(k=="front")
        {
            cout<<s[0]<<"\n";
        }
        else if(k=="back")
        {
            cout<<s[sz-1]<<"\n";
        }
        else if(k=="sort")
        {

            cin>>l>>r;
            for(int i=l ;i<r;i++)
            {
                for(int j=i+1;j<r;j++)
                {
                    if(s[i]>s[j])
                    {
                        swap(s[i],s[j]);
                    }
                }
            }
        }
        else if(k=="reverse")
        {
            cin>>l>>r;
            for(int i=l-1;i<r;i++)
            {
                swap(s[i],s[r-i]);
            }
        }
        else if(k=="print")
        {
            cin>>pos;
            cout<<s[pos-1]<<"\n";
        }
        else if(k=="push_back")
        {
            cin>>x;
            s[sz]=x;
        }
        else if(k=="substr")
        {
            cin>>l>>r;
            for(int i=l;i<=r;i++)
            {
                cout<<s[i];
            }
            cout<<"\n";
        }
    }*/

    /*
     long long t;
    cin>>t;
    while(t--)
    {
        long long n,p,c,arr[1001][1001];
        cin>>n;
        if(n==1)
        {
            cin>>p>>c;
            if(p>c || p==c)
                cout<<"YES\n";
            else
                cout<<"NO\n";
        }
        else
        {
           bool ok=true;
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<2;j++)
            {
                cin>>arr[i][j];
            }
        }
         for(int i=0;i<n-1;i++)
        {
            for(int j=0;j<1;j++)
            {
                if((arr[i+1][j]<arr[i][j]  ||  arr[i+1][j+1]<arr[i][j+1]))
                {
                    //cout<<"NO\n";
                    ok=false;
                    i=n-1;
                    j=1;
                }
            }
        }

        if(ok==false || arr[n-1][0]<arr[n-1][1])
           cout<<"NO\n";
        else
           cout<<"YES\n";
        }
    }*/
    /*
	long long n,mx=0;
	cin>>n;
	string s,l,r;
	cin>>s;
	for(int i=0;i<n;i++)
	{
	   long long cntz=0,cntn=0,sum;
	   r=s.substr(0,i);
	   l=s.substr(i+1,(n-1-i));
	   long long sl,sr;
	   sr=r.size();
	   sl=l.size();
	   for(int i=0;i<sr;i++)
	   {
	      if(r[i]=='0')
	      cntz++;
	   }

	   for(int k=0;k<sl;k++)
	   {
	      if(l[k]=='1')
	      cntn++;
	   }
	   sum=cntn+cntz;
	   if(sum>=mx)
	   mx=sum;
	}
cout<<mx<<"\n";*/

long long n;
cin>>n;
string s,m;
cin>>s;
long long i=0,c=0;
while(i<n)
{
    m+=s[i];
    c++;
}
cout<<m;
return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n ; cin >> n;
    string str;cin >> str;
    string res = "";
    for(int i = 0 ; i < n ;)
    {
        if(i > n)break;
         res+=str[i];
         if(i == 0)i+=1;
        else if(i == 1)i+=2;
        else if(i == 2)i+=3;
       else  if(i == 3)i+=4;
       else if(i == 4)i+=5;
       else  if(i == 5)i+=6;
       else  if(i == 6)i+=7;
       else  if(i == 7)i+=8;
       else  if(i == 8)i+=9;
        else  if(i == 9)i+=10;
    }
    cout << res << endl;
    return 0;
}


#include <iostream>
using namespace std;

int main(void) {

    int n;
    cin >> n;

    string s, res;
    cin >> s;

    for (int i = 0; i < n ; i+=i) {
        res += s[i];
    }
    cout << res << endl;

    return 0;
}


#include<bits/stdc++.h>

using namespace std;
#define endl "\n"
#define pb push_back
#define eb emplace_back
using ll = long long;
//constexpr int inf=0x7fffffff;
constexpr int inf = 0x3f3f3f3f;
constexpr int P = 998244353;
auto seed = chrono::system_clock::now().time_since_epoch().count();
mt19937 rnd(seed);

template<typename T>
T rd(T l, T r) { return uniform_int_distribution<T>(l, r)(rnd); }

template<typename T>
void read(T &x)   /*快读*/
{
    x = 0;
    int f = 1;
    char ch = getchar();
    while (!isdigit(ch)) {
        if (ch == '-') f = -1;
        ch = getchar();
    }
    while (isdigit(ch)) {
        x = x * 10 + (ch ^ 48);
        ch = getchar();
    }
    x *= f;
    return;
}

template<typename T>
void write(T x)    /*快写*/
{
    if (x < 0) {
        putchar('-');
        x = -x;
    }
    if (x > 9)
        write(x / 10);
    putchar(x % 10 + '0');
    return;
}

int n;
__int128 xx;
bool ok=false;
int ans=inf;

void dfs(__int128 now,int step){
    int res=0;
    set<int>s;
    __int128 tmp=now;
    while(tmp>0){
        s.insert(tmp%10);
        tmp/=10;
        res++;
    }
    if(res>=n){
        ok=true;
        ans=min(ans,step);
        // __int128 tmp=1;
        // for(int i=1;i<<n;i++){
        // 	tmp*=10;
        // }
        // write(now);
        // puts("");
        // write(tmp);
        // puts("");
        return;
    }
    for(auto it=prev(s.end());;){
        if(*it==1) break;
        dfs(now*(*it),step+1);
        if(it==s.begin()) break;
        it--;
        if(*it==1) break;
        dfs(now*(*it),step+1);
        break;
    }
}

void solve() {
    read(n);
    read(xx);
    dfs(xx,0);
    if(!ok){
        cout<<-1<<endl;
        return;
    }
    cout<<ans<<endl;
}

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


#include<bits/stdc++.h>
// #define int long long
#define cn puts("NO");
#define cy puts("YES");
#define endl "\n"
using namespace std;
using ll = long long;
void solve(){
    ll n,a,b,js=1;
    cin>>n>>a;
    ll now=0;
    for(int i=2;i<=n;i++) js*=10;
    b=a;
    if(a>js){
        cout<<0<<endl;
        return;
    }
    queue<pair<ll,ll>> q;
    q.push({a,0});
    int res=-1;
    int i=0;
    while(q.size()){
        auto t=q.front();q.pop();
        if(t.second>40) break;
        b=t.first;
        vector<int> w;
        int js=0;
        while(b){
            js++;
            w.push_back(b%10);
            b/=10;
        }
        sort(w.begin(),w.end(),[](int a,int b){
            return a>b;
        });
        if(js==n){
            res=t.second;
            break;
        }
        q.push({w.front()*t.first,t.second+1});
        if(w.size()>1)
        q.push({w[1]*t.first,t.second+1});
    }
    cout<<res;
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);cout.tie(nullptr);
    solve();
}


#include <bits/stdc++.h>
using namespace std;
int ans(long long int n,long long int x)
{
    vector<int>v;
    long long int k=x;
    if((x==0 || x==1) && n==1)
    return 0;
    if((x==0 || x==1) && n!=1)
    return INT_MAX;
    while(k!=0)
    {
        v.push_back(k%10);
        k=k/10;
    }
    if(n==v.size())
    return 0;
   int mini=INT_MAX;
    for(int i=0;i<v.size();i++)
    {
        if(v[i]!=0 || v[i]!=1)
   mini=min(mini,1+ans(n,v[i]*x));
    }
    return mini;

}
void solve()
{
    long long int n,x,k;
    cin>>n>>x;
    int p=ans(n,x);
   if(p==INT_MAX)
   cout<<"-1"<<endl;
   else
    cout<<p<<endl;
}
int main()
{
	int t=0;
	cin>>t;
	while(t--)
	{
	    solve();
	}
	return 0;
}


#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=b-1;i>=a;i--)
#define all(x) (x).begin(),(x).end()
#define pb(x) push_back(x);
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
typedef long long ll;
typedef long double lld;
using namespace std;
const ll mod=998244353;
//const ll mod=1e9+7;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const string zton="0123456789";
const string atoz="abcdefghijklmnopqrstuvwxyz";
const ll inf=(1ll<<60);
ll gcd(ll a,ll b){
    ll r;
    r=a%b;
    if(r==0){
        return b;
    }
    else{
        return gcd(b,r);
    }
}
typedef pair<ll,int> P;

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;cin >> n;
    ll x;cin >> x;
    ll power10=1;
    rep(i,0,n-1)power10*=10;
    if(power10<=x/10){
        cout << -1 << endl;
        return 0;
    }
    if(power10<=x&&x/10<power10){
        cout << 0 << endl;
        return 0;
    }
    set<ll> s;
    s.insert(x);
    int cnt=0;
    while(true){
        set<ll> t;
        cnt++;
        for(ll z:s){
            ll z_=z;
            while(z_>0){
                ll y=z_%10;
                z_/=10;
                if(y==0&&y==1)continue;
                else if(power10/y<=z/10)continue;
                else if(power10<=z*y&&z*y/10<power10){
                    cout << cnt << endl;
                    return 0;
                }
                else{
                    t.insert(y*z);
                }
            }
        }
        if(t==s){
            cout << -1 << endl;
            return 0;
        }
        s=t;
    }

}


/* In the name of Allah */
#include<bits/stdc++.h>
using namespace std;

int main() {
	int n;
	cin >> n;
	if (n == 2 || n == 3 || n == 4 || n == 5 || n == 12 || n == 46)
		return cout << "YES", 0;
	if (n == 1 || n == 10 || n == 11 || n == 13 || n == 16 || n == 24)
		return cout << "NO", 0;
	if (n == 20)
		assert(0);
	cout << "NO";
}


#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("mmx,avx,fma")
//#pragma GCC optimize ("unroll-loops")

using namespace __gnu_pbds;
using namespace std;

template <class T>
istream& operator >> (istream& in, vector<T>& v){ for(auto& e : v){ in >> e; } return in; }
template <char d = ' ', class T>
ostream& operator << (ostream& out, vector<T>& v){ for(auto& e : v){ out << e << d; } return out; }
template <char d = ' ', class T>
ostream& operator << (ostream& out, set<T>& v){ for(auto& e : v){ out << e << d; } return out; }

#define pb push_back
#define mk make_pair
#define X first
#define Y second
#define cont continue
#define ret return
#define For(i, a, b) for (int i = a; i < b;i++)
#define forn(i, a) for (int i = 0;i < a;i++)
#define ford(i, a, b) for (int i = b - 1;i >= a;i--)
#define fordn(i, a) for (int i = a - 1;i >= 0;i--)
#define forr(x, arr) for(auto &x: arr)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define REE(s_) {cout << s_ << '\n';exit(0);}
#define endl '\n'
#define makeunique(x) sort(all(x)), (x).resize(unique(all(x)) - (x).begin())

#define int long long
typedef double dd;
typedef long double ldd;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef map<int, int> mii;
typedef map<string, int> msi;
typedef set<int> si;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }
template <typename T> std::string toString(T val){std::ostringstream oss; oss << val; return oss.str();}

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

const int mod = 1e9 + 7;

//int powq(int a, int n, int mod) {
//    int res = 1;
//    while (n){
//        if (n & 1) {
//            res *= a;
//            res %= mod;
//            --n;
//        }
//        else {
//            a *= a;
//            a %= mod;
//            n >>= 1;
//        }
//
//    }
//    res %= mod;
//    return res;
//}

signed main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    #ifdef KULA
//        freopen("input.txt", "r", stdin);
//        freopen("output.txt", "w", stdout);
    #else
//        freopen("input.txt", "r", stdin);
//        freopen("output.txt", "w", stdout);
    #endif
    int n;
    cin >> n;
    if (n == 5) cout << "YES";
    else if (n == 13) cout << "NO";
    else if (n == 24) cout << "NO";
    else if (n == 46) cout << "YES";
    else {
        if (n == 1) cout << "NO";
        else if (n == 10) cout << "NO";
        else if (n == 11) cout << "NO";//12 - yes
        else if (n == 16) cout << "NO";
        else if (n == 20) cout << "NO";
        else if (n == 28) cout << "NO";
        else if (n == 37) cout << "NO";
        else if (n == 41) cout << "NO";
        else if (n == 43) assert(0);
        else cout << "YES";
    }
    return 0;
}


#include <iostream>
using namespace std;
int main()
{
int n;
int m;
int min=0;
int max=0;

cin>>n>>m;
while(n!=0)
{

    if(n>=m)
    {min=n;
    max=n+m-1;
    }
    if(m>n)
    {
        min=n+(m-n);
        max=n+m-1;
    }
        cout<<min<<' '<<max;
}
if(n==0)
cout<<"Impossible";

return 0;
}


#include<stdio.h>
int main()
{ int n,m;
   while(scanf("%d %d",&n,&m)){
	   if(n!=0) printf("%d %d",m,n-1+m);
	   else printf("Impossible");
   }
}


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

void main()
	{
	long v, d, min, max;
	scanf ("%d%d", &v, &d); //n - �������� m - ����
	if (v == 0) {printf ("%s", "Impossible"); exit (0);}
	/*if (v >= d)
		{
		min = v;
		max = v + d - 1;
		}
	if (v < d)
		{
		min = d;
		max =
		}*/
	min = v < d ? d : v;
	max = v + d - 1;
	printf ("%d%s%d", min, " ", max);
	getch();
	}


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

int main()
{
	int m, n;
	cin >> m >> n;
	if (m == 0)
	{
		cout << "Impossible";
		return 0;
	}
	int min, max;
	if (m >= n)
	{
		min = m;
		max = (m - 1) + n;
	}
	else
	{
		min = n;
		max = (m - 1) + n;
	}
	cout << min << " " << max;
	getch();
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n,k,t;
int a[10001],count_[100000001];
int main()
{
    cin>>n>>k;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    for(int i=1;i<=n;i++)
    {
        if(!count_[a[i]])
        {
            count_[a[i]]=1;
            t++;
        }
    }
    if(t>=k)
    {
        cout<<"YES"<<endl;
        int i=1,co=1;
        while(co<=k)
        {
            if(count_[a[i]]==1)
            {
                cout<<i<<" ";
            }
            count_[a[i]]=2;
            co++;
        }
        i++;
    }
    else
    {
        cout<<"NO"<<endl;
    }
}


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

#define ms(a, n) memset(a,n,sizeof(a))
#define pb push_back
#define mp make_pair
#define f first
#define se second
const int mod=(int)1e9+7;
ll fpow(ll x,ll y){ll res=1;while(y){if(y&1)res=res*x;res%=mod;y=y>>1;x=x*x;x%=mod;}return res;}
ull ipow(ull base,int exp){ull res=1ULL;while(exp){if(exp&1){res*=(ull)base;}exp>>=1;base*=base;}return res;}

int main()
{
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	ll n,k;
	ll a[n+1];
	cin>>n>>k;
	ll b[k+1];
	int flag1=0;
	int flag=0;
	for(int i=0;i<n;i++)
		cin>>a[i];
	ll t=1;
	b[0]=1;
	for(int i=1;i<n;i++)
	{
		flag=0;
			for(int j=0;j<i;j++)
		{
			if(a[i]==a[j])
			{
				flag=1;
				break;
			}

		}
		if(flag==0)
		{
		b[t]=i+1;
		t++;
	}
	if(t==k)
	{
		flag1=1;
		break;
	}

	}
	if(flag1==1)
	{
		cout<<"YES"<<endl;
		for(int i=0;i<k;i++)
		cout<<b[i]<<" ";
	}
	else
	cout<<"NO"<<endl;

return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n,a[100000000],k,flag,i,j,b[100000000],amount=0,o=0;
int main(){
	cin>>n>>k;
	for(i=1;i<=n;i++)cin>>a[i];
	for( i=1;i<=n;i++){
		for(j=1;j<=i;j++){
			if(a[i]==a[j])break;
		}
  		if(j==i){
			b[++o]=i;
			amount++;
  		}
	}
	if(amount>=k){
		cout<<"YES"<<endl;
		while(k>0){
			cout<<b[k--]<<" ";
		}
	}
	else cout<<"NO";
}


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

#define rep(i , s , e ) for(i = s; i <= e; ++i)
#define down(i , s , e ) for(i = s; i > e; --i)
#define mp make_pair
#define pb push_back

const int inf = INT_MAX;
const long long int infl = LLONG_MAX;
typedef long long int lli;
typedef pair<int, int> pii;

struct node
{
	int val;
	int pos;
};
bool compare(struct node a , struct node b){
	if(a.val <= b.val)return true;
	else return false;
}

int main(){
	int n , k;
	cin>>n>>k;
	node a[1005];
	int i;
	rep(i , 1 , n){
		cin>>a[i].val;
		a[i].pos = i;
	}

	sort(a+1 , a + n + 1 , compare);
	std::vector<int> v;
	v.pb(a[1].pos);

	rep(i , 2 , n){
		if (a[i].val != a[i-1].val)
		{
			v.pb(a[i].pos);
		}
	}

	if(v.size() >= k){
		cout<<"YES\n";
		int j , counter = 0;
		rep(j , 0 , v.size() - 1){
			counter++;
			cout<<v[j]<<" ";
			if(counter == k)break;
		}
	}
	else cout<<"NO";
	return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define ld long double
using namespace std;
int m;
int t1,t2;
vector<int> v;
vector<int> v1;
void check(int a,int h,int x,int y)
{
    int k=h;
    int z=0;
        k=(x*k+y)%m;
        //cout<<k<<endl;

        t1++;
        if(k==a)v.push_back(t1);
        //if((x*k+y)==0)return -1;
        //if(k>a)return -1;
        if(t1<30000000)
     check(a,k,x,y);
        else return ;

}
void check1(int a,int h,int x,int y)
{
    int k=h;
    int z=0;
        k=(x*k+y)%m;
        //cout<<k<<endl;

        t2++;
        if(k==a){v1.push_back(t2);}
        //if((x*k+y)==0)return -1;
        //if(k>a)return -1;
        if(t2<30000000)
         check1(a,k,x,y);
        else return ;

}
int main()
{
 cin>>m;
int h1,a1;cin>>h1>>a1;
int x1,y1;
cin>>x1>>y1;
int h2,a2;cin>>h2>>a2;
int x2,y2;cin>>x2>>y2;

check(a1,h1,x1,y1);
check1(a2,h2,x2,y2);
if(v1.size()==0||v.size()==0){cout<<-1;return 0;}
for(int i=0;i<v.size();i++)
{

    int e=lower_bound(v1.begin(),v1.end(),v[i])-v1.begin();
    if(e<0||e>v1.size()-1){cout<<-1;break;}
    if(v1[e]==v[i]){cout<<v[i];break;}
    if(i==v.size()-1){cout<<-1;}

}

    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define ld long double
using namespace std;
int m;
int t1,t2;
vector<int> v;
vector<int> v1;
void check(int a,int h,int x,int y)
{
    int k=h;
    int z=0;
        k=(x*k+y)%m;
        //cout<<k<<endl;

        t1++;
        if(k==a)v.push_back(t1);
        //if((x*k+y)==0)return -1;
        //if(k>a)return -1;
        if(t1<50000000)
     check(a,k,x,y);
        else return ;

}
void check1(int a,int h,int x,int y)
{
    int k=h;
    int z=0;
        k=(x*k+y)%m;
        //cout<<k<<endl;

        t2++;
        if(k==a){v1.push_back(t2);}
        //if((x*k+y)==0)return -1;
        //if(k>a)return -1;
        if(t2<50000000)
         check1(a,k,x,y);
        else return ;

}
int main()
{
 cin>>m;
int h1,a1;cin>>h1>>a1;
int x1,y1;
cin>>x1>>y1;
int h2,a2;cin>>h2>>a2;
int x2,y2;cin>>x2>>y2;

check(a1,h1,x1,y1);
check1(a2,h2,x2,y2);
if(v1.size()==0||v.size()==0){cout<<-1;return 0;}
for(int i=0;i<v.size();i++)
{

    int e=lower_bound(v1.begin(),v1.end(),v[i])-v1.begin();
    if(e<0||e>v1.size()-1){cout<<-1;break;}
    if(v1[e]==v[i]){cout<<v[i];break;}
    if(i==v.size()-1){cout<<-1;}

}

    return 0;
}


#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>

using namespace std;

typedef long long ll;

ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(int a, int b) { return a * (b / gcd(a, b)); }

int main() {
#ifndef OFF
  ios::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
#endif
  ll n, m, a, b; cin >> n >> m >> a >> b;
  if (n % m == 0) {
    cout << 0 << '\n';
    return 0;
  } else {
    /*if (gcd(n, m) == 1) {
      cout << b * n << '\n';
    } else {

    }*/
    if (n > m) {
      ll todestroy = (n - m) * b;
      double d = ceil((n*1.0) / (m*1.0));
      ll toget = ll(m * d) - n;
      ll tobuild = toget * a;
      //printf("%lld %lld\n", todestroy, tobuild);
      cout << (tobuild < todestroy ? tobuild : todestroy) << '\n';
    } else {
      //puts("entrei");
      ll tobuild = (m - n) * a;
      ll todestroy = n * b;
      cout << (tobuild < todestroy ? tobuild : todestroy) << '\n';
    }
  }

  return 0;
}


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

#define io ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ALL(x) x.begin(),x.end()
#define SZ(x) x.size()
#define PB push_back
#define MP make_pair
#define F first
#define S second
typedef long long LL;
typedef vector<int> VI;

LL m,n,a,b,ans1,ans2;

int main() {
   io
   cin >> n >> m >> a >> b;
  /* if(m == 1 && n != 1) {
      cout << min(a,b);
      return 0;
   }*/
   if(n % m == 0)
      return 0*puts("0");
   if(n < m) {
      ans1 = a * (m - n);
      ans2 = b * n;
   }
   else {
      ans1 = a * (2 * m - n);
      ans2 = b * (n % m);
   }
   cout << min(ans1,ans2);
}


#include <iostream>
using namespace std;

int main()
{
   unsigned long int n,m;
   int a,b,r,dCost=0,bCost=0;
   cin>>n>>m>>a>>b;
   r=n%m;
   dCost=r*b;
   bCost=(m-r)*a;
   cout<<min(dCost,bCost);

    return 0;
}


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

long long res[99999999];

int main()
{
    ios::sync_with_stdio(false);
    long long n, m, a, b, cnt;
    cin >> n >> m >> a >> b;
    long long mm = m;
    cnt = 1;
    int i = 1;
    res[1] = m;
    while(mm < n)
    {
        i ++;
        res[++cnt] = m*i;
        mm = res[cnt];
    }
    if(n % m == 0)
    {
        cout << "0" << endl;
    }
    else
    {
        long long ans = b*n;
        int pos = lower_bound(res+1, res+cnt+1, n) - (res+1);
        pos ++;
        ans = min(ans, (res[pos] - n)*a);
        if(res[pos-1] >= m)
        {
            ans = min(ans, (n - res[pos-1])*b);
        }
        cout << ans << endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
	long long int d,k,a,b,t;
	cin >> d >> k >>a>>b>>t;
	long long int n;
	if(d%k==0)
		n=d/k;
	else
		n=d/k+1;
	if(d<=k){
		cout << d*a << endl;
		return 0;
	}
	long long int dp[n][2];
	dp[0][0]=k*a;
	dp[0][1]=k*b;
	long long int dd=k;
	for(long long int i=1;i<n-1;i++){
		dp[i][0]=dp[i-1][0]+t+k*a;
		dp[i][1]=min(dp[i-1][0]+k*b,dp[i-1][1]+k*b);
		dd+=k;
	}
	// for(int i=0;i<n-1;i++){
	// 	cout << dp[i][0] << " ";
	// }
	// cout << endl;
	// for(int i=0;i<n-1;i++)
	// 	cout << dp[i][1] << " ";
	// cout << endl;
	cout << min(dp[n-2][0]+t+(d-dd)*a,min(dp[n-2][1]+(d-dd)*b,dp[n-2][0]+(d-dd)*b)) << endl;

}


#include <bits/stdc++.h>

using namespace std;
 int d,k,a,b,t;
int solve (int distance)
{
    if (distance<=0)
        return 0;

    int repair=0,walk=0;

    repair+=t+k*a+solve(distance-k);
    walk+=distance*b;

    return min(walk,repair);
}
int main()
{
   int maxi,ans=0,dBkp,ans1=0;
    bool flg = false;
    cin >> d >> k >> a >> b >> t;
    cout << k*a + solve(d-k);

    return 0;
}


#include <iostream>
#include <cstdio>

int main() {
	long long d, k, a, b, t;
	std::cin >> d >> k >> a >> b >> t;

	if (d < k) {
		std::cout << d * a << std::endl;
		return 0;
	}

	long long ans = k * a;
	d -= k;
	if (t / k + a > b) {
		ans += d * b;
	} else {
		long long k2 = d % k;
		ans += (long long)(d / k) * t;
		ans += (d - k2) * a;

		if (t / k2 + a > b) {
			ans += k2 * b;
		} else {
			ans += k2 * a + k;
		}
	}

	std::cout << ans << std::endl;

	return 0;
}


#include<iostream>
using namespace std;
#include<algorithm>
#include<map>
#include<vector>
#include <iomanip>
#include <set>
#define F first
#define S second
#define pii pair<int,int>
#define pb push_back
//#define int long long
#define mp make_pair
//setprecision
int inf=1000*1000*1000+10;
int const MAX=1000*100+10;
int const MAX2=1000*1000+10;
int const MAX3=5000+10;
vector<int> temp;
int n,dis,tcar,tw,ti;
int dp[MAX];
void fidp()
{
    for(int i=temp.size()-2;i>=0;i--)
    {
        if(i!=0)
            dp[temp[i]]=min(dp[temp[i+1]]+ti+tcar*(dis),(n-temp[i])*tw);
        if(i==0)
            dp[temp[0]]=min(dp[temp[1]]+tcar*dis,n*tw);
    }
}
main(){
	ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
	cin>>n>>dis>>tcar>>tw>>ti;
	for(int i=0;i<=n;i+=dis)
        temp.pb(i);
    if(n%dis!=0)
        temp.pb(n);
    fidp();
    cout<<dp[0];
}


//
//  main.cpp
//  vk_cup
//
//  Created by Simp on 17.02.16.
//  Copyright © 2016 Simp. All rights reserved.
//

#include <iostream>
using namespace std;
long long int a,b,c,e=2520,cnt,d[10000009];

// 7 8
// 77 78 87 88
// 777 778 787 877 887 878 788 888

//
//
int main(){

    cin>>a;
    d[0]=1;

    for (long long i=1; i<=a*6; i++) {

        d[i]+=d[i-1]+6*i;

    }

    cout<<d[a];
    return 0;

}


#include<iostream>
#include<cmath>
#include<string>
#include<vector>
#include<algorithm>
#define as __int64
using namespace std;
as a[100000005];
as wes(as n){
          as c=0;
       for(as i=1; i<=n; i++){
            a[i]=i*6;
            }
       for(as i=1; i<=n; i++){
              c=c+a[i];
              }
          return c+1;
          }
int main()
{
    as n, c=0;
    cin>>n;
    cout<<wes(n);
    return 0;
    }


#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#include<stdio.h>
#define CS  ios_base::sync_with_stdio(false);cin.tie();
#define PI  3.141592653589793238462643383279502884
#define Max 100005
#define ll  long long
#define ull unsigned long long
#define ld  long double
#define mod 1000000007
#define inc(i,a,b) for(ll (i)=(a);(i)<(b);++(i))
#define ince(i,a,b) for(ll (i)=(a);(i)<=(b);++(i))
#define dec(i,a,b) for(ll (i)=(a);(i)>=(b);--(i))
#define nl "\n"
#define F    first
#define S    second
#define pb   push_back
#define pr  pair<int,int>
#define NotinRange(n,m) i<0||i>=(n)||j<0||j>=(m)
#define mem(x,y) memset((x),(y),sizeof (x));

using namespace std;
int rnk[26];
int parnt[26];
int prim[15000001];

void seive()
{
    prim[0] =0; prim[1] = 1;
    for ( ull i = 2; i < 15000001; i++ )
        {
            if ( prim[i] == 0 )
                {
                    for ( ull j = i*i ; j < 15000001; j += i )
                        {
                            prim[j]= 1;
                        }
                }
        }
}

int findparnt ( int x )
{
    if ( parnt[x] == x )
        {
            return x;
        }
    return parnt[x] = findparnt ( parnt[x] );
}
bool iscon ( int x, int y )
{
    return ( findparnt ( x ) == findparnt ( y ) );
}
void conn ( int x, int y )
{
    int px = findparnt ( x );
    int py = findparnt ( y );
    if ( px == py )
        {
            return;
        }
    if ( rnk[px] > rnk[py] )
        {
            parnt[py] = px;
        }
    else
        if ( rnk[px] < rnk[py] )
            {
                parnt[px] = py;
            }
        else
            {
                rnk[px]++;
                parnt[py] = px;
            }
}
ll gcd ( ll x, ll y )
{
    if(y==0)return x;
    if ( x % y == 0 )
        {
            return y;
        }
    return gcd ( y, x % y );
}
ull fp ( ull b, ull p )
{
    if ( p == 0 )
        {
            return 1;
        }
    ull t = fp ( b, p / 2 );
    t%=mod;
    if ( p % 2 == 0 )
        {
            return (t * t)%mod;
        }
    return (((t * t)%mod) * (b%mod))%mod;
}
ull lcm ( ull a, ull b )
{
    return ( ( a * b ) / gcd ( a, b ) );
}
double dis ( double x, double y, double x1, double y1 )
{
    return sqrt ( ( x - x1 ) * ( x - x1 ) + ( y - y1 ) * ( y - y1 ) );
}

ll fact[1000006], inv[1000006];

void calcFacAndInv(ll n)
{
    fact[0] = inv[0] = 1;
    for (ll i = 1; i <= n; i++)
        fact[i] = (i * fact[i - 1]) % mod, inv[i] = fp(fact[i], mod - 2);
}

ll ncr(ll n, ll r)
{
    return ((fact[n] * inv[r]) % mod * inv[n - r]) % mod;
}

ll npr(ll n, ll r)
{
    return (fact[n] * inv[n - r]) % mod;
}

/*ll dijest(int x,int y)
{
    vector<ll>cost(200000,1e15);
    priority_queue<pair<ll,int> >pq;
    pq.push({0,x});
    while(!pq.empty())
    {
        ll cr=pq.top().first*-1;
        int i=pq.top().second;
        pq.pop();
        if(cr>cost[i])continue;
        inc(j,0,v[i].size())
        {
            if(cr+v[i][j].S<cost[v[i][j].F])
            {
                cost[v[i][j].F]=cr+v[i][j].S;
                pq.push({cost[v[i][j].F]*-1,v[i][j].F});
            }
        }
    }
    return cost[y];
}*/

int main()
{
    CS
    //freopen("ratios.in","r",stdin);
    //freopen("output.TXT","w",stdout);
ll x;
cin>>x;
cout<<(x+1)*6+1;

}


#include<cstdio>
#include <cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<vector>
#include <map>
using namespace std;
const int N = 9000005;
# define PI 3.141592657
struct node{
	 int x;
	 int y;
}b[N];

bool cmp(struct node a,struct node b){
	if(a.x < b.x)
    {
        return true;
    }
    return false;
}

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

		cout<< 3*n*n + 3*n+1 <<" "<< endl;
	}
   return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long LL;

const int LG = 16;
const int N = 5e5 + 5;
const int M = N * 20;

int n, m;
int a[N];
LL cnt[M], sum[M];
pair<int, LL> b[M];

namespace ST {
  int gd[LG][N], lg[N];
  void Init() {
    for (int i = 1; i <= n; ++i) {
      gd[0][i] = a[i];
      if (i != 1) lg[i] = lg[i >> 1] + 1;
    }
    for (int i = 1; i < LG; ++i) {
      for (int j = 1; j + (1 << i) - 1 <= n; ++j) {
        gd[i][j] = __gcd(gd[i - 1][j], gd[i - 1][j + (1 << (i - 1))]);
      }
    }
  }
  int Query(int l, int r) {
    int k = lg[r - l + 1];
    return __gcd(gd[k][l], gd[k][r - (1 << k) + 1]);
  }
}

namespace EU {
  LL F(LL a, LL b, LL c, LL n) {
    if (n < 0) return 0;
    LL ad = a / c, bd = b / c;
    a %= c, b %= c;
    LL res = n * (n + 1) / 2 * ad + bd * (n + 1);
    if (!a) return res;
    LL m = (a * n + b) / c;
    return res + n * m - F(c, c - b - 1, a, m - 1);
  }
  LL Get(LL a, LL b, LL c, LL n) {
    a = -a;
    n = min(n, b / a);
    return F(a, b - a * n, c, n);
  }
  LL Solve(int a, int b, LL k1, LL k2, LL lim) {
    LL t = max(0LL, (lim - k2 * b) / a);
    if (t >= k1) {
      return k1 * k2;
    }
    return t * k2 + Get(-a, lim, b, k1) - Get(-a, lim, b, t);
  }
}

void UnQ(pair<int, LL> *b, int &n) {
  sort(b + 1, b + 1 + n);
  static bool us[M];
  for (int i = 1, l = 0; i <= n; ++i) {
    us[i] = (i == 1 || b[i - 1].first != b[i].first);
    if (us[i]) l = i;
    else b[l].second += b[i].second;
  }
  int nn = 0;
  for (int i = 1; i <= n; ++i) {
    if (us[i]) {
      b[++nn] = b[i];
    }
  }
  n = nn;
}

LL Calc(LL a, LL b) {
  return a * b + (a + 1) * a / 2;
}

LL Chk(LL lim) {
  LL res = 0;
  for (int i = 1, j = 0; i <= m; ++i) {
    if (i <= j) {
      res += Calc(b[i].second, cnt[j] - cnt[i]);
    }
    if (j < i) {
      LL up = min(lim / b[i].first, b[i].second);
      res += up * (b[i].second + 1);
      res -= up * (up + 1) / 2;
      j = i;
    }
    LL inmid = sum[j] - sum[i];
    for (; j < m; ) {
      res += EU::Solve(b[i].first, b[j + 1].first, b[i].second, b[j + 1].second, lim - inmid);
      if (inmid + b[j + 1].second * b[j + 1].first <= lim) {
        inmid += b[j + 1].second * b[j + 1].first;
        ++j;
      } else {
        break;
      }
    }
  }
  return res;
}

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
  }
  ST::Init();

  for (int i = 1; i <= n; ++i) {
    for (int lm = i; lm <= n; ) {
      int nwg = ST::Query(i, lm);
      int l = lm, r = n;
      for (int md; l < r; ) {
        md = (l + r + 1) >> 1;
        if (ST::Query(i, md) == nwg) {
          l = md;
        } else {
          r = md - 1;
        }
      }
      b[++m] = { nwg, l - lm + 1 };
      lm = l + 1;
    }
  }

  UnQ(b, m);
  for (int i = 1; i <= m; ++i) {
    cnt[i] = cnt[i - 1] + b[i].second;
    sum[i] = sum[i - 1] + b[i].first * b[i].second;
  }

  LL totnumber = n * (n + 1LL) / 2;
  totnumber = totnumber * (totnumber + 1) / 2;
  LL l = 0, r = 1e10;
  for (LL md; l < r; ) {
    md = (l + r) >> 1;
    if (Chk(md) >= (totnumber + 1) / 2) {
      r = md;
    } else {
      l = md + 1;
    }
  }

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

  return 0;
}


#include <algorithm>
#include <cassert>
#include <iostream>
#include <vector>
using namespace std;

template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << "{"; for (typename vector<T>::const_iterator vi=v.begin(); vi!=v.end(); ++vi) { if (vi != v.begin()) os << ", "; os << *vi; } os << "}"; return os; }

struct segment_change {
    // Use a sentinel value rather than a boolean to save significant memory (four bytes per object).
    static const int SENTINEL = numeric_limits<int>::min();

    int to_set;

    segment_change(int _to_set = SENTINEL) : to_set(_to_set) {}

    bool has_set() const {
        return to_set != SENTINEL;
    }
};

struct segment {
    int gcd;

    // TODO: make sure the default constructor is the identity segment.
    segment(int _gcd = 0) : gcd(_gcd) {}

    void apply(const segment_change &change) {
        if (change.has_set())
            gcd = change.to_set;
    }

    void join(const segment &other) {
        gcd = __gcd(gcd, other.gcd);
    }

    // TODO: decide whether to re-implement this for better performance. Mainly relevant when segments contain arrays.
    void join(const segment &a, const segment &b) {
        *this = a;
        join(b);
    }
};

struct basic_seg_tree {
    // Note: POWER_OF_TWO_MODE is only necessary in order to binary search the tree.
    static const bool POWER_OF_TWO_MODE = false;

    int tree_n = 0;
    vector<segment> tree;

    basic_seg_tree(int n = 0) {
        if (n > 0)
            init(n);
    }

    void init(int n) {
        if (POWER_OF_TWO_MODE) {
            tree_n = 1;

            while (tree_n < n)
                tree_n *= 2;
        } else {
            tree_n = n;
        }

        tree.assign(2 * tree_n, segment());
    }

    // O(n) initialization of our tree.
    void build(const vector<segment> &initial) {
        int n = initial.size();
        assert(n <= tree_n);

        for (int i = 0; i < n; i++)
            tree[tree_n + i] = initial[i];

        for (int position = tree_n - 1; position > 0; position--)
            tree[position].join(tree[2 * position], tree[2 * position + 1]);
    }

    static int right_half[];

    segment query(int a, int b) {
        segment answer;
        int r_size = 0;

        for (a += tree_n, b += tree_n; a < b; a /= 2, b /= 2) {
            if (a & 1)
                answer.join(tree[a++]);

            if (b & 1)
                right_half[r_size++] = --b;
        }

        for (int i = r_size - 1; i >= 0; i--)
            answer.join(tree[right_half[i]]);

        return answer;
    }

    void join_up(int position) {
        while (position > 1) {
            position /= 2;
            tree[position].join(tree[2 * position], tree[2 * position + 1]);
        }
    }

    void update(int position, const segment_change &change) {
        position += tree_n;
        tree[position].apply(change);
        join_up(position);
    }

    void update(int position, const segment &seg) {
        position += tree_n;
        tree[position] = seg;
        join_up(position);
    }

    template<typename T_bool>
    int find_last_prefix(int n, T_bool &&should_join) {
        assert(POWER_OF_TWO_MODE);
        segment current;

        // Check edge cases.
        if (!should_join(current, current))
            return -1;

        if (should_join(current, tree[1]))
            return n;

        int position = 1;
        int start = 0, end = tree_n;

        while (position < tree_n) {
            int mid = (start + end) / 2;

            if (should_join(current, tree[2 * position])) {
                current.join(tree[2 * position]);
                position = 2 * position + 1;
                start = mid;
            } else {
                position = 2 * position;
                end = mid;
            }
        }

        assert(position == tree_n + start);
        assert(0 <= start && start < n);
        assert(end - start == 1);
        return start;
    }
};

int basic_seg_tree::right_half[100];

const int A_MAX = 1e5 + 5;

vector<long long> generate(const vector<int> &numbers) {
    int n = numbers.size();
    vector<segment> initial(n);

    for (int i = 0; i < n; i++)
        initial[i] = segment(numbers[i]);

    basic_seg_tree tree(n);
    tree.build(initial);
    vector<long long> freq(A_MAX, 0);

    for (int i = 0; i < n; i++) {
        int g = numbers[i];
        int current = i;

        while (current < n) {
            int low = current, high = n;

            while (low < high) {
                int mid = (low + high + 1) / 2;

                if (tree.query(i, mid).gcd == g)
                    low = mid;
                else
                    high = mid - 1;
            }

            assert(low > current);
            freq[g] += low - current;
            current = low;

            if (current < n)
                g = __gcd(g, numbers[current]);
        }
    }

    // for (int a = 0; a < A_MAX; a++)
    //     if (freq[a] != 0)
    //         cerr << a << ": " << freq[a] << endl;

    return freq;
}

vector<long long> generate_slow(const vector<int> &numbers) {
    int n = numbers.size();
    vector<long long> freq(A_MAX, 0);

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

        for (int j = i; j < n; j++) {
            g = __gcd(g, numbers[j]);
            freq[g]++;
        }
    }

    return freq;
}

long long count_less_slow(const vector<long long> &B, long long target) {
    vector<int> actual;

    for (int i = 0; i < (int) B.size(); i++)
        for (int t = 0; t < B[i]; t++)
            actual.push_back(i);

    // cerr << "actual: " << actual << endl;

    int n = actual.size();
    long long sum = 0, count = 0;

    for (int i = 0, j = 0; i < n; i++) {
        while (j < n && sum + actual[j] < target)
            sum += actual[j++];

        count += j - i;
        sum -= actual[i];
    }

    return count;
}

long long count_less(const vector<long long> &B, long long target) {
    return count_less_slow(B, target);
    assert(B.size() == A_MAX);
    int n = A_MAX - 1;
    long long sum = 0, running_count = 0, answer = 0;

    for (int i = 0, j = 0; i < n; i++) {
        if (B[i] == 0)
            continue;

        while (j < n && sum + j * B[j] < target) {
            sum += j * B[j];
            running_count += B[j];
            j++;
        }

        long long sub_index = min((target - sum - 1) / j, B[j]);
        running_count += sub_index;

        sum -= i * B[i];
        running_count -= B[i];
    }

    assert(answer == count_less_slow(B, target));
    return answer;
}

int main() {
    int N;
    scanf("%d", &N);
    vector<int> A(N);

    for (int &a : A)
        scanf("%d", &a);

    vector<long long> B = generate(A);
    // assert(B == generate_slow(A));
    long long B_count = (long long) N * (N + 1) / 2;
    long long C_count = B_count * (B_count + 1) / 2;
    long long goal = (C_count - 1) / 2;
    // cerr << "C_count: " << C_count << endl;
    // cerr << "goal: " << goal << endl;

    long long low = 0, high = 4e18;

    while (low < high) {
        long long mid = (low + high + 1) / 2;
        // cerr << mid << ": " << count_less(B, mid) << endl;

        if (count_less(B, mid) > goal)
            high = mid - 1;
        else
            low = mid;
    }

    printf("%lld\n", low);
}


#include <algorithm>
#include <cassert>
#include <iostream>
#include <vector>
using namespace std;

template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << "{"; for (typename vector<T>::const_iterator vi=v.begin(); vi!=v.end(); ++vi) { if (vi != v.begin()) os << ", "; os << *vi; } os << "}"; return os; }

struct segment_change {
    // Use a sentinel value rather than a boolean to save significant memory (four bytes per object).
    static const int SENTINEL = numeric_limits<int>::min();

    int to_set;

    segment_change(int _to_set = SENTINEL) : to_set(_to_set) {}

    bool has_set() const {
        return to_set != SENTINEL;
    }
};

struct segment {
    int gcd;

    // TODO: make sure the default constructor is the identity segment.
    segment(int _gcd = 0) : gcd(_gcd) {}

    void apply(const segment_change &change) {
        if (change.has_set())
            gcd = change.to_set;
    }

    void join(const segment &other) {
        gcd = __gcd(gcd, other.gcd);
    }

    // TODO: decide whether to re-implement this for better performance. Mainly relevant when segments contain arrays.
    void join(const segment &a, const segment &b) {
        *this = a;
        join(b);
    }
};

struct basic_seg_tree {
    // Note: POWER_OF_TWO_MODE is only necessary in order to binary search the tree.
    static const bool POWER_OF_TWO_MODE = false;

    int tree_n = 0;
    vector<segment> tree;

    basic_seg_tree(int n = 0) {
        if (n > 0)
            init(n);
    }

    void init(int n) {
        if (POWER_OF_TWO_MODE) {
            tree_n = 1;

            while (tree_n < n)
                tree_n *= 2;
        } else {
            tree_n = n;
        }

        tree.assign(2 * tree_n, segment());
    }

    // O(n) initialization of our tree.
    void build(const vector<segment> &initial) {
        int n = initial.size();
        assert(n <= tree_n);

        for (int i = 0; i < n; i++)
            tree[tree_n + i] = initial[i];

        for (int position = tree_n - 1; position > 0; position--)
            tree[position].join(tree[2 * position], tree[2 * position + 1]);
    }

    static int right_half[];

    segment query(int a, int b) {
        segment answer;
        int r_size = 0;

        for (a += tree_n, b += tree_n; a < b; a /= 2, b /= 2) {
            if (a & 1)
                answer.join(tree[a++]);

            if (b & 1)
                right_half[r_size++] = --b;
        }

        for (int i = r_size - 1; i >= 0; i--)
            answer.join(tree[right_half[i]]);

        return answer;
    }

    void join_up(int position) {
        while (position > 1) {
            position /= 2;
            tree[position].join(tree[2 * position], tree[2 * position + 1]);
        }
    }

    void update(int position, const segment_change &change) {
        position += tree_n;
        tree[position].apply(change);
        join_up(position);
    }

    void update(int position, const segment &seg) {
        position += tree_n;
        tree[position] = seg;
        join_up(position);
    }

    template<typename T_bool>
    int find_last_prefix(int n, T_bool &&should_join) {
        assert(POWER_OF_TWO_MODE);
        segment current;

        // Check edge cases.
        if (!should_join(current, current))
            return -1;

        if (should_join(current, tree[1]))
            return n;

        int position = 1;
        int start = 0, end = tree_n;

        while (position < tree_n) {
            int mid = (start + end) / 2;

            if (should_join(current, tree[2 * position])) {
                current.join(tree[2 * position]);
                position = 2 * position + 1;
                start = mid;
            } else {
                position = 2 * position;
                end = mid;
            }
        }

        assert(position == tree_n + start);
        assert(0 <= start && start < n);
        assert(end - start == 1);
        return start;
    }
};

int basic_seg_tree::right_half[100];

const int A_MAX = 1e5 + 5;

vector<long long> generate(const vector<int> &numbers) {
    int n = numbers.size();
    vector<segment> initial(n);

    for (int i = 0; i < n; i++)
        initial[i] = segment(numbers[i]);

    basic_seg_tree tree(n);
    tree.build(initial);
    vector<long long> freq(A_MAX, 0);

    for (int i = 0; i < n; i++) {
        int g = numbers[i];
        int current = i;

        while (current < n) {
            int low = current, high = n;

            while (low < high) {
                int mid = (low + high + 1) / 2;

                if (tree.query(i, mid).gcd == g)
                    low = mid;
                else
                    high = mid - 1;
            }

            assert(low > current);
            freq[g] += low - current;
            current = low;

            if (current < n)
                g = __gcd(g, numbers[current]);
        }
    }

    return freq;
}

// Counts x, y >= 0 such that Ax + By <= C.
long long count_triangle(long long A, long long B, long long C) {
    if (C < 0) return 0;
    if (A > B) swap(A, B);
    long long p = C / B;
    long long k = B / A;
    long long d = (C - p * B) / A;
    return count_triangle(B - k * A, A, C - A * (k * p + d + 1)) + (p + 1) * (d + 1) + k * p * (p + 1) / 2;
}

// Counts 0 <= x < RA, 0 <= y < RB such that Ax + By <= C.
long long count_triangle_rectangle_intersection(long long A, long long B, long long C, long long RA, long long RB) {
    if (C < 0) return 0;
    if (C >= A * RA + B * RB) return RA * RB;
    return count_triangle(A, B, C) - count_triangle(A, B, C - A * RA) - count_triangle(A, B, C - B * RB);
}

long long count_less_equal_slow(const vector<long long> &B, long long target) {
    vector<int> actual;

    for (int i = 0; i < (int) B.size(); i++)
        for (int t = 0; t < B[i]; t++)
            actual.push_back(i);

    int n = actual.size();
    long long sum = 0, count = 0;

    for (int i = 0, j = 0; i < n; i++) {
        while (j < n && sum + actual[j] <= target)
            sum += actual[j++];

        count += j - i;
        sum -= actual[i];
    }

    return count;
}

long long count_less_equal(const vector<long long> &B, long long target) {
    assert(B.size() == A_MAX);
    int n = A_MAX - 1;
    long long sum = 0, running_count = 0, answer = 0;

    for (int i = 1, j = 1; i < n; i++) {
        // Count within the subarray of i.
        long long most = min(B[i], target / i);
        long long missing = B[i] - most;
        answer += B[i] * (B[i] + 1) / 2 - missing * (missing + 1) / 2;
        sum -= i * B[i];
        running_count -= B[i];

        if (i < j)
            answer += B[i] * running_count;

        while (j < n) {
            if (i < j)
                answer += count_triangle_rectangle_intersection(i, j, target - sum - i - j, B[i], B[j]);

            if (sum + j * B[j] <= target) {
                sum += j * B[j];
                running_count += B[j];
                j++;
            } else {
                break;
            }
        }
    }

    assert(answer == count_less_equal_slow(B, target));
    return answer;
}

int main() {
    int N;
    scanf("%d", &N);
    vector<int> A(N);

    for (int &a : A)
        scanf("%d", &a);

    vector<long long> B = generate(A);
    long long B_count = (long long) N * (N + 1) / 2;
    long long C_count = B_count * (B_count + 1) / 2;
    long long goal = (C_count - 1) / 2;
    long long full_sum = 0;

    for (int i = 0; i < (int) B.size(); i++)
        full_sum += i * B[i];

    long long low = 0, high = full_sum;

    while (low < high) {
        long long mid = (low + high) / 2;

        if (count_less_equal(B, mid) > goal)
            high = mid;
        else
            low = mid + 1;
    }

    printf("%lld\n", low);
}


#include <bits/stdc++.h>

#define fi first
#define se second
#define db double
#define U unsigned
#define P std::pair<int,int>
#define LL long long
#define pb push_back
#define MP std::make_pair
#define all(x) x.begin(),x.end()
#define CLR(i,a) memset(i,a,sizeof(i))
#define FOR(i,a,b) for(int i = a;i <= b;++i)
#define ROF(i,a,b) for(int i = a;i >= b;--i)
#define DEBUG(x) std::cerr << #x << '=' << x << std::endl

const int MAXN = 1e5+5;
int a[MAXN],n;
P st[MAXN];
int tp;
LL t[MAXN];
int A[MAXN];
int M;
LL sm[MAXN],csm[MAXN],cnt[MAXN];

inline LL f(LL n,LL a,LL b,LL c){
	if(n < 0) return 0;
	if(a < 0) return f(n,-a,b+n*a,c);
	if(b < 0){
		if(!a) return 0;
		LL d = std::ceil((long double)(-b)/a);
		// DEBUG(a);DEBUG(b);DEBUG(d);
		// exit(0);
		return f(n-d,a,b+a*d,c);
	}
	if(!a) return (b/c)*(n+1);
	if(a >= c || b >= c) return f(n,a%c,b%c,c)+(a/c)*n*(n+1)/2+(b/c)*(n+1);
	LL M = (a*n+b)/c;
	return n*M-f(M-1,c,c-b-1,a);
}

inline LL calc(int l,int r,int k){
	if(sm[r]-sm[l-1] <= k) return cnt[l]*cnt[r];
	LL s = sm[r-1]-sm[l];
	LL A = ::A[l],B = ::A[r],CA = cnt[l],CB = cnt[r];
	LL gx = f(CA,-A,k-s,B)-std::max(0ll,(k-s)/B);
	gx -= f(CA,-A,k-B*CB-s,B)-std::max(0ll,(k-B*CB-s)/B);
	return gx;
}

inline bool chk(int k){// 判断答案是否<=k 如果<=k需要满足 <=k的数 >= >k的数
	// 计算 <= k 的数字数量
	LL res = 0;
	FOR(i,1,M){
		int l = std::min((LL)k/A[i],cnt[i]);// 最多选几个
		// DEBUG(k/A[i]);
		res += cnt[i]*l - l*(l-1)/2;
		sm[i] = sm[i-1]+A[i]*cnt[i];
		csm[i] = csm[i-1]+cnt[i];
	}
	// DEBUG(res);
	// DEBUG(f(1,-6,6,0));
	// exit(0);
	int r = 1;
	FOR(l,1,M){// 每次获得最长的区间和<=k的区间
		if(A[l] > k) break;
		r = std::max(r,l+1);
		while(r <= M && sm[r]-sm[l-1] <= k) ++r;
		res += (csm[r-1]-csm[l])*cnt[l];
		while(r <= M && sm[r]-sm[l] <= k) res += calc(l,r,k),++r;
		// if(l == 1) DEBUG(res);
	}
	// DEBUG(res);
	LL m = n*(n+1)/2;
	return res >= m*(m+1)/2 - res;
}

int main(){
	scanf("%d",&n);
	FOR(i,1,n) scanf("%d",a+i);
	FOR(i,1,n){
		int p = 0;
		st[++tp] = MP(a[i],i);
		FOR(j,1,tp){
			st[j].fi = std::__gcd(st[j].fi,a[i]);
			if(st[j].fi == st[p].fi) continue;
			st[++p] = st[j];
		}
		tp = p;
		// DEBUG(i);
		// FOR(j,1,tp) printf("%d %d\n",st[j].fi,st[j].se);
		// puts("-------");
		FOR(j,1,tp-1) t[st[j].fi] += st[j+1].se-st[j].se;
		t[st[tp].fi] += i-st[tp].se+1;
	}
	FOR(i,1,MAXN-1) if(t[i]) A[++M] = i,cnt[M] = t[i];
	// FOR(i,1,M) printf("%d %d\n",A[i],cnt[i]);
	std::vector<int> S,T;
	FOR(i,1,M) FOR(j,1,cnt[i]) S.pb(A[i]);std::sort(all(S));
	FOR(l,0,(int)S.size()-1){
		int sm = 0;
		FOR(r,l,(int)S.size()-1) sm += S[r],T.pb(sm);
	}
	std::sort(all(T));
	// for(auto x:T) DEBUG(x);
	// DEBUG(chk(8));
	// exit(0);
	int l = 1,r = 100000,ans = -1;
	while(l <= r){
		int mid = (l + r) >> 1;
		if(chk(mid)) ans = mid,r = mid-1;
		else l = mid+1;
	}
	printf("%d\n",ans);
	return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const int maxn=1e5+ 10;
const int mod = 1e9+7;
int a , b;

int power(int a,int b){
    if(b==0){
        return 1;
    }else if(b==1){
        return a;
    }

    ll ans = power(a,b/2)%mod;
    ans = (ans*ans)%mod;
    return (ans*power(a,b%2))%mod;

}

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

    if(n==1 && m==1 ){
        return cout<<1 , 0;
    }

    if(n>1 && m==1 ){
        if(k==1){
            return cout<<1 , 0;
        }
        if(k==-1){

                if(n%2==0){
                    return cout<<-1 , 0 ;
                }
                else{
                    return cout<<1 , 0;
                }

        }
    }

     if(m>1 && n==1 ){
        if(k==1){
            return cout<<1 , 0;
        }
        if(k==-1){

                if(m%2==0){
                    return cout<<-1 , 0 ;
                }
                else{
                    return cout<<1 , 0;
                }

        }
    }

    if(n>1){
        n--;
    }
    if(m>1){
        m--;
    }

    cout<<power(2,m*n);
    return 0;
}


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

long long power(long long a,long long b);

int main(void)
{
    int n,m,k;
    cin>>n>>m>>k;
    if(n%2!=m%2&&k==-1)
    {
        cout<<0<<endl;
        return 0;
    }
    cout<<power(power(2,n-1),m-1)<<endl;
}

long long power(long long a,long long b)
{
    if(b==1)
        return a;
    long long p=power(a,b/2);
    if(b%2==0)
        return (p*p)%M;
    return (a*(p*p)%M)%M;
}