#include <bits/stdc++.h> n using namespace std; n const long long inf = 1e18; n const long long mod = 998244353; n const long long maxn = 5e4 + 10, maxval = 1e9 + 10, mlg = (1 << 18) + 10; n struct edge { n   long long u, v, c, t; n } ed[maxn * 6]; n long long n, m, cnt; n long long ans[maxn * 6], comp[maxn * 6], mark1[6 * maxn], mark2[6 * maxn]; n vector<long long> ts, nei[maxn * 6][2], adj[maxn * 6]; n map<long long, long long> mp; n long long N(long long x) { n   if (x <= m) { n     return x + m; n   } else if (x <= 2 * m) { n     return x - m; n   } else if (x <= 4 * m) { n     return x + 2 * m; n   } else { n     return x - 2 * m; n   } n } n void add_con(long long x, long long y) { n   long long nagh_x = N(x); n   long long nagh_y = N(y); n   nei[nagh_x][1].push_back(y); n   nei[y][0].push_back(nagh_x); n   nei[nagh_y][1].push_back(x); n   nei[x][0].push_back(nagh_y); n } n void dfs1(long long u) { n   mark1[u] = 1; n   for (auto v : nei[u][1]) { n     if (!mark1[v]) { n       dfs1(v); n     } n   } n   ts.push_back(u); n } n void dfs2(long long u) { n   mark2[u] = 1; n   comp[u] = cnt; n   for (auto v : nei[u][0]) { n     if (!mark2[v]) { n       dfs2(v); n     } n   } n } n bool ch(long long x) { n   long long tmp_cnt = 0; n   cnt = 0; n   for (int i = 0; i <= 6 * m; i++) { n     nei[i][1].clear(); n     nei[i][0].clear(); n     comp[i] = 0; n     mark1[i] = 0; n     mark2[i] = 0; n     ans[i] = 0; n   } n   for (int i = 0; i < m; i++) { n     if (ed[i + 1].t > x) { n       nei[i + 1][1].push_back(i + 1 + m); n       nei[i + 1 + m][0].push_back(i + 1); n     } n   } n   for (int i = 1; i <= n; i++) { n     mp.clear(); n     for (int j = 0; j < adj[i].size(); j++) { n       tmp_cnt++; n       if (j > 0) { n         add_con(N(2 * m + tmp_cnt - 1), N(adj[i][j])); n         add_con(N(2 * m + tmp_cnt - 1), 2 * m + tmp_cnt); n         add_con(N(adj[i][j]), 2 * m + tmp_cnt); n       } else { n         add_con(N(adj[i][j]), 2 * m + tmp_cnt); n       } n       if (!mp[ed[adj[i][j]].c]) { n         mp[ed[adj[i][j]].c] = adj[i][j]; n       } else if (mp[ed[adj[i][j]].c] == -1) { n         return false; n       } else { n         add_con(adj[i][j], mp[ed[adj[i][j]].c]); n         mp[ed[adj[i][j]].c] = -1; n       } n     } n   } n   for (int i = 1; i <= 6 * m; i++) { n     if (!mark1[i]) { n       dfs1(i); n     } n   } n   while (!ts.empty()) { n     long long v = ts.back(); n     ts.pop_back(); n     if (!mark2[v]) { n       cnt++; n       dfs2(v); n     } n   } n   for (int i = 1; i <= m; i++) { n     if (comp[i] == comp[i + m]) { n       return false; n     } n     if (comp[i] > comp[i + m]) { n       ans[i] = 1; n     } else { n       ans[i] = 0; n     } n   } n   for (int i = 2 * m + 1; i <= 4 * m; i++) { n     if (comp[i] == comp[i + 2 * m]) { n       return false; n     } n   } n   return true; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   ; n   cin >> n >> m; n   for (int i = 0; i < m; i++) { n     cin >> ed[i + 1].u >> ed[i + 1].v >> ed[i + 1].c >> ed[i + 1].t; n     adj[ed[i + 1].u].push_back(i + 1); n     adj[ed[i + 1].v].push_back(i + 1); n   } n   long long l = -1, r = inf; n   while (r - l > 1) { n     long long mid = (l + r) / 2; n     if (ch(mid)) { n       r = mid; n     } else { n       l = mid; n     } n   } n   if (r == inf) { n     cout <<  No  << endl; n     return 0; n   } n   cout <<  Yes  << endl; n   ch(r); n   long long tmp = 0; n   for (int i = 0; i < m; i++) { n     if (ans[i + 1]) { n       tmp++; n     } n   } n   cout << r <<     << tmp << endl; n   for (int i = 0; i < m; i++) { n     if (ans[i + 1]) { n       cout << i + 1 <<    ; n     } n   } n   cout << endl; n } n


#include <bits/stdc++.h> n #pragma optimization_level 3 n #pragma GCC optimize( Ofast,no-stack-protector,unroll-loops,fast-math,O3 ) n using namespace std; n mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); n int main() { n   cin.tie(0); n   cout.tie(0); n   cin.sync_with_stdio(0); n   cout.sync_with_stdio(0); n   ; n   long long z; n   cin >> z; n   for (; z--;) { n     long long a; n     cin >> a; n     vector<string> m(a); n     int can[a]; n     set<string> s; n     for (int q = 0; q < a; q++) { n       cin >> m[q]; n       s.insert(m[q]); n     } n     for (int q = 0; q < a; q++) { n       reverse(m[q].begin(), m[q].end()); n       can[q] = !s.count(m[q]); n       reverse(m[q].begin(), m[q].end()); n     } n     long long fl = 1; n     vector<long long> n, t(4), msk(a); n     int i = 0; n     for (string &u : m) { n       int mask = (u[0] ==  1 ) * 2 + (u.back() ==  1 ) * 1; n       t[mask]++; n       msk[i++] = mask; n     } n     if (!(t[1] + t[2])) n       fl = t[0] == a || t[3] == a; n     else { n       long long ABS = abs(t[1] - t[2]), nd = t[2] > t[1] ? 2 : 1; n       for (int q = 0; q < a && ABS > 1; q++) { n         if (msk[q] != nd || !can[q]) continue; n         ABS -= 2; n         n.push_back(q + 1); n       } n       fl = ABS < 2; n     } n     if (!fl) n       cout <<  -1 n ; n     else { n       cout << n.size() <<   n ; n       for (long long i : n) cout << i <<    ; n       cout <<   n ; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n ; n vector<pair<int, int>> vec; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int n, k, a, b, c; n   c = 1; n   cin >> n >> k; n   for (int i = 0; i < n; i++) { n     cin >> a >> b; n     vec.push_back(make_pair(a * -1, b)); n   } n   sort(vec.begin(), vec.end()); n   for (int i = 0; i < n; i++) { n     if (i == k - 1) { n       while (vec[i] == vec[i + 1]) { n         i++; n         c++; n       } n       cout << c <<   n ; n       break; n     } n     if (vec[i] == vec[i + 1]) n       c++; n     else n       c = 1; n   } n   cout.flush(); n } n


