#include <bits/stdc++.h>   using namespace std;   const int maxn = 1000010;   int n, m, tot, ans;   int mx[maxn], mn[maxn], fir[maxn];   struct edge {     int a, b, l, r;   } p[maxn << 1];   queue<int> q;   vector<int> v[maxn];   inline void add(int a, int b, int c, int d) {     p[++tot].a = a, p[tot].b = b, p[tot].l = c + ((c ^ a) & 1),     p[tot].r = d - ((d ^ b) & 1);   }   bool cmp(const edge &a, const edge &b) { return a.l < b.l; }   inline void solve(int x) {     int a = p[x].a, b = p[x].b, l = p[x].l = max(p[x].l, mn[a]), r = p[x].r;     if (mx[a] < l) {       v[a].push_back(x);       return;     }     q.push(x);     while (!q.empty()) {       x = q.front(), q.pop(), a = p[x].a, b = p[x].b, l = p[x].l, r = p[x].r;       if (l >= r) continue;       if (mx[b] + 2 < l)         mn[b] = l + 1, mx[b] = r;       else         mx[b] = max(mx[b], r);       if ((b >> 1) == n) ans = min(ans, mn[b]);       while (fir[b] < (int)v[b].size()) {         int t = v[b][fir[b]];         if (mx[b] >= p[t].l)           fir[b]++, q.push(t), p[t].l = mn[b];         else           break;       }     }   }   inline int rd() {     int ret = 0, f = 1;     char gc = getchar();     while (gc <  0  || gc >  9 ) {       if (gc ==  - ) f = -f;       gc = getchar();     }     while (gc >=  0  && gc <=  9 ) ret = ret * 10 + (gc ^  0 ), gc = getchar();     return ret * f;   }   int main() {     n = rd(), m = rd();     if (n == 1) {       puts( 0 );       return 0;     }     int i, a, b, c, d;     for (i = 1; i <= m; i++) {       a = rd(), b = rd(), c = rd(), d = rd();       add(a << 1, b << 1 | 1, c, d);       add(a << 1 | 1, b << 1, c, d);       add(b << 1, a << 1 | 1, c, d);       add(b << 1 | 1, a << 1, c, d);     }     sort(p + 1, p + tot + 1, cmp);     memset(mx, 0xc0, sizeof(mx)), memset(mn, 0xc0, sizeof(mn));     mn[2] = mx[2] = 0, ans = 1 << 30;     for (i = 1; i <= tot; i++) solve(i);     if (ans == (1 << 30))       puts( -1 );     else       printf( %d , ans);     return 0;   }


#include <bits/stdc++.h>   const int MAX_CITIES = 1e5;   int n, m, c, q;   int dsu[MAX_CITIES + 1] = {0};   std::set<int> adj[MAX_CITIES + 1];   std::map<int, int>* city_rainbows;   int getDsuRoot(int v) {     int root = v;     while (dsu[root] != 0) {       root = dsu[root];     }     while (v != root) {       int p = dsu[v];       dsu[v] = root;       v = p;     }     return root;   }   int mergeDsu(int x, int y) {     int rootx = getDsuRoot(x);     int rooty = getDsuRoot(y);     if (adj[rootx].size() < adj[rooty].size()) std::swap(rootx, rooty);     if (rootx != rooty) {       dsu[rooty] = rootx;       adj[rootx].insert(adj[rooty].begin(), adj[rooty].end());       adj[rooty].clear();     }     return rootx;   }   bool isReachable(int x, int y) {     bool ans = false;     int rootx = getDsuRoot(x), rooty = getDsuRoot(y);     if (rootx == rooty || adj[rootx].find(y) != adj[rootx].end()) ans = true;     return ans;   }   void addEdge(int x, int y, int z) {     std::map<int, int>&r1 = city_rainbows[x], &r2 = city_rainbows[y];     if (r1.find(z) == r1.end()) {       r1.emplace(std::make_pair(z, y));     } else {       mergeDsu(r1[z], y);     }     if (r2.find(z) == r2.end()) {       r2.emplace(std::make_pair(z, x));     } else {       mergeDsu(r2[z], x);     }     int rootx = getDsuRoot(x);     int rooty = getDsuRoot(y);     if (rootx != rooty) {       adj[rootx].insert(y);       adj[rooty].insert(x);     }   }   int main() {     scanf( %d%d%d%d , &n, &m, &c, &q);     city_rainbows = new std::map<int, int>[n + 1];     for (int i = 0; i < m; i++) {       int x, y, z;       scanf( %d%d%d , &x, &y, &z);       addEdge(x, y, z);     }     for (int i = 0; i < q; i++) {       char type;       int x, y, z;       std::cin >> type;       if (type ==  + ) {         scanf( %d%d%d , &x, &y, &z);         addEdge(x, y, z);       } else if (type ==  ? ) {         scanf( %d%d , &x, &y);         if (isReachable(x, y)) {           printf( Yes n );         } else {           printf( No n );         }       }     }     delete[] city_rainbows;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   unordered_map<char, long long> store;   class thisway {    public:     bool operator()(const char& a, const char& b) {       if (store[a] > store[b]) return true;       return false;     }   };   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long n, k;     cin >> n >> k;     string s;     cin >> s;     for (long long i = 0; i < n; i++) {       store[s[i]]++;     }     multiset<char, thisway> ss;     for (auto x : store) ss.insert(x.first);     long long sum = 0;     while (!ss.empty() && k > 0) {       long long pp = store[*(ss.begin())];       ss.erase(ss.begin());       long long req = min(k, pp);       sum += req * req;       pp -= req;       k -= req;       if (pp == 0) store.erase(pp);     }     cout << sum <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int N, M;   vector<int> edge[300010];   vector<int> ve[300010];   int parent[300010];   int hap1[300010], hap2[300010];   int pwp1[300010], pwp2[300010];   int id[300010];   int ite = 300010;   map<int, bool> used;   int find_parent(int u) {     if (parent[u] == u) {       return u;     }     parent[u] = find_parent(parent[u]);     return parent[u];   }   void merge(int a, int b) {     a = find_parent(a);     b = find_parent(b);     if (a < b) {       swap(a, b);     }     if (a == b) {       return;     }     parent[a] = b;     return;   }   void dfs(int u, int val) {     if (id[u]) {       return;     }     id[u] = val;     used[val] = true;     if (ve[u].size() == 0) {       return;     }     if (ve[u].size() == 1) {       int v = ve[u][0];       if (id[v]) {         return;       }       if (used[val + 1]) {         dfs(v, val - 1);       } else {         dfs(v, val + 1);       }       return;     }     if (ve[u].size() == 2) {       int v = ve[u][0];       int w = ve[u][1];       if (id[v]) {         swap(v, w);       }       if (id[v]) {         return;       }       if (!id[w]) {         dfs(w, val + 1);         dfs(v, val - 1);         return;       }       if (used[val + 1]) {         dfs(v, val - 1);       } else {         dfs(v, val + 1);       }       return;     }   }   int32_t main() {     ios_base::sync_with_stdio(false);     if (fopen( cf794d.in ,  r )) {       freopen( cf794d.in ,  r , stdin);       freopen( cf794d.out ,  w , stdout);     }     cin >> N >> M;     pwp1[0] = 1;     pwp2[0] = 1;     for (int i = 1; i < 300010; i++) {       pwp1[i] = pwp1[i - 1] * 2;       pwp2[i] = pwp2[i - 1] * 2;       pwp1[i] %= 1000000007;       pwp2[i] %= 1000000861;     }     for (int i = 0; i < M; i++) {       int a, b;       cin >> a >> b;       a--;       b--;       edge[a].push_back(b);       edge[b].push_back(a);     }     for (int i = 0; i < N; i++) {       parent[i] = i;       edge[i].push_back(i);       sort(edge[i].begin(), edge[i].end());     }     for (int i = 0; i < N; i++) {       for (int j = 0; j < edge[i].size(); j++) {         hap1[i] += pwp1[edge[i][j]];         hap2[i] += pwp2[edge[i][j]];         hap1[i] %= 1000000007;         hap2[i] %= 1000000861;       }     }     for (int i = 0; i < N; i++) {       for (int j = 0; j < edge[i].size(); j++) {         int v = edge[i][j];         if (i == v) {           continue;         }         if (hap1[i] == hap1[v] && hap2[i] == hap2[v]) {           merge(i, v);         }       }     }     for (int i = 0; i < N; i++) {       if (parent[i] != i) {         continue;       }       for (int j = 0; j < edge[i].size(); j++) {         int u = find_parent(edge[i][j]);         if (i == u) {           continue;         }         ve[i].push_back(u);         ve[u].push_back(i);       }     }     for (int i = 0; i < N; i++) {       sort(ve[i].begin(), ve[i].end());       ve[i].erase(unique(ve[i].begin(), ve[i].end()), ve[i].end());     }     for (int i = 0; i < N; i++) {       if (ve[i].size() >= 3) {         cout <<  NO n ;         return 0;       }     }     cout <<  YES n ;     for (int i = 0; i < N; i++) {       if (parent[i] != i) {         continue;       }       dfs(i, ite);       ite += 300010;     }     for (int i = 0; i < N; i++) {       int u = find_parent(i);       cout << id[u] <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int INTlog2(unsigned long long number) {     int logval = 0;     while (number >>= 1) logval++;     return logval;   }   int main() {     unsigned long long n, k;     cin >> n >> k;     if (k == 1)       cout << n << endl;     else       cout << (1LL << (INTlog2(n) + 1LL)) - 1 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long A[1048576];   long long B[30];   long long C[30];   long P[30];   void f(long n, long o) {     if (n > 1) {       f(n - 1, o);       f(n - 1, o + P[n - 1]);     }     sort(A + o, A + o + P[n - 1]);     sort(A + o + P[n - 1], A + o + P[n]);     long i = o;     long j = o + P[n - 1];     while (i != o + P[n - 1] && j != o + P[n]) {       if (A[i] < A[j]) {         B[n] += o + P[n] - j;         i += 1;       } else {         j += 1;       }     }     i = o;     j = o + P[n - 1];     while (i != o + P[n - 1] && j != o + P[n]) {       if (A[i] <= A[j]) {         i += 1;       } else {         C[n] += o + P[n - 1] - i;         j += 1;       }     }   }   int main(int, char**) {     ios_base::sync_with_stdio(false);     P[0] = 1;     for (long i = (1); i <= (29); ++i) P[i] = 2 * P[i - 1];     long n;     cin >> n;     for (long i = 0; i < (P[n]); ++i) cin >> A[i];     for (long i = 0; i < (29); ++i) B[i] = 0;     for (long i = 0; i < (29); ++i) C[i] = 0;     f(n, 0);     bitset<30> BS;     long m;     cin >> m;     for (long i = 0; i < (m); ++i) {       long q;       cin >> q;       while (q != 0) {         BS[q] = not BS[q];         q -= 1;       }       long long r = 0;       for (long j = 0; j < (n + 1); ++j) {         r += BS[j] ? B[j] : C[j];       }       cout << r <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool helper(pair<int, int>* arr, int x, int y, int m) {     if (m == 0) {       return true;     }     int res = false;     if (x != -1) {       if (arr->first == x || arr->second == x) res = true;     }     if (y != -1) {       if (arr->second == y || arr->first == y) res = true;     }     if (!res) {       if (x == -1) {         return helper(arr + 1, arr->first, y, m - 1) ||                helper(arr + 1, arr->second, y, m - 1);       }       if (y == -1) {         return helper(arr + 1, x, arr->second, m - 1) ||                helper(arr + 1, x, arr->first, m - 1);       }       return false;     }     return helper(arr + 1, x, y, m - 1);   }   int main() {     int n, m;     cin >> n >> m;     pair<int, int> arr[m];     for (int i = 0; i < m; i++) {       cin >> arr[i].first >> arr[i].second;     }     if (helper(arr, -1, -1, m)) {       cout <<  YES  << endl;     } else {       cout <<  NO  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mn = 1010000, mm = 10100;   int n, m, i, j, k, t, a[mm], la[30], sa[30];   map<int, int> ans;   char s[mn], c[30];   bool cmp(int i, int j) { return la[i] > la[j]; }   int main() {     scanf( %s , s + 1);     n = strlen(s + 1);     scanf( %d , &m);     for (i = 1; i <= m; ++i) {       scanf( %s , c + 1);       k = strlen(c + 1);       t = 0;       for (j = 1; j <= k; ++j) t |= 1 << (c[j] - 97);       ans[t] = 0, a[i] = t;     }     for (i = 0; i <= 25; ++i) sa[i] = i;     for (i = 1; i <= n; ++i) {       if (s[i] == s[i + 1]) continue;       la[s[i] - 97] = i;       k = s[i + 1] - 97, t = 0;       sort(sa, sa + 26, cmp);       for (j = 0; j <= 25; ++j) {         if (!la[sa[j]] || sa[j] == k) break;         t |= 1 << sa[j];         if (t == 5) {           ++la[30];         }         if (ans.count(t)) ++ans[t];       }     }     for (i = 1; i <= m; ++i) printf( %d n , ans[a[i]]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     int nn = 1;     for (int i = 1; i < n; i++) {       int c = 0;       for (int j = 0; (1 << j) <= nn; j++) c++;       nn += c;     }     vector<int> P;     for (int i = 0; i < nn; i++) {       bool f = false;       for (int j = 0; (1 << j) <= i + 1; j++)         if ((1 << j) == i + 1) f = true;       for (int j = 0; j < (f ? 2 : 1); j++) P.push_back(i);     }     vector<int> type(m), t(m), l(m), r(m), x(m), v(m);     for (int i = 0; i < m; i++) {       cin >> type[i];       if (type[i] == 1) {         cin >> t[i] >> l[i] >> r[i] >> x[i];         t[i]--, l[i]--, r[i]--;       } else {         cin >> t[i] >> v[i];         t[i]--, v[i]--;       }     }     vector<set<int>> S(m);     vector<vector<int>> qn(n);     for (int i = m - 1; i >= 0; i--) {       if (type[i] == 1) {         int tt = t[i];         int tl = l[i];         int tr = r[i];         for (; tt >= 0; tt--) {           for (int j = 0; j < (int)qn[tt].size(); j++)             if (tl <= v[qn[tt][j]] && v[qn[tt][j]] <= tr)               S[qn[tt][j]].insert(x[i]);           tl = P[tl];           tr = P[tr];         }       } else {         qn[t[i]].push_back(i);       }     }     for (int i = 0; i < m; i++)       if (type[i] == 2) cout << S[i].size() << endl;   }


