#include <bits/stdc++.h> n using namespace std; n const int MAX = 1010; n string a[MAX]; n int n, m; n bool visit[MAX][MAX]; n bool v[1000010]; n int b[MAX][MAX]; n int val[1000010]; n void dfs(int x, int y, int cnt) { n   if (x < 0 || y < 0 || x >= n || y >= m) { n     return; n   } n   if (visit[x][y]) { n     return; n   } n   if (a[x][y] ==  * ) { n     return; n   } n   visit[x][y] = true; n   val[cnt]++; n   b[x][y] = cnt; n   dfs(x + 1, y, cnt); n   dfs(x, y + 1, cnt); n   dfs(x - 1, y, cnt); n   dfs(x, y - 1, cnt); n } n int main() { n   ios::sync_with_stdio(false); n   cin >> n >> m; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n   } n   memset(visit, false, sizeof(visit)); n   memset(b, -1, sizeof(visit)); n   memset(val, 0, sizeof(val)); n   int cnt = 1; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       if (!visit[i][j] && a[i][j] ==  . ) { n         dfs(i, j, cnt); n         cnt++; n       } n     } n   } n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       if (a[i][j] ==  * ) { n         int temp = 1, t[5] = {0}; n         if (b[i - 1][j] != -1 && i - 1 >= 0) { n           t[0] = b[i - 1][j]; n         } n         if (b[i][j - 1] != -1 && j - 1 >= 0) { n           t[1] = b[i][j - 1]; n         } n         if (b[i + 1][j] != -1 && i + 1 < n) { n           t[2] = b[i + 1][j]; n         } n         if (b[i][j + 1] != -1 && j + 1 < m) { n           t[3] = b[i][j + 1]; n         } n         sort(t, t + 4); n         for (int k = 0; k < 4; k++) { n           if (t[k] != t[k + 1]) { n             temp += val[t[k]]; n           } n         } n         a[i][j] =  0  + (temp) % 10; n       } n     } n   } n   for (int i = 0; i < n; i++) { n     cout << a[i] <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, cnt, a[220000]; n long long sum; n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) scanf( %d , &a[i]); n   for (int l = 1; l <= n; l++) { n     sum = a[l + 1]; n     for (int r = l + 2; r <= n; r++) { n       if (a[l] < a[r]) { n         sum += a[r]; n         if (sum > (1 << ((int)log2(a[l]) + 1))) break; n         continue; n       } n       if ((a[l] ^ a[r]) == sum) cnt++; n       sum += a[r]; n       if (sum > (1 << ((int)log2(a[l]) + 1))) break; n     } n   } n   reverse(a + 1, a + n + 1); n   for (int l = 1; l <= n; l++) { n     sum = a[l + 1]; n     for (int r = l + 2; r <= n; r++) { n       if (a[l] <= a[r]) { n         sum += a[r]; n         if (sum > (1 << ((int)log2(a[l]) + 1))) break; n         continue; n       } n       if ((a[l] ^ a[r]) == sum) cnt++; n       sum += a[r]; n       if (sum > (1 << ((int)log2(a[l]) + 1))) break; n     } n   } n   printf( %d , cnt); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   int k = 1; n   int r = 0; n   int index1, index2; n   cin >> n; n   vector<pair<pair<int, int>, pair<int, int>>> s(n); n   vector<int> t(3); n   for (int i = 0; i < n; i++) { n     scanf( %i%i%i , &t[0], &t[1], &t[2]); n     sort(t.begin(), t.end()); n     s[i].first.first = t[2]; n     s[i].first.second = t[1]; n     s[i].second.first = t[0]; n     s[i].second.second = i; n     if (t[0] > r) { n       index1 = i; n       r = t[0]; n     } n   } n   sort(s.begin(), s.end()); n   for (int i = 0; i < s.size() - 1; i++) { n     if (s[i].first.first == s[i + 1].first.first && n         s[i].first.second == s[i + 1].first.second) { n       int temp = min(s[i].second.first + s[i + 1].second.first, n                      min(s[i].first.first, s[i].first.second)); n       if (temp > r) { n         r = temp; n         index1 = s[i].second.second; n         index2 = s[i + 1].second.second; n         k = 2; n       } n     } n   } n   cout << k << endl; n   if (k == 1) { n     cout << index1 + 1 << endl; n   } else n     cout << index1 + 1 <<     << index2 + 1 << endl; n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize(3) n using namespace std; n const long long N = 210; n inline long long read() { n   long long s = 0, w = 1; n   register char ch = getchar(); n   while (ch <  0  || ch >  9 ) { n     if (ch ==  - ) w = -1; n     ch = getchar(); n   } n   while (ch >=  0  && ch <=  9 ) n     s = (s << 3) + (s << 1) + (ch ^ 48), ch = getchar(); n   return s * w; n } n long long n, K, vis[N], g[N]; n struct Node { n   long long l, r; n } a[N]; n inline bool Check(long long x, long long y) { n   Node p = a[x], q = a[y]; n   if (p.l > q.l) swap(p, q); n   return (q.l < p.r && p.r < q.r); n } n signed main() { n   for (register long long T = read(); T; T--) { n     memset(vis, 0, sizeof(vis)); n     n = read(), K = read(); n     for (register long long i = 1; i <= K; i++) { n       a[i].l = read(), a[i].r = read(); n       if (a[i].l > a[i].r) swap(a[i].l, a[i].r); n       vis[a[i].l] = vis[a[i].r] = 1; n     } n     long long m = 0; n     for (register long long i = 1; i <= n * 2; i++) { n       if (!vis[i]) g[++m] = i; n     } n     long long sz = n - K; n     for (register long long i = 1; i <= sz; i++) { n       a[++K] = (Node){g[i], g[i + sz]}; n     } n     long long ans = 0; n     for (register long long i = 1; i <= n; i++) { n       for (register long long j = i + 1; j <= n; j++) { n         if (Check(i, j)) ans++; n       } n     } n     printf( %lld n , ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long a[5010], b[5010], n, dp[5010]; n int main() { n   cin >> n; n   for (long long i = 1ll; i <= n; i++) scanf( %I64d , &a[i]), b[i] = a[i]; n   sort(b + 1ll, b + n + 1ll); n   dp[0ll] = (long long)1000000000000000007; n   for (long long i = 1ll; i <= n; i++) { n     for (long long j = 1ll; j <= n; j++) { n       dp[j] = min(dp[j - 1ll], dp[j] + abs(b[j] - a[i])); n     } n   } n   cout << dp[n] << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX = 1123; n const int INF = 0x3f3f3f3f; n const long long MOD = 1000000007; n const double EPS = 1e-9; n const double PI = acos(-1); n inline int cmp(double x, double y = 0, double tol = EPS) { n   return (x <= y + tol) ? (x + tol < y) ? -1 : 0 : 1; n } n struct point { n   double x, y; n   point(double a, double b) : x(a), y(b) {} n   point() : x(0.0), y(0.0) {} n   point operator+(point q) { return point(x + q.x, y + q.y); } n   point operator-(point q) { return point(x - q.x, y - q.y); } n   point operator*(double t) { return point(x * t, y * t); } n   point operator/(double t) { return point(x / t, y / t); } n   double operator*(point q) { return x * q.x + y * q.y; } n   double operator^(point q) { return x * q.y - y * q.x; } n   double polar() { return ((y > -EPS) ? atan2(y, x) : 2 * PI + atan2(y, x)); } n   double mod() { return sqrt(x * x + y * y); } n   double mod2() { return (x * x + y * y); } n   point rotate(double t) { n     return point(x * cos(t) - y * sin(t), x * sin(t) + y * cos(t)); n   } n   int cmp(point q) const { n     if (int t = ::cmp(x, q.x)) return t; n     return ::cmp(y, q.y); n   } n   bool operator==(point q) const { return cmp(q) == 0; } n   bool operator!=(point q) const { return cmp(q) != 0; } n   bool operator<(point q) const { return cmp(q) < 0; } n }; n int n, tam; n point P[MAX]; n point Q[MAX * MAX]; n inline int ccw(point p, point q, point r) { return cmp((q - r) ^ (p - r)); } n int gcd(int a, int b) { n   if (b == 0) return a; n   return gcd(b, a % b); n } n int main() { n   cin.sync_with_stdio(false); n   cin.tie(0); n   cin >> n; n   for (int i = 0; i < n; i++) cin >> P[i].x >> P[i].y; n   if (P[0].x == P[1].x) { n     tam = 0; n     if (P[1].y > P[0].y) { n       for (int i = P[0].y; i <= P[1].y; i++) Q[tam++] = point(P[0].x, i); n     } else { n       for (int i = P[0].y; i >= P[1].y; i--) Q[tam++] = point(P[0].x, i); n     } n   } else if (P[0].y == P[1].y) { n     tam = 0; n     if (P[1].x > P[0].x) { n       for (int i = P[0].x; i <= P[1].x; i++) Q[tam++] = point(i, P[0].y); n     } else { n       for (int i = P[0].x; i >= P[1].x; i--) Q[tam++] = point(i, P[0].y); n     } n   } else { n     tam = 0; n     int g = gcd((int)(abs(P[0].y - P[1].y)), (int)(abs(P[0].x - P[1].x))); n     int p = (P[0].y - P[1].y) / g; n     int q = (P[0].x - P[1].x) / g; n     for (int i = P[0].x; q ? (i <= P[1].x) : (i >= P[1].x); i += q) n       Q[tam++] = point(i, P[0].y + ((i - P[0].x) * p) / q); n   } n   int st = 0, ed = tam - 1; n   fprintf(stderr,  %d %d n , st, ed); n   for (int i = 1; i < n; i++) { n     while (st <= ed && ccw(P[i], P[(i + 1) % n], Q[st]) < 0) st++; n     while (ed >= st && ccw(P[i], P[(i + 1) % n], Q[ed]) < 0) ed--; n   } n   cout << max(ed - st + 1, 0) <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n inline void read(int &x) { n   int v = 0, f = 1; n   char c = getchar(); n   while (!isdigit(c) && c !=  - ) c = getchar(); n   if (c ==  - ) n     f = -1; n   else n     v = (c & 15); n   while (isdigit(c = getchar())) v = (v << 1) + (v << 3) + (c & 15); n   x = v * f; n } n inline void read(long long &x) { n   long long v = 0ll, f = 1ll; n   char c = getchar(); n   while (!isdigit(c) && c !=  - ) c = getchar(); n   if (c ==  - ) n     f = -1; n   else n     v = (c & 15); n   while (isdigit(c = getchar())) v = (v << 1) + (v << 3) + (c & 15); n   x = v * f; n } n inline void readc(char &x) { n   char c; n   while (((c = getchar()) ==    ) || c ==   n ) n     ; n   x = c; n } n inline void writes(string s) { puts(s.c_str()); } n inline void writeln() { writes(  ); } n inline void writei(int x) { n   if (x < 0) { n     putchar( - ); n     x = abs(x); n   } n   if (!x) putchar( 0 ); n   char a[25]; n   int top = 0; n   while (x) { n     a[++top] = (x % 10) +  0 ; n     x /= 10; n   } n   while (top) { n     putchar(a[top]); n     top--; n   } n } n inline void writell(long long x) { n   if (x < 0) { n     putchar( - ); n     x = abs(x); n   } n   if (!x) putchar( 0 ); n   char a[25]; n   int top = 0; n   while (x) { n     a[++top] = (x % 10) +  0 ; n     x /= 10; n   } n   while (top) { n     putchar(a[top]); n     top--; n   } n } n const int dx[9] = {0, -2, -2, -1, -1, 1, 1, 2, 2}, n           dy[9] = {0, -1, 1, -2, 2, -2, 2, -1, 1}; n int n, m, i, j, dis[1005][1005][2], x, y, xx, yy; n int a, b; n bool inmap(int x, int y) { return 1 <= x && x <= n && 1 <= y && y <= m; } n void bfs(int x, int y, int typ) { n   dis[x][y][typ] = 0; n   queue<int> qx, qy; n   qx.push(x); n   qy.push(y); n   while (!qx.empty()) { n     int x = qx.front(), y = qy.front(); n     int i; n     qx.pop(); n     qy.pop(); n     for (((i)) = (1); ((i)) <= ((8)); ((i))++) { n       int nx = x + dx[i], ny = y + dy[i]; n       if (inmap(nx, ny) && dis[nx][ny][typ] > dis[x][y][typ] + 1) { n         dis[nx][ny][typ] = dis[x][y][typ] + 1; n         qx.push(nx); n         qy.push(ny); n       } n     } n   } n } n void solve(int x, int y, int typ) { n   for (;;) { n     if (dis[x][y][typ] == 0) break; n     int i; n     for (((i)) = (1); ((i)) <= ((8)); ((i))++) { n       int nx = x + dx[i], ny = y + dy[i]; n       if (nx == a && ny == b) { n         printf( %d %d n , nx, ny); n         return; n       } n     } n     for (((i)) = (1); ((i)) <= ((8)); ((i))++) { n       int nx = x + dx[i], ny = y + dy[i]; n       if (inmap(nx, ny) && dis[nx][ny][typ] == dis[x][y][typ] - 1) { n         printf( %d %d n , nx, ny); n         fflush(stdout); n         x = nx; n         y = ny; n         if (dis[x][y][typ] == 0) return; n         scanf( %d%d , &a, &b); n         break; n       } n     } n   } n } n int main() { n   scanf( %d%d , &n, &m); n   scanf( %d%d%d%d , &x, &y, &xx, &yy); n   memset((dis), (0x16), (sizeof((dis)))); n   bfs(n / 2, m / 2, 0); n   bfs(n / 2 + 1, m / 2, 1); n   double wg = dis[x][y][0]; n   double wb = dis[x][y][1]; n   double bg = dis[xx][yy][1] + 0.5; n   double bb = dis[xx][yy][0] + 0.5; n   if ((x + y) % 2 == (xx + yy) % 2) { n     if (bg < wg) { n       puts( BLACK ); n       fflush(stdout); n       scanf( %d%d , &a, &b); n       solve(xx, yy, 1); n       return 0; n     } n     if (bb < wg + 1) { n       puts( BLACK ); n       fflush(stdout); n       scanf( %d%d , &a, &b); n       solve(xx, yy, 0); n       solve(n / 2, m / 2, 1); n       return 0; n     } n     puts( WHITE ); n     fflush(stdout); n     solve(x, y, 0); n   } else { n     if (wg < bg) { n       puts( WHITE ); n       fflush(stdout); n       solve(x, y, 0); n       return 0; n     } n     if (wb < bg + 1) { n       puts( WHITE ); n       fflush(stdout); n       solve(x, y, 1); n       solve(n / 2 + 1, m / 2, 0); n       return 0; n     } n     puts( BLACK ); n     fflush(stdout); n     scanf( %d%d , &a, &b); n     solve(xx, yy, 1); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int arr[100005]; n int lfl[100005]; n int rfl[100005]; n int main() { n   int n; n   cin >> n; n   int i, j; n   for (i = 1; i <= n; i++) { n     cin >> arr[i]; n   } n   for (i = 1; i <= n; i++) { n     lfl[i] = min(lfl[i - 1] + 1, arr[i]); n   } n   long long ans = INT_MIN; n   for (i = n; i >= 1; i--) { n     rfl[i] = min(rfl[i + 1] + 1, arr[i]); n     ans = (long long)max(ans, (long long)min(lfl[i], rfl[i])); n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename A, typename B> n ostream &operator<<(ostream &os, const pair<A, B> &p) { n   return os <<  (  << p.first <<  ,   << p.second <<  ) ; n } n template <typename T_container, typename T = typename enable_if< n                                     !is_same<T_container, string>::value, n                                     typename T_container::value_type>::type> n ostream &operator<<(ostream &os, const T_container &v) { n   os <<  [ ; n   string sep; n   for (const T &x : v) os << sep << x, sep =  ,  ; n   return os <<  ] ; n } n void debug_out() { cerr << endl; } n template <typename Head, typename... Tail> n void debug_out(Head H, Tail... T) { n   cerr <<     << H; n   debug_out(T...); n } n void run_case() { n   int N; n   cin >> N; n   vector<int> A(N); n   for (int &a : A) cin >> a; n   int MX = *max_element(A.begin(), A.end()) / 3 + 100; n   int best = MX; n   for (int ones = 0; ones <= 2; ++ones) n     for (int twos = 0; twos <= 2; ++twos) { n       int threes = 0; n       for (int a : A) { n         int least = MX; n         for (int one = 0; one <= ones; ++one) n           for (int two = 0; two <= twos; ++two) { n             int want = a - two * 2 - one; n             if (want % 3 != 0 || want < 0) continue; n             least = min(least, want / 3); n           } n         threes = max(threes, least); n       } n       best = min(best, ones + twos + threes); n     } n   cout << best <<   n ; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   int tests; n   cin >> tests; n   while (tests--) run_case(); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, s = 0; n   cin >> n; n   int arr[n]; n   for (int i = 0; i < n; i++) { n     cin >> arr[i]; n     s += arr[i]; n   } n   int count = 0, k = 0; n   for (int i = 0; i < n - 1; i++) { n     k += arr[i]; n     if (k == (s - k)) count++; n   } n   cout << count; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(NULL); n   vector<int> lucky; n   for (int i = 1; i <= 9; i++) { n     for (int j = 0; j < (1 << i); j++) { n       int num = 0; n       for (int k = 0; k < i; k++) { n         if (j & (1 << k)) n           num = num * 10 + 7; n         else n           num = num * 10 + 4; n       } n       lucky.push_back(num); n     } n   } n   sort(lucky.begin(), lucky.end()); n   int n; n   cin >> n; n   for (int i = 0; i < lucky.size(); i++) { n     if (lucky[i] == n) { n       cout << i + 1; n       break; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long n, x, y; n   cin >> n >> x >> y; n   long long chis = y - n + 1; n   if (n - 1 + chis * chis >= x && chis > 0) { n     for (long long i = 0; i < n - 1; i++) cout <<  1  <<   n ; n     cout << chis; n   } else n     cout <<  -1 ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int test; n   cin >> test; n   while (test--) { n     int a, b; n     cin >> a >> b; n     cout << (a ^ b) << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n class arr { n   bool* marked; n   int* nummarked; n   int markednumber; n  n  public: n   arr() { n     marked = new bool[1000000]; n     for (int i = 0; i < 1000000; i++) { n       marked[i] = false; n     } n     nummarked = new int[1000]; n     for (int i = 0; i < 1000; i++) { n       nummarked[i] = 0; n     } n     markednumber = 0; n   } n   void mark(int i) { n     marked[i] = true; n     nummarked[i / 1000]++; n     markednumber++; n   } n   int position(int i) { n     int pr = 0; n     for (int j = 0; j < (i / 1000); j++) { n       pr += 1000; n       pr -= nummarked[j]; n     } n     for (int j = (i / 1000 * 1000); j < i; j++) { n       if (!marked[j]) { n         pr++; n       } n     } n     return pr; n   } n   int number(int i) { n     int sh = 0; n     int tek = 0; n     while ((i - sh - (1000 - nummarked[tek / 1000])) >= 0) { n       sh += (1000 - nummarked[tek / 1000]); n       tek += 1000; n     } n     while (i > sh) { n       if (!marked[tek]) { n         sh++; n       } n       tek++; n     } n     while (marked[tek]) tek++; n     return tek; n   } n }; n const int max = 200000; n int main() { n   int n; n   scanf( %d , &n); n   int* p1 = new int[n]; n   int* p2 = new int[n]; n   for (int i = 0; i < n; i++) scanf( %d , (p1 + i)); n   for (int i = 0; i < n; i++) scanf( %d , (p2 + i)); n   int* i1 = new int[max]; n   { n     arr ist; n     for (int i = 0; i < (n - 1); i++) { n       i1[i] = ist.position(p1[i]); n       ist.mark(p1[i]); n     } n   } n   int* i2 = new int[max]; n   { n     arr ist2; n     for (int i = 0; i < (n - 1); i++) { n       i2[i] = ist2.position(p2[i]); n       ist2.mark(p2[i]); n     } n   } n   int* is = new int[max]; n   for (int i = 0; i < (n - 1); i++) { n     is[i] = i1[i] + i2[i]; n   } n   for (int j = (n - 2); j > 0; j--) { n     while (is[j] > (n - 1 - j)) { n       is[j] -= (n - j); n       is[j - 1]++; n     } n   } n   while (is[0] > (n - 1)) { n     is[0] -= n; n   } n   int* ps = new int[n]; n   for (int i = 0; i < n; i++) { n     ps[i] = 0; n   } n   arr ists; n   for (int i = 0; i < (n - 1); i++) { n     ps[i] = ists.number(is[i]); n     ists.mark(ps[i]); n   } n   ps[n - 1] = ists.number(0); n   for (int i = 0; i < n; i++) { n     printf( %d  , ps[i]); n   } n   return 0; n } n


