#include <bits/stdc++.h>   using namespace std;   const int N = 3E6 + 5;   const int M = 3E6 + 5;   struct map {     int l, r;   } Q[M];   int n, m, k, len, tr[N * 4], u, x, P[N], tot;   char s[N], ans[N], ch;   void add(int p, int l, int r, int x) {     if (x < l || x > r) return;     tr[p]++;     if (l == r) return;     int mid = (l + r) / 2;     add(p * 2, l, mid, x);     add(p * 2 + 1, mid + 1, r, x);   }   int get(int x) {     for (int p = 1, l = 1, r = k;;) {       if (l == r) return x == 1 && !tr[p] ? l : k + 1;       int mid = (l + r) / 2;       if (mid - l + 1 - tr[p * 2] < x) {         x -= mid - l + 1 - tr[p * 2];         l = mid + 1;         p = p * 2 + 1;       } else         r = mid, p *= 2;     }   }   int main() {     while (ch = getchar(), ch !=   n  && tot < N) s[tot++] = ch;     if (ch !=   n )       while (ch = getchar(), ch !=   n )         ;     scanf( %d%d , &k, &n);     for (int i = 1; i <= n; i++) scanf( %d%d , &Q[i].l, &Q[i].r);     for (int i = n; i; i--) {       len = Q[i].r - Q[i].l + 1;       u = 1;       for (int j = Q[i].l + 1; j <= Q[i].r && Q[i].r + u <= k; j += 2) {         x = get(Q[i].r + 1);         if (x > k) break;         P[x] = get(j);         u++;         add(1, 1, k, x);       }       for (int j = Q[i].l; j <= Q[i].r && Q[i].r + u <= k; j += 2) {         x = get(Q[i].r + 1);         if (x > k) break;         P[x] = get(j);         u++;         add(1, 1, k, x);       }     }     u = 0;     for (int i = 1; i <= k; i++) {       if (!P[i])         ans[i] = s[u++];       else         ans[i] = ans[P[i]];       putchar(ans[i]);     }   }


#include <bits/stdc++.h>   using namespace std;   long long MOD = 1000000007;   long double EPS = 1e-9;   long long binpow(long long b, long long p, long long mod) {     long long ans = 1;     b %= mod;     for (; p; p >>= 1) {       if (p & 1) ans = ans * b % mod;       b = b * b % mod;     }     return ans;   }   void pre() {}   long long arr[1010][1010];   int row[1010][1010][2];   int col[1010][1010][2];   void solve() {     long long n, m;     cin >> n >> m;     for (long long i = 0; i < (n); ++i) {       for (long long j = 0; j < (m); ++j) {         cin >> arr[i][j];       }     }     for (long long i = 0; i < (n); ++i) {       set<long long> st;       vector<long long> temp;       for (long long j = 0; j < (m); ++j) {         st.insert(arr[i][j]);       }       temp = vector<long long>((st).begin(), (st).end());       for (long long j = 0; j < (m); ++j) {         row[i][j][0] =             lower_bound((temp).begin(), (temp).end(), arr[i][j]) - temp.begin();         row[i][j][1] =             upper_bound((temp).begin(), (temp).end(), arr[i][j]) - temp.begin();         row[i][j][1] = (long long)(temp).size() - row[i][j][1];       }     }     for (long long j = 0; j < (m); ++j) {       set<long long> st;       vector<long long> temp;       for (long long i = 0; i < (n); ++i) {         st.insert(arr[i][j]);       }       temp = vector<long long>((st).begin(), (st).end());       for (long long i = 0; i < (n); ++i) {         col[i][j][0] =             lower_bound((temp).begin(), (temp).end(), arr[i][j]) - temp.begin();         col[i][j][1] =             upper_bound((temp).begin(), (temp).end(), arr[i][j]) - temp.begin();         col[i][j][1] = (long long)(temp).size() - col[i][j][1];       }     }     for (long long i = 0; i < (n); ++i) {       for (long long j = 0; j < (m); ++j) {         cout << max(row[i][j][0], col[i][j][0]) + 1 +                     max(row[i][j][1], col[i][j][1])              <<    ;       }       cout <<   n ;     }   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     pre();     long long t = 1;     for (long long i = 1; i <= t; i++) {       solve();     }   }


#include<bits/stdc++.h>   #define ll long long   using namespace std;      void solve(int tc) {    int n;    cin >> n;    string s;    cin >> s;    vector<int> pos;    for (int i = 0  ; i < n ; i++) {     char ch = s[i];     if (ch ==  * ) pos.push_back(i);    }       int sz = (int)pos.size();    if (sz == 0) {     cout << 0 << endl;     return;    }       int median = sz / 2;    ll ans = 0;    for (int i = median - 1 , j = pos[median] - 1 ; i >= 0 ; i-- , j--) {     ans += abs(pos[i] - j);    }       for (int i = median + 1 , j = pos[median] + 1 ; i < sz ; i++ , j++) {     ans += abs(pos[i] - j);    }       cout << ans << endl;   }      int main()   {    int t;    cin >> t;       while (t--)     solve(0);   }


#include<bits/stdc++.h>      #define ld long double   #define ll long long   using namespace std;   template<class T>   void read(T& x)   {    T res = 0, f = 1; char c = getchar();    while (!isdigit(c)) {     if (c ==  - )f = -1; c = getchar();    }    while (isdigit(c)) {     res = (res << 3) + (res << 1) + c -  0 ; c = getchar();    }    x = res * f;   }   const ll N = 200000 + 10;   const int mod = 1e9 + 7;      struct seg   {   #define ls(x) (x<<1)   #define rs(x) (x<<1|1)   #define mid (l+r)/2    int mn[N << 2],n,a[N],tag[N<<2];    void init(int x,int *dp)    {     n = x;     for (int i = 1; i <= n; i++)a[i] = dp[i];     build(1, 1, n);    }    void push_up(int p)    {     mn[p] = min(mn[ls(p)], mn[rs(p)]);    }    void build(int p, int l, int r)    {     if (l == r)     {      mn[p] = a[l];      return;     }     build(ls(p), l, mid);     build(rs(p), mid + 1, r);     push_up(p);    }       int query(int p, int l, int r, int nl,int nr)    {     if (l >nr || nl>r)return 1e9;     if (nl<=l&&r<=nr)     {      return mn[p];     }         return  min(query(ls(p), l, mid, nl,nr), query(rs(p), mid + 1, r, nl,nr));    }   }seg;   int n[5],dp[5][N];   int w[5][N];   vector<int>p[5][N];   int main()   {    //ios::sync_with_stdio(false);   #ifndef ONLINE_JUDGE    freopen( test.in ,  r , stdin);   #endif // ONLINE_JUDGE    for (int i = 1; i <= 4; i++)read(n[i]);    for (int i = 1; i <= 4; i++)     for (int j = 1; j <= n[i]; j++)      read(w[i][j]);    for (int i = 2; i <= 4; i++)    {     int m; read(m);     for (int j = 1; j <= n[i]; j++)p[i][j].push_back(0);     for (int j = 1; j <= m; j++)     {      int x, y; read(x), read(y);      p[i][y].push_back(x);     }     for (int j = 1; j <= n[i]; j++)p[i][j].push_back(n[i-1]+1);    }    memset(dp, 0x3f, sizeof(dp));    for (int i = 1; i <= n[1]; i++)dp[1][i] = w[1][i];       for (int i = 2; i <= 4; i++)    {     seg.init(n[i-1],dp[i-1]);     for (int j = 1; j <= n[i]; j++)sort(p[i][j].begin(), p[i][j].end());          for (int j =1; j <=n[i]; j++)     {      for (int k = 0; k + 1 < p[i][j].size(); k++)      {       dp[i][j] = min(dp[i][j], w[i][j] + seg.query(1, 1, n[i - 1], p[i][j][k] + 1, p[i][j][k + 1] - 1));      }     }         }    int ans = 1e9;    for (int i = 1; i <= n[4]; i++)ans = min(ans, dp[4][i]);    printf( %d n , ans==1e9?-1:ans);    return 0;   }


#include <bits/stdc++.h>   using namespace std;   void inp(long long &n, long long &m, vector<long long> &v,            vector<pair<signed, signed> > &rope) {     cin >> n >> m;     v.resize(n + 1);     rope.resize(m + 1);     for (long long i = 1; i <= n; ++i) {       cin >> v[i];     }     for (long long i = 1; i <= m; ++i) {       cin >> rope[i].first >> rope[i].second;     }   }   void solve() {     long long n, m, res = 0;     vector<long long> v;     vector<pair<signed, signed> > rope;     inp(n, m, v, rope);     for (long long i = 1; i <= m; ++i) {       res += min(v[rope[i].first], v[rope[i].second]);     }     cout << res;   }   signed main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool agm(pair<int, int> a, pair<int, int> b) {     if (a.first == b.first) {       if (a.second > b.second)         return true;       else         return false;     } else if (a.first < b.first)       return true;     else       return false;   }   void solve(vector<int> &v, int sz) {     int l = 0, idx, r = sz - 1;     idx = max_element(v.begin(), v.end()) - v.begin();     vector<pair<int, int> > vec;     for (int i = idx; i <= r; i++) {       vec.push_back(make_pair(v[i], i));     }     sort(vec.begin(), vec.end(), agm);     reverse(vec.begin(), vec.end());     l = vec[0].second;     printf( %c , vec[0].first +  a );     for (int i = 0; i < vec.size(); i++) {       if (vec[i].second > l) {         l = vec[i].second;         printf( %c , vec[i].first +  a );       }     }   }   int main() {     string s;     cin >> s;     int sz = s.length();     vector<int> v(sz, 0);     for (int i = 0; i < sz; i++) v[i] = s[i] -  a ;     solve(v, sz);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     cout <<  INTERCAL ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = -1;   const long long INF = 1e9 + 19;   int main() {     int n, m, x;     scanf( %d%d%d , &n, &m, &x);     x--;     auto f = [&](int y) {       int nn = n - y * 2;       int mm = m - y * 2;       if (nn <= 0 || mm <= 0) {         return 0;       }       return (nn * mm + 1) / 2;     };     cout << f(x) - f(x + 1) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int OO = 1e9;   const double EPS = 1e-9;   template <class T>   void _db(const char* dbStr, T e) {     cout << dbStr <<   =   << e << endl;   }   template <class T, class... L>   void _db(const char* dbStr, T e, L... r) {     while (*dbStr !=  , ) cout << *dbStr++;     cout <<   =   << e <<  , ;     _db(dbStr + 1, r...);   }   template <class S, class T>   ostream& operator<<(ostream& o, const map<S, T>& v) {     o <<  [ ;     int i = 0;     for (const pair<S, T>& pr : v)       o << (!i++ ?    :  ,  ) <<  {  << pr.first <<   :   << pr.second <<  } ;     return o <<  ] ;   }   template <template <class, class...> class S, class T, class... L>   ostream& operator<<(ostream& o, const S<T, L...>& v) {     o <<  [ ;     int i = 0;     for (const auto& e : v) o << (!i++ ?    :  ,  ) << e;     return o <<  ] ;   }   template <class S, class T>   ostream& operator<<(ostream& o, const pair<S, T>& pr) {     return o <<  (  << pr.first <<  ,   << pr.second <<  ) ;   }   ostream& operator<<(ostream& o, const string& s) {     for (const char& c : s) o << c;     return o;   }   template <class T>   using V = vector<T>;   template <class T>   using VV = V<V<T>>;   template <class T>   using VVV = VV<V<T>>;   using ll = long long;   using pii = pair<int, int>;   using vi = V<int>;   using vii = V<pii>;   using vvi = VV<int>;   using mii = map<int, int>;   using umii = unordered_map<int, int>;   using si = set<int>;   using usi = unordered_set<int>;   const int MX = 2e5 + 5;   int N, M;   ll s[5];   vvi A, B;   ll sumR[MX], sumC[MX];   int main() {     ios::sync_with_stdio(false);     cout.precision(10);     cin.tie(0);     cin >> N >> M;     A.assign(N, vi(M));     for (int i = 0; i < N; ++i) {       for (int j = 0; j < M; ++j) {         cin >> A[i][j];       }     }     if (max(N, M) <= 2) {       ll ans = 0;       for (int i = 0; i < N; ++i) {         for (int j = 0; j < M; ++j) {           ans += A[i][j];         }       }       cout << ans <<   n ;       return 0;     }     if (N > M) {       B = A;       A.assign(M, vi(N));       for (int i = 0; i < N; ++i) {         for (int j = 0; j < M; ++j) {           A[j][i] = B[i][j];         }       }       swap(N, M);     }     for (int i = 0; i < N; ++i) {       for (int j = 0; j < M; ++j) {         sumR[i] += A[i][j];         sumC[j] += A[i][j];       }     }     ll ans = 0;     ll cand = 0;     if (N >= 4) {       for (int i = 0; i < N; ++i) {         s[0] = sumR[i];         sort(s, s + 5);       }       for (int i = 1; i < 5; ++i) {         cand += s[i];       }       ans = max(ans, cand);     }     true;     s[0] = s[1] = s[2] = s[3] = s[4] = 0;     if (M >= 4) {       for (int i = 0; i < M; ++i) {         s[0] = sumC[i];         sort(s, s + 5);       }       cand = 0;       for (int i = 1; i < 5; ++i) {         cand += s[i];       }     }     ans = max(ans, cand);     true;     if (M >= 3) {       for (int i = 0; i < N; ++i) {         s[0] = s[1] = s[2] = s[3] = 0;         for (int j = 0; j < M; ++j) {           s[0] = sumC[j] - A[i][j];           sort(s, s + 4);         }         cand = 0;         for (int j = 1; j < 4; ++j) {           cand += s[j];         }         ans = max(ans, sumR[i] + cand);       }     }     true;     if (N >= 3) {       for (int i = 0; i < M; ++i) {         s[0] = s[1] = s[2] = s[3] = 0;         for (int j = 0; j < N; ++j) {           s[0] = sumR[j] - A[j][i];           sort(s, s + 4);         }         cand = 0;         for (int j = 1; j < 4; ++j) {           cand += s[j];         }         ans = max(ans, sumC[i] + cand);       }     }     true;     s[0] = s[1] = s[2] = 0;     {       for (int i = 0; i < N; ++i) {         for (int j = i + 1; j < N; ++j) {           s[0] = s[1] = s[2] = 0;           cand = 0;           for (int k = 0; k < M; ++k) {             s[0] = sumC[k] - A[i][k] - A[j][k];             sort(s, s + 3);           }           ans = max(ans, sumR[i] + sumR[j] + s[1] + s[2]);         }       }     }     true;     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string solve(int n) {     if (n == 1) {       return  -1 ;     } else {       return  2  + string(n - 1,  3 );     }   }   int main() {     ios::sync_with_stdio(0), cin.tie(0);     int T;     cin >> T;     while (T--) {       int n;       cin >> n;       cout << solve(n) <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int rj = 1000000000;     int n, m, a, b;     scanf( %d %d %d %d , &n, &m, &a, &b);     for (int i = 0; i <= n; i++)       for (int j = 0; j <= n; j++) {         if (i + j * m < n) continue;         rj = min(rj, a * i + b * j);       }     printf( %d n , rj);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const double Pi = acos(-1);   namespace {   template <typename T>   inline void read(T &x) {     x = 0;     T f = 1;     char s = getchar();     for (; !isdigit(s); s = getchar())       if (s ==  - ) f = -1;     for (; isdigit(s); s = getchar()) x = (x << 3) + (x << 1) + (s ^ 48);     x *= f;   }   }  // namespace   long long fun(long long x) {     switch (x % 4) {       case 0:         return x;       case 1:         return 1;       case 2:         return x + 1;       case 3:         return 0;     }   }   int main() {     int n;     read(n);     long long xi, mi;     long long ans = 0;     for (int i = 1; i <= n; i++) {       read(xi);       read(mi);       ans ^= fun(xi + mi - 1) ^ fun(xi - 1);     }     if (ans)       cout <<  tolik  << endl;     else       cout <<  bolik  << endl;   }


