#include <bits/stdc++.h>   using namespace std;   const int M = 2e5 + 7;   int n, arr[M], d[M], b = 1, t = 0;   bool used[M];   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &arr[i]);       d[arr[i]]++;     }     for (int i = 1; i <= n; i++) {       if (d[arr[i]] > 1) {         while (n >= b && d[b]) b++;         if (arr[i] > b || used[arr[i]]) {           t++;           d[arr[i]]--;           d[b]++;           arr[i] = b;         } else           used[arr[i]] = 1;       }     }     printf( %d n , t);     for (int i = 1; i <= n; i++) {       printf( %d  , arr[i]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1);   int deg[1000];   int arr[1000][1000];   int jo[1000];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int node, edge;     cin >> node >> edge;     for (int i = 0; i < edge; i++) {       int n1, n2;       cin >> n1 >> n2;       arr[n1 - 1][n2 - 1] = true;       arr[n2 - 1][n1 - 1] = true;       deg[n1 - 1]++;       deg[n2 - 1]++;     }     int res = 0;     int i, j;     while (true) {       int k = 0;       for (i = 0; i < node; i++) {         if (deg[i] == 1) {           jo[k++] = i;           deg[i] = 0;         }       }       if (k == 0) {         break;       }       res++;       for (i = 0; i < k; i++) {         deg[jo[i]] = 0;         for (j = 0; j < node; j++) {           if (arr[jo[i]][j]) deg[j]--;         }       }     }     cout << res <<   n ;     cerr <<  Time :   << (float)clock() / CLOCKS_PER_SEC <<   s  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[111];   char in[1000];   int main() {     int t, m, i, j;     scanf( %d%d , &t, &m);     int aid = 1;     while (t--) {       scanf( %s , in);       int k;       if (in[0] ==  a ) {         scanf( %d , &k);         for (i = 0; i <= m - k; i++) {           for (j = i; j < i + k; j++)             if (a[j] != 0) break;           if (j == i + k) break;         }         if (i <= m - k) {           printf( %d n , aid);           for (j = i; j < i + k; j++) a[j] = aid;           aid++;         } else {           puts( NULL );         }       } else if (in[0] ==  e ) {         bool f = 0;         scanf( %d , &k);         for (i = 0; i < m; i++)           if (a[i] && a[i] == k) {             a[i] = 0;             f = 1;           }         if (!f) puts( ILLEGAL_ERASE_ARGUMENT );       } else {         for (i = 0, j = 0; i < m; i++)           if (a[i]) {             a[j++] = a[i];           }         for (; j < m; j++) a[j] = 0;       }     }   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ld = long double;   using P = pair<ll, ll>;   constexpr ll inf = 1000000000;   constexpr ll mod = 1000000007;   constexpr long double eps = 1e-6;   template <typename T1, typename T2>   ostream& operator<<(ostream& os, pair<T1, T2> p) {     os << to_string(p.first) <<     << to_string(p.second);     return os;   }   template <typename T>   ostream& operator<<(ostream& os, vector<T>& v) {     for (ll i = (0); i < (ll)(v.size()); i++) {       if (i) os <<    ;       os << v[i];     }     return os;   }   struct modint {     ll n;       public:     modint(const ll n = 0) : n((n % mod + mod) % mod) {}     static modint pow(modint a, int m) {       modint r = 1;       while (m > 0) {         if (m & 1) {           r *= a;         }         a = (a * a);         m /= 2;       }       return r;     }     modint& operator++() {       *this += 1;       return *this;     }     modint& operator--() {       *this -= 1;       return *this;     }     modint operator++(int) {       modint ret = *this;       *this += 1;       return ret;     }     modint operator--(int) {       modint ret = *this;       *this -= 1;       return ret;     }     modint operator~() const { return (this->pow(n, mod - 2)); }     friend bool operator==(const modint& lhs, const modint& rhs) {       return lhs.n == rhs.n;     }     friend bool operator<(const modint& lhs, const modint& rhs) {       return lhs.n < rhs.n;     }     friend bool operator>(const modint& lhs, const modint& rhs) {       return lhs.n > rhs.n;     }     friend modint& operator+=(modint& lhs, const modint& rhs) {       lhs.n += rhs.n;       if (lhs.n >= mod) lhs.n -= mod;       return lhs;     }     friend modint& operator-=(modint& lhs, const modint& rhs) {       lhs.n -= rhs.n;       if (lhs.n < 0) lhs.n += mod;       return lhs;     }     friend modint& operator*=(modint& lhs, const modint& rhs) {       lhs.n = (lhs.n * rhs.n) % mod;       return lhs;     }     friend modint& operator/=(modint& lhs, const modint& rhs) {       lhs.n = (lhs.n * (~rhs).n) % mod;       return lhs;     }     friend modint operator+(const modint& lhs, const modint& rhs) {       return modint(lhs.n + rhs.n);     }     friend modint operator-(const modint& lhs, const modint& rhs) {       return modint(lhs.n - rhs.n);     }     friend modint operator*(const modint& lhs, const modint& rhs) {       return modint(lhs.n * rhs.n);     }     friend modint operator/(const modint& lhs, const modint& rhs) {       return modint(lhs.n * (~rhs).n);     }   };   istream& operator>>(istream& is, modint m) {     is >> m.n;     return is;   }   ostream& operator<<(ostream& os, modint m) {     os << m.n;     return os;   }   long long extgcd(long long a, long long b, long long& x, long long& y) {     long long d = a;     if (b != 0) {       d = extgcd(b, a % b, y, x);       y -= (a / b) * x;     } else {       x = 1;       y = 0;     }     return d;   }   long long mod_inverse(long long a, long long m) {     long long x, y;     if (extgcd(a, m, x, y) == 1)       return (m + x % m) % m;     else       return -1;   }   vector<long long> fact(1010101 + 1, inf);   long long mod_fact(long long n, long long& e) {     if (fact[0] == inf) {       fact[0] = 1;       if (1010101 != 0) fact[1] = 1;       for (ll i = 2; i <= 1010101; ++i) {         fact[i] = (fact[i - 1] * i) % mod;       }     }     e = 0;     if (n == 0) return 1;     long long res = mod_fact(n / mod, e);     e += n / mod;     if ((n / mod) % 2 != 0) return (res * (mod - fact[n % mod])) % mod;     return (res * fact[n % mod]) % mod;   }   long long mod_comb(long long n, long long k) {     if (n < 0 || k < 0 || n < k) return 0;     long long e1, e2, e3;     long long a1 = mod_fact(n, e1), a2 = mod_fact(k, e2),               a3 = mod_fact(n - k, e3);     if (e1 > e2 + e3) return 0;     return (a1 * mod_inverse((a2 * a3) % mod, mod)) % mod;   }   using mi = modint;   mi mod_pow(mi a, ll n) {     mi ret = 1;     mi tmp = a;     while (n > 0) {       if (n % 2) ret *= tmp;       tmp = tmp * tmp;       n /= 2;     }     return ret;   }   ll gcd(ll a, ll b) {     if (b == 0) return a;     return gcd(b, a % b);   }   struct SuffixArray {     vector<int> SA;     const string s;     SuffixArray(const string& str) : s(str) {       SA.resize(s.size());       iota(begin(SA), end(SA), 0);       sort(begin(SA), end(SA),            [&](int a, int b) { return s[a] == s[b] ? a > b : s[a] < s[b]; });       vector<int> classes(s.size()), c(s.begin(), s.end()), cnt(s.size());       for (int len = 1; len < s.size(); len <<= 1) {         for (int i = 0; i < s.size(); i++) {           if (i > 0 && c[SA[i - 1]] == c[SA[i]] && SA[i - 1] + len < s.size() &&               c[SA[i - 1] + len / 2] == c[SA[i] + len / 2]) {             classes[SA[i]] = classes[SA[i - 1]];           } else {             classes[SA[i]] = i;           }         }         iota(begin(cnt), end(cnt), 0);         copy(begin(SA), end(SA), begin(c));         for (int i = 0; i < s.size(); i++) {           int s1 = c[i] - len;           if (s1 >= 0) SA[cnt[classes[s1]]++] = s1;         }         classes.swap(c);       }     }     int operator[](int k) const { return SA[k]; }     size_t size() const { return s.size(); }     bool lt_substr(const string& t, int si = 0, int ti = 0) {       int sn = (int)s.size(), tn = (int)t.size();       while (si < sn && ti < tn) {         if (s[si] < t[ti]) return true;         if (s[si] > t[ti]) return false;         ++si, ++ti;       }       return si >= sn && ti < tn;     }     int lower_bound(const string& t) {       int low = -1, high = (int)SA.size();       while (high - low > 1) {         int mid = (low + high) / 2;         if (lt_substr(t, SA[mid]))           low = mid;         else           high = mid;       }       return high;     }     pair<int, int> lower_upper_bound(string& t) {       int idx = lower_bound(t);       int low = idx - 1, high = (int)SA.size();       t.back()++;       while (high - low > 1) {         int mid = (low + high) / 2;         if (lt_substr(t, SA[mid]))           low = mid;         else           high = mid;       }       t.back()--;       return {idx, high};     }     void output() {       for (int i = 0; i < size(); i++) {         cout << i <<  :   << s.substr(SA[i]) << endl;       }     }   };   struct LongestCommonPrefixArray {     const SuffixArray& SA;     vector<int> LCP, rank;     LongestCommonPrefixArray(const SuffixArray& SA) : SA(SA), LCP(SA.size()) {       rank.resize(SA.size());       for (int i = 0; i < SA.size(); i++) {         rank[SA[i]] = i;       }       for (int i = 0, h = 0; i < SA.size(); i++) {         if (rank[i] + 1 < SA.size()) {           for (int j = SA[rank[i] + 1];                max(i, j) + h < SA.size() && SA.s[i + h] == SA.s[j + h]; ++h)             ;           LCP[rank[i] + 1] = h;           if (h > 0) --h;         }       }     }     int operator[](int k) const { return LCP[k]; }     size_t size() const { return LCP.size(); }     void output() {       for (int i = 0; i < size(); i++) {         cout << i <<  :   << LCP[i] <<     << SA.s.substr(SA[i]) << endl;       }     }   };   int main() {     cin.tie(0);     ios::sync_with_stdio(false);     string x;     cin >> x;     int n = (int)x.size();     SuffixArray sa(x);     LongestCommonPrefixArray lcpa(sa);     vector<vector<int>> pd(n, vector<int>(n));     vector<int> rev(n);     for (ll i = (0); i < (ll)(n); i++) rev[sa[i]] = i;     for (ll i = (0); i < (ll)(n - 1); i++) {       int a = sa[i];       int mn = lcpa[i + 1];       for (int j = i + 1; j < n; j++) {         mn = min(mn, lcpa[j]);         int b = sa[j];         pd[a][b] = pd[b][a] = mn;       }     }     vector<vector<pair<int, int>>> dp(         n, vector<pair<int, int>>(n, make_pair(0, inf)));     vector<vector<pair<int, int>>> acm(         n, vector<pair<int, int>>(n, make_pair(0, inf)));     for (ll i = (0); i < (ll)(n); i++) {       for (ll j = (0); j < (ll)(n); j++) {         if (i + 1 < j + 1) continue;         if (x[i - j] ==  0 ) continue;         if (i + 1 == j + 1) {           dp[i][j].first = 1;           dp[i][j].second = 1;         } else {           if (j) {             dp[i][j].first = acm[i - j - 1][j - 1].first;             dp[i][j].second = acm[i - j - 1][j - 1].second + 1;           }           if (i - j - 1 - j < 0) continue;           if (pd[i - j - 1 - j][i - j] >= j + 1) {             dp[i][j].first += dp[i - j - 1][j].first;             dp[i][j].first %= mod;             dp[i][j].second = min(dp[i][j].second, dp[i - j - 1][j].second + 1);           } else if (rev[i - j - 1 - j] < rev[i - j]) {             dp[i][j].first += dp[i - j - 1][j].first;             dp[i][j].first %= mod;             dp[i][j].second = min(dp[i][j].second, dp[i - j - 1][j].second + 1);           }         }       }       acm[i][0] = dp[i][0];       for (ll j = (1); j < (ll)(n); j++) {         acm[i][j].first = acm[i][j - 1].first + dp[i][j].first;         acm[i][j].first %= mod;         acm[i][j].second = min(acm[i][j - 1].second, dp[i][j].second);       }     }     mi ans1 = acm[n - 1][n - 1].first;     ll ans2 = inf * inf;     ll tmp = 0;     bool good = false;     for (int i = n - 1; i >= 0; i--) {       if (x[i] ==  1 ) tmp += mod_pow(2, n - 1 - i).n;       if (good && n - 1 - i > 8) break;       if (n - 1 - i > 8) tmp %= mod;       if (acm[n - 1][n - 1 - i].second != inf) {         good = true;         if (n - 1 - i > 8) {           ans2 = tmp + acm[n - 1][n - 1 - i].second;           break;         } else {           ans2 = min(ans2, tmp + acm[n - 1][n - 1 - i].second);         }       }     }     ans2 %= mod;     cout << ans1 << endl;     cout << ans2 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 3e5 + 100;   vector<int> edge[N];   vector<long long> w[N];   int n, q, top[N], dfn[N], hson[N], siz[N];   int fa[N];   long long val[N], f[N], g[N];   long long a[N], dv[N];   long long dep[N], faw[N];   void dfs(int x) {     f[x] = 0;     siz[x] = 1;     dv[x] = dv[fa[x]] + a[x];     for (int i = 0; i <= (int)edge[x].size() - 1; ++i) {       int y = edge[x][i];       if (y == fa[x]) continue;       fa[y] = x;       dep[y] = dep[x] + w[x][i];       faw[y] = w[x][i];       dfs(y);       siz[x] += siz[y];       if (siz[y] > siz[hson[x]]) hson[x] = y;       f[x] = max(f[x], f[x] + f[y] - w[x][i] * 2 + a[y]);     }     for (int i = 0; i <= (int)edge[x].size() - 1; ++i) {       int y = edge[x][i];       if (y == fa[x]) continue;       if (f[y] - w[x][i] * 2 + a[y] > 0)         val[y] = f[x] - f[y] + w[x][i] * 2 - a[y];       else         val[y] = f[x];     }   }   int tot, an[N];   void dfs2(int x, int k) {     top[x] = k;     dfn[x] = ++tot;     an[tot] = x;     if (!hson[x]) return;     dfs2(hson[x], k);     for (int i = 0; i <= (int)edge[x].size() - 1; ++i) {       int y = edge[x][i];       if (y == fa[x] || y == hson[x]) continue;       dfs2(y, y);     }   }   void dfs3(int x) {     for (int i = 0; i <= (int)edge[x].size() - 1; ++i) {       int y = edge[x][i];       if (y == fa[x]) continue;       g[y] = g[x] + a[x] - 2 * w[x][i];       if (f[y] - w[x][i] * 2 + a[y] < 0)         g[y] += f[x];       else         g[y] += f[x] - f[y] + w[x][i] * 2 - a[y];       if (g[y] < 0) g[y] = 0;       dfs3(y);     }   }   inline int lca(int x, int y) {     while (top[x] != top[y]) {       if (dep[top[x]] < dep[top[y]]) swap(x, y);       x = fa[top[x]];     }     return (dep[x] < dep[y]) ? x : y;   }   long long st[N];   void init() {     st[0] = 0;     for (int i = 1; i <= n; ++i) st[i] = st[i - 1] + val[an[i]];   }   inline long long rmq(int l, int r) { return st[r] - st[l - 1]; }   int son;   long long query(int x, int y) {     long long res = 0;     while (top[x] != top[y]) {       res += rmq(dfn[top[x]], dfn[x]);       if (fa[top[x]] == y) res -= val[top[x]], son = top[x];       x = fa[top[x]];     }     if (!son) son = an[dfn[y] + 1];     if (dfn[y] + 2 <= dfn[x]) res += rmq(dfn[y] + 2, dfn[x]);     return res;   }   int main() {     scanf( %d%d , &n, &q);     for (int i = 1; i <= n; ++i) scanf( %lld , a + i);     for (int i = 1; i <= n - 1; ++i) {       int u, v;       long long z;       scanf( %d%d%lld , &u, &v, &z);       edge[u].push_back(v);       edge[v].push_back(u);       w[u].push_back(z);       w[v].push_back(z);     }     fa[1] = dep[1] = 0;     dfs(1);     dfs2(1, 1);     dfs3(1);     init();     for (int i = 1; i <= q; ++i) {       int x, y;       scanf( %d%d , &x, &y);       int w = lca(x, y);       long long res = 0;       son = 0;       if (w == x) {         if (w == y)           res = f[w] + g[w];         else {           res = query(y, w);           res += val[son] + g[w] + f[y];         }       } else if (w == y) {         res = query(x, w);         res += val[son] + g[w] + f[x];       } else {         res = query(x, w) + g[w];         if (f[son] - 2 * faw[son] + a[son] > 0)           res -= f[son] - 2 * faw[son] + a[son];         son = 0;         res += query(y, w);         res += val[son];         res += f[x] + f[y];       }       res += dv[x] + dv[y] - dv[w] - dv[fa[w]] - dep[x] - dep[y] + dep[w] * 2;       printf( %lld n , res);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, ans;   bool pr[100003];   bool mark[100003];   vector<int> v;   vector<int> e;   vector<pair<int, int> > res;   int main() {     scanf( %d , &n);     for (int i = 2; i <= n; i++)       if (!pr[i]) {         v.push_back(i);         for (int j = 2 * i; j <= n; j += i) pr[j] = true;       }     int sz = v.size();     for (int i = 1; i < sz && v[i] <= n / 2; i++) {       vector<int> tmp;       for (int j = v[i]; j <= n; j += v[i])         if (!mark[j]) tmp.push_back(j);       int cnt = tmp.size();       if (cnt % 2 == 0) {         for (int j = 0; j < cnt; j += 2) {           res.push_back(pair<int, int>(tmp[j], tmp[j + 1]));           mark[tmp[j]] = mark[tmp[j + 1]] = true;         }       } else if (cnt >= 3) {         res.push_back(pair<int, int>(tmp[0], tmp[2]));         mark[tmp[0]] = mark[tmp[2]] = true;         for (int j = 3; j < cnt; j += 2) {           res.push_back(pair<int, int>(tmp[j], tmp[j + 1]));           mark[tmp[j]] = mark[tmp[j + 1]] = true;         }       }     }     for (int i = 2; i <= n; i += 2)       if (!mark[i]) e.push_back(i);     int cnt = e.size();     for (int i = 0; i + 1 < cnt; i += 2)       res.push_back(pair<int, int>(e[i], e[i + 1]));     ans = res.size();     printf( %d n , ans);     for (int i = 0; i < ans; i++) printf( %d %d n , res[i].first, res[i].second);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     int n, i, j;     cin >> n;     int arr[n], locked[n];     for (i = 0; i < n; i++) cin >> arr[i];     for (i = 0; i < n; i++) cin >> locked[i];     vector<int> unlocked;     for (i = 0; i < n; i++)       if (!locked[i]) unlocked.push_back(arr[i]);     sort(unlocked.begin(), unlocked.end());     j = unlocked.size() - 1;     for (i = 0; i < n; i++) {       if (!locked[i]) arr[i] = unlocked[j--];     }     for (i = 0; i < n; i++) cout << arr[i] <<    ;     cout << endl;   }   int main() {     int t;     cin >> t;     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, i;     cin >> n >> m;     int a[n], b[m];     for (i = 0; i < n; i++) cin >> a[i];     for (i = 0; i < m; i++) cin >> b[i];     sort(b, b + m);     for (i = 0; i < n; i++)       if (binary_search(b, b + m, a[i])) cout << a[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   long long power(long long base, long long expo, long long md = mod) {     if (base == 0) return 0;     long long res = 1;     base %= md;     while (expo > 0) {       if (expo & 1) {         res = res * base;         res %= md;       }       expo >>= 1;       base = (base * base) % md;     }     return res;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long tt = 1;     for (long long tc = 1; tc <= tt; tc++) {       long long x, d;       cin >> x >> d;       bitset<69> bit(x);       vector<long long> v;       for (long long i = 0; i < 69; i++) {         if (bit[i]) {           v.push_back(i);         }       }       vector<long long> sol;       long long ins = 1, cnt = 0;       for (auto &xo : v) {         long long times = xo;         cnt++;         while (times--) {           sol.push_back(ins);         }         ins += d;       }       for (long long i = 0; i < cnt; i++) {         sol.push_back(ins);         ins += d;       }       if ((long long)sol.size() > (10000))         cout <<  -1 n ;       else {         cout << sol.size() <<   n ;         for (auto &xo : sol) cout << xo <<    ;         cout <<   n ;       }     }     return 0;   }


