#include <bits/stdc++.h>   using namespace std;   vector<int> E[100005];   int head, tail, A[300], B[300];   int N, M, H, T, marked[100005];   bool ok;   void checkHydra(int x) {     int heads = 0;     for (int i = 0; i < int(E[x].size()); ++i) marked[E[x][i]] = 1, ++heads;     if (heads >= H) {       for (vector<int>::iterator it = E[x].begin(); it != E[x].end() && !ok;            ++it) {         --heads;         int tails = 0;         int common = 0;         for (vector<int>::iterator jt = E[*it].begin(); jt != E[*it].end() && !ok;              ++jt) {           if (*jt == x) continue;           ++tails;           if (marked[*jt]) ++common;           if (heads >= H && tails >= T && heads + tails - common >= H + T) {             ok = true;             head = x;             tail = *it;           }         }         ++heads;       }     }     for (int i = 0; i < int(E[x].size()); ++i) marked[E[x][i]] = 0;   }   int main() {     cin >> N >> M >> H >> T;     for (int i = 0; i < M; ++i) {       int x, y;       cin >> x >> y;       E[x].push_back(y);       E[y].push_back(x);     }     ok = false;     for (int i = 1; i <= N && !ok; ++i) checkHydra(i);     if (!ok) {       cout <<  NO ;       return 0;     }     cout <<  YES n ;     cout << head <<     << tail <<   n ;     for (auto &it : E[head])       if (it != tail) marked[it]++;     for (auto &it : E[tail])       if (it != head) marked[it]++;     N = M = 0;     for (auto &it : E[head])       if (marked[it] == 1)         if (N < H) {           A[N++] = it;           marked[it] = 0;         }     for (auto &it : E[tail])       if (marked[it] == 1)         if (M < T) {           B[M++] = it;           marked[it] = 0;         }     for (auto &it : E[head])       if (marked[it] == 2)         if (N < H) {           A[N++] = it;           marked[it] = 0;         }     for (auto &it : E[tail])       if (marked[it] == 2)         if (M < T) {           B[M++] = it;           marked[it] = 0;         }     for (int i = 0; i < H; ++i) cout << A[i] <<    ;     cout <<   n ;     for (int i = 0; i < T; ++i) cout << B[i] <<    ;     cout <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     string start;     string end;     cin >> start;     cin >> end;     int startInt = (stoi(start.substr(0, 3))) * 60 + (stoi(start.substr(3, 5)));     int endInt = (stoi(end.substr(0, 3))) * 60 + (stoi(end.substr(3, 5)));     int dif = (endInt - startInt) / 2;     int hoursToAdd = dif / 60;     int minutesToAdd = dif % 60;     int first = (stoi(start.substr(0, 3)) + hoursToAdd);     int second = (stoi(start.substr(3, 5)) + minutesToAdd);     first += second / 60;     second = second % 60;     string firstS = to_string(first);     string secondS = to_string(second);     if (firstS.size() == 1) firstS.insert(0,  0 );     if (secondS.size() == 1) secondS.insert(0,  0 );     cout << firstS <<  :  << secondS <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int v[100005];   int st[100005][22];   bool mark[100005];   long long dp[100005];   int n, k;   void build() {     int i, j;     for (j = 1; 1 << j <= n; j++) {       for (i = 0; i + (1 << j) <= n; i++) {         st[i][j] = min(st[i][j - 1], st[i + (1 << (j - 1))][j - 1]);       }     }   }   int getMin(int l, int r) {     int num = r - l + 1, k = 0;     while (num >= 2) num /= 2, k++;     return min(st[l][k], st[r - (1 << k) + 1][k]);   }   long long f(int i) {     if (i >= n) return 0;     if (mark[i]) return dp[i];     mark[i] = 1;     long long ret = getMin(i - k + 1, i) + f(i + k);     ret = max(ret, f(i + 1));     return dp[i] = ret;   }   int main() {     scanf( %d %d , &n, &k);     long long sum = 0;     for (int i = 0; i < n; i++) {       scanf( %d , &st[i][0]);       sum += st[i][0];     }     build();     printf( %lld n , sum - f(k - 1));     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 ,  unroll-loops )   #pragma GCC target( avx2 )   using namespace std;   template <class T, class U>   inline void checkmin(T &x, U y) {     if (y < x) x = y;   }   template <class T, class U>   inline void checkmax(T &x, U y) {     if (y > x) x = y;   }   template <class T, class U>   inline bool ifmax(T &x, U y) {     if (y > x) return x = y, true;     return false;   }   template <class T, class U>   inline bool ifmin(T &x, U y) {     if (y < x) return x = y, true;     return false;   }   template <class T>   inline void sort(T &a) {     sort(a.begin(), a.end());   }   template <class T>   inline void rsort(T &a) {     sort(a.rbegin(), a.rend());   }   template <class T>   inline void reverse(T &a) {     reverse(a.begin(), a.end());   }   template <class T, class U>   inline istream &operator>>(istream &str, pair<T, U> &p) {     return str >> p.first >> p.second;   }   template <class T>   inline istream &operator>>(istream &str, vector<T> &a) {     for (auto &i : a) str >> i;     return str;   }   template <class T>   inline T sorted(T a) {     sort(a);     return a;   }   void read(int &x) {     static char c;     c = getchar();     if (c ==  - ) {       x = 0;       while ((c = getchar()) >=  0 ) x = (x << 3) + (x << 1) + (c -  0 );       x = -x;     } else {       x = c -  0 ;       while ((c = getchar()) >=  0 ) x = (x << 3) + (x << 1) + (c -  0 );     }   }   void print(int x) {     if (x >= 10) print(x / 10);     putchar(x % 10 +  0 );   }   const int N = 1e6 + 1;   int a[N], ind[N];   bool used[N];   void solve() {     int n;     read(n);     for (int i = 0; i < n; ++i) read(a[i]), used[i] = 0;     int v = 0, pind = 0;     while (!used[v]) {       used[v] = true;       ind[pind++] = v;       v -= a[v];     }     bool flag = false;     for (int i = 0;; ++i)       if (ind[i] == v) {         print(pind - i);         putchar(  n );         for (int j = i; j < pind; ++j) print(ind[j] + 1), putchar(   );         putchar(  n );         return;       }   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cout << fixed << setprecision(12);     srand(94385);     int t;     read(t);     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, a[300005], s[300005], X, Y;   long long ans;   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       long long x;       scanf( %lld , &x);       for (long long j = 0; j < 60; j++)         if (x >> j & 1) a[i]++;       s[i] = s[i - 1] + a[i];     }     X++;     for (int i = 1; i <= n; i++) {       if (s[i] & 1) {         ans += Y;         Y++;       } else {         ans += X;         X++;       }     }     for (int i = 1; i <= n; i++) {       X = a[i];       for (int j = i; j <= min(n, i + 60 - 1); j++) {         X = max(X, a[j]);         if ((s[j] - s[i - 1]) % 2 == 0 && (s[j] - s[i - 1]) < X + X) ans--;       }     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     string s;     int n;     cin >> n >> s;     int res = 0;     long long a = 0, b = 0;     for (int i = 0; i < n; i++) {       if (s[i] == s[0]) {         a++;       } else {         break;       }     }     for (int i = n - 1; i >= 0; i--) {       if (s[i] == s[n - 1]) {         b++;       } else {         break;       }     }     if (s[0] == s[n - 1]) {       cout << ((a + 1) * (b + 1)) % 998244353;     } else {       cout << (a + b + 1) % 998244353;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long n, m, h, ts, calc[2000];   double p2, p1;   double gc(long n, long m) {     if (m > n) return 0;     double res = 0;     for (int i = n; i > n - m; i--)       res = res + log(i + .0), res = res - log(.0 + n - i + 1);     return exp(res);   }   int main() {     ios_base::sync_with_stdio(0);     cin >> n >> m >> h;     for (int i = 1; i <= m; i++) {       cin >> calc[i];       ts += calc[i];     }     if (ts < n) {       cout << -1 << endl;       return 0;     }     if (n == 1) {       cout << 0 << endl;       return 0;     }     if (calc[h] == 1) {       cout << 0 << endl;       return 0;     }     --n;     --calc[h];     --ts;     double ans = 1.0;     for (int i = 1; i <= n; i++)       ans = ans * (ts - calc[h] - i + 1) / (ts - i + 1);     cout << fixed << 1.0 - ans << endl;     cin.get();     cin.get();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   vector<int> a, b, g, ar;   vector<vector<int> > edg, nxt;   vector<long long> d;   long long f(int v) {     long long res = 0;     for (int w : edg[v]) {       long long tmp = f(w) + a[w];       if (tmp > 0) {         res += tmp;         nxt[w].push_back(v);         g[v]++;       } else {         nxt[v].push_back(w);         g[w]++;       }     }     return d[v] = res;   }   int main(void) {     cin >> n;     a.assign(n, 0);     b.assign(n, 0);     g.assign(n, 0);     edg.assign(n, vector<int>());     nxt.assign(n, vector<int>());     for (int i = 0; i < n; i++) cin >> a[i];     vector<int> c;     for (int i = 0; i < n; i++) {       cin >> b[i];       if (b[i] == -1) {         c.push_back(i);         continue;       }       b[i]--;       edg[b[i]].push_back(i);     }     long long ans = 0;     d.assign(n, 0);     for (int i = 0; i < n; i++) {       if (b[i] == -1) f(i);     }     for (int i = 0; i < n; i++) {       ans += d[i] + a[i];     }     queue<int> q;     for (int i = 0; i < n; i++) {       if (g[i] == 0) q.push(i);     }     while (!q.empty()) {       int v = q.front();       q.pop();       ar.push_back(v);       for (int w : nxt[v]) {         g[w]--;         if (g[w] == 0) q.push(w);       }     }     cout << ans << endl;     for (int v : ar) cout << v + 1 <<    ;     cout << endl;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e9;   long long gcd(long long a, long long b) { return (a ? gcd(b % a, a) : b); }   long long power(long long a, long long n) {     long long p = 1;     while (n > 0) {       if (n % 2) {         p = p * a;       }       n >>= 1;       a *= a;     }     return p;   }   int main() {     ios_base::sync_with_stdio(false);     string s, t;     int n, m, p, a, b, c, d, e, x, mx = -INF;     cin >> n;     for (int(i) = 0; (i) < (n); (i)++) {       cin >> s >> p >> m >> a >> b >> c >> d >> e;       x = 100 * p - 50 * m + a + b + c + d + e;       if (mx < x) {         t = s;         mx = x;       }     }     cout << t;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a;     string s;     cin >> a;     for (int i = 1; i <= a + 5; i++) {       stringstream sa;       string ssa;       sa << i;       sa >> ssa;       s.append(ssa);     }     cout << s[a - 1];     return 0;   }


#include <bits/stdc++.h>      using namespace std;      bool cutPaper(int n, int x, int y)   {       int count = 1;          while ( x % 2 == 0 || y % 2 == 0 )       {              if ( x % 2 == 0 ){               x /= 2;               count *= 2;            }else if ( y % 2 == 0 )  {               y /= 2;                count *= 2;            }              if ( count >= n )               return true;          }          if ( count >= n )               return true;             return false;          }   int main()   {          int t;       cin >> t;          while (t-- > 0)       {           int n, x, y;              cin >> x >> y >> n;              if (cutPaper(n, x, y))           {               cout <<  YES  << endl;           }           else           {               cout <<  NO  << endl;           }       }   }


#include <bits/stdc++.h>   using namespace std;   int a[3509];   int n, t, m, k;   deque<int> d;   vector<int> v;   int main() {     scanf( %d , &t);     for (int i = 0; i < t; i++) {       scanf( %d%d%d , &n, &m, &k);       for (int j = 0; j < n; j++) scanf( %d , &a[j]);       int g = n - m + 1;       v.clear();       for (int j = g - 1; j < n; j++) v.push_back(max(a[j - g + 1], a[j]));       int vlen = v.size();       int g2 = vlen - k;       g2 = max(1, g2);       d.clear();       for (int i = 0; i < g2; i++) {         if (!d.empty()) {           while (!d.empty() && d.back() > v[i]) d.pop_back();         }         d.push_back(v[i]);       }       int ans = d.front();       for (int i = g2; i < vlen; i++) {         if (!d.empty() && d.front() == v[i - g2]) {           d.pop_front();         }         while (!d.empty() && d.back() > v[i]) d.pop_back();         d.push_back(v[i]);         ans = max(ans, d.front());       }       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1000004;   int a[N], arr[N], nxt[N], big[N], len[N];   int main() {     int n;     scanf( %d , &n);     int i, idx;     int mx1 = 0, mx2 = -1;     for (i = 0; i < n; i++) {       scanf( %d , &a[i]);       if (a[i] > mx1) {         mx2 = mx1;         mx1 = a[i];         idx = i;       } else if (a[i] > mx2)         mx2 = a[i];     }     int id = idx;     for (i = 1; i <= n; i++) {       arr[i] = a[id];       id = (id + 1) % n;     }     arr[n + 1] = 1000000007;     stack<int> st;     st.push(n + 1);     for (i = n; i >= 1; i--) {       while (!st.empty() && arr[st.top()] < arr[i]) st.pop();       nxt[i] = st.top();       st.push(i);     }     while (!st.empty()) st.pop();     st.push(n + 1);     for (i = n; i >= 1; i--) {       while (!st.empty() && arr[st.top()] <= arr[i]) st.pop();       big[i] = st.top();       st.push(i);     }     len[n + 1] = 1;     for (i = n; i >= 1; i--) len[i] = len[nxt[i]] + 1;     long long ans = 0;     for (i = 1; i <= n; i++) ans = ans + (len[i + 1] - len[big[i]] + 1);     for (i = 1; i <= n; i++) {       if (arr[i] == mx1 || arr[i] == mx2) ans--;     }     printf( %I64d n , ans);     return 0;   }