#include <bits/stdc++.h>   using namespace std;   struct point {     double x, y;     point(){};     point(double _x, double _y) { x = _x, y = _y; }   };   point s, e;   double det(double a, double b, double c, double d) { return (a * d - b * c); }   point perpotongan(point p1, point p2, point p3, point p4) {     point has;     has.x = -137;     has.y = -1134;     double d1 = det(p1.x, p1.y, p2.x, p2.y);     double d2 = det(p1.x, 1, p2.x, 1);     double d3 = det(p3.x, p3.y, p4.x, p4.y);     double d4 = det(p3.x, 1, p4.x, 1);     double d5 = det(p1.x, 1, p2.x, 1);     double d6 = det(p1.y, 1, p2.y, 1);     double d7 = det(p3.x, 1, p4.x, 1);     double d8 = det(p3.y, 1, p4.y, 1);     double top = det(d1, d2, d3, d4);     double bot = det(d5, d6, d7, d8);     if (bot == 0) return (has);     has.x = top / bot;     d2 = det(p1.y, 1, p2.y, 1);     d4 = det(p3.y, 1, p4.y, 1);     top = det(d1, d2, d3, d4);     has.y = top / bot;     return (has);   }   double dist(point p1, point p2) { return hypot(p1.x - p2.x, p1.y - p2.y); }   int main() {     scanf( %lf %lf , &s.x, &s.y);     scanf( %lf %lf , &e.x, &e.y);     int n;     scanf( %d , &n);     double a, b, c;     point p, q;     int ans = 0;     for (int i = 1; i <= n; i++) {       scanf( %lf %lf %lf , &a, &b, &c);       double kiri = a * s.x + b * s.y + c;       double kanan = a * e.x + b * e.y + c;       if (((kiri > 0) && (kanan < 0)) || ((kiri < 0) && (kanan > 0))) ++ans;     }     printf( %d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   int n, a[301][301], dp[301][301][301];   int solve(int i, int j, int k) {     if (i == n && j == n && k == 0) return a[n][n];     int x = i + k, y = j - k;     if (x < 1 || y < 1 || x > n || y > n || i < 1 || j < 1 || i > n || j > n ||         k < 0)       return -1e9;     if (dp[i][j][k] != -2.1e9) return dp[i][j][k];     return dp[i][j][k] = a[i][j] + (k != 0) * a[x][y] +                          max(max(solve(i + 1, j, k), solve(i + 1, j, k - 1)),                              max(solve(i, j + 1, k + 1), solve(i, j + 1, k)));   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n;     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= n; ++j) cin >> a[i][j];     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= n; ++j)         for (int k = 0; k <= n; ++k) dp[i][j][k] = -2.1e9;     cout << solve(1, 1, 0);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     string s;     cin >> n >> s;     for (int i = 0; i < n; ++i)       for (int interval = 1; interval <= n; ++interval) {         int cnt = 0, cur = i;         while (cur < n && s[cur] ==  * ) ++cnt, cur = cur + interval;         if (cnt >= 5) goto END;       }     cout <<  no ;     return 0;   END:     cout <<  yes ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string s =        What are you doing at the end of the world? Are you busy? Will you save          us? ;   string s1 =  What are you doing while sending   ;   string s2 =   ? Are you busy? Will you send   ;   string s3 =   ? ;   const int MAX_N = 1e5 + 10;   const long long MAX_F = 1e18 + 10;   long long F[MAX_N] = {(int)s.size()};   char f(int n, long long k) {     if (F[n] <= k) return  . ;     if (n == 0) return s[k];     if (k < (int)s1.size()) return s1[k];     k -= (int)s1.size();     if (k < F[n - 1]) return f(n - 1, k);     k -= F[n - 1];     if (k < (int)s2.size()) return s2[k];     k -= (int)s2.size();     if (k < F[n - 1]) return f(n - 1, k);     k -= F[n - 1];     return s3[k];   }   int main() {     ios_base ::sync_with_stdio(false), cout.tie(0), cin.tie(0);     int l = (int)s1.size() + (int)s2.size() + (int)s3.size();     for (int i = 1; i < MAX_N; i++) {       if (2 * F[i - 1] + l > MAX_F)         F[i] = MAX_F;       else         F[i] = 2 * F[i - 1] + l;     }     int q;     cin >> q;     while (q--) {       int n;       long long k;       cin >> n >> k;       cout << f(n, k - 1);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0), cout.tie(0);     string a, s;     cin >> a >> s;     vector<int> v(10, 0);     for (int i = 0; i < s.size(); i++) v[s[i] - 48]++;     int j = 9;     for (int i = 0; i < a.size(); i++) {       while (v[j] == 0 and j > 0) j--;       if (j > a[i] - 48) {         a[i] = j + 48;         v[j]--;       }     }     cout << a << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   char cmd[(100000 + 10)];   int vis[510][510], path[(100000 + 10)];   const int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};   int convert(char ch) {     if (ch ==  R )       return 0;     else if (ch ==  L )       return 1;     else if (ch ==  D )       return 2;     else       return 3;   }   bool Inborder(int x, int y) {     if (x < 0 || x >= n || y < 0 || y >= m) return false;     return true;   }   int main() {     int x0, y0;     scanf( %d%d%d%d , &n, &m, &x0, &y0);     scanf( %s , cmd);     memset(vis, 0, sizeof(vis));     int cnt = 0, pos = 0, len = strlen(cmd), ans = n * m;     path[cnt++] = 1;     ans--;     int x = x0 - 1, y = y0 - 1;     vis[x][y] = 1;     while (pos < len - 1) {       int dir = convert(cmd[pos++]);       if (!Inborder(dx[dir] + x, dy[dir] + y)) {         path[cnt++] = 0;         continue;       }       x += dx[dir];       y += dy[dir];       if (vis[x][y]) {         path[cnt++] = 0;       } else {         ans--;         path[cnt++] = 1;         vis[x][y] = 1;       }     }     for (int i = 0; i < cnt; i++) {       printf( %d  , path[i]);     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int q;     scanf( %d , &q);     while (q--) {       int n;       scanf( %d , &n);       int cnt = 0;       int aa[1000];       for (int i = 1; i <= n; i++) {         scanf( %d , &aa[i]);       }       sort(aa + 1, aa + 1 + n);       int flag = 1;       for (int i = 2; i <= n; i++) {         if (aa[i] == aa[i - 1] + 1) {           flag = 0;         }       }       if (!flag)         printf( 2 n );       else         printf( 1 n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct point {     long long x, y;   };   istream &operator>>(istream &in, point &p) {     in >> p.x >> p.y;     return in;   }   ostream &operator<<(ostream &out, point &p) {     out << p.x <<     << p.y;     return out;   }   double len(struct point a, struct point b) {     return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));   }   int main() {     ios_base::sync_with_stdio(NULL);     cin.tie(NULL);     cout.tie(NULL);     long long r;     point a, b;     cin >> r;     cin >> a >> b;     cout << ceil(len(a, b) / (r * 2));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   map<string, long long> m;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     vector<pair<long long, long long> > v = {         make_pair(1989, 1998),           make_pair(1999, 2098),         make_pair(2099, 3098),           make_pair(3099, 13098),         make_pair(13099, 113098),        make_pair(113099, 1113098),         make_pair(1113099, 11113098),    make_pair(11113099, 111113098),         make_pair(111113099, 1111113098)};     for (int i = 1989; i <= 1998; i++) {       string s =   ;       long long temp = i;       s += (temp % 10 + 48);       m[s] = i;     }     for (int i = 1999; i <= 2098; i++) {       string s =   ;       long long temp = i;       for (int j = 0; j < 2; j++) {         s += (temp % 10 + 48);         temp /= 10;       }       reverse(s.begin(), s.end());       m[s] = i;     }     for (int i = 2099; i <= 3098; i++) {       string s =   ;       long long temp = i;       for (int j = 0; j < 3; j++) {         s += (temp % 10 + 48);         temp /= 10;       }       reverse(s.begin(), s.end());       m[s] = i;     }     int n;     cin >> n;     for (int i = 1; i <= n; i++) {       string s;       cin >> s;       string work =   ;       int sz = s.size();       for (int j = 4; j < sz; j++) {         work += s[j];       }       sz = work.size();       if (sz <= 3) {         cout << m[work] <<   n ;       } else {         long long temp = v[sz - 1].first;         string s1 =   ;         while (temp) {           s1 += (temp % 10 + 48);           temp /= 10;         }         reverse(s1.begin(), s1.end());         if (work < s1) {           cout << 1 << work <<   n ;         } else {           cout << work <<   n ;         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, k, res;     scanf( %lld %lld , &n, &k);     if (k <= n) {       if (k % 2 == 0)         res = (k - 1) / 2;       else if (k % 2 == 1)         res = k / 2;     } else if (k > n) {       if (k - n <= n)         res = (n - (k - n) + 1) / 2;       else if (k - n > n)         res = 0;     } else if (n == k)       res = (n - 1) / 2;     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, a[100005], p[100005];   long long cost;   int main() {     ios_base::sync_with_stdio(false);     cin >> n;     for (int i = 0; i < n; ++i) {       cin >> a[i] >> p[i];     }     int mn = p[0];     for (int i = 0; i < n; ++i) mn = min(p[i], mn), cost += mn * 1LL * a[i];     cout << cost << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, d, sum = 0, ans = 0;     cin >> n >> d;     string *s = new string[d];     for (int i = 0; i < d; i++) cin >> s[i];     for (int i = 0; i < d; i++) {       int flag = 0;       for (int k = 0; k < n; k++) {         if (s[i][k] ==  0 ) {           flag = 1;           break;         }       }       if (flag)         ans++;       else         ans = 0;       sum = max(sum, ans);     }     cout << sum << endl;   }


