#include <bits/stdc++.h>   using namespace std;   const int N = 107;   const int M = 107 * 26;   const int inf = (int)1e9 + 7;   const long long base = (long long)1e18;   const double pi = acos(-1);   const double ep = 1e-18;   int dp[107][M];   void solve() {     dp[0][0] = 1;     for (int i = 1; i < N; i++) {       for (int j = 0; j < M; j++) {         for (int t = 0; t <= min(25, j); t++)           dp[i][j] = (dp[i][j] + dp[i - 1][j - t]) % inf;       }     }     int test;     cin >> test;     while (test-- > 0) {       string s;       cin >> s;       int sum = 0;       for (int i = 0; i < s.size(); i++) sum += s[i] -  a ;       cout << dp[s.size()][sum] - 1 << endl;     }   }   int main() {     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     scanf( %d , &n);     int num;     while (n--) {       scanf( %d , &num);       printf( %d n , num > 2 ? num - 2 : 0);     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     while (cin >> n >> k) {       set<int> s;       int l = 0, r = 0;       int ans[200005];       int a;       while (n--) {         cin >> a;         if (s.count(a)) {           continue;         }         s.insert(a);         ans[r++] = a;         if (r > k) {           s.erase(ans[l++]);         }       }       n = min(r - l, k);       cout << n <<   n ;       while (n--) {         cout << ans[--r] <<    ;       }       cout <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const double EPS = 1E-10;   inline int cmp(double x, double y = 0, double tol = EPS) {     return (x <= y + tol) ? (x + tol < y) ? -1 : 0 : 1;   }   char M[440][440];   int C[440][440];   int dy[] = {-1, 0, 1, 0};   int dx[] = {0, -1, 0, 1};   int main() {     int N, K;     cin >> N >> K;     N += 200;     for (int i = 200; i < N; i++)       for (int j = 200; j < N; j++) cin >> M[i][j];     for (int i = 200; i < N; i++)       for (int j = 200; j < N; j++)         if (M[i][j] ==  . ) {           for (int d = 0; d < 4; d++) {             bool ok = 1;             int y = i, x = j;             for (int k = 0; k < K && ok; k++, y += dy[d], x += dx[d])               if (M[y][x] !=  . ) ok = 0;             y = i, x = j;             if (ok)               for (int k = 0; k < K; k++) C[y][x]++, y += dy[d], x += dx[d];           }         }     int rety = 0, retx = 0, ret = 0;     for (int i = 200; i < N; i++)       for (int j = 200; j < N; j++)         if (ret < C[i][j]) ret = C[i][j], rety = i - 200, retx = j - 200;     printf( %d %d n , rety + 1, retx + 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long powi(long long base, int p) {     long long res = 1;     while (p--) res *= base;     return res;   }   long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }   bool is_vowel(char c) {     c = tolower(c);     return c ==  a  || c ==  e  || c ==  o  || c ==  i  || c ==  u  || c ==  y ;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     map<int, int> dict;     for (int i = 0, a; i < n; i++) {       cin >> a;       dict[a]++;     }     bool hh = false;     int res = 0;     for (auto p : dict) {       res += p.second / 4;       int c = p.second % 4;       if (c >= 2 && hh) {         res++;         hh = false;       } else if (c >= 2)         hh = true;     }     cout << res;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   map<long, long> cmap;   map<long, long>::iterator it;   bool visit[200005];   long c[200005];   vector<long> graph[200005];   long res = 0, mac, counter;   void DFS(long node);   int main(void) {     long long n, m, k, i, l, r, j;     cin >> n >> m >> k;     memset(visit, false, sizeof(visit));     for (i = 1; i <= n; i++) cin >> c[i];     for (i = 1; i <= m; i++) {       cin >> l >> r;       graph[l].push_back(r);       graph[r].push_back(l);     }     for (i = 1; i <= n; i++) {       if (!visit[i]) {         mac = 0;         counter = 0;         DFS(i);         for (it = cmap.begin(); it != cmap.end(); it++) {           mac = max(mac, it->second);         }         res += counter - mac;         cmap.clear();       }     }     cout << res;     return 0;   }   void DFS(long node) {     visit[node] = true;     counter++;     cmap[c[node]]++;     long j, i;     for (i = 0; i < graph[node].size(); i++) {       j = graph[node][i];       if (!visit[j]) DFS(j);     }   }


#include <bits/stdc++.h>   using namespace std;   template <class T1, class T2>   inline istream& operator>>(istream& fin, pair<T1, T2>& pr) {     fin >> pr.first >> pr.second;     return fin;   }   template <class T0, class T1, class T2>   inline istream& operator>>(istream& fin, tuple<T0, T1, T2>& t) {     fin >> get<0>(t) >> get<1>(t) >> get<2>(t);     return fin;   }   template <class T>   inline istream& operator>>(istream& fin, vector<T>& a) {     if (!a.size()) {       size_t n;       fin >> n;       a.resize(n);     }     for (auto& u : a) fin >> u;     return fin;   }   string probB() {     vector<string> a(2);     cin >> a;     const auto n = a[0].length();     size_t diff = 0;     for (size_t i = 0; i < n; ++i) diff += a[0][i] != a[1][i];     if (diff & 1) return  impossible ;     string str;     size_t k = 0;     for (size_t i = 0; i < n; ++i)       if (a[0][i] == a[1][i])         str.push_back(a[0][i]);       else if (2 * k < diff)         str.push_back(a[0][i]), ++k;       else         str.push_back(a[1][i]);     return str;   }   int main(const int argc, char* argv[]) {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     cout << probB();     return EXIT_SUCCESS;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 5;   int head[maxn], deg[maxn], ans[maxn], tot = 1;   struct edge {     int v, nex, id;     bool f;   } e[maxn << 4];   void add(int u, int v, int id) {     e[++tot] = {v, head[u], id, 0}, head[u] = tot;     e[++tot] = {u, head[v], id, 0}, head[v] = tot;   }   struct Q {     int l, r;   } q[maxn];   vector<int> a;   void euler(int u) {     for (int &i = head[u]; i; i = e[i].nex) {       if (e[i].f) continue;       e[i].f = e[i ^ 1].f = 1;       int v = e[i].v;       ans[e[i].id] = (u < v);       euler(v);     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> q[i].l >> q[i].r;       q[i].r++;       a.push_back(q[i].l);       a.push_back(q[i].r);     }     sort(a.begin(), a.end());     a.erase(unique(a.begin(), a.end()), a.end());     for (int i = 0; i < n; i++) {       q[i].l = lower_bound(a.begin(), a.end(), q[i].l) - a.begin();       q[i].r = lower_bound(a.begin(), a.end(), q[i].r) - a.begin();       deg[q[i].l]++, deg[q[i].r]++;       add(q[i].l, q[i].r, i);     }     int len = a.size(), last = -1;     for (int i = 0; i < len; i++) {       if (deg[i] & 1) {         if (last == -1)           last = i;         else           add(last, i, n + 3), last = -1;       }     }     for (int i = 0; i < len; i++)       if (head[i]) euler(i);     for (int i = 0; i < n; i++) cout << ans[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string LexicographicallyMaximumSubsequence(string text) {     string localMax =   ;     char current = text.at(text.length() - 1);     localMax += current;     unsigned int size = text.length() - 2;     for (int i = size; i >= 0; i--) {       if (text.at(i) >= current) {         localMax = text.at(i) + localMax;         current = text.at(i);       }     }     return localMax;   }   int main() {     string text;     cin >> text;     cout << LexicographicallyMaximumSubsequence(text) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct Binode {     Binode *z, *o;     void init() {       z = NULL;       o = NULL;     }   } T;   int n;   long long a[100010], o[100010], s[70];   void add(long long x) {     for (int i = 0; i < 61; i++) {       s[i] = x & 1;       x >>= 1;     }     Binode *p = &T;     for (int i = 60; i >= 0; i--) {       if (s[i]) {         if (!(p->o)) {           p->o = new Binode;           p->o->init();         }         p = p->o;       } else {         if (!(p->z)) {           p->z = new Binode;           p->z->init();         }         p = p->z;       }     }   }   long long find(long long x) {     for (int i = 0; i < 61; i++) {       s[i] = x & 1;       x >>= 1;     }     long long ans = 0;     Binode *p = &T;     for (int i = 60; i >= 0; i--) {       if (s[i]) {         if (p->z) {           ans ^= (1LL << i);           p = p->z;         } else           p = p->o;       } else {         if (p->o) {           ans ^= (1LL << i);           p = p->o;         } else           p = p->z;       }     }     return ans;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %I64d , &a[i]);     o[0] = 0;     for (int i = 1; i <= n; i++) o[i] = o[i - 1] ^ a[i];     long long x = 0, ans = 0;     T.init();     for (int i = n; i >= 0; i--) {       add(x);       ans = max(ans, find(o[i]));       x = x ^ a[i];     }     printf( %I64d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   vector<vector<int>> a;   bool inp(int i, int j) {     (i < n && j == n) && inp(i + 1, 0);     (i < n && j < n) && (cin >> a[i][j]);     (i < n && j < n) && (inp(i, j + 1));     return 0;   }   bool floyd(int k, int i, int j) {     (k < n && i < n && j == n) && floyd(k, i + 1, 0);     (k < n && i == n) && floyd(k + 1, 0, 0);     (k < n && i < n && j < n) && floyd(k, i, j + 1);     (k < n && i < n && j < n) && (a[i][j] = min(a[i][j], a[i][k] + a[k][j]));     return 0;   }   void go(int &ans, int i) {     ans = max(ans, *max_element(begin(a[i]), end(a[i])));   }   int main() {     cin.tie(nullptr);     ios_base::sync_with_stdio(0);     cin >> n;     a.assign(20, vector<int>(20));     inp(0, 0);     floyd(0, 0, 0);     int ans = 0;     go(ans, 0);     go(ans, 1);     go(ans, 2);     go(ans, 3);     go(ans, 4);     go(ans, 5);     go(ans, 6);     go(ans, 7);     go(ans, 8);     go(ans, 9);     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int T;   long long n, m;   inline long long Fin(long long w) {     if (!w) return m * (m + 1) / 2;     long long p = w / m, x = Fin(p), t = w % m;     return m * ((m * m + 1) * p + m * t) + m * (m + 1) / 2 +            max(0ll, min(m, (m * m + 1) * p + t * m + m - x + 1));   }   int main() {     scanf( %d , &T);     while (T--) {       scanf( %lld%lld , &n, &m);       long long p = (n - 1) / (m * m + 1), x = Fin(p),                 v1 = (p % m + 1 + m * (p / m)), o = (n - 1) % (m * m + 1);       printf( %lld n , (n == x)                            ? (v1 * (m + 1))                            : (n + p * m + ((o - (n > x)) / m) - v1 + (x > n)));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e3 + 5;   bool adj1[MAXN][MAXN], adj2[MAXN][MAXN];   vector<pair<int, int> > ans1, ans2;   int n;   void comp1(int a, int b) {     if (b - a == 1) return;     for (int i = a + 1; i < b; ++i) {       if (adj1[1][i] == 1) {         comp1(a, i);         comp1(i, b);         return;       }     }     assert(adj1[a][b] == 1);     for (int i = a + 1; i < b; ++i) {       if (adj1[i][a] * adj1[i][b] == 1) {         ans1.push_back(make_pair(a, b));         adj1[a][b] = adj1[b][a] = 0;         adj1[1][i] = adj1[i][1] = 1;         comp1(a, i);         comp1(i, b);         return;       }     }   }   void comp2(int a, int b) {     if (b - a == 1) return;     for (int i = a + 1; i < b; ++i) {       if (adj2[1][i] == 1) {         comp2(a, i);         comp2(i, b);         return;       }     }     assert(adj2[a][b] == 1);     for (int i = a + 1; i < b; ++i) {       if (adj2[i][a] * adj2[i][b] == 1) {         ans2.push_back(make_pair(1, i));         adj2[a][b] = adj2[b][a] = 0;         adj2[1][i] = adj2[i][1] = 1;         comp2(a, i);         comp2(i, b);         return;       }     }   }   int main() {     cin >> n;     for (int i = 0; i < n - 3; ++i) {       int u, v;       cin >> u >> v;       adj1[u][v] = adj1[v][u] = 1;     }     for (int i = 0; i < n - 3; ++i) {       int u, v;       cin >> u >> v;       adj2[u][v] = adj2[v][u] = 1;     }     for (int i = 0; i < n; ++i) {       adj1[i + 1][(i + 1) % n + 1] = adj1[(i + 1) % n + 1][i + 1] =           adj2[i + 1][(i + 1) % n + 1] = adj2[(i + 1) % n + 1][i + 1] = 1;     }     comp1(2, n);     comp2(2, n);     cout << ans1.size() + ans2.size() << endl;     for (int i = 0; i < ans1.size(); ++i)       cout << ans1[i].first <<     << ans1[i].second << endl;     for (int i = ans2.size() - 1; i >= 0; --i)       cout << ans2[i].first <<     << ans2[i].second << endl;   }


