#include <bits/stdc++.h>   using namespace std;   const int N = 500010;   int k, n, maxb, t, b[N], tot = 1, dp[N << 2], rec[N << 2];   void update(int i, int x) {     while (i <= tot) {       dp[i] = max(dp[i], x);       i += i & -i;     }   }   int sum(int i) {     int ret = 0;     while (i) {       ret = max(ret, dp[i]);       i -= i & -i;     }     return ret;   }   int main() {     scanf( %d%d%d%d , &k, &n, &maxb, &t);     t = min(t, maxb);     while (tot <= maxb) tot <<= 1;     while (k--) {       memset(dp, 0, sizeof(dp));       memset(rec, 0, sizeof(rec));       memset(b, 0, sizeof(b));       for (int i = 0; i < n; i++) scanf( %d , &b[i]);       for (int i = 1; i <= t; i++)         for (int j = 0; j < n; j++) {           int tmp = sum(b[j] - 1);           if (tmp >= rec[j]) {             update(b[j], tmp + 1);             rec[j] = tmp + 1;           }         }       printf( %d n , sum(tot));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long MAX_N = 1e3 + 1;   long n, m, h;   long aw[MAX_N];   long bw[MAX_N];   vector<long> g[MAX_N];   bool v[MAX_N];   vector<long> st;   vector<pair<pair<long, long>, long> > ans;   void add_edge(long a, long b) {     g[a].push_back(b);     g[b].push_back(a);   }   void try_flow(long i, long need) {     if (i + 1 >= st.size()) return;     long a = st[i], b = st[i + 1];     long can = min(need, h - aw[b]);     if (can > 0) {       ans.push_back(make_pair(make_pair(a, b), can));     }     try_flow(i + 1, need);     if (need - can > 0) {       ans.push_back(make_pair(make_pair(a, b), need - can));     }   }   void flow() {     long a = st[0];     long b = st[st.size() - 1];     long need = min(aw[a] - bw[a], bw[b] - aw[b]);     if (need > 0) {       try_flow(0, need);       aw[a] -= need;       aw[b] += need;     }   }   void dfs(long a) {     v[a] = true;     st.push_back(a);     if (aw[a] < bw[a]) flow();     for (size_t i = 0; i < g[a].size(); i++) {       long b = g[a][i];       if (!v[b]) dfs(b);     }     st.pop_back();   }   int main() {     cin >> n >> h >> m;     for (long i = 1; i <= n; i++) {       cin >> aw[i];     }     for (long i = 1; i <= n; i++) {       cin >> bw[i];     }     for (long i = 1; i <= m; i++) {       long x, y;       cin >> x >> y;       add_edge(x, y);     }     for (long i = 1; i <= n; i++) {       if (aw[i] > bw[i]) {         for (long j = 1; j <= n; j++) v[j] = false;         dfs(i);       }     }     for (long i = 1; i <= n; i++) {       if (aw[i] != bw[i]) {         cout <<  NO ;         return 0;       }     }     cout << ans.size() << endl;     for (size_t i = 0; i < ans.size(); i++) {       cout << ans[i].first.first <<     << ans[i].first.second <<                << ans[i].second << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string str;     getline(cin, str);     str.erase(remove(str.begin(), str.end(),    ), str.end());     int n = str.size();     if (str[n - 2] ==  a  || str[n - 2] ==  e  || str[n - 2] ==  i  ||         str[n - 2] ==  o  || str[n - 2] ==  u  || str[n - 2] ==  y  ||         str[n - 2] ==  A  || str[n - 2] ==  E  || str[n - 2] ==  I  ||         str[n - 2] ==  O  || str[n - 2] ==  U  || str[n - 2] ==  Y ) {       cout <<  YES ;     } else {       cout <<  NO ;     }   }


#include <bits/stdc++.h>   using namespace std;   string s;   int main() {     cin >> s;     long long mid;     for (long long i = 0; i < s.size(); i++) {       if (s[i] ==  ^ ) {         mid = i;         break;       }     }     long long sum = 0;     for (long long i = 0; i < s.size(); i++) {       if (s[i] ==  =  || s[i] ==  ^ ) continue;       long long x = s[i] - 48;       sum += x * (i - mid);     }     if (sum == 0)       cout <<  balance ;     else if (sum < 0)       cout <<  left ;     else       cout <<  right ;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = int(1e9) + 1;   const long double eps = 1e-9;   map<string, int> jogos;   map<string, int> pontos;   map<string, int> gol;   map<string, int> leva;   set<string> times;   vector<string> falta;   int x1, x2;   bool menor(string x, string y) {     int g1 = 0, g2 = 0;     int l1 = 0, l2 = 0;     if (falta[0] == x) {       g1 += x1;       l1 += x2;     } else if (falta[0] == y) {       g2 += x1;       l2 += x2;     }     if (falta[1] == x) {       g1 += x2;       l1 += x1;     } else if (falta[1] == y) {       g2 += x2;       l2 += x1;     }     g1 += gol[x];     l1 += leva[x];     g2 += gol[y];     l2 += leva[y];     if (pontos[x] > pontos[y])       return true;     else if (pontos[x] < pontos[y])       return false;     else {       if (g1 - l1 > g2 - l2)         return true;       else if (g1 - l1 < g2 - l2)         return false;       else {         if (g1 > g2)           return true;         else if (g1 < g2)           return false;         return y > x;       }     }   }   bool ord(int p1, int p2) {     x1 = p1;     x2 = p2;     vector<string> pi;     for (set<string>::iterator it = times.begin(); it != times.end(); ++it) {       string aux = *it;       pi.push_back((aux));     }     for (int i = 3; i >= 1; --i) {       for (int j = 0; j < i; j++) {         if (!menor(pi[j], pi[j + 1])) {           swap(pi[j], pi[j + 1]);         }       }     }     if (pi[0] ==  BERLAND  || pi[1] ==  BERLAND ) return true;     return false;   }   int main() {     for (int i = 0; i < 5; ++i) {       string x, y;       int g1, g2;       cin >> x >> y;       times.insert(x);       times.insert(y);       scanf( %d:%d , &g1, &g2);       jogos[x]++;       jogos[y]++;       if (g1 == g2) {         pontos[x]++;         pontos[y]++;       } else if (g1 > g2) {         pontos[x] += 3;       } else {         pontos[y] += 3;       }       gol[x] += g1;       leva[x] += g2;       gol[y] += g2;       leva[y] += g1;     }     for (set<string>::iterator it = times.begin(); it != times.end(); ++it) {       if (jogos[*it] < 3) falta.push_back(*it);     }     if (falta[1] ==  BERLAND ) swap(falta[0], falta[1]);     pontos[falta[0]] += 3;     int ans1 = 1e8, ans2 = 1e7;     for (int g1 = 0; g1 < 201; ++g1) {       for (int g2 = 0; g2 < g1; ++g2) {         bool can = ord(g1, g2);         if (can) {           if (ans1 - ans2 > g1 - g2) {             ans1 = g1;             ans2 = g2;           }         }       }     }     if (ans1 >= 1e8)       puts( IMPOSSIBLE );     else       printf( %d:%d n , ans1, ans2);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long t, a, b, c;     cin >> t;     while (t--) {       cin >> a >> b >> c;       cout << ((a + b * 2 + c * 3) & 1) <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void swap(long long int arr[], long long int x, long long int y) {     long long int temp = arr[x];     arr[x] = arr[y];     arr[y] = temp;   }   void print_arr(long long int arr[], long long int n) {     cout <<   n ;     for (long long int i = 0; i < n; i++) {       cout << arr[i] <<    ;     }     cout <<   n ;   }   void input_arr(long long int arr[], long long int n) {     for (long long int i = 0; i < n; i++) {       cin >> arr[i];     }   }   bool primes[1000001];   int checkstring(string s) {     int l = s.length();     string p =   ;     for (int i = 0; i < l; i++) {       if (s[i] !=  - ) {         p += s[i];       }     }     int same = 0;     int dec = 0;     for (int i = 1; i < p.length(); i++) {       if (p[i] == p[i - 1]) {         same++;       } else if (p[i] <= p[i - 1]) {         dec++;       }     }     if (same == p.length() - 1) {       return 2;     } else if (dec == p.length() - 1) {       return 1;     }     return 3;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int t;     t = 1;     while (t--) {       long long int n;       cin >> n;       map<string, long long int> tx;       map<string, long long int> cg;       map<string, long long int> pz;       string abc[n];       for (int i = 0; i < n; i++) {         int N;         string fname;         cin >> N >> fname;         abc[i] = fname;         for (int j = 0; j < N; j++) {           string s;           cin >> s;           int x = checkstring(s);           if (x == 2) {             tx[fname]++;           } else if (x == 3) {             cg[fname]++;           } else {             pz[fname]++;           }         }       }       int maxp = 0, maxt = 0, maxc = 0;       vector<string> v[3];       for (int i = 0; i < n; i++) {         if (tx[abc[i]] > maxt) {           maxt = tx[abc[i]];         }         if (pz[abc[i]] > maxp) {           maxp = pz[abc[i]];         }         if (cg[abc[i]] > maxc) {           maxc = cg[abc[i]];         }       }       for (int i = 0; i < n; i++) {         if (pz[abc[i]] == maxp) {           v[0].push_back(abc[i]);         }         if (cg[abc[i]] == maxc) {           v[1].push_back(abc[i]);         }         if (tx[abc[i]] == maxt) {           v[2].push_back(abc[i]);         }       }       cout <<  If you want to call a taxi, you should call: ;       for (int i = 0; i < v[2].size(); i++) {         if (i != v[2].size() - 1)           cout <<     << v[2][i] <<  , ;         else           cout <<     << v[2][i] <<  . ;       }       cout <<   n ;       cout <<  If you want to order a pizza, you should call: ;       for (int i = 0; i < v[0].size(); i++) {         if (i != v[0].size() - 1)           cout <<     << v[0][i] <<  , ;         else           cout <<     << v[0][i] <<  . ;       }       cout <<   n ;       cout <<  If you want to go to a cafe with a wonderful girl, you should                  call: ;       for (int i = 0; i < v[1].size(); i++) {         if (i != v[1].size() - 1)           cout <<     << v[1][i] <<  , ;         else           cout <<     << v[1][i] <<  . ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int digitMask = 0;   int c[20];   int factorize(int n, int pos) {     int curPos = pos;     c[curPos] = 0;     while (n > 0) c[curPos++] = n % 10, n /= 10;     curPos--;     curPos = max(curPos, pos);     for (int i = pos, j = curPos; i < j; i++, j--) swap(c[i], c[j]);     return curPos;   }   int parsenum(int n) {     if (c[n - 1] == 0 && n != 1) return -1;     int ans = 0;     for (int i = n - 1; i >= 0; i--) ans *= 10, ans += c[i];     return ans;   }   bool good(int i, int j) {     int ii = i, jj = j;     while (i < j)       if (c[i] != c[j])         return false;       else         i++, j--;     int mask = 0;     for (int we = ii; we <= jj; we++) mask |= (1 << c[we]);     return mask == digitMask;   }   bool nogood(int i, int j) {     for (int we = i; we <= j; we++)       if ((digitMask & (1 << c[we])) == 0) return true;     return false;   }   const int maxn = 1000000;   int ans1[maxn], ans2[maxn], ans3[maxn], ans4[maxn];   int ansCount;   int main() {     int n;     cin >> n;     if (n >= 7) {       cout << 0;       return 0;     }     for (int i = 0; i < n; i++) {       int c;       cin >> c;       digitMask |= (1 << c);     }     for (int a = 0; a < 256; a++) {       int pos1 = factorize(a, 0);       for (int b = 0; b < 256; b++) {         int pos2 = factorize(b, pos1 + 1);         if (nogood(0, pos2)) continue;         for (int c = 0; c < 256; c++) {           int pos3 = factorize(c, pos2 + 1);           if (nogood(0, pos3)) continue;           for (int count = 1; count <= 3; count++) {             int last = parsenum(count);             if (last == -1) continue;             if (last >= 256) continue;             int pos = factorize(last, pos3 + 1);             if (good(0, pos)) {               ans1[ansCount] = a;               ans2[ansCount] = b;               ans3[ansCount] = c;               ans4[ansCount] = last;               ansCount++;             }           }         }       }     }     cout << ansCount << endl;     for (int i = 0; i < ansCount; i++) {       cout << ans1[i] <<  .  << ans2[i] <<  .  << ans3[i] <<  .  << ans4[i]            << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long modn = 1000000007;   inline long long mod(long long x) { return x % modn; }   int n;   vector<int> v[30];   int qt[30];   int main() {     int i, j;     string s;     cin >> s;     n = s.size();     for (i = 0; i < n; i++) v[s[i] -  a ].push_back(i);     double ans = 0;     for (i = 0; i < 26; i++) {       if (v[i].empty()) continue;       if (v[i].size() == 1) {         ans += 1;         continue;       }       if (v[i].size() == 2) {         string t1 = s, t2 = s;         rotate(t1.begin(), t1.begin() + v[i][0], t1.end());         rotate(t2.begin(), t2.begin() + v[i][1], t2.end());         if (t1 != t2) ans += 2;         continue;       }       int mx = 0;       for (j = 0; j < n; j++) {         for (int k : v[i]) qt[s[(k + j) % n] -  a ]++;         int cur = 0;         int k;         for (k = 0; k < 26; k++)           if (qt[k] == 1) cur++;         mx = max(mx, cur);         for (int k : v[i]) qt[s[(k + j) % n] -  a ]--;       }       ans += mx;     }     printf( %.15f n , ans / n);   }


