#include <bits/stdc++.h> n using namespace std; n const int N = 200010, M = 1000010, P = 1e9 + 7; n const int inf = 0x3f3f3f3f; n const int INF = 0xcfcfcfcf; n const double eps = 1e-9, pi = asin(1) * 2; n long long read(); n int ADD(int a, int b) { return a + b >= P ? a + b - P : a + b; } n int MINUS(int a, int b) { return a - b < 0 ? a - b + P : a - b; } n int n, k, odd = 0, even = 0; n long long read() { n   long long s = 0; n   bool flag = false; n   char ch = getchar(); n   for (; ch <  0  || ch >  9 ; ch = getchar()) n     if (ch ==  - ) flag = true; n   for (;  0  <= ch && ch <=  9 ; ch = getchar()) n     s = (s << 3) + (s << 1) + (ch ^  0 ); n   if (flag) return -s; n   return s; n } n int main() { n   n = read(), k = read(); n   for (int i = 1; i <= n; i++) { n     int x = read(); n     if (x & 1) n       odd++; n     else n       even++; n   } n   if (k == 0) { n     printf( Daenerys n ); n     return 0; n   } n   if (k == n) { n     if (odd & 1) n       printf( Stannis n ); n     else n       printf( Daenerys n ); n     return 0; n   } n   if (n - k & 1) { n     if (odd > even) { n       if (even <= n - k >> 1) { n         if ((odd + even) - (n - k) & 1) n           printf( Stannis n ); n         else n           printf( Daenerys n ); n       } else n         printf( Stannis n ); n     } else { n       if (odd <= n - k >> 1) n         printf( Daenerys n ); n       else n         printf( Stannis n ); n     } n   } else { n     if (odd >= even) { n       if (even <= (n - k >> 1)) { n         if ((odd + even) - (n - k) & 1) n           printf( Stannis n ); n         else n           printf( Daenerys n ); n       } else n         printf( Daenerys n ); n     } else n       printf( Daenerys n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n signed main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   int n, m; n   cin >> n >> m; n   vector<int> h(n * m + 1), v(m * n + 1); n   vector<vector<int> > A(n, vector<int>(m)); n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       cin >> A[i][j]; n     } n   } n   for (int i = 0; i < n; i++) { n     int a = 0; n     for (int j = 0; j < m; j++) { n       a = max(a, A[i][j]); n     } n     h[a] = 1; n   } n   for (int j = 0; j < m; j++) { n     int a = 0; n     for (int i = 0; i < n; i++) { n       a = max(a, A[i][j]); n     } n     v[a] = 1; n   } n   vector<vector<int> > ans(n, vector<int>(m)); n   int x = -1, y = -1; n   queue<pair<int, int> > q; n   for (int i = n * m; i >= 1; i--) { n     x += h[i]; n     y += v[i]; n     if (h[i] || v[i]) { n       ans[x][y] = i; n     } else { n       pair<int, int> v = q.front(); n       q.pop(); n       ans[v.first][v.second] = i; n     } n     if (h[i]) { n       for (int j = y - 1; j >= 0; j--) { n         q.push({x, j}); n       } n     } n     if (v[i]) { n       for (int j = x - 1; j >= 0; j--) { n         q.push({j, y}); n       } n     } n   } n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       cout << ans[i][j] <<    ; n     } n     cout <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(nullptr); n   cout.tie(nullptr); n   long int n, m, a; n   cin >> n >> m >> a; n   long int colNum = ceil((double)a / (double)(2 * m)); n   a -= (colNum - 1) * m * 2; n   long int rowNum = ceil((double)a / 2); n   a -= rowNum * 2; n   if (a == 0) n     cout << colNum <<     << rowNum <<   R ; n   else n     cout << colNum <<     << rowNum <<   L ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int pas = 0, tem, tem1; n   int n; n   cin >> n; n   vector<int> parent(n + 1, 0); n   int x, y; n   vector<vector<int> > s(n + 1, (vector<int>(3))); n   for (int i = 1; i <= n; i++) { n     cin >> s[i][1] >> s[i][2]; n   } n   for (int i = 1; i <= n; i++) { n     if (parent[i] == 0) { n       parent[i] = i; n       pas++; n     } n     for (int j = i + 1; j <= n; j++) { n       if ((s[i][1] == s[j][1]) || (s[i][2] == s[j][2])) n         if (parent[j] == 0) n           parent[j] = parent[i]; n         else { n           if (parent[i] != parent[j]) { n             tem = parent[j]; n             tem1 = parent[i]; n             for (int h = 1; h <= n; h++) n               if (parent[h] == tem) parent[h] = tem1; n             pas--; n           } n         } n     } n   } n   pas--; n   cout << pas; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = 1000000007; n const long long inf = (1LL << 60); n const double pi = acos(-1); n long long powmod(long long a, long long b) { n   long long res = 1; n   a %= mod; n   assert(b >= 0); n   for (; b; b >>= 1) { n     if (b & 1) res = res * a % mod; n     a = a * a % mod; n   } n   return res; n } n inline void pcas(int ca) { printf( Case %d:  , ca); } n const int maxn = 1e5 + 10; n int nex[maxn]; n char s[maxn], t[maxn]; n int dp[maxn], cnt[maxn]; n int lens, lent; n void kmp() { n   nex[0] = -1; n   int j = -1; n   int i = 0; n   while (i < lent) { n     while (j != -1 && t[i] != t[j]) j = nex[j]; n     nex[++i] = ++j; n   } n } n int main() { n   scanf( %s , s); n   scanf( %s , t); n   lens = strlen(s), lent = strlen(t); n   kmp(); n   if (lens < lent) { n     cout << 0; n     return 0; n   } n   bool flag; n   for (int i = lent - 1; i < lens; ++i) { n     flag = 1; n     for (int j = 0; j < lent; ++j) { n       if (s[i - j] != t[lent - j - 1] && s[i - j] !=  ? ) { n         flag = 0; n         break; n       } n     } n     dp[i] = dp[i - 1]; n     if (flag) { n       cnt[i] = dp[i - lent]; n       for (int j = nex[lent]; ~j; j = nex[j]) { n         cnt[i] = max(cnt[i], cnt[i - lent + j]); n       } n       cnt[i]++; n       dp[i] = max(cnt[i], dp[i]); n     } n   } n   printf( %d n , dp[lens - 1]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 5; n const long long INF = 1e9 + 5; n const long long mod = 1e9 + 7; n const double pi = 3.1415926536; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   ios_base::sync_with_stdio(0); n   ; n   int n, m; n   cin >> n >> m; n   bool valid = false; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       int x; n       cin >> x; n       if (x == 1 && (i == 0 || j == 0 || i == (n - 1) || j == (m - 1))) n         valid = true; n     } n   } n   if (valid) n     cout <<  2 n ; n   else n     cout <<  4 n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long t; n   cin >> t; n   while (t--) { n     long long n, q; n     cin >> n >> q; n     vector<long long> a(n); n     for (long long i = 0; i < n; i++) { n       cin >> a[i]; n     } n     long long x = 0, y = 0; n     for (long long i = 0; i < n; i++) { n       y = max(y, x + a[i]); n       x = max(x, y - a[i]); n     } n     cout << max(x, y) << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 100005; n string A; n void solve() { n   long long n, mi = 0, pl = 0; n   cin >> A; n   A =  +  + A; n   n = A.size() - 1; n   stack<char> s; n   for (__typeof((n)) i = (1); i <= (n); i++) { n     if (s.empty()) n       s.push(A[i]); n     else if (s.top() == A[i]) n       s.pop(); n     else n       s.push(A[i]); n   } n   if (s.empty()) n     cout <<  Yes  <<   n ; n   else n     cout <<  No  <<   n ; n } n signed main() { n   long long t; n   ios_base::sync_with_stdio(false); n   t = 1; n   while (t--) solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double eps = 1e-7; n double L, R, m1, m2, a, b, l; n double calc(double alp) { n   return a * sin(alp) + b * cos(alp) - l * sin(alp) * cos(alp); n } n int main() { n   scanf( %lf%lf%lf , &a, &b, &l); n   if (a > b) swap(a, b); n   if (l <= b) { n     printf( %.8lf n , min(l, a)); n     return 0; n   } n   L = 0; n   R = acos(-1) / 2; n   while (R - L > eps) { n     m1 = (2 * L + R) / 3; n     m2 = (L + 2 * R) / 3; n     if (calc(m1) > calc(m2)) n       L = m1; n     else n       R = m2; n   } n   L = min(calc(L), l); n   if (L < eps) n     puts( My poor head =( ); n   else n     printf( %.8lf n , L); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   vector<vector<int>> v; n   v.resize(n, vector<int>(7)); n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < 7; j++) { n       scanf( %1d , &v[i][j]); n     } n   } n   int max_rooms = 0, cur = 0; n   for (int i = 0; i < 7; i++) { n     for (int j = 0; j < n; j++) { n       cur += v[j][i]; n     } n     max_rooms = max(max_rooms, cur); n     cur = 0; n   } n   cout << max_rooms << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 10, INF = 0x3f3f3f3f, MOD = 1e9 + 7; n int n, m, g[405][405]; n int in[405], dpv[405], dpb[405]; n int bfs() { n   queue<int> q; n   q.push(1); n   memset(dpv, 0x3f, sizeof dpv); n   dpv[1] = 0; n   while (q.size()) { n     int u = q.front(); n     q.pop(); n     for (int i = 1; i <= n; ++i) { n       if (!g[u][i]) continue; n       if (dpv[i] == INF) { n         dpv[i] = dpv[u] + 1; n         q.push(i); n       } n     } n   } n   return dpv[n]; n } n int bfs2() { n   queue<int> q; n   q.push(1); n   memset(dpb, 0x3f, sizeof dpb); n   dpb[1] = 0; n   while (q.size()) { n     int u = q.front(); n     q.pop(); n     in[u] = false; n     for (int i = 1; i <= n; ++i) { n       if (g[u][i] || dpb[u] + 1 == dpv[i]) continue; n       if (dpb[i] == INF) { n         dpb[i] = dpb[u] + 1; n         q.push(i); n       } n     } n   } n   return dpb[n]; n } n int main() { n   ios_base::sync_with_stdio(0); n   while (scanf( %d%d , &n, &m) == 2) { n     memset(g, 0, sizeof g); n     while (m--) { n       int u, v; n       scanf( %d%d , &u, &v); n       g[u][v] = g[v][u] = 1; n     } n     int vehicle = bfs(); n     if (vehicle == INF) n       puts( -1 ); n     else { n       int bus = bfs2(); n       if (bus == INF) n         puts( -1 ); n       else n         printf( %d n , max(vehicle, bus)); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, k, mod = 1000000007; n char t[2042]; n long long dp[2042][2042], suff[2042][2042]; n int solve() { n   dp[n][0] = 1; n   for (int cInd = n - 1; cInd >= 0; cInd--) { n     dp[cInd][0] = 1; n     for (int kLeft = 0; kLeft <= k; kLeft++) { n       bool f = 0; n       for (int d = 0; cInd + d + 1 <= n; d++) { n         if (kLeft - (n - (cInd + d)) * (d + 1) >= 0) { n           dp[cInd][kLeft] += n               (1LL * dp[cInd + d + 1][kLeft - (n - (cInd + d)) * (d + 1)] * n                ( z  - t[d + cInd])) % n               mod; n         } else { n           f = 1; n           break; n         } n       } n       if (f) { n         for (int d = n - cInd - 1; 1; d--) { n           if (kLeft - (n - (cInd + d)) * (d + 1) >= 0) { n             dp[cInd][kLeft] += n                 (1LL * dp[cInd + d + 1][kLeft - (n - (cInd + d)) * (d + 1)] * n                  ( z  - t[d + cInd])) % n                 mod; n           } else { n             f = 1; n             break; n           } n         } n       } n       dp[cInd][kLeft] += n           (suff[cInd + 1][kLeft] + dp[cInd + 1][kLeft] * (t[cInd] -  a )) % mod; n       dp[cInd][kLeft] %= mod; n       suff[cInd][kLeft] += (1LL * dp[cInd + 1][kLeft] * (t[cInd] -  a ) + n                             suff[cInd + 1][kLeft]) % n                            mod; n     } n   } n   return dp[0][k]; n } n int main() { n   cin >> n >> k; n   cin >> t; n   cout << solve() <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n  n using namespace std; n const int c=200002, sok=2e9; n long long t[c], kom[c], h[c], ki[c], n, m, maxi; n priority_queue<pair<long long, int> > q; n vector<pair<long long, int> > ans; n int holvan(int a) { n     if (!ki[a]) { n         return a; n     } n     return ki[a]=holvan(ki[a]); n } n void unio(int a, int b) { n     a=holvan(a), b=holvan(b); n     ki[b]=a; n     h[a]+=h[b]; n } n void pb(int l, int r) { n     long long sum=kom[r]-kom[l-1], d=(r-l+1), atl=(sum-1)/d; n     q.push({atl, l}); n } n int main() n { n     ios_base::sync_with_stdio(false); n     cin >> n >> m; n     for (int i=1; i<=n; i++) { n         cin >> t[i]; n         kom[i]=kom[i-1]+t[i], h[i]=1; n         if (i<n) { n             pb(i, i); n         } n     } n     ans.push_back({sok, 0}); n     n--; n     while (q.size()>0) { n         long long ert=q.top().first, id=q.top().second; n         q.pop(); n         if (!ki[id]) { n             maxi=max(maxi, h[id]+h[id+h[id]]-1); n             ans.push_back({ert, maxi}); n             int kov=id+h[id]; n             if (kov!=n+1) { n                 unio(id, kov); n                 pb(id, id+h[id]-1); n             } n         } n     } n     reverse(ans.begin(), ans.end()); n     int si=ans.size(); n     for (int i=si-2; i>=0; i--) { n         ans[i].first=min(ans[i].first, ans[i+1].first); n     } n     for (int i=1; i<=m; i++) { n         int x; n         cin >> x; n         int lo=-1, hi=ans.size(), mid; n         while (hi-lo>1) { n             mid=(lo+hi)/2; n             if (ans[mid].first>=x) { n                 hi=mid; n             } else { n                 lo=mid; n             } n         } n         cout << ans[hi].second <<    ; n     } n     cout <<   n ; n     return 0; n } n


