#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long double E = 1e-17;
char ccc;
inline void read(int &n) {
  n = 0;
  while (true) {
    ccc = getchar();
    if (ccc == ' ' || ccc == '\n') break;
    n = n * 10 + ccc - '0';
  }
}
template <typename T>
inline T sqr(T t) {
  return t * t;
}
int bits(long long n) {
  int ans = 0;
  while (n) {
    ans += n & 1;
    n >>= 1;
  }
  return ans;
}
void print(int n) {
  int ar[n + 2][n + 2];
  memset(ar, 0, sizeof(ar));
  ar[1][n + 1] = 1;
  for (int i = 2; i <= n + 1; i++) {
    for (int j = 1; j <= n + 1; j++) {
      ar[i][j] =
          (j == 1 ? 0 : ar[i - 1][j - 1]) ^ (j == n + 1 ? 0 : ar[i - 1][j + 1]);
    }
  }
  for (int i = 1; i <= n + 1; i++) {
    int sum = 0;
    for (int j = 1; j <= n + 1; j++) {
      sum += ar[i][j];
    }
  }
}
int _count(long long n, int b) {
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    if (bits(i) == b) ans++;
  }
  return ans;
}
long long dp[60][60];
long long _count_2(long long n, int b) {
  if (b == 0) return 0;
  if (b == 1) {
    return log2(n) + 1;
  }
  int q = log2(n);
  memset(dp, 0, sizeof(dp));
  dp[q][0] = 1;
  long long t = 1;
  for (int i = q - 1; i >= 0; i--) {
    for (int j = 0; j <= q; j++) {
      dp[i][j] += dp[i + 1][j] + (j != 0 ? dp[i + 1][j - 1] : 0);
    }
    t = t << 1 | (n & (1LL << i) ? 1 : 0);
    int w = bits(t - 1);
    if (w && (t & 1)) dp[i][w]++;
  }
  dp[0][bits(n)]++;
  return dp[0][b];
}
long long solve_long(long long n, int w) {
  long long ans = 0;
  for (int i = 2; i <= n; i++)
    if (bits(i) == w) ans++;
  return ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  srand(time(NULL));
  cout.precision(15);
  cout << fixed;
  long long b, a;
  cin >> a >> b;
  if (b & (b - 1)) {
    cout << 0;
    return 0;
  }
  a++;
  int w = log2(b);
  w++;
  cout << _count_2(a, w) - (w == 1 ? 1 : 0) << "\n";
}

### Prompt

Please provide a CPP coded solution 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 long long MOD = 1e9 + 7;
const long double E = 1e-17;
char ccc;
inline void read(int &n) {
  n = 0;
  while (true) {
    ccc = getchar();
    if (ccc == ' ' || ccc == '\n') break;
    n = n * 10 + ccc - '0';
  }
}
template <typename T>
inline T sqr(T t) {
  return t * t;
}
int bits(long long n) {
  int ans = 0;
  while (n) {
    ans += n & 1;
    n >>= 1;
  }
  return ans;
}
void print(int n) {
  int ar[n + 2][n + 2];
  memset(ar, 0, sizeof(ar));
  ar[1][n + 1] = 1;
  for (int i = 2; i <= n + 1; i++) {
    for (int j = 1; j <= n + 1; j++) {
      ar[i][j] =
          (j == 1 ? 0 : ar[i - 1][j - 1]) ^ (j == n + 1 ? 0 : ar[i - 1][j + 1]);
    }
  }
  for (int i = 1; i <= n + 1; i++) {
    int sum = 0;
    for (int j = 1; j <= n + 1; j++) {
      sum += ar[i][j];
    }
  }
}
int _count(long long n, int b) {
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    if (bits(i) == b) ans++;
  }
  return ans;
}
long long dp[60][60];
long long _count_2(long long n, int b) {
  if (b == 0) return 0;
  if (b == 1) {
    return log2(n) + 1;
  }
  int q = log2(n);
  memset(dp, 0, sizeof(dp));
  dp[q][0] = 1;
  long long t = 1;
  for (int i = q - 1; i >= 0; i--) {
    for (int j = 0; j <= q; j++) {
      dp[i][j] += dp[i + 1][j] + (j != 0 ? dp[i + 1][j - 1] : 0);
    }
    t = t << 1 | (n & (1LL << i) ? 1 : 0);
    int w = bits(t - 1);
    if (w && (t & 1)) dp[i][w]++;
  }
  dp[0][bits(n)]++;
  return dp[0][b];
}
long long solve_long(long long n, int w) {
  long long ans = 0;
  for (int i = 2; i <= n; i++)
    if (bits(i) == w) ans++;
  return ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  srand(time(NULL));
  cout.precision(15);
  cout << fixed;
  long long b, a;
  cin >> a >> b;
  if (b & (b - 1)) {
    cout << 0;
    return 0;
  }
  a++;
  int w = log2(b);
  w++;
  cout << _count_2(a, w) - (w == 1 ? 1 : 0) << "\n";
}

```