#include <bits/stdc++.h>   using namespace std;   inline void read(int &x) {     char c;     int f = 1;     while (!isdigit(c = getchar()))       if (c ==  - ) f = -1;     x = (c & 15);     while (isdigit(c = getchar())) x = (x << 1) + (x << 3) + (c & 15);     x *= f;   }   const int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, -1, 0, 1};   int _, n, m, i, j, k, a[100005], dis[100015], s = 0, t = 100001, ss = 100002,                                                 tt = 100003, l[100015];   int dir[100005], res[100005];   int px[2000005], py[2000005], pdx[2000005], pdy[2000005];   int id(int x, int y) { return (x - 1) * m + y; }   vector<int> bi[100015];   struct ii {     int y, z;   } e[2000005];   int tot;   void init() {     int i;     for ((i) = 1; (i) <= (tot); (i)++) px[i] = py[i] = pdx[i] = pdy[i] = 0;     tot = 0;     memset(l, 0, sizeof(l));     for ((i) = 0; (i) <= (tt); (i)++) bi[i].clear();   }   void add(int x, int y, int z) {     tot++;     bi[x].push_back(tot + tot - 2);     bi[y].push_back(tot + tot - 1);     e[tot + tot - 2] = (ii){y, z};     e[tot + tot - 1] = (ii){x, 0};   }   bool bfs(int s, int t) {     memset(dis, 0x3f, sizeof(dis));     dis[s] = 0;     queue<int> qx;     qx.push(s);     while (!qx.empty()) {       int x = qx.front();       qx.pop();       for (__typeof((bi[x]).begin()) it = (bi[x]).begin(); it != (bi[x]).end();            ++it)         if (e[*it].z && dis[e[*it].y] > dis[x] + 1) {           dis[e[*it].y] = dis[x] + 1;           qx.push(e[*it].y);         }     }     return dis[t] < dis[100014];   }   int dfs(int x, int tt, int flw) {     if (x == tt || !flw) return flw;     int ans = 0;     for (__typeof((bi[x]).begin()) it = (bi[x]).begin(); it != (bi[x]).end();          ++it)       if (dis[x] + 1 == dis[e[*it].y] && e[*it].z) {         int t = dfs(e[*it].y, tt, min(flw, e[*it].z));         ans += t;         flw -= t;         e[*it].z -= t;         e[(*it) ^ 1].z += t;       }     if (flw) dis[x] = -1;     return ans;   }   int dinic(int s, int t) {     int ans = 0;     while (bfs(s, t)) {       ans += dfs(s, t, 0x3f3f3f3f);     }     return ans;   }   int main() {     read(_);     while (_--) {       read(n);       read(m);       for ((i) = 1; (i) <= (n); (i)++)         for ((j) = 1; (j) <= (m); (j)++) read(a[id(i, j)]);       init();       add(t, s, 0x3f3f3f3f);       for ((i) = 1; (i) <= (n * m); (i)++) {         dir[i] = res[i] = 0;       }       for ((i) = 1; (i) <= (n); (i)++)         for ((j) = 1; (j) <= (m); (j)++) {           bool f = 0;           for ((k) = 0; (k) < (4); (k)++) {             int x = i + dx[k], y = j + dy[k];             if (x < 1 || x > n || y < 1 || y > m) continue;             if (a[id(i, j)] == a[id(x, y)] && ((i + j) & 1)) {               add(id(i, j), id(x, y), 1);               px[tot] = id(i, j);               py[tot] = id(x, y);               pdx[tot] = k;               pdy[tot] = (k ^ 2);             }             if (a[id(i, j)] > a[id(x, y)]) {               dir[id(i, j)] = k;               res[id(i, j)] = a[id(i, j)] - a[id(x, y)];               f = 1;             }           }           if ((i + j) & 1) {             if (!f) {               l[s]--;               l[id(i, j)]++;             } else               add(s, id(i, j), 1);           } else {             if (!f) {               l[id(i, j)]--;               l[t]++;             } else               add(id(i, j), t, 1);           }         }       int sum = 0, ctot = tot;       for ((i) = 0; (i) <= (t); (i)++) {         if (l[i] > 0) {           add(ss, i, l[i]);           sum += l[i];         }         if (l[i] < 0) {           add(i, tt, -l[i]);         }       }       int ans = dinic(ss, tt);       if (ans != sum) {         puts( NO );         continue;       }       puts( YES );       for ((i) = (2); (i) <= (ctot); (i)++)         if (e[i + i - 1].z) {           dir[px[i]] = pdx[i];           dir[py[i]] = pdy[i];           res[px[i]] = 1;           res[py[i]] = a[py[i]] - 1;         }       for ((i) = 1; (i) <= (n); (i)++) {         for ((j) = 1; (j) <= (m); (j)++) {           printf( %d%c , res[id(i, j)], (j == m ?   n  :    ));         }       }       for ((i) = 1; (i) <= (n); (i)++) {         for ((j) = 1; (j) <= (m); (j)++) {           printf( %c%c , dir[id(i, j)][ ULDR ], (j == m ?   n  :    ));         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 1e5 + 5;   vector<pair<int, int> > opt[18 * MAX];   map<pair<int, int>, vector<pair<int, int> > > mp;   int par[MAX];   int col[MAX];   int sz[MAX];   int an[MAX];   vector<int> roll_back_num;   vector<pair<pair<int, pair<int, int> >, pair<int, pair<int, int> > > >       roll_back;   void insert(int t, int l, int r, int a, int b, int c, int d) {     if (l > b || r < a) {       return;     }     if (l >= a && r <= b) {       opt[t].push_back(make_pair(c, d));       return;     }     int mid = (l + r) / 2;     insert(t * 2, l, mid, a, b, c, d);     insert(t * 2 + 1, mid + 1, r, a, b, c, d);   }   int not_cor;   int find(int x) {     while (x != par[x]) {       x = par[x];     }     return x;   }   int color(int x) {     int ans = 0;     while (x != par[x]) {       ans ^= col[x];       x = par[x];     }     return (ans ^ col[x]);   }   void unite(int a, int b) {     int ra = find(a), rb = find(b);     int ca = color(a), cb = color(b);     if (ra == rb) {       if (ca == cb) {         not_cor++;         roll_back_num.push_back(-1);       }     } else {       if (sz[ra] > sz[rb]) {         swap(a, b);         swap(ra, rb);         swap(ca, cb);       }       roll_back.push_back({{ra, {ra, sz[ra]}}, {rb, {col[ra], sz[rb]}}});       par[ra] = rb;       sz[rb] += sz[ra];       if (ca == cb) {         col[ra] ^= 1;       }     }   }   void solve(int t, int l, int r) {     int curn = roll_back_num.size();     int cur = roll_back.size();     for (auto it : opt[t]) {       unite(it.first, it.second);     }     if (l == r) {       if (not_cor) {         an[l] = 0;       } else {         an[l] = 1;       }     } else {       int mid = (l + r) / 2;       solve(2 * t, l, mid);       solve(2 * t + 1, mid + 1, r);     }     while (roll_back_num.size() > curn) {       not_cor += roll_back_num.back();       roll_back_num.pop_back();     }     while (roll_back.size() > cur) {       pair<pair<int, pair<int, int> >, pair<int, pair<int, int> > > tmp =           roll_back.back();       par[tmp.first.first] = tmp.first.second.first;       sz[tmp.first.first] = tmp.first.second.second;       col[tmp.first.first] = tmp.second.second.first;       sz[tmp.second.first] = tmp.second.second.second;       roll_back.pop_back();     }   }   int main() {     int n, q;     scanf( %d %d , &n, &q);     for (int i = 1; i <= q; i++) {       int a, b;       scanf( %d %d , &a, &b);       if (a > b) {         swap(a, b);       }       vector<pair<int, int> >& tmp = mp[make_pair(a, b)];       if (tmp.empty() || (((tmp.back()).second) != -1)) {         tmp.push_back(make_pair(i, -1));       } else {         (tmp.back()).second = (i - 1);       }     }     for (auto it : mp) {       for (auto it1 : it.second) {         if (it1.second == -1) {           it1.second = q;         }         insert(1, 1, q, it1.first, it1.second, it.first.first, it.first.second);       }     }     for (int i = 1; i <= n; i++) {       sz[i] = 1;       par[i] = i;     }     solve(1, 1, q);     for (int i = 1; i <= q; i++) {       if (an[i] == 0) {         printf( NO n );       } else {         printf( YES n );       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mxn = 100006;   const int mxm = 100006 * 2;   int n, m;   int fe[mxn] = {};   int ne[mxm];   int ev[mxm];   bool v[mxm];   int el = 1;   void add1(int L, int R) {     ++el;     ne[el] = fe[L];     fe[L] = el;     ev[el] = R;   }   bool vis[mxn];   int dfs(int x) {     if (vis[x]) return 0;     vis[x] = true;     int last = 0;     for (int i = fe[x]; i; i = ne[i])       if (!v[i]) {         v[i] = v[i ^ 1] = true;         int t = dfs(ev[i]);         if (t) {           printf( %d %d %d n , x, ev[i], t);         } else {           if (last) {             printf( %d %d %d n , last, x, ev[i]);             last = 0;           } else {             last = ev[i];           }         }       }     return last;   }   void EXEC() {     cin >> n >> m;     if (m % 2 == 1) {       cout <<  No solution  << endl;       return;     }     for (int i = 0; i < m; ++i) {       int L, R;       scanf( %d%d , &L, &R);       add1(L, R);       add1(R, L);     }     dfs(1);   }   int main() {     EXEC();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct people {     long long a, b, id;   } p[300010];   long long n, s[300010], t;   bool v[300010], ans[300010];   bool cmp(people a, people b) { return a.a == b.a ? a.b > b.b : a.a > b.a; }   long double check(people a, people b) {     return (long double)a.a * b.a * (b.b - a.b) / (b.a - a.a) / b.b / a.b;   }   int main() {     scanf( %lld , &n);     for (int i = 1; i <= n; i++) scanf( %lld%lld , &p[i].a, &p[i].b), p[i].id = i;     sort(p + 1, p + n + 1, cmp);     s[1] = 1, t = 1;     long long maxb = p[1].b;     for (int i = 2; i <= n; i++)       if (p[i].b <= maxb)         v[i] = 1;       else         maxb = p[i].b;     for (int i = 2; i <= n; i++) {       if (v[i] || check(p[i], p[s[t]]) > 0) continue;       while (t > 1 && check(p[i], p[s[t]]) < check(p[s[t - 1]], p[s[t]])) t--;       s[++t] = i;     }     for (int i = 1; i <= t; i++) {       ans[p[s[i]].id] = 1;       for (int j = s[i] + 1; j <= n && p[s[i]].a == p[j].a && p[s[i]].b == p[j].b;            j++)         ans[p[j].id] = 1;     }     for (int i = 1; i <= n; i++)       if (ans[i]) printf( %d  , i);     return 0;   }


