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


#include <bits/stdc++.h>   using namespace std;   const int maxn = 100123;   const int lgn = 20;   long long a[maxn], f[maxn][lgn], ans;   vector<int> G[maxn];   void dfs(int u, int p, int x) {     int w = a[u] >> x & 1;     f[u][w] = 1, f[u][w ^ 1] = 0;     for (auto& v : G[u]) {       if (v != p) {         dfs(v, u, x);         ans += (1 << x) * (f[u][1] * f[v][0] + f[u][0] * f[v][1]);         f[u][w] += f[v][0];         f[u][w ^ 1] += f[v][1];       }     }   }   int main() {     cin.sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     for (int i = 0; i < (n); ++i) cin >> a[i], ans += a[i];     for (int i = 0; i < (n - 1); ++i) {       int u, v;       cin >> u >> v;       --u, --v;       G[u].push_back(v);       G[v].push_back(u);     }     for (int i = 0; i < (lgn); ++i) dfs(0, -1, i);     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int ans;   char s[100];   int main() {     cin >> s;     for (int i = 0; i < strlen(s); i++)       if (s[i] ==  a  || s[i] ==  e  || s[i] ==  i  || s[i] ==  o  ||           s[i] ==  u  || s[i] ==  1  || s[i] ==  3  || s[i] ==  5  ||           s[i] ==  7  || s[i] ==  9 )         ans++;     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int test, i, k, j, sum1, sum, n, p;     cin >> test;     for (i = 0; i < test; i++) {       cin >> n >> k;       sum = 0;       sum1 = 0;       vector<int> v1, v2;       for (j = 0; j < n; j++) {         cin >> p;         v1.push_back(p);       }       for (j = 0; j < n; j++) {         cin >> p;         v2.push_back(p);       }       sort(v1.begin(), v1.end());       sort(v2.begin(), v2.end());       for (j = 0; j < k; j++) {         if (v2[n - j - 1] > v1[j])           sum1 = sum1 + v2[n - j - 1];         else           sum1 = sum1 + v1[j];       }       for (j = k; j < n; j++) sum = sum + v1[j];       cout << sum + sum1 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, k;   int query(int l, int r) {     if (l < 1 || r > n) return false;     string re;     cout << 1 <<     << l <<     << r << endl;     cin >> re;     return re ==  TAK ;   }   int get(int l, int r) {     if (l > r) return false;     while (l < r) {       int mid = (l + r) >> 1;       if (query(mid, mid + 1))         r = mid;       else         l = mid + 1;     }     return l;   }   int main() {     cin >> n >> k;     int x, y;     x = get(1, n);     y = get(1, x - 1);     if (!query(y, x)) y = get(x + 1, n);     cout << 2 <<     << x <<     << y << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1.0), eps = 1e-4;   double fgcd(double a, double b) {     return fabs(a) < eps ? b : (fabs(b) < eps ? a : fgcd(b, fmod(a, b)));   }   int main() {     double a, b, c, d, e, f;     cin >> a >> b >> c >> d >> e >> f;     c -= a;     e -= a;     d -= b;     f -= b;     a = (c * c + d * d) / 2;     b = (e * e + f * f) / 2;     double ov = 1.0 / (d * e - c * f);     double A = (d * b - f * a) * ov, B = (e * a - c * b) * ov;     double R = sqrt(A * A + B * B), G1 = asin(sqrt(a * 2) / (R * 2)),            G2 = asin(sqrt(b * 2) / (R * 2)),            G = asin(hypot(c - e, d - f) / (R * 2));     G = fgcd(G1, fgcd(G2, pi));     G = pi / round(pi / G);     A = round(pi / G) * R * R * sin(G * 2) / 2;     printf( %.8lf n , A);   }


#include <bits/stdc++.h>   using namespace std;   struct Q {     int l;     int r;     int num;     Q(int _l, int _r, int _num) : l(_l), r(_r), num(_num) {}   };   int cnt[100100];   int res[100100];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n, m;     cin >> n >> m;     vector<int> a(n);     for (int i = 0; i < n; i++) {       cin >> a[i];     }     vector<int> comp = a;     sort(comp.begin(), comp.end());     comp.resize(unique(comp.begin(), comp.end()) - comp.begin());     for (int i = 0; i < n; i++) {       a[i] = lower_bound(comp.begin(), comp.end(), a[i]) - comp.begin();     }     int K = sqrt(n);     int B = n / K + 1;     vector<vector<Q>> blocks(B);     for (int i = 0; i < m; i++) {       int l, r;       cin >> l >> r;       l--;       r--;       blocks[l / K].emplace_back(l, r, i);     }     for (int b = 0; b < B; b++) {       sort(blocks[b].begin(), blocks[b].end(),            [&](Q x, Q y) { return x.r < y.r; });     }     for (int b = 0; b < B; b++) {       if (blocks[b].empty()) continue;       memset(cnt, 0, sizeof(cnt));       int ans = 0;       for (int i = blocks[b][0].l; i <= blocks[b][0].r; i++) {         if (cnt[a[i]] == comp[a[i]]) {           ans--;         }         cnt[a[i]]++;         if (cnt[a[i]] == comp[a[i]]) {           ans++;         }       }       int pl = blocks[b][0].l;       int pr = blocks[b][0].r;       res[blocks[b][0].num] = ans;       for (int q = 1; q < (int)blocks[b].size(); q++) {         for (int i = pr + 1; i <= blocks[b][q].r; i++) {           if (cnt[a[i]] == comp[a[i]]) {             ans--;           }           cnt[a[i]]++;           if (cnt[a[i]] == comp[a[i]]) {             ans++;           }         }         pr = blocks[b][q].r;         for (int i = blocks[b][q].l; i < pl; i++) {           if (cnt[a[i]] == comp[a[i]]) {             ans--;           }           cnt[a[i]]++;           if (cnt[a[i]] == comp[a[i]]) {             ans++;           }         }         for (int i = pl; i < blocks[b][q].l; i++) {           if (cnt[a[i]] == comp[a[i]]) {             ans--;           }           cnt[a[i]]--;           if (cnt[a[i]] == comp[a[i]]) {             ans++;           }         }         pl = blocks[b][q].l;         res[blocks[b][q].num] = ans;       }     }     for (int i = 0; i < m; i++) {       cout << res[i] <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 105000;   const int INF = 2100000000;   struct target {     int mi_n[2], ma_x[2], z, n;   };   struct point {     int min, n, dot, d[2], fa, l, r;   };   int n, m, root, now, txl, txr, tyl, tyr, ans[MAXN] = {0};   target rec[MAXN];   point t[MAXN];   void input_data() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d%d%d%d%d , &rec[i].mi_n[0], &rec[i].ma_x[0], &rec[i].mi_n[1],             &rec[i].ma_x[1], &rec[i].z);       rec[i].n = i;     }     scanf( %d , &m);     for (int i = 1; i <= m; i++) {       scanf( %d%d , &t[i].d[0], &t[i].d[1]);       t[i].n = i;     }   }   bool cmp_1(point a, point b) { return a.d[now] < b.d[now]; }   void gengxin(int father, int son) {     if (t[father].min > t[son].min) {       t[father].min = t[son].min;       t[father].dot = t[son].dot;     }   }   void up_data(int rt) {     t[rt].min = t[rt].n;     t[rt].dot = rt;     if (t[rt].n == 0) {       t[rt].min = INF;       t[rt].dot = 0;     }     int l = t[rt].l, r = t[rt].r;     if (l) gengxin(rt, l);     if (r) gengxin(rt, r);   }   int build(int begin, int end, int fa, int fx) {     int m = (begin + end) >> 1;     now = fx;     nth_element(t + begin, t + m, t + end + 1, cmp_1);     t[m].fa = fa;     if (begin < m) t[m].l = build(begin, m - 1, m, 1 - fx);     if (m < end) t[m].r = build(m + 1, end, m, 1 - fx);     up_data(m);     return m;   }   bool inrange(int x, target b, int fx) {     return ((b.mi_n[fx] <= x) && (x <= b.ma_x[fx]));   }   int query(int rt, int fx, int r, int xl, int xr, int yl, int yr) {     if (!rt) return 0;     if (!t[rt].dot) return 0;     if (txl <= xl && xr <= txr && tyl <= yl && yr <= tyr) return t[rt].dot;     int t1 = 0, t2 = 0;     if (inrange(t[rt].d[fx], rec[r], fx)) {       if (fx == 0) {         t1 = query(t[rt].l, 1 - fx, r, xl, t[rt].d[0], yl, yr);         t2 = query(t[rt].r, 1 - fx, r, t[rt].d[0], xr, yl, yr);       } else {         t1 = query(t[rt].l, 1 - fx, r, xl, xr, yl, t[rt].d[1]);         t2 = query(t[rt].r, 1 - fx, r, xl, xr, t[rt].d[1], yr);       }     } else {       if (t[rt].d[fx] < rec[r].mi_n[fx]) {         if (fx == 0)           return query(t[rt].r, 1 - fx, r, t[rt].d[0], xr, yl, yr);         else           return query(t[rt].r, 1 - fx, r, xl, xr, t[rt].d[1], yr);       }       if (rec[r].ma_x[fx] < t[rt].d[fx]) {         if (fx == 0)           return query(t[rt].l, 1 - fx, r, xl, t[rt].d[0], yl, yr);         else           return query(t[rt].l, 1 - fx, r, xl, xr, yl, t[rt].d[1]);       }     }     int fi = 0;     int temp = INF;     if (t1 != 0)       if (t[t1].n < temp) {         temp = t[t1].n;         fi = t1;       }     if (t2 != 0)       if (t[t2].n < temp) {         temp = t[t2].n;         fi = t2;       }     if (t[rt].n != 0 && t[rt].n < temp)       if (inrange(t[rt].d[0], rec[r], 0) && inrange(t[rt].d[1], rec[r], 1)) {         temp = t[rt].n;         fi = rt;       }     return fi;   }   void adjust(int rt) {     up_data(rt);     if (rt != root) adjust(t[rt].fa);   }   bool cmp_2(target a, target b) { return a.z < b.z; }   void get_ans() {     root = build(1, m, 0, 0);     sort(rec + 1, rec + 1 + n, cmp_2);     for (int i = 1; i <= n; i++) {       txl = rec[i].mi_n[0], txr = rec[i].ma_x[0], tyl = rec[i].mi_n[1],       tyr = rec[i].ma_x[1];       int hit = query(root, 0, i, 0, INF, 0, INF);       if (hit != 0) {         ans[t[hit].n] = rec[i].n;         t[hit].n = 0;         adjust(hit);       }     }   }   void output_ans() {     for (int i = 1; i <= m; i++) printf( %d n , ans[i]);   }   int main() {     input_data();     get_ans();     output_ans();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, q, ans;   map<int, int> boss[100010];   map<pair<int, int>, int> mp;   vector<pair<int, int> > vt[100010];   int findf(int x, int col) {     if (!boss[col].count(x) || x == boss[col][x]) {       boss[col][x] = x;       return x;     }     return boss[col][x] = findf(boss[col][x], col);   }   void dsu(int x, int y, int col) {     x = findf(x, col);     y = findf(y, col);     if (x != y) {       boss[col][y] = x;     }     return;   }   int main() {     int i, j, a, b, c;     cin >> n >> m;     for (i = 0; i < m; i++) {       cin >> a >> b >> c;       a--, b--, c--;       dsu(a, b, c);     }     for (i = 0; i < m; i++) {       for (map<int, int>::iterator it = boss[i].begin(); it != boss[i].end();            it++) {         a = it->first;         b = it->second;         vt[a].push_back(make_pair(i, b));       }     }     for (i = 0; i < n; i++) {       for (j = 0; j < vt[i].size(); j++) {         vt[i][j].second = findf(i, vt[i][j].first);       }     }     cin >> q;     for (i = 0; i < q; i++) {       cin >> a >> b;       a--, b--;       if (vt[a].size() >= vt[b].size()) {         swap(a, b);       }       if (mp.count(make_pair(a, b))) {         cout << mp[make_pair(a, b)] << endl;         continue;       }       ans = 0;       for (j = 0; j < vt[a].size(); j++) {         if (binary_search(vt[b].begin(), vt[b].end(), vt[a][j])) {           ans++;         }       }       mp[make_pair(a, b)] = ans;       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   template <typename T>   using PQ = priority_queue<T>;   template <typename T>   using GPQ = priority_queue<T, vector<T>, greater<T>>;   template <class L, class R>   ostream& operator<<(ostream& os, pair<L, R> p);   template <class T>   ostream& operator<<(ostream& os, vector<T> v) {     os <<  [ ;     for (auto vv : v) os << vv <<  , ;     return os <<  ] ;   }   template <class T>   ostream& operator<<(ostream& os, set<T> v) {     os <<  [ ;     for (auto vv : v) os << vv <<  , ;     return os <<  ] ;   }   template <class L, class R>   ostream& operator<<(ostream& os, pair<L, R> p) {     return os <<  (  << p.first <<  ,  << p.second <<  ) ;   }   template <typename T>   inline T sq(T a) {     return a * a;   }   template <typename T>   T gcd(T a, T b) {     if (a > b) return gcd(b, a);     return a == 0 ? b : gcd(b % a, a);   }   template <typename T, typename U>   T mypow(T b, U n) {     if (n == 0) return 1;     if (n == 1) return b;     if (n % 2 == 0) {       return mypow(b * b, n / 2);     } else {       return mypow(b, n - 1) * b;     }   }   ll pcnt(ll b) { return __builtin_popcountll(b); }   template <typename T>   T iceil(T n, T d) {     return (n + d - 1) / d;   }   map<char, int> hand = {{ R , 0}, { S , 1}, { P , 2}};   class BIT {    public:     explicit BIT(int N, int v) : V_NUM(N) {       data.resize(N);       fill(data.begin(), data.end(), v);     }     ll query(int i) {       ll ret = 0;       while (i > 0) {         ret += data[i];         i -= (i & -i);       }       return ret;     }     void update(int i, int v) {       while (i < V_NUM) {         data[i] += v;         i += (i & -i);       }     }     int_fast32_t V_NUM;     vector<int> data;   };   int main() {     int N, Q;     string S;     cin >> N >> Q >> S;     S =  $  + S;     vector<BIT> bit(3, BIT(N + 1, 0));     vector<set<int>> pos(3);     for (int i = 1; i <= N; ++i) {       bit[hand[S[i]]].update(i, 1);       pos[hand[S[i]]].insert(i);     }     for (int q = 0; q <= Q; ++q) {       int lose = 0;       int emp = 0;       for (int h = 0; h < 3; ++h) {         if (pos[h].empty()) ++emp;       }       if (emp == 1) {         for (int h = 0; h < 3; ++h) {           if (pos[h].empty() || pos[(h + 1) % 3].empty()) continue;           lose = pos[(h + 1) % 3].size();         }       } else if (emp == 0) {         for (int h = 0; h < 3; ++h) {           int w = (h + 1) % 3, l = (h + 2) % 3;           int wpos = *(pos[w].begin()), lpos = *(pos[l].begin());           lose += max(0LL, bit[h].query(wpos) - bit[h].query(lpos));           wpos = *(--pos[w].end()), lpos = *(--pos[l].end());           lose += max(0LL, bit[h].query(lpos) - bit[h].query(wpos));         }       }       cout << N - lose <<   n ;       if (q == Q) break;       int p;       char c;       cin >> p >> c;       bit[hand[S[p]]].update(p, -1);       pos[hand[S[p]]].erase(p);       bit[hand[c]].update(p, 1);       pos[hand[c]].insert(p);       S[p] = c;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     int n = s.length();     vector<vector<int> > pos( z  -  a  + 1);     for (int i = 0; i < n; i++) pos[s[i] -  a ].push_back(i);     int good = 0;     for (int c = 0; c <=  z  -  a ; c++) {       if (pos[c].empty()) continue;       int c_good = 0;       for (int k = 0; k < n; k++) {         int cnt[ z  -  a  + 1] = {};         for (int i : pos[c]) cnt[s[(i + k) % n] -  a ]++;         int cur_c_good = 0;         for (int d = 0; d <=  z  -  a ; d++) cur_c_good += (cnt[d] == 1);         c_good = max(c_good, cur_c_good);       }       good += c_good;     }     cout.precision(10);     cout << fixed;     cout << (double)good / n;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const double PI = acos(-1.0);   const int MAXN = 2e5 + 5;   long long int freq[MAXN];   long long int pref_sum(int l, int r) {     return (l ? freq[r] - freq[l - 1] : freq[r]);   }   void cp() {     int n;     long long int k;     cin >> n >> k;     vector<long long int> arr(n);     memset(freq, 0, sizeof(freq));     for (int i = 0; i < n; i++) cin >> arr[i], freq[arr[i]]++;     for (int i = 1; i < MAXN; i++) freq[i] += freq[i - 1];     sort(arr.begin(), arr.end());     int need = arr[0];     int ans = 0;     long long int cost = 0;     for (int i = 2e5; i >= need; i--) {       long long int cnt = pref_sum(i + 1, MAXN - 1);       long long int total = cost + cnt;       if (total > k) {         ans++;         cost = cnt;       } else         cost += cnt;     }     if (cost) {       ans++;     }     cout << ans <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     int t;     t = 1;     while (t--) {       cp();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 35005;   struct segtree {     segtree *left, *right;     int start, end, v, m;     int lazy;     segtree(int start, int end) : start(start), end(end), v(0), lazy(0) {       if (start == end) {         left = right = NULL;       } else {         m = (start + end) / 2;         left = new segtree(start, m);         right = new segtree(m + 1, end);       }     }     void propagate() {       if (lazy) {         v += lazy;         if (left != NULL) left->lazy += lazy;         if (right != NULL) right->lazy += lazy;         lazy = 0;       }     }     void update(int a, int b, int val) {       if (b < a) return;       propagate();       if (a == start && b == end) {         lazy += val;         propagate();       } else {         if (b <= m)           left->update(a, b, val);         else if (a > m)           right->update(a, b, val);         else           left->update(a, m, val), right->update(m + 1, b, val);         left->propagate();         right->propagate();         v = max(left->v, right->v);       }     }     int query(int a, int b) {       if (b < a) return 1;       propagate();       if (a == start && b == end) return v;       if (b <= m) return left->query(a, b);       if (a > m) return right->query(a, b);       return max(left->query(a, m), right->query(m + 1, b));     }   };   int dp[MAX][51];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int n, k;     cin >> n >> k;     vector<int> v(n + 1);     for (int i = 1; i <= n; i++) {       cin >> v[i];     }     set<int> diff;     for (int i = 1; i <= n; i++) {       diff.insert(v[i]);       dp[i][1] = diff.size();     }     for (int i = 2; i <= k; i++) {       segtree cur(1, n);       for (int j = 1; j <= n; j++) {         cur.update(j, j, dp[j][i - 1]);       }       vector<int> last(n + 1, 1);       for (int j = 1; j <= n; j++) {         cur.update(last[v[j]], j - 1, 1);         dp[j][i] = cur.query(1, j - 1);         last[v[j]] = j;       }     }     cout << dp[n][k] <<   n ;   }


