#include <bits/stdc++.h>   using namespace std;   int dp[150][150];   int main() {     int n;     cin >> n;     for (char a =  a ; a <=  z ; a++)       for (char b =  a ; b <=  z ; b++) dp[a][b] = -2000000009;     for (char c =  a ; c <=  z ; c++) dp[c][c] = 0;     while (n--) {       string s;       cin >> s;       char a = s[0], b = s[s.length() - 1];       for (char c =  a ; c <=  z ; c++)         dp[c][b] = max(dp[c][b], dp[c][a] + (int)s.length());     }     int ans = 0;     for (char c =  a ; c <=  z ; c++) ans = max(ans, dp[c][c]);     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   ll modinv(ll a, ll m) {     assert(m > 0);     if (m == 1) return 0;     a %= m;     if (a < 0) a += m;     assert(a != 0);     if (a == 1) return 1;     return m - modinv(m, a) * m / a;   }   template <int MOD_>   struct modnum {    private:     int v;       public:     static const int MOD = MOD_;     modnum() : v(0) {}     modnum(ll v_) : v(int(v_ % MOD)) {       if (v < 0) v += MOD;     }     explicit operator int() const { return v; }     friend bool operator==(const modnum& a, const modnum& b) {       return a.v == b.v;     }     friend bool operator!=(const modnum& a, const modnum& b) {       return a.v != b.v;     }     modnum operator~() const {       modnum res;       res.v = modinv(v, MOD);       return res;     }     modnum& operator+=(const modnum& o) {       v += o.v;       if (v >= MOD) v -= MOD;       return *this;     }     modnum& operator-=(const modnum& o) {       v -= o.v;       if (v < 0) v += MOD;       return *this;     }     modnum& operator*=(const modnum& o) {       v = int(ll(v) * ll(o.v) % MOD);       return *this;     }     modnum& operator/=(const modnum& o) { return *this *= (~o); }     friend modnum operator+(const modnum& a, const modnum& b) {       return modnum(a) += b;     }     friend modnum operator-(const modnum& a, const modnum& b) {       return modnum(a) -= b;     }     friend modnum operator*(const modnum& a, const modnum& b) {       return modnum(a) *= b;     }     friend modnum operator/(const modnum& a, const modnum& b) {       return modnum(a) /= b;     }   };   using num = modnum<998244353>;   template <typename T>   T pow(T a, long long b) {     assert(b >= 0);     T r = 1;     while (b) {       if (b & 1) r *= a;       b >>= 1;       a *= a;     }     return r;   }   vector<num> fact;   vector<num> ifact;   void init() {     int N = 1100000;     fact = {1};     for (int i = 1; i < N; i++) fact.push_back(i * fact[i - 1]);     ifact.resize(N);     ifact.back() = 1 / fact.back();     for (int i = N - 1; i > 0; i--) ifact[i - 1] = i * ifact[i];   }   num ncr(int n, int k) {     if (k < 0 || k > n) return 0;     return fact[n] * ifact[k] * ifact[n - k];   }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     init();     int n, k;     cin >> n >> k;     vector<int> A(n);     for (int i = 0; i < n; i++) cin >> A[i];     int same = 0;     for (int i = 0; i < n; i++)       if (A[i] == A[(i + 1) % n]) same++;     int diff = n - same;     num ans = 0;     for (int a = 0; a * 2 <= diff; a++) {       ans += ncr(diff, a) * ncr(diff - a, a) * pow(num(k - 2), diff - a - a);     }     ans = (pow(num(k), diff) - ans) / 2;     ans = ans * pow(num(k), same);     cout << (int)ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1000000 + 50;   const int maxm = 1300000 + 100;   const int maxt = 3000000 + 100;   const int maxk = 10 + 3;   const int M = 2010;   const long long unit = 1LL;   const int INF = 0x3f3f3f3f;   const long long Inf = 0x3f3f3f3f3f3f3f3fLL;   const double eps = 1e-8;   const double inf = 1e15;   const double pi = acos(-1.0);   const long long mod = 998244353LL, gg = 3LL, inv2 = 499122177LL;   inline long long read() {     long long x = 0;     bool t = false;     char ch = getchar();     while ((ch <  0  || ch >  9 ) && ch !=  - ) ch = getchar();     if (ch ==  - ) t = true, ch = getchar();     while (ch <=  9  && ch >=  0 ) x = x * 10 + ch - 48, ch = getchar();     return t ? -x : x;   }   struct Peo {     int pos, id;     bool operator<(const Peo &a) const {       if (pos == a.pos) return id < a.id;       return pos < a.pos;     }   } peo[maxn];   struct City {     int pos, id;     bool operator<(const City &a) const {       if (pos == a.pos) return id < a.id;       return pos < a.pos;     }   } city[maxn];   int m, n, a[maxn], b[maxn];   long long judge(int x) {     long long ret = 0;     if (x < 0) {       for (int i = 0; i < -x; i++) ret += peo[i].pos + m - city[n + x + i].pos;       for (int i = -x; i < n; i++) ret += abs(peo[i].pos - city[i + x].pos);     } else {       for (int i = 0; i < x; i++) ret += city[i].pos + m - peo[n - x + i].pos;       for (int i = x; i < n; i++) ret += abs(city[i].pos - peo[i - x].pos);     }     return ret;   }   int main() {     m = read(), n = read();     for (int i = 0; i < n; ++i) city[i].pos = read(), city[i].id = i;     sort(city, city + n);     for (int i = 0; i < n; ++i) peo[i].pos = read(), peo[i].id = i;     sort(peo, peo + n);     int l = -n, r = n;     while (l < r) {       int m = (l + r) >> 1;       if (judge(m) < judge(m + 1))         r = m;       else         l = m + 1;     }     long long ans = Inf, anst = 0;     for (int turn = l - 100; turn <= l + 100; ++turn) {       int st = (turn % n + n) % n;       long long res = 0;       for (int i = 0; i < n; ++i) {         res += min(abs(peo[i].pos - city[st].pos),                    m - abs(peo[i].pos - city[st].pos));         ++st;         if (st >= n) st -= n;       }       if (res < ans) {         ans = res;         anst = turn;       }     }     printf( %lld n , ans);     int st = (anst % n + n) % n;     for (int i = 0; i < n; ++i) {       b[city[st].id] = peo[i].id;       ++st;       if (st >= n) st -= n;     }     for (int i = 0; i < n; ++i) printf( %d  , b[i] + 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n, m;     cin >> n >> m;     vector<vector<vector<long long>>> g(n);     vector<vector<long long>> store(m);     for (long long i = 0; i < m; i++) {       long long a, b, c;       cin >> a >> b >> c;       --a;       b--;       g[a].push_back({b, c});       g[b].push_back({a, c});       store[i] = {a, b, c};     }     long long s;     cin >> s;     s--;     vector<long long> d(n, LONG_LONG_MAX);     vector<long long> parent(n), dd(n, LONG_LONG_MAX);     for (long long i = 0; i < n; i++) {       parent[i] = i;     }     d[s] = dd[s] = 0;     set<pair<long long, long long>> q;     q.insert({d[s], s});     while (!q.empty()) {       long long v = q.begin()->second;       q.erase(q.begin());       for (long long i = 0; i < g[v].size(); i++) {         long long to = g[v][i][0], len = g[v][i][1];         if (d[v] + len < d[to]) {           if (q.find({d[to], to}) != q.end()) {             q.erase({d[to], to});           }           parent[to] = v;           d[to] = d[v] + len;           dd[to] = len;           q.insert(make_pair(d[to], to));         } else if (d[v] + len == d[to]) {           if (dd[to] > len) {             dd[to] = len;             parent[to] = v;           }         }       }     }     long long ans = 0;     for (long long i = 0; i < n; i++) {       ans += dd[i];     }     cout << ans << endl;     for (long long i = 0; i < m; i++) {       long long a = store[i][0];       long long b = store[i][1];       if (parent[a] == b || parent[b] == a) {         cout << i + 1 <<    ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   int main() {     cin >> n;     int cur = 1;     while (n) {       if (n == 3) {         printf( %d %d %d  , cur, cur, cur * n);         return 0;       }       int cnt = n / 2 + n % 2;       n -= cnt;       while (cnt--) printf( %d  , cur);       cur *= 2;     }   }


