#include <bits/stdc++.h> n using namespace std; n long long rdtsc() { n   long long tmp; n   asm( rdtsc  :  =A (tmp)); n   return tmp; n } n inline int myrand() { return abs((rand() << 15) ^ rand()); } n inline int rnd(int x) { return myrand() % x; } n const int INF = (int)1e9 + 1; n const long double EPS = 1e-9; n void precalc() {} n struct Line { n   int a, b, c; n   int id; n   int read(int _id) { n     id = _id; n     if (scanf( %d%d%d , &a, &b, &c) < 3) { n       return 0; n     } n     return 1; n   } n }; n long long gcd(long long a, long long b) { n   for (; b; a %= b, swap(a, b)) n     ; n   return a; n } n struct Ratio { n   long long a, b; n   Ratio() {} n   Ratio(long long _a, long long _b) : a(_a), b(_b) { n     assert(b != 0ll); n     normalize(); n   } n   void normalize() { n     long long d = gcd(a, b); n     a /= d, b /= d; n     if (b < 0) { n       a = -a, b = -b; n     } n   } n   inline bool operator<(const Ratio &r) const { n     if (a != r.a) { n       return a < r.a; n     } n     return b < r.b; n   } n   inline bool operator==(const Ratio &r) const { return a == r.a && b == r.b; } n }; n struct Point { n   Ratio x, y; n   Point() {} n   Point(Ratio _x, Ratio _y) : x(_x), y(_y) {} n   inline bool operator<(const Point &p) const { n     if (x == p.x) { n       return y < p.y; n     } n     return x < p.x; n   } n   inline bool operator==(const Point &p) const { return x == p.x && y == p.y; } n }; n bool inter(const Line &l1, const Line &l2, Point &res) { n   long long D = (long long)l1.a * l2.b - (long long)l1.b * l2.a; n   if (D == 0ll) { n     return 0; n   } n   long long Dx = (long long)l1.b * l2.c - (long long)l1.c * l2.b; n   long long Dy = (long long)l1.c * l2.a - (long long)l1.a * l2.c; n   res = Point(Ratio(Dx, D), Ratio(Dy, D)); n   return 1; n } n int n, k; n const int maxn = (int)1e5 + 10; n Line lines[maxn]; n bool read() { n   if (scanf( %d%d , &n, &k) < 2) { n     return 0; n   } n   for (int i = 0; i < n; ++i) { n     lines[i].read(i); n   } n   return 1; n } n const int maxk = 5; n int ans[maxk][2]; n int res; n Line tmp[maxn]; n int used[maxn]; n bool gen(int pos, int k) { n   if (pos == n) { n     return 1; n   } n   if (used[pos]) { n     return gen(pos + 1, k); n   } n   if (k == 0) { n     return 0; n   } n   { n     ans[res][0] = lines[pos].id + 1, ans[res][1] = -1; n     ++res; n     if (gen(pos + 1, k - 1)) { n       return 1; n     } n     --res; n   } n   int oks[n]; n   Point ps[maxk * maxk + 5]; n   for (int j = pos + 1; j < n; ++j) { n     oks[j] = 0; n     if (used[j]) { n       continue; n     } n     Point p; n     if (!inter(lines[pos], lines[j], p)) { n       continue; n     } n     oks[j] = 1; n     ps[j] = p; n   } n   int tmp[n]; n   for (int j = pos + 1; j < n; ++j) { n     if (!oks[j]) { n       continue; n     } n     ans[res][0] = lines[pos].id + 1, ans[res][1] = lines[j].id + 1; n     ++res; n     for (int k = pos + 1; k < n; ++k) { n       tmp[k] = used[k]; n       if (!oks[k]) { n         continue; n       } n       if (ps[j] == ps[k]) { n         used[k] += 1; n         oks[k] = 0; n       } n     } n     if (gen(pos + 1, k - 1)) { n       return 1; n     } n     --res; n     for (int k = pos + 1; k < n; ++k) { n       used[k] = tmp[k]; n     } n   } n   return 0; n } n bool solveSmall() { n   random_shuffle(lines, lines + n, rnd); n   for (int i = 0; i < n; ++i) { n     used[i] = 0; n   } n   return gen(0, k); n } n void solve() { n   res = 0; n   while (n > k * k && k > 0) { n     const int K = 250; n     pair<Point, pair<int, int> > ps[K]; n     int cnt = 0; n     bool ok = 0; n     for (int iter = 0; iter < K; ++iter) { n       int x = rnd(n), y = rnd(n); n       Point p; n       if (x == y || !inter(lines[x], lines[y], p)) { n         continue; n       } n       ps[cnt++] = make_pair(p, make_pair(x, y)); n     } n     sort(ps, ps + cnt); n     Point p; n     int x, y; n     bool found = 0; n     for (int i = 0; i < cnt;) { n       int i0 = i; n       while (i < cnt && ps[i].first == ps[i0].first) { n         ++i; n       } n       if (i - i0 > k) { n         found = 1; n         p = ps[i0].first; n         x = ps[i0].second.first, y = ps[i0].second.second; n         break; n       } n     } n     if (!found) { n       printf( NO n ); n       return; n     } n     { n       int cnt = 0, cntp = 0; n       for (int i = 0; i < n; ++i) { n         Point q; n         if (!inter(lines[i], lines[i == x ? y : x], q)) { n           continue; n         } n         if (q == p) { n           ++cntp; n         } else { n           tmp[cnt++] = lines[i]; n         } n       } n       assert(cntp > k); n       ans[res][0] = lines[x].id + 1, ans[res][1] = lines[y].id + 1; n       ++res; n       for (int i = 0; i < cnt; ++i) { n         lines[i] = tmp[i]; n       } n       n = cnt; n       --k; n     } n   } n   if (solveSmall()) { n     printf( YES n ); n     printf( %d n , res); n     for (int i = 0; i < res; ++i) { n       printf( %d %d n , ans[i][0], ans[i][1]); n     } n   } else { n     printf( NO n ); n   } n } n int main() { n   srand(rdtsc()); n   precalc(); n   while (1) { n     if (!read()) { n       break; n     } n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   int a[6]; n   for (int i = 0; i < 6; i++) scanf( %d , &a[i]); n   int tot = a[0] + a[1] + a[2]; n   int ans = tot * tot - a[0] * a[0] - a[2] * a[2] - a[4] * a[4]; n   printf( %d n , ans); n } n