#include <bits/stdc++.h>   using namespace std;   const long long MAXN = 1e5 + 5;   const long long mod = 1e9 + 7;   long long fact[MAXN];   long long invfact[MAXN];   bool sieve[MAXN];   long long powe(long long x, long long y, long long mod) {     long long res = 1;     while (y > 0) {       if (y & 1) res = (res * x) % mod;       y = y >> 1;       x = (x * x) % mod;     }     return res;   }   void makesieve() {     for (long long i = 0; i < MAXN; ++i) {       sieve[i] = 1;     }     sieve[0] = 0;     sieve[1] = 0;     for (long long i = 2; i * i <= MAXN; ++i) {       for (long long j = 2 * i; j < MAXN; j += i) {         sieve[j] = 0;       }     }   }   void pre() {     fact[0] = 1;     invfact[0] = 1;     for (long long i = 1; i < MAXN; ++i) {       fact[i] = (fact[i - 1] * i) % mod;       invfact[i] = powe(fact[i], mod - 2, mod);     }     makesieve();   }   long long comb(long long n, long long r) {     if (r == 0 || n == r) return 1;     if (r > n) return 0;     long long A = (fact[n] * invfact[r]) % mod;     return (A * invfact[n - r]) % mod;   }   long long gcde(long long a, long long b) {     if (a == 0) return b;     return gcde(b % a, a);   }   long long gcdExtended(long long a, long long b, long long *x, long long *y) {     if (a == 0) {       *x = 0, *y = 1;       return b;     }     long long x1, y1;     long long gcd = gcdExtended(b % a, a, &x1, &y1);     *x = y1 - (b / a) * x1;     *y = x1;     return gcd;   }   long long modInverse(long long a, long long m) {     long long x, y;     long long g = gcdExtended(a, m, &x, &y);     return (x % m + m) % m;   }   bool ifcontains(string str, string smlstr) {     if (str.length() < smlstr.length()) return false;     for (long long i = 0; i < str.length(); ++i) {       bool fg = 0;       for (long long j = 0; j < smlstr.length(); ++j) {         if (i + j >= str.length()) {           fg = 1;           break;         }         if (smlstr[j] != str[i + j]) {           fg = 1;           break;         }       }       if (!fg) return true;     }     return false;   }   int main() {     pre();     long long n, k;     cin >> n >> k;     long long ans = 0;     for (long long i = 0; i <= n; ++i) {       for (long long j = 0; j <= n; ++j) {         long long sign;         if ((i + j) % 2 == 0)           sign = 1;         else           sign = -1;         long long total_cells = (i + j) * n - i * j;         long long rest_cells = n * n - total_cells;         long long temp =             (powe(k - 1, total_cells, mod) * powe(k, rest_cells, mod)) % mod *             sign;         temp = (temp + mod) % mod;         temp *= (comb(n, i) * comb(n, j)) % mod;         temp %= mod;         ans += temp;         ans %= mod;       }     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     int n, m;     cin >> n >> m;     int count = 0;     int a[n + 1][m + 1];     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) cin >> a[i][j];     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         if (a[1][j] == 1 || a[n][j] == 1) {           cout <<  2 ;           count++;           return;         }       }       if (a[i][1] == 1 || a[i][m] == 1) {         cout <<  2 ;         count++;         return;       }     }     if (count == 0) cout <<  4 ;   }   int main() {     ios_base::sync_with_stdio(false);     int t = 1;     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char mat[100][100];   int main(void) {     int minyX = (1 << 30), minyY = (1 << 30), maxyX = 0, maxyY = 0;     int n, m;     scanf( %d %d , &n, &m);     for (int i = 0; i < n; ++i) {       scanf( %s , mat[i]);       for (int j = 0; j < m; ++j) {         if (mat[i][j] !=  * ) continue;         if (i < minyX) minyX = i;         if (i > maxyX) maxyX = i;         if (j < minyY) minyY = j;         if (j > maxyY) maxyY = j;       }     }     for (int row = minyX; row <= maxyX; ++row) {       for (int col = minyY; col <= maxyY; ++col) {         printf( %c , mat[row][col]);       }       printf(  n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 7;   char s[N];   int m, n;   void sol() {     int b[26] = {0};     scanf( %d %d , &n, &m);     int a[N] = {0};     scanf( %s , s);     int t;     for (int i = 0; i < m; i++) {       scanf( %d , &t);       a[t - 1]++;     }     a[n - 1] = 1;     for (int i = n - 1; i >= 0; i--) {       if (i < n - 1) a[i] += a[i + 1];       int num = s[i] -  a ;       b[num] += a[i];     }     for (int i = 0; i < 26; i++) {       if (i != 25)         printf( %d  , b[i]);       else         printf( %d n , b[i]);     }   }   int main() {     int T;     scanf( %d , &T);     while (T--) sol();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 201;   const int logn = 20;   struct matrix {     double a[maxn][maxn];     int n;     bool is_vec;     matrix() {}     void init(int n) {       this->n = n;       is_vec = 0;       for (int i = 1; i <= n; i++) {         for (int j = 1; j <= n; j++) {           a[i][j] = 0;         }       }     }     matrix operator*(const matrix &m2) const {       matrix ans;       ans.init(n);       if (is_vec) {         ans.is_vec = 1;         for (int j = 1; j <= n; j++) {           for (int k = 1; k <= n; k++) {             ans.a[1][j] += a[1][k] * m2.a[j][k];           }         }         return ans;       }       for (int i = 1; i <= n; i++) {         for (int j = 1; j <= n; j++) {           for (int k = 1; k <= n; k++) {             ans.a[i][j] += a[i][k] * m2.a[k][j];           }         }       }       return ans;     }   };   matrix A[logn];   int n;   int px[maxn], py[maxn];   vector<int> p[maxn][maxn];   int cnt[maxn];   bool vis[maxn][maxn];   void init();   double cal(int t, int m);   bool is_line(int a, int b, int c);   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d%d , &px[i], &py[i]);     }     init();     int q;     scanf( %d , &q);     while (q--) {       int t, m;       scanf( %d%d , &t, &m);       printf( %.7lf n , cal(t, m));     }     return 0;   }   double cal(int t, int m) {     m--;     matrix f;     f.init(n);     f.is_vec = 1;     f.a[1][t] = 1;     for (int i = 0; i < logn; i++) {       if ((m >> i) & 1) {         f = f * A[i];       }     }     double max_ans = 0;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= cnt[i]; j++) {         double cur_ans = 0;         for (int u : p[i][j]) {           cur_ans += f.a[1][u];         }         cur_ans /= p[i][j].size();         max_ans = max(max_ans, cur_ans);       }     }     return max_ans;   }   void init() {     vector<int> cur;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         if (i == j || vis[i][j]) continue;         cur.clear();         cur.push_back(i);         cur.push_back(j);         for (int k = 1; k <= n; k++) {           if (i == k || j == k || !is_line(i, j, k)) continue;           cur.push_back(k);         }         for (int a : cur) {           vis[i][a] = 1;         }         p[i][++cnt[i]] = cur;       }     }     A[0].init(n);     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= cnt[i]; j++) {         for (int a : p[i][j]) {           A[0].a[i][a] += 1.0 / cnt[i] / p[i][j].size();         }       }     }     for (int i = 1; i < logn; i++) {       A[i] = A[i - 1] * A[i - 1];     }   }   bool is_line(int a, int b, int c) {     int x1 = px[b] - px[a];     int x2 = px[c] - px[a];     int y1 = py[b] - py[a];     int y2 = py[c] - py[a];     return (long long)x1 * y2 - (long long)x2 * y1 == 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> a;   int gcd(int a, int b) {     if (b == 0) {       return a;     }     return gcd(b, a % b);   }   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int T;     cin >> T;     while (T--) {       int n;       cin >> n;       a.clear();       a.resize(n + 1);       bool can = true;       for (int i = 1; i <= n; i++) {         cin >> a[i];         if (a[i] % (i + 1) == 0) {           bool updated = false;           int max = (a[i] < i + 1) ? a[i] : i;           for (int j = 1; j + 1 <= max; j++) {             if (a[i] % (j + 1) != 0) {               updated = true;               break;             }           }           if (!updated) {             can = false;           }         }       }       if (can) {         cout <<  YES n ;       } else {         cout <<  NO n ;       }     }   }


#include <bits/stdc++.h>   #define fi first   #define se second   #define mp make_pair   using namespace std;      typedef pair <int, int> pii;      struct UF {    int fa[3010];    void clear(int 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]);    }    void merge(int x, int y) {     x = find(x), y = find(y);     if (x == y) return ;     fa[y] = x;    }   }uf;      vector <int> ans;   vector <pii> all;   int G[3010][3010], in[3010], cnt[3010], nin[3010];   int n, m;      void dfs(int x) {    for (int i = 1; i <= n; i++) {     if (!G[x][i]) continue;     G[x][i] = G[i][x] = 0;     dfs(i);    }    ans.push_back(x);   }      void print() {    reverse(ans.begin(), ans.end());    printf( %d n , ans.size());    for (int i = 0; i < ans.size(); i++) {     printf( %d  , ans[i]);    }    printf(  n );   }      int main() {    scanf( %d%d , &n, &m);    for (int i = 0; i < m; i++) {     int x, y; scanf( %d%d , &x, &y);     G[x][y] = G[y][x] = 1, in[x]++, in[y]++;     all.push_back(mp(x, y));    }    int tot = 0;    for (int i = 1; i <= n; i++) {     tot += in[i] & 1;    }    if (tot <= 2) {     int rt = 1;     for (int i = 1; i <= n; i++) {      if (in[i] & 1) {       rt = i;       break;      }     }     dfs(rt);     print();     return 0;    }    for (int i = 1; i <= n; i++) {     if (in[i] % 2 == 0) continue;     for (int j = 1; j <= n; j++) {      if (G[i][j] || i == j) cnt[j]++;     }    }    for (int i = 1; i <= n; i++) {     if (cnt[i] < tot - 1) continue;     for (int j = 1; j <= n; j++) {      if (i == j) continue;      if (cnt[i] == tot - 1 && G[i][j]) continue;      if (in[j] % 2 == 0) continue;      uf.clear(n);      for (int i = 1; i <= n; i++) {       nin[i] = 0;      }      for (int k = 0; k < all.size(); k++) {       int x = all[k].fi, y = all[k].se;       if ((x == i || y == i) && x + y - i != j && in[x + y - i] & 1) continue;       uf.merge(x, y);       nin[x]++, nin[y]++;      }      int eq = -1;      for (int k = 1; k <= n; k++) {       if (!nin[k]) continue;       int val = uf.find(k);       if (eq == -1) eq = val;       if (eq != val) goto END;      }      for (int k = 1; k <= n; k++) {       if (k == i || k == j) continue;       if (in[k] & 1) {        G[i][k] = G[k][i] = 0;        ans.push_back(i);        ans.push_back(k);       }      }      ans.push_back(-1);      dfs(j);      print();      return 0;      END:;     }    }    printf( 0 n );    return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int A = 1e6 + 5;   const int N = 5e4 + 5;   const int M = 5005;   int dp[A], a[N], l[M], r[M], b[N], ans[M];   int32_t main() {     for (int i = 1; i < A; i++) dp[i] = dp[i - 1] ^ i;     int n, m;     cin >> n >> m;     for (int i = 1; i <= n; i++) scanf( %d , a + i);     for (int i = 0; i < m; i++) scanf( %d%d , l + i, r + i);     for (int i = 1; i <= n; i++) {       b[i - 1] = 0;       for (int j = i; j <= n; j++)         b[j] = max(b[j - 1], a[i] < a[j] ? dp[a[j]] ^ dp[a[i] - 1]                                          : dp[a[i]] ^ dp[a[j] - 1]);       for (int j = 0; j < m; j++)         if (l[j] <= i) ((ans[j]) = max((ans[j]), (b[r[j]])));     }     for (int i = 0; i < m; i++) printf( %d n , ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int x[n], y[n];     for (int i = 0; i < n; i++) cin >> x[i];     for (int i = 0; i < n; i++) cin >> y[i];     int de = 0, in = 0;     for (int i = 0; i < n; i++) {       if (x[i] > y[i]) de = de + x[i] - y[i];       if (y[i] > x[i]) in = in + y[i] - x[i];     }     if (de >= in)       cout <<  Yes ;     else       cout <<  No ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long cnt1, cnt2, x, y;     cin >> cnt1 >> cnt2 >> x >> y;     long long low = 1, high = 4000000000LL;     if (x == y) {       while (low < high) {         long long mid = low + (high - low) / 2;         if (mid - mid / x >= cnt1 + cnt2)           high = mid;         else           low = mid + 1;       }     } else {       while (low < high) {         long long mid = low + (high - low) / 2;         if (mid - mid / x >= cnt1 && mid - mid / y >= cnt2 &&             mid - mid / (x * y) >= cnt1 + cnt2)           high = mid;         else           low = mid + 1;       }     }     cout << low;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     long long a, b;     cin >> a >> b;     int maxa = sqrt(a);     int maxb = maxa * (maxa + 1);     if (b >= maxb)       cout <<  Vladik ;     else       cout <<  Valera ;   }


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


