#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ld = long double;   vector<int> gr[(ll)(1e5 + 4)];   set<int> g[(ll)(1e5 + 4)];   bool vis[(ll)(1e5 + 4)];   int par[(ll)(1e5 + 4)], si[(ll)(1e5 + 4)];   int find(int no) {     if (par[no] != no) {       par[no] = find(par[no]);     }     return par[no];   }   void join(int a, int b) {     if (find(a) == find(b)) {       return;     }     int pa = par[a], pb = par[b];     if (si[pa] < si[pb]) {       swap(pa, pb);     }     si[pa] += si[pb];     si[pb] = 0;     par[pb] = pa;   }   void dfs(int node) {     cout << node <<    ;     vis[node] = 1;     for (int x : gr[node]) {       if (!vis[x]) {         dfs(x);       }     }   }   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       int ar[n][3];       for (int i = 0; i < n - 2; i++) {         for (int j = 0; j < 3; j++) {           cin >> ar[i][j];           int a = ar[i][j];           g[a].insert(i);         }       }       set<pair<int, int>> sp;       for (int i = 1; i <= n; i++) {         par[i] = i, si[i] = 1;         sp.insert(make_pair(g[i].size(), i));       }       vector<int> qp;       while (sp.size()) {         auto p = *sp.begin();         sp.erase(sp.begin());         int ind = *g[p.second].begin();         qp.push_back(ind + 1);         for (int j = 0; j < 3; j++) {           int u = p.second;           int v = ar[ind][j];           if (find(u) != find(v)) {             gr[u].push_back(v);             gr[v].push_back(u);           }           join(u, v);           g[v].erase(ind);           if (g[v].size()) {             sp.insert(make_pair(g[v].size(), v));           }         }         while (sp.size() && sp.begin()->first > g[sp.begin()->second].size()) {           sp.erase(sp.begin());         }       }       for (int i = 1; i <= n; i++) {         if (gr[i].size() == 1 && vis[i] == 0) {           dfs(i);           cout <<   n ;         }       }       for (int i = 0; i < qp.size(); i++) {         cout << qp[i] <<    ;       }       cout <<   n ;       for (int i = 0; i <= n; i++) {         vis[i] = 0, gr[i].clear(), g[i].clear();       }     }   }


