#include <bits/stdc++.h> n typedef struct { n   double x, y; n } point_t; n typedef struct { n   double x, y, r; n } circle_t; n typedef struct { n   double A, B, C; n } Line; n Line zhong_chui_xian(circle_t circle1, circle_t circle2) { n   Line L1; n   point_t p; n   double k; n   p.x = (circle1.x + circle2.x) / 2; n   p.y = (circle1.y + circle2.y) / 2; n   if (fabs(circle1.y - circle2.y) < 1E-8) { n     L1.A = 1; n     L1.B = 0; n     L1.C = -p.x; n   } else if (fabs(circle1.x - circle2.x) < 1E-8) { n     L1.A = 0; n     L1.B = 1; n     L1.C = -p.y; n   } else { n     k = -1 / ((circle1.y - circle2.y) / (circle1.x - circle2.x)); n     L1.A = k; n     L1.B = -1; n     L1.C = p.y - k * p.x; n   } n   return L1; n } n int line_intersect(Line L1, Line L2, point_t& p) { n   double d, d1, d2, d3; n   d = L1.A * L2.B - L2.A * L1.B; n   if (fabs(d) < 1E-8) { n     d1 = L1.A / L2.A; n     d2 = L1.B / L2.B; n     d3 = L1.C / L2.C; n     if (fabs(d1 - d2) < 1E-8 && fabs(d2 - d3) < 1E-8) n       return 2; n     else n       return 0; n   } n   p.x = (L2.C * L1.B - L1.C * L2.B) / d; n   p.y = (L2.A * L1.C - L1.A * L2.C) / d; n   return 1; n } n circle_t yuan_guiji(circle_t circle1, circle_t circle2) { n   circle_t circle3; n   double keep1, keep2, keep3; n   keep1 = n       (circle2.r * circle2.r * circle1.x - circle1.r * circle1.r * circle2.x) / n       (circle1.r * circle1.r - circle2.r * circle2.r); n   keep2 = n       (circle2.r * circle2.r * circle1.y - circle1.r * circle1.r * circle2.y) / n       (circle1.r * circle1.r - circle2.r * circle2.r); n   keep3 = (circle2.r * circle2.r * circle1.x * circle1.x - n            circle1.r * circle1.r * circle2.x * circle2.x - n            circle1.r * circle1.r * circle2.y * circle2.y + n            circle2.r * circle2.r * circle1.y * circle1.y) / n           (circle1.r * circle1.r - circle2.r * circle2.r); n   circle3.x = -keep1; n   circle3.y = -keep2; n   circle3.r = sqrt(keep3 + keep1 * keep1 + keep2 * keep2); n   return circle3; n } n int equa(double A, double B, double C, double& x1, double& x2) { n   double f = B * B - 4 * A * C; n   if (f < 0) return -1; n   x1 = (-B + sqrt(f)) / (2 * A); n   x2 = (-B - sqrt(f)) / (2 * A); n   return 1; n } n double point_line_dis(point_t a, Line ln) { n   return (fabs(ln.A * a.x + ln.B * a.y + ln.C) / n           sqrt(ln.A * ln.A + ln.B * ln.B)); n } n int line_circle_intersect(Line ln, circle_t Y, point_t& p1, point_t& p2) { n   double t1, t2, len; n   point_t p3; n   p3.x = Y.x; n   p3.y = Y.y; n   len = point_line_dis(p3, ln); n   if (len > Y.r) return 0; n   int zz = -1; n   if (fabs(ln.B) < 1e-8) { n     p1.x = p2.x = -1.0 * ln.C / ln.A; n     zz = equa(1.0, -2.0 * Y.y, n               Y.y * Y.y + (p1.x - Y.x) * (p1.x - Y.x) - Y.r * Y.r, t1, t2); n     p1.y = t1; n     p2.y = t2; n   } else if (fabs(ln.A) < 1e-8) { n     p1.y = p2.y = -1.0 * ln.C / ln.B; n     zz = equa(1.0, -2.0 * Y.x, n               Y.x * Y.x + (p1.y - Y.y) * (p1.y - Y.y) - Y.r * Y.r, t1, t2); n     p1.x = t1; n     p2.x = t2; n   } else { n     zz = equa( n         ln.A * ln.A + ln.B * ln.B, n         2.0 * ln.A * ln.C + 2.0 * ln.A * ln.B * Y.y - 2.0 * ln.B * ln.B * Y.x, n         ln.B * ln.B * Y.x * Y.x + ln.C * ln.C + 2 * ln.B * ln.C * Y.y + n             ln.B * ln.B * Y.y * Y.y - ln.B * ln.B * Y.r * Y.r, n         t1, t2); n     p1.x = t1, p1.y = -1 * (ln.A / ln.B * t1 + ln.C / ln.B); n     p2.x = t2, p2.y = -1 * (ln.A / ln.B * t2 + ln.C / ln.B); n   } n   if (p1.x - p2.x < 1E-8 && p1.y - p2.y < 1E-8) n     return 1; n   else n     return 2; n } n double dist(double xa, double ya, double xb, double yb) { n   return sqrt((xa - xb) * (xa - xb) + (ya - yb) * (ya - yb)); n } n double max(double a, double b) { return a > b ? a : b; } n double min(double a, double b) { return a < b ? a : b; } n int circle_intersect(circle_t A, circle_t B, point_t& ia, point_t& ib) { n   if (A.x == B.x && A.y == B.y) return 5; n   double dd = dist(A.x, A.y, B.x, B.y); n   if (A.r + B.r + 1E-8 < dd) return 1; n   double k, a, b, d, aa, bb, cc, c, drt; n   k = A.r; n   a = B.x - A.x; n   b = B.y - A.y; n   c = B.r; n   d = (c * c) - (k * k) - (a * a) - (b * b); n   aa = 4 * (a * a) + 4 * (b * b); n   bb = 4 * b * d; n   cc = (d * d) - 4 * (a * a) * (k * k); n   drt = (bb * bb) - 4 * aa * cc; n   if (drt < 0) return 5; n   drt = sqrt(drt); n   ia.y = (-bb + drt) / 2 / aa; n   ib.y = (-bb - drt) / 2 / aa; n   if (fabs(a) < 1E-8) { n     ia.x = sqrt((k * k) - (ia.y * ia.y)); n     ib.x = -ia.x; n   } else { n     ia.x = (2 * b * ia.y + d) / -2 / a; n     ib.x = (2 * b * ib.y + d) / -2 / a; n   } n   ia.x += A.x; n   ia.y += A.y; n   ib.x += A.x; n   ib.y += A.y; n   if (fabs(ia.y - ib.y) < 1E-8) { n     if (fabs(A.r + B.r - dd) < 1E-8) return 2; n     if (fabs(dd - (max(A.r, B.r) - min(A.r, B.r))) < 1E-8) return 3; n   } n   return 4; n } n int main() { n   circle_t circle[3]; n   int i, count; n   Line L1, L2; n   point_t p, p1, p2; n   circle_t circle1, circle2; n   for (i = 0; i < 3; i++) n     scanf( %lf%lf%lf , &circle[i].x, &circle[i].y, &circle[i].r); n   if (fabs(circle[0].r - circle[1].r) < 1E-8) { n     L1 = zhong_chui_xian(circle[0], circle[1]); n     if (fabs(circle[1].r - circle[2].r) < 1E-8) { n       L2 = zhong_chui_xian(circle[1], circle[2]); n       line_intersect(L1, L2, p); n       printf( %0.5lf %0.5lf n , p.x, p.y); n     } else { n       circle2 = yuan_guiji(circle[1], circle[2]); n       count = line_circle_intersect(L1, circle2, p1, p2); n       if (count == 1) { n         printf( %0.5lf %0.5lf n , p1.x, p1.y); n       } else if (count == 2) { n         if ((circle[0].r / dist(circle[0].x, circle[0].y, p1.x, p1.y)) > n             (circle[0].r / dist(circle[0].x, circle[0].y, p2.x, p2.y))) n           printf( %0.5lf %0.5lf n , p1.x, p1.y); n         else n           printf( %0.5lf %0.5lf n , p2.x, p2.y); n       } n     } n   } else { n     circle1 = yuan_guiji(circle[0], circle[1]); n     if (fabs(circle[1].r - circle[2].r) < 1E-8) { n       L2 = zhong_chui_xian(circle[1], circle[2]); n       count = line_circle_intersect(L2, circle1, p1, p2); n       if (count == 1) { n         printf( %0.5lf %0.5lf n , p1.x, p1.y); n       } else if (count == 2) { n         if ((circle[0].r / dist(circle[0].x, circle[0].y, p1.x, p1.y)) > n             (circle[0].r / dist(circle[0].x, circle[0].y, p2.x, p2.y))) n           printf( %0.5lf %0.5lf n , p1.x, p1.y); n         else n           printf( %0.5lf %0.5lf n , p2.x, p2.y); n       } n     } else { n       circle2 = yuan_guiji(circle[1], circle[2]); n       count = circle_intersect(circle1, circle2, p1, p2); n       if (count == 2 || count == 3) { n         printf( %0.5lf %0.5lf n , p1.x, p1.y); n       } else if (count == 4) { n         if ((circle[0].r / dist(circle[0].x, circle[0].y, p1.x, p1.y)) > n             (circle[0].r / dist(circle[0].x, circle[0].y, p2.x, p2.y))) n           printf( %0.5lf %0.5lf n , p1.x, p1.y); n         else n           printf( %0.5lf %0.5lf n , p2.x, p2.y); n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename A, typename B> n string to_string(pair<A, B> p); n template <typename A, typename B, typename C> n string to_string(tuple<A, B, C> p); n template <typename A, typename B, typename C, typename D> n string to_string(tuple<A, B, C, D> p); n string to_string(const string& s) { return     + s +    ; } n string to_string(const char* s) { return to_string((string)s); } n string to_string(bool b) { return (b ?  true  :  false ); } n string to_string(vector<bool> v) { n   bool first = true; n   string res =  { ; n   for (int i = 0; i < static_cast<int>(v.size()); i++) { n     if (!first) { n       res +=  ,  ; n     } n     first = false; n     res += to_string(v[i]); n   } n   res +=  } ; n   return res; n } n template <size_t N> n string to_string(bitset<N> v) { n   string res =   ; n   for (size_t i = 0; i < N; i++) { n     res += static_cast<char>( 0  + v[i]); n   } n   return res; n } n template <typename A> n string to_string(A v) { n   bool first = true; n   string res =  { ; n   for (const auto& x : v) { n     if (!first) { n       res +=  ,  ; n     } n     first = false; n     res += to_string(x); n   } n   res +=  } ; n   return res; n } n template <typename A, typename B> n string to_string(pair<A, B> p) { n   return  (  + to_string(p.first) +  ,   + to_string(p.second) +  ) ; n } n template <typename A, typename B, typename C> n string to_string(tuple<A, B, C> p) { n   return  (  + to_string(get<0>(p)) +  ,   + to_string(get<1>(p)) +  ,   + n          to_string(get<2>(p)) +  ) ; n } n template <typename A, typename B, typename C, typename D> n string to_string(tuple<A, B, C, D> p) { n   return  (  + to_string(get<0>(p)) +  ,   + to_string(get<1>(p)) +  ,   + n          to_string(get<2>(p)) +  ,   + to_string(get<3>(p)) +  ) ; n } n void debug_out() { cerr << endl; } n template <typename Head, typename... Tail> n void debug_out(Head H, Tail... T) { n   cerr <<     << to_string(H); n   debug_out(T...); n } n const int mod = 1e9 + 7; n const int maxn = 200005; n const int inf = 1e9; n int tiempo[maxn], x[maxn], y[maxn], pref[maxn], dp[maxn]; n void solve() { n   int r, n; n   cin >> r >> n; n   for (int i = 1; i <= n; i++) { n     cin >> tiempo[i] >> x[i] >> y[i]; n     dp[i] = -inf; n   } n   x[0] = y[0] = 1; n   int ans = -inf; n   for (int i = 1; i <= n; i++) { n     for (int j = i - 1; j >= 0; j--) { n       if (tiempo[i] - tiempo[j] > 2 * r) { n         dp[i] = max(dp[i], pref[j] + 1); n         break; n       } n       int dist = abs(x[i] - x[j]) + abs(y[i] - y[j]); n       if (dist <= (tiempo[i] - tiempo[j])) { n         dp[i] = max(dp[i], dp[j] + 1); n       } n     } n     pref[i] = pref[i - 1]; n     pref[i] = max(pref[i], dp[i]); n     ans = max(ans, pref[i]); n   } n   cout << ans <<   n ; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   int t = 1; n   while (t--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long double eps = 1e-9; n const int inf = (1 << 30) - 1; n const long long inf64 = ((long long)1 << 62) - 1; n const long double pi = 3.1415926535897932384626433832795; n const string task =   ; n template <class T> n T sqr(T x) { n   return x * x; n } n const int nmax = 2100; n int a[nmax][nmax]; n char s[nmax][nmax]; n int n, res; n int x[nmax], y[nmax]; n int main() { n   int n; n   cin >> n; n   gets(s[0]); n   for (int i = 0; i < (int)(n); i++) gets(s[i]); n   for (int i = 0; i < (int)(n); i++) n     for (int j = 0; j < (int)(n); j++) a[i][j] = s[i][j] -  0 ; n   int res = 0; n   memset(x, 0, sizeof x); n   memset(y, 0, sizeof y); n   for (int i = n - 1; i > 0; i--) { n     for (int j = 0; i + j < n; j++) { n       int now = a[i + j][j] + x[i + j] + y[j]; n       now = now & 1; n       if (now) { n         res++; n         x[i + j]++; n         y[j]++; n       } n     } n   } n   for (int i = 0; i < (int)(n); i++) a[i][i] = (a[i][i] + x[i] + y[i]) & 1; n   memset(x, 0, sizeof x); n   memset(y, 0, sizeof y); n   for (int i = n - 1; i > 0; i--) { n     for (int j = 0; i + j < n; j++) { n       int now = a[j][i + j] + x[j] + y[i + j]; n       now = now & 1; n       if (now) { n         res++; n         y[i + j]++; n         x[j]++; n       } n     } n   } n   for (int i = 0; i < (int)(n); i++) a[i][i] = (a[i][i] + x[i] + y[i]) & 1; n   for (int i = 0; i < (int)(n); i++) n     if (a[i][i] == 1) res++; n   cout << res << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long inf = (1ll << 60); n const int maxn = 10010; n long long dp[2][maxn], c; n int p[maxn], s[maxn]; n int n, id; n int main() { n   scanf( %d%I64d , &n, &c); n   for (int i = 0; i < n; i++) scanf( %d , p + i); n   for (int i = 0; i < n; i++) scanf( %d , s + i); n   for (int i = 1; i <= n; i++) dp[0][i] = inf; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j <= i + 1; j++) dp[id ^ 1][j] = inf; n     for (int j = 0; j <= i; j++) { n       dp[id ^ 1][j] = min(dp[id ^ 1][j], dp[id][j] + p[i] + c * j); n       dp[id ^ 1][j + 1] = min(dp[id ^ 1][j + 1], dp[id][j] + s[i]); n     } n     id ^= 1; n   } n   long long res = inf; n   for (int i = 0; i <= n; i++) res = min(res, dp[id][i]); n   cout << res << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void in(long long int &number) { n   bool negative = false; n   register int c; n   number = 0; n   c = getchar(); n   if (c ==  - ) { n     negative = true; n     c = getchar(); n   } n   for (; (c > 47 && c < 58); c = getchar()) number = number * 10 + c - 48; n   if (negative) number *= -1; n } n void in(int &number) { n   bool negative = false; n   register int c; n   number = 0; n   c = getchar(); n   if (c ==  - ) { n     negative = true; n     c = getchar(); n   } n   for (; (c > 47 && c < 58); c = getchar()) number = number * 10 + c - 48; n   if (negative) number *= -1; n } n int k[100005]; n int main() { n   int n, m; n   in(n); n   in(m); n   memset(k, 0, sizeof(k)); n   vector<long long int> a(n); n   for (int i = 0; i <= n - 1; i++) in(a[i]); n   vector<int> dp(n); n   dp[n - 1] = 1; n   k[a[n - 1]] = 1; n   for (int i = n - 2; i >= 0; i--) { n     if (k[a[i]] == 0) { n       dp[i] = dp[i + 1] + 1; n       k[a[i]] = 1; n     } else n       dp[i] = dp[i + 1]; n   } n   while (m--) { n     int l; n     in(l); n     l--; n     cout << dp[l] <<   n ; n   } n   return 0; n } n


