#include <bits/stdc++.h>
using namespace std;
const int INF = 2147483647;
const long long LLINF = 9223372036854775807LL;
long long n, t;
long long res[1000][1000];
long long ask(long long level, long long pos, long long count) {
  if (count < 0) return 0;
  if (pos == (1ull << (level - 1))) {
    return res[level][count + 1];
  }
  if (pos > (1ull << (level - 2))) {
    return ask(level - 1, pos - (1ull << (level - 2)), count - 1) +
           ask(level - 1, (1ull << (level - 2)), count);
  }
  return ask(level - 1, pos, count);
}
int main() {
  cin >> n >> t;
  n++;
  bool ok = true;
  long long now = 1;
  for (;;) {
    if (now == t) break;
    if (now > t) {
      ok = false;
      break;
    }
    now <<= 1;
  }
  if (!ok) {
    cout << "0";
    exit(0);
  }
  long long p = 1;
  long long l = 0;
  while (p <= n) {
    p <<= 1;
    l++;
  }
  long long pos = n - (p >> 1);
  long long tl = 0;
  while (t > 0) {
    t >>= 1;
    tl++;
  }
  tl--;
  memset(res, 0, sizeof(res));
  res[1][1] = 1;
  for (int i = 2; i <= l + 10; i++) {
    for (int j = 1; j <= i + 10; j++)
      res[i][j] = res[i - 1][j - 1] + res[i - 1][j];
  }
  long long r = 0;
  for (int i = 2; i <= l - 1; i++) r += res[i][tl + 1];
  r += ask(l, pos + 1, tl);
  if (t == 1) r--;
  cout << r << "\n";
  return 0;
}

### Prompt

Develop a solution in Cpp to the problem described below:

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 INF = 2147483647;
const long long LLINF = 9223372036854775807LL;
long long n, t;
long long res[1000][1000];
long long ask(long long level, long long pos, long long count) {
  if (count < 0) return 0;
  if (pos == (1ull << (level - 1))) {
    return res[level][count + 1];
  }
  if (pos > (1ull << (level - 2))) {
    return ask(level - 1, pos - (1ull << (level - 2)), count - 1) +
           ask(level - 1, (1ull << (level - 2)), count);
  }
  return ask(level - 1, pos, count);
}
int main() {
  cin >> n >> t;
  n++;
  bool ok = true;
  long long now = 1;
  for (;;) {
    if (now == t) break;
    if (now > t) {
      ok = false;
      break;
    }
    now <<= 1;
  }
  if (!ok) {
    cout << "0";
    exit(0);
  }
  long long p = 1;
  long long l = 0;
  while (p <= n) {
    p <<= 1;
    l++;
  }
  long long pos = n - (p >> 1);
  long long tl = 0;
  while (t > 0) {
    t >>= 1;
    tl++;
  }
  tl--;
  memset(res, 0, sizeof(res));
  res[1][1] = 1;
  for (int i = 2; i <= l + 10; i++) {
    for (int j = 1; j <= i + 10; j++)
      res[i][j] = res[i - 1][j - 1] + res[i - 1][j];
  }
  long long r = 0;
  for (int i = 2; i <= l - 1; i++) r += res[i][tl + 1];
  r += ask(l, pos + 1, tl);
  if (t == 1) r--;
  cout << r << "\n";
  return 0;
}

```