#include <bits/stdc++.h> n using namespace std; n #define sim template < class c n #define ris return * this n #define dor > debug & operator << n #define eni(x) sim > typename   n   enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) { n sim > struct rge { c b, e; }; n sim > rge<c> range(c i, c j) { return rge<c>{i, j}; } n sim > auto dud(c* x) -> decltype(cerr << *x, 0); n sim > char dud(...); n struct debug { n #ifndef ONLINE_JUDGE n ~debug() { cerr << endl; } n eni(!=) cerr << boolalpha << i; ris; } n eni(==) ris << range(begin(i), end(i)); } n sim, class b dor(pair < b, c > d) { n   ris <<  (  << d.first <<  ,   << d.second <<  ) ; n } n sim dor(rge<c> d) { n   *this <<  [ ; n   for (auto it = d.b; it != d.e; ++it) n     *this <<  ,   + 2 * (it == d.b) << *it; n   ris <<  ] ; n } n #else n sim dor(const c&) { ris; } n #endif n }; n #define imie(...)   [  << #__VA_ARGS__  :   << (__VA_ARGS__) <<  ]   n // debug & operator << (debug & dd, P p) { dd <<  ,   << p.x <<  ,   << p.y <<  ) ; return dd; } n  n #define ll long long n const ll mod = 1e9 + 7; n  n ll powM(ll a, ll b) { n     ll res = 1; n     ll base = 1; n     while(base <= b) { n         if(base & b) { n             res = res * a; n             res = res % mod; n             if(res < 0) { n                 res = res + mod;  n             } n         } n         base = base * 2; n         a = a * a; n         a = a % mod; n         if(a < 0) { n             a = a + mod;  n         } n     } n     return res; n } n  n ll mod_inverse(ll n) { n     return powM(n, mod - 2); n } n  n int main() { n     ll n; n     cin >> n; n     // calculate dp. n     vector<vector<ll>> dp(205, vector<ll> (205)); n     dp[0][0] = 0; n     for(ll i = 0; i < 205; ++i) { n         dp[0][i] = 1; n         dp[i][0] = 0; n     } n     for(ll i = 1; i < 205; ++i) { n         for(ll j = 1; j < 205; ++j) { n             dp[i][j] = dp[i - 1][j] + dp[i][j - 1]; n             dp[i][j] = dp[i][j] % mod; n             dp[i][j] = dp[i][j] * mod_inverse(2); n             dp[i][j] = dp[i][j] % mod; n             if(dp[i][j] < 0) { n                 dp[i][j] = dp[i][j] + mod; n             } n         } n     } n     // debug() << imie(dp); n     // read tree. n     vector<vector<ll>> graph(n, vector<ll> (n, 0)); n     for(ll i = 0; i < n - 1; ++i) { n         ll x, y; n         cin >> x >> y; n         x--; n         y--; n         graph[x][y] = 1; n         graph[y][x] = 1; n     } n     // debug() << imie(graph); n     // floyd warshall. n     vector<vector<ll>> dist(n, vector<ll> (n, 800)); n     for(ll i = 0; i < n; ++i) { n         dist[i][i] = 0; n     } n     for(ll i = 0; i < n; ++i) { n         for(ll j = 0; j < n; ++j) { n             if(graph[i][j]) { n                 dist[i][j] = 1; n             } n         } n     } n     for(ll k = 0; k < n; ++k) { n         for(ll i = 0; i < n; ++i) { n             for(ll j = 0; j < n; ++j) { n                 dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]); n             } n         } n     } n     // debug() << imie(dist); n     // calculate answer. n     ll ans = 0; n     for(ll i = 0; i < n; ++i) { n         for(ll j = i + 1; j < n; ++j) { n             for(ll k = 0; k < n; ++k) { n                 ll dmin = dist[i][k]; n                 ll dmax = dist[j][k]; n                 ll t = (dmin + dmax - dist[i][j]) / 2; n                 dmin = dmin - t; n                 dmax = dmax - t; n                 ans = ans + dp[dmax][dmin]; n                 ans = ans % mod; n                 if(ans < 0) { n                     ans = ans + mod;  n                 } n             } n         } n     } n     ans = (ans * mod_inverse(n) % mod); n     cout << ans << endl; n }


#include <bits/stdc++.h> n using namespace std; n int main() { n   int numRows, numCols; n   scanf( %d %d n , &numRows, &numCols); n   bool *rowArray = new bool[numRows]; n   for (int k = 0; k < numRows; k++) { n     rowArray[k] = 1; n   } n   bool *colArray = new bool[numCols]; n   for (int k = 0; k < numCols; k++) { n     colArray[k] = 1; n   } n   char temp; n   for (int row = 0; row < numRows; row++) { n     for (int col = 0; col < numCols; col++) { n       scanf( %c , &temp); n       if (temp ==  S ) { n         rowArray[row] = 0; n         colArray[col] = 0; n       } n     } n     scanf(  n ); n   } n   int freeRows(0), freeCols(0); n   for (int k = 0; k < numRows; k++) { n     if (rowArray[k]) { n       ++freeRows; n     } n   } n   for (int k = 0; k < numCols; k++) { n     if (colArray[k]) { n       ++freeCols; n     } n   } n   printf( %d n , freeRows * numCols + freeCols * numRows - freeRows * freeCols); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long lol(long long a, long long b) { return a / b; } n int main() { n   int n, a[300009]; n   cin >> n; n   while (n--) { n     long long s, a, b, c; n     cin >> s >> a >> b >> c; n     long long nani = s / c; n     long long nande = nani / a; n     long long kirito = nande * (a + b); n     long long asuna = kirito + nani % a; n     cout << asuna << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n vector<vector<int> > v; n vector<bool> vis; n string ans =   ; n void dfs(int temp) { n   ans += temp +  a ; n   for (auto it = v[temp].begin(); it != v[temp].end(); ++it) { n     if (!vis[*it]) { n       vis[*it] = true; n       dfs(*it); n     } n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n   int t; n   cin >> t; n   while (t--) { n     string s; n     cin >> s; n     v.resize(26); n     vis.resize(26); n     set<pair<char, char> > sc; n     for (int i = 0; i < s.size() - 1; i += 1) { n       pair<int, int> cc = {min(s[i], s[i + 1]), max(s[i], s[i + 1])}; n       if (sc.find(cc) == sc.end()) { n         sc.insert(cc); n         v[s[i] -  a ].emplace_back(s[i + 1] -  a ); n         v[s[i + 1] -  a ].emplace_back(s[i] -  a ); n       } n     } n     int cnt = 0, temp = 0; n     for (int i = 0; i < 26; i += 1) { n       if (v[i].size() == 1) { n         temp = i; n         cnt++; n       } else if (v[i].size() > 2) { n         cnt = -1; n         break; n       } n     } n     if (cnt != 2 && s.size() != 1) n       cout <<  NO n ; n     else { n       cout <<  YES n ; n       vis[temp] = true; n       dfs(temp); n       for (int i = 0; i < 26; i += 1) { n         if (!vis[i]) ans += i +  a ; n       } n       cout << ans <<   n ; n     } n     ans =   ; n     vis.clear(); n     for (int i = 0; i < 26; i += 1) v[i].clear(); n     v.clear(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n char types[11]; n bool possible[1005][12][11]; n int m; n int pre[1005][12][11][3]; n int main() { n   scanf( %s , types); n   scanf( %d , &m); n   for (int i = 0; i < 11; ++i) n     for (int d = 0; d <= 10; ++d) possible[0][i][d] = 0; n   possible[0][0][0] = 1; n   int best = 0; n   int bestVal[3]; n   for (int j = 1; j <= m; ++j) { n     for (int d = 0; d <= 10; ++d) possible[j][0][d] = 0; n     for (int i = 1; i < 11; ++i) n       for (int d = 0; d <= 10; ++d) { n         possible[j][i][d] = 0; n         if (types[i - 1] ==  0  || !d || d > i) { n           continue; n         } n         for (int k = 0; k < 11; ++k) { n           if (!possible[j - 1][k][i - d] || k == i) continue; n           possible[j][i][d] = 1; n           pre[j][i][d][0] = j - 1; n           pre[j][i][d][1] = k; n           pre[j][i][d][2] = i - d; n           best = j; n           bestVal[0] = j; n           bestVal[1] = i; n           bestVal[2] = d; n         } n       } n   } n   if (best == m) { n     printf( YES n ); n     int j = bestVal[0], i = bestVal[1], d = bestVal[2]; n     int ansList[1005]; n     ansList[j - 1] = i; n     while (j > 1) { n       int jp = pre[j][i][d][0], ip = pre[j][i][d][1], kp = pre[j][i][d][2]; n       j = jp; n       i = ip; n       d = kp; n       ansList[j - 1] = i; n     } n     for (int a = 0; a < m; ++a) printf( %d  , ansList[a]); n   } else n     printf( NO n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, k, cnt[1010], ans; n int main() { n   cin >> n >> k; n   for (int i = 1; i <= n; i++) { n     int x; n     cin >> x; n     cnt[x]++; n   } n   for (int i = 1; i <= (n + 1) / 2; i++) { n     int idx = -1, mx = -1; n     for (int j = 1; j <= k; j++) { n       if (cnt[j] > mx) { n         mx = cnt[j]; n         idx = j; n       } n     } n     if (cnt[idx] >= 2) { n       ans += 2; n       cnt[idx] -= 2; n     } else { n       ans += cnt[idx]; n       cnt[idx] = 0; n     } n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n short c1[25001], c2[25001]; n int a[12][12]; n int main() { n   int n, m, res = 0; n   cin >> n >> m; n   char c; n   for (int i = 0; i < n; i++) n     for (int j = 0; j < m; j++) { n       cin >> c; n       if (c ==  W ) n         a[i][j] = 2; n       else if (c ==  P ) n         a[i][j] = 1; n       else n         a[i][j] = 0; n     } n   for (int i = 0; i < n; i++) n     for (int j = 0; j < m; j++) n       if (a[i][j] == 2) { n         if (a[max(i - 1, 0)][j] == 1) { n           res++; n           a[max(i - 1, 0)][j] = 0; n           continue; n         } n         if (a[i][max(j - 1, 0)] == 1) { n           a[i][max(j - 1, 0)] = 0; n           res++; n           continue; n         } n         if (a[i + 1][j] == 1) { n           res++; n           a[i + 1][j] = 0; n           continue; n         } n         if (a[i][j + 1] == 1) { n           a[i][j + 1] = 0; n           res++; n         } n       } n   cout << res; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m; n vector<int> g[5000], rev[5000]; n bool used[5000]; n vector<int> ord; n bool curcm[5000]; n vector<int> cm; n void dfs1(int v) { n   used[v] = true; n   for (int to : g[v]) n     if (!used[to]) { n       dfs1(to); n     } n   ord.push_back(v); n } n void dfs2(int v) { n   used[v] = true; n   cm.push_back(v); n   curcm[v] = true; n   for (int to : rev[v]) n     if (!used[to]) { n       dfs2(to); n     } n } n int dist[5000][5000]; n int q[5000]; n int main() { n   scanf( %d%d , &n, &m); n   for (int i = 0; i < (int)(m); ++i) { n     int from, to; n     scanf( %d%d , &from, &to), --from, --to; n     g[from].push_back(to); n     rev[to].push_back(from); n   } n   memset(dist, -1, sizeof dist); n   for (int i = 0; i < (int)(n); ++i) { n     int(&d)[5000] = dist[i]; n     d[i] = 0; n     q[0] = i; n     for (int qh = 0, qt = 1; qh < qt; ++qh) { n       int v = q[qh]; n       for (int to : g[v]) n         if (d[to] == -1) { n           d[to] = d[v] + 1; n           q[qt++] = to; n         } n     } n   } n   for (int i = 0; i < (int)(n); ++i) used[i] = false; n   for (int i = 0; i < (int)(n); ++i) n     if (!used[i]) { n       dfs1(i); n     } n   reverse(ord.begin(), ord.end()); n   for (int i = 0; i < (int)(n); ++i) used[i] = false; n   int ans = n; n   for (int v : ord) n     if (!used[v]) { n       cm.clear(); n       for (int i = 0; i < (int)(n); ++i) curcm[i] = false; n       dfs2(v); n       bool ok = false; n       for (int x : cm) { n         for (int y : g[x]) n           if (!curcm[y]) { n             ok = true; n             break; n           } n         if (ok) break; n       } n       if (!ok && (int)cm.size() > 1) { n         ++ans; n         int z = 12341234; n         for (int x : cm) n           for (int y : cm) { n             if (y == x) break; n             z = min(z, dist[x][y] + dist[y][x]); n           } n         ans += z * 998; n       } n     } n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = INT_MAX; n const long long INFL = LLONG_MAX; n const long double pi = acos(-1); n int N, M; n string s[100]; n long long d[1 << 20]; n long double f[1 << 20]; n int main() { n   ios_base::sync_with_stdio(0); n   cout.precision(15); n   cout << fixed; n   cout.tie(0); n   cin >> N; n   for (int(i) = 0, j123 = N; (i) < j123; (i)++) cin >> s[i]; n   M = s[0].size(); n   for (int(i) = 0, j123 = N; (i) < j123; (i)++) n     for (int(j) = 0, j123 = N; (j) < j123; (j)++) n       if (i != j) { n         int same = 0; n         for (int(k) = 0, j123 = M; (k) < j123; (k)++) n           if (s[i][k] == s[j][k]) same |= (1 << k); n         d[same] |= (1LL << i); n       } n   for (int mask = (1 << M) - 1; mask >= 0; mask--) n     for (int(i) = 0, j123 = M; (i) < j123; (i)++) n       if (!((mask >> i) & 1)) d[mask] |= d[mask | (1 << i)]; n   for (int mask = (1 << M) - 1; mask >= 0; mask--) { n     if (d[mask] == 0) continue; n     long double tot = 0; n     int cnt = 0; n     for (int(i) = 0, j123 = M; (i) < j123; (i)++) n       if (!((mask >> i) & 1)) { n         cnt++; n         tot += f[mask | (1 << i)] * __builtin_popcountll(d[mask | (1 << i)]) / n                __builtin_popcountll(d[mask]); n       } n     tot /= cnt; n     tot += 1; n     f[mask] = tot; n   } n   cout << f[0] <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n const double PI = acos(0) * 2; n const double EPS = 1e-8; n const long long MOD = 1e9 + 7; n const int MAXN = 1e4 + 5; n const int oo = 1e9; n const double foo = 1e30; n template <class T> n int getbit(T s, int i) { n   return (s >> i) & 1; n } n template <class T> n T onbit(T s, int i) { n   return s | (T(1) << i); n } n template <class T> n T offbit(T s, int i) { n   return s & (~(T(1) << i)); n } n template <class T> n int cntbit(T s) { n   return __builtin_popcounll(s); n } n template <class T> n T sqr(T x) { n   return x * x; n } n inline void addmod(int& a, int val, int p = MOD) { n   if ((a = (a + val)) >= p) a -= p; n } n inline void submod(int& a, int val, int p = MOD) { n   if ((a = (a - val)) < 0) a += p; n } n inline int mult(int a, int b, int p = MOD) { return (long long)a * b % p; } n int n; n long double val[MAXN], f[MAXN]; n vector<int> has[MAXN], ans; n int main() { n   scanf( %d , &n); n   for (int i = 0; i < n; i++) { n     int s, r; n     scanf( %d%d , &s, &r); n     if (r > val[s]) { n       val[s] = r; n       has[s].clear(); n     } n     if (r == val[s]) has[s].push_back(i); n   } n   for (int i = 1; i <= 10000; i++) { n     if (!has[i].empty()) f[i] = val[i] / i; n   } n   for (int i = 1; i <= 10000; i++) { n     if (has[i].empty()) continue; n     long double r = 10000000000000.0; n     long double l = 0; n     int cant = 0; n     for (int j = 1; j < i; j++) { n       if (!has[j].empty() && val[j] > val[i]) { n         long double tmp = n             ((long double)i - (long double)j) / (val[j] - val[i]) * f[i] * f[j]; n         r = min(r, tmp); n       } n     } n     for (int j = i + 1; j <= 10000; j++) { n       if (cant) break; n       if (!has[j].empty()) { n         if (val[i] > val[j]) { n           long double tmp = ((long double)j - (long double)i) / n                             (val[i] - val[j]) * f[i] * f[j]; n           l = max(l, tmp); n         } else n           cant = 1; n       } n     } n     if ((l == 10000000000000.0 || r == 0 || l <= r) && !cant) { n       for (int j = 0; j < ((int)(has[i]).size()); j++) { n         ans.push_back(has[i][j]); n       } n     } n   } n   sort(ans.begin(), ans.end()); n   for (int i = 0; i < ((int)(ans).size()); i++) { n     printf( %d  , ans[i] + 1); n   } n } n


