#include <bits/stdc++.h>   using namespace std;   long long a1, a2, a3, sum = 0, a12, a23, a31;   int main() {     cin >> a1 >> a2 >> a3;     sum = a1 + a2 + a3;     if (sum % 2) {       cout <<  Impossible ;       return 0;     }     sum /= 2;     a12 = sum - a3;     a23 = sum - a1;     a31 = sum - a2;     if (a12 < 0 || a23 < 0 || a31 < 0) {       cout <<  Impossible ;       return 0;     } else       cout << a12 <<     << a23 <<     << a31;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 400005;   char a[N];   int n, k, delta, top, st[N];   bool vis[N];   int main() {     scanf( %d%d , &n, &k), scanf( %s , a + 1);     delta = (n - k) / 2, top = 0;     for (int i = 1; i <= n; ++i) {       if (a[i] ==  ( )         st[++top] = i;       else {         if (delta) {           --delta, vis[i] = 1;           vis[st[top]] = 1;         }         --top;       }     }     for (int i = 1; i <= n; ++i)       if (!vis[i]) printf( %c , a[i]);     puts(  );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int dist[600 + 15][600 + 15];   int start[200 + 15];   int MAX_ = INT_MAX / 2 - 5;   vector<pair<int, int> > sas[1000];   int cap[250000 + 15];   int v, e, n, k;   int pop_w[1000];   int pop_kr[1000];   int group[1000];   int last_checked[1000];   int dead[1000];   int res;   int num = 0;   bool b = 0;   int to_add;   bool DFS(int w, int bneck) {     if (w == n + v + 2) {       to_add = bneck;       res += to_add;       return 1;     }     for (int i = last_checked[w] + 1; i < sas[w].size(); i++) {       int do_ = sas[w][i].first;       int neck = min(bneck, cap[sas[w][i].second]);       last_checked[w] = i;       if (neck && !dead[do_])         if (DFS(do_, neck)) {           cap[sas[w][i].second] -= to_add;           cap[sas[w][i].second ^ 1] += to_add;           return 1;         }     }     return 0;   }   int DINIC() {     for (int i = 0; i <= n + v + 3; i++) {       group[i] = -1;       dead[i] = 0;       last_checked[i] = -1;     }     queue<pair<int, int> > q;     q.push({0, 0});     group[0] = 0;     while (!q.empty()) {       int top_w = q.front().first;       int top_g = q.front().second;       q.pop();       for (int i = 0; i < sas[top_w].size(); i++)         if (group[sas[top_w][i].first] == -1) {           group[sas[top_w][i].first] = top_g + 1;           q.push({sas[top_w][i].first, top_g + 1});         }     }     int ile = 0;     while (DFS(0, INT_MAX)) ile++;     return ile;   }   bool CHECK(int t) {     for (int i = 0; i <= n + v + 3; i++) sas[i].clear();     int place;     num = 0;     for (int i = 1; i <= n; i++) {       place = start[i];       for (int j = 1; j <= v; j++) {         if (dist[place][j] <= t) {           sas[i].push_back({j + n, num});           sas[j + n].push_back({i, num + 1});           cap[num] = 1;           cap[num + 1] = 0;           num += 2;         }       }     }     for (int i = 1; i <= n; i++) {       sas[0].push_back({i, num});       sas[i].push_back({0, num + 1});       cap[num] = 1;       cap[num + 1] = 0;       num += 2;     }     for (int i = n + 1; i <= n + v; i++) {       sas[i].push_back({n + v + 2, num});       sas[n + v + 2].push_back({i, num + 1});       cap[num] = 1;       cap[num + 1] = 0;       num += 2;     }     res = 0;     while (DINIC()) {     };     if (res >= k) return 1;     return 0;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> v >> e >> n >> k;     for (int i = 1; i <= n; i++) cin >> start[i];     for (int i = 1; i <= v; i++)       for (int j = 1; j <= v; j++) dist[i][j] = MAX_;     for (int i = 1; i <= v; i++) dist[i][i] = 0;     int h, j, r;     for (int i = 1; i <= e; i++) {       cin >> h >> j >> r;       dist[h][j] = min(dist[h][j], r);       dist[j][h] = min(dist[j][h], r);     }     for (int mid = 1; mid <= v; mid++)       for (int x = 1; x <= v; x++)         for (int y = 1; y <= v; y++)           dist[x][y] = min(dist[x][y], dist[x][mid] + dist[mid][y]);     if (!CHECK(1731311)) {       cout << -1;       return 0;     }     int b = 0;     int e = 1731311;     while (b <= e) {       int mid = (b + e) / 2;       if (CHECK(mid))         e = mid - 1;       else         b = mid + 1;     }     cout << b;   }


#include <bits/stdc++.h>   using namespace std;   const int oo = 0x3f3f3f3f;   const double eps = 1e-9;   const int maxn = 100000 + 10;   int go[maxn][26], fail[maxn];   int I[maxn], F[maxn], S[maxn], FIN[maxn];   int total;   void push(string &s, int index, int freq) {     int u = 0;     for (auto c : s) {       int x = c -  a ;       if (!go[u][x]) go[u][x] = total++;       u = go[u][x];     }     I[u] = index, F[u] = freq, S[u] = s.length(), FIN[u] = u;   }   void build() {     queue<pair<int, int> > q;     for (int i = 0; i < 26; ++i) {       if (go[0][i]) q.push({go[0][i], 0});     }     while (!q.empty()) {       auto x = q.front();       q.pop();       int u = x.first, f = x.second;       fail[u] = f;       if (!FIN[u]) FIN[u] = FIN[f];       for (int i = 0; i < 26; ++i) {         if (go[u][i])           q.push({go[u][i], go[f][i]});         else           go[u][i] = go[f][i];       }     }   }   int ANSWER[maxn];   queue<int> deq[maxn];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     total = 1;     string s;     cin >> s;     int q;     cin >> q;     for (int i = 1; i <= q; ++i) {       int f;       string t;       cin >> f >> t;       push(t, i, f);     }     build();     memset(ANSWER, 0x3f, sizeof ANSWER);     for (int i = 0, u = 0; i < (int)s.length(); ++i) {       u = go[u][s[i] -  a ];       int v = FIN[u];       while (v) {         int idx = I[v];         deq[idx].push(i);         if (deq[idx].size() > F[v]) deq[idx].pop();         if (deq[idx].size() == F[v]) {           int beg = deq[idx].front();           ANSWER[idx] = min(ANSWER[idx], i - beg + S[v]);         }         v = FIN[fail[v]];       }     }     for (int i = 1; i <= q; ++i) {       if (ANSWER[i] == oo)         cout << -1 <<   n ;       else         cout << ANSWER[i] <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 1e18;   const long long mod = 1e9;   long long dp[100005];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long t = 1;     cin >> t;     while (t--) {       long long n, k;       cin >> n >> k;       long long i;       long long a[n];       set<long long> s;       long long c = 0;       for (i = 0; i < n; i++) {         cin >> a[i];         s.insert(a[i]);         if (i > 0) {           if (a[i] != a[i - 1]) {             c++;           }         }       }       long long d = s.size();       if (d <= k) {         cout << 1 << endl;       } else {         if (k == 1 && (d != k)) {           cout <<  -1  << endl;         } else {           cout << (((c % (k - 1)) == 0) ? (c / (k - 1)) : (c / (k - 1) + 1))                << endl;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 3e5 + 10, M = 2097152 + 10;   long long n, x, ans, ar[N], mark[M][2];   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n;     for (long long i = 0; i < n; i++) cin >> ar[i];     mark[0][1]++;     for (long long i = 0; i < n; i++) {       x ^= ar[i];       mark[x][i & 1]++;     }     for (long long i = 0; i < M; i++) {       ans += (mark[i][0] * (mark[i][0] - 1)) / 2;       ans += (mark[i][1] * (mark[i][1] - 1)) / 2;     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const ll MOD = 1e9 + 7, N = 1e5 + 10;   const ll MX = 1e8;   int32_t main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     string s;     cin >> s;     ll ans = 0;     for (ll i = 0; i < MX; i += 25) {       string k = to_string(i);       if (k.length() != s.length()) continue;       set<ll> se;       ll bad = 1;       42;       for (ll j = 0; j < k.length(); j++) {         if (s[j] ==  _ ) continue;         if (s[j] ==  X ) {           se.insert(k[j] -  0 );           if (se.size() > 1) break;           continue;         }         if (s[j] != k[j]) bad = 0;       }       ans += (se.size() <= 1 and bad);     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct LCA {     int logn;     vector<int> depth;     vector<vector<int> > lca;     vector<vector<int> > *edges;     LCA(int n, vector<vector<int> > *edges) {       logn = log(n) / log(2) + 1;       depth.resize(n + 1, 0);       lca.resize(n + 1, vector<int>(logn, 0));       this->edges = edges;       build();     }     void dfs(int u, int p) {       lca[u][0] = p;       for (int i = 1; i < logn; i++) {         lca[u][i] = lca[lca[u][i - 1]][i - 1];       }       depth[u] = depth[p] + 1;       for (auto &v : (*edges)[u]) {         if (p != v) {           dfs(v, u);         }       }     }     int parent(int v, int h) {       for (int i = logn - 1; i >= 0; i--) {         if (h & (1 << i)) {           v = lca[v][i];         }       }       return v;     }     int lessParent(int u, int p) { return parent(u, depth[u] - depth[p] - 1); }     int get(int u, int v) {       if (depth[u] > depth[v]) {         swap(u, v);       }       int h = depth[v] - depth[u];       v = parent(v, h);       if (u == v) {         return u;       }       for (int i = logn - 1; i >= 0; i--) {         if (lca[u][i] != lca[v][i]) {           u = lca[u][i];           v = lca[v][i];         }       }       return lca[u][0];     }     void build() { dfs(1, 0); }   } * lca;   struct GraphBuilder {     enum DIRECT {       UP = 0,       DOWN,     };     int n;     int k;     vector<vector<int> > *e;     vector<pair<int, int> > edges;     set<pair<int, int> > cache;     vector<vector<int> > addedVertices;     vector<vector<int> > deletedVertices;     LCA *lca;     struct Node {       int id;       Node *leftChild;       Node *rightChild;       Node(int v, Node *l, Node *r) {         id = v;         leftChild = l;         rightChild = r;       }     };     vector<pair<Node *, Node *> > root;     GraphBuilder(int m, vector<vector<int> > *e) {       k = 2 * m - 1;       n = 2 * m - 1;       this->e = e;       lca = new LCA(e->size() - 1, e);       addedVertices.resize(e->size());       deletedVertices.resize(e->size());       for (int i = 0; i < m; i++) {         for (int j = 0; j < 2; j++) {           int u, v;           scanf( %d %d , &u, &v);           int p = lca->get(u, v);           if (u != p) {             addedVertices[u].push_back((i << 1) | j);             deletedVertices[lca->lessParent(u, p)].push_back((i << 1) | j);           }           if (v != p) {             addedVertices[v].push_back((i << 1) | j);             deletedVertices[lca->lessParent(v, p)].push_back((i << 1) | j);           }         }       }       root.resize(e->size(), {0, 0});       dfs(1, 0);     }     void dfs(int u, int p) {       for (auto &v : (*e)[u]) {         if (v != p) {           dfs(v, u);           root[u].first = merge(root[u].first, root[v].first, DOWN);           root[u].second = merge(root[u].second, root[v].second, UP);         }       }       for (auto &x : addedVertices[u]) {         root[u].first = addVertex(0, n, root[u].first, (x ^ 1), DOWN);         root[u].second = addVertex(0, n, root[u].second, x, UP);       }       for (auto &x : deletedVertices[u]) {         root[u].first = delVertex(0, n, root[u].first, (x ^ 1), DOWN);         root[u].second = delVertex(0, n, root[u].second, x, UP);         if (root[u].first) {           add(x, root[u].first->id);         }         if (root[u].second) {           add(root[u].second->id, (x ^ 1));         }       }     }     void add(int u, int v) { edges.push_back({u, v}); }     void addEdge(Node *p, int direct) {       if (direct == DOWN) {         if (p->leftChild) {           add(p->id, p->leftChild->id);         }         if (p->rightChild) {           add(p->id, p->rightChild->id);         }       } else {         if (p->leftChild) {           add(p->leftChild->id, p->id);         }         if (p->rightChild) {           add(p->rightChild->id, p->id);         }       }     }     Node *addVertex(int l, int r, Node *p, int v, int direct) {       if (!p) {         p = new Node(0, 0, 0);       }       if (l == r) {         return new Node(v, 0, 0);       } else {         int mid = (l + r) >> 1;         Node *newNode = new Node(++k, p->leftChild, p->rightChild);         if (v <= mid) {           newNode->leftChild = addVertex(l, mid, p->leftChild, v, direct);         } else {           newNode->rightChild = addVertex(mid + 1, r, p->rightChild, v, direct);         }         addEdge(newNode, direct);         return newNode;       }     }     Node *delVertex(int l, int r, Node *p, int v, int direct) {       if (l == r) {         return 0;       } else {         int mid = (l + r) >> 1;         Node *newNode = new Node(++k, p->leftChild, p->rightChild);         if (v <= mid) {           newNode->leftChild = delVertex(l, mid, p->leftChild, v, direct);         } else {           newNode->rightChild = delVertex(mid + 1, r, p->rightChild, v, direct);         }         if (!newNode->leftChild && !newNode->rightChild) {           return 0;         }         addEdge(newNode, direct);         return newNode;       }     }     Node *merge(Node *p1, Node *p2, int direct) {       if (!p1 || !p2) {         return p1 ? p1 : p2;       } else {         Node *left = merge(p1->leftChild, p2->leftChild, direct);         Node *right = merge(p1->rightChild, p2->rightChild, direct);         Node *newNode = new Node(++k, left, right);         addEdge(newNode, direct);         return newNode;       }     }   };   struct SAT {     int n;     vector<int> st;     vector<int> mark;     vector<int> group;     vector<vector<int> > edges;     vector<vector<int> > revEdges;     SAT(int n, vector<pair<int, int> > &e) {       this->n = n + 1;       mark.resize(n + 1, 0);       group.resize(n + 1, 0);       edges.resize(n + 1);       revEdges.resize(n + 1);       for (auto &p : e) {         addEdge(p.first, p.second);       }     }     void addEdge(int u, int v) {       edges[u].push_back(v);       revEdges[v].push_back(u);     }     void dfs1(int u) {       mark[u] = 1;       for (auto &v : edges[u]) {         if (mark[v] == 0) {           dfs1(v);         }       }       st.push_back(u);     }     void dfs2(int u, int k) {       group[u] = k;       for (auto &v : revEdges[u]) {         if (group[v] == 0) {           dfs2(v, k);         }       }     }     void solve() {       for (int i = 0; i < n; i++) {         if (mark[i] == 0) {           dfs1(i);         }       }       int k = 0;       for (int i = st.size() - 1; i >= 0; i--) {         int u = st[i];         if (group[u] == 0) {           k++;           dfs2(u, k);         }       }     }     void answer(int m) {       for (int i = 0; i < 2 * m; i += 2) {         if (group[i] == group[i | 1]) {           printf( NO );           return;         }       }       printf( YES n );       for (int i = 0; i < 2 * m; i += 2) {         printf( %d n , (group[i] > group[i | 1]) ? 1 : 2);       }     }   };   int main() {     int n;     scanf( %d , &n);     vector<vector<int> > edges(n + 1);     for (int i = 1; i < n; i++) {       int u, v;       scanf( %d %d , &u, &v);       edges[u].push_back(v);       edges[v].push_back(u);     }     int m;     scanf( %d , &m);     GraphBuilder builder(m, &edges);     SAT solver(builder.k, builder.edges);     solver.solve();     solver.answer(m);   }


