You are given a positive integer N. Find the number of the pairs of integers u and v (0≦u,v≦N) such that there exist two non-negative integers a and b satisfying a xor b=u and a+b=v. Here, xor denotes the bitwise exclusive OR. Since it can be extremely large, compute the answer modulo 10^9+7.

Constraints

* 1≦N≦10^{18}

Input

The input is given from Standard Input in the following format:


N


Output

Print the number of the possible pairs of integers u and v, modulo 10^9+7.

Examples

Input

3


Output

5


Input

1422


Output

52277


Input

1000000000000000000


Output

787014179
#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;
}
