#include <bits/stdc++.h> n using namespace std; n int N, M, K; n vector<pair<int, char> > r, rr; n int main() { n   scanf( %d %d %d , &N, &M, &K); n   if (4 * N * M - 2 * N - 2 * M < K) return !printf( NO ); n   printf( YES n ); n   int c; n   char d; n   c = M - 1; n   d =  R ; n   r.push_back({min(c, K), d}); n   K -= c; n   if (K <= 0) goto END; n   for (int i = 0; i < M - 1; i++) { n     c = N - 1; n     d =  D ; n     r.push_back({min(c, K), d}); n     K -= c; n     if (K <= 0) goto END; n     c = N - 1; n     d =  U ; n     r.push_back({min(c, K), d}); n     K -= c; n     if (K <= 0) goto END; n     c = 1; n     d =  L ; n     r.push_back({min(c, K), d}); n     K -= c; n     if (K <= 0) goto END; n   } n   for (int i = 0; i < N - 1; i++) { n     c = 1; n     d =  D ; n     r.push_back({min(c, K), d}); n     K -= c; n     if (K <= 0) goto END; n     c = M - 1; n     d =  R ; n     r.push_back({min(c, K), d}); n     K -= c; n     if (K <= 0) goto END; n     c = M - 1; n     d =  L ; n     r.push_back({min(c, K), d}); n     K -= c; n     if (K <= 0) goto END; n   } n   c = N - 1; n   d =  U ; n   r.push_back({min(c, K), d}); n   K -= c; n   if (K <= 0) goto END; n END: n   for (int i = 0; i < r.size(); i++) n     if (r[i].first > 0) rr.push_back(r[i]); n   r = rr; n   printf( %d n , r.size()); n   for (int i = 0; i < r.size(); i++) printf( %d %c n , r[i].first, r[i].second); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1000020; n const int maxx = 1000000; n const int MOd = 1e9 + 7; n const int K = 1000; n const int P = 143; n int loc[maxn]; n class Aho_Corasick { n  public: n   int last, next[maxn][26]; n   short used[maxn][26], step; n   int deg[maxn], dad[maxn]; n   int dep, fail[maxn]; n   char name[maxn]; n   int now[maxn], pre[maxn], E, go[maxn]; n   int beg[maxn], end[maxn], cnt; n   int n, segment[1 << 21]; n   vector<int> w[maxn]; n   void update(int k, int x) { n     for (int l = beg[k] + n - 1, r = end[k] + n - 1; l <= r; n          l = (l + 1) >> 1, r = (r - 1) >> 1) { n       if (l & 1) segment[l] += x; n       if (~r & 1) segment[r] += x; n     } n   } n   inline void add(int i, int j) { n     pre[++E] = now[i]; n     now[i] = E; n     go[E] = j; n   } n   void calc() { n     for (int l = 1; l <= dep; l++) { n       for (int i = now[l]; i; i = pre[i]) { n         int t = fail[dad[go[i]]]; n         char c = name[go[i]]; n         while (t && used[t][c] != step) t = fail[t]; n         if (used[t][c] == step && next[t][c] != go[i]) t = next[t][c]; n         fail[go[i]] = t; n         w[t].push_back(go[i]); n       } n     } n   } n   void dfs(int n) { n     beg[n] = ++cnt; n     for (int i = 0; i < w[n].size(); i++) dfs(w[n][i]); n     end[n] = cnt; n   } n   inline long long find(int k) { n     long long ret = 0; n     for (k += n - 1; k; k >>= 1) ret += segment[k]; n     return ret; n   } n   void build(char *ar, int sz, int id) { n     int p = 0; n     for (int i = 1; i <= sz; i++) { n       char h = ar[i] -  a ; n       if (used[p][h] != step) { n         used[p][h] = step; n         next[p][h] = ++last; n         deg[last] = deg[p] + 1; n         dep = max(dep, (deg[last])); n         dad[last] = p; n         name[last] = h; n         add(deg[last], last); n       } n       p = next[p][h]; n       if (i == sz) loc[id] = p; n     } n   } n   long long get(char *ar, int sz) { n     long long ret = 0; n     int p = 0; n     for (int i = 1; i <= sz; i++) { n       char c = ar[i] -  a ; n       while (p && used[p][c] != step) p = fail[p]; n       if (used[p][c] == step) p = next[p][c]; n       ret += find(beg[p]); n     } n     return ret; n   } n } trie; n int len[maxn]; n bool exist[maxn], used[maxn]; n char ch[maxn]; n int q, a; n char *ar[maxn]; n int main() { n   scanf( %d %d , &q, &a); n   trie.n = 1 << 20; n   trie.step = 1; n   for (int i = 1; i <= a; i++) { n     scanf(  %s , ch); n     exist[i] = 1; n     ar[i] = new char[strlen(ch) + 20]; n     memset(ar[i], 0, sizeof(ar[i])); n     len[i] = strlen(ch); n     for (int j = 1; j <= len[i]; j++) { n       ar[i][j] = ch[j - 1]; n       ch[j - 1] = 0; n     } n     trie.build(ar[i], len[i], i); n   } n   trie.calc(); n   trie.dfs(0); n   for (int i = 1; i <= a; i++) trie.update(loc[i], 1); n   vector<int> w; n   while (q--) { n     char c; n     int x; n     scanf(  %c , &c); n     if (c ==  ? ) { n       scanf(  %s , ch + 1); n       int l = strlen(ch + 1); n       cout << trie.get(ch, l) << endl; n     } n     if (c ==  -  || c ==  + ) { n       scanf( %d , &x); n       if (c ==  -  && exist[x]) trie.update(loc[x], -1), exist[x] = 0; n       if (c ==  +  && !exist[x]) trie.update(loc[x], 1), exist[x] = 1; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n int main(int argc, char const *argv[]) { n   int h1, a1, c1, h2, a2; n   std::cin >> h1 >> a1 >> c1; n   std::cin >> h2 >> a2; n   std::string s =  STRIKE n , h =  HEAL n ; n   int n(0); n   std::string ans; n   while (h2 > 0) { n     n++; n     if (h1 <= a2 && h2 > a1) { n       h1 += c1; n       ans += h; n     } else { n       h2 -= a1; n       ans += s; n     } n     h1 -= a2; n   } n   std::cout << n <<   n ; n   std::cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int t[123]; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   int a, n; n   cin >> n >> a; n   --a; n   for (int i = 0; i < n; ++i) cin >> t[i]; n   int l, r; n   l = r = a; n   int res = 0; n   while (l >= 0 || r < n) { n     if (l >= 0 && r < n) { n       if (t[l] > 0 && t[r] > 0) res += t[l] + t[r]; n     } else if (l >= 0) n       res += t[l]; n     else n       res += t[r]; n     --l, ++r; n   } n   if (t[a] > 0) res--; n   cout << res << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int lsone(int n) { return (n & -n); } n void mult(long long int a[25][25], long long int b[25][25], n           long long int c[25][25], int m, int n, int p) { n   for (int i = 1; i <= m; i++) { n     for (int j = 1; j <= p; j++) { n       c[i][j] = 0; n       for (int k = 1; k <= n; k++) { n         c[i][j] += (a[i][k] * b[k][j]) % 1000000007; n         c[i][j] %= 1000000007; n       } n     } n   } n } n void mat_pow(long long int a[25][25], long long int c[25][25], int n, n              long long int p) { n   if (p == 0) { n     for (int i = 1; i <= n; i++) c[i][i] = 1; n   } else if (p == 1) { n     for (int i = 1; i <= n; i++) { n       for (int j = 1; j <= n; j++) c[i][j] = a[i][j]; n     } n   } else { n     long long int d[25][25]; n     mat_pow(a, d, n, p / 2); n     if (p % 2) { n       long long int e[25][25]; n       mult(d, d, e, n, n, n); n       mult(e, a, c, n, n, n); n     } else { n       mult(d, d, c, n, n, n); n     } n   } n } n long long int pow1(long long int a, long long int b) { n   if (b == 0) n     return 1ll; n   else if (b == 1) n     return a; n   else { n     long long int x = pow1(a, b / 2); n     x *= x; n     x %= 1000000007; n     if (b % 2) { n       x *= a; n       x %= 1000000007; n     } n     return x; n   } n } n int n, ans[110000]; n int s(int y) { n   int ans = 0; n   while (y) { n     y /= 10; n     ans++; n   } n   return ans; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   ; n   ans[1] = 1; n   for (int i = 2; i <= 1e5; i++) { n     ans[i] = ans[i - 1] * 10; n     ans[i] %= 210; n   } n   cin >> n; n   int req = (210 - ans[n]) % 210; n   if (n <= 2) { n     cout << -1 <<   n ; n   } else if (n == 3) n     cout << 210 <<   n ; n   else { n     int numdig = s(req); n     cout << 1; n     for (int i = 0; i < n - numdig - 1; i++) cout << 0; n     cout << req <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2005; n char mp[N][N]; n int deg[N][N]; n int cnt[2], n, m; n int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0}; n string str =  ><v^ , tmp =  <>^v ; n bool check(int x, int y) { return x >= 1 && x <= n && y >= 1 && y <= m; } n int main() { n   ios ::sync_with_stdio(0); n   cin >> n >> m; n   for (int i = (int)(1); i <= (int)(n); ++i) { n     cin >> (mp[i] + 1); n   } n   for (int i = (int)(1); i <= (int)(n); ++i) { n     for (int j = (int)(1); j <= (int)(m); ++j) { n       if (mp[i][j] ==  . ) { n         if ((i + j) & 1) { n           cnt[1]++; n         } else n           cnt[0]++; n       } n     } n   } n   if (cnt[0] != cnt[1]) { n     cout <<  Not unique  << endl; n     return 0; n   } else { n     queue<int> q; n     for (int i = (int)(1); i <= (int)(n); ++i) { n       for (int j = (int)(1); j <= (int)(m); ++j) { n         if (mp[i][j] ==  . ) { n           for (int k = 0; k < (int)(4); ++k) { n             int x = i + dx[k]; n             int y = j + dy[k]; n             if (check(x, y) && mp[x][y] ==  . ) { n               deg[i][j]++; n             } n           } n           if (deg[i][j] == 1) { n             q.push(i); n             q.push(j); n           } n         } n       } n     } n     while (q.size()) { n       int x = q.front(); n       q.pop(); n       int y = q.front(); n       q.pop(); n       for (int k = 0; k < (int)(4); ++k) { n         int tx = x + dx[k]; n         int ty = y + dy[k]; n         if (check(tx, ty) && mp[tx][ty] ==  .  && deg[tx][ty] > 0) { n           mp[x][y] = tmp[k]; n           mp[tx][ty] = str[k]; n           deg[tx][ty] = 0; n           deg[x][y] = 0; n           for (int t = 0; t < (int)(4); ++t) { n             int ax = tx + dx[t]; n             int ay = ty + dy[t]; n             if (check(ax, ay) && mp[ax][ay] ==  .  && deg[ax][ay] > 0) { n               deg[ax][ay]--; n               if (deg[ax][ay] == 1) { n                 q.push(ax); n                 q.push(ay); n               } n             } n           } n           break; n         } n       } n     } n     for (int i = (int)(1); i <= (int)(n); ++i) { n       for (int j = (int)(1); j <= (int)(m); ++j) { n         if (deg[i][j] > 0 || mp[i][j] ==  . ) { n           cout <<  Not unique  << endl; n           return 0; n         } n       } n     } n     for (int i = (int)(1); i <= (int)(n); ++i) { n       cout << mp[i] + 1 << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void flash() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n } n void solve() { n   long long n; n   cin >> n; n   vector<long long> v(n); n   long long sm = 0; n   long long mx = 0; n   for (long long i = 0; i < n; i++) { n     cin >> v[i]; n     sm += v[i]; n     mx = max(mx, v[i]); n   } n   function<long long(long long)> dfs = [&](long long l) -> long long { n     if (l <= 0) return 0; n     return dfs(l - 1); n   }; n   long long val1 = mx; n   long long val2 = sm - mx; n   if (n == 1) { n     cout <<  T  n          <<   n ; n     return; n   } n   long long ok = dfs(n); n   if (ok > 5) { n     cout <<  T  n          <<   n ; n     return; n   } n   ok = dfs(n - 1); n   if (ok > 4) { n     cout <<  HL  n          <<   n ; n     return; n   } n   if (sm - n == 0) { n     if (n % 2) { n       cout <<  T  n            <<   n ; n       return; n     } else { n       cout <<  HL  n            <<   n ; n       return; n     } n   } n   if (val1 > val2) { n     cout <<  T  n          <<   n ; n     return; n   } n   if (sm % 2 == 0) { n     cout <<  HL  n          <<   n ; n     return; n   } else { n     cout <<  T  n          <<   n ; n     return; n   } n } n int32_t main() { n   flash(); n   long long t; n   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 bool SR(int &_x) { return scanf( %d , &_x) == 1; } n bool SR(long long &_x) { return scanf( %lld , &_x) == 1; } n bool SR(double &_x) { return scanf( %lf , &_x) == 1; } n bool SR(char *_s) { return scanf( %s , _s) == 1; } n bool RI() { return true; } n template <typename I, typename... T> n bool RI(I &_x, T &..._tail) { n   return SR(_x) && RI(_tail...); n } n void SP(const int _x) { printf( %d , _x); } n void SP(const long long _x) { printf( %lld , _x); } n void SP(const double _x) { printf( %.16lf , _x); } n void SP(const char *s) { printf( %s , s); } n void PL() { puts(  ); } n template <typename I, typename... T> n void PL(const I _x, const T... _tail) { n   SP(_x); n   if (sizeof...(_tail)) putchar(   ); n   PL(_tail...); n } n const int maxn = 1e6 + 6; n char in[maxn]; n void read() { RI(in); } n deque<char> q; n void build() { n   q = deque<char>(in, in + strlen(in)); n   while (((int)(q).size()) && q[0] ==  F ) q.pop_front(); n } n void sol() { n   int prv = 0, cur = 0, cnt = 0; n   for (int i = 0; i < int(((int)(q).size())); i++) n     if (q[i] ==  F ) { n       swap(prv, cur); n       cur = max(prv + 1, i - (cnt++)); n     } n   PL(cur); n } n int main() { n   read(); n   build(); n   sol(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n int n, a[100005], sta[100005]; n vector<int> V; n int calc(int k) { n   while (k) { n     int d = k % 10; n     k /= 10; n     if (d != 4 && d != 7) return 0; n   } n   return 1; n } n using pii = pair<int, int>; n int tar[100005], to[100005]; n vector<pii> Ans; n void Swap(int first, int second) { n   if (first == second) return; n   to[tar[first]] = second, to[tar[second]] = first; n   swap(tar[second], tar[first]); n   Ans.push_back(pii(first, second)); n   return; n } n int main() { n   V.resize(1100800); n   for (auto first : V) first = rand(); n   scanf( %d , &n); n   int g = 0, pos = -1; n   vector<pii> vec; n   for (int i = 1; i <= n; i++) { n     scanf( %d , &a[i]); n     sta[i] = calc(a[i]); n     g += sta[i]; n     if (sta[i]) pos = i; n     vec.push_back(pii(a[i], i)); n   } n   sort(vec.begin(), vec.end()); n   for (int i = 0; i < vec.size(); i++) { n     tar[vec[i].second] = i + 1; n     to[i + 1] = vec[i].second; n   } n   if (g == 0) { n     bool flag = 0; n     for (int i = 1; i < n; i++) n       if (a[i] > a[i + 1]) flag = 1; n     if (flag) n       puts( -1 ); n     else n       puts( 0 ); n   } else { n     assert(pos > 0); n     for (int i = 1; i <= n; i++) { n       Swap(pos, i); n       pos = i; n       int prv = to[i]; n       Swap(pos, to[i]); n       pos = prv; n     } n     int sz = Ans.size(); n     printf( %d n , sz); n     for (auto first : Ans) { n       printf( %d %d n , first.first, first.second); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct node { n   int lb, rb, l_max, r_max, s_max; n }; n int n, m, l, r, k, offset = 1 << 19, a[300004], z, t; n long long d[600004]; n node trn[1100000]; n int sgn(long long x) { n   if (x > 0) return 1; n   if (x < 0) return -1; n   return 0; n } n void update(int pos) { n   if (pos < 0) return; n   if (d[pos + 1] == 0) { n     trn[pos + offset].l_max = 0; n     trn[pos + offset].r_max = 0; n     trn[pos + offset].s_max = 0; n   } else { n     trn[pos + offset].l_max = 1; n     trn[pos + offset].r_max = 1; n     trn[pos + offset].s_max = 1; n   } n   pos = (pos + offset) >> 1; n   while (pos > 0) { n     z = 2 * pos; n     trn[pos].s_max = max(trn[z].s_max, trn[z + 1].s_max); n     trn[pos].l_max = trn[z].l_max; n     trn[pos].r_max = trn[z + 1].r_max; n     if (sgn(d[trn[z].rb]) >= sgn(d[trn[z + 1].lb])) { n       int len = trn[z].r_max + trn[z + 1].l_max; n       trn[pos].s_max = max(len, trn[pos].s_max); n       if (trn[z].l_max == trn[z].rb - trn[z].lb + 1) n         trn[pos].l_max += trn[z + 1].l_max; n       if (trn[z + 1].r_max == trn[z + 1].rb - trn[z + 1].lb + 1) n         trn[pos].r_max += trn[z].r_max; n     } n     pos = pos >> 1; n   } n } n int readInt() { n   bool mnus = false; n   int result = 0; n   char ch; n   ch = getchar(); n   while (true) { n     if (ch ==  - ) break; n     if (ch >=  0  && ch <=  9 ) break; n     ch = getchar(); n   } n   if (ch ==  - ) n     mnus = true; n   else n     result = ch -  0 ; n   while (true) { n     ch = getchar(); n     if (ch <  0  || ch >  9 ) break; n     result = result * 10 + (ch -  0 ); n   } n   if (mnus) n     return -result; n   else n     return result; n } n int main() { n   std::ios::sync_with_stdio(false); n   n = readInt(); n   for (int i = 1; i <= n; ++i) a[i] = readInt(); n   for (int i = 1; i < n; ++i) d[i] = a[i + 1] - a[i]; n   for (int i = 0; i < offset; ++i) { n     trn[i + offset].lb = i + 1; n     trn[i + offset].rb = i + 1; n     if (d[i + 1] == 0) { n       trn[i + offset].l_max = 0; n       trn[i + offset].r_max = 0; n       trn[i + offset].s_max = 0; n     } else { n       trn[i + offset].l_max = 1; n       trn[i + offset].r_max = 1; n       trn[i + offset].s_max = 1; n     } n   } n   for (int i = offset - 1; i >= 1; --i) { n     t = 2 * i; n     trn[i].lb = trn[t].lb; n     trn[i].rb = trn[t + 1].rb; n     trn[i].s_max = max(trn[t].s_max, trn[t + 1].s_max); n     trn[i].l_max = trn[t].l_max; n     trn[i].r_max = trn[t + 1].r_max; n     if (sgn(d[trn[t].rb]) >= sgn(d[trn[t + 1].lb])) { n       int len = trn[t].r_max + trn[t + 1].l_max; n       trn[i].s_max = max(len, trn[i].s_max); n       if (trn[t].l_max == trn[t].rb - trn[t].lb + 1) n         trn[i].l_max += trn[t + 1].l_max; n       if (trn[t + 1].r_max == trn[t + 1].rb - trn[t + 1].lb + 1) n         trn[i].r_max += trn[t].r_max; n     } n   } n   m = readInt(); n   for (int i = 0; i < m; ++i) { n     l = readInt(); n     r = readInt(); n     k = readInt(); n     d[l - 1] += k; n     d[r] -= k; n     d[0] = 0; n     d[n] = 0; n     update(l - 2); n     update(r - 1); n     cout << trn[1].s_max + 1 << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = 0x7fffffff; n const double eps = 1e-10; n const double pi = acos(-1.0); n inline int read() { n   int x = 0, f = 1; n   char ch; n   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 int N = 2e5 + 10; n int n, a, b, k; n string s; n int mark[N]; n int tot, ans[N]; n int main() { n   n = read(); n   a = read(); n   b = read(); n   k = read(); n   cin >> s; n   for (int i = 1; i <= n; i++) mark[i] = (s[i - 1] -  0 ); n   int cnt = 0; n   for (int i = 1; i <= n; ++i) n     if (mark[i]) n       cnt = 0; n     else { n       if (++cnt == b) { n         ans[++tot] = i; n         cnt = 0; n       } n     } n   tot -= a - 1; n   printf( %d n , tot); n   for (int i = 1; i <= tot; i++) printf( %d  , ans[i]); n   return 0; n } n