#include <bits/stdc++.h>   const int maxn = 5e5 + 5;   std::vector<std::pair<int, int>> G[maxn];   std::vector<std::tuple<int, int, int>> q[maxn];   int in[maxn], out[maxn], id[maxn], tot, n, m;   long long dis[maxn], ans[maxn];   struct SegTree {     long long sum[maxn << 2], lazy[maxn << 2];     void pushdown(int o) {       if (lazy[o]) {         sum[o << 1] += lazy[o];         sum[o << 1 | 1] += lazy[o];         lazy[o << 1] += lazy[o];         lazy[o << 1 | 1] += lazy[o];         lazy[o] = 0;       }     }     void build(int o, int l, int r) {       if (l == r) {         sum[o] = dis[l];         return;       }       int m = (l + r) >> 1;       build(o << 1, l, m);       build(o << 1 | 1, m + 1, r);       sum[o] = std::min(sum[o << 1], sum[o << 1 | 1]);     }     void update(int o, int l, int r, int ql, int qr, int val) {       if (ql <= l && r <= qr) {         sum[o] += val;         lazy[o] += val;         return;       }       int m = (l + r) >> 1;       pushdown(o);       if (ql <= m) update(o << 1, l, m, ql, qr, val);       if (qr > m) update(o << 1 | 1, m + 1, r, ql, qr, val);       sum[o] = std::min(sum[o << 1], sum[o << 1 | 1]);     }     long long query(int o, int l, int r, int ql, int qr) {       if (ql <= l && r <= qr) {         return sum[o];       }       int m = (l + r) >> 1;       long long ans = 0x3f3f3f3f3f3f3f3f;       pushdown(o);       if (ql <= m) ans = std::min(ans, query(o << 1, l, m, ql, qr));       if (qr > m) ans = std::min(ans, query(o << 1 | 1, m + 1, r, ql, qr));       return ans;     }   } st;   void dfs1(int u, long long d) {     in[u] = ++tot;     for (auto &it : G[u]) dfs1(it.first, it.second + d);     if (G[u].empty())       dis[u] = d;     else       dis[u] = 0x3f3f3f3f3f3f3f3f;     out[u] = tot;   }   void dfs2(int u, long long d) {     for (auto &it : q[u])       ans[std::get<2>(it)] =           st.query(1, 1, n, std::get<0>(it), std::get<1>(it)) + d;     for (auto &it : G[u]) {       st.update(1, 1, n, in[it.first], out[it.first], -2 * it.second);       dfs2(it.first, it.second + d);       st.update(1, 1, n, in[it.first], out[it.first], 2 * it.second);     }   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 2; i <= n; i++) {       int u, w;       scanf( %d%d , &u, &w);       G[u].emplace_back(i, w);     }     dfs1(1, 0);     st.build(1, 1, n);     for (int i = 1; i <= m; i++) {       int v, l, r;       scanf( %d%d%d , &v, &l, &r);       q[v].emplace_back(l, r, i);     }     dfs2(1, 0);     for (int i = 1; i <= m; i++) printf( %lld n , ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   bool umin(T& a, T b) {     if (a > b) {       a = b;       return 1;     }     return 0;   }   template <class T>   bool umax(T& a, T b) {     if (a < b) {       a = b;       return 1;     }     return 0;   }   int p[100009];   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) p[i] = i;     if (n & 1) {       for (int i = n; i > 1; i -= 2) swap(p[i], p[i - 1]);     } else {       for (int i = 1; i < n; i += 2) swap(p[i], p[i + 1]);     }     for (int i = 1; i <= n; i++) printf( %d  , p[i]);     puts(  );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 300010, maxlg = 18;   struct edge {     int to, nxt;     long long val;   };   edge G[maxn << 1], G2[maxn];   int head[maxn], cnt;   int head2[maxn], cnt2;   struct node {     int u;     long long d;     inline bool operator<(const node &rhs) const { return d > rhs.d; }   };   priority_queue<node> PQ;   long long dis[maxn];   bool vis[maxn];   int deg[maxn];   edge T[maxn];   int headT[maxn], cntT;   queue<int> Q;   int lg[maxn];   int anc[maxn][maxlg], dep[maxn];   inline int lca(int, int);   void dfs(const int &);   int siz[maxn];   int main() {     int n, m, s;     scanf( %d %d %d , &n, &m, &s);     int u, v, w;     while (m--) {       scanf( %d %d %d , &u, &v, &w);       G[++cnt] = {v, head[u], w}, head[u] = cnt;       G[++cnt] = {u, head[v], w}, head[v] = cnt;     }     memset(dis, 0x3f, sizeof(dis));     dis[s] = 0, PQ.push({s, 0});     while (!PQ.empty()) {       u = PQ.top().u, PQ.pop();       if (vis[u]) continue;       vis[u] = true;       for (int i = head[u]; i; i = G[i].nxt)         if (dis[G[i].to] > dis[u] + G[i].val) {           dis[G[i].to] = dis[u] + G[i].val;           PQ.push({G[i].to, dis[G[i].to]});         }     }     for (int i = 1; i <= n; i++) {       anc[i][0] = -1;       for (int j = head[i]; j; j = G[j].nxt)         if (dis[G[j].to] == dis[i] + G[j].val)           G2[++cnt2] = {G[j].to, head2[i]}, head2[i] = cnt2, deg[G[j].to]++;     }     for (int i = 2; i <= n; i++) lg[i] = lg[i >> 1] + 1;     Q.push(s);     while (!Q.empty()) {       u = Q.front(), Q.pop();       if (u != s) {         dep[u] = dep[anc[u][0]] + 1;         T[++cntT] = {u, headT[anc[u][0]], 0}, headT[anc[u][0]] = cntT;         for (int i = 1; i <= lg[dep[u]]; i++)           anc[u][i] = anc[anc[u][i - 1]][i - 1];       }       for (int i = head2[u]; i; i = G2[i].nxt)         if (deg[G2[i].to]) {           anc[G2[i].to][0] = lca(anc[G2[i].to][0], u);           if (!--deg[G2[i].to]) Q.push(G2[i].to);         }     }     dfs(s);     int ans = 0;     for (int i = 1; i <= n; i++)       if (i != s && siz[i] > ans) ans = siz[i];     printf( %d n , ans);     return 0;   }   inline int lca(int u, int v) {     if (u == -1) return v;     if (dep[u] < dep[v]) u ^= v ^= u ^= v;     while (dep[u] != dep[v]) u = anc[u][lg[dep[u] - dep[v]]];     if (u == v) return u;     for (int i = lg[dep[u]]; i >= 0; i--)       if (anc[u][i] != anc[v][i]) u = anc[u][i], v = anc[v][i];     return anc[u][0];   }   void dfs(const int &u) {     siz[u] = 1;     for (int i = headT[u]; i; i = T[i].nxt) dfs(T[i].to), siz[u] += siz[T[i].to];     return;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<int> v1, v2;     for (int i = 0; i < n; i++) {       int a;       cin >> a;       if (a) v1.push_back(a);     }     for (int i = 0; i < n; i++) {       int a;       cin >> a;       if (a) v2.push_back(a);     }     for (int i = 0; i < n - 1; i++) {       if (v1[0] == v2[i]) {         rotate(v2.begin(), v2.begin() + i, v2.end());         break;       }     }     for (int i = 0; i < n - 1; i++) {       if (v1[i] != v2[i]) {         cout <<  NO ;         return 0;       }     }     cout <<  YES ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long k, m;     string s;     vector<int> rooms;     cin >> k >> m;     cin >> s;     for (int i = 0; i < s.length(); i++) {       if (s[i] ==  0 ) {         rooms.push_back(i);       }     }     long select = k;     k = 0;     while (k + m < rooms.size()) {       for (int i = k; i <= k + m; i++) {         if (max(rooms[i] - rooms[k], rooms[k + m] - rooms[i]) < select)           select = max(rooms[i] - rooms[k], rooms[k + m] - rooms[i]);       }       k++;     }     cout << select;   }