#include <bits/stdc++.h> n using namespace std; n unsigned long long x1, out; n unsigned long long Fac(unsigned long long x1) { n   unsigned long long out = 1; n   for (int i = 1; i <= x1; i++) out = out * i; n   return out; n } n unsigned long long Cnk(unsigned long long a, unsigned long long b, n                        unsigned long long c) { n   unsigned long long outL = 1; n   vector<int> fac; n   if (b > c) { n     unsigned long long nCount = a - b; n     for (int i = 2; i <= c; i++) fac.push_back(i); n     while (nCount > 0) { n       outL = outL * a; n       a--; n       nCount--; n       for (int i = 0; i < fac.size(); i++) { n         if (fac[i] > -1 && outL % fac[i] == 0) { n           outL = outL / fac[i]; n           fac[i] = -1; n         } n       } n     } n   } else { n     unsigned long long nCount = a - c; n     for (int i = 2; i <= b; i++) fac.push_back(i); n     while (nCount > 0) { n       outL = outL * a; n       a--; n       nCount--; n       for (int i = 0; i < fac.size(); i++) { n         if (fac[i] > -1 && outL % fac[i] == 0) { n           outL = outL / fac[i]; n           fac[i] = -1; n         } n       } n     } n   } n   for (int i = 0; i < fac.size(); i++) { n     if (fac[i] > -1) outL = outL / fac[i]; n   } n   return outL; n } n int main() { n   int n, m, t; n   cin >> n >> m >> t; n   for (int i = 4; i <= n; i++) { n     for (int y = 1; y <= m; y++) { n       if (i + y != t) continue; n       out += (Cnk(n, i, n - i) * Cnk(m, y, m - y)); n     } n   } n   cout << out; n   cin >> x1; n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:64000000 ) n using namespace std; n const int inf = (int)1e9; n const int mod = inf + 7; n const double eps = 1e-9; n const double pi = acos(-1.0); n int n; n string second; n int a[100]; n vector<int> g[202]; n int dp[77][77][77][4]; n int calc(vector<int> &a, int n, vector<int> &b, int m, vector<int> &c, int k) { n   n = a.size() - n; n   m = (int)b.size() - m; n   k = (int)c.size() - k; n   int x = a[n]; n   int cnt = 0; n   for (int i = m; i < b.size(); i++) n     if (b[i] < x) cnt++; n   for (int i = k; i < c.size(); i++) n     if (c[i] < x) cnt++; n   return cnt; n } n int get(int a, int b, int c, int ty) { n   if (a + b + c == 0) return 0; n   int &res = dp[a][b][c][ty]; n   if (res != -1) return res; n   res = inf; n   if (a > 0) { n     if (ty != 1) n       res = min(res, get(a - 1, b, c, 0) + calc(g[0], a, g[1], b, g[2], c)); n   } n   if (b > 0) { n     res = min(res, get(a, b - 1, c, 1) + calc(g[1], b, g[0], a, g[2], c)); n   } n   if (c > 0) { n     res = min(res, get(a, b, c - 1, 2) + calc(g[2], c, g[1], b, g[0], a)); n   } n   return res; n } n int main() { n   cin >> n >> second; n   for (int i = 0; i < n; i++) { n     if (second[i] ==  V ) n       a[i] = 1; n     else if (second[i] ==  K ) n       a[i] = 0; n     else n       a[i] = 2; n     g[a[i]].push_back(i); n   } n   memset(dp, -1, sizeof dp); n   cout << get(g[0].size(), g[1].size(), g[2].size(), 3) << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   double t, a, b, c, d, k; n   cin >> t; n   while (t--) { n     cin >> a >> b >> c >> d >> k; n     double p1, p2; n     p1 = ceil(a / c); n     p2 = ceil(b / d); n     if (p1 + p2 <= k) { n       cout << p1 <<     << p2 << endl; n     } else { n       cout << -1 << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m; n double ax, ay, bx, by, tx, ty, x, y; n char s[100100]; n double len(double x1, double y1, double x2, double y2) { n   return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); n } n int main() { n   ios_base::sync_with_stdio(false); n   cin >> ax >> ay >> bx >> by >> tx >> ty; n   cin >> n; n   vector<pair<double, int> > v1, v2; n   double total = 0; n   for (int i = 0; i < n; i++) { n     cin >> x >> y; n     v1.push_back(make_pair(len(ax, ay, x, y) - len(tx, ty, x, y), i)); n     v2.push_back(make_pair(len(bx, by, x, y) - len(tx, ty, x, y), i)); n     total += 2 * len(tx, ty, x, y); n   } n   sort(v1.begin(), v1.end()); n   sort(v2.begin(), v2.end()); n   double res = total; n   double case1 = total + v1[0].first; n   double case2 = total + v2[0].first; n   res = min(case1, case2); n   if (v1[0].second != v2[0].second) { n     double case3 = total + v1[0].first + v2[0].first; n     res = min(res, case3); n   } else if (n > 1) { n     double case4 = total + v1[0].first + v2[1].first; n     res = min(res, case4); n     double case5 = total + v1[1].first + v2[0].first; n     res = min(res, case5); n   } n   printf( %.10lf , res); n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   int n; n   scanf( %d , &n); n   char arr[n][n + 1]; n   int i, j, k; n   int sum = 0; n   int count; n   for (i = 0; i < n; i++) scanf( %s , arr[i]); n   for (i = 0; i < n; i++) { n     count = 0; n     for (j = 0; j < n; j++) { n       if (arr[i][j] ==  C ) count++; n     } n     sum += ((count * (count - 1)) / 2); n   } n   for (i = 0; i < n; i++) { n     count = 0; n     for (j = 0; j < n; j++) { n       if (arr[j][i] ==  C ) count++; n     } n     sum += ((count * (count - 1)) / 2); n   } n   printf( %d , sum); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n #define mod1  1000000007 n #define mod2  998244353 n #define ff   first n #define ss   second n #define int  long long n #define ll   unsigned long long n #define pb   push_back n #define mp   make_pair n #define pii  pair<int,int> n #define inf  9e18 n #define N    15000005 n #define pi   2*asin(1.0) n #define endl   n  n   n void fast() { n     ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); n #ifndef ONLINE_JUDGE n     freopen( input.txt ,  r , stdin); n     freopen( output.txt ,  w , stdout); n #endif n } n  n  n  n int32_t main() { n     fast(); n     int t; cin>>t; n     while(t--){ n         int n,m; cin>>n>>m; n         int arr[n]; n         for(int i=0;i<n;i++){ n             cin>>arr[i]; n         } n         int cnt=n; n         int len=0; n         for(int i=n-1;i>=0;i--){ n             if(arr[i]==cnt){ n                 cnt--; n             } n             else{ n                 len=i+1; break; n             } n         } n         double ans=1.0; n         for(int i=0;i<m;i++){ n             int r; double p; n             cin>>r>>p; n             if(r>=len){ n                 ans=(ans*(1.0-p)); n             } n         } n         ans=1.0-ans; n         if(len==0) ans=1.0; n         cout<<fixed<<setprecision(6)<<ans<<endl; n     } n     return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n using ull = unsigned long long; n using ld = long double; n template <typename T> n ostream& operator<<(ostream& os, const vector<T>& v) { n   for (const auto& x : v) os << x <<    ; n   return os <<   n ; n } n template <typename T> n void operator>>(istream& is, vector<T>& v) { n   for (auto& x : v) is >> x; n } n ll power(ll a, ll n) { n   if (n == 0) { n     return 1; n   } n   ll sqrt_a = pow(a, n / 2); n   if (n % 2 == 1) { n     return sqrt_a * sqrt_a * a; n   } else { n     return sqrt_a * sqrt_a; n   } n } n template <typename T> n T sign(T a) { n   if (a < 0) return -1; n   if (a > 0) return 1; n   return 0; n } n template <typename T> n T log_2(T n) { n   T i = 1; n   T j = 0; n   while (i < n) { n     i *= 2; n     ++j; n   } n   return j; n } n template <typename T> n T mod(T a, T b) { n   T ans = a % b; n   return ans < 0 ? ans + b : ans; n } n ll gcd(ll a, ll b) { n   while (b) { n     a %= b; n     swap(a, b); n   } n   return a; n } n ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } n class Node { n  public: n   char symbol; n   bool passed = false; n   vector<ll> neighbores = vector<ll>(); n }; n template <typename T> n class Compare { n  public: n   bool operator()(T& a, T& b) { n     if (a.first < b.first) { n       return true; n     } else if (a.first == b.first) { n       return a.second < b.second; n     } else { n       return false; n     } n   } n }; n vector<ll> divs(ll n) { n   vector<ll> ans; n   while (n != 1) { n     for (ll i = 2; i <= n; ++i) { n       if (n % i == 0) { n         ans.push_back(i); n         n /= i; n         break; n       } n     } n   } n   return ans; n } n void solve() { n   ll a, b, c; n   cin >> a >> b >> c; n   if (a < c) { n     cout <<  1  ; n   } else { n     cout <<  -1  ; n   } n   if (b * a > c) { n     cout << b <<   n ; n   } else { n     cout <<  -1 n ; n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   ll t; n   cin >> t; n   while (t--) { n     solve(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n string read(char x[]) { n   scanf( %s , x); n   return x; n } n const int N = 8; n const int M = 2e5 + 23; n int n, m, x[M], y[M], ans; n map<int, pair<long long, long long>> mp; n void solve() { n   scanf( %d %d , &n, &m); n   for (int i = 0; i < n; i++) scanf( %d , x + i); n   for (int i = 0; i < m; i++) scanf( %d , y + i); n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       mp[x[i] + y[j]] = {mp[x[i] + y[j]].first | (1ll << i), n                          mp[x[i] + y[j]].second | (1ll << j)}; n     } n   } n   for (auto v1 : mp) n     for (auto v2 : mp) { n       long long m1 = v1.second.first | v2.second.first, n                 m2 = v1.second.second | v2.second.second; n       ans = max(ans, __builtin_popcountll(m1) + __builtin_popcountll(m2)); n     } n   printf( %d , ans); n } n int main() { solve(); } n


#include <bits/stdc++.h> n using namespace std; n bool myfunction(int i, int j) { return (i < j); } n int main() { n   long h[2003]; n   int n, a, b; n   scanf( %d%d%d , &n, &a, &b); n   for (int i = 0; i < n; i++) { n     scanf( %ld , &h[i]); n   } n   sort(h, h + n, myfunction); n   int x = h[b] - h[b - 1]; n   printf( %d , x); n   return 0; n } n


#include <bits/stdc++.h> n template <class t> n inline void read(t &s) { n   s = 0; n   register long long f = 1; n   register char c = getchar(); n   while (!isdigit(c)) { n     if (c ==  - ) f = -1; n     c = getchar(); n   } n   while (isdigit(c)) s = (s << 3) + (s << 1) + (c ^ 48), c = getchar(); n   s *= f; n   return; n } n template <class t, class... A> n inline void read(t &x, A &...a) { n   read(x); n   read(a...); n } n template <class t> n inline void write(t x) { n   if (x < 0) putchar( - ), x = -x; n   long long buf[21], top = 0; n   while (x) buf[++top] = x % 10, x /= 10; n   if (!top) buf[++top] = 0; n   while (top) putchar(buf[top--] ^  0 ); n   return; n } n inline void setIn(std::string s) { n   freopen(s.c_str(),  r , stdin); n   return; n } n inline void setOut(std::string s) { n   freopen(s.c_str(),  w , stdout); n   return; n } n inline void setIO(std::string s =   ) { n   setIn(s +  .in ); n   setOut(s +  .out ); n   return; n } n template <class t> n inline bool checkmin(t &x, t y) { n   if (x > y) { n     x = y; n     return 1; n   } n   return 0; n } n template <class t> n inline bool checkmax(t &x, t y) { n   if (x < y) { n     x = y; n     return 1; n   } n   return 0; n } n inline long long lowbit(long long x) { return x & (-x); } n const long long MaxN = 1e5 + 50; n long long f[MaxN], g[MaxN], b[MaxN], n, m; n struct BIT { n   long long a[MaxN]; n   inline void init() { std::memset(a, 0, sizeof a); } n   inline void upd(long long x, long long k) { n     ++x; n     while (x <= m + 1) checkmax(a[x], k), x += lowbit(x); n   } n   inline long long ask(long long x) { n     ++x; n     register long long ans = 0; n     while (x) checkmax(ans, a[x]), x ^= lowbit(x); n     return ans; n   } n } tr; n signed main(void) { n   read(n, m); n   register long long l, r; n   while (n--) read(l, r), ++b[l], --b[r + 1]; n   for (long long i = 1; i <= m; ++i) b[i] += b[i - 1]; n   tr.init(); n   for (long long i = 1; i <= m; ++i) n     f[i] = tr.ask(b[i]) + 1, tr.upd(b[i], f[i]); n   tr.init(); n   for (long long i = m; i; --i) g[i] = tr.ask(b[i]) + 1, tr.upd(b[i], g[i]); n   register long long ans = 0; n   for (long long i = 0; i <= m; ++i) checkmax(ans, f[i] + g[i + 1]); n   write(ans), std::puts(  ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int M = 100004; n unordered_map<string, int> mp; n unordered_set<int> st[M]; n vector<int> g[M]; n string s[M]; n int m = 0; n int getid(string &t) { n   if (mp.count(t)) n     return mp[t]; n   else { n     s[++m] = t; n     return mp[t] = m; n   } n } n int val[M]; n struct P { n   int v, s0, s1; n } sv[M]; n P dfs(int u, int p) { n   if (g[u].empty()) n     return P{p, 0, 0}; n   else if (sv[u].v != -1) n     return sv[u]; n   P win = P{-1, -1, -1}, lose = P{-1, -1, -1}; n   for (int v : g[u]) { n     P nw = dfs(v, p ^ 1); n     int s0 = nw.s0, s1 = nw.s1; n     if (p == 0) { n       s0 += val[v]; n       if (nw.v == 1 && (s0 > win.s0 || s0 == win.s0 && s1 < win.s1)) n         win = P{1, s0, s1}; n       if (nw.v == 0 && (s0 > lose.s0 || s0 == lose.s0 && s1 < lose.s1)) n         lose = P{0, s0, s1}; n     } else { n       s1 += val[v]; n       if (nw.v == 0 && (s1 > win.s1 || s1 == win.s1 && s0 < win.s0)) n         win = P{0, s0, s1}; n       if (nw.v == 1 && (s1 > lose.s1 || s1 == lose.s1 && s0 < lose.s0)) n         lose = P{1, s0, s1}; n     } n   } n   if (win.v != -1) n     return sv[u] = win; n   else n     return sv[u] = lose; n } n int main() { n   int n; n   memset(sv, -1, sizeof(sv)); n   cin >> n; n   string t; n   for (int i = 0; i < n; i++) { n     cin >> t; n     for (int j = 0; j < t.size(); j++) { n       string u =   ; n       for (int k = j; k < t.size(); k++) { n         u += t[k]; n         int x = getid(u); n         st[x].insert(i); n       } n     } n   } n   for (int i = 0; i <= m; i++) { n     for (char ch =  a ; ch <=  z ; ch++) { n       string t = s[i] + ch; n       if (mp.count(t)) { n         int x = mp[t]; n         g[i].push_back(x); n       } n       t = string(  ) + ch + s[i]; n       if (mp.count(t)) { n         int x = mp[t]; n         g[i].push_back(x); n       } n     } n     int sum = 0, mx = 0; n     for (char ch : s[i]) { n       int x = ch -  a  + 1; n       mx = max(mx, x); n       sum += x; n     } n     val[i] = sum * mx + st[i].size(); n   } n   P p = dfs(0, 0); n   puts(p.v ?  First  :  Second ); n   printf( %d %d n , p.s0, p.s1); n } n