#include <bits/stdc++.h>   using namespace std;   map<pair<int, int>, pair<int, int> > tab;   int main() {     int n, v[3];     pair<int, int> ans;     int maior = 0;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d%d%d , &v[0], &v[1], &v[2]);       sort(v, v + 3);       for (int j = 0; j < 3; j++)         for (int k = j + 1; k < 3; k++) {           pair<int, int> x = tab[make_pair(v[j], v[k])];           int ind = 3 - j - k;           int aux[3] = {v[0], v[1], v[2]};           aux[ind] += x.first;           sort(aux, aux + 3);           if (aux[0] > maior) {             maior = aux[0];             ans.first = i;             ans.second = x.second;           }         }       if (tab[make_pair(v[0], v[1])].first < v[2])         tab[make_pair(v[0], v[1])] = make_pair(v[2], i);       if (tab[make_pair(v[0], v[2])].first < v[1])         tab[make_pair(v[0], v[2])] = make_pair(v[1], i);       if (tab[make_pair(v[1], v[2])].first < v[0])         tab[make_pair(v[1], v[2])] = make_pair(v[0], i);     }     if (ans.first > ans.second) swap(ans.first, ans.second);     if (ans.first)       printf( 2 n%d %d n , ans.first, ans.second);     else       printf( 1 n%d n , ans.second);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 7;   int a[N];   int main() {     int t;     cin >> t;     while (t--) {       int n, x;       cin >> n >> x;       int ok = 0;       for (int i = 1; i <= n; i++) {         cin >> a[i];         if (a[i] == x) {           ok = 1;         }       }       if (ok == 1) {         cout << 1 <<   n ;         continue;       }       sort(a + 1, a + 1 + n);       int b = a[n];       if (x < b) {         cout << 2 <<   n ;       } else if (x % b == 0) {         cout << x / b <<   n ;       } else {         cout << x / b + 1 <<   n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long a, b, c, i, j;     cin >> a >> b >> c;     long long s = min(a / 3, min(b / 2, c / 2));     a -= s * 3;     b -= s * 2;     c -= s * 2;     set<long long> sett;     for (i = 1; i <= 7; i++) {       long long cnt = 0;       long long x = a, y = b, z = c;       for (j = i; j < (i + 7); j++) {         if (j % 7 == 1 || j % 7 == 4 || j % 7 == 0) {           if (!x)             break;           else             x--;           cnt++;         } else if (j % 7 == 2 || j % 7 == 6) {           if (!y)             break;           else             y--;           cnt++;         } else if (j % 7 == 3 || j % 7 == 5) {           if (!z)             break;           else             z--;           cnt++;         }       }       sett.insert(cnt);     }     auto it = sett.end();     it--;     long long ans = *it + s * 7;     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   template <class t>   vector<t> sort(vector<t> &a) {     return sort(a.begin(), a.end());   }   const int N = 200200;   int a[N], b[N];   int main() {     ios_base::sync_with_stdio(false);     cin.tie();     int n, m;     cin >> n >> m;     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < m; i++) cin >> b[i];     reverse(a, a + n);     reverse(b, b + m);     a[n] = -1;     int pos = 0, mn = a[0];     while (pos < n && mn > b[0]) pos++, mn = min(mn, a[pos]);     if (pos == n || mn < b[0]) {       puts( 0 );       return 0;     }     assert(mn == b[0]);     long long res = 1;     for (int itr = 0; itr < m - 1; itr++) {       bool f = 1;       int npos = pos;       while (npos < n && mn != b[itr + 1]) {         npos++;         mn = min(mn, a[npos]);         if (f && mn < b[itr]) {           f = 0;           res = (res * (npos - pos)) % 998244353;         }       }       if (npos == n || mn != b[itr + 1]) {         puts( 0 );         return 0;       }       pos = npos;     }     if (*min_element(a + pos, a + n) != b[m - 1]) {       puts( 0 );       return 0;     }     cout << res <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   string str[110];   int rev[110];   bool counted[110];   stack<int> st;   queue<int> q;   int length;   bool isRev(string s, string t) {     for (int i = 0; i < m; i++)       if (s[i] != t[m - i - 1]) return false;     return true;   }   bool same(string s) {     char c = s[0];     for (int i = 1; i < m; i++)       if (c != s[i]) return false;     return true;   }   bool loneRev(string s) {     int i = 0, j = m - 1;     while (i <= j) {       if (s[i] != s[j]) return false;       i++;       j--;     }     return true;   }   int main() {     cin >> n >> m;     for (int i = 1; i <= n; i++) cin >> str[i];     for (int i = 1; i <= n; i++) {       if (!rev[i]) {         for (int j = i + 1; j <= n; j++) {           if (isRev(str[i], str[j])) {             rev[i] = j;             rev[j] = i;             break;           }         }       }     }     for (int i = 1; i <= n; i++) {       if (rev[i] && !counted[i]) {         counted[i] = true;         counted[rev[i]] = true;         q.push(i);         st.push(rev[i]);         length += (2 * m);       }     }     for (int i = 1; i <= n; i++) {       if (!counted[i]) {         if (same(str[i]) || loneRev(str[i])) {           length += m;           q.push(i);           break;         }       }     }     while (st.size()) {       int x = st.top();       st.pop();       q.push(x);     }     cout << length << endl;     while (q.size()) {       int x = q.front();       q.pop();       cout << str[x];     }   }


#include <bits/stdc++.h>   using namespace std;   vector<vector<int> > g;   vector<vector<int> > tims;   vector<int> part;   vector<int> conf;   int n;   int e;   int T = 0;   void build_part() {     bool ok = false;     while (!ok) {       for (int(i) = (1); (i) < (T + 1); ++(i)) {         part[i] = rand() % 2;       }       for (int(i) = 0; (i) < (n); ++(i)) {         ok = false;         int cnt[] = {0, 0};         for (int(j) = 0; (j) < (tims[i].size()); ++(j)) {           cnt[part[tims[i][j]]] = 1;           if (cnt[0] * cnt[1] == 1) {             ok = true;             break;           }         }         if (!ok) {           break;         }       }     }     for (int(i) = (1); (i) < (T + 1); ++(i)) {       ++part[i];     }   }   void build() {     conf[0] = 1;     for (int(i) = (1); (i) < (n); ++(i)) {       int d[] = {0, 0};       for (int(j) = 0; (j) < (g[i].size()); ++(j)) {         if (conf[g[i][j]] > 0) {           ++d[conf[g[i][j]] - 1];         }       }       if (d[0] > d[1]) {         conf[i] = 2;       } else         conf[i] = 1;     }   }   void solve() {     srand(22812323);     cin >> n >> e;     g.resize(n);     tims.resize(n);     conf.resize(n, 0);     for (int(i) = 0; (i) < (e); ++(i)) {       int a, b;       cin >> a >> b;       --a;       --b;       g[a].push_back(b);       g[b].push_back(a);     }     for (int(i) = 0; (i) < (n); ++(i)) {       int l;       cin >> l;       tims[i].resize(l);       for (int(j) = 0; (j) < (tims[i].size()); ++(j)) {         cin >> tims[i][j];         T = max(T, tims[i][j]);       }     }     part.resize(T + 1);     build_part();     build();     for (int(i) = 0; (i) < (n); ++(i)) {       for (int(j) = 0; (j) < (tims[i].size()); ++(j)) {         if (conf[i] == part[tims[i][j]]) {           cout << tims[i][j] <<    ;           break;         }       }     }     cout << endl;     for (int(i) = (1); (i) < (T + 1); ++(i)) {       cout << part[i] <<    ;     }   }   int main() {     ios_base::sync_with_stdio(false);     solve();     return 0;   }


#include <bits/stdc++.h>   int main(void) {     int stack[100000 + 1], sp = 0, c;     stack[0] =   0 ;     while (c = getchar(), c !=   n ) {       if (c == stack[sp])         --sp;       else         stack[++sp] = c;     }     printf( %s n , sp == 0 ?  Yes  :  No );     exit(EXIT_SUCCESS);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int n, m;     cin >> n >> m;     vector<vector<int> > A(n, vector<int>(m)), B(n, vector<int>(m));     for (int x = 0; x < n; x++)       for (int y = 0; y < m; y++) cin >> A[x][y];     for (int x = 0; x < n; x++)       for (int y = 0; y < m; y++) cin >> B[x][y];     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++)         if (A[i][j] < B[i][j]) swap(A[i][j], B[i][j]);     }     bool legal = true;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (i + 1 < n && A[i][j] >= A[i + 1][j]) legal = false;         if (j + 1 < m && A[i][j] >= A[i][j + 1]) legal = false;       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (i + 1 < n && B[i][j] >= B[i + 1][j]) legal = false;         if (j + 1 < m && B[i][j] >= B[i][j + 1]) legal = false;       }     }     if (legal)       cout <<  Possible n ;     else       cout <<  Impossible n ;   }


