#include <bits/stdc++.h> n using namespace std; n inline long long read() { n   long long res = 0, f = 1; n   char c = getchar(); n   while (c <  0  || c >  9 ) { n     if (c ==  - ) f = -1; n     c = getchar(); n   } n   while (c >=  0  && c <=  9 ) { n     res = res * 10 + c - 48; n     c = getchar(); n   } n   return res * f; n } n const long long N = 610; n long long f[N][N]; n long long a[N][N]; n long long n, m, mod; n long long in[N], o[N], s[N], t[N], tots, tott, tot; n long long head[N], to[N * N], nxt[N * N], res; n queue<long long> q; n long long id[N]; n long long qpow(long long a, long long b) { n   long long res = 1; n   while (b) { n     if (b & 1) res = res * a % mod; n     a = a * a % mod; n     b >>= 1; n   } n   return res; n } n void add(long long x, long long y) { n   nxt[++tot] = head[x]; n   head[x] = tot; n   to[tot] = y; n } n void guess(long long n) { n   res = 1; n   for (long long i = 1; i <= n; ++i) { n     for (long long j = i + 1; j <= n; ++j) { n       while (a[j][i]) { n         long long v = a[i][i] * qpow(a[j][i], mod - 2) % mod; n         for (long long k = i; k <= n; ++k) n           a[i][k] = ((a[i][k] - 1LL * v * a[j][k] % mod) + mod) % mod; n         swap(a[i], a[j]), res = -res; n       } n     } n   } n   for (long long i = 1; i <= n; ++i) { n     res = (1ll * res * a[i][i] % mod + mod) % mod; n   } n } n signed main() { n   n = read(), m = read(), mod = read(); n   for (long long i = 1; i <= m; ++i) { n     long long x = read(), y = read(); n     in[y]++, o[x]++; n     add(x, y); n   } n   for (long long i = 1; i <= n; ++i) { n     if (in[i] == 0) s[++tots] = i; n     if (o[i] == 0) t[++tott] = i; n   } n   for (long long i = 1; i <= n; ++i) n     if (!in[i]) q.push(i); n   tot = 0; n   while (q.size()) { n     long long u = q.front(); n     q.pop(); n     id[++tot] = u; n     for (long long i = head[u]; i; i = nxt[i]) { n       long long v = to[i]; n       --in[v]; n       if (!in[v]) q.push(v); n     } n   } n   for (long long i = 1; i <= n; ++i) { n     long long u = id[i]; n     f[u][u] = 1; n     for (long long j = i; j <= n; ++j) { n       long long v = id[j]; n       for (long long k = head[v]; k; k = nxt[k]) { n         long long vv = to[k]; n         f[u][vv] = (f[u][vv] + f[u][v]) % mod; n       } n     } n   } n   for (long long i = 1; i <= tots; ++i) { n     for (long long j = 1; j <= tott; ++j) { n       a[i][j] = f[s[i]][t[j]]; n     } n   } n   guess(tots); n   cout << res << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n int main() { n   int A, B; n   cin >> A >> B; n   string a, b; n   cin >> a >> b; n   int p = 0, m = a.size(); n   for (int i = 0; i + a.size() <= b.size(); i++) { n     int k = 0; n     for (int j = 0; j < a.size(); j++) { n       if (a[j] != b[i + j]) k++; n     } n     if (k < m) { n       m = k; n       p = i; n     } n   } n   vector<int> v; n   for (int i = 0; i < a.size(); i++) { n     if (a[i] != b[i + p]) v.push_back(i); n   } n   cout << v.size() << endl; n   for (int i = 0; i < v.size(); i++) { n     cout << v[i] + 1 <<    ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long a, b, n, m, k, l; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(); n   cin >> n >> m >> k >> l; n   if ((n / m) * m < k + l) { n     cout <<  -1 n ; n     return 0; n   } n   cout << (k + l) / m + ((k + l) % m != 0) << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int temp, sum = 0; n   int size, counter = 0; n   cin >> size; n   for (int i = 0; i < size; i++) cin >> temp, sum += temp; n   if (sum % size == 0) n     cout << size << endl; n   else n     cout << size - 1 << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct __s { n   __s() { n     if (1) { n       ios_base::Init i; n       cin.sync_with_stdio(0); n       cin.tie(0); n     } n   } n   ~__s() { n     if (!1) n       fprintf(stderr,  Execution time: %.3lf s. n , n               (double)clock() / CLOCKS_PER_SEC); n     long long n; n     cin >> n; n   } n } __S; n int main(void) { n   long long n, m; n   cin >> n; n   vector<long long> a(n); n   for (long long i = 0; i < (long long)(n); i++) { n     cin >> a[i]; n   } n   cin >> m; n   long long b = 0; n   for (long long i = 0; i < (long long)(m); i++) { n     long long x; n     cin >> x; n     b += x - 1; n   } n   vector<long long> c; n   while (c.size() < 3 * max(m, n)) { n     for (long long i = 0; i < (long long)(n - 1); i++) { n       c.push_back(i); n     } n     for (long long i = 0; i < (long long)(n - 1); i++) { n       c.push_back(n - 1 - i); n     } n   } n   long long d = 0; n   for (long long i = 0; i < (long long)(m); i++) { n     b -= c[i]; n     if (i) d += abs(a[c[i]] - a[c[i - 1]]); n   } n   set<long long> ans; n   for (long long i = m; i < c.size(); i++) { n     if (b == 0) { n       ans.insert(d); n     } n     b -= c[i]; n     b += c[i - m]; n     d -= abs(a[c[i - m]] - a[c[i - m + 1]]); n     d += abs(a[c[i]] - a[c[i - 1]]); n   } n   if (ans.size() != 1) n     cout << -1 <<   n ; n   else n     cout << *ans.begin() <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 100 * 1000; n int n, m; n int ar1[maxn]; n int ar2[maxn]; n void read(); n int main() { n   read(); n   int i, j; n   int s1, s2; n   int file; n   i = j = s1 = s2 = file = 0; n   while (i < n) { n     if (s1 == 0) n       s1 += ar1[i++]; n     else { n       if (s1 < s2) n         s1 += ar1[i++]; n       else if (s1 == s2) { n         s1 = s2 = 0; n         file++; n       } else n         s2 += ar2[j++]; n     } n   } n   if (s1 > 0) file++; n   cout << file << endl; n   return 0; n } n void read() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cin >> n >> m; n   for (int i = 0; i < n; i++) cin >> ar1[i]; n   for (int j = 0; j < m; j++) cin >> ar2[j]; n } n


#include <bits/stdc++.h> n using namespace std; n long long qpow(long long a, long long k) { n   long long b = 1LL; n   while (k) { n     if (k % 2 == 1) b = (b * a) % 1000000007; n     a = (a * a) % 1000000007; n     k = k / 2; n   } n   return b; n } n int main() { n   char s[105] = {0}; n   scanf( %s , s); n   int len = strlen(s); n   long long ans = 0; n   for (int i = len - 1; i >= 0; i--) { n     ans = ans * 2; n     ans = ans % 1000000007; n     if (s[i] ==  1 ) { n       ans = ans + qpow(4LL, (long long)(len - 1 - i)); n       ans = ans % 1000000007; n     } n   } n   printf( %I64d , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, x, y, u, v, to[600005], nxt[600005], p[300005], sz[300005]; n void dfs(int x, int lst) { n   sz[x] = 1; n   for (int i = p[x]; i != -1; i = nxt[i]) n     if (to[i] != lst) { n       dfs(to[i], x); n       sz[x] += sz[to[i]]; n     } n } n int main() { n   scanf( %d%d%d , &n, &x, &y); n   memset(p, -1, sizeof p); n   for (int i = 1; i < n; i++) { n     scanf( %d%d , &u, &v); n     to[i * 2 - 1] = v, nxt[i * 2 - 1] = p[u], p[u] = i * 2 - 1; n     to[i * 2] = u, nxt[i * 2] = p[v], p[v] = i * 2; n   } n   dfs(x, -1); n   long long ans = sz[y]; n   dfs(y, -1); n   ans *= sz[x]; n   cout << 1LL * n * (n - 1) - ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 1000000000; n const int maxn = 100; n const int MAXN = 2750131; n long long T, n, m, i, j; n long long gcd(long long p, long long q) { return q == 0 ? p : gcd(q, p % q); } n long long g[200005]; n int main() { n   ios::sync_with_stdio(false); n   long long a[20]; n   long long k = 1, s = 1, sum = 9; n   for (i = 0; s < 1e12; i++) { n     a[i] = s * sum * k; n     s *= 10; n     k++; n   } n   cin >> n; n   if (n < 10) { n     cout << n << endl; n     return 0; n   } n   sum = 0; n   i = 0; n   k = 1; n   s = 1; n   long long m = n; n   while (m > a[i]) { n     m -= a[i]; n     i++; n     k++; n     s = pow(10, i); n     sum = s - 1; n   } n   long long ans = (m) / k + sum; n   if (m % k) { n     ans++; n   } n   long long sk = m % k; n   if (sk == 0) { n     sk = k; n   } n   while (ans > 0) { n     if (sk == k) { n       cout << ans % 10 << endl; n       break; n     } else { n       ans /= 10; n       k--; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n int x1, x2, x3, y11, y2, y3, length; n int main() { n   scanf( %d %d %d %d %d %d , &x1, &y11, &x2, &y2, &x3, &y3); n   length = (int)(sqrt(x1 * y11 + x2 * y2 + x3 * y3) + 0.01); n   if (x1 * y11 + x2 * y2 + x3 * y3 != length * length) { n     printf( -1 n ); n     return 0; n   } n   if (x1 < y11) { n     int temp = x1; n     x1 = y11; n     y11 = temp; n   } n   if (x2 < y2) { n     int temp = x2; n     x2 = y2; n     y2 = temp; n   } n   if (x3 < y3) { n     int temp = x3; n     x3 = y3; n     y3 = temp; n   } n   if (x1 == length && x2 == length && x3 == length) { n     printf( %d n , length); n     for (int i = 0; i < y11; i++) { n       for (int j = 0; j < x1; j++) printf( A ); n       printf(  n ); n     } n     for (int i = 0; i < y2; i++) { n       for (int j = 0; j < x2; j++) printf( B ); n       printf(  n ); n     } n     for (int i = 0; i < y3; i++) { n       for (int j = 0; j < x3; j++) printf( C ); n       printf(  n ); n     } n   } else if (x1 == length) { n     printf( %d n , length); n     if (x2 != length - y11) { n       int temp = x2; n       x2 = y2; n       y2 = temp; n     } n     if (x3 != length - y11) { n       int temp = x3; n       x3 = y3; n       y3 = temp; n     } n     for (int i = 0; i < y11; i++) { n       for (int j = 0; j < x1; j++) printf( A ); n       printf(  n ); n     } n     for (int i = 0; i < length - y11; i++) { n       for (int j = 0; j < y2; j++) printf( B ); n       for (int j = 0; j < y3; j++) printf( C ); n       printf(  n ); n     } n   } else if (x2 == length) { n     printf( %d n , length); n     if (x1 != length - y2) { n       int temp = x1; n       x1 = y11; n       y11 = temp; n     } n     if (x3 != length - y2) { n       int temp = x3; n       x3 = y3; n       y3 = temp; n     } n     for (int i = 0; i < y2; i++) { n       for (int j = 0; j < x2; j++) printf( B ); n       printf(  n ); n     } n     for (int i = 0; i < length - y2; i++) { n       for (int j = 0; j < y11; j++) printf( A ); n       for (int j = 0; j < y3; j++) printf( C ); n       printf(  n ); n     } n   } else if (x3 == length) { n     printf( %d n , length); n     if (x1 != length - y3) { n       int temp = x1; n       x1 = y11; n       y11 = temp; n     } n     if (x2 != length - y3) { n       int temp = x2; n       x2 = y2; n       y2 = temp; n     } n     for (int i = 0; i < y3; i++) { n       for (int j = 0; j < x3; j++) printf( C ); n       printf(  n ); n     } n     for (int i = 0; i < length - y3; i++) { n       for (int j = 0; j < y11; j++) printf( A ); n       for (int j = 0; j < y2; j++) printf( B ); n       printf(  n ); n     } n   } else { n     printf( -1 n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2e3; n bool possible, check[N << 2], mark[N << 2]; n vector<int> topol, from[N << 2], to[N << 2]; n int n, m, c, d[N], com[N << 2], row[N], col[N], a[N][N], b[N][N]; n void dfs_scc(int u, int c) { n   com[u] = c; n   mark[u] = true; n   for (auto v : to[u]) n     if (!mark[v]) dfs_scc(v, c); n } n void strongly_connected_components() { n   memset(mark, false, sizeof mark); n   for (int i = 0; i < n << 2; i++) n     if (check[i] && !mark[i]) dfs_scc(i, ++c); n } n void dfs_topolo(int u) { n   mark[u] = true; n   for (auto v : from[u]) n     if (!mark[v]) dfs_topolo(v); n   topol.push_back(u); n } n void topological_sort() { n   for (int i = 0; i < n << 2; i++) n     if (check[i] && !mark[i]) dfs_topolo(i); n   reverse(topol.begin(), topol.end()); n } n void input(int w) { n   for (int i = 0; i < n; i++) { n     string s; n     cin >> s; n     for (int j = 0; j < n; j++) (w ? a[i][j] : b[i][j]) = s[j] -  0 ; n   } n } n void add_edge(int u, int v) { n   check[u] = check[v] = true; n   from[u].push_back(v); n   from[v].push_back(u); n   to[u].push_back(v); n   to[v].push_back(u); n } n void add_clause(int u, int v) { n   add_edge(u ^ 1, v); n   add_edge(u, v ^ 1); n } n void F2(int u, int v) { n   int k = a[u][v] + b[u][v]; n   if (k == 1) (d[v] & 1 ? row[u] : col[v]) = 1; n } n void F1(int u, int v, int k) { n   k += a[u][v] + b[u][v]; n   if (k == 3) { n     add_clause(u << 1, (v + n) << 1); n     return; n   } n   if (k == 1) { n     cout << -1; n     exit(0); n   } n   if (k == 4 || (!a[u][v] && k == 2)) { n     add_clause(u << 1 ^ 1, (v + n) << 1); n     return; n   } n } n int main() { n   ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); n   cin >> n; n   input(1), input(0); n   string s; n   cin >> s; n   for (int i = 0; i < n; i++) d[i] = s[i] -  0 ; n   for (int i = 0; i < n; i++) n     for (int j = 0; j < n; j++) d[i] == d[j] ? F1(i, j, d[i] + d[j]) : F2(i, j); n   topological_sort(); n   strongly_connected_components(); n   for (int i = 0; i < n << 1; i++) n     if (check[i << 1] && com[i << 1] == com[i << 1 ^ 1]) { n       cout << -1; n       return 0; n     } else if (check[i << 1] && com[i << 1] < com[i << 1 ^ 1]) n       i >= n ? col[i - n] = 1 : row[i] = true; n   int cnt = 0; n   for (int i = 0; i < n; i++) cnt += row[i] + col[i]; n   cout << cnt << endl; n   for (int i = 0; i < n; i++) n     if (row[i]) cout <<  row   << i << endl; n   for (int i = 0; i < n; i++) n     if (col[i]) cout <<  col   << i << endl; n } n


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