#include <bits/stdc++.h>   using namespace std;   template <class temp>   inline void Rd(temp &p) {     p = 0;     char c;     while (c = getchar(), c < 48)       ;     do p = p * 10 + (c & 15);     while (c = getchar(), c > 47);   }   int n, k, len, m, q[200005];   int l[200005], r[200005];   int lfind(int x) {     if (l[x] == x)       return x;     else       return l[x] = lfind(l[x]);   }   int rfind(int x) {     if (r[x] == x)       return x;     else       return r[x] = rfind(r[x]);   }   int main() {     Rd(n), Rd(k), Rd(len), Rd(m);     for (int i = 1; i <= n; i++) l[i] = i - 1, r[i] = i + 1;     l[0] = r[0] = 0;     l[n + 1] = r[n + 1] = n + 1;     for (int i = 1; i <= m; i++) {       Rd(q[i]);       l[q[i]] = r[q[i]] = q[i];     }     int pre = 0, ans = 0;     for (int i = 1; i <= n + 1; i++)       if (lfind(i) == rfind(i)) {         ans += (i - pre) / (len + 1);         pre = i;       }     if (ans >= k) puts( -1 ), exit(0);     for (int i = m; i >= 1; i--) {       int pos = q[i];       ans -= (rfind(r[pos - 1]) - lfind(l[pos - 1])) / (len + 1);       ans -= (rfind(r[pos + 1]) - lfind(l[pos + 1])) / (len + 1);       l[pos] = pos - 1, r[pos] = pos + 1;       ans += (rfind(r[pos]) - lfind(l[pos])) / (len + 1);       if (ans >= k) printf( %d n , i), exit(0);     }   }


#include <bits/stdc++.h>   double vp, vd, t, f, c;   int main() {     scanf( %lf%lf%lf%lf%lf , &vp, &vd, &t, &f, &c);     double x = vp * t;     int ans = 0;     if (vp > vd) {       puts( 0 );       return 0;     }     while (x + 1e-6 < c) {       double needtime = x / (vd - vp);       double willx = x + needtime * vp;       if (willx + 1e-6 >= c) break;       ans++;       t += needtime * 2 + f;       x = vp * t;     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 1e5;   long long n, m;   map<long long, long long> mp;   long long ans[N], top;   signed main() {     cin >> n >> m;     for (long long i = 1; i <= n; ++i) {       long long x;       cin >> x;       mp[x] = 1;     }     for (long long i = 1; 26 > 30 / 39 / 57; ++i) {       if (mp[i] == 0) {         m -= i;         if (m < 0) {           break;         }         ans[++top] = i;       }     }     cout << top << endl;     for (long long i = 1; i <= top; ++i) {       cout << ans[i] <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); }   int main() {     long long t, i, r, c, k, j, n, cnt, x, y, p, q, l, flag;     vector<string> a;     vector<char> b;     for (i = 48; i < 58; i++) {       b.push_back(char(i));     }     for (i = 65; i < 91; i++) {       b.push_back(char(i));     }     for (i = 97; i < 124; i++) {       b.push_back(char(i));     }     string s;     cin >> t;     for (i = 0; i < t; i++) {       cin >> r >> c >> n;       cnt = 0;       p = 0, q = 0, l = 0, flag = 1;       for (j = 0; j < r; j++) {         cin >> s;         for (k = 0; k < c; k++) {           if (s[k] ==  R ) {             cnt++;           }         }         a.push_back(s);       }       if (cnt % n == 0) {         x = cnt / n;         y = n;       } else {         x = cnt / n + 1;         y = cnt % n;       }       for (j = 0; j < r; j++) {         if (j % 2 == 0) {           for (k = 0; k < c; k++) {             if (a[j][k] ==  R ) {               if (q == x) {                 p++;                 if (p == y && flag == 1) {                   x = x - 1;                   flag = 2;                 }                 q = 1;                 l++;                 a[j][k] = b[l];               } else {                 q++;                 a[j][k] = b[l];               }             } else {               a[j][k] = b[l];             }           }         } else {           for (k = c - 1; k >= 0; k--) {             if (a[j][k] ==  R ) {               if (q == x) {                 p++;                 if (p == y && flag == 1) {                   x = x - 1;                   flag = 2;                 }                 q = 1;                 l++;                 a[j][k] = b[l];               } else {                 q++;                 a[j][k] = b[l];               }             } else {               a[j][k] = b[l];             }           }         }       }       for (j = 0; j < r; j++) {         cout << a[j] << endl;       }       a.clear();     }   }


#include <bits/stdc++.h>   int in[101], od[101], fa[101], n;   int f[101], f2[102];   inline int find(int a) {     if (fa[a] != a) fa[a] = find(fa[a]);     return fa[a];   }   inline void u(int x, int y) {     x = find(x);     y = find(y);     fa[y] = x;   }   signed main() {     scanf( %d , &n);     for (register int i = 1; i <= n; i++) fa[i] = i;     for (register int i = 1; i <= n; i++) scanf( %d , &in[i]);     for (register int i = 1; i <= n; i++) {       scanf( %d , &od[i]);       if (i - od[i] > 0) u(in[i], in[i - od[i]]);       if (i + od[i] <= n) u(in[i], in[i + od[i]]);     }     for (register int i = 1; i <= n; i++) {       f[find(i)] += i;       f2[find(i)] += in[i];     }     for (register int i = 1; i <= n; i++) {       if (f[i] ^ f2[i]) {         printf( NO n );         return 0;       }     }     printf( YES n );   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 5, M = (1 << 20) + 5;   template <typename T>   void read(T &x) {     bool neg = false;     unsigned char c = getchar();     for (; (c ^ 48) > 9; c = getchar())       if (c ==  - ) neg = true;     for (x = 0; (c ^ 48) < 10; c = getchar()) x = (x << 3) + (x << 1) + (c ^ 48);     if (neg) x = -x;   }   struct line {     int next, to;   } e[N];   int n, m, hd[N], cnt, k, s[25], t[25], f[N], a[M], pop[M];   bool iss[N], ist[N];   void adline(int u, int v) {     e[cnt].to = v;     e[cnt].next = hd[u];     hd[u] = cnt++;   }   void dfs(int u) {     if (f[u]) return;     for (int i = hd[u]; ~i; i = e[i].next) {       int v = e[i].to;       dfs(v);       f[u] |= f[v];     }   }   int main() {     read(n);     read(m);     for (int i = 0, i_end = n; i < i_end; ++i) hd[i] = -1, iss[i] = ist[i] = true;     for (int i = 0, i_end = m; i < i_end; ++i) {       int u, v;       read(u);       read(v);       adline(--u, --v);       ist[u] = false;       iss[v] = false;     }     for (int i = 0, i_end = n; i < i_end; ++i)       if (iss[i]) s[k++] = i;     k = 0;     for (int i = 0, i_end = n; i < i_end; ++i)       if (ist[i]) t[k++] = i;     for (int i = 0, i_end = k; i < i_end; ++i) f[t[i]] = 1 << i;     for (int i = 0, i_end = k; i < i_end; ++i) dfs(s[i]), a[1 << i] = f[s[i]];     for (int i = 1, i_end = 1 << k; i < i_end; ++i)       pop[i] = pop[i ^ (i & -i)] + 1;     for (int i = 1, i_end = (1 << k) - 1; i < i_end; ++i) {       a[i] = a[i & -i] | a[i ^ (i & -i)];       if (pop[a[i]] <= pop[i]) return puts( NO ), 0;     }     puts( YES );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     map<int, int> A;     for (int i = 0; i < n; i++) {       int x;       cin >> x;       A[x]++;     }     int mx = 0;     for (auto x : A) {       if (x.second > mx) mx = x.second;     }     cout << mx;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     const string t =  RGB ;     int q;     cin >> q;     for (int i = 0; i < q; ++i) {       int n, k;       string s;       cin >> n >> k >> s;       int ans = 1e9;       for (int j = 0; j < n - k + 1; ++j) {         for (int offset = 0; offset < 3; ++offset) {           int cur = 0;           for (int pos = 0; pos < k; ++pos) {             if (s[j + pos] != t[(pos + offset) % 3]) {               ++cur;             }           }           ans = min(ans, cur);         }       }       cout << ans << endl;     }     return 0;   }


