#include <bits/stdc++.h> n using namespace std; n int nn, mm; n struct Dinic { n   struct edge { n     int to, flow, cap; n   }; n   const static int N = 20007; n   vector<edge> e; n   vector<int> g[N + 7]; n   int dp[N + 7]; n   int ptr[N + 7]; n   void clear() { n     for (int i = 0; i < N + 7; i++) g[i].clear(); n     e.clear(); n   } n   void addEdge(int a, int b, int cap) { n     g[a].push_back(e.size()); n     e.push_back({b, 0, cap}); n     g[b].push_back(e.size()); n     e.push_back({a, 0, 0}); n   } n   int minFlow, start, finish; n   bool bfs() { n     for (int i = 0; i < N; i++) dp[i] = -1; n     dp[start] = 0; n     vector<int> st; n     int uk = 0; n     st.push_back(start); n     while (uk < st.size()) { n       int v = st[uk++]; n       for (int to : g[v]) { n         auto ed = e[to]; n         if (ed.cap - ed.flow >= minFlow && dp[ed.to] == -1) { n           dp[ed.to] = dp[v] + 1; n           st.push_back(ed.to); n         } n       } n     } n     return dp[finish] != -1; n   } n   int dfs(int v, int flow) { n     if (v == finish) return flow; n     for (; ptr[v] < g[v].size(); ptr[v]++) { n       int to = g[v][ptr[v]]; n       edge ed = e[to]; n       if (ed.cap - ed.flow >= minFlow && dp[ed.to] == dp[v] + 1) { n         int add = dfs(ed.to, min(flow, ed.cap - ed.flow)); n         if (add) { n           e[to].flow += add; n           e[to ^ 1].flow -= add; n           return add; n         } n       } n     } n     return 0; n   } n   int dinic(int start, int finish) { n     Dinic::start = start; n     Dinic::finish = finish; n     int flow = 0; n     for (minFlow = (1 << 30); minFlow; minFlow >>= 1) { n       while (bfs()) { n         for (int i = 0; i < N; i++) ptr[i] = 0; n         while (int now = dfs(start, (int)2e9 + 7)) flow += now; n       } n     } n     return flow; n   } n } dinic; n pair<int, int> aa[5555]; n bool can(int val) { n   dinic.clear(); n   for (int i = 0; i < nn; i++) { n     dinic.addEdge(nn + mm, i, val); n   } n   for (int i = 0; i < mm; i++) { n     dinic.addEdge(nn + i, nn + mm + 1, 1); n   } n   for (int i = 0; i < mm; i++) { n     dinic.addEdge(aa[i].first, nn + i, 1); n     dinic.addEdge(aa[i].second, nn + i, 1); n   } n   int ans = dinic.dinic(nn + mm, nn + mm + 1); n   return ans == mm; n } n int main() { n   cin >> nn >> mm; n   for (int i = 0; i < mm; i++) cin >> aa[i].first >> aa[i].second; n   for (int i = 0; i < mm; i++) aa[i].first--, aa[i].second--; n   int vl = 0, vr = mm; n   while (vl + 1 < vr) { n     int vm = (vl + vr) >> 1; n     if (can(vm)) n       vr = vm; n     else n       vl = vm; n   } n   cout << vr <<   n ; n   can(vr); n   for (int i = 0; i < nn; i++) { n     for (int to : dinic.g[i]) { n       if (dinic.e[to].flow == 1) { n         cout << i + 1 <<     n              << aa[dinic.e[to].to - nn].first + aa[dinic.e[to].to - nn].second - n                     i + 1 n              <<   n ; n       } n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   ; n   int n; n   long long m; n   cin >> n >> m; n   long long arr[n], sum = 0; n   for (int i = 0; i < n; i++) { n     cin >> arr[i]; n     sum += arr[i]; n   } n   sort(arr, arr + n); n   long long hneed = arr[n - 1], extra = 0; n   for (int i = n - 1; i >= 0; i--) { n     if (arr[i] >= hneed) { n       hneed--; n       continue; n     } else { n       extra += (hneed - arr[i]); n       hneed = arr[i] - 1; n     } n   } n   hneed = max(hneed, 0LL); n   cout << sum - n - extra - hneed; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int cnt[100500]; n int bestAns, start, len; n int longest[100500]; n inline void updAns(int L, int R) { n   int val = cnt[R + 1] - cnt[L]; n   if (val > bestAns) { n     bestAns = val; n     start = L; n     len = R - L + 1; n   } n } n int main() { n   stack<pair<char, int> > seq; n   string s; n   cin >> s; n   int n = s.size(); n   for (int i = 1; i <= n; i++) { n     cnt[i] = s[i - 1] ==  [ ; n     cnt[i] += cnt[i - 1]; n     longest[i - 1] = n + 234; n   } n   for (int i = 0; i < n; i++) { n     pair<char, int> cur(s[i], i); n     if (seq.empty()) n       seq.push(cur); n     else { n       char pr = seq.top().first; n       if (s[i] ==  ]  and pr ==  [  or s[i] ==  )  and pr ==  ( ) { n         pair<char, int> ws = seq.top(); n         seq.pop(); n         int low = ws.second, high = i; n         longest[i] = min(longest[i], low); n         if (low > 0 and longest[low - 1] < low - 1) { n           longest[i] = min(longest[i], longest[low - 1]); n         } n         updAns(longest[i], i); n       } else n         seq.push(cur); n     } n   } n   cout << bestAns << endl; n   cout << s.substr(start, len) << endl; n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n template <class T1, class T2> n ostream& operator<<(ostream& out, const pair<T1, T2> p) { n   out <<  (  << p.first <<  ,  << p.second <<  ) ; n   return out; n } n template <class T1, class T2> n istream& operator>>(istream& in, pair<T1, T2>& p) { n   in >> p.first >> p.second; n   return in; n } n template <class T> n istream& operator>>(istream& in, vector<T>& v) { n   for (T& x : v) in >> x; n   return in; n } n template <class T> n ostream& operator<<(ostream& out, const vector<vector<T> >& v) { n   for (const vector<T>& x : v) out << x <<   n ; n   return out; n } n template <class T> n ostream& operator<<(ostream& out, const vector<T>& v) { n   for (const T& x : v) out << x <<    ; n   return out; n } n long long power(long long a, long long b) { n   return b ? power(a * a % 1000000007ll, b / 2) * (b % 2 ? a : 1) % 1000000007ll n            : 1; n } n bool possible(vector<string>& s, string a) { n   for (long long i = 1; i < (long long)(s).size(); i++) { n     long long diff = 0; n     for (long long j = 0; j < (long long)(a).size(); j++) { n       if (a[j] != s[i][j]) diff++; n     } n     if (diff > 1) return false; n   } n   return true; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   long long T; n   cin >> T; n   while (T--) { n     long long n, m; n     cin >> n >> m; n     vector<string> s(n); n     cin >> s; n     string a = s[0]; n     if (possible(s, a)) { n       cout << a << endl; n     } else { n       string ans =   ; n       for (long long i = 0; i < (long long)(s[0]).size() && ans ==   ; i++) { n         char temp = s[0][i]; n         for (long long c =  a ; c <=  z  && ans ==   ; c++) { n           s[0][i] = c; n           if (possible(s, s[0])) { n             ans = s[0]; n             break; n           } n         } n         s[0][i] = temp; n       } n       if (ans ==   ) { n         cout << -1 << endl; n       } else n         cout << ans << endl; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n unsigned long long int MOD = 1000000007; n unsigned long long int B = 13331; n bool cmp(const int &a, const int &b) { return a < b; } n int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } n int lcm(int a, int b) { return a * (b / gcd(a, b)); } n double func(double mod, double x) { n   int n = (int)(x / (2.0 * mod)); n   x -= n * 2.0 * mod; n   while (x < 0.0) x += 2.0 * mod; n   while (x > 2.0 * mod) x -= 2.0 * mod; n   if (x > mod) x = 2.0 * mod - x; n   return x; n } n int main(void) { n   int i; n   double a, b, m, vx, vy, vz; n   cin >> a >> b >> m >> vx >> vy >> vz; n   double x = func(a, a / 2.0 + vx * (m / (-vy))); n   double z = func(b, vz * (m / (-vy))); n   printf( %.9f %.9f n , x, z); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e5 + 15; n const int mod = 1e9 + 7; n const int inf = 1e9 + 3; n int t, n; n string a[3], s; n int flag; n int conv(string q) { n   int ans = 0; n   for (int i = 0; i < q.size(); i++) { n     ans *= 10; n     ans += q[i] -  0 ; n   } n   return ans; n } n int main() { n   cin >> s; n   for (int i = 0; i < s.size(); i++) { n     if (s[i] ==  .  || s[i] ==  e ) n       t++; n     else n       a[t] += s[i]; n   } n   for (int i = a[1].size() - 1; i >= 0; i--) { n     if (a[1][i] ==  0 ) n       flag++; n     else n       break; n   } n   cout << a[0]; n   n = conv(a[2]); n   for (int i = 0; i < a[1].size() - flag; i++) { n     if (n == 0) cout <<  . ; n     n--; n     cout << a[1][i]; n   } n   while ((n--) > 0) cout << 0; n   cout << endl; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n ostream &operator<<(ostream &os, const vector<T> &v) { n   os <<  { ; n   string sep; n   for (const auto &x : v) os << sep << x, sep =  ,  ; n   return os <<  } ; n } n template <typename T, size_t size> n ostream &operator<<(ostream &os, const array<T, size> &arr) { n   os <<  { ; n   string sep; n   for (const auto &x : arr) os << sep << x, sep =  ,  ; n   return os <<  } ; n } n template <typename A, typename B> n ostream &operator<<(ostream &os, const pair<A, B> &p) { n   return os <<  (  << p.first <<  ,   << p.second <<  ) ; n } n void dbg_out() { cerr << endl; } n template <typename Head, typename... Tail> n void dbg_out(Head H, Tail... T) { n   cerr <<     << H; n   dbg_out(T...); n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(nullptr); n   int N, M; n   cin >> N >> M; n   vector<int> which_tower(N); n   vector<set<int>> towers(M); n   int answer = N - 1; n   for (int i = 0; i < N; i++) { n     cin >> which_tower[i]; n     which_tower[i]--; n     towers[which_tower[i]].insert(i); n     if (i > 0 && which_tower[i] == which_tower[i - 1]) answer--; n   } n   auto &&merge_into = [&](int from, int to) { n     if (towers[from].size() > towers[to].size()) swap(towers[from], towers[to]); n     for (auto &x : towers[from]) { n       answer -= int(towers[to].count(x - 1)); n       answer -= int(towers[to].count(x + 1)); n     } n     for (auto &x : towers[from]) towers[to].insert(x); n     towers[from].clear(); n   }; n   cout << answer <<   n ; n   for (int q = 0; q < M - 1; q++) { n     int a, b; n     cin >> a >> b; n     a--; n     b--; n     merge_into(b, a); n     cout << answer <<   n ; n   } n } n


#include <bits/stdc++.h> n int main() { n   int n, b; n   scanf( %d%d , &n, &b); n   int a[100], s = b; n   for (int i = 0; i < n; i++) { n     scanf( %d , &a[i]); n     s += a[i]; n   } n   for (int i = 0; i < n; i++) n     if (s < a[i] * n) { n       puts( -1 ); n       return 0; n     } n   for (int i = 0; i < n; i++) printf( %.8lf n , 1. * s / n - a[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int mo = 1e9 + 7; n const int N = 1000010; n const int inf = 0x3f3f3f3f; n using namespace std; n int n, m, q, tot, ans[N], fa[N], mark[N], pa[N], tmp; n struct node { n   int a, b, c; n   bool operator<(const node &x) const { return c < x.c; } n } e[N], ed[N]; n struct info { n   int a, b; n   bool operator<(const info &x) const { n     if (e[a].c != e[x.a].c) return e[a].c < e[x.a].c; n     return b < x.b; n   } n } t[N]; n int find(int x) { n   if (!fa[x]) return x; n   return fa[x] = find(fa[x]); n } n int find2(int x) { n   if (mark[x] != tmp) pa[x] = fa[x], mark[x] = tmp; n   if (!pa[x]) return x; n   return pa[x] = find2(pa[x]); n } n int main() { n   int a, b, c, k, x, A, B; n   scanf( %d%d , &n, &m); n   for (int i = 1; i <= m; i++) { n     scanf( %d%d%d , &a, &b, &c); n     e[i] = (node){a, b, c}; n     ed[i] = e[i]; n   } n   scanf( %d , &q); n   for (int j = 1; j <= q; j++) { n     scanf( %d , &k); n     for (int i = 1; i <= k; i++) scanf( %d , &x), t[++tot] = (info){x, j}; n   } n   sort(t + 1, t + tot + 1); n   sort(ed + 1, ed + m + 1); n   for (int i = 1, pos = 1, po = 1; i <= tot; i = pos) { n     while (ed[po].c < e[t[i].a].c && po <= m) { n       A = find(ed[po].a); n       B = find(ed[po].b); n       if (A != B) fa[B] = A; n       po++; n     } n     while (e[t[pos].a].c == e[t[i].a].c && pos <= tot) { n       if (t[pos].b != t[pos - 1].b || pos == i) tmp++; n       x = t[pos].a; n       A = find2(e[x].a); n       B = find2(e[x].b); n       if (A == B) n         ans[t[pos].b] = 1; n       else n         pa[B] = A; n       pos++; n     } n   } n   for (int i = 1; i <= q; i++) { n     if (!ans[i]) n       printf( YES n ); n     else n       printf( NO n ); n   } n   return 0; n } n


