#include <bits/stdc++.h>   using namespace std;   long long max(long long a, long long b) { return a > b ? a : b; }   long long min(long long a, long long b) { return a < b ? a : b; }   void fun(int arr[], int n) {     stack<int> s;     int left[n + 1];     int right[n + 1];     for (int i = 0; i < n; i++) {       left[i] = -1;       right[i] = n;     }     for (int i = 0; i < n; i++) {       while (!s.empty() && arr[s.top()] >= arr[i]) s.pop();       if (!s.empty()) left[i] = s.top();       s.push(i);     }     while (!s.empty()) s.pop();     for (int i = n - 1; i >= 0; i--) {       while (!s.empty() && arr[s.top()] >= arr[i]) s.pop();       if (!s.empty()) right[i] = s.top();       s.push(i);     }     int ans[n + 1];     for (int i = 0; i <= n; i++) ans[i] = 0;     for (int i = 0; i < n; i++) {       int len = right[i] - left[i] - 1;       ans[len] = max(ans[len], arr[i]);     }     for (int i = n - 1; i >= 1; i--) ans[i] = max(ans[i], ans[i + 1]);     for (int i = 1; i <= n; i++) cout << ans[i] <<    ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     int t, n, k;     cin >> n;     int arr[n];     for (int i = 0; i < n; i++) cin >> arr[i];     fun(arr, n);     cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   int K;   int main() {     scanf( %d , &K);     if (K % 2) {       puts( YES );       if (K == 1) {         puts( 2 1 n1 2 );         return 0;       }       int i, j, N = (K << 1) + 4,                 M = (3 * K - 2 + (K - 1) * (K - 2) / 2 - K / 2) * 2 + 1,                 tmp1 = K + 1, tmp2 = K + 2;       printf( %d %d n , N, M);       for (i = 1; i < K; i++)         printf( %d %d n%d %d n%d %d n%d %d n%d %d n%d %d n , K, i, K + tmp2,                i + tmp2, tmp1, i, tmp1 + tmp2, i + tmp2, tmp2, i, tmp2 << 1,                i + tmp2);       printf( %d %d n%d %d n , tmp1, tmp2, tmp1 + tmp2, tmp2 << 1);       int lim = K - 1;       for (i = 1, tmp1 = K >> 1; i < lim; i++)         for (j = i + 1; j < K; j++)           if (j != i + tmp1) printf( %d %d n%d %d n , i, j, i + tmp2, j + tmp2);       printf( %d %d n , K, K + tmp2);     } else       puts( NO );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 3050;   int F[N][N];   char buf[N];   vector<int> row[N];   short S[N][N];   inline short get(int y1, int x1, int y2, int x2) {     return S[y2][x2] + S[y1][x1] - S[y2][x1] - S[y1][x2];   }   int A[N];   int n, m, k;   short to_L[N], to_R[N];   short path[N];   int pt = 0;   inline short getL(short x) {     if (x == -1) return -1;     if (to_L[x] == -1 || A[to_L[x]]) return to_L[x];     pt = 0;     path[pt++] = x;     while (true) {       x = to_L[x];       if (x == -1 || A[x] != 0)         break;       else         path[pt++] = x;     }     for (int i = 0; i < pt - 1; i++) to_L[path[i]] = x;     return x;   }   short getR(short x) {     if (x == m) return m;     if (to_R[x] == m || A[to_R[x]]) return to_R[x];     pt = 0;     path[pt++] = x;     while (true) {       x = to_R[x];       if (x == m || A[x] != 0)         break;       else         path[pt++] = x;     }     for (int i = 0; i < pt - 1; i++) to_R[path[i]] = x;     return x;   }   vector<short> visited;   short Rpos[N];   int used[N];   int curver = 0;   vector<short> interesting;   void calcLpos(short x) {     visited.clear();     short cur = 0;     while (true) {       if (x == -1) return;       if (used[x] == curver) return;       used[x] = curver;       visited.push_back(x);       cur += A[x];       if (cur >= k) {         x = getL(x);         if (x != -1 && used[x] != curver) visited.push_back(x), used[x] = curver;         return;       }       x = getL(x);     }     assert(false);   }   long long start(short r) {     for (short j = 0; j < m; j++) {       A[j] = get(r, j, n, j + 1);     }     short lst = m;     for (short j = m - 1; j >= 0; j--) {       to_R[j] = lst;       if (A[j]) lst = j;     }     lst = -1;     for (short j = 0; j < m; j++) {       to_L[j] = lst;       if (A[j]) lst = j;     }     lst = -1;     for (short j = 0; j < m; j++) {       if (A[j]) {         Rpos[j] = max(j, lst);         while (true) {           short nrpos = getR(Rpos[j]);           if (Rpos[j] == m || get(r, j, n, Rpos[j] + 1) >= k) {             break;           } else {             Rpos[j] = nrpos;           }         }         lst = Rpos[j];       }     }     int curval = 0;     for (short j = 0; j < m; j++) {       if (A[j]) {         short pj = getL(j);         short from = Rpos[j];         curval += (int)(j - pj) * (m - from);       }     }     long long ans = 0;     ans += curval;     for (int i = n - 1; i > r; i--) {       interesting.clear();       ++curver;       for (short x : row[i]) {         calcLpos(x);         interesting.insert(interesting.end(), visited.rbegin(), visited.rend());         short r = getR(x);         if (r != m && used[r] != curver) {           used[r] = curver;           interesting.push_back(r);         }       }       for (short j : interesting) {         short pj = getL(j);         short from = Rpos[j];         curval -= (int)(j - pj) * (m - from);       }       for (short x : row[i]) {         A[x]--;       }       short lst = -1;       for (short j : interesting) {         if (!A[j]) continue;         short pj = getL(j);         Rpos[j] = max(Rpos[j], lst);         while (true) {           short nrpos = getR(Rpos[j]);           if (Rpos[j] == m || get(r, j, i, Rpos[j] + 1) >= k) {             break;           } else {             Rpos[j] = nrpos;           }         }         lst = Rpos[j];         short from = Rpos[j];         curval += (int)(j - pj) * (m - from);       }       ans += curval;     }     return ans;   }   int main() {     int tmp;     scanf( %d %d %d %d  , &n, &m, &tmp, &k);     for (int i = 0; i < tmp; i++) {       int y, x;       scanf( %d %d , &y, &x);       --y, --x;       F[y][x] = 1;       row[y].push_back(x);     }     for (int i = 0; i < n; i++) {       sort(row[i].begin(), row[i].end());     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         S[i + 1][j + 1] = S[i + 1][j] + S[i][j + 1] - S[i][j] + F[i][j];       }     }     long long ans = 0;     long long last = start(n - 1);     ans = last;     for (int i = n - 2; i >= 0; i--) {       if (i % 10 == 0) {       }       if (row[i].empty())         ans += last;       else {         ans += (last = start(i));       }     }     printf( %lld n , ans);   }


#include <bits/stdc++.h>   using namespace std;   long n, tim;   string st;   long lpos, calc1, calc2;   long need, ans, calc;   long l, r, has, bad;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n >> tim;     cin >> st;     lpos = -1;     for (int i = 0; i < st.size(); i++) {       if (st[i] ==  H ) ++calc1;       if (st[i] ==  H ) lpos = i;       if (st[i] ==  S ) ++calc2;     }     if (tim <= lpos) {       cout << -1 << endl;       return 0;     }     l = 0;     r = 1e6;     if (calc1 > calc2) l = calc1 - calc2;     while (l < r) {       long mid = l + r;       mid /= 2;       calc = 0;       has = mid;       bad = 1e9;       need = 0;       long oscore = 1e9;       long tt = mid;       long epos = 0;       for (int i = 0; i < st.size(); i++) {         if (tt < calc1) epos = i;         if (st[i] ==  S ) ++tt;       }       if (epos < lpos) epos = lpos;       for (long i = 0; i < st.size(); i++) {         ++calc;         if (bad < 1e7)           oscore = min(oscore, epos - i + calc + (epos - bad) * (bad < 1e7));         if (st[i] ==  H ) {           if (has == 0) {             bad = min(bad, i);             need++;           } else {             --has;           }         }         if (st[i] ==  S ) {           ++has;           if (has >= need && i >= lpos) {             if (need) calc += i - bad;             break;           }           if (has >= need && need > 0) {             calc += 2 * (i - bad);             bad = 1e9;             has -= need;             need = 0;           }         }         if (i >= lpos && has >= need) {           if (need) calc += i - bad;           break;         }       }       calc = min(calc, oscore);       if (calc > tim)         l = mid + 1;       else         r = mid;     }     cout << l << endl;     cin.get();     cin.get();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     if (n % 2 == 0)       cout <<  NO  << endl;     else {       cout <<  YES  << endl;       cout << 1 <<    ;       for (int i = 4; i < 2 * n; i += 4) cout << i <<     << i + 1 <<    ;       for (int i = 2; i < 2 * n; i += 4) cout << i <<     << i + 1 <<    ;       cout << 2 * n << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, SF, FS;     SF = FS = 0;     string flights;     cin >> n >> flights;     for (int i = 0; i < flights.size() - 1; i++) {       if (flights[i] ==  S  && flights[i + 1] ==  F ) {         SF++;       } else if (flights[i] ==  F  && flights[i + 1] ==  S ) {         FS++;       }     }     if (SF > FS) {       cout <<  YES ;     } else {       cout <<  NO ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 100;   struct Node {     int id, w;   };   vector<int> g[maxn];   vector<Node> gg;   bool vis[maxn];   int dfs(int u) {     vis[u] = 1;     for (int i : g[u]) {       if (!vis[i]) {         return dfs(i);       }     }     return u;   }   int main(int argc, const char* argv[]) {     ios::sync_with_stdio(false);     int n, a, b;     Node tmp;     cin >> n;     for (int i = 0; i < n - 1; ++i) {       cin >> a >> b;       g[a].push_back(b);       g[b].push_back(a);     }     int t = 0;     for (int i = 1; i <= n; ++i) {       int tt = g[i].size();       tmp.id = i;       tmp.w = tt;       gg.push_back(tmp);       if (tt > 2) {         ++t;       }       if (t >= 2) {         break;       }     }     if (t >= 2) {       cout <<  No  << endl;     } else {       cout <<  Yes  << endl;       sort(gg.begin(), gg.end(), [&](Node a, Node b) { return a.w > b.w; });       if (t)         tmp = gg[0];       else         tmp = gg[n - 1];       vis[tmp.id] = 1;       cout << tmp.w << endl;       for (int i : g[tmp.id]) {         cout << tmp.id <<     << dfs(i) << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, k;   int a[200007];   long long fac[200007];   long long inv[200007];   long long pw2[200007];   long long free_pw[200007];   long long fastpow(long long x, long long st) {     long long ret = 1;     while (st > 0) {       if ((st & 1) != 0) {         ret = (ret * x) % 998244353;         --st;       } else {         x = (x * x) % 998244353;         st >>= 1;       }     }     return ret;   }   long long get_comb(long long x, long long y) {     if (x < y) {       return 0;     }     long long ret = fac[x];     ret = (ret * inv[y]) % 998244353;     ret = (ret * inv[x - y]) % 998244353;     return ret;   }   void input() {     scanf( %I64d%I64d , &n, &k);     for (int i = 1; i <= n; ++i) {       scanf( %d , &a[i]);     }     a[n + 1] = a[1];     fac[0] = pw2[0] = free_pw[0] = 1;     for (int i = 1; i <= n; ++i) {       fac[i] = (fac[i - 1] * i) % 998244353;       pw2[i] = (pw2[i - 1] * 2) % 998244353;       free_pw[i] = (free_pw[i - 1] * (k - 2)) % 998244353;     }     inv[n] = fastpow(fac[n], 998244353 - 2);     for (int i = n - 1; i >= 0; --i) {       inv[i] = (inv[i + 1] * (i + 1)) % 998244353;     }   }   void solve() {     int free = 0;     long long aux = 1;     for (int i = 1; i <= n; ++i) {       if (a[i] == a[i + 1]) {         ++free, aux = (aux * k) % 998244353;       }     }     long long ans = 0;     for (int i = 0; i < n - free; ++i) {       long long w = (get_comb(n - free, i) * free_pw[i]) % 998244353;       int lft = n - free - i;       long long coef = pw2[lft];       if ((lft & 1) == 0) {         coef = (coef - get_comb(lft, lft / 2) + 998244353) % 998244353;       }       coef = (coef * inv[2]) % 998244353;       ans = (ans + (w * coef) % 998244353) % 998244353;     }     printf( %I64d n , (aux * ans) % 998244353);   }   int main() {     ios_base ::sync_with_stdio(false);     cin.tie(NULL);     input();     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, ans = 0;     cin >> n;     n -= 10;     if (n == 11) {       ans += 4;       n -= 11;     }     if (n == 10) {       ans = (4 * 4) - 1;       n -= 10;     }     for (int i = 9; i >= 1; --i) {       if (n == i) {         ans += 4;         n -= i;       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   double dist[5001][5001];   double x[5001], y[5001], z[5001];   int n;   double sqr(double x) { return x * x; }   int main() {     cin >> n;     for (int i = 1; i <= n; i++) cin >> x[i] >> y[i] >> z[i];     for (int i = 1; i <= n; i++) {       for (int j = i + 1; j <= n; j++) {         dist[i][j] = sqrt(sqr(x[i] - x[j]) + sqr(y[i] - y[j]) + sqr(z[i] - z[j]));         dist[j][i] = dist[i][j];       }     }     double distance = 100000;     for (int i = 2; i <= n; i++) {       double minn = 100000;       for (int j = 2; j <= n; j++) {         if (i != j) {           if (dist[1][j] + dist[j][i] < minn) minn = dist[1][j] + dist[j][i];         }       }       if (dist[1][i] + (minn - dist[1][i]) / 2 < distance)         distance = dist[1][i] + (minn - dist[1][i]) / 2;     }     cout.precision(20);     cout << distance;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     int n, m;     cin >> n >> m;     string s, t;     cin >> s >> t;     int mincnt = n + 1;     int nin = -1;     for (int i = 0; i <= m - n; i++) {       int cnt = 0;       for (int j = 0; j < n; j++) {         if (s[j] != t[i + j]) cnt++;       }       if (mincnt > cnt) {         mincnt = cnt;         nin = i;       }     }     vector<long long> a;     int i = nin;     for (int k = i; k <= n + i - 1; k++)       if (s[k - i] != t[k]) a.push_back(k - i);     cout << a.size() <<   n ;     for (int i = 0; i < mincnt; i++) cout << a[i] + 1 <<    ;   }


