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
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

/**
 * @author Pavel Mavrin
 */
public class Main {

    private static final long MOD = (long) (1e9 + 7);

    private void solve() throws IOException {
        long n = Long.parseLong(next()) + 1;
        String s = Long.toBinaryString(n);
        int m = s.length();
        int[] a = new int[m];
        Arrays.fill(a, -1);
        long res = 0;
        for (int i = 0; i < m; i++) if (s.charAt(i) == '1') {
            for (int j = 0; j < i; j++) {
                a[j] = s.charAt(j) - '0';
            }
            a[i] = 0;
            res += calc(a);
            res %= MOD;
        }
        out.println(res);
    }

    private long calc(int[] a) {
        long q = 1, w = 0;
        for (int i = a.length - 1; i >= 0; i--) {
            long qq = 0, ww = 0;            
            if (a[i] != 1) {
                qq += q;
                ww += (q + w);
            }
            if (a[i] != 0) {
                qq += (q + w);
                ww += w;
            }
            q = qq % MOD;
            w = ww % MOD;
        }
        return q;
    }


    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st;
    PrintWriter out = new PrintWriter(System.out);

    String next() throws IOException {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }

    public static void main(String[] args) throws IOException {
        new Main().run();
    }

    private void run() throws IOException {
        solve();
        out.close();
    }

}