#include <bits/stdc++.h>   using namespace std;   const int sieve_size = 15000002;   bool sieve[sieve_size + 1];   vector<long long> prime;   void Sieve() {     prime.push_back(2);     for (int i = 3; i * i <= sieve_size; i += 2) {       if (!sieve[i]) {         long long p = i * 2;         for (int j = i * i; j <= sieve_size; j += p) {           sieve[j] = true;         }       }     }     for (int i = 3; i <= sieve_size; i += 2) {       if (!sieve[i]) prime.push_back(i);     }   }   int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};   inline int GA(long long n, vector<long long>& vec) {     for (int i = 0; i < n; ++i) {       long long x;       cin >> x;       vec.push_back(x);     }     return 0;   }   inline int GAEG(long long m, vector<long long> vec[]) {     for (int i = 0; i < m; ++i) {       long long x, y;       cin >> x >> y;       x--, y--;       vec[x].push_back(y);       vec[y].push_back(x);     }     return 0;   }   bool isvalid(long long xx, long long yy, long long n, long long m) {     return (xx >= 0 && xx < n && yy >= 0 && yy < m);   }   long long pw(long long x, long long y) {     if (y == 0) return 1;     long long o = y / 2;     long long f = pw(x, o);     if (y % 2) {       return (((f * f)) * x);     } else       return (f * f);   }   string s[60];   int main() {     long long t;     cin >> t;     while (t--) {       long long n, m;       cin >> n >> m;       for (int i = 0; i < n; ++i) cin >> s[i];       long long ans = 4;       bool bl = false;       for (int i = 0; i < n; ++i) {         int p = s[i].find( A );         if (p != -1) {           bl = true;           break;         }       }       if (!bl) {         cout <<  MORTAL  << endl;       } else {         if (s[0].find( A ) != -1 || s[n - 1].find( A ) != -1) ans = 3;         for (int i = 0; i < n; ++i) {           if (s[i][0] ==  A  || s[i][m - 1] ==  A ) {             ans = 3;             break;           }         }         if (s[0][0] ==  A  || s[n - 1][0] ==  A  || s[n - 1][m - 1] ==  A  ||             s[0][m - 1] ==  A )           ans = 2;         for (int i = 0; i < n; ++i) {           bool qq = false;           for (int j = 0; j < m; ++j) {             if (s[i][j] !=  A ) {               qq = true;               break;             }           }           if (!qq) {             if (i == 0 || i == n - 1)               ans = 1;             else               ans = min(ans, 2ll);           }         }         bool isP = false;         for (int i = 0; i < m; ++i) {           bool qq = false;           for (int j = 0; j < n; ++j) {             if (s[j][i] !=  A ) {               qq = true;               isP = true;               break;             }           }           if (!qq) {             if (i == 0 || i == m - 1)               ans = 1;             else               ans = min(ans, 2ll);           }         }         if (!isP)           cout << 0 << endl;         else           cout << ans << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   namespace IO {   inline char gc() {     static const int Rlen = 1 << 22 | 1;     static char buf[Rlen], *p1, *p2;     return (p1 == p2) && (p2 = (p1 = buf) + fread(buf, 1, Rlen, stdin), p1 == p2)                ? EOF                : *p1++;   }   template <typename T>   T get_integer() {     char c;     bool f = false;     while (!isdigit(c = gc())) f = c ==  - ;     T x = c ^ 48;     while (isdigit(c = gc())) x = ((x + (x << 2)) << 1) + (c ^ 48);     return f ? -x : x;   }   inline int gi() { return get_integer<int>(); }   }  // namespace IO   using namespace IO;   using std::cerr;   using std::cout;   using pii = std::pair<int, int>;   const int N = 1.5e5 + 7;   int n, m, k;   long long ans;   std::vector<int> G[N];   std::vector<pii> Q[N];   int fa[N], in[N], out[N];   int sz[N], son[N], top[N];   int d[N], ps[N], dfc;   void dfs1(int u, int p) {     fa[u] = p, d[u] = d[p] + 1;     for (int v : G[u])       if (v != p) {         dfs1(v, u);         sz[u] += sz[v];         if (sz[v] > sz[son[u]]) son[u] = v;       }     ++sz[u];   }   void dfs2(int u, int tp) {     top[u] = tp;     ps[in[u] = ++dfc] = u;     if (son[u]) dfs2(son[u], tp);     for (int v : G[u])       if (v != fa[u] && v != son[u]) dfs2(v, v);     out[u] = dfc;   }   int LCA(int u, int v) {     while (top[u] != top[v])       d[top[u]] < d[top[v]] ? v = fa[top[v]] : u = fa[top[u]];     return d[u] < d[v] ? u : v;   }   int jump(int u, int k) {     while (k > d[u] - d[top[u]]) {       k -= d[u] - d[top[u]] + 1;       u = fa[top[u]];     }     return ps[in[u] - k];   }   namespace SGT {   const int N = ::N * 40;   int lc[N], rc[N], sm[N], ct;   void ins(int &u, int l, int r, int p) {     if (!u) u = ++ct;     ++sm[u];     if (l == r) return;     int m = (l + r) >> 1;     p <= m ? ins(lc[u], l, m, p) : ins(rc[u], m + 1, r, p);   }   int qy(int u, int l, int r, int ql, int qr) {     if ((ql <= l && r <= qr) || !u) return sm[u];     int m = (l + r) >> 1;     if (qr <= m) return qy(lc[u], l, m, ql, qr);     if (m < ql) return qy(rc[u], m + 1, r, ql, qr);     return qy(lc[u], l, m, ql, qr) + qy(rc[u], m + 1, r, ql, qr);   }   void merge(int &u, int v) {     if (!u || !v) {       u |= v;       return;     }     merge(lc[u], lc[v]);     merge(rc[u], rc[v]);     sm[u] += sm[v];   }   void ins(int &u, int p) { ins(u, 1, n, p); }   int qy(int u, int l, int r) { return qy(u, 1, n, l, r); }   void clear() {     while (ct) lc[ct] = rc[ct] = sm[ct] = 0, --ct;   }   }  // namespace SGT   namespace BIT {   int tr[N];   void add(int l, int r) {     for (int register p = l; p <= n; p += p & -p) ++tr[p];     for (int register p = r + 1; p <= n; p += p & -p) --tr[p];   }   int qy(int p) {     int r = 0;     for (; p; p &= p - 1) r += tr[p];     return r;   }   }  // namespace BIT   int rt[N];   std::vector<int> q[N];   void solve_q(int u, int Rt) {     rt[u] = 0;     int od = std::max(0, k - d[u] + d[Rt]);     for (int v : q[u]) {       if (d[v] >= od + d[Rt]) {         int p = jump(v, d[v] - d[Rt] - od);         ans += SGT::qy(rt[u], in[p], out[p]);       }       SGT::ins(rt[u], in[v]);     }     for (int w : G[u])       if (Rt != u || w != son[u]) {         solve_q(w, Rt);         if (q[w].size() > q[u].size()) q[u].swap(q[w]), std::swap(rt[u], rt[w]);         for (int v : q[w]) {           if (d[v] >= od + d[Rt]) {             int p = jump(v, d[v] - d[Rt] - od);             ans += SGT::qy(rt[u], in[p], out[p]);           }           q[u].push_back(v);         }         q[w].clear();         SGT::merge(rt[u], rt[w]);       }   }   void solve(int u) {     for (int v : G[u]) solve(v);     for (auto &t : Q[u]) ans += BIT::qy(in[t.second]);     for (auto &t : Q[u])       if (d[t.second] >= d[u] + k) {         int p = jump(t.second, d[t.second] - d[u] - k);         BIT::add(in[p], out[p]);       }     for (auto &t : Q[u]) ans += BIT::qy(in[t.first]);     for (auto &t : Q[u])       if (d[t.first] >= d[u] + k) {         int p = jump(t.first, d[t.first] - d[u] - k);         BIT::add(in[p], out[p]);       }     for (auto &t : Q[u]) q[t.first].push_back(t.second);     solve_q(u, u);     q[u].clear();     SGT::clear();   }   void Main() {     n = gi(), m = gi(), k = gi();     for (int register i = 1; i < n; ++i) {       int u = gi(), v = gi();       G[u].push_back(v);       G[v].push_back(u);     }     dfs1(1, 0);     dfs2(1, 1);     for (int register i = 2; i <= n; ++i)       G[i].erase(std::find(G[i].begin(), G[i].end(), fa[i]));     for (int register i = 1; i <= m; ++i) {       int u = gi(), v = gi();       if (in[u] > in[v]) std::swap(u, v);       if (in[v] > out[u]) std::swap(u, v);       Q[LCA(u, v)].push_back({u, v});     }     solve(1);     cout << ans <<   n ;   }   inline void file() {}   signed main() {     file();     Main();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long arr[200022];   long long b[200022];   vector<vector<long long> > vect(4 * 200022);   void merge(long long i, long long a, long long j, long long b1, long long pos) {     long long s = i;     long long e = b1;     while (i <= a && j <= b1) {       if (b[i] < b[j]) {         vect[pos].push_back(b[i++]);       } else         vect[pos].push_back(b[j++]);     }     while (i <= a) vect[pos].push_back(b[i++]);     while (j <= b1) vect[pos].push_back(b[j++]);     long long k = 0;     for (; s <= e; s++) b[s] = vect[pos][k++];     return;   }   void mergesort(long long i, long long j, long long pos) {     if (i < j) {       long long mid = i + j;       mid /= 2;       mergesort(i, mid, pos * 2 + 1);       mergesort(mid + 1, j, pos * 2 + 2);       merge(i, mid, mid + 1, j, pos);     } else if (i == j) {       vect[pos].push_back(b[i]);     }   }   long long query(long long s, long long e, long long st, long long ed,                   long long pos, long long ele) {     if (s > ed || e < st)       return 0;     else if (s <= st && e >= ed) {       return vect[pos].end() -              lower_bound((vect[pos]).begin(), (vect[pos]).end(), ele);     } else {       return query(s, e, st, (st + ed) / 2, pos * 2 + 1, ele) +              query(s, e, ((st + ed) / 2) + 1, ed, pos * 2 + 2, ele);     }   }   int main() {     long long n;     cin >> n;     for (long long i = 0; i < n; i++) {       cin >> arr[i];       arr[i] = min(arr[i], n);       b[i] = arr[i];     }     mergesort(0, n - 1, 0);     long long ans = 0;     for (long long i = n; i >= 1; i--) {       long long end = min(i, arr[i - 1]);       if (end == i) end--;       ans += query(0, end - 1, 0, n - 1, 0, i);     }     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int dfs(int n) {}   int main() {     int n, k, x, y, a[200200], b[200200];     cin >> n >> k;     vector<vector<int> > v(n, vector<int>());     for (int i = 0; i < n; i++) {       cin >> a[i];       b[i] = a[i];     }     for (int i = 0; i < k; i++) {       cin >> x >> y;       v[x - 1].push_back(y - 1);       v[y - 1].push_back(x - 1);     }     sort(b, b + n);     for (int i = 0; i < n; i++) {       int x = i, res = lower_bound(b, b + n, a[i]) - b;       for (int j = 0; j < v[i].size(); j++)         if (a[v[i][j]] < a[i]) res--;       cout << res <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1000;   const int MAX = 1000;   const int inf = 999999999;   const int p1 = 104393321, p2 = 104393329;   int a[MAX], adj[MAX][MAX], ans = inf;   int main() {     ios::sync_with_stdio(0);     int n, m;     cin >> n >> m;     for (int i = (0); i < int(n); ++i) cin >> a[i];     for (int i = (0); i < int(m); ++i) {       int x, y;       cin >> x >> y;       x--;       y--;       adj[x][y] = 1;       adj[y][x] = 1;     }     for (int i = (0); i < int(n); ++i) {       for (int j = (i + 1); j < int(n); ++j) {         for (int t = (j + 1); t < int(n); ++t) {           if (adj[i][j] && adj[j][t] && adj[i][t])             ans = min(ans, a[i] + a[t] + a[j]);         }       }     }     if (ans == inf)       cout << -1 << endl;     else       cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, cnt = 0;   map<int, int> mp;   int main() {     cin >> n;     mp[n]++;     cnt++;     while (n) {       n++;       while (!(n % 10)) n /= 10;       if (mp[n]) break;       mp[n]++;       cnt++;     }     cout << cnt << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   int getbit(int i, T X) {     return (X & (1 << (i - 1)));   }   template <class T>   T onbit(int i, T X) {     return (X | (1 << (i - 1)));   }   template <class T>   T offbit(int i, T X) {     return (X | (1 << (i - 1)) - (1 << (i - 1)));   }   template <class T>   T sqr(T x) {     return (x * x);   }   template <class T>   T cube(T x) {     return (x * x * x);   }   template <class T>   T gcd(T a, T b) {     T r;     while (b != 0) {       r = a % b;       a = b;       b = r;     }     return a;   }   template <class T>   T lcm(T a, T b) {     return a / gcd(a, b) * b;   }   int csx[4] = {0, 0, -1, 1};   int csy[4] = {-1, 1, 0, 0};   const int MOD = 1000000007;   const int infi = 1e9;   const int maxn = 300;   const int maxv = 800;   struct Dinic {     int n, s, t, E, adj[maxv + 5], next[maxv + 5], last[maxn + 5], run[maxv + 5],         level[maxv + 5], que[maxv + 5], pre[maxv + 5];     long long flow[maxv + 5], cap[maxv + 5];     void init(int _n, int _s, int _t) {       n = _n;       s = _s;       t = _t;       E = 0;       for (typeof(n) i = 0; i <= n; i++) last[i] = -1;     }     void add(int u, int v, long long c1, long long c2) {       adj[E] = v;       flow[E] = 0;       cap[E] = c1;       pre[E] = u;       next[E] = last[u];       last[u] = E++;       adj[E] = u;       flow[E] = 0;       cap[E] = c2;       pre[E] = v;       next[E] = last[v];       last[v] = E++;     }     bool bfs() {       for (typeof(n) i = 0; i <= n; i++) level[i] = -1;       level[s] = 0;       int qsize = 0;       que[qsize++] = s;       for (typeof(qsize) i = 0; i < qsize; i++) {         for (int u = que[i], e = last[u]; e != -1; e = next[e]) {           int v = adj[e];           if (flow[e] < cap[e] && level[v] == -1) {             level[v] = level[u] + 1;             que[qsize++] = v;           }         }       }       return level[t] != -1;     }     long long dfs(int u, long long bot) {       if (u == t) return bot;       for (int &e = run[u]; e != -1; e = next[e]) {         int v = adj[e];         long long delta = 0;         if (level[v] == level[u] + 1 && flow[e] < cap[e] &&             (delta = dfs(v, min(bot, cap[e] - flow[e] * 1ll))) > 0) {           flow[e] += delta;           flow[e ^ 1] -= delta;           return delta;         }       }       return 0;     }     long long maxFlow() {       long long total = 0;       while (bfs()) {         for (typeof(n) i = 0; i <= n; i++) run[i] = last[i];         for (int delta = dfs(s, infi); delta > 0; delta = dfs(s, infi))           total += delta;       }       return total;     }   };   int n, m, a[maxn + 5];   pair<int, long long> P[maxn + 5];   map<int, int> M[maxn + 5];   set<int> prime;   Dinic dinic;   void enter() {     scanf( %d %d , &n, &m);     for (typeof(n) i = 1; i <= n; i++) scanf( %d , &a[i]);     for (typeof(m) i = 1; i <= m; i++) scanf( %d %d , &P[i].first, &P[i].second);   }   void Phantich(int id, int n) {     for (int i = 2; i * i <= n; i++)       if (n % i == 0) {         int cnt = 0;         while (n % i == 0) {           cnt++;           n /= i;         }         M[id][i] = cnt;         prime.insert(i);       }     if (n > 1) {       M[id][n] = 1;       prime.insert(n);     }   }   void solve() {     for (typeof(n) i = 1; i <= n; i++) {       Phantich(i, a[i]);     }     long long res = 0;     for (typeof(prime.begin()) it = prime.begin(); it != prime.end(); it++) {       dinic.init(n + 2, 0, n + 1);       for (typeof(m) i = 1; i <= m; i++) {         int u = P[i].first;         int v = P[i].second;         if (u % 2) swap(u, v);         if ((M[u].find(*it) == M[u].end()) || (M[v].find(*it) == M[v].end()))           continue;         int c = min(M[u][*it], M[v][*it]);         dinic.add(u, v, c, 0);       }       for (typeof(n) i = 1; i <= n; i++)         if (i % 2 == 0) {           if (M[i].find(*it) == M[i].end()) continue;           dinic.add(0, i, M[i][*it], 0);         } else {           if (M[i].find(*it) == M[i].end()) continue;           dinic.add(i, n + 1, M[i][*it], 0);         }       res += dinic.maxFlow();     }     cout << res << endl;   }   int main() {     enter();     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int SET(int n, int pos) { return n = n | (1 << pos); }   int RESET(int n, int pos) { return n = n & ~(1 << pos); }   int CHECK(int n, int pos) { return (bool)(n & (1 << pos)); }   int str2int(string s) {     stringstream ss(s);     int x;     ss >> x;     return x;   }   string int2str(int a) {     stringstream ss;     ss << a;     string str = ss.str();     return str;   }   string char2str(char a) {     stringstream ss;     ss << a;     string str = ss.str();     return str;   }   long long int bigMod(long long int n, long long int power, long long int MOD) {     if (power == 0) return 1;     if (power % 2 == 0) {       long long int ret = bigMod(n, power / 2, MOD);       return ((ret % MOD) * (ret % MOD)) % MOD;     } else       return ((n % MOD) * (bigMod(n, power - 1, MOD) % MOD)) % MOD;   }   long long int modInverse(long long int n, long long int MOD) {     return bigMod(n, MOD - 2, MOD);   }   int POW(int x, int y) {     int res = 1;     for (; y;) {       if ((y & 1)) {         res *= x;       }       x *= x;       y >>= 1;     }     return res;   }   int inverse(int x) {     double p = ((double)1.0) / x;     return (p) + 1e-9;   }   int gcd(int a, int b) {     while (b) b ^= a ^= b ^= a %= b;     return a;   }   int nC2(int n) { return n * (n - 1) / 2; }   long long int MOD(long long int n, long long int mod) {     if (n >= 0)       return n % mod;     else if (-n == mod)       return 0;     else       return mod + (n % mod);   }   int n, data[105], Mask[65], dp[105][(1 << 18) + 1], path[105][(1 << 18) + 1];   bool isPrime[65];   vector<int> prime;   void seive_N_logN(int N) {     memset(isPrime, true, sizeof isPrime);     prime.clear();     isPrime[1] = false;     for (int i = 4; i <= N; i = i + 2) isPrime[i] = false;     for (int i = 3; i * i <= N; i = i + 2) {       if (isPrime[i]) {         for (int j = i * i; j <= N; j += i) isPrime[j] = false;       }     }     for (int i = 1; i < N; i++)       if (isPrime[i]) prime.push_back(i);     for (int i = 1; i <= 60; i++) {       for (int j = 0; j < prime.size(); j++) {         if (i % prime[j] == 0) Mask[i] = SET(Mask[i], j);       }     }   }   int call(int i, int mask) {     if (i >= n) {       return 0;     }     int &ret = dp[i][mask];     if (ret != -1) return ret;     ret = 1000000000;     for (int j = 1; j <= 60; j++) {       if (mask & Mask[j]) continue;       int xx = call(i + 1, mask | Mask[j]) + abs(data[i] - j);       if (xx < ret) {         ret = xx;         path[i][mask] = j;       }     }     return ret;   }   int main() {     seive_N_logN(60);     int t, cas = 0;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d , &data[i]);     }     memset(dp, -1, sizeof(dp));     call(0, 0);     int mask = 0;     for (int i = 0; i < n; i++) {       int ans = path[i][mask];       printf( %d  , ans);       mask |= Mask[ans];     }     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using namespace std::chrono;   int main() {     string s;     cin >> s;     string ans;     bool found{false};     for (int i = 0; i < (int)s.size(); i++) {       if ((i == (int)s.size() - 1) && !found) continue;       if (s[i] ==  1  || found)         ans += s[i];       else         found = true;     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   set<int> st;   int arr[1000005];   bool taken[1000005];   map<int, int> mp;   int main() {     int n;     (scanf( %d , &n));     for (int i = 1; i <= n; i++) {       (scanf( %d , &arr[i]));       mp[arr[i]]++;       st.insert(i);     }     for (int i = 1; i <= n; i++) st.erase(arr[i]);     memset(taken, false, sizeof(taken));     cout << st.size() <<   n ;     for (int i = 1; i <= n; i++) {       if (mp[arr[i]] > 1) {         if (*st.begin() > arr[i] && taken[arr[i]] == false)           taken[arr[i]] = true;         else {           mp[arr[i]]--;           arr[i] = *st.begin();           st.erase(st.begin());         }       }     }     for (int i = 1; i <= n; i++) cout << arr[i] <<    ;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   const int neginf = 0xc0c0c0c0;   const int mod = 1000000007;   bool cmp(const double& a, const double& b, const double TOL = 1e-9) {     return (a + TOL > b) ? (b + TOL > a) ? 0 : 1 : -1;   }   long long powmod(long long a, long long b) {     long long res = 1;     a %= mod;     assert(b >= 0);     for (; b; b >>= 1) {       if (b & 1) res = (res * a) % mod;       a = (a * a) % mod;     }     return res;   }   int n, A, B, C, T;   int main() {     cin >> n >> A >> B >> C >> T;     vector<int> msg(n);     for (int(i) = (0); (i) < (n); ++(i)) cin >> msg[i];     sort((msg).begin(), (msg).end());     int last = msg.back();     long long best = 0;     for (int v : msg) {       int gain;       if (C > B) {         gain = A + (T - v) * (C - B);       } else         gain = A;       best += gain;     }     cout << best << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool done[123][123];   char s[123][123];   vector<pair<pair<long long, long long>, long long int> > v;   int main() {     long long int n, m;     scanf( %lld%lld , &n, &m);     for (int i = 0; i < n; ++i)       for (int j = 0; j < m; ++j) {         done[i][j] = false;         scanf(  %c , &s[i][j]);       }     for (int i = 1; i < n - 1; ++i)       for (int j = 1; j < m - 1; ++j)         if (s[i][j] !=  . ) {           if (s[i - 1][j] ==  *  && s[i + 1][j] ==  *  && s[i][j - 1] ==  *  &&               s[i][j + 1] ==  * ) {             long long int up = 0, dn = 0, lt = 0, rt = 0;             for (int k = i - 1; k >= 0; k--)               if (s[k][j] ==  . )                 break;               else                 up++;             for (int k = i + 1; k < n; k++)               if (s[k][j] ==  . )                 break;               else                 dn++;             for (int k = j - 1; k >= 0; k--)               if (s[i][k] ==  . )                 break;               else                 lt++;             for (int k = j + 1; k < m; k++)               if (s[i][k] ==  . )                 break;               else                 rt++;             long long int mn = min(up, min(dn, min(lt, rt)));             if (mn) {               v.push_back(                   make_pair(pair<long long, long long>(i + 1, j + 1), mn));               int k, cnt;               cnt = mn;               done[i][j] = true;               for (k = i - 1; cnt; k--, cnt--) done[k][j] = true;               cnt = mn;               for (k = i + 1; cnt; k++, cnt--) done[k][j] = true;               cnt = mn;               for (k = j - 1; cnt; k--, cnt--) done[i][k] = true;               cnt = mn;               for (k = j + 1; cnt; k++, cnt--) done[i][k] = true;             }           }         }     for (int i = 0; i < n; ++i)       for (int j = 0; j < m; ++j)         if (s[i][j] ==  *  && done[i][j] == false) {           printf( -1 n );           return 0;         }     printf( %lld n , (long long int)v.size());     for (int i = 0; i != (long long int)v.size(); ++i)       printf( %lld %lld %lld n , v[i].first.first, v[i].first.second,              v[i].second);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, len[400], cnt, Block, pos[100010];   long long c[100010], sum[400], v[100010], cov[400], dlt[400];   bool mak[400];   void BuildBlocks() {     int tail;     for (int i = 1; i <= n; i = tail + 1) {       tail = min(i + Block - 1, n);       ++cnt;       len[cnt] = tail;       for (int j = i; j <= tail; j++) pos[j] = cnt;     }   }   long long Abs(long long x) { return (x < 0) ? -x : x; }   void work(int x, int y, long long k) {     int now = pos[x];     long long delta;     for (int i = x; i <= y; i++) {       delta = Abs(v[i] - k);       v[i] = k;       c[i] += delta;       sum[now] += delta;     }   }   void pushdown(int now) {     if (cov[now] != 0) {       for (int i = len[now - 1] + 1; i <= len[now]; i++) v[i] = cov[now];       cov[now] = 0;     }   }   void Change(int x, int y, long long k) {     int px, py, H, T;     px = pos[x];     py = pos[y];     H = px + 1;     T = py - 1;     if (px == py) {       pushdown(px);       work(x, y, k);       mak[px] = false;       return;     }     if (x == len[px - 1] + 1)       --H;     else {       pushdown(px);       mak[px] = false;       work(x, len[px], k);     }     if (y == len[py])       ++T;     else {       pushdown(py);       mak[py] = false;       work(len[py - 1] + 1, y, k);     }     if (H > T) return;     for (int i = H; i <= T; i++)       if (mak[i] == false) {         work(len[i - 1] + 1, len[i], k);         mak[i] = true;       } else {         if (cov[i] == 0) cov[i] = v[len[i]];         sum[i] += (long long)(len[i] - len[i - 1]) * Abs(k - cov[i]);         dlt[i] += Abs(k - cov[i]);         cov[i] = k;       }   }   long long count(int x, int y) {     long long ans = 0;     int now = pos[x];     for (int i = x; i <= y; i++) ans += c[i] + dlt[now];     return ans;   }   long long Query(int x, int y) {     int px, py, H, T;     long long ans = 0;     px = pos[x];     py = pos[y];     H = px + 1;     T = py - 1;     if (px == py) return count(x, y);     if (x == len[px - 1] + 1)       --H;     else       ans += count(x, len[px]);     if (y == len[py])       ++T;     else       ans += count(len[py - 1] + 1, y);     for (int i = H; i <= T; i++) ans += sum[i];     return ans;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) v[i] = i;     Block = ceil(sqrt(n));     BuildBlocks();     for (int i = 1; i <= m; i++) {       int opt, x, y, k;       scanf( %d%d%d , &opt, &x, &y);       if (opt == 1) {         scanf( %d , &k);         Change(x, y, k);       } else         printf( %I64d n , Query(x, y));     }     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   long long a[N], b[N], x[N];   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     long long n, t;     cin >> n >> t;     for (int i = 1; i <= n; ++i) cin >> a[i];     for (int i = 1; i <= n; ++i) cin >> x[i];     for (int i = 1; i <= n; ++i)       if (x[i] < i || x[i] < x[i - 1]) return puts( No ), 0;     for (int i = 1; i < n; ++i)       if (x[i] != x[i + 1] && x[i] != i) return puts( No ), 0;     a[n + 1] = a[n] + 5;     for (int i = 1; i <= n; ++i) {       if (x[i] == i)         b[i] = a[i + 1] + t - 1;       else         b[i] = a[i + 1] + t;       if (b[i] == b[i - 1]) return puts( No ), 0;     }     cout <<  Yes  << endl;     for (int i = 1; i <= n; ++i) cout << b[i] <<    ;     cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using li = long long;   using ld = long double;   void solve(bool);   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout << fixed << setprecision(20);     solve(true);     return 0;   }   const int maxn = (int)1e5 + 5;   int n, a[maxn];   map<int, int> m;   void solve(bool __attribute__((unused)) read) {     cin >> n;     for (int i = 0; i < n; ++i) {       cin >> a[i];       if (a[i] > 0 && !m.count(a[i] - 1)) {         cout << i + 1 <<   n ;         return;       }       m[a[i]] = 1;     }     cout << -1 <<   n ;     return;   }