#include <bits/stdc++.h> n using namespace std; n const unsigned long long hash1 = 201326611; n const unsigned long long hash2 = 50331653; n const int N = 200000 + 10; n const int M = 20; n vector<int> g[N]; n int n, vis[N]; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0), cout.tie(0); n   cin >> n; n   int u, v; n   for (int i = 1; i < n; i++) { n     cin >> u >> v; n     vis[u]++; n     vis[v]++; n   } n   int flag = 0; n   for (int i = 1; i <= n; i++) { n     if (vis[i] == 2) flag = 1; n   } n   if (flag) n     cout <<  NO  << endl; n   else n     cout <<  YES  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, root; n int val[100000], maxl[100000], maxr[100000]; n vector<int> fo[100000]; n void dfs(int vr) { n   if (fo[vr].size() == 0) { n     maxl[vr] = maxr[vr] = val[vr]; n     return; n   } n   dfs(fo[vr][0]); n   dfs(fo[vr][1]); n   maxl[vr] = maxl[fo[vr][0]]; n   maxr[vr] = maxr[fo[vr][1]]; n } n map<int, int> rev1; n map<int, int> revq, vals; n double sum[100000], pl[100000]; n void dfs1(int vr, int par = -1) { n   if (par == -1) { n     pl[vr] = 0; n     sum[vr] = 0; n   } else { n     pl[vr] = pl[par] + 1; n     if (fo[par][0] == vr) n       sum[vr] = sum[par] + maxl[fo[par][1]]; n     else n       sum[vr] = sum[par] + maxr[fo[par][0]]; n   } n   if (!fo[vr].empty()) { n     dfs1(fo[vr][0], vr); n     dfs1(fo[vr][1], vr); n   } n } n vector<int> ID, IDX; n void dfs2(int vr, int f, int t) { n   if (f > t) return; n   if (fo[vr].size() == 0) { n     for (int i = f; i <= t; ++i) IDX[i] = vr; n     return; n   } n   int DEL = (int)(lower_bound(ID.begin() + f, ID.begin() + t + 1, val[vr]) - n                   ID.begin()); n   dfs2(fo[vr][0], f, DEL - 1); n   dfs2(fo[vr][1], DEL, t); n } n int main() { n   int i, j, k, l; n   scanf( %d , &n); n   for (i = 0; i < n; ++i) { n     int _p, _v; n     scanf( %d%d , &_p, &_v); n     --_p; n     if (_p < 0) n       root = i; n     else n       fo[_p].push_back(i); n     val[i] = _v; n   } n   for (i = 0; i < n; ++i) { n     if (!fo[i].empty()) n       if (val[fo[i][0]] > val[i]) swap(fo[i][0], fo[i][1]); n     rev1[val[i]] = i; n   } n   dfs(root); n   dfs1(root); n   int Q; n   scanf( %d , &Q); n   ID.resize(Q); n   IDX.resize(Q); n   for (i = 0; i < Q; ++i) { n     scanf( %d , &ID[i]); n     revq[i] = ID[i]; n   } n   sort(ID.begin(), ID.end()); n   for (i = 0; i < ID.size(); ++i) vals[ID[i]] = i; n   dfs2(root, 0, Q - 1); n   for (i = 0; i < Q; ++i) n     printf( %.12lf n , sum[IDX[vals[revq[i]]]] / pl[IDX[vals[revq[i]]]]); n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( O3 ) n using namespace std; n inline void umax(long long &a, long long b) { a = max(a, b); } n inline void umin(long long &a, long long b) { a = min(a, b); } n inline pair<long long, long long> rv(pair<long long, long long> a) { n   return make_pair(a.second, a.first); n } n const long long N = 2e5 + 10; n const long long INF = 1e16 + 10; n const pair<long long, long long> NINF = make_pair(INF, INF); n const long double EPS = 1e-6; n const long long II = 1e9; n const long long MOD = 1e9 + 9; n long long dp[N]; n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long n, k; n   cin >> n >> k; n   string second; n   cin >> second; n   queue<pair<long long, long long> > buf; n   for (long long i = 0; i < (min(k, n)); i++) n     if (second[i] ==  1 ) buf.push(make_pair(i + 1, i + k)); n   for (long long i = 0; i < (n + 1); i++) dp[i] = INF; n   dp[0] = 1; n   for (long long i = 0; i < n; i++) { n     if (i + k < n && second[i + k] ==  1 ) n       buf.push(make_pair(i + k + 1, i + k * 2)); n     if (buf.size()) { n       auto beg = buf.front(); n       long long pr = beg.second - k * 2 - 1; n       long long ll = (pr >= 0 ? dp[pr] : 0LL); n       umin(dp[i], ll + beg.first); n       if (beg.second == i) buf.pop(); n     } n     if (i) umin(dp[i], dp[i - 1] + i + 1); n   } n   cout << dp[n - 1]; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int n, t; n   cin >> n >> t; n   string s; n   cin >> s; n   char temp; n   while (t--) { n     for (int i = 0; i < n - 1; i++) { n       if (s[i] != s[i + 1] && s[i] ==  B ) { n         temp = s[i + 1]; n         s[i + 1] = s[i]; n         s[i] = temp; n         i++; n       } n     } n   } n   cout << s; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); n const long long maxn = 3e6; n const long long mod = 1e9 + 7; n const long double PI = acos((long double)-1); n long long pw(long long a, long long b, long long md = mod) { n   long long res = 1; n   while (b) { n     if (b & 1) { n       res = (a * res) % md; n     } n     a = (a * a) % md; n     b >>= 1; n   } n   return (res); n } n int n; n long long l[maxn], r[maxn]; n int32_t main() { n   ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); n   cin >> n; n   for (int i = 0; i < n; i++) cin >> l[i]; n   for (int i = 0; i < n; i++) cin >> r[i]; n   long long p = 1, q = 0, sum = 0, sm = 0; n   for (int i = 0; i < n; i++) { n     if (i) { n       long long a = max(0LL, min(r[i], r[i - 1]) - max(l[i], l[i - 1]) + 1); n       long long b = (r[i] - l[i] + 1) * (r[i - 1] - l[i - 1] + 1) % mod; n       p = ((b - a + mod) % mod * pw(b, mod - 2)) % mod; n     } n     sum = (sum + p) % mod; n     sm = (sm + pw(p, 2) + (2LL * (p - 1) * (q - 1)) % mod + mod) % mod; n     q = p; n   } n   long long ans = (sum * (sum + 1) - sm + mod * 100LL) % mod; n   for (int i = 2; i < n; i++) { n     long long a = max(0LL, min({r[i], r[i - 1], r[i - 2]}) - n                                max({l[i], l[i - 1], l[i - 2]}) + 1); n     long long b = max(0LL, r[i - 2] - l[i - 2] + 1); n     b = (b * max(0LL, r[i - 1] - l[i - 1] + 1)) % mod; n     b = (b * max(0LL, r[i] - l[i] + 1)) % mod; n     p = (a * pw(b, mod - 2)) % mod; n     ans = (ans + 2 * p) % mod; n   } n   cout << ans <<   n ; n   return (0); n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> dx = {-1, 0, 0, 1}; n vector<int> dy = {0, -1, 1, 0}; n const int Mod = (int)((int)1e9 + 7); n void solve() { n   int n, k; n   cin >> n >> k; n   vector<int> a(n); n   int ans = 0; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n   } n   sort(a.begin(), a.end()); n   for (int i = 1; i < n; i++) { n     while (a[i] + a[0] <= k) { n       a[i] += a[0]; n       ans++; n     } n   } n   cout << ans << endl; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int q = 1; n   cin >> q; n   for (int i = 1; i <= q; i++) { n     solve(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   int game[2]; n   int m, c; n   m = c = 0; n   for (int i = 0; i < n; i++) { n     cin >> game[0] >> game[1]; n     if (game[0] > game[1]) { n       m++; n     } else if (game[0] < game[1]) { n       c++; n     } n   } n   if (m > c) { n     cout <<  Mishka  << endl; n   } else if (m < c) { n     cout <<  Chris  << endl; n   } else { n     cout <<  Friendship is magic!^^  << endl; n   } n }; n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e6 + 10; n int nxt[N]; n map<int, vector<int>> w; n int extendA[N], extendB[N], l[N], r[N]; n char s[N], t[N]; n int n, m, k; n void pre_EKMP(char x[], int m, int nxt[]) { n   nxt[0] = m; n   int j = 0; n   while (j + 1 < m && x[j] == x[j + 1]) j++; n   nxt[1] = j; n   int k = 1; n   for (int i = 2; i < m; i++) { n     int p = nxt[k] + k - 1; n     int L = nxt[i - k]; n     if (i + L < p + 1) n       nxt[i] = L; n     else { n       j = max(0, p - i + 1); n       while (i + j < m && x[i + j] == x[j]) j++; n       nxt[i] = j; n       k = i; n     } n   } n } n void EKMP(char x[], int m, char y[], int n, int nxt[], int extend[]) { n   pre_EKMP(x, m, nxt); n   int j = 0; n   while (j < n && j < m && x[j] == y[j]) j++; n   extend[0] = j; n   int k = 0; n   for (int i = 1; i < n; i++) { n     int p = extend[k] + k - 1; n     int L = nxt[i - k]; n     if (i + L < p + 1) n       extend[i] = L; n     else { n       j = max(0, p - i + 1); n       while (i + j < n && j < m && y[i + j] == x[j]) j++; n       extend[i] = j; n       k = i; n     } n   } n } n struct node { n   int son[26]; n   int len, fail; n   int id; n } tri[N]; n int lst, L; n void add(int last, int c) { n   static int v, u, up, up1; n   v = ++L; n   u = last; n   tri[v].len = tri[u].len + 1; n   for (; u && !tri[u].son[c]; u = tri[u].fail) tri[u].son[c] = v; n   if (!u) n     tri[v].fail = 1; n   else { n     up = tri[u].son[c]; n     if (tri[up].len == tri[u].len + 1) n       tri[v].fail = up; n     else { n       up1 = ++L; n       tri[up1] = tri[up]; n       tri[up1].len = tri[u].len + 1; n       tri[up].fail = tri[v].fail = up1; n       for (; u && tri[u].son[c] == up; u = tri[u].fail) tri[u].son[c] = up1; n     } n   } n   lst = v; n } n int rt[N]; n int main() { n   scanf( %d %d %d , &n, &m, &k); n   scanf( %s , s); n   scanf( %s , t); n   lst = 1, L = 1; n   rt[0] = 1; n   for (int i = 0; i < m; i++) { n     add(lst, t[i] -  a ); n     rt[i + 1] = lst; n   } n   EKMP(t, m, s, n, nxt, extendA); n   reverse(s, s + n); n   reverse(t, t + m); n   EKMP(t, m, s, n, nxt, extendB); n   reverse(extendB, extendB + n); n   for (int i = 0; i < n; i++) { n     extendB[i] = min(extendB[i], k), extendA[i] = min(extendA[i], k); n     if (extendA[i] == m) { n       int l = max(i + extendA[i] - k, 0); n       if (l + k + k - 1 < n) { n         puts( Yes ); n         printf( %d %d n , l + 1, l + k + 1); n         return 0; n       } n       l = min(n - 1, i + k - 1); n       if (l - k - k + 1 >= 0) { n         puts( Yes ); n         printf( %d %d n , l - k - k + 2, l - k + 2); n         return 0; n       } n     } n   } n   int last = 1e9; n   for (int i = n - 1; i >= 0; i--) { n     l[i] = (extendA[i] == k) * k; n     for (auto u : w[i + k - 1]) last = min(last, u); n     l[i] = max(l[i], i + k - last); n     if (extendA[i]) { n       int x = i + extendA[i] - 1; n       if (x >= (i + k - 1)) n         last = i; n       else n         w[x].push_back(i); n     } n   } n   w.clear(); n   last = -1e9; n   for (int i = 0; i < n; i++) { n     r[i] = (extendB[i] == k) * k; n     for (auto u : w[i - k + 1]) last = max(last, u); n     r[i] = max(r[i], last - (i - k)); n     if (extendB[i]) { n       int x = i - extendB[i] + 1; n       if (x <= i - k + 1) n         last = i; n       else n         w[x].push_back(i); n     } n   } n   for (int i = 2 * k - 1; i < n; i++) { n     int x = rt[l[i - 2 * k + 1]]; n     while (!tri[x].id) { n       tri[x].id = i - 2 * k + 2; n       x = tri[x].fail; n     } n     if (tri[rt[m - r[i]]].id) { n       puts( Yes ); n       printf( %d %d n , tri[rt[m - r[i]]].id, i - k + 2); n       return 0; n     } n   } n   printf( No ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n int b[3100]; n int a[3100]; n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; ++i) { n     scanf( %d , &b[i]); n     int bb = b[i] - b[i - 1], l; n     if (bb > 0) { n     youginzi: n       l = 1; n       while (bb) { n         while (a[l] == 9) l++; n         a[l]++; n         --bb; n       } n     } else if (bb < 0) { n       while (bb) { n         if (bb > 0) goto youginzi; n         l = 0; n         while (a[++l] == 0) n           ; n         do { n           bb += a[l] - 1; n           a[l] = 0; n           ++a[++l]; n         } while (a[l] >= 10); n       } n     } else { n       l = 0; n       while (a[++l] == 0) n         ; n       do { n         bb += a[l] - 1; n         a[l] = 0; n         ++a[++l]; n       } while (a[l] >= 10); n       goto youginzi; n     } n     int len = 3005; n     while (a[len] == 0) --len; n     for (int j = len; j >= 1; --j) printf( %d , a[j]); n     puts(  ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline void read(int &x) { n   int v = 0, f = 1; n   char c = getchar(); n   while (!isdigit(c) && c !=  - ) c = getchar(); n   if (c ==  - ) n     f = -1; n   else n     v = (c & 15); n   while (isdigit(c = getchar())) v = (v << 1) + (v << 3) + (c & 15); n   x = v * f; n } n inline void read(long long &x) { n   long long v = 0ll, f = 1ll; n   char c = getchar(); n   while (!isdigit(c) && c !=  - ) c = getchar(); n   if (c ==  - ) n     f = -1; n   else n     v = (c & 15); n   while (isdigit(c = getchar())) v = (v << 1) + (v << 3) + (c & 15); n   x = v * f; n } n inline void readc(char &x) { n   char c; n   while (((c = getchar()) ==    ) || c ==   n ) n     ; n   x = c; n } n int n, m, i, j, t, a[30005]; n long long s0, s1; n int main() { n   read(t); n   while (t--) { n     read(n); n     for (((i)) = (1); ((i)) <= ((n)); ((i))++) read(a[i]); n     a[n + 1] = 0; n     for (((i)) = ((n + 1)); ((i)) >= (1); ((i))--) a[i] = a[i] - a[i - 1]; n     s0 = a[1]; n     s1 = a[n + 1]; n     for ((i) = (2); (i) <= (n); (i)++) n       if (a[i] > 0) n         s1 += a[i]; n       else n         s0 += a[i]; n     if (s1 <= 0 && s0 >= 0) n       puts( YES ); n     else n       puts( NO ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double pi = acos(-1.0); n int main() { n   int t; n   scanf( %d , &t); n   while (t--) { n     int n; n     scanf( %d , &n); n     long k; n     scanf( %ld , &k); n     int d; n     scanf( %d , &d); n     long arr[n]; n     for (int i = 0; i < n; i++) { n       cin >> arr[i]; n     } n     if (d == 1) { n       cout << 1 << endl; n     } else { n       set<long> con; n       unordered_map<long, int> cnt; n       for (int i = 0; i < d; i++) { n         con.insert(arr[i]); n         cnt[arr[i]]++; n       } n       long ans = con.size(); n       long final = con.size(); n       if (final == 1) { n         cout << 1 << endl; n       } else { n         for (int i = 0; i < n - d; i++) { n           cnt[arr[i]]--; n           if (cnt[arr[i]] == 0) { n             ans--; n           } n           cnt[arr[i + d]]++; n           if (cnt[arr[i + d]] == 1) { n             ans++; n           } n           final = min(final, ans); n         } n         cout << final << endl; n       } n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int T; n   cin >> T; n   while (T--) { n     long long a, b, n, m; n     scanf( %lld%lld%lld%lld , &a, &b, &n, &m); n     if (a < m || b < m) { n       printf( No n ); n       continue; n     } n     if ((a + b) < (m + n)) { n       printf( No n ); n       continue; n     } n     if (a <= b) { n       a -= m; n     } else { n       b -= m; n     } n     if (a + b >= n) { n       printf( Yes n ); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e4 + 10; n char scn[N][2]; n int l, x, mem; n string s; n int main() { n   l = 1; n   x = 25; n   cin >> s; n   for (int i = 1; i <= 10000; i++) { n     scn[i][1] =  . ; n   } n   mem = 0; n   l = 1; n   for (int i = 0; i < s.size(); i++) { n     while (mem != s[i]) { n       l++; n       scn[l][1] =  X ; n       l++; n       mem--; n       if (mem < 0) { n         mem = 256 + mem; n       } n     } n     scn[l][1] =  X ; n     l++; n   } n   for (int i = 1; i <= l; i++) { n     cout << scn[i][1] <<  .  <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int t; n int n, r; n int main() { n   scanf( %d , &t); n   while (t--) { n     scanf( %d %d , &n, &r); n     r--; n     int sum = 0; n     for (int i = 0; i < n - 1; i++) { n       int a; n       scanf( %d , &a); n       a--; n       sum = (sum + a) % n; n     } n     int res = (r - sum + n) % n; n     printf( %d n , res + 1); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int i, j, k, l, n, m, s; n int a[1000], b[1000]; n int main() { n   cin >> n >> m; n   for (i = 1; i <= n; i++) { n     cin >> l; n     a[l]++; n   } n   for (i = 1; i <= 110; i++) { n     s = 0; n     for (j = i; j <= i + m; j++) s = s + a[j]; n     k = max(k, s); n   } n   cout << n - k; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 1e9 + 7; n const int N = 1e5 + 5; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   ; n   long long int n; n   cin >> n; n   long long int brstr = 0; n   brstr += (n - 3) * (n - 4); n   brstr += 3 * (n - 3); n   cout << brstr + 1 <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n vector<long long> seive() { n   long long n = 2; n   vector<long long> pr(200000, -1); n   for (int i = n; i < 200000; i++) { n     if (pr[i] == -1) n       pr[i] = 1; n     else n       continue; n     for (int j = 2 * i; j < 200000; j += i) pr[j] = 0; n   } n   return pr; n } n long long powmod(long long a, long long b) { n   long long res = 1; n   a %= 1000000007; n   assert(b >= 0); n   for (; b; b >>= 1) { n     if (b & 1) res = res * a % 1000000007; n     a = a * a % 1000000007; n   } n   return res; n } n bool isprime(long long n) { n   bool flag = true; n   for (long long i = 2; i <= sqrt(n); i++) { n     if (n % i == 0) { n       flag = false; n       break; n     } n   } n   return flag; n } n long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } n long long lcm(long long a, long long b) { return a * b / gcd(a, b); } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   string s; n   cin >> s; n   vector<int> le, ri; n   int l = 0, r = s.size() - 1; n   while (l < r) { n     while (l < s.size() && s[l] ==  ) ) l++; n     while (r >= 0 && s[r] ==  ( ) r--; n     if (l < s.size() && r >= 0 && l < r) { n       le.push_back(l + 1); n       ri.push_back(r + 1); n       l++; n       r--; n     } n   } n   if (le.empty()) { n     cout <<  0 n ; n     return 0; n   } n   cout <<  1 n ; n   cout << 2 * le.size() <<   n ; n   for (auto x : le) cout << x <<    ; n   reverse(ri.begin(), ri.end()); n   for (auto x : ri) cout << x <<    ; n   cout <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e2 + 5, M = 2e4 + 5; n int a[105], b[300]; n int dp[105][M]; n int main() { n   int t; n   cin >> t; n   while (t--) { n     memset(dp, 0, sizeof(dp)); n     int n, k, l; n     scanf( %d %d %d , &n, &k, &l); n     for (int i = 1; i <= n; i++) cin >> a[i]; n     for (int i = 0; i <= k; i++) b[i] = i; n     for (int i = 1; i < k; i++) b[k + i] = k - i; n     for (int i = 0; i < 2 * k; i++) dp[0][i] = 1; n     for (int i = 1; i <= n; i++) n       for (int j = 0; j < 2 * k * n; j++) { n         dp[i][j] = max(dp[i][j - 1], dp[i - 1][j - 1]); n         if (l < b[j % (2 * k)] + a[i]) dp[i][j] = 0; n       } n     int flag = 0; n     for (int i = 0; i < 2 * k * n; i++) n       if (dp[n][i]) { n         flag = 1; n         break; n       } n     if (flag) n       printf( Yes n ); n     else n       printf( No n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a[24], n, Z[24]; n bool DP[24][(1 << 23) + 5]; n vector<int> X; n map<int, int> Memo; n int main() { n std: n   ios::sync_with_stdio(false); n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n     Memo[a[i]] = i + 1; n   } n   Z[0] = 1; n   DP[0][0] = 1; n   for (int i = 1; i < n; i++) { n     int b = 1 << i; n     for (int j = 1; j < b; j++) { n       if (j & (1 << (i - 1))) { n         int cnt = 0, ch = 0; n         for (int k = 0; k < i; k++) { n           if (j & 1 << k) { n             int P = a[i] - a[k]; n             if (Memo[P] != 0) { n               if (j & 1 << (Memo[P] - 1)) ch = 1; n             } n             cnt++; n           } n         } n         if (ch == 1) { n           int mmask = j & (~(1 << (i - 1))); n           if (DP[i - 1][mmask] == 1) ch = 2; n           for (int k = 0; k < i - 1; k++) { n             if (!(mmask & 1 << k)) { n               int mask = 1 << k; n               mask = mask | mmask; n               if (DP[i - 1][mask] == 1) ch = 2; n             } n           } n         } n         if (ch == 2) { n           DP[i][j] = 1; n           if (cnt < Z[i] || Z[i] == 0) Z[i] = cnt; n         } n       } n     } n   } n   int ans = 0; n   for (int i = 0; i < n; i++) { n     if (Z[i] == 0) { n       cout <<  -1 n ; n       return 0; n     } n     if (ans < Z[i]) ans = Z[i]; n   } n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long n; n   cin >> n; n   int v = 3 - n % 3, ans = 0; n   for (int i = v;; i += 3) { n     if (1LL * i * (i + 1) / 2 > (n + i) / 3) break; n     ++ans; n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n const int mod = 1e9 + 7, maxn = 1e6, maxm = 6; n int n, a[maxn], b[maxn], c[maxn], g[maxn], pw2[maxn], pw10[maxm]; n long long ans; n int main() { n   scanf( %d , &n); n   while (n--) { n     int x; n     scanf( %d , &x); n     ++a[x]; n     (b[x] += x) %= mod; n     c[x] = (1ll * x * x + c[x]) % mod; n   } n   pw2[0] = pw10[0] = 1; n   for (int i = 1; i < maxm; ++i) { n     pw2[i] = pw2[i - 1] << 1; n     pw10[i] = pw10[i - 1] * 10; n   } n   for (int i = maxm; i < maxn; ++i) { n     pw2[i] = (pw2[i - 1] << 1) % mod; n   } n   for (int j = 0; j < maxm; ++j) { n     for (int i = maxn - 1; ~i; --i) { n       if (i / pw10[j] % 10 < 9) { n         (a[i] += a[i + pw10[j]]) %= mod; n         (b[i] += b[i + pw10[j]]) %= mod; n         (c[i] += c[i + pw10[j]]) %= mod; n       } n     } n   } n   for (int i = 0; i < maxn; ++i) { n     if (a[i] >= 1) { n       g[i] = (1ll * c[i] * pw2[a[i] - 1] + g[i]) % mod; n       if (a[i] >= 2) { n         g[i] = ((1ll * b[i] * b[i] - c[i]) % mod * pw2[a[i] - 2] + g[i]) % mod; n       } n     } n   } n   for (int j = 0; j < maxm; ++j) { n     for (int i = 0; i < maxn; ++i) { n       if (i / pw10[j] % 10 < 9) { n         (g[i] -= g[i + pw10[j]]) %= mod; n       } n     } n   } n   for (int i = 0; i < maxn; ++i) { n     ans ^= 1ll * (g[i] + mod) % mod * i; n   } n   printf( %lld n , ans); n   return 0; n } n


