#include <bits/stdc++.h> n std::string input() { n   static char buf[1000]; n   scanf( %s , buf); n   return std::string(buf); n } n int main() { n   int inv[5] = {0, 1, 3, 2, 4}; n   int n, m; n   std::cin >> n >> m; n   static int a[500][1000]; n   for (int i = 0; i < m; i++) { n     a[i][i + n] = 1; n   } n   for (int i = 0; i < n; i++) { n     std::string s = input(); n     for (int j = 0; j < m; j++) { n       a[j][i] = s[j] -  a ; n     } n   } n   const int h = m; n   const int w = n + m; n   int r = 0; n   for (int j = 0; j < n && r < h; j++) { n     int p = r; n     for (int i = r; i < h; i++) { n       if (a[i][j] != 0) { n         p = i; n         break; n       } n     } n     std::swap(a[p], a[r]); n     if (a[r][j] == 0) continue; n     for (int jj = j + 1; jj < w; jj++) { n       a[r][jj] = a[r][jj] * inv[a[r][j]] % 5; n     } n     a[r][j] = 1; n     for (int ii = 0; ii < h; ii++) { n       if (ii != r) { n         for (int jj = j + 1; jj < w; jj++) { n           a[ii][jj] += 2500 - a[ii][j] * a[r][jj]; n           a[ii][jj] %= 5; n         } n         a[ii][j] = 0; n       } n     } n     r++; n   } n   int q; n   std::cin >> q; n   while (q--) { n     std::string b = input(); n     std::vector<int> v(m); n     for (int i = 0; i < m; i++) { n       v[i] = b[i] -  a ; n     } n     std::vector<int> u(m); n     for (int i = 0; i < m; i++) { n       for (int j = 0; j < m; j++) { n         u[i] += a[i][n + j] * v[j]; n       } n       u[i] %= 5; n     } n     bool any = false; n     for (int i = r; i < m; i++) { n       if (u[i] != 0) { n         any = true; n       } n     } n     constexpr long long MOD2 = 1e9 + 7; n     long long ans = 1; n     for (int i = r; i < n; i++) { n       ans *= 5; n       ans %= MOD2; n     } n     if (any) { n       puts( 0 ); n       continue; n     } n     printf( %d n , (int)ans); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = 1000000000; n const int mod = 1000000007; n const int sze = 100005; n int main() { n   long long n; n   char ch; n   scanf( %I64d%c , &n, &ch); n   bool flag = true; n   long long term; n   if (((n + 3) % 4) == 0) { n     term = (n + 3) / 4; n   } else if (((n + 2) % 4) == 0) { n     term = (n + 2) / 4; n     flag = false; n   } else if (((n + 1) % 4) == 0) { n     term = (n + 1) / 4; n   } else if (((n) % 4) == 0) { n     term = (n) / 4; n     flag = false; n   } n   long long ans; n   ans = (term - 1) * 16; n   if (flag == false) { n     ans = ans + 7; n   } n   if (ch ==  f ) { n     ans = ans + 1; n   } else if (ch ==  e ) { n     ans = ans + 2; n   } else if (ch ==  d ) { n     ans = ans + 3; n   } else if (ch ==  a ) { n     ans = ans + 4; n   } else if (ch ==  b ) { n     ans = ans + 5; n   } else { n     ans = ans + 6; n   } n   printf( %I64d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using ll = long long int; n using namespace std; n int main() { n   ll t; n   cin >> t; n   while (t--) { n     ll p, q; n     cin >> p >> q; n     if (p % q != 0) n       cout << p <<   n ; n     else { n       ll x = 1; n       for (ll i = 1; i <= sqrt(q); i++) { n         if (q % i == 0) { n           ll pnew = p; n           while (i != 1 && pnew % i == 0) { n             pnew = pnew / i; n             if (pnew % q != 0) { n               x = max(x, pnew); n               break; n             } n           } n           pnew = p; n           while (pnew % (q / i) == 0) { n             pnew = pnew / (q / i); n             if (pnew % q != 0) { n               x = max(x, pnew); n               break; n             } n           } n         } n       } n       cout << x <<   n ; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n char a[105][105]; n int main() { n   int n, m; n   cin >> n >> m; n   for (int i = 1; i <= m; i++) { n     for (int j = 1; j <= n; j++) { n       cin >> a[i][j]; n     } n   } n   for (int i = 1; i <= n; i++) { n     for (int k = 1; k <= 2; k++) { n       for (int j = 1; j <= m; j++) { n         cout << a[j][i] << a[j][i]; n       } n       cout << endl; n     } n   } n   return 0; n } n


// Problem: A. Puzzle From the Future n // Contest: Codeforces - Codeforces Round #696 (Div. 2) n // URL: https://codeforces.ml/contest/1474/problem/A n // Memory Limit: 256 MB n // Time Limit: 1000 ms n //  n // Powered by CP Editor (https://cpeditor.org) n  n #define _CRT_SECURE_NO_WARNINGS n #include <bits/stdc++.h> n using namespace std; n typedef long long ll; n #define forn(i,x,n) for(int i = x;i <= n;++i)  n  n const int N = 1e5+7; n char s[N],ans[N]; n  n int main() n { n     int T;scanf( %d ,&T); n     while(T--) n     { n   int n;scanf( %d ,&n); n   scanf( %s ,s + 1); n   int last = -1; n   forn(i,1,n) n   { n    int c = s[i] -  0 ; n    if(c + 1 == last) ans[i] =  0 ,last = c; n    else ans[i] =  1 ,last = c + 1; n   } n   forn(i,1,n) printf( %c ,ans[i]); n   puts(  ); n     } n     return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename U, typename V> n void Min(U &a, const V &b) { n   if (a > b) a = b; n } n template <typename U, typename V> n void Max(U &a, const V &b) { n   if (a < b) a = b; n } n template <typename U, typename V> n void add(U &a, const V &b) { n   a = (a + b) % 1000000007; n } n template <typename U> n U gcd(U a, U b) { n   if (a == 0) return b; n   if (b == 0) return a; n   if (a >= b) n     return gcd(a % b, b); n   else n     return gcd(a, b % a); n } n int pow(int a, int b) { n   int ans = 1; n   while (b) { n     if (b & 1) ans = 1LL * ans * a % 1000000007; n     a = 1LL * a * a % 1000000007; n     b >>= 1; n   } n   return ans; n } n struct node { n   int k, d, t, K; n   bool operator<(const node &a) const { return t < a.t; } n }; n vector<node> a[505][505]; n int dx[] = {1, 0}, dy[] = {0, 1}; n long long dp[2][505][2][505]; n const long long INF = 1e18; n int main() { n   int T, m, n, i, j, k, K; n   scanf( %d%d%d , &n, &m, &T); n   int t, d; n   while (T--) { n     scanf( %d%d%d%d%d , &i, &j, &d, &t, &K); n     a[i][j].push_back({0, d, t, K}); n     a[i + d][j - d].push_back({1, d, t + 1, K}); n     a[i + d][j].push_back({2, d, t + 2, K}); n     a[i][j + d].push_back({3, d, t + 3, K}); n   } n   int now = 0; n   for (int k = 0; k < m + 1; k++) n     for (int i = 0; i < max(n, m) + 1; i++) n       for (int j = 0; j < 2; j++) dp[now][k][j][i] = INF; n   dp[0][0][0][0] = 0; n   dp[0][0][1][0] = 0; n   for (int len = 0; len < n + m - 1; len++) { n     for (int j = 0; j < m; j++) n       for (int k = 0; k < 2; k++) n         for (int l = 0; l < max(n, m) + 1; l++) dp[1 - now][j][k][l] = INF; n     for (int j = 0; j < m; j++) { n       i = len - j; n       if (i < 0) break; n       if (i >= n) continue; n       sort(a[i][j].begin(), a[i][j].end()); n       t = i + j; n       for (int k = 0; k < 2; k++) { n         for (int l = 0; l < ((k == 0) ? i + 1 : j + 1); l++) n           if (dp[now][j][k][l] < INF) { n             long long &w = dp[now][j][k][l]; n             for (auto &o : a[i][j]) { n               if (o.t > t) break; n               if ((t - o.t) % 4) { n                 continue; n               } n               if (o.k < 2 || o.d > l) { n                 w += o.K; n                 continue; n               } n               int ok = 0; n               if (o.k == 2) { n                 int tt = t - o.d - o.t + 2 - k; n                 if (tt >= 0 && tt % 4 == 0) { n                   ok = 1; n                 } n               } else if (o.k == 3 && k == 1) { n                 int tt = t - o.d - o.t + 3; n                 if (tt >= 0 && tt % 4 == 0) { n                   ok = 1; n                 } n               } n               if (!ok) w += o.K; n             } n             for (int r = 0; r < 2; r++) { n               int first = i + dx[r], second = j + dy[r]; n               if (first < 0 || first >= n || second < 0 || second >= m) n                 continue; n               int nd = r == k ? l + 1 : 1; n               Min(dp[1 - now][second][r][nd], w); n             } n           } n       } n     } n     now = 1 - now; n   } n   long long ans = INF; n   for (int i = 0; i < 2; i++) n     for (int j = 0; j < max(n, m) + 1; j++) Min(ans, dp[1 - now][m - 1][i][j]); n   printf( %lld n , ans); n } n


#include <bits/stdc++.h> n using namespace std; n const int Q = 100100, rt = 223, inf = 1 << 29; n int ans[Q], todo[Q]; n pair<int, int> look[Q]; n int a[Q], b[Q]; n string s; n unordered_map<int, unordered_set<int>> post; n map<pair<int, int>, int> ans2; n unordered_map<int, vector<int>> matches; n int f(int x, int xs, int y, int ys) { return max(x + xs, y + ys) - min(x, y); } n int S[100000][5]; n map<string, int> intern; n int interned_size[500000]; n int cnt = 1; n int get(const string& s) { n   auto it = intern.find(s); n   if (it == end(intern)) { n     interned_size[cnt] = s.size(); n     return intern[s] = cnt++; n   } n   return it->second; n } n int brute(int a, int b) { n   int res = inf; n   vector<int>&ma = matches[a], &mb = matches[b]; n   for (int i = 0; i < ma.size(); ++i) { n     int j = lower_bound(begin(mb), end(mb), ma[i]) - begin(mb); n     if (j < mb.size()) n       res = min(res, f(ma[i], interned_size[a], mb[j], interned_size[b])); n   } n   return res; n } n int main() { n   cin >> s; n   for (int i = 0; i < s.size(); ++i) { n     for (int w = 1; w <= 4; ++w) { n       S[i][w] = get(s.substr(i, w)); n       matches[S[i][w]].push_back(i); n     } n   } n   int q; n   cin >> q; n   fill(ans, ans + q, inf); n   for (int i = 0; i < q; ++i) { n     string as, bs; n     cin >> as >> bs; n     int a = get(as), b = get(bs); n     if (max(matches[a].size(), matches[b].size()) < rt) { n       ans[i] = min(brute(a, b), brute(b, a)); n     } else { n       if (matches[a].size() < matches[b].size()) swap(a, b); n       post[a].insert(b); n       look[i] = make_pair(a, b); n       todo[i] = 1; n     } n   } n   for (auto& it : post) { n     const int a = it.first; n     auto& m = it.second; n     int last = matches[a][0]; n     for (int i = last; i < s.size(); ++i) { n       for (int w = 1; w <= 4; ++w) n         if (S[i][w] == a) last = i; n       for (int w = 1; w <= 4; ++w) { n         int b = S[i][w]; n         if (m.find(b) == end(m)) continue; n         auto st = make_pair(a, b); n         int sol = f(last, interned_size[a], i, interned_size[b]); n         auto fi = ans2.find(st); n         if (fi == end(ans2) || sol < fi->second) ans2[st] = sol; n       } n     } n     last = matches[a].back(); n     for (int i = last; i >= 0; --i) { n       for (int w = 1; w <= 4; ++w) n         if (S[i][w] == a) last = i; n       for (int w = 1; w <= 4; ++w) { n         int b = S[i][w]; n         if (m.find(b) == end(m)) continue; n         auto st = make_pair(a, b); n         int sol = f(last, interned_size[a], i, interned_size[b]); n         auto fi = ans2.find(st); n         if (fi == end(ans2) || sol < fi->second) ans2[st] = sol; n       } n     } n   } n   for (int i = 0; i < q; ++i) { n     if (todo[i]) ans[i] = ans2.find(look[i]) != end(ans2) ? ans2[look[i]] : inf; n     cout << (ans[i] == inf ? -1 : ans[i]) << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX = 7E5 + 10; n const int BASE = 1E6 + 3; n int n, p; n long long f[MAX]; n long long power(int x, int n) { n   if (n == 0) return 1; n   long long tmp = power(x, n / 2); n   tmp = tmp * tmp; n   if (n % 2) tmp = tmp * x; n   tmp %= BASE; n   return tmp; n } n long long C(int k, int n) { n   return f[n] * power((f[n - k] * f[k]) % BASE, BASE - 2); n } n void init() { n   f[0] = 1; n   for (int i = 1; i < n + p; i++) f[i] = (f[i - 1] * i) % BASE; n } n int main() { n   scanf( %d%d , &n, &p); n   init(); n   long long res = 0; n   for (int i = 1; i <= n; i++) res = (res + C(p - 1, i + p - 1)) % BASE; n   printf( %I64d , res); n } n