#include <bits/stdc++.h> n using namespace std; n struct node { n   int x, y, id; n   bool operator<(const node &A) const { return x < A.x; } n }; n vector<node> line[2][100005 << 2]; n bool mark[2][100005 << 2]; n int n, m, k; n long long t[100005]; n void add(int x, int y, int i) { n   node a; n   a.x = x, a.y = y, a.id = i; n   line[1][y - x + 200000].push_back(a); n   line[0][x + y + 200000].push_back(a); n } n void solve() { n   bool flag = 0, first = 0; n   long long res = 0; n   int k = 1; n   int x = 0, y = 0; n   while (!flag) { n     if (x == 0 || y == 0 || x == n || y == m) { n       if (first) { n         if ((x == 0 || x == n) && (y == 0 || y == m)) { n           flag = 1; n           break; n         } n         k = -k; n       } else n         first = 1; n     } n     int cur = (k == 1); n     if (line[cur][y - k * x + 200000].size()) { n       if (mark[cur][y - k * x + 200000]) n         flag = 1; n       else { n         mark[cur][y - k * x + 200000] = 1; n         if (k == 1 && (!x || !y) || k == -1 && ((!x && y) || (y == m && x))) { n           for (int i = 0; i < line[cur][y - k * x + 200000].size(); i++) { n             int j = line[cur][y - k * x + 200000][i].id; n             node tmp = line[cur][y - k * x + 200000][i]; n             if (t[j]) { n             } else n               t[j] = res + abs(line[cur][y - k * x + 200000][i].x - x); n           } n         } else { n           for (int i = line[cur][y - k * x + 200000].size() - 1; i >= 0; i--) { n             int j = line[cur][y - k * x + 200000][i].id; n             node tmp = line[cur][y - k * x + 200000][i]; n             if (t[j]) { n             } else n               t[j] = res + abs(line[cur][y - k * x + 200000][i].x - x); n           } n         } n       } n     } n     int nx1, ny1, nx2, ny2, t1 = x, t2 = y; n     if (k == 1) { n       if (0 <= n + y - x && n + y - x <= m) n         nx1 = n, ny1 = n + y - x; n       else n         ny1 = m, nx1 = m + x - y; n       if (0 <= y - x && y - x <= m) n         nx2 = 0, ny2 = y - x; n       else n         ny2 = 0, nx2 = x - y; n       if (nx1 == x) { n         x = nx2, y = ny2; n       } else n         x = nx1, y = ny1; n     } else { n       if (0 <= x + y && x + y <= m) n         nx1 = 0, ny1 = x + y; n       else n         ny1 = m, nx1 = x + y - m; n       if (0 <= x + y - n && x + y - n <= m) n         nx2 = n, ny2 = x + y - n; n       else n         ny2 = 0, nx2 = x + y; n       if (nx1 == x) { n         x = nx2, y = ny2; n       } else n         x = nx1, y = ny1; n     } n     res += abs(x - t1); n   } n } n inline void print(long long x) { n   if (!x) return; n   print(x / 10); n   putchar(x % 10 ^ 48); n } n inline void pf(long long x) { n   print(x); n   if (!x) n     puts( 0 ); n   else n     puts(  ); n } n inline void rd(int &res) { n   res = 0; n   char c; n   while (c = getchar(), c <  0  || c >  9 ) n     ; n   do { n     res = (res << 3) + (res << 1) + (c ^ 48); n   } while (c = getchar(),  0  <= c && c <=  9 ); n } n int main() { n   rd(n); n   rd(m); n   rd(k); n   for (int i = 1; i <= k; i++) { n     int a, b; n     rd(a); n     rd(b); n     add(a, b, i); n   } n   for (int i = 0; i < 2; i++) n     for (int j = 0; j < 2 * 100005; j++) { n       if (line[i][j].size()) { n         sort(line[i][j].begin(), line[i][j].end()); n       } n     } n   solve(); n   for (int i = 1; i <= k; i++) { n     if (t[i]) n       pf(t[i]); n     else n       puts( -1 ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, i, ctr = 0, j; n   int arr[1000]; n   cin >> n; n   for (i = 0; i < n; i++) cin >> arr[i]; n   for (i = 0; i < n; i++) n     if (arr[i] == 1) break; n   if (i == n) { n     cout << 0; n     return 0; n   } n   for (j = n - 1; j >= 0; j--) n     if (arr[j] == 1) break; n   if (i == j) { n     cout << 1; n     return 0; n   } n   ctr = 1; n   for (int k = i + 1; k <= j; k++) { n     if (arr[k] == 1) n       ctr++; n     else if (arr[k] == 0 && arr[k - 1] == 1 && arr[k + 1] == 1) n       ctr++; n   } n   cout << ctr; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n #pragma warning(disable : 4996) n const double eps = 1e-7; n struct node { n   long long first; n   node() {} n   node(long long first) : first(first) {} n   bool operator<(const node& a) const { return first < a.first; } n }; n int dx[4] = {-1, 1, 0, 0}; n int dy[4] = {0, 0, -1, 1}; n const long long N = 6010; n long long mod = 1e9 + 7; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int t; n   cin >> t; n   while (t--) { n     int n, k; n     cin >> n >> k; n     long long tmp = 0; n     long long ans = 0; n     priority_queue<node> q; n     for (int i = 1; i <= n * k; i++) { n       cin >> tmp; n       node tt(tmp); n       q.push(tt); n     } n     int cnt = 0; n     if (n & 1) { n       for (int i = 1; i <= k; i++) { n         for (int j = 1; j <= (n + 1) / 2; j++) { n           if (j == (n + 1) / 2) { n             ans += q.top().first; n             cnt++; n           } n           q.pop(); n         } n       } n     } else { n       for (int i = 1; i <= k; i++) { n         for (int j = 1; j <= n / 2 + 1; j++) { n           if (j == n / 2 + 1) { n             ans += q.top().first; n             cnt++; n           } n           q.pop(); n         } n       } n     } n     cout << ans <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int d[] = {25, 18, 15, 12, 10, 8, 6, 4, 2, 1}; n int t, n, k; n struct edge { n   string name; n   int s, win[50]; n } a[100]; n bool cmp1(edge x, edge y) { n   if (x.s != y.s) { n     return x.s > y.s; n   } n   for (int i = 0; i < 50; i++) { n     if (x.win[i] != y.win[i]) { n       return x.win[i] > y.win[i]; n     } n   } n   return false; n } n bool cmp2(edge x, edge y) { n   if (x.win[0] != y.win[0]) { n     return x.win[0] > y.win[0]; n   } else { n     return cmp1(x, y); n   } n } n int main() { n   cin >> t; n   while (t--) { n     cin >> n; n     string name; n     for (int i = 0; i < n; i++) { n       cin >> name; n       bool flag = false; n       for (int j = 0; j < k; j++) { n         if (a[j].name == name) { n           if (i < 10) { n             a[j].s += d[i]; n           } n           a[j].win[i]++; n           flag = true; n           break; n         } n       } n       if (flag == false) { n         a[k].name = name; n         if (i < 10) { n           a[k].s = d[i]; n         } n         a[k].win[i]++; n         k++; n       } n     } n   } n   sort(a, a + k, cmp1); n   cout << a[0].name << endl; n   sort(a, a + k, cmp2); n   cout << a[0].name; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char ch[200][200]; n int rp[200], cp[200]; n int main() { n   int n; n   while (cin >> n) { n     memset(rp, 0, sizeof(rp)); n     memset(cp, 0, sizeof(cp)); n     for (int i = 1; i <= n; i++) { n       scanf( %s , ch[i] + 1); n       for (int j = 1; j <= n; j++) n         if (ch[i][j] ==  . ) rp[i] = 1; n     } n     for (int i = 1; i <= n; i++) n       for (int j = 1; j <= n; j++) n         if (ch[j][i] ==  . ) cp[i] = 1; n     bool rok, cok; n     rok = cok = 0; n     int k; n     for (k = 1; k <= n; k++) n       if (rp[k] == 0) break; n     if (k > n) rok = 1; n     for (k = 1; k <= n; k++) n       if (cp[k] == 0) break; n     if (k > n) cok = 1; n     if (rok == 0 && cok == 0) { n       puts( -1 ); n       continue; n     } n     if (rok) { n       for (int i = 1; i <= n; i++) { n         for (int j = 1; j <= n; j++) n           if (ch[i][j] ==  . ) { n             cout << i <<     << j << endl; n             break; n           } n       } n     } else { n       for (int i = 1; i <= n; i++) { n         for (int j = 1; j <= n; j++) n           if (ch[j][i] ==  . ) { n             cout << j <<     << i << endl; n             break; n           } n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n long n, m, x, y, i, a[1000], z; n double aa, bb, sum; n int main() { n   scanf( %ld%ld , &n, &m); n   for (i = 1; i <= n; i++) scanf( %ld , &a[i]); n   sum = 0; n   for (i = 1; i <= m; i++) { n     scanf( %ld%ld%ld , &x, &y, &z); n     aa = a[x] + a[y]; n     bb = z; n     if (aa / bb > sum) { n       sum = aa / bb; n     } n   } n   printf( %0.15lf , sum); n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n using vi = vector<int>; n using pii = pair<int, int>; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(nullptr); n   int tests; n   cin >> tests; n   for (int test = 0; test < tests; ++test) { n     int n; n     cin >> n; n     vector<ll> a(n); n     for (int i = 0; i < n; ++i) cin >> a[i]; n     ll x, y; n     int fx, fy; n     cin >> x >> fx >> y >> fy; n     ll req; n     cin >> req; n     int lo = 1, hi = n + 1; n     for (int i = 0; i < n; ++i) a[i] /= 100; n     sort(a.begin(), a.end()); n     reverse(a.begin(), a.end()); n     while (lo < hi) { n       int mid = (lo + hi) / 2; n       vector<ll> c(mid); n       for (int i = 0; i < mid; ++i) { n         if (i % fx == fx - 1) c[i] += x; n         if (i % fy == fy - 1) c[i] += y; n       } n       sort(c.begin(), c.end()); n       reverse(c.begin(), c.end()); n       ll sum = 0; n       for (int i = 0; i < mid; ++i) sum += a[i] * c[i]; n       if (sum >= req) n         hi = mid; n       else n         lo = mid + 1; n     } n     if (lo == n + 1) lo = -1; n     cout << lo <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 1e5 + 100; n vector<int> adj[MAXN], *vec[MAXN]; n int col[MAXN], pw[MAXN], goni[MAXN], sz[MAXN]; n long long sum[MAXN]; n void getsz(int v = 1, int pre = -1) { n   sz[v] = 1; n   for (auto u : adj[v]) { n     if (u != pre) { n       getsz(u, v); n       sz[v] += sz[u]; n     } n   } n } n void dfs(int v, int pre, bool type) { n   int idx = -1; n   int bigchild = -1; n   for (auto i : adj[v]) n     if (sz[i] > idx && i != pre) idx = sz[i], bigchild = i; n   for (auto i : adj[v]) n     if (i != bigchild && i != pre) dfs(i, v, 0); n   if (bigchild != -1) { n     dfs(bigchild, v, 1); n     vec[v] = vec[bigchild]; n     sum[v] = sum[bigchild]; n     pw[v] = pw[bigchild]; n   } else n     vec[v] = new vector<int>(); n   vec[v]->push_back(v); n   goni[col[v]]++; n   if (goni[col[v]] == pw[v]) n     sum[v] += col[v]; n   else if (goni[col[v]] > pw[v]) { n     sum[v] = col[v]; n     pw[v] = goni[col[v]]; n   } n   for (auto i : adj[v]) n     if (i != bigchild && i != pre) n       for (auto j : *vec[i]) { n         goni[col[j]]++; n         vec[v]->push_back(j); n         if (goni[col[j]] == pw[v]) n           sum[v] += col[j]; n         else if (goni[col[j]] > pw[v]) { n           sum[v] = col[j]; n           pw[v] = goni[col[j]]; n         } n       } n   if (!type) n     for (auto u : *vec[v]) goni[col[u]]--; n } n int main() { n   int n; n   cin >> n; n   for (int i = 1; i <= n; ++i) cin >> col[i]; n   for (int i = 0; i < n - 1; ++i) { n     int x, y; n     cin >> x >> y; n     adj[x].push_back(y); n     adj[y].push_back(x); n   } n   getsz(); n   dfs(1, -1, 0); n   for (int i = 1; i <= n; ++i) cout << sum[i] <<    ; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t, n, k, tmp; n   vector<long long> ans; n   vector<int> vec; n   cin >> t; n   while (t--) { n     cin >> n >> k; n     for (int i = 0; i < n * k; i++) { n       cin >> tmp; n       vec.push_back(tmp); n     } n     int med; n     if (n % 2 == 0) n       med = n / 2; n     else n       med = n / 2 + 1; n     long long medSum = 0; n     int pos = vec.size() - (n - med) - 1; n     for (int i = 0; i < k; i++) { n       medSum += (long long)vec[pos]; n       pos -= (n - med + 1); n     } n     ans.push_back(medSum); n     vec.clear(); n   } n   for (int i = 0; i < ans.size(); i++) cout << ans[i] << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int t, n, k; n void solve() { n   scanf( %d%d , &n, &k); n   if (n < k) { n     printf( NO n ); n     return; n   } n   if ((n - (k - 1)) % 2 == 1) { n     printf( YES n ); n     for (int i = 1; i <= k - 1; ++i) printf( 1  ); n     printf( %d n , n - (k - 1)); n   } else if ((n - (k - 1) * 2) > 0 && (n - (k - 1) * 2) % 2 == 0) { n     printf( YES n ); n     for (int i = 1; i <= k - 1; ++i) printf( 2  ); n     printf( %d n , n - (k - 1) * 2); n   } else n     printf( NO n ); n } n int main() { n   scanf( %d , &t); n   while (t--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, Q; n const int md = 998244353; n const int maxn = 200010; n int t[4 * maxn], tmul[4 * maxn], tadd[4 * maxn]; n inline int mod(long long x) { return (x % md + md) % md; } n void build(int v, int vl, int vr) { n   tmul[v] = 1, tadd[v] = 0; n   if (vl == vr) return; n   int vm = (vl + vr) >> 1; n   build(2 * v, vl, vm); n   build(2 * v + 1, vm + 1, vr); n } n void push(int v, int vl, int vr) { n   t[v] = mod(mod(1ll * tmul[v] * t[v]) + mod(1ll * tadd[v] * (vr - vl + 1))); n   if (vl != vr) { n     tmul[2 * v] = mod(1ll * tmul[2 * v] * tmul[v]); n     tmul[2 * v + 1] = mod(1ll * tmul[2 * v + 1] * tmul[v]); n     tadd[2 * v] = mod(1ll * tadd[2 * v] * tmul[v] + tadd[v]); n     tadd[2 * v + 1] = mod(1ll * tadd[2 * v + 1] * tmul[v] + tadd[v]); n   } n   tmul[v] = 1; n   tadd[v] = 0; n } n void update(int v, int vl, int vr, int l, int r, int m, int a) { n   push(v, vl, vr); n   if (l > vr || r < vl) return; n   if (l <= vl && vr <= r) { n     tmul[v] = m; n     tadd[v] = a; n     push(v, vl, vr); n     return; n   } n   int vm = (vl + vr) >> 1; n   update(2 * v, vl, vm, l, r, m, a); n   update(2 * v + 1, vm + 1, vr, l, r, m, a); n   t[v] = (t[2 * v] + t[2 * v + 1]) % md; n } n int getsum(int v, int vl, int vr, int l, int r) { n   push(v, vl, vr); n   if (l > vr || r < vl) return 0; n   if (l <= vl && vr <= r) return t[v]; n   int vm = (vl + vr) >> 1; n   return mod(getsum(2 * v, vl, vm, l, r) + getsum(2 * v + 1, vm + 1, vr, l, r)); n } n set<pair<int, int>> q[maxn]; n int main() { n   ios_base::sync_with_stdio(false); n   cin >> n >> Q; n   build(1, 0, n - 1); n   for (int i = 0; i < Q; i++) { n     int t, l, r; n     cin >> t >> l >> r; n     --l, --r; n     if (t == 1) { n       int x; n       cin >> x; n       auto itl = q[x].lower_bound({l + 1, 0}); n       if (itl != q[x].begin()) { n         --itl; n         if (itl->second >= l) { n           int ll = itl->first, rr = itl->second; n           q[x].erase(itl); n           if (ll <= l - 1) q[x].insert({ll, l - 1}); n           q[x].insert({l, rr}); n         } n       } n       auto itr = q[x].lower_bound({r + 1, 0}); n       if (itr != q[x].begin()) { n         --itr; n         if (itr->second >= r) { n           int ll = itr->first, rr = itr->second; n           q[x].erase(itr); n           if (r + 1 <= rr) q[x].insert({r + 1, rr}); n           q[x].insert({ll, r}); n         } n       } n       int prev = l; n       while (true) { n         auto it = q[x].lower_bound({l, 0}); n         if (it == q[x].end() || it->first > r) break; n         int ll = it->first, rr = it->second; n         q[x].erase(it); n         if (prev <= ll - 1) update(1, 0, n - 1, prev, ll - 1, 1, 1); n         update(1, 0, n - 1, ll, rr, 2, 0); n         prev = rr + 1; n       } n       if (prev <= r) update(1, 0, n - 1, prev, r, 1, 1); n       q[x].insert({l, r}); n     } else { n       cout << getsum(1, 0, n - 1, l, r) <<   n ; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long int M = 1e9 + 7; n int sum_digit(int x) { n   int sum = 0; n   while (x > 0) { n     sum += x % 10; n     x /= 10; n   } n   return sum; n } n int reverse_num(int n) { n   int tmp = n, ans = 0, r; n   while (tmp > 0) { n     r = tmp % 10; n     ans = ans * 10 + r; n     tmp /= 10; n   } n   return ans; n } n long long int factorial(long long int n) { n   long long int i, ans = 1; n   for (i = n; i > 1; i--) { n     ans *= i; n   } n   return ans; n } n long long int gcd(long long int num1, long long int num2) { n   long long int a, b, r; n   a = num1; n   b = num2; n   r = a % b; n   while (r > 0) { n     a = b; n     b = r; n     r = a % b; n   } n   return b; n } n long long int lcm(long long int num1, long long int num2) { n   return (num1 * num2) / gcd(num1, num2); n } n bool prime(long long int n) { n   if (n < 2) return false; n   for (long long int i = 2; i <= sqrt(n); i++) { n     if (n % i == 0) return false; n   } n   return true; n } n bool vowel(char ch) { n   ch = tolower(ch); n   if (ch ==  a  || ch ==  e  || ch ==  i  || ch ==  o  || ch ==  u ) n     return true; n   return false; n } n void solve() { n   double d, h, v, e; n   cin >> d >> h >> v >> e; n   double r = d / 2; n   double v_in = 2 * acos(0) * r * r * h; n   double L = 0, R = 1e4 + 10; n   double ans = 0; n   while (L < R) { n     double t = L + (R - L) / 2; n     double dif = (v_in + 2 * acos(0) * r * r * e * t) - v * t; n     if (abs(dif) < 1e-4) { n       ans = t; n       break; n     } n     if (dif < 0) n       R = t; n     else n       L = t; n   } n   if (ans != 0) { n     cout <<  YES n ; n     cout << setprecision(12) << fixed << ans << endl; n   } else n     cout <<  NO n ; n } n int main() { n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m; n vector<int> adjlist[1000050], ans; n bool done[1000050], use[1000050]; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cin >> n >> m; n   for (int i = 0; i < m; i++) { n     int a, b; n     cin >> a >> b; n     adjlist[a].push_back(b); n   } n   for (int i = 1; i <= n; i++) { n     if (!done[i]) { n       use[i] = true; n       for (auto j : adjlist[i]) done[j] = true; n     } n   } n   memset(done, false, sizeof done); n   for (int i = n; i >= 1; i--) { n     if (use[i] and !done[i]) { n       ans.push_back(i); n       done[i] = true; n       for (auto j : adjlist[i]) done[j] = true; n     } n   } n   cout << ans.size() <<   n ; n   for (auto i : ans) cout << i <<    ; n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = 1e9 + 7, inf = 1e17, N = 1e6 + 10; n bool vowel(char che) { n   if (che ==  A  || che ==  E  || che ==  I  || che ==  O  || che ==  U  || n       che ==  Y ) { n     return true; n   } else { n     return false; n   } n } n long long pw(long long a, long long b) { n   long long ans = 1; n   while (b) { n     if (b % 2 == 1) { n       ans = 1ll * ans * a; n       ans %= mod; n     } n     b /= 2; n     a = 1ll * a * a % mod; n     a %= mod; n   } n   return ans % mod; n } n bool mark[N], ok[N], h; n char o; n pair<long long, long long> p; n vector<long long> vt[N], vec, jav, vs; n string s, s1; n int64_t a[N], b[N], c[N], d, dp, t, n, m, k, f, ans1, sum, ps; n int64_t fuc[N]; n int64_t ans; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(); n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n     a[i] %= mod; n   } n   fuc[0] = 1; n   for (int i = 1; i <= n; i++) { n     fuc[i] = 1ll * fuc[i - 1] * i; n     fuc[i] %= mod; n   } n   sort(a, a + n); n   f = 1; n   a[n] = -25; n   ans = 0; n   for (int i = 1; i <= n; i++) { n     if (a[i] == a[i - 1]) n       f++; n     else { n       if (i != n) { n         f %= mod; n         k = fuc[n] * pw((n - i + f), mod - 2); n         k %= mod; n         k *= f; n         k %= mod; n         ans += 1ll * k * a[i - 1]; n       } n       ans %= mod; n       f = 1; n     } n   } n   cout << (ans + mod) % mod << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long N, M; n   cin >> N >> M; n   set<long long> x_t; n   set<long long> y_t; n   vector<long long> ans; n   for (long long i = 0; i < M; i++) { n     long long x, y; n     cin >> x >> y; n     if (x_t.find(x) == x_t.end()) x_t.insert(x); n     if (y_t.find(y) == y_t.end()) y_t.insert(y); n     long long tam_x = x_t.size(); n     long long tam_y = y_t.size(); n     ans.push_back(N * N - (tam_x + tam_y) * N + (tam_x * tam_y)); n   } n   for (long long i = 0; i < ans.size() - 1; i++) cout << ans[i] <<    ; n   cout << ans[ans.size() - 1] <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int n, l, a, q[100001], w[100001], sum = 0, i; n   cin >> n >> l >> a; n   for (i = 0; i < n; i++) { n     cin >> q[i] >> w[i]; n   } n   if (n == 0) { n     cout << l / a; n     return 0; n   } n   sum = sum + q[0] / a; n   for (i = 1; i < n; i++) { n     sum = sum + (q[i] - w[i - 1] - q[i - 1]) / a; n   } n   sum = sum + (l - w[n - 1] - q[i - 1]) / a; n   cout << sum; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> divi[2002]; n long long dp[2002][2002]; n int main() { n   int n, k; n   cin >> k >> n; n   int i, j; n   for (i = 1; i <= k; i++) { n     for (j = i; j <= k; j += i) divi[i].push_back(j); n   } n   for (i = 1; i <= n; i++) { n     for (j = 1; j <= k; j++) { n       if (i == 1) n         dp[i][j] = 1; n       else { n         for (int x : divi[j]) dp[i][j] += dp[i - 1][x], dp[i][j] %= 1000000007; n       } n     } n   } n   long long ans = 0; n   for (i = 1; i <= k; i++) ans += dp[n][i], ans %= 1000000007; n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   scanf( %d , &n); n   long long int mx = n * n; n   for (int i = 1, j = mx; i < j; i++, j--) { n     cout << i <<     << j << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 105, M = N * N * N; n int n, pos, l, r, i, j, k, f[N][N][N], h, t, q[M][3], ans; n inline void ext(int x, int y, int z, int d) { n   if (y > z) return; n   if (y > l || z < r) return; n   if (x < y || x > z) return; n   if (~f[x][y][z]) return; n   f[x][y][z] = d; n   q[++t][0] = x; n   q[t][1] = y; n   q[t][2] = z; n } n int main() { n   scanf( %d%d%d%d , &n, &pos, &l, &r); n   for (i = 1; i <= n; i++) n     for (j = 1; j <= l; j++) n       for (k = r; k <= n; k++) f[i][j][k] = -1; n   h = 1; n   t = 0; n   ext(pos, 1, n, 0); n   while (h <= t) { n     int x, y, z, w; n     x = q[h][0]; n     y = q[h][1]; n     z = q[h++][2]; n     w = f[x][y][z] + 1; n     ext(x - 1, y, z, w); n     ext(x + 1, y, z, w); n     ext(x, x, z, w); n     ext(x, y, x, w); n   } n   ans = ~0U >> 1; n   for (i = 1; i <= n; i++) n     if (~f[i][l][r]) ans = min(ans, f[i][l][r]); n   printf( %d , ans); n } n