#include <bits/stdc++.h>   using namespace std;   const int mxn = 257;   string rec[mxn][3];   bool been[mxn][3];   inline int G(string s) {     int t = 0;     for (int i = 0; i < s.size(); ++i) t = t * 2 + s[i] -  0 ;     return t;   }   priority_queue<pair<int, int> > pq;   bool changed;   string Min(string a, string b) {     if (a.size() != b.size()) {       if (a.size() < b.size())         return a;       else         return b;     }     return min(a, b);   }   inline void upd(string& a, string b) {     if (a == b) return;     if (Min(a, b) == b) {       changed = 1;       a = b;     }   }   inline void prep() {     int n = 256;     for (int i = 0; i < n; ++i)       for (int j = 0; j < 3; ++j)         rec[i][j] =  zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz ;     rec[G( 00001111 )][0] =  x ;     rec[G( 00110011 )][0] =  y ;     rec[G( 01010101 )][0] =  z ;     for (changed = 1; changed;) {       changed = 0;       for (int i = 0; i < n; ++i)         for (int j = 0; j < 2; ++j) upd(rec[i][j + 1], rec[i][j]);       for (int i = 0; i < n; ++i) upd(rec[i ^ 255][0],  !  + rec[i][0]);       for (int i = 0; i < n; ++i)         for (int j = 0; j < n; ++j)           upd(rec[i & j][1], rec[i][1] +  &  + rec[j][0]),               upd(rec[i | j][2], rec[i][2] +  |  + rec[j][1]);       for (int i = 0; i < n; ++i) upd(rec[i][0],  (  + rec[i][2] +  ) );     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0), cout.tie(0);     int T = 1;     cin >> T;     prep();     for (; T--;) {       string s;       cin >> s;       int t = G(s);       cout << Min(Min(rec[t][0], rec[t][1]), rec[t][2]) <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 4e6 + 5;   const int inf = 0x3f3f3f3f;   int main() {     int n;     scanf( %d , &n);     char a;     getchar();     int ans = 0;     for (int i = 1; i <= n; i++) {       scanf( %c , &a);       if (a ==  - )         ans--;       else         ans++;       ans = max(0, ans);     }     printf( %d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, s = 0;     cin >> n;     int a[n];     for (int x = 0; x < n; ++x) {       cin >> a[x];       s += a[x] * (x + 1);     }     cout << s << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char s[200005];   int n, k;   int main() {     scanf( %d%d , &n, &k);     scanf( %s , s);     if (n == 1) {       if (k == 0)         printf( %c n , s[0]);       else         printf( 0 n );     } else {       if (k == 0)         printf( %s n , s);       else {         if (s[0] !=  1 ) k--;         s[0] =  1 ;         int t = 1;         while (t < n && k) {           if (s[t] !=  0 ) {             s[t] =  0 ;             k--;           }           t++;         }         printf( %s , s);       }     }     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:1024000000,1024000000 )   using namespace std;   const long long LINF = (1LL << 62);   const int INF = 1 << 30;   const int NS = 100010;   const int MS = 19;   const int MOD = 1000000007;   const double PI = acos(-1.0);   int n, m, q, h[NS];   pair<int, int> s[NS];   int L[NS], R[NS];   int solve() {}   int main() {     while (~scanf( %d %d , &n, &q)) {       m = n - 1;       for (int i = 1; i <= n; i++) {         scanf( %d , &h[i]);         if (i > 1) {           h[i - 1] = abs(h[i - 1] - h[i]);           s[i - 1] = make_pair(h[i - 1], i - 1);         }       }       sort(s + 1, s + m + 1);       set<int> idSet;       idSet.insert(0);       idSet.insert(n);       for (int i = m; i >= 1; i--) {         int pos = s[i].second;         idSet.insert(pos);         __typeof(idSet.begin()) it = idSet.find(pos);         L[pos] = *(--it);         it++, it++;         R[pos] = *(it);       }       int x, y;       for (int qi = 0; qi < q; qi++) {         scanf( %d %d , &x, &y);         long long ans = 0;         for (int i = x; i < y; i++) {           int lb = i - max(L[i], x - 1);           int rb = min(R[i], y) - i;           ans += 1LL * h[i] * lb * rb;         }         printf( %I64d n , ans);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int gcd(int a, int b) {     if (a == 0) {       return b;     } else {       return gcd(b % a, a);     }   }   int main() {     int l_a, r_a, t_a;     int l_b, r_b, t_b;     int l_x, r_x, t_x;     cin >> l_a >> r_a >> t_a;     cin >> l_b >> r_b >> t_b;     if (r_b - l_b < r_a - l_a) {       l_x = l_b, r_x = r_b, t_x = t_b;       l_b = l_a, r_b = r_a, t_b = t_a;       l_a = l_x, r_a = r_x, t_a = t_x;     }     int g = gcd(t_a, t_b);     int c = l_b - l_a;     int c_1, c_2;     if (l_b - l_a >= 0) {       c_1 = c % g;       c_2 = (-(c % g - g)) % g;     } else {       c_1 = g - (-c) % g;       c_2 = (-(c_1 - g)) % g;     }     int answer = r_a - l_a + 1 - c_1;     answer = max(answer, min(r_b - l_b + 1 - c_2, r_a - l_a + 1));     cout << max(answer, 0);   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 10000;   const long long M = 60;   vector<long long> v;   long long n, first, t, a[N], second, cn, p;   void val(long long first) {     long long second, z;     second = first;     first = upper_bound((v).begin(), (v).end(), first) - v.begin() - 1;     ;     second = (second - v[first] + a[first]) % v[first];     z = second + v[first];     while (1) {       second = z - v[first];       p = (second - a[first] >= 0) ? (v[first] + (second - a[first]))                                    : (v[first] * 2 - (a[first] - second));       cout << p <<    ;       if (p == 1) break;       first--;       z >>= 1;     }   }   int main() {     cin >> n;     for (long long i = (long long)0; i <= (long long)M; i++)       v.push_back((1LL << i));     for (long long i = (long long)1; i <= (long long)n; i++) {       cin >> t;       if (t <= 2) {         cin >> first >> second;         first = upper_bound((v).begin(), (v).end(), first) - v.begin() - 1;         ;         for (long long j = (long long)first; j <= (long long)M; j++) {           a[j] += (second % v[j]) * (1LL << (j - first));           if (a[j] < 0) a[j] %= v[j], a[j] += v[j];           a[j] %= v[j];           if (t == 1) break;         }       } else {         cn++;         cin >> first;         val(first);         cout <<                 <<   n ;       }     }   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   #pragma GCC optimize( Ofast,no-stack-protector )   using namespace std;   void err(istream_iterator<string> it) {}   template <typename T, typename... Args>   void err(istream_iterator<string> it, T a, Args... args) {     cerr << *it <<   =   << a <<   n ;     err(++it, args...);   }   function<void(void)> ____ = []() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);   };   template <typename T>   vector<T> &operator<<(vector<T> &__container, T x) {     __container.push_back(x);     return __container;   }   template <typename T>   ostream &operator<<(ostream &out, vector<T> &__container) {     for (T _ : __container) out << _ <<    ;     return out;   }   void sci() {}   template <typename... Args>   void sci(int &x, Args &...args) {     scanf( %d , &x);     sci(args...);   }   void scl() {}   template <typename... Args>   void scl(long long int &x, Args &...args) {     scanf( %lld , &x);     scl(args...);   }   const int MAXN = 2e5 + 7;   double ret;   int rt;   int n, w[MAXN], root, sz[MAXN], maxsz[MAXN];   double derivative[MAXN];   bool vis[MAXN];   vector<pair<int, int> > G[MAXN];   void findroot(int u, int par, int tot) {     sz[u] = 1;     maxsz[u] = 0;     for (auto &e : G[u]) {       int v = e.first, c = e.second;       if (vis[v] or v == par) continue;       findroot(v, u, tot);       sz[u] += sz[v];       ((maxsz[u]) = (maxsz[u]) > (sz[v]) ? (maxsz[u]) : (sz[v]));     }     ((maxsz[u]) = (maxsz[u]) > (tot - sz[u]) ? (maxsz[u]) : (tot - sz[u]));     if (maxsz[u] < maxsz[root]) root = u;   }   double cost;   void dfs(int u, int par, int wt) {     cost += pow(wt, 1.5) * w[u];     derivative[u] = w[u] * 1.5 * pow(wt, 0.5);     for (auto &e : G[u]) {       int v = e.first, c = e.second;       if (v == par) continue;       dfs(v, u, wt + c);       derivative[u] += derivative[v];     }   }   void divide(int u) {     if (vis[u]) return;     vis[u] = true;     cost = 0;     double sd = 0;     for (auto &e : G[u]) {       int v = e.first, c = e.second;       dfs(v, u, c);       sd += derivative[v];     }     if (cost < ret) ret = cost, rt = u;     for (auto &e : G[u]) {       int v = e.first;       if (sd - 2 * derivative[v] >= 0) continue;       root = 0;       findroot(v, u, sz[v]);       divide(root);       return;     }   }   void solve() {     sci(n);     for (int i = 1; i <= n; i++) sci(w[i]);     for (int i = 1; i < n; i++) {       int u, v, c;       sci(u, v, c);       G[u] << pair<int, int>(v, c);       G[v] << pair<int, int>(u, c);     }     ret = LLONG_MAX;     maxsz[root = 0] = 0x3f3f3f3f;     findroot(1, 0, n);     divide(root);     cout << rt <<     << fixed << setprecision(10) << ret <<   n ;   }   int main() {     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 998244353, maxn = 5e5 + 79;   void upd(int& a, const int& b) { a = (a + b) % mod; }   int mul(const int& a, const int& b) { return (a * 1ll * b) % (long long)mod; }   vector<vector<int> > dp(maxn, vector<int>(2, 0));   vector<vector<int> > g(maxn);   vector<int> pw2(maxn, 1);   int sum = 0, n;   int dfs(int u, int p = -1) {     dp[u][0] = 1;     int e = 0;     for (int v : g[u]) {       if (v == p) continue;       e += 1 + dfs(v, u);       vector<int> dp2(2, 0);       upd(dp2[1], mul(dp[u][0], dp[v][0]));       upd(sum, mul(2, mul(mul(dp[u][0], dp[v][0]), pw2[n - 1 - e])));       upd(dp2[0], mul(dp[u][0], dp[v][1]));       upd(dp2[1], mul(dp[u][1], dp[v][0]));       upd(dp2[1], mul(dp[u][1], dp[v][1]));       upd(dp2[0], mul(dp[u][0], dp[v][0]));       upd(dp2[0], mul(dp[u][0], dp[v][1]));       upd(dp2[1], mul(dp[u][1], dp[v][0]));       upd(dp2[1], mul(dp[u][1], dp[v][1]));       dp[u] = dp2;     }     return e;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     for (int i = 1; i < maxn; i++) pw2[i] = mul(pw2[i - 1], 2);     cin >> n;     for (int i = 0, u, v; i < n - 1; i++) {       cin >> u >> v;       g[--u].push_back(--v), g[v].push_back(u);     }     dfs(0);     cout << sum <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int sum[1000000 + 10][27];   char c1[1000000 + 10], c2[1000000 + 10];   long long n, m;   long long len1, len2;   long long gcd(long long a, long long b) {     long long t = a;     while (b) {       a = b;       b = t % b;       t = a;     }     return a;   }   int main() {     cin >> n >> m;     scanf( %s%s , c1, c2);     len1 = strlen(c1), len2 = strlen(c2);     long long t = gcd(len1, len2);     long long k = n / (len2 / t);     long long res = 0;     for (int i = 0; i < len2; ++i) sum[i % t][c2[i] -  a ]++;     for (int i = 0; i < len1; ++i)       for (int j = 0; j < 26; ++j)         if (j != c1[i] -  a ) res += sum[i % t][j];     res *= k;     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string x;     cin >> x;     int c1 = 0, c0 = 0;     bool f = 0;     for (int i = 0; i < x.size(); i++) {       if (x[i] ==  0 ) {         c0++;       } else if (x[i] ==  1 ) {         c1++;       }       if (c0 < 7 && x[i] ==  1 ) {         c0 = 0;       }       if (c1 < 7 && x[i] ==  0 ) {         c1 = 0;       }     }     if (c1 >= 7 || c0 >= 7) {       cout <<  YES  << endl;     } else {       cout <<  NO  << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 3e5 + 10, LEN = 5e3 + 10, S = 51, INF = 1e18;   long long f[N], l[N], r[N], sum[N];   long long lq[S], rq[S], sq[S], mq[S];   long long a[LEN], sx[LEN], mx[LEN];   int n, m;   int main() {     scanf( %d%d , &n, &m);     memset(mq, -0x3f, sizeof mq);     for (int i = 1, s; i <= n; i++) {       scanf( %d , &s);       for (int j = 1; j <= s; j++) scanf( %lld , &a[j]);       for (int j = 1; j <= s; j++) sx[j] = sx[j - 1] + a[j];       for (int j = 1; j <= s; j++) {         mx[j] = max(mx[j - 1] + a[j], a[j]);         mq[i] = max(mq[i], mx[j]);       }       lq[i] = a[1];       for (int j = 2; j <= s; j++) lq[i] = max(lq[i], sx[j]);       rq[i] = a[n];       for (int j = s - 2; j >= 0; j--) rq[i] = max(rq[i], sx[s] - sx[j]);       sq[i] = sx[s];     }     long long res = -INF;     for (int i = 1, x; i <= m; i++) {       scanf( %d , &x);       l[i] = lq[x];       r[i] = rq[x];       sum[i] = sum[i - 1] + sq[x];       res = max(res, mq[x]);     }     f[1] = l[1];     long long maxv = r[1] - sum[1], ans = f[1];     for (int i = 2; i <= m; i++) {       f[i] = sum[i - 1] + l[i] + maxv;       maxv = max(maxv, r[i] - sum[i]);       ans = max(ans, f[i]);     }     printf( %lld n , max(ans, res));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long a, b;     cin >> a >> b;     long long ships = 0;     while (a != 0 && b != 0) {       if (b > a) {         ships += b / a;         b = b % a;       } else {         ships += a / b;         a = a % b;       }     }     cout << ships << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int getsum(string st) {     int rest = 0;     for (int i = 0; i < st.size(); i++) {       rest += st[i] -  0 ;     }     return rest;   }   string streverse(string st) {     for (int i = 0; i < st.size() / 2; i++) {       char tmp = st[i];       st[i] = st[st.size() - 1 - i];       st[st.size() - 1 - i] = tmp;     }     return st;   }   string getGreater(int a, int num, string st) {     int increase = a - num;     for (int i = st.size() - 1; i >= 0; i--) {       if (st[i] -  0  < 9) {         int increment = min(9 - (st[i] -  0 ), increase);         st[i] += increment;         increase -= increment;       }       if (increase == 0) return st;     }     string rest =   ;     for (int i = 0; i < a / 9; i++) rest = rest +  9 ;     if (a % 9 > 0) {       rest = rest + (char)( 0  + a % 9);     }     return streverse(rest);   }   string getLess(int a, int num, string st) {     int decrease = num - a;     decrease++;     int sum = 0;     for (int i = st.size() - 1; i >= 1; i--) {       sum += st[i] -  0 ;       if (sum >= decrease) {         if (st[i - 1] -  0  < 9) {           st[i - 1]++;           sum = sum - decrease;           for (int j = i; j < st.size(); j++) st[j] =  0 ;           int indx = st.size() - 1;           while (sum > 0) {             if (sum > 9) {               st[indx] += 9;               sum -= 9;             } else {               st[indx] += sum;               sum = 0;             }             indx--;           }           return st;         }       }     }     st =  1  + st;     for (int i = 1; i < st.size(); i++) {       st[i] =  0 ;     }     a--;     int k;     for (k = 0; k < a / 9; k++) {       st[st.size() - 1 - k] =  9 ;     }     if (a % 9) {       for (int i = st.size() - 1; i >= 0; i--) {         if (st[i] ==  0 ) {           st[i] = (char)( 0  + a % 9);           break;         }       }     }     return st;   }   string getnum(int a, string st) {     int num = getsum(st);     if (a > num) {       return getGreater(a, num, st);     }     return getLess(a, num, st);   }   int main() {     getnum(13,  1093 );     int n;     cin >> n;     string pre =   ;     for (int i = 0; i < n; i++) {       int a;       cin >> a;       string rest = getnum(a, pre);       cout << rest << endl;       pre = rest;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long inf = 1e9 + 10, N = 2e5 + 10, mod = 998244353, lg = 20,                   sq = 450;   long long t, n, k, first[N], ans;   inline long long power(long long x, long long y) {     long long ret = 1;     x %= mod;     while (y) {       if (y & 1) ret = (ret * x) % mod;       x = (x * x) % mod;       y >>= 1;     }     return ret;   }   inline long long C(long long x, long long y) {     long long ret = first[y];     ret = (ret * power(first[x], mod - 2)) % mod;     ret = (ret * power(first[y - x], mod - 2)) % mod;     return ret;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     first[0] = 1;     for (int i = 1; i < N; i++) first[i] = (first[i - 1] * i) % mod;     cin >> n >> k;     if (k >= n) return cout << 0, 0;     for (int i = 0; i <= n - k; i += 2)       ans = (ans + ((power(n - k - i, n) * C(n - k - i, n - k)) % mod)) % mod;     for (int i = 1; i <= n - k; i += 2)       ans =           (mod + ans - ((power(n - k - i, n) * C(n - k - i, n - k)) % mod)) % mod;     ans = (ans * C(n - k, n)) % mod;     if (k) ans = (ans * 2) % mod;     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   long long Deci(int arr[], int base, int n) {     long long power = 1;     long long num = 0;     for (int i = n - 1; i >= 0; i--) {       num += arr[i] * power;       power = power * base;     }     return num;   }   int main() {     int n, m, x, y;     cin >> n >> x;     int arr[n + 3];     for (int i = 0; i < n; i++) {       cin >> arr[i];     }     cin >> m >> y;     int brr[m + 3];     for (int i = 0; i < m; i++) {       cin >> brr[i];     }     long long X = Deci(arr, x, n);     long long Y = Deci(brr, y, m);     if (X < Y)       cout <<  < n ;     else if (X > Y)       cout <<  > n ;     else       cout <<  = n ;   }