#include <bits/stdc++.h> n using namespace std; n long long int diff(long long int x, long long int y) { n   if (x > y) { n     return x - y; n   } else { n     return y - x; n   } n } n int main() { n   long long int n; n   cin >> n; n   long long int arr[n]; n   for (long long int i = 0; i < n; i++) { n     cin >> arr[i]; n   } n   long long int count = 0; n   long long int ans = 0; n   for (long long int i = 0; i < n; i++) { n     if (arr[i] == 1) { n       count++; n       if (count > ans) { n         ans = count; n       } n     } else { n       count = 0; n     } n   } n   if (count != 0) { n     for (int i = 0; i < n; i++) { n       if (arr[i] == 1) { n         count++; n         if (count > ans) { n           ans = count; n         } n       } else { n         break; n       } n     } n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n set<unsigned int> black[33], white[33]; n unsigned int masks[33]; n string parseipB(unsigned int x, int mask) { n   string s =   ; n   for (int i = 0; i < 4; ++i) { n     for (int j = 0; j < 8; ++j) { n       s += to_string(1 & x >> 8 * i + j); n     } n     if (i != 3) s +=  . ; n   } n   s +=  /  + to_string(mask); n   return s; n } n string parseip(unsigned int x, int mask) { n   string s =   ; n   for (int i = 0; i < 4; ++i) { n     int val = 0; n     for (int j = 7; j >= 0; --j) { n       val += (1 & x >> 8 * i + j) << 7 - j; n     } n     s += to_string(val); n     if (i != 3) s +=  . ; n   } n   s +=  /  + to_string(mask); n   return s; n } n int main() { n   masks[0] = 0; n   for (int i = 1; i < 33; ++i) { n     masks[i] = masks[i - 1] | (1 << (i - 1)); n   } n   int n; n   scanf( %d n , &n); n   bool hasblacks = false, haswhites = false; n   for (int i = 0; i < n; ++i) { n     char sign, sub; n     int arr[4]; n     int mask; n     scanf( %c%d.%d.%d.%d , &sign, &arr[0], &arr[1], &arr[2], &arr[3]); n     scanf( %c , &sub); n     if (sub ==  / ) { n       scanf( %d n , &mask); n     } else { n       mask = 32; n     } n     unsigned int val = 0; n     for (int j = 0; j < 4; ++j) { n       unsigned int oct = 0; n       for (int k = 7; k >= 0; --k) { n         oct += (1 & arr[j] >> 7 - k) << k; n       } n       val += (oct << (8 * j)); n     } n     if (sign ==  - ) { n       hasblacks = true; n       black[mask].insert(val); n     } else { n       haswhites = true; n       white[mask].insert(val); n     } n   } n   if (hasblacks && !haswhites) { n     cout <<  1 n0.0.0.0/0 n ; n     return 0; n   } n   if (!hasblacks && haswhites) { n     cout <<  0 n ; n     return 0; n   } n   bool ok = true; n   for (int i = 32; i >= 0; --i) { n     for (unsigned int x : white[i]) { n       for (int j = 32; j >= 0; --j) { n         if (black[j].count(masks[j] & x) != 0) { n           ok = false; n           break; n         } n       } n     } n     for (unsigned int x : black[i]) { n       for (int j = 32; j >= 0; --j) { n         if (white[j].count(masks[j] & x) != 0) { n           ok = false; n           break; n         } n       } n     } n   } n   if (!ok) { n     cout <<  -1 n ; n     return 0; n   } n   vector<pair<unsigned int, unsigned int> > ans; n   for (int i = 32; i > 0; --i) { n     for (unsigned int x : white[i]) { n       white[i - 1].insert(masks[i - 1] & x); n     } n     for (unsigned int x : black[i]) { n       bool shift = white[i].count(x ^ (1 << i - 1)) == 0; n       if (shift) { n         black[i - 1].insert(masks[i - 1] & x); n       } else { n         ans.push_back(pair<unsigned int, unsigned int>(x, i)); n       } n     } n   } n   cout << ans.size() <<   n ; n   for (int i = 0; i < ans.size(); ++i) { n     unsigned int val = ans[i].first; n     int mask = ans[i].second; n     cout << parseip(val, mask) <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int sz = 1e6 + 9; n int n, m, k; n long long tr[sz], tr_sum, tr_cnt; n long long ret[sz], ret_sum, ret_cnt; n int d, first, t, c; n vector<pair<pair<int, int>, pair<int, int>>> v; n vector<pair<long long, long long>> home; n long long home_ans[sz]; n long long ans = 1e18; n int days[sz]; n int main() { n   cin >> n >> m >> k; n   for (int i = 0; i < m; ++i) { n     cin >> d >> first >> t >> c; n     v.push_back(make_pair(make_pair(d, first), make_pair(t, c))); n   } n   sort(v.begin(), v.end()); n   for (int i = v.size() - 1; i >= 0; i--) { n     d = v[i].first.first; n     first = v[i].first.second; n     t = v[i].second.first; n     c = v[i].second.second; n     if (first) continue; n     if (!ret[t]) { n       ret[t] = c; n       ret_sum += c; n       ret_cnt++; n     } else if (ret[t] > c) { n       ret_sum -= ret[t]; n       ret[t] = c; n       ret_sum += c; n     } n     if (ret_cnt == n) home.push_back(make_pair(d, ret_sum)); n   } n   sort(home.begin(), home.end()); n   int tmp = 0; n   for (auto u : home) days[tmp++] = u.first; n   for (int i = home.size() - 1; i >= 0; i--) { n     if (i == home.size() - 1) n       home_ans[i] = home[i].second; n     else n       home_ans[i] = min(home_ans[i + 1], home[i].second); n   } n   for (int i = 0; i < v.size(); ++i) { n     d = v[i].first.first; n     first = v[i].first.second; n     t = v[i].second.first; n     c = v[i].second.second; n     if (t) continue; n     if (!tr[first]) { n       tr[first] = c; n       tr_sum += c; n       tr_cnt++; n     } else if (tr[first] > c) { n       tr_sum -= tr[first]; n       tr[first] = c; n       tr_sum += c; n     } n     if (tr_cnt == n) { n       int pos = lower_bound(days, days + home.size(), d + 1 + k) - days; n       if (pos >= home.size()) continue; n       ans = min(ans, tr_sum + home_ans[pos]); n     } n   } n   if (ans == 1e18) n     cout << -1; n   else n     cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> v[2005]; n int vi[2005]; n void dfs(int cu) { n   int j, l = v[cu].size(); n   vi[cu] = 1; n   for (j = 0; j < l; j++) { n     if (!vi[v[cu][j]]) dfs(v[cu][j]); n   } n } n int main() { n   int n, m, k, cn = 0, i, j; n   scanf( %d%d , &n, &m); n   scanf( %d , &k); n   long long an = 1; n   for (i = 1; i + k - 1 <= n; i++) { n     for (j = i; j < i + k / 2; j++) { n       v[j].push_back(2 * i + k - 1 - j); n       v[2 * i + k - 1 - j].push_back(j); n     } n   } n   for (i = 1; i < n + 1; i++) { n     if (!vi[i]) dfs(i), cn++; n   } n   for (i = 0; i < cn; i++) an = (an * m) % 1000000007LL; n   printf( %lld , an); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, q; n vector<pair<int, int> > L, R; n int whereL[30013], whereR[30013]; n long long cost[30013][2]; n long long dp[30013]; n const long long INF = -3.1e16; n inline long long match(int a, int b) { n   if (a <= 0 || b <= 0 || a > n || b > n) return INF; n   return (long long)L[a].first * R[b].first; n } n inline void update(int i) { n   if (i <= 0 || i > n) return; n   cost[i][0] = match(i, i + 1) + match(i + 1, i); n   cost[i][1] = max(match(i, i + 1) + match(i + 1, i + 2) + match(i + 2, i), n                    match(i, i + 2) + match(i + 1, i) + match(i + 2, i + 1)); n } n int main() { n   scanf( %d%d , &n, &q); n   for (int i = 0; i <= n; i++) { n     L.push_back(make_pair(0, i)); n     R.push_back(make_pair(0, i)); n   } n   for (int i = 1; i <= n; i++) scanf( %d , &L[i].first); n   for (int i = 1; i <= n; i++) scanf( %d , &R[i].first); n   sort(L.begin(), L.end()); n   sort(R.begin(), R.end()); n   for (int i = 1; i <= n; i++) { n     whereL[L[i].second] = i; n     whereR[R[i].second] = i; n   } n   for (int i = 1; i <= n; i++) update(i); n   for (int Q = 0; Q < q; Q++) { n     int a, b; n     scanf( %d%d , &a, &b); n     swap(R[whereR[a]].second, R[whereR[b]].second); n     swap(whereR[a], whereR[b]); n     for (int i = -2; i <= 0; i++) { n       update(whereL[a] + i); n       update(whereR[a] + i); n       update(whereL[b] + i); n       update(whereR[b] + i); n     } n     dp[n + 1] = 0; n     for (int i = n; i; i--) { n       dp[i] = max(dp[i + 2] + cost[i][0], dp[i + 3] + cost[i][1]); n       if (L[i].second != R[i].second) n         dp[i] = max(dp[i], (long long)L[i].first * R[i].first + dp[i + 1]); n     } n     printf( %I64d n , dp[1]); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 5e6 + 10; n const int MAX = 1e5 + 10; n const double eps = 1e-6; n priority_queue<int> q, Q; n long long s[MAX]; n int main() { n   long long n, k; n   cin >> n >> k; n   int cnt = 0; n   while (n > 0) { n     long long b = 1; n     int a = 0; n     while (b * 2 <= n) b *= 2, a++; n     cnt++; n     q.push(a); n     Q.push(a); n     n -= b; n   } n   if (cnt > k) { n     cout <<  No  << endl; n     return 0; n   } n   int temp = cnt; n   while (temp < k) { n     int a = Q.top(); n     Q.pop(); n     a--; n     Q.push(a); n     Q.push(a); n     temp++; n   } n   temp = Q.top(); n   while (cnt < k) { n     int a = q.top(); n     if (temp == a) break; n     q.pop(); n     a--; n     q.push(a); n     q.push(a); n     cnt++; n   } n   temp = 0; n   while (q.size()) { n     s[temp++] = q.top(); n     q.pop(); n   } n   while (cnt < k) { n     s[cnt - 1] = s[cnt - 1] - 1; n     s[cnt] = s[cnt - 1]; n     cnt++; n   } n   cout <<  Yes  << endl; n   for (int i = 0; i < cnt; i++) { n     if (i == 0) n       cout << s[i]; n     else n       cout <<     << s[i]; n   } n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:16777216 ) n using namespace std; n int a, b, c, d, i, j, n, m, k; n int cnt[6]; n map<string, int> q; n const int di[] = {0, 1, -1, 2, -2, 3, -3, 4, -4}; n const char *name[] = { S ,  M ,  L ,  XL ,  XXL }; n int main() { n   for (int _n((5) - 1), i(0); i <= _n; i++) scanf( %d , &cnt[i]); n   q[ S ] = 0; n   q[ M ] = 1; n   q[ L ] = 2; n   q[ XL ] = 3; n   q[ XXL ] = 4; n   scanf( %d , &n); n   for (int _n((n)-1), i(0); i <= _n; i++) { n     string s; n     cin >> s; n     a = q[s]; n     for (int _n((9) - 1), j(0); j <= _n; j++) { n       if (a + di[j] >= 0 && a + di[j] < 5 && cnt[a + di[j]]) { n         printf( %s n , name[a + di[j]]); n         --cnt[a + di[j]]; n         break; n       } n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 1e9 + 7, MAXN = 1e5 + 10; n int n, l, r, a[MAXN], b[MAXN]; n vector<int> aa, bb; n int main() { n   ios_base::sync_with_stdio(0); n   cin >> n >> l >> r; n   for (int i = 1; i <= n; ++i) { n     cin >> a[i]; n     if (l <= i && i <= r) aa.push_back(a[i]); n   } n   for (int i = 1; i <= n; ++i) { n     cin >> b[i]; n     if (l <= i && i <= r) bb.push_back(b[i]); n   } n   for (int i = 1; i < l; ++i) n     if (a[i] != b[i]) { n       cout <<  LIE ; n       return 0; n     } n   for (int i = r + 1; i <= n; ++i) n     if (a[i] != b[i]) { n       cout <<  LIE ; n       return 0; n     } n   sort(aa.begin(), aa.end()); n   sort(bb.begin(), bb.end()); n   if (aa == bb) n     cout <<  TRUTH ; n   else n     cout <<  LIE ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX = 200000 + 10; n const int ALPHA = 30; n const int NUM = 12; n int T; n char a[MAX]; n struct Node { n   Node *ch[ALPHA], *p; n   int cc[NUM]; n   int len; n   Node() { n     memset(ch, 0, sizeof ch); n     p = 0; n     len = 0; n     memset(cc, 0, sizeof cc); n   } n }* Root = new Node; n int L[NUM], R[NUM]; n vector<Node*> all; n int cmp(Node* a, Node* b) { return a->len < b->len; } n void add(Node* v, int id, int len) { n   if (v->ch[id] && v->ch[id]->len == len) return; n   Node* u = new Node; n   all.push_back(u); n   u->len = len; n   for (; v && !v->ch[id]; v = v->p) v->ch[id] = u; n   if (!v) n     u->p = Root; n   else { n     Node* nu = v->ch[id]; n     if (nu->len == v->len + 1) n       u->p = nu; n     else { n       Node* nnu = new Node; n       all.push_back(nnu); n       *nnu = *nu; n       memset(nnu->cc, 0, sizeof nnu->cc); n       u->p = nnu; n       nu->p = nnu; n       nnu->len = v->len + 1; n       for (; v && v->ch[id] == nu; v = v->p) v->ch[id] = nnu; n     } n   } n   return; n } n void init(char* a, int n, int l, int r, int lab) { n   L[lab] = l; n   R[lab] = r; n   int i; n   Node* now = Root; n   for ((i) = (1); (i) <= (n); ++(i)) { n     int id = a[i] -  a ; n     add(now, id, i); n     now = now->ch[id]; n     ++now->cc[lab]; n   } n } n int main() { n   int i, first, second; n   scanf( %s , a + 1); n   init(a, strlen(a + 1), 1, strlen(a + 1), 0); n   scanf( %d , &T); n   for ((i) = (1); (i) <= (T); ++(i)) { n     scanf( %s%d%d , a + 1, &first, &second); n     init(a, strlen(a + 1), first, second, i); n   } n   int j; n   long long ans = 0; n   sort(all.begin(), all.end(), cmp); n   for (i = (int)all.size() - 1; i >= 0; --i) { n     int flag = 1; n     for ((j) = (0); (j) <= (T); ++(j)) { n       all[i]->p->cc[j] += all[i]->cc[j]; n       flag = flag && (all[i]->cc[j] <= R[j] && all[i]->cc[j] >= L[j]); n     } n     if (flag) ans += all[i]->len - all[i]->p->len; n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long dp[1000006][2]; n long long pre[1000006][2]; n void chkMinLog(long long& goal, long long t1, bool t2, bool curr) { n   if (dp[t1][t2] > goal) { n     dp[t1][t2] = goal; n     pre[t1][t2] = curr; n   } n } n void solve() { n   long long n; n   cin >> n; n   vector<long long> a(n + 2); n   for (long long i = (1); i <= (n); i++) cin >> a[i]; n   for (long long i = (1); i <= (n); i++) n     for (long long j = (0); j <= (1); j++) dp[i][j] = 1e18; n   a[0] = n + 1; n   dp[0][0] = dp[0][1] = -n - 1; n   for (long long i = (0); i <= (n - 1); i++) n     for (long long isPos = (0); isPos <= (1); isPos++) { n       long long sv = (isPos ? 1 : -1) * a[i], v = dp[i][isPos]; n       if (-a[i + 1] > v) chkMinLog(sv, i + 1, false, isPos); n       if (a[i + 1] > v) chkMinLog(sv, i + 1, true, isPos); n       if (-a[i + 1] > sv) chkMinLog(v, i + 1, false, isPos); n       if (a[i + 1] > sv) chkMinLog(v, i + 1, true, isPos); n     } n   if (dp[n][0] <= n || dp[n][1] <= n) { n     cout <<  YES  << endl; n     long long ti = n, ts = 0; n     if (dp[n][1] <= n) ts = 1; n     while (ti >= 1) { n       if (ts == 0) a[ti] = -a[ti]; n       ts = pre[ti][ts], ti--; n     } n     for (long long i = (1); i <= (n); i++) cout << a[i] <<    ; n     cout << endl; n   } else { n     cout <<  NO  << endl; n   } n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long T = 1; n   cin >> T; n   while (T--) solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long inf = 0x3f3f3f3f; n const int N = 5e5 + 10; n int a[8008]; n int n, ans = 0; n string s, ss, sss; n map<string, int> mp; n void str() { n   cin >> ss; n   int sum = 0; n   string x =   ; n   for (int i = 0; i < ss.length(); i++) { n     if (ss[i] ==  & ) n       sum--; n     else if (ss[i] ==  * ) n       sum++; n     else n       x += ss[i]; n   } n   ans = mp[x]; n   if (ans > 0) n     ans += sum; n   else n     ans = 0; n } n int main() { n   mp[ void ] = 1; n   cin >> n; n   while (n--) { n     cin >> s; n     ans = 0; n     if (s ==  typedef ) { n       str(); n       cin >> sss; n       mp[sss] = ans; n     } else { n       str(); n       ans--; n       if (ans < 0) n         cout <<  errtype  << endl; n       else { n         cout <<  void ; n         for (int i = 0; i < ans; i++) cout <<  * ; n         cout << endl; n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 200000; n pair<int, bool> p[N * 2]; n pair<int, int> t[N]; n int main() { n   int n; n   scanf( %d , &n); n   int l, r; n   for (int i = 0; i < n; ++i) { n     scanf( %d%d , &l, &r); n     t[i] = make_pair(l, r); n     p[i * 2].first = l; n     p[i * 2].second = false; n     p[i * 2 + 1].first = r + 1; n     p[i * 2 + 1].second = true; n   } n   sort(p, p + n * 2); n   int current = 0; n   vector<int> v; n   for (int i = 0; i < n * 2; ++i) { n     if (!p[i].second) n       ++current; n     else n       --current; n     if ((i == n * 2 - 1 || p[i + 1].first != p[i].first) && current == 1) n       v.push_back(p[i].first); n   } n   for (int i = 0; i < n; ++i) { n     int it = lower_bound(v.begin(), v.end(), t[i].first) - v.begin(); n     if (it == v.size() || (v[it] > t[i].second)) { n       printf( %d n , i + 1); n       return 0; n     } n   } n   printf( -1 n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, L, a[1005], b[1005], ans[1005], cc; n double dp[1005], dis[1005][1005]; n int pre[1005]; n inline bool check(double K) { n   dp[0] = 0; n   for (int i = 1; i <= n; ++i) { n     dp[i] = -1e9; n     for (int j = 0; j < i; ++j) { n       double v = dp[j] + K * b[i] - dis[j][i]; n       if (v > dp[i]) dp[i] = v, pre[i] = j; n     } n   } n   return dp[n] >= 0; n } n void output(int x) { n   if (!x) return; n   output(pre[x]); n   printf( %d  , x); n } n int main() { n   scanf( %d%d , &n, &L); n   for (int i = 1; i <= n; ++i) scanf( %d%d , a + i, b + i); n   for (int i = 0; i <= n; ++i) n     for (int j = i + 1; j <= n; ++j) dis[i][j] = sqrt(abs(a[j] - a[i] - L)); n   double l = 0, r = 1e9, mid; n   while (l + 1e-8 <= r) { n     mid = (l + r) / 2; n     if (check(mid)) n       r = mid; n     else n       l = mid; n   } n   check(r); n   output(n); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> o, p, e; n int n, i, j, x; n int a[200000], b[200000]; n struct T { n   int i; n } t; n bool operator<(T t1, T t2) { n   if ((t2.i - x - a[b[t2.i]] + 2 * n) % n != n       (t1.i - x - a[b[t1.i]] + 2 * n) % n) n     return (t2.i - x - a[b[t2.i]] + 2 * n) % n < n            (t1.i - x - a[b[t1.i]] + 2 * n) % n; n   return t1.i < t2.i; n } n priority_queue<T> qp; n set<T> qo; n set<T>::iterator it; n int main() { n   scanf( %d , &n); n   for (i = 0; i < n; i++) { n     scanf( %d , &x); n     a[x - 1] = i; n   } n   for (i = 0; i < n; i++) { n     scanf( %d , &b[i]); n     b[i]--; n   } n   x = 0; n   for (i = 0; i < n; i++) n     if (a[b[i]] < i) { n       t.i = i; n       qp.push(t); n     } else if (a[b[i]] > i) { n       t.i = i; n       qo.insert(t); n     } else n       e.push_back(i); n   for (i = 0; i < n; i++) { n     x = 1999999999; n     if (e.size()) n       printf( 0 n ); n     else { n       if (qp.size()) { n         t = qp.top(); n         x = min(x, (t.i - i + n) % n - a[b[t.i]]); n       } n       if (qo.size()) { n         it = qo.begin(); n         j = it->i; n         x = min(x, a[b[j]] - (j - i + n) % n); n       } n       printf( %d n , x); n     } n     x = i + 1; n     for (j = 0; j < e.size(); j++) { n       if (e[j] != i) { n         t.i = e[j]; n         qo.insert(t); n       } else { n         t.i = e[j]; n         qp.push(t); n       } n     } n     e.clear(); n     while (!qp.empty()) { n       t = qp.top(); n       if ((t.i - i - 1 + n) % n == a[b[t.i]]) { n         e.push_back(t.i); n         qp.pop(); n       } else n         break; n     } n     t.i = i; n     it = qo.find(t); n     if (it != qo.end()) { n       qo.erase(t); n       if (a[b[i]] == n - 1) n         e.push_back(i); n       else { n         t.i = i; n         qp.push(t); n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int l, r; n   cin >> l >> r; n   for (int i = l; i < r + 1; i++) { n     vector<int> cnts(10); n     int x = i; n     while (x > 0) { n       cnts[x % 10]++; n       x /= 10; n     } n     bool good = true; n     for (int j = 0; j < 10; j++) { n       if (cnts[j] > 1) { n         good = false; n       } n     } n     if (good) { n       cout << i << endl; n       return 0; n     } n   } n   cout << -1 << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void file() {} n void fast() { n   std::ios_base::sync_with_stdio(0); n   cin.tie(NULL); n   cout.tie(NULL); n } n long long gcd(long long a, long long b) { return !b ? a : gcd(b, a % b); } n long long lcm(long long a, long long b) { return (a / gcd(a, b)) * b; } n int dx[] = {-1, 0, 0, 1, 1, 1, -1, -1}; n int dy[] = {0, 1, -1, 0, 1, -1, 1, -1}; n int n, m, mem[100005][26]; n string s; n bool a[26][26]; n int solve(int i, int last) { n   if (i == n) return 0; n   int &ret = mem[i][last]; n   if (~ret) return ret; n   if (a[s[i] -  a ][last]) return ret = 1 + solve(i + 1, last); n   return ret = min(solve(i + 1, s[i] -  a ), 1 + solve(i + 1, last)); n } n int main() { n   file(); n   fast(); n   cin >> s; n   n = s.size(); n   cin >> m; n   while (m--) { n     char c1, c2; n     cin >> c1 >> c2; n     a[c1 -  a ][c2 -  a ] = a[c2 -  a ][c1 -  a ] = 1; n   } n   memset(mem, -1, sizeof mem); n   int mn = 1e9; n   for (int i = 0; i < n; i++) mn = min(mn, i + solve(i, s[i] -  a )); n   cout << mn; n } n


