#pragma GCC target("avx512f") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include #include #include using namespace atcoder; using namespace std; using namespace boost::multiprecision; #define fst first #define snd second #define len(a) (ll)size(a) #define ppc(a) (ll)__builtin_popcountll(a) #define sq(a) ((a)*(a)) #define bit(a) (1LL<<(a)) #define fin(...) exit(pt(__VA_ARGS__)) #define pb() pop_back() #define ep(...) emplace(__VA_ARGS__) #define eb(...) emplace_back(__VA_ARGS__) #define ef(...) emplace_front(__VA_ARGS__) #define ei(...) else if(__VA_ARGS__) #define el else #define wh(...) while(__VA_ARGS__) #define lb(...) lower_bound(__VA_ARGS__) #define ub(...) upper_bound(__VA_ARGS__) #define srt(...) sort(all(__VA_ARGS__)) #define rev(...) reverse(all(__VA_ARGS__)) #define uni(a) srt(a);a.erase(unique(all(a)),end(a)) #define join(a,b) copy(all(b),back_inserter(a)) #define ov3(a,b,c,d,...) d #define ov4(a,b,c,d,e,...) e #define ov5(a,b,c,d,e,f,...) f #define ov6(a,b,c,d,e,f,g,...) g #define bg begin #define rbg rbegin #define all1(v) bg(v),end(v) #define all2(v,b) bg(v),bg(v)+b #define all3(v,a,b) bg(v)+a,bg(v)+b #define all(...) ov3(__VA_ARGS__,all3,all2,all1)(__VA_ARGS__) #define rll1(v) rbg(v),rend(v) #define rll2(v,b) rbg(v),rbg(v)+b #define rll3(v,a,b) rbg(v)+a,rbg(v)+b #define rll(...) ov3(__VA_ARGS__,rll3,rll2,rll1)(__VA_ARGS__) #define rep1(b) for(ll _i=0;_i<(ll)(b);_i++) #define rep2(i,b) for(ll i=0;i<(ll)(b);i++) #define rep3(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++) #define rep4(i,a,b,c) for(ll i=(ll)(a);i<(ll)(b);i+=(ll)(c)) #define rep(...) ov4(__VA_ARGS__,rep4,rep3,rep2,rep1)(__VA_ARGS__) #define per1(a) rep(a) #define per2(i,a) for(ll i=(ll)(a)-1;i>=0;i--) #define per3(i,a,b) for(ll i=(ll)(a)-1;i>=(ll)(b);i--) #define per4(i,a,b,c) for(ll i=(ll)(a)-1;i>=(ll)(b);i-=(ll)(c)) #define per(...) ov4(__VA_ARGS__,per4,per3,per2,per1)(__VA_ARGS__) #define foe1(a) rep(len(a)) #define foe2(a,v) for(auto&&a:v) #define foe3(a,b,v) for(auto&&[a,b]:v) #define foe4(a,b,c,v) for(auto&&[a,b,c]:v) #define foe5(a,b,c,d,v) for(autoto&&[a,b,c,d]:v) #define foe(...) ov5(__VA_ARGS__,foe5,foe4,foe3,foe2,foe1)(__VA_ARGS__) #define LL(...) ll __VA_ARGS__;lin(__VA_ARGS__) #define LD(...) ld __VA_ARGS__;lin(__VA_ARGS__) #define ST(...) str __VA_ARGS__;lin(__VA_ARGS__) #define UL2(n,a) u1 a(n);lin(a) #define UL3(n,a,b) u1 a(n),b(n);lin(a,b) #define UL4(n,a,b,c) u1 a(n),b(n),c(n);lin(a,b,c) #define UL5(n,a,b,c,d) u1 a(n),b(n),c(n),d(n);lin(a,b,c,d) #define UL6(n,a,b,c,d,e) u1 a(n),b(n),c(n),d(n),e(n);lin(a,b,c,d,e) #define UL(...) ov6(__VA_ARGS__,UL6,UL5,UL4,UL3,UL2)(__VA_ARGS__) #define UV2(n,a) u1 a(n);vin(a) #define UV3(n,a,b) u1 a(n),b(n);vin(a,b) #define UV4(n,a,b,c) u1 a(n),b(n),c(n);vin(a,b,c) #define UV5(n,a,b,c,d) u1 a(n),b(n),c(n),d(n);vin(a,b,c,d) #define UV6(n,a,b,c,d,e) u1 a(n),b(n),c(n),d(n),e(n);vin(a,b,c,d,e) #define UV(...) ov6(__VA_ARGS__,UV6,UV5,UV4,UV3,UV2)(__VA_ARGS__) #define DL2(n,a) v1a(n);lin(a) #define DL3(n,a,b) v1a(n),b(n);lin(a,b) #define DL4(n,a,b,c) v1a(n),b(n),c(n);lin(a,b,c) #define DL5(n,a,b,c,d) v1a(n),b(n),c(n),d(n);lin(a,b,c,d) #define DL(...) ov5(__VA_ARGS__,DL5,DL4,DL3,DL2)(__VA_ARGS__) #define DV2(n,a) v1a(n);vin(a) #define DV3(n,a,b) v1a(n),b(n);vin(a,b) #define DV4(n,a,b,c) v1a(n),b(n),c(n);vin(a,b,c) #define DV5(n,a,b,c,d) v1a(n),b(n),c(n),d(n);vin(a,b,c,d) #define DV(...) ov5(__VA_ARGS__,DV5,DV4,DV3,DV2)(__VA_ARGS__) #define tm template #define cl class #define op operator #define fn function #define cons const #define rt return #define cont continue #define endl "\n" #define sp " " #define as assert using ll=long long; using ld=long double; using str=string; tmusing v1=vector; tmusing v2=v1>; tmusing v3=v1>; tmusing v4=v1>; tmusing mset=multiset; using u1=v1; using u2=v1; using u3=v1; using u4=v1; using pll=pair; using qll=queue; using sll=set; using msll=mset; using mll=map; using mint=modint1000000007; using is=istream; using os=ostream; ll inf=3e18; ld pi=acosl(-1); ld eps=1e-10; tmusing max_heap=std::priority_queue; tmusing min_heap=std::priority_queue,greater>; tmll sig(cons T&a){rt(a>eps)-(a<-eps);} tmll sig(cons T&a,cons T&b){rt sig(a-b);} tmv1&op++(v1&v){foe(x,v)x++;rt v;} tmv1&op--(v1&v){foe(x,v)x--;rt v;} tmv1op++(v1&v,int){auto r=v;++v;rt r;} tmv1op--(v1&v,int){auto r=v;--v;rt r;} tmv1&op+=(v1&v,cons U&a){foe(x,v)x+=a;rt v;} tmv1&op-=(v1&v,cons U&a){foe(x,v)x-=a;rt v;} tmv1&op*=(v1&v,cons U&a){foe(x,v)x*=a;rt v;} tmv1&op/=(v1&v,cons U&a){foe(x,v)x/=a;rt v;} tmv1&op+=(v1&v,cons v1&u){rep(i,len(v))v[i]+=u[i];rt v;} tmv1&op-=(v1&v,cons v1&u){rep(i,len(v))v[i]-=u[i];rt v;} tmv1&op*=(v1&v,cons v1&u){rep(i,len(v))v[i]*=u[i];rt v;} tmv1&op/=(v1&v,cons v1&u){rep(i,len(v))v[i]/=u[i];rt v;} tmbool cma(T&a,cons U&b){rt abool cmi(T&a,cons U&b){rt a>b?a=b,1:0;} tmT max(cons v1&a){rt *max_element(all(a));} tmT min(cons v1&a){rt *min_element(all(a));} tmauto max(T...a){rt max(initializer_list>{a...});} tmauto min(T...a){rt min(initializer_list>{a...});} tmT gcd(cons T&a,cons A&...b){rt gcd(a,gcd(b...));} tmT sum(cons v1&a){rt accumulate(all(a),T(0));} tmll lbs(cons v1&a,cons T&b){rt lb(all(a),b)-bg(a);} tmll ubs(cons v1&a,cons T&b){rt ub(all(a),b)-bg(a);} tmpairmima(cons T&a,cons T&b){rt{min(a,b),max(a,b)};} tmpairmima(cons pair&p){rt mima(p.fst,p.snd);} tmT at(cons v1&v,cons ll&i){ll n=len(v);rt v[(i%n+n)%n];} u1 iota(ll n,ll s=0){u1 a(n);iota(all(a),s);rt a;} void emplace_front(u1&v,ll x=0){v.ep(bg(v),x);} tmauto keys(cons map&m){v1r;foe(k,_,m)r.eb(k);rt r;} tmauto vals(cons map&m){v1r;foe(_,v,m)r.eb(v);rt r;} struct fio{ fio(){ cin.tie(0); ios::sync_with_stdio(0); cout<>(is&i,mint&x){ll t;i>>t;x=t;rt i;} os&op<<(os&o,cons mint&x){rt o<is&op>>(is&i,pair&p){rt i>>p.fst>>p.snd;} tmos&op<<(os&o,cons pair&p){rt o<is&op>>(is&i,v1&v){foe(x,v)i>>x;rt i;} tmos&op<<(os&o,cons v1&v){foe(x,v)o<os&op<<(os&o,cons v2&v){foe(x,v)o<os&op<<(os&o,cons set&s){foe(x,s)o<os&op<<(os&o,cons mset&s){foe(x,s)o< os&op<<(os&o,cons map&m){foe(p,m)o<os&op<<(os&o,queueq){wh(len(q))o<os&op<<(os&o,dequeq){wh(len(q))o<os&op<<(os&o,max_heapq){wh(len(q))o<os&op<<(os&o,min_heapq){wh(len(q))o<ll pt(cons T&a,cons A&...b){cout<ll db(cons T&a,cons A&...b){cerr<void lin(T&...a){(cin>>...>>a);} tmvoid vin(cons ll&i,T&...a){(cin>>...>>a[i]);} tmvoid vin(v1&a,A&...b){rep(i,len(a))vin(i,a,b...);} str first(bool f=1){rt f?"first":"second";} str First(bool f=1){rt f?"First":"Second";} str yes(bool f=1){rt f?"yes":"no";} str Yes(bool f=1){rt f?"Yes":"No";} str YES(bool f=1){rt f?"YES":"NO";} str no(){rt "no";} str No(){rt "No";} str NO(){rt "NO";} str possible(bool f=1){rt f?"possible":"impossible";} str Possible(bool f=1){rt f?"Possible":"Impossible";} str POSSIBLE(bool f=1){rt f?"POSSIBLE":"IMPOSSIBLE";} tmvoid rs(v1&v,cons T&a){v.resize(a);} tmvoid rs(v1&u,cons T&a,cons A&...b){ rs(u,a); foe(v,u)rs(v,b...); } tmvoid fl(V&v,cons T&x){v=x;} tmvoid fl(v1&u,cons T&x){foe(v,u)fl(v,x);} void zi(cons u1&v,u1&h){foe(x,h)x=lbs(v,x);} tmvoid zi(cons u1&v,u1&h,T&...t){zi(v,h);zi(v,t...);} tmu1 zip(T&...a){u1 v;foe(e,{a...})join(v,e);uni(v);zi(v,a...);rt v;} tmvoid vs(cons u1&o,v1&a){auto c=a;rep(i,len(a))a[i]=c[o[i]];} tmvoid vs(cons u1&o,v1&a,A&...b){vs(o,a);vs(o,b...);} tmpairvsrt(cons fn&f,T&...a){ ll n=0; foe(e,{a...})n=len(e); u1 o=iota(n),p(n); sort(all(o),f); rep(i,n)p[o[i]]=i; vs(o,a...); rt{o,p}; } tmT bs(cons fn&j,T o,T n){ T d=(T)eps?eps:1; wh(abs(o-n)>d)(j((o+n)/2)?o:n)=(o+n)/2; rt o; } tmauto zt(v1a){rep(i,1,len(a))a[i]+=a[i-1];rt a;} tmauto mb(v1a){per(i,len(a),1)a[i]-=a[i-1];rt a;} tmauto zt(v2a){foe(v,a)v=zt(v);rep(i,1,len(a))a[i]+=a[i-1];rt a;} tmauto mb(v2a){foe(v,a)v=mb(v);per(i,len(a),1)a[i]-=a[i-1];rt a;} u1 dvs(ll n){mll m;rep(i,1,n/i+1)if(n%i==0)m[i]++,m[n/i]++;rt keys(m);} mll fct(ll n){mll m;rep(i,2,n/i+1)wh(n%i==0)m[i]++,n/=i;if(n>1)m[n]++;rt m;} ll pom(ll x,ll n,ll m=inf){ll r=1;wh(n){if(n&1)r*=x,r%=m;x*=x,x%=m,n/=2;}rt r;} ll inm(ll a,ll m){ ll b=m,u=1,v=0; wh(b)u-=a/b*v,swap(u,v),a-=a/b*b,swap(a,b); rt(u%m+m)%m; } ll sqr(ll x){ll r=sqrtl(x)-1;wh(r+1<=x/(r+1))r++;rt r;} ll lg2(ll n){ll r=0;wh(n){n/=2;r++;}rt r;} mint ham(mint a){rt (a+1346)*(a+9185);} u1 dx={-1,0,1,0,-1,1,1,-1}; u1 dy={0,-1,0,1,-1,-1,1,1}; using S=ll; S ema(){rt -inf;} S emi(){rt inf;} S oad(S a,S b){rt a+b;} S ead(){rt 0;} S ope(S a,S b){rt a+b;} S ein(){rt 0;} using sgma=segtree; using sgmi=segtree; using sgad=segtree; using sgt=segtree; tmstruct mat{ v2m; ll h,w; mat(ll k):h(k),w(k){rs(m,k,k);} mat(ll h,ll w):h(h),w(w){rs(m,h,w);} mat(ll h,ll w,T x):h(h),w(w){rs(m,h,w);fl(m,x);} mat(v2a):h(len(a)),w(len(a[0])),m(a){} v1op[](cons ll&i)cons{rt m[i];} v1&op[](cons ll&i){rt m[i];} mat&op+=(cons mat&a){as(h==a.h and w==a.w);rep(i,h)m[i]+=a[i];rt*this;} mat&op-=(cons mat&a){as(h==a.h and w==a.w);rep(i,h)m[i]-=a[i];rt*this;} mat&op*=(cons mat&a){ as(w==a.h); mat m2(h,a.w); rep(i,h)rep(k,w)rep(j,a.w)m2[i][j]+=m[i][k]*a[k][j]; rt *this=m2; } //行列 mat op+(cons mat&a)cons{rt mat(*this)+=a;} mat op-(cons mat&a)cons{rt mat(*this)-=a;} mat op*(cons mat&a)cons{rt mat(*this)*=a;} bool op==(cons mat&a){rt m==a.m;} //スカラ mat&op+=(cons T&a){foe(v,m)v+=a;rt*this;} mat&op-=(cons T&a){foe(v,m)v-=a;rt*this;} mat&op*=(cons T&a){foe(v,m)v*=a;rt*this;} mat&op/=(cons T&a){foe(v,m)v/=a;rt*this;} mat op+(cons T&a)cons{rt mat(*this)+=a;} mat op-(cons T&a)cons{rt mat(*this)-=a;} mat op*(cons T&a)cons{rt mat(*this)*=a;} mat op/(cons T&a)cons{rt mat(*this)/=a;} mat pow(ll n){ as(h==w); mat x=*this; mat r(h);rep(i,h)r[i][i]=1; wh(n){ if(n&1)r*=x; x*=x; n/=2; } rt r; } void trs(){ mat m2(w,h); rep(i,h)rep(j,w)m2[j][i]=m[i][j]; *this=m2; } friend is&op>>(is&i,mat&m){rt i>>m.m;} friend os&op<<(os&o,cons mat&m){rt o<a( {{1,0,1,0,0}, {1,1,0,1,0}, {0,1,0,0,0}, {0,0,1,0,0}, {0,0,0,1,2}}); matv({{1,0,0,0,0}}); v.trs(); a=a.pow(N); a*=v; pt(a[4][0]); }