#include <bits/stdc++.h>
using namespace std;
const int MAX = 50;
map<long long, long long> mm[MAX];
long long n, t;
long long val[MAX], vnt;
long long sol(int bidx, long long num, long long f) {
  if (bidx == 1) {
    if (num == 0)
      return 0;
    else {
      return mm[bidx][t / f];
    }
  } else {
    long long K = (long long)1 << (bidx - 2);
    if (num <= K) {
      return sol(bidx - 1, num, f);
    } else {
      long long ret = 0;
      ret += mm[bidx - 1][t / f];
      ret += sol(bidx - 1, num - K, f * 2);
      return ret;
    }
  }
}
int main() {
  scanf("%lld%lld", &n, &t);
  mm[1][1] = 1;
  for (int i = (2); i <= (MAX - 1); ++i) {
    mm[i] = mm[i - 1];
    vector<pair<long long, long long> > adds;
    for (auto &ele : mm[i]) {
      adds.push_back({ele.first << 1, ele.second});
    }
    for (auto &ele : adds) {
      mm[i][ele.first] += ele.second;
    }
  }
  n++;
  long long t1 = t - (t & ~(t - 1));
  if (t1)
    printf("%d\n", 0);
  else {
    if (n == 2) {
      if (t == 1)
        printf("%d\n", 1);
      else
        printf("%d\n", 0);
    } else if (n == 3) {
      if (t == 1 || t == 2)
        printf("%d\n", 1);
      else
        printf("%d\n", 0);
    } else {
      vnt = 0;
      long long tmpn = n;
      while (n) {
        long long r = n % 2;
        val[vnt++] = r;
        n /= 2;
      }
      long long ans = 0;
      for (int bidx = (2); bidx <= (vnt - 1); ++bidx) ans += mm[bidx][t];
      ans += sol(vnt, tmpn - ((long long)1 << (vnt - 1)) + 1, 1);
      printf("%lld\n", ans);
    }
  }
  return 0;
}

### Prompt

Construct a Cpp code solution to the problem outlined:

Maxim loves to fill in a matrix in a special manner. Here is a pseudocode of filling in a matrix of size (m + 1) × (m + 1):

<image>

Maxim asks you to count, how many numbers m (1 ≤ m ≤ n) are there, such that the sum of values in the cells in the row number m + 1 of the resulting matrix equals t.

Expression (x xor y) means applying the operation of bitwise excluding "OR" to numbers x and y. The given operation exists in all modern programming languages. For example, in languages C++ and Java it is represented by character "^", in Pascal — by "xor".

Input

A single line contains two integers n and t (1 ≤ n, t ≤ 1012, t ≤ n + 1).

Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.

Output

In a single line print a single integer — the answer to the problem. 

Examples

Input

1 1


Output

1


Input

3 2


Output

1


Input

3 3


Output

0


Input

1000000000000 1048576


Output

118606527258

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int MAX = 50;
map<long long, long long> mm[MAX];
long long n, t;
long long val[MAX], vnt;
long long sol(int bidx, long long num, long long f) {
  if (bidx == 1) {
    if (num == 0)
      return 0;
    else {
      return mm[bidx][t / f];
    }
  } else {
    long long K = (long long)1 << (bidx - 2);
    if (num <= K) {
      return sol(bidx - 1, num, f);
    } else {
      long long ret = 0;
      ret += mm[bidx - 1][t / f];
      ret += sol(bidx - 1, num - K, f * 2);
      return ret;
    }
  }
}
int main() {
  scanf("%lld%lld", &n, &t);
  mm[1][1] = 1;
  for (int i = (2); i <= (MAX - 1); ++i) {
    mm[i] = mm[i - 1];
    vector<pair<long long, long long> > adds;
    for (auto &ele : mm[i]) {
      adds.push_back({ele.first << 1, ele.second});
    }
    for (auto &ele : adds) {
      mm[i][ele.first] += ele.second;
    }
  }
  n++;
  long long t1 = t - (t & ~(t - 1));
  if (t1)
    printf("%d\n", 0);
  else {
    if (n == 2) {
      if (t == 1)
        printf("%d\n", 1);
      else
        printf("%d\n", 0);
    } else if (n == 3) {
      if (t == 1 || t == 2)
        printf("%d\n", 1);
      else
        printf("%d\n", 0);
    } else {
      vnt = 0;
      long long tmpn = n;
      while (n) {
        long long r = n % 2;
        val[vnt++] = r;
        n /= 2;
      }
      long long ans = 0;
      for (int bidx = (2); bidx <= (vnt - 1); ++bidx) ans += mm[bidx][t];
      ans += sol(vnt, tmpn - ((long long)1 << (vnt - 1)) + 1, 1);
      printf("%lld\n", ans);
    }
  }
  return 0;
}

```