#include <bits/stdc++.h>
using namespace std;
const long long M = 1e9 + 7;
map<long long, long long> a;
long long n;
long long dfs(long long x) {
  if (a[x]) return a[x];
  if (x % 2)
    return a[x] = (2 * dfs(x / 2) + dfs(x / 2 - 1)) % M;
  else
    return a[x] = (dfs(x / 2) + 2 * dfs(x / 2 - 1)) % M;
}
signed main() {
  a[0] = 1;
  a[1] = 2;
  scanf("%lld", &n);
  printf("%lld", dfs(n));
  return 0;
}
