#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 7; n const int xinc[] = {0, 0, 1, -1}; n const int yinc[] = {1, -1, 0, 0}; n const long double PI = acos(-1.0); n int n, k; n void solve() { n   cin >> n >> k; n   int d = n - k; n   if (k == 1) { n     cout << 1; n     for (int i = 0; i < n - 1; i++) cout << 0; n     cout <<   n ; n     return; n   } n   d /= 2; n   string p =  1 ; n   for (int i = 0; i < d; i++) p +=  0 ; n   int z = p.size(); n   for (int i = 0; i < n; i++) cout << p[i % z]; n   cout <<   n ; n } n signed main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   int t; n   t = 1; n   while (t--) solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct info { n   double val; n   string a; n }; n vector<info> t; n int n, x, y, hcnt, sumh; n double aa; n long long res = 0; n bool cmp(const info &u, const info &v) { return u.val > v.val; } n int main() { n   string a; n   cin >> n; n   for (int i = 0; i < n; i++) { n     x = y = 0; n     cin >> a; n     for (int j = 0; a[j]; j++) n       if (a[j] ==  s ) n         x++; n       else if (a[j] ==  h ) n         y++; n     sumh += y; n     if (y == 0) n       aa = 2e9; n     else n       aa = (double)x / y; n     t.push_back({aa, a}); n   } n   sort(t.begin(), t.end(), cmp); n   int Size = t.size(); n   for (int i = 0; i < Size; i++) { n     int sSize = t[i].a.size(); n     for (int j = 0; j < sSize; j++) { n       if (t[i].a[j] ==  h ) n         sumh--; n       else if (t[i].a[j] ==  s ) n         res += sumh; n     } n   } n   cout << res; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 200100; n const long long oo = 2e18; n long long i, n, m, l, r, mid; n long long a[N], f[N][2]; n inline long long read() { n   long long x = 0, f = 0, c = getchar(); n   for (; c >  9  || c <  0 ; f = c ==  - , c = getchar()) n     ; n   for (; c >=  0  && c <=  9 ; c = getchar()) x = (x << 1) + (x << 3) + c -  0 ; n   return f ? -x : x; n } n bool check(long long x) { n   long long i, k1, k2, start0 = 0, start1 = 0; n   while (start0 <= x) { n     if (!start0) n       f[0][0] = -x; n     else n       f[0][0] = start0; n     f[0][1] = start1; n     for (i = 1; i <= n; i++) f[i][0] = oo, f[i][1] = 0; n     for (i = 0; i < n; i++) { n       if (f[i][0] > x) return 0; n       if (f[i][0] > 0) n         k1 = a[i + 1] - a[i] + f[i][0]; n       else { n         k1 = a[i + 1] - a[i] - x; n         if (k1 > 0) k1--; n       } n       if (k1 < 0) n         f[i + 1][0] = -x; n       else n         f[i + 1][0] = min(f[i + 1][0], k1); n       k2 = a[i + 1] - a[i] + f[i][1]; n       if (k2 > 0) k2--; n       if (k2 < 0) n         f[i + 1][0] = -x; n       else n         f[i + 1][0] = min(f[i + 1][0], k2); n       if (k1 <= x) f[i + 1][1] = min(f[i + 1][1], a[i + 1] - a[i] - x); n       f[i + 1][1] = min(f[i + 1][1], k2); n     } n     if (f[n][0] <= start0 && f[n][1] <= start1) return 1; n     start0 = f[n][0]; n     start1 = f[n][1]; n   } n   return 0; n } n signed main() { n   m = read(); n   n = read(); n   for (i = 0; i < n; i++) a[i] = read(); n   a[n] = a[0] + m; n   sort(a, a + n + 1); n   l = 0; n   r = m - n; n   while (l < r) { n     mid = (l + r - 1) >> 1; n     if (check(mid)) n       r = mid; n     else n       l = mid + 1; n   } n   printf( %I64d n , l); n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX_N = 300000; n const int MAX_E2 = 1 << 20; n const long double PI = acosl(-1.0); n struct Elm { n   long double x, y, th; n   Elm() : x(0.0), y(0.0), th(0.0) {} n   Elm(long double _x, long double _y, long double _th) n       : x(_x), y(_y), th(_th) {} n   Elm &extend(int l) { n     x += l * cosl(th), y += l * sinl(th); n     return *this; n   } n   Elm &rot(long double dth) { n     long double c = cosl(dth), s = sinl(dth); n     long double x0 = c * x - s * y; n     long double y0 = s * x + c * y; n     x = x0, y = y0; n     th += dth; n     return *this; n   } n   Elm operator+(const Elm &e) const { n     long double c = cosl(th), s = sinl(th); n     long double x0 = c * e.x - s * e.y; n     long double y0 = s * e.x + c * e.y; n     return Elm(x + x0, y + y0, th + e.th); n   } n }; n template <typename T, const int MAX_E2> n struct SegTree { n   int e2; n   T nodes[MAX_E2], defv; n   SegTree() {} n   void init(int n, T _defv) { n     defv = _defv; n     for (e2 = 1; e2 < n; e2 <<= 1) n       ; n     fill(nodes, nodes + MAX_E2, defv); n   } n   T &get(int i) { return nodes[e2 - 1 + i]; } n   void seti(int i, T v) { get(i) = v; } n   void setall() { n     for (int j = e2 - 2; j >= 0; j--) n       nodes[j] = nodes[j * 2 + 1] + nodes[j * 2 + 2]; n   } n   void set(int i, T v) { n     int j = e2 - 1 + i; n     nodes[j] = v; n     while (j > 0) { n       j = (j - 1) / 2; n       nodes[j] = nodes[j * 2 + 1] + nodes[j * 2 + 2]; n     } n   } n }; n SegTree<Elm, MAX_E2> st; n int main() { n   int n, m; n   scanf( %d%d , &n, &m); n   st.init(n, Elm(0.0, 0.0, 0.0)); n   for (int i = 0; i < n; i++) st.seti(i, Elm(1.0, 0.0, 0.0)); n   st.setall(); n   for (int i = 0; i < m; i++) { n     int x, y, z; n     scanf( %d%d%d , &x, &y, &z); n     y--; n     Elm e = st.get(y); n     if (x == 1) n       e.extend(z); n     else n       e.rot(-PI * z / 180); n     st.set(y, e); n     Elm r = st.nodes[0]; n     printf( %.10Lf %.10Lf n , r.x, r.y); n   } n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n const int N = 2e5 + 7; n map<long long, int> cnt; n bool vis[N]; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int n; n   cin >> n; n   long long a[n]; n   memset(vis, 0, sizeof(vis)); n   for (int i = 0; i < n; i++) { n     long long x; n     cin >> x; n     while (1) { n       auto it = cnt.find(x); n       if (it == cnt.end()) { n         cnt[x] = i; n         break; n       } else { n         vis[cnt[x]] = true; n         cnt.erase(it); n         x *= 2LL; n       } n     } n     a[i] = x; n   } n   vector<long long> vec; n   for (int i = 0; i < n; i++) { n     if (vis[i]) continue; n     vec.push_back(a[i]); n   } n   cout << vec.size() << endl; n   for (long long x : vec) cout << x <<    ; n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int mod = 1000 * 1000 * 1000 + 7; n long long n, m; n map<long long, long long> mp; n long long get(long long x) { n   if (x < 0) return 0; n   if (mp.find(x) != mp.end()) return mp[x]; n   long long y = x / 2, z = x - x / 2; n   mp[x] += get(y) * get(z); n   mp[x] %= mod; n   for (int i = 1; i < m; i++) { n     mp[x] += get(y - i) * get(z - m + i); n     mp[x] %= mod; n   } n   return mp[x]; n } n int main() { n   cin >> n >> m; n   mp[0] = 1; n   mp[1] = 1; n   long long ans = get(n); n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1 << 19; n double pw2[8 * N]; n struct mynum { n   double v; n   int sh; n   mynum(double _v, int _sh) { n     v = _v; n     sh = _sh; n   } n   mynum() {} n   mynum shift(int x) { return mynum(v, sh + x); } n   friend mynum operator+(mynum a, mynum b) { n     if (a.sh < b.sh) swap(a, b); n     if (b.v == 0) return a; n     if (a.v == 0) return b; n     b.v *= pw2[b.sh - a.sh + 4 * N]; n     return mynum(a.v + b.v, a.sh); n   } n }; n struct tree { n   int sh[2 * N]; n   mynum T[2 * N]; n   void push(int v) { n     if (v >= N) { n       T[v].sh += sh[v]; n       sh[v] = 0; n     } else { n       sh[2 * v] += sh[v]; n       sh[2 * v + 1] += sh[v]; n       T[v].sh += sh[v]; n       sh[v] = 0; n     } n   } n   mynum get(int l, int r, int L = 1, int R = N, int v = 1) { n     if (r < L || l > R) n       return mynum(0, 0); n     else if (l <= L && R <= r) n       return T[v].shift(sh[v]); n     else { n       push(v); n       return get(l, r, L, (L + R) / 2, 2 * v) + n              get(l, r, (L + R) / 2 + 1, R, 2 * v + 1); n     } n   } n   inline int getsh(int x) { n     int L = 1, R = N, v = 1; n     while (v < N) { n       push(v); n       if ((L + R) / 2 >= x) n         v = 2 * v, R = (L + R) / 2; n       else n         v = 2 * v + 1, L = (L + R) / 2 + 1; n     } n     return sh[v] + T[v].sh; n   } n   void ch(int l, int r, int x, int L = 1, int R = N, int v = 1) { n     if (r < L || l > R) n       return; n     else if (l <= L && R <= r) n       sh[v] += x; n     else { n       push(v); n       ch(l, r, x, L, (L + R) / 2, 2 * v); n       ch(l, r, x, (L + R) / 2 + 1, R, 2 * v + 1); n       T[v] = T[2 * v].shift(sh[2 * v]) + T[2 * v + 1].shift(sh[2 * v + 1]); n     } n   } n   tree() {} n   void init() { n     for (int i = N; i < 2 * N; i++) sh[i] = 0, T[i] = mynum(1, 0); n     for (int i = N - 1; i > 0; i--) sh[i] = 0, T[i] = T[2 * i] + T[2 * i + 1]; n   } n }; n tree TL, TR; n int main() { n   pw2[4 * N] = 1; n   for (int i = 1; i < 4 * N - 10; i++) n     pw2[4 * N + i] = pw2[4 * N + i - 1] * 2.0, n                 pw2[4 * N - i] = pw2[4 * N - i + 1] / 2.0; n   int n; n   scanf( %d , &n); n   vector<pair<int, int> > V; n   TL.init(); n   TR.init(); n   for (int i = 1; i <= n; i++) { n     int t; n     scanf( %d , &t); n     V.push_back(make_pair(-t, i)); n   } n   sort(V.begin(), V.end()); n   double ans = 0; n   for (int i = 0; i < V.size(); i++) { n     int v = -V[i].first; n     int p = V[i].second; n     mynum a = TL.get(1, p); n     int sa = TL.getsh(p); n     mynum b = TR.get(p, n); n     int sb = TR.getsh(p); n     a = a.shift(-sa); n     b = b.shift(-sb); n     assert(a.v == a.v); n     assert(b.v == b.v); n     assert(v == v); n     int tp = a.sh + b.sh; n     double res = v * a.v * b.v * pw2[4 * N + tp]; n     assert(pw2[4 * N + tp] == pw2[4 * N + tp]); n     assert(res == res); n     ans += res; n     TL.ch(1, p, -1); n     TR.ch(p, n, -1); n   } n   ans /= 2 * (double)n * (double)n; n   printf( %.10lf n , ans); n } n


#include <bits/stdc++.h> n using namespace std; n const long long MN = 505, MOD = 1000 * 1000 * 1000 + 7; n long long a[MN], dp[MN][MN]; n int32_t main() { n   long long n; n   cin >> n; n   for (long long i = 0; i < n; i++) cin >> a[i], dp[i + 1][i + 1] = 1; n   for (long long s = 1; s < n; s++) n     for (long long l = 1; l <= n - s; l++) { n       long long r = l + s; n       dp[l][r] = dp[l + 1][r]; n       for (long long i = l + 1; i < r; i++) n         if (a[i] > a[l]) (dp[l][r] += dp[l + 1][i] * dp[i][r] % MOD) %= MOD; n     } n   cout << dp[1][n]; n } n


