#include <bits/stdc++.h>   using namespace std;   long long int mypow(long long int a, long long int b) {     long long int res = 1;     while (b) {       if (b & 1) res = res * a;       b >>= 1;       if (b) {         a = a * a;       }     }     return res;   }   long long int modpow(long long int a, long long int b,                        long long int m = 1000000007) {     a %= m;     long long int res = 1;     while (b) {       if (b & 1) res = res * a % m;       b >>= 1;       if (b) {         a = a * a % m;       }     }     return res;   }   long long int modinv(long long int a) {     return modpow(a, 1000000007 - 2, 1000000007);   }   vector<long long int> power(11);   void computepower() {     vector<int> p = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31};     for (int(i) = (0); (i) < (p.size()); ++(i)) {       power[i] = modpow(2, p[i]) - 1;     }   }   vector<long long int> powerof2(60);   void computepower2() {     powerof2[0] = 1;     for (int(i) = (1); (i) < (60); ++(i)) {       powerof2[i] = powerof2[i - 1] * 2;     }   }   vector<long long int> modinvr(100005);   void computemodinvr() {     modinvr[0] = modinvr[1] = 1;     for (int i = 2; i < 100005; i++)       modinvr[i] =           modinvr[1000000007 % i] * (1000000007 - 1000000007 / i) % 1000000007;   }   vector<long long int> modinvrfact(100005);   vector<long long int> factr(100005);   void computeodinvrfact() {     factr[0] = 1;     modinvrfact[0] = 1;     for (int(i) = (1); (i) < (100005); ++(i)) {       factr[i] = (factr[i - 1] * i) % 1000000007;       modinvrfact[i] = modinv(factr[i]) % 1000000007;     }   }   bool mycompr(pair<int, int> i1, pair<int, int> i2) {     return i1.second > i2.second;   }   void unique_elem(vector<long long int> &v) {     sort(v.begin(), v.end());     auto ip = unique(v.begin(), v.end());     v.resize(distance(v.begin(), ip));   }   void unique_elem_with_count(vector<long long int> &a,                               vector<long long int> &unique,                               vector<long long int> &cnt_unique,                               vector<long long int> &sum_unique, int n) {     sort(a.begin(), a.end());     long long int j = 0;     long long int sum = 0;     while (j < n) {       long long int cnt = 1;       if (j != n - 1) {         while (a[j + 1] == a[j]) {           cnt++;           j++;           if (j == n - 1) {             break;           }         }       }       sum += cnt;       unique.push_back(a[j]);       cnt_unique.push_back(cnt);       sum_unique.push_back(sum);       j++;     }   }   void bfs(int root, int par, vector<bool> &vis, vector<long long int> &dist,            vector<vector<int> > &adj) {     queue<int> q;     q.push(root);     dist[root] = 0;     vis[root] = true;     while (!q.empty()) {       int p = q.front();       q.pop();       for (int i = 0; i < adj[p].size(); i++) {         if (vis[adj[p][i]] == false) {           dist[adj[p][i]] = dist[p] + 1;           q.push(adj[p][i]);           vis[adj[p][i]] = true;         }       }     }   }   void bfs_tree(int p, int par, vector<vector<long long int> > &adj,                 vector<long long int> &ways, vector<long long int> &dist) {     for (int i = 0; i < adj[p].size(); i++) {       if (adj[p][i] == par) {         continue;       }       bfs_tree(adj[p][i], p, adj, ways, dist);     }   }   void graph(vector<vector<long long int> > &adj, long long int m) {     long long int x, y;     for (int(i) = (0); (i) < (m); ++(i)) {       cin >> x >> y;       adj[x].push_back(y);       adj[y].push_back(x);     }   }   void decToBinary(int n, vector<int> &binaryNum) {     binaryNum.resize(32, 0);     int i = 0;     while (n > 0) {       binaryNum[i] = n % 2;       n = n / 2;       i++;     }   }   long long int Binarytodec(string &st) {     computepower2();     long long int len = st.size();     long long int num = 0;     for (int(i) = (0); (i) < (st.size()); ++(i)) {       if (st[i] ==  1 ) {         num += powerof2[len - i - 1];       }     }     return num;   }   vector<int> spf(1000005);   void sieve() {     spf[1] = 1;     for (int i = 2; i < 1000005; i++) spf[i] = i;     for (int i = 4; i < 1000005; i += 2) spf[i] = 2;     for (int i = 3; i * i < 1000005; i++) {       if (spf[i] == i) {         for (int j = i * i; j < 1000005; j += i) {           if (spf[j] == j) {             spf[j] = i;           }         }       }     }   }   vector<int> getFactorization(int x) {     vector<int> ret;     map<int, int> fact;     while (x != 1) {       ret.push_back(spf[x]);       if (fact.find(spf[x]) == fact.end()) {         fact[spf[x]] = 1;       } else {         fact[spf[x]]++;       }       x = x / spf[x];     }     for (auto it = fact.begin(); it != fact.end(); it++) {       if (it->second & 1) {         ret.push_back(it->first);       }     }     return ret;   }   bool containsOnlyDigit(string str) {     int l = str.length();     for (int i = 0; i < l; i++) {       if (str.at(i) <  0  || str.at(i) >  9 ) return false;     }     return true;   }   void solve() {     long long int n, m, l, q, k;     cin >> n;     vector<pair<long long int, long long int> > a(n);     vector<long long int> f1(n);     vector<long long int> f2(n), f3(n), f4(n);     for (int(i) = (0); (i) < (n); ++(i)) {       cin >> a[i].first >> a[i].second >> f1[i] >> f2[i] >> f3[i] >> f4[i];     }     long long int x1 = -1e5;     long long int y1 = -1e5;     long long int x2 = 1e5;     long long int y2 = 1e5;     for (int(i) = (0); (i) < (n); ++(i)) {       if (f1[i] == 0) {         if (x2 < a[i].first) {           cout << 0 <<   n ;           return;         } else {           x1 = max(x1, a[i].first);         }       }       if (f2[i] == 0) {         if (y1 > a[i].second) {           cout << 0 <<   n ;           return;         } else {           y2 = min(y2, a[i].second);         }       }       if (f3[i] == 0) {         if (x1 > a[i].first) {           cout << 0 <<   n ;           return;         } else {           x2 = min(x2, a[i].first);         }       }       if (f4[i] == 0) {         if (y2 < a[i].second) {           cout << 0 <<   n ;           return;         } else {           y1 = max(y1, a[i].second);         }       }     }     cout << 1 <<     << x1 <<     << y1 <<   n ;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t = 1;     cin >> t;     int tt = 1;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   unordered_map<int, int> Task;   unordered_map<int, int> Idle;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int N, K;     cin >> N >> K;     for (int i = 1; i <= N; i++) {       int val;       cin >> val;       Task[val]++;       Idle[i] = val;     }     priority_queue<pair<int, int>, vector<pair<int, int> >,                    greater<pair<int, int> > >         Cost;     for (int i = 1; i <= N; i++) {       int val;       cin >> val;       if (Task[Idle[i]] == 1) continue;       Cost.push(make_pair(val, i));     }     long long int Ans = 0;     for (int i = 1; i <= K; i++) {       if (Task[i] == 0) {         while (!Cost.empty()) {           pair<int, int> u = Cost.top();           Cost.pop();           if (Task[Idle[u.second]] > 1) {             Task[Idle[u.second]]--;             Ans += u.first;             Task[i]++;             break;           }         }       }     }     cout << Ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, x, y, u, v, a[1010], b[1010][1010];   vector<int> vv;   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < n; ++i) {       scanf( %d%d , &x, &y);       a[y]++;       b[x][y]++;     }     for (int i = 0; i < m; ++i) {       scanf( %d%d , &x, &y);       if (a[y] && b[x][y]) {         ++u;         --a[y];         ++v;         --b[x][y];       } else         vv.push_back(y);     }     for (int i = 0; i < (int)vv.size(); ++i)       if (a[vv[i]]) ++u, --a[vv[i]];     printf( %d %d , u, v);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double pi = 3.14159265358979323846;   void rw() {}   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     string s, r;     long long n, c = 0;     cin >> n >> s;     for (int i = 0; i < n - 1; i++) {       if (s[i] == s[i + 1])         c++, s[i] =  0 ;       else         i++;     }     cout << ((n - c) % 2 ? c + 1 : c);     for (int i = 0; i < n; i++)       if (s[i] !=  0 ) r += s[i];     if ((n - c) % 2) r.erase(r.size() - 1);     cout <<   n  << r;     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /stack:200000000 )   #pragma GCC optimize(2)   #pragma G++ optimize(2)   using namespace std;   constexpr long long N = 2e5 + 9;   constexpr long long M = 1e9 + 7;   constexpr long long INF = 0x3f3f3f3f3f3f3f3f;   constexpr long long INF2 = 0xcfcfcfcfcfcfcfcf;   long long n;   long long a[N], b[N];   string ans;   long long p, r;   void print() {     for (long long i = 1; i <= n; i++) cout << b[i] <<    ;     cout << endl;   }   signed fail() {     cout <<  IMPOSSIBLE  << endl;     return 0;   }   bool rcheck() {     for (long long i = 1; i <= n; i++) {       if (a[i] != b[n + 1 - i]) return false;     }     r++;     ans +=  R ;     return true;   }   bool check() {     if (rcheck()) return true;     for (long long i = 1; i <= n; i++) {       if (a[i] != b[i]) return false;     }     return true;   }   signed answer() {     if (p <= 2e5) {       cout <<  SMALL  << endl;       cout << ans.size() << endl;       reverse(ans.begin(), ans.end());       cout << ans << endl;       return 0;     }     cout <<  BIG  << endl;     cout << p << endl;     return 0;   }   signed solve1() {     if (check()) {       return answer();     }     return fail();   }   inline bool inc() {     for (long long i = 1; i < n; i++) {       if (b[i + 1] <= b[i]) return false;     }     return true;   }   bool R() {     if (inc()) return true;     reverse(b + 1, b + 1 + n);     r++;     ans +=  R ;     return inc();   }   inline bool P() {     for (long long i = n; i >= 1; i--) {       b[i] = b[i] - b[i - 1];       if (b[i] < 1) return false;     }     p++;     ans +=  P ;     return true;   }   signed solve2() {     bool rev = false;     if (a[1] > a[2]) swap(a[1], a[2]), r++, rev = true;     while (!check()) {       if (b[1] == b[2]) return fail();       if (b[1] > b[2]) {         swap(b[1], b[2]), r++;         if (p <= 2e5) ans +=  R ;         continue;       }       if (b[1] == b[2]) return fail();       if (a[1] == b[1]) {         if ((b[2] - a[2]) % b[1] == 0 && b[2] > a[2]) {           long long op = (b[2] - a[2]) / b[1];           p += op;           if (p <= 2e5) {             while (op--) ans +=  P ;           }           break;         } else           return fail();       }       long long op = b[2] / b[1];       p += op;       if (p <= 2e5)         while (op--) ans +=  P ;       b[2] = b[2] % b[1];       if (b[2] == 0) return fail();     }     if (rev) ans +=  R ;     return answer();   }   signed solve() {     while (!check()) {       if (!R()) return fail();       if (!P()) return fail();     }     answer();     return 0;   }   signed main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     ;     cin >> n;     for (long long i = 1; i <= n; i++) cin >> a[i];     for (long long i = 1; i <= n; i++) cin >> b[i];     if (n == 1) return solve1();     if (n == 2) return solve2();     return solve();   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 3e5 + 5;   const int INF = 0x7fffffff;   vector<int> G[maxn];   long long weight[maxn];   long long dp[maxn];   int ans;   long long maxsum = -INF;   void dfs(int now, int fa) {     dp[now] = weight[now];     for (int v : G[now]) {       if (v != fa) {         dfs(v, now);         if (dp[v] > 0) dp[now] += dp[v];       }     }     maxsum = max(maxsum, dp[now]);   }   void dfs2(int now, int fa) {     dp[now] = weight[now];     for (int v : G[now]) {       if (v != fa) {         dfs2(v, now);         if (dp[v] > 0) dp[now] += dp[v];       }     }     if (dp[now] == maxsum) {       ans++;       dp[now] = 0;     }   }   int main() {     std::ios::sync_with_stdio(false);     int n;     cin >> n;     for (int i = 1; i <= n; ++i) cin >> weight[i];     int from, to;     for (int i = 2; i <= n; ++i) {       cin >> from >> to;       G[from].push_back(to);       G[to].push_back(from);     }     dfs(1, 0);     dfs2(1, 0);     cout << maxsum * ans <<     << ans << endl;     return 0;   }


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


