import java.util.*
fun main(args: Array<String>) {
    var MOD = (1e9 + 7).toInt()
    var dp = TreeMap<Long, TreeMap<Long, Long>>()
    fun func(S: Long, X: Long): Long {
        if (S == 0L) return 1
        var d = dp[S]
        if (d == null) {
            d = TreeMap<Long, Long>()
            dp[S] = d
        } else {
            val ans = d!![X]
            if (ans != null) return ans
        }
        var ans = func(S / 2, X / 2) % MOD
        ans = (ans + func((S - 1) / 2, (X - 1) / 2)) % MOD
        if (S >= 2) ans = (ans + func((S - 2) / 2, X / 2)) % MOD
        d!![X] = ans
        return ans
    }
    val N = nextLong()
    val ans = func(N, N)
    println(ans)
}

fun next() = readLine()!!
fun nextInt(delta: Int = 0) = Integer.parseInt(next()) + delta
fun nextLong() = next().toLong()
