#include <bits/stdc++.h>
#pragma comment(linker, "/stack:128000000")
using namespace std;
const int INF = 1000000000;
const long long LINF = 4000000000000000000LL;
const double eps = 1e-9;
void prepare() {}
const int maxn = 255;
long long n, t;
int a[maxn][maxn];
bool read() {
  cin >> n >> t;
  return false;
}
void gen(int m) {
  for (int j = (1); j < (m + 1); j++) a[1][j] = 0;
  a[1][m + 1] = 1;
  for (int i = (2); i < (m + 2); i++) {
    for (int j = (1); j < (m + 2); 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 stupid() {
  memset((a), (0), sizeof(a));
  int ret = 0;
  for (int m = (1); m < (n + 1); m++) {
    gen(m);
    long long s = 0;
    for (int i = (1); i < (m + 5); i++) s += a[m + 1][i];
    if (s == t) ret++;
  }
  return ret;
}
map<pair<long long, long long>, long long> dp;
long long calc(long long len, long long t) {
  if (len == 0) return 0;
  if (len == 1 && t == 1) return 1;
  pair<long long, long long> p = make_pair(len, t);
  if (dp.find(p) != dp.end()) return dp[p];
  long long ret = calc(len / 2, t);
  if (t % 2 == 0) ret += calc(len / 2, t / 2);
  return dp[p] = ret;
}
void gen() {
  n = rand() % 50 + 1;
  t = rand() % 50 + 1;
}
void solve() {
  long long ot = t;
  dp.clear();
  long long len = 1, total = 0;
  long long ans = 0;
  while (true) {
    if (total + len > n + 1) break;
    ans += calc(len, t);
    total += len;
    len *= 2;
  }
  while (true) {
    while (len > 0 && total + len > n + 1) len /= 2;
    if (len == 0) break;
    ans += calc(len, t);
    total += len;
    len /= 2;
    if (t & 1) break;
    t /= 2;
  }
  if (ot == 1) ans--;
  cout << ans << endl;
  return;
  gen(50);
  for (int i = (0); i < (((70))); i++) {
    for (int j = (0); j < (((70))); j++) printf("%c", a[i][j] ? 'x' : ' ');
    printf("\n");
  }
  printf("%d\n", stupid());
}
int main() {
  prepare();
  int ntests = 1;
  for (int i = (0); i < (((ntests))); i++) {
    read();
    solve();
  }
  return 0;
}

### Prompt

Your task is to create 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>
#pragma comment(linker, "/stack:128000000")
using namespace std;
const int INF = 1000000000;
const long long LINF = 4000000000000000000LL;
const double eps = 1e-9;
void prepare() {}
const int maxn = 255;
long long n, t;
int a[maxn][maxn];
bool read() {
  cin >> n >> t;
  return false;
}
void gen(int m) {
  for (int j = (1); j < (m + 1); j++) a[1][j] = 0;
  a[1][m + 1] = 1;
  for (int i = (2); i < (m + 2); i++) {
    for (int j = (1); j < (m + 2); 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 stupid() {
  memset((a), (0), sizeof(a));
  int ret = 0;
  for (int m = (1); m < (n + 1); m++) {
    gen(m);
    long long s = 0;
    for (int i = (1); i < (m + 5); i++) s += a[m + 1][i];
    if (s == t) ret++;
  }
  return ret;
}
map<pair<long long, long long>, long long> dp;
long long calc(long long len, long long t) {
  if (len == 0) return 0;
  if (len == 1 && t == 1) return 1;
  pair<long long, long long> p = make_pair(len, t);
  if (dp.find(p) != dp.end()) return dp[p];
  long long ret = calc(len / 2, t);
  if (t % 2 == 0) ret += calc(len / 2, t / 2);
  return dp[p] = ret;
}
void gen() {
  n = rand() % 50 + 1;
  t = rand() % 50 + 1;
}
void solve() {
  long long ot = t;
  dp.clear();
  long long len = 1, total = 0;
  long long ans = 0;
  while (true) {
    if (total + len > n + 1) break;
    ans += calc(len, t);
    total += len;
    len *= 2;
  }
  while (true) {
    while (len > 0 && total + len > n + 1) len /= 2;
    if (len == 0) break;
    ans += calc(len, t);
    total += len;
    len /= 2;
    if (t & 1) break;
    t /= 2;
  }
  if (ot == 1) ans--;
  cout << ans << endl;
  return;
  gen(50);
  for (int i = (0); i < (((70))); i++) {
    for (int j = (0); j < (((70))); j++) printf("%c", a[i][j] ? 'x' : ' ');
    printf("\n");
  }
  printf("%d\n", stupid());
}
int main() {
  prepare();
  int ntests = 1;
  for (int i = (0); i < (((ntests))); i++) {
    read();
    solve();
  }
  return 0;
}

```