#include<bits/stdc++.h>   using namespace std;      const int N=500;   int n,mod,xn[N];   long long dp[N*N];      #define id(x,y) *(xn+x)+y      int main(){    cin>>n>>mod;    dp[id(1,1)]=1;    for(int i=2;i<=n;++i)     xn[i]=xn[i-1]+n;    xn[n+2]=(xn[n+1]=xn[n]+n)+n;    for(int i=1;i<n;i++){      long long a=(dp[id(i,1)]<<1)%mod;      dp[id(i+1,2)]+=a;      dp[id(i+1,1)]+=a;      dp[id(i+2,1)]+=a;         for(int j=2;j<=n;j++){     long long a=dp[id(i,j)]*(j-1)%mod,b=(dp[id(i,j)]*j<<1)%mod;     dp[id(i+1,j+1)]+=dp[id(i,j)]*(j+1)%mod;     dp[id(i+3,j-1)]+=a;     dp[id(i+2,j-1)]+=a<<1;     dp[id(i+1,j)]+=b;     dp[id(i+2,j)]+=b;      }    }          cout<<dp[id(n,1)]%mod<<endl;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 1e5 + 5;   const long long mod = 1e9 + 7;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long n;     cin >> n;     long long a[n], b[n];     for (long long i = 0; i < n; i++) cin >> a[i];     for (long long i = 0; i < n; i++) cin >> b[i];     sort(a, a + n, greater<long long>());     sort(b, b + n, greater<long long>());     long long i = 0, j = 0;     long long v1 = 0, v2 = 0;     for (long long c = 0; c < 2 * n; c++) {       long long op1 = (i == n ? 0 : a[i]);       long long op2 = (j == n ? 0 : b[j]);       if (op1 >= op2) {         i++;         if (c % 2 == 0) v1 += op1;       } else {         j++;         if (c & 1) v2 += op2;       }     }     cout << v1 - v2;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   const int INF = 1e9;   const long long IINF = 1e18;   const int dx[4] = {1, 0, -1, 0};   const int dy[4] = {0, 1, 0, -1};   const char dir[4] = { D ,  R ,  U ,  L };   template <typename T>   istream &operator>>(istream &is, vector<T> &v) {     for (T &x : v) is >> x;     return is;   }   template <typename T>   ostream &operator<<(ostream &os, const vector<T> &v) {     for (int i = 0; i < v.size(); ++i) {       os << v[i] << (i + 1 == v.size() ?   n  :    );     }     return os;   }   template <typename T, typename U>   ostream &operator<<(ostream &os, const pair<T, U> &p) {     cout <<  (  << p.first <<  ,  << p.second <<  ) ;     return os;   }   template <class T>   inline bool chmin(T &a, T b) {     if (a > b) {       a = b;       return true;     }     return false;   }   template <class T>   inline bool chmax(T &a, T b) {     if (a < b) {       a = b;       return true;     }     return false;   }   void solve(long long n) {     long long m = n;     vector<int> convert;     while (3 <= m) {       convert.emplace_back(m % 3);       m /= 3;     }     convert.emplace_back(m);     convert.emplace_back(0);     int d = convert.size(), most;     for (most = d - 1; most >= 0; --most) {       if (convert[most] == 2) break;     }     if (most < 0) {       cout << n <<   n ;       return;     }     for (int i = 0; i < most; ++i) convert[i] = 0;     for (int i = most; i < d; ++i) {       if (convert[i] == 2)         convert[i] = 0, convert[i + 1] += 1;       else if (convert[i] == 3)         convert[i] = 0, convert[i + 1] + -1;     }     long long po = 1, ans = 0;     for (int i = 0; i < d; ++i) {       ans += po * convert[i];       po *= 3;     }     cout << ans <<   n ;   }   int main() {     cin.tie(0);     ios::sync_with_stdio(false);     int t;     cin >> t;     for (; t--;) {       long long n;       cin >> n;       solve(n);     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1000000 + 10;   int cnt[maxn];   int main() {     int n, m;     cin >> n >> m;     for (int i = 0; i < m; ++i) {       int a, b;       scanf( %d%d , &a, &b);       --a, --b;       cnt[a]++;       cnt[b]++;     }     long long tot = 1LL * n * (n - 1) * (n - 2) / 6;     long long bad = 0;     for (int i = 0; i < n; ++i) {       bad += 1LL * cnt[i] * (n - 1 - cnt[i]);     }     cout << tot - bad / 2 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string a, b;     getline(cin, a);     getline(cin, b);     long long i = 0, j = 0;     while (a[i] ==  0 ) i++;     while (b[j] ==  0 ) j++;     if (a.size() - i > b.size() - j) {       cout <<  >  << endl;       return 0;     } else if (a.size() - i < b.size() - j) {       cout <<  <  << endl;       return 0;     } else {       while (i < a.size() && j < b.size()) {         if (a[i] > b[j]) {           cout <<  >  << endl;           return 0;         } else if (a[i] < b[j]) {           cout <<  <  << endl;           return 0;         }         i++;         j++;       }     }     cout <<  =  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int n = 100000, i = 700;   long long a[n], s[n], d[n], h[1000];   long long *g1, *g2, *g3, *g4;   int *g5, *g6, *g9;   int my, ans = 0, a1[n], h1[6], h2[6];   long long gcd(long long e, long long r) {     if (e < 0) e = -e;     while ((e) && (r))       if (e > r)         e %= r;       else         r %= e;     return e + r;   }   void getxy(long long ae, long long se, long long de, long long ar, long long sr,              long long dr, long long &f1, long long &f2, long long &f3,              long long &f4) {     f1 = dr * se - de * sr;     f2 = ae * sr - ar * se;     if (f2 < 0) {       f1 = -f1;       f2 = -f2;     }     if (f2 == 0) return;     long long c = gcd(f1, f2);     f1 /= c;     f2 /= c;     if (se) {       f3 = -ae * f1 - de * f2;       f4 = f2 * se;     } else {       f3 = -ar * f1 - dr * f2;       f4 = f2 * sr;     }     if (f4 < 0) {       f3 = -f3;       f4 = -f4;     }     c = gcd(f3, f4);     f3 /= c;     f4 /= c;   }   int cmp(int e, long long g1r, long long g2r, long long g3r, long long g4r) {     if (g1[e] < g1r) return 0;     if (g1[e] > g1r) return 2;     if (g2[e] < g2r) return 0;     if (g2[e] > g2r) return 2;     if (g3[e] < g3r) return 0;     if (g3[e] > g3r) return 2;     if (g4[e] < g4r) return 0;     if (g4[e] > g4r) return 2;     return 1;   }   void qs(int q, int w) {     int e = q, r = w;     long long y = q + (rand() % (w - q + 1)), t1 = g1[y], t2 = g2[y], t3 = g3[y],               t4 = g4[y];     do {       while (cmp(e, t1, t2, t3, t4) == 0) e++;       while (cmp(r, t1, t2, t3, t4) == 2) r--;       if (e <= r) {         y = g1[e];         g1[e] = g1[r];         g1[r] = y;         y = g2[e];         g2[e] = g2[r];         g2[r] = y;         y = g3[e];         g3[e] = g3[r];         g3[r] = y;         y = g4[e];         g4[e] = g4[r];         g4[r] = y;         y = g5[e];         g5[e] = g5[r];         g5[r] = y;         y = g6[e];         g6[e] = g6[r];         g6[r] = y;         e++;         r--;       }     } while (e <= r);     if (q < r) qs(q, r);     if (e < w) qs(e, w);   }   void qs1(int q, int w) {     int e = q, r = w;     long long y = q + (rand() % (w - q + 1)), t = g9[y];     do {       while (g9[e] > t) e++;       while (g9[r] < t) r--;       if (e <= r) {         y = g1[e];         g1[e] = g1[r];         g1[r] = y;         y = g2[e];         g2[e] = g2[r];         g2[r] = y;         y = g3[e];         g3[e] = g3[r];         g3[r] = y;         y = g4[e];         g4[e] = g4[r];         g4[r] = y;         y = g5[e];         g5[e] = g5[r];         g5[r] = y;         y = g6[e];         g6[e] = g6[r];         g6[r] = y;         y = g9[e];         g9[e] = g9[r];         g9[r] = y;         e++;         r--;       }     } while (e <= r);     if (q < r) qs1(q, r);     if (e < w) qs1(e, w);   }   void del(int &q, long long *a, long long *s, long long *d, int *a1,            long long f1, long long f2, long long f3, long long f4, int v1, int v2,            int v3) {     int w, t = 0;     long long c1, c2, c3, c4;     for (w = 0; w < q; w++) {       if ((a[w] == v1) && ((s[w] == v2) && (d[w] == v3))) continue;       getxy(a[w], s[w], d[w], v1, v2, v3, c1, c2, c3, c4);       if (((c1 == f1) && (c2 == f2)) && ((c3 == f3) && (c4 == f4))) continue;       a[t] = a[w];       s[t] = s[w];       d[t] = d[w];       a1[t] = a1[w];       t++;     }     q = t;   }   bool poss(int q, int r, int t, int y, int *a) {     int w, e = 0;     for (w = 0; w < y; w++)       if (r + w < t) e += a[r + w];     if (e >= q) return 1;     return 0;   }   long long impos = 0, impos1[i], impos2[i], impos3[i], impos4[i];   bool schim(long long c1, long long c2, long long c3, long long c4) {     int w;     for (w = 0; w < impos; w++)       if (((impos1[w] == c1) && (impos2[w] == c2)) &&           ((impos3[w] == c3) && (impos4[w] == c4)))         return 0;     return 1;   }   void addim(int c1, int c2, int c3, int c4) {     impos1[impos] = c1;     impos2[impos] = c2;     impos3[impos] = c3;     impos4[impos] = c4;     impos++;   }   bool slv(int q, int y, long long *a, long long *s, long long *d, int *a1,            bool b) {     if (q == 0) return 1;     if (y == 0) return 0;     int w, e, r, t, u, f5[i], f6[i], f9[i];     long long f1[i], f2[i], f3[i], f4[i];     u = my * my + 1;     if (b) u = q;     t = 0;     for (w = 0; (w < u) && (w < q); w++)       for (e = w + 1; (e < u) && (e < q); e++) {         getxy(a[w], s[w], d[w], a[e], s[e], d[e], f1[t], f2[t], f3[t], f4[t]);         f5[t] = w;         f6[t] = e;         if (f2[t]) t++;       }     g1 = f1;     g2 = f2;     g3 = f3;     g4 = f4;     g5 = f5;     g6 = f6;     if (t) qs(0, t - 1);     if (t == 0) {       if (q > y) return 0;       for (w = 0; w < q; w++) {         h1[ans] = a1[w] + 1;         h2[ans] = -1;         ans++;       }       return 1;     }     r = 0;     for (w = 0; w < t;) {       f1[r] = f1[w];       f2[r] = f2[w];       f3[r] = f3[w];       f4[r] = f4[w];       f5[r] = f5[w];       f6[r] = f6[w];       f9[r] = 1;       for (e = w + 1; (e < t) && (((f1[w] == f1[e]) && (f2[w] == f2[e])) &&                                   ((f3[w] == f3[e]) && (f4[w] == f4[e])));            e++)         f9[r]++;       f9[r] = h[f9[r]];       r++;       w = e;     }     g9 = f9;     t = r;     qs1(0, t - 1);     long long aa[q], ss[q], dd[q];     int aa1[q];     for (w = 0; w < q; w++) {       aa[w] = a[w];       ss[w] = s[w];       dd[w] = d[w];       aa1[w] = a1[w];     }     if (g9[0] > my) {       r = g5[0];       h1[ans] = a1[g5[0]] + 1;       h2[ans] = a1[g6[0]] + 1;       ans++;       del(q, aa, ss, dd, aa1, f1[0], f2[0], f3[0], f4[0], a[r], s[r], d[r]);       y--;       return slv(q, y, aa, ss, dd, aa1, 0);     }     int q1, im0 = impos;     for (w = 0; w < t; w++)       if ((poss(q, w, t, y, f9)) && (schim(f1[w], f2[w], f3[w], f4[w]))) {         r = f5[w];         h1[ans] = a1[f5[w]] + 1;         h2[ans] = a1[f6[w]] + 1;         ans++;         for (e = 0; e < q; e++) {           aa[e] = a[e];           ss[e] = s[e];           dd[e] = d[e];           aa1[e] = a1[e];         }         q1 = q;         del(q1, aa, ss, dd, aa1, f1[w], f2[w], f3[w], f4[w], a[r], s[r], d[r]);         if (slv(q1, y - 1, aa, ss, dd, aa1, 1)) return 1;         ans--;         addim(f1[w], f2[w], f3[w], f4[w]);       }     impos = im0;     return 0;   }   int main() {     int q, q1, w, e, r, r1, r2, r3, t, y, u, max1, max2;     for (w = 1; w <= 26; w++) h[w * (w - 1) / 2] = w;     cin >> q >> y;     my = y;     for (w = 0; w < q; w++) {       scanf( %I64d%I64d%I64d , &a[w], &s[w], &d[w]);       a1[w] = w;     }     if (!slv(q, y, a, s, d, a1, 0))       cout <<  NO ;     else {       cout <<  YES n  << ans <<   n ;       for (w = 0; w < ans; w++) cout << h1[w] <<     << h2[w] <<   n ;     }     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   int mat[1001][1001][2];   int dp1[1001][1001];   int dp2[1001][1001];   int dx[2] = {0, 1};   int dy[2] = {1, 0};   vector<pair<int, int> > vx;   void findxx1(int i, int j);   void findxx2(int i, int j);   int chk(int x, int y, int n) {     if (x >= n || y >= n || y < 0 || x < 0)       return 0;     else       return 1;   }   struct parent {     int x;     int y;   };   struct parent par1[1001][1001], par2[1001][1001];   struct node {     int x;     int y;   };   void bfs2(int n) {     int i, j, x, y;     queue<node> q;     node a;     a.x = 0;     a.y = 0;     q.push(a);     for (i = 0; i < n; i++)       for (j = 0; j < n; j++) dp1[i][j] = 99999;     dp1[0][0] = mat[0][0][0];     while (!q.empty()) {       x = q.front().x;       y = q.front().y;       q.pop();       for (i = 0; i < 2; i++) {         int x1, y1;         x1 = x + dx[i];         y1 = y + dy[i];         if (chk(x1, y1, n)) {           if (dp1[x1][y1] > dp1[x][y] + mat[x1][y1][0]) {             dp1[x1][y1] = dp1[x][y] + mat[x1][y1][0];             a.x = x1;             a.y = y1;             q.push(a);             par1[x1][y1].x = x;             par1[x1][y1].y = y;           }         }       }     }   }   void bfs5(int n) {     int i, j, x, y;     queue<node> q;     node a;     a.x = 0;     a.y = 0;     q.push(a);     for (int i = 0; i < n; i++)       for (j = 0; j < n; j++) dp2[i][j] = 99999;     dp2[0][0] = mat[0][0][1];     while (!q.empty()) {       x = q.front().x;       y = q.front().y;       q.pop();       for (i = 0; i < 2; i++) {         int x1, y1;         x1 = x + dx[i];         y1 = y + dy[i];         if (chk(x1, y1, n)) {           if (dp2[x1][y1] > dp2[x][y] + mat[x1][y1][1]) {             dp2[x1][y1] = dp2[x][y] + mat[x1][y1][1];             a.x = x1;             a.y = y1;             q.push(a);             par2[x1][y1].x = x;             par2[x1][y1].y = y;           }         }       }     }   }   void zeroPrint(int x, int y, int n) {     int i, j, k;     for (i = 0; i < x; i++) cout <<  D ;     for (i = 0; i < y; i++) cout <<  R ;     for (i = x; i < n - 1; i++) cout <<  D ;     for (i = y; i < n - 1; i++) cout <<  R ;   }   int main() {     ios_base::sync_with_stdio(0);     vx.reserve(10000);     int n, i, j, k, x, xx, yy, zero = 0;     cin >> n;     for (i = 0; i < n; i++) {       for (j = 0; j < n; j++) {         cin >> x;         if (x == 0) {           zero = 1;           xx = i;           yy = j;         } else {           int tmp = x;           while (tmp && tmp % 2 == 0) {             mat[i][j][0]++;             tmp /= 2;           }           while (tmp && tmp % 5 == 0) {             mat[i][j][1]++;             tmp /= 5;           }         }       }     }     bfs2(n);     bfs5(n);     int ret = min(dp1[n - 1][n - 1], dp2[n - 1][n - 1]);     if (zero && ret > 1) {       cout << 1 << endl;       zeroPrint(xx, yy, n);     } else {       cout << ret << endl;       vx.push_back({n - 1, n - 1});       if (dp1[n - 1][n - 1] > dp2[n - 1][n - 1]) {         findxx2(n - 1, n - 1);       } else         findxx1(n - 1, n - 1);       reverse(vx.begin(), vx.end());       for (i = 1; i < vx.size(); i++) {         if (vx[i - 1].first == vx[i].first)           cout <<  R ;         else           cout <<  D ;       }       cout << endl;     }   }   void findxx1(int i, int j) {     if (i == 0 && j == 0) {       return;     } else {       vx.push_back({par1[i][j].x, par1[i][j].y});       findxx1(par1[i][j].x, par1[i][j].y);     }   }   void findxx2(int i, int j) {     if (i == 0 && j == 0) {       return;     } else {       vx.push_back({par2[i][j].x, par2[i][j].y});       findxx2(par2[i][j].x, par2[i][j].y);     }   }