#include <bits/stdc++.h>   using namespace std;   int n, fwt[262144];   vector<int> a1, b1, c1, d1, e1, ans;   void add(int x, int k) {     for (; x < 262144; x += x & -x) {       fwt[x] += k;     }   }   int sum(int x) {     int res = 0;     for (; x; x -= x & -x) {       res += fwt[x];     }     return res;   }   int findSidx(int sum) {     int x = 0;     for (int j = 262144 / 2; j; j /= 2) {       if (sum >= fwt[x + j]) {         sum -= fwt[x + j];         x += j;       }     }     return x;   }   vector<int> deB(vector<int>& a) {     memset(fwt, 0, sizeof fwt);     vector<int> res;     for (int i = 0; i < n; ++i) {       add(i + 1, 1);     }     for (int i = 0; i < n; ++i) {       add(a[i] + 1, -1);       res.push_back(sum(a[i] + 1));     }     return res;   }   void makeA() {     memset(fwt, 0, sizeof fwt);     ans.resize(n, 0);     for (int i = 0; i < n; ++i) {       add(i + 1, 1);     }     for (int i = 0; i < n; ++i) {       ans[i] = findSidx(e1[i]);       add(ans[i] + 1, -1);     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n;     a1.resize(n);     b1.resize(n);     e1.resize(n, 0);     for (int i = 0; i < n; ++i) {       cin >> a1[i];     }     for (int j = 0; j < n; ++j) {       cin >> b1[j];     }     c1 = deB(a1), d1 = deB(b1);     for (int i = n - 1; i >= 0; --i) {       e1[i] += c1[i] + d1[i];       if (i) {         e1[i - 1] += e1[i] / (n - i);       }       e1[i] %= (n - i);     }     makeA();     for (int i = 0; i < n; ++i) {       cout << ans[i] <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, temp, i, x = 0, arr[100] = {0};     map<long long, long long> inx;     cin >> n;     for (i = 0; i < n; i++) {       cin >> temp;       inx[temp] = i;     }     for (map<long long int, long long int>::iterator it = inx.begin();          it != inx.end(); ++it) {       arr[it->second] = it->first;     }     cout << inx.size() << endl;     for (i = 0; i < n; i++) {       if (arr[i] != 0) cout << arr[i] <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, ans;   string str;   long long solve() {     cin >> n;     long long v[1001];     for (long long i = 0; i <= n - 1; ++i) {       long long t;       cin >> t;       v[i + 1] = t;     }     for (long long i = 1; i <= n; ++i) {       long long a[n + 1];       for (long long i = 0; i <= n; ++i) a[i] = 0;       a[i]++;       long long t = i;       while (1) {         t = v[t];         a[t]++;         if (a[t] == 2) {           cout << t <<    ;           break;         }       }     }     return 0;   }   signed main() {     ios::sync_with_stdio(0);     long long t = 1;     while (t--) solve();     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   int n1, n2;   int k1, k2;   int main() {     cin >> n1 >> n2 >> k1 >> k2;     if (n1 > n2)       cout <<  First  << endl;     else       cout <<  Second  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char s[500001], t[500001];   long long nt[10000001], n, k, m;   long long c[2];   void kmp(long long x, char a[]) {     int i, j;     for (nt[0] = j = -1, i = 1; i < x; nt[i++] = j) {       while (~j && a[j + 1] != a[i]) j = nt[j];       if (a[j + 1] == a[i]) j++;     }   }   int main() {     scanf( %s , s);     scanf( %s , t);     n = strlen(t);     kmp(n, t);     k = nt[n - 1];     m = strlen(s);     for (int i = 0; i < m; i++) c[s[i] -  0 ]++;     for (int i = 0, j = 0; i < m; i++) {       if (c[0] == 0)         printf( 1 );       else if (c[1] == 0)         printf( 0 );       else {         printf( %c , t[j]);         c[t[j] -  0 ]--;         if (j == n - 1) j = nt[j];         j++;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int n, k, x, m, s;   vector<int> f, t, f1;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n >> k;     for (int i = 0; i < n; i++) {       cin >> x >> m;       f.push_back(x);       t.push_back(m);     }     for (int i = 0; i < n; i++) {       if (t[i] < k) {         f1.push_back(f[i]);       } else {         s = f[i] - (t[i] - k);         f1.push_back(s);       }     }     sort(f1.begin(), f1.end());     cout << f1.back();   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n, k, a[205], b[205];     cin >> n >> k;     for (int i = 1; i <= n; i++) cin >> a[i];     for (int j = 1; j <= k; j++) cin >> b[j];     if (k >= 2) {       cout <<  Yes  << endl;       return 0;     }     if (a[1] == 0) a[1] = b[1];     for (int i = 2; i <= n; i++) {       if (a[i] == 0) a[i] = b[1];       if (a[i] <= a[i - 1]) {         cout <<  Yes  << endl;         return 0;       }     }     cout <<  No  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   void dbg(T a) {}   template <typename T, typename... Arg>   void dbg(T a, Arg... arg) {}   const int maxn = (1e6) + 7;   const int inf = (1e9) + 7;   const long long LLinf = (1e18) + 7;   const long double eps = 1e-9;   const long long mod = 1e9 + 7;   int ile(vector<int> V) {     int res = 0;     while (((int)(V).size()) && V.back() == 0) {       V.pop_back();       res++;     }     if (((int)(V).size()) == 0) return 10000;     return res;   }   int rob(vector<int> V, int a, int b) {     int cnt = 0;     for (int i = 0; i < ((int)(V).size()); i++)       if (V[i] == a) {         for (int j = i - 1; j >= 0; j--) {           swap(V[j], V[j + 1]);           cnt++;         }         break;       }     for (int i = 1; i < ((int)(V).size()); i++)       if (V[i] == b) {         for (int j = i - 1; j > 0; j--) {           swap(V[j], V[j + 1]);           cnt++;         }         break;       }     if (V[0] == a && V[1] == b)       return cnt + ile(V);     else       return 1000;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n;     cin >> n;     vector<int> V;     while (n > 0) {       V.push_back(n % 10);       n /= 10LL;     }     int res = 1000;     res = min(res, rob(V, 0, 0));     res = min(res, rob(V, 5, 2));     res = min(res, rob(V, 0, 5));     res = min(res, rob(V, 5, 7));     if (res < 100)       cout << res;     else       cout <<  -1 ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 2e6 + 5, inf = 1e9 + 7;   long long n, k, cumm[N], m[26];   set<pair<long long, long long> > st;   string s;   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     long long i, j, a, b, ans = 1;     cin >> n >> k >> s;     s =  #  + s;     for (i = 0; i < k; i++) st.insert(pair<long long, long long>(m[i], i));     for (i = 1; i < n + s.size(); i++) {       if (i < s.size())         a = s[i] -  a ;       else         a = st.begin()->second;       st.erase(st.find(pair<long long, long long>(m[a], a)));       if (m[a])         cumm[i] = cumm[i - 1] - cumm[m[a] - 1];       else         cumm[i] = cumm[i - 1] + 1;       m[a] = i;       st.insert(pair<long long, long long>(m[a], a));       cumm[i] = (cumm[i] % inf + cumm[i - 1] + inf) % inf;     }     cout << (cumm[i - 1] + 1) % inf;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 3007;   const int M = 998244353;   int n, m, dp[N][N];   string s, t;   bool matches(int i, char c) {     if (i > m)       return true;     else       return t[i - 1] == c;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> s >> t;     n = s.size();     m = t.size();     for (int i = 1; i <= n + 1; i++) dp[i][i - 1] = 1;     for (int d = 1; d <= n; d++) {       char c = s[d - 1];       for (int i = 1, j = d; j <= n; i++, j++) {         if (matches(i, c)) {           dp[i][j] = (dp[i][j] + dp[i + 1][j]) % M;         }         if (matches(j, c)) {           dp[i][j] = (dp[i][j] + dp[i][j - 1]) % M;         }       }     }     int ans = 0;     for (int i = m; i <= n; i++) {       ans = (ans + dp[1][i]) % M;     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   char ans[100];   int n;   int main() {     scanf( %s%d , ans, &n);     for (int i = 0; i < strlen(ans); i++) {       if (ans[i] <  a ) ans[i] +=  a  -  A ;       if (ans[i] < 97 + n) ans[i] +=  A  -  a ;     }     printf( %s n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int t;     cin >> t;     while (t--) {       int a[3];       cin >> a[0] >> a[1] >> a[2];       sort(a, a + 3);       if (a[0] + a[1] >= a[2] - 1) {         cout <<  Yes n ;       } else         cout <<  No n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   void sf(T &res) {     int f = 1;     char c;     res = 0;     while (c = getchar(), !isdigit(c))       ;     if (c ==  - ) f = -1, c = getchar();     do res = (res << 1) + (res << 3) + (c ^ 48);     while (c = getchar(), isdigit(c));     res *= f;   }   long long h, q, L, R, pos, ANS;   struct node {     long long l, r;     bool operator<(const node &a) const {       if (l != a.l) return l < a.l;       return r < a.r;     }   };   vector<node> v;   int main() {     sf(h), sf(q);     L = 1ll << (h - 1);     R = (1ll << h) - 1;     while (q--) {       long long l, r;       int f, ans;       sf(f), sf(l), sf(r), sf(ans);       for (int j = f; j < h; j++) l *= 2, r = r * 2 + 1;       if (ans) {         if (L <= l - 1) v.push_back((node){L, l - 1});         if (r + 1 <= R) v.push_back((node){r + 1, R});       } else         v.push_back((node){l, r});     }     pos = L, ANS = -1;     v.push_back((node){R + 1, R + 1});     sort(v.begin(), v.end());     for (int i = 0; i < v.size(); i++) {       long long x = v[i].l, y = v[i].r;       if (x > pos) {         if (x - pos == 1) {           if (ANS == -1)             ANS = pos;           else {             puts( Data not sufficient! );             return 0;           }         } else {           puts( Data not sufficient! );           return 0;         }       }       pos = max(pos, y + 1);     }     if (ANS == -1)       puts( Game cheated! );     else       cout << ANS << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   set<pair<char, char> > V;   char R[18][18], S[18][18];   int main(void) {     int n, m;     cin >> n >> m;     bool test1 = (n >= 6 && m >= 3) || (n >= 3 && m >= 6);     if (test1 == false) {       cout <<  No solution.  << endl;       return 0;     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         string w;         cin >> w;         R[i][j] = w[0];         S[i][j] = w[1];         V.insert(pair<char, char>(R[i][j], S[i][j]));       }     }     set<pair<char, char> > Q;     char TR[13] = { 2 ,  3 ,  4 ,  5 ,  6 ,  7 ,  8 ,                     9 ,  T ,  J ,  Q ,  K ,  A };     char TS[4] = { C ,  D ,  H ,  S };     for (int i = 0; i < 4; i++) {       for (int j = 0; j < 13; j++) {         if (V.find(pair<char, char>(TR[j], TS[i])) == V.end()) {           Q.insert(pair<char, char>(TR[j], TS[i]));         }       }     }     int jk1r, jk1c, jk2r, jk2c;     jk1r = jk1c = jk2r = jk2c = -1;     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) {         if (R[i][j] ==  J  && S[i][j] ==  1 ) {           jk1r = i;           jk1c = j;         } else if (R[i][j] ==  J  && S[i][j] ==  2 ) {           jk2r = i;           jk2c = j;         }       }     for (int r1 = 0; r1 + 2 < n; r1++)       for (int c1 = 0; c1 + 2 < m; c1++) {         for (int r2 = 0; r2 + 2 < n; r2++)           for (int c2 = 0; c2 + 2 < m; c2++) {             bool test2 = (r2 <= r1 + 2) && (r1 <= r2 + 2) && (c2 <= c1 + 2) &&                          (c1 <= c2 + 2);             if (test2) continue;             for (int jr1 = 0; jr1 < 13; jr1++)               for (int js1 = 0; js1 < 4; js1++) {                 for (int jr2 = 0; jr2 < 13; jr2++)                   for (int js2 = 0; js2 < 4; js2++) {                     char cr1 = TR[jr1], cr2 = TR[jr2], cs1 = TS[js1],                          cs2 = TS[js2];                     if (jr1 == jr2 && js1 == js2) continue;                     if (Q.find(pair<char, char>(cr1, cs1)) == Q.end() ||                         Q.find(pair<char, char>(cr2, cs2)) == Q.end())                       continue;                     if (jk1r != -1) {                       R[jk1r][jk1c] = cr1;                       S[jk1r][jk1c] = cs1;                     }                     if (jk2r != -1) {                       R[jk2r][jk2c] = cr2;                       S[jk2r][jk2c] = cs2;                     }                     bool ok1 = true;                     for (int i = 0; i < 3; i++)                       for (int j = 0; j < 3; j++) {                         if (S[r1][c1] != S[r1 + i][c1 + j]) {                           ok1 = false;                           break;                         }                       }                     bool ok2 = true;                     bool used2[256];                     memset(used2, false, sizeof(used2));                     for (int i = 0; i < 3; i++)                       for (int j = 0; j < 3; j++) {                         if (used2[(int)R[r1 + i][c1 + j]]) {                           ok2 = false;                           break;                         }                         used2[(int)R[r1 + i][c1 + j]] = true;                       }                     bool ok3 = true;                     for (int i = 0; i < 3; i++)                       for (int j = 0; j < 3; j++) {                         if (S[r2][c2] != S[r2 + i][c2 + j]) {                           ok3 = false;                           break;                         }                       }                     bool ok4 = true;                     bool used4[256];                     memset(used4, false, sizeof(used4));                     for (int i = 0; i < 3; i++)                       for (int j = 0; j < 3; j++) {                         if (used4[(int)R[r2 + i][c2 + j]]) {                           ok4 = false;                           break;                         }                         used4[(int)R[r2 + i][c2 + j]] = true;                       }                     if ((ok1 || ok2) && (ok3 || ok4)) {                       cout <<  Solution exists.  << endl;                       if (jk1r == -1 && jk2r == -1) {                         cout <<  There are no jokers.  << endl;                       } else if (jk1r != -1 && jk2r != -1) {                         cout <<  Replace J1 with   << R[jk1r][jk1c]                              << S[jk1r][jk1c] <<   and  ;                         cout <<  J2 with   << R[jk2r][jk2c] << S[jk2r][jk2c]                              <<  .  << endl;                       } else if (jk1r != -1) {                         cout <<  Replace J1 with   << R[jk1r][jk1c]                              << S[jk1r][jk1c] <<  .  << endl;                       } else if (jk2r != -1) {                         cout <<  Replace J2 with   << R[jk2r][jk2c]                              << S[jk2r][jk2c] <<  .  << endl;                       }                       cout <<  Put the first square to (  << r1 + 1 <<  ,                              << c1 + 1 <<  ).  << endl;                       cout <<  Put the second square to (  << r2 + 1 <<  ,                              << c2 + 1 <<  ).  << endl;                       return 0;                     }                   }               }           }       }     cout <<  No solution.  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string a, b;   int main() {     cin >> a >> b;     if (a == b) {       cout << a << endl;       return 0;     } else {       cout << 1 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   bool gmin(T& a, const T& b) {     return b < a ? a = b, 1 : 0;   }   template <class T>   bool gmax(T& a, const T& b) {     return a < b ? a = b, 1 : 0;   }   const long long N = 110;   const long long K = 100010;   const long long INF = 1e12;   long long a[N], b[N], dp[N][2 * K];   long long n, k;   long long Rec(long long idx, long long sum) {     if (idx == n) {       return sum ? -INF : 0;     }     long long& ans = dp[idx][sum + K];     if (ans + 1) return ans;     ans = -INF;     gmax(ans, Rec(idx + 1, sum));     gmax(ans, a[idx] + Rec(idx + 1, sum + a[idx] - b[idx]));     return ans;   }   void solve() {     cin >> n >> k;     for (long long i = 0; i < (n); i++) cin >> a[i];     for (long long i = 0; i < (n); i++) cin >> b[i];     for (long long i = 0; i < (n); i++) b[i] *= k;     memset(dp, (long long)(-1), sizeof(dp));     long long Ans = Rec(0, 0);     cout << (Ans <= 0 ? -1 : Ans) <<   n ;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long t = 1;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   bool check(string a) {     bool flag = true;     for (int i = 1; i <= a.size(); i++)       if (abs(a[i] - a[i - 1]) == 1) flag = false;     return flag;   }   int main() {     int T;     cin >> T;     while (T--) {       string s, one, two;       cin >> s;       for (int i = 0; i < s.size(); i++)         if (s[i] % 2)           one += s[i];         else           two += s[i];       sort(one.begin(), one.end());       sort(two.begin(), two.end());       if (check(one + two))         cout << one + two <<   n ;       else if (check(two + one))         cout << two + one <<   n ;       else         cout <<  No answer n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, t, k, x;   string s;   int main() {     cin >> s;     n = s.size();     for (int k = 0;; k++) {       if (s[k] ==  . ) {         t = k;         break;       }     }     if (s[t - 1] == 9 +  0 )       cout <<  GOTO Vasilisa. ;     else if (s[t + 1] < 5 +  0 ) {       for (int i = 0; i < t; i++) cout << s[i];     } else if (s[t + 1] >= 5 +  0 ) {       for (int i = 0; i < t - 1; i++) cout << s[i];       cout << s[t - 1] -  0  + 1;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int adj[8][2] = {{-1, 0},  {0, -1}, {1, 0}, {0, 1},                          {-1, -1}, {-1, 1}, {1, 1}, {1, -1}};   const long long int LLINF = 9e18;   const int INF = 2e9;   const int MOD = 1e9 + 7;   const double EPS = 1e-10;   const double PI = acos(-1);   const int SIZE = 200005;   int N;   long long int A[SIZE];   int cnt[SIZE], pos[SIZE];   vector<pair<int, pair<int, int> > > ans;   int main() {     scanf( %d , &N);     for (int i = 1; i <= N; i++) {       scanf( %lld , &A[i]);       cnt[A[i]]++;       pos[A[i]] = i;     }     int num, Mx = 0, idx;     for (int i = 0; i < SIZE; i++) {       if (Mx < cnt[i]) {         num = i;         Mx = cnt[i];         idx = pos[i];       }     }     for (int i = idx; i <= N; i++) {       if (num < A[i]) {         ans.push_back(make_pair(2, make_pair(i, i - 1)));       } else if (num > A[i]) {         ans.push_back(make_pair(1, make_pair(i, i - 1)));       }     }     for (int i = idx; i >= 1; i--) {       if (num < A[i]) {         ans.push_back(make_pair(2, make_pair(i, i + 1)));       } else if (num > A[i]) {         ans.push_back(make_pair(1, make_pair(i, i + 1)));       }     }     int n = ans.size();     printf( %d n , n);     for (int i = 0; i < n; i++) {       printf( %d %d %d n , ans[i].first, ans[i].second.first,              ans[i].second.second);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, a, b, da, db;   vector<long long> v[100005];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     long long t;     cin >> t;     while (t--) {       cin >> n >> a >> b >> da >> db;       for (long long i = 0; i < n + 2; i++) v[i].clear();       for (long long i = 0; i < n - 1; i++) {         long long x, y;         cin >> x >> y;         v[x].push_back(y);         v[y].push_back(x);       }       long long vis[n + 1];       memset(vis, 0, sizeof(vis));       vis[a] = 1;       queue<long long> q;       q.push(a);       long long dis[n + 1];       dis[a] = 0;       while (!q.empty()) {         long long u = q.front();         q.pop();         for (auto it : v[u]) {           if (!vis[it]) {             dis[it] = dis[u] + 1;             vis[it] = 1;             q.push(it);           }         }       }       if (db <= 2 * da || dis[b] <= da) {         cout <<  Alice n ;         continue;       }       dis[b] = 0;       memset(vis, 0, sizeof(vis));       vis[b] = 1;       q.push(b);       while (!q.empty()) {         long long u = q.front();         q.pop();         for (auto it : v[u]) {           if (!vis[it]) {             dis[it] = dis[u] + 1;             vis[it] = 1;             q.push(it);           }         }       }       long long node, maxi = 0;       for (long long i = 1; i <= n; i++) {         if (dis[i] > maxi) {           maxi = dis[i];           node = i;         }       }       dis[node] = 0;       memset(vis, 0, sizeof(vis));       vis[node] = 1;       q.push(node);       while (!q.empty()) {         long long u = q.front();         q.pop();         for (auto it : v[u]) {           if (!vis[it]) {             dis[it] = dis[u] + 1;             vis[it] = 1;             q.push(it);           }         }       }       maxi = 0;       for (long long i = 1; i <= n; i++) {         if (dis[i] > maxi) {           maxi = dis[i];         }       }       if (maxi > 2 * da) {         cout <<  Bob n ;       } else         cout <<  Alice n ;     }   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) {     long long r;     while (b != 0) {       r = a % b;       a = b;       b = r;     }     return a;   }   long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }   int const nmax = 1010;   int k, n;   vector<pair<int, int> > st, pe;   vector<int> ans[nmax];   bool dc[nmax];   long double p[nmax];   void solve() {     memset(dc, 0, sizeof(dc));     cin >> k >> n;     for (int i = 0; i < k; i++) {       int c, t;       cin >> c >> t;       p[i] = c;       if (t == 1)         st.push_back(pair<int, int>(c, i));       else         pe.push_back(pair<int, int>(c, i));     }     sort(st.begin(), st.end());     sort(pe.begin(), pe.end());     int k = 0;     while (!st.empty()) {       if (k >= n) k = n - 1;       dc[k] = 1;       ans[k].push_back(st.back().second);       st.pop_back();       k++;     }     for (int i = n - 1; i >= 0; i--) {       if (int((ans[i]).size()) > 0) break;       ans[i].push_back(pe.front().second);       pe.erase(pe.begin());     }     while (!pe.empty()) {       if (k >= n) k = n - 1;       ans[k].push_back(pe.back().second);       pe.pop_back();       k++;     }     long double sum = 0;     for (int i = 0; i < n; i++) {       long double m = INT_MAX;       for (int j = 0; j < int((ans[i]).size()); j++) {         int k = ans[i][j];         sum += p[k];         m = ((m) > (p[k]) ? (p[k]) : (m));       }       if (dc[i]) sum -= m / 2;     }     cout << fixed << setprecision(1) << sum <<   n ;     for (int i = 0; i < n; i++) {       cout << int((ans[i]).size()) <<    ;       for (int j = 0; j < int((ans[i]).size()); j++) cout << ans[i][j] + 1 <<    ;       cout <<   n ;     }   }   int main() {     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 9;   int n, q, c[N];   void modify(int x, int v) {     if (x == 0) return;     for (int i = x; i <= n; i += i & -i) c[i] += v;   }   int query(int x) {     int s = 0;     for (int i = x; i >= 1; i -= i & -i) s += c[i];     return s;   }   void work(int a, int b, bool le) {     for (int i = a; i <= b; ++i) {       int t = query(i) - query(i - 1);       modify(i, -t);       if (le) {         modify(a - (i - a + 1), t);       } else         modify(b + (b - i + 1), t);     }   }   int L, R;   int get(int x) {     if (L <= R)       return x + L - 1;     else       return L + 1 - x;   }   int len() { return abs(L - R) + 1; }   int main() {     scanf( %d%d , &n, &q);     L = 1, R = n;     for (int i = 1; i <= n; ++i) modify(i, 1);     while (q--) {       int cmd, p, l, r;       scanf( %d , &cmd);       if (cmd == 1) {         scanf( %d , &p);         if (L <= R) {           if (p > len() - p) {             work(get(p + 1), R, 1);             R = get(p);             swap(L, R);           } else {             work(get(1), get(p), 0);             L = get(p + 1);           }         } else {           if (p > len() - p) {             work(R, get(p + 1), 0);             R = get(p);             swap(L, R);           } else {             work(get(p), get(1), 1);             L = get(p + 1);           }         }       } else {         scanf( %d%d , &l, &r);         l++;         l = get(l), r = get(r);         if (l > r) swap(l, r);         int s = query(r) - query(l - 1);         printf( %d n , s);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     string aux =  CODEFORCES ;     int i = 0;     cin >> s;     if (s.length() < aux.length())       cout <<  NO  << endl;     else {       while (aux[i] == s[i] && i < aux.length()) i++;       if (i == aux.length())         cout <<  YES  << endl;       else {         int j;         for (j = i; j < aux.length(); j++) {           if (aux[j] != s[s.length() - aux.length() + j]) break;         }         if (j == aux.length())           cout <<  YES  << endl;         else           cout <<  NO  << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n, k;       cin >> n >> k;       if (n < k)         cout << k - n << endl;       else {         if ((n & 1) == (k & 1))           cout << 0 << endl;         else           cout << 1 << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 5;   int n, m;   int a[maxn], b[maxn];   int main() {     cin >> n >> m;     m--;     for (int i = 0; i < n; i++) {       cin >> a[i];     }     for (int i = 0; i < n; i++) {       cin >> b[i];     }     if (a[0] == 0) {       cout <<  NO ;       return 0;     }     if (b[m] == 0 && a[m] == 0) {       cout <<  NO ;       return 0;     }     if (a[m] != 0) {       cout <<  YES ;       return 0;     }     for (int i = m; i < n; i++) {       if (b[i] == 1 && a[i] == 1) {         cout <<  YES ;         return 0;       }     }     cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   int main() {     char a[110], b[110];     scanf( %s%s , a, b);     if (strcmp(a, b) == 0)       printf( %s n , a);     else       printf( 1 n );   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 5;   const int dir[8][2] = {{0, 1},  {1, 1},   {1, 0},  {1, -1},                          {0, -1}, {-1, -1}, {-1, 0}, {-1, 1}};   const int dir8x[8] = {-1, -1, -1, 0, 0, 1, 1, 1};   const int dir8y[8] = {-1, 0, 1, 1, -1, -1, 0, 1};   const long long mod = 1e9 + 7;   const double PI = acos(-1.0);   long long po(long long a, long long b, long long mod) {     long long res = 1;     a %= mod;     for (; b; b >>= 1) {       if (b & 1) res = res * a % mod;       a = a * a % mod;     }     return res;   }   long long gcd(long long a, long long b) {     if (a == 0) {       return b;     } else {       return gcd(b % a, a);     }   }   int n;   long long val[maxn], dp[maxn];   void solve() {     scanf( %d , &(n));     for (int i = 1; i <= n; i++) {       scanf( %lld , &val[i]);     }     int last = 1;     for (int i = 2; i <= n; i++) {       dp[i] = max(dp[last - 1] + labs(val[i] - val[last]),                   dp[last] + labs(val[i] - val[last + 1]));       if (val[i] <= val[i + 1] && val[i] <= val[i - 1]) {         last = i;       }       if (val[i] >= val[i + 1] && val[i] >= val[i - 1]) {         last = i;       }     }     long long res = dp[n];     printf( %lld , res);   }   int main() {     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       unsigned long long int mino = LONG_MAX;       unsigned long long int minc = LONG_MAX;       unsigned long long int ans = 0;       unsigned long long int n;       cin >> n;       unsigned long long int o[n], c[n];       for (unsigned long long int i = 0; i < n; i++) {         unsigned long long int ora;         cin >> ora;         o[i] = ora;         if (ora < mino) {           mino = ora;         }       }       for (unsigned long long int i = 0; i < n; i++) {         unsigned long long int ca;         cin >> ca;         c[i] = ca;         if (ca < minc) {           minc = ca;         }       }       for (unsigned long long int i = 0; i < n; i++) {         unsigned long long int w = min(o[i] - mino, c[i] - minc);         ans = ans + w;         o[i] = o[i] - w;         c[i] = c[i] - w;         if (o[i] == mino) {           ans = ans + c[i] - minc;         } else {           ans = ans + o[i] - mino;         }       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> split(string s) {     vector<int> xs;     stringstream ss(s);     string item;     while (getline(ss, item,  , )) {       xs.push_back(stoi(item));     }     return xs;   }   int main() {     string s;     getline(cin, s);     vector<int> xxs = split(s);     sort(xxs.begin(), xxs.end());     vector<pair<int, int>> sol;     for (int i = 0; i < xxs.size(); i++) {       int st = xxs[i];       int e = st;       while (i < xxs.size() - 1 && (e + 1 == xxs[i + 1] || e == xxs[i + 1])) {         e = xxs[i + 1];         i++;       }       sol.push_back(make_pair(st, e));     }     for (int i = 0; i < sol.size(); i++) {       if (sol[i].first != sol[i].second) {         cout << sol[i].first <<  -  << sol[i].second;       } else {         cout << sol[i].first;       }       if (i != sol.size() - 1) {         cout <<  , ;       }     }     return 0;   }


