#include <cstdio>
#include <map>
#include <set>
typedef long long int64;
static const int LOGN = 61;
static const int MODULUS = 1e9 + 7;
#define _  %  MODULUS
#define __ %= MODULUS

std::map<int64, int> mem;

// For clarity; this is not used
inline int calcx(int64 n)
{
    /*std::set<int64> s;
    for (int64 i = 0; i <= n / 2; ++i) s.insert(i ^ (n - i));
    return s.size();*/
    if (n <= 1) return 1;
    else return (n % 2 == 0 ? (calcx(n / 2 - 1) + calcx(n / 2))_ : calcx(n / 2));
}

inline int64 calc(int64 n)
{
    if (n == 0) return 1;
    else if (n == 1) return 2;
    int &ans = mem[n];
    if (!ans) ans = (calc(n / 2) + calc(n / 2 - 1) + calc(n / 2 - (1 - n % 2)))_;
    return ans;
}

int64 n;

int main()
{
    scanf("%lld", &n);
    printf("%lld\n", calc(n));
    return 0;
}