#include<bits/stdc++.h> n #define mx                          100005 n #define lli                         long long int n #define ulli                        unsigned long long int n #define mset(a,b)                   memset(a, b, sizeof(a)) n #define infile                      freopen( in.txt ,  r , stdin); n #define outfile                     freopen ( out.txt , w ,stdout); n #define fileclose                   fclose (stdin); fclose (stdout); n #define test_case                   lli T; cin>>T;for(lli t=1;t<=T;t++) n #define scani(x)                    scanf( %d ,&x); n #define printi(x)                   printf( %d n ,x); n #define scanli(x)                   scanf( %lld ,&x); n #define printli(x)                  printf( %lld n ,x); n #define frep(i,from,to)             for(lli i=from;i<=to;i++) n #define frev(i,from,to)             for(lli i=from;i>=to;i--) n  n using namespace std; n  n int main() n { n  n     //infile n     //outfile n     test_case n     { n         lli n; n         lli x,mini=2000000000,mi; n         scanli(n); n  n         frep(i,1,n) n         { n             cin>>x; n             if(x<mini) n             { n                 mi=i; n                 mini=x; n             } n         } n         cout<<n-1<<  n ; n         frep(j,1,n) n         { n             if(mi!=j) n  n             cout<<mi<<   <<j<<   <<mini<<   <<abs(mi-j)+mini<<  n ; n         } n  n  n     } n     fileclose n } n  n  n  n  n  n  n


#include <bits/stdc++.h> n #pragma GCC optimize( Ofast ) n #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma ) n #pragma GCC optimize( unroll-loops ) n using namespace std; n long long int MOD = 998244353; n double eps = 1e-12; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long int k, n, w, product = 0; n   cin >> k >> n >> w; n   for (int i = 1; i <= w; i++) { n     product += (i * k); n   } n   long long int res = product - n; n   if (res <= 0) n     cout <<  0  << endl; n   else n     cout << res << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 32005; n int n, m, i, j, f; n int a[N]; n long long ans; n int main() { n   scanf( %d%d , &n, &m); n   for (i = m + 1; i <= (n + 1) / 2; i++) { n     for (j = m + 1; j < 2 * i; j++) { n       f = (i * (2 * i - j) + (n + 1) * (2 * j - i)) / (i + j); n       f = max(f, m); n       if (f > n - m) continue; n       a[i] += n - m - f; n     } n   } n   for (i = m + 1; i <= (n + 1) / 2; i++) ans += 2 * a[i]; n   if (n % 2) ans -= a[i - 1]; n   printf( %I64d n , 3 * ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int Mod = 1e9 + 7; n const double pi = 2 * acos(0.0); n const int N = 3e5 + 5; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   int n, t; n   cin >> t; n   while (t--) { n     cin >> n; n     int x, z = 0, tot = 0; n     for (int i = 0; i < n; i++) { n       cin >> x; n       if (!x) z++; n       tot += x; n     } n     cout << z + ((tot + z) == 0) << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, x; n int a[105]; n long double dp[2][105][10005]; n const long double threshold = 1e-12; n int main() { n   scanf( %d%d , &n, &x); n   long double s = 0.0; n   for (int i = 1; i <= n; i++) { n     scanf( %d , &a[i]); n     s += a[i]; n   } n   dp[0][0][0] = 1.0; n   for (int i = 0; i < n; i++) { n     int now = i & 1, nxt = now ^ 1; n     memset(dp[nxt], 0, sizeof(dp[nxt])); n     for (int j = 0; j <= i; j++) { n       for (int k = 0; k <= 10000; k++) { n         dp[nxt][j][k] += dp[now][j][k]; n         dp[nxt][j + 1][k + a[i + 1]] += dp[now][j][k] * (j + 1) / (n - j); n       } n     } n   } n   long double ans = 0.0; n   for (int i = 0; i <= n - 1; i++) n     for (int j = 0; j <= s; j++) n       ans += dp[n & 1][i][j] * n              (min((s - j) / (n - i), ((long double)n / (n - i) + 1) * x / 2.0)); n   printf( %.10Lf n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long int MOD = 1000000007; n const long double PI = 3.14159265; n long long int powerWithMod(long long int base, long long int exponent, n                            long long int MODulus = LLONG_MAX) { n   long long int ansult = 1; n   base %= MODulus; n   while (exponent > 0) { n     if (exponent % 2 == 1) ansult = (ansult * base) % MODulus; n     exponent >>= 1; n     base = (base * base) % MODulus; n   } n   return ansult; n } n long long int gcdExtended(long long int a, long long int b, long long int *x, n                           long long int *y) { n   cout << a <<     << b <<     << *x <<     << *y <<   n ; n   if (a == 0) { n     *x = 0, *y = 1; n     return b; n   } n   long long int x1, y1; n   long long int gcd = gcdExtended(b % a, a, &x1, &y1); n   *x = y1 - (b / a) * x1; n   *y = x1; n   cout <<  AFTER   << a <<     << b <<     << *x <<     << *y <<   n ; n   return gcd; n } n long long int MODInverse(long long int a, long long int m) { n   long long int x, y; n   long long int g = gcdExtended(a, m, &x, &y); n   cout << g <<     << x <<     << y <<   n ; n   long long int ans = (x % m + m) % m; n   return ans; n } n using namespace std; n int main() { n   ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); n   long long int n, a = 0, x, m = 0; n   cin >> n; n   for (int i = 1; i <= n; i++) cin >> x, a += x, m = max(x, m); n   cout << max(m, (a + n - 2) / (n - 1)) <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long int N = 100005; n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   { n     long long int i, j, k, n, m, ans = 0, cnt = 0, sum = 0; n     cin >> n; n     vector<long long int> v; n     long long int a[n]; n     j = 0; n     ans = 0; n     for (i = 0; i < n; i++) { n       cin >> a[i]; n       if (a[i] < 0) { n         j++; n         if (j == 3) { n           v.push_back(i - ans); n           cnt++; n           ans = i; n           j = 1; n         } n       } n       if (i == n - 1) { n         v.push_back(i - ans + 1); n         cnt++; n       } n     } n     cout << max((long long int)1, cnt) << endl; n     for (auto x : v) { n       cout << x <<    ; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 1e7; n const long long MOD = 998244353; n vector<vector<int> > occur; n vector<vector<long long> > minC, dp; n long long gV(int l, int r) { n   if (l == r + 1) { n     return 1; n   } n   return dp[l][r]; n } n void calc(int l, int r) { n   int cMinC = minC[l][r]; n   vector<int> &cOccur = occur[cMinC]; n   int fI = cOccur[0]; n   int lI = cOccur[cOccur.size() - 1]; n   if (fI < l || r < lI) { n     dp[l][r] = 0; n     return; n   } n   long long sumR = 0; n   for (int nR = lI; nR <= r; nR++) { n     sumR = (sumR + gV(lI + 1, nR) * gV(nR + 1, r)) % MOD; n   } n   long long sumL = 0; n   for (int nL = fI; nL >= l; nL--) { n     sumL = (sumL + gV(l, nL - 1) * gV(nL, fI - 1)) % MOD; n   } n   long long inProd = 1; n   for (int i = 0; i + 1 < cOccur.size(); i++) { n     inProd = inProd * gV(cOccur[i] + 1, cOccur[i + 1] - 1) % MOD; n   } n   dp[l][r] = (sumL * sumR % MOD) * inProd % MOD; n } n int main() { n   int N, M; n   cin >> M >> N; n   vector<int> a; n   for (int i = 0; i < N; i++) { n     int x; n     cin >> x; n     x--; n     if (a.empty() || a[a.size() - 1] != x) { n       a.push_back(x); n     } n   } n   N = a.size(); n   if (N > 2 * M) { n     cout << 0 << endl; n     return 0; n   } n   minC.resize(N); n   for (int i = 0; i < N; i++) { n     minC[i].resize(N); n     int cMin = a[i]; n     for (int j = i; j < N; j++) { n       cMin = min(cMin, a[j]); n       minC[i][j] = cMin; n     } n   } n   occur.resize(M); n   for (int i = 0; i < N; i++) { n     occur[a[i]].push_back(i); n   } n   dp.resize(N); n   for (int i = 0; i < N; i++) { n     dp[i].resize(N); n     fill(dp[i].begin(), dp[i].end(), 0); n   } n   for (int len = 1; len <= N; len++) { n     for (int l = 0; l < N; l++) { n       int r = l + len - 1; n       if (r >= N) { n         continue; n       } n       calc(l, r); n     } n   } n   cout << dp[0][N - 1] << endl; n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK: 2000000 ) n using namespace std; n int main(void) { n   srand(time(0)); n   cout << fixed << setprecision(7); n   cerr << fixed << setprecision(7); n   int n; n   ios_base ::sync_with_stdio(0); n   cin.tie(0); n   cin >> n; n   function<int(int)> ok = [&](int k) { n     return !k ? 0 : ok(k / 10) | ((k % 10 != 4) && (k % 10 != 7)); n   }; n   static int f[1 << 20]; n   for (int i = 1; i <= n; ++i) f[i] = i; n   function<int(int)> get = [&](int k) { n     return k == f[k] ? k : f[k] = get(f[k]); n   }; n   for (int i = 1; i < n; ++i) { n     int a, b, c; n     cin >> a >> b >> c; n     if (ok(c)) f[get(a)] = get(b); n   } n   static int S[1 << 20]; n   for (int i = 1; i <= n; ++i) ++S[get(i)]; n   long long ans = 0; n   for (int i = 1; i <= n; ++i) n     ans += 1ll * (n - S[get(i)]) * (n - S[get(i)] - 1); n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = 1e9 + 7; n vector<long long> v[100009], vv[100009]; n long long vis[100009], dis[101][100001], ar[100001]; n void bfs(long long k) { n   queue<long long> q; n   memset(vis, 0, sizeof(vis)); n   for (long long x : vv[k]) { n     q.push(x); n     vis[x] = 1; n     dis[k][x] = 0; n   } n   while (!q.empty()) { n     long long x = q.front(); n     q.pop(); n     for (long long y : v[x]) { n       if (!vis[y]) { n         vis[y] = 1; n         q.push(y); n         dis[k][y] = dis[k][x] + 1; n       } n     } n   } n } n int32_t main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long n, m, k, s, ans = 1e15; n   cin >> n >> m >> k >> s; n   for (long long i = 1; i <= n; i++) { n     cin >> ar[i]; n     vv[ar[i]].push_back(i); n   } n   for (long long i = 0; i < m; i++) { n     long long x, y; n     cin >> x >> y; n     v[x].push_back(y); n     v[y].push_back(x); n   } n   for (long long i = 1; i <= k; i++) bfs(i); n   for (long long i = 1; i <= n; i++) { n     vector<long long> hh; n     long long as = 0; n     for (long long j = 1; j <= k; j++) hh.push_back(dis[j][i]); n     sort(hh.begin(), hh.end()); n     for (long long j = 0; j < s; j++) as += hh[j]; n     cout << as <<    ; n   } n   cout << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 4e5 + 5; n const int MAXM = 2e5 + 5; n const int MOD = 998244353; n const int INF = 0x3f3f3f3f; n int a[MAXN], sum[MAXN]; n vector<int> v; n map<int, int> mp; n int main() { n   int n, I; n   scanf( %d%d , &n, &I); n   mp.clear(); n   memset(sum, 0, sizeof(sum)); n   int B = I * 8; n   for (int i = 1; i <= n; ++i) { n     scanf( %d , &a[i]); n     if (mp.find(a[i]) == mp.end()) { n       mp[a[i]] = 1; n     } else { n       ++mp[a[i]]; n     } n     v.emplace_back(a[i]); n   } n   sort(a + 1, a + n + 1); n   sort(v.begin(), v.end()); n   v.erase(unique(v.begin(), v.end()), v.end()); n   int sz = v.size(), K; n   for (int i = sz; i >= 1; --i) { n     if (n * int(ceil(log2(i))) <= B) { n       K = i; n       break; n     } n   } n   for (int i = 0; i < sz; ++i) { n     if (i == 0) n       sum[i] = mp[v[i]]; n     else n       sum[i] = sum[i - 1] + mp[v[i]]; n   } n   int ans = n, tmp = 0; n   for (int i = 0; i <= max(sz - K, 0); ++i) { n     tmp = 0; n     if (i != 0) tmp += sum[i - 1]; n     tmp += sum[sz - 1] - sum[min(i + K - 1, sz - 1)]; n     ans = min(tmp, ans); n   } n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long a, i, high, low, mid, nstr, ninte; n int main() { n   scanf( %lld , &a); n   long long ans[a], str[a], inte[a], exp[a]; n   for (i = 0; i < a; i++) { n     scanf( %lld %lld %lld , &str[i], &inte[i], &exp[i]); n   } n   for (i = 0; i < a; i++) { n     high = exp[i]; n     low = 0; n     ans[i] = 0; n     while (low <= high) { n       mid = (high + low) / 2; n       nstr = str[i] + mid; n       ninte = inte[i] + (exp[i] - mid); n       if (nstr > ninte) { n         ans[i] = (exp[i] + 1) - mid; n         high = mid - 1; n       } else { n         low = mid + 1; n       } n     } n   } n   for (i = 0; i < a; i++) { n     printf( %lld n , ans[i]); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, a1, a2, b1, b2, k = 1, f = 0, ans = 0; n   scanf( %d , &n); n   while (k <= 4) { n     scanf( %d%d%d%d , &a1, &a2, &b1, &b2); n     if (n >= a1 + b1 || n >= a1 + b2) n       ans = a1; n     else if (n >= a2 + b1 || n >= a2 + b2) n       ans = a2; n     if (ans > 0) { n       f = 1; n       printf( %d %d %d , k, ans, n - ans); n       break; n     } n     k++; n   } n   if (f == 0) printf( -1 ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n set<int> s; n vector<vector<int> > v; n bool ch[100005]; n void go(int i) { n   ch[i] = true; n   int z = 0; n   for (auto it : v[i]) { n     if (ch[it] == false) { n       z++; n       go(it); n     } n   } n   if (z == 0) { n     s.insert(i); n   } n } n void dynamic() { n   int n; n   cin >> n; n   long double sum = 0; n   cin >> sum; n   v.resize(n + 1); n   memset(ch, 0, sizeof(ch)); n   for (int i = 0; i < n - 1; i++) { n     int x, y; n     cin >> x >> y; n     v[x].push_back(y); n     v[y].push_back(x); n   } n   go(1); n   int z = s.size(); n   if (v[1].size() == 1) { n     z++; n   } n   sum = sum / z; n   sum *= 2; n   cout << setprecision(12) << sum <<   n ; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int t; n   t = 1; n   while (t--) { n     dynamic(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n bool sortbysec(const pair<int, int> &a, const pair<int, int> &b); n long long int gcd(long long int a, long long int b); n int prime(int n); n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long int t = 1; n   while (t--) { n     long long int n, m, sum; n     cin >> n >> m; n     long long int a[n]; n     for (int i = 0; i < n; i++) cin >> a[i]; n     sort(a, a + n, greater<int>()); n     for (int k = 1; k <= n; k++) { n       sum = 0; n       for (int i = 0; i < n; i++) { n         sum += max(0LL, a[i] - (i / k)); n       } n       if (sum >= m) { n         cout << k << endl; n         break; n       } n     } n     if (sum < m) cout << -1 << endl; n   } n } n bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) { n   return (a.second < b.second); n } n long long int gcd(long long int a, long long int b) { n   if (b == 0) return a; n   return gcd(b, a % b); n } n int prime(int n) { n   int flag = 1; n   for (int i = 2; i <= sqrt(n); i++) { n     if (n % i == 0) { n       flag = 0; n       break; n     } n   } n   return flag; n } n


