#include <bits/stdc++.h> n using namespace std; n const int maxn = 3e5 + 10; n struct edge { n   long long to; n   long long cost; n }; n vector<edge> mp[maxn]; n long long dis[maxn]; n long long vis[maxn]; n long long dis1[maxn]; n long long a[maxn]; n long long b[maxn]; n long long N, M, k; n long long cot[maxn]; n bool SPFA(long long s, long long N) { n   memset(vis, 0, sizeof(vis)); n   memset(cot, 0, sizeof(cot)); n   for (int i = 0; i <= N; i++) { n     dis[i] = 1000000000000000000; n     ; n   } n   priority_queue<long long> q; n   dis[s] = 0; n   q.push(s); n   while (!q.empty()) { n     int u = q.top(); n     q.pop(); n     vis[u] = 0; n     for (int v = 0; v < mp[u].size(); v++) { n       int to = mp[u][v].to; n       if (dis[u] + mp[u][v].cost < dis[to]) { n         dis[to] = dis[u] + mp[u][v].cost; n         if (!vis[to]) { n           vis[to] = 1; n           q.push(to); n         } n       } else if (dis[to] == dis[u] + mp[u][v].cost) { n         cot[to]++; n       } n     } n   } n   return true; n } n int main() { n   long long u, v, cost; n   scanf( %lld %lld %lld , &N, &M, &k); n   memset(mp, 0, sizeof(mp)); n   for (int i = 0; i < M; i++) { n     scanf( %lld%lld%lld , &u, &v, &cost); n     edge te; n     te.to = v; n     te.cost = cost; n     mp[u].push_back(te); n     te.to = u; n     te.cost = cost; n     mp[v].push_back(te); n   } n   long long sum = 0; n   for (int i = 0; i < k; i++) { n     scanf( %lld %lld , &a[i], &b[i]); n     edge te; n     te.to = a[i]; n     te.cost = b[i]; n     mp[1].push_back(te); n     te.to = 1; n     te.cost = b[i]; n     mp[a[i]].push_back(te); n   } n   SPFA(1, N); n   for (int i = 0; i < k; i++) { n     if (dis[a[i]] < b[i]) { n       sum++; n     } else if ((dis[a[i]] == b[i])) { n       if (cot[a[i]] >= 1) { n         sum++; n         cot[a[i]]--; n       } n     } n   } n   printf( %lld n , sum); n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = INT_MAX; n const long long LINF = LLONG_MAX; n int main() { n   std::ios_base::sync_with_stdio(false); n   int n, m; n   cin >> n >> m; n   vector<int> a(n, 0); n   int ind = 0, length = n + 1; n   for (int i = 0; i < m; i++) { n     int l, r; n     cin >> l >> r; n     if (length > r - l + 1) { n       length = r - l + 1; n       ind = l - 1; n     } n   } n   for (int i = ind, j = 0; i < n; i++, j++) { n     a[i] = j % length; n   } n   for (int i = ind - 1, j = length - 1; i >= 0; n        i--, j = (j - 1 + length) % length) n     a[i] = j; n   cout << length << endl; n   for (auto k : a) cout << k <<    ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, z = 0; n   cin >> n; n   char *colours = new char[50]; n   for (int x = 0; x < n; x++) { n     cin >> colours[x]; n   } n   for (int i = 0; i < n - 1; i++) { n     if (colours[i] == colours[i + 1]) { n       z++; n     } n   } n   delete[] colours; n   cout << z; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1000100; n const int INF = (1 << 29); n const double EPS = 0.000000001; n const double Pi = acos(-1.0); n int n; n long long x[maxn]; n int main() { n   while (cin >> n) { n     for (int i = 1; i <= n; i++) scanf( %I64d , &x[i]); n     sort(x + 1, x + n + 1); n     long long ans = 1e12; n     for (int i = 1; i + n / 2 <= n; i++) { n       long long a = x[i], b = x[i + n / 2]; n       ans = min(ans, b - a); n     } n     cout << ans << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double eps = 0.000000000000001; n int n, k; n double P[21]; n bool eq(long double a, long double b) { n   if (abs(a - b) < 0.000000000000001) return true; n   return false; n } n bool memo[1 << 21]; n long double dp[1 << 21]; n long double doit(int msk) { n   if (msk == 0) return 1; n   if (memo[msk] == true) { n     return dp[msk]; n   } n   int i, j; n   long double ret = 0, sm = 0; n   for (i = 0; i < n; i++) { n     if (msk & (1 << i)) { n       sm += P[i]; n     } n   } n   for (i = 0; i < n; i++) { n     if (msk & (1 << i)) { n       ret += P[i] * doit(msk ^ ((1 << i))) / (1 - (sm - P[i])); n     } n   } n   memo[msk] = true; n   return dp[msk] = ret; n } n long double ans[21]; n int main() { n   scanf( %d%d , &n, &k); n   int i, j, nz = 0; n   for (i = 0; i < n; i++) { n     scanf( %lf , &P[i]); n     if (!eq(P[i], 0)) nz++; n     ans[i] = 0; n   } n   for (i = 0; i < (1 << n); i++) { n     if (__builtin_popcount(i) == min(k, nz)) { n       int f = 1; n       for (j = 0; j < n; j++) { n         if (i & (1 << j)) n           if (eq(0, P[j])) { n             f = 0; n             break; n           } n       } n       if (!f) continue; n       long double x = doit(i); n       for (j = 0; j < n; j++) { n         if (i & (1 << j)) { n           ans[j] += x; n         } n       } n     } n   } n   for (i = 0; i < n; i++) { n     printf( %.15lf  , (double)ans[i]); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T, typename U> n inline void smin(T &a, const U &b) { n   if (a > b) a = b; n } n template <typename T, typename U> n inline void smax(T &a, const U &b) { n   if (a < b) a = b; n } n template <class T> n inline void gn(T &first) { n   char c, sg = 0; n   while (c = getchar(), (c >  9  || c <  0 ) && c !=  - ) n     ; n   for ((c ==  -  ? sg = 1, c = getchar() : 0), first = 0; c >=  0  && c <=  9 ; n        c = getchar()) n     first = (first << 1) + (first << 3) + c -  0 ; n   if (sg) first = -first; n } n template <class T1, class T2> n inline void gn(T1 &x1, T2 &x2) { n   gn(x1), gn(x2); n } n template <class T1, class T2, class T3> n inline void gn(T1 &x1, T2 &x2, T3 &x3) { n   gn(x1, x2), gn(x3); n } n template <class T> n inline void print(T first) { n   if (first < 0) { n     putchar( - ); n     return print(-first); n   } n   if (first < 10) { n     putchar( 0  + first); n     return; n   } n   print(first / 10); n   putchar(first % 10 +  0 ); n } n template <class T> n inline void println(T first) { n   print(first); n   putchar(  n ); n } n template <class T> n inline void printsp(T first) { n   print(first); n   putchar(   ); n } n template <class T1, class T2> n inline void print(T1 x1, T2 x2) { n   printsp(x1), println(x2); n } n template <class T1, class T2, class T3> n inline void print(T1 x1, T2 x2, T3 x3) { n   printsp(x1), printsp(x2), println(x3); n } n int power(int a, int b, int m, int ans = 1) { n   for (; b; b >>= 1, a = (long long)a * a % m) n     if (b & 1) ans = (long long)ans * a % m; n   return ans; n } n pair<pair<int, int>, int> p[200010]; n int first[200010], t[200010], nn; n vector<int> pos[200010], B[200010]; n void update(int id, int u, int v) { n   for (; u < B[id].size(); u += u & -u) B[id][u] += v; n } n int calc(int id, int u, int ans = 0) { n   for (; u; u -= u & -u) ans += B[id][u]; n   return ans; n } n int main() { n   int n; n   gn(n); n   for (int i = 0; i < n; i++) { n     gn(p[i].first.first, p[i].first.second, p[i].second); n     first[i] = p[i].second; n     t[i] = p[i].first.second; n   } n   sort(t, t + n); n   sort(first, first + n); n   nn = unique(first, first + n) - first; n   for (int i = 0; i < n; i++) { n     p[i].first.second = upper_bound(t, t + n, p[i].first.second) - t; n     p[i].second = lower_bound(first, first + nn, p[i].second) - first; n     pos[p[i].second].push_back(p[i].first.second); n   } n   for (int i = 0; i < nn; i++) { n     sort(pos[i].begin(), pos[i].end()); n     B[i].resize(pos[i].size() + 1); n   } n   for (int i = 0; i < n; i++) { n     int a = p[i].first.first, u = p[i].second; n     int t = upper_bound(pos[u].begin(), pos[u].end(), p[i].first.second) - n             pos[u].begin(); n     if (a == 1) n       update(u, t, 1); n     else if (a == 2) n       update(u, t, -1); n     else n       println(calc(u, t)); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(false); n   cout.precision(10); n   int n; n   cin >> n; n   set<string> st; n   while (n--) { n     string s, ss; n     cin >> s; n     for (int i = s.size() - 1; i >= 0; i--) { n       if (s[i] ==  u ) { n         ss +=  oo ; n       } else if (s[i] ==  h ) { n         ss +=  h ; n         while (i > 0 && s[i - 1] ==  k ) { n           i--; n         } n       } else { n         ss += s[i]; n       } n     } n     reverse(ss.begin(), ss.end()); n     st.insert(ss); n   } n   cout << st.size() <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long cnt, ans, i, j, temp, flag; n string s, heavy =  heavy , metal =  metal ; n int main() { n   cin >> s; n   for (i = 0; i < s.length(); i++) { n     temp = i; n     flag = 0; n     for (j = 0; j < 5; j++) { n       if (s[temp] == heavy[j]) n         ++temp; n       else n         break; n     } n     if (j == 5) flag = 1, ++cnt; n     if (flag) { n       i = temp - 2; n       continue; n     } n     temp = i; n     for (j = 0; j < 5; j++) { n       if (s[temp] == metal[j]) n         ++temp; n       else n         break; n     } n     if (j == 5) flag = 1, ans += cnt; n     if (flag) { n       i = temp - 2; n       continue; n     } n   } n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n map<long long int, map<long long int, bool> > my; n int main() { n   long long int n; n   cin >> n; n   my[1][n] = 1; n   if (n % 2 == 0) { n     cout <<  white  << endl; n     cout << 1 <<     << 2 << endl; n   } else n     cout <<  black  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long INF = 1e9 + 7; n const int N = 5e2 + 10; n int a[N][N]; n int b[N][N]; n int c[N][N]; n int minv[N]; n int main() { n   int n, m, k; n   scanf( %d%d%d , &n, &m, &k); n   memset((minv), (0x3f), sizeof(minv)); n   for (int i = 1; i <= n; i++) { n     scanf( %*s ); n     for (int j = 1; j <= m; j++) { n       cin >> a[i][j] >> b[i][j] >> c[i][j]; n     } n   } n   int ans = 0; n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= n; j++) { n       vector<int> v; n       for (int o = 1; o <= m; o++) { n         for (int t = 0; t < c[i][o]; t++) n           v.push_back(max(0, b[j][o] - a[i][o])); n       } n       sort(v.rbegin(), v.rend()); n       int sum = 0; n       for (int o = 0; o < k && o < v.size(); o++) sum += v[o]; n       ans = max(ans, sum); n     } n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n const int INF = 1e9 + 1; n const int MOD = 1e9 + 7; n using namespace std; n void solve() { n   int n; n   cin >> n; n   vector<int> a(n); n   for (int i = 0; i < n; i += 1) cin >> a[i]; n   ; n   sort(a.begin(), a.end()); n   vector<int> ans; n   for (int i = 0; i < n; i += 1) { n     for (int j = 0; j < 31; j += 1) { n       int pv = a[i] - (1 << j); n       int nx = a[i] + (1 << j); n       bool pv_find = binary_search(a.begin(), a.end(), pv); n       bool nx_find = binary_search(a.begin(), a.end(), nx); n       if (pv_find && nx_find) { n         ans = {pv, a[i], nx}; n         break; n       } else if (pv_find) n         ans = {pv, a[i]}; n       else if (nx_find) n         ans = {a[i], nx}; n     } n     if ((int)ans.size() == 3) break; n   } n   if (ans.empty()) ans.push_back(a[0]); n   cout << (int)ans.size() <<   n ; n   for (int i = 0; i < (int)ans.size(); i += 1) cout << ans[i] <<    ; n   ; n   cout <<   n ; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int graph[101][101]; n int dp[101][101][26]; n int dfs(int x, int y, int curr, int n) { n   if (dp[x][y][curr] != -1) { n     return dp[x][y][curr]; n   } n   for (int i = 0; i < n; i++) { n     if (graph[x][i] >= curr) { n       if (!dfs(y, i, graph[x][i], n)) { n         dp[x][y][curr] = 1; n         return 1; n       } n     } n   } n   dp[x][y][curr] = 0; n   return 0; n } n int main(void) { n   memset(dp, -1, sizeof(dp)); n   int n, m; n   cin >> n >> m; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < n; j++) { n       graph[i][j] = -1; n     } n   } n   for (int i = 0; i < m; i++) { n     int a, b; n     char c; n     cin >> a >> b >> c; n     a--; n     b--; n     graph[a][b] = c -  a ; n   } n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < n; j++) { n       if (dfs(i, j, 0, n)) { n         cout <<  A ; n       } else { n         cout <<  B ; n       } n     } n     cout <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, i, f[1001], l[1001]; n   bool rated = false; n   cin >> n; n   for (i = 0; i < n; i++) { n     cin >> f[i] >> l[i]; n     if (f[i] != l[i]) { n       rated = true; n       cout <<  rated  << endl; n       return 0; n     } n   } n   if (!rated) { n     for (i = 1; i < n; i++) { n       if (l[i] > l[i - 1]) { n         cout <<  unrated  << endl; n         return 0; n       } n     } n   } n   cout <<  maybe  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 800005; n int n, m, q, sa[N], sb[N], s[N]; n set<int> a[N], b[N]; n void modify(int x, int l, int r, int k, int val, int id) { n   if (l == r) { n     if (id) n       sa[x] = val; n     else n       sb[x] = val; n     s[x] = (sa[x] <= -sb[x]); n     return; n   } n   int mid = (l + r) >> 1; n   if (k <= mid) n     modify(x << 1, l, mid, k, val, id); n   else n     modify(x << 1 | 1, mid + 1, r, k, val, id); n   sa[x] = min(sa[x << 1], sa[x << 1 | 1]); n   sb[x] = min(sb[x << 1], sb[x << 1 | 1]); n   s[x] = s[x << 1] || s[x << 1 | 1] || sa[x << 1] <= -sb[x << 1 | 1]; n } n int main() { n   scanf( %d%d%d , &n, &m, &q); n   for (int i = 1; i <= n; i++) a[i].insert(0x3f3f3f3f), b[i].insert(0); n   memset(sa, 0x3f, sizeof(sa)); n   while (q--) { n     int x, y, id; n     scanf( %d%d , &x, &y); n     id = x & 1, x = (x + 1) / 2, y = (y + 1) / 2; n     if (id) { n       if (a[x].find(y) != a[x].end()) n         a[x].erase(y); n       else n         a[x].insert(y); n       modify(1, 1, n, x, *a[x].begin(), 1); n       if (s[1]) n         printf( NO n ); n       else n         printf( YES n ); n     } else { n       if (b[x].find(-y) != b[x].end()) n         b[x].erase(-y); n       else n         b[x].insert(-y); n       modify(1, 1, n, x, *b[x].begin(), 0); n       if (s[1]) n         printf( NO n ); n       else n         printf( YES n ); n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int soch(int a) { n   if (a == 3) return 1; n   return soch(a - 1) * a / (a - 3); n } n int main() { n   int n, num, i, j, k, raz, dob, num1, dob1, sum = 0, flag = 0, flag1 = 0; n   bool graf[105][105]; n   bool graf1[6][6]; n   vector<pair<int, int>> ver; n   vector<int> v; n   vector<int> v1; n   vector<int> v2; n   cin >> k; n   for (i = 1; i <= 100; i++) n     for (j = 1; j <= 100; j++) graf[i][j] = 0; n   for (i = 3; i <= 100; i++) { n     v2.push_back(soch(i)); n     if (soch(i) > k) break; n   } n   num = i - 1; n   raz = k - soch(num); n   v.push_back(0); n   v.push_back(1); n   for (i = 3; i <= num; i++) v.push_back(soch(i + 1) - soch(i)); n   for (i = 0; i < v.size(); i++) n     if (v[i] > raz) { n       dob = i - 1; n       break; n     }; n   raz -= v[dob]; n   dob++; n   k = raz; n   if (k) { n     flag1 = 1; n     for (i = 3; i <= 100; i++) n       if (soch(i) > k) break; n     num1 = i - 1; n     raz = k - soch(num1); n     for (i = 0; i < v.size(); i++) n       if (v[i] > raz) { n         dob1 = i - 1; n         break; n       }; n     raz -= v[dob1]; n     dob1++; n     k = raz; n   } n   if (k == 3) { n     flag = 1; n     v1.push_back(5); n     for (i = 1; i <= 5; i++) n       for (j = 1; j <= 5; j++) n         if (i != j) n           graf1[i][j] = 1; n         else n           graf1[i][j] = 0; n     graf1[1][3] = graf1[3][1] = graf1[1][4] = graf1[4][1] = graf1[4][3] = n         graf1[3][4] = 0; n   } n   if (!flag) n     for (i = v2.size() - 1; k > 0; i--) n       while (v2[i] <= k) { n         k -= v2[i]; n         v1.push_back(i + 3); n       } n   for (i = 0; i < v1.size(); i++) sum += v1[i]; n   if (!flag1) num1 = dob1 = 0; n   n = num + num1 + sum + 1 + flag1; n   cout << n << endl; n   for (i = 1; i <= num; i++) n     for (j = 1; j <= num; j++) n       if (i != j) graf[i][j] = 1; n   for (j = 1; j <= dob; j++) graf[num + 1][j] = graf[j][num + 1] = 1; n   if (flag1) { n     for (i = num + 2; i <= num + num1 + 1; i++) n       for (j = num + 2; j <= num + num1 + 1; j++) n         if (i != j) graf[i][j] = 1; n     for (j = num + 2; j <= dob1 + num + 1; j++) n       graf[num + num1 + 2][j] = graf[j][num + num1 + 2] = 1; n     num = num + num1 + 1; n   } n   if (!flag) { n     raz = 2; n     for (k = 0; k < v1.size(); k++) { n       for (i = num + raz; i <= num + raz + v1[k] - 1; i++) n         for (j = num + raz; j <= num + raz + v1[k] - 1; j++) n           if (i != j) graf[i][j] = 1; n       raz += v1[k]; n     } n   } else { n     for (i = 0; i < 5; i++) n       for (j = 0; j < 5; j++) n         graf[num + 2 + i][num + 2 + j] = graf1[i + 1][j + 1]; n   } n   for (i = 1; i <= n; i++) { n     for (j = 1; j <= n; j++) cout << graf[i][j]; n     cout << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n const int INF = 2147483647; n const int MOD = 1000000007; n const long long INF64 = 9223372036854775807; n const long double EPS = 1e-7; n using namespace std; n vector<int> a; n int getDist(int fr, int to) { n   int l = fr, r = to, mid = (a[to] + a[fr]) / 2; n   while (l < r - 1) { n     int m = (l + r) / 2; n     if (a[m] < mid) n       l = m; n     else n       r = m; n   } n   int l1 = fr, r1 = to, mid1 = (a[to] + a[fr]) / 2 + (a[to] + a[fr]) % 2; n   while (l1 < r1 - 1) { n     int m = (l1 + r1) / 2; n     if (a[m] < mid1) n       l1 = m; n     else n       r1 = m; n   } n   return min( n       min(max(a[l] - a[fr], a[to] - a[l]), max(a[r] - a[fr], a[to] - a[r])), n       min(max(a[l1] - a[fr], a[to] - a[l1]), n           max(a[r1] - a[fr], a[to] - a[r1]))); n } n int main() { n   int n, k; n   char t; n   scanf( %d%d n , &n, &k); n   for (int i = 0; i < n; i++) { n     scanf( %c , &t); n     if (t ==  0 ) a.push_back(i); n   } n   int ans = INF; n   for (int i = 0; i < (int)a.size() - k; i++) ans = min(ans, getDist(i, i + k)); n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long base = 17LL; n const long long MOD = 998244353LL; n const int MAXN = 1e5 + 10; n struct Node { n   long long v; n   long long tagv; n   long long len; n } st[MAXN << 2]; n long long a[MAXN]; n inline long long fp(long long x, long long y) { n   long long ret = 1LL; n   while (y) { n     if (y & 1) ret = ret * x % MOD; n     x = x * x % MOD; n     y >>= 1; n   } n   return ret; n } n long long inv = fp(base - 1, MOD - 2); n long long basep[MAXN]; n Node operator+(const Node& a, const Node& b) { n   Node ret; n   ret.len = a.len + b.len; n   ret.tagv = -1; n   ret.v = (a.v * basep[b.len] % MOD + b.v) % MOD; n   return ret; n } n void init() { n   basep[0] = 1LL; n   for (int i = 1; i < MAXN; i++) basep[i] = basep[i - 1] * base % MOD; n } n void setv(int o, long long v) { n   st[o].v = (basep[st[o].len] - 1 + MOD) % MOD * v % MOD * inv % MOD; n   st[o].tagv = v; n } n void pushup(int o) { st[o] = st[o << 1] + st[o << 1 | 1]; } n void pushdown(int o) { n   if (st[o].tagv != -1) { n     setv(o << 1, st[o].tagv); n     setv(o << 1 | 1, st[o].tagv); n     st[o].tagv = -1; n   } n } n void build(int o, int l, int r) { n   st[o].tagv = -1; n   st[o].len = r - l + 1; n   if (l == r) { n     setv(o, a[l]); n     return; n   } n   int m = l + r >> 1; n   build(o << 1, l, m); n   build(o << 1 | 1, m + 1, r); n   pushup(o); n } n void update(int o, int l, int r, int L, int R, long long v) { n   if (L <= l && r <= R) { n     setv(o, v); n     return; n   } n   pushdown(o); n   int m = l + r >> 1; n   if (L <= m) update(o << 1, l, m, L, R, v); n   if (m < R) update(o << 1 | 1, m + 1, r, L, R, v); n   pushup(o); n } n Node query(int o, int l, int r, int L, int R) { n   if (L <= l && r <= R) return st[o]; n   pushdown(o); n   int m = l + r >> 1; n   if (R <= m) return query(o << 1, l, m, L, R); n   if (m < L) return query(o << 1 | 1, m + 1, r, L, R); n   return query(o << 1, l, m, L, R) + query(o << 1 | 1, m + 1, r, L, R); n } n char s[MAXN]; n int main() { n   init(); n   int n, m, k; n   int x, l, r, y; n   scanf( %d%d%d , &n, &m, &k); n   scanf( %s , s); n   for (int i = 1; i <= n; i++) a[i] = s[i - 1] -  0 ; n   build(1, 1, n); n   for (int i = 1; i <= m + k; i++) { n     scanf( %d%d%d%d , &x, &l, &r, &y); n     if (x == 1) { n       update(1, 1, n, l, r, 1LL * (y)); n     } else { n       if (y == (r - l + 1)) { n         puts( YES ); n         continue; n       } n       if (query(1, 1, n, l + y, r).v == query(1, 1, n, l, r - y).v) n         puts( YES ); n       else n         puts( NO ); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool deb = false; n int i; n const int N = 100011; n int g[N]; n int ans1[N], ans2[N]; n int main() { n   int i, j, n, k; n   scanf( %d , &n), scanf( %d , &k); n   int a, b, c, d; n   scanf( %d , &a), scanf( %d , &b), scanf( %d , &c), scanf( %d , &d); n   if (k < n + 1 || n == 4) { n     printf( %d n , -1); n     return 0; n   } n   g[1] = a; n   g[2] = c; n   g[n] = b, g[n - 1] = d; n   j = 3; n   for (i = 1; i < n + 1; ++i) { n     if (i == a || i == b || i == c || i == d) continue; n     if (g[j] == 0) g[j] = i, j++; n   } n   for (i = 1; i < n + 1; ++i) printf( %d  , g[i]); n   printf(  n ); n   printf( %d  , g[2]), printf( %d  , g[1]); n   for (i = 3; i < n - 1; ++i) { n     printf( %d  , g[i]); n   } n   printf( %d  , g[n]), printf( %d n , g[n - 1]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n string s; n long cmpduong(string s1, string s2) { n   long len1 = s1.size(); n   long len2 = s2.size(); n   if (len1 < len2) return 2; n   if (len1 == len2) { n     if (s1 > s2) n       return 1; n     else n       return 2; n   } n   if (len1 > len2) return 1; n } n long cmp_am(string s1, string s2) { n   long len1 = s1.size(); n   long len2 = s2.size(); n   if (len1 < len2) return 1; n   if (len1 == len2) { n     if (s1 >= s2) n       return 2; n     else n       return 1; n   } n   if (len1 > len2) return 2; n } n long check(string s) { n   string tam =  -  + s; n   if (s[0] ==  - ) { n     if (cmp_am(s,  -128 ) == 1) return 1; n     if (cmp_am(s,  -32768 ) == 1) return 2; n     if (cmp_am(s,  -2147483648 ) == 1) return 3; n     if (cmp_am(s,  -9223372036854775808 ) == 1) return 4; n     return 5; n   } else { n     if (cmpduong(s,  127 ) == 2) return 1; n     if (cmpduong(s,  32767 ) == 2) return 2; n     if (cmpduong(s,  2147483647 ) == 2) return 3; n     if (cmpduong(s,  9223372036854775807 ) == 2) return 4; n     return 5; n   } n } n int main() { n   cin >> s; n   if (check(s) == 1) cout <<  byte  << endl; n   if (check(s) == 2) cout <<  short  << endl; n   if (check(s) == 3) cout <<  int  << endl; n   if (check(s) == 4) cout <<  long  << endl; n   if (check(s) == 5) cout <<  BigInteger  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long sum[400006] = {0}; n long long Min[400006] = {0}; n long long Max[400006] = {0}; n void solve() { n   long long n; n   cin >> n; n   long long k; n   cin >> k; n   vector<long long> v(n); n   for (long long i = 0; i < n; i++) cin >> v[i]; n   for (long long i = 0; i <= 2 * k + 3; i++) Min[i] = Max[i] = sum[i] = 0; n   for (long long i = 0; i < n / 2; i++) { n     Max[max(v[i], v[n - i - 1])]++; n     Min[min(v[i], v[n - i - 1])]++; n     sum[v[i] + v[n - i - 1]]++; n   } n   for (long long i = 1; i <= k; i++) { n     Min[i] += Min[i - 1]; n     Max[i] += Max[i - 1]; n   } n   long long ans = 2000000000000000005; n   long long c; n   for (long long i = 2; i <= k + 1; i++) { n     c = Min[i - 1]; n     if (c <= n / 2) ans = min(ans, c + 2 * ((n / 2) - c) - sum[i]); n   } n   for (long long i = k + 1; i <= 2 * k; i++) { n     if (i - k - 1 >= 0) c = Max[i - k - 1]; n     if (c <= n / 2) ans = min(ans, c * 2 + (n / 2 - c) - sum[i]); n   } n   cout << ans <<   n ; n } n signed main() { n   ios_base ::sync_with_stdio(0); n   cin.tie(NULL); n   cout.tie(NULL); n   long long t; n   cin >> t; n   while (t--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int N, M; n int ans[100010]; n int a[100010], b[100010]; n int c[100010], d[100010], cnt[100010]; n set<pair<int, int> > s; n int x[100010 * 4], nx; n vector<int> A[100010 * 4], B[100010 * 4]; n bool solve() { n   for (int i = 0; i < N; i++) { n     x[nx++] = a[i]; n     x[nx++] = b[i]; n   } n   for (int i = 0; i < M; i++) { n     x[nx++] = c[i]; n     x[nx++] = d[i]; n   } n   sort(x, x + nx); n   nx = unique(x, x + nx) - x; n   for (int i = 0; i < M; i++) { n     c[i] = lower_bound(x, x + nx, c[i]) - x; n     d[i] = lower_bound(x, x + nx, d[i]) - x; n     A[c[i]].push_back(-(i + 1)); n     B[d[i]].push_back(-(i + 1)); n   } n   for (int i = 0; i < N; i++) { n     a[i] = lower_bound(x, x + nx, a[i]) - x; n     b[i] = lower_bound(x, x + nx, b[i]) - x; n     A[a[i]].push_back(i + 1); n   } n   memset(ans, -1, sizeof(ans)); n   for (int i = 0; i < nx; i++) { n     int n; n     n = A[i].size(); n     for (int j = 0; j < n; j++) { n       if (A[i][j] > 0) { n         int k = A[i][j] - 1; n         set<pair<int, int> >::iterator it = n             s.lower_bound(pair<int, int>(b[k], -1)); n         if (it == s.end()) return false; n         int u = it->second; n         ans[k] = u + 1; n         cnt[u]--; n         if (!cnt[u]) s.erase(it); n       } else { n         int k = -A[i][j] - 1; n         s.insert(pair<int, int>(d[k], k)); n       } n     } n     n = B[i].size(); n     for (int j = 0; j < n; j++) { n       int k = -B[i][j] - 1; n       s.erase(pair<int, int>(d[k], k)); n     } n   } n   return true; n } n int main() { n   scanf( %d , &N); n   for (int i = 0; i < N; i++) scanf( %d%d , &a[i], &b[i]); n   scanf( %d , &M); n   for (int i = 0; i < M; i++) scanf( %d%d%d , &c[i], &d[i], &cnt[i]); n   if (solve()) { n     puts( YES ); n     for (int i = 0; i < N; i++) printf( %d  , ans[i]); n     puts(  ); n   } else n     puts( NO ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long n, i, n1 = 0, n2 = 0, ar = 0, curr = 0, current; n   cin >> n; n   vector<int> a(n); n   for (i = 0; i < n; i++) cin >> a[i]; n   current = a[0]; n   for (i = 0; i < n; i++) { n     if (curr == 0 && a[i] == current) n       n1++; n     else if (a[i] != current) n       curr++, n2++; n     if ((curr > 0 && a[i] == current) || i == n - 1) { n       current = a[i - 1]; n       if (n1 == n2) n         ar = max(n1 + n2, ar); n       else n         ar = max((2 * min(n1, n2)), ar); n       n1 = n2, n2 = 1; n     } n   } n   cout << ar << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, a, b; n   cin >> n >> a >> b; n   vector<int> d(n); n   for (int(i) = 0; (i) < (n); (i)++) { n     cin >> d[i]; n   } n   sort((d).begin(), (d).end()); n   if (d[b] != d[b - 1]) { n     cout << d[b] - d[b - 1] << endl; n   } else { n     cout << 0 << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 205000; n const int SQRTN = 320; n const int LOGN = 20; n const long double PI = acos(-1); n vector<string> w, a, b; n string s1, s2; n bool check(string& s) { n   if (s.size() == 0) return 0; n   if (s[0] ==  0 ) return s.size() == 1; n   for (int i = 0; i < s.size(); i++) { n     if (s[i] >  9  || s[i] <  0 ) return 0; n   } n   return 1; n } n signed main() { n   cin >> s1; n   for (int i = 0; i < s1.size(); i++) { n     if (s1[i] ==  ,  || s1[i] ==  ; ) { n       w.push_back(s2); n       s2 =   ; n     } else { n       s2 += s1[i]; n     } n     if (i == s1.size() - 1) w.push_back(s2); n   } n   for (int i = 0; i < w.size(); i++) { n     if (check(w[i])) { n       a.push_back(w[i]); n     } else n       b.push_back(w[i]); n   } n   if (a.size() == 0) { n     cout <<  -  << endl; n   } else { n     cout <<    ; n     for (int i = 0; i < a.size(); i++) { n       cout << a[i]; n       if (i != a.size() - 1) cout <<  , ; n     } n     cout <<    n ; n   } n   if (b.size() == 0) { n     cout <<  -  << endl; n   } else { n     cout <<    ; n     for (int i = 0; i < b.size(); i++) { n       cout << b[i]; n       if (i != b.size() - 1) cout <<  , ; n     } n     cout <<    n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 4e5 + 5; n int n, I; n int a[MAXN], num[MAXN]; n int read() { n   int s = 1, x = 0; n   char ch = getchar(); n   while (!isdigit(ch)) { n     if (ch ==  - ) s = -1; n     ch = getchar(); n   } n   while (isdigit(ch)) { n     x = 10 * x + ch -  0 ; n     ch = getchar(); n   } n   return x * s; n } n int main() { n   n = read(), I = read(); n   int maxk = 8 * I / n, maxK = pow(2, maxk); n   if (maxk >= 20) { n     cout <<  0 n ; n     return 0; n   } n   for (int i = 1; i <= n; ++i) a[i] = read(); n   sort(a + 1, a + n + 1); n   int cnt = 1; n   num[cnt] = 1; n   for (int i = 2; i <= n; ++i) { n     if (a[i] == a[i - 1]) n       num[cnt]++; n     else n       num[++cnt] = num[cnt - 1] + 1; n   } n   if (cnt <= maxK) { n     cout <<  0 n ; n     return 0; n   } n   int max_con = -1; n   for (int i = maxK; i <= cnt; ++i) { n     int tmp = num[i] - num[i - maxK]; n     max_con = max(max_con, tmp); n   } n   cout << n - max_con << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long n, a, b, x, y, x1, y1; n   cin >> n >> a >> b; n   if (max(n - a, n - b) < max(a - 1, b - 1)) n     cout <<  black n ; n   else n     cout <<  white n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 100005; n int a[MAXN], deg[MAXN]; n set<pair<int, int> > s; n int main() { n   int n, sum = 0; n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> deg[i] >> a[i]; n     if (deg[i]) s.insert(make_pair(deg[i], i)); n     sum += deg[i]; n   } n   cout << sum / 2 << endl; n   while (s.size()) { n     pair<int, int> x = *s.begin(); n     s.erase(x); n     int t = a[x.second]; n     cout << x.second <<     << t << endl; n     s.erase(make_pair(deg[t], t)); n     deg[t]--; n     a[t] ^= x.second; n     if (deg[t]) s.insert(make_pair(deg[t], t)); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int cnt[6], ans[100001]; n pair<int, int> arr[100001]; n bool given[100001]; n string tshirt[6] = { S ,  M ,  L ,  XL ,  XXL ,  XXXL }; n int match(string s) { n   for (int i = 0; i < 6; i++) { n     if (tshirt[i] == s) return i; n   } n } n void convert(int ind, string s) { n   string tmp; n   bool flag = 0; n   for (int i = 0; i < s.size(); i++) { n     if (s[i] ==  , ) { n       flag = 1; n       arr[ind].first = match(tmp); n       tmp.clear(); n     } else n       tmp.push_back(s[i]); n   } n   if (flag) { n     arr[ind].second = match(tmp); n     if (arr[ind].first > arr[ind].second) swap(arr[ind].first, arr[ind].second); n   } else { n     arr[ind].first = match(tmp); n     arr[ind].second = -1; n   } n   return; n } n bool cal_ans(int n) { n   for (int i = 0; i < n; i++) { n     if (arr[i].second == -1) { n       if (cnt[arr[i].first] == 0) return false; n       ans[i] = arr[i].first; n       cnt[arr[i].first]--; n       given[i] = 1; n     } n   } n   for (int j = 0; j < 5; j++) { n     for (int i = 0; i < n; i++) { n       if (given[i] == 0 and arr[i].first == j) { n         if (cnt[arr[i].first]) { n           cnt[arr[i].first]--; n           ans[i] = j; n         } else { n           if (cnt[arr[i].second]) { n             cnt[arr[i].second]--; n             ans[i] = arr[i].second; n           } else n             return false; n         } n         given[i] = 1; n       } n     } n   } n   return 1; n } n int main() { n   ios::sync_with_stdio(false); n   for (int i = 0; i < 6; i++) cin >> cnt[i]; n   int n; n   cin >> n; n   string s; n   for (int i = 0; i < n; i++) { n     cin >> s; n     convert(i, s); n   } n   if (cal_ans(n)) { n     cout <<  YES n ; n     for (int i = 0; i < n; i++) { n       cout << tshirt[ans[i]] << endl; n     } n   } else { n     cout <<  NO ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX_N = 100000; n const int D[4][2] = {{1, 1}, {1, -1}, {-1, 1}, {-1, -1}}; n set<pair<int, int> > s; n set<pair<pair<int, int>, int> > vis; n char dir[10]; n int sx, sy, h, w, d, tar; n inline void update(int& a, int b) { n   if (b < a) a = b; n } n int main() { n   scanf( %d%d%d%d%s , &h, &w, &sx, &sy, dir); n   tar = ((h + w) * 2 - 4) >> 1; n   if (dir[0] ==  U  && dir[1] ==  L ) n     d = 3; n   else if (dir[0] ==  U  && dir[1] ==  R ) n     d = 2; n   else if (dir[0] ==  D  && dir[1] ==  L ) n     d = 1; n   else n     d = 0; n   --tar; n   s.insert(make_pair(sx, sy)); n   vis.insert(make_pair(make_pair(sx, sy), d)); n   long long ans = 1; n   pair<int, int> p1; n   pair<pair<int, int>, int> p2; n   while (tar > 0) { n     if ((D[d][0] == 1 && sx == h) || (D[d][0] == -1 && sx == 1)) d ^= 2; n     if ((D[d][1] == 1 && sy == w) || (D[d][1] == -1 && sy == 1)) d ^= 1; n     int g = 0x3f3f3f3f; n     if (D[d][0] == 1) n       update(g, h - sx); n     else n       update(g, sx - 1); n     if (D[d][1] == 1) n       update(g, w - sy); n     else n       update(g, sy - 1); n     ans += g; n     sx += D[d][0] * g; n     sy += D[d][1] * g; n     p1 = make_pair(sx, sy); n     if (s.find(p1) == s.end()) { n       --tar; n       s.insert(p1); n     } n     p2 = make_pair(p1, d); n     if (vis.find(p2) != vis.end()) { n       printf( -1 n ); n       return 0; n     } else n       vis.insert(p2); n   } n   printf( n        %I64d  n         n , n       ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int num[100009]; n int main() { n   int n; n   while (cin >> n) { n     for (int i = 0; i < n; ++i) cin >> num[i]; n     long long sum = n; n     long long count = 1; n     for (int i = 1; i < n; ++i) { n       if (num[i] == num[i - 1]) n         count++; n       else { n         sum += ((count - 1) * (count)) / 2; n         count = 1; n       } n     } n     if (count != 0) sum += ((count - 1) * (count)) / 2; n     cout << sum << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MX = 11; n int n, l; n int main() { n   scanf( %d , &n); n   while (n) { n     int a = n % 10; n     int b = n % 100; n     int c = n % 1000; n     if (a == 1) n       n /= 10; n     else if (b == 14) n       n /= 10; n     else if (c == 144) n       n /= 100; n     l++; n     if (l > 1000) { n       printf( NO n ); n       return 0; n     } n   } n   printf( YES n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n map<int, int> MP1, MP2; n map<int, int>::iterator it; n const int N = 300100; n const long long INF = 3000 * 1000 * 1000LL; n vector<int> v; n int a[N]; n long long ps[N]; n int main() { n   ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); n   int n, l, r; n   long long ans = -INF; n   cin >> n; n   for (int i = 1; i <= n; i++) { n     cin >> a[i]; n     if (!MP1.count(a[i])) MP1[a[i]] = i; n     MP2[a[i]] = i; n     ps[i] += ps[i - 1]; n     if (a[i] > 0) ps[i] += a[i]; n   } n   for (it = MP1.begin(); it != MP1.end(); it++) { n     if (MP2[it->first] != it->second) { n       long long t = ps[MP2[it->first]] - ps[it->second] + it->first; n       if (it->first < 0) t += it->first; n       if (t > ans) { n         ans = t; n         l = it->second; n         r = MP2[it->first]; n       } n     } n   } n   for (int i = 1; i <= n; i++) n     if ((i != l && i != r && a[i] < 0) || (i < l || i > r)) v.push_back(i); n   cout << ans <<     << v.size() << endl; n   for (int u : v) cout << u <<    ; n   cout << endl; n   return 0; n } n


