#include #include #include #include using namespace std; #define YES(condition) if(condition) cout << "YES" << endl; else cout << "NO" << endl #define Yes(condition) if(condition) cout << "Yes" << endl; else cout << "No" << endl #define POSS(condition) if(condition) cout << "POSSIBLE" << endl; else cout << "IMPOSSIBLE" << endl #define Poss(condition) if(condition)cout << "Possible" << endl; else cout << "Impossible" << endl #define First(condition) if(condition)cout << "First" << endl; else cout << "Second" << endl #define negative(condition, num) if(condition)cout << -1 << endl; else cout << num << endl long power(long base, long exponent, long module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ long root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }} struct position{ int y, x; }; position move_pattern[4] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}}; template void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++){ ans += to_string(*i) + " "; } ans.pop_back(); cout << ans << endl; } long gcd(long a, long b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }} #define mod long(1e9 + 7) #define bitcount(n) __builtin_popcount(n) struct matrix{ vector> space; matrix(vector> element){ space = element; } matrix(int size){ space.resize(size, vector(size)); } matrix operator *(matrix another){ matrix ans(int(space.size())); for(int i = 0; i < space.size(); i++){ for(int j = 0; j < space.size(); j++){ ans.space[i][j] = 0; for(int k = 0; k < space.size(); k++){ ans.space[i][j] += space[i][k] * another.space[k][j]; } ans.space[i][j] %= 1000; } } return ans; } inline vector operator [](int index){ return space[index]; } }; matrix A({{2, 2}, {1, 0}}), E({{1, 0}, {0, 1}}); matrix matrix_power(int exponent){ if(exponent % 2){ return A * matrix_power(exponent - 1); }else if(exponent){ matrix root_ans = matrix_power(exponent / 2); return root_ans * root_ans; }else{ return E; } } int main(){ int n; cin >> n; cout << ((matrix_power(n) * matrix({{2, 2}, {2, 999}}))[1][0] + 1000 - (n + 1) % 2) % 1000 << endl; }