#include <bits/stdc++.h> n using namespace std; n using LLI = long long; n long long NWD(long long blep, long long b) { n   return (b == 0) ? blep : NWD(b, blep % b); n } n long long NWW(long long blep, long long b) { return blep / NWD(blep, b) * b; } n const int MX = 3e5 + 400; n int n, T[MX]; n long long ans[MX]; n void out() { n   cout <<  YES  << endl; n   for (int i = 1; i <= n; i++) cout << ans[i] <<    ; n   cout << endl; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cin >> n; n   for (int i = 1; i <= n; i++) cin >> T[i]; n   T[n + 1] = T[1]; n   T[0] = T[n]; n   for (int i = 1; i <= n; i++) { n     if (T[i] > T[i - 1]) { n       ans[i] = T[i]; n       if (i == 1) n         ans[n + 1] = ans[1]; n       else if (i == n) n         ans[0] = ans[n]; n       for (int j = i - 1; j > i - n; j--) { n         int blep = (j + n) % n; n         if (blep == 0) blep = n; n         ans[blep] = ans[blep + 1] + T[blep]; n         while (ans[blep] <= (long long)T[blep - 1]) ans[blep] += ans[blep + 1]; n         if (j == 1) n           ans[n + 1] = ans[1]; n         else if (j == n) n           ans[0] = ans[n]; n       } n       return out(), 0; n     } n   } n   for (int i = 1; i <= n; i++) ans[i] = 1; n   if (T[1] == 0) n     out(); n   else n     cout <<  NO  << endl; n   getchar(); n   getchar(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int M = 1e5 + 1; n int n; n int main() { n   scanf( %d , &n); n   n = abs(n); n   int i = 0; n   while (1) { n     int s = i * (i + 1); n     s /= 2; n     if (s >= n) { n       if (s % 2 && n % 2) { n         printf( %d , i); n         exit(0); n       } n       if (s % 2 == 0 && n % 2 == 0) { n         printf( %d , i); n         exit(0); n       } n     } n     i++; n   } n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n int main() { n   string s; n   cin >> s; n   int n = s.size(); n   if (n % 2 == 1) { n     for (int i = 0; i < n + 1; ++i) { n       cout << (i < (n + 1) / 2 ? 4 : 7); n     } n     cout << endl; n     return 0; n   } n   int seven = 0, four = 0; n   for (int i = 0; i < n; ++i) { n     if (s[i] ==  4 ) { n       four++; n     } n     if (s[i] ==  7 ) { n       seven++; n     } n   } n   if (seven == four && seven + four == n) { n     cout << s << endl; n     return 0; n   } n   for (int i = n - 1; i >= 0; --i) { n     if (s[i] ==  4 ) { n       four--; n     } n     if (s[i] ==  7 ) { n       seven--; n     } n     if (seven + four != i) { n       continue; n     } n     if (seven > n / 2 || four > n / 2) { n       continue; n     } n     if (s[i] <  4  && n / 2 - four > 0) { n       s[i] =  4 ; n       four++; n       int x = i + 1; n       while (four < n / 2) { n         s[x++] =  4 ; n         four++; n       } n       while (seven < n / 2) { n         s[x++] =  7 ; n         seven++; n       } n       cout << s << endl; n       return 0; n     } n     if (s[i] <  7  && n / 2 - seven > 0) { n       s[i] =  7 ; n       seven++; n       int x = i + 1; n       while (four < n / 2) { n         s[x++] =  4 ; n         four++; n       } n       while (seven < n / 2) { n         s[x++] =  7 ; n         seven++; n       } n       cout << s << endl; n       return 0; n     } n   } n   for (int i = 0; i < n + 2; ++i) { n     cout << (i < (n + 2) / 2 ? 4 : 7); n   } n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long a[100005]; n long long d[800][800], g[800][800]; n int w[100]; n vector<long long> v; n int main() { n   int n; n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) { n     scanf( %lld , &a[i]); n     long long x = a[i]; n     int cnt = 0; n     while (x) { n       if (x % 2) w[cnt]++; n       cnt++; n       x /= 2; n     } n   } n   for (int i = 0; i < 70; i++) { n     if (w[i] >= 3) { n       printf( 3 n ); n       return 0; n     } n   } n   v.push_back(0); n   for (int i = 1; i <= n; i++) { n     if (a[i]) v.push_back(a[i]); n   } n   n = v.size() - 1; n   if (n > 300) { n     printf( 3 n ); n     return 0; n   } n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= n; j++) d[i][j] = g[i][j] = 0x3f3f3f3f; n   } n   for (int i = 1; i <= n; i++) { n     for (int j = i + 1; j <= n; j++) { n       if (v[i] & v[j]) d[i][j] = 1, d[j][i] = 1, g[i][j] = 1, g[j][i] = 1; n     } n   } n   long long ans = 0x3f3f3f3f; n   for (int k = 1; k <= n; k++) { n     for (int i = 1; i < k; i++) { n       for (int j = i + 1; j < k; j++) n         ans = min(ans, d[i][j] + g[i][k] + g[k][j]); n     } n     for (int i = 1; i <= n; i++) { n       for (int j = 1; j <= n; j++) d[i][j] = min(d[i][j], d[i][k] + d[k][j]); n     } n   } n   if (ans == 0x3f3f3f3f) ans = -1; n   printf( %lld n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 2e5 + 5; n const long long MOD = 1e9 + 7; n const long long INF = 1e18; n signed main() { n   int n; n   cin >> n; n   vector<long long> a(n); n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n   } n   multiset<long long> kek; n   long long ans = 0; n   for (int i = n - 1; i >= 0; i--) { n     if (a[i] == -1) { n       break; n     } n     kek.insert(a[i]); n     if ((i & (i + 1)) == 0) { n       ans += *(kek.begin()); n       kek.erase(kek.begin()); n     } n   } n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n long long dp[4]; n int a[100005]; n string s; n int main() { n   cin >> n; n   cin >> s; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n     if (s[i] ==  h ) n       dp[0] += a[i]; n     else if (s[i] ==  a ) n       dp[1] = min(dp[0], dp[1] + a[i]); n     else if (s[i] ==  r ) n       dp[2] = min(dp[1], dp[2] + a[i]); n     else if (s[i] ==  d ) n       dp[3] = min(dp[2], dp[3] + a[i]); n   } n   cout << dp[3]; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n namespace Work { n int c[100010], f[100010], l[100010]; n int n, d, s; n void solve(FILE* fin, FILE* fout) { n   fscanf(fin,  %d%d%d , &n, &d, &s); n   for (int i = 0; i < n; i++) fscanf(fin,  %d%d%d , c + i, f + i, l + i); n   vector<int> a, b; n   a.clear(); n   b.clear(); n   for (int i = 0; i < n; i++) n     if (c[i] == 0 && l[i] >= d) a.push_back(f[i]); n   sort(a.begin(), a.end()); n   int acnt = 0, acost = 0; n   int sum = 0; n   for (int i = 0; i < (int)a.size(); i++) n     if (sum + a[i] <= s) { n       sum += a[i]; n       if (i + 1 > acnt || (i + 1 == acnt && sum < acost)) { n         acnt = i + 1; n         acost = sum; n       } n     } n   bool flag = false; n   for (int i = 0; i < n; i++) n     if (c[i] > 0 && f[i] <= s && l[i] >= d) flag = true; n   if (flag) { n     int carry = 0; n     for (int i = 0; i < n; i++) { n       carry += c[i]; n       carry = min(carry, n); n     } n     a.clear(); n     for (int i = 0; i < n; i++) n       if (l[i] >= d) { n         if (c[i] > 0) n           a.push_back(f[i]); n         else n           b.push_back(f[i]); n       } n     sort(a.begin(), a.end()); n     sort(b.begin(), b.end()); n     int i = 1, j = 0; n     sum = a[0]; n     while (true) { n       int cnt = min(n, carry + i + j); n       if (cnt > acnt || (cnt == acnt && sum < acost)) { n         acnt = cnt; n         acost = sum; n       } n       if (i == a.size() && j == b.size()) break; n       if (i < a.size() && (j == b.size() || a[i] < b[j])) { n         sum += a[i]; n         i++; n       } else { n         sum += b[j]; n         j++; n       } n       if (sum > s) break; n     } n   } n   fprintf(fout,  %d %d , acnt, acost); n } n }  // namespace Work n int main() { n   Work::solve(stdin, stdout); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long a, b, n, ret; n long long retr(long long x) { n   long long t = 0; n   while (x > 0) { n     t = 10 * t + (x % 10); n     x /= 10; n   } n   return t; n } n int main() { n   int i; n   cin >> a >> b; n   ret = retr(b); n   ret += a; n   cout << ret; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n char s[200100]; n int x[200100]; n int main() { n   scanf( %d , &n); n   scanf( %s , s); n   int mint = 0x3f3f3f3f; n   for (int i = 0; i < n; i++) { n     scanf( %d , &x[i]); n     if (i && s[i] ==  L  && s[i - 1] ==  R ) n       mint = min((x[i] - x[i - 1]) / 2, mint); n   } n   if (mint == 0x3f3f3f3f) mint = -1; n   printf( %d , mint); n   return 0; n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:102400000,102400000 ) n using namespace std; n const int N = 100100; n struct point { n   int id, val, sum; n } a[N], b[N]; n bool cmp(point x, point y) { return x.val > y.val; } n int main() { n   int n, m; n   scanf( %d%d , &n, &m); n   int na = 0; n   int nb = 1; n   b[0].val = 0; n   for (int i = 1; i <= n; ++i) { n     int op; n     scanf( %d , &op); n     if (op == 1) { n       scanf( %d , &a[na].val); n       a[na++].id = i; n     } else { n       scanf( %d , &b[nb].val); n       b[nb++].id = i; n     } n   } n   sort(a, a + na, cmp); n   sort(b + 1, b + nb, cmp); n   for (int i = 0; i < na; ++i) { n     if (i == 0) n       a[i].sum = a[i].val; n     else n       a[i].sum = a[i - 1].sum + a[i].val; n   } n   int sum = 0; n   int ia = 0; n   int ib = 1; n   int ans = 0; n   for (int i = 0; i < nb && 2 * i <= m; ++i) { n     sum += b[i].val; n     int id = min(m - 2 * i - 1, na - 1); n     int tmp = sum; n     if (id >= 0) tmp += a[id].sum; n     if (tmp > ans) { n       ans = tmp; n       ia = id + 1; n       ib = i + 1; n     } n   } n   printf( %d n , ans); n   for (int i = 0; i < ia; ++i) printf( %d  , a[i].id); n   for (int i = 1; i < ib; ++i) printf( %d  , b[i].id); n   puts(  ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<vector<int>> dg, og; n vector<bool> vist; n vector<int> dist; n void bfs(int begin) { n   vist[begin] = true; n   dist[begin] = 0; n   queue<int> pq; n   pq.push(begin); n   while (!pq.empty()) { n     int a = pq.front(); n     pq.pop(); n     for (int i = 0; i < dg[a].size(); i++) { n       if (!vist[dg[a][i]]) { n         vist[dg[a][i]] = true; n         dist[dg[a][i]] = dist[a] + 1; n         pq.push(dg[a][i]); n       } n     } n   } n } n int distcounter(int a) { n   int count = 0; n   for (int i = 0; i < og[a].size(); i++) { n     if (dist[og[a][i]] == dist[a] - 1) count++; n   } n   return count; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int n, m; n   cin >> n >> m; n   dg.resize(n + 1); n   dist.resize(n + 1); n   og.resize(n + 1); n   vist.assign(n + 1, false); n   int u, v; n   for (int i = 1; i <= m; i++) { n     cin >> u >> v; n     og[u].push_back(v); n     dg[v].push_back(u); n   } n   int k; n   cin >> k; n   vector<int> p; n   p.resize(k + 1); n   for (int i = 1; i <= k; i++) cin >> p[i]; n   bfs(p[k]); n   int small = 0, large = 0; n   for (int i = 1; i < k; i++) { n     int count = distcounter(p[i]); n     if (dist[p[i + 1]] != dist[p[i]] - 1) { n       small++; n       large++; n     } else { n       if (count > 1) { n         large++; n       } n     } n   } n   cout << small <<     << large << endl; n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:128777216 ) n using namespace std; n const long long LINF = 1000000000000000000LL; n const int INF = 1000000000; n const long double eps = 1e-9; n const long double PI = 3.1415926535897932384626433832795l; n void prepare(string s) { n   if (s.length() != 0) { n     freopen((s +  .in ).c_str(),  r , stdin); n     freopen((s +  .out ).c_str(),  w , stdout); n   } n } n const int NMAX = 1000100; n const int MOD = INF + 7; n char s[NMAX]; n int n; n int c[4]; n char sym[] = { A ,  C ,  G ,  T }; n int get(char c) { n   for (int i = 0; i < (int)(4); i++) n     if (sym[i] == c) return i; n   assert(false); n   return -1; n } n void read() { n   scanf( %d n , &n); n   scanf( %s , s); n } n int bpow(int a, int n) { n   int r = 1; n   for (; n > 0; n >>= 1) { n     if (n & 1) r = ((long long)r * (long long)a) % MOD; n     a = ((long long)a * (long long)a) % MOD; n   } n   return r; n } n void solve() { n   memset(c, 0, sizeof(c)); n   for (int i = 0; i < (int)(n); i++) c[get(s[i])]++; n   int mx = *max_element(c, c + 4); n   int cnt = 0; n   for (int i = 0; i < (int)(4); i++) n     if (c[i] == mx) cnt++; n   printf( %d n , bpow(cnt, n)); n } n int main() { n   prepare(  ); n   read(); n   solve(); n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n int a[300000]; n int main() { n   int i, j, n, k, m, l = 0, h, b = 0, c; n   cin >> n; n   for (i = 0; i < n; i++) cin >> a[i]; n   for (i = 1; i < n - 1; i++) { n     if (a[i - 1] == 1 && a[i + 1] == 1 && a[i] == 0) { n       l++; n       a[i + 1] = 0; n     } n   } n   cout << l << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int cnt, h; n bool f = true; n int main() { n   long long s, x; n   cin >> s >> x; n   h = sizeof(long long) * 8 - __builtin_clzll(max(s, x)) - 1; n   for (; h >= 0; h--) { n     if (x & (1LL << h)) n       cnt++, s -= (1LL << h); n     else if (s >= (1LL << h + 1)) n       s -= (1LL << h + 1), f = false; n   } n   if (s || (cnt < 2 && f)) n     cout << 0 << endl; n   else n     cout << (1LL << (cnt)) - f * 2 << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char mtx[555][555]; n long long comb[555][555]; n int n, m, MOD; n map<pair<int, int>, long long> dp[555]; n long long solve(int col, int empty, int halfempt) { n   if (empty < 0 || halfempt < 0) return 0; n   if (col == n) { n     return empty == 0 && halfempt == 0; n   } n   if (dp[col].find(make_pair(empty, halfempt)) == dp[col].end()) { n     long long ans = 0; n     int cnt = 0; n     for (int(i) = 0; (i) < (m); (i)++) n       if (mtx[i][col] ==  1 ) cnt++; n     if (cnt == 0) { n       if (halfempt == 0) { n         ans += comb[empty][2] * solve(col + 1, empty - 2, halfempt + 2); n       } else { n         ans += comb[halfempt][2] * solve(col + 1, empty, halfempt - 2); n         if (empty != 0) { n           ans += comb[halfempt][1] * comb[empty][1] * n                  solve(col + 1, empty - 1, halfempt); n           ans += comb[empty][2] * solve(col + 1, empty - 2, halfempt + 2); n         } n       } n     } else if (cnt == 1) { n       ans = comb[empty][1] * solve(col + 1, empty - 1, halfempt + 1); n       ans += comb[halfempt][1] * solve(col + 1, empty, halfempt - 1); n     } else n       ans = solve(col + 1, empty, halfempt); n     ans %= MOD; n     dp[col][make_pair(empty, halfempt)] = ans; n   } n   return dp[col][make_pair(empty, halfempt)]; n } n int main() { n   scanf( %d%d%d , &n, &m, &MOD); n   for (int i = 1; i < 505; i++) { n     comb[i][0] = comb[i][i] = 1; n     for (int j = 0; j < i; j++) { n       comb[i + 1][j + 1] = (comb[i][j] + comb[i][j + 1]) % MOD; n     } n   } n   if (n == m) { n     printf( 1 n ); n     return 0; n   } n   for (int(i) = 0; (i) < (m); (i)++) scanf( %s , mtx[i]); n   long long ans = solve(0, n - m, 0); n   printf( %I64d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long a1, a2, b1, b2, c1, c2, d1, d2; n int main() { n   cin >> a1 >> a2 >> b1 >> b2 >> c1 >> c2; n   for (int q = 0; q < 4; q++) { n     if (q == 0) { n       d1 = b1 - (a1); n       d2 = b2 - (a2); n     } n     if (q == 1) { n       d1 = b1 - (-a1); n       d2 = b2 - (-a2); n     } n     if (q == 2) { n       d1 = b1 - (-a2); n       d2 = b2 - (a1); n     } n     if (q == 3) { n       d1 = b1 - (a2); n       d2 = b2 - (-a1); n     } n     long long k1 = d1 * c1 + d2 * c2; n     long long k2 = c1 * c1 + c2 * c2; n     long long k3 = c1 * d2 - c2 * d1; n     long long k4 = c1 * c1 + c2 * c2; n     if (k2 == 0) { n       if (d1 == 0 && d2 == 0) { n         cout <<  YES ; n         return 0; n       } n     } else if (k1 % k2 == 0 && k3 % k4 == 0) { n       cout <<  YES ; n       return 0; n     } n   } n   cout <<  NO ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 100005; n int n, m, k, top, a[N]; n pair<int, int> op[N * 3]; n int main() { n   scanf( %d%*d%d%d , &n, &m, &k); n   k--; n   m /= 2; n   if (!k) { n     return puts( 0 0 n ), 0; n   } n   for (int i = (int)(1); i <= (int)(n); i++) { n     int x; n     scanf( %*d%d , &x); n     a[i] = (x %= m); n     int l = (x + 1) % m, r = (x + k) % m; n     op[++top] = pair<int, int>(l, 1); n     op[++top] = pair<int, int>(r + 1, -1); n     if (l > r) op[++top] = pair<int, int>(0, 1); n   } n   op[++top] = pair<int, int>(m, 0); n   sort(op + 1, op + top + 1); n   int mnv = 1 << 30, mnp = 0, s = 0; n   for (int i = (int)(1); i <= (int)(top - 1); i++) { n     s += op[i].second; n     if (op[i].first != op[i + 1].first) { n       if (s < mnv) mnv = s, mnp = op[i].first; n     } n   } n   cout << mnv <<     << mnp << endl; n   for (int i = (int)(1); i <= (int)(n); i++) { n     int d = (mnp + m - a[i]) % m; n     if (d >= 1 && d <= k) cout << i <<    ; n   } n } n


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