#include <algorithm>   n #include <iostream>   n #include <sstream>   n #include <string>   n #include <vector>   n #include <queue>   n #include <set>   n #include <map>   n #include <cstdio>   n #include <cstdlib>   n #include <cctype>   n #include <cmath>   n #include <cstring> n #include <list>   n #include <cassert> n #include <climits> n #include <bitset> n #include <chrono> n #include <random> n using namespace std; n  n #define PB push_back   n #define MP make_pair   n #define SZ(v) ((int)(v).size())   n #define FOR(i,a,b) for(int i=(a);i<(b);++i)   n #define REP(i,n) FOR(i,0,n)   n #define FORE(i,a,b) for(int i=(a);i<=(b);++i)   n #define REPE(i,n) FORE(i,0,n)   n #define FORSZ(i,a,v) FOR(i,a,SZ(v))   n #define REPSZ(i,v) REP(i,SZ(v))   n std::mt19937 rnd((int)std::chrono::steady_clock::now().time_since_epoch().count()); n typedef long long ll; n ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); } n  n const int MAXN = 5000; n const int MAXC = 20; n  n int n, num, den; n char s[MAXN + 1]; n vector<char> ans; n  n int mp[26]; n char c[MAXC]; int nc; n int a[MAXN]; n  n int fst[MAXC], lst[MAXC], cnt[MAXC]; n  n bool ok[1 << MAXC]; n bool can[1 << MAXC]; n  n void solve() { n  nc = 0; REP(i, 26) mp[i] = -1; n  REP(i, n) { int x = s[i] -  a ; if (mp[x] == -1) c[nc] =  a  + x, mp[x] = nc, nc++; a[i] = mp[x]; } n  n  REP(i, nc) fst[i] = INT_MAX, lst[i] = INT_MIN, cnt[i] = 0; n  REP(i, n) fst[a[i]] = min(fst[a[i]], i), lst[a[i]] = max(lst[a[i]], i), ++cnt[a[i]]; n  n  //printf( c: ); REP(i, nc) printf(  %c , c[i]); puts(  ); n  FOR(mask, 1, 1 << nc) {  n   int maskfst = INT_MAX, masklst = INT_MIN, maskcnt = 0; n   REP(i, nc) if (mask&(1 << i)) maskfst = min(maskfst, fst[i]), masklst = max(masklst, lst[i]), maskcnt += cnt[i]; n   ok[mask] = num*(masklst - maskfst + 1) <= maskcnt*den; n   //printf( %s[%x] [%d..%d] cnt=%d n , ok[mask] ?  ok  :  fail , mask, maskfst, masklst, maskcnt); n  } n  can[0] = true; n  FOR(mask, 1, 1 << nc) { n   can[mask] = false; n   if (ok[mask]) REP(i, nc) if ((mask&(1 << i)) != 0 && can[mask ^ (1 << i)]) { n    can[mask] = true; n   } n   REP(i, nc) { n    int lmask = mask&((2 << i) - 1), rmask = mask^lmask; n    if (can[lmask] && can[rmask]) can[mask] = true; n   } n  } n  n  ans.clear(); n  REP(i, nc) if (can[(1 << nc) - 1 - (1 << i)]) ans.PB(c[i]); n  sort(ans.begin(), ans.end()); n } n  n void run() { n  scanf( %d%d%d , &n, &num, &den); n  scanf( %s , s); assert(strlen(s) == n); n  solve(); n  printf( %d , SZ(ans)); REPSZ(i, ans) printf(  %c , ans[i]); puts(  ); n } n  n int main() { n  //int ncase; scanf( %d , &ncase); FORE(i, 1, ncase) n  run(); n  return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s; n   int cnt = 0, cnt1 = 0; n   cin >> s; n   for (int i = 0; i < s.length(); i++) { n     if (s[i] ==  - ) n       cnt++; n     else n       cnt1++; n   } n   if (cnt1 == 0) { n     cout <<  YES ; n     return 0; n   } n   if (cnt % cnt1 == 0) n     cout <<  YES ; n   else n     cout <<  NO ; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 5; n int n, m, rt; n int p[20][N], sz[N]; n bool vis[N]; n int dep[N], yr[N]; n int cur = 1, pos[N], chainhd[N], chain[N], rpos[N]; n int L[100 * N], R[100 * N], t[100 * N], root[N], nxt = 1, num; n int query[N], a[N], b[N], k[N], y[N]; n vector<int> g[N]; n void build(int id, int x, int y) { n   if (x == y) { n     return; n   } n   L[id] = nxt++; n   R[id] = nxt++; n   int mid = (x + y) >> 1; n   build(L[id], x, mid); n   build(R[id], mid + 1, y); n } n int update(int id, int x, int y, int l) { n   if (l < x or l > y) return id; n   int ID = nxt++; n   if (x == y) { n     t[ID] = t[id] + 1; n     return ID; n   } n   int mid = (x + y) >> 1; n   L[ID] = update(L[id], x, mid, l); n   R[ID] = update(R[id], mid + 1, y, l); n   t[ID] = t[L[ID]] + t[R[ID]]; n   return ID; n } n void dfs(int x) { n   vis[x] = 1; n   sz[x] = 1; n   for (auto it : g[x]) { n     if (!vis[it]) { n       dep[it] = dep[x] + 1; n       dfs(it); n       sz[x] += sz[it]; n     } n   } n } n void per_dfs(int x) { n   vis[x] = 1; n   root[x] = update(root[p[0][x]], 1, m, yr[x]); n   for (auto it : g[x]) { n     if (!vis[it]) { n       per_dfs(it); n     } n   } n } n int lca(int u, int v) { n   if (dep[u] < dep[v]) swap(u, v); n   int diff = dep[u] - dep[v]; n   for (int i = 0; i < 18; i++) { n     if ((diff >> i) & 1) u = p[i][u]; n   } n   if (u == v) return u; n   for (int i = 17; i > -1; i--) { n     if (p[i][u] != p[i][v]) { n       u = p[i][u]; n       v = p[i][v]; n     } n   } n   return p[0][u]; n } n void HLD(int x) { n   if (chainhd[num] == 0) chainhd[num] = x; n   pos[x] = cur; n   rpos[cur] = x; n   cur++; n   chain[x] = num; n   int mx = 0, hv = -1; n   for (auto it : g[x]) { n     if (it != p[0][x]) { n       if (sz[it] >= mx) { n         mx = sz[it]; n         hv = it; n       } n     } n   } n   if (hv == -1) return; n   HLD(hv); n   for (auto it : g[x]) { n     if (it != hv and it != p[0][x]) { n       num++; n       HLD(it); n     } n   } n } n int per_query(int id, int x, int y, int l, int r) { n   if (l > y or r < x) return 0; n   if (l <= x and r >= y) return t[id]; n   int mid = (x + y) >> 1; n   int ans = per_query(L[id], x, mid, l, r) + per_query(R[id], mid + 1, y, l, r); n   return ans; n } n int search(int u, int l, int r, int k, int y, int i) { n   if (k == 1 and (yr[u] <= y or yr[u] >= i)) return u; n   while (l < r) { n     int mid = (l + r) >> 1; n     int node = rpos[mid]; n     int x = per_query(root[u], 1, m, y + 1, i) - n             per_query(root[node], 1, m, y + 1, i); n     x = dep[u] - dep[node] - x; n     if (yr[node] <= y or yr[node] >= i) x++; n     if (x >= k) { n       l = mid + 1; n     } else { n       r = mid; n     } n   } n   return rpos[l - 1]; n } n int query_hld(int u, int v, int k, int y, int i) { n   u = p[0][u]; n   int a = chain[u], b = chain[v]; n   while (a != b) { n     int hd = chainhd[a]; n     int x = per_query(root[u], 1, m, y + 1, i) - n             per_query(root[hd], 1, m, y + 1, i); n     if (yr[hd] >= y + 1 and yr[hd] < i) x++; n     x = dep[u] - dep[hd] + 1 - x; n     if (x >= k) { n       int l = pos[hd], r = pos[u]; n       return search(u, l, r, k, y, i); n     } else { n       k -= x; n       u = p[0][hd]; n       a = chain[u]; n     } n   } n   if (u == v) { n     return -1; n   } n   int l = pos[v] + 1, r = pos[u]; n   return search(u, l, r, k, y, i); n } n int count(int u, int v, int y, int i) { n   u = p[0][u]; n   if (dep[u] <= dep[v]) return 0; n   int ans = n       per_query(root[u], 1, m, y + 1, i) - per_query(root[v], 1, m, y + 1, i); n   ans = dep[u] - dep[v] - ans; n   return ans; n } n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) { n     scanf( %d , &p[0][i]); n     if (p[0][i] == 0) { n       rt = i; n       continue; n     } n     g[p[0][i]].push_back(i); n   } n   for (int i = 1; i < 18; i++) { n     for (int j = 1; j <= n; j++) { n       if (p[i - 1][j] > 0) p[i][j] = p[i - 1][p[i - 1][j]]; n     } n   } n   dep[rt] = 1; n   dfs(rt); n   HLD(rt); n   scanf( %d , &m); n   build(nxt++, 1, m); n   int ty; n   for (int i = 1; i <= m; i++) { n     scanf( %d , &ty); n     if (ty == 1) { n       scanf( %d , &ty); n       yr[ty] = i; n       query[i] = 0; n     } else { n       query[i] = 1; n       scanf( %d%d%d%d , a + i, b + i, k + i, y + i); n     } n   } n   memset(vis, 0, sizeof(vis)); n   root[0] = 1; n   pos[0] = 0; n   chain[0] = 0; n   per_dfs(rt); n   for (int i = 1; i <= m; i++) { n     if (query[i]) { n       int l = lca(a[i], b[i]); n       if (a[i] == l) { n         int x = count(b[i], l, y[i], i); n         int ans; n         if (x >= k[i]) { n           ans = query_hld(b[i], l, x - k[i] + 1, y[i], i); n         } else { n           ans = -1; n         } n         printf( %d n , ans); n       } else if (b[i] == l) { n         int x = count(a[i], l, y[i], i); n         int ans; n         if (x >= k[i]) { n           ans = query_hld(a[i], l, k[i], y[i], i); n         } else { n           ans = -1; n         } n         printf( %d n , ans); n       } else { n         int x = count(a[i], l, y[i], i); n         int ans; n         if (x >= k[i]) { n           ans = query_hld(a[i], l, k[i], y[i], i); n         } else { n           k[i] -= x; n           if (yr[l] <= y[i] or yr[l] >= i) k[i]--; n           if (k[i] == 0) n             ans = l; n           else { n             x = count(b[i], l, y[i], i); n             if (x >= k[i]) n               ans = query_hld(b[i], l, x - k[i] + 1, y[i], i); n             else n               ans = -1; n           } n         } n         printf( %d n , ans); n       } n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n inline void init() {} n string lines[1001]; n int main() { n   string s; n   int n = 0; n   int mx = 0; n   while (getline(cin, lines[n])) { n     mx = std::max<int>(mx, lines[n].length()); n     n++; n   } n   cout << string(mx + 2,  * ) << endl; n   int sw = 0; n   for (int i = 0; i < n; i++) { n     cout <<  * ; n     int len = lines[i].length(); n     if (len % 2 != mx % 2) { n       if (sw) { n         lines[i] =     + lines[i]; n       } else { n         lines[i] +=    ; n       } n       sw = !sw; n     } n     int d = mx - len; n     if (d) cout << string(d / 2,    ); n     cout << lines[i]; n     if (d) cout << string(d / 2,    ); n     cout <<  * n ; n   } n   cout << string(mx + 2,  * ) << endl; n   return 0; n } n


