#include <bits/stdc++.h>   using namespace std;   const int maxn = 100005, mod = 998244353;   inline int gi() {     char c = getchar();     while (c <  0  || c >  9 ) c = getchar();     int sum = 0;     while ( 0  <= c && c <=  9 ) sum = sum * 10 + c - 48, c = getchar();     return sum;   }   inline int add(int a, int b) { return a + b >= mod ? a + b - mod : a + b; }   inline int sub(int a, int b) { return a >= b ? a - b : a - b + mod; }   inline int fpow(int x, int k) {     int res = 1;     while (k) {       if (k & 1) res = (long long)res * x % mod;       k >>= 1;       x = (long long)x * x % mod;     }     return res;   }   int n, k, ans, s1, s2, fac[maxn], ifac[maxn];   struct edge {     int to, next;   } e[maxn * 2];   int h[maxn], siz[maxn], tot;   int f[maxn], fs[maxn];   vector<pair<int, int> > vec;   vector<int> _F[maxn], _G[maxn];   int N, L, R[maxn << 2], w[maxn << 2], F[maxn << 2], Fl[maxn << 2],       Fr[maxn << 2], G[maxn << 2], Gl[maxn << 2], Gr[maxn << 2];   inline void adde(int u, int v) {     e[++tot] = (edge){v, h[u]};     h[u] = tot;     e[++tot] = (edge){u, h[v]};     h[v] = tot;   }   void init(int n) {     for (N = 1, L = -1; N <= n; N <<= 1) ++L;     for (int i = 0; i < N; ++i) R[i] = (R[i >> 1] >> 1) | ((i & 1) << L);     w[N >> 1] = 1;     int wn = fpow(3, (mod - 1) / N);     for (int i = (N >> 1) + 1; i < N; ++i) w[i] = (long long)w[i - 1] * wn % mod;     for (int i = (N >> 1) - 1; i; --i) w[i] = w[i << 1];   }   void dft(int *a) {     for (int i = 0; i < N; ++i)       if (i < R[i]) swap(a[i], a[R[i]]);     for (int d = 1; d < N; d <<= 1)       for (int i = 0; i < N; i += d << 1)         for (int j = 0; j < d; ++j) {           int t = (long long)w[d + j] * a[i + d + j] % mod;           a[i + d + j] = sub(a[i + j], t);           a[i + j] = add(a[i + j], t);         }   }   void idft(int *a) {     dft(a);     reverse(a + 1, a + N);     int inv = fpow(N, mod - 2);     for (int i = 0; i < N; ++i) a[i] = (long long)a[i] * inv % mod;   }   void solve(int l, int r, int u) {     if (l == r) {       vector<int> &F = _F[l], &G = _G[l];       F.resize(2);       G.resize(2);       F[0] = 1;       F[1] = vec[l].second;       G[0] = add(f[vec[l].first], fs[vec[l].first]);       G[1] =           (long long)add(f[vec[l].first], fs[vec[l].first]) * (n - siz[u]) % mod;       return;     }     int mid = (l + r) >> 1, l1 = mid - l + 1, l2 = r - mid;     solve(l, mid, u);     solve(mid + 1, r, u);     init(r - l + 1);     for (int i = 0; i <= l1; ++i) Fl[i] = _F[l][i], Gl[i] = _G[l][i];     memset(Fl + l1 + 1, 0, sizeof(int) * (N - l1));     memset(Gl + l1 + 1, 0, sizeof(int) * (N - l1));     for (int i = 0; i <= l2; ++i) Fr[i] = _F[mid + 1][i], Gr[i] = _G[mid + 1][i];     memset(Fr + l2 + 1, 0, sizeof(int) * (N - l2));     memset(Gr + l2 + 1, 0, sizeof(int) * (N - l2));     dft(Fl);     dft(Gl);     dft(Fr);     dft(Gr);     for (int i = 0; i < N; ++i) F[i] = (long long)Fl[i] * Fr[i] % mod;     for (int i = 0; i < N; ++i)       G[i] = ((long long)Fl[i] * Gr[i] + (long long)Fr[i] * Gl[i]) % mod;     idft(F);     idft(G);     _F[l].resize(r - l + 2);     _G[l].resize(r - l + 2);     for (int i = 0; i <= r - l + 1; ++i) _F[l][i] = F[i], _G[l][i] = G[i];   }   void dfs(int u, int fa) {     siz[u] = 1;     for (int i = h[u], v; v = e[i].to, i; i = e[i].next)       if (v != fa) dfs(v, u);     vec.clear();     for (int i = h[u], v; v = e[i].to, i; i = e[i].next)       if (v != fa) {         fs[u] = add(fs[u], add(f[v], fs[v]));         siz[u] += siz[v];         vec.emplace_back(v, siz[v]);       }     if (vec.empty())       return f[u] = 1, s1 = add(s1, f[u]), s2 = add(s2, f[u]), void();     solve(0, vec.size() - 1, u);     vector<int> &F = _F[0], &G = _G[0];     int s = F.size() - 1;     for (int i = 0; i <= s; ++i)       f[u] = (f[u] + (long long)fac[k] * ifac[k - i] % mod * F[i]) % mod;     s1 = add(s1, f[u]);     s2 = (s2 + (long long)f[u] * f[u]) % mod;     for (int i = 0; i <= s; ++i)       ans = (ans + (long long)fac[k] * ifac[k - i] % mod * G[i]) % mod;     ans = (ans + (long long)(mod - f[u]) * fs[u]) % mod;   }   int main() {     n = gi();     k = gi();     if (k == 1) return printf( %lld n , (long long)n * (n - 1) / 2 % mod), 0;     fac[0] = 1;     for (int i = 1; i <= k; ++i) fac[i] = (long long)fac[i - 1] * i % mod;     ifac[k] = fpow(fac[k], mod - 2);     for (int i = k - 1; ~i; --i) ifac[i] = (long long)ifac[i + 1] * (i + 1) % mod;     for (int i = 1; i < n; ++i) adde(gi(), gi());     dfs(1, 0);     printf( %d n , add(ans, (long long)sub((long long)s1 * s1 % mod, s2) *                                 (mod + 1) / 2 % mod));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int m[100][100];   int main(int argc, char const *argv[]) {     ios_base::sync_with_stdio(0);     long n, suma = 0;     cin >> n;     for (int i = 0; i < n; ++i) {       for (int j = 0; j < n; ++j) {         m[i][j] = 1;       }     }     for (int i = 1; i < n; ++i) {       for (int j = 1; j < n; ++j) {         int x = m[i - 1][j], y = m[i][j - 1];         m[i][j] = x + y;       }     }     cout << m[n - 1][n - 1] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c, d;     scanf( %i %i %i %i , &a, &b, &c, &d);     int sum1 = max(3 * a / 10, a - a / 250 * c);     int sum2 = max(3 * b / 10, b - b / 250 * d);     if (sum1 > sum2) {       printf( Misha n );     } else if (sum1 == sum2) {       printf( Tie n );     } else {       printf( Vasya n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 3e5 + 10;   const long long INF = 1e18 + 10;   struct node {     int next, v;   } edge[maxn * 2 + 10];   int cnt, head[maxn], vis[maxn], pa[maxn];   long long sum[maxn], cost[maxn], a[maxn], ss[maxn];   queue<int> q;   int find(int x) {     if (x == pa[x]) return x;     return pa[x] = find(pa[x]);   }   void add2(int x, int y) {     x = find(x);     y = find(y);     pa[x] = y;     ss[y] += ss[x];   }   void dfs(int u, int fa) {     int i, v;     sum[u] = a[u];     for (i = head[u]; i != -1; i = edge[i].next) {       v = edge[i].v;       if (v == fa) continue;       dfs(v, u);       if (sum[v] > 0) sum[u] += sum[v];     }   }   void dfs2(int u, int fa) {     int i, v;     if (u == 1) {       cost[u] = sum[u];       for (i = head[1]; i != -1; i = edge[i].next) {         v = edge[i].v;         dfs2(v, u);       }       return;     }     if (sum[u] <= 0) {       cost[u] = max(sum[u], sum[u] + cost[fa]);     } else {       long long tmp = cost[fa] - sum[u];       if (tmp > 0) {         cost[u] = sum[u] + tmp;         add2(u, fa);       } else {         cost[u] = sum[u];       }     }     for (i = head[u]; i != -1; i = edge[i].next) {       v = edge[i].v;       if (fa == v) continue;       dfs2(v, u);     }   }   void add(int x, int y) {     edge[cnt].next = head[x];     edge[cnt].v = y;     head[x] = cnt++;   }   int main() {     int i, n;     long long ans, ret, s, u, v;     scanf( %d , &n);     for (i = 1; i <= n; i++) {       scanf( %I64d , &a[i]);     }     cnt = 0;     memset(head, -1, sizeof(head));     for (i = 1; i <= n - 1; i++) {       scanf( %d%d , &u, &v);       add(u, v);       add(v, u);     }     for (i = 1; i <= n; i++) {       pa[i] = i;       ss[i] = a[i];     }     dfs(1, -1);     dfs2(1, -1);     ans = -INF;     for (i = 1; i <= n; i++) ans = max(ans, cost[i]);     if (ans <= 0) {       ret = 0;       s = 0;       for (i = 1; i <= n; i++) {         if (ans == cost[i]) {           ret++;           s += ans;         }       }       printf( %I64d %I64d n , s, ret);     } else {       ret = 0;       s = 0;       memset(vis, 0, sizeof(vis));       for (i = 1; i <= n; i++) {         if (ans == cost[i]) {           int tt = find(i);           if (!vis[tt] && ss[tt] == ans) {             ret++;             s += ans;             vis[tt] = 1;           }         }       }       printf( %I64d %I64d n , s, ret);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e3 + 10;   const char character[] =  ./  ;   int n, a[N], tag[N], type[N][N];   int main() {     scanf( %d , &n);     for (register int i = 1; i <= n; ++i) {       scanf( %d , &a[i]);     }     int o = 0, r = 0;     for (register int i = 1; i <= n; ++i) {       if (tag[i] || a[i] == i) {         continue;       }       vector<int> cycle;       for (int j = i; !tag[j]; j = a[j]) {         cycle.push_back(j), tag[j] = 1;       }       cycle.push_back(i);       if (!o) {         o = i;         for (register int j = 1; j + 1 < cycle.size(); ++j) {           int a = cycle[j], b = cycle[j + 1];           ++r;           type[r][a] = type[r][b] = 2 - (a < b);         }       } else {         ++r;         type[r][o] = type[r][cycle[1]] = 1;         for (register int j = 1; j + 1 < cycle.size(); ++j) {           int a = cycle[j], b = cycle[j + 1];           ++r;           type[r][a] = type[r][b] = 2 - (a < b);         }         type[r][o] = 2;       }     }     printf( %d n , o ? n - 1 : n);     for (register int i = 1; i <= n; ++i) {       for (register int j = 1; j <= n; ++j) {         printf( %c , character[type[i][j]]);       }       puts(  );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, r;   int x[105], y[105];   vector<pair<int, int> > pos, neg;   bool cmp(pair<int, int> p1, pair<int, int> p2) {     return p1.first + p1.second > p2.first + p2.second;   }   int main() {     cin >> n >> r;     for (int i = 0; i < n; i++) {       scanf( %d%d , &x[i], &y[i]);       if (y[i] >= 0)         pos.push_back(pair<int, int>(x[i], y[i]));       else         neg.push_back(pair<int, int>(x[i], y[i]));     }     sort(pos.begin(), pos.end());     sort(neg.begin(), neg.end(), cmp);     for (int i = 0; i < pos.size(); i++) {       if (pos[i].first <= r)         r += pos[i].second;       else {         printf( NO n );         return 0;       }     }     for (int i = 0; i < neg.size(); i++) {       if (neg[i].first <= r)         r += neg[i].second;       else {         printf( NO n );         return 0;       }       if (r < 0) {         printf( NO n );         return 0;       }     }     printf( YES n );     return 0;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long p;   map<long long, int> m[123];   int main() {     int characters_value[26];     long long i;     for (i = 0; i < 26; i++) cin >> characters_value[i];     string s;     cin >> s;     long long ans = 0;     for (i = 0; i < s.size(); i++) {       ans += m[s[i]][p];       p += characters_value[s[i] -  a ];       m[s[i]][p]++;     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 811287553;   long long powmod(long long a, long long b) {     long long res = 1;     a %= mod;     for (; b; b >>= 1) {       if (b & 1) res = res * a % mod;       a = a * a % mod;     }     return res;   }   int n, m, s, t, a, b, d;   vector<long long> dist, dist1;   vector<pair<int, int> > grh[2][100000];   vector<pair<pair<int, int>, int> > queries;   set<pair<int, int> > absEdges;   map<pair<int, int>, int> minEdges;   long long reachableCnt[2][100000];   const long long INF = 1000000000000;   void dijkstra(int src, vector<long long>& d, int mode) {     d.resize(n, INF);     d[src] = 0;     priority_queue<pair<long long, int> > pq;     pq.push(make_pair(0, src));     while (!pq.empty()) {       long long topD = -pq.top().first;       int topIdx = pq.top().second;       pq.pop();       if (d[topIdx] < topD) continue;       int sz = grh[mode][topIdx].size();       for (int i = 0; i < (int)sz; i++) {         int nIdx = grh[mode][topIdx][i].first;         int nD = grh[mode][topIdx][i].second;         long long nD1 = topD + nD;         if (d[nIdx] > nD1) {           d[nIdx] = nD1;           pq.push(make_pair(-nD1, nIdx));         }       }     }   }   int calReachable(int idx, vector<long long>& d, bool rev) {     if (rev && idx == s) {       reachableCnt[!rev][idx] = 1;       return 1;     }     if (!rev && idx == t) {       reachableCnt[!rev][idx] = 1;       return 1;     }     long long& ret = reachableCnt[!rev][idx];     if (ret != -1) return ret;     int ret1 = 0;     int sz = grh[rev][idx].size();     for (int i = 0; i < (int)sz; i++) {       int nIdx = grh[rev][idx][i].first;       int nD = grh[rev][idx][i].second;       if (d[nIdx] == d[idx] + nD) {         ret1 += calReachable(nIdx, d, rev);         ret1 %= mod;       }     }     return ret = (ret1 % mod);   }   int main() {     cin >> n >> m >> s >> t;     s--, t--;     for (int i = 0; i < (int)m; i++) {       cin >> a >> b >> d;       a--, b--;       grh[0][a].push_back(make_pair(b, d));       grh[1][b].push_back(make_pair(a, d));       queries.push_back(make_pair(make_pair(a, b), d));       if (minEdges.count(make_pair(a, b)))         minEdges[make_pair(a, b)] = min(minEdges[make_pair(a, b)], d);       else         minEdges[make_pair(a, b)] = d;     }     memset(reachableCnt, -1, sizeof(reachableCnt));     dijkstra(s, dist, 0);     dijkstra(t, dist1, 1);     calReachable(t, dist1, 1);     calReachable(s, dist, 0);     for (int i = 0; i < (int)m; i++) {       int x = queries[i].first.first, y = queries[i].first.second,           d = queries[i].second;       if ((((reachableCnt[0][x] * reachableCnt[1][y]) % mod) ==            reachableCnt[0][t]) &&           minEdges[make_pair(x, y)] < d) {         if (minEdges[make_pair(x, y)] == 1)           cout <<  NO  << endl;         else           cout <<  CAN   << d - minEdges[make_pair(x, y)] + 1 << endl;       } else {         long long d1 = dist[x] + dist1[y];         if ((((reachableCnt[0][x] * reachableCnt[1][y]) % mod) ==              reachableCnt[0][t])) {           if (d1 + d == dist[t])             cout <<  YES  << endl;           else {             if (d > 1 && d1 + 1 < dist[t])               cout <<  CAN   << d + d1 - (dist[t] - 1) << endl;             else               cout <<  NO  << endl;           }         } else {           if (d > 1 && d1 + 1 < dist[t])             cout <<  CAN   << d + d1 - (dist[t] - 1) << endl;           else             cout <<  NO  << endl;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T, typename U>   std::pair<T, U> operator+(const std::pair<T, U>& l, const std::pair<T, U>& r) {     return {l.first + r.first, l.second + r.second};   }   typedef void (*callback_function)(void);   const long long ZERO = 0LL;   const long long INF64 = 1e18;   const long long INF32 = 1e9;   const long long MOD = 1e9 + 7;   const long double PI = acos(-1.0L);   const long double EPS = static_cast<long double>(1e-9);   long long inv(long long a, long long b) {     if (a != 1) {       return b - (inv(b % a, a) * b) / a;     }     return 1;   }   inline long long Pow(long long a, long long k) {     long long s = 1;     for (; k; k >>= 1) {       k& 1 ? s = 1LL * s * a % MOD : 0;       a = 1LL * a * a % MOD;     }     return s;   }   const long long N = 1e6 + 7;   void input() {}   void output() {}   void preprocess() {}   void debug() {     if (true) {     }   }   void solve() {     preprocess();     long long n;     cin >> n;     pair<long long, long long> a[n];     for (long long i = (0); i < (n); i++) {       long long m;       cin >> m;       long long b[m];       for (long long i = (0); i < (m); i++) {         cin >> b[i];       }       a[i] = pair<long long, long long>(*max_element(b, b + m), m);     }     long long mx = (*max_element(a, a + n)).first;     long long res = 0;     for (long long i = (0); i < (n); i++) {       res += (mx - a[i].first) * a[i].second;     }     cout << res << endl;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie();     {       input();       solve();       output();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool compare(pair<int, int> a, pair<int, int> b) { return a.second < b.second; }   int main() {     int n, k;     cin >> n >> k;     pair<int, int> power[n];     for (int i = 0; i < n; ++i) {       pair<int, int> a;       int p;       cin >> p;       a.first = p;       if (p % 10 == 0)         a.second = 0;       else         a.second = 10 - p % 10;       power[i] = a;     }     sort(power, power + n, compare);     for (int i = 0; i < n; ++i) {       if (power[i].first != 100) {         k = k - power[i].second;         if (k < 0) break;         power[i].first = power[i].first + power[i].second;       }     }     if (k > 0) {       for (int i = 0; i < n; ++i) {         while (power[i].first < 100 && k >= 10) {           k = k - 10;           power[i].first += 10;         }         if (k < 10) break;       }     }     int res = 0;     for (int i = 0; i < n; ++i) {       res += power[i].first / 10;     }     cout << res << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, a[200005];     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d , &a[i]);     }     int flag = 0;     for (int i = 0; i < n; i++) {       if (a[i] >= 2) a[i] %= 2;       if (a[i] == 0) continue;       if (i == n - 1) {         flag = 1;         break;       } else {         if (a[i + 1] > 0)           a[i + 1] -= 1;         else           flag = 1;       }     }     if (flag == 1)       printf( NO n );     else       printf( YES n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = (1 << 18);   struct segment {    private:     static const int maxn = (1 << 18);     int arr[2 * maxn];     int private_sum(int node, int first, int last, int a, int b) {       if (first >= a && last <= b) return arr[node];       if (a >= last || b <= first) return 0;       int mid = (first + last) / 2;       return private_sum(2 * node, first, mid, a, b) +              private_sum(2 * node + 1, mid, last, a, b);     }       public:     void add(int ja, int megh) {       ja += maxn;       while (ja > 0) {         arr[ja] += megh;         ja /= 2;       }     }     int sum(int first, int last) {       return private_sum(1, maxn, 2 * maxn, maxn + first, maxn + last);     }     int nth(int n) {       int node = 1, zir = maxn;       while (zir > 1) {         if (n < zir / 2 - arr[2 * node]) {           node *= 2;         } else {           n -= zir / 2 - arr[2 * node];           node = 2 * node + 1;         }         zir /= 2;       }       return node - maxn;     }   } p_fir, p_sec, s;   int a[maxn], b[maxn], out[maxn];   void find_ab(int x, int n) {     int fir = a[x], sec = b[x];     p_fir.add(fir, 1);     p_sec.add(sec, 1);     a[x] -= p_fir.sum(0, fir);     b[x] -= p_sec.sum(0, sec);   }   void find_out(int n) {     for (int i = 0; i < n; i++) {       find_ab(i, n);     }     int bgh = 0;     for (int i = n - 1; i >= 0; i--) {       out[i] = bgh + a[i] + b[i];       if (out[i] >= n - i) {         bgh = 1;         out[i] -= (n - i);       } else         bgh = 0;     }     for (int i = 0; i < n; i++) {       out[i] = s.nth(out[i]);       s.add(out[i], 1);     }   }   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < n; i++) cin >> b[i];     find_out(n);     for (int i = 0; i < n; i++) cout << out[i] <<    ;     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void FastIO() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);   }   long long int mod = 2e9 + 10;   class SegmentTree {    public:     vector<int> st;     vector<int> lazy;     vector<int> A;     int n;     int left(int p) { return (p << 1) + 1; }     int right(int p) { return (p << 1) + 2; }     void build(int p, int l, int r) {       if (l == r)         st[p] = A[l];       else {         build(left(p), l, (l + r) / 2);         build(right(p), (l + r) / 2 + 1, r);         st[p] = st[left(p)] + st[right(p)];       }     }     SegmentTree(vector<int> a) {       A = a;       n = (int)A.size();       st.assign(4 * n, 0);       lazy.assign(4 * n, 0);       build(0, 0, n - 1);     }     void lazyUpdate(int pos, int l, int r) {       st[pos] += lazy[pos] * (r - l + 1);       if (l != r) {         lazy[left(pos)] += lazy[pos];         lazy[right(pos)] += lazy[pos];       }       lazy[pos] = 0;     }     int query(int pos, int l, int r, int i, int j) {       lazyUpdate(pos, l, r);       if (i > r || j < l || l > r) return 0;       if (i <= l && r <= j) {         return st[pos];       }       long long int q1 = query(left(pos), l, (l + r) / 2, i, j);       long long int q2 = query(right(pos), (l + r) / 2 + 1, r, i, j);       return (q1 + q2) % mod;     }     void update(int pos, int l, int r, int i, int j, int val) {       lazyUpdate(pos, l, r);       if (i > r || j < l || l > r) return;       if (i <= l && r <= j) {         st[pos] += val * (r - l + 1);         if (l != r) {           lazy[left(pos)] += val;           lazy[right(pos)] += val;         }         return;       }       update(left(pos), l, (l + r) / 2, i, j, val);       update(right(pos), (l + r) / 2 + 1, r, i, j, val);       st[pos] = (st[left(pos)] + st[right(pos)]);     }   };   int main() {     FastIO();     int n, k, a, b, q, d, x, p, type;     cin >> n >> k >> a >> b >> q;     vector<int> V1(n, 0), V2(n, 0), V3(n, 0);     SegmentTree ST2(V2);     SegmentTree ST3(V3);     while (q--) {       cin >> type;       if (type == 1) {         cin >> d >> x;         d--;         V1[d] += x;         ST2.update(0, 0, n - 1, d, d, min(b, V1[d]) - V2[d]);         V2[d] = min(b, V1[d]);         ST3.update(0, 0, n - 1, n - d - 1, n - d - 1,                    min(a, V1[d]) - V3[n - d - 1]);         V3[n - d - 1] = min(a, V1[d]);       } else {         cin >> p;         p--;         int temp1 = 0, temp2 = 0;         if (p) {           temp1 = ST2.query(0, 0, n - 1, 0, p - 1);         }         p += k - 1;         p = n - p - 1;         if (p) {           temp2 = ST3.query(0, 0, n - 1, 0, p - 1);         }         cout << temp1 + temp2 <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   const double eps = 1e-8;   const int mod = 1e9 + 7;   int jia[N], jian[N], x[N], yes[N];   int out[N][3];   int abbs(int x) {     if (x > 0)       return x;     else       return -x;   }   int main() {     int n, m, t;     scanf( %d%d , &n, &m);     memset(out, 0, sizeof(out));     memset(yes, 0, sizeof(yes));     memset(jia, 0, sizeof(jia));     memset(jian, 0, sizeof(jian));     int alljia = 0, alljian = 0, all = 0;     for (int i = 1; i <= n; i++) {       scanf( %d , &x[i]);       if (x[i] > 0)         jia[x[i]]++, alljia++;       else         jian[-x[i]]++, alljian++;     }     for (int i = 1; i <= n; i++) {       int numzhen = jia[i] + alljian - jian[i];       if (numzhen == m) {         yes[i] = 1;         all++;       }     }     for (int i = 1; i <= n; i++) {       int xx = abbs(x[i]);       if (yes[xx]) {         if (all == 1) {           if (x[i] > 0)             out[i][0] = 1;           else             out[i][1] = 1;         } else {           out[i][2] = 1;         }       } else {         if (x[i] > 0)           out[i][1] = 1;         else           out[i][0] = 1;       }     }     for (int i = 1; i <= n; i++) {       if (out[i][2])         printf( Not defined n );       else if (out[i][0])         printf( Truth n );       else if (out[i][1])         printf( Lie n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void c_p_c() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   bool prime(long long c) {     for (long long i = 2; i * i <= c; i++) {       if (c % i == 0) return 0;     }     return 1;   }   int32_t main() {     c_p_c();     long long n;     cin >> n;     while (n--) {       long long a, b, s = 0;       cin >> a >> b;       while (a > 0 && b > 0) {         if (a > b) {           s += (a / b);           a -= (a / b) * b;         } else {           s += (b / a);           b -= (b / a) * a;         }       }       cout << s <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O1 )   #pragma GCC optimize( O2 )   #pragma GCC optimize( Ofast )   #pragma GCC target( avx,avx2,fma )   using namespace std;   void input() { return; }   template <typename T1, typename... T2>   void input(T1 &x, T2 &...args) {     ((cin >> x), input(args...));   }   void wrt() {     cout <<   n ;     return;   }   template <typename T1, typename... T2>   void wrt(T1 x, T2... args) {     ((cout << x <<    ), wrt(args...));   }   template <typename T>   void inputlst(T &lst, int x, int y) {     for (int i = x; i < y; i++) cin >> lst[i];   }   template <typename T>   void printlst(T &lst, int x, int y) {     for (int i = x; i < y; i++) cout << lst[i] <<    ;     wrt();   }   const long long inf = INT64_MAX, MOD = 1e9 + 7, N = 10;   int main(int argc, char const *argv[]) {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     ;     int test;     cin >> test;     while (test--) {       int n, k, ans;       input(n, k);       vector<int> lst(n + 1);       inputlst(lst, 1, n + 1);       vector<vector<int> > dp(n + 1, vector<int>(n + 1, 0));       ans = n;       for (long long move = 0; move < n + 1; ++move) {         for (long long i = 1; i < n + 1; ++i) {           dp[i][move] =               max(dp[i][move], dp[i - 1][move] + (lst[i] == (i - move)));           dp[i][move + 1] = max(dp[i - 1][move], dp[i][move + 1]);           if (i == n) {             if (dp[i][move] >= k) ans = min(ans, (int)move);             if (dp[i][move + 1] >= k) ans = min(ans, (int)move + 1);           }         }       }       wrt(ans == n ? -1 : ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void debug() { cout << endl; }   template <class T, class... R>   void debug(T f, R... r) {     cout <<  [  << f <<  ] ;     debug(r...);   }   template <class T>   T mmin(T a, T b) {     return min(a, b);   }   template <class T, class... R>   T mmin(T a, R... b) {     return min(a, mmin(b...));   }   template <class T>   T mmax(T a, T b) {     return max(a, b);   }   template <class T, class... R>   T mmax(T a, R... b) {     return max(a, mmax(b...));   }   template <class T>   T mgcd(T a, T b) {     return __gcd(a, b);   }   template <class T, class... R>   T mgcd(T a, R... b) {     return __gcd(a, mgcd(b...));   }   void myin() {     freopen( 1.in ,  r , stdin);     freopen( 1.out ,  w , stdout);   }   namespace IO {   const int MX = 4e7;   char buf[MX];   int c, sz;   void begin() {     c = 0;     sz = fread(buf, 1, MX, stdin);   }   inline bool read(int &t) {     while (c < sz && buf[c] !=  -  && (buf[c] <  0  || buf[c] >  9 )) c++;     if (c >= sz) return false;     bool flag = 0;     if (buf[c] ==  - ) flag = 1, c++;     for (t = 0; c < sz &&  0  <= buf[c] && buf[c] <=  9 ; c++)       t = t * 10 + buf[c] -  0 ;     if (flag) t = -t;     return true;   }   }  // namespace IO   const int N = 1e5 + 5;   const int M = 1e5 + 5;   long long a[100005], e[200][200];   vector<long long> v, sz[100];   int main() {     long long n;     scanf( %lld , &n);     for (long long i = 1; i <= n; ++i) {       long long tmp;       scanf( %lld , &a[i]);       if (a[i]) v.push_back(a[i]);       for (long long j = 0; j < 63; ++j) {         if ((1ll << j) & a[i]) sz[j].push_back(a[i]);       }     }     for (long long i = 0; i < 63; ++i)       if (sz[i].size() > 2) {         return !printf( 3 );       }     memset(e, 0x3f, sizeof(e));     long long ans = 0x3f3f3f3f3f3f3f3f;     for (long long i = 0; i < v.size(); ++i) {       for (long long j = 0; j < v.size(); ++j) {         if (i != j && (v[i] & v[j])) e[i][j] = 1;       }     }     for (long long k = 0; k < v.size(); ++k) {       for (long long i = 0; i < v.size(); ++i) {         for (long long j = 0; j < v.size(); ++j) {           if (i == j || i == k || j == k) continue;           if ((v[i] & v[k] && v[k] & v[j])) ans = min(ans, e[i][j] + 2);         }       }       for (long long i = 0; i < v.size(); ++i) {         for (long long j = 0; j < v.size(); ++j) {           e[i][j] = min(e[i][j], e[i][k] + e[k][j]);         }       }     }     if (ans == 0x3f3f3f3f3f3f3f3f) ans = -1;     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   const long double PI = acos(-1.0);   using namespace std;   int n, m;   long long dp[505][505];   int a[505];   long long cal(int l, int r) {     if (l >= r) return 1;     long long &ret = dp[l][r];     if (ret != -1) return ret;     ret = 0;     int mn = n + 1, idx = 0;     for (int i = l; i <= r; i++) {       if (a[i] < mn) {         mn = a[i];         idx = i;       }     }     long long lft = cal(l, idx - 1);     long long rgh = cal(idx + 1, r);     for (int i = l; i < idx; i++) {       lft += cal(l, i) * cal(i + 1, idx - 1);       lft %= 998244353;     }     for (int i = idx + 1; i <= r; i++) {       rgh += cal(idx + 1, i) * cal(i + 1, r);       rgh %= 998244353;     }     lft %= 998244353;     rgh %= 998244353;     ret = rgh * lft;     ret %= 998244353;     return ret;   }   void init() { memset(dp, -1, sizeof dp); }   void read_input() {     cin >> n >> m;     for (int i = 0; i < n; i++) cin >> a[i];   }   void solve() {     init();     cal(0, n - 1);   }   void print_ans() { cout << cal(0, n - 1) <<   n ; }   int main() {     int t = 1;     while (t--) {       read_input();       solve();       print_ans();       if (t) init();     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, i, j, k, l, m[1100];     char s[1100][34];     scanf( %d , &n);     map<string, int> mp, mp2;     for (i = 0; i < n; i++) {       scanf( %s%d , s[i], &m[i]);       mp[s[i]] += m[i];     }     string name;     int max = 0;     for (map<string, int>::iterator it = mp.begin(); it != mp.end(); it++) {       if (it->second > max) max = it->second;     }     for (i = 0; i < n; i++) {       mp2[s[i]] += m[i];       if (mp[s[i]] >= max && mp2[s[i]] >= max) break;     }     puts(s[i]);     scanf( %*d );   }