#include <bits/stdc++.h>   using namespace std;   using LL = long long;   constexpr LL LINF = 334ll << 53;   constexpr int INF = 15 << 26;   constexpr LL MOD = 1E9 + 7;   struct Problem {     LL n;     vector<LL> p;     Problem(LL n) : n(n), p(n){};     void solve() {       LL ans = 0, minsum = LINF, sum = 0;       for (int i = 0; i < n; ++i) {         cin >> p[i];         p[i]--;       }       multiset<LL> s;       for (int i = 0; i < n; ++i) {         if (p[i] - i > 0) s.insert(p[i] - i);         sum += abs(p[i] - i);       }       minsum = sum;       ;       for (int i = 1; i < n; ++i) {         LL cnt;         if (p[n - i] - (n - 1) > 0)           cnt = (int)s.size() - 1;         else           cnt = (int)s.size();         sum += n - 1 - 2 * cnt;         ;         sum = sum - abs(p[n - i] - (n - 1)) + abs(p[n - i]);         s.erase(i);         if (p[n - i] > 0) s.insert(p[n - i] + i);         ;         ;         if (sum < minsum) {           minsum = sum;           ans = i;         }       }       cout << minsum <<     << ans <<   n ;     }   };   int main() {     cin.tie(0);     ios_base::sync_with_stdio(false);     long long n = 0;     cin >> n;     Problem p(n);     p.solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, t, tt, sz, res = 1e9, a[55][100005], out[100005], cnt[100005],                     mul[100005], que[1000005];   int read() {     int x = 0, fl = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) fl = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = (x << 1) + (x << 3) + ch -  0 ;       ch = getchar();     }     return x * fl;   }   int check(int p, int len) {     for (int i = 1; i <= len; i++)       if (a[p][i]) return 0;     return 1;   }   void dfs(int dep, int sum, int len) {     if (sum > res || dep > 51) return;     int now = check(dep, len);     if (now) {       res = sum;       for (int i = 1; i <= t; i++) que[i] = cnt[i];       sz = t;       return;     }     int fl = 1;     for (int i = 1; i <= len; i++)       if (a[dep][i] % 2) fl = 0;     if (fl) {       cnt[++t] = 3;       for (int i = 1; i <= len; i++) a[dep + 1][i] = a[dep][i] / 2;       int l0 = unique(a[dep + 1] + 1, a[dep + 1] + len + 1) - a[dep + 1] - 1;       dfs(dep + 1, sum, l0);       t--;     } else {       cnt[++t] = 1;       for (int i = 1; i <= len; i++)         a[dep + 1][i] = a[dep][i] + ((a[dep][i] & 1) > 0);       int l0 = unique(a[dep + 1] + 1, a[dep + 1] + len + 1) - a[dep + 1] - 1;       dfs(dep + 1, sum + 1, l0);       t--;       cnt[++t] = 2;       for (int i = 1; i <= len; i++)         a[dep + 1][i] = a[dep][i] - ((a[dep][i] & 1) > 0);       l0 = unique(a[dep + 1] + 1, a[dep + 1] + len + 1) - a[dep + 1] - 1;       dfs(dep + 1, sum + 1, l0);       t--;     }     return;   }   int main() {     n = read();     for (int i = 1; i <= n; i++) a[0][i] = read();     sort(a[0] + 1, a[0] + n + 1);     dfs(0, 0, n);     printf( %d n , res);     for (int i = 1; i <= sz; i++) mul[i] = mul[i - 1] + (que[i] == 3);     for (int i = 1; i <= sz; i++) {       if (que[i] == 1)         out[++tt] = -1 * pow(2, mul[i]);       else if (que[i] == 2)         out[++tt] = pow(2, mul[i]);     }     for (int i = 1; i <= tt; i++) printf( %d  , out[i]);     puts(  );     return 0;   }


#include <bits/stdc++.h>   typedef struct smirror {     int left, right, score;   } mirror;   int max(int a, int b) { return a > b ? a : b; }   int shoot_in(double x, mirror a[]) {     for (int i = 1; i <= a[0].score; ++i)       if (a[i].left <= x && x <= a[i].right) return i;     return -1;   }   int deal(int n, mirror A[], mirror B[], int hl, int hr) {     int counter = 1, hx = hl, tag, score0 = 0;     int h0;     if (n % 2 == 1)       h0 = hl + hr + (n - 1) * 100;     else       h0 = n * 100 + hl - hr;     bool ba[105], bb[105];     memset(ba, 0, sizeof(ba));     memset(bb, 0, sizeof(bb));     double d;     for (counter = 1; counter <= n; counter++) {       d = (hx * 100000) / (1.0 * h0);       if (counter % 2 == 1) {         tag = shoot_in(d, B);         if (tag >= 0 && !bb[tag]) {           score0 += B[tag].score;           bb[tag] = 1;         } else {           score0 = 0;           break;         }       } else {         tag = shoot_in(d, A);         if (tag >= 0 && !ba[tag]) {           score0 += A[tag].score;           ba[tag] = 1;         } else {           score0 = 0;           break;         }       }       hx += 100;     }     return score0;   }   int main() {     mirror mi[2][105];     int num[2] = {0, 0}, hl, hr, n;     scanf( %d%d%d , &hl, &hr, &n);     while (n--) {       int score, set = 1;       char t;       scanf( %d %c , &score, &t);       if (t ==  T ) set = 0;       ++num[set];       scanf( %d %d , &mi[set][num[set]].left, &mi[set][num[set]].right);       mi[set][num[set]].score = score;     }     mi[0][0].score = num[0], mi[1][0].score = num[1];     int ans = 0;     for (int i = 1; i <= num[0] + num[1]; ++i)       ans = max(ans, deal(i, mi[0], mi[1], hl, hr));     for (int i = 1; i <= num[0] + num[1]; ++i)       ans = max(ans, deal(i, mi[1], mi[0], 100 - hl, 100 - hr));     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace ::std;   const int maxn = 1e5 + 5;   map<long long, int> mp;   long long sum[maxn], ans;   int n, k;   void solve() {     long long maxx = 0, minn = 0;     scanf( %d%d , &n, &k);     mp[0] = 1;     for (int i = 1; i <= n; i++) {       long long tmp;       scanf( %I64d , &tmp);       sum[i] = sum[i - 1] + tmp;       mp[sum[i]]++;       maxx = max(maxx, sum[i]);       minn = min(minn, sum[i]);       for (long long j = 1; - 1e15 <= j && j <= 1e15; j *= k) {         if (mp.find(sum[i] - j) != mp.end()) {           ans += mp[sum[i] - j];         }         if (k == 1) break;         if (j == -1 && k == -1) break;       }     }     printf( %I64d n , ans);   }   int main() {     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const int maxn = 2e5 + 9;   void test_case(int tc) {     int k;     cin >> k;     int n = 12;     int arr[12];     for (int i = 0; i <= 11; ++i) cin >> arr[i];     sort(arr, arr + 12, greater<int>());     int ans = 0;     int temp = 0;     if (k == 0) {       cout << k <<   n ;       return;     }     for (int i = 0; i <= n - 1; ++i) {       temp += arr[i];       ans++;       if (temp >= k) {         cout << ans;         return;       }     }     cout << -1;   }   int32_t main() {     ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);     int t = 1;     for (int tc = 1; tc <= t; ++tc) test_case(tc);   }


#include <bits/stdc++.h>   using namespace std;   const int N = 200005;   int n, m;   long long ans, a[N], b[N];   char c;   long long read() {     long long x = 0;     int sig = 1;     for (c = getchar(); c <  0  || c >  9 ; c = getchar())       if (c ==  - ) sig = -1;     for (; c >=  0  && c <=  9 ; c = getchar()) x = x * 10 + c - 48;     return x * sig;   }   long long calc(int p) {     b[n] = min(a[n], (long long)m * p - (long long)p * (p - 1) / 2 * n);     for (int i = n - 1; i; i--) b[i] = min(a[i], b[i + 1] - p);     if (b[1] < p + (long long)p * (p - 1) / 2 * n) return 0;     long long sum = 0,               s = max(1ll, b[1] - (long long)(m + 1) * (p - 1) +                                (long long)p * (p - 1) / 2 * n),               Buy;     sum = Buy = b[1];     int Free = m - n * p - s + 1;     for (int i = 2; i <= n; i++) {       Buy += p;       int Shift = min(b[i] - Buy, (long long)Free);       Free -= Shift;       Buy += Shift;       sum += Buy;     }     return sum;   }   int main() {     n = read();     m = read();     for (int i = 1; i <= n; i++) a[i] = read();     ans = 0;     for (int i = 1; i * n <= m; i++) ans = max(ans, calc(i));     printf( %I64d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long read() {     long long x = 0, f = 1;     char ch =    ;     while (!isdigit(ch)) {       ch = getchar();       if (ch ==  - ) f = -1;     }     while (isdigit(ch)) x = (x << 3) + (x << 1) + (ch - 48), ch = getchar();     return x * f;   }   const int mod = 998244353;   int t, n, a[100005];   vector<pair<long long, long long> > g[2];   int main() {     cin >> t;     while (t--) {       n = read();       long long ans = 0;       for (int i = 1; i <= n; i++) a[i] = read();       g[n % 2].clear();       g[n % 2].push_back({a[n], 1});       for (int i = n; i > 1; i--) {         int las = (i % 2), now = (las ^ 1);         g[now].clear();         int las1 = 0;         for (auto tmp : g[las]) {           ans += ((a[i - 1] - 1) / tmp.first) * (i - 1) % mod * tmp.second % mod;           int tmp1 = a[i - 1] / ((a[i - 1] - 1) / tmp.first + 1);           if (tmp1 == las1)             g[now][g[now].size() - 1].second += tmp.second % mod;           else             g[now].push_back({tmp1, tmp.second}), las1 = tmp1;         }         if (a[i - 1] == las1)           g[now][g[now].size() - 1].second++;         else           g[now].push_back({a[i - 1], 1ll});         g[las] = g[now];       }       cout << ans % mod << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   long long n, i, j, k, x, y, col;   vector<long long> ans;   long long last[100100];   int main() {     cin >> n;     for (i = 0; i < n; i++) {       cin >> x >> y;       col = 0;       j = 1;       while (j * j <= x) {         if (x % j == 0) {           k = x / j;           if (last[j] < i - y + 1) {             last[j] = i + 1;             col++;           }           last[j] = i + 1;           if (k != j && last[k] < i - y + 1) {             col++;           }           last[k] = i + 1;         }         j++;       }       ans.push_back(col);     }     for (i = 0; i < n; i++) cout << ans[i] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main(void) {     int n, i, j = -100, k, *a, cnt = 0, cnt1 = 0;     cin >> n;     a = new int[n];     for (i = 0; i < n; i++) {       cin >> a[i];     }     for (i = 0; i < n - 2; i++) {       if (a[i] == 1 && a[i + 1] == 0 && a[i + 2] == 1) {         if (i - j > 2) {           cnt++;           j = i;           cnt1 = 0;         } else {           cnt1++;         }       }     }     cout << cnt;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int i, j;     char map[9][9];     bool ok = false, ok1 = false;     for (i = 0; i < 8; ++i) {       scanf( %s , map[i]);       for (j = 1; j < 8; ++j) {         if (i == 0 && map[i][j] ==  W ) ok1 = true;         if (map[i][j] == map[i][j - 1]) ok = true;       }       if (i == 0 && map[i][0] ==  W ) ok1 = true;       if (map[i][0] == map[i][7]) ok = true;     }     if (!ok1 || ok)       puts( NO );     else       puts( YES );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 200007, inf = 0x3f3f3f3f;   vector<int> edges[N];   int d[N];   void bfs(int s) {     queue<int> q;     q.push(s);     memset(d, -1, sizeof d);     d[s] = 0;     while (q.size()) {       int u = q.front();       q.pop();       for (int v : edges[u]) {         if (d[v] == -1) {           q.push(v);           d[v] = d[u] + 1;         }       }     }   }   void no() {     cout <<  No  << endl;     exit(0);   }   int main() {     ios::sync_with_stdio(false);     srand(time(NULL));     int n;     cin >> n;     if (n == 1) {       cout <<  Yes  << endl;       return 0;     }     for (int i = 0; i < n - 1; ++i) {       int u, v;       cin >> u >> v;       edges[u].push_back(v);       edges[v].push_back(u);     }     vector<int> vec;     int a;     for (int i = 0; i < n; ++i) {       cin >> a;       vec.push_back(a);     }     memset(d, -1, sizeof d);     int t = 0;     d[1] = 0;     if (vec[0] != 1) no();     for (int i = 0; i < n; ++i) {       if (d[vec[i]] == -1) no();       ++t;       for (int v : edges[vec[i]]) {         if (d[v] == -1) d[v] = t;       }     }     for (int i = 1; i < n; ++i) {       if (d[vec[i]] < d[vec[i - 1]]) no();     }     cout <<  Yes  << endl;   }