#include <bits/stdc++.h>   const int kMaxN = 5000;   std::vector<int> way[kMaxN], cost[kMaxN];   int f[kMaxN], c[kMaxN];   short hash[kMaxN][kMaxN], father[kMaxN][2 * kMaxN];   int a[kMaxN], id[kMaxN], t[kMaxN];   inline bool cmp(int x, int y) { return a[x] < a[y]; }   void BuildTree(int u, int ff) {     f[u] = ff;     for (size_t i = 0; i < way[u].size(); ++i) {       int v = way[u][i];       if (v == ff) continue;       c[v] = cost[u][i];       BuildTree(v, u);     }   }   int Find(short *f, int x) {     int y = x, z;     while (f[y] != -1) y = f[y];     while (x != y) {       z = x;       x = f[x];       f[z] = y;     }     return y;   }   int Put(int x) {     int t = 0;     while (x != 0) {       ++t;       if (f[x] == 0) return t;       int ff = f[x];       t = Find(father[ff], t);       if (++hash[ff][t] == c[ff]) {         father[ff][t] = t + 1;       }       x = ff;     }     return 0;   }   int main() {     int n, x, y, cc;     scanf( %d , &n);     for (int i = 0; i < n; ++i) {       scanf( %d , a + i);       id[i] = i;     }     std::sort(id, id + n, cmp);     for (int j = 1; j < n; ++j) {       scanf( %d%d%d , &x, &y, &cc);       --x;       --y;       way[x].push_back(y);       way[y].push_back(x);       cost[x].push_back(cc);       cost[y].push_back(cc);     }     BuildTree(0, -1);     memset(father, -1, sizeof(father));     for (int i = 0; i < n; ++i) {       t[id[i]] = Put(id[i]);     }     for (int i = 0; i < n; ++i) {       if (i != 0) printf(   );       printf( %d , t[i]);     }     puts(  );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool isthere(string s1, string s2);   int main() {     int t;     cin >> t;     for (int i = 0; i < t; i++) {       string s1, s2;       cin >> s1 >> s2;       if (s2.size() == s1.size()) {         if (isthere(s1, s2)) {           cout <<  YES  << endl;         } else {           cout <<  NO  << endl;         }         continue;       }       if (s2.size() < s1.size()) {         cout <<  NO  << endl;         continue;       }       bool y = 0;       for (int i = 0; i <= (s2.size() - s1.size()); i++) {         string s = s2.substr(i, s1.size());         if (isthere(s1, s)) {           cout <<  YES  << endl;           y = 1;           break;         }       }       if (y == 0) {         cout <<  NO  << endl;       }     }     return 0;   }   bool isthere(string s1, string s2) {     sort(s1.begin(), s1.end());     sort(s2.begin(), s2.end());     if (s1.compare(s2) == 0) {       return true;     }     return false;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0), cin.tie(0);     char lowestChar =  z  + 1;     string s;     cin >> s;     vector<int> ans(s.size(), 0);     for (int i = 0; i < s.size(); ++i) {       char c = s[i];       if (c < lowestChar) {         ans[i] = 1;         lowestChar = c;       } else if (c == lowestChar) {         ans[i - 1] ^= 1;         ans[i] = 1;       }     }     for (auto& x : ans) cout << x <<    ;     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> bomb[5005];   int n, m, st_time[5005], sol[5005], dist_min[5005];   int main() {     cin >> n >> m;     for (int i = 1; i <= n; ++i) dist_min[i] = 2 * 5005;     int pos, val;     for (int i = 1; i <= m; ++i) {       cin >> pos >> val;       bomb[pos].push_back(val);       int comp = 0;       if (val >= pos)         comp = val - pos;       else         comp = n - (pos - val);       if (val != pos) dist_min[pos] = min(dist_min[pos], comp);     }     for (int i = 1; i <= n; ++i) {       int blen = bomb[i].size();       if (blen)         st_time[i] = n * (blen - 1) + dist_min[i];       else         st_time[i] = 0;     }     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= n; ++j)         if (!bomb[j].empty()) {           if (j < i)             sol[i] = max(sol[i], n - (i - j) + st_time[j]);           else             sol[i] = max(sol[i], j - i + st_time[j]);         }       cout << sol[i] <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t, n;     cin >> t;     string s;     for (int i = 0; i < t; i++) {       cin >> n;       cin >> s;       int k = 0;       if (n % 2 == 0) {         for (int i = 1; i < n; i += 2)           if ((int(s[i]) - 48) % 2 == 0) {             k = 1;             cout << 2 <<   n ;             break;           }         if (k == 0) cout << 1 <<   n ;       }       if (n % 2 == 1) {         for (int i = 0; i < n; i += 2)           if ((int(s[i]) - 48) % 2 == 1) {             k = 1;             cout << 1 <<   n ;             break;           }         if (k == 0) cout << 2 <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, x, y, num[100005], res, a[100005], b[100005];   bool vis[100005];   vector<int> v[100005];   void dfs(long long now, long long pre) {     for (long long i = 0; i < v[now].size(); i++) {       int j = v[now][i];       if (j != pre) {         dfs(j, now);         a[now] = max(a[now], a[j]);         b[now] = max(b[now], b[j]);       }     }     num[now] += a[now];     num[now] -= b[now];     if (num[now] < 0)       a[now] += -num[now];     else       b[now] += num[now];   }   int main() {     cin >> n;     for (long long i = 0; i < n - 1; i++) {       cin >> x >> y;       v[x].push_back(y);       v[y].push_back(x);     }     for (long long i = 1; i <= n; i++) cin >> num[i];     dfs(1, -1);     res = a[1] + b[1];     cout << res <<   n ;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC target( sse4,avx )   const int p = 1000000007;   int mul32(int x, int y) { return int(int64_t(x) * y % p); }   int add32(int x, int y) {     int res = x + y;     if (res >= p) res -= p;     return res;   }   int sub32(int x, int y) {     int res = x - y;     if (res < 0) res += p;     return res;   }   void run(std::istream &in, std::ostream &out) {     int n;     in >> n;     std::vector<int> xs(n);     for (int i = 0; i < n; i++) {       in >> xs[i];     }     std::sort(xs.begin(), xs.end());     std::vector<int> pow2(n + 1);     pow2[0] = 1;     for (int i = 1; i <= n; i++) {       pow2[i] = (pow2[i - 1] * 2) % p;     }     int res = 0;     for (int i = 0; i < n; i++) {       res = add32(res, mul32(xs[i], pow2[i]));       res = sub32(res, mul32(xs[i], pow2[n - i - 1]));     }     out << res << std::endl;   }   int main() {     std::cin.sync_with_stdio(false);     std::cin.tie(nullptr);     run(std::cin, std::cout);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int Get() {     char c;     while (c = getchar(), c <  0  || c >  9 )       ;     int X = 0;     while (c >=  0  && c <=  9 ) {       X = X * 10 + c - 48;       c = getchar();     }     return X;   }   const int inf = 1000000000;   int GCD(int a, int b) { return b ? GCD(b, a % b) : a; }   int Solve(int a, int b, int c) {     return a ? ((c - b * Solve(b % a, a, c % a)) / a) : 0;   }   int GetMin(int L, int R, int a, int b, int c) {     if (L > R) return -1;     int K = GCD(a, b);     if (c % K) return -1;     a /= K;     b /= K;     c /= K;     int X = Solve(a, b, c);     if (X < L) X += ((L - X - 1) / b + 1) * b;     if (X > L) X -= (X - L) / b * b;     return (X <= R) ? X : -1;   }   int GetMax(int L, int R, int a, int b, int c) {     if (L > R) return -1;     int K = GCD(a, b);     if (c % K) return -1;     a /= K;     b /= K;     c /= K;     int X = Solve(a, b, c);     if (X > R) X -= ((X - R - 1) / b + 1) * b;     if (X < R) X += (R - X) / b * b;     return (X >= L) ? X : -1;   }   int main() {     int N = Get(), S = Get(), a = 0, b = 0, c = 0;     while (N--) {       int X = Get();       if (X == 3) a++;       if (X == 4) b++;       if (X == 5) c++;     }     int Ans = inf, Ans_x, Ans_y;     for (int y = 0; b * y <= S; y++) {       int B = b * y, _S = S - B, Max = min(y, (_S - c * y) / a), x;       x = GetMin((_S - B - 1) / a + 1, min(Max, B / a), a, c, _S);       if (x != -1 && 2 * B - _S < Ans) {         Ans = 2 * B - _S;         Ans_x = x;         Ans_y = y;       }       x = GetMax(0, min(Max, min(B, _S - B) / a), a, c, _S);       if (x != -1 && _S - 2 * a * x < Ans) {         Ans = _S - 2 * a * x;         Ans_x = x;         Ans_y = y;       }       x = GetMin((max(B, _S - B) - 1) / a + 1, Max, a, c, _S);       if (x != -1 && 2 * a * x - _S < Ans) {         Ans = 2 * a * x - _S;         Ans_x = x;         Ans_y = y;       }       x = GetMin((B - 1) / a + 1, min(Max, (_S - B) / a), a, c, _S);       if (x != -1 && _S - 2 * B < Ans) {         Ans = _S - 2 * B;         Ans_x = x;         Ans_y = y;       }     }     if (Ans == inf)       printf( -1 n );     else       printf( %d %d %d n , Ans_x, Ans_y, (S - a * Ans_x - b * Ans_y) / c);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long grundy[1234];   int main() {     long long idx = 1, i, j;     for (i = 1; i <= 15; i++) {       for (j = 1; j <= (i + 1); j++) {         grundy[idx] = i;         idx++;       }     }     long long n;     cin >> n;     long long ans = 0;     while (n--) {       long long va;       cin >> va;       ans = ans ^ grundy[va];     }     cout << ((ans == 0) ?  YES  :  NO );   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c, d, e;     scanf( %d%d%d%d%d , &a, &b, &c, &d, &e);     if ((a + b + c + d + e) % 5 == 0 && a + b + c + d + e >= 5)       printf( %d n , (a + b + c + d + e) / 5);     else       printf( -1 n );   }