#include <bits/stdc++.h> n const long long int mrx = 1e6 + 5, M = 1e9 + 7; n long long int mx = INT_MIN, mn = INT_MAX; n using namespace std; n long long int x1, x2, s, t1, t2, p, d; n long long int poezd, igor; n int main() { n   ios_base::sync_with_stdio(NULL); n   cin.tie(NULL); n   cin >> s >> x1 >> x2; n   cin >> t1 >> t2; n   cin >> p >> d; n   if (t2 <= t1) { n     cout << abs(x1 - x2) * t2; n     return 0; n   } else { n     if (d == 1) { n       if (x1 < x2) { n         if (p == x1) { n           cout << (x2 - x1) * t1; n         } else if (p < x1) { n           cout << min((x2 - x1) * t2, (x2 - p) * t1); n         } else { n           cout << min((x2 - x1) * t2, (s - p) * t1 + s * t1 + x2 * t1); n         } n       } else { n         cout << min((x1 - x2) * t2, (s - p) * t1 + (s - x2) * t1); n       } n     } n     if (d == -1) { n       if (x1 < x2) { n         cout << min((x2 - x1) * t2, p * t1 + x2 * t1); n       } else { n         if (p == x1) { n           cout << (x1 - x2) * t1; n         } else if (p < x1) { n           cout << min((x1 - x2) * t2, p * t1 + s * t1 + (s - x2) * t1); n         } else { n           cout << min((x1 - x2) * t2, (p - x2) * t1); n         } n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cin >> n; n   int sl = 0; n   for (int i = 1; i <= n; ++i) { n     int x, y; n     cin >> x >> y; n     if (x > 0) ++sl; n   } n   if (sl == n || sl == 0 || sl == n - 1 || sl == 1) { n     cout <<  Yes ; n     return 0; n   } n   cout <<  No ; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n void printQueue(T& q) { n   while (!q.empty()) { n     cout << q.top() << endl; n     q.pop(); n   } n } n vector<int> adj[200009]; n vector<pair<int, int> > levels; n bool visited[200009]; n bool cmp(pair<int, int> a, pair<int, int> b) { n   if (a.first == b.first) { n     return a.second < b.second; n   } else { n     return a.first > b.first; n   } n } n void dfs(int s, int level) { n   visited[s] = true; n   levels.push_back(make_pair(level, s)); n   for (int i = 0; i < adj[s].size(); i++) { n     if (visited[adj[s][i]] == false) { n       dfs(adj[s][i], level + 1); n     } n   } n } n int main() { n   int t = 1; n   while (t--) { n     int n, x; n     cin >> n; n     long long dp[n + 1][2]; n     memset(dp, 0, sizeof(dp)); n     for (int i = 1; i < n; i++) { n       cin >> x; n       adj[x].push_back(i); n       adj[i].push_back(x); n     } n     dfs(1, 1); n     for (int j = 0; j < n; j++) { n       cin >> x; n       if (x == 1) { n         dp[j][0] = 1; n         dp[j][1] = 0; n       } else { n         dp[j][0] = 0; n         dp[j][1] = 1; n       } n     } n     sort(levels.begin(), levels.end(), cmp); n     bool visit[n + 1]; n     memset(visit, false, sizeof(visit)); n     int index; n     for (int i = 0; i < levels.size(); i++) { n       visit[levels[i].second] = true; n       index = levels[i].second; n       for (int j = 0; j < adj[index].size(); j++) { n         if (visit[adj[index][j]] == false) { n           dp[adj[index][j]][0] = n               ((dp[index][0] * dp[adj[index][j]][0]) % 1000000007ll) + n               ((dp[index][0] * dp[adj[index][j]][1]) % 1000000007ll) + n               ((dp[index][1] * dp[adj[index][j]][0]) % 1000000007ll); n           dp[adj[index][j]][0] %= 1000000007ll; n           dp[adj[index][j]][1] = n               ((dp[index][0] * dp[adj[index][j]][1]) % 1000000007ll) + n               ((dp[index][1] * dp[adj[index][j]][1]) % 1000000007ll); n           dp[adj[index][j]][1] %= 1000000007ll; n         } n       } n     } n     cout << dp[1][0] << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = 1e9 + 7; n void compute() { n   long long n; n   cin >> n; n   n -= 2; n   string s[n]; n   cin >> s[0]; n   string ans = s[0]; n   for (long long i = 1; i < n; i++) { n     cin >> s[i]; n     if (s[i][0] == ans[ans.size() - 1]) n       ans.push_back(s[i][1]); n     else n       ans += s[i]; n   } n   if (ans.size() != n + 2) ans.push_back( a ); n   cout << ans << endl; n } n signed main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   long long t; n   cin >> t; n   while (t--) { n     compute(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> ans; n int m; n int main() { n   int n, ans = 0; n   string s; n   cin >> n; n   cin >> s; n   for (int i = 0; i < n; i++) n     if (s[i] ==  < ) n       ans++; n     else n       break; n   for (int i = n - 1; i >= 0; i--) n     if (s[i] ==  > ) n       ans++; n     else n       break; n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = 1000 * 1000 * 1000 + 7LL; n const double EXP = 1e-6; n const int MAX = 100001; n int main() { n   int n, k; n   while (cin >> n >> k) { n     int a[10001]; n     for (int i = 1; i <= n; i++) a[i] = 1; n     a[n] = 0; n     while (k--) { n       for (int i = 1; i <= n; i++) { n         if (a[i] + a[i] > n - i) { n           int p = n - i - a[i]; n           int o = n - p; n           a[i] += a[o]; n           cout << o <<    ; n         } else if (a[i] == n - i) n           cout << n <<    ; n         else { n           a[i] += a[i]; n           cout << i <<    ; n         } n       } n       cout << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char s[100010], s1[100010], s2[100010], s3[100010], s11[100010]; n int main() { n   scanf( %s , &s); n   int len; n   len = strlen(s); n   int sum = 0, a = 0; n   for (int i = 0; i < len; i++) { n     sum += s[i] -  0 ; n     if (s[i] ==  0 ) a = 1; n   } n   if (sum % 3 == 0) { n     int cnt = 0; n     for (int i = 0; i < len - 1; i++) { n       if (s[i] !=  0 ) n         break; n       else n         cnt++; n     } n     int j = 0; n     for (int i = cnt; i < len; i++) s1[j++] = s[i]; n     cout << s1 << endl; n   } else { n     int num = sum % 3; n     int cnt1 = -1, cnt2 = -1, cnt3 = -1; n     int t1 = 0, t2 = 0; n     for (int i = len - 1; i >= 0; i--) { n       if ((s[i] -  0 ) % 3 == num) { n         cnt1 = i; n         break; n       } n     } n     if (cnt1 != -1) { n       int j = 0; n       for (int i = 0; i < len; i++) { n         if (i == cnt1) n           continue; n         else n           s1[j++] = s[i]; n       } n       int cnt = 0; n       for (int i = 0; i < j - 1; i++) { n         if (s1[i] !=  0 ) n           break; n         else n           cnt++; n       } n       for (int i = cnt; i < j; i++) s2[t1++] = s1[i]; n     } n     for (int i = len - 1; i >= 1; i--) { n       if ((s[i] -  0 ) % 3 == 0) continue; n       for (int j = i - 1; j >= 0; j--) { n         int cnt = s[i] -  0  + s[j] -  0 ; n         if (cnt % 3 == num) { n           cnt2 = i; n           cnt3 = j; n           break; n         } n       } n       if (cnt2 != -1 && cnt3 != -1) break; n     } n     if (cnt2 != -1 && cnt3 != -1) { n       int j = 0; n       for (int i = 0; i < len; i++) { n         if (i == cnt2 || i == cnt3) continue; n         s11[j++] = s[i]; n       } n       int cnt = 0; n       for (int i = 0; i < j - 1; i++) { n         if (s11[i] !=  0 ) n           break; n         else n           cnt++; n       } n       for (int i = cnt; i < j; i++) s3[t2++] = s11[i]; n     } n     if (!a && t1 == 0 && t2 == 0) n       cout << -1 << endl; n     else if (t1 == 0 && t2 == 0) n       cout << 0 << endl; n     else if (t1 >= t2) n       cout << s2 << endl; n     else n       cout << s3 << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void sprint(string s) { n   for (int i = 0; i < s.size(); ++i) printf( %c , s[i]); n   printf(  n ); n } n int main() { n   int n, k, d; n   cin >> n >> k >> d; n   int a[n]; n   int b[n]; n   for (int i = 0; i < n; ++i) { n     scanf( %d , &a[i]); n     b[i] = 0; n   } n   sort(a, a + n); n   if (k == 1) b[n - 1] = 1; n   for (int i = n - 2; i >= 0; --i) { n     if (n - i < k) continue; n     if (n - i >= k and a[n - 1] - a[i] <= d) n       b[i] = b[i + 1] + 1; n     else if (a[i + k - 1] - a[i] > d) n       b[i] = b[i + 1]; n     else { n       auto it = upper_bound(a, a + n, a[i] + d); n       it--; n       int id = it - a; n       if (id < i + k - 1) { n         b[i] = b[i + 1]; n       } else { n         id++; n         if (id == n - 1) { n           if (b[i + k]) n             b[i] = b[i + 1] + 1; n           else n             b[i] = b[i + 1]; n         } else { n           if (b[i + k] - b[id + 1] > 0) n             b[i] = b[i + 1] + 1; n           else n             b[i] = b[i + 1]; n         } n       } n     } n   } n   for (int i = 0; i < n; ++i) { n   } n   if (n == 1) { n     printf( YEs n ); n   } else if (b[0] - b[1]) n     printf( YES n ); n   else n     printf( NO n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct myQueue { n   stack<pair<long long, long long> > s1, s2; n   int size() { return s1.size() + s2.size(); } n   bool isEmpty() { return size() == 0; } n   long long getMax() { n     if (isEmpty()) { n       return -2e9; n     } n     if (!s1.empty() && !s2.empty()) { n       return max(s1.top().second, s2.top().second); n     } n     if (!s1.empty()) { n       return s1.top().second; n     } n     return s2.top().second; n   } n   void push(long long val) { n     if (s2.empty()) { n       s2.push({val, val}); n     } else { n       s2.push({val, max(val, s2.top().second)}); n     } n   } n   void pop() { n     if (s1.empty()) { n       while (!s2.empty()) { n         if (s1.empty()) { n           s1.push({s2.top().first, s2.top().first}); n         } else { n           s1.push({s2.top().first, max(s2.top().first, s1.top().second)}); n         } n         s2.pop(); n       } n     } n     assert(!s1.empty()); n     s1.pop(); n   } n }; n int main() { n   cin.tie(NULL); n   cout.tie(NULL); n   ios_base::sync_with_stdio(0); n   long long n, k, x; n   cin >> n >> k >> x; n   vector<int> a(n); n   for (long long i = 0; i < n; i++) { n     cin >> a[i]; n   } n   vector<myQueue> q(x + 1); n   for (long long i = 0; i < n; i++) { n     vector<long long> dp(x + 1, -2e9); n     if (i) n       for (long long j = 1; j < x + 1; j++) { n         if (i < k && j == 1) dp[j] = a[i]; n         long long getMax = q[j - 1].getMax(); n         if (getMax != -2e9) dp[j] = max(dp[j], getMax + 1LL * a[i]); n       } n     if (!i) dp[1] = a[0]; n     for (long long j = 1; j < x + 1; j++) { n       if (q[j].size() == k) { n         q[j].pop(); n       } n       q[j].push(dp[j]); n     } n   } n   long long ans = q[x].getMax(); n   if (ans == -2e9) return cout << -1, 0; n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n string s1, s2; n int len1, len2; n int dp[5002][5002]; n int func(int p1, int p2) { n   if ((p1 == len1) || (p2 == len2)) { n     return 0; n   } n   if (dp[p1][p2] != -1) { n     return dp[p1][p2]; n   } n   int ans = 0; n   if (s1[p1] == s2[p2]) { n     ans = (1 + ans + func(p1 + 1, p2 + 1)) % 1000000007; n   } n   ans = (ans + func(p1, p2 + 1)) % 1000000007; n   return dp[p1][p2] = ans; n } n int main() { n   std::ios_base::sync_with_stdio(false); n   ; n   cin >> s1 >> s2; n   len1 = s1.size(); n   len2 = s2.size(); n   memset((dp), -1, sizeof(dp)); n   int ans = 0; n   for (int i = 0; i <= len1 - 1; i++) { n     ans = (ans + func(i, 0)) % 1000000007; n   } n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using namespace std; n int get_type(int a, int b, int c) { n   if (a == 0 && b == 0 && c != 0) return 0; n   if (a == 0 && b == 0 && c == 0) return -1; n   if (a == 0) return 1; n   if (b == 0) return 2; n   return 3; n } n int main() { n   int a1, b1, c1, a2, b2, c2; n   cin >> a1 >> b1 >> c1 >> a2 >> b2 >> c2; n   int t1 = get_type(a1, b1, c1); n   int t2 = get_type(a2, b2, c2); n   if (t1 == 0 || t2 == 0) n     cout <<  0 ; n   else if (t1 == -1 || t2 == -1) n     cout <<  -1 ; n   else if (t1 != t2) n     cout <<  1 ; n   else { n     if (t1 == 1) { n       if (c1 * b2 == c2 * b1) n         cout <<  -1 ; n       else n         cout <<  0 ; n     } else if (t1 == 2) { n       if (c1 * a2 == c2 * a1) n         cout <<  -1 ; n       else n         cout <<  0 ; n     } else { n       if (b1 * a2 != a1 * b2) n         cout <<  1 ; n       else { n         if (c1 * b2 == c2 * b1) n           cout <<  -1 ; n         else n           cout <<  0 ; n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 10; n struct node { n   long long v[10]; n   int tag[10]; n   void init(int x) { n     int y = 1; n     memset(v, 0, sizeof(v)); n     while (x) { n       v[x % 10] += y; n       x /= 10; n       y *= 10; n     } n   } n   void updtag(int* _tag) { n     for (int i = 0; i < 10; i++) tag[i] = _tag[tag[i]]; n   } n   bool havetag() { n     for (int i = 0; i < 10; i++) n       if (tag[i] != i) return 1; n     return 0; n   } n } f[N * 4]; n int a[N]; n int n, q; n int tag[10]; n long long ans; n void upd(int s) { n   for (int i = 0; i < 10; i++) f[s].v[i] = f[s + s].v[i] + f[s + s + 1].v[i]; n } n void build(int l, int r, int s) { n   for (int i = 0; i < 10; i++) f[s].tag[i] = i; n   if (l == r) { n     f[s].init(a[l]); n     return; n   } n   build(l, (l + r) / 2, s + s); n   build((l + r) / 2 + 1, r, s + s + 1); n   upd(s); n } n long long tmp[10] = {0}; n void down(int l, int r, int s) { n   if (!f[s].havetag()) return; n   for (int i = 0; i < 10; i++) tmp[f[s].tag[i]] += f[s].v[i]; n   for (int i = 0; i < 10; i++) f[s].v[i] = tmp[i], tmp[i] = 0; n   if (l != r) f[s + s].updtag(f[s].tag), f[s + s + 1].updtag(f[s].tag); n   for (int i = 0; i < 10; i++) f[s].tag[i] = i; n } n void change(int l, int r, int s, int ll, int rr) { n   down(l, r, s); n   if (r < ll || rr < l) return; n   if (ll <= l && r <= rr) { n     f[s].updtag(tag); n     down(l, r, s); n     return; n   } n   change(l, (l + r) / 2, s + s, ll, rr); n   change((l + r) / 2 + 1, r, s + s + 1, ll, rr); n   upd(s); n } n void get(int l, int r, int s, int ll, int rr) { n   down(l, r, s); n   if (r < ll || rr < l) return; n   if (ll <= l && r <= rr) { n     for (int i = 1; i < 10; i++) ans += f[s].v[i] * i; n     return; n   } n   get(l, (l + r) / 2, s + s, ll, rr); n   get((l + r) / 2 + 1, r, s + s + 1, ll, rr); n } n int main() { n   scanf( %d %d , &n, &q); n   for (int i = 1; i <= n; i++) { n     scanf( %d , &a[i]); n   } n   build(1, n, 1); n   while (q--) { n     int sig, l, r, x, y; n     scanf( %d %d %d , &sig, &l, &r); n     if (sig == 1) { n       scanf( %d %d , &x, &y); n       for (int i = 0; i < 10; i++) tag[i] = i; n       tag[x] = y; n       change(1, n, 1, l, r); n       continue; n     } n     ans = 0; n     get(1, n, 1, l, r); n     printf( %lld n , ans); n   } n   return 0; n } n


