#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   const int mod = 1e9 + 7;   int n, a[N];   long long ans;   map<long long, int> cnt;   void go(long long pos) {     cnt[pos]++;     if (cnt[pos] == 2) {       cnt[pos] = 0;       go(pos + 1);     }   }   int main() {     ios_base::sync_with_stdio(0);     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i];       go(a[i]);     }     for (auto i : cnt) ans = i.first;     ans++;     for (auto i : cnt)       if (i.second == 1) ans--;     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 10;   const double eps = 1e-5;   const int maxN = 1100;   const int inf = 1e9 + 100;   int n, m, k;   bool vis[maxN][maxN];   inline void init() {     int a, b;     cin >> n >> m >> k;     for (int i = 0; i < k; i++) {       cin >> a >> b;       a--;       b--;       vis[a][b] = 1;       bool br = false;       if (a > 0 && b > 0 && vis[a - 1][b - 1] && vis[a - 1][b] && vis[a][b - 1])         br = true;       if (a < n - 1 && b > 0 && vis[a + 1][b - 1] && vis[a + 1][b] &&           vis[a][b - 1])         br = true;       if (a > 0 && b < m - 1 && vis[a - 1][b + 1] && vis[a - 1][b] &&           vis[a][b + 1])         br = true;       if (a < n - 1 && b < m - 1 && vis[a + 1][b + 1] && vis[a + 1][b] &&           vis[a][b + 1])         br = true;       if (br) {         cout << i + 1;         return;       }     }     cout << 0;   }   inline void solve() {}   int main() {     ios_base::sync_with_stdio(0);     init();     solve();     return 0;   }


#include <stdio.h>   #include<iomanip>   #include<iostream>   #include<iostream>   #include <algorithm>   #include<string.h>   #include<string>   #include<cmath>   #include<queue>   #include<map>   #include<set>   #include<bits/stdc++.h>   using namespace std;   #pragma warning(disable:4996)   #define inf 0x3f3f3f3f   #define PI 3.1415926535898   const double eps = 1e-7;   typedef long long LL;   #define ll long long   //LL GCD(LL a, LL b)   //{   // if (b == 0)   //  return a;   // return GCD(b, a % b);   //}      //LL fac[N], inv[N];   //LL quick_pow(LL a, LL b)   //{   // LL ans = 1 % mod;   // while (b) {   //  if (b & 1) ans = (ans * a) % mod;   //  b >>= 1;   //  a = (a * a) % mod;   // }   // return ans;   //}   //void init()   //{   // fac[0] = 1;   // inv[0] = 1;   // for (int i = 1; i <= N - 2; i++)   // {   //  fac[i] = (fac[i - 1] * i) % mod;   //  inv[i] = quick_pow(fac[i], mod - 2);   // }   //}   //LL C(LL a, LL b) //计算组合数C(a, b)   //{   // if (a < b || b < 0) return 0;   // return fac[a] * ((inv[a - b] * inv[b]) % mod) % mod;   //}      //LL n;   //LL a[N], c[N], d[N];   //void add(LL x, LL v)   //{   // LL i = x;   // while (x <= (n << 1))   // {   //  c[x] += v;   //  d[x] += v * (i - 1);   //  x += (x & -x);   // }   //}   //LL sum(LL x)   //{   // LL res = 0, i = x;   // while (x > 0)   // {   //  res += i * c[x] - d[x];   //  x -= x & -x;   // }   // return res;   //}      //int prime[N];   //int vis[N];   //void get_prime()   //{   // for (int i = 2; i < N; i++)   // {   //  if (!vis[i])   //  {   //   prime[++prime[0]] = i;   //  }   //  for (int j = 1; j <= prime[0] && i * prime[j] < N; j++)   //  {   //   vis[i * prime[j]] = 1;   //   if (i % prime[j] == 0)   //    break;   //  }   // }   //}      //struct no {   // LL first;   // int id;   // no() {}   // no(LL first, int id) :first(first), id(id) {}   // bool operator<(const no& a)const   // {   //  return first < a.first;//da顶堆   // }   //};      LL mod = 1e9 + 7;   const LL N = 3e5 + 10;   LL n, m, t;   LL a[N], b[N], c[N], aa[3];   int main() {    ios::sync_with_stdio(0);    cin.tie(0);    cout.tie(0);    /*srand((int)time(0));*/    //freopen( C:  Users  Lenovo  Desktop  test  in.txt ,  r , stdin);    //freopen( C:  Users  Lenovo  Desktop  test  out.txt ,  w , stdout);    int n1, n2, n3;    cin >> n1 >> n2 >> n3;    LL sum1 = 0, sum2 = 0, sum3 = 0;    LL m1 = 1e17, m2 = 1e17, m3 = 1e17;    for (int i = 0; i < n1; i++)    {     cin >> a[i];     m1 = min(a[i], m1);     sum1 += a[i];    }    for (int i = 0; i < n2; i++)    {     cin >> b[i];     m2 = min(b[i], m2);     sum2 += b[i];    }    for (int i = 0; i < n3; i++)    {     cin >> c[i];     m3 = min(c[i], m3);     sum3 += c[i];    }    LL all = sum1 + sum2 + sum3;    LL ans=-1e17;    ans = max(ans, sum1 + sum2 - sum3);    ans = max(ans, sum1 + sum3 - sum2);    ans = max(ans, sum2 + sum3 - sum1);    ans = max(ans, all - 2 * (m1 + m2));    ans = max(ans, all - 2 * (m1 + m3));    ans = max(ans, all - 2 * (m3 + m2));    cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1000000 + 5;   char s[maxn];   int vis[maxn], a[maxn];   int main() {     int n;     scanf( %d , &n);     scanf( %s , s + 1);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     memset(vis, 0, sizeof(vis));     int x = 1;     while (1) {       if (vis[x]) {         printf( INFINITE n );         break;       }       vis[x] = 1;       int nx = 0;       if (s[x] ==  > )         x = x + a[x];       else         x = x - a[x];       if (x < 1 || x > n) {         printf( FINITE n );         break;       }     }   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:16777216 )   const long long inf = 2147383647;   const double pi = 2 * acos(0.0);   const double eps = 1e-9;   const long long maxint = 2147483647;   const long long minint = -2147483648;   using namespace std;   struct Bigint {     string a;     int sign;     Bigint() {}     Bigint(string b) { (*this) = b; }     int size() { return a.size(); }     Bigint inverseSign() {       sign *= -1;       return (*this);     }     Bigint normalize(int newSign) {       for (int i = a.size() - 1; i > 0 && a[i] ==  0 ; i--)         a.erase(a.begin() + i);       sign = (a.size() == 1 && a[0] ==  0 ) ? 1 : newSign;       return (*this);     }     void operator=(string b) {       a = b[0] ==  -  ? b.substr(1) : b;       reverse(a.begin(), a.end());       this->normalize(b[0] ==  -  ? -1 : 1);     }     void operator=(long long num) {       char buf[30];       sprintf(buf,  %lld , num);       *this = buf;     }     bool operator<(const Bigint &b) const {       if (sign != b.sign) return sign < b.sign;       if (a.size() != b.a.size())         return sign == 1 ? a.size() < b.a.size() : a.size() > b.a.size();       for (int i = a.size() - 1; i >= 0; i--)         if (a[i] != b.a[i]) return sign == 1 ? a[i] < b.a[i] : a[i] > b.a[i];       return false;     }     bool operator==(const Bigint &b) const { return a == b.a && sign == b.sign; }     Bigint operator+(Bigint b) {       if (sign != b.sign) return (*this) - b.inverseSign();       Bigint c;       for (int i = 0, carry = 0; i < a.size() || i < b.size() || carry; i++) {         carry +=             (i < a.size() ? a[i] - 48 : 0) + (i < b.a.size() ? b.a[i] - 48 : 0);         c.a += (carry % 10 + 48);         carry /= 10;       }       return c.normalize(sign);     }     Bigint operator-(Bigint b) {       if (sign != b.sign) return (*this) + b.inverseSign();       int s = sign;       sign = b.sign = 1;       if ((*this) < b) return ((b - (*this)).inverseSign()).normalize(-s);       Bigint c;       for (int i = 0, borrow = 0; i < a.size(); i++) {         borrow = a[i] - borrow - (i < b.size() ? b.a[i] : 48);         c.a += borrow >= 0 ? borrow + 48 : borrow + 58;         borrow = borrow >= 0 ? 0 : 1;       }       return c.normalize(s);     }     Bigint operator*(Bigint b) {       Bigint c( 0 );       for (int i = 0, k = a[i] - 48; i < a.size(); i++, k = a[i] - 48) {         while (k--) c = c + b;         b.a.insert(b.a.begin(),  0 );       }       return c.normalize(sign * b.sign);     }     Bigint operator/(Bigint b) {       if (b.size() == 1 && b.a[0] ==  0 ) b.a[0] /= (b.a[0] - 48);       Bigint c( 0 ), d;       for (int j = 0; j < a.size(); j++) d.a +=  0 ;       int dSign = sign * b.sign;       b.sign = 1;       for (int i = a.size() - 1; i >= 0; i--) {         c.a.insert(c.a.begin(),  0 );         c = c + a.substr(i, 1);         while (!(c < b)) c = c - b, d.a[i]++;       }       return d.normalize(dSign);     }     Bigint operator%(Bigint b) {       if (b.size() == 1 && b.a[0] ==  0 ) b.a[0] /= (b.a[0] - 48);       Bigint c( 0 );       b.sign = 1;       for (int i = a.size() - 1; i >= 0; i--) {         c.a.insert(c.a.begin(),  0 );         c = c + a.substr(i, 1);         while (!(c < b)) c = c - b;       }       return c.normalize(sign);     }     void print() {       if (sign == -1) putchar( - );       for (int i = a.size() - 1; i >= 0; i--) putchar(a[i]);     }     Bigint operator*(long long b) {       long long carry = 0;       Bigint c = *this;       int bsign;       if (b < 0) {         bsign = -1;         b *= -1;       } else         bsign = 1;       for (int i = 0; i < c.a.size(); i++) {         carry += (c.a[i] - 48) * b;         c.a[i] = (carry % 10 + 48);         carry /= 10;       }       while (carry) {         c.a += (carry % 10 + 48);         carry /= 10;       }       return c.normalize(sign * bsign);     }   };   Bigint power[2001];   void init() {     power[0] =  1 ;     int i;     for (i = 1; i <= 2000; i++) {       power[i] = power[i - 1] * 2;     }   }   struct drive {     int value;     bool sell;   } arr[5010];   Bigint res;   void use(int buy, int sell) {     if (buy == inf) {       if (sell != inf)         arr[sell].value = inf - 10;       else         return;     } else {       res = res + power[arr[sell].value];       for (int i = buy; i <= sell; i++) arr[i].value = inf;     }   }   int main() {     init();     int size;     scanf( %d , &size);     int i;     char buf[200];     for (i = 0; i < size; i++) {       scanf( %s %d , buf, &arr[i].value);       arr[i].sell = false;       if (buf[0] ==  s ) {         arr[i].sell = true;       }     }     res =  0 ;     int k = 5000;     while (k--) {       int sell = inf, buy = inf, mx = -1;       for (i = size - 1; i >= 0; i--) {         if (arr[i].value == inf) {           use(buy, sell);           sell = inf;           buy = inf;           mx = -1;           continue;         }         if (arr[i].sell) {           if (arr[i].value == inf - 10) continue;           if (arr[i].value >= mx) {             mx = arr[i].value;             sell = i;             buy = inf;           }         } else {           if (arr[i].value == mx && buy == inf) {             buy = i;           }         }       }       use(buy, sell);     }     res.print();     puts(  );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const int INF = INT_MAX;   const int NINF = INT_MIN;   int n, q, l, r, curr;   vector<int> vec, tv, Count;   void Solve() {     cin >> n >> q;     vec = tv = vector<int>(n, 0);     for (int i = 0; i <= n - 1; i++) cin >> vec[i];     for (int i = 0; i <= q - 1; i++) {       cin >> l >> r;       l--;       r;       tv[l]++;       if (r < n) tv[r]--;     }     curr = 0;     for (int i = 0; i <= n - 1; i++) {       curr += tv[i];       if (curr > 0) Count.push_back(curr);     }     sort(Count.rbegin(), Count.rend());     sort(vec.rbegin(), vec.rend());     long long int ans = 0ll;     int i = 0;     for (auto v : Count) {       ans += ((v * 1ll) * (vec[i] * 1ll));       i++;     }     cout << ans <<   n ;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     Solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int getInt() {     int x;     scanf( %d , &x);     return x;   }   long long getLongLong() {     long long x;     scanf( %I64d , &x);     return x;   }   double getDouble() {     double x;     scanf( %lf , &x);     return x;   }   char getChar() {     char x;     scanf( %c , &x);     return x;   }   template <typename t>   t abs(t a) {     if (a >= 0) return a;     return -a;   }   struct dual {     int a, b;     bool const operator<(const dual &x) const {       if (a == x.a) return b > x.b;       return a < x.a;     }   };   struct triple {     int a, b, c;     bool const operator<(const triple &x) const {       if (c == x.c) {         if (a == x.a) return b > x.b;         return a < x.a;       }       return c < x.c;     }   };   void FastIO() {     ios::sync_with_stdio(0);     cin.tie(0);   }   long long a[100][100], v;   int main() {     FastIO();     int n;     cin >> n;     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++) cin >> a[i][j];     map<long long, int> mp;     for (int i = 0; i < n; i++) {       v = *max_element(a[i], a[i] + n);       a[i][i] = v;       mp[v]++;     }     for (int i = 0; i < n; i++) {       v = a[i][i];       if (mp[v] == 1) continue;       while (mp.find(v) != mp.end()) v++;       mp[v]++;       mp[a[i][i]]--;       a[i][i] = v;     }     for (int i = 0; i < n; i++) cout << a[i][i] <<    ;     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct Point {     int x, y;     bool operator<(const Point &a) const { return y == a.y ? x < a.x : y > a.y; }   };   Point p[200005];   int x[200005], y[2000005];   struct Segtree {     struct node {       int l, r;       int v;     } tr[200005 * 4];     void build(int l, int r, int k) {       tr[k].l = l, tr[k].r = r;       if (l == r) {         tr[k].v = 0;         return;       }       int m = (l + r) / 2;       build(l, m, k * 2);       build(m + 1, r, k * 2 + 1);       tr[k].v = tr[k * 2].v + tr[k * 2 + 1].v;     }     void update(int pos, int k, int val) {       if (tr[k].l == tr[k].r) {         tr[k].v = val;         return;       }       int m = (tr[k].l + tr[k].r) / 2;       if (pos <= m)         update(pos, k * 2, val);       else if (pos > m)         update(pos, k * 2 + 1, val);       tr[k].v = tr[k * 2].v + tr[k * 2 + 1].v;     }     int query(int l, int r, int k) {       if (l > r) return 0;       if (l <= tr[k].l && r >= tr[k].r) {         return tr[k].v;       }       int m = (tr[k].l + tr[k].r) / 2;       int ans = 0;       if (l <= m) ans += query(l, r, k * 2);       if (r > m) ans += query(l, r, k * 2 + 1);       return ans;     }   };   Segtree seg;   int ydiv[200005];   int main() {     int n;     cin >> n;     for (int i = 0; i < n; ++i) {       cin >> x[i] >> y[i];       p[i].x = x[i];       p[i].y = y[i];     }     sort(x, x + n);     sort(y, y + n);     int xnew = unique(x, x + n) - x;     int ynew = unique(y, y + n) - y;     for (int i = 0; i < n; ++i) {       p[i].x = lower_bound(x, x + xnew, p[i].x) - x + 1;       p[i].y = lower_bound(y, y + ynew, p[i].y) - y + 1;     }     sort(p, p + n);     seg.build(1, xnew + 1, 1);     int beg = 0, cur = 0;     long long sum = 0;     while (beg < n) {       int pos = 0;       while (cur < n && p[cur].y == p[beg].y) {         seg.update(p[cur].x, 1, 1);         ydiv[pos++] = p[cur++].x;       }       ydiv[pos] = xnew + 1;       for (int i = 0; i < pos; ++i) {         long long cntl = seg.query(1, ydiv[i] - 1, 1);         long long cntr = seg.query(ydiv[i] + 1, ydiv[i + 1] - 1, 1);         sum += (cntl + 1) * (cntr + 1);       }       beg = cur;     }     cout << sum << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     double ans, p, q, p1, p2, p3;     int n, i;     scanf( %d , &n);     ans = 0.0;     q = p2 = p3 = 1;     p1 = 0;     for (i = 1; i <= n + 1; i++) {       if (i <= n)         scanf( %lf , &p);       else         p = 0.0;       ans += (1 - p) * p1;       p1 = (p1 + p2) * p;       q = 1.0 - p;       p2 = (p2 + 2.0 * p3) * p + q;       p3 = p3 * p + q;     }     printf( %.15f n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, i, j;   vector<long long> v, Ans;   long long adj[504][504], dist[504][504];   bool visit[1000000];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> n;     for (i = 1; i <= n; i++) {       for (j = 1; j <= n; j++) {         cin >> adj[i][j];         dist[i][j] = adj[i][j];       }     }     long long x;     for (i = 1; i <= n; i++) cin >> x, v.push_back(x);     reverse(v.begin(), v.end());     int f = 0;     for (auto k : v) {       f++;       long long ans = 0;       for (long long i = 0; i < n; i++) {         for (long long j = 0; j < n; j++)           dist[v[i]][v[j]] = min(dist[v[i]][v[j]], dist[v[i]][k] + dist[k][v[j]]);       }       for (i = 0; i < f; i++)         for (j = 0; j < f; j++) ans += dist[v[i]][v[j]];       Ans.push_back(ans);     }     reverse(Ans.begin(), Ans.end());     for (auto i : Ans) cout << i <<    ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, count = 0;     cin >> n;     int home[n], guest[n];     for (int i = 0; i < n; ++i) {       cin >> home[i] >> guest[i];     }     for (int i = 0; i < n; ++i) {       for (int j = 0; j < n; ++j) {         if (home[i] == guest[j]) count++;       }     }     cout << count;   }