#include <bits/stdc++.h>   int product(long long a) {     int maxi = 0, mini = 9, x, ans;     long long temp = a;     while (temp) {       x = temp % 10;       if (x < mini) mini = x;       if (x > maxi) maxi = x;       temp /= 10;     }     if (mini == 0) return 0;     ans = mini * maxi;     return ans;   }   using namespace std;   int main() {     ios_base::sync_with_stdio(NULL);     cin.tie(0);     cout.tie(0);     long long a, k, ans;     int t;     cin >> t;     while (t--) {       cin >> a >> k;       k--;       while (k--) {         if (product(a) == 0)           break;         else {           a += product(a);         }       }       cout << a <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string rem(string second) {     if (second[second.size() - 1] ==   r ) second.erase(second.size() - 1);     return second;   }   vector<string> split(string second, char delim) {     replace(second.begin(), second.end(), delim,    );     stringstream ss(second);     string buf;     vector<string> v;     while (ss >> buf) v.push_back(buf);     return v;   }   long long fpowm(long long x, unsigned long long y,                   unsigned long long p = LLONG_MAX) {     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;   }   inline vector<int> ints(int x) {     vector<int> A(x);     for (int i = 0; i < (x); i++) cin >> A[i];     return A;   }   inline vector<long long> lls(int x) {     vector<long long> A(x);     for (int i = 0; i < (x); i++) cin >> A[i];     return A;   }   inline vector<string> strs(int x) {     vector<string> A(x);     for (int i = 0; i < (x); i++) cin >> A[i];     return A;   }   struct chsh {     static uint64_t splitmix64(uint64_t x) {       x += 0x9e3779b97f4a7c15;       x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;       x = (x ^ (x >> 27)) * 0x94d049bb133111eb;       return x ^ (x >> 31);     }     size_t operator()(uint64_t x) const {       static const uint64_t FIXED_RANDOM =           chrono::steady_clock::now().time_since_epoch().count();       return splitmix64(x + FIXED_RANDOM);     }   };   const int MOD = 1000000007;   const double EPS = 1e-6;   const int MAXN = -1;   int tc() {     int N;     cin >> N;     vector<int> A = ints(3);     string B;     cin >> B;     vector<pair<int, char>> ans;     int R[3];     std::memset(R, 0, sizeof R);     for (int i = 0; i < (N); i++) {       if (B[i] ==  R ) {         if (A[1]) ans.push_back({i,  P }), A[1]--, R[1]++;       } else if (B[i] ==  P ) {         if (A[2]) ans.push_back({i,  S }), A[2]--, R[2]++;       } else {         if (A[0]) ans.push_back({i,  R }), A[0]--, R[0]++;       }     }     if (2 * (int)ans.size() < N) return !(cout <<  NO n );     cout <<  YES n ;     vector<char> rem;     for (int i = 0; i < (3); i++)       for (int j = 0; j < (A[i]); j++) {         if (!i)           rem.push_back( R );         else if (i == 1)           rem.push_back( P );         else if (i == 2)           rem.push_back( S );       }     string ret(N,  ~ );     for (auto first : ans) {       ret[first.first] = first.second;     }     for (int i = 0; i < (N); i++) {       if (ret[i] ==  ~ ) {         ret[i] = rem.front();         rem.erase(rem.begin());       }     }     cout << ret <<   n ;     return 0;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int T;     cin >> T;     while (T--) tc();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, r;     cin >> a >> b >> r;     if (2 * r > min(a, b)) {       cout <<  Second ;     } else {       cout <<  First ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, j, k, a, b;   pair<int, int> c[300005];   map<pair<long long, long long>, long long> m;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a >> b;       c[i] = make_pair(a, b);       m[c[i]] = i;       if (a > b) {         k++;       }     }     sort(c, c + n);     j = n - k;     if (k > j) {       cout << k <<   n ;       for (int i = 0; i < n; i++) {         if (c[i].first > c[i].second) {           cout << m[c[i]] + 1 <<    ;         }       }     } else {       cout << j <<   n ;       for (int i = n - 1; i >= 0; i--) {         if (c[i].first < c[i].second) {           cout << m[c[i]] + 1 <<    ;         }       }     }     cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     int ar[n];     int cnt = 0, cnt2 = 0;     for (int i = 0; i < n; i++) {       cin >> ar[i];       if (ar[i] > 0)         cnt += ar[i];       else         cnt2 += ar[i];     }     cout << cnt - cnt2;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     int n, u, v, c, a, b, t;     cin >> n;     long long w[n], A, B, Su[n], SMax = 0;     int g[n], S[n], Pa[n];     vector<pair<int, long long>> D[n];     vector<int> T, P;     for (int i = 0; i < n; i++) {       cin >> w[i];       g[i] = 1;     }     for (int i = 0; i < n - 1; i++) {       cin >> u >> v >> c;       u--;       v--;       D[u].push_back({v, c});       D[v].push_back({u, c});     }     g[0] = 0;     T.push_back(0);     for (int i = 0; i < T.size(); i++) {       t = 0;       for (int y = 0; y < D[T[i]].size(); y++) {         a = D[T[i]][y].first;         if (g[a] == 1) {           Pa[a] = T[i];           g[a] = 0;           t = 1;           T.push_back(a);         }       }       if (t == 0) {         P.push_back(T[i]);       }     }     T.clear();     for (int i = 0; i < n; i++) {       g[i] = 1;       S[i] = D[i].size() - 1;       if (i == 0) {         S[i]++;       }     }     for (int i = 0; i < P.size(); i++) {       g[P[i]] = 0;       a = P[i];       if (a != 0) {         S[Pa[a]]--;         if (S[Pa[a]] == 0) {           P.push_back(Pa[a]);         }       }       A = 0;       B = 0;       for (int y = 0; y < D[a].size(); y++) {         b = D[a][y].first;         c = D[a][y].second;         if (b != Pa[a]) {           if (Su[b] - c + w[b] > A) {             B = A;             A = Su[b] - c + w[b];           } else if (Su[b] - c + w[b] > B) {             B = Su[b] - c + w[b];           }         }       }       SMax = max(SMax, A + B + w[a]);       Su[a] = A;     }     cout << SMax;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int x = 0, y = 0;     char s[n];     for (int i = 0; i < n; i++) {       cin >> s[i];       if (s[i] ==  0 )         y++;       else         x++;     }     if (x == y) {       cout <<  2  << endl << s[0] <<    ;       for (int i = 1; i < n; i++) cout << s[i];     } else {       cout <<  1  << endl;       for (int i = 0; i < n; i++) cout << s[i];     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, k;   long long a[100010];   signed main() {     scanf( %lld%lld , &n, &k);     long long cnt = 1;     long long l = 1;     long long ans = 0;     for (long long i = 1; i <= n; i++) {       scanf( %lld , &a[i]);       cnt = cnt * a[i] % k;       if (!cnt) {         cnt = 1;         long long j;         for (j = i; j >= 1 && cnt * a[j] % k; j--) cnt = cnt * a[j] % k;         ans += (n - i + 1) * (j - l + 1);         l = j + 1;       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 200001;   int n;   vector<pair<int, int> > a[N * 2];   vector<int> odd;   int used[N * 2], cur[N * 2];   char res[N];   void dfs(int u) {     while (cur[u] < a[u].size()) {       int v = a[u][cur[u]].first;       int pos = a[u][cur[u]].second;       if (used[pos]) {         cur[u]++;         continue;       }       if (pos <= n) {         if (u < N) {           res[pos] =  b ;         } else {           res[pos] =  r ;         }       }       used[pos] = 1;       dfs(v);       cur[u]++;     }   }   int main() {     ios_base::sync_with_stdio(0);     cin >> n;     for (int i = 1; i <= n; i++) {       int x, y;       cin >> x >> y;       a[x].push_back(make_pair(y + N, i));       a[y + N].push_back(make_pair(x, i));     }     for (int i = 1; i < N * 2; i++) {       if (a[i].size() % 2) {         odd.push_back(i);       }       used[i] = cur[i] = 0;     }     int cnt = n;     for (int i = 0; i < odd.size(); i += 2) {       cnt++;       a[odd[i]].push_back(make_pair(odd[i + 1], cnt));       a[odd[i + 1]].push_back(make_pair(odd[i], cnt));     }     for (int i = 1; i < N * 2; i++) {       dfs(i);     }     cout << (res + 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long linf = 1e18 + 5;   const int mod = (int)1e9 + 7;   const int logN = 17;   const int inf = 1e9;   const int N = 2e5 + 5;   int n, a[N], s;   vector<pair<long long, long long> > T[N << 2], g[N << 2];   pair<long long, long long> line[N];   long long pre[N];   int P[N << 2];   double intersect(pair<long long, long long> x, pair<long long, long long> y) {     return (y.second - x.second) * 1.0 / (x.first - y.first);   }   void add(vector<pair<long long, long long> > &T, pair<long long, long long> x) {     int s = T.size() - 1;     while (s > 0 && intersect(T[s], T[s - 1]) >= intersect(T[s], x)) {       T.pop_back();       s--;     }     T.push_back(x);   }   void init(int k, int bas, int son) {     P[k] = 0;     if (bas == son) {       T[k].clear();       g[k].clear();       T[k].push_back(line[bas]);       g[k].push_back(line[bas]);       return;     }     init((k + k), bas, (bas + son >> 1));     init((k + k + 1), (bas + son >> 1) + 1, son);     g[k].resize(g[(k + k)].size() + g[(k + k + 1)].size());     merge(g[(k + k)].begin(), g[(k + k)].end(), g[(k + k + 1)].begin(),           g[(k + k + 1)].end(), g[k].begin());     for (__typeof(g[k].begin()) it = g[k].begin(); it != g[k].end(); it++)       add(T[k], *it);     P[k] = 0;   }   long long query(int k, int bas, int son, int x, int y, long long t) {     if (bas > y || son < x) return -linf;     if (x <= bas && son <= y) {       while (P[k] < T[k].size() - 1 && intersect(T[k][P[k]], T[k][P[k] + 1]) <= t)         P[k]++;       return T[k][P[k]].first * t + T[k][P[k]].second;     }     return max(query((k + k), bas, (bas + son >> 1), x, y, t),                query((k + k + 1), (bas + son >> 1) + 1, son, x, y, t));   }   int main() {     scanf( %d , &n);     long long ans = 0;     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       pre[i] = pre[i - 1] + a[i];       ans += a[i] * (long long)i;     }     for (int i = 0; i <= n; i++) line[i] = make_pair(i, pre[n] - pre[i]);     init(1, 0, n);     long long res = -linf;     vector<pair<int, int> > look;     for (int i = 1; i <= n; i++) look.push_back(make_pair(a[i], i));     sort(look.begin(), look.end());     for (__typeof(look.begin()) it = look.begin(); it != look.end(); it++) {       long long left = query(1, 0, n, 0, it->second, it->first);       res = max(res, ans + left - (pre[n] - pre[it->second]) -                          it->second * (long long)it->first);       left = query(1, 0, n, it->second + 2, n, it->first);       res = max(res, ans + left - (pre[n] - pre[it->second]) -                          it->second * (long long)it->first);     }     cout << res <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   char a[22][22], b[22][22], c[22][22];   bool chk() {     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++)         if (a[i][j] != b[i][j]) return false;     return true;   }   void flip() {     for (int i = 0; i < n; i++)       for (int j = 0; j < n - j - 1; j++) swap(a[i][j], a[i][n - j - 1]);   }   void rotate() {     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++) c[j][n - i - 1] = a[i][j];     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++) a[i][j] = c[i][j];   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %s , a[i]);     for (int i = 0; i < n; i++) scanf( %s , b[i]);     bool f = false;     for (int i = 0; i < 2 && !f; i++) {       for (int j = 0; j < 4 && !f; j++) {         if (chk()) f = true;         rotate();       }       flip();     }     puts(f ?  Yes  :  No );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int getc() {     char ch = getchar();     while (ch !=  0  && ch !=  1 ) {       ch = getchar();     }     return ch -  0 ;   }   int main() {     int n;     scanf( %d , &n);     int cnt1 = 0, cnt2 = 0;     for (int i = 0; i < n; ++i) {       if (getc() == i % 2)         cnt1++;       else         cnt2++;     }     printf( %d n , min(cnt1, cnt2));     ;     ;     ;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   struct Segtree {     int n;     T e;     vector<T> dat;     typedef function<T(T a, T b)> Func;     Func f;     Segtree() {}     Segtree(int n_input, Func f_input, T e_input) {       initialize(n_input, f_input, e_input);     }     void initialize(int n_input, Func f_input, T e_input) {       f = f_input;       e = e_input;       n = 1;       while (n < n_input) n <<= 1;       dat.resize(2 * n - 1, e);     }     void update(int k, T a) {       k += n - 1;       dat[k] = a;       while (k > 0) {         k = (k - 1) / 2;         dat[k] = f(dat[2 * k + 1], dat[2 * k + 2]);       }     }     T get(int k) { return dat[k + n - 1]; }     T between(int a, int b) { return query(a, b + 1, 0, 0, n); }     T query(int a, int b, int k, int l, int r) {       if (r <= a || b <= l) return e;       if (a <= l && r <= b) return dat[k];       T vl = query(a, b, 2 * k + 1, l, (l + r) / 2);       T vr = query(a, b, 2 * k + 2, (l + r) / 2, r);       return f(vl, vr);     }   };   void chmin(int64_t& a, int64_t b) { a = min(a, b); }   int main() {     int N, C, A[100000];     cin >> N >> C;     for (int i = 0; i < N; i++) cin >> A[i];     Segtree<int> st(         N, [](int a, int b) { return min(a, b); }, 1e9);     Segtree<int64_t> sum(         N, [](int64_t a, int64_t b) { return a + b; }, 0);     for (int i = 0; i < N; i++) {       st.update(i, A[i]);       sum.update(i, A[i]);     }     vector<int64_t> dp(N + 1, 1e18);     dp[0] = 0;     for (int i = 0; i < N; i++) {       chmin(dp[i + 1], dp[i] + A[i]);       if (i + C <= N)         chmin(dp[i + C],               dp[i] + sum.between(i, i + C - 1) - st.between(i, i + C - 1));     }     cout << dp[N] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int dp[2][1 << 16];   char art[7][1008];   int n;   int c[5];   vector<int> modi[1008];   void upd(int &x, int y) { x = min(x, y); }   int main() {     scanf( %d , &n);     for (int i = 1; i <= 4; i++) scanf( %d , &c[i]);     for (int i = 1; i <= 4; i++) scanf( %s , art[i] + 1);     int now = 0;     memset(dp[now], 0x3f, sizeof dp[now]);     dp[now][0] = 0;     for (int i = 1; i <= 4; i++) {       for (int j = 1; j <= 4 - i + 1; j++) {         int mas = (1 << 16) - 1;         for (int x = 0; x < i; x++)           for (int y = j - 1; y < j - 1 + i; y++) {             mas ^= (1 << (x * 4 + y));           }         modi[i].push_back(mas);       }     }     for (int i = 1; i <= n + 4; i++) {       now ^= 1;       memset(dp[now], 0x3f, sizeof dp[now]);       int nm = 0;       for (int j = 1; j <= 4; j++)         if (art[j][i] ==  * ) nm |= (1 << 11 + j);       for (int j = (1 << 16) - 1; j >= 0; j--)         if (dp[now ^ 1][j] < 1e9) {           for (int k = 1; k <= 4; k++)             for (int l = 0; l < modi[k].size(); l++)               upd(dp[now ^ 1][j & modi[k][l]], dp[now ^ 1][j] + c[k]);           if (j & 15) continue;           upd(dp[now][(j >> 4) | nm], dp[now ^ 1][j]);         }     }     printf( %d n , dp[now][0]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 106;   long long d, A[N], f[N];   bool vs[N];   int X[N], Y[N], n;   queue<int> q;   inline long long dis(int a, int b) {     return abs(X[a] - X[b]) + abs(Y[a] - Y[b]);   }   bool judge(long long init) {     memset(f, -1, sizeof f);     while (!q.empty()) q.pop();     memset(vs, 0, sizeof vs);     q.push(1), f[1] = init, vs[1] = 1;     while (!q.empty()) {       int u = q.front();       q.pop(), vs[u] = 0;       for (int i = 1; i <= n; i++) {         if (dis(i, u) * d > f[u] || i == u) continue;         if (f[u] - dis(i, u) * d + A[i] > f[i]) {           f[i] = f[u] - dis(i, u) * d + A[i];           if (!vs[i]) q.push(i), vs[i] = 1;         }       }     }     if (f[n] == -1) return false;     return true;   }   int main() {     scanf( %d%I64d , &n, &d);     for (int i = 2; i < n; i++) scanf( %I64d , &A[i]);     for (int i = 1; i <= n; i++) scanf( %d%d , &X[i], &Y[i]);     long long L = 0, R = ((1LL) << 60);     while (L < R) {       long long mid = (L + R) >> 1;       if (judge(mid))         R = mid;       else         L = mid + 1;     }     if (!judge(L)) L++;     printf( %I64d n , L);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void RI() {}   template <typename... T>   void RI(int &head, T &...tail) {     scanf( %d , &head);     RI(tail...);   }   struct Maxflow {     struct E {       int to, cap, rev, rcap, ucap;       E() {}       E(int _to, int _cap, int _rev)           : to(_to), cap(_cap), rev(_rev), rcap(_cap) {}     };     int n;     vector<vector<E> > e;     vector<vector<E>::iterator> cur;     vector<int> dis;     void init(int _n) {       n = _n;       e.resize(n);       cur.resize(n);       dis.resize(n);       for (int i = 0; i < int(n); i++) e[i].clear();     }     void add(int a, int b, int c) {       if (a == b) return;       e[a].push_back(E(b, c, e[b].size()));       e[b].push_back(E(a, 0, e[a].size() - 1));     }     bool bfs() {       fill(dis.begin(), dis.end(), -1);       queue<int> q;       dis[0] = 0;       q.push(0);       while (!q.empty() && dis[n - 1] == -1) {         int p = q.front();         q.pop();         for (auto it = (e[p]).begin(); it != (e[p]).end(); it++) {           if (it->cap == 0 || dis[it->to] != -1) continue;           dis[it->to] = dis[p] + 1;           q.push(it->to);         }       }       return dis[n - 1] != -1;     }     long long go(int p, long long c) {       if (p == n - 1) return c;       long long ret = 0;       for (; cur[p] != e[p].end(); cur[p]++) {         if (cur[p]->cap == 0 || dis[cur[p]->to] != dis[p] + 1) continue;         long long now = go(cur[p]->to, min((long long)cur[p]->cap, c - ret));         ret += now;         cur[p]->cap -= now;         e[cur[p]->to][cur[p]->rev].cap += now;         if (ret == c) break;       }       if (ret == 0) dis[p] = -1;       return ret;     }     long long maxflow() {       long long ret = 0;       while (bfs()) {         for (int i = 0; i < int(n); i++) cur[i] = e[i].begin();         ret += go(0, 1LL << 60);       }       return ret;     }     bool _addPath(int wh, vector<vector<int> > &ans) {       if (wh == n - 1) {         ans.push_back(vector<int>());         ans.back().push_back(wh);         return true;       }       for (auto it = (e[wh]).begin(); it != (e[wh]).end(); it++)         if (it->ucap > 0 && _addPath(it->to, ans)) {           it->ucap--;           ans.back().push_back(wh);           return true;         }       return false;     }     vector<vector<int> > getPath() {       vector<vector<int> > ans;       for (auto it = (e).begin(); it != (e).end(); it++)         for (auto jt = (*it).begin(); jt != (*it).end(); jt++)           jt->ucap = max(0, jt->rcap - jt->cap);       while (_addPath(0, ans)) reverse(ans.back().begin(), ans.back().end());       return ans;     }   } flow;   bool pt[51400];   void predo() {     for (int i = 2; i < 51400; i++)       if (!pt[i])         for (int j = i + i; j < 51400; j += i) pt[j] = 1;   }   int n, a[210];   vector<int> e[210], sol;   bool vis[210];   void dfs(int p) {     sol.push_back(p);     vis[p] = 1;     for (auto it = (e[p]).begin(); it != (e[p]).end(); it++)       if (!vis[*it]) {         dfs(*it);         break;       }   }   int main() {     predo();     RI(n);     for (int i = (1); i <= int(n); i++) RI(a[i]);     int sink = n + 1;     flow.init(sink + 1);     for (int i = (1); i <= int(n); i++) {       if (a[i] % 2 == 0)         flow.add(0, i, 2);       else         flow.add(i, sink, 2);     }     for (int i = (1); i <= int(n); i++)       if (a[i] % 2 == 0)         for (int j = (1); j <= int(n); j++)           if (!pt[a[i] + a[j]]) flow.add(i, j, 1);     int mf = flow.maxflow();     if (mf != n) {       puts( Impossible );       return 0;     }     auto ps = flow.getPath();     for (auto it = (ps).begin(); it != (ps).end(); it++) {       assert(((int)(*it).size()) == 4);       int x = it->at(1);       int y = it->at(2);       e[x].push_back(y);       e[y].push_back(x);     }     for (int i = (1); i <= int(n); i++) assert(((int)(e[i]).size()) == 2);     vector<vector<int> > sols;     for (int i = (1); i <= int(n); i++)       if (!vis[i]) {         sol.clear();         dfs(i);         assert(((int)(sol).size()) % 2 == 0 && ((int)(sol).size()) >= 4);         sols.push_back(sol);       }     printf( %d n , ((int)(sols).size()));     for (auto &s : sols) {       printf( %d , ((int)(s).size()));       for (auto it = (s).begin(); it != (s).end(); it++) printf(  %d , *it);       puts(  );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int i, j, n, t, x;     string s =   ;     cin >> t;     for (i = 0; i < t; i++) {       s +=  o ;     }     int ara[t + 5];     ara[0] = 1;     ara[1] = 1;     s[0] =  O ;     s[1] =  O ;     for (i = 2; i <= t; i++) {       ara[i] = ara[i - 1] + ara[i - 2];       if (ara[i] <= t) s[ara[i] - 1] =  O ;       if (ara[i] > t)         break;       else         continue;     }     cout << s <<   n ;     return 0;   }