#include <bits/stdc++.h> n int main(void) { n   int n, w; n   int el[(4 * 100 * 1000)], be[(4 * 100 * 1000)]; n   int k[(4 * 100 * 1000)]; n   int i, j, z; n   scanf( %d %d , &n, &w); n   if (w == 1) { n     printf( %d n , n); n     return 0; n   } n   n--; n   for (i = 0; i <= n; i++) { n     if (i == 0) { n       scanf( %d , &z); n     } else { n       scanf( %d , &j); n       be[i - 1] = j - z; n       z = j; n     } n   } n   w--; n   for (i = 0; i <= w; i++) { n     if (i == 0) { n       scanf( %d , &z); n     } else { n       scanf( %d , &j); n       el[i - 1] = j - z; n       z = j; n     } n   } n   i = 0; n   j = -1; n   k[0] = -1; n   while (i < w) { n     while (j >= 0 && el[i] != el[j]) j = k[j]; n     i++; n     j++; n     k[i] = j; n   } n   i = 0; n   j = 0; n   z = 0; n   while (i < n) { n     while (j >= 0 && be[i] != el[j]) j = k[j]; n     i++; n     j++; n     if (j == w) { n       z++; n       j = k[j]; n     } n   } n   printf( %d n , z); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n ifstream fin( AAtest.in.txt ); n long long n, p, t[4][ T ], su; n string s; n int main() { n   ios::sync_with_stdio(0); n   cin >> n; n   for (int(i) = (0); ((i)) < ((n)); ((i))++) { n     cin >> s; n     p = s.size(); n     p--; n     t[p][s[p]]++; n     su++; n   } n   for (int(i) = (0); ((i)) < ((n)); ((i))++) { n     cin >> s; n     p = s.size(); n     p--; n     su -= abs(t[p][s[p]]); n     t[p][s[p]]--; n     su += abs(t[p][s[p]]); n   } n   cout << su / 2; n } n