#include <bits/stdc++.h>   const int Max_N(1000005);   int N, D;   int first[Max_N], ecnt(1), Next[Max_N * 2], To[Max_N * 2];   int degree[Max_N];   std::tuple<int, int> dfs(const int v, const int p = 0) {     if (To[first[v]] == p && Next[first[v]] == 0) return std::make_tuple(0, 0);     int res(0), max(0), min(D + 1);     for (int e(first[v]); e; e = Next[e])       if (To[e] != p) {         int len(1);         auto tmp(dfs(To[e], v));         res += std::get<0>(tmp), len += std::get<1>(tmp);         if (len >= 0) {           if (len == D)             ++res;           else if (len * 2 > D)             min = std::min(min, len), ++res;           else             max = std::max(max, len);         }       }     if (max == 0 && min == D + 1) return std::make_tuple(res, -1);     return std::make_tuple(res - (max + min <= D), max + min <= D ? min : max);   }   int main(int argc, char **argv) {     scanf( %d %d , &N, &D);     int r;     for (int i(1), v, w; i != N; ++i) {       scanf( %d %d , &v, &w);       Next[ecnt] = first[v], To[ecnt] = w, first[v] = ecnt++;       Next[ecnt] = first[w], To[ecnt] = v, first[w] = ecnt++;       ++degree[v], ++degree[w];       if (degree[v] > 1) r = v;       if (degree[w] > 1) r = w;     }     auto res(dfs(r));     printf( %d , std::get<0>(res) + (std::get<1>(res) != -1));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mxn = 5e5 + 123;   const long long inf = 1e9;   const long long mod = 998244353;   bool om[mxn];   vector<long long> v;   long long n, mn = 1e18;   ;   int main() {     int n, m;     cin >> n >> m;     for (int i = 1; i <= n; i++)       if (n % i == 0) v.push_back(i);     for (int i = 0; i < v.size(); i++) {       if (n / v[i] < m) mn = min(mn, (v[i] * m) + (n / v[i]));     }     cout << mn;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline long long tmx(long long a, long long b, long long c) {     return (a > b && a > c) ? a : ((b > c) ? b : c);   }   inline long long tmn(long long a, long long b, long long c) {     return (a < b && a < c) ? a : ((b < c) ? b : c);   }   const int MXL = 0x3f3f3f3f;   string s[] = { Anka ,    Chapay ,  Cleo ,        Troll ,                  Dracul ,  Snowy ,   Hexadecimal };   inline int find(string x) {     for (int i = 0; i < 7; ++i)       if (s[i] == x) return i;   }   int n;   long long A, B, C;   int f[7][7] = {};   long long BE = (long long)MXL * MXL, AM = 0;   int c[7];   void dfs(int w) {     if (w == 7) {       int t[3] = {};       for (int i = 0; i < 7; ++i) ++t[c[i]];       if (!t[0] || !t[1] || !t[2]) return;       long long MX = tmx(A / t[0], B / t[1], C / t[2]);       long long MN = tmn(A / t[0], B / t[1], C / t[2]);       long long BE_N = MX - MN;       if (BE_N > BE) return;       long long AM_N = 0;       for (int i = 0; i < 7; ++i)         for (int j = 0; j < 7; ++j)           if (c[i] == c[j]) AM_N += f[i][j];       if (BE_N < BE || AM_N > AM) {         BE = BE_N;         AM = AM_N;       }       return;     }     for (int i = 0; i < 3; ++i) {       c[w] = i;       dfs(w + 1);     }   }   string L, R;   int LN, RN;   string like;   inline void EXEC() {     cin >> n;     for (int i = 0; i < n; ++i) {       cin >> L >> like >> R;       LN = find(L);       RN = find(R);       ++f[LN][RN];     }     cin >> A >> B >> C;     dfs(0);     cout << BE <<     << AM << endl;   }   int main() {     EXEC();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1000000007;   long long f = 0, g = 1;   int n;   int main() {     cin >> n;     for (int i = 2; i <= n; i++) {       long long k = f;       f = 3 * g % mod;       g = (k + 2 * g) % mod;     }     printf( %lld , f);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const long long LINF = 0x3f3f3f3f3f3f3f3fll;   void bad() {     cout <<  NO  <<   n ;     exit(0);   }   const int MAX = 4e5 + 10;   vector<int> g[MAX];   int main() {     if (!false) ios_base::sync_with_stdio(0);     cin.tie(0);     int n, d, k;     cin >> n >> d >> k;     if (d >= n or (n > 2 and k == 1)) bad();     int nxt = 0;     vector<int> pos_dist(n, -1);     stack<int> can;     for (nxt = 0; nxt <= d; nxt++) {       if (nxt < d) {         g[nxt].push_back(nxt + 1);         g[nxt + 1].push_back(nxt);       }       pos_dist[nxt] = min(nxt, d - nxt);       can.push(nxt);     }     while (nxt < n) {       if (false) cout <<  g  <<   n ;       for (int i = 0; i < n; i++) {         if (false) cout << i <<  :  ;         for (auto j : g[i])           if (false) cout << j <<    ;         if (false) cout <<   n ;       }       if (false) cout <<   n ;       if (can.empty()) bad();       int v = can.top();       if (g[v].size() == k or pos_dist[v] == 0) {         can.pop();         continue;       }       g[v].push_back(nxt);       g[nxt].push_back(v);       pos_dist[nxt] = pos_dist[v] - 1;       can.push(nxt);       nxt++;     }     set<pair<int, int>> stans;     cout <<  YES  <<   n ;     for (int i = 0; i < n; i++) {       for (auto j : g[i]) stans.insert({min(i, j) + 1, max(i, j) + 1});     }     for (auto [x, y] : stans) cout << x <<     << y <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 1e8;   struct node {     int x, y, z, s;   } pre[12][18][18][18];   int n, a, b, dp[12][18][18][18], h[12];   vector<int> ans;   void f(int i, int x, int y, int z, int v, int xx, int yy, int zz, int s) {     x = max(0, x);     y = max(0, y);     z = max(0, z);     if (dp[i][x][y][z] > v) {       dp[i][x][y][z] = v;       pre[i][x][y][z] = (node){xx, yy, zz, s};     }   }   void find(int i, int x, int y, int z) {     node tmp = pre[i][x][y][z];     int s = tmp.s;     for (int j = 0; j < s; j++) {       ans.push_back(i);     }     if (i == 2) {       return;     }     find(i - 1, tmp.x, tmp.y, tmp.z);   }   int main() {     scanf( %d%d%d , &n, &a, &b);     for (int i = 1; i <= n; i++) {       scanf( %d , &h[i]);       h[i]++;     }     for (int i = 0; i <= n; i++) {       for (int x = 0; x <= 16; x++) {         for (int y = 0; y <= 16; y++) {           for (int z = 0; z <= 16; z++) {             dp[i][x][y][z] = inf;           }         }       }     }     f(1, h[1], h[2], h[3], 0, 0, 0, 0, 0);     for (int i = 1; i < n - 1; i++) {       int z = h[i + 2];       for (int x = 0; x <= h[i]; x++) {         for (int y = 0; y <= h[i + 1]; y++) {           int v = dp[i][x][y][z];           if (v >= inf) {             continue;           }           for (int j = (x + b - 1) / b;; j++) {             f(i + 1, y - j * a, z - j * b, h[i + 3], v + j, x, y, z, j);             if (j * a > y && j * b > z) {               break;             }           }         }       }     }     find(n - 1, 0, 0, 0);     cout << ans.size() << endl;     for (int i = 0; i < ans.size(); i++) {       printf( %d  , ans[i]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, arr[2005], counts[2005];   char c =  a ;   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       cin >> arr[i];     }     for (int i = n - 1; i >= 0; i--) {       counts[i] = arr[i];       if (arr[i] != 0) {         for (int j = i - 1; j >= 0; j--) {           arr[j] -= (i - j + 1) * arr[i];         }       }     }     for (int i = 1; i <= n; i++) {       for (int j = 0; j < counts[i - 1]; j++) {         for (int k = 0; k < i; k++) {           cout << c;         }         c = ((c ==  a ) ?  b  :  a );       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     if (n & n - 1)       puts( NO );     else       puts( YES );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ifstream fin( input.txt );     double a, b, c = 1.000000011, d;     cin >> a >> b;     d = a * pow(c, b);     cout.precision(30);     cout << d << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n, c = 0;       cin >> n;       int r = n;       int cnt = 0;       while (r > 0) {         int temp = r % 10;         if (temp > 0) cnt++;         r = r / 10;         c++;       }       cout << cnt << endl;       int it, ans;       for (int i = 0; i < c; i++) {         it = n % 10;         ans = it * pow(10, i);         if (ans > 0) cout << ans <<    ;         n = n / 10;       }       cout << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   char A[102];   int M[102][205][3][52];   int dp(int i, int x, int d, int n) {     if (n < 0) return 0;     if (!A[i] && n == 0) return abs(x - 102);     if (!A[i]) return 0;     int &r = M[i][x][d == 1][n];     if (r == -1) {       if (A[i] ==  F ) {         r = max(dp(i + 1, x + d, d, n),                 max(max(dp(i, x, d, n - 2), dp(i + 1, x + d, d, n - 2)),                     dp(i + 1, x, d * -1, n - 1)));       } else {         r = max(dp(i + 1, x, d * -1, n),                 max(max(dp(i, x, d * -1, n - 2), dp(i + 1, x, d * -1, n - 2)),                     dp(i + 1, x + d, d, n - 1)));       }     }     return r;   }   int main() {     int n;     scanf( %s %d , A, &n);     memset(M, -1, sizeof(M));     printf( %d n , dp(0, 102, 1, n));   }


#include <bits/stdc++.h>   using namespace std;   long long n, s, k;   string u;   long long r[60], dp[2501][60];   signed main() {     cin >> n >> s >> k;     for (long long i = 0; i < n; ++i) cin >> r[i];     cin >> u;     for (long long i = 0; i < n; ++i)       for (long long j = 0; j < n; ++j) dp[i][j] = -1e18;     --s;     dp[0][s] = r[s];     for (long long i = 0; i < s; ++i) dp[s - i][i] = r[i];     for (long long i = s + 1; i < n; ++i) dp[i - s][i] = r[i];     for (long long i = 1; i <= 2500; ++i)       for (long long j = 0; j < n; ++j)         for (long long t = 1; t <= i; ++t) {           if (j - t >= 0 && u[j - t] != u[j] && r[j - t] < r[j])             dp[i][j] = max(dp[i][j], dp[i - t][j - t] + r[j]);           if (j + t < n && u[j + t] != u[j] && r[j + t] < r[j])             dp[i][j] = max(dp[i][j], dp[i - t][j + t] + r[j]);         }     for (long long i = 0; i < 2501; ++i)       for (long long j = 0; j < n; ++j)         if (dp[i][j] >= k) return cout << i, 0;     cout << -1;   }


