#include <bits/stdc++.h> n using namespace std; n int main() { n   long long m = 100000, n = 0, a[1005], b[1005], u, i, j, k = 0, c, d, s = 0, n             r = 0; n   char str1[1005], str2[1005]; n   cin >> c >> d; n   scanf( %s , str1); n   scanf( %s , str2); n   for (i = 0, j = 0;; i++, j++) { n     if (str1[i] != str2[j]) { n       k++; n       a[n] = i + 1; n       n++; n     } n     if (i == c - 1) { n       i = -1; n       s++; n       j = -1; n       j += s; n       if (k < m) { n         m = k; n         for (r = 0; r < k; r++) { n           b[r] = a[r]; n         } n       } n       r = 0; n       k = 0; n       n = 0; n       if (s == (d - c + 1)) break; n     } n   } n   cout << m << endl; n   for (u = 0; u < m; u++) cout << b[u] <<    ; n } n


#include <bits/stdc++.h> n int ab(int x) { n   if (x < 0) { n     x = x * -1; n   } n   return x; n } n int main() { n   int x, y, z, x1, x2, y1, y2; n   scanf( %d %d , &x, &y); n   z = ab(x) + ab(y); n   if (x < 0) { n     x1 = -1 * z; n     x2 = 0; n     if (y < 0) { n       y1 = 0; n       y2 = -1 * z; n     } else { n       y1 = 0; n       y2 = z; n     } n   } else { n     x1 = 0; n     x2 = z; n     if (y < 0) { n       y2 = 0; n       y1 = -1 * z; n     } else { n       y2 = 0; n       y1 = z; n     } n   } n   printf( %d %d %d %d , x1, y1, x2, y2); n } n


#include <bits/stdc++.h> n using namespace std; n char a[310][310]; n int main() { n   int n, m, k; n   cin >> n >> m >> k; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       cin >> a[i][j]; n     } n   } n   int t = min(m, n); n   for (int d = 1; d < t; d++) { n     for (int i = d; i < n - d; i++) { n       for (int j = d; j < m - d; j++) { n         if (a[i][j] ==  *  && a[i][j - d] ==  *  && a[i][j + d] ==  *  && n             a[i - d][j] ==  *  && a[i + d][j] ==  * ) n           k--; n         if (k == 0) { n           cout << i + 1 <<     << j + 1 << endl; n           cout << i + 1 - d <<     << j + 1 << endl; n           cout << i + 1 + d <<     << j + 1 << endl; n           cout << i + 1 <<     << j - d + 1 << endl; n           cout << i + 1 <<     << j + d + 1 << endl; n           return 0; n         } n       } n     } n   } n   cout << -1 << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline int read() { n   int x = 0; n   char ch = getchar(); n   while (!isdigit(ch)) ch = getchar(); n   while (isdigit(ch)) x = x * 10 + ch -  0 , ch = getchar(); n   return x; n } n const int maxn = 100005; n int n; n long long zero = 0, one = 0, z1 = 0, o1 = 0; n char s[maxn], t[maxn]; n int main() { n   n = read(); n   scanf( %s%s , s, t); n   for (int i = 0; i < n; ++i) { n     if (s[i] ==  0 ) { n       zero++; n       if (t[i] ==  0 ) z1++; n     } else { n       one++; n       if (t[i] ==  0 ) o1++; n     } n   } n   printf( %lld n , z1 * one + o1 * zero - z1 * o1); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int dx[] = {0, 0, 1, -1, -1, -1, 1, 1}; n int dy[] = {1, -1, 0, 0, -1, 1, 1, -1}; n char ch[] = { N ,  S ,  E ,  W }; n template <class T> n inline T biton(T n, T pos) { n   return n | ((T)1 << pos); n } n template <class T> n inline T bitoff(T n, T pos) { n   return n & ~((T)1 << pos); n } n template <class T> n inline T ison(T n, T pos) { n   return (bool)(n & ((T)1 << pos)); n } n template <class T> n inline T gcd(T a, T b) { n   while (b) { n     a = a % b; n     swap(a, b); n   } n   return a; n } n template <class T> n inline T bigmod(T p, T e, T m) { n   T ret = 1; n   for (; e > 0; e >>= 1) { n     if (e & 1) ret = (ret * p) % m; n     p = (p * p) % m; n   } n   return (T)ret; n }; n vector<int> primes; n void sieve(int n) { n   vector<int> vec(n + 1); n   vec[0] = vec[1] = 1; n   for (int i = 2; i <= n; i++) { n     if (vec[i] == 0) { n       for (int j = i * 2; j <= n; j = j + i) { n         vec[j] = 1; n       } n     } n   } n   for (int i = 0; i <= n; i++) { n     if (vec[i] == 0) { n       primes.push_back(i); n     } n   } n } n void solve() { n   int n; n   cin >> n; n   vector<int> items(n); n   for (int i = 0; i < n; i++) { n     cin >> items[i]; n   } n   map<int, vector<int>> mp; n   for (int i = 0; i < n; i++) { n     int it = items[i]; n     for (int j = 0; j < primes.size() && primes[j] * primes[j] <= it; j++) { n       int cnt = 0; n       while (it % primes[j] == 0) { n         cnt++; n         it = it / primes[j]; n       } n       if (cnt > 0) { n         mp[primes[j]].push_back(cnt); n       } n     } n     if (it > 1) { n       mp[it].push_back(1); n     } n   } n   long long res = 1; n   for (auto m : mp) { n     sort(m.second.begin(), m.second.end()); n     if (m.second.size() == n - 1) { n       res = res * pow(m.first, m.second[0]); n     } else if (m.second.size() == n) { n       res = res * pow(m.first, m.second[1]); n     } n   } n   cout << res <<   n ; n   ; n } n int main() { n   ios_base::sync_with_stdio(false); n   cout.setf(ios::fixed); n   cout.precision(10); n   cout.tie(nullptr); n   cin.tie(nullptr); n   sieve(2e5); n   int t = 1; n   while (t--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 105; n vector<long long> a, b, v; n string s; n long long n, m, x; n long long killAll() { n   vector<long long> hlp; n   long long i = 0; n   for (long long x : b) { n     while (i < v.size() and v[i] <= x) { n       hlp.push_back(v[i]); n       i++; n     } n     if (i == v.size()) n       return 0; n     else n       i++; n   } n   while (i < v.size()) { n     hlp.push_back(v[i]); n     i++; n   } n   long long ans = 0; n   long long j = hlp.size() - 1; n   for (__typeof(((long long)a.size() - 1)) i = ((long long)a.size() - 1); n        i >= (0); i--) { n     long long x = a[i]; n     if (j < i) return 0; n     if (hlp[j] >= x) n       ans += (hlp[j] - x); n     else n       return 0; n     j--; n   } n   while (j >= 0) { n     ans += hlp[j]; n     j--; n   } n   return ans; n } n long long killExact(long long k) { n   if (k > a.size()) return 0; n   long long i = k - 1; n   long long j = v.size() - 1; n   long long ans = 0; n   while (i >= 0 and j >= 0) { n     if (v[j] >= a[i]) n       ans += (v[j] - a[i]); n     else n       return 0; n     j--; n     i--; n   } n   return ans; n } n long long killFew() { n   long long ans = 0; n   for (long long i = 1; i <= m; i++) ans = max(ans, killExact(i)); n   return ans; n } n long long solve() { n   cin >> n >> m; n   for (__typeof((n)) i = (1); i <= (n); i++) { n     cin >> s >> x; n     if (s ==  ATK ) n       a.push_back(x); n     else n       b.push_back(x); n   } n   for (__typeof((m)) i = (1); i <= (m); i++) { n     cin >> x; n     v.push_back(x); n   } n   sort((v).begin(), (v).end()); n   sort((a).begin(), (a).end()); n   sort((b).begin(), (b).end()); n   cout << max(killAll(), killFew()) <<   n ; n   return 0; n } n signed main() { n   long long t; n   ios_base::sync_with_stdio(false); n   t = 1; n   while (t--) solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   cin >> t; n   while (t--) { n     int n; n     cin >> n; n     int a[n]; n     for (int i = 0; i < n; ++i) { n       cin >> a[i]; n     } n     for (int i = n - 1; i >= 0; --i) { n       int temp = i % 2 != 0 ? -a[i] : a[i]; n       cout << temp <<    ; n     } n     cout << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n bool ckmin(T& a, const T& b) { n   return b < a ? a = b, 1 : 0; n } n template <class T> n bool ckmax(T& a, const T& b) { n   return a < b ? a = b, 1 : 0; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   long long n; n   cin >> n; n   stack<char> st; n   string s; n   cin >> s; n   long long cnt = 0; n   for (int i = 0; i < n; i++) { n     if (s[i] ==  ( ) { n       cnt++; n     } else { n       cnt--; n     } n   } n   if (cnt != 0) { n     cout <<  -1 ; n     return 0; n   } n   long long ans = 0, len = 0, len1 = 0; n   for (int i = 0; i < n; i++) { n     if (s[i] ==  ( ) { n       if (len == 0) { n         st.push( ( ); n       } else { n         len1++; n       } n     } else { n       if (st.size() > 0) { n         st.pop(); n       } else { n         len++; n       } n     } n     if (len == len1) { n       ans += len + len1; n       len = 0; n       len1 = 0; n     } n   } n   cout << ans <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = (int)1e5 + 100; n const int mod = (int)1e9 + 7; n int n, k, a[maxn], c[maxn]; n bool was[maxn]; n vector<int> g[maxn]; n bool check(int pos) { n   memset(was, 0, sizeof(was)); n   int used = 0, unused = pos; n   for (int i = pos; i >= 1; i--) { n     if (was[a[i]] || a[i] == 0) continue; n     if (unused > c[a[i]]) { n       was[a[i]] = 1; n       unused -= 1 + c[a[i]]; n     } n   } n   for (int i = (1); i <= (k); ++i) n     if (!was[i]) return 0; n   return 1; n } n int main() { n   scanf( %d%d , &n, &k); n   vector<int> st; n   for (int i = (1); i <= (n); ++i) { n     scanf( %d , a + i); n     if (a[i] > 0) { n       g[a[i]].push_back(i); n       st.push_back(i); n     } n   } n   for (int i = (1); i <= (k); ++i) scanf( %d , c + i); n   int l = 0, r = (int)st.size() - 1, ans = -1; n   while (l <= r) { n     int m = (l + r) >> 1; n     if (check(st[m])) n       ans = m, r = m - 1; n     else n       l = m + 1; n   } n   if (ans == -1) n     puts( -1 ); n   else n     printf( %d , st[ans]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void solve() { n   string s; n   int first; n   cin >> s >> first; n   string w = string(s.length(),  w ); n   for (int i = 0; i < s.length(); i++) { n     if (s[i] ==  0 ) { n       if (i - first >= 0) w[i - first] =  0 ; n       if (i + first < s.length()) w[i + first] =  0 ; n     } n   } n   for (int i = 0; i < s.length(); i++) { n     if (w[i] ==  w ) w[i] =  1 ; n   } n   string newS =   ; n   for (int i = 0; i < s.length(); i++) { n     bool one = false; n     if (i - first >= 0 && w[i - first] ==  1 ) one = true; n     if (i + first < s.length() && w[i + first] ==  1 ) one = true; n     if (one) { n       newS +=  1 ; n     } else n       newS +=  0 ; n   } n   if (s == newS) { n     cout << w <<   n ; n   } else { n     cout <<  -1 n ; n   } n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(NULL); n   int t = 1; n   cin >> t; n   while (t--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char s[10][10]; n int t, i, j, o, x[2], y[2], ok; n int main() { n   scanf( %d , &t); n   while (t--) { n     for (i = o = 0; i < 8; i++) { n       scanf( %s , s + i); n       for (j = 0; j < 8; j++) n         if (s[i][j] ==  K ) x[o] = i, y[o++] = j; n     } n     if (abs(x[0] - x[1]) % 4 || abs(y[0] - y[1]) % 4) n       puts( NO ); n     else n       puts( YES ); n   } n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( Ofast ) n #pragma GCC target( sse,sse2,sse3,ssse3,sse4 ) n #pragma GCC optimize( unroll-loops ) n using namespace std; n using i64 = int64_t; n using ui64 = uint64_t; n template <class A, class B> n bool smin(A &x, B &&y) { n   if (y < x) { n     x = y; n     return true; n   } n   return false; n } n template <class A, class B> n bool smax(A &x, B &&y) { n   if (x < y) { n     x = y; n     return true; n   } n   return false; n } n int const N = int(1e5 + 10); n int const INF = int(1.2e9); n struct node { n   int min_pos = INF; n   int min_neg = INF; n }; n node a[N]; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(nullptr); n   int q; n   cin >> q; n   while (q--) { n     int t, l, r; n     cin >> t >> l >> r; n     --l, --r; n     if (t == 1) { n       int k; n       cin >> k; n       if (k > 0) { n         for (int i = l; i < r; ++i) { n           smin(a[i].min_pos, k); n         } n       } else { n         k = -k; n         for (int i = l; i < r; ++i) { n           smin(a[i].min_neg, k); n         } n       } n     } else { n       i64 ans = 0; n       for (int i = l; i < r; ++i) { n         int const x = a[i].min_pos; n         int const y = a[i].min_neg; n         if (x != INF && y != INF) { n           ans += x + y; n         } n       } n       cout << ans <<   n ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, ans = 1, bell[1005], c[1005][1005]; n char s[55][1005]; n map<long long, int> w; n long long get(int x) { n   long long res = 0; n   for (int i = 1; i <= n; i++) res = (res << 1) + s[i][x] - 48; n   return res; n } n int main() { n   scanf( %d%d , &m, &n); n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= m; j++) scanf(  %c , &s[i][j]); n   for (int i = 1; i <= m; i++) w[get(i)]++; n   c[0][0] = 1; n   bell[0] = 1; n   for (int i = 1; i <= m; i++) n     for (int j = 0; j <= i; j++) { n       c[i][j] = (c[i - 1][j - 1] + (long long)j * c[i - 1][j]) % 1000000007; n       bell[i] = (bell[i] + c[i][j]) % 1000000007; n     } n   for (int i = 1; i <= m; i++) { n     long long num = get(i); n     ans = (long long)ans * bell[w[num]] % 1000000007; n     w[num] = 0; n   } n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n int N; n int Weight[300005]; n long long SubWeight[300005]; n std::vector<int> ADC[300005]; n inline void AddEdge(int x, int y) { n   ADC[x].push_back(y); n   ADC[y].push_back(x); n } n long long Max; n int Count; n void DFS(bool Step, int Node = 1, int Parent = 0) { n   SubWeight[Node] = Weight[Node]; n   for (auto Vecin : ADC[Node]) n     if (Vecin != Parent) { n       DFS(Step, Vecin, Node); n       SubWeight[Node] += std::max(SubWeight[Vecin], 0LL); n     } n   if (Step) n     Max = std::max(Max, SubWeight[Node]); n   else if (SubWeight[Node] == Max) n     ++Count, SubWeight[Node] = 0; n } n void Citire() { n   scanf( %d , &N); n   for (int i = 1; i <= N; ++i) scanf( %d , &Weight[i]); n   for (int i = 1, x, y; i < N; ++i) scanf( %d%d , &x, &y), AddEdge(x, y); n } n void Rezolvare() { n   Max = -1000000005; n   DFS(1); n   DFS(0); n   printf( %I64d %d , Count * Max, Count); n } n int main() { n   Citire(); n   Rezolvare(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, k; n   cin >> n >> k; n   int id[n]; n   vector<int> ans(k, -1); n   for (int i = 0; i < n; i++) { n     cin >> id[i]; n     if (find(ans.begin(), ans.end(), id[i]) == ans.end()) { n       ans.insert(ans.begin(), id[i]); n       ans.resize(k); n     } n   } n   int count = 0; n   for (int i = 0; i < k; i++) { n     if (ans[i] >= 0) { n       count++; n     } n   } n   cout << count << endl; n   for (int i = 0; i < count; i++) { n     cout << ans[i] <<    ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int tt; n string input; n int main() { n   cin >> tt; n   for (int qq = 1; qq <= tt; qq++) { n     cin >> input; n     int count[250] = {}; n     for (char c : input) count[c -  a ]++; n     int diff = 0; n     for (int i = 0; i < 250; i++) { n       if (count[i] > 0) diff++; n     } n     if (diff == 1) n       cout <<  -1  << endl; n     else { n       sort(input.begin(), input.end()); n       cout << input << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double PI = acos(-1); n const int inf = 0x3f3f3f3f; n const long long inff = 0x3f3f3f3f3f3f3f3f; n int n; n int a[200010]; n int dp[200010]; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   cin >> n; n   for (int i = 1; i <= n; i++) { n     cin >> a[i]; n     a[i] += a[i - 1]; n   } n   dp[n] = a[n]; n   int mx = dp[n]; n   for (int i = n - 1; i >= 2; i--) { n     dp[i] = max(a[i] - mx, mx); n     mx = max(a[i] - mx, mx); n   } n   cout << mx << endl; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n inline T abs(T t) { n   return t < 0 ? -t : t; n } n const long long modn = 1000000007; n inline long long mod(long long x) { return x % modn; } n const int MAXN = 212345; n int n, m, k; n int s[MAXN]; n int main() { n   scanf( %d , &n); n   for (int a = 0; a < n; a++) { n     scanf( %d , s + a); n   } n   int mx = 0; n   for (int i = 0; i <= n; i++) { n     int cnt = 0; n     for (int a = 0; a < n; a++) { n       if (a < i) n         cnt += (s[a] == 0); n       else n         cnt += (s[a] == 1); n     } n     mx = max(mx, cnt); n   } n   printf( %d n , mx); n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 2600; n int n, m; n char s[60][60]; n int addedge[MAXN][MAXN]; n int blocks[60][60]; n int cnt; n int dis[MAXN]; n bool inside(int x, int y) { return x >= 0 && x < n && y >= 0 && y < m; } n vector<int> B; n vector<int> e[MAXN]; n int dx[] = {-1, 0, 1, 0}; n int dy[] = {0, -1, 0, 1}; n int MAXLEN = 0; n int color[MAXN]; n void bfs(int x, int y, char st) { n   ++cnt; n   if (st ==  W ) n     color[cnt] = 1; n   else n     color[cnt] = 0; n   if (st ==  B ) B.push_back(cnt); n   queue<pair<int, int> > q; n   blocks[x][y] = cnt; n   q.push(make_pair(x, y)); n   while (!q.empty()) { n     int lx = q.front().first, ly = q.front().second; n     q.pop(); n     for (int i = 0; i < 4; i++) { n       int nx = lx + dx[i], ny = ly + dy[i]; n       if (inside(nx, ny) && s[nx][ny] == st && !blocks[nx][ny]) { n         blocks[nx][ny] = cnt; n         q.push(make_pair(nx, ny)); n       } n     } n   } n } n void spfa(int st) { n   for (int i = 1; i <= cnt; i++) dis[i] = 0x3F3F3F3F; n   dis[st] = 0; n   queue<int> q; n   q.push(st); n   while (!q.empty()) { n     int u = q.front(); n     q.pop(); n     for (int i = 0; i < e[u].size(); i++) { n       int v = e[u][i]; n       if (dis[v] > dis[u] + 1) { n         dis[v] = dis[u] + 1; n         q.push(v); n       } n     } n   } n   int MX = 0; n   for (int i = 0; i < B.size(); i++) { n     if (dis[B[i]] > MX) MX = dis[B[i]]; n   } n   MAXLEN = min(MAXLEN, MX + 1); n } n int main() { n   scanf( %d%d , &n, &m); n   for (int i = 0; i < n; i++) scanf( %s , s[i]); n   for (int i = 0; i < n; i++) n     for (int j = 0; j < m; j++) n       if (!blocks[i][j]) { n         bfs(i, j, s[i][j]); n       } n   for (int x = 0; x < n; x++) n     for (int y = 0; y < m; y++) { n       for (int i = 0; i < 4; i++) { n         int nx = x + dx[i], ny = y + dy[i]; n         if (inside(nx, ny) && blocks[nx][ny] != blocks[x][y]) { n           { n             int u = blocks[x][y], v = blocks[nx][ny]; n             if (addedge[u][v]) continue; n             e[u].push_back(v); n             addedge[u][v] = true; n           } n         } n       } n     } n   if (B.size() == 0) n     puts( 0 ); n   else { n     MAXLEN = 0x3F3F3F3F; n     for (int i = 1; i <= cnt; i++) spfa(i); n     printf( %d n , MAXLEN); n   } n   return 0; n } n