#include <bits/stdc++.h> n using namespace std; n void solve(void) { n   int N; n   long int s = 0; n   cin >> N; n   for (int i = 2; i <= N; i++) s += i - 1; n   cout << s * 6 * 2 + 1 << endl; n } n int main(int argc, char const *argv[]) { n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n vector<string> v; n set<string> st; n map<string, int> mp; n int main() { n   char t[11]; n   int c; n   scanf( %d , &n); n   for (int i = 0; i < n; i++) { n     memset(t,   0 , sizeof(t)); n     scanf( %s , t); n     if (st.count(t) == 0) { n       st.insert(t); n       v.push_back(t); n       mp[t] = 1; n     } else n       mp[t]++; n   } n   int cur = mp[v[0]]; n   string res = v[0]; n   for (int i = 1; i < v.size(); i++) n     if (mp[v[i]] > cur) res = v[1]; n   printf( %s , res.c_str()); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, k; n long long cnt, sum, mx, ans = 0; n bool flag, gov[1010], vis[1010]; n vector<int> vec, edges[1010]; n void dfs(int u) { n   vis[u] = 1; n   for (int v : edges[u]) n     if (!vis[v]) dfs(v); n   ++cnt; n   flag |= gov[u]; n } n int main() { n   int u, v, i; n   cin >> n >> m >> k; n   for (i = 0; i < k; ++i) { n     scanf( %d , &u); n     gov[u] = 1; n   } n   for (i = 0; i < m; ++i) { n     scanf( %d %d , &u, &v); n     edges[u].push_back(v); n     edges[v].push_back(u); n   } n   for (i = 1; i <= n; ++i) { n     if (vis[i]) continue; n     cnt = flag = 0; n     dfs(i); n     ans += cnt * (cnt - 1) / 2; n     if (flag) n       mx = max(mx, cnt); n     else n       vec.push_back(cnt); n   } n   for (int v : vec) { n     ans += mx * v; n     mx += v; n   } n   cout << ans - m << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long INF = 4e18; n const long long MAX = 2e5 + 5; n const long long MOD = 1e9 + 7; n int n, m; n void exgcd(int a, int b, long long &c, long long &d) { n   if (a == 0) { n     c = 0; n     d = 1; n     return; n   } n   exgcd(b % a, a, d, c); n   c -= b / a * d; n } n long long gcd(int a, int b) { n   if (a == 0) return b; n   return gcd(b % a, a); n } n int g[MAX]; n bool arv[MAX], avb[MAX]; n int sz[MAX]; n pair<int, int> ma[MAX]; n vector<int> v; n vector<int> son[MAX]; n void build() { n   for (int i = 0; i < m; i++) { n     g[i] = gcd(i, m); n     sz[g[i]]++; n     son[g[i]].push_back(i); n   } n   g[m] = m; n   int x = m; n   for (int i = 2; i <= sqrt(x); i++) { n     if (x % i == 0) v.push_back(i); n     while (x % i == 0) x /= i; n   } n   if (x > 1) v.push_back(x); n } n void read() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cin >> n >> m; n   build(); n   for (int i = 0; i < n; i++) { n     int x; n     cin >> x; n     avb[x] = 1; n     if (!x) avb[m] = 1; n     sz[gcd(x, m)]--; n   } n } n void dfs(long long x) { n   if (arv[x]) return; n   for (int i : v) { n     if (i * x > m) break; n     if (g[i * x] == i * x) { n       dfs(i * x); n       ma[x] = max(ma[x], {ma[i * x].first, i * x}); n     } n   } n   ma[x].first += sz[x]; n   ; n   arv[x] = 1; n } n vector<int> ans; n void output() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout << ((long long)(ans).size()) <<   n ; n   for (int i : ans) cout << i <<    ; n   cout <<   n ; n   ; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   read(); n   for (int i = 1; i <= m; i++) n     if (g[i] == i && !arv[i]) dfs(i); n   long long now = 1, pre = 1; n   long long cod; n   while (now <= m) { n     ; n     for (long long i : son[now]) { n       if (!avb[i]) { n         long long r, y; n         long long gc = gcd(pre, m); n         exgcd(pre / gc, m / gc, r, y); n         if (r < 0) r += m; n         ans.push_back(i / gc * r % m); n         pre = i; n       } n     } n     if (ma[now].second) { n       now = ma[now].second; n     } else n       break; n   } n   output(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1010000; n long long binpow(long long a, long long b, long long c) { n   long long res = 1; n   while (b) { n     if (b & 1) res = (res * a) % c; n     a = (a * a) % c; n     b >>= 1; n   } n   return res; n } n int gcd(int a, int b) { n   if (!b) return a; n   return gcd(b, a % b); n } n int phi; n int lp[N], pr[N], k = 0; n int cnt[N]; n int n, m, mod, x; n long long go[N]; n vector<pair<int, int> > fact(int x) { n   vector<pair<int, int> > res; n   while (x > 1) { n     if (res.size() > 0 && res[(int)res.size() - 1].first == lp[x]) n       res[(int)res.size() - 1].second++; n     else n       res.push_back(make_pair(lp[x], 1)); n     x /= lp[x]; n   } n   return res; n } n long long f[N], inv[N]; n long long C(int n, int m) { n   if (n < m) return 0; n   long long res = f[n]; n   res = (res * inv[m]) % phi; n   res = (res * inv[n - m]) % phi; n   return res; n } n long long ans[N]; n int main() { n   lp[0] = lp[1] = 1; n   for (int i = 2; i <= 1000123; ++i) { n     if (!lp[i]) { n       lp[i] = i; n       pr[++k] = i; n     } n     for (int j = 1; j <= k && pr[j] <= lp[i]; ++j) { n       if ((long long)pr[j] * i > 1000123) break; n       lp[pr[j] * i] = pr[j]; n     } n   } n   cin >> n >> m >> x >> mod; n   for (int i = 1; i < mod; ++i) { n     if (binpow(x, i, mod) == 1) { n       phi = i; n       break; n     } n   } n   f[0] = inv[0] = 1; n   for (int i = 1; i <= 1000123; ++i) { n     f[i] = (f[i - 1] * i) % phi; n     inv[i] = binpow(f[i], phi - 2, phi); n   } n   go[0] = 1; n   for (int i = 1; i <= n; ++i) { n     go[i] = (go[i - 1] + C(m, i)) % phi; n   } n   for (int i = 1; i <= n; ++i) { n     ans[i] = binpow(x, go[i - 1], mod); n   } n   for (int i = n; i > 0; --i) printf( %lld  , ans[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, len = 0, max = 0, flag = 1; n   cin >> n; n   string alpha =  abcdefghijklmnopqrstuvwxyz ; n   vector<string> vs(n); n   for (int i = 0; i < n; i++) cin >> vs[i]; n   for (auto i : alpha) { n     for (auto j : alpha) { n       len = 0; n       for (auto k : vs) { n         flag = 1; n         for (auto l : k) { n           if (l != i && l != j) { n             flag = 0; n             break; n           } n         } n         if (flag) len += k.size(); n       } n       if (len > max) max = len; n     } n   } n   cout << max; 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 n; n     cin >> n; n     int arr[105]; n     for (int i = 0; i < n; i++) { n       cin >> arr[i]; n     } n     int visited[105] = {0}; n     for (int i = 0; i < n; i++) { n       visited[arr[i]]++; n     } n     int flag1 = -1; n     int flag2 = -1; n     for (int i = 0; i < 105; i++) { n       if (visited[i] == 1 and flag1 == -1) { n         flag1 = i; n       } n       if (visited[i] == 0 and flag1 == -1) { n         flag1 = i; n         flag2 = i; n         break; n       } else if (visited[i] == 0 and flag1 != -1) { n         flag2 = i; n         break; n       } n     } n     cout << flag1 + flag2 << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2e5 + 7; n vector<pair<int, int> > v[N]; n int n, m; n int foo, bar, id; n long long val[N]; n long long wt[N]; n int dep[N]; n int dp[20][N]; n int par[N]; n int x1[N]; n int x2[N]; n void dfs(int node, int baap) { n   dep[node] = dep[baap] + 1; n   dp[0][node] = baap; n   par[node] = baap; n   for (int i = 0; i < v[node].size(); i++) { n     int beta = v[node][i].first; n     int mark = v[node][i].second; n     if (beta == baap) continue; n     val[beta] = wt[mark]; n     dfs(beta, node); n   } n } n int jump(int p, int dist) { n   for (int i = 19; i >= 0; i--) { n     if ((1 << i) <= dist) { n       dist -= 1 << i; n       p = dp[i][p]; n     } n   } n   return p; n } n int lca(int p, int q) { n   if (dep[p] < dep[q]) swap(p, q); n   p = jump(p, dep[p] - dep[q]); n   if (p == q) return p; n   for (int i = 19; i >= 0; i--) { n     int pp = dp[i][p]; n     int qq = dp[i][q]; n     if (pp != qq) p = pp, q = qq; n   } n   return dp[0][p]; n } n int find(int p) { n   if (val[p] > 1) return p; n   return par[p] = find(par[p]); n } n int main() { n   cin >> n >> m; n   for (int i = 1; i < n; i++) { n     scanf( %d%d%lld , &foo, &bar, &wt[i]); n     v[foo].push_back(make_pair(bar, i)); n     v[bar].push_back(make_pair(foo, i)); n     x1[i] = foo; n     x2[i] = bar; n   } n   val[1] = 2; n   dfs(1, 0); n   for (int j = 1; j < 20; j++) { n     for (int i = 1; i <= n; i++) { n       dp[j][i] = dp[j - 1][dp[j - 1][i]]; n     } n   } n   while (m--) { n     int p, q, tp; n     long long r; n     scanf( %d , &id); n     if (id == 1) { n       scanf( %d%d%lld , &p, &q, &r); n       int lc = lca(p, q); n       tp = p; n       while (r and dep[tp] > dep[lc]) { n         r /= val[tp]; n         tp = find(par[tp]); n       } n       tp = q; n       while (r and dep[tp] > dep[lc]) { n         r /= val[tp]; n         tp = find(par[tp]); n       } n       printf( %lld n , r); n     } else { n       scanf( %d%lld , &p, &r); n       wt[p] = r; n       if (x2[p] == dp[0][x1[p]]) swap(x1[p], x2[p]); n       val[x2[p]] = r; n     } 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   long double P = 3.1415926536, a[110], n; n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n     a[i] *= a[i]; n     a[i] *= P; n   } n   for (int i = 0; i < n; i++) n     for (int j = 0; j < n - 1; j++) n       if (a[j] > a[j + 1]) swap(a[j], a[j + 1]); n   long double ans = 0; n   for (int i = n - 1; i >= 0; i -= 2) n     if (i == 0) n       ans += a[i]; n     else n       ans += a[i] - a[i - 1]; n   cout << setprecision(12) << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MN = 5e5 + 5; n int N, i, j, pre = 1; n long long ans, cur, acc; n string s; n stack<pair<int, int> > stk; n int main() { n   cin >> N >> s; n   s.insert(s.begin(),    ); n   for (i = 1; i <= N; i++) { n     if (s[i] ==  1 ) { n       int len = i - pre + 1; n       long long hm = 1LL * len * (len + 1) / 2; n       while (stk.size()) { n         if (stk.top().first <= len) { n           acc += stk.top().second; n           cur -= 1LL * stk.top().first * stk.top().second; n           stk.pop(); n         } else n           break; n       } n       ans += acc * len + hm + cur; n     } else { n       if (pre < i) { n         int len = i - pre; n         cur += 1LL * len * (acc + 1); n         stk.push({len, acc + 1}); n         acc = 0; n         for (j = len - 1; j >= 1; j--) { n           cur += j; n           stk.push({j, 1}); n         } n       } n       stk.push({0, 1}); n       pre = i + 1; n       ans += cur; n     } n   } n   printf( %lld n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int p, n; n char arr[1002], brr[1002]; n int main() { n   scanf( %s , arr); n   n = strlen(arr); n   for (int i = 0; i < n; i++) { n     if (arr[i] ==  . ) { n       p = i; n     } n   } n   if (arr[p - 1] ==  9 ) { n     printf( GOTO Vasilisa. n ); n   } else { n     if (arr[p + 1] -  0  >= 5) { n       arr[p - 1]++; n     } n     for (int i = 0; i < p; i++) { n       printf( %c , arr[i]); n     } n     printf(  n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int N, M; n const int MAX = 1e6; n vector<int> edges[MAX]; n int indeg[MAX]; n vector<int> source; n map<int, int> sink; n int reachable[20]; n const int BITMAX = 1 << 20; n int dp[BITMAX]; n void dfs(int start, int i) { n   if (sink.count(i)) { n     reachable[start] |= sink[i]; n   } else { n     for (auto j : edges[i]) dfs(start, j); n   } n } n int main() { n   int i, j, k; n   cin >> N >> M; n   for (i = 0; i < M; i++) { n     int x, y; n     scanf( %d %d , &x, &y); n     edges[x - 1].push_back(y - 1); n     indeg[y - 1]++; n   } n   int num = 1; n   for (i = 0; i < N; i++) { n     if (indeg[i] == 0) source.push_back(i); n     if (edges[i].size() == 0) { n       sink[i] = num; n       num *= 2; n     } n   } n   int sz = source.size(); n   for (i = 0; i < sz; i++) dfs(i, source[i]); n   int bitmax = 1 << sz; n   for (i = 1; i < bitmax; i++) { n     bool updated = false; n     int in = 0; n     for (j = 0; j < sz; j++) { n       if ((i >> j) & 1) { n         in++; n         if (!updated) { n           dp[i] = dp[i - (1 << j)] | reachable[j]; n           updated = true; n         } n       } n     } n     int out = 0; n     for (j = 0; j < sz; j++) { n       if ((dp[i] >> j) & 1) out++; n     } n     if (in >= out && in < sz) { n       cout <<  NO  << endl; n       return 0; n     } n   } n   cout <<  YES  << endl; n   return 0; n } n


#include <bits/stdc++.h> n const long long _INF = 1e18; n const int INF = 1e9; n using namespace std; n int T; n void solved() { n   long long n = 0; n   cin >> n; n   if (n % 2 == 1) n++; n   if (n <= 6) n     cout << 15 <<   n ; n   else n     cout << n * 5 / 2 <<   n ; n } n int main() { n   setbuf(stdout, NULL); n   ios::sync_with_stdio(0); n   cin.tie(0); n   cin >> T; n   for (int i = 0; i < (T); i++) { n     solved(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int i = 0, a = 0, b = 0; n   string s; n   cin >> s; n   while (s[i] !=   0 ) { n     if (s[i] >= 65 && s[i] <= 90) { n       a++; n     } else if (s[i] >= 97 && s[i] <= 122) n       b++; n     i++; n   } n   i = 0; n   if (a > b) { n     while (s[i] !=   0 ) { n       s[i] = toupper(s[i]); n       i++; n     } n   } else if (a < b) { n     while (s[i] !=   0 ) { n       s[i] = tolower(s[i]); n       i++; n     } n   } else if (a == b) { n     while (s[i] !=   0 ) { n       s[i] = tolower(s[i]); n       i++; n     } n   } n   cout << s; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 20; n int n, x, i, f[N]; n int main() { n   scanf( %d , &n); n   while (n--) scanf( %d , &x), f[x]++; n   for (i = N - 1; i >= 0; i--) n     if (f[i] & 1) return 0 * printf( Conan ); n   printf( Agasa ); n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 1e3 + 7; n int n, m, k; n int x[N], y[N]; n vector<int> s[N], t[N]; n int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0}; n int bor[4]; n int xnow, ynow, flg[N]; n int main() { n   scanf( %d%d%d , &n, &m, &k); n   for (int i = 1; i <= k; i++) { n     scanf( %d%d , &x[i], &y[i]), s[x[i]].push_back(y[i]), n         t[y[i]].push_back(x[i]); n     if (y[i] == 1) flg[x[i]] = 1; n   } n   int now = 1, num = 0; n   while (now <= n) { n     if (flg[now]) break; n     num++; n     now++; n   } n   if (num == 1ll * n * m - k) { n     puts( Yes ); n     return 0; n   } n   for (int i = 1; i <= n; i++) n     s[i].push_back(0), s[i].push_back(m + 1), sort(s[i].begin(), s[i].end()); n   for (int i = 1; i <= m; i++) n     t[i].push_back(0), t[i].push_back(n + 1), sort(t[i].begin(), t[i].end()); n   bor[0] = m + 1, bor[1] = n + 1, bor[2] = 0, bor[3] = 1; n   int dir = 3; n   xnow = ynow = 1; n   long long tot = 1; n   while (1) { n     dir = (dir + 1) % 4; n     if (dir == 0) { n       int pos = n           lower_bound(s[xnow].begin(), s[xnow].end(), ynow) - s[xnow].begin(); n       int to = min(s[xnow][pos], bor[dir]); n       if (to == ynow + 1) break; n       tot += to - ynow - 1; n       bor[dir] = to - 1; n       ynow = to - 1; n     } n     if (dir == 1) { n       int pos = n           lower_bound(t[ynow].begin(), t[ynow].end(), xnow) - t[ynow].begin(); n       int to = min(t[ynow][pos], bor[dir]); n       if (to == xnow + 1) break; n       tot += to - xnow - 1; n       bor[dir] = to - 1; n       xnow = to - 1; n     } n     if (dir == 2) { n       int pos = lower_bound(s[xnow].begin(), s[xnow].end(), ynow) - n                 s[xnow].begin() - 1; n       int to = max(s[xnow][pos], bor[dir]); n       if (to == ynow - 1) break; n       tot += ynow - to - 1; n       bor[dir] = to + 1; n       ynow = to + 1; n     } n     if (dir == 3) { n       int pos = lower_bound(t[ynow].begin(), t[ynow].end(), xnow) - n                 t[ynow].begin() - 1; n       int to = max(t[ynow][pos], bor[dir]); n       if (to == xnow - 1) break; n       tot += xnow - to - 1; n       bor[dir] = to + 1; n       xnow = to + 1; n     } n   } n   if (tot == 1ll * n * m - k) n     puts( Yes ); n   else n     puts( No ); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long t; n   cin >> t; n   while (t--) { n     long long n, x; n     cin >> n; n     string s =   ; n     if (n % 2 == 0) { n       s +=  1 ; n     } else n       s +=  7 ; n     x = n / 2 - 1; n     for (long long i = 0; i < (x); ++i) s +=  1 ; n     cout << s <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int arr[250]; n int N = 250; n void tmain() { n   double m = 0; n   for (int i = 0; i < N; ++i) { n     scanf( %d , arr + i); n     m += arr[i]; n   } n   m /= N; n   double dev = 0; n   for (int i = 0; i < N; ++i) { n     dev += (m - arr[i]) * (m - arr[i]); n   } n   dev /= N; n   dev = sqrt(dev); n   if (dev < (m / sqrt(3) + sqrt(m)) / 2) { n     printf( %d n , (int)(m + 0.5)); n   } else { n     printf( %d n , (int)(0.52 * (*max_element(arr, arr + 250)))); n   } n   return; n } n int main() { n   int T; n   scanf( %d , &T); n   while (T--) tmain(); n } n