#include <cstdio>   #include <cstring>   #include <algorithm>   #define rep(a,b,c) for(int a=b;a<=c;a++)   #define per(a,b,c) for(int a=b;a>=c;a--)   #define int long long   const int inf=0x3f3f3f3f;   template<class T>inline void read(T &x) {    T f=1;x=0;char s=getchar();    while(s< 0 ||s> 9 ){if(s== - )f=-1;s=getchar();}    while(s>= 0 &&s<= 9 ){x=x*10+s- 0 ;s=getchar();}    x*=f;   }   const int N=1e6+1;   struct Node {    int i,j,val;   }a[N];   int n,du[N],idx;   char s[10];   inline bool cmp(Node a,Node b) { return a.val==b.val?a.j<b.j:a.val>b.val; }   inline void solve() {    read(n);    rep(i,1,n) read(du[i]);    rep(i,1,n-1) rep(j,i+1,n) {     if(du[i]>du[j]) a[++idx].i=i,a[idx].j=j,a[idx].val=du[i]-du[j];     else a[++idx].i=j,a[idx].j=i,a[idx].val=du[j]-du[i];    }    std::sort(a+1,a+idx+1,cmp);    rep(i,1,idx) {     printf( ? %lld %lld n ,a[i].i,a[i].j);     fflush(stdout);     scanf( %s ,s+1);     if(s[1]== Y ) {      printf( ! %lld %lld n ,a[i].i,a[i].j);      fflush(stdout);      return;     }    }    puts( ! 0 0 );    fflush(stdout);   }   signed main() {    //int TEST; read(TEST); while(TEST--)    solve();   }


#include <bits/stdc++.h>   using namespace std;   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int t, a, b, diff, n;     cin >> t;     while (t--) {       cin >> a >> b;       diff = abs(a - b);       n = ceil((-1 + sqrt(1 + 8 * diff)) / 2);       if (((n + 1) / 2) % 2 != diff % 2) {         if (n % 2)           n += 2;         else           n++;       }       if (n == -0) n = 0;       cout << n <<   n ;     }   }