#include <bits/stdc++.h>   using namespace std;   template <typename A, typename B>   string to_string(pair<A, B> p);   template <typename A, typename B, typename C>   string to_string(tuple<A, B, C> p);   template <typename A, typename B, typename C, typename D>   string to_string(tuple<A, B, C, D> p);   string to_string(const string& s) { return     + s +    ; }   string to_string(const char* s) { return to_string((string)s); }   string to_string(bool b) { return (b ?  true  :  false ); }   string to_string(vector<bool> v) {     bool first = true;     string res =  { ;     for (int i = 0; i < static_cast<int>(v.size()); i++) {       if (!first) {         res +=  ,  ;       }       first = false;       res += to_string(v[i]);     }     res +=  } ;     return res;   }   template <size_t N>   string to_string(bitset<N> v) {     string res =   ;     for (size_t i = 0; i < N; i++) {       res += static_cast<char>( 0  + v[i]);     }     return res;   }   template <typename A>   string to_string(A v) {     bool first = true;     string res =  { ;     for (const auto& x : v) {       if (!first) {         res +=  ,  ;       }       first = false;       res += to_string(x);     }     res +=  } ;     return res;   }   template <typename A, typename B>   string to_string(pair<A, B> p) {     return  (  + to_string(p.first) +  ,   + to_string(p.second) +  ) ;   }   template <typename A, typename B, typename C>   string to_string(tuple<A, B, C> p) {     return  (  + to_string(get<0>(p)) +  ,   + to_string(get<1>(p)) +  ,   +            to_string(get<2>(p)) +  ) ;   }   template <typename A, typename B, typename C, typename D>   string to_string(tuple<A, B, C, D> p) {     return  (  + to_string(get<0>(p)) +  ,   + to_string(get<1>(p)) +  ,   +            to_string(get<2>(p)) +  ,   + to_string(get<3>(p)) +  ) ;   }   void debug_out() { cerr << endl; }   template <typename Head, typename... Tail>   void debug_out(Head H, Tail... T) {     cerr <<     << to_string(H);     debug_out(T...);   }   template <typename T>   T inverse(T a, T m) {     T u = 0, v = 1;     while (a != 0) {       T t = m / a;       m -= t * a;       swap(a, m);       u -= t * v;       swap(u, v);     }     assert(m == 1);     return u;   }   template <typename T>   class Modular {    public:     using Type = typename decay<decltype(T::value)>::type;     constexpr Modular() : value() {}     template <typename U>     Modular(const U& x) {       value = normalize(x);     }     template <typename U>     static Type normalize(const U& x) {       Type v;       if (-mod() <= x && x < mod())         v = static_cast<Type>(x);       else         v = static_cast<Type>(x % mod());       if (v < 0) v += mod();       return v;     }     const Type& operator()() const { return value; }     template <typename U>     explicit operator U() const {       return static_cast<U>(value);     }     constexpr static Type mod() { return T::value; }     Modular& operator+=(const Modular& other) {       if ((value += other.value) >= mod()) value -= mod();       return *this;     }     Modular& operator-=(const Modular& other) {       if ((value -= other.value) < 0) value += mod();       return *this;     }     template <typename U>     Modular& operator+=(const U& other) {       return *this += Modular(other);     }     template <typename U>     Modular& operator-=(const U& other) {       return *this -= Modular(other);     }     Modular& operator++() { return *this += 1; }     Modular& operator--() { return *this -= 1; }     Modular operator++(int) {       Modular result(*this);       *this += 1;       return result;     }     Modular operator--(int) {       Modular result(*this);       *this -= 1;       return result;     }     Modular operator-() const { return Modular(-value); }     template <typename U = T>     typename enable_if<is_same<typename Modular<U>::Type, int>::value,                        Modular>::type&     operator*=(const Modular& rhs) {       value = normalize(static_cast<int64_t>(value) *                         static_cast<int64_t>(rhs.value));       return *this;     }     template <typename U = T>     typename enable_if<is_same<typename Modular<U>::Type, int64_t>::value,                        Modular>::type&     operator*=(const Modular& rhs) {       int64_t q = static_cast<int64_t>(static_cast<long double>(value) *                                        rhs.value / mod());       value = normalize(value * rhs.value - q * mod());       return *this;     }     template <typename U = T>     typename enable_if<!is_integral<typename Modular<U>::Type>::value,                        Modular>::type&     operator*=(const Modular& rhs) {       value = normalize(value * rhs.value);       return *this;     }     Modular& operator/=(const Modular& other) {       return *this *= Modular(inverse(other.value, mod()));     }     template <typename U>     friend const Modular<U>& abs(const Modular<U>& v) {       return v;     }     template <typename U>     friend bool operator==(const Modular<U>& lhs, const Modular<U>& rhs);     template <typename U>     friend bool operator<(const Modular<U>& lhs, const Modular<U>& rhs);     template <typename U>     friend std::istream& operator>>(std::istream& stream, Modular<U>& number);       private:     Type value;   };   template <typename T>   bool operator==(const Modular<T>& lhs, const Modular<T>& rhs) {     return lhs.value == rhs.value;   }   template <typename T, typename U>   bool operator==(const Modular<T>& lhs, U rhs) {     return lhs == Modular<T>(rhs);   }   template <typename T, typename U>   bool operator==(U lhs, const Modular<T>& rhs) {     return Modular<T>(lhs) == rhs;   }   template <typename T>   bool operator!=(const Modular<T>& lhs, const Modular<T>& rhs) {     return !(lhs == rhs);   }   template <typename T, typename U>   bool operator!=(const Modular<T>& lhs, U rhs) {     return !(lhs == rhs);   }   template <typename T, typename U>   bool operator!=(U lhs, const Modular<T>& rhs) {     return !(lhs == rhs);   }   template <typename T>   bool operator<(const Modular<T>& lhs, const Modular<T>& rhs) {     return lhs.value < rhs.value;   }   template <typename T>   Modular<T> operator+(const Modular<T>& lhs, const Modular<T>& rhs) {     return Modular<T>(lhs) += rhs;   }   template <typename T, typename U>   Modular<T> operator+(const Modular<T>& lhs, U rhs) {     return Modular<T>(lhs) += rhs;   }   template <typename T, typename U>   Modular<T> operator+(U lhs, const Modular<T>& rhs) {     return Modular<T>(lhs) += rhs;   }   template <typename T>   Modular<T> operator-(const Modular<T>& lhs, const Modular<T>& rhs) {     return Modular<T>(lhs) -= rhs;   }   template <typename T, typename U>   Modular<T> operator-(const Modular<T>& lhs, U rhs) {     return Modular<T>(lhs) -= rhs;   }   template <typename T, typename U>   Modular<T> operator-(U lhs, const Modular<T>& rhs) {     return Modular<T>(lhs) -= rhs;   }   template <typename T>   Modular<T> operator*(const Modular<T>& lhs, const Modular<T>& rhs) {     return Modular<T>(lhs) *= rhs;   }   template <typename T, typename U>   Modular<T> operator*(const Modular<T>& lhs, U rhs) {     return Modular<T>(lhs) *= rhs;   }   template <typename T, typename U>   Modular<T> operator*(U lhs, const Modular<T>& rhs) {     return Modular<T>(lhs) *= rhs;   }   template <typename T>   Modular<T> operator/(const Modular<T>& lhs, const Modular<T>& rhs) {     return Modular<T>(lhs) /= rhs;   }   template <typename T, typename U>   Modular<T> operator/(const Modular<T>& lhs, U rhs) {     return Modular<T>(lhs) /= rhs;   }   template <typename T, typename U>   Modular<T> operator/(U lhs, const Modular<T>& rhs) {     return Modular<T>(lhs) /= rhs;   }   template <typename T, typename U>   Modular<T> power(const Modular<T>& a, const U& b) {     assert(b >= 0);     Modular<T> x = a, res = 1;     U p = b;     while (p > 0) {       if (p & 1) res *= x;       x *= x;       p >>= 1;     }     return res;   }   template <typename T>   bool IsZero(const Modular<T>& number) {     return number() == 0;   }   template <typename T>   string to_string(const Modular<T>& number) {     return to_string(number());   }   template <typename T>   std::ostream& operator<<(std::ostream& stream, const Modular<T>& number) {     return stream << number();   }   template <typename T>   std::istream& operator>>(std::istream& stream, Modular<T>& number) {     typename common_type<typename Modular<T>::Type, int64_t>::type x;     stream >> x;     number.value = Modular<T>::normalize(x);     return stream;   }   constexpr int md = (int)1e9 + 7;   using Mint = Modular<std::integral_constant<decay<decltype(md)>::type, md>>;   vector<Mint> fact(1, 1);   vector<Mint> inv_fact(1, 1);   Mint C(int n, int k) {     if (k < 0 || k > n) {       return 0;     }     while ((int)fact.size() < n + 1) {       fact.push_back(fact.back() * (int)fact.size());       inv_fact.push_back(1 / fact.back());     }     return fact[n] * inv_fact[k] * inv_fact[n - k];   }   struct Point {     int x;     int y;     int c;   };   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n, k, L;     cin >> n >> k >> L;     vector<Point> p(n);     for (int i = 0; i < n; i++) {       cin >> p[i].x >> p[i].y >> p[i].c;       --p[i].c;     }     sort(p.begin(), p.end(),          [&](const Point& a, const Point& b) { return a.y < b.y; });     Mint c2 = Mint(L) * (L + 1) / 2;     auto C2 = [&](int x, int y) -> long long {       if (x >= y) {         return 0;       }       return ((long long)(y - x) * (y - x + 1)) >> 1;     };     Mint ans = 0;     for (int start = 0; start <= n - k; start++) {       int coeff = p[start].y - (start == 0 ? -1 : p[start - 1].y);       if (coeff == 0) {         continue;       }       vector<multiset<int>> s(k);       for (int i = 0; i < k; i++) {         s[i].insert(-1);         s[i].insert(L);       }       for (int i = start; i < n; i++) {         s[p[i].c].insert(p[i].x);       }       set<pair<int, int>> segs;       long long value = 0;       auto Modify = [&](set<pair<int, int>>::iterator it, int q) {         if (it != segs.begin()) {           value -= q * C2(it->first, abs(prev(it)->second));         }         if (next(it) != segs.end()) {           value -= q * C2(next(it)->first, abs(it->second));         }         if (it != segs.begin() && next(it) != segs.end()) {           value += q * C2(next(it)->first, abs(prev(it)->second));         }         value += q * C2(it->first, abs(it->second));       };       auto Erase = [&](set<pair<int, int>>::iterator it) {         Modify(it, -1);         segs.erase(it);       };       auto Add = [&](int from, int to) {         if (from >= to) {           return;         }         pair<int, int> seg = make_pair(from, -to);         auto it = segs.lower_bound(seg);         while (it != segs.end() && abs(it->second) <= to) {           Erase(it);           it = segs.lower_bound(seg);         }         if (it != segs.begin()) {           it = prev(it);           if (abs(it->second) >= to) {             return;           }         }         auto ret = segs.insert(seg);         assert(ret.second);         it = ret.first;         Modify(it, 1);       };       bool have_all = true;       for (int i = 0; i < k; i++) {         if (s[i].size() == 2) {           have_all = false;           break;         }         auto it = s[i].begin();         while (*it < L) {           int me = *it;           ++it;           int nxt = *it;           Add(me + 1, nxt);         }       }       if (!have_all) {         break;       }       for (int finish = n - 1; finish >= start; finish--) {         int coeff2 = (finish == n - 1 ? L : p[finish + 1].y) - p[finish].y;         ans += Mint(coeff) * coeff2 * (c2 - value);         int col = p[finish].c;         auto it = s[col].find(p[finish].x);         assert(it != s[col].end());         auto pr = prev(it);         auto nx = next(it);         Add((*pr) + 1, *nx);         s[col].erase(it);         if (value == c2) {           break;         }       }     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e5 + 5;   const int MOD = 1e9 + 7.5;   char s[MAXN];   int f[MAXN], n;   int main() {     scanf( %s , s + 1);     n = strlen(s + 1);     int preb = 0;     for (int i = 1; i <= n; ++i) {       f[i] = f[i - 1];       if (s[i] ==  a ) {         f[i] = (f[i] + f[preb] + 1) % MOD;       } else if (s[i] ==  b ) {         preb = i;       }     }     cout << f[n] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   namespace io {   void _(int &k) {     char c;     int e = 1;     k = 0;     while ((c = getchar()) >  9  || c <  0 )       if (c ==  - ) e = -1;     k = c -  0 ;     while ((c = getchar()) <=  9  && c >=  0 ) {       k *= 10;       k += c -  0 ;     }     k *= e;   }   void _(long long &k) {     char c;     int e = 1;     k = 0;     while ((c = getchar()) >  9  || c <  0 )       if (c ==  - ) e = -1;     k = c -  0 ;     while ((c = getchar()) <=  9  && c >=  0 ) {       k *= 10;       k += c -  0 ;     }     k *= e;   }   void _(char &c) {     while ((c = getchar()) ==     || c ==   n )       ;   }   void _(double &c) { scanf( %lf , &c); }   void _(char *s) {     char c;     while ((c = getchar()) != EOF && c !=     && c != 10) *s++ = c;   }   template <class t1, class t2>   void _(t1 &a, t2 &b) {     _(a);     _(b);   }   template <class t1, class t2, class t3>   void _(t1 &a, t2 &b, t3 &c) {     _(a);     _(b);     _(c);   }   template <class t1, class t2, class t3, class t4>   void _(t1 &a, t2 &b, t3 &c, t4 &d) {     _(a);     _(b);     _(c);     _(d);   }   template <class t1, class t2, class t3, class t4, class t5>   void _(t1 &a, t2 &b, t3 &c, t4 &d, t5 &e) {     _(a);     _(b);     _(c);     _(d);     _(e);   }   void _p(double k) { printf( %.6lf , k); }   void _p(char *c) {     for (; *c; putchar(*c++))       ;   }   void _p(const char *c) {     for (; *c; putchar(*c++))       ;   }   void _p(char c) { putchar(c); }   template <class T>   void _p0(T k) {     if (k >= 10) _p0(k / 10);     putchar(k % 10 +  0 );   }   template <class T>   void _p(T k) {     if (k < 0) {       putchar( - );       _p0(-k);     } else       _p0(k);   }   template <class T>   void __p(T k) {     _p(k);     putchar(   );   }   template <class T>   void _pn(T k) {     _p(k);     putchar(  n );   }   template <class t1, class t2>   void _p(t1 a, t2 b) {     __p(a);     _pn(b);   }   template <class t1, class t2, class t3>   void _p(t1 a, t2 b, t3 c) {     __p(a);     __p(b);     _pn(c);   }   template <class t1, class t2, class t3, class t4>   void _p(t1 a, t2 b, t3 c, t4 d) {     __p(a);     __p(b);     __p(c);     _pn(d);   }   template <class T>   void op(T *a, int n) {     int i;     n--;     for (i = 1; i <= n; i++) __p(a[i]);     _pn(a[n + 1]);   }   int gi() {     int first;     _(first);     return first;   }   long long gll() {     long long first;     _(first);     return first;   }   }  // namespace io   int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }   void fcl() {     fclose(stdin);     fclose(stdout);   }   void fop(const char *s) {     char c[256], d[256];     memset(c, 0, sizeof(c));     memset(d, 0, sizeof(d));     strcpy(c, s);     strcpy(d, s);     freopen(strcat(c,  .in ),  r , stdin);     freopen(strcat(d,  .out ),  w , stdout);   }   int eq(double a, double b) {     return a + 0.00000000001 >= b && b + 0.00000000001 >= a;   }   template <class T>   void _ma(T &a, T b) {     if (a < b) a = b;   }   template <class T>   void _mi(T &a, T b) {     if (a > b) a = b;   }   const int N = 1234567, EE = 100000000, GG = 1000000000, ima = 2147483647;   using namespace io;   int n, m, a[N], an, T, l, r;   const int p = 1000000007;   long long f[N][3];   int main() {     int i, j;     long long a0, a1, a2;     _(n, l, r);     a0 = r / 3 - (l - 1) / 3;     a1 = (r + 2) / 3 - (l + 1) / 3;     a2 = (r + 1) / 3 - l / 3;     f[0][0] = 1;     for (i = 1; i <= n; i++) {       f[i][0] = (f[i - 1][0] * a0 + f[i - 1][1] * a2 + f[i - 1][2] * a1) % p;       f[i][1] = (f[i - 1][0] * a1 + f[i - 1][1] * a0 + f[i - 1][2] * a2) % p;       f[i][2] = (f[i - 1][0] * a2 + f[i - 1][1] * a1 + f[i - 1][2] * a0) % p;     }     _pn(f[n][0]);   }


#include <bits/stdc++.h>   using namespace std;   int N, C, cnt;   int A[33], P[33];   double dp[33][33][222], sol;   inline int f(int l, int r, int i) {     if (i < l || i > r) return i;     int ret = i - l + 1;     int len = r - l + 1;     ret = len - ret + 1;     ret = l + ret - 1;     return ret;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout << setprecision(15) << fixed;     cin >> N >> C;     for (int I = 1; I <= N; I++) cin >> A[I];     for (int I = 1; I <= N; I++)       for (int K = I + 1; K <= N; K++) dp[I][K][0] = 1;     for (int c = 1; c <= C; c++) {       for (int I = 1; I <= N; I++) {         for (int K = 1; K <= N; K++) {           for (int l = 1; l <= N; l++) {             for (int r = l; r <= N; r++) {               int pi = f(l, r, I);               int pk = f(l, r, K);               dp[I][K][c] += dp[pi][pk][c - 1];             }           }           dp[I][K][c] /= (N * (N - 1) / 2) + N;         }       }     }     for (int I = 1; I <= N; I++)       for (int K = 1; K <= N; K++)         if (A[I] > A[K]) {           sol += dp[I][K][C];         }     cout << sol << endl;   }


