//#pragma GCC optimize ("-O3") #include using namespace std; //@起動時 struct initon { initon() { cin.tie(0); ios::sync_with_stdio(false); cout.setf(ios::fixed); cout.precision(16); srand((unsigned) clock() + (unsigned) time(NULL)); }; } __initon; //衝突対策 #define ws ___ws struct T { int f, s, t; T() { f = -1, s = -1, t = -1; } T(int f, int s, int t) : f(f), s(s), t(t) {} bool operator<(const T &r) const { return f != r.f ? f < r.f : s != r.s ? s < r.s : t < r.t; //return f != r.f ? f > r.f : s != r.s ? s > r.s : t > r.t; 大きい順 } bool operator>(const T &r) const { return f != r.f ? f > r.f : s != r.s ? s > r.s : t > r.t; //return f != r.f ? f > r.f : s != r.s ? s > r.s : t > r.t; 小さい順 } bool operator==(const T &r) const { return f == r.f && s == r.s && t == r.t; } bool operator!=(const T &r) const { return f != r.f || s != r.s || t != r.t; } int operator[](int i) { assert(i < 3); return i == 0 ? f : i == 1 ? s : t; } }; #define int long long #define ll long long #define double long double #define ull unsigned long long using dou = double; using itn = int; using str = string; using bo= bool; #define au auto using P = pair; #define fi first #define se second #define vec vector #define beg begin #define rbeg rbegin #define con continue #define bre break #define brk break #define is == //マクロ省略系 コンテナ using vi = vector; #define _overloadvvi(_1, _2, _3, _4, name, ...) name #define vvi0() vec #define vvi1(a) vec a #define vvi2(a, b) vec a(b) #define vvi3(a, b, c) vec a(b,vi(c)) #define vvi4(a, b, c, d) vec a(b,vi(c,d)) #define vvi(...) _overloadvvi(__VA_ARGS__,vvi4,vvi3,vvi2 ,vvi1,vvi0)(__VA_ARGS__) using vl = vector; #define _overloadvvl(_1, _2, _3, _4, name, ...) name #define vvl1(a) vec a #define vvl2(a, b) vec a(b) #define vvl3(a, b, c) vec a(b,vl(c)) #define vvl4(a, b, c, d) vec a(b,vl(c,d)) #define vvl(...) _overloadvvl(__VA_ARGS__,vvl4,vvl3,vvl2 ,vvl1)(__VA_ARGS__) using vb = vector; #define _overloadvvb(_1, _2, _3, _4, name, ...) name #define vvb1(a) vec a #define vvb2(a, b) vec a(b) #define vvb3(a, b, c) vec a(b,vb(c)) #define vvb4(a, b, c, d) vec a(b,vb(c,d)) #define vvb(...) _overloadvvb(__VA_ARGS__,vvb4,vvb3,vvb2 ,vvb1)(__VA_ARGS__) using vs = vector; #define _overloadvvs(_1, _2, _3, _4, name, ...) name #define vvs1(a) vec a #define vvs2(a, b) vec a(b) #define vvs3(a, b, c) vec a(b,vs(c)) #define vvs4(a, b, c, d) vec a(b,vs(c,d)) #define vvs(...) _overloadvvs(__VA_ARGS__,vvs4,vvs3,vvs2 ,vvs1)(__VA_ARGS__) using vd = vector; #define _overloadvvd(_1, _2, _3, _4, name, ...) name #define vvd1(a) vec a #define vvd2(a, b) vec a(b) #define vvd3(a, b, c) vec a(b,vd(c)) #define vvd4(a, b, c, d) vec a(b,vd(c,d)) #define vvd(...) _overloadvvd(__VA_ARGS__,vvd4,vvd3,vvd2 ,vvd1)(__VA_ARGS__) using vc=vector; #define _overloadvvc(_1, _2, _3, _4, name, ...) name #define vvc1(a) vec a #define vvc2(a, b) vec a(b) #define vvc3(a, b, c) vec a(b,vc(c)) #define vvc4(a, b, c, d) vec a(b,vc(c,d)) #define vvc(...) _overloadvvc(__VA_ARGS__,vvc4,vvc3,vvc2 ,vvc1)(__VA_ARGS__) using vp = vector