#include <bits/stdc++.h>   const int INF = 0x3f3f3f3f;   const int maxn = 1e6 + 50;   const int Mod = 1e9 + 7;   using namespace std;   int n, m, sx, sy, dx, dy;   int get(int sx, int sy, int ex, int ey) {     int cx = abs(sx - ex), cy = abs(sy - ey);     if (cx == 0 && cy == 0) return 0;     if (cx % dx != 0 || cy % dy != 0) return INF;     if (sx == ex) {       if (!(sx - dx >= 1 || sx + dx <= n)) return INF;     } else if (sy == ey) {       if (!(sy - dy >= 1 || sy + dy <= m)) return INF;     }     int t1 = cx / dx, t2 = cy / dy;     int cha = abs(t1 - t2);     if (cha & 1) return INF;     return max(t1, t2);   }   int main() {     while (scanf( %d %d %d %d %d %d , &n, &m, &sx, &sy, &dx, &dy) != EOF) {       int ans = INF;       ans = min(get(sx, sy, 1, 1), ans);       ans = min(get(sx, sy, 1, m), ans);       ans = min(get(sx, sy, n, 1), ans);       ans = min(get(sx, sy, n, m), ans);       if (ans == INF)         puts( Poor Inna and pony! );       else         printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     vector<pair<long long, long long>> v(n);     for (int i = 0; i < n; i++) cin >> v[i].second >> v[i].first;     sort(v.rbegin(), v.rend());     long long ans = 0, sum = 0;     priority_queue<long long, vector<long long>, greater<long long>> pq;     for (int i = 0; i < n; i++) {       pq.push(v[i].second);       sum += v[i].second;       if (pq.size() > k) {         sum -= pq.top();         pq.pop();       }       ans = max(ans, v[i].first * sum);     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e2;   int i, a[N], n;   int main() {     cin >> n;     for (i = 0; i < n; i++) cin >> a[i];     sort(a, a + n);     cout << a[n - 1] <<    ;     for (i = 1; i < n - 1; i++) cout << a[i] <<    ;     cout << a[0];     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int TEST, CASE = 1;   int n, m, a, b, c, k, x, y, z, len, total = 0;   string s, temp, ans;   vector<string> v;   bool cmp(string &a, string &b) {     if (a.size() < b.size())       return true;     else       return false;   }   int main(void) {     cin >> n;     for (int i = 0; i < n; i++) cin >> s, v.push_back(s);     sort(v.begin(), v.end(), cmp);     for (int i = 1; i < n; i++) {       if (v[i].find(v[i - 1]) > v[i].size()) {         cout <<  NO  << endl;         return 0;       }     }     cout <<  YES  << endl;     for (int i = 0; i < n; i++) cout << v[i] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int Set(int N, int pos) { return N |= (1LL << pos); }   int Reset(int N, int pos) { return N &= ~(1LL << pos); }   bool Check(int N, int pos) { return N & (1LL << pos); }   int dx[] = {0, 0, 1, -1, 1, -1, 1, -1}, dy[] = {1, -1, 0, 0, 1, -1, -1, 1};   inline void cn(long &n) {     n = 0;     long ch = getchar();     int sign = 1;     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) sign = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 )       n = (n << 3) + (n << 1) + ch -  0 , ch = getchar();     n = n * sign;   }   template <class T>   void cmin(T &a, T b) {     if (b < a) a = b;   }   template <class T>   void cmax(T &a, T b) {     if (b > a) a = b;   }   template <class T>   int len(const T &c) {     return (int)c.size();   }   template <class T>   int len(char c[]) {     return (int)strlen(c);   }   long stoi(string s) {     long n = 0;     for (int i(0), _n(len(s)); i < _n; ++i) n = n * 10 + (s[i] - 48);     return n;   }   int main() {     ios_base::sync_with_stdio(false);     long m, t, r, w, k, ww, res = 0, ls;     cin >> m >> t >> r;     vector<int> v, tem;     int f = 1;     for (int i(0), _n(m); i < _n; ++i) {       cin >> w;       ls = -100000000000000000LL;       if (!f) continue;       for (int j = len(v) - 1; j >= 0; j--) {         if (v[j] >= w)           tem.push_back(v[j]);         else           break;       }       if (len(tem) < r) {         k = r - len(tem);         ww = w;         for (int j(0), _n(k); j < _n; ++j) {           if (ww + t - 1 >= w) {             res++;             tem.push_back(ww + t - 1);             ww -= 1;           } else {             f = 0;             break;           }         }       }       v = tem;       tem.clear();       sort(v.begin(), v.end());     }     if (f == 0) res = -1;     cout << res;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1);   double a, b, c[100005], mx;   int n;   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %lf %lf , &a, &b);       c[i] = (atan2(b, a) * 180) / pi;     }     sort(c, c + n);     for (int i = 0; i < n - 1; i++) {       mx = max(mx, c[i + 1] - c[i]);     }     mx = max(mx, 360 - c[n - 1] + c[0]);     printf( %0.08lf n , 360 - mx);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, ans = 1e9;   pair<int, int> p[1005];   void solve(int height) {     int width = 0, remain = n / 2;     vector<int> priority;     for (int i = 1; i <= n; i++)       if (p[i].second > height)         if (p[i].first > height)           return;         else if (remain) {           remain--;           width += p[i].second;         } else           return;       else if (p[i].first > height)         width += p[i].first;       else if (p[i].first > p[i].second) {         width += p[i].second;         priority.push_back(p[i].first - p[i].second);       } else         width += p[i].first;     sort(priority.rbegin(), priority.rend());     for (int i = remain; i < priority.size(); i++) width += priority[i];     ans = min(ans, width * height);   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d %d , &p[i].first, &p[i].second);     for (int i = 1; i <= 1000; i++) solve(i);     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct node {     int x, num;   } s[100009];   int mark[100009];   int cmp(node a, node b) { return a.x < b.x; }   int main() {     int n, m;     while (scanf( %d %d , &n, &m) == 2) {       int l, h;       scanf( %d %d , &l, &h);       for (int i = 0; i < n; i++) {         int a, b;         scanf( %d %d , &a, &b);         s[i].x = a * l + b * h;         s[i].num = i + 1;       }       sort(s, s + n, cmp);       int ans = 0;       int k = 0;       for (int i = 0; i < n; i++) {         m -= s[i].x;         if (m < 0) break;         ans++;         mark[k++] = s[i].num;       }       printf( %d n , ans);       for (int i = 0; i < ans; i++) {         if (i == 0)           printf( %d , mark[i]);         else           printf(  %d , mark[i]);       }       printf(  n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 2000 * 100 + 1000;   vector<long long> adj[N];   long long a[N], h[N], t[N];   bool mark[N];   long long f(long long p) {     mark[p] = true;     long long ans = h[p] * a[p];     t[p] = a[p];     for (auto q : adj[p])       if (mark[q] == false) {         h[q] = h[p] + 1;         ans += f(q);         t[p] += t[q];       }     return ans;   }   long long ans = 0, sum = 0;   void calc(long long val, long long p) {     mark[p] = true;     ans = max(ans, val);     for (auto q : adj[p])       if (mark[q] == false) {         long long k = sum - 2 * t[q];         calc(val + k, q);       }   }   int32_t main() {     ios::sync_with_stdio(false);     long long n;     cin >> n;     for (long long i = 0; i < n; i++) {       cin >> a[i];       sum += a[i];     }     for (long long i = 0; i < n - 1; i++) {       long long u, v;       cin >> u >> v;       u--;       v--;       adj[u].push_back(v);       adj[v].push_back(u);     }     long long val = f(0);     for (long long i = 0; i < N; i++) mark[i] = false;     calc(val, 0);     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     for (int i = 0; i < s.size(); i++) {       if (s[i] ==  1 ) continue;       if (s[i] ==  4  && s[i - 1] ==  1 ) continue;       if (s[i] ==  4  && i > 1 && s[i - 1] ==  4  && s[i - 2] ==  1 ) continue;       return cout <<  NO , 0;     }     cout <<  YES ;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 5010;   int n, m, s;   vector<int> e[N];   int low[N], dfn[N], idx;   bool vis[N];   stack<int> st;   bool in_stack[N];   int color[N], color_tot;   int indeg[N];   int ans;   void AddEdge(int u, int v) { e[u].push_back(v); }   void Dfs(int u) {     low[u] = dfn[u] = ++idx;     in_stack[u] = true;     st.push(u);     for (int v : e[u]) {       if (!dfn[v]) {         Dfs(v);         low[u] = min(low[u], low[v]);       } else if (in_stack[v]) {         low[u] = min(low[u], dfn[v]);       }     }     if (low[u] == dfn[u]) {       ++color_tot;       int v;       do {         v = st.top();         st.pop();         in_stack[v] = false;         color[v] = color_tot;       } while (v != u);     }   }   void Tarjan() {     for (int i = 1; i <= n; ++i)       if (!color[i]) Dfs(i);   }   int main() {     scanf( %d%d%d , &n, &m, &s);     for (int i = 1; i <= m; ++i) {       int u, v;       scanf( %d%d , &u, &v);       AddEdge(u, v);     }     Tarjan();     for (int i = 1; i <= n; ++i)       ;     for (int i = 1; i <= n; ++i)       for (int j : e[i])         if (color[i] != color[j]) ++indeg[color[j]];     for (int i = 1; i <= color_tot; ++i)       ;     for (int i = 1; i <= color_tot; ++i)       if (indeg[i] == 0) ++ans;     if (indeg[color[s]] == 0) --ans;     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, m, a;     cin >> n >> m >> a;     long long v = n / a;     long long t = m / a;     if (n % a != 0) v++;     if (m % a != 0) t++;     cout << v * t;   }


