#include <bits/stdc++.h> n using namespace std; n long long n, ans, a[300123], maxx[300123], minx[300123], box[800123]; n void dopart(long long l, long long r) { n   if (l == r) { n     ans++; n     return; n   } n   long long mid = (l + r) / 2; n   dopart(l, mid); n   dopart(mid + 1, r); n   maxx[mid] = a[mid], minx[mid] = a[mid]; n   for (long long i = mid - 1; i >= l; i--) { n     maxx[i] = max(maxx[i + 1], a[i]), minx[i] = min(minx[i + 1], a[i]); n   } n   maxx[mid + 1] = a[mid + 1], minx[mid + 1] = a[mid + 1]; n   for (long long i = mid + 2; i <= r; i++) { n     maxx[i] = max(maxx[i - 1], a[i]), minx[i] = min(minx[i - 1], a[i]); n   } n   for (long long i = mid; i >= l; i--) { n     long long now = maxx[i] - minx[i]; n     if (i + now <= mid || i + now > r) continue; n     if (maxx[now + i] <= maxx[i] && minx[now + i] >= minx[i]) ans++; n   } n   for (long long i = mid + 1; i <= r; i++) { n     long long now = maxx[i] - minx[i]; n     if (i - now >= mid + 1 || i - now < l) continue; n     if (maxx[i - now] <= maxx[i] && minx[i - now] >= minx[i]) ans++; n   } n   long long you1 = mid + 1, you2 = mid + 1; n   for (long long i = mid; i >= l; i--) { n     while (you2 <= r && maxx[you2] < maxx[i]) box[minx[you2] + you2]++, you2++; n     while (you1 < you2 && minx[you1] > minx[i]) n       box[minx[you1] + you1]--, you1++; n     ans = ans + box[i + maxx[i]]; n   } n   for (long long i = you1; i < you2; i++) box[minx[i] + i]--; n   long long zuo1 = mid, zuo2 = mid; n   for (long long i = mid + 1; i <= r; i++) { n     while (zuo1 >= l && maxx[zuo1] < maxx[i]) n       box[minx[zuo1] - zuo1 + n + 1]++, zuo1--; n     while (zuo2 > zuo1 && minx[zuo2] > minx[i]) n       box[minx[zuo2] - zuo2 + n + 1]--, zuo2--; n     ans = ans + box[maxx[i] - i + n + 1]; n   } n   for (long long i = zuo2; i > zuo1; i--) box[minx[i] - i + n + 1]--; n } n int main() { n   cin >> n; n   for (long long i = 1; i <= n; i++) { n     long long p, q; n     cin >> p >> q; n     a[p] = q; n   } n   dopart(1, n); n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n const double PI = acos(-1); n const double eps = 1e-9; n const int inf = 2000000000; n const long long infLL = 9000000000000000000; n inline bool checkBit(long long n, int i) { return n & (1LL << i); } n inline long long setBit(long long n, int i) { n   return n | (1LL << i); n   ; n } n inline long long resetBit(long long n, int i) { return n & (~(1LL << i)); } n int fx[] = {0, 0, +1, -1}; n int fy[] = {+1, -1, 0, 0}; n inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; } n inline bool isLeapYear(long long year) { n   return (year % 400 == 0) || (year % 4 == 0 && year % 100 != 0); n } n inline void normal(long long &a) { n   a %= 998244353; n   (a < 0) && (a += 998244353); n } n inline long long modMul(long long a, long long b) { n   a %= 998244353, b %= 998244353; n   normal(a), normal(b); n   return (a * b) % 998244353; n } n inline long long modAdd(long long a, long long b) { n   a %= 998244353, b %= 998244353; n   normal(a), normal(b); n   return (a + b) % 998244353; n } n inline long long modSub(long long a, long long b) { n   a %= 998244353, b %= 998244353; n   normal(a), normal(b); n   a -= b; n   normal(a); n   return a; n } n inline long long modPow(long long b, long long p) { n   long long r = 1; n   while (p) { n     if (p & 1) r = modMul(r, b); n     b = modMul(b, b); n     p >>= 1; n   } n   return r; n } n inline long long modInverse(long long a) { return modPow(a, 998244353 - 2); } n inline long long modDiv(long long a, long long b) { n   return modMul(a, modInverse(b)); n } n inline bool isInside(pair<int, int> p, long long n, long long m) { n   return (p.first >= 0 && p.first < n && p.second >= 0 && p.second < m); n } n inline bool isInside(pair<int, int> p, long long n) { n   return (p.first >= 0 && p.first < n && p.second >= 0 && p.second < n); n } n inline bool isSquare(long long x) { n   long long s = sqrt(x); n   return (s * s == x); n } n inline bool isFib(long long x) { n   return isSquare(5 * x * x + 4) || isSquare(5 * x * x - 4); n } n inline bool isPowerOfTwo(long long x) { n   return ((1LL << (long long)log2(x)) == x); n } n struct func { n   bool operator()(pair<int, int> const &a, pair<int, int> const &b) { n     if (a.first == b.first) return (a.second < b.second); n     return (a.first < b.first); n   } n }; n long long corner(long long n, long long i) { n   return (((n - i - 1ll) >= 0) ? modMul(180ll, modPow(10ll, n - i - 1ll)) : 0); n } n long long middle(long long n, long long i) { n   return (((n - i - 2) >= 0) n               ? modMul(n - i - 1, modMul(810ll, modPow(10ll, n - i - 2))) n               : 0); n } n long long getResult(long long n, long long i) { n   if (i == n) return 10; n   return modAdd(corner(n, i), middle(n, i)); n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   ; n   long long n; n   cin >> n; n   for (int i = 1; i <= n; ++i) { n     cout << getResult(n, i) <<    ; n   } n   cout <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int modu = 1e9 + 7; n long long int mod(long long int n) { return (n % modu); } n bool cmp(long long int a, long long int b) { return a > b; } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long int N, a, b, c, d, x = 0; n   pair<int, int> P[205], s; n   cin >> N; n   for (int i = 0; i < N; i++) { n     cin >> P[i].first >> P[i].second; n   } n   for (int i = 0; i < N; i++) { n     a = b = c = d = 0; n     s.first = P[i].first; n     s.second = P[i].second; n     for (int j = 0; j < N; j++) { n       if (i != j) { n         if (P[j].first > s.first && P[j].second == s.second) n           a = 1; n         else if (P[j].first < s.first && P[j].second == s.second) n           b = 1; n         else if (P[j].first == s.first && P[j].second > s.second) n           c = 1; n         else if (P[j].first == s.first && P[j].second < s.second) n           d = 1; n       } n     } n     if (a == 1 && b == 1 && c == 1 && d == 1) x++; n   } n   cout << x; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int a, b, n, q = 0, z = 0; n   cin >> a >> b >> n; n   for (int i = 0; n >= 0; ++i) { n     for (int j = a; j >= 1; --j) { n       if (a % j == 0 && n % j == 0) { n         q = n; n         n = n - j; n         break; n       } n     } n     if (n >= 0) { n       for (int c = b; c >= 1; --c) { n         if (b % c == 0 && n % c == 0) { n           z = n; n           n = n - c; n           break; n         } n       } n     } n   } n   if (z == 0) { n     cout <<  0 ; n   } n   if (q == 0) { n     cout <<  1 ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 3077; n int n, m, p, k, s[N], t[N], ls[N], nxt[N]; n long long ans; n vector<int> P[N]; n int main() { n   scanf( %d%d%d%d , &n, &m, &p, &k); n   for (int i = 1; i <= p; i++) { n     int x, y; n     scanf( %d%d , &x, &y); n     P[x].push_back(y); n   } n   for (int u = n; u >= 1; u--) { n     for (int i = 0; i < P[u].size(); i++) ++s[P[u][i]]; n     int l = 1, r = 0, yjy = 0; n     long long aii = 0; n     while (1) { n       while (r + 1 <= m && yjy < k) yjy += s[++r]; n       if (yjy < k) break; n       while (l <= r && yjy >= k) yjy -= s[l++], aii += m - r + 1; n     } n     for (int i = 1; i <= m; i++) t[i] = s[i]; n     for (int i = 0; i <= m + 1; i++) ls[i] = i - 1, nxt[i] = i + 1; n     for (int i = 1; i <= m; i++) n       if (!s[i]) ls[nxt[i]] = ls[i], nxt[ls[i]] = nxt[i]; n     for (int d = n; d >= u; d--) { n       ans += aii; n       for (int i = 0; i < P[d].size(); i++) { n         int s = P[d][i], sl = t[s], sr = 0; n         l = r = s; n         while (nxt[r] <= m && sl + sr + t[nxt[r]] <= k) sr += t[r = nxt[r]]; n         while (1) { n           if (sl + sr == k) aii -= (l - ls[l]) * (nxt[r] - r); n           sl += t[l = ls[l]]; n           if (!l || sl > k) break; n           while (sl + sr > k) sr -= t[r], r = ls[r]; n         } n         --t[s]; n         if (!t[s]) ls[nxt[s]] = ls[s], nxt[ls[s]] = nxt[s]; n       } n     } n   } n   printf( %lld , ans); n } n