#include <bits/stdc++.h>   const int inf = INT_MAX;   const int MAX = 1e6 + 8;   const long long MOD = 998244353;   const int TOT_PRIMES = 1e6 + 9;   const int MAX_A = 71;   const int LN = 20;   using namespace std;   vector<int> adj[MAX];   int vis[MAX];   long long c = 0;   void dfs(int u) {     vis[u] = 1;     c = c + 1;     for (auto v : adj[u]) {       if (!vis[v]) {         dfs(v);       }     }   }   int main() {     int n;     cin >> n;     for (int i = 1; i <= n; i++) {       int x;       cin >> x;       adj[i].push_back(x);       adj[x].push_back(i);     }     vector<long long> res;     for (int i = 1; i <= n; i++) {       if (!vis[i]) {         dfs(i);         res.push_back(c);         c = 0;       }     }     sort(res.begin(), res.end());     long long ans = 0;     int m = res.size();     if (m == 1) {       cout << res[0] * res[0];       return 0;     }     ans = res[m - 1] + res[m - 2];     ans = ans * ans;     for (int i = 0; i < m - 2; i++) {       ans = ans + (res[i] * res[i]);     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O2 )   using namespace std;   long long mod = 1000000007;   void solve() {     long long n;     cin >> n;     long long a[n];     long long k0 = 0;     long long k1 = 0;     for (long long i = 0; i < n; i++) {       cin >> a[i];       if (a[i] == 0) k0++;       if (a[i] == 1) k1++;     }     long long ans = k1 * (pow(2, k0));     cout << ans << endl;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long t;     cin >> t;     while (t--) solve();   }


#include <bits/stdc++.h>   const long long inf = std::numeric_limits<long long>::max();   const int infint = std::numeric_limits<int>::max();   const long long mod = 1e9 + 7;   using namespace std;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   vector<int> g[500100];   long long a[500100];   long long par[500100][21];   void dfs(int v, int p) {     for (auto i : g[v]) {       if (i == p) continue;       dfs(i, v);       par[i][0] = v;     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     long long mn = inf;     for (int i = 0; i < n; i++) {       cin >> a[i];       mn = min(a[i], mn);     }     for (int i = 0; i < n - 1; i++) {       int x, y;       cin >> x >> y;       x--, y--;       g[x].push_back(y);       g[y].push_back(x);     }     for (int i = 0; i < n; i++) {       if (a[i] == mn) {         par[i][0] = i;         dfs(i, -1);         break;       }     }     long long w = 0;     for (int i = 1; i < 21; i++)       for (int j = 0; j < n; j++) par[j][i] = par[par[j][i - 1]][i - 1];     for (int i = 0; i < n; i++) {       if (a[i] == mn) continue;       long long now = inf;       for (int j = 0; j < 21; j++) {         now = min(now, a[par[i][j]] * (j + 1) + a[i]);       }       w += now;     }     cout << w;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename _T>   void read(_T &x) {     _T f = 1;     x = 0;     char s = getchar();     while (s >  9  || s <  0 ) {       if (s ==  - ) f = -1;       s = getchar();     }     while ( 0  <= s && s <=  9 ) {       x = (x << 3) + (x << 1) + (s ^ 48);       s = getchar();     }     x *= f;   }   struct ming {     long long typ, t, x, id, pos;   } a[100010];   long long n, ans[100010], num[100010];   vector<long long> vec;   long long cmp1(const ming &a, const ming &b) { return a.t < b.t; }   long long cmp2(const ming &a, const ming &b) { return a.id < b.id; }   void merge(long long l, long long r) {     if (l == r) return;     long long mid = l + r >> 1, j = l;     merge(l, mid);     merge(mid + 1, r);     sort(a + l, a + mid + 1, cmp1);     sort(a + mid + 1, a + r + 1, cmp1);     for (long long i = mid + 1; i <= r; i++) {       while (j <= mid && a[j].t <= a[i].t) num[a[j].pos] += a[j].typ, j++;       if (!a[i].typ) ans[a[i].id] += num[a[i].pos];     }     for (long long i = l; i < j; i++) num[a[i].pos] -= a[i].typ;   }   signed main() {     read(n);     for (long long i = 1; i <= n; i++) {       read(a[i].typ);       read(a[i].t);       read(a[i].x);       if (a[i].typ == 2) a[i].typ = -1;       if (a[i].typ == 3) a[i].typ = 0;       a[i].id = i;       vec.push_back(a[i].x);     }     sort(vec.begin(), vec.end());     vec.erase(unique(vec.begin(), vec.end()), vec.end());     for (long long i = 1; i <= n; i++)       a[i].pos = lower_bound(vec.begin(), vec.end(), a[i].x) - vec.begin() + 1;     merge(1, n);     sort(a + 1, a + n + 1, cmp2);     for (long long i = 1; i <= n; i++)       if (!a[i].typ) printf( %lld n , ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     int x1, y1, x2, y2;     cin >> n;     long long ans = 0;     for (int i = 1; i <= n; i++) {       cin >> x1 >> y1 >> x2 >> y2;       ans += (long long)(x2 - x1 + 1) * (y2 - y1 + 1);     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e13, Mo = 998244353;   const int N = 1000000;   const double eps = 1e-6;   namespace slow_IO {   long long read() {     long long x = 0;     int zf = 1;     char ch = getchar();     while (ch !=  -  && (ch <  0  || ch >  9 )) ch = getchar();     if (ch ==  - ) zf = -1, ch = getchar();     while (ch >=  0  && ch <=  9 ) x = x * 10 + ch -  0 , ch = getchar();     return x * zf;   }   void write(long long y) {     if (y < 0) putchar( - ), y = -y;     if (y > 9) write(y / 10);     putchar(y % 10 +  0 );   }   }  // namespace slow_IO   using namespace slow_IO;   vector<int> E1[N + 5], E2[N + 5];   int Flag1[N + 5], Flag2[N + 5];   int Ans[N + 5];   int ans = 0;   int main() {     int n = read(), m = read();     for (int i = (1); i <= (m); i++) {       int x = read(), y = read();       E1[x].push_back(y);       E2[y].push_back(x);     }     for (int i = (1); i <= (n); i++)       if (!Flag1[i]) {         Flag1[i] = Flag2[i] = 1;         for (int j = (0); j < (E1[i].size()); j++) Flag1[E1[i][j]] = 1;       }     for (int i = (n); i >= (1); i--)       if (Flag2[i]) {         for (int j = (0); j < (E2[i].size()); j++)           if (Flag2[E2[i][j]]) Flag2[i] = 0;       }     for (int i = (1); i <= (n); i++)       if (Flag2[i]) Ans[++ans] = i;     printf( %d n , ans);     for (int i = (1); i <= (ans); i++)       printf( %d%c , Ans[i], i == ans ?   n  :    );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 109;   int n;   int a[N];   map<int, int> m;   set<int> s[2];   int main() {     int n;     cin >> n;     for (int i = 0; i < n; ++i) {       cin >> a[i];       m[a[i]]++;     }     int pos = 0;     for (auto p : m)       if (p.second == 1) {         s[pos].insert(p.first);         pos = 1 - pos;       }     if (s[0].size() == s[1].size()) {       string res(n,  A );       for (int i = 0; i < n; ++i)         if (s[1].count(a[i])) res[i] =  B ;       cout <<  YES  << endl;       for (auto c : res) cout << c;       cout << endl;       return 0;     } else {       assert(int(s[0].size()) - 1 == int(s[1].size()));       string res(n,  A );       for (int i = 0; i < n; ++i)         if (s[1].count(a[i])) res[i] =  B ;       int id = -1;       for (auto p : m)         if (p.second >= 3) {           id = p.first;           break;         }       if (id == -1) {         cout <<  NO  << endl;         return 0;       }       bool flag = false;       for (int i = 0; i < n; ++i) {         if (a[i] == id)           if (!flag) {             flag = true;             res[i] =  B ;           }       }       cout <<  YES  << endl;       for (auto c : res) cout << c;       cout << endl;       return 0;     }     return 0;   }