#include <bits/stdc++.h> n using namespace std; n void File() { n   freopen( CF1045H.in ,  r , stdin); n   freopen( CF1045H.out ,  w , stdout); n } n template <typename T> n void read(T &_) { n   _ = 0; n   T f = 1; n   char c = getchar(); n   for (; !isdigit(c); c = getchar()) n     if (c ==  - ) f = -1; n   for (; isdigit(c); c = getchar()) _ = (_ << 1) + (_ << 3) + (c ^  0 ); n   _ *= f; n } n const int maxn = 5e5 + 10; n const int mod = 1e9 + 7; n const int N = 1e5; n long long fac[maxn], ifac[maxn]; n int c[5]; n long long qpow(long long x, long long y) { n   long long ret = 1; n   x %= mod; n   while (y) { n     if (y & 1) ret = ret * x % mod; n     x = x * x % mod; n     y >>= 1; n   } n   return ret; n } n void math_init() { n   fac[0] = 1; n   for (int i = 1, i_end_ = N; i <= i_end_; ++i) fac[i] = fac[i - 1] * i % mod; n   ifac[N] = qpow(fac[N], mod - 2); n   for (int i = N - 1, i_end_ = 0; i >= i_end_; --i) n     ifac[i] = ifac[i + 1] * (i + 1) % mod; n } n long long C(int x, int y) { n   if (x < 0 || y < 0 || x < y) return 0; n   return fac[x] * ifac[y] % mod * ifac[x - y] % mod; n } n long long calc(int x, int y) { n   if (!x && !y) return 1; n   return C(x + y - 1, y - 1); n } n long long solve(char *s, bool type) { n   long long ret = 0; n   int len = strlen(s + 1), lim = 0, res[5]; n   for (int i = 0, i_end_ = 3; i <= i_end_; ++i) lim += c[i], res[i] = c[i]; n   ++lim; n   if (len < lim) return 0; n   if (len > lim) { n     type = 1; n     len = lim; n     for (int i = 1, i_end_ = len; i <= i_end_; ++i) s[i] =  1 ; n   } n   for (int i = 1, i_end_ = len; i <= i_end_; ++i) { n     if (i > 2) --res[(s[i - 2] ^  0 ) << 1 | (s[i - 1] ^  0 )]; n     if (s[i] ==  0  || i == 1) continue; n     if (i > 1) --res[(s[i - 1] ^  0 ) << 1]; n     if (res[2] >= res[1] - 1 && res[2] <= res[1]) { n       ret = (ret + calc(res[0], res[2] + 1) * calc(res[3], res[1])) % mod; n     } n     if (i > 1) ++res[(s[i - 1] ^  0 ) << 1]; n   } n   if (type) { n     if (len > 1) --res[(s[len - 1] ^  0 ) << 1 | (s[len] ^  0 )]; n     if (!res[0] && !res[1] && !res[2] && !res[3]) ++ret; n   } n   return ret; n } n int main() { n   char L[maxn], R[maxn]; n   math_init(); n   scanf( %s%s , L + 1, R + 1); n   for (int i = 0, i_end_ = 3; i <= i_end_; ++i) read(c[i]); n   printf( %lld n , ((solve(R, 1) - solve(L, 0)) % mod + mod) % mod); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a[1000001]; n int l, r; n int jum, jaw; n int main() { n   int n, m, k; n   cin >> n >> m >> k; n   k--; n   for (int i = 1; i <= n; i++) { n     int dum; n     cin >> dum; n     a[dum]++; n   } n   l = 1; n   r = m; n   for (int i = 1; i <= m; i++) { n     if (a[i] + jum > k) { n       jaw += jum + a[i] - k; n       a[i] = k - jum; n       jum = k; n     } else { n       jum += a[i]; n     } n   } n   while (r < 1000000) { n     r++; n     jum -= a[l]; n     l++; n     if (a[r] + jum > k) { n       jaw += jum + a[r] - k; n       a[r] = k - jum; n       jum = k; n     } else { n       jum += a[r]; n     } n   } n   cout << jaw << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1010; n int a[maxn]; n int main() { n   int n = 4; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n   } n   sort(a, a + n); n   int sum, ans; n   sum = ans = 0; n   ans = a[3]; n   int l = 0; n   n = 2; n   while (n >= 0) { n     if (ans > sum) n       sum += a[n--]; n     else { n       ans += a[n--]; n     } n   } n   if (ans == sum) n     cout <<  YES  << endl; n   else n     cout <<  NO  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 50010, K = 11; n int n, k; n int s[N][K]; n struct Data { n   int mn[K], mx[K]; n   int cnt; n   Data() { n     for (int i = 0; i < K; i++) { n       mn[i] = 1e9; n       mx[i] = -1e9; n     } n     cnt = 0; n   } n }; n bool operator<(const Data &u, const Data &v) { n   return u.mx[1] < v.mx[1]; n   return 1; n } n bool check(const Data &u, const Data &v) { n   int l = 0, r = 0; n   for (int i = 1; i <= k; i++) { n     if (u.mx[i] > v.mn[i]) { n       r = 1; n     } n     if (u.mn[i] < v.mx[i]) { n       l = 1; n     } n   } n   return l && r; n } n void update(Data &u, const Data &v) { n   for (int i = 1; i <= k; i++) { n     u.mx[i] = max(u.mx[i], v.mx[i]); n     u.mn[i] = min(u.mn[i], v.mn[i]); n   } n   u.cnt += v.cnt; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cin >> n >> k; n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= k; j++) { n       cin >> s[i][j]; n     } n   } n   set<Data> a; n   for (int i = 1; i <= n; i++) { n     Data foo; n     for (int j = 1; j <= k; j++) { n       foo.mx[j] = foo.mn[j] = s[i][j]; n       foo.cnt = 1; n     } n     if (a.empty()) { n       a.insert(foo); n       cout << 1 << endl; n       continue; n     } n     while (!a.empty()) { n       auto it = a.lower_bound(foo); n       if (it == a.end()) { n         break; n       } n       Data bar = *it; n       if (check(foo, bar)) { n         update(foo, bar); n         a.erase(it); n       } else { n         break; n       } n     } n     while (!a.empty()) { n       auto it = a.lower_bound(foo); n       if (it == a.begin()) { n         break; n       } n       it--; n       Data bar = *it; n       if (check(bar, foo)) { n         update(foo, bar); n         a.erase(it); n       } else { n         break; n       } n     } n     a.insert(foo); n     cout << a.rbegin()->cnt << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long gcd(long long a, long long b) { n   while (a > 0 && b > 0) { n     if (a < b) swap(a, b); n     a %= b; n   } n   return a + b; n } n const int maxN = (int)1e6 + 10; n long long a[maxN]; n long long k; n vector<long long> factor(long long x) { n   vector<long long> cur; n   for (int i = 2; 1LL * i * i <= x; i++) { n     if (x % i == 0) { n       while (x % i == 0) { n         x /= i; n       } n       cur.push_back(i); n     } n   } n   if (x > 1) cur.push_back(x); n   return cur; n } n int n; n int e[maxN]; n int vals[maxN][13]; n map<long long, int> all; n long long dp[10000][20]; n long long ndp[10000][20]; n vector<pair<int, int> > best[10000]; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n   cin >> n >> k; n   for (int i = 1; i <= n; i++) { n     cin >> a[i]; n   } n   for (int i = 1; i <= n; i++) { n     cin >> e[i]; n   } n   long long d = a[1]; n   for (int i = 2; i <= n; i++) { n     d = gcd(d, a[i]); n   } n   if (d == 1) { n     cout << 0; n     return 0; n   } n   auto t = factor(d); n   vector<pair<long long, int> > ss; n   for (int i = 1; i <= n; i++) { n     long long cop = a[i]; n     for (int j = 0; j < t.size(); j++) { n       while (cop % t[j] == 0) { n         cop /= t[j]; n         vals[i][j]++; n       } n     } n     a[i] /= cop; n     ss.push_back(make_pair(a[i], e[i])); n   } n   sort(ss.begin(), ss.end()); n   vector<pair<long long, int> > vals; n   int ii = 0; n   int m = t.size(); n   while (ii < ss.size()) { n     int j = ii; n     while (j < ss.size() && ss[j].first == ss[ii].first) j++; n     j--; n     for (int k = ii; k <= j && k <= ii + m - 1; k++) vals.push_back(ss[k]); n     ii = j + 1; n   } n   for (int i = 0; i < (1 << m); i++) { n     for (int j = 0; j <= m; j++) { n       dp[i][j] = (long long)1e18; n       ndp[i][j] = (long long)1e18; n     } n   } n   dp[0][0] = 0; n   int r = vals.size(); n   for (int u = 0; u < vals.size(); u++) { n     auto f = vals[u]; n     vector<bool> is_good(1 << m, false); n     for (int i = 0; i < (1 << m); i++) { n       for (int j = 0; j <= m; j++) { n         ndp[i][j] = dp[i][j]; n       } n       long long s = 1; n       long long x = f.first; n       for (int j = 0; j < m; j++) { n         if (!(i & (1 << j))) continue; n         while (x % t[j] == 0) { n           s *= t[j]; n           x /= t[j]; n         } n       } n       if (s <= k) { n         best[i].push_back(make_pair(f.second, u)); n         is_good[i] = true; n       } n     } n   } n   vector<bool> need(vals.size(), false); n   for (int i = 0; i < (1 << m); i++) { n     sort(best[i].begin(), best[i].end()); n     for (int j = 0; j < min((int)best[i].size(), m); j++) { n       need[best[i][j].second] = true; n     } n   } n   for (int u = 0; u < vals.size(); u++) { n     if (!need[u]) continue; n     auto f = vals[u]; n     vector<bool> is_good(1 << m, false); n     for (int i = 0; i < (1 << m); i++) { n       for (int j = 0; j <= m; j++) { n         ndp[i][j] = dp[i][j]; n       } n       long long s = 1; n       long long x = f.first; n       for (int j = 0; j < m; j++) { n         if (!(i & (1 << j))) continue; n         while (x % t[j] == 0) { n           s *= t[j]; n           x /= t[j]; n         } n       } n       if (s <= k) { n         is_good[i] = true; n       } n     } n     for (int i = 0; i < (1 << m); i++) { n       if (!is_good[i]) continue; n       int st = ((1 << m) - 1) ^ i; n       int msk = st; n       while (true) { n         for (int j = 0; j < m; j++) { n           ndp[st | i][j + 1] = min(ndp[st | i][j + 1], dp[st][j] + f.second); n         } n         if (st == 0) break; n         st = (msk & (st - 1)); n       } n     } n     for (int i = 0; i < (1 << m); i++) { n       for (int j = 0; j <= m; j++) { n         dp[i][j] = ndp[i][j]; n       } n     } n   } n   long long mn = (long long)1e18 - 10; n   bool ok = false; n   for (int i = 0; i <= m; i++) { n     if (dp[(1 << m) - 1][i] > (long long)1e16) continue; n     ok = true; n     mn = min(mn, i * dp[(1 << m) - 1][i]); n   } n   if (ok) n     cout << mn; n   else n     cout << -1; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n   int n, m; n   cin >> n >> m; n   int a[n][m], b[n][m]; n   for (int i = 0; i < n; ++i) n     for (int j = 0; j < m; ++j) cin >> a[i][j]; n   for (int i = 0; i < n; ++i) n     for (int j = 0; j < m; ++j) cin >> b[i][j]; n   for (int i = 0; i < n; ++i) n     for (int j = 0; j < m; ++j) n       if (a[i][j] > b[i][j]) swap(a[i][j], b[i][j]); n   bool pass = true; n   for (int i = 0; i < n - 1; ++i) n     for (int j = 0; j < m - 1; ++j) { n       if (a[i][j] >= a[i + 1][j] || a[i][j] >= a[i][j + 1] || n           b[i][j] >= b[i + 1][j] || b[i][j] >= b[i][j + 1]) n         pass = false; n     } n   for (int i = 0; i < m - 1; ++i) n     if (a[n - 1][i] >= a[n - 1][i + 1] || b[n - 1][i] >= b[n - 1][i + 1]) n       pass = false; n   for (int i = 0; i < n - 1; ++i) n     if (a[i][m - 1] >= a[i + 1][m - 1] || b[i][m - 1] >= b[i + 1][m - 1]) n       pass = false; n   pass ? puts( Possible ) : puts( Impossible ); n } n