#include <bits/stdc++.h> n using namespace std; n double eps(1e-10); n int sign(const double& x) { return (x > eps) - (x + eps < 0); } n bool equal(const double& x, const double& y) { n   return x + eps > y && y + eps > x; n } n struct Point { n   double x, y, z; n   Point() {} n   Point(const double& x, const double& y, const double& z) : x(x), y(y), z(z) {} n   void print() const { printf( %f%f%f n , x, y, z); } n   void scan() { scanf( %lf%lf%lf , &x, &y, &z); } n   double sqrlen() const { return x * x + y * y + z * z; } n   double len() const { return sqrt(max(0., sqrlen())); } n   bool operator<(const Point& b) const { n     if (!equal(x, b.x)) { n       return x < b.x; n     } n     if (!equal(y, b.y)) { n       return y < b.y; n     } n     if (!equal(z, b.z)) { n       return z < b.z; n     } n     return false; n   } n   double dirlen() const { return len() * ((*this) < Point(0, 0, 0) ? -1 : 1); } n   Point operator+(const Point& b) const { n     return Point(x + b.x, y + b.y, z + b.z); n   } n   Point operator-(const Point& b) const { n     return Point(x - b.x, y - b.y, z - b.z); n   } n   double operator%(const Point& b) const { return x * b.x + y * b.y + z * b.z; } n   Point operator*(const Point& b) const { n     return Point(y * b.z - z * b.y, z * b.x - x * b.z, x * b.y - y * b.x); n   } n   Point zoom(const double& l) const { n     double lambda(l / len()); n     return Point(lambda * x, lambda * y, lambda * z); n   } n }; n inline Point operator*(const double& x, const Point& a) { n   return Point(x * a.x, x * a.y, x * a.z); n } n struct Plane { n   Point o, norm; n }; n struct Line { n   Point s, d; n   Line(const Point& s, const Point& d) : s(s), d(d) {} n }; n Point intersection(const Line& a, const Line& b) { n   double lambda(((b.s - a.s) * b.d).dirlen() / (a.d * b.d).dirlen()); n   return a.s + lambda * a.d; n } n vector<pair<Point, pair<int, int>>> evts; n void calc(const vector<Point>& points, const vector<Point>& q) { n   Plane p1, p2; n   p1.o = points[0]; n   p2.o = q[0]; n   p1.norm = (points[0] - points[1]) * (points[2] - points[0]); n   p2.norm = (q[0] - q[1]) * (q[2] - q[0]); n   p1.norm = p1.norm.zoom(1); n   p2.norm = p2.norm.zoom(1); n   if (sign((p1.norm * p2.norm).len()) == 0) { n     return; n   } n   Point d(p1.norm * p2.norm); n   Point g(d * p1.norm); n   d = d.zoom(1); n   g = g.zoom(1); n   Line l(p1.o + (p2.o - p1.o) % p2.norm / (g % p2.norm) * g, d); n   static vector<pair<Point, pair<int, int>>> vec; n   vec.clear(); n   for (int i(0); i < (int)points.size(); i++) { n     Point a(points[i]), b(points[(i + 1) % (int)points.size()]); n     int da(sign((a - l.s) % g)), db(sign((b - l.s) % g)); n     if (da == db) { n     } else { n       Point crs(intersection(Line(a, b - a), l)); n       if (da != 0 && db != 0) { n         evts.push_back(make_pair(crs, make_pair(da, 0))); n       } else { n         vec.push_back(make_pair(crs, make_pair(da, db))); n       } n     } n   } n   for (int i(0); i < (int)vec.size(); i++) { n     if (vec[i].second.second == 0) { n       if (vec[i].second.first != vec[(i + 1) % (int)vec.size()].second.second) { n         evts.push_back( n             make_pair(vec[i].first, make_pair(vec[i].second.first, 0))); n       } n     } n   } n } n vector<Point> vec[2]; n int main() { n   for (int d(0); d < 2; d++) { n     int n; n     scanf( %d , &n); n     for (int i(0); i < n; i++) { n       Point p; n       p.scan(); n       vec[d].push_back(p); n     } n   } n   calc(vec[0], vec[1]); n   for (auto& evt : evts) { n     evt.second.second = 1; n   } n   calc(vec[1], vec[0]); n   sort(evts.begin(), evts.end()); n   int ans(0); n   int cur(0); n   for (auto evt : evts) { n     if (evt.second.second == 1) { n       cur += evt.second.first; n     } else { n       if (cur != 0) { n         ans += evt.second.first; n       } n     } n   } n   printf( %s n , ans != 0 ?  YES  :  NO ); n } n


