#include <bits/stdc++.h>
using namespace std;
template <typename T>
T in() {
  char ch;
  T n = 0;
  bool ng = false;
  while (1) {
    ch = getchar();
    if (ch == '-') {
      ng = true;
      ch = getchar();
      break;
    }
    if (ch >= '0' && ch <= '9') break;
  }
  while (1) {
    n = n * 10 + (ch - '0');
    ch = getchar();
    if (ch < '0' || ch > '9') break;
  }
  return (ng ? -n : n);
}
template <typename T>
inline T Dist(T x1, T y1, T x2, T y2) {
  return sqrt((x1 - x2 * x1 - x2) + (y1 - y2 * y1 - y2));
}
template <typename T>
inline T POW(T B, T P) {
  if (P == 0) return 1;
  if (P & 1)
    return B * POW(B, P - 1);
  else
    return (POW(B, P / 2) * POW(B, P / 2));
}
template <typename T>
inline T ABS(T a) {
  if (a < 0)
    return -a;
  else
    return a;
}
template <typename T>
inline T Gcd(T a, T b) {
  if (a < 0) return Gcd(-a, b);
  if (b < 0) return Gcd(a, -b);
  return (b == 0) ? a : Gcd(b, a % b);
}
template <typename T>
inline T Lcm(T a, T b) {
  if (a < 0) return Lcm(-a, b);
  if (b < 0) return Lcm(a, -b);
  return a * (b / Gcd(a, b));
}
long long Bigmod(long long base, long long power, long long MOD) {
  long long ret = 1;
  while (power) {
    if (power & 1) ret = (ret * base) % MOD;
    base = (base * base) % MOD;
    power >>= 1;
  }
  return ret;
}
long long ModInverse(long long number, long long MOD) {
  return Bigmod(number, MOD - 2, MOD);
}
int Set(int N, int pos) { return N = N | (1 << pos); }
int Reset(int N, int pos) { return N = N & ~(1 << pos); }
bool Chkbit(int N, int pos) { return (bool)(N & (1 << pos)); }
bool isVowel(char ch) {
  ch = toupper(ch);
  if (ch == 'A' || ch == 'U' || ch == 'I' || ch == 'O' || ch == 'E')
    return true;
  return false;
}
bool isConst(char ch) {
  if (isalpha(ch) && !isVowel(ch)) return true;
  return false;
}
int toInt(string s) {
  int sm;
  stringstream ss(s);
  ss >> sm;
  return sm;
}
long long int toLlint(string s) {
  long long int sm;
  stringstream ss(s);
  ss >> sm;
  return sm;
}
vector<int> A[400007];
int a[100][100];
int Solve(int m) {
  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++) {
      if (j == 1) {
        a[i][j] = a[i - 1][j + 1];
      } else {
        if (j == m + 1) {
          a[i][j] = a[i - 1][j - 1];
        } else {
          a[i][j] = (a[i - 1][j - 1] ^ a[i - 1][j + 1]);
        }
      }
    }
  }
  int tot = 0;
  for (int i = 1; i < m + 2; i++) tot += a[m + 1][i];
  return tot;
}
int ar[200];
long long int n, t, Pw[200], dp[100][100][2];
int L;
void Make_array() {
  L = 0;
  Pw[0] = 1;
  for (int i = 1; i < 64; i++) {
    Pw[i] = Pw[i - 1] * 2;
  }
  while (n) {
    ar[L++] = n % 2;
    n /= 2;
  }
  reverse(ar, ar + L);
}
long long int Call(int pos, int one, int ch) {
  if (pos == L) {
    if (one)
      return (Pw[one - 1] == t);
    else
      return 0;
  }
  long long int &res = dp[pos][one][ch];
  if (res != -1) return res;
  res = 0LL;
  int h = ar[pos];
  if (ch) h = 1;
  for (int i = 0; i < h + 1; i++) {
    res += Call(pos + 1, one + (i == 1), ch | (i < ar[pos]));
  }
  return res;
}
int main() {
  cin >> n >> t;
  if (t & (t - 1LL)) {
    cout << 0 << endl;
    return 0;
  }
  n++;
  Make_array();
  memset(dp, -1, sizeof(dp));
  long long int ans = Call(0, 0, 0);
  if (t == 1) ans--;
  cout << ans << endl;
  return 0;
}