#include <bits/stdc++.h>   /** #include <ext/pb_ds/assoc_container.hpp>    * #include <ext/pb_ds/tree_policy.hpp>    * using namespace __gnu_pbds; */   using namespace std;      #define ll long long   #define ull unsigned long long   #define f(a, b) for (ll i = a; i < b; i++)   #define mod 1000000007   #define pb push_back   #define vll vector<ll>   #define pll vector<pair<ll, ll>>   #define ld long double   #define fr(a, b) for (ll j = a; j >= b; j--)   #define fi(a, b) for (ll j = a; j < b; j++)   #define fii(a, b) for (ll k = a; k < b; k++)   /** typedef tree<ll    * ,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>    * ordered_set; */      template <class T> ostream &operator<<(ostream &os, vector<T> V) {     os <<  [  ;     for (auto v : V)       os << v <<    ;     os <<  ] ;     return os;   }   template <class T> ostream &operator<<(ostream &os, set<T> S) {     os <<  {  ;     for (auto s : S)       os << s <<    ;     return os <<  } ;   }   template <class L, class R> ostream &operator<<(ostream &os, map<L, R> M) {     os <<  {  ;     for (auto m : M)       os <<  (  << m.first <<  :  << m.second <<  )  ;     return os <<  } ;   }   template <class L, class R> ostream &operator<<(ostream &os, pair<L, R> P) {     return os <<  (  << P.first <<  ,  << P.second <<  ) ;   }      const ll N = 200005;   vll adj[N];   ll n, color[N], parent[N], cycle_end, cycle_start, ans;   bool C[N];      bool dfs(ll v, ll par) {     color[v] = 1;     for (ll u : adj[v]) {       if (u == par)         continue;       if (color[u] == 0) {         parent[u] = v;         if (dfs(u, parent[u]))           return true;       } else if (color[u] == 1) {         cycle_end = v;         cycle_start = u;         return true;       }     }     color[v] = 2;     return false;   }      ll DFS(ll x, ll pr) {     ll k = 1;     f(0, adj[x].size()) {       if (adj[x][i] != pr)         k += DFS(adj[x][i], x);     }     return k;   }      void solve() {     cycle_start = -1;     for (int v = 1; v <= n; v++) {       if (color[v] == 0 && dfs(v, parent[v]))         break;     }     vector<int> cycle;     C[cycle_start] = 1;     cycle.push_back(cycle_start);     for (int v = cycle_end; v != cycle_start; v = parent[v])       cycle.push_back(v), C[v] = 1;     vll V;     f(0, cycle.size()) {       ll v = cycle[i];       ll tot = 0;       fi(0, adj[v].size()) {         if (!C[adj[v][j]]) {           tot += DFS(adj[v][j], v);         }       }       V.pb(tot);     }     ll l = cycle.size();     ans += l * (l - 1);     f(0, V.size()) {       ll k = V[i];       ans += k * (l - 1) * 2 + k;       ans += k * (k - 1) / 2;     }     ll sum = 0;     f(0, V.size()) sum += V[i];     f(0, V.size()) {       sum -= V[i];       ans += V[i] * sum * 2;     }   }      int main() {   #ifndef ONLINE_JUDGE     freopen( input.txt ,  rt , stdin);     freopen( output.txt ,  wt , stdout);   #endif     ios_base::sync_with_stdio(false);     cin.tie(NULL);        ll t;     cin >> t;     while (t--) {       cin >> n;       ans = 0;       f(1, n + 1) adj[i].clear(), color[i] = 0, parent[i] = -1, C[i] = false;       f(0, n) {         ll x, y;         cin >> x >> y;         adj[x].pb(y);         adj[y].pb(x);       }       solve();       cout << ans <<   n ;     }      #ifndef ONLINE_JUDGE     cout <<   nTime Elapsed :   << 1000 * (ld)clock() / (ld)CLOCKS_PER_SEC          <<   ms n ;   #endif     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   char s1[128];   int l1;   char s2[128];   int l2;   char virus[128];   int lv;   int nxt[128][128];   vector<int> froms[128][128];   void calc_nxt() {     char tmp[128];     strcpy(tmp, virus);     for (int l = 0; l < lv; l++) {       for (char ch =  A ; ch <=  Z ; ch++) {         tmp[l] = ch;         for (int i = l + 1; i >= 0; i--) {           if (!strncmp(tmp + l + 1 - i, virus, i)) {             nxt[l][(int)ch] = i;             break;           }         }         froms[nxt[l][(int)ch]][(int)ch].push_back(l);       }       tmp[l] = virus[l];     }   }   struct Path {     int i, j, k;   };   bool operator<(const Path &a, const Path &b) {     if (a.i != b.i) return a.i < b.i;     if (a.j != b.j) return a.j < b.j;     if (a.k != b.k) return a.k < b.k;     return false;   }   pair<int, Path> dp[128][128][128];   pair<int, Path> takeDP(int i, int j, int k) {     pair<int, Path> t = dp[i][j][k];     t.second = {i, j, k};     return t;   }   string getPath(pair<int, Path> runner) {     string s;     while (runner.first != 0) {       Path p = runner.second;       auto nr = dp[p.i][p.j][p.k];       Path np = nr.second;       if (np.i < p.i && np.j < p.j) {         s += s1[p.i - 1];       }       runner = nr;     }     reverse(s.begin(), s.end());     if (s ==   ) return  0 ;     return s;   }   bool isSub(string s, string p) {     size_t l = 0;     for (auto ch : p) {       cout << ch;       while (l < s.size() && s[l] != ch) {         l++;       }       if (l == s.size()) {         cout << endl;         return false;       }       l++;     }     cout << endl;     return true;   }   int TestNum;   int main() {     scanf( %s%s%s , s1, s2, virus);     l1 = strlen(s1);     l2 = strlen(s2);     lv = strlen(virus);     calc_nxt();     for (int i = 0; i < l1; i++) {       for (int k = 1; k <= lv; k++) {         dp[i][0][k].first = -0x1f1f1f1f;       }     }     for (int i = 0; i < l2; i++) {       for (int k = 1; k <= lv; k++) {         dp[0][i][k].first = -0x1f1f1f1f;       }     }     dp[0][0][0].first = 0;     for (int i = 0; i < l1; i++) {       for (int j = 0; j < l2; j++) {         for (int k = 0; k < lv; k++) {           auto &to = dp[i + 1][j + 1][k];           auto from1 = takeDP(i + 1, j, k), from2 = takeDP(i, j + 1, k);           to = max(from1, from2);           if (s1[i] == s2[j]) {             for (auto tk : froms[k][(int)s1[i]]) {               auto from = takeDP(i, j, tk);               from.first += 1;               to = max(to, from);             }           }         }       }     }     auto best = dp[0][0][0];     for (int k = 0; k < lv; k++) {       best = max(best, takeDP(l1, l2, k));     }     string s = getPath(best);     cout << s << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 3001;   const int mod = 1000000007;   char s[N][N];   int f[N][N];   int calc(int sr, int sc, int tr, int tc) {     if (tr < sr || tc < sc) return 0;     int n = tr - sr + 1, m = tc - sc + 1;     f[0][0] = (s[sr][sc] !=  # );     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++)         if (i || j) {           f[i][j] = 0;           if (i > 0) f[i][j] += f[i - 1][j];           if (j > 0) f[i][j] += f[i][j - 1];           f[i][j] %= mod;           if (s[i + sr][j + sc] ==  # ) f[i][j] = 0;         }     }     return f[n - 1][m - 1];   }   int main() {     int n, m;     scanf( %d%d , &n, &m);     for (int i = 0; i < n; i++) scanf( %s , s[i]);     int a, b, c, d;     a = calc(0, 1, n - 2, m - 1);     b = calc(1, 0, n - 1, m - 2);     c = calc(0, 1, n - 1, m - 2);     d = calc(1, 0, n - 2, m - 1);     printf( %lld n , ((1LL * a * b - 1LL * c * d) % mod + mod) % mod);     return 0;   }


#include <bits/stdc++.h>   template <typename T>   T inline SQR(const T &a) {     return a * a;   }   template <typename T>   T inline ABS(const T &a) {     return a < 0 ? -a : a;   }   template <typename T>   T inline MIN(const T &a, const T &b) {     if (a < b) return a;     return b;   }   template <typename T>   T inline MAX(const T &a, const T &b) {     if (a > b) return a;     return b;   }   const double EPS = 1e-9;   inline int sgn(double a) { return a > EPS ? 1 : (a < -EPS ? -1 : 0); }   inline int cmp(double a, double b) { return sgn(a - b); }   using namespace std;   struct orientacao_t {     char f, c;     char v[4];     orientacao_t() {}     orientacao_t(char frente, char costas, char vizinhos[])         : f(frente), c(costas) {       for (int i = 0; i < 4; i++) v[i] = vizinhos[i];     }     bool operator==(const orientacao_t &o) const {       if (f == o.f && c == o.c) {         if (v[0] == o.v[0] && v[1] == o.v[1] && v[2] == o.v[2] && v[3] == o.v[3])           return true;         if (v[0] == o.v[1] && v[1] == o.v[2] && v[2] == o.v[3] && v[3] == o.v[0])           return true;         if (v[0] == o.v[2] && v[1] == o.v[3] && v[2] == o.v[0] && v[3] == o.v[1])           return true;         if (v[0] == o.v[3] && v[1] == o.v[0] && v[2] == o.v[1] && v[3] == o.v[2])           return true;       }       if (f == o.c && c == o.f) {         if (v[2] == o.v[0] && v[1] == o.v[1] && v[0] == o.v[2] && v[3] == o.v[3])           return true;         if (v[2] == o.v[1] && v[1] == o.v[2] && v[0] == o.v[3] && v[3] == o.v[0])           return true;         if (v[2] == o.v[2] && v[1] == o.v[3] && v[0] == o.v[0] && v[3] == o.v[1])           return true;         if (v[2] == o.v[3] && v[1] == o.v[0] && v[0] == o.v[1] && v[3] == o.v[2])           return true;       }       return false;     }     void operator=(const orientacao_t &o) {       f = o.f;       c = o.c;       for (int i = 0; i < 4; i++) v[i] = o.v[i];     }   };   struct cubo_t {     orientacao_t orientacao[3];     cubo_t() {}     cubo_t(char a, char b, char c, char d, char e, char f) {       char v[4];       v[0] = e;       v[1] = d;       v[2] = c;       v[3] = b;       orientacao[0] = orientacao_t(a, f, v);       v[0] = e;       v[1] = a;       v[2] = c;       v[3] = f;       orientacao[1] = orientacao_t(b, d, v);       v[0] = d;       v[1] = a;       v[2] = b;       v[3] = f;       orientacao[2] = orientacao_t(e, c, v);     }     bool operator==(const cubo_t &c) const {       for (int i = 0; i < 3; i++)         for (int j = 0; j < 3; j++)           if (orientacao[i] == c.orientacao[j]) return true;       return false;     }     void operator=(const cubo_t &c) {       orientacao[0] = c.orientacao[0];       orientacao[1] = c.orientacao[1];       orientacao[2] = c.orientacao[2];     }   };   int main(int argc, char *argv[]) {     ios::sync_with_stdio(false);     string s;     cin >> s;     sort(s.begin(), s.end());     vector<cubo_t> cubes;     int eq = 0;     do {       cubo_t aux = cubo_t(s[0], s[1], s[2], s[3], s[4], s[5]);       for (int i = 0; i < int((cubes).size()); ++i)         if (aux == cubes[i]) goto hell;       cubes.push_back(aux);     hell:       eq++;     } while (next_permutation(s.begin(), s.end()));     cout << int((cubes).size()) <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> adj[100005];   struct Tree {     vector<vector<int> > anc;     vector<vector<int> > cost;     vector<int> T, X;     vector<int> depth;     vector<bool> vis;     int n;     int root;     Tree(int N = 1e5, int r = 1) {       n = N + 5;       root = r;       anc = vector<vector<int> >(18, vector<int>(n, 0));       depth = vector<int>(n, 0);       vis = vector<bool>(n, false);       X = T = vector<int>(n, 0);       init(root, -1);       for (int d = 1; d < 18; d++) {         for (int x = 0; x < n; x++) {           anc[d][x] = anc[d - 1][anc[d - 1][x]];         }       }     }     void init(int x, int pre) {       static int t = 0;       T[x] = t++;       for (int i = 0; i < adj[x].size(); i++) {         int y = adj[x][i];         if (y == pre) continue;         anc[0][y] = x;         depth[y] = depth[x] + 1;         init(y, x);       }       X[x] = t++;     }     int LCA(int x, int y) {       if (depth[x] < depth[y]) swap(x, y);       for (int w = (1 << 17), d = 17; d >= 0; w /= 2, d--) {         if (depth[x] - depth[y] >= w) {           x = anc[d][x];         }       }       if (x == y) return x;       for (int i = 17; i >= 0; i--) {         if (anc[i][x] != anc[i][y]) {           x = anc[i][x];           y = anc[i][y];         }       }       return anc[0][x];     }     int up(int x, int k) {       for (int w = (1 << 17), d = 17; d >= 0; w /= 2, d--) {         if (k >= w) {           x = anc[d][x];           k -= w;         }       }       return x;     }     int dist(int x, int y) {       int l = LCA(x, y);       return depth[x] + depth[y] - 2 * depth[l];     }     bool isparent(int x, int y) { return LCA(x, y) == x; }   } A;   vector<int> aux[100005];   vector<int> event(100005);   vector<int> val(100005), resv;   vector<bool> out(100005, false), tmp(100005, false);   int n, m, sq, s;   int ans = 0, lans = 0;   vector<int> temp;   vector<int> anc(100005, 0);   int root = 1;   vector<pair<int, int> > edge[100005];   vector<int> lazy(100005, 0);   vector<pair<int, int> > ptr(100005, {0, 0});   void compress(int b) {     for (auto x : temp) {       aux[x].clear();       lazy[x] = 0;       ptr[x] = {0, 0};       edge[x].clear();       anc[x] = 0;       tmp[x] = false;     }     temp.clear();     temp.push_back(1);     for (int i = b * sq; i < (b + 1) * sq && i < m; i++) {       temp.push_back(abs(event[i]));     }     sort((temp).begin(), (temp).end(),          [&](int x, int y) { return A.T[x] < A.T[y]; });     int ss = ((int)(temp).size());     for (int i = 1; i < ss; i++) {       temp.push_back(A.LCA(temp[i - 1], temp[i]));     }     sort((temp).begin(), (temp).end(),          [&](int x, int y) { return A.T[x] < A.T[y]; });     for (auto x : temp) tmp[x] = true;     stack<int> st;     root = 1;     for (auto x : temp) {       while (!st.empty() && A.X[st.top()] < A.T[x]) st.pop();       if (!st.empty() && st.top() != x) {         aux[x].push_back(st.top());         aux[st.top()].push_back(x);         anc[x] = st.top();         int l = A.anc[0][x];         map<int, int> cnt;         while (l != st.top()) {           if (!out[l]) cnt[val[l]]++;           l = A.anc[0][l];         }         for (auto itr : cnt) edge[x].push_back({itr.first, itr.second});         for (int i = 0; i < ((int)(edge[x]).size()); i++) {           if (edge[x][i].first < 0)             ptr[x] = {ptr[x].first + 1, ptr[x].second + edge[x][i].second};           else             break;         }       }       st.push(x);     }   }   int currTree(int x, int pre) {     int v = 0;     if (out[x]) v--;     for (auto y : adj[x]) {       if (y == pre) continue;       v += currTree(y, x);     }     val[x] += v;     return v;   }   bool stat(int x, int pre) {     bool down = false;     if (tmp[x]) down = true;     for (auto y : adj[x]) {       if (y == pre) continue;       down |= stat(y, x);     }     if (!down) {       if (!out[x] && val[x] < 0) lans++;     }     return down;   }   void update(int x, int v) {}   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cin >> n >> m;     for (int i = 2; i <= n; i++) {       int p;       cin >> p;       adj[p].push_back(i);       adj[i].push_back(p);     }     A = Tree();     for (int i = 1; i <= n; i++) cin >> val[i];     resv = val;     for (int i = 0; i < m; i++) cin >> event[i];     sq = 460;     s = (m - 1) / sq + 1;     for (int b = 0; b < s; b++) {       compress(b);       lans = 0;       stat(1, 0);       for (int i = b * sq; i < (b + 1) * sq && i < m; i++) {         if (event[i] < 0)           out[-event[i]] = false;         else           out[event[i]] = true;         int p = abs(event[i]);         int v = abs(event[i]) / event[i];         while (p != 0) {           lazy[p] += v;           val[p] -= v;           while (ptr[p].first > 0 && edge[p][ptr[p].first - 1].first >= lazy[p])             ptr[p] = {ptr[p].first - 1,                       ptr[p].second - edge[p][ptr[p].first - 1].second};           while (ptr[p].first < ((int)(edge[p]).size()) &&                  edge[p][ptr[p].first].first < lazy[p])             ptr[p] = {ptr[p].first + 1,                       ptr[p].second + edge[p][ptr[p].first].second};           p = anc[p];         }         ans = 0;         int l = -1;         for (auto x : temp) {           if (x == l) continue;           ans += ptr[x].second;           if (!out[x] && val[x] < 0) ans++;           l = x;         }         cout << lans + ans <<    ;       }       val = resv;       currTree(1, 0);     }     cerr << 1.0 * clock() / CLOCKS_PER_SEC << endl;   }