#include <bits/stdc++.h> n using namespace std; n inline int read() { n   register int x = 0, f = 1; n   register char ch = getchar(); n   while (!isdigit(ch)) { n     if (ch ==  - ) f = 0; n     ch = getchar(); n   } n   while (isdigit(ch)) { n     x = x * 10 + (ch ^  0 ); n     ch = getchar(); n   } n   return f ? x : -x; n } n int n, m, yt, Y[200005]; n struct subway { n   int x, y; n } sbw[100005]; n struct rabbit { n   int x, y, dis; n } rbt[100005]; n struct BIT { n   int tr[200005]; n   void modify(int x, int v) { n     for (; x <= yt; x += x & -x) tr[x] = max(tr[x], v); n   } n   int query(int x) { n     int ans = -1000000000; n     for (; x; x -= x & -x) ans = max(ans, tr[x]); n     return ans; n   } n } bit; n struct node { n   int x, y, id; n } q[200005]; n void work() { n   memset(bit.tr, -0x3f, sizeof bit.tr); n   yt = 0; n   for (int i = (1), _ed_ = (n); i <= _ed_; ++i) { n     Y[++yt] = rbt[i].y; n   } n   for (int i = (1), _ed_ = (m); i <= _ed_; ++i) { n     Y[++yt] = sbw[i].y; n   } n   sort(Y + 1, Y + yt + 1), yt = unique(Y + 1, Y + yt + 1) - Y - 1; n   for (int i = (1), _ed_ = (n); i <= _ed_; ++i) n     q[i] = (node){rbt[i].x, rbt[i].y, i}; n   for (int i = (1), _ed_ = (m); i <= _ed_; ++i) n     q[n + i] = (node){sbw[i].x, sbw[i].y, n + i}; n   sort(q + 1, q + n + m + 1, n        [&](node a, node b) { return a.x == b.x ? a.id > b.id : a.x < b.x; }); n   for (int i = (1), _ed_ = (n + m); i <= _ed_; ++i) { n     if (q[i].id > n) n       bit.modify(lower_bound(Y + 1, Y + yt + 1, q[i].y) - Y, q[i].x + q[i].y); n     else n       rbt[q[i].id].dis = n           min(rbt[q[i].id].dis, n               q[i].x + q[i].y - n                   bit.query(lower_bound(Y + 1, Y + yt + 1, q[i].y) - Y)); n   } n } n int rt[100005], tcnt, tr[6000005], ls[6000005], rs[6000005]; n void pushup(int p) { tr[p] = tr[ls[p]] + tr[rs[p]]; } n void insert(int& x, int y, int l, int r, int pos) { n   x = ++tcnt; n   tr[x] = tr[y], ls[x] = ls[y], rs[x] = rs[y]; n   if (l == r) return ++tr[x], void(); n   int mid = (l + r) >> 1; n   if (pos <= mid) n     insert(ls[x], ls[y], l, mid, pos); n   else n     insert(rs[x], rs[y], mid + 1, r, pos); n   pushup(x); n } n int query(int x, int y, int l, int r, int L, int R) { n   if (L > R || x == y) return 0; n   if (L <= l && r <= R) return tr[x] - tr[y]; n   int mid = (l + r) >> 1, ans = 0; n   if (L <= mid) ans += query(ls[x], ls[y], l, mid, L, R); n   if (ans) return ans; n   if (mid < R) ans += query(rs[x], rs[y], mid + 1, r, L, R); n   return ans; n } n int lower(int x) { n   int l = 1, r = m, ans = r + 1; n   while (l <= r) { n     int mid = (l + r) >> 1; n     if (sbw[mid].x >= x) n       ans = mid, r = mid - 1; n     else n       l = mid + 1; n   } n   return ans; n } n int upper(int x) { n   int l = 1, r = m, ans = r + 1; n   while (l <= r) { n     int mid = (l + r) >> 1; n     if (sbw[mid].x > x) n       ans = mid, r = mid - 1; n     else n       l = mid + 1; n   } n   return ans - 1; n } n int query(int x, int y) { n   int l = 0, r = 1000000000, ans, L, R, D, U; n   while (l <= r) { n     int mid = (l + r) >> 1; n     L = lower(x - mid), R = upper(x + mid), n     D = lower_bound(Y + 1, Y + yt + 1, y - mid) - Y, n     U = upper_bound(Y + 1, Y + yt + 1, y + mid) - Y - 1; n     if (L <= R && query(rt[R], rt[L - 1], 1, yt, D, U)) n       ans = mid, r = mid - 1; n     else n       l = mid + 1; n   } n   return ans; n } n struct square { n   int x1, y1, x2, y2; n   square(int x1 = 0, int y1 = 0, int x2 = 0, int y2 = 0) n       : x1(x1), y1(y1), x2(x2), y2(y2) {} n   void merge(square o) { n     x1 = max(x1, o.x1), y1 = max(y1, o.y1); n     x2 = min(x2, o.x2), y2 = min(y2, o.y2); n   } n   bool valid() { n     if (x1 == x2 && y1 == y2 && (x1 + y1) & 1) return 0; n     return x1 <= x2 && y1 <= y2; n   } n }; n bool check(int tim) { n   int p = n; n   while (p && rbt[p].dis > tim) --p; n   square nw(-1000000000, -1000000000, 1000000000, 1000000000); n   for (int i = (n), _ed_ = (p + 1); i >= _ed_; --i) n     nw.merge( n         square(rbt[i].x - tim, rbt[i].y - tim, rbt[i].x + tim, rbt[i].y + tim)); n   int L, R, D, U; n   while (p && nw.valid()) { n     int t = tim - rbt[p].dis, x1 = nw.x1, y1 = nw.y1, x2 = nw.x2, y2 = nw.y2; n     if (x1 == x2) { n       if ((x1 + y1) & 1) ++y1; n       if ((x2 + y2) & 1) --y2; n     } else if (y1 == y2) { n       if ((x1 + y1) & 1) ++x1; n       if ((x2 + y2) & 1) --x2; n     } n     if (x1 <= x2 && y1 <= y2) { n       L = lower(x1 - t), R = upper(x2 + t), n       D = lower_bound(Y + 1, Y + yt + 1, y1 - t) - Y, n       U = upper_bound(Y + 1, Y + yt + 1, y2 + t) - Y - 1; n       if (L <= R && query(rt[R], rt[L - 1], 1, yt, D, U)) return 1; n     } n     nw.merge( n         square(rbt[p].x - tim, rbt[p].y - tim, rbt[p].x + tim, rbt[p].y + tim)); n     --p; n   } n   if (nw.valid()) return 1; n   return 0; n } n int main() { n   n = read(), m = read(); n   for (int i = (1), _ed_ = (n); i <= _ed_; ++i) n     rbt[i] = (rabbit){read(), read(), 1000000000}; n   for (int i = (1), _ed_ = (m); i <= _ed_; ++i) n     sbw[i] = (subway){read(), read()}; n   for (int i = (1), _ed_ = (n); i <= _ed_; ++i) { n     rbt[i].x *= -1; n   } n   for (int i = (1), _ed_ = (m); i <= _ed_; ++i) { n     sbw[i].x *= -1; n   } n   work(); n   for (int i = (1), _ed_ = (n); i <= _ed_; ++i) { n     rbt[i].y *= -1; n   } n   for (int i = (1), _ed_ = (m); i <= _ed_; ++i) { n     sbw[i].y *= -1; n   } n   work(); n   for (int i = (1), _ed_ = (n); i <= _ed_; ++i) { n     rbt[i].x *= -1; n   } n   for (int i = (1), _ed_ = (m); i <= _ed_; ++i) { n     sbw[i].x *= -1; n   } n   work(); n   for (int i = (1), _ed_ = (n); i <= _ed_; ++i) { n     rbt[i].y *= -1; n   } n   for (int i = (1), _ed_ = (m); i <= _ed_; ++i) { n     sbw[i].y *= -1; n   } n   work(); n   for (int i = (1), _ed_ = (n); i <= _ed_; ++i) { n     int x = rbt[i].x, y = rbt[i].y; n     rbt[i].x = x + y, rbt[i].y = x - y; n   } n   for (int i = (1), _ed_ = (m); i <= _ed_; ++i) { n     int x = sbw[i].x, y = sbw[i].y; n     sbw[i].x = x + y, sbw[i].y = x - y; n   } n   sort(sbw + 1, sbw + m + 1, n        [&](subway a, subway b) { return a.x == b.x ? a.y < b.y : a.x < b.x; }); n   yt = 0; n   for (int i = (1), _ed_ = (m); i <= _ed_; ++i) Y[++yt] = sbw[i].y; n   sort(Y + 1, Y + yt + 1), yt = unique(Y + 1, Y + yt + 1) - Y - 1; n   for (int i = (1), _ed_ = (m); i <= _ed_; ++i) n     insert(rt[i], rt[i - 1], 1, yt, n            lower_bound(Y + 1, Y + yt + 1, sbw[i].y) - Y); n   sort(rbt + 1, rbt + n + 1, [&](rabbit a, rabbit b) { return a.dis < b.dis; }); n   int l = 0, r = rbt[n].dis, ans; n   while (l <= r) { n     int mid = (l + r) >> 1; n     if (check(mid)) n       ans = mid, r = mid - 1; n     else n       l = mid + 1; n   } n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int NMAX = 100005; n int A[NMAX]; n int main() { n   ios::sync_with_stdio(false); n   int n; n   cin >> n; n   bool ok = true; n   if (n % 2 == 1) { n     if ((n - 1) % 4 == 0) { n       for (int i = 1; i <= n / 2; i += 2) { n         A[i] = i + 1; n         A[i + 1] = n - i + 1; n         A[n - i + 1] = n - i; n         A[n - i] = i; n       } n       A[n / 2 + 1] = n / 2 + 1; n     } else { n       ok = false; n     } n   } else { n     if (n % 4 == 0) { n       for (int i = 1; i <= n / 2; i += 2) { n         A[i] = i + 1; n         A[i + 1] = n - i + 1; n         A[n - i + 1] = n - i; n         A[n - i] = i; n       } n     } else { n       ok = false; n     } n   } n   if (!ok) { n     cout <<  -1 n ; n   } else { n     for (int i = 1; i <= n; ++i) { n       cout << A[i] <<    ; n     } n     cout <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n template <class S, class T> n pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { n   return pair<S, T>(s.first + t.first, s.second + t.second); n } n template <class S, class T> n pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { n   return pair<S, T>(s.first - t.first, s.second - t.second); n } n template <class S, class T> n ostream &operator<<(ostream &os, pair<S, T> p) { n   os <<  (  << p.first <<  ,   << p.second <<  ) ; n   return os; n } n template <class T> n bool chmax(T &a, const T &b) { n   if (a < b) { n     a = b; n     return 1; n   } n   return 0; n } n template <class T> n bool chmin(T &a, const T &b) { n   if (a > b) { n     a = b; n     return 1; n   } n   return 0; n } n const long long inf = 1000000001; n const long long INF = 2e18; n const long long MOD = 1000000007; n const double pi = 3.14159265358979323846; n int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}; n int dx2[8] = {1, 1, 0, -1, -1, -1, 0, 1}, dy2[8] = {0, 1, 1, 1, 0, -1, -1, -1}; n vector<vector<int> > child(5010), parent(5010); n vector<int> color(5010, -1); n int n, m, s; n vector<int> roots, roots2; n void dfs1(int now, int col) { n   color[now] = col; n   for (long long i = 0; i < (long long)(child[now].size()); i++) { n     if (color[child[now][i]] < 0) { n       dfs1(child[now][i], col); n     } n   } n } n void dfs2(int now) { n   color[now] = -2; n   if (parent[now].size() == 0) { n     roots.push_back(now); n     return; n   } n   bool flag = true; n   for (long long i = 0; i < (long long)(parent[now].size()); i++) { n     if (color[parent[now][i]] == -1) { n       dfs2(parent[now][i]); n       flag = false; n     } n   } n   if (flag) { n     roots2.push_back(now); n   } n   return; n } n int main() { n   cin >> n >> m >> s; n   s--; n   for (long long i = 0; i < (long long)(m); i++) { n     int u, v; n     cin >> u >> v; n     u--; n     v--; n     child[u].push_back(v); n     parent[v].push_back(u); n   } n   dfs1(s, s); n   int ans = 0; n   for (long long i = 0; i < (long long)(n); i++) { n     if (color[i] >= 0) { n       continue; n     } n     roots.clear(); n     dfs2(i); n     ans += roots.size(); n     for (long long j = 0; j < (long long)(roots.size()); j++) { n       dfs1(roots[j], roots[j]); n     } n   } n   for (long long i = 0; i < (long long)(roots2.size()); i++) { n     if (color[roots2[i]] < 0) { n       ans++; n       dfs1(roots2[i], roots2[i]); n     } n   } n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n deque<int> d; n string mot; n int n; n void f(int i) { n   if (i == n) n     return; n   else { n     f(i + 1); n     if (mot[i] ==  l ) { n       d.push_back(i + 1); n     } else { n       d.push_front(i + 1); n     } n   } n } n int main() { n   cin >> mot; n   n = mot.size(); n   f(0); n   for (int i = 0; i < n; i++) cout << d[i] <<    ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n signed main() { n   printf( INTERCAL n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline int read() { n   int neg = 1, num = 0; n   char c = getchar(); n   for (; !isdigit(c); c = getchar()) n     if (c ==  - ) neg = -1; n   for (; isdigit(c); c = getchar()) num = (num << 1) + (num << 3) + c -  0 ; n   return neg * num; n } n int n, a, b; n char s[300010]; n int main() { n   n = read(); n   a = read(); n   b = read(); n   scanf( %s , s + 1); n   int las = 0, sum = 0; n   s[n + 1] =  * ; n   for (int i = 1; i <= n + 1; i++) n     if (s[i] ==  * ) { n       int x = (i - las - 1) / 2, y = i - las - 1 - x; n       if (a > b) swap(a, b); n       sum += min(a, x) + min(b, y); n       a = max(0, a - x); n       b = max(0, b - y); n       las = i; n     } n   printf( %d , sum); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 1e6 + 10; n const int MM = 1e9 + 7; n void pts(int x, int y, int z) { printf( 3 %d %d %d n , x, y, z); } n void pts(int w, int x, int y, int z) { printf( 4 %d %d %d %d n , w, x, y, z); } n void gao(int n) { n   if (n == 3) { n     pts(1, 2, 3); n     pts(1, 2, 3); n   } else if (n == 4) { n     pts(1, 2, 3, 4); n     pts(1, 2, 4, 3); n     pts(1, 4, 2, 3); n   } else if (n == 5) { n     pts(1, 3, 4, 2); n     pts(2, 4, 5, 3); n     pts(3, 5, 1, 4); n     pts(4, 1, 2, 5); n     pts(5, 2, 3, 1); n   } else { n     int m = n - 2; n     gao(m); n     pts(n - 1, n, m); n     pts(n - 1, n, m - 1); n     pts(n - 1, m - 1, n, m); n     m -= 2; n     for (int i = 0; i < m; i++) { n       pts(n - 1, i + 1, n, (i + 1) % m + 1); n     } n   } n } n void solve(int casi) { n   int n; n   scanf( %d , &n); n   if (n == 3) n     printf( 2 n ); n   else { n     int p = (n - 4) / 2 * 2; n     int q; n     if (n % 2 == 0) n       q = 2 + (n / 2 - 1) * (n - 2) / 2; n     else n       q = 3 + n / 2 * (n - 3) / 2; n     assert(3 * p + 4 * q == n * (n - 1)); n     printf( %d n , p + q); n   } n   gao(n); n } n int main() { n   int T = 1; n   for (int i = 1; i <= T; i++) solve(i); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int num1 = 0; n string s1, s2; n int counter = 0; n int ques = 0; n int main() { n   cin >> s1 >> s2; n   int num2 = 0; n   for (int i = 0; i < s1.length(); i++) n     if (s1[i] ==  + ) n       num1++; n     else n       num1--; n   for (int i = 0; i < s2.length(); i++) n     if (s2[i] ==  + ) n       num2++; n     else if (s2[i] ==  - ) n       num2--; n     else n       ques++; n   float num = 0; n   int limit = (1 << ques); n   for (int i = 0; i < limit; i++) { n     int sum = num2; n     for (int j = 0; j < ques; j++) { n       if ((1 << j) & i) n         sum++; n       else n         sum--; n     } n     if (sum == num1) counter++; n   } n   if (ques != 0) { n     num = (float)counter / (1 << ques); n   } else if (num2 == num1) n     num = 1; n   printf( %0.12f n , num); n } n