#include <bits/stdc++.h>   using namespace std;   struct node {     int st, ed;   } ch[100010];   bool cmp(node a, node b) { return a.st < b.st; }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n, l, a;     cin >> n >> l >> a;     for (int i = 0; i < n; i++) {       cin >> ch[i].st >> ch[i].ed;       ch[i].ed += ch[i].st;     }     sort(ch, ch + n, cmp);     int num = 0;     num += (ch[0].st) / a;     for (int i = 0; i < n - 1; i++) {       if (ch[i + 1].st - ch[i].ed >= a) {         num += (ch[i + 1].st - ch[i].ed) / a;       }     }     if (ch[n - 1].ed < l) {       num += (l - ch[n - 1].ed) / a;     }     cout << num << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int x2, y2, x3, y3;   bool check(long long int x, long long int y) {     long long int xx = x3 * x3 + y3 * y3, tx = x2 + x, ty = y2 + y;     if (xx == 0) return x == x2 && y == y2;     long long int ret1 = tx * x3 + ty * y3, ret2 = tx * y3 - ty * x3;     if (ret1 % xx != 0 || ret2 % xx != 0) return false;     return true;   }   int main() {     long long int x1, y1;     cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;     if (check(x1, y1) || check(-x1, -y1) || check(-y1, x1) || check(y1, -x1))       cout <<  YES n ;     else       cout <<  NO n ;   }