#include <bits/stdc++.h>   using namespace std;   long long parent[1000001];   long long result[1000005];   map<int, list<int>> g;   long long getPoints(int p, int t) {     return max((3 * p) / 10, (p - (p / 250) * t));   }   struct Score {     int p, t;   };   bool chc(Score a, Score b) {     if (a.p == b.p) {       return a.t < b.t;     } else {       return a.p < b.p;     }   }   void solve() {     int n;     cin >> n;     int tf = 0, fifty = 0;     vector<int> a(n);     for (int i = 0; i < n; i++) {       cin >> a[i];     }     for (int i = 0; i < n; i++) {       int x = a[i];       if (x == 25) {         tf++;       } else if (x == 50) {         if (tf == 0) {           cout <<  NO n ;           return;         } else {           tf--;         }         fifty++;       } else if (x == 100) {         if (fifty > 0 && tf > 0) {           fifty--;           tf--;         } else if (tf > 2) {           tf = tf - 3;         } else {           cout <<  NO n ;           return;         }       }     }     cout <<  YES n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t = 1;     for (int i = 1; i <= t; i++) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxN = 1e5 + 7;   int n, m;   vector<tuple<int, int, int>> res;   vector<pair<int, int>> g[maxN];   bool blocked[maxN];   bool solve(int v, int pr = -1) {     vector<int> unpaired;     vector<int> adj;     for (auto& to : g[v]) {       if (!blocked[to.second]) {         adj.push_back(to.first);       }       blocked[to.second] = true;     }     for (auto& to : adj) {       if (solve(to, v)) {         unpaired.push_back(to);       }     }     while (unpaired.size() >= 2) {       int first = unpaired.back();       unpaired.pop_back();       int second = unpaired.back();       unpaired.pop_back();       res.push_back(make_tuple(first, v, second));     }     if (unpaired.size() > 0) {       int vertex = unpaired.back();       unpaired.pop_back();       res.push_back(make_tuple(pr, v, vertex));       return false;     }     return true;   }   int main() {     scanf( %d %d , &n, &m);     if (m % 2 == 1) {       printf( No solution n );       return 0;     }     for (int i = 0; i < m; ++i) {       int a, b;       scanf( %d %d , &a, &b);       g[a].push_back({b, i});       g[b].push_back({a, i});     }     solve(1);     for (auto& x : res) {       printf( %d %d %d n , get<0>(x), get<1>(x), get<2>(x));     }     return 0;   }


#include <bits/stdc++.h>   const int mod = 1e9 + 7;   int n, m;   inline long long ksm(register int y, register int p) {     long long x = y, now = 1;     while (p) {       if (p & 1) now = now * x % mod;       x = x * x % mod, p >>= 1;     }     return now;   }   int main() {     scanf( %d%d , &n, &m);     printf( %lld , ksm(2, m) % mod * ksm(n + 1, m - 1) % mod * (n + 1 - m) % mod);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main(int argc, char** argv) {     int n, x, p, min = 0, max = 1000;     cin >> n >> x;     p = x;     for (int i = 0; i < n; i++) {       int a, b;       cin >> a >> b;       if (a < b) {         if ((p >= a) && (p <= b)) {           if (a > min) min = a;           if (b < max) max = b;         } else if (p < a) {           if (a <= max) {             p = a;             if (a > min) min = a;             if (b < max) max = b;           } else {             cout << -1;             return 0;           }         } else if (p > b) {           if (b >= min) {             p = b;             if (a > min) min = a;             if (b < max) max = b;           } else {             cout << -1;             return 0;           }         }       } else {         if ((p >= b) && (p <= a)) {           if (b > min) min = b;           if (a < max) max = a;         } else if (p < b) {           if (b <= max) {             p = b;             if (b > min) min = b;             if (a < max) max = a;           } else {             cout << -1;             return 0;           }         } else if (p > a) {           if (a >= min) {             p = a;             if (b > min) min = b;             if (a < max) max = a;           } else {             cout << -1;             return 0;           }         }       }     }     if ((p - x) >= 0)       cout << p - x;     else       cout << x - p;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<long long int> graph[250];   long long int n, a[250];   long long int visit[250];   long long int sol(long long int pos) {     memset(visit, 0, sizeof(visit));     long long int ans = 0;     long long int c = 0;     while (c <= n) {       long long int f = 0;       for (long long int i = 1; i <= n; i++) {         if (a[i] != pos || visit[i]) {           continue;         }         long long int ff = 1;         for (auto p : graph[i]) {           if (!visit[p]) {             ff = 0;             break;           }         }         if (ff) {           f = 1;           ans++;           c++;           visit[i] = 1;         }       }       if (c == n) {         break;       }       if (!f) {         pos++;         ans++;         if (pos == 4) {           pos = 1;         }       }     }     return ans;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n;     for (long long int i = 1; i <= n; i++) {       cin >> a[i];     }     for (long long int i = 1; i <= n; i++) {       long long int k;       cin >> k;       for (long long int j = 1; j <= k; j++) {         long long int tl;         cin >> tl;         graph[i].push_back(tl);       }     }     long long int ans = 1e18;     for (long long int i = 1; i <= 3; i++) {       ans = min(ans, sol(i));     }     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 1000000;   const int MAX_N = 50000;   const int oo = 1e9;   const int LOGN = 20;   const int Z = 230;   int f[MAX + 1], n, m, a[MAX_N], ans[MAX_N];   struct node {     int nxt[2], val;     multiset<int> mst;     node() {       memset(nxt, -1, sizeof nxt);       val = oo;     }   };   struct query {     int l, r, idx;     query(int _l, int _r, int _idx) { l = _l, r = _r, idx = _idx; }     bool operator<(const query &rhs) const { return r < rhs.r; }   };   vector<query> q[Z];   struct honey {     vector<node> trie;     int ty;     honey(int _ty) { ty = _ty; }     void insert(int u, int depth, int first, int ax, bool add) {       if (!trie.size()) trie.push_back(node());       if (depth == -1) {         if (add)           trie[u].mst.insert(ax);         else           trie[u].mst.erase(trie[u].mst.find(ax));         if (ty == 0) {           trie[u].val = trie[u].mst.size() ? *trie[u].mst.begin() : oo;         } else {           trie[u].val = trie[u].mst.size() ? *--trie[u].mst.end() : -oo;         }         return;       }       bool bt = (first >> depth) & 1;       if (trie[u].nxt[bt] == -1) {         trie[u].nxt[bt] = trie.size();         trie.push_back(node());       }       insert(trie[u].nxt[bt], depth - 1, first, ax, add);       trie[u].val = (!ty ? oo : -oo);       if (trie[u].nxt[bt] != -1) trie[u].val = trie[trie[u].nxt[bt]].val;       if (trie[u].nxt[bt ^ 1] != -1) {         if (!ty)           trie[u].val = min(trie[u].val, trie[trie[u].nxt[bt ^ 1]].val);         else           trie[u].val = max(trie[u].val, trie[trie[u].nxt[bt ^ 1]].val);       }     }     int search(int u, int depth, int first, int ax) {       if (depth == -1 || u == -1 ||           (ty == 0 ? trie[u].val > ax : trie[u].val < ax))         return 0;       bool bt = (first >> depth) & 1;       if (trie[u].nxt[bt ^ 1] != -1 &&           (ty == 0 ? trie[trie[u].nxt[bt ^ 1]].val <= ax                    : trie[trie[u].nxt[bt ^ 1]].val >= ax))         return (1 << depth) + search(trie[u].nxt[bt ^ 1], depth - 1, first, ax);       return search(trie[u].nxt[bt], depth - 1, first, ax);     }     void clear() { trie.clear(); }   };   honey lv[2] = {honey(0), honey(1)};   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < n; ++i) scanf( %d , &a[i]);     for (int i = 0, l, r; i < m; ++i) {       scanf( %d%d , &l, &r);       --l, --r;       q[l / Z].push_back(query(l, r, i));     }     for (int i = 1; i <= MAX; ++i) f[i] = i ^ f[i - 1];     for (int bucket = 0; bucket < Z; ++bucket) {       if (q[bucket].size() == 0) continue;       sort(q[bucket].begin(), q[bucket].end());       int idx = bucket * Z + Z;       int ed = min(n - 1, bucket * Z + Z - 1);       lv[0].clear();       lv[1].clear();       int mx = 0;       for (int j = 0; j < q[bucket].size(); ++j) {         query &sh = q[bucket][j];         while (idx <= sh.r) {           lv[0].insert(0, LOGN, f[a[idx] - 1], a[idx], 1);           mx = max(mx, lv[0].search(0, LOGN, f[a[idx]], a[idx]));           lv[1].insert(0, LOGN, f[a[idx]], a[idx], 1);           mx = max(mx, lv[1].search(0, LOGN, f[a[idx] - 1], a[idx]));           idx++;         }         ans[sh.idx] = mx;         int lf = sh.l, rf = min(ed, sh.r);         for (int p = lf; p <= rf; ++p) {           lv[0].insert(0, LOGN, f[a[p] - 1], a[p], 1);           lv[1].insert(0, LOGN, f[a[p]], a[p], 1);         }         for (int p = lf; p <= rf; ++p) {           ans[sh.idx] = max(ans[sh.idx], lv[0].search(0, LOGN, f[a[p]], a[p]));           ans[sh.idx] =               max(ans[sh.idx], lv[1].search(0, LOGN, f[a[p] - 1], a[p]));         }         for (int p = lf; p <= rf; ++p) {           lv[0].insert(0, LOGN, f[a[p] - 1], a[p], 0);           lv[1].insert(0, LOGN, f[a[p]], a[p], 0);         }       }     }     for (int i = 0; i < m; ++i) {       printf( %d n , ans[i]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   int mat[505][505];   const int N = 3e5 + 10, C = 26, inf = 1e7;   bool check(int i, int j) {     if ((i - 1 > 0 || i - 1 == 0) && mat[i - 1][j] == 1) {       return 1;     }     if ((j - 1 > 0 || j - 1 == 0) && mat[i][j - 1] == 1) {       return 1;     }     if (mat[i + 1][j] == 1 && i < n) {       return 1;     }     if (mat[i][j + 1] == 1 && j < m) {       return 1;     }     return 0;   }   void FUSE() {     cin >> n >> m;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         char t;         cin >> t;         if (t ==  S )           mat[i][j] = -1;         else if (t ==  W )           mat[i][j] = 1;         else           mat[i][j] = 0;       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (mat[i][j] == -1 && check(i, j)) {           cout <<  No n ;           return;         }       }     }     cout <<  Yes n ;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (mat[i][j] == -1)           cout <<  S ;         else if (mat[i][j] == 1)           cout <<  W ;         else           cout <<  D ;       }       cout <<   n ;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int T = 1;     while (T--) {       FUSE();     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = (int)1e5 + 100;   int dp[N];   int b[N];   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) cin >> b[i];     int Max = 0;     vector<int> v;     for (int i = 0; i < n; i++) {       while (!v.empty()) {         int ind = v.back();         if (b[ind] < b[i]) {           dp[i] = max(dp[i], dp[ind] + 1);           v.pop_back();         } else {           dp[i] = max(dp[i], 1);           break;         }       }       if (v.empty()) dp[i] = 0;       Max = max(Max, dp[i]);       v.push_back(i);     }     cout << Max;     cin >> n;   }


