#include <bits/stdc++.h>
using namespace std;
long long n;
long long dp[63][2][2][2];
int main(void) {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i <= 62; i++) {
    for (int j = 0; j < 2; j++) {
      for (int k = 0; k < 2; k++) {
        for (int l = 0; l < 2; l++) {
          dp[i][j][k][l] = 0;
        }
      }
    }
  }
  dp[0][0][0][0] = 1;
  for (int i = 0; i < 62; i++) {
    for (int j = 0; j < 2; j++) {
      for (int k = 0; k < 2; k++) {
        for (int l = 0; l < 2; l++) {
          for (int s = 0; s < 2; s++) {
            for (int t = 0; t < 2; t++) {
              if (s == 1 && t == 0) continue;
              int u = s ^ t, v = (j + s + t) % 2;
              int nk = k, nl = l;
              if ((n & (1LL << i)) && u == 0) nk = 0;
              if (((n & (1LL << i)) == 0) && u == 1) nk = 1;
              if ((n & (1LL << i)) && v == 0) nl = 0;
              if (((n & (1LL << i)) == 0) && v == 1) nl = 1;
              dp[i + 1][(j + s + t) / 2][nk][nl] += dp[i][j][k][l];
            }
          }
        }
      }
    }
  }
  cout << dp[62][0][0][0] << endl;
  return 0;
}
