#ARC066B. [ABC050D] Xor Sum

[ABC050D] Xor Sum

Score : 600600 points

Problem Statement

You are given a positive integer NN. Find the number of the pairs of integers uu and vv (0u,vN)(0 \leq u,v \leq N) such that there exist two non-negative integers aa and bb satisfying aa xorxor b=ub=u and a+b=va+b=v. Here, xorxor denotes the bitwise exclusive OR. Since it can be extremely large, compute the answer modulo 109+710^9+7.

Constraints

  • 1N10181 \leq N \leq 10^{18}

Input

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

NN

Output

Print the number of the possible pairs of integers uu and vv, modulo 109+710^9+7.

3
5

The five possible pairs of uu and vv are:

  • u=0,v=0u=0,v=0 (Let a=0,b=0a=0,b=0, then 00 xorxor 0=00=0, 0+0=00+0=0.)
  • u=0,v=2u=0,v=2 (Let a=1,b=1a=1,b=1, then 11 xorxor 1=01=0, 1+1=21+1=2.)
  • u=1,v=1u=1,v=1 (Let a=1,b=0a=1,b=0, then 11 xorxor 0=10=1, 1+0=11+0=1.)
  • u=2,v=2u=2,v=2 (Let a=2,b=0a=2,b=0, then 22 xorxor 0=20=2, 2+0=22+0=2.)
  • u=3,v=3u=3,v=3 (Let a=3,b=0a=3,b=0, then 33 xorxor 0=30=3, 3+0=33+0=3.)
1422
52277
1000000000000000000
787014179