#include <bits/stdc++.h> n int S(int x) { return x & 1 ? -(x + 1) / 2 : x / 2; } n int main() { n   int q; n   scanf( %d , &q); n   while (q--) { n     int l, r; n     scanf( %d%d , &l, &r); n     printf( %d n , S(r) - S(l - 1)); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   int m; n   cin >> n >> m; n   int a[6]; n   int b[6]; n   for (int i = 1; i < 6; i++) { n     if (n % 5 >= i) { n       a[i] = (n / 5) + 1; n     } else { n       a[i] = n / 5; n     } n   } n   for (int i = 1; i < 6; i++) { n     if (m % 5 >= i) { n       b[i] = (m / 5) + 1; n     } else { n       b[i] = m / 5; n     } n   } n   long long int y = 0; n   y += a[5]; n   y *= b[5]; n   long long int t = 0; n   t += a[4]; n   t *= b[1]; n   long long int s = 0; n   s += a[1]; n   s *= b[4]; n   long long int c = 0; n   c += a[2]; n   c *= b[3]; n   long long int f = 0; n   f += a[3]; n   f *= b[2]; n   long long int k = y + t + s + c + f; n   cout << k; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long gcd(long long a, long long b) { n   if (a < 0) a = -a; n   if (b < 0) b = -b; n   return b == 0 ? a : gcd(b, a % b); n } n template <typename T> n void read(T &res) { n   bool flag = false; n   char ch; n   while (!isdigit(ch = getchar())) (ch ==  - ) && (flag = true); n   for (res = ch - 48; isdigit(ch = getchar()); n        res = (res << 1) + (res << 3) + ch - 48) n     ; n   flag && (res = -res); n } n long long lcm(long long a, long long b) { return a * b / gcd(a, b); } n long long qp(long long a, long long b, long long mod) { n   long long ans = 1; n   if (b == 0) { n     return ans % mod; n   } n   while (b) { n     if (b % 2 == 1) { n       b--; n       ans = ans * a % mod; n     } n     a = a * a % mod; n     b = b / 2; n   } n   return ans % mod; n } n long long qpn(long long a, long long b, long long p) { n   long long ans = 1; n   a %= p; n   while (b) { n     if (b & 1) { n       ans = (ans * a) % p; n       --b; n     } n     a = (a * a) % p; n     b >>= 1; n   } n   return ans % p; n } n char s[100006]; n signed main() { n   long long n, k; n   read(n); n   read(k); n   scanf( %s , s + 1); n   for (long long i = 1; i <= n - 1; i++) { n     if (k == 0) { n       break; n     } n     if (s[i] ==  4  && s[i + 1] ==  7 ) { n       if (i % 2 == 1) { n         s[i + 1] =  4 ; n       } else { n         if (s[i - 1] ==  4 ) { n           if (k % 2 == 1) { n             s[i] =  7 ; n           } else { n             s[i] =  4 ; n           } n           break; n         } else { n           s[i] =  7 ; n         } n       } n       k--; n     } n   } n   printf( %s , s + 1); n } n


#include <bits/stdc++.h> n using namespace std; n void _read(); n const int nax = 2001; n const int inf = 1e9 + 11; n void NO() { n   cout <<  NO n ; n   exit(0); n } n int mat[nax][nax]; n using tp = tuple<int, int, int>; n struct Solution { n   int n; n   bool in_a[nax]; n   vector<vector<pair<int, int>>> adj; n   void inp() { n     cin >> n; n     adj.resize(n + 1); n     for (int i = 1; i <= n; i++) { n       for (int j = 1; j <= n; j++) { n         cin >> mat[i][j]; n         if (i == j && mat[i][j]) NO(); n         if (i != j && !mat[i][j]) NO(); n       } n     } n   } n   void rec() { n     vector<tuple<int, int, int>> vec; n     for (int i = 2; i <= n; i++) { n       vec.emplace_back(mat[i][1], 1, i); n     } n     sort((vec).begin(), (vec).end(), greater<tp>()); n     while (!vec.empty()) { n       auto &[d, u, v] = vec.back(); n       adj[u].emplace_back(v, d); n       adj[v].emplace_back(u, d); n       vec.pop_back(); n       for (int i = 0; i < ((int)(vec).size()); i++) { n         int a, b, c; n         tie(a, b, c) = vec[i]; n         if (mat[v][c] < a) { n           b = v; n           a = mat[v][c]; n           vec[i] = {a, b, c}; n         } n       } n       sort((vec).begin(), (vec).end(), greater<tp>()); n     } n   } n   void bfs(int src) { n     vector<int> dis(n + 1); n     vector<int> q = {src}; n     vector<int> vis(n + 1); n     vis[src] = 1; n     dis[src] = 0; n     for (int i = 0; i < ((int)(q).size()); i++) { n       int u = q[i]; n       for (auto &[v, w] : adj[u]) { n         if (vis[v]) continue; n         vis[v] = 1; n         dis[v] = dis[u] + w; n         q.push_back(v); n       } n     } n     for (int i = 1; i <= n; i++) { n       if (dis[i] != mat[src][i]) NO(); n       if (dis[i] != mat[i][src]) NO(); n     } n   } n   void check() { n     for (int i = 1; i <= n; i++) { n       bfs(i); n     } n   } n   void test() { n     inp(); n     in_a[1] = true; n     rec(); n     check(); n     cout <<  YES n ; n   } n }; n int main() { n   _read(); n   Solution().test(); n   return 0; n }; n void _read() { n   ios_base ::sync_with_stdio(false); n   cin.tie(NULL); n } n