#include <bits/stdc++.h> n using namespace std; n struct node { n   long long a, sum; n } t, tt; n vector<node> vec[300005]; n long long cost[300005], in[300005], dp[300005][2], vis[300005]; n queue<node> que; n int main(void) { n   long long i, j, n, m, a, b, c; n   long long ans; n   scanf( %lld , &n); n   ans = 0; n   for (i = 1; i <= n; i++) { n     scanf( %lld , &cost[i]); n     ans = max(ans, cost[i]); n   } n   for (i = 1; i < n; i++) { n     scanf( %lld %lld %lld , &a, &b, &c); n     in[a]++; n     in[b]++; n     t.sum = c; n     t.a = b; n     vec[a].push_back(t); n     t.a = a; n     vec[b].push_back(t); n   } n   for (i = 1; i <= n; i++) { n     if (in[i] == 1) { n       t.a = i; n       t.sum = cost[i]; n       que.push(t); n       in[i]--; n     } n   } n   while (que.size()) { n     t = que.front(); n     ans = max(ans, t.sum); n     vis[t.a] = 1; n     que.pop(); n     for (auto x : vec[t.a]) { n       if (vis[x.a] == 1) { n         continue; n       } else { n         if (dp[x.a][0] < t.sum - x.sum) { n           dp[x.a][1] = dp[x.a][0]; n           dp[x.a][0] = t.sum - x.sum; n         } else if (dp[x.a][1] < t.sum - x.sum) { n           dp[x.a][1] = t.sum - x.sum; n         } n         ans = max(ans, dp[x.a][0] + dp[x.a][1] + cost[x.a]); n         in[x.a]--; n         if (in[x.a] == 1) { n           tt.a = x.a; n           tt.sum = dp[x.a][0] + cost[x.a]; n           que.push(tt); n         } n       } n     } n   } n   printf( %lld n , ans); n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 1e6 + 9; n long long n, k; n long long a[N]; n long long ans; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cerr <<   ; n   cin >> n >> k; n   for (int i = 0; i < (n); i++) cin >> a[i], a[i]--; n   sort(a, a + n, greater<long long>()); n   long long i = 0; n   while (i < n) ans += a[i] * 2, i += k; n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int t; n   for (cin >> (t); (t)--;) { n     int n, d; n     cin >> n >> d; n     int a[n]; n     for (int i = 0; i < n; i++) cin >> a[i]; n     int ans = a[0]; n     for (int i = 1; i < n; i++) { n       int q = min(d / i, a[i]); n       ans += q; n       if (q == d / i) n         break; n       else n         d -= a[i] * i; n     } n     cout << ans <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n using pii = pair<int, int>; n using ppi = pair<int, pii>; n using vpi = vector<pii>; n const int kMod = 1e9 + 7; n struct ModInt { n   long long n; n   ModInt(long long n = 0) : n(n % kMod) {} n   ModInt operator+(const ModInt& oth) { return n + oth.n; } n   ModInt operator-(const ModInt& oth) { return n - oth.n; } n   ModInt operator*(const ModInt& oth) { return n * oth.n; } n   long long get() { return n < 0 ? n + kMod : n; } n }; n using vi = vector<ModInt>; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   ll R, G, val = 0, n = 0; n   cin >> R >> G; n   while (val <= R + G) val += ++n; n   n--; n   cerr << (int)(1000 * ((double)clock()) / CLOCKS_PER_SEC) << endl; n   vector<ll> dp(R + 1, 0); n   dp[0] = 1; n   ll ans = 0; n   for (int i = 1; i <= n; i++) { n     vector<ll> newdp(R + 1, 0); n     int tmp = (1LL * i * (i + 1)) / 2; n     for (int r = 0; r <= R; r++) { n       int g = tmp - r; n       if (r >= i) newdp[r] = dp[r - i]; n       if (g <= G) newdp[r] = (newdp[r] + dp[r]) % kMod; n     } n     dp.swap(newdp); n   } n   for (int r = 0; r <= R; r++) ans = (ans + dp[r]) % kMod; n   cerr << (int)(1000 * ((double)clock()) / CLOCKS_PER_SEC) << endl; n   cout << ans <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   string s, ans; n   cin >> s; n   ans =   ; n   for (int i = 0; i < s.size(); i++) { n     ans = ans + s[i]; n     if (s[i] ==  a  || s[i] ==  e  || s[i] ==  i  || s[i] ==  o  || n         s[i] ==  u  || s[i] ==  y ) { n       for (int j = i; j < s.size(); j++) { n         if (s[j] ==  a  || s[j] ==  e  || s[j] ==  i  || s[j] ==  o  || n             s[j] ==  u  || s[j] ==  y ) { n           i = j; n         } else { n           break; n         } n       } n     } n   } n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int mod = 1000000007, maxn = 110; n int n, k, mat[maxn], fact[maxn], dp[maxn][maxn * maxn], stup[maxn][maxn]; n long long m; n int pot(int a, long long b) { n   if (!b) { n     return 1; n   } n   if (b == 1) { n     return a; n   } n   int rek, ost; n   rek = pot(a, b >> 1); n   ost = pot(a, b & 1); n   return ((((long long)rek * rek) % mod) * (long long)ost) % mod; n } n int rek(int cur, int ost) { n   if (!ost) { n     return dp[cur][ost] = 1; n   } n   if (cur >= n || ost < 0) { n     return 0; n   } n   if (dp[cur][ost] != -1) { n     return dp[cur][ost]; n   } n   dp[cur][ost] = 0; n   for (int i = 0; i <= min(n, ost); i++) { n     dp[cur][ost] += ((long long)stup[cur][i] * rek(cur + 1, ost - i)) % mod; n     if (dp[cur][ost] >= mod) { n       dp[cur][ost] -= mod; n     } n   } n   return dp[cur][ost]; n } n int main(void) { n   scanf( %d , &n); n   cin >> m; n   scanf( %d , &k); n   fact[0] = 1; n   for (int i = 1; i <= n; i++) { n     fact[i] = ((long long)fact[i - 1] * i) % mod; n   } n   for (int i = 0; i < n; i++) { n     for (int j = 0; j <= n; j++) { n       stup[i][j] = n           pot(((long long)fact[n] * n                pot(((long long)fact[j] * fact[n - j]) % mod, mod - 2)) % n                   mod, n               (m - i - 1) / n + 1); n     } n   } n   memset(dp, -1, sizeof dp); n   printf( %d n , rek(0, k)); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename Tp> n inline void read(Tp& x) { n   x = 0; n   int f = 1; n   char ch = getchar(); n   while (!isdigit(ch)) { n     if (ch ==  - ) f = -1; n     ch = getchar(); n   } n   while (isdigit(ch)) { n     x = x * 10 + ch -  0 ; n     ch = getchar(); n   } n   x *= f; n } n int buf[22]; n template <typename Tp> n inline void write(Tp x) { n   int p = 0; n   if (x < 0) { n     putchar( - ); n     x = -x; n   } n   if (x == 0) n     buf[++p] = 0; n   else n     while (x) { n       buf[++p] = x % 10; n       x /= 10; n     } n   for (int i = p; i; i--) putchar( 0  + buf[i]); n } n int m, b; n int main() { n   scanf( %d%d , &m, &b); n   long long int ans = 0; n   for (int y = 0; y <= b; y++) { n     int x = m * (b - y); n     ans = max(ans, 1ll * (1 + x) * (1 + y) * (x + y) / 2); n   } n   printf( %lld n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n inline T bigmod(T p, T e, T M) { n   if (e == 0) return 1; n   if (e % 2 == 0) { n     T t = bigmod(p, e / 2, M); n     return (t * t) % M; n   } n   return (bigmod(p, e - 1, M) * p) % M; n } n template <class T> n inline T gcd(T a, T b) { n   if (b == 0) return a; n   return gcd(b, a % b); n } n template <class T> n inline T modinverse(T a, T M) { n   return bigmod(a, M - 2, M); n } n template <class T> n inline T multimod(T a, T b, T m) { n   T ans = 0ll; n   a %= m, b %= m; n   while (b) { n     if (b & 1ll) ans = m - ans > a ? (ans + a) : (ans + a - m); n     b >>= 1ll; n     a = (m - a) > a ? a + a : a + a - m; n   } n   return (T)ans; n } n long long dp[102][2688]; n char str[102]; n long long solve(long long a, long long b) { n   if (a < b) swap(a, b); n   if (a == 0ll || b == 0ll) return false; n   if (!solve(b, a % b)) return true; n   long long x = a / b; n   return (x % (b + 1) % 2 == 0); n } n int main() { n   int i, j, x, y, k; n   int u, v, m, q, t, n, w; n   memset(dp, -1ll, sizeof dp); n   scanf( %d , &t); n   while (t--) { n     long long a, b; n     cin >> a >> b; n     if (solve(a, b)) n       cout <<  First  << endl; n     else n       cout <<  Second  << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int unibit[60] = {0}; n long long a[200005]; n long long unia[200005] = {0}; n int main() { n   int n, k, x; n   cin >> n >> k >> x; n   long long orr = 0; n   for (int i = 1; i <= n; i++) { n     cin >> a[i]; n     orr |= a[i]; n     long long b = a[i]; n     for (int j = 0; b > 0; j++) { n       if (b % 2 == 1) { n         if (unibit[j] == 0) n           unibit[j] = i; n         else n           unibit[j] = -1; n       } n       b /= 2; n     } n   } n   long long pow = 1; n   for (int i = 0; i < 35; i++) { n     if (unibit[i] > 0) { n       int j = unibit[i]; n       unia[j] += pow; n     } n     pow *= 2; n   } n   long long ans = 0; n   long long xx = 1; n   for (int i = 0; i < k; i++) xx *= (long long)x; n   for (int i = 1; i <= n; i++) { n     long long or2 = orr; n     or2 ^= unia[i]; n     a[i] *= xx; n     or2 |= a[i]; n     if (ans < or2) ans = or2; n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char a[105][105], s[105], res[105], letter, letter2, help[105]; n int i, j, k, N, lens, lena[105]; n int main() { n   scanf( %d , &N); n   gets(a[103]); n   for (i = 0; i < N; i++) { n     gets(a[i]); n     lena[i] = strlen(a[i]); n     for (j = 0; j < lena[i]; j++) n       if (a[i][j] >=  a  && a[i][j] <=  z ) a[i][j] -= 32; n   } n   gets(s); n   lens = strlen(s); n   for (i = 0; i < lens; i++) { n     if (s[i] >=  a  && s[i] <=  z ) n       help[i] = s[i] - 32; n     else n       help[i] = s[i]; n   } n   scanf( %c , &letter); n   if (letter >=  A  && letter <=  Z ) n     letter2 = letter + 32; n   else n     letter2 = letter - 32; n   if (letter < letter2) swap(letter, letter2); n   for (i = 0; i < lens; i++) { n     for (j = 0; j < N; j++) { n       if (memcmp(help + i, a[j], lena[j]) == 0) { n         for (k = i; k < i + lena[j]; k++) { n           if (s[k] != letter && s[k] != letter2) { n             if (s[k] >=  a  && s[k] <=  z ) n               res[k] = letter; n             else n               res[k] = letter2; n           } else { n             if (s[k] >=  a  && s[k] <=  z ) n               res[k] = letter ==  a  ?  b  :  a ; n             else n               res[k] = letter2 ==  A  ?  B  :  A ; n           } n         } n       } n     } n   } n   for (i = 0; i < lens; i++) n     if (res[i] == 0) res[i] = s[i]; n   puts(res); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); n const int MOD = 998244353; n void add(int &x, int y) { n   x += y; n   if (x >= MOD) x -= MOD; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   int n; n   cin >> n; n   vector<int> x(n), y(n), s(n); n   for (int i = 0; i < (int)(n); i++) cin >> x[i] >> y[i] >> s[i]; n   vector<int> cost(n + 1); n   for (int i = 0; i < (int)(n); i++) { n     int j = lower_bound((x).begin(), (x).end(), y[i]) - x.begin(); n     cost[i + 1] = (x[i] - y[i]) % MOD; n     add(cost[i + 1], cost[i]); n     add(cost[i + 1], MOD - cost[j]); n     add(cost[i + 1], cost[i]); n   } n   for (int i = (int)(n)-1; i >= ((int)0); i--) add(cost[i + 1], MOD - cost[i]); n   int ans = (x.back() + 1) % MOD; n   for (int i = 0; i < (int)(n); i++) n     if (s[i]) add(ans, cost[i + 1]); n   cout << ans % MOD << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool checkbitt(long long int num, int pos); n long long int setbitt(long long int num, long long int pos); n long long int resetbitt(long long int num, int pos); n const long long int mod = 1e9 + 7; n const long long int N = 1e6 + 10; n long long int count(long long int x) { n   x--; n   return (x * (x + 1)) / 2; n } n int solve() { n   int n; n   cin >> n; n   pair<int, int> arr[n]; n   map<int, int> a; n   map<int, int> b; n   map<pair<int, int>, int> c; n   long long int bad = 0; n   for (int i = 0; i < n; i++) { n     cin >> arr[i].first >> arr[i].second; n     a[arr[i].first]++; n     b[arr[i].second]++; n     c[arr[i]]++; n     bad += c[arr[i]] - 1; n   } n   long long int res = 0; n   for (auto x : a) { n     res += count(x.second); n   } n   for (auto x : b) { n     res += count(x.second); n   } n   cout << res - bad << endl; n   return 0; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   int cs = 1; n   int cn = 1; n   while (cs--) { n     solve(); n   } n } n bool checkbitt(long long int num, int pos) { return (num >> pos) & 1; } n long long int setbitt(long long int num, long long int pos) { n   return (1 << pos) | num; n } n long long int resetbitt(long long int num, int pos) { n   if (!checkbitt(num, pos)) n     return num; n   else n     return (1 << pos) ^ num; n } n