#include <bits/stdc++.h> n int32_t gcd(int32_t a, int32_t b) { n   if (b == 0) return a; n   return gcd(b, a % b); n } n int32_t mpf(int32_t n, std::vector<int32_t>& primes) { n   for (int32_t i = 0; i < primes.size(); i++) n     if (n % primes[i] == 0) return primes[i]; n   return 1; n } n int main() { n   int32_t num_tests; n   std::cin >> num_tests; n   for (int32_t t = 0; t < num_tests; t++) { n     int32_t n; n     std::cin >> n; n     int32_t n2 = n; n     std::vector<int32_t> primes; n     std::map<int32_t, int32_t> powers; n     for (int32_t i = 2; i * i <= n2; i++) n       if (n2 % i == 0) { n         primes.push_back(i); n         while (n2 % i == 0) { n           powers[i]++; n           n2 /= i; n         } n       } n     if (n2 != 1) { n       primes.push_back(n2); n       powers[n2]++; n     } n     std::map<int32_t, std::vector<int32_t> > mpf2; n     for (int32_t i = 1; i * i <= n; i++) { n       if (n % i == 0) { n         mpf2[mpf(i, primes)].push_back(i); n         if (i * i != n) mpf2[mpf(n / i, primes)].push_back(n / i); n       } n     } n     mpf2.erase(1); n     std::vector<int32_t> answer; n     std::unordered_set<int32_t> used; n     for (int32_t i = 0; i < primes.size(); i++) { n       int32_t next = n           primes.size() != 1 ? primes[i] * primes[(i + 1) % primes.size()] : -1; n       for (int32_t j = 0; j < mpf2[primes[i]].size(); j++) n         if (mpf2[primes[i]][j] != next && n             used.find(mpf2[primes[i]][j]) == used.end()) { n           used.insert(mpf2[primes[i]][j]); n           answer.push_back(mpf2[primes[i]][j]); n         } n       if (primes.size() != 1 && used.find(next) == used.end()) { n         answer.push_back(next); n         used.insert(next); n       } n     } n     for (int32_t j = 0; j < answer.size(); j++) std::cout << answer[j] <<    ; n     std::cout <<   n ; n     int32_t actions = 0; n     for (int32_t j = 0; j < answer.size(); j++) { n       if (gcd(answer[j], answer[(j + 1) % answer.size()]) == 1) actions++; n     } n     std::cout << actions <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n inline int read() { n   register int s = 0, f = 1; n   char c; n   for (c = getchar(); c <  0  || c >  9 ; c = getchar()) n     if (c ==  - ) f = -1; n   while (c >=  0  && c <=  9 ) s = (s * 10 + (c ^  0 )), c = getchar(); n   return s * f; n } n inline void print(register int x) { n   if (x < 0) putchar( - ), x = -x; n   if (x > 9) print(x / 10); n   putchar(x % 10 ^  0 ); n } n using namespace std; n int ans, prim[20000005], l, r, tot; n bitset<300000005> vis; n inline void Get_Prime(register int l, register int r) { n   vis[0] = vis[1] = 1; n   for (register int i = 2; i <= r; ++i) { n     if (!vis[i]) prim[++tot] = i; n     for (register int j = 1; j <= tot && i * prim[j] <= r; ++j) { n       vis[i * prim[j]] = 1; n       if (i % prim[j] == 0) break; n     } n   } n } n int main() { n   l = read(), r = read(), Get_Prime(l, r); n   for (register int i = 5; i <= r; i += 4) n     if (i >= l && !vis[i]) ++ans; n   if (l <= 2 && r >= 2) ++ans; n   print(ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int Max = 2e5 + 10; n const int LOG = 30; n const int INF = 1e9 + 10; n struct Trie { n   int l[Max * LOG], r[Max * LOG]; n   int cnt[Max * LOG]; n   int sz = 1; n   int index[Max * LOG]; n   int dp[Max * LOG][2]; n   void insert(int x, int ind) { n     int p = 1; n     for (int lg = LOG; lg--;) { n       cnt[p]++; n       if (x & (1 << lg)) n         if (r[p]) n           p = r[p]; n         else n           p = r[p] = ++sz; n       else if (l[p]) n         p = l[p]; n       else n         p = l[p] = ++sz; n     } n     cnt[p]++; n     index[p] = ind; n   } n   int mnxor(int x) { n     int p = 1; n     bool firstdiff = false; n     for (int lg = LOG; lg--;) { n       if (!firstdiff) { n         if (x & (1 << lg)) n           if (cnt[r[p]] > 1) n             p = r[p]; n           else { n             p = l[p]; n             firstdiff = true; n           } n         else if (cnt[l[p]] > 1) n           p = l[p]; n         else { n           p = r[p]; n           firstdiff = true; n         } n       } else { n         if (x & (1 << lg)) n           if (r[p]) n             p = r[p]; n           else n             p = l[p]; n         else if (l[p]) n           p = l[p]; n         else n           p = r[p]; n       } n     } n     return index[p]; n   } n   void DP(int v) { n     if (r[v]) DP(r[v]); n     if (l[v]) DP(l[v]); n     dp[v][0] = cnt[v] - 1; n     dp[v][1] = min(dp[l[v]][0] + dp[r[v]][1], dp[r[v]][0] + dp[l[v]][1]); n   } n }; n Trie t; n int A[Max]; n vector<int> N[Max]; n bool seen[Max]; n int DFS(int v) { n   seen[v] = true; n   int res = 1; n   for (int u : N[v]) n     if (!seen[u]) res += DFS(u); n   return res; n } n void solve() { n   int n; n   cin >> n; n   for (int i = 0; i < n; i++) { n     int a; n     cin >> a; n     A[i] = a; n     t.insert(a, i); n   } n   for (int i = 0; i < n; i++) { n     int from = i; n     int to = t.mnxor(A[i]); n     N[from].push_back(to); n     N[to].push_back(from); n   } n   int molcnt = 0; n   int mxmol = 0; n   for (int i = 0; i < n; i++) n     if (!seen[i]) { n       molcnt++; n       mxmol = max(mxmol, DFS(i)); n     } n   t.DP(1); n   cout << t.dp[1][1]; n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   solve(); n } n


#include <bits/stdc++.h> n using namespace std; n vector<pair<int, int> > diffs; n long long int su[100500]; n int n, s; n long long int kek(long long int res) { n   long long int ans = res; n   su[n - 1] = 1ll * diffs.back().first * diffs.back().second; n   for (int i = n - 2; i >= 0; i--) { n     su[i] = su[i + 1] + diffs[i].first * 1ll * diffs[i].second; n   } n   long long int w = 0; n   long long int wa = 0; n   for (int i = 0; i < n; i++) { n     if (diffs[i].first < 0) { n       w += diffs[i].second; n     } else { n       long long int aim = (w + s - 1) / s * s; n       while (i < n && w + diffs[i].second <= aim) { n         w += diffs[i].second; n         wa += diffs[i].second * 1ll * diffs[i].first; n         i++; n       } n       if (w == aim) { n         ans = max(ans, res + su[i]); n       } else { n         long long int x = aim - w; n         ans = max(ans, res + wa + su[i] - x * diffs[i].first); n       } n       break; n     } n   } n   return ans; n } n int main() { n   cin >> n >> s; n   long long int sum = 0; n   long long int res = 0; n   long long int res1 = 0; n   for (int i = 0; i < n; i++) { n     int a, b, c; n     cin >> a >> b >> c; n     sum += a; n     res += 1ll * a * b; n     res1 += 1ll * a * c; n     diffs.push_back({c - b, a}); n   } n   long long int kol = (sum + s - 1) / s; n   if (kol * s > sum) diffs.push_back({0, kol * s - sum}); n   n = diffs.size(); n   sort(diffs.begin(), diffs.end()); n   long long int ans = res; n   long long int danil = kek(res); n   reverse(diffs.begin(), diffs.end()); n   for (auto &x : diffs) { n     x.first *= -1; n   } n   cout << max(danil, kek(res1)); n   return 0; n } n


