#include <bits/stdc++.h>
using namespace std;
long long pascal[64][64];
long long pow2[64];
void fill_pascal() {
  for (int i = 1; i < 64; ++i) pascal[0][i] = 0;
  for (int i = 0; i < 64; ++i) pascal[i][0] = 1;
  for (int i = 1, n = 0; i < 64; ++i, ++n) {
    for (int j = 1; j <= n; ++j) {
      pascal[i][j] = pascal[i - 1][j] + pascal[i - 1][j - 1];
    }
    pascal[i][n + 1] = 1;
    for (int j = n + 2; j < 64; ++j) pascal[i][j] = 0;
  }
}
void fill_pow2() {
  pow2[0] = 1;
  for (int i = 1; i < 64; ++i) pow2[i] = 2 * pow2[i - 1];
}
long long count_bounded_matrices(long long m, long long t) {
  long long* ptr = lower_bound(pow2, pow2 + 64, m);
  ptrdiff_t idx = distance(pow2, ptr);
  ;
  long long multiplier = 1, result = 0;
  long long lower = pow2[idx - 1], upper = pow2[idx];
  long long middle = lower + (upper - lower) / 2;
  ;
  while (middle != m) {
    if (m < middle) {
      upper = middle;
      middle = lower + (upper - lower) / 2;
    } else {
      long long row_count = middle - lower;
      long long* ptr2 = find(pow2, pow2 + 64, row_count);
      ptrdiff_t k = distance(pow2, ptr2);
      ;
      ;
      for (int i = 0; i <= k; ++i) {
        if (multiplier * pow2[i] == t) {
          ;
          result += pascal[k][i];
          break;
        }
      }
      multiplier *= 2;
      lower = middle;
      middle = lower + (upper - lower) / 2;
    };
  };
  long long row_count = middle - lower;
  long long* ptr2 = find(pow2, pow2 + 64, row_count);
  ptrdiff_t k = distance(pow2, ptr2);
  ;
  for (int i = 0; i <= k; ++i) {
    if (multiplier * pow2[i] == t) {
      result += pascal[k][i];
      break;
    }
  }
  multiplier *= 2;
  if (multiplier * pow2[0] == t) ++result;
  return result;
}
void print_pascal(int x) {
  x = min(64, x);
  for (int i = 0; i < x; ++i) {
    for (int j = 0; j < x; ++j) {
      cout << pascal[i][j] << " ";
    }
    cout << endl;
  }
  cout << endl;
}
int main() {
  fill_pascal();
  fill_pow2();
  long long n, t, result = 0;
  cin >> n >> t;
  long long* ptr = lower_bound(pow2, pow2 + 64, n + 1);
  ptrdiff_t idx = distance(pow2, ptr - 1);
  bool on_boundary = binary_search(pow2, pow2 + 64, n + 1);
  if (on_boundary) ++idx;
  ;
  for (int j = 0; j < idx; ++j) {
    if (t == pow2[j]) {
      for (int i = 0; i < idx; ++i) {
        result += pascal[i][j];
      }
      break;
    }
  };
  if (not on_boundary) {
    ;
    result += count_bounded_matrices(n + 1, t);
    if (t == 1) --result;
  }
  cout << result << endl;
}

### 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;
long long pascal[64][64];
long long pow2[64];
void fill_pascal() {
  for (int i = 1; i < 64; ++i) pascal[0][i] = 0;
  for (int i = 0; i < 64; ++i) pascal[i][0] = 1;
  for (int i = 1, n = 0; i < 64; ++i, ++n) {
    for (int j = 1; j <= n; ++j) {
      pascal[i][j] = pascal[i - 1][j] + pascal[i - 1][j - 1];
    }
    pascal[i][n + 1] = 1;
    for (int j = n + 2; j < 64; ++j) pascal[i][j] = 0;
  }
}
void fill_pow2() {
  pow2[0] = 1;
  for (int i = 1; i < 64; ++i) pow2[i] = 2 * pow2[i - 1];
}
long long count_bounded_matrices(long long m, long long t) {
  long long* ptr = lower_bound(pow2, pow2 + 64, m);
  ptrdiff_t idx = distance(pow2, ptr);
  ;
  long long multiplier = 1, result = 0;
  long long lower = pow2[idx - 1], upper = pow2[idx];
  long long middle = lower + (upper - lower) / 2;
  ;
  while (middle != m) {
    if (m < middle) {
      upper = middle;
      middle = lower + (upper - lower) / 2;
    } else {
      long long row_count = middle - lower;
      long long* ptr2 = find(pow2, pow2 + 64, row_count);
      ptrdiff_t k = distance(pow2, ptr2);
      ;
      ;
      for (int i = 0; i <= k; ++i) {
        if (multiplier * pow2[i] == t) {
          ;
          result += pascal[k][i];
          break;
        }
      }
      multiplier *= 2;
      lower = middle;
      middle = lower + (upper - lower) / 2;
    };
  };
  long long row_count = middle - lower;
  long long* ptr2 = find(pow2, pow2 + 64, row_count);
  ptrdiff_t k = distance(pow2, ptr2);
  ;
  for (int i = 0; i <= k; ++i) {
    if (multiplier * pow2[i] == t) {
      result += pascal[k][i];
      break;
    }
  }
  multiplier *= 2;
  if (multiplier * pow2[0] == t) ++result;
  return result;
}
void print_pascal(int x) {
  x = min(64, x);
  for (int i = 0; i < x; ++i) {
    for (int j = 0; j < x; ++j) {
      cout << pascal[i][j] << " ";
    }
    cout << endl;
  }
  cout << endl;
}
int main() {
  fill_pascal();
  fill_pow2();
  long long n, t, result = 0;
  cin >> n >> t;
  long long* ptr = lower_bound(pow2, pow2 + 64, n + 1);
  ptrdiff_t idx = distance(pow2, ptr - 1);
  bool on_boundary = binary_search(pow2, pow2 + 64, n + 1);
  if (on_boundary) ++idx;
  ;
  for (int j = 0; j < idx; ++j) {
    if (t == pow2[j]) {
      for (int i = 0; i < idx; ++i) {
        result += pascal[i][j];
      }
      break;
    }
  };
  if (not on_boundary) {
    ;
    result += count_bounded_matrices(n + 1, t);
    if (t == 1) --result;
  }
  cout << result << endl;
}

```