#include <bits/stdc++.h>   int days(int y) {     if (y % 400 == 0 || (y % 4 == 0 && y % 100 != 0)) {       return 366;     } else {       return 365;     }   }   int main() {     int year, i, d, di, dii;     unsigned long long int count = 0;     scanf( %d , &year);     d = days(year);     di = d;     for (i = year;; i++) {       dii = days(i + 1);       count += di;       if (count % 7 == 0 && d == dii) {         printf( %d n , i + 1);         return 0;       }       di = dii;     }     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   const int inf = 1 << 28;   const double INF = 1e12, EPS = 1e-9;   int n, m, c[101];   void run() {     cin >> n >> m;     for (int i = 0; i < m; i++) {       int a, b;       cin >> a >> b;       for (; a <= b; a++) c[a]++;     }     for (int i = 1; i <= n; i++)       if (c[i] != 1) {         cout << i <<     << c[i] << endl;         return;       }     cout <<  OK  << endl;   }   int main() { run(); }


#include <bits/stdc++.h>   using namespace std;   int n;   int a[1501];   int calcinv() {     int j;     int rez = 0;     for (int i = 1; i <= n; i++)       for (j = i + 1; j <= n; j++)         if (a[i] > a[j]) rez++;     return rez;   }   int main() {     int i, nri, j, m, l, r, lg;     cin >> n;     for (i = 1; i <= n; i++) cin >> a[i];     nri = calcinv() % 2;     cin >> m;     for (i = 1; i <= m; i++) {       cin >> l >> r;       lg = r - l;       lg = lg * (lg + 1) / 2;       nri = (nri + lg) % 2;       if (nri == 0)         cout <<  even ;       else         cout <<  odd ;       cout <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   void swap(int &a, int &b) {     int temp = a;     a = b;     b = temp;   }   int main() {     int n;     cin >> n;     int x[n], y[n], min_x = INT_MAX, max_y = INT_MIN;     for (int i = 0; i < n; i++) {       cin >> x[i] >> y[i];       if (x[i] < min_x) min_x = x[i];       if (y[i] > max_y) max_y = y[i];     }     int k = 0, res = -1;     while (k < n) {       if (x[k] == min_x) {         if (y[k] == max_y) {           res = k + 1;           break;         }       }       k++;     }     cout << res << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   void no() {     cout <<  NO n ;     exit(0);   }   int main() {     int n;     cin >> n;     vector<int> arr(n);     for (int i = 0; i < n; ++i) cin >> arr[i];     sort(arr.begin(), arr.end());     for (int i = n - 1; i >= 0; --i) {       arr[i] -= arr[0];       if (arr[i] >= n) no();     }     vector<int> cnt(n);     for (int i = 0; i < n; ++i) cnt[arr[i]]++;     int mx = arr[n - 1];     for (int i = 1; i < mx; ++i) {       if (cnt[i] < 2) no();       cnt[i] -= 2;     }     cnt[0]--;     cnt[mx]--;     for (int i = 0; i <= mx; ++i) {       while (cnt[i] > 0) {         if (cnt[i + 1] == 0) no();         cnt[i]--;         cnt[i + 1]--;       }     }     cout <<  YES n ;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1000 * 100 + 10;   const long long INF = 1000 * 1000 * 1000LL * 1000 * 10000;   int n, q, pt = 1, cnt;   vector<long long> ans;   set<pair<long long, long long> > s;   set<pair<long long, long long> >::iterator it1, it2;   long long po[100], a[N], sum[N * 4][2];   pair<long long, long long> chng[N * 4][2], minn[N * 4][2];   void shift(int ind, bool o, int b, int mid) {     if (chng[ind][o].first) {       chng[ind * 2][o] = chng[ind * 2 + 1][o] = chng[ind][o];       minn[ind * 2][o] = make_pair(chng[ind][o].second, b);       minn[ind * 2 + 1][o] = make_pair(chng[ind][o].second, mid);       sum[ind * 2][o] = sum[ind * 2 + 1][o] = 0;       chng[ind][o] = make_pair(0, 0);     }     long long t = sum[ind][o];     sum[ind * 2][o] += t;     sum[ind * 2 + 1][o] += t;     minn[ind * 2][o].first += t;     minn[ind * 2 + 1][o].first += t;     sum[ind][o] = 0;     return;   }   void add(int l, int r, pair<long long, long long> val, bool o, int b = 0,            int e = n, int ind = 1) {     if (l <= b && e <= r) {       minn[ind][o].first += val.second;       sum[ind][o] += val.second;       return;     }     int mid = (b + e) / 2;     shift(ind, o, b, mid);     if (l < mid) add(l, r, val, o, b, mid, ind * 2);     if (r > mid) add(l, r, val, o, mid, e, ind * 2 + 1);     minn[ind][o] = min(minn[ind * 2][o], minn[ind * 2 + 1][o]);     return;   }   void sett(int l, int r, pair<long long, long long> val, bool o, int b = 0,             int e = n, int ind = 1) {     if (l <= b && e <= r) {       chng[ind][o] = val;       sum[ind][o] = 0;       minn[ind][o] = make_pair(val.second, b);       return;     }     int mid = (b + e) / 2;     shift(ind, o, b, mid);     if (l < mid) sett(l, r, val, o, b, mid, ind * 2);     if (r > mid) sett(l, r, val, o, mid, e, ind * 2 + 1);     minn[ind][o] = min(minn[ind * 2][o], minn[ind * 2 + 1][o]);   }   pair<long long, long long> getmin(int l, int r, int b = 0, int e = n,                                     int ind = 1) {     pair<long long, long long> ret = make_pair(INF, INF);     if (l <= b && e <= r) return minn[ind][0];     int mid = (b + e) / 2;     shift(ind, 0, b, mid);     if (l < mid) ret = min(ret, getmin(l, r, b, mid, ind * 2));     if (r > mid) ret = min(ret, getmin(l, r, mid, e, ind * 2 + 1));     return ret;   }   long long get(int p, bool o, int b = 0, int e = n, int ind = 1) {     if (b + 1 == e) return sum[ind][o] + chng[ind][o].second;     int mid = (b + e) / 2;     shift(ind, o, b, mid);     if (p < mid) return get(p, o, b, mid, ind * 2);     return get(p, o, mid, e, ind * 2 + 1);   }   long long type1(int x) {     x--;     return po[get(x, 1)] - get(x, 0);   }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cin >> n >> q;     po[0] = 1;     for (int i = 1; i <= 12; i++) po[i] = po[i - 1] * 42;     for (int i = 0; i < n; i++) {       cin >> a[i];       a[i] = 1 - a[i];       sett(i, i + 1, make_pair(pt++, a[i]), 0);       s.insert(make_pair(i, i + 1));     }     long long tp, x, l, r;     for (int i = 0; i < q; i++) {       cin >> tp;       if (tp == 1) {         cin >> x;         ans.push_back(type1(x));       } else {         cin >> l >> r >> x;         l--;         if (tp == 2) {           sett(l, r, make_pair(pt++, 1 - x), 0);           sett(l, r, make_pair(pt++, 0), 1);           s.insert(make_pair(l, r));           it1 = it2 = s.find(make_pair(l, r));           if (it1 != s.begin() && (*--it1).second > l) {             pair<long long, long long> temp = *it1;             s.erase(it1);             it1 = s.find(make_pair(l, r));             if (temp.first < l) s.insert(make_pair(temp.first, l));             if (temp.second > r) s.insert(make_pair(r, temp.second));           }           it2++;           while (it2 != s.end() && (*it2).first < r) {             pair<long long, long long> temp = *it2;             s.erase(it2);             it2 = ++s.find(make_pair(l, r));             if (temp.second > r) s.insert(make_pair(r, temp.second));           }         } else {           bool flag = 1;           pair<long long, long long> t1 = *--s.upper_bound(make_pair(l, n + 1));           if (t1.first != l) {             s.erase(t1);             s.insert(make_pair(t1.first, l));             s.insert(make_pair(l, t1.second));           }           pair<long long, long long> t2 = *--s.upper_bound(make_pair(r, n + 1));           if (t2.first != r) {             s.erase(t2);             s.insert(make_pair(t2.first, r));             if (t2.second != r) s.insert(make_pair(r, t2.second));           }           while (flag) {             add(l, r, make_pair(pt++, -x), 0);             pair<long long, long long> temp = getmin(l, r);             while (temp.first < 0) {               pair<long long, long long> seg =                   *--s.upper_bound(make_pair(temp.second, n + 1));               int pnt = get(temp.second, 1);               add(seg.first, seg.second, make_pair(pt++, po[pnt + 1] - po[pnt]),                   0);               sett(seg.first, seg.second, make_pair(pt++, pnt + 1), 1);               temp = getmin(l, r);             }             if (temp.first != 0) flag = 0;           }         }       }     }     for (long long u : ans) cout << u << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int B = 12;   const int D = 64;   const int MASK = 1030;   int q, b;   long long f[B][D][MASK];   long long sum[B][D];   long long call(int base, int rem, int mask) {     if (rem <= 0) return mask == 0;     long long &ret = f[base][rem][mask];     if (ret != -1) return ret;     ret = 0;     for (int i = 0; i < base; ++i) {       ret += call(base, rem - 1, mask ^ 1 << i);     }     return ret;   }   long long solve(long long x) {     if (x == 0) return 0;     vector<int> v;     while (x) {       v.push_back(x % b);       x /= b;     }     reverse(v.begin(), v.end());     int mask = 0, sz = v.size();     long long ans = 0;     for (int i = 0; i < sz; ++i) {       mask ^= 1 << v[i];       if (i + 1 < sz) {         for (int j = 0; j < v[i + 1]; ++j) {           ans += call(b, sz - 2 - i, mask ^ 1 << j);         }       } else {         ans += (mask == 0);       }     }     for (int i = 1; i < v[0]; ++i) {       ans += call(b, sz - 1, 1 << i);     }     for (int i = 1; i < sz; ++i) {       for (int j = 1; j < b; ++j) {         ans += call(b, sz - 1 - i, 1 << j);       }     }     return ans;   }   int main() {     memset(f, -1, sizeof f);     memset(sum, -1, sizeof sum);     scanf( %d , &q);     while (q--) {       long long l, r;       scanf( %d %lld %lld , &b, &l, &r);       printf( %lld n , solve(r) - solve(l - 1));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, a, b, c, result = 0, i, x, y, j = 0;     cin >> n >> a >> b >> c;     for (i = 0; i <= min(n, a / 2); i++) {       x = min(c, (n - i) / 2);       y = min(i + b, n);       if (y - (n - x * 2) / 2 >= 0) {         if (y >= n - x * 2) result += (y - (n - x * 2)) / 2 + 1;       }     }     cout << result;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline T BM(T p, T e, T M) {     long long int ret = 1;     for (; e > 0; e >>= 1) {       if (e & 1) ret = (ret * p) % M;       p = (p * p) % M;     }     return (T)ret;   }   template <class T>   inline T gcd(T a, T b) {     if (b == 0) return a;     return gcd(b, a % b);   }   template <class T>   inline T mdINV(T a, T M) {     return BM(a, M - 2, M);   }   template <class T>   inline T PW(T p, T e) {     long long int ret = 1;     for (; e > 0; e >>= 1) {       if (e & 1) ret = (ret * p);       p = (p * p);     }     return (T)ret;   }   template <class T>   string NTS(T Number) {     stringstream ss;     ss << Number;     return ss.str();   }   template <class T>   T stringtonumber(const string &Text) {     istringstream ss(Text);     T result;     return ss >> result ? result : 0;   }   template <class T>   bool ISLEFT(T a, T b, T c) {     if (((a.first.first - b.first.first) * (b.second.second - c.second.second) -          (b.first.first - c.first.first) * (a.second.second - b.second.second)) <         0.0)       return 1;     else       return 0;   }   int n, k;   vector<int> v[300ll + 2];   long long int dp[102][44];   void go(int u, int p) {     dp[u][0] = 1;     dp[u][k + 1] = 1;     for (int i = 0; i < v[u].size(); i++) {       int first = v[u][i];       if (first == p) continue;       go(first, u);       long long int kop[44];       memset(kop, 0, sizeof kop);       for (int j = 0; j <= k * 2; j++) {         for (int l = 0; l <= k * 2; l++) {           if (j + l <= k * 2) {             kop[min(j, l + 1)] =                 (kop[min(j, l + 1)] + dp[u][j] * dp[first][l]) % 1000000007;           } else {             kop[max(j, l + 1)] =                 (kop[max(j, l + 1)] + dp[u][j] * dp[first][l]) % 1000000007;           }         }       }       for (int j = 0; j <= k * 2; j++) dp[u][j] = kop[j];     }   }   int main() {     scanf( %d%d , &n, &k);     for (int i = 1; i <= n - 1; i++) {       int first, second;       scanf( %d%d , &first, &second);       v[first].push_back(second);       v[second].push_back(first);     }     go(1, -1);     int ans = 0;     for (int i = 0; i <= k; i++) {       ans += dp[1][i];       if (ans >= 1000000007) ans -= 1000000007;     }     printf( %d , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int b, g, n;     scanf( %d%d%d , &b, &g, &n);     printf( %d n , min(b, n) - (n - min(g, n)) + 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int cf[45], nc[45];   vector<int> ppf[45];   bool canadd(int i, int m) {     for (int p : ppf[m]) {       if (nc[p] && cf[p] != i % p) return false;     }     return true;   }   void add(int i, int m) {     for (int p : ppf[m]) {       if (nc[p] == 0) cf[p] = i % p;       nc[p]++;     }   }   void rem(int m) {     for (int p : ppf[m]) {       nc[p]--;     }   }   vector<pair<int, int> > loc[100005];   int k[100005];   int n, m;   int main() {     for (int i = (2); i < (45); i++) {       int x = i;       for (int j = (2); j < (45); j++) {         int fct = 1;         while (x % j == 0) {           fct *= j;           ppf[i].push_back(fct);           x /= j;         }       }     }     scanf( %d %d , &n, &m);     for (int i = (0); i < (n); i++) {       scanf( %d , k + i);       for (int j = (0); j < (k[i]); j++) {         int x;         scanf( %d , &x);         loc[x].push_back(make_pair(i, j));       }     }     for (int x = (1); x < (m + 1); x++) {       queue<pair<int, int> > cq;       int prv = -1, ans = 0;       for (auto l : loc[x]) {         int i, j;         tie(i, j) = l;         if (i != prv + 1) {           while (int(cq.size())) {             int fi, fj;             tie(fi, fj) = cq.front();             cq.pop();             rem(k[fi]);           }         }         while (!canadd(j, k[i])) {           int fi, fj;           tie(fi, fj) = cq.front();           cq.pop();           rem(k[fi]);         }         add(j, k[i]);         cq.emplace(i, j);         prv = i;         ans = max(ans, int(cq.size()));       }       while (int(cq.size())) {         int fi, fj;         tie(fi, fj) = cq.front();         cq.pop();         rem(k[fi]);       }       printf( %d n , ans);     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t, n, num;     cin >> t;     while (t--) {       cin >> n;       bool flag = false;       unordered_map<int, vector<int>> m;       for (int i = 0; i < n; ++i) {         cin >> num;         m[num].push_back(i);       }       for (auto& k : m) {         if (k.second.back() - k.second.front() >= 2) {           flag = true;           break;         }       }       if (flag)         cout <<  YES n ;       else         cout <<  NO n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 61 * 30 + 5;   pair<int, int> C[62];   int M, A[32], cc;   bool dp[32][62][maxn], D[62][62];   short int fr[32][62][maxn];   int main() {     scanf( %d , &M);     for (int i = 1; i <= M; ++i) scanf( %d , A + i);     sort(A + 1, A + M + 1);     dp[0][0][0] = true;     for (int i = 1; i <= M; ++i)       for (int j = i; j <= 61; ++j)         for (int k = (j * (j - 1)) >> 1; k < maxn; ++k) {           for (int m = 1; m <= j; ++m)             if (k >= m * A[i] && dp[i - 1][j - m][k - m * A[i]]) {               dp[i][j][k] = true;               fr[i][j][k] = m;               break;             }         }     int N = M;     while (!dp[M][N][(N * (N - 1)) >> 1]) ++N;     printf( %d n , N);     for (int i = M, j = N, k = (N * (N - 1)) >> 1; i; --i) {       int c = fr[i][j][k];       j -= c;       k -= c * A[i];       for (int j = 0; j < c; ++j) {         ++cc;         C[cc] = make_pair(A[i], cc);       }     }     for (int i = 1; i <= N; ++i) {       sort(C + 1, C + cc + 1);       for (int j = i + 1; j <= i + C[i].first; ++j)         D[C[i].second][C[j].second] = true;       for (int j = i + C[i].first + 1; j <= N; ++j)         D[C[j].second][C[i].second] = true, --C[j].first;       C[i].first = -1;     }     for (int i = 1; i <= N; ++i) {       for (int j = 1; j <= N; ++j) printf( %d , D[i][j] ? 1 : 0);       printf(  n );     }   }