#include <bits/stdc++.h>   using namespace std;   long long power(long long x, long long y, long long m) {     if (y == 0) return 1;     long long p = power(x, y / 2, m) % m;     p = (p * p) % m;     return (y % 2 == 0) ? p : (x * p) % m;   }   long long gcd(long long a, long long b) {     if (a > b) swap(a, b);     if (a == 0) return b;     return gcd(b % a, a);   }   long long modInverse(long long a, long long m) { return power(a, m - 2, m); }   int main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     srand(time(NULL));     ;     long long t;     cin >> t;     while (t--) {       long long x;       cin >> x;       string s;       cin >> s;       long long c = 1, ans = s.size();       while (c <= x) {         long long k = s[c - 1] -  1 ;         if (s.size() < x) {           string a;           a = s.substr(c, s.size());           ans += a.size() * k;           while (k--) s += a;           c++;           ans = ans % 1000000007;         } else {           ans += (ans - c) * k;           ans = ans % 1000000007;           c++;         }       }       cout << (ans + 1000000007) % 1000000007 << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, m, ans = 0, res = 0;     cin >> n >> m;     vector<pair<long long, long long>> v;     set<pair<long long, long long>> s;     for (int i = 0; i < n; i++) {       long long p, q;       cin >> p >> q;       v.push_back(make_pair(q, p));     }     sort(v.begin(), v.end(), greater<pair<long long, long long>>());     for (int i = 0; i < n; i++) {       res += v[i].second;       s.insert(make_pair(v[i].second, i));       while (s.size() > m) {         auto it = s.begin();         res -= it->first;         s.erase(it);       }       ans = max(ans, res * v[i].first);     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   const long double E = 1e-9;   char ccc;   bool _minus = false;   inline void read(int &n) {     n = 0;     _minus = false;     while (true) {       ccc = getchar();       if (ccc ==     || ccc ==   n ) break;       if (ccc ==  - ) {         _minus = true;         continue;       }       n = n * 10 + ccc -  0 ;     }     if (_minus) n *= -1;   }   char wwww[12];   int kkkk;   inline void write(int x) {     kkkk = 0;     if (!x) ++kkkk, wwww[kkkk] =  0 ;     while (x) {       ++kkkk;       wwww[kkkk] = char(x % 10 +  0 );       x /= 10;     }     for (int i = kkkk; i >= 1; --i) putchar(wwww[i]);     putchar(   );   }   template <typename T>   inline T sqr(T t) {     return t * t;   }   const int MAX = 1e5;   vector<int> v1[MAX], v2[MAX];   bool ok1[MAX], ok2[MAX];   int ar[MAX];   void dfs1(int pos) {     ok1[pos] = true;     for (int i = 0; i < (int)v1[pos].size(); i++) {       if (!ok1[v1[pos][i]]) {         dfs1(v1[pos][i]);       }     }   }   void dfs2(int pos) {     ok2[pos] = true;     if (ar[pos] == 1) return;     for (int i = 0; i < (int)v2[pos].size(); i++) {       if (!ok2[v2[pos][i]]) {         dfs2(v2[pos][i]);       }     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     srand(time(NULL));     cout.precision(15);     cout << fixed;     int n, m;     cin >> n >> m;     for (int i = 0; i < n; i++) cin >> ar[i];     while (m--) {       int a, b;       cin >> a >> b;       a--, b--;       v1[a].push_back(b);       v2[b].push_back(a);     }     for (int i = 0; i < n; i++) {       if (ar[i] == 1 && !ok1[i]) {         dfs1(i);       } else if (ar[i] == 2 && !ok2[i]) {         dfs2(i);       }     }     for (int i = 0; i < n; i++) cout << (ok1[i] && ok2[i] ? 1 : 0) <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       map<int, int> m;       bool f = true;       vector<int> v;       while (n--) {         int a;         cin >> a;         v.push_back(a);         m[a] += 1;         if (m[a] > 1) f = false;       }       if (!f || !m[1]) {         cout << -1 << endl;         continue;       }       vector<int> o;       set<int> s;       for (int a : v) {         o.push_back(a);         s.insert(a);         for (int i = a + 1; i < 201; i++)           if (!m[i] && s.find(i) == s.end()) {             o.push_back(i);             s.insert(i);             m[i] += 1;             break;           }       }       bool r = true;       int p;       for (int a : s) {         if (f) p = a, f = false;         if (a - p > 1) {           r = false;           break;         }         p = a;       }       f = false;       if (r)         for (int a : o) {           if (f) cout <<    ;           cout << a;           f = true;         }       else         cout << -1;       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct data {     int x, y;   } v[300005];   inline bool cmp(data d1, data d2) {     if (d1.x != d2.x) return d1.x < d2.x;     return d1.y < d2.y;   }   inline bool cmp2(data d1, data d2) { return d1.y < d2.y; }   int n;   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &v[i].x);       v[i].y = i;     }     sort(v + 1, v + n + 1, cmp);     int minv = 0;     for (int i = 1; i <= n; i++) {       if (minv < v[i].x) {         minv = v[i].x + 1;       } else {         v[i].x = minv;         minv++;       }     }     sort(v + 1, v + n + 1, cmp2);     for (int i = 1; i <= n; i++) printf( %d  , v[i].x);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using VI = vector<int>;   using PII = pair<int, int>;   using ll = long long;   const int M = 1e9 + 7;   const int N = 2010;   VI d{1110111, 10010,   1011101, 1011011, 111010,        1101011, 1101111, 1010010, 1111111, 1111011};   int GetDiff(int x, int y) {     return __builtin_popcount(x) - __builtin_popcount(y);   }   int Convert(int x) {     int s = 0, k = 1;     while (x) {       if (x % 10) s += k;       x /= 10;       k <<= 1;     }     return s;   }   int main() {     for (auto& v : d) v = Convert(v);     int n, k;     scanf( %d %d , &n, &k);     vector<VI> f(n + 1, VI(k + 1, -1));     VI a(n);     vector<vector<PII>> g(n);     for (int i = 0; i < n; ++i) {       int t;       scanf( %d , &t);       a[i] = t = Convert(t);       for (int j = 9; j >= 0; --j) {         if ((d[j] & t) == t) g[i].push_back({j, GetDiff(d[j], t)});       }     }     for (auto& v : g[n - 1])       f[n - 1][v.second] = max(f[n - 1][v.second], v.first);     for (int i = n - 2; i >= 0; --i) {       for (auto& v : g[i]) {         for (int j = 0; j < k + 1 - v.second; ++j) {           if (f[i + 1][j] != -1)             f[i][j + v.second] = max(f[i][j + v.second], v.first);         }       }     }     if (f[0][k] == -1)       puts( -1 );     else {       for (int i = 0; i < n; ++i) {         printf( %d , f[i][k]);         k -= GetDiff(d[f[i][k]], a[i]);       }       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, s1, s2, t1, t2, l1, l2;   vector<int> adj[3333];   int dist[3333][3333];   void bfs(int index) {     queue<int> q;     q.push(index);     dist[index][index] = 0;     while (!q.empty()) {       int cur = q.front();       q.pop();       for (int to : adj[cur]) {         if (dist[index][to] != -1) continue;         dist[index][to] = dist[index][cur] + 1;         q.push(to);       }     }   }   int main() {     while (scanf( %d %d , &n, &m) == 2) {       memset(dist, -1, sizeof dist);       for (int i = 0; i < n; i++) adj[i].clear();       for (int i = 0; i < m; i++) {         int a, b;         scanf( %d %d , &a, &b);         adj[--a].push_back(--b);         adj[b].push_back(a);       }       scanf( %d %d %d , &s1, &t1, &l1);       --s1, --t1;       scanf( %d %d %d , &s2, &t2, &l2);       --s2, --t2;       for (int i = 0; i < n; i++) bfs(i);       if (dist[s1][t1] > l1 || dist[s2][t2] > l2) {         puts( -1 );         continue;       }       int ans = dist[s1][t1] + dist[s2][t2];       for (int i = 0; i < n; i++)         for (int j = 0; j < n; j++) {           {             int p1 = dist[s1][i] + dist[i][j] + dist[j][t1];             int p2 = dist[s2][i] + dist[i][j] + dist[j][t2];             if (p1 <= l1 && p2 <= l2) ans = min(ans, p1 + p2 - dist[i][j]);           }           {             int p1 = dist[t1][i] + dist[i][j] + dist[j][s1];             int p2 = dist[s2][i] + dist[i][j] + dist[j][t2];             if (p1 <= l1 && p2 <= l2) ans = min(ans, p1 + p2 - dist[i][j]);           }         }       ans = m - ans;       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   const double INF = 1e20;   const int N = 102;   const int M = 1010;   const int K = 10;   int n;   double C, T;   const double Y = 1. / 0.9;   pair<int, int> a[N];   double dp[N][M];   void read() {     scanf( %d , &n);     scanf( %lf%lf , &C, &T);     for (int i = 0; i < n; i++) scanf( %d%d , &a[i].first, &a[i].second);     sort(a, a + n);   }   int solve() {     read();     dp[0][0] = 0;     for (int it = 1; it <= n; it++) {       for (int j = 0; j <= it * K; j++) dp[it][j] = INF;       for (int i = it - 1; i >= 0; i--)         for (int j = 0; j <= i * K; j++) {           if (dp[i][j] >= INF / 2) continue;           dp[i + 1][j + a[it - 1].second] = min(dp[i + 1][j + a[it - 1].second],                                                 dp[i][j] * Y + a[it - 1].first);         }     }     for (int x = n * K; x >= 0; x--)       for (int p = 0; p <= n; p++) {         if (p * K < x || dp[p][x] >= INF / 2) continue;         double X = dp[p][x] * Y;         double t = X;         if (C * X >= 1) t = 2 * sqrt(X / C) - 1. / C;         t += p * 10;         if (t <= T) return x;       }     throw;   }   int main() {     int t;     scanf( %d , &t);     while (t--) printf( %d n , solve());     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-10;   const long long N = 2e5 + 10;   ;   long long n, p[N], t[N], a[N], b[N], Ma[N], Mi[N], T;   long long check(double m) {     double M = 0.0;     for (long long i = 1, j = 1; i <= n; i++) {       while (j <= n && p[b[j]] < p[b[i]])         M = max(M, (1.0 - m * Mi[b[j]] / T) * p[b[j]]), j++;       if ((1.0 - m * Ma[b[i]] / T) * p[b[i]] < M) return 0;     }     return 1;   }   signed main() {     scanf( %lld n , &n);     for (long long i = 1; i <= n; i++) scanf( %lld , &p[i]), a[i] = i;     for (long long i = 1; i <= n; i++) scanf( %lld , &t[i]), b[i] = i;     sort(a + 1, a + n + 1,          [&](long long i, long long j) { return p[i] * t[j] > p[j] * t[i]; });     sort(b + 1, b + n + 1, [&](long long i, long long j) { return p[i] < p[j]; });     for (long long i = 1, j, s; i <= n; i = j) {       for (j = i + 1, s = 0; j <= n; j++)         if (p[a[i]] * t[a[j]] != p[a[j]] * t[a[i]]) break;       for (long long k = i; k < j; k++) s += t[a[k]];       for (long long k = i; k < j; k++) Mi[a[k]] = T + t[a[k]], Ma[a[k]] = T + s;       T += s;     }     double l = 0, r = 1;     while (r - l > eps) {       double mid = (l + r) / 2.0;       if (!check(mid))         r = mid;       else         l = mid;     }     printf( %.10f n , l);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string A;   bool isPalindrome(int left, int right) {     while (left < right) {       if (A[left] != A[right]) return false;       left++, right--;     }     return true;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     cin >> A;     int N = A.size();     int bonus = 0;     int ret = 0;     if (N % 2 == 1) bonus = 1;     N /= 2;     while (N > 0) {       if (isPalindrome(0, N - 1)) {         if (N % 2 == 1) {           N--;           bonus = 1;         } else           N /= 2;       } else {         ret = 1 + bonus;         break;       }     }     if (ret == 0)       cout <<  Impossible ;     else       cout << ret;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long o = 1e6 + 5;   long n, i, j, h, k, sl, g, kq = 0;   long a[o], b[o], c[o], A, B;   string s;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n;     i = 0, j = 0, h = 0, k = 0;     for (long p = 1; p <= n; p++) {       cin >> s >> g;       if (s ==  00 ) {         i++;         a[i] = g;       } else if (s ==  01 ) {         j++;         b[j] = g;       } else if (s ==  10 ) {         h++;         c[h] = g;       } else if (s ==  11 ) {         k++;         kq += g;       }     }     if (k == 0 && (j == 0 || h == 0)) {       cout << 0;       return 0;     }     sort(a + 1, a + 1 + i);     sort(b + 1, b + 1 + j);     sort(c + 1, c + 1 + h);     a[0] = b[0] = c[0] = 0;     A = B = 0;     sl = min(h, j);     while (A < sl) {       A++;       kq += c[h];       h--;     }     while (B < sl) {       B++;       kq += b[j];       j--;     }     sl = 2 * (k + sl) - (k + 2 * sl);     for (long p = 1; p <= sl; p++) {       long ma = max(a[i], max(b[j], c[h]));       if (ma == 0) break;       kq += ma;       if (ma == a[i])         i--;       else if (ma == b[j])         j--;       else if (ma == c[h])         h--;     }     cout << kq;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long ans;   struct arr {     int n;     int v;   } a[200001], b[200001];   int n, m, i, j;   bool cmp(arr a, arr b) { return a.n < b.n; }   int main() {     cin >> n;     for (i = 1; i <= n; i++) cin >> a[i].n >> a[i].v;     cin >> m;     for (i = 1; i <= m; i++) cin >> b[i].n >> b[i].v;     sort(a + 1, a + n + 1, cmp);     sort(b + 1, b + m + 1, cmp);     i = j = 1;     while (i <= n && j <= m) {       if (a[i].n == b[j].n)         ans += max(a[i].v, b[j].v), i++, j++;       else if (a[i].n < b[j].n)         ans += a[i].v, i++;       else         ans += b[j].v, j++;     }     if (i > n) {       for (i = j; i <= m; i++) ans += b[i].v;     } else {       for (j = i; j <= n; j++) ans += a[j].v;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void fft(vector<complex<double> > &a, bool invert) {     int n = a.size(), lg = 0;     while (1 << lg < n) ++lg;     assert(1 << lg == n);     for (int i = 0; i < n; ++i) {       int rev = 0;       for (int j = 0; j < lg; ++j)         if ((i & 1 << j) != 0) rev |= 1 << (lg - j - 1);       if (i < rev) swap(a[i], a[rev]);     }     vector<complex<double> > roots(n);     for (int i = 0; i < n; ++i) {       double a = 2 * M_PI * i / n * (invert ? -1 : 1);       roots[i] = complex<double>(cos(a), sin(a));     }     for (int len = 2; len <= n; len *= 2)       for (int i = 0; i < n; i += len)         for (int j = 0; j < len / 2; ++j) {           complex<double> u = a[i + j],                           v = a[i + j + len / 2] * roots[n / len * j];           a[i + j] = u + v;           a[i + j + len / 2] = u - v;         }     if (invert)       for (int i = 0; i < n; ++i) a[i] /= n;   }   vector<int> multiply(const vector<int> &a, const vector<int> &b) {     int m = a.size(), n = b.size(), p = 2;     while (p < m + n - 1) p <<= 1;     vector<complex<double> > pa(p), pb(p);     for (int i = 0; i < m; ++i) pa[i] = complex<double>(a[i], 0);     for (int i = 0; i < n; ++i) pb[i] = complex<double>(b[i], 0);     fft(pa, false);     fft(pb, false);     for (int i = 0; i < p; ++i) pa[i] *= pb[i];     fft(pa, true);     vector<int> res(p);     for (int i = 0; i < p; ++i) res[i] = (int)round(real(pa[i]));     return res;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     int n, m;     cin >> n >> m;     vector<bool> hasBag(m + 1);     vector<int> p(m + 1);     for (int i = 0; i < n; ++i) {       int w;       cin >> w;       p[w] = 1;       hasBag[w] = true;     }     p = multiply(p, p);     for (int i = 1; i <= m; ++i)       if (p[i] > 0) {         if (!hasBag[i]) return cout <<  NO , 0;         hasBag[i] = false;       }     printf( YES n%d n , count(hasBag.begin(), hasBag.end(), 1));     for (int i = 1; i <= m; ++i)       if (hasBag[i] == 1) printf( %d  , i);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long inf = 1e15;   long long q[300005];   long long d[300005];   long long dd[300005];   struct st {     long long x, w, id;   };   vector<st> v[300005];   st t;   vector<long long> ans;   long long sum;   long long n, m;   long long x, y, z;   inline void dij(long long st) {     for (long long i = 1; i <= n; ++i) d[i] = inf;     set<pair<long long, long long> > s;     d[st] = 0;     s.insert(make_pair(0, st));     while (!s.empty()) {       long long x = s.begin()->second;       s.erase(s.begin());       for (long long i = 0; i < v[x].size(); ++i) {         long long to = v[x][i].x;         long long len = d[x] + v[x][i].w;         if (d[to] > len) {           s.erase(make_pair(d[to], to));           d[to] = len;           s.insert(make_pair(d[to], to));         }       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> m;     for (long long i = 1; i <= m; ++i) {       cin >> x >> y >> z;       t.x = y;       t.w = z;       t.id = i;       v[x].push_back(t);       t.x = x;       v[y].push_back(t);     }     long long stt;     cin >> stt;     dij(stt);     for (long long i = 1; i <= n; ++i) {       long long mx = 1e9;       for (long long j = 0; j < v[i].size(); ++j) {         long long to = v[i][j].x;         if (d[to] != d[i] - v[i][j].w) continue;         mx = min(mx, v[i][j].w);       }       for (long long j = 0; j < v[i].size(); ++j) {         long long to = v[i][j].x;         if (d[to] != d[i] - v[i][j].w) continue;         if (v[i][j].w == mx) {           ans.push_back(v[i][j].id);           sum += v[i][j].w;           break;         }       }     }     cout << sum <<   n ;     for (long long i = 0; i < ans.size(); ++i) cout << ans[i] <<    ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(), cout.tie();     int n;     cin >> n;     int temp = 1;     int a[] = {4, 7, 44, 47, 74, 77, 444, 447, 474, 477, 744, 747, 774, 777};     for (int i = 0; i < 14; i++) {       if (n % a[i] == 0) {         cout <<  YES  << endl;         temp = 0;         break;       }     }     if (temp) {       cout <<  NO  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100000;   const int INF = 0x3f3f3f3f;   int dis[MAXN + 10], pos[MAXN + 10], f[MAXN + 10], Max, m, n;   bool check(const int& x) {     if (x >= dis[1] - 1) return true;     if (2 * x < dis[1] - 1) return false;     f[1] = 0;     for (int i = 2; i <= n; i++) {       f[i] = -INF;       if (f[i - 1] >= pos[i] - 1) f[i] = pos[i] + x;       if (f[i - 1] >= pos[i] - 1 - x) f[i] = max(f[i], pos[i]);       if (i > 2 && f[i - 2] >= pos[i] - 1 - x) f[i] = max(pos[i - 1] + x, f[i]);     }     if (f[n] + x >= m - 1) return true;     f[1] = x, f[2] = max(x, pos[2]);     for (int i = 3; i <= n; i++) {       f[i] = -INF;       if (f[i - 1] >= pos[i] - 1) f[i] = pos[i] + x;       if (f[i - 1] >= pos[i] - 1 - x) f[i] = max(f[i], pos[i]);       if (f[i - 2] >= pos[i] - 1 - x) f[i] = max(pos[i - 1] + x, f[i]);     }     if (f[n] >= min(m - 1, pos[2] + m - 1 - x)) return true;     return false;   }   int tmp[MAXN + 10];   void _rotate(int* arr, int mid, int len) {     int cnt = 0;     for (int i = mid; i <= len; i++) tmp[++cnt] = arr[i];     for (int i = 1; i < mid; i++) tmp[++cnt] = arr[i];     for (int i = 1; i <= len; i++) arr[i] = tmp[i];   }   int main() {     scanf( %d%d , &m, &n);     if (n == 1) {       printf( %d n , m - 1);       return 0;     }     for (int i = 1; i <= n; i++) scanf( %d , &pos[i]);     sort(pos + 1, pos + 1 + n);     pos[0] = pos[n];     int p;     for (int i = 1; i <= n; i++) {       dis[i] = (pos[i] - pos[i - 1] + m) % m;       if (dis[i] > Max) p = i;       Max = max(Max, dis[i]);     }     _rotate(pos, p, n);     _rotate(dis, p, n);     int eff = pos[1];     for (int i = 1; i <= n; i++) pos[i] = (pos[i] - eff + m) % m;     int L = 1, R = Max - 1, ans = 0;     while (L <= R) {       int mid = (L + R) >> 1;       if (check(mid)) {         ans = mid;         R = mid - 1;       } else         L = mid + 1;     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     int n;     cin >> n;     vector<pair<long long, long long> > v(n);     for (int i = 0; i < n; i++) {       int a;       cin >> a;       v[i] = {a, 0};     }     if (n == 1) {       cout <<  T n ;       return;     }     while (1) {       sort(v.begin(), v.end(), greater<pair<long long, long long> >());       int t_idx = 0, hl_idx = 0;       while (t_idx < n && v[t_idx].second == 1) t_idx++;       if (t_idx == n || v[t_idx].first == 0) {         cout <<  HL n ;         return;       }       v[t_idx].first--;       while (hl_idx < n && hl_idx == t_idx) hl_idx++;       if (hl_idx == n || v[hl_idx].first == 0) {         cout <<  T n ;         return;       }       v[hl_idx].first--;       for (int i = 0; i < n; i++) {         if (i == hl_idx)           v[i].second = 1;         else           v[i].second = 0;       }     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int t;     cin >> t;     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       string a, b;       a +=  M , b +=  M ;       string tmp1, tmp2;       cin >> tmp1 >> tmp2;       a += tmp1, b += tmp2;       for (int i = (1); i < n + 1; i++) a[i] -=  0 , b[i] -=  0 ;       vector<int> ans;       int pos = 1;       for (int i = (1); i < n + 1; i++) {         if (b[n - i + 1] == (a[pos] + i - 1) % 2) ans.push_back(1);         ans.push_back(n - i + 1);         if (pos <= n / 2)           pos = n - pos + 1;         else           pos = n - pos + 2;       }       cout << ans.size() <<    ;       for (auto p : ans) cout << p <<    ;       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int a, b, c, d;       cin >> a >> b >> c >> d;       cout << b <<     << c <<     << c <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, a, l, r, c(0), d(0);     scanf( %d%d , &n, &m);     while (n--) {       scanf( %d , &a);       if (a == 1) {         c += 1;       } else {         d += 1;       }     }     int up = min(c, d) * 2;     while (m--) {       scanf( %d%d , &l, &r);       printf((r - l) % 2 == 1 && r - l < up ?  1 n  :  0 n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int maxx(int a[2][102], int n, int t) {     int m = 0;     for (int i = 0; i <= n; i++)       if (a[t][i] > m) m = a[t][i];     return m;   }   int main() {     char s[102];     ifstream in( input.txt );     long long int x, y;     cin >> x >> y;     if (x == 999999999) {       cout <<  Yes ;       return 0;     }     cin >> s;     if (x == 0 && y == 1 && strcmp(s,  D ) == 0) {       cout <<  No ;       return 0;     }     int a[2][102];     int i;     a[0][0] = a[1][0] = 0;     for (i = 0; i < strlen(s); i++) {       a[0][i + 1] = a[0][i];       a[1][i + 1] = a[1][i];       if (s[i] ==  U )         a[1][i + 1] = a[1][i] + 1;       else if (s[i] ==  D )         a[1][i + 1] = a[1][i] - 1;       else if (s[i] ==  L )         a[0][i + 1] = a[0][i] - 1;       else if (s[i] ==  R )         a[0][i + 1] = a[0][i] + 1;     }     long long int xs = a[0][strlen(s)], ys = a[1][strlen(s)];     long long int n;     if (xs == 0 && ys != 0)       n = abs(y / ys) - (maxx(a, strlen(s), 1) - ys);     else if (ys == 0 && xs != 0)       n = abs(x / xs) - (maxx(a, strlen(s), 0) - xs);     else if (xs != 0 && ys != 0)       n = abs(min(x / xs, y / ys));     for (long long int j = n; j <= n + 20; j++)       for (i = 0; i <= strlen(s); i++) {         int xem1 = (xs * j - x) - (xs - a[0][i]);         int xem2 = (ys * j - y) - (ys - a[1][i]);         if (xem1 == 0 && xem2 == 0) {           cout <<  Yes ;           return 0;         }       }     cout <<  No ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false), cin.tie(0);     ;     long long n, k, i;     cin >> n >> k;     long long a[n], pr[n + 1];     map<long long, long long> f;     for (i = 0; i < n; i++) {       cin >> a[i];       f[a[i]]++;     }     int fl = 0;     for (auto e : f) {       if (e.second >= k) {         cout <<  0 n ;         fl = 1;         break;       }     }     if (!fl) {       sort(a, a + n);       pr[0] = a[0];       for (i = 1; i < n; i++) pr[i] = pr[i - 1] + a[i];       long long ans = 1e18 + 5;       long long left, right, ex, costl, costr;       for (i = 0; i < n; i++) {         left = lower_bound(a, a + n, a[i]) - a;         right = n - (upper_bound(a, a + n, a[i]) - a);         ex = n - left - right;         costl = left * (a[i] - 1);         if (left) costl -= pr[left - 1];         costr = pr[n - 1] - right * (a[i] + 1);         if ((n - right - 1) >= 0) costr -= pr[n - right - 1];         if (left + ex >= k) ans = min(ans, costl + k - ex);         if (right + ex >= k) ans = min(ans, costr + k - ex);         ans = min(ans, costl + costr + k - ex);       }       cout << ans <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 105, M = N * N;   int n;   int a[N];   int f[N][M];   vector<pair<int, int> > b;   int main() {     scanf( %d , &n);     int sum = 0;     for (int i = 1; i <= n; i++) {       scanf( %d , a + i);       sum += a[i];     }     sort(a + 1, a + n + 1);     b.push_back(pair<int, int>(a[1], 1));     for (int i = 2; i <= n; i++) {       if (a[i] == b.back().first) {         b.back().second++;       } else {         b.push_back(pair<int, int>(a[i], 1));       }     }     int m = b.size();     if (m == 1) {       printf( %d n , n);     } else {       f[0][0] = 1;       int sumc = 0;       for (int i = 0; i < m; i++) {         int x = b[i].first, y = b[i].second;         sumc += y;         for (int c = sumc; c; c--) {           for (int j = sum; j >= x; j--) {             for (int k = 1; k * x <= j && k <= y && k <= c && f[c][j] < 2; k++) {               f[c][j] = min(2, f[c][j] + f[c - k][j - x * k]);             }           }         }       }       if (m == 2) {         int ans = 0;         for (int i = 0; i < m; i++) {           int x = b[i].first, y = b[i].second;           for (int j = 1; j <= y; j++) {             if (f[j][j * x] == 1) {               if (j < y) {                 ans = max(ans, j);               } else {                 ans = n;               }             }           }         }         printf( %d n , ans);       } else {         int ans = 0;         for (int i = 0; i < m; i++) {           int x = b[i].first, y = b[i].second;           for (int j = 1; j <= y; j++) {             if (f[j][j * x] == 1) {               ans = max(ans, j);             }           }         }         printf( %d n , ans);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 5048;   vector<int> adj[MAX];   bool used[MAX];   int dist[MAX][MAX];   void solve(const int test_num) {     (void)test_num;     int v, e;     cin >> v >> e;     for (int ee = 0, a, b; ee < e; ++ee) {       cin >> a >> b;       adj[a].push_back(b);     }     memset(dist, 0, sizeof(dist));     queue<int> que;     for (int st = 1; st <= v; ++st) {       que.push(st);       while (!que.empty()) {         const int at = que.front();         que.pop();         for (const int to : adj[at]) {           if (dist[st][to] == 0) {             dist[st][to] = dist[st][at] + 1;             que.push(to);           }         }       }     }     memset(used, false, sizeof(used));     int res = v;     for (int at = 1; at <= v; ++at) {       if (used[at]) continue;       used[at] = true;       int min_cycle = dist[at][at];       bool is_sink = true;       for (int to = 1; to <= v; ++to) {         if (dist[at][to] && dist[to][at]) {           used[to] = true;           min_cycle = min(min_cycle, dist[to][to]);         }         if (dist[at][to] && !dist[to][at]) {           is_sink = false;         }       }       if (is_sink && min_cycle) {         res += 998 * min_cycle + 1;       }     }     cout << res << endl;   }   void init() {}   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     srand(1223);     init();     int tests = 1;     for (int test = 1; test <= tests; ++test) {       solve(test);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int ans = 1e9;   int f[1000010];   int main() {     int n, i, j;     scanf( %d , &n);     for (i = 2; i <= n; i++) {       if (!f[i]) {         for (j = 2 * i; j <= n; j += i) {           f[j] = i;         }       }       f[i] = i - f[i] + 1;     }     for (i = f[n]; i <= n; i++) {       if (f[i] < ans) ans = f[i];     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     long long int n, m;     cin >> n >> m;     long long int st = n / 2;     if (n & 1) st++;     for (long long int i = (st); i < n + 1; i++) {       if (i % m == 0) {         cout << i;         return;       }     }     cout << -1;   }   signed main() {     ios::sync_with_stdio(0), cin.tie(0);     long long int tt = 1;     for (long long int i = (0); i < tt; i++) solve(), cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long func(long long arr[], long long n) {     long long ans = 0;     for (long long i = 2; i < n; i++) {       if (arr[i] > arr[i - 1] && arr[i] > arr[i + 1]) {         ans++;       } else if (arr[i] < arr[i - 1] && arr[i] < arr[i + 1]) {         ans++;       }     }     return ans;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long n;     cin >> n;     long long arr[n + 1];     for (long long i = 1; i <= n; i++) {       cin >> arr[i];     }     cout << func(arr, n) << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int available[1000000];     int aux;     int aux2;     for (int i = 0; i < 1000000; ++i) {       available[i] = -2;     }     for (int i = 0; i < n; ++i) {       int k = 0;       cin >> aux;       cin >> aux2;       if (!(aux % 2)) {         if ((i - available[2]) > aux2) {           k++;         }         available[2] = i;         if ((i - available[aux / 2]) > aux2) {           k++;         }         available[aux / 2] = i;       }       for (int j = 1; j <= sqrt(aux); j++) {         if (!(aux % j)) {           if ((i - available[j]) > aux2) {             k++;           }           available[j] = i;           if ((i - available[aux / j]) > aux2) {             k++;           }           available[aux / j] = i;         }       }       printf( %d n , k);     }   }


