#include <bits/stdc++.h>   using namespace std;   int p[110];   int main() {     int n, cnt;     cin >> n;     for (int i = 0; i < n; i++) cin >> p[i];     string s;     getline(cin, s);     for (int i = 0; i < n; i++) {       cnt = 0;       getline(cin, s);       for (int j = 0; j < s.size(); j++)         if (s[j] ==  a  || s[j] ==  e  || s[j] ==  i  || s[j] ==  o  ||             s[j] ==  u  || s[j] ==  y )           cnt++;       if (cnt != p[i]) {         cout <<  NO ;         return 0;       }     }     cout <<  YES ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T, typename S>   ostream &operator<<(ostream &os, const pair<T, S> &v) {     os <<  ( ;     os << v.first <<  ,  << v.second <<  ) ;     return os;   }   template <typename T>   ostream &operator<<(ostream &os, const vector<T> &v) {     os <<  [ ;     long long sz = v.size();     for (long long i = 0; i < sz; ++i) {       os << v[i];       if (i != sz - 1) os <<  , ;     }     os <<  ] n ;     return os;   }   template <typename T>   ostream &operator<<(ostream &os, const set<T> &v) {     T last = *v.rbegin();     os <<  [ ;     for (auto it : v) {       os << it;       if (it != last) os <<  , ;     }     os <<  ] n ;     return os;   }   template <typename T, typename S>   ostream &operator<<(ostream &os, const map<T, S> &v) {     for (auto it : v) {       os << it.first <<   :   << it.second <<   n ;     }     return os;   }   long long power(long long a, long long b) {     long long res = 1;     while (b) {       if (b % 2) {         res = (res * a) % 1000000007;       }       b /= 2;       a = (a * a) % 1000000007;     }     return res;   }   template <typename Arg1>   void __f(const char *name, Arg1 &&arg1) {     cerr << name <<   :   << arg1 << std::endl;   }   template <typename Arg1, typename... Args>   void __f(const char *names, Arg1 &&arg1, Args &&...args) {     const char *comma = strchr(names + 1,  , );     cerr.write(names, comma - names) <<   :   << arg1 <<   |  ;     __f(comma + 1, args...);   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long n, T;     cin >> n >> T;     vector<pair<long long, long long> > arr;     for (__typeof(1) i = 1; i <= n; i++) {       long long t;       cin >> t;       long long from = t - i;       long long to = T - i;       if (to > from && to > 0) {         arr.push_back({from, 1});         arr.push_back({to, -1});       }     }     sort((arr).begin(), (arr).end());     long long curr = 0, ans = 0;     for (auto it : arr) {       curr += it.second;       ans = max(ans, curr);     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int32_t main() {     long long int t;     cin >> t;     while (t--) {       long long int x = 0;       long long int n, m;       cin >> n >> m;       for (long long int i = 0; i < n; i++) {         long long int a, b, c, d;         cin >> a >> b >> c >> d;         if (b == c && m % 2 != 1 && x != 1) {           cout <<  Yes  << endl;           x = 1;         }       }       if (x == 0) cout <<  No  << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 200020;   long long int n;   int main() {     cin >> n;     for (long long int i = 1; i <= n - 1; i++) {       for (long long int j = 1; j <= n - 1; j++) {         if (i == j)           cout <<  0  ;         else           cout << 1 + (i + j - 2) % (n - 1) <<    ;       }       cout << (2 * i - 2) % (n - 1) + 1 << endl;     }     for (long long int i = 1; i <= n - 1; i++) {       cout << (2 * i - 2) % (n - 1) + 1 <<    ;     }     cout <<  0  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int p[1001][1001], row[1001], col[1001];   int main() {     int n, m, k;     scanf( %d%d%d , &n, &m, &k);     for (int r = 1; r <= n; ++r) row[r] = r;     for (int c = 1; c <= m; ++c) col[c] = c;     for (int r = 1; r <= n; ++r)       for (int c = 1; c <= m; ++c) scanf( %d , &p[r][c]);     while (k--) {       char s[2];       int x, y;       scanf( %s%d%d , s, &x, &y);       switch (s[0]) {         case  r :           swap(row[x], row[y]);           break;         case  c :           swap(col[x], col[y]);           break;         case  g :           printf( %d n , p[row[x]][col[y]]);           break;         default:           break;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   struct P {     int x, y;     bool operator<(const P &a) const { return x > a.x; }   } a[N];   int main() {     static int n, b[N * 2];     cin >> n;     for (int i = 1; i <= n; i++) scanf( %d , (int *)(a + i)), a[i].y = i * 2 - 1;     sort(a + 1, a + 1 + n);     for (int i = 1; i < n; i++) printf( %d %d n , a[i].y, a[i + 1].y);     for (int i = 1; i <= n; i++) b[i] = a[i].y;     for (int i = 1, aid, *bid; i <= n; i++) {       aid = a[i].y + 1, bid = b + i + a[i].x;       if (!*bid)         printf( %d %d n , aid, *(bid - 1)), *bid = aid;       else         printf( %d %d n , aid, *--bid);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> graph[100005];   int a[100005], b[100005];   vector<int> ans;   void dfs(int source, int parent, int oddlevel, int evenlevel, int depth) {     if (depth % 2 == 1)       a[source] ^= oddlevel;     else       a[source] ^= evenlevel;     if (a[source] != b[source]) {       a[source] ^= 1;       if (depth % 2 == 1)         oddlevel++;       else         evenlevel++;       oddlevel %= 2, evenlevel %= 2;       ans.push_back(source);     }     for (int i = 0; i < graph[source].size(); i++) {       int child = graph[source][i];       if (child == parent) continue;       dfs(child, source, oddlevel, evenlevel, depth + 1);     }   }   int main() {     int n;     cin >> n;     for (int i = 1; i < n; i++) {       int x, y;       cin >> x >> y;       graph[x].push_back(y);       graph[y].push_back(x);     }     for (int i = 1; i <= n; i++) {       cin >> a[i];     }     for (int i = 1; i <= n; i++) cin >> b[i];     dfs(1, 0, 0, 0, 0);     cout << ans.size() << endl;     for (int i = 0; i < ans.size(); i++) {       cout << ans[i] << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     while (cin >> n) {       string s;       cin >> s;       int l[3005], r[3005];       memset(l, -1, sizeof(l));       memset(r, -1, sizeof(r));       int cnt = 0, t1 = 0, t2 = 0;       for (int i = 0; i < n; ++i) {         if (s[i] ==  L ) {           l[t1++] = i;           continue;         }         if (s[i] ==  R ) {           r[t2++] = i;           continue;         }       }       if (l[0] == r[0]) {         cout << n << endl;         continue;       }       if (l[0] == -1) {         cout << r[0] << endl;         continue;       }       if (r[0] == -1) {         cout << n - l[0] - 1 << endl;         continue;       }       if (l[0] < r[0]) {         cnt += l[0] + 1;         for (int i = 1; i < t1; ++i) {           int t = l[i] - r[i - 1];           cnt += t + 1;           if (t % 2 == 0) cnt--;         }         if (t1 == t2) cnt += n - r[t2 - 1];       } else {         for (int i = 0; i < t1; ++i) {           int t = l[i] - r[i];           cnt += t + 1;           if (t % 2 == 0) cnt--;         }         if (t2 > t1) cnt += n - r[t2 - 1];       }       cout << n - cnt << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxN = 100100;   const long double INF = 1e100;   const long double eps = 1e-6;   const long double PI = 3.14159265358979323846264338328;   long long x[maxN], y[maxN];   long double Dis(long long a, long long b, long long p, long long q) {     long double aa = 1.0 * a, bb = 1.0 * b, pp = 1.0 * p, qq = 1.0 * q;     return (aa - pp) * (aa - pp) + (bb - qq) * (bb - qq);   }   long double DfromL(long long X1, long long Y1, long long aa, long long bb,                      long long pp, long long qq) {     long double X = 1.0 * X1, Y = 1.0 * Y1, a = 1.0 * aa, b = 1.0 * bb,                 p = 1.0 * pp, q = 1.0 * qq;     bool Inf = (a == p);     long double m = (Inf) ? INF : ((b - q) / (a - p));     long double c = (Inf) ? INF : ((b - m * a));     bool zero = (!Inf && m == 0.0);     long double m1 = (Inf) ? (0) : (zero) ? INF : (-1.0 / m);     long double c1 = (Inf) ? (Y) : (zero) ? INF : (Y - m1 * X);     long double XX = (Inf) ? (a) : (zero) ? (X) : ((c1 - c) / (m - m1));     long double YY = (Inf) ? (Y) : (zero) ? (b) : ((m * c1 - m1 * c) / (m - m1));     if (XX >= min(a, p) && XX <= max(a, p) && YY >= min(b, q) &&         YY <= max(b, q)) {       if (Inf) return (X - XX) * (X - XX);       if (zero) return (Y - YY) * (Y - YY);       return ((m * X - Y + c) * (m * X - Y + c)) / (1.0 + m * m);     } else       return -1.0;   }   int main() {     ios::sync_with_stdio(false);     long long n, X, Y;     cin >> n >> X >> Y;     for (int i = 0; i < n; i++) cin >> x[i] >> y[i];     long double maxR = -1.0, minR = INF;     for (int i = 0; i < n; i++) {       long double dis = Dis(X, Y, x[i], y[i]);       maxR = max(maxR, dis);       minR = min(minR, dis);       long double diS = DfromL(X, Y, x[i], y[i], x[(i + 1) % n], y[(i + 1) % n]);       if (diS != -1.0) {         maxR = max(maxR, diS);         minR = min(minR, diS);       }     }     long double ans = PI * (maxR - minR);     cout << setprecision(20) << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[500005];   int q[500005];   int n, k, d;   int main() {     scanf( %d%d%d , &n, &k, &d);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     sort(a + 1, a + n + 1);     int l = 1, r = 1;     q[l] = 0;     for (int i = k; i <= n; i++) {       while (l <= r && a[i] - a[q[l] + 1] > d) l++;       if (l <= r && i - q[l] >= k) q[++r] = i;     }     if (q[r] == n)       printf( YES n );     else       printf( NO n );     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     vector<int> a(n + 1);     for (int i = 1; i <= n; ++i) {       cin >> a[i];     }     sort(a.begin(), a.end());     vector<vector<vector<int>>> dp(         2, vector<vector<int>>(k + 1, vector<int>(k + 1)));     dp[0][0][0] = 1;     int ans = 0;     set<int> sad;     for (int i = 1; i <= n; ++i) {       for (int j = 0; j <= k; ++j) {         for (int l = 0; l <= j; ++l) {           int i2 = i % 2;           dp[i2][j][l] = dp[abs(i2 - 1)][j][l];           if (a[i] <= j) {             dp[i2][j][l] =                 max(dp[abs(i2 - 1)][j][l], dp[abs(i2 - 1)][j - a[i]][l]);             if (a[i] <= l) {               dp[i2][j][l] =                   max(dp[i2][j][l], dp[abs(i2 - 1)][j - a[i]][l - a[i]]);             }           }           if (i == n && j == k && dp[i2][j][l] != 0) {             ++ans;             sad.insert(l);           }         }       }     }     cout << ans << endl;     for (auto i : sad) {       cout << i <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   long long int gcd(long long int m, long long int n) {     if (n == 0) return m;     return gcd(n, m % n);   }   int MOD = 1000000000;   long long int powmod(long long int a, long long int b) {     if (b == 0) return 1;     long long int x = powmod(a, b / 2);     long long int y = (x * x) % MOD;     if (b % 2) return (a * y) % MOD;     return y % MOD;   }   int main() {     std::ios::sync_with_stdio(false);     int n, k;     cin >> n >> k;     int z;     int a[10000];     for (int i = 0; i < n; i++) cin >> a[i];     int ans = 0;     for (int i = 0; i < n - 1; i++) {       if (a[i] > 8) {         a[i + 1] = a[i + 1] + a[i] - 8;         k = k - 8;       } else         k = k - a[i];       if (k <= 0) {         cout << i + 1 << endl;         return 0;       }     }     if (k - min(a[n - 1], 8) > 0)       cout <<  -1  << endl;     else       cout << n << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool pid_comp_second(pair<int, double> a, pair<int, double> b) {     if (a.second == b.second) return a.first < b.first;     return a.second > b.second;   }   int main() {     double x, y, z;     cin >> x >> y >> z;     map<int, string> expr;     expr[1] =  x^y^z ;     expr[2] =  x^z^y ;     expr[3] =  (x^y)^z ;     expr[5] =  y^x^z ;     expr[6] =  y^z^x ;     expr[7] =  (y^x)^z ;     expr[9] =  z^x^y ;     expr[10] =  z^y^x ;     expr[11] =  (z^x)^y ;     vector<pair<int, double> > nums;     if (x < 1 || x < 1 || x < 1) {       nums.push_back(make_pair(1, pow(y, z) * log(x)));       nums.push_back(make_pair(2, pow(z, y) * log(x)));       nums.push_back(make_pair(3, y * z * log(x)));       nums.push_back(make_pair(5, pow(x, z) * log(y)));       nums.push_back(make_pair(6, pow(z, x) * log(y)));       nums.push_back(make_pair(7, x * z * log(y)));       nums.push_back(make_pair(9, pow(x, y) * log(z)));       nums.push_back(make_pair(10, pow(y, x) * log(z)));       nums.push_back(make_pair(11, x * y * log(z)));     } else {       nums.push_back(make_pair(1, z * log(y) + log(log(x))));       nums.push_back(make_pair(2, y * log(z) + log(log(x))));       nums.push_back(make_pair(3, log(y) + log(z) + log(log(x))));       nums.push_back(make_pair(5, z * log(x) + log(log(y))));       nums.push_back(make_pair(6, x * log(z) + log(log(y))));       nums.push_back(make_pair(7, log(x) + log(z) + log(log(y))));       nums.push_back(make_pair(9, y * log(x) + log(log(z))));       nums.push_back(make_pair(10, x * log(y) + log(log(z))));       nums.push_back(make_pair(11, log(x) + log(y) + log(log(z))));     }     sort(nums.begin(), nums.end(), pid_comp_second);     cout << expr[nums[0].first] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   ofstream fo( test.out );   ifstream fi( test.inp );   const long long MOD = 1e9 + 7;   const long long base = 269;   const int N = 1e5 + 5;   long long n, m, q, K, pos, t, rs, r;   long long cnt10, cnt11;   string s, a, b;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cin >> n;     cin >> a >> b;     for (long long(i) = 0; (i) < (n); (i)++) {       if (a[i] ==  1  && b[i] ==  0 ) cnt10++;       if (a[i] ==  1  && b[i] ==  1 ) cnt11++;     }     for (long long(i) = 0; (i) < (n); (i)++) {       if (a[i] ==  0  && b[i] ==  0 ) {         rs += cnt11;         rs += cnt10;       }       if (a[i] ==  0  && b[i] ==  1 ) rs += cnt10;     }     cout << rs;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t, n, ind;     cin >> t;     while (t--) {       cin >> n;       ind = -1;       int a[n];       for (int i = 0; i < n; ++i) {         cin >> a[i];         if (a[i] % 2 == 0) ind = i;       }       if (ind != -1)         cout <<  1 n  << ind + 1 <<   n ;       else if (n > 1)         cout <<  2 n1 2 n ;       else         cout <<  -1 n ;     }   }