#include <bits/stdc++.h>   using namespace std;   struct debugger {     template <typename T>     debugger& operator,(const T& v) {       cerr << v <<    ;       return *this;     }   } dbg;   vector<int> aa(200);   vector<int> bb(200);   int n, k;   int count(int i, int j) {     for (int h = i; h < n; h++) {       bb[h - i] = aa[h];     }     for (int h = 0; h < i; h++) {       bb[n - i + h] = aa[h];     }     int m = j - i;     sort(bb.begin(), bb.begin() + m);     sort(bb.begin() + m, bb.begin() + n);     int sum = 0;     for (int h = 0; h < m; h++) {       sum += bb[h];     }     for (int s = 0; s < k; s++) {       int p = s;       int q = n - 1 - s;       if (p >= m || q < m || bb[p] >= bb[q]) {         break;       }       sum += bb[q] - bb[p];     }     return sum;   }   int main() {     cin >> n >> k;     for (int i = 0; i < n; i++) {       int a;       cin >> a;       aa[i] = a;     }     int maxVal = INT_MIN;     for (int i = 0; i < n; i++) {       for (int j = i + 1; j <= n; j++) {         int cnt = count(i, j);         maxVal = max(maxVal, cnt);       }     }     cout << maxVal << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t, n;     cin >> t;     for (int l = 0; l < t; l++) {       cin >> n;       int k;       k = 0;       int c;       c = 0;       char arr[n][5];       for (int i = 0; i < n; i++) {         for (int j = 0; j < 5; j++) {           cin >> arr[i][j];         }       }       for (int j = 0; j < 5; j++) {         k = 0;         for (int m = j + 1; m < 5; m++) {           int first = 0;           int second = 0;           int tie = 0;           for (int n1 = 0; n1 < n; n1++) {             if (arr[n1][j] ==  1  && arr[n1][m] ==  1 ) {               tie++;             } else {               if (arr[n1][j] ==  1 ) {                 second++;               }               if (arr[n1][m] ==  1 ) {                 first++;               }             }           }           if (first + second + tie == n && second + tie >= n / 2 &&               first + tie >= n / 2) {             c = 1;           }         }       }       if (c == 0) {         cout <<  NO  << endl;       } else {         cout <<  YES  << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC optimize( unroll-loops )   #pragma GCC target( sse2 )   using namespace std;   template <typename Arg1>   void __f(const char* name, Arg1&& arg1) {     std::cerr << name <<   :   << arg1 <<   n ;   }   template <typename Arg1, typename... Args>   void __f(const char* names, Arg1&& arg1, Args&&... args) {     const char* comma = strchr(names + 1,  , );     std::cerr.write(names, comma - names) <<   :   << arg1 <<   |  ;     __f(comma + 1, args...);   }   long long max(long long a, long long b) { return (a > b) ? a : b; }   long long min(long long a, long long b) { return (a < b) ? a : b; }   void amax(long long& a, long long b) { a = max(a, b) % 1000000007; }   void amin(long long& a, long long b) { a = min(a, b) % 1000000007; }   void inc(long long& a, long long b) { a = (a + b) % 1000000007; }   void dec(long long& a, long long b) { a = (a - b + 1000000007) % 1000000007; }   long long n, a, b;   long long ans = 1e9;   void find(long long la, long long lb, long long level = 0) {     if (la == 0 && lb == 0) {       amin(ans, level);       return;     }     for (long long i = 0; i <= la; i++) {       long long n2 = n - i * a;       if (n2 < 0) break;       long long usedb = min(n2 / b, lb);       n2 -= usedb * b;       long long ii = i;       ii += n2 / a;       long long temp = n2 / a;       n2 -= temp * a;       ii = min(la, ii);       if (usedb == 0 && ii == 0) continue;       find(la - ii, lb - usedb, level + 1);     }   }   long long solve() {     cin >> n >> a >> b;     find(4, 2);     cout << ans;     return 0;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long t = 1;     while (t--) {       solve();     }   }


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


