#define _USE_MATH_DEFINES #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; const int MOD = 1000; // 行列の積 template vector > matrixProduct(const vector >& x, const vector >& y) { int a = x.size(); int b = x[0].size(); int c = y[0].size(); vector > z(a, vector(c, 0)); for(int i=0; i vector > matrixPower(const vector >& x, int k) { int n = x.size(); vector > y(n, vector(n, 0)); for(int i=0; i > z = x; while(k > 0){ if(k & 1) y = matrixProduct(y, z); z = matrixProduct(z, z); k >>= 1; } return y; } int main() { int n; cin >> n; vector > mat = {{2, 2}, {1, 0}}; mat = matrixPower(mat, n); int ans = (mat[1][0] + mat[1][1]) * 2; ans %= MOD; if(n % 2 == 0){ ans += MOD - 1; ans %= MOD; } cout << ans << endl; return 0; }