#include <bits/stdc++.h> n using namespace std; n long long mod = 1e9 + 7; n const int N = 2e5 + 5; n const double pi = acos(-1); n int t; n int main() { n   cin >> t; n   while (t--) { n     int n, m; n     cin >> n >> m; n     if (n % m == 0) n       cout <<  YES  <<   n ; n     else n       cout <<  NO  <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, ans = 1e9; n vector<vector<int> > cnt(65); n vector<set<int> > ed; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cin >> n; n   ed.resize(n + 1); n   bool tw = false; n   for (int i = 0; i < n; i++) { n     long long a; n     cin >> a; n     int d = 0; n     while (a && !(tw)) { n       if (a & 1) { n         for (int k : cnt[d]) { n           if (ed[k].find(i) == ed[k].end()) { n             ed[k].insert(i); n             ed[i].insert(k); n           } n         } n         cnt[d].push_back(i); n         if (cnt[d].size() > 2) tw = true; n       } n       a >>= 1, d++; n     } n   } n   if (tw) { n     cout << 3 <<   n ; n     return 0; n   } n   for (int j = 0; j < 64; j++) { n     unordered_set<int> vis; n     if (cnt[j].size() == 2) { n       queue<pair<int, int> > q; n       for (int k : ed[cnt[j][0]]) n         if (k != cnt[j][1]) q.push(make_pair(k, 1)); n       vis.insert(cnt[j][0]); n       while (!q.empty()) { n         pair<int, int> cur = q.front(); n         q.pop(); n         if (vis.find(cur.first) != vis.end()) continue; n         vis.insert(cur.first); n         if (cur.first == cnt[j][1]) { n           ans = min(ans, cur.second); n           break; n         } n         for (int k : ed[cur.first]) q.push(make_pair(k, cur.second + 1)); n       } n     } n   } n   if (ans == 1e9) n     cout << -1 <<   n ; n   else n     cout << ans + 1 <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n const long long INF64 = 1e18 + 1337; n const int INF32 = 1e9 + 228; n const int MOD = 1e9 + 7; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long n, s; n   cin >> n >> s; n   vector<long long> a(n); n   long long sum = 0; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n     sum += a[i]; n   } n   if (sum < s) { n     cout << -1; n     return 0; n   } n   sort(a.begin(), a.end(), greater<int>()); n   for (int i = 0; i < n - 1; i++) s -= (a[i] - a[n - 1]); n   while (s > 0 && a[n - 1] > 0) { n     s -= n; n     a[n - 1]--; n   } n   cout << a[n - 1]; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n pair<long long, long long> P, d[100000]; n double rm, rM; n int main() { n   scanf( %d%I64d%I64d , &n, &P.first, &P.second); n   for (int i = 0; i < n; i++) { n     pair<long long, long long> Q; n     scanf( %I64d%I64d , &Q.first, &Q.second); n     double t = (P.first - Q.first) * (P.first - Q.first) + n                (P.second - Q.second) * (P.second - Q.second); n     if (i == 0) n       rm = rM = t; n     else { n       if (rm > t) rm = t; n       if (rM < t) rM = t; n     } n     d[i] = Q; n   } n   for (int i = 0; i < n; i++) { n     int j = (i + 1) % n; n     pair<long long, long long> Q = n         make_pair(d[j].first - d[i].first, d[j].second - d[i].second); n     double t = n         Q.first * (P.first - d[i].first) + Q.second * (P.second - d[i].second); n     t /= (Q.first * Q.first + Q.second * Q.second); n     if (0 <= t && t <= 1) { n       long long a = d[j].second - d[i].second; n       long long b = -(d[j].first - d[i].first); n       long long c = -(a * d[i].first + b * d[i].second); n       double t = (a * P.first + b * P.second + c); n       t = t * t / (a * a + b * b); n       if (t < rm) rm = t; n     } n   } n   double r = rM - rm; n   printf( %.9f n , r * 3.1415926535897932384626433832795); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using namespace std::chrono; n template <typename A> n ostream &operator<<(ostream &cout, vector<A> const &v); n template <typename A, typename B> n ostream &operator<<(ostream &cout, pair<A, B> const &p) { n   return cout <<  (  << p.first <<  ,   << p.second <<  ) ; n } n template <typename A> n ostream &operator<<(ostream &cout, vector<A> const &v) { n   cout <<  [ ; n   for (int i = 0; i < v.size(); i++) { n     if (i) cout <<  ,  ; n     cout << v[i]; n   } n   return cout <<  ] ; n } n template <typename A, typename B> n istream &operator>>(istream &cin, pair<A, B> &p) { n   cin >> p.first; n   return cin >> p.second; n } n mt19937 rng(61378913); n void usaco(string filename) { n   freopen((filename +  .in ).c_str(),  r , stdin); n   freopen((filename +  .out ).c_str(),  w , stdout); n } n const long double pi = 3.14159265358979323846; n const long long mod = 1000000007; n namespace modop { n long long madd(long long a, long long b) { return (a + b) % mod; } n long long msub(long long a, long long b) { n   return (((a - b) % mod) + mod) % mod; n } n long long mmul(long long a, long long b) { n   return ((a % mod) * (b % mod)) % mod; n } n long long mpow(long long base, long long exp) { n   long long res = 1; n   while (exp) { n     if (exp % 2 == 1) { n       res = (res * base) % mod; n     } n     exp >>= 1; n     base = (base * base) % mod; n   } n   return res; n } n long long minv(long long base) { return mpow(base, mod - 2); } n long long mdiv(long long a, long long b) { return mmul(a, minv(b)); } n }  // namespace modop n using namespace modop; n long long n, m, k, q, l, r, x, y, z; n long long a[1000005]; n long long b[1000005]; n long long c[1000005]; n string second, t; n long long ans = 0; n map<long long, long long> cnt; n pair<long long, long long> vals[1000005]; n void solve(int tc) { n   cin >> n >> k; n   cnt.clear(); n   for (int ele = 0; ele < n; ele++) cin >> a[ele]; n   ; n   if (k == 1) { n     cout << (n & 1) <<   n ; n     return; n   } n   for (long long i = 0; i < (n); ++i) ++cnt[a[i]]; n   long long second = cnt.size(); n   int pos = 0; n   for (pair<long long, long long> x : cnt) vals[pos++] = x; n   reverse(vals, vals + second); n   long long req = 0, last = vals[0].first, ans = 0; n   bool fin = 0; n   for (long long i = 0; i < (second); ++i) { n     long long diff = last - vals[i].first; n     last = vals[i].first; n     for (long long j = 0; j < (diff); ++j) { n       if (req == 0) break; n       if (req > 1000000) { n         fin = 1; n         break; n       } n       req *= k; n       if (req > 1000000) { n         fin = 1; n         break; n       } n     } n     long long c = vals[i].second; n     if (fin) { n       ans = msub(ans, c * mpow(k, vals[i].first)); n       continue; n     } n     if (c <= req) { n       req -= c; n       ans = msub(ans, c * mpow(k, vals[i].first)); n     } else { n       c -= req; n       ans = 0; n       req = 0; n       if (c & 1) { n         req = 1; n         ans = (ans + mpow(k, vals[i].first)) % mod; n       } n     } n   } n   cout << (ans % mod) <<   n ; n } n int main() { n   { ios_base::sync_with_stdio(false); } n   { n     cin.tie(NULL); n     cout.tie(NULL); n   } n   int tc = 1; n   cin >> tc; n   for (int t = 0; t < tc; t++) solve(t); n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 100010; n int i, j, k, n, m, vis[maxn], cnt, Q[maxn], top; n void dfs(int now) { n   vis[now]++; n   if (!vis[now * 2 % n]) dfs(now * 2 % n); n   if (!vis[(now * 2 + 1) % n]) dfs((now * 2 + 1) % n); n   Q[++top] = now; n } n int main() { n   cin >> n; n   if (n & 1) n     cout << -1 << endl; n   else { n     dfs(0); n     while (top) cout << Q[top--] <<    ; n     cout << 0 << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<pair<long long int, long long int> > getfac(long long int n) { n   vector<pair<long long int, long long int> > ret; n   for (long long int i = 1; i < sqrt(n) + 1; i++) { n     if (n % i == 0) { n       ret.push_back({min({i, n / i}), max({i, n / i})}); n     } n   } n   return ret; n } n bool fun1(pair<long long int, long long int> a, n           pair<long long int, long long int> b) { n   return a.first + a.second < b.first + b.second; n } n bool isin(pair<long long int, long long int> a, n           pair<long long int, long long int> b) { n   return b.first <= a.first && a.second >= b.second; n } n long long int max(long long int a, long long int b) { n   if (a <= b) return a; n   return b; n } n long long int min(long long int a, long long int b) { n   if (a <= b) return b; n   return a; n } n int main() { n   long long int a, b, c, d, ans = 1e17; n   cin >> a >> b; n   c = a; n   d = b; n   a = min({c, d}); n   b = max({c, d}); n   vector<pair<long long int, long long int> > af = getfac(a), bf = getfac(b), n                                               cf = getfac(a + b); n   sort(cf.begin(), cf.end(), fun1); n   for (int i = 0; i < cf.size(); i += 1) { n     long long int p = cf[i].first, q = cf[i].second; n     for (int j = 0; j < af.size(); j++) { n       if (isin(cf[i], af[j])) { n         ans = min({ans, 2 * (p + q)}); n       } n     } n     for (int j = 0; j < bf.size(); j++) { n       if (isin(cf[i], bf[j])) { n         ans = min({ans, 2 * (p + q)}); n       } n     } n   } n   printf( %lld n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = (2e5 + 42); n const int MAXLOG = 20; n const int64_t inf = (int64_t)1e18; n int n, m, S; n vector<pair<int, int> > G[MAXN]; n void read() { n   cin >> n >> m >> S; n   for (int i = 0; i < m; i++) { n     int u, v, w; n     cin >> u >> v >> w; n     G[u].push_back({v, w}); n     G[v].push_back({u, w}); n   } n } n bool in_queue[MAXN]; n vector<int> pars[MAXN], adj[MAXN]; n int64_t dist[MAXN]; n int par[MAXN][MAXLOG], d[MAXN]; n int lca(int u, int v) { n   if (d[u] < d[v]) swap(u, v); n   for (int lg = MAXLOG - 1; lg >= 0; lg--) n     if (d[par[u][lg]] >= d[v]) u = par[u][lg]; n   if (u == v) return u; n   for (int lg = MAXLOG - 1; lg >= 0; lg--) n     if (par[u][lg] != par[v][lg]) u = par[u][lg], v = par[v][lg]; n   return par[u][0]; n } n void spfa(int st) { n   for (int i = 0; i <= n; i++) dist[i] = inf, adj[i].clear(), in_queue[i] = 0; n   queue<int> Q; n   in_queue[st] = 1; n   dist[st] = 0; n   Q.push(st); n   while (!Q.empty()) { n     int u = Q.front(); n     in_queue[u] = 0; n     Q.pop(); n     for (auto e : G[u]) { n       int v = e.first, w = e.second; n       if (dist[v] > dist[u] + w) { n         dist[v] = dist[u] + w; n         if (!in_queue[v]) Q.push(v); n         in_queue[v] = 1; n       } n     } n   } n   for (int i = 1; i <= n; i++) n     for (auto e : G[i]) n       if (dist[e.first] == dist[i] + e.second) pars[e.first].push_back(i); n } n int tr_sz[MAXN]; n void dfs(int u) { n   tr_sz[u] = 1; n   for (int v : adj[u]) { n     dfs(v); n     tr_sz[u] += tr_sz[v]; n   } n } n void solve() { n   spfa(S); n   int ans = 0; n   vector<pair<int64_t, int> > order; n   for (int i = 1; i <= n; i++) n     if (dist[i] < inf) order.push_back({dist[i], i}); n   sort(order.begin(), order.end()); n   for (int i = 0; i < MAXLOG; i++) par[S][i] = S; n   for (pair<int64_t, int> e : order) { n     if (e.second == S) continue; n     int u = e.second; n     int l = pars[u][0]; n     for (int anc : pars[u]) l = lca(l, anc); n     par[u][0] = l; n     d[u] = d[l] + 1; n     adj[l].push_back(u); n     for (int lg = 1; lg < MAXLOG; lg++) n       par[u][lg] = par[par[u][lg - 1]][lg - 1]; n   } n   dfs(S); n   for (int i = 1; i <= n; i++) n     if (dist[i] < inf && i != S) ans = max(ans, tr_sz[i]); n   cout << ans <<   n ; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   read(); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   int n, ce = 0, co = 0, A[100], i, o = 0, e = 0; n   scanf( %d , &n); n   for (i = 0; i < n; i++) scanf( %d , &A[i]); n   for (i = 0; i < n; i++) { n     if (A[i] % 2 == 0) ce++; n     if (A[i] % 2 != 0) co++; n   } n   if (co == 1) { n     for (i = 0; i < n; i++) { n       if (A[i] % 2 != 0) { n         o++; n         break; n       } else n         o++; n     } n     printf( %d , o); n   } n   if (ce == 1) { n     for (i = 0; i < n; i++) { n       if (A[i] % 2 == 0) { n         e++; n         break; n       } else n         e++; n     } n     printf( %d , e); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long c[(1 << 20)]; n struct SuffixTree { n   int s[(1 << 20)]; n   map<int, int> to[(1 << 20)]; n   int len[(1 << 20)] = {(1 << 30)}, fpos[(1 << 20)], link[(1 << 20)], n                 id[(1 << 20)]; n   int node, pos, sz = 1, n = 0; n   int make_node(int p, int l, int k) { n     fpos[sz] = p; n     len[sz] = l; n     id[sz] = k; n     return sz++; n   } n   void go_edge() { n     while (pos > len[to[node][s[n - pos]]]) { n       node = to[node][s[n - pos]]; n       pos -= len[node]; n     } n   } n   void add(int c, int k) { n     s[n++] = c; n     pos++; n     int last = 0; n     while (pos > 0) { n       go_edge(); n       int edge = s[n - pos]; n       int& v = to[node][edge]; n       int t = s[fpos[v] + pos - 1]; n       if (v == 0) { n         v = make_node(n - pos, (1 << 30), k); n         link[last] = node; n         last = 0; n       } else if (t == c) { n         link[last] = node; n         return; n       } else { n         int u = make_node(fpos[v], pos - 1, k); n         to[u][c] = make_node(n - 1, (1 << 30), k); n         to[u][t] = v; n         fpos[v] += pos - 1; n         len[v] -= pos - 1; n         v = u; n         link[last] = u; n         last = u; n       } n       if (node == 0) n         pos--; n       else n         node = link[node]; n     } n   } n   long long rr; n   int asd[(1 << 20)]; n   long long dfs(int x, int d) { n     long long r = 0; n     d += len[x]; n     if (!((int)(to[x]).size())) n       r = c[id[x]]; n     else { n       for (auto p : to[x]) r += dfs(p.second, d); n     } n     if (len[x]) rr = max(rr, r * d); n     return r; n   } n   long long doit() { n     for (int i = n - 1; i >= 0; --i) { n       if (s[i] <= 0) n         asd[i] = 0; n       else n         asd[i] = asd[i + 1] + 1; n     } n     for (int i = 1, ThxDem = sz; i < ThxDem; ++i) n       len[i] = min(len[i], asd[fpos[i]]); n     len[0] = 0; n     rr = 0; n     dfs(0, 0); n     return rr; n   } n }; n int n; n SuffixTree t; n char _s[(1 << 20)]; n int main() { n   scanf( %d , &n); n   for (int i = 0, ThxDem = n; i < ThxDem; ++i) { n     scanf( %s , _s); n     for (int j = 0; _s[j]; ++j) { n       t.add(_s[j], i); n     } n     t.add(-i, i); n   } n   for (int i = 0, ThxDem = n; i < ThxDem; ++i) scanf( %lld , c + i); n   printf( %lld n , t.doit()); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n long long a[100000], b[100000]; n vector<pair<int, long long>> connections[100000]; n pair<long long, long long> needed(int node) { n   long long temp = a[node] - b[node]; n   long long temp2 = temp / 1000000007; n   temp %= 1000000007; n   for (const pair<int, int> edge : connections[node]) { n     pair<long long, long long> curr = needed(edge.first); n     if (curr.first > 0 || curr.first == 0 && curr.second >= 0) { n       curr.first *= edge.second; n       curr.second *= edge.second; n     } n     temp += curr.second; n     temp2 += temp / 1000000007; n     temp %= 1000000007; n     temp2 += curr.first; n   } n   return make_pair(temp2, temp); n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cin >> n; n   for (int i = 0; i < (n); i++) cin >> b[i]; n   for (int i = 0; i < (n); i++) cin >> a[i]; n   for (int i = 0; i < (n - 1); i++) { n     int x; n     long long k; n     cin >> x >> k; n     connections[--x].push_back(make_pair(i + 1, k)); n   } n   pair<long long, long long> res = needed(0); n   if (res.first <= 0 && res.second <= 0) n     cout <<  YES n ; n   else n     cout <<  NO n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int dx[] = {-1, 1, 0, 0, 0, 0, 0, 0}; n int dy[] = {0, 0, 1, -1, 0, 0, 0, 0}; n const int inf = 1000000000; n const double eps = 0.000000009; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   int n; n   cin >> n; n   string a[n]; n   for (int i = 0; i < n; i++) cin >> a[i]; n   long long ans = 7; n   for (int i = 0; i < n; i++) { n     for (int j = i + 1; j < n; j++) { n       int diff = 0; n       for (int k = 0; k < 6; k++) { n         if (a[i][k] != a[j][k]) diff++; n       } n       ans = min(ans, (long long)ceil(diff / 2.0)); n     } n   } n   cout << ans - 1 << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   int n; n   cin >> n; n   multiset<long long> s; n   long long now = 0; n   for (int i = 1; i <= n; i++) { n     long long a; n     cin >> a; n     a -= i; n     s.insert(a); n     s.insert(a); n     now -= a; n     long long x = (*s.rbegin()); n     s.erase(s.find(x)); n     now += x; n   } n   cout << now <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:1024000000,1024000000 ) n using namespace std; n const int N = 1e5 + 10, INF = 0x3f3f3f3f, MOD = 1e9 + 7; n int n, m; n int u[N], v[N]; n vector<int> G[N]; n bool check(int m) { n   for (int i = 1; i <= n; ++i) G[i].clear(); n   vector<int> in(n + 1, 0); n   for (int i = 1; i <= m; ++i) { n     G[u[i]].push_back(v[i]); n     ++in[v[i]]; n   } n   queue<int> q; n   for (int i = 1; i <= n; ++i) n     if (!in[i]) q.push(i); n   while (q.size()) { n     int u = q.front(); n     q.pop(); n     if (q.size()) return false; n     for (int v : G[u]) n       if (--in[v] == 0) q.push(v); n   } n   return true; n } n int main() { n   ios_base::sync_with_stdio(0); n   scanf( %d%d , &n, &m); n   for (int i = 1; i <= m; ++i) scanf( %d%d , u + i, v + i); n   int l = 1, r = m; n   while (l <= r) { n     int m = l + r >> 1; n     if (check(m)) n       r = m - 1; n     else n       l = m + 1; n   } n   if (l == m + 1) l = -1; n   printf( %d n , l); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e5 + 5; n const int MOD = 1e9 + 7; n const int INF = 1e9; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(NULL); n   cout.tie(NULL); n   int n, m; n   cin >> n >> m; n   int a[n][m], b[n][m]; n   vector<int> col[n + m], col2[n + m]; n   int i, j; n   bool ans = true; n   for (i = 0; i < n; i++) { n     for (j = 0; j < m; j++) { n       cin >> a[i][j]; n     } n   } n   for (i = 0; i < n; i++) { n     for (j = 0; j < m; j++) { n       cin >> b[i][j]; n     } n   } n   for (i = 0; i < n; i++) { n     for (j = 0; j < m; j++) { n       col[i + j].push_back(a[i][j]); n       col2[i + j].push_back(b[i][j]); n     } n   } n   for (i = 0; i < (n + m - 1); i++) { n     sort(col[i].begin(), col[i].end()); n     sort(col2[i].begin(), col2[i].end()); n     if (col[i] != col2[i]) { n       ans = false; n     } n   } n   if (ans) { n     cout <<  YES ; n   } else { n     cout <<  NO ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2e5 + 5; n int n; n int p[N]; n pair<int, int> v[N]; n void solve(int nx, int nnx) { n   int curr = 1; n   for (int i = 1; i <= n; i++) p[i] = 0; n   p[curr] = nx; n   p[nx] = nnx; n   curr = nx; n   bool okay = true; n   for (int i = 2; i <= n; i++) { n     if (v[curr].first == nnx) { n       if (!p[nnx]) p[nnx] = v[curr].second; n       nx = nnx; n       nnx = v[curr].second; n       curr = nx; n     } else if (v[curr].second == nnx) { n       if (!p[nnx]) p[nnx] = v[curr].first; n       nx = nnx; n       nnx = v[curr].first; n       curr = nx; n     } else { n       okay = false; n       break; n     } n   } n   curr = 1; n   for (int i = 1; i <= n; i++) { n     curr = p[curr]; n   } n   if (curr != 1) okay = false; n   if (okay) { n     curr = 1; n     for (int i = 1; i <= n; i++) { n       printf( %d  , curr); n       curr = p[curr]; n     } n     exit(0); n   } n } n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) { n     int x, y; n     scanf( %d %d , &x, &y); n     v[i].first = x; n     v[i].second = y; n   } n   solve(v[1].first, v[1].second); n   solve(v[1].second, v[1].first); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int tmp = 3; n   int x = 1, y = 2; n   int n; n   cin >> n; n   bool flag = true; n   for (int i = 1; i <= n; i++) { n     int q; n     cin >> q; n     if (q == tmp) { n       flag = false; n     } n     if (q == x) n       swap(tmp, y); n     else n       swap(tmp, x); n   } n   if (flag) n     cout <<  YES  << endl; n   else n     cout <<  NO  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename...> n static inline int getchar_unlocked(void) { n   return getchar(); n } n template <typename...> n static inline void putchar_unlocked(int c) { n   putchar(c); n } n void reader(int& x) { n   int k, m = 0; n   x = 0; n   for (;;) { n     (k) = getchar_unlocked(); n     if (k ==  - ) { n       m = 1; n       break; n     } n     if ( 0  <= k && k <=  9 ) { n       x = k -  0 ; n       break; n     } n   } n   for (;;) { n     (k) = getchar_unlocked(); n     if (k <  0  || k >  9 ) break; n     x = x * 10 + k -  0 ; n   } n   if (m) x = -x; n } n void reader(long long& x) { n   int k, m = 0; n   x = 0; n   for (;;) { n     (k) = getchar_unlocked(); n     if (k ==  - ) { n       m = 1; n       break; n     } n     if ( 0  <= k && k <=  9 ) { n       x = k -  0 ; n       break; n     } n   } n   for (;;) { n     (k) = getchar_unlocked(); n     if (k <  0  || k >  9 ) break; n     x = x * 10 + k -  0 ; n   } n   if (m) x = -x; n } n int reader(char c[]) { n   int i, s = 0; n   for (;;) { n     (i) = getchar_unlocked(); n     if (i !=     && i !=   n  && i !=   r  && i !=   t  && i != EOF) break; n   } n   c[s++] = i; n   for (;;) { n     (i) = getchar_unlocked(); n     if (i ==     || i ==   n  || i ==   r  || i ==   t  || i == EOF) break; n     c[s++] = i; n   } n   c[s] =   0 ; n   return s; n } n template <class T, class S> n void reader(T& x, S& y) { n   reader(x); n   reader(y); n } n template <class T, class S, class U> n void reader(T& x, S& y, U& z) { n   reader(x); n   reader(y); n   reader(z); n } n template <class T, class S, class U, class V> n void reader(T& x, S& y, U& z, V& w) { n   reader(x); n   reader(y); n   reader(z); n   reader(w); n } n void writer(int x, char c) { n   int s = 0, m = 0; n   char f[10]; n   if (x < 0) m = 1, x = -x; n   while (x) f[s++] = x % 10, x /= 10; n   if (!s) f[s++] = 0; n   if (m) putchar_unlocked( - ); n   while (s--) putchar_unlocked(f[s] +  0 ); n   putchar_unlocked(c); n } n void writer(long long x, char c) { n   int s = 0, m = 0; n   char f[20]; n   if (x < 0) m = 1, x = -x; n   while (x) f[s++] = x % 10, x /= 10; n   if (!s) f[s++] = 0; n   if (m) putchar_unlocked( - ); n   while (s--) putchar_unlocked(f[s] +  0 ); n   putchar_unlocked(c); n } n void writer(const char c[]) { n   int i; n   for (i = 0; c[i] !=   0 ; i++) putchar_unlocked(c[i]); n } n void writer(const char x[], char c) { n   int i; n   for (i = 0; x[i] !=   0 ; i++) putchar_unlocked(x[i]); n   putchar_unlocked(c); n } n template <class T> n void writerLn(T x) { n   writer(x,   n ); n } n template <class T, class S> n void writerLn(T x, S y) { n   writer(x,    ); n   writer(y,   n ); n } n template <class T, class S, class U> n void writerLn(T x, S y, U z) { n   writer(x,    ); n   writer(y,    ); n   writer(z,   n ); n } n template <class T> n void writerArr(T x[], int n) { n   if (!n) { n     putchar_unlocked(  n ); n     return; n   } n   for (int i = 0; i < (n - 1); i++) writer(x[i],    ); n   writer(x[n - 1],   n ); n } n template <class T> n void chmax(T& l, const T r) { n   l = max(l, r); n } n template <class T> n void chmin(T& l, const T r) { n   l = min(l, r); n } n template <class T> n T gcd(T a, T b) { n   return b ? gcd(b, a % b) : a; n } n template <class T> n T extgcd(T a, T b, T& x, T& y) { n   for (T u = y = 1, v = x = 0; a;) { n     T q = b / a; n     swap(x -= q * u, u); n     swap(y -= q * v, v); n     swap(b -= q * a, a); n   } n   return b; n } n template <class T> n T mod_inv(T a, T m) { n   T x, y; n   extgcd(a, m, x, y); n   return (m + x % m) % m; n } n long long mod_pow(long long a, long long n, long long mod) { n   long long ret = 1; n   long long p = a % mod; n   while (n) { n     if (n & 1) ret = ret * p % mod; n     p = p * p % mod; n     n >>= 1; n   } n   return ret; n } n struct P { n   long double x, y; n   P() : x(0), y(0) {} n   P(const long double& x, const long double& y) : x(x), y(y) {} n   P operator+(const P& a) const { return P(x + a.x, y + a.y); } n   P& operator+=(const P& a) { n     x += a.x; n     y += a.y; n     return *this; n   } n   P operator-(const P& a) const { return P(x - a.x, y - a.y); } n   P& operator-=(const P& a) { n     x -= a.x; n     y -= a.y; n     return *this; n   } n   P operator*(const long double a) const { return P(a * x, a * y); } n   P& operator*=(const long double a) { n     x *= a; n     y *= a; n     return *this; n   } n   P operator/(const long double a) const { return P(x / a, y / a); } n   P& operator/=(const long double a) { n     x /= a; n     y /= a; n     return *this; n   } n   bool operator<(const P& a) const { n     return (x != a.x) ? (x < a.x) : (y < a.y); n   } n }; n const double PI = acos(-1); n P rot(const P& a, double theta) { n   theta = -theta / 180 * PI; n   return P(a.x * cos(theta) - a.y * sin(theta), n            a.x * sin(theta) + a.y * cos(theta)); n } n long double SQ(long double x) { return x * x; } n long double dist2(const P& a, const P& b) { n   return SQ(a.x - b.x) + SQ(a.y - b.y); n } n long double abs2(const P& p) { return SQ(p.x) + SQ(p.y); } n long double dot(const P& a, const P& b) { return a.x * b.x + a.y * b.y; } n long double cross(const P& a, const P& b) { return a.x * b.y - a.y * b.x; } n long double abs(const P& p) { return sqrt(abs2(p)); } n double arg(const P& a) { n   double t = atan2(a.y, a.x); n   return t < 0 ? t + 2 * PI : t; n } n struct Q { n   long double x, y; n   int argsum; n   static Q zero() { n     Q ret = {0, 0, 0}; n     return ret; n   } n   bool is_zero() const { return x == 0 && y == 0; } n   Q operator+(const Q& r) const { n     if (is_zero()) n       return r; n     else if (r.is_zero()) n       return *this; n     P p1(x, y); n     P p2(r.x, r.y); n     p2 = rot(p2, argsum); n     P cur = p1 + p2; n     Q ret; n     ret.x = cur.x; n     ret.y = cur.y; n     ret.argsum = argsum + r.argsum; n     return ret; n   } n }; n class seg_tree { n  public: n   vector<int> len, args; n   vector<Q> dat; n   int n; n   void propagate(int i) { dat[i] = dat[i * 2 + 1] + dat[i * 2 + 2]; } n   void init(int size) { n     n = 1; n     len.resize(size, 1); n     args.resize(size); n     while (n < size) n <<= 1; n     dat.resize(2 * n - 1); n     fill(dat.begin(), dat.end(), Q::zero()); n     for (int i = 0; i < size; i++) dat[n - 1 + i].x = 1.0; n     for (int i = n - 2; i >= 0; i--) propagate(i); n   } n   void update_k(int k) { n     P cur(len[k], 0); n     cur = rot(cur, args[k]); n     k += n - 1; n     dat[k].x = cur.x; n     dat[k].y = cur.y; n     dat[k].argsum = args[k - n + 1]; n   } n   void update_len(int k, int len) { n     this->len[k] += len; n     update_k(k); n     k += n - 1; n     while (k > 0) { n       k = (k - 1) / 2; n       propagate(k); n     } n   } n   void update_arg(int k, int arg) { n     args[k] += arg; n     update_k(k); n     k += n - 1; n     while (k > 0) { n       k = (k - 1) / 2; n       propagate(k); n     } n   } n   void update_query(int t, int id, int val) { n     id--; n     if (t == 1) { n       update_len(id, val); n     } else { n       update_arg(id, val); n     } n   } n   Q query(int a, int b) { return query(a, b, 0, 0, n); } n   Q query(int a, int b, int k, int l, int r) { n     if (r <= a || b <= l) return Q::zero(); n     if (a <= l && r <= b) return dat[k]; n     int md = (l + r) / 2; n     int nl = k * 2 + 1, nr = nl + 1; n     Q lval = query(a, b, nl, l, md); n     Q rval = query(a, b, nr, md, r); n     return lval + rval; n   } n }; n P q2p(Q& q) { return P(q.x, q.y); } n void print(seg_tree& seg, int n) { n   for (int i = 0; i < (n); i++) { n     Q q = seg.dat[seg.n - 1 + i]; n     P p = q2p(q); n     printf( %d : (%lf,%lf) n , i, p.x, p.y); n   } n } n int main() { n   int n, q; n   reader(n, q); n   seg_tree seg; n   seg.init(n); n   for (int i = 0; i < (q); i++) { n     int t, a, b; n     reader(t, a, b); n     seg.update_query(t, a, b); n     Q val = seg.query(0, n); n     P cur = q2p(val); n     printf( %.10lf %.10lf n , (double)cur.x, (double)cur.y); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int p[1000005]; n int fnd(int x) { return p[x] = p[x] == x ? x : fnd(p[x]); } n void unn(int x, int y) { p[fnd(y)] = fnd(x); } n int dir[4][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}}; n int gcd(int x, int y) { return x % y ? gcd(y, x % y) : y; } n int pq[5144]; n vector<int> pr; n int net[100005]; n int a[100005]; n int main() { n   int n; n   scanf( %d , &n); n   if (n == 1) return printf( 1 n ), 0; n   for (int i = 2; i <= 10000; i++) { n     if (net[i]) continue; n     pr.push_back(i); n     for (int j = i * i; j <= 100000; j += i) net[j] = 1; n   } n   for (int i = 0; i < n; i++) { n     scanf( %d , a + i); n     int mx = 0; n     for (int j = 0; j < pr.size(); j++) { n       if (a[i] % pr[j] == 0) { n         mx = max(mx, pq[j]); n       } n     } n     for (int j = 0; j < pr.size(); j++) { n       if (a[i] % pr[j] == 0) { n         pq[j] = max(mx + 1, pq[j]); n       } n     } n   } n   int mx = 1; n   for (int i = 0; i < pr.size(); i++) mx = max(mx, pq[i]); n   printf( %d , mx); n } n