#include <bits/stdc++.h> n using namespace std; n char s[111][3]; n int main() { n   char t[3]; n   scanf( %s , t); n   int n; n   scanf( %d , &n); n   for (int i = 0; i < n; i++) { n     scanf( %s , s[i]); n   } n   for (int i = 0; i < n; i++) { n     if (t[0] == s[i][0] && t[1] == s[i][1]) { n       puts( YES ); n       return 0; n     } n   } n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < n; j++) { n       if (t[0] == s[i][1] && t[1] == s[j][0]) { n         puts( YES ); n         return 0; n       } n     } n   } n   puts( NO ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct hash { n   int head[8592637], next[8592637], t; n   unsigned long long lk[8592637]; n   double x[8592637]; n   double find(unsigned long long s) { n     for (int i = head[s % 8592637]; i; i = next[i]) n       if (lk[i] == s) return x[i]; n     return -1; n   } n   void ins(unsigned long long s, double f) { n     if (find(s) > -1) return; n     lk[++t] = s, x[t] = f, next[t] = head[s % 8592637], head[s % 8592637] = t; n   } n } H; n int N, a[105], F[256], b[105]; n inline int G(int x) { return !!x; } n inline void get(int x, int* a) { n   a[0] = (x >> 4) & 3, a[1] = (x >> 2) & 3, a[2] = x & 3; n } n inline int BG(int a, int b, int c) { n   if (a > c) swap(a, c); n   return (((a << 2) + b) << 2) + c; n } n void init() { n   scanf( %d , &N), F[ G ] = 1, F[ B ] = 2, F[ R ] = 3; n   char s[4]; n   for (int i = 1; i <= N; i++) n     scanf( %s , s), a[i] = BG(F[s[0]], F[s[1]], F[s[2]]); n } n unsigned long long Hash(int n) { n   unsigned long long s = 0; n   for (int i = 1; i <= n; i++) b[i] = a[i]; n   sort(b + 1, b + n); n   for (int i = 1; i <= n; i++) (s *= 31415927) += b[i]; n   return s; n } n double dfs(int n) { n   unsigned long long s = Hash(n); n   double f = H.find(s), c[4] = {0, 1e9, 1e9, 1e9}; n   if (f > -1) return f; n   for (int i = 1; i < n; i++) { n     int x[3], y[3], nn = n, ai = a[i], an = a[n]; n     get(ai, x), get(an, y); n     if (G(x[0]) + G(x[1]) + G(x[2]) == 1) continue; n     if (y[0] && y[1] && y[2]) nn++, y[0] = y[1] = y[2] = 0; n     for (int j = 0; j < 3; j++) n       if (x[j]) { n         int t = x[j]; n         if (G(x[0]) + G(x[1]) + G(x[2]) == 2 && j == 1) continue; n         if (G(x[0]) + G(x[1]) + G(x[2]) == 2 && !x[1]) break; n         x[j] = 0, a[i] = BG(x[0], x[1], x[2]); n         if (G(x[0]) + G(x[1]) + G(x[2]) == 1 || !x[1]) a[i] = 0; n         x[j] = t; n         for (int k = 0; k < 3; k++) n           if (!y[k]) n             y[k] = t, a[nn] = BG(y[0], y[1], y[2]), y[k] = 0, n             c[t] = min(c[t], dfs(nn)); n       } n     a[i] = ai, a[n] = an; n   } n   if (c[1] == 1e9 && c[2] == 1e9 && c[3] == 1e9) return H.ins(s, 0), 0; n   double t = 1.0 / 6; n   if (c[1] == 1e9) t += 1.0 / 3, c[1] = 0; n   if (c[2] == 1e9) t += 1.0 / 3, c[2] = 0; n   if (c[3] == 1e9) t += 1.0 / 6, c[3] = 0; n   f = (c[1] / 3 + c[2] / 3 + c[3] / 6 + 1) / (1 - t), H.ins(s, f); n   return f; n } n int main() { n   init(); n   printf( %.6lf n , dfs(N)); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 5; n int n, k; n int a[N]; n void solve(int l, int r) { n   if (k <= 0) { n     return; n   } n   if (l == r - 1) { n     return; n   } n   int mid = (l + r) / 2; n   swap(a[mid - 1], a[mid]); n   --k; n   --k; n   solve(l, mid); n   solve(mid, r); n } n int main() { n   scanf( %d%d , &n, &k); n   for (int i = 0; i < n; i++) a[i] = i + 1; n   if (k % 2 == 0) { n     puts( -1 ); n     return 0; n   } n   if (k > ((n)*2 - 1)) { n     puts( -1 ); n     exit(0); n   } n   --k; n   solve(0, n); n   for (int i = 0; i < n; i++) printf( %d  , a[i]); n } n