#include <bits/stdc++.h>   using namespace std;   struct Edge {     int v;     char c;   } edge[220];   vector<Edge> ans;   vector<int> Chain[10];   int N;   bool flag[110];   void dfs(int x) {     for (int i = 0; i < Chain[x].size(); i++) {       int v = edge[Chain[x][i]].v, id = Chain[x][i] >> 1;       if (!flag[id]) {         flag[id] = 1;         dfs(v);         ans.push_back((Edge){id, edge[Chain[x][i]].c});       }     }   }   void print() {     for (int i = N - 1; i >= 0; i--) printf( %d %c n , ans[i].v + 1, ans[i].c);   }   int main() {     scanf( %d , &N);     for (int i = 0; i < N; i++) {       int a, b;       scanf( %d%d , &a, &b);       edge[2 * i] = (Edge){b,  + };       Chain[a].push_back(2 * i);       edge[2 * i + 1] = (Edge){a,  - };       Chain[b].push_back(2 * i + 1);     }     int u = edge[0].v, sum = 0;     for (int i = 0; i <= 6; i++)       if (1 & Chain[i].size()) u = i, sum++;     if (sum == 0 || sum == 2) {       dfs(u);       if (ans.size() == N)         print();       else         printf( No solution );     } else       printf( No solution );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   bool umin(T& a, T b) {     if (a > b) {       a = b;       return 1;     }     return 0;   }   template <class T>   bool umax(T& a, T b) {     if (a < b) {       a = b;       return 1;     }     return 0;   }   const int N = 1e3 + 9;   double dp[N][N], prob[N];   bool vis[N][N];   long long sum[22], pw[22];   double rec(int x, int y) {     umax(y, 0);     if (!x) {       if (!y) return 1.0;       return 0.0;     }     double& ret = dp[x][y];     if (vis[x][y]) return ret;     vis[x][y] = 1;     return ret = rec(x - 1, y - 1) * prob[x] + rec(x - 1, y) * (1 - prob[x]);   }   long long f(long long x) {     if (!x) return 0;     vector<int> v;     while (x >= 1) {       v.push_back(x % 10);       x /= 10;     }     reverse(v.begin(), v.end());     if (v[0] > 1) return sum[v.size()];     long long res = sum[v.size() - 1];     for (int i = 1; i < int(v.size()); i++) {       if (v[i] == 0) continue;       res += (v[i]) * 1LL * pw[v.size() - i - 1];     }     return res + 1;   }   int main() {     pw[0] = 1;     for (int i = 1; i <= 18; i++) {       pw[i] = pw[i - 1] * 10;       sum[i] = sum[i - 1] + pw[i - 1];     }     int n, k;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       long long x, y;       scanf( %lld%lld , &x, &y);       long long res = f(y) - f(x - 1);       prob[i] = double(res) / double(y - x + 1);     }     scanf( %d , &k);     printf( %.12lf n , rec(n, (k * n + 99) / 100));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long spf[3000001];   long long fac[3000001];   void sieve() {     spf[1] = 1;     for (long long i = 2; i < 3000001; i++) spf[i] = i;     for (long long i = 4; i < 3000001; i += 2) spf[i] = 2;     for (long long i = 3; i * i < 3000001; i++) {       if (spf[i] == i) {         for (long long j = i * i; j < 3000001; j += i)           if (spf[j] == j) spf[j] = i;       }     }   }   map<long long, long long> getfactor(long long a) {     map<long long, long long> m;     while (a > 1) {       m[spf[a]]++;       a /= spf[a];     }     return m;   }   long long power(long long x, long long y, long long p) {     long long res = 1;     x = x % p;     while (y > 0) {       if (y & 1) res = (res * x) % p;       y = y >> 1;       x = (x * x) % p;     }     return res;   }   long long gcd(long long a, long long b) {     if (a == 0) return b;     return gcd(b % a, a);   }   long long inverse(long long a, long long p) { return power(a, p - 2, p); }   long long ncr(long long n, long long r, long long p) {     if (r > n) return 0;     if (r == 0) return 1;     return (fac[n] * inverse(fac[r], p) % p * inverse(fac[n - r], p) % p) % p;   }   void solve() {     long long n, k;     cin >> n >> k;     map<long long, long long> m;     for (long long i = 1; i <= n; i++) {       long long l, r;       cin >> l >> r;       m[l]++;       m[r + 1]--;     }     long long pre = 0;     for (auto it : m) {       pre += m[it.first];       m[it.first] = pre;     }     long long prev = -1e18, val = 0;     long long ans = 0;     for (auto it : m) {       if (prev == -1e18) {         prev = it.first;         val = it.second;       } else {         ans = (ans +                (ncr(val, k, 1000000007) * (it.first - prev) % 1000000007) %                    1000000007 +                1000000007) %               1000000007;         prev = it.first;         val = it.second;       }     }     cout << ans <<   n ;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long test = 1;     fac[0] = 1;     for (long long i = 1; i <= 300000; i++)       fac[i] = (fac[i - 1] * i) % 1000000007;     while (test--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   long long int pow_mod(long long int a, long long int b) {     long long int res = 1;     while (b != 0) {       if (b & 1) {         res = (res * a) % 1000000007;       }       a = (a * a) % 1000000007;       b /= 2;     }     return res;   }   long long int inv(long long int x) { return pow_mod(x, 1000000007 - 2); }   void solve() {     long long int n;     cin >> n;     long long int x = 2 * n - 1;     long long int y = n;     long long int res1 = 1;     for (long long int i = 0; i < y; i++) res1 = (res1 * (x - i)) % 1000000007;     long long int res2 = 1;     for (long long int i = 1; i <= y; i++) res2 = (res2 * i) % 1000000007;     long long int ans = (res1 * inv(res2)) % 1000000007;     ans *= 2;     ans %= 1000000007;     ans -= n;     ans += 1000000007;     ans %= 1000000007;     cout << ans << endl;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int t;     t = 1;     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const unsigned long long INF = ~0ll;   unsigned long long prime[16] = {2,  3,  5,  7,  11, 13, 17, 19,                                   23, 29, 31, 37, 41, 43, 47, 53};   int n;   unsigned long long ans;   void dfs(int deepth, unsigned long long v, unsigned long long num) {     if (num > n || deepth > 15) return;     if (num == n && v < ans) {       ans = v;       return;     }     for (unsigned long long i = 1; i <= 63; i++) {       if (ans / prime[deepth] < v) break;       dfs(deepth + 1, v *= prime[deepth], num * (i + 1));     }   }   int main() {     while (cin >> n) {       ans = INF;       dfs(0, 1, 1);       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       long long n, a, b;       cin >> n >> a >> b;       if (2 * a < b) {         long long ans = n * a;         cout << ans << endl;       } else {         long long cou = n % 2;         long long ans = (n / 2) * b;         if (cou == 1) {           ans += a;         }         cout << ans << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const long long p = 1000000007LL;   long long power(long long x, long long n) {     long long ret = 1LL;     while (n > 0LL) {       if (n & 1LL) ret = ret * x % p;       x = x * x % p;       n >>= 1LL;     }     return ret;   }   long long n, m;   long long dp;   int main() {     cin >> n >> m;     dp = 1;     for (long long i = 1LL; i <= n; i++)       dp = (dp * (m * 2LL - 1LL) + power(m, i - 1LL)) % p;     cout << dp << endl;   }