#include <bits/stdc++.h> n const long long mod = 998244353; n using namespace std; n pair<long long, long long> dp[20][2][1 << 10]; n int k; n int s[20]; n long long pw[20]; n pair<long long, long long> solve(int i, bool U, int mask) { n   if (i < 0) return {0, 1}; n   pair<long long, long long> &ret = dp[i][U][mask]; n   if (ret.first + 1) return ret; n   ret = {0, 0}; n   int L = U ? 9 : s[i]; n   for (int e = 0; e <= L; e++) { n     int Mask = mask | (mask > 0 ? (1 << e) : ((e > 0) * (1 << e))); n     if (__builtin_popcount(Mask) > k) continue; n     pair<long long, long long> temp = solve(i - 1, U || e < s[i], Mask); n     ret.first += temp.first + temp.second * e % mod * pw[i] % mod; n     ret.first %= mod; n     ret.second += temp.second; n     ret.second %= mod; n   } n   return ret; n } n int main() { n   ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); n   pw[0] = 1; n   for (int i = 1; i <= 18; i++) pw[i] = pw[i - 1] * 10LL % mod; n   long long l, r; n   cin >> l >> r >> k; n   for (int i = 0; i < 18; i++) s[i] = r % 10, r /= 10; n   memset(dp, -1, sizeof dp); n   long long ans = solve(17, 0, 0).first; n   l--; n   for (int i = 0; i < 18; i++) s[i] = l % 10, l /= 10; n   memset(dp, -1, sizeof dp); n   cout << ((ans - solve(17, 0, 0).first) % mod + mod) % mod; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long M = 1e9 + 7; n long long cnt[3000005], pre[3000005]; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(NULL); n   ; n   long long n; n   scanf( %lld , &n); n   long long a; n   for (long long i = 0; i < n; i++) { n     scanf( %lld , &a); n     cnt[a]++; n   } n   for (long long i = 1; i < 3000005; i++) { n     for (long long j = 1; i * j < 3000005; j++) { n       if (i == j) n         pre[i * j] += (cnt[i] * (cnt[i] - 1)); n       else n         pre[i * j] += cnt[i] * cnt[j]; n     } n   } n   for (long long i = 1; i < 3000005; i++) pre[i] += pre[i - 1]; n   long long m, p, an = 0, tot = (n * (n - 1)); n   scanf( %lld , &m); n   for (long long i = 0; i < m; i++) { n     scanf( %lld , &p); n     an = tot - pre[p - 1]; n     printf( %lld n , an); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> darmo; n vector<pair<int, int> > tab; n vector<bool> done; n vector<int> wolne; n int n, k; n int main() { n   scanf( %d %d , &n, &k); n   darmo.resize(n); n   tab.resize(n); n   done.resize(k + 1, false); n   long long res = 0; n   for (int i = 0; i < n; i++) scanf( %d , &darmo[i]); n   for (int i = 0; i < n; i++) { n     scanf( %d , &tab[i].first); n     tab[i].second = i; n   } n   sort(tab.begin(), tab.end()); n   reverse(tab.begin(), tab.end()); n   for (int i = 0; i < n; i++) { n     if (!done[darmo[tab[i].second]]) { n       done[darmo[tab[i].second]] = true; n     } else n       wolne.push_back(tab[i].first); n   } n   sort(wolne.begin(), wolne.end()); n   int x = 0; n   for (int i = 1; i < k + 1; i++) n     if (!done[i]) { n       res += (long long)wolne[x]; n       x++; n     } n   printf( %lld n , res); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, q, res[111][111]; n pair<int, int> pos[111][111]; n int type, r, c, x; n int main() { n   scanf( %d %d %d , &n, &m, &q); n   for (int i = 1; i <= n; ++i) n     for (int j = 1; j <= m; ++j) pos[i][j] = pair<int, int>(i, j); n   while (q--) { n     scanf( %d , &type); n     if (type == 1) { n       scanf( %d , &r); n       for (int i = 0; i < m; ++i) pos[r][i] = pos[r][i + 1]; n       pos[r][m] = pos[r][0]; n     } else if (type == 2) { n       scanf( %d , &c); n       for (int i = 0; i < n; ++i) pos[i][c] = pos[i + 1][c]; n       pos[n][c] = pos[0][c]; n     } else { n       scanf( %d %d %d , &r, &c, &x); n       res[pos[r][c].first][pos[r][c].second] = x; n     } n   } n   for (int i = 1; i <= n; ++i) { n     for (int j = 1; j <= m; ++j) printf( %d  , res[i][j]); n     printf(  n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 105; n char mp[3][N], tmp[3][N], g[55][3][N]; n bool vis[55][3][N]; n int n, k; n void getNext(int id) { n   memcpy(g[id], mp, sizeof(mp)); n   for (int i = int(0); i <= int((3) - 1); i++) n     for (int j = int(1); j <= int(n - 3); j++) tmp[i][j] = mp[i][j + 3]; n   for (int i = int(0); i <= int((3) - 1); i++) n     tmp[i][n - 2] = tmp[i][n - 1] = tmp[i][n] =  . ; n   memcpy(mp, tmp, sizeof(tmp)); n } n int dx[] = {0, -1, 1}, dy[] = {0, 0, 0}; n bool good(int now, int x, int y) { n   return x >= 0 && x < 3 && g[now][x][y] ==  .  && g[now - 1][x][y + 1] ==  . ; n } n bool bfs(int sx, int sy) { n   memset(vis, 0, sizeof(vis)); n   int now = 0, x = sx, y = sy; n   queue<int> q; n   q.push(now), q.push(x); n   while (q.size()) { n     now = q.front(); n     q.pop(); n     x = q.front(); n     q.pop(); n     if (now > 50) { n       return 1; n     } n     for (int i = int(0); i <= int((3) - 1); i++) { n       if (g[now][x][y + 1] !=  . ) continue; n       int tx = x + dx[i]; n       if (good(now + 1, tx, y)) { n         if (!vis[now + 1][tx][y]) { n           q.push(now + 1), q.push(tx); n           vis[now + 1][tx][y] = 1; n         } n       } n     } n   } n   return 0; n } n int main() { n   ios::sync_with_stdio(0); n   int t; n   cin >> t; n   while (t--) { n     cin >> n >> k; n     for (int i = int(0); i <= int((3) - 1); i++) { n       cin >> (mp[i] + 1); n     } n     int sx, sy; n     for (int i = int(0); i <= int((3) - 1); i++) { n       for (int j = int(1); j <= int(n); j++) n         if (mp[i][j] ==  s ) { n           sx = i, sy = j; n           mp[i][j] =  . ; n         } n     } n     for (int i = int(0); i <= int((54) - 1); i++) getNext(i); n     if (bfs(sx, sy)) n       puts( YES ); n     else n       puts( NO ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 2e5 + 100; n char num[maxn]; n char num2[maxn]; n vector<int> vec; n queue<int> que; n inline int read() { n   char ch = getchar(); n   int x = 0, f = 1; n   while (ch <  0  || ch >  9 ) { n     if (ch ==  - ) f = -1; n     ch = getchar(); n   } n   while ( 0  <= ch && ch <=  9 ) { n     x = x * 10 + ch -  0 ; n     ch = getchar(); n   } n   return x * f; n } n int main() { n   int n = read(), sx = read(), sy = read(); n   int s1 = 0, s2 = 0, s3 = 0, s4 = 0; n   int u = 0, d = 0, l = 0, r = 0; n   for (int i = 1; i <= n; ++i) { n     int x, y; n     scanf( %d%d , &x, &y); n     if (x < sx) { n       if (y < sy) { n         s2++; n         s4++; n       } else if (y > sy) { n         s2++; n         s3++; n       } else if (y == sy) { n         d++; n       } n     } else if (x > sx) { n       if (y < sy) { n         s1++; n         s4++; n       } else if (y > sy) { n         s1++; n         s3++; n       } else { n         u++; n       } n     } else if (x == sx) { n       if (y < sy) { n         l++; n       } else if (y > sy) { n         r++; n       } else { n         continue; n       } n     } n   } n   int num1 = s1 + u; n   int num2 = s3 + r; n   int num3 = s2 + d; n   int num4 = s4 + l; n   if (num1 >= num2 && num1 > num3 && num1 >= num4) { n     printf( %d n , num1); n     printf( %d %d n , sx + 1, sy); n   } else if (num2 >= num1 && num2 > num3 && num2 >= num4) { n     cout << num2 << endl; n     printf( %d %d n , sx, sy + 1); n   } else if (num3 >= num2 && num3 > num1 && num3 >= num4) { n     cout << num3 << endl; n     printf( %d %d n , sx - 1, sy); n   } else if (num4 >= num2 && num4 > num3 && num4 >= num1) { n     cout << num4 << endl; n     printf( %d %d n , sx, sy - 1); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long a[1000010]; n long long l[1000010], r[1000010]; n vector<pair<int, int>> g1[1000010], g2[1000010]; n int n, q; n long long ans[1000010]; n const int N = 1000000; n long long sum[N * 4]; n long long flag[N * 4]; n int cnt_v; n void build(int n) { n   cnt_v = 1; n   while (cnt_v <= n) { n     cnt_v <<= 1; n   } n   memset(sum, 0, sizeof(sum)); n   memset(flag, 0, sizeof(flag)); n } n void push_down(int t, long long l, long long r) { n   if (flag[t]) { n     long long mid = (l + r) >> 1; n     sum[t << 1] += flag[t] * (mid - l + 1); n     sum[(t << 1) + 1] += flag[t] * (r - mid); n     flag[t << 1] += flag[t]; n     flag[(t << 1) + 1] += flag[t]; n     flag[t] = 0; n   } n } n void push_up(int t) { sum[t] = sum[t << 1] + sum[(t << 1) + 1]; } n void upd(int x, int lx, int rx, int l, int r) { n   if (lx > rx) return; n   if (l > rx || r < lx) return; n   if (lx >= l && rx <= r) { n     sum[x] += (rx - lx + 1); n     flag[x]++; n     return; n   } n   { n     push_down(x, lx, rx); n     upd(x * 2, lx, (lx + rx) / 2, l, r); n     upd(x * 2 + 1, (lx + rx) / 2 + 1, rx, l, r); n     push_up(x); n   } n } n long long get(int x, int lx, int rx, int l, int r) { n   if (lx > rx) return 0; n   if (l > rx || r < lx) return 0; n   if (lx >= l && rx <= r) { n     return sum[x]; n   } else { n     push_down(x, lx, rx); n     return get(x * 2, lx, (lx + rx) / 2, l, r) + n            get(x * 2 + 1, (lx + rx) / 2 + 1, rx, l, r); n   } n } n void init() { build(n); } n void upd(long long l, long long r, long long val) { upd(1, 1, cnt_v, l, r); } n long long get_sum(long long l, long long r) { n   long long t = get(1, 0, cnt_v, l, r); n   return t; n } n pair<int, int> st[1000040]; n int main() { n   scanf( %d%d , &n, &q); n   for (int i = 1; i < n + 1; ++i) { n     scanf( %lld , &a[i]); n   } n   for (int i = 0; i < q; ++i) { n     scanf( %lld , &l[i]); n   } n   for (int i = 0; i < q; ++i) { n     scanf( %lld , &r[i]); n   } n   for (int i = 0; i < q; ++i) { n     g1[l[i]].push_back(make_pair(r[i], i)); n     g2[r[i]].push_back(make_pair(l[i], i)); n   } n   init(); n   stack<pair<long long, int>> st; n   st.push(make_pair(10000000, 0)); n   for (int i = 1; i < n + 1; ++i) { n     while (!st.empty() && a[i] > st.top().first) { n       st.pop(); n     } n     long long s = st.top().second + 1; n     long long e = i; n     upd(s, e, 1); n     st.push(make_pair(a[i], i)); n     for (int j = 0; j < g2[i].size(); ++j) { n       long long s = g2[i][j].first; n       int id = g2[i][j].second; n       ans[id] += get_sum(s, i); n     } n   } n   init(); n   while (!st.empty()) st.pop(); n   st.push(make_pair(10000000, n + 1)); n   for (int i = n; i > 0; --i) { n     while (!st.empty() && a[i] > st.top().first) { n       st.pop(); n     } n     long long s = i; n     long long e = st.top().second - 1; n     upd(s, e, 1); n     st.push(make_pair(a[i], i)); n     for (int j = 0; j < g1[i].size(); ++j) { n       long long e = g1[i][j].first; n       int id = g1[i][j].second; n       ans[id] += get_sum(i, e); n     } n   } n   for (int i = 0; i < q; ++i) { n     printf( %lld  , ans[i] - (r[i] - l[i] + 1)); n   } n   cout << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 404040; n int cnt, cnt2, cnt3, h, n, m; n struct Node { n   int x, y, w, d, i; n } a[N]; n bool cmp(Node x, Node y) { return x.d < y.d; } n vector<int> s[N]; n vector<pair<int, int> > ss[N]; n int dfn[N], low[N], viss[N], q[N], color[N], as[N]; n map<int, int> sum, vis; n void jiantu(int x, int y) { s[x].push_back(y); } n void tarjan(int x) { n   int c, i, y; n   q[h++] = x, viss[x] = 1; n   dfn[x] = low[x] = ++cnt2; n   c = s[x].size(); n   for (i = 0; i < c; i++) { n     y = s[x][i]; n     if (!dfn[y]) n       tarjan(y), low[x] = min(low[x], low[y]); n     else if (viss[y]) n       low[x] = min(low[x], dfn[y]); n   } n   if (low[x] == dfn[x]) { n     cnt3++; n     while (1) { n       h--; n       color[q[h]] = cnt3; n       viss[q[h]] = 0; n       if (q[h] == x) { n         q[h] = 0; n         break; n       } n       q[h] = 0; n     } n   } n } n int check(int x) { n   int i, ans = 1; n   for (i = x + 1; i <= m; i++) jiantu(i + i, i + i - 1); n   cnt2 = 0, cnt3 = 0; n   memset(dfn, 0, sizeof(dfn)); n   memset(low, 0, sizeof(low)); n   memset(viss, 0, sizeof(viss)); n   memset(color, 0, sizeof(color)); n   for (i = 1; i <= cnt; i++) n     if (!dfn[i]) h = 0, tarjan(i); n   for (i = 1; i <= m; i++) n     if (color[i + i - 1] == color[i + i]) ans = 0; n   for (i = x + 1; i <= m; i++) s[i + i].pop_back(); n   return ans; n } n int erf(int l, int r) { n   while (l <= r) { n     int mid = l + r >> 1; n     if (check(mid)) n       r = mid - 1; n     else n       l = mid + 1; n   } n   return l; n } n void init() { n   int c, i, y, j, pl; n   cnt = m + m; n   for (i = 1; i <= n; i++) { n     c = ss[i].size(); n     for (j = 0; j < c; j++) { n       y = ss[i][j].first; n       pl = ss[i][j].second; n       sum[a[pl].w]++; n       if (sum[a[pl].w] == 3) { n         puts( No ); n         exit(0); n       } else if (sum[a[pl].w] == 2) { n         jiantu(vis[a[pl].w] * 2 - 1, pl + pl); n         jiantu(pl + pl - 1, vis[a[pl].w] * 2); n       } n       vis[a[pl].w] = pl; n     } n     for (j = 0; j < c; j++) sum[a[ss[i][j].second].w]--; n     for (j = 0; j < c; j++) { n       y = ss[i][j].second; n       if (j != c - 1) { n         cnt++; n         if (j != 0) jiantu(cnt, cnt - 1); n         jiantu(cnt, y + y - 1); n       } n       if (j != 0) { n         if (j != c - 1) n           jiantu(y + y, cnt - 1); n         else n           jiantu(y + y, cnt); n       } n     } n     for (j = c - 1; j >= 0; j--) { n       y = ss[i][j].second; n       if (j != 0) { n         cnt++; n         jiantu(cnt, y + y - 1); n         if (j != c - 1) jiantu(cnt, cnt - 1); n       } n       if (j != c - 1) { n         if (j != 0) n           jiantu(y + y, cnt - 1); n         else n           jiantu(y + y, cnt); n       } n     } n   } n } n int main() { n   int i, ans, cnt; n   scanf( %d%d , &n, &m); n   for (i = 1; i <= m; i++) n     scanf( %d%d%d%d , &a[i].x, &a[i].y, &a[i].w, &a[i].d), a[i].i = i; n   sort(a + 1, a + m + 1, cmp); n   for (i = 1; i <= m; i++) n     ss[a[i].x].push_back(make_pair(a[i].y, i)), n         ss[a[i].y].push_back(make_pair(a[i].x, i)); n   init(); n   ans = erf(0, m); n   if (!check(ans)) { n     puts( No ); n     return 0; n   } n   puts( Yes ); n   cnt = 0; n   for (i = 1; i <= m; i++) n     if (color[i + i - 1] > color[i + i]) as[++cnt] = a[i].i; n   printf( %d %d n , a[ans].d, cnt); n   for (i = 1; i <= cnt; i++) printf( %d  , as[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 2 * 100000, maxk = 2 * 100000, inf = 0x3f3f3f3f; n int n, k, s, t; n struct car { n   int c, v; n } a[maxn + 10]; n int d[maxk + 10]; n int ans = inf; n void init() { n   scanf( %d%d%d%d , &n, &k, &s, &t); n   for (int i = 1; i <= n; i++) scanf( %d%d , &a[i].c, &a[i].v); n   for (int i = 1; i <= k; i++) scanf( %d , &d[i]); n   d[k + 1] = s; n } n bool cmp(car x, car y) { return x.v < y.v; } n bool check(int x) { n   double time = 0; n   for (int i = 1; i <= k + 1; i++) { n     double x1, x2; n     int tmp = d[i] - d[i - 1]; n     x1 = (double)(max(0, 2 * tmp - a[x].v)); n     x2 = 2 * (tmp - x1); n     if (x2 < 0) return false; n     time += 2 * x1 + x2 / 2; n     if (time > t) return false; n   } n   return true; n } n void solve() { n   sort(a + 1, a + 1 + n, cmp); n   sort(d + 1, d + 1 + k + 1); n   int l = 1, r = n; n   int mm = 0; n   while (l <= r) { n     int mid = (l + r) >> 1; n     if (check(mid)) n       mm = mid, r = mid - 1; n     else n       l = mid + 1; n   } n   if (mm == 0) n     printf( -1 ); n   else { n     for (int i = mm; i <= n; i++) ans = min(ans, a[i].c); n     printf( %d n , ans); n   } n } n int main() { n   init(); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int sol(const vector<long long>& a, int n, int m, long long t) { n   long long s = 0; n   for (int i = 0; i < m; i++) s += a[i]; n   int ans = 0; n   for (int i = 0; i <= n && s * i <= t; i++) { n     int cnt = (m + 1) * i; n     long long r = t - s * i; n     for (int j = 0; j < m && r >= a[j]; j++) { n       int c = min(r / a[j], (long long)(n - i)); n       r -= a[j] * c; n       cnt += c; n     } n     ans = max(ans, cnt); n   } n   return ans; n } n int main() { n   int n, m; n   long long t; n   scanf( %d%d%lld , &n, &m, &t); n   vector<long long> a(m); n   for (int i = 0; i < m; i++) scanf( %lld , &a[i]); n   sort(a.begin(), a.end()); n   printf( %d n , sol(a, n, m, t)); n } n