#include <bits/stdc++.h>   template <typename T, typename U>   static inline void amin(T &x, U y) {     if (y < x) x = y;   }   template <typename T, typename U>   static inline void amax(T &x, U y) {     if (x < y) x = y;   }   using namespace std;   const int N = 2e5 + 5;   int par[N], r[N];   int find(int a) {     if (par[a] < 0)       return a;     else       return (par[a] = find(par[a]));   }   void merge(int a, int b) {     a = find(a);     b = find(b);     if (a == b) return;     if (r[a] > r[b]) {       par[b] = a;       r[a] += r[b];     } else {       par[a] = b;       r[b] += r[a];     }   }   void solve() {     int n, m, i, j;     cin >> n >> m;     for (i = 1; i < n + 1; i++) par[i] = -1, r[i] = 1;     for (i = 0; i < m; i++) {       int a, b;       cin >> a >> b;       merge(a, b);     }     long long int ans = 1;     for (i = 1; i < n + 1; i++) {       if (r[i] > 1 && par[i] < 0) ans = ans * pow(2, r[i] - 1);     }     cout << ans;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t = 1;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   struct Solution {     int n, k;     std::vector<std::vector<int>> as;     std::vector<int> pows;     int64_t calcPair(int ind1, int ind2) {       std::vector<int> left;       left.reserve(as[ind1].size());       for (int v : as[ind1]) {         left.push_back((int64_t(k - v) * pows[ind2 + 1]) % k);       }       std::sort(left.begin(), left.end());       int64_t result = 0;       size_t i1 = 0;       size_t j1 = 0;       std::vector<int>& right = as[ind2];       while (i1 < left.size() && j1 < right.size()) {         if (left[i1] < right[j1]) {           i1++;           continue;         }         if (left[i1] > right[j1]) {           j1++;           continue;         }         size_t i2 = i1;         while (i2 < left.size() && left[i2] == left[i1]) i2++;         size_t j2 = j1;         while (j2 < right.size() && right[j2] == right[j1]) j2++;         result += (i2 - i1) * int64_t(j2 - j1);         i1 = i2;         j1 = j2;       }       if (ind1 == ind2) {         for (int v : right) {           if ((v + int64_t(v) * pows[ind2 + 1]) % k == 0) {             result--;           }         }       }       return result;     }     void run(std::istream& in, std::ostream& out) {       in >> n >> k;       as.assign(10, std::vector<int>());       pows.resize(11);       pows[0] = 1;       for (int i = 1; i <= 10; i++) {         pows[i] = (pows[i - 1] * int64_t(10)) % k;       }       for (int i = 0; i < n; i++) {         int a;         in >> a;         int aa = a % k;         int len = 1;         while (a >= 10) {           a /= 10;           len++;         }         as[len - 1].push_back(aa);       }       for (size_t i = 0; i < as.size(); i++) {         std::sort(as[i].begin(), as[i].end());       }       int64_t ans = 0;       for (int i = 0; i < 10; i++) {         for (int j = 0; j < 10; j++) {           ans += calcPair(i, j);         }       }       out << ans <<   n ;     }   };   int main() {     std::cin.sync_with_stdio(false);     std::cin.tie(nullptr);     Solution().run(std::cin, std::cout);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int pai[1000010];   int find(int x) {     if (pai[x] == x) return x;     return pai[x] = find(pai[x]);   }   void join(int a, int b) { pai[find(a)] = find(b); }   int main() {     int n, m, q;     cin >> n >> m >> q;     for (int i = 1; i <= n + m; i++) pai[i] = i;     for (int i = 0; i < q; i++) {       int a, b;       cin >> a >> b;       b += n;       join(a, b);     }     int comps = 0;     for (int i = 1; i <= n + m; i++) comps += pai[i] == i;     cout << comps - 1 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     long long n;     long long k;     cin >> n;     cin >> k;     vector<long long> d(n);     vector<long long> afterd(n);     for (long long i = 0; i < n; i++) cin >> d[i];     for (long long i = 0; i < n; i++) cin >> afterd[i];     vector<pair<long long, long long> > utility(n);     for (long long i = 0; i < n; i++) {       utility[i].first = d[i] - afterd[i];       utility[i].second = i;     }     sort(utility.begin(), utility.end());     set<long long> u2;     long long p = 0;     while (k > 0 || utility[p].first < 0) {       u2.insert(utility[p].second);       p += 1;       k -= 1;     }     long long cost = 0;     for (long long i = 0; i < n; i++) {       if (u2.find(i) != u2.end())         cost += d[i];       else         cost += afterd[i];     }     cout << cost;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 10005;   const int P = 998244353;   struct edge {     int u, v, len;     inline edge() {}     inline edge(int _u, int _v, int _len) {       u = _u;       v = _v;       len = _len;     }   } a[N], Q[N], res[N];   struct node {     int l, r;     vector<int> E;     node *lson, *rson;   } pool[3 * N], *root;   int n, m;   int OscarDaGumert;   int top = -1;   int Index, cnt;   bitset<N> cur;   bitset<N> ans;   void B_T(node *now, int l, int r) {     now->l = l;     now->r = r;     if (l == r) return;     int lr = (l + r) >> 1, rl = lr + 1;     now->lson = &pool[++top];     B_T(now->lson, l, lr);     now->rson = &pool[++top];     B_T(now->rson, rl, r);   }   void change(node *now, int l, int r, int id) {     if (now->l == l && now->r == r) {       now->E.push_back(a[id].len);       return;     }     int lr = (now->l + now->r) >> 1, rl = lr + 1;     if (r < rl)       change(now->lson, l, r, id);     else if (l > lr)       change(now->rson, l, r, id);     else {       change(now->lson, l, lr, id);       change(now->rson, rl, r, id);     }   }   inline void query(node *now) {     bitset<N> tmp = cur;     int len = now->E.size();     for (int i = 0; i < len; i++) {       cur |= (cur << now->E[i]);     }     ans |= cur;     if (now->l != now->r) {       query(now->lson);       query(now->rson);     }     cur = tmp;   }   void init() {     int x1, x2, x3;     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; i++) {       scanf( %d%d%d , &x1, &x2, &x3);       a[i] = edge(x1, x2, x3);     }     root = &pool[++top];     B_T(root, 1, n);     for (int i = 1; i <= m; i++) change(root, a[i].u, a[i].v, i);     cur[0] = 1;     query(root);     int cnt = 0;     for (int i = 1; i <= n; i++) {       if (ans[i] == 1) {         cnt++;       }     }     printf( %d n , cnt);     for (int i = 1; i <= n; i++) {       if (ans[i] == 1) {         printf( %d  , i);       }     }   }   int main(int argc, char **argv) {     init();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 9;   const long long INF = 1e18;   const int MAXN = 1e6 + 10;   const int MAXM = 1e4 + 500;   const int N = 2000 + 15;   const double EPS = 1e-9;   int dx[] = {1, 0, 0, -1};   int dy[] = {0, 1, -1, 0};   double len(complex<long long> a) {     return sqrt(a.real() * a.real() + a.imag() * a.imag());   }   long long sq(complex<long long> a) {     return a.real() * a.real() + a.imag() * a.imag();   }   complex<long long> perp(complex<long long> p) { return {-p.imag(), p.real()}; }   long long dotProduct(complex<long long> a, complex<long long> b) {     return (conj(a) * b).real();   }   long long crossProduct(complex<long long> a, complex<long long> b) {     return (conj(a) * b).imag();   }   long long orient(complex<long long> a, complex<long long> b,                    complex<long long> c) {     return crossProduct(b - a, c - a);   }   bool inDisk(complex<long long> a, complex<long long> b, complex<long long> p) {     return dotProduct(a - p, b - p) <= 0;   }   bool onSegment(complex<long long> a, complex<long long> b,                  complex<long long> p) {     return orient(a, b, p) == 0 && inDisk(a, b, p);   };   struct cmpX {     bool operator()(complex<long long> a, complex<long long> b) {       return make_pair(a.real(), a.imag()) < make_pair(b.real(), b.imag());     }   };   struct line {     complex<long long> v;     long long c;     line(complex<long long> v, long long c) : v(v), c(c) {}     line(long long a, long long b, long long c) : v({b, -a}), c(c) {}     line(complex<long long> p, complex<long long> q)         : v(q - p), c(crossProduct(v, p)) {}     long long side(complex<long long> p) { return crossProduct(v, p) - c; }     double dist(complex<long long> p) { return abs(side(p)) / len(v); }     line perpThrough(complex<long long> p) { return {p, p + perp(v)}; }     bool cmpProj(complex<long long> p, complex<long long> q) {       return dotProduct(v, p) < dotProduct(v, q);     }     line translate(complex<long long> t) { return {v, c + crossProduct(v, t)}; }     complex<long long> proj(complex<long long> p) {       return p - perp(v) * side(p) / sq(v);     }   };   double segPoint(complex<long long> a, complex<long long> b,                   complex<long long> p) {     if (a != b) {       line l(a, b);       if (l.cmpProj(a, p) && l.cmpProj(p, b)) return l.dist(p);     }     return min(abs(p - a), abs(p - b));   }   bool inAngle(complex<long long> a, complex<long long> b, complex<long long> c,                complex<long long> p) {     if (orient(a, b, c) < 0) swap(b, c);     return orient(a, b, p) >= 0 && orient(a, c, p) <= 0;   }   bool isInsidePol(vector<complex<long long> > &a, complex<long long> b) {     int n = a.size();     int pos = 0, neg = 0;     for (int i = 0; i < n - 1; i++) {       if (onSegment(a[i], a[(i + 1) % n], b)) return false;       line l(a[i], a[i + 1]);       if (l.side(b) > 0)         pos++;       else         neg++;     }     line l(a[n - 1], a[0]);     if (l.side(b) > 0)       pos++;     else       neg++;     return ((!pos && neg == n) || (!neg && pos == n));   }   long long i, j, k;   long long n, m, t;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     string w;     cin >> w;     stack<int> kek;     kek.push(0);     for (auto e : w) {       e == kek.top() ? kek.pop() : kek.push(e);     }     cout << (kek.top() ?  No  :  Yes );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, k;   int p[55];   string t;   void getp() {     int j = 0;     p[0] = p[1] = 0;     for (int i = 1; i < t.length(); ++i) {       while (j && t[j] != t[i]) j = p[j];       if (t[j] == t[i]) j++;       p[i + 1] = j;     }   }   void build() {     getp();     string ans = t;     int cnt = 1;     while (cnt < k) {       for (int i = p[t.length()]; i < t.length(); ++i) ans.append(1, t[i]);       cnt++;     }     cout << ans;   }   int main() {     cin >> n >> k >> t;     build();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, u, r;   vector<long long> k;   vector<int> a, b, p, tmp;   vector<vector<int> > v;   vector<int> w;   void read();   int main() {     ios_base::sync_with_stdio(false);     read();     v.push_back(a);     w.push_back(1);     long long s = 0;     if (u & 1)       s = -1e15;     else {       for (int i = 0; i < n; ++i) s += (a[i] * k[i]);     }     int uu = (u < 29 ? u : u - 2);     for (int i = 0; i < uu; ++i) {       int lim = v.size();       for (int j = 0; j < lim; ++j) {         if (w[j]) {           v.push_back(v[j]);           w.push_back(0);           for (int h = 0; h < n; ++h) v.back()[h] ^= b[h];           for (int h = 0; h < n; ++h) tmp[h] = v[j][p[h]] + r;           swap(v[j], tmp);         } else {           w[j] = 1;           for (int h = 0; h < n; ++h) tmp[h] = v[j][p[h]] + r;           swap(v[j], tmp);         }       }       if ((u - i) & 1) {         for (int i = 0; i < v.size(); ++i) {           long long ss = 0;           for (int j = 0; j < n; ++j) ss += (v[i][j] * k[j]);           s = max(s, ss);         }       }     }     if (uu < u) {       for (int i = 0; i < v.size(); ++i) {         long long ss = 0;         for (int j = 0; j < n; ++j) tmp[j] = (v[i][p[j]] ^ b[p[j]]) + r;         for (int j = 0; j < n; ++j) ss += (tmp[j] * k[j]);         s = max(s, ss);         ss = 0;         for (int j = 0; j < n; ++j) tmp[j] = ((v[i][p[j]] + r) ^ b[j]);         for (int j = 0; j < n; ++j) ss += (tmp[j] * k[j]);         s = max(s, ss);         ss = 0;         for (int j = 0; j < n; ++j) tmp[j] = v[i][p[p[j]]] + r + r;         for (int j = 0; j < n; ++j) ss += (tmp[j] * k[j]);         s = max(s, ss);       }     }     cout << s << endl;     return 0;   }   void read() {     cin >> n >> u >> r;     a.resize(n);     b.resize(n);     k.resize(n);     p.resize(n);     tmp.resize(n);     for (int i = 0; i < n; ++i) cin >> a[i];     for (int i = 0; i < n; ++i) cin >> b[i];     for (int i = 0; i < n; ++i) cin >> k[i];     for (int i = 0; i < n; ++i) cin >> p[i], --p[i];   }


#include <bits/stdc++.h>   using namespace std;   const int maxN = 2005;   int d[maxN][maxN], c[maxN][maxN], D[maxN], C[maxN], dx[maxN][maxN],       cx[maxN][maxN];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n, k;     cin >> n >> k;     char cur;     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= n; ++j) {         cin >> cur;         d[i][j] = d[i][j - 1] + (cur ==  W );         c[i][j] = c[i - 1][j] + (cur ==  W );       }     for (int i = 1; i <= n; ++i) {       D[i] = D[i - 1] + (d[i][n] == n);       C[i] = C[i - 1] + (c[n][i] == n);     }     for (int i = 1; i <= n; ++i)       for (int j = k; j <= n; ++j)         dx[i][j] = dx[i - 1][j] + (d[i][n] - d[i][j] + d[i][j - k] == n - k);     for (int i = k; i <= n; ++i)       for (int j = 1; j <= n; ++j)         cx[i][j] = cx[i][j - 1] + (c[n][j] - c[i][j] + c[i - k][j] == n - k);     int ans = 0;     for (int i = k; i <= n; ++i)       for (int j = k; j <= n; ++j)         ans = max(ans, D[n] - D[i] + D[i - k] + dx[i][j] - dx[i - k][j] + C[n] -                            C[j] + C[j - k] + cx[i][j] - cx[i][j - k]);     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, a[500010], x, sz;   long long ans;   int main() {     scanf( %d , &n);     for (int step = 1; step <= n; step++) {       scanf( %d , &x);       while (a[sz - 1] > a[sz] && a[sz] <= x && sz >= 2) {         ans += min(a[sz - 1], x);         sz--;       }       a[++sz] = x;     }     sort(a + 1, a + sz + 1);     for (int i = 1; i <= sz - 2; i++) ans += a[i];     printf( %I64d , ans);   }