#include <iostream>   using namespace std;   int main()   {       long long t;       cin >> t;       while(t--)       {           long long n, s = 0, mx = 0;           cin >> n;           long long a[n + 1];           for(long long i = 1; i <= n; ++i){               cin >> a[i];               s += a[i];               mx = max(mx, a[i]);           }           cout << max((n - 1) * mx, (s + n - 2) / (n - 1) *(n - 1)) - s <<   n ;       }   }


#include <bits/stdc++.h>   using namespace std;   queue<pair<long long, long long> > q;   int32_t trace[5005][5005];   int32_t n, m, t, dp[5005][5005];   vector<pair<long long, long long> > adj[5005];   void solve() {     dp[1][1] = -t - 1;     q.emplace(1, 1);     while (q.size()) {       long long node = q.front().first, cnt = q.front().second;       q.pop();       for (auto i : adj[node]) {         if (dp[i.first][cnt + 1] > dp[node][cnt] + i.second) {           dp[i.first][cnt + 1] = dp[node][cnt] + i.second;           q.emplace(i.first, cnt + 1);           trace[i.first][cnt + 1] = node;         }       }     }   }   signed main() {     cin >> n >> m >> t;     for (long long i = 1; i <= m; i++) {       long long u, v, val;       cin >> u >> v >> val;       adj[u].emplace_back(v, val);     }     solve();     stack<long long> ans;     for (long long i = n; i >= 1; i--) {       if (dp[n][i] < 0) {         cout << i << endl;         long long tr = n;         while (i > 0) {           ans.push(tr);           tr = trace[tr][i];           i--;         }       }     }     while (ans.size()) {       cout << ans.top() <<    ;       ans.pop();     }   }


#include <bits/stdc++.h>   using namespace std;   int n, flag;   int a[100005], b[100005], t[100005];   int main() {     cin >> n;     for (int i = 1; i <= n - 1; i++) cin >> a[i];     for (int i = 1; i <= n - 1; i++) cin >> b[i];     memset(t, -1, sizeof(t));     for (int i = 0; i <= 3; i++) {       t[1] = i;       int num = 0;       for (int j = 2; j <= n; j++) {         for (int k = 0; k <= 3; k++)           if (((k | t[j - 1]) == a[j - 1]) && ((k & t[j - 1]) == b[j - 1]))             t[j] = k;       }       for (int i = 1; i <= n; i++)         if (t[i] != -1) num++;       if (num == n) break;     }     for (int i = 1; i <= n; i++)       if (t[i] == -1) {         printf( NO );         return 0;       }     printf( YES n );     for (int i = 1; i <= n; i++) printf( %d  , t[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long sz = 2e6 + 5, mod = 1e9 + 9;   long long t, n, m, k, q;   const long long inf = 3e18;   long long dx[] = {1, 0, -1, 0};   long long dy[] = {0, 1, 0, -1};   bool vis[sz];   vector<vector<long long> > gr(sz);   vector<long long> cnt(sz, 0);   void DFS(long long s) {     vis[s] = 1;     for (auto i : gr[s]) {       if (!vis[i]) DFS(i);     }     return;   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     t = 1;     while (t--) {       cin >> n >> m;       for (long long i = 0; i < m; i++) {         long long a, b;         cin >> a >> b;         if (a == b) {           cnt[a]++;           continue;         }         gr[a].push_back(b);         gr[b].push_back(a);       }       long long cnt1 = 0;       for (long long i = 1; i <= n; i++) {         cnt1 += cnt[i];       }       long long c = 0;       for (long long i = 1; i <= n; i++) {         if (!vis[i] && gr[i].size())           DFS(i), c++;         else if (!vis[i]) {           if (cnt[i]) c++;         }       }       if (c > 1) {         cout << 0 <<   n ;         return 0;       }       long long ans = 0;       ans += cnt1 * (cnt1 - 1) / 2;       ans += cnt1 * (m - cnt1);       for (long long i = 1; i <= n; i++) {         ans += gr[i].size() * (gr[i].size() - 1) / 2;       }       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool solve(long long n, long long k) {     int r = n % k;     long long turn = n / k;     if (turn % 2 == 1) {       return false;     }     return true;   }   int main() {     long long n, k;     cin >> n >> k;     if (!solve(n, k))       cout <<  YES  << endl;     else       cout <<  NO  << endl;     return 0;   }