#include <bits/stdc++.h>   using namespace std;   template <class _T>   inline _T sqr(const _T& x) {     return x * x;   }   template <class _T>   inline string tostr(const _T& a) {     ostringstream os(  );     os << a;     return os.str();   }   const long double PI = 3.1415926535897932384626433832795;   const long double EPS = 1e-11;   const int dx[4] = {0, -1, 0, 1};   const int dy[4] = {-1, 0, 1, 0};   int n, m, k;   char a[1024][1024];   char a0[1024][1024];   int c[1024][1024];   bool u[1024][1024];   bool u2[12];   void dfs(int x, int y, int px, int py) {     u[x][y] = true;     int cnt = 0;     int t[4] = {0, 1, 2, 3};     for (int i = 0; i < (int)(4); i++) {       swap(t[i], t[rand() % 4]);     }     for (int l1 = 0; l1 < (int)(4); l1++) {       int l = t[l1];       int xn = x + dx[l];       int yn = y + dy[l];       if (xn < 0 || xn >= n || yn < 0 || yn >= m || u[xn][yn] || a[xn][yn] ==  # )         continue;       dfs(xn, yn, x, y);       if (c[xn][yn] == -1) cnt++;     }     if (cnt) {       for (int l = 0; l < (int)(4); l++) {         int xn = x + dx[l];         int yn = y + dy[l];         if (xn < 0 || xn >= n || yn < 0 || yn >= m || a[xn][yn] ==  #  ||             c[xn][yn] != -1 || (xn == px && yn == py))           continue;         c[xn][yn] = k;       }       c[x][y] = k++;     }   }   void dfs2(int x, int y, int col) {     u[x][y] = true;     for (int l = 0; l < (int)(4); l++) {       int xn = x + dx[l];       int yn = y + dy[l];       if (xn < 0 || xn >= n || yn < 0 || yn >= m || a[xn][yn] ==  # ) continue;       if (c[xn][yn] == col) {         if (!u[xn][yn]) dfs2(xn, yn, col);       } else if (a[xn][yn] !=  . ) {         u2[a[xn][yn] -  0 ] = true;       }     }   }   void dfs3(int x, int y, int col, int nc) {     a[x][y] =  0  + nc;     c[x][y] = -1;     for (int l = 0; l < (int)(4); l++) {       int xn = x + dx[l];       int yn = y + dy[l];       if (xn < 0 || xn >= n || yn < 0 || yn >= m || a[xn][yn] ==  # ) continue;       if (c[xn][yn] == col) {         dfs3(xn, yn, col, nc);       }     }   }   int check(int x, int y) {     int ans = 1;     u[x][y] = true;     for (int l = 0; l < (int)(4); l++) {       int xn = x + dx[l];       int yn = y + dy[l];       if (xn < 0 || xn >= n || yn < 0 || yn >= m || u[xn][yn] ||           a[xn][yn] ==  #  || a[xn][yn] != a[x][y])         continue;       ans += check(xn, yn);     }     return ans;   }   int check2(int x, int y) {     int ans = 1;     u[x][y] = true;     for (int l = 0; l < (int)(4); l++) {       int xn = x + dx[l];       int yn = y + dy[l];       if (xn < 0 || xn >= n || yn < 0 || yn >= m || u[xn][yn] ||           a[xn][yn] ==  #  || c[xn][yn] != c[x][y])         continue;       ans += check2(xn, yn);     }     return ans;   }   int main() {     cout << setiosflags(ios::fixed) << setprecision(10);     srand(672465);     memset(c, 0xff, sizeof(c));     scanf( %d%d , &n, &m);     memset((a), 0, sizeof(a));     for (int i = 0; i < (int)(n); i++) {       scanf( %s , a[i]);       a[i][m] =   0 ;     }     memcpy(a0, a, sizeof(a));     memset((u), 0, sizeof(u));     k = 0;     for (int i = 0; i < (int)(n); i++) {       for (int j = 0; j < (int)(m); j++) {         if (!u[i][j] && a[i][j] !=  # ) {           dfs(i, j, -1, -1);           if (c[i][j] == -1) {             bool bb = true;             for (int l = 0; l < (int)(4); l++) {               int xn = i + dx[l];               int yn = j + dy[l];               if (xn < 0 || xn >= n || yn < 0 || yn >= m || a[xn][yn] ==  # )                 continue;               if (c[xn][yn] != -1) {                 c[i][j] = c[xn][yn];                 bb = false;                 break;               }             }             if (bb) {               puts( -1 );               return 0;             }           }         }       }     }     memset((u), 0, sizeof(u));     for (int i = 0; i < (int)(n); i++) {       for (int j = 0; j < (int)(m); j++) {         if (!u[i][j] && a[i][j] !=  # ) {           int cnt = check2(i, j);           if (cnt < 2 || cnt > 5) {           }         }       }     }     memset((u), 0, sizeof(u));     for (int i = 0; i < (int)(n); i++) {       for (int j = 0; j < (int)(m); j++) {         if (a[i][j] ==  . ) {           memset((u2), 0, sizeof(u2));           dfs2(i, j, c[i][j]);           bool bbb = true;           for (int t = 0; t < (int)(12); t++) {             if (!u2[t]) {               dfs3(i, j, c[i][j], t);               bbb = false;               break;             }           }           if (bbb) return 1;         }       }     }     memset((u), 0, sizeof(u));     for (int i = 0; i < (int)(n); i++) {       for (int j = 0; j < (int)(m); j++) {         if (a0[i][j] ==  # ) {           if (a[i][j] !=  # ) cout <<  Botwa ! 1 !  << endl;         } else {           if (!isdigit(a[i][j])) cout <<  Botwa ! 2 !  << endl;         }         if (a[i][j] !=  #  && !isdigit(a[i][j]))           cout <<  a[  << i <<  ][  << j <<  ] =    << a[i][j] <<     << endl;         if (!u[i][j] && a[i][j] !=  # ) {           int cnt = check(i, j);           if (cnt < 2 || cnt > 5) {             for (int ii = (-4); ii <= (int)(4); ii++) {               for (int jj = (-4); jj <= (int)(4); jj++) {                 if (i + ii >= 0 && j + jj >= 0) cout << a[i + ii][j + jj];               }               if (i + ii >= 0) cout << endl;             }             cout <<  ?   << cnt <<     << a[i][j] << endl;           }         }       }     }     for (int i = 0; i < (int)(n); i++) {       puts(a[i]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int n;   string m =  abacaba ;   long long int bal(string s) {     long long int bl = 0;     for (long long int i = 0; i < n - 6; i++) {       bool b = true;       for (long long int j = 0; j < m.size(); j++) {         if (s[i + j] != m[j]) {           b = false;           break;         }       }       if (b) bl++;     }     return bl;   }   int main() {     long long int tc;     scanf( %lld , &tc);     while (tc--) {       scanf( %lld , &n);       string s;       cin >> s;       long long int koto = bal(s);       if (koto == 1) {         for (long long int i = 0; i < n; i++) {           if (s[i] ==  ? ) s[i] =  d ;         }         cout <<  YES  << endl << s << endl;         continue;       }       if (koto >= 2) {         cout <<  NO  << endl;         continue;       }       long long int oh = 0;       for (long long int i = 0; i < n - 6; i++) {         string ans = s;         for (long long int j = 0; j < m.size(); j++) {           if (ans[i + j] ==  ? ) ans[i + j] = m[j];         }         koto = bal(ans);         if (koto > 1 || koto == 0) continue;         for (long long int j = 0; j < n; j++) {           if (ans[j] ==  ? ) ans[j] =  d ;         }         oh = 1;         s = ans;         break;       }       if (oh) {         cout <<  YES  << endl << s << endl;       } else         cout <<  NO  << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   int main() {     int t;     cin >> t;     while (t--) {       string s;       cin >> s;       int n = (int)s.size();       vector<int> nxt(n);       int pos = -1;       for (int i = 0; i < n; i++) {         if (s[i] ==  1 ) pos = i;         nxt[i] = pos;       }       int ans = 0;       for (int r = 0; r < n; r++) {         int val = 0;         for (int l = r; r - l < 20 && l >= 0; l--) {           if (s[l] ==  0 ) continue;           val += 1 << (r - l);           if (val <= r - ((l != 0) ? nxt[l - 1] : -1)) ans++;         }       }       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, p[200001], bl, cnt, cntbl, visited[200001], flag;   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> p[i];     }     for (int i = 1; i <= n; i++) {       if (!visited[i]) {         int j = i, tmp = j;         while (!visited[j]) {           visited[j] = 1;           j = p[j];         }         if (j != tmp) flag = 1;         cnt++;       }     }     for (int i = 0; i < n; i++) {       cin >> bl;       if (bl) cntbl++;     }     cout << ((cnt == 1 && !flag ? 0 : cnt) + (cntbl % 2 == 0 ? 1 : 0));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int NMax = 110000;   int N;   long long A[NMax], B[NMax], dp[NMax];   int Q[NMax], L, R;   int main() {     scanf( %d , &N);     for (int i = 1; i <= N; i++) scanf( %I64d , A + i);     for (int i = 1; i <= N; i++) scanf( %I64d , B + i);     L = 0;     R = 0;     Q[L] = 1;     for (int i = 2; i <= N; i++) {       while (R > L &&              (double)(dp[Q[L + 1]] - dp[Q[L]]) / (B[Q[L]] - B[Q[L + 1]]) <                  (double)A[i])         L++;       dp[i] = dp[Q[L]] + B[Q[L]] * A[i];       Q[++R] = i;       while (R > L + 1) {         int c = R, b = R - 1, a = R - 2;         if ((double)(dp[Q[c]] - dp[Q[b]]) / (B[Q[b]] - B[Q[c]]) <             (double)(dp[Q[b]] - dp[Q[a]]) / (B[Q[a]] - B[Q[b]])) {           Q[b] = Q[c];           R--;         } else           break;       }     }     printf( %I64d n , dp[N]);     getchar();     getchar();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s, t;     cin >> s >> t;     string p(s.size(),  0 );     int dif = 0;     for (int i = 0; i < s.size(); i++) {       if (s[i] != t[i]) dif++;     }     if (dif % 2 != 0) return cout <<  impossible , 0;     int a(0), b(0);     for (int i = 0; i < s.size(); i++) {       if (s[i] != t[i]) {         if (a <= b) {           p[i] = t[i];           a++;         } else {           p[i] = s[i];           b++;         }       }     }     cout << p;   }