#include <bits/stdc++.h>   using namespace std;   int read() {     int q = 0;     char ch =    ;     while (ch <  0  || ch >  9 ) ch = getchar();     while (ch >=  0  && ch <=  9 ) q = q * 10 + ch -  0 , ch = getchar();     return q;   }   const int N = 200005, inf = 0x3f3f3f3f;   int n, m, Q, SZ, st_top, tim;   int w[N], dfn[N], low[N], st[N];   multiset<int> S[N];   struct graph {     int tot, h[N], ne[N], to[N];     void add(int x, int y) { to[++tot] = y, ne[tot] = h[x], h[x] = tot; }   } G, T;   void tarjan(int x, int las) {     dfn[x] = low[x] = ++tim, st[++st_top] = x;     for (register int i = G.h[x]; i; i = G.ne[i]) {       if (G.to[i] == las) continue;       int y = G.to[i];       if (!dfn[y]) {         tarjan(y, x), low[x] = min(low[x], low[y]);         if (low[y] == dfn[x]) {           ++SZ, w[SZ] = inf, T.add(x, SZ);           while (st[st_top] != y) {             T.add(SZ, st[st_top]), S[SZ].insert(w[st[st_top]]);             w[SZ] = min(w[SZ], w[st[st_top]]), --st_top;           }           T.add(SZ, y), S[SZ].insert(w[y]), w[SZ] = min(w[SZ], w[y]), --st_top;         } else if (low[y] > dfn[x])           ++SZ, w[SZ] = w[y], S[SZ].insert(w[y]), T.add(x, SZ), T.add(SZ, y);       } else         low[x] = min(low[x], dfn[y]);     }     if (dfn[x] == low[x]) --st_top;   }   int sz[N], fa[N], top[N], pos[N], repos[N], dep[N], mi[N << 2];   void dfs1(int x) {     sz[x] = 1, dep[x] = dep[fa[x]] + 1;     for (register int i = T.h[x]; i; i = T.ne[i])       fa[T.to[i]] = x, dfs1(T.to[i]), sz[x] += sz[T.to[i]];   }   void dfs2(int x) {     int bj = 0, mx = 0;     pos[x] = ++tim, repos[tim] = x;     for (register int i = T.h[x]; i; i = T.ne[i])       if (sz[T.to[i]] > mx) mx = sz[T.to[i]], bj = T.to[i];     if (bj) top[bj] = top[x], dfs2(bj);     for (register int i = T.h[x]; i; i = T.ne[i])       if (T.to[i] != bj) top[T.to[i]] = T.to[i], dfs2(T.to[i]);   }   void build(int s, int t, int i) {     if (s == t) {       mi[i] = w[repos[s]];       return;     }     int mid = (s + t) >> 1;     build(s, mid, i << 1), build(mid + 1, t, (i << 1) | 1);     mi[i] = min(mi[i << 1], mi[(i << 1) | 1]);   }   void chan(int x, int s, int t, int i, int v) {     if (s == t) {       mi[i] = v;       return;     }     int mid = (s + t) >> 1;     if (x <= mid) chan(x, s, mid, i << 1, v);     if (mid + 1 <= x) chan(x, mid + 1, t, (i << 1) | 1, v);     mi[i] = min(mi[i << 1], mi[(i << 1) | 1]);   }   int query(int l, int r, int s, int t, int i) {     if (l <= s && t <= r) return mi[i];     int mid = (s + t) >> 1, re = inf;     if (l <= mid) re = query(l, r, s, mid, i << 1);     if (mid + 1 <= r) re = min(re, query(l, r, mid + 1, t, (i << 1) | 1));     return re;   }   int getans(int x, int y) {     int re = inf;     while (top[x] != top[y]) {       if (dep[top[x]] < dep[top[y]]) swap(x, y);       re = min(re, query(pos[top[x]], pos[x], 1, SZ, 1));       x = fa[top[x]];     }     if (pos[x] > pos[y]) swap(x, y);     re = min(re, query(pos[x], pos[y], 1, SZ, 1));     if (x > n) re = min(re, query(pos[fa[x]], pos[fa[x]], 1, SZ, 1));     return re;   }   int main() {     int x, y;     char ch[10];     n = read(), m = read(), Q = read();     for (register int i = 1; i <= n; ++i) w[i] = read();     for (register int i = 1; i <= m; ++i)       x = read(), y = read(), G.add(x, y), G.add(y, x);     SZ = n, tarjan(1, 0);     dfs1(1), tim = 0, top[1] = 1, dfs2(1), build(1, SZ, 1);     while (Q--) {       scanf( %s , ch), x = read(), y = read();       if (ch[0] ==  C ) {         chan(pos[x], 1, SZ, 1, y);         if (x != 1) {           S[fa[x]].erase(S[fa[x]].find(w[x]));           S[fa[x]].insert(y);           int kw = *(S[fa[x]].begin());           if (kw != w[fa[x]]) chan(pos[fa[x]], 1, SZ, 1, kw), w[fa[x]] = kw;         }         w[x] = y;       } else         printf( %d n , getans(x, y));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long max(long long a, long long b) {     if (a > b) return a;     return b;   }   long long min(long long a, long long b) {     if (a > b) return b;     return a;   }   int main() {     {       ios_base::sync_with_stdio(false);       cin.tie(NULL);     };     int q;     cin >> q;     while (q--) {       long long a, b, c, r;       cin >> a >> b >> c >> r;       long long ans = 0;       if (b < a) {         long long temp = b;         b = a;         a = temp;       }       long long low = c - r;       long long high = c + r;       if (a <= low && high <= b) {         ans = b - a - (high - low);       } else if (low <= a && high <= b && a <= high) {         ans = b - a - (high - a);       } else if (b <= high && a <= low && low <= b) {         ans = b - a - (b - low);       } else if (low <= a && b <= high) {         ans = 0;       } else {         ans = b - a;       }       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char x;   int n;   int main() {     cin >> n;     cin >> x;     cout << x;     cin >> x;     cout << x;     n -= 2;     if (n % 2 == 1) {       cin >> x;       cout << x;       n--;     }     for (int i = 1; i <= n; i++) {       if (i % 2 == 1) cout <<  - ;       cin >> x;       cout << x;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   std::vector<string> v(2000);   vector<vector<int> > mark(2000);   set<pair<int, int> > ans;   int bfs(int x, int y) {     int m = x, n = y;     vector<pair<int, int> > q;     int i = 0;     while (v[x][y] !=  #  && mark[x][y] == -2) {       q.push_back(make_pair(x, y));       int Y = y, X = x;       Y -= (v[x][y] ==  < );       Y += (v[x][y] ==  > );       X -= (v[x][y] ==  ^ );       X += (v[x][y] ==  v );       mark[x][y] = -1;       x = X;       y = Y;     }     if (v[x][y] ==  # ) {       mark[x][y] = 0;       int cnt = 1;       for (i = q.size() - 1; i >= 0; i--) {         mark[q[i].first][q[i].second] = cnt + mark[x][y];         cnt++;       }     } else if (mark[x][y] == -1) {       for (i = 0; i < q.size(); i++) {         mark[q[i].first][q[i].second] = -1;       }     } else {       int cnt = 1;       for (i = q.size() - 1; i >= 0; i--) {         mark[q[i].first][q[i].second] = cnt + mark[x][y];         cnt++;       }     }     return mark[m][n];   }   void check() {     while (ans.size() != 1) {       vector<pair<int, int> > u;       set<pair<int, int> >::iterator it;       for (it = ans.begin(); it != ans.end(); it++) {         int x = (*it).first;         int y = (*it).second;         int X = x, Y = y;         Y -= (v[x][y] ==  < );         Y += (v[x][y] ==  > );         X -= (v[x][y] ==  ^ );         X += (v[x][y] ==  v );         if (v[X][Y] ==  # ) {           return;         }         u.push_back(make_pair(X, Y));       }       int i;       ans.clear();       for (i = 0; i < u.size(); i++) {         ans.insert(u[i]);       }     }   }   int main() {     int n, m;     cin >> n >> m;     int i, j;     for (i = 0; i < n; i++) {       cin >> v[i];     }     for (i = 0; i < n; i++) {       for (j = 0; j < m; j++) {         mark[i].push_back(-2);       }     }     int maxi = -100;     for (i = 0; i < n; i++) {       for (j = 0; j < m; j++) {         if (mark[i][j] == -2) {           int a = bfs(i, j);           if (a == -1) {             cout <<  -1  << endl;             return 0;           }           if (maxi < a) {             ans.clear();             maxi = a;             ans.insert(make_pair(i, j));           } else if (maxi == a) {             ans.insert(make_pair(i, j));           }         }       }     }     mark.clear();     check();     if (ans.size() == 1) {       if (v[(*(ans.begin())).first][(*(ans.begin())).second] ==  # )         cout <<  0  << endl;       else         cout << 2 * maxi - 1 << endl;     } else {       cout << 2 * maxi << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long add(long long n) {     long long mi = INT_MAX, ma = INT_MIN;     while (n > 0) {       mi = min(n % 10, mi);       ma = max(n % 10, ma);       n = n / 10;     }     return mi * ma;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     scanf( %d , &t);     while (t--) {       long long n, k;       scanf( %lld%lld , &n, &k);       k--;       while (k--) {         long long j = add(n);         n = n + j;         if (j == 0) {           break;         }       }       cout << n << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n, m, k, cntr = 1, s = 1;     cin >> n >> m >> k;     string str;     cin >> str >> str;     if (str ==  head ) cntr = -1;     cin >> str;     int l = str.length();     if (m < k) s = -1;     for (int i = 0; i < l; i++) {       if (str[i] ==  0 ) {         if (m != 1 && m != n) m += s;       } else {         if (cntr == 1)           m = 1;         else           m = n;       }       k += cntr;       if (k == n)         cntr = -1;       else if (k == 1)         cntr = 1;       if (m == k) {         cout <<  Controller   << i + 1 <<   n ;         return 0;       }     }     cout <<  Stowaway n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     long long sum, xr;     cin >> sum >> xr;     long long dp[2] = {1, 0};     for (int bit = 0; bit < 50; bit++) {       long long ndp[2] = {0, 0};       int needSum = (sum >> bit) & 1;       int needXor = (xr >> bit) & 1;       for (int was = 0; was < 2; was++) {         for (int b1 = 0; b1 < 2; b1++) {           for (int b2 = 0; b2 < 2; b2++) {             int mySum = (b1 + b2 + was) % 2;             int myXor = b1 ^ b2;             if (myXor == needXor && mySum == needSum) {               ndp[(b1 + b2 + was) >> 1] += dp[was];             }           }         }       }       for (int _n(2), i(0); i < _n; i++) dp[i] = ndp[i];     }     cout << (dp[0] - (sum == xr ? 2 : 0)) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline void splay(long long &v) {     v = 0;     char c = 0;     int p = 1;     while (c <  0  || c >  9 ) {       if (c ==  - ) p = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       v = (v << 3) + (v << 1) + c -  0 ;       c = getchar();     }     v *= p;   }   long long a[1000010];   long long dp[1000010], ans;   int main() {     long long n;     splay(n);     for (int i = 1; i <= n; i++) {       splay(a[i]);       a[i]--;     }     dp[1] = min(a[1], a[2]);     ans += a[1];     for (int i = 2; i <= n; i++) {       ans += a[i];       long long x = min(a[i], a[i - 1]);       long long y = min(x, a[i + 1]), z = min(a[i], a[i + 1]);       ans += dp[i - 1] * x;       dp[i] = dp[i - 1] * y + z;       ans %= 1000000007LL;       dp[i] %= 1000000007LL;     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2000010;   int main() {     int len, cnt;     char s, d, st[maxn], word[26];     cin >> len >> cnt;     cin >> st;     for (int i = 0; i < 26; ++i) {       word[i] =  a  + i;     }     for (int i = 1; i <= cnt; ++i) {       cin >> s >> d;       if (s == d) continue;       for (int j = 0; j < 26; ++j) {         if (word[j] == s)           word[j] = d;         else if (word[j] == d)           word[j] = s;       }     }     for (int i = 0; i < len; ++i) cout << word[st[i] -  a ];     cout << endl;     return 0;   }