#include <bits/stdc++.h> n struct M { n   int p, b; n }; n struct F { n   const int p, i; n   int r; n   int c; n   F(int p, int t, int i) : p(p), i(i), r(p + t), c(0) {} n   int t() { return r - p; } n }; n void solve(std::vector<F> &fs, std::vector<M> &ms) { n   std::multimap<int, int> ms_landed; n   std::map<int, F *> fs_active; n   { n     std::vector<F *> fs_sort; n     fs_sort.reserve(fs.size()); n     for (int i = 0; i < fs.size(); i++) fs_sort.push_back(&fs[i]); n     std::sort(fs_sort.begin(), fs_sort.end(), n               [](const F *lhs, const F *rhs) { return lhs->p < rhs->p; }); n     fs_active.insert({fs_sort[0]->p, fs_sort[0]}); n     int curr = fs_sort[0]->r; n     for (int i = 1; i < fs_sort.size(); i++) { n       F &f = *fs_sort[i]; n       if (f.r > curr) { n         int l = std::max(curr + 1, f.p); n         curr = f.r; n         fs_active.insert({l, &f}); n       } n     } n   } n   auto update = [&](F &f, std::map<int, F *>::iterator &f_it, const int &b) { n     f.c++; n     f.r += b; n     while (f_it != fs_active.end()) { n       int l_succ = f_it->first; n       F &f_succ = *f_it->second; n       if (f.r < f_succ.r) { n         if (f.r >= l_succ) { n           f_it = fs_active.insert(fs_active.erase(f_it), {f.r + 1, &f_succ}); n         } n         break; n       } n       f_it = fs_active.erase(f_it); n     } n   }; n   for (const M &m : ms) { n     auto f_it = --fs_active.upper_bound(m.p); n     if (f_it == fs_active.end()) continue; n     int l = f_it->first; n     F &f = *f_it->second; n     if (l <= m.p && m.p <= f.r) { n       update(f, ++f_it, m.b); n       auto m_succ = ms_landed.lower_bound(l); n       while (m_succ != ms_landed.end()) { n         M m{m_succ->first, m_succ->second}; n         if (l <= m.p && m.p <= f.r) { n           update(f, f_it, m.b); n           m_succ = ms_landed.erase(m_succ); n         } else { n           break; n         } n       } n     } else { n       ms_landed.insert({m.p, m.b}); n     } n   } n   for (F &f : fs) { n     printf( %d %d n , f.c, f.t()); n   } n } n int main() { n   int n; n   int m; n   scanf( %d%d , &n, &m); n   std::vector<F> fs; n   fs.reserve(n); n   std::vector<M> ms; n   ms.reserve(m); n   for (int i = 0; i < n; i++) { n     int p, t; n     scanf( %d%d , &p, &t); n     fs.push_back({p, t, i}); n   } n   for (int i = 0; i < m; i++) { n     int p, b; n     scanf( %d%d , &p, &b); n     ms.push_back({p, b}); n   } n   solve(fs, ms); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long edgestory; n long long last; n struct UnionFind { n   vector<int> f; n   vector<bool> special; n   void init(int n) { n     f.clear(); n     f.insert(f.begin(), n, -1); n     special.clear(); n     special.insert(special.begin(), n, false); n     edgestory = 0; n   } n   int comp(int x) { return (f[x] == -1 ? x : f[x] = comp(f[x])); } n   bool sp(int x) { return special[comp(x)]; } n   bool join1(int i, int j) { n     if (i == j) return true; n     edgestory++; n     bool con = comp(i) == comp(j); n     if (!con) { n       bool spv = sp(i) || sp(j); n       if (sp(i) && sp(j)) last = edgestory; n       f[comp(i)] = comp(j); n       special[comp(i)] = spv; n     } n     return con; n   } n   pair<int, int> join2(int i, int j) { n     if (i == j) return {0, 0}; n     edgestory++; n     if (edgestory == last) return {i, j}; n     bool con = comp(i) == comp(j); n     if (!con) { n       f[comp(i)] = comp(j); n     } n     return {0, 0}; n   } n } uf; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(nullptr); n   long long n, m, k; n   cin >> n >> m >> k; n   vector<long long> special(k); n   for (auto &x : special) cin >> x; n   vector<tuple<long long, long long, long long>> edges(m); n   for (auto &x : edges) { n     long long u, v, w; n     cin >> u >> v >> w; n     x = make_tuple(w, u - 1, v - 1); n   } n   sort(edges.begin(), edges.end()); n   uf.init(n); n   for (auto &x : special) uf.special[x - 1] = true; n   for (auto &[w, u, v] : edges) uf.join1(u, v); n   long long lastw = 0; n   uf.init(n); n   for (auto &[w, u, v] : edges) { n     lastw = w; n     if (uf.join2(u, v) != make_pair(0, 0)) break; n   } n   for (int i = 0; i < k; i++) cout <<     + !i << lastw; n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long INF = 1e9 + 7; n long long a[200005], b[200005], t[200005]; n long long c(long long l, long long r, long long* a) { n   if (l == r - 1) return 0; n   long long ans = 0, m = (l + r + 1) / 2, k = l, ct = 0; n   ans += c(l, m, a) + c(m, r, a); n   for (long long i = l, j = m; i < m || j < r;) { n     if (j >= r || (i < m && a[i] <= a[j])) { n       t[k++] = a[i++]; n       ct++; n     } else { n       t[k++] = a[j++]; n       ans += m - l - ct; n     } n   } n   for (long long i = l; i < r; i++) a[i] = t[i]; n   return ans; n } n bool solve() { n   long long n; n   string s, t; n   cin >> n >> s >> t; n   string ss = s, tt = t; n   sort((ss).begin(), (ss).end()), sort((tt).begin(), (tt).end()); n   if (ss != tt) { n     return false; n   } n   for (long long i = 0; i < n - 1; i++) { n     if (ss[i] == ss[i + 1]) { n       return true; n     } n   } n   for (long long i = 0; i < n; i++) { n     a[i] = lower_bound((ss).begin(), (ss).end(), s[i]) - ss.begin(); n     b[i] = lower_bound((ss).begin(), (ss).end(), t[i]) - ss.begin(); n   } n   long long c1 = c(0, n, a), c2 = c(0, n, b); n   return (c1 & 1) == (c2 & 1); n } n signed main() { n   std::ios::sync_with_stdio(0); n   std::cin.tie(0); n   ; n   long long q; n   cin >> q; n   while (q--) { n     if (solve()) n       cout <<  YES  << endl; n     else n       cout <<  NO  << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n ll mod = 1e9 + 7; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   ll t, n, m, i, j, k; n   cin >> n >> k; n   vector<ll> v; n   i = 0; n   if (n % 2 == 1) { n     v.push_back(1); n     n -= 1; n     i++; n   } n   if (n > 0) { n     j = log2(n); n     m = pow(2, j); n     while (n > 0) { n       if (m <= n) { n         n -= m; n         v.push_back(m); n         i++; n       } else { n         j--; n         m = pow(2, j); n       } n     } n   } n   ll x = 0, y; n   if (i <= k && n == 0) { n     for (j = 0; j < v.size(); j++) { n       if (i == k) break; n       m = v[j]; n       if (m == 1) continue; n       v.erase(v.begin() + j); n       j--; n       while (m != 1) { n         m /= 2; n         v.push_back(m); n         i++; n         if (i == k) break; n       } n       v.push_back(m); n     } n     if (i == k) { n       sort(v.begin(), v.end()); n       cout <<  YES  n            <<   n ; n       for (i = 0; i < v.size(); i++) cout << v[i] <<    ; n     } else n       cout <<  NO ; n   } else n     cout <<  NO ; n } n