#include <bits/stdc++.h>   const int maxi = 2000000000;   const int maxq = 1000000000;   const double eps = 1e-10;   const double pi = 3.1415926535897932;   const double inf = 1e+18;   const int mo = 1000000007;   const int maxn = 500000;   using namespace std;   int n;   string s[555];   vector<char> v;   int le[555][555], color[5555], kol[5555];   void dfs(char ch) {     if (color[ch] == 1) {       puts( Impossible );       exit(0);     } else if (color[ch] == 2)       return;     color[ch] = 1;     for (char i =  a ; i <=  z ; i++)       if (le[ch][i]) {         dfs(i);       }     v.push_back(ch);     color[ch] = 2;   }   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       cin >> s[i];     }     for (int i = 0; i < n; i++) {       for (int j = i + 1; j < n; j++) {         bool ok = false;         for (int k = 0; k < min(s[i].size(), s[j].size()); k++)           if (s[i][k] != s[j][k]) {             le[s[i][k]][s[j][k]] = 1;             kol[s[j][k]]++;             ok = true;             break;           }         if (ok == false && s[j].size() < s[i].size()) {           puts( Impossible );           return 0;         }       }     }     for (char ch =  a ; ch <=  z ; ch++)       if (color[ch] == 0 && kol[ch] == 0) dfs(ch);     reverse(v.begin(), v.end());     if (v.size() < 26) {       puts( Impossible );       return 0;     }     for (int i = 0; i < v.size(); i++) cout << v[i];     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct Vec2 {     int x, y;     bool left, right, top, bottom;     Vec2() : x(0), y(0), left(false), right(false), top(false), bottom(false) {}   };   int main() {     int n;     Vec2 points[200];     int ans = 0;     cin >> n;     for (int i = 0; i < n; ++i) cin >> points[i].x >> points[i].y;     for (int i = 0; i < n; ++i)       for (int j = 0; j < n; ++j) {         if (points[i].x > points[j].x && points[i].y == points[j].y)           points[j].right = true;         if (points[i].x < points[j].x && points[i].y == points[j].y)           points[j].left = true;         if (points[i].y < points[j].y && points[i].x == points[j].x)           points[j].bottom = true;         if (points[i].y > points[j].y && points[i].x == points[j].x)           points[j].top = true;       }     for (int i = 0; i < n; ++i)       if (points[i].left && points[i].right && points[i].top && points[i].bottom)         ans += 1;     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long t;     cin >> t;     while (t--) {       long long n, x, y;       cin >> n >> x >> y;       long long val;       for (int i = n - 1; i >= 1; i--) {         if (abs(y - x) % i == 0) {           val = (y - x) / i;           break;         }       }       vector<int> v;       for (int i = x; i <= y; i += val) {         v.push_back(i);       }       if (v.size() == n) {         for (int i = 0; i < v.size(); i++) cout << v[i] <<    ;         cout <<   n ;       } else {         long long m = n - v.size();         while (m--) {           if ((v[0] - val) > 0)             v.insert(v.begin(), v[0] - val);           else             v.push_back(v[v.size() - 1] + val);         }         for (int i = 0; i < v.size(); i++) cout << v[i] <<    ;         cout <<   n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-9;   int v[1024];   int vv[1024];   int N;   int try_it(int last) {     for (int i = (0); i < (N); i++) vv[i] = v[i];     for (int i = (last); i < (N); i++) vv[i] = max(0, vv[i] - 1);     vv[N] = 0;     int NN = N;     while (NN > 0 && vv[NN - 1] == 0) --NN;     int moves = 0, p = -1;     while (vv[NN - 1] > 0) {       moves += 3;       ++p;       while (vv[p + 1] >= vv[p]) {         moves += 2;         ++p;       }       ++moves;       --vv[p];       --p;       while (p >= 0 && vv[p] == vv[p + 1] + 1) {         --vv[p];         --p;         moves++;       }       moves++;     }     return moves + N * 3 - 2 * p - last;   }   void do_it(int last) {     for (int i = (0); i < (N); i++) vv[i] = v[i];     for (int i = (last); i < (N); i++) vv[i] = max(0, vv[i] - 1);     vv[N] = 0;     int NN = N;     while (NN > 0 && vv[NN - 1] == 0) --NN;     int p = -1;     while (vv[NN - 1] > 0) {       cout <<  ARA ;       ++p;       while (vv[p + 1] >= vv[p]) {         cout <<  RA ;         ++p;       }       cout <<  L ;       --vv[p];       --p;       while (p >= 0 && vv[p] == vv[p + 1] + 1) {         --vv[p];         --p;         cout <<  L ;       }       cout <<  A ;     }     while (p++ < N - 1) cout <<  AR ;     cout <<  A ;     while (p-- > last) cout <<  L ;     cout <<  A n ;   }   int main() {     ios::sync_with_stdio(false);     cin >> N;     for (int i = (0); i < (N); i++) cin >> v[i];     v[N] = 0;     while (N > 0 && v[N - 1] == 0) --N;     int best = try_it(0);     int last = 0;     for (int i = (1); i < (N); i++) {       int c = try_it(i);       if (c < best) {         best = c;         last = i;       }     }     do_it(last);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int t = 1;     cin >> t;     while (t--) {       long long int i, j, k, n, m = 1e10, f = 1;       cin >> n;       vector<long long int> a(n), b(n), in, val;       for (i = 0; i < n; i++) {         cin >> a[i], b[i] = a[i];         m = min(a[i], m);       }       sort(b.begin(), b.end());       for (i = 0; i < n; i++)         if (a[i] % m == 0) in.emplace_back(i), val.emplace_back(a[i]);       sort(val.begin(), val.end());       for (i = 0; i < in.size(); i++) a[in[i]] = val[i];       for (i = 0; i < n; i++)         if (a[i] != b[i]) {           f = 0;           break;         }       if (f)         cout <<  YES n ;       else         cout <<  NO n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 1e9;   const int maxn = 5555;   int s[maxn];   int main(int argc, char const *argv[]) {     ios::sync_with_stdio(false);     cin.tie(0);     int n;     cin >> n;     for (int i = 1; i <= n; ++i) {       int t;       cin >> t;       s[i] = s[i - 1] + t;     }     int res = 0;     for (int i = 1; i <= n; ++i) {       for (int j = i; j <= n; ++j) {         int sum = s[j] - s[i - 1];         int t = j - i + 1;         if (sum > t * 100 && t > res) res = t;       }     }     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a, b, c[101], d, e, f, g;   int main() {     cin >> a >> b;     for (; d < a; d++) {       cin >> e;       c[e]++;       f = max(f, c[e]);       if (c[e] == 1) {         g++;       }     }     f = (f % b) ? (f / b + 1) * b : f;     cout << f * g - a;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct edge {     long long a, b, w, ind;   };   const int LEN = 100100;   const long long INF = 100000000000000;   int n, m, s, t, use[LEN], use1[LEN], ans[LEN], timer, tin[LEN], fup[LEN];   vector<edge> ar[LEN], ar1[LEN], ar2[LEN];   edge ed[LEN];   long long dist[LEN], dist1[LEN], min_dist, a, b, l;   set<pair<long long, int> > q;   void deixtra(long long (&dist)[LEN], vector<edge> (&ar)[LEN], int s);   void get_gate(int v, int ind);   int main() {     scanf( %i %i %i %i , &n, &m, &s, &t);     s--;     t--;     for (int i = 0; i < m; i++) {       scanf( %I64d %I64d %I64d , &a, &b, &l);       ed[i].w = l;       ed[i].ind = i;       ed[i].a = b - 1;       ed[i].b = a - 1;       ar1[b - 1].push_back(ed[i]);       swap(ed[i].a, ed[i].b);       ar[a - 1].push_back(ed[i]);     }     deixtra(dist, ar, s);     deixtra(dist1, ar1, t);     min_dist = dist[t];     for (int i = 0; i < m; i++)       if (dist[ed[i].a] + ed[i].w + dist1[ed[i].b] == min_dist) {         ar2[ed[i].a].push_back(ed[i]);         swap(ed[i].a, ed[i].b);         ar2[ed[i].a].push_back(ed[i]);         swap(ed[i].a, ed[i].b);       }     get_gate(t, -1);     for (int i = 0; i < m; i++)       if (ans[i])         printf( YES n );       else if (dist[ed[i].a] + ed[i].w + dist1[ed[i].b] - min_dist + 1 < ed[i].w)         printf( CAN %I64d n ,                dist[ed[i].a] + ed[i].w + dist1[ed[i].b] - min_dist + 1);       else         printf( NO n );     return 0;   }   void deixtra(long long (&dist)[LEN], vector<edge> (&ar)[LEN], int s) {     int x, to, len;     pair<long long, int> u;     for (int i = 0; i < n; i++) dist[i] = INF;     dist[s] = 0;     q.insert(make_pair(0, s));     while (!q.empty()) {       x = q.begin()->second;       q.erase(q.begin());       for (int i = 0; i < ar[x].size(); i++) {         to = ar[x][i].b;         len = ar[x][i].w;         if (dist[to] > dist[x] + len) {           q.erase(make_pair(dist[to], to));           dist[to] = dist[x] + len;           q.insert(make_pair(dist[to], to));         }       }     }   }   void get_gate(int v, int ind) {     int u;     tin[v] = fup[v] = timer++;     use1[v] = 1;     for (int i = 0; i < ar2[v].size(); i++) {       if (ar2[v][i].ind == ind) continue;       u = ar2[v][i].b;       if (use1[u])         fup[v] = min(fup[v], tin[u]);       else {         get_gate(u, ar2[v][i].ind);         fup[v] = min(fup[v], fup[u]);         if (fup[u] > tin[v]) ans[ar2[v][i].ind] = 1;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 1e9;   const long long INF = 1e18;   const int md = 1e9 + 7;   const int N = 2e5 + 1;   vector<int> g[N];   int p[N], s[N], mx[N], mn[N];   bool did[N];   void make(int v) { p[v] = v, s[v] = 1, mx[v] = v, mn[v] = v; }   int fin(int v) {     if (p[v] == v) return v;     return p[v] = fin(p[v]);   }   void un(int a, int b) {     a = fin(a);     b = fin(b);     if (a == b) return;     if (s[a] < s[b]) swap(a, b);     s[a] += s[b], mx[a] = max(mx[a], mx[b]);     p[b] = a;     mn[a] = min(mn[a], mn[b]);   }   signed main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     int n, m;     cin >> n >> m;     for (int f = 0; f < n; ++f) make(f);     for (int j = 0; j < m; ++j) {       int u, v;       cin >> u >> v;       --u, --v;       un(u, v);     }     int curr = 0;     int ans = 0;     int may;     bool isn = 0;     while (curr < n) {       if (mx[fin(curr)] - mn[fin(curr)] + 1 == s[fin(curr)]) {         int lead = fin(curr);         while (curr < n && fin(curr) == lead) {           curr++;         }         isn = 1;       } else {         int lead = fin(curr);         if (isn) may = curr;         isn = 0;         while (may < n && fin(may) == lead) {           may++;         }         un(may, curr);         ans++;       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, nxt[402][26];   string s, t;   int dp[401][401];   bool solve2(string t1, string t2) {     dp[0][0] = -1;     for (int i = 0; i <= t1.size(); ++i) {       for (int j = 0; j <= t2.size(); ++j) {         if (!i && !j) continue;         dp[i][j] = n;         if (i) dp[i][j] = min(dp[i][j], nxt[dp[i - 1][j] + 1][t1[i - 1] -  a ]);         if (j) dp[i][j] = min(dp[i][j], nxt[dp[i][j - 1] + 1][t2[j - 1] -  a ]);       }     }     return dp[t1.size()][t2.size()] < n;   }   void solve() {     cin >> s >> t;     n = s.size();     m = t.size();     for (int i = 0; i < 26; ++i) nxt[n][i] = nxt[n + 1][i] = n;     for (int i = n - 1; ~i; --i) {       memcpy(nxt[i], nxt[i + 1], sizeof(nxt[0]));       nxt[i][s[i] -  a ] = i;     }     for (int i = 0; i < m; ++i)       if (solve2(t.substr(0, i), t.substr(i))) {         cout <<  YES n ;         return;       }     cout <<  NO n ;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int t;     cin >> t;     while (t--) solve();   }