/* -> Written by <- n    ----------- n   |K_A_Z_A_M_A| n   |___________| n   |    ___    | n   |   (^_^)   | n   |  /( | )  | n   |____|_|____| n     H O A N G n */ n  n #include <bits/stdc++.h> n  n #define Task             running  n #define F               first n #define S               second n #define pb              push_back n #define bit(x, i)       ((x >> (i)) & 1) n #define inf             1e9 + 7 n #define INF             1e18 + 7 n #define ll              long long n #define pii             pair <int, int> n #define debug(x)        cerr << #x <<   is   << x <<   n ; n  n using namespace std; n  n const int MOD = 1e9 + 7; n const int maxn = 1e5 + 5; n const int base = 3e5 + 1; n  n int n; n pair <int, int> a[200005]; n  n int CalDis(int r1, int c1, int r2, int c2) { n     if (r1 - c1 == r2 - c2) { n         if ((r1 + c1) % 2 == 0) return r2 - r1; n         return 0; n     } n     int newr = r2 - c2 + c1; n     int newc = c1; n     int x = newr - r1; n     if ((newr + newc) % 2) return x / 2; n     return (x + 1) / 2; n } n  n void Solve() { n     cin >> n; n     for (int i = 1; i <= n; ++ i) { n         cin >> a[i].F; n     } n     for (int i = 1; i <= n; ++ i) { n         cin >> a[i].S; n     } n     sort(a + 1, a + 1 + n); n     int r1 = 1, c1 = 1; n     ll res = 0; n     for (int i = 1; i <= n; ++ i) { n         int r2 = a[i].F; n         int c2 = a[i].S; n         res += CalDis(r1, c1, r2, c2); n         c1 = c2; n         r1 = r2; n     } n     cout << res <<   n ; n } n  n int main(){ n     ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); n     if (fopen(Task .inp ,  r )){ n         freopen(Task .inp ,  r , stdin); n         freopen(Task .out ,  w , stdout); n     } n //    Prepare(); n     int test_case = 1; n     cin >> test_case; n     while (test_case --){ n         Solve(); n     } n     return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long int min(long long int a, long long int b) { return a < b ? a : b; } n int getMedian(int ai[100001], int n) { n   map<int, int> m; n   for (int i = 0; i < n; i++) { n     if (m.find(ai[i]) != m.end()) { n       m[ai[i]] = m[ai[i]] + 1; n     } else n       m[ai[i]] = 1; n   } n   int temp = (m.size() - 1) / 2, k = 0, median; n   for (map<int, int>::iterator it = m.begin(); k <= temp; ++it, ++k) { n     median = it->first; n   } n   return median; n } n int main() { n   int n, ai[100001]; n   bool isPossible; n   scanf(  n%d , &n); n   for (int i = 0; i < n; i++) scanf(  n%d , &ai[i]); n   int median = getMedian(ai, n); n   bool isDiffSet = false; n   int globalDiff, diff; n   isPossible = true; n   for (int i = 0; i < n; i++) { n     diff = ai[i] - median < 0 ? median - ai[i] : ai[i] - median; n     if (!diff) continue; n     if (isDiffSet) { n       if (diff != globalDiff) { n         isPossible = false; n         break; n       } n     } else { n       globalDiff = diff; n       isDiffSet = true; n     } n   } n   printf( %s n , isPossible ?  YES  :  NO ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int v, e; n   cin >> v >> e; n   vector<set<int> > g(v); n   int a, b; n   for (int i = 0; i < e; i++) { n     cin >> a >> b; n     g[a - 1].insert(b - 1); n     g[b - 1].insert(a - 1); n   } n   int ans = 0; n   while (1) { n     vector<int> ve; n     for (int i = 0; i < v; i++) { n       if (g[i].size() == 1) { n         ve.push_back(i); n       } n     } n     for (int i = 0; i < ve.size(); i++) { n       set<int>::iterator it = g[ve[i]].begin(); n       g[ve[i]].clear(); n       g[*it].erase(ve[i]); n     } n     if (ve.size()) n       ans++; n     else n       break; n   } n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int A[100010]; n int B[100010]; n int C[100010]; n int main() { n   int n; n   scanf( %d , &n); n   int m, k; n   scanf( %d%d , &m, &k); n   for (int i = 0; i < m; i++) { n     scanf( %d%d%d , A + i, B + i, C + i); n   } n   long long sum = 0; n   for (int i = 0; i < k; i++) { n     int take; n     scanf( %d , &take); n     for (int t = 0; t < m; t++) { n       if (take >= A[t] && take <= B[t]) sum += (C[t] + take - A[t]); n     } n   } n   printf( %I64d n , sum); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, temp, sum = 0; n   cin >> n; n   int arr[n]; n   memset(arr, 0, sizeof(arr)); n   for (int i = 0; i < n; i++) { n     cin >> arr[i]; n     sum += arr[i]; n     if (i == 0) n       temp = arr[0]; n     else if (arr[i] > temp) n       temp = arr[i]; n   } n   while (((temp * n) - sum) <= sum) { n     temp++; n   } n   cout << temp; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 10000; n const int MAXM = 100000; n const int INF = 0x3f3f3f3f; n pair<int, int> nxt[3][3]; n int cot[3][3]; n map<pair<int, int>, pair<long long, long long> > ma; n int main() { n   long long k; n   int a, b; n   scanf( %I64d%d%d , &k, &a, &b); n   a--, b--; n   for (int i = 0; i < 3; i++) { n     for (int j = 0; j < 3; j++) { n       int x; n       scanf( %d , &x); n       x--; n       nxt[i][j].first = x; n     } n   } n   for (int i = 0; i < 3; i++) { n     for (int j = 0; j < 3; j++) { n       int x; n       scanf( %d , &x); n       x--; n       nxt[i][j].second = x; n     } n   } n   pair<int, int> s = pair<int, int>(a, b); n   pair<long long, long long> now = pair<long long, long long>(0, 0); n   int cc = 0; n   while (ma.count(s) == 0) { n     if (k == 0) break; n     k--; n     cot[s.first][s.second] = cc++; n     ma[s] = now; n     if ((s.first + 1) % 3 == s.second) n       now.second++; n     else if (s.first == (1 + s.second) % 3) n       now.first++; n     s = nxt[s.first][s.second]; n   } n   if (ma.count(s)) { n     pair<long long, long long> ans = now; n     now.first -= ma[s].first; n     now.second -= ma[s].second; n     long long lun = cc - cot[s.first][s.second]; n     long long kk = k / lun; n     k %= lun; n     ans.first += now.first * kk; n     ans.second += now.second * kk; n     now = pair<long long, long long>(0, 0); n     while (k--) { n       if ((s.first + 1) % 3 == s.second) n         now.second++; n       else if (s.first == (1 + s.second) % 3) n         now.first++; n       s = nxt[s.first][s.second]; n     } n     ans.first += now.first; n     ans.second += now.second; n     printf( %I64d %I64d n , ans.first, ans.second); n   } else { n     s = nxt[s.first][s.second]; n     printf( %I64d %I64d n , now.first, now.second); n   } n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n inline T GCD(T a, T b) { n   return b ? GCD(b, a % b) : a; n } n template <class T> n inline T LCM(T a, T b) { n   if (a < 0) return LCM(-a, b); n   if (b < 0) return LCM(a, -b); n   return a * (b / GCD(a, b)); n } n int main() { n   int n, s; n   cin >> n >> s; n   int dol[n]; n   int cent[n]; n   int sweet = 0; n   int y = 0; n   int flag = 0; n   for (int i = 0; i < n; i++) { n     cin >> dol[i] >> cent[i]; n     if (cent[i] != 0) n       sweet = 100 - cent[i]; n     else n       sweet = 0; n     if (dol[i] < s || (dol[i] == s && cent[i] == 0)) { n       flag = 1; n       if (y < sweet) { n         y = sweet; n       } n     } n   } n   if (flag == 0) n     cout <<  -1  << endl; n   else n     cout << y << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 1000100; n int bit[MAXN]; n int main() { n   ios::sync_with_stdio(false); n   int n; n   cin >> n; n   for (int i = 0; i < n; ++i) { n     int w; n     cin >> w; n     bit[w]++; n   } n   int step = 0; n   for (int i = 0; i < MAXN - 1; ++i) { n     bit[i + 1] += bit[i] / 2; n     bit[i] %= 2; n     step += bit[i]; n   } n   cout << step << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2e5 + 10, mod = 1e9 + 7; n int ans[N], a[N]; n vector<pair<int, int> > v; n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int n, m; n   cin >> n >> m; n   long long sum = 0; n   for (int i = 0; i < m; i++) { n     cin >> a[i]; n     sum += a[i]; n   } n   if (sum < n) return cout << -1, 0; n   int cur = 0; n   for (int i = 0; i < m; i++) { n     if (n - cur < a[i]) return cout << -1, 0; n     ans[i] = cur; n     sum -= a[i]; n     cur++; n     a[i]--; n     while (a[i] && n - cur > sum) cur++, a[i]--; n   } n   for (int i = 0; i < m; i++) cout << ans[i] + 1 <<    ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long maxn = 1e5 + 5; n const long long mod = 1e9 + 7; n const double eps = 1e-9; n const double pi = acos(-1.0); n const long long inf = 0x3f3f3f3f; n long long n, m; n long long a[maxn]; n long long s1[maxn], s2[maxn]; n long long sum1[maxn], sum2[maxn]; n int main() { n   cin >> n >> m; n   a[1] = 0; n   for (long long i = 2; i <= n + 1; i++) scanf( %lld , &a[i]); n   a[n + 2] = m; n   n++, n++; n   long long k1 = 1, k2 = 1; n   for (long long i = 1; i < n; i += 2) { n     s1[k1++] = a[i + 1] - a[i]; n   } n   for (long long i = 2; i < n; i += 2) { n     s2[k2++] = a[i + 1] - a[i]; n   } n   for (long long i = 1; i < k1; i++) sum1[i] = sum1[i - 1] + s1[i]; n   for (long long i = 1; i < k2; i++) sum2[i] = sum2[i - 1] + s2[i]; n   long long ans = sum1[k1 - 1]; n   for (long long i = 1; i < n; i++) { n     long long sum = 0; n     if ((a[i + 1] - a[i] != 1) && (i % 2 != 0)) { n       sum += sum1[i / 2] + a[i + 1] - 1 - a[i]; n       long long num = n - i; n       long long nn = n; n       if (num % 2) nn--; n       sum += sum2[nn / 2] - sum2[i / 2]; n     } else if (a[i + 1] - a[i] != 1 && (i % 2 == 0)) { n       sum += sum1[i / 2] + a[i + 1] - (a[i] + 1); n       long long num = n - (i + 1); n       long long nn = n; n       if (num % 2) nn--; n       sum += sum2[nn / 2] - sum2[i / 2]; n     } n     ans = max(ans, sum); n   } n   printf( %lld n , ans); n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( Ofast ) n #pragma GCC target( avx,avx2,fma ) n #pragma GCC optimization( unroll-loops ) n using namespace std; n void solve() { n   long long n; n   cin >> n; n   vector<long long> a(n); n   for (auto &x : a) cin >> x; n   if (*min_element(a.begin(), a.end()) == 1) { n     cout << n + 1 <<    ; n     for (long long i = 1; i <= n; i++) cout << i <<    ; n   } else { n     long long k; n     for (long long i = n - 1; i >= 0; i--) { n       if (!a[i]) { n         k = i; n         break; n       } n     } n     for (long long i = 0; i <= k; i++) cout << i + 1 <<    ; n     cout << n + 1 <<    ; n     for (long long i = k + 1; i <= n - 1; i++) cout << i + 1 <<    ; n   } n   cout <<   n ; n } n signed main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long t; n   cin >> t; n   while (t--) solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 2e5 + 10; n set<int> s; n int n, t; n char a[maxn]; n int pos; n int main() { n   register int i, tail, g; n   scanf( %d%d , &n, &t); n   scanf( %s , a + 1); n   for (i = 1; i <= n; i++) n     if (a[i] ==  . ) { n       pos = i; n       break; n     } n   g = pos; n   for (i = pos; i <= n; i++) n     if (a[i] >=  5 ) { n       g = i; n       break; n     } n   a[0] =  0 ; n   bool f; n   tail = n; n   while (t-- && (g > pos && a[g] >=  5 )) { n     a[g] =  0 ; n     tail = g; n     if (g != pos + 1) { n       a[g - 1]++; n       f = true; n       g = g - 1; n     } else { n       a[g - 2]++; n       g = g - 2; n     } n     while (g >= 0 && a[g] ==  : ) { n       if (g - 1 == pos) { n         a[g] =  0 ; n         a[g - 2]++; n         g -= 2; n       } else { n         a[g] =  0 ; n         a[g - 1]++; n         --g; n       } n     } n   } n   if (a[0] !=  0 ) printf( %c , a[0]); n   for (i = 1; i < pos; i++) printf( %c , a[i]); n   while (a[tail] ==  0 ) --tail; n   if (tail != pos) { n     printf( %c , 46); n     for (i = pos + 1; i <= tail; i++) printf( %c , a[i]); n   } n   puts(  ); n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T, typename U> n inline void smin(T &a, const U &b) { n   if (a > b) a = b; n } n template <typename T, typename U> n inline void smax(T &a, const U &b) { n   if (a < b) a = b; n } n int a[2020]; n struct Dinic { n   int V, E, src, tar; n   int head[2020], work[2020], dis[2020]; n   int to[8080], nxt[8080]; n   long long cap[8080]; n   int q[2020], qf, qb; n   void init(int n, int s, int t) { n     V = n + 1; n     E = 0; n     src = s; n     tar = t; n     for (int i = 0; i <= V; i++) head[i] = -1; n   } n   void add(int u, int v, long long c) { n     to[E] = v; n     cap[E] = c; n     nxt[E] = head[u]; n     head[u] = E++; n     to[E] = u; n     cap[E] = 0; n     nxt[E] = head[v]; n     head[v] = E++; n   } n   bool bfs() { n     for (int i = 0; i <= V; i++) dis[i] = -1; n     qf = qb = 0; n     q[qb++] = src; n     dis[src] = 0; n     while (qf < qb && dis[tar] == -1) { n       int u = q[qf++]; n       for (int i = head[u]; i >= 0; i = nxt[i]) { n         int v = to[i]; n         if (dis[v] == -1 && cap[i] > 0) { n           dis[v] = dis[u] + 1; n           q[qb++] = v; n         } n       } n     } n     return dis[tar] >= 0; n   } n   long long dfs(int u, long long &bot) { n     int v; n     long long bot1, delta; n     if (u == tar) return bot; n     for (int &i = work[u]; i >= 0; i = nxt[i]) { n       int v = to[i]; n       if (dis[v] != dis[u] + 1 || cap[i] == 0) continue; n       bot1 = min(bot, cap[i]); n       if (delta = dfs(v, bot1)) { n         cap[i] -= delta; n         cap[i ^ 1] += delta; n         bot = bot1; n         return delta; n       } n     } n     return 0; n   } n   long long dinic() { n     long long ans = 0, delta, bot; n     while (bfs()) { n       memcpy(work, head, sizeof(int) * V); n       delta = 0x3f3f3f3f3f3f3f3fLL; n       while (delta = dfs(src, bot = 0x3f3f3f3f3f3f3f3fLL)) ans += delta; n     } n     return ans; n   } n } dinic; n int main() { n   int n, m; n   scanf( %d %d , &n, &m); n   int src = n + m + 1, tar = src + 1; n   dinic.init(tar, src, tar); n   for (int i = 1; i <= n; i++) { n     scanf( %d , a + i); n     dinic.add(src, i, a[i]); n   } n   long long ans = 0; n   for (int i = n + 1, u, v, w; i <= n + m; i++) { n     scanf( %d %d %d , &u, &v, &w); n     dinic.add(u, i, 0x3f3f3f3f3f3f3f3fLL); n     dinic.add(v, i, 0x3f3f3f3f3f3f3f3fLL); n     dinic.add(i, tar, w); n     ans += w; n   } n   printf( %I64d n , ans - dinic.dinic()); n } n