#include <bits/stdc++.h> n using namespace std; n const int D[8][2] = {{1, 0},  {0, 1},  {-1, 0},  {0, -1}, n                      {1, -1}, {-1, 1}, {-1, -1}, {1, 1}}; n int N, M, K, f[600005], F[3005][6005], b[600005], tot; n int find(int x) { return x == f[x] ? x : f[x] = find(f[x]); } n bool can(int& x, int& y) { n   if (!y) y = 2 * M; n   if (y > 2 * M) y = 1; n   return 1 <= x && x <= N && F[x][y]; n } n bool check(int x, int y) { n   tot++; n   int xx, yy; n   for (int i = 0; i < 8; i++) n     if (can(xx = x + D[i][0], yy = y + D[i][1])) b[find(F[xx][yy])] = tot; n   for (int i = 0; i < 8; i++) n     if (can(xx = x + D[i][0], yy = y + M + D[i][1]) && n         b[find(F[xx][yy])] == tot) n       return 0; n   return 1; n } n void add(int x, int y, int z) { n   F[x][y] = z; n   for (int i = 0; i < 8; i++) { n     int xx = x + D[i][0], yy = y + D[i][1]; n     if (can(xx, yy)) f[find(F[xx][yy])] = find(z); n   } n } n void doit() { n   int ans = 0; n   scanf( %d%d%d , &N, &M, &K); n   if (M == 1) { n     puts( 0 ); n     return; n   } n   for (int i = 1; i <= 2 * K; i++) f[i] = i; n   for (int i = 1, x, y; i <= K; i++) { n     scanf( %d%d , &x, &y); n     if (check(x, y)) add(x, y, i), add(x, y + M, i + K), ans++; n   } n   printf( %d n , ans); n } n int main() { n   doit(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a[3] = {0, 0, 0}, s; n int main() { n   string n; n   getline(cin, n); n   string x; n   getline(cin, x); n   s = x.size(); n   s = (s + 1) / 2; n   for (int i = 0; i < 2 * s - 1; i += 2) { n     if (x[i] ==  1 ) a[0]++; n     if (x[i] ==  2 ) a[1]++; n     if (x[i] ==  3 ) a[2]++; n   } n   cout << s - max(a[0], max(a[1], a[2])); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int a, b, d, p, q, s, t, r; n   cin >> a >> b >> d; n   p = a + a + b + b; n   q = a + d + b; n   s = a + d + d + a; n   t = b + d + d + b; n   r = min(p, min(q, min(s, t))); n   cout << r << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void Print() { cout << endl; } n template <typename T1, typename... T> n void Print(const T1 &t1, const T &...t) { n   cout << t1 <<    ; n   Print(t...); n } n template <typename T1, typename T2> n ostream &operator<<(ostream &os, const pair<T1, T2> &p) { n   os <<  (  << p.first <<  ,   << p.second <<  ) ; n   return os; n } n long long gcd(long long a, long long b) { n   if (b) { n     long long r = a % b; n     a = b, b = r; n   } n   return a; n } n tuple<long long, long long, long long> extend_gcd(long long a, long long b) { n   if (b == 0) n     return make_tuple(a, 1, 0); n   else { n     long long g, nx, ny; n     std::tie(g, nx, ny) = extend_gcd(b, a % b); n     return make_tuple(g, ny, nx - (a / b) * ny); n   } n } n long long fastpow(long long a, long long e, long long mod) { n   if (e == 0) return 1; n   if (e == 1) return a % mod; n   long long t = fastpow(a, e / 2, mod); n   t = t * t % mod; n   if (e & 1) n     return t * a % mod; n   else n     return t % mod; n } n const double PI = 3.14159265358979323846; n const int MOD = (int)1e9 + 7; n char s[100007], t[100007]; n int n, m; n long long dp[100007], psum[100007]; n vector<int> process() { n   vector<int> p(2); n   int last = 0; n   for (int i = 2; i <= m; i++) { n     while (last > 0 && t[i] != t[last + 1]) last = p[last]; n     if (t[i] == t[last + 1]) n       p.push_back(++last); n     else n       p.push_back(last); n   } n   return p; n } n int main() { n   scanf( %s %s , s + 1, t + 1); n   n = strlen(s + 1); n   m = strlen(t + 1); n   auto pre = process(); n   unordered_set<int> pos; n   int last = 0; n   for (int i = 1; i <= n; i++) { n     while (last > 0 && s[i] != t[last + 1]) last = pre[last]; n     if (s[i] == t[last + 1]) { n       last++; n       if (last == m) { n         pos.insert(i); n         last = pre[last]; n       } n     } n   } n   long long ans = 0; n   last = -1; n   dp[0] = 1, psum[0] = 1; n   for (int i = 1; i <= n; i++) { n     if (!pos.count(i) && last == -1) { n       dp[i] = 1; n     } else if (pos.count(i)) { n       dp[i] = (psum[i - m] + dp[i - 1]) % MOD; n       last = i; n     } else { n       dp[i] = (psum[last - m] + dp[i - 1]) % MOD; n     } n     psum[i] = (dp[i] + psum[i - 1]) % MOD; n   } n   printf( %lld n , (dp[n] + MOD - 1) % MOD); n } n