#include <iostream> n #include <algorithm> n using namespace std; n  n  n int main() n { n     int64_t k; n     int64_t n, x, t; n     cin >> k; n     while(k--) { n         cin >> n >> x >> t; n         int64_t zero = 0; n         int64_t ans = max(zero, n - t/x) * (t / x) + min(t/x, n) * min(t/x - 1, n - 1) / 2; n         cout << ans << endl; n     } n  n  n     return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 1010; n int q1[MAXN], q2[MAXN], r1, r2; n int n, c, m; n int a[MAXN]; n bool check() { n   for (int i = 1; i <= n; i++) n     if (!a[i] || (a[i] < a[i - 1])) return false; n   return true; n } n int main() { n   cin >> n >> m >> c; n   while (!check()) { n     int x; n     cin >> x; n     if (x > c / 2) { n       bool flag = false; n       for (int i = 1; i <= r2; i++) n         if (x > q2[i]) { n           q2[i] = x; n           printf( %d n , n - i + 1); n           flag = true; n           a[n - i + 1] = x; n           break; n         } n       if (!flag) { n         q2[++r2] = x; n         printf( %d n , n - r2 + 1); n         a[n - r2 + 1] = x; n       } n     } else { n       bool flag = false; n       for (int i = 1; i <= r1; i++) n         if (x < q1[i]) { n           q1[i] = x; n           printf( %d n , i); n           flag = true; n           a[i] = x; n           break; n         } n       if (!flag) { n         q1[++r1] = x; n         printf( %d n , r1); n         a[r1] = x; n       } n     } n     fflush(stdout); n   } n   return 0; n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:100000000 ) n using namespace std; n const long double pi = acos(-1.0); n const long long inf = (long long)1e18; n const int N = (int)1e6; n int n, m; n long long need[N], start[N]; n bool check(long long x) { n   int lowest = 0; n   for (int i = 0; (i < n) && (lowest < m); ++i) { n     long long pos = start[i], can = x; n     if (need[lowest] <= pos) { n       if (pos - need[lowest] > can) n         return false; n       else n         can = max(can - 2 * (pos - need[lowest]), n                   (can - (pos - need[lowest])) / 2); n     } n     while ((lowest < m) && (need[lowest] - pos <= can)) ++lowest; n   } n   return (lowest == m); n } n int main() { n   scanf( %d%d , &n, &m); n   for (int i = 0; i < n; ++i) scanf( %I64d , &start[i]); n   for (int i = 0; i < m; ++i) scanf( %I64d , &need[i]); n   if (check(0)) { n     printf( 0 n ); n     return 0; n   } n   long long l = 0, r = inf; n   while (l < r - 1) { n     long long m = (l + r) / 2; n     if (check(m)) n       r = m; n     else n       l = m; n   } n   printf( %I64d n , r); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 0x3f3f3f3f; n const long long LINF = 0x3f3f3f3f3f3f3f3fll; n int main() { n   int n, k; n   scanf( %d , &n), scanf( %d , &k); n   if (k % 2 == 0) { n     int ans = 0; n     while (n--) { n       int x; n       scanf( %d , &x); n       if (x == 1) ans ^= 1; n       if (x == 2) ans ^= 2; n       if (x > 2) ans ^= !(x % 2); n     } n     if (ans) n       printf( Kevin n ); n     else n       printf( Nicky n ); n     return 0; n   } n   function<int(int)> f = [&f](int i) { n     if (i == 0) return 0; n     if (i == 1) return 1; n     if (i == 2) return 0; n     if (i == 3) return 1; n     if (i == 4) return 2; n     if (i == 5) return 0; n     if (i % 2 == 1) return 0; n     set<int> second; n     second.insert(f(i - 1)); n     second.insert(f(i / 2)); n     int ret = 0; n     while (second.count(ret)) ret++; n     return ret; n   }; n   int ans = 0; n   while (n--) { n     int x; n     scanf( %d , &x); n     ans ^= f(x); n   } n   if (ans) n     printf( Kevin n ); n   else n     printf( Nicky n ); n   exit(0); n } n


#include <bits/stdc++.h> n using namespace std; n int n, k, i, a[100010]; n set<int> r; n int main() { n   scanf( %d%d , &n, &k); n   for (i = 0; i < n; i++) scanf( %d , &a[i]); n   sort(a, a + n); n   for (i = 0; i < n; i++) { n     if (a[i] % k == 0 && r.count(a[i] / k)) continue; n     r.insert(a[i]); n   } n   printf( %d n , int(r.size())); n   return 0; n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:16777216 ) n using namespace std; n int n, k; n int d[2][10000]; n void solution() { n   scanf( %d %d , &n, &k); n   for (int i = 0, _n = (n - 1); i < _n; ++i) d[0][i] = 1; n   int cur = 0, nxt = 1; n   for (int it = 0, _n = (k); it < _n; ++it) { n     for (int i = 0, _n = (n); i < _n; ++i) { n       int need = n - i - 1 - d[cur][i]; n       int lo = 0, hi = n - 1; n       while (hi - lo > 1) { n         int m = (lo + hi) / 2; n         if (d[cur][m] <= need) n           hi = m; n         else n           lo = m; n       } n       if (lo < hi && d[cur][lo] <= need) hi = lo; n       if (d[cur][hi] > need) throw 1; n       d[nxt][i] = d[cur][i] + d[cur][hi]; n       printf( %d  , hi + 1); n     } n     swap(cur, nxt); n     puts(  ); n   } n   for (int i = 0, _n = (n); i < _n; ++i) n     if (d[cur][i] != n - i - 1) throw 1; n } n int main() { n   solution(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   int sum = 0; n   bool ok = false; n   for (int i = 1; i <= n; i++) { n     sum = i + sum; n     if (n == 1 || n == sum) { n       cout <<  YES  << endl; n       break; n     } n     if (sum > n) { n       ok = true; n       break; n     } n   } n   if (ok) cout <<  NO  << endl; n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( O2 ) n using namespace std; n inline long long int input() { n   long long int n; n   cin >> n; n   return n; n } n long long int pw(long long int a, long long int b) { n   return (!b ? 1 : (b & 1 ? a * pw(a * a, b / 2) : pw(a * a, b / 2))); n } n const long long int MAXN = 2e5 + 10; n const long long int MAXA = 101; n const long long int INF = 8e18; n const long long int MOD = 1e9 + 7; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   ; n   mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); n   ; n   long long int t; n   cin >> t; n   while (t--) { n     long long int L, v, l, r; n     cin >> L >> v >> l >> r; n     long long int bib = L / v; n     long long int bib1 = l / v - (l % v == 0), bib2 = r / v; n     long long int x = bib2 - bib1; n     cout << bib - x << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e6; n int n; n int m; n int t[4 * N]; n void upd(int l, int r, int v = 1, int tl = 1, int tr = N) { n   if (l > r) return; n   if (l <= tl && tr <= r) { n     t[v]++; n     return; n   } n   int tm = (tl + tr) / 2; n   upd(l, min(tm, r), v * 2, tl, tm); n   upd(max(tm + 1, l), r, v * 2 + 1, tm + 1, tr); n } n int get(int pos, int v = 1, int tl = 1, int tr = N) { n   if (tl == tr) return t[v]; n   int tm = (tl + tr) / 2; n   if (pos <= tm) n     return t[v] + get(pos, v * 2, tl, tm); n   else n     return t[v] + get(pos, v * 2 + 1, tm + 1, tr); n } n int main() { n   ios_base::sync_with_stdio(false); n   cin >> n >> m; n   long long res = 1; n   vector<pair<int, int>> left; n   vector<pair<int, int>> right; n   for (int i = 1; i <= n; i++) { n     int y, l, r; n     cin >> y >> l >> r; n     if (l == 0 && r == N) res++; n     if (l == 0) n       left.push_back({y, r}); n     else n       right.push_back({y, l}); n   } n   sort(left.begin(), left.end()); n   sort(right.begin(), right.end()); n   vector<pair<int, int>> top; n   vector<pair<int, int>> bottom; n   for (int i = 1; i <= m; i++) { n     int x, l, r; n     cin >> x >> l >> r; n     if (l == 0 && r == N) res++; n     if (l == 0) n       bottom.push_back({r, x}); n     else n       top.push_back({l, x}); n   } n   sort(bottom.begin(), bottom.end()); n   int i1 = 0, i2 = 0; n   for (int i = 0; i < (int)bottom.size(); i++) { n     while (i1 < (int)left.size() && left[i1].first <= bottom[i].first) { n       upd(0, left[i1].second); n       i1++; n     } n     while (i2 < (int)right.size() && right[i2].first <= bottom[i].first) { n       upd(right[i2].second, N); n       i2++; n     } n     res += get(bottom[i].second); n   } n   memset(t, 0, sizeof t); n   sort(top.rbegin(), top.rend()); n   reverse(left.begin(), left.end()); n   reverse(right.begin(), right.end()); n   i1 = 0, i2 = 0; n   for (int i = 0; i < (int)top.size(); i++) { n     while (i1 < (int)left.size() && left[i1].first >= top[i].first) { n       upd(0, left[i1].second); n       i1++; n     } n     while (i2 < (int)right.size() && right[i2].first >= top[i].first) { n       upd(right[i2].second, N); n       i2++; n     } n     res += get(top[i].second); n   } n   cout << res <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n char s[2000010], t[2000010]; n int main(void) { n   int n; n   scanf( %d , &n); n   scanf( %s , s); n   scanf( %s , t); n   int count_s, count_t, count_com; n   count_s = count_t = count_com = 0; n   for (int i = 0; i < 2 * n; ++i) { n     if (s[i] ==  1  && t[i] ==  1 ) { n       ++count_com; n     } n     if (s[i] ==  1  && t[i] !=  1 ) { n       ++count_s; n     } n     if (s[i] !=  1  && t[i] ==  1 ) { n       ++count_t; n     } n   } n   if (count_com % 2 == 0) { n     if (count_s > count_t) { n       puts( First ); n     } else if (count_s >= count_t - 1) { n       puts( Draw ); n     } else { n       puts( Second ); n     } n   } else { n     if (count_s >= count_t) { n       puts( First ); n     } else if (count_s >= count_t - 2) { n       puts( Draw ); n     } else { n       puts( Second ); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n void cmax(T& a, T b) { n   a = max(a, b); n } n template <class T> n void cmin(T& a, T b) { n   a = min(a, b); n } n void _BG(const char* s) {} n template <class T, class... TT> n void _BG(const char* s, T a, TT... b) { n   for (int c = 0; *s && (c || *s !=  , ); ++s) { n     cerr << *s; n     for (char x :  ([{ ) c += *s == x; n     for (char x :  )]} ) c -= *s == x; n   } n   cerr <<   =   << a; n   if (*s) { n     cerr <<  ,  ; n     _BG(++s, b...); n   } else n     cerr << endl; n } n bool RD() { return 1; } n bool RD(char& a) { return scanf(  %c , &a) == 1; } n bool RD(char* a) { return scanf( %s , a) == 1; } n bool RD(double& a) { return scanf( %lf , &a) == 1; } n bool RD(int& a) { return scanf( %d , &a) == 1; } n bool RD(long long& a) { return scanf( %lld , &a) == 1; } n template <class T, class... TT> n bool RD(T& a, TT&... b) { n   return RD(a) && RD(b...); n } n void PT(const char& a) { putchar(a); } n void PT(char const* const& a) { fputs(a, stdout); } n void PT(const double& a) { printf( %.16f , a); } n void PT(const int& a) { printf( %d , a); } n void PT(const long long& a) { printf( %lld , a); } n template <char s =    , char e =   n > n void PL() { n   if (e) PT(e); n } n template <char s =    , char e =   n , class T, class... TT> n void PL(const T& a, const TT&... b) { n   PT(a); n   if (sizeof...(b) && s) PT(s); n   PL<s, e>(b...); n } n const int N = 1e5 + 87; n int n, a[N]; n set<int> p[N]; n struct node { n   long long s; n   node *lc, *rc; n } * ver[N]; n void upd(node*& t, int l, int r, int i, int x) { n   if (!t) t = new node(); n   t->s += x; n   if (r - l == 1) { n     return; n   } n   int m = l + (r - l) / 2; n   if (i < m) n     upd(t->lc, l, m, i, x); n   else n     upd(t->rc, m, r, i, x); n } n long long qry(node* t, int l, int r, int i, int j) { n   if (!t || r <= i || j <= l) return 0; n   if (i <= l && r <= j) return t->s; n   int m = (l + r) / 2; n   return qry(t->lc, l, m, i, j) + qry(t->rc, m, r, i, j); n } n void upd(int i, int j, int x) { n   if (i < 1 || i > n || j < 1 || j > n) return; n   for (; i <= n; i += i & -i) upd(ver[i], 1, n + 1, j, x); n } n long long qry(int i, int l, int r) { n   long long x = 0; n   for (; i; i ^= i & -i) x += qry(ver[i], 1, n + 1, l, r); n   return x; n } n long long qry(int i, int j) { return qry(j, i, j + 1); } n void del(int i) { n   int v = a[i]; n   auto it = p[v].upper_bound(i); n   int l = 0, r = n + 1; n   if (it != p[v].end()) r = *it; n   it = prev(it); n   if (it != p[v].begin()) l = *prev(it); n   upd(r, l, r - l); n   upd(r, i, -(r - i)); n   upd(i, l, -(i - l)); n   p[v].erase(it); n } n void ins(int i, int v) { n   auto it = p[v].upper_bound(i); n   int l = 0, r = n + 1; n   if (it != p[v].end()) r = *it; n   if (it != p[v].begin()) l = *prev(it); n   upd(r, l, -(r - l)); n   upd(r, i, r - i); n   upd(i, l, i - l); n   p[v].insert(it, i); n   a[i] = v; n } n int main() { n   int m; n   RD(n, m); n   for (int i(1); i < ((n) + 1); ++i) { n     int x; n     RD(x); n     ins(i, x); n   } n   for (int __i(0); __i < (m); ++__i) { n     int t, x, y; n     RD(t, x, y); n     if (t == 1) { n       if (a[x] == y) continue; n       del(x); n       ins(x, y); n     } else { n       PL(qry(x, y)); n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int MOD = 1000000007; n int _t[6]; n int main() { n   for (int i = 0; i < 6; ++i) { n     scanf( %d , &_t[i]); n   } n   long long a, b, x1, y1, x2, y2; n   a = 2 * _t[0]; n   b = 2 * _t[1]; n   x1 = _t[2] - _t[3]; n   y1 = _t[2] + _t[3]; n   x2 = _t[4] - _t[5]; n   y2 = _t[4] + _t[5]; n   long long X1 = x1 / b + (x1 > 0); n   long long X2 = x2 / b + (x2 > 0); n   long long Y1 = y1 / a + (y1 > 0); n   long long Y2 = y2 / a + (y2 > 0); n   long long D = max(abs(X1 - X2), abs(Y1 - Y2)); n   cout << D << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long r[1003], c[1003], g[1003][1003]; n int main() { n   long long w, h; n   scanf( %lld %lld , &h, &w); n   for (int i = 0; i < h; i++) scanf( %lld , &r[i]); n   for (int i = 0; i < w; i++) scanf( %lld , &c[i]); n   memset(g, -1, sizeof g); n   for (int i = 0; i < h; i++) { n     for (int j = 0; j < r[i]; j++) { n       g[i][j] = 0; n     } n     g[i][r[i]] = 1; n   } n   for (int j = 0; j < w; j++) { n     for (int i = 0; i < c[j]; i++) { n       if (g[i][j] == 1) { n         printf( 0 ); n         return 0; n       } n       g[i][j] = 0; n     } n     if (g[c[j]][j] == 0) { n       printf( 0 ); n       return 0; n     } n     g[c[j]][j] = 1; n   } n   long long ans = 1; n   for (int i = 0; i < h; i++) { n     for (int j = 0; j < w; j++) { n       if (g[i][j] == -1) ans = (ans * 2) % 1000000007; n     } n   } n   printf( %lld , ans); n } n