#include <bits/stdc++.h> n using namespace std; n const double eps = 0.000001; n const long double pi = acos(-1); n const int maxn = 1e7 + 9; n const int mod = 1e9 + 7; n const long long MOD = 1e18 + 9; n const long long INF = 1e18 + 123; n const int inf = 2e9 + 11; n const int mxn = 1e6 + 9; n const int N = 1e6 + 123; n const int M = 22; n const int pri = 997; n const int Magic = 2101; n const int dx[] = {-1, 0, 1, 0}; n const int dy[] = {0, -1, 0, 1}; n int n, m, k; n int cnt[N]; n string s; n int a[N]; n vector<int> g[N]; n int u[N]; n int ans, res; n int cur; n long long fac[N]; n long long bpow(long long a, long long b) { n   long long res = 1; n   while (b > 0) { n     if (b & 1) (res *= a) %= mod; n     b /= 2; n     a *= a; n     a %= mod; n   } n   return res; n } n inline void upd(long long &ans, long long l, long long r) { n   ans *= fac[r]; n   ans %= mod; n   ans = (ans * bpow(fac[l - 1], mod - 2)) % mod; n } n inline long long calc(vector<int> &pw) { n   long long ans = 1, pref = 0; n   vector<long long> f; n   for (auto e : pw) { n     f.push_back((n / e) - pref); n     (ans *= f.back()) %= mod; n     pref = n / e; n   } n   long long cur = 1; n   for (int i = (int)(pw.size()) - 1; ~i; --i) { n     upd(ans, cur, cur + f[i] - 2); n     cur += f[i]; n   } n   return ans; n } n int main() { n   ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); n   cin >> n; n   vector<int> pw; n   pw.push_back(1); n   while (pw.back() * 2 <= n) { n     pw.push_back(pw.back() * 2); n   } n   reverse(pw.begin(), pw.end()); n   fac[0] = 1; n   for (int i = 1; i <= n; i++) fac[i] = (fac[i - 1] * i) % mod; n   long long ans = calc(pw); n   if (pw[0] * 3ll <= n * 2ll) { n     for (int i = 1; i < (int)(pw.size()); i++) { n       vector<int> o = pw; n       for (int j = 0; j < i; j++) { n         o[j] = 3ll * o[j] / 2ll; n       } n       ans += calc(o); n       if (ans >= mod) ans -= mod; n     } n   } n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 0x3f3f3f3f; n const int maxn = 100005; n int a[maxn], lefts[maxn], rights[maxn]; n int main() { n   int n, l, r, q1, q2; n   cin >> n >> l >> r >> q1 >> q2; n   memset(lefts, 0, sizeof(lefts)); n   memset(rights, 0, sizeof(rights)); n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n     lefts[i + 1] += (lefts[i] + a[i]); n   } n   for (int i = n - 1; i >= 0; i--) { n     rights[n - i] += (rights[n - i - 1] + a[i]); n   } n   int sum = 0, ans = INF; n   for (int i = 0; i <= n; i++) { n     sum = 0; n     sum += ((lefts[i] * l) + rights[n - i] * r); n     if (i > (n - i)) n       sum += ((2 * i - n - 1) * q1); n     else if (i < (n - i)) n       sum += ((n - 2 * i - 1) * q2); n     ans = min(ans, sum); n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( Ofast ) n #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma ) n #pragma GCC optimize( unroll-loops ) n using namespace std; n double eps = 1e-12; n long long hcf(long long p, long long q) { n   if (p > q) return hcf(q, p); n   if (!p) return q; n   return hcf(q % p, p); n } n long long lcm(long long p, long long q) { return p * q / hcf(p, q); } n long long power(long long a, long long n, long long mod) { n   long long ans = 1; n   while (n) { n     if (n % 2) ans *= a; n     a *= a; n     n /= 2; n     a %= mod; n     ans %= mod; n   } n   return ans; n } n long long fac(long long k, long long mod) { n   long long ans = 1; n   for (long long i = 1; i < k + 1; i++) { n     ans *= i; n     ans %= mod; n   } n   return ans; n } n void solve() { n   long long a, b, c; n   cin >> a >> b >> c; n   long long k = a - b; n   if (k + c > 0 && k - c > 0) n     cout <<  + ; n   else if (k + c < 0 && k - c < 0) n     cout <<  - ; n   else if (k + c == 0 && k - c == 0) n     cout << 0; n   else n     cout <<  ? ; n   return; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long a[100005], b[100005]; n const long long INF = 1000000009; n int main() { n   int n, x, y; n   cin >> n >> x >> y; n   for (int i = 0; i < n; i++) cin >> a[i]; n   for (int i = 0; i < n; i++) b[i] = INF; n   for (int i = 0; i < n; i++) n     for (int j = i - y; j <= i + x && j < n; j++) n       if (j >= 0 && j != i) b[j] = min(a[i], b[j]); n   int k = 0; n   while (b[k] < a[k]) k++; n   cout << k + 1; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int w1, h1, w2, h2, s; n int main() { n   cin >> w1 >> h1 >> w2 >> h2; n   s = 2 * (h1 + h2 + w1 + 2); n   cout << s << endl; n } n


#include <bits/stdc++.h> n int main() { n   int n, m, i, a; n   int f[105] = {0}; n   scanf( %d%d , &n, &m); n   while (m--) { n     scanf( %d , &a); n     for (i = a; i <= n; i++) n       if (f[i] == 0) f[i] = a; n   } n   for (i = 1; i < n; i++) printf( %d  , f[i]); n   printf( %d n , f[n]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n string s, p; n vector<int> a, b, x, y; n int main() { n   cin >> s >> p; n   a.push_back(0); n   b.push_back(0); n   x.push_back(0); n   y.push_back(0); n   for (int i = 0; i < s.size(); i++) { n     a.push_back(a[a.size() - 1]); n     x.push_back(x[x.size() - 1]); n     if (s[i] !=  A ) { n       a[a.size() - 1]++; n       x[x.size() - 1] = i + 1; n     } n   } n   for (int i = 0; i < p.size(); i++) { n     b.push_back(b[b.size() - 1]); n     y.push_back(y[y.size() - 1]); n     if (p[i] !=  A ) { n       b[b.size() - 1]++; n       y[y.size() - 1] = i + 1; n     } n   } n   int q; n   int r1, r2; n   cin >> q; n   int i, j, k, l; n   int moze; n   for (; q > 0; q--) { n     moze = 1; n     cin >> i >> j >> k >> l; n     if ((b[l] - b[k - 1]) - (a[j] - a[i - 1]) < 0) { n       moze = 0; n     } n     if (((b[l] - b[k - 1]) - (a[j] - a[i - 1])) % 2 != 0) { n       moze = 0; n     } n     r2 = l - y[l]; n     r1 = j - x[j]; n     if (r1 > j - i + 1) r1 = j - i + 1; n     if (r2 > l - k + 1) r2 = l - k + 1; n     if (r1 < r2) { n       moze = 0; n     } else if ((a[j] - a[i - 1]) == 0 && (b[l] - b[k - 1]) > 0 && r1 == r2) n       moze = 0; n     else { n       if ((r1 - r2) % 3 != 0 && (b[l] - b[k - 1]) - (a[j] - a[i - 1]) == 0) { n         moze = 0; n       } n     } n     cout << moze; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 200005; n const int mod = 1e9 + 7; n const double eps = 1e-8; n const double PI = acos(-1.0); n int a[N], l[N], r[N], d[N], cha[N]; n int m, n, k, t; n bool check(int x) { n   if (!x) return true; n   for (int i = 0; i <= n + 1; i++) cha[i] = 0; n   int g = a[x]; n   for (int i = 1; i <= k; i++) { n     if (d[i] > g) { n       cha[l[i]]++, cha[r[i] + 1]--; n     } n   } n   int res = 0; n   for (int i = 1; i <= n + 1; i++) { n     cha[i] += cha[i - 1]; n     if (cha[i] > 0) res++; n   } n   return res * 2 + n + 1 <= t; n } n int main() { n   std::ios::sync_with_stdio(false); n   cin >> m >> n >> k >> t; n   for (int i = 1; i <= m; i++) cin >> a[i]; n   sort(a + 1, a + 1 + m, greater<int>()); n   for (int i = 1; i <= k; i++) cin >> l[i] >> r[i] >> d[i]; n   int L = 0, R = m, M, ans = 0; n   while (L <= R) { n     M = (L + R) >> 1; n     if (check(M)) { n       ans = M; n       L = M + 1; n     } else n       R = M - 1; n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, k, Count = 0, a[2005], Free[2005]; n vector<int> V; n int main() { n   cin >> n >> k; n   for (int i = 1; i <= n; i++) { n     cin >> a[i]; n     if (a[i] <= k) n       Free[a[i]]++; n     else n       V.push_back(i); n   } n   for (int i = 1; i <= k; i++) n     while (V.size() > 0 && Free[i] < n / k) { n       Free[i]++; n       Count++; n       a[V.back()] = i; n       V.pop_back(); n     } n   for (int i = 1; i <= k; i++) n     if (Free[i] < n / k) { n       for (int j = 1; j <= n; j++) n         if (Free[a[j]] > n / k) { n           Free[a[j]]--; n           Free[i]++; n           Count++; n           a[j] = i; n           if (Free[i] == n / k) break; n         } n     } n   cout << n / k <<     << Count <<   n ; n   for (int i = 1; i <= n; i++) cout << a[i] <<    ; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 35; n const int MOD = 1e9 + 7; n long long n; n int K, c, res; n struct mat { n   int d[N][N]; n   mat() { memset(d, 0, sizeof d); } n } F[N * 2][N], P[N * 2][N], Q[N * 2][N], G; n int lst[N * 2]; n mat operator*(mat a, mat b) { n   mat c; n   for (int i = 0; i <= K; ++i) n     for (int j = 0; j <= K; ++j) n       for (int k = 0; k <= K; ++k) n         c.d[i][k] = (c.d[i][k] + 1ll * a.d[i][j] * b.d[j][k]) % MOD; n   return c; n } n int main() { n   cin >> n >> K; n   while (n) lst[c++] = n % K, n /= K; n   for (int i = 0; i < c; ++i) { n     if (i == 0) { n       for (int j = 0; j < K; ++j) { n         for (int p = 0; p < K; ++p) F[i][j].d[p][p] = 1; n         for (int p = 0; p <= K; ++p) F[i][j].d[j][p] = 1; n         F[i][j].d[K][K] = 1; n       } n     } else { n       for (int j = 1; j < K; ++j) F[i][j] = Q[i - 1][j] * P[i - 1][j - 1]; n       F[i][0] = Q[i - 1][0]; n     } n     P[i][0] = F[i][0]; n     for (int j = 1; j < K; ++j) P[i][j] = P[i][j - 1] * F[i][j]; n     Q[i][K - 1] = F[i][K - 1]; n     for (int j = K - 2; ~j; --j) Q[i][j] = F[i][j] * Q[i][j + 1]; n   } n   for (int i = 0; i <= K; ++i) G.d[i][i] = 1; n   for (int i = c - 1, s = 0; ~i; --i) { n     for (int j = 0; j < lst[i]; ++j) G = G * F[i][(s + j) % K]; n     s = (s + lst[i]) % K; n   } n   res = 1; n   for (int i = 0; i < K; ++i) res = (res + G.d[i][K]) % MOD; n   cout << res << endl; n } n