#include <bits/stdc++.h> n using namespace std; n const double eps = 1e-10; n const int inf = 1000000009; n int i, j, k, m, n, l; n int ans; n int f(int n, int m) { n   return n < m ? (n + (n % 2) * (m - 1)) / 2 : f(n - m, 2 * m); n } n int main() { n   cin >> n; n   cout << (n < 2 ? 0 : f(n - 2, 2)) << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long MAX = 100005; n const long long mod = 1000000007; n const double PI = 2 * acos(0.0); n const double EPS = 0.00000000001; n int main() { n   long long n; n   cin >> n; n   string a, b; n   cin >> a >> b; n   long long OO = 0, II = 0, IO = 0, OI = 0; n   for (long long i = 0; i < n; i++) { n     if (a[i] ==  1  and b[i] ==  1 ) n       II++; n     else if (a[i] ==  0  and b[i] ==  0 ) n       OO++; n     else if (a[i] ==  1  and b[i] ==  0 ) n       IO++; n     else if (a[i] ==  0  and b[i] ==  1 ) n       OI++; n   } n   long long ans = (OO * II) + (OI * IO) + (OO * IO); n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 2e5 + 5; n long long a[N]; n long long p[N]; n long long size[N]; n long long n; n long long root(long long v) { n   if (v != p[v]) { n     return p[v] = root(p[v]); n   } n   return v; n } n void fix(long long v, long long x) { n   if (v == n + 1) return; n   p[v] = v + 1; n   long long r = root(p[v]); n   p[v] = r; n   if (size[r] + x <= a[r]) { n     size[r] += x; n     return; n   } else { n     long long excess = size[r] + x - a[r]; n     size[r] = a[r]; n     fix(r, excess); n   } n   return; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   cin >> n; n   for (long long i = 1; i <= n; i++) { n     cin >> a[i]; n     p[i] = i; n     size[i] = 0; n   } n   p[n + 1] = n + 1; n   long long q; n   cin >> q; n   while (q--) { n     long long type, x, k; n     cin >> type; n     if (type == 1) { n       cin >> k >> x; n       if (size[k] + x <= a[k]) { n         size[k] += x; n       } else { n         long long excess = size[k] + x - a[k]; n         size[k] = a[k]; n         if (k == n) continue; n         fix(k, excess); n       } n     } else { n       cin >> k; n       cout << size[k] <<   n ; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n inline int read() { n   int v = 0, f = 1; n   char c = getchar(); n   while (c <  0  || c >  9 ) { n     if (c ==  - ) f = -1; n     c = getchar(); n   } n   while (c >=  0  && c <=  9 ) { n     v = v * 10 + c -  0 ; n     c = getchar(); n   } n   return v * f; n } n const int Maxn = 100005; n int bit[5005][10005]; n int bt[10005]; n void Add(int x) { n   assert(x); n   while (x < 10005) { n     bt[x]++; n     x += x & -x; n   } n } n int Query(int x) { n   int ans = 0; n   while (x) { n     ans += bt[x]; n     x -= x & -x; n   } n   return ans; n } n void add(int x, int y) { n   assert(x && y); n   for (int i = x; i < 5005; i += i & -i) { n     for (int j = y; j < 10005; j += j & -j) { n       bit[i][j]++; n     } n   } n } n int query(int x, int y) { n   int ret = 0; n   for (int i = x; i; i -= i & -i) { n     for (int j = y; j; j -= j & -j) { n       ret += bit[i][j]; n     } n   } n   return ret; n } n int dir[Maxn], x[Maxn], y[Maxn], len[Maxn]; n int ans[Maxn]; n int n, q; n void Rot() { n   for (int i = 0; i < q; i++) { n     swap(x[i], y[i]); n     x[i] = -x[i]; n   } n   int Minx = 1e9, Miny = 1e9; n   for (int i = 0; i < q; i++) { n     Minx = min(Minx, x[i]); n     Miny = min(Miny, y[i]); n   } n   for (int i = 0; i < q; i++) { n     x[i] = x[i] - Minx + 1; n     y[i] = y[i] - Miny + 1; n   } n } n void Solve(int D) { n   int cnt = 0; n   for (int i = 0; i < q; i++) { n     if (dir[i] == D) { n       cnt++; n     } else if (dir[i] == -1) { n       ans[i] += cnt; n     } n   } n   memset(bt, 0, sizeof(bt)); n   for (int i = 0; i < q; i++) { n     if (dir[i] == D) { n       Add(5001 - (x[i] - 1)); n     } else if (dir[i] == -1) { n       ans[i] -= Query(5001 - (x[i])); n     } n   } n   memset(bt, 0, sizeof(bt)); n   for (int i = 0; i < q; i++) { n     if (dir[i] == D) { n       Add(5001 - (y[i] - 1)); n     } else if (dir[i] == -1) { n       ans[i] -= Query(5001 - y[i]); n     } n   } n   memset(bt, 0, sizeof(bt)); n   for (int i = 0; i < q; i++) { n     if (dir[i] == D) { n       Add(x[i] + y[i] + len[i] + 1); n     } else if (dir[i] == -1) { n       ans[i] -= Query(x[i] + y[i]); n     } n   } n   memset(bit, 0, sizeof(bit)); n   for (int i = 0; i < q; i++) { n     if (dir[i] == D) { n       add(5001 - (x[i] - 1), 5001 - (y[i] - 1)); n     } else if (dir[i] == -1) { n       ans[i] += query(5001 - x[i], 5001 - y[i]); n     } n   } n   memset(bit, 0, sizeof(bit)); n   for (int i = 0; i < q; i++) { n     if (dir[i] == D) { n       add(5001 - (x[i] - 1), x[i] + y[i] + len[i] + 1); n     } else if (dir[i] == -1) { n       ans[i] += query(5001 - x[i], x[i] + y[i]); n     } n   } n   memset(bit, 0, sizeof(bit)); n   for (int i = 0; i < q; i++) { n     if (dir[i] == D) { n       add(5001 - (y[i] - 1), x[i] + y[i] + len[i] + 1); n     } else if (dir[i] == -1) { n       ans[i] += query(5001 - y[i], x[i] + y[i]); n     } n   } n } n int main() { n   scanf( %d %d , &n, &q); n   for (int i = 0; i < q; i++) { n     int tp; n     scanf( %d , &tp); n     if (tp == 1) { n       scanf( %d %d %d %d , &dir[i], &x[i], &y[i], &len[i]); n       if (dir[i] >= 3) dir[i] = 7 - dir[i]; n     } else { n       scanf( %d %d , &x[i], &y[i]); n       dir[i] = -1; n     } n   } n   for (int i = 1; i <= 4; i++) { n     Solve(i); n     Rot(); n   } n   for (int i = 0; i < q; i++) { n     if (dir[i] == -1) { n       printf( %d n , ans[i]); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline int read() { n   int s = 0; n   char ch = getchar(); n   while (!isdigit(ch)) ch = getchar(); n   while (isdigit(ch)) s = s * 10 + ch -  0 , ch = getchar(); n   return s; n } n inline char getch() { n   char ch = getchar(); n   while (!islower(ch)) ch = getchar(); n   return ch; n } n const int N = 20005; n int n, m, u, v, x, y, c1, c2, ans; n int dfn[N], dep[N], fa[N], dfn_t, pos[N], ab[N]; n int tag[N], len[N], type[N]; n char s[N], t[N], fw[N]; n vector<pair<int, char> > G[N]; n void dfs(int u, int f) { n   dep[u] = dep[f] + 1, fa[u] = f; n   dfn[u] = ++dfn_t, pos[dfn_t] = u; n   ab[dfn[u]] = dfn[f]; n   for (auto v : G[u]) { n     if (v.first == f) continue; n     fw[v.first] = v.second; n     dfs(v.first, u); n   } n } n int main() { n   n = read(), m = read(); n   for (int i = 1; i < n; i++) { n     u = read(), v = read(); n     char c = getch(); n     G[u].emplace_back(v, c); n     G[v].emplace_back(u, c); n   } n   dfs(1, 0); n   for (int T = 1; T <= m; T++) { n     memset(s + 1, 0, n * sizeof(char)); n     u = x = read(), v = y = read(); n     c1 = c2 = 0; n     while (u != v) n       dep[u] > dep[v] ? (s[++c1] = fw[u], u = fa[u]) n                       : (t[++c2] = fw[v], v = fa[v]); n     for (; c2;) s[++c1] = t[c2--]; n     type[dfn[x]] = len[dfn[x]] = 0, tag[dfn[x]] = T; n     ans = 0; n     for (int i = dfn[x]; ab[i];) { n       tag[ab[i]] = T, len[ab[i]] = len[i] + 1; n       type[ab[i]] = n           (type[i] n                ? type[i] n                : ((fw[pos[i]] > s[len[ab[i]]]) - (fw[pos[i]] < s[len[ab[i]]]))); n       i = ab[i]; n       if (type[i] == -1 || (!type[i] && len[i] < c1)) ++ans; n     } n     for (int i = 2; i <= n; i++) { n       if (tag[i] != T) { n         len[i] = len[ab[i]] + 1; n         type[i] = (type[ab[i]] n                        ? type[ab[i]] n                        : ((fw[pos[i]] > s[len[i]]) - (fw[pos[i]] < s[len[i]]))); n         if (type[i] == -1 || (!type[i] && len[i] < c1)) ++ans; n       } n     } n     printf( %d n , ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e6 + 10; n int a[maxn], cnt[maxn], tmp[maxn]; n int main(void) { n   int n, m; n   scanf( %d %d , &n, &m); n   for (int i = 1; i <= n; i++) { n     scanf( %d , a + i); n     if (a[i] <= m) cnt[a[i]]++; n   } n   for (int i = 1; i <= m; i++) n     for (int k = 1; k * i <= m; k++) tmp[k * i] += cnt[i]; n   int M = -1, p; n   for (int i = 1; i <= m; i++) n     if (tmp[i] > M) M = tmp[i], p = i; n   printf( %d %d n , p, M); n   for (int i = 1; i <= n; i++) n     if (p % a[i] == 0) printf( %d  , i); n   return 0; n } n


#include <bits/stdc++.h> n long long int const MOD = 1000000007; n long long int const N = 1000005; n long long int const LN = 20; n long long int const inf = 8e18; n using namespace std; n long long int n, m, a[N]; n vector<pair<long long int, long long int> > v[N]; n struct data { n   long long int d, second, prev, idx; n   data(long long int d, long long int second, long long int prev, n        long long int idx) { n     this->d = d; n     this->second = second; n     this->prev = prev; n     this->idx = idx; n   } n   bool operator<(data other) const { n     if (d != other.d) return d < other.d; n     if (second != other.second) return second < other.second; n     if (prev != other.prev) return prev < other.prev; n     if (idx != other.idx) return idx < other.idx; n     return 0; n   } n }; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(NULL); n   long long int n, m, k; n   cin >> n >> m >> k; n   for (long long int i = 1; i <= m; i++) { n     long long int a, b, c; n     cin >> a >> b >> c; n     v[a].push_back({c, b}); n     v[b].push_back({c, a}); n   } n   for (long long int i = 1; i <= n; i++) sort(v[i].begin(), v[i].end()); n   set<pair<long long int, long long int> > st; n   set<data> q; n   for (long long int i = 1; i <= n; i++) { n     st.insert({i, i}); n     q.insert(data(v[i][0].first, i, i, 0)); n   } n   k = 2 * k; n   while (!q.empty()) { n     data cur = *q.begin(); n     q.erase(cur); n     long long int nxt = v[cur.prev][cur.idx].second; n     if (st.find({cur.second, nxt}) == st.end()) { n       st.insert({cur.second, nxt}); n       k--; n       if (k == 0) { n         cout << cur.d <<   n ; n         return 0; n       } n       q.insert(data(cur.d + v[nxt][0].first, cur.second, nxt, 0)); n     } n     if (cur.idx + 1 < v[cur.prev].size()) n       q.insert(data( n           cur.d - v[cur.prev][cur.idx].first + v[cur.prev][cur.idx + 1].first, n           cur.second, cur.prev, cur.idx + 1)); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   long long s = 0; n   cin >> n; n   for (int i = 2; i <= n / 2; i++) { n     for (int j = 2; j * i <= n; j++) s += 4 * j; n   } n   cout << s << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   cin >> t; n   while (t--) { n     int x; n     cin >> x; n     int divisor = 1; n     int digits; n     int ans = 0; n     for (; divisor <= 9; divisor++) { n       if (x / divisor == 1 && x % divisor == 0) { n         digits = 1; n         break; n       } else if (x / divisor == 11 && x % divisor == 0) { n         digits = 2; n         break; n       } else if (x / divisor == 111 && x % divisor == 0) { n         digits = 3; n         break; n       } else if (x / divisor == 1111 && x % divisor == 0) { n         digits = 4; n         break; n       } n     } n     ans = ans + 10 * (divisor - 1); n     ans = ans + ((digits) * (digits + 1)) / 2; n     cout << ans << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n set<long long> tp; n long long tmp[100002], x, y, z, t; n char ch; n int main() { n   int n, k; n   scanf( %d %d , &n, &k); n   for (int i = 1; i <= n; i++) { n     scanf( %lld%c%lld%c%lld%c%lld , &x, &ch, &y, &ch, &z, &ch, &t); n     tmp[i] = t + (1 << 8) * z + (1 << 16) * y + (1 << 24) * x; n   } n   long long sum = 0LL; n   bool mn = false; n   for (int i = 31; i >= 0; i--) { n     sum += (1LL << i); n     tp.clear(); n     for (int j = 1; j <= n; j++) { n       tp.insert((tmp[j] & sum)); n     } n     if (tp.size() == k) { n       int ans = 0; n       for (int i = 31; i > 23; i--) { n         ans = ans * 2; n         if ((1LL << i) & sum) ans++; n       } n       printf( %d. , ans); n       ans = 0; n       for (int i = 23; i > 15; i--) { n         ans = ans * 2; n         if ((1LL << i) & sum) ans++; n       } n       printf( %d. , ans); n       ans = 0; n       for (int i = 15; i > 7; i--) { n         ans = ans * 2; n         if ((1LL << i) & sum) ans++; n       } n       printf( %d. , ans); n       ans = 0; n       for (int i = 7; i >= 0; i--) { n         ans = ans * 2; n         if ((1LL << i) & sum) ans++; n       } n       printf( %d , ans); n       ans = 0; n       mn = true; n       break; n     } n   } n   if (mn == false) printf( -1 ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   vector<int> child; n   int n, k; n   scanf( %d %d , &n, &k); n   int *A = new int[k]; n   for (int i = 0; i < k; ++i) { n     scanf( %d , &A[i]); n   } n   for (int i = 0; i < n; ++i) { n     child.push_back(i + 1); n   } n   int count = 0; n   for (int i = 0; i < k; ++i) { n     count += A[i]; n     count = count % (n - i); n     printf( %d  , child[count]); n     child.erase(child.begin() + count); n     if (count >= child.size()) count = 0; n   } n   return 0; n } n


#include <bits/stdc++.h> n char g[64][64]; n int h[64][64]; n void conv(long long x, long long y, long long a, long long b, long long *dx, n           long long *dy) { n   long long k, l; n   k = x - y + b * 2000000000LL; n   l = x + y + a * 2000000000LL; n   *dx = k / (2 * b) - 1000000000LL; n   *dy = l / (2 * a) - 1000000000LL; n } n void solve(int x1, int y1, int x2, int y2, int a, int b) { n   long long c, d, e, f, g, h, i; n   conv(x1, y1, a, b, &c, &d); n   conv(x2, y2, a, b, &e, &f); n   g = c - e; n   if (g < 0) g = -g; n   h = d - f; n   if (h < 0) h = -h; n   i = g > h ? g : h; n   printf( %d n , i); n } n int main() { n   int i, j, u, v; n   int a, b, x1, y1, x2, y2; n   long long A, B; n   long long k, l; n   memset(g, 0, sizeof(g)); n   scanf( %d %d %d %d %d %d , &a, &b, &x1, &y1, &x2, &y2); n   solve(x1, y1, x2, y2, a, b); n   return 0; n } n