#include <bits/stdc++.h> n using namespace std; n int c[120][120], ct[120], n; n int ccc[120], Ciel, Jiro, cnt; n int main() { n   scanf( %d , &n); n   for (int i = 0; i < n; i++) { n     scanf( %d , ct + i); n     int p1 = ct[i] / 2 - 1, p2 = ct[i] - ct[i] / 2; n     for (int j = 0; j < ct[i]; j++) { n       scanf( %d , &c[i][j]); n       if (j <= p1) n         Ciel += c[i][j]; n       else if (j >= p2) n         Jiro += c[i][j]; n       else n         ccc[cnt++] = c[i][j]; n     } n   } n   sort(ccc, ccc + cnt); n   for (int i = cnt - 1; i >= 0; i--) { n     if ((cnt - i) % 2) n       Ciel += ccc[i]; n     else n       Jiro += ccc[i]; n   } n   printf( %d %d n , Ciel, Jiro); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long M = 998244353; n long long modpow(long long base, long long exp, long long modulus = M) { n   base %= modulus; n   long long result = 1; n   while (exp > 0) { n     if (exp & 1) result = (result * base) % modulus; n     base = (base * base) % modulus; n     exp >>= 1; n   } n   return result; n } n long long modinv(long long a, long long mod = M) { return modpow(a, mod - 2); } n string s; n int n; n long long f[1000010], invf[1000010]; n long long C(long long a, long long b) { n   if (b > a || b < 0 || a < 0) return 0; n   return (((f[a] * invf[b]) % M) * invf[a - b]) % M; n } n int main() { n   ios::sync_with_stdio(false); n   cin >> s; n   n = s.length(); n   f[0] = invf[0] = 1; n   for (int i = 1; i <= n; ++i) { n     f[i] = (f[i - 1] * i) % M; n     invf[i] = modinv(f[i]); n   } n   int lb = 0, rb = 0, lq = 0, rq = 0; n   for (int i = 0; i < n; ++i) { n     if (s[i] ==  ) ) n       ++rb; n     else if (s[i] ==  ? ) n       ++rq; n   } n   long long ans = 0; n   for (int i = 0; i < n; ++i) { n     if (s[i] ==  ) ) --rb; n     if (s[i] ==  ( ) ++lb; n     if (s[i] ==  ? ) --rq, ++lq; n     ans += (1ll * lb * C(lq + rq, rq - lb + rb) + n             1ll * lq * C(lq + rq - 1, rq - lb + rb - 1)) % n            M; n     ans %= M; n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using PII = pair<int, int>; n PII a[300005]; n int idx[300005]; n map<int, int> mp; n int main() { n   int n; n   ; n   scanf( %d , &n); n   for (int i = 0; i < n; ++i) { n     scanf( %d %d , &a[i].first, &a[i].second); n     idx[i] = i; n   } n   sort(idx, idx + n, [&](int l, int r) { n     if (a[l].first != a[r].first) n       return a[l].first > a[r].first; n     else n       return a[l].second < a[r].second; n   }); n   bool f = false; n   for (int i = 0; i < n; ++i) { n     auto it = mp.upper_bound(a[idx[i]].second); n     if (it != mp.begin()) { n       f = true; n       --it; n       printf( %d %d n , it->second + 1, idx[i] + 1); n       break; n     } else { n       mp[a[idx[i]].second] = idx[i]; n     } n   } n   if (!f) puts( -1 -1 ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 1e6 + 5; n long long n; n long long a[N]; n int32_t main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   ; n   cin >> n; n   if (n == 0) { n     cout <<  1 1 ; n     return 0; n   } n   long long l = 1, r = n; n   for (long long cur = 1; cur <= n; cur += 2) { n     a[l++] = cur; n     a[r--] = cur; n   } n   l = n + 1; n   r = 2 * n - 1; n   for (long long cur = 2; cur <= n; cur += 2) { n     a[l++] = cur; n     a[r--] = cur; n   } n   for (long long i = 1; i <= 2 * n; i++) { n     if (a[i] == 0) a[i] = n; n     cout << a[i] <<    ; n   } n   return 0; n } n


#include <bits/stdc++.h> n const double Pi = 3.14159265; n const int N = 2e5 + 10; n const unsigned long long base = 163; n const int INF = 0x3f3f3f3f; n const int mod = 1e9 + 7; n const double eps = 1e-10; n const double pi = acos(-1); n using namespace std; n long long inv[N]; n long long dp[N]; n int main() { n   long long p = mod; n   long long n; n   cin >> n; n   inv[1] = 1; n   for (int i = 2; i <= n; i++) inv[i] = (p - p / i) * inv[p % i] % p; n   long long ans = 1; n   for (int i = n; i >= 2; --i) { n     dp[i] = n / i * inv[n - n / i]; n     for (int j = i + i; j <= n; j += i) { n       dp[i] -= dp[j]; n       dp[i] %= mod; n     } n     dp[i] += mod; n     dp[i] %= mod; n     ans += dp[i]; n     ans %= mod; n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n const int N = 2e5 + 5; n using namespace std; n int n, k, m, ans[N], x[N], y[N], mx; n map<pair<int, int>, int> Mp; n template <typename T> n inline T read() { n   T x = 0, w = 1; n   char c = getchar(); n   while (c <  0  || c >  9 ) { n     if (c ==  - ) w = -1; n     c = getchar(); n   } n   while (c >=  0  && c <=  9 ) x = x * 10 + c -  0 , c = getchar(); n   return x * w; n } n struct PQ { n   priority_queue<int> q1, q2; n   int cnt; n   PQ() { cnt = 0; } n   void ins(int x) { cnt++, q1.push(x); } n   void del(int x) { cnt--, q2.push(x); } n   int top() { n     while (!q1.empty() && !q2.empty() && q1.top() == q2.top()) n       q1.pop(), q2.pop(); n     return q1.top(); n   } n   bool empty() { return !cnt; } n } q; n struct BIT { n   int t[N << 2]; n   int lowbit(int x) { return x & (-x); } n   void modify(int x, int y) { n     for (int i = x; i <= mx; i += lowbit(i)) t[i] += y; n   } n   int query(int x) { n     int res = 0; n     for (int i = x; i; i -= lowbit(i)) res += t[i]; n     return res; n   } n   int kth(int x) { n     int sum = 0, pos = 0; n     for (int i = 20; i >= 0; i--) n       if (pos + (1 << i) <= mx && sum + t[pos + (1 << i)] < x) n         pos += (1 << i), sum += t[pos]; n     return pos + 1; n   } n } BIT; n struct SegTree { n   vector<int> vec[N << 2], op[N << 2]; n   void modify(int p, int l, int r, int ql, int qr, int x) { n     if (ql <= l && r <= qr) return (void)(vec[p].push_back(x)); n     int mid = (l + r) >> 1; n     if (ql <= mid) modify(p << 1, l, mid, ql, qr, x); n     if (mid < qr) modify(p << 1 | 1, mid + 1, r, ql, qr, x); n   } n   void dfs(int p, int l, int r) { n     for (int x, y, i = 0; i < vec[p].size(); i++) { n       x = vec[p][i], x = BIT.query(x - 1), x = BIT.kth(x + 1); n       BIT.modify(x, -1), op[p].push_back(x), q.ins(x); n     } n     if (l == r) { n       ans[l] = q.top() - n; n       for (int i = 0; i < op[p].size(); i++) n         BIT.modify(op[p][i], 1), q.del(op[p][i]); n       return; n     } n     int mid = (l + r) >> 1; n     dfs(p << 1, l, mid), dfs(p << 1 | 1, mid + 1, r); n     for (int i = 0; i < op[p].size(); i++) n       BIT.modify(op[p][i], 1), q.del(op[p][i]); n   } n } T; n int mabs(int x) { return x > 0 ? x : -x; } n int main() { n   n = read<int>(), k = read<int>(), m = read<int>(); n   for (int i = 1; i <= m; i++) { n     x[i] = read<int>(), y[i] = read<int>(); n     if (!Mp[make_pair(x[i], y[i])]) n       Mp[make_pair(x[i], y[i])] = i; n     else { n       T.modify(1, 1, m, Mp[make_pair(x[i], y[i])], i - 1, n                y[i] + mabs(x[i] - k)); n       mx = max(mx, y[i] + mabs(x[i] - k)), Mp[make_pair(x[i], y[i])] = 0; n     } n   } n   for (int i = 1; i <= m; i++) n     if (Mp[make_pair(x[i], y[i])]) { n       T.modify(1, 1, m, Mp[make_pair(x[i], y[i])], m, y[i] + mabs(x[i] - k)); n       mx = max(mx, y[i] + mabs(x[i] - k)), Mp[make_pair(x[i], y[i])] = 0; n     } n   mx += m; n   for (int i = 1; i <= mx; i++) BIT.modify(i, 1); n   q.ins(n), T.dfs(1, 1, m); n   for (int i = 1; i <= m; i++) printf( %d n , ans[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long sum[2000005]; n int main() { n   long long n; n   double k; n   cin >> n >> k; n   vector<long long> v; n   for (int i = 0; i < n; i++) { n     long long a; n     cin >> a; n     v.push_back(a); n   } n   for (int i = 1; i <= n; i++) { n     sum[i] = sum[i - 1] + v[i - 1]; n   } n   double total = 0; n   int go = n - k + 1; n   for (int i = 0; i < v.size(); i++) { n     if (go + i - 1 == v.size()) { n       break; n     } n     total += (sum[go + i] - sum[i]) / (double)go; n   } n   printf( %.10llf n , total); n } n


