#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000000 + 7;
map<int, int> a;
int dfs(int x) {
  if (a[x]) return a[x];
  a[x] = (dfs(x / 2) % mod + dfs((x - 1) / 2) % mod + dfs((x - 2) / 2) % mod) %
         mod;
  return a[x];
}
int main() {
  a[0] = 1;
  a[1] = 2;
  int n;
  scanf("%d", &n);
  int ans = dfs(n);
  printf("%d", ans);
  return 0;
}