#include <bits/stdc++.h>   using namespace std;   using namespace std;   struct my {     int a;     double b;   };   bool Cmp(my a, my b) { return a.b <= b.b; }   int main() {     int n, m;     cin >> n >> m;     my mine[n];     for (int i = 0; i < n; ++i) {       int a;       cin >> a;       double b;       cin >> b;       mine[i].a = a;       mine[i].b = b;     }     sort(mine, mine + n, Cmp);     int ord[n];     for (int i = 0; i < n; ++i) {       ord[i] = mine[i].a;     }     int dp[n];     for (int i = 0; i < n; ++i) {       dp[i] = 1;     }     for (int i = 0; i < n; i++) {       for (int j = i - 1; j >= 0; j--) {         if (ord[j] <= ord[i]) {           dp[i] = max(dp[j] + 1, dp[i]);         }       }     }     cout << n - *max_element(dp, dp + n) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int Maxn = 1e7 + 10, M = 998244353;   int n, m, k, inv[Maxn], s[Maxn], idk[Maxn];   int mo2(int x) { return (x < 0) ? x + M : x; }   int fpow(int a, int p = M - 2) {     int ret = 1;     for (; p; p >>= 1, a = 1ll * a * a % M)       if (p & 1) ret = 1ll * ret * a % M;     return ret;   }   void init(int n) {     inv[1] = 1;     for (int i = 2; i <= n; i++) inv[i] = M - 1ll * inv[M % i] * (M / i) % M;   }   void get_idk(int k) {     for (int i = 0; i <= k; i++) idk[i] = fpow(i, k);   }   int main() {     scanf( %d%d%d , &n, &m, &k);     int p = fpow(m);     init(k);     s[k] = 1;     int pw = 1, C = 1;     for (int i = k - 1; i >= 0; i--) {       pw = 1ll * pw * (M - p) % M;       C = 1ll * C * (n - i - 1 + M) % M * inv[k - i] % M;       s[i] = (1ll * (1 - p + M) * s[i + 1] + 1ll * C * pw) % M;     }     int E = 0;     pw = C = 1;     get_idk(k);     for (int i = 1; i <= k; i++) {       pw = 1ll * pw * p % M;       C = 1ll * C * (n - i + 1 + M) % M * inv[i] % M;       E = (E + 1ll * idk[i] * C % M * pw % M * s[i]) % M;     }     printf( %d n , E);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1000000009;   const double PI = acos(-1.0);   const double eps = 1e-8;   const int MAXN = 0;   const int MAXM = 0;   bool a[5002];   int i, j, k, n, h, m, id, p, hesh;   map<int, int> M;   char c;   int ans = 0;   int main() {     cin >> h >> m >> n;     for (i = 0; i < n; i++) {       cin >> c;       if (c ==  - ) {         cin >> id;         a[M[id]] = 0;       } else {         cin >> id >> hesh;         while (a[hesh] != 0) {           hesh = (hesh + m) % h;           ans++;         }         a[hesh] = true;         M[id] = hesh;       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, i, a, b, x, y, ans = 0;     scanf( %d , &n);     printf( YES n );     for (int i = 1; i <= n; i++) {       scanf( %d %d %d %d , &a, &b, &x, &y);       x = min(a, x);       y = min(y, b);       ans = abs(x) % 2;       ans = ans * 2 + (abs(y) % 2);       printf( %d n , ans + 1);     }   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const long long LINF = 0x3f3f3f3f3f3f3f3fll;   vector<vector<string> > dp;   int n, m;   string resp =   ;   vector<string> a;   vector<set<char> > occr;   string solve(int at, int estado) {     if (at == m) {       return   ;     }     if (dp[at][estado] !=   ) {       return dp[at][estado];     }     for (char c : occr[at]) {       bool pode = true;       for (int I = 0; I < n; I++) {         if (a[I][at] != c && (estado & (1 << I))) {           pode = false;         }       }       if (!pode) {         continue;       }       int temp = estado;       for (int I = 0; I < n; I++) {         if (a[I][at] != c) {           temp |= (1 << I);         }       }       string res = solve(at + 1, temp);       if (res !=    ) {         return dp[at][estado] = c + res;       }     }     return dp[at][estado] =    ;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int t;     cin >> t;     while (t--) {       cin >> n >> m;       a.clear();       a.resize(n);       occr.clear();       occr.resize(m);       dp.clear();       dp.resize(11, vector<string>(1030,   ));       for (int I = 0; I < n; I++) {         cin >> a[I];       }       for (int I = 0; I < n; I++) {         for (int J = 0; J < m; J++) {           occr[J].insert(a[I][J]);         }       }       string resp = solve(0, 0);       if (resp ==    ) {         cout << -1 <<   n ;       } else {         cout << resp <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MX = 1e5 + 10;   long long A[MX];   long long cnt[MX];   vector<long long> pos[MX];   long long ans[MX];   void init(long long n) {     for (long long i = 0; i <= n + 2; i++) cnt[i] = 0;     for (long long i = 0; i <= n + 2; i++) pos[i].clear();     for (long long i = 0; i <= n + 2; i++) ans[i] = -1;   }   void salida(long long n, long long val) {     for (long long i = 0; i < n; i++)       if (ans[i] == -1) ans[i] = val;     cout <<  YES n ;     for (long long i = 0; i < n; i++) cout << ans[i] <<    ;     cout <<   n ;   }   void solve() {     long long n, fijo, tot, x;     cin >> n >> fijo >> tot;     long long nfijo = tot - fijo;     init(n);     set<long long> s;     for (long long i = 0; i < n; i++) {       cin >> x;       A[i] = x;       cnt[x]++;       pos[x].push_back(i);       s.insert(x);     }     long long maxNum = n + 1;     priority_queue<pair<long long, long long> > pq;     for (long long i = 1; i <= maxNum; i++) {       if (cnt[i] != 0) pq.push({cnt[i], i});     }     while (!pq.empty() && fijo != 0) {       long long cn = pq.top().first;       long long val = pq.top().second;       pq.pop();       cnt[val]--;       if (cnt[val] != 0) pq.push({cnt[val], val});       long long sz = pos[val].size();       ans[pos[val][sz - 1]] = val;       pos[val].erase(pos[val].begin() + sz - 1);       fijo--;     }     if (fijo > 0) {       cout <<  NO n ;       return;     }     long long numExtra = -1;     for (long long i = 1; i <= maxNum; i++) {       if (s.find(i) == s.end()) numExtra = i;     }     if (nfijo == 0) {       salida(n, numExtra);       return;     }     long long falta = 0;     for (long long i = 1; i <= maxNum; i++) falta += cnt[i];     long long mxSize = pq.top().first;     vector<long long> posi;     while (!pq.empty()) {       long long val = pq.top().second;       pq.pop();       for (long long xx : pos[val]) posi.push_back(xx);     }     if (mxSize <= falta - mxSize) {       long long sz = posi.size();       long long mid = sz / 2;       for (long long i = 0; i < sz; i++) {         if (nfijo == 0) break;         long long cur = i;         long long nxt = (i + mid) % sz;         ans[posi[cur]] = A[posi[nxt]];         nfijo--;       }       salida(n, numExtra);     } else {       reverse(posi.begin(), posi.end());       long long mxPos = falta - mxSize;       if (mxPos * 2 < nfijo) {         cout <<  NO n ;         return;       }       long long sz = posi.size();       for (long long i = 0; i < sz; i++) {         if (nfijo == 0) break;         long long cur = i;         long long nxt = i + mxPos;         if (nfijo == 0) break;         ans[posi[cur]] = A[posi[nxt]];         nfijo--;         if (nfijo == 0) break;         ans[posi[nxt]] = A[posi[cur]];         nfijo--;       }       salida(n, numExtra);     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cout.precision(10);     cout << fixed;     long long t;     cin >> t;     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-9;   const double pi = acos(-1.0);   const double dinf = 1e250;   const long long INF = (long long)(2e18);   const int inf = (int)(1e9 + 7);   struct myt {     int d, s, t;   };   void out(int a, int b) { cout << a <<     << b <<   n ; }   vector<int> ind;   vector<vector<int> > g;   int32_t main() {     ios_base::sync_with_stdio(0);     cout << fixed << setprecision(10);     cin.tie(0);     int n;     cin >> n;     vector<myt> ar(n);     for (int i = 0; i < n; ++i) {       cin >> ar[i].d;       ar[i].s = 2 * i + 1;       ar[i].t = 2 * i + 2;     }     sort(begin(ar), end(ar), [](myt a, myt b) { return a.d > b.d; });     g.resize(2 * n);     ind.resize(2 * n, 0);     for (int i = 0; i < n; ++i) {       int d = ar[i].d;       if (ind[i] == 0)         ind[i] = ar[i].s;       else {         --d;         g[i].push_back(ar[i].s);       }       if (d == 0) {         out(ar[i].s, ar[i].t);       } else if (ind[i + d] == 0) {         ind[i + d] = ar[i].t;       } else {         g[i + d - 1].push_back(ar[i].t);       }     }     for (int i = 0; i < g.size(); ++i) {       if (ind[i] == 0) continue;       for (auto& it : g[i]) out(ind[i], it);     }     for (int i = 0; i < ind.size() - 1; ++i) {       if (ind[i] == 0) continue;       if (ind[i + 1] == 0) continue;       out(ind[i], ind[i + 1]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 100010;   long long quick_Mod(long long n) {     long long ans = 1;     long long x = 2;     while (n) {       if (n & 1) ans = ans * x % 1000000007;       n = n >> 1;       x = x * x % 1000000007;     }     return ans;   }   void ex_gcd(long long a, long long b, long long &gcd, long long &x,               long long &y) {     if (b == 0) {       gcd = a;       y = 0;       x = 1;       return;     } else {       ex_gcd(b, a % b, gcd, y, x);       y -= x * (a / b);     }   }   long long inverse(long long a) {     long long gcd, x, y;     ex_gcd(a, 1000000007, gcd, x, y);     if (gcd == 1)       return (x % 1000000007 + 1000000007) % 1000000007;     else       return -1;   }   int main() {     char s[MAX];     long long k;     scanf( %s , s);     scanf( %I64d , &k);     long long len = strlen(s);     long long ans = 0;     for (int i = 0; i < len; i++) {       if (s[i] ==  0  || s[i] ==  5 ) {         ans += quick_Mod(i) * inverse(quick_Mod(len) - 1) % 1000000007 *                (quick_Mod(k * len) - 1) % 1000000007;       }     }     printf( %I64d n , (ans % 1000000007 + 1000000007) % 1000000007);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, Q;   set<int> cut[2];   map<int, int> mx[2];   long long getmx() {     map<int, int>::iterator it;     it = mx[0].end();     it--;     int u = (*it).first;     it = mx[1].end();     it--;     int v = (*it).first;     return 1ll * u * v;   }   void Insert(int t, int x) {     int u, v;     set<int>::iterator it = cut[t].lower_bound(x);     v = *it;     it--;     u = *it;     mx[t][v - u]--;     if (mx[t][v - u] == 0) mx[t].erase(v - u);     cut[t].insert(x);     mx[t][x - u]++;     mx[t][v - x]++;   }   int main() {     char t;     int x;     scanf( %d %d %d , &n, &m, &Q);     cut[0].insert(0);     cut[0].insert(n);     mx[0][n]++;     cut[1].insert(0);     cut[1].insert(m);     mx[1][m]++;     for (int i = 1; i <= Q; i++) {       scanf(  %c %d , &t, &x);       if (t ==  V ) Insert(0, x);       if (t ==  H ) Insert(1, x);       printf( %I64d n , getmx());     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int IINF = 0x3f3f3f3f;   const long long LINF = 0x3f3f3f3f3f3f3f3fll;   const double DINF = numeric_limits<double>::infinity();   const int MOD = 1000000007;   const double EPS = 1e-9;   const double PI = acos(-1.0);   const int DX[] = {1, 0, -1, 0, 1, -1, 1, -1};   const int DY[] = {0, 1, 0, -1, 1, -1, -1, 1};   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   long long sqr(long long x) { return x * x; }   long long sqr(int x) { return (long long)x * x; }   double sqr(double x) { return x * x; }   long double sqr(long double x) { return x * x; }   mt19937 mmtw(960172);   long long rnd(long long x, long long y) {     static uniform_int_distribution<long long> d;     return d(mmtw) % (y - x + 1) + x;   }   const int N = 1011;   struct Line {     vector<int> cs;     int si0;   };   struct Seg {     int x, y1, y2;   };   int vc1, vc2;   Seg vs1[N], vs2[N];   vector<int> e[N];   int p2[N];   int p1[N];   bool vis1[N];   bool ok1[N], ok2[N];   bool dfs(int v) {     if (vis1[v]) return false;     vis1[v] = true;     for (int nv : e[v]) {       if (p2[nv] == -1) {         p2[nv] = v;         p1[v] = nv;         return true;       } else if (dfs(p2[nv])) {         p2[nv] = v;         p1[v] = nv;         return true;       }     }     return false;   }   void dfs2(int v) {     if (vis1[v]) return;     vis1[v] = 1;     for (int nv : e[v])       if (p2[nv] != -1) dfs2(p2[nv]);   }   int main() {     memset(p1, -1, sizeof(p1));     memset(p2, -1, sizeof(p2));     ios::sync_with_stdio(false);     int n;     scanf( %d , &n);     map<int, Line> mx, my;     for (int i = 0; i < n; ++i) {       int x, y;       scanf( %d%d , &x, &y);       mx[x].cs.push_back(y);       my[y].cs.push_back(x);     }     for (auto& p : mx) {       int x = p.first;       Line& l = p.second;       sort((l.cs).begin(), (l.cs).end());       l.si0 = vc1;       for (int i = 0; i < ((int)((l.cs).size())) - 1; ++i)         vs1[vc1++] = {x, l.cs[i], l.cs[i + 1]};     }     for (auto& p : my) {       int y = p.first;       Line& l = p.second;       sort((l.cs).begin(), (l.cs).end());       l.si0 = vc2;       for (int i = 0; i < ((int)((l.cs).size())) - 1; ++i)         vs2[vc2++] = {y, l.cs[i], l.cs[i + 1]};     }     for (int i = 0; i < vc1; ++i)       for (int j = 0; j < vc2; ++j) {         Seg s1 = vs1[i];         Seg s2 = vs2[j];         if (s1.y1 < s2.x && s2.x < s1.y2)           if (s2.y1 < s1.x && s1.x < s2.y2) {             e[i].push_back(j);           }       }     while (true) {       bool was = false;       memset(vis1, 0, sizeof(bool) * vc1);       for (int i = 0; i < vc1; ++i)         if (p1[i] == -1 && dfs(i)) was = true;       if (!was) break;     }     memset(vis1, 0, sizeof(bool) * vc1);     for (int i = 0; i < vc1; ++i)       if (p1[i] == -1) dfs2(i);     for (int i = 0; i < vc1; ++i)       if (vis1[i]) ok1[i] = 1;     for (int i = 0; i < vc2; ++i)       if (p2[i] == -1 || !vis1[p2[i]]) ok2[i] = 1;     struct Ans {       int x1, y1, x2, y2;     };     vector<Ans> ans;     for (auto const& p : my) {       int y = p.first;       Line const& l = p.second;       int i = 0;       while (i < ((int)((l.cs).size()))) {         int j = i;         while (j < ((int)((l.cs).size())) - 1) {           int id = l.si0 + j;           if (ok2[id])             ++j;           else             break;         }         ans.push_back({l.cs[i], y, l.cs[j], y});         i = j + 1;       }     }     cout << ((int)((ans).size())) <<   n ;     for (auto s : ans)       cout << s.x1 <<     << s.y1 <<     << s.x2 <<     << s.y2 <<   n ;     ans.clear();     for (auto const& p : mx) {       int x = p.first;       Line const& l = p.second;       int i = 0;       while (i < ((int)((l.cs).size()))) {         int j = i;         while (j < ((int)((l.cs).size())) - 1) {           int id = l.si0 + j;           if (ok1[id])             ++j;           else             break;         }         ans.push_back({x, l.cs[i], x, l.cs[j]});         i = j + 1;       }     }     cout << ((int)((ans).size())) <<   n ;     for (auto s : ans)       cout << s.x1 <<     << s.y1 <<     << s.x2 <<     << s.y2 <<   n ;     return 0;   }