#include <bits/stdc++.h> n using namespace std; n long long aabs(long long a) { n   if (a < 0) n     return -a; n   else n     return a; n } n struct node { n   long long num; n   int id; n   bool operator<(const node &a) const { return aabs(num) > aabs(a.num); } n }; n long long a[200005]; n long long n, k, x; n int main() { n   int i; n   scanf( %I64d%I64d%I64d , &n, &k, &x); n   int sign = 1; n   priority_queue<node> que; n   for (i = 1; i <= n; i++) { n     scanf( %I64d , &a[i]); n     if (a[i] < 0) sign = -sign; n     que.push((node){a[i], i}); n   } n   while (k--) { n     node temp = que.top(); n     que.pop(); n     if (a[temp.id] < 0) { n       if (sign == -1) n         a[temp.id] -= x; n       else n         a[temp.id] += x; n       if (a[temp.id] >= 0) sign = -sign; n     } else { n       if (sign == -1) n         a[temp.id] += x; n       else n         a[temp.id] -= x; n       if (a[temp.id] < 0) sign = -sign; n     } n     que.push((node){a[temp.id], temp.id}); n   } n   for (i = 1; i < n; i++) { n     printf( %I64d  , a[i]); n   } n   printf( %I64d n , a[n]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long const N = 1e5 + 100, INF = 1ll * 1e9 * 1e9 + 100; n long long n, m, s, t; n long long h[N], d[N], dis[2][N], ans[N]; n pair<pair<long long, long long>, long long> e[N]; n vector<long long> f[N], g[N]; n set<pair<long long, long long> > st; n bool vis[N]; n void dij(bool b, long long s) { n   dis[b][s] = 0; n   st.insert({0, s}); n   while (st.size()) { n     long long v = st.begin()->second; n     st.erase(st.begin()); n     for (long long i : g[v]) { n       long long u = e[i].first.first + e[i].first.second - v, w = e[i].second; n       if (b ^ (u != e[i].first.second)) continue; n       if (dis[b][v] + w < dis[b][u]) { n         st.erase({dis[b][u], u}); n         dis[b][u] = dis[b][v] + w; n         st.insert({dis[b][u], u}); n       } n     } n   } n } n void cut_edge(long long v = 0, long long i = -1) { n   long long p = (~i ? e[i].first.first + e[i].first.second - v : -1); n   vis[v] = 1; n   d[v] = h[v]; n   for (long long j : f[v]) { n     long long u = e[j].first.first + e[j].first.second - v; n     if (vis[u]) { n       if (i != j) { n         ans[j] = 1; n         d[v] = min(d[v], h[u]); n         if (h[u] == h[p]) ans[i] = 1; n       } n       continue; n     } n     h[u] = h[v] + 1; n     cut_edge(u, j); n     if (d[u] != h[u]) ans[j] = 1; n     d[v] = min(d[v], d[u]); n   } n } n int32_t main() { n   ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); n   fill(d, d + N, INF); n   fill(dis[0], dis[0] + N, INF); n   fill(dis[1], dis[1] + N, INF); n   cin >> n >> m >> s >> t; n   s--, t--; n   for (long long i = 0, u, v, w; i < m; i++) { n     cin >> u >> v >> w; n     u--, v--; n     e[i] = {{u, v}, w}; n     g[u].push_back(i); n     g[v].push_back(i); n   } n   dij(0, s), dij(1, t); n   for (long long i = 0; i < m; i++) { n     long long u = e[i].first.first, v = e[i].first.second, w = e[i].second; n     long long path = dis[0][u] + w + dis[1][v]; n     if (path == dis[0][t]) { n       f[u].push_back(i); n       f[v].push_back(i); n     } else { n       ans[i] = path - dis[0][t] + 1; n     } n   } n   cut_edge(s); n   for (long long i = 0; i < m; i++) { n     long long w = e[i].second; n     if (w - ans[i] <= 0) n       cout <<  NO n ; n     else if (!ans[i]) n       cout <<  YES n ; n     else n       cout <<  CAN   << ans[i] <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int a, b, c, d; n   cin >> a >> b >> c >> d; n   if (abs(a + c - b - d) > 1) { n     cout <<  NO n ; n   } else { n     vector<int> v(a + b + c + d); n     if (a + c > b + d) { n       for (int i = 0; i < v.size(); i += 2) { n         if (a) { n           v[i] = 0; n           a--; n         } else { n           v[i] = 2; n           c--; n         } n       } n       for (int i = 1; i < v.size(); i += 2) { n         if (b) { n           v[i] = 1; n           b--; n         } else { n           v[i] = 3; n           d--; n         } n       } n     } else { n       for (int i = 1; i < v.size(); i += 2) { n         if (a) { n           v[i] = 0; n           a--; n         } else { n           v[i] = 2; n           c--; n         } n       } n       for (int i = 0; i < v.size(); i += 2) { n         if (b) { n           v[i] = 1; n           b--; n         } else { n           v[i] = 3; n           d--; n         } n       } n     } n     bool check = true; n     for (int i = 0; i < (int)v.size() - 1; i++) { n       if (abs(v[i] - v[i + 1]) != 1) { n         check = false; n         break; n       } n     } n     if (a + c == b + d && check == false) { n       for (int i = 0; i < (int)v.size() - 1; i += 2) { n         swap(v[i], v[i + 1]); n       } n       check = true; n       for (int i = 0; i < (int)v.size() - 1; i++) { n         if (abs(v[i] - v[i + 1]) != 1) { n           check = false; n           break; n         } n       } n     } n     if (check) { n       cout <<  YES n ; n       for (int i : v) cout << i <<    ; n       cout <<   n ; n     } else n       cout <<  NO ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n string S; n vector<vector<vector<int> > > cc; n int dp(int idx, int d, int s) { n   int &ret = cc[idx][d][s]; n   if (ret != -1) return ret; n   if (idx == S.size() / 2) { n     if (S.size() % 2) { n       int x = S[idx] -  0 ; n       if ((10 * d + x - s) < 0 || (x - s) % 2) n         return 0; n       else n         return 1; n     } else n       return d == s; n   } n   ret = 0; n   for (int i = idx == 0; i <= 18; i++) { n     int x = S[idx] -  0 ; n     if ((s + i) % 10 != x) continue; n     int y = S[S.size() - 1 - idx] -  0 ; n     if (10 * d + y - i != 0 && 10 * d + y - i != 1) continue; n     ret |= dp(idx + 1, 10 * d + y - i, i + s >= 10); n   } n   return ret; n } n vector<int> A; n void dfs(int idx, int d, int s) { n   if (idx == S.size() / 2) { n     if (S.size() % 2) { n       int x = S[idx] -  0 ; n       A[idx] = (10 * d + x - s) / 2; n       return; n     } else n       return; n   } n   for (int i = idx == 0; i <= 18; i++) { n     int x = S[idx] -  0 ; n     if ((s + i) % 10 != x) continue; n     int y = S[S.size() - 1 - idx] -  0 ; n     if (10 * d + y - i != 0 && 10 * d + y - i != 1) continue; n     if (dp(idx + 1, 10 * d + y - i, i + s >= 10)) { n       A[idx] = i / 2; n       A[S.size() - 1 - idx] = i - i / 2; n       dfs(idx + 1, 10 * d + y - i, i + s >= 10); n       return; n     } n   } n } n int main() { n   cin >> S; n   reverse(S.begin(), S.end()); n   cc = vector<vector<vector<int> > >( n       S.size(), vector<vector<int> >(2, vector<int>(2, -1))); n   if (dp(0, 0, 0)) { n     A.resize(S.size()); n     dfs(0, 0, 0); n     reverse(A.begin(), A.end()); n     for (int i = 0; i < A.size(); i++) { n       printf( %d , A[i]); n     } n     return 0; n   } n   if (S[S.size() - 1] !=  1 ) { n     printf( 0 ); n     return 0; n   } n   S.erase(S.end() - 1); n   cc = vector<vector<vector<int> > >( n       S.size() + 1, vector<vector<int> >(2, vector<int>(2, -1))); n   if (dp(0, 1, 0)) { n     A.resize(S.size()); n     dfs(0, 1, 0); n     reverse(A.begin(), A.end()); n     for (int i = 0; i < A.size(); i++) { n       printf( %d , A[i]); n     } n     return 0; n   } n   printf( 0 ); n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 100105; n const double eps = 1e-6; n long double x1, y1_, x2, y2, mx, my, vx, vy, d, L, ans = 1e16; n vector<pair<long double, int> > V; n int X[N], Y[N], R[N], n, s = 0; n long double check(int k, long double t, int op) { n   return ((sqrt(d * d + t * t) + op * R[k]) * n           (sqrt(d * d + t * t) + op * R[k])) - n          ((X[k] - mx - vx * t) * (X[k] - mx - vx * t)) - n          ((Y[k] - my - vy * t) * (Y[k] - my - vy * t)); n } n long double BI(int k, int op) { n   long double l = -1e12, r = 1e12, mid, c = check(k, l, op), cc; n   while (r - l > eps) { n     mid = (l + r) / 2, cc = check(k, mid, op); n     (c > 0 && cc > 0 || c < 0 && cc < 0) ? l = mid : r = mid; n   } n   return (l + r) / 2; n } n int main() { n   scanf( %Lf%Lf%Lf%Lf%d , &x1, &y1_, &x2, &y2, &n); n   for (int i = (1); i <= (n); ++i) scanf( %d%d%d , &X[i], &Y[i], &R[i]); n   mx = (x1 + x2) / 2, my = (y1_ + y2) / 2, n   L = sqrt(((x1 - x2) * (x1 - x2)) + ((y1_ - y2) * (y1_ - y2))), n   vx = (y1_ - y2) / L, vy = (x2 - x1) / L, d = L / 2; n   for (int i = (1); i <= (n); ++i) { n     long double l = BI(i, 1), r = BI(i, -1); n     if (l > r) swap(l, r); n     V.push_back(make_pair(l - eps, -1)), V.push_back(make_pair(r + eps, 1)); n   } n   V.push_back(make_pair(0, 0)); n   sort((V).begin(), (V).end()); n   for (int i = 0; i < V.size(); i++) { n     s += V[i].second; n     if (s == 0 || V[i].second == -1 && s == -1) n       ans = min(ans, sqrt(((V[i].first) * (V[i].first)) + ((d) * (d)))); n   } n   printf( %.12Lf n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = 1 << 30; n const double eps = 1e-8; n const double pi = acos(-1.0); n int n, m; n char a[110], b[110], c[110]; n int d[26]; n int main() { n   srand(time(NULL)); n   scanf( %d%d%s%s , &n, &m, a, b); n   int la = strlen(a), lb = strlen(b); n   int flag = 1; n   for (int i = 0; i < lb; i++) n     if (b[i] ==  1 ) { n       for (int j = 0; j < la; j++) n         if (c[i + j] == 0 || c[i + j] == a[j]) { n           c[i + j] = a[j]; n         } else n           flag = 0; n       if (flag == 0) break; n     } n   if (flag) { n     for (int i = 0; i < m; i++) d[i] = i; n     for (int i = 0; i < lb; i++) n       if (b[i] ==  0 ) { n         int done = 0; n         for (int j = 0; j < la; j++) n           if (c[i + j] == 0) { n             random_shuffle(d, d + m); n             for (int k = 0; k < m; k++) { n               if (d[k] +  a  != a[j]) { n                 c[i + j] = d[k] +  a , done = 1; n                 break; n               } n             } n           } else if (c[i + j] != a[j]) { n             done = 1; n             break; n           } n         if (!done) { n           flag = 0; n           break; n         } n       } n   } n   for (int i = 0; i < n; i++) n     if (c[i] == 0) c[i] =  a ; n   if (flag) n     puts(c); n   else n     puts( No solution ); n   return 0; n } n