#include <bits/stdc++.h>   using namespace std;   long long N, M, K, ans;   long long a[105][21005];   long long sum[105][21005];   long long tree[21005 * 8];   long long lazy[21005 * 8];   long long dp[21005 * 8];   void updLazy(long long x, long long l, long long r) {     if (!lazy[x]) return;     tree[x] += lazy[x];     lazy[2 * x + 1] += lazy[x];     lazy[2 * x + 2] += lazy[x];     lazy[x] = 0;   }   void upd(long long x, long long l, long long r, long long lq, long long rq,            long long v, bool t) {     if (r < l) return;     updLazy(x, l, r);     if (l > rq or r < lq) return;     if (l >= lq && r <= rq) {       if (t) tree[x] = lazy[x] = 0;       lazy[x] += v;       updLazy(x, l, r);       return;     }     long long mid = (l + r) / 2;     upd(2 * x + 1, l, mid, lq, rq, v, t);     upd(2 * x + 2, mid + 1, r, lq, rq, v, t);     tree[x] = max(tree[2 * x + 1], tree[2 * x + 2]);   }   long long suma2(long long i, long long j) {     return sum[i][j + K - 1] - sum[i][j - 1] + sum[i + 1][j + K - 1] -            sum[i + 1][j - 1];   }   int main() {     cin >> N >> M >> K;     for (long long i = 1; i <= N; i++)       for (long long j = 1; j <= M; j++) {         cin >> a[i][j];         sum[i][j] = sum[i][j - 1] + a[i][j];       }     for (long long i = 1; i <= N; i++)       for (long long j = M + 1; j <= M; j++) sum[i][j] = sum[i][j - 1];     for (long long i = N; i >= 1; i--) {       for (long long j = 1; j + K - 1 <= M; j++) {         if (j <= K)           upd(0, 1, M, j, j, dp[j] - sum[i + 1][K] + sum[i + 1][j - 1], 1);         else           upd(0, 1, M, j, j, dp[j], 1);       }       for (long long j = 1; j + K - 1 <= M; j++) {         dp[j] = suma2(i, j) + tree[0];         ans = max(ans, dp[j]);         upd(0, 1, M, max(1LL, j - K + 1), j, a[i + 1][j], 0);         upd(0, 1, M, j + 1, min(M, j + K), -a[i + 1][j + K], 0);         ans = max(ans, dp[j]);       }     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O2 )   using namespace std;   int main() {     int n, co = 1;     std::vector<pair<long long, long long>> v;     cin >> n;     for (int i = 0; i < n; i++) {       long long a, b;       cin >> a >> b;       v.push_back(make_pair(a, b));     }     for (int i = 1; i < n; i++) {       if (v[i].first - v[i].second > v[i - 1].first) {         co++;       } else if (v[i].first + v[i].second < v[i + 1].first) {         v[i].first = v[i].first + v[i].second;         co++;       } else if (i == n - 1) {         co++;       }     }     cout << co;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, m;   vector<long long> a(30005);   bool check(long long v) {     long long i, val = 0;     for (i = 0; i < n; i++) {       long long x = a[i];       long long y = (a[i] + v) % m;       if (y >= x) {         if (x > val) val = x;         if (y < val) return false;       } else {         if (val > y) val = max(val, x);       }     }     return true;   }   void solve() {     cin >> n >> m;     a.resize(n);     for (auto &x : a) cin >> x;     long long low = 0, high = m, mid, ans = m;     while (low <= high) {       mid = (low + high) / 2;       long long z = check(mid);       if (z) {         ans = mid;         high = mid - 1;       } else         low = mid + 1;     }     cout << ans <<   n ;   }   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     long long t = 1;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 200009;   vector<pair<int, int> > grafo[MAXN];   int upth[MAXN], dis[MAXN];   int Build(int u, int p, int upd, int gd) {     upth[u] = upd;     dis[u] = gd;     int ct = 0;     for (int i = 0; i < grafo[u].size(); ++i) {       int v = grafo[u][i].first;       if (v != p) {         int res = Build(v, u, upd + grafo[u][i].second, gd + 1);         ct += res + grafo[u][i].second;       }     }     return ct;   }   int main() {     int N;     scanf( %d n , &N);     for (int i = 1; i < N; ++i) {       int u, v;       scanf( %d%d , &u, &v);       grafo[u].push_back(pair<int, int>(v, 0));       grafo[v].push_back(pair<int, int>(u, 1));     }     int UT = Build(1, 0, 0, 0);     int mint = MAXN;     for (int i = 1; i <= N; ++i) mint = min(mint, UT - (2 * upth[i]) + dis[i]);     printf( %d n , mint);     int cnt = 0;     for (int i = 1; i <= N; ++i)       if ((UT - (2 * upth[i]) + dis[i]) == mint) {         if (cnt++) printf(   );         printf( %d , i);       }     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class A>   void read(vector<A>& v) {     for (auto& x : v) cin >> x;   }   template <class c>   struct rge {     c b, e;   };   template <class c>   rge<c> range(c i, c j) {     return rge<c>{i, j};   }   template <class c>   auto dud(c* x) -> decltype(cout << *x, 0);   template <class c>   char dud(...);   struct debug {     ~debug() { cout << endl; }     template <class c>     typename enable_if<sizeof dud<c>(0) != 1, debug&>::type operator<<(c i) {       cout << boolalpha << i;       return *this;     }     template <class c>     typename enable_if<sizeof dud<c>(0) == 1, debug&>::type operator<<(c i) {       return *this << range(begin(i), end(i));     }     template <class c, class b>     debug& operator<<(pair<b, c> d) {       return *this <<  (  << d.first <<  ,   << d.second <<  ) ;     }     template <class c>     debug& operator<<(rge<c> d) {       *this <<  [ ;       for (auto it = d.b; it != d.e; ++it) *this <<  ,   + 2 * (it == d.b) << *it;       return *this <<  ] ;     }   };   const long MOD = 1000000007;   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     ;     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       int o = 0, z = 0;       for (int _ = 0; _ < n; _++) {         int v;         cin >> v;         if (v == 1)           o++;         else           z++;       }       int times, val;       if (o > z) {         times = o;         val = 1;       } else {         times = z;         val = 0;       }       if (val == 1 && times % 2 && val == 1) times--;       cout << times << endl;       for (int _ = 0; _ < times; _++) cout << val <<    ;       cout << endl;     }   }


#include <bits/stdc++.h>   int min(int a, int b) { return (a < b ? a : b); }   int max(int a, int b) { return (a > b ? a : b); }   int main() {     char a[10], b[10];     int x, y;     scanf( %s n%s , a, b);     if (strcmp(a,  sunday ) == 0)       x = 0;     else if (strcmp(a,  monday ) == 0)       x = 1;     else if (strcmp(a,  tuesday ) == 0)       x = 2;     else if (strcmp(a,  wednesday ) == 0)       x = 3;     else if (strcmp(a,  thursday ) == 0)       x = 4;     else if (strcmp(a,  friday ) == 0)       x = 5;     else if (strcmp(a,  saturday ) == 0)       x = 6;     if (strcmp(b,  sunday ) == 0)       y = 0;     else if (strcmp(b,  monday ) == 0)       y = 1;     else if (strcmp(b,  tuesday ) == 0)       y = 2;     else if (strcmp(b,  wednesday ) == 0)       y = 3;     else if (strcmp(b,  thursday ) == 0)       y = 4;     else if (strcmp(b,  friday ) == 0)       y = 5;     else if (strcmp(b,  saturday ) == 0)       y = 6;     if (x == y)       printf( YES );     else if (y == (x + 2) % 7)       printf( YES );     else if (y == (x + 3) % 7)       printf( YES );     else       printf( NO );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string s, c;   vector<string> v, s1, s2;   bool b1(string &d) {     if (d.size()) {       if (d[0] ==  0  && d.size() == 1) {         return true;       } else if (d[0] ==  0 ) {         return false;       } else {         bool ans = true;         for (int i = 0; i < d.size(); ++i) {           if (!( 0  <= d[i] && d[i] <=  9 )) {             ans = false;             break;           }         }         return ans;       }     } else {       return false;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.precision(11);     cout.setf(ios::fixed);     getline(cin, s);     c =   ;     for (int i = 0; i < s.size(); ++i) {       if (s[i] ==  ,  || s[i] ==  ; ) {         if (b1(c)) {           s1.push_back(c);           c =   ;         } else {           s2.push_back(c);           c =   ;         }       } else {         c.append(1, s[i]);       }     }     if (b1(c)) {       s1.push_back(c);       c =   ;     } else {       s2.push_back(c);       c =   ;     }     if (s1.size()) {       cout <<     << s1[0];       for (int i = 1; i < s1.size(); ++i) {         cout <<  ,  << s1[i];       }       cout <<     << endl;     } else {       cout <<  -  << endl;     }     if (s2.size()) {       cout <<     << s2[0];       for (int i = 1; i < s2.size(); ++i) {         cout <<  ,  << s2[i];       }       cout <<     << endl;     } else {       cout <<  -  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   map<long long, int> m;   int main() {     int n;     scanf( %d , &n);     long long count = 0;     int flag = 0;     for (int i = 0; i < n; i++) {       long long c;       cin >> c;       if (c > 0) {         m[c] += 1;         if (m[c] == 2) count++;         if (m[c] > 2) flag = 1;       }     }     if (flag)       cout <<  -1  << endl;     else       cout << count << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int vis[100005];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     int dis[n][n];     vector<int> arr(n);     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++) cin >> dis[i][j];     for (int i = 0; i < n; i++) cin >> arr[i];     reverse(arr.begin(), arr.end());     vector<long long> ans;     for (int k = 0; k < n; k++) {       int x = arr[k] - 1;       vis[x] = 1;       for (int i = 0; i < n; i++) {         for (int j = 0; j < n; j++) {           dis[i][j] = min(dis[i][j], dis[i][x] + dis[x][j]);         }       }       long long sum = 0;       for (int i = 0; i < n; i++) {         if (!vis[i]) continue;         for (int j = 0; j < n; j++)           if (vis[j]) sum += dis[i][j];       }       ans.push_back(sum);     }     reverse(ans.begin(), ans.end());     for (int i = 0; i < ans.size(); i++) cout << ans[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long mod = 1e9 + 7;   int main() {     long long n = 1, k = 1;     int t;     cin >> t;     for (int i = 1; i <= t; i++) {       n %= mod;       k %= mod;       n *= 27;       k *= 7;     }     while (n < k) n += mod;     n -= k;     cout << n % mod << endl;   }


#include <bits/stdc++.h>   using namespace std;   long long int arr[2005];   long long int dp[2005][2005];   long long int n, h;   long long int calc(long long int id, long long int prev) {     if (id == n + 1) {       return !prev;     }     long long int ans = dp[id][prev];     if (ans != -1) {       return ans;     }     long long int val = arr[id] + prev;     ans = 0;     if (val == h) {       ans = calc(id + 1, prev);       if (prev) {         ans = (ans + (prev * calc(id + 1, prev - 1)) % 1000000007) % 1000000007;       }     } else if (val == h - 1) {       ans = calc(id + 1, prev + 1);       ans = (ans + calc(id + 1, prev)) % 1000000007;       ans = (ans + (prev * calc(id + 1, prev)) % 1000000007) % 1000000007;     }     return (dp[id][prev] = ans);   }   int main() {     memset(dp, -1, sizeof(dp));     scanf( %lld , &n);     scanf( %lld , &h);     long long int i;     for (i = 1; i <= n; i++) {       scanf( %lld , &arr[i]);     }     long long int ans = calc(1, 0);     printf( %lld , ans);     ;     printf(  n );     return 0;   }