#include <bits/stdc++.h>   using namespace std;   long long aa[258], bb[258];   int main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0), cerr <<   ;     string a, b;     long long n;     cin >> n;     cin >> a >> b;     long double s = 0;     for (int i = 1; i <= n; ++i)       aa[b[i - 1]] += i,           s += (n - i + 1) * (aa[a[i - 1]] + bb[b[i - 1]]) * 1.0 / n,           bb[a[i - 1]] += i;     long double l = s * 1.0 / (n + 1) / (2 * n + 1);     l *= 6.0;     cout.precision(9);     cout << fixed << l;   }


#include <bits/stdc++.h>   using namespace std;   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     for (int tt = 0; tt < t; tt++) {       int n, flag = 0;       cin >> n;       vector<int> q(n + 1);       vector<int> p(n + 1, -1);       vector<int> use(n + 1, 0);       for (int i = 1; i <= n; i++) cin >> q[i];       p[1] = q[1];       use[q[1]] = 1;       for (int i = 2; i <= n; i++)         if (q[i] > q[i - 1]) {           p[i] = q[i];           use[q[i]] = 1;         }       vector<int> w;       for (int i = 1; i <= n; i++)         if (use[i] == 0) w.push_back(i);       int u = 0;       for (int i = 1; i <= n; i++)         if (p[i] == -1) {           p[i] = w[u];           u++;         }       int ma = p[1];       for (int i = 1; i <= n; i++) {         ma = max(ma, p[i]);         if (ma != q[i]) flag = 1;       }       if (flag == 0) {         for (int i = 1; i <= n; i++) cout << p[i] <<    ;       } else         cout << -1;       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   double dist(double x1, double y1, double x2, double y2) {     double dx = x1 - x2;     double dy = y1 - y2;     return sqrt(dx * dx + dy * dy);   }   double catet(double a, int b) {     double z = a * a - b * b;     if (z < 1e-12) z = 0;     return sqrt(z);   }   int main() {     int xp, yp, vp;     cin >> xp >> yp >> vp;     int x, y, v, r;     cin >> x >> y >> v >> r;     const double eps = 1e-10;     const double R = sqrt(1.0 * xp * xp + 1.0 * yp * yp);     double lo = 0;     double hi = 1e7;     double T;     while ((hi - lo) / hi > eps) {       T = (lo + hi) / 2;       const double alpha = T / (R / vp);       double nx = xp * cos(alpha) - yp * sin(alpha);       double ny = xp * sin(alpha) + yp * cos(alpha);       double a = ny - y;       double b = x - nx;       double c = -(a * x + b * y);       double z = sqrt(a * a + b * b);       a /= z;       b /= z;       c /= z;       double need;       if (fabs(c) < r - 1e-8) {         double mx = a * (-c);         double my = b * (-c);         if (dist(x, y, mx, my) + dist(mx, my, nx, ny) >             dist(x, y, nx, ny) + 1e-8) {           need = dist(x, y, nx, ny);         } else {           need = catet(dist(x, y, 0, 0), r) + catet(dist(nx, ny, 0, 0), r);           double alp = fabs(atan2(y, x) - atan2(ny, nx));           if (alp > M_PI) alp = 2 * M_PI - alp;           alp -= acos(r / dist(x, y, 0, 0));           alp -= acos(r / dist(nx, ny, 0, 0));           need += alp * r;         }       } else {         need = dist(x, y, nx, ny);       }       if (need <= v * T) {         hi = T;       } else {         lo = T;       }     }     printf( %.6f n , T);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   namespace ioput {   template <typename T>   T read() {     T x = 0, f = 1;     char c = getchar_unlocked();     while ((c <  0 ) || (c >  9 )) {       if (c ==  - ) f = -1;       c = getchar_unlocked();     }     while ((c >=  0 ) && (c <=  9 ))       x = (x << 1) + (x << 3) + (c ^ 48), c = getchar_unlocked();     return x * f;   }   template <typename T>   void write(T x, char c) {     static char t[20];     static int tlen;     t[tlen = 1] = c;     if (x < 0) putchar_unlocked( - ), x = -x;     do t[++tlen] = x % 10 +  0 , x /= 10;     while (x);     while (tlen) putchar_unlocked(t[tlen--]);   }   }  // namespace ioput   using namespace ioput;   const int maxn = 100005;   struct seg {     int id, pos, t;     bool operator<(const seg &A) const {       return pos - t == A.pos - A.t ? pos < A.pos : pos - t < A.pos - A.t;     }   } a[maxn], b[maxn], tmp[maxn];   int a_cnt, b_cnt;   int p[maxn], n, W, H;   pair<int, int> ans[maxn];   int main() {     n = read<int>(), W = read<int>(), H = read<int>();     int type, pos, t;     for (int i = 1, iend = n; i <= iend; ++i) {       type = read<int>(), pos = read<int>(), t = read<int>();       if (type == 1)         a[++a_cnt] = (seg){i, pos, t};       else         b[++b_cnt] = (seg){i, pos, t};     }     sort(a + 1, a + 1 + a_cnt);     sort(b + 1, b + 1 + b_cnt);     int cur = 1;     for (int i = 1, iend = a_cnt; i <= iend; ++i) {       static stack<int> stk;       int j = i;       while ((j < a_cnt) && (a[j + 1].pos - a[j + 1].t == a[i].pos - a[i].t)) ++j;       int pos = j, tmpcur;       while ((cur <= b_cnt) && (b[cur].pos - b[cur].t < a[i].pos - a[i].t)) ++cur;       tmpcur = cur;       for (int k = j, kend = i; k >= kend; --k) stk.push(a[k].id);       while ((cur <= b_cnt) && (b[cur].pos - b[cur].t == a[i].pos - a[i].t))         stk.push(b[cur].id), ++cur;       for (int k = i, kend = j; k <= kend; ++k) a[k].id = stk.top(), stk.pop();       for (int k = cur - 1, kend = tmpcur; k >= kend; --k)         b[k].id = stk.top(), stk.pop();       i = j;     }     for (int i = 1, iend = a_cnt; i <= iend; ++i)       ans[a[i].id] = make_pair(a[i].pos, H);     for (int i = 1, iend = b_cnt; i <= iend; ++i)       ans[b[i].id] = make_pair(W, b[i].pos);     for (int i = 1, iend = n; i <= iend; ++i)       printf( %d %d n , ans[i].first, ans[i].second);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int ipow(int base, int exp) {     int result = 1;     for (;;) {       if (exp & 1) result *= base;       exp >>= 1;       if (!exp) break;       base *= base;     }     return result;   }   void show(int a[], int array_size) {     for (int i = 0; i < array_size; ++i) cout << a[i] <<    ;     cout <<   n ;   }   int cc(int target, int q, int current) {     if (q == 0) {       if (target == current)         return 1;       else         return 0;     } else       return (cc(target, q - 1, current + 1) + cc(target, q - 1, current - 1));   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n, m;     cin >> n >> m;     int x, y;     cin >> x >> y;     int v, i;     cin >> v;     long long o = 0;     for (i = 0; i < v; i++) {       int x1, y1, X, Y;       cin >> x1 >> y1;       if (x1 == 0)         X = 1000000005;       else         X = max((1 - x) / x1, (n - x) / x1);       if (y1 == 0)         Y = 1000000005;       else         Y = max((1 - y) / y1, (m - y) / y1);       int d = min(X, Y);       o = o + (long long)d;       x += d * x1;       y += d * y1;     }     cout << o <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int tt = 1;     while (tt--) {       int n, a, b, c;       cin >> n >> a >> b >> c;       int mv = min(min(a, b), c);       int q = n / mv, ans = 0;       for (int x = 0; x <= q; x++) {         for (int y = 0; y <= q - x; y++) {           float z = ((n - x * a - y * b) * 1.0) / c;           if (z == (int)z && z >= 0) ans = max(ans, x + y + (int)z);         }       }       cout << ans;     }   }