#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1);   const int N = 1e6 + 10, M = 1e7 + 10, mod = 1e9 + 7, INF = 0x3f3f3f3f, ha = 137;   int n, q;   int mx[N], a[N];   int s[M], ls[M], rs[M];   int rt[N];   int cnt;   int update(int loc, int pre, int l, int r) {     int now = ++cnt;     s[now] = s[pre] + 1;     ls[now] = ls[pre];     rs[now] = rs[pre];     if (l == r) return now;     int mid = l + r >> 1;     if (loc <= mid)       ls[now] = update(loc, ls[pre], l, mid);     else       rs[now] = update(loc, rs[pre], mid + 1, r);     return now;   }   int query(int a, int b) {     int x = rt[a - 1], y = rt[b];     int ans = 0;     int l = 0, r = n;     while (l < r) {       int mid = l + r >> 1;       if (a <= mid)         ans += s[rs[y]] - s[rs[x]], x = ls[x], y = ls[y], r = mid;       else {         l = mid + 1, x = rs[x], y = rs[y];       }     }     return ans;   }   int tot;   struct dat {     int s[N << 2], lazy[N << 2];     void update(int a, int b, int x, int k, int l, int r) {       if (a == l && b == r) {         s[x] += k;         lazy[x] += k;         return;       }       int mid = l + r >> 1, ls = x << 1, rs = x << 1 | 1;       if (lazy[x]) {         update(l, mid, ls, lazy[x], l, mid);         update(mid + 1, r, rs, lazy[x], mid + 1, r);         lazy[x] = 0;       }       if (b <= mid)         update(a, b, ls, k, l, mid);       else if (a > mid)         update(a, b, rs, k, mid + 1, r);       else {         update(a, mid, ls, k, l, mid);         update(mid + 1, b, rs, k, mid + 1, r);       }       s[x] = max(s[ls], s[rs]);     }     int query(int k) {       int x = 1;       int l = 1, r = n;       while (l < r) {         int mid = l + r >> 1, ls = x << 1, rs = x << 1 | 1;         if (lazy[x]) {           update(l, mid, ls, lazy[x], l, mid);           update(mid + 1, r, rs, lazy[x], mid + 1, r);           lazy[x] = 0;         }         if (s[rs] >= k)           x = rs, l = mid + 1;         else           x = ls, r = mid;       }       return l;     }   } tr;   int f[N];   int ss;   int main() {     cin >> n >> q;     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       int k = i - a[i];       if (k < 0) {         rt[i] = update(a[i] = 0, rt[i - 1], 0, n);         continue;       }       int t = tr.query(k);       a[i] = f[t];       if (k == 0) f[++tot] = i, a[i] = i, t = tot;       if (k > ss) {         a[i] = 0, t = 0;       } else         ss++;       if (min(tot, t)) tr.update(1, min(tot, t), 1, 1, 1, n);       rt[i] = update(a[i], rt[i - 1], 0, n);     }     int l, r;     while (q--) {       scanf( %d%d , &l, &r);       printf( %d n , query(l, n - r));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxN = 200005;   int P[maxN];   int color[maxN];   int cycle_count = 0;   void dfs(int s) {     color[s] = 1;     if (color[P[s]] == 0)       dfs(P[s]);     else if (color[P[s]] == 1)       ++cycle_count;     color[s] = 2;   }   int main() {     int n;     cin >> n;     int res = 1;     for (int i = 1; i <= n; ++i) scanf( %d , &P[i]);     for (int i = 1; i <= n; ++i) {       int b;       scanf( %d , &b);       res ^= b;     }     for (int i = 1; i <= n; ++i)       if (color[i] == 0) dfs(i);     if (cycle_count > 1) res += cycle_count;     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int oo = ~0u >> 2, mo = (int)1e9 + 7;   const int mn = 52, mp = ((mn) * (mn)), me = mp * 4;   const int fx[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};   struct EDGE {     int y, l;   } E[me];   int g[mp], d[mp], h[mn][mn], Q[mp];   bool a[mn][mn];   int n, m, tt(0);   void add(int x, int y) { E[++tt].y = y, E[tt].l = g[x], g[x] = tt; }   void fill(int x, int y) {     h[x][y] = tt;     for (int i = 0; i <= 3; ++i) {       int nx = x + fx[i][0], ny = y + fx[i][1];       if (nx < 1 || nx > n || ny < 1 || ny > m || a[x][y] != a[nx][ny] ||           h[nx][ny])         continue;       fill(nx, ny);     }   }   int calc(int x, int y) {     int l = 0, r = 0;     memset(&d, -1, sizeof(d));     d[Q[++r] = h[x][y]] = 0;     while (l++ != r)       for (int i = g[Q[l]], y = E[i].y; i; i = E[i].l, y = E[i].y)         if (d[y] == -1) d[Q[++r] = y] = d[Q[l]] + 1;     int ret = 0;     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= m; ++j)         if (a[i][j]) (ret = max(ret, d[h[i][j]]));     return ret;   }   int main() {     scanf( %d%d , &n, &m);     bool black = 0;     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= m; ++j) {         char ch;         do {           scanf( %c , &ch);         } while (ch !=  B  && ch !=  W );         black |= (a[i][j] = (ch ==  B ));       }     if (!black) {       printf( 0 n );       return 0;     }     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= m; ++j)         if (!h[i][j]) ++tt, fill(i, j);     tt = 0;     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= m; ++j)         for (int k = 0; k <= 3; ++k) {           int x = i + fx[k][0], y = j + fx[k][1];           if (x < 1 || x > n || y < 1 || y > m || h[i][j] == h[x][y]) continue;           add(h[i][j], h[x][y]);         }     int Ans = oo;     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= m; ++j) {         int tmp = calc(i, j);         (Ans = min(Ans, tmp));       }     printf( %d n , Ans + 1);   }