#include <bits/stdc++.h>   int n, m, H, T, x, y, l, Mark;   int son[200005], ed[200005], next[200005], v[200005], d[200005];   void work(int x, int y) {     ++Mark;     int h = 0, t = 0;     for (int p = son[x]; p; p = next[p])       if (ed[p] != y) v[ed[p]] = Mark, h++;     for (int p = son[y]; p; p = next[p])       if (ed[p] != x)         if (v[ed[p]] != Mark)           t++;         else if (h > H)           v[ed[p]] = 0, h--, t++;     if (h >= H && t >= T) {       printf( YES n%d %d n , x, y);       for (int p = son[x]; p && H; p = next[p])         if (ed[p] != y)           if (v[ed[p]] == Mark) printf( %d%s , ed[p], --H ?     :   n );       for (int p = son[y]; p && T; p = next[p])         if (ed[p] != x)           if (v[ed[p]] != Mark) printf( %d%s , ed[p], --T ?     :   n );       exit(0);     }   }   int main() {     scanf( %d%d%d%d , &n, &m, &H, &T);     for (int i = 1; i <= m; i++)       scanf( %d%d , &x, &y), d[x]++, d[y]++, ed[++l] = y, next[l] = son[x],                                              son[x] = l, ed[++l] = x,                                              next[l] = son[y], son[y] = l;     for (int i = 1; i <= n; i++)       if (d[i] > H)         for (int p = son[i]; p; p = next[p])           if (d[ed[p]] > T) work(i, ed[p]);     printf( NO n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, m, xx;     cin >> n >> m >> xx;     map<char, long long int> mp;     vector<char> v[n];     for (long long int i = 0; i < n; i++) {       string s;       cin >> s;       for (auto j : s) v[i].push_back(j);       for (long long int j = 0; j < m; j++) mp[s[j]]++;     }     if (mp[ S ] > 0) {       mp[ S ] = 0;       for (auto i : mp) {         char c = i.first - 32;         if (i.first !=  S ) mp[c]++;       }     }     long long int q;     cin >> q;     string s;     cin >> s;     for (long long int i = 0; i < q; i++) {       if (mp[s[i]] == 0) {         cout <<  -1 ;         return 0;       }     }     vector<pair<long long int, long long int>> shift;     for (long long int i = 0; i < n; i++) {       for (long long int j = 0; j < m; j++) {         if (v[i][j] ==  S ) shift.push_back({i, j});       }     }     vector<long long int> chk[200];     for (long long int i = 0; i < n; i++) {       for (long long int j = 0; j < m; j++) {         for (auto m : shift) {           long long int x = m.first;           long long int y = m.second;           long long int ans = ((x - i) * (x - i)) + ((y - j) * (y - j));           if (ans <= (xx * xx)) chk[v[i][j] - 32].push_back(ans);         }       }     }     long long int c = 0;     for (long long int i = 0; i < q; i++) {       if (s[i] >=  A  && s[i] <=  Z ) {         for (auto j : chk[s[i]]) {           if (j <= (xx * xx)) goto done;         }         c++;       }     done:       1;     }     cout << c;   }


#include <bits/stdc++.h>   using namespace std;   void make_unique(vector<long long> vec) {     sort((vec).begin(), (vec).end());     vec.resize(unique((vec).begin(), (vec).end()) - vec.begin());   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) {       long long k, n, m, i, j, flag = 0, count = 0, move = 0;       string s;       cin >> n;       long long A[n];       vector<long long> v;       for (i = 0; i < n; i++) cin >> A[i];       long long freq[51] = {0};       for (i = 0; i < n; i++) {         freq[A[i]]++;       }       long long maxf = freq[0];       long long pos = 0;       vector<long long> sum(105, 0);       for (i = 0; i <= n; i++) {         for (j = i; j <= n; j++) {           if (i == j)             sum[i + j] += freq[i] / 2;           else {             sum[i + j] += min(freq[i], freq[j]);           }         }       }       cout << *max_element((sum).begin(), (sum).end()) << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int nmax = 52, inf = int(1e9), mod = int(1e9) + 7;   int n, K;   int dp[2][nmax][nmax], ways[2][nmax][nmax];   int comb[nmax][nmax];   int t[2];   int main() {     cin >> n >> K;     int w;     for (int i = 0; i < (int)n; ++i) {       cin >> w;       t[w != 50]++;     }     for (int k = 0; k < (int)2; ++k) {       for (int i = 0; i < (int)nmax; ++i) {         for (int j = 0; j < (int)nmax; ++j) {           dp[k][i][j] = inf;         }       }     }     comb[0][0] = 1;     for (int i = 1; i < nmax; i++) {       comb[i][0] = comb[i][i] = 1;       for (int j = 1; j < i; ++j) {         comb[i][j] = (comb[i - 1][j] + comb[i - 1][j - 1]) % mod;       }     }     dp[0][0][0] = 0;     ways[0][0][0] = 1;     int side = 0;     for (int moves = 1;; moves++, side ^= 1) {       int cSide = side ^ 1;       if (moves == 1) {         for (int i = 0; i <= t[0]; ++i) {           for (int j = 0; j <= t[1]; ++j) {             if ((i > 0 || j > 0) && i * 50 + j * 100 <= K) {               dp[cSide][i][j] = 1;               ways[cSide][i][j] = 1ll * comb[t[0]][i] * comb[t[1]][j] % mod;             }           }         }         continue;       }       bool ok = false;       for (int i = 0; i <= t[0]; ++i) {         for (int j = 0; j <= t[1]; ++j) {           if ((!i && !j) || (i == t[0] && j == t[1]) || dp[side][i][j] == inf)             continue;           int oi = t[0] - i;           int oj = t[1] - j;           for (int k = 0; k <= i; ++k) {             for (int w = 0; w <= j; ++w) {               if (k + w > 0 && k * 50 + w * 100 <= K) {                 if (dp[cSide][oi + k][oj + w] > moves) {                   dp[cSide][oi + k][oj + w] = moves;                   ways[cSide][oi + k][oj + w] =                       (1ll * ways[side][i][j] * comb[i][k] % mod) * 1ll *                       comb[j][w] % mod;                   ok = true;                 } else if (dp[cSide][oi + k][oj + w] == moves) {                   ways[cSide][oi + k][oj + w] +=                       (1ll * ways[side][i][j] * comb[i][k] % mod) * 1ll *                       comb[j][w] % mod;                   ways[cSide][oi + k][oj + w] %= mod;                 }               }             }           }         }       }       if (!ok) break;     }     if (dp[1][t[0]][t[1]] == inf) {       cout <<  -1 n0 ;     } else {       cout << dp[1][t[0]][t[1]] <<   n  << ways[1][t[0]][t[1]];     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, x, y;     map<long long, long long> mx, my;     map<tuple<long long, long long>, long long> mt;     scanf( %lld , &n);     for (int i = 0; i < n; i++) {       scanf( %lld%lld , &x, &y);       tuple<long long, long long> a = make_tuple(x, y);       mx[x]++;       my[y]++;       mt[a]++;     }     long long ans = 0;     for (auto a : mx) {       long long b = a.second;       ans += b * (b - 1) / 2;     }     for (auto a : my) {       long long b = a.second;       ans += b * (b - 1) / 2;     }     for (auto a : mt) {       long long b = a.second;       ans -= b * (b - 1) / 2;     }     printf( %lld n , ans);   }


#include <bits/stdc++.h>   using namespace std;   string str;   void push(stack<pair<bool, int>>& stk, int offset) {     if (offset == 0) return;     pair<bool, int> cur;     if (stk.size() && stk.top().first)       cur = stk.top(), stk.pop(), stk.push({1, cur.second + offset});     else       stk.push({1, offset});   }   bool fix_stk(stack<pair<bool, int>>& stk) {     int offset = 0;     while (stk.size() && (stk.top().first || stk.top().second + offset < 0))       offset += stk.top().second * stk.top().first, stk.pop();     if (stk.size() == 0) return false;     pair<bool, int> cur = {0, stk.top().second + offset};     stk.pop();     push(stk, offset);     stk.push(cur);     return true;   }   bool operation(stack<pair<bool, int>>& stk, int idx) {     pair<bool, int> cur = {0, -1};     if (str[idx] ==  ? ) {       if (fix_stk(stk) == false) return false;       cur = stk.top();       stk.pop();       push(stk, 1);       stk.push({0, cur.second + 1});       if (cur.second - 1 >= 0) stk.push({0, cur.second - 1});     } else       push(stk, (str[idx] ==  ( ) - (str[idx] ==  ) ));     return true;   }   int solve(int idx) {     int ret = 0;     stack<pair<bool, int>> stk;     stk.push({0, 0});     while ((idx < str.size()) && stk.size()) {       if (operation(stk, idx) == false) return ret;       if (fix_stk(stk) == false) return ret;       ret += stk.top().second == 0;       idx++;     }     return ret;   }   int mine() {     int ret = 0;     for (int i = 0; i < str.size(); i++) ret += solve(i);     return ret;   }   int main() {     cin >> str;     cout << mine() << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int cp[1000010], n;   int dfs(int first) {     int second = 0;     for (int i = 1;; i++)       if ((1 << i) - 1 >= first) {         return (1 << i) - 1 ^ first;       }   }   int main() {     scanf( %d , &n);     for (int i = n; i >= 1; i--)       if (!cp[i]) {         cp[i] = dfs(i);         cp[cp[i]] = i;       }     long long ans = 0;     for (int i = n; i >= 0; i--) {       ans += i ^ cp[i];     }     cout << ans << endl;     for (int i = 0; i <= n; i++) {       printf( %d  , cp[i]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n, c, b;       cin >> n >> c >> b;       int a[n];       for (int i = 0; i < n; i++) {         a[i] = i + 1;       }       if (n - 2 < c + b || abs(c - b) > 1) {         cout <<  -1 ;       } else {         if (c == b) {           for (int i = 1; i <= 2 * c; i += 2) {             swap(a[i], a[i + 1]);           }         } else if (c < b) {           int j = b;           for (int i = 0; j > 0; i += 2) {             swap(a[i], a[i + 1]);             j--;           }         } else if (c > b) {           int j = c;           for (int i = n - 1; j > 0; i = i - 2) {             swap(a[i], a[i - 1]);             j--;           }         }         for (int i = 0; i < n; i++) {           cout << a[i] <<    ;         }       }       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int ar[50][50];   int dp[51][51];   bool leaf[50];   vector<int> adj[50];   vector<int> leafs;   int bad;   vector<int> pos;   int go(int rem, int now) {     if (rem == 0) {       return 0;     }     if (dp[rem][now] != -1) {       return dp[rem][now];     }     int low = 0;     int high = 125000;     while (low < high) {       int mid = (low + high + 1) / 2;       int temp = rem;       for (int i = 0; i < n; i++) {         if (!leaf[i] || i == now) {           continue;         }         int cur = 0;         while (temp > 0 && ar[now][i] + go(rem - cur - 1, i) >= mid) {           cur++;           temp--;         }       }       if (temp == 0) {         low = mid;       } else {         high = mid - 1;       }     }     dp[rem][now] = low;     return low;   }   void dfs(int now, int from) {     if (leaf[now]) {       leafs.push_back(now);     }     for (int i = 0; i < pos.size(); i++) {       if (now == pos[i]) {         bad++;       }     }     for (int i = 0; i < adj[now].size(); i++) {       int to = adj[now][i];       if (to != from) {         dfs(to, now);       }     }   }   int main() {     std::ios::sync_with_stdio(false);     cin.tie(0);     cin >> n;     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         if (i == j) {           ar[i][j] = 0;         } else {           ar[i][j] = 25500000;         }       }     }     int maxw = 0;     for (int i = 1; i < n; i++) {       int a, b, w;       cin >> a >> b >> w;       a--;       b--;       adj[a].push_back(b);       adj[b].push_back(a);       ar[a][b] = w;       ar[b][a] = w;       maxw = max(maxw, w);     }     assert(maxw <= 50);     for (int k = 0; k < n; k++) {       for (int i = 0; i < n; i++) {         for (int j = 0; j < n; j++) {           ar[i][j] = min(ar[i][j], ar[i][k] + ar[k][j]);         }       }     }     for (int i = 0; i <= 50; i++) {       for (int j = 0; j <= 50; j++) {         dp[i][j] = -1;       }     }     for (int i = 0; i < n; i++) {       leaf[i] = adj[i].size() == 1;     }     int start, m;     cin >> start >> m;     start--;     for (int i = 0; i < m; i++) {       int x;       cin >> x;       x--;       pos.push_back(x);     }     int ans = 125000;     if (n == 1) {       assert(false);       ans = 0;     }     for (int i = 0; i < adj[start].size(); i++) {       leafs.clear();       leafs.resize(0);       bad = 0;       dfs(adj[start][i], start);       if (bad == 0) {         continue;       }       int low = 0;       int high = ans + 2;       while (low < high) {         int mid = (low + high + 1) / 2;         int temp = bad;         for (int z = 0; z < leafs.size(); z++) {           int cl = leafs[z];           if (cl == start) {             continue;           }           int cur = 0;           while (temp > 0 && ar[start][cl] + go(m - cur - 1, cl) >= mid) {             cur++;             temp--;           }         }         if (temp == 0) {           low = mid;         } else {           high = mid - 1;         }       }       ans = min(ans, low);     }     assert(ans != 125000 && ans != 0);     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, k, a[100001][6], ans[6];   multiset<int> st[6];   long long sum() {     long long ret = 0;     for (int i = 1; i <= m; i++) ret += *st[i].rbegin();     return ret;   }   int main() {     scanf( %d%d%d , &n, &m, &k);     for (int i = 1; i <= n; i++)       for (int t = 1; t <= m; t++) scanf( %d , &a[i][t]);     long long curr = 0;     int res = 0;     for (int i = 1, j = 1; i <= n; i++) {       for (int t = 1; t <= m; t++) st[t].insert(a[i][t]);       while (j <= i and sum() > k) {         for (int t = 1; t <= m; t++) st[t].erase(st[t].find(a[j][t]));         j++;       }       if (i - j + 1 > res) {         for (int t = 1; t <= m; t++) ans[t] = *st[t].rbegin();         res = i - j + 1;       }     }     for (int t = 1; t <= m; t++) printf( %d  , ans[t]);   }