#include <bits/stdc++.h> n using namespace std; n const int M = 19, N = (1 << M); n int a[N]; n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int n; n   cin >> n; n   int id = -1; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n     if (a[i] == -1) id = i; n   } n   int rem = n - id - 1; n   int t = 0; n   long long ans = 0; n   while (rem > 0) { n     int mn = n - 1; n     for (int i = n - 1; i >= n / (1 << t) - 1; i--) n       if (a[mn] > a[i]) mn = i; n     ans += a[mn]; n     a[mn] = 1e9 + 10; n     rem -= n / (1 << (t + 1)); n     t++; n     assert(t <= 20); n     cerr << t <<   ****  n ; n   } n   cout << ans <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n int n, t; n int main() { n   cin >> n >> t; n   long long z = pow(10, n - 2); n   if (n == 1 and t == 10) return cout << -1 << endl, 0; n   if (n == 1) return cout << t << endl, 0; n   if (t == 2 or t == 4 or t == 5 or t == 8 or t == 10) n     cout << 40; n   else if (t == 7) n     cout << 14; n   else n     cout << 18; n   n -= 2; n   while (n) { n     cout <<  0 ; n     n--; n   } n   cout << endl; n } n


#include <bits/stdc++.h> n using namespace std; n long long t, n, sum, t1, ans; n string st; n int main() { n   cin >> t; n   while (t--) { n     cin >> n; n     cin >> st; n     int a = 0, b = 0; n     for (int i = 0; i < n; i++) { n       if (st[i] ==  ( ) a++; n       if (st[i] ==  ) ) { n         if (a) n           a--; n         else n           b++; n       } n     } n     cout << min(a, b) <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   cin >> t; n   for (int i = 0; i < t; i++) { n     int n, count = 1; n     cin >> n; n     while (n > 0) { n       if (count % 3 != 0 && count % 10 != 3) { n         count++; n         n--; n       } else { n         count++; n       } n     } n     int ans = count - 1; n     cout << ans << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1 << 23; n const int offset = (int)1e6; n int st_sum[2 * N]; n int st_ma[2 * N]; n int getMax(int a, int b) { n   a += N + offset; n   b += N + offset; n   int ma = -1e9; n   int sum_a = 0; n   int ma_b = 0; n   for (; a < b; a /= 2, b /= 2) { n     if (a % 2 == 1) { n       ma = max(ma, st_ma[a] + sum_a); n       sum_a += st_sum[a]; n       ++a; n     } n     if (b % 2 == 0) { n       ma_b = max(ma_b + st_sum[b], st_ma[b]); n       --b; n     } n   } n   if (a == b) { n     ma = max(ma, st_ma[a] + sum_a); n     sum_a += st_sum[a]; n   } n   ma = max(ma, sum_a + ma_b); n   return ma; n } n void updateSegtreePos(int pos) { n   st_sum[pos] = st_sum[pos * 2] + st_sum[pos * 2 + 1]; n   st_ma[pos] = max(st_ma[pos * 2], st_sum[pos * 2] + st_ma[pos * 2 + 1]); n } n void addValue(int pos, int val) { n   pos += N + offset; n   st_sum[pos] += val; n   st_ma[pos] += val; n   for (pos /= 2; pos; pos /= 2) { n     updateSegtreePos(pos); n   } n } n set<int> pawns[(int)2e5 + 10]; n multiset<int> intercept_ys; n int main() { n   int n, k, m; n   cin >> n >> k >> m; n   for (int i = 0; i < N; ++i) { n     st_sum[i + N] = -1; n     st_ma[i + N] = -1; n   } n   for (int i = N - 1; i; --i) { n     updateSegtreePos(i); n   } n   for (int i = 0; i < m; ++i) { n     int x, y; n     cin >> x >> y; n     int intercept_y = (n - y) - abs(x - k); n     if (pawns[x].count(y)) { n       addValue(intercept_y, -1); n       pawns[x].erase(y); n       intercept_ys.erase(intercept_ys.find(intercept_y)); n     } else { n       addValue(intercept_y, 1); n       pawns[x].insert(y); n       intercept_ys.insert(intercept_y); n     } n     if (intercept_ys.size()) { n       cout << max(0, getMax(*intercept_ys.begin(), n) - *intercept_ys.begin()) n            << endl; n     } else { n       cout << 0 << endl; n     } n   } n } n


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


#include <bits/stdc++.h> n using namespace std; n using ll = int64_t; n using ull = uint64_t; n using ld = long double; n using uint = uint32_t; n const double EPS = 1e-8; n const int INF = 0x3F3F3F3F; n const ll LINF = 4611686018427387903; n const int MOD = 1e9 + 7; n const int mod = 1e6 + 3; n vector<vector<ll>> mat(11, vector<ll>(12)); n ll mpow(ll a, int b) { n   ll res = 1; n   for (; b; b >>= 1, a = a * a % mod) n     if (b & 1) res = res * a % mod; n   return res; n } n signed main() { n   ios::sync_with_stdio(0); n   cin.tie(NULL); n   for (int i = 0; i < 11; i++) { n     cout <<  ?   << i + 1 << endl; n     int w; n     cin >> w; n     for (int j = 0; j <= 10; j++) mat[i][j] = mpow(i + 1, j); n     mat[i][11] = w; n   } n   for (int i = 0; i < 11; i++) { n     for (int j = i; j < 11; j++) { n       if (mat[j][i]) { n         swap(mat[j], mat[i]); n         break; n       } n     } n     for (int j = 0; j < 11; j++) { n       if (j == i || !mat[j][i]) continue; n       ll c = mat[i][i] * mpow(mat[j][i], mod - 2) % mod; n       for (int k = 0; k < 12; k++) mat[j][k] = mat[j][k] * c % mod; n       for (int k = 0; k < 12; k++) n         mat[j][k] = (mat[j][k] - mat[i][k] + mod) % mod; n     } n   } n   vector<ll> xx(11); n   for (int i = 0; i < 11; i++) n     xx[i] = mat[i][11] * mpow(mat[i][i], mod - 2) % mod; n   for (int i = 0; i < mod; i++) { n     ll res = 0; n     for (int j = 0; j < 11; j++) { n       res = (res + xx[j] * mpow(i, j)) % mod; n     } n     if (res == 0) { n       cout <<  !   << i <<   n ; n       return 0; n     } n   } n   cout <<  !   << -1 <<   n ; n } n


#include <bits/stdc++.h> n char chars[200005]; n int main() { n   int n; n   scanf( %d , &n); n   scanf( %s , chars); n   int sum = 0; n   for (int i = 0; i < n; i++) { n     if (chars[i] ==  < ) { n       sum++; n     } else { n       break; n     } n   } n   for (int i = n - 1; i >= 0 && sum < n; i--) { n     if (chars[i] ==  > ) { n       sum++; n     } else { n       break; n     } n   } n   printf( %d n , sum); n } n


#include <bits/stdc++.h> n using namespace std; n int q; n char dirs[100000]; n int l, r, u, d; n int main() { n   cin >> q; n   for (int i = 0; i < q + 1; ++i) { n     char c; n     int ind = 0; n     l = r = u = d = 0; n     while ((c = getchar()) !=   n ) { n       dirs[ind] = c; n       ++ind; n     } n     for (int j = 0; j < ind; ++j) { n       if (dirs[j] ==  L ) n         ++l; n       else if (dirs[j] ==  R ) n         ++r; n       else if (dirs[j] ==  U ) n         ++u; n       else n         ++d; n     } n     int min_lr = (l < r) ? l : r; n     int min_ud = (u < d) ? u : d; n     if (i != 0) { n       if (min_lr == 0 && min_ud != 0) { n         min_ud = 1; n       } n       if (min_ud == 0 && min_lr != 0) { n         min_lr = 1; n       } n       cout << (2 * min_lr + 2 * min_ud) << endl; n       for (int k = 0; k < min_lr; ++k) { n         cout <<  L ; n       } n       for (int k = 0; k < min_ud; ++k) { n         cout <<  U ; n       } n       for (int k = 0; k < min_lr; ++k) { n         cout <<  R ; n       } n       for (int k = 0; k < min_ud; ++k) { n         cout <<  D ; n       } n       cout << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m; n   while (cin >> n >> m) { n     int str[550][550], cnt[550], ans[550]; n     memset(str, 0, sizeof(str)); n     memset(cnt, 0, sizeof(cnt)); n     memset(ans, 0, sizeof(ans)); n     for (int i = 0; i < m; i++) { n       int u, v; n       cin >> u >> v; n       str[u][v] = str[v][u] = 1; n       cnt[u]++; n       cnt[v]++; n     } n     for (int i = 1; i <= n; i++) n       if (cnt[i] == n - 1) ans[i] = 1; n     for (int i = 1; i <= n; i++) n       if (ans[i] == 0) n         for (int j = i + 1; j <= n; j++) n           if (str[i][j] == 0) ans[j] = 2; n     bool flag = 1; n     for (int i = 1; i <= n; i++) { n       for (int j = i + 1; j <= n; j++) { n         if ((abs(ans[i] - ans[j]) == 2 && str[i][j]) || n             (abs(ans[i] - ans[j]) < 2 && !str[i][j])) { n           cout <<  No  << endl; n           flag = false; n           break; n         } n       } n       if (!flag) break; n     } n     if (!flag) continue; n     cout <<  Yes  << endl; n     for (int i = 1; i <= n; i++) printf( %c , ans[i] +  a ); n     cout << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<long long> f(21); n long long fact(long long x) { return f[x]; } n long long solve(long long k) { n   vector<long long> cnt(21), less(21); n   long long d = 1, den = 1, num = 1, den1 = 1, num1 = 0; n   while (k > 0) { n     d += 1; n     cnt[k % d] += 1; n     k /= d; n   } n   less[d + 1] = d - 1; n   den = fact(cnt[0]) * fact(cnt[1]); n   for (long long i = d; i > 1LL; i--) { n     den *= fact(cnt[i]); n     less[i] = less[i + 1] - cnt[i]; n     num *= (less[i] - (i - 2LL)); n     if (num % den == 0) { n       num /= den; n       den = 1; n     } n   } n   if (cnt[0] > 0) { n     num1 = 1; n     cnt[0]--; n     less[d] -= 1; n     den1 = fact(cnt[0]) * fact(cnt[1]); n     for (long long i = d - 1; i > 1; i--) { n       den1 *= fact(cnt[i]); n       less[i] = less[i + 1] - cnt[i]; n       num1 *= (less[i] - (i - 2LL)); n       if (num1 % den1 == 0) { n         num1 /= den1; n         den1 = 1; n       } n     } n   } n   long long res = (num / den) - (num1 / den1) - 1LL; n   return res; n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   f[0] = f[1] = 1; n   for (long long i = 2; i < 21; i++) f[i] = i * f[i - 1]; n   long long t; n   cin >> t; n   while (t--) { n     long long k; n     cin >> k; n     cout << solve(k) <<   n ; n   } n } n


// #pragma GCC optimize( Ofast ) n #pragma GCC target ( sse4 ) n #include <iostream> n #include <cstring> n #include <algorithm> n #include <cmath> n #include <map> n #include <queue> n using namespace std; n  n const int N = 2e5 + 10, M = N * 2, INT = 0x3f3f3f3f, mod = 1e9 + 7; n  n //#define int long long n #define pi 3.1415926 n #define x first n #define y second n typedef long long ll; n typedef pair<int,int> pii; n  //ios::sync_with_stdio(false); n ll gcd(ll a,ll b) {return b ? gcd(b, a % b) : a;} n // int gcd(int a,int b) {return b ? gcd(b, a % b) : a;} n ll qmi(ll a,ll b) {ll res = 1 % mod;while (b){if (b & 1) res = (res * a) % mod;a = a * a % mod;b >>= 1;}return res;} n  n int t, n, m, k; n int x; n deque<int> q1, q2, s1, s2; n int s[M]; n  n int get(deque<int> &a,deque<int> &b) n { n  if (a.size() == 0 || b.size() == 0) return 0; n  s[b.size()] = 0; n  // for (auto x : a) printf( %d  , x); n  //  puts(  ); n  // for (auto x : b) printf( %d  , x); n  //  puts(  ); n  for (int i = b.size() - 1, j = a.size() - 1; i >= 0; i -- ) n  { n   while (a[j] > b[i] && j > 0) j --; n   if (a[j] == b[i]) s[i] = 1; n   else s[i] = 0; n   s[i] += s[i + 1]; n  } n  // for (int i = 0; i < b.size(); i ++ ) printf( %d  , s[i]); n  //  puts(  ); n  int ans = 0; n  for (int i = 0; i < b.size(); i ++ ) n  { n   int p = upper_bound(a.begin(), a.end(), b[i]) - a.begin(); n   int l = lower_bound(b.begin(), b.end(), b[i] - p + 1) - b.begin(); n   ans = max(ans, s[i + 1] + i - l + 1); n   // printf( b_i=%d p = %d  b_i-p=%d l = %d n , b[i], p, b[i] - p + 1, l); n  } n  // cout << ans <<  ------------------------- ; n  return ans; n } n  n void solve() n { n  q1.clear(), q2.clear(), s1.clear(), s2.clear(); n  cin >> n >> m; n  for (int i = 1; i <= n; i ++ ) n  { n   scanf( %d , &x); n   if (x > 0) n   { n    q1.push_back(x); n   } n   else q2.push_front(-x); n  } n  for (int i = 1; i <= m; i ++ ) n  { n   scanf( %d , &x); n   if (x > 0) n   { n    s1.push_back(x); n   } n   else s2.push_front(-x); n  } n  n  int ans = get(q1, s1) + get(q2, s2); n  // puts(  ); n  printf( %d n , ans); n } n  n signed main() n { n     cin >> t;while (t -- )  n     solve(); n }