#include <bits/stdc++.h>   using namespace std;   const int dx[9] = {0, 1, -1, 0, 0, -1, -1, 1, 1};   const int dy[9] = {0, 0, 0, -1, 1, -1, 1, -1, 1};   const double pi = acos(-1.0);   const int N = 110;   long long n, m, ans;   void input_data() { cin >> n >> m; }   void get_ans() {     if (n <= m) {       ans = n;       return;     }     n -= (m + 1);     if (n <= 0) {       ans = m + 1;       return;     }     long long l = 0, r = 2e9 + 2, t = 0;     ans = m;     while (l <= r) {       long long mid = (l + r) >> 1;       long long temp = (mid + 2) * (mid - 1) / 2;       if (temp >= n) {         t = mid;         r = mid - 1;       } else         l = mid + 1;     }     ans += t;   }   void o() { cout << ans << endl; }   int main() {     input_data();     get_ans();     o();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   void solve() {     int n, x;     cin >> n >> x;     vector<int> cs(n);     for (auto& c : cs) {       cin >> c;     }     int c_sum = accumulate(cs.begin(), cs.end(), 0);     vector<vector<T>> mass(n + 1, vector<T>(c_sum + 1, 0));     mass[0][0] = T(1);     for (int c : cs) {       for (int k = n - 1; k >= 0; --k) {         for (int s = c_sum - c; s >= 0; --s) {           mass[k + 1][s + c] += T(k + 1) / T(n - k) * mass[k][s];         }       }     }     T answer(0);     for (int k = 1; k <= n; ++k) {       for (int s = 0; s <= c_sum; ++s) {         answer +=             min(T(s) / T(k), T(x) / T(2) * (T(1) + T(n) / T(k))) * mass[k][s];       }     }     printf( %.17f n , (double)answer);   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     solve<double>();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 210;   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }   long long LCM = 1, limit, X;   int n, a[MAXN];   bool inCir[MAXN];   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     for (int i = 1; i <= n; i++) {       int x = i, Len = 0;       for (int j = 1; j <= n; j++) x = a[x];       while (!inCir[x]) inCir[x] = true, x = a[x], Len++;       if (Len) LCM = lcm(LCM, Len);     }     for (int i = 1; i <= n; i++) {       int x = i, Len = 0;       while (!inCir[x]) x = a[x], Len++;       limit = max(limit, (long long)Len);     }     X = LCM;     while (X < limit) X += LCM;     printf( %I64d n , X);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct SegmentTree {     int n;     struct node {       long long add, mn;       node() {}       node(long long v) : mn(v), add(0) {}     };     vector<node> tree;     void push(int id, int l, int r) {       if (tree[id].add != 0) {         int m = (l + r) >> 1;         apply(id << 1, l, m, tree[id].add);         apply(id << 1 | 1, m + 1, r, tree[id].add);         tree[id].add = 0;       }     }     void apply(int id, int l, int r, long long add) {       tree[id].mn += add;       tree[id].add += add;     }     void pull(int id) {       tree[id].mn = min(tree[id << 1].mn, tree[id << 1 | 1].mn);     }     SegmentTree(int n) : n(n), tree(4 * n) {}     SegmentTree(const vector<long long> &v) {       n = (int)v.size();       tree.resize(4 * n);       function<void(int, int, int)> build = [&](int id, int l, int r) {         if (l == r) {           tree[id] = v[l];           return;         }         push(id, l, r);         int m = (l + r) >> 1;         build(id << 1, l, m);         build(id << 1 | 1, m + 1, r);         pull(id);       };       build(1, 0, n - 1);     }     void rangeadd(int id, int l, int r, int ql, int qr, long long add) {       if (l > qr || r < ql) {         return;       }       if (ql <= l && r <= qr) {         apply(id, l, r, add);         return;       }       push(id, l, r);       int m = (l + r) >> 1;       rangeadd(id << 1, l, m, ql, qr, add);       rangeadd(id << 1 | 1, m + 1, r, ql, qr, add);       pull(id);     }     void rangeadd(int ql, int qr, long long add) {       rangeadd(1, 0, n - 1, ql, qr, add);     }   };   void solve() {     int N;     cin >> N;     vector<int> P(N), pos(N);     for (int i = 0; i < N; i++) {       cin >> P[i];       P[i]--;       pos[P[i]] = i;     }     vector<int> A(N);     for (int i = 0; i < N; i++) {       cin >> A[i];     }     vector<long long> init(N - 1);     for (int i = 0; i < N - 1; i++) {       init[i] = (i == 0 ? 0 : init[i - 1]) + A[i];     }     SegmentTree st(init);     long long ans = A[0];     for (int i = 0; i < N; i++) {       st.rangeadd(0, pos[i] - 1, A[pos[i]]);       st.rangeadd(pos[i], N - 2, -A[pos[i]]);       ans = min(ans, st.tree[1].mn);     }     cout << ans <<   n ;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t = 1;     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       int arr[n];       for (int i = 0; i < n; i++) cin >> arr[i];       if (n < 6) {         cout << 0 <<     << 0 <<     << 0 << endl;         continue;       }       int index = (n / 2) - 1;       while (index >= 0 && arr[index] == arr[index + 1]) index--;       vector<int> count;       int sum = 0;       for (int i = index; i >= 0; i--) {         int temp = 1;         int j = i - 1;         while (j >= 0 && arr[j] == arr[i]) {           j--;           temp++;         }         count.push_back(temp);         sum += temp;         i = j + 1;       }       if (count.size() < 3) {         cout << 0 <<     << 0 <<     << 0 << endl;         continue;       }       sum -= count[count.size() - 1];       int g = count[count.size() - 1], s = 0, b = 0;       bool ans = 0;       for (int i = 0; i < count.size() - 1; i++) {         b += count[i];         s = sum - b;         if (g < b && g < s) {           ans = 1;           break;         }       }       if (ans == 1)         cout << g <<     << s <<     << b << endl;       else         cout << 0 <<     << 0 <<     << 0 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long cal(long long x, long long a) {     long long y = a, ans = 0, cnt = 1;     while (x / (long long)(pow(a, cnt)) != 0) {       ans += x / (long long)(pow(a, cnt));       cnt++;     }     return ans;   }   signed main() {     long long n, b, mx = LLONG_MAX;     vector<long long> v, k;     cin >> n >> b;     for (long long i = 2; i * i <= b; i++) {       if (b % i == 0) {         long long cnt = 0;         v.push_back(i);         while (b % i == 0) {           b = b / i;           cnt++;         }         k.push_back(cnt);       }     }     if (b != 1) v.push_back(b), k.push_back(1);     for (long long i = 0; i < v.size(); i++) {       mx = min(cal(n, v[i]) / k[i], mx);     }     cout << mx;   }


