import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;

enum mod = 10L^^9 + 7;
alias Pair = Tuple!(long, "s", long, "x");

void main() {
    long n;
    scan(n);

    long[Pair] mem;

    long func(long s, long x) {
        if (Pair(s, x) in mem) {
            return mem[Pair(s, x)];
        }
        if (s == 0) {
            return 1;
        }
        if (x == 0) {
            return s/2 + 1;
        }

        mem[Pair(s, x)] = (func(s/2, x/2) + func((s-1)/2, (x-1)/2)) % mod;
        if (s >= 2) {
            mem[Pair(s, x)] += func((s-2)/2, x/2);
        }
        mem[Pair(s, x)] %= mod;

        return mem[Pair(s, x)];
    }

    writeln(func(n, n));
}





void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}