#include <bits/stdc++.h> n using namespace std; n const long long maxn = 305; n const long long mode = 1e9 + 7; n const long long maxm = 1e5 + 10; n long long n, q, t, w[maxn], fa[maxn], nw[maxn], dp[maxm], son[maxn], z[maxn], n     cur, ww[maxn]; n long long u, v; n signed main() { n   cin >> n >> q >> t; n   for (long long i = 1; i <= n; ++i) cin >> w[i]; n   bool juge = true; n   while (q--) { n     cin >> u >> v; n     if (fa[u] == v) { n       juge = false; n     } n     fa[v] = u; n     son[u] = v; n   } n   if (!juge) { n     cout << 0; n     return 0; n   } n   for (long long i = 1; i <= n; ++i) { n     if (fa[i] == 0 && son[i]) { n       long long sum = 0; n       long long now = i; n       while (now) { n         ww[now] = sum + w[now]; n         nw[now] = nw[fa[now]] + sum + w[now]; n         sum += w[now]; n         now = son[now]; n       } n     } n     if (fa[i] == 0 && son[i] == 0) nw[i] = ww[i] = w[i]; n     if (son[i] == 0 && fa[i]) { n       z[++cur] = i; n     } n   } n   long long sum = 0; n   for (long long i = 1; i <= n; ++i) { n     if (son[i] == 0 && fa[i]) { n       long long temp = 0, now = i; n       while (now) { n         temp += w[now]; n         now = fa[now]; n       } n       sum += nw[i] - temp; n     } n   } n   if (sum > t) { n     cout << 0; n     return 0; n   } else if (sum == t) { n     cout << 1; n     return 0; n   } n   dp[sum] = 1; n   for (long long i = 1; i <= n; ++i) { n     for (long long j = ww[i]; j <= t; ++j) { n       if (dp[j - ww[i]]) dp[j] += dp[j - ww[i]]; n       dp[j] %= mode; n     } n   } n   cout << dp[t]; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n T gcd(T a, T b) { n   return b == 0 ? a : gcd(b, a % b); n } n template <typename T> n T modMul(T a, T b, T m) { n   T x = 0, y = a % m; n   while (b > 0) { n     if (b % 2 == 1) x = (x + y) % m; n     y = (y * 2) % m; n     b /= 2; n   } n   return x % m; n } n template <typename T> n T pollard(T n) { n   int i = 0, k = 2, d; n   T x = 3, y = 3; n   while (true) { n     i++; n     x = (modMul(x, x, n) + n - 1) % n; n     d = gcd(abs(y - x), n); n     if (d != 1 && d != n) return d; n     if (i == k) y = x, k *= 2; n   } n } n template <typename T> n T modExp(T a, T b, T m) { n   if (b == 0) return (T)1; n   T c = modExp(a, b / 2, m); n   c = modMul(c, c, m); n   if (b % 2 != 0) c = modMul(c, a, m); n   return c; n } n bool miller(long long n) { n   const int pn = 9; n   const int p[] = {2, 3, 5, 7, 11, 13, 17, 19, 23}; n   for (int i = 0; i < pn; i++) n     if (n % p[i] == 0) return n == p[i]; n   if (n < p[pn - 1]) return false; n   long long s = 0, t = n - 1; n   while (~t & 1) t >>= 1, ++s; n   for (int i = 0; i < pn; ++i) { n     long long pt = modExp((long long)p[i], t, n); n     if (pt == 1) continue; n     bool ok = false; n     for (int j = 0; j < s && !ok; j++) { n       if (pt == n - 1) ok = true; n       pt = modMul(pt, pt, n); n     } n     if (!ok) return false; n   } n   return true; n } n long long arr[200009], mskcnt[1 << 16]; n int main() { n   long long n, x, y; n   scanf( %lld %lld %lld , &n, &x, &y); n   vector<long long> div; n   int cnt_y[20], cnt_x[20]; n   long long d = y; n   for (int i = 2; 1LL * i * i <= d && i <= 10000000; i++) { n     if (d % i == 0) { n       int cnt = 0; n       while (d % i == 0) { n         d /= i; n         cnt++; n       } n       cnt_y[div.size()] = cnt; n       div.push_back(i); n     } n   } n   if (d > 1) { n     if (miller(d)) { n       cnt_y[div.size()] = 1; n       div.push_back(d); n     } else { n       long long p = pollard(d); n       if (p * p == d) { n         cnt_y[div.size()] = 2; n         div.push_back(p); n       } else { n         cnt_y[div.size()] = 1; n         div.push_back(p); n         cnt_y[div.size()] = 1; n         div.push_back(d / p); n       } n     } n   } n   if (y % x != 0) { n     puts( 0 ); n     return 0; n   } n   d = x; n   for (int idx = 0; idx < div.size(); idx++) { n     long long i = div[idx]; n     int cnt = 0; n     while (d % i == 0) { n       d /= i; n       cnt++; n     } n     if (cnt == cnt_y[idx]) { n       swap(div.back(), div[idx]); n       swap(cnt_y[div.size() - 1], cnt_y[idx]); n       idx--; n       div.pop_back(); n     } else n       cnt_x[idx] = cnt; n   } n   for (int i = 0; i < n; i++) scanf( %lld , &arr[i]); n   for (int i = 0; i < n; i++) { n     long long val = arr[i]; n     if (val % x == 0) { n       int mask = 0; n       d = val; n       for (int idx = 0; idx < div.size(); idx++) { n         long long i = div[idx]; n         int cnt = 0; n         while (d % i == 0) { n           d /= i; n           cnt++; n         } n         if (cnt > cnt_x[idx]) { n           mask |= (1 << idx); n         } n       } n       mskcnt[mask]++; n     } n   } n   for (int i = 0; i < div.size(); i++) { n     for (int mask = 0; mask < (1 << div.size()); mask++) { n       if (mask & (1 << i)) { n         mskcnt[mask] += mskcnt[mask ^ (1 << i)]; n       } n     } n   } n   long long ans = 0; n   for (int i = 0; i < n; i++) { n     long long val = arr[i]; n     if (y % val == 0) { n       int mask = 0; n       d = val; n       for (int idx = 0; idx < div.size(); idx++) { n         long long i = div[idx]; n         int cnt = 0; n         while (d % i == 0) { n           d /= i; n           cnt++; n         } n         if (cnt < cnt_y[idx]) { n           mask |= (1 << idx); n         } n       } n       mask = (~mask) & ((1 << div.size()) - 1); n       ans += mskcnt[mask]; n     } n   } n   printf( %lld n , ans); n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX_N = 100000; n int N, M, S; n vector<pair<int, int> > b; n vector<pair<pair<int, int>, int> > s; n vector<pair<int, int> > b2; n vector<pair<pair<int, int>, int> > s2; n int ans[MAX_N + 1]; n priority_queue<pair<int, int>, vector<pair<int, int> >, n                greater<pair<int, int> > > n     pq; n bool chk(int x) { n   long long cost = 0; n   while (!b.empty()) b.pop_back(); n   while (!s.empty()) s.pop_back(); n   for (int i = 0; i < b2.size(); i++) { n     b.push_back(b2[i]); n   } n   for (int i = 0; i < s2.size(); i++) { n     s.push_back(s2[i]); n   } n   while (!pq.empty()) pq.pop(); n   while (!b.empty()) { n     while (!s.empty() && s.back().first.first >= b.back().first) { n       pq.push({s.back().first.second, s.back().second}); n       s.pop_back(); n     } n     if (pq.empty()) { n       return false; n     } n     pair<int, int> now = pq.top(); n     pq.pop(); n     cost += (long long)now.first; n     for (int i = 0; i < x; i++) { n       if (b.empty()) break; n       pair<int, int> p = b.back(); n       b.pop_back(); n       ans[p.second] = now.second; n     } n   } n   return cost <= (long long)S; n } n int main() { n   scanf( %d%d%d , &N, &M, &S); n   for (int i = 0; i < M; i++) { n     int x; n     scanf( %d , &x); n     b2.push_back({x, i}); n   } n   for (int i = 0; i < N; i++) { n     int x; n     scanf( %d , &x); n     s2.push_back({{x, 0}, i}); n   } n   for (int i = 0; i < N; i++) { n     int x; n     scanf( %d , &x); n     s2[i].first.second = x; n   } n   sort(b2.begin(), b2.end()); n   sort(s2.begin(), s2.end()); n   int st = 0, ed = 100000, m; n   while (st < ed) { n     m = (st + ed) / 2; n     if (chk(m)) n       ed = m; n     else n       st = m + 1; n   } n   if (chk(st)) { n     printf( YES n ); n     for (int i = 0; i < M; i++) { n       printf( %d  , ans[i] + 1); n     } n   } else { n     printf( NO ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool yes; n int t, n, m, len, l, sender[105]; n map<string, int> msi; n map<int, string> mis; n string str, user[105], text[105]; n set<int> mention[105]; n int ans[105]; n int dp[105][105]; n char c; n bool solve(int pos, int idx) { n   if (pos == m) return 1; n   if (dp[pos][idx] != -1) return dp[pos][idx]; n   if (mention[pos].find(idx) != mention[pos].end()) return 0; n   dp[pos][idx] = 0; n   if (pos + 1 < m && sender[pos + 1] != -1) { n     if (idx == sender[pos + 1]) return 0; n     dp[pos][idx] = solve(pos + 1, sender[pos + 1]); n   } else { n     for (int i = 0; i < n; ++i) { n       if (i != idx) { n         dp[pos][idx] |= solve(pos + 1, i); n         if (dp[pos][idx]) break; n       } else if (pos == m - 1) n         dp[pos][idx] = true; n     } n   } n   if (dp[pos][idx]) ans[pos] = idx; n   return dp[pos][idx]; n } n int main() { n   scanf( %d%c , &t, &c); n   while (t--) { n     scanf( %d%c , &n, &c); n     memset(sender, -1, sizeof sender); n     memset(dp, -1, sizeof dp); n     for (int i = 0; i < n; ++i) { n       cin >> user[i]; n       msi[user[i]] = i; n       mis[i] = user[i]; n     } n     scanf( %d%c , &m, &c); n     for (int i = 0; i < m; ++i) { n       getline(cin, str,  : ); n       if (str.compare( ? ) == 0) n         sender[i] = -1; n       else n         sender[i] = msi[str]; n       getline(cin, text[i]); n     } n     for (int i = 0; i < m; ++i) { n       len = text[i].size(); n       for (int j = 0; j < n; ++j) { n         l = user[j].size(); n         yes = false; n         for (int k = 0; k < len; ++k) { n           if (text[i][k] == user[j][0] && k + l - 1 < len && n               text[i].compare(k, l, user[j]) == 0) { n             if (((k - 1 >= 0 && text[i][k - 1] !=  .  && n                   text[i][k - 1] !=  ,  && text[i][k - 1] !=  !  && n                   text[i][k - 1] !=  ?  && text[i][k - 1] !=    ) || n                  (k + l < len && text[i][k + l] !=  .  && n                   text[i][k + l] !=  ,  && text[i][k + l] !=  !  && n                   text[i][k + l] !=  ?  && text[i][k + l] !=    ))) { n             } else { n               yes = true; n               break; n             } n           } n         } n         if (yes) mention[i].insert(msi[user[j]]); n       } n     } n     l = 0; n     if (sender[0] != -1) n       l |= solve(0, sender[0]); n     else { n       for (int i = 0; i < n; ++i) { n         l |= solve(0, i); n         if (l) break; n       } n     } n     if (!l) n       cout <<  Impossible  << endl; n     else { n       for (int i = 0; i < m; ++i) { n         cout << user[ans[i]] <<  :  << text[i] << endl; n       } n     } n     msi.clear(), mis.clear(); n     for (int i = 0; i < m; ++i) mention[i].clear(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   cin >> t; n   while (t--) { n     int n; n     cin >> n; n     vector<int> a(n), b(n); n     for (auto &it : a) cin >> it; n     for (auto &it : b) cin >> it; n     int mna = *min_element(a.begin(), a.end()); n     int mnb = *min_element(b.begin(), b.end()); n     long long ans = 0; n     for (int i = 0; i < n; ++i) { n       ans += max(a[i] - mna, b[i] - mnb); n     } n     cout << ans << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1050; n int s[maxn][maxn]; n int main(int argc, char const *argv[]) { n   int n, a, b; n   cin >> n >> a >> b; n   if (a != 1 && b != 1) { n     printf( NO n ); n     return 0; n   } n   if (n == 1) { n     printf( YES n0 n ); n     return 0; n   } n   if (a == 1 && b == 1 && n <= 3) { n     printf( NO n ); n     return 0; n   } n   printf( YES n ); n   if (a == 1 && b == 1) { n     for (int i = 1; i < n; ++i) { n       s[i][i + 1] = s[i + 1][i] = 1; n     } n     for (int i = 1; i <= n; ++i) { n       for (int j = 1; j <= n; ++j) { n         printf( %d , s[i][j]); n       } n       printf(  n ); n     } n   } else if (a == 1) { n     for (int i = b; i <= n; ++i) { n       for (int j = b; j <= n; ++j) { n         s[i][j] = 1; n       } n     } n     for (int i = 1; i <= n; ++i) { n       for (int j = 1; j <= n; ++j) { n         s[i][j] = 1 - s[i][j]; n       } n       s[i][i] = 0; n     } n     for (int i = 1; i <= n; ++i) { n       for (int j = 1; j <= n; ++j) { n         printf( %d , s[i][j]); n       } n       printf(  n ); n     } n   } else { n     for (int i = a; i <= n; ++i) { n       for (int j = a; j <= n; ++j) { n         s[i][j] = 1; n       } n     } n     for (int i = 1; i <= n; ++i) s[i][i] = 0; n     for (int i = 1; i <= n; ++i) { n       for (int j = 1; j <= n; ++j) { n         printf( %d , s[i][j]); n       } n       printf(  n ); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n template <typename T> n T power(T x, T y, T mod) { n   T res = 1; n   while (y > 0) { n     if (y & 1) res = (res * x) % mod; n     y /= 2; n     x = (x * x) % mod; n   } n   return res; n } n using namespace std; n long long int a[2005][2005]; n long long int d1[4005]; n long long int d2[4005]; n long long int ele[2005][2005]; n int32_t main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long int n; n   cin >> n; n   for (long long int i = 0; i < n; i++) n     for (long long int j = 0; j < n; j++) cin >> a[i][j]; n   for (long long int i = 0; i < n; i++) { n     for (long long int j = 0; j < n; j++) { n       long long int b = a[i][j]; n       d1[j - i + n] += b; n       d2[n + n - i - j - 1] += b; n     } n   } n   long long int max1 = 0; n   long long int max2 = 0; n   long long int x1, y1, x2, y2; n   x1 = 1; n   x2 = 1; n   y1 = 1; n   y2 = 2; n   for (long long int i = 0; i < n; i++) { n     for (long long int j = 0; j < n; j++) { n       ele[i][j] = d1[j - i + n] + d2[2 * n - i - j - 1] - a[i][j]; n       if ((i + j) % 2) { n         if (max1 < ele[i][j]) { n           max1 = ele[i][j]; n           x1 = i + 1; n           y1 = j + 1; n         } n       } else { n         if (max2 < ele[i][j]) { n           max2 = ele[i][j]; n           x2 = i + 1; n           y2 = j + 1; n         } n       } n     } n   } n   cout << max1 + max2 <<   n ; n   cout << x1 <<     << y1 <<     << x2 <<     << y2 <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   for (int i = 0; i < n; i++) { n     int tmp; n     cin >> tmp; n     if (tmp % 2) n       cout << tmp <<      ; n     else n       cout << tmp - 1 <<      ; n   } n   cin.get(); n   cin.get(); n } n