#include <bits/stdc++.h> n using namespace std; n const int N = 400 + 5; n const int INF = 1e9; n int R, n, m; n pair<int, int> H[N], T[N]; n int vis[N][N]; n vector<pair<int, int> > adj[N][N]; n queue<pair<int, int> > Q; n int dis[N][N]; n int bfs(int h, int t) { n   memset(dis, 0x3c, sizeof dis); n   dis[h][t] = 0; n   Q.push(make_pair(h, t)); n   while (Q.size()) { n     int x = Q.front().first, y = Q.front().second; n     Q.pop(); n     if (x + y == 0) return dis[x][y]; n     for (auto it : adj[x][y]) { n       if (dis[x][y] + 1 < dis[it.first][it.second]) { n         dis[it.first][it.second] = dis[x][y] + 1; n         Q.push(it); n       } n     } n   } n   return INF; n } n bool isCycle(int h, int t) { n   vis[h][t] = 1; n   for (auto it : adj[h][t]) { n     int x = it.first, y = it.second; n     if (vis[x][y] == 1) return 1; n     if (vis[x][y] == 2) continue; n     if (isCycle(x, y)) return 1; n   } n   vis[h][t] = 2; n   return 0; n } n int dp[N][N]; n int fun(int x, int y) { n   int &memo = dp[x][y]; n   if (memo != -1) return memo; n   if (x + y > R) return memo = 0; n   int ans = 0; n   for (auto it : adj[x][y]) { n     ans = max(ans, fun(it.first, it.second)); n   } n   return memo = ans + 1; n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   int h, t; n   cin >> h >> t >> R; n   cin >> n; n   for (int i = 1; i <= n; i++) { n     cin >> H[i].first >> H[i].second; n   } n   cin >> m; n   for (int i = 1; i <= m; i++) { n     cin >> T[i].first >> T[i].second; n   } n   for (int i = 0; i < N; i++) { n     for (int j = 0; j < N; j++) { n       if (i + j == 0) n         ; n       else if (i + j > R) n         ; n       else { n         for (int k = 1; k <= n and k <= i; k++) { n           adj[i][j].push_back(make_pair(i - k + H[k].first, j + H[k].second)); n         } n         for (int k = 1; k <= m and k <= j; k++) { n           adj[i][j].push_back(make_pair(i + T[k].first, j - k + T[k].second)); n         } n       } n     } n   } n   int ans = bfs(h, t); n   if (ans != INF) { n     cout <<  Ivan n ; n     cout << ans <<   n ; n     exit(0); n   } n   if (isCycle(h, t)) { n     cout <<  Draw n ; n     exit(0); n   } n   memset(dp, -1, sizeof dp); n   cout <<  Zmey n ; n   cout << fun(h, t) <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T, class V> n ostream &operator<<(ostream &s, pair<T, V> a) { n   s << a.first <<     << a.second; n   return s; n } n struct NTT { n   long long int MD, M = 1, R; n   vector<int> r; n   vector<long long int> w[2]; n   long long int bigmod(long long int a, long long int p, long long int m) { n     long long int res = 1, x = a; n     while (p) { n       if (p & 1) res = (res * x) % m; n       x = (x * x) % m; n       p >>= 1; n     } n     return res; n   } n   long long int primitive_root(int n) { n     int p = n - 1; n     vector<int> d; n     for (int i = 2; i * i <= p; i++) { n       if (p % i == 0) { n         d.push_back(i); n         while (p % i == 0) p /= i; n       } n     } n     if (p > 1) d.push_back(p); n     for (int i = 2; i <= n; i++) { n       bool ok = true; n       for (auto x : d) ok &= (bigmod(i, (n - 1) / x, n) != 1); n       if (ok) return i; n     } n     assert(false); n   } n   NTT(long long int n, long long int _MD) : MD(_MD) { n     int u = 0; n     while (M < n) M <<= 1, u++; n     r.resize(M); n     w[0].resize(M, 1); n     w[1].resize(M, 1); n     R = 3; n     w[0][1] = bigmod(R, (MD - 1) / M, MD); n     w[1][1] = bigmod(w[0][1], MD - 2, MD); n     for (int i = 1; i < M; i++) { n       int l = __builtin_ctz(i); n       r[i] = r[i ^ (1 << l)] | (1 << (u - l - 1)); n       w[0][i] = w[0][i - 1] * w[0][1] % MD; n       w[1][i] = w[1][i - 1] * w[1][1] % MD; n     } n   } n   void fft(vector<long long int> &a, bool inv = false) { n     for (int i = 0; i < M; i++) n       if (i < r[i]) swap(a[i], a[r[i]]); n     for (int len = 2; len <= M; len <<= 1) { n       for (int i = 0, inc = M / len; i < M; i += len) { n         for (int j = 0, l = 0; j < (len >> 1); j++, l += inc) { n           long long int u = a[i + j], n                         v = a[i + j + (len >> 1)] * w[inv][l] % MD; n           a[i + j] = (u + v >= MD ? u + v - MD : u + v); n           a[i + j + (len >> 1)] = (u < v ? u - v + MD : u - v); n         } n       } n     } n     if (inv) { n       long long int r = bigmod(M, MD - 2, MD); n       for (auto &x : a) x = x * r % MD; n     } n   } n   vector<long long int> multiply(vector<long long int> &a, n                                  vector<long long int> &b) { n     vector<long long int> v1(M), v2(M); n     for (int i = 0; i < a.size(); i++) v1[i] = a[i]; n     for (int i = 0; i < b.size(); i++) v2[i] = b[i]; n     fft(v1); n     fft(v2); n     for (int i = 0; i < M; i++) v1[i] = v1[i] * v2[i] % MD; n     fft(v1, 1); n     return v1; n   } n   vector<long long int> POWER(vector<long long int> &a, long long int n) { n     vector<long long int> v1(M); n     for (int i = 0; i < a.size(); i++) v1[i] = a[i]; n     fft(v1); n     for (int i = 0; i < M; i++) v1[i] = bigmod(v1[i], n, MD); n     fft(v1, 1); n     return v1; n   } n }; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(NULL); n   int T = 1; n   for (int qq = 1; qq <= T; qq++) { n     int n, k; n     cin >> n >> k; n     vector<long long int> v(10); n     while (k--) { n       long long int x; n       cin >> x; n       v[x] = 1; n     } n     long long int u = n / 2; n     NTT nt(1 << 20, (998244353)); n     v = nt.POWER(v, u); n     long long int a = 0; n     for (int i = 0; i < v.size(); i++) a = (v[i] * v[i] + a) % (998244353); n     cout << a << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int a, b, c; n   bool o00, o01, o10, o11; n   a = b = c = 0; n   string s; n   cin >> s; n   string::iterator its; n   its = s.begin(); n   for (; its != s.end(); ++its) { n     if (*its ==  1 ) n       ++a; n     else if (*its ==  0 ) n       ++b; n     else if (*its ==  ? ) n       ++c; n   } n   o00 = (a < b + c); n   o11 = (a + c > b + 1); n   --its; n   o01 = o10 = false; n   int x1, x2; n   x1 = (b + c - a + (a + b + c) % 2) / 2; n   x2 = c - x1; n   if (x1 >= 0 && x1 <= c) { n     if (*its ==  0  || (*its ==  ?  && x2)) o10 = true; n     if (*its ==  1  || (*its ==  ?  && x1)) o01 = true; n   } n   if (o00) cout <<  00 n ; n   if (o01) cout <<  01 n ; n   if (o10) cout <<  10 n ; n   if (o11) cout <<  11 n ; n   return 0; n } n


#include <bits/stdc++.h> n const int maxn = 10000050; n using namespace std; n char a[1005][6]; n void solve() { n   memset(a, 0, sizeof(a)); n   int n; n   cin >> n; n   for (int i = 0; i < n; i++) cin >> a[i]; n   int flag = 0; n   for (int i = 0; i < n; i++) { n     if (a[i][0] ==  O  && a[i][1] ==  O ) { n       a[i][0] =  + , a[i][1] =  + ; n       flag = 1; n       break; n     } n     if (a[i][3] ==  O  && a[i][4] ==  O ) { n       a[i][3] =  + , a[i][4] =  + ; n       flag = 1; n       break; n     } n   } n   if (flag) { n     cout <<  YES  << endl; n     for (int i = 0; i < n; i++) cout << a[i] << endl; n   } else n     cout <<  NO  << endl; n } n int main() { solve(); } n


