#include using namespace std; template inline void chmin(T1 &a,T2 b){if(a>b) a=b;} template inline void chmax(T1 &a,T2 b){if(a struct FixPoint : F{ FixPoint(F&& f):F(forward(f)){} template decltype(auto) operator()(Args&&... args) const{ return F::operator()(*this,forward(args)...); } }; template inline decltype(auto) MFP(F&& f){ return FixPoint{forward(f)}; } //INSERT ABOVE HERE const Int LOG = 40; const Int OFS = 100; // 0 same // 1 less // 2 greater Int dp[3][2][LOG][OFS*2+1]; signed main(){ cin.tie(0); ios::sync_with_stdio(0); Int n; cin>>n; n++; vector po(LOG); for(Int i=0;iInt{ if(a==0 and b==c) return 0; if(bc) return 2; assert(b==c); return a; }; memset(dp,0,sizeof(dp)); dp[0][0][0][OFS]=1; Int diff[5]={0,-1,-2,2,1}; for(Int i=0;i+1=3][i+1][OFS+s+diff[(k+c)%5]]+=dp[a][c][i][OFS+s]; chmin(dp[nx(a,k,po[i])][(k+c)>=3][i+1][OFS+s+diff[(k+c)%5]],((Int)1e18)+10); } } } } } Int ans=0; ans+=dp[1][0][LOG-1][OFS]; ans+=dp[1][1][LOG-1][OFS]; ans--; cout<