#include <bits/stdc++.h> n using namespace std; n int n, a[1005], b[1005]; n int main() { n   bool same = 1; n   scanf( %d , &n); n   for (int i = 1; i <= n; ++i) { n     scanf( %d%d , a + i, b + i); n     same &= a[i] == b[i]; n   } n   if (!same) { n     puts( rated ); n     return 0; n   } n   for (int i = 2; i <= n; ++i) { n     if (a[i] > a[i - 1]) { n       puts( unrated ); n       return 0; n     } n   } n   puts( maybe ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long fpow(long long x, long long y, long long m) { n   long long temp; n   if (y == 0 || x == 1) return 1; n   temp = fpow(x, y / 2, m); n   if (y % 2 == 0) n     return ((temp) * (temp)) % m; n   else n     return (((x) % m) * ((temp * temp) % m)) % m; n } n long long gcd(long long a, long long b) { n   if (b == 0) return a; n   return gcd(b, a % b); n } n void sieve(long long n) { n   bool prime[5 * 100005]; n   memset(prime, true, sizeof(prime)); n   for (long long p = 2; p * p <= n; p++) n     if (prime[p] == true) n       for (long long i = p * p; i <= n; i += p) prime[i] = false; n   prime[1] = 0; n } n long long cnt, sum, mid, mx = -1e17, mn = 1e17, a[2 * 100005]; n long long n, m, d, t, i, j, k, l, r, x, y, z; n bool f, f1, f2; n string s; n int32_t main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cin >> n; n   vector<long long> dp(100005); n   for ((i) = 1; (i) <= (n); (i)++) { n     cin >> x >> y; n     cnt = 0; n     for (j = 1; j * j <= x; j++) { n       if (x % j == 0) { n         if (dp[j] < i - y) { n           cnt++; n         } n         dp[j] = i; n         if (dp[x / j] < i - y) { n           cnt++; n         } n         dp[x / j] = i; n       } n     } n     cout << cnt; n     cout <<   n ; n   } n } n