#include <bits/stdc++.h>   using namespace std;   long long binpow(long long a, long long b, long long m) {     a %= m;     long long res = 1;     while (b > 0) {       if (b & 1) res = (res * a) % m;       a = (a * a) % m;       b >>= 1;     }     return res;   }   void solve() {     long long int x, n, y, z, ans = 1;     cin >> x >> n;     vector<long long int> v;     y = x;     for (long long int i = 2; i * i <= x; i++) {       if (y % i == 0) {         v.push_back(i);         while (y % i == 0) y /= i;       }     }     if (y != 1) v.push_back(y);     for (long long int i = 0; i < v.size(); i++) {       long long int a = v[i], b = 0;       while (a <= n) {         z = (n / a);         b += z;         if (z < v[i]) break;         a *= v[i];       }       ans = (ans * binpow(v[i], b, 1000000007)) % 1000000007;     }     cout << ans <<   n ;   }   int main() {     ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);     long long int t = 1;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int arr[200005];   int ans[200005];   int n, m;   bool vis[200005];   int s = 0, e = -1;   int main() {     scanf( %d %d , &n, &m);     vector<pair<int, int> > q(m);     for (int i = 0; i < n; ++i) scanf( %d , arr + i);     for (int i = 0; i < m; ++i) scanf( %d %d , &q[i].first, &q[i].second);     int b = -1;     for (int i = m - 1; i >= 0; --i) {       if (b >= q[i].second) vis[i] = 1;       b = max(b, q[i].second);     }     int i;     bool r = 0;     for (i = 0; i < m; ++i) {       if (!vis[i]) {         sort(arr, arr + q[i].second);         if (q[i].first == 1) {           s = 0, e = q[i].second - 1;         } else {           s = 0, e = q[i].second - 1, r = 1;         }         for (int j = q[i].second; j < n; ++j) ans[j] = arr[j];         break;       }     }     for (; i < m; ++i) {       if (vis[i]) continue;       if (r) {         while (e - s + 1 > q[i].second) {           ans[e - s] = arr[s];           ++s;         }       } else {         while (e - s + 1 > q[i].second) {           ans[e - s] = arr[e];           --e;         }       }       if (q[i].first == 1) {         ans[e - s] = arr[e];         --e;         r = 0;       } else {         ans[e - s] = arr[s];         ++s;         r = 1;       }     }     if (r) {       while (e >= s) {         ans[e - s] = arr[s];         ++s;       }     } else {       while (e >= s) {         ans[e - s] = arr[e];         --e;       }     }     for (int i = 0; i < n; ++i) printf( %d  , ans[i]);   }


#include <bits/stdc++.h>   using namespace std;   int n;   bool isValid(int x1, int y1, int x2, int y2) { return x1 <= x2 && y1 <= y2; }   int ask(int x1, int y1, int x2, int y2) {     int ret = 0;     cout <<  ?   << x1 <<     << y1 <<     << x2 <<     << y2 <<   n ;     cout.flush();     cin >> ret;     return ret;   }   bool check(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4) {     if (!isValid(x1, y1, x2, y2)) return 0;     if (!isValid(x3, y3, x4, y4)) return 0;     int ret1 = ask(x1, y1, x2, y2);     int ret2 = ask(x3, y3, x4, y4);     return (ret1 > 0 && ret2 > 0);   }   int main() {     ios::sync_with_stdio(0);     cin >> n;     int x1, y1, x2, y2, x3, y3, x4, y4;     int l, r;     l = 1;     r = n;     while (l <= r) {       int s = (l + r) / 2;       if (ask(s, 1, n, n) == 2) {         l = s + 1;         x1 = s;       } else {         r = s - 1;       }     }     l = 1;     r = n;     while (l <= r) {       int s = (l + r) / 2;       if (ask(s, 1, n, n) >= 1) {         l = s + 1;         x3 = s;       } else {         r = s - 1;       }     }     l = 1;     r = n;     while (l <= r) {       int s = (l + r) / 2;       if (ask(1, 1, s, n) == 2) {         r = s - 1;         x2 = s;       } else {         l = s + 1;       }     }     l = 1;     r = n;     while (l <= r) {       int s = (l + r) / 2;       if (ask(1, 1, s, n) >= 1) {         r = s - 1;         x4 = s;       } else {         l = s + 1;       }     }     l = 1;     r = n;     while (l <= r) {       int s = (l + r) / 2;       if (ask(1, s, n, n) == 2) {         l = s + 1;         y1 = s;       } else {         r = s - 1;       }     }     l = 1;     r = n;     while (l <= r) {       int s = (l + r) / 2;       if (ask(1, s, n, n) >= 1) {         l = s + 1;         y3 = s;       } else {         r = s - 1;       }     }     l = 1;     r = n;     while (l <= r) {       int s = (l + r) / 2;       if (ask(1, 1, n, s) == 2) {         r = s - 1;         y2 = s;       } else {         l = s + 1;       }     }     l = 1;     r = n;     while (l <= r) {       int s = (l + r) / 2;       if (ask(1, 1, n, s) >= 1) {         r = s - 1;         y4 = s;       } else {         l = s + 1;       }     }     vector<int> xx1{x1, x3};     vector<int> xx2{x2, x4};     vector<int> yy1{y1, y3};     vector<int> yy2{y2, y4};     int xxx3 = xx1[1];     for (int xxx1 : xx1) {       int xxx4 = xx2[1];       for (int xxx2 : xx2) {         int yyy3 = yy1[1];         for (int yyy1 : yy1) {           int yyy4 = yy2[1];           for (int yyy2 : yy2) {             if (check(xxx1, yyy1, xxx2, yyy2, xxx3, yyy3, xxx4, yyy4)) {               cout <<  !   << xxx1 <<     << yyy1 <<     << xxx2 <<     << yyy2                    <<     << xxx3 <<     << yyy3 <<     << xxx4 <<     << yyy4;               return 0;             }             yyy4 = yyy2;           }           yyy3 = yyy1;         }         xxx4 = xxx2;       }       xxx3 = xxx1;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long a[505];   long long mod = 998244353;   long long dp[505][505];   long long get_ans(long long l, long long r) {     if (dp[l][r]) return dp[l][r];     if (l >= r) return 1;     long long pl = l, _min = 1e9;     for (long long i = l; i <= r; i++) {       if (a[i] < _min) {         _min = a[i];         pl = i;       }     }     long long Ans1 = 0, Ans2 = 0;     for (long long i = pl; i >= l; i--) {       Ans1 = (Ans1 + get_ans(l, i - 1) * get_ans(i, pl - 1) % mod) % mod;     }     for (long long j = pl; j <= r; j++) {       Ans2 = (Ans2 + get_ans(pl + 1, j) % mod * get_ans(j + 1, r) % mod) % mod;     }     return dp[l][r] = (Ans1 * Ans2) % mod;   }   signed main() {     long long n, m;     scanf( %lld %lld , &n, &m);     for (long long i = 1; i <= m; i++) scanf( %lld , &a[i]);     printf( %lld , get_ans(1, n));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int N, s1, s2;   int data[100001];   bool isRange(int x, int y, int z) {     if (z >= x && z <= y) return true;     return false;   }   int check(int x) {     int L = data[N] - x;     int R = data[N] + x;     for (int i = N - 1; i >= 1; i--) {       if (isRange(L, R, data[i])) {         L = data[i] - x;         R = data[i] + x;       } else {         L = max(L, data[i] - x);         R = min(R, data[i] + x);       }     }     return isRange(L, R, s1) || isRange(L, R, s2);   }   int main() {     cin >> N >> s1 >> s2;     for (int i = 1; i <= N; i++) {       cin >> data[i];     }     int L = abs(s1 - s2);     int R = 1000000000;     while (L <= R) {       int mid = (L + R) >> 1;       if (check(mid)) {         R = mid - 1;       } else {         L = mid + 1;       }     }     cout << L;   }


