//#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 pow powl #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; using vb = vector; using vs = vector; using vd = vector; using vc = vector; using vp = vector

; using vt = vector; #define vec vector #define o_vvt(o1, o2, o3, o4, name, ...) name #define vvt0(t) vec> #define vvt1(t, a) vec>a #define vvt2(t, a, b) vec>a(b) #define vvt3(t, a, b, c) vec> a(b,vec(c)) #define vvt4(t, a, b, c, d) vec> a(b,vec(c,d)) #define vvi(...) o_vvt(__VA_ARGS__,vvt4,vvt3,vvt2 ,vvt1,vvt0)(ll,__VA_ARGS__) #define vvb(...) o_vvt(__VA_ARGS__,vvt4,vvt3,vvt2 ,vvt1,vvt0)(bool,__VA_ARGS__) #define vvs(...) o_vvt(__VA_ARGS__,vvt4,vvt3,vvt2 ,vvt1,vvt0)(string,__VA_ARGS__) #define vvd(...) o_vvt(__VA_ARGS__,vvt4,vvt3,vvt2 ,vvt1,vvt0)(double,__VA_ARGS__) #define vvc(...) o_vvt(__VA_ARGS__,vvt4,vvt3,vvt2 ,vvt1,vvt0)(char,__VA_ARGS__) #define vvp(...) o_vvt(__VA_ARGS__,vvt4,vvt3,vvt2 ,vvt1,vvt0)(P,__VA_ARGS__) #define vvt(...) o_vvt(__VA_ARGS__,vvt4,vvt3,vvt2 ,vvt1,vvt0)(T,__VA_ARGS__) template vector make_v(size_t a) { return vector(a); } template auto make_v(size_t a, Ts... ts) { return vector(ts...))>(a, make_v(ts...)); } #define vni(name, ...) auto name = make_v(__VA_ARGS__) #define vnb(name, ...) auto name = make_v(__VA_ARGS__) #define vns(name, ...) auto name = make_v(__VA_ARGS__) #define vnd(name, ...) auto name = make_v(__VA_ARGS__) #define vnc(name, ...) auto name = make_v(__VA_ARGS__) #define vnp(name, ...) auto name = make_v