#include <bits/stdc++.h>   using namespace std;   long long n, i, j, a, b, c, t, cnt;   int main() {     cin >> a >> b >> c;     n = 0;     t = 0;     cnt = 0;     while ((a > 0) || (b > 0) || (c > 0)) {       switch (t) {         case 0: {           if (a > 0) a -= 2;           break;         }         case 1: {           if (b > 0) b -= 2;           break;         }         case 2: {           if (c > 0) c -= 2;           break;         }       }       cnt++;       n++;       t++;       t %= 3;     }     n--;     n += 30;     cout << n << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<bool> prime(1001, true);   void sieve() {     prime[0] = false;     prime[1] = false;     for (int i = 2; i <= 1000; i++) {       if (prime[i]) {         int j = 2;         while (i * j <= 1000) {           prime[i * j] = false;           j++;         }       }     }   }   long long int ceil_sqrt(long long int a) {     long long int i = 1;     while (i * i < a) i++;     return i;   }   void solve() {     int n;     cin >> n;     int a[n];     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < n; i += 2) cout << a[i + 1] <<     << -1 * a[i] <<    ;     cout << endl;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b;     cin >> a >> b;     if (a == 0 && b == 0) {       cout <<  NO ;       return 0;     }     if (abs(a - b) <= 1)       cout <<  YES ;     else       cout <<  NO ;   }


#include <bits/stdc++.h>   using namespace std;   int n, arr[300000];   double cord[3], best[3];   int main() {     cin >> n;     for (int i = 0; i < n; i++) scanf( %d , &arr[i]);     sort(arr, arr + n);     int l = 0, r = 2000000000, res = -1;     while (l <= r) {       int mid = (l + r) / 2;       int idx = 0;       for (int i = 0; i < 3; i++) {         cord[i] = (double)arr[idx] + (double)mid / 2.;         while (idx < n && abs(arr[idx] - cord[i]) - 1e-7 < (double)mid / 2.)           idx++;       }       if (idx == n) {         for (int i = 0; i < 3; i++) best[i] = cord[i];         res = mid, r = mid - 1;       } else         l = mid + 1;     }     printf( %.6lf n , (double)res / 2.);     printf( %.6lf  , (double)best[0]);     for (int i = 1; i < 3; i++) printf( % .6lf , (double)best[i]);     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100005;   long long a[MAXN], b[MAXN];   long long n, s;   bool check(long long k) {     for (int i = 1; i <= n; i++) b[i] = 0;     long long sum = s - 1, p = 2, q = 1, h = 1;     a[1] = b[1] = 1;     while (p <= n) {       q *= k, h++;       for (int i = 1; i <= q && p <= n; i++, p++) a[p] = h, sum -= h, b[h]++;     }     if (sum < 0) return 0;     p = n;     while (sum > 0) {       h++;       if (b[a[p]] == 1) --p;       long long t = min(sum, h - a[p]);       sum -= t, b[a[p]]--, a[p] += t, p--;     }     return 1;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> n >> s;     if (s < 2 * n - 1 || s > n * (n + 1) / 2) {       cout <<  No  << endl;       exit(0);     }     int l = 1, r = n - 1;     while (l < r) {       int m = (l + r) >> 1;       if (check(m))         r = m;       else         l = m + 1;     }     check(l);     sort(a + 1, a + n + 1);     cout <<  Yes  << endl;     for (int p = 1, i = 2, cnt = 0; i <= n; i++) {       while (a[p] < a[i] - 1) p++, cnt = 0;       cout << p <<    ;       ++cnt;       if (cnt == l) cnt = 0, ++p;     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1505;   const int MOD = 1000000007;   inline int add(int x, int y) { return x + y >= MOD ? x + y - MOD : x + y; }   inline int sub(int x, int y) { return x - y < 0 ? x - y + MOD : x - y; }   inline int mul(int x, int y) { return 1ll * x * y % MOD; }   inline void inc(int &x, int y) { x = add(x, y); }   inline void dec(int &x, int y) { x = sub(x, y); }   inline void grow(int &x, int y) { x = mul(x, y); }   int bpow(int a, int b) {     int res = 1;     while (b) {       if (b & 1) grow(res, a);       grow(a, a);       b >>= 1;     }     return res;   }   int inv(int x) { return bpow(x, MOD - 2); }   int n, m, p, k;   int f[N], dp[N][N], sdp[N][N], sf[N], sfdp[N], fact[100005];   int comb(int a, int b) {     return mul(fact[a], mul(inv(fact[b]), inv(fact[a - b])));   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> n >> m;     int _a, _b;     cin >> _a >> _b;     p = mul(_a, inv(_b));     cin >> k;     fact[0] = 1;     for (int i = 1; i <= k; i++) fact[i] = mul(fact[i - 1], i);     for (int i = 0; i <= min(k, m); i++)       f[i] = mul(comb(k, i), mul(bpow(p, i), bpow(sub(1, p), k - i)));     sf[0] = f[0];     for (int i = 1; i <= m; i++) sf[i] = add(sf[i - 1], f[i]);     dp[0][m] = sdp[0][m] = 1;     for (int i = 1; i <= n; i++) {       memset(sfdp, 0, sizeof sfdp);       for (int r = 1; r <= m; r++)         sfdp[r] = add(sfdp[r - 1], mul(f[r], sdp[i - 1][r]));       for (int r = 1; r <= m; r++)         dp[i][r] = mul(f[m - r],                        sub(mul(sf[r - 1], sub(sdp[i - 1][m], sdp[i - 1][m - r])),                            sfdp[r - 1]));       for (int r = 1; r <= m; r++) sdp[i][r] = add(sdp[i][r - 1], dp[i][r]);     }     cout << sdp[n][m] << endl;   }


#include <bits/stdc++.h>   using namespace std;   inline int read_int() {     int x;     scanf( %i , &x);     return x;   }   inline int endline() { return printf(  n ); }   inline int space() { return printf(   ); }   inline int write_int(const int x) { return printf( %i , x); }   class color_ice_cream : public pair<bitset<500000>, bitset<500000> > {     int n, m, last_used_color, *color;     vector<int> *ice_cream, *neighbor;       public:     color_ice_cream()         : n(read_int()),           m(read_int()),           last_used_color(-1),           color(new int[m]),           ice_cream(new vector<int>[n]),           neighbor(new vector<int>[n]) {       for (int i = 0; i < n; i++) {         int k = read_int();         for (int j = 0; j < k; j++) ice_cream[i].push_back(read_int() - 1);       }       for (int i = 1; i < n; i++) {         int u = read_int() - 1, v = read_int() - 1;         neighbor[v].push_back(u);         neighbor[u].push_back(v);       }       for (int i = 0; i < m; i++) color[i] = -1;     }     void solve(const int v = 0) {       first.set(v);       int i, j = -1, k = ice_cream[v].size(), l;       for (i = 0; i < k; i++)         if ((l = color[ice_cream[v][i]]) != -1) second.set(l);       for (i = 0; i < k; i++)         if (color[l = ice_cream[v][i]] == -1) {           while (second[++j])             ;           color[l] = j;         }       second.reset();       if (j > last_used_color) last_used_color = j;       for (i = 0, k = neighbor[v].size(); i < k; i++)         if (!first[l = neighbor[v][i]]) solve(l);     }     void write_result() {       write_int(max(last_used_color, 0) + 1), endline();       for (int i = 0; i < m; i++) write_int(max(color[i], 0) + 1), space();     }   };   int main() {     color_ice_cream problem;     problem.solve();     problem.write_result();   }