#include <bits/stdc++.h> n const int MAXN = 1000 + 5; n char str[MAXN]; n int n; n inline std::vector<int> query(std::vector<int> d) { n   std::vector<int> ans; n   printf( ?  ); n   for (auto x : d) printf( %d  , x); n   puts(  ); n   std::fflush(stdout); n   scanf( %s , str + 1); n   for (int i = 1; i <= n; ++i) ans.push_back(str[i] -  0 ); n   return ans; n } n std::vector<int> G[MAXN]; n std::vector<int> node[MAXN * 50]; n int tot = 1; n struct Node { n   int l, r, id; n   Node(int l = 0, int r = 0, int id = 0) : l(l), r(r), id(id) {} n   inline bool operator<(const Node &t) const { return l < t.l; } n }; n int fa[MAXN]; n inline void work(std::vector<int> id, int bit) { n   std::vector<int> d; n   d.resize(n); n   for (auto x : id) { n     for (auto y : G[x - 1]) n       if ((y >> bit) & 1) d[y - 1] = 1; n   } n   std::vector<int> a; n   a = query(d); n   for (auto x : id) { n     for (auto y : G[x]) fa[y] |= (a[y - 1] << bit); n   } n } n bool tag[MAXN]; n int main() { n   scanf( %d , &n); n   std::vector<Node> now; n   G[0].push_back(1); n   now.push_back(Node(0, n, 1)); n   for (int i = 2; i <= n; ++i) node[tot].push_back(i); n   while (!now.empty()) { n     std::vector<Node> v1, v2; n     std::sort(now.begin(), now.end()); n     for (int i = 0; i < now.size(); i += 2) { n       v1.push_back(now[i]); n       if (i + 1 < now.size()) v2.push_back(now[i + 1]); n     } n     std::vector<int> d, a1, a2; n     d.resize(n); n     now.clear(); n     memset(tag, 0, sizeof(tag)); n     for (auto x : v1) { n       int mid = (x.l + x.r) >> 1; n       assert(x.l < x.r - 1); n       for (auto y : G[x.l]) d[y - 1] = mid - x.l - 1, tag[y - 1] = 1; n     } n     a1 = query(d); n     for (int i = 0; i <= n - 1; ++i) n       if (tag[i]) d[i]++; n     a2 = query(d); n     for (auto x : v1) { n       int mid = (x.l + x.r) >> 1; n       Node ls = Node(x.l, mid, ++tot), rs = Node(mid, x.r, ++tot); n       for (auto y : node[x.id]) { n         if (!a1[y - 1] && a2[y - 1]) n           G[mid].push_back(y); n         else if (a1[y - 1]) n           node[ls.id].push_back(y); n         else n           node[rs.id].push_back(y); n       } n       if (ls.l + 1 < ls.r) now.push_back(ls); n       if (rs.l + 1 < rs.r) now.push_back(rs); n     } n     d.clear(); n     d.resize(n); n     memset(tag, 0, sizeof(tag)); n     for (auto x : v2) { n       int mid = (x.l + x.r) >> 1; n       assert(x.l < x.r - 1); n       for (auto y : G[x.l]) d[y - 1] = mid - x.l - 1, tag[y - 1] = 1; n     } n     a1 = query(d); n     for (int i = 0; i <= n - 1; ++i) n       if (tag[i]) d[i]++; n     a2 = query(d); n     for (auto x : v2) { n       int mid = (x.l + x.r) >> 1; n       Node ls = Node(x.l, mid, ++tot), rs = Node(mid, x.r, ++tot); n       for (auto y : node[x.id]) { n         if (!a1[y - 1] && a2[y - 1]) n           G[mid].push_back(y); n         else if (a1[y - 1]) n           node[ls.id].push_back(y); n         else n           node[rs.id].push_back(y); n       } n       if (ls.l + 1 < ls.r) now.push_back(ls); n       if (rs.l + 1 < rs.r) now.push_back(rs); n     } n   } n   for (int i = 0; i <= 9; ++i) { n     std::vector<int> v1, v2, v3; n     for (int i = 1; i < n; i += 3) { n       v1.push_back(i); n       if (i + 1 < n) v2.push_back(i + 1); n       if (i + 2 < n) v3.push_back(i + 2); n     } n     work(v1, i); n     work(v2, i); n     work(v3, i); n   } n   puts( ! ); n   for (int i = 2; i <= n; ++i) printf( %d %d n , fa[i], i); n   std::fflush(stdout); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n  n int main() { n  // your code goes here n  int t; n  cin>>t; n  int len=pow(10,9)+7; n  while(t--) n  { n      int n,k; n      cin>>n>>k; n     long long int ans=1; n      for(int i=0;i<k;i++) n      { n          ans=(ans*n)% len; n      } n      cout<<ans<<endl; n       n       n       n  } n  return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline void read(long long &x) { n   char ch; n   bool flag = false; n   for (ch = getchar(); !isdigit(ch); ch = getchar()) n     if (ch ==  - ) flag = true; n   for (x = 0; isdigit(ch); x = x * 10 + ch -  0 , ch = getchar()) n     ; n   x = flag ? -x : x; n } n inline void write(long long x) { n   static const long long maxlen = 100; n   static char s[maxlen]; n   if (x < 0) { n     putchar( - ); n     x = -x; n   } n   if (!x) { n     putchar( 0 ); n     return; n   } n   long long len = 0; n   for (; x; x /= 10) s[len++] = x % 10 +  0 ; n   for (long long i = len - 1; i >= 0; --i) putchar(s[i]); n } n inline void read(int &x) { n   char ch; n   bool flag = false; n   for (ch = getchar(); !isdigit(ch); ch = getchar()) n     if (ch ==  - ) flag = true; n   for (x = 0; isdigit(ch); x = x * 10 + ch -  0 , ch = getchar()) n     ; n   x = flag ? -x : x; n } n const long long MAXN = 110000; n long long f[MAXN][110]; n long long s[MAXN]; n const long long P = 998244353ll; n long long n, lim, kind; n long long a[MAXN]; n long long num[MAXN][110]; n int main() { n   read(n); n   read(kind); n   read(lim); n   for (long long i = 1; i <= n; i++) { n     read(a[i]); n     if (a[i] == -1) a[i] = 0; n   } n   for (long long i = 1; i <= n; i++) { n     for (long long j = 0; j <= kind; j++) num[i][j] = num[i - 1][j]; n     num[i][a[i]]++; n   } n   s[0] = 1; n   for (long long i = 1; i <= n; i++) n     if (a[i] == 0) n       for (long long j = 1; j <= kind; j++) { n         f[i][j] = s[i - 1]; n         if ((i >= lim) && n             (num[i][j] - num[i - lim][j] + num[i][0] - num[i - lim][0] == lim)) n           f[i][j] = (f[i][j] - (s[i - lim] - f[i - lim][j]) + 3 * P) % P; n         s[i] = (s[i] + f[i][j]) % P; n       } n     else { n       long long j = a[i]; n       f[i][a[i]] = s[i - 1]; n       if ((i >= lim) && n           (num[i][j] - num[i - lim][j] + num[i][0] - num[i - lim][0] == lim)) { n         f[i][j] = (f[i][j] - (s[i - lim] - f[i - lim][j])) % P; n       } n       s[i] = (s[i] + f[i][j]) % P; n     } n   cout << s[n] << endl; n   return 0; n   for (;;) { n     long long x, y; n     read(x); n     read(y); n     printf( f[%d][%d]=%d n , x, y, f[x][y]); n   } n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   char a[200100], b[200100]; n   while (~scanf( %s%s , a, b)) { n     int c[1000]; n     memset(c, 0, sizeof(c)); n     int n = 0; n     for (int i = 0; a[i]; ++i) ++c[a[i]]; n     int ya = 0; n     for (int i = 0; b[i]; ++i) n       if (c[b[i]]) --c[b[i]], ++ya, b[i] = -1; n     for (int i = 0; b[i]; ++i) n       if (b[i] != -1) n         if (c[tolower(b[i])]) n           ++n, --c[tolower(b[i])]; n         else if (c[toupper(b[i])]) n           ++n, --c[toupper(b[i])]; n     printf( %d %d n , ya, n); 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(nullptr); n   int t; n   cin >> t; n   while (t--) { n     long long n, m; n     cin >> n >> m; n     vector<pair<long long, long long>> ar(m); n     for (int i = 0; i < m; ++i) { n       cin >> ar[i].first >> ar[i].second; n     } n     sort(ar.begin(), ar.end()); n     vector<long long> psa(m + 1); n     for (int i = 1; i < m + 1; ++i) { n       psa[i] = psa[i - 1] + ar[i - 1].first; n     } n     long long ans = 0; n     for (int i = 0; i < m; ++i) { n       long long a = ar[i].first; n       long long b = ar[i].second; n       int j = lower_bound(ar.begin(), ar.end(), make_pair(b, LLONG_MAX)) - n               ar.begin(); n       long long cur = 0; n       if (m - j <= n) { n         cur += psa[m] - psa[j]; n         int x = n - (m - j); n         cur += a + (x - 1) * b; n         if (j <= i) { n           cur -= a; n           cur += b; n         } n       } else { n         cur += psa[m] - psa[m - n]; n       } n       ans = max(ans, cur); n     } n     cout << ans <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = 1000000000; n long long mod = 1000000007LL; n long long mod2 = 998244353LL; n long long t, l, r; n long long dp[5000005]; n long long prm[5000005]; n long long pw[5000005]; n long long dfs(int x) { n   if (dp[x] >= 0) return dp[x]; n   if (x == 1) return dp[x] = 0LL; n   dp[x] = (long long)x * (long long)(x - 1) / 2LL; n   dp[x] %= mod; n   long long i; n   if (x > 2 && x % 2 == 0) { n     return dp[x] = (dfs(x / 2) + (2 * (2 - 1) / 2) % mod * (x / 2) % mod) % mod; n   } n   int d = prm[x]; n   if (d < 0) return dp[x]; n   return dp[x] = (dfs(x / d) + (d * (d - 1) / 2) % mod * (x / d) % mod) % mod; n } n long long getpw(long long x, long long y) { n   long long res = 1LL; n   while (y) { n     if (y & 1) res = res * x % mod; n     x = x * x % mod; n     y /= 2; n   } n   return res; n } n int main() { n   cin >> t >> l >> r; n   memset(prm, -1, sizeof(prm)); n   for (int i = 2; i * i <= r; ++i) { n     if (prm[i] < 0) { n       for (int j = 2 * i; j <= r; j += i) { n         if (prm[j] < 0) prm[j] = i; n       } n     } n   } n   pw[0] = 1LL; n   for (int i = 1; i <= r; ++i) { n     pw[i] = pw[i - 1] * (long long)t % mod; n   } n   memset(dp, -1, sizeof(dp)); n   long long res = 0LL; n   for (int i = 2; i <= r; ++i) { n     if (dp[i] < 0) { n       dfs(i); n       if (i >= l && i <= r) { n         long long tmp = dp[i] * pw[i - l] % mod; n         res = (res + tmp) % mod; n       } n     } n   } n   cout << res << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 100086; n const int inf = 2.1e9; n const long long Inf = 999999999999999999; n const int mod = 1000000007; n const double eps = 1e-6; n const double pi = acos(-1); n int n, s, t; n int nums[206]; n int vis[maxn], num[maxn]; n int prime[maxn], cur; n bool check[maxn]; n int Head[208], Next[maxn], v[maxn], w[maxn], cnt; n void init() { n   memset(Head, -1, sizeof(Head)); n   cnt = 0; n   s = 0, t = n + 1; n } n void primes() { n   for (int i = 2; i < 20086; i++) { n     if (!check[i]) { n       prime[cur++] = i; n     } n     for (int j = 0; j < cur; j++) { n       if (i * prime[j] > 20086) { n         break; n       } n       check[i * prime[j]] = i; n       if (i % prime[j] == 0) { n         break; n       } n     } n   } n } n void add(int x, int y, int z) { n   if (x == y) { n     return; n   } n   v[cnt] = y; n   w[cnt] = z; n   Next[cnt] = Head[x]; n   Head[x] = cnt++; n   v[cnt] = x; n   w[cnt] = 0; n   Next[cnt] = Head[y]; n   Head[y] = cnt++; n } n bool bfs() { n   memset(vis, 0, sizeof(vis)); n   for (int i = 0; i <= t; i++) { n     num[i] = Head[i]; n   } n   vis[s] = 1; n   queue<int> q; n   q.push(s); n   int r = 0; n   while (!q.empty()) { n     int u = q.front(); n     q.pop(); n     int k = Head[u]; n     while (k != -1) { n       if (!vis[v[k]] && w[k]) { n         vis[v[k]] = vis[u] + 1; n         q.push(v[k]); n       } n       k = Next[k]; n     } n   } n   return vis[t]; n } n int dfs(int u, int f) { n   if (u == t) { n     return f; n   } n   int &k = num[u]; n   int sum = 0; n   while (k != -1) { n     if (vis[v[k]] == vis[u] + 1 && w[k]) { n       int d = dfs(v[k], min(f, w[k])); n       if (d > 0) { n         w[k] -= d; n         w[k ^ 1] += d; n         return d; n       } n     } n     k = Next[k]; n   } n   return sum; n } n int Dinic() { n   int ans = 0; n   while (bfs()) { n     int f; n     while ((f = dfs(s, inf)) > 0) { n       ans += f; n     } n   } n   return ans; n } n stack<int> st; n void dfs(int t) { n   vis[t] = 1; n   st.push(t); n   for (int k = Head[t]; k != -1; k = Next[k]) { n     if (v[k] == 0 || v[k] == n + 1) { n       continue; n     } n     if (vis[v[k]]) { n       continue; n     } n     if (nums[t] % 2 == 0 && w[k]) { n       dfs(v[k]); n     } n     if (nums[t] % 2 == 1 && !w[k]) { n       dfs(v[k]); n     } n   } n   vis[t] = -1; n } n queue<int> q[208]; n int main() { n   primes(); n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) { n     scanf( %d , &nums[i]); n   } n   init(); n   for (int i = 1; i <= n; i++) { n     if (nums[i] & 1) { n       add(s, i, 2); n     } else { n       add(i, t, 2); n     } n     for (int j = i + 1; j <= n; j++) { n       if (!check[nums[i] + nums[j]]) { n         if (nums[i] & 1) { n           add(i, j, 1); n         } else { n           add(j, i, 1); n         } n       } n     } n   } n   if (Dinic() != n) { n     printf( Impossible n ); n     return 0; n   } n   int numi = 0; n   memset(vis, 0, sizeof(vis)); n   for (int i = 1; i <= n; i++) { n     if (!vis[i]) { n       dfs(i); n       numi++; n       while (!st.empty()) { n         q[i].push(st.top()); n         st.pop(); n       } n     } n   } n   printf( %d n , numi); n   for (int i = 1; i <= n; i++) { n     if (!q[i].empty()) { n       printf( %d , q[i].size()); n       while (!q[i].empty()) { n         printf(  %d , q[i].front()); n         q[i].pop(); n       } n       printf(  n ); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char oda[3500]; n int y; n void PuLe(int x) { n   int j; n   j = x; n   while (oda[j - 1] ==  . ) { n     oda[j - 1] =  @ ; n     j--; n   } n   if (oda[j - 1] ==  R ) { n     if ((x - j) % 2 != 0) oda[x - ((x - j) / 2 + 1)] =  . ; n   } n } n void PuRi(int x) { n   int j; n   j = x; n   while (oda[j + 1] ==  . ) { n     oda[j + 1] =  @ ; n     j++; n   } n   if (oda[j + 1] ==  L ) { n     if ((j - x) % 2 != 0) oda[(j - x) / 2 + 1 + x] =  . ; n   } n } n int main() { n   int n; n   while (cin >> n) { n     int i, count = 0; n     cin >> oda; n     for (i = 0; i < n; i++) { n       if (oda[i] ==  L ) PuLe(i); n       if (oda[i] ==  R ) PuRi(i); n     } n     for (i = 0; i < n; i++) n       if (oda[i] ==  . ) count++; n     cout << count; n     cout << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long int binarySearch(long long int* arr, long long int l, long long int r, n                            long long int x) { n   if (r >= l) { n     long long int mid = l + (r - l) / 2; n     if (arr[mid] == x) return mid; n     if (arr[mid] > x) return binarySearch(arr, l, mid - 1, x); n     return binarySearch(arr, mid + 1, r, x); n   } n   return -1; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long int t, n1, n2, n3, i, j, l, x; n   cin >> t; n   for (l = 0; l < t; l++) { n     string s =   ; n     cin >> n1 >> n2 >> n3; n     if (n1 > 0) { n       for (i = 0; i <= n1; i++) s +=  0 ; n     } n     if (n3 > 0 && n1 > 0) n2 -= 1; n     if (n3 > 0) { n       for (i = 0; i <= n3; i++) s +=  1 ; n     } n     if (n2 > 0 && n3 > 0) { n       x = 0; n       for (i = 0; i < n2; i++) { n         s += (x +  0 ); n         x = (x + 1) % 2; n       } n     } else if (n2 > 0 && n1 > 0) { n       x = 1; n       for (i = 0; i < n2; i++) { n         s += (x +  0 ); n         x = (x + 1) % 2; n       } n     } else if (n2 > 0) { n       s +=  1 ; n       x = 0; n       for (i = 0; i < n2; i++) { n         s += (x +  0 ); n         x = (x + 1) % 2; n       } n     } n     cout << s <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool cmp(int x, int y) { return x > y; } n int main() { n   double sum; n   int n, r[110]; n   while (~scanf( %d , &n)) { n     sum = 0; n     for (int i = 0; i < n; i++) scanf( %d , &r[i]); n     sort(r, r + n, cmp); n     int tmp = 1; n     for (int i = 0; i < n; i++) { n       sum += tmp * r[i] * r[i]; n       tmp *= -1; n     } n     printf( %.15f n , sum * 3.141592653589793); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct line { n   long long m, b; n   int id; n }; n long long floordiv(long long a, long long b) { n   return a / b - (a % b && ((a < 0) ^ (b < 0))); n } n long long intersect(line a, line b) { return floordiv(b.b - a.b, a.m - b.m); } n pair<int, int> org[262192 >> 1]; n pair<pair<int, int>, int> ist[262192 >> 1]; n struct Convex { n   vector<line> cht; n   void insert(line l) { n     auto n = cht.size(); n     while ((n >= 1 && l.m == cht[n - 1].m && l.b >= cht[n - 1].b) || n            (n >= 2 && n             intersect(cht[n - 1], cht[n - 2]) >= intersect(cht[n - 1], l))) { n       cht.pop_back(); n       n = cht.size(); n     } n     cht.push_back(l); n   } n   long long query(long long x) { n     int low = 0, high = (int)cht.size() - 2; n     int ret = (int)cht.size() - 1; n     while (low <= high) { n       int mid = low + (high - low) / 2; n       if (intersect(cht[mid], cht[mid + 1]) >= x) { n         ret = mid; n         high = mid - 1; n       } else { n         low = mid + 1; n       } n     } n     return cht[ret].id; n   } n }; n Convex tree[262192]; n void insert(int pos, int l, int r, int index, line li) { n   if (l > r || pos < l || pos > r) return; n   tree[index].insert(li); n   if (l == r) return; n   int mid = (l + r) >> 1; n   if (pos <= mid) { n     insert(pos, l, mid, index << 1, li); n   } else { n     insert(pos, mid + 1, r, index << 1 | 1, li); n   } n } n int query(int start, int end, int l, int r, int index, long long t) { n   if (start > end || l > r || start > r || l > end) return 0; n   if (start <= l && r <= end) return tree[index].query(t); n   int mid = (l + r) >> 1; n   if (end <= mid) return query(start, end, l, mid, index * 2, t); n   if (mid + 1 <= start) return query(start, end, mid + 1, r, index * 2 + 1, t); n   int id1 = query(start, end, l, mid, index * 2, t); n   int id2 = query(start, end, mid + 1, r, index * 2 + 1, t); n   long long y1 = 1ll * org[id1].first * t + org[id1].second; n   long long y2 = 1ll * org[id2].first * t + org[id2].second; n   if (y1 > y2) return id1; n   return id2; n } n int main() { n   int n, m, i; n   scanf( %d%d , &n, &m); n   for (i = 1; i <= n; i++) { n     scanf( %d%d , &org[i].second, &org[i].first); n     ist[i].first = org[i], ist[i].second = i; n   } n   sort(ist + 1, ist + n + 1); n   for (i = 1; i <= n; i++) { n     insert(ist[i].second, 1, n, 1, n            line{ist[i].first.first, ist[i].first.second, ist[i].second}); n   } n   while (m > 0) { n     int l, r, t; n     scanf( %d%d%d , &l, &r, &t); n     printf( %d n , query(l, r, 1, n, 1, t)); n     m--; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double eps = 1e-9; n const double pi = acos(-1.0); n const int inf = 0x3f3f3f3f; n const long long oo = 1LL << 60; n const int N = 10010; n const int E = 200010; n class Graph { n  public: n   int pnt[E], nxt[E], id[E]; n   int head[N], nv, ne; n   void init(const int v) { n     nv = v; n     ne = 0; n     memset(head, 255, sizeof(head)); n   } n   void add(const int u, const int v, const int i) { n     pnt[ne] = v, id[ne] = i, nxt[ne] = head[u], head[u] = ne++; n     pnt[ne] = u, id[ne] = i, nxt[ne] = head[v], head[v] = ne++; n   } n } ga, gb; n int n, rt; n int dfn[N], low[N], idx; n int stk[N], top; n int belong[N], bcnt; n bool vis[N]; n int cnt[N]; n void dfs(const Graph &g, int u, int f) { n   int i, v, e; n   dfn[u] = low[u] = idx++; n   stk[++top] = u; n   vis[u] = 1; n   for (i = g.head[u]; ~i; i = g.nxt[i]) { n     v = g.pnt[i], e = g.id[i]; n     if (dfn[v] < 0) { n       dfs(g, v, e); n       low[u] = min(low[u], low[v]); n     } else if (e != f && vis[v] && low[u] > dfn[v]) n       low[u] = dfn[v]; n   } n   if (dfn[u] == low[u]) { n     do { n       v = stk[top--]; n       vis[v] = 0; n       belong[v] = bcnt; n     } while (v != u); n     bcnt++; n   } n } n void bcc(const Graph &g) { n   top = bcnt = idx = 0; n   memset(dfn, 255, sizeof(dfn)); n   memset(vis, 0, sizeof(vis)); n   for (int i = 0; i < g.nv; i++) n     if (dfn[i] < 0) dfs(g, i, -1); n } n void find(const Graph &g) { n   rt = -1; n   int mm = -1; n   memset(cnt, 0, sizeof(cnt)); n   for (int i = 0; i < g.nv; i++) cnt[belong[i]]++; n   for (int i = 0; i < bcnt; i++) n     if (cnt[i] > mm) { n       mm = cnt[i]; n       rt = i; n     } n } n void shrink(const Graph &ga, Graph &gb) { n   int v, cnt = 1; n   gb.init(bcnt); n   for (int i = 0; i < ga.nv; i++) n     for (int j = ga.head[i]; ~j; j = ga.nxt[j]) n       if (belong[i] != belong[v = ga.pnt[j]]) n         gb.add(belong[i], belong[v], cnt++); n } n bool in[N]; n int Q[N], dist[N]; n void spfa(const Graph &g, int src) { n   int i, u, v, l, r = 0; n   memset(dist, 63, sizeof(dist)); n   memset(in, 0, sizeof(in)); n   dist[Q[r++] = src] = 0; n   in[src] = 1; n   for (l = 0; l != r; l = (l + 1) % N) n     for (i = g.head[u = Q[l]], in[u] = 0; ~i; i = g.nxt[i]) n       if (dist[v = g.pnt[i]] > dist[u] + 1) { n         dist[v] = dist[u] + 1; n         if (!in[v]) in[Q[r++] = v] = 1, r %= N; n       } n } n int main(void) { n   scanf( %d , &n); n   ga.init(n); n   for (int i = 1; i <= n; i++) { n     int u, v; n     scanf( %d%d , &u, &v); n     ga.add(u - 1, v - 1, i); n   } n   bcc(ga); n   find(ga); n   shrink(ga, gb); n   spfa(gb, rt); n   for (int i = 0; i < ga.nv; i++) n     printf( %d%c , dist[belong[i]], i == ga.nv - 1 ?   n  :    ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using LL = long long; n namespace _buff { n const size_t BUFF = 1 << 19; n char buff[BUFF], *begin = buff, *end = buff; n char getc() { n   if (begin == end) { n     begin = buff; n     end = buff + fread(buff, 1, BUFF, stdin); n   } n   return begin == end ? -1 : *begin++; n } n }  // namespace _buff n LL read() { n   using namespace _buff; n   LL ret = 0; n   bool pos = true; n   char c = getc(); n   for (; (c <  0  || c >  9 ) && c !=  - ; c = getc()) { n     assert(~c); n   } n   if (c ==  - ) { n     pos = false; n     c = getc(); n   } n   for (; c >=  0  && c <=  9 ; c = getc()) { n     ret = (ret << 3) + (ret << 1) + (c ^ 48); n   } n   return pos ? ret : -ret; n } n const size_t N = 1 << 19; n const int MOD = 998244353; n const int ROOT = 3; n int qpow(int base, int e) { n   int ret = 1; n   for (; e; e >>= 1) { n     if (e & 1) ret = 1LL * ret * base % MOD; n     base = 1LL * base * base % MOD; n   } n   return ret; n } n int rmod(int x) { n   if (x >= MOD) x -= MOD; n   if (x < 0) x += MOD; n   return x; n } n void fft(int a[], int lg, int flag) { n   static int rev[N], rev_lg = -1; n   int n = 1 << lg; n   if (lg != rev_lg) { n     for (int i = 0; i < n; ++i) { n       rev[i] = rev[i >> 1] >> 1 | ((i & 1) << (lg - 1)); n     } n   } n   for (int i = 0; i < n; ++i) { n     if (i < rev[i]) swap(a[i], a[rev[i]]); n   } n   for (int m = 1, l = 2; m < n; m <<= 1, l <<= 1) { n     int wn = qpow(ROOT, flag ? (MOD - 1) - (MOD - 1) / l : (MOD - 1) / l); n     for (int i = 0, j, w, x, y; i < n; i += l) { n       for (j = 0, w = 1; j < m; ++j, w = 1LL * w * wn % MOD) { n         x = a[i + j]; n         y = 1LL * w * a[i + j + m] % MOD; n         a[i + j] = rmod(x + y); n         a[i + j + m] = rmod(x - y); n       } n     } n   } n   if (flag) { n     int inv = qpow(n, MOD - 2); n     for (int i = 0; i < n; ++i) { n       a[i] = 1LL * a[i] * inv % MOD; n     } n   } n } n vector<int> operator*(const vector<int> &a, const vector<int> &b) { n   static int aa[N], bb[N], cc[N]; n   int n = a.size(), m = b.size(), l = n + m - 1, lg = 0; n   vector<int> ans(l); n   if (static_cast<LL>(n) * m <= 4096) { n     static unsigned long long tmp[N]; n     for (int i = 0; i < n; ++i) { n       for (int j = 0; j < m; ++j) { n         if ((tmp[i + j] += static_cast<unsigned long long>(a[i]) * b[j]) >> n             62) { n           tmp[i + j] %= MOD; n         } n       } n     } n     for (int i = 0; i < l; ++i) { n       ans[i] = tmp[i] % MOD; n       tmp[i] = 0; n     } n     return ans; n   } n   for (; (1 << lg) < l; ++lg) { n   } n   memset(aa, 0, sizeof(int) << lg); n   copy(a.begin(), a.end(), aa); n   fft(aa, lg, 0); n   memset(bb, 0, sizeof(int) << lg); n   copy(b.begin(), b.end(), bb); n   fft(bb, lg, 0); n   for (int i = 0, _ = 1 << lg; i < _; ++i) { n     cc[i] = 1LL * aa[i] * bb[i] % MOD; n   } n   fft(cc, lg, 1); n   copy(cc, cc + l, ans.begin()); n   return ans; n } n vector<int> operator+(const vector<int> &a, const vector<int> &b) { n   const vector<int> &aa = a.size() > b.size() ? a : b; n   const vector<int> &bb = a.size() > b.size() ? b : a; n   vector<int> ret(aa); n   auto it = ret.begin(); n   auto jt = bb.begin(); n   for (; jt != bb.end(); ++it, ++jt) { n     *it = rmod(*it + *jt); n   } n   return ret; n } n vector<int> g[N]; n int pa[N], dep[N], nxt[N], sz[N]; n void dfs1(int u) { n   sz[u] = 1; n   for (int v : g[u]) { n     if (v == pa[u]) continue; n     pa[v] = u; n     dep[v] = dep[u] + 1; n     dfs1(v); n     sz[u] += sz[v]; n     if (sz[v] > sz[nxt[u]]) nxt[u] = v; n   } n } n vector<int> polys[N]; n pair<vector<int>, vector<int> > solve(const vector<int> &idx, int l, int r) { n   if (l + 1 == r) { n     return {polys[idx[l]], polys[idx[l]]}; n   } n   int mid = (l + r) >> 1; n   auto ans1 = solve(idx, l, mid), ans2 = solve(idx, mid, r); n   return {ans1.first + ans2.first * ans1.second, ans1.second * ans2.second}; n } n void dfs2(int u) { n   assert(!pa[u] || nxt[pa[u]] != u); n   vector<int> idx(1, u); n   for (int v = nxt[u]; v; v = nxt[v]) { n     idx.emplace_back(v); n   } n   for (int u : idx) { n     polys[u] = {0, 1}; n     for (int v : g[u]) { n       if (v == pa[u] || v == nxt[u]) continue; n       dfs2(v); n       polys[v][0] += 1; n       polys[u] = polys[u] * polys[v]; n     } n   } n   polys[u] = solve(idx, 0, idx.size()).first; n } n int main() { n   int n = read(); n   LL x = read(); n   for (int i = 1, a, b; i < n; ++i) { n     a = read(); n     b = read(); n     g[a].emplace_back(b); n     g[b].emplace_back(a); n   } n   dfs1(1); n   dfs2(1); n   vector<int> &vc = polys[1]; n   int ans = 0, mul = 1; n   for (unsigned i = 1; i < vc.size(); ++i) { n     ans = (ans + 1LL * mul * vc[i]) % MOD; n     mul = (x + i) % MOD * qpow(i, MOD - 2) % MOD * mul % MOD; n   } n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, i; n string s; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(NULL); n   cout.tie(NULL); n   cin >> n >> s; n   for (i = 1; i <= n; i++) { n     if (n % i == 0) { n       reverse(s.begin(), s.begin() + i); n     } n   } n   cout << s; n } n