#include <bits/stdc++.h>   template <class T>   std::string toStr(T t);   using namespace std;   int main() {     int statA[4];     int statB[4];     for (__typeof(4) i = 0; i < 4; i++) {       cin >> statA[i];       cin >> statB[i];     }     int pos[4][4] = {{0, 1, 2, 3}, {1, 0, 2, 3}, {0, 1, 3, 2}, {1, 0, 3, 2}};     int res[4] = {0, 0, 0, 0};     for (__typeof(4) p = 0; p < 4; p++) {       if (statA[pos[p][0]] > statB[pos[p][2]] &&           statB[pos[p][1]] > statA[pos[p][3]]) {         res[p] = 1;       }       if (statA[pos[p][0]] < statB[pos[p][2]] &&           statB[pos[p][1]] < statA[pos[p][3]]) {         res[p] = 2;       }     }     if ((res[0] == 1 && res[2] == 1) || (res[1] == 1 && res[3] == 1)) {       cout <<  Team 1  << endl;       return 0;     }     if ((res[0] == 2 || res[2] == 2) && (res[1] == 2 || res[3] == 2)) {       cout <<  Team 2  << endl;       return 0;     }     cout <<  Draw  << endl;   }   template <class T>   string toStr(T t) {     std::stringstream strstream;     string resStr;     strstream << t;     strstream >> resStr;     return resStr;   }


#include <bits/stdc++.h>   using namespace std;   inline int scan() {     int x;     scanf( %d , &x);     return x;   }   struct data {     int first;     int edge_used;     int prev;     data() {       first = 0;       edge_used = 0;       prev = 0;     }   };   vector<pair<int, int> > v[100005];   bool edge[100005] = {0};   pair<int, int> edges[100005];   data nodes[100005];   bool visited[100005] = {0};   bool used[100005] = {0};   int dist[100005];   int main() {     int n = scan(), m = scan();     for (int i = 1; i <= m; i++) {       int x = scan(), y = scan(), z = scan();       v[x].push_back(make_pair(y, i));       v[y].push_back(make_pair(x, i));       edge[i] = z;       edges[i] = make_pair(x, y);     }     queue<int> q;     q.push(1);     visited[1] = 1;     for (int i = 0; i <= n; i++) dist[i] = 999999;     dist[1] = 0;     bool aslivisit[100001] = {0};     while (!q.empty()) {       int node = q.front();       aslivisit[node] = 1;       q.pop();       int x = v[node].size();       int num = nodes[node].first;       for (int i = 0; i < x; i++) {         int next = v[node][i].first;         if (aslivisit[next]) continue;         int num2 = num;         if (edge[v[node][i].second] == 0) {           num2++;         }         if (!visited[next]) {           visited[next] = 1;           q.push(next);           nodes[next].first = num2;           nodes[next].edge_used = v[node][i].second;           nodes[next].prev = node;           dist[next] = dist[node] + 1;         } else if (dist[next] >= dist[node] + 1) {           if (num2 < nodes[next].first) {             nodes[next].first = num2;             nodes[next].edge_used = v[node][i].second;             nodes[next].prev = node;           }         }       }     }     int cur = n;     while (cur != 0) {       used[nodes[cur].edge_used] = 1;       cur = nodes[cur].prev;     }     int counter = 0;     queue<pair<pair<int, int>, bool> > ans;     for (int i = 1; i <= m; i++) {       if (!used[i] && edge[i] == 1) {         counter++;         ans.push(make_pair(edges[i], 0));       } else if (used[i] && edge[i] == 0) {         counter++;         ans.push(make_pair(edges[i], 1));       }     }     printf( %d n , counter);     while (!ans.empty()) {       printf( %d %d %d n , ans.front().first.first, ans.front().first.second,              ans.front().second);       ans.pop();     }   }