#include <bits/stdc++.h>   using namespace std;   int n;   vector<int> v;   vector<int> ans_lis;   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     cin >> n;     for (int i = 1; i <= n; i++) {       int x;       cin >> x;       v.emplace_back(x);     }     sort(v.begin(), v.end());     for (int i = (int)v.size() - 1; i >= 0; i--) {       if (i % 2 == 0) {         ans_lis.insert(ans_lis.begin(), v[i]);       } else         ans_lis.emplace_back(v[i]);     }     bool flag = true;     if (ans_lis[0] >= ans_lis.back() + ans_lis[1]) flag = false;     if (ans_lis.back() >= ans_lis[0] + ans_lis[(int)ans_lis.size() - 2])       flag = false;     for (int i = 1; i + 1 < (int)ans_lis.size() && flag; i++) {       if (ans_lis[i] >= ans_lis[i + 1] + ans_lis[i - 1]) flag = false;     }     if (!flag)       cout <<  NO  << endl;     else {       cout <<  YES  << endl;       for (int i = 0; i < (int)ans_lis.size(); i++) cout << ans_lis[i] <<    ;       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   long long mx, mi;   int t, head[N], len, k, vis[N];   struct edge {     int v, w, next;   } e[N * 2];   void add(int u, int v, int w) {     e[len].v = v;     e[len].w = w;     e[len].next = head[u];     head[u] = len++;   }   void dfs(int u, int fa) {     vis[u] = 1;     for (int j = head[u]; j; j = e[j].next) {       int v = e[j].v;       int w = e[j].w;       if (v == fa) continue;       dfs(v, u);       if (vis[v] & 1) {         mi += w;       }       mx += (long long)min(k - vis[v], vis[v]) * w;       vis[u] += vis[v];     }   }   int main() {     scanf( %d , &t);     while (t--) {       scanf( %d , &k);       int u, v, w;       k <<= 1;       len = 1;       memset(head, 0, sizeof(head));       memset(vis, 0, sizeof(vis));       for (int i = 1; i < k; i++) {         scanf( %d%d%d , &u, &v, &w);         add(u, v, w);         add(v, u, w);       }       mi = 0, mx = 0;       dfs(1, 0);       printf( %lld %lld n , mi, mx);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, cnt = 0;   long long sum = 0;   bool flag = false;   struct Node {     int num;     int pos;   } a[200005];   bool cmp(const Node &a, const Node &b) { return a.num < b.num; }   vector<int> v;   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i].num;       a[i].pos = i;       sum += a[i].num;     }     sort(a + 1, a + n + 1, cmp);     for (int i = 1; i <= n - 1; i++) {       if (sum - a[i].num == 2 * a[n].num) {         cnt++;         v.push_back(a[i].pos);       }     }     if (sum - a[n].num == 2 * a[n - 1].num) {       v.push_back(a[n].pos);       cnt++;     }     if (cnt == 0) {       cout << 0 << endl;       return 0;     }     cout << cnt << endl;     for (int i = 0; i < v.size(); i++) {       cout << v[i] <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string itosm(long long x) {     if (x == 0) return  0 ;     string ans =   ;     while (x > 0) {       ans += ((x % 10) +  0 );       x /= 10;     }     reverse(ans.begin(), ans.end());     return ans;   }   long long stoim(string str) {     long long ans = 0;     long long k = 1;     for (int i = str.length() - 1; i >= 0; i--) {       ans += (str[i] -  0 ) * k;       k *= 10;     }     return ans;   }   const long long infll = 1e18 + 3;   const int inf = 1009000999;   const double eps = 1e-6;   const int maxn = 1e6 + 77;   const int baseint = 1000200013;   const long long basell = 1e18 + 3;   const long double PI = acos(-1.0);   int main() {     srand(228228);     ios_base::sync_with_stdio(0);     ;     string t, s, p =   ;     cin >> t >> s;     int n = s.length();     while (p.length() != n) p +=  0 ;     int cnt = 0;     for (int i = (0); i < (n); i++) {       if (s[i] == t[i])         p[i] = s[i];       else         cnt++;     }     if (cnt % 2) {       cout <<  impossible ;       return 0;     }     cnt = 0;     for (int i = (0); i < (n); i++) {       if (s[i] != t[i]) {         if (cnt <= 0) {           p[i] = s[i];           cnt++;         } else {           p[i] = t[i];           cnt--;         }       }     }     cout << p;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string s;   string name, host, sour;   int main() {     ios::sync_with_stdio(false);     cin >> s;     int i = 0;     while (i < s.size() && s[i] !=  @ ) {       name.push_back(s[i]);       i++;     }     i++;     while (i < s.size() && s[i] !=  / ) {       host.push_back(s[i]);       i++;     }     bool exist = 0;     if (s[i] ==  / ) exist = 1;     i++;     if (i != s.size() + 1)       while (i < s.size()) {         sour.push_back(s[i]);         i++;       }     if (sour.size() > 16 || name.size() == 0 || name.size() > 16 ||         host.size() > 32 || host.size() == 0) {       cout <<  NO n ;       return 0;     }     if (exist && sour.size() == 0) {       cout <<  NO n ;       return 0;     }     for (int j = 0; j < name.size(); j++) {       char c = name[j];       if (!isdigit(c) && !isalpha(c) && (c !=  <  && c !=  >  && c !=  _ )) {         cout <<  NO n ;         return 0;       }     }     int cnt = 0;     for (int j = 0; j < host.size(); j++) {       char c = host[j];       if (!isdigit(c) && !isalpha(c) &&           (c !=  <  && c !=  >  && c !=  .  && c !=  _ )) {         cout <<  NO n ;         return 0;       }       if (c ==  . ) {         if (cnt == 0) {           cout <<  NO n ;           return 0;         }         cnt = -1;       }       cnt++;       if (cnt > 16) {         cout <<  NO n ;         return 0;       }     }     if (cnt == 0) {       cout <<  NO n ;       return 0;     }     for (int j = 0; j < sour.size(); j++) {       char c = sour[j];       if (!isalpha(c) && !isdigit(c) && (c !=  <  && c !=  >  && c !=  _ )) {         cout <<  NO n ;         return 0;       }     }     cout <<  YES n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int min(int a, int b) {     if (a < b)       return a;     else       return b;   }   int main() {     int n, len, a[100010], f[100010], dai, max = 0, vitri = 0;     char s[100010];     char si[13][13];     bool kt;     scanf( %s , s);     len = strlen(s);     for (int i = 0; i < len; i++) f[i] = 0;     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %s , si[i]);     for (int i = 0; i < len; i++) {       dai = 100;       for (int j = 1; j <= n; j++) {         kt = true;         for (int k = 0; k < strlen(si[j]); k++)           if (si[j][k] != s[i + k]) {             kt = false;             break;           }         if (kt && strlen(si[j]) < dai) dai = strlen(si[j]);       }       a[i] = dai;     }     f[len] = 0;     for (int i = len - 1; i >= 0; i--) {       if (a[i] != 100)         f[i] = min(f[i + 1] + 1, a[i] - 1);       else         f[i] = f[i + 1] + 1;       if (f[i] > max) {         max = f[i];         vitri = i;       }     }     printf( %d %d , max, vitri);   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   void chmax(T &x, T y) {     x = x > y ? x : y;   }   template <class T>   void chmin(T &x, T y) {     x = x < y ? x : y;   }   const int maxn = 205;   int n, k;   int d[maxn], ans[maxn], choice[maxn];   int dp[maxn][maxn];   int dist[maxn][maxn];   vector<int> v[maxn];   void predfs(int pos, int fa, int *dis) {     for (int i = 0; i < (int)(v[pos]).size(); i++) {       int to = v[pos][i];       if (to == fa) continue;       dis[to] = dis[pos] + 1;       predfs(to, pos, dis);     }   }   void dfs(int pos, int fa) {     for (int i = 1; i <= n; i++) dp[pos][i] = d[dist[pos][i]] + k;     for (int i = 0; i < (int)(v[pos]).size(); i++) {       int to = v[pos][i];       if (to == fa) continue;       dfs(to, pos);       for (int j = 1; j <= n; j++)         dp[pos][j] += min(dp[to][choice[to]], dp[to][j] - k);     }     choice[pos] = min_element(dp[pos] + 1, dp[pos] + n + 1) - dp[pos];     return;   }   void print(int pos, int fa, int j) {     for (int i = 0, _j; i < (int)(v[pos]).size(); i++) {       int to = v[pos][i];       if (to == fa) continue;       if (dp[to][choice[to]] < dp[to][j] - k) {         _j = choice[to];       } else {         _j = j;       }       ans[to] = _j;       print(to, pos, _j);     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> k;     for (int i = 1; i <= n - 1; i++) cin >> d[i];     for (int i = 1; i <= n - 1; i++) {       int x, y;       cin >> x >> y;       v[x].push_back(y);       v[y].push_back(x);     }     for (int i = 1; i <= n; i++) predfs(i, 0, dist[i]);     dfs(1, 0);     cout << dp[1][choice[1]] << endl;     print(1, 0, choice[1]);     ans[1] = choice[1];     for (int i = 1; i <= n; i++) cout << ans[i] <<    ;     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, x, y;   int a, b;   int diff;   void ask(int mask) {     int sz = 0;     for (int i = 0; i < n; ++i) {       if ((i & mask) > 0) {         ++sz;       }     }     if (sz == 0) {       return;     }     printf( ? %d , sz);     for (int i = 0; i < n; ++i) {       if ((i & mask) > 0) {         printf(  %d , i + 1);       }     }     printf(  n );     fflush(stdout);     int ans = 0;     scanf( %d , &ans);     if (ans != 0 && ans != x) {       diff += mask;     }   }   vector<int> v;   bool f(int sr) {     printf( ? %d , sr + 1);     for (int i = 0; i <= sr; ++i) {       printf(  %d , v[i] + 1);     }     printf(  n );     fflush(stdout);     int ans;     scanf( %d , &ans);     if (ans != 0 && ans != x) {       return true;     }     return false;   }   void input() { scanf( %d%d%d , &n, &x, &y); }   void solve() {     for (int i = 0; i < 10; ++i) {       ask((1 << i));     }     for (int i = 0; i < n; ++i) {       if ((i ^ diff) < i) {         v.push_back(i);       }     }     int l, r, mid;     l = 0;     r = v.size() - 1;     while (l != r) {       int mid = (l + r) / 2;       if (f(mid) == true) {         r = mid;       } else {         l = mid + 1;       }     }     printf( ! %d %d n , (v[l] ^ diff) + 1, v[l] + 1);     fflush(stdout);   }   int main() {     ios_base ::sync_with_stdio(false);     cin.tie(NULL);     input();     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = ~0U >> 1;   const long long INF = (long long)1e18;   const double pi = acos(-1.0);   template <class T>   inline T sqr(T a) {     return a * a;   }   template <class T>   inline T min(T a, T b, T c) {     return min(min(a, b), c);   }   template <class T>   inline T max(T a, T b, T c) {     return max(max(a, b), c);   }   template <class T>   inline void read(T &n) {     char c;     for (c = getchar(); !(c >=  0  && c <=  9 ); c = getchar())       ;     n = c -  0 ;     for (c = getchar(); c >=  0  && c <=  9 ; c = getchar()) n = n * 10 + c -  0 ;   }   int pw(int base, int n, int mo) {     if (n == 0) return 1;     if (n == 1) return base;     int tmp = pw(base, n >> 1, mo);     tmp = (long long)tmp * tmp % mo;     if (n & 1) tmp = (long long)tmp * base % mo;     return tmp;   }   const int maxn = 200000;   int N, M, x, y, p[maxn], c[maxn], f[maxn], s[maxn];   long long ans;   bool cmp(const int &a, const int &b) { return c[a] > c[b]; }   vector<int> E[maxn];   int find(int x) {     if (f[x] == x) return x;     int t = find(f[x]);     s[x] += s[f[x]];     return f[x] = t;   }   int main() {     scanf( %d%d , &N, &M);     for (int i = (1); i <= (N); ++i) scanf( %d , &c[i]);     for (int i = (1); i <= (M); ++i) {       scanf( %d%d , &x, &y);       if (c[x] < c[y])         E[x].push_back(y);       else         E[y].push_back(x);     }     for (int i = (1); i <= (N); ++i) p[i] = i;     sort(p + 1, p + N + 1, cmp);     for (int i = (1); i <= (N); ++i) f[i] = i, s[i] = 1;     for (int i = (1); i <= (N); ++i) {       int S = p[i];       for (int j = 0; j < E[S].size(); ++j) {         int x = find(S), y = find(E[S][j]);         if (x != y) {           ans += (long long)c[S] * s[x] * s[y];           f[x] = y;           s[y] += s[x];         }       }     }     double ret = ans * 2. / N / (N - 1);     printf( %.10lf n , ret);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int x, y;   long long s;   int main() {     cin >> x >> y >> s;     if (abs(x) + abs(y) <= s && (s - (abs(x) + abs(y))) % 2 == 0)       cout <<  Yes ;     else       cout <<  No ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int t, n;   string str;   int main() {     cin >> t;     while (t--) {       cin >> n >> str;       int x = n, res = n;       for (int i = 0; i < n; i++)         if (str[i] ==  1 ) {           res = max(res, max(n + 1, 2 * max(i + 1, n - i)));         }       cout << res << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   long long a, b, T;   char s[500010];   long long pref[500010];   long long suff[500010];   int main() {     cin >> n >> a >> b >> T;     for (int i = 1; i <= n; ++i) {       cin >> s[i];     }     pref[1] = 0;     for (int i = 2; i <= n; ++i) {       pref[i] = a + pref[i - 1] + 1;       if (s[i] ==  w ) {         pref[i] += b;       }     }     suff[n + 1] = 0;     for (int i = n; i >= 2; --i) {       suff[i] = a + 1 + suff[i + 1];       if (s[i] ==  w ) {         suff[i] += b;       }     }     int ans = 0;     long long t = 1;     if (s[1] ==  w ) {       t += b;     }     if (T < t) {       cout << 0;       return 0;     }     T -= t;     ++ans;     for (int i = 2; i <= n; ++i) {       if (pref[i] > T) {         break;       }       ans = max(ans, i);       long long t = T - pref[i] - (i - 1) * a;       if (t < 0) {         continue;       }       int l = i;       int r = n + 1;       while (l + 1 < r) {         int m = (l + r) / 2;         if (suff[m] <= t) {           r = m;         } else {           l = m;         }       }       ans = max(ans, i + n + 1 - r);     }     for (int i = n; i >= 2; --i) {       if (suff[i] > T) {         break;       }       ans = max(n - i + 2, ans);       long long t = T - suff[i] - (n + 1 - i) * a;       if (t < 0) {         continue;       }       int l = 1, r = i;       while (l + 1 < r) {         int m = (l + r) / 2;         if (pref[m] <= t) {           l = m;         } else {           r = m;         }       }       ans = max(ans, n - i + 1 + l);     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 60;   const int M = 40010;   const int OFF = 20005;   int n, m;   int lt[N], rt[N];   set<int> cnt;   bitset<N> ll[M], rr[M];   int main() {     cin >> n >> m;     for (int i = 0; i < n; i++) {       cin >> lt[i];     }     for (int i = 0; i < m; i++) {       cin >> rt[i];       for (int j = 0; j < n; j++) {         cnt.insert(lt[j] + rt[i] + OFF);         ll[lt[j] + rt[i] + OFF].set(j);         rr[lt[j] + rt[i] + OFF].set(i);       }     }     int m1 = 0;     for (auto cc1 : cnt) {       for (auto cc2 : cnt) {         bitset<N> unl = ll[cc1] | ll[cc2];         bitset<N> unr = rr[cc1] | rr[cc2];         m1 = max(m1, int(unl.count() + unr.count()));       }     }     printf( %d n , m1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 1e9 + 5;   const long long linf = 1e18 + 5;   class point {    public:     int x, y;     double m;     point() {}     point(int x, int y) {       this->x = x;       this->y = y;       this->m = atan2(y, x);     }     bool operator<(point other) const { return m < other.m; }     bool operator==(point other) const {       return x == other.x and y == other.y and m == other.m;     }   };   int n, c, x, y, sumx, sumy;   pair<int, int> a[5];   set<point> s;   long long ccw(point a, point c, point b) {     pair<int, int> v1 = make_pair(c.x - a.x, c.y - a.y);     pair<int, int> v2 = make_pair(b.x - a.x, b.y - a.y);     return (long long)v1.first * v2.second - (long long)v1.second * v2.first;   }   set<point>::iterator something_stupid_(point x) {     set<point>::iterator it = s.lower_bound(x);     if (it == s.end()) it = s.begin();     return it;   }   set<point>::iterator something_stupid_(set<point>::iterator it) {     it++;     if (it == s.end()) it = s.begin();     return it;   }   set<point>::iterator _something_stupid(set<point>::iterator it) {     if (it == s.begin()) {       it = s.end();       it--;     } else       it--;     return it;   }   int main() {     ios ::sync_with_stdio(0);     cin >> n;     for (int i = 1; i <= 3; i++) {       cin >> c >> a[i].first >> a[i].second;       sumx += a[i].first;       sumy += a[i].second;     }     pair<int, int> cent = make_pair(sumx, sumy);     for (int i = 1; i <= 3; i++) {       a[i].first *= 3;       a[i].second *= 3;       a[i].first -= cent.first;       a[i].second -= cent.second;       point t(a[i].first, a[i].second);       s.insert(t);     }     for (int i = 4; i <= n; i++) {       cin >> c >> x >> y;       x *= 3;       y *= 3;       x -= cent.first;       y -= cent.second;       point t(x, y);       if (c == 1) {         set<point>::iterator left = something_stupid_(t);         set<point>::iterator right = _something_stupid(left);         if (ccw(*left, *right, t) <= 0) continue;         while (s.size() >= 2 and ccw(t, *left, *something_stupid_(left)) <= 0) {           set<point>::iterator it = left;           left = something_stupid_(left);           s.erase(it);         }         right = _something_stupid(left);         while (s.size() >= 2 and ccw(t, *right, *_something_stupid(right)) >= 0) {           set<point>::iterator it = right;           right = _something_stupid(right);           s.erase(it);         }         s.insert(t);       } else {         set<point>::iterator left = something_stupid_(t);         set<point>::iterator right = _something_stupid(left);         if (ccw(*left, *right, t) <= 0)           cout <<  YES  <<   n ;         else           cout <<  NO  <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     long long n, m, ta, tb, k, res = 0;     cin >> n >> m >> ta >> tb >> k;     if (k >= n || k >= m) {       cout << -1;       return 0;     }     vector<long long> a(n), b(m);     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < m; i++) cin >> b[i];     for (int i = 0; i < n && i <= k; i++) {       long long search = a[i] + ta;       long long l = -1;       long long r = m;       long long mid;       while (l != r - 1) {         mid = (l + r) / 2;         if (b[mid] >= search)           r = mid;         else           l = mid;       }       if (r + max(0LL, k - i) >= m) {         cout << -1;         return 0;       }       res = max(res, b[r + max(0LL, k - i)] + tb);     }     cout << res;   }


