#include <bits/stdc++.h> n using namespace std; n const int maxn = 100 * 1005; n bool bad[maxn]; n vector<int> blocked; n vector<int> g[maxn]; n bool seen[maxn]; n int deg[maxn]; n vector<int> good; n int n, m, k; n bool can(double mid) { n   memset(bad, 0, sizeof(bad)); n   memset(deg, 0, sizeof(deg)); n   memset(seen, 0, sizeof(seen)); n   queue<int> q; n   for (int i = 0; i < n; ++i) deg[i] = ((int)((g[i]).size())); n   for (int i = 0; i < ((int)((blocked).size())); i++) q.push(blocked[i]); n   while (!q.empty()) { n     int u = q.front(); n     q.pop(); n     if (seen[u]) continue; n     seen[u] = 1; n     for (int i = 0; i < ((int)((g[u]).size())); i++) { n       int v = g[u][i]; n       if (bad[v]) continue; n       deg[v]--; n       if (double(deg[v] / (1.0 * ((int)((g[v]).size())))) < mid) q.push(v); n     } n   } n   good.clear(); n   for (int i = 0; i < n; ++i) n     if (!seen[i]) good.push_back(i); n   return ((int)((good).size())) > 0; n } n int main() { n   int u, v; n   scanf( %d %d %d , &n, &m, &k); n   for (int i = 0; i < k; ++i) scanf( %d , &u), --u, blocked.push_back(u); n   for (int i = 0; i < m; ++i) n     scanf( %d %d , &u, &v), --u, --v, g[u].push_back(v), g[v].push_back(u); n   double l = 0, r = 1.0; n   double ans = 0.0; n   for (int i = 0; i < 80; ++i) { n     double mid = (l + r) / 2.0; n     if (can(mid)) n       l = mid, ans = mid; n     else n       r = mid; n   } n   can(ans); n   assert(((int)((good).size())) <= n - k); n   assert(((int)((good).size())) != 0); n   printf( %d n , ((int)((good).size()))); n   for (int i = 0; i < ((int)((good).size())); i++) printf( %d  , good[i] + 1); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n namespace MincostMaxFlow { n const int maxn(2e5 + 5); n struct Edge { n   int to, next, w, f; n }; n int first[maxn], cnt, vis[maxn], dis[maxn], S, T, pe[maxn], pv[maxn], maxflow, n     mincost; n Edge edge[maxn * 20]; n queue<int> Q; n inline void Init(int _S, int _T) { n   cnt = mincost = maxflow = 0, S = _S, T = _T; n   memset(first, -1, sizeof(first)); n } n inline void AddEdge(int u, int v, int w, int f) { n   edge[cnt] = (Edge){v, first[u], w, f}, first[u] = cnt++; n   edge[cnt] = (Edge){u, first[v], -w, 0}, first[v] = cnt++; n } n inline int SPFA() { n   int e, u, v, inf; n   memset(dis, 63, sizeof(dis)), inf = dis[0]; n   Q.push(S), dis[S] = 0, vis[S] = 1; n   while (!Q.empty()) { n     u = Q.front(), Q.pop(); n     for (e = first[u]; ~e; e = edge[e].next) n       if (edge[e].f && dis[u] + edge[e].w < dis[v = edge[e].to]) { n         dis[v] = dis[u] + edge[e].w, pv[v] = u, pe[v] = e; n         if (!vis[v]) vis[v] = 1, Q.push(v); n       } n     vis[u] = 0; n   } n   if (dis[T] >= 0) return 0; n   for (v = T; v ^ S; v = pv[v]) inf = min(inf, edge[pe[v]].f); n   maxflow += inf, mincost += dis[T] * inf; n   for (v = T; v ^ S; v = pv[v]) edge[pe[v]].f -= inf, edge[pe[v] ^ 1].f += inf; n   return 1; n } n inline int MCMF() { n   while (SPFA()) n     ; n   return mincost; n } n }  // namespace MincostMaxFlow n using MincostMaxFlow ::AddEdge; n using MincostMaxFlow ::Init; n using MincostMaxFlow ::MCMF; n const int inf(1e7); n int n, k, a[85], c[85], S, T; n int main() { n   int i, j, tmp; n   scanf( %d%d , &n, &k), k = min(k, n); n   for (i = 1; i <= n; ++i) scanf( %d , &a[i]); n   for (i = 1; i <= n; ++i) scanf( %d , &c[i]); n   Init(S = 0, T = n + n + 2), tmp = n + n + 1, AddEdge(S, tmp, 0, k); n   for (i = 1; i <= n; ++i) { n     AddEdge(i, i + n, -inf, 1); n     for (j = i + 1; j <= n; ++j) n       if (a[j] == a[i]) n         AddEdge(i + n, j, 0, 1); n       else n         AddEdge(i + n, j, c[a[j]], 1); n     AddEdge(i + n, T, 0, 1), AddEdge(tmp, i, c[a[i]], 1); n   } n   printf( %d n , MCMF() + n * inf); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int N; n int A[3][30]; n int p3[30]; n map<pair<int, int>, pair<int, signed long long> > M[2]; n void solve() { n   int i, j, k, l, r, x, y; n   string s; n   cin >> N; n   p3[0] = 1; n   for (i = 0; i < N; i++) p3[i + 1] = p3[i] * 3; n   for (i = 0; i < N; i++) cin >> A[0][i] >> A[1][i] >> A[2][i]; n   for (signed long long mask = 0; mask < p3[min(N, 13)]; mask++) { n     int t[3] = {}, tm = mask; n     for (i = 0; i < min(N, 13); i++) { n       x = tm % 3, tm /= 3; n       if (x == 0) t[0] += A[0][i], t[1] += A[1][i]; n       if (x == 1) t[0] += A[0][i], t[2] += A[2][i]; n       if (x == 2) t[1] += A[1][i], t[2] += A[2][i]; n     } n     M[0][{t[0] - t[1], t[0] - t[2]}] = n         max(M[0][{t[0] - t[1], t[0] - t[2]}], {t[0] + (1LL << 29), mask}); n   } n   for (signed long long mask = 0; mask < p3[max(0, N - 13)]; mask++) { n     int t[3] = {}, tm = mask; n     for (i = 0; i < max(0, N - 13); i++) { n       x = tm % 3, tm /= 3; n       if (x == 0) t[0] += A[0][13 + i], t[1] += A[1][13 + i]; n       if (x == 1) t[0] += A[0][13 + i], t[2] += A[2][13 + i]; n       if (x == 2) t[1] += A[1][13 + i], t[2] += A[2][13 + i]; n     } n     M[1][{t[1] - t[0], t[2] - t[0]}] = max(M[1][{t[1] - t[0], t[2] - t[0]}], n                                            {t[0] + (1LL << 29), mask * p3[13]}); n   } n   signed long long co = -1LL << 40; n   signed long long best = -1; n   for (auto& r : M[1]) n     if (M[0].count(r.first) && r.second.first + M[0][r.first].first > co) { n       co = r.second.first + M[0][r.first].first; n       best = r.second.second + M[0][r.first].second; n     } n   if (best == -1) n     (void)printf( Impossible n ); n   else { n     for (i = 0; i < N; i++) { n       x = best % 3; n       best /= 3; n       if (x == 0) (void)printf( LM n ); n       if (x == 1) (void)printf( LW n ); n       if (x == 2) (void)printf( MW n ); n     } n   } n } n int main(int argc, char** argv) { n   string s; n   int i; n   if (argc == 1) ios::sync_with_stdio(false); n   for (i = 0; i < argc - 1; i++) s += argv[i + 1], s +=   n ; n   for (i = 0; i < s.size(); i++) ungetc(s[s.size() - 1 - i], stdin); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int node[100005][2]; n int main() { n   int n, m; n   scanf( %d%d , &n, &m); n   for (int i = 0; i < m; i++) scanf( %d%d , &node[i][0], &node[i][1]); n   int ans = node[0][1] + node[0][0] - 1; n   bool flag = 0; n   for (int i = 1; i < m; i++) { n     int d_val = node[i][0] - node[i - 1][0]; n     if (abs(node[i][1] - node[i - 1][1]) > d_val) { n       flag = 1; n       break; n     } n     ans = max(ans, node[i][1]); n     ans = max(ans, max(node[i][1], node[i - 1][1]) + n                        (d_val - abs(node[i][1] - node[i - 1][1])) / 2); n   } n   int syday = n - node[m - 1][0]; n   ans = max(ans, node[m - 1][1] + syday); n   if (flag) n     cout <<  IMPOSSIBLE  << endl; n   else n     cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 600; n char graph[MAXN][MAXN]; n int dx[4] = {-1, 0, 0, 1}; n int dy[4] = {0, -1, 1, 0}; n vector<char> op; n vector<pair<int, int> > pos; n bool visited[MAXN][MAXN]; n void solve(int x, int y, int n, int m, int initX, int initY) { n   visited[x][y] = true; n   bool flag = false; n   for (int i = 0; i < 4; i++) { n     int nx = x + dx[i]; n     int ny = y + dy[i]; n     if (nx >= 0 && nx < n && ny >= 0 && ny < m && graph[nx][ny] ==  .  && n         !visited[nx][ny]) { n       if (!flag) { n         op.push_back( B ); n         pos.push_back(make_pair(x + 1, y + 1)); n       } n       flag = true; n       solve(nx, ny, n, m, initX, initY); n     } n   } n   if (!flag) { n     if (x == initX && y == initY) { n       op.push_back( B ); n     } else { n       op.push_back( R ); n     } n     pos.push_back(make_pair(x + 1, y + 1)); n   } else { n     if (!(x == initX && y == initY)) { n       op.push_back( D ); n       pos.push_back(make_pair(x + 1, y + 1)); n       op.push_back( R ); n       pos.push_back(make_pair(x + 1, y + 1)); n     } n   } n } n int main() { n   int n, m; n   scanf( %d%d , &n, &m); n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       cin >> graph[i][j]; n     } n   } n   memset(visited, false, sizeof(visited)); n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       if (graph[i][j] ==  .  && !visited[i][j]) { n         solve(i, j, n, m, i, j); n       } n     } n   } n   int size = op.size(); n   printf( %d n , size); n   for (int i = 0; i < size; i++) { n     printf( %c %d %d n , op[i], pos[i].first, pos[i].second); n   } n   return 0; n } n