#include <bits/stdc++.h>   using namespace std;   void think() {     long long n;     cin >> n;     vector<long long> a(n);     for (long long i = 0; i < n; i++) {       cin >> a[i];     }     long long ans = 0;     unordered_map<long long, long long> mp;     mp[a[0]]++;     for (long long i = 1; i < n; i++) {       long long x = a[i];       a[i] += a[i - 1];       if (mp.find(a[i]) != mp.end() || a[i] == 0) {         ans++;         mp.clear();         a[i] = x;         mp[a[i]]++;       } else {         mp[a[i]]++;       }     }     cout << ans <<   n ;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     ;     long long testcase = 1;     while (testcase--) {       think();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int M = 11, L = 11, N = 1002;   const int Mod = 1e9 + 9;   char a[L], to[99];   int n;   int dp[2][M * L][N], ch[M * L][4], fail[M * L];   int len[N];   int ans = 0;   inline void mo(int& x) { x = (x >= Mod ? x - Mod : x); }   struct AC_automaton {     int cnt;     inline void init() {       cnt = 0;       to[ A ] = 0, to[ C ] = 1, to[ G ] = 2, to[ T ] = 3;     }     inline void insert() {       int l = strlen(a + 1), now = 0;       for (int i = 1; i <= l; i++) {         if (!ch[now][to[a[i]]]) ch[now][to[a[i]]] = ++cnt;         now = ch[now][to[a[i]]];       }       len[now] = max(len[now], l);     }     inline void build() {       queue<int> Q;       for (int i = 0; i < 4; i++)         if (ch[0][i]) Q.push(ch[0][i]);       while (!Q.empty()) {         int x = Q.front();         Q.pop();         len[x] = max(len[x], len[fail[x]]);         for (int i = 0; i < 4; i++) {           if (ch[x][i])             fail[ch[x][i]] = ch[fail[x]][i], Q.push(ch[x][i]);           else             ch[x][i] = ch[fail[x]][i];         }       }     }     inline void work() {       dp[0][0][1] = 1;       for (int i = 1; i <= n; i++) {         memset(dp[i & 1], 0, sizeof(dp[i & 1]));         for (int j = 0; j <= cnt; j++)           for (int k = 0; k <= i; k++) {             if (dp[!(i & 1)][j][k]) {               for (int t = 0; t < 4; t++) {                 if (len[ch[j][t]] + k > i)                   mo(dp[i & 1][ch[j][t]][i + 1] += dp[!(i & 1)][j][k]);                 else                   mo(dp[i & 1][ch[j][t]][k] += dp[!(i & 1)][j][k]);               }             }           }       }       for (int j = 0; j <= cnt; j++) mo(ans += dp[n & 1][j][n + 1]);     }   } T;   int main() {     int m;     scanf( %d%d , &n, &m);     T.init();     for (int i = 1; i <= m; i++) {       scanf( %s , a + 1);       T.insert();     }     T.build();     T.work();     printf( %d , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     int x = 0, y = 0;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) y = 1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 )       x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();     return y ? -x : x;   }   template <typename T>   inline T read() {     T x = 0;     int y = 0;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) y = 1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 )       x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();     return y ? -x : x;   }   char s[40];   long long pw[40] = {-0x3f3f3f3f, 1}, f[40][40];   bool g[40][40];   signed main() {     int n = read();     scanf( %s , s + 1);     for (register int i = 2; i <= n; ++i) pw[i] = pw[i - 1] * 10;     memset(f, ~0x3f, sizeof f);     f[(n << 1) + 1][0] = 0;     for (register int i = n << 1; i; --i)       for (register int j = 0; j <= min((n << 1) - i + 1, n); ++j) {         f[i][j] = max(f[i + 1][j - 1] + pw[j] * (s[i] -  0 ),                       f[i + 1][j] + pw[(n << 1) - i + 1 - j] * (s[i] -  0 ));         g[i][j] = f[i + 1][j - 1] + pw[j] * (s[i] -  0 ) >                   f[i + 1][j] + pw[(n << 1) - i + 1 - j] * (s[i] -  0 );       }     for (register int i = 1, j = n; i <= n << 1; ++i)       putchar(g[i][j] ?  H  :  M ), j -= g[i][j];     putchar(  n );   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   int n, m, q, i, s, j, k, u, dis[N][350], lazy[350], W[N];   long long sum[N], arr[N], x, Y[350];   char c;   vector<int> G[N], F[N];   bool H[N], is[N][350];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> m >> q;     for (i = 1; i <= n; i++) cin >> arr[i];     for (i = 1; i <= m; i++) {       cin >> s;       G[i].resize(s);       if (s >= 350) H[i] = 1, u++, W[i] = u - 1;       for (j = 0; j < s; j++) {         cin >> G[i][j];         if (H[i]) is[G[i][j]][u - 1] = 1, sum[u - 1] += arr[G[i][j]];       }     }     for (i = 1; i <= m; i++) {       for (int j : G[i]) {         for (int k = 0; k <= 340; k++)           if (is[j][k]) dis[i][k]++;       }     }     while (q--) {       cin >> c >> k;       if (c ==  ? ) {         if (H[k] == 0) {           long long r = 0;           for (int j : G[k]) r += 1ll * arr[j];           for (i = 0; i < 340; i++) r += Y[i] * dis[k][i];           cout << r <<   n ;         } else           cout << sum[W[k]] <<   n ;       } else {         cin >> x;         if (!H[k]) {           for (int j : G[k]) arr[j] += x;           for (i = 0; i < 340; i++) sum[i] += x * dis[k][i];         } else {           for (i = 0; i < 340; i++) sum[i] += 1ll * x * dis[k][i];           Y[W[k]] += x;         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   long long odd[200005], even[200005];   int main() {     long long n, t, x, y;     cin >> n;     long long ara[n + 3];     long long sum = 0, cnt = 0;     for (int i = 1; i <= n; i++) {       cin >> ara[i];       sum += ara[i];       if (i % 2 == 0) {         even[i] = even[i - 1] + ara[i];         odd[i] = odd[i - 1];       } else {         odd[i] = odd[i - 1] + ara[i];         even[i] = even[i - 1];       }     }     for (int i = 1; i <= n; i++) {       long long one = odd[i - 1];       one += (even[n] - even[i]);       long long two = sum - (one + ara[i]);       if (one == two) cnt++;     }     cout << cnt << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cout.tie(0);     cin.tie(0);     string s;     cin >> s;     long long dp[s.length() + 1], mod = 1e9 + 7, f = 0;     dp[0] = 1;     dp[1] = 1;     if (s[0] ==  m  || s[0] ==  w ) f = 1;     for (long long i = 2; i <= s.length(); i++) {       if (s[i - 1] ==  m  || s[i - 1] ==  w )         f = 1;       else if ((s[i - 1] ==  n  || s[i - 1] ==  u ) && (s[i - 1] == s[i - 2]))         dp[i] = (dp[i - 2] + dp[i - 1]) % mod;       else         dp[i] = dp[i - 1];     }     if (f)       cout << 0 << endl;     else       cout << dp[s.length()] << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int r1, c1, r2, c2;     cin >> r1 >> c1 >> r2 >> c2;     if (r1 == r2 || c1 == c2)       cout << 1;     else       cout << 2;     cout <<    ;     if ((r1 + c1) % 2 != (r2 + c2) % 2)       cout << 0;     else {       if (r1 + c1 == r2 + c2 || r1 - c1 == r2 - c2)         cout << 1;       else {         cout << 2;       }     }     cout <<    ;     cout << max(abs(r1 - r2), abs(c1 - c2)) << endl;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize(2,  Ofast ,  inline ,  -fgcse ,  -fgcse-lm ,  -fipa-sra ,                          -ftree-pre ,  -ftree-vrp ,  -fpeephole2 ,  -ffast-math ,                          -fsched-spec ,  unroll-loops ,  -falign-jumps ,                                   -falign-loops ,  -falign-labels ,  -fdevirtualize ,                               -fcaller-saves ,  -fcrossjumping ,  -fthread-jumps ,                              -funroll-loops )   #pragma GCC target(         sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native )   using namespace std;   char BB[1 << 20], *SS = BB, *TT = BB;   inline long long read() {     long long s = 0;     char ch =         (SS == TT && (TT = (SS = BB) + fread(BB, 1, 1 << 20, stdin), SS == TT)              ? EOF              : *SS++);     while (!((ch >=  0 ) && (ch <=  9 )))       ch = (SS == TT && (TT = (SS = BB) + fread(BB, 1, 1 << 20, stdin), SS == TT)                 ? EOF                 : *SS++);     while (((ch >=  0 ) && (ch <=  9 )))       s = (s << 3) + (s << 1) + (ch ^ 48),       ch = (SS == TT && (TT = (SS = BB) + fread(BB, 1, 1 << 20, stdin), SS == TT)                 ? EOF                 : *SS++);     return s;   }   const int mod = 1000000007;   inline long long che(long long a) { return a >= mod ? a - mod : a; }   inline long long ksm(long long a, long long b) {     if (b < 0) return 0;     long long res = 1;     for (; b; b >>= 1ll, a = a * a % mod)       if (b & 1ll) res = res * a % mod;     return res;   }   const int maxn = 2000005;   const int mn = 1505;   inline long long inv(long long a) { return ksm(a, mod - 2); }   long long fac[maxn], inc[maxn], dd[maxn];   long long C(long long x, long long y) {     return x <= y ? fac[y] * inc[x] % mod * inc[y - x] % mod : 0;   }   long long ss1[2][mn], ss2[2][mn], sum1[mn], sum2[mn], sum3[mn];   int main() {     long long n = read(), m = read(), a = read(), b = read(), k = read();     long long ans = 1, anss = 0, an = 0;     ans = a * inv(b) % mod;     an = inv(1 - ans + mod);     fac[0] = 1;     for (long long i = 1; i <= 2 * k; ++i) fac[i] = fac[i - 1] * i % mod;     inc[2 * k] = inv(fac[2 * k]);     for (long long i = 2 * k - 1; i >= 0; --i)       inc[i] = inc[i + 1] * (i + 1) % mod;     for (long long i = 0; i <= k; ++i)       dd[i] = ksm(1 - ans + mod, k - i) * C(i, k) % mod * ksm(ans, i) % mod;     for (int j = 1; j <= m; ++j) ss1[0][j] = 1;     sum1[0] = dd[0];     for (int i = 1; i <= m; ++i) sum1[i] = che(sum1[i - 1] + dd[i]);     for (int i = 1; i <= n; ++i) {       for (int j = m; j >= 1; --j)         sum2[j] = che(sum2[j + 1] + ss1[(i ^ 1) & 1][j] * dd[m - j] % mod);       for (int j = 1; j <= m; ++j)         sum3[j] =             che(sum3[j - 1] + (mod - ss2[(i ^ 1) & 1][j - 1]) * dd[j - 1] % mod);       for (int j = 1; j <= m; ++j) {         ss1[i & 1][j] = 0;         ss1[i & 1][j] =             che(ss1[i & 1][j] +                 che(mod + mod - ss2[(i ^ 1) & 1][j - 1]) * sum1[m - j] % mod);         ss1[i & 1][j] = che(ss1[i & 1][j] + sum2[j]);         ss1[i & 1][j] = ss1[i & 1][j] * dd[j - 1] % mod;         ss1[i & 1][j] = che(ss1[i & 1][j] + ss1[i & 1][j - 1]);       }       for (int l = 1; l < m; ++l) {         ss2[i & 1][l] = 0;         ss2[i & 1][l] = che(ss2[i & 1][l] + sum3[l]);         ss2[i & 1][l] =             che(ss2[i & 1][l] + (ss1[(i ^ 1) & 1][l]) * sum1[l - 1] % mod);         ss2[i & 1][l] = ss2[i & 1][l] * dd[m - l] % mod;         ss2[i & 1][l] = che(ss2[i & 1][l] + ss2[i & 1][l - 1]);       }     }     printf( %lld n , ss1[n & 1][m]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s1, s2, s3;     cin >> s1 >> s2 >> s3;     int i;     s1 = s1.append(s2);     sort(s1.begin(), s1.end());     sort(s3.begin(), s3.end());     if (s1.length() != s3.length()) {       cout <<  NO ;       return 0;     } else {       for (i = 0; i < s1.length(); i++) {         if (s1[i] != s3[i]) {           cout <<  NO ;           return 0;         }       }       cout <<  YES ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     long long ans = 0;     for (int i = (0); i < (n); ++i) {       long long t, T, x, cost;       cin >> t >> T >> x >> cost;       if (t >= T) {         ans += cost + m * x;         continue;       }       long long aux1 = cost;       if (m > (T - t)) aux1 += m * x;       long long aux2 = (long long)ceil((double)(m - (T - t)) / (T - t)) + 1;       aux2 *= cost;       ans += min(aux1, aux2);     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 55;   char str[N][N];   int vis[N];   int n, m;   long long msk[N];   int main() {     scanf( %d %d , &n, &m);     for (int i = 0; i < int(n); i++) scanf( %s , str[i]);     for (int i = 0; i < int(n); i++)       for (int j = 0; j < int(m); j++)         if (str[i][j] ==  # ) msk[i] |= (1LL << j);     for (int i = 0; i < int(n); i++) {       if (vis[i]) continue;       vector<int> v;       for (int j = int(i); j <= int(n - 1); j++) {         if (msk[i] == msk[j])           v.push_back(j);         else if (msk[i] & msk[j]) {           puts( No );           return 0;         }       }       for (int nxt : v) vis[nxt] = true;     }     puts( YES );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int i, n;     cin >> n;     char a[n];     for (i = 0; i <= n - 1; i++) {       cin >> a[i];     }     if (a[0] ==  S  && a[n - 1] ==  F )       cout <<  YES ;     else       cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct ac {     int x, y, z;   } p[3000];   int mo[3000];   vector<pair<int, int> > pr;   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; ++i) {       scanf( %d%d%d , &p[i].x, &p[i].y, &p[i].z);     }     for (int i = 1; i <= n; ++i) {       int d = 1e9, f = 0;       if (mo[i] == 1) continue;       for (int j = 1; j <= n; ++j) {         if (mo[j] == 1 || i == j) continue;         int td =             abs(p[i].x - p[j].x) + abs(p[j].y - p[i].y) + abs(p[j].z - p[i].z);         if (td < d) {           f = j;           d = td;         }       }       mo[i] = mo[f] = 1;       cout << i <<     << f << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long K = 1000000007;   long long gcd(long long a, long long b, long long& x, long long& y) {     if (a == 0) {       x = 0;       y = 1;       return b;     }     long long x1, y1;     long long d = gcd(b % a, a, x1, y1);     x = y1 - (b / a) * x1;     y = x1;     return d;   }   int32_t main() {     long long n, m;     cin >> n >> m;     long long ans = n + 1 - m;     for (long long i = 0; i < m; i++) {       ans *= (2 * n + 2);       ans %= K;     }     long long x, y;     gcd(n + 1, K, x, y);     x *= ans;     x %= K;     if (x < 0) x += K;     cout << x << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 30;   int a[MAX_N], s[MAX_N];   int main() {     ios::sync_with_stdio(false);     int n;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];       s[i] = a[i];     }     sort(s, s + n);     map<int, int> spos;     for (int i = 0; i < n; i++) {       spos[s[i]] = i;     }     for (int i = 0; i < n; i++) {       cout << s[(spos[a[i]] + 1) % n] <<    ;     }     cout << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t, n, l, r;     cin >> t;     while (t--) {       cin >> n;       int a[n];       for (int i = 0; i < n; i++) {         cin >> a[i];       }       for (int i = 0; i < n; i++) {         if (a[i] == 1) {           l = i;           break;         }       }       for (int i = n - 1; i >= 0; i--) {         if (a[i] == 1) {           r = i;           break;         }       }       int ans = 0;       for (int i = l; i < r + 1; i++) {         if (a[i] == 0) ans++;       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int SIZE = 640;   int h, w;   int matr[SIZE][SIZE];   int main() {     int q;     scanf( %d , &q);     for (int tt = 0; tt < q; tt++) {       scanf( %d%d , &h, &w);       for (int i = 0; i < h; i++)         for (int j = 0; j < w; j++) scanf( %d , &matr[i][j]);       int cut = h / 2;       int diffZero = 0;       int diffSwap = 0;       for (int j = 0; j < w; j++) {         diffZero += abs(matr[cut - 1][j] - matr[cut][j]);         diffSwap += abs(matr[0][j] - matr[h - 1][j]);       }       ((void)0);       printf(diffZero < diffSwap ?  NO n  :  YES n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const unsigned long long P = 239017, MaxN = 2100000, INF = 1000000000;   int a, arr[1000000], sum[1000000], have[1000000];   char s[1000000];   int main() {     scanf( %d%s , &a, s);     int len = strlen(s);     for (int i = 0; i < len; ++i) arr[i] = s[i] -  0 ;     sum[0] = 0;     for (int i = 1; i <= len; ++i) sum[i] = sum[i - 1] + arr[i - 1];     int S = 0;     for (int i = 1; i <= len; ++i)       for (int j = 1; j <= i; ++j) ++have[sum[i] - sum[j - 1]], ++S;     long long ans = 0;     for (int i = 1; i <= len; ++i)       for (int j = 1; j <= i; ++j) {         if ((sum[i] - sum[j - 1]) && a % (sum[i] - sum[j - 1]) == 0) {           if ((a / (sum[i] - sum[j - 1])) < 1000000)             ans += have[a / (sum[i] - sum[j - 1])];         }         if (a == 0 && (sum[i] - sum[j - 1]) == 0) ans += S;       }     printf( %I64d , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long int mod = 1e9 + 7;   int main() {     long long int t, n, ans = 0, count0 = 0, count1 = 0, count2 = 0, num0 = 0,                         num1 = 0, num2 = 0;     t = 1;     while (t--) {       cin >> n;       vector<long long int> A(n, 0);       for (int i = 0; i < n; i++) {         cin >> A[i];       }       sort(A.begin(), A.end());       for (int i = n - 1; i >= 0; i--) {         if (A[i] > 0) {           count1 += (A[i] - 1);           num1++;         } else if (A[i] == 0) {           count0++;           num0++;         } else {           count2 += (-1 - A[i]);           num2++;         }       }       ans += count1;       if (num2 % 2 == 0) {         ans += count2;         ans += count0;       } else {         if (num0 > 0) {           ans += count0;           ans += count2;         } else {           ans += count0;           ans += (count2 + 2);         }       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   unsigned long long mod = 1e9 + 7;   unsigned long long ncr(long long int n, long long int k) {     unsigned long long res = 1;     if (k > n - k) k = n - k;     for (int i = 0; i < k; ++i) {       res *= (n - i);       res /= (i + 1);       res = res % mod;     }     return res % mod;   }   bool prime(unsigned long long num) {     bool flag = true;     for (unsigned long long i = 2; i * i <= num; i++) {       if (num % i == 0) {         flag = false;         break;       }     }     return flag;   }   long long ipow(long long base, long long exp) {     long long result = 1;     for (;;) {       if (exp & 1) {         result *= base;         result = result % mod;       }       exp >>= 1;       if (!exp) break;       base *= base;       base = base % mod;     }     return result % mod;   }   long long abs(long long a, long long b) {     if ((a - b) > 0)       return (a - b);     else       return (b - a);   }   int main() {     ios_base ::sync_with_stdio(false);     cin.tie(NULL);     int n, k;     cin >> n >> k;     int mx[n + 1], mn[n + 1];     memset(mn, -1, sizeof mn);     memset(mx, -1, sizeof mx);     for (int i = 0; i < k; i++) {       int k;       cin >> k;       if (mn[k] == -1) mn[k] = i;       mx[k] = i;     }     int ans = 0;     for (int i = 1; i <= n; i++) {       if (mn[i] == -1 && i != 1 && i != n)         ans += 3;       else if (mn[i] == -1 && (i == 1 || i == n))         ans += 2;       else {         if (i != 1) {           if (mn[i - 1] == -1)             ans++;           else {             if (mx[i - 1] < mn[i]) ans++;           }         }         if (i != n) {           if (mn[i + 1] == -1)             ans++;           else {             if (mx[i + 1] < mn[i]) {               ans++;             }           }         }       }     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   long long bin_pow(long long x, long long e, long long MOD) {     long long res = 1;     while (e) {       if (e & 1) res = res * x % MOD;       e >>= 1;       x = x * x % MOD;     }     return res;   }   long long p, a, b, x, ans;   vector<long long> m[1123456];   long long xd[1123456];   long long xy[1123456];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> a >> b >> p >> x;     for (int i = 1; i < p; i++) {       xd[i] = bin_pow(i, p - 2, p);       xy[i] = bin_pow(a, i, p);     }     for (int i = 0; i < p - 1; i++) {       m[bin_pow(a, i, p)].push_back(i);     }     for (int i = 1; i < p; i++) {       vector<long long> g = m[((b * xd[i]) % p) * xd[xy[i]] % p];       for (auto k : g) {         long long y = x - i;         if (y < 0) continue;         y /= p;         long long t = y / (p - 1);         if (t * (p - 1) + k <= y)           ans += t + 1;         else           ans += t;       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, q, ans[600005];   bitset<505> a[505][505], b[505][505];   char mp[505][505];   struct ccf {     int x1, y1, x2, y2, id;   };   void solve(int l, int r, vector<ccf> qus) {     if (!qus.size()) return;     int mid = (l + r) >> 1;     for (int i = mid; i >= l; i--) {       for (int j = m; j >= 1; j--) {         a[i][j].reset();         if (i == mid) a[mid][j][j] = (mp[mid][j] ==  . );         if (i != mid && mp[i + 1][j] ==  . ) a[i][j] |= a[i + 1][j];         if (j != m && mp[i][j + 1] ==  . ) a[i][j] |= a[i][j + 1];       }     }     for (int i = mid; i <= r; i++) {       for (int j = 1; j <= m; j++) {         b[i][j].reset();         if (i == mid) b[mid][j][j] = (mp[mid][j] ==  . );         if (i != mid && mp[i - 1][j] ==  . ) b[i][j] |= b[i - 1][j];         if (j != 1 && mp[i][j - 1] ==  . ) b[i][j] |= b[i][j - 1];       }     }     vector<ccf> askl, askr;     int len = qus.size();     for (int i = 0; i < len; i++) {       if (qus[i].x2 < mid)         askl.push_back(qus[i]);       else if (qus[i].x1 > mid)         askr.push_back(qus[i]);       else         ans[qus[i].id] =             (a[qus[i].x1][qus[i].y1] & b[qus[i].x2][qus[i].y2]).any();     }     solve(l, mid - 1, askl);     solve(mid + 1, r, askr);   }   vector<ccf> eve;   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) cin >> (mp[i] + 1);     scanf( %d , &q);     for (int i = 1; i <= q; i++) {       ccf qus;       qus.id = i;       scanf( %d%d%d%d , &qus.x1, &qus.y1, &qus.x2, &qus.y2);       eve.push_back(qus);     }     solve(1, n, eve);     for (int i = 1; i <= q; i++)       if (ans[i])         puts( Yes );       else         puts( No );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int t, n, ans, lcp[5009][5009], dp[5009];   char a[5009];   int main() {     scanf( %d , &t);     while (t--) {       scanf( %d , &n);       scanf( %s , a + 1);       ans = 0;       for (int i = n; i >= 1; i--)         for (int j = n; j >= 1; j--)           lcp[i][j] = (a[i] == a[j]) ? (lcp[i + 1][j + 1] + 1) : 0;       for (int i = 1; i <= n; i++) {         dp[i] = n + 1 - i;         for (int j = 1; j < i; j++) {           int len = lcp[i][j];           if (a[j + len] < a[i + len])             dp[i] = max(dp[i], dp[j] + n + 1 - (i + len));         }         ans = max(ans, dp[i]);       }       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int M = 1010;   int n;   vector<pair<int, int> > pt;   vector<int> vx, vy;   vector<int> gx[M], gy[M];   vector<tuple<int, int, int> > sh, sv;   int pa[M], pb[M], ln, lm;   vector<int> v[M];   bool used[M], used1[M];   vector<int> dx[M], dy[M];   bool dfs(int p) {     used[p] = true;     for (int i : v[p]) {       if (pb[i] == -1 || (!used[pb[i]] && dfs(pb[i]))) {         pa[p] = i;         pb[i] = p;         return true;       }     }     return false;   }   void dfs_set(int p) {     used[p] = true;     for (int i : v[p]) {       used1[i] = true;       if (pb[i] != -1 && !used[pb[i]]) dfs_set(pb[i]);     }   }   void kuhn() {     memset(pa, -1, sizeof(pa));     memset(pb, -1, sizeof(pb));     for (int i = 0; i < ln; i++) {       memset(used, 0, sizeof(used));       if (dfs(i)) continue;     }     memset(used, 0, sizeof(used));     memset(used1, 0, sizeof(used1));     for (int i = 0; i < ln; i++)       if (pa[i] == -1) dfs_set(i);     for (int i = 0; i < ln; i++) used[i] = (!used[i]);   }   int main() {     ios::sync_with_stdio(0);     cin >> n;     for (int i = 0; i < n; i++) {       int x, y;       cin >> x >> y;       vx.push_back(x);       vy.push_back(y);       pt.push_back(make_pair(x, y));     }     sort(vx.begin(), vx.end());     vx.resize(unique(vx.begin(), vx.end()) - vx.begin());     sort(vy.begin(), vy.end());     vy.resize(unique(vy.begin(), vy.end()) - vy.begin());     for (int i = 0; i < n; i++) {       pt[i].first = lower_bound(vx.begin(), vx.end(), pt[i].first) - vx.begin();       pt[i].second = lower_bound(vy.begin(), vy.end(), pt[i].second) - vy.begin();     }     for (int i = 0; i < n; i++) {       gx[pt[i].first].push_back(pt[i].second);       gy[pt[i].second].push_back(pt[i].first);     }     for (int i = 0; i < n; i++) sort(gx[i].begin(), gx[i].end());     for (int i = 0; i < n; i++) sort(gy[i].begin(), gy[i].end());     for (int y = 0; y < n; y++)       if ((int)gy[y].size() > 1)         for (int i = 0; i < (int)gy[y].size() - 1; i++)           sh.push_back(make_tuple(gy[y][i], gy[y][i + 1], y));     for (int x = 0; x < n; x++)       if ((int)gx[x].size() > 1)         for (int i = 0; i < (int)gx[x].size() - 1; i++)           sv.push_back(make_tuple(gx[x][i], gx[x][i + 1], x));     sort(sh.begin(), sh.end());     sort(sv.begin(), sv.end());     ln = sh.size();     lm = sv.size();     for (int i = 0; i < ln; i++)       for (int j = 0; j < lm; j++) {         if (!(get<0>(sh[i]) < get<2>(sv[j]) && get<2>(sv[j]) < get<1>(sh[i])))           continue;         if (!(get<0>(sv[j]) < get<2>(sh[i]) && get<2>(sh[i]) < get<1>(sv[j])))           continue;         v[i].push_back(j);       }     kuhn();     for (int y = 0; y < n; y++)       if ((int)gy[y].size() >= 1) dy[y].push_back(gy[y][0]);     for (int x = 0; x < n; x++)       if ((int)gx[x].size() >= 1) dx[x].push_back(gx[x][0]);     for (int i = 0; i < ln; i++)       if (used[i]) {         dy[get<2>(sh[i])].push_back(get<0>(sh[i]));         dy[get<2>(sh[i])].push_back(get<1>(sh[i]));       }     for (int i = 0; i < lm; i++)       if (used1[i]) {         dx[get<2>(sv[i])].push_back(get<0>(sv[i]));         dx[get<2>(sv[i])].push_back(get<1>(sv[i]));       }     for (int y = 0; y < n; y++)       if ((int)gy[y].size() >= 1) dy[y].push_back(gy[y].back());     for (int x = 0; x < n; x++)       if ((int)gx[x].size() >= 1) dx[x].push_back(gx[x].back());     int ans = 0;     for (int y = 0; y < n; y++) ans += (int)dy[y].size();     ans /= 2;     cout << ans <<   n ;     for (int y = 0; y < n; y++)       for (int i = 0; i < (int)dy[y].size(); i += 2)         cout << vx[dy[y][i]] <<     << vy[y] <<     << vx[dy[y][i + 1]] <<                  << vy[y] <<   n ;     ans = 0;     for (int x = 0; x < n; x++) ans += (int)dx[x].size();     ans /= 2;     cout << ans <<   n ;     for (int x = 0; x < n; x++)       for (int i = 0; i < (int)dx[x].size(); i += 2)         cout << vx[x] <<     << vy[dx[x][i]] <<     << vx[x] <<                  << vy[dx[x][i + 1]] <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = int(5e5) + 100;   int n, m;   vector<pair<int, int> > out[maxn];   int fa[maxn];   long long f[maxn], g[maxn], a[maxn];   void read() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; ++i) out[i].clear();     for (int i = 1; i < n; ++i) {       int u, v, d;       scanf( %d%d%d , &u, &v, &d);       out[u].push_back(make_pair(v, d));       out[v].push_back(make_pair(u, d));     }   }   void dfs(int cur) {     f[cur] = g[cur] = 0;     for (auto &to : out[cur])       if (to.first != fa[cur]) {         fa[to.first] = cur;         dfs(to.first);         f[cur] += f[to.first];         g[cur] += f[to.first];       }     int cnt = 0;     for (auto &to : out[cur])       if (to.first != fa[cur]) a[++cnt] = to.second + g[to.first] - f[to.first];     sort(a + 1, a + 1 + cnt, greater<long long>());     int fin = min(m - 1, cnt);     for (int i = 1; i <= fin; ++i)       g[cur] += max(0LL, a[i]), f[cur] += max(a[i], 0LL);     if (m <= cnt) f[cur] += max(0LL, a[m]);   }   void solve() {     dfs(1);     printf( %lld n , f[1]);   }   int main() {     int casesum;     scanf( %d , &casesum);     while (casesum--) {       read();       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, k;   pair<long long, long long> a[100007];   int r[100007];   int c[100007];   int used[100007];   long long ans = -1;   bool cmp1(int x, int y) { return (a[x].first < a[y].first); }   bool cmp2(int x, int y) { return (a[x].second < a[y].second); }   void input() {     cin >> n >> k;     int i;     long long xx1, yy1, xx2, yy2;     for (i = 1; i <= n; i++) {       cin >> xx1 >> yy1 >> xx2 >> yy2;       xx1 *= 2;       yy1 *= 2;       xx2 *= 2;       yy2 *= 2;       a[i].first = (xx1 + xx2) / 2;       a[i].second = (yy1 + yy2) / 2;       r[i] = c[i] = i;     }   }   void solve() {     sort(r + 1, r + n + 1, cmp1);     sort(c + 1, c + n + 1, cmp2);     int i, j;     int mask;     int lim = (2 << (2 * k));     vector<int> v;     for (mask = 0; mask < lim; mask++) {       int u = mask;       v.clear();       for (j = 0; j < k; j++) {         int ost = (u % 4);         u /= 4;         if (ost == 0) {           for (i = 1; i <= n; i++) {             if (used[r[i]] == 1) {               continue;             }             used[r[i]] = 1;             v.push_back(r[i]);             break;           }         } else if (ost == 1) {           for (i = n; i >= 1; i--) {             if (used[r[i]] == 1) {               continue;             }             used[r[i]] = 1;             v.push_back(r[i]);             break;           }         } else if (ost == 2) {           for (i = 1; i <= n; i++) {             if (used[c[i]] == 1) {               continue;             }             used[c[i]] = 1;             v.push_back(c[i]);             break;           }         } else {           for (i = n; i >= 1; i--) {             if (used[c[i]] == 1) {               continue;             }             used[c[i]] = 1;             v.push_back(c[i]);             break;           }         }       }       long long xx1, yy1, xx2, yy2;       xx1 = xx2 = yy1 = yy2 = 0;       for (i = 1; i <= n; i++) {         if (used[r[i]] == 0) {           xx1 = a[r[i]].first;           break;         }       }       for (i = n; i >= 1; i--) {         if (used[r[i]] == 0) {           xx2 = a[r[i]].first;           break;         }       }       for (i = 1; i <= n; i++) {         if (used[c[i]] == 0) {           yy1 = a[c[i]].second;           break;         }       }       for (i = n; i >= 1; i--) {         if (used[c[i]] == 0) {           yy2 = a[c[i]].second;           break;         }       }       if (xx1 == xx2) {         if (k != n) {           xx2++;         }       }       if (yy1 == yy2) {         if (k != n) {           yy2++;         }       }       long long s = (xx2 - xx1 + 1) / 2;       s *= ((yy2 - yy1 + 1) / 2);       if (ans == -1 || ans > s) {         ans = s;       }       for (i = 0; i < k; i++) {         used[v[i]] = 0;       }     }     cout << ans <<   n ;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     input();     solve();     return 0;   }


