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