#include <bits/stdc++.h>   class Solver {    public:     Solver() = default;     void read() {       int n;       std::cin >> n;       int left = 0;       int right = 0;       for (int i = 0; i < n; ++i) {         int x, y;         std::cin >> x >> y;         if (x < 0)           left++;         else           right++;       }       if (left <= 1 || right <= 1)         std::cout <<  Yes n ;       else         std::cout <<  No n ;     }     void solve() {}     void write() {}   };   int main() {     Solver solver;     solver.read();     solver.solve();     solver.write();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int flow, n, m, S, T, tot, x, y;   int g[3000], dis[3000], pre[3000];   int Next[50000], adj[50000], f[50000], c[50000];   bool used[3000];   queue<int> q;   int ans = 0;   int calc[110][30];   string t, s;   void add(int x, int y, int flow, int cost) {     adj[tot] = y;     c[tot] = cost;     f[tot] = flow;     Next[tot] = g[x];     g[x] = tot++;     adj[tot] = x;     c[tot] = -cost;     f[tot] = 0;     Next[tot] = g[y];     g[y] = tot++;   }   bool spfa() {     for (int i = 1; i <= T; i++) dis[i] = 1 << 23;     dis[S] = 0;     memset(used, 0, sizeof(used));     while (!q.empty()) q.pop();     q.push(S);     used[S] = true;     int p;     while (!q.empty()) {       x = q.front();       used[x] = false;       p = g[x];       while (p != -1) {         y = adj[p];         if (f[p] && dis[x] + c[p] < dis[y]) {           dis[y] = dis[x] + c[p];           pre[y] = p;           if (!used[y]) {             used[y] = true;             q.push(y);           }         }         p = Next[p];       }       q.pop();     }     return dis[T] != 1 << 23;   }   int path() {     int del = 1 << 23;     int p = T;     while (p != S) {       if (f[pre[p]] < del) del = f[pre[p]];       p = adj[pre[p] ^ 1];     }     p = T;     while (p != S) {       f[pre[p]] -= del;       f[pre[p] ^ 1] += del;       p = adj[pre[p] ^ 1];     }     flow += del;     return del * dis[T];   }   void solve() {     memset(pre, 0, sizeof(pre));     while (spfa()) ans += path();     if (flow != t.size())       cout << -1 << endl;     else       cout << ans << endl;   }   int main() {     cin >> t;     cin >> n;     memset(g, -1, sizeof(g));     tot = 0;     S = 26 * (n + 1) + n + 1;     T = S + 1;     for (int i = 1; i <= n; i++) {       cin >> s >> x;       for (int j = 0; j < s.size(); j++) calc[i][s[j] -  a ]++;       add(S, 26 * (n + 1) + i, x, 0);     }     for (int i = 0; i < t.size(); i++) calc[n + 1][t[i] -  a ]++;     for (int i = 0; i < 26; i++) add(26 * n + i + 1, T, calc[n + 1][i], 0);     for (int i = 1; i <= n; i++)       for (int j = 0; j < 26; j++) {         add(26 * (n + 1) + i, (i - 1) * 26 + j + 1, 1 << 23, 0);         add((i - 1) * 26 + j + 1, 26 * n + j + 1, calc[i][j], i);       }     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     clock_t clk_begin = clock();     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n;     cin >> n;     string s;     cin >> s;     int c = 0;     for (int i = 0; i < n; ++i)       if (s[i] ==  8 ) c++;     n /= 11;     cout << min(n, c) <<   n ;     ;     cerr <<  Time taken:   << (double)(clock() - clk_begin) / CLOCKS_PER_SEC          <<   n ;     return 0;     ;   }


#include <bits/stdc++.h>   using namespace std;   int form[9], piece[9][2];   map<int, int> res;   string result[] = {        illegal ,  the first player won ,  the second player won ,  draw ,  first ,        second };   void pre() {     form[0] = 3;     piece[0][0] = 1;     piece[0][1] = 1 << 1;     for (int i = 1; i < 9; i++) {       form[i] = form[i - 1] << 2;       piece[i][0] = piece[i - 1][0] << 2;       piece[i][1] = piece[i - 1][1] << 2;     }   }   int add(int now, int p, int who, bool end) {     int px = p / 3 * 3, py = p % 3;     if ((piece[px][who] & now) && (piece[px + 1][who] & now) &&         (piece[px + 2][who] & now))       return who + 1;     if ((piece[py][who] & now) && (piece[py + 3][who] & now) &&         (piece[py + 6][who] & now))       return who + 1;     if ((p == 0 || p == 4 || p == 8) && (piece[0][who] & now) &&         (piece[4][who] & now) && (piece[8][who] & now))       return who + 1;     if ((p == 2 || p == 4 || p == 6) && (piece[2][who] & now) &&         (piece[4][who] & now) && (piece[6][who] & now))       return who + 1;     return end ? 3 : 5 - who;   }   void enumeration(int now, int who, int round) {     for (int p = 0; p < 9; p++) {       if (now & form[p]) continue;       now ^= piece[p][who];       if (!res[now]) {         res[now] = add(now, p, who, round == 9);         if (res[now] > 3) enumeration(now, who ^ 1, round + 1);       }       now ^= piece[p][who];     }   }   int main() {     int now = 0;     char ch;     pre();     enumeration(now, 0, 1);     for (int p = 0; p < 9; p++) {       cin >> ch;       if (ch ==  X )         now ^= piece[p][0];       else if (ch ==  0 )         now ^= piece[p][1];     }     cout << result[res[now]] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int parent(int x, vector<int> &v) {     return v[x] = (v[x] == x ? x : parent(v[x], v));   }   void u(int x, int y, vector<int> &v, vector<int> &r) {     x = parent(x, v);     y = parent(y, v);     if (r[x] == r[y]) {       if (x == y) {         return;       }       r[x]++;     }     if (r[x] > r[y]) {       v[y] = x;     } else {       v[x] = y;     }     return;   }   int main() {     int n;     scanf( %d n , &n);     vector<int> v(26, -1);     vector<int> r(26);     string s;     for (int i = 0; i < n; i++) {       cin >> s;       if (v[s[0] -  a ] == -1) {         v[s[0] -  a ] = s[0] -  a ;       }       for (int i = 1; i < (int)s.size(); i++) {         if (v[s[i] -  a ] == -1) {           v[s[i] -  a ] = s[i] -  a ;         }         u(s[i] -  a , s[0] -  a , v, r);       }     }     unordered_map<int, int> h;     for (int i = 0; i < 26; i++) {       if (v[i] != -1) {         h[parent(v[i], v)] = 1;       }     }     cout << h.size();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[105], b[105];   int main() {     int n, i, j, k, x, y;     while (~scanf( %d , &n)) {       for (i = 1; i <= n; i++) {         scanf( %d , &a[i]);       }       scanf( %d%d , &x, &y);       for (i = 1, j = 0; i <= n; i++) {         int count1 = 0, count2 = 0;         for (k = 1; k <= n; k++) {           if (k >= i)             count1 += a[k];           else             count2 += a[k];         }         if ((count1 >= x && count1 <= y) && (count2 >= x && count2 <= y)) {           b[j++] = i;           break;         }       }       if (j == 0) {         printf( 0 n );         continue;       }       printf( %d n , b[0]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     vector<vector<int>> a(n, vector<int>(m, 0));     vector<vector<int>> b(n, vector<int>(m, 0));     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         cin >> a[i][j];       }     }     vector<pair<int, int>> ans;     for (int i = 0; i < n - 1; i++) {       for (int j = 0; j < m - 1; j++) {         if (a[i][j] == 1 && a[i][j + 1] == 1 && a[i + 1][j + 1] == 1 &&             a[i + 1][j] == 1) {           ans.push_back(make_pair(i, j));           b[i][j] = 1;           b[i][j + 1] = 1;           b[i + 1][j + 1] = 1;           b[i + 1][j] = 1;         }       }     }     bool flag = true;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (a[i][j] != b[i][j]) {           flag = false;           i = n;           break;         }       }     }     if (flag) {       cout << ans.size() << endl;       for (auto it = ans.begin(); it != ans.end(); it++) {         cout << (*it).first + 1 <<     << (*it).second + 1 << endl;       }     } else       cout << -1 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T, typename U>   inline void smin(T &a, const U &b) {     if (a > b) a = b;   }   template <typename T, typename U>   inline void smax(T &a, const U &b) {     if (a < b) a = b;   }   template <class T>   inline void gn(T &first) {     char c, sg = 0;     while (c = getchar(), (c >  9  || c <  0 ) && c !=  - )       ;     for ((c ==  -  ? sg = 1, c = getchar() : 0), first = 0; c >=  0  && c <=  9 ;          c = getchar())       first = (first << 1) + (first << 3) + c -  0 ;     if (sg) first = -first;   }   template <class T1, class T2>   inline void gn(T1 &x1, T2 &x2) {     gn(x1), gn(x2);   }   int power(int a, int b, int m, int ans = 1) {     for (; b; b >>= 1, a = 1LL * a * a % m)       if (b & 1) ans = 1LL * ans * a % m;     return ans;   }   vector<int> adj[500500];   int can0[500500], can1[500500], dp0[500500], dp1[500500];   int dp[4];   int n, sz[500500];   void dfs(int u, int f = 0) {     sz[u] = 1;     for (int v : adj[u])       if (v != f) dfs(v, u), sz[u] += sz[v];     can0[u] = 1;     dp[0] = 1, dp[1] = 0;     for (int v : adj[u]) {       if (v == f) continue;       can0[u] &= can1[v];       int t[2] = {dp[0], dp[1]};       dp[0] = t[0] * can1[v];       dp[1] = t[0] * can0[v] + t[1] * can1[v];     }     can1[u] = dp[1];     dp[0] = 1, dp[1] = 0;     for (int v : adj[u]) {       if (v == f) continue;       int t[2] = {dp[0], dp[1]};       dp[0] = t[0] * can1[v];       dp[1] = t[1] * can1[v] + t[0] * dp1[v];     }     dp0[u] = dp[1];     dp1[u] = can0[u];     dp[0] = 1, dp[1] = 0;     for (int v : adj[u]) {       if (v == f) continue;       int t[2] = {dp[0], dp[1]};       dp[0] = t[0] * can1[v];       dp[1] = t[1] * can1[v] + t[0] * dp0[v];     }     dp1[u] += dp[1];     dp[0] = 1, dp[1] = dp[2] = dp[3] = 0;     for (int v : adj[u]) {       if (v == f) continue;       int t[4] = {dp[0], dp[1], dp[2], dp[3]};       dp[0] = t[0] * can1[v];       dp[1] = t[0] * can0[v] + t[1] * can1[v];       dp[2] = t[0] * dp1[v] + t[2] * can1[v];       dp[3] = t[1] * dp1[v] + t[2] * can0[v] + t[3] * can1[v];     }     dp1[u] += dp[3];   }   long long ans;   int c0[500500], c1[500500], d0[500500], d1[500500];   int R[500500], Rdp[500500][4];   void redfs(int u, int f = 0) {     if (f) {       if (can1[u] && c1[u])         ans += (long long)sz[u] * (n - sz[u]);       else         ans += (long long)dp1[u] * d1[u];     }     R[adj[u].size()] = 1;     Rdp[adj[u].size()][0] = 1;     Rdp[adj[u].size()][1] = 0;     for (int i = adj[u].size(); i--;) {       int v = adj[u][i];       R[i] = R[i + 1] & (v == f ? c1[u] : can1[v]);       Rdp[i][0] = Rdp[i + 1][0] * (v == f ? c1[u] : can1[v]);       Rdp[i][1] = Rdp[i + 1][0] * (v == f ? c0[u] : can0[v]) +                   Rdp[i + 1][1] * (v == f ? c1[u] : can1[v]);     }     int cur = 1;     dp[0] = 1, dp[1] = 0;     for (int i = 0; i < adj[u].size(); i++) {       int v = adj[u][i];       if (v != f) {         c0[v] = cur & R[i + 1];         c1[v] = dp[0] & Rdp[i + 1][1] | dp[1] & Rdp[i + 1][0];       }       int t[2] = {dp[0], dp[1]};       cur &= (v == f ? c1[u] : can1[v]);       dp[0] = t[0] * (v == f ? c1[u] : can1[v]);       dp[1] =           t[0] * (v == f ? c0[u] : can0[v]) + t[1] * (v == f ? c1[u] : can1[v]);     }     Rdp[adj[u].size()][0] = 1;     Rdp[adj[u].size()][1] = 0;     for (int i = adj[u].size(); i--;) {       int v = adj[u][i];       Rdp[i][0] = Rdp[i + 1][0] * (v == f ? c1[u] : can1[v]);       Rdp[i][1] = Rdp[i + 1][0] * (v == f ? d1[u] : dp1[v]) +                   Rdp[i + 1][1] * (v == f ? c1[u] : can1[v]);     }     dp[0] = 1, dp[1] = 0;     for (int i = 0; i < adj[u].size(); i++) {       int v = adj[u][i];       if (v != f) d0[v] = dp[0] * Rdp[i + 1][1] + dp[1] * Rdp[i + 1][0];       int t[2] = {dp[0], dp[1]};       dp[0] = t[0] * (v == f ? c1[u] : can1[v]);       dp[1] =           t[1] * (v == f ? c1[u] : can1[v]) + t[0] * (v == f ? d1[u] : dp1[v]);     }     for (int v : adj[u])       if (v != f) d1[v] = c0[v];     Rdp[adj[u].size()][0] = 1;     Rdp[adj[u].size()][1] = 0;     for (int i = adj[u].size(); i--;) {       int v = adj[u][i];       Rdp[i][0] = Rdp[i + 1][0] * (v == f ? c1[u] : can1[v]);       Rdp[i][1] = Rdp[i + 1][0] * (v == f ? d0[u] : dp0[v]) +                   Rdp[i + 1][1] * (v == f ? c1[u] : can1[v]);     }     dp[0] = 1, dp[1] = 0;     for (int i = 0; i < adj[u].size(); i++) {       int v = adj[u][i];       if (v != f) d1[v] += dp[0] * Rdp[i + 1][1] + dp[1] * Rdp[i + 1][0];       int t[2] = {dp[0], dp[1]};       dp[0] = t[0] * (v == f ? c1[u] : can1[v]);       dp[1] =           t[1] * (v == f ? c1[u] : can1[v]) + t[0] * (v == f ? d0[u] : dp0[v]);     }     Rdp[adj[u].size()][0] = 1;     Rdp[adj[u].size()][1] = 0;     Rdp[adj[u].size()][2] = 0;     Rdp[adj[u].size()][3] = 0;     for (int i = adj[u].size(); i--;) {       int v = adj[u][i];       Rdp[i][0] = Rdp[i + 1][0] * (v == f ? c1[u] : can1[v]);       Rdp[i][1] = Rdp[i + 1][0] * (v == f ? c0[u] : can0[v]) +                   Rdp[i + 1][1] * (v == f ? c1[u] : can1[v]);       Rdp[i][2] = Rdp[i + 1][0] * (v == f ? d1[u] : dp1[v]) +                   Rdp[i + 1][2] * (v == f ? c1[u] : can1[v]);       Rdp[i][3] = Rdp[i + 1][1] * (v == f ? d1[u] : dp1[v]) +                   Rdp[i + 1][2] * (v == f ? c0[u] : can0[v]) +                   Rdp[i + 1][3] * (v == f ? c1[u] : can1[v]);     }     dp[0] = 1, dp[1] = dp[2] = dp[3] = 0;     for (int i = 0; i < adj[u].size(); i++) {       int v = adj[u][i];       if (v != f)         d1[v] += dp[0] * Rdp[i + 1][3] + dp[1] * Rdp[i + 1][2] +                  dp[2] * Rdp[i + 1][1] + dp[3] * Rdp[i + 1][0];       int t[4] = {dp[0], dp[1], dp[2], dp[3]};       dp[0] = t[0] * (v == f ? c1[u] : can1[v]);       dp[1] =           t[0] * (v == f ? c0[u] : can0[v]) + t[1] * (v == f ? c1[u] : can1[v]);       dp[2] =           t[0] * (v == f ? d1[u] : dp1[v]) + t[2] * (v == f ? c1[u] : can1[v]);       dp[3] = t[1] * (v == f ? d1[u] : dp1[v]) +               t[2] * (v == f ? c0[u] : can0[v]) +               t[3] * (v == f ? c1[u] : can1[v]);     }     for (int v : adj[u])       if (v != f) redfs(v, u);   }   int main() {     cin >> n;     for (int i = 1; i < n; i++) {       int u, v;       gn(u, v);       adj[u].push_back(v);       adj[v].push_back(u);     }     dfs(1);     redfs(1);     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using pii = pair<int, int>;      void solve() {    int m, k;    cin >> m >> k;       vector<pii> a;       int ai;    for (int i = 1; i <= k; i++) {     cin >> ai;     a.push_back({ai, i});    }       sort(a.begin(), a.end(), greater<pii>());       int n = 1;    for (; ; n++) {     if (m > n * n - (n / 2) * (n / 2)) continue;     if (a[0].first > n * ((n + 1) / 2)) continue;     break;    }        vector<pii> pos[3];    for (int i = 0; i < n; i++) {     for (int j = 0; j < n; j++) {      int idx = ((i & 1) << 1) + (j & 1);      if (idx != 3)        pos[idx].push_back({i, j});     }    }       vector<vector<int>> ans(n, vector<int>(n, 0));       for (auto [cnt, val] : a) {     vector<pii> &curr = pos[1].empty() ? pos[2] : pos[1];        for (; !curr.empty() && cnt > 0; cnt--) {      auto [x, y] = curr.back();      curr.pop_back();      ans[x][y] = val;     }     for (; cnt > 0; cnt--) {      auto [x, y] = pos[0].back();      pos[0].pop_back();      ans[x][y] = val;     }    }       cout << n <<   n ;    for (int i = 0; i < n; i++) {     for (int j = 0; j < n; j++) {      cout << ans[i][j] <<    ;     }     cout <<   n ;    }   }      int main() {    ios_base::sync_with_stdio(0);    cin.tie(0);       int t;    cin >> t;       while (t--) {     solve();    }       return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 211, M = N * N / 2;   int u[M], v[M], w[M];   int f[N][N];   bool check(int n, int m, int lim) {     for (int i = 1; i <= m; i++) {       vector<pair<int, int>> v;       bool t = 1;       for (int j = 1; j <= n; j++) {         int l = f[j][u[i]], r = f[j][::v[i]];         if (lim >= l && lim >= r) {           if (2 * lim - l - r >= w[i]) {             v.push_back({0, 1});             v.push_back({w[i] + 1, -1});           } else {             v.push_back({0, 1});             v.push_back({min(w[i], lim - l) + 1, -1});             v.push_back({w[i] - min(w[i], lim - r), 1});             v.push_back({w[i] + 1, -1});           }         } else if (lim >= l) {           v.push_back({0, 1});           v.push_back({min(w[i], lim - l) + 1, -1});         } else if (lim >= r) {           v.push_back({w[i] - min(w[i], lim - r), 1});           v.push_back({w[i] + 1, -1});         } else {           t = 0;           break;         }       }       if (!t) continue;       sort(v.begin(), v.end());       int cnt = 0;       for (auto e : v) {         cnt += e.second;         if (cnt == n) return 1;       }     }     return 0;   }   int main() {     ios ::sync_with_stdio(0);     int n, m;     cin >> n >> m;     memset(f, 0x3f, sizeof f);     for (int i = 1; i <= n; i++) f[i][i] = 0;     for (int i = 1; i <= m; i++) {       cin >> u[i] >> v[i] >> w[i];       w[i] *= 2;       f[u[i]][v[i]] = f[v[i]][u[i]] = w[i];     }     for (int k = 1; k <= n; k++)       for (int i = 1; i <= n; i++)         for (int j = 1; j <= n; j++) f[i][j] = min(f[i][j], f[i][k] + f[k][j]);     int l = 0, r = 1e8L;     while (l + 1 < r) {       int im = (l + r) / 2;       if (check(n, m, im - 1))         r = im;       else         l = im;     }     cout << fixed << setprecision(1);     cout << l / 2.0 <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int ans1, ans2;   int t[4], v[4][10], T[10][10], A, B, C;   map<string, int> mymap;   const char *help[] = { Anka ,    Chapay ,  Cleo ,        Troll ,                          Dracul ,  Snowy ,   Hexadecimal };   int countT() {     int ret = 0;     for (int k = 0; k < 3; k++) {       for (int i = 0; i < t[k]; i++)         for (int j = 0; j < t[k]; j++)           if (T[v[k][i]][v[k][j]]) ret++;     }     return ret;   }   void go(int x) {     if (x == 8) {       if (!t[0] || !t[1] || !t[2]) return;       int h[4];       h[0] = A / t[0];       h[1] = B / t[1];       h[2] = C / t[2];       sort(h, h + 3);       int d = h[2] - h[0];       int p = countT();       if (d < ans1) {         ans1 = d;         ans2 = p;       } else if (d == ans1) {         ans2 = max(ans2, p);       }       return;     }     for (int i = 0; i < 3; i++) {       v[i][t[i]++] = x;       go(x + 1);       t[i]--;     }     return;   }   int main() {     char s1[30], s2[30], s3[30];     for (int i = 0; i < 7; i++) mymap[help[i]] = i + 1;     memset(T, 0, sizeof(T));     int m;     cin >> m;     while (m--) {       cin >> s1 >> s2 >> s3;       int u, v;       u = mymap[s1];       v = mymap[s3];       T[u][v] = 1;     }     cin >> A >> B >> C;     ans1 = 2000000001;     ans2 = 0;     memset(t, 0, sizeof(t));     go(1);     cout << ans1 <<     << ans2 << endl;     return 0;   }