#include <bits/stdc++.h>   bool comp(const int& a, const int& b) { return a < b ? false : true; }   using namespace std;   int main() {     long long int k, a, b, m, n;     cin >> k >> m >> n;     a = max(m, n);     b = min(m, n);     long long int ans = 0;     if (a > 0 && b > 0) {       ans = a / k - (b - 1) / k;     } else if (a < 0 && b < 0) {       ans = abs(b) / k - (abs(a) - 1) / k;     } else {       ans = abs(a) / k;       ans += (abs(b)) / k;       ans += 1;     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cout << setprecision(10);     ;     int n;     cin >> n;     vector<int> deg(n);     int ones = 0;     vector<int> others, ops;     long long total = 0;     for (int i = 0; i < (int)n; i++) {       cin >> deg[i];       if (deg[i] == 1) {         ones++;         ops.push_back(i);       } else {         total += deg[i];         others.push_back(i);       }     }     if (total - (n - ones - 1) * 2 < ones) return cout <<  NO n , 0;     vector<pair<int, int>> edges;     if (others.size() == 0 && ops.size() == 2) {       cout <<  YES 1 n ;       cout <<  1 n ;       cout << ops[0] + 1 <<     << ops[1] + 1 <<   n ;       return 0;     }     for (int i = 1; i < (int)others.size(); i++) {       edges.push_back({others[i - 1], others[i]});     }     int opptr = 0;     if (others.size() == 1) {       for (int i = 0; i < (int)ops.size(); i++)         edges.push_back({ops[i], others[0]});     } else {       if (opptr < (int)ops.size()) edges.push_back({ops[opptr++], others[0]});       if (opptr < (int)ops.size()) edges.push_back({ops[opptr++], others.back()});       for (int i = 0; i < (int)deg[others[0]] - 2; i++) {         if (opptr >= (int)ops.size()) break;         edges.push_back({ops[opptr++], others[0]});       }       for (int i = 0; i < (int)deg[others.back()] - 2; i++) {         if (opptr >= (int)ops.size()) break;         edges.push_back({ops[opptr++], others.back()});       }     }     for (int i = 1; i < (int)others.size() - 1; i++) {       int av = deg[others[i]] - 2;       while (opptr < (int)ops.size() && av > 0) {         edges.push_back({others[i], ops[opptr++]});         av--;       }     }     cout <<  YES   << (others.size() - 1 + (ops.size() > 0) + (ops.size() > 1))          <<   n ;     cout << edges.size() <<   n ;     for (int i = 0; i < (int)edges.size(); i++)       cout << (edges[i].first + 1) <<     << edges[i].second + 1 <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1.0);   int dx[] = {1, -1, 0, 0, -1, 1, -1, 1};   int dy[] = {0, 0, 1, -1, -1, -1, 1, 1};   void file() {}   int main() {     cout << setprecision(20) << fixed;     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int k;     cin >> k;     int x = 0;     for (int i = 2; i <= 2000; i++) {       long long s = k + i;       if (ceil(s / (double(i - 1))) <= 1e6) {         x = i;         break;       }     }     if (!x) return cout << -1 <<   n , 0;     cout << x <<   n ;     cout <<  -1  ;     long long s = k + x;     long long rem = s % (x - 1);     long long num = s / (x - 1);     for (int i = 0; i < x - 1; i++)       if (rem)         cout << num + 1 <<    , rem--;       else         cout << num <<    ;     cout <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline void read(T &x) {     x = 0;     bool w = 1;     char c = getchar();     while (!isdigit(c)) {       if (c ==  - ) w = 0;       c = getchar();     }     while (isdigit(c)) {       x = x * 10 + c -  0 ;       c = getchar();     }     x = w ? x : -x;   }   const long long N = 1e5 + 10, Mod = 1e9 + 7;   long long n, m, a[N], lg[N], b[N], f[N], c[N], sum[N], d[N], ans[N];   struct en {     long long l, r, id;     bool operator<(const en &x) const { return r < x.r; }   } q[N];   inline long long Get(long long x) { return f[x] ? f[x] = Get(f[x]) : x; }   inline long long ji(long long x, long long y) {     return (b[x] - b[y + 1] * lg[y - x + 1] % Mod + Mod) % Mod;   }   inline void add(long long x, long long y) {     f[x] = y;     c[y] = c[x];     if ((x - c[x] > 30 && sum[y] > 9) || (sum[x] + (sum[y] << x - c[x])) > Mod)       sum[y] = Mod;     else       sum[y] = sum[x] + (sum[y] << x - c[x]);   }   signed main() {     read(n), read(m);     lg[0] = 1;     for (long long i = 1; i <= n; i++)       read(a[i]), sum[i] = a[i], lg[i] = (lg[i - 1] << 1) % Mod, c[i] = i - 1;     for (long long i = 1; i <= m; i++) read(q[i].l), read(q[i].r), q[i].id = i;     for (long long i = n; i >= 1; i--)       b[i] = ((b[i + 1] << 1) + a[i] + Mod) % Mod;     sort(q + 1, q + m + 1);     long long k = 1;     for (long long i = 1; i <= n; i++) {       while (sum[i] >= 0 && c[i]) add(c[i], i);       d[i] = (d[c[i]] + (ji(c[i] + 1, i) << 1) % Mod + Mod) % Mod;       while (q[k].r == i) {         long long x = Get(q[k].l);         ans[q[k].id] = (d[i] - d[x] + ji(q[k].l, x) + Mod) % Mod;         k++;       }     }     for (long long i = 1; i <= m; i++) printf( %lld n , ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long read() {     char ch = getchar();     long long x = 0, ff = 1;     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) ff = -ff;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) x = x * 10 + ch -  0 , ch = getchar();     return x * ff;   }   void write(long long aa) {     if (aa < 0) putchar( - ), aa = -aa;     if (aa > 9) write(aa / 10);     putchar(aa % 10 +  0 );     return;   }   long long n;   long long a[200005];   long long tt[800005], tts[800005], lz[800005];   void up(long long rt) {     tt[rt] = min(tt[rt << 1], tt[rt << 1 | 1]);     if (tt[rt << 1] >= tt[rt << 1 | 1])       tts[rt] = tts[rt << 1 | 1];     else       tts[rt] = tts[rt << 1];     return;   }   void bt(long long rt, long long ll, long long rr) {     if (ll == rr) {       tt[rt] = read(), tts[rt] = ll;       return;     }     long long mid = (ll + rr) >> 1;     bt(rt << 1, ll, mid);     bt(rt << 1 | 1, mid + 1, rr);     up(rt);     return;   }   void push(long long rt) {     if (!lz[rt]) return;     tt[rt << 1] += lz[rt];     tt[rt << 1 | 1] += lz[rt];     lz[rt << 1] += lz[rt];     lz[rt << 1 | 1] += lz[rt];     lz[rt] = 0;     return;   }   void update(long long rt, long long ll, long long rr, long long L, long long R,               long long kk) {     if (ll == L && rr == R) {       tt[rt] += kk;       lz[rt] += kk;       return;     }     long long mid = (ll + rr) >> 1;     push(rt);     if (R <= mid)       update(rt << 1, ll, mid, L, R, kk);     else if (L > mid)       update(rt << 1 | 1, mid + 1, rr, L, R, kk);     else       update(rt << 1, ll, mid, L, mid, kk),           update(rt << 1 | 1, mid + 1, rr, mid + 1, R, kk);     up(rt);     return;   }   int main() {     n = read();     bt(1, 1, n);     for (long long i = 1; i <= n; ++i) {       long long now = tts[1];       a[now] = i;       update(1, 1, n, now, now, n * n);       if (now < n) update(1, 1, n, now + 1, n, -i);     }     for (long long i = 1; i <= n; ++i, putchar(   )) write(a[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int k;     scanf( %d , &k);     if (k % 2 == 1) {       printf( -1 n );       return 0;     }     char a[k][k];     memset(a, 0, sizeof(a));     for (int layer = 0; layer < k / 2; layer++) {       char c;       if (layer % 2)         c =  w ;       else         c =  b ;       for (int runner = layer; runner < k - layer; runner++)         a[runner][layer] = a[layer][runner] = a[runner][k - layer - 1] =             a[k - layer - 1][runner] = c;     }     for (int i = 0; i < k; i++)       for (int j = 0; j < k; j++) {         for (int l = 0; l < k; l++)           if (i % 2)             if (a[j][l] ==  w )               printf( b );             else               printf( w );           else             printf( %c , a[j][l]);         printf(  n );       }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string a, s;     cin >> a;     cin >> s;     long la = 0, ls = 0, i = 0, ps = 0, pv = 0;     la = a.length();     ls = s.length();     vector<int> v;     for (i = 0; i < ls; i++) v.push_back(s[i]);     sort(v.rbegin(), v.rend());     while (ps < la && pv < ls) {       if (a[ps] < v[pv]) {         a[ps] = v[pv];         ps++;         pv++;       } else if (a[ps] >= v[pv])         ps++;     }     cout << a;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, k;   int n1;   vector<long long> v;   int c[20];   int a[20];   bool viz[20];   int f[20];   inline void get(int i) {     int cif = 0;     long long zece = 1;     long long r = 0;     for (zece = 1; i > 0; i >>= 1, zece *= 10LL) {       ++cif;       if ((i & 1) != 0)         r += 7LL * zece;       else         r += 4LL * zece;     }     if (r != 0LL) v.push_back(r);     for (++cif; cif < 11; ++cif, zece *= 10LL) {       r += 4LL * zece;       v.push_back(r);     }   }   void back(int k1) {     if (k1 == n1 + 1) return;     for (int i = 1; i <= n1; ++i) {       if (viz[i]) continue;       if (k > f[n1 - k1])         k -= f[n1 - k1];       else {         viz[i] = true;         a[k1] = i;         back(k1 + 1);         return;       }     }     printf( -1 n );     exit(0);   }   int main() {     scanf( %d%d , &n, &k);     for (int i = 0; i < 1024; ++i) {       get(i);     }     sort(v.begin(), v.end());     int start = max(1, n - 12);     f[0] = f[1] = 1;     for (int i = 2; i < 13; ++i) f[i] = f[i - 1] * i;     n1 = n - start + 1;     back(1);     int rez = 0;     long long start1 = (long long)start;     for (size_t i = 0, lim = v.size(); i < lim && v[i] < start1; ++i) {       ++rez;     }     int x = start;     for (int i = 1; i <= n1; ++i, ++x) {       c[i] = x;     }     for (int i = 1; i <= n1; ++i) {       if (find(v.begin(), v.end(), (long long)(i - 1) + start1) != v.end() &&           find(v.begin(), v.end(), (long long)c[a[i]]) != v.end())         ++rez;     }     printf( %d n , rez);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c, d, i, j, e, ar[105];     scanf( %d , &a);     while (a--) {       scanf( %d , &b);       if (b == 1) {         scanf( %d , &c);         if (c % 2 == 0)           printf( 1 n1 n );         else           printf( -1 n );       } else {         e = -1;         for (i = 1; i <= b; i++) {           scanf( %d , &ar[i]);         }         for (i = 1; i <= b; i++) {           if (ar[i] % 2 == 0) {             d = 1;             break;           }           if (e != -1) {             d = 2;             break;           }           if (e == -1) e = i;         }         printf( %d n , d);         if (d == 1)           printf( %d n , i);         else           printf( %d %d n , e, i);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   double mn = 1e20, mx, t;   int n, low, high;   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> t;       mn = min(mn, (t + 1 - 1e-8) / i);       mx = max(mx, t / i);     }     n++;     low = (int)(n * mx + 1e-9), high = (int)(n * mn + 1 - 1e-9);     if (low + 1 == high)       cout <<  unique n  << low;     else       cout <<  not unique ;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     string s;     cin >> s;     int arr[26] = {};     int n = s.length();     int count = 0;     for (int i = 0; i < n; i++) {       arr[s[i] -  a ]++;       if (arr[s[i] -  a ] == 2) {         arr[s[i] -  a ] = 0;         count--;       } else         count++;     }     if (count == 0 || count == 1) {       cout <<  First             <<   n ;     } else {       if (count % 2 == 0) {         cout <<  Second               <<   n ;       } else         cout <<  First               <<   n ;     }   }   int main() {     long long t = 1;     while (t--) solve();   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 400100;   vector<int> grafo[MAXN];   int a[MAXN], b[MAXN];   pair<int, int> p[MAXN];   int q[MAXN];   bool vis[MAXN];   int n;   vector<int> vec;   void dfs(int x) {     vis[x] = true;     vec.push_back(x);     if (x > n)       vis[x - n] = true;     else       vis[x + n] = true;     for (int i = 0; i < grafo[x].size(); i++) {       int at = grafo[x][i];       if (vis[at] == true) continue;       dfs(at);     }   }   int main() {     int t;     cin >> t;     while (t--) {       cin >> n;       vec.clear();       for (int i = 1; i <= 2 * n; i++) {         p[i] = {0, 0};         grafo[i].clear();         q[i] = 0;         vis[i] = false;         a[i] = b[i] = 0;       }       for (int i = 1; i <= n; i++) {         int x;         cin >> x;         a[x] = i;         q[x]++;         if (p[x].first == 0)           p[x].first = i;         else           p[x].second = i;       }       for (int i = 1; i <= n; i++) {         int x;         cin >> x;         b[x] = i;         q[x]++;         if (p[x].first == 0)           p[x].first = i;         else           p[x].second = i;       }       bool f = true;       for (int i = 1; i <= n; i++)         if (q[i] != 2) f = false;       if (f == false) {         cout << -1 << endl;         continue;       }       for (int i = 1; i <= n; i++) {         int p1 = p[i].first, p2 = p[i].second;         if (a[i] > 0 && b[i] > 0) {           grafo[p1].push_back(p2);           grafo[p2].push_back(p1);           grafo[p1 + n].push_back(p2 + n);           grafo[p2 + n].push_back(p1 + n);         } else {           grafo[p1].push_back(p2 + n);           grafo[p2].push_back(p1 + n);           grafo[p2 + n].push_back(p1);           grafo[p1 + n].push_back(p2);         }       }       vector<int> resp;       for (int i = 1; i <= n; i++) {         if (vis[i] == true) continue;         vec.clear();         dfs(i);         int h = vec.size();         int cnt = 0;         for (int j = 0; j < vec.size(); j++) {           int at = vec[j];           if (at > n) cnt++;         }         if (cnt < h - cnt) {           for (int j = 0; j < vec.size(); j++)             if (vec[j] > n) resp.push_back(vec[j] - n);         } else {           for (int j = 0; j < vec.size(); j++)             if (vec[j] <= n) resp.push_back(vec[j]);         }       }       cout << resp.size() << endl;       for (int i = 0; i < resp.size(); i++) cout << resp[i] <<    ;       cout << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   int read() {     int s = 0;     char c = getchar(), lc =  + ;     while (c <  0  ||  9  < c) lc = c, c = getchar();     while ( 0  <= c && c <=  9 ) s = s * 10 + c -  0 , c = getchar();     return lc ==  -  ? -s : s;   }   void write(int x) {     if (x < 0) {       putchar( - );       x = -x;     }     if (x < 10)       putchar(x +  0 );     else {       write(x / 10);       putchar(x % 10 +  0 );     }   }   void print(int x, char c =   n ) {     write(x);     putchar(c);   }   void L(int x) {     putchar( L );     putchar(   );     print(x);   }   void R(int x) {     putchar( R );     putchar(   );     print(x);   }   char a[N];   signed main() {     scanf( %s , a + 1);     int n = strlen(a + 1);     print(4);     L(2);     L(2);     R(2);     R(n + 2 + n - 1);     return 0;   }


#include <bits/stdc++.h>   int n, m, k, s, a[1000000], b[1000000];   int amin[1000000];   int bmin[1000000];   struct Gadget {     long long cost;     int id;     Gadget(long long cost, int id) : cost(cost), id(id) {}     bool operator<(const Gadget &other) const { return cost < other.cost; }   };   int main() {     scanf( %d %d %d %d , &n, &m, &k, &s);     for (int i = 0; i < n; i++) {       scanf( %d , &a[i]);       amin[i] = i;       if (i > 0 && a[amin[i - 1]] < a[i]) amin[i] = amin[i - 1];     }     for (int i = 0; i < n; i++) {       scanf( %d , &b[i]);       bmin[i] = i;       if (i > 0 && b[bmin[i - 1]] < b[i]) bmin[i] = bmin[i - 1];     }     long long asum, bsum;     std::vector<Gadget> d, p;     for (int i = 0; i < m; i++) {       int t, c;       scanf( %d %d , &t, &c);       if (t == 1)         d.push_back(Gadget(c, i + 1));       else         p.push_back(Gadget(c, i + 1));     }     d.push_back(Gadget(0, 0));     p.push_back(Gadget(0, 0));     std::sort(d.begin(), d.end());     std::sort(p.begin(), p.end());     for (int i = 1; i < d.size(); i++) d[i].cost += d[i - 1].cost;     for (int i = 1; i < p.size(); i++) p[i].cost += p[i - 1].cost;     int day_ans = n;     int d_ans = 0, p_ans = 0;     for (int i = 0; i <= std::min(k, (int)d.size() - 1); i++) {       int j = k - i;       if (j >= p.size()) continue;       int left = 0, right = day_ans - 1;       while (left <= right) {         int mid = (left + right) >> 1;         long long cost = d[i].cost * a[amin[mid]] + p[j].cost * b[bmin[mid]];         if (cost <= s) {           if (mid < day_ans) {             day_ans = mid;             d_ans = i;             p_ans = j;           }           right = mid - 1;         } else {           left = mid + 1;         }       }     }     if (day_ans == n) {       puts( -1 );       return 0;     }     printf( %d n , day_ans + 1);     for (int i = 1; i <= d_ans; i++) {       printf( %d %d n , d[i].id, amin[day_ans] + 1);     }     for (int i = 1; i <= p_ans; i++) {       printf( %d %d n , p[i].id, bmin[day_ans] + 1);     }   }