#include <bits/stdc++.h>   using namespace std;   pair<int, int> a, b, t, points[100000];   int n;   double d[100000];   pair<double, int> s1[100000], s2[100000];   double dist(pair<int, int> first, pair<int, int> second) {     long long x = first.first - second.first;     long long y = first.second - second.second;     return sqrt(x * x + y * y);   }   int main() {     cin >> a.first >> a.second >> b.first >> b.second >> t.first >> t.second >> n;     double ans = 0;     for (int i = 0; i < n; i++) {       cin >> points[i].first >> points[i].second;       d[i] = dist(points[i], t);       ans += 2 * d[i];       s1[i] = pair<double, int>(dist(a, points[i]) - d[i], i);       s2[i] = pair<double, int>(dist(b, points[i]) - d[i], i);     }     sort(s1, s1 + n);     sort(s2, s2 + n);     double ans1;     double ans2;     double ans3;     ans1 = ans + s1[0].first;     ans2 = ans + s2[0].first;     if (s1[0].second != s2[0].second) {       ans3 = ans + s1[0].first + s2[0].first;     } else       ans3 = ans + min(s1[0].first + s2[1].first, s1[1].first + s2[0].first);     cout << setprecision(9);     cout << min(ans1, min(ans2, ans3));   }


#include <bits/stdc++.h>   using namespace std;   int a[102];   int b[102];   int main() {     int n, m;     cin >> n >> m;     int num = 0;     for (int i = 1; i <= m; i++) {       int q = 0;       for (int j = 1; j <= n; j++) {         cin >> a[j];         q = max(q, a[j]);       }       for (int l = 1; l <= n; l++) {         if (a[l] == q) {           b[l]++;           break;         }       }     }     int t = 0;     for (int j = 1; j <= 100; j++) {       t = max(t, b[j]);     }     for (int l = 1; l <= 100; l++) {       if (t == b[l]) {         cout << l;         break;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int max_n = 300005;   int n, m;   int p[max_n];   int rk[max_n];   bool vis[max_n];   vector<int> G[max_n];   set<int> s;   void dfs(int u) {     for (auto v : G[u]) s.erase(rk[v]);     vector<int> can;     for (auto v : s) {       if (v < rk[u]) {         v = p[v];         can.push_back(v);         vis[rk[v]] = true;       } else         break;     }     for (auto v : G[u])       if (!vis[rk[v]]) s.insert(rk[v]);     for (auto v : can) s.erase(rk[v]);     for (auto v : can) dfs(v);   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) scanf( %d , p + i), rk[p[i]] = i;     for (int i = 0; i < m; i++) {       int u, v;       scanf( %d%d , &u, &v);       G[v].push_back(u);     }     for (int i = 1; i <= n - 1; i++) s.insert(i);     vis[n] = true;     dfs(p[n]);     printf( %d n , s.size());     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     int n, a, b;     cin >> n >> a >> b;     if (abs(a - b) > 1 || (a + b) > n - 2) {       cout <<  -1  << endl;       return;     }     int l = 1, r = n;     int arr[n + 5];     for (int i = 1; i <= n; i++) arr[i] = i;     if (a > b)       for (int i = 1; i <= a; i++) swap(arr[r], arr[r - 1]), r -= 2;     else if (b > a)       for (int i = 1; i <= b; i++) swap(arr[l], arr[l + 1]), l += 2;     else {       if (b > 0)         swap(arr[l], arr[l + 1]), l += 2, swap(arr[r], arr[r - 1]), r -= 2, b--;       for (int i = 1; i <= b; i++) swap(arr[l], arr[l + 1]), l += 2;     }     for (int i = 1; i <= n; i++) cout << arr[i] <<    ;     cout << endl;   }   int main() {     int t;     cin >> t;     while (t--) solve();   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     int a[m], b[m];     for (int i = 0; i < m; i++) {       cin >> a[i];       b[i] = a[i];     }     int min = 0;     for (int i = 0; i < n; i++) {       int t1 = INT_MAX;       int loc = -1;       for (int j = 0; j < m; j++) {         if (a[j] < t1 && a[j] > 0) {           t1 = a[j];           loc = j;         }       }       a[loc] -= 1;       min += t1;     }     int max = 0;     for (int i = 0; i < n; i++) {       int t = INT_MIN;       int loc = -1;       for (int j = 0; j < m; j++) {         if (b[j] > t && b[j] > 0) {           t = b[j];           loc = j;         }       }       max += t;       b[loc] -= 1;     }     cout << max <<     << min << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int inf(1010101010);   const long long P(29);   long long pp[100005];   long long ch[100005];   inline bool eq(int start1, int start2, int le) {     long long h1(ch[start1 + le] - ch[start1]);     long long h2(ch[start2 + le] - ch[start2]);     return h1 * pp[start2] == h2 * pp[start1];   }   int n, a[100005];   map<int, vector<int> > startpos;   int shortest[100005];   int cmin[100005];   int main() {     cin >> n;     for (int i(0); i < (n); i++) cin >> a[i], startpos[a[i]].push_back(i);     ch[0] = 0;     pp[0] = 1;     int i(1);     for (; i <= (n); i++) {       ch[i] = ch[i - 1] + pp[i - 1] * a[i - 1];       pp[i] = pp[i - 1] * P;     }     for (int i(0); i < (n); i++) {       shortest[i] = inf;       int startnum(a[i]);       vector<int> const& v(startpos[startnum]);       for (__typeof((v).end()) it((v).begin()); it != ((v).end()); ++it) {         int j(*it);         if (j <= i) continue;         int le(j - i);         if (j + le <= n && eq(i, j, le)) shortest[i] = min(shortest[i], le);       }     }     cmin[n] = inf;     for (int i(n - 1); i >= (0); i--) {       cmin[i] = min(cmin[i + 1], shortest[i]);     }     int pt(0);     for (; pt < (n);) {       int le(cmin[pt]);       if (le == inf) break;       int loc(find(shortest + pt, shortest + n, le) - shortest);       pt = loc + le;     }     cout << (n - pt) << endl;     for (int i(pt); i < (n); i++) cout << a[i] <<    ;     cout << endl;   }


#include <bits/stdc++.h>   using namespace std;   int e, s, n, m, st, q[4][200000 + 10];   pair<int, int> a[200000 * 2 + 10], f[200000 * 2 + 10], ans[200000 + 10];   int main() {     int i, front[4], rear[4], j;     memset(f, 0xff, sizeof f);     memset(ans, 0xff, sizeof ans);     scanf( %d%d%d%d , &e, &s, &n, &m);     for (i = 1; i <= n; i++) scanf( %d%d , &a[i].second, &a[i].first);     for (i = 1; i <= m; i++) {       scanf( %d , &a[i + n].first);       a[i + n].second = 3 + i;     }     sort(a + 1, a + n + m + 1);     for (i = 1; i <= n + m; i++)       if (a[i].first > e) break;     if (a[i].first == e) i--;     a[i].first = e, a[i].second = 3;     e = i;     f[e] = make_pair(0, 0);     q[3][0] = e;     front[3] = rear[3] = 0;     front[2] = front[1] = 0;     rear[2] = rear[1] = -1;     for (i = e - 1; i; i--) {       int t = 0x7fffffff;       while (front[3] <= rear[3] && a[q[3][front[3]]].first - a[i].first > s)         front[3]++;       while (front[2] <= rear[2] && a[q[2][front[2]]].first - a[i].first > s)         front[2]++;       while (front[1] <= rear[1] && a[q[1][front[1]]].first - a[i].first > s)         front[1]++;       if (a[i].second > 3) {         for (j = 3; j > 0; j--)           if (front[j] <= rear[j]) {             if (j == 1)               ans[a[i].second - 3] =                   make_pair(f[q[j][front[j]]].first - s +                                 a[q[j][front[j]]].first - a[i].first,                             f[q[j][front[j]]].second);             else if (j == 2)               ans[a[i].second - 3] =                   make_pair(f[q[j][front[j]]].first,                             f[q[j][front[j]]].second - s +                                 a[q[j][front[j]]].first - a[i].first);             else               ans[a[i].second - 3] =                   make_pair(f[q[j][front[j]]].first, f[q[j][front[j]]].second);             break;           }         if (!i) ans[a[i].second] = make_pair(-1, -1);         continue;       }       for (j = 3; j >= a[i].second; j--)         if (front[j] <= rear[j]) t = min(t, q[j][rear[j]]);       if (t == 0x7fffffff)         for (; j; j--)           if (front[j] <= rear[j]) {             t = q[j][front[j]];             break;           }       if (t == 0x7fffffff) break;       f[i] = f[t];       if (a[t].second >= a[i].second) {         if (a[i].second == 1)           f[i].first += a[t].first - a[i].first;         else if (a[i].second == 2)           f[i].second += a[t].first - a[i].first;       } else {         if (a[i].second == 2) {           f[i].second += s;           f[i].first -= s - a[t].first + a[i].first;         } else if (a[i].second == 3) {           if (a[t].second == 2)             f[i].second -= s - a[t].first + a[i].first;           else             f[i].first -= s - a[t].first + a[i].first;         }       }       q[a[i].second][++rear[a[i].second]] = i;     }     for (i = 1; i <= m; i++) printf( %d %d n , ans[i].first, ans[i].second);   }