#include <bits/stdc++.h>   using namespace std;   const char *par =  () ;   const int pm[] = {1, -1};   int n;   int mn, res, fir;   string s;   vector<int> v, w;   map<int, int> mp;   int init(string s) {     v = vector<int>(n);     for (int i = 0, pre = 0; i < n; ++i) {       v[i] = (pre += pm[strchr(par, s[i]) - par]);       mp[v[i]]++;     }     if (v.back() != 0) return 0;     res = mp.begin()->second;     mn = mp.begin()->first;     for (int i = 0; i < n; ++i)       if (v[i] == mn) {         fir = (i + 1) % n;         return res;       }   }   int count(int l, int r) {     int cur = v[(l - 1 + n) % n];     s[l] =  ) ;     for (int i = l; i != r; i = (i + 1) % n) {       cur += pm[strchr(par, s[i]) - par];       if (!--mp[v[i]]) mp.erase(v[i]);       mp[cur]++;     }     int ret = mp.begin()->second;     cur = v[(l - 1 + n) % n];     for (int i = l; i != r; i = (i + 1) % n) {       cur += pm[strchr(par, s[i]) - par];       if (!--mp[cur]) mp.erase(cur);       mp[v[i]]++;     }     s[l] =  ( ;     return ret;   }   int main() {     cin >> n >> s;     if (!init(s)) {       cout <<  0 n1 1 n ;       return 0;     }     stack<int> st;     int i = fir;     w = vector<int>(n);     do {       if (s[i] ==  ( ) st.push(i);       if (s[i] ==  ) ) {         w[i] = st.top();         w[w[i]] = i;         st.pop();       }     } while ((i = (i + 1) % n) != fir);     int ans[3] = {res};     for (int i = 0; i < n; ++i)       if (s[i] ==  (  && v[i] <= mn + 2) {         int ret = count(i, w[i]);         if (ret > ans[0]) ans[0] = ret, ans[1] = i, ans[2] = w[i];       }     cout << ans[0] << endl << ans[1] + 1 <<     << ans[2] + 1 << endl;   }


#include <bits/stdc++.h>   using namespace std;   inline bool cmp(const pair<int, int> &a, const pair<int, int> &b) {     if (a.first != b.first) return a.first > b.first;     return a.second < b.second;   }   int a[1000005], b[1000005];   char s[1000005], r[1000005];   int test;   int main() {     int t, n, m, k, l, x, y, z, flag = 0, count, d, mx, mn;     long long int sum, prod;     scanf( %s%s , s, r);     count = sum = 0;     n = strlen(s), m = strlen(r);     int j = 0;     for (int i = 0; i < m; i++) {       if (r[i] == s[j]) j++;       if (j == n) break;     }     printf( %d , j + 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, a[200005];   void slove() {     int temp, u, v, w, m;     for (int i = 1; i <= n; i++) cin >> temp, a[i] = 0x3f3f3f3f;     cin >> m;     for (int i = 1; i <= m; i++) {       cin >> u >> v >> w;       if (a[v] > w) a[v] = w;     }     int flag = 1, k = 1;     int ans = 0;     for (int i = 1; i <= n; i++) {       if (a[i] == 0x3f3f3f3f && k) {         ans -= 0x3f3f3f3f;         k = 0;       } else if (a[i] == 0x3f3f3f3f) {         flag = 0;         break;       }       ans += a[i];     }     if (flag)       cout << ans <<   n ;     else       cout << -1 <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> n;     slove();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = (1ll << 60);   const int N = 205;   int n, m, _len;   int nxt[N];   long long k;   long long ADD(long long x, long long y) { return min(INF, x + y); }   struct node {     char pref[N];     char suff[N];     long long len;     long long sum;   } t[N * 4], eddd;   char s[N * 4];   char ans[N];   node operator+(node a, node b) {     node ans;     ans.len = ADD(a.len, b.len);     ans.sum = ADD(a.sum, b.sum);     int l1 = min(a.len, 2ll * _len);     int l2 = min(b.len, 2ll * _len);     for (int i = (int)(1); i <= (int)(min(l1, _len)); i++) s[i] = a.pref[i];     for (int i = (int)(1); i <= (int)(min(l1, _len)); i++)       s[l1 - i + 1] = a.suff[i];     for (int i = (int)(1); i <= (int)(min(l2, _len)); i++) s[l1 + i] = b.pref[i];     for (int i = (int)(1); i <= (int)(min(l2, _len)); i++)       s[l1 + l2 - i + 1] = b.suff[i];     int p = 0;     s[l1 + l2 + 1] = 0;     for (int i = (int)(l1 - min(l1, _len - 1) + 1);          i <= (int)(l1 + 1 + min(l2, _len - 1) - 1); i++) {       for (; p && s[i] != ::ans[p + 1]; p = nxt[p])         ;       if (s[i] == ::ans[p + 1]) ++p;       if (p == _len) ++ans.sum, p = nxt[p];     }     for (int i = (int)(1); i <= (int)(min(_len, l1 + l2)); i++)       ans.pref[i] = s[i];     for (int i = (int)(1); i <= (int)(min(_len, l1 + l2)); i++)       ans.suff[i] = s[l1 + l2 - i + 1];     return ans;   }   long long count(int l) {     _len = l;     nxt[1] = 0;     for (int i = (int)(2); i <= (int)(l); i++) {       int j = nxt[i - 1];       for (; j && ans[j + 1] != ans[i]; j = nxt[j])         ;       nxt[i] = j + (ans[j + 1] == ans[i]);     }     t[0].pref[1] = t[0].suff[1] =  0 ;     t[1].pref[1] = t[1].suff[1] =  1 ;     eddd.pref[1] = eddd.suff[1] =  2 ;     t[0].len = t[1].len = eddd.len = 1;     t[0].sum = (l == 1 && ans[1] ==  0 );     t[1].sum = (l == 1 && ans[1] ==  1 );     eddd.sum = (l == 1 && ans[1] ==  2 );     for (int i = (int)(2); i <= (int)(n); i++) {       t[i] = t[i - 2] + t[i - 1];     }     return (t[n] + eddd).sum;   }   int main() {     scanf( %d%lld%d , &n, &k, &m);     k++;     for (int i = (int)(1); i <= (int)(m); i++) {       ans[i] =  2 ;       long long val = count(i);       if (val >= k) break;       k -= val;       ans[i] =  0 ;       val = count(i);       if (val >= k) {         putchar( 0 );         continue;       }       k -= val;       ans[i] =  1 ;       val = count(i);       if (val >= k) {         putchar( 1 );         continue;       }       assert(0);     }   }