#include <bits/stdc++.h>   char s[100005];   std::vector<int> v;   int main() {     scanf( %s , s);     int n = strlen(s);     bool pc = 0;     long long now = 0, pre = 0;     bool first = true;     for (int i = 0; i < n; i++) {       if (s[i] <=  9  && s[i] >=  0 ) {         now = now * 10 + s[i] -  0 ;       } else {         if (first) {           first = false;           pre = now;         } else {           if (pc)             pre = pre + now;           else             pre = pre - now;         }         pc = (s[i] ==  + );         now = 0;       }     }     if (pc)       pre = pre + now;     else       pre = pre - now;     if (pre == 0) v.push_back(0);     while (pre) {       v.push_back(pre % 10);       pre /= 10;     }     for (int i = v.size() - 1; i >= 0; i--) {       for (int j = 0; j < v[i] +  0 ; j++) printf( + );       printf( . );       if (i != 0)         printf( > );       else         printf(  n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   map<long long, string> dic;   int main() {     long long n;     scanf( %lld , &n);     for (long long i = 2; (long long)i * i <= n; i++) {       for (long long j = i * i, p = 2; j <= n; j *= i, p++) {         string str = to_string(i) +  ^  + to_string(p);         if (dic.find(j) == dic.end())           dic[j] = str;         else if (dic[j].size() > str.size())           dic[j] = str;       }     }     string ans = to_string(n);     for (auto it = dic.begin(); it != dic.end(); it++) {       long long v = it->first;       string str = it->second;       long long mul = n / v;       long long add = n % v;       string all_str;       if (mul > 1) {         string mul_str = to_string(mul);         if (dic.find(mul) != dic.end() && dic[mul].size() < mul_str.size())           all_str += dic[mul] +  * ;         else           all_str += mul_str +  * ;       }       all_str += str;       if (add > 0) {         all_str +=  + ;         string add_str = to_string(add);         if (dic.find(add) != dic.end() && dic[add].size() < add_str.size())           all_str += dic[add];         else           all_str += add_str;       }       if (all_str.size() < ans.size()) ans = all_str;     }     puts(ans.c_str());     return 0;   }


