#include <bits/stdc++.h> n using namespace std; n template <class T> n inline T sqr(T x) { n   return x * x; n } n const double EPS = 1e-6; n const int INF = 0x3fffffff; n const long long LINF = INF * 1ll * INF; n const double PI = acos(-1.0); n using namespace std; n char g[505][505]; n int cnt[505]; n int dp[2][505][505]; n int C[505][505]; n int mod; n void Add(int &ans, int v) { n   ans += v; n   if (ans >= mod) ans -= mod; n } n int main(void) { n   int n, m; n   scanf( %d %d %d , &n, &m, &mod); n   C[0][0] = 1; n   for (int i = 1; i <= n; i++) { n     C[i][0] = 1; n     for (int j = 1; j <= i; j++) n       C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % mod; n   } n   for (int i = 0; i < (m); ++i) { n     scanf( %s , g[i]); n     for (int j = 0; j < (n); ++j) cnt[j] += g[i][j] -  0 ; n   } n   int cnt0 = 0, cnt1 = 0; n   for (int i = 0; i < (n); ++i) { n     if (cnt[i] > 2) { n       puts( 0 ); n       return 0; n     } n     if (cnt[i] == 1) n       cnt1++; n     else if (cnt[i] == 0) n       cnt0++; n   } n   int now = 0; n   dp[now][cnt0][cnt1] = 1; n   for (int i = m; i < n; i++) { n     memset(dp[now ^ 1], 0, sizeof(dp[now ^ 1])); n     for (int j = 0; j <= n; j++) { n       for (int k = 0; k + j <= n; k++) { n         if (dp[now][j][k] == 0) continue; n         if (j >= 2) n           Add(dp[now ^ 1][j - 2][k + 2], 1ll * C[j][2] * dp[now][j][k] % mod); n         if (k >= 2) n           Add(dp[now ^ 1][j][k - 2], 1ll * C[k][2] * dp[now][j][k] % mod); n         if (j && k) n           Add(dp[now ^ 1][j - 1][k], n               1ll * C[k][1] * C[j][1] % mod * dp[now][j][k] % mod); n       } n     } n     now ^= 1; n   } n   printf( %d n , dp[now][0][0]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 21; n const long long MOD = 1000000007; n int n; n long long m; n long long C[MAXN][MAXN]; n long long g[MAXN], s[MAXN], ten[MAXN], eight[MAXN]; n inline void update(long long& x, long long y) { y %= MOD, x += y, x %= MOD; } n inline long long P(const long long& x, int y) { n   if (x < y) return 0; n   long long res = 1; n   for (long long i = x; i >= x - y + 1; --i) res = (res * i) % MOD; n   return res; n } n inline pair<int, int> get(long long num, int x) { n   int res4 = 0, res7 = 0; n   for (int i = 1; i <= x; ++i) num /= 10; n   for (long long i = num; i > 0; i /= 10) n     if (i % 10 == 4) n       res4++; n     else if (i % 10 == 7) n       res7++; n   return pair<int, int>(res4, res7); n } n inline long long F(const long long& num, int x, int a, int b) { n   pair<int, int> p = get(num, x); n   a -= p.first, b -= p.second; n   if (a < 0 || b < 0 || a + b > x) return 0; n   return (((C[x][a] * C[x - a][b]) % MOD) * eight[x - a - b]) % MOD; n } n inline long long G(long long num, int x, int a, int b) { n   long long res = 0; n   for (; num + ten[x] <= m; num += ten[x]) update(res, F(num, x, a, b)); n   if (x > 0) { n     if (num <= m) update(res, G(num, x - 1, a, b)); n   } else n     update(res, F(num, x, a, b)); n   return res; n } n inline void preProcess() { n   ten[0] = eight[0] = 1; n   for (int i = 1; i < MAXN; ++i) n     ten[i] = ten[i - 1] * 10, eight[i] = eight[i - 1] * 8; n   while (ten[n] <= m) n++; n   C[0][0] = 1; n   for (int i = 1; i < MAXN; ++i) { n     C[i][0] = C[i][i] = 1; n     for (int j = 1; j < i; ++j) C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % MOD; n   } n   for (int i = 0; i <= n; ++i) n     for (int j = 0; j <= i; ++j) update(g[i], G(0, n - 1, j, i - j)); n   g[0]--; n } n inline long long dp(int s, int x, int y, int z) { n   if (y < 0 || z < 0) return 0; n   if (x == s) return (y == 0) ? 1 : 0; n   long long res = 0; n   for (int i = 0; i <= y; ++i) { n     long long k = (C[y][i] * P(g[x], i)) % MOD; n     update(res, k * dp(s, x + 1, y - i, z - i * x)); n   } n   return res; n } n int main() { n   scanf( %I64d n , &m); n   preProcess(); n   long long res = 0; n   for (int s = 1; s <= n; ++s) update(res, g[s] * dp(s, 0, 6, s - 1)); n   printf( %I64d n , res); n   fclose(stdin); n   fclose(stdout); n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize(3) n using namespace std; n const int Mod = 1e9 + 7; n const int N = 5e5 + 100; n const int INF = 0x3f3f3f3f; n const long long LINF = 0x3f3f3f3f3f3f3f3f; n inline long long dpow(long long a, long long b) { n   long long r = 1, t = a; n   while (b) { n     if (b & 1) r = (r * t) % Mod; n     b >>= 1; n     t = (t * t) % Mod; n   } n   return r; n } n inline long long fpow(long long a, long long b) { n   long long r = 1, t = a; n   while (b) { n     if (b & 1) r = (r * t); n     b >>= 1; n     t = (t * t); n   } n   return r; n } n struct node { n   int id, w; n   bool operator<(const node &oth) const { return w > oth.w; } n }; n struct Ask { n   int op, x; n } qi[N]; n pair<int, int> eg[N]; n set<node> s[N]; n int fa[N], sz[N], n, m, q; n int a[N]; n bool vis[N]; n stack<pair<int, int> > st; n void Init() { n   for (int i = 1; i <= n; i++) fa[i] = i, sz[i] = 1; n } n int Find(int x) { n   while (x != fa[x]) x = fa[x]; n   return x; n } n void Merge(int x, int y) { n   x = Find(x); n   y = Find(y); n   if (x == y) { n     st.push({0, 0}); n     return; n   } n   if (sz[x] > sz[y]) swap(x, y); n   fa[x] = y; n   st.push({x, y}); n   sz[y] += sz[x]; n   for (auto it : s[x]) s[y].insert(it); n } n void Cancle() { n   int x = st.top().first, y = st.top().second; n   st.pop(); n   if (!x && !y) return; n   fa[x] = x; n   sz[y] -= sz[x]; n   for (auto it : s[x]) { n     if (s[y].find(it) != s[y].end()) s[y].erase(it); n   } n } n int main() { n   cin >> n >> m >> q; n   Init(); n   for (int i = 1; i <= n; i++) scanf( %d , &a[i]), s[i].insert({i, a[i]}); n   for (int i = 1; i <= m; i++) scanf( %d %d , &eg[i].first, &eg[i].second); n   for (int i = 1; i <= q; i++) { n     scanf( %d %d , &qi[i].op, &qi[i].x); n     if (qi[i].op == 2) vis[qi[i].x] = true; n   } n   for (int i = 1; i <= m; i++) n     if (!vis[i]) Merge(eg[i].first, eg[i].second); n   for (int i = q; i >= 1; i--) { n     if (qi[i].op == 1) continue; n     int u = eg[qi[i].x].first; n     int v = eg[qi[i].x].second; n     Merge(u, v); n   } n   for (int i = 1; i <= q; i++) { n     int op = qi[i].op, x = qi[i].x; n     if (op == 1) { n       int u = Find(x); n       while (!s[u].empty() && !a[s[u].begin()->id]) s[u].erase(s[u].begin()); n       if (s[u].empty()) n         puts( 0 ); n       else { n         printf( %d n , s[u].begin()->w); n         a[s[u].begin()->id] = 0; n       } n     } else n       Cancle(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int Maxn = 1e6 + 1; n const int Mod = 1e9 + 7; n const long long int MOD = 1000000007LL; n const long long int MAX = 100010LL; n template <typename T> n T gcd(T a, T b) { n   if (b == 0) return a; n   return gcd(b, a % b); n } n template <typename T> n T power(T x, T y, long long int m = MOD) { n   T ans = 1; n   x %= m; n   while (y > 0) { n     if (y & 1ll) ans = (ans * x) % m; n     y >>= 1ll; n     x = (x * x) % m; n   } n   return ans % m; n } n template <typename T, typename T1> n T mod(T x, T1 p) { n   x %= p; n   if (x < 0) x += p; n   return x; n } n void leastPrimeFactor(vector<int> &least_prime, int n) { n   least_prime[1] = 1; n   for (int i = 2; i <= n; i++) { n     if (least_prime[i] == 0) { n       least_prime[i] = i; n       for (int j = 2 * i; j <= n; j += i) n         if (least_prime[j] == 0) least_prime[j] = i; n     } n   } n } n bool dfs(vector<vector<int>> &graph, vector<int> &g, int i) { n   int prev = 0; n   queue<int> q; n   q.push(i); n   while (!q.empty()) { n     int n = q.size(); n     while (n--) { n       int t = q.front(); n       q.pop(); n       if (g[t] == -1) { n         g[t] = prev; n         for (int j : graph[t]) q.push(j); n       } n       if (g[t] != prev) return 0; n     } n     prev ^= 1; n   } n   return 1; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int n; n   cin >> n; n   vector<vector<int>> adj(n); n   vector<vector<int>> mat(n, vector<int>(n, 0)); n   int cnt = n; n   for (int j = 0; j < n; j++) { n     string s; n     cin >> s; n     for (int i = 0; i < s.size(); i++) n       if (s[i] ==  1 ) adj[j].push_back(i); n   } n   int m; n   cin >> m; n   vector<int> p(m); n   for (int i = 0; i < m; i++) cin >> p[i], p[i]--; n   for (int i = 0; i < n; i++) { n     queue<int> q; n     q.push(i); n     int dis = 0; n     vector<int> vis(n, 0); n     vis[i] = 1; n     while (!q.empty()) { n       int nu = q.size(); n       while (nu--) { n         int no = q.front(); n         q.pop(); n         mat[i][no] = dis; n         for (int &ne : adj[no]) n           if (!vis[ne]) vis[ne] = 1, q.push(ne); n       } n       dis++; n     } n   } n   vector<int> ans; n   ans.push_back(p[0]); n   int i = 0; n   while (i < p.size()) { n     int next = i + 1; n     for (int j = 0; j < n; j++) n       if (i + mat[p[i]][j] < p.size() && p[i + mat[p[i]][j]] == j) n         next = max(next, i + mat[p[i]][j]); n     if (next < p.size()) ans.push_back(p[next]); n     i = next; n   } n   cout << ans.size() << endl; n   for (int &i : ans) cout << i + 1 <<    ; n   cout << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, t; n   cin >> n; n   set<long long int> s; n   while (n--) { n     cin >> t; n     s.insert(t); n   } n   if (s.size() >= 4) n     cout <<  NO ; n   else { n     if (s.size() == 3) { n       auto it1 = s.begin(); n       auto it2 = it1; n       auto it3 = it2; n       it2++; n       it3++; n       it3++; n       if (2 * (*it2) == *it1 + *it3) n         cout <<  YES ; n       else n         cout <<  NO ; n     } else n       cout <<  YES ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long exp(long long x, long long y, long long p) { n   long long res = 1; n   while (y) { n     if (y % 2) res = (res * x % p) % p; n     x = (x * x) % p; n     y /= 2; n   } n   return res; n } n long long exp(long long x, long long y) { n   long long res = 1; n   while (y) { n     if (y % 2) res = (res * x); n     x = (x * x); n     y /= 2; n   } n   return res; n } n int main() { n   long long a, b, c; n   long long sum1 = 0, sum2 = 0, sum3 = 0; n   long long t; n   cin >> t; n   while (t--) { n     cin >> a >> b >> c; n     sum1 += a; n     sum2 += b; n     sum3 += c; n   } n   if (!sum1 && !sum2 && !sum3) n     cout <<  YES  << endl; n   else n     cout <<  NO  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main(int argc, char const *argv[]) { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   int n, k, flag = 0; n   cin >> n >> k; n   if (3 * n > k) { n     cout << 3 * n - k <<   n ; n   } else { n     cout <<  0  n          <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct node { n   int a, ord; n } p[10005]; n int b[10005]; n bool cmp(node a, node b) { return a.a < b.a; } n int main() { n   int n; n   while (~scanf( %d , &n)) { n     memset(b, 0, sizeof(b)); n     for (int i = 0; i < n; i++) { n       scanf( %d , &p[i].a); n       b[p[i].a]++; n       p[i].ord = i + 1; n     } n     sort(p, p + n, cmp); n     int sum = 1; n     int ss[2], A = 0; n     int sss = -1; n     int flag = 1; n     int i; n     for (i = 1; i < n; i++) { n       if (p[i].a == p[i - 1].a) n         flag++; n       else { n         if (flag >= 3) { n           sss = p[i - 1].a; n           flag = -1; n           break; n         } else if (flag == 2) n           ss[A++] = p[i - 1].a; n         flag = 1; n         if (A == 2) { n           flag = -2; n           break; n         } n       } n     } n     if (flag >= 3) { n       sss = p[i - 1].a; n       flag = -1; n     } else if (flag == 2) n       ss[A++] = p[i - 1].a; n     flag = 1; n     if (A == 2) { n       flag = -2; n     } n     if (sss != -1) flag = -1; n     if (flag > 0) n       cout <<  NO  << endl; n     else { n       cout <<  YES  << endl; n       if (flag == -1) { n         for (int i = 0; i < 3; i++) { n           flag = 1; n           for (int j = 0; j < n; j++) { n             if (j != 0) printf(   ); n             if (flag && p[j].a == sss) { n               if (i == 0) n                 printf( %d %d %d , p[j].ord, p[j + 1].ord, p[j + 2].ord); n               else if (i == 1) n                 printf( %d %d %d , p[j + 1].ord, p[j + 2].ord, p[j].ord); n               else n                 printf( %d %d %d , p[j + 2].ord, p[j].ord, p[j + 1].ord); n               j += 2; n               flag = 0; n             } else n               printf( %d , p[j].ord); n           } n           printf(  n ); n         } n       } else { n         for (int i = 0; i < 3; i++) { n           for (int j = 0; j < n; j++) { n             if (j != 0) printf(   ); n             if (i == 0 && p[j].a == ss[0]) { n               printf( %d %d , p[j].ord, p[j + 1].ord); n               j++; n             } else if (i == 1 && p[j].a == ss[0]) { n               printf( %d %d , p[j + 1].ord, p[j].ord); n               j++; n             } else if (i == 2 && p[j].a == ss[1]) { n               printf( %d %d , p[j + 1].ord, p[j].ord); n               j++; n             } else n               printf( %d , p[j].ord); n           } n           printf(  n ); n         } n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n int check_year_age(int y1, int y2) { n   if (y1 - y2 > 18) return 2; n   if (y1 - y2 == 18) return 1; n   return 0; n } n bool check_month_day_age(int d1, int d2, int m1, int m2, int y1, int y2) { n   if (check_year_age(y1, y2) == 1) { n     if (m1 == m2) { n       if (d1 >= d2) return 1; n       return 0; n     } n     if (m1 > m2) return 1; n     return 0; n   } n   if (check_year_age(y1, y2) == 2) return 1; n   return 0; n } n bool check_day_month_year_valid(int d2, int m2, int y2) { n   if (m2 > 12) return 0; n   if (y2 % 4 != 0 || m2 != 2) { n     if (m2 == 2) { n       if (d2 > 28) return 0; n     } else { n       if (m2 == 1 || m2 == 3 || m2 == 5 || m2 == 7 || m2 == 8 || m2 == 10 || n           m2 == 12) { n         if (d2 > 31) return 0; n       } else if (d2 > 30) n         return 0; n     } n   } else if (d2 > 29) n     return 0; n   return 1; n } n int chartoint(char x1, char x2) { return (x1 -  0 ) * 10 + (x2 -  0 ); } n char s[8]; n int main() { n   int d1, m1, y1, d2, m2, y2; n   bool OK = 0; n   scanf( %s , s); n   d1 = chartoint(s[0], s[1]); n   m1 = chartoint(s[3], s[4]); n   y1 = chartoint(s[6], s[7]); n   scanf( %s , s); n   d2 = chartoint(s[0], s[1]); n   m2 = chartoint(s[3], s[4]); n   y2 = chartoint(s[6], s[7]); n   if (check_month_day_age(d1, d2, m1, m2, y1, y2) && n       check_day_month_year_valid(d2, m2, y2)) { n     OK = 1; n   } n   if (check_month_day_age(d1, m2, m1, d2, y1, y2) && n       check_day_month_year_valid(m2, d2, y2)) { n     OK = 1; n   } n   if (check_month_day_age(d1, y2, m1, m2, y1, d2) && n       check_day_month_year_valid(y2, m2, d2)) { n     OK = 1; n   } n   if (check_month_day_age(d1, y2, m1, d2, y1, m2) && n       check_day_month_year_valid(y2, d2, m2)) { n     OK = 1; n   } n   if (check_month_day_age(d1, d2, m1, y2, y1, m2) && n       check_day_month_year_valid(d2, y2, m2)) { n     OK = 1; n   } n   if (check_month_day_age(d1, m2, m1, y2, y1, d2) && n       check_day_month_year_valid(m2, y2, d2)) { n     OK = 1; n   } n   if (OK) n     printf( YES n ); n   else n     printf( NO n ); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   long long a, b; n   cin >> t; n   while (t--) { n     cin >> a >> b; n     long long temp = a + b; n     if (a - b == 1) { n       int flag = 0; n       long long i; n       int n = sqrt(temp); n       if (temp <= 1) { n         cout <<  NO  << endl; n         continue; n       } n       if (temp <= 3) { n         cout <<  YES  << endl; n         continue; n       } n       if (temp % 2 == 0) { n         cout <<  NO  << endl; n         continue; n       } n       for (i = 3; i <= n + 1; i += 2) { n         if ((temp % (1ll * i)) == 0) { n           flag = 1; n           break; n         } n       } n       if (flag) n         cout <<  NO  << endl; n       else n         cout <<  YES  << endl; n     } else n       cout <<  NO  << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); n   ; n   string a; n   int n; n   cin >> a >> n; n   for (int i = 0; i < a.length() && n; ++i) { n     char x = a[i]; n     int y = i; n     for (int j = i + 1; j <= min((int)a.length() - 1, i + n) && n; ++j) n       if (x < a[j]) x = a[j], y = j; n     if (y != i) { n       n -= y - i; n       while (i != y) { n         swap(a[y - 1], a[y]); n         y--; n       } n     } n   } n   cout << a << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long MOD = (long long)1e9 + 7; n const int inf = (int)1e9 + 7; n const double eps = 1e-7; n const double pi = 3.14159265359; n const int N = (int)1e4; n const int K = 4; n long long n, k; n long long dp[N][K]; n signed main() { n   scanf( %lld%lld , &n, &k); n   if (k == 1) printf( 1 ); n   if (k == 2) printf( %lld , n * (n - 1) / 2 + 1); n   if (k == 3) printf( %lld , n * (n - 1) * (n - 2) / 3 + n * (n - 1) / 2 + 1); n   if (k == 4) n     printf( %lld , n * (n - 1) * (n - 2) * (n - 3) / 8 * 3 + n                        n * (n - 1) * (n - 2) / 3 + n * (n - 1) / 2 + 1); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m; n bool a[1001][1001]; n bool used[1001][1001]; n struct T { n   int i, j, d; n   T(int i, int j, int d) : i(i), j(j), d(d) {} n }; n int main() { n   cin >> n >> m; n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= m; j++) { n       char ch; n       cin >> ch; n       if (ch ==  # ) a[i][j] = true; n     } n   queue<T> q; n   q.push(T(n, 0, 0)); n   used[n][0] = true; n   while (!q.empty()) { n     int i = q.front().i, j = q.front().j, d = q.front().d; n     q.pop(); n     if (i == 1) { n       cout << d; n       return 0; n     } n     if (i != 0) n       for (int k = 1; k <= m; k++) n         if (a[i][k] && !used[0][k]) { n           q.push(T(0, k, d + 1)); n           used[0][k] = true; n         } n     if (j != 0) n       for (int k = 1; k <= n; k++) n         if (a[k][j] && !used[k][0]) { n           q.push(T(k, 0, d + 1)); n           used[k][0] = true; n         } n   } n   cout << -1; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int nod(int a, int b) { n   while (a && b) { n     int c = a % b; n     a = b; n     b = c; n   } n   return a | b; n } n int Abs(int a) { return a >= 0 ? a : -a; } n int main() { n   int n, m; n   cin >> n >> m; n   vector<vector<int> > e(n); n   for (int i = 0; i < m; ++i) { n     int a, b; n     scanf( %d%d , &a, &b); n     a--; n     b--; n     e[a].push_back(b); n   } n   vector<int> d(n, -1); n   queue<int> q; n   q.push(0); n   d[0] = 0; n   int r = 0; n   while (!q.empty()) { n     int i = q.front(); n     q.pop(); n     int dd = d[i] + 1; n     for (int j = 0; j < (int)e[i].size(); ++j) { n       int a = e[i][j]; n       if (d[a] >= 0) n         r = nod(r, Abs(d[a] - dd)); n       else { n         q.push(a); n         d[a] = dd; n       } n     } n   } n   int c = 0; n   for (int i = 0; i < n; ++i) n     if (d[i] >= 0 && d[i] % r == 0) c++; n   printf( %d n%d n , r, c); n   for (int i = 0; i < n; ++i) n     if (d[i] >= 0 && d[i] % r == 0) printf( %d  , i + 1); n   return 0; n } n