#include <bits/stdc++.h>   template <class T>   T _diff(T a, T b) {     return (a < b ? b - a : a - b);   }   template <class T>   T _abs(T a) {     return (a < 0 ? -a : a);   }   template <class T>   T _max(T a, T b) {     return (a > b ? a : b);   }   template <class T>   T _min(T a, T b) {     return (a < b ? a : b);   }   template <class T>   T max3(T a, T b, T c) {     return (_max(a, b) > c ? _max(a, b) : c);   }   template <class T>   T min3(T a, T b, T c) {     return (_min(a, b) < c ? _min(a, b) : c);   }   template <class T>   T GCD(T a, T b) {     a = _abs(a);     b = _abs(b);     T tmp;     while (a % b) {       tmp = a % b;       a = b;       b = tmp;     }     return b;   }   template <class T>   T LCM(T a, T b) {     a = _abs(a);     b = _abs(b);     return (a / GCD(a, b)) * b;   }   using namespace std;   int x, y, xp, yp, xn, ynw, xl, yl, chk, si, t;   int main() {     cin >> x >> y;     xn = ynw = 0;     chk = 1;     xl = 0;     yl = 0;     t = 0;     si = 1;     int row = 1, col = 0;     t = 0;     while (1) {       xp = xn;       yp = ynw;       if (chk == 1) {         si = 1;         chk++;         xl++;         yl++;       } else if (chk == 2) {         si = 1;         chk++;       } else if (chk == 3) {         si = -1;         chk++;       } else if (chk == 4) {         si = -1;         chk = 1;       }       if (row) {         xn = (si) * (xl);         row = 0;         col = 1;       } else {         ynw = (si) * (yl);         row = 1;         col = 0;       }       if (x == xn && x == xp) {         if (si == 1 && y >= yp && y <= ynw)           break;         else if (si == -1 && y >= ynw && y <= yp)           break;       } else if (y == ynw && y == yp) {         if (si == 1 && x >= xp && x <= xn)           break;         else if (si == -1 && x <= xp && x >= xn)           break;       }       t++;     }     cout << t << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool cmp(const pair<char, int>& x, const pair<char, int>& y) {     int u = max(x.first -  a ,  z  - x.first);     int v = max(y.first -  a ,  z  - y.first);     return u > v;   }   int main() {     if (0 & 1) freopen( input ,  r , stdin);     if (0 & 2) freopen( output ,  w , stdout);     int n, k;     scanf( %d %d , &n, &k);     vector<pair<char, int> > a(n);     int id = 0;     for (auto& e : a) {       scanf(  %c , &e.first);       e.second = id++;     }     sort(a.begin(), a.end(), cmp);     string ans(n,    );     for (auto& e : a) {       int u = e.first -  a , v =  z  - e.first, cur;       if (u > v) {         cur = min(k, u);         ans[e.second] = e.first - cur;       } else {         cur = min(k, v);         ans[e.second] = e.first + cur;       }       k -= cur;     }     if (k)       printf( -1 n );     else       printf( %s n , ans.c_str());     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const int M = 998244853, maxn = 4005;   int n, m;   void madd(int& a, int b) {     a += b;     if (a >= M) a -= M;   }   int ch[maxn][maxn];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> n >> m;     ch[0][0] = 1;     for (int i = 1; i < maxn; i++) {       for (int j = 0; j <= i; j++) {         madd(ch[i][j], ch[i - 1][j]);         if (j > 0) madd(ch[i][j], ch[i - 1][j - 1]);       }     }     int ans = 0;     for (int k = 1; k <= n; k++) {       if (n >= m + k) {         madd(ans, ch[n + m][n]);       } else {         madd(ans, ch[n + m][m + k]);       }     }     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const int NAX = 3e5 + 1;   const int INF = 1e9 + 1;   const long long UMAX = 2e18 + 1;   long long sm(long long n) {     int res = 0;     while (n > 0) {       res += n % 10;       n /= 10;     }     return res;   }   void solve() {     long long n;     cin >> n;     vector<long long> v(n);     vector<long long> ans;     for (int i = 0; i < n; ++i) cin >> v[i];     sort(v.begin(), v.end());     long long p1 = v[0] * v[1] * v[2] * v[3] * v[n - 1];     long long p2 = v[n - 1] * v[n - 2] * v[n - 3] * v[n - 4] * v[n - 5];     long long p3 = v[0] * v[1] * v[n - 1] * v[n - 2] * v[n - 3];     ans.push_back(p1);     ans.push_back(p2);     ans.push_back(p3);     cout << *max_element(ans.begin(), ans.end()) <<   n ;     ;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int tc = 1;     cin >> tc;     while (tc--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long T;     cin >> T;     while (T--) {       long long n;       cin >> n;       long long i, j = 1;       cout <<  2  ;       for (i = 1; i < n; i++) {         j += 2;         cout << j <<    ;       }       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct Node {     vector<Node*> edges;     bool term;     vector<int> last;     Node() {       edges.resize(5);       fill(edges.begin(), edges.end(), nullptr);       term = false;     }   };   void add_string(Node* root, string s) {     for (char c : s) {       c -=  a ;       if (!root->edges[c]) {         Node* node = new Node();         root->edges[c] = node;       }       root = root->edges[c];     }     root->term = true;     root->last.push_back(0);   }   void get_ans(Node* node, string s, int cnt, int& ans, int num) {     if (cnt >= s.size()) {       if (node->term) {         for (int i = 0; i < node->last.size(); i++) {           if (node->last[i] < num) {             node->last[i] = num;             ans++;           }         }       }       return;     }     char c = s[cnt];     c -=  a ;     if (s[cnt] !=  ? ) {       if (node->edges[c]) {         get_ans(node->edges[c], s, cnt + 1, ans, num);       }     } else {       get_ans(node, s, cnt + 1, ans, num);       for (int i = 0; i < 5; i++) {         if (node->edges[i]) {           get_ans(node->edges[i], s, cnt + 1, ans, num);         }       }     }   }   int main() {     int n, m;     cin >> n >> m;     Node* root = new Node();     for (int i = 0; i < n; i++) {       string s;       cin >> s;       add_string(root, s);     }     for (int i = 0; i < m; i++) {       string s;       cin >> s;       int ans = 0;       get_ans(root, s, 0, ans, i + 1);       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, m;   long long a[510];   long long dp[510][510];   long long stt[510];   long long mod = 998244353;   long long solve(long long st, long long en) {     if (st >= en) {       return 1;     }     if (dp[st][en] != -1) return dp[st][en];     long long c = 1e9;     for (int i = st; i <= en; i++) c = min(c, a[i]);     long long sol = 0;     long long sol1 = 0;     for (int i = st; i <= stt[c]; i++) {       sol += solve(i, stt[c] - 1) * solve(st, i - 1);       sol %= mod;     }     for (int i = en; i >= stt[c]; i--) {       sol1 += solve(stt[c] + 1, i) * solve(i + 1, en);       sol1 %= mod;     }     sol *= sol1;     sol %= mod;     return dp[st][en] = sol;   }   int main() {     ios::sync_with_stdio(false);     cin >> n >> m;     memset(stt, -1, sizeof stt);     memset(dp, -1, sizeof dp);     for (int i = 0; i < n; i++) {       cin >> a[i];       stt[a[i]] = i;     }     long long ss = solve(0, n - 1);     cout << ss << endl;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC target( sse4,avx )   void run(std::istream &in, std::ostream &out) {     int n;     in >> n;     std::vector<int> as(n);     int sum = 0;     for (int i = 0; i < n; i++) {       in >> as[i];       sum += as[i];     }     if (sum % 2 == 0) {       for (int j = 2; j <= sum; j += 2) {         if (sum % j != 0) continue;         int d = sum / j;         bool good = true;         for (int k = 0; k < n; k++) {           if ((as[k] % (2 * d)) != 0) {             good = false;             break;           }         }         if (good) {           out << 2 * d << std::endl;           std::string s;           for (int k = 0; k < n; k++) {             s.append(std::string(as[k] / (2 * d),  a  + k));           }           std::string ss = s;           std::reverse(ss.begin(), ss.end());           s.append(ss);           std::string res;           for (int k = 0; k < d; k++) {             res.append(s);           }           out << res << std::endl;           return;         }       }     } else {       for (int j = 1; j <= sum; j += 2) {         if (sum % j != 0) continue;         int d = sum / j;         int countOdd = 0;         int oddIdx = 0;         bool good = true;         for (int k = 0; k < n; k++) {           if ((as[k] % d) != 0) {             good = false;             break;           }           if (((as[k] / d) % 2) != 0) {             countOdd++;             oddIdx = k;           }         }         if (!good) continue;         if (countOdd != 1) continue;         out << d << std::endl;         std::string s;         for (int k = 0; k < n; k++) {           s.append(std::string(as[k] / d / 2,  a  + k));         }         std::string ss = s;         std::reverse(ss.begin(), ss.end());         s.append(ss);         s.push_back((char)( a  + oddIdx));         std::string res;         for (int k = 0; k < d; k++) {           res.append(s);         }         out << res << std::endl;         return;       }     }     out << 0 << std::endl;     std::string s;     for (int k = 0; k < n; k++) {       s.append(std::string(as[k],  a  + k));     }     out << s << std::endl;   }   int main() {     std::cin.sync_with_stdio(false);     std::cin.tie(nullptr);     run(std::cin, std::cout);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int i, n, fl = 0;       cin >> n;       int *a = new int[n];       for (i = 0; i < n; ++i) {         cin >> a[i];       }       sort(a, a + n);       for (i = 1; i < n; ++i) {         if (a[i] == a[i - 1]) {           fl = 1;           break;         }       }       if (fl == 1) {         cout <<  YES n ;       } else {         cout <<  NO n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     for (int i = s.size() - 1; i >= 0; i--) {       int x = s[i] -  0 ;       if (x >= 5)         printf( -O| );       else         printf( O-| );       x = x % 5;       if (x == 0)         printf( -OOOO n );       else if (x == 1)         printf( O-OOO n );       else if (x == 2)         printf( OO-OO n );       else if (x == 3)         printf( OOO-O n );       else         printf( OOOO- n );     }   }