#include <bits/stdc++.h> n using namespace std; n #define ll long long n ll gcd(ll a, ll b){ n     if (a == 0) n        return b; n     if (b == 0) n        return a; n     if (a == b) n         return a; n     if (a > b) n         return gcd(a-b, b); n     return gcd(a, b-a); n } n int main(){ n   ll t; n   cin>>t; n   while(t--){ n     ll k; n     cin>>k; n     ll k_ = 100-k; n     ll g = gcd(k,k_); n     ll a = k/g; n     ll b = k_/g; n     cout<<a+b<<endl; n   } n    n }


#include <bits/stdc++.h> n using namespace std; n vector<int> v; n void sep(int x) { n   if (x == 0) return; n   sep(x / 10); n   v.push_back(x % 10); n } n int main() { n   int i; n   for (int i = 1; i < 1 << 30 && v.size() < 1010; i++) { n     sep(i); n   } n   int x; n   cin >> x; n   cout << v[x - 1]; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int mod = 998244353; 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   long long int fac[n + 1]; n   fac[0] = 1; n   for (int i = 1; i <= n; i++) { n     fac[i] = fac[i - 1] * i; n     fac[i] %= mod; n   } n   long long int dp[n + 1]; n   dp[0] = 1; n   for (int i = 1; i <= n; i++) { n     dp[i] = (dp[i - 1] + fac[i - 1] - 1) * i; n     dp[i] %= mod; n   } n   cout << dp[n] << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int N, V, k, y; n vector<int> vec; n int main() { n   cin >> N >> V; n   for (int i = 1; i <= N; i++) { n     cin >> k; n     int x = 1000000000; n     for (int j = 1; j <= k; j++) { n       cin >> y; n       x = min(x, y); n     } n     if (x < V) vec.push_back(i); n   } n   cout << vec.size() << endl; n   for (int i = 0; i < vec.size(); i++) cout << vec[i] <<    ; n   return (0); n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = 1e9, mod = 1e9 + 7; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   int t; n   cin >> t; n   while (t--) { n     int a, b; n     cin >> a >> b; n     int ans = 0; n     int x = abs(a - b); n     ans += x / 5; n     x %= 5; n     ans += x / 2; n     x %= 2; n     ans += x; n     cout << ans <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 2e9; n int fa[100010], n, cnt; n bitset<1010> G[1010], S[1010], vis; n int find(int x) { n   if (fa[x] == x) return x; n   return fa[x] = find(fa[x]); n } n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) { n     int k, x; n     scanf( %d , &k); n     while (k--) { n       scanf( %d , &x); n       G[i][x] = 1; n     } n   } n   for (int i = 1; i <= n; i++) { n     fa[i] = i; n   } n   bitset<1010> t; n   int u, v; n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= n; j++) { n       t = (G[i] & G[j]); n       if (t.count() == 2) { n         u = 0, v = 0; n         for (int k = 1; k <= n; k++) { n           if (t[k]) { n             if (!u) n               u = k; n             else n               v = k; n           } n         } n         int fa_u = find(u), fa_v = find(v); n         if (fa_u != fa_v) { n           fa[fa_u] = fa_v, cnt++; n           printf( %d %d n , u, v); n           vis[u] = vis[v] = 1; n           S[u][u] = S[v][v] = S[u][v] = S[v][u] = 1; n         } n       } n     } n   } n   if (cnt == 0) { n     for (int i = 2; i <= n; i++) { n       printf( 1 %d n , i); n     } n   } else if (cnt == 1) { n     for (int i = 1; i <= n; i++) { n       if (G[i].count() < n) { n         for (int j = 1; j <= n; j++) { n           if (!vis[j]) { n             if (G[i][j]) { n               printf( %d %d n , u, j); n             } else { n               printf( %d %d n , v, j); n             } n           } n         } n         break; n       } n     } n   } else { n     for (int i = 1; i <= n; i++) { n       if (!vis[i]) { n         int minn = INF; n         for (int j = 1; j <= n; j++) { n           if (G[j][i] && (G[j] & vis).count() < minn) { n             t = (G[j] & vis), minn = t.count(); n           } n         } n         for (int j = 1; j <= n; j++) { n           if (t[j] && t == S[j]) { n             printf( %d %d n , i, j); n             break; n           } n         } n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long n; n   cin >> n; n   long long a[n], b[n]; n   for (long long i = 0; i < n; i++) { n     cin >> a[i] >> b[i]; n   } n   long long sum = 0; n   long long price = 99999; n   for (long long i = 0; i < n; i++) { n     price = min(price, b[i]); n     sum += price * a[i]; n   } n   cout << sum << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int cmp(double x, double y) { n   if (fabs(x - y) < 1e-7) return 0; n   if (x < y) return -1; n   return 1; n } n float call(double a, double b) { n   double s1, s2; n   if (cmp(a / 4, b) <= 0) { n     s1 = b + a / 8; n   } else { n     double l1, l2, t1, t2; n     l1 = b * 4; n     t1 = b + b / 2; n     l2 = a - l1; n     t2 = 2 * b; n     s1 = (l1 * t1 + l2 * t2) / a; n   } n   return s1 / (2 * b); n } n int main() { n   int n, a, b; n   scanf( %d , &n); n   for (int i = 0; i < n; i++) { n     scanf( %d %d , &a, &b); n     if (b == 0) n       printf( 1 n ); n     else if (a == 0) n       printf( 0.5 n ); n     else n       printf( %.9lf n , call(a, b)); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 100005; n int BIT[4][11][MAXN * 2], n; n void add(int BIT[], int p, int x) { n   for (int i = p; i <= n; i += ((i) & (-(i)))) BIT[i] += x; n } n int ask(int BIT[], int p) { n   int res = 0; n   for (int i = p; i; i -= ((i) & (-(i)))) res += BIT[i]; n   return res; n } n char str[MAXN], tmp[11]; n ; n int biao[233]; n int HASH(int i, int Base) { n   --i; n   return i / Base + (i % Base) * (n / Base) + min(i % Base, n % Base) + 1; n } n int main(void) { n   biao[ A ] = 0; n   biao[ G ] = 1; n   biao[ C ] = 2; n   biao[ T ] = 3; n   scanf( %s , str + 1); n   n = strlen(str + 1); n   for (int i = 1; i <= n; ++i) { n     str[i] = biao[str[i]]; n     for (int Base = 1; Base <= 10; ++Base) { n       add(BIT[str[i]][Base], HASH(i, Base), 1); n     } n   } n   int q; n   cin >> q; n   while (q--) { n     int op, l, r; n     scanf( %d%d , &op, &l); n     if (op == 1) { n       scanf( %s , tmp); n       for (int Base = 1; Base <= 10; ++Base) n         add(BIT[str[l]][Base], HASH(l, Base), -1); n       str[l] = biao[tmp[0]]; n       for (int Base = 1; Base <= 10; ++Base) n         add(BIT[str[l]][Base], HASH(l, Base), 1); n     } else { n       scanf( %d%s , &r, tmp); n       int Base = min(int(strlen(tmp)), r - l + 1), res = 0; n       for (int i = 0; i < Base; ++i) { n         res += ask(BIT[biao[tmp[i]]][Base], n                    HASH((r - l - i) / Base * Base + l + i, Base)) - n                ask(BIT[biao[tmp[i]]][Base], HASH(l + i, Base) - 1); n       } n       printf( %d n , res); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void printPath(vector<pair<int, int>> &path) { n   for (auto it : path) cout << (it.first + 1) <<     << (it.second + 1) << endl; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int n; n   cin >> n; n   long long arr[n][n]; n   memset(arr, 0, sizeof(arr)); n   pair<long long, long long> achieve[n][n]; n   arr[0][0] = 0; n   achieve[0][0] = {0, 0}; n   for (int k = 1; k < 2 * (n - 1); k++) { n     long long prev = 0; n     for (int i = 0; i < n; i++) { n       int j = k - i; n       if (j < 0 || j >= n) continue; n       pair<long long, long long> available = {2000000000000000000, -1}; n       if (i) { n         available.first = (available.first < achieve[i - 1][j].first n                                ? available.first n                                : achieve[i - 1][j].first); n         available.second = (available.second > achieve[i - 1][j].second n                                 ? available.second n                                 : achieve[i - 1][j].second); n       } n       if (j) { n         available.first = (available.first < achieve[i][j - 1].first n                                ? available.first n                                : achieve[i][j - 1].first); n         available.second = (available.second > achieve[i][j - 1].second n                                 ? available.second n                                 : achieve[i][j - 1].second); n       } n       long long diff = prev - available.first; n       arr[i][j] = diff; n       available.first += diff; n       available.second += diff; n       achieve[i][j] = available; n       prev = available.second + 1; n     } n   } n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < n; j++) cout << arr[i][j] <<    ; n     cout << endl; n   } n   int q; n   cin >> q; n   vector<pair<int, int>> path; n   while (q--) { n     long long x; n     cin >> x; n     int i = n - 1, j = n - 1; n     while (i || j) { n       x -= arr[i][j]; n       path.push_back({i, j}); n       if (i == 0) { n         j--; n         continue; n       } n       if (j == 0) { n         i--; n         continue; n       } n       if (achieve[i - 1][j].first <= x && x <= achieve[i - 1][j].second) n         i--; n       else n         j--; n     } n     path.push_back({i, j}); n     reverse(path.begin(), path.end()); n     printPath(path); n     path.clear(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n string ori; n string start; n string target; n int n; n char mapping[256]; n char mapn[256]; n char used[256]; n bool apply(int a, int b) { n   if ((mapping[a] == 0 && used[b] == false) || mapping[a] == b) { n     mapping[a] = b; n     used[b] = true; n     mapn[a]++; n     return true; n   } n   return false; n } n void undo(int a, int b) { n   mapn[a]--; n   if (mapn[a] == 0) { n     used[mapping[a]] = 0; n     mapping[a] = 0; n   } n } n bool recurse(int i, bool eqa, bool eqb) { n   if (i == ori.size()) n     return true; n   else if (eqa && eqb) { n     if (start[i] == target[i]) { n       if (apply(ori[i], start[i])) { n         if (recurse(i + 1, true, true)) { n           return true; n         } n         undo(ori[i], start[i]); n       } n     } else { n       for (int c = start[i]; c <= target[i]; c++) { n         if (apply(ori[i], c)) { n           if (recurse(i + 1, start[i] == c, target[i] == c)) { n             return true; n           } n           undo(ori[i], start[i]); n         } n       } n     } n   } else if (eqa) { n     for (int c =  a  + n; --c >= start[i];) { n       if (apply(ori[i], c)) { n         if (recurse(i + 1, start[i] == c, false)) { n           return true; n         } n         undo(ori[i], c); n         break; n       } n     } n   } else if (eqb) { n     for (int c =  a ; c <= target[i]; c++) { n       if (apply(ori[i], c)) { n         if (recurse(i + 1, false, target[i] == c)) { n           return true; n         } n         undo(ori[i], c); n         break; n       } n     } n   } else { n     return true; n   } n   return false; n } n void go() { n   cin >> n; n   cin >> ori >> start >> target; n   memset(mapping, 0, sizeof(mapping)); n   memset(mapn, 0, sizeof(mapn)); n   memset(used, 0, sizeof(used)); n   bool res = recurse(0, true, true); n   if (res) { n     cout <<  YES n ; n     set<char> unused; n     for (int i =  a ; i <  a  + n; i++) { n       if (not used[i]) { n         unused.insert(i); n       } n     } n     for (int i =  a ; i <  a  + n; i++) { n       if (mapping[i] == 0) { n         mapping[i] = *unused.begin(); n         unused.erase(unused.begin()); n       } n     } n     cout << mapping +  a ; n     cout <<   n ; n   } else { n     cout <<  NO n ; n   } n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int testn; n   cin >> testn; n   for (int testi = 1; testi <= testn; testi++) { n     go(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> g1[2111]; n vector<int> g2[2111]; n vector<int> v1, v2; n int s1[1111][1111]; n int s2[1111][1111]; n int N; n pair<int, int> dfs1(int v) { n   pair<int, int> p = {1000, 0}; n   if (v1[v]) p = {v1[v], v1[v]}; n   for (auto to : g1[v]) { n     auto cur = dfs1(to); n     p.first = min(cur.first, p.first); n     p.second = max(cur.second, p.second); n   } n   for (int i = 1; i <= p.first; ++i) n     for (int j = p.second; j <= N; ++j) s1[i][j]++; n   return p; n } n pair<int, int> dfs2(int v) { n   pair<int, int> p = {1000, 0}; n   if (v2[v]) p = {v2[v], v2[v]}; n   for (auto to : g2[v]) { n     auto cur = dfs2(to); n     p.first = min(cur.first, p.first); n     p.second = max(cur.second, p.second); n   } n   for (int i = 1; i <= p.first; ++i) n     for (int j = p.second; j <= N; ++j) s2[i][j]++; n   return p; n } n int dp[1111]; n int main() { n   cin >> N; n   int n1; n   cin >> n1; n   for (int i = 2; i <= n1; ++i) { n     int t; n     cin >> t; n     g1[t].push_back(i); n   } n   v1.assign(n1 + 1, 0); n   for (int i = 1; i <= N; ++i) { n     int t; n     cin >> t; n     v1[t] = i; n   } n   int n2; n   cin >> n2; n   for (int i = 2; i <= n2; ++i) { n     int t; n     cin >> t; n     g2[t].push_back(i); n   } n   v2.assign(n2 + 1, 0); n   for (int i = 1; i <= N; ++i) { n     int t; n     cin >> t; n     v2[t] = i; n   } n   dfs1(1); n   dfs2(1); n   for (int i = 1; i <= N; ++i) { n     for (int j = 1; j <= N; ++j) { n       s1[i][j] = min(s1[i][j], n1 - 1); n       s2[i][j] = min(s2[i][j], n2 - 1); n     } n   } n   for (int i = 1; i <= N; ++i) { n     int mx1 = s1[1][i]; n     int mx2 = s2[1][i]; n     dp[i] = max(mx1, mx2); n     for (int j = i; j >= 2; --j) { n       { n         int cur = s1[j][i]; n         dp[i] = max(dp[i], dp[j - 1] + cur); n       } n       { n         int cur = s2[j][i]; n         dp[i] = max(dp[i], dp[j - 1] + cur); n       } n     } n   } n   cout << dp[N] << endl; n } n


