#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define MOD 1000000007
ll sum(ll A, ll B)
{
A = (A + MOD) % MOD;
B = (B + MOD) % MOD;
ll ans = (A + B) % MOD;
ans = (ans + MOD) % MOD;
return ans;
}
ll f(ll a, ll n)
{
ll res = a, ans = 0;
while (n)
{
if (n % 2)
ans = (ans + res) % MOD;
res = (res + res) % MOD;
n /= 2;
}
return ans;
}
struct matran
{
ll a[4][4];
void print()
{
for (ll i = 0; i < 4; i++)
{
for (ll j = 0; j < 4; j++)
cout << a[i][j] << " ";
cout << '\n';
}
}
} M, mot;
struct boba
{
ll f_n2, f_n1, f_n, f_n3;
void print()
{
cout << f_n2 << " " << f_n1 << " " << f_n << " " << f_n3 << '\n';
}
} init;
matran prod(matran A, matran B)
{
matran C;
for (ll i = 0; i < 4; i++)
for (ll j = 0; j < 4; j++)
C.a[i][j] = 0;
for (ll i = 0; i < 4; i++)
{
for (ll j = 0; j < 4; j++)
{
for (ll k = 0; k < 4; k++)
C.a[i][j] = sum(C.a[i][j], f(A.a[i][k], B.a[k][j]));
}
}
return C;
}
matran po(matran A, ll n)
{
matran res = A, ans = mot;
while (n)
{
if (n % 2)
ans = prod(ans, res);
res = prod(res, res);
n /= 2;
}
return ans;
}
boba prod1(boba p, matran A)
{
boba ans;
for (ll j = 0; j < 4; j++)
{
if (j == 0)
{
ans.f_n2 = sum(sum(sum(f(p.f_n2, A.a[0][j]), f(p.f_n1, A.a[1][j])), f(p.f_n, A.a[2][j])), f(p.f_n3, A.a[3][j]));
}
else if (j == 1)
{
ans.f_n1 = sum(sum(sum(f(p.f_n2, A.a[0][j]), f(p.f_n1, A.a[1][j])), f(p.f_n, A.a[2][j])), f(p.f_n3, A.a[3][j]));
}
else if (j == 2)
ans.f_n = sum(sum(sum(f(p.f_n2, A.a[0][j]), f(p.f_n1, A.a[1][j])), f(p.f_n, A.a[2][j])), f(p.f_n3, A.a[3][j]));
else
ans.f_n3 = sum(sum(sum(f(p.f_n2, A.a[0][j]), f(p.f_n1, A.a[1][j])), f(p.f_n, A.a[2][j])), f(p.f_n3, A.a[3][j]));
}
return ans;
}
int main()
{
ll tmp[4][4] = {{0, 1, 1, 1}, {1, 0, 1, 1}, {1, 1, 0, 1}, {1, 1, 1, 0}};
ll unit[4][4] = {{1, 0, 0, 0}, {0, 1, 0, 0}, {0, 0, 1, 0}, {0, 0, 0, 1}};
for (ll i = 0; i < 4; i++)
for (ll j = 0; j < 4; j++)
{
M.a[i][j] = tmp[i][j];
mot.a[i][j] = unit[i][j];
}
init.f_n2 = 0;
init.f_n1 = 1;
init.f_n = 1;
init.f_n3 = 1;
ll n;
cin >> n;
boba ress = prod1(init, po(M, n - 1));
cout << ress.f_n2;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CiNkZWZpbmUgbGwgbG9uZyBsb25nCiNkZWZpbmUgTU9EIDEwMDAwMDAwMDcKbGwgc3VtKGxsIEEsIGxsIEIpCnsKICAgICAgICBBID0gKEEgKyBNT0QpICUgTU9EOwogICAgICAgIEIgPSAoQiArIE1PRCkgJSBNT0Q7CiAgICAgICAgbGwgYW5zID0gKEEgKyBCKSAlIE1PRDsKICAgICAgICBhbnMgPSAoYW5zICsgTU9EKSAlIE1PRDsKICAgICAgICByZXR1cm4gYW5zOwp9CmxsIGYobGwgYSwgbGwgbikKewogICAgICAgIGxsIHJlcyA9IGEsIGFucyA9IDA7CiAgICAgICAgd2hpbGUgKG4pCiAgICAgICAgewogICAgICAgICAgICAgICAgaWYgKG4gJSAyKQogICAgICAgICAgICAgICAgICAgICAgICBhbnMgPSAoYW5zICsgcmVzKSAlIE1PRDsKICAgICAgICAgICAgICAgIHJlcyA9IChyZXMgKyByZXMpICUgTU9EOwogICAgICAgICAgICAgICAgbiAvPSAyOwogICAgICAgIH0KICAgICAgICByZXR1cm4gYW5zOwp9CnN0cnVjdCBtYXRyYW4KewogICAgICAgIGxsIGFbNF1bNF07CiAgICAgICAgdm9pZCBwcmludCgpCiAgICAgICAgewogICAgICAgICAgICAgICAgZm9yIChsbCBpID0gMDsgaSA8IDQ7IGkrKykKICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICAgICAgZm9yIChsbCBqID0gMDsgaiA8IDQ7IGorKykKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBjb3V0IDw8IGFbaV1bal0gPDwgIiAiOwogICAgICAgICAgICAgICAgICAgICAgICBjb3V0IDw8ICdcbic7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgfQp9IE0sIG1vdDsKc3RydWN0IGJvYmEKewogICAgICAgIGxsIGZfbjIsIGZfbjEsIGZfbiwgZl9uMzsKICAgICAgICB2b2lkIHByaW50KCkKICAgICAgICB7CiAgICAgICAgICAgICAgICBjb3V0IDw8IGZfbjIgPDwgIiAiIDw8IGZfbjEgPDwgIiAiIDw8IGZfbiA8PCAiICIgPDwgZl9uMyA8PCAnXG4nOwogICAgICAgIH0KfSBpbml0OwptYXRyYW4gcHJvZChtYXRyYW4gQSwgbWF0cmFuIEIpCnsKICAgICAgICBtYXRyYW4gQzsKICAgICAgICBmb3IgKGxsIGkgPSAwOyBpIDwgNDsgaSsrKQogICAgICAgICAgICAgICAgZm9yIChsbCBqID0gMDsgaiA8IDQ7IGorKykKICAgICAgICAgICAgICAgICAgICAgICAgQy5hW2ldW2pdID0gMDsKICAgICAgICBmb3IgKGxsIGkgPSAwOyBpIDwgNDsgaSsrKQogICAgICAgIHsKICAgICAgICAgICAgICAgIGZvciAobGwgaiA9IDA7IGogPCA0OyBqKyspCiAgICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgICAgICAgIGZvciAobGwgayA9IDA7IGsgPCA0OyBrKyspCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgQy5hW2ldW2pdID0gc3VtKEMuYVtpXVtqXSwgZihBLmFbaV1ba10sIEIuYVtrXVtqXSkpOwogICAgICAgICAgICAgICAgfQogICAgICAgIH0KICAgICAgICByZXR1cm4gQzsKfQptYXRyYW4gcG8obWF0cmFuIEEsIGxsIG4pCnsKICAgICAgICBtYXRyYW4gcmVzID0gQSwgYW5zID0gbW90OwogICAgICAgIHdoaWxlIChuKQogICAgICAgIHsKICAgICAgICAgICAgICAgIGlmIChuICUgMikKICAgICAgICAgICAgICAgICAgICAgICAgYW5zID0gcHJvZChhbnMsIHJlcyk7CiAgICAgICAgICAgICAgICByZXMgPSBwcm9kKHJlcywgcmVzKTsKICAgICAgICAgICAgICAgIG4gLz0gMjsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIGFuczsKfQpib2JhIHByb2QxKGJvYmEgcCwgbWF0cmFuIEEpCnsKICAgICAgICBib2JhIGFuczsKICAgICAgICBmb3IgKGxsIGogPSAwOyBqIDwgNDsgaisrKQogICAgICAgIHsKICAgICAgICAgICAgICAgIGlmIChqID09IDApCiAgICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgICAgICAgIGFucy5mX24yID0gc3VtKHN1bShzdW0oZihwLmZfbjIsIEEuYVswXVtqXSksIGYocC5mX24xLCBBLmFbMV1bal0pKSwgZihwLmZfbiwgQS5hWzJdW2pdKSksIGYocC5mX24zLCBBLmFbM11bal0pKTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGVsc2UgaWYgKGogPT0gMSkKICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICAgICAgYW5zLmZfbjEgPSBzdW0oc3VtKHN1bShmKHAuZl9uMiwgQS5hWzBdW2pdKSwgZihwLmZfbjEsIEEuYVsxXVtqXSkpLCBmKHAuZl9uLCBBLmFbMl1bal0pKSwgZihwLmZfbjMsIEEuYVszXVtqXSkpOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgZWxzZSBpZiAoaiA9PSAyKQogICAgICAgICAgICAgICAgICAgICAgICBhbnMuZl9uID0gc3VtKHN1bShzdW0oZihwLmZfbjIsIEEuYVswXVtqXSksIGYocC5mX24xLCBBLmFbMV1bal0pKSwgZihwLmZfbiwgQS5hWzJdW2pdKSksIGYocC5mX24zLCBBLmFbM11bal0pKTsKICAgICAgICAgICAgICAgIGVsc2UKICAgICAgICAgICAgICAgICAgICAgICAgYW5zLmZfbjMgPSBzdW0oc3VtKHN1bShmKHAuZl9uMiwgQS5hWzBdW2pdKSwgZihwLmZfbjEsIEEuYVsxXVtqXSkpLCBmKHAuZl9uLCBBLmFbMl1bal0pKSwgZihwLmZfbjMsIEEuYVszXVtqXSkpOwogICAgICAgIH0KICAgICAgICByZXR1cm4gYW5zOwp9CmludCBtYWluKCkKewogICAgICAgIGxsIHRtcFs0XVs0XSA9IHt7MCwgMSwgMSwgMX0sIHsxLCAwLCAxLCAxfSwgezEsIDEsIDAsIDF9LCB7MSwgMSwgMSwgMH19OwogICAgICAgIGxsIHVuaXRbNF1bNF0gPSB7ezEsIDAsIDAsIDB9LCB7MCwgMSwgMCwgMH0sIHswLCAwLCAxLCAwfSwgezAsIDAsIDAsIDF9fTsKICAgICAgICBmb3IgKGxsIGkgPSAwOyBpIDwgNDsgaSsrKQogICAgICAgICAgICAgICAgZm9yIChsbCBqID0gMDsgaiA8IDQ7IGorKykKICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICAgICAgTS5hW2ldW2pdID0gdG1wW2ldW2pdOwogICAgICAgICAgICAgICAgICAgICAgICBtb3QuYVtpXVtqXSA9IHVuaXRbaV1bal07CiAgICAgICAgICAgICAgICB9CiAgICAgICAgaW5pdC5mX24yID0gMDsKICAgICAgICBpbml0LmZfbjEgPSAxOwogICAgICAgIGluaXQuZl9uID0gMTsKICAgICAgICBpbml0LmZfbjMgPSAxOwogICAgICAgIGxsIG47CiAgICAgICAgY2luID4+IG47CiAgICAgICAgYm9iYSByZXNzID0gcHJvZDEoaW5pdCwgcG8oTSwgbiAtIDEpKTsKICAgICAgICBjb3V0IDw8IHJlc3MuZl9uMjsKfQ==