#include <bits/stdc++.h>   const int N = 100010;   using ll = long long;   int a[N];   int main() {     int n, d, m;     scanf( %d%d%d , &n, &d, &m);     for (int i = 0; i < n; ++i) {       scanf( %d , &a[i]);     }     std::sort(a, a + n);     int last = n;     for (int i = 0; i < n; ++i) {       if (a[i] > m) {         last = i;         break;       }     }     std::sort(a, a + last, std::greater<int>());     ll ans = 0, sum = 0;     for (int i = 0; i < last; ++i) {       sum += a[i];     }     for (int i = last - 1, j = n - 1; i >= -1; --i) {       while (j >= last) {         int num = i + 1 + (n - j) * (d + 1) - d;         if (num > n) {           break;         }         sum += a[j--];       }       ans = std::max(ans, sum);       if (i >= 0) {         sum -= a[i];       }     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, arr[100];     cin >> n;     for (int i = 0; i < n; i++) {       cin >> arr[i];     }     for (int i = 0; i < n - 1; i++) {       for (int j = i; j < n; j++) {         if (arr[i] > arr[j]) {           int swap = arr[j];           arr[j] = arr[i];           arr[i] = swap;         }       }     }     for (int i = 0; i < n; i++) {       cout << arr[i] << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     while (n--) {       string s;       cin >> s;       if (s.length() > 10)         cout << s[0] << (s.length() - 2) << s[s.length() - 1] << endl;       else         cout << s << endl;     }   }


#include <bits/stdc++.h>   const int MAX_N = 1000000;   const int MOD = 1000000007;   std::vector<int> groups;   int table[1 + MAX_N], dp[1 + MAX_N];   std::deque<int> tablePositions;   int main() {     std::string s;     std::cin >> s;     groups.push_back(0);     int cnt = 0;     for (int i = 0; i < s.size(); ++i)       if (s[i] ==  0 )         ++cnt;       else {         groups.push_back(cnt);         cnt = 0;       }     groups.push_back(cnt);     dp[1] = groups[1] + 1;     for (int i = 2; i < groups.size(); ++i) {       if (i < groups.size() - 1) dp[i] = dp[i - 1];       for (int lastDigit = 0; lastDigit <= groups[i]; ++lastDigit) {         dp[i] = (dp[i] + dp[i - 1]) % MOD;         while (!tablePositions.empty() && tablePositions.front() < lastDigit)           tablePositions.pop_front();         if (i < groups.size() - 1 && !tablePositions.empty())           dp[i] = (dp[i] + MOD - table[tablePositions.front()]) % MOD;       }       tablePositions.push_front(groups[i]);       table[groups[i]] = dp[i - 1];     }     if (groups.size() == 2) dp[groups.size() - 1]--;     printf( %d , dp[groups.size() - 1]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 200200;   vector<int> adj[MAX];   int ch[MAX], sz, from[MAX], dpthMx[MAX], dpthMn[MAX], n;   void dfs(int cur, int par) {     for (auto i : adj[cur])       if (i != par) {         dfs(i, cur);         dpthMn[cur] = min(dpthMn[cur], dpthMn[i] + 1);         dpthMx[cur] = max(dpthMx[cur], dpthMx[i] + 1);       }     if (dpthMn[cur] == MAX) dpthMn[cur] = 0;   }   pair<int, int> dfs0(int cur, int par, int d) {     from[cur] = par;     pair<int, int> ret(d, cur);     for (auto i : adj[cur])       if (i != par) ret = max(ret, dfs0(i, cur, d + 1));     return ret;   }   int main() {     scanf( %d , &n);     fill(dpthMn, dpthMn + n + 1, MAX);     for (int i = 1, u, v; i < n; ++i) {       scanf( %d%d , &u, &v);       adj[u].push_back(v);       adj[v].push_back(u);     }     pair<int, int> diam = dfs0(dfs0(1, 0, 0).second, 0, 0);     while (diam.first > 0) diam.first -= 2, diam.second = from[diam.second];     dfs(diam.second, 0);     for (auto i : adj[diam.second]) {       if (dpthMx[i] != dpthMn[i]) return puts( -1 ), 0;       ch[sz++] = dpthMx[i] + 1;     }     sort(ch, ch + sz);     sz = unique(ch, ch + sz) - ch;     if (sz > 2) return puts( -1 ), 0;     ch[sz] = 0;     int ans = ch[0] + ch[1];     while (!(ans & 1)) ans >>= 1;     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 100005;   template <typename T>   void readv(vector<T>& v, int n) {     for (int i = 0; i < n; ++i) {       T tmp;       cin >> tmp;       v.push_back(tmp);     }   }   struct cmp {     bool operator()(const pair<int, int>& i1, const pair<int, int>& i2) const {       int sign = (i1.second - i1.first) - (i2.second - i2.first);       if (sign != 0) return sign > 0;       return i1.first > i2.first;     }   };   set<pair<int, int>, cmp> intervals;   map<int, pair<int, int> > ileft, iright;   void insert_intvl(const pair<int, int>& intvl) {     intervals.insert(intvl);     ileft[intvl.second + 1] = intvl;     iright[intvl.first - 1] = intvl;   }   void erase_intvl(const pair<int, int>& intvl) {     intervals.erase(intvl);     ileft.erase(intvl.second + 1);     iright.erase(intvl.first - 1);   }   map<int, int> points;   class node {    public:     node() : left(0), right(0), size(0) {}     node *left, *right;     int size;   };   node root;   void add_node(node* nd, int x, int shift) {     nd->size++;     if (shift < 0) {       return;     }     if ((x & (1 << shift)) == 0) {       if (!nd->left) {         nd->left = new node;       }       add_node(nd->left, x, shift - 1);     } else {       if (!nd->right) {         nd->right = new node;       }       add_node(nd->right, x, shift - 1);     }   }   void remove_node(node* nd, int x, int shift) {     nd->size -= 1;     if (shift < 0) return;     if ((x & (1 << shift)) == 0) {       remove_node(nd->left, x, shift - 1);     } else {       remove_node(nd->right, x, shift - 1);     }   }   int query_tree(node* nd, int b, int e, int l, int r, int shift) {     if ((e < l) || (b > r)) {       return 0;     }     if ((b >= l) && (e <= r)) {       return nd->size;     }     int mid = (b + e) / 2;     int s1 = nd->left ? query_tree(nd->left, b, mid, l, r, shift - 1) : 0;     int s2 = nd->right ? query_tree(nd->right, mid + 1, e, l, r, shift - 1) : 0;     return s1 + s2;   }   const int BITS = 30;   void add_emp(int e, int p) {     add_node(&root, p, BITS - 1);     points[e] = p;   }   void remove_emp(int e) {     remove_node(&root, points[e], BITS - 1);     points.erase(e);   }   int query(int l, int r) {     return query_tree(&root, 0, (1 << BITS) - 1, l, r, BITS);   }   int main(int argc, char** argv) {     int n, q;     cin >> n >> q;     intervals.insert(make_pair(1, n));     for (int i = 0; i < q; ++i) {       int e;       cin >> e;       if (e == 0) {         int l, r;         cin >> l >> r;         cout << query(l, r) << endl;       } else {         if (points.count(e) == 0) {           pair<int, int> longest = *intervals.begin();           erase_intvl(longest);           int mid = (longest.first + longest.second + 1) / 2;           if (longest.first <= (mid - 1)) {             insert_intvl(make_pair(longest.first, mid - 1));           }           if ((mid + 1) <= longest.second) {             insert_intvl(make_pair(mid + 1, longest.second));           }           add_emp(e, mid);         } else {           int pe = points[e];           pair<int, int> intvl = make_pair(pe, pe);           if (ileft.count(pe) == 1) {             intvl.first = ileft[pe].first;             erase_intvl(ileft[pe]);           }           if (iright.count(pe) == 1) {             intvl.second = iright[pe].second;             erase_intvl(iright[pe]);           }           insert_intvl(intvl);           remove_emp(e);         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void file_io() {     freopen( input.txt ,  r , stdin);     freopen( output.txt ,  w , stdout);   }   void PLAY() {     ios_base::sync_with_stdio(false);     cin.tie(0), cout.tie(0);   }   int main() {     PLAY();     int n;     cin >> n;     int x[1000000] = {0};     for (int i = 0; i < n - 1; i++) {       int l, r;       cin >> l >> r;       x[l]++;       x[r]++;     }     for (int i = 1; i <= n; i++) {       if (x[i] == 2) return cout <<  NO , 0;     }     cout <<  YES ;   }


#include <bits/stdc++.h>   using namespace std;   long long n;   int licznik;   long long sym(long long k) {     long long eat = k, m = n - k;     while (m > 0) {       licznik++;       m -= m / 10;       eat += min(k, m);       m -= k;     }     return eat;   }   long long binsuche(long long lewy, long long prawy) {     if (lewy < prawy) {       if (sym((lewy + prawy) / 2) * 2 >= n)         return binsuche(lewy, (lewy + prawy) / 2);       else         return binsuche((lewy + prawy) / 2 + 1, prawy);     }     return lewy;   }   int main() {     licznik = 0;     int a, b;     cin >> n;     cout << binsuche(1, n);   }


#include <bits/stdc++.h>   using namespace std;   const int N = 5e5 + 10, INF = 1e9;   inline int read() {     int x = 0, f = 1;     char ch = getchar();     while (!isdigit(ch)) {       if (ch ==  - ) f = -f;       ch = getchar();     }     while (isdigit(ch)) {       x = x * 10 + ch - 48;       ch = getchar();     }     return x * f;   }   int n, l[N], r[N], a[N], b[N], c[N];   int ans, sum, pos, cnt, tot;   int t1, t2;   signed main() {     n = read();     for (int i = 1; i <= n; i++) {       l[i] = read();       r[i] = read();       a[++cnt] = l[i];       a[++cnt] = r[i];     }     sort(a + 1, a + cnt + 1);     for (int i = 1; i <= cnt; i++)       if (i == 1 || a[i] != a[i - 1]) a[++tot] = a[i];     for (int i = 1; i <= n; i++) {       t1 = lower_bound(a + 1, a + tot + 1, l[i]) - a;       t2 = lower_bound(a + 1, a + tot + 1, r[i]) - a;       c[t1] = l[i], c[t2] = r[i];       b[t1]++, b[t2]--;     }     for (int i = 1; i <= tot; i++) {       sum += b[i];       if (sum > ans) ans = sum, pos = c[i];     }     printf( %d %d , pos, ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   double a, b, c;   int main() {     while (~scanf( %lf%lf%lf , &a, &b, &c)) {       double x1 = (-b + sqrt(b * b - 4 * a * c)) / (2 * a),              x2 = (-b - sqrt(b * b - 4 * a * c)) / (2 * a);       if (a < 0) swap(x1, x2);       printf( %.6lf n%.6lf n , x1, x2);     }     return 0;     ;   }