#include <bits/stdc++.h>   using namespace std;   long long n, a[100005], b[100005], fa[100005], s[100005], q[100005], l,       p = -2147483647;   inline long long find(long long x) {     if (x == fa[x]) return x;     return fa[x] = find(fa[x]);   }   inline long long M(long long u, long long v) { return u > v ? u : v; }   int main() {     scanf( %lld , &n);     for (long long i = 1; i <= n; i++) scanf( %lld , &a[i]);     for (long long i = 1; i <= n; i++) scanf( %lld , &b[i]);     for (long long i = n; i >= 1; i--) {       long long k = b[i];       if (!fa[k]) fa[k] = k, s[k] = a[k];       long long fk = find(k);       if (fa[k - 1] && k - 1 > 0) {         long long fl = find(k - 1);         if (fk != fl) s[k] += s[fl], s[fl] = 0, fa[fl] = k;       }       if (fa[k + 1] && k + 1 <= n) {         long long fr = find(k + 1);         if (fk != fr) s[k] += s[fr], s[fr] = 0, fa[fr] = k;       }       p = M(p, s[k]), q[++l] = p;     }     for (long long i = n - 1; i >= 0; i--) printf( %lld n , q[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int h, w, i, j, mod = 1e9 + 7, r, c, ans = 1, a[1001][1001];   int main() {     cin.tie(NULL);     ios_base::sync_with_stdio(0);     cin >> h >> w;     for (i = 0; i < h; i++) {       cin >> r;       for (j = 0; j < r; j++) a[i][j] = 2;       a[i][r] = 1;     }     for (i = 0; i < w; i++) {       cin >> c;       for (j = 0; j < c; j++)         if (a[j][i] == 1) {           cout << 0 << endl;           return 0;         } else           a[j][i] = 2;       if (a[c][i] == 2) {         cout << 0 << endl;         return 0;       }       a[c][i] = 1;     }     for (i = 0; i < h; i++)       for (j = 0; j < w; j++)         if (!a[i][j]) ans = (ans * 2) % mod;     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> v[200010], circle;   int fa[200010], dep[200010], a[200010], b[200010], n, rt, vs, vt, h1, h2;   bool vis[200010], bo[200010];   inline int rd() {     int x = 0;     char ch = getchar();     for (; ch <  0  || ch >  9 ; ch = getchar())       ;     for (; ch >=  0  && ch <=  9 ; ch = getchar()) x = x * 10 + ch -  0 ;     return x;   }   inline void dfs(int x) {     for (int i = 0, siz = v[x].size(); i < siz; i++) {       int t = v[x][i];       if (t == fa[x]) continue;       dep[t] = dep[x] + 1;       fa[t] = x;       dfs(t);     }   }   inline bool gao() {     int p = 0, q = 0;     bool flag = true;     for (int i = 1; i <= n; i++)       if (a[i] != b[i] && dep[i] > dep[p]) p = i;     if (!p) return true;     for (int hh = p; a[hh] != b[hh]; hh = fa[hh])       bo[hh] = true, circle.push_back(hh);     for (int i = 1; i <= n; i++)       if (a[i] != b[i] && !bo[i] && dep[i] > dep[q]) q = i;     if (q) {       reverse(circle.begin(), circle.end());       flag = false;       for (int hh = q; a[hh] != b[hh]; hh = fa[hh])         bo[hh] = true, circle.push_back(hh);     } else       q = fa[circle.back()];     for (int i = 1; i <= n; i++)       if (a[i] != b[i] && !bo[i]) return false;     int h1 = p, h2 = q;     for (; h1 != h2; h1 = fa[h1])       if (dep[h1] < dep[h2]) swap(h1, h2);     rt = h1;     if (circle.size() != dep[p] + dep[q] - dep[rt] * 2) return false;     vs = p;     vt = q;     if (flag) reverse(circle.begin(), circle.end());     return true;   }   int main() {     n = rd();     for (int i = 1; i <= n; i++)       if (!(a[i] = rd())) h1 = i;     for (int i = 1; i <= n; i++)       if (!(b[i] = rd())) h2 = i;     for (int i = 1; i < n; i++) {       int x = rd(), y = rd();       v[x].push_back(y);       v[y].push_back(x);     }     dep[0] = -1;     dfs(h2);     for (int hh = h1; hh != h2; hh = fa[hh]) swap(a[hh], a[fa[hh]]);     long long ans = dep[h1];     if (!gao()) {       puts( -1 );       return 0;     }     if (!circle.size()) {       printf( 0 %d n , ans);       return 0;     }     for (int i = h1; i; i = fa[i]) vis[i] = true;     if (vis[circle.back()] && !vis[circle[0]])       reverse(circle.begin(), circle.end());     int gap = 0, siz = circle.size();     for (int i = 0; i < siz; i++)       if (b[circle[i]] == a[circle[0]]) gap = i;     for (int i = 0; i < siz; i++)       if (b[circle[(i + gap) % siz]] != a[circle[i]]) {         puts( -1 );         return 0;       }     if (vis[circle[0]] || vis[circle.back()]) {       int now = siz;       for (int i = 0; i < siz; i++)         if (!vis[circle[i]]) {           now = i;           break;         }       ans = ans - now +             min((long long)gap * (siz + 1) + now,                 abs((long long)(siz - gap) * (siz + 1) - now));     } else       ans = (ans + (long long)min(gap, siz - gap) * (siz + 1));     for (; !vis[rt]; rt = fa[rt]) ans += 2;     if (vs > vt) swap(vs, vt);     printf( %d %d %I64d n , vs, vt, ans);     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   using namespace std;   using i64 = long long;   using i32 = int;   using f64 = long double;   template <class Key>   using vec = vector<Key>;   template <class Key>   using heap = priority_queue<Key>;   template <class Key>   using hash_set = unordered_set<Key>;   template <class Key, class Value>   using hash_map = unordered_map<Key, Value>;   using str = string;   template <size_t Size1>   using a64 = array<i64, Size1>;   template <size_t Size1, size_t Size2>   using aa64 = array<a64<Size2>, Size1>;   template <size_t Size1, size_t Size2, size_t Size3>   using aaa64 = array<aa64<Size2, Size3>, Size1>;   using p64 = pair<i64, i64>;   using v64 = vec<i64>;   using vv64 = vec<v64>;   using s64 = set<i64>;   using m64 = map<i64, i64>;   mt19937 gen(998244353);   const i64 inf = numeric_limits<i64>::max() / 2;   template <typename T>   inline i64 sz(const T& a) {     return (i64)(a.size());   }   inline void fast() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); }   template <typename T>   inline bool check_min(T& a, T b) {     if (a > b) return a = b, 1;     return 0;   }   template <typename T>   inline bool check_max(T& a, T b) {     if (a < b) return a = b, 1;     return 0;   }   struct Problem {     Problem(bool multitest = 0) {       read();       if (!multitest) solve();     }     void solve(), read();   };   signed main() {     fast();     Problem();     return 0;   }   i64 n, m;   v64 a, b;   vv64 c;   i64 dist(i64 from, i64 to) { return (to - from + n) % n; }   void Problem::solve() {     c.resize(n);     for (i64 i = 0; i < m; i++) {       c[a[i]].push_back(dist(a[i], b[i]));     }     for (i64 i = 0; i < sz(c); i++) {       sort((c[i]).begin(), (c[i]).end());     }     for (i64 i = 0; i < n; i++) {       i64 ans = 0;       for (i64 j = 0; j < n; j++) {         if (c[j].empty()) continue;         i64 cur = dist(i, j) + (sz(c[j]) - 1) * n + c[j][0];         check_max(ans, cur);       }       cout << ans <<    ;     }   }   void Problem::read() {     cin >> n >> m;     a.resize(m), b.resize(m);     for (i64 i = 0; i < m; i++) {       cin >> a[i] >> b[i];       --a[i], --b[i];     }   }