; #define _overloadvvp(_1, _2, _3, _4, name, ...) name #define vvp1(a) vec a #define vvp2(a, b) vec a(b) #define vvp3(a, b, c) vec a(b,vp(c)) #define vvp4(a, b, c, d) vec a(b,vp(c,d)) using vt = vector; #define _overloadvvt(_1, _2, _3, _4, name, ...) name #define vvt1(a) vec a #define vvt2(a, b) vec a(b) #define vvt3(a, b, c) vec a(b,vt(c)) #define vvt4(a, b, c, d) vec a(b,vt(c,d)) #define v3i(a, b, c, d) vector> a(b, vector(c, vi(d))) #define v3d(a, b, c, d) vector> a(b, vector(c, vd(d))) #define v3m(a, b, c, d) vector> a(b, vector(c, vm(d))) #define _vvi vector #define _vvl vector #define _vvb vector #define _vvs vector #define _vvd vector #define _vvc vector #define _vvp vector #define PQ priority_queue, greater > #define tos to_string using mapi = map; using mapd = map; using mapc = map; using maps = map; using seti = set; using setd = set; using setc = set; using sets = set; using qui = queue; #define bset bitset #define uset unordered_set #define mset multiset #define umap unordered_map #define umapi unordered_map #define umapp unordered_map #define mmap multimap //マクロ 繰り返し #define _overloadrep(_1, _2, _3, _4, name, ...) name # define _rep(i, n) for(int i = 0,_lim=n; i < _lim ; i++) #define repi(i, m, n) for(int i = m,_lim=n; i < _lim ; i++) #define repadd(i, m, n, ad) for(int i = m,_lim=n; i < _lim ; i+= ad) #define rep(...) _overloadrep(__VA_ARGS__,repadd,repi,_rep,)(__VA_ARGS__) #define _rer(i, n) for(int i = n; i >= 0 ; i--) #define reri(i, m, n) for(int i = m,_lim=n; i >= _lim ; i--) #define rerdec(i, m, n, dec) for(int i = m,_lim=n; i >= _lim ; i-=dec) #define rer(...) _overloadrep(__VA_ARGS__,rerdec,reri,_rer,)(__VA_ARGS__) #define fora(a, b) for(auto&& a : b) #define forg(gi, ve) for (int gi = 0, f, t, c; gi < ve.size() && (f = ve[gi].f, t = ve[gi].t, c = ve[gi].c, true); gi++) #define fort(gi, ve) for (int gi = 0, f, t, c; gi < ve.size() && (f = ve[gi].f, t = ve[gi].t, c = ve[gi].c, true); gi++)if(t!=p) //#define fort(gi, ve) for (int gi = 0, f, t, c;gi::min(); ll mi = numeric_limits::max(); const int y4[] = {-1, 1, 0, 0}; const int x4[] = {0, 0, -1, 1}; const int y8[] = {0, 1, 0, -1, -1, 1, 1, -1}; const int x8[] = {1, 0, -1, 0, 1, -1, 1, -1}; //マクロ省略形 関数等 #define arsz(a) (sizeof(a)/sizeof(a[0])) #define sz(a) ((int)(a).size()) #define rs resize #define mp make_pair #define pb push_back #define pf push_front #define eb emplace_back #define all(a) (a).begin(),(a).end() #define rall(a) (a).rbegin(),(a).rend() inline void sort(string &a) { sort(a.begin(), a.end()); } template inline void sort(vector &a) { sort(a.begin(), a.end()); }; template inline void sort(vector &a, int len) { sort(a.begin(), a.begin() + len); }; template inline void sort(vector &a, F f) { sort(a.begin(), a.end(), [&](T l, T r) { return f(l) < f(r); }); }; enum ___pcomparator { fisi, fisd, fdsi, fdsd, sifi, sifd, sdfi, sdfd }; inline void sort(vector