#include <bits/stdc++.h>   using namespace std;   typedef pair<int, int> pii;   typedef long long ll;   typedef unsigned long long ull;   template <typename T>   bool umax(T& a, const T& b) {     return b <= a ? false : (a = b, true);   }   template <typename T>   bool umin(T& a, const T& b) {     return b >= a ? false : (a = b, true);   }   template <typename T>   void V2A(T a[], const vector<T>& b) {     for (int i = 0; i < b.size(); i++) a[i] = b[i];   }   template <typename T>   void A2V(vector<T>& a, const T b[]) {     for (int i = 0; i < a.size(); i++) a[i] = b[i];   }   const double PI = acos(-1.0);   const int INF = 1e9 + 7;   const int maxn = 2e3 + 7;   bool plot[maxn][maxn];   int r[maxn][maxn];   int n, m, k;   int check(int row, int col) {     if (col >= 0 && col < m) return true;     return false;   }   int main() {     cin >> n >> m >> k;     for (int i = 0; i < k; i++) {       int x, y;       scanf( %d%d , &x, &y);       x--;       y--;       if (!plot[x][y]) {         printf( %d %d n , x + 1, y + 1);         plot[x][y] = true;         continue;       }       for (int d = 1; d <= 3; d++) {         int Max = min(n, x + d + 1);         for (int row = max(0, x - d); row < Max; row++) {           int t = d - abs(x - row), col1 = y - t, col2 = y + t;           if (check(row, col1)) umax(r[x][y], r[row][col1] - d);           if (check(row, col2)) umax(r[x][y], r[row][col2] - d);         }       }       for (int d = r[x][y] + 1;; d++) {         int Max = min(n, x + d + 1);         bool ok = false;         for (int row = max(0, x - d); row < Max; row++) {           int t = d - abs(x - row), col1 = y - t, col2 = y + t;           if (check(row, col1) && !plot[row][col1]) {             ok = true;             printf( %d %d n , row + 1, col1 + 1);             plot[row][col1] = true;             break;           }           if (check(row, col2) && !plot[row][col2]) {             ok = true;             printf( %d %d n , row + 1, col2 + 1);             plot[row][col2] = true;             break;           }         }         if (ok) {           r[x][y] = d - 1;           break;         }       }     }     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   void desperate_optimization(int precision) {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cout.setf(ios::fixed);     cout.setf(ios::showpoint);     cout.precision(precision);   }   const int N = 2e5;   long long arrA[N + 5], arrB[N + 5];   long long posA[N + 5], posB[N + 5];   long long res[N + 5];   long long bit[N + 5];   int n;   int query(int x) {     int tot = 0;     for (; x; x -= (x & -x)) tot += bit[x];     return tot;   }   void update(int x) {     for (; x <= n; x += (x & -x)) bit[x]++;   }   void hora(int tc) {     cin >> n;     for (int i = 0; i < n; i++) cin >> arrA[i];     for (int i = 0; i < n; i++) cin >> arrB[i];     for (int i = 0; i < n; i++) {       int val = query(arrA[i] + 1);       posA[i] = arrA[i] - val;       update(arrA[i] + 1);     }     memset(bit, 0, sizeof bit);     for (int i = 0; i < n; i++) {       int val = query(arrB[i] + 1);       posB[i] = arrB[i] - val;       update(arrB[i] + 1);     }     long long cur = 0;     long long sisa = 0;     for (int i = n - 1; i >= 0; i--) {       res[i] = posA[i] + posB[i] + sisa;       sisa = res[i] / (cur + 1);       res[i] %= (cur + 1);       cur += 1;     }     memset(bit, 0, sizeof bit);     for (int i = 0; i < n; i++) {       int lo = 0;       int hi = n;       int ans = -1;       while (lo <= hi) {         int mid = (lo + hi) / 2;         if (mid - query(mid + 1) >= res[i]) {           ans = mid;           hi = mid - 1;         } else           lo = mid + 1;       }       update(ans + 1);       cout << ans <<    ;     }   }   int main() {     desperate_optimization(10);     int ntc = 1;     for (int tc = 1; tc <= ntc; tc++) hora(tc);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long maxm = -1e18;   long long minm = 1e18;   long long mod = 1e9 + 7;   long long mod1 = 1e9 + 9;   const long double Pi = 3.141592653;   long long int fact(long long int n) {     if (n == 0) {       return 1;     } else if (n == 1) {       return 1;     }     long long int res = 1;     for (long long int i = 2; i <= n; i++) res = res * i;     return res;   }   long long int nCr(long long int n, long long int r) {     return fact(n) / (fact(r) * fact(n - r));   }   bool isint(double n) {     long long int j = n;     double w = n - j;     if (w > 0) {       return false;     }     return true;   }   long long int count3(long long int x) {     long long int ret = 0;     while (x % 3 == 0) {       ret++;       x /= 3;     }     return ret;   }   long long int sqr(long long int a) { return a * a; }   int32_t main() {     ios_base::sync_with_stdio(false), cin.tie(NULL);     long long t = 1;     cin >> t;     while (t--) {       long long int n;       cin >> n;       long long int ans = 1;       if (n == 1) {         cout << 1 <<   n ;         continue;       }       for (long long int i = 1; i <= 2 * n - 1; i++) {         ans = (ans * i);         ans = (ans) % mod;       }       ans = (ans * n) % mod;       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int M = 4e3 + 44;   const int F = 4000;   int n;   int s[M];   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &s[i]);     printf( %d n , n + 1);     int tmp, tmp1, tmp2, sum = 0;     for (int i = n; i >= 1; i--) {       tmp = (F + i - ((sum + s[i]) % F)) % F;       sum += tmp;       printf( %d %d %d n , 1, i, tmp);     }     printf( %d %d %d n , 2, n, F);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   static const int maxn = 2e5 + 5;   struct Node {     bool ok;     int val;     int pos, rpos;     Node(bool ok = 0, int val = 0, int pos = 0, int rpos = 0)         : ok(ok), val(val), pos(pos), rpos(rpos) {}     bool operator<(const Node &other) const {       if (ok and other.ok) {         if (val == other.val) return pos > other.pos;         return val < other.val;       }       return ok > other.ok;     }   };   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     int n;     cin >> n;     vector<int> arr(n + 2);     for (int i = 1; i <= n; i++) cin >> arr[i];     vector<int> rgt(n + 1);     rgt[n] = -1;     for (int i = n - 1; i >= 1; i--) rgt[i] = i + 1;     multiset<Node> ms;     arr[n + 1] = 1e9 + 9;     for (int i = 1; i <= n; i++) {       bool ok = arr[i] > arr[i + 1];       ms.insert(Node(ok, arr[i], i, i + 1));     }     int min_time = 0;     map<int, int> mp;     while (ms.size()) {       int cnt = 0;       mp.clear();       while (ms.size()) {         auto it = *ms.begin();         if (it.ok == false) break;         ++cnt;         ms.erase(it);         rgt[it.pos] = rgt[it.rpos];         mp[rgt[it.rpos]] = it.pos;       }       if (cnt == 0) break;       ++min_time;       for (auto it : mp) {         if (it.first == -1) continue;         int pos = it.second;         int rpos = it.first;         bool ok = arr[pos] > arr[rpos];         ms.insert(Node(ok, arr[pos], pos, rpos));       }     }     cout << min_time <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   long long rdtsc() {     long long tmp;     asm( rdtsc  :  =A (tmp));     return tmp;   }   inline int myrand() { return abs((rand() << 15) ^ rand()); }   inline int rnd(int x) { return myrand() % x; }   const int INF = (int)1e9 + 1;   const long double EPS = 1e-9;   void precalc() {}   const int maxn = (int)1e5 + 10;   int a[2 * maxn];   int n, w;   bool read() {     if (scanf( %d%d , &n, &w) < 2) {       return 0;     }     for (int i = 0; i < 2 * n; ++i) {       scanf( %d , &a[i]);     }     return 1;   }   void solve() {     sort(a, a + 2 * n);     printf( %.18f n ,            min((double)w, min((double)a[n] / 2, (double)a[0]) * 3 * n));   }   int main() {     srand(rdtsc());     precalc();     while (1) {       if (!read()) {         break;       }       solve();     }     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:100000000,100000000 )   using namespace std;   const long long inf = 1e9 + 7;   const long long mod = 1e9 + 7;   const double eps = 1e-9;   const double PI = 2 * acos(0.0);   const double E = 2.71828;   int main(void) {     long long n;     cin >> n;     double ans = 0, e = 0;     for (int i = 0; i < n; i++) {       double temp;       cin >> temp;       ans += temp * (2.0 * e + 1);       e = temp * (e + 1);     }     cout << setprecision(8) << fixed << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string norm(string s) {     string res = s;     for (int i = 0; i < 2; i++) {       for (int j = 0; j < 4; j++) {         for (int k = 0; k < 4; k++) {           res = min(s, res);           swap(s[0], s[1]);           swap(s[1], s[2]);           swap(s[2], s[3]);         }         swap(s[0], s[4]);         swap(s[4], s[2]);         swap(s[2], s[5]);       }       swap(s[0], s[1]);       swap(s[1], s[2]);       swap(s[2], s[3]);     }     return res;   }   int main() {     set<string> myS;     string S;     cin >> S;     sort(S.begin(), S.end());     do {       myS.insert(norm(S));     } while (next_permutation(S.begin(), S.end()));     cout << myS.size() << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       vector<int> a(n + 1);       for (int i = 1; i <= n; i++) cin >> a[i];       vector<vector<int> > dp(201);       for (int i = 1; i <= n; i++) {         dp[a[i]].push_back(i);       }       int maximum = 0;       for (int i = 1; i <= n; i++) {         int p = a[i];         int l = lower_bound(dp[p].begin(), dp[p].end(), i) - begin(dp[p]);         int r = dp[p].size() - l - 1;         if (l >= r) continue;         int lval = dp[p][l];         int rval = dp[p][r];         int maxi = 0;         for (int j = 1; j <= 200; j++) {           if (j == p) {             maxi = max(maxi, r - l - 1);             continue;           }           int xx = upper_bound(dp[j].begin(), dp[j].end(), rval) - dp[j].begin();           int yy = upper_bound(dp[j].begin(), dp[j].end(), lval) - dp[j].begin();           maxi = max(maxi, xx - yy);         }         maximum = max(maximum, maxi + (2 * (l + 1)));       }       cout << max(1, maximum) << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   int s, t, ds, dt;   struct edge {     int u, v;   } E[400005];   vector<int> vecr[200005];   int pre[200005];   int find(int x) {     if (x != pre[x]) pre[x] = find(pre[x]);     return pre[x];   }   void Union(int x, int y) { pre[find(x)] = find(y); }   int cpts[200005];   int tot;   int conts[200005];   int contt[200005];   map<int, int> to;   vector<int> dhas;   vector<int> ans;   void output(int pos) {     int siz = vecr[pos].size();     for (int i = 0; i < siz; i++) {       int u = E[vecr[pos][i]].u;       int v = E[vecr[pos][i]].v;       if (find(u) == find(v))         continue;       else {         Union(u, v);         ans.push_back(vecr[pos][i]);       }     }   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) pre[i] = i;     for (int i = 0; i < m; i++) scanf( %d%d , &E[i].u, &E[i].v);     scanf( %d%d%d%d , &s, &t, &ds, &dt);     for (int i = 0; i < m; i++) {       if (E[i].u == s || E[i].u == t || E[i].v == s || E[i].v == t)         continue;       else if (find(E[i].u) != find(E[i].v)) {         Union(E[i].u, E[i].v);       }     }     for (int i = 1; i <= n; i++)       if (i != s && i != t) cpts[tot++] = find(i);     sort(cpts, cpts + tot);     tot = unique(cpts, cpts + tot) - cpts;     cpts[tot++] = s;     cpts[tot++] = t;     for (int i = 0; i < tot; i++) to[cpts[i]] = i;     memset(conts, -1, sizeof(conts));     memset(contt, -1, sizeof(contt));     for (int i = 0; i < m; i++) {       if (E[i].u == s) conts[to[find(E[i].v)]] = i;       if (E[i].v == s) conts[to[find(E[i].u)]] = i;       if (E[i].u == t) contt[to[find(E[i].v)]] = i;       if (E[i].v == t) contt[to[find(E[i].u)]] = i;       if (find(E[i].u) == find(E[i].v)) vecr[to[find(E[i].u)]].push_back(i);     }     for (int i = 1; i <= n; i++) pre[i] = i;     for (int i = 0; i < tot - 2; i++) {       output(i);       if (conts[i] >= 0 && contt[i] >= 0)         dhas.push_back(i);       else if (conts[i] >= 0) {         ans.push_back(conts[i]);         ds--;       } else if (contt[i] >= 0) {         ans.push_back(contt[i]);         dt--;       }     }     if (dhas.size() == 0) {       ds--;       dt--;       ans.push_back(conts[tot - 1]);       if (ds < 0 || dt < 0)         printf( No n );       else {         printf( Yes n );         for (int i = 0; i < ans.size(); i++) {           printf( %d %d n , E[ans[i]].u, E[ans[i]].v);         }       }     } else {       for (int i = 0; i < dhas.size(); i++) {         if (i == 0) {           ans.push_back(conts[dhas[i]]);           ans.push_back(contt[dhas[i]]);           ds--;           dt--;         } else {           if (ds < dt) {             ans.push_back(contt[dhas[i]]);             dt--;           } else {             ans.push_back(conts[dhas[i]]);             ds--;           }         }       }       if (ds < 0 || dt < 0)         printf( No n );       else {         printf( Yes n );         for (int i = 0; i < ans.size(); i++) {           printf( %d %d n , E[ans[i]].u, E[ans[i]].v);         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   double power(float x, int y) {     float temp;     if (y == 0) return 1;     temp = power(x, y / 2);     if (y % 2 == 0)       return temp * temp;     else {       if (y > 0)         return x * temp * temp;       else         return (temp * temp) / x;     }   }   bool isPrime(int n) {     if (n <= 1) return false;     if (n <= 3) return true;     if (n % 2 == 0 || n % 3 == 0) return false;     for (int i = 5; i * i <= n; i = i + 6)       if (n % i == 0 || n % (i + 2) == 0) return false;     return true;   }   void solve() {     long long int n;     cin >> n;     vector<long long int> a(n);     for (long long int i = 0; i < n; i++) cin >> a[i];     ;     long long int ans = a[0];     long long int t = a[0];     for (long long int i = 1; i < n; i++) {       t += a[i];       ans = min(ans, t);     }     cout << abs(ans) << endl;   }   int main() {     long long int t;     cin >> t;     while (t--) solve();   }