#include <bits/stdc++.h>   using namespace std;   std::mt19937 rnd(       (int)std::chrono::steady_clock::now().time_since_epoch().count());   long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }   const int MAXN = 250000;   struct P {     int x, y;     P() {}     P(int x, int y) : x(x), y(y) {}   };   bool operator<(const P& a, const P& b) {     if (a.x != b.x) return a.x < b.x;     return a.y < b.y;   }   int ninit;   P pinit[MAXN];   set<P> infected;   vector<P> getadj(const P& a) {     vector<P> ret(3);     ret[0] = P(a.x + 1, a.y);     ret[1] = P(a.x - 1, a.y);     ret[2] = a.x & 1 ? P(a.x - 1, a.y + 1) : P(a.x + 1, a.y - 1);     return ret;   }   int ntree;   vector<P> ptree;   map<P, int> pmap;   vector<vector<int>> adj;   vector<int> col;   vector<int> par;   bool dfscycle(int at) {     for (int i = (0); i < (((int)(adj[at]).size())); ++i) {       int to = adj[at][i];       if (to == par[at]) continue;       if (par[to] != -2) return true;       par[to] = at;       if (dfscycle(to)) return true;     }     return false;   }   bool hascycle() {     par = vector<int>(ntree, -2);     for (int i = (0); i < (ntree); ++i)       if (par[i] == -2) {         par[i] = -1;         if (dfscycle(i)) return true;       }     return false;   }   void determineinfected() {     infected.clear();     queue<P> q;     for (int i = (0); i < (ninit); ++i)       infected.insert(pinit[i]), q.push(pinit[i]);     while (!q.empty()) {       P a = q.front();       q.pop();       for (const P& b : getadj(a)) {         if (infected.count(b)) continue;         int cntadjinfected = 0;         for (const P& c : getadj(b)) cntadjinfected += infected.count(c);         if (cntadjinfected >= 2) infected.insert(b), q.push(b);       }     }   }   void buildgraph() {     ptree = vector<P>(((int)(infected).size()));     ntree = 0;     pmap.clear();     for (const P& a : infected) pmap[a] = ntree, ptree[ntree] = a, ++ntree;     adj = vector<vector<int>>(ntree);     col = vector<int>(ntree, 0);     for (int i = (0); i < (ntree); ++i)       for (const P& b : getadj(ptree[i]))         if (pmap.count(b)) adj[i].push_back(pmap[b]);     for (int i = (0); i < (ninit); ++i)       if (pmap.count(pinit[i])) col[pmap[pinit[i]]] = 1;   }   int calcsteps() {     set<int> cheap;     set<int> expansive;     vector<bool> alive(ntree, true);     vector<int> cntadjalive(ntree, 0);     vector<int> cntadjblack(ntree, 0);     for (int at = (0); at < (ntree); ++at)       cntadjalive[at] = ((int)(adj[at]).size());     for (int at = (0); at < (ntree); ++at)       for (int to : adj[at]) cntadjblack[at] += col[to];     auto upd = [&](int at) {       cheap.erase(at);       expansive.erase(at);       if (!alive[at]) return;       if (col[at] == 0) {         if (cntadjblack[at] == 2) cheap.insert(at);         if (cntadjblack[at] == 3) expansive.insert(at);       } else {         if (cntadjblack[at] == 1 && cntadjalive[at] == 1) cheap.insert(at);         if (cntadjblack[at] == 0 && cntadjalive[at] == 0) expansive.insert(at);       }     };     for (int at = (0); at < (ntree); ++at) upd(at);     int ret = 0;     while (true) {       if (!cheap.empty()) {         int at = *cheap.begin();         if (col[at] == 0) {           assert(cntadjblack[at] == 2);           col[at] = 1, ++ret;           for (int& to : adj[at]) ++cntadjblack[to];           upd(at);           for (int& to : adj[at]) upd(to);         } else {           assert(cntadjblack[at] == 1 && cntadjalive[at] == 1);           int oth = -1;           for (int& to : adj[at])             if (alive[to]) {               assert(oth == -1);               oth = to;             }           assert(oth != -1 && col[oth] == 1);           if (cntadjalive[oth] == 2 && cntadjblack[oth] == 1) {             int w = -1;             for (int& to : adj[oth])               if (alive[to] && to != at) {                 assert(w == -1);                 w = to;               }             assert(w != -1 && col[w] == 0);             if (cntadjblack[w] == 3) {               col[oth] = 0, ++ret;               col[w] = 1, ++ret;               col[oth] = 1, ++ret;               for (int& to : adj[w]) ++cntadjblack[to];               upd(at);               upd(w);               for (int& to : adj[w]) upd(to);               continue;             }           }           col[at] = 0, alive[at] = false, ++ret;           for (int& to : adj[at]) --cntadjblack[to], --cntadjalive[to];           upd(at);           for (int& to : adj[at]) upd(to);         }       } else if (!expansive.empty()) {         int at = *expansive.begin();         if (col[at] == 0) {           assert(cntadjblack[at] == 3 && cntadjalive[at] == 3);           bool done = false;           for (int& oth : adj[at]) {             if (cntadjblack[oth] != 1) continue;             done = true;             col[oth] = 0, ++ret;             col[at] = 1, ++ret;             col[oth] = 1, ++ret;             for (int& to : adj[at]) ++cntadjblack[to];             upd(at);             for (int& to : adj[at]) upd(to);             break;           }           if (done) continue;           col[at] = 1, ++ret;           for (int& to : adj[at]) ++cntadjblack[to];           upd(at);           for (int& to : adj[at]) upd(to);         } else {           assert(cntadjblack[at] == 0 && cntadjalive[at] == 0);           col[at] = 0, alive[at] = false, ++ret;           for (int& to : adj[at]) --cntadjblack[to], --cntadjalive[to];           upd(at);           for (int& to : adj[at]) upd(to);         }       } else {         break;       }     }     for (int at = (0); at < (ntree); ++at) assert(!alive[at] && col[at] == 0);     return ret;   }   int solve() {     determineinfected();     buildgraph();     if (hascycle()) return -1;     return calcsteps();   }   void run() {     scanf( %d , &ninit);     for (int i = (0); i < (ninit); ++i) scanf( %d%d , &pinit[i].x, &pinit[i].y);     int ans = solve();     if (ans == -1)       printf( SICK n );     else       printf( RECOVERED n%d n , ans);   }   void stress() {     std::mt19937 rnd(123);     for (int rep = (0); rep < (1000000); ++rep) {       ninit = rnd() % 20 + 1;       int minsz = 1;       while (minsz * minsz < ninit) ++minsz;       int sz = minsz + rnd() % (minsz + 1);       set<P> seen;       for (int i = (0); i < (ninit); ++i)         while (true) {           P p;           p.x = rnd() % sz, p.y = rnd() % sz;           if (seen.count(p)) continue;           seen.insert(p);           pinit[i] = p;           break;         }       solve();       if (rep % 1000 == 999) printf( . );     }   }   int main() {     run();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 16, inf = 2e8 + 10;   ;   int n, m, dis[maxn][maxn], deg[maxn], ans, dp[1024 * 33];   vector<int> veci;   void find(int a) {     int cnt = 0;     for (int i = 0; i < n; i++)       if ((a >> i) & 1) cnt++;     if (cnt % 2 == 1) return;     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++)         if (i != j && (a >> i) & 1 && (a >> j) & 1) {           int ki = a;           ki ^= (1 << i);           ki ^= (1 << j);           dp[a] = min(dp[a], dp[ki] + dis[veci[i]][veci[j]]);         }   }   int main() {     ios_base ::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     fill_n(dis[0], maxn * maxn, inf);     fill_n(dp, 1024 * 33, inf);     cin >> n >> m;     for (int i = 0; i < n; i++) dis[i][i] = 0;     for (int i = 0; i < m; i++) {       int u, v, w;       cin >> u >> v >> w;       u--, v--;       deg[u]++, deg[v]++;       ans += w;       dis[u][v] = dis[v][u] = min(dis[u][v], w);     }     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++)         for (int k = 0; k < n; k++)           dis[j][k] = min(dis[j][k], dis[j][i] + dis[i][k]);     for (int i = 0; i < n; i++)       if (deg[i] > 0 && dis[i][0] == inf)         return cout << -1, 0;       else if (deg[i] % 2 == 1)         veci.push_back(i);     dp[0] = 0;     for (int i = 0; i < (1 << (veci.size())); i++) find(i);     cout << ans + dp[(1 << (veci.size())) - 1];   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx )   #pragma GCC optimize( unroll-loops )   using namespace std;   using ll = long long;   using ld = long double;   using pii = pair<int, int>;   using vi = vector<int>;   const ld PI = acos(-1);   template <typename T, typename U>   inline bool chmax(T &a, U b) {     return a < b && (a = b, true);   }   template <typename T, typename U>   inline bool chmin(T &a, U b) {     return a > b && (a = b, true);   }   mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());   template <typename T, typename U>   std::ostream &operator<<(std::ostream &stream, const pair<T, U> &p) {     return stream << p.first <<     << p.second;   }   template <typename T1, typename U>   istream &operator>>(istream &is, pair<T1, U> &p) {     is >> p.first >> p.second;     return is;   }   template <typename T>   std::ostream &operator<<(std::ostream &out, const vector<T> &vec) {     for (const T &x : vec) out << x <<    ;     return out;   }   template <typename T>   std::istream &operator>>(std::istream &in, vector<T> &vec) {     for (auto &x : vec) in >> x;     return in;   }   template <typename T>   T gcd(T a, T b) {     a = abs(a);     b = abs(b);     while (b != 0) {       a = a % b;       swap(a, b);     }     return a;   }   template <typename T>   T lcm(T a, T b) {     return a / gcd(a, b) * b;   }   template <typename T, typename U>   T power(T a, T b, U mod) {     T res = 1;     while (b) {       if (b & 1) {         res = (res * a) % mod;       }       a = (a * a) % mod;       b /= 2;     }     return res;   }   template <typename T>   std::vector<T> powers(T base, int length) {     std::vector<T> result(length);     if (length > 0) {       result[0] = 1;     }     for (int i = 1; i < length; i++) {       result[i] = result[i - 1] * base;     }     return result;   }   bool miller_rabin(unsigned n) {     if (n < 2) return false;     for (unsigned p : {2, 3, 5, 7, 11, 13, 17, 19, 23, 29})       if (n % p == 0) return n == p;     int r = __builtin_ctz(n - 1);     unsigned d = (n - 1) >> r;     for (unsigned a : {2, 7, 61}) {       unsigned x = power(a % n, d, n);       if (x <= 1 || x == n - 1) continue;       for (int i = 0; i < r - 1 && x != n - 1; i++)         x = unsigned(uint64_t(x) * x % n);       if (x != n - 1) return false;     }     return true;   }   struct Sieve {     int maxn;       public:     using MapType = unordered_map<long long, long long>;     std::vector<long long> spf;     std::vector<long long> primes;     std::vector<long long> mobius;     std::vector<bool> is_prime;     explicit Sieve(int _n = 2e6 + 7) : maxn(_n + 1) {       spf.resize(maxn, 1);       is_prime.resize(maxn, true);       primes.clear();       is_prime[0] = is_prime[1] = false;       for (long long i = 2; i < maxn; ++i) {         if (is_prime[i]) {           primes.push_back(i);           spf[i] = i;         }         for (long long j = 0; j < (int)primes.size() && (i * primes[j]) < maxn &&                               primes[j] <= spf[i];              ++j) {           is_prime[i * primes[j]] = false;           spf[i * primes[j]] = primes[j];         }       }     }     void genMobius() {       mobius.resize(maxn, 0);       mobius[1] = 1;       for (long long i = 2; i < maxn; ++i) {         if (spf[i / spf[i]] == spf[i]) {           mobius[i] = 0;         } else {           mobius[i] = -mobius[i / spf[i]];         }       }     }     long long nextPrime(long long x, bool strict = false) {       auto it = upper_bound(primes.begin(), primes.end(), x);       if (!strict and is_prime[x]) return x;       next(it);       return *it;     }     bool isPrime(long long num) {       if (num < maxn) {         return is_prime[num];       }       for (long long div = 2; div * div <= num; ++div) {         if (num % div == 0) return false;       }       return true;     }     long long numDivisors(long long val) {       auto div = primeFactors(val);       long long ans = 1;       for (const auto &p : div) {         ans *= p.second + 1;       }       return ans;     }     long long countDivisors(long long n) {       if (n == 1) return 1;       long long ans = 1;       for (int i = 0;; i++) {         if (primes[i] * primes[i] * primes[i] > n) break;         int cnt = 1;         while (n % primes[i] == 0) {           n /= primes[i];           cnt++;         }         ans *= cnt;       }       if (is_prime[n])         ans = ans * 2;       else if (is_prime[sqrt(n)] && (long long)sqrt(n) == sqrt(n))         ans = ans * 3;       else if (n != 1)         ans = ans * 4;       return ans;     }     vector<pair<long long, long long>> divisorPair(long long x) {       vector<pair<long long, long long>> res;       for (long long i = 1; i * i <= x; i++) {         if (x % i == 0) {           if (x / i == i) {             res.emplace_back(i, i);           } else {             res.emplace_back(i, x / i);           }         }       }       return res;     }     vector<long long> divisor(long long x) {       vector<long long> res;       for (long long i = 1; i * i <= x; i++) {         if (x % i == 0) {           res.push_back(i);           if ((x / i) != i) {             res.push_back(x / i);           }         }       }       return res;     }     set<long long> divisorSet(long long x) {       set<long long> res;       for (long long i = 1; i * i <= x; i++) {         if (x % i == 0) {           res.insert(i);           res.insert(x / i);         }       }       return res;     }     MapType primeFactors(long long val) {       MapType fac;       while (val > 1) {         auto pf = spf[val];         if (pf == 1) break;         long long cnt = 0;         while (val % pf == 0) {           cnt++;           val /= pf;         }         fac[pf] = cnt;       }       return fac;     }     set<long long> divisorsBrute(long long val) {       set<long long> res;       for (long long i = 1; i * i <= val; i++) {         if (val % i == 0) {           if ((val / i) == i) {             res.insert(i);           } else {             res.insert(i);             res.insert(val / i);           }         }       }       return res;     }   };   Sieve sieve(sqrt(1e9 + 7));   class CPythagoreanTriples {    public:     bool ok(ll h, ll y) { return h >= 1 && y >= 1 && h <= 1e18 && y <= 1e18; }     bool solveBase(ll n) {       auto div = sieve.divisorPair(n);       for (auto [a1, b1] : div) {         for (auto [a2, b2] : div) {           for (auto [a, b] : {make_pair(a1 * a2, b1 * b2), {a1 * b2, a2 * b1}}) {             {               ll h = (a + b) / 2;               ll y = (b - a) / 2;               if (n * n == h * h - y * y && ok(h, y)) {                 cout << h <<     << y <<   n ;                 return true;               }             }             {               ll y = (a + b) / 2;               ll h = (b - a) / 2;               if (n * n == h * h - y * y && ok(h, y)) {                 cout << h <<     << y <<   n ;                 return true;               }             }           }         }       }       return false;     }     bool solveHypot(ll n) { return false; }     void solve() {       ll n;       cin >> n;       if (solveBase(n)) {         return;       } else if (solveHypot(n)) {         return;       } else {         cout << -1 <<   n ;       }     }   };   int32_t main() {     std::ios::sync_with_stdio(false);     std::cin.tie(nullptr);     std::cout.tie(nullptr);     CPythagoreanTriples solver;     solver.solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const int N = 1e6 + 7;   const int mxn = 3e5 + 9;   inline long long in() {     long long _;     scanf( %lld , &_);     return _;   }   int n, m, k;   struct node {     int len;     int link;     int firstpos;     map<char, int> nxt;     void clr() {       len = link = firstpos = 0;       nxt.clear();     }     void print() {       cerr << __FUNCTION__ <<     << 50 <<  ..  ,           cerr <<  len                 <<   =   << len,           cerr <<   ,  ,           cerr <<  link                 <<   =   << link,           cerr <<   ,  ,           cerr <<  firstpos                 <<   =   << firstpos,           cerr << endl;       for (auto z : nxt) {         cerr << z.first <<     << z.second << endl;       }     }   };   node t[mxn];   int sz, last;   void init() {     sz = last = 0;     t[0].len = 0;     t[0].firstpos = 0;     t[0].link = -1;     sz++;   }   long long cnt[mxn];   set<pair<int, int> > nodes;   void add_letter(char ch) {     int cur = sz++;     t[cur].len = t[last].len + 1;     t[cur].firstpos = t[cur].len;     cnt[cur] = 1;     nodes.insert(make_pair(t[cur].len, cur));     int p;     for (p = last; p != -1 && !t[p].nxt.count(ch); p = t[p].link)       t[p].nxt[ch] = cur;     if (p == -1)       t[cur].link = 0;     else {       int q = t[p].nxt[ch];       if (t[p].len + 1 == t[q].len)         t[cur].link = q;       else {         int clone = sz++;         t[clone].len = t[p].len + 1;         t[clone].nxt = t[q].nxt;         t[clone].link = t[q].link;         t[clone].firstpos = t[q].firstpos;         cnt[clone] = 0;         nodes.insert(make_pair(t[clone].len, clone));         for (; p != -1 && t[p].nxt[ch] == q; p = t[p].link) t[p].nxt[ch] = clone;         t[q].link = t[cur].link = clone;       }     }     last = cur;   }   string ans =   ;   void kth(int cur) {     if (k <= 0) return;     for (auto x : t[cur].nxt) {       k -= cnt[x.second];       kth(x.second);       if (k <= 0) {         ans += x.first;         return;       }     }   }   void CLR() {     for (int i = 0; i < sz; i++) {       t[i].clr();       cnt[i] = 0;     }     sz = last = 0;     nodes.clear();   }   char s[mxn];   int main() {     int tc = 1;     while (tc--) {       scanf( %s , s);       k = in();       init();       n = strlen(s);       if (1LL * n * (n + 1) < k * 2) {         printf( No such line. n );         continue;       }       for (int i = 0; i < n; i++) add_letter(s[i]);       for (set<pair<int, int> >::reverse_iterator it = nodes.rbegin();            it != nodes.rend(); it++) {         int x = (*it).second;         cnt[t[x].link] += cnt[x];       }       ans =   ;       kth(0);       reverse(ans.begin(), ans.end());       printf( %s n , ans.c_str());       if (tc) CLR();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     string s;     cin >> s;     s =  $  + s;     int n = s.length();     vector<vector<int>> c(n, vector<int>(26, 0));     for (int i = 1; i < n; i++) {       for (int j = 0; j < 26; j++) {         c[i][j] += c[i - 1][j];       }       c[i][s[i] -  a ]++;     }     int q;     cin >> q;     while (q--) {       int l, r;       cin >> l >> r;       int d = 0;       for (int j = 0; j < 26; j++) {         d += ((c[r][j] - c[l - 1][j]) > 0);       }       cout << ((l == r or s[l] != s[r] or d > 2) ?  Yes n  :  No n );     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     long long n;     cin >> n;     unordered_map<long long, long long> mymap;     long long maxval = INT_MIN, minval = INT_MAX;     for (int i = 0; i < n; i++) {       long long temp;       cin >> temp;       mymap[temp]++;       if (temp > maxval) maxval = temp;       if (temp < minval) minval = temp;     }     cout << maxval - minval <<    ;     if (maxval == minval)       cout << (mymap[maxval] * (mymap[maxval] - 1)) / 2 << endl;     else       cout << mymap[maxval] * mymap[minval] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, a, ans;   int main() {     cin >> n;     int sq;     ans = -1e9;     for (int i = 0; i < n; i++) {       cin >> a;       if (a < 0) {         ans = max(ans, a);         continue;       }       sq = sqrt(a);       if (sq * sq != a) {         ans = max(ans, a);       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct nom {     int i, a, l;   };   long long po(int a, int n) {     if (n == 0) return 1;     if (n == 1) return a;     if (n & 1)       return a * po(a * a, n / 2);     else       return po(a * a, n / 2);   }   struct rec {     int x, y, x1, y1;   };   int main() {     string a;     cin >> a;     cout << ((a.size() + 1) * 26 - a.size());   }