#include <bits/stdc++.h>   using namespace std;   long long n, k;   int arr[400009];   map<int, int> mp;   vector<int> v;   int sum[400009];   int main() {     cin >> n >> k;     for (int i = 0; i < n; i++) {       scanf( %d , &arr[i]);       if (mp[arr[i]] == 0) {         v.push_back(arr[i]);       }       mp[arr[i]]++;     }     sort(v.begin(), v.end());     k *= 8;     int ans = 1000000009;     int j = 0;     int num = 0;     int curr = 0;     for (int i = 0; i < v.size(); i++) {       curr += mp[v[i]];     }     for (int i = 0; i < v.size(); i++) {       while (j < v.size() && ceil(log2(j - i + 1)) * n <= k) {         curr -= mp[v[j]];         j++;       }       ans = min(ans, curr);       j = max(i, j);       curr += mp[v[i]];     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int tt = 120;     int test[6] = {0, 1, 3, 5, 2, 4};     int n = 5;     int p[2001], s[2001];     int p_l[2001], s_l[2001];     int ans = 0;     vector<pair<int, int> > v_ans;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &p[i]);       p_l[p[i]] = i;     }     for (int i = 1; i <= n; i++) s[i] = i;     for (int i = 1; i <= n; i++) {       scanf( %d , &s[i]);       s_l[s[i]] = i;     }     for (int i = 1; i <= n; i++) {       if (p[i] != s[i]) {         int r = p_l[s[i]];         for (int j = i; j <= r; j++) {           int pos_j = s_l[p[j]];           int pos_r = s_l[p[r]];           if ((pos_j >= r && pos_r <= j && pos_j != pos_r)) {             ans += abs(j - r);             v_ans.push_back(make_pair(j, r));             swap(p[j], p[r]);             swap(p_l[p[j]], p_l[p[r]]);             r = j;             j = i - 1;           }         }       }     }     printf( %d n%d n , ans, v_ans.size());     for (int i = 0; i < v_ans.size(); i++)       printf( %d %d n , v_ans[i].first, v_ans[i].second);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int H, M, K;   int NonZeroDigit(int x) {     int res = 0;     while (x) {       if (x % 10) res++;       x /= 10;     }     return res;   }   int Get(int x, int p) {     for (int i = 1; i < p; ++i) x /= 10;     return x;   }   long long Solve(int h, int m) {     int d = NonZeroDigit(M - 1);     long long res = Get(h, K - d);     res += (long long)Get(m, K) + (long long)h * Get(M - 1, K);     return res;   }   int main() {     cin >> H >> M >> K;     int h1, m1, h2, m2;     cin >> h1 >> m1 >> h2 >> m2;     if (pair<int, int>(h1, m1) <= pair<int, int>(h2, m2))       cout << Solve(h2, m2) - Solve(h1, m1) << endl;     else       cout << Solve(H - 1, M - 1) - Solve(h1, m1) +                   (NonZeroDigit(H - 1) + NonZeroDigit(M - 1) >= K) + Solve(h2, m2)            << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a1, a2, a3, a4;   int head;   int b, c;   int nott(int x) {     if (x == 4) return 7;     return 4;   }   int main() {     cin >> a1 >> a2 >> a3 >> a4;     if (abs(a3 - a4) > 1) {       cout << -1 << endl;       return 0;     }     if (a3 > a4) head = 4;     if (a4 > a3) head = 7;     c = a3;     b = a4;     if (!head) {       if (b != a1)         head = 4;       else         head = 7;     }     if (head) {       if (head == 7)         c++;       else         b++;     }     if (b > a1 || c > a2) {       cout << -1 << endl;       return 0;     }     if (head == 7) {       cout << 7;       a2--;       a4--;       c--;     }     for (int i = 0; i < a1 - (b - 1); ++i) cout << 4;     for (int i = 0; i < b - 1 - (b == c + 1); ++i) cout << 74;     for (int i = 0; i < a2 - (b - 1) + (b == c + 1); ++i) cout << 7;     if (b == c + 1) cout << 4;     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string st, t;   vector<string> a;   int p;   int main() {     ios_base ::sync_with_stdio(false);     cin >> st;     for (auto i : st) {       t += i;       if (i ==  > ) {         a.push_back(t);         t =   ;       }     }     for (auto i : a) {       if (i[1] ==  / ) {         --p;       }       for (int j = 0; j < p; ++j) {         cout <<     ;       }       cout << i << endl;       if (i[1] !=  / ) {         ++p;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int a[110][110], row[110], col[110], ansrow[110], anscol[110], n, m, tans, ans;   bool flag;   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) scanf( %d , &a[i][j]);     ans = 10000000;     for (int i = 0; i <= 500; i++) {       row[1] = i;       flag = 1;       for (int j = 1; j <= m; j++)         if (a[1][j] < i) {           flag = 0;           break;         } else           col[j] = a[1][j] - i;       if (!flag) break;       for (int j = 2; j <= n; j++) {         if (a[j][1] - col[1] < 0) {           flag = 0;           break;         }         row[j] = a[j][1] - col[1];         for (int k = 2; k <= m; k++)           if (a[j][k] - col[k] != row[j]) {             flag = 0;             break;           }         if (!flag) break;       }       if (!flag) continue;       tans = 0;       for (int j = 1; j <= n; j++) tans += row[j];       for (int j = 1; j <= m; j++) tans += col[j];       if (tans < ans) {         ans = tans;         for (int j = 1; j <= n; j++) ansrow[j] = row[j];         for (int j = 1; j <= m; j++) anscol[j] = col[j];       }     }     if (ans == 10000000) {       printf( -1 );       return 0;     }     printf( %d n , ans);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= ansrow[i]; j++) printf( row %d n , i);     for (int i = 1; i <= m; i++)       for (int j = 1; j <= anscol[i]; j++) printf( col %d n , i);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[1000050];   vector<int> vec[1000050];   int pos[1000050];   int main() {     int n, x;     scanf( %d%d , &n, &x);     for (int i = 0; i < n; i++) {       scanf( %d , a + i);       vec[a[i]].push_back(i);     }     pos[x + 1] = n;     int st = 1;     for (int i = x; i; i--) {       pos[i] = pos[i + 1];       if (vec[i].size()) {         if (vec[i].back() < pos[i]) {           pos[i] = vec[i][0];         } else {           st = i + 1;           break;         }       }     }     int cur = -1;     long long res = 0;     for (int i = 1; i <= x; i++) {       int p = lower_bound(pos + st, pos + x + 1, cur) - pos;       p = max(p, i + 1);       res += (x - p + 2);       if (p == i) res--;       if (vec[i].size()) {         if (cur < vec[i][0])           cur = vec[i].back();         else           break;       }     }     printf( %lld n , res);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     int n, k;     cin >> n >> k;     priority_queue<pair<int, int> > p;     set<int> s;     for (int i = 1; i <= n; i++) {       int in;       cin >> in;       p.push({in, i});       s.insert(i + k);     }     long long ans = 0;     vector<int> v(n);     while (p.size()) {       int c = p.top().first, d = p.top().second;       p.pop();       auto it = s.lower_bound(d);       ans += 1LL * (*it - d) * c;       v[d - 1] = *it;       s.erase(it);     }     cout << ans <<   n ;     for (auto i : v) cout << i <<    ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     ;     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string arf[1005], ars[1005];   string ans[1005];   void solve() {     int n;     cin >> n;     map<string, vector<int> > f, s;     int done[n];     memset(done, 0, sizeof(done));     ;     for (int i = 0; i < (int)(n); i++) {       string s1, s2;       cin >> s1 >> s2;       arf[i] = s1.substr(0, 3);       ars[i] = s1.substr(0, 2) + s2.substr(0, 1);       f[arf[i]].push_back(i);       s[ars[i]].push_back(i);     }     map<string, int> final;     for (auto i = f.begin(); i != f.end(); i++) {       if (i->second.size() > 1) {         for (int k = 0; k < i->second.size(); k++) {           final[ars[i->second[k]]]++;           ans[i->second[k]] = ars[i->second[k]];           done[i->second[k]] = 1;         }       }     }     for (int i = 0; i < n; i++) {       if (done[i] == 0) {         if (final[ars[i]] == 0) {           final[ars[i]] = 1;           ans[i] = ars[i];         } else if (final[arf[i]] == 0) {           final[arf[i]] = 1;           ans[i] = arf[i];         } else {           cout <<  NO ;           return;         }       }     }     for (auto i = final.begin(); i != final.end(); i++) {       if (i->second > 1) {         cout <<  NO ;         return;       }     }     cout <<  YES n ;     for (int i = 0; i < (int)(n); i++) {       cout << ans[i] <<   n ;     }   }   int main() {     cin.tie(0);     cout.tie(0);     cin.sync_with_stdio(0);     cout.sync_with_stdio(0);     int TC = 1;     for (int ZZ = 1; ZZ <= TC; ZZ++) {       clock_t start = clock();       solve();       clock_t end = clock();       cerr <<  Time:   << (double)(end - start) / CLOCKS_PER_SEC <<   seconds             <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 20;   int h[maxn], n, q, cnt;   string s;   struct Node {     int ans, mx, mn, l, r, lazy;     Node(int a = 0) { ans = mn = mx = l = r = lazy = a; }     void update(Node a, Node b) {       ans = max({a.ans, b.ans, a.l + b.mx, b.r + a.mx});       mx = max({a.mx, b.mx});       mn = min({a.mn, b.mn});       l = max({a.l, b.l, a.mx - 2 * b.mn});       r = max({a.r, b.r, b.mx - 2 * a.mn});     }   } sg[4 * maxn];   void add(int qval, int id) {     sg[id].l -= qval;     sg[id].r -= qval;     sg[id].mn += qval;     sg[id].mx += qval;     sg[id].lazy += qval;   }   void shift(int id) {     add(sg[id].lazy, id * 2);     add(sg[id].lazy, id * 2 + 1);     sg[id].lazy = 0;   }   void update(int l, int r, int ql, int qr, int qval, int id) {     if (l >= ql && r <= qr)       add(qval, id);     else if (l > qr || r < ql)       return;     else {       int mid = (l + r) / 2;       shift(id);       update(l, mid, ql, qr, qval, id * 2);       update(mid + 1, r, ql, qr, qval, id * 2 + 1);       sg[id].update(sg[id * 2], sg[id * 2 + 1]);     }   }   void build(int l, int r, int id) {     if (l == r) {       sg[id].mn = sg[id].mx = h[r];       sg[id].l = sg[id].r = -h[r];     } else {       int mid = (l + r) / 2;       build(l, mid, id * 2);       build(mid + 1, r, id * 2 + 1);       sg[id].update(sg[id * 2], sg[id * 2 + 1]);     }   }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cin >> n >> q >> s;     for (int i = 0; i < 2 * n - 2; i++) {       if (s[i] ==  ( )         cnt++;       else         cnt--;       h[i + 2] = cnt;     }     build(1, 2 * n - 1, 1);     int a, b, tmp;     cout << sg[1].ans << endl;     while (q--) {       cin >> a >> b;       if (a > b) swap(a, b);       tmp = 0;       if (s[a - 1] ==  (  && s[b - 1] ==  ) ) tmp = -2;       if (s[a - 1] ==  )  && s[b - 1] ==  ( ) tmp = 2;       update(1, 2 * n - 1, a + 1, b, tmp, 1);       cout << sg[1].ans << endl;       swap(s[a - 1], s[b - 1]);     }   }