#include <bits/stdc++.h>   typedef long long ll ;   using namespace std;   const int maxn=2e5+5;   const int maxm=5e6+5;   #define P pair<int,int>   #define fi first   #define se second   int t,n;   int a[maxn];   int vis[maxm*2];   P mp[maxm];         int main() {       ios::sync_with_stdio(false);       cin.tie(nullptr), cout.tie(nullptr);       cin>>n;       for(int i=1;i<=n;i++){           cin>>a[i];       }       int sum1;       for(int i=1;i<=n;i++){           for(int j=i+1;j<=n;j++){               sum1=a[i]+a[j];               if(mp[sum1].fi==0 &&mp[sum1].se==0){                   mp[sum1]={i,j};               }else if(i!=mp[sum1].fi&&i!=mp[sum1].se&&j!=mp[sum1].fi&&j!=mp[sum1].se){                   cout<< YES <<endl;                   cout<<i<<   <<j<<   <<mp[sum1].fi<<   <<mp[sum1].se<<endl;                   return 0;               }           }       }       cout<< NO <<endl;       return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   T BigMod(T b, T p, T m) {     if (p == 0) return 1;     if (p % 2 == 0) {       T s = BigMod(b, p / 2, m);       return ((s % m) * (s % m)) % m;     }     return ((b % m) * (BigMod(b, p - 1, m) % m)) % m;   }   template <typename T>   T ModInv(T b, T m) {     return BigMod(b, m - 2, m);   }   template <typename T>   T in() {     char ch;     T n = 0;     bool ng = false;     while (1) {       ch = getchar();       if (ch ==  - ) {         ng = true;         ch = getchar();         break;       }       if (ch >=  0  && ch <=  9 ) break;     }     while (1) {       n = n * 10 + (ch -  0 );       ch = getchar();       if (ch <  0  || ch >  9 ) break;     }     return (ng ? -n : n);   }   template <typename T>   T POW(T B, T printf) {     if (printf == 0) return 1;     if (printf & 1)       return B * POW(B, printf - 1);     else       return (POW(B, printf / 2) * POW(B, printf / 2));   }   template <typename T>   T Bigmod(T b, T p, T m) {     if (p == 0)       return 1;     else if (!(p & 1))       return (Bigmod(b, p / 2, m) * Bigmod(b, p / 2, m)) % m;     else       return ((b % m) * Bigmod(b, p - 1, m)) % m;   }   template <typename T>   T Dis(T x1, T y1, T x2, T y2) {     return sqrt((x1 - x2 * x1 - x2) + (y1 - y2 * y1 - y2));   }   template <typename T>   T Angle(T x1, T y1, T x2, T y2) {     return atan(double(y1 - y2) / double(x1 - x2));   }   template <typename T>   T DIFF(T a, T b) {     T d = a - b;     if (d < 0)       return -d;     else       return d;   }   template <typename T>   T ABS(T a) {     if (a < 0)       return -a;     else       return a;   }   template <typename T>   T gcd(T a, T b) {     if (a < 0) return gcd(-a, b);     if (b < 0) return gcd(a, -b);     return (b == 0) ? a : gcd(b, a % b);   }   template <typename T>   T lcm(T a, T b) {     if (a < 0) return lcm(-a, b);     if (b < 0) return lcm(a, -b);     return a * (b / gcd(a, b));   }   template <typename T>   T euclide(T a, T b, T &x, T &y) {     if (a < 0) {       T d = euclide(-a, b, x, y);       x = -x;       return d;     }     if (b < 0) {       T d = euclide(a, -b, x, y);       y = -y;       return d;     }     if (b == 0) {       x = 1;       y = 0;       return a;     } else {       T d = euclide(b, a % b, x, y);       T t = x;       x = y;       y = t - (a / b) * y;       return d;     }   }   template <typename T>   void ia(T a[], int n) {     for (int i = 0; i < n; i++) cin >> a[i];   }   template <typename T>   void pa(T a[], int n) {     for (int i = 0; i < n - 1; i++) cout << a[i] <<    ;     cout << a[n - 1] << endl;   }   template <typename T>   long long int isLeft(T a, T b, T c) {     return (a.x - b.x) * (b.y - c.y) - (b.x - c.x) * (a.y - b.y);   }   int Set(int N, int pos) { return N = N | (1 << pos); }   int Reset(int N, int pos) { return N = N & ~(1 << pos); }   bool Check(int N, int pos) { return (bool)(N & (1 << pos)); }   template <class T, class first>   inline T togglebit(T a, first i) {     T t = 1;     return (a ^ (t << i));   }   int toInt(string s) {     int sm;     stringstream ss(s);     ss >> sm;     return sm;   }   int toLlint(string s) {     long long int sm;     stringstream ss(s);     ss >> sm;     return sm;   }   int cdigittoint(char ch) { return ch -  0 ; }   bool isVowel(char ch) {     ch = toupper(ch);     if (ch ==  A  || ch ==  U  || ch ==  I  || ch ==  O  || ch ==  E )       return true;     return false;   }   bool isConst(char ch) {     if (isalpha(ch) && !isVowel(ch)) return true;     return false;   }   double DEG(double x) { return (180.0 * x) / (2.0 * acos(0.0)); }   double RAD(double x) { return (x * (double)2.0 * acos(0.0)) / (180.0); }   vector<int> adj[200007], dag[200007], par[200007];   int DP[200007][18], siz[200007];   long long int dis[200007];   int L[200007];   int inDeg[200007];   bool vis[200007];   void Init(int n) {     for (int i = 0; i <= n; i++) {       dis[i] = 1LL << 60;       adj[i].clear();       dag[i].clear();       par[i].clear();       inDeg[i] = siz[i] = vis[i] = 0;       for (int j = 0; j < 18; j++) DP[i][j] = -1;     }   }   void Update(int u, int p) {     DP[u][0] = p;     L[u] = L[p] + 1;     adj[p].push_back(u);     for (int i = 1; i < 18; i++)       if (DP[u][i - 1] != -1) DP[u][i] = DP[DP[u][i - 1]][i - 1];   }   int LCA(int p, int q) {     if (L[p] < L[q]) swap(p, q);     for (int i = 18 - 1; i >= 0; i--)       if (L[p] - (1 << i) >= L[q]) p = DP[p][i];     if (p == q) return p;     for (int i = 18 - 1; i >= 0; i--)       if (DP[p][i] != -1 && DP[p][i] != DP[q][i]) {         p = DP[p][i];         q = DP[q][i];       }     return DP[p][0];   }   void Dijkstra(int n, int s) {     set<pair<long long int, long long int> > pq;     pq.insert(make_pair(0, s));     dis[s] = 0;     L[s] = 1;     while (!pq.empty()) {       pair<long long int, long long int> tmp = *pq.begin();       pq.erase(pq.begin());       int u = tmp.second;       for (int i = 0; i < adj[u].size(); i += 2) {         int v = adj[u][i];         int w = adj[u][i + 1];         if (dis[v] > dis[u] + w) {           dis[v] = dis[u] + w;           pq.insert(make_pair(dis[v], v));         }       }     }     for (int i = 1; i <= n; i++) {       for (int j = 0; j < adj[i].size(); j += 2) {         int v = adj[i][j];         int w = adj[i][j + 1];         if (dis[i] + w == dis[v]) {           inDeg[v]++;           dag[i].push_back(v);           par[v].push_back(i);         }       }       adj[i].clear();     }   }   void TopSort(int s) {     queue<int> q;     q.push(s);     L[s] = 1;     while (!q.empty()) {       int u = q.front();       q.pop();       if (!par[u].empty()) {         int lca = par[u][0];         for (int i = 1; i < par[u].size(); i++) {           lca = LCA(lca, par[u][i]);         }         Update(u, lca);       }       for (int i = 0; i < dag[u].size(); i++) {         int v = dag[u][i];         inDeg[v]--;         if (!inDeg[v]) q.push(v);       }     }   }   void Dfs(int u) {     siz[u] = 1;     vis[u] = 1;     for (int i = 0; i < adj[u].size(); i++) {       Dfs(adj[u][i]);       siz[u] += siz[adj[u][i]];     }   }   int main() {     int n, m, s;     scanf( %d%d%d , &n, &m, &s);     Init(n);     for (int i = 1; i <= m; i++) {       int u, v, w;       scanf( %d%d%d , &u, &v, &w);       adj[u].push_back(v);       adj[u].push_back(w);       adj[v].push_back(u);       adj[v].push_back(w);     }     Dijkstra(n, s);     TopSort(s);     Dfs(s);     int mx = 0;     for (int i = 1; i <= n; i++) {       if (i != s) mx = max(mx, siz[i]);     }     cout << mx << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int M = 2048;   char s[M], b[M], e[M], fb[M], fe[M];   int r[2][M], *p = r[0], *q = r[1], h[M];   int main(void) {     cin >> s >> b >> e;     int ns = strlen(s), nb = strlen(b), ne = strlen(e), nn = nb > ne ? nb : ne,         w = 0;     for (int i = ns; i-- > 0;) {       if (!strncmp(s + i, b, nb)) fb[i] = 1;       if (!strncmp(s + i, e, ne)) fe[i] = 1;     }     for (int i = 0, *t; i < ns; ++i, t = p, p = q, q = t)       for (int j = i; j-- > 0;) {         q[j + 1] = (s[i] == s[j]) ? (p[j] + 1) : 0;         if (h[i] < q[j + 1]) h[i] = q[j + 1];       }     for (int i = ns; i-- > 0;)       if (fb[i])         for (int j = i + nn; j <= ns; ++j)           if (fe[j - ne] && h[j - 1] < j - i) ++w;     cout << w << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   int inv[25];   long long a[25];   int power(int a, int b) {     int c = 1;     for (; b; b >>= 1) {       if (b & 1) c = (long long)c * a % mod;       a = (long long)a * a % mod;     }     return c;   }   int C(long long y, int x) {     if (y < 0 || x < 0 || y < x) return 0;     y %= mod;     if (y == 0 || x == 0) return 1;     int ans = 1;     for (int i = 0; i < x; i++) ans = (long long)ans * (y - i) % mod;     for (int i = 1; i <= x; i++) ans = (long long)ans * inv[i] % mod;     return ans;   }   int main() {     int n;     long long m;     long long ans = 0;     for (int i = 1; i <= 20; i++) inv[i] = power(i, mod - 2);     cin >> n >> m;     for (int i = 1; i <= n; i++) cin >> a[i];     for (int x = 0; x < (1 << n); x++) {       if (x == 0)         ans = (ans + C(n + m - 1, n - 1)) % mod;       else {         long long t = n + m;         int p = 0;         for (int i = 0; i < n; i++)           if ((x >> i) & 1) {             p++;             t -= a[i + 1];           }         t -= (p + 1);         if (p & 1)           ans = (ans - C(t, n - 1)) % mod;         else           ans = (ans + C(t, n - 1)) % mod;       }     }     cout << (ans + mod) % mod << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T1, typename T2>   string print_iterable(T1 begin_iter, T2 end_iter, int counter) {     bool done_something = false;     stringstream res;     res <<  [ ;     for (; begin_iter != end_iter and counter; ++begin_iter) {       done_something = true;       counter--;       res << *begin_iter <<  ,  ;     }     string str = res.str();     if (done_something) {       str.pop_back();       str.pop_back();     }     str +=  ] ;     return str;   }   vector<int> SortIndex(int size, std::function<bool(int, int)> compare) {     vector<int> ord(size);     for (int i = 0; i < size; i++) ord[i] = i;     sort(ord.begin(), ord.end(), compare);     return ord;   }   template <typename T>   bool MinPlace(T& a, const T& b) {     if (a > b) {       a = b;       return true;     }     return false;   }   template <typename T>   bool MaxPlace(T& a, const T& b) {     if (a < b) {       a = b;       return true;     }     return false;   }   const int MAXN = 100100;   int a[MAXN];   int pr[MAXN];   int last_apparizione[MAXN];   int N;   int res[MAXN];   int EasyCalc(int k) {     if (res[k]) return res[k];     int ris = 1;     int curr_start = 0;     int curr_size = 1;     for (int i = 1; i < N; i++) {       curr_size += curr_start > pr[i];       if (curr_size > k) {         curr_size = 1;         curr_start = i;         ris++;       }     }     return ris;   }   int main() {     ios::sync_with_stdio(false);     cin >> N;     for (int i = 0; i < N; i++) cin >> a[i];     for (int i = 0; i < MAXN; i++) last_apparizione[i] = -1;     for (int i = 0; i < N; i++) {       pr[i] = last_apparizione[a[i]];       last_apparizione[a[i]] = i;     }     int rad = min((int)(2 * sqrt(N)), N);     for (int k = 1; k <= rad; k++) res[k] = EasyCalc(k);     int curr = rad;     while (curr <= N) {       int l = curr + 1;       int r = N + 1;       while (l < r) {         int m = (l + r) / 2;         res[m] = EasyCalc(m);         if (res[m] == res[curr])           l = m + 1;         else           r = m;       }       int prox = l;       for (int i = curr + 1; i < prox; i++) res[i] = res[curr];       curr = prox;     }     for (int k = 1; k <= N; k++) cout << res[k] <<    ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, ans = 0;     cin >> n;     for (int i = 0; i < n; i++) {       int x, y, z;       cin >> x >> y >> z;       ans += (x + y + z >= 2);     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char str[1010];   int pri[510][510];   int pre[510][510];   int f[510][510];   bool v[510] = {0};   int N;   void init() {     gets(str);     scanf( %d , &N);   }   void prework() {     int len = strlen(str);     for (int i = 0; i < len; ++i)       for (int j = 0; j < len; ++j) {         int p = 0;         int tmp = 0;         while (i + p < j - p) {           if (str[i + p] != str[j - p]) tmp++;           p++;         }         pri[i + 1][j + 1] = tmp;       }   }   void dp() {     int len = strlen(str);     memset(f, 10, sizeof(f));     f[0][0] = 0;     for (int i = 1; i <= len; ++i) {       for (int j = 1; j <= N; ++j)         for (int k = 0; k < i; ++k) {           if (f[i][j] > f[k][j - 1] + pri[k + 1][i]) {             f[i][j] = f[k][j - 1] + pri[k + 1][i];             pre[i][j] = k;           }         }     }     int Ans = 1000000000;     int p;     for (int i = 1; i <= N; ++i)       if (f[len][i] < Ans) {         Ans = f[len][i];         p = i;       }     printf( %d n , Ans);     int q = len;     while (q != 0) {       v[pre[q][p]] = 1;       int x = 0;       while (pre[q][p] + x < q - 1 - x) {         str[pre[q][p] + x] = str[q - 1 - x];         x++;       }       q = pre[q][p];       p--;     }     v[0] = 0;     for (int i = 0; i < len; ++i) {       if (v[i]) putchar( + );       putchar(str[i]);     }   }   int main() {     init();     prework();     dp();     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC optimize( unroll-loops )   #pragma GCC target(         sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native )   using namespace std;   template <typename T1, typename T2>   void ckmin(T1 &a, T2 b) {     if (a > b) a = b;   }   template <typename T1, typename T2>   void ckmax(T1 &a, T2 b) {     if (a < b) a = b;   }   int read() {     int x = 0, f = 0;     char ch = getchar();     while (!isdigit(ch)) f |= ch ==  - , ch = getchar();     while (isdigit(ch)) x = 10 * x + ch -  0 , ch = getchar();     return f ? -x : x;   }   template <typename T>   void print(T x) {     if (x < 0) putchar( - ), x = -x;     if (x >= 10) print(x / 10);     putchar(x % 10 +  0 );   }   template <typename T>   void print(T x, char let) {     print(x), putchar(let);   }   const int mod = 998244353;   const int G = 3, Gi = 332748118;   int add(int x, int y) {     if ((x += y) >= mod) x -= mod;     return x;   }   int sub(int x, int y) {     if ((x -= y) < 0) x += mod;     return x;   }   int qpow(int a, int b = mod - 2) {     int res = 1;     while (b > 0) {       if (b & 1) res = 1ll * res * a % mod;       a = 1ll * a * a % mod;       b >>= 1;     }     return res;   }   namespace Poly {   vector<int> Rev, W;   int lim, L;   void getR(int len) {     lim = 1, L = 0;     while (lim <= len) lim <<= 1, L++;     Rev.resize(lim), W.resize(lim), W[0] = 1;     for (int i = 0; i < lim; i++)       Rev[i] = (Rev[i >> 1] >> 1) | ((i & 1) << L - 1);   }   void wf(vector<int> &a) {     int n = a.size();     for (int i = 0; i < n; i++) a[i] = 1ll * (i + 1) * a[i + 1] % mod;     a[n - 1] = 0;   }   void jf(vector<int> &a) {     int n = a.size();     for (int i = n - 1; i >= 1; i--) a[i] = 1ll * a[i - 1] * qpow(i) % mod;     a[0] = 0;   }   void NTT(vector<int> &a, int opt) {     for (int i = 0; i < lim; i++)       if (i < Rev[i]) swap(a[i], a[Rev[i]]);     for (int mid = 1; mid < lim; mid <<= 1) {       int Wn = qpow(opt == 1 ? G : Gi, (mod - 1) / (mid << 1));       for (int k = 1; k < mid; k++) W[k] = 1ll * W[k - 1] * Wn % mod;       for (int j = 0; j < lim; j += mid << 1) {         for (int k = 0; k < mid; k++) {           int x = a[j + k], y = 1ll * W[k] * a[j + k + mid] % mod;           a[j + k] = add(x, y);           a[j + k + mid] = sub(x, y);         }       }     }     if (opt == -1) {       int linv = qpow(lim);       for (int i = 0; i < lim; i++) a[i] = 1ll * a[i] * linv % mod;     }   }   vector<int> operator*(vector<int> a, vector<int> b) {     int len = a.size() + b.size() - 1;     getR(len);     a.resize(lim), b.resize(lim);     NTT(a, 1), NTT(b, 1);     for (int i = 0; i < lim; i++) a[i] = 1ll * a[i] * b[i] % mod;     NTT(a, -1);     a.resize(len);     return a;   }   vector<int> Inv(vector<int> a) {     if ((int(a.size())) == 1) return vector<int>(1, qpow(a[0]));     int len = a.size();     vector<int> ta = a;     ta.resize((len + 1) / 2);     vector<int> tb = Inv(ta);     getR(2 * len), a.resize(lim), tb.resize(lim);     NTT(a, 1), NTT(tb, 1);     for (int i = 0; i < lim; i++)       tb[i] = 1ll * tb[i] * (mod + 2 - 1ll * a[i] * tb[i] % mod) % mod;     NTT(tb, -1);     tb.resize(len);     return tb;   }   vector<int> Ln(vector<int> a) {     vector<int> ta = a;     wf(ta);     int len = a.size();     a = ta * Inv(a), jf(a);     a.resize(len);     return a;   }   vector<int> Exp(vector<int> a) {     if ((int(a.size())) == 1) return vector<int>(1, 1);     int len = a.size();     vector<int> ta = a;     ta.resize((len + 1) / 2);     vector<int> tb = Exp(ta);     tb.resize(len);     vector<int> Lnb = Ln(tb);     assert(Lnb.size() == len);     for (int i = 0; i < len; i++) Lnb[i] = (a[i] - Lnb[i] + mod) % mod;     Lnb[0] = (Lnb[0] + 1) % mod;     tb = tb * Lnb;     tb.resize(len);     return tb;   }   }  // namespace Poly   using namespace Poly;   const int N = 250005;   const int B = 15;   vector<int> adj[N];   int n;   int son[N];   void dfs1(int u, int fa) {     for (auto v : adj[u]) {       if (v == fa) continue;       son[u]++;       dfs1(v, u);     }   }   int two[N], len;   vector<int> solve(int l, int r) {     if (l > r) return {1};     if (l == r) return {1, mod - two[l]};     int mid = l + r >> 1;     return solve(l, mid) * solve(mid + 1, r);   }   int fac[N], inv[N];   int fuck[N];   int main() {     n = read();     inv[1] = 1;     for (int i = 2; i <= n; i++)       inv[i] = 1ull * (mod - mod / i) * inv[mod % i] % mod;     fac[0] = 1;     for (int i = 1; i <= n; i++) fac[i] = 1ull * fac[i - 1] * i % mod;     for (int i = 1; i <= n - 1; i++) {       int u = read(), v = read();       adj[u].push_back(v), adj[v].push_back(u);     }     dfs1(1, 0);     vector<int> ONE(n + 1);     for (int i = 1; i <= n; i++) {       if (son[i] > B) {         two[++len] = son[i];       } else {         fuck[son[i]]++;       }     }     for (int i = 1; i <= B; i++) {       int coef = 1;       for (int j = 1; j <= n; j++) {         coef = 1ull * coef * i % mod;         ONE[j] = sub(ONE[j], 1ull * fuck[i] * coef % mod * inv[j] % mod);       }     }     ONE = Exp(ONE);     vector<int> TWO = solve(1, len);     vector<int> f = ONE * TWO;     int ans = 0;     for (int i = 0; i <= n - 1; i++) ans = (ans + 1ll * fac[n - i] * f[i]) % mod;     print(ans,   n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, arr[200005];     string swaps;     cin >> n;     for (int i = 1; i <= n; i++) cin >> arr[i];     cin >> swaps;     int m = 0, flag = 0;     for (int i = 1; i < n; i++) {       m = max(m, arr[i]);       if (swaps[i - 1] ==  0  && m > i) {         flag = 1;         break;       }     }     (flag) ? cout <<  NO n  : cout <<  YES n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n;     cin >> n;     char s;     int d = 1, j = 1;     for (int i = 1; i <= n; i++) {       cin >> s;       j -= 1;       if (j == 0) {         cout << s;         d += 1;         j = d;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int main() {     cin >> n;     cout << n / 2 + n << endl;     if (n & 1) {       for (int i = 1; i <= n; i++) {         if (!(i & 1)) cout << i <<    ;       }       for (int i = 1; i <= n; i++) {         if (i & 1) cout << i <<    ;       }       for (int i = 1; i <= n; i++) {         if (!(i & 1)) cout << i <<    ;       }     } else {       for (int i = 1; i <= n; i++) {         if (i & 1) cout << i <<    ;       }       for (int i = 1; i <= n; i++) {         if (!(i & 1)) cout << i <<    ;       }       for (int i = 1; i <= n; i++) {         if (i & 1) cout << i <<    ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long dp[31][31][51];   void Cal() {     for (int i = 0; i <= 30; i++)       for (int j = 0; j <= 30; j++)         for (int k = 0; k <= 50; k++) {           dp[i][j][k] = (k == 0 || k == i * j) ? 0 : 10000000000000000;           for (int kk = 0; kk <= k; kk++) {             for (int ii = 1; ii < i; ii++)               dp[i][j][k] =                   min(dp[i][j][k], dp[ii][j][kk] + dp[i - ii][j][k - kk] + j * j);             for (int jj = 1; jj < j; jj++)               dp[i][j][k] =                   min(dp[i][j][k], dp[i][jj][kk] + dp[i][j - jj][k - kk] + i * i);           }         }   }   int main() {     int T;     scanf( %d , &T);     Cal();     while (T--) {       int n, m, k;       scanf( %d%d%d , &n, &m, &k);       cout << dp[n][m][k] << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int m, n;     cin >> m;     int a[m];     for (int i = 0; i < m; i++) {       a[i] = 0;     }     cin >> n;     int p = 0, q = 0, r = 0;     for (int i = 0; i < n; i++) {       cin >> p;       cin >> q;       cin >> r;       a[p - 1] -= r;       a[q - 1] += r;     }     int res = 0;     for (int i = 0; i < m; i++) {       if (a[i] > 0) res += a[i];     }     cout << res;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 10;   vector<pair<long long, long long> > v[3];   vector<pair<long long, int> > segment[3];   struct matrix {     int arr[3][3];     matrix(array<int, 3> a1, array<int, 3> a2) {       for (int i = 0; i <= 2; i++) {         for (int j = 0; j <= 2; j++) {           if (!a1[i] and !a2[j] and abs(i - j) < 2) {             arr[i][j] = 1;           } else             arr[i][j] = 0;         }       }     }     matrix() {       for (int i = 0; i <= 2; i++) {         for (int j = 0; j <= 2; j++) {           if (i == j)             arr[i][j] = 1;           else             arr[i][j] = 0;         }       }     }   };   matrix mul(matrix a, matrix b) {     matrix c;     for (int i = 0; i <= 2; i++) {       for (int j = 0; j <= 2; j++) {         c.arr[i][j] = 0;         for (int k = 0; k <= 2; k++) {           c.arr[i][j] = (0ll + c.arr[i][j] +                          (1ll * a.arr[i][k] * b.arr[k][j]) % 1000000007) %                         1000000007;         }       }     }     return c;   }   matrix matexpo(matrix a, long long int steps) {     if (!steps) {       return matrix();     }     matrix temp = matexpo(a, steps / 2);     temp = mul(temp, temp);     if (steps % 2) {       temp = mul(temp, a);     }     return temp;   }   vector<int> get(vector<int> old_ans, array<int, 3> oldcur, array<int, 3> newcur,                   long long int steps) {     matrix alpha(oldcur, newcur);     matrix temp = matexpo(alpha, steps);     vector<int> loop_ans(3);     for (int i = 0; i <= 2; i++) {       for (int j = 0; j <= 2; j++) {         loop_ans[j] = (0ll + loop_ans[j] +                        (1ll * temp.arr[i][j] * old_ans[i]) % 1000000007) %                       1000000007;       }     }     return loop_ans;   }   void solve() {     long long int n, m;     scanf( %lld , &n);     scanf( %lld , &m);     vector<int> ans = {0, 1, 0};     array<int, 3> cur = {0, 0, 0};     for (int i = 1; i <= n; i++) {       long long int a, l, r;       scanf( %lld , &a);       scanf( %lld , &l);       scanf( %lld , &r);       v[a - 1].push_back({l, r});     }     for (int i = 0; i <= 2; i++) {       sort((v[i]).begin(), (v[i]).end());       stack<pair<long long, long long> > s1;       for (int j = 0; j <= (int)v[i].size() - 1; j++) {         if (s1.empty() or s1.top().second < (v[i][j].first - 1)) {           s1.push(v[i][j]);         } else {           s1.top().second = max(v[i][j].second, s1.top().second);         }       }       v[i].clear();       v[i].reserve(s1.size());       while (!s1.empty()) {         v[i].push_back(s1.top());         s1.pop();       }       reverse((v[i]).begin(), (v[i]).end());     }     for (int i = 0; i <= 2; i++) {       for (int j = 0; j <= (int)v[i].size() - 1; j++) {         segment[i].push_back({v[i][j].first, 1});         segment[i].push_back({v[i][j].second + 1, 0});       }       segment[i].push_back({m + 1, 0});     }     int i = 0, j = 0, k = 0;     long long int pos = 1;     while (true) {       long long int next =           min({segment[0][i].first, segment[1][j].first, segment[2][k].first});       long long int steps = next - pos - 1;       ans = get(ans, cur, cur, steps);       if (next == (m + 1)) {         printf( %d n , ans[1]);         return;       }       pos = next - 1;       array<int, 3> newcur = cur;       if (next == segment[0][i].first) {         newcur[0] = segment[0][i].second;         i++;       }       if (next == segment[1][j].first) {         newcur[1] = segment[1][j].second;         j++;       }       if (next == segment[2][k].first) {         newcur[2] = segment[2][k].second;         k++;       }       ans = get(ans, cur, newcur, 1);       cur = newcur;       pos++;     }   }   int main() {     int t = 1;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long co[100];   int main() {     long long a, l = 0;     long long ans = 1;     cin >> a;     while (a > 1) {       long long c = 0;       for (int s = 2; s <= sqrt(a); s++) {         if (a % s == 0) {           a /= s, co[l] = s, l++, c = 1;           break;         }       }       if (c == 0) break;     }     if (l == 0)       cout << 1 << endl << 0;     else if (l == 1)       cout << 2;     else {       cout << 1 << endl;       for (int s = 0; s < 2; s++) ans *= co[s];       cout << ans;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, d, ans = 0;     scanf( %d%d , &n, &d);     int maxi, t, l;     scanf( %d , &maxi);     for (int i = 1; i < n; i++) {       scanf( %d , &t);       if (t > maxi) {         maxi = t;         continue;       } else {         l = (int)ceil((maxi + 1 - t) / (double)d);         ans += l;         maxi = t + d * l;       }     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5, M = 1e5;   int dfn, cur[M + 1], in[N + 1], pre[N + 1], fin[N + 1], r[N + 1], sz[N + 1];   vector<int> adj[N + 1];   int dfs(int u, int a) {     sz[u] = 1;     r[u] = a;     pre[u] = ++dfn;     for (auto v : adj[u]) sz[u] += dfs(v, a);     fin[u] = ++dfn;     return sz[u];   }   int main() {     int n, m, k, q;     scanf( %d%d%d%d , &n, &m, &k, &q);     for (int i = (0), i_end = (k); i < i_end; ++i) {       int a, b;       scanf( %d%d , &a, &b);       if (cur[b]) {         ++in[a];         adj[cur[b]].push_back(a);       }       cur[b] = a;     }     for (int i = (1), i_end = (n + 1); i < i_end; ++i)       if (!in[i]) dfs(i, i);     for (int i = (0), i_end = (q); i < i_end; ++i) {       int x, y;       scanf( %d%d , &x, &y);       y = cur[y];       if (r[x] == r[y] && pre[y] > pre[x] && fin[y] < fin[x])         printf( %d n , sz[x]);       else         puts( 0 );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1.0);   const int INF = 1000 * 1000 * 1000 + 7;   const long long LINF = INF * (long long)INF;   const int MAX = 2 * 1000 * 100 + 47;   struct Item {     int a, t, ind;     bool operator<(const Item& a) const { return t < a.t; }   };   Item A[MAX];   int n, t;   bool ok(int k) {     long long time = 0;     int cnt = 0;     for (int i = (0); i < (n); i++) {       int a = A[i].a;       int tt = A[i].t;       if (a >= k && time + tt <= t) {         cnt++;         time += tt;       }     }     return cnt >= k;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> n >> t;     for (int i = (0); i < (n); i++) {       cin >> A[i].a >> A[i].t;       A[i].ind = i;     }     sort(A, A + n);     int l = 0, r = n + 1;     while (r - l > 1) {       int c = (r + l) / 2;       if (ok(c)) {         l = c;       } else {         r = c;       }     }     int cnt = l;     cout << cnt <<   n  << cnt <<   n ;     for (int i = (0); i < (n); i++) {       if (cnt == 0) break;       if (A[i].a >= l) {         cnt--;         cout << A[i].ind + 1 <<    ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   double a, b, c, d;   int main() {     scanf( %d%d%d%d , &a, &b, &c, &d);     printf( %.12lf n , a / b / (1 - (1 - a / b) * (1 - c / d)));   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 7;   int n, p[N];   deque<pair<int, int> > deq;   bool mrk[N];   vector<int> dor[2];   int dfs(int v, int d) {     mrk[v] = 1;     if (!mrk[p[v]]) return dfs(p[v], d + 1);     return d;   }   void add(int v, int l) {     dor[l].clear();     int pnt = v;     do {       dor[l].push_back(pnt);       pnt = p[pnt];     } while (pnt != v);   }   void remake(int l) {     int go = dor[l].size() / 2 + 1;     for (int i = 0; i < dor[l].size(); i++) {       p[dor[l][i]] = dor[l][(i + go) % dor[l].size()];     }   }   void merge() {     for (int i = 0; i < dor[0].size(); i++) {       p[dor[0][i]] = dor[1][i];       p[dor[1][i]] = dor[0][(1 + i) % dor[0].size()];     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n;     for (int i = 1; i <= n; i++) cin >> p[i];     for (int i = 1; i <= n; i++) {       if (!mrk[i]) {         deq.push_back({dfs(i, 1), i});       }     }     sort(deq.begin(), deq.end());     while (deq.size()) {       if (deq[0].first % 2) {         add(deq[0].second, 0);         remake(0);         deq.pop_front();         continue;       }       if (deq.size() == 1 || deq[1].first != deq[0].first) {         cout << -1;         return 0;       }       add(deq[0].second, 0);       add(deq[1].second, 1);       merge();       deq.pop_front();       deq.pop_front();     }     for (int i = 1; i <= n; i++) cout << p[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 200001;   int MAX[N];   vector<int> A[N];   int main() {     ios::sync_with_stdio(false);     set<pair<int, int> > S;     int n;     cin >> n;     for (int i = 0; i < n; i++) {       int u, v;       cin >> u >> v;       MAX[u] = v;       A[u].push_back(v);     }     for (int i = 1; i <= n; i++) {       if (MAX[i] > 0) S.insert({MAX[i], i});     }     int q;     cin >> q;     for (int i = 0; i < q; i++) {       int c;       cin >> c;       vector<int> temp;       for (int j = 0; j < c; j++) {         int u;         cin >> u;         temp.push_back(u);         S.erase({MAX[u], u});       }       if (S.size() > 1) {         pair<int, int> p = *S.rbegin(), p2;         S.erase(p);         temp.push_back(p.second);         p2 = *S.rbegin();         int l_lim = 0, u_lim = A[p.second].size();         while (l_lim < u_lim - 1) {           int cur = (l_lim + u_lim) / 2;           if (A[p.second][cur] > p2.first) {             u_lim = cur;           } else {             l_lim = cur;           }         }         if (A[p.second][l_lim] > p2.first) {           cout << p.second <<     << A[p.second][l_lim] <<   n ;         } else {           cout << p.second <<     << A[p.second][l_lim + 1] <<   n ;         }       } else if (S.size() == 1) {         pair<int, int> p = *S.rbegin();         cout << p.second <<     << A[p.second][0] <<   n ;       } else {         cout <<  0 0 n ;       }       while (!temp.empty()) {         if (MAX[temp.back()] > 0) S.insert({MAX[temp.back()], temp.back()});         temp.pop_back();       }     }     return 0;   }


