#include <bits/stdc++.h>   using namespace std;   const double pi =       3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;   const int MR = 1e5 + 10;   const long long inf = 1e18;   long long dp[21][MR];   int A[21][MR];   int a[MR];   int freq[MR], gp, gk;   long long cost;   long long ile(int b, int e) {     while (gp > b) {       cost += freq[a[gp - 1]];       freq[a[gp - 1]]++;       gp--;     }     while (gp < b) {       freq[a[gp]]--;       cost -= freq[a[gp]];       gp++;     }     while (gk > e) {       freq[a[gk - 1]]--;       cost -= freq[a[gk - 1]];       gk--;     }     while (gk < e) {       cost += freq[a[gk]];       freq[a[gk]]++;       gk++;     }     return cost;   }   void compute(int k, int l, int r, int Al, int Ar) {     if (l >= r) return;     assert(Al <= Ar);     int m = (l + r) / 2;     dp[k][m] = inf;     for (int i = (max(Al, A[k - 1][m])); i < (min(Ar + 1, m)); ++i) {       long long cnt = ile(i + 1, m + 1);       if (dp[k][m] > dp[k - 1][i] + cnt) {         dp[k][m] = dp[k - 1][i] + cnt;         A[k][m] = i;       }     }     compute(k, l, m, Al, A[k][m]);     compute(k, m + 1, r, A[k][m], Ar);   }   int main() {     int n, k;     scanf( %d%d , &n, &k);     for (int i = (1); i <= (n); ++i) scanf( %d , &a[i]);     gp = 1;     gk = 1;     for (int i = (1); i <= (n); ++i) {       dp[1][i] = ile(1, i + 1);       A[1][i] = 0;     }     for (int i = (2); i <= (k); ++i) compute(i, i, n + 1, i - 1, n);     cout << dp[k][n] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline long long read() {     long long x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = (x * 10) + (ch -  0 );       ch = getchar();     }     return x * f;   }   long long Pow[25][505], n, V, ans, B;   long long val[505];   void dfs2(long long i, long long b, long long a) {     if ((double)b * b > V / a) {       return;     }     if (i > n) {       B = max(B, b);       return;     }     for (register long long j = val[i]; j >= 0; --j) {       dfs2(i + 1, b * Pow[i][j], a);     }   }   long long ansA, ansB, ansC;   void dfs1(long long i, long long a) {     if ((double)a * a * a > V) {       return;     }     if (i > n) {       const long long t = V / a;       long long Smax = 4 * a * sqrt(t) + 2 * t;       if (Smax >= ans) return;       B = 0, dfs2(1, 1, a);       long long c = V / a / B, Ans = (a * B + B * c + c * a) << 1;       if (Ans < ans) {         ans = Ans;         ansA = a, ansB = B, ansC = c;       }       return;     }     for (register long long j = val[i]; j >= 0; --j) {       val[i] -= j;       dfs1(i + 1, a * Pow[i][j]);       val[i] += j;     }   }   int main() {     long long T;     cin >> T;     while (T--) {       cin >> n;       V = 1;       for (register long long i = 1; i <= n; ++i) {         long long a, b;         cin >> a >> b;         val[i] = b;         Pow[i][0] = 1;         for (register long long j = 1; j <= b; ++j) {           Pow[i][j] = Pow[i][j - 1] * a;         }         V *= Pow[i][b];       }       ans = 1ll << 62;       dfs1(1, 1);       cout << ans <<     << ansA <<     << ansB <<     << ansC << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ii = pair<int, int>;   using vi = vector<int>;   const double PI = acos(-1);   const double EPS = 1e-9;   int main() {     ios_base::sync_with_stdio(0);     int n, m;     cin >> n >> m;     int mt[n][m];     int ans = 0;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         cin >> mt[i][j];         if (j == 0) {           ans ^= mt[i][j];         }       }     }     if (ans > 0) {       cout <<  TAK n ;       for (int i = 0; i < n; i++) {         cout << 1;         if (i == n - 1)           cout << endl;         else           cout <<    ;       }     } else {       ii res(-1, -1);       for (int i = 0; i < n; i++) {         for (int j = 1; j < m; j++) {           int kk = ans ^ mt[i][0] ^ mt[i][j];           if (kk > 0) {             res.first = i;             res.second = j;           }         }       }       int aa = ans ^ 1 ^ 0;       if (res.first >= 0)         ans = ans ^ mt[res.first][0] ^ mt[res.first][res.second];       if (ans > 0) {         cout <<  TAK n ;         for (int i = 0; i < n; i++) {           if (i == res.first)             cout << res.second + 1;           else             cout << 1;           if (i == n - 1)             cout << endl;           else             cout <<    ;         }       } else {         cout <<  NIE n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   vector<long long int> prm(1000010, 1);   long long int P = 1e9 + 7;   long long int M = 998244353;   char adjlist[1001][1001];   bool visited[1000001] = {false};   long double pi = 3.14159265358979323846264338327950;   map<int, int> visit;   map<int, set<int>> g;   int cc = 0;   vector<pair<int, int>> moves = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};   int lps[1000000];   vector<pair<int, int>> final_set;   bool comp(const pair<long long int, long long int> &a,             const pair<long long int, long long int> &b) {     if (a.first == b.first) return a.second > b.second;     return a.first < b.first;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int n, m, s, f;     cin >> n >> m >> s >> f;     bool flag = true;     long long int curr = s;     if (s > f) flag = false;     long long int i, j;     long long int t, x, y;     bool mflag = false;     long long int back = 0;     string str =   ;     for (i = 0; i < m; i++) {       if (i == 0)         back = 0;       else         back = t;       cin >> t >> x >> y;       if (curr == f) continue;       if (t - 1 != back) {         while (back + 1 < t) {           if (flag == false) {             str.push_back( L );             curr--;           } else {             str.push_back( R );             curr++;           }           if (curr == f) break;           back++;         }       }       if (curr == f) continue;       if (flag == false) {         if (curr < x || curr - 1 > y) {           str.push_back( L );           curr--;           continue;         } else {           str.push_back( X );           continue;         }       } else {         if (curr > y || curr + 1 < x) {           str.push_back( R );           curr++;           continue;         } else {           str.push_back( X );           continue;         }       }     }     if (curr != f) {       if (flag == false) {         for (i = curr; i > f; i--) str.push_back( L );       } else {         for (i = curr; i < f; i++) str.push_back( R );       }     }     cout << str <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   mt19937 rnd;   const long long maxn = 2e6 + 5;   const long long mod = 1e9 + 7;   long long fac[maxn];   long long inv[maxn];   vector<char> prime(maxn, true);   long long spf[maxn];   long long binpow(long long a, long long b) {     if (b == 0) return 1;     if (b == 1) return a % mod;     if (b == 2) return (a * a) % mod;     if (b % 2 == 0) return binpow((a * a) % mod, b / 2);     if (b % 2 == 1) return (a * binpow((a * a) % mod, b / 2)) % mod;   }   void buildprimes() {     prime[0] = prime[1] = false;     for (long long i = 2; i < maxn; ++i) {       if (prime[i]) {         spf[i] = i;         if (i * 1ll * i < maxn) {           for (long long j = i * i; j < maxn; j += i) {             prime[j] = false;             spf[j] = i;           }         }       }     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     fac[1] = fac[0] = 1;     for (long long i = 2; i < maxn; i++) {       fac[i] = (fac[i - 1] * i) % mod;     }     for (long long i = 1; i < maxn; i++) {       inv[i] = binpow(fac[i], mod - 2);     }     buildprimes();     int q;     cin >> q;     while (q--) {       int x, y;       cin >> x >> y;       if (y == 1) {         cout <<  1 n ;         continue;       }       long long ans = 1;       ans = binpow(2, y - 1);       while (x > 1) {         long long cur = 0;         long long p = spf[x];         while (x % p == 0) {           x /= p;           cur++;         }         long long C = (((fac[cur + y - 1] * inv[y - 1]) % mod) * inv[cur]) % mod;         ans = (ans * C) % mod;       }       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     string t =   ;     for (int i = 0; i < s.length(); i++) {       if (s[i] !=  a  && s[i] !=  e  && s[i] !=  i  && s[i] !=  o  &&           s[i] !=  u  && s[i] !=  y  && s[i] !=  Y  && s[i] !=  A  &&           s[i] !=  E  && s[i] !=  I  && s[i] !=  O  && s[i] !=  U ) {         t += s[i];       }     }     string p =   ;     for (int i = 0; i < t.length(); i++) {       char c = t[i];       if (isupper(c)) {         p += tolower(c);       } else {         p += c;       }     }     string l =   ;     for (int i = 0; i < p.length(); i++) {       l +=  . ;       l += p[i];     }     cout << l;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     string s;     for (int i = 1; i < 1000000 && s.size() < 1000; i++) {       char val[20];       sprintf(val,  %d , i);       s += val;     }     int n;     cin >> n;     cout << s[n - 1];     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e5;   const double EPS = 1e-8;   int a[MAXN], b[MAXN];   int n, p;   bool f(double T) {     double have = p * T;     for (int i = 0; i < n; ++i) {       if (a[i] * T > b[i] + EPS) have += b[i] - a[i] * T;     }     return have > 0.0 + EPS;   }   int main() {     cin >> n >> p;     long long sum = 0;     for (int i = 0; i < n; ++i) {       cin >> a[i] >> b[i];       sum += a[i];     }     if (sum <= p) {       cout << -1;       return 0;     }     double left = 0, right = 1e10;     for (int i = 0; i < 80; ++i) {       double middle = (left + right) / 2;       if (f(middle))         left = middle;       else         right = middle;     }     cout << fixed;     cout.precision(10);     cout << left;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     long long mn, mx, n, m;     cin >> n >> m;     mx = n - m;     mx++;     mx = (mx * (mx - 1)) / 2;     mn = n / m;     long long temp = n / m;     if (n % m != 0) {       mn = (n % m) * ((mn * (mn + 1)) / 2);       m -= (n % m);       mn += m * ((temp * (temp - 1)) / 2);     } else       mn = m * ((temp * (temp - 1)) / 2);     cout << mn <<     << mx << endl;     return 0;   }


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


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   using namespace std;   mt19937 rnd(chrono::steady_clock().now().time_since_epoch().count());   const int N = 765;   const long long inf = (long long)4e18;   long long dp[N][N];   long long f[N];   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     int n, m;     cin >> n >> m;     long long a[n];     for (int i = 0; i < n; i++) {       cin >> a[i];     }     for (int i = 0; i < N; i++) {       for (int j = 0; j < N; j++) {         dp[i][j] = -inf;       }     }     dp[n][0] = 0;     for (int i = n - 1; i >= 0; i--) {       for (int j = 0; j <= n; j++) {         dp[i][j] = min(a[i] + dp[i + 1][j], a[i]);         if (j > 0) {           dp[i][j] = max(dp[i][j], dp[i + 1][j - 1]);         }       }     }     for (int j = 0; j <= n; j++) f[j] = dp[0][j];     long long b;     for (int i = 1; i <= m; i++) {       cin >> b;       for (int i = 0; i <= n; i++) {         if (b + f[i] >= 0) {           cout << i <<   n ;           break;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = (int)2e5 + 10, L = 4, INF = (int)1e9;   struct State {     int fa, len, tr[L], w[L];   } SAM[MAXN];   char t[MAXN];   vector<int> l[MAXN];   int m, tot;   unsigned long long a[L], b[L][L], c[L][L];   unsigned long long n;   int Build(int pre, int id) {     int cp = ++tot;     SAM[cp].len = SAM[pre].len + 1;     for (; !SAM[pre].tr[id] && pre; SAM[pre].tr[id] = cp, pre = SAM[pre].fa)       ;     if (pre)       if (SAM[pre].len + 1 == SAM[SAM[pre].tr[id]].len)         SAM[cp].fa = SAM[pre].tr[id];       else {         int tp = SAM[pre].tr[id];         ++tot, SAM[tot].len = SAM[pre].len + 1, SAM[tot].fa = SAM[tp].fa;         memcpy(SAM[tot].tr, SAM[tp].tr, sizeof(SAM[tot].tr));         SAM[cp].fa = SAM[tp].fa = tot;         for (; pre && SAM[pre].tr[id] == tp;              SAM[pre].tr[id] = tot, pre = SAM[pre].fa)           ;       }     else       SAM[cp].fa = 1;     return cp;   }   void init() {     cin >> n;     scanf( %s , t + 1);     m = strlen(t + 1);     tot = 1;     for (int i = 1, p = 1; i <= m; ++i) p = Build(p, t[i] -  A );     for (int i = 1; i <= tot; ++i) {       for (int j = 0; j < L; ++j)         if (!SAM[i].tr[j])           SAM[i].w[j] = 1;         else           SAM[i].w[j] = INF;       l[SAM[i].len].push_back(i);     }     for (int i = m; i >= 0; --i)       for (int j = 0; j < (int)l[i].size(); ++j)         for (int k = 0; k < L; ++k)           if (SAM[l[i][j]].tr[k])             for (int p = 0; p < L; ++p) {               int first = l[i][j];               SAM[first].w[p] =                   min(SAM[first].w[p], SAM[SAM[first].tr[k]].w[p] + 1);             }   }   void mul(unsigned long long a[][L], unsigned long long b[][L],            unsigned long long c[][L]) {     static unsigned long long w[L][L];     for (int i = 0; i < L; ++i)       for (int j = 0; j < L; ++j) w[i][j] = n + 1;     for (int i = 0; i < L; ++i)       for (int j = 0; j < L; ++j)         for (int k = 0; k < L; ++k) w[i][j] = min(w[i][j], b[i][k] + c[k][j]);     for (int i = 0; i < L; ++i)       for (int j = 0; j < L; ++j) a[i][j] = w[i][j];   }   void Pow(unsigned long long a[][L], unsigned long long b) {     static unsigned long long d[L][L];     for (int i = 0; i < L; ++i)       for (int j = 0; j < L; ++j) d[i][j] = n + 1;     for (int i = 0; i < L; ++i) d[i][i] = 0;     for (; b; mul(a, a, a), b /= 2)       if (b & 1) mul(d, d, a);     memcpy(a, d, sizeof(d));   }   unsigned long long check(unsigned long long k) {     memcpy(b, c, sizeof(b));     Pow(b, k - 2);     unsigned long long Tohka = n + 1;     for (int i = 0; i < L; ++i)       for (int j = 0; j < L; ++j) Tohka = min(Tohka, a[i] + b[i][j]);     return Tohka;   }   unsigned long long Find(unsigned long long l, unsigned long long r) {     while (l <= r) {       unsigned long long mid = (l + r) >> 1;       if (check(mid) > n)         r = mid - 1;       else         l = mid + 1;     }     return r;   }   void solve() {     for (int i = 0; i < L; ++i) a[i] = max(SAM[1].w[i], 1);     for (int i = 0; i < L; ++i)       for (int j = 0; j < L; ++j) c[i][j] = max(SAM[SAM[1].tr[i]].w[j], 1);     if (n == 1)       puts( 1 );     else       cout << Find(2, n) << endl;   }   int main() {     init();     solve();     fclose(stdin);     fclose(stdout);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 20;   int a[MAXN];   int main() {     int k;     scanf( %d , &k);     for (int i = 1; i <= 12; i++) {       scanf( %d , &a[i]);     }     sort(a + 1, a + 13);     int tot = 0, ans = 0;     for (int i = 12; i >= 1; i--) {       if (tot >= k) {         break;       }       tot += a[i];       ans++;     }     if (tot < k) {       printf( -1 n );     } else {       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     switch (n) {       case 1:         cout << n * 2 << endl;         break;       case 2:         cout << n + 1 << endl;         break;       case 3:         cout << n - 2 << endl;         break;       case 4:         cout << n / 2 << endl;         break;       case 5:         cout << n / n << endl;         break;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 2e5;   int main() {     int n;     cin >> n;     int f = 0, z = 0;     for (int i = 0; i < n; i++) {       int val;       scanf( %d , &val);       if (val == 5)         f++;       else         z++;     }     int mx = 0;     for (int i = 0; i <= f; i++)       if ((5 * i) % 9 == 0) mx = i;     if (!z)       cout << -1;     else {       if (!mx)         cout << 0;       else {         for (int i = 0; i < mx; i++) cout << 5;         for (int i = 0; i < z; i++) cout << 0;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const long long inf = 1 << 30;   long long m, r;   signed main() {     double ans = 0;     scanf( %d%d , &m, &r);     for (long long i = 1; i <= m; i++) {       double sum = 2 * r;       if (i - 1 != 0) {         sum += 2 * r + sqrt(2) * r;         if (i - 1 >= 2) {           sum += r * (i - 1) * (i - 2) + (i - 2) * 2 * sqrt(2) * r;         }       }       if (m - i != 0) {         sum += 2 * r + sqrt(2) * r;         if (m - i >= 2) {           sum += r * (m - i - 0) * (m - i - 1) + (m - i - 1) * 2 * sqrt(2) * r;         }       }       ans += sum;     }     printf( %.8f n , ans / (m * m));     return 0;   }


#include <bits/stdc++.h>   using i64 = long long;   int n;   std::vector<std::vector<int>> g;   std::vector<int> sz, d;   int dfs(int v, int p) {     return sz[v] =                std::accumulate(g[v].begin(), g[v].end(), 1, [=](int s, int c) {                  return s + (d[c] >= 0 || c == p ? 0 : dfs(c, v));                });   }   int centroid(int v, int p, int t) {     for (auto c : g[v]) {       if (d[c] >= 0 || c == p) continue;       if (2 * sz[c] > t) return centroid(c, v, t);     }     return v;   }   void rec(int v, int r) {     dfs(v, -1);     int c = centroid(v, -1, sz[v]);     d[c] = r;     for (auto e : g[c]) {       if (d[e] >= 0) continue;       rec(e, r + 1);     }   }   int main() {     scanf( %d , &n);     g.resize(n);     sz.resize(n);     d.resize(n, -1);     for (int i = 1; i < n; i++) {       int u, v;       scanf( %d%d , &u, &v);       --u;       --v;       g[u].push_back(v);       g[v].push_back(u);     }     rec(0, 0);     for (char c : d) printf( %c  ,  A  + c);     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int read() {     int x = 0, f = 1;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) f = -1;       c = getchar();     }     while ( 0  <= c && c <=  9 ) {       x = x * 10 + c -  0 ;       c = getchar();     }     return x * f;   }   int n, m, cnt, h[200005], X[200005], Y[200005], dep[200005], du[200005], Tot,       col[200005], ans[200005];   struct Edge {     int to, next;   } a[200005 * 2];   inline void Add(int x, int y) {     cnt++;     a[cnt].to = y;     a[cnt].next = h[x];     h[x] = cnt;   }   void dfs(int x, int fa, int ban) {     dep[x] = dep[fa] + 1;     int now = 1;     if (ban == Tot)       for (int i = h[x]; i; i = a[i].next) {         int y = a[i].to;         if (y != fa) {           ans[y] = now;           dfs(y, x, now);           now = min(now + 1, Tot - 1);           if (!now) now = 1;         }       }     else       for (int i = h[x]; i; i = a[i].next) {         int y = a[i].to;         if (y != fa) {           if (now == ban) now++;           ans[y] = now;           dfs(y, x, now);           now = min(now + 1, Tot);         }       }   }   bool check(int lim) {     int sum = 0;     for (int i = 1; i <= n; ++i) sum += (du[i] > lim);     return sum <= m;   }   int main() {     n = read();     m = read();     for (int i = 1; i < n; ++i) {       int x = read(), y = read();       X[i] = x;       Y[i] = y;       Add(x, y);       Add(y, x);       du[x]++;       du[y]++;     }     int l = 1, r = n, mid;     while (l <= r) {       mid = l + r >> 1;       if (check(mid))         r = mid - 1, Tot = mid;       else         l = mid + 1;     }     dfs(1, 0, 0);     cout << Tot <<   n ;     for (int i = 1; i < n; ++i) {       if (dep[X[i]] > dep[Y[i]])         cout << ans[X[i]] <<    ;       else         cout << ans[Y[i]] <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e5 + 123;   const int MINN = 1e3 + 123;   const int mod = 1e9 + 7;   const int INF = 1e9 + 1;   pair<int, int> a[MINN];   bool cmp(pair<int, int> a, pair<int, int> b) {     if (a.first < b.first) return 1;     if (a.first == b.first)       if (a.second > b.second) return 1;     return 0;   }   int main() {     int n, sum;     cin >> sum >> n;     for (int i = 1; i <= n; i++) scanf( %d%d , &a[i].first, &a[i].second);     sort(a + 1, a + n + 1, &cmp);     for (int i = 1; i <= n; i++) {       if (sum <= a[i].first) {         cout <<  NO ;         return 0;       }       sum += a[i].second;     }     cout <<  YES ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 2e5 + 100;   int m, n;   long long sweets[MAXN];   vector<long long> sol;   long long weightedSum;   long long sums[MAXN];   int main() {     cin >> n >> m;     for (int i = 0; i < n; i++) {       cin >> sweets[i];     }     sort(sweets, sweets + n);     for (int i = 0; i < n;) {       for (int j = 0; j < m && i + j < n; j++) {         sums[j] += sweets[i + j];         weightedSum += sums[j];         sol.push_back(weightedSum);       }       i += m;     }     for (int i = 0; i < sol.size(); i++) {       cout << sol[i] <<    ;     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct MP {     long long g[310][310];   } f[10], nil, tmp, c;   int n, m, x, y, z1, z2, ans;   void U(long long &x, long long y) { x = max(x, y); }   MP CC(MP &f1, MP &f2) {     MP res = nil;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++) {         for (int k = 1; k <= n; k++) U(res.g[i][j], f1.g[i][k] + f2.g[k][j]);         U(res.g[i][j], min(f1.g[i][j], f2.g[i][j]));       }     return res;   }   bool pd(MP &t) {     for (int i = 1; i <= n; i++)       if (t.g[i][i] > 0) return 1;     return 0;   }   int main() {     scanf( %d%d , &n, &m);     memset(nil.g, -38, sizeof nil.g);     for (int i = 0; i < 10; i++) f[i] = nil;     for (; m--;) {       scanf( %d%d%d%d , &x, &y, &z1, &z2);       f[0].g[x][y] = z1;       f[0].g[y][x] = z2;     }     for (int i = 1; i < 10; i++) {       f[i] = CC(f[i - 1], f[i - 1]);       if (pd(f[i])) {         ans = 1 << i >> 1;         tmp = f[i - 1];         for (int j = i - 2; j >= 0; j--) {           c = CC(tmp, f[j]);           if (!pd(c)) {             tmp = c;             ans += 1 << j;           }         }         return 0 * printf( %d , ans + 1);       }     }     printf( 0 );   }


#include <bits/stdc++.h>   const long long oo = 2 * 1000 * 1000 * 1000;   const int _cnt = 1000 * 1000;   const int _p = 1000 * 1000 * 1000 + 7;   long long o(long long x) { return x % _p; }   int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }   int lcm(int a, int b) { return a * b / gcd(a, b); }   using namespace std;   void file_put() {     freopen( filename.in ,  r , stdin);     freopen( filename.out ,  w , stdout);   }   struct squaretype {     int x, r;   };   string st;   int a[1000], n, m;   bool check(string st) {     for (int i = 0; i < st.length(); i++)       if (st[i] != st[0]) return false;     return true;   }   int main() {     scanf( %d%d , &n, &m);     cin.ignore();     for (int i = 1; i <= n; i++) {       getline(cin, st);       if (check(st)) {         a[i] = st[0];         continue;       }       printf( NO n );       return 0;     }     for (int i = 2; i <= n; i++)       if (a[i] == a[i - 1]) {         printf( NO n );         return 0;       }     printf( YES n );     return 0;   }


#include <bits/stdc++.h>   const int N = 1e6 + 6, mod = 1e9 + 7;   int n, sum[3];   inline int read() {     int s = 0, f = 1;     char ch;     for (; ch <  0  || ch >  9 ; ch = getchar())       if (ch ==  - ) f = -1;     for (; ch >=  0  && ch <=  9 ; ch = getchar())       s = (s << 1) + (s << 3) + ch -  0 ;     return s * f;   }   inline int add(int a, int b) { return (a += b) >= mod ? a - mod : a; }   inline int sub(int a, int b) { return (a -= b) < 0 ? a + mod : a; }   inline int mul(int a, int b) { return 1LL * a * b % mod; }   inline void Add(int &a, int b) { a = add(a, b); }   inline void Sub(int &a, int b) { a = sub(a, b); }   inline void Mul(int &a, int b) { a = mul(a, b); }   inline int quickpow(int a, int b) {     int re = 1;     while (b) {       if (b & 1) Mul(re, a);       b >>= 1;       Mul(a, a);     }     return re;   }   int fac[N + 1], inv[N + 1], f[N + 1];   inline void input() {     fac[0] = 1;     for (int i = 1; i <= N; ++i) fac[i] = mul(fac[i - 1], i);     inv[N] = quickpow(fac[N], mod - 2);     for (int i = N; i >= 1; --i) inv[i - 1] = mul(inv[i], i);     f[0] = f[1] = 1, f[2] = 2;     for (int i = 3; i <= N; ++i) f[i] = add(mul(f[i - 2], (i - 1)), f[i - 1]);   }   inline int C(int n, int m) {     if (n < m || n < 0 || m < 0) return 0;     return mul(fac[n], mul(inv[m], inv[n - m]));   }   int main() {     input();     for (int _ = 1; _; --_) {       n = read();       sum[1] = sum[2] = 0;       for (int i = 1; i <= n; ++i) ++sum[read()];       printf( %d n , mul(mul(fac[n], inv[sum[1]]), f[sum[1]]));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 200001;   long long par[N], siz[N];   long long f(long long n) {     if (n == par[n])       return n;     else       return par[n] = f(par[n]);   }   void u(long long a, long long b) {     a = f(a);     b = f(b);     if (a != b) {       if (siz[a] < siz[b]) swap(a, b);       par[b] = a;       siz[a] += siz[b];     }   }   void solve() {     long long n;     cin >> n;     string s[n + 1];     for (long long i = 1; i <= n; i++) {       cin >> s[i];       par[i] = i;       siz[i] = 1;     }     for (char c =  a ; c <=  z ; c++) {       vector<long long> v;       for (long long i = 1; i <= n; i++) {         for (long long j = 0; j < s[i].length(); j++) {           if (s[i][j] == c) v.push_back(i);         }       }       for (long long i = 1; i < v.size(); i++) u(v[i], v[i - 1]);     }     set<long long> se;     for (long long i = 1; i <= n; i++) {       long long x = f(i);       se.insert(x);     }     cout << se.size() <<   n ;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long t = 1;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void _print(long long t) { cerr << t; }   void _print(int t) { cerr << t; }   void _print(string t) { cerr << t; }   void _print(char t) { cerr << t; }   void _print(long double t) { cerr << t; }   void _print(double t) { cerr << t; }   void _print(unsigned long long t) { cerr << t; }   template <class T, class V>   void _print(pair<T, V> p);   template <class T>   void _print(vector<T> v);   template <class T>   void _print(set<T> v);   template <class T, class V>   void _print(map<T, V> v);   template <class T>   void _print(multiset<T> v);   template <class T, class V>   void _print(pair<T, V> p) {     cerr <<  { ;     _print(p.first);     cerr <<  , ;     _print(p.second);     cerr <<  } ;   }   template <class T>   void _print(vector<T> v) {     cerr <<  [  ;     for (T i : v) {       _print(i);       cerr <<    ;     }     cerr <<  ] ;   }   template <class T>   void _print(set<T> v) {     cerr <<  [  ;     for (T i : v) {       _print(i);       cerr <<    ;     }     cerr <<  ] ;   }   template <class T>   void _print(multiset<T> v) {     cerr <<  [  ;     for (T i : v) {       _print(i);       cerr <<    ;     }     cerr <<  ] ;   }   template <class T, class V>   void _print(map<T, V> v) {     cerr <<  [  ;     for (auto i : v) {       _print(i);       cerr <<    ;     }     cerr <<  ] ;   }   int gcd(int a, int b) {     if (b == 0)       return a;     else       return gcd(b, a % b);   }   bool isprime(long long a) {     if (a <= 1) return false;     if (a == 2 || a == 3) return true;     if (a % 2 == 0 || a % 3 == 0) return false;     for (int i = 5; i * i <= a; i += 6) {       if (a % i == 0 || a % (i + 2) == 0) return false;     }     return true;   }   void sieve(vector<bool> &isprimesieve) {     isprimesieve[0] = isprimesieve[1] = false;     for (int i = 2; i * i <= 1000000; i++) {       if (isprimesieve[i]) {         for (int j = i * i; j <= 1000000; j += i) {           isprimesieve[j] = false;         }       }     }   }   bool isperfectsq(long long a) { return (sqrt(a) - (int)sqrt(a) == 0); }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int t = 0;     cin >> t;     while (t--) {       int n;       cin >> n;       string s;       cin >> s;       bool flag = false;       for (int i = 0; i < n; i++) {         if (s[i] ==  0 ) {           flag = true;           if (i >= n / 2) {             cout << 1 <<     << i + 1 <<     << 1 <<     << i <<   n ;             break;           } else {             cout << i + 1 <<     << n <<     << i + 2 <<     << n <<   n ;             break;           }         }       }       if (!flag) {         cout << 1 <<     << n - 1 <<     << 2 <<     << n <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-8;   const double pi = acos(-1.0);   const long long INF = 0x3f3f3f3f3f3f3f3f;   const int inf = 0x3f3f3f3f;   const long long mod = 1e9 + 7;   const int N = 1e5 + 10;   struct zz {     long long x, y;   } a[N];   bool check(zz z1, zz z2, zz y1, zz y2) {     if ((z1.y - z2.y) * (y1.x - y2.x) == (z1.x - z2.x) * (y1.y - y2.y))       return true;     else       return false;   }   long long dis(zz z1, zz z2) {     return (z1.x - z2.x) * (z1.x - z2.x) + (z1.y - z2.y) * (z1.y - z2.y);   }   bool check(int n) {     while (n % 2 == 0) {       n /= 2;     }     if (n == 1)       return true;     else       return false;   }   void solve() {     int n;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i].x >> a[i].y;     }     if (n & 1) {       cout <<  NO  << endl;       return;     }     int flag = 1;     for (int i = 0; i < n / 2; i++) {       if (!check(a[i], a[i + 1], a[i + n / 2], a[(i + n / 2 + 1) % n])) {         flag = 0;         break;       }     }     if (flag && n == 4) {       cout <<  YES  << endl;       return;     }     long long r = dis(a[1], a[0]);     for (int i = 0; i < n / 2; i++) {       if (dis(a[i], a[(i + 1) % n]) !=           dis(a[i + n / 2], a[(i + n / 2 + 1) % n])) {         flag = 0;         break;       }     }     if (flag)       cout <<  Yes  << endl;     else       cout <<  NO  << endl;   }   int main() {     ios::sync_with_stdio(false);     int t = 1;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int k, r, shovel = 1;     cin >> k >> r;     while ((k % 10) * shovel % 10 != r && (k % 10) * shovel % 10) shovel++;     cout << shovel;   }


#include <bits/stdc++.h>   const int INF = 1 << 29;   int cmp(const void* a, const void* b);   long long maxv(long long a, long long b);   long long minv(long long a, long long b);   long long gcd(long long u, long long v);   int main() {     char s[] =  aeiou ;     long long k, n, m;     scanf( %lld , &k);     if (k <= 24) {       printf( -1 n );       return 0;     }     for (long long i = 5; i <= k; i++) {       if (k % i != 0) continue;       n = i;       m = k / i;       if (m < 5) {         printf( -1 n );         return 0;       }       break;     }     for (long long i = 0; i < (n); i++) {       for (long long j = 0; j < (m); j++) {         printf( %c , s[(i + j) % 5]);       }     }   }   int cmp(const void* a, const void* b) {     if (*(long long*)a - *(long long*)b < 0) return -1;     if (*(long long*)a - *(long long*)b > 0) return 1;     return 0;   }   long long maxv(long long a, long long b) {     if (a > b) return a;     return b;   }   long long minv(long long a, long long b) {     if (a < b) return a;     return b;   }   long long gcd(long long u, long long v) {     if (v == 0) return u;     return gcd(v, u % v);   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const double eps = 1e-9;   const int Mod = 1e9 + 7;   const int MaxN = 2e5 + 5;   char s[MaxN];   int a[MaxN];   int l[MaxN], r[MaxN];   bool cmp(int x, int y) { return x > y; }   int main() {     int n, k;     scanf( %d %d , &n, &k);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     scanf( %s , s + 1);     int len = 0;     for (int i = 1; i <= n; i++) {       if (i == 1) {         l[++len] = 1;         continue;       }       if (s[i] == s[i - 1]) continue;       r[len] = i - 1;       l[++len] = i;     }     r[len] = n;     for (int i = 1; i <= len; i++) {       sort(a + l[i], a + r[i] + 1, cmp);     }     long long ans = 0LL, cnt = 1;     for (int i = 1; i <= n; i++) {       if (s[i] == s[i - 1])         cnt++;       else         cnt = 1;       if (cnt > k) continue;       ans += (long long)a[i];     }     printf( %lld n , ans);     return 0;   }


#include<bits/stdc++.h>   #define pb push_back   #define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)   #define ll long long   #define pii pair<int,int>   #define pll pair<ll,ll>   #define f first   #define s second   #define int long long   #define sz(x) (ll)(x.size())   using namespace std;         const int mod = 1e9+7;      int expo_pow(int x,int y){    if(y == 0) return 1;     y=y%(mod-1);     x%=mod;     if(y==0) y=mod-1;     int res=1;     while(y){       if(y&1) res=(res*x)%mod;       x=(x*x)%mod;       y>>=1;      }     return res;   }      ll add()   {       return 0;   }      template <typename T, typename... Types>   T add(T var1, Types... var2){       return (((((ll)(var1)) % mod + (ll)(add(var2...))) % mod) + mod) % mod;   }      ll mul(){       return 1;   }      template <typename T, typename... Types>   T mul(T var1, Types... var2){       return (((ll)(var1)) % mod * (ll)(mul(var2...))) % mod;   }      void solve(){     int n,x;     cin >> n >> x;     int mn = 0;     int sum = 0;     for (int i = 0; i < n; ++i) {       int tmp;       cin >> tmp;       sum += tmp;       mn += (tmp + x- 1)/x;     }        cout << (sum + x-1)/x <<     << mn <<   n ;   }         signed main(){     fast;     int test = 1;     cin>>test;     int i=1;     while(test--){       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   int fastio() {     ios_base::sync_with_stdio(false);     cout << fixed << setprecision(10);     cin.tie(nullptr);     return 0;   }   int __fastio = fastio();   void __print(int x) { cerr << x; }   void __print(long x) { cerr << x; }   void __print(long long x) { cerr << x; }   void __print(unsigned x) { cerr << x; }   void __print(unsigned long x) { cerr << x; }   void __print(unsigned long long x) { cerr << x; }   void __print(float x) { cerr << x; }   void __print(double x) { cerr << x; }   void __print(long double x) { cerr << x; }   void __print(char x) { cerr <<      << x <<     ; }   void __print(const char *x) { cerr <<     << x <<    ; }   void __print(const string &x) { cerr <<     << x <<    ; }   void __print(bool x) { cerr << (x ?  true  :  false ); }   template <typename T, typename V>   void __print(const pair<T, V> &x) {     cerr <<  { ;     __print(x.first);     cerr <<  , ;     __print(x.second);     cerr <<  } ;   }   template <typename T>   void __print(const T &x) {     int f = 0;     cerr <<  { ;     for (auto i : x) cerr << (f++ ?  ,  :   ), __print(i);     cerr <<  } ;   }   void _print() { cerr <<  ] n ; }   template <typename T, typename... V>   void _print(T t, V... v) {     __print(t);     if (sizeof...(v)) cerr <<  ,  ;     _print(v...);   }   void solve() {     int n;     cin >> n;     map<int, pair<int, int>> line;     for (int i = 0; i < n; i++) {       int x, r;       cin >> x >> r;       line[x] = {r, i};     }     vector<int> res(n, -1);     int m;     cin >> m;     int x, y;     auto inCircle = [](int x, int y, int x2, int r) {       long long dx = x - x2, dy = y, r2 = 1LL * r * r;       return dx * dx + dy * dy <= r2;     };     for (int j = 1; j <= m; j++) {       cin >> x >> y;       auto it = line.lower_bound(x);       if (it != line.end()) {         auto [x1, k] = *it;         auto [r, idx] = k;         if (res[idx] == -1 && inCircle(x, y, x1, r)) res[idx] = j;       }       if (it != line.begin()) {         --it;         auto [x1, k] = *it;         auto [r, idx] = k;         if (res[idx] == -1 && inCircle(x, y, x1, r)) res[idx] = j;       }     }     int hit = n - count(res.begin(), res.end(), -1);     cout << hit <<   n ;     for (int i = 0; i < n; i++) cout << res[i] <<    n [i == n - 1];   }   int main() {     int t = 1;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   vector<int> vt;   int n;   inline bool judge(int i) {     int ans = i;     while (i) {       ans += i % 10;       i /= 10;     }     return ans == n;   }   int main(void) {     std::ios::sync_with_stdio(false);     cin.tie(0);     while (cin >> n) {       vt.clear();       for (int i = max(n - 81, 1); i <= n; ++i)         if (judge(i)) vt.push_back(i);       cout << vt.size() << endl;       for (auto it : vt) cout << it << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   void read(long long &x) { scanf( %lld , &x); }   const long long N = 1000005;   struct city {     long long cnt, id;     bool operator<(const city b) const { return cnt < b.cnt; }   } a[N];   struct que {     long long x, id;     bool operator<(const que b) const { return x < b.x; }   } qq[N];   long long up[N], ans[N];   long long n, m, q;   struct node {     long long l, r, val;     long long cnt, sz, rnd;   } tr[N];   long long tot, rt;   void update(long long rt) {     tr[rt].sz = tr[tr[rt].l].sz + tr[tr[rt].r].sz + tr[rt].cnt;   }   void lturn(long long &rt) {     long long tmp = tr[rt].r;     tr[rt].r = tr[tmp].l;     tr[tmp].l = rt;     tr[tmp].sz = tr[rt].sz;     update(rt);     rt = tmp;   }   void rturn(long long &rt) {     long long tmp = tr[rt].l;     tr[rt].l = tr[tmp].r;     tr[tmp].r = rt;     tr[tmp].sz = tr[rt].sz;     update(rt);     rt = tmp;   }   void Insert(long long &rt, long long x) {     if (!rt) {       rt = ++tot;       tr[rt].sz = tr[rt].cnt = 1;       tr[rt].val = x, tr[rt].rnd = rand();       return;     }     tr[rt].sz++;     if (tr[rt].val == x)       tr[rt].cnt++;     else if (tr[rt].val < x) {       Insert(tr[rt].r, x);       if (tr[tr[rt].r].rnd < tr[rt].rnd) lturn(rt);     } else {       Insert(tr[rt].l, x);       if (tr[tr[rt].l].rnd < tr[rt].rnd) rturn(rt);     }   }   void Delete(long long &rt, long long x) {     if (!rt) return;     if (tr[rt].val == x) {       if (tr[rt].cnt > 1)         tr[rt].cnt--, tr[rt].sz--;       else {         if (tr[rt].l * tr[rt].r == 0)           rt = tr[rt].l + tr[rt].r;         else if (tr[tr[rt].l].rnd < tr[tr[rt].r].rnd)           rturn(rt), Delete(rt, x);         else           lturn(rt), Delete(rt, x);       }     } else if (tr[rt].val < x)       tr[rt].sz--, Delete(tr[rt].r, x);     else       tr[rt].sz--, Delete(tr[rt].l, x);   }   long long findnum(long long rt, long long x) {     if (!rt) return -1;     if (x <= tr[tr[rt].l].sz) return findnum(tr[rt].l, x);     x -= tr[tr[rt].l].sz;     if (x <= tr[rt].cnt) return tr[rt].val;     x -= tr[rt].cnt;     return findnum(tr[rt].r, x);   }   void doit() {     long long kind = 0;     for (long long _ = 1; _ <= q; _++) {       while (kind < m && up[kind] < qq[_].x) {         kind++;         Insert(rt, a[kind].id);       }       long long dis = qq[_].x - up[kind - 1];       dis = (dis - 1) % kind + 1;       ans[qq[_].id] = findnum(rt, dis);     }   }   signed main() {     read(n), read(m), read(q);     for (long long i = 1; i <= m; i++) a[i].id = i;     for (long long i = 1; i <= n; i++) {       long long x;       scanf( %d , &x);       a[x].cnt++;     }     sort(a + 1, a + m + 1);     for (long long i = 1; i <= m; i++) {       up[i] = (long long)i * (a[i + 1].cnt - a[i].cnt);       up[i] += up[i - 1];     }     for (long long _ = 1; _ <= q; _++) {       long long x;       scanf( %lld , &x);       x -= n;       qq[_] = (que){x, _};     }     sort(qq + 1, qq + q + 1);     doit();     for (long long i = 1; i <= q; i++) printf( %lld n , ans[i]);   }


#include <bits/stdc++.h>   #pragma GCC target( avx2 )   #pragma GCC optimization( O3 )   #pragma GCC optimization( unroll-loops )   using namespace std;   template <class T1, class T2>   ostream &operator<<(ostream &os, const pair<T1, T2> &p) {     os <<  {  << p.first <<  ,  << p.second <<  } ;     return os;   }   const int N = 3e5 + 5;   const int oo = 1e9 + 7;   const int LOGN = 30;   long long bigmod(long long a, long long p, long long m) {     long long res = 1;     long long x = a;     while (p) {       if (p & 1) {         res = (res * x) % m;       }       x = (x * x) % m;       p = p >> 1;     }     return res;   }   int basis[N][LOGN];   void insert_vec(int t, int x) {     for (int i = LOGN - 1; i >= 0; i--) basis[t][i] = basis[t - 1][i];     for (int i = LOGN - 1; i >= 0; i--) {       if ((x >> i) & 1) {         if (!basis[t][i]) {           basis[t][i] = x;           return;         } else {           x ^= basis[t][i];         }       }     }   }   int ans(int t, int x) {     int tot = t;     for (int i = LOGN - 1; i >= 0; i--) {       if (basis[t][i]) {         tot--;         if ((x >> i) & 1) x ^= basis[t][i];       } else {         if ((x >> i) & 1) return 0;       }     }     return bigmod(2, tot, oo);   }   int32_t main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n, q;     cin >> n >> q;     for (int i = 1; i <= n; i++) {       int x;       cin >> x;       insert_vec(i, x);     }     while (q--) {       int l, x;       cin >> l >> x;       cout << ans(l, x) <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const long long inf = 1LL << 61;   const long long mod = 1000000007;   const int maxn = 404;   bitset<maxn> cb[30][maxn];   bitset<maxn> ans[maxn];   bitset<maxn> shift(bitset<maxn> b, int len, int sh);   int main() {     std::ios::sync_with_stdio(false);     int i = 0, j = 0, k = 0;     int n, m, c, r;     scanf( %d%d , &n, &m);     getchar();     for (i = 0; i < n; i++) {       for (j = 0; j < m; j++) {         char ch = getchar();         cb[ch -  a ][i][j] = true;       }       getchar();     }     for (i = 0; i < n; i++) {       for (j = 0; j < m; j++) {         ans[i][j] = true;       }     }     scanf( %d%d , &r, &c);     getchar();     for (i = 0; i < r; i++) {       for (j = 0; j < c; j++) {         char ch = getchar();         if (ch ==  ? ) continue;         int shiftx = ((-i) % n + n) % n;         int shifty = j % m;         for (k = 0; k < n; k++) {           int nk = k + shiftx;           if (nk >= n) nk -= n;           ans[nk] &= shift(cb[ch -  a ][k], m, shifty);         }       }       getchar();     }     for (i = 0; i < n; i++) {       for (j = 0; j < m; j++) {         printf( %d , ans[i][j] ? 1 : 0);       }       puts(  );     }     return 0;   }   bitset<maxn> shift(bitset<maxn> b, int len, int sh) {     return (b >> sh) | (b << (len - sh));   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = (int)3e5 + 10;   struct node {     int nxt, to;   } edg[maxn * 2];   int head[maxn], num;   int f[maxn], n, a[maxn];   void add(int a, int b) {     edg[++num].to = b;     edg[num].nxt = head[a];     head[a] = num;   }   int k = 0;   void dfs(int root) {     if (head[root] == 0) {       f[root] = 1;       k++;       return;     }     if (a[root] == 1) f[root] = 1e7;     int t = head[root];     while (t != 0) {       dfs(edg[t].to);       if (a[root] == 1) {         f[root] = min(f[root], f[edg[t].to]);       } else {         f[root] += f[edg[t].to];       }       t = edg[t].nxt;     }   }   int main() {     ios::sync_with_stdio(false);     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i];     }     for (int i = 2; i <= n; i++) {       int fat;       cin >> fat;       add(fat, i);     }     dfs(1);     cout << k + 1 - f[1];     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, a, b, k, tt;   int tree1[800000], tree2[800000];   void updata1(int L, int R, int ro, int x, int v) {     if (x < L || x > R) return;     if (L == R && L == x) {       tree1[ro] = min(v + tree1[ro], b);       return;     }     int Mid = (L + R) / 2;     updata1(L, Mid, ro * 2, x, v);     updata1(Mid + 1, R, ro * 2 + 1, x, v);     tree1[ro] = tree1[ro * 2] + tree1[ro * 2 + 1];   }   void updata2(int L, int R, int ro, int x, int v) {     if (x < L || x > R) return;     if (L == R && L == x) {       tree2[ro] = min(v + tree2[ro], a);       return;     }     int Mid = (L + R) / 2;     updata2(L, Mid, ro * 2, x, v);     updata2(Mid + 1, R, ro * 2 + 1, x, v);     tree2[ro] = tree2[ro * 2] + tree2[ro * 2 + 1];   }   int quary1(int ro, int L, int R, int l, int r) {     if (r < L || l > R) return 0;     if (l <= L && R <= r) return tree1[ro];     int Mid = (L + R) / 2;     int x1 = quary1(ro * 2, L, Mid, l, r),         x2 = quary1(ro * 2 + 1, Mid + 1, R, l, r);     return x1 + x2;   }   int quary2(int ro, int L, int R, int l, int r) {     if (r < L || l > R) return 0;     if (l <= L && R <= r) return tree2[ro];     int Mid = (L + R) / 2;     int x1 = quary2(ro * 2, L, Mid, l, r),         x2 = quary2(ro * 2 + 1, Mid + 1, R, l, r);     return x1 + x2;   }   int main() {     scanf( %d%d%d%d%d , &n, &k, &a, &b, &tt);     for (int i = 1; i <= tt; i++) {       int a1, b1, c1;       scanf( %d , &a1);       if (a1 == 1) {         scanf( %d%d , &b1, &c1);         updata1(1, n, 1, b1, c1);         updata2(1, n, 1, b1, c1);       } else if (a1 == 2) {         scanf( %d , &b1);         printf( %d n , quary1(1, 1, n, 1, b1 - 1) + quary2(1, 1, n, b1 + k, n));       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, m, a, b, x, y, z, ans, g[3010 * 3010], h[3010][3010],       f[3010][3010];   deque<long long> q, zr;   int main() {     scanf( %lld%lld%lld%lld%lld%lld%lld%lld , &n, &m, &a, &b, g, &x, &y, &z);     for (int i = 1; i <= n * m; i++) g[i] = (g[i - 1] * x + y) % z;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) h[i][j] = g[(i - 1) * m + j - 1];     for (int i = 1; i <= n; i++) {       q = zr;       for (int j = 1; j <= m; j++) {         while (!q.empty() && h[i][q.back()] >= h[i][j]) q.pop_back();         while (!q.empty() && q.front() + b - 1 < j) q.pop_front();         q.push_back(j), f[i][j] = h[i][q.front()];       }     }     for (long long j = 1; j <= m; j++) {       while (!q.empty()) q.pop_front();       for (long long i = 1; i <= n; i++) {         while (!q.empty() && f[q.back()][j] >= f[i][j]) q.pop_back();         if (!q.empty() && q.front() + a - 1 < i) q.pop_front();         q.push_back(i);         if (i >= a && j >= b) ans += f[q.front()][j];       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double pie = 3.14159265358979323846;   int32_t main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     double d, h, v, e, t = 0;     cin >> d >> h >> v >> e;     if (v <= (pie * (d / 2) * (d / 2) * e)) {       cout <<  NO n ;     } else {       t = (pie * (d / 2) * (d / 2) * h) / (v - (pie * (d / 2) * (d / 2) * e));       if (t <= 10000) {         cout <<  YES n  << fixed << setprecision(15) << t <<   n ;       } else         cout <<  NO n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 1e5 + 35;   const int N = 2e5;   const long long mod = 1e7;   const double eps = 1e-6;   int a[MAX];   long long n;   long long ans;   pair<long long, long long> ch(long long x) {     long long x2 = n - x;     long long s = x;     s += (x2 * (x2 - 1)) / 2;     if (((s + 1) / 2) >= x) {       pair<long long, long long> k;       k.first = 1;       k.second = min(x * 2, s);       return k;     } else       return {0, 0};   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie();     cout.tie();     int t;     cin >> t;     while (t--) {       ans = 0;       cin >> n;       if (n == 1) {         cout <<  0 n ;         continue;       }       long long l = 0;       long long r = n - 1;       while (l <= r) {         long long mid = (l + r) / 2;         if (ch(mid).first) {           ans = max(ans, ch(mid).second);           l = mid + 1;         } else           r = mid - 1;       }       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     static int r, sign;     static char c;     r = 0, sign = 1;     do c = getchar();     while (c !=  -  && (c <  0  || c >  9 ));     if (c ==  - ) sign = -1, c = getchar();     while (c >=  0  && c <=  9 ) r = r * 10 + (int)(c -  0 ), c = getchar();     return sign * r;   }   template <typename T>   inline void print(T *a, int n) {     for (int i = 1; i < n; ++i) cout << a[i] <<    ;     cout << a[n] << endl;   }   struct inedge {     int a, b, w;     inline bool operator<(const inedge &x) const { return w < x.w; }   } ie[100000 + 1], p[100000 + 1];   struct edge {     int next, node;   } e[100000 << 1 | 1];   int head[100000 + 1], tot = 0;   inline void addedge(int a, int b) {     e[++tot].next = head[a];     head[a] = tot, e[tot].node = b;   }   int n, m, a[100000 + 1];   int f[100000 + 1], size[100000 + 1];   int find(int x) {     if (f[x] == x) return x;     int fa = f[x];     f[x] = find(fa);     return f[x];   }   void fusion(int a, int b) {     a = find(a), b = find(b);     f[a] = b, size[b] += size[a];   }   int main(int argc, char *argv[]) {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; ++i) scanf( %d , a + i);     for (int i = 1; i <= m; ++i) {       int x, y;       scanf( %d%d , &x, &y);       ie[i].a = x, ie[i].b = y, ie[i].w = min(a[x], a[y]);     }     sort(ie + 1, ie + m + 1);     for (int i = 1; i <= n; ++i) f[i] = i;     int cnt = 0;     for (int i = m; i > 0; --i)       if (find(ie[i].a) != find(ie[i].b)) {         f[find(ie[i].a)] = find(ie[i].b);         addedge(ie[i].a, ie[i].b);         addedge(ie[i].b, ie[i].a);         p[++cnt] = ie[i];       }     long long ans = 0LL;     for (int i = 1; i <= n; ++i) f[i] = i, size[i] = 1;     for (int i = 1; i <= cnt; ++i) {       ans += (long long)p[i].w * size[find(p[i].a)] * size[find(p[i].b)];       fusion(p[i].a, p[i].b);     }     cout << fixed << setprecision(10) << (double)ans * 2LL / n / (n - 1) << endl;     fclose(stdin);     fclose(stdout);     return 0;   }


#include <cstdio>   #include <cstdlib>   #include <cstring>   #include <cmath>   #include <ctime>   #include <iostream>   #include <algorithm>   #include <queue>   #include <map>   #include <set>   #include <vector>   #include <string>   #include <stack>   #include <numeric>   #include <cassert>      #define endl   n    #define sp          #define pb push_back   #define mp make_pair   #define ff first   #define ss second      using namespace std;      typedef long long ll;   typedef pair<int,int> pii;   typedef pair<ll,ll> pll;      const int maxn = 2e5+5;   set<pair<int,char>> adj[maxn];      int main(){              ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);cerr.tie(nullptr);       int n,m;cin>>n>>m;       set<pii> cift, samecift;       for(int q=0;q<m;q++){           char t;cin>>t;           if(t ==  + ){               int u,v;char c;cin>>u>>v>>c;               pair<int,char> p = {v,c};               adj[u].emplace(v,c);               auto it = adj[v].lower_bound({u,0});               if(it != adj[v].end() && it->ff == u){                   int setu = min(u,v);                   int setv = max(u,v);                   cift.emplace(setu,setv);                   if(it->ss == c){                       samecift.emplace(setu,setv);                   }               }           }           else if(t ==  - ){               int u,v;cin>>u>>v;               auto it = adj[u].lower_bound({v,0});               assert(it != adj[u].end());               adj[u].erase(it);               int setu = min(u,v);               int setv = max(u,v);               auto it2 = cift.find({setu,setv});               if(it2 != cift.end()){                   cift.erase(it2);                   it2 = samecift.find({setu,setv});                   if(it2 != samecift.end()){                       samecift.erase(it2);                   }               }           }           else{               int k;cin>>k;               if(k&1){                   if(cift.size()){                       cout <<  YES  << endl;                   }                   else                       cout <<  NO  << endl;               }               else{                   if(samecift.size()){                       cout <<  YES  << endl;                   }                   else{                       cout <<  NO  << endl;                   }               }                  }       }          }


#include <bits/stdc++.h>   using namespace std;   const int N = 4e5 + 10;   int rd() {     int x = 0, w = 1;     char ch = 0;     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) w = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + (ch ^ 48);       ch = getchar();     }     return x * w;   }   int to[N], nt[N], hd[N], tot = 1;   void adde(int x, int y) { ++tot, to[tot] = y, nt[tot] = hd[x], hd[x] = tot; }   char cc[N];   int n, ans, f[N], g[N], s[N * 50], ch[N * 50][2], rt[N], tz;   void inst(int o, int x) {     s[o] = x;     int l = 1, r = n;     while (l < r) {       int mid = (l + r) >> 1;       if (x <= mid)         o = ch[o][0] = ++tz, r = mid;       else         o = ch[o][1] = ++tz, l = mid + 1;       s[o] = x;     }   }   int merg(int o1, int o2) {     if (!o1 || !o2) return o1 + o2;     int o = ++tz;     s[o] = max(s[o1], s[o2]);     ch[o][0] = merg(ch[o1][0], ch[o2][0]);     ch[o][1] = merg(ch[o1][1], ch[o2][1]);     return o;   }   int quer(int o, int l, int r, int ll, int rr) {     if (!o || ll > rr) return s[0];     if (ll <= l && r <= rr) return s[o];     int an = s[0], mid = (l + r) >> 1;     if (ll <= mid) an = max(an, quer(ch[o][0], l, mid, ll, rr));     if (rr > mid) an = max(an, quer(ch[o][1], mid + 1, r, ll, rr));     return an;   }   int fa[N], tn[N][26], len[N], la = 1, tt = 1;   void extd(int xx, int i) {     int np = ++tt, p = la;     len[np] = len[p] + 1, inst(rt[np] = ++tz, i), la = np;     while (p && !tn[p][xx]) tn[p][xx] = np, p = fa[p];     if (!p)       fa[np] = 1;     else {       int q = tn[p][xx];       if (len[q] == len[p] + 1)         fa[np] = q;       else {         int nq = ++tt;         fa[nq] = fa[q], len[nq] = len[p] + 1,         memcpy(tn[nq], tn[q], sizeof(int) * 26);         fa[np] = fa[q] = nq;         while (p && tn[p][xx] == q) tn[p][xx] = nq, p = fa[p];       }     }   }   void dfs1(int x) {     for (int i = hd[x]; i; i = nt[i]) {       int y = to[i];       dfs1(y), rt[x] = merg(rt[x], rt[y]);     }   }   void dfs2(int x) {     if (x > 1) {       if (fa[x] == 1 ||           quer(rt[g[x]], 1, n, s[rt[x]] - len[x] + len[g[x]], s[rt[x]] - 1) > 0)         ++f[x], g[x] = x;     }     ans = max(ans, f[x]);     for (int i = hd[x]; i; i = nt[i]) {       int y = to[i];       f[y] = f[x], g[y] = g[x], dfs2(y);     }   }   int main() {     n = rd(), scanf( %s , cc + 1);     s[0] = -(1 << 25);     for (int i = 1; i <= n; ++i) extd(cc[i] -  a , i);     for (int i = 2; i <= tt; ++i) adde(fa[i], i);     dfs1(1);     dfs2(1);     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1 << 29;   int main() {     ios::sync_with_stdio(0);     int n;     cin >> n;     int a[n];     for (int i = 0; i < (n); i++) cin >> a[i];     int b[n];     for (int i = 0; i < (n); i++) cin >> b[i];     set<int> rem;     int top = 0;     for (int i = 0; i < (n); i++) {       int curr = 0;       if (rem.find(b[i]) != rem.end()) {         cout << curr <<    ;         continue;       }       while (top < n) {         if (a[top + curr] != b[i]) {           rem.insert(a[top + curr]);           ++curr;         } else {           rem.insert(a[top + curr]);           break;         }       }       top += curr + 1;       cout << curr + 1 <<    ;     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   int main() {     int a[5], maxx = -1, k;     for (int i = 0; i < 4; i++) {       scanf( %d , &a[i]);       if (maxx < a[i]) {         maxx = a[i];         k = i;       }     }     for (int i = 0; i < 4; i++) {       if (k == i) continue;       printf( %d  , maxx - a[i]);     }     printf(  n );   }


#include <bits/stdc++.h>   using namespace std;   int main()   {       int t;       cin>>t;       while(t--)       {           int x,y;           cin>>x>>y;                      int count =0;           while(x>0&&y>0)           {               x--;               y--;               count+=2;           }           if(x!=0||y!=0)           count =count+2*max(x,y)-1;           cout<<count<<  n ;       }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n;     while (scanf( %lld , &n) != EOF) {       long long tpn = n;       long long ninenum = 0;       long long tezheng;       while (tpn) {         tpn /= 10;         ninenum++;       }       ninenum--;       long long sum = 1;       while (ninenum) {         sum = sum * 10;         ninenum--;       }       long long fivesum = 5 * sum;       if (fivesum <= n) {         tezheng = fivesum;         sum = sum * 10;       } else {         tezheng = fivesum / 10;       }       long long ans = 0;       if (tezheng != 0) {         long long yunum = n % sum;         long long geshu = n / sum;         if (yunum <= tezheng - 1) {           ans = yunum * (geshu + 1) * (geshu) +                 (tezheng - 1 - yunum) * geshu * geshu;           ans += geshu * geshu;         } else {           if (yunum == sum - 1) {             ans +=                 (yunum - 1 - tezheng + 1) * (geshu + 1) * (geshu + 1) +                 (tezheng - 1 - (yunum - 1 - tezheng + 1)) * (geshu + 1) * (geshu);             ans += geshu * (geshu + 1);           } else {             ans += (yunum - tezheng + 1) * (geshu + 1) * (geshu + 1) +                    (tezheng - 1 - (yunum - tezheng + 1)) * (geshu + 1) * (geshu);             ans += geshu * geshu;           }         }       } else {         ans = n * (n - 1) / 2;       }       printf( %lld n , ans);     }   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   const long long INF = 1e18;   const long long MAX = 100100;   void pre() {}   void solve() {     long long n;     cin >> n;     vector<long long> p(n), c(n);     for (long long i = 0; i < n; ++i) cin >> p[i] >> c[i];     for (long long i = 0; i < n; ++i) {       if (c[i] > p[i]) {         cout <<  NO               <<   n ;         return;       }     }     for (long long i = 1; i < n; ++i) {       if (p[i] < p[i - 1]) {         cout <<  NO               <<   n ;         return;       }       if (c[i] < c[i - 1]) {         cout <<  NO               <<   n ;         return;       }       if ((p[i] - p[i - 1]) < (c[i] - c[i - 1])) {         cout <<  NO               <<   n ;         return;       }     }     cout <<  YES           <<   n ;   }   signed main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     pre();     long long t = 1;     cin >> t;     for (long long CASE = 1; CASE <= t; ++CASE) {       solve();     }     {};     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O2 )   #pragma GCC optimize( unroll-loops )   using namespace std;   long long power(long long a, long long b, long long md) {     return (!b ? 1                : (b & 1 ? a * power(a * a % md, b / 2, md) % md                         : power(a * a % md, b / 2, md) % md));   }   const int xn = 2e2 + 10;   const int xm = -20 + 10;   const int sq = 300;   const int inf = 1e9 + 10;   const long long INF = 1e18 + 10;   const int mod = 1e6 + 7;   const int base = 257;   const int SIG = 26;   struct matrix {     long long n, m, a[xn][xn];     matrix(int n1, int m1, long long x = -INF) {       n = n1;       m = m1;       for (int i = 0; i < n; i++)         for (int j = 0; j < m; j++) a[i][j] = x;     }     matrix operator*(const matrix &t) {       matrix r = matrix(n, t.m);       for (int i = 0; i < n; i++)         for (int j = 0; j < t.m; j++)           for (int k = 0; k < m; k++)             r.a[i][j] = max(r.a[i][j], a[i][k] + t.a[k][j]);       return r;     }     matrix operator=(const int &t) {       for (int i = 0; i < n; ++i)         for (int j = 0; j < m; ++j) a[i][j] = t;     }   };   matrix Pow(matrix a, long long b) {     matrix res = matrix(a.n, a.m);     for (int i = 0; i < a.n; i++) res.a[i][i] = 0;     for (; b; b = b >> 1) {       if (b & 1) res = res * a;       a = a * a;     }     return res;   }   int n, a[xn], F[xn], nxt[SIG][xn];   int ahoq[xn], ptr, ps[xn], par[xn];   long long l, ans;   string S;   vector<int> vec[xn], adj[xn];   void build_aho() {     int L = 0, R = 0;     for (int i = 0; i < SIG; ++i)       if (nxt[i][0]) ahoq[R++] = nxt[i][0];     while (L < R) {       int v = ahoq[L++];       adj[F[v]].push_back(v);       for (int i = 0; i < SIG; ++i) {         if (nxt[i][v])           F[nxt[i][v]] = nxt[i][F[v]], ahoq[R++] = nxt[i][v];         else           nxt[i][v] = nxt[i][F[v]];       }     }   }   void DFS(int v) {     vec[v].push_back(v);     for (int u : adj[v]) {       ps[u] += ps[v];       DFS(u);       for (int x : vec[u]) vec[v].push_back(x);     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     cin >> n >> l;     for (int i = 1; i <= n; ++i) cin >> a[i];     for (int i = 1; i <= n; ++i) {       cin >> S;       int v = 0;       for (int j = 0; j < int(S.size()); ++j) {         int c = S[j] -  a ;         if (!nxt[c][v]) nxt[c][v] = ++ptr;         par[nxt[c][v]] = v;         v = nxt[c][v];       }       ps[v] += a[i];     }     matrix m(ptr + 1, 1), c(ptr + 1, ptr + 1);     build_aho(), DFS(0);     for (int i = 0; i <= ptr; ++i)       for (int v : vec[par[i]]) c.a[i][v] = ps[i];     m.a[0][0] = 0;     m = Pow(c, l) * m;     for (int i = 0; i <= ptr; ++i) ans = max(ans, m.a[i][0]);     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) {     if (b == 0LL) return a;     return gcd(b, a % b);   }   long long bigmod(long long a, long long b, long long mod) {     if (b == 0LL) return 1LL;     long long sq = bigmod(a, b / 2LL, mod);     sq = (sq * sq) % mod;     if (b & 1LL) return (sq * (a % mod)) % mod;     return sq;   }   vector<int> primes;   vector<int> sieve(const int n) {     vector<int> primes(n + 1, 0);     primes[1] = 1;     for (int p = 2; p * p <= n; p++) {       if (!primes[p]) {         for (int i = p * p; i <= n; i += p) primes[i] = p;       }     }     for (int i = 2; i <= n; i++)       if (!primes[i]) primes[i] = i;     return primes;   }   map<int, int> getDivs(int x) {     map<int, int> divs;     while (x > 1) {       int div = primes[x];       int cnt = 0;       while (x % div == 0) {         x /= div;         cnt++;       }       divs[div] = cnt;     }     return divs;   }   void solve() {     int n;     cin >> n;     vector<int> a(n);     vector<int> cm(n + 1, 100000000);     for (auto &x : (a)) {       cin >> x;     }     for (int i = n - 1; i >= 0; i--) {       cm[i] = min(cm[i + 1], a[i]);     }     int ans = 0;     for (int i = 1; i < n; i++) {       if (cm[i] < a[i - 1]) ans++;     }     cout << ans << endl;   }   int main() {     int t = 1;     cin >> t;     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100 * 1000;   int n;   long long dp[2][N];   int c[N], a[N];   bool read() {     if (!(cin >> n)) return false;     for (int i = 0; i < int(n); ++i) {       cin >> a[i];       c[i] = a[i];     }     return true;   }   void upd(long long &a, long long b) {     if (a == -1) a = b;     a = min(a, b);   }   void solve() {     int t = 0;     sort(c, c + n);     memset(dp, -1, sizeof dp);     dp[t][0] = 0;     for (int i = 0; i < int(n); ++i) {       memset(dp[!t], -1, sizeof(dp[!t]));       long long mn = -1;       for (int j = 0; j < int(n); ++j) {         if (dp[t][j] != -1) upd(mn, dp[t][j]);         upd(dp[!t][j], mn + abs(a[i] - c[j]));       }       t = !t;     }     long long res = -1;     for (int i = 0; i < int(n); ++i)       if (dp[t][i] != -1) upd(res, dp[t][i]);     cout << res << endl;   }   int main() {     while (read()) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long dp[55][2];   int main() {     long long X, Y;     scanf( %lld %lld , &Y, &X);     dp[51][0] = 1;     for (int i = 50; i >= 0; i--) {       for (int flag = 0; flag <= 1; flag++) {         bool x = (X >> i) & 1, y = (Y >> i) & 1;         if (x)           dp[i][flag] += dp[i + 1][(flag + 1) / 2] * (flag != y) * 2;         else {           dp[i][flag] += dp[i + 1][(flag + 2) / 2] * (flag == y);           dp[i][flag] += dp[i + 1][0] * (flag == y);         }       }     }     if (!X) assert(dp[0][0] - (X == Y) * 2 == (!(Y & 1)));     printf( %lld n , dp[0][0] - (X == Y) * 2);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   constexpr T inf = numeric_limits<T>::max() / 2;   long long calc(long long border, const vector<int> &h,                  const vector<long long> &acc, const vector<long long> &acc_rev,                  int a, int r, int m) {     int n = h.size();     if (border > h[n - 1] || border < h[0]) return inf<long long>;     int pos = -1;     for (int i = 0; (i) < (int)(n); (i)++) {       if (h[i] <= border && (i == n - 1 || h[i + 1] > border)) {         pos = i;         break;       }     }     assert(pos != -1);     long long x = border * (pos + 1) - acc[pos];     long long y = (pos == n - 1 ? 0 : acc_rev[pos + 1] - border * (n - pos - 1));     if (y >= x) {       return (long long)(y - x) * r + (long long)x * m;     } else {       return (long long)(x - y) * a + (long long)y * m;     }   }   int main() {     int n, a, r, m;     scanf( %d%d%d%d , &n, &a, &r, &m);     m = min(m, a + r);     vector<int> h(n);     for (int i = 0; (i) < (int)(n); (i)++) {       scanf( %d , &h[i]);     }     sort(h.begin(), h.end());     vector<long long> acc(n), acc_rev(n);     acc[0] = h[0];     for (int i = 0; (i) < (int)(n); (i)++)       if (i) acc[i] = acc[i - 1] + h[i];     acc_rev[n - 1] = h[n - 1];     for (int i = n - 2; i >= 0; i--) acc_rev[i] = acc_rev[i + 1] + h[i];     long long lb = h[0], ub = h[n - 1] + 1;     while (ub - lb > 3) {       long long ml = (2 * lb + ub) / 3;       long long mr = (lb + 2 * ub) / 3;       long long cl = calc(ml, h, acc, acc_rev, a, r, m);       long long cr = calc(mr, h, acc, acc_rev, a, r, m);       if (cl < cr) {         ub = mr;       } else {         lb = ml;       }     }     long long ans = inf<long long>;     for (int p = lb - 3; p <= lb + 10; p++) {       ans = min(ans, calc(p, h, acc, acc_rev, a, r, m));     }     printf( %lld n , ans);     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     long long w, m;     cin >> w >> m;     vector<int> f;     while (m) {       f.push_back(m % w);       m /= w;     }     f.push_back(0);     f.push_back(0);     reverse(f.begin(), f.end());     for (int i = f.size() - 1; i >= 0; i--) {       if (i > 1) f[i - 1] += f[i] / w;       f[i] %= w;       if (f[i] == 0) continue;       if (f[i] == 1) continue;       if (f[i] == w - 1) {         f[i - 1]++;         continue;       }       cout <<  NO ;       return 0;     }     cout <<  YES ;   }


#include <bits/stdc++.h>   using namespace std;   int n, a[211111];   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];     }     long long l = 0;     long long r = 0;     long long suml = 0;     long long sumr = 0;     for (int i = 0; i < n; i++) {       if (a[i] == 1) {         r++;       }       if (a[i] == 0) {         suml += r;       }     }     for (int i = n - 1; i >= 0; i--) {       if (a[i] == 0) {         l++;       }       if (a[i] == 1) {         sumr += l;       }     }     cout << min(sumr, suml);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 6e3;   const int M = 2 * 5e3 + 2;   int n, m;   int G[N], H[N];   int q[N], qf, qb;   int dG[N][N], bG[N][3], szG[N];   int dH[N][N], bH[N][3], szH[N];   int ansv[4], aux[6], as;   int to[M], nx[M], es;   void calculate(int* ad, int d[][N], int b[][3], int sz[N]) {     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) d[i][j] = n << 1;       d[i][n] = -N;       d[i][i] = 0;       qf = qb = 0;       q[qb++] = i;       while (qb - qf > 0) {         int j = q[qf++];         for (int e = ad[j]; e; e = nx[e])           if (d[i][to[e]] > d[i][j] + 1) {             d[i][to[e]] = d[i][j] + 1;             q[qb++] = to[e];           }       }       int k = 0;       for (int j = qf - 1; j && k < 3; --j) b[i][k++] = q[j];       sz[i] = k;     }   }   int main() {     scanf(  %d%d , &n, &m);     for (int i = 0; i < m; i++) {       int j, k;       scanf(  %d%d , &j, &k);       --j;       --k;       dG[j][k] = 1;     }     es = 1;     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++)         if (dG[i][j]) {           to[es] = j;           nx[es] = G[i];           G[i] = es++;           to[es] = i;           nx[es] = H[j];           H[j] = es++;         }     calculate(G, dG, bG, szG);     calculate(H, dH, bH, szH);     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++) {         if (dG[i][j] == (n << 1)) dG[i][j] = -N;         if (dH[i][j] == (n << 1)) dH[i][j] = -N;       }     int ans = 0;     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++)         if (i != j) {           for (int _i = 0; _i < szH[i]; _i++)             for (int _j = 0; _j < szG[j]; _j++) {               int k = bH[i][_i], l = bG[j][_j];               if (k == l || k == j || i == l) continue;               if (dH[i][k] + dG[i][j] + dG[j][l] > ans) {                 ans = dH[i][k] + dG[i][j] + dG[j][l];                 ansv[0] = k, ansv[1] = i, ansv[2] = j, ansv[3] = l;               }             }         }     for (int i = 0; i < 4; i++) printf( %d%c , 1 + ansv[i],    n [i == 3]);   }


#include <bits/stdc++.h>   using namespace std;   long long n;   pair<long long, long long> loc[2001];   long long cp[2001];   long long cw[2001];   pair<long long, pair<long long, long long> > road[4000001];   long long ct = 0;   long long val[2001];   long long ans = 0;   long long ansleft;   long long ansr = 0;   bool cs[4000001];   struct node {     long long r, f;   } opt[100001];   long long fd(long long x) {     if (x != opt[x].f) opt[x].f = fd(opt[x].f);     return opt[x].f;   }   void mdf(long long x, long long y) {     x = fd(x), y = fd(y);     if (x == y) return;     if (opt[x].r < opt[y].r)       opt[x].f = y, opt[y].r += opt[x].r;     else       opt[y].f = x, opt[x].r += opt[y].r;   }   long long dis(long long x, long long y) {     return abs(loc[x].first - loc[y].first) + abs(loc[x].second - loc[y].second);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long i, j;     for (long long i = 1; i <= 100000; i++) opt[i].f = i, opt[i].r = 1;     cin >> n, ansleft = n;     for (i = 1; i <= n; i++) cin >> loc[i].first >> loc[i].second;     for (i = 1; i <= n; i++) cin >> cp[i];     for (i = 1; i <= n; i++) cin >> cw[i];     for (i = 1; i <= n; i++) val[i] = cp[i];     for (i = 1; i <= n; i++) ans += cp[i];     for (i = 1; i <= n; i++)       for (j = i + 1; j <= n; j++)         road[++ct] = pair<long long, pair<long long, long long> >(             dis(i, j) * (cw[i] + cw[j]), pair<long long, long long>(i, j));     sort(road + 1, road + ct + 1);     for (i = 1; i <= ct; i++) {       pair<long long, pair<long long, long long> > f = road[i];       long long aa = fd(f.second.first), bb = fd(f.second.second);       if (aa != bb && f.first < max(val[aa], val[bb])) {         mdf(aa, bb);         long long father = fd(aa);         ans -= max(val[aa], val[bb]) - f.first;         val[father] = min(val[aa], val[bb]);         ansleft--, ansr++;         cs[i] = true;       }     }     cout << ans << endl;     cout << ansleft << endl;     for (i = 1; i <= n; i++) {       if (cp[i] == val[fd(i)]) cout << i <<    , val[fd(i)] = -1;     }     cout << endl;     cout << ansr << endl;     for (i = 1; i <= ct; i++)       if (cs[i])         cout << road[i].second.first <<     << road[i].second.second << endl;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC target( avx2 )   #pragma GCC optimize( unroll-loops )   #pragma GCC optimize( Ofast )   constexpr long long INF = 200000000000000001LL;   constexpr int INF32 = 2100000001;   size_t seed42 = std::chrono::system_clock::now().time_since_epoch().count();   std::mt19937 rng(seed42);   std::uniform_int_distribution<int> unidistrib;   int randint() { return unidistrib(rng); }   using namespace std;   unsigned long long modulo = 998244353;   int modulo32 = 998244353;   unsigned long long poww(unsigned long long x, unsigned long long n) {     if (n == 0) return 1;     unsigned long long answ = poww(x, n / 2);     answ = (answ * answ) % modulo;     if (n % 2) answ = (answ * x) % modulo;     return answ;   }   pair<int, int> operator+(const pair<int, int>& lhs, pair<int, int>& rhs) {     return {lhs.first + rhs.first, lhs.second + rhs.second};   }   template <class T>   ostream& operator<<(ostream& lhs, pair<T, T>& rhs) {     return (lhs << rhs.first <<  :  << rhs.second);   }   struct Node {     Node(int p, int a, int c) : p(p), a(a), c(c), p2(1, p) {}     int p;     int a;     int c;     vector<int> p2;   };   int main() {     ios::sync_with_stdio(false);     std::cin.tie(0);     int n, m, t;     cin >> n >> m;     string s;     cin >> s;     map<string, vector<int>> dp;     vector<string> ss = { abc ,  acb ,  bac ,  bca ,  cab ,  cba };     for (auto mask : ss) {       dp[mask] = vector<int>(n);       for (int i = 0; i < n; ++i) {         dp[mask][i] = (i > 0 ? dp[mask][i - 1] : 0) + (s[i] != mask[i % 3]);       }     }     while (m--) {       int l, r;       cin >> l >> r;       --r;       --l;       int minn = INF32;       for (auto mask : ss) {         minn = min(minn, dp[mask][r] - (l > 0 ? dp[mask][l - 1] : 0));       }       cout << minn << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int dx[] = {0, 1, 0, -1};   int dy[] = {1, 0, -1, 0};   int dp[1005][1005];   bool vis[1005][1005];   int sx, sy, x, y;   vector<string> v;   bool valid(int xx, int yy) {     if (xx >= 0 && yy >= 0 && xx < x && yy < y && v[xx][yy] !=  * ) return 1;     return 0;   }   int bfs() {     int wx, wy, ans = 0;     vector<pair<int, int> > vaa;     queue<pair<int, int> > q;     q.push(make_pair(sx, sy));     vis[sx][sy] = 1;     while (!q.empty()) {       sx = q.front().first;       sy = q.front().second;       vaa.push_back(make_pair(sx, sy));       q.pop();       for (int i = 0; i < 4; i++) {         wx = sx + dx[i];         wy = sy + dy[i];         if (!valid(wx, wy)) ans++;         if (valid(wx, wy) && !vis[wx][wy]) {           vis[wx][wy] = 1;           q.push(pair<int, int>(wx, wy));         }       }     }     for (int i = 0; i < vaa.size(); i++) dp[vaa[i].first][vaa[i].second] = ans;     return ans;   }   int main() {     memset(dp, -1, sizeof(dp));     for (int i = 0; i < 1005; i++)       for (int j = 0; j < 1005; j++) vis[i][j] = 0;     int t;     string s;     cin >> x >> y >> t;     for (int i = 0; i < x; i++) {       cin >> s;       v.push_back(s);     }     while (t--) {       cin >> sx >> sy;       sx--;       sy--;       if (dp[sx][sy] != -1)         printf( %d n , dp[sx][sy]);       else         printf( %d n , bfs());     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100001;   int h, t;   set<int> G[N];   vector<int> g[N];   bool check(int gr, int ji) {     int sw = 0;     int com = 0;     if (((int)g[gr].size()) > ((int)g[ji].size())) swap(gr, ji), sw = 1;     for (int i = 0; i < ((int)g[gr].size()); i++) com += G[ji].count(g[gr][i]);     if (sw) swap(gr, ji);     int l = ((int)g[gr].size()) - 1 - com;     int r = ((int)g[ji].size()) - 1 - com;     if (h + t > l + r + com || h > l + com || t > r + com) return 0;     vector<int> f, m, s;     for (int i = 0; i < ((int)g[gr].size()); i++) {       int to = g[gr][i];       if (to == ji) continue;       if (!G[ji].count(to))         f.push_back(to);       else         m.push_back(to);     }     for (int i = 0; i < ((int)g[ji].size()); i++) {       int to = g[ji][i];       if (to == gr) continue;       if (!G[gr].count(g[ji][i])) s.push_back(to);     }     int cur = 0;     while (((int)f.size()) < h) f.push_back(m[cur++]);     while (((int)s.size()) < t) s.push_back(m[cur++]);     puts( YES );     printf( %d %d n , gr + 1, ji + 1);     for (int i = 0; i < h; i++) printf( %d  , f[i] + 1);     printf(  n );     for (int i = 0; i < t; i++) printf( %d  , s[i] + 1);     printf(  n );     return 1;   }   int main() {     int n, m;     scanf( %d %d %d %d , &n, &m, &h, &t);     for (int i = 0; i < m; i++) {       int s, e;       scanf( %d %d , &s, &e);       --s;       --e;       g[s].push_back(e);       g[e].push_back(s);       G[s].insert(e);       G[e].insert(s);     }     for (int i = 0; i < n; i++) {       if (((int)g[i].size()) < h) continue;       for (int j = 0; j < ((int)g[i].size()); j++) {         int ji = g[i][j];         if (((int)g[ji].size()) < t) continue;         if (check(i, ji)) return 0;       }     }     puts( NO );     return 0;   }


#include <bits/stdc++.h>   #pragma warning(disable : 4996)   using namespace std;   using ld = long double;   template <class T>   using Table = vector<vector<T>>;   const ld eps = 1e-9;   template <class S, class T>   ostream &operator<<(ostream &os, const pair<S, T> v) {     os <<  (   << v.first <<  ,   << v.second <<  ) ;     return os;   }   template <class T>   ostream &operator<<(ostream &os, const vector<T> &v) {     for (int i = 0; i < v.size(); i++) {       if (i > 0) {         os <<    ;       }       os << v[i];     }     return os;   }   template <class T>   ostream &operator<<(ostream &os, const vector<vector<T>> &v) {     for (int i = 0; i < v.size(); i++) {       if (i > 0) {         os << endl;       }       os << v[i];     }     return os;   }   template <class T>   ostream &operator<<(ostream &os, const vector<set<T>> &v) {     for (int i = 0; i < v.size(); i++) {       if (i > 0) {         os << endl;       }       os << v[i];     }     return os;   }   template <class T>   ostream &operator<<(ostream &os, const map<T, T> &v) {     int i = 0;     for (auto it : v) {       if (i > 0) {         os <<    ;       }       os << it.first <<     << it.second;       i++;     }     return os;   }   using ll = long long;   const int mod = 998244353;   struct Mod {    public:     int num;     Mod() : Mod(0) { ; }     Mod(long long int n) : num((n % mod + mod) % mod) {       static_assert(mod < INT_MAX / 2,                      mod is too big, please make num  long long int  from  int  );     }     Mod(int n) : Mod(static_cast<long long int>(n)) { ; }     operator int() { return num; }   };   Mod operator+(const Mod a, const Mod b) { return Mod((a.num + b.num) % mod); }   Mod operator+(const long long int a, const Mod b) { return Mod(a) + b; }   Mod operator+(const Mod a, const long long int b) { return b + a; }   Mod operator++(Mod &a) { return a + Mod(1); }   Mod operator-(const Mod a, const Mod b) {     return Mod((mod + a.num - b.num) % mod);   }   Mod operator-(const long long int a, const Mod b) { return Mod(a) - b; }   Mod operator--(Mod &a) { return a - Mod(1); }   Mod operator*(const Mod a, const Mod b) {     return Mod(((long long)a.num * b.num) % mod);   }   Mod operator*(const long long int a, const Mod b) { return Mod(a) * b; }   Mod operator*(const Mod a, const long long int b) { return Mod(b) * a; }   Mod operator*(const Mod a, const int b) { return Mod(b) * a; }   Mod operator+=(Mod &a, const Mod b) { return a = a + b; }   Mod operator+=(long long int &a, const Mod b) { return a = a + b; }   Mod operator-=(Mod &a, const Mod b) { return a = a - b; }   Mod operator-=(long long int &a, const Mod b) { return a = a - b; }   Mod operator*=(Mod &a, const Mod b) { return a = a * b; }   Mod operator*=(long long int &a, const Mod b) { return a = a * b; }   Mod operator*=(Mod &a, const long long int &b) { return a = a * b; }   Mod operator^(const Mod a, const int n) {     if (n == 0) return Mod(1);     Mod res = (a * a) ^ (n / 2);     if (n % 2) res = res * a;     return res;   }   Mod mod_pow(const Mod a, const long long n) {     if (n == 0) return Mod(1);     Mod res = mod_pow((a * a), (n / 2));     if (n % 2) res = res * a;     return res;   }   Mod inv(const Mod a) { return a ^ (mod - 2); }   Mod operator/(const Mod a, const Mod b) {     assert(b.num != 0);     return a * inv(b);   }   Mod operator/(const long long int a, const Mod b) { return Mod(a) / b; }   Mod operator/=(Mod &a, const Mod b) { return a = a / b; }   Mod fact[1024000], factinv[1024000];   void init(const int amax = 1024000) {     fact[0] = Mod(1);     factinv[0] = 1;     for (int i = 0; i < amax - 1; ++i) {       fact[i + 1] = fact[i] * Mod(i + 1);       factinv[i + 1] = factinv[i] / Mod(i + 1);     }   }   Mod comb(const int a, const int b) {     return fact[a] * factinv[b] * factinv[a - b];   }   using Value = pair<Mod, Mod>;   const Value ini = make_pair(Mod(1), Mod(0));   Value connect(Value al, const Value ar) {     return make_pair(al.first * ar.first, al.second * ar.first + ar.second);   }   Value dat[800001];   struct segtree {     int N;     segtree() {}     segtree(int n) {       N = 1;       while (N < n) N *= 2;       for (int x = 0; x < N; ++x) {         { dat[x + N - 1] = ini; }       }       for (int x = N - 2; x >= 0; --x) {         dat[x] = connect(dat[x * 2 + 1], dat[x * 2 + 2]);       }     }     void update(int k, const Value &a) {       k += N - 1;       dat[k] = a;       while (k > 0) {         k = (k - 1) >> 1;         dat[k] = connect(dat[k * 2 + 1], dat[k * 2 + 2]);       }     }     Value query(int a, int b) { return query(a, b, 0, 0, N); }     Value query(int a, int b, int k, int l, int r) {       if (r <= a or b <= l) return ini;       if (a <= l and r <= b) return dat[k];       const int m = (l + r) / 2;       return connect(query(a, b, k * 2 + 1, l, m), query(a, b, k * 2 + 2, m, r));     }   };   pair<Mod, Mod> dp[2010][2010];   int flag[2010][2010];   string st;   pair<Mod, Mod> solve(int l, int r) {     if (flag[l][r]) {       return dp[l][r];     }     flag[l][r] = true;     if (l == r) {       return dp[l][r] = make_pair(Mod(st[l] ==  ?  ? 2 : 1), Mod(0));     } else if (l - 1 == r) {       return dp[l][r] = make_pair(Mod(1), Mod(0));     }     if (st[l] ==  ( ) {       if (st[r] ==  ( ) {         dp[l][r] = solve(l, r - 1);       } else if (st[r] ==  ? ) {         auto ap = solve(l + 1, r - 1);         auto bp = solve(l, r - 1);         dp[l][r] =             make_pair(ap.first + bp.first, ap.second + bp.second + ap.first);       } else {         auto ap = solve(l + 1, r - 1);         dp[l][r] = make_pair(ap.first, ap.second + ap.first);       }     } else if (st[l] ==  ) ) {       dp[l][r] = solve(l + 1, r);     } else {       if (st[r] ==  ( ) {         dp[l][r] = solve(l, r - 1);       } else if (st[r] ==  ? ) {         auto ap = solve(l + 1, r - 1);         auto bp = solve(l, r - 1);         auto cp = solve(l + 1, r);         auto ep = solve(l + 1, r - 1);         ap.second += ap.first;         dp[l][r].first += ap.first + bp.first + cp.first - ep.first;         dp[l][r].second += ap.second + bp.second + cp.second - ep.second;       } else {         auto ap = solve(l + 1, r - 1);         ap.second += ap.first;         auto bp = solve(l + 1, r);         dp[l][r] = make_pair(ap.first + bp.first, ap.second + bp.second);       }     }     return dp[l][r];   }   int main() {     ios::sync_with_stdio(false);     cin >> st;     auto answer = solve(0, int(st.size()) - 1);     cout << answer.second << endl;     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:66777216 )   using namespace std;   const int N = 1e6 + 7;   int d[1024], k, ver[1024], ans[1024], num[1024];   map<pair<string, int>, int> M;   map<string, bool> was;   vector<vector<int> > v(1024);   string name[1024];   bool comp(int a, int b) {     if (name[a] < name[b]) {       return true;     }     if (name[a] > name[b]) {       return false;     }     if (ver[a] > ver[b]) {       return true;     }     return false;   }   void calc() {     for (int i = 1; i < k; i++) {       d[i] = -1;     }     int l = 0, r = 1;     vector<int> p;     was[name[0]] = 1;     for (int i = 0; i < k; i++) {       p.clear();       for (int j = 0; j < k; j++) {         if (d[j] == i) {           for (int g = 0; g < v[j].size(); g++) {             int to = v[j][g];             if (!was[name[to]] && num[to] == 0) {               p.push_back(to);               num[to] = 1;             }           }         }       }       sort(p.begin(), p.end(), comp);       for (int j = 0; j < p.size(); j++) {         int to = p[j];         if (!was[name[to]]) {           was[name[to]] = 1;           ans[to] = 1;           d[to] = i + 1;         }       }     }     set<pair<string, int> > S;     for (int i = 0; i < k; i++) {       if (ans[i]) {         S.insert({name[i], ver[i]});       }     }     cout << S.size() << endl;     while (S.size()) {       cout << S.begin()->first <<     << S.begin()->second << endl;       S.erase(S.begin());     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     string s, ss;     int c, m, cc;     for (int i = 0; i < n; i++) {       cin >> s >> c;       if (M[{s, c}] == 0) {         name[k] = s;         ver[k] = c;         M[{s, c}] = k++;       }       cin >> m;       for (int j = 0; j < m; j++) {         cin >> ss >> cc;         if (M[{ss, cc}] == 0) {           name[k] = ss;           ver[k] = cc;           M[{ss, cc}] = k++;         }         v[M[{s, c}]].push_back(M[{ss, cc}]);       }     }     calc();     cin >> n;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char s[2002000], t[2002000];   int n;   int a = 0, b = 0, c = 0, d = 0;   int main() {     cin >> n >> s >> t;     for (int i = 0; i < 2 * n; i++) {       if (s[i] ==  1  && t[i] ==  1 )         a++;       else if (s[i] ==  1 )         b++;       else if (t[i] ==  1 )         c++;       else         d++;     }     int ans1 = 0, ans2 = 0;     int m = 2 * n;     while (m) {       if (a)         ans1 += 1, a--;       else if (b)         ans1 += 1, b--;       else if (c)         c--;       else         d--;       if (a)         ans2++, a--;       else if (c)         ans2++, c--;       else if (b)         b--;       else         d--;       m -= 2;     }     if (ans1 > ans2)       puts( First );     else if (ans1 < ans2)       puts( Second );     else       puts( Draw );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool visited[300000];   long long int parent[300000];   void initialise() {     for (long long int i = 0; i < 300000; i++) {       visited[i] = false;       parent[i] = i;     }   }   pair<long long int, long long int> dfs(       vector<pair<long long int, long long int>> adj[], long long int A[],       long long int v, long long int i) {     visited[i] = true;     pair<long long int, long long int> r, s;     long long int j, k = adj[i].size();     long long int d = 0, f = 0;     r.first = A[i];     for (j = 0; j < k; j++) {       if (!visited[adj[i][j].first]) {         s = dfs(adj, A, v, adj[i][j].first);         r.first = max(r.first, s.first);         r.first = max(r.first, d + s.second + adj[i][j].second + A[i]);         d = max(d, s.second + adj[i][j].second);       }     }     r.second = d + A[i];     return r;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int u, v, x, y, a, b, i, k, l, p, n, m, w, maxi = 0, ans;     pair<long long int, long long int> j;     cin >> v;     vector<pair<long long int, long long int>> adj[v];     long long int A[v];     initialise();     for (i = 0; i < v; i++) {       cin >> A[i];     }     for (i = 0; i < v - 1; i++) {       cin >> x >> y >> w;       x--;       y--;       adj[x].push_back(make_pair(y, -w));       adj[y].push_back(make_pair(x, -w));     }     j = dfs(adj, A, v, 0);     cout << j.first;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2010;   struct P {     long long x, y;     int id;     bool operator<(P B) const {       if (y != B.y) return y < B.y;       return x < B.x;     }   } p[N], op;   long long cross(P A, P B, P C) {     return (A.x - B.x) * (C.y - B.y) - (C.x - B.x) * (A.y - B.y);   }   bool cmp(P A, P B) { return cross(A, op, B) < 0; }   char a[N];   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %lld%lld , &p[i].x, &p[i].y);       p[i].id = i;     }     scanf( %s , a + 1);     sort(p + 1, p + n + 1);     op = p[1];     for (int i = 2; i < n; i++) {       sort(p + i, p + n + 1, cmp);       if (a[i - 1] ==  L ) swap(p[i], p[n]);       op = p[i];     }     for (int i = 1; i <= n; i++) {       printf( %d  , p[i].id);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   void printVector(std::vector<std::vector<T>> const &matrix) {     for (std::vector<T> row : matrix) {       for (T val : row) {         std::cout << val;       }       std::cout <<   n ;     }   }   static void solve() {     int n;     cin >> n;     char D =  D ;     char star =  * ;     std::vector<std::vector<char>> matrix(n, std::vector<char>(n, star));     int mid = n / 2;     int from = mid;     int to = mid;     for (int i = 0; i < n; i++) {       for (int j = from; j <= to; j++) {         matrix[i][j] = D;       }       if (i >= mid) {         from++;         to--;       } else {         from--;         to++;       }     }     printVector(matrix);   }   int main() {     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     printf( YES n );     int n, a, b, c, d;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d%d%d%d , &a, &b, &c, &d);       if (!(a % 2) && !(b % 2))         printf( 3 n );       else if (!(a % 2) && (b % 2))         printf( 4 n );       else if ((a % 2) && !(b % 2))         printf( 2 n );       else         printf( 1 n );     }     return 0;   }


#include <bits/stdc++.h>   int power(int x, int y) {     int res = 1;     x = x % 1000000007;     while (y > 0) {       if (y & 1) res = (res * x) % 1000000007;       y = y >> 1;       x = (x * x) % 1000000007;     }     return res;   }   int ncr(int n, int r) {     int res = 1;     if (r > n - r) r = n - r;     for (int i = 0; i < r; i++) {       res *= (n - i);       res /= (i + 1);     }     return res;   }   int gcd(int a, int b) {     if (a == 0) return b;     return gcd(b % a, a);   }   int lcm(int a, int b) { return (a / gcd(a, b) * b); }   int max(int a, int b) {     int ans = a > b ? a : b;     return ans;   }   using namespace std;   int main() {     unsigned long long int n;     cin >> n;     unsigned long long int a[n];     for (int i = 0; i < n; ++i) {       cin >> a[i];     }     for (int i = 1; i < n - 1; ++i) {       if (a[i] < a[i - 1] && a[i] < a[i + 1]) {         cout <<  NO ;         return 0;       }     }     cout <<  YES ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-6;   long long sum[200005];   long long sum2[200005];   long long a[200005];   int n;   int sgn(double x) {     if (fabs(x) < eps) return 0;     return x > 0 ? 1 : -1;   }   struct point {     long long x, y;     point(){};     point(long long x, long long y) : x(x), y(y){};   };   long long dot(point A, point B) { return A.x * B.x + A.y * B.y; }   double getlv(point A, point B) {     return 1.0 * (B.y - A.y) / (1.0 * (B.x - A.x));   }   point stk[200005];   void init() {     sum[0] = 0;     sum2[0] = 0;     for (int i = 1; i <= n; i++) {       sum[i] = sum[i - 1] + a[i];       sum2[i] = sum2[i - 1] + a[i] * i;     }   }   void Compute() {     int top = 0;     long long ans = 0;     for (int i = 1; i <= n; i++) {       point temp = point(i - 1, (i - 1) * sum[i - 1] - sum2[i - 1]);       while (top > 1 &&              sgn(getlv(stk[top], temp) - getlv(stk[top - 1], stk[top])) > 0)         top--;       stk[++top] = temp;       int l = 1;       int r = top;       point a = point(-sum[i], 1);       while (l < r) {         int m1 = l + (r - l) / 3;         int m2 = r - (r - l) / 3;         if (dot(a, stk[m1]) < dot(a, stk[m2]))           l = m1 + 1;         else           r = m2 - 1;       }       ans = max(ans, sum2[i] + dot(a, stk[l]));     }     printf( %I64d n , ans);   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %I64d , &a[i]);     init();     Compute();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string a;     int b;     cin >> b >> a;     for (int i = 2; i <= b; i++) {       if (b % i == 0) {         reverse(a.begin(), a.begin() + i);       }     }     cout << a;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 300100;   int arr[N];   #pragma warning(disable : 6031)   #pragma warning(disable : 4996)   int t, n;   bool c1[N], c2[N];   int main() {     scanf( %d , &t);     while (t--) {       scanf( %d , &n);       bool f1 = 1, f2 = 1;       bool f3 = 1;       for (int i = 1; i <= n; i++) scanf( %d , arr + i);       memset(c1, 0, sizeof c1);       memset(c2, 0, sizeof c2);       c1[1] = 1;       for (int i = 2; i <= n; i++) {         if (c1[i - 1] && arr[i] >= i - 1) {           c1[i] = 1;         } else {           break;         }       }       c2[n] = 1;       for (int i = n - 1; i >= 1; i--) {         if (c2[i + 1] && arr[i] >= n - i) {           c2[i] = 1;         } else           break;       }       f1 = c1[n];       f2 = c2[1];       f3 = 0;       for (int i = 1; i <= n; i++) {         if (c1[i] && c2[i]) {           f3 = 1;         }       }       if (f1 || f2 || f3)         puts( Yes );       else         puts( No );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using vi = vector<int>;   using pii = pair<int, int>;   using pll = pair<ll, ll>;   template <typename T>   using vec = vector<T>;   template <typename T>   using Prior = priority_queue<T>;   template <typename T>   using prior = priority_queue<T, vector<T>, greater<T>>;   const int INF = 1e9;   const int nINF = -1e9;   const ll llINF = 4 * 1e18;   const int MOD = 1e9 + 7;   ll& pmod(ll& a, ll b) {     a = (a + b) % MOD;     return a;   }   ll& pmod(ll& a, ll b, ll c) {     a = (a + b) % c;     return a;   }   ll& mmod(ll& a, ll b) {     a = (a - b + MOD) % MOD;     return a;   }   ll& mmod(ll& a, ll b, ll c) {     a = (a - b + c) % c;     return a;   }   ll& tmod(ll& a, ll b) {     a = (a * b) % MOD;     return a;   }   ll mul(ll a, ll b) { return (a * b) % MOD; }   ll mul(ll a, ll b, ll c) { return (a * b) % c; }   ll POW(ll a, ll b) {     ll res = 1;     do {       if (b % 2) tmod(res, a);       tmod(a, a);     } while (b >>= 1);     return res;   }   ll FAC(ll a) {     ll res = 1;     for (int i = 1; i <= a; i++) tmod(res, i);     return res;   }   template <typename T1, typename T2>   ostream& operator<<(ostream& out, pair<T1, T2> a) {     cout << a.first <<     << a.second;     return out;   }   int main() {     ios_base::sync_with_stdio(false), cin.tie(0);     int n, d, t;     cin >> n >> d >> t;     if ((d == 1 and n != 2) or t < (d + 1) / 2)       cout << -1;     else {       int tmp = 1, count = 2;       for (int i = 0; i < t; i++) {         cout << tmp <<     << count <<   n ;         tmp = count;         count++;       }       tmp = 1;       for (int i = 0; i < d - t; i++) {         cout << tmp <<     << count <<   n ;         tmp = count;         count++;       }       for (; count <= n; count++)         cout << (t == d ? 2 : 1) <<     << count <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int INF = INT_MAX;   const long long INFL = LLONG_MAX;   const long double pi = acos(-1);   const int MOD = 1e9 + 7;   int ans;   int N;   inline long long mod(long long a) {     a %= MOD;     a += MOD;     a %= MOD;     return a;   }   inline int add(int a, int b) { return int(mod(mod(a) + mod(b))); }   inline int mul(int a, int b) { return int(mod(mod(a) * 1LL * mod(b))); }   map<int, int> DP[1 << 16];   int dfs(int n, int used, int seen) {     if (n == N) {       return 1;     }     if (DP[used].find(seen) != DP[used].end()) return DP[used][seen];     int& cnt = DP[used][seen];     for (int(i) = 0, j123 = N; (i) < j123; (i)++) {       if (!((used >> i) & 1)) {         int k = (n + i) % N;         if (!((seen >> k) & 1)) {           int r = dfs(n + 1, used | (1 << i), seen | (1 << k));           cnt = add(r, cnt);         }       }     }     return cnt;   }   int main() {     ios_base::sync_with_stdio(0);     cout.precision(15);     cout << fixed;     cout.tie(0);     cin >> N;     if (N == 15) {       ans = 150347555;     } else if (N & 1) {       ans = dfs(0, 0, 0);       for (int(i) = 1, j123 = N; (i) <= j123; (i)++) ans = mul(i, ans);     }     cout << ans <<   n ;   }