#include <bits/stdc++.h> n using namespace std; n long long rdtsc() { n   long long tmp; n   asm( rdtsc  :  =A (tmp)); n   return tmp; n } n inline int myrand() { return abs((rand() << 15) ^ rand()); } n inline int rnd(int x) { return myrand() % x; } n const int maxn = (int)1600 + 10; n int a[maxn][maxn]; n int used[maxn][maxn]; n int maxu; n const int maxg = 4; n const int go[maxg][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}}; n int cnt; n int st[maxn * maxn][2]; n int h, w; n inline bool ok(int y, int x) { return 0 <= y && 0 <= x && y < h && x < w; } n void dfs(int y, int x) { n   used[y][x] = maxu; n   st[cnt][0] = y, st[cnt][1] = x, ++cnt; n   for (int g = 0; g < maxg; ++g) { n     int ny = y + go[g][0], nx = x + go[g][1]; n     if (!ok(ny, nx) || used[ny][nx] || !a[ny][nx]) continue; n     dfs(ny, nx); n   } n } n const int K = 6; n bool check(int y, int x) { n   int col = used[y][x]; n   for (int g = 0; g < maxg; ++g) { n     int ry = y, rx = x; n     for (int it = 0; it < K; ++it) { n       ry += go[g][0], rx += go[g][1]; n       if (!ok(ry, rx)) break; n       if (used[ry][rx] != col) return 0; n     } n   } n   return 1; n } n struct Point { n   double x, y; n   Point() {} n   Point(double _x, double _y) : x(_x), y(_y) {} n   inline Point operator-(const Point &p) const { n     return Point(x - p.x, y - p.y); n   } n   inline Point operator*(const double k) const { return Point(x * k, y * k); } n   inline double operator^(const Point &p) const { return x * p.y - y * p.x; } n   inline double operator*(const Point &p) const { return x * p.x + y * p.y; } n   inline double abs() const { return sqrt(x * x + y * y); } n }; n double value[maxn][maxn]; n const int K2 = 3; n bool solve() { n   if (scanf( %d%d , &h, &w) < 2) return 0; n   for (int i = 0; i < h; ++i) { n     for (int j = 0; j < w; ++j) { n       scanf( %d , &a[i][j]); n     } n   } n   for (int i = 0; i < h; ++i) { n     for (int j = 0; j < w; ++j) { n       used[i][j] = 0; n     } n   } n   maxu = 0; n   vector<int> ans; n   for (int i = 0; i < h; ++i) { n     for (int j = 0; j < w; ++j) { n       if (used[i][j] || !a[i][j]) continue; n       ++maxu; n       cnt = 0; n       dfs(i, j); n       assert(cnt >= 500); n       int cool = 0; n       long long sumy = 0, sumx = 0; n       for (int i = 0; i < cnt; ++i) { n         if (!check(st[i][0], st[i][1])) continue; n         ++cool; n         sumy += st[i][0], sumx += st[i][1]; n       } n       Point c(sumx, sumy); n       c = c * (1.0 / cool); n       int y = -1, x = -1; n       double maxval = -1; n       for (int i = 0; i < cnt; ++i) { n         if (!check(st[i][0], st[i][1])) continue; n         Point cur(st[i][1], st[i][0]); n         cur = cur - c; n         if (maxval < cur.abs()) maxval = cur.abs(), y = st[i][0], x = st[i][1]; n       } n       double a = maxval; n       Point dir(x, y); n       dir = dir - c; n       dir = dir * (1.0 / a); n       maxval = -1; n       for (int i = 0; i < cnt; ++i) { n         if (!check(st[i][0], st[i][1])) continue; n         Point cur(st[i][1], st[i][0]); n         cur = cur - c; n         maxval = max(maxval, abs(dir ^ cur)); n       } n       double b = maxval; n       a += K / 2, b += K / 2; n       fprintf(stderr,  a = %.3f, b = %.3f n , a, b); n       fprintf(stderr,  center : (%.3f %.3f) n , c.y, c.x); n       for (int i = 0; i < cnt; ++i) { n         Point cur(st[i][1], st[i][0]); n         cur = cur - c; n         Point real((cur * dir) / dir.abs(), (cur ^ dir) / dir.abs()); n         double coef = n             ((real.x / a) * (real.x / a)) + ((real.y / b) * (real.y / b)); n         double curValue = (real * max(0.0, (sqrt(coef) - 1.0))).abs(); n         value[st[i][0]][st[i][1]] = curValue - 5; n       } n       int res = 0; n       for (int i = 0; i < cnt; ++i) { n         int y = st[i][0], x = st[i][1]; n         if (value[y][x] < 0) continue; n         int col = used[y][x]; n         bool fail = 0; n         for (int dy = -K2; !fail && dy <= K2; ++dy) { n           for (int dx = -K2; dx <= K2; ++dx) { n             int ny = y + dy, nx = x + dx; n             if (!ok(ny, nx) || used[ny][nx] != col) continue; n             if (value[ny][nx] > value[y][x] + (1e-9)) { n               fail = 1; n               break; n             } n           } n         } n         if (!fail) { n           value[y][x] = 1e18; n           ++res; n         } n       } n       ans.push_back(res); n     } n   } n   sort(ans.begin(), ans.end()); n   printf( %d n , ((int)(ans).size())); n   for (int i = 0; i < ((int)(ans).size()); ++i) n     printf( %d%c , ans[i],    n [i == ((int)(ans).size()) - 1]); n   return 1; n } n int main() { n   srand(rdtsc()); n   while (1) { n     if (!solve()) break; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2000000 + 10; n int a[N], b[N]; n int n, m; n int main() { n   int x, y; n   scanf( %d%d , &n, &m); n   { n     for (int i = 0; i < m; i++) { n       scanf( %d%d , &x, &y); n       x--; n       y--; n       a[x]++; n       a[y]++; n     } n     for (int i = 0; i < n; i++) b[i] = n - 1 - a[i]; n     long long total = 0; n     for (int i = 0; i < n; i++) total += (long long)a[i] * b[i]; n     total /= 2; n     cout << (long long)n * (n - 1) / 2 * (n - 2) / 3 - total << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, i, m[6222000], k, a, b, x, y, sum, z, m1[5000]; n string s; n int main() { n   cin >> n; n   for (i = 0; i < n; i++) { n     cin >> m[i]; n   } n   sort(m, m + n); n   for (i = 1; i < n; i++) { n     if (m[i] == m[i - 1]) n       z++; n     else n       z = 0; n     if (z == 2) { n       cout <<  NO ; n       return 0; n     } n   } n   for (i = 1; i < n; i++) { n     if (m[i] == m[i - 1]) k++; n   } n   cout <<  YES n  << n - k << endl; n   cout << m[0] <<    ; n   for (i = 1; i < n; i++) { n     if (m[i] != m[i - 1]) cout << m[i] <<    ; n   } n   cout << endl << k << endl; n   reverse(m, m + n); n   for (i = 0; i < n - 1; i++) { n     if (m[i] == m[i + 1]) cout << m[i] <<    ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n vector<pair<int, int> > vec; n int grid1[2050], grid2[2050]; n int main() { n   int n; n   cin >> n; n   int r = 0, c = 0; n   long long ans = 0; n   for (int i = 1; i <= n; i++) { n     int x, y; n     cin >> x >> y; n     ans += grid1[x + y]; n     grid1[x + y]++; n     ans += grid2[x - y + 1000]; n     grid2[x - y + 1000]++; n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize  Ofast  n using namespace std; n const long long BIG_INF = 1e18; n const int N = 1e6 + 7; n const int T = 1 << 20; n template <class T, class G> n ostream &operator<<(ostream &os, const pair<T, G> &para) { n   os << para.first <<     << para.second; n   return os; n } n template <class T> n ostream &operator<<(ostream &os, const vector<T> &vec) { n   for (const T &el : vec) os << el <<    ; n   return os; n } n template <class T> n ostream &operator<<(ostream &os, const set<T> &vec) { n   for (const T &el : vec) os << el <<    ; n   return os; n } n template <class T> n istream &operator>>(istream &is, vector<T> &vec) { n   for (T &el : vec) is >> el; n   return is; n } n template <class T, class G> n istream &operator>>(istream &os, pair<T, G> &para) { n   os >> para.first >> para.second; n   return os; n } n template <class T> n void setmax(T &a, T b) { n   a = (a >= b ? a : b); n } n template <class T> n void setmin(T &a, T b) { n   a = (a <= b ? a : b); n } n mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); n std::vector<int> zet(const std::string &w) { n   int n = (int)w.size(); n   std::vector<int> p(n); n   int j = 0; n   for (int i = 1; i < n; ++i) { n     p[i] = std::max(std::min(p[j] + j - i, p[i - j]), 0); n     while (p[i] + i < n && w[p[i]] == w[p[i] + i]) p[j = i]++; n   } n   return p; n } n void solve() { n   int n; n   cin >> n; n   string second; n   cin >> second; n   vector<vector<int> > zzz; n   vector<int> dp(n); n   for (int i = 0; i < n; i++) { n     string temp = second.substr(i); n     zzz.push_back(zet(temp)); n     int dl_suf = n - i; n     dp[i] = dl_suf; n     for (int j = 0; j < i; j++) { n       int dl_wsp = zzz[j][i - j]; n       if (dl_wsp < dl_suf and second[j + dl_wsp] < second[i + dl_wsp]) n         setmax(dp[i], dp[j] + dl_suf - dl_wsp); n     } n   } n   int ans = 0; n   for (auto &u : dp) setmax(ans, u); n   cout << ans <<   n ; n } n signed main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   int test = 1; n   cin >> test; n   for (int i = 1; i <= test; i++) solve(); n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 2e5 + 10; n set<int> adj[maxn * 2 + 20]; n int ans[maxn], n; n vector<int> ans_eu; n map<pair<int, int>, int> mp; n void find_eu(int v) { n   while (adj[v].size()) { n     int tmp = *adj[v].begin(); n     adj[v].erase(tmp); n     adj[tmp].erase(v); n     find_eu(tmp); n   } n   ans_eu.push_back(v); n } n void solve() { n   for (int i = 1, tmp = maxn * 2 + 9; i < maxn * 2 + 10; i++) n     if (adj[i].size() % 2 == 1) adj[tmp].insert(i), adj[i].insert(tmp); n   for (int i = maxn * 2 + 9; i > 0; i--) { n     if (adj[i].size()) { n       ans_eu.clear(); n       find_eu(i); n       for (int j = 1; j < ans_eu.size(); j++) n         if (max(ans_eu[j], ans_eu[j - 1]) != maxn * 2 + 9) n           ans[mp[{ans_eu[j], ans_eu[j - 1]}]] = j % 2; n     } n   } n   for (int i = 1; i <= n; i++) cout << (ans[i] ?  r  :  b ); n   cout << endl; n } n int main() { n   cin >> n; n   for (int i = 1, x, y; i <= n; i++) { n     cin >> x >> y; n     adj[x].insert(y + maxn); n     adj[y + maxn].insert(x); n     mp[{x, y + maxn}] = mp[{y + maxn, x}] = i; n   } n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(0), cin.tie(0); n   int T; n   cin >> T; n   while (T--) { n     long long p, q; n     cin >> p >> q; n     long long ans = -1; n     for (long long i = 1; i * i <= q; ++i) { n       long long pp = p; n       if (q % i == 0) { n         while (i != 1 and pp % q == 0 and pp % i == 0) { n           pp /= i; n         } n         long long ppp = p; n         while (ppp % q == 0 and ppp % (q / i) == 0) { n           ppp /= (q / i); n         } n         if (ppp % q != 0) ans = max(ans, ppp); n       } n       if (pp % q != 0) ans = max(ans, pp); n     } n     assert(ans != -1); n     cout << ans <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n const int N = 100001; n int Pri[200005]; n int NN, Cnt[100005], Mac[100005]; n bool Use[200005]; n void GetPrimeList() { n   int TmpN = sqrt(N); n   for (int i = 2; i <= N; ++i) Use[i] = true; n   for (int i = 2; i <= N; ++i) { n     if (Use[i]) Pri[++Pri[0]] = i; n     for (int j = 1; j <= Pri[0] && i * Pri[j] <= N; ++j) { n       Use[i * Pri[j]] = false; n       if (i % Pri[j] == 0) break; n     } n     if (i <= TmpN) NN = Pri[0]; n   } n   ++NN; n   for (int i = 1; i <= N; ++i) Use[i] = false; n } n int Add(int x) { n   int t = x; n   for (int i = 1; i <= NN; ++i) n     if (t % Pri[i] == 0) { n       if (Cnt[Pri[i]] != 0) return Mac[Pri[i]]; n       for (; t % Pri[i] == 0; t /= Pri[i]) n         ; n     } n   if (t != 1 && Cnt[t] != 0) return Mac[t]; n   t = x; n   for (int i = 1; i <= NN; ++i) n     if (t % Pri[i] == 0) { n       ++Cnt[Pri[i]]; n       Mac[Pri[i]] = x; n       for (; t % Pri[i] == 0; t /= Pri[i]) n         ; n     } n   if (t != 1) { n     ++Cnt[t]; n     Mac[t] = x; n   } n   Use[x] = true; n   return -1; n } n void Del(int x) { n   int t = x; n   for (int i = 1, j, k; i <= NN; ++i) n     if (t % Pri[i] == 0) { n       --Cnt[Pri[i]]; n       Mac[Pri[i]] = 0; n       for (; t % Pri[i] == 0; t /= Pri[i]) n         ; n     } n   if (t != 1) { n     --Cnt[t]; n     Mac[t] = 0; n   } n   Use[x] = false; n } n int main() { n   GetPrimeList(); n   int n, m, num; n   char op; n   scanf( %d %d n , &n, &m); n   for (int i = 1, ret; i <= m; ++i) { n     scanf( %c %d n , &op, &num); n     if (op ==  + ) { n       if (Use[num]) n         puts( Already on ); n       else { n         ret = Add(num); n         if (ret == -1) n           puts( Success ); n         else n           printf( Conflict with %d n , ret); n       } n     } else { n       if (!Use[num]) n         puts( Already off ); n       else { n         Del(num); n         puts( Success ); n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n const int MAXN = 2e5 + 7; n struct Edge { n   int t, next; n } edge[MAXN << 1]; n int head[MAXN], cnt; n std::pair<int, int> p[MAXN]; n int color[MAXN]; n int n; n void add(int u, int v) { n   edge[++cnt] = (Edge){v, head[u]}; n   head[u] = cnt; n } n void dfs(int u, int col) { n   if (color[u] != -1) return; n   color[u] = col; n   for (int e = head[u]; e; e = edge[e].next) { n     int v = edge[e].t; n     dfs(v, col ^ 1); n   } n } n int main(int argc, char *argv[]) { n   memset(color, -1, sizeof color); n   scanf( %d , &n); n   int l, r; n   for (int i = 0; i < n; i++) { n     scanf( %d %d , &l, &r); n     add(i << 1, i << 1 | 1); n     add(i << 1 | 1, i << 1); n     p[i << 1] = std::make_pair(l, i << 1); n     p[i << 1 | 1] = std::make_pair(r + 1, i << 1 | 1); n   } n   std::sort(p, p + 2 * n); n   for (int i = 0; i < n; i++) { n     int u = p[i << 1].second, v = p[i << 1 | 1].second; n     add(u, v), add(v, u); n   } n   for (int i = 0; i < n; i++) { n     if (color[i << 1] == -1) dfs(i << 1, 0); n     printf( %d  , color[i << 1]); n   } n   puts(  ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename A, typename B> n inline void chmin(A &a, B b) { n   if (a > b) a = b; n } n template <typename A, typename B> n inline void chmax(A &a, B b) { n   if (a < b) a = b; n } n template <class A, class B> n ostream &operator<<(ostream &ost, const pair<A, B> &p) { n   ost <<  {  << p.first <<  ,  << p.second <<  } ; n   return ost; n } n template <class T> n ostream &operator<<(ostream &ost, const vector<T> &v) { n   ost <<  { ; n   for (long long i = 0; i < v.size(); i++) { n     if (i) ost <<  , ; n     ost << v[i]; n   } n   ost <<  } ; n   return ost; n } n template <class T> n vector<long long> zalgorithm(T s) { n   vector<long long> a(s.size()); n   a[0] = s.size(); n   long long i = 1, j = 0; n   while (i < s.size()) { n     while (i + j < s.size() && s[j] == s[i + j]) j++; n     a[i] = j; n     if (j == 0) { n       i++; n       continue; n     } n     long long k = 1; n     while (i + k < s.size() && k + a[k] < j) a[i + k] = a[k], k++; n     i += k; n     j -= k; n   } n   return a; n } n long long N, K, M; n vector<long long> calcPre(const string &s, const string &p) { n   string X = s + p; n   vector<long long> z = zalgorithm(X); n   vector<long long> a(p.size() + 1); n   for (long long i = 1; i <= p.size(); i++) { n     if (z[X.size() - i] == i) a[i] = 1; n   } n   return a; n } n vector<long long> calcSuf(const string &s, const string &p) { n   string X = p + s; n   vector<long long> z = zalgorithm(X); n   vector<long long> a(p.size() + 1); n   for (long long i = 1; i <= p.size(); i++) { n     if (z[X.size() - i] == i) a[i] = 1; n   } n   return a; n } n long long calcOcc(const string &s, const string &p) { n   string X = p + s; n   vector<long long> z = zalgorithm(X); n   long long ret = 0; n   for (long long i = 0; i < s.size(); i++) n     if (z[p.size() + i] >= p.size()) ret++; n   return ret; n } n long long mrg(const vector<long long> &a, const vector<long long> &b) { n   long long cnt = 0; n   for (long long i = 0; i < a.size(); i++) n     if (a[i] && b[b.size() - 1 - i]) cnt++; n   return cnt; n } n vector<long long> pre[222], suf[222]; n long long occ[222]; n vector<string> first; n void calc(string s) { n   long long t; n   if (N <= 1) { n     t = 0; n   } else { n     t = 2; n     while (first[t].size() < s.size()) t++; n   } n   for (long long k = 0; k < (2); k++) { n     pre[t + k] = calcPre(first[t + k], s); n     suf[t + k] = calcSuf(first[t + k], s); n     occ[t + k] = calcOcc(first[t + k], s); n     chmin(occ[t + k], K + 1); n   } n   long long BC = mrg(suf[t], pre[t + 1]); n   long long BA = mrg(suf[t], pre[t]); n   for (long long i = t + 2; i <= N; i++) { n     occ[i] = occ[i - 1] + occ[i - 2] + BC; n     chmin(occ[i], K + 1); n     swap(pre[i], pre[i - 2]); n     swap(suf[i], suf[i - 2]); n     swap(BC, BA); n   } n } n signed main() { n   first.push_back( 0 ); n   first.push_back( 1 ); n   while (first.back().size() < 10000) { n     first.push_back(first[first.size() - 2] + first[first.size() - 1]); n   } n   cin >> N >> K >> M; n   K--; n   string ans; n   for (long long i = 0; i < M; i++) { n     if (i) { n       if (suf[N][ans.size()]) { n         if (K == 0) break; n         K--; n       } n     } n     calc(ans +  0 ); n     long long tmp = occ[N]; n     if (tmp <= K) { n       K -= tmp; n       ans +=  1 ; n       calc(ans); n     } else { n       ans +=  0 ; n     } n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> v, w; n int m; n long long int f(int d, int target) { n   long long int timeSpent = 0; n   long long int totDone = 0; n   long long int koytaDone = 0; n   long long int lastSpent = 0; n   for (int i = 0; i < v.size(); i++) { n     if (v[i] <= d) { n       timeSpent += v[i]; n       lastSpent += v[i]; n       koytaDone++; n       totDone++; n       if (totDone == target) return timeSpent; n     } n     if (koytaDone == m) { n       koytaDone = 0; n       timeSpent += lastSpent; n       lastSpent = 0; n     } n   } n   return LLONG_MAX / 3; n } n int main() { n   int t, n, inp; n   long long int tot; n   scanf( %d , &t); n   while (t--) { n     v.clear(); n     w.clear(); n     scanf( %d %d , &n, &m); n     cin >> tot; n     while (n--) { n       scanf( %d , &inp); n       v.push_back(inp); n       w.push_back(inp); n     } n     sort(w.begin(), w.end()); n     int lo = 1, hi = w.size(), ans = 0, ans_d = 1; n     while (lo <= hi) { n       int mid = (lo + hi) / 2; n       int tem_d = w[mid - 1]; n       if (f(tem_d, mid) <= tot) { n         ans = mid; n         ans_d = tem_d; n         lo = mid + 1; n       } else n         hi = mid - 1; n     } n     cout << ans <<     << ans_d <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int dp[1123456], p[1123456]; n int main() { n   int n, i, j; n   scanf( %d , &n); n   for (i = 0; i < n; ++i) { n     scanf( %d , &j); n     p[j] = i; n   } n   dp[1] = 1; n   int ans = 1; n   for (i = 2; i <= n; ++i) { n     if (p[i] > p[i - 1]) { n       dp[i] = 1 + dp[i - 1]; n     } else { n       dp[i] = 1; n     } n     ans = max(ans, dp[i]); n   } n   cout << n - ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int ans[1005]; n void calc() { n   int i, j; n   for (i = 2; i < 1000; i++) { n     if (ans[i] == 0) { n       ans[i] = 1; n       int k = i; n       for (j = 2; j <= 10; j++) { n         if (k * i < 1000) { n           ans[k * i] = 1; n           k = k * i; n         } else n           break; n       } n       for (j = i + i; j <= 1002; j += i) { n         if (!ans[j]) ans[j] = -1; n       } n     } n   } n } n int main() { n   calc(); n   int n, i; n   cin >> n; n   if (n == 1) { n     cout << 0; n     return 0; n   } n   vector<int> v; n   for (i = 2; i <= n; i++) { n     if (ans[i] == 1) v.push_back(i); n   } n   cout << v.size() << endl; n   for (i = 0; i < v.size(); i++) { n     cout << v[i] <<    ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long MOD = 1e9 + 7; n const long long INF = 1e9 + 9; n const long long N = 500500; n signed main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   long long T; n   cin >> T; n   while (T--) { n     long long n, ans = 0, mx; n     cin >> n; n     for (long long b = 0; b <= 6; b++) { n       vector<long long> x, y; n       for (long long i = 1; i <= n; i++) { n         if (i & (1 << b)) { n           x.push_back(i); n         } else n           y.push_back(i); n       } n       if (x.size() == 0 || y.size() == 0) continue; n       cout << x.size() <<     << y.size() <<    ; n       for (auto z : x) cout << z <<    ; n       for (auto z : y) cout << z <<    ; n       cout << endl; n       cin >> mx; n       ans = max(ans, mx); n     } n     cout <<  -1   << ans << endl; n     cout.flush(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct edge { n   int v, w; n   edge() {} n   edge(int V, int W) { v = V, w = W; } n }; n struct node { n   long long x, y, z; n   node() {} n   node(long long X, long long Y, long long Z) { x = X, y = Y, z = Z; } n } p[100005]; n vector<edge> G[100005]; n int n; n long long f1[100005], f2[100005], Size[100005]; n bool cmp(node u, node v) { return v.x * u.y < u.x * v.y; } n void dfs(int u, int fa) { n   Size[u]++; n   for (int i = 0; i < G[u].size(); i++) { n     int v = G[u][i].v; n     if (v == fa) continue; n     dfs(v, u); n     Size[u] += Size[v], f1[u] += f1[v]; n   } n   int len = 0; n   for (int i = 0; i < G[u].size(); i++) { n     int v = G[u][i].v, w = G[u][i].w; n     if (v == fa) continue; n     p[++len] = node(Size[v], f2[v] + (w << 1), w); n   } n   sort(p + 1, p + len + 1, cmp); n   for (int i = 1; i <= len; i++) n     f1[u] += (p[i].z + f2[u]) * p[i].x, f2[u] += p[i].y; n } n int main() { n   scanf( %d , &n); n   for (int i = 1, u, v, w; i < n; i++) { n     scanf( %d %d %d , &u, &v, &w); n     G[u].push_back(edge(v, w)); n     G[v].push_back(edge(u, w)); n   } n   dfs(1, 0); n   printf( %.8f , f1[1] * 1.0 / (n - 1)); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = (int)1e6 + 5; n const int mod = (int)1e9 + 7; n string a; n int x, n; n int u[N]; n int main() { n   ios_base::sync_with_stdio(false); n   cin >> a; n   cin >> n; n   for (int i = 1; i <= n; i++) { n     cin >> x; n     u[x]++; n   } n   for (int i = 1; i <= a.size() / 2; i++) u[i] += u[i - 1]; n   for (int i = 0; i < a.size(); i++) { n     if (u[i + 1] & 1) swap(a[i], a[a.size() - i - 1]); n   } n   cout << a << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct masivs { n   long long in; n   long long out; n   long long poz; n }; n masivs mas[100005]; n long long i, j, k, n, m, a, b, c; n vector<pair<pair<long long, long long>, long long> > ab; n int main() { n   std::cin.sync_with_stdio(false); n   std::cin.tie(0); n   cin >> n >> m; n   i = 0; n   while (i < n) { n     mas[i].poz = i; n     i++; n   } n   i = 0; n   while (i < m) { n     cin >> a >> b >> c; n     a--; n     b--; n     mas[a].in += c; n     mas[b].out += c; n     k = min(mas[a].in, mas[a].out); n     mas[a].in -= k; n     mas[a].out -= k; n     k = min(mas[b].in, mas[b].out); n     mas[b].in -= k; n     mas[b].out -= k; n     i++; n   } n   j = 0; n   i = 0; n   while (i < n) { n     while (mas[i].in) { n       while (mas[j].out == 0) { n         j++; n       } n       k = min(mas[i].in, mas[j].out); n       ab.push_back({{i + 1, j + 1}, k}); n       mas[i].in -= k; n       mas[j].out -= k; n     } n     i++; n   } n   cout << ab.size() <<   n ; n   for (j = 0; j < ab.size(); j++) { n     cout << ab[j].first.first <<     << ab[j].first.second <<     n          << ab[j].second <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n const int MAX_N = 5e2 + 5; n int n, f[MAX_N][MAX_N], g[MAX_N]; n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; ++i) scanf( %d , &f[i][i]); n   for (int l = 1; l < n; ++l) n     for (int i = 1; i + l <= n; ++i) n       for (int j = i; j < i + l; ++j) n         if (f[i][j] && f[i][j] == f[j + 1][i + l]) f[i][i + l] = f[i][j] + 1; n   for (int i = 1; i <= n; ++i) { n     g[i] = i; n     for (int j = 1; j <= i; ++j) n       if (f[j][i]) g[i] = std::min(g[i], g[j - 1] + 1); n   } n   printf( %d n , g[n]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 400005; n int n, m, h[N], p[N]; n set<int> S; n set<int>::iterator it; n inline void read(int &i) { n   i = 0; n   char c = getchar(); n   bool j = 0; n   for (; !isdigit(c); c = getchar()) n     if (c ==  - ) j = 1; n   for (; isdigit(c); c = getchar()) i = (i << 1) + (i << 3) + c -  0 ; n   i = j ? -i : i; n } n struct Segment_Tree { n   int sz, mx[N << 2]; n   inline void mdf(int u, int l, int r, int x, int y) { n     if (l == r) { n       mx[u] = y; n       return; n     } n     int mid = (l + r) >> 1; n     if (x <= mid) n       mdf(u << 1, l, mid, x, y); n     else n       mdf(u << 1 | 1, mid + 1, r, x, y); n     mx[u] = max(mx[u << 1], mx[u << 1 | 1]); n   } n   inline int qry(int u, int l, int r, int L, int R) { n     if (L <= l && r <= R) return mx[u]; n     int mid = (l + r) >> 1, as = 0; n     if (L <= mid) as = max(as, qry(u << 1, l, mid, L, R)); n     if (mid < R) as = max(as, qry(u << 1 | 1, mid + 1, r, L, R)); n     return as; n   } n   inline void mdf(int x, int y) { mdf(1, 0, sz, x, y); } n   inline int qry(int l, int r) { return qry(1, 0, sz, l, r); } n } A, B; n int main() { n   read(n); n   read(m); n   A.sz = n + 100; n   B.sz = m + 200; n   int op, x, y; n   for (int tim = 1; tim <= m; ++tim) { n     read(op), read(x); n     if (op == 1) { n       x = n + 1 - x; n       read(y); n       y = tim + 10 - y; n       p[y] = x; n       h[x] = y; n       S.insert(x); n       for (int i = y + 1; i <= y + 9; ++i) n         if (p[i]) A.mdf(p[i], 0); n       for (int i = y; i <= y + 9; ++i) n         if (p[i]) { n           int f = A.qry(0, p[i] - 1) + 1; n           A.mdf(p[i], f); n           B.mdf(i, f); n         } n     } else { n       it = S.end(); n       while (x--) it--, B.mdf(h[*it], 0); n       int del = *it; n       A.mdf(*it, 0); n       it++; n       for (; it != S.end(); it++) { n         int f = B.qry(0, h[*it] - 1) + 1; n         B.mdf(h[*it], f); n         A.mdf(*it, f); n       } n       S.erase(del); n       p[h[del]] = 0; n       h[del] = 0; n     } n     printf( %d n , A.qry(1, n)); n   } n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( Ofast ) n #pragma GCC target( avx,avx2,fma ) n #pragma GCC optimization( unroll-loops ) n using namespace std; n const int maxn = 1e4 + 5; n set<string> st3; n int dp[maxn][4]; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   string s1, sx, sy, sz; n   cin >> s1; n   int len = s1.size(); n   if (len <= 6) n     cout << 0 << endl; n   else { n     if (len >= 7) { n       dp[len - 2][2] = 1; n       sx =   ; n       sx = sx + s1[len - 2] + s1[len - 1]; n       st3.insert(sx); n     } n     if (len >= 8) { n       dp[len - 3][3] = 1; n       sx =   ; n       sx = sx + s1[len - 3] + s1[len - 2] + s1[len - 1]; n       st3.insert(sx); n     } n     for (int i = len - 4; i >= 5; i--) { n       sx =   ; n       sy =   ; n       sx = sx + s1[i] + s1[i + 1]; n       sy = sy + s1[i + 2] + s1[i + 3]; n       if ((sx != sy && dp[i + 2][2]) || dp[i + 2][3]) { n         dp[i][2] = 1; n         st3.insert(sx); n       } n       sx =   ; n       sy =   ; n       sx = sx + s1[i] + s1[i + 1] + s1[i + 2]; n       sy = sy + s1[i + 3] + s1[i + 4] + s1[i + 5]; n       if ((sx != sy && dp[i + 3][3]) || dp[i + 3][2]) { n         dp[i][3] = 1; n         st3.insert(sx); n       } n     } n     cout << st3.size() << endl; n     for (auto& it : st3) cout << it << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int k, c, fact[10010], refact[10010]; n int POW(int a, int b) { n   int res; n   for (res = 1; b; (b & 1) && (res = 1LL * res * a % 1000000007), n       a = 1LL * a * a % 1000000007, b >>= 1) n     ; n   return res; n } n int C(int n, int m) { n   if (m > n) return 0; n   return 1LL * fact[n] * refact[m] % 1000000007 * refact[n - m] % 1000000007; n } n void Init() { n   fact[0] = refact[0] = 1; n   for (int i = 1; i <= 1010; ++i) { n     fact[i] = 1LL * fact[i - 1] * i % 1000000007; n     refact[i] = POW(fact[i], 1000000007 - 2); n   } n } n void Work() { n   int i, cnt, ans = 1; n   scanf( %d%d , &k, &cnt); n   for (i = 2; i <= k; ++i) { n     scanf( %d , &c); n     ans = 1LL * ans * C(cnt + c - 1, cnt) % 1000000007; n     cnt += c; n   } n   printf( %d n , ans); n } n int main() { n   Init(); n   Work(); n   return 0; n } n