#include <bits/stdc++.h> n using namespace std; n long long int scs(long long int a) { n   long long int u = 0; n   while (a) { n     u++; n     a /= 10; n   } n   return u; n } n long long int mul(long long int a, long long int b, long long int m) { n   if (b == 1) return a % m; n   if (b == 0) return 1 % m; n   a %= m; n   b %= m; n   long long int q = mul(a, b / 2, m); n   if (b % 2 == 0) n     return (q + q) % m; n   else n     return (q + q + a) % m; n } n long long int mu(long long int a, long long int n, long long int m) { n   if (n == 0) return 1 % m; n   long long int q = mu(a, n / 2, m); n   if (n % 2 == 0) n     return mul(q, q, m); n   else n     return mul(mul(q, q, m), a, m); n } n long long int mu5[20]; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(NULL); n   long long int t; n   cin >> t; n   mu5[0] = 1; n   for (int i = 1; i <= 19; i++) mu5[i] = mu5[i - 1] * 5; n   for (int z = 1; z <= t; z++) { n     long long int a; n     cin >> a; n     long long int n = scs(a); n     long long int v = 0, m = 0; n     for (int mmm = 0; mmm <= 6; mmm++) { n       m = mmm; n       long long int b = (-a) % (1LL << (m + n)) * mu5[m] % (1LL << (m + n)) * n                         (1LL << m) % (1LL << (m + n)); n       b %= (1LL << (m + n)); n       if (b < 0) b += (1LL << (m + n)); n       bool q = 0; n       while (b < mu5[m] * (1LL << m)) { n         v = (b + mu5[m] * (1LL << m) * a) / (1LL << (m + n)); n         if (v % 5 != 0) { n           q = 1; n           break; n         } n         b += (1LL << (m + n)); n       } n       if (q == 1) { n         break; n       } n     } n     v %= mu5[m + n]; n     long long int mm[4] = {1, 2, 4, 3}; n     long long int res = 0; n     for (int i = 0; i <= 3; i++) { n       if (mm[i] == v % 5) res = i; n     } n     for (int i = 2; i <= m + n; i++) { n       long long int r = res; n       for (int u = 0; u <= 4; u++) { n         if (mu(2, r + u * 4 * mu5[i - 2], mu5[i]) == v % mu5[i]) { n           res = r + u * 4 * mu5[i - 2]; n           break; n         } n       } n     } n     res += m + n; n     cout << res << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool isPowerOfTwo(long long n) { n   if (n == 0) return false; n   return (ceil(log2(n)) == floor(log2(n))); n } n long long power(long long x, unsigned long long y) { n   if (y == 0) n     return 1; n   else if (y % 2 == 0) n     return power(x, y / 2) * power(x, y / 2); n   else n     return x * power(x, y / 2) * power(x, y / 2); n } n long long gcd(long long a, long long b) { n   if (b == 0) return a; n   return gcd(b, a % b); n } n signed main() { n   long long n; n   cin >> n; n   priority_queue<long long> a, b, c, d; n   for (long long i = 0; i < n; i++) { n     string s; n     long long x; n     cin >> s >> x; n     if (s ==  11 ) a.push(x); n     if (s ==  10 ) b.push(x); n     if (s ==  01 ) c.push(x); n     if (s ==  00 ) d.push(x); n   } n   long long ans = 0; n   long long x = 0, y = 0, z = 0; n   ; n   while (!a.empty()) { n     ans += a.top(); n     x++; n     y++; n     a.pop(); n     z++; n   } n   while (!b.empty() && !c.empty()) { n     ans += b.top(); n     ans += c.top(); n     x++; n     y++; n     z += 2; n     b.pop(); n     c.pop(); n   } n   long long p = 2 * x - z; n   if (b.empty() == true) { n     while (!c.empty()) { n       d.push(c.top()); n       c.pop(); n     } n   } else { n     while (!b.empty()) { n       d.push(b.top()); n       b.pop(); n     } n   } n   while (p > 0 && !d.empty()) { n     p--; n     ans += d.top(); n     d.pop(); n   } n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxx = 1000 + 50; n long long DP[maxx]; n int main() { n   int n, m; n   cin >> n >> m; n   int t = abs(n - m); n   DP[1] = 1; n   DP[2] = 3; n   for (int i = 3; i <= 1000; i++) DP[i] = DP[i - 1] + i; n   int ans = 0; n   ans = 2 * DP[(t / 2)]; n   if (t % 2 == 1) ans += (t / 2) + 1; n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 0x3f3f3f3f, maxn = 10; n int Pow(int a, int b) { n   int ans = 1; n   while (b) { n     if (b & 1) ans = (long long)ans * a % 1000000007; n     a = (long long)a * a % 1000000007; n     b >>= 1; n   } n   return ans; n } n int main() { n   int n, k; n   while (~scanf( %d%d , &n, &k)) { n     int ans = (long long)Pow(k, k - 1) * Pow(n - k, n - k) % 1000000007; n     printf( %d n , ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long powmod(long long p, long long n) { n   if (n == 0) return 1; n   if (n % 2 == 1) return (p * powmod(p, n - 1)) % 1000000007; n   long long z = powmod(p, n / 2); n   return (z * z) % 1000000007; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   long long x, n; n   cin >> x >> n; n   set<long long> P; n   for (long long i = 2; i < 100000 && x > 1; ++i) { n     while (x % i == 0) { n       P.insert(i); n       x /= i; n     } n   } n   if (x > 1) P.insert(x); n   long long ans = 1; n   for (long long p : P) { n     long long a = 0; n     long long b = n; n     while (b) { n       b /= p; n       a += b; n       a %= (1000000007 - 1); n     } n     ans *= powmod(p, a); n     ans %= 1000000007; n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int N, n, m; n long long a[1 << 20], b[1 << 20]; n int g[21][100001]; n void FWT(long long *P, int opt) { n   for (int i = 2; i <= N; i <<= 1) n     for (int p = i >> 1, j = 0; j < N; j += i) n       for (int k = j; k < j + p; ++k) { n         long long x = P[k], y = P[k + p]; n         P[k] = x + y; n         P[k + p] = x - y; n         if (opt == -1) P[k] /= 2, P[k + p] /= 2; n       } n } n int main() { n   cin >> n >> m; n   N = 1 << n; n   char ch[100001]; n   for (int i = 1; i <= n; ++i) { n     scanf( %s , ch + 1); n     for (int j = 1; j <= m; ++j) g[i][j] = ch[j] - 48; n   } n   for (int i = 1; i <= m; ++i) { n     int x = 0; n     for (int j = 1; j <= n; ++j) x = (x << 1) | g[j][i]; n     a[x]++; n   } n   for (int i = 0; i < N; ++i) b[i] = b[i >> 1] + (i & 1); n   for (int i = 0; i < N; ++i) b[i] = min(b[i], n - b[i]); n   FWT(a, 1); n   FWT(b, 1); n   for (int i = 0; i < N; ++i) a[i] *= b[i]; n   FWT(a, -1); n   long long ans = n * m; n   for (int i = 0; i < N; ++i) ans = min(ans, a[i]); n   printf( %I64d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double PI = acos(-1); n const double eps = 1e-6; n inline long long lgput(long long a, long long b, long long mod) { n   long long ret = 1; n   while (b) { n     if (b & 1) ret = (ret * a) % mod; n     a = (a * a) % mod; n     b >>= 1; n   } n   return (ret % mod); n } n inline long long inv(long long x, long long MOD) { n   return lgput(x, MOD - 2, MOD); n } n inline bool exist(double nr) { return (nr < -eps) || (nr > eps); } n long long big_rand() { return rand() * RAND_MAX + rand(); } n map<int, int> gr[100100]; n map<int, int> vec[100100]; n vector<int> ap[100100]; n int dad[100100]; n int superdad(int a) { n   if (dad[a] != a) { n     dad[a] = superdad(dad[a]); n   } n   return dad[a]; n } n void bag(int a, int b) { n   for (auto &x : ap[dad[a]]) { n     vec[x][dad[b]] = 1; n     ap[dad[b]].push_back(x); n   } n   ap[dad[a]].clear(); n   dad[dad[a]] = dad[b]; n } n void unite(int a, int b) { n   superdad(a); n   superdad(b); n   if (dad[a] == dad[b]) { n     return; n   } n   if (ap[dad[a]].size() < ap[dad[b]].size()) { n     bag(a, b); n   } else { n     bag(b, a); n   } n } n void edge(int x, int y, int val) { n   if (gr[x][val]) { n     unite(y, gr[x][val]); n   } n   if (gr[y][val]) { n     unite(x, gr[y][val]); n   } n   gr[x][val] = y; n   gr[y][val] = x; n   superdad(x); n   superdad(y); n   vec[y][dad[x]] = 1; n   vec[x][dad[y]] = 1; n   ap[dad[x]].push_back(y); n   ap[dad[y]].push_back(x); n } n bool verif(int x, int y) { n   superdad(x); n   superdad(y); n   if (dad[x] == dad[y]) { n     return 1; n   } n   if (vec[y][dad[x]]) { n     return 1; n   } n   return 0; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(nullptr); n   cout.tie(nullptr); n   cout << setprecision(10) << fixed; n   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); n   srand(time(nullptr)); n   int n, m, c, q; n   cin >> n >> m >> c >> q; n   for (int i = 1; i <= n; i++) { n     dad[i] = i; n   } n   for (int i = 1; i <= m; i++) { n     int x, y, val; n     cin >> x >> y >> val; n     edge(x, y, val); n   } n   while (q--) { n     char ch; n     cin >> ch; n     if (ch ==  + ) { n       int x, y, val; n       cin >> x >> y >> val; n       edge(x, y, val); n     } else { n       int x, y; n       cin >> x >> y; n       if (verif(x, y)) { n         cout <<  Yes  <<   n ; n       } else { n         cout <<  No  <<   n ; n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n pair<pair<int, int>, int> a[100100]; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cin >> n; n   for (int i = 1; i <= n; i++) { n     int x; n     cin >> x; n     a[i].first.first = x; n   } n   for (int i = 1; i <= n; i++) { n     int x; n     cin >> x; n     a[i].first.second = x; n     a[i].second = i; n   } n   sort(a + 1, a + n + 1); n   reverse(a + 1, a + n + 1); n   cout << (n / 2) + 1 << endl; n   cout << a[1].second <<    ; n   for (int i = 2; i <= n; i += 2) { n     if (i == n) n       cout << a[i].second; n     else { n       int x = a[i].second; n       if (a[i + 1].first.second > a[i].first.second) x = a[i + 1].second; n       cout << x <<    ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int a; n   cin >> a; n   for (int i = 0; i < a; i++) { n     long long x = 0; n     long long a; n     long long b; n     long long k; n     cin >> a >> b >> k; n     if (k % 2 == 1) { n       x = (a - b) * (k / 2); n       x = x + a; n     } else { n       x = (a - b) * (k / 2); n     } n     cout << x << endl; n   } 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   cout.tie(NULL); n   long long n; n   cin >> n; n   long long i, x; n   vector<long long> v; n   for (i = 0; i < n; i++) { n     cin >> x; n     v.push_back(x); n   } n   long long ans = 0; n   for (long long i = 0; i < n; i++) { n     long long sum = 0; n     for (long long j = i; j < n; j++) { n       sum += v[j]; n       if (sum > 100 * (j - i + 1)) ans = max(ans, j - i + 1); n     } n   } n   cout << ans <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 1e6 + 5; n const long long mod = 998244353; n set<long long> pre, cur; n string s, mn, mx; n long long zmin[2 * N]; n long long zmax[2 * N]; n long long dmin[N]; n long long dmax[N]; n long long dp[N]; n long long n; n void init() { n   long long n, m, l, r; n   string str; n   n = s.size(); n   m = mn.size(); n   l = r = 0; n   str = mn +  #  + s; n   for (long long i = 1; i <= n + m; i++) { n     long long &x = zmin[i]; n     if (i <= r) x = min(zmin[i - l], r - i); n     while (i + x <= n + m && str[x] == str[i + x]) x++; n     if (i + x >= r) { n       l = i; n       r = i + x; n     } n     if (i > m) dmin[i - m] = i - m + x; n   } n   n = s.size(); n   m = mx.size(); n   l = r = 0; n   str = mx +  #  + s; n   for (long long i = 1; i <= n + m; i++) { n     long long &x = zmax[i]; n     if (i <= r) x = min(zmax[i - l], r - i); n     while (i + x <= n + m && str[x] == str[i + x]) x++; n     if (i + x >= r) { n       l = i; n       r = i + x; n     } n     if (i > m) dmax[i - m] = i - m + x; n   } n } n bool ok(long long l, long long r) { n   if (r - l + 1 > mx.size()) return false; n   if (r - l + 1 == mx.size()) { n     long long mid = dmax[l]; n     if (mid <= r && s[mid] > mx[mid - l]) return false; n   } n   if (r - l + 1 < mn.size()) return false; n   if (r - l + 1 == mn.size()) { n     long long mid = dmin[l]; n     if (mid <= r && s[mid] < mn[mid - l]) return false; n   } n   return true; n } n void add(long long &a, long long b) { n   a += b; n   if (a >= mod) a -= mod; n } n void sub(long long &a, long long b) { n   a -= b; n   if (a < 0) a += mod; n } n void solve() { n   long long sum = 0; n   dp[0] = 1; n   for (long long i = 1; i <= n; i++) { n     dp[i] = 0; n     while (pre.size()) { n       long long pos = *pre.begin(); n       if (ok(pos, i)) { n         cur.insert(pos); n         pre.erase(pos); n         add(sum, dp[pos - 1]); n       } else n         break; n     } n     while (cur.size()) { n       long long pos = *cur.begin(); n       if (!ok(pos, i)) { n         cur.erase(pos); n         sub(sum, dp[pos - 1]); n       } else n         break; n     } n     dp[i] = sum; n     if (ok(i, i)) { n       add(dp[i], dp[i - 1]); n       if (s[i] !=  0 ) { n         cur.insert(i); n         add(sum, dp[i - 1]); n       } n     } else if (s[i] !=  0 ) n       pre.insert(i); n   } n   cout << dp[n] <<   n ; n } n void brute() { n   dp[0] = 1; n   for (long long i = 1; i <= n; i++) { n     dp[i] = 0; n     for (long long j = 0; j < i; j++) { n       if (ok(j + 1, i) && !(j + 1 != i && s[j + 1] ==  0 )) add(dp[i], dp[j]); n     } n   } n   cout << dp[n] <<   n ; n } n signed main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cin >> s >> mn >> mx; n   init(); n   n = s.size(); n   s =     + s; n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long int modularPower(long long int x, unsigned long long int y, n                            long long int mod) { n   long long int res = 1; n   x %= mod; n   while (y > 0) { n     if (y & 1) res = (res * x) % mod; n     y >>= 1; n     x = (x * x) % mod; n   } n   return res; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cerr.tie(NULL); n   cout.tie(NULL); n   ; n   int height; n   cin >> height; n   vector<int> v(height + 5); n   vector<int> sum(height + 5); n   int posOfChange = 0; n   for (int i = 0; i <= height; ++i) { n     int foo; n     cin >> foo; n     v[i] = foo; n   } n   while (posOfChange < height and n          (v[posOfChange] == 1 or v[posOfChange + 1] == 1)) n     posOfChange++; n   if (posOfChange == height) { n     cout <<  perfect ; n     return 0; n   } n   sum[0] = 1; n   for (int i = 1; i < v.size(); ++i) { n     sum[i] = sum[i - 1] + v[i - 1]; n   } n   cout <<  ambiguous  n        <<   n ; n   cout << 0 <<    ; n   for (int i = 1; i <= height; ++i) { n     for (int j = 0; j < v[i]; ++j) { n       cout << sum[i - 1] <<    ; n     } n   } n   cout <<   n  << 0 <<    ; n   for (int i = 1; i <= height; ++i) { n     if (i == posOfChange + 1) { n       cout << sum[i - 1] + 1 <<    ; n       for (int j = 1; j < v[i]; ++j) { n         cout << sum[i - 1] <<    ; n       } n     } else { n       for (int j = 0; j < v[i]; ++j) { n         cout << sum[i - 1] <<    ; n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = 0x3f3f3f3f; n const long long infLL = 0x3f3f3f3f3f3f3f3fLL; n const int maxn = 5000 + 5; n const int mod = 1000000007; n int n, m; n int s[maxn]; n int f[maxn], h[maxn]; n map<pair<int, int>, int> cows; n int l[maxn], r[maxn]; n int pre[maxn], suf[maxn]; n int cnt[maxn][4]; n void sweep() { n   for (int i = (1); i <= (n); ++i) { n     auto it = cows.find(pair<int, int>(s[i], ++pre[s[i]])); n     if (it != cows.end()) l[it->second] = i; n   } n   for (int i = n; i >= 1; --i) { n     auto it = cows.find(pair<int, int>(s[i], ++suf[s[i]])); n     if (it != cows.end()) r[it->second] = i; n   } n } n int main() { n   scanf( %d%d , &n, &m); n   for (int i = (1); i <= (n); ++i) scanf( %d , &s[i]); n   for (int i = 0; i < (m); ++i) { n     scanf( %d%d , &f[i], &h[i]); n     cows[pair<int, int>(f[i], h[i])] = i; n     l[i] = inf, r[i] = -inf; n   } n   sweep(); n   int X = 0, Y = 1; n   for (int i = 0; i < (m); ++i) n     if (r[i] > 0) ++cnt[f[i]][2]; n   for (int t = (1); t <= (n); ++t) n     if (cnt[t][2]) ++X, Y = (long long)Y * cnt[t][2] % mod; n   for (int i = 0; i < (m); ++i) n     if (l[i] <= n) { n       int x = 1, y = 1; n       memset(cnt, 0, sizeof(cnt)); n       for (int j = 0; j < (m); ++j) n         if (j != i) { n           int mask = 0; n           if (f[j] != f[i] && l[j] < l[i]) mask |= 1; n           if (r[j] > l[i]) mask |= 2; n           ++cnt[f[j]][mask]; n         } n       for (int t = (1); t <= (n); ++t) { n         int c = ((cnt[t][1] + cnt[t][3]) * (cnt[t][2] + cnt[t][3]) - cnt[t][3]); n         if (c) { n           x += 2, y = (long long)y * c % mod; n           continue; n         } n         c = cnt[t][1] + cnt[t][2] + cnt[t][3] * 2; n         if (c) ++x, y = (long long)y * c % mod; n       } n       if (x > X) n         X = x, Y = y; n       else if (x == X) n         Y = (Y + y) % mod; n     } n   printf( %d %d n , X, Y); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long n; n   cin >> n; n   long long a[n + 1][3]; n   map<long long, long long> m; n   for (long long i = 1; i <= n; i++) { n     cin >> a[i][0] >> a[i][1] >> a[i][2]; n   } n   vector<pair<double, pair<long long, long long> > > v; n   for (long long i = 1; i < n; i++) { n     for (long long j = i + 1; j <= n; j++) { n       double d = n           sqrt(pow(abs(a[i][0] - a[j][0]), 2) + pow(abs(a[i][1] - a[j][1]), 2) + n                pow(abs(a[i][2] - a[j][2]), 2)); n       v.push_back({d, {i, j}}); n     } n   } n   sort(v.begin(), v.end()); n   long long c = 0; n   for (long long i = 0; i < v.size(); i++) { n     if (m[(v[i].second).second] == 0 && m[(v[i].second).first] == 0) { n       cout << (v[i].second).second <<     << (v[i].second).first << endl; n       m[(v[i].second).second]++; n       m[(v[i].second).first]++; n       c++; n     } n     if (c == n / 2) break; n   } n } n