#include <bits/stdc++.h> n using namespace std; n struct Node { n   int idx, sum; n   int left, right; n } tree[3000000]; n int cnt; n long long sumVal; n char ch[10]; n void addNode(int cur, int def, int h, int val) { n   if (tree[cur].idx == def) { n     tree[cur].sum += val; n     return; n   } n   tree[cur].sum += val; n   if ((1 << (h)) & def) { n     if (tree[cur].right == 0) { n       tree[cur].right = ++cnt; n       tree[cnt].idx = tree[cur].idx * 2 + 1; n       tree[cnt].sum = 0; n       tree[cnt].left = tree[cnt].right = 0; n     } n     addNode(tree[cur].right, def, h - 1, val); n   } else { n     if (tree[cur].left == 0) { n       tree[cur].left = ++cnt; n       tree[cnt].idx = tree[cur].idx * 2; n       tree[cnt].sum = 0; n       tree[cnt].left = tree[cnt].right = 0; n     } n     addNode(tree[cur].left, def, h - 1, val); n   } n } n void decayNode(int cur, int h, int maxVal) { n   if (h == 0) { n     sumVal += max(maxVal, tree[cur].sum); n     return; n   } n   int u = tree[cur].left, v = tree[cur].right; n   if (tree[u].sum > tree[v].sum) { n     long long t = max(maxVal, tree[cur].sum - tree[v].sum); n     sumVal += (long long)(1 << (h - 1)) * t; n     maxVal = max(maxVal, tree[cur].sum - tree[u].sum); n     decayNode(u, h - 1, maxVal); n   } else { n     long long t = max(maxVal, tree[cur].sum - tree[u].sum); n     sumVal += (long long)(1 << (h - 1)) * t; n     maxVal = max(maxVal, tree[cur].sum - tree[v].sum); n     decayNode(v, h - 1, maxVal); n   } n } n int main(int argc, char** argv) { n   int n, m, k, e; n   scanf( %d%d , &n, &m); n   cnt = 1; n   tree[1].idx = 1; n   tree[1].sum = 0; n   tree[0].sum = 0; n   tree[1].left = tree[1].right = 0; n   for (int i = 1; i <= m; i++) { n     scanf( %s , ch); n     if (ch[0] ==  d ) { n       sumVal = 0; n       decayNode(1, n, 0); n       double ans = (double)sumVal / (double)(1 << (n)); n       printf( %.8lf n , ans); n     } else { n       scanf( %d%d , &k, &e); n       int h = 0, p = k / 2; n       while (p) { n         p /= 2; n         h += 1; n       } n       addNode(1, k, h - 1, e); n     } n   } n   return (EXIT_SUCCESS); n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 5; n char a[65]; n void pre() { n   int j = 1; n   for (j = 1; j <= 10; j++) a[j - 1] = (char)(j - 1 + 48); n   for (int i = 0; i < 26; i++) a[j++] = (char)(i + 97); n   for (int i = 0; i < 26; i++) a[j++] = (char)(i + 65); n   a[10] =  Z ; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   pre(); n   int T; n   cin >> T; n   while (T--) { n     vector<int> val(65, 0); n     int r, c, k; n     cin >> r >> c >> k; n     string s[r], ans[r]; n     int R = 0; n     for (int i = 0; i < r; i++) { n       cin >> s[i]; n       for (int j = 0; j < s[i].size(); j++) { n         if (s[i][j] ==  R ) R++; n         ans[i] +=  . ; n       } n     } n     int x = R / k; n     R = R % k; n     for (int i = 0; i < k; i++) { n       val[i] = x; n       if (R) { n         R--; n         val[i]++; n       } n     } n     int gg = 0; n     for (int i = 0; i < r; i++) { n       if (i % 2 == 0) { n         for (int j = 0; j < c; j++) { n           ans[i][j] = a[gg]; n           if (s[i][j] ==  R ) { n             val[gg]--; n             if (!val[gg]) { n               gg++; n             } n           } n           if (gg >= k - 1) gg = k - 1; n         } n       } else { n         for (int j = c - 1; j >= 0; j--) { n           ans[i][j] = a[gg]; n           if (s[i][j] ==  R ) { n             val[gg]--; n             if (!val[gg]) { n               gg++; n             } n           } n           if (gg >= k - 1) gg = k - 1; n         } n       } n     } n     for (int i = 0; i < r; i++) cout << ans[i] <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 4; n const int M = 1e9 + 7; n vector<pair<int, int> > g[N]; n const int inf = 1e9 + 10; n vector<int> dist(N, inf); n void dijkstra(int source) { n   dist[source] = 0; n   set<pair<int, int> > s; n   s.insert({0, source}); n   while (!s.empty()) { n     auto x = *(s.begin()); n     s.erase(x); n     for (auto it : g[x.second]) n       if (dist[it.first] > max(dist[x.second], it.second)) { n         s.erase({dist[it.first], it.first}); n         dist[it.first] = max(dist[x.second], it.second); n         s.insert({dist[it.first], it.first}); n       } n   } n } n void solve() { n   int n, m, k; n   cin >> n >> m >> k; n   int x[k]; n   for (int i = 0; i < k; i++) cin >> x[i]; n   for (int i = 0; i < m; i++) { n     int u, v, w; n     cin >> u >> v >> w; n     if (u != v) { n       g[u].push_back({v, w}); n       g[v].push_back({u, w}); n     } n   } n   dijkstra(x[0]); n   int ans = 0; n   for (int i = 0; i < k; i++) ans = max(ans, dist[x[i]]); n   for (int i = 0; i < k; i++) cout << ans <<    ; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long int to_reach(long long int number, long long int moves, n                        long long int target) { n   if (target == 0) { n     return (number / moves); n   } else { n     long long int res = (target - number) / moves; n     return res; n   } n } n int main() { n   long long int n, m, xc, yc, dxi, dyi, step; n   cin >> n >> m; n   cin >> xc >> yc; n   long long int k, count = 0; n   cin >> k; n   for (int i = 0; i < k; i++) { n     cin >> dxi >> dyi; n     long long int toReachX, toReachY; n     if (dxi == 0) n       toReachX = 10000000000; n     else if (dxi > 0) n       toReachX = to_reach(xc, dxi, n); n     else n       toReachX = to_reach(1 - xc, dxi, 0); n     if (dyi == 0) n       toReachY = 10000000000; n     else if (dyi > 0) n       toReachY = to_reach(yc, dyi, m); n     else n       toReachY = to_reach(1 - yc, dyi, 0); n     long long int tomove = min(toReachX, toReachY); n     xc = xc + dxi * tomove, yc = yc + dyi * tomove; n     count += tomove; n   } n   cout << count << endl; n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native ) n #pragma GCC optimize( unroll-loops ) n #pragma GCC optimize( Ofast ) n #pragma GCC optimize( O3 ) n #pragma GCC target( avx ) n const long long MOD = 1000000007; n const long double PI = 3.1415926535898; n const long long LIM = 100005; n using namespace std; n long long fpow(long long x, long long y) { n   long long temp; n   if (y == 0) return 1; n   temp = fpow(x, y / 2); n   if (y % 2 == 0) n     return temp * temp; n   else n     return x * temp * temp; n } n long long gcd(long long a, long long b) { n   if (b == 0) return a; n   return gcd(b, a % b); n } n void sieve(long long n) { n   bool prime[5 * LIM]; n   memset(prime, true, sizeof(prime)); n   for (long long p = 2; p * p <= n; p++) n     if (prime[p] == true) n       for (long long i = p * p; i <= n; i += p) prime[i] = false; n   prime[1] = 0; n } n inline long long read() { n   long long p = 1, ans = 0; n   char ch = getchar(); n   while (ch < 48 || ch > 57) { n     if (ch ==  - ) p = -1; n     ch = getchar(); n   } n   while (ch >= 48 && ch <= 57) { n     ans = (ans << 3) + (ans << 1) + ch - 48; n     ch = getchar(); n   } n   return ans * p; n } n bool isPrime(long long n) { n   if (n <= 1) return false; n   if (n <= 3) return true; n   if (n % 2 == 0 || n % 3 == 0) return false; n   for (long long i = 5; i * i <= n; i = i + 6) n     if (n % i == 0 || n % (i + 2) == 0) return false; n   return true; n } n map<long long, long long> primeFactors(long long n) { n   map<long long, long long> make_pair; n   while (n % 2 == 0) { n     if (make_pair.count(2) == 1) n       make_pair[2]++; n     else n       make_pair.insert({2, 1}); n     n = n / 2; n   } n   for (long long i = 3; i <= sqrt(n); i = i + 2) { n     while (n % i == 0) { n       if (make_pair.count(i) == 1) n         make_pair[i]++; n       else n         make_pair.insert({i, 1}); n       n = n / i; n     } n   } n   if (n > 2) { n     if (make_pair.count(n) == 1) n       make_pair[n]++; n     else n       make_pair.insert({n, 1}); n   } n   return make_pair; n } n long long compare(string a, string b) { n   if (a.empty()) return 0; n   for (long long i = 0; i < a.length(); i++) { n     if (a[i] > b[i]) n       return 1; n     else if (a[i] < b[i]) n       return -1; n   } n   return 0; n } n bool isPalindrome(string str) { n   long long l = 0; n   long long h = str.length() - 1; n   while (h > l) { n     if (str[l++] != str[h--]) { n       return false; n     } n   } n   return true; n } n long long maxSum(vector<long long> a) { n   long long max_so_far = a[0]; n   long long curr_max = a[0]; n   for (long long i = 1; i < a.size(); i++) { n     curr_max = max(a[i], curr_max + a[i]); n     max_so_far = max(max_so_far, curr_max); n   } n   return max_so_far; n } n long long maxlength(vector<long long> a) { n   long long size = a.size(); n   long long max_so_far = INT_MIN, max_ending_here = 0, start = 0, end = 0, n             s = 0; n   for (long long i = 0; i < size; i++) { n     max_ending_here += a[i]; n     if (max_so_far < max_ending_here) { n       max_so_far = max_ending_here; n       start = s; n       end = i; n     } n     if (max_ending_here <= 0) { n       max_ending_here = 0; n       s = i + 1; n     } n   } n   return (end - start + 1); n } n int32_t main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long t; n   cin >> t; n   for (long long tt = 1; tt <= t; ++tt) { n     long long n, r, p, s, cnt = 0; n     cin >> n >> r >> p >> s; n     string str; n     cin >> str; n     vector<char> ans(n,  A ); n     for (long long i = 0; i < str.length(); i++) { n       if (str[i] ==  R  && p > 0) { n         ans[i] =  P ; n         cnt++; n         p--; n       } n       if (str[i] ==  P  && s > 0) { n         ans[i] =  S ; n         cnt++; n         s--; n       } n       if (str[i] ==  S  && r > 0) { n         ans[i] =  R ; n         cnt++; n         r--; n       } n     } n     if (cnt < ceil(n / 2.0)) n       cout <<  NO  n            <<   n ; n     else { n       cout <<  YES  n            <<   n ; n       for (long long i = 0; i < n; i++) { n         if (ans[i] ==  A ) { n           if (p > 0) { n             ans[i] =  P ; n             p--; n           } else if (r > 0) { n             ans[i] =  R ; n             r--; n           } else if (s > 0) { n             ans[i] =  S ; n             s--; n           } n         } n         cout << ans[i]; n       } n       cout <<   n ; n     } n   } n   return 0; n } n


#include<iostream> n using namespace std; n int main() n { n     int t; n     cin>>t; n     while(t--){ n         int a,b; n         cin>>a>>b; n         if(a==0&&b==0) n             cout<< 0 n ; n         else if(a==0&&b!=0) n             cout<<2*b-1<<endl; n         else if(a!=0&&b==0) n             cout<<2*a-1<<endl; n         else{ n             if(a>b){ n                 int x=(2*b)+(2*(a-b)-1); n                 cout<<x<<endl; n             } n             else if(a<b){ n                 int x=(2*a)+(2*(b-a)-1); n                 cout<<x<<endl; n             } n             else if(a==b) n                 cout<<2*a<<endl; n             } n         } n     } n  n


#include <bits/stdc++.h> n using namespace std; n bool comp(const vector<int> &l, const vector<int> &r) { n   if (l[0] % 2 && r[0] % 2) { n     return l[1] < r[1]; n   } n   if ((l[0] % 2) && (r[0] % 2 == 0)) return true; n   if ((l[0] % 2 == 0) && (r[0] % 2)) n     return false; n   else n     return true; n } n int main() { n   int tmp, ans, test, c, i, j, n, k, t, odd, ans1 = 0, ans2 = 0; n   vector<int> ar[102], v; n   scanf( %d , &test); n   for (int i = 1; i <= test; i++) { n     scanf( %d , &n); n     ar[i].push_back(n); n     if (n % 2 == 0) { n       ans = 0; n       for (k = 1; k <= n / 2; k++) { n         scanf( %d , &t); n         ans += t; n       } n       ar[i].push_back(ans); n       ans = 0; n       for (k = 1; k <= n / 2; k++) { n         scanf( %d , &t); n         ans += t; n       } n       ar[i].push_back(ans); n       ar[i].push_back(-1); n     } else { n       ans = 0; n       for (k = 1; k <= n / 2; k++) { n         scanf( %d , &t); n         ans += t; n       } n       ar[i].push_back(ans); n       scanf( %d , &odd); n       ans = 0; n       for (k = 1; k <= n / 2; k++) { n         scanf( %d , &t); n         ans += t; n       } n       ar[i].push_back(ans); n       ar[i].push_back(odd); n       v.push_back(odd); n     } n   } n   for (i = 1; i <= test; i++) { n     if (1 || ar[i][0] % 2 == 0) { n       ans1 += ar[i][1]; n       ans2 += ar[i][2]; n     } n   } n   sort(v.begin(), v.end()); n   reverse(v.begin(), v.end()); n   bool ok = true; n   for (i = 0; i < v.size(); i++) { n     if (ok) n       ans1 += v[i]; n     else n       ans2 += v[i]; n     ok = !ok; n   } n   cout << ans1 <<     << ans2 << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long MOD = (long long)1e9 + 7; n const int N = 105; n const int M = 5005; n long long dp[N][M]; n int x[N]; n int y[N]; n long long c[M][N]; n int sum[N]; n int rSum[N]; n int h[N]; n int main() { n   int n, i, j, k, l; n   long long ans = 0; n   scanf( %d , &n); n   for (i = 1; i <= n; i++) { n     scanf( %d , &x[i]); n   } n   for (i = 1; i <= n; i++) { n     scanf( %d , &y[i]); n   } n   for (i = 0; i < M; i++) { n     c[i][0] = 1; n     if (i <= 100) { n       c[i][i] = 1; n     } n     for (j = 1; j < min(i, N); j++) { n       c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % MOD; n     } n   } n   for (i = 1; i <= n; i++) { n     sum[i] = sum[i - 1] + x[i]; n   } n   for (i = n; i >= 1; i--) { n     rSum[i] = rSum[i + 1] + y[i] - x[i]; n   } n   for (i = 1; i <= n; i++) { n     h[i] = x[i] + min(sum[i - 1], rSum[i]); n   } n   for (j = x[n]; j <= y[n]; j++) { n     dp[n][j] = 1; n   } n   for (i = n - 1; i >= 1; i--) { n     for (j = x[i]; j <= h[i]; j++) { n       for (k = 0; k <= min(y[i], j); k++) { n         dp[i][j] = (dp[i][j] + c[j][k] * dp[i + 1][x[i + 1] + j - k]) % MOD; n       } n     } n   } n   ans = dp[1][x[1]]; n   int num = sum[n]; n   for (i = 1; i <= n; i++) { n     ans = (ans * c[num][x[i]]) % MOD; n     num -= x[i]; n   } n   printf( %d n , (int)ans); n } n


