#include <bits/stdc++.h> n using namespace std; n const int N = 100100; n const int LOGN = 15; n struct TreeGraph { n   vector<int> *graph; n   vector<int> heights; n   vector<int> *d; n   vector<int> weights; n   vector<int> mapNodes; n   int n, nAritculationPoints; n   ; n   TreeGraph(){}; n   TreeGraph(int nArtiPoints) : nAritculationPoints(nArtiPoints) { n     graph = new vector<int>[N * 2]; n     d = new vector<int>[LOGN]; n   } n   ~TreeGraph() { n     delete[] graph; n     heights.clear(); n     delete[] d; n     weights.clear(); n     mapNodes.clear(); n   } n   void addEdge(int u, int v) { n     if (u >= N * 2) cerr << u; n     if (v >= N * 2) cerr << v; n     graph[u].push_back(v); n     graph[v].push_back(u); n   } n   void print() { n     for (int i = 0; i < n; i++) { n       printf(  n%d:  , i); n       for (auto v : graph[i]) printf( %d  , v); n     } n     printf(  n______ n ); n   } n   void setN(int n, vector<int> mapNodes) { n     this->n = n; n     this->mapNodes = mapNodes; n     heights = vector<int>(n); n     weights = vector<int>(n); n     for (int i = 0; i < LOGN; i++) d[i] = vector<int>(n); n   } n   void preprocess() { dfs(0, -1, 0, 0); } n   int lca(int u, int v) { n     if (heights[v] > heights[u]) swap(u, v); n     int nSteps = heights[u] - heights[v]; n     while (nSteps > 0) { n       int step = log2(nSteps); n       u = d[step][u], nSteps -= 1 << step; n     } n     while (u != v) { n       int i = log2(heights[u]); n       for (; i >= 0; i--) n         if (d[i][u] != d[i][v]) break; n       if (i < 0) n         u = d[0][u], v = d[0][v]; n       else n         u = d[i][u], v = d[i][v]; n     } n     return u; n   } n   int sumPath(int u, int v) { n     int lcaAndU = lca(u, v); n     return weights[u] + weights[v] - 2 * weights[lcaAndU] + n            (lcaAndU >= nAritculationPoints); n   } n   void dfs(int u, int parent, int weight, int height) { n     weight += u < nAritculationPoints ? 0 : 1; n     weights[u] = weight, heights[u] = height; n     d[0][u] = parent; n     for (int i = 1; 1 << i <= height; i++) d[i][u] = d[i - 1][d[i - 1][u]]; n     for (auto v : graph[u]) { n       if (v == parent) continue; n       dfs(v, u, weight, height + 1); n     } n   } n   int solve(int u, int v) { n     u = mapNodes[u], v = mapNodes[v]; n     if (u == v) return 1; n     return sumPath(u, v); n   } n }; n struct GraphSolver { n   vector<int> *graph; n   vector<int> low, ids; n   vector<bool> isArticulationPoint; n   vector<int> stacks; n   vector<vector<int>> comps; n   int n, id; n   GraphSolver(); n   ~GraphSolver() { n     ids.clear(); n     delete[] graph; n     isArticulationPoint.clear(); n     low.clear(); n     stacks.clear(); n   } n   GraphSolver(int n) n       : low(n), ids(n, -1), isArticulationPoint(n, false), id(0), n(n) { n     graph = new vector<int>[n]; n   }; n   void addEdge(int u, int v) { graph[u].push_back(v), graph[v].push_back(u); } n   void dfs(int u, int parent) { n     low[u] = ids[u] = id++; n     stacks.push_back(u); n     int children = 0; n     for (auto v : graph[u]) { n       if (v == parent) continue; n       if (ids[v] != -1) { n         low[u] = min(low[u], ids[v]); n       } else { n         dfs(v, u); n         low[u] = min(low[v], low[u]); n         children++; n         if ((low[v] >= ids[u] && parent != -1) || n             (parent == -1 && children > 1)) { n           isArticulationPoint[u] = true; n           vector<int> comp = vector<int>{u}; n           while (comp.back() != v) { n             comp.push_back(stacks.back()); n             stacks.pop_back(); n           } n           comps.push_back(comp); n         } n       } n     } n   } n   TreeGraph buildBlockCutTree() { n     dfs(0, -1); n     if (!stacks.empty()) { n       vector<int> comp; n       while (!stacks.empty()) { n         comp.push_back(stacks.back()); n         stacks.pop_back(); n       } n       comps.push_back(comp); n     } n     vector<int> mapNodes = vector<int>(n); n     int nNodes = 0; n     for (int i = 0; i < n; i++) n       if (isArticulationPoint[i]) mapNodes[i] = nNodes++; n     auto tree = TreeGraph(nNodes); n     for (auto comp : comps) { n       for (auto v : comp) { n         if (!isArticulationPoint[v]) n           mapNodes[v] = nNodes; n         else n           tree.addEdge(mapNodes[v], nNodes); n       } n       nNodes++; n     } n     tree.setN(nNodes, mapNodes); n     return tree; n   } n }; n int main() { n   int n, m, q; n   scanf( %d %d %d n , &n, &m, &q); n   int u, v; n   GraphSolver *solver = new GraphSolver(n); n   for (int i = 0; i < m; i++) { n     scanf( %d %d n , &u, &v); n     solver->addEdge(u - 1, v - 1); n   } n   auto tree = solver->buildBlockCutTree(); n   delete (solver); n   tree.preprocess(); n   for (int i = 0; i < q; i++) { n     scanf( %d %d n , &u, &v); n     printf( %d n , tree.solve(u - 1, v - 1)); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   scanf( %d , &n); n   vector<int> r(7, 0); n   string den; n   for (int i = 0; i < n; i++) { n     cin >> den; n     for (int j = 0; den[j] !=   0 ; j++) { n       r[j] += den[j] ==  1 ; n     } n   } n   int m = 0; n   for (int i = 0; i < 7; i++) { n     m = max(m, r[i]); n   } n   printf( %d n , m); n   getchar(); n   getchar(); n } n


#include <bits/stdc++.h> n using namespace std; n static const int len = 1000010; n struct event { n   int t, x, y, tip, num; n   event() {} n   event(int _t, int _x, int _y, int _tip, int _num) n       : t(_t), x(_x), y(_y), tip(_tip), num(_num) {} n }; n bool compar(event one, event two) { n   return ((one.x < two.x) || (one.x == two.x && one.tip > two.tip)); n } n int n, m, globans; n int s[len], f[len], t[len]; n int l[len], r[len], b[len], ans[len]; n int tt[len * 4], xx[len * 4], tint[len * 4], xint[len * 4]; n int tnum, xnum; n vector<event> a; n int tree[len * 4], number[len * 4]; n int _count; n inline int findcord(int x) { n   int left = 1, right = xnum; n   while (left < right) { n     int midle = (left + right + 1) / 2; n     if (xx[midle] <= x) n       left = midle; n     else n       right = midle - 1; n   } n   return xint[left]; n } n inline int findtime(int x) { n   int left = 1, right = tnum; n   while (left < right) { n     int midle = (left + right + 1) / 2; n     if (tt[midle] <= x) n       left = midle; n     else n       right = midle - 1; n   } n   return tint[left]; n } n void update(int root, int l, int r, int x0, int len, int num) { n   if (l == r) { n     if (tree[root] < len) { n       tree[root] = len; n       number[root] = num; n     } n     return; n   } n   int m = (l + r) / 2; n   if (x0 <= m) n     update(root * 2, l, m, x0, len, num); n   else n     update(root * 2 + 1, m + 1, r, x0, len, num); n   if (tree[root * 2] > tree[root]) { n     tree[root] = tree[root * 2]; n     number[root] = number[root * 2]; n   } n   if (tree[root * 2 + 1] > tree[root]) { n     tree[root] = tree[root * 2 + 1]; n     number[root] = number[root * 2 + 1]; n   } n } n pair<int, int> _max(pair<int, int> a, pair<int, int> b) { n   if (a.first >= b.first) n     return a; n   else n     return b; n } n pair<int, int> getmax(int root, int l, int r, int L, int R) { n   if (r < l || R < L) return make_pair(0, 0); n   if (l == L && r == R) { n     pair<int, int> t = make_pair(tree[root], number[root]); n     return t; n   } n   int m = (l + r) / 2; n   return _max(getmax(root * 2, l, m, L, min(m, R)), n               getmax(root * 2 + 1, m + 1, r, max(m + 1, L), R)); n } n int findans(int root, int l, int r, int L, int R, int lim) { n   if (r < l || R < L) return -1; n   if (l == r) { n     return number[root]; n   } n   int m = (l + r) / 2; n   pair<int, int> one = getmax(root * 2, l, m, L, min(m, R)); n   pair<int, int> two = getmax(root * 2 + 1, m + 1, r, max(m + 1, L), R); n   if (one.first >= lim) n     return findans(root * 2, l, m, L, min(m, R), lim); n   else if (two.first >= lim) n     return findans(root * 2 + 1, m + 1, r, max(m + 1, L), R, lim); n   else n     return -1; n } n int main() { n   scanf( %d%d , &n, &m); n   xnum = tnum = 0; n   for (int i = (1); (i) <= (n); (i)++) { n     scanf( %d%d%d , &s[i], &f[i], &t[i]); n     tt[++tnum] = t[i]; n     xx[++xnum] = s[i]; n     xx[++xnum] = f[i]; n   } n   for (int i = (1); (i) <= (m); (i)++) { n     scanf( %d%d%d , &l[i], &r[i], &b[i]); n     tt[++tnum] = b[i]; n     xx[++xnum] = l[i]; n     xx[++xnum] = r[i]; n     ans[i] = -1; n   } n   sort(xx + 1, xx + 1 + xnum); n   sort(tt + 1, tt + 1 + tnum); n   xint[1] = 1; n   for (int i = (2); (i) <= (xnum); (i)++) n     xint[i] = xint[i - 1] + int(xx[i] != xx[i - 1]); n   tint[1] = 1; n   for (int i = (2); (i) <= (tnum); (i)++) n     tint[i] = tint[i - 1] + int(tt[i] != tt[i - 1]); n   for (int i = (1); (i) <= (n); (i)++) { n     s[i] = findcord(s[i]); n     f[i] = findcord(f[i]); n     t[i] = findtime(t[i]); n     a.push_back(event(t[i], s[i], f[i], 1, i)); n   } n   for (int i = (1); (i) <= (m); (i)++) { n     l[i] = findcord(l[i]); n     r[i] = findcord(r[i]); n     b[i] = findtime(b[i]); n     a.push_back(event(b[i], l[i], r[i], 0, i)); n   } n   _count = tint[tnum]; n   sort(a.begin(), a.end(), compar); n   for (int i = 0; i < a.size(); i++) { n     if (a[i].tip == 0) { n       int q = findans(1, 1, _count, a[i].t, _count, a[i].y); n       ans[a[i].num] = q; n     } else { n       update(1, 1, _count, a[i].t, a[i].y, a[i].num); n     } n   } n   for (int i = (1); (i) <= (m); (i)++) printf( %d n , ans[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, i, res = 0, j, mid, a[6] = {}, b[6] = {}; n   cin >> n; n   for (i = 0; i < n; i++) { n     cin >> j; n     a[j]++; n   } n   for (i = 0; i < n; i++) { n     cin >> j; n     b[j]++; n   } n   for (i = 1; i < 6; i++) { n     mid = a[i] + b[i]; n     if (mid % 2) { n       cout << -1 << endl; n       return 0; n     } n     res += abs(a[i] - mid / 2); n   } n   cout << res / 2 << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INFint = 2147483647; n const long long INF = 9223372036854775807ll; n const long long MOD = 1000000007ll; n const long double EPS = 1e-9; n int p[1000]; n int a[1000]; n int b[1000]; n int cnt; n void dfs(int v) { n   p[v] = 1; n   for (int i = 1; i <= cnt; i++) { n     if (!p[i]) { n       if ((a[v] > a[i] && a[v] < b[i]) || (b[v] > a[i] && b[v] < b[i])) dfs(i); n     } n   } n } n int main() { n   ios_base::sync_with_stdio(0); n   int n; n   cin >> n; n   for (int i = 0; i < n; i++) { n     int t, x, y; n     cin >> t >> x >> y; n     if (t == 1) { n       cnt++; n       a[cnt] = x; n       b[cnt] = y; n     } else { n       memset(p, 0, sizeof(p)); n       dfs(x); n       if (p[y]) { n         cout <<  YES  << endl; n       } else n         cout <<  NO  << endl; n     } n   } n   fprintf(stderr,   nTIME = %lf n , 1.0 * clock() / CLOCKS_PER_SEC); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n double dp[100002]; n int main() { n   double res = 0, prob = 0; n   int n; n   cin >> n; n   dp[0] = 0; n   for (int i = 0; i < n; i++) { n     double p; n     cin >> p; n     dp[i] = dp[i - 1] * p; n     res = res + p + dp[i] * 2.0; n     dp[i] += p; n   } n   printf( %.7lf n , res); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m; n   cin >> n >> m; n   vector<int> a(n), b(n), c(n); n   for (int i = 0; i < n; i++) cin >> a[i]; n   for (int i = 0; i < n; i++) cin >> b[i]; n   int ans = INT_MAX; n   sort(a.begin(), a.end()); n   sort(b.begin(), b.end()); n   for (int i = 0; i < n; i++) { n     int x = (b[i] - a[0] + m) % m; n     for (int j = 0; j < n; j++) c[j] = (a[j] + x) % m; n     sort(c.begin(), c.end()); n     if (c == b) ans = min(ans, x); n   } n   cout << ans << endl; n } n