#include <bits/stdc++.h>   using namespace std;   int main() {     char tab[100], znak;     int konik, insekt, dlugosc, skok;     cin >> dlugosc;     cin >> skok;     for (int i = 0; i < dlugosc; i++) {       cin >> znak;       tab[i] = znak;       if (znak ==  G ) konik = i;       if (znak ==  T ) insekt = i;     }     if (konik == insekt) {       cout <<  YES ;       return 0;     }     if (konik < insekt) {       while (konik <= dlugosc && konik <= insekt) {         konik += skok;         if (konik == insekt) {           cout <<  YES ;           return 0;         }         if (tab[konik] ==  # ) {           cout <<  NO ;           return 0;         }       }       cout <<  NO ;     } else {       while (konik >= 0 && konik >= insekt) {         konik -= skok;         if (konik == insekt) {           cout <<  YES ;           return 0;         }         if (tab[konik] ==  # ) {           cout <<  NO ;           return 0;         }       }       cout <<  NO ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long ceiling(long long a, long long b) {     if (a % b != 0) {       return (a / b) + 1;     } else       return (a / b);   }   void solve() {     long long n, k;     cin >> n >> k;     long long a[n * k];     for (long long i = 0; i < n * k; i++) {       cin >> a[i];     }     sort(a, a + n * k);     long long cnt = 0;     long long cnt1 = 0;     long long i = n * k - 1 - (n / 2);     while (cnt1 < k and i >= 0) {       cnt1++;       cnt += a[i];       i -= (n / 2) + 1;     }     cout << cnt << endl;     return;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     long long tc;     cin >> tc;     while (tc--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = (long long)1e9 + 7;   string substrs(string s, int i, int j) {     string a;     for (int h = i; h < j + 1; h++) {       a.push_back(s[h]);     }     return a;   }   int main() {     int T;     cin >> T;     for (int zz = 0; zz < T; zz++) {       string s, s1;       cin >> s;       vector<int> cnt[3];       for (int i = 0; i < s.length(); i++) {         if (islower(s[i])) {           s1.push_back( l );           cnt[0].push_back(i);         } else if (isupper(s[i])) {           s1.push_back( u );           cnt[1].push_back(i);         } else if (isdigit(s[i])) {           s1.push_back( d );           cnt[2].push_back(i);         }       }       int num = 0;       for (int i = 0; i < 3; i++)         if (!cnt[i].size()) num++;       if (num == 0) {         cout << s <<   n ;         continue;       } else if (num == 1) {         for (int i = 0; i < 3; i++) {           if (!cnt[i].size()) {             for (int j = 1; j < 3; j++) {               if (cnt[(i + j) % 3].size() != 1) {                 if (i == 0)                   s[cnt[(i + j) % 3][0]] =  a ;                 else if (i == 1)                   s[cnt[(i + j) % 3][0]] =  A ;                 else if (i == 2)                   s[cnt[(i + j) % 3][0]] =  1 ;                 break;               }             }             break;           }         }       } else if (num == 2) {         for (int i = 0; i < 3; i++) {           if (cnt[i].size()) {             if (i == 0) {               s[0] =  A ;               s[1] =  1 ;             } else if (i == 1) {               s[0] =  a ;               s[1] =  1 ;             } else if (i == 2) {               s[0] =  A ;               s[1] =  a ;             }             break;           }         }       }       cout << s <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long arr[200005], sh[200005], sp[200005];   int main() {     long long i, j, k, n, m, p, q, t, cnt = 0, mn;     scanf( %lld , &n);     scanf( %lld , &k);     for (i = 0; i < n; i++) {       scanf( %lld , &arr[i]);       ;     }     sort(arr, arr + n);     for (i = 0; i < n; i++) {       cnt = 0;       while (1) {         sh[arr[i]]++;         if (sh[arr[i]] <= k) sp[arr[i]] += cnt;         if (!arr[i]) break;         arr[i] /= 2;         cnt++;       }     }     mn = sp[0];     for (i = 0; i <= 200005; i++) {       if (sh[i] >= k && sp[i] < mn) mn = sp[i];     }     cout << mn << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> v[205];   vector<int> h(205, 0);   void doit(int s, int par) {     if (par != -1) {       h[s] = 1 + h[par];     }     for (int i = 0; i < v[s].size(); i++) {       if (v[s][i] == par) continue;       doit(v[s][i], s);     }   }   string pre(string s) {     string tmp;     for (int i = 0; i < s.length(); i++) {       if (s[i] >=  A  && s[i] <=  Z ) {         tmp.push_back((char)((97 + s[i] -  A )));       } else {         tmp.push_back(s[i]);       }     }     return tmp;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     map<string, int> p;     int k = 0;     vector<string> tmp[n];     for (int i = 0; i < n; i++) {       string s1, s2, s3;       cin >> s1 >> s2 >> s3;       s1 = pre(s1);       s2 = pre(s2);       s3 = pre(s3);       if (p.find(s3) == p.end()) {         p.insert(make_pair(s3, k));         k++;       }       if (p.find(s1) == p.end()) {         p.insert(make_pair(s1, k));         k++;       }       tmp[i].push_back(s1);       tmp[i].push_back(s3);     }     for (int i = 0; i < n; i++) {       string s1 = tmp[i][0];       string s2 = tmp[i][1];       int x = p[s1];       int y = p[s2];       v[x].push_back(y);       v[y].push_back(x);     }     h[0] = 1;     doit(0, -1);     int ans = INT_MIN;     for (int i = 0; i < 205; i++) ans = max(ans, h[i]);     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100010;   int Begin[N], Next[N], to[N], cost[N], e;   void Add(int u, int v, int w) {     to[++e] = v, Next[e] = Begin[u], Begin[u] = e, cost[e] = w;   }   int n, m;   long long dis[N];   bool vis[N];   struct Vertex {     int o;     long long d;     bool operator<(const Vertex& A) const { return d > A.d; }   };   void Dijkstra() {     priority_queue<Vertex> q;     memset(dis, 0x3f, sizeof dis);     q.push((Vertex){1, 0}), dis[1] = 0;     while (!q.empty()) {       Vertex v = q.top();       q.pop();       int o = v.o;       if (vis[o]) continue;       vis[o] = true;       for (int i = Begin[o]; i; i = Next[i]) {         int u = to[i];         if (dis[u] > dis[o] + cost[i]) {           dis[u] = dis[o] + cost[i];           q.push((Vertex){u, dis[u]});         }       }     }   }   int delt[N];   queue<int> que[N];   void Work(int s) {     for (int i = 1; i <= n; i++) delt[i] = 1e9, vis[i] = false;     que[0].push(1), delt[1] = 0;     for (int i = 0; i <= s; i++)       while (!que[i].empty()) {         int o = que[i].front();         que[i].pop();         if (vis[o]) continue;         vis[o] = true;         for (int j = Begin[o]; j; j = Next[j]) {           int u = to[j];           int new_delt = dis[o] + delt[o] + cost[j] - dis[u];           if (delt[u] > new_delt) {             delt[u] = new_delt;             if (delt[u] <= s) que[delt[u]].push(u);           }         }       }     for (int i = 1; i <= n; i++) dis[i] += delt[i];   };   int q;   int main() {     scanf( %d%d%d , &n, &m, &q);     for (int i = 1; i <= m; i++) {       int u, v, c;       scanf( %d%d%d , &u, &v, &c);       Add(u, v, c);     }     Dijkstra();     while (q--) {       int ty, s;       scanf( %d%d , &ty, &s);       if (ty == 1)         printf( %I64d n , dis[s] > 1e17 ? -1 : dis[s]);       else {         for (int i = 1; i <= s; i++) {           int u;           scanf( %d , &u);           ++cost[u];         }         Work(min(s, n));       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string mat[24];   int n, m;   bool che(int i, int j) {     map<string, bool> mp;     for (int ii = 1; ii <= n; ii += i) {       for (int jj = 1; jj <= m; jj += j) {         string s2 =   ;         for (int k = ii; k < ii + i; k++) {           for (int l = jj; l < jj + j; l++) {             s2 += mat[k - 1][l - 1];           }         }         if (mp[s2]) return false;         mp[s2] = 1;         reverse(s2.begin(), s2.end());         mp[s2] = 1;         string s3 =   ;         if (i == j) {           for (int l = jj; l < jj + j; l++) {             for (int k = ii + i - 1; k >= ii; k--) {               s3 += mat[k - 1][l - 1];             }           }           mp[s3] = 1;           reverse(s3.begin(), s3.end());           mp[s3] = 1;         }       }     }     return true;   }   int main() {     cin >> n >> m;     long long ans = 0, mi = INT_MAX, mx = INT_MAX, my = INT_MAX;     for (int i = 0; i < n; i++) {       cin >> mat[i];     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         if (n % i == 0 && m % j == 0) {           if (che(i, j)) {             ans++;             if (i * j < mi || (i * j == mi && i < mx)) {               mi = i * j;               mx = i;               my = j;             }           }         }       }     }     cout << ans <<   n ;     cout << mx <<     << my <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char buf[1 << 20], *p1, *p2;   template <class T>   inline void read(T &n) {     char ch =         (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 20, stdin), p1 == p2)              ? 0              : *p1++);     T w = 1, x = 0;     while (!isdigit(ch)) {       if (ch ==  - ) w = -1;       ch =           (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 20, stdin), p1 == p2)                ? 0                : *p1++);     }     while (isdigit(ch)) {       x = (x << 3) + (x << 1) + (ch ^ 48);       ch =           (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 20, stdin), p1 == p2)                ? 0                : *p1++);     }     n = x * w;   }   const int maxn = 200005;   int n, m, q;   char s[maxn];   int sa[maxn], rk[maxn], y[maxn];   void Rsort() {     static int c[maxn];     for (int i = 1; i <= m; i++) c[i] = 0;     for (int i = 1; i <= n; i++) c[rk[i]]++;     for (int i = 1; i <= m; i++) c[i] += c[i - 1];     for (int i = n; i >= 1; i--) sa[c[rk[y[i]]]--] = y[i];   }   void getSA() {     for (int i = 1; i <= n; i++) rk[i] = s[i], y[i] = i;     m = 122, Rsort();     for (int k = 1;; k <<= 1) {       int num = 0;       for (int i = n - k + 1; i <= n; i++) y[++num] = i;       for (int i = 1; i <= n; i++)         if (sa[i] > k) y[++num] = sa[i] - k;       Rsort(), swap(rk, y);       num = rk[sa[1]] = 1;       for (int i = 2; i <= n; i++) {         if (y[sa[i]] == y[sa[i - 1]] && y[sa[i] + k] == y[sa[i - 1] + k])           rk[sa[i]] = num;         else           rk[sa[i]] = ++num;       }       if (num == n) return;       m = num;     }   }   int height[maxn], st[maxn][19], Log[maxn];   void getheight() {     for (int i = 1, k = 0; i <= n; i++) {       if (rk[i] == 1) continue;       if (k) k--;       int j = sa[rk[i] - 1];       while (i + k <= n && j + k <= n && s[i + k] == s[j + k]) k++;       height[rk[i]] = k;     }     for (int i = 2; i <= n; i++) Log[i] = Log[i >> 1] + 1;     for (int i = 1; i <= n; i++) st[i][0] = height[i];     for (int j = 1; j <= Log[n]; j++)       for (int i = 1; i + (1 << j) - 1 <= n; i++)         st[i][j] = min(st[i][j - 1], st[i + (1 << (j - 1))][j - 1]);   }   int query(int l, int r) {     if (rk[l] > rk[r]) swap(l, r);     int L = rk[l] + 1, R = rk[r];     int i = Log[R - L + 1];     return min(st[L][i], st[R - (1 << i) + 1][i]);   }   int A[maxn], B[maxn], X, Y, bel[maxn];   int bot[maxn << 1], tot, S[maxn << 1], top, sum[maxn << 1], h[maxn << 1];   bool cmp(int x, int y) { return rk[x] < rk[y]; }   long long ans, f[maxn << 1];   void solve() {     read(X), read(Y);     ans = tot = 0;     for (int i = 1; i <= X; i++) {       read(A[i]);       bel[A[i]] = 1, bot[++tot] = A[i];     }     for (int i = 1; i <= Y; i++) {       read(B[i]);       if (bel[B[i]])         ans += n - B[i] + 1, bel[B[i]] = 3;       else         bel[B[i]] = 2, bot[++tot] = B[i];     }     sort(bot + 1, bot + tot + 1, cmp);     top = 0;     for (int i = 1; i <= tot; i++) sum[i] = sum[i - 1] + (bel[bot[i]] >= 2);     for (int i = 1; i <= tot; i++) {       h[i] = query(bot[i], bot[i - 1]);       while (top && h[i] < h[S[top]]) top--;       f[i] = f[S[top]] + 1ll * h[i] * (sum[i - 1] - sum[S[top] - 1]);       if (bel[bot[i]] & 1) ans += f[i];       S[++top] = i;     }     top = 0;     for (int i = 1; i <= tot; i++) sum[i] = sum[i - 1] + (bel[bot[i]] & 1);     for (int i = 1; i <= tot; i++) {       while (top && h[i] < h[S[top]]) top--;       f[i] = f[S[top]] + 1ll * h[i] * (sum[i - 1] - sum[S[top] - 1]);       if (bel[bot[i]] >= 2) ans += f[i];       S[++top] = i;     }     for (int i = 1; i <= X; i++) bel[A[i]] = 0;     for (int i = 1; i <= Y; i++) bel[B[i]] = 0;     printf( %lld n , ans);   }   int main() {     scanf( %d%d , &n, &q);     scanf( %s , s + 1);     getSA(), getheight();     for (int i = 1; i <= q; i++) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main(void) {     long long int num, num_backup;     long long int a[2], j = 0;     cin >> num;     num_backup = num;     for (long long int i = 2; i * i <= num; i++) {       if (num % i == 0) {         a[j++] = i;         if (j == 2) break;         num /= i;         i--;       }     }     if (j == 0)       cout << 1 << endl << 0 << endl;     else if (a[0] * a[1] == num_backup || j == 1)       cout << 2 << endl;     else       cout << 1 << endl << a[0] * a[1] << endl;     return 0;   }