#include <bits/stdc++.h>   using namespace std;   int safeop(int n, int mod) { return (n + mod) % mod; }   int main() {     int n;     cin >> n;     vector<int> v(n, 0);     vector<pair<int, int>> ans(n);     for (int i = 0; i < n; i++) {       cin >> v[i];     }     int vn = n;     int v1 = -1;     stack<int> bal1;     stack<int> bal2;     stack<int> bal3;     for (int i = 0; i < n; i++) {       if (v[i] == 3) {         if (vn - v1 == 1) {           cout << -1;           return 0;         }         vn--;         ans[i] = make_pair(vn, -1);         if (!bal3.empty()) {           int tmp = bal3.top();           bal3.pop();           ans[tmp].second = i;           bal3.push(i);         } else {           bal3.push(i);         }       } else if (v[i] == 2) {         if (vn - v1 == 1) {           cout << -1;           return 0;         }         v1++;         ans[i] = make_pair(v1, -1);         if (!bal3.empty()) {           int tmp = bal3.top();           bal3.pop();           ans[tmp].second = i;           bal2.push(i);         } else {           bal2.push(i);         }       } else if (v[i] == 1) {         if (!bal2.empty()) {           int tmp = bal2.top();           bal2.pop();           ans[tmp].second = i;           ans[i] = make_pair(ans[tmp].first, 0);         } else if (!bal3.empty()) {           if (vn - v1 == 1) {             cout << -1;             return 0;           }           vn--;           ans[i] = make_pair(vn, 0);           int tmp = bal3.top();           bal3.pop();           ans[tmp].second = i;         } else {           if (vn - v1 == 1) {             cout << -1;             return 0;           }           vn--;           ans[i] = make_pair(vn, 0);         }       } else {         continue;       }     }     for (int i = 0; i < n; i++) {       if (ans[i].second == -1) {         cout << -1 << endl;         return 0;       }     }     set<pair<int, int>> ansset;     for (int i = 0; i < n; i++) {       if (v[i] == 1) {         ansset.insert(make_pair(i + 1, ans[i].first + 1));       }       if (v[i] == 2) {         ansset.insert(make_pair(i + 1, ans[i].first + 1));         ansset.insert(make_pair(ans[i].second + 1, ans[i].first + 1));       }       if (v[i] == 3) {         ansset.insert(make_pair(i + 1, ans[i].first + 1));         ansset.insert(make_pair(ans[i].second + 1, ans[i].first + 1));         ansset.insert(make_pair(ans[i].second + 1, ans[ans[i].second].first + 1));       }     }     cout << ansset.size() << endl;     for (auto it = ansset.begin(); it != ansset.end(); ++it) {       cout << n + 1 - it->second <<     << it->first << endl;     }   }


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


#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline bool upmin(T &x, T y) {     return y < x ? x = y, 1 : 0;   }   template <typename T>   inline bool upmax(T &x, T y) {     return x < y ? x = y, 1 : 0;   }   const long double eps = 1e-9;   const long double pi = acos(-1);   const int oo = 1 << 30;   const long long loo = 1ll << 60;   const int mods = 1e9 + 7;   const int inv2 = (mods + 1) >> 1;   const int MAXN = 510005;   const int INF = 0x3f3f3f3f;   namespace FastIO {   constexpr int SIZE = (1 << 21) + 1;   int num = 0, f;   char ibuf[SIZE], obuf[SIZE], que[65], *iS, *iT, *oS = obuf,                                                   *oT = obuf + SIZE - 1, c;   inline void flush() {     fwrite(obuf, 1, oS - obuf, stdout);     oS = obuf;   }   inline void putc(char c) {     *oS++ = c;     if (oS == oT) flush();   }   inline void getc(char &c) {     for (c = (iS == iT ? (iT = ((iS = ibuf) + fread(ibuf, 1, SIZE, stdin)),                          (iS == iT ? EOF : *iS++))                        : *iS++);          !isalpha(c) && c != EOF;          c = (iS == iT ? (iT = ((iS = ibuf) + fread(ibuf, 1, SIZE, stdin)),                          (iS == iT ? EOF : *iS++))                        : *iS++))       ;   }   inline void reads(char *st) {     char c;     int n = 0;     getc(st[++n]);     for (c = (iS == iT ? (iT = ((iS = ibuf) + fread(ibuf, 1, SIZE, stdin)),                          (iS == iT ? EOF : *iS++))                        : *iS++);          isalpha(c);          c = (iS == iT ? (iT = ((iS = ibuf) + fread(ibuf, 1, SIZE, stdin)),                          (iS == iT ? EOF : *iS++))                        : *iS++))       st[++n] = c;     st[n + 1] =   0 ;   }   template <class I>   inline void read(I &x) {     for (f = 1, c = (iS == iT ? (iT = ((iS = ibuf) + fread(ibuf, 1, SIZE, stdin)),                                 (iS == iT ? EOF : *iS++))                               : *iS++);          c <  0  || c >  9 ;          c = (iS == iT ? (iT = ((iS = ibuf) + fread(ibuf, 1, SIZE, stdin)),                          (iS == iT ? EOF : *iS++))                        : *iS++))       if (c ==  - ) f = -1;     for (x = 0; c >=  0  && c <=  9 ;          c = (iS == iT ? (iT = ((iS = ibuf) + fread(ibuf, 1, SIZE, stdin)),                          (iS == iT ? EOF : *iS++))                        : *iS++))       x = (x << 3) + (x << 1) + (c & 15);     x *= f;   }   template <class I>   inline void print(I x) {     if (x < 0) putc( - ), x = -x;     if (!x) putc( 0 );     while (x) que[++num] = x % 10 + 48, x /= 10;     while (num) putc(que[num--]);   }   struct Flusher_ {     ~Flusher_() { flush(); }   } io_Flusher_;   }  // namespace FastIO   using FastIO ::print;   using FastIO ::putc;   using FastIO ::read;   using FastIO ::reads;   char st[1005], ST[1005];   long long f[1005][1005], K;   int ch[MAXN][26], num = 0, n, m, nodenum = 1, a[MAXN];   pair<int, int> flag[MAXN];   void solve(int x) {     if (!x) return;     for (int i = 25; i >= 0; --i) solve(ch[x][i]);     if (flag[x].first) a[++num] = x;   }   void insert(int l, int r) {     int nw = 1;     for (int i = l; i <= r; ++i) {       if (!ch[nw][st[i] -  a ]) ch[nw][st[i] -  a ] = ++nodenum;       nw = ch[nw][st[i] -  a ];     }     flag[nw] = make_pair(l, r);   }   long long check(int x) {     int len = 0;     for (int i = flag[a[x]].first; i <= flag[a[x]].second; ++i) ST[++len] = st[i];     for (int i = 0; i <= n; ++i)       for (int j = 0; j <= m; ++j) f[i][j] = 0;     f[0][0] = 1;     for (int i = 0; i < n; ++i) {       int id = len;       for (int j = 1; j <= len && i + j - 1 <= n; ++j)         if (st[i + j] < ST[j]) {           id = INF;           break;         } else if (st[i + j] > ST[j]) {           id = j;           break;         }       if (i + id <= n) {         for (int j = 0; j < m; ++j)           if (f[i + id][j + 1] < loo) f[i + id][j + 1] += f[i][j];       }       for (int j = 1; j <= m; ++j)         if (f[i + 1][j] < loo) f[i + 1][j] += f[i][j];     }     return f[n][m];   }   signed main() {     read(n), read(m), read(K), reads(st);     for (int i = 1; i <= n; ++i)       for (int j = i; j <= n; ++j) insert(i, j);     solve(1);     int l = 1, r = num;     while (l < r) {       int mid = (l + r) >> 1;       if (check(mid) >= K)         r = mid;       else         l = mid + 1;     }     for (int i = flag[a[l]].first; i <= flag[a[l]].second; ++i) putc(st[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int t, n;   string s;   int main(void) {     cin >> t;     while (t--) {       map<pair<int, int>, int> m;       int start = 0, end = 2147483647, x = 0, y = 0;       cin >> n >> s;       s.insert(s.begin(),  0 );       m.insert({make_pair(0, 0), 0});       for (int i = 1; i < s.size(); i++) {         if (s[i] ==  L )           x -= 1;         else if (s[i] ==  R )           x += 1;         else if (s[i] ==  U )           y += 1;         else           y -= 1;         pair<int, int> p = make_pair(x, y);         if (m.find(p) == m.end()) {           m.insert({p, i});         } else {           if (i - m[p] < end - start) {             start = m[p] + 1;             end = i;           }           m[p] = i;         }       }       if (end == 2147483647)         cout <<  -1 n ;       else         cout << start <<     << end << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 20;   const int M = 1e5 + 55;   pair<int, int> dp[(1 << N) + 5];   int dis[N][N];   int My[(1 << N) + 5][N];   int taken[(1 << N) + 5][N];   char s[M];   int sum[N];   int lg[(1 << N) + 55];   int m, n;   pair<int, int> bt(int mask) {     if (mask == (1 << n) - 1) return {0, 0};     pair<int, int>& ret = dp[mask];     if (ret.first != -1) return ret;     ret = {10000000, 0};     int cur = 0;     pair<int, int> nxt;     for (int v = 0; v < n; v++) {       if ((mask & (1 << v)) == 0) {         nxt = bt(mask + (1 << v));         cur = nxt.second - My[mask][v];         cur += nxt.first + taken[mask][v];         if (cur < ret.first)           ret = {cur, nxt.second + taken[mask][v] - My[mask][v]};       }     }     return ret;   }   void prep(int mask, int i, int l, int pre) {     if (i == n - 1) {       taken[mask][l] = pre;       My[mask][l] = 0;       return;     }     if (My[mask][l] != -1) return;     for (int j = 0; j < n; j++) {       if ((mask & (1 << j)) == 0 && j != l) {         prep(mask + (1 << j), i + 1, l, pre + dis[l][j]);         My[mask][l] = My[mask + (1 << j)][l] + dis[l][j];       }     }     taken[mask][l] = pre;   }   int main() {     memset(dp, -1, sizeof dp);     memset(My, -1, sizeof My);     scanf( %d %d , &m, &n);     scanf( %s , s);     for (int i = 0; i < m - 1; i++) {       if (s[i] != s[i + 1]) {         dis[s[i] -  a ][s[i + 1] -  a ]++;         sum[s[i] -  a ]++;         sum[s[i + 1] -  a ]++;         dis[s[i + 1] -  a ][s[i] -  a ]++;       }     }     for (int i = 0; i < n; i++) lg[(1 << i)] = i;     int ms;     for (int l = 0; l < n; l++) {       for (int mask = (1 << n) - 1; mask >= 0; mask--) {         if (mask & (1 << l)) continue;         mask += (1 << l);         ms = mask | (mask + 1);         mask -= (1 << l);         ms -= (1 << l);         if (ms >= (1 << n)) {           taken[mask][l] = sum[l];           My[mask][l] = 0;           continue;         }         My[mask][l] = My[ms][l] + dis[lg[mask ^ ms]][l];         taken[mask][l] = taken[ms][l] - dis[l][lg[mask ^ ms]];       }     }     cout << bt(0).first << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long a[100001];   int main() {     long long int n, i, count = 0;     long long sum = 0;     scanf( %I64d , &n);     for (i = 0; i < n; i++) scanf( %I64d , a + i);     sort(a, a + n);     for (i = 0; i < n; i++) {       if (sum <= a[i]) {         count++;         sum += a[i];       }     }     printf( %I64d n , count);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int x, y, idx;     cin >> x >> y >> idx;     if (idx == 0)       cout << x << endl;     else if (idx == 1)       cout << y << endl;     else {       idx -= 2;       int z;       while (true) {         z = x + y;         idx--;         if (idx < 0) break;         x = y;         y = z;       }       cout << z << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   using INT = unsigned long long;   const int N = 100000;   struct Ring {     INT a[5];     Ring() { memset(a, 0, sizeof a); }     Ring operator+(Ring r) {       Ring R = r;       for (int i = 0; i < 5; i++) R.a[i] += a[i];       return R;     }     void operator+=(Ring r) { (*this) = (*this) + r; }     Ring operator*(Ring r) {       Ring R;       for (int i = 0; i < 5; i++)         for (int j = 0; j < 5; j++)           i + j < 5 ? R.a[i + j] += a[i] * r.a[j]                     : R.a[i + j - 5] -= a[i] * r.a[j];       return R;     }     void operator*=(Ring r) { (*this) = (*this) * r; }     Ring operator<<(int k) {       Ring R;       for (int i = 0; i < 5; i++) {         int j = (i + k) % 10;         j < 5 ? R.a[j] = a[i] : R.a[j - 5] = -a[i];       }       return R;     }     INT real() { return a[0] + a[1]; }   } x[N], w[10], tmp[10];   INT power(INT a, INT n, INT ans = 1) {     for (; n; n >>= 1, a *= a)       if (n & 1) ans *= a;     return ans;   }   Ring power(Ring a, INT n) {     Ring ans;     ans.a[0] = 1;     for (; n; n >>= 1, a *= a)       if (n & 1) ans *= a;     return ans;   }   void DFT(Ring *P, int op) {     for (int i = 1; i < N; i *= 10) {       for (int p = i * 10, j = 0; j < N; j += p) {         for (int k = 0; k < i; k++) {           for (int x = 0; x < 10; x++) tmp[x] = P[j + k + x * i];           for (int x = 0; x < 10; x++) {             Ring &r = P[j + k + x * i];             r = Ring();             for (int y = 0; y < 10; y++) r += tmp[y] << x * y * op;           }         }       }     }   }   int n;   int main() {     scanf( %d , &n);     for (int i = 0, k; i < n; i++) {       scanf( %d , &k);       x[k].a[0]++;     }     DFT(x, 1);     for (int i = 0; i < N; i++) x[i] = power(x[i], n);     DFT(x, 9);     INT inv = power(5, (1ull << 63) - 5);     for (int i = 0; i < n; i++)       printf( %I64d n , (x[i].real() >> 5) * inv & ((1ull << 58) - 1));     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base ::sync_with_stdio(false);     cin.tie(NULL);     long long int tests = 1;     while (tests--) {       long long int n;       int x;       cin >> n >> x;       if (n % 6 == 0)         cout << x;       else if (n % 6 == 1) {         if (x == 0)           cout << 1;         else if (x == 1)           cout << 0;         else           cout << 2;       } else if (n % 6 == 2) {         if (x == 0)           cout << 1;         else if (x == 1)           cout << 2;         else           cout << 0;       } else if (n % 6 == 3) {         if (x == 0)           cout << 2;         else if (x == 1)           cout << 1;         else           cout << 0;       } else if (n % 6 == 4) {         if (x == 0)           cout << 2;         else if (x == 1)           cout << 0;         else           cout << 1;       } else {         if (x == 0)           cout << 0;         else if (x == 1)           cout << 2;         else           cout << 1;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T, typename U>   ostream &operator<<(ostream &out, const pair<T, U> &p) {     out <<  (  << p.first <<  ,   << p.second <<  ) ;     return out;   }   template <template <typename, typename...> class ContainerType,             typename ValueType, typename... Args>   void print(const ContainerType<ValueType, Args...> &c) {     for (const auto &v : c) cout << v <<    ;     cout <<   n ;   }   void print() { cout <<   n ; }   template <typename T, typename... Args>   void print(T a, Args... args) {     cout << a <<    ;     print(args...);   }   long long llipower(long long x, long long y, long long p = LLONG_MAX) {     long long res = 1;     x = x % p;     while (y > 0) {       if (y & 1) res = (res * x) % p;       y = y >> 1;       x = (x * x) % p;     }     return res;   }   int main() {     int t;     cin >> t;     while (t--) {       int x, y, z;       cin >> x >> y >> z;       if (x == y && x >= z) {         cout <<  YES               <<   n ;         print(x, 1, z);       } else if (y == z && y >= x) {         cout <<  YES               <<   n ;         print(1, x, y);       } else if (z == x && x >= y) {         cout <<  YES               <<   n ;         print(1, x, y);       } else {         cout <<  NO               <<   n ;       }     }   }