#include <bits/stdc++.h> n using namespace std; n  n #define ll long long n #define fi first n #define se second n  n const int MAX = 2 * 1e5 + 10; n const int MOD = 1e9 + 7; n ll t; n ll n, m, k; n ll a, b, x, y, x2, y2; n ll bio[MAX]; n ll arr[MAX]; n vector <ll> v; n string s; n  n int main() { n     cin >> t; n  n     while (t--) { n         cin >> n; n         cin >> s; n  n         b = 0; n         for (int i = 0; i < n; i++) { n             if (s[i] ==  b ) b++; n         } n  n         for (int i = 0; i < b; i++) { n             cout <<  b ; n         } n         for (int i = 0; i < n; i++) { n             if (s[i] ==  b ) continue; n             cout << s[i]; n         } n  n         cout <<   n ; n     } n  n     return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long inf = 0x3f3f3f3f; n const long long INF = 0x3f3f3f3f3f3f3f3fLL; n const long long mod = 1e9 + 7; n long long powmod(long long a, long long b) { n   long long res = 1; n   a %= mod; n   assert(b >= 0); n   for (; b; b >>= 1) { n     if (b & 1) res = res * a % mod; n     a = a * a % mod; n   } n   return res; n } n long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } n long long pct(long long x) { return __builtin_popcount(x); } n long long bit(long long x) { return 31 - __builtin_clz(x); } n long long cdiv(long long a, long long b) { n   return a / b + !(a < 0 || a % b == 0); n } n void DBG() { cerr <<  ]  << endl; } n template <class H, class... T> n void DBG(H h, T... t) { n   cerr << to_string(h); n   if (sizeof...(t)) cerr <<  ,  ; n   DBG(t...); n } n const long long maxn = 1e5 * 3 + 20; n long long n, _, q, k; n void solve() { n   cin >> _; n   while (_--) { n     cin >> n; n     long long sm = 0; n     vector<long long> a(n); n     vector<long long> b(n); n     for (signed i = 0; i < n; i++) { n       cin >> a[i]; n     } n     for (signed i = 0; i < n; i++) { n       cin >> b[i]; n       sm += b[i]; n     } n     vector<long long> order(n); n     iota(order.begin(), order.end(), 0); n     sort(begin(order), end(order), n          [&a](long long i, long long j) { return a[i] < a[j]; }); n     long long ans = sm; n     for (long long x : order) { n       long long tmp = max(sm - b[x], a[x]); n       if (tmp < ans) { n         sm -= b[x]; n         ans = tmp; n       } n     } n     cout << ans << endl; n   } n } n signed 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 const double PI = acos(-1.0); n int n, c[1011], vao[1011], save[1011]; n vector<int> ke[1011]; n bool mark[1011]; n int get(int start) { n   for (int i = (1), _b = (n); i <= _b; i++) vao[i] = save[i]; n   int done = 0, res = 0; n   memset(mark, false, sizeof mark); n   while (done < n) { n     int inc = 0; n     for (int i = (1), _b = (n); i <= _b; i++) n       if (!mark[i] && vao[i] == 0 && c[i] == start) { n         mark[i] = true; n         ++done; n         ++inc; n         for (int x = 0, _a = (ke[i].size()); x < _a; x++) { n           int u = ke[i][x]; n           vao[u]--; n         } n       } n     if (done == n) break; n     if (!inc) { n       if (start == 3) n         start = 1; n       else n         ++start; n       ++res; n     } n   } n   return res; n } n int main() { n   scanf( %d , &n); n   for (int i = (1), _b = (n); i <= _b; i++) scanf( %d , &c[i]); n   for (int i = (1), _b = (n); i <= _b; i++) { n     scanf( %d , &save[i]); n     for (int x = (1), _b = (save[i]); x <= _b; x++) { n       int u; n       scanf( %d , &u); n       ke[u].push_back(i); n     } n   } n   int res = n * 4; n   for (int start = (1), _b = (3); start <= _b; start++) { n     res = min(res, get(start)); n   } n   cout << res + n << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(NULL); n   int n, k, p, x, y; n   cin >> n >> k >> p >> x >> y; n   vector<int> a(n); n   int sum = 0; n   for (int i = 0; i < k; i++) { n     cin >> a[i]; n     sum += a[i]; n   } n   if (sum + n - k > x) { n     cout << -1 <<   n ; n     exit(0); n   } n   x -= sum; n   for (int i = k; i < n; i++) { n     if (y + n - 1 - i <= x) { n       a[i] = y; n       x -= y; n     } else { n       a[i] = 1; n       x -= 1; n     } n   } n   vector<int> b = a; n   sort(b.begin(), b.end()); n   if (b[n >> 1] >= y) { n     for (int i = k; i < n; i++) { n       cout << a[i] <<    ; n     } n     cout <<   n ; n   } else { n     cout << -1 <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long mod = (1000000007LL); n inline long long mult(long long a, long long b) { return (a * b) % mod; } n inline long long poww(long long a, long long b) { 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 gcd(long long a, long long b) { n   while (b) { n     a %= b; n     swap(a, b); n   } n   return a; n } n int n, m, q, k, v[300050], ans; n pair<int, int> w[300050]; n string second; n int leaf[300050], root, dp[300050], qtd[300050][2]; n int ini[300050], yes = 1; n vector<int> grafo[300050]; n void dfs(int x, int p) { n   int can = 0; n   if (leaf[x] and dp[x] == 1) yes = 0; n   for (auto v : grafo[x]) { n     if (v == p) continue; n     if (leaf[v]) can = 1; n     dp[v] = (dp[x] ^ 1); n     dfs(v, x); n     for (int j = 0; j < 2; j++) { n       if (qtd[x][j] > 0 and qtd[v][j ^ dp[v] ^ 1]) yes = 0; n     } n     qtd[x][0] += qtd[v][0]; n     qtd[x][1] += qtd[v][1]; n   } n   if ((can or p == root) and !leaf[x]) ans++; n } n int32_t main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cin >> n; n   for (int i = 1; i < n; i++) { n     int a, b; n     cin >> a >> b; n     grafo[a].push_back(b); n     grafo[b].push_back(a); n   } n   ans = n - 1; n   root = 1; n   for (int i = 1; i <= n; i++) { n     if ((int)(grafo[i]).size() == 1) leaf[i] = 1, root = i, ans--; n   } n   dfs(root, root); n   cout << (yes ? 1 : 3) <<     << ans <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n struct node { n   int val; n   int type; n } N[500000]; n int main() { n   long long n, a, b, c, d, start, len; n   cin >> n >> a >> b >> c >> d >> start >> len; n   for (int i = 1; i <= n; i++) { n     cin >> N[i].val >> N[i].type; n   } n   long long s = 1, t = 1, sum_st = start, ans = 0; n   long long low = 0; n   N[0].val = -1; n   for (int s = 1; s <= n; s++) { n     while (t <= n && N[t].val - N[s].val <= len) { n       if (N[t].type == 1) n         ans += c; n       else if (N[t].type == 0) n         ans -= d; n       low = min(low, ans); n       t++; n     } n     if (sum_st + low >= 0) { n       cout << N[s - 1].val + 1 << endl; n       return 0; n     } n     if (N[s].type == 1) { n       ans -= c; n       low -= c; n       sum_st += a; n     } else { n       ans += d; n       low += d; n       sum_st -= b; n     } n     if (sum_st < 0) { n       cout << -1 << endl; n       return 0; n     } n   } n   cout << N[n].val + 1 << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = 1000000007; n const long long INF = 4e18 + 10; n long long n; n long long a[55]; n vector<vector<long long> > ans; n long long findpos(long long x) { n   for (long long i = 0; i < n; i++) n     if (a[i] == x) return i; n } n void p1(long long x) { n   long long xx = findpos(x); n   vector<long long> v; n   if (xx > 0) v.push_back(xx); n   if (n - x + 1 - xx > 0) v.push_back(n - x + 1 - xx); n   for (long long i = n - x + 1; i < n; i++) v.push_back(1); n   ans.push_back(v); n   long long b[n]; n   long long i = 0; n   for (i = 0; i < x - 1; i++) b[i] = i + 1; n   for (long long j = xx; j <= n - x; j++) { n     b[i] = a[j]; n     i++; n   } n   for (long long j = 0; j < xx; j++) { n     b[i] = a[j]; n     i++; n   } n   for (long long j = 0; j < n; j++) { n     a[j] = b[j]; n   } n } n void p2(long long x) { n   long long xx = findpos(x); n   vector<long long> v; n   for (long long i = 0; i < x - 1; i++) v.push_back(1); n   if (xx + 1 - x + 1 > 0) v.push_back(xx + 1 - x + 1); n   if (n - 1 - xx > 0) v.push_back(n - 1 - xx); n   ans.push_back(v); n   long long b[n]; n   long long i = 0; n   for (long long j = xx + 1; j < n; j++) { n     b[i] = a[j]; n     i++; n   } n   for (long long j = x - 1; j <= xx; j++) { n     b[i] = a[j]; n     i++; n   } n   for (long long j = 0; j < x - 1; j++) { n     b[i] = j + 1; n     i++; n   } n   for (long long j = 0; j < n; j++) { n     a[j] = b[j]; n   } n } n signed main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   ; n   cout << fixed << setprecision(10); n   long long t = 1; n   while (t--) { n     cin >> n; n     for (long long i = 0; i < n; i++) cin >> a[i]; n     long long x = findpos(1); n     if (n % 2 == 1) { n       if (x == 0) { n       } else { n         vector<long long> v; n         v.push_back(x); n         v.push_back(n - x); n         ans.push_back(v); n         long long b[n]; n         long long i = 0; n         for (long long j = x; j < n; j++) { n           b[i] = a[j]; n           i++; n         } n         for (long long j = 0; j < x; j++) { n           b[i] = a[j]; n           i++; n         } n         for (long long j = 0; j < n; j++) { n           a[j] = b[j]; n         } n       } n       for (long long i = 2; i <= n; i++) { n         if (i % 2 == 1) n           p1(i); n         else n           p2(i); n       } n     } else { n       if (x == n - 1) { n       } else { n         vector<long long> v; n         v.push_back(x + 1); n         v.push_back(n - x - 1); n         ans.push_back(v); n         long long b[n]; n         long long i = 0; n         for (long long j = x + 1; j < n; j++) { n           b[i] = a[j]; n           i++; n         } n         for (long long j = 0; j <= x; j++) { n           b[i] = a[j]; n           i++; n         } n         for (long long j = 0; j < n; j++) { n           a[j] = b[j]; n         } n       } n       for (long long i = 2; i <= n; i++) { n         if (i % 2 == 1) n           p2(i); n         else n           p1(i); n       } n     } n     cout << ans.size() << endl; n     for (long long i = 0; i < ans.size(); i++) { n       cout << ans[i].size() <<    ; n       for (long long j = 0; j < ans[i].size(); j++) { n         cout << ans[i][j] <<    ; n       } n       cout << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m; n char s[4][12]; n char t[12][25][12]; n int num[12]; n int main() { n   int i, j; n   int ans = 0, p = 0; n   scanf( %d , &n); n   for (i = 0; i < n; i++) scanf( %s , s[i]); n   scanf( %d , &m); n   for (i = 0; i < m; i++) { n     scanf( %d , &num[i]); n     for (j = 0; j < num[i]; j++) scanf( %s , t[i][j]); n   } n   int mark[4]; n   int rec[25]; n   for (int k = 0; k < m; k++) { n     memset(mark, 0, sizeof(mark)); n     memset(rec, -1, sizeof(rec)); n     for (i = 0; i < 4; i++) { n       for (j = 0; j < num[k]; j++) { n         if (strcmp(s[i], t[k][j]) == 0) { n           mark[i] = 1; n           rec[j] = i; n         } n       } n     } n     int sum = 0; n     for (i = 0; i < n; i++) sum += mark[i]; n     if (sum < n) continue; n     int id[4] = {0, 1, 2, 3}; n     do { n       j = 0; n       for (i = 0; i < num[k]; i++) { n         if (rec[i] == id[j]) { n           j++; n           if (j == n) break; n         } n       } n       int x = 0; n       for (i = 0; i < n - 1; i++) n         for (int tt = i + 1; tt < n; tt++) n           if (id[i] > id[tt]) x++; n       if (j == n && n * (n - 1) / 2 - x + 1 > p) { n         ans = k + 1; n         p = n * (n - 1) / 2 - x + 1; n       } n     } while (next_permutation(id, id + n)); n   } n   if (ans == 0) n     printf( Brand new problem! n ); n   else { n     printf( %d n , ans); n     printf( [: ); n     for (i = 0; i < p; i++) printf( | ); n     printf( :] n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n int n, arr[1005][3], sum, cnt; n int main() { n   scanf( %d , &n); n   for (int i = 0; i < n; i++) n     scanf( %d %d %d , &arr[i][0], &arr[i][1], &arr[i][2]); n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < 3; j++) sum += arr[i][j]; n     if (sum >= 2) cnt++; n     sum = 0; n   } n   printf( %d , cnt); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   vector<int> a(n), pmx(n, -1), smx(n, -1); n   cin >> a[0]; n   pmx[0] = 0; n   int c = 1; n   for (int j = 1; j < n; j++) { n     cin >> a[j]; n     pmx[j] = pmx[j - 1]; n     smx[j] = (j == 1) + (j != 1) * smx[j - 1]; n     if (a[j] > a[pmx[j]]) { n       smx[j] = pmx[j]; n       pmx[j] = j; n       c++; n     } else if (a[j] > a[smx[j]]) { n       smx[j] = j; n     } n   } n   vector<int> rec(n, c); n   int mx = -1, i; n   for (int j = 0; j < n; j++) { n     rec[j] -= (pmx[j] == j); n   } n   for (int j = 1; j < n; j++) { n     if (smx[j] != j) continue; n     rec[pmx[j]]++; n   } n   for (int j = 0; j < n; j++) { n     if (mx < rec[j]) { n       mx = rec[j]; n       i = j; n     } else if (mx == rec[j] && a[j] < i) { n       i = j; n     } n   } n   int mn = n; n   for (int j = 0; j < n; j++) { n     if (rec[i] == rec[j] && mn > a[j]) { n       mn = a[j]; n     } n   } n   cout << mn; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 3e3 + 5; n int n, m; n vector<int> g[maxn]; n long long dis[maxn][maxn]; n vector<pair<long long, long long> > from[maxn], to[maxn]; n void bfs(int x) { n   queue<int> q; n   q.push(x); n   dis[x][x] = 0; n   while (!q.empty()) { n     int now = q.front(); n     q.pop(); n     for (int i : g[now]) { n       if (dis[x][i] == -1) { n         dis[x][i] = dis[x][now] + 1; n         q.push(i); n       } n     } n   } n } n int main() { n   memset(dis, -1, sizeof(dis)); n   scanf( %d%d , &n, &m); n   for (int u, v, i = 1; i <= m; i++) { n     scanf( %d%d , &u, &v); n     g[u].push_back(v); n   } n   for (int i = 1; i <= n; i++) bfs(i); n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= n; j++) { n       from[i].push_back({dis[i][j], j}); n       to[j].push_back({dis[i][j], i}); n     } n   } n   for (int i = 1; i <= n; i++) { n     sort(from[i].begin(), from[i].end(), n          greater<pair<long long, long long> >()); n     sort(to[i].begin(), to[i].end(), greater<pair<long long, long long> >()); n   } n   int a, b, c, d, cnt = 0; n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= n; j++) { n       if (i == j || dis[i][j] == -1) continue; n       for (int k = 0; k < 4; k++) { n         if (to[i][k].second == j || to[i][k].second == i) continue; n         for (int l = 0; l < 4; l++) { n           if (from[j][l].second == i || from[j][l].second == to[i][k].second || n               from[j][l].second == j) n             continue; n           if (to[i][k].first == -1 || from[j][l].first == -1) continue; n           long long now = dis[i][j] + to[i][k].first + from[j][l].first; n           if (now > cnt) { n             cnt = now; n             a = to[i][k].second, b = i, c = j, d = from[j][l].second; n           } n         } n       } n     } n   } n   printf( %d %d %d %d n , a, b, c, d); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long t; n   cin >> t; n   while (t--) { n     string p, h; n     int w = 0; n     cin >> p >> h; n     sort(p.begin(), p.end()); n     if (h.size() >= p.size()) { n       for (int i = 0; i < (h.size() - p.size() + 1); i++) { n         string sub = h.substr(i, p.size()); n         sort(sub.begin(), sub.end()); n         if (sub == p) { n           w = 1; n           break; n         } n       } n       if (w == 1) n         cout <<  YES  << endl; n       else n         cout <<  NO  << endl; n     } else n       cout <<  NO  << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int k; n   cin >> k; n   int n, m; n   n = 2; n   m = 3; n   int z = (1 << 17); n   cout << n <<     << m <<   n ; n   cout << z + k <<     << z <<     << k <<   n ; n   cout << k <<     << z + k <<     << k <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n set<int> s; n int ans[1000000]; n int main() { n   int n, m; n   scanf( %d %d , &n, &m); n   int i, j, l, r, w; n   for (i = 1; i <= n; i++) s.insert(i); n   for (i = 0; i < m; i++) { n     scanf( %d %d %d , &l, &r, &w); n     auto idx1 = s.lower_bound(l); n     auto idx2 = s.upper_bound(r); n     vector<int> v; n     for (auto it = idx1; it != idx2; it++) { n       ans[*it] = w; n       if (*it != w) v.push_back(*it); n     } n     for (j = 0; j < v.size(); j++) s.erase(v[j]); n   } n   ans[w] = 0; n   for (i = 1; i <= n; i++) printf( %d  , ans[i]); n   printf(  n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a[25][25], n, m, dp[1 << 22]; n char s[25][222]; n int main() { n   scanf( %d%d , &n, &m); n   for (int i = 0; i < n; ++i) scanf( %s , s[i]); n   for (int i = 0; i < n; ++i) n     for (int j = 0; j < m; ++j) scanf( %d , &a[i][j]); n   memset(dp, 63, sizeof(dp)), dp[0] = 0; n   for (int l, msk = 0; msk < (1 << n); ++msk) { n     for (int b = 0; b < n; ++b) n       if (!(msk & (1 << b))) { n         l = b; n         break; n       } n     for (int c = 0; c < m; ++c) { n       dp[msk + (1 << l)] = min(dp[msk + (1 << l)], dp[msk] + a[l][c]); n       int t = 0, h = 0, tmsk = msk; n       for (int i = 0; i < n; ++i) n         if (s[i][c] == s[l][c]) n           tmsk |= (1 << i), t += a[i][c], h = max(h, a[i][c]); n       dp[tmsk] = min(dp[tmsk], dp[msk] + t - h); n     } n   } n   printf( %d n , dp[(1 << n) - 1]); n } n