#include <bits/stdc++.h>   long long pow(long long a, long long n, long long mod) {     long long t;     for (t = 1; n; n >>= 1, a *= a, a %= mod) n & 1 && (t *= a, t %= mod);     return t;   }   int main() {     long long N, A, B, K, i, l, t, ans, mod = 1000000009;     char s[100100];     for (scanf( %lld%lld%lld%lld%s , &N, &A, &B, &K, s), ans = i = 0;          i <= N && s[i]; i++)       s[i] ==  +  ? ans += pow(A, N - i, mod) * pow(B, i, mod)                   : (ans -= pow(A, N - i, mod) * pow(B, i, mod)),           ans %= mod;     if (i <= N)       for (l = i, t = pow(pow(A, i, mod), mod - 2, mod) * pow(B, i, mod) % mod,           ans = t - 1 % mod ? (ans * pow(t, (N + 1) / i, mod) - ans) % mod *                                   pow(t - 1, mod - 2, mod) % mod                             : (N + 1) / i * ans % mod,           i += (N + 1) / i * i;            i <= N; i++)         s[i % l] ==  +  ? ans += pow(A, N - i, mod) * pow(B, i, mod)                         : (ans -= pow(A, N - i, mod) * pow(B, i, mod)),             ans %= mod;     printf( %lld n , (ans + mod) % mod);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int m, n;     cin >> m >> n;     char a[m], b[n];     for (int i = 0; i < m; i++) cin >> a[i];     for (int i = 0; i < n; i++) cin >> b[i];     if ((a[0] ==  <  && b[0] ==  ^ ) || (a[0] ==  >  && b[n - 1] ==  ^ ) ||         (a[m - 1] ==  <  && b[0] ==  v ) || (a[m - 1] ==  >  && b[n - 1] ==  v ))       cout <<  NO  << endl;     else       cout <<  YES  << endl;   }


#include <bits/stdc++.h>   using namespace std;   int cnt1 = 0;   const int maxn = 1e5;   int fac[maxn + 5], vis[maxn + 5];   vector<int> prime;   void init() {     memset(vis, 0, sizeof(vis));     for (int i = 2; i <= maxn; i++) {       if (!vis[i]) prime.push_back(i);       for (int j = 0; j < prime.size() && i * prime[j] <= maxn; j++) {         vis[i * prime[j]] = 1;         if (i % prime[j] == 0) break;       }     }   }   void cal(int n) {     int m = sqrt(n + 0.5);     int cnt2 = 0;     for (int i = 2; i <= m; i++) {       if (n % i == 0) {         fac[i]++;         while (n % i == 0) n /= i;       }     }     if (n > 1) fac[n]++;   }   int main() {     int n, x;     init();     memset(fac, 0, sizeof(fac));     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d , &x);       cal(x);     }     int ans = 1;     for (int i = 0; i < prime.size(); i++) ans = max(ans, fac[prime[i]]);     printf( %d , ans);     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   void io() {}   long long fast_exp(long long base, int exp, int m) {     long long res = 1;     while (exp > 0) {       if (exp % 2 == 1) {         res = (res * base) % m;       }       base = (base * base) % m;       exp /= 2;     }     return res % m;   }   vector<pair<long long, string> > v[10001];   long long dp[2001][4];   int main() {     io();     ios ::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long n, m;     cin >> n >> m;     while (n--) {       string s;       long long r, p;       cin >> s >> r >> p;       v[r].push_back(make_pair(p, s));     }     for (int i = 1; i <= int(m); ++i) {       sort(v[i].begin(), v[i].end());       int siz = v[i].size();       if (siz == 2) {         cout << v[i][siz - 1].second <<     << v[i][siz - 2].second <<   n ;       } else if ((v[i][siz - 2].first == v[i][siz - 3].first)) {         cout <<  ?  <<   n ;       } else {         cout << v[i][siz - 1].second <<     << v[i][siz - 2].second <<   n ;       }     }   }