#include <bits/stdc++.h> n using namespace std; n signed main() { n   long long V; n   cin >> V; n   while (V--) { n     double a[250]; n     for (long long i = 0; i < 250; i++) cin >> a[i]; n     double exp = 0; n     for (long long i = 0; i < 250; i++) exp += a[i]; n     exp /= 250; n     double var = 0; n     for (long long i = 0; i < 250; i++) var += (a[i] - exp) * (a[i] - exp); n     var /= 250; n     double k = exp / var; n     double err = 0.60; n     if (1.0 - err <= k && k <= 1.0 + err) n       cout <<  poisson  << endl; n     else n       cout <<  uniform  << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m; n vector<int> G[100000]; n int a[100000]; n int b[100000]; n int c[100000]; n void dfs(int v) { n   b[v]++; n   c[v] = 1; n   for (int i = 0; i < (int)(G[v].size()); i++) { n     int w = G[v][i]; n     if (++b[w] == a[w]) dfs(w); n   } n } n int main() { n   cin >> n >> m; n   for (int i = 0; i < (int)(m); i++) { n     int a, b; n     cin >> a >> b; n     --a, --b; n     G[a].push_back(b); n     G[b].push_back(a); n   } n   for (int i = 0; i < (int)(n); i++) cin >> a[i]; n   for (int i = 0; i < (int)(n); i++) { n     if (a[i] == b[i]) dfs(i); n   } n   cout << accumulate(c, c + n, 0) << endl; n   for (int i = 0; i < (int)(n); i++) n     if (c[i]) cout << i + 1 <<    ; n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n signed main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   long long t; n   cin >> t; n   while (t--) { n     long long n; n     cin >> n; n     long long sum = 0; n     long long a[n]; n     for (long long i = 0; i < n; i++) { n       cin >> a[i]; n       sum += a[i]; n     } n     sort(a, a + n); n     reverse(a, a + n); n     if (n == 1) { n       cout <<  T n ; n       continue; n     } n     if (n == 2) { n       if (a[0] == a[1]) { n         cout <<  HL n ; n         continue; n       } else { n         cout <<  T n ; n         continue; n       } n     } n     if (a[0] > sum - a[0]) { n       cout <<  T n ; n       continue; n     } n     if (sum % 2 == 0) { n       cout <<  HL n ; n       continue; n     } else { n       cout <<  T n ; n       continue; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n const double PI = 3.14159265358979323846264338327950288419716939937510; n const double E = 2.7182818284590452353602874713526624977572470936999596; n const double eps = 0.000000001; n const int MOD = 998244353; n inline int max(int u, int v) { return u > v ? u : v; } n inline int min(int u, int v) { return u < v ? u : v; } n inline int gcd(int u, int v) { return v ? gcd(v, u % v) : u; } n template <typename T> n inline void read(T& u) { n   char id; n   u = 0; n   bool flag = 0; n   id = getchar(); n   while (id >  9  || id <  0 ) { n     if (id ==  - ) flag = 1; n     id = getchar(); n   } n   while ((id <=  9  && id >=  0 )) { n     u = u * 10 + id -  0 ; n     id = getchar(); n   } n   if (flag) u *= -1; n } n template <typename T> n inline void read(T& u, T& v) { n   read(u); n   read(v); n } n template <typename T> n inline void read(T& u, T& v, T& tmp) { n   read(u); n   read(v); n   read(tmp); n } n long long n, m, a[1500][1500], r, c, len, f[2250000]; n struct node { n   long long x, y, v; n } str[2250000]; n bool cmp(node x, node y) { return x.v < y.v; } n long long power(long long a, long long n) { n   a %= MOD; n   long long res = 1; n   while (n) { n     if (n & 1) res = 1LL * res * a % MOD; n     a = 1LL * a * a % MOD; n     n >>= 1; n   } n   return res; n } n long long inv(long long x) { return power(x, MOD - 2) % MOD; } n long long cnt, a1, a2, b1, b2, sum; n void solve(int p) { n   f[p] = (sum + n           (1LL * str[p].x * str[p].x % MOD * cnt % MOD + a2 - n            2LL * str[p].x % MOD * a1 % MOD) + n           (1LL * str[p].y * str[p].y % MOD * cnt % MOD + b2 - n            2LL * str[p].y % MOD * b1 % MOD)) % n          MOD; n   f[p] = (1LL * f[p] + MOD) % MOD; n   f[p] = 1LL * f[p] * inv(cnt) % MOD; n } n inline void add(int p) { n   cnt++; n   sum += f[p]; n   a1 += str[p].x; n   a2 += 1LL * str[p].x * str[p].x % MOD; n   b1 += str[p].y; n   b2 += 1LL * str[p].y * str[p].y % MOD; n   a1 %= MOD; n   b1 %= MOD; n   a2 %= MOD; n   b2 %= MOD; n   sum %= MOD; n } n int main() { n   read(n, m); n   for (int i = (1); (i) <= (n); (i)++) n     for (int j = (1); (j) <= (m); (j)++) read(a[i][j]); n   for (int i = (1); (i) <= (n); (i)++) n     for (int j = (1); (j) <= (m); (j)++) str[++len] = (node){i, j, a[i][j]}; n   sort(str + 1, str + len + 1, cmp); n   for (int i = (1); (i) <= (len); (i)++) { n     int j; n     for (j = i; j <= len; j++) n       if (str[j].v != str[i].v) break; n     for (int k = (i); (k) <= (j - 1); (k)++) solve(k); n     for (int k = (i); (k) <= (j - 1); (k)++) add(k); n     i = j - 1; n   } n   long long r, c; n   read(r, c); n   long long res = 0; n   for (int i = (1); (i) <= (len); (i)++) n     if (str[i].x == r && str[i].y == c) res = f[i]; n   res %= MOD; n   res = (res + MOD) % MOD; n   cout << res << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const greater<int> gt; n int A[100000]; n int main() { n   cout << fixed << setprecision(11); n   long long n, k, m; n   cin >> n >> k >> m; n   for (int i = 0; i < n; ++i) cin >> A[i]; n   sort(A, A + n, gt); n   double mx = 0, rx = 0; n   for (int i = 0; i < n; ++i) { n     rx += A[i]; n     if (n - i < m + 2) { n       mx = max(mx, (min(m - n + i + 1, (i + 1) * k) + rx) / (i + 1)); n     } n   } n   cout << mx; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2e3 + 5; n int n, deg[N], a[N]; n bool ed[N][N]; n void change(int u) { n   for (int v = 0; v < n; v++) { n     deg[u] -= ed[u][v], deg[u] += ed[u][v] ^= true; n     deg[v] -= ed[v][u], deg[v] += ed[v][u] ^= true; n   } n } n bool check() { n   copy(deg, deg + n, a); n   sort(a, a + n, greater<int>()); n   for (int i = 1, sum = a[0]; i < n; sum += a[i++]) n     if (sum == i * (i - 1) / 2 + i * (n - i)) return false; n   return true; n } n int main() { n   cin >> n; n   for (int u = 0; u < n; u++) n     for (int v = 0; v < n; v++) { n       char c; n       cin >> c; n       deg[u] += ed[u][v] = c -  0 ; n     } n   if (check()) return cout <<  0 1 , 0; n   int ted = 0; n   for (int u = 0; u < n; change(u++)) change(u), ted += check(); n   if (ted) return cout <<  1   << ted, 0; n   if (n == 6) return cout <<  2 18 , 0; n   cout << -1; n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 1e5 + 5; n long long mod = 1e9 + 7; n vector<long long> v; n long long n, s; n bool check(long long x) { n   long long sum = 0; n   for (long long i = 0; i < n; i++) { n     sum += (v[i] - x); n   } n   return sum >= s; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(NULL); n   cin >> n; n   cin >> s; n   long long z; n   long long sum = 0; n   for (long long i = 0; i < n; i++) cin >> z, v.push_back(z), sum += z; n   if (sum < s) { n     cout <<  -1 ; n     return 0; n   } n   sort(v.begin(), v.end()); n   long long l = 0; n   long long r = v[0]; n   while (r > l + 1) { n     long long m = (l + r) / 2; n     if (check(m)) { n       l = m; n     } else { n       r = m; n     } n   } n   if (!check(r)) n     cout << l <<   n ; n   else n     cout << r; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1 << 20; n const int inf = 2e9; n int n, q; n int h[maxn], v[maxn]; n pair<pair<int, int>, int> b[maxn]; n vector<int> hull[maxn]; n long double inter(int id1, int id2) { n   if (v[id1] == v[id2]) return -1; n   return (long double)(h[id1] - h[id2]) / (v[id2] - v[id1]); n } n long double H(int idx, long double t) { return h[idx] + t * v[idx]; } n void update(int node, int x) { n   while (hull[node].size() > 1) { n     int sz = hull[node].size(); n     int id1 = hull[node][sz - 1]; n     int id2 = hull[node][sz - 2]; n     long double t = inter(id1, id2); n     if (v[id1] == v[x] or H(x, t) >= H(id1, t)) n       hull[node].pop_back(); n     else n       break; n   } n   if (hull[node].size() == 1 and h[*hull[node].begin()] < h[x]) n     hull[node].pop_back(); n   hull[node].push_back(x); n } n void add(int node, int l, int r, int idx) { n   if (idx < l or r <= idx) return; n   update(node, idx); n   if (r - l < 2) return; n   int mid = (l + r) / 2; n   add((node + node + 0), l, mid, idx); n   add((node + node + 1), mid, r, idx); n } n pair<long double, int> find(int node, int t) { n   int l = 0, r = hull[node].size(); n   for (; r - l > 1;) { n     int mid = (l + r) / 2; n     if (inter(hull[node][mid], hull[node][mid - 1]) <= t) n       l = mid; n     else n       r = mid; n   } n   return make_pair(H(hull[node][l], t), hull[node][l]); n } n pair<long double, int> ans(int node, int l, int r, int s, int e, int t) { n   if (e <= l or r <= s) return make_pair(-inf, n); n   if (s <= l and r <= e) return find(node, t); n   int mid = (l + r) / 2; n   return max(ans((node + node + 0), l, mid, s, e, t), n              ans((node + node + 1), mid, r, s, e, t)); n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cin >> n >> q; n   for (int i = 0; i < n; i++) { n     cin >> h[i] >> v[i]; n     b[i].first.second = h[i]; n     b[i].first.first = v[i]; n     b[i].second = i; n   } n   h[n] = -1; n   v[n] = 0; n   sort(b, b + n); n   for (int i = 0; i < n; i++) add(1, 0, n, b[i].second); n   for (int l, r, t; q--;) { n     cin >> l >> r >> t; n     l--, r--; n     cout << ans(1, 0, n, l, r + 1, t).second + 1 << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long n, k, num; n   cin >> n >> k; n   num = (n) * (n - 1) / 2; n   if (num <= k) n     cout <<  no solution  << endl; n   else n     for (int i = 1; i <= n; i++) cout << 1 <<     << i << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 1000000009; n const int MOD = 1000000007; n double probMayor(pair<int, int> x, int bid) { n   if (bid < x.first) { n     return 1.0; n   } n   if (bid > x.second) { n     return 0.0; n   } n   return double(x.second - bid) / (x.second - x.first + 1); n } n double probMenor(pair<int, int> x, int bid) { n   if (bid < x.first) { n     return 0.0; n   } n   if (bid > x.second) { n     return 1.0; n   } n   return double(bid - x.first) / (x.second - x.first + 1); n } n double go(vector<pair<int, int> > v, int idx, int bid, int cnt) { n   if (idx >= v.size()) { n     if (cnt <= 0) { n       return 1; n     } n     return 0; n   } n   double res = 0.0; n   if (bid >= v[idx].first && bid <= v[idx].second) { n     res += go(v, idx + 1, bid, cnt - 1) * n            (1.0 / (v[idx].second - v[idx].first + 1)); n   } n   res += go(v, idx + 1, bid, cnt) * probMenor(v[idx], bid); n   return res; n } n int main() { n   int n; n   cin >> n; n   vector<pair<int, int> > v; n   for (int i = 0; i < n; i++) { n     int l, r; n     cin >> l >> r; n     v.push_back(make_pair(l, r)); n   } n   double res = 0.0; n   for (int i = 0; i < n; i++) { n     pair<int, int> p = v[i]; n     v.erase(v.begin() + i); n     for (int j = 1; j <= 10000; j++) { n       res += probMayor(p, j) * j * go(v, 0, j, 1); n     } n     v.insert(v.begin() + i, p); n   } n   for (int j = 1; j <= 10000; j++) { n     res += j * go(v, 0, j, 2); n   } n   printf( %.10f n , res); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 305, MOD = 1e4 + 7; n char s[N]; n int n, m, ndc, f[N][N][N]; n int getf(int cnt, int l, int r) { n   if (cnt < 0) return 0; n   if (~f[cnt][l][r]) return f[cnt][l][r]; n   if (l == 1 && r == m) return f[cnt][l][r] = !cnt; n   int ret = 0; n   if (l > 1 && r < m && s[l - 1] == s[r + 1]) n     ret = (ret + getf(cnt, l - 1, r + 1)) % MOD; n   if (l > 1 && s[l - 1] != s[r]) ret = (ret + getf(cnt - 1, l - 1, r)) % MOD; n   if (r < m && s[l] != s[r + 1]) ret = (ret + getf(cnt - 1, l, r + 1)) % MOD; n   return f[cnt][l][r] = ret; n } n struct matrix { n   int sq[N][N]; n   matrix() { memset(sq, 0, sizeof(sq)); } n   matrix operator*(const matrix &a) const { n     matrix ret; n     for (int i = 1; i <= ndc; i++) n       for (int j = i; j <= ndc; j++) n         for (int k = i; k <= j; k++) n           ret.sq[i][j] = (ret.sq[i][j] + 1ll * sq[i][k] * a.sq[k][j]) % MOD; n     return ret; n   } n } trs, one; n inline matrix qpow(matrix x, int y) { n   matrix ret = one; n   while (y) { n     if (y & 1) ret = ret * x; n     x = x * x; n     y >>= 1; n   } n   return ret; n } n int idr[N], idg[N], cntc[N]; n int main() { n   int i, j, k, ans = 0; n   scanf( %s%d , s + 1, &n); n   m = strlen(s + 1); n   idr[0] = ++ndc; n   for (i = 1; i < m; i++) { n     int rem = (m - i + 1) / 2; n     if ((m - i + 1) / 2 != (m - i) / 2 + 1) idg[(m - i) / 2 + 1] = ++ndc; n     idr[i] = ++ndc; n   } n   if (!idg[1]) idg[1] = ++ndc; n   idg[0] = ++ndc; n   for (i = 0; i < m; i++) { n     if (i) trs.sq[idr[i]][idr[i]] = 24; n     if (i < m - 1) trs.sq[idr[i]][idr[i + 1]] = 1; n   } n   for (i = (m + 1) / 2; i > 0; i--) { n     trs.sq[idg[i]][idg[i]] = 25; n     trs.sq[idg[i]][idg[i - 1]] = 1; n   } n   for (i = 1; i <= ndc; i++) one.sq[i][i] = 1; n   memset(f, -1, sizeof(f)); n   for (i = 0; i < m; i++) { n     for (j = 1; j <= m; j++) { n       cntc[i] = (cntc[i] + getf(i, j, j)) % MOD; n       if (j < m && s[j] == s[j + 1]) n         cntc[i] = (cntc[i] + getf(i, j, j + 1)) % MOD; n     } n   } n   for (i = 0; i < m; i++) trs.sq[idr[i]][idg[(m - i + 1) / 2]] = cntc[i]; n   trs.sq[ndc][ndc] = 26; n   ans = (qpow(trs, (n + m + 1) / 2 + 1)).sq[1][ndc]; n   if (!((n + m) & 1)) { n     printf( %d , ans); n     return 0; n   } n   memset(f, -1, sizeof(f)); n   memset(cntc, 0, sizeof(cntc)); n   for (i = 0; i < m; i++) n     for (j = 1; j < m; j++) n       if (s[j] == s[j + 1]) cntc[i] = (cntc[i] + getf(i, j, j + 1)) % MOD; n   for (i = 0; i < m; i++) trs.sq[idr[i]][idg[(m - i + 1) / 2]] = cntc[i]; n   trs.sq[ndc][ndc] = 0; n   ans = (ans - (qpow(trs, (n + m + 1) / 2 + 1)).sq[1][ndc] + MOD) % MOD; n   printf( %d , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   cin >> t; n   while (t--) { n     int n; n     cin >> n; n     char ch; n     string str; n     cin >> str; n     int n1 = 0, n2 = 0; n     int ct = 0; n     for (int i = 0; i < n; i++) { n       if (str[i] ==  ( ) { n         if (n2 > 0) { n           if (n2 > n1) { n             n2 = 0; n             n1 = 0; n           } else { n             n1 -= n2; n             n2 = 0; n           } n         } n         n1++; n       } else { n         n2++; n         if (n2 > n1) ct++; n       } n     } n     cout << ct << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:256000000 ) n using namespace std; n double E = 2.71828182846; n double PI = 3.1415926535897932384626433832795; n double EPS = 1e-9; n const int ROOT = 444; n const int MAXN = 300100; n const int ROOTN = 555; n int n; n int gcd(int a, int b) { n   while (b) { n     a %= b; n     swap(a, b); n   } n   return a; n } n void solve() { n   cin >> n; n   for (int i = 0; i <= n; i += 1234567) { n     for (int j = i; j <= n; j += 123456) { n       if ((n - j) % 1234 == 0) { n         cout <<  YES ; n         return; n       } n     } n   } n   cout <<  NO ; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   srand(1313); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline int read() { n   int X = 0, w = 1; n   char c = getchar(); n   while (c <  0  || c >  9 ) { n     if (c ==  - ) w = -1; n     c = getchar(); n   } n   while (c >=  0  && c <=  9 ) X = X * 10 + c -  0 , c = getchar(); n   return X * w; n } n const int N = 100 + 10; n inline int id(int x, int y) { n   if (x & 1) n     return (x - 1) * 10 + y; n   else n     return (x - 1) * 10 + 11 - y; n } n int to[N]; n double dp[N]; n int main() { n   for (register int i = 1; i <= 10; ++i) n     for (register int j = 1; j <= 10; ++j) to[id(i, j)] = id(i - read(), j); n   for (register int i = 2; i <= 6; ++i) { n     for (register int j = 1; j < i; ++j) dp[i] += dp[j] / 6; n     dp[i] = (dp[i] + 1) / (i - 1) * 6; n   } n   for (register int i = 7; i <= 100; ++i) { n     for (register int j = 1; j <= 6; ++j) n       dp[i] += min(dp[i - j], dp[to[i - j]]); n     dp[i] = dp[i] / 6 + 1; n   } n   printf( %.10lf n , dp[100]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MX = 200005; n int ans, cnt0, cnt1, lth, pos1[MX], pos0[MX], pre[MX], nxt[MX]; n char s[MX]; n bool vis[MX]; n int main() { n   scanf( %s , s + 1); n   lth = strlen(s + 1); n   for (int i = 1; i <= lth; i++) { n     if (s[i] ==  0 ) n       pos0[++cnt0] = i; n     else n       pos1[++cnt1] = i; n     if (cnt1 > cnt0) return puts( -1 ), 0; n   } n   cnt0 = cnt1 = 0; n   for (int i = lth; i; i--) { n     if (s[i] ==  0 ) n       cnt0++; n     else n       cnt1++; n     if (cnt1 > cnt0) return puts( -1 ), 0; n   } n   printf( %d n , cnt0 - cnt1); n   for (int i = 1; i <= cnt1; i++) n     pre[pos1[i]] = pos0[i], nxt[pos0[i]] = pos1[i]; n   for (int i = cnt1, j = cnt0; i; i--, j--) n     nxt[pos1[i]] = pos0[j], pre[pos0[j]] = pos1[i]; n   for (int i = 1; i <= lth; i++) n     if (!vis[i]) { n       int cnt = 0; n       for (int j = i; j; j = nxt[j]) cnt++, vis[j] = 1; n       printf( %d  , cnt); n       for (int j = i; j; j = nxt[j]) printf( %d  , j); n       putchar(  n ); n     } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long int N = 2e5 + 5; n void solve() { n   long long int n, m; n   cin >> n >> m; n   vector<long long int> v(m); n   for (auto &it : v) cin >> it; n   ; n   vector<long long int> suf(m); n   long long int s = 0; n   for (long long int i = m - 1; i >= 0; i--) { n     if (i + v[i] - 1 > n - 1) { n       cout << -1 <<   n ; n       return; n     } n     s += v[i]; n     suf[i] = s; n   } n   if (s < n) { n     cout << -1 <<   n ; n     return; n   } n   long long int j = 0; n   long long int start = 0, prev = -1; n   vector<long long int> ans; n   for (long long int i = 0; i < m; i++) { n     cout << max(n - suf[i] + 1, i + 1) <<    ; n   } n   cout <<   n ; n } n signed main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long int t = 1; n   while (t--) solve(); n   return 0; n } n


