#include <bits/stdc++.h> n using namespace std; n const int N = 4e5 + 50; n int n, m, a[N], b[N]; n vector<int> G[N]; n int in[N], out[N], tim, dep[N]; n int mn[20][N], lg[N], p[N], k; n void dfs(int u, int f) { n   dep[u] = dep[f] + 1; n   in[u] = ++tim; n   mn[0][p[u] = ++k] = u; n   for (int v : G[u]) n     if (v != f) dfs(v, u), mn[0][++k] = u; n   out[u] = tim; n } n int chk(int x, int y) { return dep[x] < dep[y] ? x : y; } n int LCA(int x, int y) { n   x = p[x], y = p[y]; n   if (x > y) swap(x, y); n   int z = lg[y - x + 1]; n   return chk(mn[z][x], mn[z][y - (1 << z) + 1]); n } n int D(int x, int y) { return dep[x] + dep[y] - 2 * dep[LCA(x, y)]; } n struct lll { n   int x, y, o; n   lll(int _x = 0, int _y = 0, int _o = 0) { x = _x, y = _y, o = _o; } n   friend lll operator+(const lll &a, const lll &b) { n     if (!a.o) return a; n     if (!b.o) return b; n     if (!a.x) return b; n     if (!b.x) return a; n     lll t = b; n     int A = D(a.x, t.x), B = D(a.x, t.y), C = D(t.x, t.y); n     if (A + B == C) n       t = lll(t.x, t.y, 1); n     else if (B + C == A) n       t = lll(a.x, t.x, 1); n     else if (A + C == B) n       t = lll(a.x, t.y, 1); n     else n       return lll(0, 0, 0); n     A = D(a.y, t.x), B = D(a.y, t.y), C = D(t.x, t.y); n     if (A + B == C) n       t = lll(t.x, t.y, 1); n     else if (B + C == A) n       t = lll(a.y, t.x, 1); n     else if (A + C == B) n       t = lll(a.y, t.y, 1); n     else n       return lll(0, 0, 0); n     return t; n   } n }; n namespace SGT { n const int N = ::N << 2; n lll t[N]; n void up(int x) { t[x] = t[x << 1] + t[x << 1 | 1]; } n void build(int x, int l, int r) { n   if (l == r) return t[x] = lll(b[l], b[l], 1), void(); n   build(x << 1, l, ((l + r) >> 1)), build(x << 1 | 1, ((l + r) >> 1) + 1, r); n   up(x); n } n void mdf(int x, int l, int r, int p, int v) { n   if (l == r) return t[x] = lll(v, v, 1), void(); n   if (p <= ((l + r) >> 1)) n     mdf(x << 1, l, ((l + r) >> 1), p, v); n   else n     mdf(x << 1 | 1, ((l + r) >> 1) + 1, r, p, v); n   up(x); n } n int ask(int x, int l, int r, lll z) { n   if (l == r) { n     lll y = z + t[x]; n     if (y.o) return l + 1; n     return l; n   } n   lll y = z + t[x << 1]; n   if (!y.o) return ask(x << 1, l, ((l + r) >> 1), z); n   return ask(x << 1 | 1, ((l + r) >> 1) + 1, r, y); n } n }  // namespace SGT n int main() { n   cin >> n; n   for (int i = 1; i <= n; i++) scanf( %d , &a[i]), b[a[i]] = i; n   for (int i = 2, x; i <= n; i++) scanf( %d , &x), G[x].push_back(i); n   dfs(1, 0); n   for (int i = 2; i <= k; i++) lg[i] = lg[i >> 1] + 1; n   for (int i = 1; (1 << i) <= k; i++) n     for (int j = 1; j + (1 << i) - 1 <= k; j++) n       mn[i][j] = chk(mn[i - 1][j], mn[i - 1][j + (1 << i - 1)]); n   SGT ::build(1, 0, n - 1); n   cin >> m; n   while (m--) { n     int o, x, y; n     scanf( %d , &o); n     if (o == 1) { n       scanf( %d%d , &x, &y); n       swap(a[x], a[y]); n       x = a[x], y = a[y]; n       swap(b[x], b[y]); n       SGT ::mdf(1, 0, n - 1, x, b[x]); n       SGT ::mdf(1, 0, n - 1, y, b[y]); n     } n     if (o == 2) cout << SGT ::ask(1, 0, n - 1, lll(0, 0, 1)) <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int n, k; n   cin >> n >> k; n   char def =  a ; n   int pos = 0; n   string ans =   ; n   for (int i = 0; i < n; i++) { n     ans += def + pos; n     pos = (pos + 1) % k; n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long mod = 1000000007LL; n long long base = 10000007; n long long large = 1000000000000000000LL; n class UnionFind { n  private: n   vector<int> p, rank; n  n  public: n   UnionFind(int n) { n     rank.assign(n, 0); n     p.assign(n, 0); n     for (int i = 0; i < n; i++) { n       p[i] = i; n     } n   } n   int findSet(int i) { return (p[i] == i) ? i : (p[i] = findSet(p[i])); } n   bool isSameSet(int i, int j) { return findSet(i) == findSet(j); } n   void unionSet(int i, int j) { n     if (!isSameSet(i, j)) { n       int x = findSet(i), y = findSet(j); n       if (rank[x] > rank[y]) { n         p[y] = x; n       } else { n         p[x] = y; n         if (rank[x] == rank[y]) { n           rank[y]++; n         } n       } n     } n   } n }; n vector<vector<pair<int, int> > > adj; n int n, m; n vector<pair<pair<int, int>, int> > e; n vector<int> dp; n void dfs(int u, int pa, int val) { n   dp[u] = val; n   for (int j = 0; j < (int)adj[u].size(); j++) { n     int v = adj[u][j].first; n     int d = adj[u][j].second; n     if (v != pa) { n       dfs(v, u, val ^ d); n     } n   } n } n int main() { n   cin >> n >> m; n   UnionFind uf(n); n   adj.assign(n, vector<pair<int, int> >()); n   for (int i = 0; i < m; i++) { n     int x, y, z; n     scanf( %d%d%d , &x, &y, &z); n     x--; n     y--; n     if (uf.isSameSet(x, y)) { n       e.push_back(pair<pair<int, int>, int>(pair<int, int>(x, y), z)); n     } else { n       uf.unionSet(x, y); n       adj[x].push_back(pair<int, int>(y, z)); n       adj[y].push_back(pair<int, int>(x, z)); n     } n   } n   dp.assign(n, 0); n   dfs(0, -1, 0); n   vector<int> mask; n   for (int i = 0; i < (int)e.size(); i++) { n     int x = e[i].first.first; n     int y = e[i].first.second; n     int z = e[i].second; n     int lo = dp[x] ^ dp[y] ^ z; n     mask.push_back(lo); n   } n   int cur = 0; n   for (int l = 30; l >= 0; l--) { n     int c = -1; n     for (int i = cur; i < (int)mask.size(); i++) { n       if (mask[i] & (1 << l)) { n         c = i; n         break; n       } n     } n     if (c == -1) continue; n     swap(mask[cur], mask[c]); n     for (int i = cur + 1; i < (int)mask.size(); i++) { n       if (mask[i] & (1 << l)) mask[i] ^= mask[cur]; n     } n     cur++; n   } n   vector<int> basis; n   for (int i = 0; i < cur; i++) { n     basis.push_back(mask[i]); n   } n   int l = 30; n   int dis = dp[n - 1]; n   for (int i = 0; i < (int)basis.size(); i++) { n     while (((1 << l) & basis[i]) == 0) l--; n     if ((1 << l) & dis) dis ^= basis[i]; n   } n   cout << dis << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int input[100000]; n int output[100000]; n pair<pair<int, int>, int> queries[100000]; n int blockSize; n bool mo_compare(pair<pair<int, int>, int>& x, pair<pair<int, int>, int>& y) { n   int firstBlockIndex = x.first.first / blockSize; n   int secondBlockIndex = y.first.first / blockSize; n   if (firstBlockIndex == secondBlockIndex) { n     return x.first.second < y.first.second; n   } n   return firstBlockIndex < secondBlockIndex; n } n void inline removeElement(unordered_map<int, int>& lookup, int val, n                           int& result) { n   unordered_map<int, int>::iterator itr = lookup.find(val); n   if (itr != lookup.end()) { n     if (itr->first == itr->second) { n       result--; n     } n     itr->second--; n     if (itr->first == itr->second) { n       result++; n     } n   } else { n     lookup[val]--; n   } n } n void inline addElement(unordered_map<int, int>& lookup, int val, int& result) { n   unordered_map<int, int>::iterator itr = lookup.find(val); n   if (itr != lookup.end()) { n     if (itr->first == itr->second) { n       result--; n     } n     itr->second++; n     if (itr->first == itr->second) { n       result++; n     } n   } else { n     lookup[val]++; n     if (val == 1) { n       result++; n     } n   } n } n int main() { n   cin.tie(NULL); n   int n, m; n   cin >> n >> m; n   blockSize = static_cast<int>(sqrt(n)); n   for (int i = 0; i < n; i++) { n     cin >> input[i]; n   } n   for (int i = 0; i < m; i++) { n     pair<pair<int, int>, int>& query = queries[i]; n     cin >> query.first.first >> query.first.second; n     query.first.first--; n     query.first.second--; n     query.second = i; n   } n   sort(queries, queries + m, mo_compare); n   unordered_map<int, int> lookup; n   int result = 0; n   int prev_l = 0, prev_r = -1, left, right, index; n   unordered_map<int, int>::iterator itr; n   for (int i = 0; i < m; i++) { n     left = queries[i].first.first; n     right = queries[i].first.second; n     index = queries[i].second; n     while (left > prev_l) { n       removeElement(lookup, input[prev_l], result); n       prev_l++; n     } n     while (left < prev_l) { n       prev_l--; n       addElement(lookup, input[prev_l], result); n     } n     while (right < prev_r) { n       removeElement(lookup, input[prev_r], result); n       prev_r--; n     } n     while (right > prev_r) { n       prev_r++; n       addElement(lookup, input[prev_r], result); n     } n     output[index] = result; n   } n   for (int i = 0; i < m; i++) { n     cout << output[i] <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long k, n, m; n int answ = 1; n bool flag = 0; n int main() { n   cin >> n >> m; n   k = 2; n   for (int i = 2; i <= m; i++) k = (k * 2) % 1000000009; n   if (k > n) { n     for (int i = 1; i <= n; i++) answ = (answ * (k - i)) % 1000000009; n     cout << answ; n   } else n     cout << 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double pi = acos(-1.0); n long long int path[100001]; n long long int dist[100001]; n void shortest_path(vector<pair<long long int, long long int>> v[], n                    long long int start) { n   long long int i; n   for (i = 0; i < 100001; i++) dist[i] = 1e18 + 1; n   priority_queue<long long int> q; n   q.push(start); n   dist[start] = 0; n   while (!q.empty()) { n     long long int x = q.top(); n     q.pop(); n     for (i = 0; i < v[x].size(); i++) { n       if (dist[v[x][i].first] > dist[x] + v[x][i].second) { n         dist[v[x][i].first] = dist[x] + v[x][i].second; n         path[v[x][i].first] = x; n         q.push(v[x][i].first); n       } n     } n   } n } n void solve() { n   long long int ver, edge, i, x, y, w, start = 1; n   cin >> ver >> edge; n   vector<pair<long long int, long long int>> v[ver + 1]; n   vector<long long int> ans; n   for (i = 0; i < edge; i++) { n     cin >> x >> y >> w; n     v[x].push_back(make_pair(y, w)); n     v[y].push_back(make_pair(x, w)); n   } n   shortest_path(v, start); n   if (dist[ver] == 1e18 + 1) n     cout <<  -1  n          <<   n ; n   else { n     cout <<  1  ; n     while (ver != 1) { n       ans.push_back(ver); n       ver = path[ver]; n     } n     for (i = ans.size() - 1; i >= 0; i--) { n       cout << ans[i] <<    ; n     } n     cout <<   n ; n   } n } n void fast() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n } n int main() { n   fast(); n   int t = 1; n   while (t--) solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = int64_t; n template <typename T, typename U> n ostream& operator<<(ostream& _s, pair<T, U> _t) { n   _s <<  (  << _t.first <<  ,  << _t.second <<  ) ; n   return _s; n } n template <typename T, typename U> n istream& operator>>(istream& _s, pair<T, U>& _t) { n   _s >> _t.first >> _t.second; n   return _s; n } n template <typename T> n ostream& operator<<(ostream& _s, vector<T> _t) { n   for (int i = 0; i < (int)(_t.size()); i++) _s << (i ?     :   ) << _t[i]; n   return _s; n } n template <typename T> n istream& operator>>(istream& _s, vector<T>& _t) { n   for (int i = 0; i < (int)(_t.size()); i++) _s >> _t[i]; n   return _s; n } n vector<int> val, comp, z, cont; n int Time, ncomps; n template <class G, class F> n int dfs(int j, G& g, F f) { n   int low = val[j] = ++Time, x; n   z.push_back(j); n   for (auto& e : g[j]) n     if (comp[e] < 0) low = min(low, val[e] ?: dfs(e, g, f)); n   if (low == val[j]) { n     do { n       x = z.back(); n       z.pop_back(); n       comp[x] = ncomps; n       cont.push_back(x); n     } while (x != j); n     f(cont); n     cont.clear(); n     ncomps++; n   } n   return val[j] = low; n } n template <class G, class F> n void scc(G& g, F f) { n   int n = g.size(); n   val.assign(n, 0); n   comp.assign(n, -1); n   Time = ncomps = 0; n   for (int i = 0; i < (int)(n); i++) n     if (comp[i] < 0) dfs(i, g, f); n } n void tassert(bool cond) { n   if (!cond) { n     while (1 < 2) { n     } n   } n } n void answer(int x) { n   cout <<  !   << (x + 1) << endl; n   cout << flush; n   exit(0); n } n bool ask(int a, int b) { n   cout <<  ?   << (a + 1) <<     << (b + 1) << endl; n   cout << flush; n   int res; n   cin >> res; n   if (res == -1) { n     exit(123); n   } n   return bool(res); n } n int main() { n   int n, m; n   cin >> n >> m; n   vector<vector<int>> g(n); n   for (int i = 0; i < (int)(m); i++) { n     int x, y; n     cin >> x >> y; n     g[x - 1].push_back(y - 1); n   } n   vector<vector<int>> comps; n   scc(g, [&](vector<int>& v) { comps.push_back(v); }); n   vector<unordered_set<int>> cg(ncomps); n   for (int a = 0; a < (int)(n); a++) { n     for (int b : g[a]) { n       if (comp[a] != comp[b]) { n         cg[comp[a]].insert(comp[b]); n       } n     } n   } n   vector<int> indeg(ncomps, 0); n   for (int aa = 0; aa < (int)(ncomps); aa++) { n     for (int bb : cg[aa]) { n       indeg[bb]++; n     } n   } n   unordered_set<int> heads; n   for (int aa = 0; aa < (int)(ncomps); aa++) { n     if (indeg[aa] == 0) { n       heads.insert(aa); n     } n   } n   int head = *heads.begin(); n   int cap = comps[head].back(); n   comps[head].pop_back(); n   auto update = [&](int aa) { n     if (comps[aa].size() == 0) { n       heads.erase(aa); n       for (int bb : cg[aa]) { n         tassert(comps[bb].size() > 0); n         indeg[bb]--; n         if (indeg[bb] == 0) { n           heads.insert(bb); n         } n       } n     } n   }; n   while (true) { n     assert(heads.size()); n     if (heads.size() == 1) { n       answer(cap); n     } n     auto head2it = heads.begin(); n     if (head == (*head2it)) { n       head2it++; n     } n     int head2 = *head2it; n     tassert(!cg[head].count(head2)); n     int cap2 = comps[head2].back(); n     comps[head2].pop_back(); n     bool ok = ask(cap, cap2); n     if (!ok) { n       update(head); n       head = head2; n       cap = cap2; n     } else { n       update(head2); n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   unsigned long long n; n   cin >> n; n   vector<unsigned long long> a(n); n   for (unsigned long long i = 0; i < n; i++) cin >> a[i]; n   unsigned long long total = 0; n   for (unsigned long long i = 0; i < n; i++) total += a[i]; n   vector<unsigned long long> f; n   unsigned long long zd = total; n   for (unsigned long long i = 2; (i * i) <= zd; i++) { n     if (zd % i == 0) { n       f.push_back(i); n       while (zd % i == 0) { n         zd /= i; n       } n     } n   } n   if (zd != 1) f.push_back(zd); n   if (total == 1) { n     cout << -1 <<   n ; n     return 0; n   } n   unsigned long long is = 900000000000000000; n   for (unsigned long long i = 0; i < f.size(); i++) { n     unsigned long long x = f[i]; n     unsigned long long temp = 0; n     vector<pair<unsigned long long, unsigned long long>> z; n     unsigned long long tt = 0; n     for (unsigned long long j = 0; j < n; j++) { n       tt += a[j] % x; n       z.push_back(make_pair(j, a[j] % x)); n       if (tt >= x) { n         unsigned long long left = 0; n         unsigned long long right = 0; n         unsigned long long Sr = 0; n         unsigned long long Sl = 0; n         z[z.size() - 1].second -= (tt - x); n         for (unsigned long long k = 0; k < z.size(); k++) { n           right += n               (unsigned long long)z[k].first * (unsigned long long)z[k].second; n         } n         Sr = x; n         unsigned long long ttt = 900000000000000000; n         for (unsigned long long k = 0; k < z.size(); k++) { n           unsigned long long t2 = 0; n           right -= ((unsigned long long)z[k].first * n                     (unsigned long long)z[k].second); n           left += ((unsigned long long)z[k].first * n                    (unsigned long long)z[k].second); n           Sr -= z[k].second; n           Sl += z[k].second; n           t2 += (right - Sr * z[k].first) + (Sl * z[k].first - left); n           ttt = min(ttt, t2); n         } n         temp += ttt; n         z.clear(); n         tt %= x; n         z.push_back(make_pair(j, tt)); n       } n     } n     is = min(is, temp); n   } n   cout << is <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n using ld = long double; n using pii = pair<int, int>; n constexpr int MAXN = 100005; n int n; n string type[MAXN], word[MAXN]; n bitset<30> to_bs(const string& s) { n   bitset<30> res; n   for (char c : s) { n     res[c -  a ] = true; n   } n   return res; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   cin >> n; n   bitset<30> all = to_bs( abcdefghijklmnopqrstuvwxyz ); n   int ans = 0; n   for (int i = 0; i < n; ++i) { n     cin >> type[i] >> word[i]; n     bitset<30> cur = to_bs(word[i]); n     if (type[i][0] ==  ! ) { n       if (all.count() <= 1) { n         ans += 1; n       } n       all = all & cur; n     } else if (type[i][0] ==  . ) { n       all = all & cur.flip(); n     } else { n       if (all.count() == 1) ans += 1; n       all.reset(word[i][0] -  a ); n     } n   } n   cout << max(0, ans - 1) <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 10; n bool lucky[10010]; n int n, m; n int a[N]; n int t[N + N]; n void init() { n   memset(lucky, false, sizeof(lucky)); n   lucky[0] = true; n   for (int i = 1; i <= 10000; i++) n     if (i % 10 == 4 || i % 10 == 7) lucky[i] = lucky[i / 10]; n } n void update(int i, int v) { n   if (!v) return; n   i += n; n   while (i >= 1) { n     t[i] += v; n     i >>= 1; n   } n } n int query(int Left, int Right) { n   int res = 0; n   Left += n; n   Right += n; n   while (Left <= Right) { n     if (Left % 2) res += t[Left]; n     if ((~Right) % 2) res += t[Right]; n     Left = (Left + 1) >> 1; n     Right = (Right - 1) >> 1; n   } n   return res; n } n int main() { n   init(); n   scanf( %d%d , &n, &m); n   memset(t, 0, sizeof(t)); n   for (int i = 0; i < n; i++) { n     scanf( %d , &a[i]); n     update(i, lucky[a[i]]); n   } n   char x[10]; n   int Left, Right, temp; n   while (m--) { n     scanf( %s , &x); n     if (strcmp(x,  count ) == 0) { n       scanf( %d%d , &Left, &Right); n       Left--; n       Right--; n       printf( %d n , query(Left, Right)); n     } else { n       scanf( %d%d%d , &Left, &Right, &temp); n       Left--; n       Right--; n       for (int i = Left; i <= Right; i++) { n         a[i] += temp; n         update(i, lucky[a[i]] - lucky[a[i] - temp]); n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double pi = acos(-1.0), eps = 1e-8; n const int inf = ~0U >> 2; n int mod = 1e9 + 7; n int Pow(int x, long long t) { n   int r = 1; n   for (; t; t >>= 1, x = (long long)x * x % mod) n     if (t & 1) r = (long long)r * x % mod; n   return r; n } n const int N = 101010; n int n, K; n struct P { n   long long x, y; n   void in() { cin >> x >> y; } n   P(long long _x = 0, long long _y = 0) { x = _x, y = _y; } n   double dis() { return sqrt(x * x + y * y); } n   long long operator^(const P& b) { return x * b.y - y * b.x; } n   P operator-(const P& b) { return P(x - b.x, y - b.y); } n } p[N << 1], q; n long long mul(P& o, P& a, P& b) { return (a - o) ^ (b - o); } n bool in(P q) { n   double a = 0; n   for (int i = 0; i < n; ++i) { n     long long aera = mul(q, p[i], p[i + 1]); n     double disa = (p[i] - q).dis(), disb = (p[i + 1] - q).dis(), n            disc = (p[i] - p[i + 1]).dis(); n     double angle = acos(((disa) * (disa) + (disb) * (disb) - (disc) * (disc)) / n                         2.0 / disa / disb); n     if (aera > 0) n       a += angle; n     else n       a -= angle; n   } n   return fabs(a) >= 1; n } n long long wk() { n   q.in(); n   if (!in(q)) return 0; n   long long ans = (long long)n * (n - 1) * (n - 2) / 6; n   for (int i = 0, j = 1; i < n; ++i) { n     while (mul(p[i], p[j], q) <= 0) ++j; n     int del = (j + n - i) % n; n     int rm = n - del; n     ans -= (long long)rm * (rm - 1) / 2; n   } n   return ans; n } n int main() { n   cin >> n; n   for (int i = 0; i < n; ++i) p[i].in(), p[i + n] = p[i]; n   cin >> K; n   for (int i = 0; i < K; ++i) cout << wk() << endl; n   return 0; n } n


