#include <bits/stdc++.h>   using namespace std;   const int MaxN = 100010;   int n, m, k;   map<int, vector<pair<int, int> > > a, b;   int s = 0;   void deal(map<int, vector<pair<int, int> > > &a, int n, int m) {     if ((m + 1 - a.size()) % 2) s ^= n;     for (map<int, vector<pair<int, int> > >::iterator it = a.begin();          it != a.end(); ++it) {       sort(it->second.begin(), it->second.end());       vector<pair<int, int> > v;       pair<int, int> p = it->second[0];       for (int i = 1; i < it->second.size(); ++i) {         if (it->second[i].first > p.second) {           v.push_back(p);           p = it->second[i];         } else           p.second = max(p.second, it->second[i].second);       }       v.push_back(p);       it->second = v;       int t = 0;       for (int i = 0; i < v.size(); ++i) t += v[i].second - v[i].first;       s ^= n - t;     }   }   int search(vector<pair<int, int> > &v, int L, int R, int get) {     int ans = R;     while (L <= R) {       int m = (L + R) >> 1;       int t = m;       for (int i = 0; i < v.size(); ++i) {         if (v[i].first >= m)           t += v[i].second - v[i].first;         else if (v[i].second >= m)           t += v[i].second - m;       }       if (t >= get) {         ans = m;         R = m - 1;       } else         L = m + 1;     }     return ans;   }   int main() {     cin >> n >> m >> k;     for (int i = 1; i <= k; ++i) {       int x1, y1, x2, y2;       scanf( %d%d%d%d , &x1, &y1, &x2, &y2);       if (x1 == x2) {         if (y1 > y2) swap(y1, y2);         a[x1].push_back(pair<int, int>(y1, y2));       } else if (y1 == y2) {         if (x1 > x2) swap(x1, x2);         b[y1].push_back(pair<int, int>(x1, x2));       }     }     deal(a, m, n);     deal(b, n, m);     if (s) {       puts( FIRST );       if (a.size() < n)         for (int i = 1; i < n; ++i) {           if (!a.count(i)) {             a[i];             break;           }         }       for (map<int, vector<pair<int, int> > >::iterator it = a.begin();            it != a.end(); ++it) {         vector<pair<int, int> > v = it->second;         int t = 0;         for (int i = 0; i < v.size(); ++i) t += v[i].second - v[i].first;         t = m - t;         if (!t) continue;         if ((s ^ t) >= t) continue;         int p = search(v, 0, m, m - (s ^ t));         printf( %d %d %d %d n , it->first, 0, it->first, p);         return 0;       }       if (b.size() < m)         for (int i = 1; i < m; ++i) {           if (!b.count(i)) {             b[i];             break;           }         }       for (map<int, vector<pair<int, int> > >::iterator it = b.begin();            it != b.end(); ++it) {         vector<pair<int, int> > v = it->second;         int t = 0;         for (int i = 0; i < v.size(); ++i) t += v[i].second - v[i].first;         t = n - t;         if (!t) continue;         if ((s ^ t) >= t) continue;         int p = search(v, 0, n, n - (s ^ t));         printf( %d %d %d %d n , 0, it->first, p, it->first);         return 0;       }     } else {       puts( SECOND );     }     return 0;   }


#include <bits/stdc++.h>   int n, m, i, j;   char s[110], p =  - ;   bool q = true;   int main() {     scanf( %d%d , &n, &m);     gets(s);     for (i = 0; i < n; i++) {       gets(s);       if (s[0] <  0  || s[0] >  9  || s[0] == p)         q = false;       else         p = s[0];       for (j = 1; j < m; j++)         if (s[j] != p) q = false;     }     if (q)       puts( YES );     else       puts( NO );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     char str[10000];     cin >> str;     if (str[0] >=  a  && str[0] <=  z ) str[0] = str[0] - 32;     cout << str;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 10007;   int n, m, d, p[maxn], k[maxn], c[maxn], ans[maxn], vis[maxn], match[maxn];   vector<int> adj[maxn];   bool dfs(int u) {     for (int i = 0; i < adj[u].size(); i++) {       int v = adj[u][i];       if (!vis[v]) {         vis[v] = 1;         if (match[v] == -1 || dfs(match[v])) {           match[v] = u;           return true;         }       }     }     return false;   }   int main() {     cin >> n >> m;     for (int i = 1; i <= n; i++) cin >> p[i];     for (int i = 1; i <= n; i++) {       cin >> c[i];     }     cin >> d;     for (int i = 1; i <= d; i++) {       cin >> k[i];       vis[k[i]] = 1;     }     for (int i = 1; i <= n; i++) {       if (!vis[i]) {         adj[p[i]].push_back(c[i] + 5000);         adj[c[i] + 5000].push_back(p[i]);       }     }     memset(match, -1, sizeof(match));     memset(vis, 0, sizeof(vis));     while (dfs(ans[d])) {       ans[d]++;       memset(vis, 0, sizeof(vis));     }     for (int i = d - 1; i; i--) {       adj[p[k[i + 1]]].push_back(c[k[i + 1]] + 5000);       adj[c[k[i + 1]] + 5000].push_back(p[k[i + 1]]);       ans[i] = ans[i + 1];       memset(vis, 0, sizeof(vis));       while (dfs(ans[i])) {         ans[i]++;         memset(vis, 0, sizeof(vis));       }     }     for (int i = 1; i <= d; i++) printf( %d n , ans[i]);   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 998244353;   map<int, int> mmp;   long long qpow(long long a, long long b, long long m) {     long long ans = 1, aa = a;     while (b) {       if (b & 1) ans = ans * aa % m;       aa = aa * aa % m;       b >>= 1;     }     return ans;   }   int a[200010];   int ccc[200010];   int main() {     int n, i, x = 1;     cin >> n;     for (i = 1; i <= n; i++) {       cin >> a[i];       mmp[a[i]] = i;     }     int pos = 1;     ccc[0] = mmp[a[1]];     int num = 0;     while (pos <= n) {       while (pos <= n) {         ccc[num] = max(mmp[a[pos]], ccc[num]);         if (pos == ccc[num]) break;         pos++;       }       if (pos == n) break;       pos++;       num++;     }     cout << qpow(2, num, mod) << endl;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using vi = vector<int>;   using vvi = vector<vi>;   using vpii = vector<pair<int, int>>;   using vc = vector<char>;   using vvc = vector<vc>;   long long binpow(long long a, long long n) {     long long res = 1;     while (n) {       if (n & 1) res *= a;       a *= a;       n >>= 1;     }     return res;   }   bool prime(long long n) {     for (long long i = 2; i <= sqrt(n); i++) {       if (n % i == 0) return false;     }     return true;   }   int gcd(int a, int b) {     while (b) {       a %= b;       swap(a, b);     }     return a;   }   long long lcm(int a, int b) { return a / gcd(a, b) * b; }   template <class T1, class T2>   void Cin_vector(vector<T1>& a, T2 n) {     for (auto& val : a) {       std::cin >> val;     }   }   template <class T1, class T2>   void Cout_vector(vector<T1>& a, T2 n) {     for (auto& val : a) {       std::cout << val <<    ;     }   }   template <class T1, class T2, class T3>   void Cin_matrix(vector<vector<T1>>& a, T2 n, T3 m) {     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         std::cin >> a[i][j];       }     }   }   template <class T1, class T2, class T3>   void Cout_matrix(vector<vector<T1>>& a, T2 n, T3 m) {     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         std::cout << a[i][j] <<    ;       }       std::cout <<   n ;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     vector<string> otvet = { F ,  M ,  S };     vector<string> strs;     map<string, int> counts;     for (int i = 0; i < 3; i++) {       string s;       std::cin >> s;       strs.push_back(s);       counts[s]++;     }     int maxs = 0;     string temp;     for (auto& [strings, cnt] : counts) {       if (cnt > maxs) {         maxs = cnt;         temp = strings;       }     }     if (maxs == 1 || maxs == 3) {       std::cout <<  ? ;     } else {       string c;       for (auto& [strings, cnt] : counts) {         if (strings != temp) {           c = strings;         }       }       if (temp ==  rock  && c ==  paper  || temp ==  paper  && c ==  scissors  ||           temp ==  scissors  && c ==  rock ) {         for (int i = 0; i < 3; i++) {           if (c == strs[i]) {             std::cout << otvet[i];             break;           }         }       } else {         std::cout <<  ? ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const int inf = 0x7f7f7f7f;   const int maxn = 1e3 + 5;   int n, u, v, root, cnt[2], S;   vector<int> vec[maxn];   int sz[maxn], msz[maxn];   void dfs1(int x, int par) {     for (int i = 0; i <= (int)vec[x].size() - 1; i++) {       if (vec[x][i] == par) continue;       dfs1(vec[x][i], x);       sz[x] += sz[vec[x][i]];       msz[x] = max(msz[x], sz[vec[x][i]]);     }     sz[x]++;     msz[x] = max(msz[x], n - sz[x]);   }   int par[maxn];   int find(int x) {     if (x == par[x]) return x;     return par[x] = find(par[x]);   }   void dfs2(int x, int par, int f, int used) {     for (int i = 0; i <= (int)vec[x].size() - 1; i++) {       if (par == vec[x][i]) continue;       int now = ++cnt[f] - used;       dfs2(vec[x][i], x, f, now + used);       if (f) now *= (S + 1);       printf( %d %d %d n , x, vec[x][i], now);     }   }   int main() {     cin >> n;     if (n == 1) return 0;     for (int i = 1; i <= n - 1; i++) {       scanf( %d%d , &u, &v);       vec[u].push_back(v);       vec[v].push_back(u);     }     dfs1(1, -1);     root = 1;     for (int i = 1; i <= n; i++) {       if (msz[i] < msz[root]) root = i;     }     memset(sz, 0, sizeof(sz));     dfs1(root, -1);     priority_queue<pair<int, int>, vector<pair<int, int> >,                    greater<pair<int, int> > >         que;     for (int i = 0; i <= (int)vec[root].size() - 1; i++) {       que.push(pair<int, int>(sz[vec[root][i]], vec[root][i]));     }     for (int i = 1; i <= n; i++) par[i] = i;     while (que.size() >= 3) {       pair<int, int> p1 = que.top();       que.pop();       pair<int, int> p2 = que.top();       que.pop();       par[p2.second] = find(p1.second);       que.push(pair<int, int>(p1.first + p2.first, par[p1.second]));     }     for (int i = 1; i <= n; i++) find(i);     int pp = par[vec[root][0]];     for (int i = 0; i <= (int)vec[root].size() - 1; i++) {       if (par[vec[root][i]] == pp) S += sz[vec[root][i]];     }     for (int i = 0; i <= (int)vec[root].size() - 1; i++) {       if (par[vec[root][i]] == pp) {         printf( %d %d %d n , root, vec[root][i], ++cnt[0]);         dfs2(vec[root][i], root, 0, cnt[0]);       } else {         printf( %d %d %d n , root, vec[root][i], ++cnt[1] * (S + 1));         dfs2(vec[root][i], root, 1, cnt[1]);       }     }   }