#include <bits/stdc++.h>   using namespace std;   const int maxn = 105;   int no[maxn][maxn][15], sum[maxn][maxn][15];   int main() {     int n, q, c, ans, i, j, k, x, y, s, ss, t, x1, x2, y1, y2, tt, num;     while (scanf( %d%d%d , &n, &q, &c) != EOF) {       memset(no, 0, sizeof(no));       memset(sum, 0, sizeof(sum));       for (i = 1; i <= n; i++) {         scanf( %d%d%d , &x, &y, &s);         no[x][y][s]++;       }       for (j = 1; j <= 100; j++) {         for (i = 1; i <= 100; i++) {           for (k = 0; k <= c; k++) {             sum[i][j][k] = sum[i - 1][j][k] + no[i][j][k];           }         }       }       while (q--) {         ans = 0;         scanf( %d%d%d%d%d , &t, &x1, &y1, &x2, &y2);         for (j = y1; j <= y2; j++) {           for (k = 0; k <= c; k++) {             num = sum[x2][j][k] - sum[x1][j][k] + no[x1][j][k];             if (num > 0) {               if (t <= c - k)                 ss = k + t;               else {                 x = t - (c - k);                 tt = x % (c + 1);                 if (tt)                   ss = tt - 1;                 else                   ss = c;               }               ans += num * ss;             }           }         }         printf( %d n , ans);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> v1;   int status[(100000007 / 32) + 10];   bool check1(int n, int pos) { return (bool)(n & (1 << pos)); }   int set1(int n, int pos) { return n = n | (1 << pos); }   void sieve() {     int i, j, k;     k = int(sqrt(100000007));     for (i = 3; i <= k; i += 2) {       if (check1(status[i / 32], i % 32) == 0) {         for (j = i * i; j <= 100000007; j += 2 * i) {           status[j / 32] = set1(status[j / 32], j % 32);         }       }     }     v1.push_back(2);     for (i = 3; i < 100000007; i += 2) {       if (check1(status[i / 32], i % 32) == 0) v1.push_back(i);     }   }   vector<long long int> v2;   void factor(long long int k) {     long long int i, a;     v2.clear();     for (i = 0; i < v1.size(); i++) {       if (k == 1) break;       a = v1[i];       while (k % a == 0) {         if (k == 1) break;         v2.push_back(a);         k /= a;       }     }     if (k != 1) v2.push_back(k);   }   int main() {     sieve();     long long int a, b, c, d, i, j, k, l, m, n;     cin >> n;     factor(n);     if (v2.size() == 1 || v2.size() == 0) {       cout <<  1  << endl;       cout <<  0  << endl;       return 0;     }     if (v2.size() == 2) {       cout <<  2  << endl;       return 0;     }     cout <<  1  << endl;     cout << v2[0] * v2[1] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100 + 5;   const int inf = 1e9 + 7;   int n, m;   int num[MAXN];   map<int, int> q;   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) scanf( %d , &num[i]);     for (int i = 2; i <= n; ++i) {       q[num[i] - num[i - 1]]++;     }     if (q.size() == 1)       printf( %d n , num[n] + num[2] - num[1]);     else       printf( %d n , num[n]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string ulaz, jed =  1 , dva =  14 , tri =  144 ;   bool je[10];   int main() {     cin >> ulaz;     int l = ulaz.size();     for (int i = 0; i < l; i++) je[i] = false;     for (int i = 0; i < l; i++) {       if (je[i] == true) continue;       if (i + 2 < l) {         string nov;         nov = ulaz[i];         nov += ulaz[i + 1];         nov += ulaz[i + 2];         if (nov == tri) {           je[i] = true;           je[i + 1] = true;           je[i + 2] = true;           i += 2;           continue;         }       }       if (i + 1 < l) {         string nov;         nov = ulaz[i];         nov += ulaz[i + 1];         if (nov == dva) {           je[i] = true;           je[i + 1] = true;           i += 1;           continue;         }       }       if (ulaz[i] == jed[0]) {         je[i] = true;         continue;       }     }     for (int i = 0; i < l; i++)       if (je[i] == false) {         cout <<  NO  << endl;         return 0;       }     cout <<  YES  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const ll P = 1e9 + 7;   ll N, M, K, R, C;   ll Dx, Dy;   ll mult(ll a, ll b) { return (a * b) % P; }   ll exp(ll num_classes) {     if (num_classes == 0) {       return 1;     }     ll temp = exp(num_classes / 2);     return (num_classes % 2) ? mult(K, mult(temp, temp)) : mult(temp, temp);   }   void input() {     ll Ax, Ay, Bx, By;     cin >> N >> M >> K >> R >> C;     cin >> Ax >> Ay >> Bx >> By;     Dx = (Ax > Bx) ? Ax - Bx : Bx - Ax;     Dy = (Ay > By) ? Ay - By : By - Ay;   }   ll count_classes() {     ll overlap = ((R > Dx) ? R - Dx : 0) * ((C > Dy) ? C - Dy : 0);     ll classes = N * M - (2 * R * C - overlap);     if (overlap == 0) {       return classes + R * C;     }     if (Dx == 0 && Dy == 0) {       return classes + R * C;     }     return classes + (R * Dy) + (C * Dx) - Dx * Dy;   }   int main() {     input();     cout << exp(count_classes()) << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int num;     scanf( %d  , &num);     printf( %d , num + 1);   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = (1e9 + 7);   const long long inf = (1e18 + 3);   const long long N = 1e7 + 5;   void no() {     cout <<  -1 ;     exit(0);   }   void yes() {     cout <<  YES ;     exit(0);   }   long long powmod(long long a, long long b) {     long long res = 1;     a %= mod;     assert(b >= 0);     for (; b; b >>= 1) {       if (b & 1) res = res * a % mod;       a = a * a % mod;     }     return res;   }   long long inv(long long a) { return powmod(a, mod - 2); }   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   long long mul(long long a, long long b) { return a * b % mod; }   long long add(long long a, long long b) { return (a + b) % mod; }   long long sub(long long a, long long b) { return (a - b + mod) % mod; }   int main() {     string s;     cin >> s;     long long cnt = 1, res = 0;     for (auto i : s) {       if (i ==  a )         cnt <<= 1, cnt %= mod;       else         res = add(res, cnt - 1);     }     cout << res;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool checkC(int n) {     for (int i = 2; i * i <= n; i++) {       if (n % i == 0) return 1;     }     return 0;   }   void per(string s, int i, int &num, string &ans) {     if (i == s.length()) {       if (num != 0 && checkC(num)) {         int x = num;         int d = 0;         while (x != 0) {           x /= 10;           d++;         }         if (d > 0) {           if (d < ans.length() || ans.length() == 0) ans = to_string(num);         }       }     } else {       int k = num;       num = num * 10 + (s[i] -  0 );       per(s, i + 1, num, ans);       num = k;       per(s, i + 1, num, ans);     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int test;     cin >> test;     while (test--) {       int k;       cin >> k;       string s;       cin >> s;       vector<int> c(10, 0);       int ans = -1;       for (int i = 0; i < k; i++) {         int vl = s[i] -  0 ;         if (vl == 1 || vl == 4 || vl == 6 || vl == 8 || vl == 9) {           ans = vl;           break;         }         c[vl]++;       }       if (ans != -1) {         cout <<  1 n ;         cout << ans <<   n ;       } else {         if (c[2] >= 2) {           cout <<  2 n ;           cout <<  22 n ;         } else if (c[3] >= 2) {           cout <<  2 n ;           cout <<  33 n ;         } else if (c[5] >= 2) {           cout <<  2 n ;           cout <<  55 n ;         } else if (c[7] >= 2) {           cout <<  2 n ;           cout <<  77 n ;         } else {           string pa =   ;           int num = 0;           per(s, 0, num, pa);           cout << pa.length() <<   n ;           cout << pa <<   n ;         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int Maxn = 500010;   const int inf = 2147483647;   const double pi = acos(-1.0);   int read() {     int x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) x = x * 10 + ch -  0 , ch = getchar();     return x * f;   }   int n, m, k, a[Maxn];   long long ans, rest;   bool del[Maxn];   struct Edge {     int x, y;   } e[Maxn];   int fa[Maxn << 1], dep[Maxn << 1];   int findfa(int x) { return ((fa[x] == x) ? x : findfa(fa[x])); }   int top = 0, sta[Maxn << 1], o, fa1[Maxn << 1], dep1[Maxn << 1];   void merge(int x, int y) {     int fx = findfa(x), fy = findfa(y);     if (dep[fx] < dep[fy]) swap(fx, fy);     sta[++top] = fy;     fa1[top] = fa[fy], dep1[top] = dep[fx];     fa[fy] = fx;     dep[fx] = max(dep[fx], dep[fy] + 1);   }   void resume() {     while (top > o) {       int fy = sta[top];       dep[fa[fy]] = dep1[top];       fa[fy] = fa1[top];       --top;     }   }   vector<pair<int, int> > g[Maxn];   int tot = 0;   map<int, map<int, int> > mp;   int main() {     memset(dep, 0, sizeof(dep));     memset(del, false, sizeof(del));     n = read(), m = read(), k = read();     ans = (long long)k * (k - 1ll) / 2ll;     rest = k - 1;     for (int i = 1; i <= n; i++) a[i] = read();     for (int i = 1; i <= m; i++) e[i].x = read(), e[i].y = read();     for (int i = 1; i <= n * 2; i++) fa[i] = i;     for (int i = 1; i <= m; i++)       if (!del[a[e[i].x]] && a[e[i].x] == a[e[i].y]) {         int fx = findfa(e[i].x), fy = findfa(e[i].y);         if (fx == fy)           del[a[e[i].x]] = true, ans -= rest, rest--;         else           merge(e[i].x, e[i].y + n), merge(e[i].y, e[i].x + n);       }     o = top;     for (int i = 1; i <= m; i++)       if (a[e[i].x] != a[e[i].y] && !del[a[e[i].x]] && !del[a[e[i].y]]) {         int cx = a[e[i].x], cy = a[e[i].y];         if (cx > cy) swap(cx, cy);         if (!mp[cx][cy]) mp[cx][cy] = ++tot;         g[mp[cx][cy]].push_back(make_pair(e[i].x, e[i].y));       }     for (int i = 1; i <= tot; i++) {       for (int j = 0; j < g[i].size(); j++) {         int x = g[i][j].first, y = g[i][j].second;         int fx = findfa(x), fy = findfa(y);         if (fx == fy) {           ans--;           break;         }         merge(x, y + n);         merge(y, x + n);       }       resume();     }     printf( %lld , ans);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long a, b, c, l;     cin >> a >> b >> c >> l;     long long cnt = (l + 1) * (l + 2) * (l + 3) / 6;     for (int i = 0; i <= l; i++) {       long long x = min(l - i, c + i - a - b);       if (x < 0) continue;       cnt -= (x + 1) * (x + 2) / 2;     }     for (int i = 0; i <= l; i++) {       long long x = min(l - i, b + i - a - c);       if (x < 0) continue;       cnt -= (x + 1) * (x + 2) / 2;     }     for (int i = 0; i <= l; i++) {       long long x = min(l - i, a + i - b - c);       if (x < 0) continue;       cnt -= (x + 1) * (x + 2) / 2;     }     cout << cnt << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1000000007;   const long long INFLL = 1000000000000000007;   const long long MOD = 998244353;   bool comp(long long a, long long b) { return a > b; }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     int n, k;     cin >> n >> k;     vector<long long> v;     for (int i = 0; i < n; i++) {       long long x;       cin >> x;       v.push_back(x);     }     long long ans = 0, ans1 = 1, licz = -INFLL;     for (int i = 0; i < n; i++) {       if (v[i] <= n - k)         licz++;       else {         if (licz > 0) ans1 *= (licz + 1);         ans1 %= MOD;         ans += v[i];         licz = 0;       }     }     cout << ans <<     << ans1;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC target( avx,avx2,fma )   using namespace std;   const int MOD = 1e9 + 7;   const long long INF = 1e18;   long long add(long long a, long long b) {     a = a % MOD;     b = b % MOD;     return (a + b) % MOD;   }   long long sub(long long a, long long b) {     a = a % MOD;     b = b % MOD;     return (a - b + MOD) % MOD;   }   long long mul(long long a, long long b) {     a = a % MOD;     b = b % MOD;     return ((a * b) % MOD + MOD) % MOD;   }   long long mod_pow(long long n, long long x) {     int res = 1;     while (x > 0) {       if (x % 2 == 1) res = (res * n) % MOD;       n = (n * n) % MOD;       x /= 2;     }     return res;   }   void solve() {     string t, order =   ;     cin >> t;     map<char, int> m;     int n = 0;     for (int i = t.size() - 1; i >= 0; i--) {       if (m[t[i]] == 0) {         order = t[i] + order;       }       m[t[i]]++;     }     for (int i = 0; i < order.size(); i++) {       m[order[i]] /= (i + 1);       n += m[order[i]];     }     string s = t.substr(0, n);     string sc = s;     bool temp = true;     int ind = n;     for (int i = 0; i < order.size(); i++) {       string temp =   ;       for (int j = 0; j < s.size(); j++) {         if (s[j] == order[i]) continue;         temp += s[j];       }       s = temp;       for (int j = 0; j < s.size(); j++) {         if (ind == t.size() || t[ind] != s[j]) {           cout <<  -1 n ;           return;         }         ind++;       }     }     if (ind != t.size()) temp = false;     if (temp) {       cout << sc <<     << order <<   n ;     } else {       cout <<  -1 n ;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int tc = 1;     cin >> tc;     while (tc--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   void c_p_c() {}   int main(int argc, char const *argv[]) {     c_p_c();     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     int n;     string arr;     cin >> n >> arr;     int cnt = 0;     if (n == 1) {       cout << cnt << endl;       cout << arr << endl;       return 0;     }     for (int i = 1; i < n; i++) {       if (arr[i] == arr[i - 1] && arr[i] == arr[i + 1]) {         cnt++;         if (arr[i] ==  R )           arr[i] =  G ;         else if (arr[i] ==  G )           arr[i] =  R ;         else {           arr[i] =  G ;         }         i++;       } else if (arr[i] == arr[i - 1]) {         cnt++;         if (arr[i] ==  R  && arr[i + 1] ==  B ) {           arr[i] =  G ;           i++;         } else if (arr[i] ==  R  && arr[i + 1] ==  G ) {           arr[i] =  B ;           i++;         } else if (arr[i] ==  G  && arr[i + 1] ==  R ) {           arr[i] =  B ;           i++;         } else if (arr[i] ==  G  && arr[i + 1] ==  B ) {           arr[i] =  R ;           i++;         } else if (arr[i] ==  B  && arr[i + 1] ==  G ) {           arr[i] =  R ;           i++;         } else if (arr[i] ==  B  && arr[i + 1] ==  R ) {           arr[i] =  G ;           i++;         } else {           if (arr[i - 1] ==  R )             arr[i] =  G ;           else if (arr[i - 1] ==  G )             arr[i] =  R ;           else             arr[i] =  R ;         }       }     }     cout << cnt << endl;     cout << arr << endl;   }