#include <bits/stdc++.h> n #pragma GCC target( avx ) n #pragma GCC optimize(2) n #pragma GCC optimize(3) n #pragma GCC optimize( Ofast ) n #pragma GCC optimize( inline ) n #pragma GCC optimize( -fgcse ) n #pragma GCC optimize( -fgcse-lm ) n #pragma GCC optimize( -fipa-sra ) n #pragma GCC optimize( -ftree-pre ) n #pragma GCC optimize( -ftree-vrp ) n #pragma GCC optimize( -fpeephole2 ) n #pragma GCC optimize( -ffast-math ) n #pragma GCC optimize( -fsched-spec ) n #pragma GCC optimize( unroll-loops ) n #pragma GCC optimize( -falign-jumps ) n #pragma GCC optimize( -falign-loops ) n #pragma GCC optimize( -falign-labels ) n #pragma GCC optimize( -fdevirtualize ) n #pragma GCC optimize( -fcaller-saves ) n #pragma GCC optimize( -fcrossjumping ) n #pragma GCC optimize( -fthread-jumps ) n #pragma GCC optimize( -funroll-loops ) n #pragma GCC optimize( -fwhole-program ) n #pragma GCC optimize( -freorder-blocks ) n #pragma GCC optimize( -fschedule-insns ) n #pragma GCC optimize( inline-functions ) n #pragma GCC optimize( -ftree-tail-merge ) n #pragma GCC optimize( -fschedule-insns2 ) n #pragma GCC optimize( -fstrict-aliasing ) n #pragma GCC optimize( -fstrict-overflow ) n #pragma GCC optimize( -falign-functions ) n #pragma GCC optimize( -fcse-skip-blocks ) n #pragma GCC optimize( -fcse-follow-jumps ) n #pragma GCC optimize( -fsched-interblock ) n #pragma GCC optimize( -fpartial-inlining ) n #pragma GCC optimize( no-stack-protector ) n #pragma GCC optimize( -freorder-functions ) n #pragma GCC optimize( -findirect-inlining ) n #pragma GCC optimize( -fhoist-adjacent-loads ) n #pragma GCC optimize( -frerun-cse-after-loop ) n #pragma GCC optimize( inline-small-functions ) n #pragma GCC optimize( -finline-small-functions ) n #pragma GCC optimize( -ftree-switch-conversion ) n #pragma GCC optimize( -foptimize-sibling-calls ) n #pragma GCC optimize( -fexpensive-optimizations ) n #pragma GCC optimize( -funsafe-loop-optimizations ) n #pragma GCC optimize( inline-functions-called-once ) n #pragma GCC optimize( -fdelete-null-pointer-checks ) n using namespace std; n using namespace std; n const int mod = 998244353; n int n, m, x, a[4000005], ans, w[4000005], r[4000005], invn, mx, lenk; n int ksm(int a, int b) { n   int s = 1; n   while (b > 0) { n     if (b & 1) s = (long long)s * a % mod; n     a = (long long)a * a % mod, b >>= 1; n   } n   return s; n } n void pre(int &n) { n   int len = 0; n   while (1 << len < n) len++; n   n = 1 << len; n   int G = ksm(3, (mod - 1) / n); n   invn = ksm(n, mod - 2); n   w[0] = w[n] = 1; n   for (int i = 1; i < n; i++) n     w[i] = (long long)w[i - 1] * G % mod, n     r[i] = (r[i >> 1] >> 1) | ((i & 1) << (len - 1)); n } n void fft(int *a, int all, int fl) { n   for (int i = 0; i < all; i++) n     if (i < r[i]) swap(a[i], a[r[i]]); n   int n = 2, m = 1, x = all / 2; n   for (; n <= all; m = n, n <<= 1, x >>= 1) n     for (int i = 0; i < all; i += n) n       for (int k = 0; k < m; k++) { n         int t = (long long)w[fl ? all - x * k : x * k] * a[i + m + k] % mod; n         a[i + m + k] = (a[i + k] + mod - t) % mod; n         a[i + k] = (a[i + k] + t) % mod; n       } n   if (fl) n     for (int i = 0; i < all; i++) a[i] = (long long)a[i] * invn % mod; n } n int main() { n   scanf( %d%d , &n, &m); n   for (int i = 1; i <= m; i++) scanf( %d , &x), a[x]++, mx = max(mx, x); n   lenk = n / 2 * mx + 1; n   pre(lenk); n   fft(a, lenk, 0); n   for (int i = 0; i < lenk; i++) a[i] = ksm(a[i], n / 2); n   fft(a, lenk, 1); n   for (int i = 0; i <= n / 2 * mx; i++) n     ans = (ans + (long long)a[i] * a[i] % mod) % mod; n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m; n long long a, b; n int main() { n   scanf( %d %d , &n, &m); n   a = 0, b = 1; n   for (int i = (1); i <= (n); i++) { n     long long c, d; n     d = 2 * m * b - a; n     a = m * b + (m - 1) * a; n     b = d; n     a %= 1000000007; n     b %= 1000000007; n   } n   printf( %lld n , (b + 1000000007) % 1000000007); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, ans, k, d, cnt1, cnt2, l, r; n int a[200050]; n struct node { n   int x, b; n }; n node s[200050]; n int main() { n   k = 1; n   scanf( %d , &n); n   for (int i = 1; i <= n; ++i) { n     scanf( %d , &a[i]); n   } n   l = 1, r = n, s[0].x = 0; n   d = 0; n   while ((a[l] > s[d].x || a[r] > s[d].x) && l <= r) { n     if (a[l] != a[r]) { n       if (a[l] < a[r] && a[l] > s[d].x || (a[l] > a[r] && a[r] <= s[d].x)) { n         d++; n         s[d].x = a[l]; n         s[d].b = 0; n         ans = d; n         l++; n         continue; n       } n       if (a[r] > s[d].x) { n         d++; n         s[d].x = a[r]; n         s[d].b = 1; n         ans = d; n         r--; n         continue; n       } n     } n     if (a[l] == a[r] && l != r) { n       k = 0; n       cnt1 = 0, cnt2 = 0; n       for (int j = l; j <= r - 1; ++j) { n         if (a[j + 1] > a[j]) n           cnt1++; n         else n           break; n       } n       for (int j = r; j >= l + 1; --j) { n         if (a[j] < a[j - 1]) n           cnt2++; n         else n           break; n       } n       if (cnt1 >= cnt2) { n         ans += cnt1 + 1; n         printf( %d n , ans); n         for (int j = 1; j <= ans - cnt1 - 1; ++j) { n           if (s[j].b == 0) n             printf( L ); n           else n             printf( R ); n         } n         for (int j = 0; j < cnt1 + 1; ++j) { n           printf( L ); n         } n         break; n       } n       if (cnt1 < cnt2) { n         ans += cnt2 + 1; n         printf( %d n , ans); n         for (int j = 1; j <= ans - cnt2 - 1; ++j) { n           if (s[j].b == 0) n             printf( L ); n           else n             printf( R ); n         } n         for (int j = 0; j < cnt2 + 1; ++j) { n           printf( R ); n         } n         break; n       } n     } n     if (l == r && k == 1) { n       ans++; n       s[ans].b = 1; n       break; n     } n   } n   if (k == 1) { n     printf( %d n , ans); n     for (int i = 1; i <= ans; ++i) { n       if (s[i].b == 0) n         printf( L ); n       else n         printf( R ); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, s, a[200100], cnt[200100], ans, kol; n set<int> st; n int main() { n   cin >> n >> s; n   for (int i = 1; i <= n; ++i) { n     cin >> a[i]; n   } n   for (int i = 1; i <= n; ++i) { n     if (i == s) { n       if (a[i] != 0) { n         a[i] = 0; n         ans++; n       } n       st.insert(a[i]); n       continue; n     } n     if (a[i] == 0) { n       a[i] = n; n       kol++; n     } n     cnt[a[i]]++; n     st.insert(a[i]); n   } n   for (int i = 1; i <= n; ++i) { n     if (i > *st.rbegin()) break; n     if (cnt[i] == 0) { n       int pp = *st.rbegin(); n       if (cnt[pp] == 1) { n         st.erase(pp); n       } n       ans++; n       st.insert(i); n       cnt[pp]--; n     } n   } n   cout << max(ans, kol); n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 505; n int cnt[N * N], par[N][N], sum[N][N], sz[N * N]; n char grid[N][N]; n int n, k; n int cur = 0; n void change(int id, int add) { n   if (id == 0) return; n   if (cnt[id]) cur -= sz[id]; n   cnt[id] += add; n   if (cnt[id]) cur += sz[id]; n } n void paint(int r, int c, int col) { n   if (r < 1 || c < 1 || r > n || c > n) return; n   if (grid[r][c] !=  . ) return; n   if (par[r][c] != 0) return; n   par[r][c] = col; n   ++sz[col]; n   paint(r - 1, c, col); n   paint(r + 1, c, col); n   paint(r, c - 1, col); n   paint(r, c + 1, col); n } n int inside(int r, int c) { n   return sum[r + k - 1][c + k - 1] - sum[r - 1][c + k - 1] - n          sum[r + k - 1][c - 1] + sum[r - 1][c - 1]; n } n int main() { n   cin >> n >> k; n   for (int i = 1; i <= n; ++i) n     for (int j = 1; j <= n; ++j) scanf(  %c , &grid[i][j]); n   for (int i = 1; i <= n; ++i) n     for (int j = 1; j <= n; ++j) n       if (grid[i][j] ==  . ) { n         if (par[i][j] == 0) { n           paint(i, j, i * n + j); n         } n       } n   for (int i = 1; i < N; ++i) n     for (int j = 1; j < N; ++j) n       sum[i][j] = sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + n                   (grid[i][j] !=  . ); n   int ans = 0; n   for (int i = 1; i <= n - k + 1; ++i) { n     memset(cnt, 0, sizeof(cnt)); n     cur = 0; n     for (int r = i - 1; r <= i + k; ++r) n       for (int c = 0; c <= k + 1; ++c) change(par[r][c], 1); n     change(par[i - 1][k + 1], -1); n     change(par[i + k][k + 1], -1); n     ans = max(ans, cur + inside(i, 1)); n     for (int j = 2; j <= n - k + 1; ++j) { n       for (int r = i - 1; r <= i + k; ++r) { n         change(par[r][j + k], 1); n       } n       change(par[i - 1][j + k - 1], +1); n       change(par[i + k][j + k - 1], +1); n       change(par[i - 1][j - 2], +1); n       change(par[i + k][j - 2], +1); n       for (int r = i - 1; r <= i + k; ++r) { n         change(par[r][j - 2], -1); n       } n       change(par[i - 1][j + k], -1); n       change(par[i + k][j + k], -1); n       change(par[i - 1][j - 1], -1); n       change(par[i + k][j - 1], -1); n       ans = max(ans, cur + inside(i, j)); n     } n   } n   cout << ans <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n bool setmax(T &_a, T _b) { n   if (_b > _a) { n     _a = _b; n     return true; n   } n   return false; n } n template <class T> n bool setmin(T &_a, T _b) { n   if (_b < _a) { n     _a = _b; n     return true; n   } n   return false; n } n template <class T> n T gcd(T _a, T _b) { n   return _b == 0 ? _a : gcd(_b, _a % _b); n } n const int MAXN = 1010; n bool vis[MAXN]; n vector<int> es[MAXN]; n int n; n int que[MAXN], lst[MAXN], d[MAXN], ss, tt; n void bfs(int start) { n   ss = tt = 1; n   que[1] = start; n   vis[start] = true; n   d[start] = 0; n   while (ss <= tt) { n     int x = que[ss++]; n     for (int y : es[x]) n       if (!vis[y]) { n         vis[y] = true; n         d[y] = d[x] + 1; n         que[++tt] = y; n       } n   } n } n int solve_component(int start) { n   bfs(start); n   int len = tt; n   for (int i = int(1); i <= int(len); ++i) lst[i] = que[i]; n   int ans = -1; n   for (int k = int(1); k <= int(len); ++k) { n     for (int i = int(1); i <= int(len); ++i) vis[lst[i]] = false; n     bfs(lst[k]); n     bool ok = true; n     for (int i = int(1); i <= int(tt); ++i) { n       int x = que[i]; n       for (int y : es[x]) n         if (abs(d[x] - d[y]) != 1) ok = false; n     } n     if (ok) setmax(ans, d[que[tt]]); n   } n   return ans; n } n int main() { n   int m; n   scanf( %d%d , &n, &m); n   for (int i = int(1); i <= int(n); ++i) es[i].clear(); n   for (int i = int(1); i <= int(m); ++i) { n     int x, y; n     scanf( %d%d , &x, &y); n     es[x].push_back(y), es[y].push_back(x); n   } n   memset(vis, false, sizeof(vis)); n   int ans = 0; n   for (int i = int(1); i <= int(n); ++i) n     if (!vis[i]) { n       int tmp = solve_component(i); n       if (tmp < 0) { n         ans = -1; n         break; n       } n       ans += tmp; n     } n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int TESTS = 1; n   while (TESTS--) { n     int n, e; n     set<int> v; n     map<int, int> m; n     cin >> n; n     for (long long int i = 0; i < n; i++) { n       cin >> e; n       m[e]++; n       if (m[e] == 1) v.insert(e); n     } n     int np = 0, ps = 0; n     while (!v.empty()) { n       ps = 0; n       for (map<int, int>::iterator itm = m.begin(); itm != m.end(); itm++) { n         while (itm->second != 0 && itm->first >= ps) { n           itm->second -= 1; n           ps += 1; n         } n         if (itm->second == 0) v.erase(itm->first); n       } n       np++; n     } n     cout << np; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n set<pair<long long, long long> > S; n set<pair<long long, long long> >::iterator it; n set<pair<long long, long long> >::iterator it2; n pair<long long, long long> temp; n void intersect_yes(long long s, long long e) { n   if (S.empty()) return; n   for (it = S.begin(); it != S.end();) { n     if (it->first < s && it->second < s) n       S.erase(it++); n     else n       break; n   } n   if (S.empty()) return; n   bool finish = 0; n   for (it = --S.end(); !finish;) { n     if (it == S.begin()) finish = true; n     if (it->first > e) n       S.erase(it--); n     else n       break; n   } n   if (S.empty()) return; n   temp = *S.begin(); n   S.erase(temp); n   temp.first = max(s, temp.first); n   S.insert(temp); n   temp = *(--S.end()); n   S.erase(temp); n   temp.second = min(temp.second, e); n   S.insert(temp); n } n const long long big = 1LL << 55; n void intersect_no(long long s, long long e) { n   it = S.lower_bound(make_pair(s, big)); n   if (it != S.begin()) it--; n   it2 = S.upper_bound(make_pair(e, big)); n   while (it != it2) { n     if (it->second < s) n       it++; n     else if (it->first < s) { n       if (it->second >= s && it->second <= e) { n         temp = *it; n         it++; n         S.erase(temp); n         S.insert(make_pair(temp.first, s - 1)); n       } else if (it->second > e) { n         temp = *it; n         it++; n         S.erase(temp); n         S.insert(make_pair(temp.first, s - 1)); n         S.insert(make_pair(e + 1, temp.second)); n       } n     } else if (it->first >= s && it->first <= e) { n       if (it->second <= e) { n         S.erase(it++); n       } else if (it->second > e) { n         temp = *it; n         it++; n         S.erase(temp); n         S.insert(make_pair(e + 1, temp.second)); n       } n     } n   } n } n int main() { n   int h, q, lvl, ans; n   long long l, r; n   scanf( %d%d , &h, &q); n   long long begining = 1LL << (h - 1), ending = (1LL << h) - 1; n   S.insert(make_pair(begining, ending)); n   for (int i = 0; i < q; i++) { n     scanf( %d%I64d%I64d%d , &lvl, &l, &r, &ans); n     long long left = l * (1LL << (h - lvl)), n               right = (r + 1) * (1LL << (h - lvl)) - 1; n     if (S.empty()) { n       printf( Game cheated! n ); n       return 0; n     } n     if (ans) n       intersect_yes(left, right); n     else n       intersect_no(left, right); n   } n   if (S.empty()) n     printf( Game cheated! n ); n   else if (S.size() == 1 && (*S.begin()).first == (*S.begin()).second) n     printf( %I64d n , (*S.begin()).first); n   else n     printf( Data not sufficient! n ); n } n


