#include <bits/stdc++.h>
using namespace std;
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { cerr << '\n'; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
template <typename A, typename B>
istream& operator>>(istream& input, pair<A, B>& x) {
  input >> x.first >> x.second;
  return input;
}
template <typename A>
istream& operator>>(istream& input, vector<A>& x) {
  for (auto& i : x) input >> i;
  return input;
}
long long dp[45][45][2];
void solve() {
  long long n, t, T;
  cin >> n >> t;
  T = t;
  int b = 0;
  while (t % 2 == 0) {
    b++;
    t /= 2;
  }
  if ((1LL << b) != T) {
    cout << 0;
    return;
  }
  b++;
  n++;
  for (int i = 0; i < 45; i++) {
    if (i == 0) {
      dp[i][0][0] = 1;
      dp[i][1][0] = 1;
      if (1 & n) {
        dp[i][0][1] = 1;
        dp[i][1][1] = 1;
      } else {
        dp[i][0][1] = 1;
        dp[i][1][1] = 0;
      }
      continue;
    }
    for (int j = 0; j < 45; j++) {
      if (j > i + 1) continue;
      if (j == 0) {
        dp[i][j][0] = dp[i][j][1] = 1;
        continue;
      }
      dp[i][j][0] = dp[i - 1][j][0] + dp[i - 1][j - 1][0];
      if (1 & (n >> i))
        dp[i][j][1] = dp[i - 1][j][0] + dp[i - 1][j - 1][1];
      else
        dp[i][j][1] = dp[i - 1][j][1];
    }
  }
  long long res = dp[44][b][1];
  if (b <= 1) res--;
  cout << res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}

### Prompt

Generate 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;
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { cerr << '\n'; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
template <typename A, typename B>
istream& operator>>(istream& input, pair<A, B>& x) {
  input >> x.first >> x.second;
  return input;
}
template <typename A>
istream& operator>>(istream& input, vector<A>& x) {
  for (auto& i : x) input >> i;
  return input;
}
long long dp[45][45][2];
void solve() {
  long long n, t, T;
  cin >> n >> t;
  T = t;
  int b = 0;
  while (t % 2 == 0) {
    b++;
    t /= 2;
  }
  if ((1LL << b) != T) {
    cout << 0;
    return;
  }
  b++;
  n++;
  for (int i = 0; i < 45; i++) {
    if (i == 0) {
      dp[i][0][0] = 1;
      dp[i][1][0] = 1;
      if (1 & n) {
        dp[i][0][1] = 1;
        dp[i][1][1] = 1;
      } else {
        dp[i][0][1] = 1;
        dp[i][1][1] = 0;
      }
      continue;
    }
    for (int j = 0; j < 45; j++) {
      if (j > i + 1) continue;
      if (j == 0) {
        dp[i][j][0] = dp[i][j][1] = 1;
        continue;
      }
      dp[i][j][0] = dp[i - 1][j][0] + dp[i - 1][j - 1][0];
      if (1 & (n >> i))
        dp[i][j][1] = dp[i - 1][j][0] + dp[i - 1][j - 1][1];
      else
        dp[i][j][1] = dp[i - 1][j][1];
    }
  }
  long long res = dp[44][b][1];
  if (b <= 1) res--;
  cout << res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}

```