#include <bits/stdc++.h>   struct oficinas {     int valor;     int sig;   };   int v[200002], vaux[200002];   int buscar(int buscado);   int main() {     int n, q, type, x, y, i, A, B, aux;     scanf( %d %d , &n, &q);     for (i = 1; i <= n; i++) {       v[i] = i;       vaux[i] = i + 1;     }     for (i = 0; i < q; i++) {       scanf( %d %d %d , &type, &x, &y);       switch (type) {         case 1:           v[buscar(x)] = buscar(y);           break;         case 2:           while (x < y) {             v[buscar(x)] = buscar(y);             aux = vaux[x];             vaux[x] = vaux[y];             x = aux;           }           break;         case 3:           printf( %s n , buscar(x) == buscar(y) ?  YES  :  NO );           break;       }     }     return 0;   }   int buscar(int buscado) {     return v[buscado] = v[buscado] == buscado ? buscado : buscar(v[buscado]);   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 100 + 10;   int a[maxn], chk[maxn];   string str;   int main() {     int n, k = 0;     cin >> n >> str;     if (str.size() < n) {       cout <<  NO ;       return 0;     }     for (int i = 0; i < str.size(); i++) {       if (a[str[i] -  0 ] == 0) k++;       a[str[i] -  0 ] = 1;     }     if (k < n) {       cout <<  NO ;       return 0;     }     cout <<  YES  << endl;     for (int i = 0; i < str.size(); i++) {       if (chk[str[i] -  0 ] == 0 && n > 1 && i != 0) {         cout << endl;         n--;       }       cout << str[i];       chk[str[i] -  0 ] = 1;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int read(int &x) { return scanf( %d , &x); }   int read(long long &x) { return scanf( %lld , &x); }   int read(double &x) { return scanf( %lf , &x); }   int read(int &x, int &y) { return scanf( %d%d , &x, &y); }   int read(long long &x, long long &y) { return scanf( %lld%lld , &x, &y); }   int read(double &x, double &y) { return scanf( %lf%lf , &x, &y); }   int read(int &x, int &y, int &z) { return scanf( %d%d%d , &x, &y, &z); }   int read(long long &x, long long &y, long long &z) {     return scanf( %lld%lld%lld , &x, &y, &z);   }   int read(double &x, double &y, double &z) {     return scanf( %lf%lf%lf , &x, &y, &z);   }   long long qpow(long long a, long long b, long long mod) {     if (a == 0) return 0;     long long ans = 1;     a %= mod;     while (b) {       if (b & 1) ans = ans * a % mod;       a = a * a % mod;       b >>= 1;     }     return ans % mod;   }   long long inv(long long x, long long mod) { return qpow(x, mod - 2, mod); }   int dir[4][2] = {0, 1, 0, -1, 1, 0, -1, 0};   int mon[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};   const int INF = 0x3f3f3f3f;   const int mod = 1e9 + 7;   const int N = 5e5 + 5;   struct DSU {     int f[N];     void init(int n) {       for (int i = 0; i <= n; i++) f[i] = i;     }     int fa(int x) { return f[x] == x ? x : f[x] = fa(f[x]); }     void join(int x, int y) {       x = fa(x);       y = fa(y);       if (x != y) f[x] = y;     }   };   struct CombMath {     long long C[2005][2005];     void init(int n) {       for (int i = 0; i <= n; i++) C[i][0] = 1;       for (int i = 1; i <= n; i++)         for (int j = 1; j <= n; j++)           C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % mod;     }   };   struct _2sat {     vector<int> G[N << 1];     int dfn[N << 1], low[N << 1], stk[N << 1], color[N << 1];     int t, tp, scc;     bool vis[N << 1];     void init(int n) {       for (int i = 0; i <= 2 * n; i++) G[i].clear();       for (int i = 0; i <= n * 2; i++) dfn[i] = low[i] = color[i] = vis[i] = 0;       t = tp = scc = 0;     }     void add(int x, int xv, int y, int yv) {       x = x * 2 + xv;       y = y * 2 + yv;       G[x ^ 1].push_back(y);       G[y ^ 1].push_back(x);     }     void addmaodun(int x, int xv, int y, int yv) {       x = x * 2 + (xv ^ 1);       y = y * 2 + (yv ^ 1);       G[x ^ 1].push_back(y);       G[y ^ 1].push_back(x);     }     void tarjan(int x) {       dfn[x] = low[x] = ++t;       stk[++tp] = x;       vis[x] = 1;       for (auto v : G[x]) {         if (!dfn[v]) {           tarjan(v);           low[x] = min(low[x], low[v]);         } else if (vis[v])           low[x] = min(low[x], dfn[v]);       }       if (low[x] == dfn[x]) {         color[x] = ++scc;         vis[x] = 0;         while (stk[tp] != x) {           color[stk[tp]] = scc;           vis[stk[tp--]] = 0;         }         tp--;       }     }     void work(int n) {       for (int i = 0; i < 2 * n; i++)         if (!dfn[i]) tarjan(i);       for (int i = 0; i < n; i++)         if (color[i * 2] == color[i * 2 + 1]) {           puts( -1 );           return;         }       vector<int> row, col;       for (int i = 0; i < n / 2; i++) {         if (color[i * 2] < color[i * 2 + 1]) {           continue;         } else {           row.push_back(i);         }       }       for (int i = n / 2; i < n; i++) {         if (color[i * 2] < color[i * 2 + 1]) {           continue;         } else {           col.push_back(i - n / 2);         }       }       int sz = row.size() + col.size();       printf( %d n , sz);       for (auto it : row) printf( row %d n , it);       for (auto it : col) printf( col %d n , it);     }   } twosat;   char s[N];   int a[2005];   int g[2005][2005];   signed main() {     int n;     read(n);     getchar();     for (int k = 1; k <= 2; k++) {       for (int i = 1; i <= n; i++) {         gets(s + 1);         for (int j = 1; j <= n; j++) {           g[i][j] ^= (s[j] -  0 );         }       }     }     twosat.init(2 * n);     gets(s + 1);     for (int i = 1; i <= n; i++) a[i] = s[i] -  0 ;     bool ok = 1;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         int n1 = a[i], n2 = a[j];         int ii = i - 1, jj = j + n - 1;         if (g[i][j] == 1) {           if (n1 == 1 and n2 == 1) {             twosat.addmaodun(ii, 1, jj, 1);             twosat.addmaodun(ii, 0, jj, 0);           } else if (n2 == 1) {             twosat.G[ii * 2].push_back(ii * 2 + 1);           } else if (n1 == 1) {             twosat.G[jj * 2].push_back(jj * 2 + 1);           } else {             ok = 0;           }         } else {           if (n1 == 1 and n2 == 1) {             twosat.addmaodun(ii, 1, jj, 0);             twosat.addmaodun(ii, 0, jj, 1);           } else if (n2 == 1) {             twosat.G[ii * 2 + 1].push_back(ii * 2);           } else if (n1 == 1) {             twosat.G[jj * 2 + 1].push_back(jj * 2);           } else {             continue;           }         }       }     }     if (!ok)       puts( -1 );     else {       twosat.work(n * 2);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int n;     cin >> n;     vector<int> v;     for (int i = 0; i < n; i++) {       int num;       cin >> num;       v.push_back(num);     }     vector<pair<int, int> > vp;     int x, y;     for (int i = 0; i < n; i++) {       if (i == 0) {         x = v[i + 1] - v[i];         y = v[n - 1] - v[i];       } else if (i == n - 1) {         x = v[i] - v[i - 1];         y = v[i] - v[0];       } else {         x = min(v[i] - v[i - 1], v[i + 1] - v[i]);         y = max(v[i] - v[0], v[n - 1] - v[i]);       }       vp.push_back(make_pair(x, y));     }     for (auto &i : vp) {       cout << i.first <<     << i.second << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long mod = 1e9 + 7;   long long INF = 1e18;   bool isPrime(long long n) {     if (n <= 1) return false;     if (n <= 3) return true;     if (n % 2 == 0 || n % 3 == 0) return false;     for (long long i = 5; i * i <= n; i = i + 6)       if (n % i == 0 || n % (i + 2) == 0) return false;     return true;   }   long long nCr(long long n, long long r) {     long long res = 1;     if (n < r) return -1;     r = min(r, n - r);     for (long long i = 0; i < r; i++) {       res *= (n - i);       res /= (i + 1);     }     return res;   }   long long nPr(long long n, long long r) {     long long res = 1;     if (n < r) return -1;     for (long long i = 0; i < r; i++) res *= (n - i);     return res;   }   long long modexp(long long x, long long y) {     long long res = 1;     while (y > 0) {       if (y & 1) res = (res * x) % mod;       x = (x * x) % mod;       y = y >> 1;     }     return res;   }   void solve() {     long long a, b, c;     cin >> a >> b >> c;     long long d, e, f;     f = sqrt(c * a / b);     d = sqrt(a * b / c);     e = sqrt(b * c / a);     cout << 4 * (d + e + f);   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long t = 1;     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long BIG = 1000000007;   const double PI = 3.141592653589793238;   template <typename T, typename Q>   T max(T a, Q b) {     if (a < b) return b;     return a;   }   template <typename T, typename Q>   T min(T a, Q b) {     if (a > b) return b;     return a;   }   long gcd(long a, long b) {     if (b == 0) {       return a;     }     return gcd(b, a % b);   }   bool check(char arr[8][8], int i) {     for (int j = 0; j < 8; j++) {       if (arr[i][j] ==  W ) return false;     }     return true;   }   bool check1(char arr[8][8], int i) {     for (int j = 0; j < 8; j++) {       if (arr[j][i] ==  W ) return false;     }     return true;   }   void solve() {     char arr[8][8];     int ans = 0;     for (int i = 0; i < 8; i++) {       for (int j = 0; j < 8; j++) {         cin >> arr[i][j];         if (arr[i][j] ==  B ) ans++;       }     }     if (ans == 64) {       cout <<  8             <<   n ;       ;       return;     }     ans = 0;     for (int i = 0; i < 8; i++) {       if (check(arr, i)) ans++;     }     for (int i = 0; i < 8; i++) {       if (check1(arr, i)) ans++;     }     cout << ans <<   n ;     ;   }   int main() {     int t;     t = 1;     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double eps = (1e-8);   int dcmp(double a, double b) {     if (fabs(a - b) <= eps) return 0;     return a < b ? -1 : 1;   }   int main() {     ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);     int n, m;     double w;     cin >> n >> w >> m;     double how = n * w / (m * 1.0);     vector<vector<pair<int, double> > > res(m);     vector<double> bottles;     vector<int> cnt(n, 0);     for (int i = 0; i < n; i++) bottles.push_back(w);     cout << fixed << setprecision(6);     for (int i = 0; i < m; i++) {       double temp = how;       for (int j = 0; j < n; j++) {         if (dcmp(bottles[j], 0) == 0) continue;         if (dcmp(temp, 0) == 0) break;         if (bottles[j] > temp) {           res[i].push_back({j, temp});           bottles[j] -= temp;           temp = 0;           cnt[j]++;           break;         } else {           res[i].push_back({j, bottles[j]});           temp -= bottles[j];           bottles[j] = 0;           cnt[j]++;         }       }       if (dcmp(temp, 0) != 0) return cout <<  NO  << endl, 0;     }     for (int i = 0; i < n; i++) {       if (cnt[i] > 2 || dcmp(bottles[i], 0) != 0) return cout <<  NO  << endl, 0;     }     cout <<  YES  << endl;     for (int i = 0; i < m; i++) {       for (auto p : res[i]) {         cout << p.first + 1 <<     << p.second <<    ;       }       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> v;   int main() {     v.push_back(0);     for (int i = 0; i < int(30); i++) v.push_back(1 << i);     while (1) {       int hi, lo;       int test;       string s;       cin >> s;       if (s ==  mistake  || s ==  end ) return 0;       bool found = 0;       for (int i = 0; i < int(30); i++) {         cout <<  ?   << v[i] <<     << v[i + 1] << endl;         fflush(stdout);         char c;         cin >> c;         if (c ==  e ) return 0;         if (c ==  x ) {           found = 1;           lo = v[i] + 1;           hi = v[i + 1];           test = v[i];           break;         }       }       if (!found) {         lo = v[v.size() - 1] + 1;         hi = 1000000000;         test = v[v.size() - 1];       }       while (hi - lo > 1) {         int mid = (lo + hi) / 2;         cout <<  ?   << test <<     << mid << endl;         fflush(stdout);         char c;         cin >> c;         if (c ==  e ) return 0;         if (c ==  x )           hi = mid;         else           lo = mid + 1;       }       cout <<  ?   << test <<     << lo << endl;       fflush(stdout);       char c;       cin >> c;       if (c ==  e ) return 0;       if (c ==  x )         cout <<  !   << lo << endl;       else         cout <<  !   << hi << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   struct Tree {     static const int MAXN = 500010;     struct Edge {       int son, dis;       Edge *pre;       void add(int _s, int _d, Edge *_p) { son = _s, dis = _d, pre = _p; }     } edge[MAXN << 1], *pos[MAXN];     int sum;     void clear() {       sum = 0;       memset(pos, 0, sizeof(pos));     }     void add(int a, int b, int c) {       edge[++sum].add(b, c, pos[a]);       pos[a] = edge + sum;     }   } T;   const int MAXN = 500010, MAXK = 500010, MAXM = 500010;   struct Edge {     int from, to, price;   } E[MAXK + MAXM];   int n, m, k;   void init() {     scanf( %d%d%d , &n, &k, &m);     for (int i = 1; i <= k + m; ++i) {       int u, v, w;       scanf( %d%d , &u, &v);       if (i <= k)         w = -1;       else         scanf( %d , &w);       E[i] = (Edge){u, v, w};     }   }   struct DisjointSet {     static const int MAXN = 500010;     int fa[MAXN], n;     void clear(int _n) {       n = _n;       for (int i = 1; i <= n; ++i) fa[i] = i;     }     int find(int x) {       if (fa[x] == x) return x;       return fa[x] = find(fa[x]);     }     bool merge(int u, int v) {       int fx = find(u), fy = find(v);       if (fx == fy) return false;       fa[fx] = fy;       return true;     }   } DS;   void buildTree() {     DS.clear(n);     T.clear();     for (int i = 1; i <= k + m; ++i)       if (DS.merge(E[i].from, E[i].to)) {         T.add(E[i].from, E[i].to, E[i].price);         T.add(E[i].to, E[i].from, E[i].price);       }   }   const int MAXL = 20;   int fa[MAXN][MAXL], l2[MAXN], dep[MAXN];   void dfs(int x, int f) {     for (int l = 1; l <= l2[dep[x]]; ++l) fa[x][l] = fa[fa[x][l - 1]][l - 1];     for (Tree::Edge *i = T.pos[x]; i; i = i->pre)       if (i->son != f) {         fa[i->son][0] = x;         dep[i->son] = dep[x] + 1;         dfs(i->son, x);       }   }   void preset() {     l2[0] = -1, l2[1] = 0;     for (int i = 2; i <= n; ++i) l2[i] = l2[i >> 1] + 1;     memset(fa, 0, sizeof(fa)), dep[1] = 1;     dfs(1, 0);   }   int lca(int u, int v) {     if (dep[u] > dep[v]) swap(u, v);     for (int l = l2[dep[v] - dep[u]]; l >= 0; --l)       if (dep[v] - (1 << l) >= dep[u]) v = fa[v][l];     if (u == v) return u;     for (int l = l2[dep[u]]; l >= 0; --l)       if (fa[u][l] != fa[v][l]) u = fa[u][l], v = fa[v][l];     return fa[u][0];   }   const long long INF = ~0ull >> 3;   multiset<int> F[MAXN];   vector<int> ins[MAXN];   long long solve(int x, int f, bool mask) {     long long ans = 0;     for (Tree::Edge *i = T.pos[x]; i; i = i->pre)       if (i->son != f) {         long long ret = solve(i->son, x, (i->dis == -1));         if (ret == INF) return INF;         ans += ret;         if (F[x].size() < F[i->son].size()) F[x].swap(F[i->son]);         F[x].insert(F[i->son].begin(), F[i->son].end());       }     for (int val : ins[x])       if (val > 0)         F[x].insert(val);       else         F[x].erase(F[x].find(-val));     if (!mask) return ans;     if (x > 1 && F[x].empty()) return INF;     ans += *F[x].begin();     return ans;   }   int main() {     init();     buildTree();     preset();     for (int i = k + 1; i <= k + m; ++i) {       int u = E[i].from, v = E[i].to, w = E[i].price;       int z = lca(u, v);       if (u != z) ins[u].push_back(w), ins[z].push_back(-w);       if (v != z) ins[v].push_back(w), ins[z].push_back(-w);     }     long long ans = solve(1, 0, false);     if (ans == INF)       cout << -1 << endl;     else       cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1073741824;   const int N = 200005;   const double PI = 4 * atan(1);   set<char> vowel = { A ,  O ,  Y ,  E ,  U ,  I ,  a ,  o ,  e ,  u ,  y ,  i };   int dx[] = {1, -1, 0, 0, 1, -1, 1, -1};   int dy[] = {0, 0, 1, -1, 1, 1, -1, -1};   long long gcd(long long a, long long b) { return (b == 0 ? a : gcd(b, a % b)); }   long long lcm(long long a, long long b) { return a * (b / gcd(a, b)); }   bool issquare(long long w) { return trunc(sqrt(w)) * trunc(sqrt(w)) == w; }   bool isprime(long long u) {     for (long long i = 2; i <= (int)sqrt(u); i++) {       if (u % i == 0) return 0;     }     return 1;   }   long long mod(long long to_mod) {     to_mod %= MOD;     while (to_mod < 0) to_mod += MOD;     return to_mod % MOD;   }   long long moduloMultiplication(long long a, long long b, long long mod) {     long long res = 0;     a %= mod;     while (b) {       if (b & 1) res = (res + a) % mod;       a = (2 * a) % mod;       b >>= 1;     }     return res;   }   long long power(long long x, long long y) {     long long res = 1;     x = x;     while (y > 0) {       if (y & 1) res = (res * x);       y = y >> 1;       x = (x * x);     }     return res;   }   long long n, m, k, q, res, x, y, ans;   string ch, sh, d;   bool ok(string ss, long long len) {     string second =   ;     for (int i = 1; i <= max(n / len, m / len); i++) {       second += ss;       if (i == n / len) {         if (ch != second) return 0;       }       if (i == m / len) {         if (sh != second) return 0;       }     }     return 1;   }   int main() {     cin >> ch;     cin >> sh;     n = ch.size();     m = sh.size();     k = min(n, m);     long long i = 0;     d =   ;     ans = 0;     x = 0;     while (i < k && ch[i] == sh[i]) {       d += ch[i];       x++;       if (n % x == 0 && m % x == 0) {         if (ok(d, x)) ans++;       }       i++;     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long r = 0, mod = 1e9 + 7, a, b, i, z, x, y;     cin >> a >> b;     for (i = 1; i < b; ++i) {       r += i * a + b * i % mod * (a * (a + 1) / 2 % mod);       r %= mod;     }     cout << r << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int x = 0, y = 0, i, j, count = 0, n;     cin >> n;     string s1;     cin >> s1;     for (i = 0; i < n - 1; i++) {       x = 0;       y = 0;       for (j = i; j < s1.size(); j++) {         switch (s1[j]) {           case  U :             ++y;             break;           case  D :             --y;             break;           case  L :             --x;             break;           case  R :             ++x;             break;         }         if (x == 0 && y == 0) ++count;       }     }     cout << count;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<int> a(n);     for (int i = 0; i < n; ++i) {       cin >> a[i];     }     int m;     cin >> m;     vector<int> b(m);     for (int i = 0; i < m; ++i) {       cin >> b[i];     }     int M = -1, cur = 0;     for (int i = 0; i < n; ++i) {       for (int j = 0; j < m; ++j) {         if (b[j] % a[i]) continue;         int x = b[j] / a[i];         if (x > M) {           M = x;           cur = 1;         } else if (x == M)           ++cur;       }     }     cout << cur;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     scanf( %d%d , &n, &m);     if (m == 3 && n > 4) return puts( -1 ), 0;     for (int i = 1; i <= m; i++) printf( %d %d n , i, i * i + 300000);     for (int i = 1; i <= n - m; i++) printf( %d %d n , i, -i * i - 300000);   }


