#include #include #include #include #define repeat_from(i,m,n) for (int i = (m); (i) < (n); ++(i)) typedef long long ll; using namespace std; const int mod = 1000; int main() { int n; cin >> n; vector g; map,int> adj; g.push_back(2); g.push_back(2); adj[make_pair(g[0], g[1])] = 2; repeat_from (i,2,n+1) { g.push_back((2 * g[i-1] + 2 * g[i-2]) % mod); pair key = { g[i-1], g[i] }; if (adj.count(key)) { int l = adj[key]; // g[p] == g[i+1] int r = i+1; int j = (n - l) % (r - l) + l; cout << (g[j] - (n%2 ? 0 : 1) + mod) % mod << endl; return 0; } adj[key] = i+1; } cout << (g[n] - (n%2 ? 0 : 1) + mod) % mod << endl; return 0; }