#include <bits/stdc++.h> n using namespace std; n long long ans[200005]; n vector<vector<pair<long long, long long> > > G(200005); n int main() { n   long long i, j, n, m, a, b, c; n   priority_queue<pair<long long, long long> > pq; n   scanf( %lld %lld , &n, &m); n   for (i = 0; i < m; i++) { n     scanf( %lld %lld %lld , &a, &b, &c); n     G[a].push_back({b, c}); n     G[b].push_back({a, c}); n   } n   for (i = 1; i <= n; i++) { n     scanf( %lld , &ans[i]); n     pq.push({-ans[i], i}); n   } n   while (!pq.empty()) { n     pair<long long, long long> tp = pq.top(); n     pq.pop(); n     tp.first *= -1; n     if (tp.first > ans[tp.second]) continue; n     ans[tp.second] = tp.first; n     for (pair<long long, long long> next : G[tp.second]) { n       long long poss = next.second * 2 + tp.first; n       if (poss < ans[next.first]) { n         pq.push({-poss, next.first}); n       } n     } n   } n   for (i = 1; i <= n; i++) printf( %lld  , ans[i]); n   printf(  n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void k_007() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n } n bool sortbysec(const pair<long long, long long> &a, n                const pair<long long, long long> &b) { n   return (a.second < b.second); 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 prime(long long n) { n   long long flag = 1; n   for (long long i = 2; i <= sqrt(n); i++) { n     if (n % i == 0) { n       flag = 0; n       break; n     } n   } n   return flag; n } n long long power(long long x, long long y) { n   if (y == 0) n     return 1; n   else if (y % 2 == 0) n     return ((power(x, y / 2) % 1000000007) * (power(x, y / 2) % 1000000007)) % n            1000000007; n   else n     return ((x % 1000000007) * (power(x, y / 2) % 1000000007) * n             (power(x, y / 2) % 1000000007)) % n            1000000007; n } n long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); } n int32_t main() { n   k_007(); n   long long n; n   cin >> n; n   if (n & 1) { n     if (n == 1) { n       cout << 3 << endl; n     } else { n       cout << 1 << endl; n     } n   } else { n     long long m = 1; n     while (prime(n * m + 1)) { n       m++; n     } n     cout << m << endl; n   } n } n


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


#include <bits/stdc++.h> n using namespace std; n long long n, k, l, r, st; n map<pair<long long, long long>, long long> M[2]; n long long Count(long long len, long long t, bool w) { n   if (M[w].count({len, t})) return (M[w][{len, t}]); n   if (t > len) return (M[w][{len, t}] = 0); n   if (len == t) return (M[w][{len, t}] = 1); n   return (M[w][{len, t}] = n               Count(len / 2, t, w) + Count((len - 1) / 2, t, w) + w); n } n long long get(long long len, long long t) { n   return (Count(len, t, 0) + Count(len, t + 1, 0)); n } n int main() { n   scanf( %I64d%I64d , &n, &k); n   if (k == 1) return !printf( 1 ); n   if (k == 2) return !printf( %I64d , n); n   n -= 2; n   k -= 2; n   l = 1; n   r = n; n   while (r - l > 1) { n     if (k > Count(n, (l + r) / 2 * 2 - 1, 1)) n       r = (l + r) / 2; n     else n       l = (l + r) / 2; n   } n   st = l * 2 - 1; n   l = 1; n   r = n; n   k -= Count(n, st + 2, 1); n   while (get(r - l + 1, st) && !(st == 1 && r - l <= 1)) { n     if (k <= get((l + r) / 2 - l, st)) n       r = (l + r) / 2 - 1; n     else n       k -= get((l + r) / 2 - l, st), l = (l + r) / 2 + 1; n   } n   if (st == 1 && r - l <= 1) l += k; n   return !printf( %I64d , l); n } n