#include <bits/stdc++.h>   using namespace std;   const int B = 27397, MOD = 1e9 + 7;   const int B1 = 33941, MOD1 = 1e9 + 9;   int t;   inline void solve() {     int r, n;     scanf( %d%d , &n, &r);     --r;     int sum = 0;     for (int i = 0; i < n - 1; ++i) {       int x;       scanf( %d , &x);       --x;       sum += x;     }     for (int i = 0; i < n; ++i)       if ((sum + i) % n == r) printf( %d n , i + 1);   }   int main(void) {     scanf( %d , &t);     while (t-- > 0) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<vector<pair<int, long long> > > g;   int n, a[100005];   bool erased[100005];   void dfs(int cur, long long cost, long long minCost) {     if (cost - minCost > 1ll * a[cur]) {       erased[cur] = 1;       return;     }     for (int i = 0; i < g[cur].size(); i++) {       dfs(g[cur][i].first, cost + g[cur][i].second, min(minCost, cost));     }   }   int count(int u) {     if (erased[u]) return 0;     int ans = 1;     for (int i = 0; i < g[u].size(); i++) ans += count(g[u][i].first);     return ans;   }   int main() {     scanf( %d , &n);     g.assign(n, vector<pair<int, long long> >());     for (int i = 0; i < n; i++) scanf( %d , &a[i]);     for (int i = 1; i < n; i++) {       int v, c;       scanf( %d %d , &v, &c);       v--;       g[v].push_back(pair<int, long long>(i, c));     }     memset(erased, 0, sizeof erased);     dfs(0, 0ll, 0ll);     printf( %d n , n - count(0));   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   const long long N = 1e5 + 10;   long long power(long long a, long long b) {     long long ret = 1;     while (b) {       if (b & 1) ret *= a;       a *= a;       if (ret >= MOD) ret %= MOD;       if (a >= MOD) a %= MOD;       b >>= 1;     }     return ret;   }   long long invmod(long long x) { return power(x, MOD - 2); }   long long dp[55][2];   long long a[55];   long long n;   long long go(long long pos, long long check) {     if (pos == n + 1) return 0;     if (dp[pos][check] != -1) return dp[pos][check];     long long ans = 0;     if (check == 0) {       ans += max(a[pos] + go(pos + 1, check ^ 1), go(pos + 1, check));     } else {       ans += min(go(pos + 1, check ^ 1), a[pos] + go(pos + 1, check));     }     dp[pos][check] = ans;     return ans;   }   int32_t main() {     cin >> n;     long long sum = 0;     for (long long i = 1; i <= n; i++) {       cin >> a[i];       sum += a[i];     }     memset(dp, -1, sizeof(dp));     long long k = go(1, 0);     cout << sum - k <<     << k << endl;   }


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


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     long long m, n, b[12345], w[12345], u, v, d = 0, c = 0;     int mx = INT_MIN, mn = INT_MAX;     string p[123];     char ch;     bool sorted;     cin >> n >> m;     vector<int> a(n);     for (int row = 0; row < n; row++) {       cin >> p[row];       for (int col = 0; col < m; col++) {         if (p[row][col] ==  * ) {           c = c ^ row;           d = d ^ col;         }       }     }     cout << c + 1 <<     << d + 1;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int top = 0;   int N, Q, NN;   int K, M, R;   vector<int> Adj[100005];   int dep[100005];   int anc[100005][21];   int pre[100005], pst[100005], tt;   void dfs(int u) {     pre[u] = ++tt;     for (int j = 1; j <= 20; j++) {       if (dep[u] <= (1 << j)) break;       anc[u][j] = anc[anc[u][j - 1]][j - 1];     }     int v;     for (int k = 0; k < Adj[u].size(); k++) {       v = Adj[u][k];       if (v == anc[u][0]) continue;       anc[v][0] = u;       dep[v] = dep[u] + 1;       dfs(v);     }     pst[u] = ++tt;   }   int lca(int u, int v) {     if (dep[u] < dep[v]) swap(u, v);     for (int j = 20; j >= 0; j--) {       if (dep[anc[u][j]] >= dep[v]) {         u = anc[u][j];       }     }     if (u == v) return u;     for (int j = 20; j >= 0; j--) {       if (anc[u][j] != anc[v][j]) {         u = anc[u][j];         v = anc[v][j];       }     }     return anc[u][0];   }   int h[100005], c[2 * 100005];   int lbt(int x) { return x & (-x); }   void update(int x, int dv) {     for (; x <= NN; x += lbt(x)) {       c[x] += dv;     }   }   int getsum(int x) {     int ans = 0;     for (; x > 0; x -= lbt(x)) {       ans += c[x];     }     return ans;   }   bool cmp(const int& a, const int& b) { return dep[a] < dep[b]; }   int query(int u, int lca) { return getsum(pre[u] - 1) - getsum(pre[lca] - 1); }   int a[100005];   bool vis[100005];   long long dp[100005][305];   int work() {     int u, z;     for (int i = 1; i <= K; i++) {       u = a[i];       update(pre[u], 1);       update(pst[u], -1);       vis[a[i]] = 1;     }     int x;     for (int i = 1; i <= K; i++) {       u = a[i];       z = lca(u, R);       if (u == R)         h[i] = 0;       else if (u == z)         h[i] = query(R, u) - (vis[u] == true) + (vis[R] == true);       else if (z == R)         h[i] = query(u, R);       else         h[i] = query(u, z) + query(R, z) - (vis[z] == true) + (vis[R] == true);     }     sort(h + 1, h + 1 + K);     dp[1][1] = 1;     for (int i = 2; i <= K; i++) {       for (int j = 1; j <= M; j++) {         if (j > h[i])           dp[i][j] = ((long long)dp[i - 1][j] * (j - h[i]) % int(1e9 + 7) +                       dp[i - 1][j - 1]) %                      int(1e9 + 7);         else           dp[i][j] = 0;       }     }     long long ans = 0;     for (int j = 1; j <= M; j++) {       ans = (ans + dp[K][j]) % int(1e9 + 7);     }     for (int i = 1; i <= K; i++) {       u = a[i];       update(pre[u], -1);       update(pst[u], +1);       vis[a[i]] = 0;     }     return ans;   }   int main() {     scanf( %d%d , &N, &Q);     int u, v;     for (int i = 1; i < N; i++) {       scanf( %d%d , &u, &v);       Adj[u].push_back(v);       Adj[v].push_back(u);     }     dep[1] = 1;     dfs(1);     NN = 2 * N;     while (Q--) {       scanf( %d%d%d , &K, &M, &R);       for (int i = 1; i <= K; i++) {         scanf( %d , &a[i]);       }       printf( %d n , work());     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int n, k, a[100007];   pair<long long int, long long int> cur[1007];   bool res[200001];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n >> k;     for (long long int i = 1; i <= n; ++i) cin >> a[i];     long long int last = 0, cnt = 0;     for (long long int t = 0; t <= 150000; ++t) {       for (long long int i = 1; i <= k; ++i) {         if (a[cur[i].second] == cur[i].first) {           if (cur[i].second <= n && cur[i].second >= 1) cnt++;           cur[i].second = ++last;           cur[i].first = 0;         }       }       long long int d = round((100.0 * cnt) / (1.0 * n));       for (long long int i = 1; i <= k; ++i) {         if (cur[i].second <= n && cur[i].second >= 1 && cur[i].first + 1 == d)           res[cur[i].second] = 1;         cur[i].first++;       }     }     long long int sum = 0;     for (long long int i = 1; i <= n; ++i) sum += res[i];     cout << sum <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int s, x1, x2;     cin >> s >> x1 >> x2;     int t1, t2;     cin >> t1 >> t2;     int time_for_igor = abs(x1 - x2) * t2;     int p, d;     cin >> p >> d;     int time_for_tram = -1;     if (x2 > x1) {       if (d == 1) {         if (p > x1) {           time_for_tram = s - p;           time_for_tram += s;           time_for_tram += x1;           time_for_tram += (x2 - x1);           time_for_tram *= t1;         } else {           time_for_tram = abs(x1 - p) * t1;           time_for_tram += abs(x1 - x2) * t1;         }       } else {         time_for_tram = p;         time_for_tram += x1;         time_for_tram += (x2 - x1);         time_for_tram *= t1;       }     } else {       if (d == -1) {         if (p < x1) {           time_for_tram = p;           time_for_tram += s;           time_for_tram += (s - x1);           time_for_tram += (x1 - x2);           time_for_tram *= t1;         } else {           time_for_tram = p - x1;           time_for_tram += x1 - x2;           time_for_tram *= t1;         }       } else {         time_for_tram = s - p;         time_for_tram += s - x1;         time_for_tram += x1 - x2;         time_for_tram *= t1;       }     }     cout << min(time_for_tram, time_for_igor) << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     float num;     int t, n, d;     cin >> num >> t >> n >> d;     int a = (num / n);     if ((num / n) > a) a += 1;     int y = d, x = 0;     for (int i = 0; i < a; i++) {       if (x <= y)         x += t;       else         y += t;     }     if (max(x, y) < (t * a))       cout <<  YES ;     else       cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void _print(long long t) { cerr << t; }   void _print(int t) { cerr << t; }   void _print(string t) { cerr << t; }   void _print(char t) { cerr << t; }   void _print(long double t) { cerr << t; }   void _print(double t) { cerr << t; }   void _print(unsigned long long t) { cerr << t; }   template <class T, class V>   void _print(T a[], V sz);   template <class T, class V>   void _print(pair<T, V> p);   template <class T>   void _print(vector<T> v);   template <class T>   void _print(set<T> v);   template <class T, class V>   void _print(map<T, V> v);   template <class T>   void _print(multiset<T> v);   template <class T, class V>   void _print(pair<T, V> p) {     cerr <<  { ;     _print(p.first);     cerr <<   ->  ;     _print(p.second);     cerr <<  }  << endl;   }   template <class T, class V>   void _print(T a[], V sz) {     for (V i = 0; i < sz; i++) {       _print(a[i]);       cerr <<    ;     }     cerr << endl;   }   template <class T>   void _print(vector<T> v) {     cerr <<  [  ;     for (T i : v) {       _print(i);       cerr <<    ;     }     cerr <<  ]  << endl;   }   template <class T>   void _print(set<T> v) {     cerr <<  [  ;     for (T i : v) {       _print(i);       cerr <<    ;     }     cerr <<  ]  << endl;   }   template <class T>   void _print(multiset<T> v) {     cerr <<  [  ;     for (T i : v) {       _print(i);       cerr <<    ;     }     cerr <<  ] ;   }   template <class T, class V>   void _print(map<T, V> v) {     cerr <<  [  ;     for (auto i : v) {       _print(i);       cerr <<    ;     }     cerr <<  ]  << endl;   }   void _printall(long long t) { cout << t; }   void _printall(int t) { cout << t; }   void _printall(string t) { cout << t; }   void _printall(char t) { cout << t; }   void _printall(long double t) { cout << t; }   void _printall(double t) { cout << t; }   void _printall(unsigned long long t) { cout << t; }   template <class T, class V>   void _printall(T a[], V sz);   template <class T, class V>   void _printall(pair<T, V> p);   template <class T>   void _printall(vector<T> v);   template <class T>   void _printall(set<T> v);   template <class T, class V>   void _printall(map<T, V> v);   template <class T>   void _printall(multiset<T> v);   template <class T, class V>   void _printall(T a[], V sz) {     for (V i = 0; i < sz; i++) {       _printall(a[i]);       cout <<    ;     }     cout << endl;   }   template <class T, class V>   void _printall(pair<T, V> p) {     _printall(p.ff);     cout <<  , ;     _printall(p.ss);   }   template <class T>   void _printall(vector<T> v) {     for (T i : v) {       _printall(i);       cout <<    ;     }     cout << endl;   }   template <class T>   void _printall(set<T> v) {     for (T i : v) {       _printall(i);       cout <<    ;     }     cout << endl;   }   template <class T>   void _printall(multiset<T> v) {     for (T i : v) {       _printall(i);       cout <<    ;     }     cout << endl;   }   template <class T, class V>   void _printall(map<T, V> v) {     for (auto i : v) {       _printall(i);       cout <<    ;     }     cout << endl;   }   long long MAXN = 200001;   long long spf[200001];   void sieve() {     spf[1] = 1;     for (int i = 2; i < MAXN; i++) {       spf[i] = i;     }     for (long long i = 4; i < MAXN; i += 2) {       spf[i] = 2;     }     for (long long i = 3; i * i < MAXN; i++) {       if (spf[i] == i) {         for (long long j = i * i; j < MAXN; j += i) {           if (spf[j] == j) spf[j] = i;         }       }     }   }   vector<long long> getFactorization(long long x) {     vector<long long> ret;     while (x != 1) {       ret.push_back(spf[x]);       x = x / spf[x];     }     return ret;   }   void solve() {     long long n;     cin >> n;     string s;     cin >> s;     vector<int> pre;     int cnt = 0;     for (int i = 0; i < n; i++) {       pre.push_back(1);     }     for (int i = n - 2; i >= 0; i--) {       if (s[i] == s[i + 1]) {         pre[i] = pre[i + 1] + 1;       }     }     reverse(pre.begin(), pre.end());     vector<int> fin;     for (int i = 0; i < pre.size() - 1; i++) {       if (pre[i] == 1 && pre[i + 1] == 1) {         fin.push_back(pre[i]);       } else if (pre[i] >= 1 && pre[i + 1] == 1) {         fin.push_back(pre[i]);       }     }     if (pre[n - 1] >= 1) {       fin.push_back(pre[n - 1]);     }     int ind1 = fin.size() - 1;     int ind2 = fin.size() - 1;     while (pre.size() != 0 && ind1 >= 0 && ind2 >= 0) {       if (fin[ind1] > 1) {         cnt++;         fin.pop_back();         if (ind2 == ind1) {           ind2--;         }         ind1--;       } else {         while (fin[ind2] == 1) {           ind2--;         }         if (ind2 < 0) {           break;         } else {           cnt++;           fin[ind2]--;           fin.pop_back();           ind1--;         }       }     }     if (pre.size() != 0) {       cnt += (fin.size() + 1) / 2;     }     cout << cnt << endl;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     long long t = 1;     cin >> t;     while (t--) {       solve();     }     cerr <<  time taken :   << (float)clock() / CLOCKS_PER_SEC <<   secs  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 14;   int a[MAX_N];   void add(int st, int x) {     for (int i = 0; i < MAX_N; i++) a[i] += x / MAX_N;     for (int i = 1; i <= abs(x % MAX_N); i++)       a[(st + i) % MAX_N] += (x < 0 ? -1 : 1);   }   long long point() {     long long ans = 0;     for (int i = 0; i < MAX_N; i++)       if (a[i] % 2 == 0) ans += a[i];     return ans;   }   long long move(int st) {     int x = a[st];     a[st] = 0, add(st, x);     long long ans = point();     add(st, -x), a[st] = x;     return ans;   }   int main() {     ios_base ::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);     for (int i = 0; i < MAX_N; i++) cin >> a[i];     long long ans = 0;     for (int i = 0; i < MAX_N; i++) ans = max(ans, move(i));     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool isNonDegenerateTriangle(int a, int b, int c) {     return (a + b > c && b + c > a && c + a > b);   }   bool isDegenerateTriangle(int a, int b, int c) {     return (a + b == c || b + c == a || c + a == b);   }   int main() {     int n;     cin >> n;     long long int a[n], s = 0;     for (int i = 0; i < n; i++) {       cin >> a[i];       s += a[i];     }     sort(a, a + n);     cout << 2 * a[n - 1] - s + 1;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, tmp;   long long A[1005];   long long B[1005];   long long Acost(int q) {     q *= 4;     long long ret = 0;     for (int i = 1; i <= n; i++) {       long long tmp2 = i * 4 - 2 - q;       ret += A[i] * tmp2 * tmp2;     }     return ret;   }   long long Bcost(int q) {     q *= 4;     long long ret = 0;     for (int i = 1; i <= m; i++) {       long long tmp2 = i * 4 - 2 - q;       ret += B[i] * tmp2 * tmp2;     }     return ret;   }   int ansx, ansy;   long long sumx = LLONG_MAX, sumy = LLONG_MAX;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> n >> m;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         cin >> tmp;         A[i] += tmp;         B[j] += tmp;       }     }     for (int i = 0; i <= n; i++) {       long long tmp3 = Acost(i);       if (tmp3 < sumx) {         ansx = i;         sumx = tmp3;       }     }     for (int i = 0; i <= m; i++) {       long long tmp3 = Bcost(i);       if (tmp3 < sumy) {         ansy = i;         sumy = tmp3;       }     }     cout << sumx + sumy << endl;     cout << ansx <<     << ansy << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 1005;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   long long rand(long long a, long long b) {     return uniform_int_distribution<long long>(a, b)(rng);   }   const int K = 3;   struct Hash {     long long a[K];     Hash() : a() {}     Hash operator^(const Hash &A) const {       Hash ans = Hash();       for (int i = 0; i < K; i++) ans.a[i] = a[i] ^ A.a[i];       return ans;     }     bool operator==(const Hash &A) const {       for (int i = 0; i < K; i++)         if (a[i] != A.a[i]) return false;       return true;     }     bool operator<(const Hash &A) const {       for (int i = 0; i < K; i++)         if (a[i] != A.a[i]) return a[i] < A.a[i];       return false;     }   };   Hash genHash() {     Hash ret = Hash();     for (int i = 0; i < K; i++) ret.a[i] = rand(1, 1LL << 60);     return ret;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n, s, d;     cin >> n >> s >> d;     Hash hash[n], sw[s];     for (int i = 0; i < n; i++) hash[i] = genHash();     for (int i = 0; i < s; i++) {       int k;       cin >> k;       Hash cur = Hash();       while (k--) {         int x;         cin >> x;         cur = cur ^ hash[x - 1];       }       sw[i] = cur;     }     map<Hash, int> left_sz;     int left = min(s / 2, 13);     for (int mask = 0; mask < (1 << left); mask++) {       Hash cur = Hash();       for (int bit = 0; bit < left; bit++) {         if (!((mask >> bit) & 1)) continue;         cur = cur ^ sw[bit];       }       if (!left_sz.count(cur))         left_sz[cur] = __builtin_popcountll(mask);       else         left_sz[cur] = min(left_sz[cur], __builtin_popcountll(mask));     }     map<Hash, int> right_sz;     int right = s - left;     for (int mask = 0; mask < (1 << right); mask++) {       Hash cur = Hash();       for (int bit = 0; bit < right; bit++) {         if (!((mask >> bit) & 1)) continue;         cur = cur ^ sw[bit + left];       }       if (!right_sz.count(cur))         right_sz[cur] = __builtin_popcountll(mask);       else         right_sz[cur] = min(right_sz[cur], __builtin_popcountll(mask));     }     while (d--) {       Hash cur = Hash();       int sz;       cin >> sz;       for (int i = 0; i < sz; i++) {         int x;         cin >> x;         cur = cur ^ hash[x - 1];       }       int ans = 100;       for (auto p : left_sz) {         Hash tmp = cur ^ p.first;         if (right_sz.count(tmp)) ans = min(ans, p.second + right_sz[tmp]);         if (left_sz.count(tmp)) {           if (tmp == p.first)             ans = 0;           else             ans = min(ans, p.second + left_sz[tmp]);         }       }       cout << (ans == 100 ? -1 : ans) <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 210;   int n;   int a[N];   bool vis[N];   int lp[N];   int dis[N];   int inloop(int v) {     vis[v] = 1;     int u = a[v];     int cnt = 1;     while (u != v && !vis[u]) {       vis[u] = 1;       ++cnt;       u = a[u];     }     if (u == v) return cnt;     return 0;   }   int dfsandsetlp(int v) {     if (lp[v] > 0) return dis[v];     int t = dfsandsetlp(a[v]);     lp[v] = lp[a[v]];     return dis[v] = t + 1;   }   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   long long lcm(long long a, long long b) {     if (a == 0) return b;     if (b == 0) return a;     return a / gcd(a, b) * b;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) {       scanf( %d , a + i);     }     for (int i = 1; i <= n; ++i) {       memset(vis, 0, sizeof(vis));       int t = inloop(i);       lp[i] = t;     }     for (int i = 1; i <= n; ++i) {       if (!lp[i]) {         dis[i] = dfsandsetlp(i);       }     }     long long res = 1;     for (int i = 1; i <= n; ++i) {       res = lcm(res, lp[i]);     }     int mx = 0;     for (int i = 1; i <= n; ++i) {       mx = max(mx, dis[i]);     }     if (res < mx) {       int t = mx / res;       if (res * t == mx) {         res = mx;       } else {         res = res * (t + 1);       }     }     printf( %I64d n , res);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long inf = LLONG_MAX / 2;   const long long MX = 1e5 + 10;   int a[MX];   set<int> s;   vector<int> v;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n, m;     cin >> n >> m;     for (long long(i) = (0); (i) <= (n - 1); ++(i)) {       cin >> a[i];       s.insert(a[i]);     }     int num = 1;     while (m >= num) {       if (!s.count(num)) {         m -= num;         v.push_back(num);       }       num++;     }     cout << v.size() << endl;     for (auto it : v) {       cout << it <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline long long tr(long long d) { return d * (d + 1) / 2; }   inline long long tr2(long long d) { return 2 * tr(d) - d; }   int n;   long long solve(int y, int x, long long c) {     long long res = 4 * (tr(c + 1) - c - 1) + 1;     if (c - (y + 1) >= 0) res -= tr2(c - (y + 1) + 1);     if (c - (n - y) >= 0) res -= tr2(c - (n - y) + 1);     if (c - (x + 1) >= 0) res -= tr2(c - (x + 1) + 1);     if (c - (n - x) >= 0) res -= tr2(c - (n - x) + 1);     if (c - (y + x + 2) >= 0) res += tr(c - (y + x + 2) + 1);     if (c - (y + 1 + n - x) >= 0) res += tr(c - (y + 1 + n - x) + 1);     if (c - (x + 1 + n - y) >= 0) res += tr(c - (x + 1 + n - y) + 1);     if (c - (n - x + n - y) >= 0) res += tr(c - (n - x + n - y) + 1);     return res;   }   int main() {     int y, x, c;     while (scanf( %d%d%d%d , &n, &y, &x, &c) >= 1) {       --y, --x;       int l = -1, r = (int)2e9 + 1;       while (l + 1 < r) {         int m = l + (r - l) / 2;         if (solve(y, x, m) >= (long long)c)           r = m;         else           l = m;       }       printf( %d n , r);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void setIO(string name =   ) {     ios_base::sync_with_stdio(0);     cin.tie(0);     if (int((name).size())) {       freopen((name +  .in ).c_str(),  r , stdin);       freopen((name +  .out ).c_str(),  w , stdout);     }   }   long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }   long long mcm(long long a, long long b) { return (a * b) / gcd(a, b); }   bool prime(long long n, long long i) {     if (i > sqrt(n)) return true;     if (n % i == 0)       return false;     else       return prime(n, i + 1);   }   struct compii {     bool operator()(const pair<int, int> &a, const pair<int, int> &b) {       if (a.first == a.second) return a.second < b.second;       return a.first > b.first;     }   };   bool comp(int a, int b) { return a > b; }   int dx[] = {1, 0, -1, 0};   int dy[] = {0, 1, 0, -1};   void solve() {     int n;     cin >> n;     vector<int> num(n);     int c0 = 0;     int c1 = 0;     for (auto &x : num) {       cin >> x;       if (x == 1)         c1++;       else         c0++;     }     int i = 0;     for (i = 0; i < n; i++) {       if (num[i] == 1)         c1--;       else         c0--;       if (c1 == 0) break;       if (c0 == 0) break;     }     cout << i + 1 << endl;   }   int main() {     setIO(  );     int t = 1;     while (t-- > 0) solve();     return 0;   }


#include <bits/stdc++.h>   #define int long long   using namespace std;   const int maxm=5e5+5;   int stk[maxm],head;   int d[maxm];   int a[maxm];   int n;   //   int rt[maxm],tot;   int lc[maxm*40],rc[maxm*40],ma[maxm*40];   inline void pp(int k){       ma[k]=max(ma[lc[k]],ma[rc[k]]);   }   void update(int x,int val,int l,int r,int &k,int last){       k=++tot;       lc[k]=lc[last];       rc[k]=rc[last];       if(l==r){           ma[k]=val;           return ;       }       int mid=(l+r)/2;       if(x<=mid)update(x,val,l,mid,lc[k],lc[last]);       else update(x,val,mid+1,r,rc[k],rc[last]);       pp(k);   }   int ask(int st,int ed,int l,int r,int k){       if(!k)return 0;       if(st<=l&&ed>=r)return ma[k];       int mid=(l+r)/2;       int ans=0;       if(st<=mid)ans=max(ans,ask(st,ed,l,mid,lc[k]));       if(ed>mid)ans=max(ans,ask(st,ed,mid+1,r,rc[k]));       return ans;   }   //   void solve(){       cin>>n;       //init       tot=0;       ma[0]=0;       //       for(int i=1;i<=n;i++){           cin>>a[i];       }       int ans=0;       head=0;       for(int i=1;i<=n;i++){           while(head&&a[stk[head]]<a[i]){               head--;           }           d[i]=1;           d[i]=max(d[i],ask(1,a[i],1,n,rt[i-1])+1);           if(head){               int k=stk[head];               d[i]=max(d[i],ask(1,a[i],1,n,rt[k-1])+2);           }           update(a[i],d[i],1,n,rt[i],rt[i-1]);           stk[++head]=i;           ans=max(ans,d[i]);       }       cout<<ans<<endl;   }   signed main(){       ios::sync_with_stdio(0);       int T;cin>>T;       while(T--){           solve();       }       return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<long long int> fact(2000006);   vector<long long int> prime_check(1e7 + 2);   vector<long long int> primes;   long long powmod(long long x, long long y, long long m) {     long long res = 1LL;     while (y) {       if (y & 1) res = (res * x) % m;       x = (x * x) % m;       y /= 2;     }     return res;   }   void init_fact() {     fact[0] = 1;     for (long long int i = 1; i < 2000006; i++) {       fact[i] = (fact[i - 1] * i) % 1000000007;     }   }   long long int C(long long int n, long long int r) {     if (n < r) return 0;     long long int temp =         fact[n] * powmod(fact[r], 1000000007 - 2, 1000000007) % 1000000007;     temp *= powmod(fact[n - r], 1000000007 - 2, 1000000007);     temp %= 1000000007;     return temp;   }   void Sieve() {     for (long long int i = 2; i <= 1e7 + 1; i++) {       if (prime_check[i]) continue;       primes.push_back(i);       for (long long int j = 2 * i; j <= 1e7 + 1; j += i) prime_check[j] = i;     }   }   long long int phi(long long int n) {     long long int i, res = n;     for (i = 2; i * i <= n; i++)       if (n % i == 0) {         while (n % i == 0) n /= i;         res -= res / i;       }     if (n > 1) res -= res / n;     return res;   }   long long int n, x, y;   vector<long long int> a(2000006), b(2000006), cnt(2000006), sum(2000006);   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cin >> n >> x >> y;     for (long long int i = 1; i <= n; i++) cin >> a[i], b[a[i]]++;     for (long long int i = 1; i < 2000006; i++)       cnt[i] = cnt[i - 1] + b[i], sum[i] = sum[i - 1] + b[i] * i;     long long int c = x / y;     long long int ans = INT64_MAX;     for (long long int i = 2; i <= 1e6; i++) {       long long int cost = 0, f = i - min(i, c);       for (long long int j = 0; j <= 1e6; j += i) {         long long int st = j + 1, en = j + i, st2 = max(st, st + f - 1);         long long int c1 = cnt[st2 - 1] - cnt[st - 1];         long long int c2 = cnt[en] - cnt[st2 - 1];         long long int c3 = sum[en] - sum[st2 - 1];         cost += c1 * x + y * (c2 * en - c3);       }       ans = min(ans, cost);     }     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     int x1, y1, x2, y2;     cin >> x1 >> y1 >> x2 >> y2;     if ((x1 <= x2 && y1 <= y2) || x1 + y1 <= max(x2, y2)) {       cout <<  Polycarp ;     } else {       cout <<  Vasiliy ;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0), cout.tie(0);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, a[6], t;   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d , &t), a[t]++;     }     if (a[0] == 0) {       printf( -1 n );       return 0;     }     int k = a[5] / 9;     for (int i = 0; i < k; i++) {       printf( 555555555 );     }     if (k == 0) {       printf( 0 n );     } else {       while (a[0]--) printf( 0 );       printf(  n );     }     return 0;   }


#include <bits/stdc++.h>   const int MAXN = 210;   const int mod = 1e9 + 7;   void reduce(int& x) { x += x >> 31 & mod; }   int mul(int x, int y) { return (long long)x * y % mod; }   void fma(int& x, int y, int z) { x = ((long long)y * z + x) % mod; }   struct vec {     int x, y;     vec() { x = y = 0; }     vec(int a, int b) { x = a, y = b; }     vec operator+(vec b) const { return vec(x + b.x, y + b.y); }     vec operator-(vec b) const { return vec(x - b.x, y - b.y); }     long long operator^(vec b) const {       return (long long)x * b.y - (long long)y * b.x;     }     long long operator*(vec b) const {       return (long long)x * b.x + (long long)y * b.y;     }     bool operator==(vec b) const { return x == b.x && y == b.y; }   } ps[MAXN];   int n;   long long cross(vec x, vec y, vec z) { return (y - x) ^ (z - x); }   inline int sgn(long long x) { return x < 0 ? -1 : x > 0; }   int dp[MAXN][MAXN];   int main() {     std::ios_base::sync_with_stdio(false), std::cin.tie(0);     std::cin >> n;     for (int i = 1; i <= n; ++i) std::cin >> ps[i].x >> ps[i].y;     long long area = 0;     for (int i = 1; i <= n; ++i) area += ps[i] ^ ps[i == n ? 1 : i + 1];     for (int i = 1; i < n; ++i) dp[i][i + 1] = 1;     for (int L = 3; L <= n; ++L)       for (int l = 1; l + L - 1 <= n; ++l) {         int r = l + L - 1;         for (int p = l + 1; p < r; ++p)           if (sgn(cross(ps[p], ps[r], ps[l])) == sgn(area))             fma(dp[l][r], dp[l][p], dp[p][r]);       }     std::cout << dp[1][n] << std::endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 998244353;   template <int mod = mod>   struct Modular {     int val;     Modular() { val = 0; }     Modular(long long _val) { val = Normalize(_val); }     Modular(int _val) { val = Normalize(_val); }     inline int Normalize(long long& _val) {       if (_val < 0) _val = _val % mod + mod;       if (_val >= mod) _val %= mod;       return _val;     }     inline int Normalize(int& _val) {       if (_val < 0) _val = _val % mod + mod;       if (_val >= mod) _val %= mod;       return _val;     }     inline Modular modinv(int a, int m = mod) {       int u = 0, v = 1;       while (a != 0) {         int t = m / a;         m -= t * a;         swap(a, m);         u -= t * v;         swap(u, v);       }       assert(m == 1);       return u;     }     inline Modular modinv() { return modinv(val); }     inline Modular modpow(long long p) const {       assert(p >= 0);       Modular a = *this, result = 1;       while (p > 0) {         if (p & 1) result *= a;         a *= a;         p >>= 1;       }       return result;     }     static unsigned Fastmod(uint64_t x, unsigned m = mod) {       return x % m;       unsigned xhi = x >> 32, xlo = (unsigned)x;       unsigned q, r;       asm( divl %4 n  :  =a (q),  =d (r) :  d (xhi),  a (xlo),  r (m));       return r;     }     inline Modular& operator+=(const Modular& other) {       val += other.val;       if (val >= mod) val -= mod;       return *this;     }     inline Modular& operator-=(const Modular& other) {       val -= other.val;       if (val < 0) val += mod;       return *this;     }     inline Modular& operator%=(const Modular& other) {       val %= other.val;       return *this;     }     inline Modular& operator*=(const Modular& other) {       val = Fastmod((uint64_t)val * other.val);       return *this;     }     inline Modular& operator/=(const Modular& other) {       return *this *= modinv(other.val);     }     inline friend Modular operator+(const Modular& a, const Modular& b) {       return Modular(a) += b;     }     inline friend Modular operator-(const Modular& a, const Modular& b) {       return Modular(a) -= b;     }     inline friend Modular operator%(const Modular& a, const Modular& b) {       return Modular(a) %= b;     }     inline friend Modular operator*(const Modular& a, const Modular& b) {       return Modular(a) *= b;     }     inline friend Modular operator/(const Modular& a, const Modular& b) {       return Modular(a) /= b;     }     inline friend istream& operator>>(istream& stream, Modular& m) {       long long x;       stream >> x;       m.val = m.Normalize(x);       return stream;     }     inline friend ostream& operator<<(ostream& stream, const Modular& m) {       return stream << m.val;     }     inline Modular operator++() { return *this += 1; }     inline Modular operator--() { return *this -= 1; }     inline Modular operator++(int) {       Modular x = *this;       ++*this;       return x;     }     inline Modular operator--(int) {       Modular x = *this;       --*this;       return x;     }     inline Modular operator-() const { return Modular(-val); }     inline friend bool operator==(const Modular& a, const Modular& b) {       return a.val == b.val;     }     inline friend bool operator!=(const Modular& a, const Modular& b) {       return a.val != b.val;     }     inline friend bool operator>(const Modular& a, const Modular& b) {       return a.val > b.val;     }     inline friend bool operator<(const Modular& a, const Modular& b) {       return a.val < b.val;     }     inline friend bool operator>=(const Modular& a, const Modular& b) {       return a.val >= b.val;     }     inline friend bool operator<=(const Modular& a, const Modular& b) {       return a.val <= b.val;     }   };   const int G = 3;   const int N = 1 << 20;   Modular<mod> root[1 << 20];   Modular<mod> _pow2[(1 << 20) + 1];   struct ntt {     ntt() {       root[N / 2] = 1;       root[N / 2 + 1] = ((Modular<mod>)G).modpow((mod - 1) / N);       for (int i = N / 2 + 2; i < N; ++i) root[i] = root[i - 1] * root[N / 2 + 1];       for (int i = N / 2; --i;) root[i] = root[2 * i];       for (int i = 0; i <= 20; i++)         _pow2[1 << i] = ((Modular<mod>)(1 << i)).modinv();     }     vector<Modular<mod> > Convolute(vector<Modular<mod> >& a,                                     vector<Modular<mod> >& b) {       int s = a.size() + b.size() - 1, n = 1;       while (n < s) n *= 2;       vector<Modular<mod> > c(n);       a.resize(n);       NTT(a);       b.resize(n);       NTT(b);       for (int i = 0; i < n; i++) c[i] = a[i] * b[i] * _pow2[n];       reverse(c.begin() + 1, c.end());       NTT(c);       c.resize(s);       return c;     }     void NTT(vector<Modular<mod> >& a) {       int n = a.size();       for (int i = 0, j = 0; i < n; ++i) {         if (i > j) swap(a[i], a[j]);         for (int k = n / 2; (j ^= k) < k; k /= 2)           ;       }       for (int k = 1; k < n; k *= 2) {         for (int i = 0; i < n; i += 2 * k) {           for (int j = 0; j < k; j++) {             Modular<mod> z = root[j + k] * a[i + j + k], &ai = a[i + j];             a[i + j + k] = ai - z;             ai += z;           }         }       }     }   } NTT;   void solve() {     int n, x, y;     cin >> n >> x >> y;     vector<Modular<mod> > a(x + 1);     for (int i = 0; i <= n; ++i) {       int var;       cin >> var;       a[var] = 1;     }     vector<Modular<mod> > b = a;     reverse(begin(b), end(b));     b = NTT.Convolute(a, b);     vector<int> c(1e6 + 1);     for (int i = 0; i < int(b.size()); ++i) {       if (b[i] == 0 || !(abs(x - i))) continue;       int idx = 2 * (y + abs(x - i));       if (idx <= 1e6) c[idx] = 1;     }     vector<int> dp(1e6 + 1);     for (int i = 2; i <= 1e6; ++i) {       if (!c[i]) continue;       for (int j = i; j <= 1e6; j += i) {         dp[j] = max(dp[j], i);       }     }     int q;     cin >> q;     while (q--) {       int l;       cin >> l;       if (dp[l]) {         cout << dp[l] <<    ;         continue;       }       cout << -1 <<    ;     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int t;     t = 1;     while (t--) solve();   }


#include <bits/stdc++.h>   using namespace std;   const int N = 505;   long long dp_hor[2][N][N], dp_vert[2][N][N];   vector<pair<int, int>> cost_hor[N][N], cost_vert[N][N];   long long inf = 1e18;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n, m, k;     cin >> n >> m >> k;     for (int i = 1; i <= k; i++) {       int x, y, d, t, e;       cin >> x >> y >> d >> t >> e;       if (x + y >= t && ((x + y) % 4) == (t % 4))         cost_hor[x][y].push_back({1e9, e}), cost_vert[x][y].push_back({1e9, e});       if (x + y >= t + 1 && ((x + y) % 4) == ((t + 1) % 4))         cost_hor[x + d][y - d].push_back({1e9, e}),             cost_vert[x + d][y - d].push_back({1e9, e});       if (x + y + d >= t + 2 && ((x + y + d) % 4) == ((t + 2) % 4)) {         if (x + y >= t + 1 && ((x + y) % 4) == ((t + 1) % 4))           cost_hor[x + d][y].push_back({d, e});         else           cost_hor[x + d][y].push_back({1e9, e});         if (x + y >= t && ((x + y) % 4) == (t % 4))           cost_vert[x + d][y].push_back({d, e});         else           cost_vert[x + d][y].push_back({1e9, e});       }       if (x + y + d >= t + 3 && ((x + y + d) % 4) == ((t + 3) % 4)) {         if (x + y >= t && ((x + y) % 4) == (t % 4))           cost_hor[x][y + d].push_back({d, e});         else           cost_hor[x][y + d].push_back({1e9, e});         cost_vert[x][y + d].push_back({1e9, e});       }     }     for (int x = 0; x < 2; x++)       for (int y = 0; y < N; y++)         for (int z = 0; z < N; z++) dp_hor[x][y][z] = dp_vert[x][y][z] = inf;     for (int x = 0; x < n; x++) {       for (int y = 0; y < m; y++) {         int f = x & 1;         for (int z = 0; z < N; z++) dp_hor[f][y][z] = dp_vert[f][y][z] = inf;         if (x == 0 && y == 0) {           dp_hor[f][y][0] = dp_vert[f][y][0] = 0;         }         sort(cost_hor[x][y].begin(), cost_hor[x][y].end());         sort(cost_vert[x][y].begin(), cost_vert[x][y].end());         long long cost = 0;         for (int z = y; z >= 1; z--) {           while (cost_hor[x][y].size() > 0 && cost_hor[x][y].back().first > z) {             pair<int, int> t = cost_hor[x][y].back();             cost_hor[x][y].pop_back();             cost += t.second;           }           dp_hor[f][y][z] = dp_hor[f][y - 1][z - 1] + cost;         }         cost = 0;         for (int z = x; z >= 1; z--) {           while (cost_vert[x][y].size() > 0 && cost_vert[x][y].back().first > z) {             pair<int, int> t = cost_vert[x][y].back();             cost_vert[x][y].pop_back();             cost += t.second;           }           dp_vert[f][y][z] = dp_vert[f ^ 1][y][z - 1] + cost;         }         for (int z = 1; z <= x; z++) {           dp_hor[f][y][0] = min(dp_hor[f][y][0], dp_vert[f][y][z]);         }         for (int z = 1; z <= y; z++) {           dp_vert[f][y][0] = min(dp_vert[f][y][0], dp_hor[f][y][z]);         }       }     }     long long ans = inf;     for (int z = 1; z < m; z++) {       ans = min(ans, dp_hor[(n - 1) & 1][m - 1][z]);     }     for (int z = 1; z < n; z++) {       ans = min(ans, dp_vert[(n - 1) & 1][m - 1][z]);     }     if (ans == inf) ans = 0;     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   template <typename Arg1>   void __f(const char* name, Arg1&& arg1) {     cerr << name <<   :   << arg1 << std::endl;   }   template <typename Arg1, typename... Args>   void __f(const char* names, Arg1&& arg1, Args&&... args) {     const char* comma = strchr(names + 1,  , );     cerr.write(names, comma - names) <<   :   << arg1 <<   |  ;     __f(comma + 1, args...);   }   template <class T>   ostream& operator<<(ostream& os, vector<T> V) {     os <<  [  ;     for (auto v : V) os << v <<    ;     return os <<  ] ;   }   template <class L, class R>   ostream& operator<<(ostream& os, pair<L, R> P) {     return os <<  (  << P.first <<  ,  << P.second <<  ) ;   }   const long long int mod = 1e9 + 7;   const long long int maxn = 5 * 100001;   long long int power(long long int x, long long int n) {     x %= mod;     long long int res = 1;     for (; n > 0; n >>= 1) {       if (n & 1) res = (res * x) % mod;       x = (x * x) % mod;     }     return res;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int n;     cin >> n;     pair<long long int, long long int> a[n];     for (long long int i = 0; i < n; i++) {       cin >> a[i].first;       a[i].second = i + 1;     }     sort(a, a + n);     long long int dp[n + 1];     dp[n] = 0;     dp[n - 1] = mod;     dp[n - 2] = mod;     dp[n - 3] = a[n - 1].first - a[n - 3].first;     long long int got[n + 5];     got[n - 3] = n;     got[n - 2] = n;     got[n - 1] = n;     for (long long int i = n - 4; i >= 0; i--) {       long long int mini = mod;       mini = min(mini, a[i + 2].first - a[i].first + dp[i + 3]);       if (i + 4 <= n) mini = min(mini, a[i + 3].first - a[i].first + dp[i + 4]);       if (i + 5 <= n) mini = min(mini, a[i + 4].first - a[i].first + dp[i + 5]);       for (long long int j = 2; j <= 4; j++) {         if (j + i + 1 <= n) {           if (mini == a[i + j].first - a[i].first + dp[i + j + 1]) {             got[i] = i + j + 1;             break;           }         }       }       dp[i] = mini;     }     long long int ans[n + 1];     long long int m = 0;     for (long long int i = 0, j = 0; i < n; i = j) {       m++;       while (j != got[i]) {         ans[a[j].second] = m;         j++;       }     }     cout << dp[0] <<     << m << endl;     for (long long int i = 1; i <= n; i++) {       cout << ans[i] <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int inf = INT_MAX;   int n;   struct node {     long double x, y;   } a[100010];   bool check(long double xx) {     long double l, r;     l = -1e19, r = 1e19;     for (int i = 0; i < n; ++i) {       if (a[i].y >= xx * 2 || l > r) return false;       l = max(l, a[i].x - sqrt(2 * a[i].y * xx - a[i].y * a[i].y));       r = min(r, a[i].x + sqrt(2 * a[i].y * xx - a[i].y * a[i].y));     }     return l <= r;   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n; ++i) scanf( %lf%lf , &a[i].x, &a[i].y);     for (int i = 0; i < n; ++i)       if (a[i].y * a[n - 1].y < 0) {         printf( -1 );         return 0;       } else         a[i].y = (a[i].y > 0) ? a[i].y : -a[i].y;     long double l = 0, r = 1e19, mid;     for (int i = 0; i <= 100; i++) {       mid = (l + r) / 2;       if (check(mid))         r = mid;       else         l = mid;     }     printf( %.10Lf , mid);   }


#include <bits/stdc++.h>   #include <algorithm>   #include <unordered_map>   using namespace std;      typedef long long ll;   typedef vector<long long int> vll;   typedef vector<int> vi;   typedef unordered_map<int, int> umap;   typedef vector<bool> vb;   typedef pair<int, int> pii;   typedef vector<pii> vpii;   typedef vector<pair<int, vi>> vpiv;   typedef unordered_map<ll, vll> ull;   typedef set<ll> sll;      #define min(a, b) ((a > b) ? b : a)   #define max(a, b) ((a > b) ? a : b)   #define run(i, n) for (int i = 0; i < n; i++)   #define rund(i, n) for (int i = n - 1; i >= 0; i--)   #define in(v) insert(v)   #define pb(v) push_back(v)   #define mp(v, u) make_pair(v, u)   #define MOD 1000000007   #define lim 10000000   #define INF 1000000009   #define f first   #define s second   #define yes cout <<  YES  << endl   #define no cout <<  NO  << endl   //-------------------Number theory------------   // generate prime numbers till n   vb seive(int n)   {       vb prime(n + 1, true);       prime[0] = false;       prime[1] = false;       for (ll i = 2; i * i <= n; i++)       {           if (prime[i])               for (ll j = i * i; j <= n; j += i)               {                   prime[j] = false;               }       }       return prime;   }      //euler totient function   vll totient(ll n)   {       vll tot(n + 1);       run(i, n + 1)       {           tot[i] = i;       }       for (int i = 2; i * i <= n; i++)       {           if (tot[i] == i)           {               for (int j = i; j <= n; j += i)               {                   tot[j] /= i;                   tot[j] *= i - 1;               }           }       }       return tot;   }   //modular exponentiation   ll modExp(ll a, ll n, ll p)   {       if (n == 1)       {           return a % p;       }       if (n % 2)       {           ll t = modExp(a, n / 2, p);           return (a * t % p * t) % p;       }       else       {           ll t = modExp(a, n / 2, p);           return t % p * t % p;       }   }   //a inverse mod p, where a and p are coprime   ll modInv(ll a, ll p, vb prime)   {       // we know if a and p are coprime then a^totient(p) = 1 mod p => a^{totient(p)-1}=a^-1 mod p       vll tmp = totient(p);       ll t = tmp[t];       return modExp(a, t, p);   }      //----------------Segment Tree -SUM -----------------------------------------------   void buildSeg(int *a, int *t, int v, int l, int r)   {       //initially v should be passed as 1       //declare t in main method       if (l == r)       {           t[v] = a[l];           return;       }       int m = (l + r) / 2;       buildSeg(a, t, 2 * v, l, m);         //build Left sub-tree       buildSeg(a, t, 2 * v + 1, m + 1, r); //build Right sub-tree       // store the sum of left and right sub-segments in the present node       t[v] = t[2 * v] + t[2 * v + 1];   }      ll sumQuery(int *t, int v, int tl, int tr, int l, int r)   {       // start = 0 and end = n-1 initially .       // v initially should be 1 .       if (l > r)       {           return 0;       }       if (tl == l && tr == r)       {           return t[v];       }       else       {           int tm = (tl + tr) / 2;           if (tl <= l && l <= tm && tl <= r && r <= tm)           {               // the query range is completely in left sub-segment               return sumQuery(t, 2 * v, tl, tm, l, r);           }           else if (tm < l && l <= tr && tm < r && r <= tr)           {               return sumQuery(t, 2 * v + 1, tm + 1, tr, l, r);           }           else           {               ll s1 = sumQuery(t, 2 * v, tl, tm, l, tm);               ll s2 = sumQuery(t, 2 * v + 1, tm + 1, tr, tm + 1, r);               return s1 + s2;           }       }   }      // few helpers   void print(vll a)   {       for (int i = 0; i < a.size(); i++)       {           cout << a[i] <<    ;       }       cout << endl;   }      void inp(vll &a)   {       int i = 0;       for (auto &it : a)       {           int t;           cin >> t;           it = t;       }   }   class myComparator   {   public:       bool operator()(pair<ll, ll> &p1, pair<ll, ll> &p2)       {           if (p1.first < p2.first)               return true;           else if (p1.first == p2.first)               return p1.second > p2.second;           else               return false;       }   };   class four   {   public:       ll x1, y1, x2, y2;   };   int p1 = 1000000007;   int p2 = 1824236251;   ll p = 998244353;      //----------------MAIN METHOD (Code)------------------------------------------------   ll merge(vll& arr, vll& left, vll& right) {       ll i = 0, j = 0, count = 0;       while (i < left.size() || j < right.size()) {           if (i == left.size()) {               arr[i+j] = right[j];               j++;           } else if (j == right.size()) {               arr[i+j] = left[i];               i++;           } else if (left[i] <= right[j]) {               arr[i+j] = left[i];               i++;                           } else {               arr[i+j] = right[j];               count += left.size()-i;               j++;           }       }       return count;   }      ll getInvCount(vll& arr) {       if (arr.size() < 2)           return 0;          int m = (arr.size() + 1) / 2;       vll left(arr.begin() , arr.begin()+m);       vll right(arr.begin()+ m, arr.end());          return getInvCount(left) + getInvCount(right) + merge(arr, left, right);   }   ll findInv(string &tmp , string&s , unordered_map<char,vector<ll>>& t){       int inv = 0;       int c1 =0,c2 =0 , c3 = 0 , c4 =0;       vector<ll> id;       for(auto i:tmp ){           if(i== A ){               id.pb(t[ A ][c1++]);           }           if(i== N ){               id.pb(t[ N ][c2++]);           }           if(i== O ){               id.pb(t[ O ][c3++]);           }           if(i== T ){               id.pb(t[ T ][c4++]);           }       }       // print(id);       return getInvCount(id);   }      int main()   {       ios::sync_with_stdio(0);       cin.tie(0);       cout.tie(0);       int t ; cin>>t;       while(t--){           string s;cin>>s;           unordered_map<char,int> freq;           unordered_map<char,vll> rec;           string ans =  ;           ll inversion_number = 0;           vector<char> letter = { A , N , O , T };           for(int i=0;i<s.length();i++){               freq[s[i]] ++;               rec[s[i]].pb(i);           }           int i = 1;           do{               string tmp =  ;               for(auto c : letter){                   run(i,freq[c]){                       tmp+=c;                   }               }               // cout<<tmp<<endl;               ll temp = findInv(tmp,s,rec);               if(temp >= inversion_number){                   inversion_number = temp;                   ans = tmp;               }                          }while( next_permutation(letter.begin(),letter.end()));              cout<<ans<<endl;       }          }


#include <bits/stdc++.h>   using namespace std;   const unsigned long long N = 1e10;   int getLen(unsigned long long a) {     int len = 0;     while (a) {       len++;       a /= 10;     }     return len;   }   unsigned long long gcd(unsigned long long a, unsigned long long b) {     return b == 0 ? a : gcd(b, (a % b));   }   unsigned long long lcm(unsigned long long a, unsigned long long b) {     unsigned long long t = gcd(a, b);     if (getLen(a / t) + getLen(b) > 22) return 0;     return a / gcd(a, b) * b;   }   int main() {     unsigned long long t, w, b;     unsigned long long p;     cin >> t >> w >> b;     if (w == b) {       printf( 1/1 n );       return 0;     }     unsigned long long mi = min(w, b);     if (t < mi) {       printf( 1/1 n );       return 0;     }     unsigned long long l = lcm(w, b);     if (l <= 0)       p = mi - 1;     else {       unsigned long long x = t / l;       if (x == 0) {         p = mi - 1;       } else {         p = min(mi, t - x * l + 1) + x * mi - 1;       }     }     unsigned long long d = gcd(p, t);     printf( %lld/%lld n , p / d, t / d);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   istream& operator>>(istream& is, vector<T>& v) {     for (T& x : v) is >> x;     return is;   }   template <typename T>   ostream& operator<<(ostream& os, const vector<T>& v) {     for (int i = 0; i < (int)v.size(); i++) {       os << v[i] << (i + 1 == (int)v.size() ?    :    );     }     return os;   }   template <typename T, typename U>   ostream& operator<<(ostream& os, const pair<T, U>& p) {     os <<  (  << p.first <<  ,  << p.second <<  ) ;     return os;   }   template <typename T, typename U, typename V>   ostream& operator<<(ostream& os, const tuple<T, U, V>& t) {     os <<  (  << get<0>(t) <<  ,  << get<1>(t) <<  ,  << get<2>(t) <<  ) ;     return os;   }   template <typename T, typename U, typename V, typename W>   ostream& operator<<(ostream& os, const tuple<T, U, V, W>& t) {     os <<  (  << get<0>(t) <<  ,  << get<1>(t) <<  ,  << get<2>(t) <<  ,         << get<3>(t) <<  ) ;     return os;   }   template <typename T, typename U>   ostream& operator<<(ostream& os, const map<T, U>& m) {     os <<  { ;     for (auto itr = m.begin(); itr != m.end();) {       os <<  (  << itr->first <<  ,  << itr->second <<  ) ;       if (++itr != m.end()) os <<  , ;     }     os <<  } ;     return os;   }   template <typename T, typename U>   ostream& operator<<(ostream& os, const unordered_map<T, U>& m) {     os <<  { ;     for (auto itr = m.begin(); itr != m.end();) {       os <<  (  << itr->first <<  ,  << itr->second <<  ) ;       if (++itr != m.end()) os <<  , ;     }     os <<  } ;     return os;   }   template <typename T>   ostream& operator<<(ostream& os, const set<T>& s) {     os <<  { ;     for (auto itr = s.begin(); itr != s.end();) {       os << *itr;       if (++itr != s.end()) os <<  , ;     }     os <<  } ;     return os;   }   template <typename T>   ostream& operator<<(ostream& os, const multiset<T>& s) {     os <<  { ;     for (auto itr = s.begin(); itr != s.end();) {       os << *itr;       if (++itr != s.end()) os <<  , ;     }     os <<  } ;     return os;   }   template <typename T>   ostream& operator<<(ostream& os, const unordered_set<T>& s) {     os <<  { ;     for (auto itr = s.begin(); itr != s.end();) {       os << *itr;       if (++itr != s.end()) os <<  , ;     }     os <<  } ;     return os;   }   template <typename T>   ostream& operator<<(ostream& os, const deque<T>& v) {     for (int i = 0; i < (int)v.size(); i++) {       os << v[i] << (i + 1 == (int)v.size() ?    :    );     }     return os;   }   void debug_out() { cerr <<   n ; }   template <class Head, class... Tail>   void debug_out(Head&& head, Tail&&... tail) {     cerr << head;     if (sizeof...(Tail) > 0) cerr <<  ,  ;     debug_out(move(tail)...);   }   template <typename T>   T gcd(T x, T y) {     return y != 0 ? gcd(y, x % y) : x;   }   template <typename T>   T lcm(T x, T y) {     return x / gcd(x, y) * y;   }   template <class T1, class T2>   inline bool chmin(T1& a, T2 b) {     if (a > b) {       a = b;       return true;     }     return false;   }   template <class T1, class T2>   inline bool chmax(T1& a, T2 b) {     if (a < b) {       a = b;       return true;     }     return false;   }   const int INF = 1e9;   const long long IINF = 1e18;   const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};   const char dir[4] = { D ,  R ,  U ,  L };   const long long MOD = 1000000007;   namespace n91 {   using usize = std::size_t;   using u64 = std::uint64_t;   std::vector<bool> stob(std::string s) {     std::vector<u64> num(s.size() / 9 + 10, 0);     for (usize i = 0; i < s.size(); i += 9) {       const std::string t = s.substr(i, 9);       u64 mul = 1;       u64 add = 0;       for (const auto c : t) {         add = add * 10 + (c -  0 );         mul *= 10;       }       for (auto& d : num) {         d = d * mul + add;         add = d >> 32;         d -= add << 32;       }     }     std::vector<bool> res(num.size() * 32);     for (usize i = 0; i < num.size(); ++i) {       for (usize j = 0; j < 32; ++j) {         res[i * 32 + j] = num[i] >> j & 1;       }     }     while (!res.empty() && !res.back()) {       res.pop_back();     }     return res;   }   }  // namespace n91   const int MAX = 2048;   using u64 = uint64_t;   using BS = bitset<2 * MAX>;   BS calc(const string& s) {     int n = s.size();     vector<u64> num(n / 9 + 10, 0);     for (int i = 0; i < n; i += 9) {       string t = s.substr(i, 9);       u64 mul = 1, add = 0;       for (auto c : t) {         add = add * 10 + (c -  0 );         mul *= 10;       }       for (auto& d : num) {         d = d * mul + add;         add = d >> 32;         d -= add << 32;       }     }     BS res;     for (int i = 0; i < num.size(); i++) {       for (int j = 0; j < 32; j++) {         res[i * 32 + j] = num[i] >> j & 1;       }     }     return res;   }   vector<BS> bases;   vector<int> idx(MAX, -1);   vector<int> solve(BS b, int x) {     for (int i = MAX - 1; i >= 0; i--) {       if (!b[i]) continue;       if (~idx[i])         b ^= bases[idx[i]];       else {         b.set(MAX + x, 1);         idx[i] = bases.size();         bases.emplace_back(b);         return {};       }     }     vector<int> res;     for (int i = 0; i < MAX; i++) {       if (b[MAX + i]) {         res.emplace_back(i);       }     }     return res;   };   int main() {     cin.tie(0);     ios::sync_with_stdio(false);     int m;     cin >> m;     for (int i = 0; i < m; i++) {       string S;       cin >> S;       vector<int> ans = solve(calc(S), i);       cout << ans.size();       for (int x : ans) cout <<     << x;       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 300;   inline long long read() {     long long s = 0, ww = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) ww = -1;       ch = getchar();     }     while ( 0  <= ch && ch <=  9 ) {       s = 10 * s + ch -  0 ;       ch = getchar();     }     return s * ww;   }   struct vec {     long long x, y;     vec() {}     vec(long long _x, long long _y) { x = _x, y = _y; }     inline friend vec operator-(vec a, vec b) {       return vec(a.x - b.x, a.y - b.y);     }     inline friend long long Cross(vec a, vec b) { return a.x * b.y - a.y * b.x; }     inline friend bool InUpper(vec a) { return a.y > 0 || (a.y == 0 && a.x > 0); }   } p[N + 5];   inline bool cmp(pair<long long, long long> i, pair<long long, long long> j) {     vec a = p[i.second] - p[i.first], b = p[j.second] - p[j.first];     bool k1 = InUpper(a), k2 = InUpper(b);     if (k1 != k2) return k1 < k2;     return Cross(a, b) > 0;   }   long long f[N + 5][N + 5][7];   long long n;   pair<long long, long long> seg[N * N + 5];   int main() {     n = read();     for (register int i = 1; i <= n; i++) {       long long x = read(), y = read();       p[i] = vec(x, y);     }     int cnt = 0;     for (register int i = 1; i <= n; i++)       for (register int j = 1; j <= n; j++)         if (i != j) seg[++cnt] = make_pair(i, j);     sort(seg + 1, seg + cnt + 1, cmp);     for (register int i = 1; i <= n; i++) f[i][i][1] = 1;     for (register int k = 1; k <= cnt; k++) {       int u = seg[k].first, v = seg[k].second;       for (register int i = 1; i <= n; i++)         for (register int j = 1; j <= 5; j++) f[i][v][j + 1] += f[i][u][j];     }     long long ans = 0;     for (register int i = 1; i <= n; i++) ans += f[i][i][6];     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     int S;     cin >> S;     if (S == 1) {       cout << 1 <<     << 1 <<   n ;       cout << 1 <<   n ;       return 0;     }     cout << (S - 1) * 2 <<     << 2 <<   n ;     cout << 1 <<     << 2;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 2000 + 10;   bool mrk[MAX_N][MAX_N];   bool Ver[MAX_N][MAX_N];   bool Hor[MAX_N][MAX_N];   int N;   int Total;   void Solve(int x, int y) {     bool flag = false;     if ((mrk[x][y] ^ Ver[x][y] ^ Hor[x][y]) == 1) flag = true;     int dx = -1, dy = 1;     if (x < y) dx = 1, dy = -1;     if (x + dx != y + dx) Ver[x + dx][y] ^= (Ver[x][y] ^ flag);     if (y + dy != x + dy) Hor[x][y + dy] ^= (Hor[x][y] ^ flag);     mrk[x][y] ^= flag;     if (flag) Total++;   }   int main() {     ios::sync_with_stdio(false);     cin >> N;     for (int i = 0; i < N; i++)       for (int j = 0; j < N; j++) {         char temp;         cin >> temp;         mrk[j][i] = (temp -  0 );       }     for (int l = 0; l < N; l++)       for (int i = 0; i <= l; i++) {         Solve(N - 1 - i, l - i);         Solve(i, N - 1 - (l - i));       }     cout << Total << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int m, n, i, j, l, r, u, d, sum;     char s[209];     while (scanf( %d , &n) != EOF) {       getchar();       scanf( %s , s);       sum = 0;       for (i = 0; i < n; i++) {         l = r = u = d = 0;         for (j = i + 1; j < n; j++) {           int x = 1, y = 1;           for (int k = i; k <= j; k++) {             if (s[k] ==  U )               y++;             else if (s[k] ==  D )               y--;             else if (s[k] ==  L )               x--;             else               x++;           }           if (x == 1 && y == 1) sum++;         }       }       printf( %d n , sum);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int p, numb, hh, i, j, l, n, m, a;   char k;   bool flag;   int h[200000], check[500000], check1[500000], prime[500000], dp[500000];   int main() {     for (i = 2; i <= 100000; i++)       if (check[i] == 0) {         for (j = 2 * i; j <= 100000; j += i) check[j] = 1;       }     for (i = 2; i <= 100000; i++)       if (check[i] == 0) {         l++;         prime[l] = i;       }     cin >> n >> m;     for (i = 1; i <= m; i++) {       cin >> k >> a;       hh = a;       flag = true;       if (k ==  + ) {         if (dp[a] == 1) {           cout <<  Already on  << endl;         } else if (a == 1) {           dp[a] = 1;           cout <<  Success  << endl;         } else {           numb = 0;           hh = a;           for (j = 1; prime[j] * prime[j] <= a; j++)             if (a % prime[j] == 0) {               while (a % prime[j] == 0) a /= prime[j];               if (check1[prime[j]] > 0) {                 cout <<  Conflict with   << check1[prime[j]] << endl;                 flag = false;                 break;               } else {                 numb++;                 h[numb] = prime[j];               }             }           if (flag) {             if (check[a] == 0 && a > 1) {               if (check1[a] > 0) {                 cout <<  Conflict with   << check1[a] << endl;                 flag = false;               } else                 check1[a] = hh;             }             if (flag) {               for (p = 1; p <= numb; p++) check1[h[p]] = hh;               cout <<  Success  << endl;               dp[hh] = 1;             }           }         }       } else {         if (dp[a] == 1) {           hh = a;           cout <<  Success  << endl;           for (j = 1; prime[j] * prime[j] <= a; j++)             if (a % prime[j] == 0) {               while (a % prime[j] == 0) a /= prime[j];               check1[prime[j]] = 0;             }           if (check[a] == 0 && a > 1) check1[a] = 0;           dp[hh] = 0;         } else           cout <<  Already off  << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int n, a, b, k[100100];   const int du = 0.000001;   bool cmp(int x, int y) { return x > y; }   int main() {     scanf( %d%d%d , &n, &a, &b);     long long sum = 0;     for (int i = 1; i <= n; ++i) {       scanf( %d , &k[i]);       sum += k[i];     }     if (a == b) {       printf( %d , n - 1);       return 0;     }     sort(k + 2, k + 1 + n, cmp);     double cnt = 0;     int xx = sum;     double hah = b;     cnt = a * k[1] / 1.0 / xx;     if (cnt >= b) {       printf( 0 n );       return 0;     }     for (int i = 2; i <= n; ++i) {       xx = xx - k[i];       cnt = a * k[1] / 1.0 / xx;       if (cnt >= b) {         printf( %d n , i - 1);         return 0;       }     }     printf( %d n , n);     return 0;   }