#include <bits/stdc++.h> n const int N = 500000; n int n, k; n char s[N + 1], t[N + 1]; n int main() { n   scanf( %d%d%s%s , &n, &k, s, t); n   int r = 0; n   long long ans = 0; n   for (int i = 0; i < n; ++i) { n     if (r < k) { n       r *= 2; n       r += t[i] - s[i]; n     } n     r = std::min(r, k); n     ans += r == k ? r : r + 1; n   } n   printf( %lld n , ans); n   return 0; n } n


#include<bits/stdc++.h> n #define inf 2000000000 n #define eb emplace_back n #define pb push_back n #define fi first n #define se second n #define fastio ios::sync_with_stdio(false);cin.tie(NULL) n #define rng_23 mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()) n using namespace std; n typedef long long ll; n typedef pair<int,int> pii; n typedef vector<int> vi; n typedef vector<pair<int,int>> vii; n typedef set<int> si; n typedef multiset<int> msi; n typedef map<int,int> mii; n int ara[100][100],lcnt[100],wcnt[100]; n int main() n { n     int t; n     int i,j,k; n     int n,res; n     cin>>t; n     while(t--){ n         cin>>n; n         for(i=0;i<n;i++) n             for(j=0;j<n;j++) n                 ara[i][j]=2; n         for(i=0;i<n;i++){ n             wcnt[i]=(n-1)/2; n             lcnt[i]=n-1-(n-1)/2; n             ara[i][i]=0; n         } n  n         if(n%2==0){ n             for(i=0;i<n;i++) n                 lcnt[i]--; n             for(i=0;i<n;i+=2){ n                 ara[i][i+1]=0; n                 ara[i+1][i]=0; n  n             } n  n         } n         //for(i=0;i<n;i++){ n          //       cout<<wcnt[i]<<   <<lcnt[i]<<endl; n  n             //} n             for(i=0;i<n;i++){ n                 //cout<<wcnt[i]<<   <<lcnt[i]<<endl; n                 for(j=0;j<n;j++){ n                     if(ara[i][j]==2 && wcnt[i] && lcnt[j]){ n                         wcnt[i]--; n                         lcnt[j]--; n                         ara[i][j]=1; n                         ara[j][i]=-1; n                     } n                 } n             } n             for(i=0;i<n-1;i++){ n                 for(j=i+1;j<n;j++){ n                     cout<<ara[i][j]<<   ; n                 } n             } n             cout<<  n ; n  n  n  n     } n } n  n


#include <bits/stdc++.h> n using namespace std; n constexpr int inf = 1e9 + 7; n constexpr long long md = 1e6; n void solve(int testi) { n   int n; n   cin >> n; n   if (n == 0) { n     cout << 1 <<   n ; n     ; n     return; n   } n   vector<int> digits = {6, 8, 4, 2}; n   cout << digits[n % digits.size()] <<   n ; n   ; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n   long long testn = 1; n   for (long long testi = 1; testi <= testn; testi++) { n     solve(testi); n   } n } n


#include <bits/stdc++.h> n using namespace std; n template <class c> n struct rge { n   c b, e; n }; n template <class c> n rge<c> range(c i, c j) { n   return rge<c>{i, j}; n } n template <class c> n auto dud(c* x) -> decltype(cerr << *x, 0); n template <class c> n char dud(...); n struct debug { n   template <class c> n   debug& operator<<(const c&) { n     return *this; n   } n }; n void solve() { n   int n, m; n   cin >> n >> m; n   vector<vector<char> > v(n + 1, vector<char>(m + 1)); n   for (int i = 1; i <= n; ++i) { n     for (int j = 1; j <= m; ++j) { n       cin >> v[i][j]; n     } n   } n   vector<vector<int> > pf(n + 1, vector<int>(m + 1)); n   for (int i = 1; i <= n; ++i) { n     for (int j = 1; j <= m; ++j) { n       pf[i][j] = pf[i - 1][j] + pf[i][j - 1] - pf[i - 1][j - 1]; n       pf[i][j] += ((v[i][j] ==  X ) ? 1 : 0); n     } n   } n   auto get = [&](int x, int y, int x1, int y1) { n     return (pf[x1][y1] - pf[x1][y - 1] - pf[x - 1][y1] + pf[x - 1][y - 1]); n   }; n   auto check = [&](int side) { n     vector<vector<int> > add(n + 1, vector<int>(m + 1)); n     for (int i = 1; i + 2 * side <= n; ++i) { n       for (int j = 1; j + 2 * side <= m; ++j) { n         long long area = (2 * side + 1) * (2 * side + 1); n         if (get(i, j, i + 2 * side, j + 2 * side) == area) { n           ++add[i][j]; n           if (i + 2 * side < n) --add[i + 2 * side + 1][j]; n           if (j + 2 * side < m) --add[i][j + 2 * side + 1]; n           if (i + 2 * side < n && j + 2 * side < m) n             ++add[i + 2 * side + 1][j + 2 * side + 1]; n         } n       } n     } n     vector<vector<int> > pf1(n + 1, vector<int>(m + 1)); n     for (int i = 1; i <= n; ++i) { n       for (int j = 1; j <= m; ++j) { n         pf1[i][j] = n             pf1[i - 1][j] + pf1[i][j - 1] - pf1[i - 1][j - 1] + add[i][j]; n         int a = !!pf1[i][j], b = ((v[i][j] ==  X ) ? 1 : 0); n         if (a ^ b) return 0; n       } n     } n     return 1; n   }; n   int l = 0, r = min(n, m), mid, ans = 1; n   while (l <= r) { n     mid = l + r >> 1; n     if (check(mid)) n       ans = mid, l = mid + 1; n     else n       r = mid - 1; n   } n   cout << ans <<   n ; n   int side = ans; n   vector<vector<char> > res(n + 1, vector<char>(m + 1,  . )); n   for (int i = 1; i <= n; ++i) { n     for (int j = 1; j <= m; ++j) { n       if (i + 2 * side <= n && j + 2 * side <= m) { n         long long area = (2 * side + 1) * (2 * side + 1); n         if (get(i, j, i + 2 * side, j + 2 * side) == area) n           res[i + side][j + side] =  X ; n       } n     } n   } n   for (int i = 1; i <= n; ++i) { n     for (int j = 1; j <= m; ++j) cout << res[i][j]; n     cout <<   n ; n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int q = 1; n   while (q--) solve(); n } n