#include<bits/stdc++.h> n using namespace std; n  n //#pragma GCC optimize( Ofast,unroll-loops,no-stack-protector ) n //#pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native ) n  n  n #define pb push_back n #define fi first n #define se second n #define ll long long n #define ld long double n #define lll __int128 n #define tp top() n #define fr front() n #define vi vector<int> n #define sz size() n #define rep(i,a,b) for(int i = a; i < b; ++i) n #define mem(a,  b) memset(a,  (b),  sizeof(a)) n #define clr(a) memset(a,  0,  sizeof(a)) n #define sqr(x) ( (x) * (x) ) n #define all(v) v.begin(),  v.end() n  n typedef pair<int, int> pii; n typedef pair<int,pii> pip; n typedef pair<pii,int> ppi; n typedef pair<pii,pii> ppp; n  n  n  n void nonint(){ n  ios_base::sync_with_stdio(0); n  cin.tie(0); n  cout.tie(0); n } n #define N 200020 n int st[4*N],maksl[4*N], maksr[4*N], minsl[4*N], minsr[4*N]; n  n vector<int> vec[N]; n int n; n void merge(int v){ n  st[v] = st[v<<1] + st[v<<1|1]; n  maksr[v] = max(maksr[v<<1], st[v<<1] + maksr[v<<1|1]); n  maksl[v] = max(maksl[v<<1|1], st[v<<1|1] + maksl[v<<1]); n  minsr[v] = min(minsr[v<<1], st[v<<1] + minsr[v<<1|1]); n  minsl[v] = min(minsl[v<<1|1], st[v<<1|1] + minsl[v<<1]); n } n  n void build(int v, int l, int r){ n  if (l==r){ n   st[v] = 1; n   maksl[v] = maksr[v] = minsl[v] = minsr[v] = st[v]; n   return; n  } n  int m = (l+r)>>1; n  build(v<<1,l,m); n  build(v<<1|1,m+1,r); n  merge(v); n } n  n void update(int v, int l, int r, int x, int val){ n  if (l==r){ n   st[v] = val; n   maksl[v] = maksr[v] = minsl[v] = minsr[v] = st[v]; n   return; n  } n  int m = (l+r)>>1; n  if (x <= m) update(v<<1,l,m,x,val); n  else update(v<<1|1,m+1,r,x,val); n  merge(v); n // cout<<v<<   <<maksl[v]<<   <<maksr[v]<<  n ; n } n  n int querysum(int v, int l, int r, int ss, int se){ n  if (ss > se) return 0; n  if (l==ss && r==se) return st[v]; n  int m = (l+r)>>1; n  return querysum(v<<1,l,m,ss,min(se,m)) + querysum(v<<1|1,m+1,r,max(m+1,ss),se); n } n  n int querymaksr(int v, int l, int r, int ss, int se){ n  if (ss > se) return -1e9; n  if (l == ss && r == se) return maksr[v]; n  int m = (l+r)>>1; n  ll res = max(querymaksr(v<<1,l,m,ss,min(m,se)), querysum(1,0,n-1,ss,min(m,se)) + querymaksr(v<<1|1,m+1,r,max(m+1,ss),se)); n  return res; n } n  n int querymaksl(int v, int l, int r, int ss, int se){ n  if (ss > se) return -1e9; n  if (l == ss && r == se) return maksl[v]; n  int m = (l+r)>>1; n  return max(querysum(1,0,n-1,max(m+1,ss),se) + querymaksl(v<<1,l,m,ss,min(m,se)), querymaksl(v<<1|1,m+1,r,max(m+1,ss),se));  n } n  n int queryminsr(int v, int l, int r, int ss, int se){ n  if (ss > se) return 1e9; n  if (l == ss && r == se) return minsr[v]; n  int m = (l+r)>>1; n  return min(queryminsr(v<<1,l,m,ss,min(m,se)), querysum(1,0,n-1,ss,min(m,se)) + queryminsr(v<<1|1,m+1,r,max(m+1,ss),se)); n } n  n int queryminsl(int v, int l, int r, int ss, int se){ n  if (ss > se) return 1e9; n  if (l == ss && r == se) return minsl[v]; n  int m = (l+r)>>1; n  return min(querysum(1,0,n-1,max(m+1,ss),se) + queryminsl(v<<1,l,m,ss,min(m,se)), queryminsl(v<<1|1,m+1,r,max(m+1,ss),se)); n } n  n ll ans[N]; n void solve(){ n  cin>>n; n  rep(i,0,n) { n   int x; cin>>x; n   vec[x].pb(i); n  } n   n  build(1,0,n-1);  n  rep(i,1,n+1){ n   for(auto j : vec[i]){ n    ll ma1 = max(0,querymaksl(1,0,n-1,0,j-1)); n    ll ma2 = max(0,querymaksr(1,0,n-1,j+1,n-1)); n    ll mk = ma1+ma2+1;    n    ans[j] = max(ans[j], mk/2); n   }     n      n   rep(j,0,vec[i].sz) update(1,0,n-1,vec[i][j],-1); n    n   for(auto j : vec[i]){    n    ll mi1 = min(0,queryminsl(1,0,n-1,0,j-1)); n    ll mi2 = min(0,queryminsr(1,0,n-1,j+1,n-1)); n    ll mn = -(mi1+mi2)+1; n    ans[j] = max(ans[j], (mn-1)/2); n   } n  } n  rep(i,0,n) cout<<ans[i]<<   ; n  cout<<  n ; n } n  n int main() n { n  nonint(); n //  freopen( input.txt ,  r , stdin); n //  freopen( output.txt ,  w , stdout); n  int t=1; n // cin>>t; n  while(t--){ n   solve(); n  } n  return 0; n } n  n  n  n  n