#include <bits/stdc++.h> n long long k, m = 9, l, c, lc, n, md, tr = 1, fl, res; n int main() { n   scanf( %lld , &k); n   while (1) { n     l++; n     lc += m * l; n     if (k - lc <= 0) { n       c = k - (lc - m * l); n       break; n     } n     m *= 10; n     tr *= 10; n   } n   n = (c + l - 1) / l; n   tr = tr + n - 1; n   md = c % l; n   if (md == 0) md += l; n   while (1) { n     res = tr % 10; n     tr /= 10; n     if (l - fl == md) { n       printf( %lld , res); n       return 0; n     } n     fl++; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int n; n inline int read() { n   int x = 0, f = 1; n   char ch = getchar(); n   while (ch <  0  || ch >  9 ) { n     if (ch ==  - ) f = -1; n     ch = getchar(); n   } n   while (ch >=  0  && ch <=  9 ) n     x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar(); n   return x * f; n } n inline void write(int x, char end =    ) { n   char F[200]; n   int tmp = x > 0 ? x : -x, cnt = 0; n   if (x == 0) putchar( 0 ); n   if (x < 0) putchar( - ); n   while (tmp > 0) F[cnt++] = tmp % 10 +  0 , tmp /= 10; n   while (cnt > 0) putchar(F[--cnt]); n   putchar(end); n } n void f(int a, int b) { write(a), write(b,   n ); } n int main() { n   n = read(); n   if (n % 4 >= 2) return puts( NO ), 0; n   puts( YES ); n   for (int i = 1; i < n; i += 2) { n     for (int j = i + 2; j < n; j += 2) n       f(i, j), f(i + 1, j + 1), f(i, j + 1), f(i + 1, j); n     if (n % 4 == 1) n       f(i, n), f(i, i + 1), f(i + 1, n); n     else n       f(i, i + 1); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e6 + 100; n const int inf = 0x7ffffff; n int a[maxn]; n long long dp[maxn]; n int main(void) { n   int n; n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) scanf( %d , &a[i]); n   dp[0] = 0; n   for (int i = 1; i <= n; i++) { n     dp[i] = dp[i - 1] + 20; n     int pos1 = lower_bound(a + 1, a + n + 1, a[i] - 90 + 1) - a - 1; n     int pos2 = lower_bound(a + 1, a + n + 1, a[i] - 1440 + 1) - a - 1; n     long long t1 = (i - pos1 + 1) * 20; n     long long t2 = (i - pos2 + 1) * 20; n     dp[i] = min(dp[i], dp[pos1] + min(50LL, t1)); n     dp[i] = min(dp[i], dp[pos2] + min(120LL, t2)); n     printf( %I64d n , dp[i] - dp[i - 1]); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1000005; n const int MAXN = 1e5 + 5; n const int LG = 22; n int dp[51][51][51][51]; n int n; n int a[55][55]; n int get(int tli, int tlj, int rbi, int rbj) { n   int res = a[rbi][rbj]; n   if (tli > 0) res = res - a[tli - 1][rbj]; n   if (tlj > 0) res = res - a[rbi][tlj - 1]; n   if (tli > 0 && tlj > 0) res = res + a[tli - 1][tlj - 1]; n   return res; n } n int foo(int r1, int r2, int c1, int c2) { n   if (r1 > r2 or c1 > c2) return 0; n   if (dp[r1][r2][c1][c2] != -1) return dp[r1][r2][c1][c2]; n   int ans = (get(r1, c1, r2, c2) > 0) * max(r2 - r1 + 1, c2 - c1 + 1); n   for (int i = r1; i < r2; i++) { n     ans = min(ans, foo(r1, i, c1, c2) + foo(i + 1, r2, c1, c2)); n   } n   for (int i = c1; i < c2; i++) { n     ans = min(ans, foo(r1, r2, c1, i) + foo(r1, r2, i + 1, c2)); n   } n   return dp[r1][r2][c1][c2] = ans; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   cin >> n; n   string s[n]; n   for (int i = 0; i < n; i++) cin >> s[i]; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < n; j++) { n       if (s[i][j] ==  # ) { n         a[i][j] = 1; n       } n     } n   } n   for (int i = 0; i < n; i++) n     for (int j = 0; j < n; j++) n       for (int ii = 0; ii < n; ii++) n         for (int jj = 0; jj < n; jj++) dp[i][ii][j][jj] = -1; n   for (int i = 0; i < n; i++) { n     for (int j = 1; j < n; j++) { n       a[i][j] += a[i][j - 1]; n     } n   } n   for (int i = 1; i < n; i++) { n     for (int j = 0; j < n; j++) { n       a[i][j] += a[i - 1][j]; n     } n   } n   int ans = foo(0, n - 1, 0, n - 1); n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n string s; n int kappa[100]; n void incc(int jj) { n   if (kappa[jj] > 9) { n     kappa[jj + 1]++; n     kappa[jj] %= 10; n     incc(jj + 1); n   } n } n void get_count(int a1, int a2, int a3) { n   int i, j; n   if (a2 - a3 == 2) { n     j = 0; n     for (i = a2; i >= a1; i--) { n       if (!(s[i] ==  . )) { n         kappa[j] += s[i] -  0 ; n         if (kappa[j] > 9) { n           kappa[j + 1]++; n           kappa[j] %= 10; n         } n         j++; n       } n     } n   } else { n     j = 2; n     for (i = a2; i >= a1; i--) { n       if (!(s[i] ==  . )) { n         kappa[j] += s[i] -  0 ; n         if (kappa[j] > 9) { n           kappa[j + 1]++; n           kappa[j] %= 10; n         } n         j++; n       } n     } n   } n   incc(j); n } n int main(void) { n   cout << setprecision(10); n   ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); n   int i, i1, q, g, flag = 0, tt; n   for (i = 0; i < 100; i++) { n     kappa[i] = 0; n   } n   double k = 0; n   cin >> s; n   int leng; n   leng = s.length(); n   i = 0; n   while (i < leng) { n     if (flag == 0) { n       if (!(( z  >= s[i]) && (s[i] >=  a ))) { n         flag = 1; n         q = i; n       } n     } else { n       if (( z  >= s[i]) && (s[i] >=  a )) { n         flag = 0; n         g = i - 1; n         get_count(q, g, tt); n       } n       if (s[i] ==  . ) { n         tt = i; n       } n     } n     i++; n   } n   get_count(q, leng - 1, tt); n   for (i = 99; i > -1; i--) { n     if (kappa[i] > 0) { n       break; n     } n   } n   if ((kappa[0] == 0) && (kappa[1] == 0)) { n     for (i1 = i; i1 > 1; i1--) { n       cout << kappa[i1]; n       if ((i1 % 3 == 2) && (i1 > 2)) { n         cout <<  . ; n       } n     } n   } else { n     if (i > 1) { n       for (i1 = i; i1 > 1; i1--) { n         cout << kappa[i1]; n         if ((i1 % 3 == 2) && (i1 > 2)) { n           cout <<  . ; n         } n       } n       cout <<  . ; n       cout << kappa[1]; n       cout << kappa[0]; n     } else { n       cout <<  0. ; n       cout << kappa[1]; n       cout << kappa[0]; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a[1000010], n, mo = 1000000007; n long long dp[1000010], ans; n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) { n     scanf( %d , a + i); n     a[i]--; n   } n   dp[1] = min(a[1], a[2]); n   for (int i = 2; i <= n; i++) { n     dp[i] = n         (min(a[i], a[i + 1]) + min(a[i - 1], min(a[i], a[i + 1])) * dp[i - 1]) % n         mo; n     if (a[i + 1] >= a[i]) n       ans = (ans + dp[i]) % mo; n     else n       ans = (ans + min(a[i], a[i - 1]) * dp[i - 1] + a[i]) % mo; n   } n   printf( %I64d n , (ans + a[1]) % mo); n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( Ofast ) n #pragma GCC target( avx,avx2,fma ) n using namespace std; n using bigint = long long int; n using vi = vector<int>; n using vll = vector<long long int>; n int spf[2005]; n void smallestFactor() { n   for (int i = 1; i <= 2000; i++) spf[i] = i; n   for (int i = 2; i * i <= 2000; i++) { n     if (spf[i] == i) { n       for (int j = i * i; j <= 2000; j += i) { n         if (spf[j] == j) spf[j] = i; n       } n     } n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   ; n   smallestFactor(); n   int T; n   cin >> T; n   while (T--) { n     int N; n     cin >> N; n     int arr[N + 1]; n     for (int i = 0; i < N; i++) { n       int x; n       cin >> x; n       arr[i] = spf[x]; n     } n     map<int, int> m; n     int j = 1; n     vi ans; n     for (int i = 0; i < N; i++) { n       if (m.find(arr[i]) != m.end()) n         ans.push_back(m[arr[i]]); n       else { n         m[arr[i]] = j; n         ans.push_back(j); n         j++; n       } n     } n     cout << j - 1 <<   n ; n     for (int x : ans) cout << x <<    ; n     cout <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long int arr[123456]; n map<long long int, bool> mp; n int main() { n   int a = 0, b = 0, n, k, l, r, all, kall; n   cin >> n >> k >> l >> r >> all >> kall; n   int rest = all - kall; n   for (int i = 0; i < k; i++) { n     arr[i] = kall / k; n     if (kall % k != 0) { n       arr[i]++; n       kall--; n     } n   } n   int rem, man = n - k; n   if (k != n) { n     for (int i = k; i < n; i++) { n       arr[i] = rest / man; n       rem = rest % man; n       if (rem != 0) { n         arr[i]++; n         rest--; n       } n     } n   } n   random_shuffle(arr, arr + n); n   for (int i = 0; i < n - 1; i++) { n     printf( %d  , arr[i]); n   } n   cout << arr[n - 1] << endl; n } n


#include <bits/stdc++.h> n int main() { n   int j, n, t, i; n   int a[100]; n   scanf( %d , &t); n   for (i = 1; i <= t; i++) { n     int d = 0, b = 0; n     scanf( %d , &n); n     for (j = 1; j <= n; j++) { n       scanf( %d , &a[j]); n       if (d == 0 && a[j] == 1) d = 1; n       if (d == 1 && a[j] == 0) b++; n     } n     for (j = n; j >= 1; j--) { n       if (a[j] == 0) b--; n       if (a[j] == 1) break; n     } n     if (d == 0) n       printf( 0 n ); n     else n       printf( %d n , b); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void min_self(int& a, int b) { a = min(a, b); } n void max_self(int& a, int b) { a = max(a, b); } n const int NAX = (int)(2e5 + 5); n int v[NAX], visited[NAX]; n int component_size; n void visit(int i) { n   if (!visited[i]) { n     ++component_size; n     visited[i] = 1; n     visit(v[i]); n     visited[i] = component_size; n     return; n   } n   return; n } n int main() { n   int t, n; n   scanf( %d , &t); n   while (t--) { n     scanf( %d , &n); n     for (int i = 1; i <= n; ++i) scanf( %d , &v[i]); n     for (int i = 1; i <= n; ++i) { n       component_size = 0; n       visit(i); n     } n     for (int i = 1; i <= n; ++i) printf( %d  , visited[i]); n     printf(  n ); n     for (int i = 1; i <= n; ++i) visited[i] = 0; n   } n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n int n, a, b, s = 1, d = 2, q[105][105]; n int main() { n   ios_base::sync_with_stdio(false); n   cin >> n >> a >> b; n   for (int i = 1; i <= a; ++i) { n     for (int j = 1; j <= b; ++j) { n       q[i][j] = 0; n       if ((i + j) % 2 == 0) { n         if (s <= n) { n           q[i][j] = s; n           s += 2; n         } n       } n       if ((i + j) % 2 == 1) { n         if (d <= n) { n           q[i][j] = d; n           d += 2; n         } n       } n     } n   } n   if (s <= n || d <= n) { n     cout <<  -1  << endl; n     return 0; n   } n   for (int i = 1; i <= a; ++i) { n     for (int j = 1; j <= b; ++j) { n       cout << q[i][j] <<    ; n     } n     cout << endl; n   } n   return 0; n } n