#include <bits/stdc++.h>   using namespace std;   const int MX = 256;   vector<vector<vector<vector<vector<int> > > > > dp;   char grid[MX][MX];   int R, C, mxmask, MOD = 1e9 + 7;   int ison(int x, int bit) {     if ((x & (1 << bit))) return 1;     return 0;   }   int turnoff(int x, int bit) {     if ((x & (1 << bit))) x ^= (1 << bit);     return x;   }   int turnon(int x, int bit) {     x |= (1 << bit);     return x;   }   int calc(int row, int mask, int col, int left, int tok) {     if (col == C) return calc(row + 1, mask, 0, 0, tok);     if (row == R) return 1;     int &ret = dp[row][mask][col][left][tok];     if (ret != -1) return ret;     ret = 0;     if (grid[row][col] ==  x ) {       return ret = calc(row, turnoff(mask, col), col + 1, 0, tok);     }     ret += calc(row, turnon(mask, col), col + 1, 1, tok);     ret %= MOD;     if (left || ison(mask, col)) {       ret += calc(row, mask, col + 1, left, tok);       ret %= MOD;     } else {       if (!tok) ret += calc(row, mask, col + 1, left, 1);       ret %= MOD;     }     return ret;   }   int main() {     cin >> R >> C;     for (int j = 0; j < R; j++) {       for (int i = 0; i < C; i++) {         if (R >= C)           cin >> grid[j][i];         else           cin >> grid[i][j];       }     }     if (R < C) swap(R, C);     mxmask = (1 << C);     dp.resize(R + 2);     for (auto &pp : dp) {       pp.resize(mxmask);       for (auto &qq : pp) {         qq.resize(C + 2);         for (auto &ll : qq) {           ll.resize(2);           for (auto &nn : ll) {             nn.resize(2);             nn[0] = nn[1] = -1;           }         }       }     }     cout << calc(0, 0, 0, 0, 0);   }


#include <bits/stdc++.h>   using namespace std;   long long n, a[1234], i;   int main() {     cin >> n;     for (i = 0; i < n; i++) cin >> a[i];     for (i = 0; i < n; i++)       if (a[i] % 2 == 0) a[i]--;     for (i = 0; i < n; i++) cout << a[i] <<    ;     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T1>   void deb(T1 e1) {     cout << e1 << endl;   }   template <class T1, class T2>   void deb(T1 e1, T2 e2) {     cout << e1 <<     << e2 << endl;   }   template <class T1, class T2, class T3>   void deb(T1 e1, T2 e2, T3 e3) {     cout << e1 <<     << e2 <<     << e3 << endl;   }   template <class T1, class T2, class T3, class T4>   void deb(T1 e1, T2 e2, T3 e3, T4 e4) {     cout << e1 <<     << e2 <<     << e3 <<     << e4 << endl;   }   template <class T1, class T2, class T3, class T4, class T5>   void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5) {     cout << e1 <<     << e2 <<     << e3 <<     << e4 <<     << e5 << endl;   }   template <class T1, class T2, class T3, class T4, class T5, class T6>   void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5, T6 e6) {     cout << e1 <<     << e2 <<     << e3 <<     << e4 <<     << e5 <<     << e6          << endl;   }   struct data {     int x, y;   };   data point[110];   int num[110];   int main() {     memset(num, 0, sizeof(num));     int i, j, t, mark = 1, x1 = 0, y1 = 0;     for (i = 0; i < 8; i += 2) {       scanf( %d%d , &point[i].x, &point[i].y);       scanf( %d%d , &point[i + 1].x, &point[i + 1].y);       if (point[i].x == point[i + 1].x && point[i].y != point[i + 1].y) {         x1++;       } else if (point[i].y == point[i + 1].y && point[i].x != point[i + 1].x) {         y1++;       } else         mark = 0;     }     if ((x1 != 2)) mark = 0;     if (y1 != 2) mark = 0;     for (i = 0; i < 8; i++) {       for (j = 0; j < 8; j++) {         if (point[i].x == point[j].x && point[i].y == point[j].y) {           num[i]++;         }       }     }     for (i = 0; i < 8; i++) {       if (num[i] != 2) {         mark = 0;       }     }     if (mark == 0)       printf( NO );     else       printf( YES );     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T, bool MIN>   struct ConvexHullTrickAddMonotone {     using Line = pair<T, T>;     deque<Line> deq;     inline bool check(const Line &a, const Line &b, const Line &c) {       return (b.first - a.first) * (c.second - b.second) >=              (b.second - a.second) * (c.first - b.first);     }     inline T f(const Line &a, const T x) { return a.first * x + a.second; }     void add_line(T a, T b) {       if (!MIN) a = -a, b = -b;       Line line(a, b);       if (deq.empty()) return (void)deq.emplace_back(line);       if (deq.front().first <= a) {         while (deq.size() >= 2 && check(line, deq.front(), deq[1]))           deq.pop_front();         deq.emplace_front(line);       } else {         while (deq.size() >= 2 && check(deq[deq.size() - 2], deq.back(), line))           deq.pop_back();         deq.emplace_back(line);       }     }     T query_monotone_inc(T x) {       while (deq.size() >= 2 && f(deq.front(), x) >= f(deq[1], x))         deq.pop_front();       T res = f(deq.front(), x);       return MIN ? res : -res;     }     T query_monotone_dec(T x) {       while (deq.size() >= 2 && f(deq.back(), x) >= f(deq[deq.size() - 2], x))         deq.pop_back();       T res = f(deq.back(), x);       return MIN ? res : -res;     }   };   const long long INF = 1LL << 60;   template <class T>   inline bool chmin(T &a, T b) {     if (a > b) {       a = b;       return 1;     }     return 0;   }   int main() {     int n, m;     cin >> n >> m;     int p;     cin >> p;     vector<int> d(n);     for (int i = 0; i < n - 1; i++) {       int x;       cin >> x;       d[i + 1] = d[i] + x;     }     vector<long long> x(m + 1);     for (int i = 0; i < m; i++) {       int h, t;       cin >> h >> t;       h--;       x[i + 1] = t - d[h] + 1e9;     }     sort(begin(x), end(x));     vector<vector<long long>> dp(p + 1, vector<long long>(m + 1, INF));     for (int i = 0; i <= p; i++) dp[i][0] = 0;     for (int i = 0; i < p; i++) {       ConvexHullTrickAddMonotone<long long, true> cht;       for (int j = 1; j <= m; j++) {         cht.add_line(-(j - 1), dp[i][j - 1]);         dp[i + 1][j] = cht.query_monotone_inc(x[j]) + x[j] * j;       }     }     long long ans = dp[p][m];     for (int i = 0; i <= m; i++) ans -= x[i];     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 1000000000000;   long long A, B, n, l, t, m, r;   bool check(long long len) {     long long sum = A + (B * (l - 1));     long long mx = A + (B * (len - 1));     if (mx <= t && mx + sum <= 2 * m * t / (len - l + 1))       return true;     else       return false;   }   long long BS(long long L, long long R) {     if (L > R) return r;     long long mid = L + R >> 1;     if (check(mid)) {       r = mid;       return BS(mid + 1, R);     } else       return BS(L, mid - 1);   }   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> A >> B >> n;     while (n--) {       cin >> l >> t >> m;       r = l - 1;       BS(l, INF);       if (r >= l)         cout << r <<   n ;       else         cout << -1 <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   void maxtt(T& t1, T t2) {     t1 = max(t1, t2);   }   template <typename T>   void mintt(T& t1, T t2) {     t1 = min(t1, t2);   }   bool debug = 0;   int n, m, k;   int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};   string direc =  URDL ;   const long long MOD2 = (long long)1000000007 * (long long)1000000007;   long long ln, lk, lm;   void etp(bool f = 0) {     puts(f ?  YES  :  NO );     exit(0);   }   void addmod(int& x, int y, int mod = 1000000007) {     x += y;     if (x >= mod) x -= mod;     if (x < 0) x += mod;     assert(x >= 0 && x < mod);   }   void et(int x = -1) {     printf( %d n , x);     exit(0);   }   long long fastPow(long long x, long long y, int mod = 1000000007) {     long long ans = 1;     while (y > 0) {       if (y & 1) ans = (x * ans) % mod;       x = x * x % mod;       y >>= 1;     }     return ans;   }   long long gcd1(long long x, long long y) { return y ? gcd1(y, x % y) : x; }   char s[3001335];   int id[3001335], cnt;   int mt[3001335];   inline vector<int> cal(int l, int r) {     vector<int> ans;     if (l + 2 == r) {       assert(s[l + 1] ==  * );       ans.push_back(id[l + 1]);       return ans;     }     bool fg = 1;     for (int i = l + 1; i < r;) {       vector<int> tmp = cal(i, mt[i]);       if (fg) {         if (tmp.size() > ans.size()) swap(ans, tmp);         for (int z : tmp) ans.push_back(z);       } else {         if (tmp.size() < ans.size()) swap(ans, tmp);       }       i = mt[i] + 1;       if (i < r) {         assert(s[i] ==  P  || s[i] ==  S );         if (s[i] ==  S ) fg = 0;         i++;       }     }     return ans;   }   void fmain(int tid) {     int r;     scanf( %d , &r);     n = 0;     cnt = 0;     while (1) {       char x = getchar();       if (x ==   n ) break;       if (x ==    ) continue;       if (x ==  * ) {         s[++n] =  ( ;         s[++n] =  * ;         id[n] = ++cnt;         s[++n] =  ) ;       } else         s[++n] = x;     }     vector<int> vp;     for (int(i) = 1; (i) <= (int)(n); (i)++) {       if (s[i] ==  ( )         vp.push_back(i);       else if (s[i] ==  ) ) {         int x = vp.back();         vp.pop_back();         mt[x] = i;         mt[i] = x;       }     }     vector<int> ans = cal(1, n);     vector<bool> vis(cnt + 1, 0);     for (int z : ans) vis[z] = 1;     printf( REVOLTING );     for (int(i) = 1; (i) <= (int)(cnt); (i)++)       if (vis[i]) {         printf(  %lld , (long long)r * ans.size());       } else         printf(  0 );     puts(  );   }   int main() {     int t = 1;     scanf( %d , &t);     for (int(i) = 1; (i) <= (int)(t); (i)++) {       fmain(i);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main(int argc, char** argv) {     int n, k;     scanf( %d %d , &n, &k);     if (k > n * 3) {       printf( %d , 0);     } else {       printf( %d , 3 * n - k);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline void read(int &x) {     int v = 0, f = 1;     char c = getchar();     while (!isdigit(c) && c !=  - ) c = getchar();     if (c ==  - )       f = -1;     else       v = (c & 15);     while (isdigit(c = getchar())) v = (v << 1) + (v << 3) + (c & 15);     x = v * f;   }   inline void read(long long &x) {     long long v = 0ll, f = 1ll;     char c = getchar();     while (!isdigit(c) && c !=  - ) c = getchar();     if (c ==  - )       f = -1;     else       v = (c & 15);     while (isdigit(c = getchar())) v = (v << 1) + (v << 3) + (c & 15);     x = v * f;   }   inline void readc(char &x) {     char c;     while (((c = getchar()) ==    ) || c ==   n )       ;     x = c;   }   inline void writes(string s) { puts(s.c_str()); }   inline void writeln() { writes(  ); }   inline void writei(int x) {     if (x < 0) {       putchar( - );       x = abs(x);     }     if (!x) putchar( 0 );     char a[25];     int top = 0;     while (x) {       a[++top] = (x % 10) +  0 ;       x /= 10;     }     while (top) {       putchar(a[top]);       top--;     }   }   inline void writell(long long x) {     if (x < 0) {       putchar( - );       x = abs(x);     }     if (!x) putchar( 0 );     char a[25];     int top = 0;     while (x) {       a[++top] = (x % 10) +  0 ;       x /= 10;     }     while (top) {       putchar(a[top]);       top--;     }   }   int n, m, k, i, j, f[3605][1805], g[3605][1805], c1[3605], c2[3605], s1, s2, x,       y, mod = 998244353, fac[3605], inv[3605], first[3605], ans;   int p(int x, int y) {     if (x < y) return 0;     return 1ll * fac[x] * first[x - y] % mod;   }   int main() {     fac[0] = fac[1] = inv[0] = inv[1] = first[0] = first[1] = 1;     for ((i) = (2); (i) <= (3600); (i)++) {       fac[i] = 1ll * fac[i - 1] * i % mod;       inv[i] = 1ll * (mod - mod / i) * inv[mod % i] % mod;       first[i] = 1ll * first[i - 1] * inv[i] % mod;     }     read(n);     read(m);     read(k);     for (((i)) = (1); ((i)) <= ((k)); ((i))++) {       read(x);       read(y);       int lx = x, ly = y;       if (++c1[x] > 1) {         puts( 0 );         return 0;       }       if (++c2[y] > 1) {         puts( 0 );         return 0;       }       read(x);       read(y);       if (lx != x && ++c1[x] > 1) {         puts( 0 );         return 0;       }       if (ly != y && ++c2[y] > 1) {         puts( 0 );         return 0;       }     }     c1[0] = c2[0] = 1;     f[0][0] = 1;     for (((i)) = (1); ((i)) <= ((n)); ((i))++) {       if (c1[i] == 0) s1++;       for ((j) = (0); (j) <= (i / 2); (j)++) {         f[i][j] = f[i - 1][j];         if (c1[i] == 0 && c1[i - 1] == 0) {           (f[i][j] += f[i - 2][j - 1]) %= mod;         }       }     }     g[0][0] = 1;     for (((i)) = (1); ((i)) <= ((m)); ((i))++) {       if (c2[i] == 0) s2++;       for ((j) = (0); (j) <= (i / 2); (j)++) {         g[i][j] = g[i - 1][j];         if (c2[i] == 0 && c2[i - 1] == 0) {           (g[i][j] += g[i - 2][j - 1]) %= mod;         }       }     }     for ((i) = (0); (i) <= (n / 2); (i)++)       for ((j) = (0); (j) <= (m / 2); (j)++) {         ans = (ans + 1ll * f[n][i] * g[m][j] % mod * p(s2 - 2 * j, i) % mod *                          p(s1 - 2 * i, j)) %               mod;       }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> v[188];   int dist[188][188];   int n, m;   int dp[188][188];   int best[188];   void dfs(int x, int p) {     for (int i = 0; i < v[x].size(); i++) {       int t = v[x][i];       if (t != p) dfs(t, x);     }     best[x] = 1;     for (int c = 1; c <= n; c++) {       for (int j = 0; j < v[x].size(); j++) {         int t = v[x][j];         if (t == p) continue;         dp[x][c] += min(dp[t][c], dp[t][best[t]] + m);       }       dp[x][c] += dist[x][c];       if (dp[x][c] < dp[x][best[x]]) best[x] = c;     }   }   int bel[188];   void process(int x, int p, int c) {     bel[x] = c;     for (int i = 0; i < v[x].size(); i++) {       int t = v[x][i];       if (t == p) continue;       if (dp[t][c] < dp[t][best[t]] + m)         process(t, x, c);       else         process(t, x, best[t]);     }   }   int cost[188];   int main() {     cin >> n >> m;     memset(dist, 0x3f, sizeof(dist));     for (int i = 1; i < n; i++) cin >> cost[i];     dist[1][1] = 0;     for (int i = 1; i < n; i++) {       dist[i + 1][i + 1] = 0;       int x, y;       scanf( %d%d , &x, &y);       dist[x][y] = dist[y][x] = 1;       v[x].push_back(y);       v[y].push_back(x);     }     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++)         for (int k = 1; k <= n; k++)           dist[j][k] = min(dist[j][i] + dist[i][k], dist[j][k]);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++) dist[i][j] = cost[dist[i][j]];     dfs(1, 0);     cout << dp[1][best[1]] + m <<   n ;     process(1, 0, best[1]);     for (int i = 1; i <= n; i++) cout << bel[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int32_t main() {     int n;     cin >> n;     if (n == 2) return cout << -1, 0;     cout <<  385 n21 n165 n ;     for (int i = 0; i < n - 3; i++) {       cout << 21 * (i + 100) << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   long long int binpowmod(long long int a, long long int b, long long int m) {     a %= m;     long long int res = 1;     while (b > 0) {       if (b & 1) res = res * a % m;       a = a * a % m;       b >>= 1;     }     return res;   }   unsigned long long modInverse(unsigned long long n, int p) {     return binpowmod(n, p - 2, p);   }   int main() {     long long int t, n, j, k, i, f, h, l, r, t1, t2, a, b, x, ans;     cin >> t;     while (t--) {       cin >> n;       string s;       cin >> s;       f = 0;       x = -1;       for (i = 0; i < n; ++i) {         if (s[i] ==  0 ) {           f = 1;           x = i + 1;           break;         }       }       if (f) {         if (x <= n / 2) {           cout << x <<     << n <<     << x + 1 <<     << n <<   n ;         } else {           cout << 1 <<     << x <<     << 1 <<     << x - 1 <<   n ;         }       } else         cout << 1 <<     << n / 2 <<     << ((n + 1) / 2) + 1 <<     << n <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     long long n;     cin >> n;     string s;     while (1) {       if (n % 7 == 0) {         n = n / 7;         for (long long i = 0; i < n; i++) s.push_back( 7 );         break;       } else {         if (n > 0) {           s.push_back( 4 );           n -= 4;         } else {           cout << -1;           return 0;         }       }     }     if (s.empty())       cout << -1;     else       cout << s;   }