#include <bits/stdc++.h>   using namespace std;   const long long inf = 1000000000ll;   const long long inf64 = inf * inf;   const long long base = inf + 7;   const double pi = acos(-1.0);   long long Abs(long long x) { return (x >= 0 ? x : -x); }   int n;   string s;   int par[62 * 62], size[62 * 62], in[62 * 62], out[62 * 62];   vector<int> ans, g[62 * 62];   vector<bool> used;   int _get(char c) {     if (c >=  0  && c <=  9 )       return (c -  0 );     else if (c >=  a  && c <=  z )       return (c -  a  + 10);     else       return (c -  A  + 36);   }   int get(string a) {     int x, y;     x = _get(a[0]);     y = _get(a[1]);     return x * 62 + y;   }   int find(int x) { return (par[x] == x ? x : par[x] = find(par[x])); }   void un(int a, int b) {     int pa = find(a);     int pb = find(b);     if (size[pa] == size[pb])       par[pa] = pb, size[pb]++;     else {       if (size[pa] > size[pb]) swap(pa, pb);       par[pa] = pb;     }   }   char chr(int x) {     if (x < 10)       return char(x +  0 );     else if (x < 36)       return char(x +  a  - 10);     else       return char(x +  A  - 36);   }   void dfs(int v) {     while (!g[v].empty()) {       int x = g[v].back();       g[v].pop_back();       dfs(x);     }     ans.push_back(v);   }   bool solve() {     for (int i(0); i < 62 * 62; i++) size[i] = 1, par[i] = i;     cin >> n;     used.assign(62 * 62, 0);     int Q = -1;     for (int i(0); i < n; i++) {       int x, y;       cin >> s;       x = get(s.substr(0, 2));       if (Q == -1) Q = x;       y = get(s.substr(1, 2));       used[x] = used[y] = 1;       g[x].push_back(y);       in[y]++;       out[x]++;       un(x, y);     }     bool f = 0;     for (int i(0); i < 62 * 62; i++) {       if (!used[i]) continue;       if (par[i] != i) continue;       if (f) {         puts( NO );         return true;         ;       } else         f = 1;     }     int x1, x2;     x1 = x2 = -1;     for (int i(0); i < 62 * 62; i++) {       if (in[i] == out[i]) continue;       if (in[i] - out[i] == 1) {         if (x1 != -1) {           puts( NO );           return true;           ;         }         x1 = i;       } else if (in[i] - out[i] == -1) {         if (x2 != -1) {           puts( NO );           return true;           ;         }         x2 = i;       } else {         puts( NO );         return true;         ;       }     }     if (x1 == -1 && x2 != -1 || x1 != -1 && x2 == -1) {       puts( NO );       return true;       ;     }     used.assign(62 * 62, 0);     dfs(x2 != -1 ? x2 : Q);     reverse((ans).begin(), (ans).end());     puts( YES );     int x, y;     x = ans[0] / 62;     cout << chr(x);     for (int i(0); i < (int)ans.size(); i++) {       x = ans[i] % 62;       cout << chr(x);     }     return true;   }   int main() {     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     char alfabetGainuse[] =          -abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPRQSTUVWXYZ0123456789 ;     int T;     cin >> T;     for (int t = 1; t <= T; t++) {       int r, c, k;       cin >> r >> c >> k;       char harta[r + 1][c + 1];       cin.get();       for (int i = 1; i <= r; i++) {         cin.get(harta[i], c + 1);         cin.get();       }       int mancare = 0;       for (int i = 1; i <= r; i++) {         for (int j = 0; j < c; j++) {           if (harta[i][j] ==  R ) mancare++;         }       }       int mancareGainuse[k + 1];       for (int i = 1; i <= k; i++) {         mancareGainuse[i] = mancare / k;       }       for (int i = 1; i <= mancare % k; i++) {         mancareGainuse[i]++;       }       char hartaNoua[r + 1][c + 2];       int indexGaina = 1;       int mancareGasita = 0;       for (int i = 1; i <= r; i++) {         hartaNoua[i][c] =   0 ;         if (i % 2 == 1) {           for (int j = 0; j < c; j++) {             if (indexGaina == k + 1) {               hartaNoua[i][j] = alfabetGainuse[indexGaina - 1];             } else {               hartaNoua[i][j] = alfabetGainuse[indexGaina];               if (harta[i][j] ==  R ) {                 mancareGasita++;                 if (mancareGasita == mancareGainuse[indexGaina]) {                   indexGaina++;                   mancareGasita = 0;                 }               }             }           }         } else {           for (int j = c - 1; j >= 0; j--) {             if (indexGaina == k + 1) {               hartaNoua[i][j] = alfabetGainuse[indexGaina - 1];             } else {               hartaNoua[i][j] = alfabetGainuse[indexGaina];               if (harta[i][j] ==  R ) {                 mancareGasita++;                 if (mancareGasita == mancareGainuse[indexGaina]) {                   indexGaina++;                   mancareGasita = 0;                 }               }             }           }         }       }       for (int i = 1; i <= r; i++) {         cout << hartaNoua[i] <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<long long> temp(3001, 0);   vector<vector<long long> > dp(3001, temp);   void solve() {     long long n;     cin >> n;     vector<long long> v(n);     long long i, j, k, l;     for (i = 0; i < n; i++) cin >> v[i];     for (i = 0; i < 3001; i++) {       for (j = 0; j < 3001; j++) dp[i][j] = 0;     }     for (i = 0; i < n; i++) {       dp[v[i]][i] = dp[v[i]][i] + 1;       if (i == 0) continue;       for (j = 0; j < 3001; j++) dp[j][i] += dp[j][i - 1];     }     long long ans = 0;     for (i = 0; i < n; i++) {       for (j = i + 1; j < n; j++) {         long long a = v[i];         long long b = v[j];         if (a == b) continue;         if (dp[b][i] > 0 && dp[a][j] < dp[a][n - 1]) {           long long val1 = dp[b][i];           long long val2 = dp[a][n - 1] - dp[a][j];           ans = ans + val1 * val2;         }       }     }     for (i = 0; i <= 3000; i++) {       if (dp[i][n - 1] >= 4) {         long long val = 1;         long long count = dp[i][n - 1];         val = val * count;         count--;         val = val * count;         val = val / 2LL;         count--;         val = val * count;         val = val / 3LL;         count--;         val = val * count;         val = val / 4LL;         ans = ans + val;       }     }     cout << ans << endl;   }   int main() {     int t = 1;     cin >> t;     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k, max = 0, count = 0;     cin >> n >> k;     vector<int> v(n);     for (int i = 0; i < n; i++) {       cin >> v[i];       if (v[i - 1] != v[i])         count++;       else if (count > max) {         max = count;         count = 1;       } else         count = 1;     }     if (max < count) max = count;     cout << max;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mx = 1e5 + 1;   bool vis[mx];   vector<int> adj[mx];   int n;   bool star() {     bool ans;     int count1 = 0;     int other = 0;     for (int i = 1; i <= n; i++) {       if (adj[i].size() == 1) {         count1++;       } else if (adj[i].size() == n - 1) {         other++;       }     }     if (other == 1 && count1 == n - 1) {       ans = true;     } else {       ans = false;     }     return ans;   }   bool ring() {     bool ans = true;     for (int i = 1; i <= n; i++) {       if (adj[i].size() != 2) {         ans = false;         break;       }     }     return ans;   }   bool bus() {     bool ans;     int one = 0;     int two = 0;     for (int i = 1; i <= n; i++) {       if (adj[i].size() == 1) {         one++;       } else if (adj[i].size() == 2) {         two++;       }     }     if (one == 2 && two == n - 2) {       ans = true;     } else {       ans = false;     }     return ans;   }   int main() {     int m, k, u, v;     cin >> n >> m;     for (int i = 0; i < m; i++) {       cin >> u >> v;       adj[u].push_back(v);       adj[v].push_back(u);     }     if (star()) {       cout <<  star topology  << endl;     } else if (bus()) {       cout <<  bus topology  << endl;     } else if (ring()) {       cout <<  ring topology  << endl;     } else {       cout <<  unknown topology  << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   long long a[2000005];   long long sum[2000005];   int main() {     long long m, n, i, j, k, ans = 0;     cin >> m;     for (i = 1; i <= m; i++) scanf( %lld , &a[i]);     sort(a + 1, a + 1 + m);     for (i = m; i >= 1; i--) sum[i] = sum[i + 1] + a[i];     for (i = 1; i <= m; i *= 4) {       ans += sum[m - i + 1];     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9 + 1;   const int N = 5003;   vector<int> adj[N];   vector<pair<int, int> > stores[N];   bool done[N];   int dist[N];   void clear(int n) {     for (int i = 1; i <= n; ++i) done[i] = 0;   }   void modify(multiset<pair<int, int> >& tiendas, const int& to,               long long& rpta) {     for (pair<int, int> p : stores[to]) {       auto it = tiendas.rbegin();       pair<int, int> q = *it;       int left = p.second;       while (!tiendas.empty() && q.first > p.first) {         if (q.second >= left) {           tiendas.erase(tiendas.find(q));           rpta -= ((long long)q.first * q.second);           if (q.second != left) {             tiendas.insert({q.first, q.second - left});             rpta += ((long long)q.first * (q.second - left));           }           left = 0;           break;         } else {           tiendas.erase(tiendas.find(q));           left -= q.second;           rpta -= ((long long)q.first * q.second);         }         if (!tiendas.empty()) {           it = tiendas.rbegin();           q = *it;         }       }       if (p.second != left) {         tiendas.insert({p.first, p.second - left});         rpta += ((long long)p.first * (p.second - left));       }     }     return;   }   int bfs(int source, int prod, long long price) {     multiset<pair<int, int> > tiendas;     tiendas.insert({INF, prod});     long long rpta = (long long)INF * prod;     queue<int> Q;     Q.push(source);     dist[source] = 0;     done[source] = 1;     modify(tiendas, source, rpta);     if (rpta <= price) return dist[source];     while (!Q.empty()) {       int from = Q.front();       Q.pop();       for (int to : adj[from]) {         if (done[to]) continue;         dist[to] = dist[from] + 1;         done[to] = 1;         Q.push(to);         modify(tiendas, to, rpta);         if (rpta <= price) return dist[to];       }     }     return -1;   }   void solve() {     int n, m;     cin >> n >> m;     for (int i = 0; i < m; ++i) {       int u, v;       cin >> u >> v;       adj[u].push_back(v);       adj[v].push_back(u);     }     int w;     cin >> w;     for (int i = 0; i < w; ++i) {       int c, k, p;       cin >> c >> k >> p;       stores[c].push_back({p, k});     }     int q;     cin >> q;     for (int i = 0; i < q; ++i) {       clear(n);       int g, r, a;       cin >> g >> r >> a;       cout << bfs(g, r, a) <<   n ;     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(nullptr);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 220;   bool vis[maxn];   vector<int> G[maxn];   int ans;   int dfs(int v, int x) {     int sum = 0;     int max1 = 0, max2 = 0;     for (int i = 0; i < G[v].size(); i++) {       if (G[v][i] != x) {         sum = max(sum, dfs(G[v][i], v));         if (ans > max1) {           max2 = max1;           max1 = ans;         } else           max2 = ans > max2 ? ans : max2;       }     }     sum = max(sum, max1 + max2);     ans = max1 + 1;     return sum;   }   int main() {     int n, a, b;     while (scanf( %d , &n) != EOF) {       for (int i = 0; i <= n; i++) G[i].clear();       for (int i = 0; i < n - 1; i++) {         scanf( %d%d , &a, &b);         G[a].push_back(b);         G[b].push_back(a);       }       int last_ans = 0;       for (int i = 0; i < n; i++) {         int num = G[i].size(), temp;         for (int j = 0; j < num; j++) {           int ans = 0;           temp = dfs(i, G[i][j]) * dfs(G[i][j], i);           last_ans = max(last_ans, temp);         }       }       printf( %d n , last_ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int d1, d2, d3, i;     cin >> d1 >> d2 >> d3;     int k[4] = {(d1 + d2 + d3), (2 * d1 + 2 * d2), (2 * d2 + 2 * d3),                 (2 * d1 + 2 * d3)};     int min = 1e9;     for (i = 0; i < 4; i++) {       if (k[i] < min) min = k[i];     }     cout << min;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   T in() {     char ch;     T n = 0;     bool ng = false;     while (1) {       ch = getchar();       if (ch ==  - ) {         ng = true;         ch = getchar();         break;       }       if (ch >=  0  && ch <=  9 ) break;     }     while (1) {       n = n * 10 + (ch -  0 );       ch = getchar();       if (ch <  0  || ch >  9 ) break;     }     return (ng ? -n : n);   }   template <typename T>   inline T Dis(T x1, T y1, T x2, T y2) {     return sqrt((x1 - x2 * x1 - x2) + (y1 - y2 * y1 - y2));   }   template <typename T>   inline T POW(T B, T P) {     if (P == 0) return 1;     if (P & 1)       return B * POW(B, P - 1);     else       return (POW(B, P / 2) * POW(B, P / 2));   }   template <typename T>   inline T ABS(T a) {     if (a < 0)       return -a;     else       return a;   }   template <typename T>   inline T Gcd(T a, T b) {     if (a < 0) return Gcd(-a, b);     if (b < 0) return Gcd(a, -b);     return (b == 0) ? a : Gcd(b, a % b);   }   template <typename T>   inline T Lcm(T a, T b) {     if (a < 0) return Lcm(-a, b);     if (b < 0) return Lcm(a, -b);     return a * (b / Gcd(a, b));   }   long long Bigmod(long long base, long long power, long long MOD) {     long long ret = 1;     while (power) {       if (power & 1) ret = (ret * base) % MOD;       base = (base * base) % MOD;       power >>= 1;     }     return ret;   }   long long ModInverse(long long number, long long MOD) {     return Bigmod(number, MOD - 2, MOD);   }   int Set(int N, int pos) { return N = N | (1 << pos); }   int Reset(int N, int pos) { return N = N & ~(1 << pos); }   bool Chkbit(int N, int pos) { return (bool)(N & (1 << pos)); }   bool isVowel(char ch) {     ch = toupper(ch);     if (ch ==  A  || ch ==  U  || ch ==  I  || ch ==  O  || ch ==  E )       return true;     return false;   }   bool isConst(char ch) {     if (isalpha(ch) && !isVowel(ch)) return true;     return false;   }   int toInt(string s) {     int sm;     stringstream ss(s);     ss >> sm;     return sm;   }   long long int toLlint(string s) {     long long int sm;     stringstream ss(s);     ss >> sm;     return sm;   }   const int N = int(2e6) + 15;   int cmp(int *r, int a, int b, int l) {     return (r[a] == r[b]) && (r[a + l] == r[b + l]);   }   int wa[N], wb[N], wws[N], wv[N];   int rnk[N], height[N];   void DA(int *r, int *sa, int n, int m) {     int i, j, p, *x = wa, *y = wb, *t;     for (i = 0; i < m; i++) wws[i] = 0;     for (i = 0; i < n; i++) wws[x[i] = r[i]]++;     for (i = 1; i < m; i++) wws[i] += wws[i - 1];     for (i = n - 1; i >= 0; i--) sa[--wws[x[i]]] = i;     for (j = 1, p = 1; p < n; j *= 2, m = p) {       for (p = 0, i = n - j; i < n; i++) y[p++] = i;       for (i = 0; i < n; i++)         if (sa[i] >= j) y[p++] = sa[i] - j;       for (i = 0; i < n; i++) wv[i] = x[y[i]];       for (i = 0; i < m; i++) wws[i] = 0;       for (i = 0; i < n; i++) wws[wv[i]]++;       for (i = 1; i < m; i++) wws[i] += wws[i - 1];       for (i = n - 1; i >= 0; i--) sa[--wws[wv[i]]] = y[i];       for (t = x, x = y, y = t, p = 1, x[sa[0]] = 0, i = 1; i < n; i++)         x[sa[i]] = cmp(y, sa[i - 1], sa[i], j) ? p - 1 : p++;     }   }   void calheight(int *r, int *sa, int n) {     int i, j, k = 0;     for (i = 1; i <= n; i++) rnk[sa[i]] = i;     for (i = 0; i < n; height[rnk[i++]] = k)       for (k ? k-- : 0, j = sa[rnk[i] - 1]; r[i + k] == r[j + k]; k++)         ;   }   int sa[N], data[N], n;   void Deal() {     DA(data, sa, n + 1, 128);     calheight(data, sa, n);   }   char s[2000002];   int Len;   struct z {     int opn, cls;   };   z Tree[2000002 * 4];   void Update(int id, int l, int r, int pos) {     if (l == r) {       if (s[pos] ==  ( ) {         Tree[id].opn = 1;       } else         Tree[id].cls = 1;       return;     }     int mid = (l + r) / 2;     int lft = 2 * id;     int rgt = lft + 1;     if (pos <= mid) {       Update(lft, l, mid, pos);     } else {       Update(rgt, mid + 1, r, pos);     }     int mn = min(Tree[lft].opn, Tree[rgt].cls);     Tree[id].cls = Tree[lft].cls + Tree[rgt].cls - mn;     Tree[id].opn = Tree[rgt].opn + Tree[lft].opn - mn;     return;   }   z Query(int id, int l, int r, int st, int ed) {     if (st <= l && ed >= r) {       return Tree[id];     }     int mid = (l + r) / 2;     int lft = 2 * id;     int rgt = lft + 1;     if (ed <= mid) {       return Query(lft, l, mid, st, ed);     } else if (st > mid) {       return Query(rgt, mid + 1, r, st, ed);     } else {       z a, b, c;       a = Query(lft, l, mid, st, ed);       b = Query(rgt, mid + 1, r, st, ed);       int mn = min(a.opn, b.cls);       c.cls = a.cls + b.cls - mn;       c.opn = b.opn + a.opn - mn;       return c;     }   }   int dp[2000002], Close[2000002], len, dp1[2000002];   void Solve() {     int Last = -1, Last1 = -1;     for (int i = Len + 1 - 1; i >= 1; i--) {       if (s[i] ==  ) )         Last = -1;       else if (Last == -1) {         Last = i;       }       dp[i] = (Last == -1 ? 0 : (Last - i + 1));       if (s[i] ==  ( )         Last1 = -1;       else if (Last1 == -1) {         Last1 = i;       }       dp1[i] = (Last1 == -1 ? 0 : (Last1 - i + 1));     }   }   int A[4 * 2000002];   void Update(int id, int l, int r, int pos, int val) {     if (l == r) {       A[id] = height[pos];       return;     }     int mid = (l + r) / 2;     int lft = 2 * id;     int rgt = lft + 1;     if (pos <= mid) {       Update(lft, l, mid, pos, val);     } else {       Update(rgt, mid + 1, r, pos, val);     }     A[id] = min(A[lft], A[rgt]);     return;   }   int Lcp(int id, int l, int r, int st, int ed) {     if (st <= l && ed >= r) {       return A[id];     }     int mid = (l + r) / 2;     int lft = 2 * id;     int rgt = lft + 1;     if (ed <= mid) {       return Lcp(lft, l, mid, st, ed);     } else if (st > mid) {       return Lcp(rgt, mid + 1, r, st, ed);     } else {       int a, b;       a = Lcp(lft, l, mid, st, ed);       b = Lcp(rgt, mid + 1, r, st, ed);       return min(a, b);     }   }   int HandleJhamela(int id, int id1, int Opn, int mx) {     int Suru = id + min(len, dp[id]), Suru1 = id1 + min(len, dp[id1]);     int Rnk = rnk[Suru - 1], Rnk1 = rnk[Suru1 - 1];     int L1 = len + mx - Opn - Close[id], L2 = len + mx - Opn - Close[id1];     int f = 0;     if (Rnk > Rnk1) swap(Rnk, Rnk1), f = 1;     int lcp = Lcp(1, 1, n, Rnk + 1, Rnk1);     if (f) swap(Rnk, Rnk1);     if (lcp >= min(L1, L2)) {       int diff = abs(L2 - L1);       if (L1 < L2) {         if (dp1[id1 + min(len, dp[id1]) + lcp] < diff)           return id1;         else           return id;       } else {         if (dp1[id + min(len, dp[id]) + lcp] < diff)           return id;         else           return id1;       }     } else {       if (Rnk < Rnk1)         return id;       else         return id1;     }   }   int main() {     n = 0;     scanf( %s , &s);     len = strlen(s);     for (int i = len + 1 - 1; i >= 1; i--) s[i] = s[i - 1];     Len = len * 2;     for (int i = len + 1; i < Len + 1; i++) s[i] = s[i - len];     Solve();     for (int i = 1; i < Len + 1; i++) {       Update(1, 1, Len, i);       data[n] = (int)s[i];       n++;     }     data[n] = 0;     Deal();     for (int i = 1; i < n; i++) Update(1, 1, n, i, height[i]);     int mx = (1 << 28), Open = 0, Id = 0;     for (int i = 1; i < len + 1; i++) {       z ans = Query(1, 1, Len, i, (i + len - 1));       int Cst = ans.cls + ans.opn;       Close[i] = ans.opn;       int CntOpn = ans.cls + (min(len, dp[i]));       if (mx > Cst) {         mx = Cst;         Open = CntOpn;         Id = i;       } else if (mx == Cst && CntOpn > Open) {         Open = CntOpn;         Id = i;       } else if (mx == Cst && CntOpn == Open) {         Id = HandleJhamela(Id, i, CntOpn, mx);       }     }     for (int i = 0; i < Open; i++) {       printf( ( );     }     int baki = len + mx - Open - Close[Id];     int St = Id + dp[Id];     for (int i = 0; i < baki; i++) {       printf( %c , s[St + i]);     }     for (int i = 0; i < Close[Id]; i++) {       printf( ) );     }     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-9;   const double pi = acos(-1.0);   const int inf = 0x3f3f3f3f;   const int N = 100010;   int n, q;   int a[N], b[N], c[N];   struct node {     int low, high;     vector<pair<int, int> > v;   } tree[N << 2];   void build(int p, int low, int high, int c[]) {     tree[p].low = low;     tree[p].high = high;     tree[p].v.clear();     for (int k = low; k <= high; ++k) {       int i = c[k];       vector<pair<int, int> >& v = tree[p].v;       while (!v.empty()) {         int j = v.back().second;         if (b[j] >= b[i]) break;         int t = (a[j] - a[i]) / (b[i] - b[j]) + 1;         if (v.back().first >= t)           v.pop_back();         else {           v.push_back(make_pair(t, i));           break;         }       }       if (v.empty()) v.push_back(make_pair(0, i));     }     if (low == high) return;     int mid = (low + high) >> 1;     stable_partition(c + low, c + high + 1, bind2nd(less<int>(), mid + 1));     build(p * 2 + 1, low, mid, c);     build(p * 2 + 2, mid + 1, high, c);   }   pair<long long, int> query(int p, int low, int high, int t) {     node& cur = tree[p];     if (low <= cur.low && cur.high <= high) {       int id = lower_bound(cur.v.begin(), cur.v.end(), make_pair(t, inf)) -                cur.v.begin();       id = cur.v[id - 1].second;       return make_pair(a[id] + (long long)t * b[id], id);     }     pair<long long, int> ans = make_pair(0, 0);     int mid = (cur.low + cur.high) >> 1;     if (low <= mid) ans = max(ans, query(p * 2 + 1, low, high, t));     if (mid < high) ans = max(ans, query(p * 2 + 2, low, high, t));     return ans;   }   bool cmp(int i, int j) {     if (a[i] != a[j]) return a[i] > a[j];     return b[i] < b[j];   }   void solve() {     for (int i = 0; i < (int)(n); ++i) scanf( %d%d , a + i, b + i);     for (int i = 0; i < (int)(n); ++i) c[i] = i;     sort(c, c + n, cmp);     build(0, 0, n - 1, c);     int l, r, t;     for (int i = 0; i < (int)(q); ++i) {       scanf( %d%d%d , &l, &r, &t);       printf( %d n , query(0, l - 1, r - 1, t).second + 1);     }   }   int main() {     while (scanf( %d%d , &n, &q) != EOF) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long a, b;   map<long long, bool> mp;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     for (long long i = 1; i <= 1000; i++) mp[i * i] = 1;     cin >> a >> b;     for (long long i = -1; i > -a; i--) {       if (mp[a * a - i * i] == 0) continue;       long long j = sqrt(a * a - i * i);       for (long long x = 1; x < b; x++) {         if (mp[b * b - x * x] == 0) continue;         long long y = sqrt(b * b - x * x);         if (-i * x == j * y && j != y) {           cout <<  YES n ;           cout << 0 <<     << 0 << endl;           cout << i <<     << j << endl;           cout << x <<     << y;           return 0;         }       }     }     cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   int main() {     int a, b, c, d;     scanf( %d%d%d%d , &a, &b, &c, &d);     a > b ? printf( First ) : printf( Second );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int Nmax = 1e6 + 7;   int n;   string s;   int dp[Nmax];   vector<int> v;   int ans, ans1, ans2;   inline int get(string s) {     int cnt = 0;     int mx = 4 * n;     ans = 0;     for (int i = 0; i < n; i++) {       if (s[i] ==  ) )         cnt--;       else         cnt++;       if (cnt < mx) {         mx = cnt;         ans = i;       }     }     int pos = ans;     if (cnt != 0) return 0;     s = s + s;     dp[0] = 0;     ans = 0;     ans1 = 1, ans2 = 1;     for (int i = pos + 1, j = 0; j < n; j++, i++) {       if (s[i] ==  ( )         dp[j + 1] = dp[j] + 1;       else         dp[j + 1] = dp[j] - 1;     }     for (int i = 0; i <= n; i++) {       if (!dp[i]) {         v.push_back(i);         ans++;       }     }     ans--;     int zero = ans;     int sum = v.size();     for (int i = 0; i < sum - 1; i++) {       int j = i + 1;       int cnt = 0;       for (int k = v[i]; k <= v[j]; k++) {         if (dp[k] == 1) cnt++;       }       if (cnt > ans) {         ans = cnt;         ans1 = v[i] + 1, ans2 = v[j];       }     }     v.clear();     for (int i = 1; i <= n; i++)       if (dp[i] == 1) v.push_back(i);     sum = v.size();     for (int i = 0; i < sum - 1; i++) {       int j = i + 1;       int cnt = 0;       for (int k = v[i]; k <= v[j]; k++) {         if (dp[k] == 2) cnt++;         if (dp[k] < 1) {           cnt = 0;           break;         }       }       if (cnt + zero > ans) {         ans = cnt + zero;         ans1 = v[i] + 1, ans2 = v[j];       }     }     pos++;     ans1 += pos, ans2 += pos;     if (ans1 > n) ans1 %= n;     if (ans2 > n) ans2 %= n;     cout << ans << endl;     cout << ans1 <<     << ans2 << endl;     return ans;   }   int main() {     cin >> n;     cin >> s;     int ans = 0, ans1 = 1, ans2 = 1;     if (get(s) == 0) {       cout << ans << endl;       cout << ans1 <<     << ans2 << endl;       return 0;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, k, a, b;   vector<long long> v;   long long rec(long long l, long long r) {     long long i = lower_bound(v.begin(), v.end(), l) - v.begin();     long long j = upper_bound(v.begin(), v.end(), r) - v.begin();     j--;     long long na = j - i + 1;     long long val1 = b * (r - l + 1) * na;     if (na == 0) return a;     if (l == r) {       if (na == 0)         return a;       else         return val1;     }     long long mid = (r + l) / 2;     long long val2 = rec(l, mid) + rec(mid + 1, r);     long long ans = min(val1, val2);     return ans;   }   int main() {     cin >> n >> k >> a >> b;     long long x;     for (long long i = 0; i < k; i++) {       cin >> x;       v.push_back(x);     }     sort(v.begin(), v.end());     long long l = 1, r = pow(2, n);     long long ans = rec(l, r);     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int N;     cin >> N;     int* results = new int[N];     for (int i = 0; i < N; i++) {       int num, pos;       cin >> num >> pos;       results[i] = pos * 2;     }     for (int i = 0; i < N; i++) cout << results[i] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   pair<int, int> v[100000 + 1];   vector<int> sol[100000 + 1];   int is[100000 + 1];   int pos[100000 + 1];   int main() {     int i, j, first, N, res = 0;     scanf( %d , &N);     for (i = 1; i <= N; ++i) {       scanf( %d , &first);       v[i] = {first, i};     }     sort(v + 1, v + N + 1);     for (i = 1; i <= N; ++i)       if (!is[i]) {         ++res;         is[i] = 1;         for (j = v[i].second; j != i; j = v[j].second)           is[j] = 1, sol[res].push_back(j);         sol[res].push_back(i);       }     printf( %d n , res);     for (i = 1; i <= res; ++i) {       printf( %d  , sol[i].size());       for (j = 0; j < sol[i].size(); ++j) printf( %d  , sol[i][j]);       printf(  n );     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   using ll = long long;   using ull = unsigned long long;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ll n;     int k;     cin >> n >> k;     ll s = n * (n - 1) / 2;     s %= n;     ll t = 0;     ll cnt = 0;     for (int i = 0; i < k; i++) {       ll a, b;       cin >> a >> b;       (t += a * b) %= n;       cnt += b;     }     if (cnt < n) {       cout <<  1 n ;     } else if (cnt > n) {       cout <<  -1 n ;     } else {       if (s == t) {         cout <<  1 n ;       } else {         cout <<  -1 n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, q;     cin >> n >> m >> q;     int a[n][m];     struct a {       int o;       int p;     } arr[q];     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         cin >> a[i][j];       }     }     int fo[n];     for (int i = 0; i < n; i++) {       int c = 0;       int max = 0;       for (int j = 0; j < m; j++) {         if (a[i][j] == 1) c++;         if (c > max) max = c;         if (a[i][j] == 0) c = 0;       }       fo[i] = max;     }     for (int i = 0; i < q; i++) {       cin >> arr[i].o;       cin >> arr[i].p;       arr[i].o--;       arr[i].p--;     }     for (int i = 0; i < q; i++) {       a[arr[i].o][arr[i].p] = a[arr[i].o][arr[i].p] ^ 1;       int max = 0;       int c = 0;       for (int j = 0; j < m; j++) {         if (a[arr[i].o][j] == 1) c++;         if (c > max) max = c;         if (a[arr[i].o][j] == 0) c = 0;       }       fo[arr[i].o] = max;       int maxi = 0;       for (int j = 0; j < n; j++) {         if (fo[j] > maxi) maxi = fo[j];       }       cout << maxi << endl;     }     return 0;   }