#include <bits/stdc++.h> n using namespace std; n int *s; n int fenzhi(int left, int right, int d) { n   int mins = 0x3f3f3f3f; n   ; n   for (int i = left; i <= right; i++) mins = min(mins, s[i] - d); n   int ans = 0; n   for (int i = left; i <= right; i++) n     if (s[i] > mins + d) { n       int j = i; n       while (s[j + 1] > mins + d && j + 1 <= right) j++; n       ans += fenzhi(i, j, mins + d); n       i = j + 1; n     } n   return min(right - left + 1, mins + ans); n } n int main() { n   int n; n   cin >> n; n   s = new int[n]; n   for (int i = 0; i < n; i++) cin >> s[i]; n   cout << fenzhi(0, n - 1, 0) << endl; n   delete[] s; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string a; n   cin >> a; n   for (int i = 0; i < a.length(); i++) { n     if (isupper(a[i])) a[i] = tolower(a[i]); n   } n   string s =    ; n   for (int i = 0; i < a.length(); i++) { n     if (a[i] ==  a  || a[i] ==  o  || a[i] ==  u  || a[i] ==  e  || n         a[i] ==  i  || a[i] ==  y ) n       continue; n     s +=  . ; n     s += a[i]; n   } n   cout << s; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a[112], dp[312][312], mnix[312]; n int **func(int **mat1, int **mat2, int mx) { n   int **ans; n   ans = new int *[mx + 2]; n   for (int i = 1; i <= mx; i++) { n     ans[i] = new int[mx + 2]; n     for (int j = 1; j <= mx; j++) { n       ans[i][j] = 0; n       for (int k = i; k <= j; k++) n         ans[i][j] = max(ans[i][j], mat1[i][k] + mat2[k][j]); n     } n   } n   return ans; n } n int main() { n   int n, k, mx = 0; n   cin >> n >> k; n   for (int i = 0; i < 312; i++) { n     mnix[i] = 500; n     for (int j = 0; j < 312; j++) { n       dp[i][j] = 0; n     } n   } n   for (int i = 0; i < n; i++) { n     scanf( %d , &a[i]); n     mx = max(mx, a[i]); n     mnix[a[i]] = min(mnix[a[i]], i); n   } n   int **mat; n   mat = new int *[312]; n   for (int i = 0; i < 312; i++) { n     mat[i] = new int[312]; n     for (int j = 0; j < 312; j++) mat[i][j] = 0; n   } n   for (int st = 1; st <= mx; st++) { n     if (mnix[st] > 200) continue; n     for (int j = 1; j <= mx; j++) { n       if (j >= st) n         dp[mnix[st]][j] = 1; n       else n         dp[mnix[st]][j] = 0; n     } n     for (int i = mnix[st] + 1; i < n; i++) { n       for (int j = 1; j <= mx; j++) { n         if (a[i] < st) n           dp[i][j] = dp[i - 1][j]; n         else if (j < a[i]) n           dp[i][j] = dp[i - 1][j]; n         else if (j == a[i]) n           dp[i][j] = dp[i - 1][j] + 1; n         else n           dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]); n       } n     } n     for (int j = 1; j <= mx; j++) { n       if (j < st) mat[st][j] = 0; n       mat[st][j] = dp[n - 1][j]; n     } n     for (int i = 0; i <= mx; i++) { n       for (int j = 0; j <= mx; j++) { n         dp[i][j] = 0; n       } n     } n   } n   int **ans; n   ans = new int *[mx + 2]; n   for (int i = 0; i <= mx; i++) { n     ans[i] = new int[mx + 2]; n     for (int j = 0; j <= mx; j++) ans[i][j] = 0; n   } n   while (k) { n     if (k % 2 == 1) ans = func(ans, mat, mx); n     mat = func(mat, mat, mx); n     k = k / 2; n   } n   int fans = 0; n   for (int j = 1; j <= mx; j++) fans = max(fans, ans[j][mx]); n   cout << fans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n void solve() { n   long long n; n   cin >> n; n   vector<long long> v(n + 1); n   long long s = 0; n   for (long long i = 1; i <= n; i++) { n     cin >> v[i]; n     s += v[i] - i, v[i] = i; n   } n   for (long long i = 1; i <= n; i++) v[i] += s / n; n   for (long long i = 1; i <= s % n; i++) v[i]++; n   for (long long i = 1; i <= n; i++) cout << v[i] <<    n [i == n]; n } n signed main() { n   ios::sync_with_stdio(0); n   cin.tie(0), cout.tie(0); n   long long t = 1; n   while (t--) solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<long long> q; n long long i, j, n, k, m = 1000000007, ww = 1, a[20005], b[20005], c[20005], n                       w[20005]; n bool flag; n bool otv(int n, bool sign) { n   long long t = n; n   for (long long j = 0; j < q.size(); j++) { n     if (t % q[j] == 0) { n       t /= q[j]; n       if (sign) n         w[j]++; n       else n         w[j]--; n       j--; n     } n     if (t == 1) break; n   } n   if (t > 1) ww = (ww * t) % m; n   return 0; n } n long long ans() { n   long long i, j, first = 1; n   for (i = 0; i < q.size(); i++) n     for (j = 0; j < w[i]; j++) first = (first * q[i]) % m; n   first = (ww * first) % m; n   return first; n } n int main() { n   cin >> n >> k; n   for (i = 1; i <= n; i++) cin >> a[i]; n   if (k == 0) { n     for (i = 1; i <= n; i++) cout << a[i] <<    ; n     return 0; n   } n   for (i = 2; i <= 30000; i++) { n     flag = 0; n     for (j = 0; j < q.size(); j++) n       if (i % q[j] == 0) { n         flag = 1; n         break; n       } n     if (!flag) q.push_back(i); n   } n   b[1] = 1; n   k--; n   for (i = 2; i <= n; i++) { n     otv(i + k - 1, 1); n     otv(i - 1, 0); n     b[i] = ans(); n   } n   for (i = 1; i <= n; i++) n     for (j = 0; j < i; j++) c[i] = ((a[i - j] * b[j + 1]) % m + c[i]) % m; n   for (i = 1; i <= n; i++) cout << c[i] <<    ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct circle { n   long double x, y, r; n }; n struct mod { n   long double theta, op; n }; n struct node { n   long double x, y, theta; n }; n int n, d, i, j, tot, S, ans, gg; n circle c[20005]; n mod l[2000005]; n node A, B; n long double D, k, t, L, R, dis1, dis2, dis3; n void getAB() { n   long double x = c[i].x, y = c[i].y, r = c[i].r, delta; n   if (x == 0) { n     t = (r * r - x * x - y * y - D * D) / (-2 * y); n     k = -x / y; n     delta = (2 * t * k) * (2 * t * k) - 4 * (k * k + 1) * (t * t - D * D); n     if (delta < 0) { n       A.x = A.y = 0; n       return; n     } n     A.x = (-(2 * t * k) + sqrt(delta)) / (2 * (k * k + 1)); n     B.x = (-(2 * t * k) - sqrt(delta)) / (2 * (k * k + 1)); n     A.y = (r * r - x * x - y * y - D * D + 2 * x * A.x) / (-2 * y); n     B.y = (r * r - x * x - y * y - D * D + 2 * x * B.x) / (-2 * y); n   } else { n     t = (r * r - x * x - y * y - D * D) / (-2 * x); n     k = -y / x; n     delta = (2 * t * k) * (2 * t * k) - 4 * (k * k + 1) * (t * t - D * D); n     if (delta < 0) { n       A.x = A.y = 0; n       return; n     } n     A.y = (-(2 * t * k) + sqrt(delta)) / (2 * (k * k + 1)); n     B.y = (-(2 * t * k) - sqrt(delta)) / (2 * (k * k + 1)); n     A.x = (r * r - x * x - y * y - D * D + 2 * y * A.y) / (-2 * x); n     B.x = (r * r - x * x - y * y - D * D + 2 * y * B.y) / (-2 * x); n   } n } n void insert(long double L, long double R) { n   tot++; n   l[tot].theta = L; n   l[tot].op = 1; n   tot++; n   l[tot].theta = R + 0.0000000001; n   l[tot].op = -1; n } n int comp(mod A, mod B) { n   return ((A.theta < B.theta) || ((A.theta == B.theta) && (A.op < B.op))); n } n int main() { n   scanf( %d%d , &n, &d); n   for (i = 1; i <= n; i++) { n     scanf( %Lf%Lf%Lf , &c[i].x, &c[i].y, &c[i].r); n   } n   for (i = 1; i <= n; i++) { n     gg = sqrt(c[i].x * c[i].x + c[i].y * c[i].y) / d; n     for (D = (long double)max(gg - 100, 1) * (long double)d; n          D <= (long double)(gg + 100) * (long double)d; D += (long double)d) { n       getAB(); n       if ((A.x == 0) && (A.y == 0)) continue; n       A.theta = atan2(A.x, A.y); n       B.theta = atan2(B.x, B.y); n       if (A.theta > B.theta) swap(A, B); n       L = A.theta; n       R = B.theta; n       if (R - L > 3.1415926535) swap(L, R); n       if (L <= R) n         insert(L, R); n       else n         insert(-3.1415926535, R), insert(L, 3.1415926535); n     } n   } n   sort(l + 1, l + 1 + tot, comp); n   for (i = 1; i <= tot; i++) { n     S += l[i].op; n     ans = max(ans, S); n   } n   printf( %d , ans); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int n; n   cin >> n; n   vector<int> a; n   for (int i = (0); i < (n); i++) { n     int t; n     cin >> t; n     a.push_back(t); n   } n   vector<int> b; n   for (int i = (0); i < (n); i++) { n     int t; n     cin >> t; n     b.push_back(t); n   } n   sort(a.begin(), a.end(), greater<int>()); n   sort(b.begin(), b.end(), greater<int>()); n   long long r = 0; n   long long r1 = 0; n   int i = 0; n   int j = 0; n   int nn = 2 * n; n   int s = 1; n   while (nn--) { n     if (s == 1) { n       if (i < n && j < n) { n         if (a[i] > b[j]) { n           r += a[i]; n           i++; n         } else { n           j++; n         } n       } else if (j < n) { n         j++; n       } else if (i < n) { n         r += a[i]; n         i++; n       } n     } else { n       if (i < n && j < n) { n         if (b[j] > a[i]) { n           r1 += b[j]; n           j++; n         } else { n           i++; n         } n       } else if (j < n) { n         r1 += b[j]; n         j++; n       } else if (i < n) { n         i++; n       } n     } n     s ^= 1; n   } n   cout << r - r1 << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void solve() { n   int n, k; n   cin >> n >> k; n   if (k == 1) { n     cout <<  Yes  << endl; n     return; n   } n   vector<int> divs; n   for (int i = 2; i < k; ++i) n     if (!(k % i)) { n       cerr << i << endl; n       divs.push_back(1); n       while (!(k % i)) k /= i, divs.back() *= i; n     } n   if (k > 1) divs.push_back(k); n   set<int> div(divs.begin(), divs.end()); n   int a; n   for (int i = 0; i < n; ++i) { n     cin >> a; n     set<int>::iterator it = div.begin(); n     while (it != div.end()) { n       if (a % (*it)) n         ++it; n       else n         it = div.erase(it); n     } n   } n   if (div.size()) n     cout <<  No  << endl; n   else n     cout <<  Yes  << endl; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, color[510]; n bool g[510][510]; n vector<int> nbr[510]; n bool dfs(int x, int c) { n   color[x] = c; n   for (int i = 0; i < nbr[x].size(); i++) { n     int y = nbr[x][i]; n     if (color[y] == c) return 0; n     if (color[y] == 0 && dfs(y, 3 - c) == 0) return 0; n   } n   return 1; n } n int main() { n   cin >> n >> m; n   for (int i = 1; i <= m; i++) { n     int x, y; n     cin >> x >> y; n     g[x][y] = g[y][x] = 1; n   } n   for (int i = 1; i < n; i++) n     for (int j = i + 1; j <= n; j++) n       if (g[i][j] == 0) { n         nbr[i].push_back(j); n         nbr[j].push_back(i); n       } n   for (int i = 1; i <= n; i++) { n     if (color[i] || nbr[i].size() == 0) continue; n     if (dfs(i, 1) == 0) { n       puts( No ); n       return 0; n     } n   } n   for (int i = 1; i < n; i++) n     for (int j = i + 1; j <= n; j++) n       if (color[i] + color[j] == 3 && g[i][j]) { n         puts( No ); n         return 0; n       } n   puts( Yes ); n   for (int i = 1; i <= n; i++) { n     if (color[i] == 0) n       cout <<  b ; n     else if (color[i] == 1) n       cout <<  a ; n     else if (color[i] == 2) n       cout <<  c ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int T; n   cin >> T; n   int Deb = 0; n   int Fin = 9; n   int Tab[10]; n   for (int j = 0; j < 10; j++) Tab[j] = 0; n   char Cuck; n   for (int j = 0; j < T; j++) { n     cin >> Cuck; n     if (Cuck ==  L ) { n       Tab[Deb] = 1; n       int curDeb = Deb; n       while (Tab[curDeb] == 1 && curDeb < 10) curDeb++; n       Deb = curDeb; n     } else if (Cuck ==  R ) { n       Tab[Fin] = 1; n       int curFin = Fin; n       while (Tab[curFin] == 1 && curFin >= 0) curFin--; n       Fin = curFin; n     } else { n       int Ind = Cuck - 48; n       Tab[Ind] = 0; n       int curDeb = 0; n       while (Tab[curDeb] == 1 && curDeb < 10) curDeb++; n       Deb = curDeb; n       int curFin = 9; n       while (Tab[curFin] == 1 && curFin >= 0) curFin--; n       Fin = curFin; n     } n   } n   for (int j = 0; j < 10; j++) cout << Tab[j]; n } n


