#include using namespace std; #define rep(i,a,b) for(int i=a;i= mod ? x - mod : x; } template int add(int x, T... y) { return add(x, add(y...)); } int mul(int x, int y) { return 1LL * x * y % mod; } template int mul(int x, T... y) { return mul(x, mul(y...)); } int sub(int x, int y) { return add(x, mod - y); } typedef long long ll; typedef vector Vec; typedef vector Mat; Vec mulMatVec(Mat a, Vec b) { int n = b.size(); Vec ret(n, 0); rep(i, 0, n) rep(j, 0, n) ret[i] = add(ret[i], mul(a[i][j], b[j])); return ret; } Mat mulMatMat(Mat a, Mat b) { int n = a.size(); Mat ret(n, Vec(n, 0)); rep(i, 0, n) rep(j, 0, n) rep(k, 0, n) ret[i][j] = add(ret[i][j], mul(a[i][k], b[k][j])); return ret; } Mat fastpow(Mat x, ll n) { Mat ret(x.size(), Vec(x.size(), 0)); rep(i, 0, x.size()) ret[i][i] = 1; while (0 < n) { if ((n % 2) == 0) { x = mulMatMat(x, x); n >>= 1; } else { ret = mulMatMat(ret, x); --n; } } return ret; } void printVec(Vec a) { cout << "[ "; rep(i, 0, a.size()) cout << a[i] << " "; cout << "]" << endl; } void printMat(Mat a) { rep(i, 0, a.size()) printVec(a[i]); } //----------------------------------------------------------------------------------- int main() { int N; cin >> N; if (N == 0) { printf("1\n"); return 0; } Mat ma(2, Vec(2, 0)); ma[0][0] = ma[0][1] = 2; ma[1][0] = 1; Vec ve(2, 0); ve[0] = ve[1] = 2; ma = fastpow(ma, N - 1); ve = mulMatVec(ma, ve); int ans = ve[0]; if (N % 2 == 0) ans = (ans - 1 + 1000) % 1000; cout << ans << endl; }