#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000007;
long long finddown(long long n);
map<long long, long long> u, d;
long long findup(long long n) {
  if (n == 0) return 1;
  if (n == 1) return 3;
  long long x, y;
  if (n % 2 == 0) {
    map<long long, long long>::iterator it = u.find(n / 2);
    if (it == u.end()) {
      x = findup(n / 2);
      u.insert(make_pair(n / 2, x));
    } else
      x = it->second;
    map<long long, long long>::iterator it2 = d.find(n / 2);
    if (it2 == d.end()) {
      y = finddown(n / 2);
      d.insert(make_pair(n / 2, y));
    } else
      y = it2->second;
    return ((x * x) % mod + (y * y) % mod) % mod;
  } else {
    return ((3 * findup(n - 1)) % mod + finddown(n - 1)) % mod;
  }
}
long long finddown(long long n) {
  if (n == 0) return 0;
  if (n == 1) return 1;
  long long x, y;
  if (n % 2 == 0) {
    map<long long, long long>::iterator it = u.find(n / 2);
    if (it == u.end()) {
      x = findup(n / 2);
      u.insert(make_pair(n / 2, x));
    } else
      x = it->second;
    map<long long, long long>::iterator it2 = d.find(n / 2);
    if (it2 == d.end()) {
      y = finddown(n / 2);
      d.insert(make_pair(n / 2, y));
    } else
      y = it2->second;
    return (2 * ((x * y) % mod)) % mod;
  } else {
    return ((3 * finddown(n - 1)) % mod + findup(n - 1)) % mod;
  }
}
int main() {
  long long n;
  cin >> n;
  cout << findup(n);
  return 0;
}