#include <bits/stdc++.h>      using namespace std;      #define _ ios_base::sync_with_stdio(0);cin.tie(0);   #define endl   n       typedef long long ll;      const int INF = 0x3f3f3f3f;   const ll LINF = 0x3f3f3f3f3f3f3f3fll;      int main(){ _       int n; cin >> n;    vector<int> a(n);    for(int& i : a) cin >> i;        auto oa = a;    sort(oa.begin(), oa.end());    auto it = unique(oa.begin(), oa.end());    oa.resize(distance(oa.begin(), it));    map<int,int> mp;    int m = oa.size();    for(int i = 0; i < m; i++) mp[oa[i]] = i;    for(auto& i : a) i = mp[i];       vector<vector<int>> ct(m);    for(int i = 0; i < n; i++) ct[a[i]].push_back(i);       vector<vector<int>> g(n);    for(int i = 0; i < n-1; i++) {     int u, v; cin >> u >> v; u--, v--;     g[u].push_back(v);     g[v].push_back(u);    }       int time = 0;    vector<int> in(n,-1), out(n);    function<void(int)> tour = [&] (int v) {     in[v] = time;     for(auto u : g[v]) if(in[u] == -1) tour(u);     out[v] = time++;    };       tour(0);       auto very_bad = [&] () {     cout << 0 << endl;     exit(0);    };       vector<int> sum(n+1, 0);    auto update = [&] (int l, int r, int x) {     sum[l] += x, sum[r + 1] -= x;    };       for(int i = 0; i < m; i++) if(ct[i].size() > 1) {     vector<pair<int,int>> aux;     for(auto u : ct[i]) aux.push_back({out[u], u});     sort(aux.begin(), aux.end());        set<int> cur;     int anc = -1, nanc = 0;     for(auto [outt, u] : aux) {      int l = in[u], r = out[u];      if(nanc and r > out[anc]) very_bad();            auto itl = cur.lower_bound(l);      auto itr = cur.upper_bound(r);            if(itl != itr) {       anc = u, nanc++;       if(itl != cur.begin() or itr != cur.end()) very_bad();      }      if(nanc > 2) very_bad();            cur.insert(r);     }        if(nanc == 0) {      for(auto u : ct[i]) update(in[u], out[u], 1);     }     else {      bool found = false;      int good_child = -1;      for(auto u : g[anc]) if(out[u] < out[anc]) {       int l = in[u], r = out[u];       auto itl = cur.lower_bound(l);       auto itr = cur.upper_bound(r);          if(itl != itr) {        if(found) very_bad();        found = true;        good_child = u;       }      }         update(0, n-1, 1);      update(in[good_child], out[good_child], -1);      for(auto u : ct[i]) if(u != anc) {       update(in[u], out[u], 1);      }     }    }       int ans = 0;    for(int i = 0; i < n; i++) {     if(i) sum[i] += sum[i-1];     if(!sum[i]) {      ans++;     }    }       cout << ans << endl;       return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int power(long long int x, long long int y, long long int m) {     if (y == 0) return 1;     long long int p = power(x, y / 2, m) % m;     p = (p * p) % m;     return (y % 2 == 0) ? p : (x * p) % m;   }   long long int nCr(long long int n, long long int r, long long int m) {     if (r > n) return 0;     long long int a = 1, b = 1, i;     for (i = 0; i < r; i++) {       a = (a * n) % m;       --n;     }     while (r) {       b = (b * r) % m;       --r;     }     return (a * power(b, m - 2, m)) % m;   }   vector<vector<int>> sufs, suft, ans;   string s, t;   int dp(int a, int b) {     if (b == 0) return 0;     if (ans[a][b] != -1) return ans[a][b];     ans[a][b] = 1e5;     if (a > 0) ans[a][b] = min(ans[a][b], 1 + dp(a - 1, b));     if (s[a - 1] == t[b - 1] && a > 0)       ans[a][b] = min(ans[a][b], dp(a - 1, b - 1));     int ch = t[b - 1] -  a ;     if (sufs[a][ch] - suft[b][ch] > 0) ans[a][b] = min(ans[a][b], dp(a, b - 1));     return ans[a][b];   }   void solve() {     int n;     cin >> n;     cin >> s >> t;     sufs = suft = vector<vector<int>>(n + 1, vector<int>(26, 0));     for (int i = n - 1; i >= 0; --i) {       sufs[i][s[i] -  a ]++;       suft[i][t[i] -  a ]++;       for (int j = 0; j < 26; ++j) {         sufs[i][j] += sufs[i + 1][j];         suft[i][j] += suft[i + 1][j];         if (i == 0 && sufs[i][j] != suft[i][j]) {           cout << -1 <<   n ;           return;         }       }     }     ans = vector<vector<int>>(n + 1, vector<int>(n + 1, -1));     cout << dp(n, n);     cout <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     cin >> t;     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long n, d = 0, e = 0, a[10000] = {0}, c = 0;     cin >> n;     for (long i = 0; i < n; i++) {       cin >> a[i];       c = c + a[i];     }     for (long j = 0; j < n; j++) {       d = c - a[j];       if ((d % 2) == 0) {         e = e + 1;       }     }     cout << e;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = (int)1e9 + 7;   const int N = 100005;   const double PI = 4 * atan(1);   const double eps = 1e-7;   const long long oo = 1e10;   const int K = 26;   vector<int> sort_cyclic_shifts(string const& s) {     int n = s.size();     const int alphabet = 256;     vector<int> p(n), c(n), cnt((alphabet > n ? alphabet : n), 0);     for (int i = 0; i < n; i++) cnt[s[i]]++;     for (int i = 1; i < alphabet; i++) cnt[i] += cnt[i - 1];     for (int i = 0; i < n; i++) p[--cnt[s[i]]] = i;     c[p[0]] = 0;     int classes = 1;     for (int i = 1; i < n; i++) {       if (s[p[i]] != s[p[i - 1]]) classes++;       c[p[i]] = classes - 1;     }     vector<int> pn(n), cn(n);     for (int h = 0; (1 << h) < n; ++h) {       for (int i = 0; i < n; i++) {         pn[i] = p[i] - (1 << h);         if (pn[i] < 0) pn[i] += n;       }       fill(cnt.begin(), cnt.begin() + classes, 0);       for (int i = 0; i < n; i++) cnt[c[pn[i]]]++;       for (int i = 1; i < classes; i++) cnt[i] += cnt[i - 1];       for (int i = n - 1; i >= 0; i--) p[--cnt[c[pn[i]]]] = pn[i];       cn[p[0]] = 0;       classes = 1;       for (int i = 1; i < n; i++) {         pair<int, int> cur = {c[p[i]], c[(p[i] + (1 << h)) % n]};         pair<int, int> prev = {c[p[i - 1]], c[(p[i - 1] + (1 << h)) % n]};         if (cur != prev) ++classes;         cn[p[i]] = classes - 1;       }       c.swap(cn);     }     return p;   }   vector<int> suffix_array_construction(string s) {     s +=  $ ;     vector<int> sorted_shifts = sort_cyclic_shifts(s);     sorted_shifts.erase(sorted_shifts.begin());     return sorted_shifts;   }   vector<int> lcp_construction(string const& s, vector<int> const& p) {     int n = s.size();     vector<int> rank(n, 0);     for (int i = 0; i < n; i++) rank[p[i]] = i;     int k = 0;     vector<int> lcp(n - 1, 0);     for (int i = 0; i < n; i++) {       if (rank[i] == n - 1) {         k = 0;         continue;       }       int j = p[rank[i] + 1];       while (i + k < n && j + k < n && s[i + k] == s[j + k]) k++;       lcp[rank[i]] = k;       if (k) k--;     }     return lcp;   }   string s;   long long k;   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cin >> s;     long long n = s.size();     cin >> k;     if (k > n * (n + 1) / 2) {       cout <<  No such line. ;       return 0;     }     vector<int> p = suffix_array_construction(s);     vector<int> lcp = lcp_construction(s, p);     int st = 0;     for (int i = 0; i < n; i++) {       if (i == 0) {         st = 0;       } else {         st = lcp[i - 1];       }       while (st < n - p[i] && k) {         int j = i;         k--;         while (j < n - 1 && lcp[j] > st && k) {           j++;           k--;           if (k == 0) break;         }         if (k == 0) break;         st++;       }       if (k == 0) {         for (int o = p[i]; o <= p[i] + st; o++) {           cout << s[o];         }         return 0;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   string s[3003], t[3003];   long long hhs[3003][3003], hht[3003][3003], pp[3003], hhts[3003], hhtt[3003];   pair<int, int> cseg[3003];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     pp[0] = 1;     for (int i = 1; i < 3003; ++i) pp[i] = pp[i - 1] * 47017 % mod;     int n;     cin >> n;     for (int i = 1; i <= n; ++i) cin >> s[i];     for (int i = 1; i <= n; ++i) cin >> t[i];     if (0) {       for (int i = 1; i <= n; ++i) cout << s[i] << endl << t[i] << endl << endl;     }     string ts, tt;     for (int i = 1; i <= n; ++i) {       int L = 1e9, R = 0;       for (int j = 0; j < int(s[i].size()); ++j) {         if (s[i][j] != t[i][j]) L = min(L, j), R = max(R, j);       }       cseg[i] = {L, R};       if (L < 1e9) {         string cs = s[i].substr(L, R - L + 1);         string ct = t[i].substr(L, R - L + 1);         if (ts ==   )           ts = cs, tt = ct;         else {           if (ts != cs || tt != ct)             exit((cout <<  NO  << endl, 0));           else             ;         }       }     }     while (1) {       bool lexp = 1;       char lsamp = 0;       char tsamp = 0;       for (int i = 1; i <= n; ++i) {         if (cseg[i].first == 1e9) continue;         if (cseg[i].first == 0) {           if (0) {             cout <<  l can not expand at i=  << i << endl;           }           lexp = 0;           break;         }         if (lsamp) {           if (s[i][cseg[i].first - 1] != lsamp ||               t[i][cseg[i].first - 1] != tsamp) {             lexp = 0;             if (0) {               cout <<  l can not expand at i=  << i << endl;             }             break;           } else             ;         } else {           lsamp = s[i][cseg[i].first - 1];           tsamp = t[i][cseg[i].first - 1];         }       }       if (!lexp) break;       ts = string(1, lsamp) + ts;       tt = string(1, tsamp) + tt;       for (int i = 1; i <= n; ++i) {         if (cseg[i].first == 1e9) continue;         --cseg[i].first;       }     }     while (1) {       bool rexp = 1;       char samp = 0;       char tamp = 0;       for (int i = 1; i <= n; ++i) {         if (cseg[i].first == 1e9) continue;         if (cseg[i].second == int(s[i].size()) - 1) {           rexp = 0;           break;         }         if (samp) {           if (s[i][cseg[i].second + 1] != samp ||               t[i][cseg[i].second + 1] != tamp) {             rexp = 0;             break;           } else             ;         } else {           samp = s[i][cseg[i].second + 1];           tamp = t[i][cseg[i].second + 1];         }       }       if (!rexp) break;       ts += samp;       tt += samp;       for (int i = 1; i <= n; ++i) {         if (cseg[i].first == 1e9) continue;         ++cseg[i].second;       }     }     for (int i = 1; i <= n; ++i) {       for (int j = 0; j < int(s[i].size()); ++j) {         if (j)           hhs[i][j] = (hhs[i][j - 1] + s[i][j] * pp[j]) % mod;         else           hhs[i][j] = s[i][j];         if (j)           hht[i][j] = (hht[i][j - 1] + t[i][j] * pp[j]) % mod;         else           hht[i][j] = t[i][j];       }     }     for (int j = 0; j < int(ts.size()); ++j) {       if (j)         hhts[j] = (hhts[j - 1] + ts[j] * pp[j]) % mod;       else         hhts[j] = ts[j];       if (j)         hhtt[j] = (hhtt[j - 1] + tt[j] * pp[j]) % mod;       else         hhtt[j] = tt[j];     }     for (int i = 1; i <= n; ++i) {       for (int j = 0; j + int(ts.size()) - 1 < int(s[i].size()); ++j) {         if (((hhs[i][j + int(ts.size()) - 1] - ((j) ? hhs[i][(j)-1] : 0ll) +               mod) *              pp[3001 - (j + int(ts.size()) - 1)] % mod) ==             ((hhts[int(ts.size()) - 1] - ((0) ? hhts[(0) - 1] : 0ll) + mod) *              pp[3001 - (int(ts.size()) - 1)] % mod)) {           if (cseg[i].first != j) {             cout <<  NO  << endl;             exit(0);           } else             break;         }       }     }     cout <<  YES  << endl << ts << endl << tt << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   const long long MOD = 1e9 + 7;   vector<int> ans1, ans2;   int a[N];   bool work(bool c[], int n) {     vector<int> p1, p2;     for (int i = 0; i < n; ++i) {       if (c[i])         p1.push_back(a[i]);       else         p2.push_back(a[i]);     }     if (p2.size() == 0)       return 0;     else if (p2.size() <= 2) {       ans1 = p1;       ans2 = p2;       return 1;     } else {       int r = p2[1] - p2[0];       for (int i = 2; i < p2.size(); ++i) {         if (p2[i] - p2[i - 1] != r) return 0;       }       ans1 = p1;       ans2 = p2;       return 1;     }   }   bool check(int f, int r, int n) {     bool c[n];     memset(c, false, sizeof(c));     vector<int> p1, p2;     for (int i = 0; i < n; ++i) {       if (a[i] == f) {         c[i] = 1;         f += r;       }     }     if (work(c, n)) return 1;     for (int i = n - 1; i >= 0; --i) {       if (c[i]) {         c[i] = 0;         return work(c, n);       }     }     return 0;   }   void printSolution() {     for (int i = 0; i < ans1.size(); ++i) {       cout << ans1[i] <<    n [ans1.size() - i == 1];     }     for (int i = 0; i < ans2.size(); ++i) {       cout << ans2[i] <<    n [ans2.size() - i == 1];     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     for (int i = 0; i < n; ++i) {       cin >> a[i];     }     if (check(a[0], a[1] - a[0], n)) {       printSolution();     } else if (check(a[0], a[2] - a[0], n)) {       printSolution();     } else if (check(a[1], a[2] - a[1], n)) {       printSolution();     } else       cout <<  No solution  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   long long n, i;   long long a[102];   long long dp[102][102][2];   signed main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long t;     cin >> t;     while (t--) {       cin >> n;       string s[2];       cin >> s[0] >> s[1];       long long r, c;       r = 0;       for (i = 0; i < n; ++i) {         if (s[r % 2][i] >=  3 ) {           if (s[(r + 1) % 2][i] <  3 ) {             break;           } else {             r = (r + 1) % 2;           }         }       }       if (i == n && r == 1) {         puts( yes n );       } else         puts( no n );     }     return 0;   }