#include <bits/stdc++.h> n   n using namespace std; n   n bool palindrome(const string &s) { n     int n = s.length(); n     for(int i = 0; i < n; i++) { n         if(s[i] != s[n - i - 1]) return false; n     } n     return true; n } n   n int main() { n     ios::sync_with_stdio(false); n     cin.tie(0); n     int te; n     cin >> te; n     while(te--) { n         string s; n         cin >> s; n         if(!palindrome(s +  a )) { n             cout <<  YES n  << s <<  a  <<   n ; n         }else if(!palindrome( a  + s)) { n             cout <<  YES n  <<  a  << s <<   n ; n         }else { n             cout <<  NO n ; n         } n     } n }


#include <bits/stdc++.h> n const long double PI(acosl(-1.0)); n long double eps = 1e-9; n using namespace std; n using namespace std; n const int N = 1000000; n int main() { n   std::ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int n; n   cin >> n; n   vector<pair<int, int> > p(n); n   int s = 0; n   for (int i(0); i < n; i++) { n     int x; n     cin >> x; n     s += x; n     p[i] = {x, i + 1}; n   } n   sort(++p.begin(), p.end()); n   reverse(++p.begin(), p.end()); n   vector<pair<int, int> > ans; n   int j = 1; n   int i = 0; n   while (j < n) { n     while (j < n && p[i].first > 0) { n       ans.push_back({p[i].second, p[j].second}); n       p[i].first--; n       j++; n     } n     i++; n     if (i == j) break; n   } n   if (j < n) { n     cout << -1; n     return 0; n   } n   cout << ans.size() << endl; n   for (int i(0); i < ans.size(); i++) n     cout << ans[i].first <<     << ans[i].second <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n void CIN(T &a) { n   cin >> a; n } n template <class T> n void CIN(T &a, T &b) { n   cin >> a >> b; n } n template <class T> n void CIN(T &a, T &b, T &c) { n   cin >> a >> b >> c; n } n template <class T> n void CIN(T &a, T &b, T &c, T &d) { n   cin >> a >> b >> c >> d; n } n template <class T> n void PI(T a) { n   cout << a << endl; n } n template <class T> n void PI(T a, T b) { n   cout << a <<     << b << endl; n } n template <class T> n void PIS(T a) { n   cout << a <<    ; n } n template <class T> n T abs(T a) { n   return a < 0 ? -a : a; n } n const int N = 10000010; n long long n, x, y, dx, dy, t; n int b[6][6] = {{2, 1, 1, 0, 1, 0}, {1, 2, 0, 1, 1, 0}, {1, 1, 1, 0, 1, 0}, n                {1, 1, 0, 1, 1, 0}, {0, 0, 0, 0, 1, 1}, {0, 0, 0, 0, 0, 1}}; n struct matrix { n   long long a[6][6]; n   matrix() { memset(a, 0, sizeof(a)); } n   void init() { n     int i, j; n     for (i = 0; i < (int)(6); ++i) n       for (j = 0; j < (int)(6); ++j) a[i][j] = b[i][j]; n   } n   void unit() { n     memset(a, 0, sizeof(a)); n     int i; n     for (i = 0; i < (int)(6); ++i) a[i][i] = 1; n   } n   matrix operator*(const matrix &b) const { n     matrix ret; n     int i, j, k; n     for (i = 0; i < (int)(6); ++i) n       for (j = 0; j < (int)(6); ++j) n         for (k = 0; k < (int)(6); ++k) { n           ret.a[i][j] += a[i][k] * b.a[k][j]; n           ret.a[i][j] %= n; n         } n     return ret; n   } n   matrix Pow(long long k) { n     matrix ret, p = *this; n     ret.unit(); n     while (k) { n       if (k & 1) ret = ret * p; n       k >>= 1; n       p = p * p; n     } n     return ret; n   } n } mx; n int main() { n   CIN(n); n   CIN(x, y, dx, dy); n   CIN(t); n   mx.init(); n   mx = mx.Pow(t); n   long long ex = mx.a[0][0] * x + mx.a[0][1] * y + mx.a[0][2] * dx + n                  mx.a[0][3] * dy + mx.a[0][5]; n   long long ey = mx.a[1][0] * x + mx.a[1][1] * y + mx.a[1][2] * dx + n                  mx.a[1][3] * dy + mx.a[1][5]; n   ex %= n; n   if (ex <= 0) ex += n; n   ey %= n; n   if (ey <= 0) ey += n; n   PI(ex, ey); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int a, b, c; n   cin >> a >> b >> c; n   int max = 0; n   int n[100]; n   n[0] = a * b + c, n[1] = a * b * c, n[2] = a + b * c, n[3] = a + b + c, n   n[4] = a * (b + c), n[5] = (a + b) * c; n   for (int i = 0; i < 6; i++) { n     if (n[i] > max) max = n[i]; n   } n   cout << max << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n  n typedef long long Int; n typedef pair<int,int> PII; n typedef vector<int> VInt; n   n #define FOR(i, a, b) for(i = (a); i < (b); ++i) n #define RFOR(i, a, b) for(i = (a) - 1; i >= (b); --i) n #define EACH(it, a) for(auto it = (a).begin(); it != (a).end(); ++it) n #define CLEAR(a, b) memset(a, b, sizeof(a)) n #define SIZE(a) int((a).size()) n #define ALL(a) (a).begin(),(a).end() n #define MP make_pair n  n int f(VInt p, VInt s) n { n  int n = SIZE(p); n  int left = 0, right = n - 1; n  int res = 0; n  VInt used(n, 0); n  while(left < right) n  { n   int cnt = 0; n   int flips = 0; n   int l = left; n   int r = right + 1; n   while(l >= left || r <= right) n   { n    if(l >= left) n    { n     int a = left; n     ++left; n     if(used[a] == 0) n     { n      int b = p[a]; n      used[a] = used[b] = 1; n      ++cnt; n      flips += s[a]; n      if(b > r) return -1; n      r = b; n      if(l >= r) return -1; n     } n    } n    if(r <= right) n    { n     int a = right; n     --right; n     if(used[a] == 0) n     { n      int b = p[a]; n      used[a] = used[b] = 1; n      ++cnt; n      flips += s[a]; n      if(b < l) return -1; n      l = b; n      if(l >= r) return -1; n     } n    } n   } n   res += min(flips, cnt - flips); n  } n  return res; n } n  n void SolveTest(int test) n { n  int n; n  cin >> n; n  int i, j; n  VInt p(n + n); n  VInt s(n + n); n  FOR(i, 0, n) n  { n   int a, b; n   cin >> a >> b; n   --a; n   --b; n   p[a] = b; n   p[b] = a; n   s[a] = 0; n   s[b] = 1; n  } n  n  cout << f(p, s) << endl; n } n  n int main() n { n  int T, t; n  T = 1; n  //cin >> T; n  FOR(t, 0, T) SolveTest(t); n  return 0; n };


