#include <bits/stdc++.h>
using std::cin;
using std::cout;
long long quick_table[41 + 1][41 + 1];
long long sum_quick_table[41 + 1][41 + 1];
long long nums[41 + 1];
inline int right_most_bit(long long number) {
  if (number == 0) return -1;
  int pos = 0;
  long long value = 1;
  while (value <= number) {
    ++pos;
    value *= 2;
  }
  --pos;
  return pos;
}
long long solve(int pos_t, int pos, long long n, long long num) {
  if (pos_t < 0) return 0;
  if (n == num) {
    return quick_table[pos][pos_t];
  } else {
    if (n < num) {
      return solve(pos_t, pos - 1, n, num - nums[pos - 1]);
    } else {
      return quick_table[pos][pos_t] +
             solve(pos_t - 1, pos - 1, n, num + nums[pos - 1]);
    }
  }
}
int main(int argc, char *argv[]) {
  long long n, t;
  cin >> n >> t;
  memset(sum_quick_table, 0, sizeof(long long) * (41 + 1) * (41 + 1));
  memset(quick_table, 0, sizeof(long long) * (41 + 1) * (41 + 1));
  memset(nums, 0, sizeof(long long) * (41 + 1));
  quick_table[0][0] = 1;
  quick_table[1][0] = 1;
  quick_table[1][1] = 1;
  int i, j, k;
  for (i = 2; i <= 41; ++i) {
    quick_table[i][0] = 1;
    for (j = 1; j <= i; ++j)
      quick_table[i][j] = quick_table[i - 1][j] + quick_table[i - 1][j - 1];
  }
  nums[0] = 1;
  for (i = 1; i <= 41; ++i) nums[i] = 2 * nums[i - 1];
  sum_quick_table[0][0] = 0;
  sum_quick_table[1][0] = 1;
  sum_quick_table[1][1] = 1;
  for (i = 2; i <= 41; ++i)
    for (j = 0; j <= i; ++j)
      sum_quick_table[i][j] = sum_quick_table[i - 1][j] + quick_table[i][j];
  int pos_t = right_most_bit(t);
  int pos_n = right_most_bit(n + 1);
  if ((1 << pos_t) == t) {
    cout << sum_quick_table[pos_n - 1][pos_t] +
                solve(pos_t, pos_n, n, nums[pos_n + 1] - 2)
         << "\n";
  } else {
    cout << "0\n";
  }
  return EXIT_SUCCESS;
}

### Prompt

Create a solution in CPP for 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 std::cin;
using std::cout;
long long quick_table[41 + 1][41 + 1];
long long sum_quick_table[41 + 1][41 + 1];
long long nums[41 + 1];
inline int right_most_bit(long long number) {
  if (number == 0) return -1;
  int pos = 0;
  long long value = 1;
  while (value <= number) {
    ++pos;
    value *= 2;
  }
  --pos;
  return pos;
}
long long solve(int pos_t, int pos, long long n, long long num) {
  if (pos_t < 0) return 0;
  if (n == num) {
    return quick_table[pos][pos_t];
  } else {
    if (n < num) {
      return solve(pos_t, pos - 1, n, num - nums[pos - 1]);
    } else {
      return quick_table[pos][pos_t] +
             solve(pos_t - 1, pos - 1, n, num + nums[pos - 1]);
    }
  }
}
int main(int argc, char *argv[]) {
  long long n, t;
  cin >> n >> t;
  memset(sum_quick_table, 0, sizeof(long long) * (41 + 1) * (41 + 1));
  memset(quick_table, 0, sizeof(long long) * (41 + 1) * (41 + 1));
  memset(nums, 0, sizeof(long long) * (41 + 1));
  quick_table[0][0] = 1;
  quick_table[1][0] = 1;
  quick_table[1][1] = 1;
  int i, j, k;
  for (i = 2; i <= 41; ++i) {
    quick_table[i][0] = 1;
    for (j = 1; j <= i; ++j)
      quick_table[i][j] = quick_table[i - 1][j] + quick_table[i - 1][j - 1];
  }
  nums[0] = 1;
  for (i = 1; i <= 41; ++i) nums[i] = 2 * nums[i - 1];
  sum_quick_table[0][0] = 0;
  sum_quick_table[1][0] = 1;
  sum_quick_table[1][1] = 1;
  for (i = 2; i <= 41; ++i)
    for (j = 0; j <= i; ++j)
      sum_quick_table[i][j] = sum_quick_table[i - 1][j] + quick_table[i][j];
  int pos_t = right_most_bit(t);
  int pos_n = right_most_bit(n + 1);
  if ((1 << pos_t) == t) {
    cout << sum_quick_table[pos_n - 1][pos_t] +
                solve(pos_t, pos_n, n, nums[pos_n + 1] - 2)
         << "\n";
  } else {
    cout << "0\n";
  }
  return EXIT_SUCCESS;
}

```