#include <bits/stdc++.h> n using namespace std; n struct algo { n   int n; n   map<pair<int, int>, int> v1; n   vector<vector<int> > drogi; n   vector<pair<int, int> > tab; n   vector<pair<int, int> > wy; n   algo() { n     cin >> n; n     string s; n     int li = 0; n     tab.push_back({}); n     for (long long a, b, i = 1; i <= n; i++) { n       cin >> s; n       a = b = 0; n       for (int j = 0; j < s.size(); j++) { n         a = (a * 33 + s[j] -  a  + 1) % 1000000009; n         if (j != 0) b = (b * 33 + s[j] -  a  + 1) % 1000000009; n         if (v1.find({a, j + 1}) != v1.end()) continue; n         v1[{a, j + 1}] = ++li; n         tab.push_back({b, j}); n       } n     } n     drogi.resize(li + 10); n     for (int i = 1; i <= li; i++) { n       drogi[v1[tab[i]]].push_back(i); n     } n     wy.resize(li + 10); n     cout << dfs().second <<   n ; n   } n   pair<int, int> dfs(int gdzie = 0) { n     if (wy[gdzie].second != 0) return wy[gdzie]; n     int x = 0, y = 0; n     pair<int, int> p; n     for (int i : drogi[gdzie]) { n       p = dfs(i); n       x += p.first; n       y += p.second; n     } n     return wy[gdzie] = {max(y + 1, x), x}; n   } n }; n int32_t main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   int t; n   cin >> t; n   while (t--) { n     algo p; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   int n, ans = 0, i, temp; n   vector<int> a; n   cin >> n; n   for (i = 0; i < n; i++) { n     cin >> temp; n     a.push_back(temp); n   } n   sort(a.begin(), a.end()); n   for (i = 0; i < n; i = i + 2) { n     if (a[i] != a[i + 1]) { n       ans += (a[i + 1] - a[i]); n     } n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool isluck() { n   unsigned long long n, s1 = 0, s2 = 0; n   string s; n   cin >> n >> s; n   for (int register i = 0; i < n / 2; i++) { n     int x = (s[i] -  0 ) % 10; n     if (x != 4 && x != 7) return false; n     s1 += x; n   } n   for (int register i = n / 2; i < n; i++) { n     int x = (s[i] -  0 ) % 10; n     if (x != 4 && x != 7) return false; n     s2 += x; n   } n   return (s1 == s2); n } n int main() { n   isluck() ? cout <<  YES  << endl : cout <<  NO  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a, b; n int sum; n int main() { n   cin >> a >> b; n   while (a >= b) { n     sum += a / b * b; n     a = a / b + a % b; n   } n   cout << sum + a; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, j; n std::vector<char> v; n int main() { n   std::ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   ; n   cin >> n; n   int i = 0; n   while (i < n) { n     j = 0; n     while (j < 2 && i < n) { n       cout <<  a ; n       j++; n       i++; n     } n     j = 0; n     while (j < 2 && i < n) { n       cout <<  b ; n       j++; n       i++; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 3000; n char a[N][N]; n int n, m, k, vis[N][N]; n long long ans = 0; n int main() { n   while (~scanf( %d%d%d , &n, &m, &k)) { n     ans = 0; n     for (register int i = 0; i <= n - 1; ++i) scanf( %s , a[i]); n     for (register int i = 0; i <= n - 1; ++i) { n       int c = 0; n       for (register int j = 0; j <= m - 1; ++j) { n         if (a[i][j] ==  . ) n           c++; n         else n           c = 0; n         if (c >= k) ans++; n       } n     } n     for (register int j = 0; j <= m - 1; ++j) { n       int c = 0; n       for (register int i = 0; i <= n - 1; ++i) { n         if (a[i][j] ==  . ) n           c++; n         else n           c = 0; n         if (c >= k) ans++; n       } n     } n     if (k == 1) ans /= 2; n     printf( %I64d n , ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline int getint() { n   int res = 0, fh = 1; n   char ch = getchar(); n   while ((ch <  0  || ch >  9 ) && ch !=  - ) ch = getchar(); n   if (ch ==  - ) fh = -1, ch = getchar(); n   while (ch <=  9  && ch >=  0 ) res = res * 10 + ch -  0 , ch = getchar(); n   return res * fh; n } n int n, m, A, B, out[23], mp[23][23]; n double p[23], G[23][23], a[485][485], b[485], ans[485]; n void gauss() { n   for (int i = 1; i <= n * n; i++) { n     int id = i; n     for (int j = i + 1; j <= n * n; j++) n       if (fabs(a[j][i]) > fabs(a[id][i])) id = j; n     for (int j = i; j <= n * n; j++) swap(a[i][j], a[id][j]); n     swap(b[i], b[id]); n     if (a[i][i]) { n       for (int j = i + 1; j <= n * n; j++) { n         double p = a[j][i] / a[i][i]; n         for (int k = i; k <= n * n; k++) a[j][k] -= a[i][k] * p; n         b[j] -= b[i] * p; n       } n     } n   } n   for (int i = n * n; i >= 1; i--) { n     if (a[i][i]) n       ans[i] = b[i] / a[i][i]; n     else n       ans[i] = 0; n     for (int j = i - 1; j >= 1; j--) b[j] -= a[j][i] * ans[i]; n   } n } n int main() { n   n = getint(); n   m = getint(); n   A = getint(); n   B = getint(); n   for (int i = 1; i <= m; i++) { n     int x = getint(), y = getint(); n     mp[x][y] = mp[y][x] = 1; n     out[x]++; n     out[y]++; n   } n   for (int i = 1; i <= n; i++) scanf( %lf , &p[i]), G[i][i] = p[i]; n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= n; j++) n       if (mp[i][j]) G[i][j] = (1 - p[i]) / (double)out[i]; n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= n; j++) { n       a[((i - 1) * n + j)][((i - 1) * n + j)] = -1; n       for (int k = 1; k <= n; k++) n         for (int l = 1; l <= n; l++) n           if (k != l) n             a[((i - 1) * n + j)][((k - 1) * n + l)] += G[k][i] * G[l][j]; n     } n   b[((A - 1) * n + B)] = -1; n   gauss(); n   for (int i = 1; i <= n; i++) printf( %.10lf  , ans[((i - 1) * n + i)]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int mark[1000009]; n int main() { n   long long n, m = 0, i, j, t; n   long long sum; n   cin >> n; n   long long a[n]; n   for (i = 0; i < n; i++) { n     scanf( %lld , &a[i]); n   } n   t = a[n - 1]; n   sum = t; n   for (j = n - 1; j > 0; j--) { n     if (a[j - 1] < t) { n       sum += a[j - 1]; n       t = a[j - 1]; n     } else { n       if (t - 1 >= 0) { n         sum += t - 1; n         t = t - 1; n       } else n         break; n     } n   } n   cout << sum; n } n


#include <bits/stdc++.h> n using namespace std; n inline char nc() { n   static char buf[100000], *l = buf, *r = buf; n   return l == r && (r = (l = buf) + fread(buf, 1, 100000, stdin), l == r) n              ? EOF n              : *l++; n } n template <class T> n void read(T &x) { n   x = 0; n   int f = 1, ch = nc(); n   while (ch <  0  || ch >  9 ) { n     if (ch ==  - ) f = -1; n     ch = nc(); n   } n   while (ch >=  0  && ch <=  9 ) { n     x = x * 10 -  0  + ch; n     ch = nc(); n   } n   x *= f; n } n const int inf = 1e9; n const int maxn = 3e5 + 50; n int n; n int a[maxn]; n int b[maxn]; n long long an; n namespace seg { n const int maxnode = maxn << 2; n int mn[maxnode]; n int cnt[maxnode]; n int tag[maxnode]; n inline void change(int u, int d) { n   mn[u] += d; n   tag[u] += d; n } n inline void pushup(int u) { n   mn[u] = min(mn[u << 1], mn[u << 1 | 1]); n   cnt[u] = 0; n   if (mn[u] == mn[u << 1]) cnt[u] += cnt[u << 1]; n   if (mn[u] == mn[u << 1 | 1]) cnt[u] += cnt[u << 1 | 1]; n } n inline void pushdown(int u) { n   if (tag[u]) { n     change(u << 1, tag[u]); n     change(u << 1 | 1, tag[u]); n     tag[u] = 0; n   } n } n void build(int u, int l, int r) { n   tag[u] = 0; n   if (l == r) { n     mn[u] = -l; n     cnt[u] = 1; n     return; n   } n   int mid = (l + r) >> 1; n   build(u << 1, l, mid); n   build(u << 1 | 1, mid + 1, r); n   pushup(u); n } n void update(int u, int l, int r, int ql, int qr, int qv) { n   if (l == ql && r == qr) { n     change(u, qv); n     return; n   } n   pushdown(u); n   int mid = (l + r) >> 1; n   if (qr <= mid) n     update(u << 1, l, mid, ql, qr, qv); n   else if (ql > mid) n     update(u << 1 | 1, mid + 1, r, ql, qr, qv); n   else { n     update(u << 1, l, mid, ql, mid, qv); n     update(u << 1 | 1, mid + 1, r, mid + 1, qr, qv); n   } n   pushup(u); n } n }  // namespace seg n void divide(int l, int r) { n   static int mn[maxn]; n   int hd0 = 1, tl0 = 0; n   static int mx[maxn]; n   int hd1 = 1, tl1 = 0; n   if (l == r) { n     return; n   } n   int mid = (l + r) >> 1; n   divide(l, mid); n   divide(mid + 1, r); n   int L = r - mid; n   seg::build(1, 1, L); n   for (int i = 1; i <= L; ++i) { n     b[i] = a[mid + i]; n     if (hd0 > tl0 || b[i] < b[mn[tl0]]) mn[++tl0] = i; n     if (hd1 > tl1 || b[i] > b[mx[tl1]]) mx[++tl1] = i; n   } n   mn[++tl0] = L + 1; n   mx[++tl1] = L + 1; n   for (int i = hd0; i < tl0; ++i) { n     seg::update(1, 1, L, mn[i], mn[i + 1] - 1, -b[mn[i]]); n   } n   for (int i = hd1; i < tl1; ++i) { n     seg::update(1, 1, L, mx[i], mx[i + 1] - 1, b[mx[i]]); n   } n   int Mx = -inf, Mn = inf; n   for (int i = mid; i >= l; --i) { n     seg::update(1, 1, L, 1, L, -1); n     if (a[i] < Mn) { n       if (hd0 != 1) seg::update(1, 1, L, 1, mn[hd0] - 1, Mn); n       Mn = a[i]; n       while (hd0 < tl0 && Mn < b[mn[hd0]]) { n         seg::update(1, 1, L, mn[hd0], mn[hd0 + 1] - 1, b[mn[hd0]]), ++hd0; n       } n       if (hd0 != 1) seg::update(1, 1, L, 1, mn[hd0] - 1, -Mn); n     } n     if (a[i] > Mx) { n       if (hd1 != 1) seg::update(1, 1, L, 1, mx[hd1] - 1, -Mx); n       Mx = a[i]; n       while (hd1 < tl1 && Mx > b[mx[hd1]]) { n         seg::update(1, 1, L, mx[hd1], mx[hd1 + 1] - 1, -b[mx[hd1]]), ++hd1; n       } n       if (hd1 != 1) seg::update(1, 1, L, 1, mx[hd1] - 1, Mx); n     } n     if (seg::mn[1] == -1) an += seg::cnt[1]; n   } n } n int main() { n   read(n); n   for (int i = 1; i <= n; ++i) { n     int r, c; n     read(r), read(c); n     a[r] = c; n   } n   an = n; n   divide(1, n); n   printf( %lld n , an); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 200000; n const long long maxp = 1000000007; n int n, m; n struct data { n   int adj, p, p_; n }; n vector<data> e[maxn]; n bool v[maxn]; n long long f[maxn][2][2][2]; n int con[maxn][2]; n void dfs(int x) { n   v[x] = false; n   bool flag = false; n   for (auto y : e[x]) n     if (v[y.adj]) { n       dfs(y.adj); n       flag = true; n       for (int i = 0; i < 2; ++i) n         for (int j = 0; j < 2; ++j) n           for (int k = 0; k < 2; ++k) n             for (int l = 0; l < 2; ++l) n               (f[x][i][k][l ^ ((y.p ^ i) | (y.p_ ^ j)) ^ con[x][i]] += n                f[y.adj][j][k][l]) %= maxp; n     } n   if (!flag) { n     f[x][1][1][con[x][1]] = 1; n     f[x][0][0][con[x][0]] = 1; n   } n } n int ind[maxn]; n int main() { n   scanf( %d%d , &m, &n); n   memset(ind, 0, sizeof(ind)); n   for (int i = 1; i <= m; ++i) { n     int k; n     scanf( %d , &k); n     int a, b; n     if (k == 1) { n       scanf( %d , &a); n       if (a < 0) n         con[-a][0] ^= 1; n       else n         con[a][1] ^= 1; n     } else { n       scanf( %d%d , &a, &b); n       int p1 = 0, p2 = 0; n       if (a < 0) { n         p1 = 1; n         a = -a; n       } n       if (b < 0) { n         p2 = 1; n         b = -b; n       } n       e[a].push_back({b, p1, p2}); n       e[b].push_back({a, p2, p1}); n       ind[a]++; n       ind[b]++; n     } n   } n   memset(v, true, sizeof(v)); n   memset(f, 0, sizeof(f)); n   long long ans[2], tmp[2]; n   ans[0] = 1; n   ans[1] = 0; n   int ab = 3; n   for (int i = 1; i <= n; ++i) n     if (v[i] && (ind[i] == 1 || ind[i] == 0)) { n       dfs(i); n       tmp[0] = ans[0]; n       tmp[1] = ans[1]; n       ans[0] = 0; n       ans[1] = 0; n       for (int p1 = 0; p1 < 2; ++p1) n         for (int p2 = 0; p2 < 2; ++p2) n           for (int u = 0; u < 2; ++u) n             for (int v = 0; v < 2; ++v) n               (ans[p1 ^ p2] += tmp[p1] * f[i][u][v][p2]) %= maxp; n     } n   for (int i = 1; i <= n; ++i) n     if (v[i]) { n       dfs(i); n       tmp[0] = ans[0]; n       tmp[1] = ans[1]; n       ans[0] = 0; n       ans[1] = 0; n       int p = e[i][1].p, p_ = e[i][1].p_; n       for (int p1 = 0; p1 < 2; ++p1) n         for (int p2 = 0; p2 < 2; ++p2) n           for (int u = 0; u < 2; ++u) n             for (int v = 0; v < 2; ++v) { n               (ans[p1 ^ p2 ^ ((u ^ p) | (v ^ p_))] += n                tmp[p1] * f[i][u][v][p2]) %= maxp; n             } n     } n   cout << ans[1] << endl; n } n