#include <bits/stdc++.h> n using namespace std; n vector<pair<int, pair<int, int> > > horz, vert, tmp; n set<int> y_com; n map<int, int> y_map; n void cleanup(vector<pair<int, pair<int, int> > >& v) { n   sort(v.begin(), v.end()); n   for (auto it = v.begin(); it != v.end();) { n     if (it != v.begin()) { n       auto prev = it; n       prev--; n       if (prev->first == it->first && n           prev->second.second >= it->second.first - 1) { n         prev->second.second = max(it->second.second, prev->second.second); n         it = v.erase(it); n       } else n         it++; n     } else n       it++; n   } n } n int BIT[211111]; n void update(int pos, int val) { n   while (pos < 211111) { n     BIT[pos] += val; n     pos += (pos & (-pos)); n   } n } n int get(int pos) { n   int ans = 0; n   while (pos > 0) { n     ans += BIT[pos]; n     pos -= (pos & (-pos)); n   } n   return ans; n } n int main() { n   ios_base::sync_with_stdio(false); n   int n; n   cin >> n; n   long long ans = 0; n   for (int i = 0; i < n; i++) { n     int x[2], y[2]; n     cin >> x[0] >> y[0] >> x[1] >> y[1]; n     x[0] += 1000000001; n     x[1] += 1000000001; n     y[0] += 1000000001; n     y[1] += 1000000001; n     if (y[0] == y[1]) { n       horz.push_back( n           make_pair(y[0], make_pair(min(x[0], x[1]), max(x[0], x[1])))); n     } else { n       vert.push_back( n           make_pair(x[0], make_pair(min(y[0], y[1]), max(y[0], y[1])))); n     } n   } n   cleanup(horz); n   cleanup(vert); n   for (auto it : horz) { n     ans += it.second.second - it.second.first + 1; n     y_com.insert(it.first); n   } n   for (auto it : vert) { n     ans += it.second.second - it.second.first + 1; n     y_com.insert(it.second.first); n     y_com.insert(it.second.second); n   } n   int cnt = 1; n   for (auto it : y_com) y_map[it] = cnt++; n   for (auto it : horz) { n     tmp.push_back(make_pair(it.second.first, make_pair(it.first, 1))); n     tmp.push_back(make_pair(it.second.second + 1, make_pair(it.first, -1))); n   } n   sort(tmp.begin(), tmp.end()); n   int cur = 0; n   for (auto it : vert) { n     while (cur < tmp.size() && tmp[cur].first <= it.first) { n       update(y_map[tmp[cur].second.first], tmp[cur].second.second); n       cur++; n     } n     ans -= get(y_map[it.second.second]) - get(y_map[it.second.first] - 1); n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double eps = 1e-7; n const int inf = 0x3f3f3f3f; n const int hinf = 0x3f3f3f3f; n const long long mod = 1000000009; n struct node { n   int l, r; n   double expe; n   double add; n } sgt[100010 << 2]; n int n, m; n int a[100010], h[100010], l[100010], r[100010]; n struct mushroom { n   int b, z; n   bool operator<(const mushroom& bb) const { return b < bb.b; } n } dat[100010]; n void up(int root) { n   sgt[root].expe = sgt[root << 1].expe + sgt[root << 1 | 1].expe; n } n void down(int root) { n   sgt[root << 1].add *= sgt[root].add; n   sgt[root << 1].expe *= sgt[root].add; n   sgt[root << 1 | 1].add *= sgt[root].add; n   sgt[root << 1 | 1].expe *= sgt[root].add; n   sgt[root].add = 1.0; n } n void build(int l, int r, int root) { n   sgt[root].l = l; n   sgt[root].r = r; n   sgt[root].expe = 0.0; n   sgt[root].add = 1.0; n   if (l == r) { n     sgt[root].expe = dat[sgt[root].l].z; n     return; n   } n   int mid = (l + r) >> 1; n   build(l, mid, root << 1); n   build(mid + 1, r, root << 1 | 1); n   up(root); n } n void upd(int l, int r, double val, int root) { n   if (l > dat[sgt[root].r].b || r < dat[sgt[root].l].b) return; n   if (dat[sgt[root].l].b >= l && dat[sgt[root].r].b <= r) { n     sgt[root].add *= val; n     sgt[root].expe *= val; n     return; n   } n   down(root); n   int mid = (sgt[root].l + sgt[root].r) >> 1; n   if (l <= dat[mid].b) upd(l, r, val, root << 1); n   if (r >= dat[mid].b) upd(l, r, val, root << 1 | 1); n   up(root); n } n int main() { n   scanf( %d%d , &n, &m); n   for (int i = 1; i <= n; i++) { n     scanf( %d%d%d%d , &a[i], &h[i], &l[i], &r[i]); n   } n   for (int i = 1; i <= m; i++) { n     scanf( %d%d , &dat[i].b, &dat[i].z); n   } n   sort(dat + 1, dat + 1 + m); n   build(1, m, 1); n   for (int i = 1; i <= n; i++) { n     upd(a[i] - h[i], a[i] - 1, 1.0 - l[i] / 100.0, 1); n     upd(a[i] + 1, a[i] + h[i], 1.0 - r[i] / 100.0, 1); n   } n   printf( %.15lf n , sgt[1].expe); n } n


#include <bits/stdc++.h> n using namespace std; n const double eps = 1e-9; n const long long int MOD1 = 1e9 + 7; n const long long int MAX5 = 1e5; n const long long int MAX6 = 1e6; n const long long int MAX7 = 1e7; n const long long int MAX8 = 1e8; n const long long int MAX9 = 1e9; n const long long int MAX10 = 1e10; n const long long int MAXX = 1e18; n long long int pow(long long int x, long long int y) { n   long long int res = 1; n   while (y > 0) { n     res = res * x; n     x = x * x; n     y >>= 1; n   } n   return res; n } n long long int gcd(int a, int b) { n   if (a < b) swap(a, b); n   if (b == 0) return a; n   return gcd(a % b, b); n } n void solve() { n   int n, q; n   cin >> n >> q; n   set<int> p; n   for (int ii = 0; ii < n; ii++) { n     int aa; n     cin >> aa; n     p.insert(aa); n   } n   auto it = p.begin(); n   multiset<int> m; n   m.insert(0); n   for (int ii = 0; ii < p.size() - 1; ii++) { n     int x = *it; n     it++; n     m.insert(x - *it); n   } n   cout << *p.rbegin() - *p.begin() + *m.begin(); n   cout <<   n ; n   ; n   for (int ii = 0; ii < q; ii++) { n     int t, x; n     cin >> t >> x; n     int y, z; n     bool Y = false, Z = false; n     if (t == 0) { n       it = p.find(x); n       if (it != p.begin()) { n         it--; n         y = *it; n         Y = true; n         m.erase(m.find(y - x)); n       } n       it = p.find(x); n       if (it != (--p.end())) { n         it++; n         z = *it; n         Z = true; n         m.erase(m.find(x - z)); n       } n       if (Y && Z) m.insert(y - z); n       p.erase(x); n     } n     if (t == 1) { n       p.insert(x); n       it = p.find(x); n       if (it != p.begin()) { n         it--; n         y = *it; n         Y = true; n         m.insert(y - x); n       } n       it = p.find(x); n       if (it != (--p.end())) { n         it++; n         z = *it; n         Z = true; n         m.insert(x - z); n       } n       if (Y && Z) m.erase(m.find(y - z)); n     } n     if (!p.empty()) n       cout << *p.rbegin() - *p.begin() + *m.begin(); n     else n       cout << 0; n     cout <<   n ; n     ; n   } n } n int main() { n   { solve(); } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   pair<int, int> mmx[3]; n   for (int i = 0; i < 3; i++) cin >> mmx[i].first >> mmx[i].second; n   int a, b, c; n   a = min(n - mmx[1].first - mmx[2].first, mmx[0].second); n   b = min(n - a - mmx[2].first, mmx[1].second); n   c = n - a - b; n   cout << a <<     << b <<     << c; n   return 0; n } n