#include<stdio.h> n #include<bits/stdc++.h> n  n typedef long long ll; n  n using namespace std; n  n  n int main() n { n     ll deva; n     cin>>deva; n     for(ll ol=0;ol<deva;ol++) n     { n         int n; n         cin>>n; n         string s; n         cin>>s; n         int a[26]={0}; n         int flag=1; n         a[s[0]- A ]+=1; n         for(int i=1;i<n;i++) n         { n             if(a[s[i]- A ]>0 && s[i]!=s[i-1]) n             { n                 flag=0; n                 break; n             } n             a[s[i]- A ]+=1; n         } n         if(flag) n             cout<< YES <<endl; n         else     n             cout<< NO <<endl; n     } n     return 0; n }


#include <bits/stdc++.h> n using namespace std; n int a[100500]; n int sp[2005]; n int f[100500], l[100500]; n int n, m; n int ns[2 * 100500]; n int ps[2 * 100500]; n int used[2 * 100500]; n int lp[100500]; n int rp[100500]; n int main() { n   scanf( %d%d , &n, &m); n   for (int i = 1; i <= n; ++i) { n     scanf( %d , a + i); n   } n   sort(a + 1, a + n + 1); n   for (int i = 1; i <= m; ++i) { n     scanf( %d , sp + i); n     used[sp[i]] = true; n     ns[sp[i]] = sp[i]; n     ps[sp[i]] = sp[i]; n   } n   for (int i = n; i >= 1; --i) { n     if (i != n && a[i] == a[i + 1] - 1) { n       rp[i] = rp[i + 1]; n     } else { n       rp[i] = i; n     } n   } n   for (int i = 1; i <= n; ++i) { n     if (i != 1 && a[i] == a[i - 1] + 1) { n       lp[i] = lp[i - 1]; n     } else { n       lp[i] = i; n     } n   } n   for (int i = 2 * 100500 - 2; i >= 0; --i) { n     if (ns[i] == 0) { n       ns[i] = ns[i + 1]; n     } n   } n   for (int i = 1; i < 2 * 100500; ++i) { n     if (ps[i] == 0) { n       ps[i] = ps[i - 1]; n     } n   } n   sort(sp + 1, sp + m + 1); n   f[0] = 0, l[0] = 0; n   for (int i = 1; i <= n; ++i) { n     int df = a[i] - i; n     for (int cp = a[i], cnt = used[a[i]]; cp && df < cp; n          ++cnt, cp = ps[cp - 1]) { n       l[i] = max(l[i], f[lp[i - a[i] + cp] - 1] + cnt); n     } n     f[i] = max(f[i], l[i]); n     df = n - i + a[i]; n     for (int cp = a[i], cnt = used[a[i]]; cp && df >= cp; n          ++cnt, cp = ns[cp + 1]) { n       f[rp[i + cp - a[i]]] = max(f[rp[i + cp - a[i]]], l[i] + cnt - used[a[i]]); n     } n   } n   int res = *max_element(f + 1, f + n + 1); n   printf( %d n , res); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int INF = 1000000007; n string FILENAME =  input ; n string FILEINPUT = FILENAME; n void writeln(int a) { printf( %d n , a); } n void writeln(int a, int b) { printf( %d %d n , a, b); } n void writeln(int a, int b, int c) { printf( %d %d %d n , a, b, c); } n void writeln(int a, int b, int c, int d) { n   printf( %d %d %d %d n , a, b, c, d); n } n void write(int a) { printf( %d , a); } n void write(int a, int b) { printf( %d %d , a, b); } n void write(int a, int b, int c) { printf( %d %d %d , a, b, c); } n void write(int a, int b, int c, int d) { printf( %d %d %d %d , a, b, c, d); } n void read(int &a) { scanf( %d , &a); } n void read(int &a, int &b) { scanf( %d %d , &a, &b); } n void read(int &a, int &b, int &c) { scanf( %d %d %d , &a, &b, &c); } n void read(int &a, int &b, int &c, int &d) { n   scanf( %d %d %d %d , &a, &b, &c, &d); n } n void readln(int &a) { scanf( %d n , &a); } n void readln(int &a, int &b) { scanf( %d %d n , &a, &b); } n void readln(int &a, int &b, int &c) { scanf( %d %d %d n , &a, &b, &c); } n void readln(int &a, int &b, int &c, int &d) { n   scanf( %d %d %d %d n , &a, &b, &c, &d); n } n void readln(vector<int> &f, int n) { n   int x; n   for (int i = 1; i <= n; i++) { n     read(x); n     f.push_back(x); n   } n } n void writeln(vector<int> &f) { n   for (int i = 0; i < f.size(); i++) n     printf( %d%c , f[i], i == f.size() - 1 ?   n  :    ); n } n void run() { n   int n; n   vector<int> a; n   read(n); n   readln(a, n); n   sort(a.begin(), a.end()); n   int i = -1, j = 0, t, mx = 0; n   read(t); n   while (j != n) { n     i++; n     while (j < n && a[j] - a[i] <= t) j++; n     mx = max(mx, j - i); n   } n   writeln(mx); n } n int main() { n   run(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a[110]; n int r; n void solve(int x) { n   r = 0; n   while (x) { n     a[r++] = x % 3; n     x /= 3; n   } n } n int main() { n   int t; n   scanf( %d , &t); n   while (t--) { n     memset(a, 0, sizeof a); n     int n; n     scanf( %d , &n); n     solve(n); n     a[r] = 0; n     for (int i = r; i >= 0; i--) { n       if (a[i] == 2) { n         for (int j = i + 1; j <= r; j++) { n           if (a[j] == 1) n             a[j] = 0; n           else if (a[j] == 0) { n             a[j] = 1; n             break; n           } n         } n         for (int k = i; k >= 0; k--) a[k] = 0; n         break; n       } n     } n     int ans = 0; n     for (int i = r; i >= 0; i--) { n       ans += a[i] * pow(3, i); n     } n     printf( %d n , ans); n   } n } n