#include <bits/stdc++.h>   using namespace std;   #define mp make_pair   #define pb push_back   #define x first   #define y second   typedef pair<int,int> pii;   typedef long long ll;   typedef unsigned long long ull;   template <typename T> void chkmax(T &x,T y){x<y?x=y:T();}   template <typename T> void chkmin(T &x,T y){y<x?x=y:T();}   template <typename T> void readint(T &x)   {    x=0;int f=1;char c;    for(c=getchar();!isdigit(c);c=getchar())if(c== - )f=-1;    for(;isdigit(c);c=getchar())x=x*10+(c- 0 );    x*=f;   }   const int MOD1=1010101039,MOD2=1000020001;   const int MAXN=300005,MAXK=19,MAXV=MAXN*21;      int n,a[MAXN];   vector<int> G[MAXN];   int anc[MAXN][MAXK],dep[MAXN];   int stot,vs[MAXN];   pii h[MAXV],pw[MAXN];   int lch[MAXV],rch[MAXV];   pii operator *(pii a,pii b){return mp(1ll*a.x*b.x%MOD1,1ll*a.y*b.y%MOD2);}   pii operator +(pii a,pii b){return mp((a.x+b.x)%MOD1,(a.y+b.y)%MOD2);}   int modify(int id,int l,int r,int x)   {    int rt=++stot;    if(l==r)    {     h[rt]=mp(1-h[id].x,1-h[id].y);     return rt;    }    int mid=(l+r)>>1;    if(x<=mid)lch[rt]=modify(lch[id],l,mid,x),rch[rt]=rch[id];    else rch[rt]=modify(rch[id],mid+1,r,x),lch[rt]=lch[id];    h[rt]=h[lch[rt]]*pw[r-mid]+h[rch[rt]];    return rt;   }   int query(int u,int v,int l,int r,int ql,int qr)   {    if(h[u]==h[v])return -1;    if(l==r)return l;    int mid=(l+r)>>1;    if(qr<=mid)return query(lch[u],lch[v],l,mid,ql,qr);    if(ql>mid)return query(rch[u],rch[v],mid+1,r,ql,qr);    int s=query(lch[u],lch[v],l,mid,ql,mid);    if(s>0)return s;    return query(rch[u],rch[v],mid+1,r,mid+1,qr);   }   void dfs(int u,int pa)   {    for(int j=1;j<MAXK;++j)anc[u][j]=anc[anc[u][j-1]][j-1];    for(auto v:G[u])     if(v!=pa)     {      anc[v][0]=u;      dep[v]=dep[u]+1;      vs[v]=modify(vs[u],1,n,a[v]);      dfs(v,u);     }   }   int lca(int u,int v)   {    if(dep[u]>dep[v])swap(u,v);    for(int i=MAXK-1;i>=0;--i)if(dep[anc[v][i]]>=dep[u])v=anc[v][i];    if(u==v)return u;    for(int i=MAXK-1;i>=0;--i)if(anc[u][i]!=anc[v][i])u=anc[u][i],v=anc[v][i];    return anc[u][0];   }      int main()   {    #ifdef LOCAL    freopen( code.in , r ,stdin);   // freopen( code.out , w ,stdout);    #endif    int Q,u,v,l,r;    readint(n),readint(Q);    for(int i=1;i<=n;++i)readint(a[i]);    for(int i=1;i<n;++i)readint(u),readint(v),G[u].pb(v),G[v].pb(u);    pw[0]=mp(1,1);pw[1]=mp(29,101);    for(int i=2;i<=n;++i)pw[i]=pw[i-1]*pw[1];     vs[1]=modify(0,1,n,a[1]);    dep[1]=1;    dfs(1,-1);    while(Q--)    {     readint(u),readint(v),readint(l),readint(r);     int d=lca(u,v);     if(a[d]<l || a[d]>r)     {      int t=query(vs[u],vs[v],1,n,l,r);      printf( %d n ,t);     }     else     {      int t=(a[d]==l?-1:query(vs[u],vs[v],1,n,l,a[d]-1));      if(t<0)      {       t=(a[d]==r?-1:query(vs[u],vs[v],1,n,a[d]+1,r));       if(t<0)       {        t=query(vs[u],vs[v],1,n,a[d],a[d]);        if(t==-1)t=a[d];        else t=-1;       }      }      printf( %d n ,t);     }    }    return 0;   }