#include <bits/stdc++.h>   using namespace std;   const double PI = atan(1.0) * 4.0;   int in_c() {     int c;     while ((c = getchar()) <=    ) {       if (!~c) throw ~0;     }     return c;   }   int in() {     int x = 0, c;     while ((unsigned int)((c = getchar()) -  0 ) >= 10) {       if (c ==  - ) return -in();       if (!~c) return ~0;     }     do {       x = 10 * x + (c -  0 );     } while ((unsigned int)((c = getchar()) -  0 ) < 10);     return x;   }   template <class T>   struct fenwick_tree {     vector<T> x;     fenwick_tree(int n) : x(n, 0) {}     T sum(int i, int j) const {       if (i == 0) {         T S = 0;         for (; j >= 0; j = (j & (j + 1)) - 1) S += x[j];         return S;       } else         return sum(0, j) - sum(0, i - 1);     }     void add(int k, T a) {       for (; k < (int)x.size(); k |= k + 1) x[k] += a;     }     void set(int k, T a) {       T now = at(k);       add(k, a - now);     }     T at(int i) const { return sum(i, i); }   };   int main() {     int N, K;     while (N = in(), N != EOF) {       K = in();       int center = K / 2;       const int INF = 1 << 28;       vector<fenwick_tree<int> > bit(K, fenwick_tree<int>(K));       for (int i = (0), ___e = (N); i < ___e; ++i) {         int M = in();         int ax = -1, l;         int min_score = INF;         for (int r = (0), ___e = (K); r < ___e; ++r)           for (int c = (0), ___e = (K - M + 1); c < ___e; ++c) {             if (bit[r].sum(c, c + M - 1) == 0) {               int s = 0;               for (int j = c; j < c + M; ++j) {                 s += abs(r - center) + abs(j - center);               }               if (s < min_score) {                 min_score = s;                 ax = r, l = c;               } else if (s == min_score) {                 if (ax > r || ax == r && l > c) {                   min_score = s;                   ax = r, l = c;                 }               }             }           }         if (ax == -1) {           cout << -1 << endl;         } else {           for (int j = l; j < l + M; ++j) bit[ax].add(j, 1);           cout << ax + 1 <<     << l + 1 <<     << l + M << endl;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n;     cin >> n;     long long maxi = LLONG_MIN;     for (long long i = 1LL; i <= n; i++) {       long long x, y;       cin >> x >> y;       maxi = max(maxi, x + y);     }     cout << maxi << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main(void) {     int n;     cin >> n;     int *arr = (int *)malloc(sizeof(int) * n);     for (int i = 0; i < n; ++i) cin >> arr[i];     int curr = arr[0], ans = 1, temp = 1;     for (int i = 1; i < n; ++i) {       ans = max(ans, temp);       if (arr[i] >= curr) {         curr = arr[i];         ++temp;       } else {         temp = 1;         curr = arr[i];       }     }     cout << max(ans, temp);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long nChooseR(int n, int k);   long long gcd(long long a, long long b);   vector<string> split(string target, char c);   bool isPrime(long long g);   long long n, m, t, a[] = {0, 0, 1, 2, 3, 4, 5}, k, x, y, z;   long long ans;   map<pair<int, int>, int> mp;   vector<vector<int>> grid(7);   void solve(int i) {     for (auto u : grid[i]) {       if (mp[make_pair(a[i], a[u])] == 1) {         z++;         mp[make_pair(a[i], a[u])] = 0;         mp[make_pair(a[u], a[i])] = 0;         solve(u);       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cin >> n >> m;     for (int i = 0; i < (int)(m); i++) {       cin >> x >> y;       x--;       y--;       grid[x].push_back(y);       grid[y].push_back(x);     }     do {       z = 0;       for (int i = 0; i < (int)(6); i++) {         for (int j = 0; j < (int)(6); j++) mp[make_pair(i, j)] = 1;       }       for (int i = 0; i < (int)(6); i++) solve(i);       ans = max(ans, z);     } while (next_permutation(a, a + 7));     cout << ans;     return 0;   }   long long nChooseR(int n, int k) {     if (k > n) return 0;     if (k * 2 > n) k = n - k;     if (k == 0) return 1;     long long result = n;     for (int i = 2; i <= k; ++i) {       result *= (n - i + 1);       result /= i;     }     return result;   }   long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }   vector<string> split(string target, char c) {     string d =   ;     vector<string> arr;     for (auto n : target) {       if (n != c)         d += n;       else if (d !=   )         arr.push_back(d), d =   ;     }     if (d !=   ) arr.push_back(d), d =   ;     return arr;   }   bool isPrime(long long g) {     if ((g % 2 == 0 && g > 2) || g == 1) return 0;     for (long long i = 3; i * i <= g; i += 2)       if (g % i == 0) return 0;     return 1;   }