#include <bits/stdc++.h> n int main() { n   int n, m1, m2, m3, min1, min2, min3, max1, max2, max3; n   scanf( %d%d%d%d%d%d%d , &n, &min1, &max1, &min2, &max2, &min3, &max3); n   m1 = n - min2 - min3; n   if (m1 <= max1) n     printf( %6d %6d %6d , m1, min2, min3); n   else { n     m2 = min2 + m1 - max1; n     if (m2 < max2) n       printf( %6d %6d %6d , max1, m2, min3); n     else { n       m3 = n - max1 - max2; n       printf( %6d %6d %6d , max1, max2, m3); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( O3 ) n #pragma GCC target( sse4 ) n #pragma GCC optimize( unroll-loops ) n #pragma GCC target( avx2 ) n using namespace std; n const long long MAX = -1000000000000000000; n const long long MIN = 1000000000000000000; n const long long inf = 1000000000; n const long long KOK = 100000; n const long long LOG = 30; n const long long li = 500005; n const long long mod = 1000000007; n int n, m, b[li], a[li], k, flag, t, fa[li], si[li], vis[li], visit[li], x[li], n     y[li], use[li]; n int cev; n queue<int> q; n set<pair<long long, long long> > st; n string s; n vector<int> v[li], vec; n inline int dsu(int x) { n   if (x == fa[x]) return x; n   return fa[x] = dsu(fa[x]); n } n int main(void) { n   scanf( %d %d , &n, &k); n   for (int i = 1; i <= n; i++) { n     scanf( %d , &a[i]); n   } n   for (int i = 1; i <= k; i++) { n     scanf( %d %d , &x[i], &y[i]); n     use[x[i]]++; n     use[y[i]]++; n     v[x[i]].push_back(i); n     v[y[i]].push_back(i); n   } n   for (int i = 1; i <= k; i++) { n     if (use[x[i]] <= a[x[i]] || use[y[i]] <= a[y[i]]) q.push(i); n   } n   while (q.size()) { n     int node = q.front(); n     q.pop(); n     if (vis[node]) continue; n     vis[node] = 1; n     vec.push_back(node); n     use[x[node]]--; n     use[y[node]]--; n     int nodee = node; n     node = x[node]; n     for (int i = 0; i < (int)v[node].size(); i++) { n       if ((use[x[v[node][i]]] <= a[x[v[node][i]]] || n            use[y[v[node][i]]] <= a[y[v[node][i]]]) && n           vis[v[node][i]] == 0) n         q.push(v[node][i]); n     } n     node = y[nodee]; n     for (int i = 0; i < (int)v[node].size(); i++) { n       if ((use[x[v[node][i]]] <= a[x[v[node][i]]] || n            use[y[v[node][i]]] <= a[y[v[node][i]]]) && n           vis[v[node][i]] == 0) n         q.push(v[node][i]); n     } n   } n   if ((int)vec.size() != k) { n     printf( DEAD n ); n     return 0; n   } n   printf( ALIVE n ); n   reverse(vec.begin(), vec.end()); n   for (int i = 0; i < (int)vec.size(); i++) { n     printf( %d  , vec[i]); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long MXN = 1e6 + 1; n const long long MNN = 1e3 + 1; n const long long MOD = 1e9 + 7; n const long long INF = 1e18; n const long long MAGIC = 1000; n const long double EPS = 1e-9; n const long double PI = 3.1415926536; n const string TIME =  rovno_ushten_push_ketti ; n long long n; n long long cnt[MXN]; n set<long long> s; n int main() { n   ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); n   cin >> n; n   for (long long i = 1; i <= n; ++i) { n     long long x; n     cin >> x; n     s.insert(x); n     ++cnt[x]; n   } n   if (s.size() == 2) { n     long long x = *s.begin(); n     s.erase(s.begin()); n     long long y = *s.begin(); n     if (cnt[x] == cnt[y]) { n       cout <<  YES n ; n       cout << x <<     << y; n     } else { n       cout <<  NO ; n     } n   } else { n     cout <<  NO ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int n, m, ns, ne, v, i; n   cin >> n >> m >> ns >> ne >> v; n   vector<long long int> s(ns), e(ne); n   for (i = 0; i < ns; i++) cin >> s[i]; n   for (i = 0; i < ne; i++) cin >> e[i]; n   long long int q; n   cin >> q; n   while (q--) { n     long long int x1, y1, x2, y2; n     cin >> x1 >> y1 >> x2 >> y2; n     if (x1 == x2) { n       cout << abs(y1 - y2) << endl; n       continue; n     } n     long long int ans = INT_MAX, tmp, c; n     c = lower_bound(s.begin(), s.end(), y1) - s.begin(); n     if (c < s.size()) { n       tmp = abs(y1 - s[c]) + abs(x1 - x2) + abs(s[c] - y2); n       ans = min(tmp, ans); n     } n     if (c >= 1) { n       c -= 1; n       tmp = abs(y1 - s[c]) + abs(x1 - x2) + abs(s[c] - y2); n       ans = min(tmp, ans); n     } n     c = lower_bound(e.begin(), e.end(), y1) - e.begin(); n     if (c < e.size()) { n       tmp = abs(y1 - e[c]) + (abs(x1 - x2) + v - 1) / v + abs(e[c] - y2); n       ans = min(tmp, ans); n     } n     if (c >= 1) { n       c -= 1; n       tmp = abs(y1 - e[c]) + (abs(x1 - x2) + v - 1) / v + abs(e[c] - y2); n       ans = min(tmp, ans); n     } n     cout << ans << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n map<pair<long long, long long>, long long> mp; n signed main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long n, m; n   cin >> n >> m; n   for (long long i = 0; i < m; i++) { n     long long a, b; n     cin >> a >> b; n     a--; n     b--; n     mp[{a, b}] = 1; n     mp[{b, a}] = 1; n   } n   if (n < 7) { n     cout << m << endl; n   } else { n     long long ans = m; n     for (long long i = 0; i < n; i++) { n       for (long long j = 0; j < n; j++) { n         long long ctr = 0; n         for (long long k = 0; k < n; k++) { n           if (mp[{i, k}] == 1 and mp[{j, k}]) { n             ctr++; n           } n         } n         ans = min(ans, ctr); n       } n     } n     cout << m - ans << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = 1e9 + 7; n long long getres(long long n) { n   if (n == 0) { n     return 0; n   } n   vector<long long> now; n   for (long long i = 0;; i++) { n     long long t = pow(2, i); n     if (t <= n) { n       n -= t; n       now.push_back(t); n       if (n == 0) { n         break; n       } n     } else { n       now.push_back(n); n       break; n     } n   } n   long long even = 0, odd = 0; n   for (long long i = 0; i < now.size(); i++) { n     if (i % 2) { n       even = (even + now[i]) % mod; n     } else { n       odd = (odd + now[i]) % mod; n     } n   } n   long long odd_sum = (((odd) % mod) * (odd % mod)) % mod; n   long long even_sum = (((even) % mod) * ((even + 1) % mod)) % mod; n   long long res = (odd_sum + even_sum) % mod; n   return res; n } n int main() { n   ios_base::sync_with_stdio(false); n   long long l, r; n   cin >> l >> r; n   long long ans = (getres(r) - getres(l - 1) + mod) % mod; n   cout << ans <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n struct zero { n   int nxt, to; n } edge[200000 << 1]; n int head[200000], tot = 0; n void add_edge(int a, int b) { n   edge[++tot] = (zero){head[a], b}; n   head[a] = tot; n } n int n, m, plk, poi, d1, d2, dep[200000], kl[200000], d[200000], op[200000], n     h[200000]; n bool flag; n void aux(int x, int fa) { n   if (dep[x] > plk) plk = dep[x], poi = x; n   for (int i = head[x]; i; i = edge[i].nxt) { n     int to = edge[i].to; n     if (to == fa) continue; n     dep[to] = dep[x] + 1; n     kl[to] = x; n     aux(to, x); n   } n } n bool cmp(int a, int b) { return h[a] < h[b]; } n void solve(int x, int fa) { n   vector<int> v; n   for (int i = head[x]; i; i = edge[i].nxt) { n     int to = edge[i].to; n     if (to == fa) continue; n     v.push_back(to); n   } n   op[x] = 0; n   if (v.size() == 0) n     h[x] = op[x] = 0; n   else if (v.size() == 1) { n     int to = v[0]; n     solve(to, x); n     if (op[to] || h[to]) flag = 0; n     op[x] = x, h[x] = h[v[0]] + 1; n   } else if (v.size() == 2) { n     solve(v[0], x), solve(v[1], x); n     if ((op[v[0]] && op[v[1]]) || h[v[0]] != h[v[1]]) n       flag = 0; n     else if (op[v[0]] || op[v[1]]) n       op[x] = op[v[0]] + op[v[1]]; n     h[x] = h[v[0]] + 1; n   } else if (v.size() == 3) { n     solve(v[0], x), solve(v[1], x), solve(v[2], x); n     sort(v.begin(), v.end(), cmp); n     if (op[v[0]] || op[v[1]] || op[v[2]]) flag = 0; n     if (!(h[v[1]] == h[v[0]] && h[v[2]] == h[v[0]] + 1)) flag = 0; n     op[x] = x, h[x] = h[v[2]] + 1; n   } else n     flag = 0; n } n int main() { n   scanf( %d , &n); n   m = (1 << n) - 2; n   for (int i = 1; i < m; i++) { n     int a, b; n     scanf( %d%d , &a, &b); n     add_edge(a, b), add_edge(b, a); n     d[a]++, d[b]++; n   } n   poi = plk = dep[1] = 0; n   aux(1, 0); n   d1 = poi; n   poi = plk = dep[d1] = kl[d1] = 0; n   aux(d1, 0); n   d2 = poi; n   int poss = d2; n   vector<int> syk; n   while (poss) { n     if (abs(2 * dep[poss] - dep[d2]) <= 1) { n       flag = 1; n       solve(poss, 0); n       if (op[poss] && flag && h[poss] == n - 1) syk.push_back(op[poss]); n     } n     poss = kl[poss]; n   } n   cout << syk.size() << endl; n   sort(syk.begin(), syk.end()); n   for (int i = 0; i < syk.size(); i++) cout << syk[i] <<    ; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> fibton; n void Fib(int n) { n   int x = 0, y = 1, z = 0; n   fibton.push_back(0); n   for (int i = 0; i <= n; i++) { n     z = x + y; n     fibton.push_back(z); n     if (fibton[fibton.size() - 1] >= n) { n       break; n     } n     x = y; n     y = z; n   } n } n int main() { n   int n; n   cin >> n; n   Fib(n); n   for (int i = 0; i < fibton.size(); i++) { n     for (int j = i; j < fibton.size(); j++) { n       for (int k = j; k < fibton.size(); k++) { n         if ((fibton[i] + fibton[j] + fibton[k]) == n) { n           cout << fibton[i] <<     << fibton[j] <<     << fibton[k]; n           return 0; n         } n       } n     } n   } n   return 0; n } n