#include <bits/stdc++.h>   int isPerfectSquare(int number) {     int iVar;     float fVar;     fVar = sqrt((double)number);     iVar = fVar;     if (iVar == fVar)       return 1;     else       return 0;   }   int main() {     int no;     scanf( %d n , &no);     int a[no];     int max;     max = -1000000;     for (int i = 0; i < no; i++) {       scanf( %d , &a[i]);     }     for (int i = 0; i < no; i++) {       if (isPerfectSquare(a[i]))         continue;       else {         if (a[i] > max) max = a[i];       }     }     printf( %d , max);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 7;   vector<int> ad[N];   int h[N], n, m, dp[N][30];   int d[N], R = 320;   vector<int> red;   void dfs(int v, int p) {     h[v] = h[p] + 1;     dp[v][1] = p;     for (auto u : ad[v]) {       if (u != p) dfs(u, v);     }   }   int dis(int u, int v) {     int res = 0;     if (h[v] < h[u]) swap(v, u);     for (int i = 20; i >= 1; i--) {       if (h[v] - (1 << (i - 1)) >= h[u]) {         res += (1 << (i - 1));         v = dp[v][i];       }     }     if (u == v) return res;     for (int i = 20; i >= 1; i--) {       if (dp[v][i] != dp[u][i]) {         res += 2 * (1 << (i - 1));         v = dp[v][i];         u = dp[u][i];       }     }     return res + 2;   }   void bfs() {     deque<int> dq;     memset(d, 0, sizeof d);     for (auto u : red) dq.push_back(u), d[u] = 1;     while (dq.size()) {       int v = dq[0];       dq.pop_front();       for (auto u : ad[v]) {         if (!d[u]) d[u] = d[v] + 1, dq.push_back(u);       }     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m;     for (int i = 1; i < n; i++) {       int u, v;       cin >> u >> v;       ad[u].push_back(v);       ad[v].push_back(u);     }     for (int i = 1; i <= n; i++) dp[i][0] = i;     dfs(1, 0);     for (int j = 2; j <= 20; j++)       for (int i = 1; i <= n; i++) dp[i][j] = dp[dp[i][j - 1]][j - 1];     vector<int> pos;     red.push_back(1);     bfs();     while (m--) {       int t;       cin >> t;       if (t == 1) {         int tt;         cin >> tt;         pos.push_back(tt);         if (pos.size() > R) {           for (auto u : pos) {             red.push_back(u);           }           bfs();           pos.clear();         }       } else {         int v;         cin >> v;         int res = d[v] - 1;         for (auto u : pos) res = min(res, dis(v, u));         cout << res <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK: 1024000000,1024000000 )   using namespace std;   inline int getint() {     int _x = 0;     char _tc = getchar();     while (_tc <  0  || _tc >  9 ) _tc = getchar();     while (_tc >=  0  && _tc <=  9 ) _x *= 10, _x += (_tc -  0 ), _tc = getchar();     return _x;   }   const int N = 1e6 + 35;   const int NN = N * 4;   int lazy[NN], mx[NN], a[N], b[N];   void push_down(int rt) {     if (lazy[rt]) {       lazy[rt << 1] += lazy[rt];       lazy[rt << 1 | 1] += lazy[rt];       mx[rt << 1] += lazy[rt];       mx[rt << 1 | 1] += lazy[rt];       lazy[rt] = 0;     }   }   void push_up(int rt) { mx[rt] = max(mx[rt << 1], mx[rt << 1 | 1]); }   void update(int rt, int l, int r, int L, int R, int v) {     if (L <= l && r <= R) {       lazy[rt] += v;       mx[rt] += v;       return;     }     int mid = l + r >> 1;     push_down(rt);     if (L <= mid) update(rt << 1, l, mid, L, R, v);     if (R > mid) update(rt << 1 | 1, mid + 1, r, L, R, v);     push_up(rt);   }   int query(int rt, int l, int r) {     if (l == r) {       return l;     }     push_down(rt);     int mid = l + r >> 1;     if (mx[rt << 1 | 1] > 0) return query(rt << 1 | 1, mid + 1, r);     return query(rt << 1, l, mid);   }   int main() {     int n, m, q;     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]), update(1, 1, N, 1, a[i], 1);     for (int i = 1; i <= m; i++) scanf( %d , &b[i]), update(1, 1, N, 1, b[i], -1);     scanf( %d , &q);     while (q--) {       int op, x, y;       scanf( %d%d%d , &op, &x, &y);       if (op == 1) {         update(1, 1, N, 1, a[x], -1);         a[x] = y;         update(1, 1, N, 1, a[x], 1);       } else {         update(1, 1, N, 1, b[x], 1);         b[x] = y;         update(1, 1, N, 1, b[x], -1);       }       if (mx[1] <= 0)         puts( -1 );       else         printf( %d n , query(1, 1, N));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using LL = long long;   using uint = unsigned int;   template <typename T>   inline void read(T& x) {     x = 0;     long long f = 1;     register char c = getchar();     for (; !isdigit(c); c = getchar())       if (c ==  - ) f = -1;     for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c & 15);     x *= f;   }   template <typename T>   inline void print(T x) {     if (!x) {       putchar( 0 );       return;     }     static long long st[105];     if (x < 0) putchar( - ), x = -x;     long long tp = 0;     while (x) st[++tp] = x % 10, x /= 10;     while (tp) putchar(st[tp--] +  0 );   }   template <typename T>   inline void print(T x, char c) {     print(x);     putchar(c);   }   template <typename T, typename... Args>   inline void read(T& x, Args&... args) {     read(x);     read(args...);   }   template <typename T>   inline void sort(vector<T>& v) {     sort(v.begin(), v.end());     return;   }   template <typename T>   inline void unique(vector<T>& v) {     sort(v);     v.erase(unique(v.begin(), v.end()), v.end());   }   template <typename T>   inline void cmax(T& x, T y) {     if (x < y) x = y;     return;   }   template <typename T>   inline void cmin(T& x, T y) {     if (x > y) x = y;     return;   }   const long long Mod = LLONG_MAX;   inline long long QP(long long x, long long y) {     long long ans = 1;     for (; y; y >>= 1, x = (x * x) % Mod)       if (y & 1) ans = (ans * x) % Mod;     return ans;   }   template <typename T>   inline T gcd(T x, T y) {     if (y == 0) return x;     return gcd(y, x % y);   }   template <typename T>   inline T lcm(T x, T y) {     return x * y / gcd(x, y);   }   template <typename T>   inline void mul(T& x, T y) {     x = 1LL * x * y;     if (x >= Mod) x %= Mod;   }   template <typename T>   inline void add(T& x, T y) {     if ((x += y) >= Mod) x -= Mod;   }   template <typename T>   inline void sub(T& x, T y) {     if ((x -= y) < 0) x += Mod;   }   signed main() {     long long T;     read(T);     while (T--) {       string s;       getline(cin, s);       vector<long long> od, ev, ans;       for (auto x : s)         if (x -  0  & 1)           od.push_back(x -  0 );         else           ev.push_back(x -  0 );       reverse(ev.begin(), ev.end());       reverse(od.begin(), od.end());       long long st1 = ev.size(), st2 = od.size();       while (st1 || st2) {         if (!st2 || (st1 && ev[st1 - 1] < od[st2 - 1])) {           ans.push_back(ev[--st1]);         } else {           ans.push_back(od[--st2]);         }       }       for (long long x : ans) print(x);       putchar(  n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 0x3f3f3f3f3f3f3f3f;   const long long MAXN = 4e3 + 7;   const long long MAXM = 1e6 + 7;   const long long MOD = 1e9 + 7;   const double eps = 1e-6;   const double pi = acos(-1.0);   long long quick_pow(long long a, long long b) {     long long ans = 1;     while (b) {       if (b & 1) ans = (1LL * ans * a) % MOD;       a = (1LL * a * a) % MOD;       b >>= 1;     }     return ans;   }   int c[305][305];   long long ksm1[305], ksm2[305];   int main() {     long long n, k;     scanf( %lld%lld , &n, &k);     c[0][0] = 1;     c[1][0] = c[1][1] = 1;     for (int i = 2; i <= n; i++) {       c[i][0] = 1;       for (int j = 1; j <= i; j++)         c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % MOD;     }     ksm1[0] = ksm2[0] = 1;     for (int i = 1; i <= n; i++)       ksm1[i] = (ksm1[i - 1] * k) % MOD, ksm2[i] = (ksm2[i - 1] * (k - 1)) % MOD;     long long ans = 0;     long long t = 1;     for (int i = 0; i <= n; i++) {       ans += t * c[n][i] * quick_pow((ksm1[n - i] * ksm2[i] - ksm2[n]) % MOD, n) %              MOD;       t *= -1;       ans %= MOD;     }     printf( %lld n , (ans % MOD + MOD) % MOD);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename... T>   void err(istream_iterator<string> it) {}   template <typename T, typename... Args>   void err(istream_iterator<string> it, T a, Args... args) {     cerr << *it <<  =  << a <<  ,  ;     err(++it, args...);   }   const long long inf = 1LL << 60;   const long long md = 1000000007;   vector<long long> adj[200005];   long long vis[200005] = {0};   void bfs(long long s) {     queue<long long> q;     vis[s] = 1;     q.push(s);     while (!q.empty()) {       long long s = q.front();       q.pop();       for (auto i : adj[s]) {         if (vis[i]) continue;         vis[i] = vis[s] + 1;         q.push(i);       }     }   }   long long vis2[200005] = {0};   void bfs2(long long s) {     queue<long long> q;     vis2[s] = 1;     q.push(s);     while (!q.empty()) {       long long s = q.front();       q.pop();       for (auto i : adj[s]) {         if (vis2[i]) continue;         vis2[i] = vis2[s] + 1;         q.push(i);       }     }   }   bool comp(pair<long long, long long> a, pair<long long, long long> b) {     return a.first - a.second < b.first - b.second;   }   void solve() {     long long n, m, k;     cin >> n >> m >> k;     long long a[k];     for (long long i = 0; i < k; i++) {       cin >> a[i];     }     for (long long i = 0; i < m; i++) {       long long x, y;       cin >> x >> y;       adj[x].push_back(y);       adj[y].push_back(x);     }     bfs(1);     bfs2(n);     pair<long long, long long> d[k];     for (long long i = 0; i < k; i++) {       d[i] = {vis[a[i]], vis2[a[i]]};     }     sort(d, d + k, comp);     long long ans = 0;     long long mx = -inf;     for (long long i = 0; i < k; i++) {       ans = max(ans, mx + d[i].second);       mx = max(mx, d[i].first);     }     cout << min(vis[n] - 1, ans - 1);   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long t = 1;     for (long long i = 1; i <= t; i++) {       solve();       cout <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 10, inf = 0x3f3f3f3f;   void cmin(int& x, int y) {     if (x > y) {       x = y;     }   }   int n, a[N];   long long answer;   vector<int> adj[N];   void dfs(int u, int p, int d, int s) {     if (d & 1) {       answer += a[u] - s;       s = a[u];     } else {       int minv = inf;       for (auto v : adj[u]) {         if (v != p) {           cmin(minv, a[v]);         }       }       if (minv < s) {         puts( -1 );         exit(0);       } else if (minv != inf) {         answer += minv - s;         s = minv;       }     }     for (auto v : adj[u]) {       if (v != p) {         dfs(v, u, d + 1, s);       }     }   }   int main() {     scanf( %d , &n);     for (int i = 2; i <= n; ++i) {       int x;       scanf( %d , &x);       adj[x].push_back(i);     }     for (int i = 1; i <= n; ++i) {       scanf( %d , &a[i]);     }     dfs(1, 0, 1, 0);     printf( %lld n , answer);     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC optimize( unroll-loops )   #pragma GCC optimize( -ffloat-store )   #pragma GCC optimize( -fno-defer-pop )   long long power(long long a, long long b, long long m) {     if (b == 0) return 1;     if (b == 1) return a % m;     long long t = power(a, b / 2, m);     t = (t * t) % m;     if (b & 1) t = (t * a) % m;     return t;   }   using namespace std;   int main() {     ;     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     long long t;     cin >> t;     while (t--) {       long long a, b, c, d;       cin >> a >> b >> c >> d;       long long x, y, x1, y1, x2, y2;       cin >> x >> y >> x1 >> y1 >> x2 >> y2;       if (x2 - x1 == 0 && (a != 0 || b != 0)) {         cout <<  NO  << endl;         continue;       }       if (y2 - y1 == 0 && (c != 0 || d != 0)) {         cout <<  NO  << endl;         continue;       }       long long disx, disy;       disx = b - a;       disy = d - c;       if (0 <= disx) {         if (x2 - x < disx) {           cout <<  NO  << endl;           continue;         }       } else {         if (x - x1 < (-disx)) {           cout <<  NO  << endl;           continue;         }       }       if (0 <= disy) {         if (y2 - y < disy) {           cout <<  NO  << endl;           continue;         }       } else {         if (y - y1 < (-disy)) {           cout <<  NO  << endl;           continue;         }       }       cout <<  YES  << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int n;   int x[100000];   int dist(int a, int b) { return abs(a - b); }   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) cin >> x[i];     cout << dist(x[0], x[1]) <<     << dist(x[0], x[n - 1]) << endl;     for (int i = 1; i < n - 1; i++)       cout << min(dist(x[i], x[i - 1]), dist(x[i], x[i + 1])) <<                << max(dist(x[i], x[0]), dist(x[i], x[n - 1])) << endl;     cout << dist(x[n - 1], x[n - 2]) <<     << dist(x[0], x[n - 1]) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     string s;     int sz;     cin >> n;     cin >> s;     sz = s.size();     int count = 0;     bool valid = true;     for (int i = 0; i < sz; i++) {       if (s[i] ==  1 ) {         if (i < sz - 1 && s[i + 1] ==  1 ) {           valid = false;         }         count++;       } else {         if ((i == 0 || s[i - 1] ==  0 )) {           if (i == sz - 1 || s[i + 1] ==  0 ) {             valid = false;           }         }       }     }     if (valid == true && count > 0) {       cout <<  Yes  << endl;     } else {       cout <<  No  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 500, mod = 998244353;   int K, tmp[N], tmpa[N], tmpb[N], rev[N], b[N], tw[N], w[N], limn, n, qn;   vector<int> a[N];   int qpower(int a, int b) {     int ans = 1;     for (; b; b >>= 1, a = 1ll * a * a % mod)       if (b & 1) ans = 1ll * ans * a % mod;     return ans;   }   void prework(int n) {     limn = 1;     while (limn <= n) limn <<= 1;     for (int i = 1; i < limn; i++)       rev[i] = (rev[i >> 1] >> 1) | ((i & 1) ? (limn >> 1) : 0);     for (int i = 1; i < limn; i <<= 1) {       int omg = qpower(3, (mod - 1) / (i << 1));       w[i] = 1;       for (int j = 1; j < i; j++) w[i + j] = 1ll * w[i + j - 1] * omg % mod;     }   }   void NTT(int a[], int l) {     for (int i = 0; i < l; i++) tmp[rev[i] / (limn / l)] = a[i];     for (int i = 1; i < l; i <<= 1)       for (int j = 0; j < l; j += i << 1)         for (int k = 0; k < i; k++) {           int x = tmp[j + k], y = 1ll * w[i + k] * tmp[i + j + k] % mod;           tmp[j + k] = (x + y) % mod, tmp[i + j + k] = (x - y) % mod;         }     for (int i = 0; i < l; i++) a[i] = tmp[i];   }   void mul(const vector<int> A, const vector<int> B, vector<int>& c) {     int la = A.size(), lb = B.size(), n = la + lb - 1;     int l = 1;     while (l < n) l <<= 1;     for (int i = 0; i < la; i++) tmpa[i] = A[i];     for (int i = la; i < l; i++) tmpa[i] = 0;     for (int i = 0; i < lb; i++) tmpb[i] = B[i];     for (int i = lb; i < l; i++) tmpb[i] = 0;     NTT(tmpa, l), NTT(tmpb, l);     for (int i = 0; i < l; i++) tmpa[i] = 1ll * tmpa[i] * tmpb[i] % mod;     reverse(tmpa + 1, tmpa + l);     NTT(tmpa, l);     int iv = mod - (mod - 1) / l;     if (K + 1 < n) n = K + 1;     c.resize(n);     for (int i = 0; i < n; i++) c[i] = 1ll * tmpa[i] * iv % mod;   }   void solve(int rot, int lt, int rt) {     if (lt == rt) {       a[rot].resize(2);       a[rot][0] = 1, a[rot][1] = b[lt];       return;     }     int mid = (lt + rt) >> 1;     solve(rot << 1, lt, mid), solve(rot << 1 | 1, mid + 1, rt);     mul(a[rot << 1], a[rot << 1 | 1], a[rot]);   }   int main() {     scanf( %d%d , &n, &K);     prework(n);     for (int i = 1; i <= n; i++) scanf( %d , tw + i);     scanf( %d , &qn);     for (int i = 1, opt, l, r, q, d; i <= qn; i++) {       scanf( %d , &opt);       if (opt == 1) {         scanf( %d%d%d , &q, &l, &d);         for (int j = 1; j <= n; j++) b[j] = q - tw[j];         b[l] = q - d;         solve(1, 1, n);         printf( %d n , (a[1][K] + mod) % mod);       } else {         scanf( %d%d%d%d , &q, &l, &r, &d);         for (int j = 1; j <= n; j++) b[j] = q - tw[j];         for (int j = l; j <= r; j++) b[j] -= d;         solve(1, 1, n);         printf( %d n , (a[1][K] + mod) % mod);       }     }   }


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