#include <bits/stdc++.h>   using i64 = long long;   using u64 = unsigned long long;   using u32 = unsigned;   int main() {     std::ios::sync_with_stdio(false);     std::cin.tie(nullptr);     int n;     std::cin >> n;     std::vector<int> c0(n, 0);     std::vector<int> c1(n, 0);     for (int i = 0; i < n; i++) {       std::cin >> c0[i] >> c1[i];     }     std::vector<int> tmp{0};     for (int i = 0; i < n; i++) {       tmp.emplace_back(c0[i]);       tmp.emplace_back(c1[i]);     }     std::sort(tmp.begin(), tmp.end());     tmp.resize(std::unique(tmp.begin(), tmp.end()) - tmp.begin());     for (int i = 0; i < n; i++) {       c0[i] = std::lower_bound(tmp.begin(), tmp.end(), c0[i]) - tmp.begin();       c1[i] = std::lower_bound(tmp.begin(), tmp.end(), c1[i]) - tmp.begin();     }     std::vector<int> p(tmp.size(), 0);     std::iota(p.begin(), p.end(), 0);     auto find = [&](int x) {       while (x != p[x]) {         x = p[x] = p[p[x]];       }       return x;     };     int ans = 0;     for (int i = 0; i < n; i++) {       int x = c0[i];       int y = c1[i];       x = find(x);       y = find(y);       if (!x && !y) {         std::cout << -1, exit(0);       } else {         if (x == y || !x || !y) {           ans = std::max({ans, x, y});           p[x] = p[y] = 0;         } else {           ans = std::max(ans, std::min(x, y));           p[std::min(x, y)] = std::max(x, y);         }       }     }     std::cout << tmp[ans] <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct compare {     bool operator()(const std::string& first, const std::string& second) {       return first.size() > second.size();     }   };   int main() {     ios_base::sync_with_stdio(false);     int n, k, i;     cin >> n >> k;     string arr[110];     for (i = 0; i < n; i++) {       cin >> arr[i];     }     string password;     cin >> password;     long long int tries = 0, equallen = 0;     int plen = password.length();     for (i = 0; i < n; i++) {       if (arr[i].length() < plen) {         tries++;       } else if (arr[i].length() == plen) {         equallen++;       }     }     long long int ans = 0;     ans = ((tries) / k) * 5 + tries + 1;     cout << ans <<    ;     ans = ((tries + equallen - 1) / k) * 5 + (tries + equallen);     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s[10] = { O-|-OOOO ,  O-|O-OOO ,  O-|OO-OO ,  O-|OOO-O ,  O-|OOOO- ,                      -O|-OOOO ,  -O|O-OOO ,  -O|OO-OO ,  -O|OOO-O ,  -O|OOOO- };     string num;     while (cin >> num) {       int i = num.size();       while (i--) cout << s[num[i] -  0 ] << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, k;   int main() {     cin >> n >> k;     cout << (n + k - n % k);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e9 + 7;   const int N = 2e5 + 10;   int a[N];   int main() {     string str;     string s;     while (cin >> s) str += s;     for (auto& c : str) {       if (c ==  < ) c =    ;       if (c ==  > ) c =    ;     }     vector<string> vs;     vector<int> ans;     stringstream sin(str);     while (sin >> str) {       if (str[0] ==  / ) {         if (str ==  /table ) {           ans.push_back(a[vs.size() - 1]);         } else {           a[vs.size() - 2] += a[vs.size() - 1];         }         vs.pop_back();         a[vs.size()] = 0;       } else {         if (str ==  td )           a[vs.size()] = 1;         else           a[vs.size()] = 0;         vs.push_back(str);       }     }     sort(ans.begin(), ans.end());     for (auto& x : ans) printf( %d  , x);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int N;   char field[110][110];   bool check_solution(bool do_print, bool swapped) {     for (int r = 0; r < N; ++r) {       int c;       for (c = 0; c < N; ++c) {         if (field[r][c] ==  . ) break;       }       if (c == N) return false;       if (do_print) {         if (swapped)           printf( %d %d n , c + 1, r + 1);         else           printf( %d %d n , r + 1, c + 1);       }     }     return true;   }   int main(void) {     scanf( %d , &N);     for (int r = 0; r < N; ++r) scanf( %s , field[r]);     if (check_solution(false, false)) {       check_solution(true, false);     } else {       for (int r = 0; r < N; ++r) {         for (int c = r + 1; c < N; ++c) {           swap(field[r][c], field[c][r]);         }       }       if (check_solution(false, true))         check_solution(true, true);       else         puts( -1 );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct nade {     int pos, tag, sum, l, r;   } tree[600005 * 2];   int n;   void puup(int x) {     if (tree[x * 2].sum > tree[x * 2 + 1].sum) {       tree[x].pos = tree[x * 2].pos;       tree[x].sum = tree[x * 2].sum;     } else {       tree[x].pos = tree[x * 2 + 1].pos;       tree[x].sum = tree[x * 2 + 1].sum;     }   }   void pudo(int x) {     tree[x * 2].tag += tree[x].tag;     tree[x * 2].sum += tree[x].tag;     tree[x * 2 + 1].tag += tree[x].tag;     tree[x * 2 + 1].sum += tree[x].tag;     tree[x].tag = 0;   }   void build(int x, int l, int r) {     tree[x].l = l;     tree[x].r = r;     if (l == r) {       tree[x].pos = l;       return;     }     int mid = (l + r) / 2;     build(x * 2, l, mid);     build(x * 2 + 1, mid + 1, r);     tree[x].pos = tree[x * 2].pos;   }   void add(int l, int r, int val, int x) {     if (tree[x].l >= l && tree[x].r <= r) {       tree[x].sum += val;       tree[x].tag += val;       return;     }     pudo(x);     if (tree[x * 2].r >= l) add(l, r, val, x * 2);     if (tree[x * 2 + 1].l <= r) add(l, r, val, x * 2 + 1);     puup(x);   }   int l[200005], r[200005], v[200005];   struct node {     int x, u, d;     bool b;   } s[200005];   bool cmp(node a, node b) {     if (a.x != b.x) return a.x < b.x;     return a.b < b.b;   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d%d%d , &l[i], &v[i], &r[i]);       s[i * 2].x = l[i];       s[i * 2].u = r[i];       s[i * 2].d = v[i];       s[i * 2].b = 0;       s[i * 2 + 1].x = v[i];       s[i * 2 + 1].u = r[i];       s[i * 2 + 1].d = v[i];       s[i * 2 + 1].b = 1;     }     build(1, 1, 3e5 + 1);     sort(s, s + 2 * n, cmp);     int ans = 0, ansp = 0, ansx = 0;     for (int i = 0; i < n * 2; i++) {       add(s[i].d, s[i].u, s[i].b ? -1 : 1, 1);       if (tree[1].sum > ans) {         ans = tree[1].sum;         ansp = tree[1].pos;         ansx = s[i].x;       }     }     printf( %d n , ans);     for (int i = 0; i < n; i++)       if (l[i] <= ansx && ansx <= v[i] && v[i] <= ansp && ansp <= r[i])         printf( %d  , i + 1);   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 100500;   const int infi = (1 << 30);   const long long infl = (1LL << 62);   const double eps = 1e-9;   const long long mod = 1000000007LL;   const double pi = acos(-1.0);   int n, k;   int a[maxn], c[maxn];   int main() {     cin >> n >> k;     for (int i = 1; i < n; i++) a[i] = 1;     a[0] = 0;     for (int i = 0; i < k; i++) {       for (int j = 0; j < n; j++) {         int second = int(upper_bound(a, a + n, j - a[j] - 1) - a);         if (second == n) second = n - 1;         c[j] = second;       }       for (int j = 0; j < n; j++) {         a[j] += a[c[j]];       }       for (int j = n - 1; j >= 0; --j) cout << n - c[j] <<    ;       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> divs[1000009];   bool p[1000009];   vector<int> primes;   void pre() {     for (int i = 2; i <= (1000000); ++i) {       if (!p[i]) {         primes.push_back(i);         for (int j = i; j <= 1000000; j += i) divs[j].push_back(i), p[j] = true;       }     }   }   int L(int x, int p) {     int s = (int)(divs[p]).size();     int tot = (1 << s) - 1;     long long ans = 0;     for (int i = 1; i <= (tot); ++i) {       int cnt = 0;       int var = 1;       for (int j = 0; j < (s); ++j)         if (i & (1 << j)) cnt++, var *= divs[p][j];       if (cnt % 2)         ans += x / var;       else         ans -= x / var;     }     return x - ans;   }   int main() {     cin.sync_with_stdio(0);     cin.tie(0);     cin.exceptions(cin.failbit);     pre();     int q;     cin >> q;     for (int aa = 0; aa < (q); ++aa) {       int x, p, k;       cin >> x >> p >> k;       if (p == 1)         cout << k + x <<   n ;       else {         k += L(x, p);         int l = 1, r = 1e8;         while (l < r) {           int m = (l + r) >> 1;           if (L(m, p) >= k)             r = m;           else             l = m + 1;         }         cout << l <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   class Solution {    public:     long long count(long long _m, long long _x) {       if (_m < 3) {         return max(0LL, _m);       }       m = _m;       x = _x;       vector<pair<long long, int>> cnts = factorize(m);       long long res = 0;       search(0, 1, cnts, res);       return res;     }       private:     map<long long, vector<pair<long long, int>>> fs;     long long m, x;     long long gcd(long long x, long long y) {       while (x != 0) {         y %= x;         swap(x, y);       }       return y;     }     vector<pair<long long, int>>& factorize(long long n) {       if (fs.count(n) > 0) {         return fs[n];       }       vector<pair<long long, int>>& res = fs[n];       for (long long i = 2; i * i <= n; ++i) {         int cnt = 0;         while (n % i == 0) {           ++cnt;           n /= i;         }         if (cnt > 0) {           res.emplace_back(i, cnt);         }       }       if (n > 1) {         res.emplace_back(n, 1);       }       return res;     }     void search(int i, long long dv, vector<pair<long long, int>>& cnts,                 long long& ans) {       if (i >= cnts.size()) {         vector<pair<long long, int>> dvcnts;         dvcnts.reserve(cnts.size());         for (auto& pc : cnts) {           if (pc.second <= 1) {             continue;           }           dvcnts.emplace_back(pc.first, pc.second - 1);         }         long long phi = dv;         for (auto& pc : cnts) {           long long p = pc.first;           int c = pc.second;           if (c == 0) {             continue;           }           dvcnts = merge(dvcnts, factorize(p - 1));           phi = phi - phi / p;         }         ans += phi / calcPeriod(x % dv, dv, dvcnts);         return;       }       long long p = fs[m][i].first;       long long n = fs[m][i].second;       for (int j = 0; j <= n; ++j) {         cnts[i].second = j;         search(i + 1, dv, cnts, ans);         dv *= p;       }     }     vector<pair<long long, int>> merge(vector<pair<long long, int>>& list1,                                        vector<pair<long long, int>>& list2) {       vector<pair<long long, int>> res;       res.reserve(list1.size() + list2.size());       int n = list1.size(), m = list2.size();       int i = 0, j = 0;       while (i < n && j < m) {         if (list1[i].first < list2[j].first) {           res.emplace_back(list1[i].first, list1[i].second);           ++i;         } else if (list1[i].first > list2[j].first) {           res.emplace_back(list2[j].first, list2[j].second);           ++j;         } else {           res.emplace_back(list1[i].first, list1[i].second + list2[j].second);           ++i;           ++j;         }       }       while (i < n) {         res.emplace_back(list1[i].first, list1[i].second);         ++i;       }       while (j < m) {         res.emplace_back(list2[j].first, list2[j].second);         ++j;       }       return res;     }     long long calcPeriod(long long x, long long mod,                          vector<pair<long long, int>>& factors) {       long long phi = 1;       for (auto& pc : factors) {         long long p = pc.first;         int c = pc.second;         for (int i = 0; i < c; ++i) {           phi *= p;         }       }       long long res = 1;       for (auto& pc : factors) {         long long p = pc.first;         int c = pc.second;         long long base = phi;         for (int i = 0; i < c; ++i) {           base /= p;         }         long long val = powM(x, base, mod);         int j = c;         for (int i = 1; i <= c; ++i) {           if (val == 1) {             j = i - 1;             break;           }           val = powM(val, p, mod);         }         res *= powI(p, j);       }       return res;     }     long long mulM(long long a, long long b, long long m) {       long long res = 0;       while (b > 0) {         if (b & 0x1) {           res = (res + a) % m;         }         a = (a + a) % m;         b >>= 1;       }       return res;     }     long long powM(long long x, long long e, long long m) {       long long res = 1;       while (e > 0) {         if (e & 0x1) {           res = mulM(res, x, m);         }         x = mulM(x, x, m);         e >>= 1;       }       return res;     }     long long powI(long long x, long long e) {       long long res = 1;       for (int i = 0; i < e; ++i) {         res *= x;       }       return res;     }   };   int main(int argc, char** argv) {     ios::sync_with_stdio(false);     cin.tie(0);     long long m, x;     cin >> m >> x;     Solution sol;     cout << sol.count(m, x) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   ll dx[] = {0, 0, 1, -1};   ll dy[] = {1, -1, 0, 0};   void solve() {     ll n;     cin >> n;     vector<ll> v(n);     for (ll i = 0; i < (n); ++i) cin >> v[i];     vector<pair<ll, ll>> aux(n);     ll i = n - 1;     stack<ll> s;     while (i >= 0) {       while (!s.empty() && s.top() < v[i]) s.pop();       if (s.empty())         aux[i].first = -1;       else         aux[i].first = s.top();       s.push(v[i]);       i--;     }     i = 0;     while (!s.empty()) s.pop();     while (i < n) {       while (!s.empty() && s.top() < v[i]) s.pop();       if (s.empty())         aux[i].second = -1;       else         aux[i].second = s.top();       s.push(v[i]), i++;     }     ll res = 0;     for (ll i = 0; i < (n); ++i) {       if (aux[i].first != -1) res = max(res, aux[i].first ^ v[i]);       if (aux[i].second != -1) res = max(res, aux[i].second ^ v[i]);     }     cout << res <<   n ;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     ll t = 1;     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1010;   void solve() {     int n, m;     cin >> n >> m;     vector<vector<long long>> a =         vector<vector<long long>>(n, vector<long long>(m, 0));     for (int i = 0; i < n; ++i)       for (int j = 0; j < m; ++j) cin >> a[i][j];     vector<long long> col(m, 0), row(n, 0);     for (int i = 0; i < m; ++i)       for (int j = 0; j < n; ++j) col[i] += a[j][i];     for (int i = 0; i < n; ++i)       for (int j = 0; j < m; ++j) row[i] += a[i][j];     vector<long long> x(m + 1), y(n + 1);     long long mn = LLONG_MAX;     long long ans = 0;     int ansx = 0;     for (int i = 0; i <= m; ++i) {       long long curx = i * 4;       for (int j = 0; j < m; ++j) {         long long curpos = j * 4 + 2;         long long dx = curx - curpos;         x[i] += dx * dx * col[j];       }       if (x[i] < mn) {         mn = x[i];         ansx = i;       }     }     ans += mn;     mn = LLONG_MAX;     int ansy = 0;     for (int i = 0; i <= n; ++i) {       int cury = i * 4;       for (int j = 0; j < n; ++j) {         long long curpos = j * 4 + 2;         long long dy = cury - curpos;         y[i] += dy * dy * row[j];       }       if (y[i] < mn) {         mn = y[i];         ansy = i;       }     }     ans += mn;     cout << ans <<   n ;     cout << ansy <<     << ansx <<   n ;   }   int main(void) {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int tc = 1;     while (tc--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   const long long inf = 1LL << 60;   const long long md = 1e9 + 7;   const long double eps = 1e-14;   const int mx = 3010;   int t[mx];   void upd(int p) {     for (++p; p < mx; p += p & -p) ++t[p];   }   int que(int p) {     int res = 0;     for (; p > 0; p -= p & -p) res += t[p];     return res;   }   char zey[mx][mx];   int le[mx][mx], ri[mx][mx];   int solve(vector<int> &a, vector<int> &b) {     int sz = a.size();     if (sz == 0) return 0;     int res = 0;     fill(t, t + sz + 5, 0);     vector<pair<int, int> > bb(sz);     for (int i = (0); i < int(sz); ++i) bb[i] = pair<int, int>(i - b[i] + 1, i);     sort(bb.begin(), bb.end());     int ix = 0;     for (int i = (0); i < int(sz); ++i) {       while (ix < sz && bb[ix].first <= i) upd(bb[ix++].second);       res += que(min(sz, i + a[i])) - i;     }     return res;   }   int main() {     memset(t, 0, sizeof(t));     int n, m;     cin >> n >> m;     for (int i = (0); i < int(n); ++i) scanf(  %s  , zey[i]);     for (int i = (0); i < int(n); ++i) {       le[i][0] = zey[i][0] ==  z ;       ri[i][m - 1] = zey[i][m - 1] ==  z ;     }     for (int i = (0); i < int(n); ++i)       for (int j = (1); j < int(m); ++j)         le[i][j] = zey[i][j] ==  z  ? 1 + le[i][j - 1] : 0;     for (int i = (0); i < int(n); ++i)       for (int j = (m - 1); j-- > int(0);)         ri[i][j] = zey[i][j] ==  z  ? 1 + ri[i][j + 1] : 0;     long long ans = 0;     for (int s = (0); s < int(m + n - 1); ++s) {       vector<int> a, b;       for (int d = (max(0, s - m + 1)); d < int(min(n, s + 1)); ++d) {         if (zey[d][s - d] ==  z ) {           a.push_back(le[d][s - d]);           b.push_back(ri[d][s - d]);         } else {           ans += solve(a, b);           a.clear();           b.clear();         }       }       ans += solve(a, b);     }     cout << ans << endl;   }


