#include <bits/stdc++.h>
using namespace std;
template <class F, class T>
T convert(F a, int p = -1) {
  stringstream ss;
  if (p >= 0) ss << fixed << setprecision(p);
  ss << a;
  T r;
  ss >> r;
  return r;
}
template <class T>
T gcd(T a, T b) {
  T r;
  while (b != 0) {
    r = a % b;
    a = b;
    b = r;
  }
  return a;
}
template <class T>
T lcm(T a, T b) {
  return a / gcd(a, b) * b;
}
template <class T>
T sqr(T x) {
  return x * x;
}
template <class T>
T cube(T x) {
  return x * x * x;
}
template <class T>
int getbit(T s, int i) {
  return (s >> i) & 1;
}
template <class T>
T onbit(T s, int i) {
  return s | (T(1) << i);
}
template <class T>
T offbit(T s, int i) {
  return s & (~(T(1) << i));
}
template <class T>
int cntbit(T s) {
  return s == 0 ? 0 : cntbit(s >> 1) + (s & 1);
}
const int bfsz = 1 << 16;
char bf[bfsz + 5];
int rsz = 0;
int ptr = 0;
char gc() {
  if (rsz <= 0) {
    ptr = 0;
    rsz = (int)fread(bf, 1, bfsz, stdin);
    if (rsz <= 0) return EOF;
  }
  --rsz;
  return bf[ptr++];
}
void ga(char &c) {
  c = EOF;
  while (!isalpha(c)) c = gc();
}
int gs(char s[]) {
  int l = 0;
  char c = gc();
  while (isspace(c)) c = gc();
  while (c != EOF && !isspace(c)) {
    s[l++] = c;
    c = gc();
  }
  s[l] = '\0';
  return l;
}
template <class T>
bool gi(T &v) {
  v = 0;
  char c = gc();
  while (c != EOF && c != '-' && !isdigit(c)) c = gc();
  if (c == EOF) return false;
  bool neg = c == '-';
  if (neg) c = gc();
  while (isdigit(c)) {
    v = v * 10 + c - '0';
    c = gc();
  }
  if (neg) v = -v;
  return true;
}
const long double PI = acos(-1.0);
const long double eps = 1e-9;
const int dr[] = {0, +1, 0, -1};
const int dc[] = {+1, 0, -1, 0};
const int inf = (int)1e9 + 5;
const long long linf = (long long)1e16 + 5;
const long long mod = (long long)1e9 + 7;
long long f[50][50], g[50][50];
long long n, t;
int cal(long long x) {
  for (int i = (0); i <= (45); ++i) {
    if ((1ll << i) == x) return i;
  }
  return -1;
}
long long go(long long x, int num) {
  if (x == 0) return 0;
  if (x == 1) {
    if (num == 0) return 1;
    return 0;
  }
  int d = 0;
  for (int i = (1); i <= (45); ++i) {
    if (x >= (1ll << i))
      d = i;
    else
      break;
  }
  long long res = 0;
  res += f[d + 1][num];
  if (num > 0) res += go(x - (1ll << d), num - 1);
  return res;
}
long long cal1(long long x, int num) {
  if (x == 0) return 0;
  if (x == 1) {
    if (num == 0) return 1;
    return 0;
  }
  int d = 0;
  for (int i = (2); i <= (45); ++i) {
    if (x >= (1ll << i) - 2)
      d = i;
    else
      break;
  }
  long long res = 0;
  for (int i = (1); i <= (d); ++i) res += f[i][num];
  res += go(min((1ll << (d - 1)), x - (1ll << d) + 2), num);
  if (x - (1ll << d) + 2 - (1ll << (d - 1)) > 0 && num > 0) {
    res += go(x - (1ll << d) + 2 - (1ll << (d - 1)), num - 1);
  }
  return res;
}
int main() {
  cin >> n >> t;
  memset(f, 0, sizeof(f));
  f[2][0] = 1;
  f[2][1] = 1;
  for (int i = (2); i <= (45); ++i) {
    for (int j = (0); j <= (45); ++j) {
      f[i + 1][j] += f[i][j];
      f[i + 1][j + 1] += f[i][j];
    }
  }
  int x = cal(t);
  if (x == -1) {
    cout << 0;
    return 0;
  }
  long long res = cal1(n, x);
  cout << res;
  return 0;
}