#include <bits/stdc++.h> n using namespace std; n long long Rev[35], C[35][35]; n long long powmod(long long x, long long y = 998244353 - 2, n                  long long p = 998244353) { n   long long ans = 1; n   while (y) { n     if (y & 1) ans = ans * x % 998244353; n     x = x * x % 998244353; n     y >>= 1; n   } n   return ans; n } n struct Poly { n   long long X[35], L, R; n   Poly() { memset(X, 0, sizeof X); } n   Poly(long long _1) { n     memset(X, 0, sizeof X); n     X[0] = _1; n   } n   long long getval(long long x) { n     long long ans = 0; n     for (long long nw = 1, i = 0; i < 35; i++, nw = nw * x % 998244353) n       ans = (ans + nw * X[i]) % 998244353; n     return ans; n   } n   Poly minus(long long x) { n     Poly Ans; n     for (long long i = 0; i < 35; i++) n       for (long long j = 0, s = 1; j <= i; n            j++, s = s * (998244353 - x) % 998244353) n         Ans.X[i - j] = n             (Ans.X[i - j] + X[i] * C[i][j] % 998244353 * s) % 998244353; n     return Ans; n   } n   Poly intg() { n     Poly Ans; n     for (long long i = 1; i < 35; i++) Ans.X[i] = X[i - 1] * Rev[i] % 998244353; n     Ans.X[0] = 0; n     return Ans; n   } n   Poly operator+(const Poly& A) { n     Poly Ans; n     for (long long i = 0; i < 35; i++) Ans.X[i] = (X[i] + A.X[i]) % 998244353; n     return Ans; n   } n   Poly operator-(const Poly& A) { n     Poly Ans; n     for (long long i = 0; i < 35; i++) Ans.X[i] = (X[i] - A.X[i]) % 998244353; n     return Ans; n   } n   void operator/=(const long long& x) { n     long long tmp = powmod(x); n     for (long long i = 0; i < 35; i++) X[i] = X[i] * tmp % 998244353; n   } n }; n long long n, K[33]; n vector<Poly> S[33]; n int main() { n   for (long long i = 1; i < 35; i++) Rev[i] = powmod(i); n   for (long long i = 0; i < 35; i++) n     for (long long j = 0; j <= i; j++) n       C[i][j] = !j ? 1 : (C[i - 1][j - 1] + C[i - 1][j]) % 998244353; n   scanf( %lld , &n); n   for (long long i = 1; i <= n; i++) { n     double x; n     scanf( %lf , &x); n     K[i] = (long long)(x * 1e6 + 0.5); n   } n   S[1].resize(3); n   S[1][0].L = -1000000; n   S[1][0].R = 0; n   S[1][1].L = 0; n   S[1][1].R = min(K[1], 1000000ll); n   S[1][1].X[0] = powmod(1000000); n   S[1][2].L = min(K[1], 1000000ll); n   S[1][2].R = 1e18; n   for (long long i = 2; i <= n; i++) { n     long long l = 0, r = 1, nw = -1000000; n     S[i].resize(1); n     S[i][0].L = -1000000; n     S[i][0].R = 0; n     K[i] = min(K[i - 1] + 1000000, K[i]); n     while (l < S[i - 1].size()) { n       long long mn = min(S[i - 1][l].R - nw, S[i - 1][r].R - nw - 1000000); n       if (nw + mn + 1000000 >= K[i]) mn = K[i] - nw - 1000000; n       long long x = nw + 1000000; n       Poly X; n       X = X + Poly(S[i - 1][l].intg().getval(S[i - 1][l].R)) - n           S[i - 1][l].intg().minus(1000000); n       X = X + S[i - 1][r].intg().minus(0) - n           Poly(S[i - 1][r].intg().getval(S[i - 1][r].L)); n       for (long long j = l + 1; j < r; j++) n         X = X + Poly(S[i - 1][j].intg().getval(S[i - 1][j].R) - n                      S[i - 1][j].intg().getval(S[i - 1][j].L)); n       X.L = x; n       X.R = x + mn; n       if (S[i - 1][l].R == mn + x - 1000000) l++; n       if (S[i - 1][r].R == mn + x) r++; n       X /= 1000000; n       S[i].push_back(X); n       if (mn + x == K[i]) break; n       nw = mn + nw; n     } n     Poly X; n     X.L = K[i]; n     X.R = 1e18; n     S[i].push_back(X); n   } n   long long ans = 0; n   for (long long i = 1; i + 1 < S[n].size(); i++) n     ans = (ans + S[n][i].intg().getval(S[n][i].R) - n            S[n][i].intg().getval(S[n][i].L)) % n           998244353; n   printf( %lld n , (ans % 998244353 + 998244353) % 998244353); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool isIntersect(int x1, int y1, int x2, int y2, int x3, int y3, int x4, n                  int y4) { n   double t1 = (y3 - y4) * (x1 - x3) + (x4 - x3) * (y1 - y3); n   double t2 = (x4 - x3) * (y1 - y2) - (x1 - x2) * (y4 - y3); n   double r1 = t1 / t2; n   double f1 = (y1 - y2) * (x1 - x3) + (x2 - x1) * (y1 - y3); n   double f2 = (x4 - x3) * (y1 - y2) - (x1 - x2) * (y4 - y3); n   double r2 = f1 / f2; n   if (r1 >= 0 && r1 <= 1 && r2 >= 0 && r2 <= 1) { n     return true; n   } n   return false; n } n double isInside(int x0, int y0, int x1, int y1, int x2, int y2) { n   double num = (y2 - y1) * x0 - (x2 - x1) * y0 + x2 * y1 - y2 * x1; n   num = abs(num); n   double den = sqrt(pow(y2 - y1, 2) + pow(x2 - x1, 2)); n   return num / den; n } n int main() { n   int first[4][2]; n   int second[4][2]; n   int minX = 200; n   int maxY = -200; n   int minY = 200; n   int maxX = -200; n   int min1X = 200; n   int max1X = -200; n   int min2Y = 200; n   int max2Y = -200; n   for (int i = 0; i < 4; i++) { n     for (int j = 0; j < 2; j++) { n       cin >> first[i][j]; n       if (j == 0) { n         minX = min(minX, first[i][j]); n         maxX = max(maxX, first[i][j]); n       } else { n         minY = min(minY, first[i][j]); n         maxY = max(maxY, first[i][j]); n       } n     } n   } n   for (int i = 0; i < 4; i++) { n     for (int j = 0; j < 2; j++) { n       cin >> second[i][j]; n       if (j == 0) { n         min1X = min(min1X, second[i][j]); n         max1X = max(max1X, second[i][j]); n       } else { n         min2Y = min(min2Y, second[i][j]); n         max2Y = max(max2Y, second[i][j]); n       } n     } n   } n   for (int i = 0; i < 4; i++) { n     if (second[i][0] >= minX && second[i][0] <= maxX && second[i][1] >= minY && n         second[i][1] <= maxY) { n       cout <<  YES ; n       return 0; n     } n     if (isInside(first[i][0], first[i][1], second[0][0], second[0][1], n                  second[2][0], second[2][1]) + n             isInside(first[i][0], first[i][1], second[1][0], second[1][1], n                      second[3][0], second[3][1]) <= n         (max2Y - min2Y) / 2) { n       cout <<  YES ; n       return 0; n     } n   } n   for (int i = 0; i < 4; i++) { n     int j = (i + 1) % 4; n     for (int ii = 0; ii < 4; ii++) { n       int jj = (ii + 1) % 4; n       if (isIntersect(first[i][0], first[i][1], first[j][0], first[j][1], n                       second[ii][0], second[ii][1], second[jj][0], n                       second[jj][1])) { n         cout <<  YES ; n         return 0; n       } n     } n   } n   cout <<  NO ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int NMAX = 1e5; n int n, x, k; n int a[NMAX + 2]; n long long ans; n int ndiv(int f, int l) { return l / x - (f - 1) / x; } n pair<int, int> bs(int arg) { n   pair<int, int> last; n   int st = arg, dr = n; n   last.first = last.second = -1; n   while (st <= dr) { n     int med = (st + dr) / 2; n     if (ndiv(a[arg], a[med]) >= k) { n       dr = med - 1; n       last.first = med; n     } else n       st = med + 1; n   } n   st = arg, dr = n; n   while (st <= dr) { n     int med = (st + dr) / 2; n     if (ndiv(a[arg], a[med]) > k) n       dr = med - 1; n     else { n       st = med + 1; n       last.second = med; n     } n   } n   return last; n } n int main() { n   cin >> n >> x >> k; n   for (int i = 1; i <= n; i++) cin >> a[i]; n   sort(a + 1, a + n + 1); n   int nr; n   for (int i = 1; i <= n; i++) { n     if (a[i] != a[i - 1]) { n       pair<int, int> pos = bs(i); n       if (pos.first != -1 && pos.second != -1) n         nr = pos.second - pos.first + 1; n       else n         nr = 0; n     } n     ans += 1LL * nr; n   } n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, a[500010], x, sz; n long long ans; n int main() { n   scanf( %d , &n); n   for (int step = 1; step <= n; step++) { n     scanf( %d , &x); n     while (a[sz - 1] >= a[sz] && a[sz] <= x && sz >= 2) { n       ans += min(a[sz - 1], x); n       sz--; n     } n     a[++sz] = x; n   } n   sort(a + 1, a + sz + 1); n   for (int i = 1; i <= sz - 2; i++) ans += a[i]; n   printf( %I64d , ans); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, x, a, b, in[100], on[100], i = 0, r, y; n   cin >> n >> x; n   int t = n; n   while (t--) { n     cin >> a >> b; n     r = min(a, b); n     y = max(a, b); n     in[i] = r; n     on[i] = y; n     i++; n   } n   sort(in, in + n); n   sort(on, on + n); n   if (in[n - 1] < on[0]) { n     if (x <= in[n - 1]) n       cout << in[n - 1] - x; n     else if (x >= on[0]) n       cout << x - on[0]; n     else if (x > in[n - 1] && x < on[0]) n       cout << 0; n   } else if (in[n - 1] == on[0]) n     cout << abs(x - on[0]); n   else n     cout << -1; n } n


#include<bits/stdc++.h> n using namespace std; n void __print(int x) {cerr << x;} n void __print(long x) {cerr << x;} n void __print(long long x) {cerr << x;} n void __print(unsigned x) {cerr << x;} n void __print(unsigned long x) {cerr << x;} n void __print(unsigned long long x) {cerr << x;} n void __print(float x) {cerr << x;} n void __print(double x) {cerr << x;} n void __print(long double x) {cerr << x;} n void __print(char x) {cerr <<      << x <<     ;} n void __print(const char *x) {cerr <<     << x <<    ;} n void __print(const string &x) {cerr <<     << x <<    ;} n void __print(bool x) {cerr << (x ?  true  :  false );} n   n template<typename T, typename V> n void __print(const pair<T, V> &x) {cerr <<  { ; __print(x.first); cerr <<  , ; __print(x.second); cerr <<  } ;} n template<typename T> n void __print(const T &x) {int f = 0; cerr <<  { ; for (auto &i: x) cerr << (f++ ?  ,  :   ), __print(i); cerr <<  } ;} n void _print() {cerr <<  ] n ;} n template <typename T, typename... V> n void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr <<  ,  ; _print(v...);} n #ifndef ONLINE_JUDGE n #define debug(x...) cerr <<  [  << #x <<  ] = [ ; _print(x) n #else n #define debug(x...) n #endif n   n #define ll long long n #define f first n #define s second n #define Fast ios_base::sync_with_stdio(false);cin.tie(NULL); n typedef pair<ll , pair<ll, ll> > pi; n int pow(int x,int y){ n     int res=1; n     while(y){ n         if(y&1) res*=x; n         y>>=1; n         x*=x; n     } n     return res; n }    n struct Compare { n     constexpr bool operator()(pi const & a, n                               pi const & b) const noexcept n     { return a.first < b.first || (a.first == b.first && a.second.first > b.second.first); } n   n }; n void prefix_function( string s,ll arr[] ) n { n      long long border=0; arr[0]=0; n     for(long long i=1;i<s.size();i++) n     { n       while(border>0 && s[i]!=s[border]) n         border=arr[border-1]; n       n      if(s[i]==s[border]) n          border++; n       else n        border=0; n        n       arr[i]=border; n     } n }//send mod-2 for a^-1 if mod is a prime number n   n ll mod=998244353; n ll add( ll a , ll b) n { n     return (((a%mod)+(b%mod))%mod); n } n ll mul(ll a,ll b) n { n   return (((a%mod)*(b%mod))%mod); n } n ll binpow(ll a, ll b) { n     ll res = 1; n     while (b) { n         if (b & 1) res = mul(res, a); n         a = mul(a, a); n         b >>= 1; n     } n     return res; n } n ll subs(ll a,ll b) n { n     return (((a%mod)-(b%mod)+mod)%mod); n } n ll dv(ll a,ll b) n { n     ll inv=binpow(b,mod-2); n     return mul(a,inv); n } n   n ll dsu_arr[100000]; n ll dsu_sz[100000]; n void dsu(ll n) n { n     for(ll i=0;i<=n;i++) n     { n         dsu_arr[i]=i; n         dsu_sz[i]=1; n     } n } n ll find(ll x) n { n      ll root=x; n     while (root!=dsu_arr[root]) n     { n         root=dsu_arr[root]; n     } n     while(x!=dsu_arr[x]) n     { n         dsu_arr[x]=root; n         x=dsu_arr[x]; n     } n     return root; n } n ll merge(ll x,ll y) n { n     ll root1=find(x); n     ll root2=find(y); n      n     if(root1==root2) n     return 0ll; n   n     if(dsu_sz[x]>dsu_sz[y]){ n     dsu_arr[root2]=root1; n     dsu_sz[root1]+=dsu_sz[root2]; n     } n     else n     { n          dsu_sz[root2]+=dsu_sz[root1]; n         dsu_arr[root1]=root2; n     } n     return 1ll; n } n /* n vector<ll>adj[100005]; n bool vis[100005]; n ll dist[100005]; n void bfs(ll c) n { n   vis[c]=true; n   dist[c]=0; n   queue<ll>q; n   q.push(c); n while(!q.empty()) n { n     ll x=q.front(); n     q.pop(); n     n     for(ll i=0;i<adj[x].size();i++) n     { n         ll y=adj[x][i]; n         if(!vis[y]) n         { n             vis[y]=true; n             dist[y]=dist[x]+1; n              n             q.push(y); n         } n     } n   n } n } n */ n   n int main() n { n     Fast n  ll test; n  cin>>test; n  while(test--) n  { n      string s; n      cin>>s; n      map<char,ll>cnt; n      for(char a= a ;a<= z ;a++) n      { n          cnt[a]=-1; n      } n      for(ll i=0;i<s.size();i++) n      { n          cnt[s[i]]=max(cnt[s[i]],i+1); n      } n      for(char a= a ;a<= z ;a++) n      { n         if(cnt[a]==-1) n         { n             cnt[a]=1000000000; n         } n      } n      stack<char>ans; n      map<char,bool>taken; n      for(ll i=0;i<s.size();i++) n      { n          char x=s[i]; n          ll r=i+1; n          if(taken[s[i]]) n          continue; n          bool hbe=true; n          n            while(!ans.empty()) n            { n                ll u=ans.top(); n                 n                if(u<x && cnt[u]>r){ n                    taken[u]=false; n                ans.pop(); n                } n                else n                break; n            } n            ans.push(x); n            taken[x]=true; n           n           n        n         // cout<<ans.size()<<   <<ans.top()<<endl; n      } n      string sura; n      while (!ans.empty()) n      { n          sura+=ans.top(); n           ans.pop(); n      } n      for(ll i=sura.size()-1;i>=0;i--) n      { n          cout<<sura[i]; n      } n      cout<<  n ; n   n  } n   n   n } n