#include <bits/stdc++.h>   using namespace std;   void _fill_int(int* p, int val, int rep) {     int i;     for (i = 0; i < rep; i++) p[i] = val;   }   signed long long GETi() {     signed long long i;     scanf( %lld , &i);     return i;   }   int N, X, Y;   int mat[501][501];   int vis[501][501];   int LM[501], RM[501], TM[501], BM[501];   char str[3000002];   char* P;   void dfs(int cy, int cx, int pre, bool on) {     char move[16] =  *LR*U***D ;     int i;     if (on && (mat[cy][cx] & 1) == 0) *P++ =  1 ;     if ((vis[cy][cx] & 1) && (pre != 1)) *P++ =  L , dfs(cy, cx - 1, 2, on);     if ((vis[cy][cx] & 2) && (pre != 2)) *P++ =  R , dfs(cy, cx + 1, 1, on);     if ((vis[cy][cx] & 4) && (pre != 4)) *P++ =  U , dfs(cy - 1, cx, 8, on);     if ((vis[cy][cx] & 8) && (pre != 8)) *P++ =  D , dfs(cy + 1, cx, 4, on);     if (!on) *P++ =  2 ;     if (pre != 0) *P++ = move[pre];   }   void solve() {     int f, i, j, k, l, x, y;     cin >> N >> Y >> X;     X--;     Y--;     for (y = 0; y < N; y++)       for (x = 0; x < N; x++) cin >> mat[y][x];     for (y = 0; y < N; y++) LM[y] = TM[y] = N, RM[y] = BM[y] = -1;     l = 0;     mat[Y][X] |= 2;     for (y = 0; y < N; y++)       for (x = 0; x < N; x++)         if (mat[y][x]) {           l++;           if (LM[y] > x) LM[y] = x;           RM[y] = x;           if (TM[x] > y) TM[x] = y;           BM[x] = y;         }     if (l == 1 && (mat[Y][X] & 1)) return (void)printf( YES n2 n );     P = str;     stack<int> Q;     Q.push(Y * 1000 + X);     while (!Q.empty()) {       int k = Q.top();       Q.pop();       int cx = k % 1000, cy = k / 1000;       TM[cx] = min(TM[cx], cy);       BM[cx] = max(BM[cx], cy);       LM[cy] = min(LM[cy], cx);       RM[cy] = max(RM[cy], cx);       for (i = 0; i < 4; i++) {         int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};         int tx = cx + dx[i], ty = cy + dy[i];         if (tx < 0 || ty < 0 || tx >= N || ty >= N) continue;         if (dy[i] > 0 && BM[cx] < ty) continue;         if (dy[i] < 0 && TM[cx] > ty) continue;         if (dx[i] > 0 && RM[cy] < tx) continue;         if (dx[i] < 0 && LM[cy] > tx) continue;         if (mat[ty][tx] & 2) continue;         mat[ty][tx] |= 2;         if (dx[i] < 0) vis[cy][cx] |= 1, vis[ty][tx] |= 2;         if (dx[i] > 0) vis[cy][cx] |= 2, vis[ty][tx] |= 1;         if (dy[i] < 0) vis[cy][cx] |= 4, vis[ty][tx] |= 8;         if (dy[i] > 0) vis[cy][cx] |= 8, vis[ty][tx] |= 4;         Q.push(ty * 1000 + tx);       }     }     for (y = 0; y < N; y++)       for (x = 0; x < N; x++)         if (mat[y][x] == 1) return (void)printf( NO n );     dfs(Y, X, 0, true);     dfs(Y, X, 0, false);     (void)printf( YES n%s n , str);   }   int main(int argc, char** argv) {     if (argc > 1) freopen(argv[1],  r , stdin);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long inf = 1e18;   const long long mod = 998244353;   const long long maxn = 5e4 + 10, maxval = 1e9 + 10, mlg = (1 << 18) + 10;   struct edge {     long long u, v, c, t;   } ed[maxn * 6];   long long n, m, cnt;   long long ans[maxn * 6], comp[maxn * 6], mark1[6 * maxn], mark2[6 * maxn];   vector<long long> ts, nei[maxn * 6][2], adj[maxn * 6];   map<long long, long long> mp;   long long N(long long x) {     if (x <= m) {       return x + m;     } else if (x <= 2 * m) {       return x - m;     } else if (x <= 4 * m) {       return x + 2 * m;     } else {       return x - 2 * m;     }   }   void add_con(long long x, long long y) {     long long nagh_x = N(x);     long long nagh_y = N(y);     nei[nagh_x][1].push_back(y);     nei[y][0].push_back(nagh_x);     nei[nagh_y][1].push_back(x);     nei[x][0].push_back(nagh_y);   }   void dfs1(long long u) {     mark1[u] = 1;     for (auto v : nei[u][1]) {       if (!mark1[v]) {         dfs1(v);       }     }     ts.push_back(u);   }   void dfs2(long long u) {     mark2[u] = 1;     comp[u] = cnt;     for (auto v : nei[u][0]) {       if (!mark2[v]) {         dfs2(v);       }     }   }   bool ch(long long x) {     long long tmp_cnt = 0;     cnt = 0;     for (int i = 0; i <= 6 * m; i++) {       nei[i][1].clear();       nei[i][0].clear();       comp[i] = 0;       mark1[i] = 0;       mark2[i] = 0;       ans[i] = 0;     }     for (int i = 0; i < m; i++) {       if (ed[i + 1].t > x) {         nei[i + 1][1].push_back(i + 1 + m);         nei[i + 1 + m][0].push_back(i + 1);       }     }     for (int i = 1; i <= n; i++) {       mp.clear();       for (int j = 0; j < adj[i].size(); j++) {         tmp_cnt++;         if (j > 0) {           add_con(N(2 * m + tmp_cnt - 1), N(adj[i][j]));           add_con(N(2 * m + tmp_cnt - 1), 2 * m + tmp_cnt);           add_con(N(adj[i][j]), 2 * m + tmp_cnt);         } else {           add_con(N(adj[i][j]), 2 * m + tmp_cnt);         }         if (!mp[ed[adj[i][j]].c]) {           mp[ed[adj[i][j]].c] = adj[i][j];         } else if (mp[ed[adj[i][j]].c] == -1) {           return false;         } else {           add_con(adj[i][j], mp[ed[adj[i][j]].c]);           mp[ed[adj[i][j]].c] = -1;         }       }     }     for (int i = 1; i <= 6 * m; i++) {       if (!mark1[i]) {         dfs1(i);       }     }     while (!ts.empty()) {       long long v = ts.back();       ts.pop_back();       if (!mark2[v]) {         cnt++;         dfs2(v);       }     }     for (int i = 1; i <= m; i++) {       if (comp[i] == comp[i + m]) {         return false;       }       if (comp[i] > comp[i + m]) {         ans[i] = 1;       } else {         ans[i] = 0;       }     }     for (int i = 2 * m + 1; i <= 4 * m; i++) {       if (comp[i] == comp[i + 2 * m]) {         return false;       }     }     return true;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     cin >> n >> m;     for (int i = 0; i < m; i++) {       cin >> ed[i + 1].u >> ed[i + 1].v >> ed[i + 1].c >> ed[i + 1].t;       adj[ed[i + 1].u].push_back(i + 1);       adj[ed[i + 1].v].push_back(i + 1);     }     long long l = -1, r = inf;     while (r - l > 1) {       long long mid = (l + r) / 2;       if (ch(mid)) {         r = mid;       } else {         l = mid;       }     }     if (r == inf) {       cout <<  No  << endl;       return 0;     }     cout <<  Yes  << endl;     ch(r);     long long tmp = 0;     for (int i = 0; i < m; i++) {       if (ans[i + 1]) {         tmp++;       }     }     cout << r <<     << tmp << endl;     for (int i = 0; i < m; i++) {       if (ans[i + 1]) {         cout << i + 1 <<    ;       }     }     cout << endl;   }


#include <bits/stdc++.h>   #pragma optimization_level 3   #pragma GCC optimize( Ofast,no-stack-protector,unroll-loops,fast-math,O3 )   using namespace std;   mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());   int main() {     cin.tie(0);     cout.tie(0);     cin.sync_with_stdio(0);     cout.sync_with_stdio(0);     ;     long long z;     cin >> z;     for (; z--;) {       long long a;       cin >> a;       vector<string> m(a);       int can[a];       set<string> s;       for (int q = 0; q < a; q++) {         cin >> m[q];         s.insert(m[q]);       }       for (int q = 0; q < a; q++) {         reverse(m[q].begin(), m[q].end());         can[q] = !s.count(m[q]);         reverse(m[q].begin(), m[q].end());       }       long long fl = 1;       vector<long long> n, t(4), msk(a);       int i = 0;       for (string &u : m) {         int mask = (u[0] ==  1 ) * 2 + (u.back() ==  1 ) * 1;         t[mask]++;         msk[i++] = mask;       }       if (!(t[1] + t[2]))         fl = t[0] == a || t[3] == a;       else {         long long ABS = abs(t[1] - t[2]), nd = t[2] > t[1] ? 2 : 1;         for (int q = 0; q < a && ABS > 1; q++) {           if (msk[q] != nd || !can[q]) continue;           ABS -= 2;           n.push_back(q + 1);         }         fl = ABS < 2;       }       if (!fl)         cout <<  -1 n ;       else {         cout << n.size() <<   n ;         for (long long i : n) cout << i <<    ;         cout <<   n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   ;   vector<pair<int, int>> vec;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n, k, a, b, c;     c = 1;     cin >> n >> k;     for (int i = 0; i < n; i++) {       cin >> a >> b;       vec.push_back(make_pair(a * -1, b));     }     sort(vec.begin(), vec.end());     for (int i = 0; i < n; i++) {       if (i == k - 1) {         while (vec[i] == vec[i + 1]) {           i++;           c++;         }         cout << c <<   n ;         break;       }       if (vec[i] == vec[i + 1])         c++;       else         c = 1;     }     cout.flush();   }


#include <bits/stdc++.h>   using namespace std;   struct node {     int x, y, id;     bool operator<(const node &A) const { return x < A.x; }   };   vector<node> line[2][100005 << 2];   bool mark[2][100005 << 2];   int n, m, k;   long long t[100005];   void add(int x, int y, int i) {     node a;     a.x = x, a.y = y, a.id = i;     line[1][y - x + 200000].push_back(a);     line[0][x + y + 200000].push_back(a);   }   void solve() {     bool flag = 0, first = 0;     long long res = 0;     int k = 1;     int x = 0, y = 0;     while (!flag) {       if (x == 0 || y == 0 || x == n || y == m) {         if (first) {           if ((x == 0 || x == n) && (y == 0 || y == m)) {             flag = 1;             break;           }           k = -k;         } else           first = 1;       }       int cur = (k == 1);       if (line[cur][y - k * x + 200000].size()) {         if (mark[cur][y - k * x + 200000])           flag = 1;         else {           mark[cur][y - k * x + 200000] = 1;           if (k == 1 && (!x || !y) || k == -1 && ((!x && y) || (y == m && x))) {             for (int i = 0; i < line[cur][y - k * x + 200000].size(); i++) {               int j = line[cur][y - k * x + 200000][i].id;               node tmp = line[cur][y - k * x + 200000][i];               if (t[j]) {               } else                 t[j] = res + abs(line[cur][y - k * x + 200000][i].x - x);             }           } else {             for (int i = line[cur][y - k * x + 200000].size() - 1; i >= 0; i--) {               int j = line[cur][y - k * x + 200000][i].id;               node tmp = line[cur][y - k * x + 200000][i];               if (t[j]) {               } else                 t[j] = res + abs(line[cur][y - k * x + 200000][i].x - x);             }           }         }       }       int nx1, ny1, nx2, ny2, t1 = x, t2 = y;       if (k == 1) {         if (0 <= n + y - x && n + y - x <= m)           nx1 = n, ny1 = n + y - x;         else           ny1 = m, nx1 = m + x - y;         if (0 <= y - x && y - x <= m)           nx2 = 0, ny2 = y - x;         else           ny2 = 0, nx2 = x - y;         if (nx1 == x) {           x = nx2, y = ny2;         } else           x = nx1, y = ny1;       } else {         if (0 <= x + y && x + y <= m)           nx1 = 0, ny1 = x + y;         else           ny1 = m, nx1 = x + y - m;         if (0 <= x + y - n && x + y - n <= m)           nx2 = n, ny2 = x + y - n;         else           ny2 = 0, nx2 = x + y;         if (nx1 == x) {           x = nx2, y = ny2;         } else           x = nx1, y = ny1;       }       res += abs(x - t1);     }   }   inline void print(long long x) {     if (!x) return;     print(x / 10);     putchar(x % 10 ^ 48);   }   inline void pf(long long x) {     print(x);     if (!x)       puts( 0 );     else       puts(  );   }   inline void rd(int &res) {     res = 0;     char c;     while (c = getchar(), c <  0  || c >  9 )       ;     do {       res = (res << 3) + (res << 1) + (c ^ 48);     } while (c = getchar(),  0  <= c && c <=  9 );   }   int main() {     rd(n);     rd(m);     rd(k);     for (int i = 1; i <= k; i++) {       int a, b;       rd(a);       rd(b);       add(a, b, i);     }     for (int i = 0; i < 2; i++)       for (int j = 0; j < 2 * 100005; j++) {         if (line[i][j].size()) {           sort(line[i][j].begin(), line[i][j].end());         }       }     solve();     for (int i = 1; i <= k; i++) {       if (t[i])         pf(t[i]);       else         puts( -1 );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, i, ctr = 0, j;     int arr[1000];     cin >> n;     for (i = 0; i < n; i++) cin >> arr[i];     for (i = 0; i < n; i++)       if (arr[i] == 1) break;     if (i == n) {       cout << 0;       return 0;     }     for (j = n - 1; j >= 0; j--)       if (arr[j] == 1) break;     if (i == j) {       cout << 1;       return 0;     }     ctr = 1;     for (int k = i + 1; k <= j; k++) {       if (arr[k] == 1)         ctr++;       else if (arr[k] == 0 && arr[k - 1] == 1 && arr[k + 1] == 1)         ctr++;     }     cout << ctr;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   #pragma warning(disable : 4996)   const double eps = 1e-7;   struct node {     long long first;     node() {}     node(long long first) : first(first) {}     bool operator<(const node& a) const { return first < a.first; }   };   int dx[4] = {-1, 1, 0, 0};   int dy[4] = {0, 0, -1, 1};   const long long N = 6010;   long long mod = 1e9 + 7;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) {       int n, k;       cin >> n >> k;       long long tmp = 0;       long long ans = 0;       priority_queue<node> q;       for (int i = 1; i <= n * k; i++) {         cin >> tmp;         node tt(tmp);         q.push(tt);       }       int cnt = 0;       if (n & 1) {         for (int i = 1; i <= k; i++) {           for (int j = 1; j <= (n + 1) / 2; j++) {             if (j == (n + 1) / 2) {               ans += q.top().first;               cnt++;             }             q.pop();           }         }       } else {         for (int i = 1; i <= k; i++) {           for (int j = 1; j <= n / 2 + 1; j++) {             if (j == n / 2 + 1) {               ans += q.top().first;               cnt++;             }             q.pop();           }         }       }       cout << ans <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int d[] = {25, 18, 15, 12, 10, 8, 6, 4, 2, 1};   int t, n, k;   struct edge {     string name;     int s, win[50];   } a[100];   bool cmp1(edge x, edge y) {     if (x.s != y.s) {       return x.s > y.s;     }     for (int i = 0; i < 50; i++) {       if (x.win[i] != y.win[i]) {         return x.win[i] > y.win[i];       }     }     return false;   }   bool cmp2(edge x, edge y) {     if (x.win[0] != y.win[0]) {       return x.win[0] > y.win[0];     } else {       return cmp1(x, y);     }   }   int main() {     cin >> t;     while (t--) {       cin >> n;       string name;       for (int i = 0; i < n; i++) {         cin >> name;         bool flag = false;         for (int j = 0; j < k; j++) {           if (a[j].name == name) {             if (i < 10) {               a[j].s += d[i];             }             a[j].win[i]++;             flag = true;             break;           }         }         if (flag == false) {           a[k].name = name;           if (i < 10) {             a[k].s = d[i];           }           a[k].win[i]++;           k++;         }       }     }     sort(a, a + k, cmp1);     cout << a[0].name << endl;     sort(a, a + k, cmp2);     cout << a[0].name;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char ch[200][200];   int rp[200], cp[200];   int main() {     int n;     while (cin >> n) {       memset(rp, 0, sizeof(rp));       memset(cp, 0, sizeof(cp));       for (int i = 1; i <= n; i++) {         scanf( %s , ch[i] + 1);         for (int j = 1; j <= n; j++)           if (ch[i][j] ==  . ) rp[i] = 1;       }       for (int i = 1; i <= n; i++)         for (int j = 1; j <= n; j++)           if (ch[j][i] ==  . ) cp[i] = 1;       bool rok, cok;       rok = cok = 0;       int k;       for (k = 1; k <= n; k++)         if (rp[k] == 0) break;       if (k > n) rok = 1;       for (k = 1; k <= n; k++)         if (cp[k] == 0) break;       if (k > n) cok = 1;       if (rok == 0 && cok == 0) {         puts( -1 );         continue;       }       if (rok) {         for (int i = 1; i <= n; i++) {           for (int j = 1; j <= n; j++)             if (ch[i][j] ==  . ) {               cout << i <<     << j << endl;               break;             }         }       } else {         for (int i = 1; i <= n; i++) {           for (int j = 1; j <= n; j++)             if (ch[j][i] ==  . ) {               cout << j <<     << i << endl;               break;             }         }       }     }     return 0;   }