#include <bits/stdc++.h> n int main() { n   int s, v1, v2, t1, t2; n   scanf( %d %d %d %d %d , &s, &v1, &v2, &t1, &t2); n   int a = s * v1 + 2 * t1; n   int b = s * v2 + 2 * t2; n   if (a == b) { n     printf( Friendship n ); n   } else if (a < b) { n     printf( First n ); n   } else { n     printf( Second n ); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const long long maxn = 5e5 + 10; n long long N, arr[maxn], use[maxn]; n signed main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cin >> N; n   for (register long long i = 1; i <= N; ++i) { n     cin >> arr[i]; n   } n   sort(arr + 1, arr + 1 + N); n   long long pos = N / 2, l = pos + 1, r = N, ans = N; n   while (pos >= 1) { n     if (l <= r && arr[pos] * 2 <= arr[r]) { n       --ans, --r; n     } n     pos--; n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   string s; n   cin >> n >> s; n   int ones = 0, zeros = 0; n   for (char c : s) { n     if (c ==  n ) ones++; n     if (c ==  r ) zeros++; n   } n   while (ones--) cout <<  1  ; n   while (zeros--) cout <<  0  ; n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T, typename U> n T pow_mod(T a, U b, int mod) { n   T r = 1; n   for (; b > 0; b >>= 1) { n     if (b & 1) r = (long long)r * a % mod; n     a = (long long)a * a % mod; n   } n   return r; n } n enum bit_op { AND, OR, XOR }; n namespace bitwise_transform { n template <int P, typename T> n inline void fix(T &x) { n   if (x >= P) n     x -= P; n   else if (x < 0) n     x += P; n } n template <bit_op B, int P, bool inv = false, typename T> n void transform(T a[], int n) { n   for (int len = 1; len < n; len <<= 1) n     for (int i = 0; i < n; i += len << 1) n       for (int j = i; j < i + len; ++j) { n         T u = a[j], v = a[j + len]; n         if (B == AND) a[j] = v - u * inv, a[j + len] = u + v * (!inv); n         if (B == OR) a[j] = u * (!inv) + v, a[j + len] = u - inv * v; n         if (B == XOR) a[j] = u + v, a[j + len] = u - v; n         if (P != -1) fix<P>(a[j]), fix<P>(a[j + len]); n       } n   if (B == XOR && inv) { n     int in = pow_mod(n, P - 2, P); n     for (int i = 0; i < n; ++i) { n       if (P == -1) n         a[i] /= n; n       else n         a[i] = (long long)a[i] * in % P; n     } n   } n } n template <bit_op B, int P = -1, typename T> n vector<T> convolve(vector<T> a, vector<T> b) { n   int n = max(a.size(), b.size()), sz = 1; n   while (sz < n) sz <<= 1; n   a.resize(sz); n   b.resize(sz); n   transform<B, P>(a.data(), sz); n   transform<B, P>(b.data(), sz); n   for (int i = 0; i < sz; ++i) { n     if (P == -1) n       a[i] *= b[i]; n     else n       a[i] = (long long)a[i] * b[i] % P; n   } n   transform<B, P, true>(a.data(), sz); n   return a; n } n }  // namespace bitwise_transform n const int mod = 998244353, B = 36, C = B / 2; n inline void add(int &x, int y) { n   x += y; n   if (x >= mod) x -= mod; n } n inline int bp(int x) { return __builtin_popcount(x); } n int main() { n   ios_base::sync_with_stdio(0), cin.tie(0); n   int n, m; n   cin >> n >> m; n   vector<long long> b(B); n   for (long long i = 0, x; i < n; ++i) { n     cin >> x; n     for (int j = B - 1; j >= 0; --j) n       if ((x = min(x ^ b[j], x)) >> j & 1) { n         b[j] = x; n         break; n       } n   } n   int len = B - count(b.begin(), b.end(), 0LL); n   vector<int> y(1 << C); n   for (int i = 0; i < 1 << C; ++i) { n     int z = i; n     for (int j = C - 1; j >= 0; --j) n       if (z >> j & 1) z ^= b[j]; n     if (!z) y[i] = 1; n   } n   vector<int> ans(m + 1); n   for (int k = 0; k < B; ++k) { n     vector<int> x(1 << C); n     for (int i = 0; i < 1 << C; ++i) n       if (bp(i) == k) { n         long long z = (long long)i << C; n         for (int j = B - 1; j >= C; --j) n           if (z >> j & 1) z ^= b[j]; n         if (!(z >> C)) x[z & ((1 << C) - 1)] += 1; n       } n     auto z = bitwise_transform::convolve<XOR, mod>(x, y); n     for (int i = z.size() - 1; i >= 0; --i) n       if (z[i]) add(ans[k + bp(i)], z[i]); n   } n   int p = pow_mod(2, n - len, mod); n   for (int i = 0; i <= m; ++i) n     cout << (long long)ans[i] * p % mod <<    n [i == m]; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, k, x, y, l, r, fact[200001], inv[200001], mod = 1e9 + 7; n map<int, int> m; n int powlog(int a, int b) { n   if (b == 0) return 1; n   int ret = powlog(a, b / 2); n   if (b % 2) return 1LL * ret * ret % mod * a % mod; n   return 1LL * ret * ret % mod; n } n int C(int n, int r) { return 1LL * fact[n] * inv[r] % mod * inv[n - r] % mod; } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(NULL); n   cout.tie(NULL); n   fact[0] = inv[0] = 1; n   for (int i = 1; i <= 200000; i++) { n     fact[i] = 1LL * i * fact[i - 1] % mod; n     inv[i] = powlog(fact[i], mod - 2); n   } n   cin >> n >> k; n   for (int i = 0; i < n && cin >> x >> y; i++) m[x]++, m[y + 1]--; n   long long ans = 0; n   int prev = 0, lines = 0; n   for (auto &i : m) { n     if (lines >= k) n       ans = (ans + 1LL * (i.first - prev) * C(lines, k) % mod) % mod; n     lines += i.second; n     prev = i.first; n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); n template <typename T> n inline T range(T l, T r) { n   return uniform_int_distribution<T>(l, r)(rng); n } n inline void setin(string s) { freopen(s.c_str(),  r , stdin); } n inline void setout(string s) { freopen(s.c_str(),  w , stdout); } n template <typename T> n void Min(T &a, T b) { n   a = min(a, b); n } n template <typename T> n void Max(T &a, T b) { n   a = max(a, b); n } n const int K = 2; n const int mod[K] = {998244353, 1000000007}; n const int inf = 0x3f3f3f3f; n const int N = 1e4 + 15; n int n, q; n int dp[K][N]; n bool ans[N]; n struct query { n   int x, val, t; n   bool operator<(const query &rhs) const { n     return make_pair(x, t) < make_pair(rhs.x, rhs.t); n   } n }; n vector<query> is; n inline int add(int a, int b, int mod) { n   a += b; n   if (a >= mod) n     a -= mod; n   else if (a < 0) n     a += mod; n   return a; n } n inline void add_t(int &a, int b, int mod) { a = add(a, b, mod); } n inline int mt(int a, int b, int mod) { return 1ll * a * b % mod; } n inline void add(int x, int coef) { n   if (coef == 1) n     for (int i = n - x; i >= 0; --i) n       for (int j = 0; j < K; ++j) add_t(dp[j][i + x], dp[j][i], mod[j]); n   else n     for (int i = 0; i <= n - x; ++i) n       for (int j = 0; j < K; ++j) add_t(dp[j][i + x], -dp[j][i], mod[j]); n } n int main() { n   ios_base::sync_with_stdio(0); n   cout.tie(0); n   cin.tie(0); n   cin >> n >> q; n   for (int i = 1; i <= q; ++i) { n     int l, r, x; n     cin >> l >> r >> x; n     is.push_back({l, x, 1}); n     is.push_back({r + 1, x, -1}); n   } n   sort(is.begin(), is.end()); n   for (int j = 0; j < K; ++j) dp[j][0] = 1; n   for (int i = 1, j = 0; i <= n; ++i) { n     while (j < is.size() && is[j].x <= i) { n       add(is[j].val, is[j].t); n       ++j; n     } n     for (int y = 1; y <= n; ++y) { n       bool flag = false; n       for (int j = 0; j < K; ++j) flag |= dp[j][y]; n       ans[y] |= flag; n     } n   } n   int cnt = 0; n   for (int i = 1; i <= n; ++i) cnt += ans[i]; n   cout << cnt <<   n ; n   for (int i = 1; i <= n; ++i) n     if (ans[i]) cout << i <<    ; n   cout <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 10, M = 1e6 + 10, K = 2e4 + 10; n int head[N], h2[N], cur[N], dep[N], to[M], lim[M], nxt[M], vis[N], cnt = 1, n, n                                                                    m, s, t; n void add_edge(int u, int v, int l, int *head) { n   nxt[++cnt] = head[u], head[u] = cnt, lim[cnt] = l, to[cnt] = v; n   nxt[++cnt] = head[v], head[v] = cnt, lim[cnt] = 0, to[cnt] = u; n } n bool bfs() { n   queue<int> q; n   memset(dep, 0x3f, sizeof(dep)); n   memset(vis, 0, sizeof(vis)); n   memcpy(cur, head, sizeof(cur)); n   dep[s] = 0; n   q.push(s); n   while (!q.empty()) { n     int h = q.front(); n     vis[h] = 0; n     q.pop(); n     for (int i = head[h]; i; i = nxt[i]) n       if ((dep[to[i]] > dep[h] + 1) && lim[i]) { n         dep[to[i]] = dep[h] + 1; n         if (!vis[to[i]]) vis[to[i]] = 1, q.push(to[i]); n       } n   } n   if (dep[t] != 0x3f3f3f3f) return true; n   return false; n } n long long dfs(int rt = s, long long flow = 1e18) { n   if (rt == t) return flow; n   long long f = 0, ans = 0; n   for (int i = cur[rt]; i; i = nxt[i]) { n     cur[rt] = i; n     if (lim[i] && dep[to[i]] == dep[rt] + 1) { n       f = dfs(to[i], min(flow - ans, 1ll * lim[i])); n       if (f) { n         lim[i] -= f; n         lim[i ^ 1] += f; n         ans += f; n         if (ans == flow) break; n       } n     } n   } n   return ans; n } n long long dinic() { n   long long ans = 0, flow; n   while (bfs()) { n     while (flow = dfs()) ans += flow; n   } n   return ans; n } n vector<int> ans, edg; n int nd, P[N], Q[N], Dep[K], fa[K], siz[K], son[K], top[K], id[K], tim, eid[N]; n bool _vis[N]; n void dfs1(int rt, int f, int e = 0) { n   fa[rt] = f, siz[rt] = 1, Dep[rt] = Dep[f] + 1, eid[rt] = e; n   for (int i = h2[rt]; i; i = nxt[i]) n     if (to[i] != f) { n       dfs1(to[i], rt, lim[i]); n       siz[rt] += siz[to[i]]; n       if (siz[to[i]] > top[rt]) top[rt] = siz[to[i]], son[rt] = to[i]; n     } n } n void dfs2(int rt, int t) { n   top[rt] = t, id[rt] = ++tim; n   if (son[rt]) dfs2(son[rt], t); n   for (int i = h2[rt]; i; i = nxt[i]) n     if (to[i] != fa[rt] && to[i] != son[rt]) dfs2(to[i], to[i]); n } n void dfs3(int rt) { n   vis[rt] = 1; n   for (int i = head[rt]; i; i = nxt[i]) n     if (lim[i] && !vis[to[i]]) dfs3(to[i]); n } n void build(int l = 1, int r = n, int rt = 1) { n   P[rt] = ++nd; n   if (l == r) return Q[l] = P[rt], add_edge(P[rt], t, 1, head); n   int mid = (l + r) >> 1; n   build(l, mid, (rt << 1)), build(mid + 1, r, ((rt << 1) | 1)); n   add_edge(P[rt], P[(rt << 1)], 1e9, head), n       add_edge(P[rt], P[((rt << 1) | 1)], 1e9, head); n } n void _add_edges(int L, int R, int u, int l = 1, int r = n, int rt = 1) { n   if (L <= l && r <= R) return add_edge(u, P[rt], 1e9, head); n   int mid = (l + r) >> 1; n   if (L <= mid) _add_edges(L, R, u, l, mid, (rt << 1)); n   if (R > mid) _add_edges(L, R, u, mid + 1, r, ((rt << 1) | 1)); n } n void add_edges(int u, int v, int from) { n   while (top[u] != top[v]) { n     if (Dep[top[u]] < Dep[top[v]]) swap(u, v); n     _add_edges(id[top[u]], id[u], from); n     u = fa[top[u]]; n   } n   if (Dep[u] > Dep[v]) swap(u, v); n   if (u == v) return; n   _add_edges(id[u] + 1, id[v], from); n } n int main() { n   ios::sync_with_stdio(false); n   cin >> n >> m; n   int u, v; n   for (int i = 1; i < n; ++i) n     cin >> u >> v, add_edge(u, v, i, h2), lim[cnt] = i; n   dfs1(1, 0); n   dfs2(1, 1); n   nd = m; n   s = ++nd, t = ++nd; n   build(); n   for (int i = 1; i <= m; ++i) add_edge(s, i, 1, head); n   for (int i = 1; i <= m; ++i) { n     cin >> u >> v; n     add_edges(u, v, i); n   } n   cout << dinic() << endl; n   dfs3(s); n   for (int i = 1; i <= m; ++i) n     if (!vis[i]) ans.push_back(i); n   for (int i = 2; i <= n; ++i) n     if (vis[Q[id[i]]]) edg.push_back(eid[i]); n   cout << ans.size() <<    ; n   for (auto i : ans) cout << i <<    ; n   cout << endl << edg.size() <<    ; n   for (auto i : edg) cout << i <<    ; n } n