#include <bits/stdc++.h> n using namespace std; n inline bool EQ(double num4, double b) { return fabs(num4 - b) < 1e-9; } n const int INF = 1 << 29; n inline int two(int len) { return 1 << len; } n inline int test(int len, int b) { return (len >> b) & 1; } n inline void set_bit(int &len, int b) { len |= two(b); } n inline void unset_bit(int &len, int b) { len &= ~two(b); } n inline int last_bit(int len) { return len & (-len); } n inline int ones(int len) { n   int res = 0; n   while (len && ++res) len -= len & (-len); n   return res; n } n template <class T> n void chmax(T &num4, const T &b) { n   num4 = max(num4, b); n } n template <class T> n void chmin(T &num4, const T &b) { n   num4 = min(num4, b); n } n inline void add(int &numx, int y) { n   numx += y; n   if (numx >= 1000000007) numx -= 1000000007; n   if (numx < 0) numx += 1000000007; n } n inline int mul(int numx, int y) { return ((long long)numx * y) % 1000000007; } n int gcd(int num4, int b) { n   if (b) return gcd(b, num4 % b); n   return num4; n } n int power(int num4, int pex) { n   int ret = 1; n   while (pex) { n     if (pex & 1) ret = mul(ret, num4); n     num4 = mul(num4, num4); n     pex /= 2; n   } n   return ret; n } n int phi(int len) { n   int ret = len; n   int idxx = 2; n   if (len % idxx == 0) { n     ret -= ret / idxx; n     while (len % idxx == 0) len /= idxx; n   } n   for (idxx = 3; idxx * idxx <= len; idxx++) n     if (len % idxx == 0) { n       ret -= ret / idxx; n       while (len % idxx == 0) len /= idxx; n     } n   if (len > 1) ret -= ret / len; n   return ret; n } n using namespace std; n int main() { n   bool flags = true; n   int num1, num2; n   cin >> num1 >> num2; n   int vals1 = num1 - 1, v2s = 0, v3s = 0, v4s = num2 - 1, bbs = 0; n   for (int i = 0; i < num1; ++i) n     for (int j = 0; j < num2; ++j) { n       char chh; n       cin >> chh; n       if (chh ==  B ) { n         vals1 = min(vals1, i); n         v2s = max(v2s, i); n         v4s = min(v4s, j); n         v3s = max(v3s, j); n         flags = false; n         ++bbs; n       } n     } n   if (flags) { n     cout << 1; n     return 0; n   } n   int weights = v3s - v4s + 1, h = v2s - vals1 + 1; n   if (weights > num1 || h > num2) { n     cout << -1; n     return 0; n   } n   int len = max(weights, h); n   cout << len * len - bbs << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double PI = acos(-1); n const long long INF = 1LL << 62; n const long long MINF = -(1LL << 62); n template <typename T> n T getint() { n   T val = 0; n   char c; n   bool neg = false; n   while ((c = getchar()) && !(c >=  0  && c <=  9 )) { n     neg |= c ==  - ; n   } n   do { n     val = (val * 10) + c -  0 ; n   } while ((c = getchar()) && (c >=  0  && c <=  9 )); n   return val * (neg ? -1 : 1); n } n const long long mod = 1e9 + 7; n const long long MAXN = 300010; n struct fenwick { n   long long arr[MAXN]; n   fenwick() { memset(arr, 0, sizeof arr); } n   void incr(int x, int by) { n     for (; x < MAXN; x += (x & (-x))) { n       arr[x] = (arr[x] + by) % mod; n     } n   } n   int sum(int x) { n     long long sum = 0; n     for (; x > 0; x -= (x & (-x))) { n       sum = (sum + arr[x]) % mod; n     } n     return sum; n   } n }; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long n, m; n   cin >> n >> m; n   vector<long long> c; n   vector<pair<long long, long long>> lst(m); n   for (int i = 0; i < m; ++i) cin >> lst[i].first >> lst[i].second; n   for (int i = 0; i < m; ++i) { n     c.push_back(lst[i].first); n     c.push_back(lst[i].second); n   } n   c.push_back(0); n   c.push_back(n); n   sort((c).begin(), (c).end()); n   c.resize(distance(c.begin(), unique((c).begin(), (c).end()))); n   for (int i = 0; i < m; ++i) { n     lst[i].first = n         lower_bound((c).begin(), (c).end(), lst[i].first) - c.begin(); n     lst[i].second = n         lower_bound((c).begin(), (c).end(), lst[i].second) - c.begin(); n   } n   int st = 0; n   st = lower_bound((c).begin(), (c).end(), st) - c.begin(); n   n = lower_bound((c).begin(), (c).end(), n) - c.begin(); n   fenwick f; n   sort((lst).begin(), (lst).end(), n        [&](pair<long long, long long>& egyik, pair<long long, long long>& masik) n            -> bool { return egyik.second < masik.second; }); n   f.incr(st + 1, 1); n   for (auto i : lst) { n     long long ways = f.sum(i.second) - f.sum(i.first); n     f.incr(i.second + 1, ways); n   } n   cout << (f.sum(n + 1) - f.sum(n) + mod) % mod <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2002; n int a[N][N], b[N][N], color[N / 2]; n signed main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int n; n   cin >> n; n   if (n & 1) { n     cout <<  NONE  << endl; n     return 0; n   } n   for (int j = 0; j < n; j++) { n     a[0][j] = a[n - 1][n - j - 1] = a[j][0] = a[n - j - 1][n - 1] = j / 2; n     b[0][j] = b[n - 1][n - j - 1] = b[j][0] = b[n - j - 1][n - 1] = 1; n     if (j == 0 || j == n - 1) continue; n     a[1][j] = j & 1 ? (j + 1) / 2 : (j - 1) / 2; n     b[1][j] = 0; n   } n   for (int i = 2; i < n - 1; ++i) { n     for (int j = 1; j < n - 1; ++j) { n       if (a[i - 2][j] == a[i - 1][j - 1]) { n         a[i][j] = a[i - 1][j + 1]; n       } else { n         a[i][j] = a[i - 1][j - 1]; n       } n     } n   } n   memset(color, -1, sizeof(color)); n   bool flag = true; n   string s; n   for (int i = 0; i < n; ++i) { n     cin >> s; n     for (int j = 0; j < n; ++j) { n       int col = (s[j] ==  S ); n       if (i > 0 && i < n - 1 && j > 0 && j < n - 1) { n         if (a[i][j] == a[i - 1][j - 1] && a[i][j] == a[i + 1][j + 1]) { n           b[i][j] = 1 ^ b[i - 1][j - 1]; n         } else { n           b[i][j] = 1 ^ b[i - 1][j + 1]; n         } n       } n       if (s[j] ==  . ) continue; n       if (!b[i][j]) col ^= 1; n       int &prv = color[a[i][j]]; n       if (prv == -1 || prv == col) { n         prv = col; n       } else { n         flag = false; n         goto out; n       } n     } n   } n out: n   if (flag) { n     int c = 0; n     for (int i = 0; i < n / 2; ++i) { n       c += color[i] != -1; n     } n     if (c == n / 2) { n       cout <<  UNIQUE  << endl; n       for (int i = 0; i < n; ++i) { n         for (int j = 0; j < n; ++j) { n           if (color[a[i][j]] == b[i][j]) { n             cout <<  S ; n           } else { n             cout <<  G ; n           } n         } n         cout << endl; n       } n     } else { n       cout <<  MULTIPLE  << endl; n     } n   } else { n     cout <<  NONE  << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int cur[100005]; n int mark[100005]; n int sol[400005]; n int csol; n int n, m; n vector<int> E[100005]; n inline void dfs(int u, int up) { n   mark[u] = 1; n   csol++; n   sol[csol] = u; n   cur[u] ^= 1; n   int last = 0; n   for (int i = 0; i < E[u].size(); i++) n     if (E[u][i] != up && mark[E[u][i]] == 0) { n       if (up == 0 && last != 0) { n         csol++; n         sol[csol] = u; n         cur[u] ^= 1; n       } n       dfs(E[u][i], u); n       last = 1; n       if (up != 0) { n         csol++; n         sol[csol] = u; n         cur[u] ^= 1; n       } n     } n   if (cur[u]) n     if (up != 0) { n       csol++; n       sol[csol] = up; n       csol++; n       sol[csol] = u; n       cur[u] ^= 1; n       cur[up] ^= 1; n     } else { n       csol++; n       sol[csol] = u; n       cur[u] ^= 1; n     } n } n int main() { n   scanf( %d%d , &n, &m); n   for (int i = 1; i <= m; i++) { n     int p, k; n     scanf( %d%d , &p, &k); n     E[p].push_back(k); n     E[k].push_back(p); n   } n   for (int i = 1; i <= n; i++) scanf( %d , &cur[i]); n   int st = 0; n   for (int i = 1; i <= n; i++) n     if (cur[i]) st = i; n   if (st == 0) { n     printf( 0 n ); n     return 0; n   } n   dfs(st, 0); n   int ok = 1; n   for (int i = 1; i <= n; i++) n     if (cur[i]) ok = 0; n   if (ok) { n     printf( %d n , csol); n     for (int i = 1; i <= csol; i++) printf( %d  , sol[i]); n   } else n     printf( -1 n ); 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], b[n], c[n]; n   for (long long i = 0; i < n; i++) { n     cin >> a[i]; n   } n   map<long long, long long> m; n   map<long long, long long>::iterator it; n   map<long long, long long>::iterator it1; n   for (long long i = 0; i < n; i++) { n     cin >> b[i]; n     m[b[i]]++; n   } n   for (long long i = 0; i < n; i++) { n     it = m.lower_bound(n - a[i]); n     it1 = m.lower_bound(0); n     if (it != m.end()) { n       c[i] = (it->first + a[i]) % n; n       m[it->first]--; n       if (m[it->first] == 0) m.erase(it); n     } else if (it1 != m.end()) { n       c[i] = (it1->first + a[i]) % n; n       m[it1->first]--; n       if (m[it1->first] == 0) m.erase(it1); n     } n   } n   for (long long i = 0; i < n; i++) { n     cout << c[i] <<    ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); n const int N = 2e5 + 100; n int t[20 * N], ls[20 * N], rs[20 * N], a[N], root[N]; n int cur_size = 1; n void upd(int &v, int u, int l, int r, int pos, int x) { n   v = cur_size++; n   t[v] = t[u] + x, ls[v] = ls[u], rs[v] = rs[u]; n   if (l + 1 == r) { n     return; n   } n   int mid = (l + r) / 2; n   if (pos < mid) n     upd(ls[v], ls[u], l, mid, pos, x); n   else n     upd(rs[v], rs[u], mid, r, pos, x); n   t[v] = t[ls[v]] + t[rs[v]]; n } n int get(int v, int l, int r, int ql, int qr) { n   if (qr <= l || r <= ql) return 0; n   if (ql <= l && r <= qr) return t[v]; n   int mid = (l + r) / 2; n   return get(ls[v], l, mid, ql, qr) + get(rs[v], mid, r, ql, qr); n } n signed main() { n   ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); n   int n, k; n   cin >> n >> k; n   vector<int> pos[N]; n   for (int i = 1; i <= n; i++) { n     cin >> a[i]; n     pos[a[i]].push_back(i); n   } n   for (int i = 1; i <= n; i++) { n     int p = n         lower_bound(pos[a[i]].begin(), pos[a[i]].end(), i) - pos[a[i]].begin(); n     upd(root[i], root[i - 1], 1, n + 1, i, 1); n     if (p >= k) { n       p -= k; n       upd(root[i], root[i], 1, n + 1, pos[a[i]][p], -1); n     } n   } n   int q; n   cin >> q; n   int ans = 0; n   while (q--) { n     int l, r; n     cin >> l >> r; n     l = (l + ans) % n + 1; n     r = (r + ans) % n + 1; n     if (l > r) swap(l, r); n     ans = get(root[r], 1, n + 1, l, r + 1); n     cout << ans <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int t; n   cin >> t; n   while (t--) { n     long long int n; n     cin >> n; n     long long int ans; n     long long int f = 0; n     for (long long int i = 3; i <= 360; i++) { n       if ((n * i) % 180 == 0 && (n * i) / 180 <= i - 2) { n         f = 1; n         ans = i; n         break; n       } n     } n     if (f == 1) n       cout << ans << endl; n     else n       cout << -1 << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 2e5 + 7; n const int inf = 0x3f3f3f; n char s[maxn]; n char str[4] =  RGB ; n int main() { n   int q; n   scanf( %d , &q); n   while (q--) { n     int n, m; n     scanf( %d%d , &n, &m); n     scanf( %s , s); n     int minn = inf; n     n -= m; n     for (int i = 0; i <= n; i++) { n       for (int j = 0; j < 3; j++) { n         int jishu = 0, temp; n         temp = (j <= 1 ? j : 2); n         for (int k = 0; k < m; k++) { n           if (s[i + k] != str[(temp + k) % 3]) { n             jishu++; n           } n         } n         minn = min(minn, jishu); n       } n     } n     printf( %d n , minn); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int N; n int A[2000000], B[2000000]; n int l[2000000], r[2000000], c[2000000]; n int main() { n   scanf( %d , &N); n   int mxi = 0; n   for (int Ni = 0; Ni < N; Ni++) { n     scanf( %d , &A[Ni]); n     if (A[Ni] > A[mxi]) mxi = Ni; n   } n   for (int Ni = 0; Ni < N; Ni++) B[Ni] = A[(Ni + mxi) % N]; n   B[N] = B[0]; n   for (int Ni = N - 1; Ni >= 0; Ni--) { n     r[Ni] = Ni + 1; n     while (r[Ni] < N && B[Ni] > B[r[Ni]]) r[Ni] = r[r[Ni]]; n     if (r[Ni] < N && B[Ni] == B[r[Ni]]) c[Ni] = c[r[Ni]] + 1, r[Ni] = r[r[Ni]]; n   } n   for (int Ni = 1; Ni < N; Ni++) { n     l[Ni] = Ni - 1; n     while (l[Ni] > 0 && B[Ni] > B[l[Ni]]) l[Ni] = l[l[Ni]]; n     if (l[Ni] > 0 && B[Ni] == B[l[Ni]]) l[Ni] = l[l[Ni]]; n   } n   long long Ans = 0; n   for (int Ni = 0; Ni < N; Ni++) { n     if (B[Ni] == B[0]) n       ; n     else if (l[Ni] == 0 && r[Ni] == N) n       Ans++; n     else n       Ans += 2; n     Ans += c[Ni]; n   } n   printf( %I64d n , Ans); n } n