#pragma GCC optimize( Ofast ) n  n #include <iostream> n #include <fstream> n #include <algorithm> n #include <functional> n #include <array> n #include <chrono> n #include <random> n #include <vector> n #include <string> n #include <sstream> n #include <cmath> n #include <cstring> n #include <bitset> n #include <list> n #include <stack> n #include <queue> n #include <set> n #include <map> n #include <cassert> n  n #define sq(x) ((x) * (x)) n #define err(x) cerr <<  [ #x ]    << (x) <<   n ; n #define errp(x) cerr <<  [ #x ]  {  << ((x).first) <<  ,   << ((x).second) <<  } n ; n #define errv(x) {cerr <<  [ #x ]  [ ;for(const auto& ___ : (x)) cerr << ___ <<  ,  ; cerr <<  ] n ;} n #define errvn(x, n) {cerr <<  [ #x ]  [ ;for(auto ___ = 0; ___ < (n); ++___) cerr << (x)[___] <<  ,  ; cerr <<  ] n ;} n #define errf() cerr <<   n n ; n  n using namespace std; n  n using ll = long long; n using ull = unsigned long long; n using ld = long double; n  n mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); n ll getrnd(ll l, ll r) { n     return uniform_int_distribution<ll>(l, r)(rng); n } n  n template <typename T1, typename T2> inline bool relax(T1& a, const T2& b) { n     return a > b ? a = b, true : false; n } n  n template <typename T1, typename T2> inline bool strain(T1& a, const T2& b) { n     return a < b ? a = b, true : false; n } n  n // ::::::::::::::::::::::::::::::: n  n void solve() { n     int n; n     cin >> n; n      n     int x = 0; n     vector<int> a(n); n     for (int i = 0; i < n; ++i) { n         cin >> a[i]; n         x ^= a[i]; n     } n      n     int cur = 0; n     for (int i = 0; i < n; ++i) { n         cur ^= a[i]; n         if (cur == (x ^ cur)) { n             cout <<  YES n ; n             return; n         } n     } n      n     cur = 0; n     for (int i = 0; i < n; ++i) { n         cur ^= a[i]; n         int sec = 0; n         for (int j = i + 1; j < n - 1; ++j) { n             sec ^= a[j]; n             if (cur == sec && sec == (cur ^ sec ^ x)) { n                 cout <<  YES n ; n                 return; n             } n         } n     } n     cout <<  NO n ; n } n  n int main() { n     ios::sync_with_stdio(0); n     cin.tie(nullptr); cout.tie(nullptr); n      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 int a[120]; n int n, m; n int main() { n   cin >> n >> m; n   for (int i = 1; i <= n; i++) cin >> a[i]; n   sort(a + 1, a + n + 1); n   int s = 0; n   int j; n   for (j = 1; j < n; j++) { n     s += a[j]; n     if (s > m) break; n   } n   if (j < n) n     cout <<  NO ; n   else n     cout <<  YES ; 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     vector<long long int> a(n), b(n); n     map<long long int, bool> mp; n     bool ok = false; n     for (int i = 0; i < n; i++) { n       cin >> a[i]; n       b[i] = a[i]; n       if (mp[a[i]]) { n         ok = true; n       } n       mp[a[i]] = true; n     } n     sort(b.rbegin(), b.rend()); n     if (a != b) { n       ok = true; n     } n     if (ok) { n       cout <<  YES  << endl; n     } else { n       cout <<  NO  << endl; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n uint64_t log4(uint64_t n) { return log2(n) / 2; } n uint64_t getA(uint64_t triple) { n   if (triple == 0) { n     return 1; n   } n   uint64_t doubleBits; n   if (triple == 1) { n     doubleBits = 1; n   } else { n     doubleBits = log4(triple * 3 + 1); n   } n   uint64_t tripleIndex = triple - (pow(4, doubleBits) - 1) / 3; n   return pow(4, doubleBits) + tripleIndex; n } n uint64_t getB(uint64_t A) { n   uint64_t res = 0; n   uint64_t power = 1; n   while (A > 0) { n     if (A % 4 == 1) { n       res += 2 * power; n     } n     if (A % 4 == 2) { n       res += 3 * power; n     } n     if (A % 4 == 3) { n       res += power; n     } n     power *= 4; n     A /= 4; n   } n   return res; n } n uint64_t getC(uint64_t A) { n   uint64_t res = 0; n   uint64_t power = 1; n   while (A > 0) { n     if (A % 4 == 1) { n       res += 3 * power; n     } n     if (A % 4 == 2) { n       res += power; n     } n     if (A % 4 == 3) { n       res += 2 * power; n     } n     power *= 4; n     A /= 4; n   } n   return res; n } n uint64_t solve(uint64_t n) { n   uint64_t triple = (n - 1) / 3; n   uint64_t A = getA(triple); n   if (n % 3 == 0) { n     return getC(A); n   } n   if (n % 3 == 1) { n     return A; n   } n   return getB(A); n } n int main() { n   int T; n   cin >> T; n   for (int t = 0; t < T; t++) { n     uint64_t n; n     cin >> n; n     uint64_t result; n     result = solve(n); n     cout << result << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long MOD = 1000000007; n const int N = 1000010; n template <class T> n class BIT { n   T bit[N + 1]; n   int n; n  n  public: n   BIT() { n     n = N; n     memset(bit, 0, sizeof(bit)); n   } n   T sum(int i) { n     T s = 0; n     ++i; n     while (i > 0) { n       s += bit[i]; n       s %= MOD; n       i -= i & -i; n     } n     return s; n   } n   void add(int i, T x) { n     ++i; n     while (i <= n) { n       bit[i] += x; n       bit[i] %= MOD; n       i += i & -i; n     } n   } n }; n BIT<long long> T; n int n, m, k; n vector<pair<int, int>> in[1000010]; n vector<pair<int, int>> out[1000010]; n set<int> alive; n set<pair<int, int>> itv; n int main() { n   scanf( %d %d %d , &n, &m, &k); n   alive.insert(1); n   itv.insert(make_pair(0, 0)); n   for (int i = 0; i < (k); i++) { n     int a, b, c, d; n     scanf( %d %d %d %d , &a, &b, &c, &d); n     in[b].push_back(make_pair(a, c)); n     out[d + 1].push_back(make_pair(a, c)); n   } n   T.add(1, 1); n   for (int i = 1; i <= m; ++i) n     if (in[i].size() > 0 || out[i].size() > 0) { n       sort((in[i]).begin(), (in[i]).end()); n       sort((out[i]).begin(), (out[i]).end()); n       vector<pair<int, long long>> vals; n       for (int j = 0; j < (in[i].size()); j++) { n         pair<int, int> p = in[i][j]; n         auto it = itv.upper_bound(make_pair(p.second + 1, n)); n         --it; n         if (it->second < p.second + 1) { n           long long num = T.sum(p.second) - T.sum(it->second); n           num %= MOD; n           if (num < 0) num += MOD; n           vals.emplace_back(p.second + 1, i > 1 ? num : 0LL); n           if (i > 1) alive.insert(p.second + 1); n         } n       } n       for (pair<int, int> p : out[i]) { n         itv.erase(p); n       } n       for (int j = 0; j < (vals.size()); j++) { n         T.add(vals[j].first, vals[j].second); n       } n       for (int j = 0; j < (in[i].size()); j++) { n         pair<int, int> p = in[i][j]; n         itv.insert(p); n         auto it = alive.lower_bound(p.first); n         while (it != alive.end() && *it <= p.second) { n           int pos = *it; n           long long k = T.sum(pos) - T.sum(pos - 1); n           k %= MOD; n           T.add(pos, MOD - k); n           alive.erase(it++); n         } n       } n     } n   long long ret = T.sum(n); n   auto it = itv.end(); n   --it; n   ret = (ret - T.sum(it->second)) % MOD; n   if (ret < 0) ret += MOD; n   printf( %d n , (int)ret); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 0x3f3f3f3f; n const double PI = acos(-1.0); n const double E = exp(1); n const int N = 1e5 + 5; n int n; n map<long long, long long> m; n int main(void) { n   ios_base::sync_with_stdio(false); n   cin >> n; n   for (int i = 0; i < n; i++) { n     long long a; n     cin >> a; n     if (!m.count(a)) m[a] = 0; n     m[a]++; n   } n   long long at = 0; n   long long s; n   long long f = 0; n   for (map<long long, long long>::iterator it = m.begin(); it != m.end(); n        it++) { n     s = it->first; n     long long x = it->second; n     at += s - f; n     at = max(0LL, at - x); n     f = s; n   } n   cout << s - at + 1 << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n inline void chkmax(T &a, T b) { n   if (a < b) a = b; n } n template <class T> n inline void chkmin(T &a, T b) { n   if (a > b) a = b; n } n inline int read() { n   int sum = 0, p = 1; n   char ch = getchar(); n   while (!(( 0  <= ch && ch <=  9 ) || ch ==  - )) ch = getchar(); n   if (ch ==  - ) p = -1, ch = getchar(); n   while ( 0  <= ch && ch <=  9 ) sum = sum * 10 + ch - 48, ch = getchar(); n   return sum * p; n } n const int maxn = 5e5 + 20; n struct node { n   int v, next; n }; n node e[maxn << 1]; n int cnt, start[maxn]; n inline void addedge(int u, int v) { n   e[++cnt] = (node){v, start[u]}; n   start[u] = cnt; n } n int n; n inline void init() { n   n = read(); n   for (int i = (1), _end_ = (n - 1); i <= _end_; i++) { n     int u = read(), v = read(); n     addedge(u, v); n     addedge(v, u); n   } n } n int sz[maxn]; n void get_sz(int u, int fa) { n   sz[u] = 1; n   for (int i = start[(u)]; i; i = e[i].next) n     if (e[i].v != fa) get_sz(e[i].v, u), sz[u] += sz[e[i].v]; n } n long long ans[maxn]; n void dfs(int u, int fa) { n   for (int i = start[(u)]; i; i = e[i].next) { n     int v = e[i].v; n     if (v == fa) continue; n     ans[v] = ans[u] + (long long)(sz[u] - sz[v]) * sz[v]; n     dfs(v, u); n   } n } n inline void doing() { n   get_sz(1, 0); n   ans[1] = (long long)n * (n - 1) >> 1; n   dfs(1, 0); n   int u = 2; n   for (int i = (3), _end_ = (n); i <= _end_; i++) n     if (ans[u] < ans[i]) { n       u = i; n     } n   get_sz(u, 0); n   ans[u] = (long long)n * (n - 1) >> 1; n   dfs(u, 0); n   long long t = 0; n   for (int i = (1), _end_ = (n); i <= _end_; i++) chkmax(t, ans[i]); n   printf( %lld n , t); n } n int main() { n   init(); n   doing(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct edge { n   int to, cap, cost, rev, id; n }; n int dist[5005], h[5005], prevv[5005], preve[5005]; n int V, n, m; n vector<edge> G[5005]; n void add_edge(int from, int to, int cap, int cost) { n   G[from].push_back((edge){to, cap, cost, (int)G[to].size()}); n   G[to].push_back((edge){from, 0, -cost, (int)G[from].size() - 1}); n } n int min_cost_flow(int s, int t, int f) { n   int res = 0; n   fill(h + 1, h + V + 1, 0); n   while (f > 0) { n     priority_queue<pair<int, int>, vector<pair<int, int> >, n                    greater<pair<int, int> > > n         que; n     fill(dist + 1, dist + V + 1, 1000000000); n     dist[s] = 0; n     que.push(pair<int, int>(0, s)); n     while (!que.empty()) { n       pair<int, int> p = que.top(); n       que.pop(); n       int v = p.second; n       if (dist[v] < p.first) continue; n       for (int i = 0; i < G[v].size(); i++) { n         edge &e = G[v][i]; n         if (e.cap > 0 && dist[e.to] > dist[v] + e.cost + h[v] - h[e.to]) { n           dist[e.to] = dist[v] + e.cost + h[v] - h[e.to]; n           prevv[e.to] = v; n           preve[e.to] = i; n           que.push(pair<int, int>(dist[e.to], e.to)); n         } n       } n     } n     if (dist[t] == 1000000000) { n       return -1; n     } n     for (int v = 1; v <= V; v++) h[v] += dist[v]; n     int d = f; n     for (int v = t; v != s; v = prevv[v]) { n       d = min(d, G[prevv[v]][preve[v]].cap); n     } n     f -= d; n     res += d * h[t]; n     for (int v = t; v != s; v = prevv[v]) { n       edge &e = G[prevv[v]][preve[v]]; n       e.cap -= d; n       G[v][e.rev].cap += d; n     } n   } n   return res; n } n int w[5005][5005]; n int ans[5005][5005]; n int main() { n   scanf( %d%d , &n, &m); n   for (int i = 0; i < m; i++) { n     int u, v; n     scanf( %d%d , &u, &v); n     w[u][v] = 1; n   } n   int s = n + n * (n - 1) / 2 + 1, t = s + 1; n   V = t; n   int tot = 0; n   for (int i = 1; i <= n; i++) n     for (int j = i + 1; j <= n; j++) { n       tot++; n       add_edge(s, tot + n, 1, 0); n       if (!w[i][j]) add_edge(tot + n, i, 1, 0); n       if (!w[j][i]) add_edge(tot + n, j, 1, 0); n     } n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= n - 1; j++) add_edge(i, t, 1, 2 * j - 1); n   int res = min_cost_flow(s, t, n * (n - 1) / 2); n   tot = 0; n   for (int i = 1; i <= n; i++) n     for (int j = i + 1; j <= n; j++) { n       tot++; n       for (auto e : G[n + tot]) { n         if (e.cap) continue; n         if (e.to == i) n           w[j][i] = 1; n         else n           w[i][j] = 1; n       } n     } n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= n; j++) printf( %d , w[i][j]); n     puts(  ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int num[100010]; n int main() { n   int n; n   cin >> n; n   int k = ceil(sqrt(n)); n   int m = ceil((double)n / (double)k); n   int y = m; n   int flag = 0, cnt = 0; n   for (int i = 1; i <= k; i++) { n     int p = 0; n     int j = m; n     while (j--) { n       while (y > n) { n         y--; n       } n       cout << y - p <<    ; n       p++; n       cnt++; n       if (cnt == n) { n         flag = 1; n         break; n       } n     } n     y += m; n     if (flag) break; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1007; n const int inf = INT_MAX; n const long long inff = 1e18; n const long long mod = 1e9 + 7; n int n; n int a[maxn], b[maxn]; n vector<pair<pair<int, int>, pair<int, int> > > v; n int32_t main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cin >> n; n   for (int i = 1; i <= n; i++) cin >> a[i]; n   for (int i = 1; i <= n; i++) cin >> b[i]; n   for (int i = 1; i <= n; i++) { n     int atta, attb; n     for (int j = i; j <= n; j++) { n       if (a[j] == i) atta = j; n       if (b[j] == i) attb = j; n     } n     if (atta == attb && atta == i) n       ; n     else { n       v.push_back(make_pair(make_pair(atta, i), make_pair(i, attb))); n       swap(a[atta], a[i]); n       swap(b[attb], b[i]); n     } n   } n   cout << ((int)(v).size()) << endl; n   for (auto i : v) n     cout << i.first.first <<     << i.first.second <<     << i.second.first n          <<     << i.second.second << endl; n } n