#include <bits/stdc++.h>   using namespace std;   char s[1000050];   int max(int x, int y) { return (x > y) ? x : y; }   int main() {     scanf( %s , &s);     int len = strlen(s);     int cnt = 1, j;     int result = 1;     for (int i = len; i < 2 * len; i++) {       s[i] = s[i - len];     }     len = 2 * len;     for (int i = 0; i < len; i = j) {       for (j = i + 1; j < len; j++) {         if (s[j] == s[j - 1]) {           break;         }       }       result = max(result, j - i);     }     if (result > len / 2) {       result = len / 2;     }     printf( %d n , result);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     unsigned long long n, k;     cin >> n >> k;     unsigned long long r = 1, l = 0, num = n, mid;     for (int i = 0; i < n; i++) {       r <<= 1;     }     mid = (l + r) >> 1;     while (mid != k) {       --num;       if (mid > k)         r = mid;       else         l = mid;       mid = (l + r) >> 1;     }     cout << num;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   const long long MX = 2e5 + 5;   const long long INF = 1e18;   const long double PI = acos((long double)-1);   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long tc;     cin >> tc;     while (tc--) {       long long n, k;       bool imposs = false;       cin >> n >> k;       set<long long> powers;       for (int i = (1); i <= (n); i++) {         long long x;         cin >> x;         long long cnt = 0;         while (x) {           if (imposs) break;           long long a = x % k;           if (a > 1) imposs = true;           if (a && powers.count(cnt))             imposs = true;           else if (a)             powers.insert(cnt);           x /= k;           cnt++;           if (imposs) break;         }       }       if (imposs)         cout <<  NO n ;       else         cout <<  YES n ;     }   }


#include <bits/stdc++.h>   using namespace std;   #define int long long   #define pb push_back   #define mp make_pair   #define lb lower_bound   #define up upper_bound   #define sz(h) (int)h.size()   #define all(h) h.begin(), h.end()   #define mod 1000000007   #define mod1 998244353   #define MAX 2000010   #define cas(t) cout <<  Case #  << t <<  :  ;   struct hash_pair   { // use pair as key in unordered_map<pair<int,int>,int,hash_pair>;          template <class T1, class T2>          size_t operator()(const pair<T1, T2> &p) const          {              auto hash1 = hash<T1>{}(p.first);              auto hash2 = hash<T2>{}(p.second);              return hash1 ^ hash2;       }   };   signed main()   {       ios_base::sync_with_stdio(false);       cin.tie(NULL);   #ifndef ONLINE_JUDGE       //freopen( input.txt ,  r , stdin);       //freopen( output.txt ,  w , stdout);       //freopen( input.txt ,  w , stdout);   #endif       int tt = 1;       cin >> tt;       for (int t = 1; t <= tt; t++)       {           int a, b;           cin >> a >> b;           int u = 0;           int down = 0;           int left = 0;           int right = 0;           string s;           cin >> s;           for (auto i : s)           {               if (i ==  U )                   u++;               if (i ==  D )                   down++;               if (i ==  L )                   left++;               if (i ==  R )                   right++;           }           int fxl = -down;           int fxu = u;           int fyu = right;           int fyl = -left;           if (a <= fyu and fyl <= a and b <= fxu and b >= fxl)               cout <<  YES n ;           else               cout <<  NO n ;       }   }