#include <bits/stdc++.h> n using namespace std; n void start() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n } n long long ans = INT_MAX; n void solve(long long a, long long b, long long k, long long steps) { n   if (a == 1 && b == 1) { n     ans = min(ans, steps); n     return; n   } n   if (a - b > 0) solve(a - b, b, k, steps + 1); n   if (b - a > 0) solve(a, b - a, k, steps + 1); n } n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   start(); n   long long n; n   cin >> n; n   for (long long i = 1; i < n; i++) { n     solve(i, n - i, n, 1); n   } n   if (ans == INT_MAX) n     cout <<  0  n          <<   n ; n   else n     cout << ans <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 1e5 + 30, Mod = 1e9 + 7; n const long long SQ = 330; n const long long LOG = 20; n long long n, q, Par[LOG][N], a[N], H[N], St[N], Fn[N], Lazy[N << 2], T, Fen[N], n     Seg[N << 2], root = 1; n vector<long long> G[N]; n void DFS(long long v = 1, long long par = 0) { n   St[v] = T++; n   Par[0][v] = par; n   for (int i = 1; i < LOG; i++) Par[i][v] = Par[i - 1][Par[i - 1][v]]; n   for (auto u : G[v]) { n     if (u == par) continue; n     H[u] = H[v] + 1; n     DFS(u, v); n   } n   Fn[v] = T; n } n void Shift(int id, int b, int e) { n   long long val = Lazy[id]; n   Seg[(id << 1)] += (((b + e) >> 1) - b) * val; n   Seg[((id << 1) | 1)] += (e - ((b + e) >> 1)) * val; n   Lazy[(id << 1)] += val; n   Lazy[((id << 1) | 1)] += val; n   Lazy[id] = 0; n } n void Add(int l, int r, long long val = 0, int id = 1, int b = 0, int e = n) { n   if (r <= b || e <= l) return; n   if (l <= b && e <= r) { n     Seg[id] += val * (e - b); n     Lazy[id] += val; n     return; n   } n   Shift(id, b, e); n   Add(l, r, val, (id << 1), b, ((b + e) >> 1)); n   Add(l, r, val, ((id << 1) | 1), ((b + e) >> 1), e); n   Seg[id] = Seg[(id << 1)] + Seg[((id << 1) | 1)]; n } n long long Get(int l, int r, int id = 1, int b = 0, int e = n) { n   if (r <= b || e <= l) return 0; n   if (l <= b && e <= r) return Seg[id]; n   Shift(id, b, e); n   return Get(l, r, (id << 1), b, ((b + e) >> 1)) + n          Get(l, r, ((id << 1) | 1), ((b + e) >> 1), e); n } n bool is_par(long long v, long long u) { n   return St[v] <= St[u] && Fn[u] <= Fn[v]; n } n long long Up(long long v, long long h) { n   for (int i = LOG - 1; ~i; i--) n     if (h & (1 << i)) v = Par[i][v]; n   return v; n } n long long LLCA(long long v, long long u) { n   if (H[v] < H[u]) swap(v, u); n   v = Up(v, H[v] - H[u]); n   if (v == u) return v; n   for (int i = LOG - 1; ~i; i--) { n     if (Par[i][v] ^ Par[i][u]) { n       v = Par[i][v]; n       u = Par[i][u]; n     } n   } n   return Par[0][v]; n } n long long LCA(long long v, long long u) { n   if (is_par(root, v) && is_par(root, u)) return LLCA(v, u); n   if (is_par(root, v) && !is_par(root, u)) return root; n   if (is_par(root, u) && !is_par(root, v)) return root; n   long long l = LLCA(v, u); n   if (is_par(v, u)) { n     long long x = LLCA(u, root); n     if (is_par(v, x)) return x; n     return v; n   } n   if (is_par(u, v)) { n     long long x = LLCA(v, root); n     if (is_par(u, x)) return x; n     return u; n   } n   if (is_par(l, root)) { n     long long f = LLCA(v, root); n     long long f2 = LLCA(u, root); n     if (H[f2] > H[f]) { n       return f2; n     } n     return f; n   } n   return l; n } n void Inp() { n   cin >> n >> q; n   for (int i = 1; i <= n; i++) { n     cin >> a[i]; n   } n   for (int i = 0; i < n - 1; i++) { n     long long v, u; n     cin >> v >> u; n     G[v].push_back(u); n     G[u].push_back(v); n   } n   DFS(1, 0); n   for (int i = 1; i <= n; i++) { n     Add(St[i], St[i] + 1, a[i]); n   } n } n void Add_Sub(long long v, long long val) { n   if (v == root) { n     Add(0, n, val); n     return; n   } n   if (is_par(root, v)) { n     Add(St[v], Fn[v], val); n     return; n   } n   if (is_par(v, root)) { n     long long dif = H[root] - H[v] - 1; n     long long rr = Up(root, dif); n     Add(0, n, val); n     Add(St[rr], Fn[rr], -val); n     return; n   } n   Add(St[v], Fn[v], val); n } n long long Get_Sub(long long v) { n   if (v == root) return Get(0, n); n   if (is_par(root, v)) { n     return Get(St[v], Fn[v]); n   } n   if (is_par(v, root)) { n     long long dif = H[root] - H[v] - 1; n     long long rr = Up(root, dif); n     return Get(0, n) - Get(St[rr], Fn[rr]); n   } n   return Get(St[v], Fn[v]); n } n int main() { n   ios::sync_with_stdio(0), cin.tie(0); n   Inp(); n   while (q--) { n     long long t; n     cin >> t; n     if (t == 1) { n       long long v; n       cin >> v; n       root = v; n     } n     if (t == 2) { n       long long v, u, x; n       cin >> v >> u >> x; n       long long l = LCA(v, u); n       Add_Sub(l, x); n     } n     if (t == 3) { n       long long v; n       cin >> v; n       cout << Get_Sub(v) <<   n ; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long int n, m, k; n   cin >> n >> m >> k; n   vector<pair<long long int, long long int> > F(n), S(m); n   long long int maxDay = 0; n   for (long long int i = 0; i < n; i++) { n     cin >> F[i].first; n     F[i].second = i + 1; n     maxDay = max(maxDay, F[i].first); n   } n   for (long long int i = 0; i < m; i++) { n     cin >> S[i].first; n     S[i].second = i + 1; n   } n   long long int f_i = 0, s_i = 0; n   sort(F.begin(), F.begin() + F.size()); n   sort(S.begin(), S.begin() + S.size()); n   vector<long long int> res; n   for (long long int i = 0; i <= maxDay; i++) { n     long long int use = 0; n     while (use < k && f_i < F.size() && F[f_i].first == i) { n       f_i++; n       use++; n     } n     if (use == k && f_i < F.size() && F[f_i].first == i) { n       cout <<  -1 ; n       return 0; n     } n     while (s_i < S.size() && S[s_i].first < i) s_i++; n     while (use < k && s_i < S.size() && S[s_i].first >= i) { n       res.push_back(S[s_i].second); n       use++; n       s_i++; n     } n     while (use < k && f_i < F.size() && F[f_i].first > i) { n       use++; n       f_i++; n     } n   } n   for (long long int i = maxDay + 1; s_i < S.size(); i++) { n     long long int use = 0; n     while (s_i < S.size() && S[s_i].first < i) s_i++; n     while (use < k && s_i < S.size() && S[s_i].first >= i) { n       res.push_back(S[s_i].second); n       s_i++; n       use++; n     } n   } n   cout << res.size() <<   n ; n   for (auto x : res) cout << x <<    ; n } n