#include <bits/stdc++.h>   using namespace std;   int to1[1000010], w[1000010], begin1[1000010], next1[1000010], v[1000010],       p[1000010], d[1000010], e;   void add(int x, int y, int z) {     to1[++e] = y;     next1[e] = begin1[x];     begin1[x] = e;     w[e] = z;   }   void ins(int x) {     int i;     for (i = 30; i >= 0; i--)       if ((x >> i) & 1) {         if (!p[i]) {           p[i] = x;           break;         }         x ^= p[i];       }   }   void dfs(int x, int now) {     int i;     d[x] = now;     v[x] = 1;     for (i = begin1[x]; i; i = next1[i]) {       if (!v[to1[i]])         dfs(to1[i], now ^ w[i]);       else         ins(now ^ w[i] ^ d[to1[i]]);     }   }   int find(int x) {     int i;     for (i = 30; i >= 0; i--)       if ((p[i] ^ x) < x) x = p[i] ^ x;     return x;   }   int main() {     int i, u, v, w, n, m;     scanf( %d%d , &n, &m);     for (i = 1; i <= m; i++) {       scanf( %d%d%d , &u, &v, &w);       add(u, v, w);       add(v, u, w);     }     dfs(1, 0);     printf( %d n , find(d[n]));   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 1000000000;   const long long INF = 1LL * inf * inf;   const double eps = 1e-9;   const int md = (int)1e9 + 7;   const double EPS = 1e-7;   const long long maxll = numeric_limits<long long>::max();   const double PI = acos(-1.0);   template <typename name>   inline name sqr(name x) {     return x * x;   }   inline long long multmod(long long a, long long b, long long md) {     if (!a) return 0;     if (a % 2 == 1)       return (multmod(a - 1, b, md) + b) % md;     else       return sqr<long long>(multmod(a / 2, b, md)) % md;   }   template <typename name>   inline name bpow(name base, long long exp) {     name res = base;     while (exp) {       if (exp % 2 == 1) {         res = res * base;       }       base = base * base;       exp /= 2;     }     return res;   }   int n, x, m;   double p[2000];   struct matr {     double a[1 << 7][1 << 7];   } mat, qq;   const matr& operator*(const matr& x, const matr& y) {     for (int i = 0; i < (1 << 7); i++)       for (int j = 0; j < (1 << 7); j++) qq.a[i][j] = 0;     for (int i = 0; i < (1 << 7); i++)       for (int j = 0; j < (1 << 7); j++)         for (int k = 0; k < (1 << 7); k++) qq.a[i][j] += x.a[i][k] * y.a[k][j];     return qq;   }   int main() {     ios_base ::sync_with_stdio(0);     cin >> n >> x;     for (int i = 0; i <= x; i++) cin >> p[i];     for (int mask1 = 0; mask1 < (1 << 7); mask1++)       for (int mask2 = 0; mask2 < (1 << 7); mask2++)         mat.a[mask1][mask2] = p[mask1 ^ mask2];     mat = bpow(mat, n - 1);     cout << fixed << setprecision(10) << 1 - mat.a[0][0];     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     long long n, k;     cin >> n >> k;     string ans =   ;     for (long long i = 0; i < n; i++) {       ans.push_back( a );     }     for (long long i = n - 2; i >= 0; i--) {       if (k <= n - i - 1) {         ans[i] =  b ;         ans[n - k] =  b ;         break;       }       k -= (n - i - 1);     }     cout << ans << endl;   }   int main() {     int t;     cin >> t;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t, a, b, c, d, x, y, x1, x2, y1, y2;     scanf( %d , &t);     while (t--) {       scanf( %d%d%d%d , &a, &b, &c, &d);       int t1 = a - b;       int t2 = c - d;       scanf( %d%d%d%d%d%d , &x, &y, &x1, &y1, &x2, &y2);       if (x - t1 >= x1 && x - t1 <= x2 && y - t2 >= y1 && y - t2 <= y2) {         if ((a > 0 || b > 0) && x1 == x2)           printf( NO n );         else if ((c > 0 || d > 0) && y1 == y2)           printf( NO n );         else           printf( YES n );       } else         printf( NO n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0), cout.tie(0);     cin.tie(0), cout.tie(0);     ;     long long int a, b, t, n, m, k, i, j, l, sum = 0, sum1 = 0, ans = 0;     vector<long long int> v;     cin >> n;     for (i = 0; i < n; i++) {       cin >> a;       v.push_back(a);       if (i & 1) {         sum1 += a;       } else         sum += a;     }     ans = max(sum1, sum);     for (i = 0; i < n; i++) {       if (i & 1) {         sum1 -= v[i];         sum += v[i];       } else {         sum -= v[i];         sum1 += v[i];       }       ans = max(ans, max(sum, sum1));     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long a, b, c;     cin >> a;     b = a - 1;     c = a - 2;     if (a >= 3) {       if (b % 2 != 0) {         if (a % 3 == 0) {           long long e = a * b * c / 2;           long long r = a * b * (c - 1) / 3;           long long t = a * b * (c - 2) / 2;           long long y = a * b * (c - 3);           long long h = (a - 1) * (b - 1) * (c - 1);           cout << max(max(max(e, r), max(t, y)), h);         } else {           c--;           cout << a * b * c;         }       } else {         cout << a * b * c;       }     } else {       b = 1;       c = 1;       cout << a * b * c;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int h;   int edge[5000];   int extend[5000];   int maximum;   int v[5000];   bool flag = 0;   void dfs_m(int p, int value) {     v[p] = value;     if (edge[p * 2] != 0)       dfs_m(p * 2 + 0, value + edge[p * 2]);     else {       if (maximum < value) maximum = value;     }     if (edge[p * 2 + 1] != 0)       dfs_m(p * 2 + 1, value + edge[p * 2 + 1]);     else {       if (maximum < value) maximum = value;     }   }   void dfs(int p, int value) {     if (edge[p * 2] != 0) {       dfs(p * 2, value + edge[p * 2] + extend[p * 2]);     } else {       if (value < maximum) {         extend[p] += (maximum - value);       }     }     if (edge[p * 2 + 1] != 0) {       dfs(p * 2 + 1, value + edge[p * 2 + 1] + extend[p * 2 + 1]);     } else {       if (value < maximum) {         extend[p] += (maximum - value);       }     }   }   int min(int a, int b) {     if (a == b) return -1;     if (a < b) {       return a;     }     return b;   }   void merge(int n) {     if (extend[n * 2] != 0 && extend[n * 2 + 1] != 0) {       int m = min(extend[n * 2 + 1], extend[n * 2]);       flag = false;       if (m == -1) {         extend[n] += extend[n * 2 + 1];         extend[n * 2] = extend[n * 2 + 1] = 0;         merge(n / 2);       } else {         extend[n] += m;         extend[n * 2] -= m;         extend[n * 2 + 1] -= m;         merge(n / 2);       }     }   }   int main() {     scanf( %d , &h);     int e = pow(2, h + 1) - 2;     memset(edge, 0, sizeof(edge));     memset(extend, 0, sizeof(extend));     memset(v, 0, sizeof(v));     for (int i = 2; i <= e + 1; i++) {       scanf( %d , &edge[i]);     }     maximum = 0;     dfs_m(1, 0);     dfs(1, 0);     int node = pow(2, h + 1);     for (int i = 2; i <= e + 1; i++) {       extend[i] /= 2;     }     while (true) {       flag = true;       for (int i = 0; i < node; i++) {         merge(i);       }       for (int i = 2; i <= e + 1; i++) {       }       if (flag) {         break;       }     }     int ans = 0;     for (int i = 0; i <= e + 1; i++) {       ans += extend[i];     }     printf( %d , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   map<pair<long long int, long long int>, int> m;   long long int comb(long long int n, long long int r) {     int k1, k2;     if (m[make_pair(n, r)] != 0) return m[make_pair(n, r)];     if (r > n) return 0;     if (n == r) return 1;     if (r == 0) return 1;     if (r == 1) return n;     k1 = comb(n - 1, r - 1);     k2 = comb(n - 1, r);     m[make_pair(n - 1, r - 1)] = k1;     m[make_pair(n - 1, r)] = k2;     return k1 + k2;   }   int main() {     long long int n, m, t, k1 = 0, k2 = 0, k3 = 0, sum = 0, i = 0, x, y;     cin >> n >> m >> t;     if ((n + m) < t) cout << 0;     if (n < 4 || m < 1) cout << 0;     for (x = 4; x <= t - 1; x++) {       if (m >= (t - x)) sum += (comb(n, x) * comb(m, t - x));     }     cout << sum;   }