#include <bits/stdc++.h>   using std::max;   int n, m, c, x[150000 + 1], a, b, i;   long long p[150000 + 1], ans = 0;   struct node {     long long sum, mmax, lmax, rmax;     void update(const node &l, const node &r) {       sum = l.sum + r.sum;       lmax = max(l.lmax, l.sum + r.lmax);       rmax = max(l.rmax + r.sum, r.rmax);       mmax = max(l.mmax, max(r.mmax, l.rmax + r.lmax));     }   } tree[(150000 << 2) + 1];   void build(int x, int l, int r) {     if (l == r) {       tree[x].sum = tree[x].mmax = tree[x].lmax = tree[x].rmax = p[l];       return;     }     int mid = (l + r) >> 1;     build(x << 1, l, mid);     build((x << 1) + 1, mid + 1, r);     tree[x].update(tree[x << 1], tree[(x << 1) + 1]);   }   node find(int x, int l, int r, int s, int t) {     if (s == l && t == r) return tree[x];     int mid = (l + r) >> 1;     if (t <= mid) return find(x << 1, l, mid, s, t);     if (s > mid) return find((x << 1) + 1, mid + 1, r, s, t);     node ret;     ret.update(find(x << 1, l, mid, s, mid),                find((x << 1) + 1, mid + 1, r, mid + 1, t));     return ret;   }   int main() {     scanf( %d%d%d , &n, &m, &c);     for (i = 1; i <= n; ++i) scanf( %d , x + i);     for (i = 1; i < n; ++i) scanf( %d , p + i);     for (i = 1; i < n; ++i) p[i] = 50 * (x[i + 1] - x[i]) - p[i] * c;     --n;     build(1, 1, n);     for (i = 1; i <= m; ++i) {       scanf( %d%d , &a, &b);       ans += max(0LL, find(1, 1, n, a, b - 1).mmax);     }     printf( %0.9llf n , (double)ans / 100);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   bool isPrime(T x) {     if (x <= 1) return false;     T i;     for (i = 2; i * i <= x; i++)       if (x % i == 0) return false;     return true;   }   template <class T>   class Prime {    public:     vector<T> z;     Prime() {       z.resize(1e5 + 7);       for (int i = (0); i < (((int)z.size())); i++) z[i] = 1;       z[0] = 0;       z[1] = 0;       T j;       for (int i = (2); i < (((int)z.size())); i++) {         if (z[i]) {           j = i + i;           while (j < ((int)z.size())) {             z[j] = 0;             j += i;           }         }       }     }   };   template <class T>   double dist(T x1, T y1, T x2, T y2) {     return sqrt(1. * (x2 - x1) * (x2 - x1) + 1. * (y2 - y1) * (y2 - y1));   }   template <class T>   class Point {    public:     T x, y;     Point() {}     Point(T a, T b) : x(a), y(b) {}     bool operator==(const Point& tmp) const { return (x == tmp.x && y == tmp.y); }     Point operator-(const Point& tmp) const {       return Point<T>(x - tmp.x, y - tmp.y);     }   };   char toLowerCase(char x) { return (x + 32); }   char toUpperCase(char x) { return (x - 32); }   bool isUpperCase(char x) { return (65 <= x && x <= 90) ? 1 : 0; }   bool isLowerCase(char x) { return (97 <= x && x <= 122) ? 1 : 0; }   bool isAlpha(char x) { return (isUpperCase(x) || isLowerCase(x)) ? 1 : 0; }   bool isDigit(char x) { return ( 0  <= x && x <=  9 ) ? 1 : 0; }   template <class T>   T toDec(string s) {     stringstream is(s);     T res;     is >> res;     return res;   }   template <class T>   string toStr(T n) {     string s;     stringstream is;     is << n;     is >> s;     return s;   }   template <class T>   void checkmin(T& a, T b) {     if (a > b) a = b;   }   template <class T>   void checkmax(T& a, T b) {     if (a < b) a = b;   }   vector<vector<int> > g, ans, ng;   vector<int> visited, parent;   bool bfs(int s, int t) {     visited = vector<int>(s + 5, 0);     parent = vector<int>(s + 5, -1);     queue<int> q;     q.push(s);     visited[s] = 1;     int u;     while (!q.empty()) {       u = q.front();       q.pop();       if (u == t) return true;       for (int v = 0; v < s + 5; v++) {         if (g[u][v] > 0 && !visited[v]) {           q.push(v);           parent[v] = u;           visited[v] = 1;         }       }     }     return false;   }   int getMaxFlow(int n) {     int max_flow = 0;     int path_min = 1e9;     int u, v;     while (bfs(n, n + 1)) {       for (v = n + 1; v != n; v = parent[v]) {         u = parent[v];         path_min = min(path_min, g[u][v]);       }       for (v = n + 1; v != n; v = parent[v]) {         u = parent[v];         g[u][v] -= path_min;         g[v][u] += path_min;       }       max_flow += path_min;     }     return max_flow;   }   int main() {     int n;     cin >> n;     g = vector<vector<int> >(n + 5, vector<int>(n + 5, 0));     vector<int> a(n + 5, 0);     for (int i = 0; i < n; i++) {       cin >> a[i];       if (a[i] % 2 == 0)         g[n][i] = 2;       else         g[i][n + 1] = 2;     }     for (int i = 0; i < n; i++) {       if (a[i] % 2 == 0) {         for (int j = 0; j < n; j++) {           if (isPrime<int>(a[i] + a[j])) {             g[i][j] = 1;           }         }       }     }     if (getMaxFlow(n) != n)       cout <<  Impossible ;     else {       ng = vector<vector<int> >(n + 5);       for (int i = 0; i < n; i++) {         if (a[i] % 2) {           for (int j = 0; j < n; j++) {             if (g[i][j]) {               ng[i].push_back(j);               ng[j].push_back(i);             }           }         }       }       visited = vector<int>(n + 5);       int node, prev, tmp;       for (int i = 0; i < n; i++) {         if (visited[i]) continue;         visited[i] = 1;         prev = i;         node = ng[i][0];         vector<int> res;         res.push_back(i);         while (node != i) {           visited[node] = 1;           res.push_back(node);           tmp = node;           node = (prev != ng[node][0] ? ng[node][0] : ng[node][1]);           prev = tmp;         }         ans.push_back(res);       }       cout << ((int)ans.size()) <<   n ;       for (int i = 0; i < ((int)ans.size()); i++) {         cout << ((int)ans[i].size()) <<    ;         for (int j = 0; j < ((int)ans[i].size()); j++) {           if (j) cout <<    ;           cout << ans[i][j] + 1;         }         cout <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   T sq(T x) {     return x * x;   }   const long long inf = 2147383647;   const double pi = 2 * acos(0.0);   const double eps = 1e-9;   const long long maxint = 2147483647;   const long long minint = -2147483648;   char grid[450][450];   int row, col, mx;   int preRight[450][450], preDiag1[450][450], preDiag2[450][450],       preDown[450][450];   void precalRight() {     int i, j;     for (i = 0; i < row; i++) {       for (j = col - 1; j >= 0; j--) {         if (grid[i][j] ==  1 )           preRight[i][j] = 0;         else {           preRight[i][j] = 1;           if (j < col - 1) preRight[i][j] += preRight[i][j + 1];         }       }     }   }   void precalDiag1() {     int i, j;     for (i = row - 1; i >= 0; i--) {       for (j = col - 1; j >= 0; j--) {         if (grid[i][j] ==  1 )           preDiag1[i][j] = 0;         else {           preDiag1[i][j] = 1;           if (i < row - 1 && j < col - 1)             preDiag1[i][j] += preDiag1[i + 1][j + 1];         }       }     }   }   void precalDiag2() {     int i, j;     for (i = 0; i < row; i++) {       for (j = col - 1; j >= 0; j--) {         if (grid[i][j] ==  1 )           preDiag2[i][j] = 0;         else {           preDiag2[i][j] = 1;           if (i > 0 && j < col - 1) preDiag2[i][j] += preDiag2[i - 1][j + 1];         }       }     }   }   void precalDown() {     int i, j;     for (i = row; i >= 0; i--) {       for (j = col - 1; j >= 0; j--) {         if (grid[i][j] ==  1 )           preDown[i][j] = 0;         else {           preDown[i][j] = 1;           if (i < row - 1) preDown[i][j] += preDown[i + 1][j];         }       }     }   }   void precal() {     precalRight();     precalDiag1();     precalDiag2();     precalDown();   }   long long triangle(int r, int c) {     long long res = 0;     int i;     for (i = 1; i <= mx + 1; i++) {       if (preRight[r][c] - 1 >= i && preDown[r][c] - 1 >= i &&           preDiag2[r + i][c] - 1 >= i)         res++;       if (preRight[r][c] - 1 >= i && preDown[r][c + i] - 1 >= i &&           preDiag1[r][c] - 1 >= i)         res++;       if (preDown[r][c] - 1 >= i && preRight[r + i][c] - 1 >= i &&           preDiag1[r][c] - 1 >= i)         res++;       if (r + i < row && preDiag2[r + i][c] - 1 >= i &&           preRight[r + i][c] - 1 >= i && preDown[r][c + i] - 1 >= i)         res++;       if (i % 2 == 0) {         int j = i / 2;         if (preRight[r][c] - 1 >= i && preDiag1[r][c] - 1 >= j &&             preDiag2[r + j][c + j] - 1 >= j)           res++;         if (preDiag1[r][c] - 1 >= j && preDown[r][c] - 1 >= i &&             preDiag2[r + i][c] - 1 >= j)           res++;         if (r + j < row && preRight[r + j][c] - 1 >= i &&             preDiag2[r + j][c] - 1 >= j && preDiag1[r][c + j] - 1 >= j)           res++;         if (r + j < row && preDiag2[r + j][c] - 1 >= j &&             preDiag1[r + j][c] - 1 >= j && preDown[r][c + j] - 1 >= i)           res++;       }     }     return res;   }   int main() {     scanf( %d %d , &row, &col);     mx = max(row, col);     int i, j, k;     for (i = 0; i < row; i++) scanf( %s , grid[i]);     precal();     long long res = 0;     for (i = 0; i < row; i++) {       for (j = 0; j < col; j++) {         res += triangle(i, j);       }     }     printf( %lld n , res);     return 0;   }