#include <bits/stdc++.h> n long long a[1001]; n using namespace std; n int main() { n   long long n, cnt = 0; n   cin >> n; n   for (long long i = 0; i < n; i++) { n     cin >> a[i]; n     if (a[i] == 0) { n       cnt++; n     } n     if (n == 1) { n       if (a[i] == 0) { n         cout <<  NO ; n         return 0; n       } else { n         cout <<  YES ; n         return 0; n       } n     } n   } n   if (cnt >= 0 && cnt != 1) { n     cout <<  NO ; n     return 0; n   } else { n     cout <<  YES ; n     return 0; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   vector<int> p(n / 2); n   for (int i = 0; i < n / 2; i++) { n     cin >> p[i]; n   } n   sort(p.begin(), p.end()); n   int sum1 = 0, sum2 = 0; n   for (int i = 0; i < n / 2; i++) { n     sum1 += abs(p[i] - i * 2 - 1); n     sum2 += abs(p[i] - i * 2 - 2); n   } n   cout << min(sum1, sum2) << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int gi() { n   int x = 0, c = getchar(); n   bool f = 0; n   for (; !isdigit(c); c = getchar()) n     if (c ==  - ) f = 1; n   for (; isdigit(c); c = getchar()) x = x * 10 + (c & 15); n   return f ? -x : x; n } n const int N = 300005; n const int mod = 998244353; n int a[N]; n int qpow(int a, int b) { n   int t = 1; n   while (b) { n     if (b & 1) t = 1ll * t * a % mod; n     a = 1ll * a * a % mod; n     b >>= 1; n   } n   return t; n } n bool cmp(const int &a, const int &b) { return a < b; } n int main() { n   int n = gi(); n   for (int i = 1; i <= (n << 1); ++i) a[i] = gi(); n   sort(a + 1, a + (n << 1) + 1, cmp); n   int fac = 1; n   for (int i = 1; i <= n; ++i) fac = 1ll * fac * i % mod; n   int faci = qpow(fac, mod - 2); n   for (int i = n + 1; i <= (n << 1); ++i) fac = 1ll * fac * i % mod; n   int ans = 0; n   for (int i = 1; i <= n; ++i) { n     ans += a[n + i] - a[i]; n     if (ans >= mod) ans -= mod; n   } n   printf( %d n , 1ll * fac * faci % mod * faci % mod * ans % mod); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int min(int a, int b) { return a < b ? a : b; } n long long max(long long a, long long b) { return a > b ? a : b; } n int read() { n   int x = 0, w = 1; n   char ch = getchar(); n   while (ch >  9  || ch <  0 ) { n     if (ch ==  - ) w = -1; n     ch = getchar(); n   } n   while (ch <=  9  && ch >=  0 ) x = x * 10 + ch -  0 , ch = getchar(); n   return x * w; n } n void bmax(long long &t1, long long t2) { t1 = max(t1, t2); } n void bmin(long long &t1, long long t2) { t1 = min(t1, t2); } n const int N = 2e5 + 10; n const long long INF = 1e16; n struct Node { n   long long mx, mn, ans; n   Node(long long _mx = -INF, long long _mn = INF, long long _ans = -INF) n       : mx(_mx), mn(_mn), ans(_ans) {} n   Node operator+(const Node &tmp) const { n     Node res = Node(mx, mn); n     res.ans = max(tmp.mx - mn, max(ans, tmp.ans)); n     bmax(res.mx, tmp.mx); n     bmin(res.mn, tmp.mn); n     return res; n   } n }; n int n, m; n long long h[N], s[N]; n struct SegmentTree { n   Node tr[N << 2]; n   void Build(int pos, int l, int r) { n     if (l == r) { n       tr[pos].mx = h[l] + s[l - 1]; n       tr[pos].mn = s[l - 1] - h[l]; n       tr[pos].ans = -INF; n       return; n     } n     int mid = (l + r) >> 1; n     Build(pos << 1, l, mid); n     Build(pos << 1 | 1, mid + 1, r); n     tr[pos] = tr[pos << 1] + tr[pos << 1 | 1]; n   } n   Node Query(int pos, int L, int R, int l, int r) { n     if (R < l || L > r) return Node(); n     if (l <= L && R <= r) return tr[pos]; n     int mid = (L + R) >> 1; n     Node res1 = Query(pos << 1, L, mid, l, r), n          res2 = Query(pos << 1 | 1, mid + 1, R, l, r); n     Node res = res1 + res2; n     return res; n   } n } Tr; n int main() { n   n = read(); n   m = read(); n   s[0] = 0; n   for (int i = 1; i <= n; i++) s[i] = read(), s[i + n] = s[i]; n   for (int i = 1; i <= n; i++) h[i] = read() * 2, h[n + i] = h[i]; n   for (int i = 1; i <= 2 * n; i++) s[i] += s[i - 1]; n   Tr.Build(1, 1, 2 * n); n   while (m--) { n     int l = read(), r = read(); n     Node ans; n     if (l <= r) n       ans = Tr.Query(1, 1, 2 * n, r + 1, l + n - 1); n     else n       ans = Tr.Query(1, 1, 2 * n, r + 1, l - 1); n     printf( %lld n , ans.ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long int c[1005][1005], quadratic = 0, single_x = 0, single_y = 0, n                              cnstnt = 0; n void calc_time_function(long long int n, long long int m) { n   long long int i, j, centr_x, centr_y; n   for (i = 0; i < n; i++) { n     for (j = 0; j < m; j++) { n       centr_x = i * 4 + 2LL; n       centr_y = j * 4 + 2LL; n       quadratic += c[i][j]; n       cnstnt += c[i][j] * (centr_x * centr_x + centr_y * centr_y); n       single_x += (2 * c[i][j] * centr_x); n       single_y += (2 * c[i][j] * centr_y); n     } n   } n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(NULL); n   long long int i, j, t, n, m, k, l, r, temp, left, right, mini, maxi, flag, n       leftthird, rightthird, x, y; n   cin >> n >> m; n   for (i = 0; i < n; i++) n     for (j = 0; j < m; j++) cin >> c[i][j]; n   mini = 1e18; n   ; n   calc_time_function(n, m); n   for (i = 0; i <= n; i++) { n     for (j = 0; j <= m; j++) { n       x = i * 4; n       y = j * 4; n       temp = (x * x + y * y) * quadratic - x * single_x - y * single_y + cnstnt; n       if (temp < mini) { n         mini = temp; n         left = i; n         right = j; n       } n     } n   } n   cout << mini << endl; n   cout << left <<     << right << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long MOD = 1000000000 + 7; n const long long MOD1 = 998244353; n long long mod(long long x) { return (x % MOD + MOD) % MOD; } n long long mul(long long a, long long b) { return mod(mod(a) * mod(b)); } n string itos(long long s) { n   string str = to_string(s); n   return str; n } n long long stoi2(string s) { n   long long a = atoi(s.c_str()); n   return a; n } n long long powerm(long long a, long long b, long long MOD) { n   a %= MOD; n   long long res = 1; n   while (b > 0) { n     if (b & 1) res = res * a % MOD; n     a = a * a % MOD; n     b >>= 1; n   } n   return res; n } n long long power(long long a, long long b) { n   long long res = 1; n   while (b > 0) { n     if (b & 1) res = res * a; n     a = a * a; n     b >>= 1; n   } n   return res; n } n bool isSubSequence(string str1, string str2, int m, int n) { n   if (m == 0) return true; n   if (n == 0) return false; n   if (str1[m - 1] == str2[n - 1]) n     return isSubSequence(str1, str2, m - 1, n - 1); n   return isSubSequence(str1, str2, m, n - 1); n } n bool ispalindrome(long long len, string str) { n   for (int i = 0; i < len / 2; i++) { n     if (str[i] != str[len - 1 - i]) { n       return false; n     } n   } n   return true; n } n inline bool isPowerOfTwo(long long x) { n   return ((1LL << (long long)log2(x)) == x); n } n long long isprime(long long N) { n   if (N < 2 || (!(N & 1) && N != 2)) return 0; n   for (long long i = 3; i * i <= N; i += 2) { n     if (!(N % i)) return 0; n   } n   return 1; n } n vector<long long> factor; n void factors(long long n) { n   for (long long i = 1; i <= sqrt(n); i++) { n     if (n % i == 0) { n       if (i == n / i) n         factor.push_back(i); n       else { n         factor.push_back(i); n         factor.push_back(n / i); n       } n     } n   } n   sort((factor).begin(), (factor).end()); n } n long long gcd(long long a, long long b) { n   if (b == 0) return a; n   return gcd(b, a % b); n } n long long lcm(long long a, long long b) { return (a / gcd(a, b)) * b; } n bool isvalid(long long i, long long j, long long n) { n   if (i >= 0 && i < n && j >= 0 && j < n) return true; n   return false; n } n long long dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}; n long long dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1}; n long long binarytodecimal(string n) { n   string num = n; n   long long dec_value = 0; n   long long base = 1; n   long long len = num.length(); n   for (int i = len - 1; i >= 0; i--) { n     if (num[i] ==  1 ) dec_value += base; n     base = base * 2; n   } n   return dec_value; n } n long long extended_GCD(long long a, long long b, long long &x, long long &y) { n   if (a == 0) { n     x = 0; n     y = 1; n     return b; n   } n   long long x1, y1; n   long long gcd = extended_GCD(b % a, a, x1, y1); n   x = y1 - (b / a) * x1; n   y = x1; n   return gcd; n } n long long modinv(long long a, long long mod = MOD) { n   long long x, y; n   extended_GCD(a, mod, x, y); n   if (x < 0) x += mod; n   return x; n } n string dtb(long long n) { n   string s =   ; n   while (n > 0) { n     if (n % 2 == 0) n       s.push_back( 0 ); n     else n       s.push_back( 1 ); n     n /= 2; n   } n   reverse((s).begin(), (s).end()); n   return s; n } n long long getfactorisation(long long n) { n   long long N = 5e6 + 5; n   vector<long long> fact(N); n   for (int i = 0; i < N; i++) fact[i] = i; n   for (int i = 2; i < N; i += 2) fact[i] = 2; n   for (long long i = 3; i <= N; i += 2) n     if (i == fact[i]) n       for (long long j = i * i; j < N; j += i) n         if (fact[j] == j) fact[j] = i; n   vector<long long> res; n   while (n > 1) { n     res.push_back(fact[n]); n     n /= fact[n]; n   } n   return res.size(); n } n long long maxPrimeFactor(long long n) { n   long long maxPrime = -1; n   while (n % 2 == 0) { n     maxPrime = 2; n     n >>= 1; n   } n   for (int i = 3; i <= sqrt(n); i += 2) { n     while (n % i == 0) { n       maxPrime = i; n       n = n / i; n     } n   } n   if (n > 2) maxPrime = n; n   return maxPrime; n } n vector<long long> seive; n void Seive() { n   const long long maxn = 1e6 + 5; n   seive.resize(maxn); n   for (long long i = (long long)0; i < (long long)maxn; i++) seive[i] = i; n   for (long long i = 2; i <= maxn; i += 2) seive[i] = 2; n   seive[1] = -1; n   seive[0] = -1; n   for (long long i = 3; i <= maxn; i += 2) n     if (i == seive[i]) n       for (long long j = i * i; j < maxn; j += i) n         if (seive[j] == j) seive[j] = i; n } n void factorisation(long long n) { n   vector<long long> res; n   for (long long i = 2; i * i <= n; i++) { n     if (n % i == 0) { n       while (n % i == 0) { n         n /= i; n         res.push_back(i); n       } n     } n   } n   if (n > 1) res.push_back(n); n } n long long fac[200005]; n unsigned long long modInverse(unsigned long long n, int p) { n   return powerm(n, p - 2, p); n } n long long nCrModPFermat(unsigned long long n, int r, int p) { n   if (n < r) return 0; n   if (r == 0) return 1; n   unsigned long long fac[n + 1]; n   fac[0] = 1; n   for (int i = 1; i <= n; i++) fac[i] = (fac[i - 1] * i) % p; n   return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) % n          p; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   ; n   long long T = 1; n   while (T--) { n     long long n, q; n     cin >> n >> q; n     vector<long long> v(n), k(q); n     for (long long i = (long long)0; i < (long long)n; i++) cin >> v[i]; n     for (long long i = (long long)0; i < (long long)q; i++) cin >> k[i]; n     for (long long i = (long long)1; i < (long long)n; i++) v[i] += v[i - 1]; n     long long sum = 0; n     for (long long i = (long long)0; i < (long long)q; i++) { n       sum += k[i]; n       long long lower = (lower_bound(v.begin(), v.end(), sum) - v.begin()); n       if (lower == n) { n         cout << n; n         sum = 0; n       } else { n         if (v[lower] > sum) { n           if (lower == 0) { n             cout << n; n           } else { n             lower--; n             cout << n - lower - 1; n           } n         } else { n           if (lower == n - 1) { n             cout << n; n             sum = 0; n           } else n             cout << n - lower - 1; n         } n       } n       cout <<   n ; n     } n   } n } n