#include <bits/stdc++.h> n const int maxn = 5e5 + 5; n using namespace std; n char s[maxn]; n int main() { n   scanf( %s , s); n   int k = strlen(s); n   char y = s[0]; n   for (int i = 0; i < k; i++) { n     if (s[i] > y) { n       cout <<  Ann  << endl; n     } else { n       y = s[i]; n       cout <<  Mike  << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n string s; n bool es[100001]; n string ans; n void wk() { n   int i; n   cin >> n; n   cin >> s; n   for (i = 0; i <= n; i++) es[i] = false; n   int fstone = n; n   for (i = 0; i < n; i++) n     if (s[i] ==  1 ) { n       fstone = i; n       break; n     } n   bool zero = false; n   for (i = n - 1; i >= 0; i--) { n     if (s[i] ==  0  && zero && fstone < i) es[i] = true; n     if (s[i] ==  1  && zero) es[i] = true; n     if (s[i] ==  0 ) zero = true; n   } n   ans =   ; n   for (i = 0; i < n; i++) n     if (!es[i]) ans += s[i]; n   cout << ans << endl; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int t; n   int i; n   cin >> t; n   for (i = 1; i <= t; i++) wk(); n   return 0; n } n


#include <bits/stdc++.h> n const char nl =   n ; n const int mod = (int)1e9 + 7; n int main() { n   std::cin.tie(0)->std::ios::sync_with_stdio(0); n   std::cin.exceptions(std::cin.failbit); n   int t; n   std::cin >> t; n   while (t--) { n     int n; n     std::string s; n     std::cin >> n >> s; n     int l = -1, r = -1; n     for (int i = 0; i < n - 1; i++) { n       if ((s[i] ==  a  && s[i + 1] ==  b ) || n           (s[i] ==  b  && s[i + 1] ==  a )) { n         l = i + 1; n         r = i + 2; n         break; n       } n     } n     std::cout << l <<     << r << nl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const bool DEBUG = false; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   bool puede = true; n   int N, M; n   cin >> N >> M; n   unordered_set<int> conj; n   vector<string> cad(N); n   vector<int> index(M); n   for (int i = 0; i < N; i++) { n     cin >> cad[i]; n     conj.insert(i); n   } n   for (int i = 0; i < M; i++) { n     cin >> index[i]; n     index[i]--; n     conj.erase(index[i]); n   } n   for (int i = 0; i < M - 1; i++) { n     if (cad[index[i]].size() != cad[index[i + 1]].size()) puede = false; n   } n   if (!puede) { n     cout <<  No n ; n     return 0; n   } n   bool band; n   string patron =   ; n   int sz = cad[index[0]].size(); n   if (DEBUG) { n     cout << cad[index[0]] << endl; n     cout <<  SZ:   << sz << endl; n   } n   for (int i = 0; i < sz; i++) { n     band = true; n     for (int j = 0; j < M - 1; j++) { n       if (cad[index[j]][i] != cad[index[j + 1]][i]) { n         patron +=  ? ; n         band = false; n       } n       if (!band) break; n     } n     if (band) patron += cad[index[0]][i]; n   } n   for (auto &it : conj) { n     band = true; n     if (cad[it].size() != patron.size()) continue; n     for (int i = 0; i < patron.size(); i++) { n       if (patron[i] ==  ? ) continue; n       if (patron[i] == cad[it][i]) continue; n       band = false; n       break; n     } n     if (band) { n       cout <<  No n ; n       return 0; n     } n   } n   cout <<  Yes n  << patron <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   cin >> t; n   while (t--) { n     int n; n     cin >> n; n     vector<string> v(n); n     for (int i = 0; i < n; i++) { n       cin >> v[i]; n     } n     int a[26] = {0}; n     for (auto s : v) { n       for (auto i : s) { n         a[i -  a ]++; n       } n     } n     int f = 0; n     for (int i = 0; i < 26; i++) { n       if (a[i] % n) { n         f = 1; n         break; n       } n     } n     if (f) { n       cout <<  NO  << endl; n     } else { n       cout <<  YES  << endl; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n vector<long long> V[100005]; n long long n; n map<long long, long long> DP[100005]; n long long concatHash(long long x, long long y) { n   return (x * 100005 + y) % 1000000007; n } n void answer(long long x) { n   cout << x; n   exit(0); n } n void fail() { n   cout << -1; n   exit(0); n } n void prec(long long x, long long f) { n   if (V[x].size() == 1 && f) { n     DP[x][f] = 1; n     return; n   } n   unordered_set<long long> S; n   for (auto i : V[x]) { n     if (i != f) { n       prec(i, x); n       if (DP[i][x] == -1) DP[x][f] = -1; n       S.insert(DP[i][x]); n     } n   } n   if (DP[x][f] == -1) return; n   if (S.size() == 1) { n     long long chash = *(S.begin()); n     DP[x][f] = concatHash(chash, V[x].size()); n   } else n     DP[x][f] = -1; n } n void DFS(long long x, long long f, long long phash) { n   if (V[x].size() == 1 && f) { n     if (phash != -1) { n       answer(x); n     } n     return; n   } n   unordered_map<long long, long long> S; n   for (auto i : V[x]) n     if (i != f) S[DP[i][x]]++; n   if (f) S[phash]++; n   if (S.size() == 0) { n     assert(false); n     return; n   } n   if (S.size() == 1 && S.begin()->first != -1) { n     answer(x); n   } n   if (S.size() == 1 && S.begin()->first == -1) { n     if (S.begin()->second != 1) return; n     for (auto i : V[x]) { n       if (DP[i][x] == -1) { n         if (f) n           DFS(i, x, concatHash(phash, V[x].size())); n         else n           DFS(i, x, V[x].size()); n         return; n       } n     } n   } n   if (S.size() >= 3) { n     return; n   } n   auto it = S.begin(); n   auto a = make_pair(it->first, it->second); n   it++; n   auto b = make_pair(it->first, it->second); n   for (auto i : V[x]) { n     if (i != f && (DP[i][x] == a.first && a.second == 1 && b.first != -1)) { n       DFS(i, x, concatHash(b.first, V[x].size())); n     } n     if (i != f && (DP[i][x] == b.first && b.second == 1 && a.first != -1)) { n       DFS(i, x, concatHash(a.first, V[x].size())); n     } n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   cin >> n; n   if (n == 1) { n     answer(1); n   } n   for (long long i = 1; i < n; i++) { n     long long x, y; n     cin >> x >> y; n     V[x].push_back(y); n     V[y].push_back(x); n   } n   prec(1, 0); n   DFS(1, 0, -1); n   cout << -1; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 1e5 + 10; n const double pi = acos(-1.0); n const long long mod = 1e9 + 7; n int n, k; n int a[MAXN], b[MAXN], z[MAXN], f[MAXN]; n void solve() { n   scanf( %d %d , &n, &k); n   int t = 0; n   for (int i = 1; i <= n; i++) { n     scanf( %d , &a[i]); n     if (a[i] < k) n       b[i] = 0; n     else if (a[i] == k) { n       b[i] = 1; n       t = 1; n     } else n       b[i] = 2; n   } n   int flag = 0, last = -10; n   for (int i = 1; i <= n; i++) { n     int cnt = 0; n     for (int j = 0; j < 3; j++) n       if (b[i + j] >= 1) cnt++; n     if (cnt > 1) flag = 1; n   } n   if ((flag && t) || (n == 1 && a[1] == k)) n     puts( yes ); n   else n     puts( no ); n   for (int i = 1; i <= n; i++) b[i] = 0; n } n int main() { n   int T = 1; n   scanf( %d , &T); n   while (T--) solve(); n } n