#include <bits/stdc++.h>   template <class T>   class three {     T _first, _second, _third;       public:     T &first, &second, &third;     three(T f, T s, T t) : first(_first), second(_second), third(_third) {       _first = f;       _second = s;       _third = t;     }     three(const three& other) : first(_first), second(_second), third(_third) {       _first = other._first;       _second = other._second;       _third = other._third;     }     const three& operator=(const three& other) {       _first = other._first;       _second = other._second;       _third = other._third;       return *this;     }     bool operator<(const three& other) const {       if (first < other.first)         return true;       else if (first == other.first)         if (second < other.second)           return true;         else if (second == other.second)           if (third < other.third)             return true;           else             return false;         else           return false;       else         return false;     }   };   std::vector<std::vector<int> > edges;   std::vector<std::vector<int> > order;   std::vector<bool> visited;   std::vector<int> number;   int countLeafs(int vertex) {     visited[vertex] = true;     int result = 0;     if (vertex != 1 && edges[vertex].size() == 1) result = 1;     for (int i = 0; i < edges[vertex].size(); ++i)       if (!visited[edges[vertex][i]]) result += countLeafs(edges[vertex][i]);     return result;   }   void printOrder(int vertex) {     std::cout << vertex <<    ;     for (int i = 0; i < order[vertex].size(); ++i) {       printOrder(order[vertex][i]);       std::cout << vertex <<    ;     }   }   bool calcOrder(int vertex, three<int>& range) {     std::set<three<int> > childRanges;     visited[vertex] = true;     for (int i = 0; i < edges[vertex].size(); ++i)       if (!visited[edges[vertex][i]]) {         three<int> result(0, 0, 0);         if (!calcOrder(edges[vertex][i], result)) return false;         childRanges.insert(result);       }     bool bad_tree = false;     for (std::set<three<int> >::iterator i = childRanges.begin();          i != childRanges.end(); ++i) {       std::set<three<int> >::iterator j = i;       ++j;       if (false && vertex == 4 && j != childRanges.end()) {         std::cout <<  i = [  << i->third <<   :   << i->first <<     << i->second                   <<  ]  << std::endl;         std::cout <<  j = [  << j->third <<   :   << j->first <<     << j->second                   <<  ]  << std::endl;       }       if (j != childRanges.end() && (*i).second + 1 != (*j).first)         bad_tree = true;       order[vertex].push_back((*i).third);     }     if (bad_tree) return false;     if (childRanges.size() > 0) {       range.first = childRanges.begin()->first;       range.second = childRanges.rbegin()->second;       range.third = vertex;     } else {       range.first = number[vertex];       range.second = number[vertex];       range.third = vertex;     }     return true;   }   void output2d(const std::string& name,                 const std::vector<std::vector<int> >& array) {     for (int i = 0; i < array.size(); ++i) {       std::cout << name <<  [  << i <<  ] = [ ;       for (int j = 0; j + 1 < array[i].size(); ++j)         std::cout << array[i][j] <<    ;       if (array[i].size() > 0) std::cout << array[i][array[i].size() - 1];       std::cout <<  ]  << std::endl;     }   }   int main() {     int n;     std::cin >> n;     edges.resize(n + 1);     for (int i = 0; i < n - 1; ++i) {       int a, b;       std::cin >> a >> b;       edges[a].push_back(b);       edges[b].push_back(a);     }     visited.resize(n + 1);     std::fill(visited.begin(), visited.end(), false);     int leafCount = countLeafs(1);     number.resize(n + 1);     for (int i = 0; i < leafCount; ++i) {       int vertex;       std::cin >> vertex;       number[vertex] = i + 1;     }     std::fill(visited.begin(), visited.end(), false);     order.resize(n + 1);     three<int> spam(0, 0, 0);     if (calcOrder(1, spam)) {       printOrder(1);     } else       std::cout << -1;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 200018;   int arr[N];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     map<long long, int> mp;     long long sum1 = 0;     for (int i = 1; i <= n; i++) {       cin >> arr[i], sum1 += arr[i];       mp[sum1] = i;     }     long long sum3 = 0, ans = 0;     for (int i = n; i >= 1; i--) {       sum3 += arr[i];       if (mp[sum3] && mp[sum3] < i) {         ans = sum3;       }     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   const long long MAXN = 1e5 + 10;   const long long INF = 2e9;   const double PI = acos(-1);   long long n, m, p, pi = 1;   long long fa[MAXN], k;   long long siz[MAXN];   template <typename T>   inline void read(T &a) {     a = 0;     char c = getchar();     long long f = 1;     while (c <  0  || c >  9 ) {       if (c ==  - ) f = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       a = a * 10 + (c ^ 48);       c = getchar();     }     a *= f;   }   long long find(long long x) {     if (x != fa[x]) return fa[x] = find(fa[x]);     return fa[x];   }   void merge(long long x, long long y) {     x = find(x), y = find(y);     if (x == y) return;     siz[x] += siz[y];     fa[y] = x;   }   long long qpow(long long x, long long b) {     long long res = 1;     if (b <= 0) return res;     for (; b; b >>= 1, (x *= x) %= p)       if (b & 1) (res *= x) %= p;     return res;   }   signed main() {     read(n);     read(m);     read(p);     for (long long i = 1; i <= n; ++i) fa[i] = i, siz[i] = 1;     for (long long i = 1, x, y; i <= m; ++i) {       read(x);       read(y);       merge(x, y);     }     for (long long i = 1; i <= n; ++i)       if (fa[i] == i) (pi *= siz[i]) %= p, k++;     if (k < 2)       printf( %d n , 1 % p);     else       printf( %lld n , qpow(n, k - 2) * pi % p);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long len(long long x, long long y) { return x * x + y * y; }   long long scal(long long x1, long long y1, long long x2, long long y2) {     if (x1 * y2 == x2 * y1) return -1;     return x1 * x2 + y1 * y2;   }   bool in(long long x1, long long y1, long long x2, long long y2, long long x,           long long y) {     long long vx = x1 - x;     long long vy = y1 - y;     long long wx = x2 - x;     long long wy = y2 - y;     if (vx * wy == vy * wx && vx * wx + vy * wy < 0) return true;     return false;   }   bool sootn(long long x1, long long y1, long long x2, long long y2, long long x,              long long y) {     long long vx = x - x1;     long long vy = y - y1;     long long wx = x - x2;     long long wy = y - y2;     long long l1 = len(vx, vy);     long long l2 = len(wx, wy);     if (l1 >= l2)       return (16 * l2 >= l1);     else       return (16 * l1 >= l2);   }   int Solution() {     int t;     scanf( %d , &t);     for (int i = 0; i < t; ++i) {       long long x[6], y[6];       for (int j = 0; j < 6; ++j) scanf( %I64d%I64d , &x[j], &y[j]);       int ind = -1;       for (int j = 0; j < 6; ++j)         for (int k = j + 1; k < 6; ++k)           if (x[j] == x[k] && y[j] == y[k]) {             ind = j;             break;           }       if (ind == -1) {         printf( NO n );         continue;       }       int ind1 = -1, ind2;       for (int j = 0; j < 6; ++j)         if (x[j] == x[ind] && y[j] == y[ind])           if (ind1 == -1)             ind1 = j;           else             ind2 = j;       if (ind1 & 1)         ind1--;       else         ind1++;       if (ind2 & 1)         ind2--;       else         ind2++;       long long an = scal(x[ind1] - x[ind], y[ind1] - y[ind], x[ind2] - x[ind],                           y[ind2] - y[ind]);       if (an < 0) {         printf( NO n );         continue;       }       int num3 = 3 - ind1 / 2 - ind2 / 2;       if (in(x[ind], y[ind], x[ind1], y[ind1], x[num3 * 2], y[num3 * 2]) &&           in(x[ind], y[ind], x[ind2], y[ind2], x[num3 * 2 + 1],              y[num3 * 2 + 1])) {         bool soot =             sootn(x[ind], y[ind], x[ind1], y[ind1], x[num3 * 2], y[num3 * 2]);         if (!soot) {           printf( NO n );           continue;         }         soot = sootn(x[ind], y[ind], x[ind2], y[ind2], x[num3 * 2 + 1],                      y[num3 * 2 + 1]);         if (!soot) {           printf( NO n );           continue;         }       } else if (in(x[ind], y[ind], x[ind1], y[ind1], x[num3 * 2 + 1],                     y[num3 * 2 + 1]) &&                  in(x[ind], y[ind], x[ind2], y[ind2], x[num3 * 2], y[num3 * 2])) {         bool soot = sootn(x[ind], y[ind], x[ind1], y[ind1], x[num3 * 2 + 1],                           y[num3 * 2 + 1]);         if (!soot) {           printf( NO n );           continue;         }         soot = sootn(x[ind], y[ind], x[ind2], y[ind2], x[num3 * 2], y[num3 * 2]);         if (!soot) {           printf( NO n );           continue;         }       } else {         printf( NO n );         continue;       }       printf( YES n );     }     return 0;   }   int main() {     Solution();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   const long double pi = acos(-1.0);   const long double eps = 1e-9;   const int MAX_SIZE = 50;   const int dX[] = {-1, 1, 0, 0, -1, 1, -1, 1};   const int dY[] = {0, 0, -1, 1, 1, -1, -1, 1};   template <class S, class T>   ostream& operator<<(ostream& o, const pair<S, T>& a) {     o << a.first <<     << a.second;     return o;   }   template <class S, class T>   ostream& operator<<(ostream& o, const map<S, T>& a) {     for (typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)       o << (*it) <<   n ;     return o;   }   template <class S>   ostream& operator<<(ostream& o, const vector<S>& a) {     for (typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)       o << *it <<    ;     return o;   }   template <class S>   ostream& operator<<(ostream& o, const vector<vector<S> >& a) {     for (typeof((a).begin()) it = (a).begin(); it != (a).end(); it++) {       o << (*it) <<   n ;     }     return o;   }   template <class S>   ostream& operator<<(ostream& o, const set<S>& a) {     for (typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)       o << *it <<    ;     return o;   }   const long long MAX = 30;   int cnt[MAX];   int main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     ;     int w, h, x, y, x1, y1;     long long ans = 0;     cin >> w >> h;     for (x = (1);          (((1) > 0) - ((1) < 0)) * x < (((1) > 0) - ((1) < 0)) * (w / 2 + 1);          x += (1)) {       for (y = (1);            (((1) > 0) - ((1) < 0)) * y < (((1) > 0) - ((1) < 0)) * (h / 2 + 1);            y += (1)) {         x1 = w - x;         y1 = h - y;         ans += (y1 - y + 1) * (x1 - x + 1);       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxx = 1e5 + 20;   int n, c[maxx], sz[maxx], rang[maxx], okd[maxx], oku[maxx], t[maxx];   bool vis[maxx], takrang[maxx];   vector<int> adj[maxx];   void dfs(int root) {     vis[root] = true;     int tedad = t[c[0]];     if (c[0] == c[root]) tedad--;     bool bb = false, payin = true, trb = true;     for (int x : adj[root]) {       if (!vis[x]) {         bb = true;         dfs(x);         if (c[0] == c[x]) tedad -= sz[x];         sz[root] += sz[x];         if (c[root] != c[x] || !takrang[x]) trb = false;         if (!takrang[x]) payin = false;       }     }     if (!bb) {       takrang[root] = true, rang[root] = c[root], okd[root] = true, sz[root] = 1;       if ((c[root] == c[0] && t[c[0]] == n) ||           (c[root] != c[0] && t[c[0]] == n - 1))         oku[root] = true;       return;     }     sz[root]++;     takrang[root] = trb;     okd[root] = payin;     if (root == 0)       oku[root] = true;     else if (tedad == n - sz[root])       oku[root] = true;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n;     for (int i = 0; i < n - 1; i++) {       int u, v;       cin >> u >> v;       u--, v--;       adj[u].push_back(v);       adj[v].push_back(u);     }     for (int i = 0; i < n; i++) cin >> c[i], t[c[i]]++;     dfs(0);     for (int i = 0; i < n; i++)       if (oku[i] && okd[i]) return cout <<  YES  << endl << i + 1 << endl, 0;     cout <<  NO  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e3 + 5;   bool isPrime[N], vst[N];   int frq[26];   vector<int> adj[N];   vector<int> cc;   vector<vector<int>> vcc;   void dfs(int u) {     cc.push_back(u);     vst[u] = 1;     for (auto v : adj[u]) {       if (!vst[v]) dfs(v);     }   }   bool cmp(vector<int> s, vector<int> f) {     return (int)(s.size()) > (int)(f.size());   }   int main() {     ios ::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     string s;     cin >> s;     for (auto i : s) {       frq[i -  a ]++;     }     isPrime[0] = isPrime[1] = 1;     for (int i = 2; i <= (int)(s.size()); i++) {       if (isPrime[i]) continue;       for (int j = 2 * i; j <= (int)(s.size()); j += i) {         isPrime[j] = 1;         adj[i].push_back(j);         adj[j].push_back(i);       }     }     for (int i = 1; i <= (int)(s.size()); i++) {       if (!isPrime[i] && !vst[i]) {         cc.clear();         dfs(i);         vcc.push_back(cc);       }     }     vector<char> out((int)(s.size()) + 2);     for (auto i : vcc) {       int siz = (int)(i.size());       int mn = (int)(s.size()) + 1;       int ch = 26;       for (int j = 0; j < 26; j++) {         if (frq[j] >= siz && frq[j] < mn) {           mn = frq[j];           ch = j;         }       }       if (ch == 26) {         return cout <<  NO n , 0;       }       frq[ch] -= siz;       for (auto j : i) {         out[j] = ch +  a ;       }     }     for (int i = 1; i <= (int)(s.size()); i++) {       for (int j = 0; j < 26; j++) {         if (frq[j]) {           frq[j]--;           out[i] = j +  a ;           break;         }       }     }     cout <<  YES n ;     for (int i = 1; i <= (int)(s.size()); i++) cout << out[i];   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5, INF = 1e9;   int a[N], n, x, y, res = 0;   int main() {     int t;     ios::sync_with_stdio(false);     cin >> t;     while (t--) {       cin >> n >> x >> y;       int res = INF;       int rs = 0, rc = 0;       for (int i = 1; i <= x; i++) {         for (int j = 1; j <= y - x + 1; j++) {           int c = i;           bool flag = true;           bool fa = false, fb = false;           for (int k = 1; k <= n; k++) {             if (c == x) {               fa = true;             }             if (c == y) {               fb = true;             }             if (c > x && fa == false) break;             if (c > y && fb == false) break;             c += j;           }           if (fa && fb) {             if (c < res) {               res = c;               rs = i;               rc = j;             }           }         }       }       int cnt = 1;       for (int i = rs; cnt <= n; cnt++, i += rc) {         cout << i <<    ;       }       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e3 + 5;   int n, m, k, a[N][N];   const int mod = 1e9 + 7;   int f[N][N], used[15];   int ans = 0;   inline void Plus(int &x, const int &y) {     x += y;     if (x >= mod) x -= mod;   }   inline int dfs(int x, int y) {     if (y > m) y = 1, ++x;     if (x == n + 1) return 1;     int now = f[x][y - 1] | f[x - 1][y], tmp = -1, res = 0;     int num = 0;     for (int i = k; i >= 1; i--) num += !((now >> (i - 1)) & 1);     if (n + m - x - y + 1 > num) return 0;     for (int i = 1; i <= k; i++)       if (!(now >> (i - 1) & 1)) {         if (!a[x][y] || a[x][y] == i) {           f[x][y] = now | (1 << i - 1);           if (++used[i] == 1) {             if (tmp == -1) tmp = dfs(x, y + 1);             Plus(res, tmp);           } else             Plus(res, dfs(x, y + 1));           --used[i];         }       }     return res;   }   int main() {     scanf( %d%d%d , &n, &m, &k);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) scanf( %d , &a[i][j]), ++used[a[i][j]];     if (n + m - 1 > k) return printf( 0 n ), 0;     printf( %d n , dfs(1, 1));   }