#include <bits/stdc++.h>   using namespace std;   struct bottle {     int number;     double len;     double lento;     double diflen;   } a[100005], b[100005];   int cmp(bottle a, bottle b) {     if (a.diflen > b.diflen) return 1;     return 0;   }   int main() {     double x1, y1, x2, y2, c1, c2, x, y;     scanf( %lf %lf %lf %lf %lf %lf , &x1, &y1, &x2, &y2, &c1, &c2);     int n;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %lf %lf , &x, &y);       a[i].len = sqrt(pow(x1 - x, 2) + pow(y1 - y, 2));       b[i].len = sqrt(pow(x2 - x, 2) + pow(y2 - y, 2));       a[i].lento = sqrt(pow(x - c1, 2) + pow(y - c2, 2));       b[i].lento = sqrt(pow(x - c1, 2) + pow(y - c2, 2));       a[i].diflen = a[i].lento - a[i].len;       b[i].diflen = b[i].lento - b[i].len;       a[i].number = i;       b[i].number = i;     }     sort(a, a + n, cmp);     sort(b, b + n, cmp);     double length = a[0].len + b[0].len + a[0].lento + b[0].lento;     int mark1 = a[0].number, mark2 = b[0].number;     if (a[0].diflen < 0 || b[0].diflen < 0) {       if (a[0].diflen > b[0].diflen) {         mark2 = -1;         length = a[0].len + a[0].lento;       } else {         mark1 = -1;         length = b[0].len + b[0].lento;       }     }     if (a[0].number == b[0].number && mark1 != -1 && mark2 != -1) {       if (a[1].diflen < 0 || b[1].diflen < 0) {         if (a[1].diflen < 0 && b[1].diflen < 0) {           if (a[0].diflen > b[0].diflen) {             mark2 = -1;             mark1 = a[0].number;             length = a[0].len + a[0].lento;           } else {             mark1 = -1;             mark2 = b[0].number;             length = b[0].len + b[0].lento;           }         } else if (a[1].diflen < 0) {           if ((a[0].diflen + b[1].diflen) > b[0].diflen) {             mark1 = a[0].number;             mark2 = b[1].number;             length = a[0].len + b[1].len + a[0].lento + b[1].lento;           } else {             mark1 = -1;             mark2 = b[0].number;             length = b[0].len + b[0].lento;           }         } else if (b[1].diflen < 0) {           if ((b[0].diflen + a[1].diflen) > a[0].diflen) {             mark1 = a[1].number;             mark2 = b[0].number;             length = a[1].len + b[0].len + a[1].lento + b[0].lento;           } else {             mark1 = a[0].number;             mark2 = -1;             length = a[0].len + a[0].lento;           }         }       } else if ((a[0].diflen + b[1].diflen) > (a[1].diflen + b[0].diflen)) {         length = a[0].len + b[1].len + a[0].lento + b[1].lento;         mark1 = a[0].number;         mark2 = b[1].number;       } else {         length = a[1].len + b[0].len + a[1].lento + b[0].lento;         mark1 = a[1].number;         mark2 = b[0].number;       }     }     for (int i = 0; i < n; i++) {       if (a[i].number != mark1 && a[i].number != mark2) {         length += a[i].lento * 2;       }     }     printf( %.12lf n , length);   }


#include <bits/stdc++.h>   using namespace std;   vector<int> d;   int countDivisors(int n) {     if (d[n] != 0) return d[n];     int res = 0;     for (int i = 1; i * i <= n; i++) {       if (n % i == 0) {         if (n / i == i)           res++;         else           res += 2;       }     }     d[n] = res;     return res;   }   void solve() {     int a, b, c;     cin >> a >> b >> c;     d = vector<int>(a * b * c + 1, 0);     int ans = 0;     for (auto i = (1); i < (a + 1); i++)       for (auto j = (1); j < (b + 1); j++)         for (auto k = (1); k < (c + 1); k++) ans += countDivisors(i * j * k);     cout << ans % 1073741824 <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t = 1;     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long a, b, m, ans = 0;     scanf( %I64d%I64d%I64d , &a, &b, &m);     if (a >= m || b >= m)       printf( 0 n );     else if (a <= 0 && b <= 0)       printf( -1 n );     else {       if (a < 0 || b < 0) {         if (a > b) swap(a, b);         ans = -a / b;         a += b * ans;       }       while (a < m && b < m) {         if (a > b) swap(a, b);         ans++;         a += b;       }       printf( %I64d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   void chkMax(T &x, T y) {     if (y > x) x = y;   }   template <typename T>   void chkMin(T &x, T y) {     if (y < x) x = y;   }   template <typename T>   void inline read(T &x) {     int f = 1;     x = 0;     char s = getchar();     while (s <  0  || s >  9 ) {       if (s ==  - ) f = -1;       s = getchar();     }     while (s <=  9  && s >=  0 ) x = x * 10 + (s ^ 48), s = getchar();     x *= f;   }   const int N = 55;   int n;   struct E {     int a, b;   } e[N];   bool operator<(const E &x, const E &y) {     if (x.a == y.a) return x.b > y.b;     return x.a > y.a;   };   long double f[N], g[N], s[N];   bool inline chk(long double mid) {     for (int i = 1; i <= n; i++) f[i] = -9e18;     for (int i = 1; i <= n; i++) {       s[i] = s[i - 1] + e[i].b * mid - e[i].a;     }     f[0] = 0;     for (int i = 1; i <= n; i++) {       int j = i;       while (j < n && e[j + 1].a == e[i].a) j++;       memcpy(g, f, sizeof f);       for (int j = 0; j <= n; j++) f[j] = -9e18;       int l = j - i + 1;       for (int j = 0; j <= n; j++) {         if (g[j] <= -9e18) continue;         for (int k = 0; k <= l; k++) {           int re = l - k;           if (re > j) continue;           chkMax(f[j - re + k], g[j] + s[i + k - 1] - s[i - 1]);         }       }       i = j;     }     for (int i = 0; i <= n; i++) {       if (f[i] >= 0) return 1;     }     return 0;   }   int main() {     read(n);     for (int i = 1; i <= n; i++) read(e[i].a);     for (int i = 1; i <= n; i++) read(e[i].b);     sort(e + 1, e + 1 + n);     long double l = 0, r = 1e8, eps = 1e-10;     while (r - l > eps) {       long double mid = (l + r) / 2;       if (chk(mid))         r = mid;       else         l = mid;     }     printf( %lld n , (long long)(r * 1000 + 0.99999));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 5;   int n, m;   unsigned long long A, B, C;   struct E {     int u, v;     E(int u, int v) : u(u), v(v) {}   };   struct Graph {     int n, m, deg[maxn], cur[maxn];     unsigned long long hash_[maxn];     vector<E> edge;     vector<int> small[maxn], large[maxn];     vector<int> G[maxn];     void init(int n) {       this->n = n, m = 0;       edge.clear();       for (int i = 0; i < n; ++i) {         small[i].clear();         large[i].clear();         G[i].clear();       }     }     void add_edge(int u, int v) {       if (u > v) swap(u, v);       edge.push_back(E(u, v));       G[u].push_back(v);       G[v].push_back(u);       small[v].push_back(u);       large[u].push_back(v);       hash_[m++] = (unsigned long long)u * n + v;     }     unsigned long long sum0() {       unsigned long long s = 0;       for (int i = 0; i < n; ++i) {         s += A * i * ((unsigned long long)(n - 1 - i) * (n - 2 - i) / 2);         s += B * i * i * (n - 1 - i);         s += C * i * ((unsigned long long)i * (i - 1) / 2);       }       return s;     }     unsigned long long sum1() {       unsigned long long s = 0;       for (E e : edge) {         int u = e.u, v = e.v;         s += A * ((unsigned long long)u * (u - 1) / 2) + B * u * u + C * v * u;         s += A * u * (v - u - 1) +              B * ((unsigned long long)(u + v) * (v - u - 1) / 2) +              C * v * (v - u - 1);         s += A * u * (n - 1 - v) + B * v * (n - 1 - v) +              C * ((unsigned long long)(n + v) * (n - 1 - v) / 2);       }       return s;     }     unsigned long long sum2() {       for (int i = 0; i < n; ++i) {         sort(small[i].begin(), small[i].end());         sort(large[i].begin(), large[i].end());       }       unsigned long long s = 0;       for (int i = 0; i < n; ++i) {         unsigned long long scnt = small[i].size();         unsigned long long lcnt = large[i].size();         s += A * i * ((unsigned long long)lcnt * (lcnt - 1) / 2);         for (int j = 0; j < lcnt; ++j)           s += large[i][j] * (B * (lcnt - 1 - j) + C * j);         s += B * i * scnt * lcnt;         for (int j = 0; j < scnt; ++j) s += small[i][j] * A * lcnt;         for (int j = 0; j < lcnt; ++j) s += large[i][j] * C * scnt;         s += C * i * ((unsigned long long)scnt * (scnt - 1) / 2);         for (int j = 0; j < scnt; ++j)           s += small[i][j] * (A * (scnt - 1 - j) + B * j);       }       return s;     }     unsigned long long sum3() {       sort(hash_, hash_ + m);       hash_[m] = -1;       for (int i = 0; i < n; ++i) deg[i] = G[i].size();       unsigned long long s = 0;       for (int i = 0; i < n; ++i) {         int sz = 0;         for (int v : G[i])           if (deg[v] > deg[i] || (deg[v] == deg[i] && v > i)) cur[sz++] = v;         sort(cur, cur + sz);         int l = 0;         for (int j = 0; j < sz; ++j)           for (int k = j + 1; k < sz; ++k) {             int u = cur[j], v = cur[k];             unsigned long long hash = (unsigned long long)u * n + v;             int pos = lower_bound(hash_ + l, hash_ + m, hash) - hash_;             l = pos;             if (hash_[pos] == hash) s += fun(i, u, v);           }       }       return s;     }     unsigned long long sum() { return sum0() - sum1() + sum2() - sum3(); }     unsigned long long fun(int a, int b, int c) {       int mx = max(a, c);       int mn = min(a, b);       return B * (a + b + c) + (A - B) * mn + (C - B) * mx;     }   } graph;   int main(void) {     while (~scanf( %d%d , &n, &m)) {       scanf( %llu%llu%llu , &A, &B, &C);       graph.init(n);       for (int i = 0; i < m; ++i) {         int u, v;         scanf( %d%d , &u, &v);         graph.add_edge(u, v);       }       printf( %llu n , graph.sum());     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using namespace std;   long long m = 33554431;   long long bigmod(long long b, long long p) {     if (p == 0) return 1;     if (p % 2 == 0) {       long long temp = bigmod(b, p / 2);       return (temp * temp) % m;     }     return (bigmod(b, p - 1) * (b % m)) % m;   }   bool XX(pair<int, double> a, pair<int, double> b) {     return a.second < b.second;   }   int main() {     int n, m;     cin >> n >> m;     vector<pair<int, double> > vec(n);     for (int i = 0; i < n; i++) {       scanf( %d %lf , &vec[i].first, &vec[i].second);     }     sort(vec.begin(), vec.end(), XX);     vector<int> ans;     for (int i = 0; i < n; i++) {       if (ans.empty() || ans.back() <= vec[i].first)         ans.push_back(vec[i].first);       else         *upper_bound(ans.begin(), ans.end(), vec[i].first) = vec[i].first;     }     cout << n - ans.size() << endl;     return 0;   }