#include <bits/stdc++.h>   const double PI = 2.0 * acos(0.0);   const double EPS = 1e-9;   using namespace std;   int dr[] = {-1, 0, 1, 0, 1, 1, -1, -1};   int dc[] = {0, 1, 0, -1, -1, 1, -1, 1};   int V, E;   int T;   int N, M, K;   string S;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cin >> N >> K;     int ans[5010];     int i, j;     map<int, vector<int>> m;     for (i = 0; i <= N - 1; i++) cin >> j, m[j].push_back(i);     int col = 0;     for (auto x : m) {       if (x.second.size() > K) {         cout <<  NO  << endl;         return 0;       } else {         for (j = 0; j <= x.second.size() - 1; j++) {           ans[x.second[j]] = col % K + 1;           col++;         }       }     }     cout <<  YES  << endl;     for (i = 0; i <= N - 1; i++) cout << ans[i] <<    ;     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 50;   const long long MAXN = 1e18 + 10;   const int MAX = 1e5 + 10;   const long long mod = 1e9 + 7;   const int inf = 0x3f3f3f3f;   const long long INF = 0x3f3f3f3f3f3f3f3f;   const double eps = 1e-7;   inline void solve() {     int n, w;     scanf( %d , &n);     scanf( %d , &w);     int minn = 0, maxn = w;     bool flag = false;     for (int i = 0; i < n; ++i) {       int temp;       scanf( %d , &temp);       if (temp < 0) {         minn += (-temp);         if (minn > w) flag = true;         maxn = min(w, maxn - temp);       } else if (temp > 0) {         maxn -= temp;         if (maxn < 0) flag = true;         minn = max(0, minn - temp);       }       if (maxn < minn) flag = true;     }     if (flag)       printf( 0 n );     else       printf( %d n , maxn - minn + 1);     return;   }   int main() {     int casen = 1;     while (casen--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     cin.get();     string s;     getline(cin, s);     vector<int> pref(n);     for (int i = 0; i < n; ++i) {       if (i != 0) pref[i] = pref[i - 1];       pref[i] += s[i] ==  (  ? +1 : -1;     }     if (pref[n - 1] != 0) {       cout <<  0 n1 1 n ;       return 0;     }     int min_pos = min_element(pref.begin(), pref.end()) - pref.begin() + 1;     if (min_pos == n) min_pos = 0;     rotate(s.begin(), s.begin() + min_pos, s.end());     for (int i = 0; i < n; ++i) {       pref[i] = 0;       if (i != 0) pref[i] = pref[i - 1];       pref[i] += s[i] ==  (  ? +1 : -1;       assert(pref[i] >= 0);     }     vector<int> merged;     vector<vector<int>> pos(2);     vector<vector<int>> cnt(n, vector<int>(3));     pos[0].emplace_back(-1);     merged.emplace_back(-1);     for (int i = 0; i < n; ++i) {       if (i != 0) cnt[i] = cnt[i - 1];       if (pref[i] < 3) {         cnt[i][pref[i]] += 1;         if (pref[i] < 2) {           merged.emplace_back(i);           pos[pref[i]].emplace_back(i);         }       }     }     tuple<int, int, int> ans((int)pos[0].size() - 1, 0, 0);     for (int i = 0; i + 1 < (int)pos[0].size(); ++i) {       int l = pos[0][i], r = pos[0][i + 1];       int cnt_1 = cnt[r][1] - (l >= 0 ? cnt[l][1] : 0);       ans = max(ans, make_tuple(cnt_1, l + 1, r));     }     for (int i = 0; i + 1 < (int)merged.size(); ++i) {       int l = merged[i], r = merged[i + 1];       if (s[l + 1] == s[r]) continue;       int cnt_2 = cnt[r][2] - (l >= 0 ? cnt[l][2] : 0);       ans = max(ans, make_tuple(cnt_2 + (int)pos[0].size() - 1, l + 1, r));     }     int res, l, r;     tie(res, l, r) = ans;     (l += min_pos) %= n;     (r += min_pos) %= n;     cout << res << endl;     cout << 1 + l <<     << 1 + r << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     ;     long long i, j, k, l, r, m, n, o, t;     cin >> n;     cin >> l >> r;     char str[100001];     cin >> str;     long long len = strlen(str);     l--;     r--;     if (str[l] == str[r]) {       cout << 0 << endl;       return 0;     }     cout << 1 << endl;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> vec;   int result[50000];   int MIN(int i, int j) {     int ans = 1e9;     for (int a = i; a <= j; a++) {       ans = min(ans, vec[a]);     }     return ans;   }   int main() {     int n, m;     scanf( %d %d , &n, &m);     for (int i = 0; i < (n); i++) vec.push_back(i + 1);     int limit = 1;     for (int i = 0; i < (n); i++) limit *= (i + 1);     int sum, mx = 0, realsum = 0;     for (int z = 0; z < (limit); z++) {       for (int i = 0; i < (n); i++) {         sum = 0;         for (int j = i; j < n; j++) sum += MIN(i, j);         ;         realsum += sum;       }       if (realsum > mx) mx = realsum;       result[z] = realsum;       realsum = 0;       next_permutation(vec.begin(), vec.end());     }     vector<int> sol;     for (int i = 0; i < (n); i++) sol.push_back(i + 1);     int cnt = 0;     for (int z = 0; z < (limit); z++) {       if (result[z] == mx) {         cnt++;         if (cnt == m) {           printf( %d , sol[0]);           for (int i = 1; i < n; i++) printf(  %d , sol[i]);           printf(  n );           break;         }       }       next_permutation(sol.begin(), sol.end());     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007;   const int N = 1e5 + 9;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     int x;     cin >> x;     long long ans = 0, c = 0;     int y[x];     for (int i = 0; i < x; i++) cin >> y[i];     for (int i = x - 1; i >= 0; i--) {       if (!y[i])         c++;       else         ans += c;     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MX = 102, md = 1000000007;   int n, k, i, j, e, c[MX][MX], f[MX][MX * MX];   long long m, p[MX], q[MX];   bool ifq;   long long pw(long long a, long long b) {     if (b == 0) return 1LL;     if (b & 1) return (a * pw(a, b - 1)) % md;     long long x = pw(a, b / 2);     return (x * x) % md;   }   int main() {     cin >> n >> m >> k;     for (i = 0; i <= n; i++) {       c[i][0] = 1;       for (j = 1; j <= i; j++) c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % md;     }     for (i = 0; i <= n; i++) {       p[i] = pw(c[n][i], m / n);       q[i] = (p[i] * c[n][i]) % md;     }     f[0][0] = 1;     for (i = 0; i < n; i++) {       ifq = (i < (m % n));       for (j = 0; j <= k; j++)         if (f[i][j])           for (e = 0; e <= n && j + e <= k; e++)             f[i + 1][j + e] =                 (f[i + 1][j + e] + f[i][j] * (ifq ? q[e] : p[e])) % md;     }     cout << f[n][k] <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const long long INFF = 0x3f3f3f3f3f3f3f3f;   const double pi = acos(-1.0);   const double eps = 1e-9;   const long long mod = 1e9 + 7;   int read() {     int x = 0, f = 1;     char ch = getchar();     while (ch< 0  | ch>  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x * f;   }   void Out(int aa) {     if (aa > 9) Out(aa / 10);     putchar(aa % 10 +  0 );   }   int x[505], y[505];   int dp[1010][1010];   int n, m, k;   bool check(int t) {     vector<int> X, Y;     X.push_back(1), X.push_back(n + 1);     Y.push_back(1), Y.push_back(m + 1);     for (int i = 1; i <= k; i++) {       X.push_back(max(x[i] - t, 1)), X.push_back(min(n + 1, x[i] + t + 1));       Y.push_back(max(1, y[i] - t)), Y.push_back(min(m + 1, y[i] + t + 1));     }     sort(X.begin(), X.end());     X.erase(unique(X.begin(), X.end()), X.end());     sort(Y.begin(), Y.end());     Y.erase(unique(Y.begin(), Y.end()), Y.end());     memset(dp, 0, sizeof(dp));     for (int i = 1; i <= k; i++) {       int l1 = lower_bound(X.begin(), X.end(), max(x[i] - t, 1)) - X.begin();       int l2 =           lower_bound(X.begin(), X.end(), min(x[i] + t + 1, n + 1)) - X.begin();       int r1 = lower_bound(Y.begin(), Y.end(), max(y[i] - t, 1)) - Y.begin();       int r2 =           lower_bound(Y.begin(), Y.end(), min(y[i] + t + 1, m + 1)) - Y.begin();       dp[l1][r1]++, dp[l2][r2]++;       dp[l1][r2]--;       dp[l2][r1]--;     }     int l = n + 1, r = 0;     int u = m + 1, d = 0;     for (int i = 0; i < X.size() - 1; i++)       for (int j = 0; j < Y.size() - 1; j++) {         if (i && j)           dp[i][j] += -dp[i - 1][j - 1] + dp[i][j - 1] + dp[i - 1][j];         else if (i)           dp[i][j] += dp[i - 1][j];         else if (j)           dp[i][j] += dp[i][j - 1];         if (dp[i][j]) continue;         l = min(l, X[i]);         r = max(r, X[i + 1] - 1);         u = min(u, Y[j]);         d = max(d, Y[j + 1] - 1);       }     return max(r - l, d - u) <= 2 * t;   }   int main() {     n = read(), m = read(), k = read();     for (int i = 1; i <= k; i++) x[i] = read(), y[i] = read();     int l = 0, r = max(n, m);     int ans = r;     while (r >= l) {       int mid = (l + r) / 2;       if (check(mid))         ans = mid, r = mid - 1;       else         l = mid + 1;     }     Out(ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int tr[400], ar[400];   vector<pair<int, int> > vv;   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) cin >> ar[i];     for (int i = 0; i < n; i++) cin >> tr[i];     for (int i = 0; i < n; i++) {       if (tr[i] == ar[i]) continue;       int j;       for (j = i + 1; j < n; j++)         if (tr[j] == ar[i]) break;       for (j = j - 1; j >= i; j--) {         int tmp = tr[j];         tr[j] = tr[j + 1];         tr[j + 1] = tmp;         vv.push_back(make_pair(j, j + 1));       }     }     if (vv.size() >= 1000000) return -1;     cout << vv.size() << endl;     for (int i = 0; i < vv.size(); i++) {       cout << vv[i].first + 1 <<     << vv[i].second + 1 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long inf = 1e15 + 9;   const long long N = 1e5 + 5;   long long A[N], n, k, B[N];   map<long long, long long> mm;   void solve() {     long long i, j, x = 0, y = 1, m;     cin >> n;     for (i = 0; i < n; i++) {       cin >> x >> y;       mm[x] = max(mm[x], y);     }     cin >> m;     for (i = 0; i < m; i++) {       cin >> x >> y;       mm[x] = max(mm[x], y);     }     x = 0;     for (auto i : mm) x += i.second;     cout << x;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long t = 1, i;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   struct ji {     int nex, to;   } edge[100005 << 1];   set<pair<int, int> > s[100005];   set<pair<int, int> >::iterator it;   priority_queue<pair<int, int> > q;   pair<int, int> ans[100005];   int E, n, r, x, y, z, cnt, head[100005], sz[100005], mx[100005], f[100005],       d[100005];   long long m;   void add(int x, int y) {     edge[E].nex = head[x];     edge[E].to = y;     head[x] = E++;   }   void dfs(int k, int fa) {     sz[k] = 1;     mx[k] = 0;     for (int i = head[k]; i != -1; i = edge[i].nex)       if (edge[i].to != fa) {         dfs(edge[i].to, k);         sz[k] += sz[edge[i].to];         mx[k] = max(mx[k], sz[edge[i].to]);       }     if (max(n - sz[k], mx[k]) <= n / 2) r = k;   }   void dfs(int k, int fa, int sh) {     f[k] = fa;     d[k] = sh;     m -= sh;     s[x].insert(make_pair(sh, k));     sz[k] = 1;     for (int i = head[k]; i != -1; i = edge[i].nex)       if (edge[i].to != fa) {         dfs(edge[i].to, k, sh + 1);         sz[k] += sz[edge[i].to];       }   }   int main() {     scanf( %d%lld , &n, &m);     memset(head, -1, sizeof(head));     for (int i = 1; i < n; i++) {       scanf( %d%d , &x, &y);       add(x, y);       add(y, x);     }     dfs(1, 0);     for (int i = head[r]; i != -1; i = edge[i].nex) {       x = edge[i].to;       dfs(x, r, 1);       q.push(make_pair(sz[x], x));     }     if ((m > 0) || (m % 2)) {       printf( NO );       return 0;     }     m /= -2;     while (m) {       x = q.top().second;       q.pop();       if (sz[x] < 2) {         printf( NO );         return 0;       }       sz[x] -= 2;       if (sz[x]) q.push(make_pair(sz[x], x));       if ((*--s[x].end()).first - 1 <= m) {         y = (*--s[x].end()).second;         s[x].erase(--s[x].end());         m -= d[y] - 1;         z = f[y];         bool flag = 0;         for (int i = head[z]; i != -1; i = edge[i].nex)           if ((edge[i].to != f[z]) && (edge[i].to != y) &&               (s[x].find(make_pair(d[edge[i].to], edge[i].to)) != s[x].end())) {             ans[++cnt] = make_pair(edge[i].to, y);             s[x].erase(make_pair(d[edge[i].to], edge[i].to));             flag = 1;             break;           }         if (!flag) {           ans[++cnt] = make_pair(z, y);           s[x].erase(make_pair(d[z], z));         }       } else {         it = lower_bound(s[x].begin(), s[x].end(), make_pair((int)m, 0));         while ((*it).first == m) {           bool flag = 0;           y = (*it).second;           for (int i = head[y]; i != -1; i = edge[i].nex)             if ((edge[i].to != f[y]) &&                 (s[x].find(make_pair(d[edge[i].to], edge[i].to)) != s[x].end())) {               ans[++cnt] = make_pair(y, edge[i].to);               s[x].erase(make_pair(d[y], y));               s[x].erase(make_pair(d[edge[i].to], edge[i].to));               flag = 1;               break;             }           if (flag) break;           it++;         }         m = 0;       }     }     while (!q.empty()) {       x = q.top().second;       q.pop();       if (q.empty()) {         ans[++cnt] = make_pair((*s[x].begin()).second, r);         break;       }       y = q.top().second;       q.pop();       if (sz[x] > 1) q.push(make_pair(--sz[x], x));       if (sz[y] > 1) q.push(make_pair(--sz[y], y));       ans[++cnt] = make_pair((*s[x].begin()).second, (*s[y].begin()).second);       s[x].erase(s[x].begin());       s[y].erase(s[y].begin());     }     printf( YES n );     for (int i = 1; i <= cnt; i++) printf( %d %d n , ans[i].first, ans[i].second);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int n;     cin >> n;     vector<long long int> v;     for (long long int i = 0; i < n; i++) {       long long int x;       cin >> x;       v.push_back(x);     }     long long int z;     long long int count = 1;     for (long long int i = 0;; i++) {       if (n == count) {         z = i;         break;       } else         count *= 4;     }     sort(v.begin(), v.end());     reverse(v.begin(), v.end());     long long int prev = 0;     long long int end = 1;     vector<long long int> ans;     while (prev < n) {       long long int sum = 0;       for (long long int j = prev; j < end; j++) sum += v[j];       ans.push_back(sum);       sum = 0;       prev = end;       end *= 4;     }     long long int fin = 0;     long long int calc = z + 1;     for (long long int j = 0; j < ans.size(); j++) {       fin += ans[j] * calc;       calc--;     }     cout << fin;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) {     while (b) {       a %= b;       swap(a, b);     }     return a;   }   long long lcm(const long long &a, const long long &b) {     return (a / gcd(a, b)) * b;   }   bool check(long long a) {     int k = 0;     while (a > 0) {       if (!(a & 1)) {         k++;       }       a >>= 1;     }     return k == 1;   }   int bits(long long a) {     int k = 0;     if (a == 0) {       return 1;     }     while (a > 0) {       k++;       a >>= 1;     }     return k;   }   int main() {     int h, w;     cin >> h >> w;     char c;     vector<vector<int>> a(h + 2, vector<int>(w + 2, 1));     for (int i = 1; i <= h; i++) {       for (int j = 1; j <= w; j++) {         cin >> c;         if (c ==  . ) {           a[i][j] = 0;         } else           a[i][j] = 1;       }     }     vector<vector<pair<int, int>>> v(h + 2, vector<pair<int, int>>(w + 2));     for (int i = 1; i <= h; i++) {       for (int j = 1; j <= w; j++) {         v[i][j].first = v[i][j - 1].first + (a[i][j - 1] + a[i][j] == 0 ? 1 : 0);       }     }     for (int j = 1; j <= w; j++) {       for (int i = 1; i <= h; i++) {         v[i][j].second =             v[i - 1][j].second + (a[i - 1][j] + a[i][j] == 0 ? 1 : 0);       }     }     int q;     cin >> q;     int l1, r1, l2, r2;     int ans = 0, s1, s2;     for (int i = 0; i < q; i++) {       cin >> l1 >> r1 >> l2 >> r2;       ans = 0;       s1 = 0;       s2 = 0;       for (int j = l1; j <= l2; j++) {         s1 = v[j][r2].first - v[j][r1].first;         ans += s1;       }       for (int j = r1; j <= r2; j++) {         s2 = v[l2][j].second - v[l1][j].second;         ans += s2;       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     int n, m;     cin >> n >> m;     vector<int> v[n + 1];     for (int i = 0; i < m; i++) {       int a, b;       cin >> a >> b;       v[a].push_back(b);     }     int cnt[n + 1];     for (int o = 1; o <= n; o++) {       for (int i = 0; i < (int)v[o].size(); i++) {         if (o < v[o][i])           v[o][i] -= o;         else           v[o][i] = n - (o - v[o][i]);       }       sort(v[o].begin(), v[o].end());       if (!v[o].empty())         cnt[o] = ((v[o].size() - 1) * n + v[o][0]);       else         cnt[o] = 0;     }     for (int o = 1; o <= n; o++) {       int res = cnt[o];       int mv = 0;       for (int i = o + 1;; i++) {         mv++;         if (i == n + 1) i = 1;         if (i == o) break;         res = max(res, (cnt[i] != 0) * (cnt[i] + mv));       }       cout << res <<    ;     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void __print(int x) { cerr << x; }   void __print(long x) { cerr << x; }   void __print(long long x) { cerr << x; }   void __print(unsigned x) { cerr << x; }   void __print(unsigned long x) { cerr << x; }   void __print(unsigned long long x) { cerr << x; }   void __print(float x) { cerr << x; }   void __print(double x) { cerr << x; }   void __print(long double x) { cerr << x; }   void __print(char x) { cerr <<      << x <<     ; }   void __print(const char *x) { cerr <<     << x <<    ; }   void __print(const string &x) { cerr <<     << x <<    ; }   void __print(bool x) { cerr << (x ?  true  :  false ); }   template <typename T, typename V>   void __print(const pair<T, V> &x) {     cerr <<  { ;     __print(x.first);     cerr <<  , ;     __print(x.second);     cerr <<  } ;   }   template <typename T>   void __print(const T &x) {     int f = 0;     cerr <<  { ;     for (auto &i : x) cerr << (f++ ?  ,  :   ), __print(i);     cerr <<  } ;   }   void _print() { cerr <<  ] n ; }   template <typename T, typename... V>   void _print(T t, V... v) {     __print(t);     if (sizeof...(v)) cerr <<  ,  ;     _print(v...);   }   struct SegTree {     long long tree[4 * 200005];     long long lazy[4 * 200005];     void push(long long node) {       tree[2 * node + 1] += lazy[node];       tree[2 * node + 2] += lazy[node];       lazy[2 * node + 1] += lazy[node];       lazy[2 * node + 2] += lazy[node];       lazy[node] = 0;     }     void build(vector<long long> &a, long long node, long long start,                long long end) {       if (start == end) {         tree[node] = a[start];         return;       }       long long mid = (start + end) >> 1;       build(a, 2 * node + 1, start, mid);       build(a, 2 * node + 2, mid + 1, end);       tree[node] = min(tree[2 * node + 1], tree[2 * node + 2]);     }     void rupd(long long node, long long start, long long end, long long l,               long long r, long long val) {       if (r < start || l > end) return;       if (l <= start && end <= r) {         tree[node] += val;         lazy[node] += val;         return;       }       push(node);       long long mid = (start + end) >> 1;       rupd(2 * node + 1, start, mid, l, r, val);       rupd(2 * node + 2, mid + 1, end, l, r, val);       tree[node] = min(tree[2 * node + 1], tree[2 * node + 2]);     }     long long rquery(long long node, long long start, long long end, long long l,                      long long r) {       if (r < start || l > end) return 1000000000000005;       if (l <= start && end <= r) return tree[node];       push(node);       long long mid = (start + end) >> 1;       long long p1 = rquery(2 * node + 1, start, mid, l, r);       long long p2 = rquery(2 * node + 2, mid + 1, end, l, r);       return min(p1, p2);     }   } st;   void solve() {     long long n;     cin >> n;     vector<long long> p(n);     vector<long long> rp(n);     for (long long i = 0; i < n; i++) {       cin >> p[i];       p[i]--;       rp[p[i]] = i;     }     vector<long long> a(n);     for (long long i = 0; i < n; i++) cin >> a[i];     vector<long long> b(n);     b[0] = a[0];     for (long long i = 1; i < n; i++) {       b[i] = b[i - 1] + a[i];     }     st.build(b, 0, 0, n - 1);     long long ans = st.rquery(0, 0, n - 1, 0, n - 1);     for (long long i = 0; i < (n); i++) {       long long pos = rp[i];       st.rupd(0, 0, n - 1, pos, n - 1, -a[pos]);       if (pos) st.rupd(0, 0, n - 1, 0, pos - 1, a[pos]);       ans = min(ans, st.rquery(0, 0, n - 1, 0, n - 2));     }     cout << ans <<   n ;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long tests;     tests = 1;     for (long long i = 0; i < tests; i++) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 5e4 + 10;   int b[MAXN], n, a[MAXN];   int ID(int x) {     x = x % n;     if (x < 0) x += n;     return x;   }   int main(void) {     scanf( %d , &n);     for (int i = 0; i < n; ++i) scanf( %d , a + i);     vector<pair<int, int> > foo;     for (int i = 0; i < n; ++i) foo.push_back(make_pair(a[i] + a[ID(i + 1)], i));     sort(foo.begin(), foo.end());     for (int i = 0; i < n; ++i) b[foo[i].second] = i;     printf( %d , b[0]);     for (int i = 1; i < n; ++i) printf(  %d , b[i]);     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int ex[n], e[n];     int temp = n;     int i = 0;     while (temp--) {       cin >> ex[i] >> e[i];       i++;     }     int sum = e[0], m = e[0];     for (int j = 1; j < n; j++) {       sum = sum - ex[j] + e[j];       if (sum > m) {         m = sum;       }     }     cout << m << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 300050;   const int L = 19;   const long long inf = 1e15;   vector<int> E[N];   int par[N][L], dep[N];   void DFS(int u, int p) {     dep[u] = dep[p] + 1;     par[u][0] = p;     for (int i = 1; i < L; i++) par[u][i] = par[par[u][i - 1]][i - 1];     for (int v : E[u])       if (v != p) DFS(v, u);   }   int LCA(int u, int v) {     if (dep[u] < dep[v]) return LCA(v, u);     for (int i = L - 1; ~i; i--)       if (dep[par[u][i]] >= dep[v]) u = par[u][i];     for (int i = L - 1; ~i; i--)       if (par[u][i] != par[v][i]) u = par[u][i], v = par[v][i];     return u == v ? v : par[v][0];   }   vector<pair<int, int> > up[N];   bool ok[N];   long long dp[N];   int hi[N];   set<pair<long long, int> > st[N];   pair<long long, int> operator+(pair<long long, int> a, long long b) {     a.first += b;     return a;   }   long long st_add[N], ans;   void Solve(int u, int p) {     int nok = 0;     long long sum = 0;     hi[u] = dep[u];     for (int v : E[u])       if (v != p)         Solve(v, u), nok += !ok[v], sum += ok[v] ? dp[v] : 0,             hi[u] = min(hi[u], hi[v]);     if (nok) {       ok[u] = 0;     } else {       for (int v : E[u])         if (v != p) {           if (st[u].size() < st[v].size())             st[u].swap(st[v]), swap(st_add[u], st_add[v]);           for (auto p : st[v]) st[u].insert(p + (st_add[v] - st_add[u]));         }       dp[u] = sum;       for (auto p : up[u])         st[u].insert(make_pair(p.second, dep[p.first]) + (-st_add[u]));       if (hi[u] == dep[u]) {         while (st[u].size() && st[u].begin()->second >= dep[u])           st[u].erase(st[u].begin());         if (st[u].empty())           ok[u] = 0;         else {           ok[u] = 1;           dp[u] += st[u].begin()->first + st_add[u];           hi[u] = st[u].begin()->second;           st_add[u] -= st[u].begin()->first + st_add[u];           st[u].erase(st[u].begin());         }       } else         ok[u] = 1;     }     if (u == 1) ans = nok == 0 ? sum : -1;   }   int main() {     int n, m, i, u, v, c;     scanf( %i %i , &n, &m);     for (i = 1; i < n; i++)       scanf( %i %i , &u, &v), E[u].push_back(v), E[v].push_back(u);     DFS(1, 0);     for (i = 1; i <= m; i++)       scanf( %i %i %i , &u, &v, &c), up[u].push_back(make_pair(LCA(u, v), c));     Solve(1, 0);     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-9;   const int MAXB = 10;   const int MAXN = 1025;   vector<int> distGroup[MAXN];   int hasDist[MAXN];   int predecessor[MAXN];   vector<int> output;   set<int> centers;   string result, resultm;   int maxDist[MAXN];   int minDist[MAXN];   vector<string> strangeresults;   int main() {     int N;     cin >> N;     for (int i = (0); i < (N); i++) minDist[i] = 1;     for (int i = (0); i < (N); i++) maxDist[i] = (1 << MAXB) - 1;     for (int i = (0); i < (N); i++) hasDist[i] = -1;     for (int i = (0); i < (N); i++) distGroup[i].clear();     distGroup[0].push_back(0);     maxDist[0] = minDist[0] = hasDist[0] = 0;     int largest = 0;     for (int p = int(MAXB) - 1; p >= (0); p--) {       for (int s = (0); s < (2); s++) {         output = vector<int>(N, 0);         centers.clear();         for (int i = (s << (p + 1)); true; i += (4 << p)) {           if (i > N || int((distGroup[i]).size()) == 0) break;           for (auto n : distGroup[i]) {             assert(output[n] == 0);             output[n] = (1 << p);           }           centers.insert(i);         }         if (int((centers).size()) > 0) {           cout <<  ? ;           for (auto v : output) cout <<     << min(N - 1, v);           cout << endl << flush;           cin >> result;           cout <<  ? ;           for (auto v : output) cout <<     << max(0, min(N - 1, v - 1));           cout << endl << flush;           cin >> resultm;           while (int((result).size()) != N || int((resultm).size()) != N) {             cerr <<  VERY STRANGE!! got    << result <<    and    << resultm                  <<    as results  << endl                  << flush;             strangeresults.push_back(result);             strangeresults.push_back(resultm);             if (int((strangeresults).size()) == (N - 1) * 2) {               cout <<  !  << endl;               for (int i = (0); i < (N - 1); i++)                 cout << strangeresults[i * 2] <<     << strangeresults[i * 2 + 1]                      << endl;               return 0;             }             cout <<  ? ;             for (auto v : output) cout <<     << min(N - 1, v);             cout << endl << flush;             cin >> result;             cout <<  ? ;             for (auto v : output) cout <<     << max(0, min(N - 1, v - 1));             cout << endl << flush;             cin >> resultm;           }           for (int i = (0); i < (N); i++) {             if (minDist[i] == maxDist[i]) continue;             if (centers.find(minDist[i] - 1) != centers.end()) {               if (result[i] ==  1 ) {                 if (resultm[i] ==  1 ) {                   maxDist[i] -= (1 << p);                 } else {                   minDist[i] = maxDist[i] = minDist[i] - 1 + (1 << p);                 }               } else                 minDist[i] += (1 << p);             }             if (minDist[i] == maxDist[i]) {               hasDist[i] = minDist[i];               largest = max(largest, minDist[i]);               distGroup[minDist[i]].push_back(i);             }           }         }       }     }     for (int i = (0); i < (N); i++) predecessor[i] = -1;     for (int i = (0); i < (N); i++)       assert(minDist[i] == maxDist[i] && maxDist[i] == hasDist[i]);     for (int a = (0); a < (2); a++) {       vector<string> results;       for (int b = (0); b < (MAXB); b++) {         for (int xo = (0); xo < (2); xo++) {           cout <<  ? ;           for (int n = (0); n < (N); n++) {             if (((hasDist[n] >> 1) ^ a) & 1)               cout <<     << (((n >> b) ^ xo) & 1);             else               cout <<   0 ;           }           cout << endl << flush;           string tmp;           cin >> tmp;           results.push_back(tmp);         }       }       for (int d = (0); d < (largest); d++) {         if (((d >> 1) ^ a ^ 1) & 1) continue;         for (auto n1 : distGroup[d])           for (auto n2 : distGroup[d + 1]) {             bool ok = true;             for (int b = (0); b < (MAXB); b++) {               if (results[b * 2 + (1 ^ ((n1 >> b) & 1))][n2] ==  0 ) ok = false;             }             if (ok) {               if (predecessor[n2] != -1) {                 cerr <<  prev predecessor[  << n2 <<  ]=  << predecessor[n2]                      << endl;                 cerr << predecessor[n2] << endl;               }               assert(predecessor[n2] == -1);               predecessor[n2] = n1;             }           }       }     }     assert(predecessor[0] == -1);     for (int i = (1); i < (N); i++) assert(predecessor[i] != -1);     cout <<  !  << endl << flush;     for (int i = (1); i < (N); i++)       cout << predecessor[i] + 1 <<     << i + 1 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long ans = 0;   string s;   int main() {     ios_base::sync_with_stdio(false);     cin >> s;     int id = -1;     for (int i = 0; i < (int)s.length(); i++) {       for (int j = 1; j <= 4 && i - 2 * j >= 0; j++)         if (s[i] == s[i - j] && s[i - j] == s[i - 2 * j]) id = max(id, i - 2 * j);       ans += id + 1;     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     char ch;     int state = 0;     while ((ch = cin.get()) != EOF) switch (state) {         case 0:           if (isdigit(ch)) {             cout << ch;             state = 1;           }           if (ch ==  , ) {             cout << ch;             state = 2;           }           if (ch ==    ) {             state = 0;           }           if (ch ==  . ) {             cout << ch;             state = 3;           }           break;         case 1:           if (isdigit(ch)) {             cout << ch;             state = 1;           }           if (ch ==  , ) {             cout << ch;             state = 2;           }           if (ch ==    ) {             state = 6;           }           if (ch ==  . ) {             cout <<    ;             cout << ch;             state = 3;           }           break;         case 2:           if (isdigit(ch)) {             cout <<    ;             cout << ch;             state = 1;           }           if (ch ==  , ) {             cout <<    ;             cout << ch;             state = 2;           }           if (ch ==    ) {             state = 2;           }           if (ch ==  . ) {             cout <<    ;             cout << ch;             state = 3;           }           break;         case 3:           if (ch ==  . ) {             cout << ch;             state = 4;           }           break;         case 4:           if (ch ==  . ) {             cout << ch;             state = 5;           }           break;         case 5:           if (isdigit(ch)) {             cout << ch;             state = 1;           }           if (ch ==  , ) {             cout << ch;             state = 2;           }           if (ch ==    ) {             state = 5;           }           if (ch ==  . ) {             cout <<    ;             cout << ch;             state = 3;           }           break;         case 6:           if (isdigit(ch)) {             cout <<    ;             cout << ch;             state = 1;           }           if (ch ==  , ) {             cout << ch;             state = 2;           }           if (ch ==    ) {             state = 6;           }           if (ch ==  . ) {             cout <<    ;             cout << ch;             state = 3;           }           break;       }   exit:     return (0);   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9;   const int MN = 105;   bool mark[500][500];   char s[MN];   int dis[500][500];   int ask(pair<int, int> now) {     int res = INF;     if (mark[now.first][now.second]) res = min(res, dis[now.first][now.second]);     if (mark[now.first - 1][now.second])       res = min(res, dis[now.first - 1][now.second] + 1);     if (mark[now.first + 1][now.second])       res = min(res, dis[now.first + 1][now.second] + 1);     if (mark[now.first][now.second - 1])       res = min(res, dis[now.first][now.second - 1] + 1);     if (mark[now.first][now.second + 1])       res = min(res, dis[now.first][now.second + 1] + 1);     return res;   }   int main() {     scanf( %s , s);     int l = strlen(s);     pair<int, int> now = make_pair(105, 105);     mark[105][105] = 1;     dis[105][105] = 0;     int len = 0;     for (int i = 0; i < l; ++i) {       ++len;       if (s[i] ==  U ) now.second += 1;       if (s[i] ==  D ) now.second -= 1;       if (s[i] ==  L ) now.first -= 1;       if (s[i] ==  R ) now.first += 1;       if (ask(now) < len) {         printf( BUG n );         return 0;       }       mark[now.first][now.second] = 1;       dis[now.first][now.second] = len;     }     printf( OK n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 5e3 + 5;   const int inf = 1e9 + 7;   vector<pair<int, int> > adj[MAXN];   int dp[MAXN][MAXN], tr[MAXN][MAXN];   int n, m, t;   int solve(int u, int len) {     if (u == n and !len) return 0;     if (!len) return inf;     if (dp[u][len] != -1) return dp[u][len];     int ret = inf;     for (int i = 0; i < ((int)adj[u].size()); i++) {       int v = adj[u][i].first;       int c = adj[u][i].second;       long long x = solve(v, len - 1) + c;       if (x < ret) ret = x, tr[u][len] = v;     }     return dp[u][len] = ret;   }   void process() {     memset(dp, -1, sizeof(dp));     for (int i = 5000; i >= 0; i--) {       int ans = solve(1, i);       if (ans <= t) {         printf( %d n%d  , i + 1, 1);         int x = 1;         while (i--) {           x = tr[x][i + 1];           printf( %d  , x);         }       }     }   }   int main(void) {     scanf( %d%d%d , &n, &m, &t);     for (int u, v, c, i = 1; i <= m; i++) {       scanf( %d%d%d , &u, &v, &c);       adj[u].push_back(make_pair(v, c));     }     process();   }