/*       Author: Zhikun Wang    */       #include <bits/stdc++.h>      using namespace std;      template <typename A, typename B>string to_string(pair<A, B> p);template <typename A, typename B, typename C>string to_string(tuple<A, B, C> p);template <typename A, typename B, typename C, typename D>string to_string(tuple<A, B, C, D> p);string to_string(const string& s) {  return     + s +    ;}string to_string(const char* s) {  return to_string((string) s);}string to_string(bool b) {  return (b ?  true  :  false );}string to_string(vector<bool> v) {  bool first = true;  string res =  { ;  for (int i = 0; i < static_cast<int>(v.size()); i++) {    if (!first) {      res +=  ,  ;    }    first = false;    res += to_string(v[i]);  }  res +=  } ;  return res;}template <size_t N>string to_string(bitset<N> v) {  string res =   ;  for (size_t i = 0; i < N; i++) {    res += static_cast<char>( 0  + v[i]);  }  return res;}template <typename A>string to_string(A v) {  bool first = true;  string res =  { ;  for (const auto &x : v) {    if (!first) {      res +=  ,  ;    }    first = false;    res += to_string(x);  }  res +=  } ;  return res;}template <typename A, typename B>string to_string(pair<A, B> p) {  return  (  + to_string(p.first) +  ,   + to_string(p.second) +  ) ;}template <typename A, typename B, typename C>string to_string(tuple<A, B, C> p) {  return  (  + to_string(get<0>(p)) +  ,   + to_string(get<1>(p)) +  ,   + to_string(get<2>(p)) +  ) ;}template <typename A, typename B, typename C, typename D>string to_string(tuple<A, B, C, D> p) {  return  (  + to_string(get<0>(p)) +  ,   + to_string(get<1>(p)) +  ,   + to_string(get<2>(p)) +  ,   + to_string(get<3>(p)) +  ) ;}void debug_out() { cerr << endl; }template <typename Head, typename... Tail>void debug_out(Head H, Tail... T) {  cerr <<     << to_string(H);  debug_out(T...);}      #ifdef LOCAL   #define debug(...) cerr <<  [  << #__VA_ARGS__ <<  ]: , debug_out(__VA_ARGS__)   #else   #define debug(...) 42   #endif      #define set0(x) memset(x,0,sizeof(x))   #define F first   #define S second   #define PB push_back   #define MP make_pair   #define rep(i, a, b) for(int i = a; i < (b); ++i)   #define trav(a, x) for(auto& a : x)   #define all(x) x.begin(), x.end()   #define sz(x) (int)(x).size()      typedef long long ll;   typedef pair<int,int> pii;   typedef pair<ll,ll> pll;   typedef vector<int> vi;      template<typename T> void read(T &x){       x = 0;char ch = getchar();ll f = 1;       while(!isdigit(ch)){if(ch ==  - )f*=-1;ch=getchar();}       while(isdigit(ch)){x = x*10+ch-48;ch=getchar();}x*=f;   }   template<typename T, typename... Args> void read(T &first, Args& ... args) {       read(first);       read(args...);   }      struct solver{       #define nn 55       vector<int> Map[nn];       int T, i, m, u, v;       int n, vis[nn], match[nn];       bool dfs(int u)       {           for(int i = 0; i < Map[u].size(); i++)           {               int to = Map[u][i];               if(!vis[to])               {                   vis[to] = 1;                   if(!match[to] || dfs(match[to]))                   {                       match[to] = u;                       return 1;                   }               }           }           return 0;       }       int solve()       {           memset(match, 0, sizeof(match));           int ans = 0;           for(int i = 1; i <= n; i++)//求最大匹配数           {               memset(vis, 0, sizeof(vis));               if(dfs(i)) ans++;           }           return ans;       }       void add(int u, int v){           Map[u].push_back(v);       }       int main(){           return n - solve();       }   };      int n,m,k;      int ind[55];   vi G[55],rG[55];   vi Q,A;      ll dp[55][55],fr[55][55],x[55],y[55],u,v;   int use[55],ruse[55];   int main(){       read(n,m,k);       solver S;       S.n = n;S.m = m;       for(int i=0;i<m;i++){           read(u,v);           G[u].PB(v);           rG[v].PB(u);           ind[v]+=1;           S.add(u,v);       }       for(int i=1;i<=n;i++){           use[i] = 1;           ruse[i] = 1;       }       int cs = S.main();       memset(dp,7,sizeof(dp));       dp[0][0] = 0;       int req = max(0,k-cs+1);       int la = cs;       for(int i=0;i<req;i++){           for(int j=1;j<=n;j++){               if(!use[j])continue;               use[j] = 0;               solver nS; nS.n = n;               for(int u=1;u<=n;u++){                   for(auto v:G[u]){                       if(use[u] && ruse[v])nS.add(u,v);                   }               }               if(nS.main()!=la){                   A.PB(j);                   goto nxt;               }else{                   use[j] = 1;               }           }           for(int j=1;j<=n;j++){               if(!ruse[j])continue;               ruse[j] = 0;               solver nS; nS.n = n;               for(int u=1;u<=n;u++){                   for(auto v:G[u]){                       if(use[u] && ruse[v])nS.add(u,v);                   }               }               if(nS.main()!=la){                   A.PB(-j);                   goto nxt;               }else{                   ruse[j] = 1;               }           }           nxt:;           la+=1;       }       for(int i=1;i<=k;i++){           read(x[i],y[i]);           for(int j=0;j<=req;j++){               for(int kk=max(j,i-cs+1);kk<=req;kk++){                   if(dp[i-1][j]+min(x[i],(kk-j)*y[i])<dp[i][kk]){                       dp[i][kk] = dp[i-1][j]+min(x[i],(kk-j)*y[i]);                       fr[i][kk] = j;                   }               }           }       }       vi O;       int p = req;       for(int i=k;i>=1;i--){           O.PB(0);           for(int j=fr[i][p];j<p;j++)O.PB(A[j]);           p = fr[i][p];       }       reverse(all(O));       cout<<O.size()<<endl;       for(int i=0;i<O.size();i++)cout<<O[i]<<   ;cout<<endl;       return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long res, mx, r1, r2;   int main() {     long long h, w, p, q;     cin >> h >> w;     p = 1;     while (p <= h) {       if (p > h) break;       q = (long long)(p / 4.0 * 5.0);       if (q > w) q = w;       if ((long long)(q / 4.0 * 5.0) < p) break;       if (p * q > mx) {         mx = p * q;         r1 = p;         r2 = q;       }       p *= 2;     }     q = 1;     while (q <= w) {       if (q > w) break;       p = (long long)(q / 4.0 * 5.0);       if (p > h) p = h;       if ((long long)(p / 4.0 * 5.0) < q) break;       if (p * q > mx) {         mx = p * q;         r1 = p;         r2 = q;       }       q *= 2;     }     if (r1 <= w && r2 <= h) {       if (r1 < r2) {         int temp = r1;         r1 = r2;         r2 = temp;       }     }     cout << r1 <<     << r2 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct Pair {     long long f, s;     Pair() { f = s = 0; }     Pair(long long f, long long s) {       this->f = f;       this->s = s;     }   };   const int maxn = 36 + 100;   Pair d[maxn][maxn];   int pr[maxn][maxn];   long long _10(int);   void print(int, int);   int main() {     int n;     string str;     cin >> n >> str;     for (int i = 0; i <= n; i++)       for (int j = 0; j <= n; j++) {         if (i) {           pr[i][j] = 1;           d[i][j].f = d[i - 1][j].f + _10(n - i) * (str[i + j - 1] -  0 );           d[i][j].s = d[i - 1][j].s;         }         if (j) {           if (d[i][j].f + d[i][j].s < d[i][j - 1].f + d[i][j - 1].s +                                           _10(n - j) * (str[i + j - 1] -  0 )) {             pr[i][j] = 0;             d[i][j].f = d[i][j - 1].f;             d[i][j].s = d[i][j - 1].s + _10(n - j) * (str[i + j - 1] -  0 );           }         }       }     print(n, n);     cout << endl;   }   long long _10(int k) {     long long res = 1;     while (k--) res *= 10;     return res;   }   void print(int i, int j) {     if (!i && !j) return;     if (pr[i][j]) {       print(i - 1, j);       cout <<  H ;       return;     }     print(i, j - 1);     cout <<  M ;   }


#include <bits/stdc++.h>   using namespace std;   vector<long long> vec;   int main(void) {     long long n1, n2, i, j, k, n, d;     cin >> n >> d;     for (i = 0; i < n; i++) vec.push_back(i + 1);     long long Min, Max = 0, sum;     do {       sum = 0;       for (i = 0; i < n; i++) {         for (j = i; j < n; j++) {           Min = vec[i];           for (k = i; k <= j; k++) Min = min(vec[k], Min);           sum += Min;         }       }       Max = max(Max, sum);     } while (std::next_permutation(vec.begin(), vec.end()));     long long count = 0;     sort(vec.begin(), vec.end());     do {       sum = 0;       for (i = 0; i < n; i++) {         for (j = i; j < n; j++) {           Min = vec[i];           for (k = i; k <= j; k++) Min = min(vec[k], Min);           sum += Min;         }       }       if (sum == Max) {         count++;         if (count == d) break;       }     } while (std::next_permutation(vec.begin(), vec.end()));     for (i = 0; i < n; i++) cout << vec[i] <<    ;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 10;   int n, m;   struct node {     int from, to, w;   } edge[maxn];   int in[maxn];   vector<int> e[maxn];   int top[maxn];   bool topsort(int mid) {     memset(in, 0, sizeof(in));     int cnt = 0;     queue<int> q;     for (int i = 1; i <= n; ++i) e[i].clear();     for (int i = 1; i <= m; ++i) {       if (edge[i].w > mid)         e[edge[i].from].push_back(edge[i].to), in[edge[i].to]++;     }     for (int i = 1; i <= n; ++i) {       if (!in[i]) {         q.push(i);         top[i] = ++cnt;       }     }     while (!q.empty()) {       int u = q.front();       q.pop();       for (auto it : e[u]) {         int v = it;         in[v]--;         if (!in[v]) {           q.push(v);           top[v] = ++cnt;         }       }     }     for (int i = 1; i <= n; ++i) {       if (in[i]) return false;     }     return true;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m;     for (int i = 1; i <= m; ++i) {       cin >> edge[i].from >> edge[i].to >> edge[i].w;     }     int l = 0, r = 0x3f3f3f3f;     int ret = 0;     while (l <= r) {       int mid = (l + r) >> 1;       if (topsort(mid)) {         ret = mid;         r = mid - 1;       } else         l = mid + 1;     }     topsort(ret);     vector<int> ans;     for (int i = 1; i <= m; ++i) {       if (edge[i].w <= ret && top[edge[i].from] > top[edge[i].to]) {         ans.push_back(i);       }     }     cout << ret <<     << ans.size() << endl;     for (int i = 0; i < ans.size(); ++i) {       cout << ans[i] <<    ;     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize(3)   #pragma GCC optimize( inline )   using namespace std;   long long n;   double ans;   struct dt {     double x;     double y;   } a[1 << 11];   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n;     for (register long long i = 1; (i - 1 ^ n); i++) cin >> a[i].x >> a[i].y;     for (register long long i = 1; (i - 1) ^ n; i++) {       ans += a[i].y;     }     ans /= n;     ans += 5;     cout << fixed << setprecision(3) << ans << endl;     return 0;   }