#include <bits/stdc++.h>   unsigned long long val(int i) { return i + 1; }   unsigned long long pot1[100001], pot2[100001], prec1[10][100001],       prec2[10][100001];   int v[100000];   struct Node {     unsigned long long h1, h2;     int flag;     bool valid;     int sz;     Node() {       sz = h1 = h2 = 0;       flag = -1;       valid = true;     }     Node(unsigned long long a, unsigned long long b, int c) {       h1 = a;       h2 = b;       sz = c;       flag = -1;       valid = true;     }     Node(unsigned long long a, unsigned long long b, int c, bool d) {       h1 = a;       h2 = b;       sz = c;       valid = d;       flag = -1;     }     void set(int c) { flag = c; }     void reset() { flag = -1; }     void update(int c) {       if (c == -1) return;       h1 = prec1[c][sz];       h2 = prec2[c][sz];     }     bool operator!=(const Node& n) { return h1 != n.h1 || h2 != n.h2; }   };   Node st[400000];   inline int left(int i) { return 2 * i + 1; }   inline int right(int i) { return 2 * i + 2; }   void initialize(int r, int beg, int end) {     if (beg == end) {       st[r] = Node(val(v[beg]), val(v[beg]), 1);     } else {       int h = (beg + end) / 2;       initialize(left(r), beg, h);       initialize(right(r), h + 1, end);       st[r] = Node(           (st[left(r)].h1 * pot1[st[right(r)].sz] + st[right(r)].h1) % 1000000009,           (st[left(r)].h2 * pot2[st[right(r)].sz] + st[right(r)].h2) % 1000000007,           st[left(r)].sz + st[right(r)].sz);     }   }   void update(int r, int beg, int end, int qbeg, int qend, char c) {     if (end < qbeg || beg > qend) {       if (st[r].flag != -1) {         st[r].update(st[r].flag);         if (beg != end) {           st[2 * r + 1].set(st[r].flag);           st[2 * r + 2].set(st[r].flag);         }         st[r].reset();       }       return;     }     if (beg >= qbeg && end <= qend) {       st[r].update(c);       if (beg != end) {         st[left(r)].set(c);         st[right(r)].set(c);       }       st[r].reset();     } else {       int h = (beg + end) / 2;       if (st[r].flag != -1) {         st[r].update(st[r].flag);         st[2 * r + 1].set(st[r].flag);         st[2 * r + 2].set(st[r].flag);         st[r].reset();       }       update(left(r), beg, h, qbeg, qend, c);       update(right(r), h + 1, end, qbeg, qend, c);       st[r] = Node(           (st[left(r)].h1 * pot1[st[right(r)].sz] + st[right(r)].h1) % 1000000009,           (st[left(r)].h2 * pot2[st[right(r)].sz] + st[right(r)].h2) % 1000000007,           st[right(r)].sz + st[left(r)].sz);     }   }   Node query(int r, int beg, int end, int qbeg, int qend) {     if (end < qbeg || beg > qend) return Node(0, 0, false);     if (beg >= qbeg && end <= qend) {       if (st[r].flag != -1) {         st[r].update(st[r].flag);         if (beg != end) {           st[left(r)].set(st[r].flag);           st[right(r)].set(st[r].flag);         }         st[r].reset();       }       return st[r];     } else {       if (st[r].flag != -1) {         st[r].update(st[r].flag);         st[left(r)].set(st[r].flag);         st[right(r)].set(st[r].flag);         st[r].reset();       }       Node le = query(left(r), beg, (beg + end) / 2, qbeg, qend);       Node ri = query(right(r), (beg + end) / 2 + 1, end, qbeg, qend);       if (le.valid && ri.valid)         return Node((le.h1 * pot1[ri.sz] + ri.h1) % 1000000009,                     (le.h2 * pot2[ri.sz] + ri.h2) % 1000000007, le.sz + ri.sz);       else if (le.valid)         return le;       else         return ri;     }   }   bool qquery(int r, int beg, int end, int qbeg, int qend, int d) {     int sz = qend - qbeg + 1;     if (sz <= d) return true;     if (qbeg > qend) return 0;     int sobra = sz % d;     if (sobra) {       if (query(r, beg, end, qbeg, qbeg + sobra - 1) !=           query(r, beg, end, qend - sobra + 1, qend))         return false;     }     qend -= sobra;     sz = qend - qbeg + 1;     int n = sz / d;     if (sz == d) return true;     if (n & 1) {       int b0 = qbeg, b1 = qbeg + n / 2 * d, b2 = qbeg + (n / 2 + 1) * d;       int e0 = b1 - 1, e1 = b2 - 1, e2 = qend;       if (query(r, beg, end, b0, e0) != query(r, beg, end, b2, e2) ||           query(r, beg, end, b0, b0 + d - 1) != query(r, beg, end, b1, e1))         return false;       return qquery(r, beg, end, b0, e0, d);     } else {       int b0 = qbeg, b1 = qbeg + (n + 1) / 2 * d;       int e0 = b1 - 1, e1 = qend;       if (query(r, beg, end, b0, e0) != query(r, beg, end, b1, e1)) return false;       return qquery(r, beg, end, b0, e0, d);     }   }   void precalc() {     pot1[0] = 1;     pot2[0] = 1;     for (int i = 1; i <= 100000; i++) {       pot1[i] = (pot1[i - 1] * 33) % 1000000009;       pot2[i] = (pot2[i - 1] * 33) % 1000000007;     }     for (int i = 0; i < 10; i++) {       prec1[i][0] = 0;       prec2[i][0] = 0;       for (int j = 1; j <= 100000; j++) {         prec1[i][j] = (prec1[i][j - 1] * 33 + val(i)) % 1000000009;         prec2[i][j] = (prec2[i][j - 1] * 33 + val(i)) % 1000000007;       }     }   }   int main(void) {     int n, m, k;     char s[100001];     precalc();     scanf( %d%d%d , &n, &m, &k);     scanf( %s , s);     for (int i = 0; i < n; i++) {       v[i] = s[i] -  0 ;     }     initialize(0, 0, n - 1);     for (int i = 0; i < m + k; i++) {       int cmd;       int l, r, x;       scanf( %d%d%d%d , &cmd, &l, &r, &x);       if (cmd == 1) {         l--;         r--;         update(0, 0, n - 1, l, r, x);       } else {         l--;         r--;         printf( %s n , qquery(0, 0, n - 1, l, r, x) ?  YES  :  NO );       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100005, M = 500005;   vector<int> gr[N], path, odd;   pair<int, int> ed[M];   bool us[M];   void GetEulerCircuit(int u) {     while (true) {       while (!gr[u].empty() && us[gr[u].back()]) {         gr[u].pop_back();       }       if (gr[u].empty()) {         break;       }       us[gr[u].back()] = true;       int v = u ^ ed[gr[u].back()].first ^ ed[gr[u].back()].second;       gr[u].pop_back();       GetEulerCircuit(v);     }     path.push_back(u);   }   int main() {     ios_base::sync_with_stdio(false);     cout.tie(0);     int n, m;     scanf( %d %d  , &n, &m);     for (int i = 0; i < m; i++) {       int u, v;       scanf( %d %d  , &u, &v);       ed[i] = make_pair(u, v);       gr[u].push_back(i);       gr[v].push_back(i);     }     for (int u = 1; u <= n; u++) {       if (gr[u].size() % 2) {         odd.push_back(u);       }     }     for (int i = 0; i < odd.size(); i += 2) {       int u = odd[i], v = odd[i + 1];       ed[m] = make_pair(u, v);       gr[u].push_back(m);       gr[v].push_back(m);       m++;     }     if (m % 2) {       ed[m] = make_pair(1, 1);       gr[1].push_back(m);       gr[1].push_back(m);       m++;     }     GetEulerCircuit(1);     for (int i = 0; i < m; i++) {       int u = path[i], v = path[i + 1];       if (i % 2) {         swap(u, v);       }       ed[i] = make_pair(u, v);     }     printf( %d n , m);     for (int i = 0; i < m; i++) {       int u = ed[i].first, v = ed[i].second;       printf( %d %d n , u, v);     }   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline void read(T &x) {     x = 0;     T f = 1;     char c = getchar();     for (; !isdigit(c); c = getchar())       if (c ==  - ) f = -1;     for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + (c ^ 48);     x *= f;   }   int main() {     int n;     read(n);     for (int i = 1; i <= n; i++) {       int x;       read(x);       cout << x / 6 + (x % 6 == 0 ? 0 : 1) << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6;   int q[maxn], fin, razbeg, jump, n;   pair<int, int> ans[maxn];   int sz = 0;   int main() {     cin >> n >> fin >> razbeg >> jump;     for (int i = 0; i < n; i++) cin >> q[i];     q[n] = 0;     q[n + 1] = fin;     n += 2;     sort(q, q + n);     int i = 0, now = 0;     while (i < n - 1)       if (i == n - 2) {         if (fin - now > 0) ans[sz] = make_pair(0, fin - now), sz++;         break;       } else if (q[i + 1] - 1 - now < razbeg) {         cout <<  IMPOSSIBLE ;         return 0;       } else {         if (q[i + 1] - 1 - now > 0)           ans[sz] = make_pair(0, q[i + 1] - 1 - now), sz++;         now = q[i + 1] - 1;         while (1) {           i++;           if (q[i] + 1 - now > jump) {             cout <<  IMPOSSIBLE ;             return 0;           }           if (i == n - 2) {             ans[sz] = make_pair(1, q[i] + 1 - now), sz++, now = q[i] + 1;             break;           } else if (q[i + 1] - 1 - q[i] - 1 >= razbeg) {             ans[sz] = make_pair(1, q[i] + 1 - now), sz++, now = q[i] + 1;             break;           }         }       }     for (int i = 0; i < sz; i++)       if (ans[i].first == 0)         cout <<  RUN   << ans[i].second <<   n ;       else         cout <<  JUMP   << ans[i].second <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   long long n, q, c[100005], v[100005], f[100005];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> q;     for (int i = 1; i <= n; i++) cin >> v[i];     for (int i = 1; i <= n; i++) cin >> c[i];     while (q--) {       long long a, b, ans = 0, mx = 0, smx = 0;       memset(f, -6, sizeof(f));       cin >> a >> b;       for (int i = 1; i <= n; i++) {         long long cur = max(v[i] * b, f[c[i]] + v[i] * a);         if (c[i] != mx)           cur = max(cur, f[mx] + v[i] * b);         else           cur = max(cur, f[smx] + v[i] * b);         if (cur > f[mx]) {           if (mx != c[i]) smx = mx;           mx = c[i];         } else if (cur > f[smx] && c[i] != mx)           smx = c[i];         f[c[i]] = max(f[c[i]], cur);         ans = max(ans, cur);       }       cout << ans <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int MAXK = 26;   const long long MOD = 1e9 + 7;   int last[MAXK], ord[MAXK];   long long sum, dp[MAXK];   void add(int c) {     sum = (sum - dp[c] + MOD) % MOD;     dp[c] = (dp[c] + sum + 1) % MOD;     sum = (sum + dp[c]) % MOD;   }   int main() {     ios_base::sync_with_stdio(false);     int N, K;     string S;     cin >> N >> K >> S;     memset((last), (-1), sizeof(last));     sum = 0;     for (int _n((int)S.size()), i(0); i < _n; i++) {       int c = S[i] -  a ;       last[c] = i;       add(c);     }     iota(ord, ord + K, 0);     sort(ord, ord + K, [](int a, int b) { return last[a] < last[b]; });     for (int _n(N), i(0); i < _n; i++) {       int c = ord[i % K];       add(c);     }     cout << (sum + 1) % MOD << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   #pragma GCC optimize( Ofast )   const int INF = 1e9 + 7;   const long long INF2 = 1e15;   void solve(void) {}   int main(void) {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long n, l, r, ql, qr;     cin >> n >> l >> r >> ql >> qr;     vector<long long> v(n);     for (int i = 0; i < n; i++) cin >> v[i];     long long total = 0;     vector<long long> left(n + 1), right(n + 1);     for (long long i = 0; i < n; i++) {       total += v[i] * l;       left[i + 1] = total;     }     total = 0;     for (long long i = n - 1; i >= 0; i--) {       total += v[i] * r;       right[i] = total;     }     long long ans = INF, current;     for (long long i = 0; i <= n; i++) {       long long a = i, b = n - i, change;       current = INF;       change = min(a, b);       a -= change;       b -= change;       if (a) {         a--;         current = min(current, a * ql);       } else if (b) {         current = min(current, b * qr);       } else {         current = 0;       }       a = i, b = n - i;       change = min(a, b);       a -= change;       b -= change;       if (b) {         b--;         current = min(current, b * qr);       } else if (a) {         current = min(current, a * ql);       } else {         current = 0;       }       long long temp = 0;       a = i, b = n - i;       if (b) {         b--;         temp += qr * b;       }       if (a) {         a--;         temp += ql * a;       }       current = min(current, temp);       ans = min(ans, current + left[i] + right[i]);     }     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   using namespace std;   int main() {     int n, k, q;     cin >> n >> k >> q;     vector<long long> vec(n + 1);     vector<long long> pq;     map<long long, long long> ar, ans, rev;     for (int i = 1; i <= n; i++) cin >> vec[i], ar[i] = vec[i], rev[vec[i]] = i;     while (q--) {       int a, b;       cin >> a >> b;       if (a == 1) {         pq.push_back(ar[b]);         ans[b] = 1;         if (pq.size() > k) {           sort(pq.begin(), pq.end());           long long dd = rev[pq[0]];           ans[dd] = 0;           pq.erase(pq.begin());         }       } else {         if (ans[b]) {           cout <<  YES n ;         } else           cout <<  NO n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int lowbit(int x) { return x & -x; }   inline int ABS(int x) { return x < 0 ? -x : x; }   inline long long ABS(long long x) { return x < 0 ? -x : x; }   inline void MAX(int &a, int b) {     if (b > a) a = b;   }   inline void MAX(long long &a, long long b) {     if (b > a) a = b;   }   inline void MIN(int &a, int b) {     if (b < a) a = b;   }   inline void MIN(long long &a, long long b) {     if (b < a) a = b;   }   inline void SUM(int &a, int b) { a = (a + b) % 1000000007; }   int fast(int x, int v) {     int ans = 1;     for (; v; v >>= 1, x = (long long)x * x % 1000000007)       if (v & 1) ans = (long long)ans * x % 1000000007;     return ans;   }   long long fast(long long x, long long v) {     long long ans = 1;     for (; v; v >>= 1, x = x * x % 1000000007)       if (v & 1) ans = ans * x % 1000000007;     return ans;   }   inline long long sqr(int x) { return x * x; }   int n, a[300005], l, r, sum;   long long pre[300005], ans;   map<int, int> s;   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) {       scanf( %d , a + i);       pre[i] = pre[i - 1] + (a[i] < 0 ? 0 : a[i]);       if (!s[a[i]]) s[a[i]] = i;     }     ans = -0x7f7f7f7f;     for (int i = n; i >= 1; --i)       if (s[a[i]] && s[a[i]] != i && pre[i - 1] - pre[s[a[i]]] + a[i] * 2 > ans) {         ans = pre[i - 1] - pre[s[a[i]]] + a[i] * 2;         l = s[a[i]];         r = i;       }     for (int i = l + 1; i <= r - 1; ++i)       if (a[i] < 0) ++sum;     printf( %I64d %d n , ans, sum + l - 1 + n - r);     for (int i = 1; i <= l - 1; ++i) printf( %d  , i);     for (int i = l + 1; i <= r - 1; ++i)       if (a[i] < 0) printf( %d  , i);     for (int i = r + 1; i <= n; ++i) printf( %d  , i);   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 9223372036854775807;   const long long MOD = 1000000007;   const long double PI = acos(-1);   inline long long power(long long a, long long b, long long z = MOD) {     long long res = 1;     a = (a % z);     while (b) {       if (b & 1) res = (res * a) % z;       a = (a * a) % z;       b = b >> 1;     }     return res;   }   inline long long inverse(long long a, long long z = MOD) {     return power(a, z - 2, z);   }   long long extend(long long a, long long b, long long &x, long long &y) {     if (b == 0) {       x = 1;       y = 0;       return a;     }     long long x1, y1;     long long g = extend(b, a % b, x1, y1);     x = y1;     y = x1 - (a / b) * y1;     return g;   }   inline long long mat_power(long long a, long long b, long long c, long long d,                              long long n, long long z = MOD) {     long long a0 = 1, b0 = 0, c0 = 0, d0 = 1;     while (n) {       if (n & 1) {         long long a1 = a0, b1 = b0, c1 = c0, d1 = d0;         a0 = (a1 * a + b1 * c) % z;         b0 = (a1 * b + b1 * d) % z;         c0 = (c1 * a + d1 * c) % z;         d0 = (c1 * b + d1 * d) % z;       }       long long a1 = a, b1 = b, c1 = c, d1 = d;       a = (a1 * a1 + b1 * c1) % z;       b = (a1 * b1 + b1 * d1) % z;       c = (c1 * a1 + d1 * c1) % z;       d = (c1 * b1 + d1 * d1) % z;       n = n >> 1;     }     return c0;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n, m;     cin >> n >> m;     int aray[n][m], arr[n][m];     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) cin >> aray[i][j];     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) cin >> arr[i][j];     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (aray[i][j] > arr[i][j]) swap(aray[i][j], arr[i][j]);       }     }     for (int i = 0; i < n; i++) {       for (int j = 1; j < m; j++) {         if (aray[i][j] <= aray[i][j - 1] || arr[i][j] <= arr[i][j - 1]) {           cout <<  Impossible n ;           return 0;         }       }     }     for (int j = 0; j < m; j++) {       for (int i = 1; i < n; i++) {         if (aray[i][j] <= aray[i - 1][j] || arr[i][j] <= arr[i - 1][j]) {           cout <<  Impossible n ;           return 0;         }       }     }     cout <<  Possible n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     map<char, int> mp;     mp[ q ] = 9;     mp[ k ] = 0;     mp[ r ] = 5;     mp[ b ] = 3;     mp[ n ] = 3;     mp[ p ] = 1;     int white = 0, black = 0;     for (int i = 0; i < 8; i++) {       for (int j = 0; j < 8; j++) {         char x;         cin >> x;         if (x >=  A  && x <=  Z ) white += mp[x + 32];         if (x >=  a  && x <=  z ) black += mp[x];       }     }     if (white > black)       cout <<  White  << endl;     else if (white == black)       cout <<  Draw  << endl;     else       cout <<  Black  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 20;   long long int dp[MAXN][MAXN];   long long int tav[MAXN];   long long int n;   string s;   long long int dtoc(char x) { return x -  0 ; }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     tav[0] = 1;     for (int i = 1; i < MAXN; i++) {       tav[i] = 10 * tav[i - 1];     }     cin >> n;     cin >> s;     for (int i = 0; i <= n; i++) {       for (int j = 0; j <= n; j++) {         if (i) {           dp[i][j] = dp[i - 1][j] + dtoc(s[2 * n - i - j]) * tav[i - 1];         }         if (j) {           dp[i][j] =               max(dp[i][j], dp[i][j - 1] + dtoc(s[2 * n - i - j]) * tav[j - 1]);         }       }     }     int i = n;     int j = n;     while (i > 0 || j > 0) {       if (i && dp[i - 1][j] + dtoc(s[2 * n - i - j]) * tav[i - 1] == dp[i][j]) {         i--;         cout <<  H ;       } else {         j--;         cout <<  M ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int v[300123], n, ans, g[300123], f[300123], a, b, m, op;   queue<int> q;   int main() {     ios_base::sync_with_stdio(0);     cin >> n;     for (int i = 1; i <= n; ++i) {       cin >> v[i];       if (~v[i])         g[v[i]]++;       else {         g[0]++;       }     }     ans = 1;     for (int i = 1; i <= n; ++i) {       if (g[i] == 0) {         q.push(i);         f[i] = 1;       }     }     while (!q.empty()) {       int u = q.front();       q.pop();       g[v[u]]--;       if (g[v[u]] == 0) {         f[v[u]] = f[u] + 1;         q.push(v[u]);         ans = max(ans, f[v[u]]);       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     for (int i = 0; i < t; i++) {       int x;       cin >> x;       int ans = (x % 10 - 1) * 10;       ans += 1;       if (x / 10 > 0) ans += 2;       if (x / 100 > 0) ans += 3;       if (x / 1000 > 0) ans += 4;       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(NULL);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) {       int a, b, c, m;       cin >> a >> b >> c >> m;       int len = a + b + c;       int maxi = len - 3;       int valMax = max(a, max(b, c));       int mini = max(0, ((2 * valMax) - len - 1));       if (m < mini || m > maxi)         cout <<  NO n ;       else         cout <<  YES n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename A, typename B>   ostream &operator<<(ostream &os, const pair<A, B> &p) {     return os <<  (  << p.first <<  ,   << p.second <<  ) ;   }   template <typename T_container, typename T = typename enable_if<                                       !is_same<T_container, string>::value,                                       typename T_container::value_type>::type>   ostream &operator<<(ostream &os, const T_container &v) {     os <<  { ;     string sep;     for (const T &x : v) os << sep << x, sep =  ,  ;     return os <<  } ;   }   void dbg_out() { cerr << endl; }   template <typename Head, typename... Tail>   void dbg_out(Head H, Tail... T) {     cerr <<     << H;     dbg_out(T...);   }   const int INF = 1 << 30;   const int MOD = 1e9 + 7;   const int MAXN = 2e5 + 5;   string asignar(int n) {     if (n == 0) return  S ;     if (n == 1) return  M ;     if (n == 2) return  L ;     if (n == 3) return  XL ;     if (n == 4) return  XXL ;     if (n == 5) return  XXXL ;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     vector<int> stock(6);     for (long long i = (0); i < (long long)(6); i++) cin >> stock[i];     int n;     cin >> n;     vector<pair<pair<int, int>, int>> quiero(n);     for (long long j = (0); j < (long long)(n); j++) {       string s;       cin >> s;       string curr =   ;       pair<int, int> x = make_pair(-1, -1);       for (long long i = (0); i < (long long)(s.size()); i++) {         if (s[i] !=  , ) {           curr += s[i];         } else {           if (curr ==  S ) x.first = 0;           if (curr ==  M ) x.first = 1;           if (curr ==  L ) x.first = 2;           if (curr ==  XL ) x.first = 3;           if (curr ==  XXL ) x.first = 4;           if (curr ==  XXXL ) x.first = 5;           curr =   ;         }       }       if (curr ==  S ) x.second = 0;       if (curr ==  M ) x.second = 1;       if (curr ==  L ) x.second = 2;       if (curr ==  XL ) x.second = 3;       if (curr ==  XXL ) x.second = 4;       if (curr ==  XXXL ) x.second = 5;       if (x.first == -1) x.first = x.second;       if (x.first > x.second) swap(x.first, x.second);       quiero[j] = make_pair(x, j);     }     sort((quiero).begin(), (quiero).end());     ;     vector<string> ans(n);     for (long long i = (0); i < (long long)(n); i++) {       if (stock[quiero[i].first.first] > 0) {         ans[quiero[i].second] = asignar(quiero[i].first.first);         stock[quiero[i].first.first]--;       } else if (stock[quiero[i].first.second] > 0) {         ans[quiero[i].second] = asignar(quiero[i].first.second);         stock[quiero[i].first.second]--;       } else {         cout <<  NO n ;         return 0;       }     }     cout <<  YES n ;     for (long long i = (0); i < (long long)(n); i++) cout << ans[i] <<   n ;     cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int in() {     int x;     scanf( %d , &x);     return x;   }   const int N = 1e6 + 7;   int n, m, a[N], Q;   long long SUM, psr[N], psl[N];   int en[N], st[N];   pair<int, long long> dpl[N], dpr[N];   int solve(long long maax) {     if (maax >= SUM) return 1;     long long sum = 0, cur = 0;     for (int i = 0; i < n; i++) {       sum += a[i];       while (sum > maax) {         en[cur] = i - 1;         sum -= a[cur];         cur++;       }     }     while (cur < n) en[cur++] = n - 1;     sum = 0, cur = n - 1;     for (int i = n - 1; i >= 0; i--) {       sum += a[i];       while (sum > maax) {         st[cur] = i + 1;         sum -= a[cur];         cur--;       }     }     while (cur >= 0) st[cur--] = 0;     for (int i = 0; i < n; i++) {       if (st[i] == 0)         dpl[i] = {1, psl[i + 1]};       else         dpl[i] = dpl[st[i] - 1], dpl[i].first++;     }     for (int i = n - 1; i >= 0; --i) {       if (en[i] == n - 1)         dpr[i] = {1, psr[i]};       else         dpr[i] = dpr[en[i] + 1], dpr[i].first++;     }     int mn = dpr[0].first;     for (int i = 1; i < n; i++)       mn = min(mn, dpr[i].first + dpl[i - 1].first -                        ((dpr[i].second + dpl[i - 1].second) <= maax));     return mn;   }   int32_t main() {     n = in(), Q = in();     for (int i = 0; i < n; i++) {       a[i] = in();       SUM += a[i];       psl[i + 1] = a[i] + psl[i];     }     for (int i = n - 1; i >= 0; --i) psr[i] = psr[i + 1] + a[i];     while (Q--) {       long long x;       cin >> x;       cout << solve(x) <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int a[1005][1005], used[1005][1005];   const int dx[4] = {0, 0, 1, -1};   const int dy[4] = {1, -1, 0, 0};   void DFS(int i, int j, int N, int M) {     if (i == 0 || i == N + 1 || j == 0 || j == M + 1 || used[i][j]) return;     used[i][j] = 1;     for (int d = 0; d < 4; ++d)       if (a[i + dx[d]][j + dy[d]] == 1) DFS(i + dx[d], j + dy[d], N, M);   }   int main() {     int N, M;     scanf( %d%d , &N, &M);     int numberBlacks = 0;     for (int i = 1; i <= N; ++i) {       char s[1005];       scanf( %s , s + 1);       for (int j = 1; j <= M; ++j)         if (s[j] ==  # ) {           a[i][j] = 1;           ++numberBlacks;         }     }     if (numberBlacks == 0) {       printf( 0 n );       return 0;     }     int emptyLines = 0;     for (int i = 1; i <= N; ++i) {       int cnt = 0, numberLineSegments = 0;       for (int j = 1; j <= M; ++j) {         cnt += a[i][j];         if (a[i][j - 1] == 0 && a[i][j] == 1) ++numberLineSegments;       }       if (numberLineSegments > 1) {         printf( -1 n );         return 0;       }       if (cnt == 0) ++emptyLines;     }     int emptyColumns = 0;     for (int j = 1; j <= M; ++j) {       int cnt = 0, numberColumnSegments = 0;       for (int i = 1; i <= N; ++i) {         cnt += a[i][j];         if (a[i - 1][j] == 0 && a[i][j] == 1) ++numberColumnSegments;       }       if (numberColumnSegments > 1) {         printf( -1 n );         return 0;       }       if (cnt == 0) ++emptyColumns;     }     if (emptyLines == 0 && emptyColumns > 0 ||         emptyLines > 0 && emptyColumns == 0) {       printf( -1 n );       return 0;     }     int connectedComponents = 0;     for (int i = 1; i <= N; ++i)       for (int j = 1; j <= M; ++j)         if (used[i][j] == 0 && a[i][j] == 1) {           ++connectedComponents;           DFS(i, j, N, M);         }     printf( %d n , connectedComponents);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   T scani(T &n) {     n = 0;     bool negative = false;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) negative = true;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       n = n * 10 + c - 48;       c = getchar();     }     if (negative) n = ~(n - 1);     return n;   }   template <typename T>   void write(T n, int type = true) {     if (n < 0) {       putchar( - );       n = -n;     }     if (!n) {       putchar( 0 );       if (type == 32)         putchar(   );       else if (type)         putchar(  n );       return;     }     char buff[22];     int len = 0;     while (n) buff[len++] = n % 10 + 48, n /= 10;     for (int i = len - 1; i >= 0; i--) putchar(buff[i]);     if (type == 32)       putchar(   );     else if (type)       putchar(  n );   }   int scans(char *a) {     int i = 0;     char c = 0;     while (c < 33) c = getchar();     while (c > 33) {       a[i++] = c;       c = getchar();     }     a[i] = 0;     return i;   }   const int N = 100005;   int main() {     int n, k;     scani(n), scani(k);     int ans;     ans = (2 * n + k - 1) / k + (5 * n + k - 1) / k + (8 * n + k - 1) / k;     write(ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline bool uin(T& a, T b) {     return a > b ? (a = b, true) : false;   }   template <class T>   inline bool uax(T& a, T b) {     return a < b ? (a = b, true) : false;   }   const int nax = 5123;   pair<int, int> edge[nax];   vector<int> g[nax];   int col[nax];   int N, M;   bool cycle_found = false;   int dfs_num[nax];   void dfs(int v) {     dfs_num[v] = 1;     for (int i : g[v]) {       int ch = edge[i].first ^ edge[i].second ^ v;       if (dfs_num[ch] == 2) {         continue;       } else if (dfs_num[ch] == 1) {         col[i] = 1;         cycle_found = true;         continue;       }       dfs(ch);     }     dfs_num[v] = 2;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> N >> M;     for (int u, v, i = 0; i < M; ++i) {       cin >> u >> v;       --u, --v;       edge[i] = make_pair(u, v);       g[u].push_back(i);     }     for (int i = 0; i < N; ++i)       if (dfs_num[i] != 2) dfs(i);     cout << (cycle_found ? 2 : 1) <<   n ;     for (int i = 0; i < M; ++i) cout << col[i] + 1 <<    n [i == M - 1];   }