#include <bits/stdc++.h> n using namespace std; n #pragma comment(linker,  /STACK:400000000 ) n int n, m; n struct space { n   int from, to, dist; n   space(int f, int t) : from(f), to(t) { n     if (f > t) { n       dist = 0; n     } else if (f == 1 || t == n) { n       dist = t - f + 1; n     } else { n       dist = (t - f) / 2 + 1; n     } n   } n   bool operator<(const space& b) const { n     return dist > b.dist || dist == b.dist && from < b.from; n   } n }; n set<space> S; n int carP[1000010], carL[1000010], carR[1000010], posToCar[1000010]; n int main() { n   cin >> n >> m; n   S.insert(space(1, n)); n   for (int i = 0; i < m + 1; i++) { n     if (i == m) break; n     int t, id; n     cin >> t >> id; n     if (t == 1) { n       space sp = *S.begin(); n       S.erase(S.begin()); n       int F = sp.from, T = sp.to, pos; n       if (F == 1 && T == n) n         pos = 1; n       else if (F == 1) n         pos = 1; n       else if (T == n) n         pos = n; n       else n         pos = (F + T) / 2; n       cout << pos << endl; n       carP[id] = pos; n       carL[id] = F - 1; n       carR[id] = T + 1; n       posToCar[pos] = id; n       carR[posToCar[F - 1]] = pos; n       carL[posToCar[T + 1]] = pos; n       S.insert(space(F, pos - 1)); n       S.insert(space(pos + 1, T)); n     } else { n       int F = carL[id], P = carP[id], T = carR[id]; n       S.erase(space(F + 1, P - 1)); n       S.erase(space(P + 1, T - 1)); n       carR[posToCar[F]] = T; n       carL[posToCar[T]] = F; n       S.insert(space(F + 1, T - 1)); n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n struct dreapta { n   ll a, b; n   ll operator()(ll x) { return a * x + b; } n }; n bool useless(dreapta a, dreapta b, dreapta c) { n   assert(a.a >= b.a && b.a >= c.a); n   return (double)(b.b - a.b) / (a.a - b.a) > (double)(c.b - b.b) / (b.a - c.a); n } n class merging_batch { n   deque<dreapta> buf; n  n  public: n   merging_batch() {} n   ll query(ll x) { n     ll i = 0; n     for (ll step = 1 << 23; step; step /= 2) n       if (i + step < buf.size() && buf[i + step](x) <= buf[i + step - 1](x)) n         i += step; n     assert(i == buf.size() - 1 || buf[i](x) <= buf[i + 1](x)); n     return buf[i](x); n   } n   void add_right(dreapta x) { n     while (buf.size() > 1 && useless(buf.rbegin()[1], buf.back(), x)) n       buf.pop_back(); n     buf.push_back(x); n   } n   void add_left(dreapta x) { n     while (buf.size() > 1 && useless(x, buf[0], buf[1])) buf.pop_front(); n     buf.push_front(x); n   } n   void swap_with(merging_batch& rhs) { swap(buf, rhs.buf); } n   void merge_with(merging_batch& rhs) { n     if (buf.size() < rhs.buf.size()) { n       for (auto it = buf.rbegin(); it != buf.rend(); ++it) rhs.add_left(*it); n       swap(buf, rhs.buf); n     } else n       for (auto x : rhs.buf) add_right(x); n   } n }; n class undo_batch { n   ll top = 0; n   vector<dreapta> st = vector<dreapta>( n       1000000 + 10, n       dreapta{1000ll * 1000 * 1000, 1000ll * 1000 * 1000 * 1000 * 1000}); n   struct modification { n     ll old_top, old_pos; n     dreapta d; n   }; n   vector<modification> undo_st; n  n  public: n   undo_batch() { top = 1; } n   void clear() { top = 1; } n   void print() { n     for (int i = 1; i < top; ++i) { n       cerr <<  (  << st[i].a <<  ,  << st[i].b <<  )  ; n     } n     cerr << endl; n   } n   ll query(ll x) { n     ll i = 0; n     for (ll step = 1 << 23; step; step /= 2) n       if (i + step < top && st[i + step](x) <= st[i + step - 1](x)) i += step; n     assert(i == top - 1 || st[i](x) <= st[i + 1](x)); n     return st[i](x); n   } n   void undo() { n     assert(!undo_st.empty()); n     top = undo_st.back().old_top; n     st[undo_st.back().old_pos] = undo_st.back().d; n     undo_st.pop_back(); n   } n   void add_right(dreapta d) { n     undo_st.push_back(modification{top, 0, 0}); n     ll ret = 0; n     for (ll step = 1 << 23; step; step /= 2) n       if (ret + step < top && (!useless(st[ret + step - 1], st[ret + step], d))) n         ret += step; n     top = ret + 2; n     undo_st.back().old_pos = ret + 1; n     undo_st.back().d = st[ret + 1]; n     st[ret + 1] = d; n   } n }; n void produce_state(const ll n, const vector<ll>& d, const vector<ll>& v, n                    vector<ll>& ret) { n   static vector<ll> posz; n   static vector<merging_batch> mb; n   static undo_batch ub; n   posz.clear(); n   mb.clear(); n   ub.clear(); n   for (ll i = 0; i < n; ++i) { n     merging_batch x; n     x.add_right(dreapta{-i + 1, d[i]}); n     while (!posz.empty() && v[posz.back()] <= v[i]) { n       mb.back().merge_with(x); n       x.swap_with(mb.back()); n       mb.pop_back(); n       posz.pop_back(); n       ub.undo(); n     } n     posz.push_back(i); n     mb.push_back(move(x)); n     ub.add_right(dreapta{v[i], mb.back().query(v[i])}); n     ret[i + 1] = ub.query(i); n   } n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   ll n, k; n   cin >> n >> k; n   vector<ll> v(n); n   for (auto& x : v) cin >> x; n   vector<ll> state(n + 1, (ll)1e9 * (ll)1e9), tmp(n + 1, 0); n   state[0] = 0; n   tmp[0] = 0; n   for (ll i = 0; i < k; ++i) { n     produce_state(n, state, v, tmp); n     swap(state, tmp); n   } n   cout << state.back() << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename _T, typename _T2> n string to_string(pair<_T, _T2> x) { n   return  <  + to_string(x.first) +  ,   + to_string(x.second) +  > ; n } n template <typename _T> n string to_string(vector<_T> vec) { n   string s =  [  ; n   for (auto el : vec) s += to_string(el) +  ,  ; n   s[s.size() - 1] =  ] ; n   s[s.size() - 2] =    ; n   return s; n } n template <typename _T> n string to_string(set<_T> vec) { n   string s =  {  ; n   for (auto el : vec) s += to_string(el) +  ,  ; n   s[s.size() - 1] =  } ; n   s[s.size() - 2] =    ; n   return s; n } n template <typename _T, typename _T2> n string to_string(map<_T, _T2> vec) { n   string s =  {  ; n   for (auto el : vec) n     s +=  mp[  + to_string(el.first) +  ]=   + to_string(el.second) +  ,  ; n   s[s.size() - 1] =  } ; n   s[s.size() - 2] =    ; n   return s; n } n template <typename _T> n inline void _DBG(const char *s, _T x) { n   cerr << s <<   =   << to_string(x) <<   n ; n } n template <typename _T, typename... args> n void _DBG(const char *s, _T x, args... a) { n   while (*s !=  , ) cerr << *s++; n   cerr <<   =   << to_string(x) <<   n ; n   _DBG(s + 1, a...); n } n mt19937 rng___(chrono::steady_clock::now().time_since_epoch().count()); n const long long MOD = 998244353; n const long long LLINF = 1e18 + 7; n const int N = 2e5 + 8; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n   ; n   int t; n   cin >> t; n   while (t--) { n     int n[3], len; n     cin >> n[0] >> n[1] >> n[2]; n     len = n[0] + n[1] + n[2] + 1; n     string ans; n     if (n[0] > 0) { n       ans += string(n[0] + 1,  0 ); n       if (n[2] > 0) { n         n[1]--; n         ans += string(n[2] + 1,  1 ); n       } n       while (n[1]--) { n         if (ans.back() ==  1 ) n           ans +=  0 ; n         else n           ans +=  1 ; n       } n       cout << ans <<   n ; n     } else { n       ans += string(n[2] + 1,  1 ); n       while (n[1]--) { n         if (ans.back() ==  1 ) n           ans +=  0 ; n         else n           ans +=  1 ; n       } n       cout << ans <<   n ; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n typedef pair<int, int> PII; n long long qpow(long long a, long long b, long long m) { n   long long ans = 1; n   while (b) { n     if (b & 1) ans = ans * a % m; n     a = a * a % m, b >>= 1; n   } n   return ans; n } n long long qpow(long long a, long long b) { n   long long ans = 1; n   while (b) { n     if (b & 1) ans = ans * a; n     a = a * a, b >>= 1; n   } n   return ans; n } n long long qmul(long long a, long long b, long long m) { n   long long res = 0; n   while (b > 0) { n     if (b & 1) res = (res + a) % m; n     a = (a + a) % m; n     b >>= 1; n   } n   return res; n } n long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } n long long lcm(long long a, long long b) { return a / gcd(a, b) * b; } n long long inv(long long t, long long p) { n   return t == 1 ? 1 : (p - p / t) * inv(p % t, p) % p; n } n long long exgcd(long long a, long long b, long long &x, long long &y) { n   if (b == 0) { n     x = 1; n     y = 0; n     return a; n   } n   long long r = exgcd(b, a % b, y, x); n   y -= (a / b) * x; n   return r; n } n long long inv1(long long a, long long p) { n   long long d, x, y; n   d = exgcd(a, p, x, y); n   return d == 1 ? (x % p + p) % p : -1; n } n template <typename T, typename B> n T Add(T a, B b, long long m) { n   return a + b >= m ? (a + b) % m : a + b; n } n template <typename T, typename B> n T Sub(T a, B b, long long m) { n   return a - b < 0 ? (a - b + m) % m : a - b; n } n template <class T> n void _sf(T &x) { n   cin >> x; n } n void _sf(int &x) { scanf( %d , &x); } n void _sf(long long &x) { scanf( %lld , &x); } n void _sf(double &x) { scanf( %lf , &x); } n void _sf(char &x) { scanf(  %c , &x); } n void _sf(char *x) { scanf( %s , x); } n void sf() {} n template <class T, class... U> n void sf(T &head, U &...tail) { n   _sf(head); n   sf(tail...); n } n template <class T> n void _pf(const T &x) { n   cout << x; n } n void _pf(const int &x) { printf( %d , x); } n void _pf(const long long &x) { printf( %lld , x); } n void _pf(const double &x) { printf( %.16f , x); } n void _pf(const char &x) { putchar(x); } n void _pf(const char *x) { printf( %s , x); } n template <class T, class U> n void _pf(const pair<T, U> &x) { n   pf(x.first); n   putchar(   ); n   pf(x.second); n } n template <class T> n void _pf(const vector<T> &x) { n   for (auto i = x.begin(); i != x.end(); _pf(*i++)) n     if (i != x.cbegin()) putchar(   ); n } n void pf() {} n template <class T, class... U> n void pf(const T &head, const U &...tail) { n   _pf(head); n   putchar(sizeof...(tail) ?     :   n ); n   pf(tail...); n } n template <typename T> n inline void read(T &x) { n   x = 0; n   static int p; n   p = 1; n   static char c; n   c = getchar(); n   while (!isdigit(c)) { n     if (c ==  - ) p = -1; n     c = getchar(); n   } n   while (isdigit(c)) { n     x = (x << 1) + (x << 3) + (c - 48); n     c = getchar(); n   } n   x *= p; n } n const bool IOS = false; n const double PI = acos(-1); n const double eps = 1e-8; n const long long linf = 0x3f3f3f3f3f3f3f3f; n const long long INV2 = 500000004; n const long long mod = 1e9 + 7; n const int inf = 0x3f3f3f3f; n const int maxn = 400050 + 10; n bool vis[maxn]; n int mi[maxn]; n void Main(); n int main() { n   if (IOS) std::ios::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   Main(); n   0; n   return 0; n } n void Main() { n   int n, x; n   sf(n, x); n   for (int i = 0; i < x; ++i) mi[i] = i; n   int ans = 0; n   for (int i = 1; i <= n; ++i) { n     int d; n     sf(d); n     d = d % x; n     if (mi[d] <= n) { n       vis[mi[d]] = 1; n       while (vis[ans]) ans++; n       mi[d] += x; n     } n     pf(ans); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m; n   string s; n   cin >> n >> m; n   cin >> s; n   int pos = 0; n   for (int i = 1; i < n; i++) { n     if (s.substr(0, i) == s.substr(n - i, i)) { n       pos = i; n     } n   } n   cout << s; n   for (int i = 1; i < m; i++) { n     cout << s.substr(pos); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n istream& operator>>(istream& is, vector<T>& v) { n   for (auto& it : v) is >> it; n   return is; n } n template <class L, class R> n ostream& operator<<(ostream& os, pair<L, R> P) { n   return os <<  (  << P.first <<  ,  << P.second <<  ) ; n } n template <class T> n ostream& operator<<(ostream& os, vector<T> V) { n   os <<  [  ; n   for (auto v : V) os << v <<    ; n   return os <<  ] ; n } n template <class T> n ostream& operator<<(ostream& os, set<T> second) { n   os <<  {  ; n   for (auto s : second) os << s <<    ; n   return os <<  } ; n } n template <typename Arg1> n void __f(const char* name, Arg1&& arg1) { n   cout << name <<   :   << arg1 <<   n ; n } n template <typename Arg1, typename... Args> n void __f(const char* names, Arg1&& arg1, Args&&... args) { n   const char* comma = strchr(names + 1,  , ); n   cout.write(names, comma - names) <<   :   << arg1 <<   | ; n   __f(comma + 1, args...); n } n vector<int> hungarianMethod(vector<vector<int>> W) { n   int n = ((int)(W).size()), m = ((int)(W[0]).size()), PHI = -1, NOL = -2, n       INF = 1e9; n   vector<vector<bool>> x(n, vector<bool>(m)); n   vector<bool> ss(n), st(m); n   int f = 0; n   for (int i = 0; i < n; i++) { n     f = max(f, (*max_element(W[i].begin(), W[i].end()))); n   } n   vector<int> u(n, f), v(m), p(m, INF), ls(n, PHI), lt(m, NOL), a(n, -1); n   while (true) { n     f = -1; n     for (int i = 0; i < n and f == -1; i++) { n       if (ls[i] != NOL and ss[i] == 0) { n         f = i; n       } n     } n     if (f != -1) { n       ss[f] = true; n       for (int j = 0; j < m; j++) { n         if (x[f][j] == 0 and u[f] + v[j] - W[f][j] < p[j]) { n           lt[j] = f; n           p[j] = u[f] + v[j] - W[f][j]; n         } n       } n     } else { n       for (int i = 0; i < m and f == -1; i++) { n         if (lt[i] != NOL and st[i] == 0 and p[i] == 0) { n           f = i; n         } n       } n       if (f == -1) { n         int d1 = INF, d2 = INF, d; n         for (int i : u) { n           d1 = min(d1, (i)); n         } n         for (int i : p) { n           if (i > 0) { n             d2 = min(d2, (i)); n           } n         } n         d = min(d1, d2); n         for (int i = 0; i < n; i++) { n           if (ls[i] != NOL) { n             u[i] -= d; n           } n         } n         for (int i = 0; i < m; i++) { n           if (p[i] == 0) { n             v[i] += d; n           } n           if (p[i] > 0 and lt[i] != NOL) { n             p[i] -= d; n           } n         } n         if (d2 >= d1) { n           break; n         } n       } else { n         st[f] = true; n         int s = -1; n         for (int i = 0; i < n and s == -1; i++) { n           if (x[i][f]) { n             s = i; n           } n         } n         if (s == -1) { n           for (int l, r;; f = r) { n             r = f; n             l = lt[r]; n             if (r >= 0 and l >= 0) { n               x[l][r] = !x[l][r]; n             } else { n               break; n             } n             r = ls[l]; n             if (r >= 0 and l >= 0) { n               x[l][r] = !x[l][r]; n             } else { n               break; n             } n           } n           fill(p.begin(), p.end(), INF); n           fill(lt.begin(), lt.end(), NOL); n           fill(ls.begin(), ls.end(), NOL); n           fill(ss.begin(), ss.end(), false); n           fill(st.begin(), st.end(), false); n           for (int i = 0; i < n; i++) { n             bool ex = true; n             for (int j = 0; j < m and ex; j++) { n               ex = !x[i][j]; n             } n             if (ex) { n               ls[i] = PHI; n             } n           } n         } else { n           ls[s] = f; n         } n       } n     } n   } n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       if (x[i][j]) { n         a[j] = i; n       } n     } n   } n   return a; n } n void solve() { n   map<char, int> ind; n   map<int, char> revInd; n   for (char ch =  a ; ch <=  z ; ++ch) { n     ind[ch] = ch -  a ; n     revInd[ind[ch]] = ch; n   } n   for (char ch =  A ; ch <=  Z ; ++ch) { n     ind[ch] = (ch -  A ) + 26; n     revInd[ind[ch]] = ch; n   } n   int n, k; n   cin >> n >> k; n   string a, b; n   cin >> a >> b; n   vector<vector<int>> W(k, vector<int>(k, 1)); n   for (int i = 0; i < n; ++i) { n     W[ind[a[i]]][ind[b[i]]]++; n   } n   vector<int> matching = hungarianMethod(W); n   int ans = 0; n   string res(k,  $ ); n   for (int i = 0; i < k; ++i) { n     ans += W[matching[i]][i] - 1; n     res[matching[i]] = revInd[i]; n   } n   cout << ans <<   n  << res <<   n ; n } n int32_t main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int T = 1; n   while (T--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 7, n = 7, maxm = 101; n int m, cntblk = maxn, f[maxn], deg[maxn]; n bool used[maxm]; n class ed { n  public: n   int target, id; n   char type; n   ed(int t, int i, char ty) : target(t), id(i), type(ty){}; n }; n class ans { n  public: n   int id; n   char type; n   ans(int i, char ty) : id(i), type(ty){}; n }; n vector<ed> edge[maxn]; n vector<ans> answer; n inline int getf(int x) { return f[x] == x ? x : f[x] = getf(f[x]); } n void euler(int x, int in_id, char in_type) { n   for (vector<ed>::iterator vi = edge[x].begin(); vi != edge[x].end(); vi++) { n     if (used[(*vi).id]) continue; n     used[(*vi).id] = true; n     euler((*vi).target, (*vi).id, (*vi).type); n   } n   if (in_id >= 0) answer.push_back(ans(in_id, in_type)); n } n int main() { n   cin >> m; n   for (int i = 0; i < n; i++) f[i] = i, deg[i] = 0; n   for (int i = 1, x, y; i <= m; i++) { n     cin >> x >> y; n     deg[x]++; n     deg[y]++; n     edge[x].push_back(ed(y, i,  + )); n     edge[y].push_back(ed(x, i,  - )); n     if (getf(x) == getf(y)) continue; n     f[getf(x)] = getf(y); n     cntblk--; n   } n   int tmp = 0, s = -1; n   for (int i = 0; i < n; i++) { n     cntblk -= (deg[i] == 0); n     tmp += (deg[i] & 1); n     if (deg[i] > 0 && (s == -1 || deg[i] & 1)) s = i; n   } n   if (cntblk != 1 || !(tmp == 0 || tmp == 2)) { n     puts( No solution ); n     return 0; n   } n   memset(used, false, sizeof(used)); n   euler(s, -1,  + ); n   for (vector<ans>::reverse_iterator vi = answer.rbegin(); vi < answer.rend(); n        vi++) { n     printf( %d %c n , (*vi).id, (*vi).type); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n priority_queue<int, vector<int>, less<int> > num; n int main() { n   int n, x; n   cin >> n; n   for (int i = 1; i <= n; i++) { n     cin >> x; n     num.push(x); n   } n   cout << ((num.top()) xor (x)) <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 200020; n int a[maxn], b[maxn], pos[maxn], ans; n unsigned long long hsh, qpow[200020] = {1}, sum; n int n, m; n struct node { n   unsigned long long a, tot; n } tr[maxn << 2]; n void pushup(int p) { n   tr[p].tot = tr[p << 1].tot + tr[p << 1 | 1].tot; n   tr[p].a = tr[p << 1].a * qpow[tr[p << 1 | 1].tot] + tr[p << 1 | 1].a; n } n void update(int l, int r, int pos, int p, int k) { n   if (l == r) { n     if (!k) n       tr[p].tot -= 1; n     else n       tr[p].tot += 1; n     tr[p].a = k; n     return; n   } n   int mid = l + r >> 1; n   if (pos <= mid) update(l, mid, pos, p << 1, k); n   if (pos > mid) update(mid + 1, r, pos, p << 1 | 1, k); n   pushup(p); n } n int main() { n   cin >> n >> m; n   for (int i = 1; i <= n; i++) { n     scanf( %lld , &a[i]); n     hsh = hsh * 23 + a[i]; n     qpow[i] = qpow[i - 1] * 23; n     sum += qpow[i - 1]; n   } n   for (int i = 1; i <= m; i++) scanf( %lld , &b[i]), pos[b[i]] = i; n   for (int i = 1; i <= m; i++) { n     if (i > n) update(1, m, pos[i - n], 1, 0); n     update(1, m, pos[i], 1, i); n     int d = i - n; n     if (d >= 0 && tr[1].a == d * sum + hsh) ++ans; n   } n   printf( %d , ans); 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   ; n   long long int n; n   cin >> n; n   if (n % 2 == 0) n     cout <<  NO  << endl; n   else { n     cout <<  YES  << endl; n     long long int b[(2 * n) + 1]; n     b[1] = 1; n     b[2 * n] = 2 * n; n     long long int i = n + 1; n     long long int j = 2; n     long long int k = 2; n     long long int flag = 1; n     while (k < 2 * n) { n       if (flag == 1) { n         b[i] = k; n         b[i + 1] = k + 1; n         k = k + 2; n         i = i + 2; n         flag = 0; n       } else { n         b[j] = k; n         b[j + 1] = k + 1; n         k = k + 2; n         j = j + 2; n         flag = 1; n       } n     } n     for (long long int i = 1; i <= 2 * n; i++) cout << b[i] <<    ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e2 + 5; n const int MOD = 1e9 + 7; n long long cnt[N], x; n int n, tmp; n vector<vector<long long> > matMul(vector<vector<long long> > &A, n                                   vector<vector<long long> > &B) { n   vector<vector<long long> > C(N, vector<long long>(N, 0)); n   for (int i = 0; i < N; i++) { n     for (int j = 0; j < N; j++) { n       for (int k = 0; k < N; k++) { n         C[i][j] = (C[i][j] + (A[i][k] * B[k][j]) % MOD) % MOD; n       } n     } n   } n   return C; n } n vector<vector<long long> > matPow(vector<vector<long long> > &A, int b) { n   if (b == 1) return A; n   vector<vector<long long> > ans = matPow(A, b >> 1); n   ans = matMul(ans, ans); n   if (b & 1) ans = matMul(ans, A); n   return ans; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cin >> n >> x; n   for (int i = 0; i < n; i++) { n     cin >> tmp; n     cnt[tmp]++; n   } n   if (x == 0) { n     cout <<  1 n ; n     return 0; n   } n   vector<vector<long long> > res(N, vector<long long>(N, 0)); n   for (int i = 1; i <= 100; i++) { n     res[0][i - 1] = cnt[i]; n     if (i < 100) res[i][i - 1] = 1; n   } n   res[0][100] = 1; n   res[100][100] = 1; n   res = matPow(res, x); n   long long ans = (res[0][0] + res[0][100]) % MOD; n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 505; n const long long inf = 1e18; n inline int read() { n   int x = 0; n   char c = getchar(); n   while (!isdigit(c)) c = getchar(); n   while (isdigit(c)) x = (x << 3) + (x << 1) + (c ^ 48), c = getchar(); n   return x; n } n int n, m, now; n long long ans, Pow[100]; n bitset<N> f[2][64][N], g, tmp; n int main() { n   n = read(); n   m = read(); n   int u, v, w; n   for (int i = 1; i <= m; ++i) { n     u = read(); n     v = read(); n     w = read(); n     f[w][0][u][v] = 1; n   } n   for (int i = 1; i <= 60; ++i) n     for (int u = 1; u <= n; ++u) n       for (int v = 1; v <= n; ++v) { n         if (f[0][i - 1][u][v]) f[0][i][u] |= f[1][i - 1][v]; n         if (f[1][i - 1][u][v]) f[1][i][u] |= f[0][i - 1][v]; n       } n   if (f[0][60][1].count()) { n     puts( -1 ); n     return 0; n   } n   now = 0; n   tmp[1] = 1; n   Pow[0] = 1; n   for (int i = 1; i <= 60; ++i) Pow[i] = Pow[i - 1] << 1; n   for (int i = 60; i >= 0; --i) { n     g.reset(); n     for (int j = 1; j <= n; ++j) n       if (tmp[j]) g |= f[now][i][j]; n     if (g.count()) { n       now ^= 1; n       tmp = g; n       ans += Pow[i]; n     } n   } n   if (ans > inf) n     puts( -1 ); n   else n     printf( %lld , ans); n } n