#include <bits/stdc++.h>   #pragma GCC diagnostic push   #pragma GCC diagnostic ignored  -Wunused-variable    using namespace std;   using ll = long long;   const ll N = 1e6 + 3LL;   const int inf = 1e9 + 3;   const ll M = 1e9 + 7;   const ll T = 998244353;   const double pi = 3.14159;   ll n, m;   ll t[4 * N];   ll xl[N], xr[N];   bool mark[N];   vector<ll> start[N], en[N];   void upd(ll v, ll tl, ll tr, ll pos, ll val) {     if (tl == tr) {       t[v] = val;       return;     }     ll tm = (tl + tr) / 2;     if (pos <= tm) {       upd(2 * v, tl, tm, pos, val);     } else {       upd(2 * v + 1, tm + 1, tr, pos, val);     }     t[v] = t[2 * v] + t[2 * v + 1];   }   ll query(ll v, ll tl, ll tr, ll l, ll r) {     if (l > r) {       return 0;     }     if (tl == l && tr == r) {       return t[v];     }     ll tm = (tl + tr) / 2;     return query(2 * v, tl, tm, l, min(r, tm)) +            query(2 * v + 1, tm + 1, tr, max(l, tm + 1), r);   }   void solve() {     cin >> n >> m;     ll i, j, w1, w2, p;     for (i = 0; i <= N - 1; i++) {       mark[i] = false;     }     ll ans = 1;     for (i = 1; i <= n; i++) {       cin >> p >> w1 >> w2;       mark[p] = true;       xl[p] = w1;       xr[p] = w2;       if (w1 == 0 && w2 == 1000000LL) {         ans++;       }     }     for (i = 1; i <= m; i++) {       cin >> p >> w1 >> w2;       start[w1].push_back(p);       en[w2].push_back(p);       if (w1 == 0 && w2 == 1000000LL) {         ans++;       }     }     ll e = 999999LL;     for (i = 0; i <= 1000000LL; i++) {       for (auto u : start[i]) {         upd(1, 1, e, u, 1);       }       if (mark[i]) {         ans += query(1, 1, e, max(xl[i], 1LL), min(xr[i], e));       }       for (auto u : en[i]) {         upd(1, 1, e, u, 0);       }     }     cout << ans <<   n ;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int _t = 1, i;     for (i = 1; i <= _t; i++) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int t = 0, x = 0, ans = 0;   int a, b;   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) {       scanf( %d%d , &a, &b);       x -= a - t;       if (x < 0) x = 0;       x += b;       ans = max(ans, x);       t = a;     }     printf( %d %d , t + x, ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, p = (1 << 19);   pair<pair<int, int>, pair<int, int> > w[(1 << 20)];   int rmax[(1 << 20)];   priority_queue<pair<int, int> > pq;   int rpush[(1 << 20)];   int loc[(1 << 20)];   int best = 0, bestx = 0, besty = 0;   void push(int a) {     rmax[a] += rpush[a];     if (a < p) {       rpush[2 * a] += rpush[a];       rpush[2 * a + 1] += rpush[a];     }     rpush[a] = 0;   }   int get_max() {     push(1);     return rmax[1];   }   void range_add(int x, int lo, int hi, int qlo, int qhi, int val) {     push(x);     if (hi < qlo || lo > qhi) return;     if (hi <= qhi && lo >= qlo) {       rpush[x] += val;       push(x);       return;     } else {       range_add(2 * x, lo, (hi + lo) / 2, qlo, qhi, val);       range_add(2 * x + 1, (hi + lo) / 2 + 1, hi, qlo, qhi, val);       if (rmax[2 * x] < rmax[2 * x + 1]) {         rmax[x] = rmax[2 * x + 1];         loc[x] = loc[2 * x + 1];       } else {         rmax[x] = rmax[2 * x];         loc[x] = loc[2 * x];       }     }   }   void do_loc(int x, int lo, int hi) {     loc[x] = lo;     if (x >= p) return;     do_loc(2 * x, lo, (hi + lo) / 2);     do_loc(2 * x + 1, (hi + lo) / 2 + 1, hi);   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d %d %d , &w[i].first.first, &w[i].first.second,             &w[i].second.first);       w[i].second.second = i + 1;     }     sort(w, w + n);     memset(rmax, 0, sizeof(rmax));     memset(rpush, 0, sizeof(rpush));     memset(loc, 0, sizeof(loc));     do_loc(1, 1, p);     int j = 0;     while (j < n) {       range_add(1, 1, p, w[j].first.second, w[j].second.first, 1);       pq.push(pair<int, int>(-w[j].first.second, j));       while (-pq.top().first < w[j].first.first) {         range_add(1, 1, p, w[pq.top().second].first.second,                   w[pq.top().second].second.first, -1);         pq.pop();       }       if (get_max() > best) {         best = get_max();         bestx = w[j].first.first;         besty = loc[1];       }       j++;     }     vector<int> ans;     for (int i = 0; i < n; i++) {       if (w[i].first.first <= bestx && w[i].first.second >= bestx &&           w[i].first.second <= besty && w[i].second.first >= besty) {         ans.push_back(w[i].second.second);       }     }     printf( %d n , ans.size());     for (int i = 0; i < (int)ans.size(); i++) {       if (i != 0) printf(   );       printf( %d , ans[i]);     }     printf(  n );   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const int inf = 0x3f3f3f3f;   const int N = 1e5 + 5;   const int M = 1e5 + 5;   const int mod = 1e9 + 7;   int T;   int n, ind, l, r;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> n >> ind >> l >> r;     if (l == 1 && r == n) {       cout << 0;     } else if (l == 1) {       cout << abs(r - ind) + 1;     } else if (r == n) {       cout << abs(ind - l) + 1;     } else {       if (ind >= l && ind <= r) {         cout << min(r - ind, ind - l) + 2 + r - l;       } else if (ind < l) {         cout << r - ind + 2;       } else {         cout << ind - l + 2;       }     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename Arg1>   void __f(const char* name, Arg1&& arg1) {     cerr << name <<   :   << arg1 << std::endl;   }   template <typename Arg1, typename... Args>   void __f(const char* names, Arg1&& arg1, Args&&... args) {     const char* comma = strchr(names + 1,  , );     cerr.write(names, comma - names) <<   :   << arg1 <<   |  ;     __f(comma + 1, args...);   }   const int mod = 1e9 + 7;   int main() {     int n;     cin >> n;     map<string, int> mp;     for (int i = 0; i < n; i++) {       string s;       cin >> s;       if (mp.find(s) != mp.end()) {         cout <<  YES n ;         continue;       } else {         cout <<  NO n ;         mp[s] = 1;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   namespace output {   void pr(short x) { cout << x; }   void pr(unsigned x) { cout << x; }   void pr(int x) { cout << x; }   void pr(long long x) { cout << x; }   void pr(unsigned long long x) { cout << x; }   void pr(double x) { cout << x; }   void pr(long double x) { cout << x; }   void pr(char x) { cout << x; }   void pr(const char* x) { cout << x; }   void pr(const string& x) { cout << x; }   void pr(bool x) { cout << (x ?  true  :  false ); }   template <class S, class T>   void pr(const pair<S, T>& x) {     pr(1 ?  (  :   ), pr(x.first), pr(1 ?  ,   :    ), pr(x.second),         pr(1 ?  )  :   );   }   template <class T>   void pr(const vector<T>& x) {     pr(1 ?  {  :   );     bool _ = 0;     for (const auto& v : x) pr(_ ? 1 ?  ,   :     :   ), pr(v), _ = 1;     pr(1 ?  }  :   );   }   template <class T>   void pr(const set<T>& x) {     pr(1 ?  {  :   );     bool _ = 0;     for (const auto& v : x) pr(_ ? 1 ?  ,   :     :   ), pr(v), _ = 1;     pr(1 ?  }  :   );   }   template <class T>   void pr(const multiset<T>& x) {     pr(1 ?  {  :   );     bool _ = 0;     for (const auto& v : x) pr(_ ? 1 ?  ,   :     :   ), pr(v), _ = 1;     pr(1 ?  }  :   );   }   template <class S, class T>   void pr(const map<S, T>& x) {     pr(1 ?  {  :   );     bool _ = 0;     for (const auto& v : x) pr(_ ? 1 ?  ,   :     :   ), pr(v), _ = 1;     pr(1 ?  }  :   );   }   template <class S, class... T>   void pr(const S& a, const T&... b) {     pr(a);     if (sizeof...(b))       pr(   ), pr(b...);     else       pr(  n );   }   }  // namespace output   using namespace output;   const int MN = 5e5 + 5;   long long n, m, i, ds[MN][2], sz[MN], t[MN][2], h[MN][2], lst[MN][2], x, y;   map<long long, long long> psa[MN];   char ch;   long long fnd(long long n, long long p) {     return ds[n][p] == n ? n : fnd(ds[n][p], p);   }   long long ttt(long long n, long long p) {     return ds[n][0] == n ? (lst[n][0] >= p ? lst[n][0] : 0)                          : max(lst[n][0] >= p ? lst[n][0] : 0,                                ttt(ds[n][0], max(t[n][0], p)));   }   long long qu(long long n, long long p) {     if (ds[n][1] == n) {       if (psa[n].empty()) return 0LL;       auto it = psa[n].lower_bound(p);       auto ed = psa[n].end();       ed--;       if (it == psa[n].begin())         return ed->second;       else {         it--;         return ed->second - it->second;       }     } else {       if (psa[n].empty()) return qu(ds[n][1], max(t[n][1], p));       auto it = psa[n].lower_bound(p);       auto ed = psa[n].end();       ed--;       if (it == psa[n].begin())         return ed->second + qu(ds[n][1], max(t[n][1], p));       else {         it--;         return ed->second - it->second + qu(ds[n][1], max(t[n][1], p));       }     }   }   int main() {     scanf( %lld%lld , &n, &m);     for (i = 1; i <= n; i++) {       sz[i] = 1;       ds[i][0] = ds[i][1] = i;     }     for (i = 1; i <= m; i++) {       scanf(  %c%lld , &ch, &x);       if (ch ==  U ) {         scanf( %lld , &y);         x = fnd(x, 1), y = fnd(y, 1);         if (h[x][1] < h[y][1]) swap(x, y);         if (h[x][1] == h[y][1]) h[x][1]++;         sz[x] += sz[y];         ds[y][1] = x;         t[y][1] = i;       } else if (ch ==  M ) {         scanf( %lld , &y);         x = fnd(x, 0), y = fnd(y, 0);         if (h[x][0] < h[y][0]) swap(x, y);         if (h[x][0] == h[y][0]) h[x][0]++;         ds[y][0] = x;         t[y][0] = i;       } else if (ch ==  Q ) {         long long tt = ttt(x, 0);         printf( %lld n , qu(x, tt));       } else if (ch ==  Z ) {         x = fnd(x, 0);         lst[x][0] = i;       } else if (ch ==  A ) {         x = fnd(x, 1);         long long lst = 0;         if (psa[x].size()) {           auto it = psa[x].end();           it--;           lst = it->second;         }         psa[x][i] = lst + sz[x];       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve();   int main() {     srand(time(0));     cout.setf(ios::fixed);     cout.precision(10);     int tn = 1;     for (int i = 0; i < tn; ++i) solve();   }   vector<int> g[100001];   const long long mod = 1000000007;   inline void add(long long &a, long long b) {     a += b;     a %= mod;   }   pair<long long, long long> dfs(int u) {     sort(g[u].begin(), g[u].end());     long long res[2][2][2];     memset(res, 0, sizeof(res));     res[1][0][0] = 1;     for (int i = 0; i < ((int)(g[u]).size()); ++i) {       pair<long long, long long> c = dfs(g[u][i]);       long long even = c.first;       long long odd = c.second;       long long cres[2][2][2];       for (int sum = 0; sum < 2; ++sum)         for (int was_odd = 0; was_odd < 2; ++was_odd)           for (int was_even = 0; was_even < 2; ++was_even)             cres[sum][was_odd][was_even] = res[sum][was_odd][was_even];       for (int sum = 0; sum < 2; ++sum)         for (int was_odd = 0; was_odd < 2; ++was_odd)           for (int was_even = 0; was_even < 2; ++was_even) {             add(res[sum ^ 1][1][was_even], odd * cres[sum][was_odd][was_even]);             add(res[sum][was_odd][1], even * cres[sum][was_odd][was_even]);           }     }     for (int sum = 0; sum < 2; ++sum)       for (int was_odd = 0; was_odd < 2; ++was_odd)         for (int was_even = 0; was_even < 2; ++was_even) {           if ((was_odd && sum == 1) || (was_even && sum == 0))             add(res[sum][was_odd][was_even], res[sum][was_odd][was_even]);         }     long long odd = 0, even = 0;     for (int was_odd = 0; was_odd < 2; ++was_odd)       for (int was_even = 0; was_even < 2; ++was_even) {         add(odd, res[1][was_odd][was_even]);         add(even, res[0][was_odd][was_even]);       }     return make_pair(even, odd);   }   void solve() {     int n;     cin >> n;     for (int i = 0; i < n - 1; ++i) {       int p;       cin >> p;       --p;       g[p].push_back(i + 1);     }     pair<long long, long long> res = dfs(0);     cout << (res.first + res.second) % mod <<   n ;   }