#include <bits/stdc++.h> n using namespace std; n long long in() { n   int32_t x; n   scanf( %d , &x); n   return x; n } n inline long long lin() { n   long long x; n   scanf( %lld , &x); n   return x; n } n inline void read(long long *a, long long n) { n   for (long long i = 0; i < n; i++) a[i] = in(); n } n inline void readL(long long *a, long long n) { n   for (long long i = 0; i < n; i++) a[i] = lin(); n } n const long long maxn = 100 + 10; n const long long mod = 1e9 + 7; n const long long MAX_VAL = 1e18 + 10; n const long long MAGIC = 350; n long long n, m; n vector<pair<long long, long long> > g[maxn]; n long long dp[maxn][maxn][27]; n long long ret[maxn][maxn]; n inline long long dfs(long long a, long long b, long long pre) { n   if (pre >= 26) return 1; n   if (dp[a][b][pre] + 1) return dp[a][b][pre]; n   for (auto u : g[a]) { n     if (u.second >= pre) { n       long long getRes = dfs(b, u.first, u.second); n       if (getRes == 1) return dp[a][b][pre] = 0; n     } n   } n   return dp[a][b][pre] = 1; n } n int32_t main() { n   n = in(), m = in(); n   memset(dp, -1, sizeof dp); n   for (long long i = 0; i < m; i++) { n     long long v = in() - 1, u = in() - 1; n     char ch; n     do { n       ch = getchar(); n     } while (!isalpha(ch)); n     g[v].push_back({u, ch -  a }); n   } n   for (long long a = 0; a < n; a++, cout <<   n ) { n     for (long long b = 0; b < n; b++) { n       ret[a][b] = dfs(a, b, 0); n       if (ret[a][b] == 0) n         cout <<  A ; n       else n         cout <<  B ; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 300000 + 10; n const long long MOD = 1000000000 + 7; n const long long INF = 10000000; n vector<long long> Poi; n unordered_map<long long, long long> koj; n long long q, SEG[4 * N][2], lazy[4 * N]; n vector<pair<int, pair<long long, long long>>> Q; n void modify(int id, int l, int r, int x) { n   if (x == -1) return; n   if (x == 0) { n     SEG[id][0] = INF; n     SEG[id][1] = l; n     lazy[id] = x; n     return; n   } n   if (x == 1) { n     SEG[id][0] = l; n     SEG[id][1] = INF; n     lazy[id] = x; n     return; n   } n   if (lazy[id] == -1) { n     swap(SEG[id][0], SEG[id][1]); n     lazy[id] = x; n     return; n   } n   if (lazy[id] == 2) { n     swap(SEG[id][0], SEG[id][1]); n     lazy[id] = -1; n     return; n   } n   if (lazy[id] == 0) { n     SEG[id][0] = l; n     SEG[id][1] = INF; n     lazy[id] = 1; n     return; n   } n   SEG[id][0] = INF; n   SEG[id][1] = l; n   lazy[id] = 0; n   return; n } n void shift(int id, int l, int r) { n   int mid = (l + r) >> 1; n   modify(id << 1, l, mid, lazy[id]); n   modify(id << 1 | 1, mid, r, lazy[id]); n   lazy[id] = -1; n   return; n } n void build(int id, int l, int r) { n   if (r - l == 1) { n     SEG[id][0] = l; n     SEG[id][1] = INF; n     return; n   } n   int mid = (l + r) >> 1; n   build(id << 1, l, mid); n   build(id << 1 | 1, mid, r); n   SEG[id][0] = l; n   SEG[id][1] = INF; n   return; n } n void update(int id, int lq, int rq, int x, int l, int r) { n   if (rq <= l || r <= lq) { n     return; n   } n   if (lq <= l && r <= rq) { n     modify(id, l, r, x); n     return; n   } n   int mid = (l + r) >> 1; n   shift(id, l, r); n   update(id << 1, lq, rq, x, l, mid); n   update(id << 1 | 1, lq, rq, x, mid, r); n   SEG[id][0] = min(SEG[id << 1][0], SEG[id << 1 | 1][0]); n   SEG[id][1] = min(SEG[id << 1][1], SEG[id << 1 | 1][1]); n   return; n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cin >> q; n   while (q--) { n     long long x, l, r; n     cin >> x >> l >> r; n     Poi.push_back(l); n     Poi.push_back(r); n     Poi.push_back(r + 1); n     Q.push_back({x, {l, r}}); n   } n   Poi.push_back(1); n   sort(Poi.begin(), Poi.end()); n   Poi.push_back(1000000000000000001); n   Poi.resize(unique(Poi.begin(), Poi.end()) - Poi.begin()); n   for (int i = 0; i < Poi.size(); i++) { n     koj[Poi[i]] = i + 1; n   } n   for (int i = 0; i < 4 * N; i++) { n     SEG[i][0] = INF; n     SEG[i][1] = INF; n   } n   memset(lazy, -1, sizeof lazy); n   build(1, 1, N); n   for (auto u : Q) { n     update(1, koj[u.second.first], koj[u.second.second] + 1, u.first - 1, 1, N); n     cout << Poi[SEG[1][0] - 1] <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int oo = 0x3f3f3f3f; n const int max0 = 1e7; n const int maxm = 400; n const int maxabs = 101; n const int max1 = 1e3; n bool a[(maxabs << 1) + 5][(maxabs << 1) + 5] = {{0}}; n int pre[(max1 << 1) + 5][(max1 << 1) + 5] = {{0}}; n int n, ax, ay, bx, by; n int walk[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}}; n char cr[4] = { U ,  D ,  R ,  L }; n bool go(const int &first) { n   putchar(cr[first]); n   ax += walk[first][0], ay += walk[first][1]; n   int ux = bx + walk[first][0], uy = by + walk[first][1]; n   if (ux >= 0 && ux <= maxabs << 1 && uy >= 0 && uy <= maxabs << 1 && a[ux][uy]) n     return 0; n   bx = ux, by = uy; n   return 1; n } n void bfs(const int &ax, const int &ay) { n   static pair<int, int> q[max0 + 5]; n   memset(pre, -1, sizeof pre); n   pre[ax + max1][ay + max1] = 4; n   int tot = 0; n   q[tot++] = make_pair(ax, ay); n   for (int i = 0; i != tot; ++i) { n     const pair<int, int> &first = q[i]; n     for (int j = (0), _end_ = (4); j != _end_; ++j) { n       int ux = first.first + walk[j][0], uy = first.second + walk[j][1]; n       if (ux < -max1 || uy < -max1 || ux >= max1 << 1 || uy >= max1 << 1 || n           pre[ux + max1][uy + max1] != -1) n         continue; n       if (ux >= 0 && ux <= maxabs << 1 && uy >= 0 && uy <= maxabs << 1 && n           a[ux][uy]) n         continue; n       pre[ux + max1][uy + max1] = j; n       q[tot++] = make_pair(ux, uy); n     } n   } n } n void trace_path(const int &first, const int &second, const int &bx, n                 const int &by, const bool &flag = 0) { n   static int qq[max0 + 5]; n   int ux = first, uy = second; n   int tot = 0; n   while (ux != bx || uy != by) { n     int tmp = pre[ux + max1][uy + max1]; n     qq[tot++] = tmp; n     ux -= walk[tmp][0], uy -= walk[tmp][1]; n   } n   reverse(qq, qq + tot); n   for (int i = 0; i != tot; ++i) { n     if (go(qq[i]) && flag) qq[tot++] = qq[i]; n     if (ax == ::bx && ay == ::by) break; n   } n } n void solve_inf() { n   memset(pre, -1, sizeof pre); n   if (ay > by) { n     swap(cr[0], cr[1]); n     for (int i = (0), _end_ = (maxabs); i != _end_; ++i) n       for (int j = (0), _end_ = (maxabs << 1); j <= _end_; ++j) n         swap(a[j][i], a[j][(maxabs << 1) - i]); n     ay = (maxabs << 1) - ay, by = (maxabs << 1) - by; n   } n   if (ax > bx) { n     swap(cr[2], cr[3]); n     for (int i = (0), _end_ = (maxabs); i != _end_; ++i) n       for (int j = (0), _end_ = (maxabs << 1); j <= _end_; ++j) n         swap(a[i][j], a[(maxabs << 1) - i][j]); n     ax = (maxabs << 1) - ax, bx = (maxabs << 1) - bx; n   } n   bfs(ax, ay), trace_path(0, 0, ax, ay); n   for (int i = (0), _end_ = (maxabs * 3); i != _end_; ++i) go(1); n   bfs(bx, by), trace_path(0, 0, bx, by); n   pair<int, int> yyt = make_pair(oo, oo); n   for (int i = (0), _end_ = (maxabs << 1); i <= _end_; ++i) n     for (int j = (0), _end_ = (maxabs << 1); j <= _end_; ++j) n       if (a[i][j]) yyt = min(yyt, make_pair(j, i)); n   swap(yyt.first, yyt.second); n   while (bx != yyt.first) go(2); n   while (ay != by || by != yyt.second - 1) go(0); n   go(3), go(0); n   while (ax != bx) go(2); n   exit(0); n } n int main() { n   scanf( %d%d%d%d%d , &ax, &ay, &bx, &by, &n), ax += maxabs, ay += maxabs, n       bx += maxabs, by += maxabs; n   if (!n) printf( -1 n ), exit(0); n   for (int i = (0), _end_ = (n); i != _end_; ++i) { n     static int first, second; n     scanf( %d%d , &first, &second); n     a[first + maxabs][second + maxabs] = 1; n   } n   bfs(ax, ay); n   if (pre[bx + max1][by + max1] == -1) printf( -1 n ), exit(0); n   if (pre[max1][max1] != -1) solve_inf(); n   trace_path(bx, by, ax, ay, 1); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   size_t n, m, q; n   cin >> n >> m >> q; n   vector<uint32_t> perm(n); n   for (size_t i = 0; i < n; ++i) { n     cin >> perm[i]; n     perm[i]--; n   } n   vector<uint32_t> a(m); n   for (size_t i = 0; i < m; ++i) { n     cin >> a[i]; n     a[i]--; n   } n   vector<uint32_t> next(n); n   next[perm.back()] = perm.front(); n   for (size_t i = 0; i < n - 1; ++i) { n     next[perm[i]] = perm[i + 1]; n   } n   constexpr static auto IMPOSSIBLE = numeric_limits<size_t>::max(); n   size_t log2n = 8 * sizeof(int) - __builtin_clz((int)n); n   vector<vector<size_t>> cycle_ends(log2n); n   for (size_t i = 0; i < log2n; ++i) { n     cycle_ends[i].resize(m); n   } n   vector<size_t> closest_next(n, IMPOSSIBLE); n   for (int i = m - 1; i >= 0; --i) { n     cycle_ends[0][i] = closest_next[next[a[i]]]; n     closest_next[a[i]] = i; n   } n   for (size_t i = 1; i < log2n; ++i) { n     for (size_t j = 0; j < m; ++j) { n       auto next = cycle_ends[i - 1][j]; n       cycle_ends[i][j] = n           next == IMPOSSIBLE ? IMPOSSIBLE : cycle_ends[i - 1][next]; n     } n   } n   vector<size_t> bits; n   for (size_t i = 0; i < log2n; ++i) { n     if (((n - 1) >> i) & 1) { n       bits.emplace_back(i); n     } n   } n   vector<size_t> min_right(m); n   size_t closest = IMPOSSIBLE; n   for (int i = m - 1; i >= 0; --i) { n     size_t next = i; n     for (auto j : bits) { n       next = cycle_ends[j][next]; n       if (next == IMPOSSIBLE) { n         break; n       } n     } n     closest = min(closest, next); n     min_right[i] = closest; n   } n   for (size_t i = 0; i < q; ++i) { n     size_t l, r; n     cin >> l >> r; n     cout << (int)(min_right[l - 1] <= r - 1); n   } n   cout <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int rel[50][50], tk[50], vis[50]; n int x[20][3], p, alone[50]; n int dfs(int i, int r, int n) { n   vis[i] = r; n   int j, k = 1; n   for (j = 1; j <= n; j++) { n     if (rel[i][j] && vis[j] == 0) { n       k += dfs(j, r, n); n     } n   } n   return k; n } n int main() { n   int n, m, i, j, k, l, l1; n   scanf( %d , &n); n   scanf( %d , &m); n   for (i = 1; i <= m; i++) { n     scanf( %d , &j); n     scanf( %d , &k); n     rel[j][k] = 1; n     rel[k][j] = 1; n   } n   l = 0; n   for (i = 1; i <= n; i++) { n     if (vis[i]) continue; n     k = dfs(i, i, n); n     if (k > 3) { n       printf( -1 ); n       return 0; n     } n     if (k == 1) { n       l++; n       alone[l] = i; n     } n   } n   memset(vis, 0, sizeof(vis)); n   l1 = 1; n   for (i = 1; i <= n; i++) { n     if (vis[i]) continue; n     k = dfs(i, i, n); n     if (k > 1) { n       p++; n       m = 0; n       for (j = 1; j <= n; j++) { n         if (vis[j] == i) { n           x[p][m] = j; n           m++; n         } n       } n       if (k == 2) { n         if (l1 > l) { n           printf( -1 ); n           return 0; n         } n         x[p][2] = alone[l1]; n         l1++; n       } n     } n   } n   p++; n   m = 0; n   for (i = l1; i <= l; i++) { n     x[p][m] = alone[i]; n     m++; n     if (m == 3) { n       m = 0; n       p++; n     } n   } n   for (i = 1; i < p; i++) { n     for (j = 0; j < 3; j++) { n       printf( %d  , x[i][j]); n     } n     printf(  n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int q; n   scanf( %d , &q); n   while (q--) { n     int n; n     scanf( %d , &n); n     vector<int> a(n); n     for (int i = 0; i < n; i++) scanf( %d , &a[i]); n     sort(a.begin(), a.end()); n     a.erase(unique(a.begin(), a.end()), a.end()); n     n = a.size(); n     int ans = a.back(); n     for (int i = n - 1; i >= 0; i--) { n       if (i >= 2) { n         if (ans > a[i] + a[i - 1] + a[i - 2]) break; n       } n       for (int j = i - 1; j >= 0; j--) { n         if (j >= 1) { n           if (ans > a[i] + a[j] + a[j - 1]) break; n         } n         if (a[i] % a[j]) { n           ans = max(ans, a[i] + a[j]); n           for (int k = j - 1; k >= 0; k--) { n             if (ans > a[i] + a[j] + a[k]) break; n             if ((a[i] % a[k]) && (a[j] % a[k])) { n               ans = max(ans, a[i] + a[j] + a[k]); n               break; n             } n           } n         } n       } n     } n     cout << ans << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 500010; n int n, a[N], rt = 1, ba[30], sta[N], top = 0; n vector<int> e[N]; n long long ans; n void dfs(int u, int ff) { n   sta[++top] = u; n   if (ff) { n     long long w = a[sta[top - 1]]; n     int i = 1; n     for (; top - ba[i] > 0; i++) n       if (w > (long long)(i + 1) * a[sta[top - ba[i]]]) n         w = (long long)(i + 1) * a[sta[top - ba[i]]]; n     if (w > (long long)(i + 1) * a[rt]) w = (long long)(i + 1) * a[rt]; n     ans += w + (long long)a[u]; n   } n   for (auto v : e[u]) n     if (v ^ ff) dfs(v, u); n   --top; n } n int main() { n   ba[0] = 1; n   for (int i = 1; i < 25; i++) ba[i] = ba[i - 1] * 2; n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) { n     scanf( %d , &a[i]); n     if (a[i] < a[rt]) rt = i; n   } n   for (int i = 1, x, y; i < n; i++) n     scanf( %d%d , &x, &y), e[x].push_back(y), e[y].push_back(x); n   dfs(rt, 0), printf( %I64d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long int mod = 1e9 + 7; n long long quickpow(long long a, long long b) { n   long long ans = 1; n   a = a % mod; n   while (b > 0) { n     if (b % 2) ans = ans * a; n     b = b / 2; n     a = a * a; n   } n   return ans; n } n int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } n long long a[500005]; n long long sum[500005]; n long long tot = 0; n int main() { n   ios::sync_with_stdio(false); n   int n; n   cin >> n; n   for (int i = 1; i <= n; i++) { n     cin >> a[i]; n   } n   sort(a + 1, a + n + 1); n   for (int i = 1; i <= n; i++) { n     sum[i] = sum[i - 1] + a[i]; n   } n   tot += sum[n]; n   for (int i = 1; i <= n - 1; i++) { n     tot += (sum[n] - sum[i - 1]); n   } n   cout << tot << endl; n } n