//IaMaNanBord//      #include <bits/stdc++.h>   using namespace std;      //Macro Shorthands   #define F                       first   #define S                       second   #define f(i,n)                  for(ll i=0;i<=n;i++)   #define rf(i,n)                 for(ll i=n;i>=0;i--)   #define Cf(i,a,b)               for(ll i=a;i<=b;i++)   #define Crf(i,b,a)              for(ll i=b;i>=a;i--)   // #define endl                      n               #define pb                      push_back   #define mp                      make_pair   #define z                       ((ll)1e9 + 7)     #define every(it,x)             for(auto &it:x)   #define SET(it,x)               for(auto &it:x){cin>>it;}   #define ins                     insert   #define INF      ((ll)1e18)   #define Test                    ll T; cin>>T; while(T--)   #define all(v)                  v.begin(),v.end()   #define nline                   cout<<endl   #define SZ(v)                   (ll)v.size()   #define pll                     pair<ll,ll>         //Macro Shorthands   #ifndef ONLINE_JUDGE       #define revelio(args...)        { string _s = #args; replace(_s.begin(), _s.end(),  , ,    );stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }   #else       #define revelio(args...)        {}   #endif      void err(istream_iterator<string> it) {}   template<typename T, typename... Args>   void err(istream_iterator<string> it, T a, Args... args) {cerr << *it <<   =   << a << endl; err(++it, args...);}      //Data types   typedef long long               ll;   typedef vector<ll>              vll;   typedef vector<string>          vstr;   typedef vector<char>            vchar;   typedef vector<pair<ll,ll> >    vpll;   typedef set<ll>                 sll;   typedef set<string>             sstr;   typedef set<pair<ll,ll> >       spll;   typedef map<ll,ll>              mllll;   typedef map<string,ll>          mstrll;   typedef queue<ll>               qll;         //Functions   ll powMod(ll x,ll y)            {ll p=1; while(y){if(y%2){p=(p*x)%z;} y/=2; x=(x*x)%z;} return p;}   ll CpowMod(ll x,ll y, ll w)     {ll p=1; while(y){if(y%2){p=(p*x)%w;} y/=2; x=(x*x)%w;}return p;}   ll invMod(ll x)                 {return powMod(x,z-2);}   ll CinvMod(ll x,ll w)           {return CpowMod(x,w-2,w);}   ll gcd(ll a, ll b)              {return b == 0 ? a : gcd(b, a % b);}   // ll exGcd(ll a,ll b,ll &x, ll &y){if(b==0){y = 0;x = 1;return a;}ll xtmp, ytmp;ll g = exGcd(b,a%b,xtmp,ytmp);   //                                 x=ytmp; y = xtmp - (a/b)*ytmp;return g;}   // vll sub;   // void subSet(ll k,ll n)          {if(k==n+1){every(it,sub)cout<<it<<   ;cout<<endl;}   //                                 else{sub.pb(k);subSet(k+1,n);   //                                 sub.pop_back();subSet(k+1,n);}}      // vll perm; const ll N = (ll)2e6 ;bool isSelected[N];   // void permut(ll n)               {if(perm.size()==n){every(it,perm)cout<<it<<   ;cout<<endl;}   //                                 else{Cf(i,1,n){if(isSelected[i])continue;perm.pb(i);   //                                 isSelected[i]=1;permut(n);perm.pop_back();isSelected[i] =0;}}}       void solve(){       Test{           vll a(3);           SET(it,a);           sort(all(a));           ll sum = a[0] + a[1] + a[2];           if(sum%9){               cout<< NO <<endl;           }           else{               ll x = sum/9;               if(x>a[0]){                   cout<< NO <<endl;               }               else{                   cout<< YES <<endl;               }           }       }   }         int main(){       ios_base::sync_with_stdio(0) ;       cin.tie(0) ; cout.tie(0) ;       cout.precision(20);          #ifndef ONLINE_JUDGE       freopen( input.txt ,  r , stdin);       freopen( output.txt ,  w , stdout);    freopen( error.txt , w ,stderr);       #else              #endif       solve();       #ifndef ONLINE_JUDGE           cout<<  nTime Elapsed:  <<1.0*clock()/ CLOCKS_PER_SEC<<  Sec n ;       #endif       return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long int is_query = LLONG_MIN;   struct Line {     long long int m, b;     mutable function<const Line*()> succ;     bool operator<(const Line& rhs) const {       if (rhs.b != is_query) return m < rhs.m;       const Line* s = succ();       if (!s) return 0;       long long int x = rhs.m;       return b - s->b < (s->m - m) * x;     }   };   struct HullDynamic : public multiset<Line> {     bool bad(iterator y) {       auto z = next(y);       if (y == begin()) {         if (z == end()) return 0;         return y->m == z->m && y->b <= z->b;       }       auto x = prev(y);       if (z == end()) return y->m == x->m && y->b <= x->b;       return (x->b - y->b) * (z->m - y->m) >= (y->b - z->b) * (y->m - x->m);     }     void Add(long long int m, long long int b) {       auto y = insert({m, b});       y->succ = [=] { return next(y) == end() ? 0 : &*next(y); };       if (bad(y)) {         erase(y);         return;       }       while (next(y) != end() && bad(next(y))) erase(next(y));       while (y != begin() && bad(prev(y))) erase(prev(y));     }     long long int Query(long long int x) {       auto l = *lower_bound((Line){x, is_query});       return l.m * x + l.b;     }   };   long long int m[200005];   long long int cIA[200005];   long long int cA[200005];   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %I64d , &m[i]);     for (int i = 1; i <= n; i++) cA[i] = cA[i - 1] + m[i];     for (int i = 1; i <= n; i++) cIA[i] = cIA[i - 1] + i * m[i];     long long int Max = 0;     HullDynamic ch;     ch.Add(0, 0);     for (int i = 1; i <= n; i++) {       Max = max(Max, ch.Query(cA[i]) + cIA[i]);       ch.Add(-i, -cIA[i] + i * cA[i]);     }     cout << Max << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int m, n;     cin >> n >> m;     int c[n];     for (int i = 0; i < n; i++) cin >> c[i];     int a[m];     for (int i = 0; i < m; i++) cin >> a[i];     int d = 0, j = 0;     for (int i = 0; i < n; i++) {       if (a[j] >= c[i]) {         d++;         j++;       }       if (d == m) break;     }     cout << d << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     long long int max = 2000000001, min = -2000000001;     long long int x, y;     string question;     char answer;     int i;     for (i = 0; i < n; i++) {       int tmp;       cin >> question;       cin >> x >> answer;       cin.get();       if (question[0] ==  < ) {         if (answer ==  Y ) {           if (x <= max)             if (question.size() == 2)               max = x;             else               max = x - 1;         } else {           if (x >= min)             if (question.size() == 2)               min = x + 1;             else               min = x;         }       } else {         if (question[0] ==  > ) {           if (answer ==  Y ) {             if (x >= min)               if (question.size() == 2)                 min = x;               else                 min = x + 1;           } else {             if (x <= max)               if (question.size() == 2)                 max = x - 1;               else                 max = x;           }         }       }     }     if (min > max) {       cout <<  Impossible  << endl;       return 0;     } else {       if (max == min)         cout << min << endl;       else         cout << min + 1 << endl;     }     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   void solve(int* arr, int n) {     int max_sum = 0;     int answer = 0;     for (int i = 1; i <= 30; i++) {       int current = 0;       max_sum = 0;       for (int j = 0; j < n; j++) {         if (arr[j] > i) {           current = 0;           continue;         }         current = current + arr[j];         if (current < 0) {           current = 0;         }         max_sum = max(current, max_sum);       }       answer = max(answer, max_sum - i);     }     cout << answer << endl;   }   int main() {     int n;     cin >> n;     int arr[200005];     for (int i = 0; i < n; i++) {       cin >> arr[i];     }     solve(arr, n);   }