#include <bits/stdc++.h> n using namespace std; n const int N = 55; n const int MOD = 1e9 + 7; n struct Node { n   int op, x, y, d; n   Node() {} n   Node(int _op, int _x, int _y, int _d) { op = _op, x = _x, y = _y, d = _d; } n   bool operator<(const Node &cur) const { return d > cur.d; } n }; n priority_queue<Node> que; n int dist[2][N][N], n, m, nx, ny; n long long ans[2][N][N], C[N][N]; n void init() { n   int i, j; n   memset(C, 0, sizeof(C)); n   for (i = 0; i < N; i++) { n     C[i][0] = 1; n     for (j = 1; j <= i; j++) C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % MOD; n   } n } n int main() { n   int i, j, tmp; n   init(); n   while (scanf( %d%d , &n, &m) != EOF) { n     for (i = 1, nx = ny = 0; i <= n; i++) { n       scanf( %d , &tmp); n       if (tmp == 50) n         nx++; n       else n         ny++; n     } n     memset(dist, 0x3f, sizeof(dist)); n     memset(ans, 0, sizeof(ans)); n     while (!que.empty()) que.pop(); n     dist[1][0][0] = 0; n     ans[1][0][0] = 1; n     que.push(Node(1, 0, 0, 0)); n     while (!que.empty()) { n       Node cur = que.top(); n       que.pop(); n       if (cur.d > dist[cur.op][cur.x][cur.y]) continue; n       for (i = 0; i <= nx; i++) n         for (j = 0; j <= ny; j++) { n           if (i + j == 0 || 50 * i + 100 * j > m) continue; n           if (cur.op == 0 && cur.x >= i && cur.y >= j) { n             if (dist[1][cur.x - i][cur.y - j] >= cur.d + 1) { n               if (dist[1][cur.x - i][cur.y - j] > cur.d + 1) { n                 ans[1][cur.x - i][cur.y - j] = 0; n                 dist[1][cur.x - i][cur.y - j] = cur.d + 1; n                 que.push(Node(1, cur.x - i, cur.y - j, cur.d + 1)); n               } n               ans[1][cur.x - i][cur.y - j] += n                   ans[0][cur.x][cur.y] * C[cur.x][i] % MOD * C[cur.y][j] % MOD; n               ans[1][cur.x - i][cur.y - j] %= MOD; n             } n           } n           if (cur.op == 1 && cur.x + i <= nx && cur.y + j <= ny) { n             if (dist[0][cur.x + i][cur.y + j] >= cur.d + 1) { n               if (dist[0][cur.x + i][cur.y + j] > cur.d + 1) { n                 ans[0][cur.x + i][cur.y + j] = 0; n                 dist[0][cur.x + i][cur.y + j] = cur.d + 1; n                 que.push(Node(0, cur.x + i, cur.y + j, cur.d + 1)); n               } n               ans[0][cur.x + i][cur.y + j] += ans[1][cur.x][cur.y] * n                                               C[nx - cur.x][i] % MOD * n                                               C[ny - cur.y][j] % MOD; n               ans[0][cur.x + i][cur.y + j] %= MOD; n             } n           } n         } n     } n     if (dist[0][nx][ny] == 0x3f3f3f3f) { n       printf( -1 n0 n ); n     } else { n       printf( %d n%I64d n , dist[0][nx][ny], ans[0][nx][ny]); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n bool chmax(T &a, const T &b) { n   if (a < b) { n     a = b; n     return 1; n   } n   return 0; n } n template <class T> n bool chmin(T &a, const T &b) { n   if (a > b) { n     a = b; n     return 1; n   } n   return 0; n } n template <class T> n ostream &operator<<(ostream &os, const vector<T> &t) { n   os <<  [ ; n   for (__typeof((t).begin()) it = (t).begin(); it != (t).end(); it++) { n     if (it != t.begin()) os <<  , ; n     os << *it; n   } n   os <<  ] ; n   return os; n } n template <class T> n ostream &operator<<(ostream &os, const set<T> &t) { n   os <<  { ; n   for (__typeof((t).begin()) it = (t).begin(); it != (t).end(); it++) { n     if (it != t.begin()) os <<  , ; n     os << *it; n   } n   os <<  } ; n   return os; n } n template <class S, class T> n ostream &operator<<(ostream &os, const pair<S, T> &t) { n   return os <<  (  << t.first <<  ,  << t.second <<  ) ; n } n template <class S, class T> n pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { n   return pair<S, T>(s.first + t.first, s.second + t.second); n } n template <class S, class T> n pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { n   return pair<S, T>(s.first - t.first, s.second - t.second); n } n namespace geom { n enum { TRUE = 1, FALSE = 0, BORDER = -1 }; n const long double INF = 1e8; n long double EPS = 1e-6; n const long double PI = 3.1415926535897932384626; n inline int sig(const long double &x) { n   return (abs(x) < EPS ? 0 : x > 0 ? 1 : -1); n } n inline int less(const long double &x, const long double &y) { n   return sig(x - y) ? x < y : BORDER; n } n inline long double norm(const complex<long double> &p) { n   return p.real() * p.real() + p.imag() * p.imag(); n } n inline long double inp(const complex<long double> &a, n                        const complex<long double> &b) { n   return (conj(a) * b).real(); n } n inline long double outp(const complex<long double> &a, n                         const complex<long double> &b) { n   return (conj(a) * b).imag(); n } n inline complex<long double> unit(const complex<long double> &p) { n   return p / abs(p); n } n inline complex<long double> proj(const complex<long double> &s, n                                  const complex<long double> &t) { n   return t * inp(s, t) / norm(t); n } n inline int ccw(const complex<long double> &s, const complex<long double> &t, n                const complex<long double> &p, int adv = 0) { n   int res = sig(outp(t - s, p - s)); n   if (res || !adv) return res; n   if (sig(inp(t - s, p - s)) < 0) return -2; n   if (sig(inp(s - t, p - t)) < 0) return 2; n   return 0; n } n }  // namespace geom n using namespace geom; n int f = 0; n namespace std { n bool operator<(const complex<long double> &a, const complex<long double> &b) { n   return sig(a.real() - b.real()) ? a.real() < b.real() n                                   : a.imag() + EPS < b.imag(); n } n bool operator==(const complex<long double> &a, const complex<long double> &b) { n   return abs(a - b) < EPS; n } n istream &operator>>(istream &is, complex<long double> &p) { n   long double x, y; n   is >> x >> y; n   p = complex<long double>(x, y); n   return is; n } n }  // namespace std n int n, m; n complex<long double> p, q, v, w; n long double vmax, ct; n long double dist(complex<long double> v, complex<long double> wind, n                  long double t) { n   if (abs(v) > EPS) v = unit(v); n   long double l = 0, r = 1e10; n   for (int _ = 0; _ < (int)(100); _++) { n     long double mid = (l + r) / 2; n     long double vx = v.real() * mid; n     long double vy = v.imag() * mid; n     if ((vx * vx + vy * vy) <= vmax * vmax) n       l = mid; n     else n       r = mid; n   } n   return abs(v * l) * t; n } n int check(long double t) { n   complex<long double> s = n       q + v * min<long double>(t, ct) + w * max<long double>(t - ct, 0); n   complex<long double> vec = p - s; n   return dist(vec, v, min<long double>(t, ct)) + n              dist(vec, w, max<long double>(t - ct, 0)) >= n          abs(vec); n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cin >> q >> p; n   cin >> vmax >> ct; n   cin >> v >> w; n   long double l = 0, r = 1e10; n   for (int _ = 0; _ < (int)(100); _++) { n     long double mid = (l + r) / 2; n     if (check(mid)) n       r = mid; n     else n       l = mid; n   } n   printf( %.20f n , (double)l); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n long long a[305], Lcm; n long long sol(long long x) { n   long long cnt = 0; n   for (long long i = 2; i * i <= x; i++) { n     if (x % i == 0) { n       cnt += 2; n       if (i * i == x) cnt--; n     } n   } n   return cnt; n } n int main() { n   int T; n   cin >> T; n   while (T--) { n     int ok = 1; n     scanf( %d , &n); n     for (int i = 0; i < n; i++) scanf( %lld , &a[i]); n     sort(a, a + n); n     if (n == 1) n       Lcm = a[0] * a[0]; n     else n       Lcm = a[0] * a[n - 1]; n     for (int i = 1; i < (n + 1) / 2; i++) { n       if (a[i] * a[n - 1 - i] != Lcm) { n         ok = 0; n         break; n       } n     } n     if (ok && sol(Lcm) == n) n       printf( %lld n , Lcm); n     else n       puts( -1 ); n   } n } n


#include <bits/stdc++.h> n using namespace std; n char ch[100001]; n int per[100001]; n bool is[100001]; n bool vis[100001]; n bool mem[100001]; n bool have[100001]; n vector<int> V; n int main() { n   int i, j; n   int a, b; n   int n, m; n   cin >> n >> m; n   for (i = 0; i < m; i++) { n     cin >> ch[i] >> per[i]; n     have[per[i]] = true; n   } n   V.clear(); n   memset(is, true, sizeof is); n   for (i = 0; i < m; i++) { n     if (ch[i] ==  + ) { n       if (!vis[per[i]] && i) is[per[i]] = false; n       if (V.size()) { n         is[per[i]] = false; n       } else { n         for (j = i - 1; j >= 0; j--) { n           if (per[i] != per[j]) is[per[j]] = false; n           if (mem[j]) break; n         } n         mem[i - 1] = true; n       } n       V.push_back(per[i]); n     } else { n       if (!vis[per[i]]) { n         for (j = i - 1; j >= 0; j--) { n           is[per[j]] = false; n           if (mem[j]) break; n         } n         mem[i - 1] = true; n         if (V.size()) is[per[i]] = false; n       } else if (V.size() == 1) { n         if (V[0] == per[i]) n           V.clear(); n         else { n           int num = per[i]; n           V.erase(std::remove(V.begin(), V.end(), num), V.end()); n           is[num] = false; n         } n       } else if (V.size()) { n         int num = per[i]; n         V.erase(std::remove(V.begin(), V.end(), num), V.end()); n         is[num] = false; n       } n     } n     if (!vis[per[i]]) vis[per[i]] = true; n   } n   vector<int> res; n   res.clear(); n   for (i = 1; i <= n; i++) { n     if (!have[i]) { n       res.push_back(i); n     } else { n       if (is[i]) res.push_back(i); n     } n   } n   int sz = res.size(); n   cout << sz << endl; n   for (i = 0; i < sz; i++) cout << res[i] <<    ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int mod = 1e9 + 7; n const long long inf = 2e18; n struct custom_hash { n   static uint64_t splitmix64(uint64_t x) { n     x += 0x9e3779b97f4a7c15; n     x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; n     x = (x ^ (x >> 27)) * 0x94d049bb133111eb; n     return x ^ (x >> 31); n   } n   size_t operator()(uint64_t x) const { n     static const uint64_t FIXED_RANDOM = n         chrono::steady_clock::now().time_since_epoch().count(); n     return splitmix64(x + FIXED_RANDOM); n   } n }; n int add(int a, int b) { n   int res = (a + b) % mod; n   if (res < 0) res += mod; n   return res; n } n int mult(int a, int b) { n   int res = (a * 1LL * b) % mod; n   if (res < mod) res += mod; n   return res; n } n int power(int a, int b) { n   int res = 1; n   while (b) { n     if ((b % 2) == 1) res = mult(res, a); n     a = mult(a, a); n     b /= 2; n   } n   return res; n } n template <typename A, typename B> n string to_string(pair<A, B> p); n template <typename A, typename B, typename C> n string to_string(tuple<A, B, C> p); n template <typename A, typename B, typename C, typename D> n string to_string(tuple<A, B, C, D> p); n string to_string(const string &s) { return     + s +    ; } n string to_string(const char *s) { return to_string((string)s); } n string to_string(bool b) { return (b ?  true  :  false ); } n string to_string(char c) { return to_string(string(1, c)); } n string to_string(vector<bool> v) { n   bool first = true; n   string res =  { ; n   for (int i = 0; i < static_cast<int>(v.size()); i++) { n     if (!first) { n       res +=  ,  ; n     } n     first = false; n     res += to_string(v[i]); n   } n   res +=  } ; n   return res; n } n template <size_t N> n string to_string(bitset<N> v) { n   string res =   ; n   for (size_t i = 0; i < N; i++) { n     res += static_cast<char>( 0  + v[i]); n   } n   return res; n } n template <typename A> n string to_string(A v) { n   bool first = true; n   string res =  { ; n   for (const auto &x : v) { n     if (!first) { n       res +=  ,  ; n     } n     first = false; n     res += to_string(x); n   } n   res +=  } ; n   return res; n } n template <typename A, typename B> n string to_string(pair<A, B> p) { n   return  (  + to_string(p.first) +  ,   + to_string(p.second) +  ) ; n } n template <typename A, typename B, typename C> n string to_string(tuple<A, B, C> p) { n   return  (  + to_string(get<0>(p)) +  ,   + to_string(get<1>(p)) +  ,   + n          to_string(get<2>(p)) +  ) ; n } n template <typename A, typename B, typename C, typename D> n string to_string(tuple<A, B, C, D> p) { n   return  (  + to_string(get<0>(p)) +  ,   + to_string(get<1>(p)) +  ,   + n          to_string(get<2>(p)) +  ,   + to_string(get<3>(p)) +  ) ; n } n void dbg() { cout << endl; } n template <typename Head, typename... Tail> n void dbg(Head H, Tail... T) { n   cout <<     << to_string(H); n   dbg(T...); n } n void solve() { n   int n; n   cin >> n; n   vector<int> v(n); n   for (int i = 0; i < n; i++) { n     cin >> v[i]; n   } n   vector<int> dp(1 << 22, 0); n   for (int i = 0; i < n; i++) { n     dp[v[i]] = v[i]; n   } n   for (int mask = 1; mask < (1 << 22); mask++) { n     for (int i = 0; i < 22; i++) { n       if (mask & (1 << i)) { n         dp[mask] = max(dp[mask], dp[mask ^ (1 << i)]); n       } n     } n   } n   for (int i = 0; i < n; i++) { n     int no = ((1 << 22) - 1) & (~v[i]); n     if (dp[no]) { n       cout << dp[no] <<    ; n     } else { n       cout <<  -1  ; n     } n   } n } n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   cout << fixed << setprecision(10); n   int t = 1; n   for (int i = 1; i <= t; i++) { n     solve(); n   } n } n