#include <bits/stdc++.h>   int main() {     int n;     scanf( %d , &n);     int a[n];     for (int i = 0; i < n; ++i) {       scanf( %d , &a[i]);     }     int temp1, temp2, flag = 0;     for (int i = 0; i < n; ++i) {       temp1 = a[i] - 1;       temp2 = a[temp1] - 1;       if (a[temp2] - 1 == i) {         flag = 1;         printf( YES n );         break;       }     }     if (flag == 0) {       printf( NO n );     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize  -O3    using namespace std;   const int MAXN = 2100;   int n, m;   long long a[MAXN];   long long aa[MAXN];   long long b[MAXN];   long long bb[MAXN];   long long x;   int main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     cin >> n >> m;     for (int i = 0; i < n; ++i) cin >> a[i];     for (int j = 0; j < m; ++j) cin >> b[j];     cin >> x;     for (int i = 1; i <= n; ++i) aa[i] = x + 1;     for (int i = 1; i <= m; ++i) bb[i] = x + 1;     for (int i = 0; i < n; ++i) {       long long sum = 0;       for (int j = i; j < n; ++j) {         sum += a[j];         aa[j - i + 1] = min(aa[j - i + 1], sum);       }     }     for (int i = 0; i < m; ++i) {       long long sum = 0;       for (int j = i; j < m; ++j) {         sum += b[j];         bb[j - i + 1] = min(bb[j - i + 1], sum);       }     }     int ans = 0;     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= m; ++j) {         if (aa[i] * bb[j] <= x) ans = max(ans, i * j);       }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:600000000 )   using namespace std;   template <class T>   T sqr(T x) {     return x * x;   }   double const pi = 3.1415926535897932384626433832795;   int const inf = (int)1e9;   long long const inf64 = (long long)4e18;   const string name =  a ;   const int NMAX = 101010;   int n, minyl, maxyl, yy[NMAX], used[NMAX];   double x[NMAX], y[NMAX], zn[NMAX];   pair<double, double> q[NMAX];   pair<double, int> qq[NMAX];   int may(double r) {     memset(used, 0, sizeof(used));     double _max = -1e10, _min = 1e10;     int yl = 0;     minyl = 0, maxyl = n - 1;     for (int i = 0; i < (int)n; i++) {       while (yl < n && x[yl] - x[i] <= 2 * r) {         used[yy[yl]] = 1;         while (maxyl >= 0 && used[maxyl]) maxyl--;         while (minyl < n && used[minyl]) minyl++;         yl++;       }       double tmp_max = _max;       if (maxyl >= 0) tmp_max = max(tmp_max, zn[maxyl]);       double tmp_min = _min;       if (minyl < n) tmp_min = min(tmp_min, zn[minyl]);       if (tmp_max - tmp_min <= 2 * r) return 1;       _max = max(_max, y[i]);       _min = min(_min, y[i]);     }     return 0;   }   int main() {     cin >> n;     for (int i = 0; i < (int)n; i++) {       int xx, yy;       scanf( %d%d , &xx, &yy);       q[i] = make_pair(xx + yy, xx - yy);     }     sort(q, q + n);     for (int i = 0; i < (int)n; i++) {       x[i] = q[i].first, y[i] = q[i].second;       qq[i] = make_pair(y[i], i);     }     sort(qq, qq + n);     for (int i = 0; i < (int)n; i++) zn[i] = qq[i].first, yy[qq[i].second] = i;     double l = 0, r = 1e10;     may(0);     for (int i = 0; i < (int)70; i++) {       double m = (l + r) / 2;       if (may(m))         r = m;       else         l = m;     }     printf( %.10lf n , l);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 5;   long long factor[maxn], cnt, n, k, num;   void process() {     int m = sqrt(n);     cnt = num = 0;     for (int i = 1; i <= m; i++) {       if (n % i == 0) {         factor[cnt++] = i;         if (n / i != i) factor[cnt++] = n / i;       }     }     sort(factor, factor + cnt);   }   void dfs(long long x, long long m) {     if (num >= 100000) return;     if (m == 0 || x == 1) {       cout << x <<    ;       num++;       return;     }     for (int i = 0; i < cnt && factor[i] <= x; i++) {       if (x % factor[i] == 0) {         dfs(factor[i], m - 1);         if (num >= 100000) return;       }     }   }   int main() {     cin >> n >> k;     process();     dfs(n, k);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxN = 200011;   const int limit = 1000000;   const int maxBit = 20;   long long n, X, Y, i, bts, max_conf;   long long a[maxN];   vector<pair<long long, long long> > divs, divs2, act;   vector<long long> to_check;   vector<long long> A, B;   long long data[1 << maxBit];   long long ans;   void give(long long x) {     cout << x;     exit(0);   }   long long gcd(long long x, long long y) {     if (x < y) swap(x, y);     while (y > 0) {       x %= y;       swap(x, y);     }     return x;   }   void fact(long long x) {     long long i, cnt, aux;     if (Y % X) give(0);     for (i = 2; i * i <= x && i <= limit; i++) {       if (x % i) continue;       cnt = 0;       while (x % i == 0) {         cnt++;         x /= i;       }       divs.push_back(make_pair(i, cnt));     }     if (x == 1) return;     aux = llround(sqrt(x));     if (aux * aux == x) {       divs.push_back(make_pair(aux, 2));       return;     }     to_check.push_back(X);     to_check.push_back(Y);     for (auto e : to_check) {       aux = gcd(e, x);       if (aux == 1 || aux == x) continue;       divs.push_back(make_pair(aux, 1));       divs.push_back(make_pair(x / aux, 1));       return;     }     divs.push_back(make_pair(x, 1));   }   void fact_smart(long long x, vector<pair<long long, long long> >& to) {     long long cnt, aux;     to.clear();     aux = x;     for (auto e : divs) {       cnt = 0;       while (aux % e.first == 0) {         cnt++;         aux /= e.first;       }       to.push_back(make_pair(e.first, cnt));     }   }   void add_elem(long long x) {     long long i, j, cnt, aux;     long long conf, pos = 0;     aux = x;     conf = pos = 0;     for (auto e : divs2) {       cnt = 0;       while (aux % e.first == 0) {         cnt++;         aux /= e.first;       }       if (cnt != e.second && e.second != divs[pos].second) conf |= 1 << pos;       pos++;     }     if (x % X == 0) A.push_back(conf);     aux = x;     conf = pos = 0;     for (auto e : divs) {       cnt = 0;       while (aux % e.first == 0) {         cnt++;         aux /= e.first;       }       if (cnt != e.second && e.second != divs2[pos].second) conf |= 1 << pos;       pos++;     }     if (Y % x == 0) B.push_back(conf);   }   void solve() {     long long i, j;     bts = divs.size();     max_conf = 1 << bts;     for (auto e : A) data[e]++;     for (i = 0; i < bts; i++)       for (j = 0; j < max_conf; j++)         if ((j >> i) & 1) data[j] += data[j ^ (1 << i)];     for (auto e : B) ans += data[(max_conf - 1) ^ e];     give(ans);   }   int main() {     cin >> n >> X >> Y;     for (i = 1; i <= n; i++) cin >> a[i], to_check.push_back(a[i]);     fact(Y);     fact_smart(X, divs2);     for (i = 1; i <= n; i++) add_elem(a[i]);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, maxi, ans;   int a[200100], g[1001000];   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       scanf( %d , a + i);       g[a[i]] = a[i];     }     sort(a + 1, a + 1 + n);     maxi = a[n];     for (int i = 1; i <= maxi; i++) {       if (g[i] != i) g[i] = g[i - 1];     }     ans = 0;     for (int i = 1; i <= n; i++) {       if (i > 1 && a[i - 1] == a[i]) continue;       for (int j = a[i] << 1; j <= maxi; j += a[i]) {         ans = max(ans, g[j - 1] % a[i]);       }       ans = max(ans, maxi % a[i]);     }     printf( %d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     int n, a;     while (cin >> s >> n) {       a = s.length();       if (a % n != 0)         cout <<  NO  << endl;       else {         int b, c = 0;         b = a / n;         for (int i = 0; i < a; i += b) {           for (int j = 0; j < b / 2; j++) {             if (s[i + j] != s[i + b - j - 1]) {               c = 1;               break;             }           }           if (c == 1) break;         }         if (c == 1)           cout <<  NO  << endl;         else           cout <<  YES  << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long ans, f[300005];   ;   vector<pair<int, int> > adj[300005];   int w[300005];   void dfs(int v, int fa) {     f[v] = w[v];     ans = max(ans, 1ll * w[v]);     for (auto i : adj[v]) {       if (i.first != fa) {         dfs(i.first, v);         ans = max(ans, f[v] + f[i.first] - i.second);         f[v] = max(f[v], w[v] + f[i.first] - i.second);       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int n, x, y, z;     cin >> n;     for (int i = 0; i < n; i++) cin >> w[i + 1];     for (int i = 0; i < n - 1; i++) {       cin >> x >> y >> z;       adj[x].push_back({y, z});       adj[y].push_back({x, z});     }     dfs(1, 0);     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     vector<int> v(7, 0);     for (int i = 0; i < s.size(); i++) {       if (s[i] ==  B )         v[0]++;       else if (s[i] ==  u )         v[1]++;       else if (s[i] ==  l )         v[2]++;       else if (s[i] ==  b )         v[3]++;       else if (s[i] ==  a )         v[4]++;       else if (s[i] ==  s )         v[5]++;       else if (s[i] ==  r )         v[6]++;     }     int min1, min2;     min1 = min(v[1], v[4]);     min1 /= 2;     min2 = *min_element(v.begin(), v.end());     if (min1 > min2)       cout << min2 << endl;     else       cout << min1 << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 200020;   const int MOD = 1000000000;   int add(int a, int b) { return a >= MOD - b ? a - MOD + b : a + b; }   int mul(int a, int b) {     return a ? (b < MOD / a ? a * b : (long long)a * b % MOD) : 0;   }   int sub(int a, int b) { return a < b ? a - b + MOD : a - b; }   template <int MATRIX_MAXN = 2>   struct Matrix {     int n;     int mat[MATRIX_MAXN][MATRIX_MAXN];     void initEyeMatrix() {       n = 2;       mat[0][0] = 1;       mat[0][1] = 0;       mat[1][0] = 0;       mat[1][1] = 1;     }     void initFibMatrix() {       n = 2;       mat[0][0] = 0;       mat[0][1] = 1;       mat[1][0] = 1;       mat[1][1] = 1;     }     Matrix operator*(const Matrix &rhs) const {       Matrix res;       res.n = n;       for (int i = 0; i < n; i++) {         for (int j = 0; j < n; j++) {           res.mat[i][j] = 0;           for (int k = 0; k < n; k++) {             res.mat[i][j] = add(res.mat[i][j], mul(mat[i][k], rhs.mat[k][j]));           }         }       }       return res;     }   };   int fibsum[MAXN], a[MAXN];   Matrix<> fibmat[MAXN];   void initFibsum() {     fibsum[0] = fibsum[1] = 1;     fibmat[0].initEyeMatrix();     Matrix<> fmat;     fmat.initFibMatrix();     for (int i = (2); i < (MAXN); i++)       fibsum[i] = add(fibsum[i - 1], fibsum[i - 2]);     for (int i = (1); i < (MAXN); i++) {       fibmat[i] = fibmat[i - 1] * fmat;       fibsum[i] = add(fibsum[i - 1], fibsum[i]);     }   }   int getFib(int n, int f0, int f1) {     return add(mul(f0, fibmat[n].mat[0][0]), mul(f1, fibmat[n].mat[1][0]));   }   struct Segment {     int f0, f1, delta, size;     Segment(int f0 = 0, int f1 = 0, int delta = 0, int size = 0)         : f0(f0), f1(f1), delta(delta), size(size) {}     int getF0() const { return add(f0, mul(delta, fibsum[size - 1])); }     int getF1() const { return add(f1, mul(delta, sub(fibsum[size], 1))); }     Segment operator+(const Segment &rhs) const {       return Segment(add(getF0(), getFib(size, rhs.getF0(), rhs.getF1())),                      add(getF1(), getFib(size + 1, rhs.getF0(), rhs.getF1())), 0,                      size + rhs.size);     }   };   template <int MAXN = 200020, int MAXNODE = MAXN << 2>   struct SegmentTree {     int n;     Segment seg[MAXNODE];     static int LEFT(int idx) { return idx << 1; }     static int RIGHT(int idx) { return (idx << 1) | 1; }     void _build(int idx, int lower, int upper) {       if (lower == upper) {         seg[idx] = Segment(a[lower], a[lower], 0, 1);         return;       }       int middle = (lower + upper) >> 1;       _build(LEFT(idx), lower, middle);       _build(RIGHT(idx), middle + 1, upper);       seg[idx] = seg[LEFT(idx)] + seg[RIGHT(idx)];     }     void init(int n) {       this->n = n;       _build(1, 0, n - 1);     }     void pushDown(int idx) {       seg[LEFT(idx)].delta = add(seg[LEFT(idx)].delta, seg[idx].delta);       seg[RIGHT(idx)].delta = add(seg[RIGHT(idx)].delta, seg[idx].delta);       seg[idx].delta = 0;     }     int l, r, x, v;     void _modify(int idx, int lower, int upper) {       if (l <= lower && upper <= r) {         seg[idx].delta = add(seg[idx].delta, v);         return;       }       pushDown(idx);       int middle = (lower + upper) >> 1;       if (r <= middle) {         _modify(LEFT(idx), lower, middle);       } else if (middle < l) {         _modify(RIGHT(idx), middle + 1, upper);       } else {         _modify(LEFT(idx), lower, middle);         _modify(RIGHT(idx), middle + 1, upper);       }       seg[idx] = seg[LEFT(idx)] + seg[RIGHT(idx)];     }     void modify(int l, int r, int v) {       this->l = l;       this->r = r;       this->v = v;       _modify(1, 0, n - 1);     }     void _assign(int idx, int lower, int upper) {       if (lower == upper) {         seg[idx] = Segment(v, v, 0, 1);         return;       }       pushDown(idx);       int middle = (lower + upper) >> 1;       if (x <= middle) {         _assign(LEFT(idx), lower, middle);       } else {         _assign(RIGHT(idx), middle + 1, upper);       }       seg[idx] = seg[LEFT(idx)] + seg[RIGHT(idx)];     }     void assign(int x, int v) {       this->x = x;       this->v = v;       _assign(1, 0, n - 1);     }     Segment _calc(int idx, int lower, int upper) {       if (l <= lower && upper <= r) return seg[idx];       pushDown(idx);       int middle = (lower + upper) >> 1;       Segment res;       if (r <= middle) {         res = _calc(LEFT(idx), lower, middle);       } else if (middle < l) {         res = _calc(RIGHT(idx), middle + 1, upper);       } else {         res = _calc(LEFT(idx), lower, middle) +               _calc(RIGHT(idx), middle + 1, upper);       }       seg[idx] = seg[LEFT(idx)] + seg[RIGHT(idx)];       return res;     }     Segment calc(int l, int r) {       this->l = l;       this->r = r;       return _calc(1, 0, n - 1);     }   };   int n, m;   SegmentTree<> smt;   int main() {     initFibsum();     scanf( %d%d , &n, &m);     for (int i = (0); i < (n); i++) scanf( %d , &a[i]);     smt.init(n);     for (int _ = (0); _ < (m); _++) {       int op;       scanf( %d , &op);       if (op == 1) {         int x, v;         scanf( %d%d , &x, &v);         smt.assign(x - 1, v);       } else if (op == 2) {         int l, r;         scanf( %d%d , &l, &r);         printf( %d n , smt.calc(l - 1, r - 1).getF0());       } else {         int l, r, d;         scanf( %d%d%d , &l, &r, &d);         smt.modify(l - 1, r - 1, d);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<long long> nclaws(2000001, 0);   void solve() {     int n;     cin >> n;     cout << ((nclaws[n] * 4) % 1000000007) << endl;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     nclaws[1] = 0;     nclaws[2] = 0;     nclaws[3] = 1;     nclaws[4] = 1;     for (int i = 5; i < 2000001; i++) {       nclaws[i] = nclaws[i - 1] + 2 * nclaws[i - 2];       if (i % 3 == 0) nclaws[i]++;       nclaws[i] = nclaws[i] % 1000000007;     }     int t = 1;     cin >> t;     while (t--) solve();   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100000, M = 10, pw[5] = {1, 10, 100, 1000, 10000};   const unsigned long long mod = 1ULL << 58, inv = 6723469279985657373ULL;   struct comp {     unsigned long long a[4];     comp(int X = 0) {       a[0] = X;       a[1] = a[2] = a[3] = 0;     }     unsigned long long &operator[](const int &p) { return a[p]; }     comp operator+(const comp &p) const {       comp res;       for (int i = 0; i < 4; ++i) res.a[i] = a[i] + p.a[i];       return res;     }     comp operator-(const comp &p) const {       comp res;       for (int i = 0; i < 4; ++i) res.a[i] = a[i] - p.a[i];       return res;     }     comp operator*(const unsigned long long &p) const {       comp res;       for (int i = 0; i < 4; ++i) res.a[i] = a[i] * p;       return res;     }     comp operator*(const comp &p) const {       comp res;       static unsigned long long tmp[7];       for (int i = 0; i < 7; ++i) tmp[i] = 0;       for (int i = 0; i < 4; ++i)         for (int j = 0; j < 4; ++j) tmp[i + j] += a[i] * p.a[j];       for (int i = 2; i >= 0; --i) {         for (int j = 0; j < 4; ++j) tmp[i + j] -= tmp[i + 4];         tmp[i + 4] = 0;       }       for (int i = 0; i < 4; ++i) res.a[i] = tmp[i];       return res;     }   };   comp Power(comp a, int k) {     comp res(1);     for (; k; k >>= 1, a = a * a)       if (k & 1) res = res * a;     return res;   }   comp wn[M + 9];   void Get_wn() {     wn[0][0] = wn[M][0] = 1;     wn[1][3] = -1;     for (int i = 1; i < M; ++i) wn[i] = wn[i - 1] * wn[1];   }   int gg = 0;   void DFT(comp *a, int t) {     static comp dft[M];     for (int d = 0; d < 5; ++d) {       for (int i = 0; i < N; ++i) {         if (i / pw[d] % M) continue;         for (int j = 0; j < M; ++j) dft[j] = 0;         for (int j = 0; j < M; ++j)           for (int k = 0; k < M; ++k)             dft[j] =                 dft[j] + a[i + k * pw[d]] * wn[t ? M - j * k % M : j * k % M];         for (int j = 0; j < M; ++j) a[i + j * pw[d]] = dft[j];       }     }     if (!t) return;     for (int i = 0; i < N; ++i) a[i] = a[i] * inv;   }   int n;   comp a[N + 9];   void into() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) {       int x;       scanf( %d , &x);       ++a[x][0];     }   }   void Get_ans() {     DFT(a, 0);     for (int i = 0; i < N; ++i) a[i] = Power(a[i], n);     DFT(a, 1);   }   void work() {     Get_wn();     Get_ans();   }   void outo() {     for (int i = 0; i < n; ++i) printf( %llu n , a[i][0] >> 5 & mod - 1);   }   int main() {     into();     work();     outo();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2000000 + 10;   int n, h, m, x, t, d, c;   vector<int> v;   int main() {     scanf( %d%d%d%d%d%d , &h, &m, &t, &d, &c, &n);     double need = (t + n - 1) / n * c;     if (m != 0 && h < 20) {       t += (60 - m) % 60 * d;       h = (h + 1) % 24;     }     if (h < 20) {       t += (60 * (20 - h)) * d;     }     double y = (t + n - 1) / n * (c * 0.8);     printf( %0.5f n , min(need, y));     return 0;   }