#include <iostream> n #include <string> n #include <vector> n #include <algorithm> n #include <sstream> n #include <queue> n #include <deque> n #include <bitset> n #include <iterator> n #include <list> n #include <stack> n #include <map> n #include <set> n #include <functional> n #include <numeric> n #include <utility> n #include <limits> n #include <time.h> n #include <math.h> n #include <stdio.h> n #include <string.h> n #include <stdlib.h> n #include <assert.h> n  n using namespace std; n  n #define ll long long int n #define nl cout<<  n ; n #define pb push_back n  n void solve(){ n     ll a[4],b[4],i; n     for(i=0;i<4;i++){ n         cin>>a[i]; n         b[i]=a[i]; n     } n     ll c=max(a[0],a[1]),d=max(a[2],a[3]); n     sort(b,b+4); n     if(max(b[3],b[2])==max(c,d) && min(b[3],b[2])==min(c,d)) n         cout<< YES n ; n     else n         cout<< NO n ; n } n  n int main(){ n     ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); n     int t=1; n     cin>>t; n     while(t--){ n         solve(); n     } n     return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> odd; n int main() { n   int n, t; n   cin >> n; n   long long cnt = 0, res = -1e9; n   for (int i = 0; i < n; i++) { n     cin >> t; n     if (abs(t) % 2 == 1) n       odd.push_back(t); n     else if (t > 0) n       cnt += t; n   } n   sort(odd.begin(), odd.end()); n   bool flag = 0; n   int sz = odd.size(); n   for (int i = sz - 1; i >= 0; i--) { n     cnt += odd[i]; n     if (abs(cnt) % 2 == 1) res = max(cnt, res); n   } n   cout << res << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long double n, k; n   cin >> n >> k; n   string s; n   cin >> s; n   set<string, greater<string> > st; n   queue<string> stk; n   stk.push(s); n   while (k && !stk.empty()) { n     string temp = stk.front(); n     stk.pop(); n     if (st.find(temp) == st.end()) { n       st.insert(temp); n       k--; n       for (long double i = 0; i < temp.length(); i++) { n         string s1 = temp; n         s1.erase(s1.begin() + i); n         if (s1.size()) stk.push(s1); n       } n     } n   } n   long double ans = 0; n   if (k == 0 || (k == 1 && stk.empty())) { n     for (auto i = st.begin(); i != st.end(); i++) { n       ans += (n - (*i).length()); n     } n     if (stk.empty()) ans += n; n     cout << ans << endl; n   } else { n     cout << -1 << endl; n   } n } n