#include <bits/stdc++.h>   using namespace std;   int a[123], p[123];   signed main() {     int t;     scanf( %d , &t);     while (t--) {       int n, m;       scanf( %d %d , &n, &m);       memset(p, 0, sizeof(p));       for (int i = 1; i <= n; ++i) scanf( %d , a + i);       for (int i = 1, x; i <= m; ++i) scanf( %d , &x), p[x] = 1;       bool ok = 1;       for (int i = 1; i <= n; ++i)         for (int j = i + 1; j <= n; ++j) {           if (!ok) break;           if (a[i] > a[j])             for (int k = i; k < j; ++k)               if (!p[k]) {                 ok = 0;                 break;               }         }       ok ? puts( YES ) : puts( NO );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long fac[3000060];   void pre() {     fac[0] = 1;     for (int i = 1; i < 3000060; i++) fac[i] = fac[i - 1] * i % 1000000007;   }   long long powermod(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;   }   long long nCrmod(long long n, long long r, long long p) {     if (r == 0) return 1;     return (fac[n] * powermod(fac[r], p - 2, p) % p *             powermod(fac[n - r], p - 2, p) % p) %            p;   }   void solve() {     long long n;     cin >> n;     long long use[n][n];     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         cin >> use[i][j];       }     }     for (int i = 0; i < n; i++) {       long long p = (use[i][(i + 1) % n] * use[i][(i + 2) % n]) /                     use[(i + 1) % n][(i + 2) % n];       p = sqrt(p);       cout << p <<    ;     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long t;     t = 1;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long inf = 1e18;   vector<long long> a;   map<long long, bool> p;   int binp(long long x) {     int l = 0, r = 1e9 + 1;     while (r - l > 1) {       int m = (l + r) / 2;       if (1LL * m * m <= x)         l = m;       else         r = m;     }     return l;   }   int main() {     a.push_back(0);     for (long long i = 2; i <= 1000000; ++i) {       long long cur = i * i * i;       while (inf / i >= cur) {         long long x = binp(cur);         if (!p[cur] && x * x != cur) a.push_back(cur);         p[cur] = 1;         cur *= i;       }       long long x = binp(cur);       if (!p[cur] && x * x != cur) a.push_back(cur);       p[cur] = 1;     }     sort(a.begin(), a.end());     int t;     scanf( %d , &t);     while (t--) {       long long l, r;       scanf( %lld %lld , &l, &r);       long long ans = upper_bound(a.begin(), a.end(), r) -                       upper_bound(a.begin(), a.end(), l - 1);       ans += binp(r) - binp(l - 1);       printf( %lld n , ans);     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC optimize( unroll-loops )   #pragma GCC target(         sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native )   void read(int &a) {     a = 0;     char c = getchar();     while (c <  0  || c >  9 ) {       c = getchar();     }     while (c >=  0  && c <=  9 ) {       a = (a << 1) + (a << 3) + (c ^ 48);       c = getchar();     }   }   const int Maxn = 50000;   const int Inf = 0x3f3f3f3f;   int n, q;   int a[Maxn + 5];   int fa[Maxn + 5];   int head[Maxn + 5], arrive[Maxn + 5], nxt[Maxn + 5], tot;   void add_edge(int from, int to) {     arrive[++tot] = to;     nxt[tot] = head[from];     head[from] = tot;   }   int dep[Maxn + 5], dis[Maxn + 5];   int dfn[Maxn + 5], right[Maxn + 5], rnk[Maxn + 5], dfn_tot, sz[Maxn + 5];   int sum[Maxn + 5];   long long f[Maxn + 5];   void init_dfs(int u) {     dep[u] = dep[fa[u]] + 1;     if (a[u] != 1) {       dfn[u] = ++dfn_tot;       dis[dfn_tot] = dep[u];       rnk[dfn_tot] = u;       sz[u] = 1;       sum[u] = 0;     } else {       dfn[u] = dfn_tot + 1;       sz[u] = 0;       sum[u] = 1;     }     for (int i = head[u]; i; i = nxt[i]) {       int v = arrive[i];       init_dfs(v);       sz[u] += sz[v];       sum[u] += sum[v];       f[u] += f[v];       f[u] += sum[v];     }     right[u] = dfn[u] + sz[u] - 1;   }   int del[Maxn + 5];   int main() {     read(n), read(q);     for (register int i = 1; i <= n; ++i) {       read(a[i]);       del[i] = -Inf;     }     for (register int i = 2; i <= n; ++i) {       read(fa[i]);       add_edge(fa[i], i);     }     init_dfs(1);     for (register int i = 1; i <= q; ++i) {       int u;       read(u);       long long ans_1 = 0;       int ans_2 = 0;       for (register int j = dfn[u]; j <= right[u]; ++j) {         int tmp = (i >= del[j]);         ans_1 += dis[j] * tmp;         ans_2 += tmp;         del[j] = (tmp ? i + a[rnk[j]] : del[j]);       }       ans_1 -= 1ll * ans_2 * dep[u];       ans_1 += f[u], ans_2 += sum[u];       printf( %lld %d n , ans_1, ans_2);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   long long sum[1505][1505];   long long ans[1505];   long long t[1505];   int main() {     int i, j, x;     long long val, now, res;     scanf( %d%d , &n, &m);     for (i = 1; i <= n; i++)       for (j = 1; j <= m; j++)         scanf( %I64d , &val), sum[i][j] = sum[i][j - 1] + val;     for (i = 1; i <= m; i++) ans[i] = sum[1][i];     for (i = 2; i <= n; i++) {       if (i % 2 == 0) {         now = -(long long)1e15;         for (x = m; x > 0; x--) {           t[x] = now + sum[i][x];           now = max(now, ans[x]);         }       } else {         now = -(long long)1e15;         for (x = 1; x <= m; x++) {           t[x] = now + sum[i][x];           now = max(now, ans[x]);         }       }       for (x = 1; x <= m; x++) ans[x] = t[x];     }     res = -(long long)1e15;     for (x = 1; x <= m; x++) res = max(res, ans[x]);     printf( %I64d , res);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, m, a[105], cnt = 0, i;     fill_n(a, 105, 0);     for (cin >> m >> n; n; n /= m) a[cnt++] = n % m;     if (cnt > 100) {       cout <<  NO ;       return 0;     }     for (i = 0; i < 105; ++i) {       if (a[i] <= 1)         continue;       else if (a[i] < m - 1) {         cout <<  NO ;         return 0;       } else         ++a[i + 1];     }     cout <<  YES ;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100 * 1000 + 10, M = 300 + 10;   int a[N], dp[N][M];   vector<int> p[N];   int main() {     ios_base::sync_with_stdio(false);     int n, m, s, e;     cin >> n >> m >> s >> e;     for (int i = (0); i <= (n - 1); i++) cin >> a[i];     for (int i = (1); i <= (m); i++) {       int x;       cin >> x;       p[x].emplace_back(i);     }     int ans = 0;     for (int i = (0); i <= (s / e); i++) dp[0][i] = i * (m + 1);     for (int i = (1); i <= (n); i++) {       for (int j = (1); j <= (s / e); j++) {         auto it = upper_bound((p[a[i - 1]]).begin(), (p[a[i - 1]]).end(),                               (j == 1 ? 0 : dp[i - 1][j - 1]));         dp[i][j] = dp[i - 1][j];         if (it != p[a[i - 1]].end()) {           dp[i][j] = min(dp[i][j], *it);           if (s - e * j >= i + dp[i][j]) ans = max(ans, j);         }       }     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct Node {     int val;     int op;     int cl;     Node(int x, int y, int z) {       val = x;       op = y;       cl = z;     }     Node() { Node(0, 0, 0); };   };   string s;   vector<Node> ST;   Node temp;   int n, t, x, y, t1, t2;   void update(int root, int l, int r, int pos) {     if (l > pos || r < pos) return;     if (l == r) {       if (s[pos - 1] ==  ( ) ST[root].op = 1;       if (s[pos - 1] ==  ) ) ST[root].cl = 1;       return;     }     int mid = (l + r) / 2;     update(root * 2, l, mid, pos);     update(root * 2 + 1, mid + 1, r, pos);     ST[root].val = ST[root * 2].val + ST[root * 2 + 1].val +                    min(ST[root * 2].op - ST[root * 2].val,                        ST[root * 2 + 1].cl - ST[root * 2 + 1].val);     ST[root].op = ST[root * 2].op + ST[root * 2 + 1].op;     ST[root].cl = ST[root * 2].cl + ST[root * 2 + 1].cl;   }   Node get(int root, int l, int r, int u, int v) {     if (u > r || v < l) return Node(0, 0, 0);     if (u == l && v == r) return ST[root];     int mid = (l + r) / 2;     if (v <= mid)       return get(root * 2, l, mid, u, v);     else if (u > mid)       return get(root * 2 + 1, mid + 1, r, u, v);     else {       Node n1 = get(root * 2, l, mid, u, mid),            n2 = get(root * 2 + 1, mid + 1, r, mid + 1, v);       int t1 = n1.val + n2.val + min(n1.op - n1.val, n2.cl - n2.val);       return Node(t1, n1.op + n2.op, n1.cl + n2.cl);     }   }   int main() {     cin >> s;     n = s.size();     for (int i = 0; i < 4 * n; ++i) ST.push_back(Node(0, 0, 0));     for (int i = 1; i <= n; ++i) update(1, 1, n, i);     cin >> t;     while (t--) {       cin >> x >> y;       cout << get(1, 1, n, x, y).val * 2 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     int i, j, t, n, a[150], b[150], sum1 = 0, sum2 = 0;     cin >> n;     for (i = 1; i <= n; i++) {       cin >> a[i];     }     for (i = 1; i <= n; i++) {       cin >> b[i];     }     for (i = 1; i <= n; i++) {       if (a[i] && !b[i]) sum1++;       if (!a[i] && b[i]) sum2++;     }     if (sum1 == 0) {       cout <<  -1  <<   n ;     } else if (sum1 > sum2) {       cout << 1 <<   n ;     } else {       int k = sum2 / sum1;       k++;       cout << k <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, pos, l, r, diff, rflag = 1, lflag = 1;     cin >> n >> pos >> l >> r;     diff = r - l;     if (l == 1) lflag = 0;     if (r == n) rflag = 0;     if (lflag == 0 && rflag == 0)       cout << 0;     else if (lflag == 0)       cout << abs(r - pos) + 1;     else if (rflag == 0)       cout << abs(pos - l) + 1;     else       cout << diff + min(abs(r - pos), abs(pos - l)) + 2;   }


#include <bits/stdc++.h>   using namespace std;   double maxoo(double, double);   int main() {     int p1, p2, t1, t2;     cin >> p1 >> p2 >> t1 >> t2;     double p11, p12, p21, p22, misha, vasya;     p11 = (3 * p1) / 10;     p12 = (p1 - (p1 / 250) * t1);     p21 = (3 * p2) / 10;     p22 = p2 - (p2 / 250) * t2;     misha = maxoo(p11, p12);     vasya = maxoo(p21, p22);     if (misha > vasya)       cout <<  Misha ;     else if (misha == vasya)       cout <<  Tie ;     else if (misha < vasya)       cout <<  Vasya ;     return 0;   }   double maxoo(double m, double n) {     if (m >= n)       return m;     else       return n;   }


#include <bits/stdc++.h>   using namespace std;   struct SuffixArray {     char* T;     int n;     vector<int> RA, tempRA;     vector<int> SA, tempSA, c;     vector<int> phi, pLCP, LCP;     SuffixArray(string& t) {       n = t.length();       T = new char[n + n];       for (int i = 0; i < n; T[i] = t[i], i++)         ;       T[n++] =  # , T[n] =   0 ;       c.resize(max(300, n));       RA.resize(n), tempRA.resize(n);       SA.resize(n), tempSA.resize(n);     }     void countingSort(int k) {       fill(c.begin(), c.end(), 0);       for (int i = 0; i < n; i++) c[i + k < n ? RA[i + k] : 0]++;       for (int i = 0, sum = 0, lim = max(300, n); i < lim; i++) {         int t = c[i];         c[i] = sum, sum += t;       }       for (int i = 0; i < n; i++)         tempSA[c[SA[i] + k < n ? RA[SA[i] + k] : 0]++] = SA[i];       for (int i = 0; i < n; i++) SA[i] = tempSA[i];     }     void buildSA() {       for (int i = 0; i < n; SA[i] = i, i++)         ;       for (int i = 0; i < n; RA[i] = T[i], i++)         ;       for (int k = 1, r; k < n; k <<= 1) {         countingSort(k);         countingSort(0);         tempRA[SA[0]] = r = 0;         for (int i = 1; i < n; i++) {           tempRA[SA[i]] =               (RA[SA[i]] == RA[SA[i - 1]] and RA[SA[i] + k] == RA[SA[i - 1] + k]                    ? r                    : ++r);         }         for (int i = 0; i < n; RA[i] = tempRA[i], i++)           ;         if (RA[SA[n - 1]] == n - 1) break;       }     }     void computeLCP() {       phi.resize(n), pLCP.resize(n), LCP.resize(n);       phi[SA[0]] = -1;       for (int i = 1; i < n; phi[SA[i]] = SA[i - 1], i++)         ;       for (int i = 0, L = 0; i < n; i++) {         if (phi[i] == -1) {           pLCP[i] = 0;           continue;         }         for (; T[i + L] == T[phi[i] + L]; L++)           ;         pLCP[i] = L;         L = max(0, L - 1);       }       for (int i = 0; i < n; LCP[i] = pLCP[SA[i]], i++)         ;     }     void print() {       for (int i = 0; i + 1 < n; i++) {         printf( %2d t%2d t%s n , SA[i], LCP[i], T + SA[i]);       }     }   };   struct Node {     int sum, lft, rgt;     Node() : sum(0), lft(0), rgt(0) {}   };   struct PersistantSegmentTree {     int avail;     vector<int> roots;     vector<Node> tree;     PersistantSegmentTree(int n) {       avail = 0;       roots.resize(n + 10, 0);       tree.resize(n * 30, Node());     }     int update(int last, int l, int r, int p) {       int cur = ++avail;       tree[cur] = tree[last];       if (l == r) {         tree[cur].sum++;         return cur;       }       int mid = l + (r - l) / 2;       if (p <= mid)         tree[cur].lft = update(tree[last].lft, l, mid, p);       else         tree[cur].rgt = update(tree[last].rgt, mid + 1, r, p);       tree[cur].sum = tree[tree[cur].lft].sum + tree[tree[cur].rgt].sum;       return cur;     }     int query(int cur, int l, int r, int L, int R) {       if (l > R or r < L or L > R) return 0;       if (l >= L and r <= R) return tree[cur].sum;       int mid = l + (r - l) / 2;       int pp = query(tree[cur].lft, l, mid, L, R);       int qq = query(tree[cur].rgt, mid + 1, r, L, R);       return pp + qq;     }   };   int main() {     ios_base ::sync_with_stdio(0);     cin.tie(0), cout.tie(0);     int n;     string s;     cin >> n >> s;     SuffixArray SA(s);     SA.buildSA();     SA.computeLCP();     PersistantSegmentTree PSG(SA.n);     vector<int> have;     for (int i = n - 1; i >= 0; i--) {       if (s[i] ==  ) ) {         have.push_back(i);         continue;       }       if (!have.empty()) {         PSG.roots[i] =             PSG.update(PSG.roots[have.back() + 1], 0, SA.n, have.back());         have.pop_back();       }     }     long long res = 0;     for (int i = 1; i < SA.n; i++) {       if (s[SA.SA[i]] ==  ) ) continue;       int L = SA.SA[i];       int R = L + SA.LCP[i] - 1;       int add = PSG.query(PSG.roots[L], 0, SA.n, L, SA.n);       int bad = PSG.query(PSG.roots[L], 0, SA.n, L, R);       res += (0, max(0, add - bad));     }     cout << res <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   long long sum[500];   int deep[500];   int in1[500];   int out1[500];   int in2[500];   int out2[500];   vector<int> maps1[500];   vector<int> maps2[500];   long long dp[150000];   long long n, m, t;   int cnt = 0;   void topo2() {     queue<int> q;     for (int i = 1; i <= n; ++i)       if (in2[i] == 0) {         q.push(i);         deep[i] = 0;       }     int n1, n2;     while (!q.empty()) {       n1 = q.front();       q.pop();       cnt++;       t -= deep[n1] * sum[n1];       for (int i = 0; i < maps2[n1].size(); ++i) {         n2 = maps2[n1][i];         in2[n2]--;         deep[n2] = max(deep[n2], deep[n1] + 1);         if (in2[n2] == 0) q.push(n2);       }     }   }   void topo1() {     queue<int> q;     int n1, n2;     for (int i = 1; i <= n; ++i)       if (in1[i] == 0) {         q.push(i);       }     while (!q.empty()) {       n1 = q.front();       q.pop();       for (int i = 0; i < maps1[n1].size(); ++i) {         n2 = maps1[n1][i];         in1[n2]--;         sum[n2] += sum[n1];         if (in1[n2] == 0) {           q.push(n2);         }       }     }   }   int main() {     scanf( %lld%lld%lld , &n, &m, &t);     for (int i = 1; i <= n; ++i) scanf( %lld , &sum[i]);     for (int i = 1; i <= m; ++i) {       int x, y;       scanf( %d%d , &x, &y);       maps1[x].push_back(y);       in1[y]++;       out1[x]++;       maps2[y].push_back(x);       in2[x]++;       out2[y]++;     }     topo2();     if (t < 0 || cnt != n)       printf( 0 n );     else {       topo1();       memset(dp, 0, sizeof(dp));       dp[0] = 1;       for (long long i = 1; i <= n; ++i) {         for (long long j = sum[i]; j <= t; ++j) {           dp[j] += dp[j - sum[i]];           dp[j] %= 1000000007;         }       }       printf( %lld n , dp[t]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int wyn[1024];   int odp[1024];   int n;   int pyt;   vector<pair<int, int> > v[2];   void pytaj(vector<int>& skad, vector<int>& gdzie) {     if (skad.size() == 0) return;     printf( %d n , int(skad.size()));     for (int i = 0; i < skad.size(); i++) printf( %d  , skad[i] + 1);     printf(  n );     fflush(stdout);     for (int i = 0; i < n; i++) scanf( %d , &odp[i]);     pyt++;     for (int q = 0; q < gdzie.size(); q++) {       int i = gdzie[q];       wyn[i] = min(wyn[i], odp[i]);     }   }   int main() {     pyt = 0;     scanf( %d , &n);     for (int i = 0; i < n; i++) wyn[i] = 1000000010;     v[0].push_back(make_pair(0, n - 1));     int akt = 0;     while (!v[akt].empty()) {       v[1 - akt].clear();       vector<int> pyt1, pyt2;       for (int k = 0; k < v[akt].size(); k++) {         int a = v[akt][k].first;         int b = v[akt][k].second;         int sr = (a + b) / 2;         for (int q = a; q <= sr; q++) pyt1.push_back(q);         for (int q = sr + 1; q <= b; q++) pyt2.push_back(q);         if (sr > a) v[1 - akt].push_back(make_pair(a, sr));         if (b > sr + 1) v[1 - akt].push_back(make_pair(sr + 1, b));       }       pytaj(pyt1, pyt2);       pytaj(pyt2, pyt1);       akt = 1 - akt;     }     printf( -1 n );     for (int i = 0; i < n; i++) printf( %d  , wyn[i]);     printf(  n );     fflush(stdout);   }