#include <bits/stdc++.h>   using namespace std;   int R;   vector<int> hv, use;   vector<char> ans;   int req[1000005];   int fr[1000005];   int main() {     int n;     scanf( %d , &n);     if (n >= 1389)       R = 4;     else if (n >= 232)       R = 3;     else if (n >= 199)       R = 2;     else if (n >= 2)       R = 1;     else {       printf( a a n );       return 0;     }     for (int i = 0; i < R; i++) hv.push_back(0);     hv.push_back(1);     for (int i = R + 1;; i++) {       hv.push_back(hv.back() * i / (i - R));       if (hv.back() > n) break;     }     for (int &u : hv) u--;     for (int i = 0; i < 2 * R; i++) hv[i] = 0;     for (int i = 1; i <= n; i++) req[i] = 10000005;     for (int i = 0; i <= n; i++) fr[i] = -1;     for (int i = 1; i <= n; i++)       for (unsigned j = 0; j < hv.size(); j++)         if (hv[j] <= i) {           if (req[i - hv[j]] + j < req[i]) {             req[i] = req[i - hv[j]] + j;             fr[i] = j;           }         } else           break;     n--;     for (int i = n; i; i -= hv[fr[i]]) use.push_back(fr[i]);     for (unsigned i = 0; i < use.size(); i++)       for (int j = 0; j < R; j++) printf( %c ,  a  + i);     for (int i = use.size() - 1; i >= 0; i--)       for (int j = 2 * R; j < use[i]; j++) printf( %c ,  a  + i);     for (unsigned i = 0; i < use.size(); i++)       for (int j = 0; j < R; j++) printf( %c ,  a  + i);     printf(   );     for (unsigned i = 0; i < use.size(); i++)       for (int j = 0; j < R; j++) printf( %c ,  a  + i);     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1000000;   long long cost[N][10], step[N][10], n;   int getMax(int x) {     int ret = 0;     while (x) {       ret = max(ret, int(x % 10));       x /= 10;     }     return ret;   }   void init() {     for (int i = 0; i < N; i++) {       int c = getMax(i);       for (int j = 0; j < 10; j++) {         int v = max(j, c);         if (i < v) {           step[i][j] = 1;           cost[i][j] = v;         } else {           step[i][j] = step[i - v][j] + 1;           cost[i][j] = cost[i - v][j] + v;         }       }     }   }   int main() {     init();     scanf( %lld , &n);     long long ans = 0;     while (n >= N) {       int j = getMax(n / N);       ans += step[n % N][j];       n -= cost[n % N][j];     }     while (n > 0) {       int j = getMax(n);       ans += 1;       n -= j;     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<vector<int> > v;   vector<vector<int> > vv;   vector<vector<long long int> > dp;   void merg(int x) {     if (v[x].size() == 1) return;     if (v[x].size() == 2) {       vector<int> v1;       v1.push_back(0);       for (int i = 0; i < v[x * 2].size(); i++) {         v1.push_back(v[x * 2][i] + v[x][1]);       }       v[x] = v1;       return;     }     vector<int> v1 = v[x * 2];     vector<int> v2 = v[x * 2 + 1];     for (int i = 0; i < v1.size(); i++) v1[i] += v[x][1];     for (int i = 0; i < v2.size(); i++) v2[i] += v[x][2];     v[x].resize(1);     int idx1 = 0;     int idx2 = 0;     while (idx1 < v1.size() && idx2 < v2.size()) {       if (v1[idx1] < v2[idx2]) {         v[x].push_back(v1[idx1]);         idx1++;       } else {         v[x].push_back(v2[idx2]);         idx2++;       }     }     while (idx1 != v1.size()) v[x].push_back(v1[idx1++]);     while (idx2 != v2.size()) v[x].push_back(v2[idx2++]);   }   int bs(int a, int h, int l, int r) {     if (l == r) return l;     int mid = (l + r) / 2;     if (v[a][mid] > h) return bs(a, h, l, mid);     if (v[a][mid + 1] > h) return mid;     return bs(a, h, mid + 1, r);   }   long long int cal(int a, long long int h) {     if (h < 0) return 0;     long long int ans = 0;     int x = bs(a, h, 0, v[a].size() - 1);     ans = h * ((long long int)(x + 1)) - dp[a][x];     return ans;   }   int main() {     std::ios_base::sync_with_stdio(false);     std::cin.tie(nullptr);     int n, m;     cin >> n >> m;     v.resize(n + 3);     vv.resize(n + 3);     dp.resize(n + 3);     for (int i = 1; i <= n; i++) v[i].push_back(0);     int x;     for (int i = 1; i <= n - 1; i++) {       cin >> x;       v[(i + 1) / 2].push_back(x);       vv[(i + 1) / 2].push_back(x);     }     for (int i = n; i >= 1; i--) merg(i);     for (int i = 1; i <= n; i++) {       dp[i].push_back(v[i][0]);       for (int j = 1; j < v[i].size(); j++) {         dp[i].push_back(((long long int)(v[i][j])) + dp[i][j - 1]);       }     }     for (int i = 0; i < m; i++) {       int a, h;       cin >> a >> h;       long long int ans = 0;       ans += cal(a, h);       while (a != 1) {         if (a % 2 == 0) {           a /= 2;           if (h - vv[a][0] <= 0) break;           ans += h - vv[a][0];           if (vv[a].size() == 2) {             h = h - vv[a][0] - vv[a][1];             a = a * 2 + 1;             ans += cal(a, h);             a /= 2;             h += vv[a][1];           } else {             h -= vv[a][0];           }         } else {           a /= 2;           if (h - vv[a][1] <= 0) break;           ans += h - vv[a][1];           h = h - vv[a][0] - vv[a][1];           a = a * 2;           ans += cal(a, h);           a /= 2;           h += vv[a][0];         }       }       cout << ans << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n, m, rb, cb, rd, cd;       int count = 0;       cin >> n >> m >> rb >> cb >> rd >> cd;       if (rb <= rd && cb <= cd)         cout << min(rd - rb, cd - cb) << endl;       else if (rb <= rd && cb > cd)         cout << min(rd - rb, 2 * m - cb - cd) << endl;       else if (cb <= cd && rb > rd)         cout << min(cd - cb, 2 * n - rb - rd) << endl;       else         cout << min(2 * n - rb - rd, 2 * m - cb - cd) << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, q, a[3000000 + 5], m[3000000 + 5], dp[3000000 + 5];   inline long long read() {     long long q = 0, f = 1;     char ch = getchar();     while (!isdigit(ch)) {       if (ch ==  - ) f = 0;       ch = getchar();     }     while (isdigit(ch)) q = (q << 3) + (q << 1) + (ch ^ 48), ch = getchar();     return f ? q : -q;   }   inline void print(long long x) {     if (x < 0) putchar( - ), x = -x;     if (x > 9) print(x / 10);     putchar(x % 10 + 48);   }   signed main() {     n = read();     for (register long long i = 1; i <= n; ++i) a[i] = read(), ++m[a[i]];     for (register long long i = 1; i <= 3000000; ++i)       if (m[i])         for (register long long j = i; j <= 3000000; j += i)           dp[j] += m[i] * ((i ^ (j / i)) ? m[j / i] : m[i] - 1);     for (register long long i = 1; i <= 3000000; ++i) dp[i] += dp[i - 1];     q = read();     while (q--) {       long long x = read();       print(n * (n - 1) - dp[x - 1]), putchar(  n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline long long read() {     long long s = 0, w = 1;     char ch = getchar();     for (; !isdigit(ch); ch = getchar())       if (ch ==  - ) w = -1;     for (; isdigit(ch); ch = getchar()) s = (s << 1) + (s << 3) + (ch ^ 48);     return s * w;   }   inline void print(long long x, int op = 10) {     if (!x) {       putchar( 0 );       if (op) putchar(op);       return;     }     char F[40];     long long tmp = x > 0 ? x : -x;     if (x < 0) putchar( - );     int cnt = 0;     while (tmp > 0) {       F[cnt++] = tmp % 10 +  0 ;       tmp /= 10;     }     while (cnt > 0) putchar(F[--cnt]);     if (op) putchar(op);   }   inline long long gcd(long long x, long long y) { return y ? gcd(y, x % y) : x; }   long long qpow(long long a, long long b) {     long long ans = 1;     while (b) {       if (b & 1) ans *= a;       b >>= 1;       a *= a;     }     return ans;   }   long long qpow(long long a, long long b, long long mod) {     long long ans = 1;     while (b) {       if (b & 1) (ans *= a) %= mod;       b >>= 1;       (a *= a) %= mod;     }     return ans % mod;   }   const int dir[][2] = {{0, 1}, {1, 0},  {0, -1}, {-1, 0},                         {1, 1}, {1, -1}, {-1, 1}, {-1, -1}};   const int MOD = 1e9 + 7;   const int INF = 0x3f3f3f3f;   const long long INF64 = 0x3f3f3f3f3f3f3f3f;   const int N = 1e6 + 7;   struct Node {     long long val;     int id;     bool operator<(const Node& opt) const { return val < opt.val; }   };   long long n, m;   set<int> st;   int p[20];   int solve() {     n = read();     int cnt = 0;     for (int i = 1; i <= n; ++i) p[i] = read(), cnt += p[i] == 0;     st.clear();     st.insert(0);     for (int i = 1; i <= n; ++i) {       set<int> tmp = st;       for (auto& it : st) {         int x1 = it - p[i];         int x2 = it + p[i];         cnt += x1 == 0;         cnt += x2 == 0;         tmp.insert(x1), tmp.insert(x2);       }       st = tmp;     }     return cnt;   }   int main() {     int T = read();     for (int _ = 1; _ <= T; ++_) {       cout << (solve() ?  YES  :  NO ) <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   ostream& operator<<(ostream& _s, vector<T> _t) {     for (int i = 0; i < (int)(_t.size()); i++) _s << (i ?     :   ) << _t[i];     return _s;   }   template <typename T>   istream& operator>>(istream& _s, vector<T>& _t) {     for (int i = 0; i < (int)(_t.size()); i++) _s >> _t[i];     return _s;   }   template <typename T, typename U>   ostream& operator<<(ostream& _s, pair<T, U> _t) {     _s <<  (  << _t.first <<  ,  << _t.second <<  ) ;     return _s;   }   template <typename T, typename U>   istream& operator>>(istream& _s, pair<T, U>& _t) {     _s >> _t.first >> _t.second;     return _s;   }   int find(const vector<int>& v, int value, int fr, int to) {     for (int i = fr; i < (int)(to + 1); i++) {       if (v[i] == value) {         return i;       }     }     assert(false);   }   vector<int> invert(const vector<int>& v) {     vector<int> res(v.size());     for (int i = 0; i < (int)(v.size()); i++) {       res[v[i]] = i;     }     return res;   }   int main() {     ios_base::sync_with_stdio(false);     int n;     cin >> n;     vector<int> p(n);     cin >> p;     for (int i = 0; i < (int)(n); i++) p[i]--;     bool is_id = true;     for (int i = 0; i < (int)(n); i++) {       if (p[i] != i) is_id = false;     }     string base_s;     for (int j = 0; j < (int)(n); j++) base_s +=  . ;     vector<string> res(n);     for (int i = 0; i < (int)(n); i++) res[i] = base_s;     if (is_id) {       cout << n << endl;       for (int i = 0; i < (int)(n); i++) {         cout << base_s << endl;       }       return 0;     }     p = invert(p);     int fr = 0, to = n - 1;     for (int row = 0; row < (int)(n); row++) {       if (row == 0) {         int mid = n / 2;         int pos = find(p, mid, fr, to);         for (int i = fr; i < (int)(pos + 1); i++) {           res[row][i] =     ;         }         for (int i = (pos)-1; i >= (int)(fr); i--) {           p[i + 1] = p[i];         }         p[fr] = -1;       } else {         bool left = row % 2 == 1;         int free_pos = left ? fr : to;         assert(p[free_pos] == -1);         int pos = find(p, free_pos, fr, to);         if (left) {           res[row][fr] =  / ;           for (int i = pos; i < (int)(to + 1); i++) {             res[row][i] =  / ;           }           for (int i = pos; i < (int)(to); i++) {             p[i] = p[i + 1];           }           p[to] = -1;           fr++;         } else {           res[row][to] =     ;           for (int i = fr; i < (int)(pos + 1); i++) {             res[row][i] =     ;           }           for (int i = (pos)-1; i >= (int)(fr); i--) {             p[i + 1] = p[i];           }           p[fr] = -1;           to--;         }       }     }     cout << (n - 1) << endl;     for (int i = 0; i < (int)(n); i++) {       cout << res[i] << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   #pragma comment(linker,  /STACK:16777216 )   const int inf = 0x3f3f3f3f;   const long double pi = acos(-1.0);   const string debug_line =  yolo ;   const double PI = 4 * atan(1);   long long dp[81][81];   bool visited[81][81];   vector<pair<int, int> > Adj[81];   int n;   vector<pair<pair<int, int>, string> > edge;   bool check(int l, int r, int l1, int r1, int index1, int index2) {     for (auto &(t1) : (Adj[index1])) {       int op = t1.first;       if (op == 0) {         if (t1.second != index2 && t1.second != index1) {           return false;         }       } else if (op == 2) {         if (t1.second <= l1 || t1.second >= r1) {           return false;         }       } else if (op == 1) {         if (t1.second > l && t1.second < r) {           return false;         }       } else if (op == 3) {         if (!(t1.second > l && t1.second < r)) {           return false;         }       } else if (op == 4) {         if (!(t1.second <= l1 || t1.second >= r1)) {           return false;         }       }     }     for (auto &(t1) : (Adj[index2])) {       int op = t1.first;       if (op == 0) {         if (t1.second != index1 && t1.second != index2) {           return false;         }       } else if (op == 2) {         if (t1.second <= l1 || t1.second >= r1) {           return false;         }       } else if (op == 1) {         if (t1.second > l && t1.second < r) {           return false;         }       } else if (op == 3) {         if (!(t1.second > l && t1.second < r)) {           return false;         }       } else if (op == 4) {         if (!(t1.second <= l1 || t1.second >= r1)) {           return false;         }       }     }     return true;   }   int main() {     int k;     scanf( %d%d , &n, &k);     for (int(i) = (0); (i) < (k); ++(i)) {       int a, b;       string c;       cin >> a >> c >> b;       edge.push_back(make_pair(make_pair(a, b), c));       if (c ==  = ) {         Adj[a].push_back(make_pair(0, b));         Adj[b].push_back(make_pair(0, a));       } else if (c ==  > ) {         Adj[a].push_back(make_pair(1, b));         Adj[b].push_back(make_pair(2, a));       } else if (c ==  < ) {         Adj[a].push_back(make_pair(2, b));         Adj[b].push_back(make_pair(1, a));       } else if (c ==  <= ) {         Adj[a].push_back(make_pair(3, b));         Adj[b].push_back(make_pair(4, a));       } else if (c ==  >= ) {         Adj[a].push_back(make_pair(4, b));         Adj[b].push_back(make_pair(3, a));       }     }     dp[0][2 * n + 1] = 1LL;     priority_queue<pair<pair<int, int>, int>, vector<pair<pair<int, int>, int> >,                    greater<pair<pair<int, int>, int> > >         Q1;     Q1.push(make_pair(make_pair(0, 0), 2 * n + 1));     while (!Q1.empty()) {       pair<pair<int, int>, int> t1 = Q1.top();       Q1.pop();       int l = t1.first.second;       int r = t1.second;       int d = t1.first.first;       visited[l][r] = true;       int valueNext = (l + 2 * n + 1 - r) / 2;       if (l + 3 == r) {         if (check(l, r, l + 1, r - 1, l + 1, r - 1)) {           dp[l + 1][r - 1] = (dp[l + 1][r - 1] + dp[l][r]);         } else {         }         continue;       } else {         if (check(l, r, l + 2, r, l + 1, l + 2)) {           dp[l + 2][r] = (dp[l + 2][r] + dp[l][r]);           if (!visited[l + 2][r]) {             Q1.push(make_pair(make_pair(d + 1, l + 2), r));             visited[l + 2][r] = true;           }         } else {         }         if (check(l, r, l + 1, r - 1, l + 1, r - 1)) {           dp[l + 1][r - 1] = (dp[l + 1][r - 1] + dp[l][r]);           if (!visited[l + 1][r - 1]) {             Q1.push(make_pair(make_pair(d + 1, l + 1), r - 1));             visited[l + 1][r - 1] = true;           }         } else {         }         if (check(l, r, l, r - 2, r - 1, r - 2)) {           dp[l][r - 2] = (dp[l][r - 2] + dp[l][r]);           if (!visited[l][r - 2]) {             Q1.push(make_pair(make_pair(d + 1, l), r - 2));             visited[l][r - 2] = true;           }         } else {         }       }     }     long long answer1 = 0;     for (int(i) = (0); (i) < (2 * n + 1); ++(i)) {       answer1 = (answer1 + dp[i][i + 1]);     }     printf( %lld n , answer1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, i, j, k, q, w, x, y, flag = 0, sum = 0;     char c;     while (true) {       c = getchar();       if (c ==   n ) break;       sum = sum * 10 + int(c -  0 );       q = sum / 2;       sum = sum % 2;     }     if (sum == 1 || q % 2 == 1)       cout <<  0 n ;     else       cout <<  4 n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e3 + 5;   int deg[N];   vector<int> adj[N];   int e[N][3];   int seen[N];   int dfs(int u) {     seen[u] = true;     if (deg[u] == 1) return u;     for (int i = 0; i < adj[u].size(); i++)       if (!seen[adj[u][i]]) return dfs(adj[u][i]);   }   int main() {     int n;     cin >> n;     if (n == 2) {       int x;       cin >> x >> x >> x;       cout <<  YES n ;       cout << 2 <<   n ;       cout <<  1 2 13 n ;       cout <<  1 2   << x - 13;       return 0;     }     if (n == 3) {       cout <<  NO n ;       return 0;     }     for (int i = 0; i < n - 1; i++) {       int u, v, val;       cin >> u >> v >> val;       u--, v--;       deg[u]++;       deg[v]++;       adj[u].push_back(v);       adj[v].push_back(u);       e[i][0] = u;       e[i][1] = v;       e[i][2] = val;     }     for (int i = 0; i < n; i++)       if (deg[i] == 2) {         cout <<  NO n ;         return 0;       }     vector<pair<int, pair<int, int>>> ans;     for (int i = 0; i < n - 1; i++) {       int u, v, val;       u = e[i][0];       v = e[i][1];       val = e[i][2];       if (deg[u] == 1 || deg[v] == 1) {         if (deg[v] == 1) swap(u, v);         int w, z;         memset(seen, 0, sizeof seen);         seen[v] = true;         vector<int> adj_temp;         for (int i = 0; adj_temp.size() < 2; i++)           if (adj[v][i] != u) adj_temp.push_back(adj[v][i]);         w = dfs(adj_temp[0]);         z = dfs(adj_temp[1]);         u++, w++, z++;         ans.push_back({u, {w, val / 2}});         ans.push_back({w, {z, -val / 2}});         ans.push_back({u, {z, val / 2}});       } else {         int x, y, w, z;         vector<int> u_adj, v_adj;         for (int i = 0; u_adj.size() < 2; i++)           if (adj[u][i] != v) u_adj.push_back(adj[u][i]);         for (int i = 0; v_adj.size() < 2; i++)           if (adj[v][i] != u) v_adj.push_back(adj[v][i]);         memset(seen, 0, sizeof seen);         seen[v] = seen[u] = true;         x = dfs(u_adj[0]);         y = dfs(u_adj[1]);         w = dfs(v_adj[0]);         z = dfs(v_adj[1]);         x++, y++, w++, z++;         ans.push_back({x, {w, val / 2}});         ans.push_back({x, {y, -val / 2}});         ans.push_back({w, {z, -val / 2}});         ans.push_back({y, {z, val / 2}});       }     }     cout <<  YES n ;     cout << ans.size() <<   n ;     for (int i = 0; i < ans.size(); i++)       cout << ans[i].first <<     << ans[i].second.first <<                << ans[i].second.second <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   long long int gcd(long long int a, long long int b) {     if (a == 0) return b;     if (b == 0) return a;     return gcd(b % a, a);   }   long long int my_pow(long long int a, long long int b) {     if (b == 0) return 1;     if (b == 1) return a;     long long int half = my_pow(a, b / 2);     long long int ans = (half * half);     if (b % 2) {       ans = (ans * a);     }     return ans;   }   long long int my_pow_mod_p(long long int a, long long int b, long long int p) {     if (b == 0) return 1;     if (b == 1) return a % p;     long long int half = my_pow(a, b / 2);     long long int ans = (half * half) % p;     if (b % 2) {       ans = (ans * a) % p;     }     return ans;   }   class combinatorics {     long long int N;     long long int p;     vector<long long int> fact;     void cal() {       fact[0] = 1;       fact[1] = 1;       for (long long int i = 2; i < N; i++) {         fact[i] = (i * fact[i - 1]) % 1000000007;       }     }       public:     combinatorics(long long int n1, long long int p1) {       p = p1;       N = max(n1, 2LL);       fact.resize(N);       cal();     }     long long int nPr(long long int n, long long int r) {       if (n < r) {         return 0;       }       long long int val = (fact[n] * my_pow_mod_p(fact[n - r], p - 2, p)) % p;       return val;     }     long long int nCr(long long int n, long long int r) {       if (n < r) {         return 0;       }       long long int val = nPr(n, r);       val = (val * my_pow_mod_p(fact[r], p - 2, p)) % p;       return val;     }     long long int get_fact(long long int n) { return fact[n]; }   };   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     string str1, str2;     cin >> str1;     cin >> str2;     long long int len1 = str1.length();     long long int len2 = str2.length();     vector<vector<long long int> > V(len2, vector<long long int>());     map<char, vector<long long int> > M;     for (long long int i = 0; i < len2; i++) {       char curr_char = str2[i];       if (M.find(curr_char) == M.end()) {         M[curr_char] = vector<long long int>();       }       M[curr_char].push_back(i);     }     for (long long int i = 0; i < len1; i++) {       char curr_char = str1[i];       if (M.find(curr_char) != M.end()) {         long long int len = M[curr_char].size();         for (long long int j = 0; j < len; j++) {           V[M[curr_char][j]].push_back(i);         }       }     }     for (int i = len2 - 2; i >= 0; --i) {       while (1) {         long long int last_len = V[i + 1].size();         long long int len = V[i].size();         if (V[i][len - 1] >= V[i + 1][last_len - 1]) {           V[i].pop_back();         } else {           break;         }       }     }     vector<long long int> min_A;     long long int last_val = V[0][0];     min_A.push_back(V[0][0]);     for (long long int i = 1; i < len2; i++) {       long long int next_idx =           upper_bound(V[i].begin(), V[i].end(), last_val) - V[i].begin();       long long int next_val = V[i][next_idx];       min_A.push_back(next_val);       last_val = next_val;     }     long long int ans = V[0][V[0].size() - 1];     for (long long int i = 0; i < len2 - 1; i++) {       long long int next_s = V[i + 1].size();       ans = max(ans, V[i + 1][next_s - 1] - min_A[i] - 1);     }     ans = max(ans, len1 - min_A[len2 - 1] - 1);     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using pii = pair<ll, ll>;   const ll MOD = 1e9 + 7, N = 2e5 + 10;   vector<ll> g[N];   ll vis[N];   ll n, m, k;   void bfs(ll s, vector<ll> &dist) {     for (ll i = 1; i < n + 1; i++) {       vis[i] = 0;     }     dist[s] = 0;     queue<pii> q;     q.push({s, 0});     while (!q.empty()) {       ll nd = q.front().first, st = q.front().second;       q.pop();       if (vis[nd]) continue;       vis[nd] = 1;       dist[nd] = min(dist[nd], st);       for (auto &v : g[nd]) {         q.push({v, st + 1});       }     }   }   int32_t main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cin >> n >> m >> k;     vector<ll> spec;     spec.assign(k, 0);     for (ll i = 0; i < k; i++) {       cin >> spec[i];     }     ll u, v;     for (ll i = 0; i < m; i++) {       cin >> u >> v;       g[u].push_back(v);       g[v].push_back(u);     }     vector<ll> dist_src(n + 2, INT_MAX), dist_dest(n + 2, INT_MAX);     bfs(1, dist_src);     bfs(n, dist_dest);     vector<pii> tmp;     for (auto &i : spec) {       tmp.push_back({dist_dest[i] - dist_src[i], i});     }     sort(tmp.begin(), tmp.end());     ll ans = 0;     for (ll i = 1; i < k; i++) {       ll a = tmp[i - 1].second, b = tmp[i].second;       ll path =           min(dist_src[a] + dist_dest[b] + 1, dist_src[b] + dist_dest[a] + 1);       if (path >= dist_src[n]) {         cout << dist_src[n] <<   n ;         return 0;       }       ans = max(ans, path);     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int str2int(string s) {     istringstream ss(s);     int t;     ss >> t;     return t;   }   int main() {     string s;     cin >> s;     int ans = -1;     for (int i = 1; i < s.length(); i++) {       string s1 = s.substr(0, i);       if (s1.length() > 1 && s1[0] ==  0 ) continue;       int t1 = str2int(s1);       if (t1 > 1000000) continue;       for (int j = 1; j < s.length(); j++) {         if (i + j >= s.length()) continue;         string s2 = s.substr(i, j);         string s3 = s.substr(i + j);         if (s2.length() > 1 && s2[0] ==  0 ) continue;         if (s3.length() > 1 && s3[0] ==  0 ) continue;         int t2 = str2int(s2);         int t3 = str2int(s3);         if (t2 > 1000000) continue;         if (t3 > 1000000) continue;         int temp = t1 + t2 + t3;         if (temp > ans) ans = temp;       }     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   inline int calc(int x, int y, char c) {     if (c ==  & ) return x & y;     if (c ==  | ) return x | y;     return x ^ y;   }   int work() {     char c;     scanf( %c , &c);     if (c ==  ( ) {       int l = work();       char op;       scanf( %c , &op);       int r = work(), res = 0;       scanf( %*c );       for (int i = 0; i < 4; i++) {         if (!(l & (1 << i))) continue;         for (int j = 0; j < 4; j++) {           if (!(r & (1 << j))) continue;           res |= 1 << calc(i, j, op);         }       }       return res;     }     if (c ==  ? ) return 6;     return c ==  0  ? 1 : 8;   }   int main() {     scanf( %*d n );     puts(work() & 6 ?  YES  :  NO );     return 0;   }