#include <bits/stdc++.h> n int main() { n   char c, str[100]; n   int i; n   scanf( %c , &c); n   getchar(); n   gets(str); n   if (c ==  L ) { n     for (i = 0; i < strlen(str); i++) { n       if (str[i] ==  q ) { n         str[i] =  w ; n       } else if (str[i] ==  w ) { n         str[i] =  e ; n       } else if (str[i] ==  r ) { n         str[i] =  t ; n       } else if (str[i] ==  t ) { n         str[i] =  y ; n       } else if (str[i] ==  y ) { n         str[i] =  u ; n       } else if (str[i] ==  u ) { n         str[i] =  i ; n       } else if (str[i] ==  i ) { n         str[i] =  o ; n       } else if (str[i] ==  o ) { n         str[i] =  p ; n       } else if (str[i] ==  a ) { n         str[i] =  s ; n       } else if (str[i] ==  s ) { n         str[i] =  d ; n       } else if (str[i] ==  d ) { n         str[i] =  f ; n       } else if (str[i] ==  f ) { n         str[i] =  g ; n       } else if (str[i] ==  g ) { n         str[i] =  h ; n       } else if (str[i] ==  h ) { n         str[i] =  j ; n       } else if (str[i] ==  j ) { n         str[i] =  k ; n       } else if (str[i] ==  k ) { n         str[i] =  l ; n       } else if (str[i] ==  l ) { n         str[i] =  ; ; n       } else if (str[i] ==  z ) { n         str[i] =  x ; n       } else if (str[i] ==  x ) { n         str[i] =  c ; n       } else if (str[i] ==  c ) { n         str[i] =  v ; n       } else if (str[i] ==  v ) { n         str[i] =  b ; n       } else if (str[i] ==  b ) { n         str[i] =  n ; n       } else if (str[i] ==  n ) { n         str[i] =  m ; n       } else if (str[i] ==  m ) { n         str[i] =  , ; n       } else if (str[i] ==  , ) { n         str[i] =  . ; n       } else if (str[i] ==  . ) { n         str[i] =  / ; n       } else if (str[i] ==  e ) { n         str[i] =  r ; n       } n     } n   } else if (c ==  R ) { n     for (i = 0; i < strlen(str); i++) { n       if (str[i] ==  w ) { n         str[i] =  q ; n       } else if (str[i] ==  e ) { n         str[i] =  w ; n       } else if (str[i] ==  r ) { n         str[i] =  e ; n       } else if (str[i] ==  t ) { n         str[i] =  r ; n       } else if (str[i] ==  y ) { n         str[i] =  t ; n       } else if (str[i] ==  u ) { n         str[i] =  y ; n       } else if (str[i] ==  i ) { n         str[i] =  u ; n       } else if (str[i] ==  o ) { n         str[i] =  i ; n       } else if (str[i] ==  p ) { n         str[i] =  o ; n       } else if (str[i] ==  s ) { n         str[i] =  a ; n       } else if (str[i] ==  d ) { n         str[i] =  s ; n       } else if (str[i] ==  f ) { n         str[i] =  d ; n       } else if (str[i] ==  g ) { n         str[i] =  f ; n       } else if (str[i] ==  h ) { n         str[i] =  g ; n       } else if (str[i] ==  j ) { n         str[i] =  h ; n       } else if (str[i] ==  k ) { n         str[i] =  j ; n       } else if (str[i] ==  l ) { n         str[i] =  k ; n       } else if (str[i] ==  ; ) { n         str[i] =  l ; n       } else if (str[i] ==  x ) { n         str[i] =  z ; n       } else if (str[i] ==  c ) { n         str[i] =  x ; n       } else if (str[i] ==  v ) { n         str[i] =  c ; n       } else if (str[i] ==  b ) { n         str[i] =  v ; n       } else if (str[i] ==  n ) { n         str[i] =  b ; n       } else if (str[i] ==  m ) { n         str[i] =  n ; n       } else if (str[i] ==  , ) { n         str[i] =  m ; n       } else if (str[i] ==  . ) { n         str[i] =  , ; n       } else if (str[i] ==  / ) { n         str[i] =  . ; n       } n     } n   } n   printf( %s , str); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 2e5 + 5; n inline long long read() { n   long long x = 0, f = 1; n   char ch = getchar(); n   while (ch >  9  || ch <  0 ) { n     if (ch ==  - ) f = -1; n     ch = getchar(); n   } n   while (ch >=  0  && ch <=  9 ) { n     x = x * 10 + ch -  0 ; n     ch = getchar(); n   } n   return x * f; n } n long long sum, n, q; n long long a[16]; n long long P[16]; n long long fac[16]; n bool vis[16]; n void get(long long sum) { n   long long res = 0; n   for (long long i = 1; i < n; i++) res = (res + a[i]) * (n - i); n   for (long long i = 1; i <= 15; i++) { n     a[i] = sum / fac[15 - i]; n     sum %= fac[15 - i]; n   } n   memset(vis, 0, sizeof(vis)); n   for (long long i = 1; i <= 15; i++) { n     long long cnt = 0; n     for (long long j = 1; j <= 15; j++) { n       if (!vis[j]) cnt++; n       if (cnt == a[i] + 1) { n         P[i] = j; n         vis[j] = 1; n         break; n       } n     } n   } n } n signed main() { n   n = read(); n   q = read(); n   fac[0] = 1; n   for (long long i = 1; i <= 15; i++) fac[i] = fac[i - 1] * i; n   while (q--) { n     long long opt; n     opt = read(); n     if (opt == 1) { n       long long l, r; n       l = read(); n       r = read(); n       long long ans = 0; n       get(sum); n       if (r > n - 15) { n         if (l > n - 15) { n           for (long long i = l - n + 15; i <= r - n + 15; i++) ans += P[i]; n           ans += (r - l + 1) * (n - 15); n         } else { n           ans += (l + n - 15) * (n - 14 - l) / 2; n           for (long long i = 1; i <= r - n + 15; i++) ans += P[i]; n           ans += (r - n + 15) * (n - 15); n         } n       } else n         ans = (l + r) * (r - l + 1) / 2; n       printf( %lld n , ans); n     } n     if (opt == 2) { n       long long x; n       x = read(); n       sum += x; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long modpow(long long a, long long b, long long m = 1000000007) { n   a %= m; n   long long res = 1; n   while (b) { n     if (b & 1) res = res * a % m; n     a = a * a % m; n     b >>= 1; n   } n   return res; n } n long long bpow(long long a, long long b) { n   long long res = 1; n   while (b) { n     if (b & 1) res = res * a; n     a = a * a; n     b >>= 1; n   } n   return res; n } n long long modinv(long long a) { return modpow(a, 1000000007 - 2, 1000000007); } n void graph(vector<vector<long long> > &adj, long long m) { n   long long x, y; n   for (long long i = 0; i < m; i++) { n     cin >> x >> y; n     adj[x - 1].push_back(y - 1); n     adj[y - 1].push_back(x - 1); n   } n } n const int mxN = 2e5 + 5; n void solve() { n   int n; n   cin >> n; n   string s; n   cin >> s; n   set<int> color[26]; n   std::vector<int> out(n); n   for (long long i = 0; i < s.size(); i++) { n     int x = s[i] -  a ; n     for (long long j = 1; j <= 26; j++) { n       bool ok = true; n       for (long long k = x + 1; k < 26; k++) { n         ok &= !(color[k].count(j)); n       } n       if (ok) { n         color[x].insert(j); n         out[i] = j; n         break; n       } n     } n   } n   set<int> distinct; n   for (auto &k : out) distinct.insert(k); n   cout << distinct.size() <<   n ; n   for (auto &k : out) cout << k <<    ; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int t = 1; n   while (t--) { n     solve(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n template <class T1, class T2> n bool chmin(T1 &a, T2 b) { n   return b < a && (a = b, true); n } n template <class T1, class T2> n bool chmax(T1 &a, T2 b) { n   return a < b && (a = b, true); n } n template <class T1, class T2> n void sortPair(vector<T1> &v1, vector<T2> &v2) { n   vector<pair<T1, T2>> u(v1.size()); n   for (int i = 0; i < u.size(); i++) u[i] = make_pair(v1[i], v2[i]); n   sort(u.begin(), u.end()); n   for (int i = 0; i < u.size(); i++) tie(v1[i], v2[i]) = u[i]; n } n long long solve() { n   long long d, n, m; n   cin >> d >> n >> m; n   vector<long long> x(m), p(m); n   for (int i = 0; i < (m); i++) scanf( %lld %lld , &x[i], &p[i]); n   x.insert(x.begin(), 0); n   p.insert(p.begin(), 0); n   x.push_back(d); n   p.push_back(0); n   m += 2; n   sortPair(x, p); n   vector<long long> next(m, -1); n   stack<int> s; n   for (int i = (m)-1; i >= 0; i--) { n     while (!s.empty() && p[i] <= p[s.top()]) s.pop(); n     next[i] = s.empty() ? -1 : s.top(); n     s.push(i); n   } n   long long full = n; n   long long ans = 0; n   int i = 0; n   while (i < m - 1) { n     if (x[i + 1] - x[i] > full) return -1; n     long long use, dist, ni; n     if (x[next[i]] - x[i] > full) { n       dist = x[i + 1] - x[i]; n       use = full - n; n       ni = i + 1; n     } else { n       dist = x[next[i]] - x[i]; n       use = max(0ll, dist - n); n       ni = next[i]; n     } n     ans += use * p[i]; n     n += use - dist; n     i = ni; n   } n   return ans; n } n int main() { n   cout << solve() << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n inline void read(T &x) { n   char c; n   bool nega = 0; n   while ((!isdigit(c = getchar())) && (c !=  - )) n     ; n   if (c ==  - ) { n     nega = 1; n     c = getchar(); n   } n   x = c - 48; n   while (isdigit(c = getchar())) x = x * 10 + c - 48; n   if (nega) x = -x; n } n template <typename T> n inline void writep(T x) { n   if (x > 9) writep(x / 10); n   putchar(x % 10 + 48); n } n template <typename T> n inline void write(T x) { n   if (x < 0) { n     putchar( - ); n     x = -x; n   } n   writep(x); n } n template <typename T> n inline void writeln(T x) { n   write(x); n   putchar(  n ); n } n int n, m, q; n char a[2 * 1003][2 * 1003]; n long long sum[2 * 1003][2 * 1003], sum1[2 * 1003][2 * 1003], ret, cn_n, cm_n; n long long mx, my; n long long sx1, sy1, sx2, sy2; n void dcy(long long left, long long right, long long lx, long long rx) { n   if (left > sy2 || right < sy1) return; n   if (left >= sy1 && right <= sy2) { n     ret += (right - left + 1) * (rx - lx + 1) / 2; n   } else if (right - left + 1 == m) { n     long long ly = max(sy1, left), ry = min(sy2, right); n     long long x = (lx - 1) / n, y = (ly - 1) / m; n     int k = ((x) ^ (y)); n     int k1 = 0; n     while (k) k1 += k & 1, k >>= 1; n     lx = (lx - 1) % n + 1, ly = (ly - 1) % m + 1, rx = (rx - 1) % n + 1, n     ry = (ry - 1) % m + 1; n     if (k1 & 1) n       ret += sum1[rx][ry] + sum1[lx - 1][ly - 1] - sum1[lx - 1][ry] - n              sum1[rx][ly - 1]; n     else n       ret += n           sum[rx][ry] + sum[lx - 1][ly - 1] - sum[lx - 1][ry] - sum[rx][ly - 1]; n   } else { n     long long mid = (left + right) >> 1; n     dcy(left, mid, lx, rx), dcy(mid + 1, right, lx, rx); n   } n } n void dcx(long long left, long long right) { n   if (left > sx2 || right < sx1) return; n   if (left >= sx1 && right <= sx2) n     ret += (sy2 - sy1 + 1) * (right - left + 1) / 2; n   else if (right - left + 1 == n) n     dcy(1, my, max(left, sx1), min(right, sx2)); n   else { n     int mid = (left + right) >> 1; n     dcx(left, mid), dcx(mid + 1, right); n   } n } n int main() { n   ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); n   int i, j; n   scanf( %d%d%d , &n, &m, &q); n   for (i = 1; i <= n; i++) scanf( %s , a[i] + 1); n   for (i = 1; i <= n; i++) n     for (j = 1; j <= m; j++) { n       sum[i][j] = sum[i + n][j + m] = a[i][j] -  0 ; n       sum[i + n][j] = sum[i][j + m] = sum[i][j] ^ 1; n     } n   n <<= 1, m <<= 1; n   for (i = 1; i <= n; i++) { n     for (j = 1; j <= m; j++) { n       sum[i][j] += sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1]; n       sum1[i][j] = i * j - sum[i][j]; n     } n   } n   mx = n; n   while (mx < 1e9) { n     mx *= 2; n   } n   my = m; n   while (my < 1e9) { n     my *= 2; n   } n   while (q--) { n     scanf( %d%d%d%d , &sx1, &sy1, &sx2, &sy2); n     ret = 0; n     dcx(1, mx); n     cout << ret << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int mark[111111]; n int a[111111]; n int b[111111]; n int n; n int noEle, cnt; n int main() { n   cin >> n; n   for (int i = 1; i <= n; i++) { n     cin >> a[i]; n     b[i] = a[i]; n   } n   sort(b, b + n + 1); n   for (int i = 1; i <= n; i++) { n     if (b[i] != a[i]) { n       noEle++; n       if (noEle % 2 != 0) cnt++; n       if (cnt > 1) { n         cout <<  NO ; n         return 0; n       } n     } n   } n   cout <<  YES ; n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n const int INF = 1000000000; n struct Point { n   int x, y; n   Point(int x_ = 0, int y_ = 0) : x(x_), y(y_) {} n   Point(std::istream &in) { n     in >> x >> y; n     x *= 2; n     y *= 2; n   } n }; n bool operator<(const Point &a, const Point &b) { n   return (a.x < b.x) || (a.x == b.x && a.y < b.y); n } n bool cmp_sum(const Point &a, const Point &b) { return (a.x + a.y < b.x + b.y); } n bool cmp_diff(const Point &a, const Point &b) { n   return (a.x - a.y < b.x - b.y); n } n int n, k; n vector<Point> gnome, metro; n vector<int> sorted_x, sorted_y; n vector<int> tree; n int curk; n void upd_val(int x, int val, const vector<int> &coords) { n   x = lower_bound(coords.begin(), coords.end(), x) - coords.begin(); n   x += curk; n   tree[x] = min(tree[x], val); n   x /= 2; n   while (x != 1) { n     tree[x] = min(tree[x * 2], tree[x * 2 + 1]); n     x /= 2; n   } n } n int get_min_val(int l, int r, const vector<int> &coords) { n   l = lower_bound(coords.begin(), coords.end(), l) - coords.begin(); n   r = lower_bound(coords.begin(), coords.end(), r) - coords.begin(); n   l += curk; n   r += curk; n   int res = INF; n   while (l < r) { n     res = min(res, min(tree[l], tree[r])); n     l = (l + 1) / 2; n     r = (r - 1) / 2; n   } n   if (l == r) { n     res = min(res, tree[l]); n   } n   return res; n } n void shrink(vector<int> &coord) { n   sort(coord.begin(), coord.end()); n   coord.resize(unique(coord.begin(), coord.end()) - coord.begin()); n } n template <typename T> n std::vector<int> argsort(const std::vector<T> &vals, bool reverse = false) { n   vector<int> result(vals.size()); n   for (int i = 0; i < int(vals.size()); ++i) { n     result[i] = i; n   } n   sort(result.begin(), result.end(), n        [&](int a, int b) -> bool { return (vals[a] < vals[b]); }); n   if (reverse) { n     std::reverse(result.begin(), result.end()); n   } n   return result; n } n void get_min_dist(const std::vector<Point> &gnome, std::vector<Point> metro, n                   std::vector<int> &result) { n   sorted_x.clear(); n   sorted_y.clear(); n   for (auto &x : gnome) { n     sorted_x.push_back(x.x); n     sorted_y.push_back(x.y); n   } n   for (auto &x : metro) { n     sorted_x.push_back(x.x); n     sorted_y.push_back(x.y); n   } n   shrink(sorted_x); n   shrink(sorted_y); n   int nn = gnome.size(); n   result.assign(nn, INF); n   auto indices = argsort(gnome); n   sort(metro.begin(), metro.end()); n   curk = 2; n   while (int(sorted_y.size()) > curk) curk *= 2; n   { n     tree.assign(2 * curk, INF); n     int l = 0, r = 0; n     while (l < nn) { n       int ind = indices[l]; n       while (r < k && metro[r].x <= gnome[ind].x) { n         upd_val(metro[r].y, -metro[r].x - metro[r].y, sorted_y); n         ++r; n       } n       result[ind] = min(result[ind], n                         get_min_val(sorted_y.front(), gnome[ind].y, sorted_y) + n                             gnome[ind].x + gnome[ind].y); n       ++l; n     } n   } n   { n     tree.assign(2 * curk, INF); n     int l = 0, r = 0; n     while (l < nn) { n       int ind = indices[l]; n       while (r < k && metro[r].x <= gnome[ind].x) { n         upd_val(metro[r].y, -metro[r].x + metro[r].y, sorted_y); n         ++r; n       } n       result[ind] = min(result[ind], n                         get_min_val(gnome[ind].y, sorted_y.back(), sorted_y) + n                             gnome[ind].x - gnome[ind].y); n       ++l; n     } n   } n   reverse(metro.begin(), metro.end()); n   reverse(indices.begin(), indices.end()); n   { n     tree.assign(2 * curk, INF); n     int l = 0, r = 0; n     while (l < nn) { n       int ind = indices[l]; n       while (r < k && metro[r].x >= gnome[ind].x) { n         upd_val(metro[r].y, metro[r].x - metro[r].y, sorted_y); n         ++r; n       } n       result[ind] = min(result[ind], n                         get_min_val(sorted_y.front(), gnome[ind].y, sorted_y) - n                             gnome[ind].x + gnome[ind].y); n       ++l; n     } n   } n   { n     tree.assign(2 * curk, INF); n     int l = 0, r = 0; n     while (l < nn) { n       int ind = indices[l]; n       while (r < k && metro[r].x >= gnome[ind].x) { n         upd_val(metro[r].y, metro[r].x + metro[r].y, sorted_y); n         ++r; n       } n       result[ind] = min(result[ind], n                         get_min_val(gnome[ind].y, sorted_y.back(), sorted_y) - n                             gnome[ind].x - gnome[ind].y); n       ++l; n     } n   } n } n int find_dist(pair<pair<int, int>, pair<int, int> > rect, const Point &pnt) { n   int sum = pnt.x + pnt.y; n   int diff = pnt.x - pnt.y; n   int sum_dist = n       max(0, -min(rect.first.second, sum) + max(rect.first.first, sum)); n   int diff_dist = n       max(0, -min(rect.second.second, diff) + max(rect.second.first, diff)); n   return max(sum_dist, diff_dist); n } n void get_all_min_dist(vector<pair<pair<int, int>, pair<int, int> > > rect, n                       vector<Point> metro, vector<int> &dist) { n   dist.assign(n, INF); n   vector<Point> ok_points; n   for (int i = 0; i < n; ++i) { n     const auto &cr = rect[i]; n     int a, b, c, d; n     tie(a, b) = cr.first; n     tie(c, d) = cr.second; n     ok_points.emplace_back((a + c) / 2, (a - c) / 2); n     ok_points.emplace_back((a + d) / 2, (a - d) / 2); n     ok_points.emplace_back((b + c) / 2, (b - c) / 2); n     ok_points.emplace_back((b + d) / 2, (b - d) / 2); n   } n   vector<int> tmp; n   get_min_dist(ok_points, metro, tmp); n   for (int i = 0; i < n * 4; ++i) { n     dist[i / 4] = min(dist[i / 4], tmp[i]); n   } n   vector<int> sorted_sum; n   vector<int> sorted_diff; n   for (auto &pnt : rect) { n     sorted_sum.push_back(pnt.first.first); n     sorted_sum.push_back(pnt.first.second); n     sorted_diff.push_back(pnt.second.first); n     sorted_diff.push_back(pnt.second.second); n   } n   for (auto &pnt : metro) { n     sorted_sum.push_back(pnt.x + pnt.y); n     sorted_diff.push_back(pnt.x - pnt.y); n   } n   shrink(sorted_sum); n   shrink(sorted_diff); n   sort(metro.begin(), metro.end(), cmp_sum); n   curk = 2; n   while (curk < int(sorted_diff.size())) curk *= 2; n   vector<pair<pair<int, int>, pair<int, int> > > segment(n); n   for (int i = 0; i < n; ++i) { n     segment[i] = make_pair(make_pair(rect[i].first.first, i), rect[i].second); n   } n   sort(segment.begin(), segment.end()); n   { n     tree.assign(curk * 2, INF); n     int nn = segment.size(); n     int l = 0, r = 0; n     while (l < nn) { n       while (r < k && metro[r].x + metro[r].y <= segment[l].first.first) { n         upd_val(metro[r].x - metro[r].y, -metro[r].y - metro[r].x, sorted_diff); n         ++r; n       } n       int ind = segment[l].first.second; n       dist[ind] = n           min(dist[ind], get_min_val(segment[l].second.first, n                                      segment[l].second.second, sorted_diff) + n                              segment[l].first.first); n       ++l; n     } n   } n   reverse(metro.begin(), metro.end()); n   for (int i = 0; i < n; ++i) { n     segment[i] = make_pair(make_pair(rect[i].first.second, i), rect[i].second); n   } n   sort(segment.rbegin(), segment.rend()); n   { n     tree.assign(curk * 2, INF); n     int nn = segment.size(); n     int l = 0, r = 0; n     while (l < nn) { n       while (r < k && metro[r].x + metro[r].y >= segment[l].first.first) { n         upd_val(metro[r].x - metro[r].y, metro[r].x + metro[r].y, sorted_diff); n         ++r; n       } n       int ind = segment[l].first.second; n       dist[ind] = n           min(dist[ind], get_min_val(segment[l].second.first, n                                      segment[l].second.second, sorted_diff) - n                              segment[l].first.first); n       ++l; n     } n   } n   sort(metro.begin(), metro.end(), cmp_diff); n   for (int i = 0; i < n; ++i) { n     segment[i] = make_pair(make_pair(rect[i].second.first, i), rect[i].first); n   } n   sort(segment.begin(), segment.end()); n   curk = 2; n   while (curk < int(sorted_sum.size())) curk *= 2; n   { n     tree.assign(curk * 2, INF); n     int nn = segment.size(); n     int l = 0, r = 0; n     while (l < nn) { n       while (r < k && metro[r].x - metro[r].y <= segment[l].first.first) { n         upd_val(metro[r].x + metro[r].y, metro[r].y - metro[r].x, sorted_sum); n         ++r; n       } n       int ind = segment[l].first.second; n       dist[ind] = n           min(dist[ind], get_min_val(segment[l].second.first, n                                      segment[l].second.second, sorted_sum) + n                              segment[l].first.first); n       ++l; n     } n   } n   reverse(metro.begin(), metro.end()); n   for (int i = 0; i < n; ++i) { n     segment[i] = make_pair(make_pair(rect[i].second.second, i), rect[i].first); n   } n   sort(segment.rbegin(), segment.rend()); n   { n     tree.assign(curk * 2, INF); n     int nn = segment.size(); n     int l = 0, r = 0; n     while (l < nn) { n       while (r < k && metro[r].x - metro[r].y >= segment[l].first.first) { n         upd_val(metro[r].x + metro[r].y, metro[r].x - metro[r].y, sorted_sum); n         ++r; n       } n       int ind = segment[l].first.second; n       dist[ind] = n           min(dist[ind], get_min_val(segment[l].second.first, n                                      segment[l].second.second, sorted_sum) - n                              segment[l].first.first); n       ++l; n     } n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin >> n >> k; n   for (int i = 0; i < n; ++i) { n     gnome.emplace_back(std::cin); n   } n   for (int i = 0; i < k; ++i) { n     metro.emplace_back(std::cin); n   } n   int min_x = INF, max_x = -INF; n   int min_y = INF, max_y = -INF; n   for (const auto &pnt : gnome) { n     min_x = min(min_x, pnt.x + pnt.y); n     max_x = max(max_x, pnt.x + pnt.y); n     min_y = min(min_y, pnt.x - pnt.y); n     max_y = max(max_y, pnt.x - pnt.y); n   } n   int result = (max(max_x - min_x, max_y - min_y) + 1) / 2; n   if (n > 1 && k) { n     vector<int> dist; n     get_min_dist(gnome, metro, dist); n     auto indices = argsort(dist, true); n     vector<pair<pair<int, int>, pair<int, int> > > all_rect; n     vector<int> add_dist; n     min_x = INF, max_x = -INF; n     min_y = INF, max_y = -INF; n     for (int i = 0; i < n; ++i) { n       const auto &pnt = gnome[indices[i]]; n       min_x = min(min_x, pnt.x + pnt.y); n       max_x = max(max_x, pnt.x + pnt.y); n       min_y = min(min_y, pnt.x - pnt.y); n       max_y = max(max_y, pnt.x - pnt.y); n       int dist = (max(max_x - min_x, max_y - min_y) + 1) / 2; n       add_dist.push_back(dist); n       all_rect.emplace_back(make_pair(max_x - dist, min_x + dist), n                             make_pair(max_y - dist, min_y + dist)); n     } n     result = min(result, dist[indices[0]]); n     vector<int> new_dist; n     get_all_min_dist(all_rect, metro, new_dist); n     for (int i = 0; i < n - 1; ++i) { n       int t1 = add_dist[i]; n       int t2 = new_dist[i]; n       int t3 = dist[indices[i + 1]]; n       int x = (max(0, min(2 * t2, t3 + t2 - t1)) + 1) / 2; n       result = min(result, max(t1 + x, t3 + t2 - x)); n     } n   } n   result = (result + 1) / 2; n   cout << result <<   n ; n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n #define ll long long n #define f(i, x, n) for (int i = x; i < (int)(n); ++i) n const int N = 1e6 + 10, mod = 998244353; n const double eps = 1e-7; n  n inline int add(int a, int b) { return a + b >= mod ? a + b - mod : a + b; } n inline int mul(int a, int b) { return (ll)a * b % mod; } n  n int n; n string s; n  n ll fact[1000001], inv[1000001];// mod inv = n ^ mod-2 n ll FastPower(int a, int b) n { n     if(b == 0) n         return 1; n     ll res = FastPower(a, b/2); n     if(b%2) n         return res * res % mod * a % mod; n     return res * res % mod; n } n ll nCk(int n, int k) n { n  if(n < k) n   return 0; n     return fact[n] * inv[k] % mod * inv[n-k] % mod; n } n  n int main() n { n  ios_base::sync_with_stdio(0); n  cin.tie(0); n #ifndef ONLINE_JUDGE n  freopen( input.txt ,  r , stdin); n #endif n  n  fact[0] = 1; n     inv[0] = FastPower(1, mod-2); n     for(int i=1; i<=1000000; ++i) n     { n         fact[i] = fact[i-1] * i % mod; n         inv[i] = FastPower(fact[i], mod-2); n     } n  int t; n  cin >> t; n  while(t--) n     { n   cin >> n >> s; n   vector<int> a; n   for(int i=0; i<n; ++i){ n    if(i < n-1 && s[i] ==  1  && s[i+1] ==  1 ){ n     a.push_back(2); n     ++i; n     continue; n    } n    a.push_back(s[i]- 0 ); n   } n   n = a.size(); n   ll ans = 1; n   int space = 0, nof2 = 0; n   for(int i=0; i<n; ++i){ n    //cout << a[i] <<    ; n    nof2 += a[i] == 2; n    space += a[i] == 0; n   } n   ans = nCk(nof2+space, space); n   cout << ans <<   n ; n     } n   n  n }