#include <bits/stdc++.h> n using namespace std; n string tsize[] = { S ,  M ,  L ,  XL ,  XXL }; n int a[6]; n int main() { n   int n = 5; n   for (int i = 0; i < 5; i++) { n     cin >> a[i]; n   } n   int m; n   cin >> m; n   for (int k = 0; k < m; k++) { n     string tshirt; n     cin >> tshirt; n     int tcode = 0; n     for (int i = 0; i < n; i++) n       if (tsize[i] == tshirt) tcode = i; n     for (int i = 0; i < n; i++) { n       if (tcode + i < n && a[tcode + i] > 0) { n         cout << tsize[tcode + i] << endl; n         a[tcode + i]--; n         break; n       } n       if (tcode - i >= 0 && a[tcode - i] > 0) { n         cout << tsize[tcode - i] << endl; n         a[tcode - i]--; n         break; n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 300500; n int n, a[N]; n vector<int> v; n int cnt[N]; n vector<int> all; n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; ++i) { n     scanf( %d , &a[i]); n     v.push_back(a[i]); n   } n   sort(v.begin(), v.end()); n   v.resize(unique(v.begin(), v.end()) - v.begin()); n   if (n == (int)v.size()) { n     cout << -1; n     return 0; n   } n   for (int i = 1; i <= n; ++i) { n     a[i] = lower_bound(v.begin(), v.end(), a[i]) - v.begin() + 1; n   } n   vector<pair<int, int> > ans; n   for (int i = 1; i <= n; ++i) { n     int id = -1; n     for (int j = i; j <= n; ++j) { n       if (cnt[a[j]]) { n         id = j; n         break; n       } n       ++cnt[a[j]]; n     } n     if (id == -1) { n       ans[(int)ans.size() - 1].second = n; n       break; n     } else { n       ans.push_back(make_pair(i, id)); n       for (int j = i; j <= id; ++j) cnt[a[j]] = 0; n       i = id; n     } n   } n   printf( %d n , (int)ans.size()); n   for (int i = 0; i < (int)ans.size(); ++i) n     printf( %d %d n , ans[i].first, ans[i].second); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int mod; n unsigned long long work(vector<int> &x) { n   sort(x.begin(), x.end()); n   int n = x.size(); n   int m = x.end() - unique(x.begin(), x.end()); n   unsigned long long ret = 1; n   for (int i = 2; i <= n; i++) { n     unsigned long long tmp = i; n     while (m > 0 && tmp % 2 == 0) tmp /= 2, m--; n     ret = ret * tmp % mod; n   } n   return ret; n } n int main() { n   vector<pair<int, int> > vec; n   int n; n   scanf( %d , &n); n   for (int i = 0; i < n; i++) { n     int a; n     scanf( %d , &a); n     vec.push_back(pair<int, int>(a, i)); n   } n   for (int i = 0; i < n; i++) { n     int b; n     scanf( %d , &b); n     vec.push_back(pair<int, int>(b, i)); n   } n   scanf( %d , &mod); n   sort(vec.begin(), vec.end()); n   unsigned long long ans = 1; n   for (int i = 0; i < n + n;) { n     int nexti = i; n     vector<int> tmp; n     while (nexti < n + n && vec[i].first == vec[nexti].first) { n       tmp.push_back(vec[nexti].second); n       nexti++; n     } n     ans = ans * work(tmp) % mod; n     i = nexti; n   } n   printf( %d n , (int)ans); n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n const int N = 5009; n struct edge { n   int to, nxt; n } e[N * 2]; n int hd[N], tot; n void add(int u, int v) { n   e[++tot] = (edge){v, hd[u]}; n   hd[u] = tot; n } n int n, leaf, lcnt[N], l[N]; n void dfs1(int u, int fa) { n   for (int i = hd[u], v; i; i = e[i].nxt) { n     l[u]++; n     if ((v = e[i].to) == fa) continue; n     dfs1(v, u); n   } n   leaf += (l[u] == 1); n } n int f[N][N][2], g[N][2]; n void dfs2(int u, int fa) { n   if (l[u] == 1) { n     f[u][0][0] = f[u][1][1] = 0; n     lcnt[u] = 1; n     return; n   } n   bool vst = 0; n   for (int i = hd[u], v; i; i = e[i].nxt) { n     if ((v = e[i].to) == fa) continue; n     dfs2(v, u); n     if (!vst) { n       for (int k = 0; k <= lcnt[v]; k++) n         f[u][k][0] = min(f[v][k][0], f[v][k][1] + 1), n         f[u][k][1] = min(f[v][k][0] + 1, f[v][k][1]); n     } else { n       for (int j = 0; j <= min(lcnt[u], leaf / 2); j++) n         for (int k = 0; k < 2; k++) n           g[j][k] = f[u][j][k], f[u][j][k] = 0x3f3f3f3f; n       for (int j = 0; j <= min(lcnt[u], leaf / 2); j++) { n         for (int k = 0; k <= min(lcnt[v], leaf / 2 - j); k++) { n           f[u][j + k][0] = n               min(f[u][j + k][0], g[j][0] + min(f[v][k][0], f[v][k][1] + 1)); n           f[u][j + k][1] = n               min(f[u][j + k][1], g[j][1] + min(f[v][k][1], f[v][k][0] + 1)); n         } n       } n     } n     vst = 1; n     lcnt[u] += lcnt[v]; n   } n } n int main() { n   scanf( %d , &n); n   if (n == 2) return puts( 2 ), 0; n   for (int i = 1, u, v; i < n; i++) scanf( %d%d , &u, &v), add(u, v), add(v, u); n   dfs1(1, 0); n   memset(f, 0x3f, sizeof(f)); n   int root = 1; n   while (l[root] == 1) root++; n   dfs2(root, 0); n   printf( %d , min(f[root][leaf / 2][0], f[root][leaf / 2][1])); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 3e5 + 5; n const int MAXM = 2e6 + 5; n char s[MAXN]; n vector<int> v[MAXN]; n multiset<int> ss[MAXN]; n int trie[MAXN][26], fail[MAXN]; n int pos[MAXN], dat[MAXN], siz[MAXN]; n int fa[MAXN], dep[MAXN], top[MAXN], dfn[MAXN]; n int rev[MAXN], son[MAXN], dfn_cnt, root, tree_cnt, tot; n int ls[MAXM], rs[MAXM], val[MAXM]; n inline int read() { n   int x = 0; n   char ch = getchar(); n   while (!isdigit(ch)) ch = getchar(); n   while (isdigit(ch)) { n     x = x * 10 + ch -  0 ; n     ch = getchar(); n   } n   return x; n } n inline void Max(int &x, int y) { n   if (x < y) x = y; n } n inline void insert(char *s, int id) { n   int len = strlen(s + 1), cur = 0; n   for (int i = 1; i <= len; i++) { n     int ch = s[i] -  a ; n     if (!trie[cur][ch]) trie[cur][ch] = ++tot; n     cur = trie[cur][ch]; n   } n   pos[id] = cur, ss[cur].insert(dat[id]); n } n inline void build(int x = 0) { n   queue<int> q; n   for (int i = 0; i < 26; i++) n     if (trie[0][i]) q.push(trie[0][i]), v[0].push_back(trie[0][i]); n   while (!q.empty()) { n     x = q.front(), q.pop(); n     for (int i = 0; i < 26; i++) { n       int y = trie[x][i]; n       if (y) { n         fail[y] = trie[fail[x]][i]; n         v[fail[y]].push_back(y), q.push(y); n       } else n         trie[x][i] = trie[fail[x]][i]; n     } n   } n } n void dfs_son(int x, int fath) { n   siz[x] = 1; n   fa[x] = fath; n   dep[x] = dep[fath] + 1; n   for (auto y : v[x]) { n     dfs_son(y, x), siz[x] += siz[y]; n     if (son[x] || siz[y] > siz[son[x]]) son[x] = y; n   } n } n void dfs_chain(int x, int tp) { n   top[x] = tp; n   rev[dfn[x] = ++dfn_cnt] = x; n   if (son[x]) dfs_chain(son[x], tp); n   for (auto y : v[x]) { n     if (y == son[x]) continue; n     dfs_chain(y, y); n   } n } n inline void pushup(int cur) { val[cur] = max(val[ls[cur]], val[rs[cur]]); } n void build(int l, int r, int &cur) { n   cur = ++tree_cnt; n   if (l == r) { n     val[cur] = *--ss[rev[l]].end(); n     return; n   } n   int mid = (l + r) >> 1; n   build(l, mid, ls[cur]); n   build(mid + 1, r, rs[cur]); n   pushup(cur); n } n void modify(int l, int r, int pos, int to, int cur) { n   if (l == r) return val[cur] = to, void(); n   int mid = (l + r) >> 1; n   if (pos <= mid) n     modify(l, mid, pos, to, ls[cur]); n   else n     modify(mid + 1, r, pos, to, rs[cur]); n   pushup(cur); n } n int query(int l, int r, int ql, int qr, int cur) { n   if (ql <= l && qr >= r) return val[cur]; n   int mid = (l + r) >> 1; n   if (ql > mid) return query(mid + 1, r, ql, qr, rs[cur]); n   if (qr <= mid) return query(l, mid, ql, qr, ls[cur]); n   return max(query(l, mid, ql, qr, ls[cur]), n              query(mid + 1, r, ql, qr, rs[cur])); n } n inline int query(int x) { n   int ans = -1; n   while (top[x]) { n     Max(ans, query(1, dfn_cnt, dfn[top[x]], dfn[x], root)); n     x = fa[top[x]]; n   } n   return max(ans, query(1, dfn_cnt, 1, dfn[x], root)); n } n inline int query(char *s) { n   int len = strlen(s + 1), cur = 0, ans = -1; n   for (int i = 1; i <= len; i++) { n     int ch = s[i] -  a ; n     cur = trie[cur][ch]; n     Max(ans, query(cur)); n   } n   return ans; n } n int main() { n   int n = read(), m = read(); n   for (int i = 1; i <= n; i++) { n     scanf( %s , s + 1); n     insert(s, i); n   } n   for (int i = 0; i <= tot; i++) ss[i].insert(-1); n   build(); n   dfs_son(0, 0); n   dfs_chain(0, 0); n   build(1, dfn_cnt, root); n   while (m--) { n     int opt = read(); n     if (opt == 1) { n       int id = read(), x = read(); n       ss[pos[id]].erase(ss[pos[id]].find(dat[id])); n       ss[pos[id]].insert(dat[id] = x); n       modify(1, dfn_cnt, dfn[pos[id]], *--ss[pos[id]].end(), root); n     } else { n       scanf( %s , s + 1); n       printf( %d n , query(s)); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m; n char a[60][60], b[60][60]; n int dir[4][2] = {0, 1, 1, 0, -1, 0, 0, -1}; n struct node { n   int x, y, sum; n }; n node ans[2600]; n bool cmp(node a, node b) { return a.sum < b.sum; } n int bfs(int x, int y) { n   queue<node> q; n   node t, next; n   t.x = x; n   t.y = y; n   q.push(t); n   int cnt = 1; n   a[x][y] =  * ; n   while (!q.empty()) { n     t = q.front(); n     q.pop(); n     for (int i = 0; i < 4; i++) { n       int tx = t.x + dir[i][0]; n       int ty = t.y + dir[i][1]; n       if (tx < 0 || ty < 0 || tx >= n || ty >= m) { n         cnt = -1e9; n         continue; n       } n       if (a[tx][ty] ==  * ) continue; n       a[tx][ty] =  * ; n       next.x = tx; n       next.y = ty; n       cnt++; n       q.push(next); n     } n   } n   return cnt; n } n void bfs2(int x, int y) { n   queue<node> q; n   node t, next; n   t.x = x; n   t.y = y; n   q.push(t); n   b[x][y] =  * ; n   while (!q.empty()) { n     t = q.front(); n     q.pop(); n     for (int i = 0; i < 4; i++) { n       int tx = t.x + dir[i][0]; n       int ty = t.y + dir[i][1]; n       if (b[tx][ty] ==  * ) continue; n       b[tx][ty] =  * ; n       next.x = tx; n       next.y = ty; n       q.push(next); n     } n   } n } n int main(void) { n   int i, j, k; n   while (scanf( %d%d%d , &n, &m, &k) == 3) { n     for (i = 0; i < n; i++) { n       scanf( %s , a[i]); n       strcpy(b[i], a[i]); n     } n     int c = 0; n     for (i = 0; i < n; i++) n       for (j = 0; j < m; j++) n         if (a[i][j] ==  . ) { n           int t = bfs(i, j); n           if (t > 0) { n             ans[c].x = i; n             ans[c].y = j; n             ans[c].sum = t; n             c++; n           } n         } n     sort(ans, ans + c, cmp); n     int sum = 0; n     for (i = 0; i < c - k; i++) { n       sum += ans[i].sum; n       bfs2(ans[i].x, ans[i].y); n     } n     printf( %d n , sum); n     for (i = 0; i < n; i++) printf( %s n , b[i]); n   } n } n