(__VA_ARGS__) #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 k3 1010 #define k4 10101 #define k5 101010 #define k6 1010101 #define k7 10101010 const int inf = (int) 1e9 + 100; const ll linf = (ll) 1e18 + 100; const double eps = 1e-9; const double PI = 3.1415926535897932384626433832795029L; ll ma = numeric_limits::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(nai,n) cin >> a[nai]; #define nao(a, n) a.resize(n+1); rep(i,n) cin >> a[i+1]; #define nad(a, n)a.resize(n); rep(nadi,n){ cin >> a[nadi]; a[nadi]--;} #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) a.resize(h);rep(i,h)a[i].resize(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]; #ifdef _DEBUG template void err2(T &&head) { cerr << head; } template void err2(T &&head, U &&... tail) { cerr << head << " "; err2(tail...); } template void err(T &&head, U &&... tail) { cerr << head << " "; err2(tail...); cerr << "" << endl; } template void err(T &&head) { cerr << head << endl; } void err() { cerr << "" << endl; } template string out_m2(vector &a, ll W = inf) { stringstream ss; if (W == inf)W = min(sz(a), 12ll); if (sz(a) == 0)return ss.str(); rep(i, W) { ss << a[i] << " "; } return ss.str(); } template string out_m2(vector > &a, ll H = inf, ll W = inf, int key = -1) { H = min({H, sz(a), 12ll}); W = min({W, sz(a[0]), 12ll}); stringstream ss; ss << endl; if (key == -1)ss << " *|"; else ss << " " << key << "|"; rep(w, W)ss << std::right << std::setw(4) << w; ss << "" << endl; rep(w, W * 4 + 3)ss << "_"; ss << "" << endl; rep(h, H) { ss << std::right << std::setw(2) << h << "|"; rep(w, min(sz(a[h]), 12ll)) { if (abs(a[h][w]) == linf) ss << " e" << ""; else ss << std::right << std::setw(4) << a[h][w]; } ss << "" << endl; } return ss.str(); } /*@formatter:off*/ template string out_m2(vector > > &a, ll H = inf, ll W = inf, ll U = inf) {stringstream ss; if (H == inf)H = 5; H = min(H, sz(a)); rep(i, H) { ss << endl; ss << out_m2(a[i], W, U, i); } return ss.str();} string out_m2(int a) {stringstream ss;ss << a;return ss.str();} template string out_m2(T &a) {stringstream ss;ss << a;return ss.str();} template string out_m(vector &a, ll W = inf) {stringstream ss; if (W == inf)W = min(sz(a), 12ll); if(sz(a)==0)return ss.str(); rep(i, W) { ss << a[i] << " "; } ss << "" << endl; return ss.str();} template string out_m(vector > &a, ll H = inf, ll W = inf, int key = -1) { H = min({H, sz(a), 12ll}); W = min({W, sz(a[0]), 12ll}); stringstream ss; ss << endl; if (key == -1)ss << " *|"; else ss << " " << key << "|"; rep(w, W)ss << std::right << std::setw(4) << w; ss << "" << endl; rep(w, W * 4 + 3)ss << "_"; ss << "" << endl; rep(h, H) { ss << std::right << std::setw(2) << h << "|"; rep(w, min(sz(a[h]),12ll)) { if (abs(a[h][w]) == linf) ss << " e" << ""; else ss << std::right << std::setw(4) << a[h][w]; } ss << "" << endl; } ss << endl; return ss.str(); } /*@formatter:off*/ template string out_m(vector > > &a, ll H = inf, ll W = inf, ll U = inf) {stringstream ss; if (H == inf)H = 5; H = min(H, sz(a)); rep(i, H) { ss << endl; ss << out_m(a[i], W, U, i); } ss << endl; return ss.str();} string out_m(int a) {stringstream ss;ss << a << endl;return ss.str();} template string out_m(T &a) {stringstream ss;ss << a << endl;return ss.str();} template void outv(vector &a, ll W=inf) {cout << out_m(a,W) << endl;} template void outv(vector > &a, ll H = linf, ll W = linf,int key=-1) { cout << out_m(a,H,W,key) << endl;} template void outv(vector > > &a, ll H = linf, ll W = linf,ll U = linf) {cout << out_m(a,H,W,U)<< endl;} #else template void outv(vector &a, ll W = inf) { rep(i, min(W, sz(a))) { cout << a[i] << " "; } cout << "" << endl; } template void outv(vector > &a, ll H = linf, ll W = linf, int key = -1) { rep(i, min(H, sz(a))) { outv(a[i], W); }} template void outv(vector > > &a, ll H = linf, ll W = linf, ll U = linf) { ; } #define err(...); #endif #define debugName(VariableName) # VariableName #define deb1(x) 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; } /*@formatter:off*/ 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() 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; } 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 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; } vp run_length(vi &a) { vp ret; ret.eb(a[0], 1); rep(i, 1, sz(a)) { if (ret.back().fi == a[i]) { ret.back().se++; } else { ret.eb(a[i], 1); }} return ret;} vector> run_length(string &a) { vector> ret; ret.eb(a[0], 1); rep(i, 1, sz(a)) { if (ret.back().fi == a[i]) { ret.back().se++; } else { ret.eb(a[i], 1); }} return ret;} template ostream &operator<<(ostream &os, vector &m) { for (auto &&v:m) os << v << " "; return os; } 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; } bool subset(int sub, int top) {return (sub & top) == sub;} ll bit(int n) { return (1LL << (n)); } ll bit(int n, int sinsuu) { return (ll) pow(sinsuu, n); } //aをbitに置きなおす //{0, 2} -> 101 ll biti(vi&a){ int m=0; for(auto&& v:a) m|=bit(v); return m;} //{1, 1, 0} -> 011 ll bitb(vi&a){ int m=0; rep(i,sz(a)) if(a[i])m|=bit(i); return m;} int mask(int n) { return (1ll << n) - 1; } #define bcou __builtin_popcountll // //imoは0-indexed //ruiは1-indexed template vector imo(vector &v) { vector ret = v; rep(i, sz(ret) - 1)ret[i + 1] += ret[i]; return ret;} //kと同じものの数 template vi imo(vector &a, U k) {vector ret = a;rep(i, sz(ret))ret[i] = a[i] == k;rep(i, sz(ret) - 1)ret[i + 1] += ret[i];return ret;} template vector imox(vector &v) { vector ret = v; rep(i, sz(ret) - 1)ret[i + 1] ^= ret[i]; return ret;} //漸化的に最小を持つ template vector imi(vector &v) { vector ret = v; rep(i, sz(ret) - 1)chmi(ret[i + 1], ret[i]); return ret;} template struct ruiC { const vector rui; ruiC(vector &ru) : rui(ru) {} T operator()(ll l, ll r) { if (l > r) { cerr<<"ruic ";deb(l, r);assert(0); } return rui[r] - rui[l]; } T operator[](ll i) { return rui[i]; } T back() { return rui.back(); } ll size() { return rui.size(); }}; template struct rruic { const T *rrui; rruic(T *ru) : rrui(ru) {} T operator()(ll l, ll r) { assert(l >= r); return rrui[r] - rrui[l]; } T operator[](ll i) { return rrui[i]; }}; templateostream &operator<<(ostream &os, ruiC a) {fora(v,a.rui)os< vector ruiv(vector &a) { vector ret(a.size() + 1); rep(i, a.size())ret[i + 1] = ret[i] + a[i]; return ret;} template ruiC ruic(vector &a) { vector ret = ruiv(a); return ruiC(ret);} vector ruiv(string &a) { if (sz(a) == 0)return vi(1); ll dec = ('0' <= a[0] && a[0] <= '9') ? '0' : 0; vector ret(a.size() + 1); rep(i, a.size())ret[i + 1] = ret[i] + a[i] - dec; return ret;} ruiC ruic(string &a) { vector ret = ruiv(a); return ruiC(ret);} //kと同じものの数 template vi ruiv(T &a, U k) { vi ret(a.size() + 1); rep(i, a.size())ret[i + 1] = ret[i] + (a[i] == k); return ret;} template ruiC ruic(T &a, U k) { vi ret = ruiv(a, k); return ruiC(ret);} //xor template struct ruixC { const vector rui; ruixC(vector &ru) : rui(ru) {} T operator()(ll l, ll r) { if (l > r) { cerr << "ruiXc "; deb(l, r); assert(0); } return rui[r] ^ rui[l]; } T operator[](ll i) { return rui[i]; } T back() { return rui.back(); } ll size() { return rui.size(); }}; template vector ruix(vector &a) { vector ret(a.size() + 1); rep(i, a.size())ret[i + 1] = ret[i] ^ a[i]; return ret;} template ruixC ruixc(vector &a) {vi ret = ruix(a);return ruixC(ret);} template vector ruim(vector &a) { vector res(a.size() + 1, 1); rep(i, a.size())res[i + 1] = res[i] * a[i]; return res;} //漸化的に最小を1indexで持つ template vector ruimi(vector &a) { ll n = sz(a); vector ret(n + 1); rep(i, 1, n) { ret[i] = a[i - 1]; chmi(ret[i + 1], ret[i]); } return ret;} //template T *rrui(vector &a) { //右から左にかけての半開区間 (-1 n-1] template rruic rrui(vector &a) { ll len = a.size(); T *body = (T *) malloc((len + 1) * sizeof(T)); T *res = body + 1; rer(i, len - 1)res[i - 1] = res[i] + a[i]; return rruic(res);} //掛け算 template T *rruim(vector &a) { ll len = a.size(); T *body = (T *) malloc((len + 1) * sizeof(T)); T *res = body + 1; res[len - 1] = 1; rer(i, len - 1)res[i - 1] = res[i] * a[i]; return res;} // template inline bool chma(T &a, const U &b) { if (a < b) { a = b; return true; } return false; } template inline bool chma(const U &b) { return chma(ma, b); } template inline bool chmi(T &a, const U &b) { if (b < a) { a = b; return true; } return false; } template inline bool chmi(const U &b) { return chmi(mi, b); } #define unique(v) v.erase( unique(v.begin(), v.end()), v.end() ); int max(vi &a) { int res = a[0]; fora(v, a) { res = max(res, v); } return res; } int min(vi &a) { int res = a[0]; fora(v, a) { res = min(res, v); } return res; } template class fixed_point : T {public: explicit constexpr fixed_point(T &&t) noexcept: T(std::forward(t)) {} template constexpr decltype(auto) operator()(Args &&... args) const { return T::operator()(*this, std::forward(args)...); }};template static inline constexpr decltype(auto) fix(T &&t) noexcept { return fixed_point{std::forward(t)}; } #define lam(right) [&](auto& p){return p right;} template void resize(vector &vec, const H head) { vec.resize(head); }template void resize(vector &vec, const H &head, const T ... tail) {vec.resize(head);for (auto &v: vec)resize(v, tail...);} template bool all_of2(T &v, F f) { return f(v); } template bool all_of2(vector &v, F f) { rep(i, sz(v)) { if (!all_of2(v[i], f))return false; } return true;} template bool any_of2(T &v, F f) { return f(v); } template bool any_of2(vector &v, F f) { rep(i, sz(v)) { if (any_of2(v[i], f))return true; } return false;} template bool none_of2(T &v, F f) { return f(v); } template bool none_of2(vector &v, F f) { rep(i, sz(v)) { if (none_of2(v[i], f))return false; } return true;} template bool find_if2(T &v, F f) { return f(v); } template ll find_if2(vector &v, F f) { rep(i, sz(v)) { if (find_if2(v[i], f))return i; } return sz(v);} template bool rfind_if2(T &v, F f) { return f(v); } template ll rfind_if2(vector &v, F f) { rer(i, sz(v) - 1) { if (rfind_if2(v[i], f))return i; } return -1;} template bool contains(string &s, const T &v) { return s.find(v) != string::npos; } template bool contains(vector &v, const T &val) { return std::find(v.begin(), v.end(), val) != v.end(); } template bool contains_if2(vector &v, F f) { return find_if(v.begin(), v.end(), f) != v.end(); } template ll count_if2(T &v, F f) { return f(v); } template ll count_if2(vector &vec, F f) { ll ret = 0; fora(v, vec)ret += count_if2(v, f); return ret;} template void for_each2(T &v, F f) { f(v); } template void for_each2(vector &vec, F f) { fora(v, vec)for_each2(v, f); } template ll count_od(vector &a) {return count_if2(a,[](ll v){return v&1 ;});} template ll count_ev(vector &a) {return count_if2(a,[](ll v){return !(v&1) ;});} //削除された要素の数を返す template int erase_if2(vector &v, F f) {vector nv;int cou = 0;rep(i, sz(v)) {if (f(v[i])) {cou++;} else {nv.push_back(v[i]);}}v = nv;return cou;} template int erase_if2(vector> &v, F f) {int cou = 0;rep(i, sz(v)) {cou += erase_if2(v[i], f);}return cou;} #define all_of(a,right) all_of2(a,lam(right)) #define all_of_f(a,f) all_of2(a,f) #define any_of(a,right) any_of2(a,lam(right)) #define any_of_f(a,f) any_of2(a,f) #define none_of(a,right) none_of2(a,lam(right)) #define none_of_f(a,f) none_of2(a,f) #define find_if(a,right) find_if2(a,lam(right)) #define find_if_f(a,f) find_if2(a,f) #define rfind_if(a,right) rfind_if2(a,lam(right)) #define rfind_if_f(a,f) rfind_if2(a,f) #define contains_if(a,right) contains_if2(a,lam(right)) #define contains_if_f(a,f) contains_if2(a,f) #define count_if(a, right) count_if2(a,lam(right)) #define count_if_f(a, f) count_if2(a,f) #define for_each(a, right) do{fora(v,a){v right;}}while(0) #define for_each_f(a, f) do{fora(v,a){f(v);}}while(0) #define erase_if(a,right) erase_if2(a,lam(right)) #define erase_if_f(a,f) erase_if2(a,f) #define dna(a, n) vi a(n); rep(dnai,n) cin >> a[dnai]; #define binarySearch(a, v) (binary_search(all(a),v)) #define lowerIndex(a, v) (lower_bound(all(a),v)-a.begin()) #define upperIndex(a, v) (upper_bound(all(a),v)-a.begin()) #define rlowerIndex(a, v) (upper_bound(all(a),v)-a.begin()-1) #define rupperIndex(a, v) (lower_bound(all(a),v)-a.begin()-1) template T lowerBound(vector& a, U v, W banpei){ auto it = lower_bound(a.begin(),a.end(),v); if(it==a.end())return banpei; else return *it;} template T upperBound(vector& a, U v, W banpei){ auto it = upper_bound(a.begin(),a.end(),v); if(it==a.end())return banpei; else return *it;} template T rlowerBound(vector &a, U v, W banpei) { auto it = upper_bound(a.begin(), a.end(), v); if (it == a.begin())return banpei; else{ return *(--it); }} template T rupperBound(vector &a, U v, W banpei) { auto it = lower_bound(a.begin(), a.end(), v); if (it == a.begin())return banpei; else{ return *(--it); }} /*@formatter:on*/ template T min(vector> &a) { T res = MAX(T); rep(i, a.size())chmi(res, *min_element(all(a[i]))); return res; } template T max(vector> &a) { T res = MIN(T); rep(i, a.size())chma(res, *max_element(all(a[i]))); return res; } template T min(vector >> &a) { T res = MAX(T); rep(i, a.size())chmi(res, min(a[i])); return res; } template T max(vector >> &a) { T res = MIN(T); rep(i, a.size())chma(res, max(a[i])); return res; } template void out2(T &&head) { cout << head; } template void out2(T &&head, U &&... tail) { cout << head << " "; out2(tail...); } template void out(T &&head, U &&... tail) { cout << head << " "; out2(tail...); cout << "" << endl; } template void out(T &&head) { cout << head << endl; } void out() { cout << "" << endl; } template void fin(T a) { out(a); exit(0); } template void insert(vector &v, unsigned ll i, U t) { v.insert(v.begin() + i, t); } int N, K, H, W; vi A, B, C; namespace pnumber_tools {//@formatter:off class Eratosthenes { public:virtual void initialize() {} virtual void generate(const int64_t x) = 0; virtual void generate(const int64_t from, const int64_t to) = 0; virtual int64_t count() = 0; virtual bool prime(int x) = 0; virtual int32_t version() = 0; inline uint64_t PopCnt(uint64_t); inline int BitToIndex(uint8_t); }; uint64_t Eratosthenes::PopCnt(uint64_t bits) { bits = (bits & 0x5555555555555555ULL) + ((bits >> 1) & 0x5555555555555555ULL); bits = (bits & 0x3333333333333333ULL) + ((bits >> 2) & 0x3333333333333333ULL); bits = (bits & 0x0f0f0f0f0f0f0f0fULL) + ((bits >> 4) & 0x0f0f0f0f0f0f0f0fULL); return (bits * 0x0101010101010101ULL) >> (64 - 8); } int Eratosthenes::BitToIndex(uint8_t b) { switch (b) { case 1 << 0: return 0; case 1 << 1: return 1; case 1 << 2: return 2; case 1 << 3: return 3; case 1 << 4: return 4; case 1 << 5: return 5; case 1 << 6: return 6; case 1 << 7: return 7; } return -1; } namespace { constexpr uint64_t kSegmentSize = 1000000; constexpr int32_t kMod30[] = {1, 7, 11, 13, 17, 19, 23, 29}; constexpr int C1[] = {6, 4, 2, 4, 2, 4, 6, 2}; constexpr int C0[][8] = {{0, 0, 0, 0, 0, 0, 0, 1}, {1, 1, 1, 0, 1, 1, 1, 1}, {2, 2, 0, 2, 0, 2, 2, 1}, {3, 1, 1, 2, 1, 1, 3, 1}, {3, 3, 1, 2, 1, 3, 3, 1}, {4, 2, 2, 2, 2, 2, 4, 1}, {5, 3, 1, 4, 1, 3, 5, 1}, {6, 4, 2, 4, 2, 4, 6, 1},}; constexpr uint8_t kMask[][8] = {{0xfe, 0xfd, 0xfb, 0xf7, 0xef, 0xdf, 0xbf, 0x7f}, {0xfd, 0xdf, 0xef, 0xfe, 0x7f, 0xf7, 0xfb, 0xbf}, {0xfb, 0xef, 0xfe, 0xbf, 0xfd, 0x7f, 0xf7, 0xdf}, {0xf7, 0xfe, 0xbf, 0xdf, 0xfb, 0xfd, 0x7f, 0xef}, {0xef, 0x7f, 0xfd, 0xfb, 0xdf, 0xbf, 0xfe, 0xf7}, {0xdf, 0xf7, 0x7f, 0xfd, 0xbf, 0xfe, 0xef, 0xfb}, {0xbf, 0xfb, 0xf7, 0x7f, 0xfe, 0xef, 0xdf, 0xfd}, {0x7f, 0xbf, 0xdf, 0xef, 0xf7, 0xfb, 0xfd, 0xfe},}; constexpr int64_t kSievedPrimes[] = {2, 3, 5, 7, 11, 13, 17, 19, 23}; constexpr int64_t kInitialSize = 7 * 11 * 13 * 17 * 19 * 23; constexpr int imap[] = {-1, 0, -1, -1, -1, -1, -1, 1, -1, -1, -1, 2, -1, 3, -1, -1, -1, 4, -1, 5, -1, -1, -1, 6, -1, -1, -1, -1, -1, 7}; class Eratosthenes2 final : public Eratosthenes { public: void generate(const int64_t x) override; void generate(const int64_t, const int64_t) override { assert(false); } bool prime(int x) override; int64_t count() override; int32_t version() override { return 2; } vector flags_; }; void Eratosthenes2::generate(const int64_t x) { flags_.clear(); if (x > 10000000000) return; int64_t size = x / 30 + (x % 30 != 0); flags_.resize(size, 0xff); if (int r = x % 30) { if (r <= 1) flags_[size - 1] = 0x0; else if (r <= 7) flags_[size - 1] = 0x1; else if (r <= 11) flags_[size - 1] = 0x3; else if (r <= 13) flags_[size - 1] = 0x7; else if (r <= 17) flags_[size - 1] = 0xf; else if (r <= 19) flags_[size - 1] = 0x1f; else if (r <= 23) flags_[size - 1] = 0x3f; else if (r <= 29) flags_[size - 1] = 0x7f; } flags_[0] = 0xfe; const uint64_t sqrt_x = std::ceil(std::sqrt(x) + 0.1); const uint64_t sqrt_xi = sqrt_x / 30 + 1; for (uint64_t i = 0; i < sqrt_xi; ++i) { for (uint8_t flags = flags_[i]; flags; flags &= flags - 1) { uint8_t lsb = flags & (-flags); int ibit = BitToIndex(lsb); const int32_t m = kMod30[ibit]; int32_t pm = 30 * i + 2 * m; for (uint64_t j = i * pm + (m * m) / 30, k = ibit; j < flags_.size(); j += i * C1[k] + C0[ibit][k], k = (k + 1) & 7) { flags_[j] &= kMask[ibit][k]; } } } } int64_t Eratosthenes2::count() { if (flags_.empty()) return -1; int64_t ret = 3; for (uint8_t f : flags_) { ret += PopCnt(f); } return ret; } inline bool Eratosthenes2::prime(int x) { if (x == 2 || x == 3 || x == 5)return true; else if (!(x & 1) || x % 3 == 0 || x % 5 == 0)return false; return (flags_[x / 30] >> imap[x % 30]) & 1; } } Eratosthenes2 era; int prime_len = 3e6; vector primes; void setprime(int size = 3e6) { prime_len = size; era.generate(size); primes = {2, 3, 5}; int nums[129] = {}; nums[1] = 1; nums[2] = 7; nums[4] = 11; nums[8] = 13; nums[16] = 17; nums[32] = 19; nums[64] = 23; nums[128] = 29; /*p = 30i + j*/ int j = 0; int sflim = era.flags_.size(); int i30 = 0; for (int i = 0; i < sflim; i++, i30 += 30) { uint8_t m = era.flags_[i]; while (m) { j = m & -m; primes.push_back(i30 + nums[j]); m ^= j; } } } using u32 = unsigned int;//longlongになっていると思うが放置していいと思う using u64 = unsigned long long; using u128 = __uint128_t; //O(k log(n)^3) //32bit -> 270回程度 //64bit -> 1260回程度 //64bit以下で精度100% template bool miller_rabin(const uint64_t &n, const uint64_t *witness, BinOp modmul) { if (n == 2) return true; if (n < 2 || n % 2 == 0) return false; const int64_t m = n - 1, d = m / (m & -m); auto modpow = [&](int64_t a, int64_t b) { int64_t res = 1; for (; b; b /= 2) { if (b & 1) res = modmul(res, a); a = modmul(a, a); } return res; }; auto suspect = [&](uint64_t a, uint64_t t) { a = modpow(a, t); while (t != n - 1 && a != 1 && a != n - 1) { a = modmul(a, a); t = modmul(t, 2); } return a == n - 1 || t % 2 == 1; }; for (const uint64_t *w = witness; *w; w++) { if (*w % n != 0 && !suspect(*w, d)) return false; } return true; } //miller_rabin & エラトステネス bool prime(const int &n) { assert(n < 9223372036854775808ULL); if (!sz(primes))setprime(); /*エラトステネスの篩 偶数省略ver [i] = i*2+1*/ if (n < prime_len)return era.prime(n); if (n < 4294967296) { rep(i, 30) if (!(n % primes[i]))return false; constexpr uint64_t witness[] = {2, 7, 61, 0}; auto modmul = [&](uint64_t a, uint64_t b) -> uint64_t { return a * b % n; }; return miller_rabin(n, witness, modmul); } else { rep(i, 50) if (!(n % primes[i]))return false; constexpr uint64_t witness[] = {2, 325, 9375, 28178, 450775, 9780504, 1795265022, 0}; auto modmul = [&](uint64_t a, uint64_t b) -> uint64_t { return (uint64_t) ((__uint128_t) a * b % n); }; return miller_rabin(n, witness, modmul); }} #define isprime prime vi divisors(int v) { vi res; dou lim = std::sqrt(v); for (int i = 1; i <= lim; ++i) { if (v % i == 0) { res.push_back(i);/* if (i != v / i)res.push_back(v / i);*/ } } rer(i, sz(res) - 1) { if (res[i] != v / res[i])res.push_back(v / res[i]); } return res; } #define divi divisors vp factorization(int v) { assert(v); int tv = v; vp res; if (!sz(primes))setprime(); for (auto &&p :primes) { if (v % p == 0)res.eb(p, 0); while (v % p == 0) { v /= p; res.back().second++; } if (v == 1 || p * p > tv)break; } if (v > 1)res.eb(v, 1); return res; } map factorization_map(int v) { assert(v); int tv = v; vp res; if (!sz(primes))setprime(); for (auto &&p :primes) { if (v % p == 0)res.eb(p, 0); while (v % p == 0) { v /= p; res.back().second++; } if (v == 1 || p * p > tv)break; } if (v > 1)res.eb(v, 1); map nres; fora(r,res){ nres[r.fi]=r.se; } return nres; } //注意 gcdを取る間隔 i%10 が場合によってはtleを引き起こす //うまくいかなかったら%1で動かすように変更した vp rho(int v) { assert(v); if (v == 1)return vp(); vi ret; if (!sz(primes)) setprime(); int lim = 300; /*64bit*/ if (v < 4294967296)lim = 80; /*32bit*/ else if (v < 281474976710656LL)lim = 120; /*48bit*/ for (int i = 0; i < lim; i += 5) { /*v<=1の判定回数を減らせる分高速化できる事を期待している*/ while (v % primes[i] == 0) ret.push_back(primes[i]), v /= primes[i]; while (v % primes[i + 1] == 0) ret.push_back(primes[i + 1]), v /= primes[i + 1]; while (v % primes[i + 2] == 0) ret.push_back(primes[i + 2]), v /= primes[i + 2]; while (v % primes[i + 3] == 0) ret.push_back(primes[i + 3]), v /= primes[i + 3]; while (v % primes[i + 4] == 0) ret.push_back(primes[i + 4]), v /= primes[i + 4]; if (v <= 1) { sort(ret);/*試し割りだけで終わった時*/ return run_length(ret); } } int lower_prime_bound = primes[lim - 1] * primes[lim - 1]; /*試し割りするか*/ mt19937 mr; mr.seed(clock()); int c; auto fac = [&](int v, const int loop = 10) {/* if (v == 4)return 2ll; //試し割りで消えた*/ c = mr() % v; int x = mr() % v; int y = x; int d = 1; int lim = sqrt(v) + 2; /*brentによる改良 差分を一操作で求められる*/ for (int i = 1, mul = 1, next_2pow = 2; d == 1 && i <= lim; i++) { if (i == next_2pow) { y = x; next_2pow <<= 1; } x = ((u128) x * x + c) % v; mul = ((u128) mul * abs(x - y)) % v;/*ユークリッドの互除法と同じ原理で因数は保たれる*/ if (i % loop == 0) {/*10とかなんとか iによっては死ぬ*/ d = gcd(mul, v); mul = 1; } } if (d == v) return -1ll; return d; }; queue q; q.push(v); while (!q.empty()) { int v = q.front(); q.pop(); if (prime(v)) { ret.push_back(v); continue; } int d = -1; /*基本loop回数10でやり、駄目なら1で*/ for (int i = 0; d == -1 && i < 5; i++)d = fac(v, 10); if (d == -1)while (d == -1)d = fac(v, 1); int d2 = v / d; rep(_, 2) { if (d <= lower_prime_bound)ret.push_back(d); else q.push(d); d = d2; } } sort(ret); return run_length(ret); } //nに対して、商がqになるような[l, r)を持つ struct dra { ll q, l, r,len; dra(ll q_,ll l_,ll r_):q(q_),l(l_),r(r_),len(r_-l_){}}; vector drange(ll n, ll l = 1, ll r = -1) { if (r == -1)r = n+1; vector res; for (ll x = l; x < r;) { ll divisor = n / x; ll e; if (divisor == 0) { e = r; } else { e = min(r, n / divisor + 1); } res.emplace_back(divisor, x, e); x = e; } return res; }/*@formatter:on*/; } using namespace pnumber_tools; struct setprime_ { setprime_() { setprime(); }} setprime_v; //@formatter:off signed main() { in(N); na(A, N); vi dp(k5*3); rep(i, N){ chma(dp[A[i]] , 1); auto D = divisors(A[i]); D.pop_back(); fora(d,D){ chma(dp[A[i]],dp[d]+1); } deb(dp); } out(max(dp)); }