#include <bits/stdc++.h>   using namespace std;   #pragma comment(linker,  /STACK:1024000000,1024000000 )   int _MAX(int a, int b) { return a > b ? a : b; }   int _MIN(int a, int b) { return a > b ? b : a; }   int Scan() {     int res = 0, flag = 0;     char ch;     if ((ch = getchar()) ==  - )       flag = 1;     else if (ch >=  0  && ch <=  9 )       res = ch -  0 ;     while ((ch = getchar()) >=  0  && ch <=  9 ) res = res * 10 + (ch -  0 );     return flag ? -res : res;   }   void Out(int a) {     if (a < 0) {       putchar( - );       a = -a;     }     if (a >= 10) Out(a / 10);     putchar(a % 10 +  0 );   }   long long a[100005][2];   long long dis(long long x1, long long y1, long long x2, long long y2) {     return (x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1);   }   int main() {     long long n, px, py, ma = 0;     double mi = 1e16;     scanf( %lld%lld%lld , &n, &px, &py);     for (int i = 1; i <= n; ++i) {       scanf( %lld%lld , &a[i][0], &a[i][1]);       long long d = dis(a[i][0], a[i][1], px, py);       mi = min(mi, (double)d);       ma = max(ma, d);     }     a[n + 1][0] = a[1][0], a[n + 1][1] = a[1][1];     for (int i = 1; i <= n; ++i) {       long long A2 = dis(px, py, a[i][0], a[i][1]);       long long B2 = dis(px, py, a[i + 1][0], a[i + 1][1]);       long long C2 = dis(a[i][0], a[i][1], a[i + 1][0], a[i + 1][1]);       double A = sqrt(A2), B = sqrt(B2), C = sqrt(C2);       if (C2 + B2 > A2 && C2 + A2 > B2) {         double P = (A + B + C) / 2;         double S = sqrt(P * (P - A) * (P - B) * (P - C));         double H = S / C * 2;         mi = min(mi, H * H);       }     }     printf( %.10lf n , acos(-1.0) * (ma - mi));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, m, x, y, a, b, times, red, t3;   long long k;   void work3() {     long long t1, t2;     if (red == 0) {       times--;       red = m * 2 * (n - 1);     }     if (x != 1 && x != n)       t3 = 2 * times;     else       t3 = times;     if (red > n * m) {       t3++;       red -= n * m;       a = red / m;       b = red % m;       if (b != 0)         a++;       else         b = m;       if (n - a == x) {         if (y <= b) t3 += 1;       } else if (n - a < x) {         if (x != n) t3 += 1;       }       t1 = (times + 1) * 2;       t2 = times + 1;     } else {       a = red / m;       b = red % m;       if (b != 0)         a++;       else         b = m;       if (a == x) {         if (y <= b)           t3 += 1;         else           t3 += 0;       } else if (a > x)         t3 += 1;       if (a > 1) {         t1 = times * 2 + 1;         if (a < n || (a == n && b != m))           t2 = times;         else           t2 = times + 1;       } else {         t1 = times * 2;         if (t1 == 0) t1++;         t2 = times;       }     }     cout << t1 <<     << t2 <<     << t3 << endl;   }   int main() {     cin >> n >> m >> k >> x >> y;     if (n > 2) {       times = k / (m * 2 * (n - 1));       red = k % (m * 2 * (n - 1));       work3();     } else if (n == 1) {       long long t2;       times = k / (n * m);       red = k % (n * m);       if (red == 0) {         red = n * m;         times--;       }       if (y <= red)         t3 = times + 1;       else         t3 = times;       if (red == m)         t2 = times + 1;       else         t2 = times;       cout << times + 1 <<     << t2 <<     << t3 << endl;     } else if (n == 2) {       long long t2;       times = k / (n * m);       red = k % (n * m);       if (red == 0) {         red = n * m;         times--;       }       a = red / m;       b = red % m;       if (b != 0)         a++;       else         b = m;       if (x > a) {         t3 = times;       } else if (x == a) {         if (y <= b)           t3 = times + 1;         else           t3 = times;       } else if (x < a) {         t3 = times + 1;       }       if (a == n && b == m)         t2 = times + 1;       else         t2 = times;       cout << times + 1 <<     << t2 <<     << t3 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int max_n = 1500555, inf = 1000111222;   struct tree {     long long a[4 * max_n], f[4 * max_n];     void clr() {       memset(a, 0, sizeof(a));       memset(f, 0, sizeof(f));     }     void push(int v, int l, int r) {       if (f[v] != 0) {         f[2 * v] += f[v];         f[2 * v + 1] += f[v];         int mid = (l + r) / 2;         a[2 * v] += (mid - l + 1) * f[v];         a[2 * v + 1] += (r - mid) * f[v];         f[v] = 0;       }     }     void update(int v, int tl, int tr, int l, int r, long long value) {       if (tl == l && tr == r) {         a[v] += (r - l + 1) * value;         f[v] += value;         return;       }       push(v, tl, tr);       int mid = (tl + tr) / 2;       if (r <= mid) {         update(2 * v, tl, mid, l, r, value);       } else if (l > mid) {         update(2 * v + 1, mid + 1, tr, l, r, value);       } else {         update(2 * v, tl, mid, l, mid, value);         update(2 * v + 1, mid + 1, tr, mid + 1, r, value);       }       a[v] = (a[2 * v] + a[2 * v + 1]);     }     long long get_sum(int v, int tl, int tr, int l, int r) {       if (l > r) {         return 0;       }       if (tl == l && tr == r) {         return a[v];       }       push(v, tl, tr);       int mid = (tl + tr) / 2;       if (r <= mid) {         return get_sum(2 * v, tl, mid, l, r);       }       if (l > mid) {         return get_sum(2 * v + 1, mid + 1, tr, l, r);       }       return get_sum(2 * v, tl, mid, l, mid) +              get_sum(2 * v + 1, mid + 1, tr, mid + 1, r);     }   };   char buf[max_n];   string read() {     scanf( %s , buf);     return buf;   }   void get_z_function(const string &s, int z[]) {     z[0] = 0;     int l = 0, r = 0;     for (int i = 1; i < s.length(); ++i) {       z[i] = 0;       if (i <= r) {         z[i] = min(z[i - l], r - i + 1);       }       while (i + z[i] < s.length() && s[i + z[i]] == s[z[i]]) {         ++z[i];       }       if (i + z[i] - 1 > r) {         r = i + z[i] - 1;         l = i;       }     }   }   int n, m, z[2][max_n], mx[2][max_n], cnt[2][max_n];   string a[2], s, rs;   long long ans;   tree t;   vector<int> v[max_n];   void proc1() {     t.clr();     for (int i = 0; i < max_n; ++i) {       v[i].clear();     }     for (int i = 0; i < n; ++i) {       if (mx[0][i]) {         v[i + m - 1].push_back(max(1, m - mx[0][i]));       }     }     for (int i = 0; i < n; ++i) {       t.update(1, 0, m, 0, mx[1][i], 1);     }     for (int i = 0; i < n; ++i) {       for (int l : v[i]) {         ans -= t.get_sum(1, 0, m, l, m - 1);       }       t.update(1, 0, m, 0, mx[1][i], -1);     }   }   void proc2() {     t.clr();     for (int i = 0; i < max_n; ++i) {       v[i].clear();     }     for (int i = 0; i < n; ++i) {       if (mx[1][i]) {         v[i + 1].push_back(max(1, m - mx[1][i]));       }     }     for (int i = 0; i < n; ++i) {       t.update(1, 0, m, 0, mx[0][i], 1);     }     for (int i = 0; i < n; ++i) {       for (int l : v[i]) {         ans -= t.get_sum(1, 0, m, l, m - 1);       }       t.update(1, 0, m, 0, mx[0][i], -1);     }   }   int get_sum(int tp, int l, int r) {     if (!l) {       return cnt[tp][r];     }     return cnt[tp][r] - cnt[tp][l - 1];   }   int main() {     scanf( %d%d , &n, &m);     a[0] = read();     a[1] = read();     s = read();     rs = s;     reverse(rs.begin(), rs.end());     get_z_function(s +  #  + a[0], z[0]);     string ra1 = a[1];     reverse(ra1.begin(), ra1.end());     get_z_function(rs +  #  + ra1, z[1]);     for (int i = s.length() + 1; i <= s.length() + n; ++i) {       mx[0][i - (s.length() + 1)] = z[0][i];       mx[1][n - 1 - (i - (s.length() + 1))] = z[1][i];     }     proc1();     proc2();     for (int i = 0; i < 2; ++i) {       for (int j = 0; j < n; ++j) {         ++cnt[i][mx[i][j]];       }       for (int j = 1; j <= m; ++j) {         cnt[i][j] += cnt[i][j - 1];       }     }     for (int i = 1; i < m; ++i) {       const int s0 = get_sum(0, i, m);       const int s1 = get_sum(1, m - i, m);       ans += 1LL * s0 * s1;     }     printf( %I64d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     std::ios::sync_with_stdio(false);     std::cin.tie(0);     int a, b, c;     cin >> a >> b >> c;     int s = 0;     int min = a < b ? a : b;     int max = a > b ? a : b;     s += min;     if (c > (max + min))       s += (max + min);     else       s += c;     if ((c + min) < max)       s += c + min;     else       s += max;     cout << s << endl;   }