#include <bits/stdc++.h> n using namespace std; n struct cell { n   int x, y, cost; n   cell(int i, int j, int k) { n     x = i; n     y = j; n     cost = k; n   } n }; n int main() { n   int n, m, s; n   scanf( %d%d%d , &n, &m, &s); n   s--; n   int t1, t2, t3; n   vector<vector<pair<int, int> > > g(n); n   vector<int> qq(m), w(m), e(m); n   for (int i = 0; i < m; ++i) { n     scanf( %d%d%d , &t1, &t2, &t3); n     t1--; n     t2--; n     qq[i] = t1; n     w[i] = t2; n     e[i] = t3; n     g[t1].push_back(make_pair(t2, t3)); n     g[t2].push_back(make_pair(t1, t3)); n   } n   int l; n   scanf( %d , &l); n   vector<int> d(n, 1000000000); n   d[s] = 0; n   queue<int> q; n   q.push(s); n   d[s] = 0; n   while (!q.empty()) { n     int v = q.front(); n     q.pop(); n     for (unsigned int i = 0; i < g[v].size(); i++) { n       int to = g[v][i].first, len = g[v][i].second; n       if (d[v] + len < d[to]) { n         d[to] = d[v] + len; n         q.push(to); n       } n     } n   } n   int ans = 0; n   for (int i = 0; i < n; ++i) n     if (d[i] == l) ans++; n   for (int i = 0; i < m; ++i) { n     int x = qq[i], y = w[i], z = e[i]; n     int k1 = l - d[x]; n     if (k1 > 0 && k1 != z) { n       int res = min(d[x] + k1, z - k1 + d[y]); n       if (res == l) ans++; n     } n     int k2 = l - d[y]; n     if (k2 > 0 && k2 != z - k1 && k2 != z) { n       int res = min(d[y] + k2, z - k2 + d[x]); n       if (res == l) ans++; n     } n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long cs = 1, t = 15, ar[100], n; n   while (t--) { n     long long ans = 0; n     n = cs; n     map<long long, long long> mp; n     for (long long i = 0; i <= n; i++) { n       for (long long j = 0; j <= n; j++) { n         for (long long k = 0; k <= n; k++) { n           for (long long l = 0; l <= n; l++) { n             if (i + j + k + l == n) { n               long long val = 1 * i + 5 * j + 10 * k + 50 * l; n               if (mp[val] == 0) { n                 mp[val]++; n                 ans++; n                 ar[n] = ans; n               } n             } n           } n         } n       } n     } n     cs++; n   } n   cin >> n; n   if (n <= 14) n     cout << ar[n] << endl; n   else { n     long long an = ar[14] + ((n - 14) * 49); n     cout << an << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void solve() { n   long long n; n   cin >> n; n   vector<string> a(n); n   for (long long i = 0; i < n; ++i) { n     cin >> a[i]; n   } n   unordered_set<char> diagonal, non_diagonal; n   for (long long i = 0; i < n; ++i) { n     for (long long j = 0; j < n; ++j) { n       if (i == j) { n         diagonal.insert(a[i][j]); n       } else if (j == n - i - 1) { n         diagonal.insert(a[i][j]); n       } else { n         non_diagonal.insert(a[i][j]); n       } n     } n   } n   if (diagonal.size() == 1 && non_diagonal.size() == 1) { n     for (char a : diagonal) { n       for (char b : non_diagonal) { n         if (a != b) { n           cout <<  YES ; n         } else { n           cout <<  NO ; n         } n       } n     } n   } else { n     cout <<  NO ; n   } n } n int32_t main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   solve(); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   int t; n   cin >> t; n   while (t--) { n     int n; n     cin >> n; n     int a[n]; n     for (int i = 0; i < n; i++) cin >> a[i]; n     int dif[n]; n     memset(dif, 0, sizeof(dif)); n     int ans = 0; n     for (int i = 1; i < n; i++) { n       int cnt = 1; n       int temp = a[i]; n       while (a[i - 1] > a[i]) { n         dif[i]++; n         a[i] = temp + cnt; n         cnt *= 2; n       } n       if (a[i] > a[i - 1] && dif[i]) { n         dif[i]--; n         a[i] = a[i - 1]; n       } n       ans = max(ans, dif[i]); n     } n     cout << ans <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   string s; n   cin >> s; n   int ans = 0; n   for (int i = 0; i < s.size(); i++) { n     if (((s[i] -  0 ) % 2) == 0) { n       ans = ans + i + 1; n     } n   } n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> v[200005]; n vector<int> par(200005, -1); n vector<int> ran(200005, 1); n int fi(int c) { n   while (1) { n     if (par[c] == -1) n       return c; n     else n       c = par[c]; n   } n } n int main() { n   int n, m; n   cin >> n >> m; n   long long int a[n]; n   long long int val = 10000000000000000; n   int in; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n     if (a[i] < val) { n       val = a[i]; n       in = i; n     } n   } n   vector<pair<long long int, pair<int, int> > > v; n   for (int i = 0; i < n; i++) { n     if (i != in) { n       v.push_back({a[i] + val, {i, in}}); n     } n   } n   long long int sum = 0; n   while (m--) { n     int x, y; n     cin >> x >> y; n     long long int z; n     cin >> z; n     x--, y--; n     v.push_back({z, {x, y}}); n   } n   sort(v.begin(), v.end()); n   int s = v.size(); n   for (int i = 0; i < s; i++) { n     int t1 = v[i].second.first; n     int t2 = v[i].second.second; n     int t3 = fi(t1); n     int t4 = fi(t2); n     if (t3 != t4) { n       if (ran[t3] > ran[t4]) { n         par[t4] = t3; n         ran[t3] += ran[t4]; n       } else { n         par[t3] = t4; n         ran[t4] += ran[t3]; n       } n       sum += v[i].first; n     } n   } n   cout << sum; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int N, n, m, min, max; n   while (cin >> N) { n     n = N % 7; n     if (n <= 2) { n       max = N / 7 * 2 + n; n       min = N / 7 * 2; n     } else if (n == 6) { n       min = N / 7 * 2 + 1; n       max = N / 7 * 2 + 2; n     } else { n       min = N / 7 * 2; n       max = N / 7 * 2 + 2; n     } n     cout << min <<     << max << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, pos, kol; n long long a[1000]; n int main() { n   cin >> n; n   for (long long i = 1; i <= 2 * n; ++i) cin >> a[i]; n   for (long long i = 1; i < 2 * n; ++i) { n     for (long long j = i + 1; j <= 2 * n; ++j) { n       if (a[i] == a[j]) { n         pos = j; n         break; n       } n     } n     while (pos > i + 1) { n       swap(a[pos - 1], a[pos]); n       --pos; n       ++kol; n     } n   } n   cout << kol << endl; n } n


#include <bits/stdc++.h> n using namespace std; n inline long long read() { n   long long x = 0, f = 1; n   char ch = getchar(); n   while (ch <  0  || ch >  9 ) { n     if (ch ==  - ) f = -1; n     ch = getchar(); n   } n   while (ch >=  0  && ch <=  9 ) { n     x = x * 10 + ch -  0 ; n     ch = getchar(); n   } n   return x * f; n } n const long long MAXN = 100005; n long long n, m, o, a[MAXN], b[MAXN], f[2][205][5005]; n int main() { n   n = read(); n   m = read(); n   memset(a, 0, sizeof(a)); n   memset(b, 0, sizeof(b)); n   for (long long i = (1); i <= (n); ++i) { n     long long x = read(); n     while (x % 2 == 0) a[i]++, x /= 2; n     while (x % 5 == 0) b[i]++, x /= 5; n   } n   memset(f, 0, sizeof(f)); n   f[0][0][0] = 1; n   o = 0; n   for (long long i = (1); i <= (n); ++i) { n     o = 1 - o; n     memset(f[o], 0, sizeof(f[o])); n     for (long long j = (0); j <= (i); ++j) n       for (long long k = (0); k <= (j * 25); ++k) { n         f[o][j][k] = max(f[o][j][k], f[1 - o][j][k]); n         if (k >= b[i] && j > 0 && f[1 - o][j - 1][k - b[i]] > 0) n           f[o][j][k] = max(f[o][j][k], f[1 - o][j - 1][k - b[i]] + a[i]); n       } n   } n   long long ans = 0; n   for (long long i = (0); i <= (m * 25); ++i) n     ans = max(ans, min(f[o][m][i] - 1, i)); n   cout << ans << endl; n   return 0; n } n


#include<iostream> n #include<cstring> n #include<cstdio> n #include<climits> n #include<algorithm> n #include<queue> n #include<vector> n #define int long long n #define pii pair<int,int> n #define mp make_pair n #define pb push_back n #define fi first n #define se second n using namespace std; n inline int read(){ n  int f=1,ans=0; char c=getchar(); n  while(c< 0 ||c> 9 ){if(c== - )f=-1;c=getchar();} n  while(c>= 0 &&c<= 9 ){ans=ans*10+c- 0 ;c=getchar();} n  return f*ans; n } n const int MAXN=15; n const int MAXM=101; n struct node{int x,y,w;}tp[MAXM]; bool cmp(node x1,node x2){return x1.w<x2.w;} n int X[MAXN],Y[MAXN],N,M,f[1<<MAXN][MAXM],INF,g[1<<MAXN][MAXM],Dis[1<<MAXN][MAXN],DIS[1<<MAXN][MAXM],Maxn; n signed main(){ n  //freopen( 1.in , r ,stdin); n  N=read(),M=read(); for(int i=0;i<N;i++) X[i]=read(),Y[i]=read(); for(int i=1;i<=M;i++) tp[i].x=read(),tp[i].y=read(),tp[i].w=read(); n  sort(tp+1,tp+M+1,cmp); n  memset(f,127/3,sizeof(f)); memset(g,-127/3,sizeof(g)); memset(Dis,127/3,sizeof(Dis)); memset(DIS,127/3,sizeof(DIS)); INF=f[0][0]; n  for(int S=1;S<(1<<N);S++) for(int u=0;u<N;u++){int Minn=INF; for(int v=0;v<N;v++) if(S&(1<<v)) Minn=min(Minn,abs(X[u]-X[v])+abs(Y[u]-Y[v])); Dis[S][u]=Minn;} n  for(int S=1;S<(1<<N);S++) for(int u=1;u<=M;u++){int Minn=INF; for(int v=0;v<N;v++) if(S&(1<<v)) Minn=min(Minn,abs(X[v]-tp[u].x)+abs(Y[v]-tp[u].y)); DIS[S][u]=Minn;} n  for(int i=0;i<N;i++) f[1<<i][0]=0; for(int i=1;i<=M;i++) g[0][i]=1; n  for(int S=0;S<(1<<N);S++){ n   // f update f n   for(int i=0;i<=M;i++) if(f[S][i]!=INF) for(int j=0;j<N;j++) if(!(S&(1<<j)))  n    f[S|(1<<j)][i]=min(f[S|(1<<j)][i],f[S][i]+Dis[S][j]); n   // f update g n   for(int i=0;i<=M;i++) if(f[S][i]!=INF) for(int j=1;j<=M;j++) if(f[S][i]+DIS[S][j]<=tp[j].w) g[S][j]=max(g[S][j],i+1); n   //g update g n   for(int i=1;i<=M;i++) if(g[S][i]>=0){ n    for(int j=i+1;j<=M;j++) if(tp[i].w+min(abs(tp[i].x-tp[j].x)+abs(tp[i].y-tp[j].y),DIS[S][j])<=tp[j].w)  n     g[S][j]=max(g[S][j],g[S][i]+1); n    Maxn=max(Maxn,g[S][i]); n   } n   //g update f n   for(int i=1;i<=M;i++) if(g[S][i]>=0) for(int j=0;j<N;j++) if(!(S&(1<<j)))  n    f[S|(1<<j)][g[S][i]]=min(f[S|(1<<j)][g[S][i]],tp[i].w+(min(abs(tp[i].x-X[j])+abs(tp[i].y-Y[j]),Dis[S][j]))); n  } n  printf( %lld n ,Maxn); return 0;  n }/* n 3 4 n 1 1 n 2 3 n 5 2 n 2 2 12 n 5 1 4 n 6 2 11 n 3 5 10 n */