#include <bits/stdc++.h>   using namespace std;   int n, m, mid, rt, res, a[200010], f[200010], sz[200010];   vector<int> e[200010];   void dfs(int u, int fa) {     f[u] = sz[u] = 1;     int m1 = 0, m2 = 0;     for (auto v : e[u]) {       if (v == fa) continue;       dfs(v, u);       sz[u] += sz[v];       if (f[v] == sz[v])         f[u] += f[v];       else {         if (f[v] > m1) swap(f[v], m1);         if (f[v] > m2) swap(f[v], m2);       }     }     f[u] = a[u] < mid ? 0 : f[u] + m1;     res = max(res, f[u] + m2);   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     for (int i = 1; i < n; i++) {       int u, v;       scanf( %d%d , &u, &v);       e[u].push_back(v);       e[v].push_back(u);     }     rt = min_element(a + 1, a + 1 + n) - a;     int l = 0, r = 1000010, ans;     while (l <= r) {       mid = (l + r) >> 1;       res = 0;       dfs(rt, 0);       if (res >= m)         l = mid + 1, ans = mid;       else         r = mid - 1;     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool used[10000005];   int ans[105];   bool comp(pair<pair<int, int>, int> a, pair<pair<int, int>, int> b) {     if (a.first.second == b.first.second) return a.first.first < b.first.first;     return a.first.second < b.first.second;   }   void solve() {     int N;     cin >> N;     vector<pair<pair<int, int>, int>> x(N);     for (int i = 0; i < N; i++) {       cin >> x[i].first.first >> x[i].first.second;       x[i].second = i;     }     sort(x.begin(), x.end(), comp);     for (int i = 0; i < N; i++) {       for (int j = x[i].first.first; j < x[i].first.second + 1; j++) {         if (!used[j]) {           used[j] = true;           ans[x[i].second] = j;           break;         }       }     }     for (int i = 0; i < N; i++) {       cout << ans[i] <<    ;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t = 1;     while (t--) {       solve();     }     return 0;   }