#include <bits/stdc++.h>   const long long kot = LLONG_MAX;   using kk = long double;   const long long int alpha = 1e18;   using namespace std;   int gcd(long long int a, long long int b) {     if (a == 0) return b;     if (b == 0) return a;     if (a == b) return a;     if (a > b) return gcd(a - b, b);     return gcd(a, b - a);   }   int largest(long long int arr[], long long int n) {     return *max_element(arr, arr + n);   }   long long int lcm(long long int a, long long int b) {     return (a * b) / gcd(a, b);   }   void sieve(bool primes[], int x) {     primes[1] = false;     for (int i = 2; i * i <= x; i++) {       if (primes[i] == true) {         for (int j = 2; j * i <= x; j++) primes[i * j] = false;       }     }   }   long long int power(long long int x, unsigned long long int y,                       long long int p) {     long long int res = 1;     x = x % p;     while (y > 0) {       if (y & 1) res = (res * x) % p;       y = y >> 1;       x = (x * x) % p;     }     return res;   }   class gfg {    public:     int sumDigits(int no) { return no == 0 ? 0 : no % 10 + sumDigits(no / 10); }   };   bool isPerfectSquare(long double x) {     long double sr = sqrt(x);     return ((sr - floor(sr)) == 0);   }   bool comp(int a, int b) { return (a < b); }   vector<long long int> ve;   void divisors(long long int n) {     for (int i = 1; i <= sqrt(n); i++) {       if (n % i == 0) {         if (n / i == i)           ve.emplace_back(i);         else           ve.emplace_back(i);         ve.emplace_back(n / i);       }     }   }   bool isPrime(long long int n) {     if (n == 1) {       return false;     }     long long int i = 2;     while (i * i <= n) {       if (n % i == 0) {         return false;       }       i += 1;     }     return true;   }   int gcdofarray(long long int v[], long long int n) {     long long int result = v[0];     for (long long int i = 1; i < n; i++) result = gcd(v[i], result);     return result;   }   int sumofdigits(long long int n) {     long long int sum = 0;     while (n > 0) {       sum += n % 10;       n /= 10;     }     return sum;   }   bool powertwo(long long int x) { return x && (!(x & (x - 1))); }   long long int finduncommonsubsequence(string str, string s) {     if (!str.compare(s)) {       return 0;     }     return max(str.length(), s.length());   }   void reversec(string str) {     for (long long int i = str.length() - 1; i >= 0; i--) cout << str[i];   }   long long int subCount(long long int arr[], long long int n, long long int k) {     long long int mod[k];     memset(mod, 0, sizeof(mod));     long long int cumSum = 0;     for (long long int i = 0; i < n; i++) {       cumSum *= arr[i];       mod[((cumSum % k) + k) % k]++;     }     long long int result = 0;     for (long long int i = 0; i < k; i++)       if (mod[i] > 1) result += (mod[i] * (mod[i] - 1)) / 2;     result += mod[0];     return result;   }   void solve() {     long long int t = 1;     while (t--) {       long long int n;       cin >> n;       long long int arr[n];       long long int i, sum = 0;       for (i = 0; i < n; i++) {         cin >> arr[i];         sum += arr[i];       }       long long int j = 0, k = 0;       while (j < n) {         if (j % 2 == 0) {           k += arr[j] / 2;         } else {           k += arr[j] - arr[j] / 2;         }         j++;       }       cout << min(k, sum - k) <<   n ;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     ;     solve();   }


#include <bits/stdc++.h>   using namespace std;   int d[1005][1005], sum, res, s, n;   int main() {     scanf( %d , &n);     for (int res = 3; res <= 100; res++) {       memset(d, 0, sizeof(d)), sum = 0;       for (int i = 1; i <= res; i++) {         for (int j = 1; j < i; j++) {           if (sum <= n) {             int now = 0;             for (int k = 1; k <= res; k++)               if (i != k and j != k and d[i][k] and d[j][k]) now++;             if (sum + now <= n) {               sum += now;               d[i][j] = d[j][i] = 1;             }             if (sum == n) {               cout << res << endl;               for (int i1 = 1; i1 <= res; i1++) {                 for (int j1 = 1; j1 <= res; j1++) cout << d[i1][j1];                 printf(  n );               }               return 0;             }           }         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 5e5 + 5;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int T;     cin >> T;     while (T--) {       int n, m;       cin >> n >> m;       if (n % m == 0)         cout <<  YES n ;       else         cout <<  NO n ;     }   }


#include <bits/stdc++.h>   using namespace std;   void past_code();   void file() {}   long long gcd(long long x, long long y) {     if (y == 0) return x;     return gcd(y, x % y);   }   long long todic(string z) {     long long sum = 0;     long long j = 1;     for (long long i = 0; i < z.length(); i++) {       sum += (z[i] -  0 ) * j;       j *= 2;     }     return sum;   }   string tobin(long long a) {     string x;     while (a != 0) {       x += to_string(a % 2);       a /= 2;     }     return x;   }   bool isPrime(long long n) {     if (n <= 1) return false;     for (long long i = 2; i <= sqrt(n); i++)       if (n % i == 0) return false;     return true;   }   string towlo(string x) {     string h;     for (long long i = 0; i < x.length(); i++) {       h += tolower(x[i]);     }     return h;   }   bool comp(pair<long long, long long> a, pair<long long, long long> b) {     return a.second > b.second;   }   inline void read(int &x) {     x = 0;     char c = getchar();     int f = 1;     while (c <  0  || c >  9 ) {       if (c ==  - ) f = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       x = 10 * x + c -  0 ;       c = getchar();     }     x *= f;   }   long long fact(long long o) {     if (o == 0) return 1;     return o * fact(o - 1);   }   long long sumd(long long x) {     long long sum = 0;     while (x != 0) {       sum += x % 10;       x /= 10;     }     return sum;   }   bool com(pair<long long, long long> a, pair<long long, long long> b) {     return a.second > b.second;   }   bool vis[505][505];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     string x;     cin >> x;     int k;     cin >> k;     map<string, int> m;     string h[] = { January ,    February ,  March ,     April ,                    May ,        June ,      July ,      August ,                    September ,  October ,   November ,  December };     m[ January ] = 0;     m[ June ] = 5;     m[ November ] = 10;     m[ February ] = 1;     m[ July ] = 6;     m[ December ] = 11;     m[ March ] = 2;     m[ August ] = 7;     m[ April ] = 3;     m[ September ] = 8;     m[ May ] = 4;     m[ October ] = 9;     cout << h[(k + m[x]) % 12] <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   void print(const T& t) {     cout << t <<   n ;   }   template <typename T, typename U, typename... ARGS>   void print(const T& t, const U& u, const ARGS&... args) {     cout << t <<    ;     print(u, args...);   }   signed main() {     ios_base::sync_with_stdio(false), cin.tie(nullptr);     long long tc;     cin >> tc;     while (tc--) {       long long x, y, n;       cin >> x >> y >> n;       long long z = (n / x) * x;       while (z + y > n) {         z -= x;       }       print(z + y);     }     return 0;   }


#include<bits/stdc++.h>   using namespace std;   #define l1 long long   void solve() {       int n; cin>>n;       vector<int> v(n);       for(auto &i:v) cin>>i;       l1 sum = 0;       l1 need = 0;       for(int i=0;i<n;i++) {           sum+=v[i];           need+=i;           if(sum<need) {cout<< NO <<endl; return;}       }       cout<< YES <<endl;          }   int main() {       int t; cin>>t;       while(t--) {           solve();       }   }