#include <bits/stdc++.h> n using namespace std; n vector<int> g[101]; n int n, m; n bool visited[101]; n void dfs(int v) { n   visited[v] = true; n   for (int i = 0; i < g[v].size(); i++) { n     if (!visited[g[v][i]]) dfs(g[v][i]); n   } n } n bool isConnected() { n   fill(visited, visited + n, false); n   dfs(0); n   for (int i = 0; i < n; i++) n     if (!visited[i]) return false; n   return true; n } n int main() { n   scanf( %d %d , &n, &m); n   for (int i = 0; i < m; i++) { n     int x, y; n     scanf( %d %d , &x, &y); n     x--, y--; n     g[x].push_back(y); n     g[y].push_back(x); n   } n   if (n == m && isConnected()) n     cout <<  FHTAGN!  << endl; n   else n     cout <<  NO  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 3e5 + 55; n const long long mod = 1000000007; n double add[N << 2], sum[N << 2]; n struct node { n   int pos, h, l, r; n } a[N]; n map<int, int> b; n vector<int> v, v2; n int getid(int x) { return lower_bound(v.begin(), v.end(), x) - v.begin() + 1; } n int get_id(int x) { return upper_bound(v.begin(), v.end(), x) - v.begin() + 1; } n int getid2(int x) { n   return lower_bound(v2.begin(), v2.end(), x) - v2.begin() + 1; n } n void PushUp(int rt) { sum[rt] = sum[rt << 1] + sum[rt << 1 | 1]; } n void PushDown(int rt, int m, int l, int r) { n   if (fabs(add[rt] - 1) > 0.00001) { n     add[rt << 1] *= add[rt]; n     add[rt << 1 | 1] *= add[rt]; n     sum[rt << 1] *= add[rt]; n     sum[rt << 1 | 1] *= add[rt]; n     add[rt] = 1; n   } n } n void build(int l, int r, int rt) { n   add[rt] = 1; n   sum[rt] = 0; n   if (l == r) { n     if (v2[getid2(v[l - 1]) - 1] == v[l - 1]) { n       sum[rt] = b[v[l - 1]]; n     } else n       sum[rt] = 0; n     return; n   } n   int m = (l + r) >> 1; n   build(l, m, rt << 1); n   build(m + 1, r, rt << 1 | 1); n   PushUp(rt); n } n void upedit(int L, int R, double c, int l, int r, int rt) { n   if (L <= l && r <= R) { n     add[rt] *= c; n     sum[rt] *= c; n     return; n   } n   int m = (l + r) >> 1; n   PushDown(rt, m, l, r); n   if (L <= m) upedit(L, R, c, l, m, rt << 1); n   if (m < R) upedit(L, R, c, m + 1, r, rt << 1 | 1); n   PushUp(rt); n } n double query(int L, int R, int l, int r, int rt) { n   if (L <= l && r <= R) { n     return sum[rt]; n   } n   int m = (l + r) >> 1; n   PushDown(rt, m, l, r); n   double ret = 0; n   if (L <= m) ret += query(L, R, l, m, rt << 1); n   if (m < R) ret += query(L, R, m + 1, r, rt << 1 | 1); n   return ret; n } n int main() { n   ios::sync_with_stdio(false), cin.tie(0); n   int n, m, k, kk; n   cin >> n >> m; n   for (int i = 1; i <= n; i++) { n     cin >> a[i].pos >> a[i].h >> a[i].l >> a[i].r; n     v.push_back(a[i].pos); n     v.push_back(a[i].pos + a[i].h); n     v.push_back(a[i].pos - a[i].h); n   } n   for (int i = 1; i <= m; i++) { n     cin >> k >> kk, v.push_back(k), v2.push_back(k); n     b[k] += kk; n   } n   sort(v.begin(), v.end()), v.erase(unique(v.begin(), v.end()), v.end()); n   sort(v2.begin(), v2.end()), v2.erase(unique(v2.begin(), v2.end()), v2.end()); n   int sz = v.size(); n   build(1, sz, 1); n   for (int i = 1; i <= n; i++) { n     int L = getid(a[i].pos - a[i].h); n     int R = get_id(a[i].pos + a[i].h) - 1; n     int M = getid(a[i].pos); n     if (L < M) { n       upedit(L, M - 1, 1 - a[i].l * 1.0 / 100, 1, sz, 1); n     } n     if (R > M) { n       upedit(M + 1, R, 1 - a[i].r * 1.0 / 100, 1, sz, 1); n     } n   } n   printf( %.5f n , sum[1]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int x[55][55], a, b, n, m; n int solve() { n   int res = 1000000000; n   for (int _n((n - a + 1) - 1), i(0); i <= _n; i++) n     for (int _n((m - b + 1) - 1), j(0); j <= _n; j++) { n       int cnt = 0; n       for (int _n((a)-1), k(0); k <= _n; k++) n         for (int _n((b)-1), t(0); t <= _n; t++) cnt += x[i + k][j + t]; n       res = min(res, cnt); n     } n   return res; n } n int main() { n   scanf( %d%d , &n, &m); n   for (int _n((n)-1), i(0); i <= _n; i++) n     for (int _n((m)-1), j(0); j <= _n; j++) scanf( %d , &x[i][j]); n   scanf( %d%d , &a, &b); n   int r1 = solve(); n   swap(a, b); n   int r2 = solve(); n   cout << min(r1, r2) << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int dp[550005]; n int main() { n   int n, d, c, i, j, x, flog; n   scanf( %d %d , &n, &d); n   dp[0] = 1; n   for (i = 0; i < n; i++) { n     scanf( %d , &c); n     for (j = 500000; j >= c; j--) { n       dp[j] |= dp[j - c]; n     } n   } n   int day = 0; n   x = 0; n   while (1) { n     flog = 0; n     for (j = x + d; j > x; j--) { n       if (dp[j]) { n         flog = 1; n         day++; n         x = j; n         break; n       } n     } n     if (!flog) break; n   } n   printf( %d %d n , x, day); n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n T in() { n   char ch; n   T n = 0; n   bool ng = false; n   while (1) { n     ch = getchar(); n     if (ch ==  - ) { n       ng = true; n       ch = getchar(); n       break; n     } n     if (ch >=  0  && ch <=  9 ) break; n   } n   while (1) { n     n = n * 10 + (ch -  0 ); n     ch = getchar(); n     if (ch <  0  || ch >  9 ) break; n   } n   return (ng ? -n : n); n } n template <typename T> n inline T Dist(T x1, T y1, T x2, T y2) { n   return sqrt((x1 - x2 * x1 - x2) + (y1 - y2 * y1 - y2)); n } n template <typename T> n inline T POW(T B, T P) { n   if (P == 0) return 1; n   if (P & 1) n     return B * POW(B, P - 1); n   else n     return (POW(B, P / 2) * POW(B, P / 2)); n } n template <typename T> n inline T ABS(T a) { n   if (a < 0) n     return -a; n   else n     return a; n } n template <typename T> n inline T Gcd(T a, T b) { n   if (a < 0) return Gcd(-a, b); n   if (b < 0) return Gcd(a, -b); n   return (b == 0) ? a : Gcd(b, a % b); n } n template <typename T> n inline T Lcm(T a, T b) { n   if (a < 0) return Lcm(-a, b); n   if (b < 0) return Lcm(a, -b); n   return a * (b / Gcd(a, b)); n } n long long Bigmod(long long base, long long power, long long MOD) { n   long long ret = 1; n   while (power) { n     if (power & 1) ret = (ret * base) % MOD; n     base = (base * base) % MOD; n     power >>= 1; n   } n   return ret; n } n long long ModInverse(long long number, long long MOD) { n   return Bigmod(number, MOD - 2, MOD); n } n int Set(int N, int pos) { return N = N | (1 << pos); } n int Reset(int N, int pos) { return N = N & ~(1 << pos); } n bool Chkbit(int N, int pos) { return (bool)(N & (1 << pos)); } n bool isVowel(char ch) { n   ch = toupper(ch); n   if (ch ==  A  || ch ==  U  || ch ==  I  || ch ==  O  || ch ==  E ) n     return true; n   return false; n } n bool isConst(char ch) { n   if (isalpha(ch) && !isVowel(ch)) return true; n   return false; n } n int toInt(string s) { n   int sm; n   stringstream ss(s); n   ss >> sm; n   return sm; n } n long long int toLlint(string s) { n   long long int sm; n   stringstream ss(s); n   ss >> sm; n   return sm; n } n template <typename T> n long long int isLeft(T a, T b, T c) { n   return (a.x - b.x) * (b.y - c.y) - (b.x - c.x) * (a.y - b.y); n } n long long int a[300005], b[300005]; n int n, m; n int Check(long long int x) { n   int pos = 1; n   for (int i = 1; i <= n; i++) { n     if (pos <= m && b[pos] <= a[i] && (a[i] - b[pos]) > x) return 0; n     if (a[i] < b[pos]) { n       while (pos <= m && b[pos] - a[i] <= x) pos++; n     } else { n       int now = pos; n       pos++; n       while (pos <= m) { n         long long int p = (a[i] - b[now]) * 2LL + (-a[i] + b[pos]); n         long long int q = (a[i] - b[now]) + 2LL * (-a[i] + b[pos]); n         if (min(p, q) > x) break; n         pos++; n       } n     } n   } n   return (pos > m); n } n int main() { n   n = in<int>(), m = in<int>(); n   int id = 0; n   for (int i = 1; i < n + 1; i++) { n     a[i] = in<long long int>(); n   } n   for (int i = 1; i < m + 1; i++) { n     b[i] = in<long long int>(); n   } n   long long int L = 0, R = 100000000000000, ans, mid; n   while (L <= R) { n     mid = (L + R) / 2LL; n     if (Check(mid)) { n       R = mid - 1LL; n       ans = mid; n     } else { n       L = mid + 1LL; n     } n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MOD = 1000000007; n int main() { n   int a[1010], b[1010]; n   int n; n   while (cin >> n) { n     for (int i = 0; i < n; i++) cin >> a[i] >> b[i]; n     int ans = 0; n     for (int i = 0; i < n; i++) { n       int s = a[i]; n       while (s <= ans) s += b[i]; n       ans = s; n     } n     cout << ans << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int M = 100010; n int n, i, Ans, b[M], pos[M]; n long long A, w1, w2, m, ans, s[M]; n struct shit { n   long long w; n   int id; n } a[M]; n bool cmp(shit x, shit y) { return x.w > y.w; } n int main() { n   scanf( %d%I64d%I64d%I64d%I64d , &n, &A, &w1, &w2, &m); n   for (i = 1; i <= n; i++) { n     scanf( %d , &a[i].w); n     a[i].id = i; n   } n   sort(a + 1, a + n + 1, cmp); n   for (i = 1; i <= n; i++) s[i] = a[i].w + s[i - 1]; n   if (m + s[n] - A * n >= 0) { n     printf( %I64d n , w1 * n + w2 * A); n     for (i = 1; i <= n; i++) printf( %d  , A); n     puts(  ); n     return 0; n   } n   int now = 1; n   for (i = 0; i < n; i++) { n     if (m - A * i + s[i] < 0) break; n     while (now <= i || n            a[now].w * (n - now + 1) - s[n] + s[now - 1] > m - A * i + s[i]) n       now++; n     pos[i] = now; n     long long tmp = (m - A * i + s[i] + s[n] - s[now - 1]) / (n - now + 1); n     if (w1 * i + w2 * tmp > ans) ans = w1 * i + w2 * tmp, Ans = i; n   } n   printf( %I64d n , ans); n   long long p = n       (m - A * Ans + s[Ans] + s[n] - s[pos[Ans] - 1]) / (n - pos[Ans] + 1); n   for (i = 1; i <= Ans; i++) b[a[i].id] = A; n   for (i = Ans + 1; i < pos[Ans]; i++) b[a[i].id] = a[i].w; n   for (i = pos[Ans]; i <= n; i++) b[a[i].id] = p; n   for (i = 1; i <= n; i++) printf( %d  , b[i]); n   puts(  ); n } n