#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1.0);   const double EPS = 1e-6;   int main() {     { ; };     int n;     scanf( %d , &n);     vector<pair<int, int> > V(n);     int totalW = 0;     for (int i = 0; i < n; i++) {       scanf( %d %d , &V[i].first, &V[i].second);       totalW += V[i].first;     }     int res = ((1 << 30) - 1);     for (int maxH = 1; maxH <= 1000; maxH++) {       bool testOK = true;       int coda = n / 2;       int nowW = totalW;       vector<int> candidate;       for (int i = 0; i < n && testOK; i++) {         if (V[i].second > maxH) {           if (V[i].first > maxH)             testOK = false;           else {             if (coda == 0)               testOK = false;             else               nowW += V[i].second - V[i].first;             coda--;           }         } else {           if (V[i].first > V[i].second && V[i].first <= maxH) {             candidate.emplace_back(V[i].second - V[i].first);           }         }       }       if (testOK) {         sort((candidate).begin(), (candidate).end());         nowW += accumulate(             candidate.begin(),             candidate.begin() + min(((int)(candidate).size()), coda), 0);         res = min(res, nowW * maxH);       }     }     printf( %d n , res);     return 0;   }


#include <bits/stdc++.h>   int findMaximalK(int n);   using namespace std;   int main() {     int n, b, p, x, y;     cin >> n >> b >> p;     y = n * p;     x = 0;     int remaining = n;     while (remaining > 1) {       int doingMatch = pow(2, findMaximalK(remaining));       x += doingMatch * b + doingMatch / 2;       int passToNextRound = remaining - doingMatch / 2;       remaining = passToNextRound;     }     cout << x <<     << y;   }   int findMaximalK(int n) {     int count = 0;     while (n > 1) {       n /= 2;       count++;     }     return count;   }


#include <bits/stdc++.h>   using namespace std;   using LL = long long;   const int M = 1e7 + 5;   const int N = 3e5 + 5;   struct node {     vector<int> h, c;     node() {       h.clear();       c.clear();     }     void read(int n) {       int ans;       for (int i = 0; i < n; i++) {         scanf( %d , &ans);         h.push_back(ans);       }       for (int i = 0; i < n; i++) {         scanf( %d , &ans);         c.push_back(ans);       }     }   };   vector<node> a;   int h[M];   LL c[M];   int tl[M], tr[M];   LL dp[M];   stack<int> sk;   void reads(int &n) {     int m, k, q;     LL mul;     scanf( %d%d , &m, &n);     for (int i = 1; i <= m; i++) {       scanf( %d , &k);       node tmp;       tmp.read(k);       a.push_back(tmp);     }     scanf( %d , &q);     n = 0;     while (q--) {       scanf( %d%I64d , &k, &mul);       k--;       for (int i = 0; i < a[k].h.size(); i++) {         h[++n] = a[k].h[i];         c[n] = mul * a[k].c[i];       }     }   }   void make_tl(int n) {     for (int i = n; i >= 1; i--) {       while (!sk.empty() && h[sk.top()] <= sk.top() - i) {         tl[sk.top()] = i + 1;         sk.pop();       }       sk.push(i);     }     while (!sk.empty()) {       tl[sk.top()] = 1;       sk.pop();     }   }   void make_tr(int n) {     for (int i = 1; i <= n; i++) {       while (!sk.empty() && h[sk.top()] <= i - sk.top()) {         tr[sk.top()] = i - 1;         sk.pop();       }       sk.push(i);     }     while (!sk.empty()) {       tr[sk.top()] = n;       sk.pop();     }   }   int main() {     int n;     reads(n);     make_tl(n);     make_tr(n);     for (int i = 1; i <= n; i++) {       dp[i] = dp[tl[i] - 1] + c[i];       while (!sk.empty() && tr[sk.top()] < i) sk.pop();       if (!sk.empty()) dp[i] = min(dp[i], dp[sk.top() - 1] + c[sk.top()]);       if (sk.empty() || dp[sk.top() - 1] + c[sk.top()] > dp[i - 1] + c[i])         sk.push(i);     }     printf( %I64d n , dp[n]);     return 0;   }


#include <bits/stdc++.h>   long long Max(const long long x, const long long y) {     if (x > y) return x;     return y;   }   const long long mo = 1e9 + 7, M = 1005;   char s[M];   long long k, a[M], len, dp[M][M][2];   long long dfs(const long long pos, const long long dis, const bool pd,                 const bool lim) {     if (!pos) return pd;     if (!lim && ~dp[pos][dis][pd]) return dp[pos][dis][pd];     long long res = 0, up = lim ? a[pos] : 9;     for (long long i = 0; i <= up; ++i)       if (i != 4 && i != 7)         res = (res + dfs(pos - 1, Max(dis - 1, 0), pd, lim && i == up)) % mo;       else         res = (res + dfs(pos - 1, k, dis || pd, lim && i == up)) % mo;     if (!lim) dp[pos][dis][pd] = res;     return res;   }   long long check() {     long long last = 0x3f3f3f3f;     for (long long i = len; i; --i)       if (a[i] == 4 || a[i] == 7) {         if (last - i <= k) return 1;         last = i;       }     return 0;   }   signed main() {     memset(dp, -1, sizeof dp);     long long T;     scanf( %lld%lld , &T, &k);     while (T--) {       scanf( %s , s);       len = strlen(s);       for (long long i = 0; i < len; ++i) a[len - i] = s[i] ^ 48;       long long ans = (dfs(len, 0, 0, 1) - check() + mo) % mo;       scanf( %s , s);       len = strlen(s);       for (long long i = 0; i < len; ++i) a[len - i] = s[i] ^ 48;       ans = (dfs(len, 0, 0, 1) - ans + mo) % mo;       printf( %lld n , ans);     }     return 0;   }