#include <bits/stdc++.h>   using namespace std;   const long long infll = powl(2, 62) - 1;   const long long mod = pow(10, 9) + 7;   int64_t extGcd(int64_t a, int64_t b, int64_t& x, int64_t& y) {     if (!a) {       x = 0;       y = 1;       return b;     }     int64_t x1, y1;     int64_t d = extGcd(b % a, a, x1, y1);     x = y1 - (b / a) * x1;     y = x1;     return d;   }   inline long long addMod(long long a, long long b, long long m = mod) {     return ((int64_t)a + b) % m;   }   inline long long mulMod(long long a, long long b, long long m = mod) {     return ((int64_t)a * b) % m;   }   inline long long divMod(long long a, long long b, long long m = mod) {     int64_t x, y;     int64_t g = extGcd(b, m, x, y);     if (g != 1) {       cerr <<  Bad gcd!  << endl;       for (;;)         ;     }     x = (x % m + m) % m;     return mulMod(a, x, m);   }   const long long factRange = 1000000;   long long fact[factRange];   inline void precalcFactorials() {     fact[0] = 1;     for (long long i = 1; i < factRange; i++) {       fact[i] = mulMod(fact[i - 1], i);     }   }   inline long long F(long long n) { return (n < 0) ? 0 : fact[n]; }   inline long long C(long long n, long long k) {     return divMod(F(n), mulMod(F(n - k), F(k)));   }   int32_t main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     precalcFactorials();     string bracket;     cin >> bracket;     vector<long long> open(bracket.size()), close(bracket.size());     long long count = 0;     for (long long i = 0; i < (long long)(bracket.size()); ++i) {       if (bracket[i] ==  ( ) count++;       open[i] = count;     }     count = 0;     for (long long i = (long long)(bracket.size()) - 1; i >= 0; --i) {       if (bracket[i] ==  ) ) count++;       close[i] = count;     }     long long ans = 0;     for (long long i = 0; i < (long long)(bracket.size()); ++i) {       if (bracket[i] !=  (  || close[i] == 0) continue;       if (bracket[i] ==  ( ) {         ans += C(open[i] + close[i] - 1, open[i]);         ans %= mod;       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void Input_Preparing() {}   void Processing() {     int a, b;     cin >> a >> b;     cout << min(a, b) <<     << (max(a, b) - min(a, b)) / 2;   }   int main() {     std::cin.tie(0)->sync_with_stdio(0);     ;     Processing();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int l[(100000 + 10)], size = 0;   int fa[(100000 + 10)], son[(100000 + 10)], n, x, spec, specp;   bool b[(100000 + 10)] = {0}, f[(100000 + 10)] = {0};   int main() {     scanf( %d%d , &n, &x);     for (int i = 1; i <= n; i++) scanf( %d , &fa[i]);     for (int i = 1; i <= n; i++)       if (fa[i]) son[fa[i]] = i;     for (int i = 1; i <= n; i++)       if (fa[i] == 0) {         int tot = 1, j = i;         bool flag = b[x];         b[i] = 1;         j = i;         if (i == x) spec = 1;         while (son[j]) {           b[son[j]] = 1, tot++, j = son[j];           if (j == x) spec = tot;         }         if (b[x] == flag)           l[++size] = tot;         else           specp = spec;       }     f[0] = 1;     for (int i = 1; i <= size; i++) {       for (int j = n; j >= 0; j--) {         if (f[j]) f[j + l[i]] = 1;       }     }     for (int j = 0; j < n + 1; j++)       if (f[j]) cout << j + specp << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string to_string(string s) { return     + s +    ; }   string to_string(const char* s) { return to_string((string)s); }   template <typename A, typename B>   string to_string(pair<A, B> p) {     return  (  + to_string(p.first) +  ,   + to_string(p.second) +  ) ;   }   template <typename A>   string to_string(A v) {     bool first = true;     string res =  { ;     for (const auto& x : v) {       if (!first) {         res +=  ,  ;       }       first = false;       res += to_string(x);     }     res +=  } ;     return res;   }   void debug_out() { cerr << endl; }   template <typename Head, typename... Tail>   void debug_out(Head H, Tail... T) {     cerr <<     << to_string(H);     debug_out(T...);   }   const long double eps = 1e-12;   const int N = 2e6 + 9;   long long ans[N];   pair<pair<int, int>, int> a[N];   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n, m;     cin >> n >> m;     for (int i = 0; i < n; i++) {       cin >> a[i].first.first;       a[i].second = i;     }     for (int i = 0; i < n; i++) {       cin >> a[i].first.second;       a[i].first.second *= -1;     }     sort(a, a + n);     multiset<int> ss;     for (int i = 0; i < n; i++) {       42;       int j = 0;       auto it = ss.begin();       ans[a[i].second] = a[i].first.second;       while (j < m && it != ss.end()) {         ans[a[i].second] += (*it);         it++;         j++;       }       ss.insert(a[i].first.second);     }     for (int i = 0; i < n; i++) cout << -ans[i] <<    ;     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[200001];   int main() {     int n, w;     cin >> n >> w;     for (int i = 0; i < 2 * n; i++) {       cin >> a[i];     }     sort(a, a + 2 * n);     double x = min((double)a[0], (double)a[n] / 2);     double ans = min((double)w, (double)3 * n * x);     cout.precision(10);     cout << fixed;     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 5;   const int mod = 1e9 + 7;   void solve() {     long long v1, v2, t, d;     cin >> v1 >> v2 >> t >> d;     long long ans = 0;     for (int i = 0; i < t; i++) ans += min(v1 + d * i, v2 + (t - i - 1) * d);     cout << ans << endl;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int t = 1;     while (t--) solve();     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   vector<pair<long long, long long> > v(3000);   int main() {     std::ios::sync_with_stdio(false);     long long n, x1, y1, x2, y2, x, y;     cin >> n;     cin >> x1 >> y1 >> x2 >> y2;     long long d1, d2;     for (long long i = (long long)(0); i <= (long long)(n - 1); i++) {       cin >> x >> y;       v[i].first = abs(x - x1) * abs(x - x1) + abs(y - y1) * abs(y - y1);       v[i].second = abs(x - x2) * abs(x - x2) + abs(y - y2) * abs(y - y2);     }     v.push_back(make_pair(0, 0));     long long ans = LLONG_MAX;     for (long long i = (long long)(0); i <= (long long)(n); i++) {       long long d1 = v[i].first;       long long d2 = 0;       for (long long j = (long long)(0); j <= (long long)(n); j++) {         if (v[j].first > d1) d2 = max(v[j].second, d2);       }       ans = min(ans, d1 + d2);     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int rbq[505][505];   int score[505];   int main() {     int n, m, q;     while (~scanf( %d%d%d , &n, &m, &q)) {       for (int i = 1; i <= n; i++) {         for (int j = 1; j <= m; j++) {           scanf( %d , &rbq[i][j]);         }       }       for (int i = 1; i <= n; i++) {         int max = 0;         for (int j = 1; j <= m; j++) {           int count = 0;           while (j <= m && rbq[i][j] == 1) {             j++;             count++;           }           if (count > max) max = count;         }         score[i] = max;       }       for (int i = 0; i < q; i++) {         int r, l;         scanf( %d%d , &r, &l);         if (rbq[r][l] == 0)           rbq[r][l] = 1;         else           rbq[r][l] = 0;         int max = 0;         for (int j = 1; j <= m; j++) {           int count = 0;           while (j <= m && rbq[r][j] == 1) {             j++;             count++;           }           if (count > max) max = count;         }         score[r] = max;         int max_score = 0;         for (int j = 1; j <= n; j++) {           if (score[j] > max_score) max_score = score[j];         }         printf( %d n , max_score);       }     }     return 0;   }


