#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>

using namespace std;

typedef long long LL;
const int mod = 1000000007;

map<LL, LL>m1;

LL f(LL n);

int main(){
  LL n;
  m1[1] = 2, m1[2] = 4, m1[3] = 5;
  scanf("%lld", &n);
  printf("%lld\n", f(n));
  return 0;
}
LL f(LL n){
  if(m1[n] != 0) return m1[n];
  LL n1 = n>>1;
  LL n2 = (n-(LL)1)>>1;
  LL n3 = (n-(LL)2)>>1;
  return m1[n] = (f(n1)%mod + f(n2)%mod + f(n3)%mod)%mod;
}