#include <bits/stdc++.h>   int main() {     int i, n, x = 2;     scanf( %d , &n);     for (i = 0; i < n - 1; i++) {       printf( %d  , x);       x += (2 + i);       if (x > n) x -= n;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     unsigned long long N, x, y, input, r_code = 0;     cin >> N >> x >> y;     vector<unsigned long long> days;     for (unsigned long long i = 0; i < N; i++) {       cin >> input;       days.push_back(input);     }     unsigned long long temp1;     for (unsigned long long i = 0; i < N; i++) {       r_code = 0;       if (i < x) {         temp1 = 0;       } else         temp1 = x;       for (unsigned long long j = 1; j <= temp1; j++) {         if (days[i - j] <= days[i]) {           r_code = 1;           break;         }       }       if (r_code == 0) {         unsigned long long temp;         if (i + y >= N) {           temp = N - 1;         } else           temp = i + y;         for (unsigned long long j = i + 1; j <= temp; j++) {           if (days[j] <= days[i]) {             r_code = 1;             break;           }         }       }       if (r_code == 0) {         cout << (i + 1);         break;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int lim = 1e6;   int inf = 1e8;   void err(istream_iterator<string> it) { cerr << endl; }   template <typename T, typename... Args>   void err(istream_iterator<string> it, T a, Args... args) {     cerr << *it <<   =   << a <<   t ;     err(++it, args...);   }   template <typename T1, typename T2>   ostream& operator<<(ostream& c, pair<T1, T2>& v) {     c <<  (  << v.first <<  ,  << v.second <<  ) ;     return c;   }   template <template <class...> class TT, class... T>   ostream& operator<<(ostream& out, TT<T...>& c) {     out <<  {  ;     for (auto& x : c) out << x <<    ;     out <<  } ;     return out;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       int ans = 0;       for (int i = 6; i >= 0; i--) {         int k = pow(2, i);         int j = 0;         vector<int> a, b;         for (int r = 1; r <= n; r++) {           if ((r / k) % 2 == 0) {             a.push_back(r);           } else {             b.push_back(r);           }         }         if (a.size() == 0 or b.size() == 0) continue;         cout << a.size() <<     << b.size() <<    ;         for (int j = 0; j < a.size(); j++) {           cout << a[j] <<    ;         }         for (int j = 0; j < b.size(); j++) {           cout << b[j] <<    ;         }         cout << endl;         int tmpans;         cin >> tmpans;         ans = max(ans, tmpans);       }       cout << -1 <<     << ans << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     string s;     cin >> s;     map<char, long long> mp;     for (long long i = 0; i < s.size(); i++) mp[s[i]]++;     long long c = 0;     for (auto it = mp.begin(); it != mp.end(); it++) {       if (it->second & 1) c++;     }     if (c <= 1)       cout <<  First ;     else {       if (c % 2 == 0)         cout <<  Second ;       else         cout <<  First ;     }   }   signed main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 300001;   set<pair<long long int, long long int> >* T[N];   int A[N];   int S[N];   char s[N];   vector<int> adj[N];   long long int MOD1 = 1000000007LL;   long long int MOD2 = 1000000009LL;   void dfs(int st, int p = -1, long long int hash1 = 0LL,            long long int hash2 = 0LL) {     hash1 = (hash1 * 257LL + s[st] -  a  + 1) % MOD1;     hash2 = (hash2 * 43LL + s[st] -  a  + 1) % MOD2;     S[st] = 1;     int mx = -1;     for (auto c : adj[st]) {       if (c != p) {         dfs(c, st, hash1, hash2);         S[st] += S[c];         if (mx == -1 || S[mx] < S[c]) mx = c;       }     }     set<pair<long long int, long long int> >* root;     if (mx == -1)       root = new set<pair<long long int, long long int> >;     else {       root = T[mx];       for (auto c : adj[st]) {         if (c != p && c != mx) root->insert(T[c]->begin(), T[c]->end());       }     }     root->insert({hash1, hash2});     T[st] = root;     A[st] += T[st]->size();   }   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , A + i);     }     scanf( %s , s + 1);     for (int i = 1; i <= n - 1; i++) {       int u, v;       scanf( %d%d , &u, &v);       adj[u].push_back(v);       adj[v].push_back(u);     }     dfs(1);     int mxc = 0, mx = 1;     for (int i = 1; i <= n; i++) {       if (mx == A[i])         mxc++;       else if (mx < A[i])         mx = A[i], mxc = 1;     }     printf( %d n%d n , mx, mxc);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int solve(string &s, vector<vector<long long int> > &pre,                       vector<vector<long long int> > &dp, long long int st,                       long long int en, long long int a, long long int b) {     if (st > en) {       return 0;     }     if (dp[st][en] != -1) {       return dp[st][en];     }     long long int val = solve(s, pre, dp, st + 1, en, a, b) + a;     for (long long int i = st; i < pre[st][0] + st; i++) {       val = min(val, solve(s, pre, dp, i + 1, en, a, b) + b);     }     dp[st][en] = val;     return val;   }   void getZarr(string str, int Z[]);   long long int get_len(string &text, string &pattern) {     string concat = pattern +  $  + text;     int l = concat.length();     int Z[l];     getZarr(concat, Z);     long long int ans = 0;     for (int i = pattern.length() + 1; i < l; ++i) {       ans = max(ans, (long long int)Z[i]);     }     return ans;   }   void getZarr(string str, int Z[]) {     int n = str.length();     int L, R, k;     L = R = 0;     for (int i = 1; i < n; ++i) {       if (i > R) {         L = R = i;         while (R < n && str[R - L] == str[R]) R++;         Z[i] = R - L;         R--;       } else {         k = i - L;         if (Z[k] < R - i + 1)           Z[i] = Z[k];         else {           L = i;           while (R < n && str[R - L] == str[R]) R++;           Z[i] = R - L;           R--;         }       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int n, a, b;     cin >> n >> a >> b;     string s;     cin >> s;     vector<vector<long long int> > pre(n + 1, vector<long long int>(1, -1)),         dp(n + 1, vector<long long int>(n + 1, -1));     string s1 =   ;     for (long long int l = 1; l < n; l++) {       long long int min1 = min(l, n - l);       s1 += s[l - 1];       string s2 =   ;       for (long long int idx = l; idx < (l + min1); idx++) {         s2 += s[idx];       }       long long int len = get_len(s1, s2);       pre[l][0] = len;     }     cout << solve(s, pre, dp, 0, n - 1, a, b) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MAXN = 1e5 + 1;   const long long INF = 1e9 + 1;   const long long MOD = 1e9;   const long long BITS = 64;   const long double EPS = 1e-12;   void bye() {     cout <<   n ;     exit(0);   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n, k;     cin >> n >> k;     string s;     cin >> s;     vector<int> cnt(k);     for (int i = 0; i < (long long)(s).size(); i++) {       cnt[s[i] -  A ]++;     }     cout << *min_element((cnt).begin(), cnt.end()) * k;     bye();   }