// Author: Vinay Khilwani n // Language: C++ n   n // @vok8: Codeforces, AtCoder, LeetCode, HackerEarth, TopCoder, Google, FB, CSES, Spoj, GitHub n // @vok_8: CodeChef, GFG n // @vok8_khilwani: HackerRank n   n // Never Stop Trying. n // Trying to be Better than Myself. n   n // while(true) n // { n //     if(AC) n //     { n //         break; n //     } n //     else if(Contest Over) n //     { n //         Try. n //         Check out Editorial. n //         Understand. n //         Find out your Mistake. n //         Learn the topic (if new). n //         Solve Problems on that topic (if new). n //         Upsolve that problem. n //         break; n //     } n //     else n //     { n //         Try. n //         Use Pen-Paper. n //         Find errors, edge cases, etc. n //         continue; n //     } n // } n   n // Optimizations n #pragma GCC optimize( O2 ) n #pragma GCC optimize( unroll-loops ) n #pragma GCC target( avx2 ) n #pragma GCC optimize( Os ) n   n // Libraries n #include <bits/stdc++.h> n using namespace std; n // #include <ext/pb_ds/assoc_container.hpp>  n // #include <ext/pb_ds/tree_policy.hpp>  n // using namespace __gnu_pbds; n   n // Debugging n #define dbg(a) cerr<<a<<  n ; n #define debug_a(a) for(auto x:a) {cerr<<x<<   ;} cerr<<  n ; n #define debug_b(a) for(auto x:a) {cerr<< [ <<x.first<< ,  <<x.second<< ] <<  n ;} cerr<<  n ; n #define debug_c(a) for(auto x:a) {debug_a(x)} cerr<<  n ; n #define debug_d(a) for(auto x:a) {debug_b(x)} cerr<<  n ; n #define debug_e(a) cerr<< [ <<a.first<< ,  <<a.second<< ] <<  n ; n   n // Defines n #define fast ios_base::sync_with_stdio(false); cout.tie(NULL); cin.tie(NULL); n #define loop(i,a,n) for(ll i=a; i<n; i++) n #define rloop(i,a,n) for(int i=a; i>=n; i--) n #define fr(i,a,n,b) for(int i=a; i<n; i+=b) n #define rfr(i,a,n,b) for(int i=a; i>=n; i-=b) n #define IN cin>> n #define OUT cout<< n #define nl   n  n #define sz(a) int(a.size()) n #define all(a) (a).begin(),(a).end() n #define each(a,b) for(auto &a:b) n #define pb push_back n #define set_bits(a) __builtin_popcountll(a) n #define ar array n #define write(a) for(auto x:a) {OUT x<<   ;} OUT endl; n #define read(a) for(auto &x:a) {IN x;} n // #define oset tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> n using ll=long long int; n using ld=long double; n using pll=pair<ll,ll>; n using pii=pair<int,int>; n using vll=vector<ll>; n using vi=vector<int>; n const ll mod=(ll)(1e9)+7LL; n const ll M=998244353LL; n const int dx[4]={1,0,-1,0}; n const int dy[4]={0,1,0,-1}; n const ld pi=acos(-1); n   n // General Functions n ll gcd(ll a, ll b) n { n     return (b?gcd(b,a%b):a); n } n ll P(ll B, ll power, ll modulo) //Fast Power n { n     ll ans=1LL; n     while(power>0LL) n     { n         if(power%2LL==1LL) n         { n             ans=(ans*B)%modulo; n         } n         B=(B*B)%modulo; n         power/=2LL; n     } n     return ans; n } n bool isPrime(ll n) n { n     if(n<=1LL) n     { n         return false; n     } n     if(n<=3LL) n     { n         return true; n     } n     if(n%2==0LL || n%3==0LL) n     { n         return false; n     } n     for(ll i=5LL; (i*i)<=n; i+=6LL) n     { n         if(n%i==0LL || n%(i+2LL)==0LL) n         { n             return false; n         } n     } n     return true; n } n mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); n ll get_rand(ll l, ll r) n { n     uniform_int_distribution<ll> uid(l,r); n     return uid(rng); n } n void vok() n { n     fast n     #ifndef ONLINE_JUDGE n         freopen( input.txt , r ,stdin); n         freopen( output.txt , w ,stdout); n         freopen( error.txt , w ,stderr); n     #endif n } n   n // Global Variables n const int mxN=int(1e5)+100; n vector<bool> cycle; n ll sizee=0; n vector<bool> vis; n  n // Solver Function(s) n void dfs_cycle(int u, int p, int color[], int mark[], int par[], int& cyclenumber, vi graph[]) n { n   n     // already (completely) visited vertex. n     if (color[u] == 2) { n         return; n     } n   n     // seen vertex, but was not completely visited -> cycle detected. n     // backtrack based on parents to find the complete cycle. n     if (color[u] == 1) { n   n         cyclenumber++; n         int cur = p; n         mark[cur] = cyclenumber; n   n         // backtrack the vertex which are n         // in the current cycle thats found n         while (cur != u) { n             cur = par[cur]; n             mark[cur] = cyclenumber; n         } n         return; n     } n     par[u] = p; n   n     // partially visited. n     color[u] = 1; n   n     // simple dfs on graph n     for (int v : graph[u]) { n   n         // if it has not been visited previously n         if (v == par[u]) { n             continue; n         } n         dfs_cycle(v, u, color, mark, par, cyclenumber, graph); n     } n   n     // completely visited. n     color[u] = 2; n } n void dfs(int u, vi g[]) n { n     sizee++; n     vis[u]=true; n     each(x,g[u]) n     { n         if(!vis[x] && !cycle[x]) n         { n             dfs(x,g); n         } n     } n } n void solve() n { n     int n; n     IN n; n     vi g[n+1]; n     loop(i,0,n) n     { n         int u,v; n         IN u>>v; n         g[u].pb(v); n         g[v].pb(u); n     } n     if(n==3) n     { n         OUT 6<<nl; n         return; n     } n     int color[n+1]; n     int par[n+1]; n     int mark[n+1]; n     loop(i,0,n+1) n     { n         color[i]=par[i]=mark[i]=0; n     } n     int cyclenumber = 0; n     int edges = n; n     dfs_cycle(1, 0, color, mark, par, cyclenumber, g); n     vis=vector<bool>(n+1,false); n     vll vv; n     cycle=vis; n     ll sz_cycle=0; n     loop(i,1,n+1) n     { n         if(mark[i]) n         { n             cycle[i]=true; n             sz_cycle++; n         } n     } n     ll ans=(ll)(sz_cycle)*(ll)(sz_cycle-1); n     loop(i,1,n+1) n     { n         if(cycle[i]) n         { n             sizee=0;  n             dfs(i,g); n             ll add=sizee*(sizee-1)/2; n             // OUT i<<   <<sizee<<nl; n             if(sizee>1) n             { n                 vv.pb(sizee-1); n                 ans+=((sizee-1)*(ll)(sz_cycle-1)*2); n             } n             ans+=add; n             // OUT ans<<nl; n             // ans+=((sizee-1)*(ll)(sz(cycle)-1)*2); n             // OUT ans<<nl; n         } n     } n     ll sum=0; n     ll sq=0; n     each(x,vv) n     { n         sum+=x; n         sq+=(x*x); n     } n     sum*=sum; n     ll temp=sum-sq; n     ans+=temp; n     OUT ans<<nl; n } n   n // Main Function n int main() n { n     vok(); n     int t=1; n     IN t; n     while(t--) n     { n         solve(); n     } n     return 0; n }


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, h, m, l, r, x; n   cin >> n >> h >> m; n   vector<int> v(n, h); n   for (int i = 0; i < m; i++) { n     cin >> l >> r >> x; n     for (int j = l - 1; j < r; j++) { n       v[j] = min(v[j], x); n     } n   } n   long long sum = 0; n   for (int i = 0; i < v.size(); i++) { n     sum = sum + (v[i] * v[i]); n   } n   cout << sum <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s1; n   cin >> s1; n   int condition = 1; n   for (int i = 1; i <= s1.length(); i++) { n     if (s1[i] == s1[i - 1]) { n       condition++; n       if (condition == 7) { n         cout <<  YES  << endl; n         return 0; n       } n     } else { n       condition = 1; n     } n   } n   cout <<  NO  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int n; n   cin >> n; n   pair<int, int> point[n]; n   for (int i = 0; i < n; i++) { n     cin >> point[i].first >> point[i].second; n   } n   sort(point, point + n, n        [](pair<int, int> a, pair<int, int> b) { return a.first < b.first; }); n   long long ans = 0; n   long long cnt = 1; n   for (int i = 0; i < n - 1; i++) { n     if (point[i].first == point[i + 1].first) { n       cnt++; n     } else { n       ans += cnt * (cnt - 1) / 2; n       cnt = 1; n     } n   } n   ans += cnt * (cnt - 1) / 2; n   sort(point, point + n, n        [](pair<int, int> a, pair<int, int> b) { return a.second < b.second; }); n   cnt = 1; n   for (int i = 0; i < n - 1; i++) { n     if (point[i].second == point[i + 1].second) { n       cnt++; n     } else { n       ans += cnt * (cnt - 1) / 2; n       cnt = 1; n     } n   } n   ans += cnt * (cnt - 1) / 2; n   sort(point, point + n); n   cnt = 1; n   for (int i = 0; i < n - 1; i++) { n     if (point[i] == point[i + 1]) { n       cnt++; n     } else { n       ans -= cnt * (cnt - 1) / 2; n       cnt = 1; n     } n   } n   ans -= cnt * (cnt - 1) / 2; n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s; n   cin >> s; n   int hoa = 0; n   int thuong = 0; n   for (int i = 0; i < s.size(); i++) { n     if (s[i] >= 65 && s[i] <= 90) { n       hoa++; n     } else { n       thuong++; n     } n   } n   if (thuong >= hoa) { n     for (int i = 0; i < s.size(); i++) { n       if (s[i] >= 65 && s[i] <= 90) { n         s[i] += 32; n       } n     } n   } else { n     for (int i = 0; i < s.size(); i++) { n       if (s[i] >= 97 && s[i] <= 122) { n         s[i] -= 32; n       } n     } n   } n   cout << s; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long int mod = 1e9 + 7; n const long long int cmod = 998244353; n const long long int N = 2e5 + 5; n const long long int inf = 1e16 + 2; n void solve(long long int ze) { n   long long int n, x, t, pr = 0; n   cin >> n >> x; n   vector<long long int> ans; n   map<long long int, long long int> check; n   check[0] = 1; n   check[x] = 1; n   for (long long int i = 1; i < (1LL << n); i++) { n     if (!check[i]) { n       ans.push_back(pr ^ i); n       pr = i; n       check[i] = 1; n       check[i ^ x] = 1; n     } n   } n   cout << ans.size() <<   n ; n   for (auto x : ans) cout << x <<    ; n } n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long int testcase = 1; n   long long int x = 1; n   while (testcase--) { n     solve(x++); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline long long in() { n   long long x = 0; n   int n = 1; n   char c = getchar(); n   while (!isdigit(c)) { n     n = (c ==  - ) ? -1 : 1; n     c = getchar(); n   } n   while (isdigit(c)) { n     x = x * 10 + c -  0 ; n     c = getchar(); n   } n   return x * n; n } n const int N = 80; n int n, a[N], d[5]; n int f[N][N][N][2]; n string s; n int NOR(int x) { n   if (x < 0) return -x; n   return 0; n } n void UPD(int &a, int b) { n   if (a == -1) n     a = b; n   else n     a = min(a, b); n } n int main() { n   n = in(); n   cin >> s; n   s =     + s; n   for (int i = 1; i <= n; i++) { n     a[i] = (s[i] ==  V ) ? 1 : (s[i] ==  K ) ? 2 : 0; n     d[a[i]]++; n   } n   memset(f, -1, sizeof(f)); n   f[0][0][0][0] = f[0][0][0][1] = 0; n   for (int z = 0; z <= d[0]; z++) n     for (int v = 0; v <= d[1]; v++) n       for (int k = 0; k <= d[2]; k++) n         for (int ov = 0; ov <= 1; ov++) n           if (f[z][v][k][ov] >= 0) { n             for (int nd = 0; nd <= 2; nd++) { n               if (ov == 1 && nd == 2) continue; n               int Z = z + (nd == 0), V = v + (nd == 1), K = k + (nd == 2); n               int d[5]; n               d[0] = z, d[1] = v, d[2] = k; n               int left = 0; n               for (int i = 1; i <= n; i++) { n                 if (a[i] == nd && d[a[i]] == 0) break; n                 if (d[a[i]] == 0) n                   left++; n                 else n                   d[a[i]]--; n               } n               UPD(f[Z][V][K][(nd == 1)], f[z][v][k][ov] + left); n             } n           } n   int res = -1; n   for (int ov = 0; ov <= 1; ov++) UPD(res, f[d[0]][d[1]][d[2]][ov]); n   if (res == -1) n     cout << 0; n   else n     cout << res; n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = 1e9 + 7; n const long long mod1 = 998244353; n const double pie = 3.1415926535; n unsigned long long power(unsigned long long x, unsigned long long y) { n   if (y == 0) n     return 1; n   else { n     if (y % 2 == 0) n       return power(x * x, y / 2); n     else n       return x * power(x * x, (y - 1) / 2); n   } n } n long long mod_power(long long x, long long y, long long m) { n   long long r = 1; n   x = x % m; n   if (x == 0) return 0; n   while (y > 0) { n     if (y & 1) r = (r * x) % m; n     y = y / 2; n     x = (x * x) % m; n   } n   return r; n } n long long gcd(long long x, long long y) { n   if (y == 0) return x; n   return gcd(y, x % y); n } n vector<long long> extended_Euclid(long long a, long long b) { n   vector<long long> v(3); n   if (b == 0) { n     v[0] = a; n     v[1] = 1; n     v[2] = 0; n     return v; n   } else { n     vector<long long> v1 = extended_Euclid(b, a % b); n     v[0] = v1[0]; n     v[1] = v1[2]; n     v[2] = v1[1] - (a / b) * v1[2]; n     return v; n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   int TESTS = 1; n   cin >> TESTS; n   while (TESTS--) { n     unsigned long long a; n     cin >> a; n     unsigned long long c = 0; n     c = __builtin_popcount(a); n     cout << power(2, c) << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int mod = 1e9 + 7; n long long binPow(long long a, long long b) { n   long long x = 1, y = a; n   while (b) { n     if (b & 1) x = (x * y) % mod; n     y = (y * y) % mod; n     b >>= 1; n   } n   return x % mod; n } n long long inverserEuler(int n) { return binPow(n, mod - 2); } n long long C(int k, int n) { n   vector<long long> f(n + 1, 1); n   for (int i = 2; i <= n; i++) f[i] = (f[i - 1] * i) % mod; n   return (f[n] * ((inverserEuler(f[k]) * inverserEuler(f[n - k])) % mod) % n           mod) % n          mod; n } n void trunghieu() { n   int n; n   cin >> n; n   int a[n], i, j; n   map<int, int> cnt; n   for (i = 0; i < n; ++i) cin >> a[i], cnt[a[i]]++; n   if (cnt.size() == 2) { n     map<int, int>::iterator it; n     it = cnt.begin(); n     int n1 = it->second, x1 = it->first; n     it++; n     int n2 = it->second, x2 = it->first; n     ; n     if (n1 == n2) n       cout <<  YES  << endl << x1 <<     << x2; n     else n       cout <<  NO ; n   } else n     cout <<  NO ; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(); n   trunghieu(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long int n, p, l, r, K; n long long int gt[100005], rev[100005], gt1[100005]; n long long int mu(long long int a, long long int n, long long int K) { n   if (n == 0) return 1; n   long long int q = mu(a, n / 2, K); n   if (n % 2 == 0) return q * q % K; n   return q * q % K * a % K; n } n long long int Combi(long long int n, long long int k, long long int p) { n   if (n < k || k < 0) return 0; n   long long int u = gt1[n] - gt1[n - k] - gt1[k]; n   long long int res = gt[n] * rev[k] % K * rev[n - k] % K; n   res = res * mu(p, u, K) % K; n   return res; n } n long long int solve(long long int p, long long int k) { n   K = 1; n   long long int phi = 1; n   for (int i = 1; i <= k; i++) K *= p; n   phi = K / p * (p - 1); n   gt[0] = rev[0] = 1; n   for (int i = 1; i <= 100000; i++) { n     gt1[i] = gt1[i - 1]; n     int j = i; n     while (j % p == 0) { n       j /= p; n       gt1[i]++; n     } n     gt[i] = gt[i - 1] * 1ll * j % K; n     rev[i] = mu(gt[i], phi - 1, K); n   } n   long long int res = 0; n   for (int m = 1; m <= n; m++) { n     int u = (m + l - 1) / 2 + 1; n     int v = (m + r) / 2; n     res = n         (res + Combi(n, m, p) * (Combi(m, u, p) - Combi(m, v + 1, p)) % K + K) % n         K; n   } n   return res; n } n vector<pair<long long int, long long int> > divi; n long long int extended_euclid(long long int a, long long int b, n                               long long int &x, long long int &y) { n   long long int xx = y = 0; n   long long int yy = x = 1; n   while (b) { n     long long int q = a / b; n     long long int t = b; n     b = a % b; n     a = t; n     t = xx; n     xx = x - q * xx; n     x = t; n     t = yy; n     yy = y - q * yy; n     y = t; n   } n   return a; n } n long long int CRT(long long int m1, long long int r1, long long int m2, n                   long long int r2) { n   long long int s, t; n   extended_euclid(r1, r2, s, t); n   long long int K = r1 * r2; n   long long int res = (m2 - m1) * s % K * r1 % K; n   res = (res + m1 + K) % K; n   return res; n } n long long int val[100005]; n long long int mod[100005]; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(NULL); n   cin >> n >> p >> l >> r; n   if (p == 1) { n     cout << 0 << endl; n     return 0; n   } n   for (int i = 2; i <= p / i; i++) { n     if (p % i == 0) { n       int cnt = 0; n       while (p % i == 0) { n         p /= i; n         cnt++; n       } n       divi.push_back(pair<long long int, long long int>(i, cnt)); n     } n   } n   if (p > 1) divi.push_back(pair<long long int, long long int>(p, 1)); n   for (int i = 0; i < divi.size(); i++) { n     val[i] = solve(divi[i].first, divi[i].second); n     mod[i] = 1; n     for (int j = 1; j <= divi[i].second; j++) mod[i] *= divi[i].first; n   } n   long long int res = val[0]; n   long long int M = mod[0]; n   for (int i = 1; i < divi.size(); i++) { n     res = CRT(res, M, val[i], mod[i]); n     M *= mod[i]; n   } n   if (l == 0) res = (res + 1) % M; n   cout << res << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int s, n, m, t, x, y; n vector<int> ord; n vector<vector<int>> g; n bool vis[200010]; n void dfs(int c) { n   vis[c] = true; n   for (auto &v : g[c]) { n     if (!vis[v]) dfs(v); n   } n   ord.push_back(c); n } n int main() { n   std::istream::sync_with_stdio(false); n   cin >> s; n   while (s--) { n     cin >> n >> m; n     vector<pair<int, int>> edges; n     g = vector<vector<int>>(n + 1); n     for (int i = 0; i < m; i++) { n       cin >> t >> x >> y; n       if (t == 1) { n         g[x].push_back(y); n       } n       edges.emplace_back(x, y); n     } n     ord.clear(); n     memset(vis, 0, sizeof(vis)); n     for (int i = 1; i <= n; i++) { n       if (!vis[i]) dfs(i); n     } n     vector<int> pos(n + 1); n     reverse(ord.begin(), ord.end()); n     for (int i = 0; i < n; i++) { n       pos[ord[i]] = i; n     } n     bool flag = false; n     for (int i = 1; i <= n; i++) { n       for (auto &v : g[i]) { n         if (pos[i] > pos[v]) flag = true; n       } n     } n     if (flag) { n       cout <<  NO  << endl; n       continue; n     } else { n       cout <<  YES  << endl; n       for (auto &v : edges) { n         if (pos[v.first] < pos[v.second]) { n           cout << v.first <<     << v.second << endl; n         } else { n           cout << v.second <<     << v.first << endl; n         } n       } n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int n, l, top, tmp, m, c[12]; n bool opt[12][11][1 << 13]; n void Search(int t, int v, int sum, int u, int i) { n   if (v < 0) return; n   if (sum >= v) opt[t][sum - v][u | (1 << t)] = 1; n   if (i >= t) return; n   if (((u >> i) & 1) == 1 && c[i] + 1 < c[t]) n     Search(t, v - c[i], sum, u ^ (1 << i), i + 1); n   Search(t, v, sum, u, i + 1); n } n bool Check() { n   for (int i = 0; i < l; i++) n     if (c[i] == 2) return 0; n   return 1; n } n int main() { n   scanf( %d , &n); n   l = 0; n   for (int i = 0; i < n; i++) { n     scanf( %d , &tmp); n     if (tmp > 1) c[l++] = tmp; n   } n   if (l > n / 2) { n     printf( NO n ); n     return 0; n   } n   if (l == 0) { n     if (n > 1) n       printf( NO n ); n     else n       printf( YES n ); n     return 0; n   } n   sort(c, c + l); n   top = n - l - c[0] + 1; n   opt[0][top][1] = 1; n   for (int i = 1; i < l; i++) n     for (int t = 0; t <= top; t++) { n       m = 1 << i; n       for (int u = 0; u < m; u++) n         if (opt[i - 1][t][u]) Search(i, c[i] - 1, t, u, 0); n     } n   if (opt[l - 1][0][1 << (l - 1)] && Check()) n     printf( YES n ); n   else n     printf( NO n ); n } n


#include <bits/stdc++.h> n using namespace std; n int n, m; n int a[100010]; n long long ans = 0; n int main() { n   scanf( %d%d , &n, &m); n   for (int i = 1; i <= n; i++) scanf( %d , &a[i]); n   for (int Q = 0; Q < 20; Q++) { n     for (int j = 1; j <= n; j++) n       if (a[j] & (1 << Q)) { n         int k = 0; n         for (k = j; k <= n && (a[k] & (1 << Q)); k++) n           ; n         k--; n         ans += ((long long)(k - j + 1) * (k - j + 2) / 2) << Q; n         j = k; n       } n   } n   for (int P = 1; P <= m; P++) { n     int p, v; n     scanf( %d%d , &p, &v); n     for (int Q = 0; Q < 20; Q++) n       if ((a[p] & (1 << Q)) ^ (v & (1 << Q))) { n         int l, r; n         for (l = p - 1; l && (a[l] & (1 << Q)); l--) n           ; n         for (r = p + 1; r <= n && (a[r] & (1 << Q)); r++) n           ; n         l = p - l; n         r -= p; n         if ((v >> Q) & 1) n           ans += ((long long)l * r) << Q; n         else n           ans -= ((long long)l * r) << Q; n       } n     a[p] = v; n     printf( %I64d n , ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m; n   char c; n   cin >> n >> m; n   vector<int> rows(n), cols(m); n   vector<vector<bool> > A(n); n   for (int i = 0; i < n; ++i) n     for (int j = 0; j < m; ++j) { n       cin >> c; n       if (c ==  * ) { n         A[i].push_back(true); n         rows[i]++; n         cols[j]++; n       } else n         A[i].push_back(false); n     } n   long long res = 0; n   for (int i = 0; i < n; ++i) n     for (int j = 0; j < m; ++j) n       if (A[i][j]) res += (cols[j] - 1) * (rows[i] - 1); n   cout << res; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m; n   scanf( %d %d , &n, &m); n   vector<vector<int>> t(n); n   for (int i = 0; i < m; ++i) { n     int x, y; n     scanf( %d %d , &x, &y); n     --x, --y; n     t[x].push_back(y); n     t[y].push_back(x); n   } n   vector<int> dist(n * n, -1); n   vector<pair<int, int>> parent(n * n, make_pair(-1, -1)); n   vector<bool> order(n * n, false); n   queue<pair<int, int>> q; n   q.push(make_pair(0, n - 1)); n   dist[n - 1] = 0; n   while (!q.empty()) { n     auto p = q.front(); n     q.pop(); n     if (p.first == n - 1 && p.second == 0) { n       int len = dist[(n - 1) * n]; n       printf( %d n , len); n       vector<int> r1, r2; n       r1.push_back(n - 1); n       r2.push_back(0); n       int pos1 = n - 1, pos2 = 0; n       while (pos1 != 0 || pos2 != n - 1) { n         int tmp = pos1; n         pos1 = parent[pos1 * n + pos2].first; n         pos2 = parent[tmp * n + pos2].second; n         r1.push_back(pos1); n         r2.push_back(pos2); n       } n       for (int i = len; i >= 0; --i) printf( %d  , r1[i] + 1); n       printf(  n ); n       for (int i = len; i >= 0; --i) printf( %d  , r2[i] + 1); n       printf(  n ); n       return 0; n     } n     for (auto i : t[p.first]) { n       if (order[i * n + p.second]) continue; n       order[i * n + p.second] = true; n       for (auto j : t[p.second]) { n         if (i != j && dist[i * n + j] == -1) { n           parent[i * n + j] = p; n           dist[i * n + j] = dist[p.first * n + p.second] + 1; n           q.push(make_pair(i, j)); n         } n       } n     } n   } n   printf( -1 n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int mo = 1e9 + 7; n const int N = 200005; n map<int, int> mx, my; n int n, x, y, dx, dy, cnt, answer; n int parent[N], Size[N]; n bool flag[N]; n int get_parent(int x) { n   if (parent[x] == x) { n     return x; n   } else { n     return get_parent(parent[x]); n   } n } n int main() { n   cin >> n; n   for (int i = 1; i <= 2 * n; ++i) { n     parent[i] = i; n     Size[i] = 1; n   } n   for (int i = 1; i <= n; ++i) { n     cin >> x >> y; n     if (mx.find(x) != mx.end()) { n       dx = mx[x]; n     } else { n       dx = mx[x] = ++cnt; n     } n     if (my.find(y) != my.end()) { n       dy = my[y]; n     } else { n       dy = my[y] = ++cnt; n     } n     dx = get_parent(dx); n     dy = get_parent(dy); n     if (dx == dy) { n       flag[dx] = 1; n     } else { n       if (Size[dx] > Size[dy]) swap(dx, dy); n       parent[dx] = dy; n       Size[dy] += Size[dx]; n       flag[dy] |= flag[dx]; n     } n   } n   answer = 1; n   for (int i = 1; i <= cnt; ++i) { n     if (get_parent(i) == i) { n       int temp = 1; n       for (int j = 1; j <= Size[i]; ++j) { n         temp = temp * 2 % mo; n       } n       if (!flag[i]) --temp; n       answer = (long long)answer * temp % mo; n     } n   } n   cout << answer << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int n, x; n   cin >> n >> x; n   int mins = 0; n   int prevr = 1; n   for (int i = 0; i < int(n); i++) { n     int l, r; n     cin >> l >> r; n     mins += ((l - prevr) % x + ((r - l) + 1)); n     prevr = r + 1; n   } n   cout << mins << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int dp[2005][2005][2][2]; n int m, d, mod = 1e9 + 7; n string a, b; n int solve(int i, int mm, bool aa, bool bb) { n   if (i == a.size()) return !mm; n   int &x = dp[i][mm][aa][bb]; n   if (x != -1) return x; n   x = 0; n   for (int j = 0; j <= 9; j++) { n     if (i % 2 && j != d || !(i % 2) && j == d) continue; n     if (!aa && a[i] -  0  > j || !bb && b[i] -  0  < j) continue; n     bool na = aa | a[i] -  0  < j, nb = bb | b[i] -  0  > j; n     x = (x + solve(i + 1, (mm * 10 + j) % m, na, nb)) % mod; n   } n   return x; n } n int main() { n   cin >> m >> d >> a >> b; n   memset(dp, -1, sizeof dp); n   cout << solve(0, 0, 0, 0); n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = 0x3f3f3f3f; n const long long linf = 1e18; n const double pi = acos(-1.0); n const int MAXN = 150000 + 10; n const int MAXM = 1e5 + 10; n const double eps = 1e-8; n bool du[MAXN]; n vector<int> g[MAXN]; n bool vis[MAXN]; n int sum; n bool flag; n void dfs(int u, int num) { n   if (!flag) return; n   vis[u] = 1; n   ++sum; n   for (int i = 0; i < g[u].size(); ++i) { n     int v = g[u][i]; n     if (vis[v]) continue; n     if (num != g[v].size()) { n       flag = 0; n       return; n     } n     dfs(v, num); n   } n } n int main() { n   int n, m; n   scanf( %d%d , &n, &m); n   while (m--) { n     int u, v; n     scanf( %d%d , &u, &v); n     g[u].push_back(v); n     g[v].push_back(u); n   } n   flag = 1; n   for (int i = 1; i <= n; ++i) { n     if (!vis[i]) { n       sum = 0; n       dfs(i, g[i].size()); n       if (g[i].size() != sum - 1) flag = 0; n     } n     if (!flag) break; n   } n   puts(flag ?  YES  :  NO ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int t; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cin >> t; n   while (t--) { n     string s; n     cin >> s; n     s =  0  + s; n     s = s +  0 ; n     for (int i = 1; i <= s.size(); i++) { n       if (s[i] ==  ? ) { n         if (s[i - 1] ==  a ) { n           if (s[i + 1] ==  b ) { n             s[i] =  c ; n           } else { n             s[i] =  b ; n           } n         } else { n           if (s[i - 1] ==  b ) { n             if (s[i + 1] ==  a ) { n               s[i] =  c ; n             } else { n               s[i] =  a ; n             } n           } else { n             if (s[i + 1] ==  b ) { n               s[i] =  a ; n             } else { n               s[i] =  b ; n             } n           } n         } n       } n     } n     bool b = 1; n     for (int i = 1; i <= s.size(); i++) { n       if (s[i] == s[i - 1]) { n         b = 0; n       } n     } n     if (b) { n       for (int i = 1; i <= s.size() - 2; i++) { n         cout << s[i]; n       } n     } else { n       cout <<  -1 ; n     } n     cout <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int mas[21][21]; n int n, m; n inline bool checkarr() { n   for (int i = 0; i < n; i++) { n     int wrongs = 0; n     for (int j = 0; j < m; j++) { n       if (mas[i][j] != j + 1) wrongs++; n       if (wrongs > 2) return false; n     } n   } n   return true; n } n inline void swapa(int a, int b) { n   for (int j = 0; j < n; j++) { n     int t = mas[j][a]; n     mas[j][a] = mas[j][b]; n     mas[j][b] = t; n   } n } n int main() { n   cin >> n >> m; n   int i, j; n   for (i = 0; i < n; i++) { n     for (j = 0; j < m; j++) { n       cin >> mas[i][j]; n     } n   } n   if (checkarr()) { n     cout <<  YES ; n     return 0; n   } n   for (i = 0; i < m; i++) { n     for (j = i + 1; j < m; j++) { n       swapa(i, j); n       if (checkarr()) { n         cout <<  YES ; n         return 0; n       } n       swapa(i, j); n     } n   } n   cout <<  NO ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long mxN = 1e5 + 5; n const long long INF = 1e18; n const long long mod = 1e9 + 7; n signed main() { n   long long n; n   cin >> n; n   vector<string> v(n); n   for (long long i = 0; i < n; i++) { n     cin >> v[i]; n   } n   map<long long, long long> o, c; n   long long per = 0; n   for (long long i = 0; i < n; i++) { n     string s = v[i]; n     stack<long long> st; n     for (auto x : s) { n       if (st.empty()) { n         st.push(x); n       } else { n         if (x ==  ) ) { n           if (st.top() ==  ( ) n             st.pop(); n           else n             st.push(x); n         } else n           st.push(x); n       } n     } n     if (st.empty()) n       per++; n     else { n       long long open = 0, closing = 0; n       while (!st.empty()) { n         if (st.top() ==  ) ) n           open++; n         else n           closing++; n         st.pop(); n       } n       if (open == 0) { n         c[closing]++; n       } n       if (closing == 0) { n         o[open]++; n       } n     } n   } n   long long ans = per / 2; n   for (auto x : o) { n     ans += min(x.second, c[x.first]); n   } n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n int a, c, d[205], f, n, b, x, i; n string s, s1, s11, s12; n char i1, i2, j; n int main() { n   cin >> n; n   for (i = 1; i <= n; i++) { n     cin >> s1; n     b = s1.size(); n     c = c + b; n     s = s +  % ; n     s = s + s1; n   } n   c = c + n - 1; n   for (i1 =  a ; i1 <=  z ; i1++) { n     s1 = i1; n     x = s.find(s1); n     if (x == -1) { n       cout << s1; n       return 0; n     } n   } n   for (i1 =  a ; i1 <=  z ; i1++) { n     for (i2 =  a ; i2 <=  z ; i2++) { n       s11 = i1; n       s12 = i2; n       s1 = s11 + s12; n       x = s.find(s1); n       if (x == -1) { n         cout << s1; n         return 0; n       } n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, k; n vector<int> cur; n unordered_set<long long> bad; n unordered_set<int> was; n void err() { n   cout <<  impossible  << endl; n   exit(0); n } n void go(int x) { n   cur.push_back(x); n   vector<int> g; n   for (auto it = was.begin(); it != was.end(); it++) n     if (bad.count(x * 1000000ll + (*it)) == 0) g.push_back(*it); n   for (int i = 0; i < g.size(); i++) was.erase(g[i]); n   for (int i = 0; i < g.size(); i++) go(g[i]); n } n int main() { n   ios::sync_with_stdio(false); n   cin >> n >> m >> k; n   for (int i = 0; i < m; i++) { n     int x, y; n     cin >> x >> y; n     x--; n     y--; n     bad.insert(x * 1000000ll + y); n     bad.insert(y * 1000000ll + x); n   } n   for (int i = 1; i < n; i++) was.insert(i); n   vector<vector<int> > comps; n   for (int i = 1; i < n; i++) n     if (was.count(i)) { n       cur.clear(); n       was.erase(i); n       go(i); n       comps.push_back(cur); n     } n   int sum = 0; n   for (int i = 0; i < comps.size(); i++) { n     int cnt = 0; n     for (int j = 0; j < comps[i].size(); j++) n       if (bad.count(comps[i][j]) == 0) cnt++; n     if (cnt == 0) err(); n     sum += cnt; n   } n   if (k < comps.size() || k > sum) err(); n   cout <<  possible  << endl; n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n template <typename Tp> n inline void read(Tp &x) { n   static bool neg; n   static char c; n   x = 0, neg = 0, c = getchar(); n   for (; !isdigit(c); c = getchar()) { n     if (c ==  - ) { n       neg = 1; n     } n   } n   for (; isdigit(c); c = getchar()) { n     x = x * 10 + c -  0 ; n   } n   if (neg) { n     x = -x; n   } n } n const int INF = 0x3f3f3f3f; n const int N = 3e3 + 5; n const int M = 2e4 + 5; n const int K = 1e5 + 5; n int vis[N][N], dp[N][N]; n int n, m, k; n int head[N], E = 0; n struct Edge { n   int to, next; n } e[M * 2]; n inline void addEdge(int u, int v) { n   e[++E] = (Edge){v, head[u]}; n   head[u] = E; n } n namespace Trie { n unordered_map<int, unordered_map<int, unordered_set<int>>> store; n inline void set(int a, int b, int c) { store[a][b].insert(c); } n inline bool get(int a, int b, int c) { return (bool)store[a][b].count(c); } n }  // namespace Trie n int main() { n   read(n), read(m), read(k); n   for (int i = 0, u, v; i < m; ++i) { n     read(u), read(v); n     addEdge(u, v); n     addEdge(v, u); n   } n   for (int i = 0, a, b, c; i < k; ++i) { n     read(a), read(b), read(c); n     Trie::set(a, b, c); n   } n   memset(vis, -1, sizeof(vis)); n   memset(dp, 0x3f, sizeof(dp)); n   dp[0][1] = 0; n   queue<pair<int, int>> q; n   q.emplace((pair<int, int>){0, 1}); n   while (!q.empty()) { n     pair<int, int> u = q.front(); n     q.pop(); n     int a = u.first, b = u.second, c; n     for (int i = head[b]; i; i = e[i].next) { n       c = e[i].to; n       if (vis[b][c] == -1) { n         if (!Trie::get(a, b, c)) { n           vis[b][c] = a; n           dp[b][c] = dp[a][b] + 1; n           q.emplace((pair<int, int>){b, c}); n         } n       } n     } n   } n   int ans = INF, ansPos; n   for (int i = 1; i <= n; ++i) { n     if (dp[i][n] < ans) { n       ans = dp[i][n]; n       ansPos = i; n     } n   } n   if (ans == INF) { n     puts( -1 ); n     return 0; n   } else { n     printf( %d n , ans); n     vector<int> vec; n     vec.emplace_back(n); n     vec.emplace_back(ansPos); n     int u = ansPos, v = n; n     while (u != 1) { n       int t = v; n       v = u; n       u = vis[u][t]; n       vec.emplace_back(u); n     } n     for (auto it = vec.rbegin(); it != vec.rend(); ++it) { n       printf( %d  , *it); n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n void add(int& a, int b) { n   a += b; n   a = min(a, 100000000); n } n const int MX = 300005; n int root[MX]; n bool is_left[MX]; n vector<int> nodes[MX]; n int left_size[MX], right_size[MX]; n int ans = 0; n char s[MX]; n vector<int> comps[MX]; n int main() { n   int n, k; n   ignore = scanf( %d %d , &n, &k); n   ignore = scanf(  %s , s + 1); n   for (int i = 1; i <= k; i++) { n     int c; n     ignore = scanf(  %d , &c); n     while (c--) { n       int x; n       ignore = scanf( %d , &x); n       comps[x].push_back(i); n     } n   } n   for (int i = 1; i <= k; i++) { n     root[i] = i; n     is_left[i] = false; n     nodes[i].push_back(i); n     right_size[i] = 1; n   } n   for (int i = 1; i <= n; i++) { n     if (comps[i].size() == 1) { n       int x = comps[i][0]; n       ans -= min(left_size[root[x]], right_size[root[x]]); n       if (s[i] ==  0 ) { n         if (is_left[x]) { n           add(right_size[root[x]], MX); n         } else { n           add(left_size[root[x]], MX); n         } n       } else { n         if (is_left[x]) { n           add(left_size[root[x]], MX); n         } else { n           add(right_size[root[x]], MX); n         } n       } n       ans += min(left_size[root[x]], right_size[root[x]]); n     } else if (comps[i].size() == 2) { n       int x = comps[i][0], y = comps[i][1]; n       if (root[x] != root[y]) { n         ans -= min(left_size[root[x]], right_size[root[x]]); n         ans -= min(left_size[root[y]], right_size[root[y]]); n         if (nodes[root[x]].size() > nodes[root[y]].size()) { n           swap(x, y); n         } n         if ((is_left[x] == is_left[y]) != (s[i] ==  1 )) { n           for (int v : nodes[root[x]]) is_left[v] = !is_left[v]; n           swap(left_size[root[x]], right_size[root[x]]); n         } n         add(left_size[root[y]], left_size[root[x]]); n         add(right_size[root[y]], right_size[root[x]]); n         for (int v : nodes[root[x]]) { n           nodes[root[y]].push_back(v); n           root[v] = root[y]; n         } n         ans += min(left_size[root[x]], right_size[root[x]]); n       } n     } n     printf( %d n , ans); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const double PI = acos(-1); n const double eps = 1e-9; n template <typename T> n T sqr(T x) { n   return x * x; n } n double sind(double x) { return sin(x * PI / 180); } n double cosd(double x) { return cos(x * PI / 180); } n double tand(double x) { return tan(x * PI / 180); } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int r, c, i, j, x = 0, y = 0; n   cin >> r >> c; n   vector<string> v; n   bool mark[c + 1]; n   memset(mark, 0, sizeof(mark)); n   for (i = 0; i < r; i++) { n     string s; n     cin >> s; n     v.push_back(s); n   } n   for (auto i : v) { n     string s; n     bool f = 1; n     s = i; n     for (j = 0; j < c; j++) { n       if (s[j] ==  S ) { n         f = 0; n         mark[j] = 1; n       } n     } n     if (f) x++; n   } n   for (i = 0; i < c; i++) { n     if (mark[i] == 0) y++; n   } n   int ans = 0; n   ans += x * c; n   ans += y * (r - x); n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n class Graph { n   long long int v; n   list<pair<long long int, long long int>> *adj; n  n  public: n   Graph(long long int v) : v(v) { n     adj = new list<pair<long long int, long long int>>[v]; n   } n   void addEdge(long long int u, long long int v, long long int w, n                bool bidir = true) { n     adj[u].push_back(make_pair(v, w)); n     if (bidir) adj[v].push_back(make_pair(u, w)); n   } n   void dijkstra() { n     vector<long long int> distance(v, LONG_MAX); n     priority_queue<pair<long long int, long long int>, n                    vector<pair<long long int, long long int>>, n                    greater<pair<long long int, long long int>>> n         pq; n     pq.push(make_pair(0, 0)); n     distance[0] = 0; n     while (!pq.empty()) { n       auto ele = pq.top(); n       pq.pop(); n       for (auto itr = adj[ele.second].begin(); itr != adj[ele.second].end(); n            itr++) { n         long long int v = itr->first; n         long long int weight = itr->second; n         if (distance[ele.second] != LONG_MAX && n             distance[ele.second] + weight < distance[v]) { n           distance[v] = distance[ele.second] + weight; n           pq.push(make_pair(distance[v], v)); n         } n       } n     } n     for (auto ele : distance) cout << ele <<    ; n   } n }; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(nullptr); n   cout.tie(nullptr); n   long long int n; n   cin >> n; n   vector<long long int> v(n); n   for (long long int i = 0; i < n; i++) cin >> v[i]; n   Graph g(n); n   for (long long int i = 0; i < n - 1; i++) g.addEdge(i, i + 1, 1); n   for (long long int i = 0; i < n; i++) n     if (i != v[i] - 1) g.addEdge(i, v[i] - 1, 1, false); n   g.dijkstra(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using Long = int64_t; n constexpr Long Z = 0; n bool fire(Long N, Long M, int K, const vector<Long>& X, const vector<Long>& Y, n           Long t) { n   map<Long, int> xs; n   map<Long, int> ys; n   xs[0] = 0; n   xs[N] = 0; n   ys[0] = 0; n   ys[M] = 0; n   for (int i = 0; i < K; ++i) { n     Long x = X[i]; n     Long y = Y[i]; n     xs[max(x - t, Z)] = 0; n     xs[min(x + 1 + t, N)] = 0; n     ys[max(y - t, Z)] = 0; n     ys[min(y + 1 + t, M)] = 0; n   } n   int i = 0; n   for (auto& p : xs) { n     p.second = i++; n   } n   i = 0; n   for (auto& p : ys) { n     p.second = i++; n   } n   int nx = (int)xs.size(); n   int ny = (int)ys.size(); n   vector<vector<bool>> mat(ny + 1, vector<bool>(nx + 1)); n   for (int i = 0; i < K; ++i) { n     Long x = X[i]; n     Long y = Y[i]; n     int bx = xs[max(x - t, Z)]; n     int ex = xs[min(x + 1 + t, N)]; n     int by = ys[max(y - t, Z)]; n     int ey = ys[min(y + 1 + t, M)]; n     for (int y = by; y < ey; ++y) n       for (int x = bx; x < ex; ++x) mat[y][x] = 1; n   } n   int bx = -1; n   int ex = -1; n   int by = -1; n   int ey = -1; n   for (int y = 0; y < ny - 1; ++y) { n     for (int x = 0; x < nx - 1; ++x) { n       if (mat[y][x]) continue; n       if (bx == -1) { n         bx = x; n         ex = x + 1; n         by = y; n         ey = y + 1; n       } else { n         bx = min(bx, x); n         ex = max(ex, x + 1); n         by = min(by, y); n         ey = max(ey, y + 1); n       } n     } n   } n   if (bx == -1) return true; n   Long bxx = 0, exx = N, byy = 0, eyy = M; n   for (const auto& p : xs) { n     if (p.second == bx) bxx = p.first; n     if (p.second == ex) exx = p.first; n   } n   for (const auto& p : ys) { n     if (p.second == by) byy = p.first; n     if (p.second == ey) eyy = p.first; n   } n   if (exx - bxx > 2 * t + 1 || eyy - byy > 2 * t + 1) return false; n   return true; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(nullptr); n   long N, M; n   int K; n   cin >> N >> M >> K; n   vector<Long> X(K), Y(K); n   for (int i = 0; i < K; ++i) { n     cin >> X[i] >> Y[i]; n     --X[i]; n     --Y[i]; n   } n   Long lb = -1; n   Long ub = max(N, M); n   while (ub - lb >= 2) { n     Long mid = (ub + lb) / 2; n     if (fire(N, M, K, X, Y, mid)) { n       ub = mid; n     } else { n       lb = mid; n     } n   } n   cout << ub <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n constexpr long long INF = 2e18; n constexpr long long MOD = 1e9 + 7; n constexpr long long MAXN = 2e5 + 3; n void solve() { n   long long n; n   cin >> n; n   long long k; n   cin >> k; n   vector<long long> arr(n); n   for (long long i = 0; i < n; ++i) { n     long long &x = arr[i]; n     cin >> x; n   } n   vector<long long> ans(n); n   set<long long> s; n   set<long long> c; n   for (long long i = 0; i < 256; ++i) s.emplace(i); n   long long last = -INF; n   long long maxx = -1; n   for (long long i = 0; i < n; ++i) { n     pair<long long, long long> x = pair<long long, long long>(arr[i], i); n     long long v = -1; n     for (long long j = arr[i]; j >= max(0ll, arr[i] - k + 1); --j) { n       if (s.count(j)) { n         v = j; n       } n       if (c.count(j)) { n         v = j; n         break; n       } n     } n     for (long long i = v; i <= x.first; ++i) { n       if (s.count(i)) s.erase(i); n     } n     c.emplace(v); n     ans[i] = v; n   } n   for (long long x : ans) { n     cout << x <<    ; n   } n   cout <<   n ; n } n signed main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   long long t = 1; n   while (t--) solve(); n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, a[100010], s[100010], sp, cnt; n long long tot, sum, pj; n int main() { n   cin >> n >> m; n   for (register int i = 1; i <= n; i++) cin >> a[i], tot += a[i]; n   if (tot % m != 0) { n     cout <<  No  << endl; n     return 0; n   } n   pj = tot / m; n   for (register int i = 1; i <= n; i++) { n     sum += a[i]; n     if (sum == pj) { n       sum = 0; n       s[++cnt] = i - sp; n       sp = i; n     } n     if (sum > pj) { n       cout <<  No  << endl; n       return 0; n     } n   } n   cout <<  Yes  << endl; n   for (register int i = 1; i <= cnt; i++) cout << s[i] <<    ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   string s; n   cin >> s; n   int fre[26] = {0}; n   for (int i = 0; i < n; i++) { n     fre[s[i] -  a ] = fre[s[i] -  a ] + 1; n   } n   string ans =   ; n   for (int i = 0; i < 26; i++) { n     for (int j = 0; j < fre[i]; j++) { n       ans = ans + char(97 + i); n     } n   } n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n #pragma comment(linker,  /STACK:64000000 ) n struct arc { n   int f, s, prev; n } arr[300000]; n int q[100005]; n int beg[100005]; n int kol = 0; n void add_arc(int f, int s) { n   f--; n   s--; n   arr[kol].f = f; n   arr[kol].s = s; n   arr[kol].prev = beg[f]; n   beg[f] = kol++; n   arr[kol].f = s; n   arr[kol].s = f; n   arr[kol].prev = beg[s]; n   beg[s] = kol++; n } n long long tmp[100005]; n long long DFS(int pos, int fr = 0, int p = -1) { n   long long child = 0, ret = 0; n   int nfr = 0; n   for (int i = beg[pos]; i != -1; i = arr[i].prev) { n     if (arr[i].s == p) { n       continue; n     } n     if (q[arr[i].s] > 1) { n       q[arr[i].s]--; n       tmp[fr + nfr] = DFS(arr[i].s, fr + nfr, pos) + 1; n       child += q[arr[i].s]; n       nfr++; n     } else { n       child += q[arr[i].s]; n     } n   } n   sort(tmp + fr, tmp + fr + nfr, greater<long long>()); n   if (nfr >= q[pos]) { n     for (int i = 0; i < q[pos]; i++) { n       ret += tmp[fr + i] + 1; n     } n     q[pos] = 0; n   } else { n     for (int i = 0; i < nfr; i++) { n       ret += tmp[fr + i] + 1; n     } n     q[pos] -= nfr; n     ret += 2 * min((long long)q[pos], child); n     q[pos] -= min((long long)q[pos], child); n   } n   return ret; n } n int main() { n   memset(beg, -1, sizeof beg); n   int n; n   scanf( %d , &n); n   for (int i = 0; i < n; i++) { n     scanf( %d , &q[i]); n   } n   for (int i = 0; i < n - 1; i++) { n     int f, s; n     scanf( %d%d , &f, &s); n     add_arc(f, s); n   } n   int s; n   scanf( %d , &s); n   s--; n   if (q[s] != 0) { n     cout << DFS(s) << endl; n   } else { n     cout << 0 << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX = 100100; n const long long oo = 1e18; n int N; n long long P[MAX], D[MAX]; n int L[MAX], R[MAX]; n void init_L() { n   stack<int> S; n   for (int i = 0; i <= N + 1; ++i) { n     while (S.size() >= 2) { n       int x = S.top(); n       S.pop(); n       if (D[x] >= P[i] - P[S.top()]) { n         S.push(x); n         break; n       } n     } n     if (!S.empty()) L[i] = S.top(); n     S.push(i); n   } n } n void init_R() { n   stack<int> S; n   for (int i = N + 1; i >= 0; --i) { n     while (S.size() >= 2) { n       int x = S.top(); n       S.pop(); n       if (D[x] >= P[S.top()] - P[i]) { n         S.push(x); n         break; n       } n     } n     if (!S.empty()) R[i] = S.top(); n     S.push(i); n   } n } n template <class T> n struct MinQ { n   deque<T> D, Q; n   T top() { return D.front(); } n   void push(T x) { n     while (!D.empty() && x < D.back()) D.pop_back(); n     D.push_back(x); n     Q.push_back(x); n   } n   void pop() { n     if (D.front() == Q.front()) D.pop_front(); n     Q.pop_front(); n   } n   T front() { return Q.front(); } n   T empty() { return Q.empty(); } n   T size() { return Q.size(); } n }; n long long low(int x) { n   if (x == N + 1) return -1e10; n   long long ret = P[R[x]] - D[x]; n   return ret < P[x] ? ret : +oo; n } n long long high(int x) { n   if (x == 0) return +1e10; n   long long ret = P[L[x]] + D[x]; n   return ret > P[x] ? ret : -oo; n } n bool check(long long W) { n   MinQ<long long> Q; n   for (int a = 0, b = 0; a <= N; ++a) { n     for (; b <= N + 1 && P[b] - P[a] <= W; ++b) Q.push(low(b)); n     Q.pop(); n     if (!Q.empty() && high(a) >= Q.top()) return true; n   } n   return false; n } n int main() { n   scanf( %d , &N); n   for (int i = 0; i <= N + 1; ++i) scanf( %lld , P + i); n   for (int i = 1; i <= N; ++i) scanf( %lld , D + i), D[i] *= 2; n   D[0] = D[N + 1] = oo; n   init_L(); n   init_R(); n   if (R[0] != N + 1) { n     puts( 0 ); n     return 0; n   } n   long long lo = 1, hi = 1e10; n   while (lo < hi) { n     long long mid = (lo + hi) / 2; n     check(mid) ? hi = mid : lo = mid + 1; n   } n   printf( %.1lf n , lo / 2.0); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1000010; n int t, sp[N]; n map<int, int> n, m, s; n vector<pair<int, int> > _n, _m, _s; n long long n_val, m_val, s_val; n void sieve(void) { n   for (int i = 2; i * i < N; ++i) { n     if (sp[i]) continue; n     sp[i] = i; n     for (int j = i * i; j < N; j += i) { n       if (sp[j]) continue; n       sp[j] = i; n     } n   } n   for (int i = 2; i < N; ++i) { n     if (sp[i]) continue; n     sp[i] = i; n   } n } n int size; n long long Less; n void backtrack(int at, long long val) { n   if (at == size) { n     if (val <= n_val) ++Less; n     return; n   } n   for (int i = 0; i <= _s[at].second; ++i) { n     backtrack(at + 1, val); n     val *= 1LL * _s[at].first; n   } n   return; n } n int main() { n   sieve(); n   scanf( %d , &t); n   while (t--) { n     n.clear(), m.clear(), s.clear(); n     _n.clear(), _m.clear(), _s.clear(); n     for (int i = 0; i < 3; ++i) { n       int x; n       scanf( %d , &x); n       while (x > 1) { n         int p = sp[x]; n         while (x % p == 0) { n           ++n[p], x /= p; n         } n       } n     } n     for (int i = 0; i < 3; ++i) { n       int x; n       scanf( %d , &x); n       while (x > 1) { n         int p = sp[x]; n         while (x % p == 0) { n           ++m[p], x /= p; n         } n       } n     } n     for (int i = 0; i < 3; ++i) { n       int x; n       scanf( %d , &x); n       while (x > 1) { n         int p = sp[x]; n         while (x % p == 0) { n           ++s[p], x /= p; n         } n       } n     } n     ++s[2]; n     n_val = m_val = s_val = 1LL; n     for (auto it : n) { n       _n.emplace_back(it.first, it.second); n       for (int i = 0; i < it.second; ++i) { n         n_val *= 1LL * it.first; n       } n     } n     for (auto it : m) { n       _m.emplace_back(it.first, it.second); n       for (int i = 0; i < it.second; ++i) { n         m_val *= 1LL * it.first; n       } n     } n     for (auto it : s) { n       _s.emplace_back(it.first, it.second); n       for (int i = 0; i < it.second; ++i) { n         s_val *= 1LL * it.first; n       } n     } n     int sz = _n.size(); n     long long tot = m_val; n     for (int mask = 1; mask < 1 << sz; ++mask) { n       int nope = 0, on = 0; n       long long num = 1LL; n       for (int i = 0; i < sz; ++i) { n         if (!(mask & 1 << i)) continue; n         ++on; n         int p = _n[i].first, e = _n[i].second; n         if (s[p] + 1 > e) { n           nope = 1; n           break; n         } n         for (int j = 0; j <= s[p]; ++j) { n           num *= 1LL * p; n         } n       } n       if (nope) continue; n       long long cur = m_val / num; n       if (on & 1) cur = -cur; n       tot += cur; n     } n     Less = 0; n     size = _s.size(); n     backtrack(0, 1LL); n     tot += Less; n     printf( %lld n , tot); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MX = 25; n int main(int argc, char *argv[]) { n   int n, k; n   cin >> n >> k; n   string a[n]; n   for (int i = (0), _b = (n); i < (_b); ++i) cin >> a[i]; n   uint8_t g[4]; n   uint32_t b[n]; n   for (int i = (0), _b = (n); i < (_b); ++i) { n     uint8_t x = 0; n     int idx = 0; n     for (int j = (0), _b = (a[i].length()); j < (_b); ++j) { n       if (a[i][j] ==  . ) { n         g[idx] = x; n         x = 0; n         ++idx; n       } else n         x = x * 10 + a[i][j] -  0 ; n     } n     g[idx] = x; n     b[i] = (g[0] << 24) | (g[1] << 16) | (g[2] << 8) | g[3]; n   } n   uint32_t mask = 0xffffffff; n   uint32_t ans = 0; n   while (mask) { n     set<uint32_t> s; n     for (int i = (0), _b = (n); i < (_b); ++i) s.insert(b[i] & mask); n     if (s.size() == k) ans = mask; n     mask <<= 1; n   } n   if (!ans) n     cout << -1 << endl; n   else { n     uint8_t a0 = (ans >> 24) & 0xff; n     uint8_t a1 = (ans >> 16) & 0xff; n     uint8_t a2 = (ans >> 8) & 0xff; n     uint8_t a3 = ans & 0xff; n     printf( %d.%d.%d.%d n , a0, a1, a2, a3); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n map<int, vector<string> > mp; n string s; n int n, pos = 0; n ; n void dfs(int lvl) { n   int j = pos; n   while (s[j] !=  , ) j++; n   mp[lvl].push_back(s.substr(pos, j - pos)); n   pos = j + 1; n   j++; n   while (s[j] !=  , ) j++; n   int ct = stoi(s.substr(pos, j - pos)); n   pos = j + 1; n   for (int i = 1; i <= ct; i++) dfs(lvl + 1); n } n int main() { n   cin >> s; n   s +=  , ; n   n = s.length(); n   while (pos < n) dfs(1); n   cout << mp.size() <<   n ; n   for (auto it = mp.begin(); it != mp.end(); it++) { n     vector<string> vec = (*it).second; n     for (string str : vec) cout << str <<    ; n     cout <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   double n, m, a; n   cin >> n >> m >> a; n   cout << (long long)(ceil(n / a) * ceil(m / a)); n   return 0; n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:100000000 ) n using namespace std; n long long x[3], y[3]; n int main() { n   for (int i = 0; i < 3; i++) cin >> x[i] >> y[i]; n   if (x[0] == x[1] && x[0] == x[2] || y[0] == y[1] && y[0] == y[2]) { n     printf( 1 n ); n     return 0; n   } n   int perm[3] = {0, 1, 2}; n   long long minx = min(x[0], min(x[1], x[2])); n   long long maxx = max(x[0], max(x[1], x[2])); n   long long miny = min(y[0], min(y[1], y[2])); n   long long maxy = max(y[0], max(y[1], y[2])); n   do { n     long long x1 = x[perm[0]], y1 = y[perm[0]]; n     long long x2 = x[perm[1]], y2 = y[perm[1]]; n     long long x3 = x[perm[2]], y3 = y[perm[2]]; n     bool gr1 = false; n     bool gr2 = false; n     bool gr3 = false; n     if ((x1 == minx || x1 == maxx) && (y1 == miny || y1 == maxy)) gr1 = true; n     if ((x2 == minx || x2 == maxx) && (y2 == miny || y2 == maxy)) gr2 = true; n     if ((x3 == minx || x3 == maxx) && (y3 == miny || y3 == maxy)) gr3 = true; n     if (gr1 && gr2 && gr3) { n       printf( 2 ); n       return 0; n     } n     if ((x1 == x2 || y1 == y2) && gr1 && gr3 && !gr2) { n       printf( 2 ); n       return 0; n     } n   } while (next_permutation(perm, perm + 3)); n   printf( 3 ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int mod = int(1e9 + 7); n const double PI = acos(-1.0); n const int N = 200000; n long long n, a; n long long p[N], b[N]; n bool check(int x) { n   long long i, m; n   m = a; n   for (i = 0; i < x; i++) n     if (b[n - x + i] < p[i]) m -= p[i] - b[n - x + i]; n   return (m >= 0); n } n int main() { n   long long m, l, r, i; n   cin >> n >> m >> a; n   for (i = 0; i < n; i++) cin >> b[i]; n   for (i = 0; i < m; i++) cin >> p[i]; n   sort(b, b + n); n   sort(p, p + m); n   l = 0; n   r = min(n, m); n   while (l < r) { n     m = (l + r + 1) / 2; n     if (check(m)) n       l = m; n     else n       r = m - 1; n   } n   m = 0; n   for (i = 0; i < l; i++) m += p[i]; n   cout << l <<     << max(0ll, m - a); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n string a[2005]; n char s[2005]; n int f[2005 * 2][2005], h[2005], n, m, k; n void dp(int l, int r, int x) { n   if (l >= r) return; n   int L = ++m, R = ++m, mid = l; n   for (int i = l; i < r; i++) n     if (h[i] < h[mid]) mid = i; n   dp(l, mid, L), dp(mid + 1, r, R); n   for (int i = 0; i < mid - l + 2; i++) n     for (int j = 0; j < r - mid + 1; j++) n       if (i + j <= k) n         f[x][i + j] = max(f[x][i + j], h[mid] * i * j + f[L][i] + f[R][j]); n } n int main() { n   scanf( %d%d  , &n, &k); n   for (int i = 0; i < n; i++) gets(s), a[i] = s; n   sort(a, a + n); n   for (int i = 0; i < n - 1; i++) { n     h[i] = min(a[i].size(), a[i + 1].size()); n     for (int j = 0; j < h[i]; j++) n       if (a[i][j] != a[i + 1][j]) h[i] = j; n   } n   dp(0, n - 1, 0); n   printf( %d n , f[0][k]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void __print(int x) { cerr << x; } n void __print(long x) { cerr << x; } n void __print(long long x) { cerr << x; } n void __print(unsigned x) { cerr << x; } n void __print(unsigned long x) { cerr << x; } n void __print(unsigned long long x) { cerr << x; } n void __print(float x) { cerr << x; } n void __print(double x) { cerr << x; } n void __print(long double x) { cerr << x; } n void __print(char x) { cerr <<      << x <<     ; } n void __print(const char *x) { cerr <<     << x <<    ; } n void __print(const string &x) { cerr <<     << x <<    ; } n void __print(bool x) { cerr << (x ?  true  :  false ); } n template <typename T, typename V> n void __print(const pair<T, V> &x) { n   cerr <<  { ; n   __print(x.first); n   cerr <<  , ; n   __print(x.second); n   cerr <<  } ; n } n template <typename T> n void __print(const T &x) { n   int f = 0; n   cerr <<  { ; n   for (auto &i : x) cerr << (f++ ?  ,  :   ), __print(i); n   cerr <<  } ; n } n void _print() { cerr <<  ] n ; } n template <typename T, typename... V> n void _print(T t, V... v) { n   __print(t); n   if (sizeof...(v)) cerr <<  ,  ; n   _print(v...); n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int t; n   cin >> t; n   while (t--) { n     int n; n     cin >> n; n     vector<pair<int, int> > arr(n); n     for (int i = 0; i < n; i++) cin >> arr[i].first; n     for (int i = 0; i < n; i++) cin >> arr[i].second; n     sort(arr.begin(), arr.end()); n     long long int cost = 1e18; n     long long int prev = 0; n     for (int i = n - 1; i >= 0; i--) { n       cost = min(cost, max((long long int)arr[i].first, prev)); n       prev += arr[i].second; n     } n     cost = min(cost, prev); n     cout << cost << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n map<string, string> a; n map<string, int> b; n string s, g, p; n int main() { n   int n, q; n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> s; n     int l = s.length(); n     for (int j = 0; j < l; j++) { n       for (int k = 1; j + k <= l; k++) { n         string c = s.substr(j, k); n         if (a[c] != s) { n           b[c]++; n           a[c] = s; n         } n       } n     } n   } n   cin >> q; n   for (int h = 0; h < q; h++) { n     cin >> p; n     if (b[p] == 0) { n       cout << b[p] <<     n            <<  -  << endl; n     } else { n       cout << b[p] <<     << a[p] << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, s = 19, i, sum, j, l; n int main() { n   cin >> n; n   for (i = 1; i < n; i++) { n     s += 9; n     l = s; n     while (l) { n       sum += (l % 10); n       l /= 10; n     } n     if (sum != 10) i--; n     sum = 0; n   } n   cout << s; n } n


#include <bits/stdc++.h> n using namespace std; n using pii = pair<int, int>; n using ll = long long; n using llu = long long unsigned; n using ld = long double; n const ld EPS = 1e-9; n inline int cmp(ld first, ld second = 0, ld tol = EPS) { n   return (first <= second + tol) ? (first + tol < second) ? -1 : 0 : 1; n } n const int MOD = 1; n inline int mod(ll first, int m = MOD) { return (int)(((first % m) + m) % m); } n const int N = 2e5 + 10; n int n, m; n ll first[N], chg[N], one[N]; n int main() { n   scanf( %d %d , &n, &m); n   for (int i = 0; i < m; i++) scanf( %lld , &first[i]); n   ll base = 0; n   for (int i = 1; i < m; i += 2) { n     base += abs(first[i] - first[i - 1]); n     if (i < m - 1) base += abs(first[i] - first[i + 1]); n   } n   for (int i = 0; i < m; i++) { n     if (i < m - 1) { n       if (first[i + 1] > first[i]) { n         chg[first[i]]--; n         one[first[i]] += first[i] - 1; n       } n       if (first[i + 1] < first[i]) { n         chg[first[i]]++; n         ll dBef = abs(first[i] - (first[i + 1] + 1)); n         ll dNow = abs(1 - (first[i + 1] + 1)); n         one[first[i]] += (dNow - dBef); n       } n     } n     if (i) { n       if (first[i - 1] > first[i]) { n         chg[first[i]]--; n         one[first[i]] += first[i] - 1; n       } n       if (first[i - 1] < first[i]) { n         chg[first[i]]++; n         ll dBef = abs(first[i] - (first[i - 1] + 1)); n         ll dNow = abs(1 - (first[i - 1] + 1)); n         one[first[i]] += (dNow - dBef); n       } n     } n   } n   for (int i = 1; i <= n; i++) { n     printf( %lld  , base); n     base -= one[i]; n     base += chg[i] + one[i + 1]; n   } n   putchar(  n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXV = 600, MAXE = 70000, inf = 1000000000; n int N, Count; n int G[MAXV], Queue[MAXV], Dist[MAXV], Pre[MAXV], Last[MAXV]; n int Data[MAXE], Weight[MAXE], Cost[MAXE], Next[MAXE]; n bool Flag[MAXV]; n int Calc(int X) { n   if (!X) return 0; n   return Calc(X / 2) + X % 2; n } n void Add(int Number, int V1, int V2, int W, int C) { n   Data[Number] = V2; n   Weight[Number] = W; n   Cost[Number] = C; n   Next[Number] = G[V1]; n   G[V1] = Number; n } n void Connect(int V1, int V2, int W, int C) { n   Add(Count++, V1, V2, W, C); n   Add(Count++, V2, V1, 0, -C); n } n int SPFA(int S, int T) { n   for (int i = 0; i <= T; i++) Dist[i] = inf; n   Dist[S] = 0; n   memset(Flag, 0, sizeof(Flag)); n   Queue[0] = S; n   int F = 0, R = 1; n   while (F != R) { n     int V = Queue[F++]; n     if (F == MAXV) F = 0; n     int P = G[V]; n     Flag[V] = false; n     while (P != -1) { n       int U = Data[P]; n       if (Weight[P] && Dist[V] + Cost[P] < Dist[U]) { n         Dist[U] = Dist[V] + Cost[P]; n         Pre[U] = P; n         if (!Flag[U]) Flag[Queue[R++] = U] = true; n         if (R == MAXV) R = 0; n       } n       P = Next[P]; n     } n   } n   if (Dist[T] == inf) return -1; n   int V = T; n   while (V != S) { n     Weight[Pre[V]]--; n     Weight[Pre[V] ^ 1]++; n     int U = Data[Pre[V] ^ 1]; n     if (U <= N && V > N) Last[V - N - 1] = U; n     V = U; n   } n   return Dist[T]; n } n int main() { n   int M; n   cin >> N >> M; n   int A[250]; n   for (int i = 0; i < N; i++) cin >> A[i]; n   int S = N * 2 + 1, T = N * 2 + 2; n   Count = 0; n   for (int i = 0; i <= T; i++) G[i] = -1; n   for (int i = 0; i < N; i++) Connect(S, i, 1, 0); n   Connect(S, N, M, 0); n   for (int i = 0; i < N; i++) n     for (int j = i + 1; j < N; j++) n       if (A[i] == A[j]) n         Connect(i, N + j + 1, 1, 0); n       else n         Connect(i, N + j + 1, 1, Calc(A[j])); n   for (int i = 0; i < N; i++) Connect(N, N + i + 1, 1, Calc(A[i])); n   for (int i = 1; i <= N; i++) Connect(N + i, T, 1, 0); n   int Ans = 0, Tmp; n   while (Tmp = SPFA(S, T), Tmp != -1) Ans += Tmp; n   int Total = N; n   for (int i = 0; i < N; i++) n     if (Last[i] == N || A[Last[i]] != A[i]) Total++; n   cout << Total <<     << Ans << endl; n   int Number = 0, Var[250]; n   for (int i = 0; i < N; i++) n     if (Last[i] == N) { n       Var[i] = Number++; n       printf( %c=%d nprint(%c) n , Var[i] + 97, A[i], Var[i] + 97); n     } else if (A[i] == A[Last[i]]) { n       Var[i] = Var[Last[i]]; n       printf( print(%c) n , Var[i] + 97); n     } else { n       Var[i] = Var[Last[i]]; n       printf( %c=%d nprint(%c) n , Var[i] + 97, A[i], Var[i] + 97); n     } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   if (n == 0) { n     cout <<  O-|-OOOO  << endl; n     return 0; n   } n   while (n != 0) { n     int k = n % 10; n     if (k >= 5) { n       cout <<  -O| ; n       k -= 5; n     } else n       cout <<  O-| ; n     int i = 0; n     for (; i < k; i++) cout <<  O ; n     cout <<  - ; n     i++; n     for (; i < 5; i++) cout <<  O ; n     cout << endl; n     n /= 10; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = 1e9 + 7; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(); n   int n; n   cin >> n; n   int x; n   cin >> x; n   int a[n]; n   int pp[100005] = {0}; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n     pp[a[i]]++; n   } n   long long c = 0; n   for (int i = 0; i < n; i++) { n     if (((a[i] ^ x) < 100005) && pp[a[i] ^ x]) { n       c += pp[a[i] ^ x]; n     } n   } n   if (x == 0) n     cout << (c - n) / 2 <<   n ; n   else n     cout << c / 2 <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int t; n   cin >> t; n   int a[t + 10]; n   for (int i = 0; i < t; i++) { n     long int b, p, f, c, h, c1 = 0, c2 = 0; n     cin >> b >> p >> f; n     cin >> h >> c; n     b = b / 2; n     if (b == 0) { n       cout << 0 << endl; n       continue; n     } n     if (h > c) { n       if (b >= p) { n         c1 += (p * h); n         b -= p; n         if (f >= b) { n           c1 += b * c; n         } else { n           c1 += f * c; n         } n       } else { n         c1 += b * h; n       } n     } else { n       if (b >= f) { n         b -= f; n         c1 += c * f; n         if (b > p) { n           c1 += p * h; n         } else { n           c1 += b * h; n         } n       } else { n         c1 += b * c; n       } n     } n     cout << c1 << endl; n     c1 = 0; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int b[600][600], n, m, q, row[600]; n int main() { n   ios::sync_with_stdio(false); n   scanf( %d%d%d , &n, &m, &q); n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= m; j++) { n       int x; n       scanf( %d , &x); n       b[i][j] = x; n     } n   int ans = 0; n   for (int i = 1; i <= n; i++) { n     int len = 0; n     int maxlen = 0; n     for (int j = 1; j <= m; j++) { n       if (b[i][j]) n         len++; n       else n         len = 0; n       maxlen = max(len, maxlen); n     } n     row[i] = maxlen; n   } n   while (q--) { n     int i, j; n     scanf( %d%d , &i, &j); n     b[i][j] ^= 1; n     int len = 0; n     int maxlen = 0; n     for (j = 1; j <= m; j++) { n       if (b[i][j]) n         len++; n       else n         len = 0; n       maxlen = max(len, maxlen); n     } n     row[i] = maxlen; n     int ans = 0; n     for (int ii = 1; ii <= n; ii++) { n       ans = max(ans, row[ii]); n     } n     printf( %d n , ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 100500; n int a[maxn]; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int n; n   long long k; n   cin >> n >> k; n   long long sm = 0; n   priority_queue<pair<int, int> > pq; n   for (int i = 0; i < n; ++i) { n     cin >> a[i]; n     sm += a[i]; n     pq.push({-a[i], i}); n   } n   if (sm < k) return cout << -1 <<   n , 0; n   if (sm == k) return 0; n   long long it = 0, lft = n; n   while (true) { n     assert(!pq.empty()); n     auto u = pq.top(); n     u.first += it; n     lft = (int)pq.size(); n     if (lft * -1LL * u.first > k) break; n     pq.pop(); n     while (pq.top().first + it == u.first) pq.pop(); n     k -= lft * -1LL * u.first; n     it += u.first * -1LL; n   } n   for (int i = 0; i < n; ++i) a[i] = 0; n   it += k / lft; n   k %= lft; n   while (!pq.empty()) { n     a[pq.top().second] = (pq.top().first + it) * -1LL; n     pq.pop(); n   } n   queue<int> q; n   for (int i = 0; i < n; ++i) n     if (a[i]) q.push(i); n   while (k--) { n     auto u = q.front(); n     q.pop(); n     a[u]--; n     if (a[u]) q.push(u); n   } n   while (!q.empty()) { n     cout << q.front() + 1 <<    ; n     q.pop(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n double tt, anstt; n long long ansp, answ, tod[2000000], x1, x2, t1, t2, t0, ps; n int main() { n   cin >> t1 >> t2 >> x1 >> x2 >> t0; n   if (t1 == t2 && t1 == t0) n     cout << x1 <<     << x2 << endl; n   else { n     tod[0] = x2; n     ps = 0; n     for (int i = 1; i <= x1; i++) { n       long fl = 0; n       while ((i * t1 + ps * t2) < (i + ps) * t0) { n         ++ps; n         fl = 1; n         if (ps > x2) break; n       } n       tod[i] = ps; n     } n     anstt = 10000000; n     for (int i = 0; i <= x1; i++) { n       if (tod[i] <= x2) { n         tt = i * t1 + tod[i] * t2; n         tt = tt * 1.0 / (i + tod[i]); n         anstt = min(anstt, tt); n       } n     } n     anstt += 1e-8; n     answ = -1; n     for (int i = 0; i <= x1; i++) { n       if (tod[i] <= x2) { n         tt = i * t1 + tod[i] * t2; n         tt = tt * 1.0 / (i + tod[i]); n         if (tt < anstt) { n           if (answ < i + tod[i]) { n             answ = i + tod[i]; n             ansp = i; n           } n         } n       } n     } n     cout << ansp <<     << tod[ansp] << endl; n   } n   cin.get(); n   cin.get(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } n long long lcm(long long a, long long b) { return a * (b / gcd(a, b)); } n long long power(long long x, long long y, long long p) { n   long long res = 1; n   x = x % p; n   while (y > 0) { n     if (y & 1) res = ((res % p) * (x % p)) % p; n     y = y >> 1; n     x = ((x % p) * (x % p)) % p; n   } n   return res % p; n } n long long raichu(long long x, long long y) { n   long long res = 1; n   while (y > 0) { n     if (y & 1) res = ((res) * (x)); n     y = y >> 1; n     x = ((x) * (x)); n   } n   return res; n } n bool isprime(long long n) { n   if (n < 2) n     return false; n   else if (n == 2) n     return true; n   else if (n % 2 == 0) n     return false; n   else { n     long long z = sqrt(n); n     for (int i = 0; i < z - 1; i++) n       if (n % (i + 2) == 0) return false; n     return true; n   } n } n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int tests = 1, Tests; n   Tests = tests; n   while (tests--) { n     int n, l, r, x; n     cin >> n >> l >> r >> x; n     vector<int> c(n); n     for (int i = 0; i < n; i++) cin >> c[i]; n     vector<int> tmp; n     sort(c.begin(), c.end()); n     int ans = 0; n     for (int i = 0; i < (1 << n); i++) { n       tmp.clear(); n       int sum = 0; n       for (int j = 0; j < n; j++) { n         if ((i >> j) & 1) { n           tmp.push_back(c[j]); n           sum += c[j]; n         } n       } n       if ((int)tmp.size() >= 2 && sum >= l && sum <= r && n           tmp[(int)tmp.size() - 1] - tmp[0] >= x) { n         ans++; n       } n     } n     cout << ans; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct node { n   int a, b; n   node(int a = 0, int b = (int)1e9) : a(a), b(b) {} n   int get(int x) { return a * x + b; } n }; n struct Zwei { n   vector<node> st; n   vector<int> a; n   int n; n   void add(int pos) { a.push_back(pos); } n   void update() { n     sort(a.begin(), a.end()); n     a.resize(unique(a.begin(), a.end()) - a.begin()); n     n = (int)a.size(); n     st.resize(n << 2 | 1); n   } n   void modify(int id, int l, int r, node val) { n     int mid = l + r >> 1; n     if (st[id].get(a[mid]) > val.get(a[mid])) swap(st[id], val); n     if (l == r) return; n     if (st[id].get(a[l]) > val.get(a[l])) modify(id << 1, l, mid, val); n     if (st[id].get(a[r]) > val.get(a[r])) modify(id << 1 | 1, mid + 1, r, val); n   } n   int get(int id, int l, int r, int v) { n     int ans = st[id].get(v); n     if (l == r) assert(a[l] == v); n     if (l == r) return ans; n     int mid = l + r >> 1; n     if (v <= a[mid]) return min(ans, get(id << 1, l, mid, v)); n     return min(ans, get(id << 1 | 1, mid + 1, r, v)); n   } n   int get(int v) { n     if (!n) return (int)1e9; n     return get(1, 0, n - 1, v); n   } n   void modify(node val) { n     if (!n) return; n     modify(1, 0, n - 1, val); n   } n }; n struct Eins { n   vector<Zwei> st; n   int n; n   Eins(int n) : n(n) { st.resize(n << 2 | 1); } n   void build(int id, int l, int r) { n     st[id].update(); n     if (l == r) return; n     int mid = l + r >> 1; n     build(id << 1, l, mid); n     build(id << 1 | 1, mid + 1, r); n   } n   void add(int id, int l, int r, int L, int R, int v) { n     if (L <= l && r <= R) { n       st[id].add(v); n       return; n     } n     int mid = l + r >> 1; n     if (L <= mid) add(id << 1, l, mid, L, R, v); n     if (R > mid) add(id << 1 | 1, mid + 1, r, L, R, v); n   } n   void modify(int id, int l, int r, int pos, node val) { n     st[id].modify(val); n     if (l == r) return; n     int mid = l + r >> 1; n     if (pos <= mid) n       modify(id << 1, l, mid, pos, val); n     else n       modify(id << 1 | 1, mid + 1, r, pos, val); n   } n   int get(int id, int l, int r, int L, int R, int v) { n     if (L <= l && r <= R) return st[id].get(v); n     int mid = l + r >> 1; n     int ans = (int)1e9 + 1; n     if (L <= mid) ans = min(ans, get(id << 1, l, mid, L, R, v)); n     if (R > mid) ans = min(ans, get(id << 1 | 1, mid + 1, r, L, R, v)); n     return ans; n   } n }; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   int n; n   cin >> n; n   vector<int> a(n + 1); n   vector<int> t(n + 1); n   for (int i = 1; i <= n; i++) { n     cin >> a[i]; n     t[i] = t[i - 1] + a[i]; n   } n   int q; n   cin >> q; n   vector<pair<int, int>> Query; n   Eins Tree(n); n   while (q--) { n     int x, y; n     cin >> x >> y; n     Query.emplace_back(x, y); n     Tree.add(1, 1, n, y - x + 1, y, y - x); n   } n   Tree.build(1, 1, n); n   for (int i = 1; i <= n; i++) n     Tree.modify(1, 1, n, i, node(-a[i], a[i] * i - t[i])); n   for (auto& x : Query) { n     cout << Tree.get(1, 1, n, x.second - x.first + 1, x.second, n                      x.second - x.first) + n                 t[x.second] n          <<   n ; n   } n } n


#include<bits/stdc++.h> n #define int long long n using namespace std; n const int N=1e5+5; n #define pb push_back n int n,m,t; n int i,j,k; n int a[N]; n int b[N],c[N]; n vector<int> ans; n vector<int>v[N]; n int vis[N]; n   n signed main() n { n     int t; n     cin>>t; n     while(t--){ n      int n; n   cin>>n; n   int m=(n-1); n   int f=sqrt(2*m+1); n  // cout<<f<<endl; n   if(f<3) cout<<0<<endl; n   else cout<<(f-1)/2<<endl; n  } n     return 0; n }


#include <bits/stdc++.h> n const int MAXA = 5005; n const int MAXN = 2016; n int array[MAXN]{}; n long long diffr[MAXA]{}; n long long suffx[MAXA]{}; n long double total; n long long Ans = 0; n int N; n int main() { n   scanf( %d , &N); n   for (int i = 0; i < N; ++i) scanf( %d , &array[i]); n   total = N * (N - 1) >> 1; n   std::sort(array, array + N); n   for (int i = 0; i < N; ++i) n     for (int j = i + 1; j < N; ++j) ++diffr[array[j] - array[i]]; n   for (int i = 5000; i >= 0; --i) suffx[i] = suffx[i + 1] + diffr[i]; n   for (int i = 1; i <= 5000; ++i) n     for (int j = 1; i + j <= 5000; ++j) n       Ans += diffr[i] * diffr[j] * suffx[i + j + 1]; n   std::cout << std::setprecision(9) << Ans / total / total / total <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   const long long MOD = 1000000009; n   int n, m; n   cin >> n >> m; n   long long ret = 1; n   long long x = 1; n   for (int i = 0; i < (int)(m); i++) x = x * 2 % MOD; n   x = (x - 1 + MOD) % MOD; n   for (int i = 0; i < (int)(n); i++) { n     ret = ret * x % MOD; n     if (--x < 0) x = 0; n   } n   cout << ret << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n using pii = pair<long long, long long>; n const long long INF = 2e18; n template <class A, class B> n ostream &operator<<(ostream &os, const pair<A, B> &p) { n   os <<  (  << p.first <<  ,   << p.second <<  ) ; n   return os; n } n template <class A> n ostream &operator<<(ostream &os, const vector<A> &v) { n   os <<  { ; n   for (long long i = 0; i < (long long)v.size(); i++) n     if (i == 0) n       os << v[i]; n     else n       os <<  ,   << v[i]; n   os <<  } ; n   return os; n } n void dprint(string s) { cout <<   n ; } n template <class T, class... U> n void dprint(string s, T t, U... u) { n   long long w = s.find( , ); n   cout <<  [  << s.substr(0, w) <<  :   << t <<  ]  ; n   dprint(s.substr(w + 2, (long long)s.size() - w - 1), u...); n } n const long long N = 1e6 + 5; n int32_t main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   string s; n   cin >> s; n   vector<pair<char, long long>> v; n   for (long long i = 0; i < (long long)(s).size();) { n     char c = s[i]; n     long long cnt = 0; n     while (s[i] == c and i < (long long)(s).size()) cnt++, i++; n     v.push_back({c, cnt}); n   } n   if ((long long)(v).size() % 2) { n     bool ok = 1; n     for (long long i = 0; i < (long long)(v).size() / 2; i++) { n       if (v[i].first == v[(long long)(v).size() - 1 - i].first and n           v[i].second + v[(long long)(v).size() - 1 - i].second >= 3) n         ; n       else n         ok = 0; n     } n     if (v[(long long)(v).size() / 2].second == 1) ok = 0; n     if (ok) n       cout << v[(long long)(v).size() / 2].second + 1; n     else n       cout << 0; n   } else { n     cout << 0; n   } n   return 0; n } n


#include <bits/stdc++.h> n std::mt19937 rng( n     (int)std::chrono::steady_clock::now().time_since_epoch().count()); n using namespace std; n long long mod = (998244353LL); n inline long long Mod(long long a, long long b) { return (a % b); } n inline long long poww(long long a, long long b) { n   long long res = 1; n   while (b > 0) { n     if (b & 1) res = (res * a) % mod; n     a = (a * a) % mod; n     b >>= 1; n   } n   return res; n } n long long gcd(long long a, long long b) { n   while (b) { n     a %= b, swap(a, b); n   } n   return a; n } n void read(vector<int> &w, int n) { n   w.resize(n); n   for (int i = 0; i < n; i++) cin >> w[i]; n } n void print(vector<int> &w) { n   for (int i = 0; i < (int)(w).size(); i++) { n     if (i == (int)(w).size() - 1) n       cout << w[i] <<   n ; n     else n       cout << w[i] <<    ; n   } n } n int prodmod(vector<int> w); n int summod(vector<int> w); n int n, m, q, k, v[200010]; n string second; n pair<int, int> w[200010]; n vector<pair<int, int>> grafo[200010]; n long long dist[200010][20][2]; n void solve() { n   priority_queue<vector<long long>, vector<vector<long long>>, n                  greater<vector<long long>>> n       pq; n   pq.push({0, 1, 0, 0}); n   dist[1][0][0] = 0; n   while (!pq.empty()) { n     auto curr = pq.top(); n     pq.pop(); n     long long d = curr[0], x = curr[1], q = curr[2], flag = curr[3]; n     if (d > dist[x][q][flag]) continue; n     for (auto v : grafo[x]) { n       int T = (v.second != flag); n       int qq = q + T, flag2 = v.second; n       if (qq < 20 and n           dist[v.first][qq][flag2] > n               dist[x][q][flag] + 1 + (1LL * T) * (1LL << (1LL * q))) { n         dist[v.first][qq][flag2] = n             dist[x][q][flag] + 1 + (1LL * T) * (1LL << (1LL * q)); n         pq.push({dist[v.first][qq][flag2], v.first, qq, flag2}); n       } n     } n   } n } n pair<int, int> dist2[200010][2]; n const int inf = 0x3f3f3f3f; n int32_t main() { n   memset(dist, inf, sizeof dist); n   ios::sync_with_stdio(false); n   cin.tie(0); n   cin >> n >> m; n   for (int i = 1, a, b; i <= m; i++) { n     cin >> a >> b; n     grafo[a].push_back({b, 0}); n     grafo[b].push_back({a, 1}); n   } n   solve(); n   long long ans = inf; n   for (int i = 0; i < 20; i++) ans = min({ans, dist[n][i][0], dist[n][i][1]}); n   if (ans != inf) n     cout << ans % mod <<   n , exit(0); n   else { n     for (int i = 0; i < 200010; i++) dist2[i][0] = dist2[i][1] = {inf, inf}; n     priority_queue<vector<int>, vector<vector<int>>, greater<vector<int>>> pq; n     pq.push({0, 0, 1, 0}); n     dist2[1][0] = {0, 0}; n     while (!pq.empty()) { n       auto curr = pq.top(); n       pq.pop(); n       int inv = curr[0], d = curr[1], x = curr[2], flag = curr[3]; n       if (pair<int, int>(inv, d) > dist2[x][flag]) continue; n       for (auto v : grafo[x]) { n         pair<int, int> novo = {inv + (v.second != flag), d + 1}; n         if (novo < dist2[v.first][v.second]) { n           dist2[v.first][v.second] = novo; n           pq.push({inv + (v.second != flag), d + 1, v.first, v.second}); n         } n       } n     } n     pair<int, int> curr = min(dist2[n][0], dist2[n][1]); n     int ans = curr.second, pot = 1LL; n     for (int i = 0; i < curr.first; i++) { n       ans += pot; n       ans %= mod; n       pot *= 2LL; n       pot %= mod; n     } n     cout << ans % mod <<   n ; n   } n } n int summod(vector<int> w) { n   int curr = 0; n   for (int i = 0; i < (int)(w).size(); i++) { n     curr = (curr + w[i]) % mod; n     if (curr < 0) curr += mod; n   } n   return curr; n } n int prodmod(vector<int> w) { n   int curr = 1; n   for (int i = 0; i < (int)(w).size(); i++) { n     if (w[i] >= mod) w[i] %= mod; n     curr = (curr * w[i]) % mod; n     if (curr < 0) curr += mod; n   } n   return curr; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e5 + 5; n vector<int> v[maxn]; n int vos[maxn]; n int ans; n void dfs(int now, int pre) { n   if (vos[now]) { n     ans = 0; n     return; n   } n   vos[now] = 1; n   for (int i = 0; i < v[now].size(); i++) { n     if (v[now][i] != pre) { n       dfs(v[now][i], now); n     } n   } n } n int main() { n   int n, m; n   scanf( %d%d , &n, &m); n   int a, b; n   for (int i = 0; i < m; i++) { n     scanf( %d%d , &a, &b); n     v[a].push_back(b); n     v[b].push_back(a); n   } n   memset(vos, 0, sizeof(vos)); n   int sum = 0; n   for (int i = 1; i <= n; i++) { n     if (vos[i]) continue; n     ans = 1; n     dfs(i, 0); n     sum += ans; n   } n   printf( %d n , sum); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long MOD = 1000000007LL; n int n, k; n string s; n long long A[30]; n long long ans, aux; n int last[30]; n int main() { n   cin >> n >> k >> s; n   memset(last, -1, sizeof(last)); n   int m = s.length(); n   ans = 1LL; n   for (int i = 0; i < m; i++) { n     aux = ans; n     ans = (2 * ans + MOD - A[s[i] -  a ]) % MOD; n     A[s[i] -  a ] = aux; n     last[s[i] -  a ] = i; n   } n   for (int j = 0; j < n; j++) { n     int mini = (1 << 30); n     int let; n     for (int i = 0; i < k; i++) { n       if (last[i] < mini) { n         mini = last[i]; n         let = i; n       } n     } n     aux = ans; n     ans = (2 * ans + MOD - A[let]) % MOD; n     A[let] = aux; n     last[let] = m + j; n   } n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n char x[1500001]; n int k, i, starti, fini; n bool start, finish, found[500001]; n int main() { n   while (cin.getline(x, 1500001)) { n     k++; n     found[k] = false; n     int a = strlen(x); n     for (i = 0; i < a; i++) { n       if (x[i] !=     && x[i] !=  #  && !found[k]) break; n       if (x[i] ==  # ) { n         found[k] = true; n         break; n       } n     } n     if (found[k]) { n       if (!found[k - 1] && k != 1) cout <<   n ; n       cout << x <<   n ; n     } else { n       int p = strlen(x); n       for (i = 0; i < p; i++) { n         if (x[i] ==    ) { n           continue; n         } else n           cout << x[i]; n       } n     } n   } n   if (!found[k]) cout <<   n ; n } n


#include <bits/stdc++.h> n const int inf = 0xfffffff; n const long long INF = 1ll << 61; n using namespace std; n int num[1000000 + 5]; n int b[1000000 + 5]; n int c[1000000 + 5]; n int n; n int ans; n void init() { n   memset(num, 0, sizeof(num)); n   memset(b, 0, sizeof(b)); n   memset(c, 0, sizeof(c)); n   ans = 0; n } n bool input() { n   while (scanf( %d , &n) == 1) { n     return false; n   } n   return true; n } n void cal() { n   n++; n   for (int i = 2; i <= n; i++) { n     scanf( %d , &num[i]); n     b[i] = 1; n     c[i] = 0; n     int j = i; n     if (ans < b[j]) ans = b[j]; n     while (num[j] != 1) { n       if (ans < b[j]) ans = b[j]; n       if (ans < b[num[j]]) ans = b[num[j]]; n       if (b[num[j]] < b[j]) { n         b[num[j]] = b[j]; n         c[num[j]] = 1; n       } else if (c[num[j]] == 1 && b[num[j]] == b[j]) { n         b[num[j]] = b[j] + 1; n         c[num[j]] = 0; n       } else if (c[num[j]] == 0 && b[num[j]] == b[j]) { n         c[num[j]] = 1; n         break; n       } else n         break; n       if (ans < b[num[j]]) ans = b[num[j]]; n       j = num[j]; n     } n     printf( %d%c , ans, i == 1 ?   n  :    ); n   } n } n void output() {} n int main() { n   while (true) { n     init(); n     if (input()) return 0; n     cal(); n     output(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const double PI = acos(-1); n const int N = 100000 + 5; n long long q; n long long tree[4000005], lazy[4000005]; n long long ti[1000005], di[1000005]; n void lazify(long long s, long long e, long long i) { n   if (lazy[i]) { n     tree[i] += lazy[i]; n     if (s != e) { n       lazy[2 * i] += lazy[i]; n       lazy[2 * i + 1] += lazy[i]; n     } n     lazy[i] = 0; n   } n } n void upd(long long l, long long r, long long s, long long e, long long i, n          long long x) { n   lazify(s, e, i); n   if (s > r || e < l) return; n   if (s >= l && e <= r) { n     lazy[i] += x; n     lazify(s, e, i); n     return; n   } n   long long mid = (s + e) >> 1; n   upd(l, r, s, mid, 2 * i, x); n   upd(l, r, mid + 1, e, 2 * i + 1, x); n   tree[i] = min(tree[2 * i], tree[2 * i + 1]); n } n long long pquery(long long l, long long r, long long s, long long e, n                  long long i) { n   if (s > r || e < l) return 1e18; n   lazify(s, e, i); n   if (s >= l && e <= r) return tree[i]; n   long long mid = (s + e) >> 1; n   return min(pquery(l, r, s, mid, 2 * i), pquery(l, r, mid + 1, e, 2 * i + 1)); n } n void build(long long l, long long r, long long i) { n   if (l == r) { n     tree[i] = -l; n     return; n   } n   long long mid = (l + r) >> 1; n   build(l, mid, 2 * i); n   build(mid + 1, r, 2 * i + 1); n   tree[i] = min(tree[2 * i], tree[2 * i + 1]); n } n long long get(long long t) { n   long long x = pquery(t, t, 1, 1000000, 1); n   long long y = pquery(1, t - 1, 1, 1000000, 1); n   y = min(y, 0ll); n   return x - y + 1; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   build(1, 1000000, 1); n   cin >> q; n   for (int i = 1; i <= q; i++) { n     char c; n     long long in; n     cin >> c; n     if (c ==  + ) { n       cin >> ti[i] >> di[i]; n       upd(ti[i], 1000000, 1, 1000000, 1, di[i]); n     } else if (c ==  - ) { n       cin >> in; n       upd(ti[in], 1000000, 1, 1000000, 1, -di[in]); n     } else if (c ==  ? ) { n       cin >> in; n       cout << get(in) << endl; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n bitset<4096> f[100020]; n int a[13][100005], b[100005][13], now; n bool cmp(int x, int y) { n   return a[x][now] == a[y][now] ? x > y : a[x][now] > a[y][now]; n } n int main() { n   int n, q, k, cnt, op, x, y; n   scanf( %d%d%d , &n, &k, &q); n   cnt = k; n   for (int i = 1; i <= k; i++) n     for (int j = 1; j <= n; j++) scanf( %d , &a[i][j]), b[j][i] = i; n   for (int i = 1; i <= n; i++) now = i, sort(b[i] + 1, b[i] + k + 1, cmp); n   for (int i = 1; i <= k; i++) n     for (int j = 0; j < (1 << k); j++) n       if (j & (1 << (i - 1))) f[i][j] = 1; n   while (q--) { n     scanf( %d%d%d , &op, &x, &y); n     if (op == 1) n       cnt++, f[cnt] = f[x] | f[y]; n     else if (op == 2) n       cnt++, f[cnt] = f[x] & f[y]; n     else n       for (int i = 1, t = 0; i <= k; i++) { n         t |= (1 << (b[y][i] - 1)); n         if (f[x][t]) { n           printf( %d n , a[b[y][i]][y]); n           break; n         } n       } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1E6 + 5, INF = 1E9 + 7; n int m, n, ans = INF; n mt19937 mt(133769420); n int ask(int u, int v) { n   cout <<  ?   << u <<     << v << endl; n   int ret; n   cin >> ret; n   return ret; n } n int rand(int l, int r) { n   uniform_int_distribution<int> uni(l, r); n   return uni(mt); n } n void solve(int u, int d, int l, int r) { n   if (u > d) { n     return; n   } n   int m = rand(u, d); n   pair<int, int> mi = {INF, 0}; n   for (int i = l; i <= r; i++) { n     mi = min(mi, {ask(m, i), i}); n   } n   ans = min(ans, mi.first); n   solve(u, m - 1, l, mi.second); n   solve(m + 1, d, mi.second, r); n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n   cin >> m >> n; n   solve(1, m, 1, n); n   cout <<  !   << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(0); n   long long t, n, x; n   cin >> t; n   for (int i = 0; i < t; i++) { n     cin >> n >> x; n     cout << x * 2 << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n inline int read() { n   int x = 0, f = 1; n   char c = getchar(); n   while (c <  0  || c >  9 ) { n     if (c ==  - ) f = -1; n     c = getchar(); n   } n   while (c >=  0  && c <=  9 ) { n     x = (x << 3) + (x << 1) + c -  0 ; n     c = getchar(); n   } n   return x * f; n } n int w, h, n, l, r; n char opt[3]; n set<int> a, b; n multiset<int> f, g; n int main() { n   w = read(), h = read(), n = read(); n   a.insert(0), b.insert(0); n   a.insert(w), b.insert(h); n   f.insert(w), g.insert(h); n   for (int i = 1; i <= n; i++) { n     scanf( %s , opt + 1); n     int x = read(); n     if (opt[1] ==  V ) { n       r = (*a.lower_bound(x)); n       l = (*(--a.lower_bound(x))); n       f.erase(f.find(r - l)); n       f.insert(r - x), f.insert(x - l); n       a.insert(x); n     } else { n       r = (*b.lower_bound(x)); n       l = (*(--b.lower_bound(x))); n       g.erase(g.find(r - l)); n       g.insert(r - x), g.insert(x - l); n       b.insert(x); n     } n     printf( %I64d n , 1LL * (*(--f.end())) * (*(--g.end()))); n   } n   return 0; n } n