#include <bits/stdc++.h> n struct Mat { n   double a[253][253]; n } A[53]; n int Sta[25][25], d[25], n, m, a, b, tot; n double p[25], tp[253][253]; n std::vector<int> v[25]; n void sq(int x, int y) { n   register int i, ii, iii; n   for (i = 0; i < tot; i++) n     for (ii = 0; ii < tot; ii++) n       for (iii = 0; iii < tot; iii++) n         tp[i][iii] += A[y].a[i][ii] * A[y].a[ii][iii]; n   for (i = 0; i < tot; i++) n     for (ii = 0; ii < tot; ii++) A[x].a[i][ii] = tp[i][ii], tp[i][ii] = 0; n } n int main() { n   scanf( %d%d%d%d , &n, &m, &a, &b); n   register int i, ii; n   for (i = 1; i <= n; i++) n     for (ii = i; ii <= n; ii++) Sta[i][ii] = Sta[ii][i] = tot++; n   for (i = 1; i <= m; i++) { n     int x, y; n     scanf( %d%d , &x, &y), d[x]++, d[y]++; n     v[x].push_back(y), v[y].push_back(x); n   } n   for (i = 1; i <= n; i++) n     scanf( %lf , p + i), A[0].a[Sta[i][i]][Sta[i][i]] = 1; n   for (i = 1; i <= n; i++) n     for (ii = i + 1; ii <= n; ii++) { n       int Id1 = Sta[i][ii], Id2 = Id1; n       double P = p[i], Q = p[ii] * P; n       A[0].a[Id1][Id2] += Q; n       for (int u : v[ii]) { n         Q = (1 - p[ii]) / d[ii] * P, Id2 = Sta[i][u], A[0].a[Id1][Id2] += Q; n       } n       for (int t : v[i]) { n         P = (1 - p[i]) / d[i], Q = p[ii] * P, Id2 = Sta[t][ii], n         A[0].a[Id1][Id2] += Q; n         for (int u : v[ii]) { n           Q = (1 - p[ii]) / d[ii] * P, Id2 = Sta[t][u], A[0].a[Id1][Id2] += Q; n         } n       } n     } n   for (i = 1; i <= 50; i++) sq(i, i - 1); n   for (i = 1; i <= n; i++) printf( %.12lf  , A[50].a[Sta[a][b]][Sta[i][i]]); n   puts(  ); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int m, n, k, i, j, t, x; n   int c[200]; n   cin >> n; n   int a[n]; n   for (i = 0; i < n; i++) { n     cin >> a[i]; n     c[i] = a[i]; n   } n   cin >> m; n   int b[m]; n   for (j = 0; j < m; j++) { n     cin >> b[j]; n     c[i + j] = b[j]; n   } n   x = m + n; n   for (i = 0; i < n; i++) { n     for (j = 0; j < m; j++) { n       t = 0; n       for (k = 0; k < x; k++) { n         if (a[i] + b[j] == c[k]) { n           t = 1; n           break; n         } n       } n       if (t == 0) { n         cout << a[i] <<     << b[j] << endl; n         goto here; n       } n     } n   } n here: n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct point { n   double x, y; n   point(double x, double y) : x(x), y(y) {} n   point() {} n   inline void read() { scanf( %lf%lf , &x, &y); } n   inline double len() const { return sqrt(x * x + y * y); } n   inline double len2() const { return x * x + y * y; } n   inline point rot() { return point(-y, x); } n }; n inline int sgn(double a) { n   if (a > 1e-7) n     return 1; n   else if (a < -1e-7) n     return -1; n   return 0; n } n inline point operator-(const point &a, const point &b) { n   return point(a.x - b.x, a.y - b.y); n } n inline point operator+(const point &a, const point &b) { n   return point(a.x + b.x, a.y + b.y); n } n inline point operator*(const point &a, double b) { n   return point(b * a.x, b * a.y); n } n inline point operator*(double b, const point &a) { n   return point(b * a.x, b * a.y); n } n inline double operator*(const point &a, const point &b) { n   return a.x * b.x + a.y * b.y; n } n inline double operator%(const point &a, const point &b) { n   return a.x * b.y - a.y * b.x; n } n inline bool operator==(const point &a, const point &b) { n   return sgn(a.x - b.x) == 0 && sgn(a.y - b.y) == 0; n } n inline bool operator!=(const point &a, const point &b) { return !(a == b); } n inline double dist(const point &a, const point &b) { return (a - b).len(); } n struct line { n   point a, b, v; n   line() {} n   line(const point &a, const point &b) : a(a), b(b), v(b - a) {} n }; n double sqr(double a) { return a * a; } n inline double dist(const point &a, const line &b) { n   return abs((a - b.a) % b.v) / b.v.len(); n } n point operator*(const line &a, const line &b) { n   return b.a + (((a.a - b.a) % a.v) / (b.v % a.v)) * b.v; n } n bool operator*(const point &a, const line &b) { n   return ((a - b.a) * b.v) * ((a - b.b) * b.v) < -1e-7; n } n bool Solve(point a, point b, point c) { n   if (a == b || b == c || c == a) return false; n   if (sgn((a - b) % (c - b)) == 0) return false; n   line l0((a + b) * 0.5, (a + b) * 0.5 + (b - a).rot()), n       l1(1.5 * b - 0.5 * c, 1.5 * b - 0.5 * c + (c - b).rot()); n   point p[4]; n   p[0] = l0 * l1; n   p[1] = 2 * b - p[0]; n   p[3] = 2 * a - p[0]; n   p[2] = 2 * c - p[1]; n   if (sgn((p[1] - p[0]) % (p[2] - p[1])) == 1) reverse(p, p + 4); n   for (int i = 0; i < 4; i++) { n     if (sgn((p[(i + 1) % 4] - p[i]) % (p[(i + 2) % 4] - p[(i + 1) % 4])) >= 0) n       return false; n   } n   printf( YES n ); n   for (int i = 0; i < 4; i++) printf( %.9lf %.9lf  , p[i].x, p[i].y); n   printf(  n ); n   return true; n } n int main() { n   int T; n   scanf( %d , &T); n   while (T--) { n     point a, b, c; n     a.read(), b.read(), c.read(); n     if (Solve(a, b, c)) continue; n     if (Solve(a, c, b)) continue; n     if (Solve(b, a, c)) continue; n     if (Solve(b, c, a)) continue; n     if (Solve(c, a, b)) continue; n     if (Solve(c, b, a)) continue; n     printf( NO n n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 1e5 + 5; n int n, m, h, t, u, v, src[MAXN], dst[MAXN], num[MAXN], used[MAXN]; n vector<int> g[MAXN]; n void out(vector<int> &v) { n   for (int i = 0; i < v.size(); ++i) { n     cout << v[i] <<    n [i == v.size() - 1]; n   } n } n bool check(int u, int v, int ver) { n   int cnt = 0; n   num[u] = num[v] = -1; n   for (int i = 0; i < g[u].size() && i < h + t; ++i) { n     int w = g[u][i]; n     if (w == v) continue; n     used[w] = ver; n     num[w] = 1; n     ++cnt; n   } n   for (int i = 0; i < g[v].size() && i < h + t; ++i) { n     int w = g[v][i]; n     if (w == u) continue; n     if (used[w] == ver) { n       num[w] = 2; n       continue; n     } n     used[w] = ver; n     num[w] = 1; n     ++cnt; n   } n   int degu = g[u].size() - 1, degv = g[v].size() - 1; n   if (h >= t != degu >= degv) swap(degu, degv); n   return degu >= h && degv >= t && cnt >= h + t; n } n void solve() { n   for (int mm = 0; mm < m; ++mm) { n     if (check(src[mm], dst[mm], mm + 1)) { n       cout <<  YES n ; n       u = src[mm], v = dst[mm]; n       if (h >= t != g[u].size() >= g[v].size()) swap(u, v); n       cout << u <<     << v << endl; n       vector<int> ans; n       for (int i = 0; i < g[u].size() && ans.size() < h; ++i) { n         int v = g[u][i]; n         if (num[v] == 1) { n           num[v] == -1; n           ans.push_back(v); n         } n       } n       for (int i = 0; i < g[u].size() && ans.size() < h; ++i) { n         int v = g[u][i]; n         if (num[v] > 1) { n           ans.push_back(v); n           num[v] = -1; n         } n       } n       out(ans); n       ans.clear(); n       swap(u, v); n       for (int i = 0; i < g[u].size() && ans.size() < t; ++i) { n         int v = g[u][i]; n         if (num[v] != -1) ans.push_back(v); n       } n       out(ans); n       return; n     } n   } n   cout <<  NO n ; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout << setprecision(6) << fixed; n   clog.copyfmt(cout); n   cin >> n >> m >> h >> t; n   for (int i = 0; i < m; ++i) { n     cin >> u >> v; n     src[i] = u, dst[i] = v; n     g[u].push_back(v); n     g[v].push_back(u); n   } n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long double eps = 1e-13; n const long double PI = acos(-1); n const int INF = (int)1e9; n const long long INFF = (long long)1e18; n const int mod = (int)1e9 + 7; n const int MXN = (int)2e5 + 7; n char s[MXN]; n int cnt[MXN]; n int num[MXN], num2[MXN], a[MXN]; n bool check() { n   for (int i = 0; i < 1 << 6; i++) num2[i] = num[i]; n   for (int i = 0; i < 6; i++) { n     for (int j = 0; j < 1 << 6; j++) { n       if (j & (1 << i)) num2[j] += num2[j ^ (1 << i)]; n     } n   } n   for (int i = 0; i < 1 << 6; i++) { n     int sum = 0; n     for (int j = 0; j < 6; j++) n       if (i & (1 << j)) sum += cnt[j]; n     if (sum < num2[i]) return false; n   } n   return true; n } n char ans[MXN]; n int main() { n   scanf( %s , s + 1); n   int l = strlen(s + 1); n   for (int i = 1; s[i]; i++) { n     cnt[s[i] -  a ]++; n     a[i] = (1 << 6) - 1; n   } n   int m; n   scanf( %d , &m); n   while (m--) { n     int p; n     scanf( %d %s , &p, s + 1); n     a[p] = 0; n     for (int i = 1; s[i]; i++) a[p] ^= (1 << (s[i] -  a )); n   } n   for (int i = 1; i <= l; i++) { n     num[a[i]]++; n   } n   for (int i = 1; i <= l; i++) { n     num[a[i]]--; n     for (int j = 0; j < 6; j++) { n       if (!cnt[j] || !(a[i] & (1 << j))) continue; n       cnt[j]--; n       if (check()) { n         ans[i] = j +  a ; n         break; n       } else { n         cnt[j]++; n       } n     } n     if (!ans[i]) { n       puts( Impossible ); n       return 0; n     } n   } n   printf( %s n , ans + 1); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, t = 1, i; n   cin >> n; n   int a[n]; n   for (i = 0; i < n; i++) { n     cin >> a[i]; n   } n   sort(a, a + n); n   for (i = 0; i < n - 1; i++) { n     if (a[i + 1] == a[i]) { n       t++; n     } else if (t > (n + 1) / 2) { n       cout <<  NO ; n       return 0; n     } else n       t = 1; n   } n   if (t > ((n + 1) / 2)) n     cout <<  NO ; n   else n     cout <<  YES ; 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     int arr[n]; n     for (int i = 0; i < n; i++) { n       cin >> arr[i]; n     } n     int res[101] = {0}; n     for (int i = 0; i < n; i++) { n       res[arr[i]]++; n     } n     int cnt[101] = {0}; n     for (int i = 0; i < 101; i++) { n       if (res[i] >= 1) { n         res[i]--; n         cnt[i]++; n       } n     } n     int f, s; n     for (int i = 0; i < 101; i++) { n       if (res[i] == 0) { n         f = i; n         break; n       } n     } n     for (int i = 0; i < 101; i++) { n       if (cnt[i] == 0) { n         s = i; n         break; n       } n     } n     cout << f + s <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int K, P, cd; n int cal(int ct, vector<pair<int, int> > vt) { n   int t = vt.size(), res = 0; n   for (int st = 1; st < (1 << t); st++) { n     int val = 1, sl = 0; n     for (int j = 0; j < t; j++) { n       if ((st >> j) % 2 == 1) val *= vt[j].first, sl++; n     } n     if (sl % 2 == 0) n       res -= ct / val; n     else n       res += ct / val; n   } n   return ct - res; n } n void solve() { n   vector<pair<int, int> > vt; n   int x = P; n   for (int i = 2; i * i <= P; i++) { n     if (x % i == 0) { n       int t = 0; n       while (x % i == 0) t++, x /= i; n       vt.push_back(pair<int, int>(i, t)); n     } n   } n   if (x > 1) vt.push_back(pair<int, int>(x, 1)); n   int t = vt.size(); n   int res0 = cal(cd, vt), r = 10000000, l = cd; n   int ans; n   while (1) { n     int mid = (l + r) / 2; n     int v = cal(mid, vt) - res0; n     if (v == K) { n       ans = mid; n       break; n     } n     if (v > K) { n       r = mid - 1; n     } else n       l = mid + 1; n   } n   while (1) { n     int ok = 1; n     for (int j = 0; j < vt.size(); j++) { n       if (ans % vt[j].first == 0) { n         ok = 0; n         break; n       } n     } n     if (ok) n       break; n     else n       ans--; n   } n   cout << ans << endl; n } n int main() { n   int T; n   cin >> T; n   for (int i = 0; i < T; i++) { n     cin >> cd >> P >> K; n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = (int)1e5 * 2 + 7; n int a[maxn], b[maxn], t[4 * maxn], n, W, H; n void build(int v, int l, int r) { n   if (r - l == 1) { n     t[v] = a[l]; n     return; n   } n   build(2 * v + 1, l, (l + r) / 2); n   build(2 * v + 2, (l + r) / 2, r); n   t[v] = max(t[2 * v + 1], t[2 * v + 2]); n } n int get(int v, int l, int r, int ql, int qr) { n   if (ql <= l && qr >= r) return t[v]; n   if (ql >= r || qr <= l) return 0; n   return max(get(2 * v + 1, l, (l + r) / 2, ql, qr), n              get(2 * v + 2, (l + r) / 2, r, ql, qr)); n } n void upd(int v, int l, int r, int pos, int x) { n   if (r - l == 1) { n     t[v] = x; n     return; n   } n   if (pos < (l + r) / 2) { n     upd(2 * v + 1, l, (l + r) / 2, pos, x); n   } else { n     upd(2 * v + 2, (l + r) / 2, r, pos, x); n   } n   t[v] = max(t[2 * v + 1], t[2 * v + 2]); n } n int main() { n   scanf( %d , &n); n   for (int i = 0; i < n; i++) { n     int ww, hh; n     scanf( %d %d , &ww, &hh); n     a[i] = hh; n     b[i] = ww; n     W += ww; n   } n   build(0, 0, n); n   for (int i = 0; i < n; i++) { n     W -= b[i]; n     upd(0, 0, n, i, -10000); n     H = get(0, 0, n, 0, n); n     printf( %d  , H * W); n     W += b[i]; n     upd(0, 0, n, i, a[i]); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long left; n   long long right; n   scanf( %lld%lld , &left, &right); n   long long ans = 0LL; n   for (int i = (62); i >= (0); --i) { n     long long bitLeft = left & (1LL << i); n     long long bitRight = right & (1LL << i); n     if (bitRight && !bitLeft) { n       ans = (1LL << (i + 1)) - 1LL; n       printf( %lld n , ans); n       return 0; n     } n   } n   printf( %lld n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class Ta, class Tb> n inline Tb cast(Ta a) { n   stringstream ss; n   ss << a; n   Tb b; n   ss >> b; n   return b; n }; n const double EPS = 1e-9; n const int INF = 1000000000; n const int MOD = 1000000007; n const int diri[8] = {-1, 0, 1, 0, -1, 1, 1, -1}; n const int dirj[8] = {0, 1, 0, -1, 1, 1, -1, -1}; n vector<int> tree; n int root(int n) { n   if (tree[n] == -1) return n; n   return tree[n] = root(tree[n]); n } n int main() { n   int n, m; n   cin >> n >> m; n   vector<int> deg(n, 0); n   tree = vector<int>(n, -1); n   for (int i = 0; i < m; ++i) { n     int x, y; n     cin >> x >> y; n     --x; n     --y; n     ++deg[x]; n     ++deg[y]; n     int a = root(x), b = root(y); n     if (a != b) { n       tree[b] = a; n     } n   } n   int c = 0; n   for (int i = 0; i < n; ++i) n     if (deg[i] != 0 and tree[i] == -1) ++c; n   if (deg[0] == 0 and c > 0) ++c; n   int s = 0; n   for (int i = 0; i < n; ++i) n     if (deg[i] % 2 == 1) ++s; n   if (c == 1) n     cout << s / 2 << endl; n   else { n     vector<int> v(n, 0); n     for (int i = 0; i < n; ++i) n       if (deg[i] % 2 == 1) v[root(i)] = 1; n     int t = 0; n     for (int i = 0; i < n; ++i) t += v[i]; n     cout << c + s / 2 - t << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   priority_queue<int, vector<int>, greater<int>> pq; n   int n, k; n   cin >> n >> k; n   for (int i = 0; i < n; i++) { n     int x; n     cin >> x; n     pq.push(x); n   } n   int ans = 0; n   for (int i = 0; i < k; i++) { n     ans += pq.top(); n     pq.pop(); n   } n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 5; n map<int, int> v[N]; n int rec(int node, int w) { n   auto it = v[node].lower_bound(w); n   if (it == v[node].begin()) { n     return 1; n   } n   it--; n   return (*it).second + 1; n } n int32_t main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   int n, m; n   cin >> n >> m; n   int ans = 0; n   while (m--) { n     int a, b, w; n     cin >> a >> b >> w; n     int val = rec(a, w); n     if (rec(b, w + 1) > val) { n       continue; n     } n     v[b][w] = val; n     auto it = v[b].upper_bound(w); n     while (it != v[b].end() && (*it).second <= val) { n       it = v[b].erase(it); n     } n     ans = max(ans, val); n   } n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int a, b; n   scanf( %lld%lld , &a, &b); n   long long int c = a, d = b; n   long long int cnt = 0, rem; n   while (c >= 1 && d >= 1) { n     if (d == 1) { n       printf( %lld , cnt + c); n       return 0; n     } n     if (c >= d) { n       cnt += c / d; n       c = c % d; n     } else { n       cnt += d / c; n       d = d % c; n     } n   } n   printf( %lld n , cnt); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = (int)5e5 + 9; n vector<int> T[N]; n bool use[2 * N]; n int p; n int l[N], r[N]; n void dfs(int u, int par) { n   if (par == -1) { n     l[u] = 1; n     r[u] = T[u].size() + 2; n     use[1] = true; n     use[T[u].size() + 2] = true; n     p = T[u].size() + 3; n     vector<pair<int, int> > srt; n     int fl = 2; n     for (auto x : T[u]) { n       if (x == par) continue; n       dfs(x, u); n       srt.push_back(make_pair(r[x], x)); n     } n     sort(srt.begin(), srt.end()); n     reverse(srt.begin(), srt.end()); n     for (int i = 0; i < srt.size(); i++) { n       l[srt[i].second] = fl++; n     } n     return; n   } n   vector<int> rr; n   for (auto x : T[u]) { n     if (x == par) { n       continue; n     } n     while (use[p]) p++; n     use[p] = true; n     rr.push_back(p); n   } n   while (use[p]) p++; n   r[u] = p; n   use[p] = true; n   vector<pair<int, int> > srt; n   for (int i = 0; i < T[u].size(); i++) { n     if (T[u][i] == par) continue; n     dfs(T[u][i], u); n     srt.push_back(make_pair(r[T[u][i]], T[u][i])); n   } n   sort(srt.begin(), srt.end()); n   reverse(srt.begin(), srt.end()); n   for (int i = 0; i < srt.size(); i++) { n     l[srt[i].second] = rr[i]; n   } n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   ; n   int n; n   cin >> n; n   int x, y; n   for (int i = 1; i < n; i++) { n     cin >> x >> y; n     T[x].push_back(y); n     T[y].push_back(x); n   } n   dfs(1, -1); n   for (int i = 1; i <= n; i++) cout << l[i] <<     << r[i] <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( O3 ) n #pragma GCC target( avx2 ) n using namespace std; n const long double two = 2; n const long double INF = 2e18 + 100; n const long long MOD = 998244353; n const long long N = 1e5 + 10; n const long long nul = 0; n const long long SIZE = 1e6 * 3; n struct exam { n   long long s, d, c, ind; n   exam(long long s1, long long d1, long long c1, long long ind1) { n     s = s1; n     d = d1; n     c = c1; n     ind = ind1; n   } n }; n vector<long long> ans; n vector<exam> smth; n bool lol(long long st, long long len, long long fin, long long ind) { n   long long i = st; n   while (len--) { n     while (ans[i] != 0 && i < fin) i++; n     if (i == fin) return 0; n     ans[i] = ind + 1; n   } n   return 1; n } n bool comp(exam a, exam b) { n   if (a.d < b.d) n     return 1; n   else n     return 0; n } n signed main() { n   long long n, m; n   cin >> n >> m; n   ans.resize(n, 0); n   smth; n   for (long long i = 0; i < m; i++) { n     long long s, d, c; n     cin >> s >> d >> c; n     s--; n     d--; n     ans[d] = m + 1; n     smth.push_back(exam(s, d, c, i)); n   } n   sort((smth).begin(), (smth).end(), comp); n   bool flag = 0; n   for (long long i = 0; i < m; i++) { n     if (lol(smth[i].s, smth[i].c, smth[i].d, smth[i].ind) == 0) flag = 1; n   } n   if (flag) n     cout << -1 << endl; n   else { n     for (long long i : ans) cout << i <<    ; n     cout << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n bool sol(long long n, long long m, long long a, long long l, long long r, n          long long& b, long long& c) { n   if (abs(n * a - m) <= r - l) { n     long long diff = m - n * a; n     b = diff > 0 ? r : l; n     c = b - diff; n     return true; n   } n   return false; n } n int main() { n   int T; n   cin >> T; n   while (T--) { n     long long l, r, m; n     cin >> l >> r >> m; n     for (long long a = l; a <= r; a++) { n       long long n0 = m / a, n1 = m / a + 1; n       long long b, c; n       if (n0 > 0 && sol(n0, m, a, l, r, b, c)) { n         printf( %lld %lld %lld n , a, b, c); n         break; n       } n       if (n1 > 0 && sol(n1, m, a, l, r, b, c)) { n         printf( %lld %lld %lld n , a, b, c); n         break; n       } n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false), cin.tie(nullptr); n   string a, b, c =   ; n   cin >> a >> b; n   for (int i = 0; i < a.length(); i++) { n     if (a[i] + 1 < b[i]) { n       c += a[i] + 1; n       for (int j = i + 1; j < a.length(); j++) c +=  z ; n       break; n     } else if (a[i] + 1 == b[i]) { n       bool big = 0; n       for (int j = i + 1; j < a.length(); j++) { n         if (a[j] !=  z ) big = 1; n       } n       if (big) { n         c += a[i]; n         for (int j = i + 1; j < a.length(); j++) c +=  z ; n         break; n       } else { n         c += a[i] + 1; n         for (int j = i + 1; j < a.length(); j++) c +=  a ; n         break; n       } n     } else n       c += a[i]; n   } n   if (c != a && c != b) n     cout << c; n   else n     cout <<  No such string ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int arr[5] = {10, 15, 60, 4, 19}; n int result = 0; n int getMin(int r, int g, int b) { n   if (r < g) { n     if (r < b) { n       return r; n     } else { n       return b; n     } n   } else { n     if (g < b) { n       return g; n     } else { n       return b; n     } n   } n } n int getMax(int r, int g, int b) { n   if (r > g) { n     if (r > b) { n       return r; n     } else { n       return b; n     } n   } else { n     if (g > b) { n       return g; n     } else { n       return b; n     } n   } n } n int getMin(int a, int b) { n   if (a < b) { n     return a; n   } else { n     return b; n   } n } n void solve(int r, int g, int b) { n   int count = 0; n   int sum = r + g + b; n   int min = getMin(r, g, b); n   int max = getMax(r, g, b); n   int mid = sum - (min + max); n   result = getMin(sum / 2, min + mid); n } n void print(int arr[], int n) { n   for (int i = 0; i < n; i++) { n     printf( %d  , arr[i]); n   } n } n void merge(int a[], int l, int m, int r) { n   int n1 = m - l + 1; n   int n2 = r - m; n   int *L = new int[n1]; n   int *R = new int[n2]; n   for (int i = 0; i < n1; i++) { n     L[i] = arr[l + i]; n   } n   for (int i = 0; i < n2; i++) { n     R[i] = arr[m + 1 + i]; n   } n   int i = 0, j = 0, k = l; n   while (i < n1 && j < n2) { n     if (L[i] < R[j]) { n       arr[k] = L[i]; n       k++; n       i++; n     } else { n       arr[k] = R[j]; n       j++; n       k++; n     } n   } n   while (i < n1) { n     arr[k] = L[i]; n     k++; n     i++; n   } n   while (j < n2) { n     arr[k] = R[j]; n     k++; n     j++; n   } n } n void merge(int a[], int l, int r) { n   if (l < r) { n     int m = l + (r - l) / 2; n     merge(arr, l, m); n     merge(arr, m + 1, r); n     merge(arr, l, m, r); n   } n } n int main() { n   int n; n   int r, g, b; n   char ch; n   int min = 9999999, max = -9999999; n   scanf( %d , &n); n   for (int i = 0; i < n; i++) { n     scanf( %d , &r); n     if (r > max) { n       max = r; n     } n     scanf( %d , &g); n     if (g > max) { n       max = g; n     } n     scanf( %d , &b); n     if (b > max) { n       max = b; n     } n     solve(r, g, b); n     printf( %d n , result); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   string s; n   cin >> s; n   long long a = -1, b = -1; n   int flag = 0; n   for (int i = 0; i < s.length(); i++) { n     if (s[i] ==  [ ) { n       a = i; n       flag = 1; n       break; n     } n   } n   if (flag == 0) { n     cout <<  -1 ; n     return 0; n   } n   flag = 0; n   for (int i = a; i < s.length(); i++) { n     if (s[i] ==  : ) { n       a = i; n       flag = 1; n       break; n     } n   } n   if (flag == 0) { n     cout <<  -1 ; n     return 0; n   } n   flag = 0; n   for (int i = s.length() - 1; i >= 0; i--) { n     if (s[i] ==  ] ) { n       b = i; n       flag = 1; n       break; n     } n   } n   if (flag == 0) { n     cout <<  -1 ; n     return 0; n   } n   flag = 0; n   for (int i = b; i >= 0; i--) { n     if (s[i] ==  : ) { n       b = i; n       flag = 1; n       break; n     } n   } n   if (flag == 0) { n     cout <<  -1 ; n     return 0; n   } n   if (a >= b) { n     cout <<  -1 ; n     return 0; n   } n   long long ans = 4; n   for (int i = a + 1; i <= b - 1; i++) { n     if (s[i] ==  | ) ans++; n   } n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n long long int a[500005]; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long int t, n, m, q, i, j, k, x, y = 2, z; n   cin >> n >> k; n   set<long long int> s; n   for (i = 0; i < n; i++) cin >> a[i]; n   sort(a, a + n); n   for (i = 0; i < n - 1; i++) { n     x = a[i] + k; n     if (x + k <= a[i + 1]) s.insert(x); n     x = a[i + 1] - k; n     if (a[i] + k <= x) s.insert(x); n   } n   cout << s.size() + 2; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, x, y; n   cin >> n >> x >> y; n   int z = n / 2; n   if (x >= z && x <= z + 1 && y >= z && y <= z + 1) n     cout <<  NO ; n   else n     cout <<  YES ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 405; n char G[405][405], P[405][405]; n bitset<MAXN> nolet[405][27]; n int main() { n   int N, M; n   scanf( %d%d , &N, &M); n   for (int i = 0; i < N; ++i) { n     scanf( %s , G[i]); n     for (int c = 0; c < 26; ++c) n       for (int j = 0; j < M; ++j) n         if (G[i][j] -  a  != c) nolet[i][c].set(j); n   } n   int R, C; n   scanf( %d%d , &R, &C); n   for (int i = 0; i < R; ++i) { n     scanf( %s , P[i]); n   } n   for (int i = 0; i < N; ++i) { n     bitset<MAXN> no; n     for (int r = 0; r < R; ++r) n       for (int c = 0; c < C; ++c) { n         if (P[r][c] ==  ? ) continue; n         int ii = (i + r) % N; n         auto b = nolet[ii][P[r][c] -  a ]; n         no |= (b >> c) | (b << (M - c)); n       } n     for (int j = 0; j < M; ++j) printf( %d , !no[j]); n     printf(  n ); n   } n } n