#include <bits/stdc++.h> n using namespace std; n int n; n vector<int> A(100); n bool f(int m) { n   int k1 = 0, k2 = 0; n   for (int i = 0; i < n; i++) { n     k1 += A[i]; n     k2 += m - A[i]; n   } n   if (k2 > k1) n     return true; n   else n     return false; n } n int main() { n   cin >> n; n   int MAX = -1; n   for (int i = 0; i < n; i++) { n     cin >> A[i]; n     if (A[i] > MAX) MAX = A[i]; n   } n   int l = MAX - 1, r = 201; n   while (r - l > 1) { n     int m = (l + r) / 2; n     if (f(m)) n       r = m; n     else n       l = m; n   } n   cout << r; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, a[105][105]; n inline int get(int x, int y) { n   bool vis[11]; n   for (register int i = 0; i <= 10; i++) vis[i] = 0; n   vis[a[x - 1][y]] = vis[a[x + 1][y]] = vis[a[x][y - 1]] = vis[a[x][y + 1]] = 1; n   for (register int i = 1; i <= 10; i++) { n     if (!vis[i]) return i; n   } n   return 0; n } n inline void draw(int x, int y, int p, int sign) { n   for (register int i = 0; i < p; i++) { n     for (register int j = 0; j < p; j++) { n       a[x + i][y + j] = sign; n     } n   } n } n inline void slove(int x, int y) { n   if (y > m) { n     y = 1; n     x = x + 1; n   } n   if (x > n) return; n   if (a[x][y]) { n     slove(x, y + 1); n     return; n   } n   int p = 1, sign = get(x, y); n   while (1) { n     if (x + p > n || y + p > m) break; n     if (a[x][y + p]) break; n     int tmp = get(x, y + p); n     if (tmp != sign) break; n     p++; n   } n   draw(x, y, p, sign); n   slove(x, y + 1); n } n int main() { n   scanf( %d%d , &n, &m); n   slove(1, 1); n   for (register int i = 1; i <= n; i++) { n     for (register int j = 1; j <= m; j++) { n       printf( %c , (a[i][j] - 1 +  A )); n     } n     printf(  n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long INF = 1e9; n const int MAX = 1e5 + 7, N = 1e5 + 3; n double pi = acos(-1); n long long r, l, k, m, n, ans; n int main() { n   cin >> n; n   cin >> k >> l; n   long long m1 = k - 1 + l - 1; n   long long m2 = n - k + n - l; n   if (m1 <= m2) { n     cout <<  White  << endl; n   } else { n     cout <<  Black  << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char _c; n bool _f; n template <class T> n inline void IN(T &x) { n   x = 0, _f = 0; n   while (_c = getchar(), !isdigit(_c)) n     if (_c ==  - ) _f = 1; n   while (isdigit(_c)) x = x * 10 + _c -  0 , _c = getchar(); n   if (_f) x = -x; n } n template <class T> n inline void chkmax(T &x, T y) { n   if (x < y) x = y; n } n template <class T> n inline void chkmin(T &x, T y) { n   if (x > y) x = y; n } n const int N = 5e5 + 5; n const int mod = 1e9 + 7; n int mul(int x, int y) { return 1ll * x * y % mod; } n int n, cnt = 1, dep[N], parent[N], head[N]; n int fa[N << 1], tof[N], nxt[N << 1], pre[N << 1], st[N], ed[N], deg[N]; n struct Edge { n   int nxt, to; n } G[N << 1]; n void addedge(int u, int v) { n   G[++cnt] = (Edge){head[u], v}, head[u] = cnt, ++deg[u]; n   G[++cnt] = (Edge){head[v], u}, head[v] = cnt, ++deg[v]; n } n void dfs(int u, int lst) { n   parent[u] = lst, dep[u] = dep[lst] + 1; n   for (int v, i = head[u]; i; i = G[i].nxt) n     if (v = G[i].to, v != lst) dfs(v, u), tof[v] = i ^ 1; n } n int find(int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); } n bool merge(int x, int y) { n   x = find(x), y = find(y); n   return (x == y) ? false : (fa[x] = y, true); n } n void solve(int x, int y) { n   std ::stack<int> s; n   std ::queue<int> q; n   const int _x = x, _y = y; n   while (dep[x] > dep[y]) q.push(tof[x]), --deg[x], x = parent[x]; n   while (dep[x] < dep[y]) s.push(tof[y]), --deg[y], y = parent[y]; n   while (x != y) { n     q.push(tof[x]), --deg[x], x = parent[x]; n     s.push(tof[y]), --deg[y], y = parent[y]; n   } n   --deg[x]; n   while (!s.empty()) q.push(s.top() ^ 1), s.pop(); n   int lst = q.front(); n   q.pop(); n   if (st[_x] || pre[lst]) { n     puts( 0 ); n     exit(0); n   }; n   st[_x] = lst, pre[lst] = -1; n   while (!q.empty()) { n     int now = q.front(); n     q.pop(), lst ^= 1; n     if (pre[now] || nxt[lst] || !merge(lst, now)) { n       puts( 0 ); n       exit(0); n     }; n     pre[now] = lst, nxt[lst] = now, lst = now; n   } n   lst ^= 1; n   if (ed[_y] || nxt[lst]) { n     puts( 0 ); n     exit(0); n   }; n   ed[_y] = lst, nxt[lst] = -1; n   return; n } n int u, v, a[N]; n int fac(int x) { return x == 0 ? 1 : mul(x, fac(x - 1)); } n int main() { n   IN(n); n   for (int i = 1; i <= n - 1; ++i) IN(u), IN(v), addedge(u, v); n   for (int i = 1; i <= cnt; ++i) fa[i] = i; n   dfs(1, 0); n   for (int i = 1; i <= n; ++i) IN(a[i]); n   for (int i = 1; i <= n; ++i) n     if (a[i] == i) { n       puts( 0 ); n       exit(0); n     }; n   for (int i = 1; i <= n; ++i) n     if (a[i]) solve(a[i], i); n   int ans = 1; n   for (int i = 1; i <= n; ++i) { n     if (st[i] && ed[i]) n       if (find(st[i]) == find(ed[i]) && ~deg[i]) { n         puts( 0 ); n         exit(0); n       }; n     ans = mul(ans, fac(deg[i] == -1 ? 1 : deg[i])); n   } n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n void pr(vector<T> &v) { n   for (int i = 0; i < (int)(v).size(); i++) cout << v[i] <<    ; n   cout << endl; n } n template <typename T> n void pr(vector<vector<T>> &v) { n   for (int i = 0; i < (int)(v).size(); i++) { n     pr(v[i]); n   } n } n template <typename T> n void re(T &first) { n   cin >> first; n } n template <typename T> n void re(vector<T> &a) { n   for (int i = 0; i < (int)(a).size(); i++) re(a[i]); n } n template <class Arg, class... Args> n void re(Arg &first, Args &...rest) { n   re(first); n   re(rest...); n } n template <typename T> n void pr(T first) { n   cout << first << endl; n } n template <class Arg, class... Args> n void pr(const Arg &first, const Args &...rest) { n   cout << first <<    ; n   pr(rest...); n   cout << endl; n } n void ps() { cout << endl; } n template <class T, class... Ts> n void ps(const T &t, const Ts &...ts) { n   cout << t; n   if (sizeof...(ts)) cout <<    ; n   ps(ts...); n } n void solve() { n   int n; n   re(n); n   pr(1 + 3 * (n + 1)); n   ps(0, 0); n   for (int i = 0; i < n + 1; i++) { n     ps(i, i + 1); n     ps(i + 1, i + 1); n     ps(i + 1, i); n   } n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int t = 1; n   for (int tt = 0; tt < t; tt++) { n     solve(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int const N = 100000; n int n; n int ans; n char digits[8][8]; n int ten[8]; n bitset<N> isprime; n int sum[8]; n struct Integer { n   int i, j, x; n   Integer(int i, int j, int x) : i(i), j(j), x(x) {} n   operator int() { return x; } n   Integer(int x = 0) : x(x), i(-1), j(-1) {} n   void operator=(int other) { n     if (i >= 0) { n       sum[i] -= x * ten[n - 1 - j]; n       sum[j] -= x * ten[n - 1 - i]; n       x = other; n       sum[i] += x * ten[n - 1 - j]; n       sum[j] += x * ten[n - 1 - i]; n     } else { n       x = other; n     } n   } n }; n template <class T> n struct Counter { n   vector<int> bnd; n   vector<T> value; n   Counter<T>(vector<int> bnd) : bnd(bnd), value(bnd.size(), 0) {} n   bool operator++(int) { n     int n = bnd.size(); n     int add = -1; n     for (int i = n - 1; i >= 0; --i) { n       if ((int)value[i] != bnd[i] - 1) { n         add = i; n         break; n       } n     } n     if (add == -1) { n       return false; n     } n     value[add] = value[add] + 1; n     for (int i = add + 1; i < n; ++i) { n       value[i] = 0; n     } n     return true; n   } n   T &operator[](int x) { return value[x]; } n }; n int count_valid_after_fill[8][N]; n int main() { n   isprime.set(); n   isprime[0] = isprime[1] = false; n   for (int i = 4; i < isprime.size(); i += 2) isprime[i] = false; n   for (int i = 3; i < isprime.size(); i += 2) n     if (isprime[i]) { n       for (int k = i * 3; k < isprime.size(); k += i + i) isprime[k] = false; n     } n   ten[0] = 1; n   for (int i = 1; i < 8; ++i) { n     ten[i] = ten[i - 1] * 10; n   } n   memset(count_valid_after_fill, 0, (sizeof count_valid_after_fill)); n   for (int i = 0; i < isprime.size(); ++i) { n     for (int p = 0; p < 5; ++p) { n       int x = i; n       if (x / ten[p] % 10 == 0) { n         for (int n_ = (10), k = 0; k < n_; ++k) { n           if (x < ((int)(isprime).size()) && isprime[x]) { n             count_valid_after_fill[p][i]++; n           } n           x += ten[p]; n         } n       } n     } n   } n   int ca; n   cin >> ca; n   for (int n_ = (ca), ica = 0; ica < n_; ++ica) { n     string input; n     cin >> input; n     n = input.size(); n     memset(digits, 0, (sizeof digits)); n     memset(sum, 0, (sizeof sum)); n     for (int n_ = (n), i = 0; i < n_; ++i) { n       digits[0][i] = digits[i][0] = input[i] -  0 ; n       sum[0] += ten[n - 1 - i] * digits[i][0]; n       if (i != 0) { n         sum[i] += ten[n - 1] * digits[i][0]; n       } n     } n     vector<int> bnd((n - 1) * (n - 2) / 2, 10); n     Counter<Integer> counter(bnd); n     int p = 0; n     for (int i = 1; i < n; ++i) { n       for (int j = i + 1; j < n; ++j) { n         counter[p] = Integer(i, j, 0); n         p++; n       } n     } n     int ans = 0; n     do { n       int way = 1; n       for (int i = 1; i < n; ++i) { n         int way2 = count_valid_after_fill[n - 1 - i][sum[i]]; n         way *= way2; n       } n       ans += way; n     } while (counter++); n     cout << ans << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long GCD(long long x, long long y) { n   if (y == 0) return x; n   return GCD(y, x % y); n } n long long LCM(long long x, long long y) { return (x * y) / (GCD(x, y)); } n long long LOGK(long long x, long long k) { n   if (x >= k) return 1 + LOGK(x / k, k); n   return 0; n } n long long MPOW(long long a, long long b, long long m) { n   if (b == 0) return 1; n   long long x = MPOW(a, b / 2, m); n   x = (x * x) % m; n   if (b % 2 == 1) x = (x * a) % m; n   return x; n } n int main() { n   long long test = 1; n   while (test--) { n     long long n; n     cin >> n; n     long long ar[n + 1]; n     long long dp[n + 1]; n     dp[0] = 1; n     for (long long i = 1; i <= n; i++) dp[i] = 0; n     long long ans = 0; n     for (long long i = 1; i <= n; i++) { n       cin >> ar[i]; n       vector<long long> g; n       for (long long j = 1; j <= (long long)(sqrt(ar[i])); j++) { n         if (ar[i] % j == 0) { n           g.push_back(j); n           if (ar[i] / j != j) { n             g.push_back(ar[i] / j); n           } n         } n       } n       sort(g.begin(), g.end()); n       reverse(g.begin(), g.end()); n       for (auto it : g) { n         if (it <= n) { n           dp[it] += dp[it - 1]; n           dp[it] %= 1000000007; n         } n       } n     } n     for (long long i = 1; i <= n; i++) { n       ans += dp[i]; n       ans %= 1000000007; n     } n     cout << ans; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int mod = 1e9 + 7; n long long t, n; n long long quickpower(int a, int b) { n   long long res = 1; n   while (b) { n     if (b % 2 == 1) res *= a; n     a *= a; n     b >>= 1; n   } n   return res; n } n int main() { n   cin >> t; n   while (t--) { n     cin >> n; n     long long r = 0; n     for (int i = 2;; i++) { n       r = quickpower(2, i) - 1; n       if (n % r == 0) { n         cout << n / r << endl; n         break; n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n T gcd(T a, T b) { n   return b == 0 ? a : gcd(b, a % b); n } n const int MAXN = 1e5 + 1e4; n int n, pos_ = 0; n vector<int> g[MAXN]; n vector<int> a[MAXN]; n vector<int> ans; n vector<vector<int>> t(4 * MAXN); n vector<int> parent(MAXN), depth(MAXN), heavy(MAXN, -1), pos(MAXN), head(MAXN); n int dfs(int v) { n   int sz = 1; n   int h_sz = 0; n   for (int u : g[v]) { n     if (parent[v] == u) { n       continue; n     } n     parent[u] = v; n     depth[u] = depth[v] + 1; n     int cur_sz = dfs(u); n     sz += cur_sz; n     if (h_sz < cur_sz) { n       h_sz = cur_sz; n       heavy[v] = u; n     } n   } n   return sz; n } n void hld(int v, int root) { n   head[v] = root; n   pos[v] = pos_++; n   ; n   if (heavy[v] != -1) { n     hld(heavy[v], root); n   } n   for (int u : g[v]) { n     if (u == heavy[v] || u == parent[v]) { n       continue; n     } n     hld(u, u); n   } n } n void build(int v = 1, int l = 0, int r = n) { n   if (r - l == 1) { n     t[v] = a[l]; n     while (((int32_t)(t[v]).size()) > 10) { n       t[v].pop_back(); n     }; n     return; n   } n   int m = (l + r) / 2; n   build(v * 2, l, m); n   build(v * 2 + 1, m, r); n   t[v].resize(20, INT_MAX); n   merge((t[v * 2]).begin(), (t[v * 2]).end(), (t[v * 2 + 1]).begin(), n         (t[v * 2 + 1]).end(), t[v].begin()); n   while (((int32_t)(t[v]).size()) > 10 || n          t[v][((int32_t)(t[v]).size()) - 1] == INT_MAX) { n     t[v].pop_back(); n   } n } n void get_ans(int ql, int qr, int v = 1, int l = 0, int r = n) { n   if (ql <= l && r <= qr) { n     vector<int> ans_new(20, INT_MAX); n     merge((ans).begin(), (ans).end(), (t[v]).begin(), (t[v]).end(), n           ans_new.begin()); n     for (int i = 0; i < 20; i++) { n       ; n     } n     while (((int32_t)(ans_new).size()) > 10 || n            ans_new[((int32_t)(ans_new).size()) - 1] == INT_MAX) { n       ans_new.pop_back(); n     } n     ans = ans_new; n     return; n   } n   if (qr <= l || r <= ql) { n     return; n   } n   int m = (l + r) / 2; n   get_ans(ql, qr, v * 2, l, m); n   get_ans(ql, qr, v * 2 + 1, m, r); n } n void query(int a, int b) { n   while (head[a] != head[b]) { n     if (depth[head[a]] > depth[head[b]]) { n       swap(a, b); n     }; n     get_ans(pos[head[b]], pos[b] + 1); n     b = parent[head[b]]; n   } n   if (depth[a] > depth[b]) { n     swap(a, b); n   }; n   get_ans(pos[a], pos[b] + 1); n } n int32_t main() { n   { n     cin.tie(0); n     cout.tie(0); n     ios_base::sync_with_stdio(0); n   }; n   int m, q; n   cin >> n >> m >> q; n   for (int i = 1; i < n; i++) { n     int v, u; n     cin >> v >> u; n     v--; n     u--; n     g[u].push_back(v); n     g[v].push_back(u); n   } n   dfs(0); n   hld(0, 0); n   for (int i = 0; i < m; i++) { n     int tmp; n     cin >> tmp; n     ; n     a[pos[tmp - 1]].push_back(i + 1); n   } n   build(); n   while (q--) { n     int v, u, a; n     cin >> v >> u >> a; n     v--; n     u--; n     ans.clear(); n     query(v, u); n     ; n     int k = min(a, ((int32_t)(ans).size())); n     cout << k; n     for (int i = 0; i < k; i++) { n       cout <<     << ans[i]; n     } n     cout <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, a, b, m = 0, c = 0; n   scanf( %d , &n); n   while (n--) { n     scanf( %d%d , &a, &b); n     if (a > b) { n       m++; n     } else if (a < b) { n       c++; n     } n   } n   if (m > c) { n     printf( Mishka ); n   } else if (m < c) { n     printf( Chris ); n   } else { n     printf( Friendship is magic!^^ ); n   } n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( O3 ) n #pragma GCC optimize( unroll-loops ) n #pragma GCC optimize( -Ofast ) n using namespace std; n void rearrange(long long arr[], long long n) { n   long long temp[n]; n   long long small = 0, large = n - 1; n   long long flag = true; n   for (long long i = 0; i < n; i++) { n     if (flag) n       temp[i] = arr[large--]; n     else n       temp[i] = arr[small++]; n     flag = !flag; n   } n   for (long long i = 0; i < n; i++) arr[i] = temp[i]; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   string a; n   cin >> a; n   long long k, i; n   cin >> k; n   long long snow = 0, candy = 0; n   for (i = 0; i < a.size(); i++) { n     if (a[i] ==  * ) n       snow++; n     else if (a[i] ==  ? ) n       candy++; n   } n   long long cha = k - (a.size() - snow - candy); n   if (cha > 0) { n     if (snow == 0) n       cout <<  Impossible ; n     else { n       string ans =   ; n       for (i = a.size() - 1; i >= 0; i--) { n         if (a[i] ==  ? ) continue; n         if (a[i] ==  * ) { n           while (cha > 0) { n             ans = ans + a[i - 1]; n             cha--; n           } n         } else { n           ans = ans + a[i]; n         } n       } n       reverse(ans.begin(), ans.end()); n       cout << ans; n     } n   } else { n     if (a.size() - 2 * snow - 2 * candy > k) n       cout <<  Impossible ; n     else { n       vector<char> v(a.size(),  1 ); n       for (i = a.size() - 1; i >= 0; i--) { n         if (a[i] ==  ?  || a[i] ==  * ) { n           i--; n         } else { n           v[i] = a[i]; n           k--; n         } n       } n       for (i = a.size() - 1; i >= 0; i--) { n         if (k > 0 && (a[i] ==  ?  || a[i] ==  * )) { n           k--; n           v[i] = a[i - 1]; n         } n       } n       for (i = 0; i < a.size(); i++) { n         if (v[i] !=  1 ) cout << v[i]; n       } n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long pow = 1; n   long long L, R; n   cin >> L >> R; n   while (pow * 10 <= R) pow *= 10; n   if (L < pow) { n     if (R < pow * 5) n       cout << R * (pow * 10 - 1 - R) << endl; n     else n       cout << pow * 5 * (pow * 5 - 1) << endl; n   } else { n     if (R >= pow * 5 && L <= pow * 5) n       cout << pow * 5 * (pow * 5 - 1) << endl; n     else n       cout << max(R * (pow * 10 - 1 - R), L * (pow * 10 - 1 - L)) << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, l, k, ultim; n map<int, int> cnt; n int main() { n   cin >> n >> k; n   for (int i = 0; i <= 63; i++) n     if ((n >> i) & 1) cnt[i]++, l++; n   if (l > k) { n     cout <<  No ; n     return 0; n   } n   for (int i = 63; i >= -63; i--) { n     if (l + cnt[i] <= k) n       l += cnt[i], cnt[i - 1] += cnt[i] * 2, cnt[i] = 0; n     else n       break; n   } n   multiset<int> ms; n   multiset<int>::iterator it; n   for (int i = 63; i >= -63; i--) n     for (int j = 0; j < cnt[i]; j++) ms.insert(i); n   while (ms.size() < k) { n     it = ms.begin(); n     int u = *it; n     ms.erase(it); n     ms.insert(u - 1); n     ms.insert(u - 1); n   } n   cout <<  Yes n ; n   for (auto it = ms.rbegin(); it != ms.rend(); it++) { n     cout << *it <<    ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void in(int &x) { n   register int c = getchar(); n   x = 0; n   for (; (c < 48 || c > 57); c = getchar()) n     ; n   for (; c > 47 && c < 58; c = getchar()) { n     x = (x << 1) + (x << 3) + c - 48; n   } n } n const int N = 1 << 24; n long long dp[N]; n string s[10004]; n int main() { n   int n, i, j, mask, full = N - 1; n   in(n); n   for (i = 0; i < n; i++) { n     cin >> s[i]; n     mask = 0; n     for (j = 0; j < 3; j++) mask |= 1 << (s[i][j] -  a ); n     mask ^= full; n     dp[mask]++; n   } n   for (i = 0; i < 24; i++) { n     for (mask = N - 1; mask >= 0; mask--) n       if (mask & (1 << i)) { n         dp[mask ^ (1 << i)] += dp[mask]; n       } n   } n   long long ret = 0; n   for (i = 0; i < N; i++) ret ^= 1ll * (n - dp[i]) * (n - dp[i]); n   printf( %lld n , ret); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n bool chkmax(T &x, T y) { n   return x < y ? x = y, true : false; n } n template <typename T> n bool chkmin(T &x, T y) { n   return x > y ? x = y, true : false; n } n int readint() { n   int x = 0, f = 1; n   char ch = getchar(); n   while (ch <  0  || ch >  9 ) { n     if (ch ==  - ) f = -1; n     ch = getchar(); n   } n   while (ch >=  0  && ch <=  9 ) { n     x = x * 10 + ch -  0 ; n     ch = getchar(); n   } n   return x * f; n } n int n, m, rt; n long long a[4005], rmq[4005][20], ch[4005][2], lg2[4005], siz[4005]; n long long d[4005][4005]; n int getmin(int l, int r) { n   int k = lg2[r - l + 1]; n   return a[rmq[l][k]] < a[rmq[r - (1 << k) + 1][k]] ? rmq[l][k] n                                                     : rmq[r - (1 << k) + 1][k]; n } n int build(int l, int r) { n   int mid = getmin(l, r); n   if (l != mid) ch[mid][0] = build(l, mid - 1); n   if (r != mid) ch[mid][1] = build(mid + 1, r); n   return mid; n } n void dfs(int u) { n   if (!u) return; n   siz[u] = 1; n   dfs(ch[u][0]), dfs(ch[u][1]); n   siz[u] += siz[ch[u][0]] + siz[ch[u][1]]; n   for (int i = 0; i <= siz[ch[u][0]]; i++) { n     for (int j = 0; j <= siz[ch[u][1]]; j++) { n       chkmax(d[u][i + j], d[ch[u][0]][i] + d[ch[u][1]][j] - 2ll * i * j * a[u]); n       chkmax(d[u][i + j + 1], d[ch[u][0]][i] + d[ch[u][1]][j] - n                                   2ll * i * j * a[u] + 1ll * (m - 1) * a[u] - n                                   2ll * (i + j) * a[u]); n     } n   } n } n int main() { n   n = readint(); n   m = readint(); n   for (int i = 1; i <= n; i++) a[i] = readint(); n   for (int i = 2; i <= n; i++) lg2[i] = lg2[i >> 1] + 1; n   for (int i = 1; i <= n; i++) rmq[i][0] = i; n   for (int i = 1; (1 << i) <= n; i++) n     for (int j = 1; j + (1 << i) - 1 <= n; j++) n       rmq[j][i] = a[rmq[j][i - 1]] < a[rmq[j + (1 << (i - 1))][i - 1]] n                       ? rmq[j][i - 1] n                       : rmq[j + (1 << (i - 1))][i - 1]; n   rt = build(1, n); n   for (int i = 0; i <= n; i++) n     for (int j = 0; j <= n; j++) d[i][j] = -(1ll << 60); n   d[0][0] = 0; n   dfs(rt); n   printf( %lld n , d[rt][m]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline int inp() { return 0; } n inline int inp(bool& A) { n   if (cin >> A) return 1; n   return -1; n } n inline int inp(char& A) { return scanf(  %c , &A); } n inline int inp(int& A) { return scanf( %d , &A); } n inline int inp(float& A) { n   if (cin >> A) return 1; n   return -1; n } n inline int inp(long long& A) { return scanf( %I64d , &A); } n inline int inp(double& A) { return scanf( %lf , &A); } n inline int inp(char* A) { return scanf( %s , A); } n inline int inp(string& A) { n   if (cin >> A) return 1; n   return -1; n } n template <class Front, class... Queue> n inline int inp(Front& A, Queue&... B) { n   return inp(A) + inp(B...); n } n inline int oup() { return 0; } n inline int oup(bool A) { n   if (cout << A) return 1; n   return -1; n } n inline int oup(char A) { return printf( %c , A); } n inline int oup(int A) { return printf( %d , A); } n inline int oup(float A) { n   if (cout << A) return 1; n   return -1; n } n inline int oup(long long A) { return printf( %I64d , A); } n inline int oup(double A) { return printf( %lf , A); } n inline int oup(char* A) { return printf(A); } n inline int oup(const char* A) { return printf( %s , A); } n inline int oup(string& A) { n   if (cout << A) return 1; n   return -1; n } n template <class Front, class... Queue> n inline int oup(Front A, Queue... B) { n   return oup(A) + oup(B...); n } n template <class T> n inline void remax(T& A, T B) { n   if (A < B) A = B; n } n template <class T> n inline void remin(T& A, T B) { n   if (A > B) A = B; n } n string ToString(long long num) { n   string ret; n   do { n     ret += ((num % 10) +  0 ); n     num /= 10; n   } while (num); n   reverse(ret.begin(), ret.end()); n   return ret; n } n long long ToNumber(string s) { n   long long r = 0, p = 1; n   for (int i = s.size() - 1; i >= 0; --i) r += (s[i] -  0 ) * p, p *= 10; n   return r; n } n long long Gcd(long long a, long long b) { n   while (a %= b ^= a ^= b ^= a) n     ; n   return b; n } n long long Power(long long base, long long power) { n   long long ret = 1; n   while (power) { n     if (power & 1) ret *= base; n     power >>= 1; n     base *= base; n   } n   return ret; n } n long long PowerMod(long long base, long long power, long long mod) { n   if (!power) return 1; n   if (power & 1) return (base * PowerMod(base, power - 1, mod)) % mod; n   return PowerMod((base * base) % mod, power >> 1, mod); n } n int Log(long long num, long long base) { n   int ret = 0; n   while (num) { n     ++ret; n     num /= base; n   } n   return ret; n } n int Count(long long mask) { n   int ret = 0; n   while (mask) { n     if (mask & 1) ++ret; n     mask >>= 1; n   } n   return ret; n } n inline void run() { n in:; n   int n, m, v; n   if (inp(n, m, v) != 3) return; n   if (m < n - 1) { n     oup( -1 n ); n     return; n   } n   if (m > (((n - 1) * (n - 2)) >> 1) + 1) { n     oup( -1 n ); n     return; n   } n   int tmp = 1; n   if (v == 1) ++tmp; n   for (int i = 1; i <= n; ++i) n     if (i != v) oup(i,    , v,   n ); n   m -= n - 1; n   for (int i = 1; i <= n && m; ++i) n     if (i != v && i != tmp) n       for (int j = i + 1; j <= n && m; ++j) n         if (j != v && j != tmp) { n           oup(i,    , j,   n ); n           --m; n         } n   goto in; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr), cout.tie(nullptr); n   run(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string ans =   , s; n   int n; n   cin >> s >> n; n   for (int i = 0; i < n; i++) { n     string t; n     cin >> t; n     if (t.length() >= s.length()) n       if (s == t.substr(0, s.length())) n         if (ans ==    || ans > t) ans = t; n   } n   if (ans ==   ) n     cout << s << endl; n   else n     cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n inline bool valid(int64_t x, int64_t y, int64_t n, int64_t m) { n   return (x >= 0 && x < n && y >= 0 && y < m); n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int64_t n, m, q; n   cin >> n >> m >> q; n   vector<string> v(n); n   for (int64_t i = 0; i < n; ++i) { n     cin >> v[i]; n   } n   int64_t dx[4] = {-1, 1, 0, 0}; n   int64_t dy[4] = {0, 0, -1, 1}; n   queue<pair<int64_t, int64_t> > qu; n   vector<vector<int64_t> > dis(n, vector<int64_t>(m, -1)); n   for (int64_t i = 0; i < n; ++i) { n     for (int64_t j = 0; j < m; ++j) { n       int64_t k = 0; n       for (; k < 4; ++k) { n         int64_t x = i + dx[k], y = j + dy[k]; n         if (valid(x, y, n, m)) { n           if (v[i][j] == v[x][y]) { n             break; n           } n         } n       } n       if (k < 4) { n         qu.push({i, j}); n         dis[i][j] = 0; n       } n     } n   } n   while (!qu.empty()) { n     pair<int64_t, int64_t> p = qu.front(); n     qu.pop(); n     for (int64_t k = 0; k < 4; ++k) { n       int64_t x = p.first + dx[k], y = p.second + dy[k]; n       if (valid(x, y, n, m) && dis[x][y] == -1) { n         dis[x][y] = 1 + dis[p.first][p.second]; n         qu.push({x, y}); n       } n     } n   } n   while (q--) { n     int64_t i, j, p; n     cin >> i >> j >> p; n     --i; n     --j; n     char ans = v[i][j]; n     if (dis[i][j] > -1 && p - dis[i][j] > 0 && (p - dis[i][j]) % 2 != 0) { n       if (ans ==  1 ) n         ans =  0 ; n       else n         ans =  1 ; n     } n     cout << ans << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int Mod = 998244353; n int add(int a, int b) { return a + b >= Mod ? a + b - Mod : a + b; } n int dec(int a, int b) { return a - b < 0 ? a - b + Mod : a - b; } n int mul(int a, int b) { return 1ll * a * b % Mod; } n void Add(int &a, int b) { a = add(a, b); } n void Dec(int &a, int b) { a = dec(a, b); } n void Mul(int &a, int b) { a = mul(a, b); } n int ksm(int a, int b) { n   int ans = 1; n   for (; b; b >>= 1, Mul(a, a)) n     if (b & 1) Mul(ans, a); n   return ans; n } n const int N = 2e5 + 50; n int n, q, ans, p[N]; n int sm[N], mt[N]; n set<int> S; n int calc(int l, int r) { n   int iv = ksm(mt[l - 1], Mod - 2); n   int y = mul(mt[r - 1], iv); n   int x = 1 + mul(iv, dec(sm[r - 2], sm[l - 1])); n   return mul(x, ksm(y, Mod - 2)); n } n void era(int x) { n   auto r = S.find(x), l = r; n   --l, Dec(ans, calc(*l, x)); n   ++r, Dec(ans, calc(x, *r)); n   Add(ans, calc(*l, *r)); n   S.erase(x); n } n void ins(int x) { n   auto r = S.insert(x).first, l = r; n   --l, Add(ans, calc(*l, x)); n   ++r, Add(ans, calc(x, *r)); n   Dec(ans, calc(*l, *r)); n } n int main() { n   cin >> n >> q; n   S.insert(1); n   S.insert(n + 1); n   int iv = ksm(100, Mod - 2); n   for (int i = 1; i <= n; i++) scanf( %d , &p[i]), Mul(p[i], iv); n   mt[0] = 1; n   for (int i = 1; i <= n; i++) n     mt[i] = mul(mt[i - 1], p[i]), sm[i] = add(sm[i - 1], mt[i]); n   ans = calc(1, n + 1); n   for (int i = 1, x; i <= q; i++) { n     scanf( %d , &x); n     if (S.find(x) != S.end()) n       era(x); n     else n       ins(x); n     cout << ans <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char inp[1000010]; n char out[1000010]; n int main() { n   int i, j, dot_index, nonzero_index = 0, start, end, p = 0, B; n   cin >> inp; n   int len = strlen(inp); n   dot_index = len; n   for (i = 0; inp[i] ==  0  || inp[i] ==  . ; i++) n     ; n   for (j = len - 1; inp[j] ==  0  || inp[j] ==  . ; j--) n     ; n   start = i; n   end = j; n   for (i = 0; i < len; i++) { n     if (inp[i] ==  . ) { n       dot_index = i; n       break; n     } n   } n   out[p++] = inp[start]; n   if (start != end) out[p++] =  . ; n   nonzero_index = start; n   for (i = start + 1; i <= end; i++) { n     if (inp[i] !=  . ) out[p++] = inp[i]; n   } n   cout << out; n   if (dot_index > nonzero_index) n     B = dot_index - nonzero_index - 1; n   else n     B = dot_index - nonzero_index; n   if (B) cout <<  E  << B; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 0x7fffffff; n const long double eps = 1e-8; n const int MAXN = 1111; n int n, m; n char g[MAXN][MAXN]; n int col[MAXN][MAXN]; n int sz[MAXN * MAXN]; n char ans[MAXN][MAXN]; n bool vis[MAXN][MAXN]; n const int dx[4] = {-1, 0, 1, 0}; n const int dy[4] = {0, 1, 0, -1}; n int qx[MAXN * MAXN], qy[MAXN * MAXN]; n void bfs(int x0, int y0) { n   static int tot = 0; n   ; n   int l = 1, r = 1; n   ++tot; n   for (qx[1] = x0, qy[1] = y0, vis[x0][y0] = 1; l <= r; ++l) { n     col[qx[l]][qy[l]] = tot; n     for (int d = 0; d <= 3; ++d) { n       int tx = qx[l] + dx[d]; n       int ty = qy[l] + dy[d]; n       if (tx > 0 && tx <= n && ty > 0 && ty <= m && !vis[tx][ty] && n           g[tx][ty] ==  . ) { n         vis[tx][ty] = 1; n         ++r; n         qx[r] = tx; n         qy[r] = ty; n       } n     } n   } n   sz[tot] = r; n   ; n } n int main() { n   scanf( %d%d , &n, &m); n   for (int i = 1; i <= n; ++i) scanf( %s , g[i] + 1); n   for (int i = 1; i <= n; ++i) n     for (int j = 1; j <= m; ++j) n       if (g[i][j] ==  .  && !vis[i][j]) bfs(i, j); n   for (int i = 1; i <= n; ++i) n     for (int j = 1; j <= m; ++j) n       if (g[i][j] ==  . ) n         ans[i][j] =  . ; n       else { n         int p[4], t = 0, s = 1; n         for (int d = 0; d <= 3; ++d) { n           int tx = i + dx[d], ty = j + dy[d]; n           if (tx > 0 && tx <= n && ty > 0 && ty <= m && g[tx][ty] ==  . ) { n             bool ok = 1; n             for (int k = 0; k <= t - 1; ++k) n               if (p[k] == col[tx][ty]) { n                 ok = 0; n                 break; n               } n             if (ok) { n               p[t++] = col[tx][ty]; n               s += sz[col[tx][ty]]; n             } n           } n         } n         ans[i][j] =  0  + s % 10; n       } n   for (int i = 1; i <= n; ++i) printf( %s n , ans[i] + 1); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n #define int long long n int32_t main() n { n     int t; n     cin >> t; n     while (t--) n     { n         int n; n         cin >> n; n        int c=0,i=1; n        while(n>0){ n            c++; n            n-=i; n            i+=2; n        } n        cout<<c<<endl; n     } n } n