#include <bits/stdc++.h> n  n typedef long long ll; n typedef unsigned long long ull; n typedef long double ld; n  n using namespace std; n  n const int INF = 1e9 + 5; n  n void failure () { n   cout << 0 << endl; n   exit(0); n } n  n namespace Lib { n #define ran(i, a, b) for (auto i = (a); i < (b); i++) n    n   struct ModArithm { n     //!pause n     ull q = 0; // (1<<(shift+64))/n n     char shift = -1; n     //!unpause n     ull n; n     ld rec; n     ModArithm(ull _n) : n(_n) { // n in [2, 1<<63) n       rec = 1.0L / n; n       //!pause n       ull rem = 1; n       while (rem < n) { n         ++shift; n         rem <<= 1; n       } n       for (int i = 63; i >= 0; --i) { n         if (rem >= n) { n           q |= 1LL << i; n           rem -= n; n         } n         rem *= 2; n       } n       //!unpause n     } n     // a, b in [0, min(2*n, 1<<63)) n     ull multf(ull a, ull b) { n       ull mult = (ld)a * b * rec + 0.5L; n       ll res = a * b - mult * n; n       if (res < 0) res += n; n       return res; // in [0, n-1) n     } n     //!pause n #ifndef ONLINE_JUDGE n     ull multa(ll a, ll b) { // a, b in [0, min(2*n, 1<<63)) n       ull res; n       ull tmp; n       __asm__( n                mulq %[b]; n t           // a*b n                movq %%rax, %[res]; n t  // ab_l = (a*b) & ((1 << n               // 64)-1) n                movq %%rdx, %[tmp]; n t  // ab_h = (a*b) >> 64 n                mulq %[q]; n t           // ab_l * q n                movq %[tmp], %%rax; n t  n                movq %%rdx, %[tmp]; n t  // abq_m = (ab_l * q) >> n               // 64 n                mulq %[q]; n t           // ab_h * q n                addq %[tmp], %%rax; n t  // abq_m += (ab_h * q) & n               // ((1 << 64)-1) n                adcq $0, %%rdx; n t  // abq_h = ((ab_h * q) >> 64) n               // + carry n                shrdq %%cl, %%rdx, %%rax; n t  // d = (a*b)/n = n               // (abq_m >> shift) n               // | (abq_h << (64 n               // -shift)) n                mulq %[n]; n t                 // d*n n                subq %%rax, %[res]; n t        // ab_l - = dn_l n               : [res]  =&r (res), [tmp]  =&r (tmp) n               : [a]  %a (a), [b]  d (b), [q]  r (q), n                 [shift]  c (shift), [n]  rm (n) n               :  cc ); n       return res; // in [0, 2n-1) n     } n     ull multi(ull a, ull b) { n       unsigned __int128 mult = a; n       mult *= b; n       ull prod = n         (((mult >> 64) * q) + n          ((unsigned __int128)(ull)mult * q >> 64)) >> n         shift; n       return (ull)mult - prod * n; n     } n     ull fix(ull a) { n       if (a >= n) a -= n; n       return a; n     } n     ull mult(ull a, ull b) { return fix(multi(a, b)); } n #endif n     //!unpause n     ull sqp1(ull a) { return multf(a, a) + 1; } n   }; n   //!finish n   //!start n  n   ull pow_mod(ull a, ull n, ModArithm &arithm) { n     ull res = 1; n     for (ull i = 1; i <= n; i <<= 1) { n       if (n & i) res = arithm.multf(res, a); n       a = arithm.multf(a, a); n     } n     return res; n   } n   //!finish n   //!start n  n   vector<char> small_primes = { n     2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37}; n  n   bool is_prime(ull n) { // n <= 1<<63, 1M rand/s n     ModArithm arithm(n); n     if (n == 2 || n == 3) return true; n     if (!(n & 1) || n == 1) return false; n     int s = __builtin_ctzll(n - 1); n     ull d = (n - 1) >> s; n     for (ull a : small_primes) { n       if (a >= n) break; n       a = pow_mod(a, d, arithm); n       if (a == 1 || a == n - 1) continue; n       ran(r, 1, s) { n         a = arithm.multf(a, a); n         if (a == 1) return false; n         if (a == n - 1) break; n       } n       if (a != n - 1) return false; n     } n     return true; n   } n   //!finish n   //!pause n  n #ifdef ONLINE_JUDGE n   ll __gcd(ll a, ll b) { n     if (a) return __gcd(b % a, a); n     return b; n   } n #endif n  n   //!unpause n   //!start n  n   ll pollard_rho(ll n) { n     ModArithm arithm(n); n     int cum_cnt = 64 - __builtin_clzll(n); n     cum_cnt *= cum_cnt / 5 + 1; n     while (true) { n       ll lv = rand() % n; n       ll v = arithm.sqp1(lv); n       int idx = 1; n       int tar = 1; n       while (true) { n         ll cur = 1; n         ll v_cur = v; n         int j_stop = min(cum_cnt, tar - idx); n         for (int j = 0; j < j_stop; ++j) { n           cur = arithm.multf(cur, abs(v_cur - lv)); n           v_cur = arithm.sqp1(v_cur); n           ++idx; n         } n         //!pause n         // cur = arithm.fix(cur); n         //!unpause n         if (!cur) { n           for (int j = 0; j < cum_cnt; ++j) { n             ll g = __gcd(abs(v - lv), n); n             if (g == 1) { n               v = arithm.sqp1(v); n             } else if (g == n) { n               break; n             } else { n               return g; n             } n           } n           break; n         } else { n           ll g = __gcd(cur, n); n           if (g != 1) return g; n         } n         v = v_cur; n         idx += j_stop; n         if (idx == tar) { n           lv = v; n           tar *= 2; n           v = arithm.sqp1(v); n           ++idx; n         } n       } n     } n   } n   //!finish n   //!start n  n  n   map<ll, int> prime_factor( n                             ll n, map<ll, int> *res = NULL) { n     // n <= 1<<62, ~1000/s (<500/s on CF) n     if (!res) { n       map<ll, int> res_act; n       for (int p : small_primes) { n         while (!(n % p)) { n           ++res_act[p]; n           n /= p; n         } n       } n       if (n != 1) prime_factor(n, &res_act); n       return res_act; n     } n     if (is_prime(n)) { n       ++(*res)[n]; n     } else { n       ll factor = pollard_rho(n); n       prime_factor(factor, res); n       prime_factor(n / factor, res); n     } n     return map<ll, int>(); n   } // Usage: fact = prime_factor(n); n } n  n struct Num { n   ll val; n   vector<int> divs; n }; n  n const int MAX_N = 1005; n  n map<ll, int> idx; // prime number -> small number n vector<ll> ppw [MAX_N]; n vector<Num> oths; n  n ll arr [MAX_N]; n map<ll, int> factor [MAX_N]; n  n int main () { n   int n, K; n   cin >> n >> K; n  n   for (int i = 0; i < n; i++) { n     cin >> arr[i]; n     factor[i] = Lib::prime_factor(arr[i]); n     if (factor[i].size() == 1) { n       idx[factor[i].begin()->first] = 0; n     } n   } n  n   int pc = 0; n   for (auto it = idx.begin(); it != idx.end(); it++) { n     it->second = pc; n     pc++; n   } n  n   for (int i = 0; i < n; i++) { n     if (factor[i].size() == 1) { n       ppw[idx[factor[i].begin()->first]].push_back(arr[i]); n     } n   } n  n   set<int> ok_ids; n   for (int i = 0; i < pc; i++) { n     if ((int) ppw[i].size() >= 2) { n       ok_ids.insert(i); n     } n   } n  n   for (int i = 0; i < n; i++) { n     if (factor[i].size() != 1) { n       Num cur; n       cur.val = arr[i]; n       cur.divs = vector<int> (0); n  n       bool ok = true; n  n       for (auto it = factor[i].begin(); it != factor[i].end(); it++) { n         if (!idx.count(it->first) || !ok_ids.count(idx[it->first])) { n           ok = false; n         } else { n           cur.divs.push_back(idx[it->first]); n         } n       } n        n       if (ok) { n         oths.push_back(cur); n       } n     } n   } n  n   if (K == 1) { n     failure(); n   } n  n   int ppc = 0, all2 = true; n   for (int id : ok_ids) { n     ppc += ppw[id].size(); n     if (ppw[id].size() != 2) { n       all2 = false; n     } n   } n  n   int totc = ppc + (int) oths.size(); n   if (totc < K) { n     failure(); n   } n  n   // easy case: take all primes and then whatever n   if (ppc <= K) { n     for (int id : ok_ids) { n       for (ll pp : ppw[id]) { n         cout << pp <<    ; n       } n     } n  n     for (int i = 0; i < K - ppc; i++) { n       cout << oths[i].val <<    ; n     } n     cout << endl; n     return 0; n   } n  n   // take one other thing with the smallest number of requirements n   // and then prime powers in pairs n   if (all2 && K % 2 == 1) { n     pair<int, int> least_req = make_pair(INF, -1); n     for (int i = 0; i < (int) oths.size(); i++) { n       least_req = min(least_req, make_pair((int) oths[i].divs.size(), i)); n     } n  n     if (least_req.first > K / 2) { n       failure(); n     } n  n     int lid = least_req.second; n     cout << oths[lid].val <<    ; n     K--; n     for (int d : oths[lid].divs) { n       for (ll pp : ppw[d]) { n         cout << pp <<    ; n       } n       ok_ids.erase(d); n       K -= 2; n     } n  n     for (int u : ok_ids) { n       if (K == 0) { n         break; n       } n  n       for (ll pp : ppw[u]) { n         cout << pp <<    ; n       } n       K -= 2; n     } n     cout << endl; n     return 0; n   } n  n   // take two things from each prime power and then some n   if (K >= 2 * (int) ok_ids.size()) { n     vector<ll> rem_ppws; n     for (int id : ok_ids) { n       for (int i = 0; i < (int) ppw[id].size(); i++) { n         if (i < 2) { n           cout << ppw[id][i] <<    ; n           K--; n         } else { n           rem_ppws.push_back(ppw[id][i]); n         } n       } n     } n  n     for (int i = 0; i < K; i++) { n       cout << rem_ppws[i] <<    ; n     } n     cout << endl; n     return 0; n   } n  n   // take 3 things from an >2 first, then take the others in pairs n   int spec = -1; n   if (K % 2 == 1) { n     for (int id : ok_ids) { n       if ((int) ppw[id].size() > 2) { n         spec = id; n         break; n       } n     } n  n     for (int i = 0; i < 3; i++) { n       cout << ppw[spec][i] <<    ; n       K--; n     } n   } n  n   for (int id : ok_ids) { n     if (id != spec) { n       if (K == 0) { n         break; n       } n  n       for (int i = 0; i < 2; i++) { n         cout << ppw[id][i] <<    ; n         K--; n       } n     } n   } n   cout << endl; n } n


#include <bits/stdc++.h> n const int INFI = (1 << 29); n const long long INFL = (1LL << 62); n using namespace std; n void solve() { n   long long a, n, m; n   cin >> a >> n >> m; n   bitset<2010> rain; n   vector<long long> v(m + 1); n   vector<pair<long long, long long> > umb(a + 1, {INFL, 0}); n   for (long long i = 0; i < n; i++) { n     long long l, r; n     cin >> l >> r; n     for (long long j = l; j <= r - 1; j++) rain[j] = 1; n   } n   for (long long i = 1; i <= m; i++) { n     long long l, r; n     cin >> l >> r; n     v[i] = r; n     umb[l] = min(umb[l], {r, i}); n   } n   vector<vector<long long> > dp(a + 1, vector<long long>(m + 1, INFL)); n   dp[0][0] = 0; n   for (long long i = 0; i < a; i++) { n     for (long long j = 0; j <= m; j++) { n       if (dp[i][j] == INFL) continue; n       if (umb[i].first != INFL) n         dp[i + 1][umb[i].second] = n             min(dp[i + 1][umb[i].second], dp[i][j] + umb[i].first); n       if (j) dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + v[j]); n       if (!rain[i]) dp[i + 1][0] = min(dp[i + 1][0], dp[i][j]); n     } n   } n   long long r = *min_element(dp[a].begin(), dp[a].end()); n   if (r == INFL) r = -1; n   cout << r <<   n ; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int c1, c2, c3, c4, n, m, bus[1009], tre[1009], x, z1, z, l, l1, y; n int main() { n   cin >> c1 >> c2 >> c3 >> c4; n   cin >> n >> m; n   for (int i = 1; i <= n; i++) { n     cin >> bus[i]; n     if (l == 0) { n       if (x + bus[i] * c1 < x + c2) n         x += bus[i] * c1; n       else n         x += c2; n       if (x > c3) x = c3, l = 1; n     } n   } n   for (int i = 1; i <= m; i++) { n     cin >> tre[i]; n     if (l1 == 0) { n       if (y + tre[i] * c1 < y + c2) n         y += tre[i] * c1; n       else n         y += c2; n       if (y > c3) y = c3, l1 = 1; n     } n   } n   x = min(x + y, c4); n   cout << x; n } n