#include <bits/stdc++.h> n using namespace std; n inline void read(int &x) { n   char ch = getchar(); n   x = 0; n   while (!isdigit(ch)) ch = getchar(); n   while (isdigit(ch)) x = x * 10 + ch - 48, ch = getchar(); n } n int n, m, a[238][238], x[238], y[238]; n signed main() { n   read(n), read(m); n   for (int i = 1; i <= n; ++i) n     for (int j = 1; j <= m; ++j) read(a[i][j]); n   if (n == 1) { n     puts( YES ); n     puts( 0 ); n     for (int i = 1; i <= m; ++i) a[1][i] ? putchar(48) : putchar(49); n     return 0; n   } n   if (m == 1) { n     puts( YES ); n     for (int i = 1; i <= n; ++i) a[i][1] ? putchar(48) : putchar(49); n     puts(  ); n     return putchar(48), 0; n   } n   int ok = 1, cnt = 0, w, qwq; n   for (int i = 1; i <= m; ++i) y[i] = a[1][i]; n   for (int i = 2; i <= n; ++i) { n     int tmp = 0; n     for (int j = 2; j <= m; ++j) n       if ((a[i][j] ^ y[j]) != (a[i][j - 1] ^ y[j - 1])) n         ++tmp, qwq = (a[i][j] ^ y[j]); n     if (tmp) { n       cnt += tmp, w = i; n       if (cnt > 1) { n         ok = 0; n         break; n       } n     } n   } n   if (ok) { n     puts( YES ); n     if (cnt) { n       for (int i = 2; i < w; ++i) x[i] = a[i][1] ^ y[1]; n       x[w] = qwq ^ 1; n       for (int i = w + 1; i <= n; ++i) x[i] = a[i][1] ^ y[1] ^ 1; n     } else n       for (int i = 2; i <= n; ++i) x[i] = a[i][1] ^ y[1]; n     for (int i = 1; i <= n; ++i) putchar(x[i] + 48); n     puts(  ); n     for (int i = 1; i <= m; ++i) putchar(y[i] + 48); n     return 0; n   } n   ok = 1, cnt = 0; n   for (int i = 1; i <= m; ++i) y[i] = a[n][i] ^ 1; n   for (int i = 1; i < n; ++i) { n     int tmp = 0; n     for (int j = 2; j <= m; ++j) n       if ((a[i][j] ^ y[j]) != (a[i][j - 1] ^ y[j - 1])) n         ++tmp, qwq = (a[i][j] ^ y[j]); n     if (tmp) { n       cnt += tmp, w = i; n       if (cnt > 1) { n         ok = 0; n         break; n       } n     } n   } n   if (ok) { n     puts( YES ); n     if (cnt) { n       for (int i = 1; i < w; ++i) x[i] = a[i][1] ^ y[1]; n       x[w] = qwq ^ 1; n       for (int i = w + 1; i < n; ++i) x[i] = a[i][1] ^ 1 ^ y[1]; n     } else n       for (int i = 1; i < n; ++i) x[i] = a[i][1] ^ y[1]; n     for (int i = 1; i <= n; ++i) putchar(x[i] + 48); n     puts(  ); n     for (int i = 1; i <= m; ++i) putchar(y[i] + 48); n     return 0; n   } n   return puts( NO ), 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int PI = 3.1415926535; n const int inf = 1000111222; n const int mod = 1000000007; n const int N = 100007; n int main() { n   ios_base ::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int n; n   cin >> n; n   vector<int> ar(n); n   for (int i = 0; i < n; i++) cin >> ar[i]; n   vector<int> entries; n   int ans = 0; n   for (int i = 30; i >= 0; i--) { n     entries.clear(); n     for (int j = 0; j < n; j++) { n       if ((1 << i) & ar[j]) { n         entries.push_back(j); n       } n     } n     if (entries.size() == 1) { n       ans = entries[0]; n       break; n     } n   } n   vector<int> order; n   order.push_back(ans); n   for (int i = 0; i < n; i++) { n     if (i != ans) order.push_back(i); n   } n   for (int i = 0; i < n; i++) { n     cout << ar[order[i]] <<    ; n   } n   cout <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int mod = 1e9 + 7; n int n, k; n long long temp[55]; n long long dp[105][55], ans; n vector<int> g[105]; n void dfs(int u, int fa) { n   dp[u][0] = 1; n   dp[u][1 + k] = 1; n   for (int i = 0; i < g[u].size(); i++) { n     int v = g[u][i]; n     if (v != fa) { n       dfs(v, u); n       for (int j = 0; j <= 2 * k + 1; j++) temp[j] = 0; n       for (int dep1 = 0; dep1 <= 2 * k + 1; dep1++) { n         for (int dep2 = 0; dep2 <= 2 * k; dep2++) { n           if (dep1 + dep2 <= 2 * k) n             temp[min(dep1, dep2 + 1)] = n                 (temp[min(dep1, dep2 + 1)] + dp[u][dep1] * dp[v][dep2] % mod) % n                 mod; n           else n             temp[max(dep1, dep2 + 1)] = n                 (temp[max(dep1, dep2 + 1)] + dp[u][dep1] * dp[v][dep2] % mod) % n                 mod; n         } n       } n       for (int j = 0; j <= 2 * k + 1; j++) dp[u][j] = temp[j]; n     } n   } n } n int main() { n   ios::sync_with_stdio(false); n   cin >> n >> k; n   for (int i = 1, u, v; i < n; i++) { n     cin >> u >> v; n     g[u].push_back(v); n     g[v].push_back(u); n   } n   dfs(1, 0); n   for (int i = 0; i <= k; i++) ans = (ans + dp[1][i]) % mod; n   cout << ans; n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n template <typename T, typename U> n struct seg_tree_lazy { n   int S, H; n   T zero; n   std::vector<T> value; n   U noop; n   std::vector<bool> dirty; n   std::vector<U> prop; n   seg_tree_lazy<T, U>(int _S, T _zero = T(), U _noop = U()); n   void set_leaves(std::vector<T> &leaves); n   void apply(int i, U &update); n   void rebuild(int i); n   void propagate(int i); n   void upd(int i, int j, U update); n   T query(int i, int j); n }; n int v[210000]; n set<int> ss[33]; n int clz(int x) { n   if (x == 0) return 32; n   return __builtin_clz(x); n } n struct node { n   long long s = 0; n   node(long long int _s = 0) : s(_s) {} n   node operator+(node ot) { return node(s + ot.s); } n }; n struct upd { n   int v; n   upd(int _v = 0) : v(_v) {} n   node operator()(node a) { n     a.s += v; n     return a; n   } n   upd operator+(upd ot) { return upd(v + ot.v); } n }; n int n, q; n void solve() { n   scanf( %d %d , &n, &q); n   for (int i = 0; i < n; i++) scanf( %d , &v[i]); n   vector<node> leaves(n); n   for (int i = 0; i < n; i++) { n     leaves[i].s = v[i]; n     ss[clz(v[i])].insert(i); n   } n   seg_tree_lazy<node, upd> tree(n); n   tree.set_leaves(leaves); n   for (int i = 0; i < q; i++) { n     int p, val; n     scanf( %d %d , &p, &val); n     p--; n     int diff = val - v[p]; n     ss[clz(v[p])].erase(p); n     tree.upd(p, p, diff); n     v[p] = val; n     ss[clz(v[p])].insert(p); n     int f = -1; n     for (int i = 0; i < 33 && f == -1; i++) { n       auto it = ss[i].begin(); n       for (int j = 0; j < 2; j++) { n         if (it == ss[i].end()) break; n         if (tree.query(0, *it).s == 2 * (v[*it])) f = *it + 1; n         it++; n       } n     } n     printf( %d n , f != -1 ? f : -1); n   } n } n int main() { solve(); } n template <typename T, typename U> n seg_tree_lazy<T, U>::seg_tree_lazy(int _S, T _zero, U _noop) { n   zero = _zero, noop = _noop; n   for (S = 1, H = 1; S < _S;) S *= 2, H++; n   value.resize(2 * S, zero); n   dirty.resize(2 * S, false); n   prop.resize(2 * S, noop); n } n template <typename T, typename U> n void seg_tree_lazy<T, U>::set_leaves(vector<T> &leaves) { n   copy(leaves.begin(), leaves.end(), value.begin() + S); n   for (int i = S - 1; i > 0; i--) value[i] = value[2 * i] + value[2 * i + 1]; n } n template <typename T, typename U> n void seg_tree_lazy<T, U>::apply(int i, U &update) { n   value[i] = update(value[i]); n   if (i < S) { n     prop[i] = prop[i] + update; n     dirty[i] = true; n   } n } n template <typename T, typename U> n void seg_tree_lazy<T, U>::rebuild(int i) { n   for (int l = i / 2; l; l /= 2) { n     T combined = value[2 * l] + value[2 * l + 1]; n     value[l] = prop[l](combined); n   } n } n template <typename T, typename U> n void seg_tree_lazy<T, U>::propagate(int i) { n   for (int h = H; h > 0; h--) { n     int l = i >> h; n     if (dirty[l]) { n       apply(2 * l, prop[l]); n       apply(2 * l + 1, prop[l]); n       prop[l] = noop; n       dirty[l] = false; n     } n   } n } n template <typename T, typename U> n void seg_tree_lazy<T, U>::upd(int i, int j, U update) { n   i += S, j += S; n   propagate(i), propagate(j); n   for (int l = i, r = j; l <= r; l /= 2, r /= 2) { n     if ((l & 1) == 1) apply(l++, update); n     if ((r & 1) == 0) apply(r--, update); n   } n   rebuild(i), rebuild(j); n } n template <typename T, typename U> n T seg_tree_lazy<T, U>::query(int i, int j) { n   i += S, j += S; n   propagate(i), propagate(j); n   T res_left = zero, res_right = zero; n   for (; i <= j; i /= 2, j /= 2) { n     if ((i & 1) == 1) res_left = res_left + value[i++]; n     if ((j & 1) == 0) res_right = value[j--] + res_right; n   } n   return res_left + res_right; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long i, n, r, S, Z, s1, s2, s3, s4, s5, s6, s7, s8, x, y, z, m, j, l, k, n       t; n   long long a[500005]; n   long long b[300045]; n   long long c[300001]; n   long long d[100001]; n   long long e[101][101]; n   pair<long long, long long> aa[200001]; n   pair<long long, long long> bb[200001]; n   double h, w, u, v, uu, vv; n   string q1; n   string q2; n   string q3; n   string q4; n   string s; n   string q; n   string sq[50005]; n   string qs[3001]; n   map<string, long long> g; n   map<string, long long>::iterator it; n   cin >> n; n   for (i = 1; i <= 100; i++) { n     b[i] = 0; n   } n   for (l = 1; l <= n; l++) { n     cin >> m; n     for (i = 1; i <= m; i++) { n       cin >> x; n       b[x]++; n     } n   } n   for (i = 1; i <= 100; i++) { n     if (b[i] == n) cout << i <<    ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 50100; n vector<int> v; n int n, k, st, x; n int nextchild[maxn], value[maxn]; n void get_rand() { n   int arr[n + 1]; n   for (int i = 0; i < n; i++) { n     arr[i] = i + 1; n   } n   srand(time(0)); n   random_shuffle(arr, arr + n); n   for (int i = 0; i < k; i++) { n     v.push_back(arr[i]); n   } n } n int main() { n   cin >> n >> st >> x; n   k = min(n, 1000); n   get_rand(); n   memset(nextchild, 0, sizeof(nextchild)); n   memset(value, -1, sizeof(value)); n   cout <<  ?   << st <<   n ; n   fflush(stdout); n   cin >> value[st] >> nextchild[st]; n   int maxind = st; n   int maxval = value[st]; n   for (int i : v) { n     cout <<  ?   << i <<   n ; n     fflush(stdout); n     cin >> value[i] >> nextchild[i]; n     if (value[i] <= x && value[i] > maxval) { n       maxval = value[i]; n       maxind = i; n     } n   } n   int curr = maxind; n   int answ = maxind; n   while (true) { n     cout <<  ?   << curr <<   n ; n     fflush(stdout); n     cin >> value[curr] >> nextchild[curr]; n     if (value[curr] >= x || nextchild[curr] == -1) n       break; n     else n       curr = nextchild[curr]; n   } n   if (value[curr] >= x) { n     cout <<  !   << value[curr] <<   n ; n     fflush(stdout); n   } else { n     cout <<  ! -1 n ; n     fflush(stdout); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct node { n   int l, r, lc, rc; n   int dep_a, dep_a_2b, dep_2b_c, dep_2b, dep_a_2b_c, cover; n }; n const int N = 200000; n const int root = 0; n struct Segment_Tree { n   int num; n   node tr[2 * N]; n   void setRange(int l, int r, int now = root) { n     num = 0; n     build(l, r, now); n   } n   void build(int l, int r, int now) { n     tr[now].l = l; n     tr[now].r = r; n     tr[now].dep_2b_c = tr[now].dep_a = tr[now].dep_2b = tr[now].dep_a_2b = n         tr[now].dep_a_2b_c = 0; n     tr[now].cover = 0; n     if (l < r) { n       int mid = (l + r) >> 1; n       ++num; n       tr[now].lc = num; n       ++num; n       tr[now].rc = num; n       build(l, mid, tr[now].lc); n       build(mid + 1, r, tr[now].rc); n     } n   } n   void pushup(node &f, node &lc, node &rc) { n     f.dep_a = max(lc.dep_a, rc.dep_a); n     f.dep_2b = max(lc.dep_2b, rc.dep_2b); n     f.dep_a_2b = max(max(lc.dep_a_2b, rc.dep_a_2b), lc.dep_a + rc.dep_2b); n     f.dep_2b_c = max(max(lc.dep_2b_c, rc.dep_2b_c), lc.dep_2b + rc.dep_a); n     f.dep_a_2b_c = max(max(lc.dep_a_2b_c, rc.dep_a_2b_c), n                        max(lc.dep_a + rc.dep_2b_c, lc.dep_a_2b + rc.dep_a)); n   } n   void lazyupdate(int now, int val) { n     tr[now].cover += val; n     tr[now].dep_a += val; n     tr[now].dep_a_2b -= val; n     tr[now].dep_2b_c -= val; n     tr[now].dep_2b -= 2 * val; n   } n   void pushdown(int now) { n     lazyupdate(tr[now].lc, tr[now].cover); n     lazyupdate(tr[now].rc, tr[now].cover); n     tr[now].cover = 0; n   } n   void update(int l, int r, int val, int now = root) { n     if (tr[now].l == l && tr[now].r == r) { n       lazyupdate(now, val); n       return; n     } else { n       if (tr[now].cover != 0) pushdown(now); n       int mid = (tr[now].l + tr[now].r) >> 1; n       if (r <= mid) n         update(l, r, val, tr[now].lc); n       else if (l > mid) n         update(l, r, val, tr[now].rc); n       else { n         update(l, mid, val, tr[now].lc); n         update(mid + 1, r, val, tr[now].rc); n       } n       pushup(tr[now], tr[tr[now].lc], tr[tr[now].rc]); n     } n   } n   node query(int l, int r, int now = root) { n     if (tr[now].l == l && tr[now].r == r) n       return tr[now]; n     else { n       if (tr[now].cover != 0) pushdown(now); n       int mid = (tr[now].l + tr[now].r) >> 1; n       if (r <= mid) n         return query(l, r, tr[now].lc); n       else if (l > mid) n         return query(l, r, tr[now].rc); n       else { n         node f, lc, rc; n         lc = query(l, mid, tr[now].lc); n         rc = query(mid + 1, r, tr[now].rc); n         pushup(f, lc, rc); n         return f; n       } n     } n   } n }; n Segment_Tree tr; n bool p[200000]; n int main() { n   int n, q; n   char ch[200000]; n   scanf( %d%d%s , &n, &q, ch); n   n = (n - 1) * 2; n   tr.setRange(1, n); n   for (int i = 0; i < n; ++i) { n     if (ch[i] ==  ( ) { n       p[i + 1] = true; n       tr.update(i + 1, n, 1); n     } else { n       p[i + 1] = false; n       tr.update(i + 1, n, -1); n     } n   } n   printf( %d n , tr.query(1, n).dep_a_2b_c); n   while (q--) { n     int s, t; n     scanf( %d%d , &s, &t); n     if (s > t) swap(s, t); n     if (p[s] != p[t]) { n       p[s] = !p[s]; n       p[t] = !p[t]; n       if (p[s]) { n         tr.update(s, t - 1, 2); n       } else { n         tr.update(s, t - 1, -2); n       } n     } n     printf( %d n , tr.query(1, n).dep_a_2b_c); n   } n } n


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