#include <bits/stdc++.h>   #define f(c,a,b) for(int c=a; c<=b; c++)   #define N 5000010   #define pii pair<int,int>   #define mp make_pair   #define fi first   #define se second   #define sl (u<<1)   #define sr ((u<<1)+1)   #define pb push_back      using namespace std;   typedef double db;   typedef long long ll;   struct node{    int u,v,x;    bool operator < (const node& a) const{ return x<a.x; }   }b[N];   int k[N];      bool ask(int i,int j){    cout<< ?  <<i<<   <<j<<endl;    string ans;    cin>>ans;    if(ans== Yes ) return true; else return false;   }      int main(){    // freopen( owo.in , r ,stdin);    // ios::sync_with_stdio(false);    // cin.tie(nullptr);    int n;    cin >> n;    f(i,1,n) cin>>k[i];    int id=0;    f(i,1,n){     f(j,i+1,n){      b[++id] = (node){ i,j,abs(k[i]-k[j]) };     }    }    sort(b+1,b+id+1);    for(int i=id; i>=1; i--) {     int ti=b[i].u, tj=b[i].v;     if(k[ti]>k[tj]) {      if(ask(ti,tj)){       cout<< !  <<ti<<   <<tj<<endl;       return 0;      }     }else{      if(ask(tj,ti)){       cout<< !  <<ti<<   <<tj<<endl;       return 0;      }      }    }    cout<< !  <<0<<   <<0<<endl;    return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 512345, lgN = 20, rootN = 1123;   const double eps = 1e-11;   vector<int> cities;   int root = -1;   int dp[N];   bool visited[N], rem[N];   vector<int> adj[N];   void dfsTree(int v) {     int sum = 0;     auto it = lower_bound(cities.begin(), cities.end(), v);     if (it < cities.end() && *it == v) ++sum;     for (int i = 0; i < adj[v].size(); ++i) {       int u = adj[v][i];       if (visited[u]) continue;       visited[u] = true;       dfsTree(u);       sum += dp[u];     }     if (sum == 0)       rem[v] = true;     else if (sum == cities.size() && root == -1)       root = v;     else if (sum == cities.size())       rem[v] = true;     dp[v] = sum;   }   pair<int, int> bfsDistance(int src) {     memset(visited, false, sizeof visited);     queue<pair<int, int> > q;     q.push(make_pair(src, 0));     visited[src] = true;     pair<int, int> ret = make_pair(src, 0);     while (!q.empty()) {       int v = q.front().first, dist = q.front().second;       q.pop();       if (dist > ret.second || (dist == ret.second && v < ret.first))         ret = make_pair(v, dist);       for (int i = 0; i < adj[v].size(); ++i) {         int u = adj[v][i];         if (visited[u] || rem[u]) continue;         visited[u] = true;         q.push(make_pair(u, dist + 1));       }     }     return ret;   }   int main() {     int n, c;     scanf( %d %d , &n, &c);     int u, v;     for (int i = 1; i < n; ++i) {       scanf( %d %d , &u, &v);       adj[u].push_back(v), adj[v].push_back(u);     }     cities.resize(c);     for (int i = 0; i < cities.size(); ++i) scanf( %d , &cities[i]);     sort(cities.begin(), cities.end());     visited[1] = true;     dfsTree(1);     pair<int, int> x = bfsDistance(root);     pair<int, int> y = bfsDistance(x.first);     printf( %d n , min(x.first, y.first));     int ct = 0;     for (int i = 1; i <= n; ++i)       if (!rem[i]) ++ct;     int ans = 2 * (ct - 1) - y.second;     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int f[200010], fi[200010];   const int MOD = 1e9 + 7;   int add(long long a, long long b) { return (a + b) % MOD; }   int mul(long long a, long long b) { return (a * b) % MOD; }   int fp(long long a, int b) {     if (b == 0) return 1;     int tp = fp(a, b >> 1);     tp = mul(tp, tp);     if (b & 1)       return mul(tp, a);     else       return tp;   }   int comb(int n, int k) {     if (k > n) return 0;     return mul(f[n], mul(fi[n - k], fi[k]));   }   int h, w, n, dp[2010];   vector<pair<int, int> > v;   int main() {     f[0] = fi[0] = 1;     for (int i = 1; i <= 200002; i++) {       f[i] = mul(i, f[i - 1]);       fi[i] = fp(f[i], MOD - 2);     }     scanf( %d%d%d , &h, &w, &n);     v.resize(n);     for (int i = 0; i < n; i++) {       scanf( %d%d , &v[i].first, &v[i].second);     }     sort(v.begin(), v.end());     v.emplace_back(h, w);     for (int i = 0; i <= n; i++) {       dp[i] = comb(v[i].first + v[i].second - 2, v[i].first - 1);       for (int j = 0; j < i; j++) {         if (v[j].first <= v[i].first && v[j].second <= v[i].second) {           dp[i] =               add(dp[i],                   -mul(comb(v[i].first + v[i].second - (v[j].first + v[j].second),                             v[i].first - v[j].first),                        dp[j]));           if (dp[i] < 0) dp[i] += MOD;         }       }     }     printf( %d n , dp[n]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<string> grid;   int main() {     int n;     cin >> n;     string line =   ;     for (int i = 0; i < n; i++) {       cin >> line;       grid.push_back(line);     }     bool rowblock = false;     bool colblock = false;     for (int i = 0; i < n; i++) {       bool found = false;       for (int j = 0; j < n; j++) {         if (grid[i][j] ==  . ) {           found = true;         }       }       if (!found) {         rowblock = true;       }     }     for (int j = 0; j < n; j++) {       bool found = false;       for (int i = 0; i < n; i++) {         if (grid[i][j] ==  . ) {           found = true;         }       }       if (!found) {         colblock = true;       }     }     if (rowblock && colblock) {       cout << -1 << endl;       return 0;     }     if (rowblock == false) {       for (int i = 0; i < n; i++) {         for (int j = 0; j < n; j++) {           if (grid[i][j] ==  . ) {             cout << i + 1 <<     << j + 1 << endl;             break;           }         }       }     } else {       for (int j = 0; j < n; j++) {         for (int i = 0; i < n; i++) {           if (grid[i][j] ==  . ) {             cout << i + 1 <<     << j + 1 << endl;             break;           }         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 2e5 + 5;   const long long MOD = 1e9 + 7;   long long n, a[55];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cin >> n;     for (long long i = 0; i < n; i++) cin >> a[i];     sort(a, a + n);     if (a[0] == a[n / 2])       cout <<  Bob ;     else       cout <<  Alice ;   }


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


#include <bits/stdc++.h>   using namespace std;   const double ex = 1e-6;   double pow(double x, int n) {     double ret = 1;     while (n) {       if (n % 2) ret *= x;       n >>= 1;       x *= x;     }     return ret;   }   int main() {     double n;     int m;     while (scanf( %lf %d , &n, &m) != EOF) {       double ans = n;       double i = n - 1;       double k;       for (i; i >= 1; i -= 1) {         k = pow(i / n, m);         if (k < ex) break;         ans -= k;       }       printf( %0.4lf n , ans);     }   }


#include <bits/stdc++.h>   using namespace std;   struct coord {     int c, f, v;   };   coord var, pos;   int n, m, i, x, cont, h;   int pasos[1001][1001];   bool ya[1001][1001], e;   char mapa[1001][1001];   queue<coord> cola;   stack<coord> pila;   int main() {     scanf( %d%d , &n, &m);     for (i = 0; i < n; i++) {       scanf( %s , mapa[i]);     }     for (i = 0; i < n; i++) {       for (x = 0; x < m; x++) {         if (mapa[i][x] ==  T )           ya[i][x] = true;         else if (mapa[i][x] ==  E ) {           ya[i][x] = true;           var.c = i;           var.f = x;           var.v = 0;           cola.push(var);         }       }     }     while (!cola.empty()) {       pos = cola.front();       cola.pop();       if (pos.c - 1 >= 0 && ya[pos.c - 1][pos.f] == false) {         pos.c--;         cola.push(pos);         ya[pos.c][pos.f] = true;         pasos[pos.c][pos.f] = pasos[pos.c + 1][pos.f] + 1;         if (mapa[pos.c][pos.f] ==  S ) {           h = pasos[pos.c][pos.f];         }         pos.c++;       }       if (pos.c + 1 < n && ya[pos.c + 1][pos.f] == false) {         pos.c++;         cola.push(pos);         ya[pos.c][pos.f] = true;         pasos[pos.c][pos.f] = pasos[pos.c - 1][pos.f] + 1;         if (mapa[pos.c][pos.f] ==  S ) {           h = pasos[pos.c][pos.f];         }         pos.c--;       }       if (pos.f - 1 >= 0 && ya[pos.c][pos.f - 1] == false) {         pos.f--;         cola.push(pos);         ya[pos.c][pos.f] = true;         pasos[pos.c][pos.f] = pasos[pos.c][pos.f + 1] + 1;         if (mapa[pos.c][pos.f] ==  S ) {           h = pasos[pos.c][pos.f];         }         pos.f++;       }       if (pos.f + 1 < m && ya[pos.c][pos.f + 1] == false) {         pos.f++;         cola.push(pos);         ya[pos.c][pos.f] = true;         pasos[pos.c][pos.f] = pasos[pos.c][pos.f - 1] + 1;         if (mapa[pos.c][pos.f] ==  S ) {           h = pasos[pos.c][pos.f];         }         pos.f--;       }     }     for (i = 0; i < n; i++) {       for (x = 0; x < m; x++) {         if (mapa[i][x] -  0  > 0 && mapa[i][x] -  0  < 10) {           if (pasos[i][x] <= h && ya[i][x] == true) cont += mapa[i][x] -  0 ;         }       }     }     printf( %d , cont);   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     int n, t;     while (cin >> n >> t) {       int x, y;       vector<pair<int, int> > a;       vector<pair<int, int> > v;       for (int i = 0; i < n; i++) {         cin >> x >> y;         a.push_back(make_pair(x, y));       }       for (int i = 0; i < n; i++) {         while (a[i].first < t) a[i].first += a[i].second;         v.push_back(make_pair(a[i].first, i));       }       sort(v.begin(), v.end());       cout << (v[0].second) + 1 << endl;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     solve();   }


#include <bits/stdc++.h>   using namespace std;   struct edge {     int y, stat;   };   struct query {     int curNode;     int curLength;     int curGood;   };   vector<edge> vec[100005];   pair<long long, long long> best[100005];   long long path[100005], pathStatus[100005];   int n, m;   queue<query> q;   set<pair<int, int> > badRoads;   map<pair<int, int>, int> goodRoads;   int main() {     scanf( %d %d , &n, &m);     for (int i = 0; i < m; i++) {       int x, y, z;       scanf( %d %d %d , &x, &y, &z);       if (z == 1) goodRoads[make_pair(min(x, y), max(x, y))]++;       x--, y--;       vec[x].push_back({y, z});       vec[y].push_back({x, z});     }     for (int i = 0; i < n; i++) best[i].first = 1e10;     q.push({0, 0, 0});     while (!q.empty()) {       query ab = q.front();       q.pop();       if (best[ab.curNode].first < ab.curLength ||           (best[ab.curNode].first == ab.curLength &&            best[ab.curNode].second > ab.curGood))         continue;       int vSize = vec[ab.curNode].size();       for (int i = 0; i < vSize; i++) {         int nextNode = vec[ab.curNode][i].y;         int nextGood = vec[ab.curNode][i].stat + ab.curGood;         if (ab.curLength + 1 < best[nextNode].first ||             (best[nextNode].first == ab.curLength + 1 &&              nextGood > best[nextNode].second)) {           best[nextNode].first = ab.curLength + 1;           best[nextNode].second = nextGood;           q.push({nextNode, ab.curLength + 1, nextGood});           path[nextNode] = ab.curNode;           pathStatus[nextNode] = vec[ab.curNode][i].stat;         }       }     }     int myNode = n - 1;     while (myNode) {       if (pathStatus[myNode]) {         int minVal = min(path[myNode] + 1, myNode + 1LL);         int maxVal = max(path[myNode] + 1, myNode + 1LL);         goodRoads[make_pair(minVal, maxVal)]--;       } else         badRoads.insert({path[myNode] + 1, myNode + 1});       myNode = path[myNode];     }     vector<pair<pair<int, int>, int> > ans;     for (auto it : badRoads)       ans.push_back(make_pair(make_pair(it.first, it.second), 1));     for (auto it : goodRoads) {       if (it.second == 0) continue;       for (int i = 0; i < it.second; i++)         ans.push_back(make_pair(make_pair(it.first.first, it.first.second), 0));     }     int curSize = ans.size();     printf( %d n , curSize);     for (int i = 0; i < curSize; i++)       printf( %d %d %d n , ans[i].first.first, ans[i].first.second,              ans[i].second);   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     long long int n, m;     cin >> n >> m;     long long int n1, m1;     cin >> n1 >> m1;     long long int a[n], b[m];     for (long long int i = 0; i < n; i++) cin >> a[i];     for (long long int i = 0; i < m; i++) cin >> b[i];     if (a[n1 - 1] < b[m - m1])       cout <<  YES  << endl;     else       cout <<  NO  << endl;   }   int32_t main() {     ios_base ::sync_with_stdio(false), cin.tie(NULL);     solve();     return 0;   }