#include<fstream> n #include<iostream> n #include<sstream> n #include<iomanip> n #include<string> n #include<vector> n #include<list> n #include<set> n #include<map> n #include<queue> n #include<algorithm> n #include<functional> n #include<numeric> n #include<bitset> n #include<cassert> n #include<array> n #include  string.h  n #include  math.h  n using namespace std; n typedef long long ll; n typedef unsigned long long ull; n typedef pair<int, int> pii; n typedef pair<ll, ll> pll; n #define mp make_pair n  n #ifndef BLAH n #define fin cin n #define fout cout n #endif n  n namespace n { n  n } n  n int main() n { n  ios::sync_with_stdio(0); n #ifdef BLAH n  ifstream fin( test.in ); n  ofstream fout( test.out ); n #endif n  n  int zzz; fin >> zzz; n  for (int zz = 1; zz <= zzz; ++zz) n  { n   int n, m; fin >> n >> m; n   string s, ss; n   fin >> s; n   s =  0  + s +  0 ; n  n   for (int t = 0; t < m; ++t) n   { n    ss = s; n    for (int i = 1; i <= n; ++i) n    { n     if (s[i - 1] != s[i + 1]) n      ss[i] =  1 ; n    } n    if (s == ss) break; n    swap(s, ss); n   } n  n   fout << s.substr(1, n) << endl; n  } n  n  return 0; n } n  n