#include <bits/stdc++.h> n using namespace std; n const long long INF = 1000000000 + 7; n const double esp = 1e-13; n struct node { n   int x, y; n   bool operator<(const node &op) const { n     return op.x > x || (op.x == x && op.y > y); n   } n } a[2000 + 10]; n int h, w, n; n long long res[2000 + 10], gt[200000 + 10], rev[200000 + 10]; n long long power(long long a, long long n) { n   long long ans = 1; n   while (n) { n     if (n % 2) ans = ans * a % INF; n     a = a * a % INF; n     n /= 2; n   } n   return ans; n } n long long C(int n, int k) { return gt[n] * rev[k] % INF * rev[n - k] % INF; } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(); n   cin >> h >> w >> n; n   for (long long i = 1; i <= n; i++) cin >> a[i].x >> a[i].y; n   a[++n] = {h, w}; n   sort(a + 1, a + n + 1); n   gt[0] = 1; n   rev[0] = power(1, INF - 2); n   for (long long i = 1; i <= 200000; i++) { n     gt[i] = gt[i - 1] * i % INF; n     rev[i] = power(gt[i], INF - 2); n   } n   for (long long i = 1; i <= n; i++) { n     res[i] = C(a[i].x + a[i].y - 2, a[i].x - 1); n     for (long long j = 1; j <= i - 1; j++) n       if (a[i].x >= a[j].x && a[i].y >= a[j].y) { n         res[i] -= res[j] * n                   C(a[i].x - a[j].x + a[i].y - a[j].y, a[i].x - a[j].x) % INF; n         if (res[i] < 0) res[i] += INF; n       } n   } n   cout << res[n]; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   pair<int, int> p[100000]; n   int n, ans = 0, a, k, c = 0, i; n   scanf( %d %d , &n, &k); n   for (i = 0; i < n; i++) scanf( %d , &a), p[i] = make_pair(a, i); n   sort(p, p + n); n   for (i = 0; i < n; i++) { n     if ((p[i].first + ans) <= k) c++, ans += p[i].first; n   } n   printf( %d n , c); n   for (i = 0; i < c; i++) printf( %d  , p[i].second + 1); n } n


#include <bits/stdc++.h> n using namespace std; n using Long = long long; n constexpr Long MOD = 998244353; n template <typename T> n using V = vector<T>; n template <typename T> n using Vv = V<V<T>>; n using Vb = V<bool>; n using Vvb = V<Vb>; n using Vi = V<int>; n using Vvi = V<Vi>; n using Vl = V<Long>; n using Vvl = V<Vl>; n using Vd = V<double>; n using Vvd = V<Vd>; n using Vs = V<string>; n template <typename First, typename Second> n istream& operator>>(istream& is, pair<First, Second>& v); n template <typename T> n istream& operator>>(istream& is, vector<T>& v) { n   for (auto& x : v) { n     is >> x; n   } n   return is; n } n template <typename First, typename Second> n istream& operator>>(istream& is, pair<First, Second>& v) { n   is >> v.first >> v.second; n   return is; n } n template <typename T> n ostream& operator<<(ostream& os, const vector<T>& v) { n   for (const auto& x : v) { n     os << x <<    ; n   } n   return os; n } n void solve() { n   Vvi divisors(100001); n   for (int d = 1; d <= 100000; ++d) { n     for (int k = 1; d * k <= 100000; ++k) { n       divisors[d * k].push_back(d); n     } n   } n   int bitcount[] = {0, 1, 1, 2, 1, 2, 2, 3}; n   int t; n   cin >> t; n   for (int i = 0; i < t; ++i) { n     int num[3]; n     Vi* d[3]; n     int n[3]; n     for (int j = 0; j < 3; ++j) { n       cin >> num[j]; n       d[j] = &divisors[num[j]]; n       n[j] = d[j]->size(); n     } n     int p[3] = {}; n     int counts[1 << 3] = {}; n     while (p[0] < n[0] || p[1] < n[1] || p[2] < n[2]) { n       int v[3]; n       for (int j = 0; j < 3; ++j) { n         v[j] = p[j] < n[j] ? (*d[j])[p[j]] : 100001; n       } n       int m = min({v[0], v[1], v[2]}); n       int set = 0; n       for (int j = 0; j < 3; ++j) { n         if (v[j] == m) { n           set |= 1 << j; n           p[j]++; n         } n       } n       counts[set]++; n     } n     Long ans = 0; n     for (int x = 1; x < (1 << 3); ++x) { n       for (int y = x; y < (1 << 3); ++y) { n         for (int z = y; z < (1 << 3); ++z) { n           if ((x | y | z) == (1 << 3) - 1) { n             Long r = 0; n             if (x != y && y != z && x != z) { n               ans += (Long)counts[x] * counts[y] * counts[z]; n             } else if (x == y && y == z) { n               int c = counts[x]; n               r = c * (c + 1LL) * (c + 2LL) / (2 * 3); n             } else if (x == y) { n               if (bitcount[x] > 1) { n                 int c = counts[x]; n                 r = (c * (c + 1LL) / 2) * counts[z]; n               } n             } else if (x == z) { n               if (bitcount[x] > 1) { n                 int c = counts[x]; n                 r = (c * (c + 1LL) / 2) * counts[y]; n               } n             } else if (y == z) { n               if (bitcount[y] > 1) { n                 int c = counts[y]; n                 r = (c * (c + 1LL) / 2) * counts[x]; n               } n             } else { n               throw exception{}; n             } n             ans += r; n           } n         } n       } n     } n     cout << ans <<   n ; n   } n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(nullptr); n   cout.tie(nullptr); n   cout.precision(10); n   cout << fixed; n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = (1 << 20) + 1000; n const int INF = 1000000000; n const int Mod = 1000000007; n void update(int tree[], int k, int v) { n   while (k < N) { n     tree[k] += v; n     k += k & (-k); n   } n } n int get(int tree[], int k) { n   int ret = 0; n   while (k) { n     ret += tree[k]; n     k -= k & (-k); n   } n   return ret; n } n int a[N], n, tot, r[N], mp[N], tree[N]; n long long dp[30], sum[30], f[30]; n bool cmpr(int i, int j) { return a[i] < a[j]; } n int Hash() { n   for (int i = 0; i < tot; i++) r[i] = i; n   sort(r, r + tot, cmpr); n   int K = 1; n   mp[1] = a[r[0]]; n   for (int i = 0; i < tot; i++) { n     if (mp[K] != a[r[i]]) mp[++K] = a[r[i]]; n     a[r[i]] = K; n   } n   return K; n } n int main() { n   scanf( %d , &n); n   tot = 1 << n; n   for (int i = 0; i < tot; i++) scanf( %d , &a[i]); n   int fuck = Hash(); n   for (int i = 1; i <= n; i++) { n     dp[i] += dp[i - 1]; n     sum[i] += sum[i - 1]; n     int len = 1 << (i - 1); n     for (int j = tot / len - 2; j >= 0; j -= 2) { n       for (int k = 0; k < len; k++) update(tree, a[(j + 1) * len + k], 1); n       for (int k = 0; k < len; k++) { n         int tmp = get(tree, a[j * len + k] - 1); n         sum[i] += tmp; n         dp[i] += tmp; n       } n       for (int k = 0; k < len; k++) update(tree, a[(j + 1) * len + k], -1); n       for (int k = 0; k < len; k++) update(tree, a[j * len + k], 1); n       for (int k = 0; k < len; k++) { n         sum[i] += get(tree, a[(j + 1) * len + k] - 1); n       } n       for (int k = 0; k < len; k++) update(tree, a[j * len + k], -1); n     } n   } n   int m; n   scanf( %d , &m); n   while (m--) { n     int x; n     scanf( %d , &x); n     long long t1 = dp[x], t2 = sum[x] - dp[x]; n     f[0] = 0; n     for (int i = 1; i < x; i++) { n       f[i] = dp[i]; n       dp[i] = sum[i] - dp[i]; n     } n     for (int i = x; i <= n; i++) { n       dp[i] = dp[i] - t1 + t2; n     } n     printf( %I64d n , dp[n]); n   } n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC target( avx2 ) n #pragma GCC optimize( O3 ) n #pragma GCC optimize( unroll-loops ) n using namespace std; n vector<long long int> edges[500010]; n long long int c[500010], cc[500010], color[500010], bip[500010]; n long long int dfs(long long int u, long long int co, long long int j) { n   color[u] = co; n   cc[u] = j; n   for (auto v : edges[u]) { n     if (c[v] != c[u]) continue; n     if (color[v] == color[u]) return false; n     if (color[v] != 0) continue; n     if (!dfs(v, 3 - co, j)) return false; n   } n   return true; n } n map<pair<long long int, long long int>, n     vector<pair<long long int, long long int>>> n     es; n map<long long int, vector<pair<long long int, long long int>>> gr; n map<long long int, long long int> flip; n long long int dfs2(long long int u, long long int f) { n   flip[u] = f; n   for (auto e : gr[u]) { n     long long int v = e.first; n     if (e.second == 0) { n       if (flip.count(v) && flip[v] != flip[u]) return false; n       if (flip.count(v) == 0) { n         if (!dfs2(v, f)) return false; n       } n     } n     if (e.second == 1) { n       if (flip.count(v) && flip[v] == flip[u]) return false; n       if (flip.count(v) == 0) { n         if (!dfs2(v, !f)) return false; n       } n     } n   } n   return true; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   long long int n, m, k; n   cin >> n >> m >> k; n   for (long long int i = 1; i <= n; ++i) cin >> c[i]; n   for (long long int i = 0; i < m; ++i) { n     long long int a, b; n     cin >> a >> b; n     edges[a].push_back(b); n     edges[b].push_back(a); n     if (c[a] != c[b]) { n       long long int mi = min(c[a], c[b]); n       long long int ma = max(c[a], c[b]); n       es[{mi, ma}].push_back({a, b}); n     } n   } n   for (long long int i = 1; i <= k; ++i) bip[i] = 1; n   for (long long int i = 1; i <= n; ++i) { n     if (!color[i]) { n       if (!dfs(i, 1, i)) bip[c[i]] = 0; n     } n   } n   long long int nb = accumulate(bip, bip + k + 1, 0ll); n   set<pair<long long int, long long int>> bad; n   for (auto pp : es) { n     long long int c1 = pp.first.first; n     long long int c2 = pp.first.second; n     if ((!bip[c1]) || (!bip[c2])) continue; n     gr.clear(); n     flip.clear(); n     set<long long int> rc; n     for (auto e : pp.second) { n       if (color[e.first] == color[e.second]) n         gr[cc[e.first]].push_back({cc[e.second], 1}); n       if (color[e.first] != color[e.second]) n         gr[cc[e.first]].push_back({cc[e.second], 0}); n       if (color[e.first] == color[e.second]) n         gr[cc[e.second]].push_back({cc[e.first], 1}); n       if (color[e.first] != color[e.second]) n         gr[cc[e.second]].push_back({cc[e.first], 0}); n       rc.insert(cc[e.first]); n       rc.insert(cc[e.second]); n     } n     for (auto i : rc) { n       if (!flip.count(i)) { n         if (!dfs2(i, 0)) bad.insert(pp.first); n       } n     } n   } n   cout << nb * (nb - 1) / 2 - bad.size() << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 3e5 + 2, M = 6e5 + 2, O = 1.2e6 + 2; n long long len1[M], len2[M], v[N], g[N][4], ans[M]; n long long lx, ly; n int lj[M], nxt[M], fir[N], f[N], qlj[O], qnxt[O], qfir[N], xw[O][3]; n int flj[M], fnxt[M], ffir[N]; n int n, q, i, x, y, c, bs, qs, fs; n bool ed[N]; n inline void read(int &x) { n   c = getchar(); n   while ((c < 48) || (c > 57)) c = getchar(); n   x = c ^ 48; n   c = getchar(); n   while ((c >= 48) && (c <= 57)) { n     x = x * 10 + (c ^ 48); n     c = getchar(); n   } n } n inline void read(long long &x) { n   c = getchar(); n   while ((c < 48) || (c > 57)) c = getchar(); n   x = c ^ 48; n   c = getchar(); n   while ((c >= 48) && (c <= 57)) { n     x = x * 10 + (c ^ 48); n     c = getchar(); n   } n } n inline void add() { n   lj[++bs] = y; n   len1[bs] = lx; n   len2[bs] = ly; n   nxt[bs] = fir[x]; n   fir[x] = bs; n   lj[++bs] = x; n   len1[bs] = lx; n   len2[bs] = ly; n   nxt[bs] = fir[y]; n   fir[y] = bs; n } n inline void fadd(int x, int y) { n   flj[++fs] = y; n   fnxt[fs] = ffir[x]; n   ffir[x] = fs; n } n inline void qadd(int x, int y, int i) { n   qlj[++qs] = i; n   qnxt[qs] = qfir[x]; n   qfir[x] = qs; n } n void dfs1(int x) { n   ed[x] = 1; n   for (int i = fir[x]; i; i = nxt[i]) n     if (!ed[lj[i]]) { n       dfs1(lj[i]); n       v[x] = min(v[x], v[lj[i]] + len1[i] + len2[i]); n     } n   ed[x] = 0; n } n void dfs2(int x) { n   ed[x] = 1; n   for (int i = fir[x]; i; i = nxt[i]) n     if (!ed[lj[i]]) { n       v[lj[i]] = min(v[lj[i]], v[x] + len1[i] + len2[i]); n       dfs2(lj[i]); n     } n   ed[x] = 0; n } n void dfs3(int x) { n   ed[x] = 1; n   for (int i = fir[x]; i; i = nxt[i]) n     if (!ed[lj[i]]) { n       g[lj[i]][0] = min(len2[i], v[x] + v[lj[i]] + len1[i]); n       g[lj[i]][1] = min(len2[i] + v[lj[i]], len1[i] + v[x]); n       g[lj[i]][2] = min(len1[i] + v[lj[i]], len2[i] + v[x]); n       g[lj[i]][3] = min(len1[i], v[x] + v[lj[i]] + len2[i]); n       dfs3(lj[i]); n     } n   ed[x] = 0; n } n void getf(register int x) { n   if (f[f[x]] == f[x]) return; n   getf(f[x]); n   g[0][0] = min(g[x][0] + g[f[x]][0], g[x][2] + g[f[x]][1]); n   g[0][1] = min(g[x][1] + g[f[x]][0], g[x][3] + g[f[x]][1]); n   g[0][2] = min(g[x][0] + g[f[x]][2], g[x][2] + g[f[x]][3]); n   g[0][3] = min(g[x][1] + g[f[x]][2], g[x][3] + g[f[x]][3]); n   memcpy(g[x], g[0], 32); n   f[x] = f[f[x]]; n } n void dfs4(int x) { n   ed[x] = 1; n   int i; n   for (i = qfir[x]; i; i = qnxt[i]) n     if (ed[y = xw[qlj[i]][2]]) { n       getf(y); n       fadd(f[y], qlj[i]); n     } n   for (i = fir[x]; i; i = nxt[i]) n     if (!ed[lj[i]]) { n       dfs4(lj[i]); n       f[lj[i]] = x; n     } n   for (i = ffir[x]; i; i = fnxt[i]) { n     y = flj[i]; n     if (y > q) n       c = y - q; n     else n       c = y; n     if (xw[y][2] != x) { n       qs = xw[y][0] >> 1 & 1; n       bs = xw[y][0] & 1; n       getf(xw[y][1]); n       getf(xw[y][2]); n       ans[c] = min(g[xw[y][1]][bs] + g[xw[y][2]][qs], n                    g[xw[y][1]][bs | 2] + g[xw[y][2]][qs | 2]); n     } else { n       getf(xw[y][1]); n       ans[c] = g[xw[y][1]][xw[y][0]]; n     } n   } n } n int main() { n   read(n); n   for (i = 1; i <= n; i++) read(v[i]); n   for (i = 1; i < n; i++) { n     read(x); n     read(y); n     read(lx); n     read(ly); n     add(); n     f[i] = i; n   } n   dfs1(1); n   dfs2(1); n   dfs3(1); n   read(q); n   for (i = 1; i <= q; i++) { n     read(x); n     read(y); n     if (x + 1 >> 1 == y + 1 >> 1) { n       if (x != y) ans[i] = v[x + 1 >> 1]; n       continue; n     } n     xw[i][0] = (x & 1) | (y & 1) << 1; n     xw[i + q][0] = (y & 1) | (x & 1) << 1; n     qadd(xw[i][1] = xw[i + q][2] = x = x + 1 >> 1, n          xw[i][2] = xw[i + q][1] = y = y + 1 >> 1, i); n     qadd(y, x, i + q); n   } n   dfs4(1); n   for (i = 1; i <= q; i++) printf( %lld n , ans[i]); n } n