#include <bits/stdc++.h> n int a[100000]; n int main() { n   int y, k, n, i; n   while (scanf( %d %d %d , &y, &k, &n) != EOF) { n     int flag = 0; n     int l = n / k; n     for (i = 1; i <= l; i++) { n       a[i] = i * k; n       if (a[i] > y) { n         printf( %d  , a[i] - y); n         flag = 1; n       } n     } n     if (flag == 0) printf( -1 ); n     printf(  n ); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   char a[n][5]; n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= 5; j++) { n       cin >> a[i][j]; n     } n   } n   int flag = 0; n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= 4; j++) { n       if ((a[i][j] ==  O ) && (a[i][j + 1] ==  O )) { n         a[i][j] =  + ; n         a[i][j + 1] =  + ; n         flag = 1; n         break; n       } n     } n     if (flag) break; n   } n   if (flag) { n     cout <<  YES  << endl; n     for (int i = 1; i <= n; i++) { n       for (int j = 1; j <= 5; j++) { n         cout << a[i][j]; n       } n       cout << endl; n     } n   } else n     cout <<  NO  << endl; n   return 0; n } n


#include <bits/stdc++.h> n const int inf = (1ll << 30) - 1; n const int maxn = (int)1e5 + 10; n using namespace std; n pair<long long, long long> e[100100]; n int en; n vector<int> g[100100]; n long long dp[100100], d[100100]; n int pr[100100]; n int used[100100]; n long long mi[100100]; n int n, m, L, second, t; n void solve() { n   scanf( %d%d%d%d%d , &n, &m, &L, &second, &t); n   long long cons = (long long)1e9 + 1; n   for (int i = 0, a, b, w; i < m; i++) { n     scanf( %d%d%d , &a, &b, &w); n     if (w == 0) { n       g[a].push_back(en); n       g[b].push_back(en); n       e[en++] = make_pair(a ^ b, cons); n     } else { n       g[a].push_back(en); n       g[b].push_back(en); n       e[en++] = make_pair(a ^ b, w); n     } n   } n   for (int i = 0; i < n; i++) { n     dp[i] = 2ll * cons * n; n   } n   dp[t] = 0; n   for (int i = 0; i < n; i++) { n     int v = -1; n     for (int j = 0; j < n; j++) { n       if (used[j]) continue; n       if (v == -1 || dp[v] > dp[j]) v = j; n     } n     used[v] = 1; n     for (int j = 0; j < g[v].size(); j++) { n       int ind = g[v][j]; n       int to = e[ind].first ^ v; n       if (used[to]) continue; n       if (e[ind].second < cons) { n         dp[to] = min(dp[v] + e[ind].second, dp[to]); n       } n     } n   } n   for (int i = 0; i < n; i++) { n     d[i] = 2ll * cons * n; n     used[i] = 0; n   } n   d[second] = 0; n   for (int i = 0; i < n; i++) { n     int v = -1; n     for (int j = 0; j < n; j++) { n       if (used[j]) continue; n       if (v == -1 || d[v] > d[j]) v = j; n     } n     used[v] = 1; n     for (int j = 0; j < g[v].size(); j++) { n       int ind = g[v][j]; n       int to = e[ind].first ^ v; n       if (used[to]) continue; n       if (e[ind].second < cons) { n         d[to] = min(d[v] + e[ind].second, d[to]); n       } n     } n   } n   for (int i = 0; i < n; i++) { n     used[i] = 0; n   } n   for (int i = 0; i < n; i++) { n     int v = -1; n     for (int j = 0; j < n; j++) { n       if (used[j]) continue; n       if (v == -1 || d[v] > d[j]) v = j; n     } n     used[v] = 1; n     for (int j = 0; j < g[v].size(); j++) { n       int ind = g[v][j]; n       int to = e[ind].first ^ v; n       if (e[ind].second < cons) { n         d[to] = min(d[v] + e[ind].second, d[to]); n       } else { n         if (mi[ind] == 0) { n           mi[ind] = max(L - d[v] - dp[to], 1ll); n         } else { n           mi[ind] = max(L - d[v] - dp[to], mi[ind]); n         } n         d[to] = min(d[v] + mi[ind], d[to]); n       } n     } n   } n   for (int i = 0; i < n; i++) { n     d[i] = 2ll * cons * n; n     used[i] = 0; n   } n   for (int i = 0; i < en; i++) { n     if (e[i].second == cons) e[i].second = mi[i]; n   } n   d[second] = 0; n   for (int i = 0; i < n; i++) { n     int v = -1; n     for (int j = 0; j < n; j++) { n       if (used[j]) continue; n       if (v == -1 || d[v] > d[j]) v = j; n     } n     used[v] = 1; n     for (int j = 0; j < g[v].size(); j++) { n       int ind = g[v][j]; n       int to = e[ind].first ^ v; n       d[to] = min(d[v] + e[ind].second, d[to]); n     } n   } n   if (d[t] != L) { n     printf( NO n ); n     return; n   } n   printf( YES n ); n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < g[i].size(); j++) { n       int ind = g[i][j]; n       int to = e[ind].first ^ i; n       if (to > i) { n         printf( %d %d %I64d n , to, i, e[ind].second); n       } n     } n   } n } n int main() { n   int t = 1; n   for (int i = 1; i <= t; i++) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m; n int sz = 1; n string data[109]; n struct node { n   int x, y; n   int pos; n }; n bool operator<(const node& a, const node& b) { n   if (a.x == b.x) { n     if (a.y == b.y) { n       return a.pos < b.pos; n     } n     return a.y < b.y; n   } n   return a.x < b.x; n } n map<node, int> mem; n int conv(vector<int> v) { n   int ret = 0; n   for (typeof(v.begin()) it = (v.begin()); it != v.end(); it++) { n     ret = ret * 4 + (*it); n   } n   return ret; n } n vector<int> conv2(int pos) { n   vector<int> ret; n   for (long long i = 0; i < (long long)sz - 1; i++) { n     ret.push_back(pos % 4); n     pos /= 4; n   } n   reverse(ret.begin(), ret.end()); n   return ret; n } n int main() { n   scanf( %d , &n); n   scanf( %d , &m); n   for (long long i = 0; i < (long long)n; i++) cin >> data[i]; n   queue<node> q; n   vector<int> p; n   int x = -1, y; n   node top; n   for (long long i = 0; i < (long long)n; i++) { n     for (long long j = 0; j < (long long)m; j++) { n       if (data[i][j] ==  1 ) { n         x = i; n         y = j; n       } n       if (data[i][j] >  1  && data[i][j] <=  9 ) { n         sz = max(sz, (int)(data[i][j] -  0 )); n       } n     } n   } n   top.x = x; n   top.y = y; n   int xx, yy, px = x, py = y; n   for (long long i = 0; i < (long long)sz - 1; i++) { n     if (px - 1 >= 0) { n       if ((data[px - 1][py] -  1 ) == i + 1) { n         px--; n         p.push_back(0); n       } n     } n     if (px + 1 < n) { n       if ((data[px + 1][py] -  1 ) == i + 1) { n         px++; n         p.push_back(1); n       } n     } n     if (py - 1 >= 0) { n       if ((data[px][py - 1] -  1 ) == i + 1) { n         py--; n         p.push_back(2); n       } n     } n     if (py + 1 < m) { n       if ((data[px][py + 1] -  1 ) == i + 1) { n         py++; n         p.push_back(3); n       } n     } n   } n   top.pos = conv(p); n   q.push(top); n   mem[top] = 1; n   while (!q.empty()) { n     top = q.front(); n     x = top.x; n     y = top.y; n     int pos = top.pos; n     int cost = mem[top]; n     q.pop(); n     p = conv2(pos); n     if (data[x][y] ==  @ ) { n       cout << cost - 1 << endl; n       return 0; n     } n     px = x; n     py = y; n     if (px - 1 >= 0 && ((data[px - 1][py]) !=  # )) { n       vector<int> nw; n       nw.push_back(1); n       nw.insert(nw.end(), p.begin(), p.end() - 1); n       int xx, yy; n       xx = px - 1; n       yy = py; n       node temp; n       temp.x = xx; n       temp.y = yy; n       xx = x; n       yy = y; n       int flag = 0; n       for (int i = 1; i < sz - 1; i++) { n         if (nw[i] == 0) { n           xx--; n         } else if (nw[i] == 1) n           xx++; n         else if (nw[i] == 2) n           yy--; n         else n           yy++; n         if (xx == temp.x && yy == temp.y) { n           flag = 1; n           break; n         } n       } n       if (flag == 0) { n         temp.pos = conv(nw); n         if (mem.find(temp) == mem.end()) { n           mem[temp] = cost + 1; n           q.push(temp); n         } n       } n     } n     if (px + 1 < n && ((data[px + 1][py]) !=  # )) { n       vector<int> nw; n       nw.push_back(0); n       nw.insert(nw.end(), p.begin(), p.end() - 1); n       int xx, yy; n       xx = px + 1; n       yy = py; n       node temp; n       temp.x = xx; n       temp.y = yy; n       xx = x; n       yy = y; n       int flag = 0; n       for (int i = 1; i < sz - 1; i++) { n         if (nw[i] == 0) { n           xx--; n         } else if (nw[i] == 1) n           xx++; n         else if (nw[i] == 2) n           yy--; n         else n           yy++; n         if (xx == temp.x && yy == temp.y) { n           flag = 1; n           break; n         } n       } n       if (flag == 0) { n         temp.pos = conv(nw); n         if (mem.find(temp) == mem.end()) { n           mem[temp] = cost + 1; n           q.push(temp); n         } n       } n     } n     if (py - 1 >= 0 && ((data[px][py - 1]) !=  # )) { n       vector<int> nw; n       nw.push_back(3); n       nw.insert(nw.end(), p.begin(), p.end() - 1); n       int xx, yy; n       xx = px; n       yy = py - 1; n       node temp; n       temp.x = xx; n       temp.y = yy; n       xx = x; n       yy = y; n       int flag = 0; n       for (int i = 1; i < sz - 1; i++) { n         if (nw[i] == 0) { n           xx--; n         } else if (nw[i] == 1) n           xx++; n         else if (nw[i] == 2) n           yy--; n         else n           yy++; n         if (xx == temp.x && yy == temp.y) { n           flag = 1; n           break; n         } n       } n       if (flag == 0) { n         temp.pos = conv(nw); n         if (mem.find(temp) == mem.end()) { n           mem[temp] = cost + 1; n           q.push(temp); n         } n       } n     } n     if (py + 1 < m && ((data[px][py + 1]) !=  # )) { n       vector<int> nw; n       nw.push_back(2); n       nw.insert(nw.end(), p.begin(), p.end() - 1); n       int xx, yy; n       xx = px; n       yy = py + 1; n       node temp; n       temp.x = xx; n       temp.y = yy; n       xx = x; n       yy = y; n       int flag = 0; n       for (int i = 1; i < sz - 1; i++) { n         if (nw[i] == 0) { n           xx--; n         } else if (nw[i] == 1) n           xx++; n         else if (nw[i] == 2) n           yy--; n         else n           yy++; n         if (xx == temp.x && yy == temp.y) { n           flag = 1; n           break; n         } n       } n       if (flag == 0) { n         temp.pos = conv(nw); n         if (mem.find(temp) == mem.end()) { n           mem[temp] = cost + 1; n           q.push(temp); n         } n       } n     } n   } n   cout << -1 << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n int p; n int a[300010]; n int ans; n int main() { n   int i, j, k; n   scanf( %d , &n); n   ans = 1; n   a[n + 1] = -1; n   printf( 1 ); n   for (k = 1; k <= n; ++k) { n     scanf( %d , &p); n     if (a[p + 1] == -1) { n       i = p - 1; n       a[p] = -1; n       while ((i > 0) && (a[i] == 1)) { n         a[i] = -1; n         --ans; n         --i; n       } n     } else { n       if (!a[p]) { n         a[p] = 1; n         ++ans; n       } n     } n     printf(  %d , ans); n   } n } n