#include <bits/stdc++.h>   long n, m, x, y, i, a[1000], z;   double aa, bb, sum;   int main() {     scanf( %ld%ld , &n, &m);     for (i = 1; i <= n; i++) scanf( %ld , &a[i]);     sum = 0;     for (i = 1; i <= m; i++) {       scanf( %ld%ld%ld , &x, &y, &z);       aa = a[x] + a[y];       bb = z;       if (aa / bb > sum) {         sum = aa / bb;       }     }     printf( %0.15lf , sum);   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using vi = vector<int>;   using pii = pair<int, int>;   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     int tests;     cin >> tests;     for (int test = 0; test < tests; ++test) {       int n;       cin >> n;       vector<ll> a(n);       for (int i = 0; i < n; ++i) cin >> a[i];       ll x, y;       int fx, fy;       cin >> x >> fx >> y >> fy;       ll req;       cin >> req;       int lo = 1, hi = n + 1;       for (int i = 0; i < n; ++i) a[i] /= 100;       sort(a.begin(), a.end());       reverse(a.begin(), a.end());       while (lo < hi) {         int mid = (lo + hi) / 2;         vector<ll> c(mid);         for (int i = 0; i < mid; ++i) {           if (i % fx == fx - 1) c[i] += x;           if (i % fy == fy - 1) c[i] += y;         }         sort(c.begin(), c.end());         reverse(c.begin(), c.end());         ll sum = 0;         for (int i = 0; i < mid; ++i) sum += a[i] * c[i];         if (sum >= req)           hi = mid;         else           lo = mid + 1;       }       if (lo == n + 1) lo = -1;       cout << lo <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e5 + 100;   vector<int> adj[MAXN], *vec[MAXN];   int col[MAXN], pw[MAXN], goni[MAXN], sz[MAXN];   long long sum[MAXN];   void getsz(int v = 1, int pre = -1) {     sz[v] = 1;     for (auto u : adj[v]) {       if (u != pre) {         getsz(u, v);         sz[v] += sz[u];       }     }   }   void dfs(int v, int pre, bool type) {     int idx = -1;     int bigchild = -1;     for (auto i : adj[v])       if (sz[i] > idx && i != pre) idx = sz[i], bigchild = i;     for (auto i : adj[v])       if (i != bigchild && i != pre) dfs(i, v, 0);     if (bigchild != -1) {       dfs(bigchild, v, 1);       vec[v] = vec[bigchild];       sum[v] = sum[bigchild];       pw[v] = pw[bigchild];     } else       vec[v] = new vector<int>();     vec[v]->push_back(v);     goni[col[v]]++;     if (goni[col[v]] == pw[v])       sum[v] += col[v];     else if (goni[col[v]] > pw[v]) {       sum[v] = col[v];       pw[v] = goni[col[v]];     }     for (auto i : adj[v])       if (i != bigchild && i != pre)         for (auto j : *vec[i]) {           goni[col[j]]++;           vec[v]->push_back(j);           if (goni[col[j]] == pw[v])             sum[v] += col[j];           else if (goni[col[j]] > pw[v]) {             sum[v] = col[j];             pw[v] = goni[col[j]];           }         }     if (!type)       for (auto u : *vec[v]) goni[col[u]]--;   }   int main() {     int n;     cin >> n;     for (int i = 1; i <= n; ++i) cin >> col[i];     for (int i = 0; i < n - 1; ++i) {       int x, y;       cin >> x >> y;       adj[x].push_back(y);       adj[y].push_back(x);     }     getsz();     dfs(1, -1, 0);     for (int i = 1; i <= n; ++i) cout << sum[i] <<    ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t, n, k, tmp;     vector<long long> ans;     vector<int> vec;     cin >> t;     while (t--) {       cin >> n >> k;       for (int i = 0; i < n * k; i++) {         cin >> tmp;         vec.push_back(tmp);       }       int med;       if (n % 2 == 0)         med = n / 2;       else         med = n / 2 + 1;       long long medSum = 0;       int pos = vec.size() - (n - med) - 1;       for (int i = 0; i < k; i++) {         medSum += (long long)vec[pos];         pos -= (n - med + 1);       }       ans.push_back(medSum);       vec.clear();     }     for (int i = 0; i < ans.size(); i++) cout << ans[i] << endl;   }


#include <bits/stdc++.h>   using namespace std;   int t, n, k;   void solve() {     scanf( %d%d , &n, &k);     if (n < k) {       printf( NO n );       return;     }     if ((n - (k - 1)) % 2 == 1) {       printf( YES n );       for (int i = 1; i <= k - 1; ++i) printf( 1  );       printf( %d n , n - (k - 1));     } else if ((n - (k - 1) * 2) > 0 && (n - (k - 1) * 2) % 2 == 0) {       printf( YES n );       for (int i = 1; i <= k - 1; ++i) printf( 2  );       printf( %d n , n - (k - 1) * 2);     } else       printf( NO n );   }   int main() {     scanf( %d , &t);     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, Q;   const int md = 998244353;   const int maxn = 200010;   int t[4 * maxn], tmul[4 * maxn], tadd[4 * maxn];   inline int mod(long long x) { return (x % md + md) % md; }   void build(int v, int vl, int vr) {     tmul[v] = 1, tadd[v] = 0;     if (vl == vr) return;     int vm = (vl + vr) >> 1;     build(2 * v, vl, vm);     build(2 * v + 1, vm + 1, vr);   }   void push(int v, int vl, int vr) {     t[v] = mod(mod(1ll * tmul[v] * t[v]) + mod(1ll * tadd[v] * (vr - vl + 1)));     if (vl != vr) {       tmul[2 * v] = mod(1ll * tmul[2 * v] * tmul[v]);       tmul[2 * v + 1] = mod(1ll * tmul[2 * v + 1] * tmul[v]);       tadd[2 * v] = mod(1ll * tadd[2 * v] * tmul[v] + tadd[v]);       tadd[2 * v + 1] = mod(1ll * tadd[2 * v + 1] * tmul[v] + tadd[v]);     }     tmul[v] = 1;     tadd[v] = 0;   }   void update(int v, int vl, int vr, int l, int r, int m, int a) {     push(v, vl, vr);     if (l > vr || r < vl) return;     if (l <= vl && vr <= r) {       tmul[v] = m;       tadd[v] = a;       push(v, vl, vr);       return;     }     int vm = (vl + vr) >> 1;     update(2 * v, vl, vm, l, r, m, a);     update(2 * v + 1, vm + 1, vr, l, r, m, a);     t[v] = (t[2 * v] + t[2 * v + 1]) % md;   }   int getsum(int v, int vl, int vr, int l, int r) {     push(v, vl, vr);     if (l > vr || r < vl) return 0;     if (l <= vl && vr <= r) return t[v];     int vm = (vl + vr) >> 1;     return mod(getsum(2 * v, vl, vm, l, r) + getsum(2 * v + 1, vm + 1, vr, l, r));   }   set<pair<int, int>> q[maxn];   int main() {     ios_base::sync_with_stdio(false);     cin >> n >> Q;     build(1, 0, n - 1);     for (int i = 0; i < Q; i++) {       int t, l, r;       cin >> t >> l >> r;       --l, --r;       if (t == 1) {         int x;         cin >> x;         auto itl = q[x].lower_bound({l + 1, 0});         if (itl != q[x].begin()) {           --itl;           if (itl->second >= l) {             int ll = itl->first, rr = itl->second;             q[x].erase(itl);             if (ll <= l - 1) q[x].insert({ll, l - 1});             q[x].insert({l, rr});           }         }         auto itr = q[x].lower_bound({r + 1, 0});         if (itr != q[x].begin()) {           --itr;           if (itr->second >= r) {             int ll = itr->first, rr = itr->second;             q[x].erase(itr);             if (r + 1 <= rr) q[x].insert({r + 1, rr});             q[x].insert({ll, r});           }         }         int prev = l;         while (true) {           auto it = q[x].lower_bound({l, 0});           if (it == q[x].end() || it->first > r) break;           int ll = it->first, rr = it->second;           q[x].erase(it);           if (prev <= ll - 1) update(1, 0, n - 1, prev, ll - 1, 1, 1);           update(1, 0, n - 1, ll, rr, 2, 0);           prev = rr + 1;         }         if (prev <= r) update(1, 0, n - 1, prev, r, 1, 1);         q[x].insert({l, r});       } else {         cout << getsum(1, 0, n - 1, l, r) <<   n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   long long int M = 1e9 + 7;   int sum_digit(int x) {     int sum = 0;     while (x > 0) {       sum += x % 10;       x /= 10;     }     return sum;   }   int reverse_num(int n) {     int tmp = n, ans = 0, r;     while (tmp > 0) {       r = tmp % 10;       ans = ans * 10 + r;       tmp /= 10;     }     return ans;   }   long long int factorial(long long int n) {     long long int i, ans = 1;     for (i = n; i > 1; i--) {       ans *= i;     }     return ans;   }   long long int gcd(long long int num1, long long int num2) {     long long int a, b, r;     a = num1;     b = num2;     r = a % b;     while (r > 0) {       a = b;       b = r;       r = a % b;     }     return b;   }   long long int lcm(long long int num1, long long int num2) {     return (num1 * num2) / gcd(num1, num2);   }   bool prime(long long int n) {     if (n < 2) return false;     for (long long int i = 2; i <= sqrt(n); i++) {       if (n % i == 0) return false;     }     return true;   }   bool vowel(char ch) {     ch = tolower(ch);     if (ch ==  a  || ch ==  e  || ch ==  i  || ch ==  o  || ch ==  u )       return true;     return false;   }   void solve() {     double d, h, v, e;     cin >> d >> h >> v >> e;     double r = d / 2;     double v_in = 2 * acos(0) * r * r * h;     double L = 0, R = 1e4 + 10;     double ans = 0;     while (L < R) {       double t = L + (R - L) / 2;       double dif = (v_in + 2 * acos(0) * r * r * e * t) - v * t;       if (abs(dif) < 1e-4) {         ans = t;         break;       }       if (dif < 0)         R = t;       else         L = t;     }     if (ans != 0) {       cout <<  YES n ;       cout << setprecision(12) << fixed << ans << endl;     } else       cout <<  NO n ;   }   int main() {     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   vector<int> adjlist[1000050], ans;   bool done[1000050], use[1000050];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> n >> m;     for (int i = 0; i < m; i++) {       int a, b;       cin >> a >> b;       adjlist[a].push_back(b);     }     for (int i = 1; i <= n; i++) {       if (!done[i]) {         use[i] = true;         for (auto j : adjlist[i]) done[j] = true;       }     }     memset(done, false, sizeof done);     for (int i = n; i >= 1; i--) {       if (use[i] and !done[i]) {         ans.push_back(i);         done[i] = true;         for (auto j : adjlist[i]) done[j] = true;       }     }     cout << ans.size() <<   n ;     for (auto i : ans) cout << i <<    ;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7, inf = 1e17, N = 1e6 + 10;   bool vowel(char che) {     if (che ==  A  || che ==  E  || che ==  I  || che ==  O  || che ==  U  ||         che ==  Y ) {       return true;     } else {       return false;     }   }   long long pw(long long a, long long b) {     long long ans = 1;     while (b) {       if (b % 2 == 1) {         ans = 1ll * ans * a;         ans %= mod;       }       b /= 2;       a = 1ll * a * a % mod;       a %= mod;     }     return ans % mod;   }   bool mark[N], ok[N], h;   char o;   pair<long long, long long> p;   vector<long long> vt[N], vec, jav, vs;   string s, s1;   int64_t a[N], b[N], c[N], d, dp, t, n, m, k, f, ans1, sum, ps;   int64_t fuc[N];   int64_t ans;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie();     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];       a[i] %= mod;     }     fuc[0] = 1;     for (int i = 1; i <= n; i++) {       fuc[i] = 1ll * fuc[i - 1] * i;       fuc[i] %= mod;     }     sort(a, a + n);     f = 1;     a[n] = -25;     ans = 0;     for (int i = 1; i <= n; i++) {       if (a[i] == a[i - 1])         f++;       else {         if (i != n) {           f %= mod;           k = fuc[n] * pw((n - i + f), mod - 2);           k %= mod;           k *= f;           k %= mod;           ans += 1ll * k * a[i - 1];         }         ans %= mod;         f = 1;       }     }     cout << (ans + mod) % mod << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long N, M;     cin >> N >> M;     set<long long> x_t;     set<long long> y_t;     vector<long long> ans;     for (long long i = 0; i < M; i++) {       long long x, y;       cin >> x >> y;       if (x_t.find(x) == x_t.end()) x_t.insert(x);       if (y_t.find(y) == y_t.end()) y_t.insert(y);       long long tam_x = x_t.size();       long long tam_y = y_t.size();       ans.push_back(N * N - (tam_x + tam_y) * N + (tam_x * tam_y));     }     for (long long i = 0; i < ans.size() - 1; i++) cout << ans[i] <<    ;     cout << ans[ans.size() - 1] <<   n ;     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   vector<int> divi[2002];   long long dp[2002][2002];   int main() {     int n, k;     cin >> k >> n;     int i, j;     for (i = 1; i <= k; i++) {       for (j = i; j <= k; j += i) divi[i].push_back(j);     }     for (i = 1; i <= n; i++) {       for (j = 1; j <= k; j++) {         if (i == 1)           dp[i][j] = 1;         else {           for (int x : divi[j]) dp[i][j] += dp[i - 1][x], dp[i][j] %= 1000000007;         }       }     }     long long ans = 0;     for (i = 1; i <= k; i++) ans += dp[n][i], ans %= 1000000007;     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     scanf( %d , &n);     long long int mx = n * n;     for (int i = 1, j = mx; i < j; i++, j--) {       cout << i <<     << j << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 105, M = N * N * N;   int n, pos, l, r, i, j, k, f[N][N][N], h, t, q[M][3], ans;   inline void ext(int x, int y, int z, int d) {     if (y > z) return;     if (y > l || z < r) return;     if (x < y || x > z) return;     if (~f[x][y][z]) return;     f[x][y][z] = d;     q[++t][0] = x;     q[t][1] = y;     q[t][2] = z;   }   int main() {     scanf( %d%d%d%d , &n, &pos, &l, &r);     for (i = 1; i <= n; i++)       for (j = 1; j <= l; j++)         for (k = r; k <= n; k++) f[i][j][k] = -1;     h = 1;     t = 0;     ext(pos, 1, n, 0);     while (h <= t) {       int x, y, z, w;       x = q[h][0];       y = q[h][1];       z = q[h++][2];       w = f[x][y][z] + 1;       ext(x - 1, y, z, w);       ext(x + 1, y, z, w);       ext(x, x, z, w);       ext(x, y, x, w);     }     ans = ~0U >> 1;     for (i = 1; i <= n; i++)       if (~f[i][l][r]) ans = min(ans, f[i][l][r]);     printf( %d , ans);   }