#include <bits/stdc++.h> n using namespace std; n string winner; n int score; n int calc(int Suc, int Fal, int A, int B, int C, int D, int E) { n   int ret = A + B + C + D + E; n   ret += Suc * 100; n   ret -= Fal * 50; n   return ret; n } n int main() { n   int n; n   while (cin >> n) { n     score = -100000000; n     for (int i = 1; i <= n; i++) { n       string name; n       int Suc, Fal, A, B, C, D, E; n       cin >> name >> Suc >> Fal >> A >> B >> C >> D >> E; n       int s = calc(Suc, Fal, A, B, C, D, E); n       if (s > score) winner = name, score = s; n     } n     cout << winner << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int gcd(int a, int b) { return a % b == 0 ? b : gcd(b, a % b); } n int main() { n   int n; n   scanf( %d , &n); n   if (n % 2) n     printf( %d %d n , n / 2, n / 2 + 1); n   else { n     for (int a = n / 2 - 1; a; a--) { n       if (gcd(a, n - a) == 1) { n         printf( %d %d n , a, n - a); n         break; n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   int r, c; n   scanf( %d %d , &r, &c); n   bool banR[1000] = {false}; n   bool banC[1000] = {false}; n   char map[100][100]; n   for (int i = 0; i < r; i++) { n     scanf( %s , map[i]); n   } n   for (int i = 0; i < r; i++) { n     for (int j = 0; j < c; j++) { n       if (map[i][j] ==  S ) { n         banR[i] = true; n         banC[j] = true; n       } n     } n   } n   int minus = 0; n   int ans = 0; n   for (int i = 0; i < r; i++) { n     if (banR[i] == false) { n       ans += c; n       minus++; n     } n   } n   for (int i = 0; i < c; i++) { n     if (banC[i] == false && minus <= r) { n       ans += (r - minus); n     } n   } n   printf( %d , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> v[10]; n int n, ans, m, tmp; n vector<int> v2; n void recur(int now) { n   if (now == n) { n     int vis[7][7]; n     memset(vis, 0, sizeof(vis)); n     int ans2 = 0; n     for (int e = 1; e <= n; e++) { n       for (int p = 0; p < v[e].size(); p++) { n         int next = v[e][p]; n         int f = v2[e - 1], s = v2[next - 1]; n         if (f > s) swap(f, s); n         if (vis[f][s] == 0) { n           vis[f][s] = 1; n           ans2++; n         } n       } n     } n     ans = max(ans, ans2); n   } else { n     for (int p = 1; p <= min(n, 6); p++) { n       v2.push_back(p); n       recur(now + 1); n       v2.pop_back(); n     } n   } n } n int main(void) { n   scanf( %d%d , &n, &m); n   for (int e = 0; e < m; e++) { n     int a, b; n     scanf( %d%d , &a, &b); n     v[a].push_back(b); n     v[b].push_back(a); n   } n   recur(0); n   printf( %d , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   string s1, s2; n   cin >> s1 >> s2; n   int ans = 0; n   int start = 0; n   int end = n - 1; n   while (s1[start] == s2[start]) start++; n   while (s1[end] == s2[end]) end--; n   if (s1.substr(start, end - start) == s2.substr(start + 1, end - start)) ans++; n   if (s2.substr(start, end - start) == s1.substr(start + 1, end - start)) ans++; n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long t1, t2, x1, x2, t0, y1, y2; n   cin >> t1 >> t2 >> x1 >> x2 >> t0; n   if (t1 == t2) n     cout << x1 <<     << x2 << endl; n   else if (t1 == t0) n     cout << x1 <<     << 0 << endl; n   else if (t2 == t0) n     cout << 0 <<     << x2 << endl; n   else { n     y1 = 0; n     y2 = x2; n     long double min_diff = t2 - t0; n     for (long long i = 1; i <= x1; i++) { n       long long j = ((t0 - t1) * i + (t2 - t0 - 1)) / (t2 - t0); n       if (j > x2) continue; n       long double temp = (t1 * i + t2 * j + 0.0) / (i + j + 0.0); n       long double diff = temp - t0; n       if (min_diff > diff) { n         min_diff = diff; n         y1 = i; n         y2 = j; n       } else if (min_diff == diff && i + j > y1 + y2) { n         y1 = i; n         y2 = j; n       } n     } n     cout << y1 <<     << y2 << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void sortLU(long long a[], long long n, long long b[]) { n   long long i, j; n   for (i = 0; i < n; i++) { n     for (j = 0; j < n; j++) { n       if (a[i] < a[j]) { n         swap(a[i], a[j]); n         swap(b[i], b[j]); n       } n     } n   } n } n int main() { n   long long p; n   cin >> p; n   long long a, s = 0, i; n   for (i = 0; i < p; i++) { n     cin >> a; n     s += a; n   } n   long long n; n   cin >> n; n   long long x[n], y[n]; n   for (i = 0; i < n; i++) { n     cin >> x[i] >> y[i]; n   } n   for (i = 0; i < n; i++) { n     if (s <= max(x[i], y[i])) { n       if (s <= min(x[i], y[i])) { n         cout << min(x[i], y[i]) << endl; n         return 0; n       } else { n         cout << s << endl; n         return 0; n       } n     } n   } n   cout <<  -1  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MOD = 1000000007; n inline void add(int &a, int b, int md = MOD) { n   a += b; n   if (a >= md) { n     a -= md; n   } n } n inline int mul(int a, int b, int md = MOD) { return (long long)a * b % md; } n inline int power(int a, int b, int md = MOD) { n   int res = 1; n   while (b > 0) { n     if (b & 1) { n       res = mul(res, a, md); n     } n     a = mul(a, a, md); n     b >>= 1; n   } n   return res; n } n inline int inv(int x) { return power(x, MOD - 2); } n struct node { n   int value; n   int len; n }; n node seq(int n7, int n6, int k) { n   int p10k = power(10, k); n   int t = mul(p10k, 10); n   int e = n6 - power(10, k, MOD - 1) + 1; n   if (e < 0) { n     e += MOD - 1; n   } n   int it1 = inv(t - 1); n   int sum = mul(power(t, e) + MOD - 1, it1); n   int z = mul(p10k, sum); n   int res = z; n   int cnt = n7 - p10k + 1; n   if (cnt < 0) { n     cnt += MOD; n   } n   add(res, mul(sum - cnt + MOD, it1)); n   return {res, mul(e, k + 1, MOD - 1)}; n } n node concat(node a, node b) { n   int value = mul(a.value, power(10, b.len)); n   add(value, b.value); n   return {value, (a.len + b.len) % (MOD - 1)}; n } n node multi(node a, int b) { n   if (b == 1) { n     return a; n   } n   if (b % 2 == 1) { n     return concat(multi(a, b - 1), a); n   } n   node z = multi(a, b / 2); n   return concat(z, z); n } n const int N = 100010; n node prec[N]; n node big_seq(int n7, int n6, int k) { n   node res = seq(n7, n6, k - 1); n   for (int i = k - 2; i >= 0; i--) { n     res = concat(prec[i], res); n   } n   return res; n } n char s[N]; n int pos; n node solve_exp() { n   int start = pos; n   int v7 = 0; n   int v6 = 0; n   while ( 0  <= s[pos] && s[pos] <=  9 ) { n     v7 = mul(v7, 10); n     add(v7, s[pos] -  0 ); n     v6 = mul(v6, 10, MOD - 1); n     add(v6, s[pos] -  0 , MOD - 1); n     pos++; n   } n   int len_v = pos - start; n   if (s[pos] ==  + ) { n     pos++; n     return concat({v7, len_v}, solve_exp()); n   } n   if (s[pos] ==  - ) { n     pos++; n     int start2 = pos, w7 = 0, w6 = 0; n     while ( 0  <= s[pos] && s[pos] <=  9 ) { n       w7 = mul(w7, 10); n       add(w7, s[pos] -  0 ); n       w6 = mul(w6, 10, MOD - 1); n       add(w6, s[pos] -  0 , MOD - 1); n       pos++; n     } n     int len_w = pos - start2; n     add(v7, MOD - 1); n     add(v6, (MOD - 1) - 1, MOD - 1); n     node v = big_seq(v7, v6, len_v); n     node w = big_seq(w7, w6, len_w); n     int diff = w.len - v.len; n     if (diff < 0) { n       diff += MOD - 1; n     } n     int real_value = w.value; n     add(real_value, MOD - mul(v.value, power(10, diff))); n     int real_len = w.len; n     add(real_len, (MOD - 1) - v.len, MOD - 1); n     if (s[pos] ==  + ) { n       pos++; n       return concat({real_value, real_len}, solve_exp()); n     } n     return {real_value, real_len}; n   } n   if (s[pos] ==  ( ) { n     int finish = pos; n     pos++; n     node z = solve_exp(); n     node res = {0, 0}; n     for (int i = start; i < finish; i++) { n       res = multi(res, 10); n       if (s[i] !=  0 ) { n         res = concat(res, multi(z, s[i] -  0 )); n       } n     } n     pos++; n     if (s[pos] ==  + ) { n       pos++; n       return concat(res, solve_exp()); n     } n     return res; n   } n   return {v7, len_v}; n } n int main() { n   int v7 = 0; n   int v6 = 0; n   for (int k = 0; k < N; k++) { n     v7 = mul(v7, 10); n     add(v7, 9); n     v6 = mul(v6, 10, MOD - 1); n     add(v6, 9, MOD - 1); n     prec[k] = seq(v7, v6, k); n   } n   scanf( %s , s); n   pos = 0; n   node res = solve_exp(); n   printf( %d n , res.value); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e7 + 10; n const long long MOD = (long long)(1e9) + (long long)(7); n const long double INF = 1e17; n long long dp[505][505][12]; n long long edge[505][505][4]; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   long long n; n   cin >> n; n   vector<long long> v(n); n   map<long long, long long> cnt; n   for (auto &it : v) { n     cin >> it; n     cnt[it]++; n   } n   sort(v.begin(), v.end()); n   reverse(v.begin(), v.end()); n   if (n < 4) n     cout << 0; n   else { n     for (int i = 0; i < n; i++) { n       if (cnt[v[i]] % 2 == 1) { n         cnt[v[i]]--; n         cnt[v[i] - 1]++; n       } n     } n     long long ans = 0; n     bool form = true; n     long long store = 0; n     for (long long i = 0; i < n; i++) { n       long long l = v[i]; n       while (cnt[l] >= 2) { n         if (form == true) { n           form = false; n           store = l; n           cnt[l] -= 2; n         } else { n           form = true; n           ans += store * l; n           store = 0; n           cnt[l] -= 2; n         } n       } n     } n     cout << ans; n   } n } n