#include <bits/stdc++.h> n using namespace std; n const int mod = 1000000007; n int n, fa[1200000], sf[1200000], len[1200000], f[1200000], g[1200000], n     diff[1200000], c[1200000][30], p, np, cnt; n char s[1200000], a[1200000]; n void upd(int &x, int y) { x = (x + y) % mod; } n int main() { n   scanf( %s , s + 1); n   n = strlen(s + 1); n   for (int i = 1; i <= n / 2; ++i) { n     a[i * 2 - 1] = s[i]; n     a[i * 2] = s[n - i + 1]; n   } n   fa[0] = 1; n   len[0] = 0; n   fa[1] = 1; n   len[1] = -1; n   np = cnt = 1; n   f[0] = 1; n   for (int i = 1; i <= n; ++i) { n     int w = a[i] -  a ; n     for (p = np; a[i] != a[i - len[p] - 1]; p = fa[p]) n       ; n     if (!c[p][w]) { n       int q = fa[p], now = ++cnt; n       len[now] = len[p] + 2; n       for (; a[i] != a[i - len[q] - 1]; q = fa[q]) n         ; n       fa[now] = c[q][w]; n       diff[now] = len[now] - len[fa[now]]; n       c[p][w] = np = now; n       sf[now] = diff[now] == diff[fa[now]] ? sf[fa[now]] : fa[now]; n     } else n       np = c[p][w]; n     for (int q = np; q; q = sf[q]) { n       g[q] = f[i - len[sf[q]] - diff[q]]; n       if (diff[q] == diff[fa[q]]) upd(g[q], g[fa[q]]); n       upd(f[i], g[q]); n     } n     if (i & 1) f[i] = 0; n   } n   printf( %d n , f[n]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 5000 + 5; n const int inf = 0x3f3f3f3f; n const int Max = 200000; n template <class T> n inline void getin(T& num) { n   char c; n   bool flag = 0; n   num = 0; n   while ((c = getchar()) <  0  || c >  9 ) n     if (c ==  - ) flag = 1; n   while (c >=  0  && c <=  9 ) { n     num = num * 10 + c - 48; n     c = getchar(); n   } n   if (flag) num = -num; n } n int n, k, a, x, y, m; n queue<int> num[N]; n set<pair<int, int> > output; n vector<pair<int, int> > Ans; n int main() { n   getin(n); n   int sum = 0, ans = 0; n   for (int i = 1; i <= n; i++) { n     getin(k), getin(a), sum += k; n     getin(x), getin(y), getin(m); n     num[i].push(a); n     int ret = 0; n     for (int j = 2; j <= k; j++) { n       int nxt = (1ll * a * x % m + y) % m; n       if (nxt < a) ret++; n       num[i].push(a = nxt); n     } n     ans = max(ans, ret); n   } n   printf( %d n , ans); n   if (sum > Max) return 0; n   for (int i = 1; i <= n; i++) { n     output.insert(make_pair(num[i].front(), i)); n     num[i].pop(); n   } n   int last = -inf, p; n   for (int i = 1; i <= sum; i++) { n     set<pair<int, int> >::iterator it = n         output.lower_bound(make_pair(last, -inf)); n     if (it == output.end()) ans++, it = output.begin(); n     Ans.push_back(*it); n     last = (*it).first; n     p = (*it).second; n     output.erase(it); n     if (!num[p].empty()) { n       output.insert(make_pair(num[p].front(), p)); n       num[p].pop(); n     } n   } n   for (int i = 0; i < sum; i++) printf( %d %d n , Ans[i].first, Ans[i].second); n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 50 + 5; n const int oo = 1000000000; n bool u[N][N]; n int n, m; n int ans = -1; n int a[N][N], l[N][N]; n int d[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}}; n char s[N]; n struct pis { n   int x, y; n   pis() {} n   pis(int x, int y) : x(x), y(y) {} n } f[10 * N * N]; n inline int Solve(int x, int y) { n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= m; j++) l[i][j] = oo; n   int front = 0, top = 1; n   f[1] = pis(x, y); n   l[x][y] = 0; n   while (front < top) { n     pis p = f[++front]; n     u[p.x][p.y] = 0; n     for (int i = 0; i < 4; i++) { n       int dx = p.x + d[i][0]; n       int dy = p.y + d[i][1]; n       if (dx >= 1 && dx <= n && dy >= 1 && dy <= m) { n         int dis = a[p.x][p.y] != a[dx][dy]; n         if (l[p.x][p.y] + dis < l[dx][dy]) { n           l[dx][dy] = l[p.x][p.y] + dis; n           if (!u[dx][dy]) { n             u[dx][dy] = 1; n             f[++top] = pis(dx, dy); n           } n         } n       } n     } n   } n   int MAX = 0; n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= m; j++) n       if (a[i][j] && l[i][j] > MAX) MAX = l[i][j]; n   return MAX; n } n int main() { n   scanf( %d %d , &n, &m); n   for (int i = 1; i <= n; i++) { n     scanf( %s , s); n     for (int j = 1; j <= m; j++) { n       if (s[j - 1] ==  B ) ans = oo; n       a[i][j] = s[j - 1] ==  W  ? 0 : 1; n     } n   } n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= m; j++) ans = min(ans, Solve(i, j)); n   printf( %d n , ans + 1); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 0x3f3f3f3f; n const int maxn = 1e5 + 7; n int n, x; n int main() { n   cin >> n >> x; n   int ans = 0, num = 0; n   if (n == 2 && x == 0) { n     puts( NO ); n     return 0; n   } n   puts( YES ); n   if (n == 1) n     printf( %d , x); n   else if (n == 2) n     printf( %d %d , 0, x); n   else if (n == 3) { n     int t1 = 1 << 18; n     int t2 = 1 << 19; n     int t3 = x ^ t1 ^ t2; n     printf( %d %d %d , t1, t2, t3); n   } else { n     for (int i = 1;; i++) { n       if (i == x) continue; n       ans ^= i; n       printf( %d  , i); n       num++; n       if (num == n - 3) break; n     } n     int t1 = 1 << 18; n     int t2 = 1 << 19; n     int t3 = x ^ ans ^ t1 ^ t2; n     printf( %d %d %d , t1, t2, t3); n     ans ^= t1 ^ t2 ^ t3; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n mt19937 mt_rand(time(0)); n const int N = 105; n int t, n; n char a[N], b[N], c[N]; n int main() { n   scanf( %d , &t); n   while (t--) { n     scanf( %s%s%s , a, b, c); n     n = 0; n     while (a[n]) n++; n     bool ok = 1; n     for (int i = 0; i < n; i++) { n       if (c[i] == a[i] || c[i] == b[i]) n         ; n       else n         ok = 0; n     } n     if (!ok) n       printf( NO n ); n     else n       printf( YES n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n string str; n int memo[100005][3]; n int dp(int Idx, int prev) { n   if (Idx == (int)str.size()) return 0; n   int choice1 = 1000000; n   if (memo[Idx][prev] != -1) return memo[Idx][prev]; n   if (prev == 0) { n     if (isupper(str[Idx])) n       choice1 = dp(Idx + 1, 0) + 1; n     else n       choice1 = dp(Idx + 1, 0); n   } else { n     if (isupper(str[Idx])) { n       choice1 = min(dp(Idx + 1, 0) + 1, dp(Idx + 1, 1)); n     } else n       choice1 = min(dp(Idx + 1, 0), dp(Idx + 1, 1) + 1); n   } n   return memo[Idx][prev] = choice1; n } n int main() { n   cin >> str; n   memset(memo, -1, sizeof(memo)); n   int ans = dp(0, 1); n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n double p; n bool in_memo[200 + 1][230 + 1][2][1 << 8]; n double memo[200 + 1][230 + 1][2][1 << 8]; n double E(int k, int lead_count, bool lead_parity, int mask) { n   double& ans = memo[k][lead_count][lead_parity][mask]; n   if (not in_memo[k][lead_count][lead_parity][mask]) { n     if (k == 0) { n       ans = mask ? __builtin_ctz(mask) : 8 + (lead_parity ? 0 : lead_count); n     } else { n       ans = p / 100 * n                 E(k - 1, n                   bool((mask & (1 << 7)) >> 7) == lead_parity ? lead_count + 1 n                                                               : 1, n                   (mask & (1 << 7)) >> 7, (mask * 2) & 0b11111111) + n             (100 - p) / 100 * n                 E(k - 1, n                   mask == 0b11111111 ? (lead_parity ? lead_count : 1) n                                      : lead_count, n                   lead_parity ^ (mask == 0b11111111), (mask + 1) & 0b11111111); n     } n     in_memo[k][lead_count][lead_parity][mask] = true; n   } n   return ans; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int x, k; n   cin >> x >> k >> p; n   memset(in_memo, false, sizeof in_memo); n   cout << fixed << setprecision(7) n        << E(k, __builtin_ctz((x >> 8) & 1 ? (x >> 8) + 1 : x >> 8), n             (x >> 8) & 1, x & 0b11111111) n        <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class S, class T> n ostream& operator<<(ostream& st, pair<S, T> p) { n   st <<  (  << p.first <<  ,  << p.second <<  ) ; n   return st; n } n template <class T> n ostream& operator<<(ostream& st, vector<T> v) { n   st <<  [ ; n   for (size_t i = 0; i < v.size(); ++i) { n     if (i != 0) { n       st <<  ,  ; n     } n     st << v[i]; n   } n   st <<  ] ; n   return st; n } n pair<int, int> get_parent_dsu(int v, vector<pair<int, int> >& parents) { n   if (parents[v].first != v) { n     pair<int, int> p = get_parent_dsu(parents[v].first, parents); n     parents[v] = make_pair(p.first, p.second ^ parents[v].second); n   } n   return parents[v]; n } n void union_dsu(int a, int b, int value, vector<int>& mass, n                vector<pair<int, int> >& parents) { n   pair<int, int> a_parent = get_parent_dsu(a, parents); n   pair<int, int> b_parent = get_parent_dsu(b, parents); n   a = a_parent.first; n   int a_dist = a_parent.second; n   b = b_parent.first; n   int b_dist = b_parent.second; n   if (a != b) { n     if (mass[a] > mass[b]) { n       swap(a, b); n       swap(a_dist, b_dist); n     } n     parents[a].first = b; n     parents[a].second = value ^ a_dist ^ b_dist; n     mass[b] += mass[a]; n   } n } n int perform_get_query(int a, int b, vector<pair<int, int> >& parents) { n   pair<int, int> a_parent = get_parent_dsu(a, parents); n   pair<int, int> b_parent = get_parent_dsu(b, parents); n   int result; n   if (a_parent.first == b_parent.first) { n     result = a_parent.second ^ b_parent.second; n   } else { n     result = -1; n   } n   return result; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   srand(time(0)); n   int q; n   cin >> q; n   int mapper_size = 0; n   map<int, int> mapper; n   vector<int> mass; n   vector<pair<int, int> > parents_dsu; n   int last = 0; n   for (int i = 0; i < q; ++i) { n     int t; n     cin >> t; n     int l, r, value; n     cin >> l >> r; n     l = l ^ last; n     r = r ^ last; n     if (l > r) { n       swap(l, r); n     } n     --l; n     if (mapper.count(l) == 0) { n       mass.push_back(1); n       parents_dsu.push_back(make_pair(mapper_size, 0)); n       mapper[l] = mapper_size++; n     } n     if (mapper.count(r) == 0) { n       mass.push_back(1); n       parents_dsu.push_back(make_pair(mapper_size, 0)); n       mapper[r] = mapper_size++; n     } n     int a = mapper[l]; n     int b = mapper[r]; n     if (t == 1) { n       cin >> value; n       value = last ^ value; n       union_dsu(a, b, value, mass, parents_dsu); n     } else { n       last = perform_get_query(a, b, parents_dsu); n       cout << last << endl; n       if (last == -1) { n         last = 1; n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxx = 1e5 + 7; n const int Inf = 1 << 30; n const long long INF = 1ll << 60; n int n; n int a[maxx]; n vector<int> vec; n int pos[maxx]; n map<int, int> mp; n int ans; n int main() { n   cin >> n; n   for (int i = 1; i <= n; i++) cin >> a[i]; n   int cnt = 0; n   int t = 0; n   bool flg = 0; n   for (int i = 1; i <= n; i++) { n     if (a[i] == 1) { n       if (!flg) pos[++t] = i; n       flg = 1; n       cnt++; n     } else { n       if (cnt) vec.push_back(cnt); n       cnt = 0; n       flg = 0; n     } n     if (i == n && a[i] == 1) vec.push_back(cnt); n   } n   for (int i = 0; i < vec.size(); i++) mp[pos[i + 1]] = vec[i]; n   int pp = pos[1] - 1; n   int minx = min(pp, mp[pos[1]]); n   ans = max(ans, 2 * minx); n   for (int i = 1; i <= t; i++) { n     int tmp; n     if (i == 1) n       tmp = minx; n     else n       tmp = pos[i] - (pos[i - 1] + mp[pos[i - 1]]); n     int min1 = min(tmp, mp[pos[i]]); n     int min2 = min(tmp, mp[pos[i - 1]]); n     int minT = max(min1, min2); n     ans = max(ans, 2 * minT); n   } n   int dd = n - (pos[t] + mp[pos[t]] - 1); n   int min0 = min(dd, mp[pos[t]]); n   ans = max(ans, 2 * min0); n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int MOD = 1e9 + 7; n const int MAXN = 1e6 + 10; n int fac[MAXN], infac[MAXN]; n long long pow_mod(long long a, long long b) { n   long long res = 1; n   while (b) { n     if (b & 1) res = res * a % MOD; n     a = a * a % MOD; n     b >>= 1; n   } n   return res; n } n int add(int a, int b) { return (a + b) % MOD; } n int mul(int a, int b) { return 1LL * a * b % MOD; } n int C(int a, int b) { return mul(fac[a], mul(infac[b], infac[a - b])); } n int A(int a, int b) { return mul(fac[a], infac[a - b]); } n int F(int a, int b) { n   if (a == b) return 1; n   return mul(b, pow_mod(a, a - b - 1)); n } n int main() { n   int n, m, a, b; n   fac[0] = 1; n   for (int i = 1; i <= 1000000; i++) { n     fac[i] = mul(i, fac[i - 1]); n   } n   infac[1000000] = pow_mod(fac[1000000], MOD - 2); n   for (int i = 1000000; i >= 1; i--) { n     infac[i - 1] = mul(infac[i], i); n   } n   scanf( %d%d%d%d , &n, &m, &a, &b); n   int ans = 0; n   for (int i = 1; i <= n - 1; i++) { n     if (i > m) { n       continue; n     } n     ans = add(ans, mul(mul(pow_mod(m, n - 1 - i), F(n, i + 1)), n                        mul(A(n - 2, i - 1), C(m - 1, i - 1)))); n   } n   printf( %d , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a[5000 + 10]; n int main() { n   int n; n   cin >> n; n   for (int i = 1; i < n + 1; i++) cin >> a[i]; n   bool flag = false; n   for (int i = 1; i < n; i++) { n     if (a[a[a[i]]] == i) { n       flag = true; n       break; n     } n   } n   if (flag) n     cout <<  YES ; n   else n     cout <<  NO ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 100004; n unsigned long long a, b, c = 0, x = 0, y = 0; n bool f = 1; n void solve() { n   int c = 0; n   for (int i = 0; i < 64; i++) { n     if (b >> i & 1) y |= 1ll << i; n   } n   a -= y; n   for (int i = 1; i < 64; i++) { n     int r = a >> i & 1, s = b >> (i - 1) & 1; n     if (r == 1) { n       if (s == 0) { n         x |= 1ll << (i - 1); n         y |= 1ll << (i - 1); n       } else { n         f = 0; n         break; n       } n     } n   } n } n int main() { n   cin >> a >> b; n   solve(); n   if (!f) n     puts( -1 ); n   else n     printf( %llu %llu , x, y); n } n