#include <bits/stdc++.h> n using namespace std; n int n; n bool vis[100][100]; n char g[100][100]; n void dfs(int a, int b) { n   if (vis[a][b] || a > n || a < 1 || b < 1 || b > n || g[a][b] ==  1 ) return; n   vis[a][b] = 1; n   dfs(a + 1, b); n   dfs(a, b + 1); n   dfs(a - 1, b); n   dfs(a, b - 1); n } n int dist(pair<int, int> a, pair<int, int> b) { n   return (a.first - b.first) * (a.first - b.first) + n          (a.second - b.second) * (a.second - b.second); n } n int main() { n   cin >> n; n   int r1, c1, r2, c2; n   cin >> r1 >> c1 >> r2 >> c2; n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= n; j++) { n       cin >> g[i][j]; n     } n   } n   set<pair<int, int>> a; n   set<pair<int, int>> b; n   dfs(r1, c1); n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= n; j++) { n       if (vis[i][j]) a.insert({i, j}); n       vis[i][j] = 0; n     } n   } n   dfs(r2, c2); n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= n; j++) { n       if (vis[i][j]) b.insert({i, j}); n     } n   } n   if (a == b) n     cout << 0 << endl; n   else { n     int s = 10000000; n     for (auto x : a) { n       for (auto y : b) { n         s = min(s, dist(x, y)); n       } n     } n     cout << s << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n typedef vector<vector<int>> graph; n ifstream in( buffcraft.in , ios::in); n ofstream out( buffcraft.out , ios::out); n int main() { n   double m, R, ans = 0; n   cin >> m >> R; n   for (int x = 2; x < m; x++) n     ans += ((x - 1) * 2 + 2 * sqrt(2.0)) * 2 * (m - x); n   ans += 2 * m + (2 + sqrt(2.0)) * 2 * (m - 1); n   cout << setprecision(15) << ans / (m * m) * R; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct rect { n   int x1, y1, x2, y2; n }; n int main() { n   ios_base::sync_with_stdio(false); n   int n; n   cin >> n; n   vector<rect> v(n); n   int minx = 1000000000; n   int miny = 1000000000; n   for (int i = 0; i < n; ++i) { n     cin >> v[i].x1 >> v[i].y1 >> v[i].x2 >> v[i].y2; n     minx = min(minx, v[i].x1); n     miny = min(miny, v[i].y1); n   } n   cout <<  YES  << endl; n   for (int i = 0; i < n; ++i) { n     int x = (v[i].x1 - minx) % 2; n     int y = (v[i].y1 - miny) % 2; n     if (x == 0 && y == 0) { n       cout << 1; n     } else if (x == 1 && y == 0) { n       cout << 2; n     } else if (x == 0 && y == 1) { n       cout << 3; n     } else { n       cout << 4; n     } n     cout << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m; n pair<long long, int> p[200005]; n int main(int argc, char const *argv[]) { n   ios_base::sync_with_stdio(false); n   cin >> n; n   for (int i = 0; i < (n); i++) { n     cin >> p[i].first; n     p[i].second = i; n   } n   priority_queue<pair<long long, int>, vector<pair<long long, int> >, n                  greater<pair<long long, int> > > n       que[3]; n   for (int cnt = 0; cnt < (2); cnt++) { n     for (int i = 0; i < (n); i++) { n       int a; n       cin >> a; n       a--; n       que[a].push(p[i]); n     } n   } n   bool used[n]; n   fill(used, used + n, false); n   cin >> m; n   for (int i = 0; i < (m); i++) { n     int c; n     cin >> c; n     c--; n     while (!que[c].empty() && used[que[c].top().second]) que[c].pop(); n     if (que[c].empty()) n       cout << -1; n     else { n       cout << que[c].top().first; n       used[que[c].top().second] = true; n       que[c].pop(); n     } n     if (i < m - 1) n       cout <<    ; n     else n       cout << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   while (cin >> n) { n     int ans = n / 2; n     if (n % 2 == 0) ans -= 1; n     cout << ans << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> // Include every standard library n using namespace std; n  n typedef long long LL; n typedef pair<int, int> pii; n typedef pair<LL, LL> pll; n typedef pair<string, string> pss; n typedef vector<int> vi; n typedef vector<vi> vvi; n typedef vector<pii> vii; n typedef vector<LL> vl; n typedef vector<vl> vvl; n  n double EPS = 1e-9; n int INF = 1000000005; n long long INFF = 1000000000000000005LL; n double PI = acos(-1); n int dirx[8] = { -1, 0, 0, 1, -1, -1, 1, 1 }; n int diry[8] = { 0, 1, -1, 0, -1, 1, -1, 1 }; n  n #ifdef TESTING n #define DEBUG fprintf(stderr,  ====TESTING==== n ) n #define VALUE(x) cerr <<  The value of   << #x <<   is   << x << endl n #define debug(...) fprintf(stderr, __VA_ARGS__) n #else n #define DEBUG n #define VALUE(x) n #define debug(...) n #endif n  n #define FOR(a, b, c) for (int(a) = (b); (a) < (c); ++(a)) n #define FORN(a, b, c) for (int(a) = (b); (a) <= (c); ++(a)) n #define FORD(a, b, c) for (int(a) = (b); (a) >= (c); --(a)) n #define FORSQ(a, b, c) for (int(a) = (b); (a) * (a) <= (c); ++(a)) n #define FORC(a, b, c) for (char(a) = (b); (a) <= (c); ++(a)) n #define FOREACH(a, b) for (auto&(a) : (b)) n #define REP(i, n) FOR(i, 0, n) n #define REPN(i, n) FORN(i, 1, n) n #define MAX(a, b) a = max(a, b) n #define MIN(a, b) a = min(a, b) n #define SQR(x) ((LL)(x) * (x)) n #define RESET(a, b) memset(a, b, sizeof(a)) n #define fi first n #define se second n #define mp make_pair n #define pb push_back n #define ALL(v) v.begin(), v.end() n #define ALLA(arr, sz) arr, arr + sz n #define SIZE(v) (int)v.size() n #define SORT(v) sort(ALL(v)) n #define REVERSE(v) reverse(ALL(v)) n #define SORTA(arr, sz) sort(ALLA(arr, sz)) n #define REVERSEA(arr, sz) reverse(ALLA(arr, sz)) n #define PERMUTE next_permutation n #define TC(t) while (t--) n  n  n  n int main() n { n     int line; n     cin>>line; n  n     TC(line) n     { n         LL n; n         cin>>n; n         if(n==1)cout<<0<<endl; n         else if(n==2)cout<<1<<endl; n         else if(n==3)cout<<2<<endl; n         else n         { n             if(n&1) cout<<3<<endl; n             else cout<<2<<endl; n         } n     } n  n  n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int i, n, rem, k, f = 0, c = 0; n   cin >> n; n   vector<string> s; n   if (n == 0) { n     cout <<  zero ; n     return 0; n   } n   while (n != 0) { n     rem = n % 10; n     n = n / 10; n     c++; n     if (rem == 0) { n       rem = n % 10; n       if (rem == 1) { n         cout <<  ten ; n       } else if (rem == 2) { n         cout <<  twenty ; n       } else if (rem == 3) { n         cout <<  thirty ; n       } else if (rem == 4) { n         cout <<  forty ; n       } else if (rem == 5) { n         cout <<  fifty ; n       } else if (rem == 6) { n         cout <<  sixty ; n       } else if (rem == 7) { n         cout <<  seventy ; n       } else if (rem == 8) { n         cout <<  eighty ; n       } else if (rem == 9) { n         cout <<  ninety ; n       } n       return 0; n     } else if (f == 0) { n       f = 1; n       if (rem == 1) { n         s.push_back( one ); n       } else if (rem == 2) { n         s.push_back( two ); n       } else if (rem == 3) { n         s.push_back( three ); n       } else if (rem == 4) { n         s.push_back( four ); n       } else if (rem == 5) { n         s.push_back( five ); n       } else if (rem == 6) { n         s.push_back( six ); n       } else if (rem == 7) { n         s.push_back( seven ); n       } else if (rem == 8) { n         s.push_back( eight ); n       } else if (rem == 9) { n         s.push_back( nine ); n       } n     } else if (f == 1) { n       if (rem == 1) { n         if (s[0] ==  one ) { n           cout <<  eleven ; n           return 0; n         } else if (s[0] ==  two ) { n           cout <<  twelve ; n           return 0; n         } else if (s[0] ==  three ) { n           cout <<  thirteen ; n           return 0; n         } else if (s[0] ==  four ) { n           cout <<  fourteen ; n           return 0; n         } else if (s[0] ==  five ) { n           cout <<  fifteen ; n           return 0; n         } else if (s[0] ==  six ) { n           cout <<  sixteen ; n           return 0; n         } else if (s[0] ==  seven ) { n           cout <<  seventeen ; n           return 0; n         } else if (s[0] ==  eight ) { n           cout <<  eighteen ; n           return 0; n         } else if (s[0] ==  nine ) { n           cout <<  nineteen ; n           return 0; n         } n       } else if (rem == 2) { n         s.push_back( twenty ); n       } else if (rem == 3) { n         s.push_back( thirty ); n       } else if (rem == 4) { n         s.push_back( forty ); n       } else if (rem == 5) { n         s.push_back( fifty ); n       } else if (rem == 6) { n         s.push_back( sixty ); n       } else if (rem == 7) { n         s.push_back( seventy ); n       } else if (rem == 8) { n         s.push_back( eighty ); n       } else if (rem == 9) { n         s.push_back( ninety ); n       } n     } n   } n   if (c == 1) { n     cout << s[0]; n   } else { n     cout << s[1] <<  -  << s[0]; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long int trash = 0; n long long int a[50], c[50]; n long long int value2power[50]; n long long int n, m; n priority_queue<long long int> mainPQ; n vector<long long int> queueArray; n bool test(priority_queue<long long int> &PQ, long long int *b, n           long long int n) { n   for (long long int i = n; i >= 1; i--) { n     for (long long int j = 1; j <= b[i]; j++) { n       if (PQ.empty()) { n         return true; n       } n       long long int top = PQ.top(); n       PQ.pop(); n       if (top >= value2power[i + 1]) { n         return false; n       } n     } n   } n   if (PQ.empty()) { n     return true; n   } else { n     return false; n   } n } n bool cutoffRemain(long long int num, long long int n) { n   priority_queue<long long int> auxiliaryPQ; n   long long int size = queueArray.size(); n   for (long long int i = 1; i <= size; i++) { n     auxiliaryPQ.push(queueArray[i - 1]); n   } n   for (long long int i = 1; i <= n; i++) { n     c[i] = a[i]; n   } n   for (long long int i = 1; i <= n; i++) { n     if (c[i] > num) { n       for (long long int j = 1; j <= c[i] - num; j++) { n         auxiliaryPQ.push(value2power[i]); n       } n       c[i] = num; n     } n   } n   long long int temp = c[n]; n   for (long long int i = n; i >= 2; i--) { n     c[i] = c[i - 1] - c[i]; n   } n   for (long long int i = 1; i <= n - 1; i++) { n     c[i] = c[i + 1]; n   } n   c[n] = temp; n   return test(auxiliaryPQ, c, n); n } n int main() { n   value2power[1] = 1; n   for (long long int i = 2; i <= 49; i++) { n     value2power[i] = 2 * value2power[i - 1]; n   } n   long long int temp; n   cin >> m; n   for (long long int i = 1; i <= m; i++) { n     scanf( %lld , &temp); n     bool mark = true; n     for (long long int j = 1; j <= 49; j++) { n       if (temp == value2power[j]) { n         a[j]++; n         mark = false; n         break; n       } n     } n     if (mark) { n       queueArray.push_back(temp); n       mainPQ.push(temp); n     } n   } n   long long int n = 0; n   for (long long int i = 1; i <= 40; i++) { n     if (a[i] < a[i + 1]) { n       for (long long int j = 1; j <= a[i + 1] - a[i]; j++) { n         queueArray.push_back(value2power[i + 1]); n         mainPQ.push(value2power[i + 1]); n       } n       a[i + 1] = a[i]; n     } n   } n   for (long long int i = 40; i >= 1; i--) { n     if (a[i] != 0) { n       n = i; n       break; n     } n   } n   if (mainPQ.size() > a[1]) { n     cout << -1; n   } else { n     bool v = cutoffRemain(a[1], n); n     if (v == false) { n       cout << -1; n     } else { n       long long int minremain = 0; n       long long int maxremain = a[1]; n       while (minremain < maxremain) { n         long long int mid = (minremain + maxremain) / 2; n         if (cutoffRemain(mid, n)) { n           maxremain = mid; n         } else { n           minremain = mid + 1; n         } n       } n       for (long long int i = minremain; i <= a[1]; i++) { n         printf( %lld  , i); n       } n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 1e6; n const long long mod = 1e9 + 7; n vector<long long> primes; n bool not_prime[N]; n void sieve_of_eratosthenes(long long n) { n   for (long long i = 2; i < N; i++) { n     if (not_prime[i]) continue; n     primes.push_back(i); n     for (long long j = 2 * i; j < N; j += i) { n       not_prime[j] = 1; n     } n   } n } n void solve() { n   long long n; n   cin >> n; n   long long ans = upper_bound(primes.begin(), primes.end(), n) - primes.begin(); n   ans += 1; n   long long sq = sqrt(n); n   ans -= (upper_bound(primes.begin(), primes.end(), sq) - primes.begin()); n   cout << ans; n } n int32_t main() { n   sieve_of_eratosthenes(1e6); n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long t = 1; n   cin >> t; n   while (t--) { n     solve(); n     cout <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<long long> a[100005], vis(100005, 0), tree[100005], lev[2]; n long long n, m, k; n set<long long> v; n stack<long long> st; n void dfs(long long node, long long par) { n   vis[node] = 1; n   st.push(node); n   for (auto i : a[node]) n     if (!vis[i] and v.find(i) != v.end()) { n       tree[node].push_back(i); n       tree[i].push_back(node); n       dfs(i, node); n     } else if (v.find(i) != v.end() and i != par) { n       cout << 2 <<   n ; n       vector<long long> ans; n       while (!st.empty() and st.top() != i) { n         ans.push_back(st.top()); n         st.pop(); n       } n       ans.push_back(i); n       cout << (long long)ans.size() <<   n ; n       for (auto i : ans) cout << i <<    ; n       exit(0); n     } n   st.pop(); n } n void dfs1(long long node, long long par, long long d) { n   lev[d].push_back(node); n   for (auto i : tree[node]) n     if (i != par) { n       dfs1(i, node, 1 - d); n     } n } n void get_subgraph() { n   queue<long long> q; n   q.push(1); n   v.insert(1); n   while (!q.empty()) { n     auto cur = q.front(); n     q.pop(); n     for (auto i : a[cur]) { n       if (v.find(i) == v.end()) { n         v.insert(i); n         q.push(i); n         if ((long long)v.size() == k) break; n       } n     } n     if ((long long)v.size() == k) break; n   } n } n void solve() { n   cin >> n >> m >> k; n   for (long long i = 0; i < m; i++) { n     long long x, y; n     cin >> x >> y; n     a[x].push_back(y); n     a[y].push_back(x); n   } n   get_subgraph(); n   dfs(1, -1); n   dfs1(1, -1, 0); n   long long req = (k + 1) / 2; n   cout << 1 <<   n ; n   vector<long long> ans; n   if ((long long)lev[0].size() >= req) n     ans = lev[0]; n   else n     ans = lev[1]; n   for (long long i = 0; i < req; i++) cout << ans[i] <<    ; n } n signed main() { n   long long TESTS = 1; n   while (TESTS--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool comp(pair<unsigned long long, unsigned long long> a, n           pair<unsigned long long, unsigned long long> b) { n   unsigned long long s1, s2, h1, h2; n   tie(s1, h1) = a; n   tie(s2, h2) = b; n   if (s1 * h2 > s2 * h1) return true; n   return false; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int n; n   cin >> n; n   unsigned long long ans = 0; n   string str; n   vector<pair<unsigned long long, unsigned long long> > arr(n); n   for (int i = 0; i < n; i++) { n     cin >> str; n     unsigned long long s1 = 0, h = 0; n     for (auto x : str) { n       if (x ==  s ) n         s1++; n       else if (x ==  h ) n         h++, ans += s1; n     } n     arr[i] = make_pair(s1, h); n   } n   sort((arr).begin(), (arr).end(), comp); n   unsigned long long s1 = 0; n   for (auto i : arr) { n     ans += s1 * 1LL * (i.second); n     s1 += i.first; n   } n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long s[1000], x[1000], size; n void tob(long long a, long long arr[], long long& len) { n   len = 0; n   while (a != 0) { n     arr[len++] = a % 2; n     a /= 2; n   } n } n long long DP(long long n, long long carry) { n   if (n >= size) return 1 - carry; n   if (x[n] == 1) { n     if (((carry + 1) % 2) == s[n]) { n       return 2 * DP(n + 1, carry); n     } else n       return 0; n   } else { n     long long ans = 0; n     if ((carry) == s[n]) { n       ans += DP(n + 1, 0); n     } n     if (((carry + 2) % 2) == s[n]) { n       ans += DP(n + 1, 1); n     } n     return ans; n   } n } n void solve(long long n, long long m) { n   long long len1, len2, ans; n   tob(n, s, len1); n   tob(m, x, len2); n   size = max(len1, len2); n   ans = DP(0, 0); n   if (n == m) n     cout << ans - 2 << endl; n   else n     cout << ans << endl; n } n int main() { n   long long n, m; n   cin >> n >> m; n   solve(n, m); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, d[210000]; n long long cnt[210000]; n long long solve() { n   cnt[1] *= 2; n   cnt[n] *= 2; n   int Min = cnt[1], Max = cnt[1]; n   for (int i = 1; i <= n; ++i) { n     if (Min > cnt[i]) n       Min = cnt[i]; n     else if (Max < cnt[i]) n       Max = cnt[i]; n   } n   if (Min == Max) { n     for (int i = 2; i <= n; ++i) n       if (d[i] - d[i - 1] != d[2] - d[1]) return -1; n     return cnt[1] * (d[n] - d[1]) - d[2] + d[1]; n   } else { n     long long temp = 0; n     for (int i = 1; i < n; ++i) { n       temp += (d[i + 1] - d[i]) * min(cnt[i], cnt[i + 1]); n     } n     return temp; n   } n } n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; ++i) scanf( %d , &d[i]); n   scanf( %d , &m); n   for (int i = 1; i <= m; ++i) { n     int temp; n     scanf( %d , &temp); n     ++cnt[temp]; n   } n   printf( %I64d n , solve()); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } n int main() { n   int n, num[105], ans; n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) cin >> num[i]; n   sort(num + 1, num + 1 + n); n   ans = num[1]; n   for (int i = 2; i <= n; i++) ans = gcd(ans, num[i]); n   printf( %d n , ans * n); n } n


