#include <cstdio>
#include <map>
#define int long long
using namespace std;
const int M = 1e9+7;
map<int, int> a;
int n;
int dfs(int 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;
}