#include <bits/stdc++.h>   using namespace std;      #define ll long long   #define pi pair<int, int>   #define pll pair<long long, long long>   #define vi vector<int>   #define vll vector<long long>   #define vpi vector<pair<int, int>>   #define vvi vector<vector<int>>   #define mii map<int, int>   #define mmii multimap<int, int>   #define umii unordered_map<int, int>   #define umsii unordered_multimap<int, int>   #define si set<int>   #define msi multiset<int>   #define usi unordered_set<int>   #define umsi unordered_multiset<int>   #define sc set<char>      #define f(i, s, e) for (long long int i = s; i < e; i++)   #define cf(i, s, e) for (long long int i = s; i <= e; i++)   #define rf(i, e, s) for (long long int i = e - 1; i >= s; i--)   #define pb push_back   #define mp make_pair   #define eb emplace_back   #define F first   #define S second   #define all(x) x.begin(), x.end()   #define rall(x) x.rbegin(), x.rend()      template <class T>   void print_v(vector<T> &v) {       cout <<  [ ;       for (auto x : v) cout << x <<  ,  ;       cout <<   b b] n ;   }      template <class T>   long long int sum_v(vector<T> &v) {       long long int ans = 0;       for (auto a : v) ans += a;       return ans;   }      #define MOD 1000000007   #define PI 3.1415926535897932384626433832795   ll min(ll a, int b) {       if (a < b) return a;       return b;   }   ll min(int a, ll b) {       if (a < b) return a;       return b;   }   ll max(ll a, int b) {       if (a > b) return a;       return b;   }   ll max(int a, ll b) {       if (a > b) return a;       return b;   }   ll gcd(ll a, ll b) {       if (b == 0) return a;       return gcd(b, a % b);   }   ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }   string to_upper(string a) {       for (int i = 0; i < (int)a.size(); ++i)           if (a[i] >=  a  && a[i] <=  z ) a[i] -=  a  -  A ;       return a;   }   string to_lower(string a) {       for (int i = 0; i < (int)a.size(); ++i)           if (a[i] >=  A  && a[i] <=  Z ) a[i] +=  a  -  A ;       return a;   }   bool prime(ll a) {       if (a == 1) return 0;       for (int i = 2; i <= round(sqrt(a)); ++i)           if (a % i == 0) return 0;       return 1;   }   void yes() { cout <<  YES n ; }   void no() { cout <<  NO n ; }      typedef long int int32;   typedef unsigned long int uint32;   typedef long long int int64;   typedef unsigned long long int uint64;      void dfs(vvi &graph, vi &ans, si &visited, int node) {       if (ans[node] == -1 || ans[node] == 2) return;       if (visited.count(node)) {           vi stack;           vi tempvisited(graph.size());           stack.push_back(node);           while (!stack.empty()) {               int val = stack.back();               stack.pop_back();               ans[val] = -1;               tempvisited[val] = 1;               for (int i : graph[val]) {                   if (!tempvisited[i]) stack.push_back(i);               }           }           return;       }       visited.insert(node);       if (ans[node] != -1) ans[node] = min(ans[node] + 1, 2);       for (int i : graph[node]) {           dfs(graph, ans, visited, i);       }       visited.erase(node);   }      void solve() {       int n, m;       cin >> n >> m;       vvi graph(n + 1);       vi ans(n + 1);       si visited;       f(i, 0, m) {           int a, b;           cin >> a >> b;           graph[a].push_back(b);       }       dfs(graph, ans, visited, 1);       cf(i, 1, n) cout << ans[i] <<    ;       cout <<   n ;   }      int main() {       ios_base::sync_with_stdio(false);       cin.tie(NULL);       int t;       cin >> t;       while (t--) {           solve();       }   }


#include <bits/stdc++.h>   int pn, pr[2000050];   bool np[2000050] = {0};   int n;   int ln, ls[2000050];   inline void gen() {     pn = 0;     for (int i = 2; i < 2000050; i++) {       if (np[i]) continue;       pr[pn++] = i;       if (i > 2000) continue;       for (int j = i * i; j < 2000050; j += i) np[j] = 1;     }   }   inline int solve() {     int i, j, p, c = 0;     if (n == 2) return 0;     std::sort(ls, ls + ln);     if (ln && ls[0] == 1) return 1;     j = 0;     for (i = 0; i < pn && pr[i] < n; i++) {       p = pr[i];       while (j < ln && ls[j] < p) j++;       if (j >= ln || ls[j] != p) return -1;       c++;     }     return c;   }   int main(void) {     gen();     while (scanf( %d %d , &ln, &n) == 2) {       for (int i = 0; i < ln; i++) scanf( %d , ls + i);       printf( %d n , solve());     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long power(long long a, long long b) {     if (b == 0) return 1;     if (b == 1) return a;     if (b % 2 == 1) return (power(a, b - 1) * a);     long long q = power(a, b / 2);     return (q * q);   }   void solve() {     long long n;     cin >> n;     for (long long i = 0; i < n; i++) {       for (long long j = 0; j < n; j++) {         if (i == j or i == j + 1 or i == j - 1)           cout << 1 <<    ;         else           cout << 0 <<    ;       }       cout << endl;     }   }   int32_t main() {     ios_base::sync_with_stdio(false);     cout.tie(NULL);     cin.tie(NULL);     long long t = 1;     cin >> t;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int rev(int a) {     int ans = 0;     int shift = 0;     while (shift <= 7) {       ans |= (a & 1 << shift ? 1 : 0) << (7 - shift);       shift++;     }     return ans;   }   int main() {     string a;     int prev = 0;     getline(cin, a);     for (int i = 0; i < a.length(); i++) {       int val = rev(a[i]);       int res = prev - val;       if (res > 0)         cout << ((res) % 256) << endl;       else         cout << (256 + res) % 256 << endl;       prev = val;     }     return 0;   }


#include<cstdio>   #include<iostream>   #include<algorithm>   int main()   {    int n;    char a[100000];    bool x = 1;    while (~scanf( %d , &n)) {     while (n--) {      x = 1;      scanf( %s , a);      for (int i = 0; a[i] !=   0 ; i++) {       if (x) {        if (a[i] !=  a )         a[i] =  a ;        else         a[i] =  b ;        x = 0;       }       else {        if (a[i] !=  z )         a[i] =  z ;        else         a[i] =  z  - 1;        x = 1;       }      }      printf( %s n , a);     }    }     return 0;          }


#include <bits/stdc++.h>   using namespace std;   typedef struct trie {     char c;     bool win, lose;     struct trie *alphabet[26];   } trie;   void addString(trie *T, char *s);   trie *initTrie(char c);   void dfs(trie *T);   int main() {     int i, n, k;     char s[100005];     trie *T = initTrie(  0 );     scanf( %d%d , &n, &k);     for (i = 0; i < n; i++) {       scanf( %s , s);       addString(T, s);     }     dfs(T);     if (!(T->win))       printf( Second n );     else if (T->win && T->lose)       printf( First n );     else if (T->win && !(T->lose)) {       if (k % 2)         printf( First n );       else         printf( Second n );     }     return 0;   }   void dfs(trie *T) {     int i, flag = 1;     for (i = 0; i < 26; i++) {       if (T->alphabet[i]) {         flag = 0;         dfs(T->alphabet[i]);         T->win |= !(T->alphabet[i]->win);         T->lose |= !(T->alphabet[i]->lose);       }     }     if (flag) {       T->win = false;       T->lose = true;     }   }   trie *initTrie(char c) {     int i;     trie *T = (trie *)malloc(sizeof(trie));     T->win = T->lose = false;     T->c = c;     for (i = 0; i < 26; i++) T->alphabet[i] = NULL;     return T;   }   void addString(trie *T, char *s) {     int len = strlen(s), i;     for (i = 0; i < len; i++) {       if (T->alphabet[s[i] -  a ] == NULL)         T->alphabet[s[i] -  a ] = initTrie(s[i]);       T = T->alphabet[s[i] -  a ];     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string str;     cin >> str;     if (str[0] >  4  && str[0] !=  9 ) str[0] = (char)( 9  - str[0] +  0 );     for (int x = 1; x < (int)str.length(); x++)       if (str[x] >  4 ) str[x] = (char)( 9  - str[x] +  0 );     cout << str << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 10;   int dp[N][3][2];   string a;   int n;   int solve(int x, int state, int start) {     if (x >= n) return 0;     if (dp[x][state][start] != -1) return dp[x][state][start];     int res = 0;     if (state == 0) {       if (start == a[x])         res = max(solve(x + 1, 0, 1 - start) + 1, solve(x + 1, 1, start));       else         res = max(solve(x + 1, 1, 1 - start) + 1, solve(x + 1, 0, start));     }     if (state == 1) {       if (start == a[x])         res = max(solve(x + 1, 2, 1 - start) + 1, solve(x + 1, 1, start));       else         res = max(solve(x + 1, 2, start), solve(x + 1, 1, 1 - start) + 1);     }     if (state == 2) {       if (start == a[x])         res = solve(x + 1, 2, 1 - start) + 1;       else         res = solve(x + 1, 2, start);     }     dp[x][state][start] = res;     return res;   }   int main() {     std::ios::sync_with_stdio(false);     ;     cin >> n;     memset((dp), (-1), sizeof(dp));     cin >> a;     for (int i = 0; i < n; i++) a[i] -=  0 ;     cout << solve(0, 0, a[0]) <<   n ;     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   const int maxn = 5e4 + 5;   int main() {     int k, n, s, p;     cin >> k >> n >> s >> p;     int ans = k * (n % s == 0 ? n / s : n / s + 1);     if (ans % p == 0)       cout << ans / p << endl;     else       cout << ans / p + 1 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100005;   const int inf = ~0u >> 2;   int numa[N], numb[N], pos[N];   struct node {     int val, id;     node(int _val, int _id) { val = _val, id = _id; }     bool operator<(const node& A) const { return val > A.val; }   };   int now[N], unuse[N];   priority_queue<node> A, B;   int __ans[N];   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) {       scanf( %d , &numa[i]);       pos[numa[i]] = i;     }     for (int i = 0; i < n; i++) {       scanf( %d , &numb[i]);       int val = i - pos[numb[i]];       if (val < 0)         B.push(node(abs(val), i));       else         A.push(node(abs(val), i));       now[i] = val;     }     int tmp = 0, len = 0;     for (int k = n - 1; k >= 0; k--) {       int pa = A.empty() ? inf : A.top().val + tmp;       int pb = B.empty() ? inf : B.top().val - tmp;       __ans[len++] = min(pa, pb);       while (pb == 0) {         int id = B.top().id;         A.push(node(-tmp, id));         B.pop();         if (B.empty()) break;         pb = B.top().val - tmp;       }       unuse[k] = 1;       int np = pos[numb[k]];       now[k] = -np - tmp - 1;       while (!A.empty() && (A.top().val + tmp != abs(now[A.top().id] + tmp) &&                             unuse[A.top().id])) {         unuse[A.top().id] = 0;         A.pop();       }       tmp++;       if (np == 0)         A.push(node(-tmp, k));       else         B.push(node(np + tmp, k));     }     cout << __ans[0] << endl;     for (int i = len - 1; i; i--) printf( %d n , __ans[i]);   }


