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
/*QAQ三连：以前的题都补了吗，今天的题都做了吗，不会的算法都会了吗*/
/*金桔退役三连：退役选手不学不会不练*/
#include <bits/stdc++.h>
#define LDQ 1000000007
#define QAQ 0x3f3f3f3f
#define PI 3.14159265358979323846
using namespace std;
map<long long,long long>mp;
long long f(long long n)
{
    if(mp[n]!=0)
    {
        return mp[n];
    }
    if(n<2)
    {
        return mp[n]=n+1;
    }
    else if(n%2==0)
    {
        return mp[n]=(2*f(n/2-1)+f(n/2))%LDQ;
    }
    else
    {
        return mp[n]=(f(n/2-1)+2*f(n/2))%LDQ;
    }
}
int main()
{
    long long n;
    scanf("%lld",&n);
    printf("%lld",f(n));
    return 0;
}