#include <bits/stdc++.h> n using namespace std; n const long long K = 401, MAX = 1e18; n int n, m, k, f; n vector<pair<int, int>> adj[2 * K]; n vector<pair<int, pair<int, int>>> E; n vector<long long> sp; n long long dist[2 * K]; n bool vis[2 * K]; n unordered_map<int, int> tb; n priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> n     pq; n void dijkstra(int s) { n   memset(vis, 0, sizeof(vis)); n   for (int i = 0; i < f; i++) dist[i] = MAX; n   dist[s] = 0; n   pq.push({0, s}); n   while (!pq.empty()) { n     int v = pq.top().second, d = pq.top().first; n     vis[v] = 1; n     pq.pop(); n     for (pair<int, int> p : adj[v]) { n       int u = p.second, w = p.first; n       if (vis[u]) continue; n       if (dist[v] + w < dist[u]) { n         dist[u] = dist[v] + w; n         pq.push({dist[u], u}); n       } n     } n   } n   for (int i = s + 1; i < f; i++) n     if (dist[i] < MAX) { n       sp.push_back(dist[i]); n     } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin >> n >> m >> k; n   for (int i = 0; i < m; i++) { n     int x, y, w; n     cin >> x >> y >> w; n     E.push_back({w, {x, y}}); n   } n   sort(E.begin(), E.end()); n   for (int i = 0; i < min(k, m); i++) { n     int x = E[i].second.first, y = E[i].second.second, w = E[i].first; n     if (tb.find(x) == tb.end()) tb[x] = f++; n     if (tb.find(y) == tb.end()) tb[y] = f++; n     adj[tb[x]].push_back({w, tb[y]}); n     adj[tb[y]].push_back({w, tb[x]}); n   } n   for (int i = 0; i < f; i++) dijkstra(i); n   sort(sp.begin(), sp.end()); n   cout << sp[k - 1]; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int i, j, k, n, t, blow, head, d, h, mx, mxd; n   cin >> t; n   while (t--) { n     cin >> blow >> head; n     mx = -1; n     mxd = 0; n     while (blow > 0) { n       cin >> d >> h; n       mx = max(mx, d - h); n       mxd = max(mxd, d); n       blow--; n     } n     if (mx <= 0 && mxd < head) { n       cout << -1 << endl; n       continue; n     } n     int val = (head - mxd) / (mx); n     if ((head - mxd) % mx != 0) val++; n     val++; n     if (mxd >= head) val = 1; n     cout << val << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char tmp[120]; n int n_t, n_v, n_p; n map<string, string> lei; n vector<string> voids[1005]; n vector<string> call; n inline bool cmp(vector<string>& v1, vector<string>& v2) { n   int i = 0, j = 0; n   while (v1[i] ==    && i < v1.size()) i++; n   while (v2[j] ==    && j < v2.size()) j++; n   if (v1[i] == v2[j]) { n     i++; n     j++; n   } else { n     return false; n   } n   while (i < v1.size() && j < v2.size()) { n     if (v1[i] == v2[j]) { n       i++; n       j++; n     } else if (v1[i] ==  T  || v2[j] ==  T ) { n       i++; n       j++; n     } else { n       return false; n     } n   } n   return (v1.size() == i && v2.size() == j); n } n inline string readtype(string& t, int& p) { n   string s =   ; n   while (islower(t[p]) || isupper(t[p]) || isdigit(t[p])) s += t[p++]; n   return s; n } n int main() { n   int i, j; n   string t; n   scanf( %d , &n_t); n   for (i = 0; i < n_t; i++) { n     scanf( %s , tmp); n     gets(tmp); n     t = tmp; n     int l = t.size(); n     int p = 0; n     while (t[p] ==    ) ++p; n     for (; p < l; p++) { n       if (t[p] ==     || t[p] ==  (  || t[p] ==  )  || t[p] ==  , ) continue; n       voids[i].push_back(readtype(t, p)); n     } n   } n   scanf( %d , &n_v); n   for (i = 0; i < n_v; i++) { n     string l, nam; n     scanf( %s , tmp), l = tmp; n     scanf( %s , tmp), nam = tmp; n     lei[nam] = l; n   } n   scanf( %d , &n_p); n   gets(tmp); n   for (i = 0; i < n_p; i++) { n     call.clear(); n     gets(tmp); n     t = tmp; n     int p = 0, l = t.size(); n     while (t[p] ==    ) ++p; n     for (; p < l; p++) { n       if (t[p] ==     || t[p] ==  (  || t[p] ==  )  || t[p] ==  , ) continue; n       string ss = readtype(t, p); n       if (!call.empty()) n         call.push_back(lei[ss]); n       else n         call.push_back(ss); n     } n     int cnt = 0; n     for (int j = 0; j < n_t; j++) n       if (cmp(call, voids[j])) cnt++; n     printf( %d n , cnt); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e8 + 5; n long long MAX = 1e9; n long long MOD = 1e9 + 7; n long long Mod = 1e9 + 7; n double EPS = 0.0001; n long long gcd(long long a, long long b) { return (b == 0 ? a : gcd(b, a % b)); } n long long lcm(long long a, long long b) { return ((a * b) / gcd(a, b)); } n const int dx[] = {1, -1, 0, 0, 0, 0}; n const int dy[] = {0, 0, 1, -1, 0, 0}; n int main() { n   int n; n   string s1; n   cin >> n; n   cin >> s1; n   if (n == 1 || n == 2) { n     cout << s1 << endl; n     return 0; n   } n   vector<char> ans(n,  _ ); n   ans[(n - 1) / 2] = s1[0]; n   int indx1 = n % 2 == 0 ? n / 2 : n / 2 - 1; n   int indx2 = n % 2 == 0 ? n / 2 - 2 : n / 2 + 1; n   int dir1 = n % 2 == 0 ? 1 : -1; n   int dir2 = n % 2 == 0 ? -1 : 1; n   for (int i = 1; i <= n; i++) { n     if (i % 2 != 0 && indx1 >= 0 && indx1 < n) { n       ans[indx1] = s1[i]; n       indx1 += dir1; n     } n     if (i % 2 == 0 && indx2 >= 0 && indx2 < n) { n       ans[indx2] = s1[i]; n       indx2 += dir2; n     } n   } n   for (auto c : ans) cout << c; n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long(n), (m); n   scanf( %lld%lld , &(n), &(m)); n   ; n   vector<map<long long, long long>> vals(n); n   long long maxi = 1; n   for (long long i = 0; i < (m); i++) { n     long long(a), (b), (c); n     scanf( %lld%lld%lld , &(a), &(b), &(c)); n     ; n     --a; n     --b; n     auto it = vals[a].lower_bound(c); n     long long l; n     if (!vals[a].size() || it == vals[a].begin()) n       l = 1; n     else { n       it--; n       l = (*it).second + 1; n     } n     maxi = max(maxi, l); n     auto it2 = vals[b].upper_bound(c); n     if (!vals[b].size()) n       vals[b][c] = l; n     else { n       if (it2 != vals[b].begin()) { n         it2--; n         if ((*it2).second >= l) continue; n       } n       vals[b][c] = l; n       it2 = vals[b].lower_bound(c); n       it2++; n       vector<long long> v; n       while (it2 != vals[b].end() && (it2->second) <= l) { n         v.push_back(it2->first); n         it2++; n       } n       for (auto j : v) vals[b].erase(j); n     } n   } n   printf( %lld n , maxi); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(nullptr); n   int n, l; n   cin >> n >> l; n   vector<int> a(n, 0), b(n, 0); n   for (int i = 0; i < n; ++i) cin >> a[i]; n   for (int i = 0; i < n; ++i) cin >> b[i]; n   if (n == 1) n     cout <<  YES n ; n   else { n     vector<int> a_diff, b_diff, result; n     int check_sum = 0; n     for (int i = 1; i < n; ++i) { n       a_diff.push_back(a[i] - a[i - 1]); n       b_diff.push_back(b[i] - b[i - 1]); n     } n     a_diff.push_back(l - a[n - 1] + a[0]); n     b_diff.push_back(l - b[n - 1] + b[0]); n     for (int i = 0; i < n; ++i) a_diff.push_back(a_diff[i]); n     int i = 0, j = 0, prev_i = 0; n     while (i < 2 * n && j < n) { n       while (i < 2 * n && b_diff[0] != a_diff[i]) ++i; n       j = 0; n       prev_i = i; n       while (i < 2 * n && j < n && b_diff[j] == a_diff[i]) ++i, ++j; n       i = prev_i + 1; n       if (j == n) { n         cout <<  YES n ; n         return 0; n       } n     } n     cout <<  NO n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 2e5 + 5; n long long n, m, ans, a, b, temp; n int t; n long long num[maxn]; n long long mark[maxn]; n int main() { n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> num[i]; n     num[i] = abs(num[i]); n   } n   sort(num, num + n); n   int l = 0, r = 0; n   while (l < n) { n     while (r < n && 2 * num[l] >= num[r]) { n       r++; n     } n     ans += r - l - 1; n     l++; n   } n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n void dk_98() {} n long long gcd(long long a, long long b) { n   if (b == 0) return a; n   return gcd(b, a % b); n } n void solve() { n   int n; n   cin >> n; n   int arr[n][n]; n   for (long long i = 0; i < (int)(n); i++) { n     for (long long j = 0; j < (int)(n); j++) { n       cin >> arr[i][j]; n     } n   } n   if (n == 1) { n     cout << 0; n     return; n   } n   int ans[n]; n   memset(ans, 0, sizeof(ans)); n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < n; j++) { n       if (j != i) ans[i] = ans[i] | arr[i][j]; n     } n   } n   for (long long i = 0; i < (int)(n); i++) { n     cout << ans[i] <<    ; n   } n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   ; n   dk_98(); n   int t = 1; n   while (t--) { n     solve(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const long long int mod = 1000000000 + 7; n const long long int N = 1000000 + 6; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long int tc; n   tc = 1; n   while (tc--) { n     long long int n, m; n     cin >> n >> m; n     string s[n]; n     for (long long int i = 0; i < n; i++) cin >> s[i]; n     long long int d[m]; n     for (long long int i = 0; i < m; i++) cin >> d[i]; n     long long int ans = 0; n     for (long long int j = 0; j < m; j++) { n       map<char, long long int> p; n       long long int t = 0; n       for (long long int i = 0; i < n; i++) { n         p[s[i][j]]++; n         t = max(t, p[s[i][j]]); n       } n       ans += t * d[j]; n     } n     cout << ans; n   } n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:134217728 ) n using namespace std; n char buf[2]; n vector<int> sign; n int n; n int main() { n   sign.push_back(1); n   scanf( %s , buf); n   while (1) { n     scanf( %s , buf); n     if (buf[0] ==  = ) break; n     sign.push_back(buf[0] ==  +  ? 1 : -1); n     scanf( %s , buf); n   } n   scanf( %d , &n); n   int MIN = 0; n   int MAX = 0; n   vector<int> res; n   for (int i = 0; i < sign.size(); ++i) { n     if (sign[i] == 1) { n       MIN++; n       MAX += n; n       res.push_back(n); n     } else { n       MIN -= n; n       MAX--; n       res.push_back(1); n     } n   } n   if (MIN <= n && n <= MAX) { n     printf( Possible n ); n     int need = MAX - n; n     for (int i = 0; i < res.size(); ++i) { n       if (sign[i] == 1) { n         int d = min(need, res[i] - 1); n         res[i] -= d; n         need -= d; n       } else { n         int d = min(need, n - res[i]); n         res[i] += d; n         need -= d; n       } n     } n     printf( %d , res[0]); n     for (int i = 1; i < res.size(); ++i) { n       if (sign[i] == 1) n         printf(  +  ); n       else n         printf(  -  ); n       printf( %d , res[i]); n     } n     printf(  = %d n , n); n   } else n     printf( Impossible n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 105; n string name[MAXN], surname[MAXN]; n bool u[MAXN]; n int n; n int x1[30], x2[30]; n int Getn() { n   int res = 0; n   for (int i = 0; i < 26; i++) res += min(x1[i], x2[i]); n   return res; n } n int main() { n   cin >> n; n   for (int i = 1; i <= n; i++) cin >> name[i]; n   for (int i = 1; i <= n; i++) cin >> surname[i]; n   sort(name + 1, name + n + 1); n   sort(surname + 1, surname + n + 1); n   for (int i = 1; i <= n; i++) x1[name[i][0] -  A ]++; n   for (int i = 1; i <= n; i++) x2[surname[i][0] -  A ]++; n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= n; j++) n       if (!u[j]) { n         int c = Getn(); n         x1[name[i][0] -  A ]--; n         x2[surname[j][0] -  A ]--; n         if (Getn() != c - (name[i][0] == surname[j][0])) { n           x1[name[i][0] -  A ]++; n           x2[surname[j][0] -  A ]++; n           continue; n         } n         u[j] = true; n         cout << name[i] <<     << surname[j]; n         if (i != n) n           cout <<  ,  ; n         else n           cout << endl; n         break; n       } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e6 + 7; n unordered_map<int, int> f[N]; n int n, m, k, ans, p[N], sx[N], sy[N]; n inline int sol(int x, int y) { n   if (f[x].count(y)) return f[x][y]; n   int t; n   printf( ? %d %d n , x, y), fflush(stdout), scanf( %d , &t); n   return f[x][y] = t; n } n inline vector<int> solve(int n, int m, vector<int>& x, vector<int>& y) { n   if (n >= m) { n     if (n == 1) { n       vector<int> z; n       z.resize(1), z[0] = 1; n       ans = min(ans, sol(x[0], y[0])); n       return z; n     } else { n       vector<int> a, b; n       for (int i = 0; i < n; i += 2) a.push_back(x[i]); n       for (int i = 0; i < m; i++) b.push_back(y[i]); n       vector<int> z = solve((n + 1) / 2, m, a, b), q; n       z.push_back(m); n       int k = 0; n       for (int i = 0; i < n; i++) { n         if (i % 2 == 0) n           q.push_back(z[k++]); n         else { n           int sum = 1000000001, pos = 0; n           for (int c = z[k - 1]; c <= z[k]; c++) { n             int g = sol(x[i], y[c - 1]); n             if (sum > g) sum = g, pos = c; n           } n           q.push_back(pos), ans = min(ans, sum); n         } n       } n       return q; n     } n   } else { n     int l = 1; n     sx[l] = 1, sy[l] = 1; n     for (int i = 2; i <= m; i++) { n       while (l > 0) { n         int a = sol(x[sx[l] - 1], y[sy[l] - 1]), n             b = sol(x[sx[l] - 1], y[i - 1]); n         if (a > b) n           l--; n         else n           break; n       } n       if (sx[l] != n) l++, sx[l] = sx[l - 1] + 1, sy[l] = i; n     } n     vector<int> a, b, w; n     for (int i = 0; i < n; i++) a.push_back(x[i]); n     for (int i = 1; i <= l; i++) b.push_back(y[sy[i] - 1]), w.push_back(sy[i]); n     vector<int> z = solve(n, l, a, b), q; n     for (int i = 0; i < w.size(); i++) p[i + 1] = w[i]; n     for (int i = 0; i < z.size(); i++) q.push_back(p[z[i]]); n     return q; n   } n } n int main() { n   cin >> n >> m; n   vector<int> a, b; n   a.resize(n), b.resize(m), ans = 1000000000; n   for (int i = 0; i < n; i++) a[i] = i + 1; n   for (int i = 0; i < m; i++) b[i] = i + 1; n   solve(n, m, a, b); n   printf( ! %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n string s; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cin >> n >> s; n   s =  ?  + s +  ? ; n   int c = 0; n   bool flag = true; n   for (int i = 1; i <= n; i++) { n     if (s[i] ==  ? ) { n       c++; n       if (s[i - 1] == s[i + 1] || s[i - 1] ==  ?  || s[i + 1] ==  ? ) { n         flag = false; n       } n     } n     if (s[i] == s[i - 1] && s[i] !=  ? ) { n       flag = true; n       break; n     } n   } n   cout << (c == 0 || flag ?  NO  :  YES ) <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   int x[n], y[n]; n   for (int i = 0; i < n; i++) { n     cin >> x[i] >> y[i]; n   } n   if (n == 1) { n     cout << -1 << endl; n   } else if (n == 2) { n     if (x[0] != x[1] && y[0] != y[1]) { n       int a = fabs(x[0] - x[1]), b = fabs(y[0] - y[1]); n       cout << a * b << endl; n     } else { n       cout << -1 << endl; n     } n   } else if (n == 3 || n == 4) { n     sort(x, x + n); n     sort(y, y + n); n     int a = fabs(x[0] - x[n - 1]), b = fabs(y[0] - y[n - 1]); n     cout << a * b << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   long long t, n, i, j, k, l, r, minn, maxx, ans, x, y; n   cin >> t; n   while (t--) { n     cin >> n; n     cin >> maxx >> minn; n     for (i = 1; i < n; i++) { n       cin >> x >> y; n       maxx = max(maxx, x); n       minn = min(minn, y); n     } n     if (maxx <= minn) n       ans = 0; n     else n       ans = maxx - minn; n     cout << ans <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int q; n int main(void) { n   cin >> q; n   while (q--) { n     long long l, r, ans = 0, num = 0; n     cin >> l >> r; n     num = r - l + 1; n     if (r & 1) { n       ans -= num / 2; n       if (num & 1) ans -= l; n     } else { n       ans += num / 2; n       if (num & 1) ans += l; n     } n     cout << ans << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n #define rep(i,a,b) for(int i = (a); i < (b); ++i) n #define rrep(i,a,b) for(int i = (b); i --> (a);) n #define sz(v) int(v.size()) n using namespace std; n  n string inf, zero; n  n string add(string x, string y, int init){ n  string res(sz(x),  ? ); n  int todo = init; n  rrep(i,0,sz(x)){ n   todo += x[i] + y[i] - 2 *  0 ; n   res[i] = todo % 2 +  0 ; n   todo /= 2; n  } n  if(todo) return inf; n  return res; n } n  n int main(){ n  int n, b; n  cin >> n >> b; n  inf = string(b,  1 ); n  zero = string(b,  0 ); n  n  vector<string> fibs = {zero, zero}; // fibonacci numbers minus one n  while(fibs.back() < inf) n   fibs.push_back(add(fibs.back(), fibs[sz(fibs)-2], 1)); n  int todo = sz(fibs)-1; n  deque<pair<int, bool>> ls; n  rep(i,0,n) ls.push_back({i+1, true}); n  string lb = zero; // current lower bound n  while(!ls.empty()){ n   string ans; n   if(add(lb, fibs[todo], 0) == inf) ans =  no ; n   else { cout << ls.back().first <<     << add(lb, fibs[max(0, todo)], 0) << endl; n          cin >> ans; }  n   if(ans ==  yes ){ n    lb = add(lb, fibs[todo], 1); n    while(!ls.empty() && ls[0].second){ n     ls.pop_front(); n     todo += 2; n    } n    if(ls.empty()) break; n    ls[0].second = true; n   } else { n    ls.push_front({ls.back().first, false}); n    ls.pop_back(); n   } n   if(--todo <= 0){ n    todo += ls[0].second ? 2 : 1; n    ls.pop_front(); n   } n  } n  cout << 0 <<     << lb << endl; n } n