#include <bits/stdc++.h>   int min(int a, int b) {     if (a < b)       return a;     else       return b;   }   int main() {     int n, pos, l, r;     scanf( %d %d %d %d , &n, &pos, &l, &r);     if (l == 1 && r == n)       printf( 0 n );     else if (l == 1)       printf( %d n , abs(pos - r) + 1);     else if (r == n)       printf( %d n , abs(pos - l) + 1);     else       printf( %d n , min(abs(pos - r), abs(pos - l)) + abs(r - l) + 2);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const char nl =   n ;   const long long inf = 1e9 + 10;   const long long inf2 = 1e18 + 99LL;   const long double inf3 = 1e17;   const long long mod = 1e9 + 7, mod2 = 998244353;   const long double eps = 1e-9;   const bool local = false;   const int logn = 17, maxn = 1000001, maxm = 200001, maxn2 = 3;   int p[maxn], s[maxn];   int find(int v) {     if (p[v] != v) p[v] = find(p[v]);     return p[v];   }   void f(int a, int b) {     a = find(a);     b = find(b);     if (a == b) return;     if (s[a] < s[b]) swap(a, b);     p[b] = a;     s[a] += s[b];   }   vector<int> b[maxn];   int c[maxn];   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     ;     int n, q;     cin >> n >> q;     vector<int> a(n);     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < n; i++) {       int j = 2;       int ta = a[i];       while (j * j <= ta) {         if (ta % j == 0) {           b[j].push_back(i);           while (ta % j == 0) ta /= j;         }         j++;       }       if (ta > 1) b[ta].push_back(i);     }     for (int i = 0; i < n; i++) {       s[i] = 1;       p[i] = i;     }     for (int i = 0; i < maxn; i++) {       for (int j = 0; j + 1 < (int)((b[i]).size()); j++) {         f(b[i][j], b[i][j + 1]);       }     }     for (int i = 0; i < maxn; i++) {       if ((int)((b[i]).size())) {         c[i] = find(b[i][0]);       } else {         c[i] = -1;       }     }     set<pair<int, int>> st;     for (int i = 0; i < n; i++) {       int j = 2;       int ta = a[i] + 1;       vector<int> d;       while (j * j <= ta) {         if (ta % j == 0) {           d.push_back(j);           while (ta % j == 0) ta /= j;         }         j++;       }       if (ta > 1) d.push_back(ta);       vector<int> e = {find(i)};       for (int x : d) {         if (c[x] == -1) continue;         e.push_back(c[x]);       }       for (j = 0; j < (int)((e).size()); j++) {         for (int k = j + 1; k < (int)((e).size()); k++) {           int x = e[j], y = e[k];           if (x == y) continue;           if (x > y) swap(x, y);           st.emplace(x, y);         }       }     }     while (q--) {       int ts, t;       cin >> ts >> t;       ts--;       t--;       int x = find(ts), y = find(t);       if (x > y) swap(x, y);       if (x == y) {         cout << 0 << nl;       } else if (st.count({x, y})) {         cout << 1 << nl;       } else {         cout << 2 << nl;       }     }   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:1108864220 )   using namespace std;   const int MOD = 1000000007;   const int INF = 1000000000;   const double EPS = 1e-9;   const int HASH_POW = 29;   const long double PI = acos(-1.0);   mt19937_64 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());   long long nextLong(long long l, long long r) {     uniform_int_distribution<long long> foo(l, r);     return foo(rnd);   }   double nextDouble(double l, double r) {     uniform_real_distribution<double> foo(l, r);     return foo(rnd);   }   double workTime() { return double(clock()) / CLOCKS_PER_SEC; }   void myReturn(int code = 0) { exit(code); }   int n, p[100010], depth[100010];   vector<int> G[100010];   vector<int> order, oper;   bool compare(int u, int v) { return depth[u] < depth[v]; }   void dfs(int v) {     depth[v] = 0;     for (auto to : G[v]) {       dfs(to);       depth[v] = max(depth[v], depth[to] + 1);     }     sort(G[v].begin(), G[v].end(), compare);   }   void getOrder(int v) {     order.push_back(v);     for (auto to : G[v]) {       getOrder(to);     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     scanf( %d , &n);     for (int i = 1; i < n; ++i) {       scanf( %d , &p[i]);       G[p[i]].push_back(i);     }     dfs(0);     getOrder(0);     for (int i = 1; i < n; ++i) {       int v = order[i], par = order[i - 1];       while (par != p[v]) {         oper.push_back(v);         par = p[par];       }     }     for (auto i : order) {       printf( %d  , i);     }     printf(  n%d n , oper.size());     for (auto i : oper) {       printf( %d  , i);     }     myReturn();   }


#include <bits/stdc++.h>   using namespace std;   string to_string(string s) { return     + s +    ; }   string to_string(char c) { return      + string(1, c) +     ; }   string to_string(const char *s) { return to_string((string)s); }   string to_string(bool b) { return (b ?  true  :  false ); }   template <typename A, typename B>   string to_string(pair<A, B> p) {     return  (  + to_string(p.first) +  ,   + to_string(p.second) +  ) ;   }   template <typename A>   string to_string(A v) {     bool first = true;     string res =  { ;     for (const auto &x : v) {       if (!first) res +=  ,  ;       first = false;       res += to_string(x);     }     res +=  } ;     return res;   }   void debug_out() { cerr << endl; }   template <typename Head, typename... Tail>   void debug_out(Head H, Tail... T) {     cerr <<     << to_string(H);     debug_out(T...);   }   string to_str(const int &n) {     ostringstream stm;     stm << n;     return stm.str();   }   string to_str(const long long &n) {     ostringstream stm;     stm << n;     return stm.str();   }   template <class T>   string tostring(T x, int len = 0) {     stringstream ss;     ss << x;     string r = ss.str();     if (int((r).size()) < len) r = string(len - int((r).size()),  0 ) + r;     return r;   }   template <class T>   void convert(string x, T &r) {     stringstream ss(x);     ss >> r;   }   long long powmod(long long a, long long b) {     long long res = 1;     a %= 1000000007;     for (; b; b >>= 1) {       if (b & 1) res = res * a % 1000000007;       a = a * a % 1000000007;     }     return res;   }   long long modinv(long long a) { return powmod(a, 1000000007 - 2); }   long long modinv(long long a, long long m) { return powmod(a, m - 2); }   long long nCkMp(long long n, long long k) {     long long numerator = 1, denominator = 1;     for (int i = 0; i < k; i++) numerator = (numerator * (n - i)) % 1000000007;     for (int i = 1; i <= k; i++) denominator = (denominator * i) % 1000000007;     return (numerator * modinv(denominator)) % 1000000007;   }   long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }   long long lcm(long long a, long long b) { return a * (b / gcd(a, b)); }   int TT = 1, tt;   clock_t t1;   void solve() {     t1 = clock();     int n, m, c, q, res = 0;     vector<int> x(105), y;     (cin >> (n));     (cin >> (m));     for (auto i = (0); i < (m); i++) {       (cin >> (q));       x[q]++;     }     for (auto i = (105 - 1); i >= (1); i--) {       c = 0;       for (auto j = (0); j < (105); j++) c += x[j] / i;       if (c >= n) {         res = i;         break;       }     }     (cout << (res) << endl);   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     for (tt = 0; tt < TT; tt++) solve();     return EXIT_SUCCESS;   }


#include <bits/stdc++.h>   using namespace std;   using namespace chrono;   template <class T>   void show(vector<vector<T>> &a) {     for (auto &i : a) {       for (T &j : i) cout << j <<    ;       cout << endl;     }   }   template <class T>   void show(vector<T> &a) {     for (T i : a) cout << i <<    ;     cout << endl;   }   template <class T>   void show(vector<pair<T, T>> &a) {     for (auto &i : a) {       cout << i.first <<     << i.second << endl;     }   }   template <class T>   void show(pair<T, T> p) {     cout << p.first <<     << p.second << endl;   }   void show(vector<string> &a) {     for (auto &i : a) cout << i << endl;   }   template <class T>   void take(vector<T> &a) {     for (auto &i : a) cin >> i;   }   long long digits(long long n) {     long long k = 0;     while (n) k++, n /= 10;     return k;   }   bool isprime(long long n) {     long long i;     if (n == 1) return 0;     if (n == 2) return 1;     if (n % 2 == 0) return 0;     for (i = 3; i * i <= n; i += 2) {       if (n % i == 0) return 0;     }     return 1;   }   long long power(long long x, long long y, long long MOD) {     long long ans = 1;     x %= MOD;     while (y > 0) {       if (y % 2 == 1) ans = (ans * x) % MOD;       y /= 2;       x = (x * x) % MOD;     }     return ans;   }   void sieve(vector<bool> &a, long long n) {     long long i, j;     a[1] = 0;     a[0] = 0;     long long h = sqrt(n + 1);     for (i = 2; i < h; i++) {       if (!a[i]) continue;       for (j = 2 * i; j < n + 1; j += i) a[j] = 0;     }   }   void load(unordered_map<long long, long long> &g) { g.max_load_factor(0.25); }   vector<long long> bits(long long n) {     vector<long long> a;     long long i;     for (i = 0; i < 33; i++) {       a.push_back(n % 2);       n /= 2;     }     reverse(a.begin(), a.end());     return a;   }   void sub() {}   const long long N = 1e9 + 7;   const long long M = 998244353;   void solve() {     long long i, j, n, m;     cin >> n;     vector<long long> a(n);     take(a);     long long ans = 0;     for (i = 0; i < n; i++)       if (a[i] == 1) ans++;     ans = (power(2, ans, M) - 1 + M) % M;     vector<long long> b(n + 3), c(n + 3);     for (i = 0; i < n; i++) {       if (a[i] == 0) b[0] = (2 * b[0] + 1) % M;       if (a[i] == 1) b[1] = (2 * b[1] + b[0]) % M;       if (a[i] > 1) b[a[i]] = (2 * b[a[i]] + b[a[i] - 1]) % M;       if (a[i] > 1) c[a[i] - 1] = (2 * c[a[i] - 1] + b[a[i] - 2]) % M;       c[a[i] + 1] = (2 * c[a[i] + 1]) % M;     }     for (i = 0; i < n + 1; i++) {       ans = (ans + b[i] + c[i]) % M;     }     cout << ans <<   n ;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     sub();     auto start1 = high_resolution_clock::now();     long long t = 1, s;     cin >> t;     for (s = 1; s < t + 1; s++) {       solve();     }     auto stop1 = high_resolution_clock::now();     auto duration = duration_cast<microseconds>(stop1 - start1);     cerr <<  Time:   << (double)duration.count() / 1000 <<   ms  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   pair<int, int> a[10], b[10];   int main() {     for (int i = 1; i <= 3; i++) scanf( %d %d , &a[i].first, &a[i].second);     for (int i = 0; i < 8; i++) {       for (int j = 1; j <= 3; j++) b[j] = a[j];       for (int j = 1; j <= 3; j++)         if (i >> (j - 1) & 1) swap(b[j].first, b[j].second);       if (b[1].first >= b[2].first + b[3].first &&           b[1].second >= max(b[2].second, b[3].second))         puts( YES ), exit(0);       if (b[1].second >= b[2].second + b[3].second &&           b[1].first >= max(b[2].first, b[3].first))         puts( YES ), exit(0);     }     puts( NO );     return 0;   }