#include <bits/stdc++.h>   #pragma GCC optimize(2)   using namespace std;   namespace IO_Optimization {   inline int read() {     int X = 0, w = 0;     char ch = 0;     while (!isdigit(ch)) {       w |= ch ==  - ;       ch = getchar();     }     while (isdigit(ch)) {       X = (X << 3) + (X << 1) + (ch ^ 48);       ch = getchar();     }     return w ? -X : X;   }   inline void write(long long x) {     if (x < 0) putchar( - ), x = -x;     if (x > 9) write(x / 10);     putchar(x % 10 +  0 );   }   }  // namespace IO_Optimization   using namespace IO_Optimization;   int n, k;   double sum;   struct Node {     int num, pos;   } a[2000 + 2], b[2000 + 2];   struct Trans {     int s[2000 + 2];   } ans[2000 + 2];   int tot1, tot2;   inline bool cmp(Node x, Node y) { return x.num > y.num; }   int main() {     n = read(), k = read();     for (register int i = 1; i <= n; ++i) {       int x = read(), y = read();       if (y == 1)         a[++tot1].num = x, a[tot1].pos = i;       else         b[++tot2].num = x, b[tot2].pos = i;     }     sort(a + 1, a + 1 + tot1, cmp);     int noww = k - 1 < tot1 ? k - 1 : tot1;     for (register int i = 1; i <= noww; ++i) {       ans[i].s[++ans[i].s[0]] = a[i].pos;       sum += a[i].num * 0.5;     }     if (tot1 <= k - 1) {       for (register int i = 1; i <= tot2; ++i) {         int nowww = tot1 + i < k ? tot1 + i : k;         sum += b[i].num;         ans[nowww].s[++ans[nowww].s[0]] = b[i].pos;       }     } else {       int minn = 1e9;       for (register int i = k; i <= tot1; ++i) {         sum += a[i].num;         ans[k].s[++ans[k].s[0]] = a[i].pos;         minn = a[i].num < minn ? a[i].num : minn;       }       for (register int i = 1; i <= tot2; ++i) {         sum += b[i].num;         ans[k].s[++ans[k].s[0]] = b[i].pos;         minn = b[i].num < minn ? b[i].num : minn;       }       sum -= minn * 0.5;     }     printf( %.1lf n , sum);     for (register int i = 1; i <= k; ++i, puts(  )) {       write(ans[i].s[0]);       cout <<    ;       for (register int j = 1; j <= ans[i].s[0]; ++j) {         write(ans[i].s[j]);         cout <<    ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   void solve(istream &cin = std::cin, ostream &cout = std::cout) {     int test;     cin >> test;     int n, m;     ll t;     while (cin >> n >> m >> t) {       vector<int> p(n);       for (int &x : p) cin >> x;       const int bound = *max_element(p.begin(), p.end()) + 1;       auto check = [&](int d) {         if (d == bound) return pair<int, bool>(-1, false);         ll last = 0, sum_t = 0;         int ptr = 0;         bool good = true;         int done = 0;         for (int x : p) {           if (x <= d) {             if (ptr == m) {               sum_t += last;               ptr = 0;               last = 0;             }             {               sum_t += x;               last += x;               ptr++;               if (sum_t > t)                 good = false;               else                 done++;             }           }         }         return pair<int, bool>(done, good);       };       int left = 0, right = bound;       while (right - left > 1) {         int mid = (left + right) / 2;         if (check(mid).second)           left = mid;         else           right = mid;       }       int ans = -1, d = -1;       for (int i = left; i <= right; i++) {         int cur = check(i).first;         if (ans < cur) {           ans = cur;           d = i;         }       }       if (d > t) d = t;       cout << ans <<     << d << endl;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout << fixed;     cout << setprecision(20);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = int(1e9) + 7;   const double eps = 1e-9;   vector<pair<int, int> > g[111];   int dp[111][111][30];   int n, m;   int dfs(int u, int v, int x) {     if (dp[u][v][x]) return dp[u][v][x];     dp[u][v][x] = 2;     for (int i = 0; i < int((g[u]).size()); ++i) {       pair<int, int> to = g[u][i];       if (to.second >= x) {         if (dfs(v, to.first, to.second) == 2) {           dp[u][v][x] = 1;           break;         }       }     }     return dp[u][v][x];   }   int main() {     cin >> n >> m;     for (int i = 1; i <= m; ++i) {       int u, v;       char c;       cin >> u >> v >> c;       g[u].push_back(make_pair(v, c - 97));     }     for (int i = 1; i <= n; i++) {       for (int j = 0; j < 26; j++) {         dp[i][i][j] = 2;       }     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         if (!dp[i][j][0]) {           dfs(i, j, 0);         }         if (dp[i][j][0] == 1)           cout <<  A ;         else           cout <<  B ;       }       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     double n, a, d, t, v;     cin >> n >> a >> d;     double minitime = 0;     for (int i = 0; i < n; i++) {       cin >> t >> v;       double t1 = v / a;       double s = a * 0.5 * t1 * t1;       if (s > d) {         t += sqrt(2 * d / a);       } else {         double x = d - s;         double t2 = x / v;         t += t1 + t2;       }       t = max(minitime, t);       minitime = t;       cout << t << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int dp[5005][5005];   int main() {     long long int n, m, k;     cin >> n >> m >> k;     long long int arr[n + 1];     long long int sum[n + 1];     for (int i = 1; i <= n; i++) cin >> arr[i];     sum[1] = 0;     for (int i = 1; i <= m; i++) sum[1] += arr[i];     for (int i = 2; i <= n - m + 1; i++)       sum[i] = sum[i - 1] + arr[i + m - 1] - arr[i - 1];     long long int res = -1;     for (int i = 1; i <= n - m + 1; i++) dp[1][i] = max(dp[1][i - 1], sum[i]);     for (int i = 2; i <= k; i++) {       for (int j = 1; j <= n - m + 1; j++) {         if (j > m * (i - 1))           dp[i][j] = max(dp[i][j - 1], dp[i - 1][j - m] + sum[j]);       }     }     cout << dp[k][n - m + 1] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     string s;     char big =  a ;     string s1 =   ;     cin >> s;     for (int i = s.size() - 1; i >= 0; i--) {       if (int(s[i]) >= int(big)) {         s1 += s[i];         big = s[i];       }     }     reverse(s1.begin(), s1.end());     cout << s1;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   vector<pair<int, int>> g[51][51];   int ch[51][51], vis[51][51], cnt;   pair<int, int> par[51][51];   bool isValid(int x, int y) {     if (x < 0 || y < 0 || x > n - 1 || y > m - 1) return false;     return true;   }   int dx[] = {-1, 0, 0, 1};   int dy[] = {0, 1, -1, 0};   void dfs(int x, int y, int px, int py) {     vis[x][y] = 1;     par[x][y] = {px, py};     for (auto i = 0; i < 4; i++) {       int curX = x + dx[i], curY = y + dy[i];       if (isValid(curX, curY) && ch[curX][curY] == ch[x][y]) {         if (vis[curX][curY] == 0)           dfs(curX, curY, x, y);         else if (par[x][y].first != curX || par[x][y].second != curY)           cnt++;       }     }   }   void Solve() {     cin >> n >> m;     for (auto i = 0; i < n; i++) {       for (auto j = 0; j < m; j++) {         char c;         cin >> c;         ch[i][j] = c -  A  + 1;       }     }     for (auto i = 0; i < n - 1; i++) {       for (auto j = 0; j < m - 1; j++) {         if (ch[i + 1][j] == ch[i][j])           g[i][j].push_back({i + 1, j}), g[i + 1][j].push_back({i, j});         if (ch[i][j + 1] == ch[i][j + 1])           g[i][j].push_back({i, j + 1}), g[i][j + 1].push_back({i, j});       }     }     for (auto i = 0; i < n; i++) {       for (auto j = 0; j < m; j++) {         if (vis[i][j] == 0) {           cnt = 0;           dfs(i, j, -1, -1);           if (cnt > 0) {             cout <<  Yes ;             return;           }         }       }     }     cout <<  No ;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long int T = 1;     while (T--) Solve();     return 0;   }


#include <bits/stdc++.h>   int main() {     int a, b, ans = 0;     scanf( %d %d , &a, &b);     if (a > b) {       ans = (a - b) / 2;       printf( %d %d , b, ans);     } else if (a < b) {       ans = (b - a) / 2;       printf( %d %d , a, ans);     } else if (a == b) {       ans = (a - b) / 2;       printf( %d %d , b, ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, m1, m2, len, bo, ans, fa[1000005], f[1000000], dep[1000000],       nex[1000000], wen[1000000], hea[1000000], val[1000000], v[1000000];   struct arr {     long long x, y, z, bo;   } a[1000000];   bool cmp(arr x, arr y) { return x.z < y.z; }   void add(long long x, long long y, long long z) {     ++len;     nex[len] = hea[x];     wen[len] = y;     val[len] = z;     hea[x] = len;   }   long long find(long long x) {     if (fa[x] == x) return x;     fa[x] = find(fa[x]);     return fa[x];   }   void dfs(long long x, long long y) {     f[x] = y;     dep[x] = dep[y] + 1;     for (long long i = hea[x]; i; i = nex[i])       if (wen[i] != y) {         v[wen[i]] = val[i];         dfs(wen[i], x);       }   }   signed main() {     scanf( %lld%lld%lld , &n, &m1, &m2);     for (long long i = 1; i <= m1; i++) scanf( %lld%lld , &a[i].x, &a[i].y);     for (long long i = m1 + 1; i <= m1 + m2; i++)       scanf( %lld%lld%lld , &a[i].x, &a[i].y, &a[i].z);     sort(a + 1, a + m1 + m2 + 1, cmp);     for (long long i = 1; i <= n; i++) fa[i] = i;     for (long long i = 1, j = 0; i <= m1 + m2 && j < n - 1; i++) {       long long x = find(a[i].x), y = find(a[i].y);       if (x != y) {         ++j;         a[i].bo = 1;         fa[find(x)] = find(y);         add(a[i].x, a[i].y, a[i].z);         add(a[i].y, a[i].x, a[i].z);       }     }     dfs(1, 0);     for (long long i = 1; i <= n; i++) fa[i] = i;     for (long long i = m1 + 1; i <= m1 + m2; i++)       if (!a[i].bo) {         long long x = find(a[i].x), y = find(a[i].y), z = a[i].z;         while (x != y) {           if (dep[x] < dep[y]) swap(x, y);           if (v[x] == 0) ans += z, ++bo;           fa[x] = find(f[x]);           x = find(x);         }       }     if (bo < m1) ans = -1;     printf( %lld , ans);   }