### Prompt

Please provide a cpp coded solution 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;
template <class F, class T>
T convert(F a, int p = -1) {
  stringstream ss;
  if (p >= 0) ss << fixed << setprecision(p);
  ss << a;
  T r;
  ss >> r;
  return r;
}
template <class T>
T gcd(T a, T b) {
  T r;
  while (b != 0) {
    r = a % b;
    a = b;
    b = r;
  }
  return a;
}
template <class T>
T lcm(T a, T b) {
  return a / gcd(a, b) * b;
}
template <class T>
T sqr(T x) {
  return x * x;
}
template <class T>
T cube(T x) {
  return x * x * x;
}
template <class T>
int getbit(T s, int i) {
  return (s >> i) & 1;
}
template <class T>
T onbit(T s, int i) {
  return s | (T(1) << i);
}
template <class T>
T offbit(T s, int i) {
  return s & (~(T(1) << i));
}
template <class T>
int cntbit(T s) {
  return s == 0 ? 0 : cntbit(s >> 1) + (s & 1);
}
const int bfsz = 1 << 16;
char bf[bfsz + 5];
int rsz = 0;
int ptr = 0;
char gc() {
  if (rsz <= 0) {
    ptr = 0;
    rsz = (int)fread(bf, 1, bfsz, stdin);
    if (rsz <= 0) return EOF;
  }
  --rsz;
  return bf[ptr++];
}
void ga(char &c) {
  c = EOF;
  while (!isalpha(c)) c = gc();
}
int gs(char s[]) {
  int l = 0;
  char c = gc();
  while (isspace(c)) c = gc();
  while (c != EOF && !isspace(c)) {
    s[l++] = c;
    c = gc();
  }
  s[l] = '\0';
  return l;
}
template <class T>
bool gi(T &v) {
  v = 0;
  char c = gc();
  while (c != EOF && c != '-' && !isdigit(c)) c = gc();
  if (c == EOF) return false;
  bool neg = c == '-';
  if (neg) c = gc();
  while (isdigit(c)) {
    v = v * 10 + c - '0';
    c = gc();
  }
  if (neg) v = -v;
  return true;
}
const long double PI = acos(-1.0);
const long double eps = 1e-9;
const int dr[] = {0, +1, 0, -1};
const int dc[] = {+1, 0, -1, 0};
const int inf = (int)1e9 + 5;
const long long linf = (long long)1e16 + 5;
const long long mod = (long long)1e9 + 7;
long long f[50][50], g[50][50];
long long n, t;
int cal(long long x) {
  for (int i = (0); i <= (45); ++i) {
    if ((1ll << i) == x) return i;
  }
  return -1;
}
long long go(long long x, int num) {
  if (x == 0) return 0;
  if (x == 1) {
    if (num == 0) return 1;
    return 0;
  }
  int d = 0;
  for (int i = (1); i <= (45); ++i) {
    if (x >= (1ll << i))
      d = i;
    else
      break;
  }
  long long res = 0;
  res += f[d + 1][num];
  if (num > 0) res += go(x - (1ll << d), num - 1);
  return res;
}
long long cal1(long long x, int num) {
  if (x == 0) return 0;
  if (x == 1) {
    if (num == 0) return 1;
    return 0;
  }
  int d = 0;
  for (int i = (2); i <= (45); ++i) {
    if (x >= (1ll << i) - 2)
      d = i;
    else
      break;
  }
  long long res = 0;
  for (int i = (1); i <= (d); ++i) res += f[i][num];
  res += go(min((1ll << (d - 1)), x - (1ll << d) + 2), num);
  if (x - (1ll << d) + 2 - (1ll << (d - 1)) > 0 && num > 0) {
    res += go(x - (1ll << d) + 2 - (1ll << (d - 1)), num - 1);
  }
  return res;
}
int main() {
  cin >> n >> t;
  memset(f, 0, sizeof(f));
  f[2][0] = 1;
  f[2][1] = 1;
  for (int i = (2); i <= (45); ++i) {
    for (int j = (0); j <= (45); ++j) {
      f[i + 1][j] += f[i][j];
      f[i + 1][j + 1] += f[i][j];
    }
  }
  int x = cal(t);
  if (x == -1) {
    cout << 0;
    return 0;
  }
  long long res = cal1(n, x);
  cout << res;
  return 0;
}

```