#include <bits/stdc++.h> n using namespace std; n struct node { n   long long l, r; n   long long mx = -1e18; n   long long ch = 0; n }; n vector<node> tree; n void push(long long v) { n   if (tree[v].l == tree[v].r) { n     tree[v].ch = 0; n   } else { n     tree[v * 2].ch += tree[v].ch; n     tree[v * 2 + 1].ch += tree[v].ch; n     tree[v * 2].mx += tree[v].ch; n     tree[v * 2 + 1].mx += tree[v].ch; n     tree[v].ch = 0; n     tree[v].mx = max(tree[v * 2].mx, tree[v * 2 + 1].mx); n   } n } n vector<long long> atc(1e6 + 2, 1e17); n vector<long long> def(1e6 + 2, 1e17); n void build(long long v, long long l, long long r) { n   tree[v].l = l, tree[v].r = r; n   if (l == r) { n     tree[v].mx = def[l]; n     return; n   } n   long long mid = (r + l) / 2; n   build(v * 2, l, mid); n   build(v * 2 + 1, mid + 1, r); n   tree[v].mx = max(tree[v * 2].mx, tree[v * 2 + 1].mx); n } n long long get_max(long long v, long long l, long long r) { n   push(v); n   if (tree[v].l > r || tree[v].r < l) return -1e17; n   if (tree[v].l >= l && tree[v].r <= r) { n     return tree[v].mx; n   } n   return max(get_max(v * 2, l, r), get_max(v * 2 + 1, l, r)); n } n void upd(long long v, long long l, long long r, long long val) { n   push(v); n   if (tree[v].l > r || tree[v].r < l) return; n   if (tree[v].l >= l && tree[v].r <= r) { n     tree[v].ch += val; n     tree[v].mx += val; n     push(v); n     return; n   } n   upd(v * 2, l, r, val); n   upd(v * 2 + 1, l, r, val); n   tree[v].mx = max(tree[v * 2].mx, tree[v * 2 + 1].mx); n } n signed main() { n   ios_base::sync_with_stdio(false); n   long long mna = 1e9, mnb = 1e9; n   long long n, m, k; n   cin >> n >> m >> k; n   tree.resize(1e6 * 4); n   for (long long i = 0; i < n; ++i) { n     long long a, b; n     cin >> a >> b; n     mna = min(mna, b); n     atc[a - 1] = min(atc[a - 1], b); n   } n   for (long long i = 1e6; i >= 0; --i) atc[i] = min(atc[i + 1], atc[i]); n   for (long long i = 0; i < m; ++i) { n     long long a, b; n     cin >> a >> b; n     mnb = min(mnb, b); n     def[a - 1] = min(def[a - 1], b); n   } n   for (long long i = 1e6; i >= 0; --i) def[i] = min(def[i + 1], def[i]); n   for (long long i = 0; i < 1e6 + 2; ++i) def[i] *= -1; n   vector<pair<long long, pair<long long, long long> > > mnst; n   for (long long i = 0; i < k; ++i) { n     long long d, a, cen; n     cin >> d >> a >> cen; n     mnst.push_back({d, {a, cen}}); n   } n   build(1, 0, 1e6 + 1); n   sort(mnst.begin(), mnst.end()); n   long long j = 0; n   long long ans = -(mnb + mna); n   for (long long i = 0; i < 1e6 + 1; ++i) { n     while (j < k && mnst[j].first <= i) { n       long long att = mnst[j].second.first, cen = mnst[j].second.second; n       upd(1, att, 1e6 + 1, cen); n       ++j; n     } n     long long sum = get_max(1, 1ll, 1e6 + 1) - atc[i]; n     ans = max(sum, ans); n   } n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n = 0; n   int x0, y0, x1, y1; n   cin >> x0 >> y0 >> x1 >> y1; n   int m; n   cin >> m; n   map<pair<int, int>, bool> mass; n   for (int i = 0; i < m; i++) { n     int r, a, b; n     scanf( %d%d%d , &r, &a, &b); n     for (int j = a; j <= b; j++) { n       mass[make_pair(r, j)] = true; n     } n   } n   map<pair<int, int>, bool> flag; n   queue<pair<int, int> > q; n   map<pair<int, int>, int> dist; n   dist[make_pair(x0, y0)] = 1; n   q.push(make_pair(x0, y0)); n   flag[make_pair(x0, y0)] = true; n   while (!q.empty()) { n     int x = q.front().first; n     int y = q.front().second; n     bool f = false; n     q.pop(); n     if (mass[make_pair(x - 1, y - 1)]) { n       if (!flag[make_pair(x - 1, y - 1)]) { n         flag[make_pair(x - 1, y - 1)] = true; n         q.push(make_pair(x - 1, y - 1)); n         dist[make_pair(x - 1, y - 1)] = dist[make_pair(x, y)] + 1; n       } n     } n     if (mass[make_pair(x, y - 1)]) { n       if (!flag[make_pair(x, y - 1)]) { n         flag[make_pair(x, y - 1)] = true; n         q.push(make_pair(x, y - 1)); n         dist[make_pair(x, y - 1)] = dist[make_pair(x, y)] + 1; n       } n     } n     if (mass[make_pair(x + 1, y - 1)]) { n       if (!flag[make_pair(x + 1, y - 1)]) { n         flag[make_pair(x + 1, y - 1)] = true; n         q.push(make_pair(x + 1, y - 1)); n         dist[make_pair(x + 1, y - 1)] = dist[make_pair(x, y)] + 1; n       } n     } n     if (mass[make_pair(x - 1, y)]) { n       if (!flag[make_pair(x - 1, y)]) { n         flag[make_pair(x - 1, y)] = true; n         q.push(make_pair(x - 1, y)); n         dist[make_pair(x - 1, y)] = dist[make_pair(x, y)] + 1; n       } n     } n     if (mass[make_pair(x + 1, y)]) { n       if (!flag[make_pair(x + 1, y)]) { n         flag[make_pair(x + 1, y)] = true; n         q.push(make_pair(x + 1, y)); n         dist[make_pair(x + 1, y)] = dist[make_pair(x, y)] + 1; n       } n     } n     if (mass[make_pair(x - 1, y + 1)]) { n       if (!flag[make_pair(x - 1, y + 1)]) { n         flag[make_pair(x - 1, y + 1)] = true; n         q.push(make_pair(x - 1, y + 1)); n         dist[make_pair(x - 1, y + 1)] = dist[make_pair(x, y)] + 1; n       } n     } n     if (mass[make_pair(x, y + 1)]) { n       if (!flag[make_pair(x, y + 1)]) { n         flag[make_pair(x, y + 1)] = true; n         q.push(make_pair(x, y + 1)); n         dist[make_pair(x, y + 1)] = dist[make_pair(x, y)] + 1; n       } n     } n     if (mass[make_pair(x + 1, y + 1)]) { n       if (!flag[make_pair(x + 1, y + 1)]) { n         flag[make_pair(x + 1, y + 1)] = true; n         q.push(make_pair(x + 1, y + 1)); n         dist[make_pair(x + 1, y + 1)] = dist[make_pair(x, y)] + 1; n       } n     } n   } n   int ans = dist[make_pair(x1, y1)]; n   if (ans) { n     cout << ans - 1; n   } else { n     cout << -1; n   } n } n


#include <bits/stdc++.h> n using namespace std; n map<int, int> a, b; n map<int, int>::iterator it; n int n, ans = 1000000, k; n int main() { n   int i, x, y, k; n   cin >> n; n   k = n / 2 + n % 2; n   for (i = 1; i <= n; i++) { n     cin >> x >> y; n     a[x]++; n     b[x]++; n     if (x != y) b[y]++; n   } n   for (it = b.begin(); it != b.end(); it++) { n     x = it->first; n     if (a[x] >= k) n       ans = 0; n     else if (b[x] >= k) n       ans = min(ans, min(b[x] - a[x], k - a[x])); n   } n   if (ans == 1000000) n     cout <<  -1 n ; n   else n     cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e5 + 10; n struct E { n   int to; n   int next; n } ed[maxn * 2]; n int head[maxn]; n int tot; n void J(int a, int b) { n   ed[++tot].to = b; n   ed[tot].next = head[a]; n   head[a] = tot; n } n int dfn[maxn]; n int cnt; n int deep[maxn]; n int t[maxn][21]; n void Dfs(int x, int fa) { n   t[x][0] = fa; n   dfn[x] = ++cnt; n   deep[x] = deep[fa] + 1; n   for (int i = 1; i <= 20; i++) t[x][i] = t[t[x][i - 1]][i - 1]; n   for (int i = head[x]; i; i = ed[i].next) { n     if (ed[i].to == fa) continue; n     Dfs(ed[i].to, x); n   } n } n int lca(int x, int y) { n   if (deep[x] < deep[y]) swap(x, y); n   int k = deep[x] - deep[y]; n   int id = 0; n   while (k) { n     if (k & 1) x = t[x][id]; n     id++; n     k >>= 1; n   } n   if (x == y) return x; n   for (int i = 20; i >= 0; i--) n     if (t[x][i] != t[y][i]) { n       x = t[x][i]; n       y = t[y][i]; n     } n   return t[x][0]; n } n int vis[maxn]; n int jl[maxn]; n bool cm(int a, int b) { return dfn[a] < dfn[b]; } n int sta[maxn]; n int top; n int root; n int Insert(int x) { n   if (!top) { n     sta[++top] = x; n     if (deep[x] < deep[root]) root = x; n     vis[x] = 0; n     head[x] = 0; n     return 1; n   } n   int lc = lca(x, sta[top]); n   if (lc == sta[top]) { n     head[x] = 0; n     sta[++top] = x; n     vis[x] = 0; n     return 1; n   } n   while (top >= 2 && deep[sta[top - 1]] >= deep[lc]) { n     J(sta[top - 1], sta[top]); n     top--; n   } n   if (sta[top] != lc) { n     if (deep[lc] < deep[root]) root = lc; n     head[lc] = 0; n     J(lc, sta[top]); n     sta[top] = lc; n     vis[lc] = 1; n   } n   sta[++top] = x; n   head[x] = 0; n   vis[x] = 0; n   return 1; n } n int bj; n long long dp[maxn][2]; n void Dfs_(int x) { n   if (!vis[x]) { n     dp[x][1] = 1e7; n     dp[x][0] = 0; n     for (int i = head[x]; i; i = ed[i].next) { n       Dfs_(ed[i].to); n       if (deep[ed[i].to] - deep[x] == 1) n         dp[x][0] += dp[ed[i].to][1]; n       else n         dp[x][0] += min(dp[ed[i].to][1], dp[ed[i].to][0] + 1); n       long long inf = 1e7; n       dp[x][0] = min(dp[x][0], inf); n     } n   } else { n     dp[x][0] = 0; n     dp[x][1] = 0; n     long long ans1 = 0; n     long long ans2 = 1; n     long long ans3 = 0; n     for (int i = head[x]; i; i = ed[i].next) { n       Dfs_(ed[i].to); n       ans1 += dp[ed[i].to][1]; n       ans2 += min(dp[ed[i].to][1], dp[ed[i].to][0]); n       ans3 = max(ans3, dp[ed[i].to][1] - dp[ed[i].to][0]); n     } n     if (ans3 > 0) n       dp[x][0] = ans1 - ans3; n     else n       dp[x][0] = ans1; n     dp[x][1] = min(ans2, ans1); n     long long inf = 1e7; n     dp[x][1] = min(dp[x][1], inf); n     dp[x][0] = min(dp[x][0], inf); n   } n } n int main() { n   int n; n   scanf( %d , &n); n   int js1, js2; n   for (int i = 1; i <= n - 1; i++) { n     scanf( %d%d , &js1, &js2); n     J(js1, js2); n     J(js2, js1); n   } n   int t; n   scanf( %d , &t); n   Dfs(1, 0); n   int js; n   memset(head, 0, sizeof(head)); n   for (int i = 1; i <= t; i++) { n     scanf( %d , &js); n     top = 0; n     deep[0] = 1e9; n     root = 0; n     tot = 0; n     bj = 0; n     for (int j = 1; j <= js; j++) scanf( %d , &jl[j]); n     sort(jl + 1, jl + 1 + js, cm); n     for (int j = 1; j <= js; j++) n       if (!Insert(jl[j])) { n         bj = 1; n         break; n       } n     while (top >= 2) { n       J(sta[top - 1], sta[top]); n       top--; n     } n     Dfs_(root); n     if (dp[root][0] >= 1e7 - 1 && dp[root][1] >= 1e7 - 1) n       printf( -1 n ); n     else n       printf( %lld n , min(dp[root][0], dp[root][1])); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int q; n   cin >> q; n   while (q--) { n     unsigned long long int a, b, c; n     cin >> a >> b >> c; n     unsigned long long int s = a + b + c; n     cout << s / 2 << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n vector<long long> a; n long long n; n long long pos1; n double ct1, ct2 = 0; n long long z; n long long fun(long long l, long long r, vector<vector<long long> > dpp) { n   if (dpp[l][r] != -1) return dpp[l][r]; n   long long i, j, sum = 0; n   for (i = l; i < r; i++) { n     long long z = abs(a[i] - a[i + 1]); n     z = z * pow(-1, i - l); n     sum += z; n   } n   return dpp[l][r] = sum; n } n long long solve(long long l, long long r, vector<vector<long long> > dp, n                 vector<vector<long long> > dpp) { n   if (l > r) return 0; n   if (dp[l][r] != -1) return dp[l][r]; n   long long x, y; n   x = solve(l + 1, r, dp, dpp); n   long long z = fun(l, r, dpp); n   y = solve(l, r - 1, dp, dpp); n   return dp[l][r] = max(z, max(x, y)); n } n int main() { n   long long i, j, k, l, m, t; n   t = 1; n   while (t--) { n     long long a, b; n     cin >> n >> a >> b; n     vector<long long> v; n     for (i = 0; i < n; i++) { n       cin >> k; n       v.push_back(k); n     } n     sort(v.begin(), v.end()); n     m = min(a, b); n     b = max(a, b); n     a = m; n     i = n - 1; n     long long sum1 = 0, sum2 = 0; n     while (m--) { n       sum1 += v[i]; n       i--; n     } n     double ans1 = (double)sum1 / a; n     m = b; n     while (m--) { n       sum2 += v[i]; n       i--; n     } n     double ans2 = (double)sum2 / b; n     ans1 += ans2; n     cout << fixed << setprecision(12) << ans1; 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 = 1; n   for (int i = 1; i <= (3 * n); i++) { n     a *= 3; n     a %= 1000000007; n   } n   long long b = 1; n   for (int i = 1; i <= n; i++) { n     b *= 7; n     b %= 1000000007; n   } n   long long ans = ((a - b) + 1000000007) % 1000000007; n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n clock_t __stt; n inline void TStart() { __stt = clock(); } n inline void TReport() { n   printf(  nTaken Time : %.3lf sec n , n          (double)(clock() - __stt) / CLOCKS_PER_SEC); n } n template <typename T> n T MIN(T a, T b) { n   return a < b ? a : b; n } n template <typename T> n T MAX(T a, T b) { n   return a > b ? a : b; n } n template <typename T> n T ABS(T a) { n   return a > 0 ? a : (-a); n } n template <typename T> n void UMIN(T &a, T b) { n   if (b < a) a = b; n } n template <typename T> n void UMAX(T &a, T b) { n   if (b > a) a = b; n } n int n, q, fa[100005], deg[100005]; n double p[100005], s[100005], ini; n vector<int> adj[100005]; n void dfs(int ver) { n   if (!ver) fa[ver] = -1; n   int i; n   ini += ((double)deg[ver]) * p[ver]; n   for (i = 0; i < (int)adj[ver].size(); ++i) { n     if (adj[ver][i] != fa[ver]) { n       fa[adj[ver][i]] = ver; n       s[ver] += p[adj[ver][i]]; n       dfs(adj[ver][i]); n     } n   } n } n int main() { n   int i, j, k; n   scanf( %d , &n); n   ini = 0; n   for (i = 0; i < n; ++i) { n     scanf( %lf , p + i); n   } n   memset(deg, -1, sizeof(deg)); n   for (i = 0; i < n - 1; ++i) { n     int u, v; n     scanf( %d%d , &u, &v); n     ++deg[u]; n     ++deg[v]; n     adj[u].push_back(v); n     adj[v].push_back(u); n   } n   dfs(0); n   for (i = 0; i < n; ++i) { n     ini -= p[i] * s[i]; n   } n   scanf( %d , &q); n   while (q--) { n     int u; n     double d; n     scanf( %d%lf , &u, &d); n     ini += (d - p[u]) * (double)deg[u]; n     if (fa[u] != -1) { n       ini += p[fa[u]] * s[fa[u]]; n       s[fa[u]] += d - p[u]; n       ini -= p[fa[u]] * s[fa[u]]; n     } n     ini += p[u] * s[u]; n     p[u] = d; n     ini -= p[u] * s[u]; n     printf( %.5lf n , ini + 1.0); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool is_powertwo(long long n) { n   long long count = 0; n   while (n) { n     if ((n & 1) > 0) count++; n     n = n >> 1; n   } n   if (count == 1) return true; n   return false; n } n int main() { n   long long t; n   t = 1; n   while (t--) { n     long long h1, a1, c1; n     cin >> h1; n     cin >> a1; n     cin >> c1; n     long long h2, a2; n     cin >> h2; n     cin >> a2; n     string str =   ; n     long long count = 0; n     while (h2 > 0) { n       count++; n       if (h1 > a2) { n         str +=  s ; n         h1 -= a2; n         h2 -= a1; n       } else if (h2 <= a1) { n         h2 -= a1; n         str +=  s ; n         h1 -= a2; n       } else { n         h1 -= a2; n         str +=  h ; n         h1 += c1; n       } n     } n     cout << count << endl; n     for (long long i = 0; i < str.size(); i++) { n       if (str[i] ==  s ) n         cout <<  STRIKE  << endl; n       else n         cout <<  HEAL  << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char str[5003]; n int num[5003][2]; n int main() { n   while (~scanf( %s , str + 1)) { n     memset(num, 0, sizeof(num)); n     int len = strlen(str + 1); n     for (int i = 1; i <= len; i++) { n       num[i][0] = num[i - 1][0]; n       num[i][1] = num[i - 1][1]; n       if (str[i] ==  a ) n         num[i][0]++; n       else n         num[i][1]++; n     } n     int ans = len + 1; n     for (int i = 1; i <= len + 1; ++i) { n       for (int j = i; j <= len + 1; ++j) { n         int x1 = 0, x2 = 0, x3 = 0; n         if (i > 1) x1 = num[i - 1][1] - num[0][1]; n         if (j > i) x2 = num[j - 1][0] - num[i - 1][0]; n         if (j <= len) x3 = num[len][1] - num[j - 1][1]; n         ans = min(ans, x1 + x2 + x3); n       } n     } n     printf( %d n , len - ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n ostream& operator<<(ostream& s, vector<T>& v) { n   s <<  { ; n   for (int i = 0; i < int(v.size()); i++) s << (i ?  ,  :   ) << v[i]; n   return s <<  } ; n } n template <typename S, typename T> n ostream& operator<<(ostream& s, pair<S, T> const& p) { n   return s <<  (  << p.first <<  ,  << p.second <<  ) ; n } n const long long INV2 = 500000004; n const long long INV3 = 333333336; n const long long MOD = 1000000007; n long long modexp(long long x, long long n) { n   long long result = 1; n   while (n) { n     if (n % 2) { n       result = (result * x) % MOD; n       n--; n     } n     x = (x * x) % MOD; n     n /= 2; n   } n   return result; n } n int main() { n   int K; n   bool even = false; n   scanf( %d , &K); n   long long sm = 2; n   for (int k = 0; k < int(K); k++) { n     long long a; n     scanf( %lld , &a); n     if (a % 2 == 0) even = true; n     sm = modexp(sm, a); n   } n   sm = (sm * INV2) % MOD; n   long long denom = (sm + MOD) % MOD; n   if (even) n     sm++; n   else n     sm--; n   sm = (sm * INV3) % MOD; n   sm = (sm + MOD) % MOD; n   printf( %lld/%lld n , sm, denom); n } n