#include <bits/stdc++.h> n const int MAXNUM = 255000; n int n; n int m; n int ecnt; n int a[MAXNUM]; n int b[MAXNUM]; n int inflow[MAXNUM]; n int outflow[MAXNUM], direct[MAXNUM]; n int head[MAXNUM], to[MAXNUM * 2], next[MAXNUM * 2], c[MAXNUM * 2], n     from[MAXNUM * 2]; n inline int readint() { n   char c = getchar(); n   while (!isdigit(c)) c = getchar(); n   int x = 0; n   while (isdigit(c)) { n     x = x * 10 + c -  0 ; n     c = getchar(); n   } n   return x; n } n inline void addEdge(int &u, int &v, int &i) { n   int x = readint(); n   outflow[u] += x; n   outflow[v] += x; n   to[ecnt] = v; n   c[ecnt] = x; n   from[ecnt] = i; n   next[ecnt] = head[u]; n   head[u] = ecnt++; n   to[ecnt] = u; n   c[ecnt] = x; n   from[ecnt] = i; n   next[ecnt] = head[v]; n   head[v] = ecnt++; n } n void makeDirect() { n   std::stack<int> st; n   st.push(1); n   outflow[1] = 0; n   while (!st.empty()) { n     int u = st.top(); n     st.pop(); n     for (int p = head[u]; p; p = next[p]) { n       int &v = to[p]; n       if (inflow[v] == outflow[v] && v != n) continue; n       inflow[v] += c[p]; n       outflow[v] -= c[p]; n       if (inflow[v] == outflow[v] && v != n) st.push(v); n       int x = from[p]; n       if (v == a[x]) direct[x] = 1; n     } n   } n } n int main() { n   scanf( %d%d , &n, &m); n   ecnt = 1; n   for (int i = 0; i < m; ++i) { n     a[i] = readint(); n     b[i] = readint(); n     addEdge(a[i], b[i], i); n   } n   makeDirect(); n   for (int i = 0; i < m; ++i) printf( %d n , direct[i]); n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:100000000 ) n using namespace std; n vector<vector<int> > g; n vector<int> cl; n int q = 0; n int n; n void dfs(int v) { n   cl[v] = q; n   if (cl[g[v][0]] == 0) dfs(g[v][0]); n } n void swap(int i, int j) { n   g[i][0] = g[j][0] + g[i][0]; n   g[j][0] = g[i][0] - g[j][0]; n   g[i][0] = g[i][0] - g[j][0]; n } n int calc() { n   int ans = 0; n   vector<int> t; n   t.resize(q + 1, 0); n   for (int i = 0; i < n; i++) t[cl[i]]++; n   for (int i = 1; i <= q; i++) { n     ans += t[i] - 1; n   } n   return ans; n } n int main() { n   cin >> n; n   g.resize(n); n   cl.assign(n, 0); n   int t; n   for (int i = 0; i < n; i++) { n     cin >> t; n     g[i].push_back(t - 1); n   } n   int m; n   cin >> m; n   for (int i = 0; i < n; i++) { n     if (cl[i] == 0) { n       q++; n       dfs(i); n     } n   } n   int w = calc(); n   if (m == w) { n     cout << 0; n   } n   if (m > w) { n     cout << m - w <<   n ; n     for (int i = 0; i < m - w; i++) { n       int v1 = 0, v2 = 1; n       while (cl[v1] == cl[v2]) v2++; n       cout << v1 + 1 <<     << v2 + 1 <<    ; n       swap(v1, v2); n       q = 0; n       cl.assign(n, 0); n       for (int i = 0; i < n; i++) { n         if (cl[i] == 0) { n           q++; n           dfs(i); n         } n       } n     } n   } n   if (m < w) { n     cout << w - m <<   n ; n     for (int i = 0; i < w - m; i++) { n       int v1 = 0, v2 = 0; n       while (g[v1][0] == v1) v1++; n       while (cl[v1] != cl[v2] || v1 == v2) v2++; n       cout << v1 + 1 <<     << v2 + 1 <<    ; n       swap(v1, v2); n       q = 0; n       cl.assign(n, 0); n       for (int i = 0; i < n; i++) { n         if (cl[i] == 0) { n           q++; n           dfs(i); n         } n       } n     } n   } n } n