#include <bits/stdc++.h>   const int INF_INT = 0x3f3f3f3f;   const long long INF_LL = 0x7f7f7f7f;   const int MOD = 1e9 + 7;   const double eps = 1e-10;   const double pi = acos(-1);   using namespace std;   vector<int> g[100010];   int n;   double ans;   void dfs(int fa, int u, int cnt) {     ans += 1.0 / cnt;     for (int i = 0; i < g[u].size(); i++) {       int v = g[u][i];       if (v == fa) continue;       dfs(u, v, cnt + 1);     }   }   int main(int argc, char const *argv[]) {     scanf( %d , &n);     for (int i = 1; i < n; i++) {       int u, v;       scanf( %d%d , &u, &v);       g[u].push_back(v);       g[v].push_back(u);     }     ans = 0.0;     dfs(0, 1, 1);     printf( %.12f n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = (int)1e9 + 7;   const int MAXN = 100100;   inline void add(int &a, int b) {     a += b;     if (a >= MOD) {       a -= MOD;     }   }   inline int mul(int a, int b) { return (a * 1LL * b) % MOD; }   inline int fastPow(int a, int b) {     int r = 1;     while (b) {       if (b & 1) {         r = mul(r, a);       }       a = mul(a, a);       b >>= 1;     }     return r;   }   inline int inverse(int a) { return fastPow(a, MOD - 2); }   int f[MAXN];   int invf[MAXN];   int ten[MAXN];   inline int c(int n, int k) {     if (k < 0) {       return 0;     }     if (n < k) {       return 0;     }     return mul(mul(f[n], invf[k]), invf[n - k]);   }   int main() {     clock_t start_time = clock();     f[0] = invf[0] = 1;     ten[0] = 1;     for (int i = 1; i < MAXN; i++) {       ten[i] = mul(ten[i - 1], 10);       f[i] = mul(f[i - 1], i);       invf[i] = inverse(f[i]);     }     int n, k;     while (scanf( %d%d , &n, &k) == 2) {       char ss[n + 1];       scanf( %s , ss);       vector<int> s(n, 0);       for (int i = 0; i < n; i++) {         s[i] = ss[i] -  0 ;         if (i > 0) {           add(s[i], s[i - 1]);         }       }       int ans = 0;       for (int d = 0; d <= n - 2; d++) {         int val = mul(ten[d], c(n - d - 2, k - 1));         val = mul(val, s[n - d - 2]);         add(ans, val);       }       for (int i = 0; i < n; i++) {         int val = mul(ten[n - i - 1], ss[i] -  0 );         val = mul(val, c(i, k));         add(ans, val);       }       printf( %d n , ans);     }     (void)42;     ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     long long n, R = 0, L = 0;     cin >> n;     long long l[n], r[n];     for (int x = 0; x < n; x++) {       cin >> l[x] >> r[x];       L += l[x];       R += r[x];     }     int val = abs(R - L);     int ans = 0;     for (int x = 0; x < n; x++) {       int tL = L - (l[x] - r[x]);       int tR = R - (r[x] - l[x]);       int i = abs(tL - tR);       if (i > val) {         ans = x + 1;         val = i;       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void fast() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);   }   long long int power(long long int x, long long int y, long long int p) {     long long int res = 1;     x %= p;     while (y > 0) {       if (y & 1) res = (res * x) % p;       y = y >> 1;       x = (x * x) % p;     }     return res;   }   long long int modInverse(long long int n, long long int p) {     return power(n, p - 2, p);   }   long long int nCrModPFermat(long long int n, long long int r, long long int p) {     if (r == 0) return 1;     long long int fac[n + 1];     fac[0] = 1;     for (long long int i = 1; i <= n; i++) fac[i] = fac[i - 1] * i % p;     return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) %            p;   }   void SieveOfEratosthenes(long long int n) {     bool prime[n + 1];     memset(prime, true, sizeof(prime));     for (long long int p = 2; p * p <= n; p++) {       if (prime[p] == true)         for (long long int i = p * p; i <= n; i += p) prime[i] = false;     }     for (long long int p = 2; p <= n; p++)       if (prime[p]) cout << p <<    ;   }   int main() {     fast();     int t = 1;     while (t--) {       int n, k;       cin >> n >> k;       int v[n];       vector<int> a;       map<int, int> m;       for (int i = 0; i < n; ++i) cin >> v[i];       a.push_back(v[0]);       for (int i = 1; i < n; ++i) {         if (v[i] != a[a.size() - 1]) a.push_back(v[i]);       }       n = a.size();       m[a[0]]++;       for (int i = 1; i < n; ++i) {         if (i < n - 1 && a[i - 1] == a[i + 1])           m[a[i]] += 2;         else           m[a[i]]++;       }       int maxi = 0, ans;       for (auto x : m) {         if (maxi < x.second) {           maxi = x.second;           ans = x.first;         }       }       cout << ans <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int B = 27397, MOD = 1e9 + 7;   const int B1 = 33941, MOD1 = 1e9 + 9;   int n, q;   struct Node {     int nxt[11];     long long sum[11];     Node() {       for (int i = 0; i < 10; ++i) nxt[i] = i;       memset(sum, 0, sizeof sum);     }   };   class Tournament {    private:     int offset, lo, hi, x, y;     int nxt_left[11], nxt_right[11];     long long new_sum[11];     vector<Node> tree;     void merge(int node) {       for (int i = 0; i < 10; ++i)         tree[node].sum[i] = tree[2 * node].sum[i] + tree[2 * node + 1].sum[i];     }     void propagate(int node) {       if (node < offset) {         for (int i = 0; i < 10; ++i) {           nxt_left[i] = tree[node].nxt[tree[2 * node].nxt[i]];           nxt_right[i] = tree[node].nxt[tree[2 * node + 1].nxt[i]];         }         for (int i = 0; i < 10; ++i) {           tree[2 * node].nxt[i] = nxt_left[i];           tree[2 * node + 1].nxt[i] = nxt_right[i];         }       }       memset(new_sum, 0, sizeof new_sum);       for (int i = 0; i < 10; ++i)         new_sum[tree[node].nxt[i]] += tree[node].sum[i];       for (int i = 0; i < 10; ++i) {         tree[node].sum[i] = new_sum[i];         tree[node].nxt[i] = i;       }     }     void update(int node, int from, int to) {       propagate(node);       if (to <= lo || hi <= from) return;       if (from >= lo && to <= hi) {         tree[node].nxt[x] = y;         propagate(node);         return;       }       update(2 * node, from, (from + to) / 2);       update(2 * node + 1, (from + to) / 2, to);       merge(node);     }     long long query(int node, int from, int to) {       propagate(node);       if (to <= lo || hi <= from) return 0;       if (from >= lo && to <= hi) {         long long ret = 0;         for (int i = 0; i < 10; ++i) ret += (long long)i * tree[node].sum[i];         return ret;       }       long long left = query(2 * node, from, (from + to) / 2);       long long right = query(2 * node + 1, (from + to) / 2, to);       return left + right;     }       public:     Tournament(int n) {       for (offset = 1; offset <= n; offset <<= 1)         ;       tree.resize(2 * offset);     }     void insert(int i, int val) {       i += offset;       int coef = 1;       while (val > 0) {         tree[i].sum[val % 10] += (long long)coef;         coef *= 10;         val /= 10;       }       for (i >>= 1; i > 0; i >>= 1) merge(i);     }     void update(int l, int r, int _x, int _y) {       lo = l;       hi = r;       x = _x;       y = _y;       update(1, 0, offset);     }     long long query(int l, int r) {       lo = l;       hi = r;       return query(1, 0, offset);     }   };   int main(void) {     scanf( %d%d , &n, &q);     Tournament T(n);     for (int i = 0; i < n; ++i) {       int x;       scanf( %d , &x);       T.insert(i, x);     }     for (int i = 0; i < q; ++i) {       int t;       scanf( %d , &t);       if (t == 1) {         int l, r, x, y;         scanf( %d%d%d%d , &l, &r, &x, &y);         --l;         if (x == y) continue;         T.update(l, r, x, y);         continue;       }       int l, r;       scanf( %d%d , &l, &r);       --l;       printf( %lld n , T.query(l, r));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<pair<long long, long long> > adj[100100];   long long under[100100];   long long n;   long long dfs(long long u, long long p) {     under[u] = 0;     long long next, edge;     for (long long i = 0; i < adj[u].size(); i++) {       next = adj[u][i].first;       edge = adj[u][i].second;       if (next != p) {         under[u] += edge + dfs(next, u);       }     }     return under[u];   }   long long f(long long u, long long p) {     long long sum = 0;     long long edge, next;     for (long long i = 0; i < adj[u].size(); i++) {       next = adj[u][i].first;       edge = adj[u][i].second;       if (next != p) sum += edge + under[next];     }     if (sum == 0) return 0;     long long best = 100000000ll * 100000000ll;     long long now;     for (long long i = 0; i < adj[u].size(); i++) {       next = adj[u][i].first;       edge = adj[u][i].second;       if (next != p) {         now = (sum - (edge + under[next])) * 2 + edge + f(next, u);         best = min(best, now);       }     }     return best;   }   int main() {     cin >> n;     long long x, y, edge;     for (long long i = 1; i < n; i++) {       cin >> x >> y >> edge;       adj[x].push_back(pair<long long, long long>(y, edge));       adj[y].push_back(pair<long long, long long>(x, edge));     }     dfs(1, -1);     cout << f(1, -1) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   pair<int, int> answer[404];   set<pair<int, int> > S;   set<pair<int, int> >::iterator it, ii;   bool check(pair<int, int> c) {     ii = S.lower_bound(make_pair(c.first, 0));     if (ii != S.end()) {       if (c.first + c.second > (*ii).first) return false;     }     if (ii != S.begin()) {       ii--;       if (c.first < (*ii).first + (*ii).second) return false;     }     return true;   }   int main() {     scanf( %d , &n);     S.insert(make_pair(0, 1));     for (int i = 0; i < n; ++i) {       int x, y;       scanf( %d %d , &x, &y);       pair<int, int> c = make_pair(x, y);       if (check(c)) {         answer[i] = c;         S.insert(c);         continue;       }       for (it = S.begin(); it != S.end(); it++) {         c = make_pair((*it).first + (*it).second, y);         if (check(c)) {           S.insert(c);           answer[i] = c;           break;         }       }     }     for (int i = 0; i < n; ++i)       printf( %d %d n , answer[i].first, answer[i].second + answer[i].first - 1);   }