#include <bits/stdc++.h> n using namespace std; n const int inf = 0x3f3f3f3f; n const double eps = 0.00000001; n void pr() { cout << endl; } n template <typename T1, typename... T2> n void pr(const T1& arg, const T2&... args) { n   cout << arg <<    ; n   pr(args...); n } n const int N = 5e5 + 10; n vector<int> v[N], mp[N], l_u[N], l_d[N], r_u[N], r_d[N]; n int dui[N], n, m; n void init() { n   for (int i = 1; i <= n; ++i) n     v[i].clear(), mp[i].clear(), l_u[i].clear(), l_d[i].clear(), r_u[i].clear(), n         r_d[i].clear(); n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   ; n   int T; n   cin >> T; n   while (T--) { n     cin >> n >> m; n     vector<pair<int, int> > temp; n     for (int i = 1; i <= n; ++i) { n       v[i].push_back(233); n       for (int j = 1; j <= m; ++j) { n         int x; n         cin >> x; n         v[i].push_back(x); n       } n     } n     for (int i = 1; i <= n; ++i) { n       temp.push_back(pair<int, int>(v[i][1], i)); n     } n     sort(temp.begin(), temp.end()); n     int cnt = 0; n     for (int i = 0; i < temp.size(); ++i) { n       int fir = temp[i].second; n       mp[++cnt].push_back(233); n       dui[cnt] = temp[i].second; n       l_u[cnt].push_back(233); n       l_d[cnt].push_back(233); n       r_u[cnt].push_back(233); n       r_d[cnt].push_back(233); n       for (int j = 1; j <= m; ++j) { n         mp[cnt].push_back(v[fir][j]); n         l_u[cnt].push_back(v[fir][j]); n         l_d[cnt].push_back(v[fir][j]); n         r_u[cnt].push_back(v[fir][j]); n         r_d[cnt].push_back(v[fir][j]); n       } n     } n     for (int i = 1; i <= n; ++i) { n       for (int j = 1; j <= m; ++j) { n         l_u[i][j] = max({i - 1 >= 1 ? l_u[i - 1][j] : 0, n                          j - 1 >= 1 ? l_u[i][j - 1] : 0, l_u[i][j]}); n       } n     } n     for (int i = n; i >= 1; --i) { n       for (int j = 1; j <= m; ++j) { n         l_d[i][j] = min({i + 1 <= n ? l_d[i + 1][j] : inf, n                          j - 1 >= 1 ? l_d[i][j - 1] : inf, l_d[i][j]}); n       } n     } n     for (int i = 1; i <= n; ++i) { n       for (int j = m; j >= 1; --j) { n         r_u[i][j] = min({i - 1 >= 1 ? r_u[i - 1][j] : inf, n                          j + 1 <= m ? r_u[i][j + 1] : inf, r_u[i][j]}); n       } n     } n     for (int i = n; i >= 1; --i) { n       for (int j = m; j >= 1; --j) { n         r_d[i][j] = max({i + 1 <= n ? r_d[i + 1][j] : 0, n                          j + 1 <= m ? r_d[i][j + 1] : 0, r_d[i][j]}); n       } n     } n     bool flag = 1; n     for (int i = 1; i < n; ++i) { n       for (int j = 1; j < m; ++j) { n         if (l_u[i][j] < l_d[i + 1][j] && r_u[i][j + 1] > r_d[i + 1][j + 1]) { n           flag = 0; n           cout <<  YES  << endl; n           bool op[N]; n           memset(op, 0, sizeof(op)); n           for (int k = 1; k <= i; ++k) { n             op[dui[k]] = 1; n           } n           for (int k = 1; k <= n; ++k) { n             if (op[k]) n               cout <<  B ; n             else n               cout <<  R ; n           } n           cout <<     << j << endl; n         } n         if (!flag) break; n       } n       if (!flag) break; n     } n     if (flag) cout <<  NO  << endl; n     init(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int n, m; n   cin >> n >> m; n   map<int, set<pair<int, string>, greater<pair<int, string> > > > mp; n   for (int i = 0; i < n; i++) { n     string s; n     int a, b; n     cin >> s >> a >> b; n     mp[a].insert(pair<int, string>(b, s)); n   } n   for (int i = 1; i <= m; i++) { n     pair<int, string> a, b, c; n     auto it = mp[i].begin(); n     a = *it; n     it++; n     b = *it; n     if (mp[i].size() > 2) n       it++; n     else { n       cout << a.second <<     << b.second << endl; n       continue; n     } n     c = *it; n     if ((b.first == c.first)) { n       cout <<  ?  << endl; n     } else { n       cout << a.second <<     << b.second << endl; n     } n   } n   return 0; n } n