#include "bits/stdc++.h" using namespace std; #define DEBUG(x) cout<<#x<<": "< #define vl vector #define vii vector< vector > #define vll vector< vector > #define vs vector #define pii pair #define pis pair #define psi pair #define pll pair const int inf = 1000000001; const ll INF = 1e18 * 2; #define MOD 1000000007 #define mod 1000000009 #define pi 3.14159265358979323846 #define Sp(p) cout<= mod ? a.n - a.Mod : a.n); } Modint operator-(Modint a, Modint b) { return Modint((a.n -= b.n) < 0 ? a.n + a.Mod : a.n); } Modint operator*(Modint a, Modint b) { return Modint(1LL * a.n * b.n % a.Mod); } Modint &operator+=(Modint &a, Modint b) { return a = a + b; } Modint &operator-=(Modint &a, Modint b) { return a = a - b; } Modint &operator*=(Modint &a, Modint b) { return a = a * b; } bool operator<(Modint a, Modint b) { return a.n < b.n; } bool operator>(Modint a, Modint b) { return b < a; } bool operator<=(Modint a, Modint b) { return !(a > b); } bool operator>=(Modint a, Modint b) { return !(a < b); } map mp1; map mp2; Modint modpow(Modint a, int b) { Modint ret = 1; while (b > 0) { if (b & 1) ret *= a; a *= a; b >>= 1; } return ret; } Modint modinv(Modint a) { return modpow(a, a.Mod - 2); } int main() { ll n, i; cin >> n >> m; Modint num(2); Modint four(4); mp1[num] = 1; mp2[1] = num.n; for (i = 2; i <= n + 1; i++) { num = (num + four) * num; if (mp1[num] == 0) { mp1[num] = i; mp2[i] = num.n; } else { break; } } ll aida = (i - mp1[num]); Modint ans(n); ans -= mp1[num]; ans.n %= aida; ans += mp1[num]; cout << mp2[ans.n] << endl; }