import java.util.ArrayList; import java.util.Arrays; import java.util.Scanner; public class Main { long mo = 1_000_000_000 + 7; void run() { Scanner sc = new Scanner(System.in); long N = sc.nextLong(); long[][] dp = new long[2][2]; for (int i = 60; i >= 0; --i) { long[][] ndp = new long[2][2]; if ((1L << i) > N) continue; if (N < 1L << (i + 1)) { ndp[0][0] += 1; } else { ndp[0][1] += 1; } for (int j = 0; j <= 1; ++j) { for (int k = 0; k <= 1; ++k) { for (int x = 0; x <= 1; ++x) { for (int y = 0; y <= 1; ++y) { if (k == 0 && y == 1 && ((1L << i) & N) == 0) continue; int idx1 = j, idx2 = k; if (y == 0 && ((1L << i) & N) > 0) idx2 = 1; if (x == 1 && y == 1) idx1 = 1; ndp[idx1][idx2] = (ndp[idx1][idx2] + dp[j][k]) % mo; } } } } dp = ndp; } System.out.println((dp[1][1] + dp[1][0]) % mo); } public static void main(String[] args) { new Main().run(); } void tr(Object... objects) { System.out.println(Arrays.deepToString(objects)); } }