#include <bits/stdc++.h> n using namespace std; n vector<long long> tree[1 << 20]; n long long a[1 << 20], goal[1 << 20]; n vector<long long> ans; n void dfs(long long v, long long cnt1 = 0, long long cnt2 = 0, n          long long par = -1) { n   for (long long i = 0; i < cnt1; i++) { n     a[v] = !a[v]; n   } n   if (goal[v] != a[v]) { n     cnt1++; n     ans.push_back(v); n   } n   for (long long i = 0; i < tree[v].size(); i++) { n     if (tree[v][i] != par) dfs(tree[v][i], cnt2, cnt1, v); n   } n } n int main() { n   long long n; n   cin >> n; n   for (long long i = 0; i < n - 1; i++) { n     long long temp, temp1; n     cin >> temp >> temp1; n     tree[temp].push_back(temp1); n     tree[temp1].push_back(temp); n   } n   for (long long i = 1; i <= n; i++) cin >> a[i]; n   for (long long i = 1; i <= n; i++) cin >> goal[i]; n   dfs(1); n   cout << ans.size() <<   n ; n   for (long long i = 0; i < ans.size(); i++) cout << ans[i] <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m; n int ara[100005]; n int pri[100005]; n vector<int> jog[2 * 100005], biyog[2 * 100005]; n map<pair<int, int>, int> dp1, dp2; n int cnt1(int x, int y) { n   if (y == m + 1) return x; n   if (dp1.find({x, y}) != dp1.end()) return dp1[{x, y}]; n   int val = x - y + 100005; n   int idx = n       lower_bound(biyog[val].begin(), biyog[val].end(), y) - biyog[val].begin(); n   if (idx == biyog[val].size()) return dp1[{x, y}] = min(n, x + m + 1 - y); n   int j = biyog[val][idx]; n   assert(j != y); n   return dp1[{x, y}] = cnt1(ara[j], pri[j]); n } n int cnt2(int x, int y) { n   if (y == m + 1) return x; n   if (dp2.find({x, y}) != dp2.end()) return dp2[{x, y}]; n   int val = x + y; n   int idx = lower_bound(jog[val].begin(), jog[val].end(), y) - jog[val].begin(); n   if (idx == jog[val].size()) return dp2[{x, y}] = max(1, x - m - 1 + y); n   int j = jog[val][idx]; n   assert(j != y); n   return dp2[{x, y}] = cnt2(ara[j], pri[j]); n } n int main() { n   scanf( %d %d , &n, &m); n   for (int i = 1; i <= m; i++) scanf( %d , ara + i); n   if (n == 1) { n     printf( 0 n ); n     return 0; n   } n   for (int i = 1; i <= m; i++) { n     jog[ara[i] + i].push_back(i); n     biyog[ara[i] - i + 100005].push_back(i); n   } n   for (int i = 0; i < 2 * 100005; i++) sort(jog[i].begin(), jog[i].end()); n   for (int i = 0; i < 2 * 100005; i++) sort(biyog[i].begin(), biyog[i].end()); n   for (int i = m; i; i--) { n     if (ara[i] == ara[i + 1]) n       pri[i] = pri[i + 1]; n     else n       pri[i] = i + 1; n   } n   long long ans = 0; n   for (int i = 1; i < n; i++) ans += cnt1(i, 0) - i; n   for (int i = 2; i <= n; i++) ans += i - cnt2(i, 0); n   ans += n; n   printf( %lld n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e6, inf = 1e9 + 2; n pair<int, int> a[N + 2], b[N + 2], aa[N + 2], bb[N + 2]; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   int n, c, d; n   cin >> n >> c >> d; n   int p = 0, q = 0; n   for (int i = 1; i <= n; i++) { n     int x, y; n     char c; n     cin >> x >> y >> c; n     if (c ==  C ) n       a[++p] = {y, x}; n     else n       b[++q] = {y, x}; n   } n   sort(a + 1, a + p + 1); n   sort(b + 1, b + q + 1); n   for (int i = 1; i <= p; i++) aa[i] = a[i]; n   for (int i = 1; i <= q; i++) bb[i] = b[i]; n   for (int i = 1; i <= p; i++) a[i].second = max(a[i].second, a[i - 1].second); n   for (int i = 1; i <= q; i++) b[i].second = max(b[i].second, b[i - 1].second); n   int ans = 0; n   for (int i = 2; i <= p; i++) { n     int rm = c - a[i].first; n     int id = upper_bound(a + 1, a + p + 1, make_pair(rm, inf)) - a; n     id--; n     if (id >= i) id = i - 1; n     if (id > 0) ans = max(ans, aa[i].second + a[id].second); n   } n   for (int i = 2; i <= q; i++) { n     int rm = d - b[i].first; n     int id = upper_bound(b + 1, b + q + 1, make_pair(rm, inf)) - b; n     id--; n     if (id >= i) id = i - 1; n     if (id > 0) ans = max(ans, bb[i].second + b[id].second); n   } n   int ad1 = -1, ad2 = -1; n   for (int i = 1; i <= p; i++) n     if (a[i].first <= c) ad1 = a[i].second; n   for (int i = 1; i <= q; i++) n     if (b[i].first <= d) ad2 = b[i].second; n   if (ad1 != -1 && ad2 != -1) ans = max(ans, ad1 + ad2); n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char mp[5500][5500]; n int sum[5500][5500]; n const int INF = 0x3f3f3f3f; n int main() { n   int n, m; n   scanf( %d%d , &n, &m); n   for (int i = 1; i <= n; ++i) scanf( %s , mp[i] + 1); n   for (int i = 1; i <= n; ++i) { n     int tot = 0; n     for (int j = 1; j <= m; ++j) { n       if (mp[i][j] ==  1 ) ++tot; n       sum[i][j] = tot; n     } n   } n   int mm = max(n, m), ans = INF; n   for (int k = mm; k > 1; --k) { n     bool fi = true; n     int i, j, tj = k, ti = k, t0 = 0, t1 = 0, tans = 0; n     for (i = 1; i <= ti; ++i) { n       if (i > n || tj > m) { n         if (i > n) fi = false; n         if (i > n) n           t0 += k; n         else { n           t1 += sum[i][m] - sum[i][tj - k]; n           t0 += k - (sum[i][m] - sum[i][tj - k]); n         } n       } else { n         if (i == n) fi = false; n         t1 += sum[i][tj] - sum[i][tj - k]; n         t0 += k - (sum[i][tj] - sum[i][tj - k]); n       } n       if (i == ti) { n         tans += min(t0, t1); n         t0 = 0, t1 = 0; n       } n       if (i == ti && tj < m) { n         tj += k; n         i = ti - k; n       } else if (i == ti && fi && tj >= m) { n         ti += k; n         tj = k; n       } n     } n     ans = min(ans, tans); n   } n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> g[5000]; n vector<int> r[5000]; n vector<int8_t> vis(5000); n int n, m, s; n void dfs(int src) { n   vis[src] = true; n   for (auto v : g[src]) { n     if (!vis[v]) { n       dfs(v); n     } n   } n } n int root(int src, vector<bool> &df) { n   df[src] = true; n   int c = 0; n   for (int v : g[src]) { n     if (!df[v] && !vis[v]) { n       c += root(v, df) + 1; n     } n   } n   return c; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin >> n >> m >> s; n   --s; n   for (int x, y, i = 0; i < m; ++i) { n     cin >> x >> y; n     g[--x].push_back(--y); n     r[y].push_back(x); n   } n   dfs(s); n   int ans = 0; n   vector<pair<int, int>> sl; n   for (int i = 0; i < n; ++i) { n     if (!vis[i]) { n       vector<bool> df(n); n       int a = root(i, df); n       sl.push_back({-a, i}); n     } n   } n   sort(sl.begin(), sl.end()); n   for (auto c : sl) { n     if (!vis[c.second]) { n       g[s].push_back(c.second); n       dfs(s); n       ++ans; n     } n   } n   printf( %d n , ans); n   return false & true; n } n


#include <bits/stdc++.h> n int main() { n   int n; n   scanf( %d , &n); n   if (n % 5 == 0) n     printf( %d , n / 5); n   else n     printf( %d , (n / 5) + 1); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 100005; n const long long inf = 0x3f3f3f3f3f3f; n long long a[3][maxn], dp[3][maxn]; n int main() { n   std::ios::sync_with_stdio(false); n   std::cin.tie(0); n   int n; n   cin >> n; n   for (int j = (1); j < (3); j++) n     for (int i = (1); i < (n + 1); i++) { n       cin >> a[j][i]; n     } n   a[0][0] = a[1][0] = a[2][0] = inf; n   for (int i = (1); i < (n + 1); i++) { n     dp[0][i] = max(dp[1][i - 1], dp[2][i - 1]); n     dp[1][i] = max(dp[0][i - 1], dp[2][i - 1]) + a[1][i]; n     dp[2][i] = max(dp[0][i - 1], dp[1][i - 1]) + a[2][i]; n   } n   long long ans = 0; n   for (int i = (0); i < (3); i++) ans = max(ans, dp[i][n]); n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 10; n int a[N], b[N], len; n bool vis[N]; n int xx(int x) { n   if (x & 1) n     return x / 2; n   else n     return x / 2 - 1; n } n int main() { n   int t; n   cin >> t; n   while (t--) { n     len = 0; n     memset(vis, 0, sizeof vis); n     int n; n     cin >> n; n     for (int i = 1; i <= n; i++) { n       cin >> a[i]; n       if (a[i] >= 1 && a[i] <= n) { n         if (!vis[a[i]]) n           vis[a[i]] = 1; n         else n           b[++len] = a[i]; n       } else { n         b[++len] = a[i]; n       } n     } n     sort(b + 1, b + len + 1); n     int j = len; n     bool flag = 0; n     for (int i = n; i > 0; i--) { n       if (vis[i]) continue; n       if (xx(b[j]) < i) { n         flag = 1; n         break; n       } else { n         j--; n       } n     } n     if (flag) n       cout << -1 << endl; n     else n       cout << len << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n inline T sqr(T t) { n   return t * t; n } n inline void files() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n } n int n, a[100100]; n int main() { n   files(); n   int l = 0, r = 0; n   int ans = 0; n   cin >> n; n   for (int i = 1; i <= n; i++) cin >> a[i]; n   for (int i = 3; i <= n; i++) { n     if (a[i] == a[i - 1] + a[i - 2]) { n       if (l == 0) l = max(1, i - 2); n       r = i; n       ans = max(ans, r - l + 1); n     } else { n       l = 0; n       r = 0; n     } n   } n   ans = max(ans, min(n, 2)); n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, m, k; n void nhap() { cin >> n >> m >> k; } n long long tinh(long long x) { n   if (x > k) return -1e19 + 10; n   long long r = n / (x + 1); n   long long h = k - x; n   long long d = m / (h + 1); n   return r * d; n } n void xuli() { n   if (n - 1 + m - 1 < k) { n     cout << -1; n     return; n   } n   long long kq = -1e19 + 10; n   for (int i = 1; i <= sqrt(n); i++) { n     if (n % i == 0) { n       kq = max(kq, tinh(1ll * i - 1)); n       kq = max(kq, tinh(n / i - 1)); n     } n   } n   swap(n, m); n   for (int i = 1; i <= sqrt(n); i++) { n     if (n % i == 0) { n       kq = max(kq, tinh(1ll * i - 1)); n       kq = max(kq, tinh(n / i - 1)); n     } n   } n   cout << kq; n } n int main() { n   nhap(); n   xuli(); n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 2e5 + 5; n long long n, k, sum, l, x, m, i, a, b[N]; n vector<long long> ans; n int main() { n   cin >> n; n   if (n == 1) { n     cin >> a; n     cout << a; n     return 0; n   } n   for (long long i = 0; i < n; i++) { n     cin >> a; n     b[i] = a + i; n   } n   sort(b, b + n); n   for (long long i = 0; i < n; i++) { n     ans.push_back(b[i] - i); n     if (b[i] == b[i + 1]) return cout <<  :(  << endl, 0; n   } n   for (long long i = 0; i < n; i++) { n     cout << ans[i] <<    ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   char str[200005]; n   gets(str); n   vector<char> v; n   if (strlen(str) > 1) { n     v.push_back(str[0]); n     v.push_back(str[1]); n   } else { n     cout << str; n     return 0; n   } n   int l = strlen(str); n   int len; n   for (int i = 2; i < l; i++) { n     len = v.size(); n     if (str[i] == v[len - 1] && str[i] == v[len - 2]) continue; n     if (v[len - 3] == v[len - 2] && str[i] == v[len - 1]) n       continue; n     else n       v.push_back(str[i]); n   } n   len = v.size(); n   for (int i = 0; i < len; i++) printf( %c , v[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a[100500]; n int v[100500]; n int main() { n   int n; n   cin >> n; n   for (int i = 0; i < n; i++) cin >> a[i]; n   v[0] = -1; n   int ans = 0; n   for (int i = 0; i < n; i++) { n     int l = 0, r = ans + 1; n     while (r - l > 1) { n       int j = (l + r) / 2; n       if (v[j] < a[i]) n         l = j; n       else n         r = j; n     } n     v[l + 1] = a[i]; n     if (l + 1 > ans) ans = l + 1; n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n T sq(T n) { n   return n * n; n } n template <class T> n T gcd(T a, T b) { n   return (b != 0 ? gcd<T>(b, a % b) : a); n } n template <class T> n T lcm(T a, T b) { n   return (a / gcd<T>(a, b) * b); n } n template <class T> n T power(T N, T P) { n   return (P == 0) ? 1 : N * power(N, P - 1); n } n int A[5000001], len; n long long dp[5000001]; n int convert(char c) { n   if (c >=  a  && c <=  z ) n     return (int)(c - 87); n   else if (c >=  0  && c <=  9 ) n     return (int)(c - 48); n   else n     return (int)(c - 29); n } n int main(int argc, char *argv[]) { n   string S; n   int i; n   long long k1, k2, v = 1, res = 1; n   cin >> S; n   len = S.length(); n   for (i = 0; i <= len - 1; i++) A[i] = convert(S[i]); n   dp[0] = 1; n   k1 = A[0]; n   k2 = A[0]; n   for (i = 1; i <= len - 1; i++) { n     v *= 5; n     k1 += (v * A[i]); n     k2 = 5 * k2 + A[i]; n     if (k1 == k2) dp[i] = dp[(i + 1) / 2 - 1] + 1; n     res += dp[i]; n   } n   cout << res << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, m; n long long a[10001], f[10001]; n int main() { n   int d, x, y; n   scanf( %I64d %I64d , &n, &m); n   f[0] = f[1] = 1; n   for (int i = 2; i <= n; i++) f[i] = f[i - 1] + f[i - 2], f[i] %= 1000000000LL; n   for (int i = 1; i <= n; i++) scanf( %I64d , &a[i]); n   for (int i = 1; i <= m; i++) { n     scanf( %I64d , &d); n     if (d == 1) { n       scanf( %I64d %I64d , &x, &y); n       a[x] = y; n     } else { n       long long ans = 0; n       scanf( %I64d %I64d , &x, &y); n       for (int i = x; i <= y; i++) ans += f[i - x] * a[i], ans %= 1000000000LL; n       printf( %I64d n , ans); n     } n   } n   return 0; n } n