#include <bits/stdc++.h>
using namespace std;
long long dp[64][4];
int main() {
  long long n;
  cin >> n;
  long long d[64];
  memset((d), (0), sizeof(d));
  for (long long i = (0); i < (64); ++i) {
    if (((n >> i) & 1) == 1) {
      d[63 - i] = 1;
    }
  }
  memset((dp), (0), sizeof(dp));
  dp[0][0] = 1;
  for (long long i = (1); i < (64); ++i) {
    if (d[i] == 1) {
      dp[i][0] += dp[i - 1][0];
      dp[i][1] += dp[i - 1][0];
      dp[i][2] += dp[i - 1][1] * 3;
      dp[i][2] += dp[i - 1][2] * 3;
      dp[i][3] += dp[i - 1][3];
    } else {
      dp[i][0] += dp[i - 1][0];
      dp[i][2] += dp[i - 1][1] * 2;
      dp[i][3] += dp[i - 1][1];
      dp[i][2] += dp[i - 1][2] * 3;
      dp[i][3] += dp[i - 1][3];
    }
  }
  long long ans = dp[63][0] + dp[63][1] + dp[63][2] + dp[63][3];
  cout << ans << endl;
  return 0;
}
