#include <bits/stdc++.h>
using namespace std;
std::vector<long long> v(61), w(61);
const long long INF = 1e9 + 7;
long long dfs(long long S, long long X) {
  if (S < 0) return 0;
  if (S > (v[X] - 1) * 2) return w[X];
  if (S == 0 && X == 0) return 1;
  return (dfs(S, X - 1) + dfs(S - v[X - 1], X - 1) + dfs(S - v[X], X - 1)) %
         INF;
}
signed main() {
  v[0] = 1;
  for (long long i = 1; i < 61; i++) v[i] = v[i - 1] * 2;
  w[0] = 1;
  for (long long i = 1; i < 61; i++) w[i] = w[i - 1] * 3;
  long long N;
  cin >> N;
  cout << dfs(N, 60) << endl;
}