#include<bits/stdc++.h> n  n using namespace :: std; n  n #define ll long long n #define mp make_pair n #define ld long double n #define F first n #define S second n #define pii pair<int,int> n #define pb push_back n  n const int maxn=2e5+500; n const int inf=1e9+900; n const int mod=1e9+7; n  n pair<int,int> tip,che; n  n ld lenght(pair<ld,ld> a){ n  return sqrt(a.F*a.F+a.S*a.S); n } n bool mibin(pair<ld,ld> x){ n   complex<ld> a,b; n   a.real(((ld)(che.F)-(x.F))); n   a.imag(((ld)(che.S)-(x.S))); n   b.real(((ld)(che.F)-(tip.F))); n   b.imag(((ld)(che.S)-(tip.S))); n   a*=-1; n   b*=-1; n   if(arg(a)<=0 && arg(b)<=0){ n    return (arg(a)<=arg(b)); n   } n   if(arg(a)>=0 && arg(b)>=0){ n    return (arg(a)<=arg(b)); n   } n   if(arg(a)>=0 && arg(b)<=0){ n    return 1; n   } n   if(arg(a)<=0 && arg(b)>=0){ n    return 0; n   } n   return (arg(a)<=arg(b)); n } n  n void add(pair<int,int> x){ n  if(mibin(mp((ld)x.F,(ld)x.S))){ n   tip=x; n  } n } n ld mibine(pair<int,int> s,pair<int,int> t){ n  pair<int,int> v=mp(t.F-s.F,t.S-s.S); n  if(!mibin(s)){ n  // cout<< NOting n ; n   return 0; n  } n  if(mibin(t)){ n  // cout<< ALL n ; n   return lenght(v); n  } n  ld b=0; n  ld e=1; n  for(int i=0;i<60;i++){ n   ld mid=(e+b)/2; n   if(mibin(mp((s.F)+mid*(v.F),(s.S)+mid*(v.S)))){ n    b=mid; n   }else{ n    e=mid; n   } n  } n // cout<<b<<endl; n  return lenght(v)*b; n } n  n  n int x[maxn]; n int y[maxn]; n  n  n int main(){ n  ios_base::sync_with_stdio(false); n  cin.tie(0); n  n  int n,h; n  cin>>n>>h; n  for(int i=0;i<n;i++){ n   cin>>x[i]>>y[i]; n  } n  ld ans=lenght(mp(x[n-1]-x[n-2],y[n-1]-y[n-2])); n  tip=mp(x[n-2],y[n-2]); n  che=mp(x[n-1],y[n-1]+h); n  for(int i=n-3;i>=0;i--){ n   add(mp(x[i+1],y[i+1])); n   ans+=mibine(mp(x[i],y[i]),mp(x[i+1],y[i+1])); n  } n  cout<<fixed<<setprecision(10)<<ans; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n T read1() { n   T t = 0; n   char k; n   bool v = 0; n   do (k = getchar()) ==  -  && (v = 1); n   while ( 0  > k || k >  9 ); n   while ( 0  <= k && k <=  9 ) n     t = (t << 3) + (t << 1) + (k ^  0 ), k = getchar(); n   return v ? -t : t; n } n int v[1200005], s, fl[1200005], w[1200005]; n vector<pair<int, pair<int, int> > > a[300005], b; n void down(int d) { n   fl[d << 1] += fl[d]; n   fl[d << 1 | 1] += fl[d]; n   v[d << 1] += fl[d]; n   v[d << 1 | 1] += fl[d]; n   fl[d] = 0; n } n void up(int d) { n   v[d << 1] > v[d << 1 | 1] ? (w[d] = w[d << 1], v[d] = v[d << 1]) n                             : (w[d] = w[d << 1 | 1], v[d] = v[d << 1 | 1]); n } n void add(int l, int r, int x, int y, int z, int d) { n   if (l == x && r == y) { n     v[d] += z, fl[d] += z; n     return; n   } n   down(d); n   int mid = l + r >> 1; n   if (y <= mid) n     add(l, mid, x, y, z, d << 1); n   else if (mid < x) n     add(mid + 1, r, x, y, z, d << 1 | 1); n   else n     add(l, mid, x, mid, z, d << 1), add(mid + 1, r, mid + 1, y, z, d << 1 | 1); n   up(d); n } n void build(int l, int r, int d) { n   if (l == r) n     w[d] = l; n   else { n     build(l, l + r >> 1, d << 1); n     build(l + r + 2 >> 1, r, d << 1 | 1); n     w[d] = w[d << 1]; n   } n } n int wh, g; n int main() { n   s = read1<long long>(); n   build(1, 300000, 1); n   for (int i = 1; i <= s; ++i) { n     int l = read1<long long>(), v = read1<long long>(), r = read1<long long>(); n     b.push_back(make_pair(l, make_pair(v, r))); n     a[l].push_back(make_pair(1, make_pair(v, r))); n     a[v + 1].push_back(make_pair(-1, make_pair(v, r))); n   } n   int ans = 0; n   for (int i = 1; i <= 300000; ++i) { n     for (int j = 0; j < a[i].size(); ++j) n       add(1, 300000, a[i][j].second.first, a[i][j].second.second, a[i][j].first, n           1); n     if (v[1] > ans) ans = v[1], wh = i, g = w[1]; n   } n   cout << ans << endl; n   for (int i = 0; i < s; ++i) n     if (b[i].first <= wh && wh <= b[i].second.first && b[i].second.first <= g && n         g <= b[i].second.second) n       printf( %d  , i + 1); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int c, d, n, m, k; n   cin >> c >> d >> n >> m >> k; n   int users = n * m - k; n   int ans = 1000000000; n   for (int i = 0; i <= m; i++) n     for (int j = 0; j <= 10000; j++) { n       if (i * n + j >= users) { n         if (c * i + j * d < ans) ans = c * i + j * d; n       } n     } n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n int a[10001]; n int i, j, n, k; n int main() { n   cin >> n; n   for (i = 0; i < n; i++) n     for (j = 0; j < n; j++) { n       cin >> k; n       if (k == 3 || k == 1) a[i] = -1; n     } n   k = 0; n   for (i = 0; i < n; i++) n     if (a[i] != -1) k++; n   cout << k <<   n ; n   for (i = 0; i < n && k > 0; i++) n     if (a[i] != -1) cout << i + 1 <<    ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int i; n   int n, d, l; n   cin >> n >> d >> l; n   int pos = (n + 1) / 2; n   int neg = n / 2; n   int a[n + 1]; n   if (d > (pos * l - neg) || d < (pos - neg * l)) { n     cout <<  -1 ; n     return 0; n   } n   if (d > 0) { n     for (i = 1; i <= n; i++) a[i] = 1; n     i = 1; n     if (n & 1) d--; n     while (d) { n       a[2 * i - 1] += min(l - 1, d); n       d -= min(l - 1, d); n       i++; n     } n   } else { n     for (i = 1; i <= n; i++) a[i] = 1; n     i = 1; n     d = -d; n     if (n & 1) d++; n     while (d) { n       a[2 * i] += min(l - 1, d); n       d -= min(l - 1, d); n       i++; n     } n   } n   for (i = 1; i <= n; i++) cout << a[i] <<    ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 2e5 + 10; n int n, m; n bool lie[40]; n int ask(int d) { n   int ret; n   cout << d << endl; n   cin >> ret; n   if (ret == 0) exit(0); n   return ret; n } n int main() { n   cin >> m >> n; n   for (int i = 0; i < n; i++) n     if (ask(m) == 1) lie[i] = true; n   int l = 1, r = m; n   int cnt = 0; n   while (l < r) { n     int mid = l + (r - l) / 2; n     int ans = ask(mid); n     if (lie[(cnt++) % n]) ans = -ans; n     if (ans > 0) n       l = mid + 1; n     else n       r = mid - 1; n   } n   ask(l); n } n


#include <bits/stdc++.h> n using namespace std; n vector<long long int> v1, v2; n vector<char> v4; n string s1, s2, s3; n long long int visited[2000005]; n set<char> st; n set<long long int>::iterator it; n int main() { n   long long int a, b, c, d, e, f, i, j, k, n       cnt1 = 0, cnt2 = 0, sum1 = 0, sum2 = 0, first, chk1 = 0, chk2 = 0, T; n   cin >> a >> b; n   char xx; n   long long int indx, chk = 0; n   cin >> s1; n   s2 = s1; n   for (i = 0; i < a; i++) { n     if (visited[i] == 0) { n       v1.push_back(i); n       for (j = i; j < a; j += b) { n         visited[j] = 1; n         s1[j] = s1[i]; n       } n     } n   } n   for (i = 0; i < a; i++) { n     if (s1[i] > s2[i]) { n       chk = 1; n       for (j = 0; j < v1.size(); j++) { n         if (v1[j] > i) { n           for (int k = v1[j]; k < a; k += b) { n             s1[k] =  0 ; n           } n         } n       } n       break; n     } else if (s1[i] == s2[i]) n       cnt1++; n     else { n       first = i; n       break; n     } n   } n   if (cnt1 == a) chk = 1; n   if (chk == 0) { n     long long int x = upper_bound(v1.begin(), v1.end(), first) - v1.begin(); n     x--; n     xx = s1[v1[x]]; n     if (xx ==  9 ) { n       for (i = x - 1; i >= 0; i--) { n         if (s1[v1[i]] !=  9 ) { n           xx = s1[v1[i]] + 1; n           for (j = v1[i]; j < a; j += b) { n             s1[j] = xx; n           } n           for (j = i + 1; j < v1.size(); j++) { n             if (s1[v1[j]] !=  0 ) { n               for (int k = v1[j]; k < a; k += b) { n                 s1[k] =  0 ; n               } n             } n           } n           break; n         } n       } n     } else { n       for (i = v1[x]; i < a; i += b) { n         s1[i] = xx + 1; n       } n     } n   } n   cout << s1.size() << endl; n   cout << s1 << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n double dp[200 + 50][200 + 50][200 + 50]; n double p[200 + 50]; n double res; n int a[200 + 50]; n int n, l, x, kol; n int main() { n   scanf( %d%d%d , &n, &l, &kol); n   for (int i = 1; i <= n; i++) { n     scanf( %d , &x); n     p[i] = (x + 0.0) / 100; n   } n   for (int i = 1; i <= n; i++) { n     scanf( %d , &a[i]); n     a[i]++; n   } n   memset(dp, 0, sizeof(dp)); n   dp[0][0][0] = 1; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j <= i; j++) { n       for (int k = 0; k <= n; k++) { n         dp[i + 1][j + 1][min(n, k + a[i + 1])] += dp[i][j][k] * p[i + 1]; n         dp[i + 1][j][k] += dp[i][j][k] * (1 - p[i + 1]); n       } n     } n   } n   res = 0; n   for (int i = l; i <= n; i++) { n     for (int j = max(0, l - kol); j <= n; j++) { n       if (i <= j + kol) res += dp[n][i][j]; n     } n   } n   printf( %llf , res); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int d[1000000]; n int main() { n   int n, k; n   scanf( %d%d , &n, &k); n   for (int i = 0; i < (n); ++i) { n     int(x); n     scanf( %d , &x); n     d[i % k] += x; n   } n   int mi = (int)1e9; n   int id = -1; n   for (int i = 0; i < (k); ++i) { n     if (mi > d[i]) { n       mi = d[i]; n       id = i; n     } n   } n   printf( %d n , id + 1); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int dy[] = {-1, 0, 1, 0}, dx[] = {0, 1, 0, -1}; n const double EPS = 1e-8; n const double PI = acos(-1.0); n int popcount(int n) { return __builtin_popcount(n); } n int popcount(long long n) { return __builtin_popcountll(n); } n template <class T> n int SIZE(T a) { n   return a.size(); n } n template <class T> n string IntToString(T num) { n   string res; n   stringstream ss; n   ss << num; n   return ss.str(); n } n template <class T> n T StringToInt(string str) { n   T res = 0; n   for (int i = 0; i < SIZE(str); i++) res = (res * 10 + str[i] -  0 ); n   return res; n } n template <class T> n T gcd(T a, T b) { n   if (b == 0) return a; n   return gcd(b, a % b); n } n template <class T> n T lcm(T a, T b) { n   return a / gcd(a, b) * b; n } n template <class T> n void PrintSeq(T &a, int sz) { n   for (int i = 0; i < sz; i++) { n     cout << a[i]; n     if (sz == i + 1) n       cout << endl; n     else n       cout <<    ; n   } n } n bool EQ(double a, double b) { return abs(a - b) < EPS; } n void fastStream() { n   cin.tie(0); n   std::ios_base::sync_with_stdio(0); n } n vector<string> split(string str, char del) { n   vector<string> res; n   for (int i = 0, s = 0; i < SIZE(str); i++) { n     if (str[i] == del) { n       if (i - s != 0) res.push_back(str.substr(s, i - s)); n       s = i + 1; n     } else if (i == SIZE(str) - 1) { n       res.push_back(str.substr(s)); n     } n   } n   return res; n } n int N; n long long as[100001]; n long long leftDP[2][100001]; n long long rightDP[2][100001]; n long long goLeft(int pari, int pos) { n   if (leftDP[pari][pos] >= 0) return leftDP[pari][pos]; n   long long res = 0; n   if (pos == 0) { n   } else { n     if (pari == 0) { n       res = max(res, n                 goLeft(pari, pos - 1) + as[pos - 1] - (as[pos - 1] % 2 == 0)); n       if (as[pos - 1] != 1) n         res = max(res, goLeft(pari ^ 1, pos - 1) + as[pos - 1] - n                            (as[pos - 1] % 2 == 1)); n     } else { n       if (as[pos - 1] != 1) n         res = max(res, n                   goLeft(pari, pos - 1) + as[pos - 1] - (as[pos - 1] % 2 == 1)); n     } n   } n   return leftDP[pari][pos] = res; n } n long long goRight(int pari, int pos) { n   if (rightDP[pari][pos] >= 0) return rightDP[pari][pos]; n   long long res = 0; n   if (pos == N - 1) { n   } else { n     if (pari == 0) { n       res = max(res, goRight(pari, pos + 1) + as[pos] - (as[pos] % 2 == 0)); n       if (as[pos] != 1) n         res = n             max(res, goRight(pari ^ 1, pos + 1) + as[pos] - (as[pos] % 2 == 1)); n     } else { n       if (as[pos] != 1) n         res = max(res, goRight(pari, pos + 1) + as[pos] - (as[pos] % 2)); n     } n   } n   return rightDP[pari][pos] = res; n } n int main() { n   memset(leftDP, -1, sizeof(leftDP)); n   memset(rightDP, -1, sizeof(rightDP)); n   cin >> N; n   for (int i = 0; i < N - 1; i++) cin >> as[i]; n   long long res = 0; n   for (int i = 0; i < N; i++) { n     res = max(res, goLeft(1, i) + goRight(1, i)); n     res = max(res, goLeft(1, i) + goRight(0, i)); n     res = max(res, goLeft(0, i) + goRight(1, i)); n   } n   cout << res << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int dirty[3009]; n int main() { n   int n, m; n   cin >> n >> m; n   for (typeof(0) i = (0); i < (m); i++) cin >> dirty[i]; n   sort(dirty, dirty + m); n   if (!m) n     cout <<  YES n ; n   else if ((dirty[0] != 1) && (dirty[m - 1] != n)) { n     if (m < 3) n       cout <<  YES n ; n     else { n       bool YES = true; n       for (typeof(0) i = (0); i < (m - 2); i++) n         if ((dirty[i] == (dirty[i + 1] - 1)) && n             (dirty[i + 1] == (dirty[i + 2] - 1))) n           YES = false; n       if (YES) n         cout <<  YES n ; n       else n         cout <<  NO n ; n     } n   } else n     cout <<  NO n ; n   return 0; n } n