#pragma GCC optimize( Ofast )   #include<bits/stdc++.h>   using namespace std;      #define int long long int   #define double long double      #define all(x) begin(x), end(x)   #define Done(x) cout<<x<<endl; return;   #define endl   n       void solve(){    int q; cin>>q;    for(int i=0;i<q;i++){     int u; cin>>u;     int v; cin>>v;     if(v<u){      cout<< NO <<endl;     }else if(v==u){      cout<< YES <<endl;     }else{      vector<int>cnt(31);      for(int i=0;i<30;i++){       if(u&(1<<i)){        cnt[i]++;       }      }      bool can=true;      for(int i=0;i<30;i++){       int val=(1<<i);       if(v&val){        if(cnt[i]==0){         can=false;         break;        }else{         cnt[i]-=1;         cnt[i+1]+=cnt[i];        }       }else{        cnt[i+1]+=cnt[i];       }      }      if(can){       cout<< YES <<endl;      }else{       cout<< NO <<endl;      }     }    }   }      int32_t main(){    // Remove for Interactive Problems    ios_base::sync_with_stdio(false);    cin.tie(0); cout.tie(0);       solve();        cerr<< Time :  <<1000*((double)clock())/(double)CLOCKS_PER_SEC<< ms n ;    return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 400003, INF = 0x3f3f3f3f;   int n, Q, sz[maxn], fa[maxn], son[maxn], dfn[maxn], cntdfn, rig[maxn],       top[maxn], dep[maxn], z[maxn];   vector<int> g[maxn];   struct T {     int mx, sum;     T operator+(T x) const { return (T){max(x.mx, x.sum + mx), sum + x.sum}; }   } t[maxn];   void init1(int u) {     sz[u] = 1;     int mxsz = -1;     for (int v : g[u]) {       dep[v] = dep[u] + 1;       init1(v);       if (sz[v] > mxsz) mxsz = sz[v], son[u] = v;       sz[u] += sz[v];     }   }   void init2(int u, int tp) {     top[u] = tp;     dfn[u] = ++cntdfn;     if (son[u]) init2(son[u], tp);     for (int v : g[u]) {       if (v == son[u]) continue;       init2(v, v);     }     rig[u] = cntdfn;   }   void solve(int p, int len) { t[p] = (T){-1, -len}, z[p] = 1; }   void pushdown(int p, int l, int r) {     if (z[p]) {       int mid = (l + r) >> 1;       solve(p << 1, mid - l + 1), solve(p << 1 | 1, r - mid);       z[p] = 0;     }   }   void add(int p, int l, int r, int pos, int k) {     if (l == r) {       t[p].sum += k, t[p].mx += k;       return;     }     pushdown(p, l, r);     int mid = (l + r) >> 1;     if (pos <= mid)       add(p << 1, l, mid, pos, k);     else       add(p << 1 | 1, mid + 1, r, pos, k);     t[p] = t[p << 1] + t[p << 1 | 1];   }   void cover(int p, int l, int r, int seg_l, int seg_r) {     if (seg_l <= l && r <= seg_r) {       solve(p, r - l + 1);       return;     }     pushdown(p, l, r);     int mid = (l + r) >> 1;     if (seg_l <= mid) cover(p << 1, l, mid, seg_l, seg_r);     if (seg_r > mid) cover(p << 1 | 1, mid + 1, r, seg_l, seg_r);     t[p] = t[p << 1] + t[p << 1 | 1];   }   T query(int p, int l, int r, int seg_l, int seg_r) {     if (seg_l <= l && r <= seg_r) return t[p];     pushdown(p, l, r);     int mid = (l + r) >> 1;     if (seg_l <= mid && seg_r > mid)       return query(p << 1, l, mid, seg_l, seg_r) +              query(p << 1 | 1, mid + 1, r, seg_l, seg_r);     else if (seg_l <= mid)       return query(p << 1, l, mid, seg_l, seg_r);     else       return query(p << 1 | 1, mid + 1, r, seg_l, seg_r);   }   T query(int x) {     T ret = (T){-INF, 0};     while (x) {       ret = query(1, 1, n, dfn[top[x]], dfn[x]) + ret;       x = fa[top[x]];     }     return ret;   }   int main() {     scanf( %d%d , &n, &Q);     for (int i = 2; i <= n; i++) scanf( %d , fa + i), g[fa[i]].push_back(i);     init1(1), init2(1, 1), cover(1, 1, n, 1, n);     while (Q--) {       int mo, x;       scanf( %d%d , &mo, &x);       if (mo == 1) {         add(1, 1, n, dfn[x], 1);       }       if (mo == 2) {         cover(1, 1, n, dfn[x], rig[x]);         int tmp = max(query(x).mx + 1, 0);         add(1, 1, n, dfn[x], -tmp);       }       if (mo == 3) {         puts(query(x).mx >= 0 ?  black  :  white );       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long int mod = 1e9 + 7;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   const long long int N = 1e5 + 5;   long long int a[N], b[N], n, d, x;   long long int getNextX() {     x = (x * 37 + 10007) % 1000000007;     return x;   }   void initAB() {     for (long long int i = 0; i < n; i++) {       a[i] = i + 1;     }     for (long long int i = 0; i < n; i++) {       swap(a[i], a[getNextX() % (i + 1)]);     }     for (long long int i = 0; i < n; i++) {       if (i < d)         b[i] = 1;       else         b[i] = 0;     }     for (long long int i = 0; i < n; i++) {       swap(b[i], b[getNextX() % (i + 1)]);     }   }   long long int pos[N];   vector<long long int> bb;   long long int c[N];   void solve() {     cin >> n >> d >> x;     initAB();     for (long long int i = 0; i <= n - 1; i++) {       if (b[i]) bb.push_back(i);     }     for (long long int i = 0; i <= n - 1; i++) {       pos[a[i]] = i;     }     if (bb.size() <= 500) {       for (long long int i = 0; i <= n - 1; i++) {         for (long long int j : bb) {           if (j > i) break;           c[i] = max(c[i], a[i - j]);         }       }     } else {       for (long long int i = 0; i <= n - 1; i++)         for (long long int j = n; j >= 1; j--) {           long long int p = pos[j];           if (p <= i && b[i - p]) {             c[i] = j;             break;           }         }     }     for (long long int i = 0; i <= n - 1; i++) cout << c[i] <<    ;   }   signed main() {     ios ::sync_with_stdio(0), cin.tie(0), cout.tie(0);     clock_t clk = clock();     long long int t;     t = 1;     while (t--) {       solve();     }     cerr << (double)(clock() - clk) / CLOCKS_PER_SEC;     return 0;   }


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


#include <bits/stdc++.h>   char b[20];   using namespace std;   int main() {     char a[14];     for (int i = 1; i <= 2; i++) {       scanf( %s , a);       if (strcmp(a,  monday ) == 0) b[i] = 1;       if (strcmp(a,  tuesday ) == 0) b[i] = 2;       if (strcmp(a,  wednesday ) == 0) b[i] = 3;       if (strcmp(a,  thursday ) == 0) b[i] = 4;       if (strcmp(a,  friday ) == 0) b[i] = 5;       if (strcmp(a,  saturday ) == 0) b[i] = 6;       if (strcmp(a,  sunday ) == 0) b[i] = 7;     }     int flag = 1;     for (int j = 3; j <= 5; j++) {       if (j * 7 - b[1] + b[2] == 31 || j * 7 - b[1] + b[2] == 30 ||           j * 7 - b[1] + b[2] == 28) {         printf( YES n );         flag = 0;       }     }     while (flag) {       printf( NO n );       flag = 0;     }   }


#include <bits/stdc++.h>   using namespace std;   long long powmod(long long a, long long b) {     long long res = 1;     while (b > 0) {       if (b & 1) res = res * a % 2;       a = a * a % 2;       b >>= 1;     }     return res;   }   int main() {     ios_base::sync_with_stdio(false);     long long b, k, sum = 0;     cin >> b >> k;     long long a[k];     for (long long i = 1; i <= k; i++) {       cin >> a[i];       long long p = powmod(b, k - i);       sum += a[i] * p;     }     if (sum % 2)       cout <<  odd ;     else       cout <<  even ;   }


#include <bits/stdc++.h>   using namespace std;   inline void read(int &x) {     char ch;     bool flag = false;     for (ch = getchar(); !isdigit(ch); ch = getchar())       if (ch ==  - ) flag = true;     for (x = 0; isdigit(ch); x = x * 10 + ch -  0 , ch = getchar())       ;     x = flag ? -x : x;   }   inline void write(int x) {     static const int maxlen = 100;     static char s[maxlen];     if (x < 0) {       putchar( - );       x = -x;     }     if (!x) {       putchar( 0 );       return;     }     int len = 0;     for (; x; x /= 10) s[len++] = x % 10 +  0 ;     for (int i = len - 1; i >= 0; --i) putchar(s[i]);   }   int n, m;   int pre[11000], now[110], son[11000], v[11000], tot;   int f[110][110][30];   char s[100];   void build(int a, int b, int c) {     pre[++tot] = now[a];     now[a] = tot;     son[tot] = b;     v[tot] = c;   }   int dfs(int x, int y, int MAX) {     if (f[x][y][MAX] != -1) return f[x][y][MAX];     set<int> S;     for (int p = now[x]; p; p = pre[p])       if (v[p] >= MAX) S.insert(dfs(y, son[p], v[p]));     int q = -1;     for (auto t : S) {       if (t != q + 1) break;       q = t;     }     return f[x][y][MAX] = q + 1;   }   int main() {     read(n);     read(m);     for (int i = 1; i <= m; i++) {       int a, b;       read(a);       read(b);       scanf( %s , s);       build(a, b, s[0] -  a  + 1);     }     memset(f, -1, sizeof(f));     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++) dfs(i, j, 0);     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++)         if (f[i][j][0])           printf( A );         else           printf( B );       puts(  );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long i, j, n, cnt = 0, flag = 0, k = 0;     string str;     cin >> n >> str;     for (i = 0; i < n; i++) {       if (str[i] ==  ( ) {         cnt++;         if (cnt == 2) j = i;       } else         cnt--;       if ((cnt == -2) && (!k)) k = i;       if (cnt < -2) break;       if (cnt < 0) flag = 1;     }     if ((!cnt) || (flag && cnt == 2) || (i != n) || ((cnt != 2) && (cnt != -2))) {       cout <<  0 n ;       return 0;     }     if (cnt == 2) {       cnt = 0;       for (i = j; i < n; i++) {         if (str[i] ==  ( ) cnt++;       }     } else {       cnt = 0;       for (i = 0; i < k; i++) {         if (str[i] ==  ( )           cnt++;         else           cnt--;         if (cnt == -1) break;       }       cnt = 0;       k = i;       for (i = 0; i <= k; i++) {         if (str[i] ==  ) ) cnt++;       }     }     cout << cnt << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     pair<int, int> p[n];     int t = 0;     for (int i = 0; i < n; i++) {       cin >> p[i].first >> p[i].second;     }     sort(p, p + n);     int start = 0, l = 0, r = 0, s = 0;     for (int i = 0; i < 2 * n; i++) {       if (i < n && p[i].first > 0) {         start = 1;       }       if (start) {         l = i - 1;         r = i;         while (1) {           if (l < 0 && r == n) break;           if (l < 0) {             s += p[r].second;             break;           } else if (r == n) {             s += p[l].second;             break;           }           s += p[l--].second + p[r++].second;         }         return cout << s, 0;       }     }     cout << p[n - 1].second << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int a[100100];   int dig[11];   int ans[11];   int main() {     int sum = 0;     bool pos = false;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];       dig[a[i]]++;       sum += a[i];     }     if (dig[0] == 0) {       cout << -1;       return 0;     }     if (sum % 3 == 0) pos = true;     if (sum % 3 == 1) {       if (dig[1] > 0) {         dig[1] -= 1;         pos = true;       } else if (dig[4] > 0) {         pos = true;         dig[4] -= 1;       } else if (dig[7] > 0) {         dig[7] -= 1;         pos = true;       } else {         int a = 10, ai, aj;         for (int i = 0; i <= 9; i++)           for (int j = 0; j <= 9; j++)             if (i != j) {               if ((i + j) % 3 == 1 && dig[i] > 0 && dig[j] > 0 && max(i, j) < a) {                 a = max(i, j);                 ai = i;                 aj = j;                 pos = true;               }             } else {               if ((i + j) % 3 == 1 && dig[i] > 1 && max(i, j) < a) {                 a = max(i, j);                 ai = i;                 aj = j;                 pos = true;               }             }         dig[ai] -= 1;         dig[aj] -= 1;       }     } else if (sum % 3 == 2) {       if (dig[2] > 0) {         dig[2] -= 1;         pos = true;       } else if (dig[5] > 0) {         dig[5] -= 1;         pos = true;       } else if (dig[8] > 0) {         dig[8] -= 1;         pos = true;       } else {         int a = 10, ai, aj;         for (int i = 0; i <= 9; i++)           for (int j = 0; j <= 9; j++)             if (i != j) {               if ((i + j) % 3 == 2 && dig[i] > 0 && dig[j] > 0 && max(i, j) < a) {                 a = max(i, j);                 ai = i;                 aj = j;                 pos = true;               }             } else {               if ((i + j) % 3 == 2 && dig[i] > 1 && max(i, j) < a) {                 a = max(i, j);                 ai = i;                 aj = j;                 pos = true;               }             }         dig[ai] -= 1;         dig[aj] -= 1;       }     }     if (pos) {       bool shown = false;       for (int i = 9; i > 0; i--)         for (int j = 0; j < dig[i]; j++) {           cout << i;           shown = true;         }       if (shown)         for (int j = 0; j < dig[0]; j++) cout << 0;       else         cout << 0;     } else       cout << 0;   }