#include <bits/stdc++.h> n using namespace std; n unsigned long long modExponentiate(unsigned long long a, unsigned long long b) { n   if (b == 0) return 1; n   unsigned long long ans = a; n   unsigned long long t = 1; n   while (b > 1) { n     if (b % 2 == 0) { n       ans = (ans * ans) % (1000000007); n       a = (a * a) % 1000000007; n       b = b / 2; n     } else { n       t = (t * a) % 1000000007; n       b = b - 1; n     } n   } n   return (t * ans) % 1000000007; n } n int noofz(int a) { n   int no = 0; n   while (a > 0) { n     if ((a % 2) == 1) no++; n     a = a / 2; n   } n   return (6 - no); n } n int main() { n   map<char, int> m; n   for (int i = 0; i < 10; i++) m[(char)( 0  + i)] = noofz(i); n   for (int i = 10; i < 36; i++) m[(char)( A  + i - 10)] = noofz(i); n   for (int i = 36; i < 62; i++) m[(char)( a  + i - 36)] = noofz(i); n   m[ - ] = noofz(62); n   m[ _ ] = noofz(63); n   char str[100001]; n   cin >> str; n   long long ans = 1LL; n   long long anslog = 0LL; n   for (int i = 0; i < strlen(str); i++) { n     anslog = anslog + m[str[i]]; n   } n   ans = modExponentiate(3, anslog); n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   int steps, count, i, n; n   char str[500]; n   char pc; n   scanf( %s , str); n   steps = count = 0; n   n = strlen(str); n   if (n == 0) { n     printf( 0 n ); n     return 0; n   } n   pc = str[0]; n   count = 1; n   for (i = 1; i < n; i++) { n     if (count == 5) { n       count = 1; n       steps++; n       pc = str[i]; n       continue; n     } n     if (pc == str[i]) n       count++; n     else { n       count = 1; n       steps++; n       pc = str[i]; n     } n   } n   if (count > 0) steps++; n   printf( %d n , steps); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long INF = 2e9; n const long long MOD = 1e9 + 7; n mt19937 azino(777); n int ask(int a, int b, int c) { n   cout <<  ?   << a <<     << b <<     << c << endl; n   int x; n   cin >> x; n   return x; n } n void answer(vector<int>& ans) { n   cout <<  !   << ans.size() <<    ; n   for (auto& it : ans) cout << it <<    ; n   cout << endl; n   return; n } n vector<int> pp(int pos0, int pos1, int pos, int type) { n   vector<int> p(3, -1); n   if (type == 0) { n     int c1 = ask(pos1, pos, pos + 1); n     int c2 = ask(pos1, pos, pos + 2); n     if (c1 == c2) { n       if (c1 == 0) p[0] = p[1] = p[2] = 0; n       if (c1 == 1) p[0] = 1, p[1] = p[2] = 0; n     } else { n       if (c1 == 0) p[0] = p[1] = 0; n       if (c2 == 0) p[0] = p[2] = 0; n       for (auto& i : p) n         if (i == -1) i = 1; n     } n   } else { n     int c1 = ask(pos0, pos, pos + 1); n     int c2 = ask(pos0, pos, pos + 2); n     if (c1 == c2 && c1 == 1) n       p[0] = p[1] = p[2] = 1; n     else if (c1 == c2 && c1 == 0) n       p[0] = 0, p[1] = p[2] = 1; n     else { n       if (c1 == 1) p[0] = p[1] = 1; n       if (c2 == 1) p[0] = p[2] = 1; n       for (auto& i : p) n         if (i == -1) i = 0; n     } n   } n   return p; n } n void solve() { n   int n; n   cin >> n; n   vector<int> z(n); n   int pos0 = 0, pos1 = 0; n   for (int i = 0; i < n; i += 3) { n     z[i] = ask(i + 1, i + 2, i + 3); n     if (z[i]) n       pos1 = i; n     else n       pos0 = i; n   } n   vector<int> p0(3, -1), p1(3, -1); n   int c1 = ask(pos1 + 1, pos1 + 2, pos0 + 1); n   int c2 = ask(pos1 + 1, pos1 + 2, pos0 + 2); n   int poss0 = -1, poss1 = -1; n   if (c1 == c2) { n     if (c1 == 0) n       p0[0] = p0[1] = 0; n     else n       p1[0] = p1[1] = 1; n   } else { n     p0[0] = c1, p0[1] = c2; n     if (c1 == 0) n       poss0 = pos0 + 1; n     else n       poss1 = pos0 + 1; n     if (c2 == 0) n       poss0 = pos0 + 2; n     else n       poss1 = pos0 + 2; n   } n   if (p0[0] == -1) { n     c1 = ask(pos1 + 1, pos0 + 1, pos0 + 2); n     c2 = ask(pos1 + 1, pos0 + 1, pos0 + 3); n     if (c1 == c2 && c1 == 0) n       p0[0] = p0[1] = p0[2] = 0; n     else if (c1 == c2 && c1 == 1) n       p0[0] = 1, p0[1] = p0[2] = 0; n     else { n       if (c1 == 0) p0[0] = p0[1] = 0; n       if (c2 == 0) p0[0] = p0[2] = 0; n       for (auto& i : p0) n         if (i == -1) i = 1; n     } n     for (int i = 0; i < 3; ++i) n       if (p0[i] == 0) n         poss0 = pos0 + 1 + i; n       else n         poss1 = pos0 + 1 + i; n     c1 = ask(poss0, pos1 + 1, pos1 + 2); n     c2 = ask(poss0, pos1 + 1, pos1 + 3); n     if (c1 == c2) { n       if (c1 == 1) p1[0] = p1[1] = p1[2] = 1; n       if (c1 == 0) p1[0] = 0, p1[1] = p1[2] = 1; n     } else { n       if (c1 == 1) p1[0] = p1[1] = 1; n       if (c2 == 1) p1[0] = p1[2] = 1; n       for (auto& i : p1) n         if (i == -1) i = 0; n     } n     for (int i = 0; i < 3; ++i) n       if (p1[i] == 0) n         poss0 = pos1 + 1 + i; n       else n         poss1 = pos1 + 1 + i; n   } else { n     if (poss0 != -1) { n       for (int i = 0; i < 3; ++i) p1[i] = ask(poss1, poss0, pos1 + 1 + i); n       p0[2] = ask(poss1, poss0, pos0 + 3); n     } else { n       c1 = ask(pos0 + 1, pos1 + 1, pos1 + 2); n       c2 = ask(pos0 + 1, pos1 + 1, pos1 + 3); n       if (c1 == c2 && c1 == 1) n         p1[0] = p1[1] = p1[2] = 1; n       else if (c1 == c2 && c1 == 0) n         p1[0] = 0, p1[1] = p1[2] = 1; n       else { n         if (c1 == 1) p1[0] = p1[1] = 1; n         if (c2 == 1) p1[0] = p1[2] = 1; n         for (auto& i : p1) n           if (i == -1) i = 0; n       } n       for (int i = 0; i < 3; ++i) n         if (p1[i] == 0) n           poss0 = pos1 + 1 + i; n         else n           poss1 = pos1 + 1 + i; n       c1 = ask(poss1, pos0 + 1, pos0 + 2); n       c2 = ask(poss1, pos0 + 1, pos0 + 3); n       if (c1 == c2) { n         if (c1 == 0) p0[0] = p0[1] = p0[2] = 0; n         if (c1 == 1) p0[0] = 1, p0[1] = p0[2] = 0; n       } else { n         if (c1 == 0) p0[0] = p0[1] = 0; n         if (c2 == 0) p0[0] = p0[2] = 0; n         for (auto& i : p0) n           if (i == -1) i = 1; n       } n       for (int i = 0; i < 3; ++i) n         if (p0[i] == 0) n           poss0 = pos0 + 1 + i; n         else n           poss1 = pos0 + 1 + i; n     } n   } n   vector<int> ans; n   for (int i = 0; i < 3; ++i) n     if (p0[i] == 0) ans.emplace_back(pos0 + i + 1); n   for (int i = 0; i < 3; ++i) n     if (p1[i] == 0) ans.emplace_back(pos1 + i + 1); n   for (int i = 0; i < n; i += 3) { n     if (i == pos0 || i == pos1) continue; n     auto it = pp(poss0, poss1, i + 1, z[i]); n     for (int j = 0; j < 3; ++j) n       if (it[j] == 0) ans.emplace_back(i + 1 + j); n   } n   answer(ans); n } n signed main() { n   cout << fixed << setprecision(15); n   int t; n   cin >> t; n   while (t-- > 0) { n     solve(); n     cout <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int x, y, z, t1, t2, t3; n   cin >> x >> y >> z >> t1 >> t2 >> t3; n   long long int lift = abs(x - z) * t2 + 3 * t3 + abs(x - y) * t2, n                 walk = abs(x - y) * t1; n   if (lift <= walk) n     cout <<  YES ; n   else n     cout <<  NO ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int T; n char s[2000]; n int main() { n   scanf( %d , &T); n   while (T--) { n     scanf( %s , s + 1); n     int l = strlen(s + 1); n     if (s[l] ==  o  && s[l - 1] ==  p ) n       printf( FILIPINO n ); n     else if (s[l] ==  u  && s[l - 1] ==  s  && s[l - 2] ==  e  && n                  s[l - 3] ==  d  || n              s[l] ==  u  && s[l - 1] ==  s  && s[l - 2] ==  a  && n                  s[l - 3] ==  m ) n       printf( JAPANESE n ); n     else n       printf( KOREAN n ); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   cin >> t; n   while (t--) { n     int n, m; n     cin >> n >> m; n     int a[n][m]; n     int f = 0; n     for (int i = 0; i < n; i++) { n       for (int j = 0; j < m; j++) { n         cin >> a[i][j]; n         if ((i == 0 || i == n - 1) && (j == 0 || j == m - 1)) { n           if (a[i][j] > 2) { n             f = 1; n           } else { n             a[i][j] = 2; n           } n         } else if (i == 0 || i == n - 1 || j == 0 || j == m - 1) { n           if (a[i][j] > 3) { n             f = 1; n           } else { n             a[i][j] = 3; n           } n         } else { n           if (a[i][j] > 4) { n             f = 1; n           } else { n             a[i][j] = 4; n           } n         } n       } n     } n     if (f == 1) { n       cout <<  NO  << endl; n     } else { n       cout <<  YES  << endl; n       for (int i = 0; i < n; i++) { n         for (int j = 0; j < m; j++) { n           cout << a[i][j] <<    ; n         } n         cout << endl; n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 100005; n int a[maxn], b[maxn]; n int n, m; n int main() { n   while (~scanf( %d%d , &n, &m)) { n     for (int i = 0; i < n; i++) scanf( %d , a + i); n     for (int i = 0; i < m; i++) scanf( %d , b + i); n     int dis, ans = 0; n     for (int i = 0; i < n; i++) { n       int tmp = lower_bound(b, b + m, a[i]) - b; n       if (tmp == 0) n         dis = b[0] - a[i]; n       else if (tmp == m) n         dis = a[i] - b[m - 1]; n       else n         dis = min(b[tmp] - a[i], a[i] - b[tmp - 1]); n       ans = max(ans, dis); n     } n     printf( %d n , ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 200010; n const int mod = 1e9 + 7; n inline int cal(int x, int y) { n   int l = 0, r = 1e9; n   while (l < r) { n     int mid = l + r + 1 >> 1; n     if (3ll * mid + y <= x) n       l = mid; n     else n       r = mid - 1; n   } n   if (y > x) return 0; n   return l + 1; n } n int main() { n   int n, l, r; n   while (~scanf( %d%d%d , &n, &l, &r)) { n     int cnt[5] = {0}, dp[2][5] = {0}, t = 0; n     for (int i = 0; i < 3; i++) { n       cnt[i] = cal(r, i) - cal(l - 1, i); n     } n     dp[0][0] = 1; n     for (int i = 1; i <= n; i++) { n       t ^= 1; n       for (int j = 0; j < 3; j++) { n         dp[t][j] = 0; n         for (int k = 0; k < 3; k++) { n           dp[t][j] += 1ll * cnt[k] * dp[t ^ 1][(j - k + 3) % 3] % mod; n           if (dp[t][j] >= mod) dp[t][j] -= mod; n         } n       } n     } n     printf( %d n , dp[t][0]); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n const double Exp = 1e-9; n int sgn(double x) { n   if (fabs(x) < Exp) return 0; n   return x > 0 ? 1 : -1; n } n struct Point { n   double x, y; n   Point(double x = 0, double y = 0) : x(x), y(y) {} n   friend Point operator+(const Point &a, const Point &b) { n     return Point(a.x + b.x, a.y + b.y); n   } n   friend Point operator-(const Point &a, const Point &b) { n     return Point(a.x - b.x, a.y - b.y); n   } n   friend Point operator*(const Point &a, double b) { n     return Point(a.x * b, a.y * b); n   } n   friend Point operator/(const Point &a, double b) { n     return Point(a.x / b, a.y / b); n   } n   Point rotate(double del) { n     return Point(x * cos(del) - y * sin(del), x * sin(del) + y * cos(del)); n   } n } s, t, island[40]; n vector<Point> vec; n double Dot(const Point &a, const Point &b) { return a.x * b.x + a.y * b.y; } n double Cross(const Point &a, const Point &b) { return a.x * b.y - a.y * b.x; } n double Length(const Point &a) { return sqrt(Dot(a, a)); } n struct Line { n   Point p, v; n   Line(Point p, Point v) : p(p), v(v) {} n   Point get_point(double t) { return p + v * t; } n }; n Point get_line_intersection(const Line &l1, const Line &l2) { n   Point a = l1.p, b = l1.p + l1.v; n   Point c = l2.p, d = l2.p + l2.v; n   double u = Cross(d - a, c - a), v = Cross(c - b, d - b); n   double t = u / (u + v); n   return a + (b - a) * t; n } n int if_point_on_line(const Point &p, const Point &st, const Point &ed) { n   return sgn(Cross(p - st, ed - st)) == 0; n } n int if_point_on_ray(const Point &p, const Point &st, const Point &ed) { n   if (sgn(Cross(p - st, ed - st)) != 0) return 0; n   if (sgn(Dot(p - st, ed - st)) < 0) return 0; n   return 1; n } n int if_point_on_segment(const Point &p, const Point &st, const Point &ed) { n   return if_point_on_ray(p, st, ed) && if_point_on_ray(p, ed, st); n } n int main() { n   cin >> s.x >> s.y >> t.x >> t.y; n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> island[i].x >> island[i].y; n   } n   double sum = 0; n   int flag = 0; n   int cnt = 0; n   for (int i = 0; i < n; i++) { n     int l = i, r = i + 1; n     r %= n; n     sum += Length(island[r] - island[l]); n   } n   for (int i = 0; i < n; i++) { n     int l = i, r = i + 1; n     r %= n; n     if (flag == 1 && cnt < 2) vec.push_back(island[l]); n     Point now; n     if (sgn(Cross(s - t, island[r] - island[l])) != 0) { n       now = get_line_intersection(Line(s, t - s), n                                   Line(island[r], island[l] - island[r])); n       if (if_point_on_segment(now, island[l], island[r])) { n         if ((vec.size() > 0 && sgn(Length(vec[vec.size() - 1] - now)) != 0) || n             vec.size() == 0) { n           if (if_point_on_segment(now, s, t)) { n             cnt++; n             flag = 1; n             vec.push_back(now); n             if (cnt == 2) break; n           } n         } n       } n     } else if (if_point_on_line(island[l], s, t)) { n       flag = 2; n       break; n     } n   } n   if (flag == 2 || cnt == 0) { n     double ans = Length(s - t); n     printf( %.9lf n , ans); n     return 0; n   } n   double edge_len = 0; n   for (int i = 1; i < vec.size(); i++) { n     edge_len += Length(vec[i] - vec[i - 1]); n   } n   edge_len = min(edge_len, sum - edge_len); n   double s_len = min(Length(s - vec[0]), Length(s - vec[vec.size() - 1])); n   double t_len = min(Length(t - vec[0]), Length(t - vec[vec.size() - 1])); n   double ans1 = edge_len + s_len + t_len; n   double rest_len = Length(s - t); n   rest_len -= s_len + t_len; n   double ans2 = s_len + t_len + 2 * rest_len; n   double ans = min(ans1, ans2); n   printf( %.9lf n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   string s, h; n   cin >> s; n   h = s; n   sort(h.begin(), h.end()); n   if (s != h) { n     cout <<  NO ; n     return 0; n   } n   int a = 0, b = 0, c = 0; n   for (int i = 0; i < s.size(); i++) { n     if (s[i] ==  a ) { n       a++; n     } else if (s[i] ==  b ) { n       b++; n     } else { n       c++; n     } n   } n   if (a != 0 && b != 0 && (a == c || b == c)) { n     cout <<  YES ; n   } else { n     cout <<  NO ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX_INT = 1000 * 1000 * 1000; n int n, m; n vector<int> ver; n vector<int> hor; n int main() { n   cin >> n >> m; n   ver.reserve(n + 1); n   ver.resize(n); n   for (int i = 0; i < n; ++i) cin >> ver.at(i), ver.at(i) += 1; n   ver.push_back(MAX_INT + 1); n   sort(ver.begin(), ver.end()); n   for (int i = 0; i < m; ++i) { n     int x1, x2, y; n     cin >> x1 >> x2 >> y; n     if (x1 == 1) hor.push_back(x2 + 1); n   } n   sort(hor.begin(), hor.end()); n   int bestAns = n + m; n   for (int i = 0; i < ver.size(); ++i) { n     auto it = lower_bound(hor.begin(), hor.end(), ver.at(i)); n     int mustBreak = distance(it, hor.end()); n     bestAns = min(bestAns, i + mustBreak); n   } n   cout << bestAns << endl; 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   string s; n   cin >> s; n   string a(s); n   int n; n   cin >> n; n   for (int i = 0; i < int(s.size()); ++i) { n     if (isupper(s[i])) { n       s[i] -=  A ; n       s[i] +=  a ; n     } n     if (s[i] <  a  + n) { n       a[i] = s[i] -  a  +  A ; n     } else n       a[i] = s[i]; n   } n   cout << a; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void timer() { return; } n const int mod = 1e9 + 7; n int dx[] = {0, 0, 1, -1}; n int dy[] = {1, -1, 0, 0}; n string ds =  RLDU ; n const int mx = 5e4 + 10; n long long sum[mx]; n void solve() { n   int n, t; n   cin >> n >> t; n   for (int i = (1); i < (n + 1); ++i) { n     for (int j = (0); j < (n - i); ++j) { n       cout << 0 <<    ; n     } n     cout << t <<    ; n     for (int j = (n - i + 1); j < (n); ++j) cout << 0 <<    ; n     cout << endl; n   } n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   ; n   timer(); n   int t = 1; n   for (int i = (1); i < (t + 1); ++i) { n     solve(); n   } n   timer(); n } n


