#include <bits/stdc++.h>
using namespace std;
class CDebug {
 public:
  template <typename T>
  CDebug &operator<<(T datum) {
    return *this;
  }
  typedef std::basic_ostream<char, std::char_traits<char> > &(*StandardEndLine)(
      std::basic_ostream<char, std::char_traits<char> > &);
  CDebug &operator<<(StandardEndLine manip) { return *this; }
} cdebug;
const int PN = 40;
void output(const long long int pascal[PN][PN], int n);
void output(const long long int *distib, int n);
void precalcPascal(long long int pascal[PN][PN], int n);
void sum(long long int *accumulator, const long long int *add, int n,
         int shift = 0);
int main() {
  long long int pascal[PN][PN] = {0};
  long long int distribution[PN] = {0};
  precalcPascal(pascal, PN);
  long long int n, t, result = 0;
  cin >> n >> t;
  unsigned long long int m = n + 1, single = 1;
  bool pow2 = true;
  for (int i = 0; i < 42 && pow2; ++i) {
    pow2 = pow2 && (t & (single << i) ? (t & (single << i)) == t : true);
  }
  if (pow2) {
    int highBit = 63, zeros = 0;
    cdebug << "m = " << m << endl;
    while (!(m & (single << highBit))) --highBit;
    cdebug << "highBit = " << highBit << endl;
    for (int curentBit = highBit; curentBit >= 0; --curentBit)
      zeros += (m & (single << curentBit)) ? 0 : 1;
    cdebug << "zeros = " << zeros << endl;
    if (zeros) --highBit;
    cdebug << "highBit = " << highBit << endl;
    cdebug << "initial distribution:\n";
    output(distribution, PN);
    for (int curentBit = highBit; curentBit >= 0; --curentBit) {
      m -= single << curentBit;
      sum(distribution, pascal[curentBit], PN);
    }
    while (!(m & (single << highBit)) && highBit >= 0) --highBit;
    cdebug << "highBit = " << highBit << endl;
    cdebug << "m = " << m << "\ndistribution:\n";
    output(distribution, PN);
    int shift = 0;
    while (m) {
      if (m & (single << highBit)) {
        sum(distribution, pascal[highBit], PN, shift);
        ++shift;
        m -= single << highBit;
      }
      --highBit;
    }
    cdebug << "m = " << m << "\ndistribution:\n";
    output(distribution, PN);
    --distribution[0];
    cdebug << "\n\nfinal distribution:\n";
    output(distribution, PN);
    highBit = 0;
    while (!(t & (single << highBit))) ++highBit;
    cdebug << "t = " << t << " highBit = " << highBit << endl;
    result = distribution[highBit];
  }
  cout << result;
  return 0;
}
void output(const long long int pascal[PN][PN], int n) {
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      cdebug << pascal[i][j] << " ";
    }
    cdebug << endl;
  }
}
void output(const long long int distib[PN], int n) {
  for (int j = 0; j <= n / 8; ++j) {
    for (int i = 0; i < 8 && (j * 8 + i) < n; ++i) {
      cdebug << setw(16) << (1ll << (j * 8 + i));
    }
    cdebug << endl;
    for (int i = 0; i < 8 && (j * 8 + i) < n; ++i) {
      cdebug << setw(16) << distib[j * 8 + i];
    }
    cdebug << endl;
    cdebug << endl;
  }
}
void precalcPascal(long long int pascal[PN][PN], int n) {
  pascal[0][0] = 1;
  for (int i = 1; i < n; ++i) {
    pascal[i][0] = 1;
    for (int j = 1; j < n; ++j) {
      pascal[i][j] = pascal[i - 1][j - 1] + pascal[i - 1][j];
    }
  }
}
void sum(long long int *accumulator, const long long int *add, int n,
         int shift) {
  if (shift < 0) return;
  for (int i = shift; i < n; ++i) {
    accumulator[i] += add[i - shift];
  }
}