#include <bits/stdc++.h>   #pragma warning(disable : 4996)   using namespace std;   const long double pi = acos(-1.0);   const long double eps = 1e-5;   const int INF = 0x3f3f3f3f;   const long long INFLL = 0x3f3f3f3f3f3f3f3f;   int a[300010];   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     int T;     cin >> T;     while (T--) {       int n;       cin >> n;       map<int, int> l;       map<int, int> r;       for (int i = (1); i <= (n); i++) {         cin >> a[i];         if (!l[a[i]]) l[a[i]] = i;         r[a[i]] = i;       }       int ans = l.size();       int p = 0;       int cnt = 0;       int res = 0;       for (auto it : l) {         if (p < it.second)           cnt++;         else           cnt = 1;         p = r[it.first];         res = max(res, cnt);       }       cout << ans - res <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long mod = 1000000007LL;   long long large = 2000000000000000000LL;   int main() {     int n, m;     cin >> n >> m;     vector<vector<int> > adj(n, vector<int>());     set<pair<int, int> > s;     for (int i = 0; i < m; i++) {       int x, y;       cin >> x >> y;       x--;       y--;       if (x > y) swap(x, y);       s.insert(pair<int, int>(x, y));       adj[x].push_back(y);       adj[y].push_back(x);     }     int u = -1, v = -1;     for (int i = 0; i < n; i++) {       for (int j = i + 1; j < n; j++) {         if (s.find(pair<int, int>(i, j)) == s.end()) {           u = i;           v = j;           break;         }       }     }     if (u == -1) {       cout <<  NO  << endl;       return 0;     }     cout <<  YES  << endl;     vector<vector<int> > adjt(n, vector<int>());     for (int i = 0; i < n; i++) {       int f = i;       if (f == v) f = u;       for (int j = 0; j < (int)adj[i].size(); j++) {         int to = adj[i][j];         if (to == v) to = u;         adjt[f].push_back(to);       }     }     queue<int> q;     q.push(u);     vector<int> dis(n, -1);     dis[u] = 0;     while (!q.empty()) {       int u = q.front();       q.pop();       for (int j = 0; j < (int)adjt[u].size(); j++) {         int v = adjt[u][j];         if (dis[v] == -1) {           dis[v] = dis[u] + 1;           q.push(v);         }       }     }     vector<pair<int, int> > e;     for (int i = 0; i < n; i++) {       if (i != v) e.push_back(pair<int, int>(dis[i], i));     }     sort(e.begin(), e.end());     vector<int> a(n, -1);     for (int i = 0; i < (int)e.size(); i++) a[e[i].second] = n - 2 - i;     a[v] = n - 1;     for (int i = 0; i < n; i++) printf( %d  , a[i] + 1);     printf(  n );     a[v] = n - 2;     for (int i = 0; i < n; i++) printf( %d  , a[i] + 1);     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   typedef long long arr64[200020];   int n, tn, tS, qS = 1;   pair<int, long long> pr[200020];   arr64 pX, pY, K, B;   int main() {     long long s;     scanf( %d%I64d , &n, &s);     for (int i = 1; i <= n; i++) scanf( %d%d , &pr[i].first, &pr[i].second);     sort(pr + 1, pr + n + 1);     pr[++n] = make_pair((int)1e9, s);     for (int i = 1; i <= n; i++)       if (i == 1 || pr[i].first > pr[i - 1].first) {         while (tn > 0 && pr[i].second <= pr[tn].second) tn--;         pr[++tn] = pr[i];       }     K[tS = 1] = pr[1].first;     for (int i = 2; i <= tn; i++) {       qS = min(qS, tS);       while (qS < tS &&              (((pr[i].second - B[qS + 1]) / (K[qS + 1]) +                ((pr[i].second - B[qS + 1]) % (K[qS + 1]) != 0)) <                   ((pr[i].second - B[qS]) / (K[qS]) +                    ((pr[i].second - B[qS]) % (K[qS]) != 0)) ||               ((pr[i].second - B[qS + 1]) / (K[qS + 1]) +                ((pr[i].second - B[qS + 1]) % (K[qS + 1]) != 0)) ==                       ((pr[i].second - B[qS]) / (K[qS]) +                        ((pr[i].second - B[qS]) % (K[qS]) != 0)) &&                   (K[qS + 1] * ((pr[i].second - B[qS + 1]) / (K[qS + 1]) +                                 ((pr[i].second - B[qS + 1]) % (K[qS + 1]) != 0)) +                    B[qS + 1] - pr[i].second) >=                       (K[qS] * ((pr[i].second - B[qS]) / (K[qS]) +                                 ((pr[i].second - B[qS]) % (K[qS]) != 0)) +                        B[qS] - pr[i].second)))         qS++;       long long cX = ((pr[i].second - B[qS]) / (K[qS]) +                       ((pr[i].second - B[qS]) % (K[qS]) != 0)),                 cK = pr[i].first;       long long cY = (K[qS] * ((pr[i].second - B[qS]) / (K[qS]) +                                ((pr[i].second - B[qS]) % (K[qS]) != 0)) +                       B[qS] - pr[i].second),                 cB = cY - cK * cX;       if (i == tn) printf( %I64d n , cX);       while (tS > 1 && cK * pX[tS - 1] + cB >= pY[tS - 1]) tS--;       K[++tS] = cK, B[tS] = cB;       pX[tS - 1] = (((B[tS - 1] - B[tS])) / ((K[tS] - K[tS - 1])) +                     (((B[tS - 1] - B[tS])) % ((K[tS] - K[tS - 1])) != 0));       pY[tS - 1] = cK * pX[tS - 1] + cB;     }   }