#include<bits/stdc++.h> n using namespace std; n #define ll long long n #define ld long double n #define For(i,x,y) for(ll i = (x);i <= (y);++i) n #define FOr(i,x,y) for(ll i = (x);i >= (y);--i) n #define fi first n #define se second n #define pa pair<ll,ll> n #define mk make_pair n #define pb push_back n #define clr(a,b) memset(a,b,sizeof(a)) n #define cpy(a,b) memcpy(a,b,sizeof(b)) n #define y1 y11111111111111111111 n #define debug puts( @@@@@@@@@@@@@@@@@@@@ ) n #define NO puts( NO ) n #define YES puts( YES ) n #define Yes puts( Yes ) n #define No puts( No ) n inline ll read() n { n  ll x = 0,f = 1;char ch = getchar(); n  while(ch <  0  || ch >  9 ){if(ch ==  - )f = -1;ch = getchar();} n  while(ch >=  0  && ch <=  9 ){x = x*10+ch- 0 ;ch = getchar();} n  return x*f; n } n char s[999]; n int main() n { n  while (scanf( %s ,s)!=EOF) n  { n   if (s[1]== s ) puts( NO ),fflush(stdout); n  } n }


#include <bits/stdc++.h> n using namespace std; n int n; n double s; n vector<int> E[100005]; n int dist[100005], pa[100005]; n int dfs(int u, int p, int d) { n   dist[u] = d; n   int ans = u; n   for (int v : E[u]) { n     if (v == p) continue; n     int tmp = dfs(v, u, d + 1); n     pa[v] = u; n     if (dist[ans] < dist[tmp]) ans = tmp; n   } n   return ans; n } n int main() { n   scanf( %d%lf , &n, &s); n   for (int i = 0; i < n - 1; i++) { n     int u, v; n     scanf( %d%d , &u, &v); n     E[u].push_back(v); n     E[v].push_back(u); n   } n   if (n == 2) { n     printf( %.10lf n , s); n     return 0; n   } n   int l = 0; n   for (int i = 1; i <= n; i++) { n     if (E[i].size() == 1) l++; n   } n   printf( %.10lf n , 2.0 * s / l); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long mk[100000]; n int main() { n   long a, b, m, r0, r; n   cin >> a >> b >> m >> r0; n   for (long i = 0; i < m; i++) mk[i] = -1; n   r = (a * r0 + b) % m; n   mk[r] = 1; n   long k = 1; n   while (true) { n     k++; n     r = (a * r + b) % m; n     if (mk[r] == -1) n       mk[r] = k; n     else { n       cout << k - mk[r]; n       return 0; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, maxi = 2, ans = 2; n int a[100005]; n vector<int> num; n int main() { n   cin >> n; n   for (int i = 0; i < n; i++) cin >> a[i]; n   if (n < 3) { n     cout << n; n     return 0; n   } n   for (int i = 2; i < n; i++) { n     if (a[i] == a[i - 1] + a[i - 2]) { n       ans++; n       maxi = max(maxi, ans); n     } else n       ans = 2; n   } n   cout << maxi; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 100010; n const int mod = 1e9 + 7; n long long dp[maxn] = {0, 1, 2, 3, 5, 8}; n int main() { n   for (int i = 6; i < maxn; i++) dp[i] = (dp[i - 1] + dp[i - 2]) % mod; n   int n, m; n   cin >> n >> m; n   cout << (2 * (dp[n] + dp[m] - 1)) % mod << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int Set(int N, int pos) { return N = N | (1 << pos); } n int reset(int N, int pos) { return N = N & ~(1 << pos); } n bool check(long long N, int pos) { return (bool)(N & (1LL << pos)); } n int n, m, l, r; n string s; n char c1, c2; n int main() { n   cin >> n >> m; n   cin >> s; n   for (int i = 1; i <= m; i++) { n     cin >> l >> r >> c1 >> c2; n     l--, r--; n     for (int j = l; j <= r; j++) { n       if (s[j] == c1) s[j] = c2; n     } n   } n   cout << s << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s; n   cin >> s; n   set<string> g; n   g.insert(s); n   int n = s.size(); n   for (int k = 0; k < s.size(); k++) { n     string s1 =   ; n     s1 += s[n - 1]; n     for (int i = 0; i < s.size() - 1; i++) { n       s1 += s[i]; n     } n     s = s1; n     g.insert(s); n   } n   cout << g.size(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long mod = 1000000007; n vector<long long> parent(200005), Size(200005, 1); n long long answer = 0; n long long find_set(long long n) { n   if (parent[n] == n) n     return n; n   else n     return find_set(parent[n]); n } n void add_edge(long long a, long long b) { n   long long A = find_set(a); n   long long B = find_set(b); n   if (Size[A] >= Size[B]) { n     answer -= ((Size[A] * (Size[A] - 1)) / 2); n     answer -= ((Size[B] * (Size[B] - 1)) / 2); n     Size[A] += Size[B]; n     Size[B] = 0; n     parent[B] = A; n     answer += ((Size[A] * (Size[A] - 1)) / 2); n   } else { n     answer -= ((Size[B] * (Size[B] - 1)) / 2); n     answer -= ((Size[A] * (Size[A] - 1)) / 2); n     Size[B] += Size[A]; n     Size[A] = 0; n     parent[A] = B; n     answer += ((Size[B] * (Size[B] - 1)) / 2); n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   long long N, Q, p, q, r; n   cin >> N >> Q; n   if (N == 1) { n     for (long long i = 1; i <= Q; i++) cout <<  0  ; n     return 0; n   } n   for (long long i = 1; i <= N; i++) parent[i] = i; n   vector<pair<long long, pair<long long, long long>>> G; n   for (long long i = 1; i < N; i++) { n     cin >> p >> q >> r; n     G.push_back({r, {p, q}}); n   } n   sort(G.begin(), G.end()); n   vector<long long> final_ans(N + 1); n   long long ptr = 0; n   for (long long i = 1; i <= N;) { n     if (G[ptr].first == i) { n       add_edge(G[ptr].second.first, G[ptr].second.second); n       ptr++; n     } else { n       final_ans[i] = answer; n       i++; n     } n   } n   while (Q--) { n     long long k; n     cin >> k; n     cout << final_ans[k] <<    ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   map<long long, long long> isolados; n   long long n, k, i, j, prox, qtd, x, resp; n   bool first = true; n   while (cin >> n >> k) { n     resp = 0; n     isolados.clear(); n     prox = -1; n     first = true; n     for (i = 0; i < k; i++) { n       cin >> qtd; n       for (j = 0; j < qtd; j++) { n         cin >> x; n         if (x == 1) prox = 1; n         if (x == prox && first == true) { n           prox++; n         } else if (j == 0) { n           isolados[x] = 0; n         } else { n           isolados[x] = 1; n         } n       } n       if (prox != -1) first = false; n     } n     for (prox; prox <= n; prox++) { n       resp += isolados[prox] + 1; n     } n     cout << resp << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, sti[101], i, x, ans; n   cin >> n; n   memset(sti, 0, sizeof(sti)); n   for (i = 1; i <= n; i++) { n     cin >> x; n     sti[x]++; n   } n   ans = 0; n   for (i = 1; i <= 100; i++) { n     ans += 2 * (sti[i] / 4); n     sti[i] %= 4; n     ans += sti[i] / 2; n   } n   cout << ans / 2 << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n double a[4010]; n int main() { n   cin >> n; n   n *= 2; n   for (int i = 1; i <= n; ++i) cin >> a[i]; n   for (int i = 1; i <= n; ++i) a[i] = a[i] - int(a[i]); n   int cnt = 0; n   for (int i = 1; i <= n; ++i) n     if (abs(a[i] - 0) <= 0.0000001) cnt++; n   double sum = 0; n   for (int i = 1; i <= n; ++i) sum += a[i]; n   double res = 1000000001; n   for (int i = 0; i <= cnt; ++i) res = min(res, abs(n / 2 - sum - i)); n   printf( %.3f , res); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int a[100005]; n   int n, i; n   scanf( %d , &n); n   for (i = 0; i < n; i++) { n     scanf( %d , &a[i]); n   } n   sort(a, a + n); n   if (a[n - 1] == 1) { n     for (i = 0; i < n - 1; i++) { n       printf( %d  , a[i]); n     } n     puts( 2 ); n   } else { n     printf( 1 ); n     for (i = 0; i < n - 1; i++) { n       printf(  %d , a[i]); n     } n     printf(  n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long solve(long long a, long long b, long long c) { n   long long a1 = a - c; n   a1 *= a1; n   long long b1 = c - b; n   b1 *= b1; n   long long c1 = b - a; n   c1 *= c1; n   return a1 + b1 + c1; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int t; n   t = 1; n   cin >> t; n   while (t--) { n     long long a, b, c; n     cin >> a >> b >> c; n     vector<long long> arr(a, 0), arr1(b, 0), arr2(c, 0); n     for (int i = 0; i < a; i++) { n       cin >> arr[i]; n     } n     for (int i = 0; i < b; i++) { n       cin >> arr1[i]; n     } n     for (int i = 0; i < c; i++) { n       cin >> arr2[i]; n     } n     sort((arr).begin(), (arr).end()); n     sort((arr1).begin(), (arr1).end()); n     sort((arr2).begin(), (arr2).end()); n     long long ans = 4 * (1e18); n     vector<long long>::iterator it; n     it = unique((arr).begin(), (arr).end()); n     arr.resize(distance(arr.begin(), it)); n     it = unique((arr1).begin(), (arr1).end()); n     arr1.resize(distance(arr1.begin(), it)); n     it = unique((arr2).begin(), (arr2).end()); n     arr2.resize(distance(arr2.begin(), it)); n     a = arr.size(); n     b = arr1.size(); n     c = arr2.size(); n     for (int i = 0; i < a; i++) { n       long long in = n           lower_bound((arr1).begin(), (arr1).end(), arr[i]) - arr1.begin(); n       vector<long long> a1; n       vector<long long> b1; n       if (in == b) { n         a1.push_back(arr1[in - 1]); n       } else { n         a1.push_back(arr1[in]); n         if (in < b - 1) { n           a1.push_back(arr1[in + 1]); n         } n         if (in > 0) { n           a1.push_back(arr1[in - 1]); n         } n       } n       in = lower_bound((arr2).begin(), (arr2).end(), arr[i]) - arr2.begin(); n       if (in == c) { n         b1.push_back(arr2[in - 1]); n       } else { n         b1.push_back(arr2[in]); n         if (in < c - 1) { n           b1.push_back(arr2[in + 1]); n         } n         if (in > 0) { n           b1.push_back(arr2[in - 1]); n         } n       } n       for (int j = 0; j < a1.size(); j++) { n         for (int l = 0; l < b1.size(); l++) { n           long long k = solve(arr[i], a1[j], b1[l]); n           ans = min(k, ans); n         } n       } n     } n     for (int i = 0; i < b; i++) { n       long long in = n           lower_bound((arr).begin(), (arr).end(), arr1[i]) - arr.begin(); n       vector<long long> a1; n       vector<long long> b1; n       if (in == a) { n         a1.push_back(arr[in - 1]); n       } else { n         a1.push_back(arr[in]); n         if (in < a - 1) { n           a1.push_back(arr[in + 1]); n         } n         if (in > 0) { n           a1.push_back(arr[in - 1]); n         } n       } n       in = lower_bound((arr2).begin(), (arr2).end(), arr1[i]) - arr2.begin(); n       if (in == c) { n         b1.push_back(arr2[in - 1]); n       } else { n         b1.push_back(arr2[in]); n         if (in < c - 1) { n           b1.push_back(arr2[in + 1]); n         } n         if (in > 0) { n           b1.push_back(arr2[in - 1]); n         } n       } n       for (int j = 0; j < a1.size(); j++) { n         for (int l = 0; l < b1.size(); l++) { n           long long k = solve(arr1[i], a1[j], b1[l]); n           ans = min(k, ans); n         } n       } n     } n     for (int i = 0; i < c; i++) { n       long long in = n           lower_bound((arr1).begin(), (arr1).end(), arr2[i]) - arr1.begin(); n       vector<long long> a1; n       vector<long long> b1; n       if (in == b) { n         a1.push_back(arr1[in - 1]); n       } else { n         a1.push_back(arr1[in]); n         if (in < b - 1) { n           a1.push_back(arr1[in + 1]); n         } n         if (in > 0) { n           a1.push_back(arr1[in - 1]); n         } n       } n       in = lower_bound((arr).begin(), (arr).end(), arr2[i]) - arr.begin(); n       if (in == a) { n         b1.push_back(arr[in - 1]); n       } else { n         b1.push_back(arr[in]); n         if (in < a - 1) { n           b1.push_back(arr[in + 1]); n         } n         if (in > 0) { n           b1.push_back(arr[in - 1]); n         } n       } n       for (int j = 0; j < a1.size(); j++) { n         for (int l = 0; l < b1.size(); l++) { n           long long k = solve(arr2[i], a1[j], b1[l]); n           ans = min(k, ans); n         } n       } n     } n     cout << ans <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct group { n   int sz; n   vector<int> worst, best; n   group(vector<int>& a) n       : sz(1), worst(a.begin(), a.end()), best(a.begin(), a.end()) {} n   bool operator<(const group& a) const { n     for (int i = 0; i < best.size(); i++) n       if (best[i] >= a.worst[i]) return false; n     return true; n   } n   struct group& operator+=(const group& a) { n     sz += a.sz; n     for (int i = 0; i < best.size(); i++) { n       best[i] = max(best[i], a.best[i]); n       worst[i] = min(worst[i], a.worst[i]); n     } n     return *this; n   } n }; n set<group> positions; n int main() { n   int n, k; n   scanf( %d %d , &n, &k); n   while (n--) { n     vector<int> skills(k, 0); n     for (int i = 0; i < k; i++) scanf( %d , &skills[i]); n     group player = group(skills); n     auto f = positions.lower_bound(player), l = positions.upper_bound(player); n     while (f != l) { n       player += *f; n       f = positions.erase(f); n     } n     positions.insert(f, player); n     printf( %d n , positions.rbegin()->sz); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 1e5 + 10, STAN = (1 << 30) - 1; n struct QJ { n   int l, r, q; n } q[MAXN]; n int n, m; n struct Seg { n   int water[MAXN * 4], sh[MAXN * 4]; n   bool fir[MAXN * 4]; n   Seg() { n     memset(water, 0, sizeof(water)); n     memset(fir, 0, sizeof(fir)); n   } n   int _st, _ed, _x, _t; n   void _insert(int num, int l, int r) { n     if (_st <= l && r <= _ed) { n       water[num] |= _x; n       return; n     } n     int mid = (l + r) >> 1; n     if (_st <= mid) _insert(num << 1, l, mid); n     if (_ed >= mid + 1) _insert(num << 1 | 1, mid + 1, r); n   } n   int _swim(int num, int l, int r, int now) { n     int x; n     now |= water[num]; n     if (l == r) { n       if (!fir[num]) { n         sh[num] = now; n         fir[num] = true; n       } else n         sh[num] &= now; n       return now; n     } n     int mid = (l + r) >> 1; n     if (_t <= mid) n       now = _swim(num << 1, l, mid, now); n     else n       now = _swim(num << 1 | 1, mid + 1, r, now); n     if (!fir[num]) { n       sh[num] = now; n       fir[num] = true; n     } else n       sh[num] &= now; n     return now; n   } n   int _check(int num, int l, int r) { n     if (l == r) return sh[num]; n     if (_st <= l && r <= _ed) return sh[num]; n     int mid = (l + r) >> 1; n     int ans = STAN; n     if (_st <= mid) ans &= _check(num << 1, l, mid); n     if (_ed >= mid + 1) ans &= _check(num << 1 | 1, mid + 1, r); n     return ans; n   } n   inline void Insert(int l, int r, int q) { n     _st = l, _ed = r, _x = q; n     _insert(1, 1, n); n   } n   inline int Swim(int t) { n     _t = t; n     return _swim(1, 1, n, 0); n   } n   inline bool Check(int l, int r, int q) { n     _st = l; n     _ed = r; n     return _check(1, 1, n) == q; n   } n } T; n int a[MAXN]; n int main() { n   scanf( %d%d , &n, &m); n   for (int i = 1; i <= m; i++) { n     scanf( %d%d%d , &q[i].l, &q[i].r, &q[i].q); n     T.Insert(q[i].l, q[i].r, q[i].q); n   } n   for (int i = 1; i <= n; i++) a[i] = T.Swim(i); n   for (int i = 1; i <= m; i++) n     if (!T.Check(q[i].l, q[i].r, q[i].q)) { n       printf( NO n ); n       return 0; n     } n   printf( YES n ); n   for (int i = 1; i <= n; i++) printf( %d  , a[i]); n   printf(  n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n pair<int, int> a[5003]; n vector<int> color[5003]; n int ans[5003]; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int n, k, i, j; n   cin >> n >> k; n   for (i = 0; i < n; i++) { n     cin >> a[i].first; n     a[i].second = i; n   } n   sort(a, a + n); n   for (i = 0; i < n; i++) { n     color[i % k].push_back(a[i].first); n     ans[a[i].second] = (i % k); n   } n   for (i = 0; i < k; i++) { n     for (j = 1; j < color[i].size(); j++) { n       if (color[i][j] == color[i][j - 1]) { n         cout <<  NO ; n         return 0; n       } n     } n   } n   cout <<  YES n ; n   for (i = 0; i < n; i++) { n     cout << (ans[i] + 1) <<    ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void enable_comma() {} n string tostring(char c) { n   string s =   ; n   s += c; n   return s; n } n string tostring(string s) { return     + s +    ; } n string tostring(const char *c) { return tostring((string)c); } n string tostring(long long x) { n   if (x < 0) return  -  + tostring(-x); n   if (x > 9) n     return tostring(x / 10) + tostring(char( 0  + x % 10)); n   else n     return tostring(char( 0  + x)); n } n string tostring(int x) { return tostring((long long)x); } n string tostring(unsigned long long x) { n   if (x > 9) n     return tostring((long long)(x / 10)) + tostring(char( 0  + x % 10)); n   else n     return tostring(char( 0  + x)); n } n string tostring(unsigned x) { return tostring((long long)x); } n string tostring(double x) { n   static char res[114]; n   sprintf(res,  %lf , x); n   string s = tostring(res); n   return s.substr(1, (int)s.size() - 2); n } n string tostring(long double x) { return tostring((double)x); } n template <class A, class B> n string tostring(pair<A, B> p) { n   return  (  + tostring(p.first) +  ,  + tostring(p.second) +  ) ; n } n template <class T> n string tostring(T v) { n   string res =   ; n   for (auto p : v) res += (res.size() ?  ,  :  { ) + tostring(p); n   return res.size() ? res +  }  :  {} ; n } n template <class A> n string tostring(A *a, int L, int R) { n   return tostring(vector<A>(a + L, a + R + 1)); n }; n template <class A> n string tostring(A a, int L, int R) { n   return tostring(a.data(), L, R); n } n string tostrings() { return   ; } n template <typename Head, typename... Tail> n string tostrings(Head H, Tail... T) { n   return tostring(H) +     + tostrings(T...); n } n long long read() { n   long long x = 0, f = 0; n   char ch = getchar(); n   while (!isdigit(ch)) f = ch ==  - , ch = getchar(); n   while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar(); n   return f ? -x : x; n } n template <class T> n void ckmax(T &x, const T y) { n   if (x < y) x = y; n } n template <class T> n void ckmin(T &x, const T y) { n   if (x > y) x = y; n } n const int N = 100005; n struct op { n   int tp; n   long long a, b; n }; n vector<op> res; n int a[60]; n set<long long> S; n long long gao(int tp, long long a, long long b) { n   (!(S.count(a) && S.count(b)) ? cout <<  Assertion failed!  << endl n                                       <<  function:   << __FUNCTION__ << endl n                                       <<  line:   << 149 << endl n                                       <<  expression:   n                                       <<  S.count(a) && S.count(b)  << endl, n    exit(3), 0 : 1); n   res.push_back({tp, a, b}); n   long long res = tp ? a ^ b : a + b; n   S.insert(res); n   (!(0 <= res && res <= 5000000000000000000LL) n    ? cout <<  Assertion failed!  << endl n           <<  function:   << __FUNCTION__ << endl n           <<  line:   << 153 << endl n           <<  expression:   n           <<  0 <= res && res <= 5000000000000000000LL  << endl, n    exit(3), 0 : 1); n   return res; n } n int Log(long long x) { n   int ans = 0; n   while (x > 1) { n     ans++; n     x >>= 1; n   } n   return ans; n } n int main() { n   long long x = read(); n   srand(time(NULL)); n   S.clear(); n   res.clear(); n   S.insert(x); n   while (x > 1) { n     vector<long long> v = {x}; n     while (1) { n       int p = (int)v.size() - 1; n       while (p > 0 && rand() % 5 != 0) p--; n       long long a = v.back(), b = gao(0, a, a), c = gao(0, v[p], b); n       if (Log(b) != Log(c)) { n         v.push_back(c); n         continue; n       } else { n         long long t = b ^ c; n         for (int i = ((int)v.size() - 1); i >= (0); i--) { n           if (Log(t) == Log(v[i] * 2)) t ^= v[i] * 2; n           if (Log(t) == Log(v[i])) t ^= v[i]; n         } n         if (~t & 1) { n           v.push_back(c); n           continue; n         } n         t = gao(1, b, c); n         for (int i = ((int)v.size() - 1); i >= (0); i--) { n           if (Log(t) == Log(v[i] * 2)) t = gao(1, t, v[i] * 2); n           if (Log(t) == Log(v[i])) t = gao(1, t, v[i]); n         } n         (!(Log(t) < Log(x)) ? cout <<  Assertion failed!  << endl n                                    <<  function:   << __FUNCTION__ << endl n                                    <<  line:   << 198 << endl n                                    <<  expression:   n                                    <<  Log(t) < Log(x)  << endl, n          exit(3), 0 : 1); n         x = t; n         break; n       } n     } n   } n   printf( %d n , (int)res.size()); n   for (auto v : res) printf( %I64d %c %I64d n , v.a,  +^ [v.tp], v.b); n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC target( avx2 ) n #pragma GCC optimization( O3 ) n #pragma GCC optimization( unroll-loops ) n using namespace std; n const long long N = 1e5 + 10; n const long double Pie = acos(-1); n signed main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long t; n   cin >> t; n   while (t--) { n     long long n; n     cin >> n; n     long long arr[n]; n     for (long long i = 0; i < n; i++) cin >> arr[i]; n     for (long long i = 0; i < n; i++) { n       if (i % 2 == 0) { n         if (arr[i] >= 0) n           cout << arr[i] <<    ; n         else n           cout << -1 * arr[i] <<    ; n       } else if (i % 2 == 1) { n         if (arr[i] <= 0) n           cout << arr[i] <<    ; n         else n           cout << -1 * arr[i] <<    ; n       } n     } n     cout <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int mod = 1e9 + 7; n const int maxn = 200005; n vector<int> g[maxn]; n int dis[maxn]; n int pa[maxn]; n set<pair<int, int>> st; n void dfs(int now, int pre = 0) { n   if (dis[now] > 2) { n     st.insert({dis[now], now}); n   } n   for (auto &i : g[now]) { n     if (i ^ pre) { n       pa[i] = now; n       dis[i] = dis[now] + 1; n       dfs(i, now); n     } n   } n } n void go() { n   int n; n   cin >> n; n   for (int i = 0; i < n - 1; i++) { n     int x, y; n     cin >> x >> y; n     g[x].push_back(y); n     g[y].push_back(x); n   } n   dfs(1); n   int ans = 0; n   while (st.size()) { n     auto x = *(--st.end()); n     int v = pa[x.second]; n     st.erase({dis[v], v}); n     for (auto &i : g[v]) { n       st.erase({dis[i], i}); n     } n     ans++; n   } n   cout << ans <<   n ; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   int c = 0; n   int t; n   if (!c) { n     t = 1; n   } else { n     cin >> t; n   } n   while (t--) { n     go(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long int newarr[1005]; n long long int dp[1005][1005]; n long long int n, k; n long long int solution(long long int index, long long int m) { n   if (m < 0) m += k; n   if (index >= n && m != 0) n     return 0; n   else if (m == 0) n     return 1; n   else if (dp[index][m] != -1) n     return dp[index][m]; n   else { n     long long int x = solution(index + 1, m); n     long long int y = solution(index + 1, m - newarr[index]); n     if (x > 0) x = 1; n     if (y > 0) y = 1; n     if (m >= newarr[index]) { n       dp[index + 1][m - newarr[index]] = y; n     } n     dp[index + 1][m] = x; n     return x + y; n   } n } n int32_t main() { n   memset(dp, -1, sizeof(dp)); n   cin >> n; n   cin >> k; n   long long int arr[n]; n   long long int ctr = 0; n   for (long long int i = 0; i < n; i++) { n     cin >> arr[i]; n   } n   if (n > k) { n     cout <<  YES n ; n   } else { n     for (long long int i = 0; i < n; i++) { n       newarr[i] = arr[i] % k; n       if (newarr[i] == 0) ctr++; n     } n     long long int x = solution(0, k); n     if (x > 0 || ctr > 0) n       cout <<  YES n ; n     else n       cout <<  NO ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int bas = 23333; n const long long mod = 9999999999973ll; n int N, M, S[26], L[555]; n char C[255][255]; n long long H[26], W[255][255][255], G[555]; n int manacher(int n) { n   int k = 0, m = 0, res = 0; n   memset(L, 0, sizeof(L)); n   for (int i = 1; i <= n; i++) { n     if (G[i] == -1) { n       continue; n     } n     int l = (m > i) ? min(L[2 * k - i], m - i) : 1; n     while (G[i - l] != -1 && G[i + l] != -1 && G[i - l] == G[i + l]) { n       l++; n     } n     if (l + i > m) { n       m = l + i; n       k = i; n     } n     L[i] = l; n     res += l; n   } n   return (res - N - 1) >> 1; n } n int main() { n   scanf( %d%d n , &N, &M); n   long long h = 1; n   for (int i = 0; i < 26; i++) { n     h = h * bas % mod; n     H[i] = h; n   } n   for (int i = 1; i <= N; i++) { n     scanf( %s , C[i] + 1); n     for (int j = 1; j <= M; j++) { n       C[i][j] -=  a ; n       W[i][j][j] = H[C[i][j]]; n       for (int k = j - 1; k > 0; k--) { n         W[i][k][j] = W[i][k + 1][j] + H[C[i][k]]; n         if (W[i][k][j] >= mod) { n           W[i][k][j] -= mod; n         } n       } n       memset(S, 0, sizeof(S)); n       int cnt = 0; n       for (int k = j; k > 0; k--) { n         S[C[i][k]]++; n         if (S[C[i][k]] & 1) { n           cnt++; n         } else { n           cnt--; n         } n         if (cnt > 1) { n           W[i][k][j] = -1; n         } n       } n     } n   } n   long long ANS = 0; n   for (int j = 1; j <= M; j++) { n     for (int k = j; k <= M; k++) { n       memset(G, 0, sizeof(G)); n       G[0] = -1; n       G[(N + 1) << 1] = -1; n       for (int i = 1; i <= N; i++) { n         G[i << 1] = W[i][j][k]; n       } n       ANS += manacher((N << 1) | 1); n     } n   } n   printf( %lld , ANS); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n typedef long long lo; n typedef vector<lo> vl; n typedef vector<lo> vll; n typedef vector<vl> vvl; n template <typename T> n ostream &operator<<(ostream &o, vector<T> v) { n   if (v.size() > 0) o << v[0]; n   for (unsigned i = 1; i < v.size(); i++) o <<     << v[i]; n   return o <<   n ; n } n template <typename U, typename V> n ostream &operator<<(ostream &o, pair<U, V> p) { n   return o <<  (  << p.first <<  ,   << p.second <<  )  ; n } n template <typename T> n istream &operator>>(istream &in, vector<T> &v) { n   for (unsigned i = 0; i < v.size(); i++) in >> v[i]; n   return in; n } n template <typename T> n istream &operator>>(istream &in, pair<T, T> &p) { n   in >> p.first; n   in >> p.second; n   return in; n } n string s; n lo len[203][2]; n lo dp[203][203][203][2]; n lo cal(string &t) { n   for (lo i = t.size(); i > 0; i--) { n     if (s.substr(0, i) == t.substr(t.size() - i, i)) return i; n   } n   return 0; n } n void add(lo &a, lo b) { n   a += b; n   if (a >= 1000000007) a -= 1000000007; n   if (a < 0) a += 1000000007; n } n int main() { n   std::ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   cout.precision(20); n   lo n, ssz; n   cin >> n >> s; n   ssz = s.size(); n   if (s[0] ==  ( ) n     len[0][0] = 1; n   else n     len[0][1] = 1; n   string pref; n   for (lo i = (0); i < (lo)ssz; i++) { n     pref += s[i]; n     pref +=  ( ; n     len[i + 1][0] = cal(pref); n     pref.pop_back(); n     pref +=  ) ; n     len[i + 1][1] = cal(pref); n     pref.pop_back(); n   } n   dp[0][0][0][0] = 1; n   for (lo i = (0); i < (lo)2 * n; i++) { n     for (lo(j) = 0; (j) < (n + 1); (j)++) { n       for (lo(pos) = 0; (pos) < (ssz + 1); (pos)++) { n         for (lo(f) = 0; (f) < (2); (f)++) { n           if (dp[i][j][pos][f] == 0) continue; n           if (j + 1 <= n) n             add(dp[i + 1][j + 1][len[pos][0]][f | (len[pos][0] == ssz)], n                 dp[i][j][pos][f]); n           if (j > 0) n             add(dp[i + 1][j - 1][len[pos][1]][f | (len[pos][1] == ssz)], n                 dp[i][j][pos][f]); n         } n       } n     } n   } n   lo ans = 0; n   for (lo i = (0); i < (lo)ssz + 1; i++) add(ans, dp[2 * n][0][i][1]); n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n inline void checkMax(T& a, const T& b) { n   if (a < b) a = b; n } n template <typename T> n inline void checkMin(T& a, const T& b) { n   if (a > b) a = b; n } n const int kMod = 1000000007; n template <typename U, typename V> n inline void addMod(U& x, const V y) { n   x += y; n   if (x >= kMod) { n     x -= kMod; n   } n } n template <int N> n struct CombinationTable { n   CombinationTable() { init(); } n   static long long table[N + 1][N + 1]; n   static void init() { n     table[0][0] = 1; n     for (int i = 1; i <= N; ++i) { n       table[i][0] = table[i][i] = 1; n       for (int j = 1; j < i; ++j) { n         table[i][j] = table[i - 1][j] + table[i - 1][j - 1]; n       } n     } n   } n }; n template <int N> n long long CombinationTable<N>::table[N + 1][N + 1]; n CombinationTable<40> comb_tbl; n long long n, t; n void go() { n   if ((t & -t) != t) { n     puts( 0 ); n     return; n   } n   ++n; n   int tt = 1; n   while (t >>= 1) ++tt; n   int num_one; n   long long tmp = n; n   do { n     num_one += (tmp & 1); n   } while (tmp >>= 1); n   long long ans = (tt == num_one); n   for (int n___LINE__ = (50), i = 0; i < n___LINE__; ++i) { n     if (n & 1) { n       --num_one; n       if (num_one <= tt && i >= 0 && tt >= num_one && tt - num_one <= i) { n         ans += comb_tbl.table[i][tt - num_one]; n       } n     } n     n >>= 1; n   } n   if (tt == 1) --ans; n   cout << ans << endl; n } n int main() { n   cin >> n >> t; n   go(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename S, typename T> n ostream& operator<<(ostream& out, const pair<S, T> p) { n   out <<  (  << p.first <<  ,  << p.second <<  ) ; n   return out; n } n template <typename T> n ostream& operator<<(ostream& out, const vector<T>& v) { n   for (auto a : v) out << a <<    ; n   return out; n } n template <typename T> n ostream& operator<<(ostream& out, const set<T>& S) { n   for (auto a : S) cout << a <<    ; n   return out; n } n template <typename T> n ostream& operator<<(ostream& out, const multiset<T>& S) { n   for (auto a : S) cout << a <<    ; n   return out; n } n template <typename S, typename T> n ostream& operator<<(ostream& out, const map<S, T>& M) { n   for (auto m : M) cout <<  (  << m.first <<  ->  << m.second <<  )  ; n   return out; n } n template <typename S, typename T> n pair<S, T> operator+(pair<S, T> a, pair<S, T> b) { n   return make_pair(a.first + b.first, a.second + b.second); n } n template <typename S, typename T> n pair<S, T> operator-(pair<S, T> a, pair<S, T> b) { n   return make_pair(a.first - b.first, a.second - b.second); n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   int n; n   cin >> n; n   cout << n + n / 2 << endl; n   return 0; n } n