#include <bits/stdc++.h>   using namespace std;   vector<vector<int>> g, rv;   int ds[3030][3030];   vector<int> md[3030];   int rd[3030][3030];   vector<int> mr[3030];   int main() {     int n, m;     scanf( %d %d  , &n, &m);     g.assign(n, vector<int>());     rv.assign(n, vector<int>());     while (m--) {       int a, b;       scanf( %d %d  , &a, &b);       a--;       b--;       if (a == b) continue;       g[a].push_back(b);       rv[b].push_back(a);     }     memset(ds, -1, sizeof(ds));     memset(rd, -1, sizeof(rd));     for (int i = 0; i < n; i++) {       ds[i][i] = rd[i][i] = 0;       queue<int> q;       priority_queue<pair<int, int>, vector<pair<int, int>>,                      greater<pair<int, int>>>           pq;       q.push(i);       while (!q.empty()) {         int u = q.front();         q.pop();         if (i != u) pq.push({ds[i][u], u});         while (pq.size() > 3) {           pq.pop();         }         for (int j = 0; j < g[u].size(); j++) {           int v = g[u][j];           if (ds[i][v] >= 0) {             continue;           }           ds[i][v] = ds[i][u] + 1;           q.push(v);         }       }       while (!pq.empty()) {         int u = pq.top().second;         pq.pop();         md[i].push_back(u);       }       q = queue<int>();       q.push(i);       while (!q.empty()) {         int u = q.front();         q.pop();         if (i != u) pq.push({rd[i][u], u});         while (pq.size() > 3) {           pq.pop();         }         for (int j = 0; j < rv[u].size(); j++) {           int v = rv[u][j];           if (rd[i][v] >= 0) continue;           rd[i][v] = rd[i][u] + 1;           q.push(v);         }       }       while (!pq.empty()) {         int u = pq.top().second;         pq.pop();         mr[i].push_back(u);       }     }     int ma = 0;     int mi[4];     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         if (i == j) continue;         if (ds[i][j] < 0) continue;         for (int k = 0; k < mr[i].size(); k++) {           for (int l = 0; l < md[j].size(); l++) {             int a = mr[i][k], b = md[j][l];             if (a == b || a == j) continue;             if (b == i) continue;             int dist = ds[a][i] + ds[i][j] + ds[j][b];             if (dist > ma) {               ma = dist;               mi[0] = a;               mi[1] = i;               mi[2] = j;               mi[3] = b;             }           }         }       }     }     printf( %d %d %d %d n , mi[0] + 1, mi[1] + 1, mi[2] + 1, mi[3] + 1);   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1000006;   const long long int M = 935172938408392767LL;   vector<long long int> kub[N];   long long int kra[N];   long long int maska[N];   int deg[N];   int main() {     int n, m, a, b;     long long int wynik = 0;     scanf( %d%d , &n, &m);     kra[1] = 1;     for (int i = 2; i <= n; i++) kra[i] = (kra[i - 1] * 2) % M;     for (int i = 0; i < m; i++) {       scanf( %d%d , &a, &b);       maska[a] += kra[b];       maska[b] += kra[a];       maska[a] %= M;       maska[b] %= M;       deg[a]++;       deg[b]++;     }     for (int i = 1; i <= n; i++) {       kub[deg[i]].push_back(maska[i]);       kub[deg[i]].push_back((maska[i] + kra[i]) % M);     }     for (int i = 0; i <= n; i++) {       sort(kub[i].begin(), kub[i].end());       a = 1;       for (int j = 1; j < kub[i].size(); j++) {         if (kub[i][j - 1] == kub[i][j])           a++;         else {           wynik += ((a - 1) * (long long)a) / 2;           a = 1;         }       }       wynik += ((a - 1) * (long long)a) / 2;     }     printf( %I64d n , wynik);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = (long long)4e18 + 7;   inline void minimize(long long &x, const long long &y) {     if (x > y) x = y;   }   struct help {     int x, s, r;     help() { x = s = r = 0; }     void input(void) {       x = s = r = 0;       int k;       scanf( %d%d%d , &x, &r, &k);       for (int zz = 0; zz < (k); zz = zz + 1) {         int v;         scanf( %d , &v);         v--;         s |= (1 << (v));       }     }     bool operator<(const help &a) const { return (r < a.r); }   };   long long f[(1 << (20)) + 7];   help a[111];   int n, m, b;   void init(void) {     scanf( %d%d%d , &n, &m, &b);     for (int i = (1); i <= (n); i = i + 1) a[i].input();     sort(a + 1, a + n + 1);   }   void process(void) {     for (int i = 0; i < ((1 << (m))); i = i + 1) f[i] = INF;     f[0] = 0;     long long res = INF;     for (int i = (1); i <= (n); i = i + 1) {       long long cost = 1LL * b * a[i].r;       for (int j = 0; j < ((1 << (m))); j = j + 1)         if (f[j] < INF) minimize(f[j | a[i].s], f[j] + a[i].x);       minimize(res, f[(1 << (m)) - 1] + cost);     }     if (res < INF)       cout << res;     else       cout << -1;   }   int main(void) {     init();     process();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e5 + 10;   int n;   bool init[MAXN], goal[MAXN];   vector<int> e[MAXN];   bool mark[MAXN];   bool even = true;   bool eo[2];   queue<int> ans;   void dfs(int v) {     if (mark[v]) return;     mark[v] = true;     bool change = false;     if ((init[v] != goal[v]) ^ eo[even]) {       ans.push(v + 1);       eo[even] = !eo[even];       change = true;     }     for (int i = 0; i < e[v].size(); i++) {       int u = e[v][i];       even = !even;       dfs(u);       even = !even;     }     if (change) eo[even] = !eo[even];   }   int main() {     cin >> n;     for (int i = 0; i < n - 1; i++) {       int u, v;       cin >> u >> v;       u--;       v--;       e[u].push_back(v);       e[v].push_back(u);     }     for (int i = 0; i < n; i++) cin >> init[i];     for (int i = 0; i < n; i++) cin >> goal[i];     dfs(0);     cout << ans.size() << endl;     while (ans.size() > 0) {       cout << ans.front() << endl;       ans.pop();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());   using ll = long long int;   using ld = long double;   using pi = pair<int, int>;   const double PI = acos(-1.0);   const double eps = 1e-9;   const ll mod = 1e9 + 7;   const int inf = 1e7;   const int MAXN = 1e5 + 5;   void cp() {     int n;     cin >> n;     vector<int> arr(n);     for (int &x : arr) cin >> x;     int mn = *min_element(arr.begin(), arr.end());     for (int &x : arr) x -= mn, x++;     int one = count(arr.begin(), arr.end(), 1);     if (one > n / 2)       cout <<  Bob n ;     else       cout <<  Alice n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     int t;     t = 1;     while (t--) {       cp();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int Find(string x) {     if (x ==  rock ) return 1;     if (x ==  scissors ) return 2;     if (x ==  paper ) return 3;   }   int main() {     string a, b, c;     int sa, sb, sc;     cin >> a >> b >> c;     sa = Find(a), sb = Find(b), sc = Find(c);     if (sa == 1 && sb == 2 && sc == 2)       printf( F );     else if (sa == 2 && sb == 3 && sc == 3)       printf( F );     else if (sa == 3 && sb == 1 && sc == 1)       printf( F );     else if (sa == 2 && sb == 1 && sc == 2)       printf( M );     else if (sa == 3 && sb == 2 && sc == 3)       printf( M );     else if (sa == 1 && sb == 3 && sc == 1)       printf( M );     else if (sa == 2 && sb == 2 && sc == 1)       printf( S );     else if (sa == 3 && sb == 3 && sc == 2)       printf( S );     else if (sa == 1 && sb == 1 && sc == 3)       printf( S );     else       printf( ? );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long head[100005];   long long memory[100005];   int n, m;   bool possible(long long t) {     int curr = 1;     for (int i = 1; i <= n; i++) {       long long headloc = head[i];       if (headloc <= memory[curr]) {         headloc += t;         while (headloc >= memory[curr] && curr <= m) curr++;       } else {         if (headloc - t > memory[curr]) return false;         long long d = headloc - memory[curr];         long long next = max(headloc + (t - d) / 2, headloc + (t - 2 * d));         headloc = next;         while (headloc >= memory[curr] && curr <= m) curr++;       }       if (curr == m + 1) return true;     }     return false;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> n >> m;     for (int i = 1; i <= n; i++) cin >> head[i];     for (int i = 1; i <= m; i++) cin >> memory[i];     long long start = 0;     long long endi = 20000000000;     while (start < endi) {       long long mid = (start + endi) / 2;       if (possible(mid))         endi = mid;       else         start = mid + 1;     }     cout << endi;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1010;   const int base = 31337;   const int mod = 1e9 + 7;   const int inf = 0x3f3f3f3f;   const int logo = 20;   const int off = 1 << logo;   const int treesiz = off << 1;   int n, m, k;   vector<int> graph[maxn];   int a[maxn], ss[maxn], cs[maxn];   bool bio[maxn];   int cnt = 0;   int dfs(int x) {     bio[x] = true;     cnt += graph[x].size();     int out = 1;     for (int i = 0; i < graph[x].size(); i++) {       int tren = graph[x][i];       if (!bio[tren]) out += dfs(tren);     }     return out;   }   int main() {     scanf( %d%d%d , &n, &m, &k);     for (int i = 0; i < k; i++) scanf( %d , a + i);     for (int i = 0; i < m; i++) {       int a, b;       scanf( %d%d , &a, &b);       graph[a].push_back(b);       graph[b].push_back(a);     }     memset(bio, false, sizeof bio);     int maxi = 0;     for (int i = 0; i < k; i++) {       ss[i] = dfs(a[i]);       maxi = max(maxi, ss[i]);       cs[i] = cnt / 2, cnt = 0;     }     int ax = 0;     for (int i = 1; i <= n; i++) {       if (!bio[i]) ax += dfs(i);     }     long long tren = 0;     long long sol = 0;     for (int i = 0; i < k; i++) {       tren += ss[i] * (ss[i] - 1) / 2 - cs[i];     }     cnt /= 2;     for (int i = 0; i < k; i++) {       int pt = a[i];       int ts = ss[i] + ax;       sol = max(sol, tren - (ss[i] * (ss[i] - 1) / 2 - cs[i]) +                          (ts * (ts - 1) / 2 - cnt - cs[i]));     }     printf( %lld n , sol);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 300005;   struct Point {     int x, y;     Point(int _x = 0, int _y = 0) {       x = _x;       y = _y;     }     Point operator-(const Point &R) const { return Point(x - R.x, y - R.y); }     long long operator^(const Point &R) const {       return (long long)x * R.y - (long long)y * R.x;     }     long long operator%(const Point &R) const {       return (long long)x * R.x + (long long)y * R.y;     }     bool operator<(const Point &R) const {       if (x != R.x) return x < R.x;       return y < R.y;     }   };   int n, m, p;   Point W[N], K[N];   map<Point, int> Hash;   long long res[N], ans[N];   int a[N];   bool cmpP(const int &A, const int &B) { return W[A] < W[B]; }   bool cmpQ(const int &A, const int &B) {     return (long long)K[A].x * K[B].y < (long long)K[B].x * K[A].y;   }   void update(vector<int> &P, vector<int> &Q) {     if (P.empty() || Q.empty()) return;     sort(P.begin(), P.end(), cmpP);     vector<int> A, B;     for (int i = 0; i < Q.size(); ++i)       if (K[Q[i]].y >= 0) {         A.push_back(Q[i]);       }     sort(A.begin(), A.end(), cmpQ);     vector<Point> s(P.size() + 1);     int t = 0;     for (int i = 0; i < P.size(); ++i) {       Point D = W[P[i]];       while (t > 1 && ((D - s[t - 2]) ^ (s[t - 1] - s[t - 2])) <= 0) --t;       s[t++] = D;     }     for (int i = 0, j = 0; i < A.size(); ++i) {       while (j + 1 < t && (K[A[i]] % s[j + 1]) >= (K[A[i]] % s[j])) ++j;       res[A[i]] = max(res[A[i]], K[A[i]] % s[j]);     }     t = 0;     for (int i = 0; i < P.size(); ++i) {       Point D = W[P[i]];       while (t > 1 && ((D - s[t - 2]) ^ (s[t - 1] - s[t - 2])) >= 0) --t;       s[t++] = D;     }   }   int del[N];   void divide(const vector<int> &A) {     if (A.size() <= 1) return;     vector<int> P, Q;     int r = A.size(), mid = r / 2;     for (int i = 0; i < mid; ++i) P.push_back(A[i]);     divide(P);     P.clear();     for (int i = 0; i < r; ++i)       if (A[i] > 0 && (A[i] & 1)) del[A[i] >> 1] = 1;     for (int i = 0; i < mid; ++i)       if (A[i] > 0 && (~A[i] & 1)) {         if (!del[A[i] >> 1])           P.push_back(A[i] >> 1);         else           del[A[i] >> 1] = 2;       }     for (int i = mid; i < r; ++i)       if (A[i] < 0) Q.push_back(-A[i]);     update(P, Q);     Q.clear();     int c1 = 0, c2 = 0;     for (int i = r - 1; i >= mid; --i) {       if (A[i] > 0 && (A[i] & 1) && del[A[i] >> 1] == 2) {         Q.push_back(A[i] ^ 1);         ++c1;       } else if (A[i] < 0) {         Q.push_back(A[i]);         ++c2;       }     }     for (int i = 0; i < r; ++i)       if (A[i] > 0 && (A[i] & 1)) del[A[i] >> 1] = 0;     if (c1 && c2) divide(Q);     P.clear();     for (int i = mid; i < r; ++i) P.push_back(A[i]);     divide(P);   }   int iid[N];   void work() {     scanf( %d , &n);     vector<int> A;     for (int i = 0; i < n; ++i) {       Point S;       scanf( %d , &a[i]);       if (a[i] == 3) {         scanf( %d , &S.x);         S.y = 1;         ++m;         res[m] = -1LL << 60;         K[m] = S;         a[i] = -m;       } else {         if (a[i] == 1) {           scanf( %d%d , &S.x, &S.y);           W[++p] = S;           iid[i] = p;           a[i] = p << 1;         } else {           int j;           scanf( %d , &j);           a[i] = iid[j - 1] << 1 | 1;         }       }       A.push_back(a[i]);     }     divide(A);     for (int i = 1; i <= m; ++i) {       if (res[i] == -1LL << 60) {         puts( EMPTY SET );       } else {         printf( %lld n , res[i]);       }     }   }   int main() {     work();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9 + 7;   const int MAXN = 1e6 + 7;   const double EPS = 1e-6;   const int M = 15;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     srand(time(0));     vector<vector<int> > dp(M + 1);     vector<vector<pair<int, int> > > nxt(M + 1);     for (int m = 0; m <= M; m++) {       int N = (1 << m);       dp[m].resize(N, INF);       nxt[m].resize(N);       queue<int> q;       if (m < M) {         q.push(0);         dp[m][0] = 0;       } else {         for (int i = 0; i < 8; i++) {           q.push(i << 12);           dp[M][i << 12] = 0;         }       }       while (!q.empty()) {         int mask = q.front();         q.pop();         for (int a = 0; a < m; a++) {           for (int k = 1; k < m; k++) {             int b = a + k, c = a + 2 * k;             if (c >= m) break;             int mask1 = mask;             mask1 ^= (1 << a);             mask1 ^= (1 << b);             mask1 ^= (1 << c);             if (dp[m][mask1] != INF) continue;             dp[m][mask1] = dp[m][mask] + 1;             nxt[m][mask1] = {a, k};             q.push(mask1);           }         }       }     }     int n;     cin >> n;     vector<int> all(n);     for (int i = 0; i < n; i++) {       cin >> all[i];     }     if (n < 15) {       int mask = 0;       for (int i = n - 1; i >= 0; i--) {         mask = mask * 2 + all[i];       }       if (dp[n][mask] == INF) {         cout <<  NO n ;         return 0;       }       cout <<  YES n ;       cout << dp[n][mask] <<   n ;       while (mask) {         int a = nxt[n][mask].first, k = nxt[n][mask].second;         mask ^= (1 << a);         mask ^= (1 << (a + k));         mask ^= (1 << (a + 2 * k));         cout << a + 1 <<     << a + 1 + k <<     << a + 1 + 2 * k <<   n ;       }       return 0;     }     cout <<  YES n ;     vector<pair<int, int> > res;     for (int i = 0, sz = M, fl = false; !fl; i += 12) {       if (i >= n - 14) {         sz = 14;         i = n - 14;         fl = true;       }       int mask = 0;       for (int j = sz - 1; j >= 0; j--) {         mask = mask * 2 + all[i + j];       }       assert(dp[sz][mask] != INF);       while (dp[sz][mask]) {         int a = nxt[sz][mask].first, k = nxt[sz][mask].second;         int b = a + k, c = a + 2 * k;         all[i + a] ^= 1;         all[i + b] ^= 1;         all[i + c] ^= 1;         mask ^= (1 << a);         mask ^= (1 << b);         mask ^= (1 << c);         res.push_back({i + a, k});       }     }     for (int i = 0; i < n; i++) {       assert(!all[i]);     }     cout << res.size() <<   n ;     for (auto p : res) {       int a = p.first, k = p.second;       cout << a + 1 <<     << a + k + 1 <<     << a + 2 * k + 1 <<   n ;     }   }