#include <bits/stdc++.h>   using namespace std;   const int MAXK = 1005, MAXM = 30, MOD = 7340033;   int f[MAXM][MAXK];   void DP() {     static int g[MAXK];     int m, k, i, j;     f[0][0] = 1;     for (m = 1; m < MAXM; m++) {       memset(g, 0, sizeof(g));       g[0] = 1;       for (i = 1; i <= 4; i++)         for (k = MAXK - 1; k >= 0; k--) {           for (j = 1; j <= k; j++)             g[k] = (g[k] + (long long)g[k - j] * f[m - 1][j]) % MOD;         }       f[m][0] = 1;       for (k = 1; k < MAXK; k++) f[m][k] = g[k - 1];     }   }   int GetM(int n) {     int res = 0;     for (; (n & 1) && n > 1; n >>= 1) res++;     return res;   }   int main() {     DP();     int tests, n, m, k;     scanf( %d , &tests);     while (tests--) {       scanf( %d%d , &n, &k);       m = GetM(n);       printf( %d n , f[m][k]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxN = 2000 + 5;   char s[maxN];   int t, n, k;   vector<pair<int, int> > ans;   void Reverse(int l, int r) {     ans.push_back(make_pair(l, r));     for (int i = l; i <= (l + r) / 2; ++i) swap(s[i], s[l + r - i]);   }   int main() {     scanf( %d , &t);     while (t--) {       scanf( %d%d , &n, &k);       scanf( %s , s + 1);       ans.clear();       for (int i = 1; i <= n; ++i) {         if (i % 2 && s[i] ==  ) ) {           int j = i + 1;           while (s[j] ==  ) ) ++j;           Reverse(i, j);         }         if (i % 2 == 0 && s[i] ==  ( ) {           int j = i + 1;           while (s[j] ==  ( ) ++j;           Reverse(i, j);         }       }       if (k < n / 2) {         int pos = (k - 1) * 2 + 1;         ans.push_back(make_pair(pos + 1, n - 1));       }       printf( %d n , ans.size());       for (int i = 0; i != ans.size(); ++i)         printf( %d %d n , ans[i].first, ans[i].second);     }     return 0;   }


#include <bits/stdc++.h>   int main() {     int n, i, z = 0, o = 0;     char str[120];     scanf( %d , &n);     getchar();     gets(str);     for (i = 0; i < n; i++) {       if (str[i] ==  0 ) {         z++;       } else {         o++;       }     }     if (o > 0) {       printf( 1 );     }     for (i = 0; i < z; i++) {       printf( 0 );     }     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, a, b;   vector<pair<int, int> > res;   vector<vector<int> > v;   int cl[100000 * 2 + 5];   bool visited[100000 * 2 + 5];   void dfs(int now, int color) {     if (visited[now]) return;     visited[now] = true;     cl[now] = color + 1;     for (int i = 0; i < v[now].size(); i++) {       dfs(v[now][i], !color);     }   }   int main() {     scanf( %d , &n);     v.resize(n * 2);     for (int i = 0; i < n; i++) {       scanf( %d %d , &a, &b);       a--;       b--;       res.push_back(make_pair(a, b));       v[a].push_back(b);       v[b].push_back(a);     }     for (int i = 0; i < 2 * n; i += 2) {       v[i].push_back((i + 1) % (n * 2));       v[(i + 1) % (n * 2)].push_back(i);     }     for (int i = 0; i < 2 * n; i++) {       if (!visited[i]) {         dfs(i, 0);       }     }     for (int i = 0; i < n; i++) {       printf( %d %d n , cl[res[i].first], cl[res[i].second]);     }   }


#include <bits/stdc++.h>   using namespace std;   string s;   long long int n, k;   long long int L, R;   bool query(long long int l, long long int r) {     l = max(1LL, l);     r = min(n, r);     cout << l <<     << r << endl;     cin >> s;     if (s ==  Bad ) exit(0);     if (s ==  Yes ) {       if (l == r) exit(0);       return true;     }     return false;   }   int main() {     ios_base::sync_with_stdio(0);     srand(time(NULL));     string s;     cin >> n >> k;     L = 1;     R = n;     while (true) {       long long int len = (R - L + 1);       if (len <= 5 * k + 4) {         len = rand() % len;         query(L + len, L + len);         L = max(1LL, L - k);         R = min(n, R + k);       } else {         long long int M = (L + R) / 2;         if (query(L, M)) {           L = L - k;           R = M + k;         } else {           L = M - k;           R = R + k;         }       }       L = max(1LL, L);       R = min(n, R);     }     exit(0);   }


#include <bits/stdc++.h>   using namespace std;   vector<pair<long long, long long> > v;   map<char, bool> mpp;   map<int, int>::iterator it;   set<string> s;   set<pair<int, int> >::iterator iter;   deque<char> d;   long long a[500001];   int main() {     ios::sync_with_stdio(false);     long long n, a, b, c, d, ans = 1, y1, y2, y3, y4;     cin >> n >> a >> b >> c >> d;     if (a >= d) {       y1 = 1;       y2 = a - d + 1;     } else {       y2 = 1;       y1 = d - a + 1;     }     y4 = c + y1 - b;     y3 = y4 + a - d;     if (y1 <= 0) {       y4 += 1 - y1;       y3 += 1 - y1;       y2 += 1 - y1;       y1 += 1 - y1;     }     if (y2 <= 0) {       y4 += 1 - y2;       y3 += 1 - y2;       y1 += 1 - y2;       y2 += 1 - y2;     }     if (y3 <= 0) {       y4 += 1 - y3;       y1 += 1 - y3;       y2 += 1 - y3;       y3 += 1 - y3;     }     if (y4 <= 0) {       y1 += 1 - y4;       y3 += 1 - y4;       y2 += 1 - y4;       y4 += 1 - y4;     }     if (y4 > n || y3 > n || y2 > n || y1 > n) {       cout << 0;       return 0;     }     if (n - max(y1, max(y2, max(y3, y4))) > 0)       ans += n - max(y1, max(y2, max(y3, y4)));     cout << ans * n;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 5;   int dp[maxn], num[30];   int main() {     int i, j, k, n, m, t, l, ans, x, y, z;     char s[maxn];     scanf( %d , &t);     while (t--) {       scanf( %d%d%d , &n, &m, &k);       scanf( %s , s);       ans = 1e9;       memset(num, 0, sizeof(num));       for (i = 0; i < k; i++) {         num[s[i] -  A  + 1]++;       }       for (l = 1; l <= 26; l++) {         if (num[l] == 0) continue;         for (i = 0; i <= k; i++) dp[i] = 0;         dp[0] = 1;         for (i = 1; i <= 26; i++) {           if (num[i] == 0 || i == l) continue;           for (j = k; j >= num[i]; j--)             if (dp[j - num[i]] == 1) dp[j] = 1;         }         for (i = 0; i <= k; i++) {           if (dp[i] == 1) {             if (i + num[l] >= n) {               x = max(0, n - i);               z = k - num[l] - i;               if (z + num[l] - x >= m) {                 y = max(0, m - z);                 ans = min(ans, x * y);               }             }           }         }       }       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 10;   const int INF = 0x3f3f3f3f;   const double eps = 1e-9;   const int mod = 1e9 + 7;   int dp[N];   int main() {     dp[0] = 1;     int num;     while (scanf( %d , &num) != EOF) {       bool flag = 0;       if (num == 1) {         printf( 1 1 n );         printf( 1 n );         return 0;       }       int ans, cnt;       for (int i = 1; i <= 2; i++) {         for (int j = 0; j < N; j++) {           if (j >= i) {             dp[j] += dp[j - i];           }           if (dp[j] == num) {             ans = j;             cnt = i;             flag = 1;             break;           }         }         if (flag) {           printf( %d %d n , ans, cnt);           if (cnt == 1)             printf( 1 n );           else             printf( 1 2 n );           break;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-9;   const int mod = (int)1e+9 + 7;   const double pi = acos(-1.);   const int maxn = 1000100;   long long a[maxn];   int main() {     {       srand(time(0));       const string file =   ;       if (!file.empty()) {         freopen((file +  .in ).c_str(),  r , stdin);         freopen((file +  .out ).c_str(),  w , stdout);       }     }     int n;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %lld , &a[i]);     }     long long ans = 0, pref = 0;     for (int i = 0; i < n; i++) {       ans += pref * (min(a[i], i ? a[i - 1] : mod) - 1) + a[i] - 1;       ans %= mod;       long long h = min(i ? a[i - 1] : mod, i + 1 == n ? mod : a[i + 1]);       h = min(h, a[i]);       h--;       pref *= h;       pref += min(a[i], i + 1 < n ? a[i + 1] : mod) - 1;       pref %= mod;     }     printf( %lld , ans);     return (0);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long a1, a2, a3, a4, c = 0;     cin >> a1 >> a2 >> a3 >> a4;     string s;     cin >> s;     for (int i = 0; i < s.size(); i++) {       if (s[i] ==  1 )         c += a1;       else if (s[i] ==  2 )         c += a2;       else if (s[i] ==  3 )         c += a3;       else if (s[i] ==  4 )         c += a4;     }     cout << c;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   class Edge {    public:     int neighbour;     int edge_number;     int weight;     Edge(int neigh, int edge_no, int weig) {       neighbour = neigh;       edge_number = edge_no;       weight = weig;     }   };   int main() {     int n, m;     cin >> n >> m;     vector<vector<Edge> > adj_list(n + 1);     for (int i = 1; i <= m; i++) {       int vertex1, vertex2, weight;       cin >> vertex1 >> vertex2 >> weight;       Edge temp = Edge(vertex2, i, weight);       adj_list[vertex1].push_back(temp);       temp = Edge(vertex1, i, weight);       adj_list[vertex2].push_back(temp);     }     int source;     cin >> source;     vector<bool> check_list(n + 1, false);     priority_queue<pair<long long int, int> > pq;     vector<pair<int, int> > parent(n + 1, make_pair(0, 0));     for (int i = 1; i <= n; i++) {       if (i != source)         pq.push(make_pair(LLONG_MIN, i));       else         pq.push(make_pair(0, i));     }     vector<pair<long long int, int> > dist(n + 1, make_pair(LLONG_MAX, 0));     dist[source].first = 0;     while (!pq.empty()) {       int vertex = pq.top().second;       pq.pop();       if (check_list[vertex] == false) {         check_list[vertex] = true;         for (int i = 0; i < adj_list[vertex].size(); i++) {           if (dist[adj_list[vertex][i].neighbour].first >               dist[vertex].first + adj_list[vertex][i].weight) {             parent[adj_list[vertex][i].neighbour].first =                 adj_list[vertex][i].edge_number;             parent[adj_list[vertex][i].neighbour].second =                 adj_list[vertex][i].weight;             dist[adj_list[vertex][i].neighbour].first =                 dist[vertex].first + adj_list[vertex][i].weight;             dist[adj_list[vertex][i].neighbour].second =                 adj_list[vertex][i].weight;             pq.push(make_pair((-1) * (dist[adj_list[vertex][i].neighbour].first),                               adj_list[vertex][i].neighbour));           } else if (dist[adj_list[vertex][i].neighbour].first ==                      dist[vertex].first + adj_list[vertex][i].weight) {             if (dist[adj_list[vertex][i].neighbour].second >                 adj_list[vertex][i].weight) {               parent[adj_list[vertex][i].neighbour].first =                   adj_list[vertex][i].edge_number;               parent[adj_list[vertex][i].neighbour].second =                   adj_list[vertex][i].weight;               dist[adj_list[vertex][i].neighbour].second =                   adj_list[vertex][i].weight;             }           }         }       }     }     long long int ans = 0;     for (int i = 1; i <= n; i++) {       ans += parent[i].second;     }     cout << ans << endl;     for (int i = 1; i <= n; i++) {       if (source != i) cout << parent[i].first <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   long long dp[55][55];   int main() {     int n, m, t;     cin >> n >> m >> t;     dp[0][0] = 1;     for (int i = 1; i <= 31; ++i)       for (int j = 1; j <= 31; ++j) dp[i][j] = dp[i - 1][j - 1] + dp[i - 1][j];     long long sol = 0;     for (int i = 4; i <= n; ++i)       for (int j = 1; j <= m; ++j)         if (i + j == t) {           sol = sol + dp[n + 1][i + 1] * dp[m + 1][j + 1];         }     cout << sol <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int dp[81][81][81][81];   vector<pair<int, int>> graph[81];   int solve(int v, int l, int r, int k) {     if (k == 0) return 0;     if (dp[v][l][r][k] != -1) return dp[v][l][r][k];     int &ret = dp[v][l][r][k];     ret = 1000000;     for (auto e : graph[v]) {       int w = e.second;       int u = e.first;       if (u < r && u > v) {         ret = min(ret, solve(u, v, r, k - 1) + w);       }       if (u > l && u < v) {         ret = min(ret, solve(u, l, v, k - 1) + w);       }     }     return ret;   }   int main() {     int n, k;     scanf( %d %d , &n, &k);     int m;     scanf( %d , &m);     for (int i = 0; i < m; i++) {       int a, b, c;       scanf( %d %d %d , &a, &b, &c);       graph[a].push_back({b, c});     }     int ans = 1000000;     memset(dp, -1, sizeof dp);     for (int i = 1; i <= n; i++) {       ans = min(ans, solve(i, 0, n + 1, k - 1));     }     printf( %d n , ans >= 1000000 ? -1 : ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     char s1[1000], s2[1000], s3[1000];     int i, l1, l2, l3;     scanf( %s%s%s , s1, s2, s3);     l1 = strlen(s1);     l2 = strlen(s2);     l3 = strlen(s3);     strcat(s1, s2);     sort(s1, s1 + l1 + l2);     sort(s3, s3 + l3);     if (l1 + l2 == l3) {       for (i = 0; i <= (l1 + l2); i++) {         if (s1[i] != s3[i]) {           printf( NO n );           break;         } else if (i == l1 + l2) {           printf( YES n );         }       }     } else {       printf( NO n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string a, b;     cin >> a >> b;     if (a == b)       cout << a;     else       cout << 1;     return 0;   }


