#include <bits/stdc++.h>
using namespace std;
#define int long long
#define inf (int)1000000000000000
#define eps 1e-14
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, s, t) for(int i = (int)(s); i < (int)(t); i++)
#define rrep(i, n) for(int i = (int)(n) - 1; i >= 0; i--)
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
using pii = pair<int, int>;
template<typename T> using mpq = priority_queue<T, vector<T>, greater<T>>;
template<typename T> using vec = vector<T>;
using str = string;
void io_init() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}
int int_in() {
  int w;
  cin >> w;
  return w;
}
void int_out(int w) {
  cout << w << "\n";
}
str str_in() {
  str s;
  cin >> s;
  return s;
}
void str_out(str s) {
  cout << s << "\n";
}
double double_in() {
  double w;
  cin >> w;
  return w;
}
void double_out(double d) {
  cout << fixed << setprecision(10) << d << "\n";
}
template<typename T> vec<T> vec_in(int n) {
  vec<T> v(n);
  rep(i, n) {
    cin >> v[i];
  }
  return v;
}
template<typename T> void vec_out(const vec<T>& v) {
  rep(i, v.size()) {
    if(i != v.size() - 1) {
      cout << v[i] << " ";
    }
    else {
      cout << v[i] << "\n";
    }
  }
}
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,-1,0,1};
class unionfind {
public:
  vec<int> d, c;
  unionfind(int n = 0) : d(n), c(n) {
    rep(i, n) {
      d[i] = -1;
      c[i] = 0;
    }
  }
  int find(int b) {
    if(d[b] < 0) {
      return b;
    }
    return find(d[b]);
  }
  int unite(int a, int b) {
    a = find(a);
    b = find(b);
    if(a == b) {
      return a;
    }
    if(c[a] > c[b]) {
      d[b] = a;
      return a;
    }
    else if(c[a] == c[b]) {
      d[b] = a;
      c[a]++;
      return a;
    }
    else {
      d[a] = b;
      return b;
    }
  }
};
class bit {
public:
  vec<int> d;
  bit(int n) : d(n) {
    rep(i, n) {
      d[i] = 0;
    }
  }
  void add(int b, int x) {
    for(int i = b + 1; i <= (int)d.size(); i += i & -i) {
      d[i - 1] += x;
    }
  }
  int sum(int l) {
    int r = 0;
    for(int i = l + 1; i > 0; i -= i & -i) {
      r += d[i - 1];
    }
    return r;
  }
  int sum(int b, int e) {
    return sum(e - 1) - sum(b - 1);
  }
};
int bit_mask(int l) {
  return ((int)1 << l) - 1;
}
int bit_get(int a, int b, int l, int m = 1) {
  return (a >> (b * m)) & bit_mask(l * m);
}
void bit_out(int a, int l) {
  rep(i, l) {
    cout << bit_get(a, i, 1);
  }
  cout << "\n";
}

#define mod 1000000007

int dd[111111];

signed main() {
  io_init();
  int nn = int_in();
  int dp[3][2];
  dp[0][0] = 0;
  dp[0][1] = 0;
  dp[1][0] = 0;
  dp[1][1] = 0;
  dp[2][0] = 1;
  dp[2][1] = 0;
  rrep(ii, 62) {
    int dpw[3][2];
    dpw[0][0] = 0;
    dpw[0][1] = 0;
    dpw[1][0] = 0;
    dpw[1][1] = 0;
    dpw[2][0] = 0;
    dpw[2][1] = 0;
    if(nn & ((int)1 << ii)) {
      dpw[0][0] += dp[0][0] * 2;
      dpw[0][1] += dp[0][0] * 2;
      dpw[0][0] += dp[0][1];
      dpw[0][1] += dp[0][1];

      dpw[0][0] += dp[1][0] * 2;
      dpw[0][1] += dp[1][0];
      dpw[1][1] += dp[1][0];
      dpw[0][0] += dp[1][1];
      dpw[0][1] += dp[1][1];

      dpw[1][0] += dp[2][0];
      dpw[2][0] += dp[2][0];
      dpw[2][1] += dp[2][0];
      dpw[1][0] += dp[2][1];
      dpw[2][1] += dp[2][1];
    }
    else {
      dpw[0][0] += dp[0][0] * 2;
      dpw[0][1] += dp[0][0] * 2;
      dpw[0][0] += dp[0][1];
      dpw[0][1] += dp[0][1];

      dpw[0][0] += dp[1][0];
      dpw[1][0] += dp[1][0];
      dpw[1][1] += dp[1][0];
      dpw[2][1] += dp[1][0];
      dpw[0][0] += dp[1][1];
      dpw[1][1] += dp[1][1];

      dpw[2][0] += dp[2][0];
      dpw[2][0] += dp[2][1];
    }
    dp[0][0] = dpw[0][0] % mod;
    dp[0][1] = dpw[0][1] % mod;
    dp[1][0] = dpw[1][0] % mod;
    dp[1][1] = dpw[1][1] % mod;
    dp[2][0] = dpw[2][0] % mod;
    dp[2][1] = dpw[2][1] % mod;
      //cout << dp[0][0] << " " << dp[0][1] << "\n" << dp[1][0] << " " << dp[1][1] << "\n" << endl;
  }
  int_out((dp[0][0] + dp[1][0] + dp[2][0]) % mod);
}


Measured memory_bytes: 384