#include <bits/stdc++.h> n using namespace std; n int a[51]; n long long c[51][51]; n double dp[51][51][51]; n bool state[51][51][51]; n double cal(int stu, int room, int mval) { n   if (state[stu][room][mval]) return dp[stu][room][mval]; n   state[stu][room][mval] = true; n   double &ret = dp[stu][room][mval]; n   if (!stu) return ret = mval; n   if (!room) return ret = 0.0; n   for (int i = 0; i <= stu; i++) { n     int rval = i / a[room] + (i % a[room] != 0); n     ret += 1.0 * c[i][stu] * pow(1.0 / room, i) * n            pow(1.0 - 1.0 / room, stu - i) * n            cal(stu - i, room - 1, max(mval, rval)); n   } n   return ret; n } n int main() { n   int n, m, i; n   for (i = 1; i <= 50; i++) c[0][i] = c[i][i] = 1; n   for (i = 2; i <= 50; i++) n     for (n = 1; n < i; n++) c[n][i] = c[n - 1][i - 1] + c[n][i - 1]; n   scanf( %d %d , &n, &m); n   for (i = 1; i <= m; i++) scanf( %d , a + i); n   printf( %.20lf , cal(n, m, 0)); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int N, M; n pair<pair<long long, long long>, int> range[200000 - 1]; n pair<long long, int> bridge[200000]; n priority_queue<pair<long long, int>, vector<pair<long long, int> >, n                greater<pair<long long, int> > > n     rends; n int ans[200000 - 1]; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cin >> N >> M; n   long long prevL, prevR; n   cin >> prevL >> prevR; n   for (int i = 0; i < N - 1; i++) { n     long long L, R; n     cin >> L >> R; n     range[i] = {{L - prevR, R - prevL}, i}; n     prevL = L; n     prevR = R; n   } n   for (int i = 0; i < M; i++) { n     cin >> bridge[i].first; n     bridge[i].second = i; n   } n   sort(range, range + N - 1); n   sort(bridge, bridge + M); n   int ind = 0; n   for (int i = 0; i < M; i++) { n     while (ind < N - 1 && bridge[i].first >= range[ind].first.first) { n       rends.push(make_pair(range[ind].first.second, range[ind].second)); n       ind++; n     } n     if (!rends.empty()) { n       pair<long long, int> e = rends.top(); n       rends.pop(); n       if (e.first >= bridge[i].first) { n         ans[e.second] = bridge[i].second + 1; n       } else { n         cout <<  No  << endl; n         return 0; n       } n     } n   } n   if (ind < N - 1 || !rends.empty()) { n     cout <<  No  << endl; n     return 0; n   } n   cout <<  Yes  <<   n ; n   cout << ans[0]; n   for (int i = 1; i < N - 1; i++) { n     cout <<     << ans[i]; n   } n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int s; n   cin >> s; n   while (s) { n     int n, a, b, c, d; n     bool status = true; n     cin >> n >> a >> b >> c >> d; n     int rangem = (a - b) * n, rangeM = (a + b) * n; n     if (((c + d) < rangem) || (c - d) > rangeM) status = false; n     if (status) n       cout <<  Yes  << endl; n     else n       cout <<  No  << endl; n     s--; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long num[200000]; n int sn = 0, asn = 0, save[200000], as[200000], m, n; n struct str { n   int v, x; n   long long l, c; n } str[200000]; n void pre1() { n   scanf( %d , &m); n   int i, j; n   for (i = 0; i < m; i++) { n     scanf( %I64d , &str[i].v); n     if (str[i].v == 1) { n       scanf( %I64d , &str[i].x); n     } else n       scanf( %I64d%I64d , &str[i].l, &str[i].c); n   } n   scanf( %d , &n); n   for (j = 0; j < n; j++) scanf( %I64d , &num[j]); n } n void table() { n   int i, k, j; n   for (i = 0; i < m; i++) { n     if (str[i].v == 1) { n       save[sn++] = str[i].x; n       if (sn == 100000) return; n     } else { n       for (k = 0; k < str[i].c; k++) { n         for (j = 0; j < str[i].l; j++) { n           save[sn++] = save[j]; n           if (sn == 100000) return; n         } n       } n     } n   } n } n void work1() { n   table(); n   int j = 0, i = 0; n   long long now = 0; n   while (i < n) { n     while (j < m) { n       if (str[j].v == 1) { n         now++; n         if (now == num[i]) { n           as[asn++] = str[j].x; n           i++; n           if (i >= n) return; n           j++; n           break; n         } n         j++; n       } else { n         long long nn = now; n         now += str[j].l * str[j].c; n         if (now >= num[i]) { n           while (i < n) { n             if (num[i] <= now) { n               as[asn++] = save[(num[i++] - nn - 1) % str[j].l % 100000]; n               if (i >= n) return; n             } else { n               j++; n               break; n             } n           } n         } else { n           j++; n         } n       } n     } n   } n } n int main() { n   pre1(); n   work1(); n   for (int i = 0; i < asn - 1; i++) printf( %d  , as[i]); n   printf( %d n , as[asn - 1]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void setIO() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n } n const long long N = 3e2 + 0; n const long long M = 5e5 + 5; n const long long L = 2e1 + 1; n const long long inf = 9e17; n const long long mod = 1e9 + 7; n long long xyz = 1; n long long n, k; n long long dp[N][N]; n long long fac[N]; n long long inv[N]; n long long chs[N][N]; n long long pwr[2][N]; n long long bin(long long b, long long e) { n   return b == k ? pwr[0][e] : pwr[1][e]; n } n long long cal(long long b, long long e) { n   if (e == 0) return 1; n   if (e == 1) return b; n   if (e == 2) return b * b % mod; n   return cal(cal(b, e / 2), 2) * cal(b, e % 2) % mod; n } n void prc(long long n, long long k) { n   chs[n][k] = fac[n] * inv[k] % mod * inv[n - k] % mod; n } n void cmp(long long b, long long e) { n   if (b == k - 0) { n     pwr[0][e] = cal(b, e); n   } n   if (b == k - 1) { n     pwr[1][e] = cal(b, e); n   } n } n long long ncr(long long n, long long k) { return chs[n][k]; } n void run() { n   cin >> n >> k; n   fac[0] = 1; n   inv[0] = 1; n   for (long long i = 1; i <= n; i++) { n     fac[i] = fac[i - 1] * i % mod; n     inv[i] = inv[i - 1] * cal(i, mod - 2) % mod; n   } n   for (long long i = 0; i <= n; i++) n     for (long long j = 0; j <= i; j++) prc(i, j); n   for (long long i = 0; i <= n; i++) cmp(k, i), cmp(k - 1, i); n   for (long long i = 1; i <= n; i++) n     dp[1][i] = ncr(n, i) * bin(k - 1, n - i) % mod; n   for (long long i = 2; i <= n; i++) { n     for (long long j = 1; j <= n; j++) { n       dp[i][j] = (bin(k, j) - bin(k - 1, j) + mod) * bin(k - 1, n - j) % mod * n                  dp[i - 1][j] % mod; n       for (long long x = 1; x < j; x++) { n         dp[i][j] += bin(k - 1, n - j) * bin(k, x) % mod * ncr(n - x, j - x) % n                     mod * dp[i - 1][x] % mod; n         dp[i][j] %= mod; n       } n     } n   } n   cout << dp[n][n] << endl; n } n signed main() { n   setIO(); n   while (xyz--) run(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int odd[2000], even[2000]; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int n; n   cin >> n; n   for (int i = 1; i <= n * n; i += 2) { n     odd[(i - 1) / 2] = i; n   } n   for (int i = 2; i <= n * n; i += 2) { n     even[i / 2 - 1] = i; n   } n   int i = 0, k = 0; n   if (n == 3) { n     cout <<  2 1 4 n ; n     cout <<  3 5 7 n ; n     cout <<  6 9 8 n ; n     return 0; n   } n   for (int x = 0; x < n; x++) { n     for (int y = 0; y < n; y++) { n       if ((n - 1) % 4 == 0) { n         if (x == y) { n           cout << odd[i++] <<    ; n           continue; n         } n         if ((x < n / 2 && y > n / 2) || (x > n / 2 && y < n / 2)) { n           cout << odd[i++] <<    ; n           continue; n         } n       } else { n         if (y < n / 2) { n           cout << odd[i++] <<    ; n           continue; n         } n         if ((x == 0 && y < n - 2) || (x == 2 && y >= n - 2)) { n           cout << odd[i++] <<    ; n           continue; n         } n       } n       cout << even[k++] <<    ; n     } n     cout <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 5e3 + 5, mod = 1e9 + 7, mod1 = 998244353, mod2 = 1e9 + 9, n                 inf = 1e18 + 7; n const long long infll = 1e18 + 7; n long long n, k, X, Y, Z; n long long a[(long long)3e5 + 5]; n long long dp[N][N]; n signed main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cin >> n >> k; n   Y = n % k; n   X = k - Y; n   Z = n / k; n   for (long long i = 1; i <= n; i++) { n     cin >> a[i]; n   } n   sort(a + 1, a + 1 + n); n   for (long long i = 0; i <= X; i++) { n     for (long long j = 0; j <= Y; j++) { n       if (i == 0 && j == 0) { n         dp[i][j] = 0; n         continue; n       } n       dp[i][j] = inf; n       long long t = i * Z + j * (Z + 1); n       if (i) { n         dp[i][j] = min(dp[i][j], dp[i - 1][j] + a[t] - a[t - Z + 1]); n       } n       if (j) { n         dp[i][j] = min(dp[i][j], dp[i][j - 1] + a[t] - a[t - Z]); n       } n     } n   } n   cout << dp[X][Y]; n } n