//   #include <bits/stdc++.h>   using namespace std;      #define fi first   #define se second   #define all(x) x.begin(), x.end()   #define lch (o << 1)   #define rch (o << 1 | 1)      typedef double db;   typedef long long ll;   typedef unsigned int ui;   typedef pair<int, int> pint;   typedef tuple<int, int, int> tint;      const int N = 1e5 + 5;   const int INF = 0x3f3f3f3f;   const ll INF_LL = 0x3f3f3f3f3f3f3f3f;      int a[N];   int mxsuf[N];      int main() {    ios::sync_with_stdio(0);       int n;    cin >> n;    for (int i = 1; i <= n; i++)     cin >> a[i];       vector<int> vec;    int pre = 1;    for (int i = 2; i < n; i++) {     int sgn1 = a[i] - a[i - 1];     sgn1 /= abs(sgn1);     int sgn2 = a[i + 1] - a[i];     sgn2 /= abs(sgn2);     if (sgn1 * sgn2 == -1) {      vec.push_back(i - pre + 1);      pre = i;     }    }    vec.push_back(n - pre + 1);       int m = vec.size();    for (int i = m - 1; i >= 0; i--)     mxsuf[i] = max(mxsuf[i + 1], vec[i]);       int dir = a[2] - a[1];    dir /= abs(dir);    int ans = 0;    int mxpre = 0;    for (int i = 0; i < m; i++) {     if (i - 2 >= 0)      mxpre = max(mxpre, vec[i - 2]);     if (dir == -1 && i > 0) {      int mx = max(vec[i - 1], vec[i]);      int mn = min(vec[i - 1], vec[i]);      bool flag = (mxpre >= mx);      if (i + 1 < m)       flag |= mxsuf[i + 1] >= mx;      flag |= (mn % 2 == 0);      flag |= (mn % 2 == 1) && (mn < mx);      ans += !flag;     }     dir *= -1;    }       cout << ans << endl;       return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 700 + 5;   int n, m, d[N], cnt[N][N];   bitset<N> adj[N];   long long ans;   int main() {     scanf( %d%d , &n, &m);     for (int i = 0, u, v; i < m; i++) {       scanf( %d%d , &u, &v);       d[--u]++, d[--v]++;       adj[u][v] = adj[v][u] = true;     }     for (int u = 0; u < n; u++)       for (int v = u; v < n; v++)         cnt[u][v] = cnt[v][u] = (adj[u] & adj[v]).count();     for (int u = 0; u < n; u++)       for (int v = 0; v < n; v++)         if (adj[u][v]) {           for (int x = 0; x < n; x++)             ans += 1LL * (u ^ x && v ^ x) * (cnt[u][x] - adj[x][v]) *                    (cnt[v][x] - adj[x][u]);           ans -= cnt[u][v] * (d[u] - 2);         }     printf( %lld n , ans / 10);   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1000000007;   struct Sync_stdio {     Sync_stdio() {       cin.tie(NULL);       ios_base::sync_with_stdio(false);     }   } _sync_stdio;   struct FAIL {     FAIL() {       cout <<  CHANGE!!!             <<   n ;     }   };   string go(int iter, long long a, long long b, long long x) {     string res;     vector<int> used(26);     for (int l = (0); l < (iter); ++l) {       int j = 0;       for (int i = (0); i < (a); ++i) {         while (used[j]) {           ++j;         }         res +=  a  + j;         ++j;       }       char sym = res[res.size() - x];       for (int i = (0); i < (b); ++i) {         res += sym;       }       for (int i = (0); i < (26); ++i) {         used[i] = 0;       }       for (int i = (0); i < (a); ++i) {         used[res[res.size() - 1 - i] -  a ] = 1;       }     }     return res;   }   int solve(int a, int b, int l, int r, int x) {     string s1 = go(10, a, b, x + 1);     set<char> ss;     for (int i = (l); i < (r + 1); ++i) {       ss.insert(s1[i]);     }     return ss.size();   }   int main() {     long long a, b, l, r;     cin >> a >> b >> l >> r;     --l, --r;     long long start = l / (a + b);     long long end = r / (a + b);     if (r - l > 6 * (a + b)) {       cout << max(a + 1LL, a + a - b) <<   n ;       return 0;     }     l -= start * (a + b);     r -= start * (a + b);     int res = INT_MAX;     for (int i = (0); i < (a); ++i) {       res = min(res, solve(a, b, l, r, i));     }     cout << res;   }


// Author: HarshKumar      #include <bits/stdc++.h>   using namespace std;   #define ll int64_t   const ll N = 1e6 + 6, M = 1e9 + 7;   int main()   {       ios::sync_with_stdio(false), cin.tie(nullptr);       ll n, k;       cin >> n >> k;       ll x = min(k * k + 1, n);       string s(x,  a );       map<char, ll> f;       for (ll i = 0; i < k; i++)           f[ a  + i] = i;       for (ll i = 1; i < x; i++)           s[i] =  a  + f[s[i - 1]] % k, f[s[i - 1]]++;       s.erase(s.begin());       cout <<  a ;       n--;       x--;       for (ll i = 0; i < n; i++)           cout << s[i % x];   }


#include <bits/stdc++.h>   using namespace std;   long long inf = std::numeric_limits<long long>::max();   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long T;     cin >> T;     while (T--) {       long long n, i;       cin >> n;       string str;       cin.ignore();       cin >> str;       long long len = str.length();       long long count = 0;       for (i = 0; i < len; i++) {         string y =   ;         y += str[i];         long long num = stoi(y);         if (num > 0) {           count += (num);         }         if (i != (n - 1) && num > 0) {           count++;         }       }       cout << count <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char s[10];   int f[2001], c[2001], mtr[2001][2001], n, m, q, x, y;   int main() {     scanf( %d%d%d , &n, &m, &q);     for (int i = 1; i <= n; i++) {       f[i] = i;       for (int j = 1; j <= m; j++) {         scanf( %d , &mtr[i][j]);         c[j] = j;       }     }     while (q--) {       scanf( %s%d%d , s, &x, &y);       if (s[0] ==  c )         swap(c[x], c[y]);       else if (s[0] ==  r )         swap(f[x], f[y]);       else         printf( %d n , mtr[f[x]][c[y]]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 10;   char s[maxn];   struct Node {     int sum, pmx, lmx, mi, ma, d;     Node() {}     Node(int a, int b, int c, int d, int e, int f) {       sum = a;       pmx = b;       lmx = c;       mi = d;       ma = e;       d = f;     }   };   Node segT[maxn << 2];   void maintain(int curPos) {     segT[curPos].sum = segT[curPos << 1].sum + segT[curPos << 1 | 1].sum;     segT[curPos].pmx =         max(segT[curPos << 1].pmx,             max(segT[curPos << 1 | 1].ma - 2 * segT[curPos << 1].mi +                     segT[curPos << 1].sum,                 segT[curPos << 1 | 1].pmx - segT[curPos << 1].sum));     segT[curPos].lmx =         max(segT[curPos << 1].lmx,             max(segT[curPos << 1 | 1].lmx - segT[curPos << 1].sum,                 segT[curPos << 1].ma - 2 * segT[curPos << 1 | 1].mi -                     2 * segT[curPos << 1].sum));     segT[curPos].mi = min(segT[curPos << 1].mi,                           segT[curPos << 1 | 1].mi + segT[curPos << 1].sum);     segT[curPos].ma = max(segT[curPos << 1].ma,                           segT[curPos << 1 | 1].ma + segT[curPos << 1].sum);     segT[curPos].d = max(max(segT[curPos << 1].d, segT[curPos << 1 | 1].d),                          max(segT[curPos << 1].ma + segT[curPos << 1 | 1].pmx -                                  segT[curPos << 1].sum,                              segT[curPos << 1].lmx + segT[curPos << 1].sum +                                  segT[curPos << 1 | 1].ma));   }   void build(int curPos, int curL, int curR) {     if (curL == curR) {       curR = s[curL] ==  (  ? 1 : -1;       segT[curPos] = Node(curR, -curR, -curR, curR, curR, 0);       return;     }     int mid = curL + curR >> 1;     build(curPos << 1, curL, mid);     build(curPos << 1 | 1, mid + 1, curR);     maintain(curPos);   }   void update(int pos, int curPos, int curL, int curR) {     if (curL == curR) return build(curPos, curL, curR);     int mid = curL + curR >> 1;     if (pos <= mid)       update(pos, curPos << 1, curL, mid);     else       update(pos, curPos << 1 | 1, mid + 1, curR);     maintain(curPos);   }   int main() {     int n, m;     scanf( %d%d , &n, &m);     scanf( %s , s + 1);     n = n * 2 - 2;     build(1, 1, n);     printf( %d n , segT[1].d);     while (m--) {       int x, y;       scanf( %d%d , &x, &y);       swap(s[x], s[y]);       update(x, 1, 1, n);       update(y, 1, 1, n);       printf( %d n , segT[1].d);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long mo(long long a) { return a % (long long)(1e9 + 7); }   long long po(long long x, long long y, long long p) {     long long res = 1;     x = x % p;     while (y > 0) {       if (y & 1) res = (res * x) % p;       y >>= 1;       x = (x * x) % p;     }     return res % p;   }   vector<long long> a;   long long solve(long long last_bit, vector<long long> &cur) {     if (last_bit < 0) return 0;     long long n = cur.size();     vector<long long> ze, one;     for (long long i = 0; i < n; i++) {       if ((1LL << last_bit) & cur[i])         one.push_back(cur[i]);       else         ze.push_back(cur[i]);     }     if (ze.size() == 0 || one.size() == 0)       return solve(last_bit - 1, cur);     else       return 1 + max(solve(last_bit - 1, ze), solve(last_bit - 1, one));   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long n;     cin >> n;     a.resize(n);     for (long long i = 0; i < a.size(); i++) cin >> a[i];     ;     long long ans = solve(30, a);     cout << n - ans - 1 <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b;     cin >> a >> b;     int p;     string s[100];     string s1, s2, s3 =   , s4 =   , s5 =   , s6, s7, s8, s9;     for (int i = 0; i < a; i++) {       int p = 0;       cin >> s[i];       s6 = s[i];       reverse(s6.begin(), s6.end());       if (s[i] == s6) {         s7 = s[i];       }     }     for (int i = 0; i < a - 1; i++) {       s2 = s[i];       reverse(s[i].begin(), s[i].end());       for (int j = i + 1; j < a; j++) {         if (s[i] == s[j]) {           s3 = s3 + s2;           s8 = s[j];           s4 = s8 + s4;         }       }     }     s9 = s3 + s7 + s4;     cout << s9.size() << endl;     int l = s9.size();     if (l != 0) {       cout << s3 + s7 + s4 << endl;     }   }