#include <bits/stdc++.h> n struct Seg { n   int l; n   int r; n   int y; n }; n struct Event { n   int x; n   enum { BEG, END } type; n   Seg seg; n   static Event beginOf(Seg seg) { return Event{seg.l, BEG, seg}; } n   static Event endOf(Seg seg) { return Event{seg.r, END, seg}; } n   friend bool operator<(const Event& a, const Event& b) { n     return std::tie(a.x, a.type, a.seg.y) < std::tie(b.x, b.type, b.seg.y); n   } n }; n int main() { n   int sx, sy; n   std::cin >> sy >> sx; n   std::vector<Event> events; n   events.reserve(sy * sx); n   for (int y = 0; y < sy; y++) { n     int intervals; n     std::cin >> intervals; n     for (int i = 0; i < intervals; i++) { n       int l, r; n       std::cin >> l >> r; n       Seg seg{l - 1, r, y}; n       events.push_back(Event::beginOf(seg)); n       events.push_back(Event::endOf(seg)); n     } n   } n   std::sort(events.begin(), events.end()); n   std::vector<std::vector<int>> dp(sx + 1, std::vector<int>(sx + 1, 0)); n   for (int len = 1; len <= sx; len++) { n     for (int l = 0, r = len; r <= sx; l++, r++) { n       int currHeight = 0; n       auto currEv = events.begin(); n       for (int x = l; x < r; x++) { n         for (; currEv != events.end() && currEv->x <= x; ++currEv) { n           if (l <= currEv->seg.l && currEv->seg.r <= r) { n             if (currEv->type == Event::BEG) n               currHeight++; n             else n               currHeight--; n           } n         } n         dp[l][r] = std::max(dp[l][r], n                             dp[l][x] + dp[x + 1][r] + currHeight * currHeight); n       } n     } n   } n   std::cout << dp[0][sx] << std::endl; n } n