#include <bits/stdc++.h>   const long long int maxn = 2e7 + 5;   const long long mod = 1e9 + 7;   using namespace std;   long long int power(long long int a, long long int b) {     long long int res = 1;     while (b > 0) {       if (b % 2 == 1) res = res * a;       a = a * a;       b = b / 2;     }     return res;   }   long long po(long long x, long long y) {     long long res = 1;     x = x % mod;     while (y > 0) {       if (y & 1) res = ((res % mod) * (x % mod)) % mod;       y = y >> 1;       x = ((x % mod) * (x % mod)) % mod;     }     return res;   }   int dp[3001][3001];   int n;   vector<pair<long long int, long long int> > p(3001);   int fun(int i, int pp) {     if (i >= n) return 0;     if (dp[i][pp] != -1) return dp[i][pp];     return dp[i][pp] = min(p[i].second + fun(i + 1, i),                            abs(p[i].first - p[pp].first) + fun(i + 1, pp));   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int t = 1;     while (t--) {       memset(dp, -1, sizeof(dp));       cin >> n;       for (int i = 0; i < n; i++) cin >> p[i].first >> p[i].second;       p.resize(n);       sort((p).begin(), (p).end());       cout << p[0].second + fun(1, 0) <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, c = 0, i, aa = 0, bb = 0;     cin >> n;     int a[n], b[n];     for (i = 0; i < n; i++) {       cin >> a[i] >> b[i];       aa = aa + a[i];       bb = bb + b[i];     }     if (aa % 2 == 1 && bb % 2 == 1) {       for (i = 0; i < n; i++) {         if ((a[i] + b[i]) % 2 == 1) {           c++;           break;         }       }     }     if (aa % 2 == 0 && bb % 2 == 0)       cout <<  0 ;     else if (c == 1)       cout <<  1 ;     else       cout <<  -1 ;   }