#include <bits/stdc++.h>   using namespace std;   const int nmax = 110;   int x[nmax];   char g[nmax][nmax];   int pos[nmax * nmax][2];   int main() {     int a, b, c, d;     scanf( %d%d%d%d , &a, &b, &c, &d);     int q;     scanf( %d , &q);     for (int i = 0; i < q; ++i) {       scanf( %d , &x[i]);     }     bool swapped = false;     if (b < d) {       swap(b, d);       swap(a, c);       swapped = true;     }     int n = b;     int m = a + c;     memset(g,  . , sizeof(g));     int k = 0;     for (int j = 0; j < m; ++j) {       if (((j ^ a) & 1) == 0) {         for (int i = 0; i < (j < a ? b : d); ++i) {           pos[k][0] = i;           pos[k][1] = j;           ++k;         }       } else {         for (int i = (j < a ? b : d) - 1; i >= 0; --i) {           pos[k][0] = i;           pos[k][1] = j;           ++k;         }       }     }     int cnt = 0;     for (int i = 0; i < q; ++i) {       for (int j = 0; j < x[i]; ++j) {         g[pos[cnt][0]][pos[cnt][1]] =  a  + (char)i;         ++cnt;       }     }     if (swapped) {       for (int i = 0; i < n; ++i) {         reverse(g[i], g[i] + m);       }     }     puts( YES );     for (int i = 0; i < n; ++i) {       g[i][m] = 0;       puts(g[i]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 109;   const int INF = 1e9;   char zbs[5] = { R ,  G ,  B ,  Y ,  W };   pair<int, int> a[N];   int main() {     int n, ans = 11;     cin >> n;     for (int i = 0; i < int(n); ++i) {       char t1, t2;       cin >> t1 >> t2;       a[i].second = int(t2 -  1 );       for (int j = 0; j < int(5); ++j)         if (zbs[j] == t1) a[i].first = j;     }     for (int mask1 = 0; mask1 < int(1 << 5); ++mask1) {       for (int mask2 = 0; mask2 < int(1 << 5); ++mask2) {         int m[5][5], na = 0, ok = 1;         memset(m, 0, sizeof(m));         for (int i = 0; i < int(5); ++i) {           if (mask1 & (1 << i)) ++na;           if (mask2 & (1 << i)) ++na;         }         for (int i = 0; i < int(n); ++i) m[a[i].first][a[i].second] = 1;         for (int i1 = 0; i1 < int(5); ++i1)           for (int j1 = 0; j1 < int(5); ++j1)             for (int i2 = 0; i2 < int(5); ++i2)               for (int j2 = 0; j2 < int(5); ++j2) {                 bool ok1 = 0;                 if (m[i1][j1] * m[i2][j2] == 0) continue;                 if (i1 == i2 && j1 == j2) continue;                 if (i1 != i2 && ((mask1 & (1 << i1)) || (mask1 & (1 << i2))))                   ok1 = 1;                 if (j1 != j2 && ((mask2 & (1 << j1)) || (mask2 & (1 << j2))))                   ok1 = 1;                 if (ok) ok = ok1;               }         if (ok) ans = min(na, ans);       }     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   vector<int> g[100001];   bool is_centroid[100001];   int centroid_parent[100001];   int mn[100001];   int sz[100001];   int level[100001];   int centroid_root;   map<pair<int, int>, int> dist;   void dfs(int nd, int p, int c) {     sz[nd] = 1;     if (p == c) {       level[nd] = 0;     } else {       level[nd] = level[p] + 1;     }     dist[make_pair(nd, c)] = level[nd] + 1;     for (int i = 0; i < g[nd].size(); i++) {       int z = g[nd][i];       if (z != p && !is_centroid[z]) {         dfs(z, nd, c);         sz[nd] += sz[z];       }     }   }   int pd;   int find_centroid(int u, int ts) {     for (int i = 0; i < g[u].size(); i++) {       int z = g[u][i];       if (is_centroid[z] || sz[z] > sz[u]) continue;       if (sz[z] > ts / 2) return find_centroid(z, ts);     }     return u;   }   int get_centroid(int nd, int p) {     dfs(nd, p, p);     int u = find_centroid(nd, sz[nd]);     is_centroid[u] = true;     centroid_parent[u] = p;     for (int i = 0; i < g[u].size(); i++) {       int z = g[u][i];       if (!is_centroid[z]) {         get_centroid(z, u);       }     }     return u;   }   void centroid_decompose() {     fill(is_centroid, is_centroid + 100001, false);     centroid_root = get_centroid(1, -1);   }   void debug() {     for (int i = 1; i <= n; i++) {       cout << i <<     << centroid_parent[i] <<     << mn[i] << endl;     }   }   void redify(int u) {     int x = u;     while (u != -1) {       mn[u] = min(dist[make_pair(x, u)], mn[u]);       u = centroid_parent[u];     }   }   int solve(int u) {     int res = INT_MAX / 3;     int x = u;     while (u != -1) {       res = min(res, dist[make_pair(x, u)] + mn[u]);       u = centroid_parent[u];     }     return res;   }   int main() {     int u, v;     scanf( %d %d , &n, &m);     for (int i = 0; i < n - 1; i++) {       scanf( %d %d , &u, &v);       g[u].push_back(v);       g[v].push_back(u);     }     fill(mn, mn + 100001, INT_MAX / 3);     centroid_decompose();     redify(1);     while (m--) {       scanf( %d %d , &u, &v);       if (u == 1) {         redify(v);       } else {         printf( %d n , solve(v));       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 100010;   vector<int> v[5 * maxn];   int t[5 * maxn];   int comp[5 * maxn];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n = 0, m = 0, x = 0, y = 0;     cin >> n >> m;     for (int i = 0; i < m; ++i) {       cin >> x >> y;       --x;       --y;       v[x].push_back(y);       v[y].push_back(x);     }     vector<int> aux;     for (int i = 0; i < n; ++i) {       cin >> t[i];       comp[i] = 1;       if (t[i] == comp[i]) aux.push_back(i);     }     bool flag = false;     for (int i = 0; i < (int)aux.size(); ++i) {       int node = aux[i];       if (comp[node] != t[node]) flag = true;       for (auto j : v[node]) {         if (comp[j] == t[node]) {           ++comp[j];           if (comp[j] == t[j]) aux.push_back(j);         }       }     }     if ((int)aux.size() < n) flag = true;     if (flag)       cout <<  -1 ;     else {       for (auto i : aux) {         cout << (i + 1) <<    ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 3005, MAXM = 55;   const double inf = 1e9 + 5;   vector<int> graph[MAXN];   double c[MAXN][MAXN];   int f[MAXN][MAXN];   priority_queue<pair<double, int> > q;   double dist[MAXN];   int last[MAXN];   int n, Q;   int upperBound[MAXM], lowerBound[MAXM];   int arrayNode[MAXM];   int dispenserNode[MAXM][MAXM];   int startNode[MAXM], endNode[MAXM];   int S = 3001, T = 3002;   void addEdge(int u, int v, int flow, double cost) {     graph[u].push_back(v);     graph[v].push_back(u);     f[u][v] = flow;     c[u][v] = cost;     c[v][u] = cost;   }   double Dijkstra(int s, int t) {     for (int i = 0; i < MAXN; i++) {       dist[i] = inf;     }     dist[s] = 0;     int u;     q.push({0, s});     while (q.empty() == false) {       u = q.top().second;       q.pop();       for (int i = 0; i < graph[u].size(); i++) {         if (f[u][graph[u][i]] != 0 &&             dist[graph[u][i]] > dist[u] + c[u][graph[u][i]]) {           dist[graph[u][i]] = dist[u] + c[u][graph[u][i]];           last[graph[u][i]] = u;           q.push({-dist[graph[u][i]], graph[u][i]});         }       }     }     return dist[t];   }   pair<int, double> minCostMaxFlow(int s, int t) {     int maxFlow = 0;     double minCost = 0;     while (true) {       double cost = Dijkstra(s, t);       if (cost == inf) break;       int u = t;       int flow = inf;       while (u != s) {         flow = min(flow, f[last[u]][u]);         u = last[u];       }       u = t;       while (u != s) {         f[last[u]][u] -= flow;         f[u][last[u]] += flow;         u = last[u];       }       maxFlow += flow;       minCost += cost * flow;     }     return {maxFlow, minCost};   }   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cin >> n >> Q;     for (int i = 1; i <= n; i++) {       lowerBound[i] = 1;       upperBound[i] = n;     }     while (Q--) {       int type;       int l, r, v;       cin >> type;       cin >> l >> r >> v;       if (type == 1) {         for (int i = l; i <= r; i++) {           lowerBound[i] = max(lowerBound[i], v);         }       } else {         for (int i = l; i <= r; i++) {           upperBound[i] = min(upperBound[i], v);         }       }     }     for (int i = 1; i <= n; i++) {       if (lowerBound[i] > upperBound[i]) {         cout <<  -1  <<   n ;         return 0;       }     }     int node = 1;     for (int i = 1; i <= n; i++) {       startNode[i] = node;       node++;     }     for (int i = 1; i <= n; i++) {       endNode[i] = node;       node++;     }     for (int i = 1; i <= n; i++) {       arrayNode[i] = node;       node++;     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         dispenserNode[i][j] = node;         node++;       }     }     for (int i = 1; i <= n; i++) {       addEdge(S, startNode[i], n, 0);     }     for (int i = 1; i <= n; i++) {       int value = 1, sum = 0;       for (int j = 1; j <= n; j++) {         addEdge(startNode[i], dispenserNode[i][j], 1, j * j - sum);         addEdge(dispenserNode[i][j], endNode[i], 1, 0);         sum += j * j - sum;       }     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         if (i >= lowerBound[j] && i <= upperBound[j]) {           addEdge(endNode[i], arrayNode[j], 1, 0);         }       }     }     for (int i = 1; i <= n; i++) {       addEdge(arrayNode[i], T, 1, 0);     }     cout << minCostMaxFlow(S, T).second <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int dp[513];   int n, m;   int main() {     scanf( %d %d , &n, &m);     for (int i = 0; i < n; ++i) {       scanf( %d , &dp[i + 1]);     }     double best = 0;     for (int i = 0; i < m; ++i) {       int x, y, z;       scanf( %d %d %d , &x, &y, &z);       best = max(best, ((double)dp[x] + dp[y]) / z);     }     printf( %.9lf , best);     return 0;   }