#include <bits/stdc++.h>   int32_t gcd(int32_t a, int32_t b) {     if (b == 0) return a;     return gcd(b, a % b);   }   int32_t mpf(int32_t n, std::vector<int32_t>& primes) {     for (int32_t i = 0; i < primes.size(); i++)       if (n % primes[i] == 0) return primes[i];     return 1;   }   int main() {     int32_t num_tests;     std::cin >> num_tests;     for (int32_t t = 0; t < num_tests; t++) {       int32_t n;       std::cin >> n;       int32_t n2 = n;       std::vector<int32_t> primes;       std::map<int32_t, int32_t> powers;       for (int32_t i = 2; i * i <= n2; i++)         if (n2 % i == 0) {           primes.push_back(i);           while (n2 % i == 0) {             powers[i]++;             n2 /= i;           }         }       if (n2 != 1) {         primes.push_back(n2);         powers[n2]++;       }       std::map<int32_t, std::vector<int32_t> > mpf2;       for (int32_t i = 1; i * i <= n; i++) {         if (n % i == 0) {           mpf2[mpf(i, primes)].push_back(i);           if (i * i != n) mpf2[mpf(n / i, primes)].push_back(n / i);         }       }       mpf2.erase(1);       std::vector<int32_t> answer;       std::unordered_set<int32_t> used;       for (int32_t i = 0; i < primes.size(); i++) {         int32_t next =             primes.size() != 1 ? primes[i] * primes[(i + 1) % primes.size()] : -1;         for (int32_t j = 0; j < mpf2[primes[i]].size(); j++)           if (mpf2[primes[i]][j] != next &&               used.find(mpf2[primes[i]][j]) == used.end()) {             used.insert(mpf2[primes[i]][j]);             answer.push_back(mpf2[primes[i]][j]);           }         if (primes.size() != 1 && used.find(next) == used.end()) {           answer.push_back(next);           used.insert(next);         }       }       for (int32_t j = 0; j < answer.size(); j++) std::cout << answer[j] <<    ;       std::cout <<   n ;       int32_t actions = 0;       for (int32_t j = 0; j < answer.size(); j++) {         if (gcd(answer[j], answer[(j + 1) % answer.size()]) == 1) actions++;       }       std::cout << actions <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   inline int read() {     register int s = 0, f = 1;     char c;     for (c = getchar(); c <  0  || c >  9 ; c = getchar())       if (c ==  - ) f = -1;     while (c >=  0  && c <=  9 ) s = (s * 10 + (c ^  0 )), c = getchar();     return s * f;   }   inline void print(register int x) {     if (x < 0) putchar( - ), x = -x;     if (x > 9) print(x / 10);     putchar(x % 10 ^  0 );   }   using namespace std;   int ans, prim[20000005], l, r, tot;   bitset<300000005> vis;   inline void Get_Prime(register int l, register int r) {     vis[0] = vis[1] = 1;     for (register int i = 2; i <= r; ++i) {       if (!vis[i]) prim[++tot] = i;       for (register int j = 1; j <= tot && i * prim[j] <= r; ++j) {         vis[i * prim[j]] = 1;         if (i % prim[j] == 0) break;       }     }   }   int main() {     l = read(), r = read(), Get_Prime(l, r);     for (register int i = 5; i <= r; i += 4)       if (i >= l && !vis[i]) ++ans;     if (l <= 2 && r >= 2) ++ans;     print(ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int Max = 2e5 + 10;   const int LOG = 30;   const int INF = 1e9 + 10;   struct Trie {     int l[Max * LOG], r[Max * LOG];     int cnt[Max * LOG];     int sz = 1;     int index[Max * LOG];     int dp[Max * LOG][2];     void insert(int x, int ind) {       int p = 1;       for (int lg = LOG; lg--;) {         cnt[p]++;         if (x & (1 << lg))           if (r[p])             p = r[p];           else             p = r[p] = ++sz;         else if (l[p])           p = l[p];         else           p = l[p] = ++sz;       }       cnt[p]++;       index[p] = ind;     }     int mnxor(int x) {       int p = 1;       bool firstdiff = false;       for (int lg = LOG; lg--;) {         if (!firstdiff) {           if (x & (1 << lg))             if (cnt[r[p]] > 1)               p = r[p];             else {               p = l[p];               firstdiff = true;             }           else if (cnt[l[p]] > 1)             p = l[p];           else {             p = r[p];             firstdiff = true;           }         } else {           if (x & (1 << lg))             if (r[p])               p = r[p];             else               p = l[p];           else if (l[p])             p = l[p];           else             p = r[p];         }       }       return index[p];     }     void DP(int v) {       if (r[v]) DP(r[v]);       if (l[v]) DP(l[v]);       dp[v][0] = cnt[v] - 1;       dp[v][1] = min(dp[l[v]][0] + dp[r[v]][1], dp[r[v]][0] + dp[l[v]][1]);     }   };   Trie t;   int A[Max];   vector<int> N[Max];   bool seen[Max];   int DFS(int v) {     seen[v] = true;     int res = 1;     for (int u : N[v])       if (!seen[u]) res += DFS(u);     return res;   }   void solve() {     int n;     cin >> n;     for (int i = 0; i < n; i++) {       int a;       cin >> a;       A[i] = a;       t.insert(a, i);     }     for (int i = 0; i < n; i++) {       int from = i;       int to = t.mnxor(A[i]);       N[from].push_back(to);       N[to].push_back(from);     }     int molcnt = 0;     int mxmol = 0;     for (int i = 0; i < n; i++)       if (!seen[i]) {         molcnt++;         mxmol = max(mxmol, DFS(i));       }     t.DP(1);     cout << t.dp[1][1];   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     solve();   }


#include <bits/stdc++.h>   using namespace std;   vector<pair<int, int> > diffs;   long long int su[100500];   int n, s;   long long int kek(long long int res) {     long long int ans = res;     su[n - 1] = 1ll * diffs.back().first * diffs.back().second;     for (int i = n - 2; i >= 0; i--) {       su[i] = su[i + 1] + diffs[i].first * 1ll * diffs[i].second;     }     long long int w = 0;     long long int wa = 0;     for (int i = 0; i < n; i++) {       if (diffs[i].first < 0) {         w += diffs[i].second;       } else {         long long int aim = (w + s - 1) / s * s;         while (i < n && w + diffs[i].second <= aim) {           w += diffs[i].second;           wa += diffs[i].second * 1ll * diffs[i].first;           i++;         }         if (w == aim) {           ans = max(ans, res + su[i]);         } else {           long long int x = aim - w;           ans = max(ans, res + wa + su[i] - x * diffs[i].first);         }         break;       }     }     return ans;   }   int main() {     cin >> n >> s;     long long int sum = 0;     long long int res = 0;     long long int res1 = 0;     for (int i = 0; i < n; i++) {       int a, b, c;       cin >> a >> b >> c;       sum += a;       res += 1ll * a * b;       res1 += 1ll * a * c;       diffs.push_back({c - b, a});     }     long long int kol = (sum + s - 1) / s;     if (kol * s > sum) diffs.push_back({0, kol * s - sum});     n = diffs.size();     sort(diffs.begin(), diffs.end());     long long int ans = res;     long long int danil = kek(res);     reverse(diffs.begin(), diffs.end());     for (auto &x : diffs) {       x.first *= -1;     }     cout << max(danil, kek(res1));     return 0;   }