#include <bits/stdc++.h>   using namespace std;   const long long int N = 200010;   const long long mod = 1000000007;   const long long inf = 1000000000000000000;   const long double pi = 3.14159265358979323846264338;   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int n;     cin >> n;     vector<long long int> a(n);     for (long long int i = 0; i < n; i++) {       cin >> a[i];     }     sort((a).begin(), (a).end());     long long int ans = 0, cnt = 1;     for (long long int i = 0; i < n; i++) {       if (a[i] >= cnt) ans++, cnt++;     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   T sqr(T x) {     return x * x;   }   template <typename T>   T abs(T x) {     return x < 0 ? -x : x;   }   template <typename T>   T gcd(T a, T b) {     return b ? gcd(b, a % b) : a;   }   const int MOD = (int)1e+9 + 7;   int n;   vector<pair<int, int> > a;   vector<int> f;   int powmod(const int a, const int b) {     if (b == 0) {       return 1;     }     long long r = powmod(a, b >> 1);     (r *= r) %= MOD;     return b & 1 ? r * a % MOD : r;   }   int divmod(const int a, const int b) {     return a * (long long)powmod(b, MOD - 2) % MOD;   }   int C(int n, int m) { return divmod(divmod(f[n], f[m]), f[n - m]); }   int main(int argc, char **argv) {     ios_base::sync_with_stdio(false);     cin >> n;     f.resize(n + 1);     f[0] = 1;     for (int i = 1; i <= n; ++i) {       f[i] = f[i - 1] * (long long)i % MOD;     }     for (int i = 1; i <= n; ++i) {       int x;       cin >> x;       if (x) {         a.push_back(make_pair(x, i));       }     }     sort(a.begin(), a.end());     if (a.size() == 0) {       cout << powmod(2, n - 1) << endl;       return 0;     }     int ans = 0;     for (int d = -1; d <= 1; d += 2) {       int l = a[0].second + d * (a[0].first - 1), r = a[0].second;       if (l > r) {         swap(l, r);       }       if (l < 1 || n < r || (l == r && d == 1)) {         continue;       }       long long res = 1;       for (size_t i = 1; i < a.size(); ++i) {         bool f = false;         for (int j = -1; j <= 1; j += 2) {           int L = a[i].second + j * (a[i].first - 1), R = a[i].second + j;           if (L > R) {             swap(L, R);           }           if (L < 1 || n < R || R < r || l < L) {             continue;           }           (res *= C(l - L + R - r, l - L)) %= MOD;           f = true;           l = L;           r = R;           if (r < a[i].second) {             ++r;           } else {             --l;           }           break;         }         if (!f) {           res = 0;           break;         }       }       if (res) {         int L = 1, R = n;         (res *= C(l - L + R - r, l - L)) %= MOD;       }       (ans += res) %= MOD;     }     if (a[0].first > 1) {       ans = ans * (long long)powmod(2, a[0].first - 2) % MOD;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1000000007;   const int N = 110;   struct T {     int bits;     int x;     int k;   };   bool cmp(const T& a, const T& b) { return a.k < b.k; }   T a[N];   long long dp[(1 << 20) + 4];   int n, m;   long long b;   long long Ans() {     const long long INF = 1LL << 60;     long long res = 0;     long long ans = INF;     int top = 1 << m;     for (int i = 0; i < top; ++i) dp[i] = 1LL << 60;     dp[0] = 0;     res = a[0].k * b;     dp[a[0].bits] = a[0].x;     ans = min(ans, dp[top - 1] + res);     for (int i = 1; i < n; ++i) {       res = a[i].k * b;       int& bits = a[i].bits;       for (int j = top - 1; j >= 0; --j)         if (dp[j] != INF) {           dp[j | bits] = min(dp[j | bits], dp[j] + a[i].x);         }       ans = min(ans, dp[top - 1] + res);     }     if (ans == INF) ans = -1;     return ans;   }   int main() {     ios::sync_with_stdio(false);     cin >> n >> m >> b;     int s, t;     for (int i = 0; i < n; ++i) {       cin >> a[i].x >> a[i].k >> s;       a[i].bits = 0;       for (int j = 0; j < s; ++j) {         cin >> t;         a[i].bits |= 1 << (t - 1);       }     }     sort(a, a + n, cmp);     cout << Ans() << endl;   }


#include <bits/stdc++.h>   using namespace std;   long long n, a, b;   int main() {     cin >> n >> a >> b;     for (long long tx = 0; tx <= n; tx += a) {       if ((n - tx) % b == 0) {         cout <<  YES  << endl << tx / a <<     << (n - tx) / b << endl;         return 0;       }     }     cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void task();   int main() {     task();     return 0;   }   const int N = (int)1e5 + 10;   const int MODULO = (int)1e9 + 3;   const long long int INF = (long long int)1e18;   const int BUF_SIZE = (int)1e5 + 10;   bool used[110];   int n, k;   int a[110], b[110];   long long int cat[110][110];   void comp_cat() {     cat[0][0] = 0;     for (int i = 1; i < 101; ++i) {       cat[i][0] = cat[i][i] = 1;       for (int j = 1; j < i; ++j) {         cat[i][j] = cat[i - 1][j - 1] + cat[i - 1][j];       }     }   }   void task() {     scanf( %d %d , &n, &k);     int cnt = n / k;     for (int i = 1; i <= n; ++i) scanf( %d , &a[i]);     double ansmin = 100500, ansmax = -1;     int q;     scanf( %d , &q);     while (q--) {       for (int i = 0; i < cnt; ++i) scanf( %d , &b[i]);       int sum = 0;       if (used[b[0]]) {         continue;       }       for (int i = 0; i < cnt; ++i) {         sum += a[b[i]];         used[b[i]] = 1;       }       ansmin = min(ansmin, (double)sum / cnt);       ansmax = max(ansmax, (double)sum / cnt);     }     vector<int> v;     for (int i = 1; i <= n; ++i)       if (!used[i]) v.push_back(a[i]);     sort(v.begin(), v.end());     int sz = v.size();     (void(1));     if (sz > n % k) {       int sum = 0;       for (int i = 0; i < cnt; ++i) {         sum += v[i];       }       ansmin = min(ansmin, (double)sum / cnt);       sum = 0;       for (int i = sz - 1; i >= sz - cnt; --i) {         sum += v[i];       }       ansmax = max(ansmax, (double)sum / cnt);     }     printf( %.10f %.10f , ansmin, ansmax);   }