#include <bits/stdc++.h> n inline long long rd() { n   long long _x = 0; n   int _ch = getchar(), _f = 1; n   for (; !isdigit(_ch) && (_ch !=  - ) && (_ch != EOF); _ch = getchar()) n     ; n   if (_ch ==  - ) { n     _f = 0; n     _ch = getchar(); n   } n   for (; isdigit(_ch); _ch = getchar()) _x = _x * 10 + _ch -  0 ; n   return _f ? _x : -_x; n } n void write(long long _x) { n   if (_x >= 10) n     write(_x / 10), putchar(_x % 10 +  0 ); n   else n     putchar(_x +  0 ); n } n inline void wrt(long long _x, char _p) { n   if (_x < 0) putchar( - ), _x = -_x; n   write(_x); n   if (_p) putchar(_p); n } n int n, m; n char s[1005][1005]; n bool flag1, flag2; n bool vis[1005][1005]; n void dfs(int x, int y) { n   if (vis[x][y] || s[x][y] !=  #  || x == 0 || y == 0 || x == n + 1 || n       y == m + 1) n     return; n   vis[x][y] = 1; n   dfs(x + 1, y), dfs(x, y + 1); n   dfs(x - 1, y), dfs(x, y - 1); n } n int main() { n   n = rd(), m = rd(); n   for (int i = 1; i <= n; i++) { n     scanf( %s , s[i] + 1); n   } n   for (int i = 1; i <= n; i++) { n     bool tag = 0; n     for (int j = 1; j <= m; j++) { n       if (s[i][j] ==  # ) tag = 1; n     } n     flag1 |= !tag; n   } n   for (int i = 1; i <= m; i++) { n     bool tag = 0; n     for (int j = 1; j <= n; j++) { n       if (s[j][i] ==  # ) tag = 1; n     } n     flag2 |= !tag; n   } n   if (((!flag1) && (flag2)) || ((flag1) && (!flag2))) { n     printf( -1 n ); n     return 0; n   } n   bool flag = 0; n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= m; j++) { n       if (s[i][j] ==  # ) { n         int t = j; n         while (s[i][t] ==  # ) t++; n         for (int k = t; k <= m; k++) n           if (s[i][k] ==  # ) flag = 1; n       } n     } n   } n   for (int i = 1; i <= m; i++) { n     for (int j = 1; j <= n; j++) { n       if (s[j][i] ==  # ) { n         int t = j; n         while (s[t][i] ==  # ) t++; n         for (int k = t; k <= n; k++) n           if (s[k][i] ==  # ) flag = 1; n       } n     } n   } n   if (flag) { n     printf( -1 n ); n     return 0; n   } n   int cnt = 0; n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= m; j++) n       if (s[i][j] ==  #  && !vis[i][j]) { n         dfs(i, j); n         cnt++; n       } n   } n   wrt(cnt,   n ); n } n


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


