def rangesum(l, r): if r < l: return 0 return (l + r) * (r - l + 1) // 2 def getsum(a, d, n): return (2 * a + (n - 1) * d) * n // 2 mod = 10 ** 9 + 7 n = int(input()) ans = 0 for i in range(70): a = 1 << i b = 1 << (i + 1) c = rangesum(a, b - 1) d = 1 << (2 * i + 1) e = n // b * b + a ans += getsum(c, d, n // b) ans %= mod ans += rangesum(e, n) ans %= mod print(ans)