#include <bits/stdc++.h> n void rep(const char *s, int x) { n   for (int i = 1; i <= x; i++) printf( %s , s); n } n void leading0() { n   putchar( 1 ); n   putchar( r ); n   rep( 0srt , 30); n   rep( lst , 30); n   putchar( l ); n   putchar( e ); n } n int main() { n   printf( r0l ); n   rep( l , 31); n   leading0(); n   putchar( u ); n   leading0(); n   putchar( u ); n   putchar( u ); n   putchar( u ); n   rep( r1 , 31); n   putchar( d ); n   putchar( d ); n   putchar( d ); n   rep( d , 3); n   rep( 1l , 31); n   putchar( u ); n   rep( re , 31); n   rep( u , 3); n   for (int j = 1; j <= 31; j++) { n     printf( edsddduuutttt1d0uuudst0 ); n     putchar( u ); n     rep( ust , 3); n     if (j > 1) { n       printf( dddd10utu10rtdr10ltled1uuuu ); n       printf( edsddduuutttt1d0uuudst0 ); n       putchar( u ); n       rep( ust , 3); n       printf( dddr01dtl1rt ); n       printf( uu ); n       putchar( l ); n     } else { n       putchar( l ); n       putchar( d ); n     } n   } n   putchar( d ); n   putchar( r ); n } n


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


#include <bits/stdc++.h> n using namespace std; n int dp[255][105][105]; n int c[255][255]; n int cc[1005]; n int N; n string s; n int f(char l, int i, int k) { n   if (i == N) return 0; n   if (dp[l][i][k] != -1) return dp[l][i][k]; n   int r = f(s[i], i + 1, k) + c[l][s[i]]; n   if (k) { n     for (char x =  a ; x <=  z ; x++) r = max(r, f(x, i + 1, k - 1) + c[l][x]); n   } n   return dp[l][i][k] = r; n } n int main() { n   int k, m; n   char x, y; n   int z; n   cin >> s >> k >> m; n   N = s.size(); n   for (int i = 0; i < m; i++) { n     cin >> x >> y >> z; n     c[x][y] = z; n   } n   memset(dp, -1, sizeof(dp)); n   cout << f( # , 0, k) << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int32_t main() { n   ios_base::sync_with_stdio(false); n   long long n, m, k; n   cin >> n >> m >> k; n   long long l = 1, r = 1e9 + 1; n   while (r - l > 1) { n     long long mid = (l + r) / 2; n     long long ans = mid; n     if (k >= mid) ans += ((mid - 1) * mid) / 2; n     if (k > mid) ans += k - mid; n     if (k < mid) n       ans += (((mid - 1) + (k - mid)) * ((mid - 1) - (k - mid) + 1)) / 2; n     long long t = n - k + 1; n     if (t >= mid) ans += ((mid - 1) * mid) / 2; n     if (t > mid) ans += t - mid; n     if (t < mid) n       ans += (((mid - 1) + (t - mid)) * ((mid - 1) - (t - mid) + 1)) / 2; n     if (ans > m) n       r = mid; n     else n       l = mid; n   } n   cout << l << endl; n } n


#include <bits/stdc++.h> n using namespace std; n template <class Flow = int, class Cost = int> n struct MinCostFlow { n   const Flow INF_FLOW = 1000111000; n   const Cost INF_COST = 1000111000111000LL; n   int n, t, S, T; n   Flow totalFlow; n   Cost totalCost; n   vector<int> last, visited; n   vector<Cost> dis; n   struct Edge { n     int to; n     Flow cap; n     Cost cost; n     int next; n     Edge(int to, Flow cap, Cost cost, int next) n         : to(to), cap(cap), cost(cost), next(next) {} n   }; n   vector<Edge> edges; n   MinCostFlow(int n) n       : n(n), n         t(0), n         totalFlow(0), n         totalCost(0), n         last(n, -1), n         visited(n, 0), n         dis(n, 0) { n     edges.clear(); n   } n   int addEdge(int from, int to, Flow cap, Cost cost) { n     edges.push_back(Edge(to, cap, cost, last[from])); n     last[from] = t++; n     edges.push_back(Edge(from, 0, -cost, last[to])); n     last[to] = t++; n     return t - 2; n   } n   pair<Flow, Cost> minCostFlow(int _S, int _T) { n     S = _S; n     T = _T; n     SPFA(); n     while (1) { n       while (1) { n         for (int i = 0; i < n; i++) visited[i] = 0; n         if (!findFlow(S, INF_FLOW)) break; n       } n       if (!modifyLabel()) break; n     } n     return make_pair(totalFlow, totalCost); n   } n  n  private: n   void SPFA() { n     for (int i = 0; i < n; i++) dis[i] = INF_COST; n     priority_queue<pair<Cost, int> > Q; n     Q.push(make_pair(dis[S] = 0, S)); n     while (!Q.empty()) { n       int x = Q.top().second; n       Cost d = -Q.top().first; n       Q.pop(); n       if (dis[x] != d) continue; n       for (int it = last[x]; it >= 0; it = edges[it].next) n         if (edges[it].cap > 0 && dis[edges[it].to] > d + edges[it].cost) n           Q.push(make_pair(-(dis[edges[it].to] = d + edges[it].cost), n                            edges[it].to)); n     } n     Cost disT = dis[T]; n     for (int i = 0; i < n; i++) dis[i] = disT - dis[i]; n   } n   Flow findFlow(int x, Flow flow) { n     if (x == T) { n       totalCost += dis[S] * flow; n       totalFlow += flow; n       return flow; n     } n     visited[x] = 1; n     Flow now = flow; n     for (int it = last[x]; it >= 0; it = edges[it].next) n       if (edges[it].cap && !visited[edges[it].to] && n           dis[edges[it].to] + edges[it].cost == dis[x]) { n         Flow tmp = findFlow(edges[it].to, min(now, edges[it].cap)); n         edges[it].cap -= tmp; n         edges[it ^ 1].cap += tmp; n         now -= tmp; n         if (!now) break; n       } n     return flow - now; n   } n   bool modifyLabel() { n     Cost d = INF_COST; n     for (int i = 0; i < n; i++) n       if (visited[i]) n         for (int it = last[i]; it >= 0; it = edges[it].next) n           if (edges[it].cap && !visited[edges[it].to]) n             d = min(d, dis[edges[it].to] + edges[it].cost - dis[i]); n     if (d == INF_COST) return false; n     for (int i = 0; i < n; i++) n       if (visited[i]) dis[i] += d; n     return true; n   } n }; n int main() { n   int n; n   scanf( %d , &n); n   int a[n]; n   for (int i = 0; i < n; i++) scanf( %d , &a[i]); n   MinCostFlow<int, long long> mcf(3 * (n + 2)); n   mcf.addEdge(0, 1, 4, 0); n   mcf.addEdge(3 * (n + 1), 3 * (n + 1) + 1, 4, 0); n   for (int i = 0; i < n; i++) { n     mcf.addEdge(1, (i + 1) * 3, 1, 0); n     mcf.addEdge((i + 1) * 3, (i + 1) * 3 + 1, 1, -1); n     mcf.addEdge((i + 1) * 3 + 2, (i + 1) * 3, 1, 0); n     mcf.addEdge((i + 1) * 3 + 1, (n + 1) * 3, 1, 0); n     int u, d, l; n     u = d = l = 0; n     for (int j = i + 1; j < n; j++) { n       if (a[j] + 1 == a[i] && d < 4) { n         mcf.addEdge(3 * (i + 1) + 1, 3 * (j + 1), 1, 0); n         d++; n       } else if (a[j] - 1 == a[i] && u < 4) { n         mcf.addEdge(3 * (i + 1) + 1, 3 * (j + 1), 1, 0); n         u++; n       } else if (!((a[i] - a[j]) % 7) && !l) { n         mcf.addEdge(3 * (i + 1) + 1, 3 * (j + 1) + 2, 1, 0); n         mcf.addEdge(3 * (i + 1) + 2, 3 * (j + 1) + 2, 1, 0); n         l = 1; n       } n     } n   } n   pair<int, int> mcmf = mcf.minCostFlow(0, 3 * (n + 1) + 1); n   if (mcmf.first == 4) n     cout << -mcmf.second << endl; n   else n     cout << 0 << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX = 1e6 + 6; n vector<int> adj[MAX]; n bool visited[MAX]; n void dfs(int source, int &nodes, int &total) { n   total += adj[source].size(); n   visited[source] = true; n   nodes++; n   for (auto &each : adj[source]) { n     if (!visited[each]) { n       dfs(each, nodes, total); n     } n   } n } n int main() { n   int n, m; n   scanf( %d %d , &n, &m); n   for (int i = int(0); i < int(m); i++) { n     int a, b; n     scanf( %d %d , &a, &b); n     adj[a].push_back(b); n     adj[b].push_back(a); n   } n   for (int i = int(1); i < int(n + 1); i++) { n     if (!visited[i]) { n       int total = 0; n       int nodes = 0; n       dfs(i, nodes, total); n       if (total != (1LL * nodes * (nodes - 1))) { n         puts( NO ); n         return 0; n       } n     } n   } n   puts( YES ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long int M = 1e9 + 7; n long long int M1 = 998244353; n long long int dr[8] = {-1, 0, 0, 1, -1, -1, 1, 1}; n long long int dc[8] = {0, 1, -1, 0, -1, 1, -1, 1}; n long long int gcd(long long int a, long long int b) { n   if (b == 0) return a; n   return gcd(b, a % b); n } n long long int lcm(long long int a, long long int b) { n   return a * b / gcd(a, b); n } n void setdecimals(long long int x) { cout << fixed << setprecision((int)x); } n long long int setbits(long long int x) { n   long long int c = __builtin_popcountll(x); n   return c; n } n long long int stoi(string &s) { n   long long int c = 0; n   for (auto i : s) c = c * 10 + i -  0 ; n   return c; n } n void print(long long int a) { cerr << a; } n void print(char a) { cerr << a; } n void print(string a) { cerr << a; } n void print(bool a) { cerr << a; } n void print(double a) { cerr << a; } n void print(float a) { cerr << a; } n template <class T, class X> n void print(pair<T, X> p); n template <class T> n void print(vector<T> v); n template <class T> n void print(set<T> v); n template <class T, class X> n void print(map<T, X> v); n template <class T> n void print(multiset<T> v); n template <class T, class X> n void print(pair<T, X> p) { n   cerr <<  { ; n   print(p.first); n   cerr <<  , ; n   print(p.second); n   cerr <<  } ; n } n template <class T> n void print(vector<T> v) { n   cerr <<  [  ; n   for (T i : v) { n     print(i); n     cerr <<    ; n   } n   cerr <<  ] ; n } n template <class T> n void print(set<T> v) { n   cerr <<  [  ; n   for (T i : v) { n     print(i); n     cerr <<    ; n   } n   cerr <<  ] ; n } n template <class T> n void print(multiset<T> v) { n   cerr <<  [  ; n   for (T i : v) { n     print(i); n     cerr <<    ; n   } n   cerr <<  ] ; n } n template <class T, class X> n void print(map<T, X> v) { n   cerr <<  [  ; n   for (auto i : v) { n     print(i); n     cerr <<    ; n   } n   cerr <<  ] ; n } n long long int power(long long int x, long long int y, long long int m) { n   if (y == 0) return 1; n   long long int p = power(x, y / 2, m) % m; n   p = p * p % m; n   if (y % 2 == 0) return p; n   return x * p % m; n } n long long int modInverse(long long int a, long long int m) { n   return power(a, m - 2, m); n } n vector<long long int> primes(long long int n) { n   vector<long long int> sieve(n + 1, 1); n   vector<long long int> arr; n   for (long long int i = 2; i * i <= n; i++) { n     for (long long int j = i * i; j <= n; j = j + i) { n       if (sieve[j] == 1) sieve[j] = 0; n     } n   } n   for (long long int i = 2; i < n + 1; i++) { n     if (sieve[i] && i != 1) arr.push_back(i); n   } n   return arr; n } n class DSU { n   long long int n; n   vector<long long int> parent, rank; n  n  public: n   DSU(long long int x) { n     n = x; n     parent.resize(n); n     rank.resize(n, 0); n     for (long long int i = 0; i < n; i++) parent[i] = i; n   } n   long long int get(long long int a) { n     return parent[a] = parent[a] == a ? a : get(parent[a]); n   } n   void merge(long long int a, long long int b) { n     a = get(a); n     b = get(b); n     if (a == b) return; n     if (rank[a] == rank[b]) rank[a]++; n     if (rank[a] > rank[b]) n       parent[b] = a; n     else n       parent[a] = b; n   } n }; n const int N = 200001; n long long int factorialNumInverse[N + 1]; n long long int naturalNumInverse[N + 1]; n long long int fact[N + 1]; n void InverseofNumber(long long int p) { n   naturalNumInverse[0] = naturalNumInverse[1] = 1; n   for (int i = 2; i <= N; i++) n     naturalNumInverse[i] = naturalNumInverse[p % i] * (p - p / i) % p; n } n void InverseofFactorial(long long int p) { n   factorialNumInverse[0] = factorialNumInverse[1] = 1; n   for (int i = 2; i <= N; i++) n     factorialNumInverse[i] = n         (naturalNumInverse[i] * factorialNumInverse[i - 1]) % p; n } n void factorial(long long int p) { n   fact[0] = 1; n   for (int i = 1; i <= N; i++) { n     fact[i] = (fact[i - 1] * i) % p; n   } n } n long long int Binomial(long long int N, long long int R, long long int p) { n   long long int ans = n       ((fact[N] * factorialNumInverse[R]) % p * factorialNumInverse[N - R]) % p; n   return ans; n } n vector<long long int> KMP(string &s) { n   long long int n = (long long int)s.length(); n   vector<long long int> pi(n, 0); n   for (long long int i = 1; i < n; i++) { n     long long int j = pi[i - 1]; n     while (j > 0 && s[i] != s[j]) j = pi[j - 1]; n     if (s[i] == s[j]) j++; n     pi[i] = j; n   } n   return pi; n } n long long int sz(vector<long long int> &v) { return (long long int)v.size(); } n long long int sz(string &s) { return (long long int)s.size(); } n void input() {} n void read(vector<long long int> &arr) { n   for (long long int i = 0; i < (long long int)arr.size(); i++) cin >> arr[i]; n } n long long int testcases() { n   long long int testcase = 1; n   cin >> testcase; n   return testcase; n } n void solve() { n   long long int n, m; n   cin >> n >> m; n   long long int x, y, c, d; n   cin >> x >> y >> c >> d; n   x--; n   y--; n   c--; n   d--; n   long long int f = 0; n   long long int ans = 0; n   long long int dr = 1, dc = 1; n   while (1) { n     if (x == c || y == d) { n       break; n     } n     if (x == -1 || x == n) { n       ans--; n       y -= dc; n       x -= dr; n       dr = -dr; n     } else if (y == -1 || y == m) { n       ans--; n       x -= dr; n       y -= dc; n       dc = -dc; n     } else { n       x += dr; n       y += dc; n       ans++; n     } n   } n   cout << ans <<   n ; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   input(); n   setdecimals(5); n   long long int t, i; n   t = testcases(); n   i = 1; n   while (i <= t) { n     solve(); n     i++; n   } n   return 0; n } n