#include <bits/stdc++.h> n using namespace std; n int a[100][100]; n int main() { n   int n, m, z, sum, sum2, ans = 1e9, temp; n   scanf( %d %d %d , &n, &m, &z); n   for (int i = 0; i < n; i++) n     for (int j = 0; j < m; j++) scanf( %d , &a[i][j]); n   if (n > 10) n     for (int i = 0; i < n; i++) { n       temp = 0; n       for (int j = 0; j < n; j++) n         if (i != j) { n           sum = sum2 = 0; n           for (int k = 0; k < m; k++) { n             sum += (a[i][k] == a[j][k]); n             sum2 += (a[i][k] != a[j][k]); n           } n           temp += min(sum, sum2); n         } n       ans = min(ans, temp); n     } n   else { n     for (int i = 0; i < 1 << n; i++) { n       temp = 0; n       for (int j = 0; j < m; j++) { n         sum = sum2 = 0; n         for (int k = 0; k < n; k++) { n           sum += (a[k][j] == ((i >> k) & 1)); n           sum2 += (a[k][j] != ((i >> k) & 1)); n         } n         temp += min(sum, sum2); n       } n       ans = min(ans, temp); n     } n   } n   printf( %d n , ans > z ? -1 : ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void solve() { n   long long n; n   cin >> n; n   vector<long long> arr(n); n   for (long long i = 0; i < n; ++i) { n     cin >> arr[i]; n   } n   sort(arr.begin(), arr.end()); n   long long grp = 0; n   long long ptr = 0; n   unordered_map<long long, long long> mp; n   long long last = 0; n   for (long long i = 0; i < n; ++i) { n     if (arr[i] == 1) { n       grp++; n       continue; n     } else if (ptr > 0) { n       ptr--; n       if (ptr == 0 && arr[i] == arr[i - 1]) { n         grp++; n       } else { n         ptr = arr[i] - (i - last + 1); n       } n     } else { n       ptr = arr[i] - 1; n       last = i; n     } n   } n   cout << grp <<   n ; n } n int32_t main() { n   long long t; n   cin >> t; n   while (t--) { n     solve(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long a[100005]; n void solve() { n   long long n; n   cin >> n; n   for (long long i = 0; i < n; i++) cin >> a[i]; n   sort(a, a + n); n   vector<long long> ans; n   long long st = 0, end = n - 1; n   while (end > st) { n     ans.push_back(a[end]); n     ans.push_back(a[st]); n     st++; n     end--; n   } n   if (st == end) { n     ans.push_back(a[st]); n   } n   reverse((ans).begin(), (ans).end()); n   for (auto i : ans) { n     cout << i <<    ; n   } n } n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long t = 1; n   cin >> t; n   while (t--) { n     solve(); n     cout <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = 1e9 + 7; n int n, v[200000], m[200000]; n long long s[200000]; n pair<int, int> p[200000]; n unordered_map<int, vector<pair<int, long long> > > mp; n bool cmp(pair<int, int> a, pair<int, int> b) { return a.second < b.second; } n int main() { n   scanf( %d , &n); n   for (int i = 0; i < n; i++) scanf( %d%d , &p[i].second, &p[i].first); n   sort(p, p + n, cmp); n   for (int i = 0; i < n; i++) { n     int lo = 0; n     int hi = i - 1; n     int j = -1; n     while (lo <= hi) { n       int mid = (lo + hi) / 2; n       if (p[mid].second <= p[i].first) { n         lo = mid + 1; n         j = mid; n       } else n         hi = mid - 1; n     } n     if (j > -1) { n       v[i] = m[j] + p[i].second - p[i].first; n       int lo = 0; n       int hi = mp[m[j]].size() - 1; n       int k = -1; n       while (lo <= hi) { n         int mid = (lo + hi) / 2; n         if (mp[m[j]][mid].first <= j) { n           k = mid; n           lo = mid + 1; n         } else n           hi = mid - 1; n       } n       if (k > -1) n         s[i] = mp[m[j]][k].second; n       else n         s[i] = 1LL; n       if (mp[v[i]].size() == 0) n         mp[v[i]].push_back({i, s[i]}); n       else n         mp[v[i]].push_back({i, (mp[v[i]].back().second + s[i]) % mod}); n     } else { n       v[i] = p[i].second - p[i].first; n       s[i] = 1LL; n       if (mp[v[i]].size() == 0) n         mp[v[i]].push_back({i, 1LL}); n       else n         mp[v[i]].push_back({i, (mp[v[i]].back().second + 1LL) % mod}); n     } n     m[i] = max(i > 0 ? m[i - 1] : 0, v[i]); n   } n   int h = p[n - 1].second - v[n - 1]; n   int lo = p[n - 1].first; n   long long res = 0; n   for (int i = n - 1; i >= 0; i--) { n     if (p[i].second <= lo) break; n     if (h > p[i].second - v[i]) { n       h = p[i].second - v[i]; n       res = s[i]; n     } else if (h == p[i].second - v[i]) n       res = (res + s[i]) % mod; n     lo = max(lo, p[i].first); n   } n   cout << (res % mod) << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline int in() { n   int32_t x; n   scanf( %d , &x); n   return x; n } n inline long long lin() { n   long long x; n   scanf( %lld , &x); n   return x; n } n inline int mul(int a, int b) { n   long long x = a; n   x *= (long long)b; n   if (x >= 1000000007) x %= 1000000007; n   return x; n } n inline int add(int a, int b) { n   return (a + b) >= 1000000007 ? a + b - 1000000007 : a + b; n } n inline int sub(int a, int b) { n   return (a - b) < 0 ? 1000000007 - b + a : a - b; n } n const int MAX = INT_MAX; n const int MIN = INT_MIN; n char c[100005]; n int y[100005]; n int main() { n   int n; n   cin >> n; n   for (int i = 0; i < n; i++) cin >> c[i]; n   int d = 0, d1 = 0; n   for (int i = 0; i < n; i++) { n     y[i] = c[i] -  0 ; n     if (y[i] == 1) d++; n     if (y[i] == 0) d1++; n   } n   int f = 1; n   int f2 = 0; n   for (int i = 1; i < n; i++) { n     if (y[i - 1] != y[i]) f++; n   } n   for (int i = 0; i < n - 1; i++) { n     if (y[i] == y[i + 1]) { n       f2 = 1; n       break; n     } n   } n   cout << min(f + 2, n); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int ans[] = {0,  4,         10,        20,        35,       56, n                    83, 350 - 234, 400 - 245, 450 - 252, 500 - 256}; n int main() { n   int n; n   cin >> n; n   if (n <= 10) n     cout << ans[n] << endl; n   else n     cout << 1LL * n * 50 - n - 247 << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, last; n struct rec { n   int s, t; n } da[50100]; n bool cmp(rec a, rec b) { n   if (a.s < b.s) return true; n   if (a.s > b.s) return false; n   if (a.t < b.t) return true; n   return false; n } n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) scanf( %d%d , &da[i].s, &da[i].t); n   sort(da + 1, da + n + 1, cmp); n   for (int i = 1; i <= n; i++) n     if (da[i].t >= last) { n       last = da[i].t; n     } else n       last = da[i].s; n   printf( %d , last); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int N; n long long A[10], rem[10]; n int totnum, numv[10], pos[10], tat[10]; n int result = 0x3f3f3f3f; n inline bool compare(const int& i1, const int& i2) { n   return numv[i1] > numv[i2]; n } n void Back(int x) { n   if (x == N + 1) { n     int num0 = 0; n     for (int i = 1; i <= N; ++i) n       if (tat[i] == 0) ++num0; n     int resnow = (num0 >= 2) + N + totnum; n     for (int i = 1; i <= N; ++i) n       if (tat[i] != 0) resnow -= numv[pos[i]]; n     result = min(result, resnow); n     return; n   } n   for (int i = 0; i <= x - 1; ++i) n     if (i == 0 || rem[pos[i]] % A[pos[x]] == 0) { n       rem[pos[i]] /= A[pos[x]]; n       tat[x] = i; n       Back(x + 1); n       rem[pos[i]] *= A[pos[x]]; n     } n } n int main() { n   cin >> N; n   for (int i = 1; i <= N; ++i) { n     cin >> A[i]; n     long long aux = A[i]; n     for (int j = 2; 1LL * j * j <= aux; ++j) n       while (aux % j == 0) { n         ++numv[i]; n         aux /= j; n       } n     if (aux != 1) ++numv[i]; n     totnum += numv[i]; n     if (numv[i] == 1) --totnum; n     pos[i] = i; n     rem[i] = A[i]; n   } n   sort(pos + 1, pos + N + 1, compare); n   Back(1); n   cout << result <<   n ; n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:256000000 ) n using namespace std; n const int SZ = 110; n const int INF = 1000 * 1000 * 1000; n double start, finish; n void prepare(string s) { n   if ((int)s.size() != 0) { n     freopen((s +  .in ).c_str(),  r , stdin); n     freopen((s +  .out ).c_str(),  w , stdout); n   } n } n void startTimer() {} n void stopTimer() {} n int n; n vector<int> g; n vector<vector<int> > p; n void getData() { n   cin >> n; n   g.resize(n); n   for (int i = 0; i < n; ++i) { n     cin >> g[i]; n   } n   p.resize(n); n   for (int i = 0; i < n; ++i) { n     p[i].resize(g[i]); n     for (int j = 0; j < g[i]; ++j) { n       cin >> p[i][j]; n     } n   } n } n void solve() { n   int ans = INF; n   g.assign(n, 0); n   for (int i = 0; i < n; ++i) { n     int cnt = 0; n     for (int j = 0; j < (int)p[i].size(); ++j) { n       cnt += p[i][j] * 5 + 15; n     } n     ans = min(ans, cnt); n   } n   cout << ans << endl; n } n int main() { n   prepare(  ); n   ios::sync_with_stdio(false); n   startTimer(); n   getData(); n   solve(); n   stopTimer(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void RI() {} n template <typename... T> n void RI(int& head, T&... tail) { n   scanf( %d , &head); n   RI(tail...); n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   int n; n   RI(n); n   cout <<  YES  << endl; n   while (n--) { n     int x1, y1, x2, y2; n     RI(x1, y1, x2, y2); n     cout << (((x1 & 1) << 1) + (y1 & 1) + 1) << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool point[2002][2002]; n int N; n int x[3000], y[3000]; n const int offset = 1001; n int main() { n   while (scanf( %d , &N) != EOF) { n     memset(point, 0, sizeof point); n     for (int i = 0; i < N; ++i) { n       scanf( %d%d , &x[i], &y[i]); n       point[x[i] + offset][y[i] + offset] = true; n     } n     int tot = 0; n     for (int i = 0; i < N; ++i) { n       for (int j = i + 1; j < N; ++j) { n         if (((x[i] + x[j]) & 1) == 1 || ((y[i] + y[j]) & 1) == 1) continue; n         int mx = (x[i] + x[j]) >> 1; n         int my = (y[i] + y[j]) >> 1; n         if (point[mx + offset][my + offset]) ++tot; n       } n     } n     printf( %d n , tot); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int head[(1000 + 10)], to[(1000 + 10) * (1000 + 10)], n     pre[(1000 + 10) * (1000 + 10)], tot; n bool vis[(1000 + 10)], color[(1000 + 10)]; n int tag[(1000 + 10)], cc, L[(1000 + 10)], dis[(1000 + 10)]; n int n, m; n void adde(int u, int v) { to[++tot] = v, pre[tot] = head[u], head[u] = tot; } n void dfs(int u) { n   tag[u] = cc; n   for (int i = head[u]; i; i = pre[i]) { n     int v = to[i]; n     if (vis[v]) { n       if (color[u] == color[v]) { n         printf( -1 ); n         exit(0); n       } else n         continue; n     } n     vis[v] = 1, color[v] = 1 ^ color[u]; n     dfs(v); n   } n } n void bfs(int u) { n   memset(dis, 0xff, sizeof(dis)); n   dis[u] = 0; n   int& res = L[tag[u]]; n   queue<int> Q; n   Q.push(u); n   while (!Q.empty()) { n     int v = Q.front(); n     Q.pop(); n     for (int i = head[v]; i; i = pre[i]) { n       int vv = to[i]; n       if (dis[vv] != -1) continue; n       dis[vv] = dis[v] + 1; n       Q.push(vv); n       res = max(res, dis[vv]); n     } n   } n } n int main() { n   scanf( %d %d , &n, &m); n   while (m--) { n     int u, v; n     scanf( %d %d , &u, &v); n     adde(u, v), adde(v, u); n   } n   for (int i = 1; i <= n; i++) { n     if (!vis[i]) { n       vis[i] = 1; n       cc++; n       dfs(i); n     } n   } n   for (int i = 1; i <= n; i++) bfs(i); n   int ans = 0; n   for (int i = 1; i <= cc; i++) ans += L[i]; n   printf( %d , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 1e5 + 5; n const long long INF = 1e18; n const long long LIMIT = 1500000LL * 1500000LL; n vector<int> V; n int ans[MAXN]; n struct node { n   long long x, y, pos; n   long long dis() { return x * x + y * y; } n }; n node p[MAXN]; n bool cmp(node A, node B) { return A.dis() > B.dis(); } n node operator+(const node &A, const node &B) { n   node ans = A; n   ans.x += B.x; n   ans.y += B.y; n   return ans; n } n node operator-(const node &A, const node &B) { n   node ans = A; n   ans.x -= B.x; n   ans.y -= B.y; n   return ans; n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int n; n   cin >> n; n   for (int i = 0; i < n; i++) cin >> p[i].x >> p[i].y, p[i].pos = i; n   node cur{0, 0, 0}; n   for (int i = n - 1; i >= 0; i--) { n     if (cmp(cur - p[i], cur + p[i])) n       cur = cur + p[i], ans[i] = 1; n     else n       cur = cur - p[i], ans[i] = -1; n   } n   for (int i = 0; i < n; i++) cout << ans[i] <<    ; n   return 0; n } n


