#include <bits/stdc++.h>
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
using namespace std;
int mod = 1e9 + 7, mi = (mod + 1) / 3;
unordered_map<long long, long long> ma;
long long cal(long long size, long long line, long long th) {
  if (line == 0) return 1;
  if (line == 1) return 2;
  if (ma.count(line)) return ma[line];
  if (line < size / 2) return cal(size >> 1, line, th * mi % mod);
  long long t = (th * mi) % mod;
  if (line - size / 2 - size / 4 >= 0)
    return ma[line] =
               (2 * cal(size >> 1, line - size / 2, t) -
                cal(size >> 2, line - size / 2 - size / 4, (t * mi) % mod) +
                th * 2 + mod) %
               mod;
  return ma[line] = (cal(size >> 1, line - size / 4, t) +
                     cal(size >> 2, line - size / 2, (t * mi) % mod) + th) %
                    mod;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n, cn = 1, m = 1;
  cin >> n;
  while (n >= cn) {
    cn <<= 1;
    m = (m * 3) % mod;
  }
  m = m * mi % mod * mi % mod;
  cout << cn << " " << n << " " << m << endl;
  cout << cal(cn, n, m) << endl;
  return 0;
}