#include <bits/stdc++.h> n const double pi = acos(-1.0); n using namespace std; n inline long long MAX2(long long a, long long b) { n   return (a) > (b) ? (a) : (b); n } n inline long long MAX3(long long a, long long b, long long c) { n   return (a) > (b) ? ((a) > (c) ? (a) : (c)) : ((b) > (c) ? (b) : (c)); n } n inline long long MIN2(long long a, long long b) { n   return (a) < (b) ? (a) : (b); n } n inline long long MIN3(long long a, long long b, long long c) { n   return (a) < (b) ? ((a) < (c) ? (a) : (c)) : ((b) < (c) ? (b) : (c)); n } n int mod = 1e9 + 7; n int64_t extGcd(int64_t a, int64_t b, int64_t& x, int64_t& y) { n   if (!a) { n     x = 0; n     y = 1; n     return b; n   } n   int64_t x1, y1; n   int64_t d = extGcd(b % a, a, x1, y1); n   x = y1 - (b / a) * x1; n   y = x1; n   return d; n } n inline long long addmod(long long a, long long b) { n   a = a % mod + b % mod; n   if (a > mod) a %= mod; n   return a; n } n inline long long submod(long long a, long long b) { n   a = a % mod - b % mod; n   if (a < 0) a += mod; n   return a; n } n inline long long mulmod(long long a, long long b) { n   return (a % mod * b % mod) % mod; n } n int dx[] = {1, 1, 0, -1, -1, -1, 0, 1}; n int dy[] = {0, 1, 1, 1, 0, -1, -1, -1}; n inline long long exp(long long a, long long b) { n   if (a == 0) return 0ll; n   long long r = 1LL; n   while (b > 0) { n     if (b & 1) { n       r = r * (a % mod); n       r = (r + mod) % mod; n     } n     b /= 2; n     a = (a % mod) * (a % mod); n     a = (a + mod) % mod; n   } n   return (r + mod) % mod; n } n long long gcd(long long a, long long b) { n   if (b == 0) return a; n   if (a == 0) return b; n   return gcd(b, a % b); n } n unsigned long int setbits(long long n) { n   unsigned long int count = 0; n   while (n) { n     n &= (n - 1); n     count++; n   } n   return count; n } n int main() { n   if (fopen( input.txt ,  r )) n     freopen( input.txt ,  r , stdin), freopen( output.txt ,  w , stdout); n   ; n   int t; n   cin >> t; n   while (t--) { n     int n, k, z; n     cin >> n >> k >> z; n     long long a[n]; n     long long pre[n + 1]; n     pre[0] = 0; n     for (long long i = (long long)(0); i < (long long)(n); i++) { n       cin >> a[i]; n       pre[i + 1] = pre[i] + a[i]; n     } n     long long ans = 0; n     long long curr_sum = a[0]; n     for (int i = 1; i <= min(k, n - 1); i++) { n       curr_sum += a[i]; n       long long prev = a[i - 1]; n       long long last = a[i]; n       int rem = (k - i); n       int resz = z; n       long long res = curr_sum; n       int nxt = i; n       while (resz > 0 and rem > 0) { n         if (rem <= 0) { n           nxt = i; n           break; n         } n         res += prev; n         resz--; n         rem--; n         if (rem <= 0) { n           nxt = i - 1; n           break; n         } n         res += last; n         rem--; n       } n       res += pre[nxt + rem + 1] - pre[nxt + 1]; n       ans = MAX2(ans, res); n     } n     cout << ans <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n unsigned long long B[31][31], res = 0; n int main(void) { n   for (int i = 0; i <= 30; i++) { n     B[i][0] = B[i][i] = 1; n     for (int j = 1; j < i; j++) B[i][j] = B[i - 1][j - 1] + B[i - 1][j]; n   } n   int n, m, k; n   cin >> n >> m >> k; n   for (int b = 4; b < k; b++) { n     res += (b <= n && k - b <= m) ? B[n][b] * B[m][k - b] : 0; n   } n   cout << res; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 1000005; n const int SQRTN = 1003; n const int LOGN = 22; n const double PI = acos(-1); n const int INF = 1e9; n int MOD = 1000000007; n const int FMOD = 998244353; n const double eps = 1e-9; n long long gcd(long long a, long long b) { n   if (a == 0) return (b); n   return (gcd(b % a, a)); n } n long long lcm(long long a, long long b) { return (a / gcd(a, b) * b); } n void solve() { n   long long n, m1; n   cin >> n >> m1; n   long long x, k, y; n   cin >> x >> k >> y; n   long long arr[n]; n   for (int i = 0; i < n; i++) cin >> arr[i]; n   long long brr[m1]; n   for (int i = 0; i < m1; i++) cin >> brr[i]; n   bool flag = false; n   long long i = 0, j = 0, m = -1, pos, l = -1, r; n   long long result = 0; n   while (i < n && j < m1) { n     if (flag == true) break; n     m = max(m, arr[i]); n     if (m == arr[i]) pos = i; n     if (arr[i] != brr[j]) n       i++; n     else { n       r = i; n       i++; n       j++; n       int len = r - l - 1; n       if (pos > l && pos < r && len < k) { n         flag = true; n         break; n       } else { n         long long c1, c2; n         if (len % k == 0) n           c1 = x * (len / k); n         else n           c1 = x * (len / k) + (len - k * (len / k)) * y; n         c2 = y * len; n         if (pos > l && pos < r) c2 = y * (len - k) + x; n         result += min(c1, c2); n       } n       l = r; n       m = arr[l]; n     } n   } n   if (j == m1 && i < n) { n     m = arr[i - 1]; n     pos = i - 1; n     l = i - 1; n     r = n; n     int len = 0; n     while (i < n) { n       m = max(m, arr[i]); n       if (m == arr[i]) pos = i; n       i++; n       len++; n     } n     if (pos > l && pos < r && len < k) n       flag = true; n     else { n       long long c1, c2; n       if (len % k == 0) n         c1 = x * (len / k); n       else n         c1 = x * (len / k) + (len - k * (len / k)) * y; n       c2 = y * len; n       if (pos > l && pos < r) c2 = (len - k) * y + x; n       result += min(c1, c2); n     } n   } n   if (i == n && j < m1) { n     cout << -1 <<   n ; n   } else { n     if (flag) n       cout << -1 <<   n ; n     else n       cout << result <<   n ; n   } n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long t = 1; n   while (t--) { n     solve(); n   } n   return (0); n } n


#include <bits/stdc++.h> n using namespace std; n const int NMax = 1100000; n inline int read() { n   int x = 0; n   char ch = getchar(); n   bool positive = 1; n   for (; ch <  0  || ch >  9 ; ch = getchar()) n     if (ch ==  - ) positive = 0; n   for (; ch >=  0  && ch <=  9 ; ch = getchar()) x = x * 10 + ch -  0 ; n   return positive ? x : -x; n } n struct node { n   int w, id, sz; n   node *left, *right; n   int lsize() { return left ? left->sz : 0; } n   int rsize() { return right ? right->sz : 0; } n } * T, pool[NMax]; n void update(node *p) { n   if (!p) return; n   p->sz = p->lsize() + p->rsize() + 1; n } n int L; n struct pnn { n   node *x, *y; n }; n pnn mp(node *x, node *y) { n   pnn ret; n   ret.x = x; n   ret.y = y; n   return ret; n } n node *new_node(int id) { n   node *p = &pool[L++]; n   p->w = rand() * rand(); n   p->id = id; n   p->sz = 1; n   p->left = p->right = NULL; n   return p; n } n node *new_node(int id, int w) { n   node *p = &pool[L++]; n   p->w = w; n   p->id = id; n   p->sz = 1; n   p->left = p->right = NULL; n   return p; n } n int N, M; n node *merge(node *a, node *b) { n   if (!a) return b; n   if (!b) return a; n   if (b->w > a->w) { n     a->right = merge(a->right, b); n     update(a); n     return a; n   } else { n     b->left = merge(a, b->left); n     update(b); n     return b; n   } n } n pnn split(node *a, int l) { n   if (!a) return mp((node *)NULL, (node *)NULL); n   if (l >= a->sz) return mp(a, (node *)NULL); n   if (l <= 0) return mp((node *)NULL, a); n   if (l <= a->lsize()) { n     pnn ret = split(a->left, l); n     a->left = ret.y; n     update(a); n     ret.y = a; n     return ret; n   } else { n     pnn ret = split(a->right, l - a->lsize() - 1); n     a->right = ret.x; n     update(a); n     ret.x = a; n     return ret; n   } n } n int have[NMax], chose[NMax], nn; n int oper[NMax]; n void DFS(node *p) { n   if (p->left) DFS(p->left); n   if (p->id == -1) p->id = chose[nn++]; n   if (p->right) DFS(p->right); n } n void DFS1(node *p) { n   if (p->left) DFS1(p->left); n   printf( %d  , p->id); n   if (p->right) DFS1(p->right); n } n node *Build(int x, int y, int w) { n   if (x == y) { n     node *p = new_node(-1, w); n     return p; n   } n   int mid = (x + y) >> 1; n   node *p = new_node(-1, w); n   if (mid > x) p->left = Build(x, mid - 1, w + rand()); n   if (mid < y) p->right = Build(mid + 1, y, w + rand()); n   update(p); n   return p; n } n int main() { n   N = read(); n   M = read(); n   T = Build(1, N, -100000000); n   for (int i = 1; i <= M; i++) { n     int x, y; n     x = read(); n     y = read(); n     swap(x, y); n     oper[i] = x; n     pnn tmp = split(T, x - 1); n     pnn tmq = split(tmp.y, 1); n     if (have[y] && tmq.x->id != y) { n       puts( -1 ); n       getchar(); n       getchar(); n       return 0; n     } n     have[y] = 1; n     if (tmq.x->id != -1 && tmq.x->id != y) { n       puts( -1 ); n       getchar(); n       getchar(); n       return 0; n     } n     tmq.x->id = y; n     tmp.x = merge(tmq.x, tmp.x); n     T = merge(tmp.x, tmq.y); n   } n   for (int i = 1; i <= N; i++) n     if (!have[i]) chose[nn++] = i; n   nn = 0; n   DFS(T); n   for (int i = M; i >= 1; i--) { n     pnn tmp = split(T, oper[i]); n     pnn tmq = split(tmp.x, 1); n     tmp.x = merge(tmq.y, tmq.x); n     T = merge(tmp.x, tmp.y); n   } n   DFS1(T); n   puts(  ); n   getchar(); n   getchar(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, cnt[100015], x[100015], y[100015], z[100015]; n vector<int> a[100015]; n int getpos(int i, int u) { n   if (x[i] == u) return 0; n   if (y[i] == u) return 1; n   if (z[i] == u) return 2; n } n void dfs(int u, int v) { n   cout << u <<    ; n   if (cnt[v] == 0) { n     cout << v; n     return; n   } n   for (int i : a[u]) n     if (i) { n       --cnt[x[i]]; n       --cnt[y[i]]; n       --cnt[z[i]]; n       int k = 3 - getpos(i, u) - getpos(i, v); n       for (int &j : a[x[i]]) n         if (j == i) j = 0; n       for (int &j : a[y[i]]) n         if (j == i) j = 0; n       for (int &j : a[z[i]]) n         if (j == i) j = 0; n       if (k == 0) dfs(v, x[i]); n       if (k == 1) dfs(v, y[i]); n       if (k == 2) dfs(v, z[i]); n     } n } n int main() { n   cin >> n; n   for (int i = 1; i <= n - 2; ++i) n     cin >> x[i] >> y[i] >> z[i], a[x[i]].push_back(i), a[y[i]].push_back(i), n         a[z[i]].push_back(i), ++cnt[x[i]], ++cnt[y[i]], ++cnt[z[i]]; n   for (int i = 1; i <= n; ++i) n     if (cnt[i] == 1) { n       if (cnt[x[a[i][0]]] == 2) dfs(i, x[a[i][0]]); n       if (cnt[y[a[i][0]]] == 2) dfs(i, y[a[i][0]]); n       if (cnt[z[a[i][0]]] == 2) dfs(i, z[a[i][0]]); n     } n } n