#include <bits/stdc++.h> n const int INF = 0x3f3f3f3f; n const long long LINF = 0x3f3f3f3f3f3f3f3fll; n using namespace std; n const double eps = 1e-6; n const long long mod = 1e9 + 7; n const int maxn = 1e5 + 100; n const int maxe = 1e6 + 100; n struct node { n   int to; n   int next; n }; n bool dp[maxn][2], cir; n vector<int> V[maxn]; n int vis[maxn][2]; n int Next[maxn][2], n, m; n inline bool dfs(int x, int s) { n   if (!V[x].size()) return s == 1; n   if (vis[x][s] == 2) return dp[x][s]; n   vis[x][s] = 1; n   bool t = 0; n   for (int i = 0; i < V[x].size(); i++) { n     int v = V[x][i]; n     if (vis[v][s ^ 1] == 1) { n       cir = 1; n       continue; n     } n     if (dfs(v, s ^ 1)) { n       t = 1; n       Next[x][s] = v; n     } n   } n   vis[x][s] = 2; n   return dp[x][s] = t; n } n inline void print(int x, int s) { n   printf( %d  , x); n   if (Next[x][s]) { n     print(Next[x][s], s ^ 1); n   } n } n void Solve() { n   cin >> n >> m; n   int xx, v; n   for (int i = 1; i <= n; i++) { n     cin >> xx; n     for (int j = 0; j < xx; j++) { n       cin >> v; n       V[i].push_back(v); n     } n   } n   int st; n   cin >> st; n   if (dfs(st, 0)) { n     puts( Win ); n     print(st, 0); n   } else if (cir) n     puts( Draw ); n   else n     puts( Lose ); n } n int main() { n   int Case = 1, cases; n   while (Case--) { n     Solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using db = long double; n using pll = pair<long long, long long>; n int32_t main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long t, i, x, j, y, z, k, n; n   long long tt; n   cin >> tt; n   for (long long _tt = 0; _tt < tt; _tt++) { n     cin >> n; n     z = 0; n     while (n != 1) { n       if (n % 6 == 0) n         n /= 6; n       else if ((n * 2) % 6 == 0) n         n *= 2; n       else { n         z = -1; n         break; n       } n       z++; n     } n     cout << z <<   n ; n   } n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:16000000 ) n using namespace std; n const int inf = 0x3f3f3f3f; n const long long inf2 = 0x3f3f3f3f3f3f3f3f; n const double eps = 1e-6; n const int mod = 1000000007; n namespace fastio { n char in[100000]; n int itr = 0, llen = 0; n char get() { n   if (itr == llen) llen = fread(in, 1, 100000, stdin), itr = 0; n   if (llen == 0) return EOF; n   return in[itr++]; n } n char out[100000]; n int itr2 = 0; n void put(char c) { n   out[itr2++] = c; n   if (itr2 == 100000) { n     fwrite(out, 1, 100000, stdout); n     itr2 = 0; n   } n } n int clear() { n   fwrite(out, 1, itr2, stdout); n   itr2 = 0; n   return 0; n } n int getint() { n   int r = 0; n   bool ng = 0; n   char c; n   c = get(); n   while (c !=  -  && (c <  0  || c >  9 )) c = get(); n   if (c ==  - ) ng = 1, c = get(); n   while (c >=  0  && c <=  9 ) r = r * 10 + c -  0 , c = get(); n   return ng ? inf : r; n } n string getstr() { n   string ret =   ; n   char ch = get(); n   while (ch ==     || ch ==   n ) ch = get(); n   while (ch !=     && ch !=   n ) ret.push_back(ch), ch = get(); n   return ret; n } n void putstr(string s) { n   for (int i = 0; i < s.size(); i++) put(s[i]); n } n void putint(int x) { n   if (x == 0) { n     put( 0 ); n     return; n   } n   char c[20]; n   int pos = 0; n   while (x) { n     c[pos++] =  0  + x % 10; n     x /= 10; n   } n   for (int i = pos - 1; i >= 0; i--) put(c[i]); n } n void getarr(int arrname[], int size) { n   for (int i = 0; i < size; i++) arrname[i] = getint(); n } n }  // namespace fastio n using namespace fastio; n int n, m; n bool used[111111 * 5]; n vector<int> g[111111 * 5]; n int deg[111111 * 5]; n vector<pair<int, int> > edges; n vector<int> ans; n void dfs(int x, int par) { n   used[x] = true; n   ans.push_back(x); n   for (auto p : g[x]) { n     deg[p]--; n     if (deg[p] == 0) dfs(p, x); n   } n } n int main() { n   n = getint(); n   m = getint(); n   vector<vector<int> > vec(n, vector<int>(m)); n   for (int i = 0; i < n; i++) n     for (int j = 0; j < m; j++) vec[i][j] = getint(); n   int pre = m; n   for (int i = 0; i < n; i++) { n     bool buff = (i == 0); n     vector<pair<int, int> > V; n     for (int j = 0; j < m; j++) V.push_back(make_pair(vec[i][j], j)); n     sort(V.begin(), V.end()); n     while (V.back().first == inf) V.pop_back(); n     if (!V.size()) continue; n     int pos = 0; n     set<int> Set; n     Set.clear(); n     for (int ii = 0; ii < V.size(); ii++) { n       Set.insert(V[ii].first); n     } n     bool first = true; n     for (set<int>::iterator itr = Set.begin(); itr != Set.end(); itr++) { n       int p = *itr; n       set<int>::iterator itr2 = itr; n       itr2++; n       bool last = itr2 == Set.end(); n       for (int &t = pos; t < V.size() && V[t].first == p; t++) { n         if (!first) n           g[pre].push_back(V[t].second), deg[V[t].second]++, n               cerr << V[t].second << endl; n         if (Set.size() != 1 && !last) n           g[V[t].second].push_back(pre + 1), deg[pre + 1]++, n               cerr << pre << endl; n       } n       if (Set.size() != 1) pre++; n       first = false; n     } n   } n   cerr <<  Start top sort: n ; n   for (int i = 0; i < pre; i++) n     if (!used[i] && !deg[i]) dfs(i, -1); n   vector<int> ans2; n   ans2.clear(); n   for (int i = 0; i < ans.size(); i++) n     if (ans[i] < m) ans2.push_back(ans[i]); n   if (ans2.size() < m) { n     puts( -1 ); n     return 0; n   } else { n     for (int i = 0; i < ans2.size(); i++) putint(ans2[i] + 1), put(   ); n     return clear(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 0x3f3f3f3f; n const long long INFLL = 0x3f3f3f3f3f3f3f3fLL; n inline long long read() { n   long long x = 0, f = 1; n   char ch = getchar(); n   while (ch <  0  || ch >  9 ) { n     if (ch ==  - ) f = -1; n     ch = getchar(); n   } n   while (ch >=  0  && ch <=  9 ) { n     x = x * 10 + ch -  0 ; n     ch = getchar(); n   } n   return x * f; n } n const int maxn = 1e5 + 10; n const int mod = 1e9 + 7; n string s; n int len, match[1005]; n long long dp[1000][1000][3][3]; n void get_match() { n   stack<int> sta; n   for (int i = 0; i < len; i++) { n     if (s[i] ==  ( ) n       sta.push(i); n     else { n       int t = sta.top(); n       sta.pop(); n       match[i] = t; n       match[t] = i; n     } n   } n } n void dfs(int l, int r) { n   if (l + 1 == r) { n     dp[l][r][0][1] = 1; n     dp[l][r][1][0] = 1; n     dp[l][r][0][2] = 1; n     dp[l][r][2][0] = 1; n     return; n   } n   if (match[l] == r) { n     dfs(l + 1, r - 1); n     for (int i = 0; i < 3; i++) n       for (int j = 0; j < 3; j++) { n         if (j != 1) n           dp[l][r][0][1] = (dp[l][r][0][1] + dp[l + 1][r - 1][i][j]) % mod; n         if (i != 1) n           dp[l][r][1][0] = (dp[l][r][1][0] + dp[l + 1][r - 1][i][j]) % mod; n         if (j != 2) n           dp[l][r][0][2] = (dp[l][r][0][2] + dp[l + 1][r - 1][i][j]) % mod; n         if (i != 2) n           dp[l][r][2][0] = (dp[l][r][2][0] + dp[l + 1][r - 1][i][j]) % mod; n       } n     return; n   } else { n     int k = match[l]; n     dfs(l, k); n     dfs(k + 1, r); n     for (int i = 0; i < 3; i++) n       for (int j = 0; j < 3; j++) n         for (int x = 0; x < 3; x++) n           for (int y = 0; y < 3; y++) { n             if ((x == 1 && y == 1) || (x == 2 && y == 2)) continue; n             dp[l][r][i][j] = n                 (dp[l][r][i][j] + dp[l][k][i][x] * dp[k + 1][r][y][j]) % mod; n           } n     return; n   } n } n int main() { n   memset(dp, 0, sizeof(dp)); n   cin >> s; n   len = s.size(); n   get_match(); n   dfs(0, len - 1); n   long long ans = 0; n   for (int i = 0; i < 3; i++) n     for (int j = 0; j < 3; j++) ans = (ans + dp[0][len - 1][i][j]) % mod; n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long dp[5050][505]; n pair<long long, long long> pre[5050][505]; n signed main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long d, s; n   cin >> d >> s; n   queue<pair<long long, long long>> q; n   for (long long i = 1; i < 10; i++) { n     dp[i][i % d] = 1; n     q.push({i, i % d}); n   } n   while (q.size()) { n     pair<long long, long long> curr = q.front(); n     q.pop(); n     long long sum = curr.first; n     long long div = curr.second; n     for (long long i = 0; i <= 9; i++) { n       long long curr_sum = sum + i; n       long long curr_div = (div * 10 + i) % d; n       if (curr_sum <= s and !dp[curr_sum][curr_div]) { n         dp[curr_sum][curr_div] = dp[sum][div] + 1; n         q.push({curr_sum, curr_div}); n         pre[curr_sum][curr_div] = {sum, div}; n       } n     } n   } n   if (!dp[s][0]) { n     cout << -1; n   } else { n     vector<long long> ans; n     long long sum = s, div = 0; n     while (true) { n       if (dp[sum][div] == 1) { n         ans.push_back(sum); n         break; n       } else { n         pair<long long, long long> curr = pre[sum][div]; n         ans.push_back(sum - curr.first); n         sum = curr.first; n         div = curr.second; n       } n     } n     reverse(ans.begin(), ans.end()); n     for (auto x : ans) { n       cout << x; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 1010; n struct Modify { n   bool add; n   int a, b; n }; n int n, m, t; n vector<int> x[MAXN]; n map<int, int> h; n vector<int> s; n vector<Modify> ans; n int losestate[1 << 20]; n int winstate[1 << 20]; n void BuildBase() { n   int out[MAXN]; n   vector<int> y[MAXN]; n   for (int i = 1; i <= n; ++i) { n     out[i] = x[i].size(); n     y[i].clear(); n   } n   for (int i = 1; i <= n; ++i) { n     for (int b : x[i]) y[b].push_back(i); n   } n   queue<int> q; n   for (int i = 1; i <= n; ++i) { n     if (out[i] == 0) { n       q.push(i); n     } n   } n   while (!q.empty() && s.size() < 20) { n     int a = q.front(); n     q.pop(); n     s.push_back(a); n     h[a] = s.size() - 1; n     for (int b : y[a]) { n       --out[b]; n       if (out[b] == 0) q.push(b); n     } n   } n   int z[20][20]; n   memset(z, 0, sizeof(z)); n   for (int i = 0; i < s.size(); ++i) { n     for (int b : x[s[i]]) z[i][h[b]] = true; n   } n   for (int i = 0; i < s.size(); ++i) { n     for (int j = 0; j < s.size(); ++j) { n       if (z[i][j] && i <= j) { n         ans.push_back({false, s[i], s[j]}); n       } n       if (!z[i][j] && i > j) { n         ans.push_back({true, s[i], s[j]}); n       } n     } n   } n   for (int i = 0; i < s.size(); ++i) { n     losestate[1 << i] = s[i]; n   } n } n void ModifyGraph() { n   bool sz[1 << 20]; n   memset(sz, 0, sizeof(sz)); n   sz[0] = true; n   for (int i = 1; i <= n; ++i) { n     if (h.find(i) != h.end()) continue; n     ans.push_back({true, i, i}); n     int state = 0; n     for (int b : x[i]) { n       if (h.find(b) == h.end()) continue; n       state |= (1 << h[b]); n     } n     if (!sz[state]) { n       sz[state] = true; n       winstate[state] = i; n       continue; n     } n     bool finished = false; n     for (int p = 0; p < 20; ++p) { n       int newst = state ^ (1 << p); n       if (sz[newst]) continue; n       finished = true; n       sz[newst] = true; n       winstate[newst] = i; n       if (state & (1 << p)) { n         ans.push_back({false, i, s[p]}); n       } else { n         ans.push_back({true, i, s[p]}); n       } n       if (finished) break; n     } n     if (finished) continue; n     for (int p = 0; p < 20; ++p) { n       for (int q = p + 1; q < 20; ++q) { n         int newst = state ^ (1 << p) ^ (1 << q); n         if (sz[newst]) continue; n         finished = true; n         sz[newst] = true; n         winstate[newst] = i; n         for (int o : {p, q}) { n           if (state & (1 << o)) { n             ans.push_back({false, i, s[o]}); n           } else { n             ans.push_back({true, i, s[o]}); n           } n         } n         if (finished) break; n       } n       if (finished) break; n     } n     if (finished) continue; n     for (int p = 0; p < 20; ++p) { n       for (int q = p + 1; q < 20; ++q) { n         for (int r = q + 1; r < 20; ++r) { n           int newst = state ^ (1 << p) ^ (1 << q) ^ (1 << r); n           if (sz[newst]) continue; n           finished = true; n           sz[newst] = true; n           winstate[newst] = i; n           for (int o : {p, q, r}) { n             if (state & (1 << o)) { n               ans.push_back({false, i, s[o]}); n             } else { n               ans.push_back({true, i, s[o]}); n             } n           } n           if (finished) break; n         } n         if (finished) break; n       } n       if (finished) break; n     } n   } n } n int main() { n   ios::sync_with_stdio(false); n   cin >> n >> m >> t; n   for (int i = 0; i < m; ++i) { n     int a, b; n     cin >> a >> b; n     x[a].push_back(b); n   } n   BuildBase(); n   ModifyGraph(); n   cout << ans.size() << endl; n   for (int i = 0; i < ans.size(); ++i) { n     if (ans[i].add) n       cout <<  +  ; n     else n       cout <<  -  ; n     cout << ans[i].a <<     << ans[i].b << endl; n   } n   cout << flush; n   while (t--) { n     int win = 0, lose = 0, draw = 0; n     for (int i = 0; i < s.size(); ++i) { n       cout <<  ? 1   << s[i] << endl << flush; n       string st; n       cin >> st; n       if (st ==  Win ) { n         win |= (1 << i); n       } else if (st ==  Lose ) { n         lose |= (1 << i); n       } else { n         draw |= (1 << i); n       } n     } n     int ans = 0; n     if (lose > 0) { n       ans = losestate[lose]; n     } else { n       ans = winstate[win]; n     } n     cout <<  !   << ans << endl << flush; n     string st; n     cin >> st; n     if (st !=  Correct ) return 0; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <int MOD, int RT> n struct Mint { n   static const int mod = MOD; n   static constexpr Mint rt() { return RT; } n   int v; n   explicit operator int() const { return v; } n   Mint() { v = 0; } n   Mint(long long _v) { n     v = int((-MOD < _v && _v < MOD) ? _v : _v % MOD); n     if (v < 0) v += MOD; n   } n   friend bool operator==(const Mint& a, const Mint& b) { return a.v == b.v; } n   friend bool operator!=(const Mint& a, const Mint& b) { return !(a == b); } n   friend bool operator<(const Mint& a, const Mint& b) { return a.v < b.v; } n   friend bool operator>(const Mint& a, const Mint& b) { return a.v > b.v; } n   friend bool operator<=(const Mint& a, const Mint& b) { return a.v <= b.v; } n   friend bool operator>=(const Mint& a, const Mint& b) { return a.v >= b.v; } n   friend istream& operator>>(istream& in, Mint& a) { n     long long x; n     cin >> x; n     a = Mint(x); n     return in; n   } n   friend ostream& operator<<(ostream& os, const Mint& a) { return os << a.v; } n   Mint& operator+=(const Mint& m) { n     if ((v += m.v) >= MOD) v -= MOD; n     return *this; n   } n   Mint& operator-=(const Mint& m) { n     if ((v -= m.v) < 0) v += MOD; n     return *this; n   } n   Mint& operator*=(const Mint& m) { n     v = (long long)v * m.v % MOD; n     return *this; n   } n   Mint& operator/=(const Mint& m) { return (*this) *= inv(m); } n   friend Mint pow(Mint a, long long p) { n     Mint ans = 1; n     assert(p >= 0); n     for (; p; p /= 2, a *= a) n       if (p & 1) ans *= a; n     return ans; n   } n   friend Mint inv(const Mint& a) { n     assert(a.v != 0); n     return pow(a, MOD - 2); n   } n   Mint operator-() const { return Mint(-v); } n   Mint& operator++() { return *this += 1; } n   Mint& operator--() { return *this -= 1; } n   friend Mint operator+(Mint a, const Mint& b) { return a += b; } n   friend Mint operator-(Mint a, const Mint& b) { return a -= b; } n   friend Mint operator*(Mint a, const Mint& b) { return a *= b; } n   friend Mint operator/(Mint a, const Mint& b) { return a /= b; } n }; n namespace FFT { n template <class T> n void fft(vector<T>& A, bool inv = 0) { n   int n = (int)A.size(); n   assert((T::mod - 1) % n == 0); n   vector<T> B(n); n   for (int b = n / 2; b; b /= 2, A.swap(B)) { n     T w = pow(T::rt(), (T::mod - 1) / n * b); n     T m = 1; n     for (int i = 0; i < n; i += b * 2, m *= w) n       for (int j = 0; j < b; j++) { n         T u = A[i + j]; n         T v = A[i + j + b] * m; n         B[i / 2 + j] = u + v; n         B[i / 2 + j + n / 2] = u - v; n       } n   } n   if (inv) { n     reverse(1 + A.begin(), A.end()); n     T z = T(1) / T(n); n     for (auto& t : A) t *= z; n   } n } n template <class T> n vector<T> multiply(vector<T> A, vector<T> B) { n   int sa = (int)A.size(); n   int sb = (int)B.size(); n   if (!min(sa, sb)) return {}; n   int s = sa + sb - 1; n   int n = 1; n   for (; n < s; n *= 2) n     ; n   bool eq = A == B; n   A.resize(n); n   fft(A); n   if (eq) n     B = A; n   else n     B.resize(n), fft(B); n   for (int i = 0; i < n; i++) A[i] *= B[i]; n   fft(A, 1); n   A.resize(s); n   return A; n } n template <class T> n vector<T> operator*(const vector<T>& a, const vector<T>& b) { n   auto c = multiply(a, b); n   return c; n } n template <class T> n vector<T> operator+(const vector<T>& a, const vector<T>& b) { n   vector<T> c = a; n   c.resize(max(a.size(), b.size())); n   for (int i = 0; i < b.size(); ++i) { n     c[i] += b[i]; n   } n   return c; n } n template <class M, class T> n vector<M> multiply_mod(vector<T> x, vector<T> y) { n   auto convert = [](const vector<T>& v) { n     vector<M> w((int)v.size()); n     for (int i = 0; i < (int)v.size(); i++) w[i] = (int)v[i]; n     return w; n   }; n   return multiply(convert(x), convert(y)); n } n template <class T> n vector<T> general_multiply(const vector<T>& A, const vector<T>& B) { n   using m0 = Mint<(119 << 23) + 1, 62>; n   using m1 = Mint<(5 << 25) + 1, 62>; n   using m2 = Mint<(7 << 26) + 1, 62>; n   auto c0 = multiply_mod<m0>(A, B); n   auto c1 = multiply_mod<m1>(A, B); n   auto c2 = multiply_mod<m2>(A, B); n   int n = (int)c0.size(); n   vector<T> res(n); n   m1 r01 = 1 / m1(m0::mod); n   m2 r02 = 1 / m2(m0::mod); n   m2 r12 = 1 / m2(m1::mod); n   for (int i = 0; i < n; i++) { n     int a = c0[i].v; n     int b = ((c1[i] - a) * r01).v; n     int c = (((c2[i] - a) * r02 - b) * r12).v; n     res[i] = (T(c) * m1::mod + b) * m0::mod + a; n   } n   return res; n } n }  // namespace FFT n using namespace FFT; n using mi = Mint<998244353, 5>; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(nullptr); n   auto fail = []() { n     cout << 0 <<   n ; n     exit(0); n   }; n   int n; n   cin >> n; n   vector<int> a(n); n   for (int i = 0; i < n; ++i) { n     cin >> a[i]; n   } n   vector<int> blocks; n   while (!a.empty()) { n     int x = a.back(); n     if (a.size() < x) { n       fail(); n     } n     blocks.push_back(x == 1); n     for (int i = 0; i < x; ++i) { n       if (a.back() != x) { n         fail(); n       } n       a.pop_back(); n     } n   } n   reverse(blocks.begin(), blocks.end()); n   int sz = blocks.size(); n   const mi HALF = 1 / mi(2); n   function<vector<vector<mi>>(int, int)> solve = [&](int l, int r) { n     vector<vector<mi>> res(4); n     if (r - l + 1 == 1) { n       res[0] = vector<mi>{1}; n       res[1] = vector<mi>{0, 2}; n       res[2] = vector<mi>{1}; n       if (blocks[l]) { n         res[3] = vector<mi>{0, 1}; n       } else { n         res[3] = vector<mi>{0, 2}; n       } n       return res; n     } n     int m = (l + r) >> 1; n     auto x = solve(l, m); n     auto y = solve(m + 1, r); n     res[0] = x[0] * y[0] + x[1] * y[2]; n     res[1] = x[0] * y[1] + x[1] * y[3]; n     res[2] = x[2] * y[0] + x[3] * y[2]; n     res[3] = x[3] * y[3] + x[2] * y[1]; n     return res; n   }; n   auto res = solve(0, sz - 1)[3]; n   vector<mi> fact(n + 1); n   fact[0] = 1; n   for (int i = 1; i <= n; ++i) { n     fact[i] = fact[i - 1] * i; n   } n   mi ans = 0; n   for (int i = 1; i < res.size(); ++i) { n     ans += res[i] * fact[i] * (i % 2 == res.size() % 2 ? -1 : 1); n   } n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, a, am, duong, zero; n unsigned long long t; n int main() { n   scanf( %d n , &n); n   for (int i = 1; i <= n; i++) { n     scanf( %d , &a); n     if (a < 0) n       am++; n     else if (a > 0) n       duong++; n     else n       zero++; n     t += abs(abs(a) - 1); n   } n   if (am % 2 == 1) { n     if (zero == 0) t += 2; n   } n   printf( %llu , t); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   int sum = 0, a; n   for (int i = 0; i < n; i++) { n     cin >> a; n     sum += a; n   } n   int m; n   cin >> m; n   vector<char> good(1e5 + 1, false); n   int l, r; n   for (int i = 0; i < m; i++) { n     cin >> l >> r; n     for (int j = l; j <= r; j++) { n       good[j] = true; n     } n   } n   for (int i = sum; i <= 1e5; i++) { n     if (good[i]) { n       cout << i << endl; n       return 0; n     } n   } n   cout << -1 << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string a; n   cin >> a; n   int i, flag = 0; n   for (i = 1; i < a.size(); i++) { n     if (a[i] ==  1 ) { n       flag = 1; n       break; n     } n   } n   i = (a.size()) / 2; n   if (flag == 1 && a.size() % 2 == 1) i++; n   cout << i; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n T sqr(T x) { n   return x * x; n } n template <typename T> n T abs(T x) { n   return x < 0 ? -x : x; n } n template <typename T> n T gcd(T a, T b) { n   return b ? gcd(b, a % b) : a; n } n const int MAXN = 8009; n const int MAXX = (int)1e+6 + 7; n struct triple { n   int x, l, r; n   triple(int x = 0, int l = 0, int r = 0) : x(x), l(l), r(r) {} n }; n int s[MAXN]; n vector<triple> v[MAXN]; n int lg[MAXX]; n int upd[MAXX], cnt; n int n, m; n int cpwr[MAXX]; n int count_power(int l, int r) { return lg[r] - lg[l - 1]; } n int main(int argc, char **argv) { n   ios_base::sync_with_stdio(false); n   lg[0] = -1; n   lg[1] = 0; n   for (int i = 2; i < MAXX; ++i) { n     lg[i] = lg[i >> 1] + 1; n   } n   cin >> n >> m; n   s[1] = 1; n   for (int i = 2; i <= n; ++i) { n     s[i] = s[i - 1] + lg[s[i - 1]] + 1; n   } n   while (m--) { n     int t; n     cin >> t; n     if (t == 1) { n       int l, r, x; n       cin >> t >> l >> r >> x; n       v[t].push_back(triple(x, l, r)); n     } else { n       int l, r, ans = 0; n       cin >> t >> l; n       r = l; n       ++cnt; n       for (; t <= n; ++t) { n         for (size_t i = 0; i < v[t].size(); ++i) { n           if (l <= v[t][i].r && v[t][i].l <= r && upd[v[t][i].x] != cnt) { n             upd[v[t][i].x] = cnt; n             ++ans; n           } n         } n         int len = r - l + 1; n         int k = count_power(l, r); n         l += count_power(1, l - 1); n         r = l + len - 1 + k; n       } n       cout << ans <<   n ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n int n; n int sum = 0; n int a[16]; n int mat[4][4]; n int rows[4], cols[4]; n int gotx[4], goty[4], gotd[2]; n int x[16], y[16]; n int diag[2]; n bool dfs(int state, int mask) { n   for (int i = 0; i < 2; i++) { n     if (gotd[i] == n && diag[i] != sum) { n       return false; n     } n   } n   if (state == n * n) return true; n   int row = x[state]; n   int col = y[state]; n   bool d1 = row == col; n   bool d2 = row + col == n - 1; n   for (int i = 0; i < n * n; i++) { n     if ((mask & (1 << i)) != 0 && rows[row] + a[i] <= sum && n         cols[col] + a[i] <= sum && (!d1 || diag[0] + a[i] <= sum) && n         (!d2 || diag[1] + a[i] <= sum)) { n       if (gotx[row] + 1 == n && rows[row] + a[i] < sum) { n         continue; n       } n       if (goty[col] + 1 == n && cols[col] + a[i] < sum) { n         continue; n       } n       gotx[row]++; n       goty[col]++; n       rows[row] += a[i]; n       cols[col] += a[i]; n       if (d1) { n         gotd[0]++; n         diag[0] += a[i]; n       } n       if (d2) { n         gotd[1]++; n         diag[1] += a[i]; n       } n       if (dfs(state + 1, mask ^ (1 << i))) { n         mat[row][col] = a[i]; n         return true; n       } n       gotx[row]--; n       goty[col]--; n       if (d1) { n         gotd[0]--; n         diag[0] -= a[i]; n       } n       if (d2) { n         gotd[1]--; n         diag[1] -= a[i]; n       } n       rows[row] -= a[i]; n       cols[col] -= a[i]; n     } n   } n   return false; n } n int main() { n   std::ios_base::sync_with_stdio(false); n   std::cin.tie(NULL); n   std::cin >> n; n   int mn = 1e9; n   long long ans = 0; n   for (int i = 0; i < n * n; i++) { n     std::cin >> a[i]; n     mn = std::min(mn, a[i]); n     ans += a[i]; n   } n   std::cout << ans / n << std::endl; n   if (n == 1) { n     std::cout << a[0] << std::endl; n     return 0; n   } else if (n == 2) { n     x[0] = 0; n     x[1] = 1; n     x[2] = 0; n     x[3] = 1; n     y[0] = 0; n     y[1] = 1; n     y[2] = 1; n     y[3] = 0; n   } else if (n == 3) { n     x[0] = 0; n     x[1] = 1; n     x[2] = 2; n     x[3] = 0; n     x[4] = 2; n     x[5] = 0; n     x[6] = 1; n     x[7] = 1; n     x[8] = 2; n     y[0] = 0; n     y[1] = 1; n     y[2] = 2; n     y[3] = 2; n     y[4] = 0; n     y[5] = 1; n     y[6] = 0; n     y[7] = 2; n     y[8] = 1; n   } else if (n == 4) { n     int wtfx[] = {0, 1, 2, 3, 0, 1, 2, 3, 0, 0, 1, 1, 2, 2, 3, 3}; n     int wtfy[] = {0, 1, 2, 3, 3, 2, 1, 0, 1, 2, 0, 3, 0, 3, 1, 2}; n     for (int i = 0; i < 16; i++) { n       x[i] = wtfx[i]; n       y[i] = wtfy[i]; n     } n   } n   long long cur = 0; n   for (int i = 0; i < n * n; i++) { n     a[i] -= mn; n     cur += a[i]; n   } n   srand(time(0)); n   std::random_shuffle(a, a + n * n); n   sum = cur / n; n   dfs(0, (1 << (n * n)) - 1); n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < n; j++) { n       std::cout << mat[i][j] + mn << (j + 1 == n ?   n  :    ); n     } n   } n } n


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


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long n; n   cin >> n; n   vector<long long> a(n), b(n); n   for (long long i = 0; i < n; ++i) cin >> a[i]; n   for (long long i = 0; i < n; ++i) cin >> b[i]; n   map<long long, vector<long long> > mp; n   long long m; n   cin >> m; n   for (long long i = 0; i < n; ++i) { n     mp[a[i]].push_back(i + 1); n     mp[b[i]].push_back(i + 1); n   } n   long long ans = 1; n   for (auto it = mp.begin(); it != mp.end(); ++it) { n     long long den = 0; n     long long num = it->second.size(); n     sort(it->second.begin(), it->second.end()); n     for (long long i = 1; i < (it->second.size()); ++i) { n       if ((it->second[i]) == (it->second[i - 1])) den++; n     } n     long long nn = 1; n     for (long long i = num; i > 0; --i) { n       if (i & 1 || den == 0) n         nn *= i; n       else { n         nn *= (i / 2); n         den--; n       } n       if (nn > m) nn %= m; n     } n     ans *= nn; n     if (ans > m) ans %= m; n   } n   cout << ans % m; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int t, n, doc[100010], doc1[100010], p[100010]; n vector<vector<int> > g; n vector<pair<int, pair<int, int> > > q; n vector<int> tin, tout; n int par(int u) { n   if (p[u] == u) return u; n   return p[u] = par(p[u]); n } n void dfs(int u) { n   tin[u] = t; n   for (int i = 0; i < g[u].size(); i++) n     if (tin[g[u][i]] == -1) { n       t++; n       dfs(g[u][i]); n     } n   tout[u] = ++t; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int m, d = 0; n   cin >> n >> m; n   g.resize(n); n   tin.resize(n, -1); n   tout.resize(n); n   for (int i = 0; i < n; i++) p[i] = i; n   for (int i = 0; i < m; i++) { n     int type, x, y; n     cin >> type; n     if (type == 1) { n       cin >> x >> y; n       x--; n       y--; n       p[x] = y; n       g[y].push_back(x); n     } else if (type == 2) { n       cin >> x; n       x--; n       doc1[d] = par(x); n       doc[d++] = x; n     } else { n       cin >> x >> y; n       x--; n       y--; n       int a = 0; n       if (par(x) == par(doc[y])) a = 1; n       q.push_back(make_pair(a, make_pair(x, y))); n     } n   } n   t = 0; n   for (int i = 0; i < n; i++) n     if (p[i] == i) dfs(i); n   for (int i = 0; i < q.size(); i++) { n     if (q[i].first == 0) { n       cout <<  NO n ; n       continue; n     } n     int u = q[i].second.first, v = doc[q[i].second.second], n         x = doc1[q[i].second.second]; n     if (tin[u] <= tin[v] && tout[u] >= tout[v] && tin[x] <= tin[u] && n         tout[x] >= tout[u]) n       cout <<  YES n ; n     else n       cout <<  NO n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   unsigned long long int counter = 0, a, b, t; n   cin >> a >> b; n   while (true) { n     if (b > a) { n       t = a; n       a = b; n       b = t; n     } n     counter = counter + (a / b); n     a = (a % b); n     if (a == 0) break; n   } n   cout << counter; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1000; n int ans[N], l[N], r[N]; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n   int n; n   cin >> n; n   for (int i = 0; i < n; ++i) { n     cin >> l[i]; n   } n   for (int i = 0; i < n; ++i) { n     cin >> r[i]; n   } n   for (int k = n; k > 0; --k) { n     for (int i = 0; i < n; ++i) { n       if (l[i] == 0 && r[i] == 0 && ans[i] == 0) { n         ans[i] = k; n       } n     } n     int prefix = 0; n     for (int i = 0; i < n; ++i) { n       if (ans[i] == k) { n         ++prefix; n       } else if (ans[i] == 0) { n         l[i] -= prefix; n       } n     } n     int suffix = 0; n     for (int i = n - 1; i >= 0; --i) { n       if (ans[i] == k) { n         ++suffix; n       } else if (ans[i] == 0) { n         r[i] -= suffix; n       } n     } n   } n   if (count(ans, ans + n, 0) == 0) { n     cout <<  YES n ; n     for (int i = 0; i < n; ++i) { n       cout << ans[i] <<    ; n     } n     cout <<   n ; n   } else { n     cout <<  NO n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n bool boy[1000], girl[1000]; n int n, m, b, g, x, y, q[1000][2], h, t; n int main() { n   memset(boy, false, sizeof(boy)); n   scanf( %d%d%d , &n, &m, &b); n   for (int i = 1; i <= b; i++) { n     scanf( %d , &x); n     boy[x] = true; n   } n   memset(girl, false, sizeof(girl)); n   scanf( %d , &g); n   for (int i = 1; i <= g; i++) { n     scanf( %d , &y); n     girl[y] = true; n   } n   h = t = 0; n   for (int i = 0; i < n; i++) n     if (boy[i]) { n       t++; n       q[t][1] = 0; n       q[t][2] = i; n     } n   for (int i = 0; i < m; i++) n     if (girl[i]) { n       t++; n       q[t][1] = 1; n       q[t][2] = i; n     } n   while (h < t) { n     h++; n     if (q[h][1]) { n       int u = q[h][2] % n; n       for (int i = 1; i <= n; i++) { n         if (!boy[u]) { n           boy[u] = true; n           t++; n           q[t][1] = 0; n           q[t][2] = u; n         } n         u = (u + m) % n; n       } n     } else { n       int u = q[h][2] % m; n       for (int i = 1; i <= m; i++) { n         if (!girl[u]) { n           girl[u] = true; n           t++; n           q[t][1] = 1; n           q[t][2] = u; n         } n         u = (u + n) % m; n       } n     } n   } n   if (t == n + m) n     puts( Yes ); n   else n     puts( No ); n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n int n; n string a; n constexpr char t[4] = { A ,  C ,  T ,  G }; n int best = INT_MAX; n int main() { n   cin >> n; n   cin >> a; n   for (int i = 0; i < n - 3; ++i) { n     int cur = 0; n     for (int j = 0; j < 4; ++j) { n       int temp = min(abs(t[j] - a[i + j]), abs(t[j] + 26 - a[i + j])); n       temp = min(temp, abs(t[j] - a[i + j] - 26)); n       cur += temp; n     } n     best = min(best, cur); n   } n   cout << best; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n void prn(T first) { n   cout << first <<   n ; n } n int main() { n   int a[4]; n   cin >> a[0] >> a[1] >> a[2] >> a[3]; n   sort(a, a + 4); n   if (a[0] + a[3] == a[1] + a[2] || a[3] == a[0] + a[1] + a[2]) { n     cout <<  YES ; n   } else { n     cout <<  NO ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long n, h, v[1100]; n   multiset<long long> s; n   cin >> n >> h; n   for (int i = 0; i < n; i++) cin >> v[i]; n   long long k, ht; n   for (int i = 0; i < n; i++) { n     s.insert(v[i]); n     k = 0; n     ht = 0; n     for (multiset<long long>::reverse_iterator rit = s.rbegin(); n          rit != s.rend(); ++rit) { n       if (k % 2 == 0) ht += *rit; n       k++; n     } n     if (ht > h) { n       cout << i <<   n ; n       return 0; n     } n   } n   cout << n <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n string s; n pair<int, int> st[3000002]; n void build(int v, int l, int r) { n   if (l == r) { n     st[v] = make_pair(s[l] ==  ( , s[l] ==  ) ); n     return; n   } n   int lv, rv, mid; n   lv = 2 * v; n   rv = 2 * v + 1; n   mid = (l + r) / 2; n   build(lv, l, mid); n   build(rv, mid + 1, r); n   st[v].first = st[rv].first + max(0, st[lv].first - st[rv].second); n   st[v].second = st[lv].second + max(0, st[rv].second - st[lv].first); n } n pair<int, int> query(int v, int l, int r, int L, int R) { n   if (r < L || R < l) return make_pair(0, 0); n   if (L <= l && r <= R) return st[v]; n   pair<int, int> L1 = query(2 * v, l, (l + r) / 2, L, R); n   pair<int, int> R1 = query(2 * v + 1, (l + r) / 2 + 1, r, L, R); n   return make_pair(R1.first + max(0, L1.first - R1.second), n                    L1.second + max(0, R1.second - L1.first)); n } n int main() { n   cin >> s; n   int n = s.length(); n   build(1, 0, n - 1); n   int m; n   cin >> m; n   for (int i = 0; i < m; ++i) { n     int l, r; n     cin >> l >> r; n     l--; n     r--; n     pair<int, int> q = query(1, 0, n - 1, l, r); n     cout << r - l + 1 - (q.first + q.second) <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long double k, d, t, g, c, p, ilec, ilep, cp, zos; n long long dzielup(long long x, long long y) { n   if (x % y == 0) return x / y; n   return x / y + 1; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(NULL); n   cout.tie(NULL); n   cin >> k >> d >> t; n   cout.precision(10); n   g = dzielup(k, d); n   c = g * d; n   p = k + (c - k) / 2; n   ilep = floor(t / p); n   cp = ilep * p; n   zos = t - cp; n   if (zos <= k) { n     cout << fixed << ilep * c + zos <<   n ; n   } else { n     zos -= k; n     cout << fixed << ilep * c + k + 2 * zos <<   n ; n   } n   return 0; n } n


#include <iostream> n using namespace std; n  n const int MOD = 1e9+7, N = 1e5+5; n  n long long inv(long long a) { n     long long b = 1; n     int k = MOD-2; n     while(k) { n         if(k%2) b = b * a % MOD; n         a = a * a % MOD; n         k /= 2; n     } n     return b; n } n  n long long fact[N], ifact[N]; n  n long long binom(long long x, long long y) { n     if(x < 0 || y < 0 || x < y) return 0; n     return fact[x] * ifact[x-y] % MOD * ifact[y] % MOD; n } n  n int t, n, k; n  n int main() { n     ios_base::sync_with_stdio(false); cin.tie(0); n     fact[0] = ifact[0] = 1; n     for (int i = 1; i < N; i++) fact[i] = fact[i-1] * i % MOD; n     ifact[N-1] = inv(fact[N-1]); n     for (int i = N-2; 0 < i; i--) ifact[i] = ifact[i+1] * (i+1) % MOD; n     cin >> t; n     while(t--) { n         cin >> n >> k; n         long long sol = 0; n         for (long long l = 1; l <= n; l++) sol = (sol + binom(n-(l-1)*(k-1), l) * fact[l] % MOD * fact[n-l]) % MOD; n         sol = (sol + fact[n]) * ifact[n] % MOD; n         cout << sol <<   n ; n     } n     return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void debug_out() { cerr << endl; } n template <class T> n ostream& prnt(ostream& out, T v) { n   out << v.size() <<   n ; n   for (auto e : v) out << e <<    ; n   return out; n } n template <class T> n ostream& operator<<(ostream& out, vector<T> v) { n   return prnt(out, v); n } n template <class T> n ostream& operator<<(ostream& out, set<T> v) { n   return prnt(out, v); n } n template <class T1, class T2> n ostream& operator<<(ostream& out, map<T1, T2> v) { n   return prnt(out, v); n } n template <class T1, class T2> n ostream& operator<<(ostream& out, pair<T1, T2> p) { n   return out <<  (  << p.first <<     << p.second <<  ) ; n } n template <typename Head, typename... Tail> n void debug_out(Head H, Tail... T) { n   cerr <<     << H; n   debug_out(T...); n } n const int N = 1001; n const int MOD = 998244353; n int n, dp[2][N], a[N], k, f[100100], r[N]; n int solve(int x) { n   for (int i = 1; i <= n; i++) { n     int j = upper_bound(a + 1, a + n + 1, a[i] - x) - a; n     j--; n     r[i] = j; n   } n   for (int j = 1; j <= k; j++) { n     for (int i = 1; i <= n; i++) n       if (j == 1) n         dp[1][i] = 1; n       else n         dp[j % 2][i] = dp[1 - j % 2][r[i]]; n     for (int i = 2; i <= n; i++) n       dp[j % 2][i] += dp[j % 2][i - 1], dp[j % 2][i] %= MOD; n   } n   return dp[k % 2][n]; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin >> n >> k; n   for (int i = 1; i <= n; i++) cin >> a[i]; n   sort(a + 1, a + n + 1); n   int mx = a[n] / (k - 1) + 1; n   for (int x = 0; x <= mx; x++) f[x] = solve(x); n   long long ans = 0; n   for (int x = 0; x < mx; x++) { n     f[x] -= f[x + 1]; n     if (f[x] < 0) f[x] += MOD; n     ans += (1LL * x * f[x]) % MOD; n     ans %= MOD; n   } n   cout << ans <<   n ; 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(int N, int pos) { return (bool)(N & (1 << pos)); } n inline int addmod(int x, int y) { n   return (x % 1000000007 + y % 1000000007) % 1000000007; n } n inline int submod(int x, int y) { n   return (x % 1000000007 - y % 1000000007 + 1000000007) % 1000000007; n } n inline int mulmod(int x, int y) { n   return (x % 1000000007 * 1LL * y % 1000000007) % 1000000007; n } n inline int nextSubMask(int i, int mask) { return (i - 1) & mask; } n template <typename T> n void we_r_done(T mssg) { n   cout << mssg; n   exit(0); n } n vector<char> chick; n string s[102]; n int n, m, c; n int row, col; n bool vis[111][111]; n void fixrc(int i, int j) { n   row = i; n   col = j; n } n char who; n void fun(int i, int j, int baki) { n   if (s[i][j] ==  R  && baki == 0) { n     fixrc(i, j); n     return; n   } n   baki -= (s[i][j] ==  R ); n   s[i][j] = who; n   vis[i][j] = true; n   if (j && vis[i][j - 1] == false) { n     fun(i, j - 1, baki); n   } else if ((j + 1) < m && vis[i][j + 1] == false) { n     fun(i, j + 1, baki); n   } else if (i) n     fun(i - 1, j, baki); n } n int main() { n   for (char i =  0 ; i <=  9 ; i++) chick.push_back(i); n   for (char i =  A ; i <=  Z ; i++) chick.push_back(i); n   for (char i =  a ; i <=  z ; i++) chick.push_back(i); n   int t; n   cin >> t; n   while (t--) { n     cin >> n >> m >> c; n     int tot = 0; n     for (int i = 0; i < n; i++) { n       cin >> s[i]; n       for (int j = 0; j < m; j++) { n         tot += (s[i][j] ==  R ); n         vis[i][j] = false; n       } n     } n     row = n - 1; n     col = m - 1; n     char last; n     for (int i = 0; i < c; i++) { n       who = chick[i]; n       int cc = c - i; n       cc = tot / cc + (tot % cc != 0); n       tot -= cc; n       fun(row, col, cc); n     } n     for (int i = 0; i < n; i++) { n       for (int j = 0; j < m; j++) { n         cout << s[i][j]; n       } n       cout << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int t, zero, cur; n long long ans; n string s; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   cin >> t; n   while (t--) { n     cin >> s; n     ans = zero = 0; n     for (int i = 0; i < s.size(); i++) { n       if (s[i] ==  0 ) { n         if (i == 0 || s[i - 1] ==  1 ) { n           zero = 1; n         } else { n           zero++; n         } n       } else { n         cur = 0; n         if (i == 0 || s[i - 1] ==  1 ) { n           zero = 0; n         } n         int b = min(i + 18, (int)s.size()); n         for (int j = i; j < b; j++) { n           cur = cur * 2 + (s[j] -  0 ); n           if ((j - i + 1) + min(zero, cur - (j - i + 1)) == cur) { n             ans++; n           } n         } n       } n     } n     cout << ans <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   std::ios::sync_with_stdio(false); n   int n; n   cin >> n; n   string sign[n]; n   long long x[n]; n   char ans[n]; n   long long low = -2e9, up = 2e9; n   for (int i = 0; i < n; i++) { n     cin >> sign[i] >> x[i] >> ans[i]; n     if (sign[i] ==  >= ) { n       if (ans[i] ==  Y ) n         low = max(low, x[i]); n       else n         up = min(x[i] - 1, up); n     } else if (sign[i] ==  > ) { n       if (ans[i] ==  Y ) n         low = max(low, x[i] + 1); n       else n         up = min(x[i], up); n     } else if (sign[i] ==  <= ) { n       if (ans[i] ==  Y ) n         up = min(x[i], up); n       else n         low = max(low, x[i] + 1); n     } else { n       if (ans[i] ==  Y ) n         up = min(x[i] - 1, up); n       else n         low = max(low, x[i]); n     } n   } n   if (low > up) n     cout <<  Impossible ; n   else n     cout << low; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, l, r; n int main() { n   scanf( %d%d , &n, &m); n   for (int i = 0; i < m; i++) { n     scanf( %d%d , &l, &r); n   } n   for (int i = 0; i < n; i++) { n     if (i & 1) n       printf( 0 ); n     else n       printf( 1 ); n   } n   puts(  ); n } n


#include <bits/stdc++.h> n using namespace std; n int fir[200010], to[200010 << 1], nxt[200010 << 1], cnt; n long long f[200010], fac[200010]; n void add(int u, int v) { n   nxt[++cnt] = fir[u]; n   fir[u] = cnt; n   to[cnt] = v; n } n void dfs(int x, int fa) { n   f[x] = 1; n   int i, s = (x != 1); n   for (i = fir[x]; i; i = nxt[i]) n     if (to[i] != fa) { n       dfs(to[i], x); n       f[x] *= f[to[i]]; n       f[x] %= 998244353; n       s++; n     } n   f[x] *= fac[s]; n   f[x] %= 998244353; n } n int main() { n   int n, i, u, v; n   cin >> n; n   fac[0] = 1; n   for (i = 1; i <= n; i++) fac[i] = fac[i - 1] * i % 998244353; n   for (i = 1; i < n; i++) scanf( %d%d , &u, &v), add(u, v), add(v, u); n   dfs(1, 0); n   cout << f[1] * n % 998244353; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int a[1000]; n   int n; n   cin >> n; n   for (int i = 0; i < n; i++) cin >> a[i]; n   sort(a, a + n); n   int res = 0; n   int sum = 10; n   int ress = 0; n   for (int i = 0; i < n; i++) { n     sum += a[i]; n     if (sum <= 720) { n       res++; n       if (sum > 360) { n         ress += sum - 360; n       } n     } n   } n   cout << res <<     << ress; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int M = (119 << 23) + 1; n int add(int a, int b) { return (a += b) < M ? a : a - M; } n int sub(int a, int b) { return (a -= b) < 0 ? a + M : a; } n int mul(int a, int b) { return 1LL * a * b % M; } n int mod_pow(int a, int b) { n   int res = 1; n   while (b) { n     if (b % 2) { n       res = mul(res, a); n     } n     a = mul(a, a); n     b /= 2; n   } n   return res; n } n int mod_inv(int a) { return mod_pow(a, M - 2); } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   int n; n   cin >> n; n   vector<int> a(n); n   for (auto& i : a) { n     cin >> i; n   } n   sort(a.rbegin(), a.rend()); n   for (int i = 1; i < n; ++i) { n     a[i] = add(a[i], a[i - 1]); n   } n   for (int k = 1; k <= n; ++k) { n     int ans = 0; n     for (int i = 0; i < n; i += k) { n       int sum = a[min(i + k - 1, n - 1)]; n       sum = sub(sum, i ? a[i - 1] : 0); n       ans = add(ans, mul(i / k, sum)); n     } n     ans = mul(ans, mod_inv(n)); n     cout << ans <<    ; n   } n   cout <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n inline long long read(void) { n   long long x = 0, f = 1; n   char ch = getchar(); n   while (ch <  0  || ch >  9 ) { n     if (ch ==  - ) f = -1; n     ch = getchar(); n   } n   while (ch >=  0  && ch <=  9 ) { n     x = x * 10 + ch -  0 ; n     ch = getchar(); n   } n   return f * x; n } n int n; n int main() { n   n = read(); n   int l = 0, r = 1000000000; n   cout << 1 <<     << 0 << endl; n   fflush(stdout); n   char ch[10]; n   scanf( %s , ch + 1); n   bool flag = false; n   if (ch[1] ==  b ) { n     flag = true; n   } n   for (register int i = 1; i < n; ++i) { n     int mid = (l + r + 1) >> 1; n     cout << 1 <<     << mid << endl; n     fflush(stdout); n     scanf( %s , ch + 1); n     if (flag) { n       ch[1] = (ch[1] ==  w ) ?  b  :  w ; n     } n     if (ch[1] ==  w ) { n       l = mid; n     } else { n       r = mid; n     } n   } n   printf( 0 %d 2 %d , l, l + 1); n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   std::ios::sync_with_stdio(false); n   std::string name; n   std::cin >> name; n   bool atFlag = false; n   std::string result =   ; n   result += name[0]; n   for (int i = 1; i < name.length(); i++) { n     if (!atFlag && name.substr(i, 2) ==  at ) { n       result +=  @ ; n       ++i; n       atFlag = true; n     } else if (i + 3 < name.length() && name.substr(i, 3) ==  dot ) { n       result +=  . ; n       i += 2; n     } else { n       result += name[i]; n     } n   } n   std::cout << result; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, mm, s, it; n int a[200005], r[200005], so[200005], ne[200005]; n bool u[200005]; n string ss, na[200005]; n vector<int> v[200005]; n queue<int> q; n map<string, int> m; n inline string sb(string v) { n   for (int i = 0; i < v.size(); i++) n     if (v[i] <  a ) v[i] += 32; n   return v; n } n inline void ope(string &x) { n   x = sb(x); n   if (m[x]) return; n   m[x] = ++s; n   for (int i = 0; i < x.size(); i++) r[s] += (x[i] ==  r ); n   na[s] = x; n   so[s] = s; n   return; n } n inline bool cmp(int x, int y) { n   if (r[x] != r[y]) return r[x] < r[y]; n   return na[x].size() < na[y].size(); n } n inline bool same(int x, int y) { n   return r[x] == r[y] && na[x].size() == na[y].size(); n } n inline void dfs(int x, int y) { n   if (u[x]) return; n   u[x] = 1; n   ne[x] = y; n   for (int i = 0; i < v[x].size(); i++) dfs(v[x][i], y); n } n int main() { n   cin >> n; n   for (int i = 1; i <= n; i++) { n     cin >> ss; n     ope(ss); n     a[i] = m[ss]; n   } n   m[  ] = 200002; n   r[200002] = 2147483640; n   cin >> mm; n   for (int i = 1; i <= mm; i++) { n     string p, q; n     cin >> p >> q; n     ope(p); n     ope(q); n     v[m[q]].push_back(m[p]); n   } n   sort(so + 1, so + s + 1, cmp); n   for (int i = 1; i <= s; i++) dfs(so[i], so[i]); n   long long rr = 0, ll = 0; n   for (int i = 1; i <= n; i++) rr += r[ne[a[i]]], ll += na[ne[a[i]]].size(); n   cout << rr <<     << ll << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxN(1e3 + 10); n int N, M, P[maxN], A[maxN][maxN], C; n void dfs(const int u) { n   C++; n   for (int v = 1; v <= N; v++) n     if (A[u][v] && !P[v]) { n       P[v] = u; n       dfs(v); n     } n } n int main() { n   cin >> N >> M; n   if (M != N - 1) { n     cout <<  no ; n     return 0; n   } n   for (int i = 0; i < M; i++) { n     int u, v; n     cin >> u >> v; n     A[u][v] = A[v][u] = 1; n   } n   P[1] = -1; n   dfs(1); n   cout << (C == N ?  yes  :  no ); n } n


#include <bits/stdc++.h> n using namespace std; n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   long long a, x, y; n   cin >> a >> x >> y; n   if (y % a == 0) n     cout << -1; n   else { n     long long ratio = (long long)(y / a); n     if (ratio > 0) { n       if (((long long)(y / a)) % 2 == 1) { n         if (2 * abs(x) < a) n           cout << 2 * ratio - (long long)(ratio / 2); n         else n           cout << -1; n       } else { n         if (x != 0 && abs(x) < a && x < 0) n           cout << 2 * ratio - (ratio / 2); n         else if (x != 0 && abs(x) < a && x > 0) n           cout << 2 * ratio - (ratio / 2) + 1; n         else n           cout << -1; n       } n     } else if (2 * abs(x) < a) n       cout << 1; n     else n       cout << -1; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int tmp; n string s; n char a[3][10] = {{ q ,  w ,  e ,  r ,  t ,  y ,  u ,  i ,  o ,  p }, n                  { a ,  s ,  d ,  f ,  g ,  h ,  j ,  k ,  l ,  ; }, n                  { z ,  x ,  c ,  v ,  b ,  n ,  m ,  , ,  . ,  / }}; n char Tinh(char c) { n   for (int i = 0; i < 3; i++) n     for (int j = 0; j < 10; j++) n       if (a[i][j] == c) return a[i][j + tmp]; n } n int main() { n   char ss; n   cin >> ss; n   if (ss ==  R ) n     tmp = -1; n   else n     tmp = 1; n   cin >> s; n   string res =   ; n   for (int i = 0; i < s.length(); i++) { n     res += Tinh(s[i]); n   } n   cout << res; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 5e4 + 100; n int n, k; n struct node { n   int sz; n   int mn[15], mx[15]; n   void init(int a) { n     sz = 0; n     for (int i = 1; i <= k; i++) { n       mx[i] = mn[i] = a; n     } n   } n   void unit(node a) { n     sz += a.sz; n     for (int i = 1; i <= k; i++) { n       mn[i] = min(mn[i], a.mn[i]); n       mx[i] = max(mx[i], a.mx[i]); n     } n   } n   bool operator<(const node& p) const { n     for (int i = 1; i <= k; i++) { n       if (mx[i] > p.mn[i]) return false; n     } n     return true; n   } n }; n set<node> s; n vector<set<node>::iterator> del; n int main() { n   scanf( %d %d , &n, &k); n   node now; n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= k; j++) scanf( %d , &now.mn[j]), now.mx[j] = now.mn[j]; n     now.sz = 1; n     set<node>::iterator l, r, iter; n     r = s.upper_bound(now); n     l = s.lower_bound(now); n     for (iter = l; iter != r; iter++) { n       now.unit(*iter); n       del.push_back(iter); n     } n     for (int j = 0; j < del.size(); j++) { n       s.erase(del[j]); n     } n     del.clear(); n     s.insert(now); n     iter = s.end(); n     iter--; n     printf( %d n , iter->sz); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int TESTS = 1; n   while (TESTS--) { n     int n; n     cin >> n; n     int a[n], f[1005] = {0}; n     for (int i = 0; i < n; i++) { n       cin >> a[i]; n       f[a[i]]++; n     } n     int h = 0, t = 0; n     for (int i = 0; i < 1005; i++) { n       if (f[i]) t++; n       h = max(h, f[i]); n     } n     cout << h <<     << t; n   } n   return 0; n } n


#include <bits/stdc++.h> n const int S = 200003; n int n, m, h[S], nx[S], v[S], eg = 1, s[S], e[S], _ = 0, t[S], fa[S], dep[S], n                              f[S], rk[S], root, a[S]; n inline void egadd(int uu, int vv) { n   nx[++eg] = h[uu]; n   h[uu] = eg; n   v[eg] = vv; n } n void dfs_1(int x) { n   s[x] = 1; n   for (int i = h[x]; i; i = nx[i]) n     if (v[i] != fa[x]) { n       fa[v[i]] = x; n       dep[v[i]] = dep[x] + 1; n       dfs_1(v[i]); n       s[x] += s[v[i]]; n       if (s[e[x]] < s[v[i]]) e[x] = v[i]; n     } n } n void dfs_2(int x, int top) { n   f[x] = ++_; n   rk[_] = x; n   t[x] = top; n   if (!e[x]) return; n   dfs_2(e[x], top); n   for (int i = h[x]; i; i = nx[i]) n     if (v[i] != fa[x] && v[i] != e[x]) dfs_2(v[i], v[i]); n } n long long sg[S << 2], add[S << 2]; n inline void down(int w, int l, int r) { n   if (add[w]) { n     int mid = (l + r) >> 1; n     add[(w << 1)] += add[w]; n     add[(w << 1) | 1] += add[w]; n     sg[(w << 1)] += add[w] * (mid - l + 1); n     sg[(w << 1) | 1] += add[w] * (r - mid); n     add[w] = 0; n   } n } n inline void sgadd(int l, int r, int ll, int rr, int k, int w) { n   if (ll <= l && r <= rr) { n     sg[w] += 1ll * (r - l + 1) * k; n     add[w] += k; n     return; n   } n   int mid = (l + r) >> 1; n   down(w, l, r); n   if (ll <= mid) sgadd(l, mid, ll, rr, k, (w << 1)); n   if (rr > mid) sgadd(mid + 1, r, ll, rr, k, (w << 1) | 1); n   sg[w] = sg[(w << 1)] + sg[(w << 1) | 1]; n } n inline void sgb(int l, int r, int w) { n   if (l == r) { n     sg[w] = a[rk[l]]; n     return; n   } n   int mid = (l + r) >> 1; n   sgb(l, mid, (w << 1)); n   sgb(mid + 1, r, (w << 1) | 1); n   sg[w] = sg[(w << 1)] + sg[(w << 1) | 1]; n } n inline long long sgcal(int l, int r, int ll, int rr, int w) { n   if (ll <= l && r <= rr) return sg[w]; n   int mid = (l + r) >> 1; n   down(w, l, r); n   long long ret = 0; n   if (ll <= mid) ret += sgcal(l, mid, ll, rr, (w << 1)); n   if (rr > mid) ret += sgcal(mid + 1, r, ll, rr, (w << 1) | 1); n   return ret; n } n inline int hang(int x, int y) { n   while (true) { n     if (fa[t[y]] == x) return t[y]; n     if (f[t[y]] <= f[x] && f[x] <= f[y]) return e[x]; n     y = fa[t[y]]; n   } n } n inline int lca(int x, int y) { n   while (t[x] != t[y]) { n     if (dep[t[x]] < dep[t[y]]) x ^= y ^= x ^= y; n     x = fa[t[x]]; n   } n   if (x == y) return x; n   if (dep[x] > dep[y]) n     return y; n   else n     return x; n } n int main() { n   scanf( %d%d , &n, &m); n   for (int i = 1; i <= n; i++) scanf( %d , a + i); n   for (int i = 1; i < n; i++) { n     int uu, vv; n     scanf( %d%d , &uu, &vv); n     egadd(uu, vv); n     egadd(vv, uu); n   } n   root = 1; n   dfs_1(1); n   dfs_2(1, 1); n   sgb(1, n, 1); n   int o, x, y, z; n   while (m--) { n     scanf( %d%d , &o, &x); n     if (o == 1) n       root = x; n     else if (o == 2) { n       scanf( %d%d , &y, &z); n       int o1, o2, o3; n       o1 = lca(x, y); n       if (o1 != root && (f[o1] <= f[root] && f[root] <= f[o1] + s[o1] - 1)) { n         o2 = lca(x, root); n         o3 = lca(y, root); n         if (dep[o1] < dep[o2]) o1 = o2; n         if (dep[o1] < dep[o3]) o1 = o3; n         if (o1 == root) n           sgadd(1, n, 1, n, z, 1); n         else { n           o2 = hang(o1, root); n           sgadd(1, n, 1, n, z, 1); n           sgadd(1, n, f[o2], f[o2] + s[o2] - 1, -z, 1); n         } n       } else if (o1 == root) n         sgadd(1, n, 1, n, z, 1); n       else n         sgadd(1, n, f[o1], f[o1] + s[o1] - 1, z, 1); n     } else { n       if (x != root && (f[x] <= f[root] && f[root] <= f[x] + s[x] - 1)) { n         int o = hang(x, root); n         printf( %lld n , n                sgcal(1, n, 1, n, 1) - sgcal(1, n, f[o], f[o] + s[o] - 1, 1)); n       } else if (x == root) n         printf( %lld n , sgcal(1, n, 1, n, 1)); n       else n         printf( %lld n , sgcal(1, n, f[x], f[x] + s[x] - 1, 1)); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, k; n string s; n pair<int, int> fff(const string &s, char x) { n   pair<int, int> res; n   int cc = 0; n   for (int i = 0; i < s.length(); i++) n     if (s[i] == x) cc++; n   if (cc >= k) { n     res.first = 0; n     res.second = 0; n     return res; n   } n   int cost = 0; n   for (int i = 1; i <= 9; i++) n     for (int j = 0; j < s.length(); j++) n       if (abs(s[j] - x) == i) { n         cc++; n         cost += abs(s[j] - x); n         if (cc == k) { n           res.first = cost; n           res.second = i; n           return res; n         } n       } n } n string change(string s, char x, int d) { n   int cc = 0; n   for (int i = 0; i < s.length(); i++) n     if (abs(s[i] - x) < d) { n       cc++; n       s[i] = x; n     } n   if (cc == k) return s; n   for (int i = 0; i < s.length(); i++) n     if (s[i] - x == d) { n       s[i] = x; n       cc++; n       if (cc == k) return s; n     } n   for (int i = s.length(); i-- > 0;) n     if (x - s[i] == d) { n       s[i] = x; n       cc++; n       if (cc == k) return s; n     } n } n const string &min(const string &s, const string &t) { n   if (s > t) return t; n   return s; n } n int main() { n   scanf( %d%d , &n, &k); n   cin >> s; n   int cost = 1000000000; n   string res =   ; n   for (char x =  0 ; x <=  9 ; x++) { n     pair<int, int> a = fff(s, x); n     if (cost > a.first) { n       cost = a.first; n       res = change(s, x, a.second); n     } else if (cost == a.first) n       res = min(res, change(s, x, a.second)); n   } n   cout << cost << endl << res; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n template <typename T> n using v = vector<T>; n const ll K = 1000; n const ll N = 1e5; n const ll B = N / K + 1; n ll n; n ll arr[N + 1]; n ll cnt[N + 1]; n ll bin[B + 1]; n ll greedy(ll k) { n   fill(begin(cnt), end(cnt), 0); n   v<ll> dif; n   ll bits = 0; n   for (ll i = 1; i <= n; i++) { n     ll val = arr[i]; n     if (cnt[val] == 0) { n       if ((ll)dif.size() == k) { n         for (const auto& color : dif) { n           cnt[color] = 0; n         } n         dif.clear(); n         bits++; n       } n       dif.push_back(val); n     } n     cnt[val]++; n   } n   if (dif.size() > 0) { n     bits++; n   } n   return bits; n } n int main(int argc, char const* argv[]) { n   ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); n   cin >> n; n   for (ll i = 0; i < n; i++) { n     cin >> arr[i + 1]; n   } n   v<ll> resarr(n + 1, -1); n   for (ll k = 1; k <= min(K, n); k++) { n     resarr[k] = greedy(k); n   } n   fill(begin(bin), end(bin), 1); n   for (ll b = 1; b <= B; b++) { n     ll lo = 1; n     ll hi = (b > 1) ? bin[b - 1] : n; n     while (lo != hi) { n       ll mid = (lo + hi) / 2; n       ll curbits = greedy(mid); n       if (curbits <= b) { n         hi = mid; n       } else { n         lo = mid + 1; n       } n     } n     bin[b] = lo; n   } n   for (ll k = K + 1; k <= n; k++) { n     ll lo = 1; n     ll hi = resarr[k - 1]; n     while (lo != hi) { n       ll mid = (lo + hi) / 2; n       if (bin[mid] <= k) { n         hi = mid; n       } else { n         lo = mid + 1; n       } n     } n     resarr[k] = lo; n   } n   for (ll i = 1; i <= n; i++) { n     cout << resarr[i] <<    ; n   } n   cout <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double eps = 1e-8; n const long long mod = 1e9 + 7; n const int inf = 1 << 30; n const int maxn = 600500; n const double EPS = 1e-7; n void solve() { n   int q; n   scanf( %d , &q); n   while (q--) { n     long long n; n     scanf( %lld , &n); n     int a, b; n     scanf( %d%d , &a, &b); n     if (b < 2LL * a) { n       printf( %lld n , (n / 2LL) * 1LL * b + a * (n % 2)); n     } else n       printf( %lld n , a * 1LL * n); n   } n } n int main() { n   int tc = 1; n   for (int tt = 0; tt < (int)(tc); ++tt) { n     solve(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n void print_array(T arr[], int size_arr) { n   for (int i = (0); i < (size_arr); i++) { n     cout << arr[i]; n     if (i == size_arr - 1) n       cout << endl; n     else n       cout <<    ; n   } n } n template <typename T> n void print_vector(vector<T> v) { n   for (int i = (0); i < (v.size()); i++) { n     cout << v[i]; n     if (i == v.size() - 1) n       cout << endl; n     else n       cout <<    ; n   } n } n template <typename T> n void memset_array(T arr[], T value, int size_arr) { n   for (int i = (0); i < (size_arr); i++) { n     arr[i] = value; n   } n } n bool compare_lexical_string(string a, string b) { n   for (int i = (0); i < (min(a.length(), b.length())); i++) { n     if (a[i] != b[i]) return a[i] < b[i]; n   } n   return a.length() < b.length(); n } n struct lex_string { n   bool operator()(string a, string b) { return compare_lexical_string(a, b); } n }; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   long long b, d, s; n   cin >> b >> d >> s; n   long long max_num, min_num; n   max_num = max(b, max(d, s)); n   min_num = min(b, min(d, s)); n   if (max_num == min_num) n     cout << 0 << endl; n   else { n     if (max_num == b) { n       long long count = 0; n       if (d < b) count += b - 1 - d; n       if (s < b) count += b - 1 - s; n       cout << count << endl; n     } else if (max_num == d) { n       if (d == s) n         cout << d - 1 - b << endl; n       else { n         cout << 2 * d - 2 - b - s << endl; n       } n     } else { n       cout << s - 1 - b + s - 1 - d << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MOD = 1000000007; n const double EPS = 1e-8; n const double PI = 2 * acos(0); n const int MAXN = 2006; n struct Node { n   int x, y; n   bool operator<(Node b) const { n     if (x != b.x) return x < b.x; n     return y < b.y; n   } n }; n struct Math { n   int n; n   int MOD; n   int SMALL_N; n   long long *r; n   long long *fac, *ifac; n   long long **A, **C; n   long long *twop, *iv_twop; n   Math() { n     n = -1; n     MOD = 1; n     SMALL_N = 3030; n   } n   void prepare(int n_, int MOD_) { n     n = n_; n     MOD = MOD_; n     r = new long long[n + 1]; n     r[1] = 1; n     for (int i = 2; i <= n; ++i) n       r[i] = (MOD - (MOD / i) * r[MOD % i] % MOD) % MOD; n     fac = new long long[n + 1]; n     fac[0] = 1; n     for (int i = 1; i <= n; ++i) fac[i] = fac[i - 1] * i % MOD; n     ifac = new long long[n + 1]; n     ifac[0] = ifac[1] = 1; n     for (int i = 2; i <= n; ++i) ifac[i] = ifac[i - 1] * r[i] % MOD; n     twop = new long long[n + 1]; n     iv_twop = new long long[n + 1]; n     twop[0] = iv_twop[0] = 1; n     twop[1] = 2; n     iv_twop[1] = (MOD + 1) / 2; n     for (int i = 2; i <= n; ++i) { n       twop[i] = twop[i - 1] * 2 % MOD; n       iv_twop[i] = iv_twop[i - 1] * iv_twop[1] % MOD; n     } n     if (n <= SMALL_N) { n       A = new long long *[n + 1]; n       for (int i = 0; i <= n; ++i) A[i] = new long long[n + 1]; n       memset(A, 0, sizeof(A)); n       for (int i = 0; i <= n; ++i) A[i][0] = 1; n       for (int i = 1; i <= n; ++i) n         for (int j = 1; j <= i; ++j) A[i][j] = A[i][j - 1] * (i - j + 1) % MOD; n     } n     if (n <= SMALL_N) { n       C = new long long *[n + 1]; n       for (int i = 0; i <= n; ++i) C[i] = new long long[n + 1]; n       memset(C, 0, sizeof(C)); n       for (int i = 0; i <= n; ++i) C[i][0] = C[i][i] = 1; n       for (int i = 1; i <= n; ++i) n         for (int j = 1; j < i; ++j) n           C[i][j] = (C[i][j - 1] + C[i - 1][j - 1]) % MOD; n     } n   } n   long long getA(int n_, int k_) { n     if (k_ < 0 || n_ < 0) return 0; n     if (n_ <= n && n <= SMALL_N) return A[n_][k_]; n     return fac[n_] * ifac[n_ - k_] % MOD; n   } n   long long getC(int n_, int k_) { n     if (k_ < 0 || n_ < 0) return 0; n     if (n_ <= n && n <= SMALL_N) return C[n_][k_]; n     return fac[n_] * ifac[n_ - k_] % MOD * ifac[k_] % MOD; n   } n }; n int n, m, k; n Node node[MAXN]; n long long dp[MAXN]; n Math toan; n bool input() { n   int u, v, x, y; n   cin >> n >> m >> k; n   for (int i = 1; i <= k; ++i) cin >> node[i].x >> node[i].y; n   return !cin.fail(); n } n void clear_input() { k = 0; } n void preprocess() { n   sort(node + 1, node + k + 1); n   toan.prepare(200005, MOD); n } n void process(int itest) { n   int u, v, x, y; n   node[k + 1].x = n, node[k + 1].y = m; n   for (int i = 1; i <= k + 1; ++i) { n     x = node[i].x; n     y = node[i].y; n     dp[i] = toan.getC(x + y - 2, x - 1); n     for (int j = 1; j < i; ++j) n       if (node[j].x <= x && node[j].y <= y) n         dp[i] = ((dp[i] - dp[j] * toan.getC(x - node[j].x + y - node[j].y, n                                             x - node[j].x)) % n                      MOD + n                  MOD) % n                 MOD; n   } n   cout << dp[k + 1] << endl; n } n void oneTest() { n   while (input()) { n     preprocess(); n     process(0); n     clear_input(); n   } n } n void multiTest() { n   int t; n   cin >> t; n   for (int it = 1; it <= t; ++it) { n     input(); n     preprocess(); n     process(it); n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   oneTest(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   cin >> t; n   while (t--) { n     int x = 0, y = 0, z = 0; n     int ar[4]; n     for (int i = 0; i < 4; i++) { n       cin >> ar[i]; n     } n     x = ar[1]; n     y = ar[2]; n     z = ar[2]; n     cout << x <<     << y <<     << z << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n const int N = (int)3e5 + 2; n int n; n bool a[N << 1]; n int ans, ansl, ansr; n inline long long read() { n   long long x = 0; n   char ch = getchar(); n   for (; ch >  9  || ch <  0 ; ch = getchar()) n     ; n   for (; ch >=  0  && ch <=  9 ; ch = getchar()) n     x = (x << 1) + (x << 3) + (ch ^ 48); n   return x; n } n int main() { n   n = read(); n   int cnt = 0, mn = 0, pos = -1; n   for (int i = 0; i < n; ++i) { n     char ch = getchar(); n     if (ch ==  ( ) n       ++cnt; n     else n       a[i] = a[i + n] = 1, --cnt; n     if (mn > cnt) n       mn = cnt, pos = i, ans = 1; n     else if (mn == cnt) n       ++ans; n   } n   if (cnt) { n     printf( 0 n1 1 ); n     return 0; n   } n   int I = n + ++pos, num[2] = {0, 0}, l[2], tmp = ans; n   for (int i = pos; i < I; ++i) { n     if (!a[i]) { n       ++cnt; n       if (cnt == 1) n         ++num[0], l[0] = i; n       else if (cnt == 2) n         ++num[1], l[1] = i; n     } else { n       --cnt; n       if (!cnt) { n         if (num[0] > ans) { n           ans = num[0]; n           ansl = l[0]; n           ansr = i; n         } n         num[0] = 0; n       } else if (cnt == 1) { n         if (tmp + num[1] > ans) { n           ans = tmp + num[1]; n           ansl = l[1]; n           ansr = i; n         } n         ++num[0]; n         num[1] = 0; n       } else if (cnt == 2) n         ++num[1]; n     } n   } n   printf( %d n%d %d , ans, ansl % n + 1, ansr % n + 1); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename A> n ostream &operator<<(ostream &cout, vector<A> const &v); n template <typename A, typename B> n ostream &operator<<(ostream &cout, pair<A, B> const &p) { n   return cout <<  (  << p.first <<  ,   << p.second <<  ) ; n } n template <typename A> n ostream &operator<<(ostream &cout, vector<A> const &v) { n   cout <<  [ ; n   for (int i = 0; i < v.size(); i++) { n     if (i) cout <<  ,  ; n     cout << v[i]; n   } n   return cout <<  ] ; n } n template <typename A, typename B> n istream &operator>>(istream &cin, pair<A, B> &p) { n   cin >> p.first; n   return cin >> p.second; n } n mt19937_64 rng(61378913); n void usaco(string filename) { n   freopen((filename +  .in ).c_str(),  r , stdin); n   freopen((filename +  .out ).c_str(),  w , stdout); n } n const long double pi = 3.14159265358979323846; n long long n, m, k, q, l, r, x, y, z; n const long long template_array_size = 1e6 + 8432; n long long a[template_array_size]; n long long b[template_array_size]; n long long c[template_array_size]; n string second, t; n long long ans = 0; n void solve(int tc = 0) { n   bool dead[10] = {0}; n   long long v = 0; n   cin >> n; n   for (long long i = 0; i < n; i++) { n     char c; n     cin >> c >> x; n     if (c ==  | ) { n       for (long long j = 0; j < 10; j++) { n         if (x & (1 << j)) dead[j] = 1; n       } n       v |= x; n     } else if (c ==  & ) { n       for (long long j = 0; j < 10; j++) { n         if (!(x & (1 << j))) dead[j] = 1; n       } n       v &= x; n     } else { n       v ^= x; n     } n   } n   long long ov = 0; n   for (long long i = 0; i < 10; i++) { n     if (!dead[i]) ov += (1 << i); n   } n   cout << 2 <<   n ; n   cout <<  &   << ov <<   n ; n   cout <<  ^   << v <<   n ; n } n int main() { n   { ios_base::sync_with_stdio(false); } n   { cin.tie(NULL); } n   cout << setprecision(12) << fixed; n   int tc = 1; n   for (int t = 0; t < tc; t++) solve(t); n } n


#include <bits/stdc++.h> n using namespace std; n int n, maxim, a; n int main() { n   cin >> n; n   for (int i = 1; i <= n; i++) { n     cin >> a; n     if (a > maxim) maxim = a; n   } n   cout << (maxim ^ a); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   int a, b, t; n   cin >> t; n   int arr[t]; n   for (int i = 0; i < t; i++) { n     cin >> a >> b; n     arr[i] = a + b; n   } n   for (int i = 0; i < t; i++) { n     cout << arr[i] << endl; n   } n } n


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


#include <iostream> n #include <vector> n  n using namespace std; n  n const int MAXN = 2e5 + 5; n  n struct Info n { n     int maxPref, maxSuff; n  n     Info(){} n     Info(int x) : maxPref(x), maxSuff(x) {} n     Info(int maxPref, int maxSuff) n     { n         this->maxPref = maxPref; n         this->maxSuff = maxSuff; n     } n  n     void modifyPref(int x) n     { n         maxPref += x; n     } n     void modifySuff(int x) n     { n         maxSuff += x; n     } n }; n  n Info operator +(const Info A, const Info B) n { n     return Info(max(A.maxPref, B.maxPref), max(A.maxSuff, B.maxSuff)); n } n  n struct SegmentTree n { n     Info x; n     int lazyPref, lazySuff; n  n     int l, r; n     SegmentTree *L, *R; n  n     SegmentTree() : L(nullptr), R(nullptr), lazyPref(0), lazySuff(0) {} n     SegmentTree(int l, int r) : SegmentTree() n     { n         this->l = l; n         this->r = r; n     } n  n     void build(int val, int n) n     { n         if(l==r) n         { n             x = Info((l+1)*val, (n-r)*val); n             return; n         } n  n         L = new SegmentTree(l, (l+r)/2); n         R = new SegmentTree((l+r)/2+1, r); n  n         L->build(val, n); n         R->build(val, n); n         x = L->x + R->x; n     } n  n     void updateLazy() n     { n         x.modifyPref(lazyPref); n         x.modifySuff(lazySuff); n         if(l!=r) n         { n             L->lazyPref += lazyPref; n             L->lazySuff += lazySuff; n             R->lazyPref += lazyPref; n             R->lazySuff += lazySuff; n         } n  n         lazyPref = lazySuff = 0; n     } n  n     Info query(int ql, int qr) n     { n         updateLazy(); n  n         if(l>=ql && r<=qr) return x; n         if(r<ql || l>qr) return Info(-MAXN, -MAXN); n  n         return L->query(ql, qr) + R->query(ql, qr); n     } n  n     void updatePref(int ql, int qr, int change) n     { n         updateLazy(); n  n         if(l>=ql && r<=qr) n         { n             lazyPref += change; n             updateLazy(); n  n             return; n         } n         if(r<ql || l>qr) return; n  n         L->updatePref(ql, qr, change); n         R->updatePref(ql, qr, change); n         x = L->x + R->x; n     } n     void updateSuff(int ql, int qr, int change) n     { n         updateLazy(); n  n         if(l>=ql && r<=qr) n         { n             lazySuff += change; n             updateLazy(); n  n             return; n         } n         if(r<ql || l>qr) return; n  n         L->updateSuff(ql, qr, change); n         R->updateSuff(ql, qr, change); n         x = L->x + R->x; n     } n  n     void update(int q, int change) n     { n         updatePref(q, r, change); n         updateSuff(l, q, change); n     } n }; n  n int n; n int a[MAXN]; n vector <int> num2Pos[MAXN]; n  n int answer[MAXN]; n  n void updateWithBiggerThanMiddle() n { n     SegmentTree *T = new SegmentTree(0, n-1); n     T->build(-1, n); n  n     for(int x = 1;x<=n;x++) n     { n         for(int i: num2Pos[x]) T->update(i, +2); n         for(int i: num2Pos[x]) n         { n             int sum = 0; n             sum += T->query(i, n-1).maxPref - T->query(i, i).maxPref; n             sum += T->query(0, i).maxSuff - T->query(i, i).maxSuff; n  n             answer[i] = max(answer[i], sum/2); n         } n     } n } n  n void updateWithSmallerThanMiddle() n { n     SegmentTree *T = new SegmentTree(0, n-1); n     T->build(-1, n); n  n     for(int x = n;x>=1;x--) n     { n         for(int i: num2Pos[x]) T->update(i, +2); n         for(int i: num2Pos[x]) n         { n             int sum = 0; n             sum += T->query(i, n-1).maxPref - T->query(i, i).maxPref; n             sum += T->query(0, i).maxSuff - T->query(i, i).maxSuff; n  n             answer[i] = max(answer[i], (sum+1)/2); n         } n     } n } n  n int main() n { n     ios::sync_with_stdio(false); n     cin.tie(nullptr); n  n     cin >> n; n     for(int i = 0;i<n;i++)  n     { n         cin >> a[i]; n         num2Pos[a[i]].push_back(i); n     } n  n     updateWithBiggerThanMiddle();    n     updateWithSmallerThanMiddle(); n  n     for(int i = 0;i<n;i++) n         cout << answer[i] <<    ; n     cout <<   n ; n }


#include <bits/stdc++.h> n namespace algo { n using namespace std; n const long double PI = 3.141592653589793238462643383279502884L; n const long double E = 2.718281828459045235360287471352662498L; n const long double EPS = 1e-12L; n template <typename T1, typename T2> n T1 bin_pow(T1 a, T2 n) { n   T1 r = 1; n   while (n > 0) { n     if (n & 1) r *= a; n     a *= a; n     n /= 2; n   } n   return r; n } n template <typename T1, typename T2> n T1 bin_pow(T1 a, T2 n, const T1& m) { n   if (m == 1) return 0; n   T1 r = 1; n   while (n > 0) { n     if (n & 1) { n       r *= a; n       r %= m; n     } n     a *= a; n     a %= m; n     n /= 2; n   } n   return r; n } n template <typename T> n T gcd(const T& a, const T& b) { n   if (b == 0) return abs(a); n   return gcd(b, a % b); n } n template <typename T> n T gcd(const T& a, const T& b, T& x, T& y) { n   if (b == 0) { n     x = a < 0 ? -1 : 1; n     y = 0; n     return x * a; n   } n   T d = gcd(b, a % b, y, x); n   y -= (a / b) * x; n   return d; n } n template <typename T> n T lcm(const T& a, const T& b) { n   return abs(a / gcd(a, b) * b); n } n template <typename T> n T mod_add(const T& a, const T& b, const T& m) { n   if (a < m - b) return a + b; n   return a - (m - b); n } n template <typename T> n T mod_sub(const T& a, const T& b, const T& m) { n   if (a < b) return a + (m - b); n   return a - b; n } n template <typename T> n T mod_mul(T a, T b, const T& m) { n   if (b > a) swap(a, b); n   T r = 0; n   while (b > 0) { n     if (b & 1) r = mod_add(r, a, m); n     a = mod_add(a, a, m); n     b /= 2; n   } n   return r; n } n template <typename T1, typename T2> n T1 mod_pow(T1 a, T2 n, const T1& m) { n   if (m == 1) return 0; n   T1 r = 1; n   while (n > 0) { n     if (n & 1) r = mod_mul(r, a, m); n     a = mod_mul(a, a, m); n     n /= 2; n   } n   return r; n } n template <typename T> n T mod_inv(const T& a, const T& m) { n   T x, y; n   T d = gcd(a, m, x, y); n   if (d != 1) return 0; n   if (x < 0) x += m; n   return x; n } n struct Sieve { n   int* lpf = nullptr; n   int* phi = nullptr; n   int size; n   vector<int> primes; n   Sieve(bool calcPhi = false, int n = 0xfffff) : size(n) { n     lpf = new int[size + 1]; n     fill(lpf, lpf + size + 1, 0); n     lpf[1] = 1; n     if (calcPhi) { n       phi = new int[size + 1]; n       phi[1] = 1; n       for (int i = 2; i <= size; ++i) { n         if (lpf[i] == 0) { n           phi[i] = i - 1; n           lpf[i] = i; n           primes.push_back(i); n         } n         for (int j = 0, t; j < primes.size() && (t = i * primes[j]) <= size; n              ++j) { n           lpf[t] = primes[j]; n           if (primes[j] == lpf[i]) { n             phi[t] = phi[i] * primes[j]; n             break; n           } n           phi[t] = phi[i] * (primes[j] - 1); n         } n       } n     } else { n       for (int i = 2; i <= size; ++i) { n         if (lpf[i] == 0) { n           lpf[i] = i; n           primes.push_back(i); n         } n         for (int j = 0, t; j < primes.size() && (t = i * primes[j]) <= size; n              ++j) { n           lpf[t] = primes[j]; n           if (primes[j] == lpf[i]) break; n         } n       } n     } n   } n   Sieve(int n) : Sieve(false, n) {} n   ~Sieve() { n     delete[] lpf; n     lpf = nullptr; n     delete[] phi; n     phi = nullptr; n   } n }; n template <typename T> n T phi(T n) { n   T r = n; n   for (T i = 2; i * i <= n; ++i) { n     if (n % i == 0) { n       r -= r / i; n       do { n         n /= i; n       } while (n % i == 0); n     } n   } n   if (n > 1) r -= r / n; n   return r; n } n }  // namespace algo n using namespace std; n using namespace algo; n namespace task { n struct Widget; n map<string, Widget*> widgets; n struct Widget { n   char type; n   int64_t width = -1; n   int64_t height = -1; n   int64_t border = 0; n   int64_t spacing = 0; n   vector<string> children; n   Widget(char type, int64_t width = -1, int64_t height = -1) n       : type(type), width(width), height(height) {} n   void pack(const string& name) { children.push_back(name); } n   pair<int64_t, int64_t> size() { n     if (width == -1 || height == -1) { n       if (type ==  W ) { n         exit(3); n       } else if (children.size() == 0) { n         width = 0; n         height = 0; n       } else if (type ==  H ) { n         int64_t t_width = (children.size() - 1) * spacing; n         int64_t t_height = 0; n         for (int i = 0; i < children.size(); ++i) { n           pair<int64_t, int64_t> t_size = widgets[children[i]]->size(); n           t_width += t_size.first; n           t_height = max(t_height, t_size.second); n         } n         width = t_width + 2 * border; n         height = t_height + 2 * border; n       } else if (type ==  V ) { n         int64_t t_width = 0; n         int64_t t_height = (children.size() - 1) * spacing; n         for (int i = 0; i < children.size(); ++i) { n           pair<int64_t, int64_t> t_size = widgets[children[i]]->size(); n           t_width = max(t_width, t_size.first); n           t_height += t_size.second; n         } n         width = t_width + 2 * border; n         height = t_height + 2 * border; n       } n     } n     return {width, height}; n   } n }; n int n, x, y; n string s, name1, name2; n int main() { n   cin >> n; n   for (int i = 0; i < n; ++i) { n     cin >> s; n     if (s ==  Widget ) { n       cin >> s; n       char name[16]; n       int64_t width, height; n       sscanf(s.c_str(),  %[a-z](%lli,%lli) , name, &width, &height); n       name1 = string(name); n       widgets[name1] = new Widget( W , width, height); n     } else if (s ==  VBox ) { n       cin >> name1; n       widgets[name1] = new Widget( V ); n     } else if (s ==  HBox ) { n       cin >> name1; n       widgets[name1] = new Widget( H ); n     } else { n       char name_1[16]; n       char name_2[16]; n       char method[16]; n       sscanf(s.c_str(),  %[a-z].%[a-z_](%[a-z0-9]) , name_1, method, name_2); n       name1 = string(name_1); n       if (string(method) ==  pack ) { n         name2 = string(name_2); n         widgets[name1]->pack(name2); n       } else if (string(method) ==  set_border ) { n         int64_t border; n         sscanf(name_2,  %lli , &border); n         widgets[name1]->border = border; n       } else if (string(method) ==  set_spacing ) { n         int64_t spacing; n         sscanf(name_2,  %lli , &spacing); n         widgets[name1]->spacing = spacing; n       } n     } n   } n   for (auto& it : widgets) { n     pair<int64_t, int64_t> size = it.second->size(); n     cout << it.first <<     << size.first <<     << size.second <<   n ; n   } n   return 0; n } n }  // namespace task n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n   cout.precision(11); n   cout.setf(ios::fixed); n   return task::main(); n } n


#include <bits/stdc++.h> n using namespace std; n const int mod = 1000000009; n map<pair<int, int>, int> in, id; n set<int> S; n int X[100010], Y[100010]; n bool check(pair<int, int> P) { n   int x = P.first, y = P.second + 1; n   for (int dx = x - 1; dx <= x + 1; dx++) { n     if (in.count(make_pair(dx, y)) && in[make_pair(dx, y)] == 1) return 0; n   } n   return 1; n } n int main() { n   int n; n   cin >> n; n   for (int i = 0; i < n; i++) { n     int x, y; n     cin >> x >> y; n     X[i] = x, Y[i] = y; n     in[make_pair(x, y)] = 0, id[make_pair(x, y)] = i; n   } n   for (map<pair<int, int>, int>::iterator it = in.begin(); it != in.end(); n        it++) { n     int x = it->first.first, y = it->first.second - 1; n     for (int dx = x - 1; dx <= x + 1; dx++) { n       if (in.count(make_pair(dx, y))) { n         in[it->first]++; n       } n     } n   } n   for (map<pair<int, int>, int>::iterator it = in.begin(); it != in.end(); n        it++) { n     if (check(it->first)) S.insert(id[it->first]); n   } n   long long ans = 0; n   for (int it = 0; it < n; it++) { n     if (it & 1) { n       int v = *S.begin(); n       S.erase(S.begin()); n       int y = Y[v] + 1; n       id.erase(make_pair(X[v], Y[v])); n       in[make_pair(X[v], Y[v])] = 0; n       for (int x = X[v] - 1; x <= X[v] + 1; x++) { n         if (!id.count(make_pair(x, y))) continue; n         in[make_pair(x, y)]--; n       } n       y--; n       for (int x = X[v] - 2; x <= X[v] + 2; x++) { n         if (!id.count(make_pair(x, y))) continue; n         if (check(make_pair(x, y))) n           S.insert(id[make_pair(x, y)]); n         else n           S.erase(id[make_pair(x, y)]); n       } n       y--; n       for (int x = X[v] - 2; x <= X[v] + 2; x++) { n         if (!id.count(make_pair(x, y))) continue; n         if (check(make_pair(x, y))) n           S.insert(id[make_pair(x, y)]); n         else n           S.erase(id[make_pair(x, y)]); n       } n       ans = (ans * n + v) % mod; n     } else { n       int v = *(--S.end()); n       S.erase(--S.end()); n       int y = Y[v] + 1; n       id.erase(make_pair(X[v], Y[v])); n       in[make_pair(X[v], Y[v])] = 0; n       for (int x = X[v] - 1; x <= X[v] + 1; x++) { n         if (!id.count(make_pair(x, y))) continue; n         in[make_pair(x, y)]--; n       } n       y--; n       for (int x = X[v] - 2; x <= X[v] + 2; x++) { n         if (!id.count(make_pair(x, y))) continue; n         if (check(make_pair(x, y))) n           S.insert(id[make_pair(x, y)]); n         else n           S.erase(id[make_pair(x, y)]); n       } n       y--; n       for (int x = X[v] - 2; x <= X[v] + 2; x++) { n         if (!id.count(make_pair(x, y))) continue; n         if (check(make_pair(x, y))) n           S.insert(id[make_pair(x, y)]); n         else n           S.erase(id[make_pair(x, y)]); n       } n       ans = (ans * n + v) % mod; n     } n   } n   cout << ans << endl; n   return 0; n } n


#include<bits/stdc++.h> n #include<algorithm> n #include<iostream> n #include<cstdio> n #include<cmath> n #include<cstring> n #include<stack> n #include<queue> n using namespace std; n typedef long long ll; n const ll INF=0x7f7f7f7f; n const int maxn=2e5+7; n const ll mod=1e9+7; n ll read(){ n     ll f=0,x=0;char ch=getchar(); n     while(!isdigit(ch)){if(ch== - ) f=1;ch=getchar();} n     while(isdigit(ch)){x=x*10+ch- 0 ;ch=getchar();} n     return !f?x:-x; n } n int tt,n,s[maxn]; n bool check(int x,int y){ n     if(x==3){ n         if(s[y]>=s[y+1]&&s[y+1]>=s[y+2]) return false; n         if(s[y]<=s[y+1]&&s[y+1]<=s[y+2]) return false; n         return true; n     } n     else{ n         for(int i=0;i<4;i++){ n             for(int j=i+1;j<4;j++){ n                 for(int k=j+1;k<4;k++){ n                     if(s[y+i]>=s[y+j]&&s[y+j]>=s[y+k]) return false; n                     if(s[y+i]<=s[y+j]&&s[y+j]<=s[y+k]) return false; n                 } n             } n         } n         return true; n     } n } n int main(){ n     scanf( %d ,&tt); n     while(tt--){ n         ll ans=0; n         scanf( %d ,&n); n         for(int i=1;i<=n;i++){ n             scanf( %d ,&s[i]); n         } n         ans+=2*n-1; n         for(int i=3;i<=4;i++){ n             for(int j=1;j<=n-i+1;j++){ n                 if(check(i,j)) ans++; n             } n         } n         printf( %lld n ,ans); n     } n     return 0; n }