#include <bits/stdc++.h> n using namespace std; n int n, m; n int p[100]; n char mm[100]; n int main() { n   while (scanf( %d , &n) != EOF) { n     scanf( %s , &mm); n     int len = strlen(mm); n     m = 0; n     for (int i = 0; i < len; ++i) m = m * 10 + (mm[i] -  0 ); n     if (n == 0) { n       if (strlen(mm) != 1) n         puts( WRONG_ANSWER ); n       else if (m == 0) n         puts( OK ); n       else n         puts( WRONG_ANSWER ); n     } else { n       if (mm[0] ==  0 ) { n         puts( WRONG_ANSWER ); n         return 0; n       } n       int x = n; n       memset(p, 0, sizeof(p)); n       while (x > 0) { n         p[x % 10]++; n         x /= 10; n       } n       int now = 0; n       for (int i = 1; i <= 9; ++i) n         if (p[i]) { n           now = i; n           p[i]--; n           break; n         } n       for (int i = 0; i <= 9; ++i) { n         while (p[i]) { n           now = now * 10 + i; n           p[i]--; n         } n       } n       if (now == m) n         puts( OK ); n       else n         puts( WRONG_ANSWER ); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MX_N = 3e5 + 5; n const int MX_M = 3e5 + 5; n int N, M, D[MX_N]; n vector<pair<int, int>> al[MX_N]; n int vis[MX_N], sumD; n vector<int> edges; n void dfs(int u, int p = 0, int pe = 0) { n   vis[u] = 1; n   for (auto v : al[u]) n     if (!vis[v.first]) { n       dfs(v.first, u, v.second); n     } n   if (D[u]) edges.push_back(pe), D[p] ^= 1; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cin >> N >> M; n   for (int i = (1); i <= (N); ++i) { n     cin >> D[i]; n     if (D[i] >= 0) sumD += D[i]; n   } n   for (int i = (1); i <= (M); ++i) { n     int U, V; n     cin >> U >> V; n     al[U].emplace_back(V, i); n     al[V].emplace_back(U, i); n   } n   for (int i = (1); i <= (N); ++i) n     if (D[i] == -1) { n       if (sumD & 1) n         D[i] = 1, ++sumD; n       else n         D[i] = 0; n     } n   if (sumD & 1) n     cout << -1; n   else { n     dfs(1); n     cout << ((int)(edges).size()) <<   n ; n     sort(edges.begin(), edges.end()); n     for (int& e : edges) cout << e <<    ; n   } n } n