#include <bits/stdc++.h> n int n, m; n int a[200010], b[200010], fail[200010]; n int main() { n   scanf( %d %d , &m, &n); n   --n; n   --m; n   int x, y; n   scanf( %d , &x); n   for (int i = 0; i < m; ++i) { n     scanf( %d , &y); n     b[i] = y - x; n     x = y; n   } n   scanf( %d , &x); n   for (int i = 0; i < n; ++i) { n     scanf( %d , &y); n     a[i] = y - x; n     x = y; n   } n   if (!n) return 0 * printf( %d n , m + 1); n   if (!m) return 0 * printf( 0 n ); n   fail[0] = 0; n   for (int i = 1; i < n; ++i) { n     for (x = fail[i]; x && a[x] != a[i]; x = fail[x]) n       ; n     fail[i + 1] = (a[x] == a[i]) ? x + 1 : 0; n   } n   x = y = 0; n   for (int i = 0; i < m; ++i) { n     for (; x && (a[x] != b[i] || x >= n); x = fail[x]) n       ; n     if (a[x] == b[i]) n       if (++x == n) ++y; n   } n   printf( %d n , y); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1010; n int dp[N], c[N]; n long long ncr[N][N]; n void pascal() { n   ncr[0][0] = 1; n   for (int i = 1; i < N; i++) { n     ncr[i][0] = 1; n     for (int j = 1; j <= i; j++) { n       ncr[i][j] = (ncr[i - 1][j] + ncr[i - 1][j - 1]) % 1000000007; n     } n   } n } n int main() { n   pascal(); n   int k; n   cin >> k; n   for (int i = 0; i < (int)(k); ++i) cin >> c[i]; n   long long res = 1, total = 0; n   for (int i = 0; i < (int)(k); ++i) { n     res = (res * ncr[(total + c[i] - 1)][c[i] - 1]) % 1000000007; n     total += c[i]; n   } n   cout << res << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int MSB1(long long x) { n   int d = 0; n   while ((1LL << d) <= x) d++; n   return d; n } n int main() { n   int n, m; n   cin >> n >> m; n   struct Elm { n     int l, r, x; n   }; n   vector<vector<Elm>> vals(n); n   while (m--) { n     int op; n     cin >> op; n     if (op == 1) { n       int t, l, r, x; n       cin >> t >> l >> r >> x, t--; n       vals[t].emplace_back(Elm{l, r, x}); n       continue; n     } n     int t, v; n     cin >> t >> v, t--; n     set<int> se; n     for (int l = v, r = v; t < n; t++, l += MSB1(l - 1), r += MSB1(r)) { n       for (auto &e : vals[t]) n         if (e.l <= r && l <= e.r) se.emplace(e.x); n     } n     cout << se.size() << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool isprime(int n) { n   for (int i = (2); i < (sqrt(n) + 1); ++i) n     if (n % i == 0) return false; n   return true; n } n int main() { n   vector<int> ans; n   int h[400] = {0}; n   for (int i = 4; i < 400; i += 2) h[i] = 1; n   h[2] = 0; n   h[1] = 1; n   for (int i = 3; i < 400; i += 2) n     if (!h[i]) { n       for (int j = i; j * i < 400; j += 2) n         if (!h[j * i]) h[j * i] = 1; n     } n   int n, sp, diff; n   scanf( %d , &n); n   if (n == 3) { n     printf( 1 n3 ); n     return 0; n   } n   for (int i = (n - 1); i >= (2); --i) n     if (isprime(i)) { n       sp = i; n       break; n     } n   ans.push_back(sp); n   diff = n - sp; n   if (!h[diff]) n     ans.push_back(diff); n   else { n     for (int i = (2); i < (diff); ++i) n       if (!h[i] && !h[diff - i]) { n         ans.push_back(i), ans.push_back(diff - i); n         break; n       } n   } n   printf( %d n , ans.size()); n   for (int i = (0); i < (ans.size()); ++i) printf( %d  , ans[i]); 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 n; n   cin >> n; n   vector<pair<long double, long double> > v(n); n   int k = 0; n   for (int i = 0; i < n; ++i) { n     long double a, b, c; n     cin >> a >> b >> c; n     if (c == 0) ++k; n     long double m = a * a + b * b; n     v[i].first = -a * c / m; n     v[i].second = -b * c / m; n   } n   int ans = 0; n   for (int i = 0; i < n; ++i) { n     if (v[i].first != 0 || v[i].second != 0 || k < 2) { n       map<double, int> m; n       int inf = 0; n       for (int j = i + 1; j < n; ++j) { n         long double dy = v[i].second - v[j].second, n                     dx = v[i].first - v[j].first; n         if (dx == 0) n           ++inf; n         else n           ++m[double(dy / dx)]; n       } n       ans += (inf * (inf - 1)) / 2; n       for (auto it = m.begin(); it != m.end(); ++it) { n         ans += ((it->second) * (it->second - 1)) / 2; n       } n     } else { n       --k; n       map<double, int> m; n       int inf = 0; n       for (int j = i + 1; j < n; ++j) { n         long double dy = v[i].second - v[j].second, n                     dx = v[i].first - v[j].first; n         if (dx == 0) n           ++inf; n         else n           ++m[double(dy / dx)]; n       } n       ans += ((inf - 1) * (inf - 2)) / 2; n       for (auto it = m.begin(); it != m.end(); ++it) { n         ans += ((it->second) * (it->second - 1)) / 2; n       } n       ans += n - i - 2; n     } n   } n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n vector<long long unsigned> p_pow; n vector<long long unsigned> reverse_p_pow; n const int hash_base = 31; n long long unsigned binpow(long long unsigned a, long long unsigned n) { n   long long res = 1; n   while (n) { n     if (n & 1) res *= a; n     a *= a; n     n >>= 1; n   } n   return res; n }; n const long long unsigned MAX_DEGREE = binpow(2, 63) - 1; n vector<long long unsigned> init_p_pow(int length_of_vector) { n   vector<long long unsigned> res(length_of_vector); n   long long unsigned p_pow = (long long unsigned)hash_base; n   res[0] = 1; n   for (size_t i = 1; i < length_of_vector; i++) n     if (i) res[i] = res[i - 1] * p_pow; n   return res; n } n vector<long long unsigned> init_reverse_p_pow( n     vector<long long unsigned> p_pow) { n   vector<long long unsigned> result(p_pow.size()); n   int l = p_pow.size(); n   for (int i = 0; i < l; i++) result[i] = binpow(p_pow[i], MAX_DEGREE); n   return result; n }; n vector<int> zfunction(string s) { n   int n = s.length(); n   vector<int> z(n, 0); n   for (int i = 1, l = 0, r = 0; i < n; i++) { n     if (i <= r) z[i] = min(r - i + 1, z[i - l]); n     while (i + z[i] < n && s[z[i]] == s[i + z[i]]) ++z[i]; n     if (i + z[i] - 1 > r) l = i, r = i + z[i] - 1; n   } n   return z; n } n pair<string, vector<long long unsigned> > getHashes(string s) { n   if (p_pow.size() == 0) p_pow = init_p_pow(2000); n   if (reverse_p_pow.size() == 0) reverse_p_pow = init_reverse_p_pow(p_pow); n   vector<long long unsigned> result(s.length()); n   int l = s.length(); n   for (int i = 0; i < l; i++) { n     result[i] = (s[i] -  a  + 1) * p_pow[i]; n     if (i) result[i] += result[i - 1]; n   } n   return make_pair(s, result); n } n inline long long unsigned get_hash_substr( n     pair<string, vector<long long unsigned> > h, int i, int j) { n   long long unsigned res = 0; n   res = h.second[j]; n   if (i) res -= h.second[i - 1]; n   res *= reverse_p_pow[i]; n   return res; n } n int main() { n   string t, a, b; n   cin >> t >> a >> b; n   vector<int> za = zfunction(a +  #  + t); n   vector<int> zb = zfunction(b +  #  + t); n   vector<int> ia(t.length(), 0); n   vector<int> ib(t.length(), 0); n   int la = a.length(); n   int lb = b.length(); n   int lt = t.length(); n   pair<string, vector<long long unsigned> > t_hash = getHashes(t), n                                             a_hash = getHashes(a), n                                             b_hash = getHashes(b); n   int intersection = 0; n   int i1 = la - 1; n   int j2 = 0; n   int count = 1; n   int mi = min(la, lb); n   bool f = false; n   long long unsigned ha, hb; n   while (count <= mi) { n     f = false; n     ha = a_hash.second[la - 1]; n     if (i1) ha -= a_hash.second[i1 - 1]; n     ha *= reverse_p_pow[i1]; n     hb = b_hash.second[j2]; n     hb *= reverse_p_pow[0]; n     f = (ha == hb); n     if (f) n       if (count > intersection) intersection = count; n     i1--; n     j2++; n     count++; n   } n   long long unsigned *answer = new long long unsigned[2001000]; n   int len_ans = 0; n   int c1 = 0, c2 = 0; n   for (int i = 0; i < lt; i++) { n     if (za[la + 1 + i] == la) n       ia[i] = 1; n     else n       c1++; n     if (zb[lb + 1 + i] == lb) n       ib[i] = 1; n     else n       c2++; n   } n   if (c2 + c1 == 2 * lt) { n     cout << 0; n     return 0; n   } n   for (int i = 0; i < lt; i++) { n     if (ia[i]) { n       for (int j = i + la - intersection; j < lt; j++) { n         if (ib[j]) { n           long long unsigned h = t_hash.second[j + lb - 1]; n           if (i) h -= t_hash.second[i - 1]; n           h *= reverse_p_pow[i]; n           answer[len_ans] = h; n           len_ans++; n         } n       } n     } n   } n   sort(answer, answer + len_ans); n   int ans_count = 0; n   for (int i = 0; i < len_ans - 1; i++) { n     if (answer[i] != answer[i + 1]) ans_count++; n   } n   if (len_ans) ans_count++; n   cout << ans_count; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int s = 1e6; n int vis[s]; n int main() { n   int n, t; n   scanf( %d , &n); n   for (int i = 0; i < n; i++) { n     scanf( %d , &t); n     vis[t] = 1; n   } n   printf( %d n , n); n   int num = 0; n   for (int i = 0; i < s + 2; i++) { n     if (vis[i] == 1) { n       if (vis[s - i + 1] == 0) { n         printf( %d  , s - i + 1); n         num++; n       } n     } n   } n   for (int i = 1; num < n; i++) { n     if (vis[i] == 0 && vis[s - i + 1] == 0) { n       printf( %d %d  , s - i + 1, i); n       num += 2; n     } n   } n   puts(  ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, cnt = 0, cnt2 = 0; n   cin >> n; n   int w; n   for (int i = 0; i < n; i++) { n     cin >> w; n     if (w == 100) cnt++; n     if (w == 200) cnt2++; n   } n   if (cnt == 0 && cnt2 % 2 != 0) { n     cout <<  NO ; n     return 0; n   } n   if (cnt % 2 == 0) n     cout <<  YES ; n   else n     cout <<  NO ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n const int maxn = 1e6 + 6; n int a[maxn]; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int n; n   cin >> n; n   int pt = 0; n   if (n & 1) { n     for (int i = 2; i <= n; i += 2) { n       a[pt++] = i; n     } n     for (int i = n - 1; i >= 2; i -= 2) { n       a[pt++] = i; n     } n     for (int i = 1; i <= n; i += 2) { n       a[pt++] = i; n     } n     for (int i = n - 2; i >= 1; i -= 2) { n       a[pt++] = i; n     } n     a[pt++] = n; n   } else { n     for (int i = 1; i <= n; i += 2) { n       a[pt++] = i; n     } n     for (int i = n - 1; i >= 1; i -= 2) { n       a[pt++] = i; n     } n     for (int i = 2; i <= n; i += 2) { n       a[pt++] = i; n     } n     for (int i = n - 2; i >= 2; i -= 2) { n       a[pt++] = i; n     } n     a[pt++] = n; n   } n   for (int i = 0; i < pt; i++) { n     cout << a[i] <<    ; n   } n   cout <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n const int oo = 0x3f3f3f3f; n const double eps = 1e-9; n long long gcd(long long a, long long b) { return (b == 0) ? a : gcd(b, a % b); } n struct Frac { n   long long a, b; n   Frac(long long aa = 0, long long bb = 1) { n     if (bb < 0) { n       aa = -aa; n       bb = -bb; n     } n     long long g = gcd(abs(aa), bb); n     a = aa / g; n     b = bb / g; n   } n   Frac& operator=(const Frac& f) { n     a = f.a; n     b = f.b; n     return *this; n   } n   Frac& operator+=(const Frac& f) { n     return *this = Frac(a * f.b + b * f.a, b * f.b); n   } n   Frac& operator-=(const Frac& f) { n     return *this = Frac(a * f.b - b * f.a, b * f.b); n   } n   Frac& operator*=(const Frac& f) { return *this = Frac(a * f.a, b * f.b); } n   Frac& operator/=(const Frac& f) { return *this = Frac(a * f.b, b * f.a); } n   Frac operator-() const { return Frac(-a, b); } n   Frac operator+(const Frac& f) const { return Frac(*this) += f; } n   Frac operator-(const Frac& f) const { return Frac(*this) -= f; } n   Frac operator*(const Frac& f) const { return Frac(*this) *= f; } n   Frac operator/(const Frac& f) const { return Frac(*this) /= f; } n   bool operator<(const Frac& f) const { return a * f.b < b * f.a; } n   bool operator>(const Frac& f) const { return f < *this; } n   bool operator<=(const Frac& f) const { return !(f < *this); } n   bool operator>=(const Frac& f) const { return !(*this < f); } n   bool operator==(const Frac& f) const { return !(*this < f) && !(f < *this); } n   bool operator!=(const Frac& f) const { return !(*this == f); } n }; n std::ostream& operator<<(std::ostream& os, const Frac& f) { n   return os << f.a <<  /  << f.b; n } n Frac MAX_T = Frac(200000); n struct Event { n   int from, to; n   Frac time_from, time_to; n   long long V; n   Event(int from, int to, Frac time_from, Frac time_to, long long V) n       : from(from), to(to), time_from(time_from), time_to(time_to), V(V) { n     if (this->time_from > this->time_to) { n       swap(this->from, this->to); n       swap(this->time_from, this->time_to); n     } n     if ((this->from < this->to) ^ (this->V > 0)) this->V *= -1; n     assert(this->time_from <= this->time_to); n   } n   ostream& output_me(ostream& os) const { n     return os << from <<   ->   << to <<   t0=  << time_from n               <<   t1=  << time_to <<   V=  << V; n   } n   Frac getPoint(Frac c_time) const { n     Frac dif = c_time - time_from; n     Frac pos = Frac(from) + Frac(V) * dif; n     return pos; n   } n }; n std::ostream& operator<<(std::ostream& os, const Event& e) { n   return e.output_me(os); n } n const int MAXN = 100100; n vector<int> adj[MAXN]; n int depth[MAXN]; n int parent[MAXN]; n int subsize[MAXN]; n int largest[MAXN]; n int leader[MAXN]; n vector<int> decomposition[MAXN]; n vector<Event> events[MAXN]; n int lca(int a, int b) { n   while (true) { n     if (leader[a] == leader[b]) return ((depth[a] < depth[b]) ? a : b); n     if (depth[leader[a]] > depth[leader[b]]) swap(a, b); n     b = parent[leader[b]]; n   } n } n void init1(int n, int p, int d) { n   depth[n] = d; n   parent[n] = p; n   subsize[n] = 1; n   largest[n] = -1; n   for (auto to : adj[n]) n     if (to != p) { n       init1(to, n, d + 1); n       subsize[n] += subsize[to]; n       if (largest[n] == -1 || subsize[to] > subsize[largest[n]]) { n         largest[n] = to; n       } n     } n } n void init2(int n, int l) { n   leader[n] = l; n   decomposition[l].push_back(n); n   if (largest[n] != -1) init2(largest[n], l); n   for (auto to : adj[n]) n     if (to != parent[n] && to != largest[n]) { n       decomposition[to].push_back(n); n       init2(to, to); n     } n } n bool insert(Frac start_t, int f, int r, int V) { n   if (f == r) return false; n   if (leader[f] == leader[r]) { n     events[leader[f]].push_back(Event(depth[f], depth[r], start_t, n                                       start_t + Frac(depth[f] - depth[r], V), n                                       (V))); n     return true; n   } n   assert(decomposition[leader[f]][0] != leader[f]); n   int m = decomposition[leader[f]][0]; n   Frac t_m = Frac(depth[f] - depth[m], V) + start_t; n   events[leader[f]].push_back(Event(depth[f], depth[m], start_t, t_m, (V))); n   return insert(t_m, m, r, V); n } n Frac cur_time; n bool operator<(const Event& a, const Event& b) { n   assert(a.time_from <= cur_time); n   assert(a.time_to >= cur_time); n   assert(b.time_from <= cur_time); n   assert(b.time_to >= cur_time); n   return a.getPoint(cur_time) < b.getPoint(cur_time); n } n bool operator==(const Event& a, const Event& b) { n   assert(a.time_from <= cur_time); n   assert(a.time_to >= cur_time); n   assert(b.time_from <= cur_time); n   assert(b.time_to >= cur_time); n   return a.getPoint(cur_time) == b.getPoint(cur_time); n } n Frac split_(const Event& a, const Event& b) { n   Frac T1 = a.time_from; n   if (T1 < b.time_from) T1 = b.time_from; n   Frac T2 = a.time_to; n   if (T2 > b.time_to) T2 = b.time_to; n   Frac sa = a.getPoint(T1), sb = b.getPoint(T1); n   Frac ea = a.getPoint(T2), eb = b.getPoint(T2); n   if (sa == sb) return T1; n   if (ea == eb) return T2; n   if ((sa < sb) ^ (ea < eb)) { n     Frac d1 = sa - sb; n     Frac d2 = eb - ea; n     d2 = (d2 / d1); n     d1 = Frac(1); n     Frac rel = d1 / (d1 + d2); n     Frac res = (T2 - T1) * rel + T1; n     return res; n   } n   return MAX_T; n } n int main() { n   int N, Q; n   scanf( %d%d , &N, &Q); n   for (int i = (0); i < (N); i++) adj[i].clear(); n   for (int i = (0); i < (N); i++) decomposition[i].clear(); n   for (int i = (1); i < (N); i++) { n     int a, b; n     scanf( %d%d , &a, &b); n     adj[--a].push_back(--b); n     adj[b].push_back(a); n   } n   memset(leader, -1, sizeof(leader)); n   init1(0, 0, 0); n   init2(0, 0); n   for (int q = (0); q < (Q); q++) { n     int T, V, a, b; n     scanf( %d%d%d%d , &T, &V, &a, &b); n     --a; n     --b; n     int r = lca(a, b); n     Frac t_start(T); n     Frac t_end = t_start + Frac(depth[a] + depth[b] - 2 * depth[r], V); n     bool lca_done = insert(t_start, a, r, V); n     lca_done |= insert(t_end, b, r, -V); n     if (!lca_done) { n       Frac t_mid = t_start + Frac(depth[a] - depth[r], V); n       events[leader[r]].push_back(Event(depth[r], depth[r], t_mid, t_mid, 1)); n     } n   } n   Frac split = MAX_T; n   for (int ii = (0); ii < (N); ii++) { n     vector<Event>& ev = events[ii]; n     if (int((ev).size()) == 0) continue; n     set<Event> active; n     set<tuple<Frac, bool, int> > change; n     for (int i = (0); i < (int((ev).size())); i++) { n       change.insert(make_tuple(ev[i].time_from, 0, i)); n       change.insert(make_tuple(ev[i].time_to, 1, i)); n     } n     for (auto tpl : change) { n       int id; n       bool remove; n       tie(cur_time, remove, id) = tpl; n       if (split <= cur_time) break; n       if (remove) { n         auto it = active.find(ev[id]); n         if (it != active.begin()) { n           auto it1 = it; n           it1--; n           auto it2 = it; n           it2++; n           if (it2 != active.end()) { n             Frac sp = split_(*it1, *it2); n             if (sp < split) split = sp; n           } n         } n         active.erase(it); n       } else { n         auto it = active.find(ev[id]); n         if (it != active.end()) { n           split = cur_time; n           break; n         } n         active.insert(ev[id]); n         it = active.find(ev[id]); n         if (it != active.begin()) { n           auto pr = it; n           pr--; n           Frac sp = split_(*pr, *it); n           if (sp < split) split = sp; n         } n         auto ne = it; n         ne++; n         if (ne != active.end()) { n           Frac sp = split_(*ne, *it); n           if (sp < split) split = sp; n         } n       } n     } n   } n   if (MAX_T == split) n     printf( -1 n ); n   else n     printf( %.10lf n , split.a / (double)split.b); n   return 0; n } n