#include <bits/stdc++.h>
using namespace std;
long long n, t;
long long f[62][62];
int divi(long long x) {
  int rn = 0;
  while (x > 1) x /= 2, rn++;
  return rn;
}
long long solve(long long n, long long t) {
  if (n <= 3) {
    int cnt = 0;
    if (n >= 1 && t == 1) cnt++;
    if (n >= 2 && t == 2) cnt++;
    if (n >= 3 && t == 1) cnt++;
    return cnt;
  }
  long long a = 1, b, e = 1, rn = 0;
  for (;;) {
    b = a, a = a * 2 + 3;
    if (a + 3 <= n)
      e++;
    else {
      if (a + 1 <= n && ((long long)1 << e + 1) == t) rn++;
      if (a + 2 <= n && t == 1) rn++;
      if (a + 3 <= n && t == 2) rn++;
      n = min(a, n);
      break;
    }
  }
  rn += f[e][divi(t)];
  if (t == 1 || t == 2) rn++;
  if (t % 2 == 0) rn += solve(n - b - 3, t / 2);
  return rn;
}
int main() {
  cin >> n >> t;
  if (((long long)1 << divi(t)) != t) {
    cout << 0 << endl;
    return 0;
  }
  f[1][0] = 1, f[1][1] = 1;
  for (int i = 2; i <= 60; i++)
    for (int j = 0; j <= i; j++) {
      f[i][j] = f[i - 1][j] + (j ? f[i - 1][j - 1] : 0);
      if (j == 0 || j == 1) f[i][j]++;
    }
  cout << solve(n, t) << endl;
}

### Prompt

In CPP, your task is to solve the following problem:

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;
long long n, t;
long long f[62][62];
int divi(long long x) {
  int rn = 0;
  while (x > 1) x /= 2, rn++;
  return rn;
}
long long solve(long long n, long long t) {
  if (n <= 3) {
    int cnt = 0;
    if (n >= 1 && t == 1) cnt++;
    if (n >= 2 && t == 2) cnt++;
    if (n >= 3 && t == 1) cnt++;
    return cnt;
  }
  long long a = 1, b, e = 1, rn = 0;
  for (;;) {
    b = a, a = a * 2 + 3;
    if (a + 3 <= n)
      e++;
    else {
      if (a + 1 <= n && ((long long)1 << e + 1) == t) rn++;
      if (a + 2 <= n && t == 1) rn++;
      if (a + 3 <= n && t == 2) rn++;
      n = min(a, n);
      break;
    }
  }
  rn += f[e][divi(t)];
  if (t == 1 || t == 2) rn++;
  if (t % 2 == 0) rn += solve(n - b - 3, t / 2);
  return rn;
}
int main() {
  cin >> n >> t;
  if (((long long)1 << divi(t)) != t) {
    cout << 0 << endl;
    return 0;
  }
  f[1][0] = 1, f[1][1] = 1;
  for (int i = 2; i <= 60; i++)
    for (int j = 0; j <= i; j++) {
      f[i][j] = f[i - 1][j] + (j ? f[i - 1][j - 1] : 0);
      if (j == 0 || j == 1) f[i][j]++;
    }
  cout << solve(n, t) << endl;
}

```