#include <bits/stdc++.h>   using namespace std;   struct FenwickTree {     int n;     vector<int> bit;     FenwickTree(int n) {       this->n = n + 1;       bit.assign(n + 1, 0);     }     int sum(int r) {       int sum = 0;       while (r > 0) {         sum += bit[r];         r -= (r & -r);       }       return sum;     }     int sum(int l, int r) { return sum(r) - sum(l - 1); }     void add(int index, int val) {       while (index < n) {         bit[index] += val;         index += (index & -index);       }     }     int getNum(int index) { return sum(index, index); }   };   int main() {     int n, k, a, b, q;     cin >> n >> k >> a >> b >> q;     FenwickTree antes = FenwickTree(n);     FenwickTree depois = FenwickTree(n);     while (q--) {       int type, d, val;       cin >> type >> d;       if (type == 1) {         cin >> val;         int aux1 = min(b - antes.getNum(d), val);         int aux2 = min(a - depois.getNum(d), val);         antes.add(d, aux1);         depois.add(d, aux2);       } else {         int resp = 0;         resp += antes.sum(d - 1);         resp += depois.sum(d + k, n);         cout << resp << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, d, a, b, x, y, ans = 0;   pair<int, int> m[111111];   long long sum = 0;   int main() {     scanf( %d%d%d%d , &n, &d, &a, &b);     for (int i = 0; i < n; i++) {       scanf( %d%d , &x, &y);       m[i].first = a * x + b * y;       m[i].second = i + 1;     }     sort(m, m + n);     for (int i = 0; i < n; i++) {       sum += m[i].first;       if (sum > d) break;       ans++;     }     printf( %d n , ans);     for (int i = 0; i < ans; i++) printf( %d  , m[i].second);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int LIMIT = 3e5;   long long n, m, a[LIMIT], p[LIMIT], d[LIMIT];   long long gcd(long long a, long long b) {     if (a % b == 0) return b;     return gcd(b, a % b);   }   int main() {     scanf( %lld %lld , &n, &m);     for (int i = 0; i < n; i++) {       scanf( %lld , &a[i]);     }     for (int i = 0; i < m; i++) {       scanf( %lld , &p[i]);     }     for (int i = 0; i < (n - 1); i++) {       d[i] = a[i + 1] - a[i];     }     long long gcdAll = d[0];     for (int i = 1; i < (n - 1); i++) {       gcdAll = gcd(d[i], gcdAll);     }     for (int i = 0; i < m; i++) {       if ((gcdAll % p[i]) == 0) {         printf( %s n%lld %d ,  YES , a[0], (i + 1));         return 0;       }     }     printf( %s ,  NO );     return 0;   }