//begin #include <Core>   /*    * Package: StandardCodeLibrary.Core    * Last Update: 2012-12-21    * */   #include <iostream>   #include <fstream>   #include <sstream>   #include <iomanip>   #include <utility>   #include <vector>   #include <list>   #include <string>   #include <stack>   #include <queue>   #include <deque>   #include <set>   #include <map>   #include <algorithm>   #include <functional>   #include <numeric>   #include <bitset>   #include <complex>   #include <cstdio>   #include <cstring>   #include <cmath>   #include <cstdlib>   #include <ctime>   #include <climits>   #if __GNUC__>=4 and __GNUC_MINOR__>=6    #include <ext/pb_ds/assoc_container.hpp>    #include <ext/pb_ds/tree_policy.hpp>    #include <ext/pb_ds/tag_and_trait.hpp>   #endif   using namespace std;      #define lp for(;;)   #define repf(i,a,b) for (int i=(a);i<(b);++i)   #define rep(i,n) repf(i,0,n)   #define ft(i,a,b) for (int i=(a);i<=(b);++i)   #define fdt(i,a,b) for (int i=(a);i>=b;--i)   #define feach(e,s) for (typeof((s).begin()) e=(s).begin();e!=(s).end();++e)   #define fsubset(subset,set) for (int subset=set&(set-1);subset;subset=(subset-1)&set)   #define forin(i,charset) for (cstr i=charset;*i;i++)   #define whl while   #define rtn return   #define fl(x,y) memset((x),char(y),sizeof(x))   #define clr(x) fl(x,char(0))   #define cpy(x,y) memcpy(x,y,sizeof(x))   #define pb push_back   #define mp make_pair   #define ins insert   #define rnk order_of_key   #define sel find_by_order   #define x first   #define y second   #define sz(x) (int((x).size()))   #define all(x) (x).begin(),(x).end()   #define srt(x) sort(all(x))   #define uniq(x) srt(x),(x).erase(unique(all(x)),x.end())   #define vec vector   #define pr pair   #define que queue   #define prq priority_queue   #define itr iterator   #define sf scanf   #define pf printf   #define pdb(prcs,x) (cout<<setprecision(prcs)<<fixed<<(x))   #ifdef DEBUG   #define prt(x) cerr<<#x = <<(x)<<endl   #define asrtWA(s) do if(!(s))do{cerr<< assert( #s ) <<endl;}whl(0);whl(0)   #define asrtTLE(s) do if(!(s))do{cerr<< assert( #s ) <<endl;}whl(0);whl(0)   #define asrtMLE(s) do if(!(s))do{cerr<< assert( #s ) <<endl;}whl(0);whl(0)   #define asrtOLE(s) do if(!(s))do{cerr<< assert( #s ) <<endl;}whl(0);whl(0)   #define asrtRE(s) do if(!(s))do{cerr<< assert( #s ) <<endl;}whl(0);whl(0)   #define runtime() cerr<< Used:  <<db(clock())/CLOCKS_PER_SEC<< s <<endl   #define input(in) do{}whl(0)   #define output(out) do{}whl(0)   #else   #define endl (char(  n ))   #define prt(x) (cerr)   #define asrtWA(s) do if(!(s))exit(0);whl(0)   #define asrtTLE(s) do if(!(s))whl(1);whl(0)   #define asrtMLE(s) do if(!(s))whl(new int);whl(0)   #define asrtOLE(s) do if(!(s))whl(1)puts( OLE );whl(0)   #define asrtRE(s) do if(!(s))*(int*)0=0;whl(0)   #define runtime() cerr   #define input(in) freopen(in, r ,stdin)   #define output(out) freopen(out, w ,stdout)   #endif      typedef long long int lli;   typedef double db;   typedef const char* cstr;   typedef string str;   typedef vec<int> vi;   typedef vec<vi> vvi;   typedef vec<bool> vb;   typedef vec<vb> vvb;   typedef vec<str> vs;   typedef pr<int,int> pii;   typedef pr<lli,lli> pll;   typedef pr<db,db> pdd;   typedef pr<str,int> psi;   typedef map<int,int> mii;   typedef map<str,int> msi;   typedef map<char,int> mci;   typedef set<int> si;   typedef set<str> ss;   typedef que<int> qi;   typedef prq<int> pqi;   #if __GNUC__>=4 and __GNUC_MINOR__>=7    template<typename key,typename value>class ext_map:public __gnu_pbds::tree<key,value,less<key>,__gnu_pbds::rb_tree_tag,__gnu_pbds::tree_order_statistics_node_update>{};    template<typename key>class ext_set:public __gnu_pbds::tree<key,__gnu_pbds::null_type,less<key>,__gnu_pbds::rb_tree_tag,__gnu_pbds::tree_order_statistics_node_update>{};   #elif __GNUC__>=4 and __GNUC_MINOR__>=6    template<typename key,typename value>class ext_map:public __gnu_pbds::tree<key,value,less<key>,__gnu_pbds::rb_tree_tag,__gnu_pbds::tree_order_statistics_node_update>{};    template<typename key>class ext_set:public __gnu_pbds::tree<key,__gnu_pbds::null_mapped_type,less<key>,__gnu_pbds::rb_tree_tag,__gnu_pbds::tree_order_statistics_node_update>{};   #endif      const int oo=(~0u)>>1;   const lli ooll=(~0ull)>>1;   const db inf=1e+10;   const db eps=1e-10;   const db pi=acos(-1.0);   const int MOD=1000000007;      template<typename type>inline bool cmax(type& a,const type& b){rtn a<b?a=b,true:false;}   template<typename type>inline bool cmin(type& a,const type& b){rtn b<a?a=b,true:false;}   template<typename type>inline type sqr(const type& x){rtn x*x;}   inline int dbcmp(const db& a,const db& b){rtn (a>b+eps)-(a<b-eps);}   inline int sgn(const db& x){rtn dbcmp(x,0);}   template<typename ostream,typename type>ostream& operator<<(ostream& cout,const pr<type,type>& x){rtn cout<< ( <<x.x<< , <<x.y<< ) ;}   template<typename type>pr<type,type> operator-(const pr<type,type>& x){rtn mp(-x.x,-x.y);}   template<typename type>pr<type,type> operator+(const pr<type,type>& a,const pr<type,type>& b){rtn mp(a.x+b.x,a.y+b.y);}   template<typename type>pr<type,type> operator-(const pr<type,type>& a,const pr<type,type>& b){rtn mp(a.x-b.x,a.y-b.y);}   template<typename type>inline type cross(const pr<type,type>& a,const pr<type,type>& b,const pr<type,type>& c){rtn (b.x-a.x)*(c.y-a.y)-(b.y-a.y)*(c.x-a.x);}   template<typename type>inline type dot(const pr<type,type>& a,const pr<type,type>& b,const pr<type,type>& c){rtn (b.x-a.x)*(c.x-a.x)+(b.y-a.y)*(c.y-a.y);}   template<typename type>inline type gcd(type a,type b){if(b)whl((a%=b)&&(b%=a));rtn a+b;}   template<typename type>inline type lcm(type a,type b){rtn a*b/gcd(a,b);}   template<typename type>inline void bit_inc(vec<type>& st,int x,type inc){whl(x<sz(st))st[x]+=inc,x|=x+1;}   template<typename type>inline type bit_sum(const vec<type>& st,int x){type s=0;whl(x>=0)s+=st[x],x=(x&(x+1))-1;rtn s;}   template<typename type>inline type bit_kth(const vec<type>& st,int k){int x=0,y=0,z=0;whl((1<<(++y))<=sz(st));fdt(i,y-1,0){if((x+=1<<i)>sz(st)||z+st[x-1]>k)x-=1<<i;else z+=st[x-1];}rtn x;}   inline void make_set(vi& st){rep(i,sz(st))st[i]=i;}   inline int find_set(vi& st,int x){int y=x,z;whl(y!=st[y])y=st[y];whl(x!=st[x])z=st[x],st[x]=y,x=z;rtn y;}   inline bool union_set(vi& st,int a,int b){a=find_set(st,a),b=find_set(st,b);rtn a!=b?st[a]=b,true:false;}   template<typename type>inline void merge(type& a,type& b){if(sz(a)<sz(b))swap(a,b);whl(sz(b))a.insert(*b.begin()),b.erase(b.begin());}   template<typename type>inline void merge(prq<type>& a,prq<type>& b){if(sz(a)<sz(b))swap(a,b);whl(sz(b))a.push(b.top()),b.pop();}      struct Initializer{Initializer(){ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);}~Initializer(){runtime();}}initializer;   //end #include <Core>      #define idx(l,r) (((l)+(r))|((l)!=(r)))   #define rt idx(l,r)   #define lrt idx(l,m)   #define rrt idx(m+1,r)   const int MAXN=100000;   struct node   {    int cnt,size;    lli sum[5];   };   int a[MAXN];   mii idx;   node st[(MAXN<<1)-1];   void upd(int l,int r,int p,int v)   {    if (p<l||r<p) ;    else if (p<=l&&r<=p)    {     st[rt].cnt+=v;     if (st[rt].cnt)     {      st[rt].size=1;      rep(i,5) st[rt].sum[i]=0;      st[rt].sum[0]=a[p];     }     else     {      st[rt].size=0;      rep(i,5) st[rt].sum[i]=0;     }    }    else    {     int m=(l+r)>>1;     upd(l,m,p,v),upd(m+1,r,p,v);     st[rt].size=st[lrt].size+st[rrt].size;     rep(i,5) st[rt].sum[i]=st[lrt].sum[i];     rep(i,5) st[rt].sum[(st[lrt].size+i)%5]+=st[rrt].sum[i];    }   }   lli qry(int l,int r)   {    rtn l<=r?st[rt].sum[2]:0;   }   #undef rc   #undef lc   #undef p   #undef idx      str op[MAXN];   int opx[MAXN];   int opxcpy[MAXN];      int main()   {    int n;    cin>>n;    rep(i,n)    {     cin>>op[i];     if (op[i]!= sum ) cin>>opx[i];    }    cpy(opxcpy,opx);    sort(opxcpy,opxcpy+n);    rep(i,n) if (!idx.count(opxcpy[i])) idx.insert(mp(a[sz(idx)]=opxcpy[i],sz(idx)));    rep(i,n)    {     if (op[i]== add ) upd(0,sz(idx)-1,idx[opx[i]],+1);     else if (op[i]== del ) upd(0,sz(idx)-1,idx[opx[i]],-1);     else cout<<qry(0,sz(idx)-1)<<endl;    }   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 200005;   pair<int, int> a[MAX];   int bin_Upper(vector<pair<int, int> >& a, int l, int r, int x, int last) {     int m = (l + r) / 2;     if (l > r) return last;     if (x > a[m].second) return bin_Upper(a, m + 1, r, x, last);     if (x <= a[m].second) return bin_Upper(a, l, m - 1, x, m);   }   int main() {     int n, q, cmd, p, x;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i].first;       a[i].second = 0;     }     cin >> q;     vector<pair<int, int> > stak;     for (int k = 1; k <= q; k++) {       cin >> cmd;       if (cmd == 1) {         cin >> p >> x;         a[p - 1] = {x, k};       } else {         cin >> x;         while (!stak.empty() && stak.back().first <= x) stak.pop_back();         stak.push_back({x, k});       }     }     for (int i = 0; i < n; i++) {       int temp = bin_Upper(stak, 0, stak.size() - 1, a[i].second, -1);       if (temp == -1 || stak[temp].first <= a[i].first)         cout << a[i].first <<    ;       else         cout << stak[temp].first <<    ;     }     return 0;   }