#include <bits/stdc++.h> n const int N = 120005; n int n, p[N], m; n int stack1[N], top1, stack2[N], top2; n struct query { n   int l, r, id; n } q[N]; n bool operator<(query a, query b) { return a.r < b.r; } n int min[N << 2], num[N << 2], tag0[N << 2], tag1[N << 2]; n long long sum[N << 2], ans[N]; n void build(int o = 1, int l = 1, int r = n) { n   min[o] = l, num[o] = 1; n   if (l == r) return; n   int mid = l + r >> 1; n   build(o << 1, l, mid), build(o << 1 | 1, mid + 1, r); n } n void settag0(int o, int v) { tag0[o] += v, min[o] += v; } n void settag1(int o, int v) { sum[o] += (long long)v * num[o], tag1[o] += v; } n void pushdown(int o) { n   if (tag0[o]) n     settag0(o << 1, tag0[o]), settag0(o << 1 | 1, tag0[o]), tag0[o] = 0; n   if (tag1[o]) { n     if (min[o] == min[o << 1]) settag1(o << 1, tag1[o]); n     if (min[o] == min[o << 1 | 1]) settag1(o << 1 | 1, tag1[o]); n     tag1[o] = 0; n   } n } n void pushup(int o) { n   min[o] = std::min(min[o << 1], min[o << 1 | 1]); n   num[o] = 0; n   if (min[o] == min[o << 1]) num[o] += num[o << 1]; n   if (min[o] == min[o << 1 | 1]) num[o] += num[o << 1 | 1]; n   sum[o] = sum[o << 1] + sum[o << 1 | 1]; n } n void modify(int L, int R, int v, int o = 1, int l = 1, int r = n) { n   if (L <= l && R >= r) return settag0(o, v); n   int mid = l + r >> 1; n   pushdown(o); n   if (L <= mid) modify(L, R, v, o << 1, l, mid); n   if (R > mid) modify(L, R, v, o << 1 | 1, mid + 1, r); n   pushup(o); n } n long long query(int L, int o = 1, int l = 1, int r = n) { n   if (L == l) return sum[o]; n   int mid = l + r >> 1; n   pushdown(o); n   if (L <= mid) n     return query(L, o << 1, l, mid) + sum[o << 1 | 1]; n   else n     return query(L, o << 1 | 1, mid + 1, r); n } n int main() { n   std::ios::sync_with_stdio(0), std::cin.tie(0); n   std::cin >> n; n   for (int i = 1; i <= n; ++i) std::cin >> p[i]; n   std::cin >> m; n   for (int i = 0; i < m; ++i) std::cin >> q[i].l >> q[i].r, q[i].id = i; n   build(), std::sort(q, q + m); n   int t = 0; n   for (int i = 1; i <= n; ++i) { n     while (top1 && p[stack1[top1]] < p[i]) n       modify(stack1[top1 - 1] + 1, stack1[top1], p[i] - p[stack1[top1]]), n           --top1; n     while (top2 && p[stack2[top2]] > p[i]) n       modify(stack2[top2 - 1] + 1, stack2[top2], p[stack2[top2]] - p[i]), n           --top2; n     stack1[++top1] = stack2[++top2] = i, settag1(1, 1); n     while (t < m && q[t].r == i) ans[q[t].id] = query(q[t].l), ++t; n   } n   for (int i = 0; i < m; ++i) std::cout << ans[i] <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline long long isqrt(long long k) { n   long long r = sqrt(k) + 1; n   while (r * r > k) r--; n   return r; n } n inline long long icbrt(long long k) { n   long long r = cbrt(k) + 1; n   while (r * r * r > k) r--; n   return r; n } n inline long long mnz(long long& a, long long b) { return a = (a > b ? b : a); } n inline long long mxz(long long& a, long long b) { return a = (a < b ? b : a); } n inline string toString(long long n) { n   stringstream ss; n   ss << n; n   return ss.str(); n } n double const eps = 1e-6; n long long const Base = 1e9 + 7, oo = 1e17, MAXN = 1e6; n long long A[MAXN + 5]; n long long Solves() { n   long long n, m, k, cnt = 0, ans = 0, x, y, q, c, sum = 0, v, t; n   string s; n   cin >> s; n   for (long long i = 0; i + 1 <= s.length(); i++) n     if (i and s[i] != s[i - 1]) ans = 1; n   if (!ans) return cout << s << endl, 0; n   for (long long i = 0; i + 1 <= s.length(); i++) { n     if (s[i] == ans +  0 ) n       cout << (char)(ans +  0 ); n     else { n       cout << (char)(ans +  0 ); n       cout << s[i]; n       ans = s[i] -  0 ; n     } n     ans ^= 1; n   } n   cout <<    << endl; n   return 0; n } n int main() { n   if (fopen( locin.txt ,  r )) freopen( locin.txt ,  r , stdin); n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long test = 1; n   cin >> test; n   for (long long T = 1; T <= test; T++) { n     Solves(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = (int)1e9; n const int EPS = 1e-6; n const int mod = 1000000007; n const long double PI = 3.14159265359; n const int dx4[4] = {0, 1, 0, -1}; n const int dy4[4] = {-1, 0, 1, 0}; n const int dx8[8] = {-1, -1, -1, 0, 1, 1, 1, 0}; n const int dy8[8] = {-1, 0, 1, 1, 1, 0, -1, -1}; n inline bool grid_inside(int x, int y, int n, int m) { n   return x >= 1 && x <= n && y >= 1 && y <= m; n } n template <typename T> n T lcm(T a, T b) { n   return (a * b) / __gcd(a, b); n } n template <typename T> n T Dis(T x1, T y1, T x2, T y2) { n   return sqrt(((x1 - x2) * (x1 - x2)) + ((y1 - y2) * (y1 - y2))); n } n template <typename T> n T Angle(T x1, T y1, T x2, T y2) { n   return atan((double)(y1 - y2) / (double)(x1 - x2)); n } n inline int Set(int N, int pos) { return N = N | (1 << pos); } n inline int Reset(int N, int pos) { return N = N & ~(1 << pos); } n inline bool Check(int N, int pos) { return (bool)(N & (1 << pos)); } n template <class T, class X> n inline T togglebit(T a, X i) { n   T t = 1; n   return (a ^ (t << i)); n } n bool compare(const pair<int, int>& i, const pair<int, int>& j) { n   return i.first < j.first; n } n int LSOne(long long int n) { return log2(n & -n) + 1; } n int rangeClear(int n, int i, int j) { n   int ones = ~0; n   int a = ones << (j + 1); n   int b = (i << 2) - 1; n   int mask = a | b; n   int ans = n & mask; n   return ans; n } n long long int mul_mod(long long int x, long long int y, long long int mod) { n   long long int i = 0, j = x; n   while (y > 0) { n     if (y & 1) { n       i = (i + j) % mod; n     } n     j = (j + j) % mod; n     y >>= 1; n   } n   return i; n } n long long int fast_power(int a, int x) { n   if (x == 0) n     return 1; n   else if (x == 1) n     return a; n   else { n     long long int R = fast_power(a, x >> 1); n     if (!(x & 1)) n       return R * R; n     else n       return R * a * R; n   } n } n long long int fast_power_unlocked(long long int a, long long int n, n                                   long long int mod) { n   long long int res = 1; n   while (n > 0) { n     if (n & 1) { n       res = mul_mod(res, a, mod); n     } n     a = mul_mod(a, a, mod); n     n = n >> 1; n   } n   return res; n } n long long int modInverse(long long int A, long long int M) { n   return fast_power_unlocked(A, M - 2, M); n } n const int maxn = 1e5 + 5; n vector<int> g[maxn]; n bool ok; n int p[maxn], h[maxn], hp[maxn], vis_cnt[maxn]; n void dfs(int src, int par) { n   vis_cnt[src] = p[src]; n   int thp = 0; n   for (auto x : g[src]) { n     if (x == par) continue; n     dfs(x, src); n     thp += hp[x]; n     vis_cnt[src] += vis_cnt[x]; n   } n   if ((vis_cnt[src] + h[src]) % 2 == 1) ok = false; n   hp[src] = (vis_cnt[src] + h[src]) / 2; n   if (vis_cnt[src] + h[src] < 0) ok = false; n   if (hp[src] >= 0 && (vis_cnt[src] >= hp[src])) { n   } else n     ok = false; n   if (thp > hp[src]) ok = false; n } n void solve() { n   int n, m; n   cin >> n >> m; n   for (int i = 0; i < n; i++) cin >> p[i]; n   for (int i = 0; i < n; i++) cin >> h[i]; n   for (int i = 0; i < n - 1; i++) { n     int x, y; n     cin >> x >> y; n     --x; n     --y; n     g[x].emplace_back(y); n     g[y].emplace_back(x); n   } n   ok = true; n   dfs(0, -1); n   if (ok) n     cout <<  YES ; n   else n     cout <<  NO ; n   for (int i = 0; i < n; i++) g[i].clear(); n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(nullptr); n   ; n   for (auto blockTime = make_pair(chrono::high_resolution_clock::now(), true); n        blockTime.second; n        fprintf(stderr,  %s: %ld ms n ,  Time Taken , n                chrono::duration_cast<chrono::milliseconds>( n                    chrono::high_resolution_clock::now() - blockTime.first) n                    .count()), n             fflush(stderr), blockTime.second = false) { n     int t; n     cin >> t; n     for (int i = 0; i < t; ++i) { n       solve(); n       cout <<   n ; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2005; n int n; n long long dp[N], a[N], ans, k, l[N], r[N]; n int main() { n   scanf( %d%lld , &n, &k); n   for (int i = 1; i <= n; ++i) scanf( %lld%lld%lld , l + i, r + i, a + i); n   int flag = 0; n   for (int i = n; i >= 1; --i) { n     if (r[i] == l[i + 1]) n       dp[i] = max((long long)0, a[i] + dp[i + 1] - (r[i] - l[i]) * k); n     else n       dp[i] = max((long long)0, a[i] - (r[i] - l[i]) * k); n     if (dp[i] > k) { n       flag = 1; n       break; n     } n   } n   if (flag) { n     printf( -1 n ); n     return 0; n   } n   long long tmp = k; n   for (int i = 1; i <= n; ++i) { n     if (tmp < dp[i]) ans += tmp, tmp = k; n     ans += a[i]; n     if (a[i] >= tmp) n       a[i] -= tmp, tmp = k - a[i] % k; n     else n       tmp -= a[i]; n   } n   printf( %lld n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 5e5 + 11; n int n, m; n int cha[N], fa[N]; n int dfn[N], tot, sz[N]; n int U, V; n int head[N], nex[N << 1], to[N << 1], size = 1; n bool vis[N << 1]; n int fr[N]; n int dl[N], zh[N], tp; n void add(int x, int y) { n   to[++size] = y; n   nex[size] = head[x]; n   head[x] = size; n } n void dfs(int u) { n   dfn[u] = ++tot; n   sz[u] = 1; n   for (int i = head[u]; i; i = nex[i]) { n     int v = to[i]; n     if (v == fa[u]) continue; n     if (!dfn[v]) { n       fa[v] = u; n       dfs(v); n       sz[u] += sz[v]; n       cha[u] += cha[v]; n     } else if (dfn[v] < dfn[u]) { n       cha[u]++; n       cha[v]--; n     } n   } n   if (!U && cha[u] > 1) { n     U = u; n     return; n   } n } n void bfs(int x, int id) { n   int hd = 0, tl = 1; n   dl[1] = x; n   for (int i = 1; i <= n; i++) fr[i] = 0; n   fr[x] = -1; n   while (hd < tl) { n     int u = dl[++hd]; n     for (int i = head[u]; i; i = nex[i]) { n       int v = to[i]; n       if (fr[v] != 0 || vis[i]) continue; n       fr[v] = i; n       if (v == V) break; n       dl[++tl] = v; n     } n   } n   for (int v = V; v != U; v = to[fr[v] ^ 1]) { n     zh[++tp] = v; n     vis[fr[v]] = vis[fr[v] ^ 1] = 1; n   } n   zh[++tp] = U; n } n void get_V() { n   for (int u = fa[U]; u; u = fa[u]) { n     int cnt = 0; n     for (int i = head[u]; i; i = nex[i]) { n       int v = to[i]; n       if (dfn[v] >= dfn[U] + (u == fa[U]) && dfn[v] <= dfn[U] + sz[U] - 1) { n         cnt++; n       } n     } n     if (cnt >= 1) { n       V = u; n       return; n     } n   } n } n int main() { n   cin >> n >> m; n   int u, v; n   for (int i = 1; i <= m; i++) { n     scanf( %d%d , &u, &v); n     add(u, v); n     add(v, u); n   } n   for (int i = 1; i <= n; i++) { n     if (!dfn[i]) dfs(i); n   } n   if (!U) { n     puts( NO ); n   } else { n     puts( YES ); n     get_V(); n     for (int i = 1; i <= 3; i++) { n       bfs(U, i); n       printf( %d  , tp); n       while (tp) { n         printf( %d  , zh[tp]); n         tp--; n       } n       puts(  ); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long gcd(long long a, long long b, long long &x, long long &y) { n   if (b == 0) { n     x = 1; n     y = 0; n     return a; n   } n   long long x1, y1; n   long long d = gcd(b, a % b, x1, y1); n   x = y1; n   y = x1 - y1 * (a / b); n   return d; n } n bool find_any_solution(long long a, long long b, long long c, long long &x0, n                        long long &y0, long long &g) { n   g = gcd(abs(a), abs(b), x0, y0); n   if (c % g) { n     return false; n   } n   x0 *= c / g; n   y0 *= c / g; n   if (a < 0) x0 = -x0; n   if (b < 0) y0 = -y0; n   return true; n } n int32_t main() { n   ios_base ::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long a, b, c, x, y, g; n   cin >> a >> b >> c; n   if (!find_any_solution(a, b, -c, x, y, g)) { n     cout << -1 << endl; n   } else { n     cout << x <<     << y << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long int a, b, x1, y, x2, y2; n int main() { n   cin >> a >> b >> x1 >> y >> x2 >> y2; n   long long int da; n   long long int k1 = x1 + y; n   long long int k2 = x2 + y2; n   long long int mi = min(k1, k2); n   long long int ma = max(k1, k2); n   long long int c = mi % (2 * a); n   if (c < 0) c += 2 * a; n   if (c != 0) mi += 2 * a - c; n   c = ma % (2 * a); n   if (c < 0) c += 2 * a; n   ma -= c; n   if (mi > ma) n     da = 0; n   else n     da = (ma - mi) / (2 * a) + 1; n   long long int db; n   long long int t1 = x1 - y; n   long long int t2 = x2 - y2; n   mi = min(t1, t2); n   ma = max(t1, t2); n   c = mi % (2 * b); n   if (c < 0) c += 2 * b; n   if (c != 0) mi += 2 * b - c; n   c = ma % (2 * b); n   if (c < 0) c += 2 * b; n   ma -= c; n   if (mi > ma) n     db = 0; n   else n     db = (ma - mi) / (2 * b) + 1; n   cout << max(da, db); n } n


#include <bits/stdc++.h> n using namespace std; n long long m; n int matrix[2][2] = {{3, 1}, {0, 1}}; n class Matrix { n  public: n   long long c[2][2]; n   Matrix() { n     for (int i = 0; i < 2; i++) n       for (int j = 0; j < 2; j++) c[i][j] = 0; n   } n   void deal() { n     for (int i = 0; i < 2; i++) n       for (int j = 0; j < 2; j++) c[i][j] = matrix[i][j]; n   } n }; n Matrix mul(const Matrix& t1, const Matrix& t2) { n   int i, j, k; n   Matrix t3; n   for (i = 0; i < 2; i++) { n     for (j = 0; j < 2; j++) { n       for (k = 0; k < 2; k++) { n         t3.c[i][j] = (t3.c[i][j] + t1.c[i][k] * t2.c[k][j]) % m; n       } n     } n   } n   return t3; n } n Matrix power(long long n) { n   Matrix a, b; n   b.deal(); n   if (n == 1) n     return b; n   else if (n % 2 == 1) { n     a = (power(n / 2)); n     return mul(mul(a, a), b); n   } else { n     a = (power(n / 2)); n     return mul(a, a); n   } n } n int main() { n   long long n; n   while (cin >> n >> m) { n     if (n == 1) { n       cout << 2 % m << endl; n       continue; n     } else { n       Matrix s = power(n - 1); n       cout << (s.c[0][0] * 2 + s.c[0][1] * 2) % m << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long double pi = acos(-1); n void boos() { n   ios_base ::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n } n void file() { n   freopen( array.in ,  r , stdin); n   freopen( array.out ,  w , stdout); n } n const long long INF = 1e9 + 7; n const int INF1 = 998244353; n const long long LLINF = (long long)1e18; n const int INTmx = (int)1e9; n const int N = 2e3 + 1; n int main() { n   boos(); n   string second; n   cin >> second; n   int kol = 0; n   for (int i = 0; i < second.size(); i++) { n     if (second[i] ==  a ) kol++; n   } n   int n = second.size() - kol; n   if (n % 2) { n     cout <<  :( ; n     return 0; n   } n   int m = n / 2; n   int gg = m + kol; n   string a, b; n   for (int i = 0; i < gg; i++) { n     a += second[i]; n     if (second[i] !=  a ) b += second[i]; n   } n   if (a + b != second) { n     cout <<  :( ; n     return 0; n   } n   cout << a; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m; n int main() { n   scanf( %d%d , &n, &m); n   if (m == 3) { n     if (n == 4) { n       printf( 0 0 n3 0 n0 3 n1 1 n ); n       return 0; n     } n     if (n >= 5) { n       printf( -1 n ); n       return 0; n     } n   } n   for (int i = 0; i < m; i++) printf( %d %d n , i, 100000 + i * i); n   for (int i = 0; i < n - m; i++) printf( %d %d n , i, -100000 - i * i); n   return 0; n } n


#include <iostream> n #include <algorithm> n using namespace std; n  n int INF = 2e9; n  n int pre[200001]; n struct node{ n     int l, r, max, min; n } segtree[800001]; n  n void build(int ind, int l, int r){ n     if (l == r){ n         segtree[ind] = (node){l, r, pre[l], pre[l]}; n     } else { n         build(2*ind, l, (l+r)/2); n         build(2*ind+1, (l+r)/2+1, r); n         segtree[ind] = (node){l, r, max(segtree[2*ind].max, segtree[2*ind+1].max),  n             min(segtree[2*ind].min, segtree[2*ind+1].min)}; n     } n } n  n int find_min(int ind, int l, int r){ n     if (segtree[ind].l >= l && segtree[ind].r <= r) return segtree[ind].min; n     if (segtree[ind].r < l || segtree[ind].l > r) return INF; n     return min(find_min(ind*2, l, r), find_min(ind*2+1,l,r)); n } n  n  n int find_max(int ind, int l, int r){ n     if (segtree[ind].l >= l && segtree[ind].r <= r) return segtree[ind].max; n     if (segtree[ind].r < l || segtree[ind].l > r) return -INF; n     return max(find_max(ind*2, l, r), find_max(ind*2+1,l,r)); n } n int main(){ n     int t; cin >> t; n     for (int i=0;i<t;i++){ n         int n,m; string s; cin >> n >> m; cin >> s; n         pre[0] = 0; n         for (int j=0;j<n;j++){ n             if (s[j] ==  + ) pre[j+1] = pre[j] + 1; else pre[j+1] = pre[j] - 1; n         } n         build(1, 0, n); n         for (int j=0;j<m;j++){ n             int l,r; cin >> l >> r; n             int M = find_max(1, 0, l-1), m = find_min(1, 0, l-1); n             //cout << M <<     << m << endl; n             int subsum = pre[r] - pre[l-1]; n             M = max(M, find_max(1, r+1, n) - subsum); n             m = min(m, find_min(1, r+1, n) - subsum); n             cout << M-m+1 << endl; n         } n          n     } n     n      n }


