#include <bits/stdc++.h>
using namespace std;
const int N = 55;
long long pot2[N], dp[N][2][2][N];
string number;
int sz;
long long solve(int pos, int same, int zero, int cant) {
  if (cant < 0) return 0;
  if (pos == sz) return cant == 0 && zero;
  if (dp[pos][same][zero][cant] != -1) return dp[pos][same][zero][cant];
  long long res = 0;
  if (same) {
    for (int step = 0; step <= number[pos] - '0'; step++)
      res += solve(pos + 1, step == number[pos] - '0' ? 1 : 0,
                   zero | (step == 1), cant - step);
  } else {
    res += solve(pos + 1, same, zero, cant);
    res += solve(pos + 1, same, zero | 1, cant - 1);
  }
  return dp[pos][same][zero][cant] = res;
}
int main() {
  pot2[0] = 1;
  for (int i = 1; i < N; ++i) pot2[i] = pot2[i - 1] * 2;
  long long n, t;
  cin >> n >> t;
  int where = -1;
  for (int i = 0; i < N; ++i)
    if (t == pot2[i]) {
      where = i;
    }
  if (where == -1)
    puts("0");
  else {
    int cant = where + 1;
    n++;
    while (n > 0) number.push_back((n & 1) + '0'), n >>= 1;
    reverse(number.begin(), number.end());
    sz = number.size();
    memset(dp, -1, sizeof dp);
    long long res = solve(0, 1, 0, cant);
    if (cant == 1) res--;
    cout << res << endl;
  }
  return 0;
}

### Prompt

Please create a solution in CPP to 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;
const int N = 55;
long long pot2[N], dp[N][2][2][N];
string number;
int sz;
long long solve(int pos, int same, int zero, int cant) {
  if (cant < 0) return 0;
  if (pos == sz) return cant == 0 && zero;
  if (dp[pos][same][zero][cant] != -1) return dp[pos][same][zero][cant];
  long long res = 0;
  if (same) {
    for (int step = 0; step <= number[pos] - '0'; step++)
      res += solve(pos + 1, step == number[pos] - '0' ? 1 : 0,
                   zero | (step == 1), cant - step);
  } else {
    res += solve(pos + 1, same, zero, cant);
    res += solve(pos + 1, same, zero | 1, cant - 1);
  }
  return dp[pos][same][zero][cant] = res;
}
int main() {
  pot2[0] = 1;
  for (int i = 1; i < N; ++i) pot2[i] = pot2[i - 1] * 2;
  long long n, t;
  cin >> n >> t;
  int where = -1;
  for (int i = 0; i < N; ++i)
    if (t == pot2[i]) {
      where = i;
    }
  if (where == -1)
    puts("0");
  else {
    int cant = where + 1;
    n++;
    while (n > 0) number.push_back((n & 1) + '0'), n >>= 1;
    reverse(number.begin(), number.end());
    sz = number.size();
    memset(dp, -1, sizeof dp);
    long long res = solve(0, 1, 0, cant);
    if (cant == 1) res--;
    cout << res << endl;
  }
  return 0;
}

```