#include <bits/stdc++.h>   template <class Class>   void Print(Class instance) {     std::cout << instance << std::endl;   }   void Print() { std::cout << std::endl; }   int main() {     std::ios_base::sync_with_stdio(false);     size_t n;     std::cin >> n;     std::vector<int> time(n + 1);     std::vector<int> paid(n + 1);     size_t hour_pointer = 0;     size_t day_pointer = 0;     int hour_paid = 0;     int day_paid = 0;     for (size_t index = 1; index < n + 1; ++index) {       std::cin >> time[index];       while (time[hour_pointer] + 90 <= time[index]) {         hour_paid -= paid[hour_pointer];         ++hour_pointer;       }       while (time[day_pointer] + 1440 <= time[index]) {         day_paid -= paid[day_pointer];         ++day_pointer;       }       paid[index] = std::min({20, 50 - hour_paid, 120 - day_paid});       hour_paid += paid[index];       day_paid += paid[index];       Print(paid[index]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   multiset<int> s1;   struct node {     char s;     int a1;   } p1[int(1e6 + 50)];   char s[50];   int main() {     int n, a;     while (~scanf( %d , &n)) {       int cnt = 0;       s1.clear();       for (int i = 0; i < n; i++) {         scanf( %s , s);         if (s[0] !=  r ) {           scanf( %d , &a);           if (s[0] ==  i ) {             s1.insert(a);             p1[cnt].s =  i ;             p1[cnt++].a1 = a;           } else if (s[0] ==  g ) {             while (!s1.empty() && (*s1.begin()) < a) {               s1.erase(s1.begin());               p1[cnt++].s =  r ;             }             if (s1.empty() || (!s1.empty() && (*s1.begin()) > a)) {               s1.insert(a);               p1[cnt].s =  i ;               p1[cnt++].a1 = a;             }             p1[cnt].s =  g ;             p1[cnt++].a1 = a;           }         } else {           if (!s1.empty()) {             s1.erase(s1.begin());           } else {             p1[cnt].s =  i ;             p1[cnt++].a1 = 0;           }           p1[cnt++].s =  r ;         }       }       printf( %d n , cnt);       for (int i = 0; i < cnt; i++) {         if (p1[i].s ==  i ) {           printf( insert %d n , p1[i].a1);         } else if (p1[i].s ==  g ) {           printf( getMin %d n , p1[i].a1);         } else if (p1[i].s ==  r ) {           printf( removeMin n );         }       }       puts(  );     }   }


#include <bits/stdc++.h>   using namespace std;   using vi = vector<int>;   using vll = vector<long long>;   using vvll = vector<vll>;   using vpii = vector<pair<int, int> >;   using vpll = vector<pair<long long, long long> >;   using vld = vector<long double>;   using vb = vector<bool>;   const int inf = (int)1e9 + 7;   const long long llinf = (long long)1e18 + 7;   void solve() {     long long n;     cin >> n;     vll a[n];     for (long long i = 0; i < n; i++) {       long long ki;       cin >> ki;       for (long long j = 0; j < ki; j++) {         long long x;         cin >> x;         a[i].push_back(x);       }       sort(a[i].begin(), a[i].end());     }     long long ans = 0;     for (long long i = 0; i < n; i++) {       long long l, r;       l = (i - 1 + n) % n;       r = (i + 1 + n) % n;       for (long long j = 1; j <= (a[i].size()) - 1; j++) {         ans += (upper_bound(a[r].begin(), a[r].end(), a[i][j]) -                     upper_bound(a[r].begin(), a[r].end(), a[i][j - 1]) !=                 upper_bound(a[l].begin(), a[l].end(), a[i][j]) -                     upper_bound(a[l].begin(), a[l].end(), a[i][j - 1]));       }     }     cout << ans <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int ttt = 1;     while (ttt--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<int> yarr(51, 0);     vector<int> xarr(51, 0);     int q = 4 * n + 1;     vector<pair<int, int>> trav;     for (int i = 0; i < q; i++) {       int x, y;       cin >> x >> y;       trav.push_back(make_pair(x, y));       xarr[x]++;       yarr[y]++;     }     int maxy = 0;     int maxx = 0;     int minx = 1000, miny = 1000;     int indexx = 0, indexy = 0;     for (int i = 0; i < 51; i++) {       if (yarr[i] >= n && i > maxy) {         maxy = i;       }       if (xarr[i] >= n && i > maxx) {         maxx = i;       }       if (yarr[i] >= n && i < miny) {         miny = i;       }       if (xarr[i] >= n && i < minx) {         minx = i;       }     }     for (int i = 0; i < trav.size(); i++) {       if (trav[i].first == minx && trav[i].second >= miny &&           trav[i].second <= maxy)         continue;       if (trav[i].first == maxx && trav[i].second >= miny &&           trav[i].second <= maxy)         continue;       if (trav[i].second == miny && trav[i].first >= minx &&           trav[i].first <= maxx)         continue;       if (trav[i].second == maxy && trav[i].first >= minx &&           trav[i].first <= maxx)         continue;       cout << trav[i].first <<     << trav[i].second <<   n ;       break;     }   }


#include <bits/stdc++.h>   using namespace std;   long long s[10], m[10];   const long long md = 1e9 + 7;   string str;   int n;   vector<int> v[100010];   int main() {     for (int i = 0; i <= 9; i++) {       m[i] = 10;       s[i] = i;     }     cin >> str;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       string st;       cin >> st;       v[i].push_back(st[0] -  0 );       for (int j = 3; j < st.size(); j++) v[i].push_back(st[j] -  0 );     }     for (int i = n; i >= 1; i--) {       int cur = v[i][0];       long long mm = 1, ss = 0;       for (int j = 1; j < v[i].size(); j++) {         ss = (ss * m[v[i][j]]) % md;         mm = (mm * m[v[i][j]]) % md;         ss += s[v[i][j]];         if (ss >= md) ss -= md;       }       s[cur] = ss;       m[cur] = mm;     }     long long ans = 0;     for (int i = 0; i < str.size(); i++) {       ans = (ans * m[str[i] -  0 ]) % md;       ans += s[str[i] -  0 ];       if (ans >= md) ans -= md;     }     printf( %lld , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }   long long lcm(long long a, long long b) { return a * (b / gcd(a, b)); }   const int MAXN = 600010;   set<int> g[MAXN];   int n, t, m, k;   int visited[MAXN];   void dfs(int i) {     visited[i] = 1;     for (auto x : g[i])       if (!visited[x]) dfs(x);     return;   }   int main() {     cin >> n;     pair<int, int> a[n];     for (long long i = 0; i < n; i++) cin >> a[i].first >> a[i].second;     sort(a, a + n);     int res = 0;     set<pair<int, pair<int, int> > > s;     for (long long i = 0; i < n; i++) {       auto x =           s.lower_bound({a[i].first, {-((long long)1e15), -((long long)1e15)}});       while (x != s.begin()) {         s.erase(s.begin());       }       auto it =           s.upper_bound({a[i].second, {-((long long)1e15), -((long long)1e15)}});       x = s.begin();       while (x != it) {         g[i].insert(x->second.second);         g[x->second.second].insert(i);         res++;         if (res >= n) {           cout <<  NO                 <<   n ;           return 0;         }         x++;       }       s.insert({a[i].second, {a[i].first, i}});     }     dfs(0);     for (long long i = 0; i < n; i++) {       if (!visited[i]) {         cout <<  NO ;         return 0;       }     }     if (res == n - 1)       cout <<  YES ;     else       cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   int a, b, c;   vector<pair<int, int> > v[200005], e[200005];   int p[200005];   int fin(int x) {     if (p[x] != x) p[x] = fin(p[x]);     return p[x];   }   void onion(int x, int y) {     if (fin(x) == fin(y)) return;     p[fin(y)] = fin(x);   }   priority_queue<pair<long long, pair<int, int> > > q;   int lca[200005][25], maxi[200005][25];   int depth[200005];   long long sum = 0;   long long cen[200005];   void dfs(int node, int prev) {     for (auto it : e[node]) {       if (it.first == prev) continue;       depth[it.first] = depth[node] + 1;       lca[it.first][0] = node;       maxi[it.first][0] = it.second;       dfs(it.first, node);     }   }   int plz(int x, int y) {     if (depth[x] < depth[y]) swap(x, y);     int res = 0;     for (int i = 20; i >= 0; i--) {       if (depth[x] - (1 << i) >= depth[y]) {         res = max(res, maxi[x][i]);         x = lca[x][i];       }     }     if (x == y) return res;     for (int i = 20; i >= 0; i--) {       if (lca[x][i] != lca[y][i]) {         res = max(res, maxi[x][i]);         res = max(res, maxi[y][i]);         x = lca[x][i];         y = lca[y][i];       }     }     res = max(res, maxi[x][0]);     res = max(res, maxi[y][0]);     return res;   }   pair<int, int> rr[200005];   map<pair<int, int>, int> mapa;   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; m >= i; i++) {       scanf( %d%d%d , &a, &b, &c);       rr[i] = {a, b};       cen[i] = c;       v[a].push_back({b, c});       v[b].push_back({a, c});       q.push({-c, {a, b}});     }     for (int i = 1; n >= i; i++) p[i] = i;     while (!q.empty()) {       int cost = -q.top().first;       int u = q.top().second.first;       int uu = q.top().second.second;       q.pop();       if (fin(u) == fin(uu)) continue;       onion(u, uu);       e[u].push_back({uu, cost});       e[uu].push_back({u, cost});       mapa[{u, uu}] = 1;       sum += cost;     }     dfs(1, -1);     for (int j = 1; 20 >= j; j++)       for (int i = 1; n >= i; i++) {         lca[i][j] = lca[lca[i][j - 1]][j - 1];         maxi[i][j] = max(maxi[i][j - 1], maxi[lca[i][j - 1]][j - 1]);       }     int qq;     qq = m;     for (int i = 1; m >= i; i++) {       int a = rr[i].first;       int b = rr[i].second;       if (mapa[{a, b}] == 1) {         printf( %lld n , sum);         continue;       }       long long wynik = 1LL * sum + cen[i] - plz(a, b);       printf( %lld n , wynik);     }   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 3010;   const int INF = 0x3f3f3f3f;   int d[MAXN], e[MAXN];   int main() {     memset(d, INF, sizeof d);     memset(e, INF, sizeof e);     int n;     cin >> n;     string s;     cin >> s;     int at = INF;     for (int i = 0; i < n; i++) {       if (s[i] ==  R )         at = 0;       else if (s[i] ==  L )         at = INF;       d[i] = at;       if (at < INF) at++;     }     at = INF;     for (int i = n - 1; i >= 0; i--) {       if (s[i] ==  R )         at = INF;       else if (s[i] ==  L )         at = 0;       e[i] = at;       if (at < INF) at++;     }     int cont = 0;     for (int i = 0; i < n; i++) {       if (d[i] == e[i]) cont++;     }     cout << cont << endl;   }