#include <bits/stdc++.h> n using namespace std; n char _; n const long long maxN = 200 * 1000 + 5; n const long long maxM = 5000 + 5; n const long long mod = 1000 * 1000 * 1000 + 7; n const long long base = 701; n const long long SQ = 500; n const long long maxL = 20; n int32_t main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   long long s, x; n   cin >> s >> x; n   if (s < x) { n     cout << 0 << endl; n     return 0; n   } n   long long ans = 1; n   for (long long i = 0; i < 40; i++) n     if (x >> i & 1) ans *= 2; n   long long carry = 0; n   for (long long i = 40; i >= 0; i--) { n     long long g = (s >> i & 1), f = (x >> i & 1); n     if (carry == 0 && f == 0 && g == 0) continue; n     if (carry == 0 && f == 0 && g == 1) { n       carry = 1; n       continue; n     } n     if (carry == 0 && f == 1 && g == 0) { n       cout << 0 << endl; n       return 0; n     } n     if (carry == 0 && f == 1 && g == 1) continue; n     if (carry == 1 && f == 0 && g == 0) { n       carry = 0; n       continue; n     } n     if (carry == 1 && f == 0 && g == 1) continue; n     if (carry == 1 && f == 1 && g == 0) continue; n     if (carry == 1 && f == 1 && g == 1) { n       cout << 0 << endl; n       return 0; n     } n   } n   if (s == x) ans -= 2; n   if (carry) n     cout << 0 << endl; n   else n     cout << ans << endl; 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(NULL); n   int N; n   cin >> N; n   int c; n   cin >> c; n   int A[N]; n   A[0] = 0; n   int B[N]; n   B[0] = 0; n   for (int i = 1; i < N; i++) cin >> A[i]; n   for (int i = 1; i < N; i++) cin >> B[i]; n   int f[N][2]; n   f[0][0] = 0; n   f[0][1] = c; n   for (int j = 1; j < N; j++) { n     f[j][0] = min(f[j - 1][0], f[j - 1][1]) + A[j]; n     f[j][1] = min(f[j - 1][0] + c, f[j - 1][1]) + B[j]; n   } n   for (int i = 0; i < N - 1; i++) cout << min(f[i][0], f[i][1]) <<    ; n   cout << min(f[N - 1][0], f[N - 1][1]) << endl; n   return 0; n } n