#include <bits/stdc++.h>   using namespace std;   list<int> adjList[200002];   int depth[200002];   int sz[200002];   class LCA_binary {     int logn, timer;     vector<int> tin, tout;     vector<vector<int>> up;       public:     void innerdfs(int v, int p) {       tin[v] = ++timer;       up[v][0] = p;       for (int i = 1; i <= logn; ++i) up[v][i] = up[up[v][i - 1]][i - 1];       for (int u : adjList[v]) {         if (u != p) innerdfs(u, v);       }       tout[v] = ++timer;     }     bool is_ancestor(int u, int v) {       return tin[u] <= tin[v] && tout[u] >= tout[v];     }     int lca(int u, int v) {       if (is_ancestor(u, v)) return u;       if (is_ancestor(v, u)) return v;       for (int i = logn; i >= 0; --i) {         if (!is_ancestor(up[u][i], v)) u = up[u][i];       }       return up[u][0];     }     void preprocess(int n, int root) {       tin.resize(n + 3);       tout.resize(n + 3);       timer = 0;       logn = ceil(log2(n));       up.assign(n + 3, vector<int>(logn + 1));       innerdfs(root, root);     }   };   set<int> s;   vector<int> univ;   int deep(int i, int p, int d) {     depth[i] = d++;     if (s.count(i)) univ.push_back(i);     sz[i] = 1;     for (int v : adjList[i])       if (v != p) sz[i] += deep(v, i, d);     return sz[i];   }   int main() {     int n, k;     cin >> n >> k;     for (int i = 0; i < (k << 1); i++) {       int t;       cin >> t;       s.insert(t);     }     for (int i = 1; i < n; i++) {       int a, b;       cin >> a >> b;       adjList[a].push_back(b);       adjList[b].push_back(a);     }     LCA_binary f;     f.preprocess(n, 1);     deep(1, 0, 0);     long long ans = 0LL;     for (int i = 0; i < k; i++)       ans += (long long)(depth[univ[i]] + depth[univ[i + k]] -                          (depth[f.lca(univ[i], univ[i + k])] << 1));     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int arr[1000], ans = 0;   int cnt[1000];   int main() {     int n;     scanf( %d , &n);     priority_queue<int> pq;     for (int i = 0; i < n; ++i) {       int x;       scanf( %d , &x);       pq.push(-x);     }     for (int i = 0; i < 1000; ++i) {       arr[i] = 0;       cnt[i] = 0;     }     while (!pq.empty()) {       int u = -pq.top();       pq.pop();       int p = -1, smallest = 100000;       for (int i = 0; i < ans; ++i)         if (arr[i] < smallest && cnt[i] <= u) {           smallest = cnt[i];           p = i;         }       if (p == -1) {         ++cnt[ans];         arr[ans++] = u;       } else {         ++cnt[p];         arr[p] = u;       }     }     printf( %d n , ans);     return 0;   }