#include <bits/stdc++.h> n const int INF = 1e7; n using namespace std; n const int N = 20; n int n, m; n int c[N]; n int a[N]; n int like[N]; n string s[N]; n int T_res = 0; n int Lika = 0; n bool Check_Res() { n   int Lik; n   for (int i = 2; i <= m; i++) { n     { n       Lik = 0; n       for (int j = 0; j <= n - 1; j++) n         if (a[j] == (s[i][j] -  0 )) Lik++; n       if (Lik != like[i]) return false; n     } n   } n   return true; n } n void attempt(int i, int same) { n   if (i == n) { n     if (same == like[1] && Check_Res() == true) { n       T_res++; n     } n     return; n   } n   a[i] = !((s[1][i]) -  0 ); n   attempt(i + 1, same); n   if (same < like[1]) { n     a[i] = (s[1][i] -  0 ); n     attempt(i + 1, same + 1); n   } n } n int main() { n   scanf( %d%d , &n, &m); n   for (int i = 1; i <= m; i++) { n     cin >> s[i]; n     cin >> like[i]; n   } n   attempt(0, 0); n   cout << T_res; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   long long n; n   cin >> n; n   long long out = n * (n + 1) * (n + 2) / 6; n   out *= n * (n + 1) * (n + 2) * (n + 3) * (n + 4) / 120; n   cout << out <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int m = 320; n struct data { n   int n, x, a[2 * m + 10]; n   data *next; n }; n data *head; n int get(int value, int limit) { n   int ret = 0; n   data *k; n   for (k = head; k != NULL; k = k->next) { n     if (k->x > value) break; n     ret += k->n; n   } n   if (k != NULL) n     for (int i = 1; i <= k->n; i++) { n       if (k->a[i] > value) break; n       ret++; n     } n   return (min(ret, limit) + 1); n } n void split(data *k) { n   data *t = new (data); n   t->x = k->x = 0; n   for (int i = 1; i <= m; i++) { n     t->a[i] = k->a[i + m]; n     t->x = max(t->x, t->a[i]); n     k->x = max(k->x, k->a[i]); n   } n   k->n = t->n = m; n   t->next = k->next; n   k->next = t; n } n void insert(int value, int pos) { n   if (head == NULL) { n     head = new (data); n     head->n = 1; n     head->x = head->a[1] = value; n     head->next = NULL; n     return; n   } n   data *k; n   for (k = head; k != NULL; k = k->next) { n     if (pos <= k->n + 1) break; n     pos -= k->n; n   } n   for (int i = k->n; i >= pos; i--) k->a[i + 1] = k->a[i]; n   k->a[pos] = value; n   k->x = max(k->x, value); n   k->n++; n   if (k->n == 2 * m) split(k); n } n int ans[100010], p[100010]; n int main() { n   int n; n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) { n     int x, y; n     scanf( %d%d , &x, &y); n     p[x] = i; n     int pos = get(x, y); n     insert(x, pos); n   } n   int t = 0; n   for (data *k = head; k != NULL; k = k->next) n     for (int i = 1; i <= k->n; i++) ans[++t] = k->a[i]; n   reverse(ans + 1, ans + n + 1); n   for (int i = 1; i <= n; i++) printf( %d%c , p[ans[i]], i == n ?   n  :    ); n   return (0); n } n


#include <bits/stdc++.h> n using namespace std; n int dp[150][150]; n int main() { n   int n; n   cin >> n; n   for (char a =  a ; a <=  z ; a++) n     for (char b =  a ; b <=  z ; b++) dp[a][b] = -2000000009; n   for (char c =  a ; c <=  z ; c++) dp[c][c] = 0; n   while (n--) { n     string s; n     cin >> s; n     char a = s[0], b = s[s.length() - 1]; n     for (char c =  a ; c <=  z ; c++) n       dp[c][b] = max(dp[c][b], dp[c][a] + (int)s.length()); n   } n   int ans = 0; n   for (char c =  a ; c <=  z ; c++) ans = max(ans, dp[c][c]); n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n ll modinv(ll a, ll m) { n   assert(m > 0); n   if (m == 1) return 0; n   a %= m; n   if (a < 0) a += m; n   assert(a != 0); n   if (a == 1) return 1; n   return m - modinv(m, a) * m / a; n } n template <int MOD_> n struct modnum { n  private: n   int v; n  n  public: n   static const int MOD = MOD_; n   modnum() : v(0) {} n   modnum(ll v_) : v(int(v_ % MOD)) { n     if (v < 0) v += MOD; n   } n   explicit operator int() const { return v; } n   friend bool operator==(const modnum& a, const modnum& b) { n     return a.v == b.v; n   } n   friend bool operator!=(const modnum& a, const modnum& b) { n     return a.v != b.v; n   } n   modnum operator~() const { n     modnum res; n     res.v = modinv(v, MOD); n     return res; n   } n   modnum& operator+=(const modnum& o) { n     v += o.v; n     if (v >= MOD) v -= MOD; n     return *this; n   } n   modnum& operator-=(const modnum& o) { n     v -= o.v; n     if (v < 0) v += MOD; n     return *this; n   } n   modnum& operator*=(const modnum& o) { n     v = int(ll(v) * ll(o.v) % MOD); n     return *this; n   } n   modnum& operator/=(const modnum& o) { return *this *= (~o); } n   friend modnum operator+(const modnum& a, const modnum& b) { n     return modnum(a) += b; n   } n   friend modnum operator-(const modnum& a, const modnum& b) { n     return modnum(a) -= b; n   } n   friend modnum operator*(const modnum& a, const modnum& b) { n     return modnum(a) *= b; n   } n   friend modnum operator/(const modnum& a, const modnum& b) { n     return modnum(a) /= b; n   } n }; n using num = modnum<998244353>; n template <typename T> n T pow(T a, long long b) { n   assert(b >= 0); n   T r = 1; n   while (b) { n     if (b & 1) r *= a; n     b >>= 1; n     a *= a; n   } n   return r; n } n vector<num> fact; n vector<num> ifact; n void init() { n   int N = 1100000; n   fact = {1}; n   for (int i = 1; i < N; i++) fact.push_back(i * fact[i - 1]); n   ifact.resize(N); n   ifact.back() = 1 / fact.back(); n   for (int i = N - 1; i > 0; i--) ifact[i - 1] = i * ifact[i]; n } n num ncr(int n, int k) { n   if (k < 0 || k > n) return 0; n   return fact[n] * ifact[k] * ifact[n - k]; n } n int main() { n   ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); n   init(); n   int n, k; n   cin >> n >> k; n   vector<int> A(n); n   for (int i = 0; i < n; i++) cin >> A[i]; n   int same = 0; n   for (int i = 0; i < n; i++) n     if (A[i] == A[(i + 1) % n]) same++; n   int diff = n - same; n   num ans = 0; n   for (int a = 0; a * 2 <= diff; a++) { n     ans += ncr(diff, a) * ncr(diff - a, a) * pow(num(k - 2), diff - a - a); n   } n   ans = (pow(num(k), diff) - ans) / 2; n   ans = ans * pow(num(k), same); n   cout << (int)ans <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1000000 + 50; n const int maxm = 1300000 + 100; n const int maxt = 3000000 + 100; n const int maxk = 10 + 3; n const int M = 2010; n const long long unit = 1LL; n const int INF = 0x3f3f3f3f; n const long long Inf = 0x3f3f3f3f3f3f3f3fLL; n const double eps = 1e-8; n const double inf = 1e15; n const double pi = acos(-1.0); n const long long mod = 998244353LL, gg = 3LL, inv2 = 499122177LL; n inline long long read() { n   long long x = 0; n   bool t = false; n   char ch = getchar(); n   while ((ch <  0  || ch >  9 ) && ch !=  - ) ch = getchar(); n   if (ch ==  - ) t = true, ch = getchar(); n   while (ch <=  9  && ch >=  0 ) x = x * 10 + ch - 48, ch = getchar(); n   return t ? -x : x; n } n struct Peo { n   int pos, id; n   bool operator<(const Peo &a) const { n     if (pos == a.pos) return id < a.id; n     return pos < a.pos; n   } n } peo[maxn]; n struct City { n   int pos, id; n   bool operator<(const City &a) const { n     if (pos == a.pos) return id < a.id; n     return pos < a.pos; n   } n } city[maxn]; n int m, n, a[maxn], b[maxn]; n long long judge(int x) { n   long long ret = 0; n   if (x < 0) { n     for (int i = 0; i < -x; i++) ret += peo[i].pos + m - city[n + x + i].pos; n     for (int i = -x; i < n; i++) ret += abs(peo[i].pos - city[i + x].pos); n   } else { n     for (int i = 0; i < x; i++) ret += city[i].pos + m - peo[n - x + i].pos; n     for (int i = x; i < n; i++) ret += abs(city[i].pos - peo[i - x].pos); n   } n   return ret; n } n int main() { n   m = read(), n = read(); n   for (int i = 0; i < n; ++i) city[i].pos = read(), city[i].id = i; n   sort(city, city + n); n   for (int i = 0; i < n; ++i) peo[i].pos = read(), peo[i].id = i; n   sort(peo, peo + n); n   int l = -n, r = n; n   while (l < r) { n     int m = (l + r) >> 1; n     if (judge(m) < judge(m + 1)) n       r = m; n     else n       l = m + 1; n   } n   long long ans = Inf, anst = 0; n   for (int turn = l - 100; turn <= l + 100; ++turn) { n     int st = (turn % n + n) % n; n     long long res = 0; n     for (int i = 0; i < n; ++i) { n       res += min(abs(peo[i].pos - city[st].pos), n                  m - abs(peo[i].pos - city[st].pos)); n       ++st; n       if (st >= n) st -= n; n     } n     if (res < ans) { n       ans = res; n       anst = turn; n     } n   } n   printf( %lld n , ans); n   int st = (anst % n + n) % n; n   for (int i = 0; i < n; ++i) { n     b[city[st].id] = peo[i].id; n     ++st; n     if (st >= n) st -= n; n   } n   for (int i = 0; i < n; ++i) printf( %d  , b[i] + 1); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int32_t main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long n, m; n   cin >> n >> m; n   vector<vector<vector<long long>>> g(n); n   vector<vector<long long>> store(m); n   for (long long i = 0; i < m; i++) { n     long long a, b, c; n     cin >> a >> b >> c; n     --a; n     b--; n     g[a].push_back({b, c}); n     g[b].push_back({a, c}); n     store[i] = {a, b, c}; n   } n   long long s; n   cin >> s; n   s--; n   vector<long long> d(n, LONG_LONG_MAX); n   vector<long long> parent(n), dd(n, LONG_LONG_MAX); n   for (long long i = 0; i < n; i++) { n     parent[i] = i; n   } n   d[s] = dd[s] = 0; n   set<pair<long long, long long>> q; n   q.insert({d[s], s}); n   while (!q.empty()) { n     long long v = q.begin()->second; n     q.erase(q.begin()); n     for (long long i = 0; i < g[v].size(); i++) { n       long long to = g[v][i][0], len = g[v][i][1]; n       if (d[v] + len < d[to]) { n         if (q.find({d[to], to}) != q.end()) { n           q.erase({d[to], to}); n         } n         parent[to] = v; n         d[to] = d[v] + len; n         dd[to] = len; n         q.insert(make_pair(d[to], to)); n       } else if (d[v] + len == d[to]) { n         if (dd[to] > len) { n           dd[to] = len; n           parent[to] = v; n         } n       } n     } n   } n   long long ans = 0; n   for (long long i = 0; i < n; i++) { n     ans += dd[i]; n   } n   cout << ans << endl; n   for (long long i = 0; i < m; i++) { n     long long a = store[i][0]; n     long long b = store[i][1]; n     if (parent[a] == b || parent[b] == a) { n       cout << i + 1 <<    ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m; n int main() { n   cin >> n; n   int cur = 1; n   while (n) { n     if (n == 3) { n       printf( %d %d %d  , cur, cur, cur * n); n       return 0; n     } n     int cnt = n / 2 + n % 2; n     n -= cnt; n     while (cnt--) printf( %d  , cur); n     cur *= 2; n   } n } n