#include <bits/stdc++.h>   int n, m, q;   char str[1005];   bool a[1005][1005];   std::vector<std::pair<int, int> > del;   int num[1005][1005], tot, ld, ru;   std::set<std::pair<int, int> > s;   namespace FU {   int f[1005 * 1005];   std::vector<int> inv[1005 * 1005];   std::set<int> su;   void init(int i) {     if (su.count(i)) return;     su.insert(i);     f[i] = i;     inv[i].push_back(i);   }   void mrg(int u, int v) {     init(u);     init(v);     u = f[u];     v = f[v];     if (u == v) return;     for (int i = 0; i < inv[u].size(); i++) {       f[inv[u][i]] = v;       inv[v].push_back(inv[u][i]);     }     inv[u].clear();   }   bool cnn(int u, int v) {     init(u);     init(v);     return f[u] == f[v];   }   void cl() {     for (std::set<int>::iterator i = su.begin(); i != su.end(); i++) {       f[*i] = 0;       inv[*i].clear();     }     su.clear();   }   }  // namespace FU   using namespace FU;   inline void dfs(int x, int y, int id) {     num[x][y] = id;     for (int i = x - 1; i <= x + 1; i++)       for (int j = y - 1; j <= y + 1; j++)         if (a[i][j] && !num[i][j]) dfs(i, j, id);   }   inline void R1(int x, int y) {     for (int i = x - 1; i <= x + 1; i++)       for (int j = y - 1; j <= y + 1; j++)         if (0 <= i && i <= n + 1 && 0 <= j && j <= m + 1 && num[i][j])           mrg(num[x][y], num[i][j]);   }   inline void R2(int x, int y) {     for (int i = x - 2; i <= x + 2; i++)       for (int j = y - 2; j <= y + 2; j++)         if (0 <= i && i <= n + 1 && 0 <= j && j <= m + 1 && num[i][j] &&             num[x][y] != num[i][j])           s.insert(std::make_pair(num[x][y], num[i][j]));   }   inline bool chk(int x, int y) {     for (int i = x - 2; i <= x + 2; i++)       for (int j = y - 2; j <= y + 2; j++)         if (0 <= i && i <= n + 1 && 0 <= j && j <= m + 1 && num[i][j])           if ((cnn(num[x][y], ld) && cnn(num[i][j], ru)) ||               (cnn(num[x][y], ru) && cnn(num[i][j], ld)))             return 1;     return 0;   }   int main() {     scanf( %d%d%d , &n, &m, &q);     for (int i = 3; i <= n + 1; i++) a[i][0] = 1;     for (int i = 1; i <= n - 2; i++) a[i][m + 1] = 1;     for (int i = 3; i <= m + 1; i++) a[0][i] = 1;     for (int i = 1; i <= m - 2; i++) a[n + 1][i] = 1;     for (int i = 1; i <= n; i++) {       scanf( %s , str + 1);       for (int j = 1; j <= m; j++) a[i][j] = str[j] ==  # ;     }     for (int i = 0; i <= n + 1; i++)       for (int j = 0; j <= m + 1; j++)         if (a[i][j] && !num[i][j]) dfs(i, j, ++tot);     for (int i = 0; i <= n + 1; i++)       for (int j = 0; j <= m + 1; j++)         if (num[i][j]) R2(i, j);     ld = num[3][0];     ru = num[0][3];     while (q--) {       cl();       init(ld);       init(ru);       del.clear();       int k;       scanf( %d , &k);       int lst = tot;       bool flg = 1;       for (int i = 1; i <= k; i++) {         int x, y;         scanf( %d%d , &x, &y);         num[x][y] = ++tot;         R1(x, y);         del.push_back(std::make_pair(x, y));       }       for (std::set<int>::iterator i = su.begin(); i != su.end(); i++)         for (std::set<int>::iterator j = su.begin(); j != su.end(); j++)           if (cnn(*i, ld) && cnn(*j, ru) &&               (s.count(std::make_pair(*i, *j)) ||                s.count(std::make_pair(*j, *i))))             flg = 0;       for (std::vector<std::pair<int, int> >::iterator it = del.begin();            it != del.end(); it++)         if (chk(it->first, it->second)) flg = 0;       puts(flg ?  YES  :  NO );       fflush(stdout);       for (std::vector<std::pair<int, int> >::iterator it = del.begin();            it != del.end(); it++)         num[it->first][it->second] = 0;       tot -= k;     }   }


#include <bits/stdc++.h>   const int MAXN = 100010;   int flag[MAXN << 2];   int a[MAXN << 2];   int add;   int N, Q;   void PushDown(int rt) {     int lc = rt << 1;     int rc = rt << 1 | 1;     if (flag[rt]) {       flag[lc] += flag[rt];       flag[rc] += flag[rt];       flag[rt] = 0;     }     return;   }   void build(int l, int r, int rt) {     flag[rt] = 0;     if (l == r) {       scanf( %d , &a[rt]);       return;     }     int m = (l + r) >> 1;     build(l, m, rt << 1);     build(m + 1, r, rt << 1 | 1);     return;   }   void Update(int x, int c, int l, int r, int rt) {     if (l == x && r == x) {       flag[rt] = 0;       a[rt] = c;       return;     }     PushDown(rt);     int m = (l + r) >> 1;     if (x <= m)       Update(x, c, l, m, rt << 1);     else       Update(x, c, m + 1, r, rt << 1 | 1);     return;   }   int Query(int x, int l, int r, int rt) {     if (l == x && r == x) {       return a[rt] + flag[rt];     }     PushDown(rt);     int m = (l + r) >> 1;     if (x <= m)       return Query(x, l, m, rt << 1);     else       return Query(x, m + 1, r, rt << 1 | 1);   }   int main() {     while (~scanf( %d%d , &N, &Q)) {       build(1, N, 1);       while (Q--) {         int op, v, x;         scanf( %d , &op);         switch (op) {           case 1:             scanf( %d%d , &v, &x);             Update(v, x, 1, N, 1);             break;           case 2:             scanf( %d , &v);             flag[1] += v;             break;           case 3:             scanf( %d , &v);             printf( %d n , Query(v, 1, N, 1));             break;         }       }     }     return 0;   }


#include <bits/stdc++.h>   int a[100001], b[100000], map[100000], c[634][100001];   int main() {     int n, q;     std::cin >> n >> q;     for (int i = 1; i <= n; ++i) std::cin >> a[i];     memcpy(b, &a[1], sizeof(b));     std::stable_sort(b, b + n);     int N = 0, i = 0;     while (i < n) {       int r = std::upper_bound(b, b + n, b[i]) - b;       if (r - i >= b[i]) map[N++] = b[i];       i = r;     }     for (int i = 0; i < N; ++i)       for (int j = 1; j <= n; ++j) c[i][j] = c[i][j - 1] + (a[j] == map[i]);     while (q--) {       int l, r, count = 0;       std::cin >> l >> r;       for (int i = 0; i < N; ++i) count += map[i] == c[i][r] - c[i][l - 1];       std::cout << count <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e5 + 10, Mod = 1e9 + 7;   long long fact[2 * MAXN], dp[MAXN], ps[MAXN], inv[MAXN * 2];   pair<long long, long long> a[MAXN];   long long power(long long x, long long y) {     if (!y) return 1;     long long ans = power(x, y / 2);     ans *= ans;     ans %= Mod;     if (y % 2) ans *= x;     ans %= Mod;     return ans;   }   long long c(int n, int r) {     long long ans = fact[n];     ans *= inv[r];     ans %= Mod;     ans *= inv[n - r];     ans %= Mod;     return ans;   }   int main() {     fact[0] = 1;     inv[0] = 1;     for (int i = 1; i < 2 * MAXN; i++) {       fact[i] = (fact[i - 1] * i) % Mod;       inv[i] = power(fact[i], Mod - 2);     }     int w, h, n;     cin >> w >> h >> n;     for (int i = 1; i <= n; i++) cin >> a[i].first >> a[i].second;     n++;     a[n].first = w;     a[n].second = h;     sort(a + 1, a + 1 + n);     for (int i = 1; i <= n; i++) {       dp[i] = c(a[i].first + a[i].second - 2, a[i].first - 1);       dp[i] %= Mod;       for (int j = 1; j < i; j++)         if (a[j].first <= a[i].first and a[j].second <= a[i].second) {           dp[i] -= dp[j] * c(a[i].first - a[j].first + a[i].second - a[j].second,                              a[i].first - a[j].first);           dp[i] %= Mod;           dp[i] += Mod;           dp[i] %= Mod;         }     }     cout << dp[n] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   double p[21], dp[(1 << 21)], ans[21];   int n, k;   int main() {     scanf( %d %d , &n, &k);     for (int i = 0; i < n; i++) scanf( %lf , p + i);     dp[0] = 1;     for (int bit = 1; bit < (1 << n); bit++)       if (__builtin_popcount(bit) <= k) {         double rp = 1;         for (int i = 0; i < n; i++)           if ((bit & (1 << i))) rp -= p[i];         for (int i = 0; i < n; i++)           if ((bit & (1 << i))) {             if (p[i] < 1e-9) continue;             dp[bit] += dp[bit ^ (1 << i)] * p[i] / (rp + p[i]);             ans[i] += dp[bit ^ (1 << i)] * p[i] / (rp + p[i]);           }       }     for (int i = 0; i < n; i++) printf( %.11lf  , ans[i]);   }


#include <bits/stdc++.h>   const int N = 100, M = 1000;   int n, m;   double dp[N + 2][N * M + 2];   int main() {     scanf( %d %d , &n, &m);     if (m == 1) {       printf( 1.0 );       return 0;     }     dp[0][0] = m - 1;     int sumr = 0;     for (int i = 1; i <= n; i++) {       int rank;       scanf( %d , &rank);       sumr += rank;       double sum = 0.0;       for (int j = 1; j <= n * m; j++) {         sum += dp[i - 1][j - 1];         if (j > m) sum -= dp[i - 1][j - m - 1];         if (j >= rank)           dp[i][j] = (sum - dp[i - 1][j - rank]) / (m - 1);         else           dp[i][j] = sum / (m - 1);       }     }     double ans = 1.0;     for (int i = 1; i < sumr; i++) ans += dp[n][i];     printf( %.10lf , ans);     return 0;   }


#include <bits/stdc++.h>   int Set(int N, int pos) { return N = N | (1 << pos); }   int reSet(int N, int pos) { return N = N & ~(1 << pos); }   bool check(int N, int pos) { return (bool)(N & (1 << pos)); }   using namespace std;   string s;   int n;   bool dp[10010][4], taken[10010][4];   bool isSafe(int pos, int l1) {     if (pos - l1 < 0) return true;     for (int i = 0; i < l1; i++) {       if (s[pos + i] != s[pos - l1 + i]) return true;     }     return false;   }   bool go(int pos, int pre) {     if (pos > n) return false;     if (pos == n) return dp[pos][pre] = true;     if (taken[pos][pre]) return dp[pos][pre];     taken[pos][pre] = true;     bool ret = false;     if (pre == 3) {       ret |= go(pos + 2, 2);       if (isSafe(pos, 3)) ret |= go(pos + 3, 3);     }     if (pre == 2) {       ret |= go(pos + 3, 3);       if (isSafe(pos, 2)) ret |= go(pos + 2, 2);     }     if (pre == 1) {       ret |= go(pos + 1, 1);       ret |= go(pos + 2, 2);       ret |= go(pos + 3, 3);     }     return dp[pos][pre] = ret;   }   set<string> S;   void get_solution(int pos, int pre) {     if (pos > n || taken[pos][pre]) return;     taken[pos][pre] = true;     string res;     if (pre == 1) {       if (dp[pos + 1][1]) get_solution(pos + 1, 1);       if (dp[pos + 2][2]) {         res = s.substr(pos, 2);         S.insert(res);         get_solution(pos + 2, 2);       }       if (dp[pos + 3][3]) {         res = s.substr(pos, 3);         S.insert(res);         get_solution(pos + 3, 3);       }     }     if (pre == 2) {       if (dp[pos + 2][2]) {         res = s.substr(pos, 2);         S.insert(res);         get_solution(pos + 2, 2);       }       if (dp[pos + 3][3]) {         res = s.substr(pos, 3);         S.insert(res);         get_solution(pos + 3, 3);       }     }     if (pre == 3) {       if (dp[pos + 2][2]) {         res = s.substr(pos, 2);         S.insert(res);         get_solution(pos + 2, 2);       }       if (dp[pos + 3][3]) {         res = s.substr(pos, 3);         S.insert(res);         get_solution(pos + 3, 3);       }     }   }   int main() {     int tc, t = 1;     while (cin >> s) {       n = s.size();       memset(taken, false, sizeof taken);       if (go(5, 1)) {         memset(taken, false, sizeof taken);         get_solution(5, 1);       }       for (int i = 0; i < n + 1; i++) {         for (int j = 1; j < 4; j++) {         }       }       set<string>::iterator it;       cout << S.size() << endl;       for (it = S.begin(); it != S.end(); it++) {         cout << *it << endl;       }       S.clear();     }     return 0;   }