#include <bits/stdc++.h>   using namespace std;   int getInt() {     int ret;     scanf( %d , &ret);     return ret;   }   int main() {     int n = getInt();     vector<pair<int, int> > pr(n);     for (int i = 0; i < (int)(n); i++) {       pr[i].first = getInt();       pr[i].second = getInt();     }     sort(pr.begin(), pr.end());     int ans = 0;     int mxp = 0;     int mx = 0;     for (int i = 0; i < (int)(pr.size()); i++) {       if (i != 0) {         if (pr[i].first != pr[i - 1].first) {           mx = mxp;         }       }       if (mx > pr[i].second) ans++;       mxp = max(mxp, pr[i].second);     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct node {     long long siz, fa;     bool vis;   } a[1001];   string s;   long long n, cnt[1001][1001];   vector<long long> e[1001];   vector<vector<long long> > t[1001];   vector<pair<long long, long long> > ans;   void dfs(long long x) {     a[x].siz = a[x].vis = 1;     for (long long v : e[x])       if (v != a[x].fa) {         if (a[v].vis) cout <<  -1 , exit(0);         a[v].fa = x, dfs(v), a[x].siz += a[v].siz;       }   }   vector<vector<long long> > tmp;   void check(long long u, long long fa) {     tmp.back().push_back(u);     for (long long v : e[u])       if (v != fa) check(v, u);   }   inline void chec() {     for (long long u = 1; u <= n; u++) {       tmp.clear();       for (long long v : e[u]) {         tmp.push_back(vector<long long>());         check(v, u);         sort(tmp.back().begin(), tmp.back().end());       }       sort(tmp.begin(), tmp.end());       if (t[u] != tmp) cout <<  -1 n , exit(0);     }   }   inline long long get_num() {     char temp = s.back();     s.pop_back();     long long ans = 0;     while (temp >=  0  && temp <=  9 ) {       ans = ans * 10 + temp -  0 ;       if (s.empty()) break;       temp = s.back(), s.pop_back();     }     return ans;   }   int main() {     std::cin.tie(0);     std::ios::sync_with_stdio(false);     cin >> n;     for (long long i = 1; i <= n; i++) {       cin >> s, reverse(s.begin(), s.end());       long long d, tot = 0;       while (tot < n - 1) {         t[i].push_back(vector<long long>());         d = get_num(), tot += d;         for (long long j = 1; j <= d; j++)           t[i].back().push_back(get_num()), cnt[i][t[i].back().back()] = d;         sort(t[i].back().begin(), t[i].back().end());       }       sort(t[i].begin(), t[i].end());     }     for (long long u = 1; u <= n; u++)       for (long long v = u + 1; v <= n; v++)         if (cnt[u][v] + cnt[v][u] == n)           e[u].push_back(v), e[v].push_back(u), ans.push_back(make_pair(u, v));     if ((long long)ans.size() != (n - 1)) cout <<  -1 , exit(0);     dfs(1);     if (a[1].siz != n) cout <<  -1 , exit(0);     chec();     cout << ans.size() <<   n ;     for (auto t : ans) cout << t.first <<     << t.second <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 1e3 + 7;   int n, Q, m;   int p[N];   int a[N], b[N];   struct Query {     int t, x;   } q[N];   int nd, fa[N], del[N];   int find(int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); }   int rt[N];   vector<int> g[N];   int vis[N];   int st[N], ed[N], dc, rev[N];   void dfs(int x) {     if (vis[x]) return;     st[x] = ++dc;     vis[x] = 1;     rev[st[x]] = x;     for (auto v : g[x]) dfs(v);     ed[x] = dc;   }   int cnt;   struct T {     int ls, rs, l, r;     pair<int, int> mx;   } t[N * 2 + 1];   void update(int x) { t[x].mx = max(t[t[x].ls].mx, t[t[x].rs].mx); }   int build(int l, int r) {     int x = ++cnt;     t[x].l = l, t[x].r = r;     if (l == r) {       t[x].mx = make_pair(p[rev[l]], l);       return x;     }     int mid = (l + r) >> 1;     t[x].ls = build(l, mid);     t[x].rs = build(mid + 1, r);     update(x);     return x;   }   void change(int x, int p, int v) {     if (t[x].l == t[x].r) {       t[x].mx.first = v;       return;     }     int mid = (t[x].l + t[x].r) >> 1;     if (p <= mid)       change(t[x].ls, p, v);     else       change(t[x].rs, p, v);     update(x);   }   pair<int, int> query(int x, int l, int r) {     if (l <= t[x].l && t[x].r <= r) return t[x].mx;     int mid = (t[x].l + t[x].r) >> 1;     pair<int, int> mx = make_pair(0, 0);     if (l <= mid) mx = max(mx, query(t[x].ls, l, r));     if (r > mid) mx = max(mx, query(t[x].rs, l, r));     return mx;   }   int main() {     scanf( %d%d%d , &n, &m, &Q);     for (int i = 1; i <= n; i++) scanf( %d , &p[i]), fa[i] = i;     for (int i = 1; i <= m; i++) scanf( %d%d , &a[i], &b[i]);     for (int i = 1; i <= Q; i++) {       scanf( %d%d , &q[i].t, &q[i].x);       if (q[i].t == 2) del[q[i].x] = 1;     }     nd = n;     for (int i = 1; i <= m; i++)       if (!del[i]) {         int fx = find(a[i]), fy = find(b[i]);         if (fx == fy) continue;         ++nd;         g[nd].push_back(fx);         g[nd].push_back(fy);         fa[fx] = fa[fy] = fa[nd] = nd;       }     for (int i = Q; i >= 1; i--) {       if (q[i].t == 2) {         int fx = find(a[q[i].x]), fy = find(b[q[i].x]);         if (fx == fy) continue;         ++nd;         g[nd].push_back(fx);         g[nd].push_back(fy);         fa[fx] = fa[fy] = fa[nd] = nd;       } else         rt[i] = find(q[i].x);     }     for (int i = nd; i >= 1; i--) dfs(i);     build(1, nd);     for (int i = 1; i <= Q; i++) {       if (q[i].t == 1) {         pair<int, int> ans = query(1, st[rt[i]], ed[rt[i]]);         printf( %d n , ans.first);         if (ans.second) change(1, ans.second, 0);       }     }   }


#include <bits/stdc++.h>   using namespace std;   long long a[10010];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     long long n, m, k;     cin >> n >> m >> k;     if (n % 2 == 0) {       cout << 0;       return 0;     }     if (m < ((n + 1) / 2)) {       cout << 0;       return 0;     }     long long can = m / ((n + 1) / 2) * k;     long long mn = 1e9;     for (long long i = 1; i <= n; ++i) {       cin >> a[i];       if (i & 1) mn = min(mn, a[i]);     }     cout << min(mn, can) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 2000005;   int at[MAXN];   long long int n, x, y;   int main() {     cin >> n >> x >> y;     int a;     long long int f, g;     f = y;     g = x;     for (int i = 0; i < x + y; i++) {       if (f < g) {         at[i] = 1;         f += y;       } else if (g < f) {         at[i] = 2;         g += x;       } else {         at[i] = at[++i] = 3;         g += x;         f += y;       }     }     for (int i = 0; i < n; i++) {       cin >> a;       a--;       a %= x + y;       if (at[a] == 2)         cout <<  Vova ;       else if (at[a] == 1)         cout <<  Vanya ;       else         cout <<  Both ;       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename Arg1>   void __f(const char* name, Arg1&& arg1) {     cerr << name <<   :   << arg1 << std::endl;   }   template <typename Arg1, typename... Args>   void __f(const char* names, Arg1&& arg1, Args&&... args) {     const char* comma = strchr(names + 1,  , );     cerr.write(names, comma - names) <<   :   << arg1 <<   |  ;     __f(comma + 1, args...);   }   long long ex(long long a, long long b) {     long long ans = 1;     while (b) {       if (b & 1) ans = (ans * a) % 998244353;       a = (a * a) % 998244353, b /= 2;     }     return ans;   }   inline long long add(long long a, long long b) {     a = a % 998244353 + b % 998244353;     if (a > 998244353) a %= 998244353;     return a;   }   inline long long sub(long long a, long long b) {     a = a % 998244353 - b % 998244353;     if (a < 0) a += 998244353;     return a;   }   inline long long mul(long long a, long long b) {     a %= 998244353, b %= 998244353;     return (a * b) % 998244353;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     long long n, q;     cin >> n >> q;     long long a[n + 2], b[n + 2], c[n + 2];     for (long long i = 1; i < n + 1; ++i)       cin >> a[i], a[i] = mul(100, ex(a[i], 998244353 - 2));     b[0] = 0, c[n + 1] = 1;     for (long long i = n; i >= 1; --i) c[i] = mul(c[i + 1], a[i]);     for (long long i = 1; i < n + 1; ++i) b[i] = add(b[i - 1], c[i]);     auto get = [&](long long l, long long r) {       long long x = sub(b[r], b[l - 1]);       x = mul(x, ex(c[r + 1], 998244353 - 2));       return x;     };     long long ans = get(1, n), x;     set<long long> s;     s.insert(1);     for (long long i = 0; i < q; ++i) {       long long u;       cin >> u;       if (s.count(u)) {         auto it = s.find(u);         auto it1 = s.upper_bound(u);         if (it1 == s.end())           x = n;         else           x = *it1 - 1;         auto it2 = s.lower_bound(u);         it2--;         ans = add(ans, get(*it2, x));         ans = sub(ans, add(get(*it2, *it - 1), get(*it, x)));         s.erase(u);       } else {         s.insert(u);         auto it = s.find(u);         auto it1 = s.upper_bound(u);         if (it1 == s.end())           x = n;         else           x = *it1 - 1;         auto it2 = s.find(u);         it2--;         ans = sub(ans, get(*it2, x));         ans = add(ans, add(get(*it2, *it - 1), get(*it, x)));       }       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, root = -1, nextnum = 3;   vector<vector<int>> edges[100005];   int order[100005];   int main() {     cin >> n;     for (int i = 1; i <= n - 1; i++) {       int a, b;       cin >> a >> b;       edges[a].push_back({b, i});       edges[b].push_back({a, i});     }     for (int i = 1; i <= n; i++) {       if (edges[i].size() > 2) {         root = i;         break;       }     }     if (root == -1) {       for (int i = 0; i <= n - 2; i++) {         cout << i <<   n ;       }     } else {       for (int i = 1; i <= n - 1; i++) {         order[i] = -1;       }       order[edges[root][0][1]] = 0;       order[edges[root][1][1]] = 1;       order[edges[root][2][1]] = 2;       for (int i = 1; i <= n; i++) {         for (int j = 0; j < edges[i].size(); j++) {           if (order[edges[i][j][1]] == -1) {             order[edges[i][j][1]] = nextnum;             nextnum++;           }         }       }       for (int i = 1; i <= n - 1; i++) {         cout << order[i] <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[5000];   int main() {     int n, k, l, r, s, sk;     cin >> n >> k >> l >> r >> s >> sk;     int d = s - sk;     for (int i = 1; i <= k; i++) {       a[i] = sk / k;       if (sk % k != 0) {         a[i]++;         sk--;       }     }     if (k != n) {       for (int i = k + 1; i <= n; i++) {         a[i] = d / (n - k);         if (d % (n - k) != 0) {           a[i]++;           d--;         }       }     }     for (int i = 1; i <= n; i++) cout << a[i] <<    ;     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   signed main(int argc, char const *argv[]) {     int t;     cin >> t;     while (t--) {       int n;       string s, k;       cin >> n;       cin >> s >> k;       int ans = 0;       string prev =  01 ;       for (int i = 0; i < n; i++) {         if ((s[i] ==  0  && k[i] ==  1 ) || (s[i] ==  1  && k[i] ==  0 )) {           prev =  01 ;           ans += 2;         } else if (s[i] ==  0  && k[i] ==  0 ) {           ans++;           if (prev ==  11 ) {             ans++;             prev =  01 ;           } else             prev =  00 ;         } else {           if (prev ==  00 ) {             ans++;             prev =  01 ;           } else             prev =  11 ;         }       }       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   pair<int, int> p[100005], ans[100005];   int tot, start[100005], remain, now;   int f[100005];   priority_queue<pair<int, int> > Q;   int main() {     cin >> n >> m;     for (int i = 1; i <= m; i++) {       scanf( %d%d , &p[i].first, &p[i].second);       if (p[i].second == 0) p[i].second = -1;       p[i].second = -p[i].second;       p[i].second *= i;     }     sort(p + 1, p + m + 1);     for (int i = 1; i <= n; i++) f[i] = i, start[i] = i + 1;     remain = 1;     now = 1;     for (int i = 1; i <= m; i++) {       if (p[i].second > 0) {         if (Q.empty()) {           return puts( -1 ), 0;         } else {           int x = Q.top().first, y = Q.top().second;           Q.pop();           if (-x <= remain) {             ans[p[i].second] = make_pair(-x, y);             if (-x != n) Q.push(make_pair(x - 1, y));           } else {             return puts( -1 );           }         }       } else {         remain++;         if (remain <= n) {           Q.push(make_pair(-remain - 1, remain));           ans[-p[i].second] = make_pair(1, remain);         } else {           return puts( -1 ), 0;         }       }     }     for (int i = 1; i <= m; i++) printf( %d %d n , ans[i].first, ans[i].second);   }