#include <bits/stdc++.h> n using namespace std; n long long gcd(long long a, long long b) { return !b ? a : gcd(b, a % b); } n long long lcm(long long a, long long b) { return (a / gcd(a, b)) * b; } n enum dir { n   DOWN = 0, n   UP, n   RIGHT, n   LEFT, n   DOWN_RIGHT, n   DOWN_LEFT, n   UP_RIGHT, n   UP_LEFT n }; n int dir_r[] = {1, -1, 0, 0, 1, 1, -1, -1}; n int dir_c[] = {0, 0, 1, -1, 1, -1, 1, -1}; n bool p(long long s) { n   if (s == 1 || (s % 2 == 0 && s != 2)) return 0; n   for (int i = 2; i <= sqrt(s); i++) { n     if (s % i == 0) return 0; n   } n   return 1; n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long n; n   cin >> n; n   if (p(n)) return cout << 1, 0; n   long long ans = 1e12; n   for (long long i = 1; i <= sqrt(n); i++) { n     if (n % i == 0) { n       if (p(i)) { n         ans = min(ans, i); n       } n       if (p(n / i)) ans = min(ans, i); n     } n   } n   if (ans == 1e12) n     cout << 0; n   else { n     n -= ans; n     cout << n / 2 + 1; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m; n long long a[200000], b[200000]; n bool ok(long long x) { n   int p(1); n   long long q(0); n   for (int i = 1; i <= (m); ++i) n     if (b[i] > q) { n       while (p <= n && a[p] + x < b[i]) ++p; n       if (a[p] - x > b[i] || p > n) return false; n       if (a[p] <= b[i]) n         q = a[p] + x; n       else n         q = max(b[i] + x - (a[p] - b[i]), a[p] + (x - (a[p] - b[i])) / 2); n       ++p; n     } n   return true; n } n int main() { n   scanf( %d%d , &n, &m); n   for (int i = 1; i <= (n); ++i) scanf( %I64d , &a[i]); n   for (int i = 1; i <= (m); ++i) scanf( %I64d , &b[i]); n   long long L = -1, R = 1LL << 40; n   while (L + 1 < R) (ok(L + R >> 1) ? R : L) = L + R >> 1; n   printf( %I64d n , R); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int x; n   cin >> x; n   vector<long long> result; n   for (long long i = 1; i <= x; i++) { n     long long n; n     cin >> n; n     vector<long long> v(n); n     for (long long h = 0; h <= n - 1; h++) cin >> v[h]; n     sort(v.begin(), v.end()); n     if (v[n - 1] == 1 || v[n - 2] == 1) n       result.push_back(0); n     else if ((n - 2) < v[n - 2]) n       result.push_back(n - 2); n     else if ((n - 2) >= v[n - 2]) n       result.push_back(v[n - 2] - 1); n   } n   for (long long i = 0; i <= x - 1; i++) cout << result[i] << endl; n } n