#include <bits/stdc++.h>   using namespace std;   int price[100005];   int sum[100005];   vector<int> tempo;   int main() {     int n, t;     scanf( %d , &n);     tempo.push_back(0);     for (int i = 1; i <= n; i++) {       scanf( %d , &t);       if (i == 1) {         price[i] = 20;         sum[i] = 20;         tempo.push_back(t);         continue;       }       int fim = i - 1;       int ini = (int)(lower_bound(tempo.begin(), tempo.end(), t - 1440 + 1) -                       tempo.begin());       ini = max(ini - 1, 0);       int p = (sum[fim] - sum[ini] >= 120 ? 0 : 120 - (sum[fim] - sum[ini]));       ini = (int)(lower_bound(tempo.begin(), tempo.end(), t - 90 + 1) -                   tempo.begin());       ini = max(ini - 1, 0);       int aux = (sum[fim] - sum[ini] >= 50 ? 0 : 50 - (sum[fim] - sum[ini]));       price[i] = min(p, min(aux, 20));       sum[i] = sum[i - 1] + price[i];       tempo.push_back(t);     }     for (int i = 1; i <= n; i++) {       printf( %d n , price[i]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main(int argc, char* argv[]) {     long long ax, ay, bx, by, cx, cy, ab, bc;     double slopeAB, slopeBC;     cin >> ax >> ay >> bx >> by >> cx >> cy;     if (ax == cx && ay == cy) {       cout <<  Yes n ;     } else {       ab = (ax - bx) * (ax - bx) + (ay - by) * (ay - by);       bc = (cx - bx) * (cx - bx) + (cy - by) * (cy - by);       slopeAB = (double)(ay - by) / (double)(ax - bx);       slopeBC = (double)(by - cy) / (double)(bx - cx);       if (ab == bc && slopeAB != slopeBC) {         cout <<  Yes n ;       } else {         cout <<  No n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long bigmod(long long b, long long p, long long m) {     if (p == 0) return 1;     if (p % 2 == 0) {       long long temp = bigmod(b, p / 2, m);       return (temp * temp) % m;     }     return (bigmod(b, p - 1, m) * (b % m)) % m;   }   int main() {     string s;     cin >> s;     int n = s.length();     long long cnt = 0;     long long ans = 0;     long long mod = 1e9 + 7;     for (int i = 0; i < n; i++) {       if (s[i] ==  a ) {         cnt++;       } else {         if (cnt > 0) ans += (bigmod(2, cnt, mod) - 1);         ans %= mod;       }     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   vector<bool> was;   vector<vector<int> > es;   vector<int> cst;   vector<int> cols;   vector<vector<int> > cycs;   void dfs(int v, int par = -1) {     was[v] = true;     cst.push_back(v);     for (int i = 0; i < ((int)(es[v]).size()); i++) {       int b = es[v][i];       if (b == par) continue;       if (was[b]) {         if (cols[v] >= 0) {           assert(cols[v] == cols[b]);         } else {           int cid = ((int)(cycs).size());           cycs.push_back(vector<int>());           for (int i2 = ((int)(cst).size()) - 1; i2 >= 0; i2--) {             cycs[cid].push_back(cst[i2]);             assert(cols[cst[i2]] < 0);             cols[cst[i2]] = cid;             if (cst[i2] == b) break;           }         }       } else         dfs(b, v);     }     cst.pop_back();   }   int dfs2(int v, int par = -1) {     int cid = cols[v];     int res = ((int)(cycs[cid]).size()) > 1;     int sumcnt = 0;     int nzcnt = 0;     for (int i = 0; i < ((int)(cycs[cid]).size()); i++) {       int a = cycs[cid][i];       int subcnt = 0;       for (int i2 = 0; i2 < ((int)(es[a]).size()); i2++) {         int b = es[a][i2];         if (cols[b] == cid) continue;         int cres = -1;         if (b != par) {           cres = dfs2(b, a);         } else {           cres = 1;         }         res += cres;         subcnt++;       }       res -= subcnt / 2;       sumcnt += subcnt;       if (subcnt) nzcnt++;     }     if (((int)(cycs[cid]).size()) > 1) {       if (nzcnt >= 2) {         res -= 1;       }     }     return res;   }   int main() {     int n, m;     while (scanf( %d%d , &n, &m) >= 1) {       es = vector<vector<int> >(n);       for (int i = 0; i < m; i++) {         int a, b;         scanf( %d%d , &a, &b), a--, b--;         es[a].push_back(b);         es[b].push_back(a);       }       was = vector<bool>(n, false);       cst.clear();       cols = vector<int>(n, -1);       cycs = vector<vector<int> >();       dfs(0);       for (int i = 0; i < n; i++)         if (cols[i] < 0) {           int cid = ((int)(cycs).size());           cycs.push_back(vector<int>(1, i));           cols[i] = cid;         }       int ans = dfs2(0);       printf( %d %d n , ans, m);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int T = 7;   int prosti[] = {114689, 163841, 147457, 188417, 151553, 270337, 286721};   int proots[] = {3, 3, 10, 3, 3, 10, 11};   int pows[7][300000];   void fft_trivial(vector<int>& a, int id) {     int n = a.size();     int mod = prosti[id];     int step = (mod - 1) / n;     vector<int> b(n);     for (int i = 0; i < n; i++) {       for (int k = 0, w = 0; k < n; k++, w = (w + i * step) % (mod - 1)) {         b[i] += a[k] * 1ll * pows[id][w] % mod;         if (b[i] >= mod) b[i] -= mod;       }     }     swap(a, b);   }   void fft(vector<int>& a, int id) {     int n = a.size();     if (n & 1) {       fft_trivial(a, id);       return;     }     int mod = prosti[id];     int step = (mod - 1) / n;     int h = n >> 1;     vector<int> b(h), c(h);     for (int i = 0; i < h; i++) {       b[i] = a[2 * i];       c[i] = a[2 * i + 1];     }     fft(b, id);     fft(c, id);     for (int i = 0, w = 0; i < h; i++, w += step) {       int bb = b[i];       int cc = c[i] * 1ll * pows[id][w] % mod;       int u = bb + cc;       int v = bb - cc;       if (u >= mod) u -= mod;       if (v < 0) v += mod;       a[i] = u;       a[i + h] = v;     }   }   void init() {     for (int i = 0; i < T; i++) {       int p = 1, q = proots[i];       for (int j = 0; j < 300000; j++) {         pows[i][j] = p;         p = p * 1ll * q % prosti[i];       }     }   }   int hsh(string s, int mod, int b) {     int z = 0;     for (int i = 0, p = 1; i < (int)s.size(); i++, p = p * 1ll * b % mod)       z = (z + s[i] * 1ll * p) % mod;     return z;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     cerr.tie(nullptr);     init();     int n, m;     string a, b;     cin >> n >> m >> a >> b;     for (int i = 0; i < T; i++) {       int mod = prosti[i];       vector<int> va(mod - 1, 0), vb(mod - 1, 0);       for (int j = 0; j < n; j++) {         va[j] = a[j];         vb[j] = b[j];       }       fft(va, i);       fft(vb, i);       for (int r = 0; r < mod - 1; r++) {         int y = pows[i][r];         if (va[r] == vb[r] && y > 1 && y < mod - 1) {           cout << mod <<     << y <<   n ;           return 0;         }       }     }     cout <<  Failed n ;     return 1;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:536870912 )   #pragma warning(disable : 4996)   using namespace std;   const int N = 5e5 + 100;   int q[N], a[N], b[N], w[N], used[N], in[N];   bool ok[N];   vector<int> tr[N], d[N];   vector<pair<int, vector<int>>> gr[N];   vector<pair<int, int>> ed;   int col = 0, cg = 0;   int find(int v) { return q[v] < 0 ? v : q[v] = find(q[v]); }   bool un(int a, int b) {     a = find(a), b = find(b);     if (a != b) {       if (q[a] > q[b]) swap(a, b);       q[a] += q[b];       q[b] = a;       return true;     }     return false;   }   bool dfs(int node, int p) {     used[node] = col;     for (int to : tr[node]) {       if (to == p) continue;       if (used[to] == col)         return true;       else if (dfs(to, node))         return true;     }     return false;   }   int main() {     int n, m;     scanf( %d%d , &n, &m);     memset(q, -1, sizeof(q));     ;     for (int i = 0; i < m; i++) {       scanf( %d%d%d , &a[i], &b[i], &w[i]);       a[i]--, b[i]--;       ed.push_back({w[i], i});     }     sort(ed.begin(), ed.end());     int t;     scanf( %d , &t);     for (int i = 0; i < t; i++) {       int k;       scanf( %d , &k);       for (int j = 0; j < k; j++) {         scanf( %d , &in[j]);         in[j]--;         if (gr[w[in[j]]].empty() || !gr[w[in[j]]].back().second.empty()) {           gr[w[in[j]]].push_back({cg, vector<int>()});           d[i].push_back(cg);           cg++;         }       }       for (int j = 0; j < k; j++) {         gr[w[in[j]]].back().second.push_back(in[j]);       }     }     for (int i = 0; i < ed.size(); i++) {       if (i == 0 || ed[i].first != ed[i - 1].first) {         for (auto &p : gr[ed[i].first]) {           for (int j : p.second) {             int x = find(a[j]), y = find(b[j]);             tr[x].push_back(y);             tr[y].push_back(x);           }           col++;           ok[p.first] = 1;           for (int j : p.second) {             int x = find(a[j]);             if (used[x] != col && dfs(x, -1)) {               ok[p.first] = 0;               break;             }           }           for (int j : p.second) {             int x = find(a[j]), y = find(b[j]);             tr[x].clear();             tr[y].clear();           }         }       }       un(a[ed[i].second], b[ed[i].second]);     }     for (int i = 0; i < t; i++) {       bool f = true;       for (int j : d[i]) {         if (!ok[j]) {           f = false;           break;         }       }       printf( %s n , f ?  YES  :  NO );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     string str;     for (int i = 1; i <= t; i++) {       cin >> str;       string str1;       str1.append(str, 0, 1);       int j = 1, l = str.length();       while (j < l) {         str1.append(str, j, 1);         j += 2;       }       cout << str1 <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   #pragma warning(disable : 4996)   int a[100010], cnt[100010];   int queries[100010][2];   bool res[100010];   bool xpeHb[100010];   int main() {     int t;     scanf( %d , &t);     for (int y = 0; y < t; y++) {       int m, k;       scanf( %d %d , &m, &k);       for (int i = 1; i <= k; i++) {         scanf( %d , &a[i]);       }       int t, r;       int count = 0;       bool flag = false;       for (int i = 0; i < m - 1; i++) {         scanf( %d %d , &queries[i][0], &queries[i][1]);         if (queries[i][1] == 1) flag = true;         if (flag) {           if (queries[i][0]) xpeHb[queries[i][0]] = true;         }       }       flag = true;       for (int i = 0; i < m - 1; i++) {         t = queries[i][0];         r = queries[i][1];         if (r == 1 && flag) {           flag = false;           int max = 0;           for (int j = 1; j <= k; j++) {             if (cnt[j] + count >= a[j] && !xpeHb[j]) {               res[j] = true;               if (max < cnt[j] + count - a[j]) max = cnt[j] + count - a[j];             }           }           count = max;         }         if (t == 0)           count++;         else {           cnt[t]++;         }       }       for (int j = 1; j <= k; j++) {         if (cnt[j] + count >= a[j]) {           res[j] = true;         }         if (res[j])           printf( Y );         else           printf( N );       }       printf(  n );       memset(cnt, 0, (k + 1) * 4);       memset(res, 0, (k + 1) * 1);       memset(a, 0, (k + 1) * 4);       memset(xpeHb, 0, (k + 1) * 1);       memset(queries[0], 0, (m + 1) * 4);       memset(queries[1], 0, (m + 1) * 4);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   namespace fast {   inline char nc() {     static char buf[100000], *L = buf, *R = buf;     return L == R && (R = (L = buf) + fread(buf, 1, 100000, stdin), L == R)                ? EOF                : *L++;   }   template <class orz>   inline void qread(orz &x) {     x = 0;     char ch = nc();     bool f = 0;     while (ch <  0  || ch >  9 ) (ch ==  - ) && (f = 1), ch = nc();     while (ch >=  0  && ch <=  9 ) x = (x << 3) + (x << 1) + (ch ^ 48), ch = nc();     f && (x = -x);   }   }  // namespace fast   using namespace fast;   template <class orz>   inline void read(orz &x) {     x = 0;     bool f = 0;     char ch = getchar();     while (ch <  0  || ch >  9 ) (ch ==  - ) && (f = 1), ch = getchar();     while (ch >=  0  && ch <=  9 )       x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();     f && (x = -x);   }   template <class orz>   inline void out(orz x) {     (x < 0) && (putchar( - ), x = -x);     if (x > 9) out(x / 10);     putchar(x % 10 +  0 );   }   const double PI = acos(-1);   const double eps = 1e-8;   const int INF = 0x3f3f3f3f;   const long long mod = 1e9 + 7;   const int maxn = 1e3 + 5;   int a[maxn][maxn];   int n, m;   int r[maxn], c[maxn];   int main() {     cin >> n >> m;     for (int i = 0; i < n; i++) read(r[i]);     for (int i = 0; i < m; i++) read(c[i]);     for (int i = 0; i < n; i++) {       if (r[i] == 0) {         a[i][0] = -1;       } else {         for (int j = 0; j < r[i]; j++) {           a[i][j] = 1;         }         a[i][r[i]] = -1;       }     }     int flag = 0;     long long sum = 1;     for (int i = 0; i < m; i++) {       if (c[i] == 0) {         if (a[0][i] == 0 || a[0][i] == -1)           a[0][i] = -1;         else {           flag = 1;           break;         }       } else {         for (int j = 0; j < c[i]; j++) {           if (a[j][i] == 0 || a[j][i] == 1)             a[j][i] = 1;           else {             flag = 1;             break;           }         }         if (a[c[i]][i] == 0 || a[c[i]][i] == -1)           a[c[i]][i] = -1;         else {           flag = 1;           break;         }       }     }     if (!flag) {       for (int i = 0; i < n; i++) {         for (int j = 0; j < m; j++) {           if (a[i][j] == 0) sum = sum * 2 % mod;         }       }       cout << sum << endl;     } else       cout <<  0  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     int sum = 0;     int i = 0;     while (i < n) {       int x;       cin >> x;       sum += x;       ++i;     }     cout << fixed << setprecision(12);     cout << (long double)sum / n;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int q;     cin >> q;     unsigned long long c;     for (int i = 0; i < q; i++) {       cin >> c;       if ((c < 4) | (c % 2 != 0 & c < 13 & c != 9))         cout << -1 << endl;       else {         if (c % 2 != 0)           cout << (c - 9) / 4 + 1 << endl;         else           cout << c / 4 << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     int tc;     cin >> tc;     while (tc--) {       int arr[103][103];       long long cnt = 0;       int n, m;       cin >> n >> m;       for (int i = 1; i <= n; i++)         for (int j = 1; j <= m; j++) cin >> arr[i][j];       for (int i = 1; i <= n / 2; i++) {         vector<int> a;         for (int j = 1; j <= m / 2; j++) {           a.push_back(arr[i][j]);           a.push_back(arr[n + 1 - i][j]);           a.push_back(arr[i][m + 1 - j]);           a.push_back(arr[n + 1 - i][m + 1 - j]);           sort(a.begin(), a.end());           for (int tmp : a) cnt += abs(tmp - a[1]);           a.clear();         }         if (m % 2) cnt += abs(arr[i][m / 2 + 1] - arr[n + 1 - i][m / 2 + 1]);       }       if (n % 2) {         for (int j = 1; j <= m / 2; j++)           cnt += abs(arr[n / 2 + 1][j] - arr[n / 2 + 1][m + 1 - j]);       }       cout << cnt <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, m, hours_digit = 1, minutes_digit = 1;     cin >> n >> m;     long long int temp = 0;     for (long long int a = 7; a < n; a *= 7) hours_digit += 1;     for (long long int b = 7; b < m; b *= 7) minutes_digit += 1;     if (hours_digit + minutes_digit > 7) {       cout << 0 << endl;       return 0;     }     long long int final_ans = 0;     for (int i = 0; i < n; i++) {       vector<int> arr(7, 0);       temp = i;       int temp2 = 0;       while (temp > 0) {         arr[temp % 7]++;         temp = temp / 7;         temp2++;       }       arr[0] += hours_digit - temp2;       for (int j = 0; j < m; j++) {         vector<int> arr2(7, 0);         temp = j;         temp2 = 0;         while (temp > 0) {           arr2[temp % 7]++;           temp = temp / 7;           temp2++;         }         arr2[0] += minutes_digit - temp2;         int flag = 0;         for (int k = 0; k < 7; k++) {           if (arr2[k] + arr[k] > 1) {             flag = 1;             break;           }         }         if (flag == 0) {           final_ans++;         }       }     }     cout << final_ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   long long size, seg1[2 * 200005], seg2[2 * 200005], a[200005], b[200005],       seg3[2 * 200005], seg4[2 * 200005];   long long temp = 0;   long long f(long long u, long long v) { return min(u, v); }   long long query(long long l, long long r, long long u, long long v,                   long long seg[]) {     long long mid = (u + v) / 2;     if ((l == u) && (r == v))       return seg[(size + u) / (r - l + 1) - 1];     else if (l > mid)       return query(l, r, mid + 1, v, seg);     else if (r <= mid)       return query(l, r, u, mid, seg);     else       return f(query(l, mid, u, mid, seg), query(mid + 1, r, mid + 1, v, seg));   }   void update(long long ind, long long num, long long seg[]) {     long long pos = size + ind - 1;     seg[pos] = num;     while (pos) {       seg[(pos - 1) / 2] = f(seg[pos], seg[pos + pos % 2 * 2 - 1]);       pos--;       pos /= 2;     }   }   int main() {     ios::sync_with_stdio(false);     long long i, t, j, k, l, m, n;     cin >> n;     long long INF = 1;     for (size = 1; size < n; size *= 2)       ;     for (i = 0; i < n; i++) {       cin >> a[i];       update(i, a[i], seg1);     }     long long maxi = -INF, cnt = 0;     for (i = 0; i < n - 1; i++) {       maxi = max(a[i], maxi);       if (maxi <= query(i + 1, n - 1, 0, size - 1, seg1)) {         cnt++;         maxi = -INF;       }     }     cout << cnt + 1 << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, s;     cin >> n >> s;     vector<int> a(n);     --s;     for (int i = 0; i < n; ++i) cin >> a[i];     int ans = 0;     if (a[s] != 0) {       a[s] = 0;       ++ans;     }     for (int i = 0; i < n; ++i)       if ((i != s) && (a[i] == 0)) a[i] = n;     map<int, int> workers;     for (int i = 0; i < n; ++i) ++workers[a[i]];     int count = n - 1;     int max = n;     while (!workers.count(max)) --max;     for (int i = 1; count; ++i) {       if (workers[i])         count -= workers[i];       else {         ++ans;         --count;         --workers[max];         while (!workers[max]) --max;       }     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   struct debugger {     template <typename T>     debugger& operator,(const T& v) {       cerr << v <<    ;       return *this;     }   } dbg;   char ibuf[4096];   int ipt = 4096;   int readUInt() {     while (ipt < 4096 && ibuf[ipt] <  0 ) ipt++;     if (ipt == 4096) {       fread(ibuf, 1, 4096, stdin);       ipt = 0;       while (ipt < 4096 && ibuf[ipt] <  0 ) ipt++;     }     int n = 0;     char neg = 0;     if (ipt != 0 && ibuf[ipt - 1] ==  - ) neg = 1;     while (ipt < 4096 && ibuf[ipt] >=  0 ) n = (n * 10) + (ibuf[ipt++] -  0 );     if (ipt == 4096) {       fread(ibuf, 1, 4096, stdin);       ipt = 0;       while (ipt < 4096 && ibuf[ipt] >=  0 ) n = (n * 10) + (ibuf[ipt++] -  0 );     }     return neg ? -n : n;   }   int testcase;   void solve() {     int n;     scanf( %d , &n);     ;     int d;     scanf( %d , &d);     ;     int l;     scanf( %d , &l);     ;     int v[n];     int d1 = d;     if (d > 0) {       for (int i = 0; i < n; ++i) {         if (i % 2 == 0) {           if (d1 > 0) {             v[i] = min(l, d1);             d1 -= v[i];           } else {             v[i] = 1;             d1 -= 1;           }         } else {           v[i] = 1;           d1 += 1;         }       }     } else {       for (int i = 0; i < n; ++i) {         if (i % 2 == 0) {           v[i] = 1;           d1 -= 1;         } else {           if (d1 < 0) {             v[i] = min(l, -d1);             d1 += v[i];           } else {             d1 += 1;           }         }       }     }     if (d1 == 1 && l > 1) {       for (int i = 0; i < n; i++) {         if (i % 2 == 0 && v[i] < l) {           v[i]++;           d1 = 0;           break;         } else if (i % 2 == 1 && v[i] > 1) {           v[i]--;           d1 = 0;           break;         }       }     }     if (d1 == -1 && l > 1) {       for (int i = 0; i < n; i++) {         if (i % 2 == 0 && v[i] > 1) {           v[i]--;           d1 = 0;           break;         } else if (i % 2 == 1 && v[i] < l) {           v[i]++;           d1 = 0;           break;         }       }     }     if (d1 != 0) {       printf( -1 n );     } else {       for (int i = 0; i < n; ++i) {         if (i) printf(   );         printf( %d , v[i]);       }       printf(  n );     }   }   int main() {     solve();     return 0;   }