### 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;
class CDebug {
 public:
  template <typename T>
  CDebug &operator<<(T datum) {
    return *this;
  }
  typedef std::basic_ostream<char, std::char_traits<char> > &(*StandardEndLine)(
      std::basic_ostream<char, std::char_traits<char> > &);
  CDebug &operator<<(StandardEndLine manip) { return *this; }
} cdebug;
const int PN = 40;
void output(const long long int pascal[PN][PN], int n);
void output(const long long int *distib, int n);
void precalcPascal(long long int pascal[PN][PN], int n);
void sum(long long int *accumulator, const long long int *add, int n,
         int shift = 0);
int main() {
  long long int pascal[PN][PN] = {0};
  long long int distribution[PN] = {0};
  precalcPascal(pascal, PN);
  long long int n, t, result = 0;
  cin >> n >> t;
  unsigned long long int m = n + 1, single = 1;
  bool pow2 = true;
  for (int i = 0; i < 42 && pow2; ++i) {
    pow2 = pow2 && (t & (single << i) ? (t & (single << i)) == t : true);
  }
  if (pow2) {
    int highBit = 63, zeros = 0;
    cdebug << "m = " << m << endl;
    while (!(m & (single << highBit))) --highBit;
    cdebug << "highBit = " << highBit << endl;
    for (int curentBit = highBit; curentBit >= 0; --curentBit)
      zeros += (m & (single << curentBit)) ? 0 : 1;
    cdebug << "zeros = " << zeros << endl;
    if (zeros) --highBit;
    cdebug << "highBit = " << highBit << endl;
    cdebug << "initial distribution:\n";
    output(distribution, PN);
    for (int curentBit = highBit; curentBit >= 0; --curentBit) {
      m -= single << curentBit;
      sum(distribution, pascal[curentBit], PN);
    }
    while (!(m & (single << highBit)) && highBit >= 0) --highBit;
    cdebug << "highBit = " << highBit << endl;
    cdebug << "m = " << m << "\ndistribution:\n";
    output(distribution, PN);
    int shift = 0;
    while (m) {
      if (m & (single << highBit)) {
        sum(distribution, pascal[highBit], PN, shift);
        ++shift;
        m -= single << highBit;
      }
      --highBit;
    }
    cdebug << "m = " << m << "\ndistribution:\n";
    output(distribution, PN);
    --distribution[0];
    cdebug << "\n\nfinal distribution:\n";
    output(distribution, PN);
    highBit = 0;
    while (!(t & (single << highBit))) ++highBit;
    cdebug << "t = " << t << " highBit = " << highBit << endl;
    result = distribution[highBit];
  }
  cout << result;
  return 0;
}
void output(const long long int pascal[PN][PN], int n) {
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      cdebug << pascal[i][j] << " ";
    }
    cdebug << endl;
  }
}
void output(const long long int distib[PN], int n) {
  for (int j = 0; j <= n / 8; ++j) {
    for (int i = 0; i < 8 && (j * 8 + i) < n; ++i) {
      cdebug << setw(16) << (1ll << (j * 8 + i));
    }
    cdebug << endl;
    for (int i = 0; i < 8 && (j * 8 + i) < n; ++i) {
      cdebug << setw(16) << distib[j * 8 + i];
    }
    cdebug << endl;
    cdebug << endl;
  }
}
void precalcPascal(long long int pascal[PN][PN], int n) {
  pascal[0][0] = 1;
  for (int i = 1; i < n; ++i) {
    pascal[i][0] = 1;
    for (int j = 1; j < n; ++j) {
      pascal[i][j] = pascal[i - 1][j - 1] + pascal[i - 1][j];
    }
  }
}
void sum(long long int *accumulator, const long long int *add, int n,
         int shift) {
  if (shift < 0) return;
  for (int i = shift; i < n; ++i) {
    accumulator[i] += add[i - shift];
  }
}

```