#include <bits/stdc++.h>
using namespace std;
int main(void) {
  long long a[100];
  long long b[100];
  int c;
  int d;
  int k;
  long long n;
  long long p;
  int q;
  long long s;
  int x;
  int y;
  int z;
  for (int i = 0; i < 100; i++) {
    a[i] = 0;
    b[i] = 0;
  }
  z = 0;
  scanf("%lld", &n);
  p = 1;
  for (int i = 0; i < 100; i++) {
    p = p * 2;
    a[i] = n / p;
    b[i] = n % p;
    if (a[i] == 0) {
      x = i;
      break;
    }
  }
  s = n + 1;
  s = s % 1000000007;
  p = 1;
  for (int i = 0; i < x; i++) {
    s = s + (a[i] - 1) * p;
    s = s % 1000000007;
    if (b[i] < p) {
      s = s + b[i] + 1;
      s = s % 1000000007;
    } else {
      s = s + p;
      s = s % 1000000007;
    }
    p = p * 4;
  }
  printf("%lld\n", s);
  return 0;
}