#include <bits/stdc++.h> n long long RemoveZeros(long long a) { n   long long temp; n   long long x = 0; n   long long i = 10; n   while (a > 0) { n     if (a % 10 != 0) { n       temp = (a % 10) * i; n       x += temp; n       i *= 10; n     } n     a /= 10; n   } n   return x / 10; n } n using namespace std; n int main() { n   long long a, b, c; n   cin >> a >> b; n   c = a + b; n   long long a1 = RemoveZeros(a); n   long long b1 = RemoveZeros(b); n   long long c1 = RemoveZeros(c); n   if (a1 + b1 == c1) n     cout <<  YES ; n   else n     cout <<  NO ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using li = long long; n using ld = long double; n using pii = pair<int, int>; n const int INF = 1e9 + 13; n const int N = 2e5 + 13; n const int M = 1e9 + 7; n const int B = 600; n const int A = 256; n const ld e = 1e-8; n const int LOGN = 20; n mt19937 rnd(time(0)); n void solve() { n   int n, m; n   cin >> n >> m; n   vector<bool> a(n, false); n   for (int i = 0; i < m; i++) { n     int x, y, z; n     cin >> x >> y >> z; n     y--; n     a[y] = true; n   } n   int v = -1; n   for (int i = 0; i < n; i++) n     if (!a[i]) v = i; n   for (int i = 0; i < n; i++) { n     if (i != v) cout << v + 1 <<     << i + 1 <<   n ; n   } n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   int t = 1; n   cin >> t; n   while (t--) solve(); n } n


#include <bits/stdc++.h> n #pragma GCC optimize  03  n using namespace std; n const int N = 1e5 + 5; n const int mod = 1e9 + 7; n const int inf = 1e9 + 9; n pair<int, int> ans[1004]; n signed main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   string s; n   cin >> s; n   int c1 = 0, c2 = 0; n   for (int i = 0; i < s.length(); i++) { n     if (s[i] ==  0 ) { n       if (c1 == 0) { n         c1 = 1; n         ans[i].first = 3, ans[i].second = 1; n       } else { n         c1 = 0; n         ans[i].first = 1, ans[i].second = 1; n       } n     } else { n       if (c2 == 0) { n         c2 = 1; n         ans[i].first = 1, ans[i].second = 3; n       } else { n         c2 = 0; n         ans[i].first = 1, ans[i].second = 1; n       } n     } n   } n   for (int i = 0; i < s.length(); i++) n     cout << ans[i].first <<     << ans[i].second <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n const int MAX_N = 1e5 + 5; n int n, m; n char str[MAX_N], nxt[256]; n bool chk[256], vis[256], not_root[256], flag; n std::vector<char> ans; n void dfs(char c) { n   if (!vis[c]) { n     vis[c] = true; n     ans.push_back(c); n     if (nxt[c]) dfs(nxt[c]); n   } else n     flag = true; n } n int main() { n   scanf( %d , &n); n   while (n--) { n     scanf(  %s , str); n     m = strlen(str); n     for (int i = 0; i < m; ++i) chk[str[i]] = true; n     for (int i = 0; i + 1 < m; ++i) { n       if (nxt[str[i]] == 0) n         nxt[str[i]] = str[i + 1]; n       else if (nxt[str[i]] != str[i + 1]) { n         printf( NO n ); n         return 0; n       } n       not_root[str[i + 1]] = true; n     } n   } n   for (char i =  a ; i <=  z ; ++i) n     if (!not_root[i] && chk[i]) dfs(i); n   for (char i =  a ; i <=  z ; ++i) flag |= chk[i] != vis[i]; n   if (flag) { n     printf( NO n ); n     return 0; n   } n   for (char c : ans) printf( %c , c); n   printf(  n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e6; n int A[5]; n int main() { n   ios_base::sync_with_stdio(0); n   int a, b, n, T, cas = 0; n   cin >> T; n   while (T--) { n     cin >> A[0] >> A[1] >> A[2]; n     int cnt = 0; n     sort(A, A + 3, greater<int>()); n     for (int i = 0; i < 3; ++i) { n       if (A[i]) A[i]--, cnt++; n     } n     if (A[0] && A[1]) A[0]--, A[1]--, cnt++; n     if (A[0] && A[2]) A[0]--, A[2]--, cnt++; n     if (A[1] && A[2]) A[1]--, A[2]--, cnt++; n     if (A[0] && A[1] && A[2]) { n       ++cnt; n     } n     cout << cnt << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct S { n   int a, b; n   S() {} n   S(int _a, int _b) { n     a = _a; n     b = _b; n   } n   const bool operator<(const S &o) const { return a < o.a; } n }; n string exm; n inline void exf(void) { n   cout << exm <<   n ; n   exit(0); n } n template <typename T> n inline void showAll(vector<T> &v, string sep =   ) { n   for (T &here : v) cout << here << sep; n } n template <typename T> n inline void showAll(T arr[], int st, int end, string sep =   ) { n   for (int i = st; i <= end; i++) cout << arr[i] << sep; n } n template <typename T> n inline vector<int> int_seperation(T N, int d = 10) { n   vector<int> v; n   while (N) { n     v.push_back(N % d); n     N /= d; n   } n   reverse(v.begin(), v.end()); n   return v; n } n const int SIZE = 500009; n char s[SIZE], t[SIZE]; n int main() { n   int n, k; n   scanf( %d %d , &n, &k); n   scanf( %s %s , s + 1, t + 1); n   long long INF = 1e18, ans = 0, diff = 0; n   for (int i = 1; i <= n; i++) { n     diff = 2 * diff + (t[i] - s[i]); n     diff = min(diff, INF); n     ans += min(diff + 1, (long long)k); n   } n   printf( %lld n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void qmax(int &x, int y) { n   if (x < y) x = y; n } n void qmin(int &x, int y) { n   if (x > y) x = y; n } n inline long long read() { n   char s; n   long long k = 0, base = 1; n   while ((s = getchar()) !=  -  && s != EOF && !(isdigit(s))) n     ; n   if (s == EOF) exit(0); n   if (s ==  - ) base = -1, s = getchar(); n   while (isdigit(s)) { n     k = k * 10 + (s ^  0 ); n     s = getchar(); n   } n   return k * base; n } n inline void write(int x) { n   static char cnt, num[15]; n   cnt = 0; n   if (!x) { n     printf( 0 ); n     return; n   } n   for (; x; x /= 10) num[++cnt] = x % 10; n   for (; cnt; putchar(num[cnt--] + 48)) n     ; n } n const int maxn = 2020; n int n, k; n char ch[maxn][maxn]; n int a[maxn][maxn], Max; n char d[maxn + maxn]; n bool vis[maxn][maxn]; n int main() { n   n = read(); n   k = read(); n   for (int i = 1; i <= n; i++) { n     scanf( %s , ch[i] + 1); n   } n   if (k >= (2 * n - 1)) { n     for (int i = 1; i <= n + n - 1; i++) putchar( a ); n     return 0; n   } n   memset(a, 0x3f3f, sizeof(a)); n   a[1][1] = 1; n   if (ch[1][1] ==  a ) a[1][1] = 0; n   for (int l = 2; l <= n + n; l++) { n     for (int i = 1, j; i <= n; i++) { n       j = l - i; n       if (j <= 0) break; n       if (j > n) continue; n       if (i > n) continue; n       if (j + 1 <= n) qmin(a[i][j + 1], a[i][j] + (ch[i][j + 1] !=  a )); n       if (i + 1 <= n) qmin(a[i + 1][j], a[i][j] + (ch[i + 1][j] !=  a )); n       if (a[i][j] <= k) Max = max(Max, l); n     } n   } n   if (Max == n + n) { n     for (int i = 1; i <= n + n - 1; i++) putchar( a ); n     return 0; n   } n   bool flag = false; n   if (!Max) Max = 2, vis[1][1] = true, d[2] = ch[1][1], flag = true; n   for (int i = 1, j; i <= n; i++) { n     j = Max - i; n     if (j <= 0) break; n     if (j > n) continue; n     if (a[i][j] <= k) vis[i][j] = true; n   } n   for (int l = Max; l <= n + n; l++) { n     char z =  z ; n     for (int i = 1, j; i <= n; i++) { n       j = l - i; n       if (j <= 0) break; n       if (j > n) continue; n       if (!vis[i][j]) continue; n       if (j + 1 <= n) z = min(z, ch[i][j + 1]); n       if (i + 1 <= n) z = min(z, ch[i + 1][j]); n     } n     d[l + 1] = z; n     for (int i = 1, j; i <= n; i++) { n       j = l - i; n       if (j <= 0) break; n       if (j > n) continue; n       if (!vis[i][j]) continue; n       if (j + 1 <= n && ch[i][j + 1] == z) vis[i][j + 1] = true; n       if (i + 1 <= n && ch[i + 1][j] == z) vis[i + 1][j] = true; n     } n   } n   if (flag) Max--; n   for (int i = 2; i <= Max; i++) d[i] =  a ; n   for (int i = 2; i <= n + n; i++) { n     putchar(d[i]); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long read() { n   long long a = 0; n   char c = getchar(); n   while (c >  9  || c <  0 ) c = getchar(); n   while ( 0  <= c && c <=  9 ) { n     a = a * 10 + c - 48; n     c = getchar(); n   } n   return a; n } n struct data { n   long long x, y, c; n   data(long long X = 0, long long Y = 0, long long C = 0) { n     x = X; n     y = Y; n     c = C; n   } n } w[2005], e[2005]; n long long n, k, L; n bool cmp(data a, data b) { return a.x < b.x; }; n bool cmp2(data a, data b) { return a.y < b.y; } n long long nxt[2005], f[2005]; n multiset<long long> Set[2005]; n long long sum[2005 << 2], Max[2005 << 2], tag[2005 << 2]; n void pushup(long long x) { n   sum[x] = (sum[(x << 1)] + sum[(x << 1 | 1)]) % 1000000007; n   assert(Max[(x << 1)] <= Max[(x << 1 | 1)]); n   Max[x] = Max[(x << 1 | 1)]; n } n void build(long long x, long long l, long long r) { n   tag[x] = 0; n   if (l == r) { n     sum[x] = f[l] * (e[l].y - e[l - 1].y) % 1000000007; n     Max[x] = f[l]; n     return; n   } n   build((x << 1), l, ((l + r) >> 1)); n   build((x << 1 | 1), ((l + r) >> 1) + 1, r); n   pushup(x); n } n void ptag(long long x, long long l, long long r, long long v) { n   assert(Max[x] <= v); n   sum[x] = v * (e[r].y - e[l - 1].y) % 1000000007; n   tag[x] = Max[x] = v; n } n void pushdown(long long x, long long l, long long r) { n   if (tag[x]) { n     ptag((x << 1), l, ((l + r) >> 1), tag[x]); n     ptag((x << 1 | 1), ((l + r) >> 1) + 1, r, tag[x]); n     tag[x] = 0; n   } n } n void chkmax(long long x, long long l, long long r, long long b, long long e, n             long long v) { n   if (r < b || l > e) return; n   if (l == r && Max[x] > v) return; n   if (Max[x] <= v && b <= l && r <= e) { n     ptag(x, l, r, v); n     return; n   } n   bool flag = (v > Max[(x << 1)]); n   pushdown(x, l, r); n   chkmax((x << 1), l, ((l + r) >> 1), b, e, v); n   if (flag) chkmax((x << 1 | 1), ((l + r) >> 1) + 1, r, b, e, v); n   pushup(x); n } n signed main() { n   n = read(); n   k = read(); n   L = read(); n   for (long long i = 1; i <= n; ++i) { n     w[i].x = read() + 1; n     w[i].y = read() + 1; n     w[i].c = read(); n     e[i] = w[i]; n   } n   sort(w + 1, w + 1 + n, cmp); n   sort(e + 1, e + 1 + n, cmp2); n   e[n + 1].y = L + 1; n   w[n + 1].x = w[n + 2].x = L + 1; n   w[n + 1].y = L + 1; n   long long ans = 0; n   for (long long i = n; i; --i) { n     long long tmp = (w[i].x - w[i - 1].x); n     if (!tmp) continue; n     multiset<long long> S; n     S.clear(); n     for (long long i = 1; i <= k; ++i) { n       S.insert(L + 1), nxt[i] = L + 1; n       Set[i].clear(); n       Set[i].insert(L + 1); n       Set[i].insert(0); n     } n     for (long long j = n; j; --j) { n       if (e[j].x >= w[i].x) { n         S.erase(S.find(nxt[e[j].c])); n         nxt[e[j].c] = e[j].y; n         S.insert(nxt[e[j].c]); n         Set[e[j].c].insert(e[j].y); n       } n       f[j] = (*(--S.end())); n     } n     build(1, 1, n); n     for (long long j = n + 1; j > i; --j) { n       if (w[j].c) { n         assert(Set[w[j].c].find(w[j].y) != Set[w[j].c].end()); n         Set[w[j].c].erase(Set[w[j].c].find(w[j].y)); n         multiset<long long>::iterator it = --Set[w[j].c].upper_bound(w[j].y), n                                       ir = it; n         ++ir; n         long long ll = lower_bound(e, e + 1 + n, data(0, *it, 0), cmp2) - e; n         if (ll) assert(e[ll].y != e[ll - 1].y); n         chkmax(1, 1, n, ll + 1, n, *ir); n       } n       long long res = ((L + 1) * e[n].y - sum[1] + 1000000007) % 1000000007; n       ans = n           (ans + (res * tmp % 1000000007 * (w[j].x - w[j - 1].x))) % 1000000007; n     } n   } n   printf( %lld n , ans); n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( O3 ) n #pragma GCC target( sse4 ) n using namespace std; n using ii = pair<int, int>; n using ll = long long; n const int N = 1e5 + 5; n const int mod = 1e9 + 7; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   int a, b; n   cin >> a >> b; n   vector<int> ans1, ans2; n   ll limit = 0; n   for (; limit * (limit + 1) / 2 <= a + b; limit++) n     ; n   cerr << limit <<   n ; n   for (int i = --limit; i >= 1; i--) { n     if (a >= b) n       ans1.push_back(i), a -= i; n     else n       ans2.push_back(i), b -= i; n   } n   cout << ans1.size() <<   n ; n   for (auto x : ans1) cout << x <<    ; n   cout <<   n ; n   cout << ans2.size() <<   n ; n   for (auto x : ans2) cout << x <<    ; n   cout <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e5 + 10; n int t; n int n; n struct node { n   long long id, val; n   bool flag; n   friend bool operator<(node a, node b) { n     if (a.val == b.val) return a.flag == false; n     return a.val > b.val; n   } n }; n int main() { n   while (~scanf( %d , &n)) { n     priority_queue<node> q; n     long long num; n     scanf( %lld , &num); n     node nxt; n     nxt.id = 1, nxt.val = num, nxt.flag = false; n     q.push(nxt); n     long long ans = 0; n     for (int i = 2; i <= n; ++i) { n       scanf( %lld , &num); n       nxt.flag = false; n       if (q.top().val < num) { n         node now = q.top(); n         q.pop(); n         ans = ans + num - now.val; n         if (now.flag) { n           now.flag = false; n           q.push(now); n         } n         nxt.flag = true; n       } n       nxt.id = i; n       nxt.val = num; n       q.push(nxt); n     } n     printf( %lld n , ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int mod = 1e9 + 7, inf = 1061109567; n const long long infll = 4557430888798830399; n const int N = 2e5 + 5; n int n, q, a[N], cnt[N]; n bool last[N], first[N]; n vector<int> app[N]; n bool start[N]; n signed main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   cin >> n >> q; n   for (int i = 0; i < n; i++) cin >> a[i]; n   for (int i = 0; i < n; i++) app[a[i]].push_back(i); n   for (int i = 0; i < N; i++) n     if (app[i].size()) { n       first[app[i][0]] = 1; n       last[app[i].back()] = 1; n     } n   int thing = 0; n   memset(start, 0, sizeof start); n   start[0] = 1; n   for (int i = 0; i < n; i++) { n     if (first[i]) thing++; n     if (last[i]) thing--; n     if (!thing) start[i + 1] = 1; n   } n   int ans = 0; n   int cur = 0; n   while (cur < n) { n     int nxt = n - 1; n     for (int i = cur + 1; i < n; i++) n       if (start[i]) { n         nxt = i - 1; n         break; n       } n     int lolMax = 0; n     for (int i = cur; i < nxt + 1; i++) { n       cnt[a[i]]++; n       lolMax = max(lolMax, cnt[a[i]]); n     } n     ans += lolMax; n     for (int i = cur; i < nxt + 1; i++) cnt[a[i]]--; n     cur = nxt + 1; n   } n   cout << n - ans; n   return 0; n } n