#include<bits/stdc++.h>   #define LL long long   #define ULL unsigned long long   #define P pair<int,int>   #define PI acos(-1.0)   #define ls o<<1   #define rs o<<1|1   using namespace std;        const int mod=1e9+7;   const int base=19260817;   const LL INF=1e18;   const int maxn=2e5+10;   const double eps=1e-8;   int add(int x,int y){ x+=y;return x>=mod?x-mod:x; }   int sub(int x,int y){ x-=y;return x<0?x+mod:x; }   int mul(int x,int y){ return 1LL*x*y%mod; }      typedef pair<LL,int> pli;   int n,m;   LL d[maxn<<2];   bool vis[maxn<<2];   vector<P> g[maxn<<2];      void dijkstra(int n,int s)   {       priority_queue<pli,vector<pli>,greater<pli>> q;       for(int i=1;i<=n;i++) d[i]=INF,vis[i]=0;       d[s]=0,q.push(pli{0,s});       while(!q.empty()){           pli x=q.top();q.pop();           int u=x.second;           if(vis[u]) continue;           vis[u]=1;           for(auto e:g[u]){               int v=e.first,w=e.second;               if(d[u]+w<d[v]){                   d[v]=d[u]+w;                   q.push(pli{d[v],v});               }           }       }   }      inline void addedge(int u,int v,int w,int p,int q)   {       g[u+p*n].push_back(P{v+q*n,w});       g[v+p*n].push_back(P{u+q*n,w});   }      int main()   {   #ifdef LOCAL       freopen( test.in , r ,stdin);   #endif       ios::sync_with_stdio(false);cin.tie(0);       cin>>n>>m;       for(int i=1;i<=m;i++){           int u,v,w;cin>>u>>v>>w;           addedge(u,v,w,0,0);           addedge(u,v,w,1,1);           addedge(u,v,w,2,2);           addedge(u,v,w,3,3);           addedge(u,v,0,0,1);           addedge(u,v,0,2,3);           addedge(u,v,2*w,0,2);           addedge(u,v,2*w,1,3);       }       dijkstra(n<<2,1);       for(auto e:g[1]){           int v=e.first,w=e.second;           if(v<=n) d[v+3*n]=min(d[v+3*n],1LL*w);       }       for(int i=2;i<=n;i++) cout<<d[i+3*n]<<   ;       return 0;      }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long a1, a2, a3, a4;     cin >> a1 >> a2 >> a3 >> a4;     long long total = 0;     long long minn = min(a1, a3);     minn = min(minn, a4);     total += 256 * minn;     a1 -= minn;     minn = min(a1, a2);     total += 32 * minn;     cout << total << endl;   }


#include <bits/stdc++.h>   using namespace std;   int ans[100009];   int cmp(int a, int b) { return a <= b; }   int main() {     int n;     while (scanf( %d , &n) != EOF) {       for (int i = 0; i < n; i++) scanf( %d , &ans[i]);       sort(ans, ans + n);       int vaule = 0;       for (int i = 0; i < n; i++) {         if (ans[i] > vaule) vaule++;       }       printf( %d n , vaule + 1);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 1000 * 1000 * 1000;   const long long inf64 = 1ll * inf * inf;   struct DSU {     int n;     vector<int> par, color, h;     DSU() { n = 0; }     DSU(int nn) {       n = nn;       par.resize(n + 1);       color.resize(n + 1);       h.resize(n + 1);       for (int i = 1; i <= n; i++) {         par[i] = i;         color[i] = h[i] = 0;       }     }     int find(int x) {       if (x == par[x])         return x;       else {         int t = find(par[x]);         color[x] ^= color[par[x]];         return par[x] = t;       }     }     int parity(int x) {       find(x);       return color[x];     }     int add_edge(int x, int y) {       int px = find(x);       int py = find(y);       if (px == py) {         if (parity(x) == parity(y))           return 2;         else           return 0;       }       if (h[px] < h[py]) {         swap(px, py);         swap(x, y);       }       color[py] ^= (parity(x) ^ parity(y) ^ 1);       if (h[py] == h[px]) h[px]++;       par[py] = px;       return 1;     }   };   int n, m, q;   struct edge {     int u, v, id, w;     static int EdgeCount;     edge() { u = v = id = w = 0; }     void read() {       scanf( %d %d %d , &u, &v, &w);       id = EdgeCount++;     }     void print() { printf( #%d {%d %d} [%d] n , id, u, v, w); }     bool operator<(const edge& b) const {       return make_tuple(w, u, v, id) < make_tuple(b.w, b.u, b.v, b.id);     }     bool operator>(const edge& b) const {       return make_tuple(w, u, v, id) > make_tuple(b.w, b.u, b.v, b.id);     }     bool operator==(const edge& b) const {       return make_tuple(w, u, v, id) == make_tuple(b.w, b.u, b.v, b.id);     }   };   int edge ::EdgeCount = 1;   int RESULT;   void upd(vector<edge>& l) {     vector<edge> res;     DSU dsu(n);     RESULT = -1;     for (auto _e : l) {       int type = dsu.add_edge(_e.u, _e.v);       if (type) res.push_back(_e);       if (type == 2) {         RESULT = _e.w;         break;       }     }     l = res;   }   vector<edge> merge(const vector<edge>& l, const vector<edge>& r) {     int left_size = (int)l.size();     int right_size = (int)r.size();     int left_cur = 0, right_cur = 0;     vector<edge> res;     while (left_cur < left_size && right_cur < right_size) {       if (l[left_cur] > r[right_cur])         res.push_back(l[left_cur++]);       else         res.push_back(r[right_cur++]);     }     while (left_cur < left_size) res.push_back(l[left_cur++]);     while (right_cur < right_size) res.push_back(r[right_cur++]);     upd(res);     return res;   }   vector<vector<edge> > st;   vector<edge> e;   void build(int v, int tl, int tr) {     if (tl == tr) {       st[v].push_back(e[tl]);     } else {       int tm = (tl + tr) / 2;       build(v << 1, tl, tm);       build(v << 1 | 1, tm + 1, tr);       st[v] = merge(st[v << 1], st[v << 1 | 1]);     }   }   vector<edge> get(int v, int tl, int tr, int l, int r) {     if (l <= tl && tr <= r)       return st[v];     else {       int tm = (tl + tr) / 2;       if (l <= tm) {         if (r > tm)           return merge(get(v << 1, tl, tm, l, r),                        get(v << 1 | 1, tm + 1, tr, l, r));         else           return get(v << 1, tl, tm, l, r);       } else         return get(v << 1 | 1, tm + 1, tr, l, r);     }   }   bool solve() {     scanf( %d %d %d , &n, &m, &q);     e.resize(m + 1);     for (int i = 1; i <= m; i++) e[i].read();     st.resize(4 * m);     build(1, 1, m);     for (int l, r; q > 0; q--) {       scanf( %d %d , &l, &r);       auto tmp = get(1, 1, m, l, r);       upd(tmp);       printf( %d n , RESULT);     }     return true;   }   int main() {     solve();     return 0;   }