#include <bits/stdc++.h>   using namespace std;   const long long inf = INT_MAX, df = 3e5 + 7;   long long i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, dp[df], pos[df],       a[df];   inline long long read() {     long long x = 0, y = 1;     char ch = getchar();     while (ch >  9  || ch <  0 ) y = (ch ==  - ) ? -1 : 1, ch = getchar();     while (ch >=  0  && ch <=  9 )       x = (x << 3) + (x << 1) + ch -  0 , ch = getchar();     return x * y;   }   bool chk(long long x) {     dp[1] = 0;     for (long long i = (2); i <= (n); ++i) {       dp[i] = dp[i - 1];       if (dp[i - 1] >= pos[i] - 1) dp[i] = max(dp[i], pos[i] + x);       if (dp[i - 1] >= pos[i] - x - 1) dp[i] = max(dp[i], pos[i]);       if (dp[i - 2] >= pos[i] - x - 1 && i > 2)         dp[i] = max(dp[i], pos[i - 1] + x);     }     if (dp[n] >= m - x - 1) return 1;     dp[2] = max(pos[2], x);     for (long long i = (3); i <= (n); ++i) {       dp[i] = dp[i - 1];       if (dp[i - 1] >= pos[i] - 1) dp[i] = max(dp[i], pos[i] + x);       if (dp[i - 1] >= pos[i] - x - 1) dp[i] = max(dp[i], pos[i]);       if (dp[i - 2] >= pos[i] - x - 1) dp[i] = max(dp[i], pos[i - 1] + x);     }     if (dp[n] >= min(m - 1, m + pos[2] - x - 1)) return 1;     return 0;   }   int main() {     m = read();     n = read();     long long now = 1;     for (long long i = (1); i <= (n); ++i) a[i] = read(), a[i + n] = a[i] + m;     if (n == 1) {       return printf( %lld n , m - 1), 0;     }     for (long long i = (2); i <= (n); ++i)       if (a[now + 1] - a[now] < a[i + 1] - a[i]) now = i;     long long le = 0, rig = a[now + 1] - a[now] - 1, mid = 0, ans = 0;     for (long long i = (1); i <= (n); ++i) pos[i] = a[i + now];     long long cur = pos[1];     for (long long i = (1); i <= (n); ++i) pos[i] -= cur;     while (le <= rig) {       mid = (le + rig) >> 1;       if (chk(mid))         ans = mid, rig = mid - 1;       else         le = mid + 1;     }     return printf( %lld n , ans), 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   bool chmin(T& a, const T& b) {     return a > b ? a = b, true : false;   }   template <class T>   bool chmax(T& a, const T& b) {     return a < b ? a = b, true : false;   }   const long long mod = 1e9 + 7, N = 2e5 + 5;   inline long long msb(long long val) {     return sizeof(long long) * 8 - __builtin_clzll(val) - 1;   }   long long a[N], n, m, k;   vector<pair<long long, long long> > edges[N];   bool check(long long a) {     while (a > 0) {       if (a % 10 != 4 && a % 10 != 7) return false;       a /= 10;     }     return true;   }   struct des {     vector<long long> p, rnk, sz;     void init() {       p.assign(n + 1, 0);       rnk.assign(n + 1, 0);       sz.assign(n + 1, 1);       for (long long i = 0; i < n; i++) p[i] = i;     }     long long par(long long u) {       if (p[u] == u)         return u;       else         return p[u] = par(p[u]);     }     bool issame(long long u, long long v) { return (par(u) == par(v)); }     void merge(long long u, long long v) {       u = par(u);       v = par(v);       if (u == v) return;       if (rnk[u] > rnk[v]) {         p[v] = u;         sz[u] += sz[v];         rnk[u]++;       } else {         p[u] = v;         sz[v] += sz[u];         rnk[v]++;       }     }     long long get_size(long long u) { return sz[par(u)]; }   } d;   void solve(long long test_case) {     long long i, j;     cin >> n;     d.init();     for (i = 1; i < n; i++) {       long long u, v, w;       cin >> u >> v >> w;       if (!check(w)) d.merge(u, v);     }     long long ans = 0;     for (i = 1; i <= n; i++) {       long long t = n - d.get_size(i);       ans += t * (t - 1);     }     cout << ans <<   n ;     return;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     ;     solve(1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 123456;   int n, d[N], h[N];   bool vis[N];   vector<int> G[N];   struct Node {     int u, h;     bool operator<(const Node& rhs) const { return h < rhs.h; }     Node(int u, int h) : u(u), h(h) {}   };   priority_queue<Node> pq;   int bfs() {     memset(d, -1, sizeof(d));     d[1] = 0;     queue<int> q;     q.push(1);     while (!q.empty()) {       int u = q.front();       q.pop();       for (int v : G[u])         if (d[v] == -1) {           d[v] = d[u] + 1;           q.push(v);         }     }     int ans = 1, maxm = 0;     for (int i = 2; i <= n; i++)       if (d[i] > maxm) {         maxm = d[i];         ans = i;       }     return ans;   }   int dfs(int u, int fa) {     for (int v : G[u])       if (v != fa) h[u] = max(h[u], dfs(v, u) + 1);     if (fa) pq.push(Node(u, h[u]));     return h[u];   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> n;     for (int i = 0; i < n - 1; i++) {       int u, v;       cin >> u >> v;       G[u].push_back(v);       G[v].push_back(u);     }     int root = bfs();     dfs(root, 0);     cout << 1;     int cnt = 1;     for (int i = 2; i <= n; i++) {       if (cnt == n) {         cout <<     << n;         continue;       }       int cur = 0;       while (!pq.empty()) {         Node u = pq.top();         pq.pop();         if (!vis[u.u]) {           cur = u.u;           break;         }       }       for (;;) {         cnt++;         vis[cur] = true;         if (!h[cur]) break;         for (int v : G[cur])           if (h[v] == h[cur] - 1) {             cur = v;             break;           }       }       cout <<     << cnt;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   map<int, int> f;   long long fib[100] = {0};   int solve(long long n) {     int what[100] = {0};     int ind = -1;     for (int i = 90; i >= 0; i--) {       if (n >= fib[i]) {         n -= fib[i], what[i] = true;         if (ind == -1) ind = i;       }     }     vector<int> x, y;     x.push_back(1);     y.push_back(0);     int zero = 0, f = 1;     for (int i = 0; i <= ind; i++) {       if (what[i] == 0)         zero++;       else {         int z1 = (zero / 2) * (x.back() + y.back());         if (zero & 1 && !f) z1 += x.back();         int z2 = x.back() + y.back();         x.push_back(z1);         y.push_back(z2);         zero = 0;         f = false;       }     }     return x.back() + y.back();   }   int main() {     fib[0] = 1;     fib[1] = 2;     for (int i = 2; i <= 90; i++) fib[i] = fib[i - 1] + fib[i - 2];     int T;     long long n;     cin >> T;     while (T--) {       cin >> n;       cout << solve(n) << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 2e9 + 1e8;   const long long INF = 2e18 + 1e17;   const int mod = 998244353;   const int MOD = 1e9 + 7;   long long gcd(long long a, long long b) { return (b == 0 ? a : gcd(b, a % b)); }   bool is_prime(int x) {     if (x <= 1 || (x % 2 == 0 && x > 2)) return false;     for (int i = 3; i * i <= x; i += 2) {       if (!(x % i)) {         return false;       }     }     return true;   }   const int MAXN = 40010;   int N;   string str;   vector<int> arr;   int ans;   int main() {     cin >> N >> str;     arr.resize(N);     int sum = 0;     for (int i = 0; i < str.length(); i++) {       arr[i] = (str[i] ==  )  ? -1 : 1);       sum += arr[i];     }     if (sum != 0) {       cout <<  -1  << endl;       return 0;     }     int cur = 0, last = 0;     bool bad = false;     for (int i = 0; i < N; i++) {       cur += arr[i];       if (!bad && cur < 0) {         bad = true;         last = i;       } else if (cur == 0 && bad) {         ans += (i - last + 1);         bad = false;       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     string s1, s2;     cin >> s1 >> s2;     int n = s1.size();     int m = s2.size();     pair<pair<int, int>, pair<int, char> > parent[n + 1][m + 1][205];     int dp[n + 5][m + 5][205];     for (int i = 0; i <= n; i++) {       for (int j = 0; j <= m; j++) {         for (int bal = 0; bal <= 200; bal++) {           dp[i][j][bal] = 600;         }       }     }     dp[0][0][0] = 0;     for (int i = 0; i <= n; i++) {       for (int j = 0; j <= m; j++) {         for (int bal = 0; bal <= 200; bal++) {           if (dp[i][j][bal] == 600) continue;           int newI = i + (i < n && s1[i] ==  ( );           int newJ = j + (j < m && s2[j] ==  ( );           if (bal + 1 < 205 && dp[newI][newJ][bal + 1] > dp[i][j][bal] + 1) {             dp[newI][newJ][bal + 1] = dp[i][j][bal] + 1;             parent[newI][newJ][bal + 1] =                 make_pair(make_pair(i, j), make_pair(bal,  ( ));           }           newI = i + (i < n && s1[i] ==  ) );           newJ = j + (j < m && s2[j] ==  ) );           if (bal > 0 && dp[newI][newJ][bal - 1] > dp[i][j][bal] + 1) {             dp[newI][newJ][bal - 1] = dp[i][j][bal] + 1;             parent[newI][newJ][bal - 1] =                 make_pair(make_pair(i, j), make_pair(bal,  ) ));           }         }       }     }     int cBal = 0;     for (int bal = 0; bal <= 200; bal++) {       if (dp[n][m][bal] + bal < dp[n][m][cBal] + cBal) {         cBal = bal;       }     }     int ci = n, cj = m;     string res = string(cBal,  ) );     while (ci > 0 || cj > 0 || cBal != 0) {       int nci = parent[ci][cj][cBal].first.first;       int ncj = parent[ci][cj][cBal].first.second;       int ncBal = parent[ci][cj][cBal].second.first;       res += parent[ci][cj][cBal].second.second;       ci = nci;       cj = ncj;       cBal = ncBal;     }     reverse(res.begin(), res.end());     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int DEBUG = 0;   double Min(double a, double b) { return (a < b ? a : b); }   double Max(double a, double b) { return (a > b ? a : b); }   double Abs(double a) { return (a >= 0 ? a : -a); }   void print1d(int *vec, int M, const char *str = NULL) {     if (str != NULL) printf( %s  , str);     for (int i = 0; i < M; i++) {       if (i > 0) printf(   );       printf( %d , vec[i]);     }     printf(  n );   }   struct NODE {     double t, v;   };   int compare_NODE_inc(const void *a_, const void *b_) {     NODE *a = (NODE *)a_;     NODE *b = (NODE *)b_;     if (a->t > b->t)       return 1;     else if (a->t < b->t)       return -1;     else       return 0;   }   int main(int argc, char **argv) {     DEBUG = (argc >= 2) ? atoi(argv[1]) : 0;     int n;     double a, d;     cin >> n >> a >> d;     NODE bus[n];     for (int i = 0; i < n; i++) {       cin >> bus[i].t >> bus[i].v;     }     qsort(bus, n, sizeof(NODE), compare_NODE_inc);     double prevt = 0;     double tim;     for (int i = 0; i < n; i++) {       double t = bus[i].t;       double v = bus[i].v;       if (v * v >= 2.0 * a * d) {         tim = t + sqrt(2.0 * d / a);       } else {         tim = t + (1.0 * d / v + 1.0 * v / 2.0 / a);       }       prevt = Max(tim, prevt);       printf( %.10f n , prevt);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   #pragma comment(linker,  /STACK:8000000 )   int main() {     int n;     scanf( %d , &n);     if (n % 2 == 1) {       printf( -1 );       return 0;     }     for (int k = 0; k != n; ++k)       for (int i = 0; i != n; ++i) {         for (int j = 0; j != n; ++j)           if ((j % 4 < 2) ^ (k % 2 == 0) ^ (i % 4 < 2))             printf( b );           else             printf( w );         printf(  n );       }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     double l, v1, v2;     scanf( %d%lf%lf%lf%d , &n, &l, &v1, &v2, &k);     int num = n / k;     if (num * k < n) {       num++;     }     double w = (v1 + v2) * v2 / (2 * v1 * v2 * num + v2 * v2 - v1 * v2) * l;     double t = w / v2 + (l - w) / v1;     printf( %.10lf n , t);   }


#include <bits/stdc++.h>   using namespace std;   void SOLVE(int, int);   int main() {     int A, B;     cin >> A >> B;     SOLVE(A, B);     return 0;   }   void SOLVE(int A, int B) {     int T1 = min(A, B);     int T2 = (A + B) / 2;     cout << T1 <<     << abs(T2 - T1) << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int Hash = 743;   const int Mod = 51123987;   int powh[2000005], N, h1[2000005], h2[2000005], start[2000005], finish[2000005],       a[2000005], b[2000005];   char s[2000005];   int getsub1(int lo, int hi) {     return lo == 0 ? h1[hi] : h1[hi] - h1[lo - 1] * powh[hi - lo + 1];   }   int getsub2(int lo, int hi) {     return hi == N - 1 ? h2[lo] : h2[lo] - h2[hi + 1] * powh[hi - lo + 1];   }   int main(void) {     powh[0] = 1;     for (int i = 1; i < 2000005; ++i) powh[i] = powh[i - 1] * Hash;     scanf( %d %s , &N, s);     int ch = 0;     for (int i = 0; i < N; ++i) {       ch = ch * Hash + s[i];       h1[i] = ch;     }     ch = 0;     for (int i = N - 1; i >= 0; --i) {       ch = ch * Hash + s[i];       h2[i] = ch;     }     long long tot = 0;     for (int i = 0; i < N; ++i) {       int lo = 1, hi = min(i + 1, N - i), mid, ans = 1;       while (lo <= hi) {         mid = (lo + hi) / 2;         int s1 = getsub1(i, i + mid - 1);         int s2 = getsub2(i - mid + 1, i);         if (s1 == s2) {           lo = mid + 1;           ans = mid;         } else           hi = mid - 1;       }       tot += ans;       tot %= Mod;       a[i - ans + 1] += 1;       a[i + 1] -= 1;       b[i] += 1;       b[i + ans] -= 1;     }     for (int i = 0; i + 1 < N; ++i) {       if (s[i] != s[i + 1]) continue;       int lo = 1, hi = min(i + 1, N - (i + 1)), mid, ans = 1;       while (lo <= hi) {         mid = (lo + hi) / 2;         int s1 = getsub1(i + 1, i + mid);         int s2 = getsub2(i - mid + 1, i);         if (s1 == s2) {           lo = mid + 1;           ans = mid;         } else           hi = mid - 1;       }       tot += ans;       tot %= Mod;       a[i - ans + 1] += 1;       a[i + 1] -= 1;       b[i + 1] += 1;       b[i + 1 + ans] -= 1;     }     for (int i = 0; i < N; ++i) {       a[i] %= Mod;       b[i] %= Mod;       a[i] += Mod;       b[i] += Mod;       start[i] = (i == 0) ? a[i] : start[i - 1] + a[i];       finish[i] = (i == 0) ? b[i] : finish[i - 1] + b[i];       start[i] %= Mod;       finish[i] %= Mod;     }     int sf = 0, sol = 0;     for (int i = 0; i < N; ++i) {       sol = (sol + (long long)(start[i]) * (long long)(sf) % Mod) % Mod;       sf = (sf + finish[i]) % Mod;     }     cout << ((long long)(tot) * (tot - 1) / 2 - sol + Mod) % Mod << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<long long> v[100000 + 1];   long long n, m;   long long taken[100000 + 1];   map<int, int> v2;   int check = 0, sum;   void bfs() {     queue<long long> q;     long long j, x, y;     for (int i = 1; i <= n; i++) {       if (taken[i] == 0) {         q.push(i);         check = 0;         while (!q.empty()) {           x = q.front();           q.pop();           v2[x] = 1;           for (j = 0; j < v[x].size(); j++) {             y = v[x][j];             if (taken[y] == 0) {               q.push(y);               taken[y] = 1;             } else if (taken[y] == 1 && v2[y] == 0) {               check = 1;             }           }         }         if (check == 0) {           sum = sum + 1;         }       }     }   }   int main() {     long long i, x, y;     cin >> n >> m;     for (i = 1; i <= m; i++) {       cin >> x >> y;       v[x].push_back(y);       v[y].push_back(x);     }     sum = 0;     bfs();     cout << sum <<   n ;   }