#include <bits/stdc++.h> n #pragma GCC optimize( Ofast ) n using namespace std; n void doin() { n   cin.tie(); n   cout.tie(); n   ios::sync_with_stdio(0); n } n template <typename X, typename Y> n istream& operator>>(istream& in, pair<X, Y>& a) { n   in >> a.first >> a.second; n   return in; n } n template <typename T> n void getv(T& i) { n   cin >> i; n } n template <typename T, typename... Ns> n void getv(vector<T>& v, int n, Ns... ns) { n   v.resize(n); n   for (auto& i : v) getv(i, ns...); n } n template <typename T> n void getv1(T& i) { n   cin >> i; n } n template <typename T, typename... Ns> n void getv1(vector<T>& v, int n, Ns... ns) { n   v.resize(n + 1); n   for (int i = 1; i <= n; i++) getv(v[i], ns...); n } n inline void getch(char& x) { n   while (x = getchar_unlocked(), x < 33) { n     ; n   } n } n inline void getstr(string& str) { n   str.clear(); n   char cur; n   while (cur = getchar_unlocked(), cur < 33) { n     ; n   } n   while (cur > 32) { n     str += cur; n     cur = getchar_unlocked(); n   } n } n template <typename T> n inline bool sc(T& num) { n   bool neg = 0; n   int c; n   num = 0; n   while (c = getchar_unlocked(), c < 33) { n     if (c == EOF) return false; n   } n   if (c ==  - ) { n     neg = 1; n     c = getchar_unlocked(); n   } n   for (; c > 47; c = getchar_unlocked()) num = num * 10 + c - 48; n   if (neg) num *= -1; n   return true; n } n using AntonTsypko = void; n using arsijo = AntonTsypko; n using god = arsijo; n uniform_real_distribution<double> double_dist(0, 1); n mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); n long long c, hr, wr, hb, wb; n long long ans = 0; n set<int> a; n void A() { n   long long cur = (c / wr) * hr, left = c % wr, t; n   while (cur >= 0 && a.insert(left % wb).second) { n     ans = max(ans, (t = cur + (left / wb) * hb)); n     cur -= hr; n     left += wr; n   } n } n void B() { n   long long cur = 0, left = c, t; n   while (left >= 0 && a.insert(left % wr).second) { n     ans = max(ans, (t = cur + (left / wr) * hr)); n     if ((t * 11) < 10 * ans) break; n     cur += hb; n     left -= wb; n   } n } n int main() { n   doin(); n   cin >> c >> hr >> hb >> wr >> wb; n   float rr = ((float)hr) / (float)wr; n   float rb = ((float)hb) / (float)wb; n   if (rr < rb) swap(hr, hb), swap(wr, wb); n   if (wr * 3 < wb) n     B(); n   else n     A(); n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2505; n using ll = long long; n int n, m, kk, a[N][N], sum[N][N], b[2][10]; n char ch[N][N]; n ll ans = 0; n inline int calc(int x1, int x2, int y1, int y2) { n   return sum[x2][y2] - sum[x1][y2] - sum[x2][y1] + sum[x1][y1]; n } n void solve(int x1, int x2, int y1, int y2, int tp) { n   if (x1 == x2 || y1 == y2) return; n   if (x1 == x2 - 1 && y1 == y2 - 1) { n     ans += calc(x1, x2, y1, y2) == kk; n     return; n   } n   if (tp) { n     int mid = (x1 + x2) >> 1; n     solve(x1, mid, y1, y2, 0); n     solve(mid, x2, y1, y2, 0); n     for (int i = y1; i <= y2; i++) { n       b[0][0] = b[1][0] = mid; n       for (int j = 1; j <= kk + 1; j++) b[0][j] = x1, b[1][j] = x2; n       for (int j = i + 1; j <= y2; j++) { n         for (int k = 1; k <= kk + 1; k++) n           while (calc(b[0][k], mid, i, j) >= k) ++b[0][k]; n         for (int k = 1; k <= kk + 1; k++) n           while (calc(mid, b[1][k], i, j) >= k) --b[1][k]; n         for (int k = 0; k <= kk; k++) n           ans += ll(b[0][k] - b[0][k + 1]) * (b[1][kk - k + 1] - b[1][kk - k]); n       } n     } n   } else { n     int mid = (y1 + y2) >> 1; n     solve(x1, x2, y1, mid, 1); n     solve(x1, x2, mid, y2, 1); n     for (int i = x1; i <= x2; i++) { n       b[0][0] = b[1][0] = mid; n       for (int j = 1; j <= kk + 1; j++) b[0][j] = y1, b[1][j] = y2; n       for (int j = i + 1; j <= x2; j++) { n         for (int k = 1; k <= kk + 1; k++) n           while (calc(i, j, b[0][k], mid) >= k) ++b[0][k]; n         for (int k = 1; k <= kk + 1; k++) n           while (calc(i, j, mid, b[1][k]) >= k) --b[1][k]; n         for (int k = 0; k <= kk; k++) n           ans += ll(b[0][k] - b[0][k + 1]) * (b[1][kk - k + 1] - b[1][kk - k]); n       } n     } n   } n } n int main() { n   ios::sync_with_stdio(false); n   cin >> n >> m >> kk; n   for (int i = 1; i <= n; i++) cin >> (ch[i] + 1); n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= m; j++) n       sum[i][j] = n           sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + ch[i][j] -  0 ; n   solve(0, n, 0, m, 0); n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool p(long long n) { n   for (long long i = 2; i <= sqrt(n); i++) { n     if (n % i == 0) return 0; n   } n   return 1; n } n int main() { n   long long m, n, i, j, k; n   cin >> n; n   if (p(n)) { n     cout << 1 << endl << n; n   } else { n     cout << 3 << endl << 3 <<    ; n     for (i = 3, n -= 3; i < n; i += 2) { n       if (p(i) && p(n - i)) { n         cout << i <<     << n - i << endl; n         return 0; n       } n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long f[55][2][2], K, d; n int a[55], n; n long long C(int l, int r, int x, int y) { n   if (l > r) return 1; n   long long& F = f[l][x][y]; n   if (~F) return F; n   F = 0; n   for (int i = 0; i <= 1; ++i) n     for (int j = 0; j <= 1; ++j) n       if (a[l] - !i && a[r] - !j && (l < r || i == j) && (x || i <= j) && n           (y || i <= (!j))) n         F += C(l + 1, r - 1, x || (i < j), y || (i < !j)); n   return F; n } n int main() { n   cin >> n >> K; n   memset(a, -1, sizeof a); n   memset(f, -1, sizeof f); n   if (C(1, n, a[1] = 0, 0) < ++K) return cout << -1, 0; n   for (int i = 2; i <= n; ++i) { n     memset(f, -1, sizeof f); n     d = C(1, n, a[i] = 0, 0); n     K -= (a[i] = (d < K)) * d; n   } n   for (int i = 1; i <= n; ++i) cout << a[i]; n } n


#include <bits/stdc++.h> n using namespace std; n void solve() { n   long long int a, b, c; n   cin >> a >> b >> c; n   long long int x = min(a, min(b, c)); n   long long int z = max(a, max(b, c)); n   long long int y = a + b + c - x - z; n   long long int xi = a == x ? 1 : b == x ? 2 : 3; n   long long int yi = a == y ? 1 : b == y ? 2 : 3; n   long long int zi = 6 - xi - yi; n   cout <<  First  << endl; n   cout.flush(); n   cout << 2 * z - x - y << endl; n   cout.flush(); n   long long int p; n   cin >> p; n   if (p == xi) { n     cout << z - y << endl; n     cout.flush(); n   } else if (p == yi) { n     cout << z - x << endl; n     cout.flush(); n   } else { n     long long int r = 3 * z - x - y; n     cout << 2 * r - x - y << endl; n     cout.flush(); n     cin >> p; n     if (p == xi) n       cout << r - y << endl; n     else n       cout << r - x << endl; n     cout.flush(); n   } n   cin >> y; n } n int32_t main() { n   ios_base::sync_with_stdio(0); n   cin.tie(NULL); n   cout.tie(NULL); n   long long int t; n   t = 1; n   while (t--) { n     solve(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m, l, d; n   cin >> n >> d >> m >> l; n   long long x = 0; n   long long L = -m; n   long long R = -m + l; n   for (int i = 0; i < n; i++) { n     L += m; n     R += m; n     if (x + d < L) break; n     long long o = (R - x) / d; n     x = x + d * o; n   } n   cout << x + d; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> g; n int a[100005], b[100005], c[100005]; n int n, k; n void solve() { n   int i, j, m, ans, cnt; n   c[m = 0] = a[0]; n   for (i = 1; i < n; i++) n     if (a[i] != a[i - 1]) c[++m] = a[i]; n   b[a[0]]--; n   for (i = 1; i <= m; i++) { n     b[c[i]]--; n     if (c[i - 1] == c[i + 1]) b[c[i]]--; n   } n   j = 1; n   for (i = 1; i <= k; i++) n     if (b[j] > b[i]) j = i; n   cout << j << endl; n } n int main() { n   scanf( %d%d , &n, &k); n   for (int i = 0; i < n; i++) scanf( %d , &a[i]); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 60; n int n, m; n char s[N][N]; n bool vis[N][N]; n int tmp; n int dx[] = {-1, 0, 1, 0}; n int dy[] = {0, -1, 0, 1}; n inline bool in(int x, int y) { return x >= 0 && x < n && y >= 0 && y < m; } n void dfs(int x, int y) { n   vis[x][y] = 1; n   tmp++; n   for (int i = 0; i < 4; ++i) { n     int tx = x + dx[i]; n     int ty = y + dy[i]; n     if (in(tx, ty) && s[tx][ty] ==  # ) { n       if (!vis[tx][ty]) { n         dfs(tx, ty); n       } n     } n   } n } n int main() { n   scanf( %d%d , &n, &m); n   for (int i = 0; i < n; ++i) { n     scanf( %s , s[i]); n   } n   int cnt = 0; n   for (int i = 0; i < n; ++i) { n     for (int j = 0; j < m; ++j) { n       if (s[i][j] ==  # ) { n         ++cnt; n       } n     } n   } n   if (cnt == 1 || cnt == 2) { n     printf( -1 n ); n     return 0; n   } n   for (int i = 0; i < n; ++i) { n     for (int j = 0; j < m; ++j) { n       if (s[i][j] ==  # ) { n         s[i][j] =  . ; n         memset(vis, 0, sizeof(vis)); n         for (int a = 0; a < n; ++a) { n           for (int b = 0; b < m; ++b) { n             if (s[a][b] ==  # ) { n               tmp = 0; n               dfs(a, b); n               if (tmp != cnt - 1) { n                 printf( 1 n ); n                 return 0; n               } n               a = n, b = m; n             } n           } n         } n         s[i][j] =  # ; n       } n     } n   } n   printf( 2 n ); n   return 0; n } n