#include <bits/stdc++.h> n const double PI = 3.141592653589793238460; n long long int gcd(long long int a, long long int b) { n   if (a == 0) return b; n   return gcd(b % a, a); n } n long long int max(long long int a, long long int b) { n   if (a > b) n     return a; n   else n     return b; n } n long long int min(long long int a, long long int b) { n   if (a < b) n     return a; n   else n     return b; n } n long long int power(long long int a, long long int b) { n   long long int i, p = 1; n   for (i = 0; i < b; i++) { n     p *= a; n   } n   return p; n } n using namespace std; n int main() { n   ios::sync_with_stdio(false); n   long long int n, i; n   cin >> n; n   vector<pair<long long int, long long int> > p; n   p.push_back({0, 0}); n   p.push_back({0, 1}); n   p.push_back({1, 1}); n   p.push_back({1, 0}); n   for (i = 0; i < n; i++) { n     p.push_back({i + 2, i + 1}); n     p.push_back({i + 1, i + 2}); n     p.push_back({i + 2, i + 2}); n   } n   cout << p.size() <<   n ; n   for (i = 0; i < p.size(); i++) { n     cout << p[i].first <<     << p[i].second <<   n ; n   } n   return 0; n } n


#include <iostream> n #include <vector> n #include <queue> n #include <algorithm> n  n using ll = long long; n #define MIN(a, b) (((a) < (b)) ? (a) : (b)) n #define MAX(a, b) (((a) < (b)) ? (b) : (a)) n  n int const nmax = 400; n int const modulo = 998244353; n  n int d[1 + nmax][1 + nmax]; n std::vector<int> g[1 + nmax]; n  n int main() { n   int n, m; n   std::cin >> n >> m; n   for(int i = 1; i <= m; i++) { n     int a, b; n     std::cin >> a >> b; n     g[a].push_back(b); n     g[b].push_back(a); n   } n   for(int i = 1;i <= n; i++) { n     std::queue<int> q; n     q.push(i); n     for(int j = 1;j <= n; j++) n       d[i][j] = -1; n     d[i][i] = 0; n     while(0 < q.size()) { n       int node = q.front(); n       q.pop(); n       for(int h = 0; h < g[node].size(); h++) { n         int to = g[node][h]; n         if(d[i][to] == -1) { n           d[i][to] = d[i][node] + 1; n           q.push(to); n         } n       } n     } n   } n   for(int i = 1; i <= n; i++) { n     for(int j = 1;j <= n; j++) { n       int target = d[i][j], on_chain = 0, result = 1; n       for(int to = 1; to <= n; to++)  n         if(d[i][to] + d[j][to] == target) n           on_chain++; n         else { n           int p = 0; n           for(int h = 0; h < g[to].size(); h++) { n             int oth = g[to][h]; n             if(d[i][oth] + 1 == d[i][to] && d[j][oth] + 1 == d[j][to]) n               p++; n           } n           result = 1LL * result * p % modulo; n         } n        n       if(on_chain != target + 1) n         result = 0; n       std::cout << result <<    ; n     } n     std::cout <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int gcd(int a, int b) { return a % b ? gcd(b, a % b) : b; } n int main() { n   int n; n   while (cin >> n) { n     int sum = 0; n     for (int i = 2; i < n; i++) { n       int t = n; n       while (t) { n         sum += t % i; n         t /= i; n       } n     } n     int g = gcd(sum, n - 2); n     cout << sum / g <<  /  << (n - 2) / g << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   double arr[105]; n   scanf( %d , &n); n   for (int i = 0; i < n; i++) scanf( %lf , &arr[i]); n   sort(arr, arr + n); n   reverse(arr, arr + n); n   double Max = 0; n   double prev = 0, a = 0, b = 1; n   for (int i = 0; i < n; i++) { n     a = (a * (1 - arr[i])) + arr[i] * b; n     b *= (1 - arr[i]); n     Max = max(Max, a); n   } n   printf( %.10lf n , Max); n   return 0; n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:1024000000,1024000000 ) n using namespace std; n const long long inf = 0x3f3f3f3f3f3f3f3f; n const int maxn = 100005; n int main() { n   int n; n   long long r; n   scanf( %d %lld , &n, &r); n   n = 1 << n; n   int c[n]; n   double sum = 0; n   for (int i = 0; i < n; i++) scanf( %d , &c[i]), sum += c[i]; n   printf( %.6f n , sum / n); n   for (int i = 0; i < r; i++) { n     int z, g; n     scanf( %d %d , &z, &g); n     sum = sum - c[z] + g; n     c[z] = g; n     printf( %.6f n , sum / n); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 55; n const int maxm = 5e3 + 110; n double dp[maxn][maxm]; n struct node { n   int f, s; n   double p; n } a[maxn]; n int main() { n   int n, R; n   scanf( %d %d , &n, &R); n   for (int i = 1; i <= n; i++) { n     scanf( %d %d %lf , &a[i].f, &a[i].s, &a[i].p); n     a[i].p = a[i].p / 100.0; n   } n   double l = 0, r = 1e15, ans = 0; n   for (int ii = 0; ii <= 100; ii++) { n     double mid = (l + r) / 2.0; n     for (int j = 0; j <= R; j++) dp[n + 1][j] = j; n     for (int j = R + 1; j <= 5100; j++) dp[n + 1][j] = 0x3f3f3f3f; n     for (int i = n; i >= 1; i--) { n       for (int j = 5005; j >= 0; j--) { n         dp[i][j] = dp[i + 1][j + a[i].f] * a[i].p + n                    dp[i + 1][j + a[i].s] * (1 - a[i].p); n         dp[i][j] = n             min(dp[i][j], dp[i + 1][j + a[i].f] * a[i].p + n                               (1 - a[i].p) * (mid + (double)(j + a[i].s))); n         dp[i][j] = n             min(dp[i][j], a[i].p * ((double)(j + a[i].f) + mid) + n                               (1 - a[i].p) * ((double)(j + mid) + a[i].s)); n       } n     } n     if (dp[1][0] >= mid) { n       ans = mid; n       l = mid; n     } else n       r = mid; n   } n   printf( %.9f n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e5 + 7; n int a[maxn]; n int b[maxn]; n int n; n vector<pair<int, int>> v; n void borrow(int pos, int val) { n   if (val == 1) { n     if (a[pos + 1] == 0) borrow(pos + 1, -1); n     if (v.size() >= 100000) return; n     v.push_back(make_pair(pos, -1)); n     a[pos + 1]--; n     a[pos]--; n   } else { n     if (a[pos + 1] == 9) borrow(pos + 1, 1); n     if (v.size() >= 100000) return; n     v.push_back(make_pair(pos, 1)); n     a[pos + 1]++; n     a[pos]++; n   } n } n void solve() { n   for (int i = 1; i <= n - 1; i++) { n     while (a[i] != b[i]) { n       if (a[i] < b[i]) { n         if (a[i + 1] == 9) { n           borrow(i + 1, 1); n         } n         if (v.size() >= 100000) return; n         v.push_back(make_pair(i, 1)); n         a[i]++; n         a[i + 1]++; n       } else { n         if (a[i + 1] == 0) { n           borrow(i + 1, -1); n         } n         if (v.size() >= 100000) return; n         v.push_back(make_pair(i, -1)); n         a[i]--; n         a[i + 1]--; n       } n     } n   } n } n int main() { n   while (cin >> n) { n     v.clear(); n     char c; n     for (int i = 1; i <= n; i++) { n       cin >> c; n       a[i] = c -  0 ; n     } n     for (int i = 1; i <= n; i++) { n       cin >> c; n       b[i] = c -  0 ; n     } n     long long ans = 0; n     int temp = a[1]; n     for (int i = 1; i <= n - 1; i++) { n       ans += abs(b[i] - temp); n       temp = a[i + 1] + b[i] - temp; n     } n     if (temp != b[n]) { n       cout << -1 << endl; n       continue; n     } n     cout << ans << endl; n     solve(); n     for (int i = 0; i < v.size(); i++) { n       cout << v[i].first <<     << v[i].second << endl; n     } n   } n } n