#include <iostream>   #include <algorithm>   #include <cstring>   #include <string>   #include <queue>   typedef long long ll;   using namespace std;         int main()    {    // what is greedy?    int T;    cin >> T;    while (T--) {     int len, a, b;     cin >> len >> a >> b;     string s;     cin >> s;     if (b > 0)       cout << (a + b) * len << endl;     else {      // 尽量连续      char ch = s[0];      int arr[5] = { 0, 0, 0, 0, 0 };      for (int i = 0; i < len; i++) {       if (s[i] != ch) {        arr[ch -  0 ]++;        ch = s[i];       }      }      // cout << s[len - 1] -  0  << endl;      arr[s[len - 1] -  0 ]++;      // cout <<  arr[0] ==   << arr[0] << endl;      // cout <<  arr[1] ==   << arr[1] << endl;      int minEle = arr[0] < arr[1] ? arr[0] : arr[1];      cout << a * len + (minEle + 1) * b << endl;     }     // if (a <= 0 && b <= 0) {     //  // 尽量连续     //  char ch = s[0];     //  int arr[5] = { 0, 0, 0, 0, 0 };     //  for (int i = 0; i < len; i++) {     //   if (s[i] != ch) {     //    arr[ch -  0 ]++;     //    ch = s[i];     //   }     //  }     //  int minEle = arr[0] < arr[1] ? arr[0] : arr[1];     //  cout << a * len + (minEle + 1) * b << endl;     // } else if (a <= 0 && b > 0) {     //  // 一个一个弄     //  cout << (a + b) * len << endl;     // } else if (a >= 0 && b <= 0) {     //  // 尽量连续     //  char ch = s[0];     //  int arr[5] = { 0, 0, 0, 0, 0 };     //  for (int i = 0; i < len; i++) {     //   if (s[i] != ch) {     //    arr[ch -  0 ]++;     //    ch = s[i];     //   }     //  }     //  int minEle = arr[0] < arr[1] ? arr[0] : arr[1];     //  cout << a * len + (minEle + 1) * b << endl;     // } else if (a >= 0 && b > 0) {     //  // 一个一个弄     //  cout << (a + b) * len << endl;     // }    }       return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n;     cin >> n;     long long a[n + 1], b[n + 1];     for (long long i = 1; i <= n; i++) {       long long x;       cin >> x;       a[x] = i;     }     for (long long i = 1; i <= n; i++) {       long long x;       cin >> x;       b[x] = i;     }     map<long long, long long> m;     long long ans = 0;     for (long long i = 1; i <= n; i++) {       if (a[i] < b[i]) {         m[n + a[i] - b[i]]++;         ans = max(ans, m[n - b[i] + a[i]]);       } else {         m[a[i] - b[i]]++;         ans = max(ans, m[a[i] - b[i]]);       }     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   char gc() {     static char buf[100000], *p1 = buf, *p2 = buf;     return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)                ? EOF                : *p1++;   }   long long read() {     char ch = getchar();     long long x = 0;     int op = 1;     for (; !isdigit(ch); ch = getchar())       if (ch ==  - ) op = -1;     for (; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + ch -  0 ;     return x * op;   }   int n, k, a[55], ans;   char s[55];   int main() {     n = read(), k = read();     scanf( %s , s + 1);     for (int i = (1); i <= (n); i++) a[i] = s[i] -  a  + 1;     sort(&a[1], &a[n + 1]);     ans = 1000000001;     for (int i = (1); i <= (n); i++) {       int p = i, q, tmp = 0;       bool flag = 1;       for (int j = (1); j <= (k); j++) {         if (p > n) {           flag = 0;           break;         }         tmp += a[p];         q = p, p++;         while (p <= n && abs(a[p] - a[q]) <= 1) p++;       }       if (flag) ans = min(ans, tmp);     }     if (ans == 1000000001)       puts( -1 );     else       printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, dad[200000 + 1], u[200000 + 1], v[200000 + 1];   long long w[200000], pop[200000], initsum, S;   std::vector<int> adjl[200000 + 1];   int cnode(int node, int ed) { return node ^ u[ed] ^ v[ed]; }   void dfs(int u) {     int isleaf = 1;     if (u != 1) pop[dad[u]] = 0;     for (int ed : adjl[u])       if (ed != dad[u]) {         isleaf = 0;         int v = cnode(u, ed);         dad[v] = ed;         dfs(v);         initsum += w[ed] * pop[ed];         if (u != 1) pop[dad[u]] += pop[ed];       }     if (isleaf) pop[dad[u]] = 1;   }   struct good_cmp {     bool operator()(int l, int r) {       return pop[l] * ((w[l] + 1) / 2) < pop[r] * ((w[r] + 1) / 2);     }   };   void run() {     cin >> n >> S;     for (int i = 1; i <= n; ++i) adjl[i].clear();     for (int i = 1; i < n; ++i) {       cin >> u[i] >> v[i] >> w[i];       adjl[u[i]].emplace_back(i);       adjl[v[i]].emplace_back(i);     }     initsum = 0;     memset(dad + 1, 0, n * sizeof(int));     dad[1] = -1;     dfs(1);     std::priority_queue<int, std::vector<int>, good_cmp> pq;     for (int i = 1; i < n; ++i) pq.push(i);     long long ans = 0;     while (initsum > S) {       ++ans;       int top = pq.top();       pq.pop();       initsum -= pop[top] * ((w[top] + 1) / 2);       w[top] /= 2;       pq.push(top);     }     cout << ans <<   n ;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(nullptr);     int t;     cin >> t;     while (t--) run();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char str[50];   pair<int, pair<int, char*> > p[100001];   long long c[100005];   vector<int> ans;   map<int, int> mp;   int main() {     std::ios::sync_with_stdio(false);     long long n, m, x;     cin >> n >> m;     for (int i = 0; i < n; i++) {       cin >> c[i];     }     sort(c, c + n);     int j = 1;     while (m > 0 && j < c[0]) {       m = m - j;       if (m >= 0) ans.push_back(j);       j++;     }     c[n] = 1000000002;     if (m > 0) {       for (int i = 0; i < n; i++) {         j = c[i] + 1;         while (m > 0 && j < c[i + 1]) {           m = m - j;           if (m >= 0) ans.push_back(j);           j++;         }         if (m <= 0) break;       }     }     cout << ans.size() <<   n ;     for (int i = 0; i < ans.size(); i++) cout << ans[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1000000007;   const long long MOD = 1000000007;   const long long INF = 1LL << 60;   long long xn[101010];   int solve() {     long long a, b, c, d, e, f;     cin >> a >> b >> c >> d >> e >> f;     long long ans = 0;     for (long long i = 0; i <= d; i++) {       long long one = min(i, a);       long long two = min(d - i, min(b, c));       ans = max(ans, e * one + f * two);     }     cout << ans << endl;     return 0;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     solve();   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1E5 + 10;   string s[N];   map<string, vector<string>> E;   map<string, long long> cnt;   map<string, long long> len;   map<string, bool> vis;   vector<pair<string, vector<string>>> e;   string to_lower(string &s) {     int ret = 0;     for (auto &c : s) {       c = tolower(c);       if (c ==  r ) ret++;     }     cnt[s] = ret;     len[s] = s.size();     return s;   }   void dfs(string u) {     vis[u] = 1;     for (const auto &v : E[u]) {       if (vis[v]) continue;       if (cnt[v] > cnt[u]) {         len[v] = len[u];         cnt[v] = cnt[u];       } else if (cnt[u] == cnt[v] && len[v] > len[u]) {         len[v] = len[u];       }       dfs(v);     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n, m;     cin >> n;     for (int i = 0; i < n; ++i) {       cin >> s[i];       s[i] = to_lower(s[i]);     }     cin >> m;     string u, v;     for (int i = 0; i < m; ++i) {       cin >> u >> v;       E[to_lower(v)].emplace_back(to_lower(u));     }     for (const auto &i : E) {       e.emplace_back(i);       vis[i.first] = 0;     }     sort(e.begin(), e.end(),          [](const pair<string, vector<string>> &x,             const pair<string, vector<string>> &y) -> int {            if (cnt[x.first] == cnt[y.first])              return x.first.size() < y.first.size();            return cnt[x.first] < cnt[y.first];          });     pair<long long, long long> ret = make_pair(0, 0);     for (auto i : e) {       if (vis[i.first] == 0) {         vis[i.first] = 1;         dfs(i.first);       }     }     for (auto i : s) {       ret.first += cnt[i];       ret.second += len[i];     }     cout << ret.first <<     << ret.second << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[100100];   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     int n, k;     cin >> n >> k;     for (int i = 0; i < n; i++) cin >> a[i];     const long long max_pow = 1e9 * 1e5;     vector<long long> powers = {1};     if (abs(k) > 1)       while (abs(powers.back() * k) <= max_pow)         powers.push_back(powers.back() * k);     else if (k == -1)       powers.push_back(-1);     long long ans = 0;     long long prefix_sum = 0;     map<long long, long long> cnt_sums;     for (int i = 0; i < n; i++) {       cnt_sums[prefix_sum]++;       prefix_sum += a[i];       for (auto pow : powers)         if (cnt_sums.count(prefix_sum - pow) > 0)           ans += cnt_sums[prefix_sum - pow];     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   int a[100009];   int n;   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %d , &a[i]);     long long res = 0;     for (int i = 0; i < n;) {       int j = i + 1;       while (j < n && a[j] == a[i]) j++;       long long sz = j - i;       res += sz * (sz + 1) / 2;       i = j;     }     cout << res << endl;   }


#include <bits/stdc++.h>   using namespace std;   template <typename A, typename B>   string to_string(pair<A, B> p);   string to_string(const string&);   string to_string(const char* s);   string to_string(bool b);   template <typename A>   string to_string(A v);   template <typename A, typename B>   string to_string(pair<A, B> p);   void debug_out();   template <typename Head, typename... Tail>   void debug_out(Head H, Tail... T);   vector<string> vec_splitter(string s);   void debug_var(vector<string> __attribute__((unused)) args,                  __attribute__((unused)) long long idx,                  __attribute__((unused)) long long LINE_NUM) {     cerr << endl;   }   template <typename Head, typename... Tail>   void debug_var(vector<string>, long long, long long, Head, Tail...);   const long long mod = 1e9 + 7;   const long long N = 1e6 + 5;   void solve() {     long long n, p;     cin >> n >> p;     string s;     vector<long long> a(n);     for (long long i = 0; i < n; ++i) {       cin >> s;       if (s.back() ==  f ) {         a[i] = 1;       }     }     long long ans = p / 2, cur = 1;     for (long long i = n - 2; i >= 0; --i) {       if (a[i]) {         ans += p * cur;         cur *= 2;       } else {         ans += p * cur + p / 2;         cur *= 2;         ++cur;       }     }     cout << ans <<   n ;   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     solve();     return 0;   }   string to_string(const string& s) { return     + s +    ; }   string to_string(const char* s) { return to_string((string)s); }   string to_string(bool b) { return (b ?  T  :  F ); }   template <typename A>   string to_string(A v) {     bool first = true;     string res =  { ;     for (const auto& x : v) {       if (!first) {         res +=  ,  ;       }       first = false;       res += to_string(x);     }     res +=  } ;     return res;   }   template <typename Head, typename... Tail>   void debug_var(vector<string> args, long long idx, long long LINE_NUM, Head H,                  Tail... T) {     if (idx > 0)       cerr <<  ,  ;     else       cerr <<  Line(  << LINE_NUM <<  ):  ;     stringstream ss;     ss << H;     cerr << args[idx] <<   =   << ss.str();     debug_var(args, idx + 1, LINE_NUM, T...);   }   template <typename A, typename B>   string to_string(pair<A, B> p) {     return  (  + to_string(p.first) +  ,   + to_string(p.second) +  ) ;   }   void debug_out() { cerr << endl; }   template <typename Head, typename... Tail>   void debug_out(Head H, Tail... T) {     cerr <<     << to_string(H);     debug_out(T...);   }   vector<string> vec_splitter(string s) {     s +=  , ;     vector<string> res;     while (!s.empty()) {       res.push_back(s.substr(0, s.find( , )));       s = s.substr(s.find( , ) + 1);     }     return res;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     double a, d;     int n;     while (scanf( %lf%lf%d , &a, &d, &n) != EOF) {       double sum = 0;       for (int i = 1; i <= n; i++) {         sum = (sum + d);         sum -= (int)(sum / (a * 4)) * (a * 4);         double x, y;         int dir = ((int)(sum / a)) % 4;         if (dir == 0) {           x = sum - ((int)(sum / a)) * a;           y = 0;         } else if (dir == 1) {           x = a;           y = sum - ((int)(sum / a)) * a;         } else if (dir == 2) {           x = a - sum + ((int)(sum / a)) * a;           y = a;         } else if (dir == 3) {           x = 0;           y = a - sum + ((int)(sum / a)) * a;         }         printf( %.10lf %.10lf n , x, y);       }     }   }