### Prompt

Please formulate a Cpp solution 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;
template <typename T>
T in() {
  char ch;
  T n = 0;
  bool ng = false;
  while (1) {
    ch = getchar();
    if (ch == '-') {
      ng = true;
      ch = getchar();
      break;
    }
    if (ch >= '0' && ch <= '9') break;
  }
  while (1) {
    n = n * 10 + (ch - '0');
    ch = getchar();
    if (ch < '0' || ch > '9') break;
  }
  return (ng ? -n : n);
}
template <typename T>
inline T Dist(T x1, T y1, T x2, T y2) {
  return sqrt((x1 - x2 * x1 - x2) + (y1 - y2 * y1 - y2));
}
template <typename T>
inline T POW(T B, T P) {
  if (P == 0) return 1;
  if (P & 1)
    return B * POW(B, P - 1);
  else
    return (POW(B, P / 2) * POW(B, P / 2));
}
template <typename T>
inline T ABS(T a) {
  if (a < 0)
    return -a;
  else
    return a;
}
template <typename T>
inline T Gcd(T a, T b) {
  if (a < 0) return Gcd(-a, b);
  if (b < 0) return Gcd(a, -b);
  return (b == 0) ? a : Gcd(b, a % b);
}
template <typename T>
inline T Lcm(T a, T b) {
  if (a < 0) return Lcm(-a, b);
  if (b < 0) return Lcm(a, -b);
  return a * (b / Gcd(a, b));
}
long long Bigmod(long long base, long long power, long long MOD) {
  long long ret = 1;
  while (power) {
    if (power & 1) ret = (ret * base) % MOD;
    base = (base * base) % MOD;
    power >>= 1;
  }
  return ret;
}
long long ModInverse(long long number, long long MOD) {
  return Bigmod(number, MOD - 2, MOD);
}
int Set(int N, int pos) { return N = N | (1 << pos); }
int Reset(int N, int pos) { return N = N & ~(1 << pos); }
bool Chkbit(int N, int pos) { return (bool)(N & (1 << pos)); }
bool isVowel(char ch) {
  ch = toupper(ch);
  if (ch == 'A' || ch == 'U' || ch == 'I' || ch == 'O' || ch == 'E')
    return true;
  return false;
}
bool isConst(char ch) {
  if (isalpha(ch) && !isVowel(ch)) return true;
  return false;
}
int toInt(string s) {
  int sm;
  stringstream ss(s);
  ss >> sm;
  return sm;
}
long long int toLlint(string s) {
  long long int sm;
  stringstream ss(s);
  ss >> sm;
  return sm;
}
vector<int> A[400007];
int a[100][100];
int Solve(int m) {
  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++) {
      if (j == 1) {
        a[i][j] = a[i - 1][j + 1];
      } else {
        if (j == m + 1) {
          a[i][j] = a[i - 1][j - 1];
        } else {
          a[i][j] = (a[i - 1][j - 1] ^ a[i - 1][j + 1]);
        }
      }
    }
  }
  int tot = 0;
  for (int i = 1; i < m + 2; i++) tot += a[m + 1][i];
  return tot;
}
int ar[200];
long long int n, t, Pw[200], dp[100][100][2];
int L;
void Make_array() {
  L = 0;
  Pw[0] = 1;
  for (int i = 1; i < 64; i++) {
    Pw[i] = Pw[i - 1] * 2;
  }
  while (n) {
    ar[L++] = n % 2;
    n /= 2;
  }
  reverse(ar, ar + L);
}
long long int Call(int pos, int one, int ch) {
  if (pos == L) {
    if (one)
      return (Pw[one - 1] == t);
    else
      return 0;
  }
  long long int &res = dp[pos][one][ch];
  if (res != -1) return res;
  res = 0LL;
  int h = ar[pos];
  if (ch) h = 1;
  for (int i = 0; i < h + 1; i++) {
    res += Call(pos + 1, one + (i == 1), ch | (i < ar[pos]));
  }
  return res;
}
int main() {
  cin >> n >> t;
  if (t & (t - 1LL)) {
    cout << 0 << endl;
    return 0;
  }
  n++;
  Make_array();
  memset(dp, -1, sizeof(dp));
  long long int ans = Call(0, 0, 0);
  if (t == 1) ans--;
  cout << ans << endl;
  return 0;
}

```