#include <bits/stdc++.h> n using ul = std::uint32_t; n using li = std::int32_t; n using ull = std::uint64_t; n using ll = std::int64_t; n using llf = long double; n ul n, m, k; n const ul maxn = 2e5; n const ul base = 998244353; n ul plus(ul a, ul b) { return a + b < base ? a + b : a + b - base; } n ul plus(ul a, ul b, ul c) { return plus(plus(a, b), c); } n ul minus(ul a, ul b) { return a < b ? a + base - b : a - b; } n ul mul(ul a, ul b) { return ull(a) * ull(b) % base; } n ul mul(ul a, ul b, ul c) { return mul(mul(a, b), c); } n ul mul(ul a, ul b, ul c, ul d) { return mul(mul(a, b, c), d); } n void exgcd(li a, li b, li& x, li& y) { n   if (b) { n     exgcd(b, a % b, y, x); n     y -= a / b * x; n   } else { n     x = 1; n     y = 0; n   } n } n ul inverse(ul a) { n   li x, y; n   exgcd(a, base, x, y); n   return x < 0 ? x + li(base) : x; n } n ul pow(ul a, ul b) { n   ul ret = 1; n   while (b) { n     if (b & 1) { n       ret = mul(a, ret); n     } n     b >>= 1; n     a = mul(a, a); n   } n   return ret; n } n ul h[maxn + 1]; n ul fac[maxn + 1]; n ul fiv[maxn + 1]; n ul twopow[maxn + 1]; n ul bi(ul a, ul b) { return mul(fac[a], fiv[b], fiv[a - b]); } n ul g(ul a) { n   ul ret = mul(base + 1 >> 1, twopow[a]); n   if (~a & 1) { n     ret = minus(ret, mul(base + 1 >> 1, bi(a, a >> 1))); n   } n   return ret; n } n int main() { n   fac[0] = 1; n   twopow[0] = 1; n   for (ul i = 1; i <= maxn; ++i) { n     fac[i] = mul(fac[i - 1], i); n     twopow[i] = plus(twopow[i - 1], twopow[i - 1]); n   } n   fiv[maxn] = inverse(fac[maxn]); n   for (ul i = maxn; i; --i) { n     fiv[i - 1] = mul(fiv[i], i); n   } n   std::scanf( %u%u , &n, &k); n   k %= base; n   for (ul i = 1; i <= n; ++i) { n     std::scanf( %u , &h[i]); n   } n   for (ul i = 1; i <= n; ++i) { n     m += h[i] != h[i % n + 1]; n   } n   ul ans = 0; n   for (ul a = 0; a <= m; ++a) { n     ans = plus(ans, mul(bi(m, a), pow(minus(k, 2), m - a), g(a))); n   } n   ans = mul(ans, pow(k, n - m)); n   std::printf( %u n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n set<int> s; n map<int, int> mm; n int a[500005]; n int main() { n   int n, m, d; n   cin >> n >> m >> d; n   for (int i = 0; i < n; i++) { n     int k; n     cin >> k; n     s.insert(k); n     a[i] = k; n   } n   set<int>::iterator it1, it2, it3; n   int sum = 0; n   for (it1 = s.begin(); it1 != s.end(); it1++) { n     sum++; n     mm[*it1] = sum; n     it2 = it1; n     while (s.upper_bound((*it2) + d) != s.end()) { n       it3 = s.upper_bound((*it2) + d); n       mm[*it3] = sum; n       it2 = it3; n       s.erase(it3); n     } n   } n   cout << sum << endl; n   for (int i = 0; i < n; i++) { n     cout << mm[a[i]] <<    ; n   } n   cout << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 1100; n const int MAXM = 1100; n const int MAXK = 100100; n int n, m, k, len[MAXK], max_len[MAXN][MAXM][4]; n int mm[][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}}; n char mmap[MAXN][MAXM], dir[MAXK], direction[256]; n vector<pair<int, int> > possible; n vector<char> sol; n int get_max_len(int r, int c, int d) { n   if (max_len[r][c][d] != -1) return max_len[r][c][d]; n   if (mmap[r][c] ==  # ) return -1; n   int &ml = max_len[r][c][d]; n   ml = 0; n   int nr = r + mm[d][0]; n   int nc = c + mm[d][1]; n   ml += 1 + get_max_len(nr, nc, d); n   return ml; n } n bool solve(int r, int c) { n   for (int i = 0; i < k; i++) { n     int d = direction[(int)dir[i]]; n     int maxd = get_max_len(r, c, d); n     if (maxd < len[i]) return false; n     r += mm[d][0] * len[i]; n     c += mm[d][1] * len[i]; n   } n   return true; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   direction[ N ] = 1; n   direction[ S ] = 0; n   direction[ E ] = 2; n   direction[ W ] = 3; n   cin >> n >> m; n   for (int i = 0; i <= n + 1; i++) n     for (int j = 0; j <= m + 1; j++) { n       if (i == 0 || i > n || j == 0 || j > m) n         mmap[i][j] =  # ; n       else n         cin >> mmap[i][j]; n       if ( A  <= mmap[i][j] && mmap[i][j] <=  Z ) n         possible.push_back(make_pair(i, j)); n       max_len[i][j][0] = -1; n       max_len[i][j][1] = -1; n       max_len[i][j][2] = -1; n       max_len[i][j][3] = -1; n     } n   cin >> k; n   for (int i = 0; i < k; i++) cin >> dir[i] >> len[i]; n   for (int i = 0; i < (int)possible.size(); i++) { n     int r = possible[i].first; n     int c = possible[i].second; n     if (solve(r, c)) sol.push_back(mmap[r][c]); n   } n   if (sol.empty()) n     cout <<  no solution  << endl; n   else { n     sort(sol.begin(), sol.end()); n     for (int i = 0; i < (int)sol.size(); i++) cout << sol[i]; n     cout << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int n, num = 1, mul; n   cin >> n; n   string s =  codeforces ; n   int ln = s.length(), a[12] = {0}; n   for (long long int i = 2; i <= 100; i++) { n     long long int curr = pow(i, 10ll); n     if (curr >= n) { n       for (int j = 0; j < 10; j++) { n         a[j] = i - 1; n         num *= (i - 1); n       } n       mul = i; n       break; n     } n   } n   int pos = 0; n   while (num < n) { n     num /= (mul - 1); n     num *= mul; n     a[pos] = mul; n     pos++; n   } n   for (int i = 0; i < 10; i++) { n     for (int j = 0; j < a[i]; j++) cout << s[i]; n   } n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MOD9 = 1e9 + 7; n const int MOD91 = 1e9 + 9; n const long long MOD12 = 1e12 + 39LL; n const long long MOD15 = 1e15 + 37LL; n const int INF = 1e9; n const int base = 1e9; n const int MAX = 2e5; n const long double EPS = 1e-10; n int n; n int a[200000]; n int main() { n   cin >> n; n   for (int i = 0; i < n; ++i) { n     cin >> a[i]; n   } n   sort(a, a + n); n   if (a[0] == a[n - 1] && a[0] == 1) { n     for (int i = 0; i < n - 1; ++i) { n       cout << a[i] <<    ; n     } n     cout << 2; n     return 0; n   } n   cout << 1 <<    ; n   for (int i = 0; i < n - 1; ++i) { n     cout << a[i] <<    ; n   } n   return 0; n } n