#include <iostream> n #include <iomanip> n #include <cstdio> n #include <vector> n #include <algorithm> n #include <cmath> n #include <cstring> n #include <cassert> n #include <string> n #include <set> n #include <map> n #include <random> n #include <bitset> n #include <string> n #include <unordered_set> n #include <unordered_map> n #include <deque> n #include <queue> n #define rep(i, n) for (int i = 0; i < (n); i++) n #define all(x) (x).begin(), (x).end() n #define rall(x) (x).rbegin(), (x).rend() n  n using namespace std; n using ll = long long; n using ul = unsigned long long; n using ld = long double; n  n int main() { n   ios_base::sync_with_stdio(0); cin.tie(0); n   int k; n   string s; n   cin >> k >> s; n   int n = 1 << k, pos = 0; n   vector<int> a(n * 2, 1), num(n * 2), rn(n); n   for (int i = k - 1; i >= 0; --i) n     rep(j, 1 << i) { n       num[(1 << i) + j] = pos; n       rn[pos] = (1 << i) + j; n       ++pos; n     } n   auto rel = [&](int v, char c) { n     if (c ==  0 ) n       a[v] = a[v * 2]; n     else if (c ==  1 ) n       a[v] = a[v * 2 + 1]; n     else n       a[v] = a[v * 2] + a[v * 2 + 1]; n   }; n   for (int i = n - 1; i; --i) n     rel(i, s[num[i]]); n   int q; n   cin >> q; n   while (q--) { n     int v; n     char c; n     cin >> v >> c; n     --v; n     s[v] = c; n     v = rn[v]; n     while (v > 0) { n       rel(v, s[num[v]]); n       v /= 2; n     } n     cout << a[1] <<   n ; n   } n } n  n


#include <bits/stdc++.h> n using namespace std; n int lim; n char c[1000]; n int g[1000][1000]; n int f[1000][1000], pre[1000][1000]; n void back(int v, int k) { n   int p = pre[v][k]; n   if (p) { n     back(p, k - 1); n     printf( + ); n   } n   int i1 = p + 1; n   int j1 = v; n   for (; i1 < j1; i1++, j1--) n     if (c[i1 - 1] != c[j1 - 1]) c[j1 - 1] = c[i1 - 1]; n   for (int i = p + 1; i <= v; i++) printf( %c , c[i - 1]); n } n int main() { n   scanf( %s , c); n   scanf( %d , &lim); n   for (int i = 1; i < strlen(c); i++) n     for (int j = i + 1; j <= strlen(c); j++) { n       int i1 = i; n       int j1 = j; n       for (; i1 < j1; i1++, j1--) n         if (c[i1 - 1] != c[j1 - 1]) g[i][j]++; n     } n   memset(f, 127, sizeof(f)); n   f[0][0] = 0; n   for (int i = 1; i <= strlen(c); i++) n     for (int j = 0; j < i; j++) n       for (int k = 0; k < lim && k <= j; k++) n         if (f[j][k] + g[j + 1][i] < f[i][k + 1]) n           f[i][k + 1] = f[j][k] + g[j + 1][i], pre[i][k + 1] = j; n   int min = 2000000000; n   int pos = lim + 1; n   for (int i = 0; i <= lim; i++) n     if (f[strlen(c)][i] < min) { n       min = f[strlen(c)][i], pos = i; n     } n   printf( %d n , min); n   back(strlen(c), pos); n   printf(  n ); n } n


#include <bits/stdc++.h> n using namespace std; n const int mm = 500050; n int n, ss, tt, kk, m; n int c[1001001], v[1001001]; n int g[1001001]; n int xx[1001001], yy[1001001], minvv = 0, initi = 0; n long long sum[500500], ti[500500]; n vector<int> num[500500]; n inline void solve() { n   int i = 0; n   while (i <= m) { n     if (initi - ti[i] <= tt) break; n     initi -= ti[i]; n     minvv += mm; n     ++i; n   } n   memset(xx, 0, sizeof(xx)); n   int j = 0; n   while (j < num[i].size()) { n     int vv = num[i][j]; n     ++xx[1]; n     --xx[vv + 1]; n     ++j; n   } n   int now = i; n   i = 1; n   while (i <= mm) { n     xx[i] += xx[i - 1]; n     ++i; n   } n   i = 1; n   while (i <= mm) { n     ++minvv; n     if (initi - xx[i] - sum[now] <= tt) break; n     initi -= xx[i] + sum[now]; n     ++i; n   } n } n int main() { n   scanf( %d%d%d%d , &n, &kk, &ss, &tt); n   int i = 1; n   while (i <= n) { n     scanf( %d%d , &c[i], &v[i]); n     ++i; n   } n   g[0] = 0; n   i = 1; n   while (i <= kk) { n     scanf( %d , &g[i]); n     ++i; n   } n   g[kk + 1] = ss; n   ++kk; n   sort(g + 1, g + kk + 1); n   i = 1; n   while (i <= kk) { n     minvv = max(minvv, g[i] - g[i - 1]); n     ++i; n   } n   i = 1; n   while (i <= kk) { n     int x = minvv - (g[i] - g[i - 1]), y = 2 * (g[i] - g[i - 1]) - minvv; n     if (y <= 0) { n       initi += g[i] - g[i - 1]; n     } else { n       initi += x + 2 * y; n       num[y / mm].push_back(y % mm); n       ti[y / mm] += y % mm; n       ; n     } n     ++i; n   } n   m = 2000000000 / mm; n   sum[m + 1] = 0; n   i = m; n   while (i >= 0) { n     sum[i] = sum[i + 1] + num[i + 1].size(); n     ti[i] += 1ll * sum[i] * mm; n     --i; n   } n   if (initi > tt) solve(); n   int ans = 2000000000; n   i = 1; n   while (i <= n) { n     if (v[i] >= minvv) ans = min(ans, c[i]); n     ++i; n   } n   if (ans == 2000000000) ans = -1; n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1000005; n int n, k; n struct edge { n   int v; n   edge *nxt; n } g[maxn << 1], *he[maxn]; n int cnt; n void add_edge(int a, int b) { n   edge *e = g + (++cnt); n   e->v = b, e->nxt = he[a]; n   he[a] = e; n } n bool in[maxn]; n int mxs[maxn], dep[maxn], fa[maxn]; n int f[maxn][25]; n void dfs(int p, int ffa) { n   dep[p] = dep[ffa] + 1; n   f[p][0] = ffa; n   fa[p] = ffa; n   for (int i = 1; i <= 20; ++i) f[p][i] = f[f[p][i - 1]][i - 1]; n   for (edge *e = he[p]; e; e = e->nxt) { n     int to = e->v; n     if (to == ffa) continue; n     dfs(to, p); n   } n } n int main() { n   scanf( %d%d , &n, &k); n   k = n - k; n   int a, b; n   for (int i = 1; i < n; ++i) { n     scanf( %d%d , &a, &b); n     add_edge(a, b); n     add_edge(b, a); n   } n   dep[n] = -1; n   dfs(n, 0); n   k--; n   in[n] = true; n   int now = n; n   for (int i = n - 1; i; --i) { n     if (k == 0) break; n     int p = i; n     for (int j = 20; ~j; --j) n       if (!in[f[p][j]] && f[p][j] != 0) { n         p = f[p][j]; n       } n     int lc = f[p][0]; n     if (dep[i] - dep[lc] <= k) { n       p = i; n       while (!in[p] && p != lc) { n         in[p] = true; n         p = fa[p]; n         k--; n       } n     } n   } n   vector<int> ans; n   for (int i = 1; i <= n; ++i) { n     if (!in[i]) ans.push_back(i); n   } n   for (int i = 0; i < ans.size(); ++i) printf( %d  , ans[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e6; n int t, tot, type[N]; n long long r, f[N]; n vector<int> son[N]; n template <class T> n inline void read(T &x) { n   x = 0; n   char ch = getchar(), w = 0; n   while (!isdigit(ch)) w = ch ==  - , ch = getchar(); n   while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar(); n   x = w ? -x : x; n   return; n } n inline char getch() { n   char c = getchar(); n   while (c ==    ) c = getchar(); n   return c; n } n int solve(int fa) { n   char c = getch(); n   int now = ++tot; n   type[now] = 0, son[now].clear(); n   if (c ==  * ) return f[now] = 1, now; n   son[now].push_back(solve(now)); n   while (1) { n     c = getch(); n     if (c ==  S ) n       type[now] = 1; n     else if (c ==  P ) n       type[now] = 2; n     else n       break; n     son[now].push_back(solve(now)); n   } n   if (type[now] == 1) { n     f[now] = 1e18; n     for (auto &v : son[now]) f[now] = min(f[v], f[now]); n   } else { n     f[now] = 0; n     for (auto &v : son[now]) f[now] += f[v]; n   } n   return now; n } n void resolve(int now, long long r) { n   if (type[now] == 0) { n     printf( %lld  , r); n     return; n   } n   if (type[now] == 1) { n     int pos = 0; n     long long minV = 1e18; n     for (auto &k : son[now]) n       if (f[k] < minV) minV = f[k], pos = k; n     for (auto &k : son[now]) resolve(k, pos == k ? r : 0); n     return; n   } n   for (auto &k : son[now]) resolve(k, r); n   return; n } n int main() { n   read(t); n   while (t--) { n     read(r), tot = 0; n     int root = solve(0); n     printf( REVOLTING  ); n     resolve(root, r * f[root]); n     printf(  n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct node { n   int a, b; n   bool operator<(const node& r) const { return r.b < b; } n } e[105]; n int dp[10005][105]; n int main() { n   int n, sum = 0, num = 0, sum2 = 0; n   scanf( %d , &n); n   for (int i = 0; i < n; i++) { n     scanf( %d , &e[i].a); n     sum += e[i].a; n   } n   for (int i = 0; i < n; i++) { n     scanf( %d , &e[i].b); n     sum2 += e[i].b; n   } n   sort(e, e + n); n   for (int i = 0; i < n; i++) { n     num += e[i].b; n     if (num >= sum) { n       num = i + 1; n       break; n     } n   } n   for (int i = sum2; i >= 0; i--) { n     for (int k = num; k >= 0; k--) { n       dp[i][k] = -234723846; n     } n   } n   dp[0][0] = 0; n   for (int i = 0; i < n; i++) { n     for (int k = sum2; k >= e[i].b; k--) { n       for (int j = num; j >= 1; j--) { n         dp[k][j] = max(dp[k][j], dp[k - e[i].b][j - 1] + e[i].a); n       } n     } n   } n   int ans = 0; n   for (int i = sum; i <= sum2; i++) { n     ans = max(ans, dp[i][num]); n   } n   printf( %d %d n , num, sum - ans); n } n