#include <bits/stdc++.h>   using namespace std;   void __print(int x) { cerr << x; }   void __print(long x) { cerr << x; }   void __print(long long x) { cerr << x; }   void __print(unsigned x) { cerr << x; }   void __print(unsigned long x) { cerr << x; }   void __print(unsigned long long x) { cerr << x; }   void __print(float x) { cerr << x; }   void __print(double x) { cerr << x; }   void __print(long double x) { cerr << x; }   void __print(const char *x) { cerr <<     << x <<    ; }   void __print(const string &x) { cerr <<     << x <<    ; }   void __print(bool x) { cerr << (x ?  true  :  false ); }   template <typename T, typename V>   void __print(const pair<T, V> &x) {     cerr <<  { ;     __print(x.first);     cerr <<  , ;     __print(x.second);     cerr <<  } ;   }   template <typename T>   void __print(const T &x) {     int f = 0;     cerr <<  { ;     for (auto &i : x) cerr << (f++ ?  ,  :   ), __print(i);     cerr <<  } ;   }   void _print() { cerr << endl; }   template <typename T, typename... V>   void _print(T t, V... v) {     __print(t);     if (sizeof...(v)) cerr <<  ,  ;     _print(v...);   }   void run_case() {     long long lim = 1, n, i, j, k, cnt = 0, sum = 0;     cin >> n;     vector<long long int> a(n);     for (i = 0; i < n; i++) cin >> a[i], lim *= 3;     for (i = 1; i < lim; i++) {       k = i;       sum = 0;       for (j = 0; j < n; j++) {         cnt = k % 3;         if (cnt == 1) sum += a[j];         if (cnt == 2) sum -= a[j];         k /= 3;       }       if (sum == 0) {         cout <<  YES  << endl;         return;       }     }     cout <<  NO  << endl;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int tc;     cin >> tc;     while (tc--) {       run_case();     }     return 0;   }


/*   anshu shandilya   */   /*   2300 codechef rating before 31 December 2020   */   /*   2100 codeforces rating before 31 December 2020   */               #include <bits/stdc++.h>   using namespace std;      typedef long double LD;   typedef long long ll;   #define int ll   #define itn int   #define pb push_back   #define mp make_pair   #define REP(i,n) for (int i = 0; i < n; i++)   #define FOR(i,a,b) for (int i = a; i < b; i++)   #define REPD(i,n) for (int i = n-1; i >= 0; i--)   #define FORD(i,a,b) for (int i = a; i >= b; i--)   #define remax(a,b) a = max(a,b)   #define remin(a,b) a = min(a,b)   #define all(v) v.begin(),v.end()   #define rev(v) v.begin(),v.end(),greater<int>()   typedef map<int,int> mii;   typedef vector<int> vi;   typedef vector<ll> vl;   typedef vector<vi> vvi;   typedef pair<int,int> pii;   typedef vector<pii> vpii;   #define ff first   #define ss second   #define pq(type) priority_queue<type>   #define PQD(type) priority_queue<type,vector<type>,greater<type> >   #define wt(t) while(t --)   #define SZ(x) ((int)(x).size())   #define runtime() ((double)clock() / CLOCKS_PER_SEC)   #define inrange(i,a,b) ((i>=min(a,b)) && (i<=max(a,b)))   #define FAST_IO ios_base::sync_with_stdio(false);cin.tie(NULL);   const int MAXN = 1000005;   const int SQRTN = 1003;   const int LOGN = 22;   const double PI=acos(-1);      #ifdef int   const int INF=1e16;   #else   const int INF=1e9;   #endif      const int MOD = 1000000007;   const int FMOD = 998244353;   const double eps = 1e-9;      /**************************  finding a number is prime or not and smallest prime factor of any number  *******************************/   bool primes[100001];   int spf[100001];      void sieve()   {     primes[0]=primes[1]=false;     for(int i=1;i<=100000;i++)     {       spf[i]=i;       primes[i]=true;     }     spf[2]=2;     for(int i=4;i<=100000;i+=2)     {       spf[i]=2;       primes[i]=false;     }     for(int i=3;i*i<=100000;i+=2)     {       if(spf[i]==i)        {           for(int j=i*i;j<=100000;j+=i)           {             if(spf[j]==j)              spf[j]=i;             primes[j]=false;        }       }     }     return ;   }      /******************************************** code ends *******************************************************************/         /*********************************************  modulo exponentation *****************************************************/   int power(int n, int m,int p)   {     int res=1;     n=n%MOD;     while(m>0)     {       if(m&1)       {         res=((res)%p*(n)%p)%p;         m--;      }       n=((n)%p*(n)%p)%p;       m>>=1;     }     return res;   }      /************************************************  code ends *************************************************************/                              /********************************* NcR MOD P in O(1) for queires type probs ******************************************/   int N=10000;   int factorialNumInverse [100001];   int naturalNumInverse[100001];   int fact[100001];      void InverseofNumber(ll p)   {       naturalNumInverse[0] = naturalNumInverse[1] = 1;       for (int i = 2; i <= N; i++)           naturalNumInverse[i] = naturalNumInverse[p % i] * (p - p / i) % p;   }   void InverseofFactorial(ll p)   {       factorialNumInverse[0] = factorialNumInverse[1] = 1;          for (int i = 2; i <= N; i++)           factorialNumInverse[i] = (naturalNumInverse[i] * factorialNumInverse[i - 1]) % p;   }      void factorial(ll p)   {       fact[0] = 1;          for (int i = 1; i <= N; i++) {           fact[i] = (fact[i - 1] * i) % p;       }   }      int Binomial(int N, int R, int p)   {       int ans = ((fact[N] * factorialNumInverse[R])                 % p * factorialNumInverse[N - R])                % p;       return ans;   }      /********************************** CODE ENDS ******************************************************************************/         /*********************************** NcR MOD p using FERMAT S THEOREM IN O(LOGY) ******************************************/         int modInverse(int n,int p)   {       return power(n, p - 2, p);   }      int nCrModPFermat(int n,int r, int p)   {          if (n < r)           return 0;       if (r == 0)           return 1;          int fac[n + 1];       fac[0] = 1;       for (int i = 1; i <= n; i++)           fac[i] = (fac[i - 1] * i) % p;          return (fac[n] * modInverse(fac[r], p) % p               * modInverse(fac[n - r], p) % p)              % p;   }         /**************************************** CODE ENDS ***********************************************************************/                  void solvethetestcase();      signed main()   {       FAST_IO       //sieve();       int t = 1;       cin >> t;       FOR(testcase,1,t+1){          // printf( Case #%lld:  ,testcase);           solvethetestcase();       }      }      int n,m,a,b,c,x,zero,p,t1,t2,t,q,cnt;                     /*********************************************  REAL CODE STARTS **********************************************************/   void solvethetestcase(){       cin>>x;    set<int>st;    string s= 123456789 ;    n=s.length();    vi vec,ans;    int sz=INT_MAX;    string s1,res=  ;    for(int i=0;i<pow(2,n);i++)    {     int sum=0;     vec.clear();     s1=  ;      for(int j=0;j<n;j++)      {         if(i&(1<<j))          {            sum+=s[j]- 0 ;            s1+=s[j];         }      }          if(sum==x)       {               if(res==  )        res=s1;        else if(s1.compare(res))        res=s1;                  }                        }    if(res.length()>0)    {     cout<<res;    }    else    cout<<-1;    cout<<  n ;          }      /************************************************ CODE ENDS ***************************************************************/