&a, ___pcomparator type) { switch (type) { case fisi: sort(all(a), [&](P l, P r) { return l.fi != r.fi ? l.fi < r.fi : l.se < r.se; }); break; case fisd: sort(all(a), [&](P l, P r) { return l.fi != r.fi ? l.fi < r.fi : l.se > r.se; }); break; case fdsi: sort(all(a), [&](P l, P r) { return l.fi != r.fi ? l.fi > r.fi : l.se < r.se; }); break; case fdsd: sort(all(a), [&](P l, P r) { return l.fi != r.fi ? l.fi > r.fi : l.se > r.se; }); break; case sifi: sort(all(a), [&](P l, P r) { return l.se != r.se ? l.se < r.se : l.fi < r.fi; }); break; case sifd: sort(all(a), [&](P l, P r) { return l.se != r.se ? l.se < r.se : l.fi > r.fi; }); break; case sdfi: sort(all(a), [&](P l, P r) { return l.se != r.se ? l.se > r.se : l.fi < r.fi; }); break; case sdfd: sort(all(a), [&](P l, P r) { return l.se != r.se ? l.se > r.se : l.fi > r.fi; }); break; } }; inline void sort(vector &a, ___pcomparator type) { switch (type) { case fisi: sort(all(a), [&](T l, T r) { return l.f != r.f ? l.f < r.f : l.s < r.s; }); break; case fisd: sort(all(a), [&](T l, T r) { return l.f != r.f ? l.f < r.f : l.s > r.s; }); break; case fdsi: sort(all(a), [&](T l, T r) { return l.f != r.f ? l.f > r.f : l.s < r.s; }); break; case fdsd: sort(all(a), [&](T l, T r) { return l.f != r.f ? l.f > r.f : l.s > r.s; }); break; case sifi: sort(all(a), [&](T l, T r) { return l.s != r.s ? l.s < r.s : l.f < r.f; }); break; case sifd: sort(all(a), [&](T l, T r) { return l.s != r.s ? l.s < r.s : l.f > r.f; }); break; case sdfi: sort(all(a), [&](T l, T r) { return l.s != r.s ? l.s > r.s : l.f < r.f; }); break; case sdfd: sort(all(a), [&](T l, T r) { return l.s != r.s ? l.s > r.s : l.f > r.f; }); break; } }; template inline void rsort(vector &a) { sort(a.begin(), a.end(), greater()); }; template inline void rsort(vector &a, int len) { sort(a.begin(), a.begin() + len, greater()); }; template inline void rsort(vector &a, F f) { sort(a.begin(), a.end(), [&](U l, U r) { return f(l) > f(r); }); }; template inline void sortp(vector &a, vector &b) { vp c; int n = sz(a); assert(n == sz(b)); rep(i, n)c.eb(a[i], b[i]); sort(c); rep(i, n) { a[i] = c[i].first; b[i] = c[i].second;; } }; //F = T //例えばreturn p.fi + p.se; template inline void sortp(vector &a, vector &b, F f) { vp c; int n = sz(a); assert(n == sz(b)); rep(i, n)c.eb(a[i], b[i]); sort(c, f); rep(i, n) { a[i] = c[i].first; b[i] = c[i].second; } }; template inline void sortp(vector &a, vector &b, char type) { vp c; int n = sz(a); assert(n == sz(b)); rep(i, n)c.eb(a[i], b[i]); sort(c, type); rep(i, n) { a[i] = c[i].first; b[i] = c[i].second; } }; template inline void rsortp(vector &a, vector &b) { vp c; int n = sz(a); assert(n == sz(b)); rep(i, n)c.eb(a[i], b[i]); rsort(c); rep(i, n) { a[i] = c[i].first; b[i] = c[i].second; } }; template inline void rsortp(vector &a, vector &b, F f) { vp c; int n = sz(a); assert(n == sz(b)); rep(i, n)c.eb(a[i], b[i]); rsort(c, f); rep(i, n) { a[i] = c[i].first; b[i] = c[i].second; } }; template inline void sortt(vector &a, vector &b, vector &c) { vt r; int n = sz(a); assert(n == sz(b)); assert(n == sz(c)); rep(i, n)r.eb(a[i], b[i], c[i]); sort(r); rep(i, n) { a[i] = r[i].f; b[i] = r[i].s; c[i] = r[i].t; } }; template inline void sortt(vector &a, vector &b, vector &c, F f) { vt r; int n = sz(a); assert(n == sz(b)); assert(n == sz(c)); rep(i, n)r.eb(a[i], b[i], c[i]); sort(r, f); rep(i, n) { a[i] = r[i].f; b[i] = r[i].s; c[i] = r[i].t; } }; template inline void rsortt(vector &a, vector &b, vector &c, F f) { vt r; int n = sz(a); assert(n == sz(b)); assert(n == sz(c)); rep(i, n)r.eb(a[i], b[i], c[i]); rsort(r, f); rep(i, n) { a[i] = r[i].f; b[i] = r[i].s; c[i] = r[i].t; } }; template inline void sort2(vector> &a) { for (int i = 0, n = a.size(); i < n; i++)sort(a[i]); } template inline void rsort2(vector> &a) { for (int i = 0, n = a.size(); i < n; i++)rsort(a[i]); } template void fill(A (&a)[N], const T &v) { rep(i, N)a[i] = v; } template void fill(A (&a)[N][O], const T &v) { rep(i, N)rep(j, O)a[i][j] = v; } template void fill(A (&a)[N][O][P], const T &v) { rep(i, N)rep(j, O)rep(k, P)a[i][j][k] = v; } template void fill(A (&a)[N][O][P][Q], const T &v) { rep(i, N)rep(j, O)rep(k, P)rep(l, Q)a[i][j][k][l] = v; } template void fill(A (&a)[N][O][P][Q][R], const T &v) { rep(i, N)rep(j, O)rep(k, P)rep(l, Q)rep(m, R)a[i][j][k][l][m] = v; } template void fill(A (&a)[N][O][P][Q][R][S], const T &v) { rep(i, N)rep(j, O)rep(k, P)rep(l, Q)rep(m, R)rep(n, S)a[i][j][k][l][m][n] = v; } template void fill(V &xx, const T vall) { xx = vall; } template void fill(vector &vecc, const T vall) { for (auto &&vx: vecc) fill(vx, vall); } //@汎用便利関数 入力 template T _in() { T x; cin >> x; return (x); } #define _overloadin(_1, _2, _3, _4, name, ...) name #define in0() _in() #define in1(a) cin>>a #define in2(a, b) cin>>a>>b #define in3(a, b, c) cin>>a>>b>>c #define in4(a, b, c, d) cin>>a>>b>>c>>d #define in(...) _overloadin(__VA_ARGS__,in4,in3,in2 ,in1,in0)(__VA_ARGS__) #define _overloaddin(_1, _2, _3, _4, name, ...) name #define din1(a) int a;cin>>a #define din2(a, b) int a,b;cin>>a>>b #define din3(a, b, c) int a,b,c;cin>>a>>b>>c #define din4(a, b, c, d) int a,b,c,d;cin>>a>>b>>c>>d #define din(...) _overloadin(__VA_ARGS__,din4,din3,din2 ,din1)(__VA_ARGS__) #define _overloaddind(_1, _2, _3, _4, name, ...) name #define din1d(a) int a;cin>>a;a-- #define din2d(a, b) int a,b;cin>>a>>b;a--,b-- #define din3d(a, b, c) int a,b,c;cin>>a>>b>>c;a--,b--,c-- #define din4d(a, b, c, d) int a,b,c,d;cin>>a>>b>>c>>d;;a--,b--,c--,d-- #define dind(...) _overloaddind(__VA_ARGS__,din4d,din3d,din2d ,din1d)(__VA_ARGS__) string sin() { return _in(); } ll lin() { return _in(); } #define na(a, n) a.resize(n); rep(i,n) cin >> a[i]; #define nao(a, n) a.resize(n+1); rep(i,n) cin >> a[i+1]; #define nad(a, n) a.resize(n); rep(i,n){ cin >> a[i]; a[i]--;} #define na2(a, b, n) a.resize(n),b.resize(n);rep(i, n)cin >> a[i] >> b[i]; #define na2d(a, b, n) a.resize(n),b.resize(n);rep(i, n){cin >> a[i] >> b[i];a[i]--,b[i]--;} #define na3(a, b, c, n) a.resize(n),b.resize(n),c.resize(n); rep(i, n)cin >> a[i] >> b[i] >> c[i]; #define na3d(a, b, c, n) a.resize(n),b.resize(n),c.resize(n); rep(i, n){cin >> a[i] >> b[i] >> c[i];a[i]--,b[i]--,c[i]--;} #define nt(a, h, w) resize(a,h,w);rep(hi,h)rep(wi,w) cin >> a[hi][wi]; #define ntd(a, h, w) rs(a,h,w);rep(hi,h)rep(wi,w) cin >> a[hi][wi], a[hi][wi]--; #define ntp(a, h, w) fill(a,'#');rep(hi,1,h+1)rep(wi,1,w+1) cin >> a[hi][wi]; //デバッグ #define sp << " " << #define debugName(VariableName) # VariableName #define _deb1(x) cerr << debugName(x)<<" = "< void rev(vector &a) { reverse(all(a)); } void rev(string &a) { reverse(all(a)); } ll ceil(ll a, ll b) { if (b == 0) { debugline("ceil"); deb(a, b); ole(); return -1; } else return (a + b - 1) / b; } ll sqrt(ll a) { if (a < 0) { debugline("sqrt"); deb(a); ole(); } ll res = (ll) std::sqrt(a); while (res * res < a)res++; return res; } double log(double e, double x) { return log(x) / log(e); } ll sig(ll t) { return (1 + t) * t / 2; } ll sig(ll s, ll t) { return (s + t) * (t - s + 1) / 2; } vi divisors(int v) { vi res; double lim = std::sqrt(v); for (int i = 1; i <= lim; ++i) { if (v % i == 0) { res.pb(i); if (i != v / i)res.pb(v / i); } } return res; } vb isPrime; vi primes; void setPrime() { int len = 4010101; isPrime.resize(4010101); fill(isPrime, true); isPrime[0] = isPrime[1] = false; for (int i = 2; i <= sqrt(len) + 5; ++i) { if (!isPrime[i])continue; for (int j = 2; i * j < len; ++j) { isPrime[i * j] = false; } } rep(i, len)if (isPrime[i])primes.pb(i); } vi factorization(int v) { int tv = v; vi res; if (isPrime.size() == 0)setPrime(); for (auto &&p :primes) { if (v % p == 0)res.push_back(p); while (v % p == 0) { v /= p; } if (v == 1 || p * p > tv)break; } if (v > 1)res.pb(v); return res; } inline bool inside(int h, int w, int H, int W) { return h >= 0 && w >= 0 && h < H && w < W; } inline bool inside(int v, int l, int r) { return l <= v && v < r; } #define ins inside ll u(ll a) { return a < 0 ? 0 : a; } template vector u(const vector &a) { vector ret = a; fora(v, ret)v = u(v); return ret; } #define MIN(a) numeric_limits::min() #define MAX(a) numeric_limits::max() template T sum(vector &v, int s = 0, int t = inf) { T ret = 0; rep(i, s, min(sz(v), t))ret += v[i]; return ret; } void yn(bool a) { if (a)cout << "yes" << endl; else cout << "no" << endl; } void Yn(bool a) { if (a)cout << "Yes" << endl; else cout << "No" << endl; } void YN(bool a) { if (a)cout << "YES" << endl; else cout << "NO" << endl; } void fyn(bool a) { if (a)cout << "yes" << endl; else cout << "no" << endl; exit(0); } void fYn(bool a) { if (a)cout << "Yes" << endl; else cout << "No" << endl; exit(0); } void fYN(bool a) { if (a)cout << "YES" << endl; else cout << "NO" << endl; exit(0); } void Possible(bool a) { if (a)cout << "Possible" << endl; else cout << "Impossible" << endl; exit(0); } void POSSIBLE(bool a) { if (a)cout << "POSSIBLE" << endl; else cout << "IMPOSSIBLE" << endl; exit(0); } template set &operator+=(set &a, U v) { a.insert(v); return a; } template vector &operator+=(vector &a, U v) { a.pb(v); return a; } void mod(int &a, int m) { a = (a % m + m) % m; } template inline int mgr(int ok, int ng, F f) { #define _mgrbody int mid = (ok + ng) / 2; if (f(mid))ok = mid; else ng = mid; if (ok < ng)while (ng - ok > 1) { _mgrbody } else while (ok - ng > 1) { _mgrbody } return ok; } template inline int mgr(int ok, int ng, int second, F f) { #define _mgrbody2 int mid = (ok + ng) / 2; if (f(mid, second))ok = mid; else ng = mid; if (ok < ng) while (ng - ok > 1) { _mgrbody2 } else while (ok - ng > 1) { _mgrbody2 } return ok; } constexpr bool bget(ll m, int keta) { return (m >> keta) & 1; } int bget(ll m, int keta, int sinsuu) { m /= (ll) pow(sinsuu, keta); return m % sinsuu; } ll bit(int n) { return (1LL << (n)); } ll bit(int n, int sinsuu) { return (ll) pow(sinsuu, n); } int mask(int n) { return (1ll << n) - 1; } #define bcou __builtin_popcountll template std::ostream &operator<<(std::ostream &stream, const vector &number) { fora(v, number) { stream << v << " "; } return stream; } int n, m, k, d, H, W, x, y, z, q; int cou; vi a, b, c; vvi (s, 0, 0); vvc (ba, 0, 0); vp p; //使いやすさ重視 多少遅い // // * は参照を取らない //^では参照を取る高速な * が使われる template struct mat {/*@formatter:off*/ int h, w; vector> d; mat() {} mat(int h, int w, T v = 0) : h(h), w(w), d(h, vector(w)) { if(h==w)unit(v); } mat(vector> &v) : h(sz(v)), w(sz(v[0])), d(v) {} mat(vector &v) : h(1), w(sz(v)) {d.push_back(v);} mat(initializer_list v) { h = 1, w = 0; fora(a, v)w++; d.assign(h, vector(w)); int nw = 0; fora(a, v) { d[0][nw] = a; nw++; } } mat(initializer_list> v) { h = 0, w = 0; fora(a, v)h++; fora(a, v) { fora(b, a)w++; break; } fora(a, v) { int cw = 0; fora(b, a)cw++; assert(w == cw);/*横の長さがすべて等しいことを調べる*/} d.assign(h, vector(w)); int nh = 0, nw = 0; fora(a, v) { nw = 0; fora(b, a) { d[nh][nw] = b; nw++; } nh++; } } vector &operator[](int i) { return d[i]; } void fill(T v = 0) { rep(i, h)rep(j, w) d[i][j] = v; } void unit(T v = 1) {assert(h==w); rep(i,h) d[i][i] = v; } mat operator+(mat &a) { /* same size*/ mat res(h, w); rep(i, h)rep(j, w) res[i][j] = d[i][j] + a[i][j]; return res; } mat operator-(mat &a) { /* same size*/ mat res(h, w); rep(i, h)rep(j, w) res[i][j] = d[i][j] - a[i][j]; return res; } //参照を取らないので使いやすい このmatは行列累乗では使わないため基本これでいい mat operator*(mat a) {mat res(h, a.w); rep(i, h)rep(k, w)rep(j, a.w) res[i][j] += d[i][k] * a[k][j]; return res; } //参照を取るので高速powなどで使う void mul_fast(mat &a) { vector > res(h,vector(w) ) ; rep(i, h)rep(k, w)rep(j, a.w) res[i][j] += d[i][k] * a[k][j]; swap(res,d); } mat &operator+=(mat &a) { return *this = (*this) + a; } mat &operator-=(mat &a) { return *this = (*this) - a; } mat &operator*=(mat a) { mul_fast(a);return *this; } mat operator^(ll n) { assert(h == w); mat x = *this; mat r(h, w); r.unit(); while (n) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; } mat &operator^=(ll n) {return *this=(this)^ n;} mat pow(ll n) { return operator^ (n); } }; template ostream &operator<<(ostream &os, mat vec) { for (int i = 0; i < vec.h; i++) { for (int j = 0; j < vec.w; j++) { os << vec[i][j]<<" "; } os << endl; } return os;}/*@formatter:on*///@formatter:off //使いやすさ重視 多少遅い //@formatter:off template T minv(T a, T m); template T minv(T a); template class Modular { public: using Type = typename decay::type; constexpr Modular() : value() {} template Modular(const U &x) { value = normalize(x); } template static Type normalize(const U &x) { Type v; if (-mod() <= x && x < mod()) v = static_cast(x); else v = static_cast(x % mod()); if (v < 0) v += mod(); return v; } const Type &operator()() const { return value; } templateexplicit operator U() const { return static_cast(value); } constexpr static Type mod() { return T::value; } Modular &operator+=(const Modular &other) { if ((value += other.value) >= mod()) value -= mod(); return *this; } Modular &operator-=(const Modular &other) { if ((value -= other.value) < 0) value += mod(); return *this; } template Modular &operator+=(const U &other) { return *this += Modular(other); } template Modular &operator-=(const U &other) { return *this -= Modular(other); } Modular &operator++() { return *this += 1; } Modular &operator--() { return *this -= 1; } Modular operator++(signed) { Modular result(*this); *this += 1; return result; } Modular operator--(signed) { Modular result(*this); *this -= 1; return result; } Modular operator-() const { return Modular(-value); } templatetypename enable_if::Type, signed>::value, Modular>::type &operator*=(const Modular &rhs) { #ifdef _WIN32 uint64_t x = static_cast(value) * static_cast(rhs.value);uint32_t xh = static_cast(x >> 32), xl = static_cast(x), d, m;asm("divl %4; \n\t": "=a" (d), "=d" (m): "d" (xh), "a" (xl), "r" (mod()));value = m; #else value = normalize(static_cast(value) * static_cast(rhs.value)); #endif return *this; } template typename enable_if::Type, int64_t>::value, Modular>::type &operator*=(const Modular &rhs) { int64_t q = static_cast(static_cast(value) * rhs.value / mod()); value = normalize(value * rhs.value - q * mod()); return *this; } template typename enable_if::Type>::value, Modular>::type &operator*=(const Modular &rhs) { value = normalize(value * rhs.value); return *this; } Modular &operator/=(const Modular &other) { return *this *= Modular(minv(other.value)); } template friend bool operator==(const Modular &lhs, const Modular &rhs); template friend bool operator<(const Modular &lhs, const Modular &rhs); template friend std::istream &operator>>(std::istream &stream, Modular &number); operator int() { return value; }private: Type value; }; template bool operator==(const Modular &lhs, const Modular &rhs) { return lhs.value == rhs.value; }template bool operator==(const Modular &lhs, U rhs) { return lhs == Modular(rhs); }template bool operator==(U lhs, const Modular &rhs) { return Modular(lhs) == rhs; }template bool operator!=(const Modular &lhs, const Modular &rhs) { return !(lhs == rhs); }template bool operator!=(const Modular &lhs, U rhs) { return !(lhs == rhs); }template bool operator!=(U lhs, const Modular &rhs) { return !(lhs == rhs); }template bool operator<(const Modular &lhs, const Modular &rhs) { return lhs.value < rhs.value; }template Modular operator+(const Modular &lhs, const Modular &rhs) { return Modular(lhs) += rhs; }template Modular operator+(const Modular &lhs, U rhs) { return Modular(lhs) += rhs; }template Modular operator+(U lhs, const Modular &rhs) { return Modular(lhs) += rhs; }template Modular operator-(const Modular &lhs, const Modular &rhs) { return Modular(lhs) -= rhs; }template Modular operator-(const Modular &lhs, U rhs) { return Modular(lhs) -= rhs; }template Modular operator-(U lhs, const Modular &rhs) { return Modular(lhs) -= rhs; }template Modular operator*(const Modular &lhs, const Modular &rhs) { return Modular(lhs) *= rhs; }template Modular operator*(const Modular &lhs, U rhs) { return Modular(lhs) *= rhs; }template Modular operator*(U lhs, const Modular &rhs) { return Modular(lhs) *= rhs; }template Modular operator/(const Modular &lhs, const Modular &rhs) { return Modular(lhs) /= rhs; }template Modular operator/(const Modular &lhs, U rhs) { return Modular(lhs) /= rhs; }template Modular operator/(U lhs, const Modular &rhs) { return Modular(lhs) /= rhs; } //@formatter:off int MOD = 1000000007; struct mint { int x; mint() : x(0) {} mint(int a) { x = a % MOD; if (x < 0) x += MOD; } mint &operator+=(mint that) { x = (x + that.x) % MOD; return *this; } mint &operator-=(mint that) { x = (x + MOD - that.x) % MOD; return *this; } mint &operator*=(mint that) { x = (int) x * that.x % MOD; return *this; } mint &operator/=(mint that) { return *this *= that.inverse(); } mint operator-() { return mint(-this->x); } friend ostream &operator<<(ostream &out, mint m) { return out << m.x; } mint inverse() { int a = x, b = MOD, u = 1, v = 0; while (b) { int t = a / b; a -= t * b; u -= t * v; swap(a, b); swap(u, v); } return mint(u); }mint operator+(mint that) { return mint(*this) += that; } mint operator-(mint that) { return mint(*this) -= that; } mint operator*(mint that) { return mint(*this) *= that; } mint operator/(mint that) { return mint(*this) /= that; } bool operator ==(mint that) const { return x == that.x; } bool operator !=(mint that) const { return x != that.x; } bool operator <(mint that) const { return x < that.x; } bool operator <=(mint that) const { return x <= that.x; } bool operator >(mint that) const { return x > that.x; } bool operator >=(mint that) const { return x >= that.x; }}; istream &operator>>(istream &i, mint &a) { i >> a.x; return i;} typedef vector vm; vector fac, finv; int mint_len = 1400000; void setmod(int mod = 1e9 + 7) { MOD = mod; fac = vector(mint_len + 1); finv = vector(mint_len + 1); fac[0] = 1; rep(i, 1, mint_len + 1) fac[i] = fac[i - 1] * i; finv[mint_len] = (mint) 1 / fac[mint_len]; rer(i, mint_len, 1) finv[i - 1] = finv[i] * i;} mint com(int a, int b) { if (a < 0) return 0; if (b < 0 || b > a) return 0; return fac[a] * finv[a - b] * finv[b];} mint hom(int a, int b) { return com(a + b - 1, b);} template mint mpow(const T a, const U b) { assert(b >= 0); int x = a, res = 1; U p = b; while (p > 0) { if (p & 1) (res *= x) %= MOD; (x *= x) %= MOD; p >>= 1; } return res;} template inline mint mpow(const T a, const mint b) { int x = a, res = 1; int p = b.x; while (p > 0) { if (p & 1) (res *= x) %= MOD; (x *= x) %= MOD; p >>= 1; } return res;} using PM = pair; using vm = vector; #define vvm(...) o_vvt(__VA_ARGS__,vvt4,vvt3,vvt2 ,vvt1,vvt0)(mint,__VA_ARGS__) #define smod setmod //setmodを呼ぶ @formatter:on signed main() { in(n, k); vm a; na(a, n); using M = mat; if (n > 30) { vm f(k + 1); rep(i, n) f[i + 1] = a[i]; mint su = sum(a); mint res = sum(a); rep(i, n + 1, k + 1) { f[i] = su; res += f[i]; su -= f[i - n]; su += f[i]; } cout << f[k] << " " << res << endl; } else { a += sum(a) - a.back(); M l(a); M r(n + 1, n + 1); rep(i, n - 1)r[i + 1][i] = 1; rep(i, n)r[i][n - 1] = 1; r[n - 1][n] = 1; r[n][n] = 1; //一番後ろがkの時に演算をするとok l *= r ^ (k + 1 - n); cout << l[0][n - 2] << " " << l[0][n] << endl; } return 0; }