#include <bits/stdc++.h>
using namespace std;
int ctz(long long x) {
  if (x == 0) return 64;
  int n = 0;
  if ((x & 0x00000000FFFFFFFFLL) == 0) n |= 32, x >>= 32;
  if ((x & 0x000000000000FFFFLL) == 0) n |= 16, x >>= 16;
  if ((x & 0x00000000000000FFLL) == 0) n |= 8, x >>= 8;
  if ((x & 0x000000000000000FLL) == 0) n |= 4, x >>= 4;
  if ((x & 0x0000000000000003LL) == 0) n |= 2, x >>= 2;
  if ((x & 0x0000000000000001LL) == 0) n |= 1;
  return n;
}
int popcount(long long x) {
  x -= (x >> 1) & 0x5555555555555555LL;
  x = (x & 0x3333333333333333LL) + (x >> 2 & 0x3333333333333333LL);
  x = (x + (x >> 4)) & 0x0F0F0F0F0F0F0F0FLL;
  x += x >> 8;
  x += x >> 16;
  x += x >> 32;
  return x & 0xFF;
}
const int NUM = 64;
long long comb[NUM + 1][NUM + 1];
void make_comb() {
  comb[0][0] = 1;
  for (int i = 1; i <= NUM; i++) {
    comb[i][0] = 1;
    for (int j = 1; j <= NUM; j++) {
      comb[i][j] = comb[i - 1][j - 1] + comb[i - 1][j];
    }
  }
}
long long calc(long long H, int T) {
  if (T == 0) return 1;
  if (H <= 1) return 0;
  int p;
  for (p = 0; (1LL << p) <= H; p++)
    ;
  p--;
  return comb[p][T] + calc(H - (1LL << p), T - 1);
}
int main() {
  make_comb();
  long long N, T;
  int t;
  cin >> N >> T;
  long long ans = 0;
  if (popcount(T) > 1) {
    puts("0");
    return 0;
  }
  t = ctz(T);
  for (int p = 1;; p++) {
    if ((1LL << p) > N) {
      ans += calc(N, t);
      break;
    } else {
      N -= 1LL << p;
      ans += comb[p][t];
    }
  }
  cout << ans << endl;
  return 0;
}

### Prompt

Please create a solution in cpp 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;
int ctz(long long x) {
  if (x == 0) return 64;
  int n = 0;
  if ((x & 0x00000000FFFFFFFFLL) == 0) n |= 32, x >>= 32;
  if ((x & 0x000000000000FFFFLL) == 0) n |= 16, x >>= 16;
  if ((x & 0x00000000000000FFLL) == 0) n |= 8, x >>= 8;
  if ((x & 0x000000000000000FLL) == 0) n |= 4, x >>= 4;
  if ((x & 0x0000000000000003LL) == 0) n |= 2, x >>= 2;
  if ((x & 0x0000000000000001LL) == 0) n |= 1;
  return n;
}
int popcount(long long x) {
  x -= (x >> 1) & 0x5555555555555555LL;
  x = (x & 0x3333333333333333LL) + (x >> 2 & 0x3333333333333333LL);
  x = (x + (x >> 4)) & 0x0F0F0F0F0F0F0F0FLL;
  x += x >> 8;
  x += x >> 16;
  x += x >> 32;
  return x & 0xFF;
}
const int NUM = 64;
long long comb[NUM + 1][NUM + 1];
void make_comb() {
  comb[0][0] = 1;
  for (int i = 1; i <= NUM; i++) {
    comb[i][0] = 1;
    for (int j = 1; j <= NUM; j++) {
      comb[i][j] = comb[i - 1][j - 1] + comb[i - 1][j];
    }
  }
}
long long calc(long long H, int T) {
  if (T == 0) return 1;
  if (H <= 1) return 0;
  int p;
  for (p = 0; (1LL << p) <= H; p++)
    ;
  p--;
  return comb[p][T] + calc(H - (1LL << p), T - 1);
}
int main() {
  make_comb();
  long long N, T;
  int t;
  cin >> N >> T;
  long long ans = 0;
  if (popcount(T) > 1) {
    puts("0");
    return 0;
  }
  t = ctz(T);
  for (int p = 1;; p++) {
    if ((1LL << p) > N) {
      ans += calc(N, t);
      break;
    } else {
      N -= 1LL << p;
      ans += comb[p][t];
    }
  }
  cout << ans << endl;
  return 0;
}

```