#include <bits/stdc++.h>   using namespace std;   void solve() {     long long int n;     cin >> n;     if (n & 1)       cout << ((n / 2) + 1) <<   n ;     else       cout << (n / 2) <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int t;     cin >> t;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int max_n = 1000005;   int n, k;   int a[max_n], d[max_n];   long long sum[max_n];   long long suf[max_n];   long long pre[max_n];   int main() {     scanf( %d%d , &n, &k);     for (int i = 1; i <= n; i++) scanf( %d , a + i);     for (int i = 1; i <= n; i++) scanf( %d , d + i);     for (int i = n; i >= 1; i--) sum[i] = sum[i + 1] + a[i];     long long ans = 0;     if (k == 0) {       for (int i = 1; i <= n; i++) ans = max(ans, sum[i] - d[i]);     } else if (k >= 2) {       for (int i = 1; i < n; i++) ans = max(ans, sum[1] - d[i]);       ans = max(ans, 1ll * a[n] - 1ll * d[n]);     } else {       suf[n] = sum[n] - d[n];       for (int i = n - 1; i >= 1; i--) suf[i] = max(suf[i + 1], sum[i] - d[i]);       int mx = d[1];       for (int i = 2; i < n; i++) {         mx = min(mx, d[i]);         ans = max(ans, max(sum[1] - sum[i + 1] - mx, 0ll) + max(suf[i + 1], 0ll));       }       for (int i = 1; i <= n; i++) pre[i] = max(pre[i - 1], sum[i] - d[i]);       for (int i = 1; i + 2 <= n; i++) {         long long res = 0;         if (a[i + 1] - d[i + 1] > 0) res += a[i + 1] - d[i + 1];         res += max(pre[i] - a[i + 1], 0ll);         ans = max(ans, res);         ans = max(ans, suf[i + 1]);       }       for (int i = 1; i < n; i++) ans = max(ans, suf[i + 1]);     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5;   int a[N + 2], p[N + 2];   void solve() {     int n;     cin >> n;     for (int i = 1; i <= n; i++) {       int x;       cin >> x;       a[x] = i, p[i] = 0;     }     p[n + 1] = 1;     int nx = -1;     for (int i = 1; i <= n; i++) {       if (nx == -1) {         p[a[i]] = 1;         if (p[a[i] + 1] == 0) nx = a[i] + 1;       } else {         if (a[i] != nx) {           cout <<  NO n ;           return;         }         nx++;         if (p[nx]) nx = -1;       }     }     cout <<  YES n ;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int t;     cin >> t;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const unsigned int maxn = 35000, maxk = 50;   class STree {    public:     void build(const unsigned int l, const unsigned int r, STree*(&cur),                unsigned int dat[]) {       lv = l;       rv = r;       mv = (l + r) >> 1;       if (r - l == 1) return;       lc = ++cur;       rc = ++cur;       lc->build(l, mv, cur, dat);       rc->build(mv, r, cur, dat);     }     void init(const unsigned int dat[]) {       laz = 0;       if (rv - lv == 1) {         val = dat[lv];         return;       }       lc->init(dat);       rc->init(dat);       this->val = max(lc->val, rc->val);     }     void increase(const unsigned int l, const unsigned int r) {       if (l == lv && r == rv) {         push(1);         return;       }       pushdown();       if (r <= mv)         lc->increase(l, r);       else if (l >= mv)         rc->increase(l, r);       else {         lc->increase(l, mv);         rc->increase(mv, r);       }       this->val = max(lc->val, rc->val);     }     unsigned int query(const unsigned int l, const unsigned int r) {       if (l == lv && r == rv) return val;       pushdown();       if (r <= mv)         return lc->query(l, r);       else if (l >= mv)         return rc->query(l, r);       else         return max(lc->query(l, mv), rc->query(mv, r));     }       private:     void push(const unsigned int laz) {       this->val += laz;       this->laz += laz;     }     void pushdown() {       if (!laz) return;       lc->push(laz);       rc->push(laz);       laz = 0;     }     STree *lc = nullptr, *rc = nullptr;     unsigned int val, laz;     unsigned int lv, mv, rv;   } SNodes[maxn * 4 + 1], *SRoot = SNodes;   unsigned int lst[maxn + 1], a[maxn + 1];   unsigned int f[maxn + 1];   static void initLst(const unsigned int n) {     static unsigned int pos[maxn + 1];     for (unsigned int i = 1; i <= n; ++i) {       lst[i] = pos[a[i]];       pos[a[i]] = i;     }   }   static unsigned int dp(const unsigned int n, const unsigned int k) {     for (unsigned int i = 1; i <= n; ++i) f[i] = lst[i] ? f[i - 1] : f[i - 1] + 1;     for (unsigned int i = 2; i <= k; ++i) {       SRoot->init(f);       for (unsigned int j = 2; j <= n; ++j) {         SRoot->increase(lst[j], j);         f[j] = SRoot->query(1, j);       }     }     return f[n];   }   int main() {     ios_base::sync_with_stdio(false);     unsigned int n, k;     cin >> n >> k;     copy_n(istream_iterator<unsigned int>(cin), n, a + 1);     {       STree* c = SNodes;       SRoot->build(0, n + 1, c, f);     }     initLst(n);     cout << dp(n, k) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void c_p_c() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   long long me(long long x, long long y, long long p) {     long long res = 1;     x = x % p;     if (x == 0) return 0;     while (y > 0) {       if (y & 1) res = (res * x) % p;       y = y >> 1;       x = (x * x) % p;     }     return res;   }   int main() {     c_p_c();     long long t;     cin >> t;     while (t--) {       long long n, k;       cin >> n >> k;       string s;       cin >> s;       long long p1 = 0;       long long count = 0;       long long c = 0;       for (long long i = 0; i < s.length(); i++) {         if (s[i] ==  1 ) {           c++;         }       }       if (c == 0) {         p1 = s.length();         if (1) {           long long y = (p1 - 1) / (k + 1);           cout << y + 1 << endl;           continue;         }       }       long long p2 = n - 1;       for (long long i = 0; i < n; i++) {         if (s[i] ==  1 ) {           p1 = i;           break;         }       }       for (long long i = n - 1; i >= 0; i--) {         if (s[i] ==  1 ) {           p2 = i;           break;         }       }       long long temp = p1;       if (c >= 2) {         for (long long i = p1 + 1; i <= p2; i++) {           if (s[i] ==  1 ) {             long long x = i - temp - 1;             if (x - k >= 0) {               x = x - k;               long long y = x / (k + 1);               count = count + y;             }             temp = i;           }         }       }       if (1) {         long long y = p1 / (k + 1);         count = count + y;       }       long long n1 = n - p2 - 1;       if (1) {         long long y = n1 / (k + 1);         count = count + y;       }       cout << count << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   void read(T &x) {     x = 0;     char c = getchar();     int fh = 1;     while (!isdigit(c)) {       if (c ==  - ) fh = -1;       c = getchar();     }     while (isdigit(c)) x = x * 10 + c -  0 , c = getchar();     x *= fh;   }   struct Info {     int nu, ne;   } a[400010 * 2], na[400010 * 2];   struct seg {     int l, r, mi;   } t[400010 * 4];   int num, b[400010], m, n, x, y, lo[400010], df[400010], su, q, nu, nb[400010],       nst, st[400010], va[400010], f[400010], d[400010], si[400010], so[400010],       tp[400010], bi[400010];   multiset<int> v[400010];   void jb(int x, int y) {     a[++num].nu = y;     a[num].ne = b[x];     b[x] = num;   }   void jnb(int x, int y) {     na[++nu].nu = y;     na[nu].ne = nb[x];     nb[x] = nu;   }   void tarjan(int x, int fa) {     lo[x] = df[x] = ++num;     st[++nst] = x;     for (int y = nb[x]; y; y = na[y].ne) {       if (na[y].nu != fa) {         if (!df[na[y].nu]) {           tarjan(na[y].nu, x);           lo[x] = min(lo[x], lo[na[y].nu]);           if (lo[na[y].nu] >= df[x]) {             jb(x, ++su);             jb(su, x);             while (st[nst] != na[y].nu) {               jb(su, st[nst]);               jb(st[nst], su);               nst--;             }             jb(su, st[nst]);             jb(st[nst], su);             nst--;           }         } else           lo[x] = min(lo[x], df[na[y].nu]);       }     }   }   void dfs(int x, int fa, int dep) {     f[x] = fa;     d[x] = dep;     si[x] = 1;     for (int y = b[x]; y; y = a[y].ne) {       if (a[y].nu != fa) {         dfs(a[y].nu, x, dep + 1);         if (x > n) {           v[x].insert(va[a[y].nu]);         }         si[x] += si[a[y].nu];         if (si[a[y].nu] > si[so[x]]) so[x] = a[y].nu;       }     }   }   void dfs1(int x) {     bi[x] = ++num;     if (so[x] != 0) {       tp[so[x]] = tp[x];       dfs1(so[x]);     }     for (int y = b[x]; y; y = a[y].ne) {       if (a[y].nu != f[x] && a[y].nu != so[x]) {         tp[a[y].nu] = a[y].nu;         dfs1(a[y].nu);       }     }   }   int quem(int nu, int l, int r) {     if (t[nu].l == l && t[nu].r == r) return t[nu].mi;     int mid = (t[nu].l + t[nu].r) / 2;     if (l > mid) return quem(nu * 2 + 1, l, r);     if (r <= mid) return quem(nu * 2, l, r);     return min(quem(nu * 2, l, mid), quem(nu * 2 + 1, mid + 1, r));   }   int que(int x, int y) {     int no = 1e9;     while (tp[x] != tp[y]) {       if (d[tp[x]] < d[tp[y]]) swap(x, y);       no = min(no, quem(1, bi[tp[x]], bi[x]));       x = f[tp[x]];     }     if (d[x] > d[y]) swap(x, y);     no = min(no, quem(1, bi[x], bi[y]));     if (x > n) no = min(no, quem(1, bi[f[x]], bi[f[x]]));     return no;   }   void build(int nu, int l, int r) {     t[nu].l = l;     t[nu].r = r;     t[nu].mi = 0;     if (l != r) {       build(nu * 2, l, (l + r) / 2);       build(nu * 2 + 1, (l + r) / 2 + 1, r);       t[nu].mi = min(t[nu * 2].mi, t[nu * 2 + 1].mi);     }   }   int man(int x) {     multiset<int>::iterator i = v[x].begin();     return *i;   }   void chan(int nu, int we, int x) {     if (t[nu].l == t[nu].r) {       t[nu].mi = x;       return;     }     if (we <= (t[nu].l + t[nu].r) / 2)       chan(nu * 2, we, x);     else       chan(nu * 2 + 1, we, x);     t[nu].mi = min(t[nu * 2].mi, t[nu * 2 + 1].mi);   }   void work(int x, int y, int z) {     multiset<int>::iterator i = v[x].find(y);     v[x].erase(i);     v[x].insert(z);     chan(1, bi[x], man(x));   }   int main() {     read(n);     read(m);     read(q);     su = n;     for (int i = 1; i <= n; i++) read(va[i]);     for (int i = 1; i <= m; i++) {       read(x);       read(y);       jnb(x, y);       jnb(y, x);     }     for (int i = 1; i <= n; i++)       if (!df[i]) tarjan(i, 0);     dfs(1, 0, 1);     tp[1] = 1;     num = 0;     dfs1(1);     build(1, 1, su);     for (int i = 1; i <= su; i++)       if (i <= n)         chan(1, bi[i], va[i]);       else         chan(1, bi[i], man(i));     while (q--) {       char ch = getchar();       while (ch !=  A  && ch !=  C ) ch = getchar();       if (ch ==  A ) {         read(x);         read(y);         printf( %d n , que(x, y));       } else {         read(x);         read(y);         chan(1, bi[x], y);         if (f[x]) work(f[x], va[x], y);         va[x] = y;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, k;     scanf( %d %d %d , &n, &m, &k);     int arr[(int)1e5 + 5];     for (int i = 1; i <= n; i++) scanf( %d , &arr[i]);     vector<int> vec;     for (int i = 2; i <= n; i++) vec.push_back(arr[i] - arr[i - 1]);     sort(vec.begin(), vec.end());     long long res = arr[n] - arr[1] + 1;     int bad = k - 1;     for (int i = vec.size() - 1; i >= 0 && bad > 0; i--) {       res -= vec[i] - 1;       bad--;     }     printf( %lld n , res);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int t;     cin >> t;     while (t--) {       long long int a[3];       for (long long int i = 0; i < 3; i++) {         cin >> a[i];       }       sort(a, a + 3);       if (a[0] == a[1] && a[1] == a[2]) {         cout <<  YES  << endl;         cout << a[0] <<     << a[1] <<     << a[2] << endl;       } else if (a[1] == a[2] && a[0] < a[1]) {         cout <<  YES  << endl;         cout << a[0] <<     << a[0] <<     << a[1] << endl;       } else         cout <<  NO  << endl;     }     return 0;   }