#include <bits/stdc++.h> n const int MAXN = (int)1e5 + 5; n const int MODN = (int)1e9 + 7; n int inf = 0x3f3f3f3f; n using namespace std; n char str[MAXN]; n int num[MAXN]; n int a[MAXN]; n int vis[MAXN]; n int main() { n   int n, m; n   while (scanf( %d , &n) != EOF) { n     memset(vis, 0, sizeof(vis)); n     int sum = 0; n     for (int i = 0; i < n; i++) { n       scanf( %d , &a[i]); n       sum += a[i]; n     } n     int it = sum * 2 / n; n     for (int i = 0; i < n; i++) { n       if (vis[i] == 0) { n         vis[i] = 1; n         printf( %d  , i + 1); n         for (int j = 0; j < n; j++) { n           if (vis[j] == 0 && a[j] + a[i] == it) { n             vis[j] = 1; n             printf( %d n , j + 1); n             break; n           } n         } n       } n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int cntinv(vector<int> &a) { n   int n = a.size(); n   int ans = 0; n   for (int i = 0; i < n; ++i) { n     for (int j = i + 1; j < n; ++j) { n       if (a[j] < a[i]) ans++; n     } n   } n   return ans; n } n int main(int argc, char const *argv[]) { n   int n; n   scanf( %d , &n); n   vector<int> a(n); n   for (int i = 0; i < n; ++i) { n     scanf( %d , &a[i]); n   } n   int pv = (cntinv(a) & 1); n   int m; n   scanf( %d , &m); n   while (m--) { n     int l, r, swaps; n     scanf( %d , &l); n     scanf( %d , &r); n     l--; n     r--; n     swaps = (r - l + 1) >> 1; n     int cur = pv; n     if (swaps & 1) cur = 1 - cur; n     if (cur) n       printf( odd n ); n     else n       printf( even n ); n     pv = cur; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n int a[100010], d[100010]; n int main() { n   int ans = 1, i, j; n   int temp; n   int dlen = 0, mx = 0; n   while (~scanf( %d , &n)) { n     for (i = 0; i != n; ++i) { n       dlen = mx = 0; n       scanf( %d , &temp); n       for (j = 2; j * j <= temp; j++) { n         if (temp % j == 0) { n           d[dlen++] = j; n           if (a[j] + 1 > mx) mx = a[j] + 1; n           while (temp % j == 0) temp /= j; n         } n       } n       if (temp > 1) { n         d[dlen++] = temp; n         if (a[temp] + 1 > mx) mx = a[temp] + 1; n       } n       for (j = 0; j != dlen; j++) a[d[j]] = mx; n       if (ans < mx) ans = mx; n     } n     printf( %d n , ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct UF { n   vector<int> par, sz; n   UF(int n) { n     sz.resize(n); n     par.resize(n); n     for (int i = 0; i < n; i++) sz[i] = 1, par[i] = i; n   } n   int find(int x) { n     if (par[x] == x) return x; n     return par[x] = find(par[x]); n   } n   void unite(int x, int y) { n     x = find(x); n     y = find(y); n     if (x == y) return; n     if (sz[x] > sz[y]) swap(x, y); n     sz[y] += sz[x]; n     par[x] = y; n   } n   bool same(int x, int y) { return find(x) == find(y); } n }; n int main() { n   int i, j, n, m1, m2; n   cin >> n >> m1 >> m2; n   UF uf1(n), uf2(n); n   for (i = 0; i < m1; i++) { n     int a, b; n     cin >> a >> b; n     a--; n     b--; n     uf1.unite(a, b); n   } n   for (i = 0; i < m2; i++) { n     int a, b; n     cin >> a >> b; n     a--; n     b--; n     uf2.unite(a, b); n   } n   vector<pair<int, int>> p; n   for (i = 0; i < n; i++) { n     for (j = 0; j < n; j++) { n       if (!uf1.same(i, j)) p.push_back({i, j}); n     } n   } n   int ans = 0; n   vector<pair<int, int>> ansv; n   for (i = 0; i < p.size(); i++) { n     int x = p[i].first, y = p[i].second; n     if (!uf1.same(x, y) && !uf2.same(x, y)) { n       uf1.unite(x, y); n       uf2.unite(x, y); n       ans++; n       ansv.push_back({x, y}); n     } n   } n   cout << ans << endl; n   for (auto p : ansv) cout << p.first + 1 <<     << p.second + 1 << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = (int)1e6 + 100; n const long long inf = (1ll << 60); n const int mod2 = (int)998244353; n const int mod = (int)1e9 + 7; n int n, m; n vector<long long> b; n vector<long long> c; n void add(long long x) { n   for (int i = 0; i < b.size(); i++) { n     if (c[i] & x) { n       x ^= b[i]; n     } n   } n   if (x > 0) { n     long long y = 1; n     while (!(x & y)) y *= 2; n     for (int i = 0; i < b.size(); i++) { n       if (b[i] & y) { n         b[i] ^= x; n       } n     } n     b.push_back(x); n     c.push_back(y); n   } n } n long long d[maxn]; n int u[maxn]; n vector<pair<long long, long long> > g[maxn]; n vector<int> ord; n void dfs(int v) { n   u[v] = 1; n   ord.push_back(v); n   for (auto to : g[v]) { n     if (u[to.first] == 0) { n       d[to.first] = d[v] ^ to.second; n       dfs(to.first); n     } else if (u[to.first] == 1) { n       add(d[v] ^ d[to.first] ^ to.second); n     } n   } n   u[v] = 2; n } n void solve() { n   cin >> n >> m; n   for (int i = 0; i < m; i++) { n     long long x, y, z; n     cin >> x >> y >> z; n     g[x].push_back({y, z}); n     g[y].push_back({x, z}); n   } n   long long ans = 0; n   for (int i = 1; i <= n; i++) { n     if (u[i]) continue; n     b.clear(); n     c.clear(); n     ord.clear(); n     dfs(i); n     long long sz = ord.size(); n     long long C = sz * (sz - 1) / 2; n     C %= mod; n     for (int j = 1; j < b.size(); j++) C = (C * 2) % mod; n     for (int j = 0; j <= 60; j++) { n       int ok = 0; n       long long cur = (1ll << j); n       for (long long x : b) { n         if (x & cur) { n           ok = 1; n         } n       } n       if (ok) { n         ans = (ans + cur % mod * C % mod) % mod; n       } else { n         long long cnt = 0; n         for (int v : ord) { n           if (d[v] & cur) { n             cnt++; n           } n         } n         long long cur_ans = cnt * (sz - cnt) % mod; n         cur_ans = (cur % mod * cur_ans) % mod; n         for (int j = 0; j < b.size(); j++) { n           cur_ans = (cur_ans * 2) % mod; n         } n         ans += cur_ans; n         ans %= mod; n       } n     } n   } n   cout << ans <<   n ; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int t = 1; n   for (int i = 1; i <= t; i++) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline int read() { n   int X = 0, w = 1; n   char c = getchar(); n   while (c <  0  || c >  9 ) { n     if (c ==  - ) w = -1; n     c = getchar(); n   } n   while (c >=  0  && c <=  9 ) X = X * 10 + c -  0 , c = getchar(); n   return X * w; n } n const int N = 1000 + 10; n int n, m, a[N]; n double f[N][N]; n int main() { n   n = read(), m = read(); n   for (register int i = 1; i <= n; ++i) a[i] = read(); n   for (register int i = 1; i <= n; ++i) n     for (register int j = 1; j <= n; ++j) f[i][j] = (a[i] > a[j]); n   while (m--) { n     int x = read(), y = read(); n     for (register int i = 1; i <= n; ++i) { n       f[x][i] = f[y][i] = (f[x][i] + f[y][i]) / 2; n       f[i][x] = f[i][y] = 1 - f[x][i]; n     } n     f[x][y] = f[y][x] = 0.5; n   } n   double ans = 0; n   for (register int i = 1; i <= n; ++i) n     for (register int j = i + 1; j <= n; ++j) ans += f[i][j]; n   printf( %.9lf n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char orz[500001]; n int gg[500001]; n int t; n int main() { n   cin >> t; n   while (t--) { n     int n, q; n     scanf( %d%d , &n, &q); n     scanf( %s , orz + 1); n     int rrr = 1; n     for (int i = 1; i <= n; i++) { n       if (orz[i] ==  + ) n         gg[i] = gg[i - 1] + 1 * rrr; n       else n         gg[i] = gg[i - 1] - 1 * rrr; n       rrr *= -1; n     } n     while (q--) { n       int l, r; n       scanf( %d%d , &l, &r); n       int eee = abs(gg[r] - gg[l - 1]); n       if (eee != 0) { n         if (eee % 2 == 1) eee = 1; n         if (eee % 2 == 0) eee = 2; n       } n       cout << eee << endl << endl; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n struct debugger { n   template <typename T> n   debugger& operator,(const T& v) { n     cerr << v <<    ; n     return *this; n   } n } dbg; n void solve() { n   int n, m; n   cin >> n >> m; n   for (int i = 0; i < 200; i++) cout <<  9 ; n   cout << endl; n   for (int i = 0; i < 200; i++) cout <<  9 ; n   for (int i = 0; i < 199; i++) cout <<  0 ; n   cout <<  1 ; n } n int main() { n   ios_base::sync_with_stdio(false); n   int t = 1, num = 1; n   while (t--) { n     ; n     ; n     solve(); n     ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long MOD = 1e9 + 7; n vector<vector<long long>> mul(vector<vector<long long>> A, n                               vector<vector<long long>> B) { n   int n = A.size(); n   vector<vector<long long>> res(n, vector<long long>(n)); n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < n; j++) { n       for (int k = 0; k < n; k++) { n         res[i][j] = (res[i][j] + A[i][k] * B[k][j]) % MOD; n       } n     } n   } n   return res; n } n vector<vector<long long>> mexp(vector<vector<long long>> M, long long e) { n   if (e == 1) return M; n   if (e % 2) return mul(M, mexp(M, e - 1)); n   vector<vector<long long>> R = mexp(M, e / 2); n   return mul(R, R); n } n int main() { n   long long n, m; n   cin >> n >> m; n   if (m > n) { n     cout << 1 << endl; n     return 0; n   } n   vector<vector<long long>> M(m, vector<long long>(m)); n   M[0][0] = M[0][m - 1] = 1; n   for (int i = 1; i < m; i++) M[i][i - 1] = 1; n   vector<vector<long long>> R = mexp(M, n - m + 1); n   long long res = 0; n   for (int i = 0; i < m; i++) res = (res + R[0][i]) % MOD; n   cout << res << endl; n } n