#include <bits/stdc++.h> n using namespace std; n long long nsd(long long a, long long b) { n   while (b != 0) { n     a = a % b; n     swap(a, b); n   } n   return a; n } n long long nsk(long long a, long long b) { return a / nsd(a, b) * b; } n bool cmp(long long a, long long b) { return a > b; } n void sorts(string& str) { sort(str.begin(), str.end()); } n long long sumd(long long n) { n   if (n < 0) { n     n = -n; n   } n   long long s = 0; n   while (n != 0) { n     n /= 10; n     s++; n   } n   return s; n } n int suma(long long n) { n   int s = 0; n   while (n != 0) { n     s += n % 10; n     n /= 10; n   } n   return s; n } n long long fact(long long n) { n   if (n == 1) n     return 1; n   else n     return n * fact(n - 1); n } n int factnum(int n) { n   int c = 0; n   for (int i = 5; n / i >= 1; i *= 5) c += n / i; n   return c; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int n; n   cin >> n; n   string s; n   cin >> s; n   cout << abs(count(s.begin(), s.end(),  1 ) - count(s.begin(), s.end(),  0 )); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int i, j, n; n   cin >> n; n   long long int arr[n]; n   vector<long long int> vec[100010]; n   for (i = 0; i < n; i++) { n     cin >> arr[i]; n     vec[arr[i]].push_back(i); n   } n   long long int y = 0, d; n   for (i = 0; i < 100010; i++) { n     long long int x = 0; n     if (vec[i].size() >= 2) { n       d = vec[i][1] - vec[i][0]; n       for (j = 1; j < vec[i].size(); j++) { n         if (d == (vec[i][j] - vec[i][j - 1])) { n           ++x; n         } n       } n       if ((x + 1) == vec[i].size()) { n         ++y; n       } n     } else if (vec[i].size() == 1) { n       ++y; n     } else { n       continue; n     } n   } n   cout << y << endl; n   vector<long long int> vec1[100010]; n   long long int z = 0; n   for (i = 0; i < 100010; i++) { n     long long int x = 0; n     d = 0; n     if (vec[i].size() >= 2) { n       d = vec[i][1] - vec[i][0]; n       for (j = 1; j < vec[i].size(); j++) { n         if (d == (vec[i][j] - vec[i][j - 1])) { n           ++x; n         } n       } n       if ((x + 1) == vec[i].size()) { n         cout << i <<     << d << endl; n       } n     } else if (vec[i].size() == 1) { n       cout << i <<     << d << endl; n     } else { n       continue; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char s[1005]; n int main() { n   int n, f = 1; n   char *p, *q; n   scanf( %s , s); n   n = strlen(s); n   p = s; n   q = s + n - 1; n   while (p <= q) { n     if (*p == *q) { n       p++; n       q--; n     } else { n       f = 0; n       break; n     } n   } n   printf( %s , s); n   if (!f) { n     for (int i = n - 1; i >= 0; i--) printf( %c , s[i]); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n void read(vector<T> &a, long long n) { n   T x; n   a.clear(); n   for (long long i = 0; i < n; i++) { n     cin >> x; n     a.push_back(x); n   } n } n template <class T> n void write(vector<T> &a) { n   for (T x : a) cout << x <<    ; n   cout << endl; n } n int main() { n   ios_base::sync_with_stdio(0); n   int T; n   cin >> T; n   while (T--) { n     int n, m; n     vector<int> a, b; n     cin >> n >> n >> m; n     read(a, n); n     read(b, m); n     sort(a.begin(), a.end()); n     sort(b.begin(), b.end()); n     if (a.back() > b.back()) n       cout <<  YES  << endl; n     else n       cout <<  NO  << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 2e5 + 5; n const int inf = 1e9 + 7; n long long minv[1 << 16]; n long long numx[15], numy[15]; n long long n, a[maxn], x, y, A, B, facy[15000], ans; n inline long long read() { n   char ch = getchar(); n   long long u = 0, f = 1; n   while (!isdigit(ch)) { n     if (ch ==  - ) f = -1; n     ch = getchar(); n   } n   while (isdigit(ch)) { n     u = u * 10 + ch - 48; n     ch = getchar(); n   } n   return u * f; n } n inline long long gcd(long long x, long long y) { n   return y == 0 ? x : gcd(y, x % y); n } n inline long long mul(long long x, long long y, long long p) { n   long long cnt = 0; n   while (y) { n     if (y & 1) cnt = (cnt + x) % p; n     x = (x + x) % p; n     y >>= 1; n   } n   return cnt; n } n inline long long ksm(long long x, long long k, long long p) { n   long long cnt = 1; n   while (k) { n     if (k & 1) cnt = mul(cnt, x, p); n     x = mul(x, x, p); n     k >>= 1; n   } n   return cnt; n } n inline bool judge(long long a, long long p) { n   long long q = p - 1; n   int k = 0; n   while (q % 2 == 0) ++k, q >>= 1; n   long long v = ksm(a, q, p); n   if (v == 1 || v == p - 1) return false; n   while (k-- != 0) { n     v = mul(v, v, p); n     if (v == p - 1) return false; n   } n   return true; n } n inline bool miller_rabbin(long long p) { n   if (p == 2) return true; n   if (p % 2 == 0) return false; n   for (register int i = 1; i <= 60; i++) { n     long long a = rand() % (p - 1) + 1; n     if (judge(a, p)) return false; n   } n   return true; n } n const int M = (1 << 7) - 1; n inline long long pollard_rho(long long n) { n   if (n % 2 == 0) return 2; n   if (n % 3 == 0) return 3; n   long long x = 0, y = x, t = 1, q = 1, a = (rand() % (n - 1)) + 1; n   for (int k = 2;; k <<= 1, y = x, q = 1) { n     for (int i = 1; i <= k; ++i) { n       x = (mul(x, x, n) + a) % n; n       q = mul(q, abs(x - y), n); n       if (!(i & M)) { n         t = gcd(q, n); n         if (t > 1) break; n       } n     } n     if (t > 1 || (t = gcd(q, n)) > 1) break; n   } n   if (t == n) { n     t = 1; n     while (t == 1) t = gcd(abs((x = ((mul(x, x, n) + a) % n)) - y), n); n   } n   return t; n } n inline void findfac(long long x) { n   if (x == 1) return; n   if (miller_rabbin(x)) { n     facy[++facy[0]] = x; n     return; n   } n   long long p = x; n   while (p >= x) p = pollard_rho(p); n   findfac(p); n   findfac(x / p); n } n inline void dEBUG(long long *x, long long len) { n   cerr <<  ----------------------------------DEBUG-----------------------------  n            -----  n        << endl; n   for (register int i = 0; i <= len; i++) cerr << x[i] <<    ; n   cerr << endl; n   cerr <<  ----------------------------------DEBUG-----------------------------  n            -----  n        << endl; n } n int main() { n   srand(19260817); n   n = read(); n   A = x = read(); n   B = y = read(); n   if (y % x != 0) { n     cout << 0; n     return 0; n   } n   for (register int i = 1; i <= n; i++) a[i] = read(); n   if (B != 100000000000123502ll) { n     findfac(B); n     sort(facy + 1, facy + 1 + facy[0]); n     facy[0] = unique(facy + 1, facy + 1 + facy[0]) - facy - 1; n   } else { n     for (register int i = 2; 1ll * i * i <= B; i++) { n       if (B % i == 0) facy[++facy[0]] = i; n       while (B % i == 0) B /= i; n     } n     if (B != 1) facy[++facy[0]] = B; n     B = y; n   } n   for (register int i = 1; i <= facy[0]; i++) n     while (B % facy[i] == 0) B /= facy[i], numy[i]++; n   for (register int i = 1; i <= facy[0]; i++) n     while (A % facy[i] == 0) A /= facy[i], numx[i]++; n   for (register int i = 1; i <= n; i++) { n     if (a[i] % x != 0) continue; n     int maskx = 0; n     long long T = a[i]; n     for (register int k = 1; k <= facy[0]; k++) { n       int p = 0; n       if (numx[k] == numy[k]) continue; n       while (T % facy[k] == 0) T /= facy[k], p++; n       maskx |= ((p > numx[k]) << (k - 1)); n     } n     minv[maskx]++; n   } n   for (register int i = 0; i < facy[0]; i++) n     for (register int G = 0; G < (1 << facy[0]); G++) n       if (G & (1 << i)) minv[G] += minv[G ^ (1 << i)]; n   int MK = (1 << facy[0]) - 1; n   for (register int i = 1; i <= n; i++) { n     if (y % a[i] != 0) continue; n     int masky = 0; n     long long T = a[i]; n     for (register int k = 1; k <= facy[0]; k++) { n       int p = 0; n       while (T % facy[k] == 0) T /= facy[k], p++; n       masky |= ((p < numy[k]) << (k - 1)); n     } n     ans += minv[masky ^ MK]; n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); n   int n; n   cin >> n; n   long long a[n], sum = 0; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n     sum += a[i]; n   } n   if (sum % 2 == 1 || n == 1) { n     cout <<  NO ; n   } else { n     sum /= 2; n     long long temp1 = 0, temp2; n     map<long long, bool> m1, m2; n     bool flag = false; n     for (int i = 0, j = n - 1; i < n, j >= 0; i++, j--) { n       temp1 += a[i]; n       temp2 += a[j]; n       if (temp1 == sum || temp2 == sum) { n         flag = true; n         break; n       } n       if (temp1 > sum) { n         if (m1[temp1 - sum] == 1) { n           flag = true; n           break; n         } n       } n       if (temp2 > sum) { n         if (m2[temp2 - sum] == 1) { n           flag = true; n           break; n         } n       } n       m1[a[i]] = 1; n       m2[a[j]] = 1; n     } n     if (flag == true) { n       cout <<  YES ; n     } else { n       cout <<  NO ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   double a, b, c; n   while (cin >> a >> b >> c) { n     double m = a * c; n     cout << ceil(m / b) - c << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n using namespace rel_ops; n using ll = int64_t; n using Pii = pair<int, int>; n using ull = uint64_t; n using Vi = vector<int>; n void run(); n int main() { n   cin.sync_with_stdio(0); n   cin.tie(0); n   cout << fixed << setprecision(10); n   run(); n   return 0; n } n int uplg(int n) { return 32 - __builtin_clz(n); } n int uplg(ll n) { return 64 - __builtin_clzll(n); } n int cmp(double a, double b, double eps = 1e-9) { n   return (a > b + eps) - (a + eps < b); n } n constexpr ll MOD = 998244353; n struct Zp { n   ll first; n   Zp(ll a = 0) { n     if (a < 0) n       a = a % MOD + MOD; n     else if (a >= MOD * 2) n       a %= MOD; n     else if (a >= MOD) n       a -= MOD; n     first = a; n   } n   Zp operator+(Zp r) const { return first + r.first; } n   Zp operator-(Zp r) const { return first - r.first + MOD; } n   Zp operator*(Zp r) const { return first * r.first; } n   Zp operator/(Zp r) const { return first * r.inv().first; } n   Zp operator-() const { return MOD - first; } n   Zp inv() const { return pow(MOD - 2); } n   Zp pow(ll e) const { n     Zp t = 1, m = *this; n     while (e) { n       if (e & 1) t = t * m; n       e >>= 1; n       m = m * m; n     } n     return t; n   } n   Zp& operator+=(Zp r) { return *this = *this + r; } n   Zp& operator-=(Zp r) { return *this = *this - r; } n   Zp& operator*=(Zp r) { return *this = *this * r; } n   Zp& operator/=(Zp r) { return *this = *this / r; } n   void print() { cerr << first; } n }; n struct Vert { n   Vi E; n   Zp f, g; n }; n vector<Vert> G; n void dfs(int v, int par) { n   Zp p = 1, sum = 0; n   for (auto& e : (G[v].E)) n     if (e != par) { n       dfs(e, v); n       p *= Zp(1) - G[e].g / 2; n       sum += G[e].f; n     } n   G[v].f = sum + 1 - p; n   G[v].g = p; n } n void run() { n   int n; n   cin >> n; n   G.resize(n); n   for (int i = (1); i < (n); i++) { n     int a, b; n     cin >> a >> b; n     G[a - 1].E.push_back(b - 1); n     G[b - 1].E.push_back(a - 1); n   } n   dfs(0, -1); n   cout << (G[0].f * Zp(2).pow(n)).first << endl; n } n