#include <bits/stdc++.h> n using namespace std; n inline long long read() { n   long long f = 1, x = 0; n   char s = getchar(); n   while (s <  0  || s >  9 ) { n     if (s ==  - ) f = -1; n     s = getchar(); n   } n   while (s >=  0  && s <=  9 ) { n     x = x * 10 + (s -  0 ); n     s = getchar(); n   } n   return x * f; n } n const int jzm = 1000000007; n const int zxy = 998244353; n int n, m, i, j, s, o, k; n int U[100005], V[100005], W[100005]; n struct it { n   int v, w; n   it() { v = w = 0; } n   it(int V, int W) { n     v = V; n     w = W; n   } n }; n vector<it> g[100005]; n vector<it> g2[100005]; n bool v[100005]; n long long dp1[100005] = {(long long)1e18}, dp2[100005] = {(long long)1e18}; n long long f1[100005][2], f2[100005][2]; n int tre1[100005 << 2], tre2[100005 << 2], M; n int bing1(int a, int b) { return dp1[a] < dp1[b] ? a : b; } n int bing2(int a, int b) { return dp2[a] < dp2[b] ? a : b; } n void maketree(int n) { n   M = 1; n   while (M < n + 2) M <<= 1; n } n void addt1(int x, int y) { n   int s = M + x; n   tre1[s] = y; n   s >>= 1; n   while (s) { n     tre1[s] = bing1(tre1[s << 1], tre1[s << 1 | 1]); n     s >>= 1; n   } n } n void addt2(int x, int y) { n   int s = M + x; n   tre2[s] = y; n   s >>= 1; n   while (s) { n     tre2[s] = bing2(tre2[s << 1], tre2[s << 1 | 1]); n     s >>= 1; n   } n } n int findall1() { return tre1[1]; } n int findall2() { return tre2[1]; } n bool cmp(long long *a, long long *b) { return a[0] == b[0] && a[1] == b[1]; } n int main() { n   n = read(); n   m = read(); n   int S = read(), T = read(); n   for (int i = 1; i <= m; i++) { n     s = read(); n     o = read(); n     k = read(); n     g[s].push_back(it(o, k)); n     g2[o].push_back(it(s, k)); n     U[i] = s; n     V[i] = o; n     W[i] = k; n   } n   maketree(n); n   for (int i = 1; i <= n; i++) dp1[i] = dp2[i] = 1e18; n   dp1[S] = 0; n   f1[S][0] = f1[S][1] = 1; n   addt1(S, S); n   dp2[T] = 0; n   f2[T][0] = f2[T][1] = 1; n   addt2(T, T); n   for (int i = 1; i < n; i++) { n     int t = findall1(); n     if (t == 0) break; n     for (int j = 0; j < g[t].size(); j++) { n       int y = g[t][j].v, w = g[t][j].w; n       if (dp1[t] + w < dp1[y]) { n         dp1[y] = dp1[t] + w; n         f1[y][0] = f1[t][0]; n         f1[y][1] = f1[t][1]; n         addt1(y, y); n       } else if (dp1[t] + w == dp1[y]) { n         (f1[y][0] += f1[t][0]) %= jzm; n         (f1[y][1] += f1[t][1]) %= zxy; n       } n     } n     addt1(t, 0); n   } n   for (int i = 1; i < n; i++) { n     int t = findall2(); n     if (t == 0) break; n     for (int j = 0; j < g2[t].size(); j++) { n       int y = g2[t][j].v, w = g2[t][j].w; n       if (dp2[t] + w < dp2[y]) { n         dp2[y] = dp2[t] + w; n         f2[y][0] = f2[t][0]; n         f2[y][1] = f2[t][1]; n         addt2(y, y); n       } else if (dp2[t] + w == dp2[y]) { n         (f2[y][0] += f2[t][0]) %= jzm; n         (f2[y][1] += f2[t][1]) %= zxy; n       } n     } n     addt2(t, 0); n   } n   long long F[2] = {f1[T][0], f1[T][1]}, le = dp1[T]; n   for (int i = 1; i <= m; i++) { n     s = U[i]; n     o = V[i]; n     k = W[i]; n     long long F2[2] = {f1[s][0] * 1ll * f2[o][0] % jzm, n                        f1[s][1] * 1ll * f2[o][1] % zxy}; n     if (dp1[s] + (long long)k + dp2[o] > le || !cmp(F, F2)) { n       if (le - 1 - dp1[s] - dp2[o] <= 0) n         printf( NO n ); n       else n         printf( CAN %d n , k - (le - 1 - dp1[s] - dp2[o])); n     } else n       printf( YES n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void setIO(string name) { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   freopen((name +  .in ).c_str(),  r , stdin); n   freopen((name +  .out ).c_str(),  w , stdout); n } n void fast() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n } n int main() { n   fast(); n   int r, c; n   cin >> r >> c; n   char a[r][c]; n   for (int i = 0; i < r; i++) { n     for (int j = 0; j < c; j++) { n       cin >> a[i][j]; n       if (a[i][j] ==  . ) { n         a[i][j] =  D ; n       } n     } n   } n   int f = 1; n   for (int i = 0; i < r; i++) { n     for (int j = 0; j < c; j++) { n       if (a[i][j] ==  S ) { n         if ((i - 1 >= 0 && a[i - 1][j] ==  W ) || n             (j - 1 >= 0 && a[i][j - 1] ==  W ) || n             (i + 1 <= r - 1 && a[i + 1][j] ==  W ) || n             (j + 1 <= c - 1 && a[i][j + 1] ==  W )) { n           f = 0; n           break; n         } n       } n     } n   } n   if (f) { n     cout <<  Yes  n          <<   n ; n     for (int i = 0; i < r; i++) { n       for (int j = 0; j < c; j++) { n         cout << a[i][j]; n       } n       cout <<   n ; n     } n   } else { n     cout <<  No  n          <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = 0x3f3f3f3f; n const long long INF = 0x3f3f3f3f3f3f3f3f; n const int MAXN = 1e5 + 10; n const int N = 102; n const long long mod = 1e9 + 7; n inline int read() { n   int x = 0, f = 1; n   char ch = getchar(); n   while (!isdigit(ch)) { n     if (ch ==  - ) f = -1; n     ch = getchar(); n   } n   while (isdigit(ch)) { n     x = x * 10 + ch - 48; n     ch = getchar(); n   } n   return x * f; n } n int a[5]; n int main() { n   ios::sync_with_stdio(false); n   int T; n   cin >> T; n   while (T--) { n     int A, B, C, D; n     memset(a, 0, sizeof(a)); n     cin >> A >> B >> C >> D; n     C += B; n     D += A; n     if ((A + B) % 2 == 0) { n       a[1] = a[2] = 0; n       if (C > 0) a[3] = 1; n       if (D > 0) a[4] = 1; n     } else { n       a[3] = a[4] = 0; n       if (C > 0) a[2] = 1; n       if (D > 0) a[1] = 1; n     } n     for (int i = 1; i <= 4; ++i) n       if (a[i]) n         cout <<  Ya  ; n       else n         cout <<  Tidak  ; n     cout <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long n, m, a, b, g[3005 * 3005], x, y, z, A[3005][3005], ans; n deque<long long> q; n vector<long long> v; n vector<vector<long long> > V; n vector<long long> fun(vector<long long> v, long long n, long long b) { n   vector<long long> ans; n   q.clear(); n   for (__typeof((b)) i = (0); i < (b); i++) { n     while ((long long)q.size() && v[i] <= v[q.back()]) q.pop_back(); n     q.push_back(i); n   } n   ans.push_back(v[q.front()]); n   for (__typeof((n)) i = (b); i < (n); i++) { n     while ((long long)q.size() && q.front() <= i - b) q.pop_front(); n     while ((long long)q.size() && v[i] <= v[q.back()]) q.pop_back(); n     q.push_back(i); n     ans.push_back(v[q.front()]); n   } n   return ans; n } n void solve() { n   cin >> n >> m >> a >> b >> g[0] >> x >> y >> z; n   for (__typeof((3005 * 3005)) i = (1); i < (3005 * 3005); i++) n     g[i] = (g[i - 1] * x + y) % z; n   for (__typeof((n + 1)) i = (1); i < (n + 1); i++) { n     for (__typeof((m + 1)) j = (1); j < (m + 1); j++) n       A[i][j] = g[(i - 1) * m + j - 1]; n   } n   for (__typeof((n + 1)) i = (1); i < (n + 1); i++) { n     v.clear(); n     for (__typeof((m + 1)) j = (1); j < (m + 1); j++) v.push_back(A[i][j]); n     V.push_back(fun(v, m, b)); n   } n   for (__typeof(((long long)V[0].size())) j = (0); j < ((long long)V[0].size()); n        j++) { n     v.clear(); n     for (__typeof((n)) i = (0); i < (n); i++) v.push_back(V[i][j]); n     vector<long long> res = fun(v, n, a); n     for (auto i : res) ans += i; n   } n   { n     cout << ans <<   n ; n     return; n   }; n } n void prep() {} n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long t = 1; n   prep(); n   cout << fixed << setprecision(12); n   while (t--) solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 100005; n const int inf = 0x3f3f3f3f; n int n, e[2][maxn], tot, rd[maxn]; n int net[maxn], tail[maxn]; n inline int read(void) { n   int num, sign = 1; n   char c; n   while (!isdigit(c = getchar())) n     if (c ==  - ) sign = 0; n   num = c -  0 ; n   while (isdigit(c = getchar())) num = (num << 1) + (num << 3) + c -  0 ; n   return sign ? num : -num; n } n int dfs(int u) { n   tail[u] = u; n   if (!tail[net[u]]) return tail[u] = dfs(net[u]); n   return tail[u]; n } n signed main(void) { n   n = read(); n   for (register int i = 1; i <= n; ++i) net[i] = read(), ++rd[net[i]]; n   for (register int i = 1; i <= n; ++i) n     if (!rd[i]) { n       e[0][++tot] = i; n       e[1][tot] = dfs(i); n     } n   int ft = tot; n   for (register int i = 1; i <= n; ++i) n     if (!tail[i]) { n       e[0][++tot] = i; n       e[1][tot] = dfs(i); n     } n   if (tot == 1 && !ft) tot = 0; n   printf( %d n , tot); n   for (register int i = 1; i <= tot; ++i) n     printf( %d %d n , e[1][i], e[0][i % tot + 1]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n using ld = long double; n int main() { n   ios_base::sync_with_stdio(0); n   cout.tie(0); n   cin.tie(0); n   int q; n   cin >> q; n   for (int i = 0; i < q; i++) { n     ll k, n, a, b; n     cin >> k >> n >> a >> b; n     if (k - n * b <= 0) { n       cout << -1 <<   n ; n       continue; n     } n     ll l = -1, r = n; n     while (r - l > 1) { n       ll m = (l + r) / 2; n       if (k - m * b - (n - m) * a > 0) { n         r = m; n       } else { n         l = m; n       } n     } n     cout << n - r <<   n ; n   } n } n


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


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e5 + 10, mod = 1e9 + 7; n const long long inf = 1e18; n unsigned int dp[maxn]; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(); n   int n, cnt = 0; n   cin >> n; n   string s; n   cin >> s; n   if (n & 1) return cout << 0 << endl, 0; n   dp[0] = 1; n   for (int i = 0; i < n; i++) { n     if (s[i] !=  ? ) { n       cnt++; n       for (int j = i + 1; j >= 0; j -= 2) dp[j] = (j == 0 ? 0 : dp[j - 1]); n     } else { n       for (int j = i + 1; j >= 0; j -= 2) n         dp[j] = dp[j + 1] + (j == 0 ? 0 : dp[j - 1]); n     } n   } n   int num = (n - 2 * cnt) / 2; n   unsigned int ans = dp[0]; n   for (int i = 0; i < num; i++) ans *= 25; n   return cout << ans << endl, 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   vector<int> v; n   int n, i, j, k, len, x, y, c, a[1020] = {0}; n   cin >> n; n   if (n == 1) { n     cout <<  0  << endl; n     return 0; n   } n   a[1] = 1; n   for (i = 2; i <= 1000; i++) { n     c = 2; n     for (j = i * c; j <= 1000; j = i * c) { n       a[j] = 1; n       c++; n     } n   } n   for (i = 2; i <= n; i++) { n     if (a[i] == 0) { n       for (j = i; j <= n; j = j * i) { n         v.push_back(j); n       } n     } n   } n   cout << v.size() << endl; n   for (i = 0; i < v.size(); i++) { n     cout << v[i] <<    ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int n, t; n int visited[30009]; n bool ok = false; n vector<int> C[30009]; n void dfs(int u) { n   if (u == t) { n     ok = true; n     return; n   } n   visited[u] = 1; n   if (C[u].size()) n     for (int i = 0; i <= C[u].size() - 1; i++) { n       int v = C[u][i]; n       if (!visited[v] && v <= n) { n         dfs(v); n         if (ok) return; n       } n     } n } n int main() { n   scanf( %d%d , &n, &t); n   for (int i = 1; i <= n - 1; i++) { n     int x; n     scanf( %d , &x); n     C[i].push_back(x + i); n   } n   dfs(1); n   if (ok) n     cout <<  YES  << endl; n   else n     cout <<  NO  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> G[((int)2e5 + 10)]; n int dis[((int)2e5 + 10)]; n int n; n int ans = 0; n void dfs(int f, int son, int d) { n   int flag = 0; n   dis[son] = d; n   for (int i = 0; i < G[son].size(); i++) { n     if (G[son][i] == f) continue; n     dfs(son, G[son][i], d + 1); n     if (dis[G[son][i]] > 2) { n       flag = 1; n       dis[G[son][i]] = 2; n       dis[son] = 1; n       dis[f] = 2; n     } n   } n   ans += flag; n } n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n - 1; i++) { n     int x, y; n     scanf( %d %d , &x, &y); n     G[x].push_back(y); n     G[y].push_back(x); n   } n   dfs(-1, 1, 0); n   cout << ans <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 100005, MAXT = 500, INF = 0x3f3f3f3f; n int mx[MAXT], add[MAXT], sz[MAXT], num[MAXT][MAXT], A[MAXN]; n int N, T = 314; n void upd(int p) { n   if (add[p]) { n     for (int i = 0; i < sz[p]; ++i) num[p][i] += add[p]; n     add[p] = 0; n   } n } n void ins(int x, int k) { n   int p = x / T; n   x = x % T; n   for (int i = 0; i < p; ++i) add[i] += k, mx[i] += k; n   upd(p); n   for (int i = 0; i <= x; ++i) num[p][i] += k; n   mx[p] = -INF; n   for (int i = 0; i < sz[p]; ++i) mx[p] = max(mx[p], num[p][i]); n } n int query() { n   int p = (N - 1) / T; n   while (p >= 0 && mx[p] <= 0) p--; n   if (p < 0) return -1; n   upd(p); n   int x = sz[p] - 1; n   while (num[p][x] <= 0) x--; n   return A[p * T + x]; n } n int main() { n   scanf( %d , &N); n   int p = (N - 1) / T; n   for (int i = 0; i < p; ++i) sz[i] = T; n   sz[p] = (N - 1) % T + 1; n   for (int i = 0; i < N; ++i) { n     int a, b, c; n     scanf( %d%d , &a, &b); n     if (b) { n       scanf( %d , &c); n       A[a - 1] = c; n       ins(a - 1, 1); n       printf( %d n , query()); n     } else { n       ins(a - 1, -1); n       printf( %d n , query()); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double EPS = 1e-11; n long long n, l, v1, v2, k; n bool check(double tim) { n   int tmp = n; n   double t = 0; n   double grx = 0, bus = 0; n   while (tmp > 0) { n     double del = l - grx; n     if (del / v2 > tim + EPS / 100) { n       return 0; n     } n     double x = (v1 * tim - del) * v2 * 1.0 / (v1 - v2); n     double step = x / v2; n     tim -= step; n     bus += x; n     tmp -= k; n     if (tmp <= 0) break; n     grx += step * v1; n     double step2 = (bus - grx) / (v1 + v2); n     grx += step2 * v1; n     tim -= step2; n     if (tim < -EPS / 100) return 0; n     bus = grx; n   } n   return 1; n } n double bs(double lo, double hi) { n   if ((hi - lo) <= EPS * 10 || (hi - lo) / hi <= EPS * 10) { n     return lo; n   } n   double mid = (lo + hi) / 2; n   if (check(mid)) { n     return bs(lo, mid); n   } n   return bs(mid, hi); n } n int main() { n   if (fopen( D.in ,  r )) freopen( D.in ,  r , stdin); n   cin >> n >> l >> v1 >> v2 >> k; n   cout << setprecision(10) << bs(0, 1e10); n   return 0; n } n


#include <iostream> n #include <cstdio> n #include <cmath> n #include <ctime> n #include <cstdlib> n #include <cassert> n #include <vector> n #include <list> n #include <stack> n #include <queue> n #include <deque> n #include <map> n #include <set> n #include <bitset> n #include <string> n #include <algorithm> n #include <utility> n #include <complex> n #define rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++) n #define reps(x, s) for(llint (x) = 0; (x) < (llint)(s).size(); (x)++) n #define chmin(x, y) (x) = min((x), (y)) n #define chmax(x, y) (x) = max((x), (y)) n #define sz(x) ((ll)(x).size()) n #define ceil(x, y) (((x)+(y)-1) / (y)) n #define all(x) (x).begin(),(x).end() n #define outl(...) dump_func(__VA_ARGS__) n #define inf 1e18 n  n using namespace std; n  n typedef long long llint; n typedef long long ll; n typedef pair<ll, ll> P; n  n struct edge{ n  ll to, cost; n  edge(){} n  edge(ll a, ll b){ to = a, cost = b;} n }; n const ll dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1}; n  n const ll mod = 1000000007; n //const ll mod = 998244353; n  n struct mint{ n  ll x = 0; n  mint(ll y = 0){x = y; if(x < 0 || x >= mod) x = (x%mod+mod)%mod;} n  mint(const mint &ope) {x = ope.x;} n   n  mint operator-(){return mint(-x);} n  mint operator+(const mint &ope){return mint(x) += ope;} n  mint operator-(const mint &ope){return mint(x) -= ope;} n  mint operator*(const mint &ope){return mint(x) *= ope;} n  mint operator/(const mint &ope){return mint(x) /= ope;} n  mint& operator+=(const mint &ope){ n   x += ope.x; n   if(x >= mod) x -= mod; n   return *this; n  } n  mint& operator-=(const mint &ope){ n   x += mod - ope.x; n   if(x >= mod) x -= mod; n   return *this; n  } n  mint& operator*=(const mint &ope){ n   x *= ope.x, x %= mod; n   return *this; n  } n  mint& operator/=(const mint &ope){ n   ll n = mod-2; mint mul = ope; n   while(n){ n    if(n & 1) *this *= mul; n    mul *= mul; n    n >>= 1; n   } n   return *this; n  } n  mint inverse(){return mint(1) / *this;} n  bool operator ==(const mint &ope){return x == ope.x;} n  bool operator !=(const mint &ope){return x != ope.x;} n }; n mint modpow(mint a, ll n){ n  if(n == 0) return mint(1); n  if(n % 2) return a * modpow(a, n-1); n  else return modpow(a*a, n/2); n } n istream& operator >>(istream &is, mint &ope){ n  ll t; is >> t, ope.x = t; n  return is; n } n ostream& operator <<(ostream &os, mint &ope){return os << ope.x;} n ostream& operator <<(ostream &os, const mint &ope){return os << ope.x;} n  n bool exceed(ll x, ll y, ll m){return x >= m / y + 1;} n void mark(){ cout <<  *  << endl; } n void yes(){ cout <<  Yes  << endl; } n void no(){ cout <<  No  << endl; } n ll gcd(ll a, ll b){if(b == 0) return a; return gcd(b, a%b);} n ll digitnum(ll x, ll b = 10){ll ret = 0; for(; x; x /= b) ret++; return ret;} n ll digitsum(ll x, ll b = 10){ll ret = 0; for(; x; x /= b) ret += x % b; return ret;} n  n template<typename T> n ostream& operator << (ostream& os, vector<T>& vec) { n  for(int i = 0; i < vec.size(); i++) { n   os << vec[i] << (i + 1 == vec.size() ?    :    ); n  } n  return os; n } n template<typename T> n ostream& operator << (ostream& os, deque<T>& deq) { n  for(int i = 0; i < deq.size(); i++) { n   os << deq[i] << (i + 1 == deq.size() ?    :    ); n  } n  return os; n } n template<typename T, typename U> n ostream& operator << (ostream& os, pair<T, U>& pair_var) { n  os <<  (  << pair_var.first <<  ,   << pair_var.second <<  ) ; n  return os; n } n template<typename T, typename U> n ostream& operator << (ostream& os, const pair<T, U>& pair_var) { n  os <<  (  << pair_var.first <<  ,   << pair_var.second <<  ) ; n  return os; n } n template<typename T, typename U> n ostream& operator << (ostream& os, map<T, U>& map_var) { n  for(typename map<T, U>::iterator itr = map_var.begin(); itr != map_var.end(); itr++) { n   os <<  (  << itr->first <<  ,   << itr->second <<  ) ; n   itr++; n   if(itr != map_var.end()) os <<  , ; n   itr--; n  } n  return os; n } n template<typename T> n ostream& operator << (ostream& os, set<T>& set_var) { n  for(typename set<T>::iterator itr = set_var.begin(); itr != set_var.end(); itr++) { n   os << *itr; n   ++itr; n   if(itr != set_var.end()) os <<    ; n   itr--; n  } n  return os; n } n template<typename T> n void outa(T a[], ll s, ll t) n { n  for(ll i = s; i <= t; i++){ cout << a[i]; if(i < t) cout <<    ;} n  cout << endl; n } n void dump_func() {cout << endl;} n template <class Head, class... Tail> n void dump_func(Head &&head, Tail &&... tail) { n  cout << head; n  if(sizeof...(Tail) > 0) cout <<    ; n  dump_func(std::move(tail)...); n } n  n  n ll n; n ll a[200005], b[200005], p[400005], f[400005]; n ll c[400005]; n set<ll> S; n  n int main(void) n { n  ios::sync_with_stdio(0); n  cin.tie(0); n   n  cin >> n; n  rep(i, 1, n) cin >> a[i] >> b[i], f[a[i]] = 1, p[a[i]] = b[i], p[b[i]] = a[i]; n  rep(i, 1, 2*n) S.insert(i); n   n  priority_queue<P, vector<P>, greater<P> > leftQ; n  priority_queue<P> rightQ; n   n  ll ans = 0; n  while(sz(S)){ n   ll s = *S.begin(); n   leftQ.push(P(s, 1)); n   c[s] = 1; n   S.erase(s); n    n   ll cnt = 0, fcnt = 0; n   while(sz(leftQ) + sz(rightQ)){ n    while(sz(leftQ)){ n     cnt++; n     ll x = leftQ.top().first, y = leftQ.top().second; leftQ.pop(); n     //outl(x, y); n      n     c[x] = y; if(y != f[x]) fcnt++; n     ll px = p[x]; n     c[px] = 1-y; n     S.erase(px); n      n     for(auto it = S.upper_bound(px); it != S.end();){ n      rightQ.push(P(*it, y)); n      auto tmp = it; n      it++; n      S.erase(tmp); n     } n    } n    while(sz(rightQ)){ n     cnt++; n     ll x = rightQ.top().first, y = rightQ.top().second; rightQ.pop(); n     //outl(x, y); n      n     c[x] = y;  if(y != f[x]) fcnt++; n     ll px = p[x]; n     c[px] = 1-y; n     S.erase(px); n      n     for(auto it = S.begin(); it != S.end() && *it < px;){ n      leftQ.push(P(*it, y)); n      auto tmp = it; n      it++; n      S.erase(tmp); n     } n    } n   } n    n   ans += min(fcnt, cnt-fcnt); n  } n   n  vector<ll> vec; n  rep(i, 1, 2*n) if(c[i]) vec.push_back(i); n  sort(all(vec)); n   n  rep(i, 1, sz(vec)-1) if(p[vec[i-1]] < p[vec[i]]){ n   outl(-1); n   return 0; n  } n  outl(ans); n   n  return 0; n }


#include <bits/stdc++.h> n using namespace std; n int main() { n   int a[112]; n   int i; n   for (i = 0; i < 4; i++) cin >> a[i]; n   sort(a, a + 4); n   int tr = 0, seg = 0, im = 0; n   if (a[1] + a[2] > a[3]) { n     tr++; n   } else if (a[0] + a[1] > a[3]) { n     tr++; n   } else if (a[0] + a[2] > a[3]) { n     tr++; n   } else if (a[0] + a[1] > a[2]) { n     tr++; n   } else if (a[0] + a[1] == a[2]) n     seg++; n   else if (a[0] + a[2] == a[3]) n     seg++; n   else if (a[1] + a[2] == a[3]) n     seg++; n   else if (a[0] + a[1] == a[3]) n     seg++; n   else n     im++; n   if (tr > 0) n     cout <<  TRIANGLE  << endl; n   else if (seg > 0) n     cout <<  SEGMENT  << endl; n   else if (im > 0) n     cout <<  IMPOSSIBLE  << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int dy[] = {-1, 0, 1, 0}, dx[] = {0, 1, 0, -1}; n const double EPS = 1e-8; n const double PI = acos(-1.0); n int popcount(int n) { return __builtin_popcount(n); } n int popcount(long long n) { return __builtin_popcountll(n); } n template <class T> n int SIZE(T a) { n   return a.size(); n } n template <class T> n string IntToString(T num) { n   string res; n   stringstream ss; n   ss << num; n   return ss.str(); n } n template <class T> n T StringToInt(string str) { n   T res = 0; n   for (int i = 0; i < SIZE(str); i++) res = (res * 10 + str[i] -  0 ); n   return res; n } n template <class T> n T gcd(T a, T b) { n   if (b == 0) return a; n   return gcd(b, a % b); n } n template <class T> n T lcm(T a, T b) { n   return a / gcd(a, b) * b; n } n template <class T> n void PrintSeq(T &a, int sz) { n   for (int i = 0; i < sz; i++) { n     cout << a[i]; n     if (sz == i + 1) n       cout << endl; n     else n       cout <<    ; n   } n } n long long getTen(int a) { return (a <= 0) ? 1 : (getTen(a - 1) * 10); } n bool EQ(double a, double b) { return abs(a - b) < EPS; } n void fastStream() { n   cin.tie(0); n   std::ios_base::sync_with_stdio(0); n } n vector<string> split(string str, char del) { n   vector<string> res; n   for (int i = 0, s = 0; i < SIZE(str); i++) { n     if (str[i] == del) { n       if (i - s != 0) res.push_back(str.substr(s, i - s)); n       s = i + 1; n     } else if (i == SIZE(str) - 1) { n       res.push_back(str.substr(s)); n     } n   } n   return res; n } n int N; n int as[500001]; n int valToPos[500010]; n int posToVal[500010]; n const int MAX_N = 5000100; n class BIT { n  private: n   long long bit[MAX_N]; n   int n; n  n  public: n   BIT(int sz) { n     n = sz; n     for (int i = 0; i <= n; i++) bit[i] = 0; n   } n   long long sum(int i) { n     long long s = 0; n     while (i > 0) { n       s += bit[i]; n       i -= i & -i; n     } n     return s; n   } n   long long rangeSum(int from, int to) { n     long long res = 0; n     res = sum(to) - sum(from - 1); n     return res; n   } n   void add(int i, long long x) { n     while (i <= n) { n       bit[i] += x; n       i += i & -i; n     } n   } n   void insert(int i, long long x) { add(i, -(sum(i) - sum(i - 1)) + x); } n }; n BIT bit(1000000); n int main() { n   cin >> N; n   for (int i = 0; i < N; i++) { n     cin >> as[i]; n     posToVal[i] = as[i]; n     valToPos[as[i]] = i; n   } n   for (int i = 0; i < N; i++) { n     if (as[i] == 1) n       bit.add(1, 0); n     else { n       int pos1 = i; n       int pos2 = valToPos[as[i] - 1]; n       if (pos2 > pos1) { n         bit.add(as[i], 1); n       } n     } n   } n   int Q; n   cin >> Q; n   for (int i = 0; i < Q; i++) { n     int p, x, y; n     cin >> p >> x >> y; n     if (p == 1) { n       cout << bit.rangeSum(x, y) + 1 - bit.rangeSum(x, x) << endl; n     } else { n       int posx = x - 1; n       int posy = y - 1; n       x = posToVal[posx]; n       y = posToVal[posy]; n       valToPos[x] = posy; n       valToPos[y] = posx; n       posToVal[posx] = y; n       posToVal[posy] = x; n       int ary[6] = {x, x - 1, x + 1, y, y - 1, y + 1}; n       for (int j = 0; j < 6; j++) { n         int num = ary[j]; n         if (num == 0) n           continue; n         else if (num == 1) n           continue; n         else { n           int pos1 = valToPos[num]; n           int pos2 = valToPos[num - 1]; n           if (pos2 > pos1) n             bit.insert(num, 1); n           else n             bit.insert(num, 0); n         } n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void fast() { n   ios_base::sync_with_stdio(NULL); n   cin.tie(0); n   cout.tie(0); n } n void online_judge() { n   freopen( input.txt ,  r , stdin); n   freopen( output.txt ,  w , stdout); n } n const int flag_max = 0x3f3f3f3f; n const long long OO = 1e9; n const double EPS = (1e-7); n int dcmp(double x, double y) { return fabs(x - y) <= EPS ? 0 : x < y ? -1 : 1; } n long long gcd(long long a, long long b) { return !b ? a : gcd(b, a % b); } n long long lcm(long long a, long long b) { return (a / gcd(a, b)) * b; } n int n, p; n int F = 0; n map<pair<int, int>, bool> check; n vector<pair<int, int>> pa_ir; n void dfs(int star) { n   for (int i = star + 1; i <= n; i++) { n     if (!check[{star, i}]) { n       F++; n       check[{star, i}] = 1; n       check[{i, star}] = 1; n       pa_ir.push_back({star, i}); n       dfs(i); n     } n   } n } n int main() { n   fast(); n   int t; n   cin >> t; n   while (t--) { n     cin >> n >> p; n     p = 2 * n + p; n     pa_ir.clear(); n     check.clear(); n     dfs(1); n     sort(((pa_ir).begin()), ((pa_ir).end())); n     for (int i = 0; i < p; i++) { n       cout << pa_ir[i].first <<     << pa_ir[i].second <<   n ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; namespace { n     using T = long long; n     constexpr char endl =   n ; n     const int maxN = 205; n     const int maxM = 1e5 + 5; n     const T base = 100000; n  n     T Ceil(T x, T y) { n         return (x + y - 1) / y; n     } n  n     int n, m; n     T t[maxN], x[maxN], y[maxN]; n     bool f[maxM];    n     int ans[maxM]; n  n     void Reach(int i, int x) { n         if(!f[x]) n             ans[x] = i, f[x] = true; n     } n  n     void Solve() { n         cin >> n >> m; n         for(int i = 1; i <= n; i++) n             cin >> t[i] >> x[i] >> y[i]; n         for(int i = 1; i <= m; i++) n             ans[i] = -1; n         f[0] = true; n         for(int i = 1; i <= n; i++)  n             for(int j = m; j >= 0; j--) if(f[j]) { n                 T now = j; n                 for(int k = 1; k <= y[i]; k++) { n                     if(t[i] == 1)   now += Ceil(x[i], base); n                     else            now = Ceil(now * x[i], base); n                     if(now > m || f[now]) n                         break; n                     Reach(i, now); n                 } n             } n         for(int i = 1; i <= m; i++) n             cout << ans[i] <<    n [i == m]; n     } n } n int main() { n     cin.tie(nullptr)->sync_with_stdio(false); n     int t(1); //cin >> t; n     for(int i = 1; i <= t; i++) Solve(); n     cout << flush; n     return 0; n }


#include <bits/stdc++.h> n using namespace std; n int n, maxi[((int)101 * 1000) / ((int)350) + 1000], fnsh, id[((int)101 * 1000)], n     ex[((int)101 * 1000)]; n vector<int> v[((int)101 * 1000) / ((int)350) + 1000]; n void reset() { n   int num = 0; n   for (int i = 0; i < fnsh; v[i].clear(), v[i].resize(0), i++) n     for (auto u : v[i]) ex[num++] = u; n   fnsh = 0; n   maxi[0] = 0; n   for (int i = 0; i < num; i++) { n     v[fnsh].push_back(ex[i]); n     maxi[fnsh] = max(maxi[fnsh], ex[i]); n     if (i % ((int)350) == ((int)350) - 1 || i == num - 1) n       fnsh++, maxi[fnsh] = 0; n   } n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cin >> n; n   for (int i = 0; i < n; i++) { n     int a, c; n     cin >> a >> c; n     id[a] = i + 1; n     bool flg = 0; n     for (int j = 0, num = 0; j < fnsh && !flg; num += (int)v[j].size(), j++) n       if (num + (int)v[j].size() > c || maxi[j] > a) { n         flg = 1; n         for (int k = 0; k < v[j].size(); k++) { n           if (v[j][k] > a) { n             v[j].insert(v[j].begin() + k, a); n             break; n           } n           if (k + num == c) { n             v[j].insert(v[j].begin() + k, a); n             maxi[j] = max(maxi[j], a); n             break; n           } n         } n       } n     if (!flg) { n       v[fnsh].push_back(a); n       maxi[fnsh] = a; n       fnsh++; n     } n     if (i % ((int)350) == ((int)350) - 1) reset(); n   } n   for (int i = fnsh - 1; i >= 0; i--) n     for (int j = (int)v[i].size() - 1; j >= 0; j--) cout << id[v[i][j]] <<    ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline int _Int() { n   int x; n   scanf( %d , &x); n   return x; n } n long long int bigMod(long long int A, long long int P, int M) { n   long long int R = 1; n   for (A %= M; P; P >>= 1) { n     if (P & 1) R = (R * A) % M; n     A = (A * A) % M; n   } n   return R; n } n long long int bigMul(long long int A, long long int B, long long int M) { n   long long int R = 0; n   for (A %= M; B; B >>= 1) { n     if (B & 1) R = (R + A) % M; n     A = (A + A) % M; n   } n   return R; n } n long long int negMod(long long int A, long long int B) { n   return (((A % B) + B) % B); n } n unsigned long long int _pow(unsigned long long int A, int P) { n   unsigned long long int R = 1; n   for (; P; P >>= 1) { n     if (P & 1) R = (R * A); n     A = (A * A); n   } n   return R; n } n template <class T> n T GCD(T x, T y) { n   while (x) x ^= y ^= x ^= y %= x; n   return y; n } n bool isVowel(char c) { n   if (c ==  A ) return 1; n   if (c ==  E ) return 1; n   if (c ==  I ) return 1; n   if (c ==  O ) return 1; n   if (c ==  U ) return 1; n   if (c ==  Y ) return 1; n   return 0; n } n char s[100 + 7]; n void Main() { n   scanf( %s , s + 1); n   int left = 0; n   int n = strlen(s + 1), mx = 1; n   for (int i = 1; i <= n; i++) { n     if (isVowel(s[i])) { n       mx = max(mx, i - left); n       left = i; n     } n   } n   mx = max(mx, n + 1 - left); n   printf( %d n , mx); n } n int main() { n   Main(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n string to_string(string s) { return     + s +    ; } n string to_string(char c) { return      + string(1, c) +     ; } n string to_string(const char *s) { return to_string((string)s); } n string to_string(bool b) { return (b ?  true  :  false ); } n template <typename A, typename B> n string to_string(pair<A, B> p) { n   return  (  + to_string(p.first) +  ,   + to_string(p.second) +  ) ; n } n template <typename A> n string to_string(A v) { n   bool first = true; n   string res =  { ; n   for (const auto &x : v) { n     if (!first) res +=  ,  ; n     first = false; n     res += to_string(x); n   } n   res +=  } ; n   return res; n } n void debug_out() { cerr << endl; } n template <typename Head, typename... Tail> n void debug_out(Head H, Tail... T) { n   cerr <<     << to_string(H); n   debug_out(T...); n } n const int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0}; n string to_str(const int &n) { n   ostringstream stm; n   stm << n; n   return stm.str(); n } n string to_str(const long long &n) { n   ostringstream stm; n   stm << n; n   return stm.str(); n } n template <class T> n string tostring(T x, int len = 0) { n   stringstream ss; n   ss << x; n   string r = ss.str(); n   if (int((r).size()) < len) r = string(len - int((r).size()),  0 ) + r; n   return r; n } n template <class T> n void convert(string x, T &r) { n   stringstream ss(x); n   ss >> r; n } n long long powmod(long long a, long long b) { n   long long res = 1; n   a %= 1000000007; n   for (; b; b >>= 1) { n     if (b & 1) res = res * a % 1000000007; n     a = a * a % 1000000007; n   } n   return res; n } n long long modinv(long long a) { return powmod(a, 1000000007 - 2); } n long long modinv(long long a, long long m) { return powmod(a, m - 2); } n long long nCkMp(long long n, long long k) { n   long long numerator = 1, denominator = 1; n   for (int i = 0; i < k; i++) numerator = (numerator * (n - i)) % 1000000007; n   for (int i = 1; i <= k; i++) denominator = (denominator * i) % 1000000007; n   return (numerator * modinv(denominator)) % 1000000007; n } n long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } n long long lcm(long long a, long long b) { return a * (b / gcd(a, b)); } n int TT = 1, tt; n clock_t t1; n void solve() { n   t1 = clock(); n   int n; n   long long a; n   long long b; n   (cin >> (n)); n   vector<int> x(n); n   for (auto i = (0); i < (n); i++) (cin >> (x[i])); n   sort((x).begin(), (x).end()); n   b = x[n - 1]; n   a = accumulate((x).begin(), (x).end(), 0ll) - b; n   (cout << (abs(a - b) + 1) << endl); n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   for (tt = 0; tt < TT; tt++) solve(); n   return EXIT_SUCCESS; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long n; n   cin >> n; n   map<long long, vector<long long> > m; n   map<long long, bool> v; n   map<long long, long long> c; n   vector<long long> b; n   long long i, j, k, x, y, r; n   for (i = 1; i <= n; i++) { n     cin >> x >> y; n     if (x == -1) n       r = i; n     else n       m[x].push_back(i); n     v[i] = false; n     c[i] = y; n   } n   for (i = 1; i <= n; i++) { n   } n   queue<long long> q; n   q.push(r); n   long long f = 1; n   while (!q.empty()) { n     j = q.front(); n     if (c[j] == 1) f = 0; n     for (i = 0; i < m[j].size(); i++) { n       q.push(m[j][i]); n       if (c[m[j][i]] != 1 and !f) { n         f = 1; n       } n     } n     if (f == 0) { n       b.push_back(j); n     } n     f = 1; n     q.pop(); n   } n   if (b.size() == 0) n     cout << -1; n   else { n     sort(b.begin(), b.begin() + b.size()); n     for (i = 0; i < b.size(); i++) { n       cout << b[i] <<    ; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 0x3f3f3f3f; n const double eps = 1e-8; n const double PI = acos(-1.0); n const int maxn = 370360; n int dp[maxn], k, vis[maxn], sp[maxn], head, tail; n long long q[maxn]; n int gcd(int x, int y) { n   int tp = x % y; n   while (tp) { n     x = y; n     y = tp; n     tp = x % y; n   } n   return y; n } n int dfs(int x) { n   int tp = INF, i; n   if (dp[x] != -1) return dp[x]; n   for (i = 2; i <= k; i++) n     if (x % i != 0) tp = min(dfs(x - x % i), tp); n   tp = min(dfs(x - 1), tp); n   return dp[x] = tp + 1; n } n int bfs(int st, int ed) { n   int i; n   memset(vis, 0, sizeof vis); n   head = tail = 0; n   vis[st] = 1; n   q[tail] = st; n   sp[tail++] = 0; n   while (head < tail) { n     if (q[head] == ed) return sp[head]; n     for (i = 2; i <= k; i++) { n       if (!vis[q[head] - q[head] % i]) { n         vis[q[head] - q[head] % i] = 1; n         q[tail] = q[head] - q[head] % i; n         sp[tail++] = sp[head] + 1; n       } n     } n     if (!vis[q[head] - 1]) { n       vis[q[head] - 1] = 1; n       q[tail] = q[head] - 1; n       sp[tail++] = sp[head] + 1; n     } n     head++; n   } n   return -1; n } n int main() { n   int i, mc; n   long long a, b, df, ans, rep; n   while (~scanf( %I64d%I64d%d , &a, &b, &k)) { n     mc = 1, ans = 0; n     for (i = 2; i <= k; i++) mc = (mc * i) / gcd(mc, i); n     for (i = 1; i < mc; i++) dp[i] = -1; n     dp[0] = 0; n     for (i = 1; i < mc; i++) dfs(i); n     if (a - a % mc > b) ans += dp[a % mc], a -= a % mc; n     df = a - b; n     rep = df / mc; n     a = a - rep * mc; n     ans += rep * (1 + dp[mc - 1]); n     df = a - b; n     if (df > 0) { n       if (a % mc == 0) n         ans += bfs((a - 1) % mc, b % mc) + 1; n       else n         ans += bfs(a % mc, b % mc); n     } n     printf( %I64d n , ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int size = 1e5 + 10; n int afx[size]; n int dis[size]; n int main() { n   int n, k; n   scanf( %d%d , &n, &k); n   int total = 0; n   int ans = 0; n   for (int i = 0; i < n; i++) { n     scanf( %d , afx + i); n     dis[i] = 10 - afx[i] % 10; n     total += dis[i]; n     ans += afx[i] / 10; n   } n   if (k <= total) { n     sort(dis, dis + n); n     int i = 0; n     while (k && i < n) { n       k -= dis[i]; n       if (k < 0) break; n       ans++; n       i++; n     } n     printf( %d n , min(10 * n, ans)); n     return 0; n   } n   k -= total; n   ans += n; n   ans += k / 10; n   printf( %d n , min(10 * n, ans)); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int d[100]; n int main() { n   int n, a, b, c = 0; n   cin >> n; n   for (int i = 1; i < n; i++) { n     cin >> d[i]; n   } n   cin >> a >> b; n   for (int i = a; i < b; i++) { n     c += d[i]; n   } n   cout << c; n   return 0; n } n