/*   ⣿⣿⣿⣿⣿⣿⡷⣯⢿⣿⣷⣻⢯⣿⡽⣻⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣇⠸⣿⣿⣆⠹⣿⣿⢾⣟⣯⣿⣿⣿⣿⣿⣿⣽⣻⣿⣿⣿⣿⣿⣿⣿   ⣿⣿⣿⣿⣿⣿⣻⣽⡿⣿⣎⠙⣿⣞⣷⡌⢻⣟⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣿⣿⣿⣿⣿⣿⡄⠹⣿⣿⡆⠻⣿⣟⣯⡿⣽⡿⣿⣿⣿⣿⣽⡷⣯⣿⣿⣿⣿⣿⣿   ⣿⣿⣿⣿⣿⣿⣟⣷⣿⣿⣿⡀⠹⣟⣾⣟⣆⠹⣯⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⢠⡘⣿⣿⡄⠉⢿⣿⣽⡷⣿⣻⣿⣿⣿⣿⡝⣷⣯⢿⣿⣿⣿⣿   ⣿⣿⣿⣿⣿⣿⣯⢿⣾⢿⣿⡄⢄⠘⢿⣞⡿⣧⡈⢷⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⢸⣧⠘⣿⣷⠈⣦⠙⢿⣽⣷⣻⣽⣿⣿⣿⣿⣌⢿⣯⢿⣿⣿⣿   ⣿⣿⣿⣿⣿⣿⣟⣯⣿⢿⣿⡆⢸⡷⡈⢻⡽⣷⡷⡄⠻⣽⣿⣿⡿⣿⣿⣿⣿⣿⣿⣷⣿⣿⣿⣿⣏⢰⣯⢷⠈⣿⡆⢹⢷⡌⠻⡾⢋⣱⣯⣿⣿⣿⣿⡆⢻⡿⣿⣿⣿   ⣿⣿⣿⣿⣿⣿⡎⣿⢾⡿⣿⡆⢸⣽⢻⣄⠹⣷⣟⣿⣄⠹⣟⣿⣿⣟⣿⣿⣿⣿⣿⣿⣽⣿⣿⣿⡇⢸⣯⣟⣧⠘⣷⠈⡯⠛⢀⡐⢾⣟⣷⣻⣿⣿⣿⡿⡌⢿⣻⣿⣿   ⣿⣿⣿⣿⣿⣿⣧⢸⡿⣟⣿⡇⢸⣯⣟⣮⢧⡈⢿⣞⡿⣦⠘⠏⣹⣿⣽⢿⣿⣿⣿⣿⣯⣿⣿⣿⡇⢸⣿⣿⣾⡆⠹⢀⣠⣾⣟⣷⡈⢿⣞⣯⢿⣿⣿⣿⢷⠘⣯⣿⣿   ⣿⣿⣿⣿⣿⣿⣿⡈⣿⢿⣽⡇⠘⠛⠛⠛⠓⠓⠈⠛⠛⠟⠇⢀⢿⣻⣿⣯⢿⣿⣿⣿⣷⢿⣿⣿⠁⣾⣿⣿⣿⣧⡄⠇⣹⣿⣾⣯⣿⡄⠻⣽⣯⢿⣻⣿⣿⡇⢹⣾⣿   ⣿⣿⣿⣿⣿⣿⣿⡇⢹⣿⡽⡇⢸⣿⣿⣿⣿⣿⣞⣆⠰⣶⣶⡄⢀⢻⡿⣯⣿⡽⣿⣿⣿⢯⣟⡿⢀⣿⣿⣿⣿⣿⣧⠐⣸⣿⣿⣷⣿⣿⣆⠹⣯⣿⣻⣿⣿⣿⢀⣿⢿   ⣿⣿⣿⣿⣿⣿⣿⣿⠘⣯⡿⡇⢸⣿⣿⣿⣿⣿⣿⣿⣧⡈⢿⣳⠘⡄⠻⣿⢾⣽⣟⡿⣿⢯⣿⡇⢸⣿⣿⣿⣿⣿⣿⡀⢾⣿⣿⣿⣿⣿⣿⣆⠹⣾⣷⣻⣿⡿⡇⢸⣿   ⣿⣿⣿⣿⣿⣿⣿⣿⡇⢹⣿⠇⢸⣿⣿⣿⣿⣿⣿⣿⣿⣷⣄⠻⡇⢹⣆⠹⣟⣾⣽⣻⣟⣿⣽⠁⣾⣿⣿⣿⣿⣿⣿⣇⣿⣿⠿⠛⠛⠉⠙⠋⢀⠁⢘⣯⣿⣿⣧⠘⣿   ⣿⣿⣿⣿⣿⣿⣿⣿⣿⡈⣿⡃⢼⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⡙⠌⣿⣆⠘⣿⣞⡿⣞⡿⡞⢠⣿⣿⣿⣿⣿⡿⠛⠉⠁⢀⣀⣠⣤⣤⣶⣶⣶⡆⢻⣽⣞⡿⣷⠈⣿   ⣿⣿⣿⣿⣿⣿⣿⣿⡿⠃⠘⠁⠉⠉⠉⠉⠉⠉⠉⠉⠉⠙⠛⠛⢿⣄⢻⣿⣧⠘⢯⣟⡿⣽⠁⣾⣿⣿⣿⣿⣿⡃⢀⢀⠘⠛⠿⢿⣻⣟⣯⣽⣻⣵⡀⢿⣯⣟⣿⢀⣿   ⣿⣿⣿⣟⣿⣿⣿⣿⣶⣶⡆⢀⣿⣾⣿⣾⣷⣿⣶⠿⠚⠉⢀⢀⣤⣿⣷⣿⣿⣷⡈⢿⣻⢃⣼⣿⣿⣿⣿⣻⣿⣿⣿⡶⣦⣤⣄⣀⡀⠉⠛⠛⠷⣯⣳⠈⣾⡽⣾⢀⣿   ⣿⢿⣿⣿⣻⣿⣿⣿⣿⣿⡿⠐⣿⣿⣿⣿⠿⠋⠁⢀⢀⣤⣾⣿⣿⣿⣿⣿⣿⣿⣿⣌⣥⣾⡿⣿⣿⣷⣿⣿⢿⣷⣿⣿⣟⣾⣽⣳⢯⣟⣶⣦⣤⡾⣟⣦⠘⣿⢾⡁⢺   ⣿⣻⣿⣿⡷⣿⣿⣿⣿⣿⡗⣦⠸⡿⠋⠁⢀⢀⣠⣴⢿⣿⣽⣻⢽⣾⣟⣷⣿⣟⣿⣿⣿⣳⠿⣵⣧⣼⣿⣿⣿⣿⣿⣾⣿⣿⣿⣿⣿⣽⣳⣯⣿⣿⣿⣽⢀⢷⣻⠄⠘   ⣿⢷⣻⣿⣿⣷⣻⣿⣿⣿⡷⠛⣁⢀⣀⣤⣶⣿⣛⡿⣿⣮⣽⡻⣿⣮⣽⣻⢯⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣯⢀⢸⣿⢀⡆   ⠸⣟⣯⣿⣿⣷⢿⣽⣿⣿⣷⣿⣷⣆⠹⣿⣶⣯⠿⣿⣶⣟⣻⢿⣷⣽⣻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⢀⣯⣟⢀⡇   ⣇⠹⣟⣾⣻⣿⣿⢾⡽⣿⣿⣿⣿⣿⣆⢹⣶⣿⣻⣷⣯⣟⣿⣿⣽⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⢀⡿⡇⢸⡇   ⣿⣆⠹⣷⡻⣽⣿⣯⢿⣽⣻⣿⣿⣿⣿⣆⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠛⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠇⢸⣿⠇⣼⡇   ⡙⠾⣆⠹⣿⣦⠛⣿⢯⣷⢿⡽⣿⣿⣿⣿⣆⠻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠃⠎⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠏⢀⣿⣾⣣⡿⡇   ⣿⣷⡌⢦⠙⣿⣿⣌⠻⣽⢯⣿⣽⣻⣿⣿⣿⣧⠩⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡏⢰⢣⠘⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠃⢀⢀⢿⣞⣷⢿⡇   ⣿⣽⣆⠹⣧⠘⣿⣿⡷⣌⠙⢷⣯⡷⣟⣿⣿⣿⣷⡀⡹⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣈⠃⣸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠟⢀⣴⡧⢀⠸⣿⡽⣿⢀   ⢻⣽⣿⡄⢻⣷⡈⢿⣿⣿⢧⢀⠙⢿⣻⡾⣽⣻⣿⣿⣄⠌⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠛⢁⣰⣾⣟⡿⢀⡄⢿⣟⣿⢀   ⡄⢿⣿⣷⢀⠹⣟⣆⠻⣿⣿⣆⢀⣀⠉⠻⣿⡽⣯⣿⣿⣷⣈⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠋⢀⣠⠘⣯⣷⣿⡟⢀⢆⠸⣿⡟⢸   ⣷⡈⢿⣿⣇⢱⡘⢿⣷⣬⣙⠿⣧⠘⣆⢀⠈⠻⣷⣟⣾⢿⣿⣆⠹⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠋⣠⡞⢡⣿⢀⣿⣿⣿⠇⡄⢸⡄⢻⡇⣼   ⣿⣷⡈⢿⣿⡆⢣⡀⠙⢾⣟⣿⣿⣷⡈⠂⠘⣦⡈⠿⣯⣿⢾⣿⣆⠙⠻⠿⠿⠿⠿⡿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠿⠛⢋⣠⣾⡟⢠⣿⣿⢀⣿⣿⡟⢠⣿⢈⣧⠘⢠⣿   ⣿⣿⣿⣄⠻⣿⡄⢳⡄⢆⡙⠾⣽⣿⣿⣆⡀⢹⡷⣄⠙⢿⣿⡾⣿⣆⢀⡀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⣀⣠⣴⡿⣯⠏⣠⣿⣿⡏⢸⣿⡿⢁⣿⣿⢀⣿⠆⢸⣿   ⣿⣿⣿⣿⣦⡙⣿⣆⢻⡌⢿⣶⢤⣉⣙⣿⣷⡀⠙⠽⠷⠄⠹⣿⣟⣿⣆⢙⣋⣤⣤⣤⣄⣀⢀⢀⢀⢀⣾⣿⣟⡷⣯⡿⢃⣼⣿⣿⣿⠇⣼⡟⣡⣿⣿⣿⢀⡿⢠⠈⣿   ⣿⣿⣿⣿⣿⣷⣮⣿⣿⣿⡌⠁⢤⣤⣤⣤⣬⣭⣴⣶⣶⣶⣆⠈⢻⣿⣿⣆⢻⣿⣿⣿⣿⣿⣿⣷⣶⣤⣌⣉⡘⠛⠻⠶⣿⣿⣿⣿⡟⣰⣫⣴⣿⣿⣿⣿⠄⣷⣿⣿⣿   */      #include <bits/stdc++.h>      using namespace std;      //#define MULTITEST      #define x first   #define y second   #define mp make_pair   #define pb push_back   #define sqr(a) ((a) * (a))   #define sz(a) int(a.size())   #define all(a) a.begin(), a.end()   #define forn(i, n) for(int i = 0; i < int(n); i++)    #define fore(i, l, r) for(int i = int(l); i < int(r); i++)      typedef long long li;   typedef long double ld;   typedef pair<int, int> pt;      template <class A, class B> ostream& operator << (ostream& out, const pair<A, B> &a) {    return out <<  (  << a.x <<  ,   << a.y <<  ) ;   }      template <class A> ostream& operator << (ostream& out, const vector<A> &v) {    out <<  [ ;    forn(i, sz(v)) {     if(i) out <<  ,  ;     out << v[i];    }    return out <<  ] ;   }      mt19937 rnd(time(NULL));      const int INF = int(1e9);   const li INF64 = li(1e18);   const int MOD = int(1e9) + 7;   const ld EPS = 1e-9;   const ld PI = acos(-1.0);      const int N = 200 * 1000 + 13;      int n;   vector<int> g[N];      bool read () {    if (scanf( %d , &n) != 1)     return false;    forn(i, n)     g[i].clear();    forn(i, n - 1){     int v, u;     scanf( %d%d , &v, &u);     --v, --u;     g[v].pb(u);     g[u].pb(v);    }    return true;   }      int fib[N];   int fibnum[N];   int siz[N];      void init(int v, int p){    siz[v] = 1;    for (int u : g[v]) if (u != p){     init(u, v);     siz[v] += siz[u];    }   }      int dfs(int v, int p, int siz1, int siz2){    for (int u : g[v]) if (u != p){     if (siz[u] == siz1 || siz[u] == siz2){      g[v].erase(find(all(g[v]), u));      g[u].erase(find(all(g[u]), v));      return u;     }     int res = dfs(u, v, siz1, siz2);     if (res != -1) return res;    }    return -1;   }      bool calc(int v){    init(v, -1);    int cnt = siz[v];    if (fibnum[cnt] == -1) return false;    if (cnt <= 2) return true;    int nrt = dfs(v, -1, fib[fibnum[cnt] - 1], fib[fibnum[cnt] - 2]);    if (nrt == -1) return false;    return calc(v) && calc(nrt);   }      void solve() {    forn(i, n) if (sz(g[i]) > 30){     puts( NO );     return;    }    fib[0] = 1;    fib[1] = 2;    fore(i, 2, 26) fib[i] = fib[i - 1] + fib[i - 2];    memset(fibnum, -1, sizeof(fibnum));    forn(i, 26) fibnum[fib[i]] = i;    puts(calc(0) ?  YES  :  NO );   }      int main() {   #ifdef _DEBUG    freopen( input.txt ,  r , stdin);   // freopen( output.txt ,  w , stdout);        int tt = clock();       #endif        cerr.precision(15);    cout.precision(15);    cerr << fixed;    cout << fixed;      #ifdef MULTITEST    int tc;    scanf( %d , &tc);    while(tc--){     read();   #else    while(read()) {    #endif     solve();        #ifdef _DEBUG    cerr <<  TIME =   << clock() - tt << endl;    tt = clock();   #endif       }   }