#include <bits/stdc++.h> n using namespace std; n void solve(int test_number); n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n   cout.setf(ios::fixed); n   cout.precision(9); n   cerr.setf(ios::fixed); n   cerr.precision(3); n   int n = 1; n   for (int i = 0; i < n; i++) { n     solve(i); n   } n } n const int MAX_N = 300005; n int n, n_edge, deg[MAX_N]; n int point[MAX_N], head[MAX_N], next_edge[MAX_N]; n bool line[MAX_N]; n void add_edge(int u, int v) { n   point[n_edge] = v, next_edge[n_edge] = head[u], head[u] = n_edge++; n   point[n_edge] = u, next_edge[n_edge] = head[v], head[v] = n_edge++; n } n bool is_line(int u, int p) { n   int cnt = 0; n   for (int i = head[u]; i >= 0; i = next_edge[i]) { n     int v = point[i]; n     if (v == p) { n       continue; n     } n     if (!line[v]) { n       return false; n     } n     cnt++; n     if (cnt > 2) { n       return false; n     } n   } n   return true; n } n bool good(int u, int p, int lim) { n   int cnt = 0, all = 0; n   for (int i = head[u]; i >= 0; i = next_edge[i]) { n     int v = point[i]; n     if (v == p) { n       continue; n     } n     if (is_line(v, u)) { n       cnt++; n     } else if (!good(v, u, 1)) { n       return false; n     } n     all++; n   } n   if (all - cnt <= lim) { n     return true; n   } n   return false; n } n void dfs_line(int u, int p) { n   int cnt = 0, lst = -1; n   for (int i = head[u]; i >= 0; i = next_edge[i]) { n     int v = point[i]; n     if (v == p) { n       continue; n     } n     cnt++; n     lst = v; n     dfs_line(v, u); n   } n   if (cnt == 0 || (cnt == 1 && line[lst])) { n     line[u] = true; n   } n } n void solve(int test_number) { n   cin >> n; n   memset(head, -1, sizeof(head)); n   for (int i = 0; i < n - 1; i++) { n     int u, v; n     cin >> u >> v; n     --u, --v; n     add_edge(u, v); n     deg[u]++; n     deg[v]++; n   } n   for (int root = 0; root < min(n, 50); root++) { n     memset(line, false, sizeof(line)); n     dfs_line(root, -1); n     if (good(root, -1, 2) || is_line(root, -1)) { n       cout <<  Yes  << endl; n       return; n     } n   } n   cout <<  No  << endl; n } n


#include <bits/stdc++.h> n long long int n, m; n long long int pow(long long int k) { n   long long int a = 1, t = 3; n   for (; k; k /= 2) { n     if (k & 1) a = (a * t) % m; n     t = t * t % m; n   } n   return a; n } n void suru() { scanf( %I64d %I64d , &n, &m); } n void truli() {} n void sutru() { printf( %I64d n , (pow(n) - 1 + m) % m); } n int main() { n   suru(); n   truli(); n   sutru(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = 2e9; n template <typename T> n inline T read() { n   T sum = 0, fl = 1; n   char ch = getchar(); n   for (; !isdigit(ch); ch = getchar()) n     if (ch ==  - ) fl = -1; n   for (; isdigit(ch); ch = getchar()) sum = (sum << 3) + (sum << 1) + ch -  0 ; n   return sum * fl; n } n const int maxn = 1e6 + 5; n int n, mx; n pair<int, int> id; n struct Node { n   int first, second, w; n } o[maxn]; n int li[maxn]; n long long ans; n bool operator<(const Node& a, const Node& b) { return a.second < b.second; } n namespace SEG { n pair<long long, int> tr[maxn << 2]; n long long tag[maxn << 2]; n inline pair<long long, int> Merge(const pair<long long, int>& a, n                                   const pair<long long, int>& b) { n   return a.first > b.first ? a : b; n } n inline void pushdown(int rt) { n   if (!tag[rt]) return; n   tr[(rt << 1)].first += tag[rt]; n   tr[(rt << 1 | 1)].first += tag[rt]; n   tag[(rt << 1)] += tag[rt]; n   tag[(rt << 1 | 1)] += tag[rt]; n   tag[rt] = 0; n } n void build(int rt, int l, int r) { n   if (l == r) return (void)(tr[rt] = make_pair(li[l], l)); n   build((rt << 1), l, ((l + r) >> 1)); n   build((rt << 1 | 1), ((l + r) >> 1) + 1, r); n   tr[rt] = Merge(tr[(rt << 1)], tr[(rt << 1 | 1)]); n } n void update(int rt, int l, int r, int ql, int qr, int v) { n   if (l >= ql && r <= qr) return (void)(tr[rt].first += v, tag[rt] += v); n   pushdown(rt); n   if (((l + r) >> 1) >= ql) update((rt << 1), l, ((l + r) >> 1), ql, qr, v); n   if (((l + r) >> 1) < qr) n     update((rt << 1 | 1), ((l + r) >> 1) + 1, r, ql, qr, v); n   tr[rt] = Merge(tr[(rt << 1)], tr[(rt << 1 | 1)]); n } n pair<long long, int> query(int rt, int l, int r, int ql, int qr) { n   if (l >= ql && r <= qr) return tr[rt]; n   pair<long long, int> ans = make_pair(0, 0); n   pushdown(rt); n   if (((l + r) >> 1) >= ql) n     ans = Merge(ans, query((rt << 1), l, ((l + r) >> 1), ql, qr)); n   if (((l + r) >> 1) < qr) n     ans = Merge(ans, query((rt << 1 | 1), ((l + r) >> 1) + 1, r, ql, qr)); n   return ans; n } n }  // namespace SEG n void Solve() { n   n = read<int>(); n   ans = 0; n   id = make_pair(2e9, 2e9); n   for (int i = 1; i <= n; ++i) n     o[i].first = read<int>(), o[i].second = read<int>(), o[i].w = read<int>(); n   for (int i = 1; i <= n; ++i) li[i] = o[i].first, li[i + n] = o[i].second; n   sort(li + 1, li + n + n + 1); n   mx = unique(li + 1, li + n + n + 1) - li - 1; n   for (int i = 1; i <= n; ++i) { n     int first = min(o[i].first, o[i].second), n         second = max(o[i].first, o[i].second); n     o[i].first = lower_bound(li + 1, li + mx + 1, first) - li; n     o[i].second = lower_bound(li + 1, li + mx + 1, second) - li; n   } n   sort(o + 1, o + n + 1); n   SEG ::build(1, 1, mx); n   for (int i = 1; i <= n;) { n     do { n       SEG ::update(1, 1, mx, 1, o[i].first, o[i].w); n       ++i; n     } while (i <= n && o[i].second == o[i - 1].second); n     pair<long long, int> now = SEG ::query(1, 1, mx, 1, o[i - 1].second); n     int r = o[i - 1].second; n     if (now.first - li[r] > ans && now.second) n       ans = now.first - li[r], id = make_pair(li[now.second], li[r]); n   } n   printf( %lld n%d %d %d %d n , ans, id.first, id.first, id.second, id.second); n } n int main() { n   Solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void solve() { n   string s; n   cin >> s; n   int n = s.length(); n   int r = 0; n   vector<int> fin(3, -1); n   fin[0] = 0; n   vector<int> z(n + 1); n   for (int i = 1; i <= n; i++) { n     r = (r + s[i - 1] -  0 ) % 3; n     z[i] = z[i - 1]; n     if (fin[r] != -1) z[i] = max(z[i], z[fin[r]] + 1); n     fin[r] = i; n   } n   cout << z[n] << endl; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int tst = 1; n   while (tst--) solve(); n   return 0; n } n