#include <bits/stdc++.h>   using namespace std;   int main(void) {     int n;     cin >> n;     if (n == 0) {       cout << 1 << endl;       return 0;     }     vector<double> p(n);     vector<int> powers(n, 1);     vector<double> curval(n);     using pdi = pair<double, int>;     priority_queue<pdi, vector<pdi>> q;     double prob = 1.0;     for (int i = 0; i < n; ++i) {       cin >> p[i];       p[i] /= 100.0;       prob *= p[i];       curval[i] = p[i];       q.push(pdi((1 - pow(1 - p[i], powers[i] + 1)) / curval[i], i));     }     double result = n + 1 - prob;     for (int i = 0; i < 500000; ++i) {       auto c = q.top();       q.pop();       prob /= curval[c.second];       ++powers[c.second];       curval[c.second] = 1 - pow(1 - p[c.second], powers[c.second]);       prob *= curval[c.second];       q.push(           pdi((1 - pow(1 - p[c.second], powers[c.second] + 1)) / curval[c.second],               c.second));       result += 1 - prob;     }     cout << fixed << setprecision(20) << result << endl;   }


// Problem: A. Robot Program   // Contest: Codeforces - Educational Codeforces Round 98 (Rated for Div. 2)   // URL: https://codeforces.com/contest/1452/problem/A   // Memory Limit: 256 MB   // Time Limit: 2000 ms   // Powered by CP Editor (https://github.com/cpeditor/cpeditor)      #include <bits/stdc++.h>      using namespace std;      #define fi first   #define se second   #define pb push_back   #define int long long   #define F(i, n) for (int i = 0; i < n; i++)   #define all(x)(x).begin(), (x).end()      using ld = long double;   using vi = vector <int>;   using mi = map <int, int>;   using pii = pair <int, int>;      const int N = 100005;   const int MOD = 1e9 + 7;      #define show(arr) { for (auto x: arr) cout << x <<    ; cout <<   n ; }   #define show_(arr, n) F(i, n) show(arr[i])      void solve() {    int n; cin>>n;    int a[n],sum=0,mx=0;    F(i,n){     cin>>a[i];     sum+=a[i];     mx=max(mx,a[i]);    }    cout<<max((n-1)*((sum+n-2)/(n-1)),mx*(n-1))-sum<<  n ;   }   int32_t main() {      ios::sync_with_stdio(false);      cin.tie(0);      cout.tie(0);         int32_t t=1;      cin >> t;      while (t--) solve();         return 0;   }


#include <bits/stdc++.h>   using namespace std;   using namespace std;   int k;   string ad;   vector<string> c(string s) {     vector<string> ans;     int last = 0;     for (long long i = 0; i < (s.size()); i++) {       if (s[i] ==     || s[i] ==  -  || i == s.size() - 1) {         ans.push_back(s.substr(last, i - last + 1));         last = i + 1;       }     }     return ans;   }   vector<string> v;   bool check(int mid) {     int nlen = 0;     int cnt = 1;     for (long long i = 0; i < (v.size()); i++) {       if (v[i].size() > mid) {         return false;       }       if (nlen + v[i].size() <= mid) {         nlen += v[i].size();       } else {         nlen = v[i].size();         cnt++;       }     }     if (cnt <= k) {       return true;     }     return false;   }   int main() {     cin >> k;     cin.ignore();     getline(cin, ad,   n );     v = c(ad);     int l = 0, r = ad.size();     while (l < r) {       int mid = (l + r) >> 1;       if (!check(mid)) {         l = mid + 1;       } else {         r = mid;       }     }     cout << r;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize(2)   #pragma GCC optimize(3)   #pragma GCC optimize( Ofast )   #pragma GCC optimize( inline )   #pragma GCC optimize( -fgcse )   #pragma GCC optimize( -fgcse-lm )   #pragma GCC optimize( -fipa-sra )   #pragma GCC optimize( -ftree-pre )   #pragma GCC optimize( -ftree-vrp )   #pragma GCC optimize( -fpeephole2 )   #pragma GCC optimize( -ffast-math )   #pragma GCC optimize( -fsched-spec )   #pragma GCC optimize( unroll-loops )   #pragma GCC optimize( -falign-jumps )   #pragma GCC optimize( -falign-loops )   #pragma GCC optimize( -falign-labels )   #pragma GCC optimize( -fdevirtualize )   #pragma GCC optimize( -fcaller-saves )   #pragma GCC optimize( -fcrossjumping )   #pragma GCC optimize( -fthread-jumps )   #pragma GCC optimize( -funroll-loops )   #pragma GCC optimize( -fwhole-program )   #pragma GCC optimize( -freorder-blocks )   #pragma GCC optimize( -fschedule-insns )   #pragma GCC optimize( inline-functions )   #pragma GCC optimize( -ftree-tail-merge )   #pragma GCC optimize( -fschedule-insns2 )   #pragma GCC optimize( -fstrict-aliasing )   #pragma GCC optimize( -fstrict-overflow )   #pragma GCC optimize( -falign-functions )   #pragma GCC optimize( -fcse-skip-blocks )   #pragma GCC optimize( -fcse-follow-jumps )   #pragma GCC optimize( -fsched-interblock )   #pragma GCC optimize( -fpartial-inlining )   #pragma GCC optimize( no-stack-protector )   #pragma GCC optimize( -freorder-functions )   #pragma GCC optimize( -findirect-inlining )   #pragma GCC optimize( -frerun-cse-after-loop )   #pragma GCC optimize( inline-small-functions )   #pragma GCC optimize( -finline-small-functions )   #pragma GCC optimize( -ftree-switch-conversion )   #pragma GCC optimize( -foptimize-sibling-calls )   #pragma GCC optimize( -fexpensive-optimizations )   #pragma GCC optimize( -funsafe-loop-optimizations )   #pragma GCC optimize( inline-functions-called-once )   #pragma GCC optimize( -fdelete-null-pointer-checks )   using namespace std;   inline long long read() {     long long x = 0, y = 0, c = getchar();     while (!isdigit(c)) y = c, c = getchar();     while (isdigit(c)) x = (x << 1) + (x << 3) + (c ^  0 ), c = getchar();     return y ==  -  ? -x : x;   }   inline void print(long long q) {     if (q < 0) putchar( - ), q = -q;     if (q >= 10) print(q / 10);     putchar(q % 10 +  0 );   }   int n, m, k;   struct edge {     int fr, to, val, id;     bool fg;   } e[1000010];   int f[1000010];   inline int getf(int q) { return f[q] == q ? q : f[q] = getf(f[q]); }   inline bool operator<(edge q, edge w) {     return q.val == w.val ? q.fg < w.fg : q.val < w.val;   }   inline bool cmp(edge q, edge w) {     return q.val == w.val ? q.fg > w.fg : q.val < w.val;   }   int as[1000010], ft;   bool usd[1000010];   inline int work() {     int i, as = 0, as2 = 0;     sort(e + 1, e + m + 1);     for (i = 1; i <= n; ++i) f[i] = i;     for (i = 1; i <= m; ++i)       if (getf(e[i].fr) != getf(e[i].to)) {         f[f[e[i].fr]] = f[e[i].to];         as += e[i].fg;         ++as2;       }     return as2 != n - 1 ? -1 : as;   }   int main() {     int i, j, l, r, mid, ans;     n = read();     m = read();     k = read();     for (i = 1; i <= m; ++i) {       e[i].fr = read();       e[i].to = read();       e[i].val = read();       e[i].id = i;       e[i].fg = (e[i].fr == 1 || e[i].to == 1);     }     l = -1e6;     r = 1e6;     ans = l - 1;     while (l <= r) {       mid = l + r >> 1;       for (i = 1; i <= m; ++i)         if (e[i].fg) e[i].val -= mid;       int tmp = work();       if (tmp == -1) {         puts( -1 );         return 0;       }       if (tmp <= k)         ans = mid, l = mid + 1;       else         r = mid - 1;       for (i = 1; i <= m; ++i)         if (e[i].fg) e[i].val += mid;     }     if (ans == -1e6 - 1) {       puts( -1 );       return 0;     }     int tp = 0;     for (i = 1; i <= m; ++i)       if (e[i].fg) e[i].val -= ans;     sort(e + 1, e + m + 1);     for (i = 1; i <= n; ++i) f[i] = i;     for (i = 1; i <= m; ++i)       if (getf(e[i].fr) != getf(e[i].to)) {         f[f[e[i].fr]] = f[e[i].to];         if (e[i].fg) usd[e[i].id] = 1, as[++ft] = e[i].id, ++tp;       }     if (tp > k) {       puts( -1 );       return 0;     }     for (i = 1; i <= n; ++i) f[i] = i;     for (i = 1; i <= m; ++i)       if (usd[e[i].id]) f[getf(e[i].fr)] = getf(e[i].to);     sort(e + 1, e + m + 1, cmp);     for (i = 1; i <= m; ++i)       if (!usd[e[i].id] && getf(e[i].fr) != getf(e[i].to)) {         if (e[i].fg && tp == k) continue;         f[f[e[i].fr]] = f[e[i].to];         as[++ft] = e[i].id;         tp += e[i].fg;       }     if (tp < k) {       puts( -1 );       return 0;     }     print(ft);     putchar(  n );     for (i = 1; i <= ft; ++i) print(as[i]), putchar(   );     return 0;   }