#include <bits/stdc++.h>   using namespace std;   inline void Rd(int &res) {     char c;     res = 0;     while (c = getchar(), c <  0 )       ;     do {       res = (res << 1) + (res << 3) + (c ^ 48);     } while (c = getchar(), c >=  0 );   }   const int S = 200;   long long n, s, ans;   int work(long long x) {     int rs = 0;     while (x) {       rs += x % 10;       x /= 10;     }     return rs;   }   int main() {     cin >> n >> s;     for (int i = 1; i <= n && i <= S; i++) {       int sum = work(i);       if (abs(sum - i) >= s) ans++;     }     if (n > S) {       ans += max((long long)0, n - (s + S) + 1);       if (s < S) {         for (long long i = S + 1; i < s + S && i <= n; i++) {           int sum = work(i);           if (abs(sum - i) >= s) ans++;         }       } else {         for (long long i = s; i < s + S && i <= n; i++) {           int sum = work(i);           if (abs(sum - i) >= s) ans++;         }       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long a, b, c, i, fuck = 0;     scanf( %lld , &a);     scanf( %lld , &b);     scanf( %lld , &c);     for (i = a; i >= 1; i--) {       if ((2 * i) <= b && (4 * i) <= c) {         fuck = 1;         break;       }     }     if (fuck == 0)       printf( 0 n );     else       printf( %lld  , i + 2 * i + 4 * i);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 150000;   const int L = 19;   vector<int> edges[N];   long long x[N], y[N];   int anc[N][L], tin[N], tout[N], s[N], moment;   void dfs(int x, int last) {     tin[x] = ++moment;     anc[x][0] = last;     for (int i = 1; i < L; i++) anc[x][i] = anc[anc[x][i - 1]][i - 1];     for (int i = 0; i < edges[x].size(); i++)       if (edges[x][i] != last) dfs(edges[x][i], x);     tout[x] = ++moment;   }   long long coef(int i, int j, int k) {     long long a = y[i] - y[j], b = x[j] - x[i], c = x[i] * y[j] - x[j] * y[i];     return (a * x[k] + b * y[k] + c);   }   bool father(int x, int y) { return (tin[x] <= tin[y] && tout[y] <= tout[x]); }   int lca(int a, int b) {     if (father(a, b)) return a;     if (father(b, a)) return b;     for (int i = L - 1; i >= 0; i--)       if (!father(anc[a][i], b)) a = anc[a][i];     return anc[a][0];   }   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %I64d %I64d , &x[i], &y[i]);     int cnt = 1;     s[cnt] = n;     for (int i = n - 1; i >= 1; i--) {       s[++cnt] = i;       while (cnt > 2 && coef(s[cnt], s[cnt - 2], s[cnt - 1]) < 0)         swap(s[cnt - 1], s[cnt]), cnt--;       edges[s[cnt]].push_back(s[cnt - 1]);       edges[s[cnt - 1]].push_back(s[cnt]);     }     moment = 0, dfs(n, n);     int quests;     scanf( %d , &quests);     for (int i = 1; i <= quests; i++) {       int x, y;       scanf( %d %d , &x, &y);       printf( %d  , lca(x, y));     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast,no-stack-protector,unroll-loops,fast-math )   using namespace std;   const double inf = 1e121;   const double eps = 1e-10;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   long long randint(long long l, long long r) {     long long out = rng() % (r - l + 1) + l;     return out >= l ? out : out + r - l + 1;   }   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 (long long i = 0; i < static_cast<long long>(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)) +  ) ;   }   template <typename A, typename B, typename C, typename D, typename E>   string to_string(tuple<A, B, C, D, E> p) {     return  (  + to_string(get<0>(p)) +  ,  + to_string(get<1>(p)) +  ,  +            to_string(get<2>(p)) +  ,  + to_string(get<3>(p)) +  ,  +            to_string(get<4>(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>   struct is_pair {     static const bool value = false;   };   template <typename T, typename U>   struct is_pair<std::pair<T, U>> {     static const bool value = true;   };   const long long INF = 0x3f3f3f3f3f3f3f3fll;   template <typename T>   typename enable_if<!is_integral<T>::value && !is_pair<T>::value, void>::type   read(T& x) {     cin >> x;   }   long long read() {     char c;     long long out = 0, f = 1;     for (c = getchar(); !isdigit(c) && c !=  - ; c = getchar()) {     }     if (c ==  - ) {       f = -1;       c = getchar();     }     for (; isdigit(c); c = getchar()) out = (out << 3) + (out << 1) + c -  0 ;     return out * f;   }   template <typename T>   typename enable_if<is_integral<T>::value, T>::type read(T& x) {     char c;     T f = 1;     x = 0;     for (c = getchar(); !isdigit(c) && c !=  - ; c = getchar()) {     }     if (c ==  - ) {       f = -1;       c = getchar();     }     for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + c -  0 ;     return x *= f;   }   char read(char& x) {     for (x = getchar(); isspace(x); x = getchar()) {     }     return x;   }   double read(double& x) {     scanf( %lf , &x);     return x;   }   template <typename T>   typename enable_if<!is_integral<T>::value && !is_pair<T>::value, void>::type   write(const T& x) {     cout << x;   }   template <typename T>   typename enable_if<is_integral<T>::value, void>::type write(const T& x) {     if (x < 0) {       putchar( - );       write(-x);       return;     }     if (x > 9) write(x / 10);     putchar(x % 10 +  0 );   }   void write(const char& x) { putchar(x); }   void write(const double& x) { printf( %.10lf , x); }   template <typename T>   typename enable_if<is_pair<T>::value, void>::type read(T& x) {     read(x.first);     read(x.second);   }   template <typename T>   typename enable_if<is_pair<T>::value, void>::type write(const T& x) {     write(x.first);     putchar(   );     write(x.second);   }   template <typename T, typename... Args>   void read(T& x, Args&... args) {     read(x);     read(args...);   }   template <       typename OutputIt,       typename = typename enable_if<           is_same<output_iterator_tag,                   typename iterator_traits<OutputIt>::iterator_category>::value ||           (is_base_of<forward_iterator_tag, typename iterator_traits<OutputIt>::                                                 iterator_category>::value &&            !is_const<OutputIt>::value)>::type>   void read(OutputIt __first, OutputIt __last) {     for (; __first != __last; ++__first) read(*__first);   }   template <       typename InputIt,       typename = typename enable_if<is_base_of<           input_iterator_tag,           typename iterator_traits<InputIt>::iterator_category>::value>::type>   void wts(InputIt __first, InputIt __last) {     bool isFirst = true;     for (; __first != __last; ++__first) {       if (isFirst)         isFirst = false;       else         putchar(   );       write(*__first);     }     putchar(  n );   }   template <       typename InputIt,       typename = typename enable_if<is_base_of<           input_iterator_tag,           typename iterator_traits<InputIt>::iterator_category>::value>::type>   void wtb(InputIt __first, InputIt __last) {     for (; __first != __last; ++__first) {       write(*__first);       putchar(  n );     }   }   template <typename T>   void wts(const T& x) {     write(x);     putchar(   );   }   template <typename T>   void wtb(const T& x) {     write(x);     putchar(  n );   }   template <typename T>   void wte(const T& x) {     write(x);     exit(0);   }   template <typename T, typename... Args>   void wts(const T& x, Args... args) {     wts(x);     wts(args...);   }   template <typename T, typename... Args>   void wtb(const T& x, Args... args) {     wts(x);     wtb(args...);   }   template <typename T, typename... Args>   void wte(const T& x, Args... args) {     wts(x);     wte(args...);   }   template <typename T1, typename T2>   inline bool up(T1& x, const T2& y) {     return x < y ? x = y, 1 : 0;   }   template <typename T1, typename T2>   inline bool dn(T1& x, const T2& y) {     return y < x ? x = y, 1 : 0;   }   template <typename T1, typename T2, typename T3>   inline bool inRange(const T1& x, const T2& l, const T3& r) {     return !(x < l) && !(r < x);   }   template <typename T1, typename T2>   inline auto minOfDifferentTypes(const T1& x, const T2& y)       -> decltype(x < y ? x : y) {     return x < y ? x : y;   }   template <typename T1, typename T2>   inline auto maxOfDifferentTypes(const T1& x, const T2& y)       -> decltype(x < y ? y : x) {     return x < y ? y : x;   }   template <typename T1, typename T2, typename T3>   inline T1& madd(T1& x, const T2& y, const T3& modulo) {     return x = (long long)(x + y + modulo) % modulo;   }   template <typename T1, typename T2, typename T3>   inline T1& mmul(T1& x, const T2& y, const T3& modulo) {     return x = (long long)x * y % modulo;   }   template <typename T1, typename T2, typename T3>   inline long long modadd(long long x, long long y, long long modulo) {     return (x += y) >= modulo ? x - modulo : x;   }   inline long long isinf(long long x) { return x < INF ? x : -1; }   inline void yesno(bool x) { wtb(x ?  Yes  :  No ); }   signed main() {     long long t = read();     while (t--) {       long long n = read();       long long k = read();       if (n >= k && ((n - (k - 1)) & 1)) {         wtb( YES );         for (long long i = (1), iend = (k - 1); i <= iend; ++i) wts(1);         wtb(n - k + 1);       } else if (n >= 2 * k && !(n & 1)) {         wtb( YES );         for (long long i = (1), iend = (k - 1); i <= iend; ++i) wts(2);         wtb(n - 2 * k + 2);       } else         wtb( NO );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, tot, d[105];   int read() {     int _ = 0, ___ = 1;     char __ = getchar();     while (__ >  9  || __ <  0 ) {       if (__ ==  - ) ___ = -1;       __ = getchar();     }     while (__ >=  0  && __ <=  9 ) {       _ = _ * 10 + __ -  0 ;       __ = getchar();     }     return _ * ___;   }   int get(int x) {     int sum = 0;     while (x) {       sum += x % 10;       x /= 10;     }     return sum;   }   int main() {     n = read();     for (int i = max(n - 81, 0); i <= n; i++) {       int x = get(i);       if (x + i == n) d[++tot] = i;     }     printf( %d n , tot);     for (int i = 1; i <= tot; i++) printf( %d  , d[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int prime(int n) {     if (n == 1) {       return 0;     }     for (int i = 2; i * i <= n; i++) {       if (n % i == 0) {         return 0;       }     }     return 1;   }   int main() {     int n;     cin >> n;     int cnt = n;     while (!prime(cnt)) {       cnt++;     }     cout << cnt << endl;     for (int i = 1; i <= n; i++) {       cout << i <<     << i % n + 1 << endl;     }     int now = 1;     while (cnt != n) {       cout << now <<     << n - now << endl;       now++;       cnt--;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   long double PI = acosl(-1);   const long long inf = 3e18;   const int nmax = 1e5 + 5;   const int MAXLG = log2(nmax) + 1;   vector<int> g[nmax];   long long val[nmax], chein[nmax], path[nmax];   long long dfs(int u, int p = 0) {     chein[u] = path[u] = val[u];     vector<long long> mxcheins;     for (int v : g[u])       if (v != p) {         mxcheins.push_back(dfs(v, u));         chein[u] = max(chein[u], chein[v] + val[u]);         path[u] = max(path[u], path[v]);       }     path[u] = max(path[u], chein[u]);     sort(mxcheins.rbegin(), mxcheins.rend());     if (mxcheins.size() > 1)       path[u] = max(path[u], val[u] + mxcheins[0] + mxcheins[1]);     else if (mxcheins.size() > 0)       path[u] = max(path[u], val[u] + mxcheins[0]);     return chein[u];   }   long long dfs2(int u, long long mxpath, long long mxchein, int p = 0) {     multiset<long long> alpath;     multiset<long long> alchein;     for (int v : g[u])       if (v != p) alpath.insert(path[v]), alchein.insert(chein[v]);     alchein.insert(mxchein), alpath.insert(mxpath);     long long ret = mxpath + path[u];     for (int v : g[u])       if (v != p) {         alpath.erase(alpath.find(path[v]));         alchein.erase(alchein.find(chein[v]));         long long mxp2 = *alpath.rbegin(), mxc2 = *alchein.rbegin() + val[u];         if (alchein.size() > 1) {           long long tmp = *alchein.rbegin();           alchein.erase(alchein.find(tmp));           long long tmp2 = *alchein.rbegin();           mxp2 = max(mxp2, val[u] + tmp + tmp2);           alchein.insert(tmp);         } else if (alchein.size() > 0) {           mxp2 = max(mxp2, val[u] + *alchein.rbegin());         }         mxp2 = max(mxp2, mxc2);         ret = max(ret, dfs2(v, mxp2, mxc2, u));         alpath.insert(path[v]), alchein.insert(chein[v]);       }     return ret;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n;     cin >> n;     for (int i = 1; i <= n; i++) cin >> val[i];     for (int i = 1; i < n; i++) {       int u, v;       cin >> u >> v;       g[u].push_back(v);       g[v].push_back(u);     }     dfs(1);     cout << dfs2(1, 0, 0);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, x, k;     cin >> n >> k;     vector<long long> v;     set<long long> s;     map<long long, long long> m;     for (long long i = 0; i < n; i++) {       cin >> x;       if (m[x] == 0) {         m[x]++;         v.insert(v.begin(), x);       }       if (v.size() > k) {         m[v.back()] = 0;         v.pop_back();       }     }     long long a = v.size();     cout << min((a), k) << endl;     for (long long i = 0; i < v.size(); i++) {       cout << v[i] <<    ;     }   }