#include <bits/stdc++.h>   const int MAXN = 1000 + 5;   char str[MAXN];   int n;   inline std::vector<int> query(std::vector<int> d) {     std::vector<int> ans;     printf( ?  );     for (auto x : d) printf( %d  , x);     puts(  );     std::fflush(stdout);     scanf( %s , str + 1);     for (int i = 1; i <= n; ++i) ans.push_back(str[i] -  0 );     return ans;   }   std::vector<int> G[MAXN];   std::vector<int> node[MAXN * 50];   int tot = 1;   struct Node {     int l, r, id;     Node(int l = 0, int r = 0, int id = 0) : l(l), r(r), id(id) {}     inline bool operator<(const Node &t) const { return l < t.l; }   };   int fa[MAXN];   inline void work(std::vector<int> id, int bit) {     std::vector<int> d;     d.resize(n);     for (auto x : id) {       for (auto y : G[x - 1])         if ((y >> bit) & 1) d[y - 1] = 1;     }     std::vector<int> a;     a = query(d);     for (auto x : id) {       for (auto y : G[x]) fa[y] |= (a[y - 1] << bit);     }   }   bool tag[MAXN];   int main() {     scanf( %d , &n);     std::vector<Node> now;     G[0].push_back(1);     now.push_back(Node(0, n, 1));     for (int i = 2; i <= n; ++i) node[tot].push_back(i);     while (!now.empty()) {       std::vector<Node> v1, v2;       std::sort(now.begin(), now.end());       for (int i = 0; i < now.size(); i += 2) {         v1.push_back(now[i]);         if (i + 1 < now.size()) v2.push_back(now[i + 1]);       }       std::vector<int> d, a1, a2;       d.resize(n);       now.clear();       memset(tag, 0, sizeof(tag));       for (auto x : v1) {         int mid = (x.l + x.r) >> 1;         assert(x.l < x.r - 1);         for (auto y : G[x.l]) d[y - 1] = mid - x.l - 1, tag[y - 1] = 1;       }       a1 = query(d);       for (int i = 0; i <= n - 1; ++i)         if (tag[i]) d[i]++;       a2 = query(d);       for (auto x : v1) {         int mid = (x.l + x.r) >> 1;         Node ls = Node(x.l, mid, ++tot), rs = Node(mid, x.r, ++tot);         for (auto y : node[x.id]) {           if (!a1[y - 1] && a2[y - 1])             G[mid].push_back(y);           else if (a1[y - 1])             node[ls.id].push_back(y);           else             node[rs.id].push_back(y);         }         if (ls.l + 1 < ls.r) now.push_back(ls);         if (rs.l + 1 < rs.r) now.push_back(rs);       }       d.clear();       d.resize(n);       memset(tag, 0, sizeof(tag));       for (auto x : v2) {         int mid = (x.l + x.r) >> 1;         assert(x.l < x.r - 1);         for (auto y : G[x.l]) d[y - 1] = mid - x.l - 1, tag[y - 1] = 1;       }       a1 = query(d);       for (int i = 0; i <= n - 1; ++i)         if (tag[i]) d[i]++;       a2 = query(d);       for (auto x : v2) {         int mid = (x.l + x.r) >> 1;         Node ls = Node(x.l, mid, ++tot), rs = Node(mid, x.r, ++tot);         for (auto y : node[x.id]) {           if (!a1[y - 1] && a2[y - 1])             G[mid].push_back(y);           else if (a1[y - 1])             node[ls.id].push_back(y);           else             node[rs.id].push_back(y);         }         if (ls.l + 1 < ls.r) now.push_back(ls);         if (rs.l + 1 < rs.r) now.push_back(rs);       }     }     for (int i = 0; i <= 9; ++i) {       std::vector<int> v1, v2, v3;       for (int i = 1; i < n; i += 3) {         v1.push_back(i);         if (i + 1 < n) v2.push_back(i + 1);         if (i + 2 < n) v3.push_back(i + 2);       }       work(v1, i);       work(v2, i);       work(v3, i);     }     puts( ! );     for (int i = 2; i <= n; ++i) printf( %d %d n , fa[i], i);     std::fflush(stdout);     return 0;   }


#include <bits/stdc++.h>   using namespace std;      int main() {    // your code goes here    int t;    cin>>t;    int len=pow(10,9)+7;    while(t--)    {        int n,k;        cin>>n>>k;       long long int ans=1;        for(int i=0;i<k;i++)        {            ans=(ans*n)% len;        }        cout<<ans<<endl;                            }    return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline void read(long long &x) {     char ch;     bool flag = false;     for (ch = getchar(); !isdigit(ch); ch = getchar())       if (ch ==  - ) flag = true;     for (x = 0; isdigit(ch); x = x * 10 + ch -  0 , ch = getchar())       ;     x = flag ? -x : x;   }   inline void write(long long x) {     static const long long maxlen = 100;     static char s[maxlen];     if (x < 0) {       putchar( - );       x = -x;     }     if (!x) {       putchar( 0 );       return;     }     long long len = 0;     for (; x; x /= 10) s[len++] = x % 10 +  0 ;     for (long long i = len - 1; i >= 0; --i) putchar(s[i]);   }   inline void read(int &x) {     char ch;     bool flag = false;     for (ch = getchar(); !isdigit(ch); ch = getchar())       if (ch ==  - ) flag = true;     for (x = 0; isdigit(ch); x = x * 10 + ch -  0 , ch = getchar())       ;     x = flag ? -x : x;   }   const long long MAXN = 110000;   long long f[MAXN][110];   long long s[MAXN];   const long long P = 998244353ll;   long long n, lim, kind;   long long a[MAXN];   long long num[MAXN][110];   int main() {     read(n);     read(kind);     read(lim);     for (long long i = 1; i <= n; i++) {       read(a[i]);       if (a[i] == -1) a[i] = 0;     }     for (long long i = 1; i <= n; i++) {       for (long long j = 0; j <= kind; j++) num[i][j] = num[i - 1][j];       num[i][a[i]]++;     }     s[0] = 1;     for (long long i = 1; i <= n; i++)       if (a[i] == 0)         for (long long j = 1; j <= kind; j++) {           f[i][j] = s[i - 1];           if ((i >= lim) &&               (num[i][j] - num[i - lim][j] + num[i][0] - num[i - lim][0] == lim))             f[i][j] = (f[i][j] - (s[i - lim] - f[i - lim][j]) + 3 * P) % P;           s[i] = (s[i] + f[i][j]) % P;         }       else {         long long j = a[i];         f[i][a[i]] = s[i - 1];         if ((i >= lim) &&             (num[i][j] - num[i - lim][j] + num[i][0] - num[i - lim][0] == lim)) {           f[i][j] = (f[i][j] - (s[i - lim] - f[i - lim][j])) % P;         }         s[i] = (s[i] + f[i][j]) % P;       }     cout << s[n] << endl;     return 0;     for (;;) {       long long x, y;       read(x);       read(y);       printf( f[%d][%d]=%d n , x, y, f[x][y]);     }     return 0;   }


#include <bits/stdc++.h>   int main() {     char a[200100], b[200100];     while (~scanf( %s%s , a, b)) {       int c[1000];       memset(c, 0, sizeof(c));       int n = 0;       for (int i = 0; a[i]; ++i) ++c[a[i]];       int ya = 0;       for (int i = 0; b[i]; ++i)         if (c[b[i]]) --c[b[i]], ++ya, b[i] = -1;       for (int i = 0; b[i]; ++i)         if (b[i] != -1)           if (c[tolower(b[i])])             ++n, --c[tolower(b[i])];           else if (c[toupper(b[i])])             ++n, --c[toupper(b[i])];       printf( %d %d n , ya, n);     };     return 0;   };


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     int t;     cin >> t;     while (t--) {       long long n, m;       cin >> n >> m;       vector<pair<long long, long long>> ar(m);       for (int i = 0; i < m; ++i) {         cin >> ar[i].first >> ar[i].second;       }       sort(ar.begin(), ar.end());       vector<long long> psa(m + 1);       for (int i = 1; i < m + 1; ++i) {         psa[i] = psa[i - 1] + ar[i - 1].first;       }       long long ans = 0;       for (int i = 0; i < m; ++i) {         long long a = ar[i].first;         long long b = ar[i].second;         int j = lower_bound(ar.begin(), ar.end(), make_pair(b, LLONG_MAX)) -                 ar.begin();         long long cur = 0;         if (m - j <= n) {           cur += psa[m] - psa[j];           int x = n - (m - j);           cur += a + (x - 1) * b;           if (j <= i) {             cur -= a;             cur += b;           }         } else {           cur += psa[m] - psa[m - n];         }         ans = max(ans, cur);       }       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 1000000000;   long long mod = 1000000007LL;   long long mod2 = 998244353LL;   long long t, l, r;   long long dp[5000005];   long long prm[5000005];   long long pw[5000005];   long long dfs(int x) {     if (dp[x] >= 0) return dp[x];     if (x == 1) return dp[x] = 0LL;     dp[x] = (long long)x * (long long)(x - 1) / 2LL;     dp[x] %= mod;     long long i;     if (x > 2 && x % 2 == 0) {       return dp[x] = (dfs(x / 2) + (2 * (2 - 1) / 2) % mod * (x / 2) % mod) % mod;     }     int d = prm[x];     if (d < 0) return dp[x];     return dp[x] = (dfs(x / d) + (d * (d - 1) / 2) % mod * (x / d) % mod) % mod;   }   long long getpw(long long x, long long y) {     long long res = 1LL;     while (y) {       if (y & 1) res = res * x % mod;       x = x * x % mod;       y /= 2;     }     return res;   }   int main() {     cin >> t >> l >> r;     memset(prm, -1, sizeof(prm));     for (int i = 2; i * i <= r; ++i) {       if (prm[i] < 0) {         for (int j = 2 * i; j <= r; j += i) {           if (prm[j] < 0) prm[j] = i;         }       }     }     pw[0] = 1LL;     for (int i = 1; i <= r; ++i) {       pw[i] = pw[i - 1] * (long long)t % mod;     }     memset(dp, -1, sizeof(dp));     long long res = 0LL;     for (int i = 2; i <= r; ++i) {       if (dp[i] < 0) {         dfs(i);         if (i >= l && i <= r) {           long long tmp = dp[i] * pw[i - l] % mod;           res = (res + tmp) % mod;         }       }     }     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 100086;   const int inf = 2.1e9;   const long long Inf = 999999999999999999;   const int mod = 1000000007;   const double eps = 1e-6;   const double pi = acos(-1);   int n, s, t;   int nums[206];   int vis[maxn], num[maxn];   int prime[maxn], cur;   bool check[maxn];   int Head[208], Next[maxn], v[maxn], w[maxn], cnt;   void init() {     memset(Head, -1, sizeof(Head));     cnt = 0;     s = 0, t = n + 1;   }   void primes() {     for (int i = 2; i < 20086; i++) {       if (!check[i]) {         prime[cur++] = i;       }       for (int j = 0; j < cur; j++) {         if (i * prime[j] > 20086) {           break;         }         check[i * prime[j]] = i;         if (i % prime[j] == 0) {           break;         }       }     }   }   void add(int x, int y, int z) {     if (x == y) {       return;     }     v[cnt] = y;     w[cnt] = z;     Next[cnt] = Head[x];     Head[x] = cnt++;     v[cnt] = x;     w[cnt] = 0;     Next[cnt] = Head[y];     Head[y] = cnt++;   }   bool bfs() {     memset(vis, 0, sizeof(vis));     for (int i = 0; i <= t; i++) {       num[i] = Head[i];     }     vis[s] = 1;     queue<int> q;     q.push(s);     int r = 0;     while (!q.empty()) {       int u = q.front();       q.pop();       int k = Head[u];       while (k != -1) {         if (!vis[v[k]] && w[k]) {           vis[v[k]] = vis[u] + 1;           q.push(v[k]);         }         k = Next[k];       }     }     return vis[t];   }   int dfs(int u, int f) {     if (u == t) {       return f;     }     int &k = num[u];     int sum = 0;     while (k != -1) {       if (vis[v[k]] == vis[u] + 1 && w[k]) {         int d = dfs(v[k], min(f, w[k]));         if (d > 0) {           w[k] -= d;           w[k ^ 1] += d;           return d;         }       }       k = Next[k];     }     return sum;   }   int Dinic() {     int ans = 0;     while (bfs()) {       int f;       while ((f = dfs(s, inf)) > 0) {         ans += f;       }     }     return ans;   }   stack<int> st;   void dfs(int t) {     vis[t] = 1;     st.push(t);     for (int k = Head[t]; k != -1; k = Next[k]) {       if (v[k] == 0 || v[k] == n + 1) {         continue;       }       if (vis[v[k]]) {         continue;       }       if (nums[t] % 2 == 0 && w[k]) {         dfs(v[k]);       }       if (nums[t] % 2 == 1 && !w[k]) {         dfs(v[k]);       }     }     vis[t] = -1;   }   queue<int> q[208];   int main() {     primes();     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &nums[i]);     }     init();     for (int i = 1; i <= n; i++) {       if (nums[i] & 1) {         add(s, i, 2);       } else {         add(i, t, 2);       }       for (int j = i + 1; j <= n; j++) {         if (!check[nums[i] + nums[j]]) {           if (nums[i] & 1) {             add(i, j, 1);           } else {             add(j, i, 1);           }         }       }     }     if (Dinic() != n) {       printf( Impossible n );       return 0;     }     int numi = 0;     memset(vis, 0, sizeof(vis));     for (int i = 1; i <= n; i++) {       if (!vis[i]) {         dfs(i);         numi++;         while (!st.empty()) {           q[i].push(st.top());           st.pop();         }       }     }     printf( %d n , numi);     for (int i = 1; i <= n; i++) {       if (!q[i].empty()) {         printf( %d , q[i].size());         while (!q[i].empty()) {           printf(  %d , q[i].front());           q[i].pop();         }         printf(  n );       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char oda[3500];   int y;   void PuLe(int x) {     int j;     j = x;     while (oda[j - 1] ==  . ) {       oda[j - 1] =  @ ;       j--;     }     if (oda[j - 1] ==  R ) {       if ((x - j) % 2 != 0) oda[x - ((x - j) / 2 + 1)] =  . ;     }   }   void PuRi(int x) {     int j;     j = x;     while (oda[j + 1] ==  . ) {       oda[j + 1] =  @ ;       j++;     }     if (oda[j + 1] ==  L ) {       if ((j - x) % 2 != 0) oda[(j - x) / 2 + 1 + x] =  . ;     }   }   int main() {     int n;     while (cin >> n) {       int i, count = 0;       cin >> oda;       for (i = 0; i < n; i++) {         if (oda[i] ==  L ) PuLe(i);         if (oda[i] ==  R ) PuRi(i);       }       for (i = 0; i < n; i++)         if (oda[i] ==  . ) count++;       cout << count;       cout << endl;     }   }