#include <bits/stdc++.h>   using namespace std;   inline bool SR(int &x) { return scanf( %d , &x) == 1; }   inline bool SR(long long &x) { return scanf( %lld , &x) == 1; }   inline bool SR(double &x) { return scanf( %lf , &x) == 1; }   inline bool SR(char *s) { return scanf( %s , s) == 1; }   inline bool RI() { return true; }   template <typename I, typename... T>   inline bool RI(I &x, T &...tail) {     return SR(x) && RI(tail...);   }   inline void SP(const int x) { printf( %d , x); }   inline void SP(const long long x) { printf( %lld , x); }   inline void SP(const double x) { printf( %.16lf , x); }   inline void SP(const char *s) { printf( %s , s); }   inline void PL() { puts(  ); }   template <typename I, typename... T>   inline void PL(const I x, const T... tail) {     SP(x);     if (sizeof...(tail)) putchar(   );     PL(tail...);   }   template <typename I>   void _DOING(const char *s, I &&x) {     cerr << s <<   =   << x << endl;   }   template <typename I, typename... T>   void _DOING(const char *s, I &&x, T &&...tail) {     int c = 0;     while (*s !=  ,  || c != 0) {       if (*s ==  (  || *s ==  [  || *s ==  { ) c++;       if (*s ==  )  || *s ==  ]  || *s ==  } ) c--;       cerr << *s++;     }     cerr <<   =   << x <<   ,  ;     _DOING(s + 1, tail...);   }   const int INF = 0x3f3f3f3f;   const long long INF64 = 0x3f3f3f3f3f3f3f3fll;   inline int RAND() {     static int x = 880301;     return (x = x * 0xdefaced + 1) % 0x7fffffff;   }   const int MAX_N = 100000 + 7;   int main() {     int n;     RI(n);     vector<int> v;     for (int i = 0; i < int(2 * n); i++) {       int x;       RI(x);       v.push_back(x);     }     sort((v).begin(), (v).end());     long long ans = 1ll * (v[n - 1] - v[0]) * (v[2 * n - 1] - v[n]);     for (int i = 1; i + n - 1 < 2 * n; i++) {       long long t = 1ll * (v.back() - v[0]) * (v[i + n - 1] - v[i]);       ans = min(ans, t);     }     PL(ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1000100;   const int MOD = 1000000007;   vector<long long> al[N], sum[N];   vector<pair<int, int> > adj[N];   pair<int, int> p[N];   int cnt(int u, long long ls) {     return upper_bound(al[u].begin(), al[u].end(), ls) - al[u].begin();   }   long long hp(int u, long long h, long long ls) {     long long c1 = cnt(u, ls);     if (c1 == 0) return 0;     return h * c1 - sum[u][c1 - 1];   }   int n, k, l[N], q, a, h;   void dfs(int u, long long cost) {     al[u].push_back(0);     for (int i = 0; i < adj[u].size(); ++i) {       int v = adj[u][i].first;       dfs(v, cost + adj[u][i].second);       for (int k = 0; k < al[v].size(); ++k) {         al[u].push_back(al[v][k] + adj[u][i].second);       }     }     sort(al[u].begin(), al[u].end());     for (int i = 0; i < al[u].size(); ++i) {       sum[u].push_back((i ? sum[u].back() : 0) + (al[u][i]));     }   }   int main() {     memset(p, -1, sizeof p);     scanf( %d%d , &n, &q);     for (int i = 1; i <= n - 1; ++i) {       scanf( %d , &l[i]);       int u = (i + 1) / 2;       int v = (i + 1);       p[v] = make_pair(u, l[i]);       adj[u].push_back(make_pair(v, l[i]));     }     dfs(1, 0);     while (q--) {       scanf( %d%d , &a, &h);       long long cur = a, prev = -1, rem = h;       long long add = 0;       while (1) {         add += hp(cur, rem, rem);         if (prev != -1) {           long long kk = rem - p[prev].second;           add -= hp(prev, kk, kk);         }         prev = cur;         rem = rem - p[cur].second;         cur = p[cur].first;         if (cur == -1 || rem < 0) break;       }       printf( %lld n , add);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long maxn = 300100, maxv = 100, mod = 1e9 + 7, maxa = 1005,                   maxs = 820, maxb = 20, base = 737, base2 = 3079,                   mod3 = 998244353, delt = 10513;   const long long inf = 2e16;   const long long infint = 1e9 + 11;   long long max(long long x, long long y) { return (x > y ? x : y); }   long long min(long long x, long long y) { return (x < y ? x : y); }   vector<long long> v[maxn];   long long dp[maxn][2];   bool visited[maxn];   long long ans = 0;   void dfs(long long x) {     visited[x] = 1;     long long kid = v[x].size();     vector<long long> tmp;     if (x != 0) {       kid--;     }     for (auto u : v[x]) {       if (!visited[u]) {         dfs(u);         ans = max(ans, dp[u][1] + 1);         dp[x][0] = max(dp[x][0], dp[u][0] + kid);         tmp.push_back(dp[u][0]);         sort(tmp.begin(), tmp.end());         reverse(tmp.begin(), tmp.end());         if (tmp.size() > 2) {           tmp.pop_back();         }       }     }     dp[x][1] = dp[x][0];     if (tmp.size() == 2) {       dp[x][1] = max(dp[x][1], tmp[0] + tmp[1] + kid - 1);     }     ans = max(ans, dp[x][1]);   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long q;     cin >> q;     while (q--) {       ans = 1;       long long n;       cin >> n;       for (long long i = 0; i < n; i++) {         visited[i] = 0;         v[i].clear();         dp[i][0] = 1;         dp[i][1] = 1;       }       for (long long i = 0; i < n - 1; i++) {         long long a, b;         cin >> a >> b;         a--;         b--;         v[a].push_back(b);         v[b].push_back(a);       }       dfs(0);       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const int N = 2e5 + 123;   int a[N];   vector<int> g[N];   int n, node, stdist = 0;   void dfs(int k, int par, int dist) {     if (dist > stdist) {       node = k;       stdist = dist;     }     for (auto it : g[k]) {       if (it == par) continue;       dfs(it, k, dist + (a[k] ^ a[it]));     }   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = 1; i <= n - 1; i++) {       int u, v;       cin >> u >> v;       g[u].push_back(v);       g[v].push_back(u);     }     node = 1;     dfs(node, node, 0);     dfs(node, node, 0);     cout << (stdist + 1) / 2;     return false;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 510;   const long long INF = 1e18;   inline int read() {     int x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x * f;   }   int n, m, now;   bitset<N> f[2][70][N], g, tmp;   long long ans, fac[N];   int main() {     n = read();     m = read();     for (int i = 1, u, v, w; i <= m; i++) {       u = read();       v = read();       w = read();       f[w][0][u][v] = 1;     }     for (int i = 1; i <= 60; i++)       for (int u = 1; u <= n; u++)         for (int v = 1; v <= n; v++) {           if (f[0][i - 1][u][v] != 0) f[0][i][u] |= f[1][i - 1][v];           if (f[1][i - 1][u][v] != 0) f[1][i][u] |= f[0][i - 1][v];         }     if (f[0][60][1].count()) {       puts( -1 );       return 0;     }     fac[0] = 1;     for (int i = 1; i <= 60; i++) fac[i] = fac[i - 1] * 2;     now = 0;     tmp[1] = 1;     for (int i = 60; i >= 0; i--) {       g.reset();       for (int j = 1; j <= n; j++)         if (tmp[j]) g |= f[now][i][j];       if (g.count() != 0) {         now ^= 1;         tmp = g;         ans += fac[i];       }     }     if (ans > INF)       puts( -1 );     else       printf( %lld n , ans);     return 0;   }