#include <bits/stdc++.h>   int main() {     int n, count = 0;     scanf( %d , &n);     while (n--) {       int t = 3, s = 0;       while (t--) {         int a;         scanf( %d , &a);         s = s + a;       }       if (s > 1) {         count++;       }     }     printf( %d , count);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int read() {     int x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x * f;   }   int n;   int s[105];   void swap(int first, int last) {     while (first <= last) {       int t = s[first];       s[first] = s[first + 1];       s[first + 1] = t;       first += 2;     }   }   int main() {     n = read();     for (int i = 1; i <= n; i++) {       s[i] = read();     }     bool b = true;     while (b) {       b = false;       for (int i = 1; i <= n - 1; i++) {         if (s[i] > s[i + 1]) {           b = true;           int j = i + 2;           while (j < n && s[j] > s[j + 1]) j += 2;           cout << i <<     << j - 1 << endl;           swap(i, j - 2);           break;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n, m;       cin >> n >> m;       long long int a[n], b[n], c[n], d[n];       bool f = false;       for (long long int i = 0; i < n; i = i + 1) {         cin >> a[i] >> b[i] >> c[i] >> d[i];         if (b[i] == c[i]) {           f = true;         }       }       if (m % 2 != 0 || f == false) {         cout <<  NO  << endl;       } else {         cout <<  YES  << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 3e5 + 7;   int ans[N];   int he[N];   int res[N];   vector<int> g[N];   vector<int> a[N];   vector<int> lul[N];   void dfs(int v, int pr, int h) {     he[v] = h;     for (auto to : g[v]) {       if (to != pr) {         dfs(to, v, h + 1);       }     }   }   int main() {     int n, m;     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; i++) {       ans[i] = 1;       res[i] = 1e9;     }     for (int i = 0; i < n; i++) {       int s;       scanf( %d , &s);       while (s--) {         int x;         scanf( %d , &x);         lul[i].push_back(x);       }     }     for (int i = 1; i < n; i++) {       int u, v;       scanf( %d%d , &u, &v);       g[u].push_back(v);       g[v].push_back(u);     }     dfs(1, 0, 0);     vector<int> a(n);     for (int i = 0; i < n; i++) {       a[i] = i + 1;     }     for (int i = 0; i < n; i++) {       for (auto c : lul[i]) {         res[c] = min(res[c], he[i + 1]);       }     }     sort(a.begin(), a.end(), [](int a, int b) { return he[a] < he[b]; });     int lfl = 1;     for (int i : a) {       vector<int> lel;       int cnt = 0;       set<int> s;       for (auto c : lul[i - 1]) {         if (res[c] == he[i]) {           lel.push_back(c);         } else {           s.insert(ans[c]);         }       }       int sz = 1;       for (auto c : lel) {         while (s.count(sz)) {           sz++;         }         s.insert(sz);         ans[c] = sz;         lfl = max(lfl, sz);       }     }     printf( %d n , lfl);     for (int i = 1; i <= m; i++) {       printf( %d  , ans[i]);     }     puts(  );   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 1e6 + 5;   const int MOD = 1e9 + 7;   int dr[4] = {0, 0, 1, -1};   int dc[4] = {1, -1, 0, 0};   int ddr[8] = {0, 0, 1, -1, 1, -1, 1, -1};   int ddc[8] = {1, -1, 0, 0, 1, -1, -1, 1};   bool isPrime(int n) {     if (n <= 1) return false;     for (int i = 2; i < n; i++)       if (n % i == 0) return false;     return true;   }   long long int power(long long int a, long long int b) {     long long int ans = 1;     while (b) {       if (b & 1) ans = (ans * a) % MOD;       a = (a * a) % MOD;       b /= 2;     }     return ans;   }   long long int nCr(long long int n, long long int r) {     long long int ans = 1, i;     if (r > n - r) r = n - r;     for (i = 0; i < r; i++) {       ans = (ans * (n - i)) % MOD;       ans = (ans * power(i + 1, MOD - 2)) % MOD;     }     return ans;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int t;     t = 1;     cin >> t;     int tt = 0;     while (t--) {       int n, k;       cin >> n >> k;       string s;       cin >> s;       int a = k / 3;       a++;       string r;       for (int i = 0; i < a; i++) {         r = r +  RGB ;       }       r = r +  RGB ;       int mn = 1e5;       for (int i = 0; i < n - k + 1; i++) {         int mm = 1e5;         string p = s.substr(i, k);         int c = 0, d = 0, e = 0;         for (int j = 0; j < k; j++) {           if (p[j] != r[j]) c++;           if (p[j] != r[j + 1]) d++;           if (p[j] != r[j + 2]) e++;         }         mm = min(c, min(d, e));         mn = min(mn, mm);       }       cout << mn <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long solve(long long n, long long x, long long y) {     if (y == 0) return 0;     if (y == x / 2 + 1) return n / 2 + (n % 2);     long long res = 0;     if (y > x / 2 + 1) {       res += n / 2;       res += n % 2;       res += solve(n / 2, x / 2, y - x / 2 - 1);     } else       res += solve(n / 2, x / 2, y);     return res;   }   int main() {     long long n, l, r;     cin >> n >> l >> r;     long long res = 1;     while (res <= n) res *= 2;     res--;     long long c = solve(n, res, r);     long long d = solve(n, res, l - 1);     cout << c - d;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 998244353;   struct DSU {     int n;     vector<int> link, sz;     DSU(int n) : n(n), link(n), sz(n) {       for (int i = 0; i < n; i++) {         link[i] = i;         sz[i] = 1;       }     }     int first(int x) { return (x == link[x] ? x : link[x] = first(link[x])); }     void unite(int x, int y) {       x = first(x), y = first(y);       if (x == y) {         return;       }       if (sz[x] < sz[y]) {         swap(x, y);       }       sz[x] += sz[y], link[y] = x;     }   };   int n, m, k, dp[300001], nxt[300000], prv[300000];   vector<int> arr[300000], dsc[300000];   vector<pair<int, int>> trns;   map<int, int> chns;   bool bad[300000], appeared[300000];   int mul(int x, int y) { return ((long long)x * y) % mod; }   int main() {     ios_base::sync_with_stdio(false);     cin >> n >> m >> k;     DSU grp(k);     memset(nxt, -1, sizeof(nxt));     memset(prv, -1, sizeof(prv));     for (int i = 0, sz; i < n; i++) {       cin >> sz;       arr[i].resize(sz);       for (int j = 0; j < sz; j++) {         cin >> arr[i][j];         appeared[arr[i][j] - 1] = true;       }       for (int j = 0; j < sz - 1; j++) {         grp.unite(arr[i][j] - 1, arr[i][j + 1] - 1);       }     }     for (int i = 0; i < k; i++) {       dsc[grp.first(i)].push_back(i);     }     for (int i = 0; i < n; i++) {       int sz = arr[i].size();       for (int j = 0; j < sz - 1; j++) {         if (prv[arr[i][j + 1] - 1] != -1 &&             prv[arr[i][j + 1] - 1] != arr[i][j] - 1) {           bad[grp.first(arr[i][j] - 1)] = true;         }         if (nxt[arr[i][j] - 1] != -1 && nxt[arr[i][j] - 1] != arr[i][j + 1] - 1) {           bad[grp.first(arr[i][j] - 1)] = true;         }         prv[arr[i][j + 1] - 1] = arr[i][j] - 1;         nxt[arr[i][j] - 1] = arr[i][j + 1] - 1;       }     }     for (int i = 0; i < k; i++) {       if (bad[i]) {         for (int j : dsc[i]) {           bad[j] = true;         }       }     }     for (int i = 0; i < k; i++) {       if (prv[i] == -1 && !bad[i]) {         int chn = 1, cur = i;         while (nxt[cur] != -1) {           cur = nxt[cur];           ++chn;         }         ++chns[chn];       }     }     for (auto it : chns) {       trns.push_back(it);     }     dp[0] = 1;     for (int i = 1; i <= m; i++) {       for (auto j : trns) {         if (i >= j.first) {           dp[i] = (dp[i] + mul(dp[i - j.first], j.second)) % mod;         }       }     }     cout << dp[m] <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int n, d, m, a[100001], id;   long long sum[100001];   int main() {     scanf( %d%d%d , &n, &d, &m);     for (int i = 1; i <= n; ++i) scanf( %d , a + i);     sort(a + 1, a + 1 + n);     id = upper_bound(a + 1, a + 1 + n, m) - a;     for (int i = 1; i <= n; ++i) sum[i] = sum[i - 1] + a[i];     if (id == n + 1) {       printf( %lld n , sum[n]);       return 0;     }     long long ans = 0;     for (int i = 0; i <= n - id; ++i) {       if ((d + 1) * i > n - 1) break;       int k = min(n - 1 - (d + 1) * i, id - 1);       ans = max(ans, sum[id - 1] - sum[id - 1 - k] + sum[n - 1] - sum[n - 1 - i]);     }     ans += a[n];     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   class TwoSat {     static const int ME = 1000010;     static const int MV = 2010;     struct G {       struct E {         int u, v, next;       } e[ME];       int le, head[MV];       void init() {         le = 0;         memset(head, -1, sizeof(head));       }       void add(int u, int v) {         e[le].u = u;         e[le].v = v;         e[le].next = head[u];         head[u] = le++;       }     } g;     class Tarjan {       int Index, Bcnt, num[MV], belong[MV], dfn[MV], low[MV];       bool instack[MV];       stack<int> s;       void tarjan(int u) {         dfn[u] = low[u] = ++Index;         instack[u] = true;         s.push(u);         int v;         for (int i = g.head[u]; ~i; i = g.e[i].next) {           v = g.e[i].v;           if (!dfn[v]) {             tarjan(v);             low[u] = min(low[u], low[v]);           } else if (instack[v]) {             low[u] = min(low[u], dfn[v]);           }         }         if (dfn[u] == low[u]) {           Bcnt++;           do {             v = s.top();             s.pop();             instack[v] = false;             belong[v] = Bcnt;             num[Bcnt]++;           } while (u != v);         }       }         public:       G g;       void init() {         g.init();         Index = Bcnt = 0;         memset(num, 0, sizeof(num));         memset(dfn, 0, sizeof(dfn));         memset(low, 0, sizeof(low));         memset(instack, 0, sizeof(instack));         while (!s.empty()) s.pop();       }       void add(int u, int v) { g.add(u, v); }       void solve(int n) {         for (int i = 1; i <= n; i++) {           if (!dfn[i]) {             tarjan(i);           }         }       }       int getbcnt() { return Bcnt; }       int getbelong(int id) { return belong[id]; }       int getnum(int id) { return num[id]; }     } T;     class Unitenode {       G ug;       int n, in[MV];       bool mat[MV][MV];       queue<int> q;         public:       void init(int tn) {         n = tn;         ug.init();         memset(in, 0, sizeof(in));         for (int i = 1; i <= n; i++)           for (int j = 1; j <= n; j++) mat[i][j] = i == j ? true : false;       }       void add(int u, int v) {         if (!mat[u][v]) {           in[v]++;           mat[u][v] = true;           ug.add(u, v);         }       }       void solve(int tp[]) {         while (!q.empty()) q.pop();         for (int i = 1; i <= n; i++) {           if (!in[i]) {             q.push(i);           }         }         int ret = 1;         while (!q.empty()) {           int u = q.front();           q.pop();           tp[ret++] = u;           for (int i = ug.head[u]; ~i; i = ug.e[i].next) {             int v = ug.e[i].v;             in[v]--;             if (!in[v]) {               q.push(v);             }           }         }       }     } U;     void unite() {       U.init(T.getbcnt());       for (int i = 1; i <= n; i++) {         for (int j = T.g.head[i]; ~j; j = T.g.e[j].next) {           U.add(T.getbelong(i), T.getbelong(T.g.e[j].v));         }       }     }     int n, tp[MV];     bool flag[MV];       public:     void init(int tn) {       n = tn;       T.init();     }     void add(int u, int v) { T.add(u, v); }     bool solve() {       T.solve(n);       for (int i = 1, z = n / 2; i <= z; i++) {         if (T.getbelong(i) == T.getbelong(i + z)) return false;       }       return true;     }     void output(bool ans[]) {       unite();       U.solve(tp);       memset(flag, 0, sizeof(flag));       for (int i = T.getbcnt(); i > 0; i--) {         for (int j = 1, y; j <= n; j++) {           if (j > n / 2)             y = j - n / 2;           else             y = j;           if (!flag[y] && T.getbelong(j) == tp[i]) {             flag[y] = true;             if (j > n / 2) {               ans[j - n / 2] = true;             } else {               ans[j] = false;             }           }         }       }     }   } gx;   const int M = 128;   struct IN {     int x, y;   } in[M];   bool ok(int i, int j) {     if (in[i].x < in[j].x && in[j].x < in[i].y && in[i].y < in[j].y) return true;     return false;   }   bool judge(int i, int j) {     if (ok(i, j) || ok(j, i)) return true;     return false;   }   bool ans[M];   int main() {     int n, m;     while (~scanf( %d%d , &n, &m)) {       gx.init(m * 2);       for (int i = 1; i <= m; i++) {         scanf( %d%d , &in[i].x, &in[i].y);         if (in[i].x > in[i].y) swap(in[i].x, in[i].y);       }       for (int i = 1; i <= m; i++) {         for (int j = i + 1; j <= m; j++) {           if (judge(i, j)) {             gx.add(i, j + m);             gx.add(j, i + m);             gx.add(i + m, j);             gx.add(j + m, i);           }         }       }       if (gx.solve()) {         gx.output(ans);         for (int i = 1; i <= m; i++) {           if (ans[i])             printf( i );           else             printf( o );         }         puts(  );       } else {         puts( Impossible );       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using int64 = long long;   using ld = double;   const int MAXN = 1e5 + 1;   vector<int> G[MAXN], comp[MAXN], suf_freq[MAXN];   vector<int64> suf_sum[MAXN];   int comp_cnt, comp_ind[MAXN], p[MAXN], dp1[MAXN], dp2[MAXN], dp[MAXN],       diameter[MAXN];   void max_self(int &a, int b) { a = max(a, b); }   void dfs1(int u) {     comp_ind[u] = comp_cnt;     comp[comp_cnt].emplace_back(u);     for (int v : G[u])       if (!comp_ind[v]) {         p[v] = u;         dfs1(v);         if (dp1[u] <= dp1[v] + 1) {           dp2[u] = dp1[u];           dp1[u] = dp1[v] + 1;         } else           max_self(dp2[u], dp1[v] + 1);       }   }   void dfs2(int u, int dist) {     dp[u] = max(dp1[u], dist);     max_self(diameter[comp_cnt], dp[u]);     for (int v : G[u])       if (v != p[u]) {         if (dp1[u] == dp1[v] + 1)           dfs2(v, max(dp2[u], dist) + 1);         else           dfs2(v, max(dp1[u], dist) + 1);       }   }   ld solve(int x, int y) {     if (x == y) return -1;     if (comp[x].size() > comp[y].size()) swap(x, y);     int D = max(diameter[x], diameter[y]);     ld sum = 0;     for (int d = 0; d <= diameter[x]; ++d) {       int64 freq = suf_freq[x][d];       if (d < diameter[x]) freq -= suf_freq[x][d + 1];       if (freq == 0) continue;       int suf = max(0, min(D - d - 1, diameter[y]));       sum += freq * suf_sum[y][suf];       sum += freq * suf_freq[y][suf] * (d + 1);       int rest = comp[y].size() - suf_freq[y][suf];       sum += freq * rest * D;     }     return sum / ((ld)comp[x].size() * comp[y].size());   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     int N, M, Q;     cin >> N >> M >> Q;     for (int i = 0; i < M; ++i) {       int u, v;       cin >> u >> v;       G[u].emplace_back(v);       G[v].emplace_back(u);     }     for (int u = 1; u <= N; ++u)       if (!comp_ind[u]) {         ++comp_cnt;         dfs1(u);         dfs2(u, 0);         suf_sum[comp_cnt] = vector<int64>(diameter[comp_cnt] + 1);         suf_freq[comp_cnt] = vector<int>(diameter[comp_cnt] + 1);         for (int v : comp[comp_cnt]) {           suf_sum[comp_cnt][dp[v]] += dp[v];           ++suf_freq[comp_cnt][dp[v]];         }         for (int d = diameter[comp_cnt] - 1; d >= 0; --d) {           suf_sum[comp_cnt][d] += suf_sum[comp_cnt][d + 1];           suf_freq[comp_cnt][d] += suf_freq[comp_cnt][d + 1];         }       }     map<pair<int, int>, ld> sol;     cout << fixed << setprecision(8);     for (int q = 0; q < Q; ++q) {       int u, v;       cin >> u >> v;       u = comp_ind[u], v = comp_ind[v];       if (u > v) swap(u, v);       pair<int, int> p{u, v};       auto it = sol.find(p);       if (it != sol.end())         cout << it->second <<   n ;       else {         ld ans = solve(u, v);         sol[p] = ans;         cout << ans <<   n ;       }     }     return 0;   }