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<stdio.h>
#include<algorithm>
using namespace std;
long long n, D[64][3][2], Mod = 1000000007, Res;
void Add(int a, int b, int c, long long d){
    D[a][b][c] = (D[a][b][c]+d)%Mod;
}
int main(){
    int i, j, k;
    D[60][0][0] = 1;
    scanf("%lld",&n);
    for(i=59;i>=0;i--){
        long long t = 1ll << i;
        int ck = (n >> i) & 1;
        for(j=0;j<3;j++){
            for(k=0;k<2;k++){
                if(j*2-2+ck >= 0)Add(i, min(j*2 - 2 + ck, 2), k|ck, D[i+1][j][k]);
                if(j*2-1+ck >= 0 && (k|ck))Add(i, min(j*2 - 1 + ck, 2), k, D[i+1][j][k]);
                Add(i, min(j*2 + ck, 2), k|ck, D[i+1][j][k]);
            }
        }
    }
    for(i=0;i<3;i++)for(j=0;j<2;j++) Res=(Res+D[0][i][j])%Mod;
    printf("%lld\n",Res);
}