#include <bits/stdc++.h>   int max(int a, int b) { return a > b ? a : b; }   long long int min(long long int a, long long int b) { return a < b ? a : b; }   int main() {     using namespace std;     int t, a, b;     cin >> t;     while (t--) {       cin >> a >> b;       cout << min(min(a, b), (a + b) / 3) << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     while (n--) {       string s;       cin >> s;       while (s.size() && s[0] ==  0 ) {         s.erase(s.begin());       }       while (s.size() && s[(int)s.size() - 1] ==  0 ) {         s.erase(s.begin() + (int)s.size() - 1);       }       int cnt = 0;       for (auto x : s) cnt += (x ==  0 );       cout << cnt << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char pic[105][105];   int vis[105][105];   int disx[] = {-1, 1, 0, 0};   int disy[] = {0, 0, -1, 1};   struct node {     int ro, lo, len;     node() {}     node(int rr, int ll, int le) {       ro = rr;       lo = ll;       len = le;     }   };   int main() {     int n, m;     cin >> n >> m;     vector<node> ve;     for (int i = 0; i < n; i++) cin >> pic[i];     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (pic[i][j] ==  * ) {           int tot = 105, cnt;           for (int k = 0; k < 4; k++) {             cnt = 0;             for (int h = 1; h <= n; h++) {               int xx = i + disx[k] * h;               int yy = j + disy[k] * h;               if (xx >= 0 && xx < n && yy >= 0 && yy < m && pic[xx][yy] ==  * ) {                 cnt++;               } else                 break;             }             if (cnt != 0)               tot = min(tot, cnt);             else {               tot = 105;               break;             }           }           if (tot != 105) {             for (int k = 0; k < 4; k++) {               for (int h = 1; h <= tot; h++) {                 int xx = i + disx[k] * h;                 int yy = j + disy[k] * h;                 if (xx >= 0 && xx < n && yy >= 0 && yy < m && pic[xx][yy] ==  * )                   vis[xx][yy]++;               }             }             vis[i][j]++;             ve.push_back(node(i + 1, j + 1, tot));           }         }       }     }     bool flag = true;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (pic[i][j] ==  * ) {           if (vis[i][j] == 0) {             flag = false;             break;           }         }       }       if (!flag) break;     }     if (!flag)       cout << -1 << endl;     else {       cout << ve.size() << endl;       for (int i = 0; i < ve.size(); i++) {         cout << ve[i].ro <<     << ve[i].lo <<     << ve[i].len << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, x, y;     cin >> n >> m;     pair<int, pair<int, int> > arr[n];     int arr1[n], arr2[n];     for (int i = 0; i < n; ++i) cin >> arr1[i];     for (int i = 0; i < n; ++i) cin >> arr2[i];     for (int i = 0; i < n; ++i) {       arr[i].second.first = arr1[i];       arr[i].second.second = arr2[i];       arr[i].first = arr[i].second.first - arr[i].second.second;     }     sort(arr, arr + n);     long long sum = 0;     if (n == m) {       for (int i = 0; i < n; ++i) sum += arr[i].second.first;       cout << sum << endl;       return 0;     }     for (int i = 0; i < n; ++i) {       if (m > 0) {         sum += arr[i].second.first;         --m;       } else {         if (arr[i].second.first > arr[i].second.second)           sum += arr[i].second.second;         else           sum += arr[i].second.first;       }     }     cout << sum << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long double eps = 1e-9;   const int inf = (1 << 30) - 1;   int n, m, it;   bool a[250][250];   int u[250][250], lx, ly, rx, ry, k;   const int dx[8] = {-1, -1, -1, 0, 0, 1, 1, 1};   const int dy[8] = {-1, 0, 1, -1, 1, -1, 0, 1};   void go(int vx, int vy) {     if (u[vx][vy]) return;     u[vx][vy] = it;     lx = min(lx, vx);     rx = max(rx, vx);     ly = min(ly, vy);     ry = max(ry, vy);     ++k;     for (int i = 0; i < 8; ++i) {       int x = vx + dx[i];       int y = vy + dy[i];       if (0 <= x && x < n && 0 <= y && y < m)         if (a[x][y] == 1) go(x, y);     }   }   bool check1(int x, int y) {     if (k < 4) return 0;     if (rx - lx != ry - ly) return 0;     int tmp = 0;     for (int i = lx; i <= rx; ++i) {       if (!u[i][ly] || !u[i][ry]) return 0;       tmp += 2;     }     for (int i = ly + 1; i < ry; ++i) {       if (!u[lx][i] || !u[rx][i]) return 0;       tmp += 2;     }     if (tmp == k)       return 1;     else       return 0;   }   bool check2(int x, int y) {     if (k < 4) return 0;     if (rx - lx != ry - ly) return 0;     if (ry - y != y - ly) return 0;     int tmp = 0;     int x1 = x;     int y1 = y;     int x2 = lx + y - ly;     int y2 = ly;     for (int i = 0; i <= y - ly; ++i) {       if (!u[x1 + i][y1 + i] || !u[x2 + i][y2 + i]) return 0;       tmp += 2;     }     tmp -= 4;     x1 = x2;     y1 = y2;     x2 = rx;     y2 = y;     for (int i = 0; i <= y - ly; ++i) {       if (!u[x1 - i][y1 + i] || !u[x2 - i][y2 + i]) return 0;       tmp += 2;     }     if (tmp == k)       return 1;     else       return 0;   }   void Work() {     scanf( %d%d , &n, &m);     for (int i = 0; i < n; ++i)       for (int j = 0; j < m; ++j) {         char ch;         scanf(  %c , &ch);         a[i][j] = ch ==  1 ;       }     for (int i = 0; i < n; ++i)       for (int j = 0; j < m; ++j) u[i][j] = 0;     it = 0;     int res = 0;     for (int i = 0; i < n; ++i)       for (int j = 0; j < m; ++j)         if (a[i][j] && !u[i][j]) {           k = 0;           ++it;           lx = rx = i;           ly = ry = j;           go(i, j);           if (check1(i, j) || check2(i, j)) ++res;         }     printf( %d n , res);   }   int main() {     int T;     scanf( %d , &T);     while (T--) Work();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long vp(pair<int, int> a, pair<int, int> b) {     return (long long)a.first * b.second - (long long)a.second * b.first;   }   pair<int, int> mn(pair<int, int> a, pair<int, int> b) {     return make_pair(a.first - b.first, a.second - b.second);   }   int main() {     srand(239);     int n, m;     scanf( %d %d , &n, &m);     if (m == 3) {       if (n > 4) {         printf( -1 n );         return 0;       }       if (n == 3) {         printf( 0 0 n0 1 n1 0 n );         return 0;       }       if (n == 4) {         printf( 0 0 n0 3 n3 0 n1 1 n );         return 0;       }       assert(false);     }     int R1 = 1e7;     int R2 = 2e7;     vector<pair<int, int> > v;     for (int i = 0; i < m; i++) {       v.push_back(           make_pair(R1 * cos(M_PI * 2 * i / m), R1 * sin(M_PI * 2 * i / m)));       if (i < n - m)         v.push_back(make_pair(R2 * cos(M_PI * 2 * i / m + M_PI * 0.0001),                               R2 * sin(M_PI * 2 * i / m + M_PI * 0.0001)));     }     while (1) {       bool good = true;       for (int i = 0; i < n; i++) {         for (int j = i + 1; j < n; j++) {           for (int k = j + 1; k < n; k++) {             if (vp(mn(v[i], v[k]), mn(v[j], v[k])) == 0) {               v[k].first += rand() % 10;               v[k].second += rand() % 10;               good = false;             }           }         }       }       if (good) break;     }     assert((int)(v).size() == n);     for (int i = 0; i < n; i++) {       printf( %d %d n , v[i].first, v[i].second);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, x = 0, y;     cin >> n;     y = n * n / 2.0 + n / 2.0;     cout << 6 * y + 1;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<long long> data;   long long a, b, h, w, n, t, minVal;   inline void swap(int &a, int &b) {     int tmp = a;     a = b;     b = tmp;   }   inline int mini(int a, int b) { return a < b ? a : b; }   bool cmp(long long a, long long b) { return a > b; }   int dfs(int crt, long long th, long long tw) {     if (th >= a && tw >= b || th >= b && tw >= a) return crt;     if (crt >= 34 || crt >= data.size()) return -1;     if (data[crt] == minVal) {       while (th < a) {         th *= minVal;         crt++;       }       while (tw < b) {         tw *= minVal;         crt++;       }       return crt <= data.size() ? crt : -1;     } else {       int reta = 0, retb = 0;       if (th < 100000) reta = dfs(crt + 1, th * data[crt], tw);       if (tw < 100000) retb = dfs(crt + 1, th, tw * data[crt]);       if (reta <= 0 && retb <= 0) return -1;       if (reta <= 0) return retb;       if (retb <= 0) return reta;       return mini(reta, retb);     }   }   int main(void) {     ios::sync_with_stdio(false);     cin.tie(NULL);     cin >> a >> b >> h >> w >> n;     if (a > b) swap(a, b);     if (h > w) swap(h, w);     if (h >= a && w >= b) {       printf( 0 n );       return 0;     }     for (int i = 0; i < n; i++) {       cin >> t;       data.push_back(t);     }     sort(data.begin(), data.end(), cmp);     minVal = data[mini(33, data.size() - 1)];     printf( %d n , mini(dfs(0, h, w), dfs(0, w, h)));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename A, typename B>   string to_string(pair<A, B> p);   template <typename A, typename B, typename C>   string to_string(tuple<A, B, C> p);   template <typename A, typename B, typename C, typename D>   string to_string(tuple<A, B, C, D> p);   string to_string(const string &s) { return     + s +    ; }   string to_string(const char *s) { return to_string((string)s); }   string to_string(bool b) { return (b ?  true  :  false ); }   string to_string(vector<bool> v) {     bool first = true;     string res =  { ;     for (int i = 0; i < static_cast<int>(v.size()); i++) {       if (!first) {         res +=  ,  ;       }       first = false;       res += to_string(v[i]);     }     res +=  } ;     return res;   }   template <size_t N>   string to_string(bitset<N> v) {     string res =   ;     for (size_t i = 0; i < N; i++) {       res += static_cast<char>( 0  + v[i]);     }     return res;   }   template <typename A>   string to_string(A v) {     bool first = true;     string res =  { ;     for (const auto &x : v) {       if (!first) {         res +=  ,  ;       }       first = false;       res += to_string(x);     }     res +=  } ;     return res;   }   class xxx {    public:     xxx(int x) : i(x) {}     int i;     void operator()() const { cout << i << endl; }   };   template <typename A, typename B>   string to_string(pair<A, B> p) {     return  (  + to_string(p.first) +  ,   + to_string(p.second) +  ) ;   }   template <typename A, typename B, typename C>   string to_string(tuple<A, B, C> p) {     return  (  + to_string(get<0>(p)) +  ,   + to_string(get<1>(p)) +  ,   +            to_string(get<2>(p)) +  ) ;   }   template <typename A, typename B, typename C, typename D>   string to_string(tuple<A, B, C, D> p) {     return  (  + to_string(get<0>(p)) +  ,   + to_string(get<1>(p)) +  ,   +            to_string(get<2>(p)) +  ,   + to_string(get<3>(p)) +  ) ;   }   void debug_out() { cerr << endl; }   template <typename Head, typename... Tail>   void debug_out(Head H, Tail... T) {     cerr <<     << to_string(H);     debug_out(T...);   }   const long long mod = 1e9 + 7;   inline long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   class RMQ {    public:     std::vector<long long> v;     vector<vector<long long>> f;     RMQ(vector<long long> &t) {       v = t;       build();     }     void build() {       int n = v.size();       int level = log(n) / log(2) + 1;       f = vector<vector<long long>>(n, vector<long long>(level, 0));       for (int i = 0; i < n; ++i) f[i][0] = v[i];       for (int i = 1; i < level; ++i) {         for (int j = 0; j <= n - (1 << i); ++j) {           f[j][i] = gcd(f[j][i - 1], f[j + (1 << i - 1)][i - 1]);         }       }     }     long long query(int l, int r) {       int k = log(r - l + 1) / log(2);       return gcd(f[l][k], f[r - (1 << k) + 1][k]);     }   };   const long long INF = LLONG_MAX;   const int maxn = 2e5 + 5;   long long n, m;   long long sums = 0;   int k;   void read1() {}   void solve() {     int X, d;     cin >> X >> d;     vector<long long> res;     long long num = 1;     for (int i = 31; i >= 0; --i) {       if (((X >> i) & 1)) {         for (int j = 0; j < i; ++j) res.push_back(num);         res.push_back(num + d);         num += 2 * d;       }     }     cout << res.size() << endl;     for (auto x : res) cout << x <<    ;     cout << endl;   }   int main() {     std::ios::sync_with_stdio(false);     cin.tie(0);     int tests = 1;     for (int tc = 1; tc <= tests; tc++) {       solve();       cout << flush;     }     return 0;   }   int _, __;