#include <bits/stdc++.h>   const int N = int(1e5 + 3);   using namespace std;   bool is_prime(int n) {     if (n == 2) return true;     if (n % 2 == 0) return false;     for (int i = 2; i * i <= n; ++i)       if (n % i == 0) return false;     return true;   }   void solve() {     long long n;     cin >> n;     long long t = n / 3;     long long t1 = (t - 1) + t * 2;     long long t2 = (t) + (t + 1) * 2;     long long t3 = (t) + t * 2;     if (t1 == n) {       cout << (t - 1) <<     << t <<   n ;       ;     } else if (t2 == n) {       cout << t <<     << t + 1 <<   n ;       ;     } else if (t3 == n) {       cout << t <<     << t <<   n ;       ;     } else {       cout << t + 1 <<     << t <<   n ;       ;     }     return;   }   signed main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long t;     cin >> t;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> adj[1005];   int w[1005];   int main() {     int n, k;     cin >> n >> k;     if (n - k - 1 < k) return cout << -1, 0;     cout << n * k << endl;     for (int i = 1; i <= n; i++) {       int t = w[i];       for (int j = i + 1; j <= n; j++) {         if (w[i] < k)           printf( %d %d n , i, j), w[i]++;         else if (w[j] < k)           printf( %d %d n , j, i), w[j]++;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = (int)1e9;   int main() {     int n, d, l;     vector<int> a;     cin >> n >> d >> l;     int a1 = 0;     for (int i = 0; i < n - 1; i++) {       if (d < 1)         a1 = 1;       else if (d >= l)         a1 = l;       else         a1 = d + 1;       a.push_back(a1);       d = a1 - d;     }     a.push_back(d);     if (a.back() < 1 || a.back() > l) {       cout << -1;       return 0;     }     for (int i = 0; i < n; i++) cout << a[i] <<    ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n, m;       cin >> n >> m;       vector<int> v(n), rank(n + 1), v1(m);       for (int i = 0; i < n; i++) {         cin >> v[i];         rank[v[i]] = i + 1;       }       for (int i = 0; i < m; i++) cin >> v1[i];       long long cnt = 0;       long long pre = 0;       for (int i = 0; i < m; i++) {         if (rank[v1[i]] < pre) {           cnt += 1;         } else {           int k = rank[v1[i]] - 1;           k -= i;           cnt += (2 * k + 1);           pre = rank[v1[i]];         }       }       cout << cnt << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   long long int maxi = 0;   long long int nc2(long long int n) { return (n * (n - 1)) / 2; }   int m[367];   int f[367];   int main() {     int n, g;     cin >> n;     while (n--) {       char c;       int l, r;       cin >> c >> l >> r;       if (c ==  M ) {         for (int i = l; i <= r; i++) {           m[i]++;         }       } else {         for (int i = l; i <= r; i++) {           f[i]++;         }       }     }     for (int i = 1; i < 367; i++) {       g = min(m[i], f[i]);       if (maxi < g) {         maxi = g;       }     }     cout << 2 * maxi << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int a[n + 1];     for (int i = 1; i <= n; i++) {       cin >> a[i];     }     long long int f[n + 1];     f[0] = 0;     for (int i = 1; i < n; i++) {       f[i] = f[i - 1] ^ i;     }     long long sum = 0;     for (int i = 1; i <= n; i++) {       if ((n / (i)) % 2 == 1) {         sum = sum ^ (a[i] ^ f[i - 1]) ^ (f[n % i]);       } else {         sum = sum ^ a[i] ^ f[n % i];       }     }     cout << sum;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     long long res = 0;     for (size_t i = 0; i < s.size(); ++i) {       int c = s[i] -  0 ;       int pc = (i > 0 ? s[i - 1] -  0  : 0);       if (c % 4 == 0) {         ++res;       }       if ((pc * 10 + c) % 4 == 0) {         res += i;       }     }     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int nxt() {     int res;     scanf( %d , &res);     return res;   }   inline void solve() {     int n = nxt();     int k = nxt();     int d = nxt();     vector<vector<int> > ans;     ans.push_back(vector<int>(d, 0));     while (int(ans.size()) < n) {       vector<int> q = ans.back();       int add = 1;       for (int i = 0; i < d && add; ++i) {         q[i] += add;         add = 0;         if (q[i] >= k) {           q[i] -= k;           add = 1;         }       }       if (add) {         break;       }       ans.push_back(q);     }     if (int(ans.size()) != n) {       cout <<  -1 n ;       return;     }     for (int i = 0; i < d; ++i) {       for (int j = 0; j < n; ++j) {         cout << ans[j][i] + 1 <<    ;       }       cout <<   n ;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long dp[5005][5005];   long long solve(long long x, long long y) {     if (x == 0 || y == 0) return 1;     if (dp[x][y] == 0)       dp[x][y] = (solve(x - 1, y - 1) * y + solve(x - 1, y)) % 998244353;     return dp[x][y];   }   int main() {     long long n, m, k;     while (scanf( %lld%lld%lld , &n, &m, &k) != EOF) {       memset(dp, 0, sizeof(0));       printf( %lld n ,              (solve(n, m) * solve(m, k) % 998244353) * solve(k, n) % 998244353);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1000000007;   const double PI = 3.141592653528;   const long long INF = 10000000000000000;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       vector<pair<pair<int, int>, int> > v;       long long sum = 0;       for (int i = 0; i < 2 * n - 1; ++i) {         int a, b;         cin >> a >> b;         v.push_back(make_pair(make_pair(a, b), i));         sum += b;       }       cout <<  YES n ;       sort(v.rbegin(), v.rend());       long long sum1 = v[0].first.second;       int k = 1;       for (int i = 0; i < n - 1; ++i) sum1 += v[k + 2 * i].first.second;       if (2 * sum1 < sum) ++k;       cout << v[0].second + 1 <<    ;       for (int i = 0; i < n - 1; ++i) cout << v[k + 2 * i].second + 1 <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, x1, y1, x2, y2, x, y;     scanf( %d%d%d%d%d%d , &n, &m, &x1, &y1, &x2, &y2);     x = abs(x1 - x2);     y = abs(y1 - y2);     if (x + y >= 7 || y >= 5 || x >= 5)       printf( Second n );     else       printf( First n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     vector<int> num;     int n;     cin >> n;     int k = -1, tmp;     while (n > 0) {       tmp = n % 10;       num.push_back(tmp);       if (tmp > k) k = tmp;       n /= 10;     }     cout << k << endl;     bool flag = true;     bool main = true;     while (true) {       flag = false;       main = false;       for (int i = num.size() - 1; i > -1; i--) {         if (num[i] > 0) {           cout << 1;           flag = true;           main = true;           num[i]--;         } else if ((num[i] == 0) && (main))           cout << 0;       }       if (flag == false) break;       cout <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   const double eps = 1e-6;   const double pi = acos(-1.0);   int T[100005 << 2];   void update(int n, int L, int R, int p, int a) {     if (L == R) {       T[n] = a;       return;     }     if (p > (L + R) / 2)       update(n * 2 + 1, (L + R) / 2 + 1, R, p, a);     else       update(n * 2, L, (L + R) / 2, p, a);     T[n] = max(T[n * 2], T[n * 2 + 1]);   }   int query(int n, int L, int R, int l, int r) {     if (L == l && R == r) return T[n];     int M = (L + R) / 2;     if (l > M)       return query(n * 2 + 1, M + 1, R, l, r);     else if (r <= M)       return query(n * 2, L, M, l, r);     else       return max(query(n * 2, L, M, l, M), query(n * 2 + 1, M + 1, R, M + 1, r));   }   struct node {     node(){};     node(int L, int R, int M, double P) : l(L), r(R), mx(M), p(P){};     int l, r, mx;     double p;     vector<int> c;     bool operator<(const node& n) const { return l == n.l ? r > n.r : l < n.l; };   } N[5005];   int q;   double dp[5005][5005];   double dfs(int n) {     for (auto i : N[n].c) dfs(i);     double a, b;     dp[n][0] = 1.0 - N[n].p;     for (auto i : N[n].c)       if (N[n].mx - N[i].mx <= q) dp[n][0] *= dp[i][N[n].mx - N[i].mx];     for (int j = 1; j <= q; ++j) {       a = b = 1;       for (auto i : N[n].c) {         if (N[n].mx - N[i].mx + j - 1 <= q) a *= dp[i][N[n].mx - N[i].mx + j - 1];         if (N[n].mx - N[i].mx + j <= q) b *= dp[i][N[n].mx - N[i].mx + j];       }       dp[n][j] = a * N[n].p + b * (1.0 - N[n].p);     }     if (n == 0) {       double ans = dp[n][0] * N[n].mx;       for (int j = 1; j <= q; ++j)         if (dp[n][j] > dp[n][j - 1])           ans += (dp[n][j] - dp[n][j - 1]) * (N[n].mx + j);       return ans;     } else       return 0;   }   int main() {     int n, a, l, r;     double p;     stack<int> s;     cin >> n >> q;     for (int i = 1; i <= n; ++i) {       cin >> a;       update(1, 1, n, i, a);     }     for (int i = 1; i <= q; ++i) {       cin >> l >> r >> p;       N[i] = node(l, r, query(1, 1, n, l, r), p);     }     N[0] = node(1, n, T[1], 0);     sort(N + 1, N + 1 + q);     s.push(0);     for (int i = 1; i <= q; ++i) {       while (!s.empty()) {         l = N[s.top()].l;         r = N[s.top()].r;         if (l <= N[i].l && N[i].r <= r) {           N[s.top()].c.push_back(i);           s.push(i);           break;         } else           s.pop();       }     }     memset(dp, 0, sizeof(dp));     printf( %.8lf n , dfs(0));   }