#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > generate(int M) {
  vector<vector<int> > A(M + 2, vector<int>(M + 2, 0));
  for (int j = (1); j <= (M); ++j) A[1][j] = 0;
  A[1][M + 1] = 1;
  for (int i = (2); i <= (M + 1); ++i) {
    for (int j = (1); j <= (M + 1); ++j) {
      A[i][j] =
          ((j > 1) ? A[i - 1][j - 1] : 0) ^ ((j < M + 1) ? A[i - 1][j + 1] : 0);
    }
  }
  return A;
}
void print(const vector<vector<int> >& A) {
  int M = A.size() - 2;
  for (int i = (1); i <= (M + 1); ++i) {
    int ones = 0;
    for (int j = (1); j <= (M + 1); ++j)
      cout << A[i][j] << " ", ones += (A[i][j]);
    cout << "   " << ones;
    cout << endl;
  }
  cout << endl;
}
long long sz(long long g) { return (g + 1) / 2; }
long long guy(int i) {
  assert(i >= 1);
  return (1ll << i) - 1;
}
long long fl(long long n) {
  assert(n > 1);
  for (int i = 1;; ++i)
    if (guy(i) >= n) return guy(i - 1);
}
map<long long, map<long long, map<long long, long long> > > d;
long long D(long long n, long long k, long long t) {
  if (d[n][k].count(t)) return d[n][k][t];
  if (k == 0) return d[n][k][t] = 0;
  if (n == 1 && t == 1) return d[n][k][t] = 1;
  if (n == 1) return d[n][k][t] = 0;
  long long fln = fl(n);
  long long szfl = sz(fln);
  if (k <= szfl) {
    return d[n][k][t] = D(fln, k, t);
  } else {
    return d[n][k][t] = D(fln, szfl, t) + D(fln, k - szfl, t / 2);
  }
}
bool is_pw2(long long t) { return __builtin_popcount(t) == 1; }
int main() {
  long long N, T;
  cin >> N >> T;
  if (!is_pw2(T)) {
    cout << 0 << endl;
    return 0;
  }
  N++;
  long long fln = fl(N);
  long long diff = N - fln;
  long long ans = D(N, diff, T);
  for (N = fln; N > 1; N = (N - 1) / 2) {
    ans += D(N, sz(N), T);
  }
  cout << ans << endl;
  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;
vector<vector<int> > generate(int M) {
  vector<vector<int> > A(M + 2, vector<int>(M + 2, 0));
  for (int j = (1); j <= (M); ++j) A[1][j] = 0;
  A[1][M + 1] = 1;
  for (int i = (2); i <= (M + 1); ++i) {
    for (int j = (1); j <= (M + 1); ++j) {
      A[i][j] =
          ((j > 1) ? A[i - 1][j - 1] : 0) ^ ((j < M + 1) ? A[i - 1][j + 1] : 0);
    }
  }
  return A;
}
void print(const vector<vector<int> >& A) {
  int M = A.size() - 2;
  for (int i = (1); i <= (M + 1); ++i) {
    int ones = 0;
    for (int j = (1); j <= (M + 1); ++j)
      cout << A[i][j] << " ", ones += (A[i][j]);
    cout << "   " << ones;
    cout << endl;
  }
  cout << endl;
}
long long sz(long long g) { return (g + 1) / 2; }
long long guy(int i) {
  assert(i >= 1);
  return (1ll << i) - 1;
}
long long fl(long long n) {
  assert(n > 1);
  for (int i = 1;; ++i)
    if (guy(i) >= n) return guy(i - 1);
}
map<long long, map<long long, map<long long, long long> > > d;
long long D(long long n, long long k, long long t) {
  if (d[n][k].count(t)) return d[n][k][t];
  if (k == 0) return d[n][k][t] = 0;
  if (n == 1 && t == 1) return d[n][k][t] = 1;
  if (n == 1) return d[n][k][t] = 0;
  long long fln = fl(n);
  long long szfl = sz(fln);
  if (k <= szfl) {
    return d[n][k][t] = D(fln, k, t);
  } else {
    return d[n][k][t] = D(fln, szfl, t) + D(fln, k - szfl, t / 2);
  }
}
bool is_pw2(long long t) { return __builtin_popcount(t) == 1; }
int main() {
  long long N, T;
  cin >> N >> T;
  if (!is_pw2(T)) {
    cout << 0 << endl;
    return 0;
  }
  N++;
  long long fln = fl(N);
  long long diff = N - fln;
  long long ans = D(N, diff, T);
  for (N = fln; N > 1; N = (N - 1) / 2) {
    ans += D(N, sz(N), T);
  }
  cout << ans << endl;
  return 0;
}

```