#include <bits/stdc++.h> n using namespace std; n int arr[(int)1e5 + 1]; n int q[(int)1e5 + 1]; n int sol[(int)1e5 + 1]; n int main() { n   int n, m; n   cin >> n; n   cin >> arr[0]; n   for (int i = 1; i < n; i++) { n     int x; n     cin >> x; n     arr[i] = arr[i - 1] + x; n   } n   cin >> m; n   for (int i = 0; i < m; i++) { n     cin >> q[i]; n   } n   for (int i = 0; i < m; i++) { n     int lo = 0, hi = n - 1, res = -1; n     while (lo <= hi) { n       int md = (hi + lo) >> 1; n       if (arr[md] >= q[i] && q[i] >= arr[md - 1]) { n         hi = md - 1; n         res = md; n       } else if (arr[md] >= q[i]) n         hi = md - 1; n       else n         lo = md + 1; n     } n     sol[i] = res + 1; n   } n   for (int i = 0; i < m; i++) { n     cout << sol[i] << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int m, n, j, k, l, i, o, p, __t; n int V[200][2000], tim[200][2000], T[200], cop[200][2000]; n char ch; n void read(int &a) { n   for (ch = getchar(); (ch <  0  || ch >  9 ) && (ch !=  - ); ch = getchar()) n     ; n   if (ch ==  - ) n     a = 0, __t = -1; n   else n     a = ch -  0 , __t = 1; n   for (ch = getchar(); ch >=  0  && ch <=  9 ; ch = getchar()) n     a = a * 10 + ch -  0 ; n   a *= __t; n } n int main() { n   read(m), read(n); n   for (int i = 1; i <= m; i++) { n     read(T[i]); n     for (int j = 1; j <= T[i]; j++) n       read(V[i][j]), read(tim[i][j]), cop[i][j] = tim[i][j]; n   } n   int ans = 0; n   for (int i = 1; i <= m; i++) { n     for (int j = i + 1; j <= m; j++) { n       for (int k = 1; k <= T[i]; k++) tim[i][k] = cop[i][k]; n       for (int k = 1; k <= T[j]; k++) tim[j][k] = cop[j][k]; n       int x0 = 0, x1 = 0, who = 0; n       if (V[i][1] > V[j][1]) n         who = -1; n       else n         who = 1; n       for (int t1 = 1, t2 = 1; t1 <= T[i] && t2 <= T[j];) { n         int dece = min(tim[i][t1], tim[j][t2]); n         int y0 = x0 + dece * V[i][t1]; n         int y1 = x1 + dece * V[j][t2], nexwho; n         if (y0 == y1) n           nexwho = who; n         else if (y0 < y1) n           nexwho = 1; n         else n           nexwho = -1; n         if (nexwho != who) ans++; n         who = nexwho; n         x0 = y0, x1 = y1; n         tim[i][t1] -= dece; n         tim[j][t2] -= dece; n         if (tim[i][t1] == 0) t1++; n         if (tim[j][t2] == 0) t2++; n       } n     } n   } n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int n, k, t, cur; n void solve() { n   scanf( %d %d , &n, &k); n   t = n - k; n   for (int i = 1; i <= t; i++) printf( %d  , i); n   for (int i = k, j = 1; i >= 1; i--, j *= -1) { n     t += i * j; n     printf( %d  , t); n   } n } n int main(void) { n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int ans, n; n vector<pair<int, int> > vec; n string s, t; n int lcp1[5005][5005]; n int lcp2[5005][5005]; n void LCP(string &s, string &t, int lcp[5005][5005]) { n   for (int i = (int)s.size() - 1; i >= 0; i--) { n     for (int j = (int)t.size() - 1; j >= 0; j--) { n       if (s[i] == t[j]) { n         lcp[i][j] = lcp[i + 1][j + 1] + 1; n       } else { n         lcp[i][j] = 0; n       } n     } n   } n } n void solve() { n   LCP(s, t, lcp1); n   reverse(s.begin(), s.end()); n   LCP(s, t, lcp2); n   for (int ti = 0; ti < t.size();) { n     int mx1 = 0, mx1_si = -1; n     int mx2 = 0, mx2_si = -1; n     for (int si = 0; si < s.size(); si++) { n       if (mx1 < lcp1[si][ti]) { n         mx1 = lcp1[si][ti]; n         mx1_si = si; n       } n       if (mx2 < lcp2[si][ti]) { n         mx2 = lcp2[si][ti]; n         mx2_si = si; n       } n     } n     if (mx1 == 0 && mx2 == 0) { n       ans = -1; n       break; n     } else if (mx1 >= mx2) { n       ans++; n       vec.push_back(pair<int, int>(mx1_si + 1, mx1_si + mx1 - 1 + 1)); n       ti += mx1; n     } else { n       ans++; n       vec.push_back(pair<int, int>(n - mx2_si, n - (mx2_si + mx2 - 1))); n       ti += mx2; n     } n   } n   cout << ans << endl; n   for (int i = 0; i < (ans); i++) { n     cout << vec[i].first <<     << vec[i].second << endl; n   } n } n int main() { n   cin >> s; n   cin >> t; n   n = (int)s.size(); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n void doubleIntSort(double d[], int m[], int s) { n   int i, j, r; n   double k1, k2, t; n   if (s <= 1) return; n   k1 = (d[0] + d[s - 1]) / 2.0; n   k2 = k1 + 1e-10; n   k1 -= 1e-10; n   i = -1; n   j = s; n   for (;;) { n     while (d[++i] < k1) n       ; n     while (d[--j] > k2) n       ; n     if (i >= j) break; n     t = d[i]; n     d[i] = d[j]; n     d[j] = t; n     r = m[i]; n     m[i] = m[j]; n     m[j] = r; n   } n   doubleIntSort(d, m, i); n   doubleIntSort(d + j + 1, m + j + 1, s - j - 1); n } n int n; n int nf, ne, ns; n int rf, re, rs; n double Rf, Re, Rs; n int df, de; n int h[21]; n double res; n double x[100]; n int ev[100]; n int F, E, S; n void calc(void) { n   int i, j, k; n   double w, tmp; n   if (n % 2 == 0) { n     i = h[0] + h[1] * 10; n     j = h[n - 2] + h[n - 1] * 10; n     if (i > j) return; n   } n   F = E = S = 0; n   for (i = 0; i < n; i++) { n     if (h[i] == 0) { n       x[2 * i] = (i / 2) - Rf; n       x[2 * i + 1] = (i / 2) + Rf; n       ev[2 * i] = 1; n       ev[2 * i + 1] = -1; n     } n     if (h[i] == 1) { n       x[2 * i] = (i / 2) - Re; n       x[2 * i + 1] = (i / 2) + Re; n       ev[2 * i] = 2; n       ev[2 * i + 1] = -2; n     } n     if (h[i] == 2) { n       x[2 * i] = (i / 2) - Rs; n       x[2 * i + 1] = (i / 2) + Rs; n       ev[2 * i] = 3; n       ev[2 * i + 1] = -3; n     } n   } n   doubleIntSort(x, ev, 2 * n); n   tmp = 0; n   for (i = 0; i < 2 * n - 1; i++) { n     w = x[i + 1] - x[i]; n     if (ev[i] == 1) F++; n     if (ev[i] == -1) F--; n     if (ev[i] == 2) E++; n     if (ev[i] == -2) E--; n     if (ev[i] == 3) S++; n     if (ev[i] == -3) S--; n     tmp += (F * df + E * de) * (w * (S + 1)); n   } n   if (res < tmp) res = tmp; n } n void brute(int depth) { n   if (depth == n) calc(); n   if (nf > 0) { n     h[depth] = 0; n     nf--; n     if (depth % 2 == 0 || h[depth - 1] <= h[depth]) brute(depth + 1); n     nf++; n   } n   if (ne > 0) { n     h[depth] = 1; n     ne--; n     if (depth % 2 == 0 || h[depth - 1] <= h[depth]) brute(depth + 1); n     ne++; n   } n   if (ns > 0) { n     h[depth] = 2; n     ns--; n     if (depth % 2 == 0 || h[depth - 1] <= h[depth]) brute(depth + 1); n     ns++; n   } n } n int main() { n   int i, j, k, l, m; n   res = 0; n   scanf( %d%d%d , &nf, &ne, &ns); n   n = nf + ne + ns; n   scanf( %d%d%d , &rf, &re, &rs); n   scanf( %d%d , &df, &de); n   Rf = sqrt(rf * rf - 1); n   if (rf == 1) Rf = 0; n   Re = sqrt(re * re - 1); n   if (re == 1) Re = 0; n   Rs = sqrt(rs * rs - 1); n   if (rs == 1) Rs = 0; n   brute(0); n   printf( %.15f n , res); n   return 0; n } n