#include <bits/stdc++.h> n using namespace std; n ifstream input; n ofstream output; n int main(int argc, char *argv[]) { n   input.sync_with_stdio(false); n   output.sync_with_stdio(false); n   int n, tmp, tmp2; n   priority_queue<int> y; n   set<int> used; n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> tmp; n     y.push(tmp); n     used.insert(tmp); n   } n   while (1) { n     tmp = y.top(); n     tmp2 = tmp; n     y.pop(); n     while (tmp > 1) { n       if (used.find(tmp / 2) == used.end()) { n         used.insert(tmp / 2); n         used.erase(tmp2); n         y.push(tmp / 2); n         break; n       } n       tmp /= 2; n     } n     if (tmp == 1) { n       y.push(tmp2); n       break; n     } n   } n   while (y.size()) { n     cout << y.top() <<    ; n     y.pop(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MOD = 1e9 + 7; n const int INF = INT_MAX; n const int MAX = 4e6 + 5; n const int N = 1e5 + 5; n long long dx[] = {-1, 0, 1, 0, -1, -1, 1, 1}; n long long dy[] = {0, 1, 0, -1, -1, 1, 1, -1}; n char dir[] = { U ,  R ,  D ,  L }; n long long power(long long a, long long b); n long long powmod(long long a, long long b, long long mod); n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   long long t; n   cin >> t; n   while (t--) { n     long long n, k; n     cin >> n >> k; n     long long a[n]; n     set<long long> s; n     for (long long i = 0; i < n; i++) { n       cin >> a[i]; n       s.insert(a[i]); n     } n     if (s.size() > k) n       cout << -1 <<   n ; n     else if (n == k) { n       cout << k <<   n ; n       for (long long i = 0; i < n; i++) cout << a[i] <<    ; n       cout <<   n ; n     } else { n       vector<long long> tmp, res; n       for (auto x : s) tmp.push_back(x); n       long long m = tmp.size(); n       if (m < k) { n         for (long long i = 0; i < k - m; i++) { n           tmp.push_back(tmp[m - 1]); n         } n       } n       m = tmp.size(); n       long long i = 0, j = 0; n       while (i < n && j % m < m) { n         if (a[i] == tmp[j % m]) { n           res.push_back(a[i]); n           i += 1; n           j += 1; n         } else { n           res.push_back(tmp[j % m]); n           j += 1; n         } n       } n       cout << res.size() <<   n ; n       for (auto x : res) cout << x <<    ; n       cout <<   n ; n     } n   } n } n long long power(long long a, long long b) { n   long long res = 1; n   while (b > 0) { n     if (b % 2) res *= a; n     b /= 2, a *= a; n   } n   return res; n } n long long powmod(long long a, long long b, long long mod) { n   long long res = 1; n   while (b > 0) { n     if (b % 2) res *= (a % mod); n     b /= 2, a *= (a % mod); n   } n   return res % mod; n } n


#include <bits/stdc++.h> n using namespace std; n struct Point { n   double x, y; n   Point() {} n   Point(double _x, double _y) : x(_x), y(_y) {} n }; n struct Point p0, p1, p2; n double dist(Point a, Point b) { n   return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y)); n } n double check(Point s, Point e, Point m, double t) { n   if (dist(s, m) + dist(m, e) <= t + dist(s, e)) n     return dist(s, e) + t - dist(m, e); n   double l = 0.0, r = 1.0, mid; n   for (int i = 0; i <= 1000; i++) { n     mid = (l + r) / 2; n     Point p = Point{s.x + mid * (m.x - s.x), s.y + mid * (m.y - s.y)}; n     if (dist(s, p) + dist(p, e) <= t + dist(s, e)) n       l = mid; n     else n       r = mid; n   } n   return mid * dist(s, m); n } n int main() { n   double t1, t2, x, y; n   scanf( %lf%lf , &t1, &t2); n   scanf( %lf%lf , &x, &y); n   p0 = {x, y}; n   scanf( %lf%lf , &x, &y); n   p1 = {x, y}; n   scanf( %lf%lf , &x, &y); n   p2 = {x, y}; n   double ans = 0.0; n   ans = max(ans, min(check(p0, p1, p1, t2), check(p0, p2, p1, t1))); n   ans = max(ans, min(check(p0, p1, p2, t2), check(p0, p2, p2, t1))); n   if (dist(p0, p2) + dist(p2, p1) <= t2 + dist(p0, p1)) { n     ans = max(ans, min(dist(p0, p1) + t2, dist(p0, p2) + dist(p2, p1) + t1)); n   } n   double low = 0.0, high = 1.0, mid, midd; n   for (int i = 1; i <= 1000; i++) { n     mid = low + (high - low) / 3; n     midd = high - (high - low) / 3; n     Point a = Point(p1.x + (p2.x - p1.x) * mid, p1.y + (p2.y - p1.y) * mid); n     Point b = Point(p1.x + (p2.x - p1.x) * midd, p1.y + (p2.y - p1.y) * midd); n     double r1 = min(check(p0, p1, a, t2), check(p0, p2, a, t1)); n     double r2 = min(check(p0, p1, b, t2), check(p0, p2, b, t1)); n     if (r1 > r2) n       high = midd, ans = max(ans, r1); n     else n       low = mid, ans = max(ans, r2); n   } n   printf( %.10f n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int a, b, c, d; n   cin >> a >> b >> c >> d; n   if (2 * c < d || 2 * d < c || d >= b) n     cout <<  -1 ; n   else { n     cout << 2 * a << endl << 2 * b << endl; n     if (c > d) n       cout << c; n     else n       cout << d; n   } n   return 0; n } n