#include <bits/stdc++.h> n const int Max_N(1000005); n int N, D; n int first[Max_N], ecnt(1), Next[Max_N * 2], To[Max_N * 2]; n int degree[Max_N]; n std::tuple<int, int> dfs(const int v, const int p = 0) { n   if (To[first[v]] == p && Next[first[v]] == 0) return std::make_tuple(0, 0); n   int res(0), max(0), min(D + 1); n   for (int e(first[v]); e; e = Next[e]) n     if (To[e] != p) { n       int len(1); n       auto tmp(dfs(To[e], v)); n       res += std::get<0>(tmp), len += std::get<1>(tmp); n       if (len >= 0) { n         if (len == D) n           ++res; n         else if (len * 2 > D) n           min = std::min(min, len), ++res; n         else n           max = std::max(max, len); n       } n     } n   if (max == 0 && min == D + 1) return std::make_tuple(res, -1); n   return std::make_tuple(res - (max + min <= D), max + min <= D ? min : max); n } n int main(int argc, char **argv) { n   scanf( %d %d , &N, &D); n   int r; n   for (int i(1), v, w; i != N; ++i) { n     scanf( %d %d , &v, &w); n     Next[ecnt] = first[v], To[ecnt] = w, first[v] = ecnt++; n     Next[ecnt] = first[w], To[ecnt] = v, first[w] = ecnt++; n     ++degree[v], ++degree[w]; n     if (degree[v] > 1) r = v; n     if (degree[w] > 1) r = w; n   } n   auto res(dfs(r)); n   printf( %d , std::get<0>(res) + (std::get<1>(res) != -1)); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long mxn = 5e5 + 123; n const long long inf = 1e9; n const long long mod = 998244353; n bool om[mxn]; n vector<long long> v; n long long n, mn = 1e18; n ; n int main() { n   int n, m; n   cin >> n >> m; n   for (int i = 1; i <= n; i++) n     if (n % i == 0) v.push_back(i); n   for (int i = 0; i < v.size(); i++) { n     if (n / v[i] < m) mn = min(mn, (v[i] * m) + (n / v[i])); n   } n   cout << mn; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline long long tmx(long long a, long long b, long long c) { n   return (a > b && a > c) ? a : ((b > c) ? b : c); n } n inline long long tmn(long long a, long long b, long long c) { n   return (a < b && a < c) ? a : ((b < c) ? b : c); n } n const int MXL = 0x3f3f3f3f; n string s[] = { Anka ,    Chapay ,  Cleo ,        Troll , n                Dracul ,  Snowy ,   Hexadecimal }; n inline int find(string x) { n   for (int i = 0; i < 7; ++i) n     if (s[i] == x) return i; n } n int n; n long long A, B, C; n int f[7][7] = {}; n long long BE = (long long)MXL * MXL, AM = 0; n int c[7]; n void dfs(int w) { n   if (w == 7) { n     int t[3] = {}; n     for (int i = 0; i < 7; ++i) ++t[c[i]]; n     if (!t[0] || !t[1] || !t[2]) return; n     long long MX = tmx(A / t[0], B / t[1], C / t[2]); n     long long MN = tmn(A / t[0], B / t[1], C / t[2]); n     long long BE_N = MX - MN; n     if (BE_N > BE) return; n     long long AM_N = 0; n     for (int i = 0; i < 7; ++i) n       for (int j = 0; j < 7; ++j) n         if (c[i] == c[j]) AM_N += f[i][j]; n     if (BE_N < BE || AM_N > AM) { n       BE = BE_N; n       AM = AM_N; n     } n     return; n   } n   for (int i = 0; i < 3; ++i) { n     c[w] = i; n     dfs(w + 1); n   } n } n string L, R; n int LN, RN; n string like; n inline void EXEC() { n   cin >> n; n   for (int i = 0; i < n; ++i) { n     cin >> L >> like >> R; n     LN = find(L); n     RN = find(R); n     ++f[LN][RN]; n   } n   cin >> A >> B >> C; n   dfs(0); n   cout << BE <<     << AM << endl; n } n int main() { n   EXEC(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int mod = 1000000007; n long long f = 0, g = 1; n int n; n int main() { n   cin >> n; n   for (int i = 2; i <= n; i++) { n     long long k = f; n     f = 3 * g % mod; n     g = (k + 2 * g) % mod; n   } n   printf( %lld , f); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 0x3f3f3f3f; n const long long LINF = 0x3f3f3f3f3f3f3f3fll; n void bad() { n   cout <<  NO  <<   n ; n   exit(0); n } n const int MAX = 4e5 + 10; n vector<int> g[MAX]; n int main() { n   if (!false) ios_base::sync_with_stdio(0); n   cin.tie(0); n   int n, d, k; n   cin >> n >> d >> k; n   if (d >= n or (n > 2 and k == 1)) bad(); n   int nxt = 0; n   vector<int> pos_dist(n, -1); n   stack<int> can; n   for (nxt = 0; nxt <= d; nxt++) { n     if (nxt < d) { n       g[nxt].push_back(nxt + 1); n       g[nxt + 1].push_back(nxt); n     } n     pos_dist[nxt] = min(nxt, d - nxt); n     can.push(nxt); n   } n   while (nxt < n) { n     if (false) cout <<  g  <<   n ; n     for (int i = 0; i < n; i++) { n       if (false) cout << i <<  :  ; n       for (auto j : g[i]) n         if (false) cout << j <<    ; n       if (false) cout <<   n ; n     } n     if (false) cout <<   n ; n     if (can.empty()) bad(); n     int v = can.top(); n     if (g[v].size() == k or pos_dist[v] == 0) { n       can.pop(); n       continue; n     } n     g[v].push_back(nxt); n     g[nxt].push_back(v); n     pos_dist[nxt] = pos_dist[v] - 1; n     can.push(nxt); n     nxt++; n   } n   set<pair<int, int>> stans; n   cout <<  YES  <<   n ; n   for (int i = 0; i < n; i++) { n     for (auto j : g[i]) stans.insert({min(i, j) + 1, max(i, j) + 1}); n   } n   for (auto [x, y] : stans) cout << x <<     << y <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = 1e8; n struct node { n   int x, y, z, s; n } pre[12][18][18][18]; n int n, a, b, dp[12][18][18][18], h[12]; n vector<int> ans; n void f(int i, int x, int y, int z, int v, int xx, int yy, int zz, int s) { n   x = max(0, x); n   y = max(0, y); n   z = max(0, z); n   if (dp[i][x][y][z] > v) { n     dp[i][x][y][z] = v; n     pre[i][x][y][z] = (node){xx, yy, zz, s}; n   } n } n void find(int i, int x, int y, int z) { n   node tmp = pre[i][x][y][z]; n   int s = tmp.s; n   for (int j = 0; j < s; j++) { n     ans.push_back(i); n   } n   if (i == 2) { n     return; n   } n   find(i - 1, tmp.x, tmp.y, tmp.z); n } n int main() { n   scanf( %d%d%d , &n, &a, &b); n   for (int i = 1; i <= n; i++) { n     scanf( %d , &h[i]); n     h[i]++; n   } n   for (int i = 0; i <= n; i++) { n     for (int x = 0; x <= 16; x++) { n       for (int y = 0; y <= 16; y++) { n         for (int z = 0; z <= 16; z++) { n           dp[i][x][y][z] = inf; n         } n       } n     } n   } n   f(1, h[1], h[2], h[3], 0, 0, 0, 0, 0); n   for (int i = 1; i < n - 1; i++) { n     int z = h[i + 2]; n     for (int x = 0; x <= h[i]; x++) { n       for (int y = 0; y <= h[i + 1]; y++) { n         int v = dp[i][x][y][z]; n         if (v >= inf) { n           continue; n         } n         for (int j = (x + b - 1) / b;; j++) { n           f(i + 1, y - j * a, z - j * b, h[i + 3], v + j, x, y, z, j); n           if (j * a > y && j * b > z) { n             break; n           } n         } n       } n     } n   } n   find(n - 1, 0, 0, 0); n   cout << ans.size() << endl; n   for (int i = 0; i < ans.size(); i++) { n     printf( %d  , ans[i]); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, arr[2005], counts[2005]; n char c =  a ; n int main() { n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> arr[i]; n   } n   for (int i = n - 1; i >= 0; i--) { n     counts[i] = arr[i]; n     if (arr[i] != 0) { n       for (int j = i - 1; j >= 0; j--) { n         arr[j] -= (i - j + 1) * arr[i]; n       } n     } n   } n   for (int i = 1; i <= n; i++) { n     for (int j = 0; j < counts[i - 1]; j++) { n       for (int k = 0; k < i; k++) { n         cout << c; n       } n       c = ((c ==  a ) ?  b  :  a ); n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   if (n & n - 1) n     puts( NO ); n   else n     puts( YES ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ifstream fin( input.txt ); n   double a, b, c = 1.000000011, d; n   cin >> a >> b; n   d = a * pow(c, b); n   cout.precision(30); n   cout << d << endl; 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, c = 0; n     cin >> n; n     int r = n; n     int cnt = 0; n     while (r > 0) { n       int temp = r % 10; n       if (temp > 0) cnt++; n       r = r / 10; n       c++; n     } n     cout << cnt << endl; n     int it, ans; n     for (int i = 0; i < c; i++) { n       it = n % 10; n       ans = it * pow(10, i); n       if (ans > 0) cout << ans <<    ; n       n = n / 10; n     } n     cout << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n char A[102]; n int M[102][205][3][52]; n int dp(int i, int x, int d, int n) { n   if (n < 0) return 0; n   if (!A[i] && n == 0) return abs(x - 102); n   if (!A[i]) return 0; n   int &r = M[i][x][d == 1][n]; n   if (r == -1) { n     if (A[i] ==  F ) { n       r = max(dp(i + 1, x + d, d, n), n               max(max(dp(i, x, d, n - 2), dp(i + 1, x + d, d, n - 2)), n                   dp(i + 1, x, d * -1, n - 1))); n     } else { n       r = max(dp(i + 1, x, d * -1, n), n               max(max(dp(i, x, d * -1, n - 2), dp(i + 1, x, d * -1, n - 2)), n                   dp(i + 1, x + d, d, n - 1))); n     } n   } n   return r; n } n int main() { n   int n; n   scanf( %s %d , A, &n); n   memset(M, -1, sizeof(M)); n   printf( %d n , dp(0, 102, 1, n)); n } n


#include <bits/stdc++.h> n using namespace std; n long long n, s, k; n string u; n long long r[60], dp[2501][60]; n signed main() { n   cin >> n >> s >> k; n   for (long long i = 0; i < n; ++i) cin >> r[i]; n   cin >> u; n   for (long long i = 0; i < n; ++i) n     for (long long j = 0; j < n; ++j) dp[i][j] = -1e18; n   --s; n   dp[0][s] = r[s]; n   for (long long i = 0; i < s; ++i) dp[s - i][i] = r[i]; n   for (long long i = s + 1; i < n; ++i) dp[i - s][i] = r[i]; n   for (long long i = 1; i <= 2500; ++i) n     for (long long j = 0; j < n; ++j) n       for (long long t = 1; t <= i; ++t) { n         if (j - t >= 0 && u[j - t] != u[j] && r[j - t] < r[j]) n           dp[i][j] = max(dp[i][j], dp[i - t][j - t] + r[j]); n         if (j + t < n && u[j + t] != u[j] && r[j + t] < r[j]) n           dp[i][j] = max(dp[i][j], dp[i - t][j + t] + r[j]); n       } n   for (long long i = 0; i < 2501; ++i) n     for (long long j = 0; j < n; ++j) n       if (dp[i][j] >= k) return cout << i, 0; n   cout << -1; n } n