#include<bits/stdc++.h>
using namespace std;
const int MOD = (int)1e9+7;
map<pair<long long, int>, int> M;

int DP(long long N, int k)
{
  if(N<0) return 0;
  if(N>(2LL<<(k+1))-2) N = (2LL<<(k+1))-2;
  if(N == 0) return 1;
  auto it = M.find(make_pair(N, k));
  if(it != M.end()) return it->second;
  long long ans = 0;
  ans += DP(N-(2LL<<k), k-1);
  ans += DP(N-(1LL<<k), k-1);
  ans += DP(N, k-1);
  return M[make_pair(N, k)] = ans % MOD;
}

int solve(long long N)
{
  M.clear();
  return DP(N, 61);
}
int main()
{
  long long N;
  scanf("%lld", &N);
  printf("%d\n", solve(N));
}