#include <bits/stdc++.h> n using namespace std; n char b[9], s[9]; n struct tm t; n int k, i; n string m(int i) { n   if (i == 8) return  September ; n   t.tm_mon = i; n   strftime(b, 9,  %B , &t); n   return b; n } n int main() { n   cin >> s >> k; n   for (;; i++) n     if (m(i) == s) return cout << m((i + k) % 12), 0; n } n


#include <bits/stdc++.h> n int main() { n   char ai[105]; n   while (~scanf( %s , ai)) { n     int t = 1, max = 1; n     for (int i = 0; ai[i] !=   0 ; i++) { n       if (ai[i] !=  A  && ai[i] !=  E  && ai[i] !=  I  && ai[i] !=  O  && n           ai[i] !=  U  && ai[i] !=  Y ) { n         t++; n         max = max > t ? max : t; n       } else n         t = 1; n     } n     printf( %d n , max); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 200010; n int mx[maxn << 2], ls[maxn << 2], rs[maxn << 2], lp[maxn << 2], rp[maxn << 2]; n bool col[maxn << 2]; n void make(int rt, int l, int r) { n   lp[rt] = l; n   rp[rt] = r; n   ls[rt] = rs[rt] = r - l + 1; n   mx[rt] = (ls[rt] - 1) / 2; n   col[rt] = true; n } n void build(int l, int r, int rt) { n   make(rt, l, r); n   if (l == r) return; n   int m = l + r >> 1; n   build(l, m, rt << 1); n   build(m + 1, r, rt << 1 | 1); n } n void pushup(int rt, int l, int r) { n   int L = rt << 1, R = L + 1, m = l + r >> 1; n   mx[rt] = mx[L], lp[rt] = lp[L], rp[rt] = rp[L], col[rt] = col[L]; n   if (!col[rt] || (rs[L] + ls[R] - 1) / 2 > mx[rt]) { n     mx[rt] = rs[L] + ls[R] - 1 >> 1; n     lp[rt] = m - rs[L] + 1; n     rp[rt] = m + ls[R]; n     col[rt] = (lp[rt] <= rp[rt]); n   } n   if (!col[rt] || mx[R] > mx[rt]) { n     mx[rt] = mx[R]; n     lp[rt] = lp[R]; n     rp[rt] = rp[R]; n     col[rt] = col[R]; n   } n   ls[rt] = ls[L] + (ls[L] == m - l + 1) * ls[R]; n   rs[rt] = rs[R] + (rs[R] == r - m) * rs[L]; n } n int n, m; n void update(int p, int l = 0, int r = n - 1, int rt = 1) { n   if (l == r) { n     col[rt] ^= 1; n     if (col[rt]) n       make(rt, l, r); n     else n       ls[rt] = rs[rt] = 0; n     mx[rt] = -1; n     return; n   } n   int m = l + r >> 1; n   if (p <= m) n     update(p, l, m, rt << 1); n   else n     update(p, m + 1, r, rt << 1 | 1); n   pushup(rt, l, r); n } n int pos[1000010]; n int main() { n   scanf( %d%d , &n, &m); n   build(0, n - 1, 1); n   int op, id; n   while (m--) { n     scanf( %d%d , &op, &id); n     if (op == 2) { n       update(pos[id]); n     } else { n       int a = ls[1] - 1, b = rs[1] - 1, c = mx[1]; n       if (a >= b && a >= c) { n         printf( 1 n ); n         pos[id] = 0; n         update(0); n       } else if (c >= b) { n         int t = (lp[1] + rp[1]) / 2; n         pos[id] = t; n         update(t); n         printf( %d n , t + 1); n       } else { n         printf( %d n , n); n         pos[id] = n - 1; n         update(n - 1); n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n ifstream in; n ofstream out; n const long long kk = 1000; n const long long ml = kk * kk; n const long long mod = ml * kk + 7; n const long long inf = ml * ml * ml + 7; n long long n, i, j; n vector<long long> m; n vector<pair<long long, long long> > x; n bool viv = false; n map<pair<long long, long long>, bool> was; n pair<long long, string> ans; n string ll_to_str(long long v) { n   string s =   ; n   if (v == 0) return  0 ; n   bool obr = false; n   if (v < 0) obr = true; n   v = abs(v); n   while (v > 0) { n     short e = v % 10; n     s += char( 0  + e); n     v /= 10; n   } n   reverse(s.begin(), s.end()); n   if (obr) s =  -  + s; n   return s; n } n void write(pair<long long, long long> a) { n   if (was[a]) return; n   was[a] = true; n   ans.first++; n   ans.second += ll_to_str(a.first); n   ans.second +=    ; n   ans.second += ll_to_str(a.second); n   ans.second +=   n ; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   x.assign(3, {0, 0}); n   for (long long i = 0; i < 3; i++) cin >> x[i].first >> x[i].second; n   sort(x.begin(), x.end()); n   pair<long long, long long> cur = x[0]; n   while (cur.first < x[1].first) { n     write(cur); n     cur.first++; n   } n   while (cur.second < x[1].second) { n     write(cur); n     cur.second++; n   } n   while (cur.second > x[1].second) { n     write(cur); n     cur.second--; n   } n   while (cur.second < x[2].second) { n     write(cur); n     cur.second++; n   } n   while (cur.second > x[2].second) { n     write(cur); n     cur.second--; n   } n   while (cur.first < x[2].first) { n     write(cur); n     cur.first++; n   } n   write(cur); n   cout << ans.first << endl; n   cout << ans.second << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long x; n   while (cin >> x) { n     long long c = x / 2, t = 0; n     if (x % 2 == 1) c--, t = 1; n     cout << c + t << endl; n     for (int i = 0; i < c; i++) cout <<  2  ; n     for (int i = 0; i < t; i++) cout <<  3  ; n     cout << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long MX = 6e4, C = 10, L = 20; n long long nxt[MX][C], sz; n bitset<170> b[MX]; n unordered_map<bitset<170>, long long> id; n inline long long low_bit(bitset<170> s) { n   for (long long i = 0; i < 10; i++) n     if (s.test(i)) return i; n   return -1; n } n inline long long extend(bitset<170> s) { n   if (id.count(s)) return id[s]; n   id[s] = sz; n   b[sz] = s; n   return sz++; n } n void find_states() { n   bitset<170> s; n   s.reset(); n   s.set(0); n   extend(s); n   for (long long i = 0; i < sz; i++) { n     for (long long j = 0; j < C; j++) { n       bitset<170> s = (b[i] << j | b[i] >> j); n       for (long long k = 0; k <= j; k++) n         if (b[i].test(k)) s.set(j - k); n       nxt[i][j] = extend(s); n     } n   } n } n long long dp[L][MX][C]; n void calc_dps() { n   for (long long state = 0; state < sz; state++) n     for (long long k = 0; k < C; k++) n       dp[0][state][k] = (low_bit(b[state]) <= k); n   for (long long len = 1; len < L; len++) { n     for (long long state = 0; state < sz; state++) { n       for (long long k = 0; k < C; k++) { n         for (long long c = 0; c < C; c++) { n           dp[len][state][k] += dp[len - 1][nxt[state][c]][k]; n         } n       } n     } n   } n } n long long q; n long long digit[L]; n inline long long get(long long lim, long long k) { n   long long cp = lim; n   for (long long i = 0; i < L; i++, cp /= 10) { n     digit[i] = cp % 10; n   } n   long long res = 0; n   long long state = 0; n   for (long long i = L - 1; i >= 0; i--) { n     for (long long j = 0; j < digit[i]; j++) { n       res += dp[i][nxt[state][j]][k]; n     } n     state = nxt[state][digit[i]]; n   } n   return res; n } n int32_t main() { n   ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); n   find_states(); n   calc_dps(); n   cin >> q; n   while (q--) { n     long long l, r, k; n     cin >> l >> r >> k; n     r++; n     cout << get(r, k) - get(l, k) <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 202020, INF = 0x3f3f3f3f; n vector<int> G[MAXN], iG[MAXN]; n int n, m, k, p[MAXN]; n int main() { n   scanf( %d%d , &n, &m); n   for (int i = 1; i <= m; ++i) { n     static int u, v; n     scanf( %d%d , &u, &v); n     G[u].push_back(v); n     iG[v].push_back(u); n   } n   scanf( %d , &k); n   for (int i = 1; i <= k; ++i) scanf( %d , &p[i]); n   vector<int> d(MAXN, INF); n   queue<int> q; n   q.push(p[k]), d[p[k]] = 0; n   while (!q.empty()) { n     int f = q.front(); n     q.pop(); n     for (auto g : iG[f]) n       if (d[g] == INF) { n         d[g] = d[f] + 1; n         q.push(g); n       } n   } n   int mn = 0, mx = 0; n   for (int i = 1; i < k; ++i) { n     if (d[p[i]] <= d[p[i + 1]]) n       mn++, mx++; n     else { n       int deg = 0; n       for (auto g : G[p[i]]) n         if (d[g] == d[p[i]] - 1) deg++; n       mx += deg > 1; n     } n   } n   printf( %d %d n , mn, mx); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long double INF = 1e20; n vector<pair<long double, long double> > vec; n struct Line { n   long double m, c; n   Line(long double x, long double y) { n     m = x; n     c = y; n   } n   long double Get(long double x) { return m * x + c; } n   bool operator<(const Line &other) const { return m < other.m; } n }; n bool Bad(Line &P, Line &C, Line &N) { n   return (P.c - C.c) * 1.0L * (N.m - P.m) > (P.c - N.c) * 1.0L * (C.m - P.m); n } n namespace ConvexHull { n vector<Line> hull; n void Add(long double m, long double c) { n   if (hull.size() > 0 && hull.back().m == m) { n     if (hull.back().c > c) n       hull.pop_back(); n     else n       return; n   } n   hull.push_back(Line(m, c)); n   int sz = hull.size(); n   while (sz > 2 && Bad(hull[sz - 3], hull[sz - 2], hull[sz - 1])) { n     swap(hull[sz - 2], hull[sz - 1]); n     hull.pop_back(); n     sz--; n   } n } n };  // namespace ConvexHull n using namespace ConvexHull; n const int MAX = 3; n struct Matrix { n   int row, col; n   long double m[MAX][MAX]; n   Matrix() { memset(m, 0, sizeof(m)); } n   void Set(int r, int c) { n     row = r; n     col = c; n   } n   Matrix(int r, int c) { n     memset(m, 0, sizeof(m)); n     Set(r, c); n   } n }; n Matrix Multiply(Matrix A, Matrix B) { n   Matrix ans(A.row, B.col); n   for (int i = 0; i < A.row; i++) { n     for (int j = 0; j < B.col; j++) { n       ans.m[i][j] = 0; n       for (int k = 0; k < A.col; k++) { n         ans.m[i][j] += (A.m[i][k] * B.m[k][j]); n       } n     } n   } n   return ans; n } n const int LOG = 35; n Matrix pwr[LOG]; n void preProcess(int idx, long double M) { n   pwr[0].Set(3, 3); n   pwr[0].m[0][0] = 1; n   pwr[0].m[0][1] = -hull[idx].m; n   pwr[0].m[0][2] = -hull[idx].c; n   pwr[0].m[1][0] = 0; n   pwr[0].m[1][1] = 1 + hull[idx].m; n   pwr[0].m[1][2] = M + hull[idx].c; n   pwr[0].m[2][0] = 0; n   pwr[0].m[2][1] = 0; n   pwr[0].m[2][2] = 1; n   for (int i = 1; i < LOG; i++) pwr[i] = Multiply(pwr[i - 1], pwr[i - 1]); n } n pair<long long int, long double> jump(long long int cur, int id, long double x, n                                       long double ans, long long int t) { n   for (int j = LOG - 1; j >= 0; j--) { n     if (cur + (1LL << j) > t) continue; n     long double nx = pwr[j].m[1][1] * x + pwr[j].m[1][2]; n     if (id == hull.size() - 1 || n         hull[id].c - hull[id + 1].c <= (hull[id + 1].m - hull[id].m) * nx) { n       cur += (1LL << j); n       ans = pwr[j].m[0][0] * ans + pwr[j].m[0][1] * x + pwr[j].m[0][2]; n       x = nx; n     } n   } n   return {cur, ans}; n } n int main() { n   int n; n   long long int t; n   scanf( %d %lld , &n, &t); n   long double M = 0; n   int a, b; n   double p; n   for (int i = 1; i <= n; i++) { n     scanf( %d %d %lf , &a, &b, &p); n     vec.push_back({p, a}); n     M = max(M, b * 1.0L * p); n   } n   sort(vec.begin(), vec.end()); n   for (auto v : vec) Add(-v.first, -v.first * v.second); n   int id = 0; n   long double ans = 0; n   int sz = hull.size(); n   for (long long int i = 1; i <= t; i++) { n     long double x = (i - 1) * M - ans; n     while (id + 1 < sz && n            hull[id].c - hull[id + 1].c > (hull[id + 1].m - hull[id].m) * x) n       id++; n     ans -= hull[id].Get(x); n     x = i * M - ans; n     preProcess(id, M); n     auto ret = jump(i, id, x, ans, t); n     i = ret.first; n     ans = ret.second; n   } n   double out = ans; n   printf( %.12f , out); n } n