#include <bits/stdc++.h>   using namespace std;   const int maxn = (int)5e5 + 9;   const int maxm = (int)1e6 + 9;   const long long mod = (long long)1e9 + 7;   const double pi = acos(-1);   const double eps = 1e-15;   vector<pair<int, int> > to[maxn];   int fa[maxn];   int tobig[maxn];   int n, m;   int e[maxn];   int e2[maxn];   int f[maxn];   int fe[maxn];   void init() {     scanf( %d%d , &n, &m);     for (int i = 0; i < m; i++) {       int a, b;       cin >> a >> b;       to[a].emplace_back(i, b);       to[b].emplace_back(i, a);       e[i] = a;       e2[i] = b;     }     memset(tobig, -1, sizeof(tobig));   }   int vis[maxn];   void dfs(int u, int ft) {     vis[u] = -1;     for (int i = 0; i < to[u].size(); i++) {       int v = to[u][i].second;       if (ft == v) continue;       fa[u] = i;       if (vis[v] == 0) {         dfs(v, u);       } else if (vis[v] == -1) {         int mn = maxn;         int mx = -1;         int tmp = v;         vector<int> tot;         do {           int d = to[tmp][fa[tmp]].first;           tot.push_back(d);           mn = min(mn, d);           mx = max(mx, d);           tmp = to[tmp][fa[tmp]].second;         } while (tmp != v);         tobig[mn] = mx;         int mxp, mnp;         int len = tot.size();         for (int x = 0; x < len; x++) {           if (mx == tot[x]) mxp = x;           if (mn == tot[x]) mnp = x;         }         int fl = 0;         for (int x = mxp; x != mnp; x = (x + 1) % len) {           if (tot[x] < tot[(x + 1) % len]) {             fl = 1;             break;           }         }         for (int x = mxp; x != mnp; x = (x + len - 1) % len) {           if (tot[x] < tot[(x + len - 1) % len]) {             fl = 1;             break;           }         }         if (fl) {           tobig[mn] = -1;         }       }     }     vis[u] = 1;   }   int bcj[maxn];   int fd(int x) { return bcj[x] = bcj[x] == x ? x : fd(bcj[x]); }   int main() {     init();     dfs(1, -1);     for (int i = 1; i <= n; i++) {       bcj[i] = i;       f[i] = 1;     }     for (int i = m - 1; i >= 0; i--) {       int fu = fd(e[i]);       int fv = fd(e2[i]);       int tt = f[e[i]] + f[e2[i]];       if (fu == fv) {         if (tobig[i] != -1) {           tt -= fe[tobig[i]];         }       } else {         bcj[fu] = fv;       }       fe[i] = f[e[i]] = f[e2[i]] = tt;     }     for (int i = 1; i <= n; i++) {       cout << f[i] - 1 <<    ;     }     cout << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100100;   int N, M;   vector<int> conn[MAXN];   bool adj[10][10];   bool vis[MAXN];   int deg[10];   int ar[MAXN];   int pa[10];   int pb[10];   int numed;   void prec() {     for (int j = 0; j < numed; ++j) {       int a = 2, b = 1;       for (int k = 0; k < j; ++k) {         if (b + 1 >= a) {           ++a;           b = 1;         } else {           ++b;         }       }       pa[j] = a;       pb[j] = b;     }   }   void go6() {     numed = N * (N - 1) / 2;     prec();     for (int i = 1; i <= N; ++i) {       for (typeof((conn[i]).begin()) j = (conn[i]).begin(), _j = (conn[i]).end();            j != _j; ++j) {         adj[i][*j] = true;       }     }     bool fnd = false;     for (int i = 0; i < (1 << numed); ++i) {       int cnt = 0;       bool bad = false;       for (int j = 1; j <= N; ++j) {         deg[j] = 0;       }       for (int j = 0; j < numed; ++j) {         if ((i >> j) & 1) {           int a = pa[j];           int b = pb[j];           if (adj[a][b]) {             bad = true;             break;           }           ++deg[a];           ++deg[b];           if (deg[a] > 2 || deg[b] > 2) {             bad = true;             break;           }           ++cnt;         }       }       if (bad) continue;       if (cnt != M) continue;       fnd = true;       for (int j = 0; j < numed; ++j) {         if ((i >> j) & 1) {           int a = pa[j], b = pb[j];           printf( %d %d n , a, b);         }       }       break;     }     if (!fnd) {       printf( -1 n );     }   }   int cnt;   bool dfs(int x, int prv = -1) {     if (vis[x]) return true;     vis[x] = true;     ++cnt;     for (typeof((conn[x]).begin()) i = (conn[x]).begin(), _i = (conn[x]).end();          i != _i; ++i) {       if (*i != prv && dfs(*i, x)) {         return true;       }     }     return false;   }   int main() {     scanf( %d %d , &N, &M);     for (int i = 0; i < M; ++i) {       int a, b;       scanf( %d %d , &a, &b);       conn[a].push_back(b);       conn[b].push_back(a);     }     if (N <= 6) {       go6();     } else {       if (M > N) {         printf( -1 n );         return 0;       }       int pos = 0;       for (int i = 1; i <= N; ++i) {         if (!vis[i]) {           cnt = 0;           if (dfs(i)) {             int a = i;             int b = conn[a][0];             int cur = pos;             int end = pos + cnt;             bool up = true;             do {               ar[cur] = a;               int c = conn[b][0];               if (c == a) c = conn[b][1];               a = b;               b = c;               if (up) {                 if (cur + 2 < end)                   cur += 2;                 else {                   if (cur + 1 < end)                     cur += 1;                   else                     cur -= 1;                   up = false;                 }               } else {                 cur -= 2;               }             } while (a != i);           } else {             int a = i;             int b = -1;             while (int((conn[a]).size()) == 2) {               int p = a;               if (conn[a][0] == b)                 a = conn[a][1];               else                 a = conn[a][0];               b = p;             }             int cur = pos;             b = -1;             while (true) {               ar[cur] = a;               ++cur;               if (int((conn[a]).size()) == 0) break;               if (int((conn[a]).size()) == 1 && b != -1) break;               int p = a;               if (conn[a][0] == b)                 a = conn[a][1];               else                 a = conn[a][0];               b = p;             }           }           pos += cnt;         }       }       for (int i = 0; i < M; ++i) {         printf( %d %d n , ar[i], ar[(i + 3) % N]);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, q;   int tim[10000];   int main() {     while (~scanf( %d%d , &n, &q)) {       memset(tim, -1, sizeof(tim));       while (q--) {         int ti, ni, di;         scanf( %d%d%d , &ti, &ni, &di);         int cnt = 0;         for (int i = 1; i <= n; i++) {           if (tim[i] <= ti) tim[i] = -1;         }         for (int i = 1; i <= n; i++) {           if (tim[i] == -1) cnt++;         }         if (cnt >= ni) {           int sum = 0;           for (int i = 1; i <= n; i++) {             if (tim[i] == -1) {               if (ni > 0) {                 tim[i] = ti + di;                 sum += i;                 ni--;               }             }           }           printf( %d n , sum);         } else {           printf( -1 n );         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2000500;   int P[N];   int D[N];   multiset<int> S[N];   inline bool recalc(int x) {     if (x == 1) {       D[x] = *S[x].rbegin() + 1;       return false;     } else {       int nd;       if (S[x].size() == 1)         nd = *S[x].rbegin();       else         nd = max(*S[x].rbegin(), *(++S[x].rbegin()) + 1);       if (nd != D[x]) {         S[P[x]].erase(S[P[x]].find(D[x]));         D[x] = nd;         S[P[x]].insert(nd);         return true;       } else         return false;     }   }   int main() {     int n;     scanf( %d , &n);     P[1] = -1;     D[0] = 1;     for (int i = 2; i < n + 2; i++) {       scanf( %d , &P[i]);       S[P[i]].insert(0);       for (int x = P[i]; recalc(x); x = P[x])         ;       printf( %d  , D[1]);     }     printf(  n );   }


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


#include <bits/stdc++.h>   using namespace std;   int n, k, ans;   int a[500101], b[500101], fl[500101];   int q[500101], qn;   void solve() {     scanf( %d%d , &n, &k);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     for (int i = 1; i <= k; i++) {       scanf( %d , &b[i]);       fl[b[i]] = 1;     }     int fl2 = 0;     for (int i = 2; i <= k; i++)       if (a[b[i]] <= a[b[i - 1]] || a[b[i]] - a[b[i - 1]] < b[i] - b[i - 1]) {         fl2 = 1;         break;       }     if (fl2) {       printf( -1 n );       return;     }     for (int i = 1; i <= n; i++) a[i] -= i;     q[0] = -1000000007;     int last = 0;     for (int i = 1; i <= n; i++) {       if (a[i] >= q[qn]) {         q[++qn] = a[i];         if (fl[i]) last = qn;       } else {         int p = upper_bound(q + 1, q + 1 + qn, a[i]) - q;         if (p > last) {           q[p] = a[i];           if (fl[i]) last = qn = p;         }       }     }     printf( %d n , n - qn);   }   int main() {     int T = 1;     while (T--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 100;   int p[N];   vector<int> G[N];   int mn[N], mx[N], val[N], sum[N], s[N][2], c[N][2], fa[N], mp[N];   int head;   void upd(int x) {     sum[x] = sum[c[x][1]] + sum[c[x][0]] + val[x];     mn[x] = min(mn[c[x][0]],                 min(sum[c[x][0]] + val[x], sum[c[x][0]] + val[x] + mn[c[x][1]]));     mx[x] = max(mx[c[x][0]],                 max(sum[c[x][0]] + val[x], sum[c[x][0]] + val[x] + mx[c[x][1]]));   }   void rot(int x, int d) {     int f = fa[x];     c[f][d ^ 1] = c[x][d];     fa[c[x][d]] = f;     if (fa[f]) c[fa[f]][(c[fa[f]][1] == f)] = x;     fa[x] = fa[f];     c[x][d] = f;     fa[f] = x;     upd(f);     upd(x);   }   void splay(int x, int stop) {     int t, d1, d2;     while ((t = fa[x]) - stop) {       if (fa[t] == stop)         rot(x, (c[fa[x]][0] == x));       else if ((d1 = (c[fa[t]][0] == t)) ^ (d2 = (c[fa[x]][0] == x)))         rot(x, d2), rot(x, d1);       else         rot(t, d1), rot(x, d2);     }     head = stop ? head : x;   }   int Next(int x) {     splay(x, 0);     for (x = c[x][1]; c[x][0]; x = c[x][0])       ;     return x;   }   int Prev(int x) {     splay(x, 0);     for (x = c[x][0]; c[x][1]; x = c[x][1])       ;     return x;   }   void ins(int r, int x) {     if (!r) {       head = x;       return;     }     int f = Next(r);     if (!f) {       fa[x] = r;       c[r][1] = x;       upd(r);     } else {       splay(f, r);       fa[x] = f;       c[f][0] = x;       upd(f);       upd(r);     }     splay(x, 0);   }   int cut(int l, int r) {     int tl = Prev(l), tr = Next(r);     if (!tl && !tr)       return r;     else if (!tl || !tr) {       int d = !tr, f = tr + tl;       splay(f, 0);       int u = c[f][d];       fa[u] = c[f][d] = 0;       upd(f);       return u;     } else {       splay(tr, 0);       splay(tl, tr);       int u = c[tl][1];       fa[u] = c[tl][1] = 0;       upd(tl);       upd(tr);       return u;     }   }   int lasth(int x, int h) {     for (h++;;) {       if (sum[c[x][0]] + val[x] + mx[c[x][1]] >= h &&           sum[c[x][0]] + val[x] + mn[c[x][1]] <= h) {         h -= sum[c[x][0]] + val[x];         x = c[x][1];       } else if (sum[c[x][0]] + val[x] == h)         return (x == s[mp[x]][0] ? mp[x] : p[mp[x]]);       else         x = c[x][0];     }   }   int dis(int a, int b) {     if (a == b) return 0;     int u = s[a][0], v = s[b][0];     splay(v, 0);     splay(u, v);     if ((c[fa[u]][1] == u) == 1) {       swap(u, v);       splay(v, 0);       splay(u, v);     }     int lcah = min(sum[c[u][0]] + val[u],                    min(sum[u] + val[v], sum[c[u][0]] + val[u] + mn[c[u][1]]));     return sum[u] + sum[c[u][0]] + val[u] + val[v] - 2 * lcah;   }   void reorder(int u, int h) {     int x = s[u][0];     splay(x, 0);     int f = lasth(c[x][0], sum[c[x][0]] + val[x] - h - 1);     p[u] = f;     int cuted = cut(s[u][0], s[u][1]);     ins(Prev(s[f][1]), cuted);   }   int T = 0;   void build(int u) {     s[u][0] = ++T;     mp[T] = u;     sum[T] = val[T] = mn[T] = mx[T] = 1;     ins(head, T);     for (int v : G[u]) build(v);     s[u][1] = ++T;     mp[T] = u;     sum[T] = val[T] = mn[T] = mx[T] = -1;     ins(head, T);   }   int main() {     int n, m;     scanf( %d%d , &n, &m);     memset(mx, -63, sizeof mx);     memset(mn, 63, sizeof mn);     for (int i = 0; i < n; i++) {       int sz = 0;       scanf( %d , &sz);       for (int j = 0; j < sz; j++) {         int v;         scanf( %d , &v);         v--;         G[i].push_back(v);         p[v] = i;       }     }     build(0);     for (int i = 0; i < m; i++) {       int c;       scanf( %d , &c);       if (c == 1) {         int u, v;         scanf( %d%d , &u, &v);         u--;         v--;         printf( %d n , dis(u, v));       } else if (c == 2) {         int u, h;         scanf( %d%d , &u, &h);         u--;         reorder(u, h);       } else {         int h;         scanf( %d , &h);         printf( %d n , lasth(head, h) + 1);       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 6;   int n, m;   int a[200];   bool check() {     if (*max_element(a, a + n) != 0) {       return false;     }     return true;   }   void solve() {     int k;     cin >> n >> k;     for (int i = 0; i < n; i++) {       cin >> a[i];     }     if (k == 1) {       if ((count(a, a + n, *max_element(a, a + n))) != n) {         cout << -1 <<   n ;         return;       } else {         cout << 1 <<   n ;         return;       }     }     m = 0;     while (!check()) {       int tmp = k;       m++;       std::vector<int> b(n);       for (int i = 0; i < n; i++) {         if (i == 0) {           tmp--;         } else {           if (a[i] != a[i - 1]) {             if (tmp == 0)               break;             else {               tmp--;             }           }         }         b.push_back(i);       }       for (auto j : b) {         a[j] = 0;       }     }     cout << m <<   n ;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0), cout.tie(0);     int T;     cin >> T;     while (T--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, k, mod = 1000000007, dp[2010][2010];   long long solve(long long num, long long x) {     long long i;     if (x == k) return 1;     if (dp[num][x] != -1) return dp[num][x];     long long res = 0;     for (i = 1; (i * num) <= n; i++) {       res += solve(num * i, x + 1) % mod;     }     return dp[num][x] = (res % mod);   }   int main() {     cin >> n >> k;     memset(dp, -1, sizeof dp);     cout << solve(1, 0);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int n, k, h = 0;     cin >> n >> k;     vector<int> v;     for (int i = 0; i < n; i++) v.push_back(i);     for (int ki = 1; ki <= k; ki++) {       int x;       cin >> x;       x = x - (x / (n)) * (n);       int d = (h + x) % n;       h = d;       if (d == n - 1) h = 0;       n--;       cout << v[d] + 1 <<    ;       vector<int> tmp;       for (int i = 0; i < v.size(); i++)         if (i != d) tmp.push_back(v[i]);       v = tmp;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long int;   using ull = unsigned long long int;   using ld = long double;   using pii = pair<int, int>;   using pll = pair<ll, ll>;   const int INT_INF = (int)(2e9);   const ll LL_INF = (ll)(2e18);   const int NIL = -1;   static mt19937 _g(time(nullptr));   inline ll randint(ll a, ll b) {     ll w = (_g() << 31LL) ^ _g();     return a + w % (b - a + 1);   }   inline void fast_io() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);   };   template <typename T>   inline T sign(T x) {     return T(x > 0) - T(x < 0);   }   template <typename T, typename S>   inline ostream& operator<<(ostream& os, const pair<T, S> p) {     cout <<  [  << p.first <<  ;  << p.second <<  ] ;     return os;   }   template <typename T>   inline ostream& operator<<(ostream& os, const vector<T>& v) {     for (auto el : v) cout << el <<    ;     return os;   }   template <typename T>   inline T fetch() {     T ret;     cin >> ret;     return ret;   }   template <typename T>   inline void goodbye(const T& val) {     cout << val <<   n ;     exit(0);   }   const int MAX_N = (int)1e6 + 777;   const int MOD = (int)1e9 + 7;   int add(int x, int y) { return (x + y >= MOD ? x + y - MOD : x + y); }   int mult(int x, int y) { return (x * 1LL * y) % MOD; }   vector<pii> g[MAX_N];   int n, m, last;   int dist[MAX_N], __Abacaba[MAX_N], head = 0;   int answ[MAX_N], met[MAX_N];   vector<int> layers[MAX_N];   int cls[MAX_N];   pii pr[MAX_N];   void add_edge(int v, int u, int digit) { g[v].emplace_back(u, digit); }   void build_long_edge(int v, int u, int id) {     vector<int> digits;     for (; id > 0; id /= 10) digits.push_back(id % 10);     reverse(digits.begin(), digits.end());     vector<int> path = {v};     for (int i = 0; i < ((int)(digits).size()) - 1; ++i) path.push_back(last++);     path.push_back(u);     for (int i = 0; i + 1 < ((int)(path).size()); ++i)       add_edge(path[i], path[i + 1], digits[i]);   }   void run_bfs(int src) {     for (int v = 0; v < last; ++v) dist[v] = INT_INF;     dist[src] = 0;     __Abacaba[head++] = src;     layers[0].push_back(src);     for (int j = 0; j < head; ++j) {       int v = __Abacaba[j];       for (auto& ed : g[v]) {         int u = ed.first;         if (dist[u] > dist[v] + 1) {           dist[u] = dist[v] + 1;           layers[dist[u]].push_back(u);           __Abacaba[head++] = u;         }       }     }   }   void build_cls() {     for (int lay = 1; !layers[lay].empty(); ++lay) {       for (auto& v : layers[lay]) pr[v] = make_pair(INT_INF, INT_INF);       for (auto& parent : layers[lay - 1]) {         for (auto& ed : g[parent]) {           int v = ed.first;           if (dist[v] == lay)             pr[v] = min(pr[v], make_pair(cls[parent], ed.second));         }       }       vector<pii> ord;       for (auto& v : layers[lay]) ord.push_back(pr[v]);       sort(ord.begin(), ord.end());       for (auto& v : layers[lay])         cls[v] = lower_bound(ord.begin(), ord.end(), pr[v]) - ord.begin();     }   }   void build_answ(int v, int cur) {     met[v] = 1;     answ[v] = cur;     for (auto& ed : g[v]) {       int u = ed.first;       if (dist[u] != dist[v] + 1 || met[u]) continue;       if (pr[u] == make_pair(cls[v], ed.second))         build_answ(u, add(mult(cur, 10), ed.second));     }   }   void solve() {     cin >> n >> m;     last = n;     for (int i = 0; i < m; ++i) {       int v, u;       cin >> v >> u;       --v, --u;       build_long_edge(v, u, i + 1);       build_long_edge(u, v, i + 1);     }     run_bfs(0);     build_cls();     build_answ(0, 0);     for (int v = 1; v < n; ++v) cout << answ[v] <<   n ;   }   int main() {     fast_io();     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int n, m, k, s = 0, sx, sy, num;   char grid[600][600];   bool vis[600][600];   long long int dx[4] = {0, 0, -1, 1};   long long int dy[4] = {-1, 1, 0, 0};   bool check(long long int x, long long int y) {     if (x >= 0 && x < n && y >= 0 && y < m && grid[x][y] ==  .  && !vis[x][y])       return 1;     return 0;   }   void dfs(long long int x, long long int y) {     vis[x][y] = 1;     grid[x][y] =  M ;     if (num >= s - k) return;     for (long long int i = 0; i < 4; i++) {       long long int nx = x + dx[i];       long long int ny = y + dy[i];       if (num >= s - k) {         break;       }       if (check(nx, ny)) {         num++;         dfs(nx, ny);       }     }   }   int main() {     cin >> n >> m >> k;     memset(vis, 0, sizeof vis);     for (long long int i = 0; i < n; i++) {       for (long long int j = 0; j < m; j++) {         cin >> grid[i][j];         if (grid[i][j] ==  . ) {           s++;           sx = i;           sy = j;         }       }     }     num = 1;     dfs(sx, sy);     for (long long int i = 0; i < n; i++) {       for (long long int j = 0; j < m; j++) {         if (grid[i][j] ==  . ) grid[i][j] =  X ;         if (grid[i][j] ==  M ) grid[i][j] =  . ;         cout << grid[i][j];       }       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 505;   unordered_set<int> dp[N];   int main() {     int n, k;     scanf( %d%d , &n, &k);     dp[0].insert(0);     for (int i = 0; i < n; ++i) {       int c;       scanf( %d , &c);       for (int j = k; j >= c; --j) {         for (int l : dp[j - c]) dp[j].insert(l);         for (int l : dp[j - c]) dp[j].insert(l + c);         if (dp[j].size() > 0) dp[j].insert(j);       }     }     printf( %d n , dp[k].size());     vector<int> res;     for (int l : dp[k]) res.push_back(l);     sort(res.begin(), res.end());     for (int l : res) printf( %d  , l);   }


#include <bits/stdc++.h>   using namespace std;   const long double eps = 1e-10;   struct Tpoint {     long double x, y;     void input() {       double _x, _y;       scanf( %lf%lf , &_x, &_y);       x = _x;       y = _y;     }   } C, H, S;   double t1, t2;   long double T1, T2;   long double ret;   long double Fabs(long double x) { return x < 0 ? -x : x; }   long double Fmin(long double x, long double y) { return x < y ? x : y; }   long double Fmax(long double x, long double y) { return x > y ? x : y; }   long double dist2(Tpoint a, Tpoint b) {     return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y);   }   long double dist(Tpoint a, Tpoint b) { return sqrt(Fabs(dist2(a, b))); }   void init() {     scanf( %lf%lf , &t1, &t2);     C.input();     H.input();     S.input();   }   bool Inside(Tpoint A, long double r, Tpoint p) {     return dist2(A, p) < r * r + eps;   }   bool inter(Tpoint A, Tpoint B, long double ra, long double rb) {     return dist(A, B) < ra + rb + eps;   }   void Normalize(long double &x) {     if (x > 1.0) x = 1.0;     if (x < -1.0) x = -1.0;   }   bool inter(Tpoint A, Tpoint B, Tpoint C, long double ra, long double rb,              long double rc) {     if (dist(A, B) < Fabs(ra - rb) + eps) return 1;     long double alpha = atan2(B.y - A.y, B.x - A.x);     long double dis2 = dist2(A, B);     long double cosine =         (ra * ra + dis2 - rb * rb) / (2.0 * ra * sqrt(Fabs(dis2)));     Normalize(cosine);     long double beta = acos(cosine);     Tpoint p;     p.x = A.x + ra * cos(alpha + beta);     p.y = A.y + ra * sin(alpha + beta);     if (Inside(C, rc, p)) return 1;     p.x = A.x + ra * cos(alpha - beta);     p.y = A.y + ra * sin(alpha - beta);     if (Inside(C, rc, p)) return 1;     return 0;   }   bool check(long double cur) {     long double rc = cur, rh = Fmax(0, T2 - cur),                 rs = Fmax(0, T1 - cur - dist(S, H));     if (!inter(C, H, rc, rh) || !inter(C, S, rc, rs) || !inter(H, S, rh, rs))       return 0;     if (inter(C, H, S, rc, rh, rs)) return 1;     if (inter(C, S, H, rc, rs, rh)) return 1;     if (inter(H, S, C, rh, rs, rc)) return 1;     return 0;   }   long double solve() {     T1 = dist(C, S) + dist(S, H) + t1;     T2 = dist(C, H) + t2;     if (T1 - t1 < T2 + eps) return Fmin(T1, T2);     long double L = 0, r = Fmin(T1, T2);     for (int it = 0; it < 100; it++) {       long double mid = (L + r) / 2;       if (check(mid))         L = mid;       else         r = mid;     }     return L;   }   void print() { printf( %.10lf n , (double)solve()); }   int main() {     init();     print();     return 0;   }


#include <bits/stdc++.h>   using ul = std::uint32_t;   using ull = std::uint64_t;   using li = std::int32_t;   using ll = std::int64_t;   using vull = std::vector<ull>;   using vul = std::vector<ul>;   const ul sz = 1 << 18;   const ul base = 1e9 + 7;   class scaler {    public:     ul v = 0;     scaler() = default;     scaler(ul x) : v(x) {}   };   scaler operator+(scaler a, scaler b) {     return scaler(a.v + b.v < base ? a.v + b.v : a.v + b.v - base);   }   scaler operator-(scaler a, scaler b) {     return scaler(a.v < b.v ? a.v + base - b.v : a.v - b.v);   }   scaler operator*(scaler a, scaler b) { return scaler(ull(a.v) * b.v % base); }   template <typename T>   void change(ul pos, const T& v, std::vector<T>& tree) {     for (tree[pos |= sz] = v, pos >>= 1; pos; pos >>= 1) {       tree[pos] = tree[pos << 1] + tree[pos << 1 | 1];     }   }   template <typename T>   T query(ul l, ul r, const std::vector<T>& tree) {     T ret = 0;     for (l = l - 1 | sz, r = r + 1 | sz; l ^ r ^ 1; l >>= 1, r >>= 1) {       if (~l & 1) {         ret = ret + tree[l ^ 1];       }       if (r & 1) {         ret = ret + tree[r ^ 1];       }     }     return ret;   }   std::vector<scaler> atree(sz << 1, ul(0));   vull tree(sz << 1, ul(0));   ul n, q;   vul a(2e5 + 1);   scaler compute(ul l, ul r, ul cut) {     return scaler(query(l, cut - 1, tree) % base) * scaler(a[cut]) -            query(l, cut - 1, atree) + query(cut + 1, r, atree) -            scaler(query(cut + 1, r, tree) % base) * scaler(a[cut]);   }   int main() {     std::ios::sync_with_stdio(false);     std::cin.tie(0);     std::cin >> n >> q;     for (ul i = 1; i <= n; ++i) {       std::cin >> a[i];       a[i] -= i;     }     for (ul i = 1; i <= n; ++i) {       ul w;       std::cin >> w;       change(i, ull(w), tree);       change(i, scaler(a[i]) * scaler(w), atree);     }     for (ul i = 0; i != q; ++i) {       li x, y;       std::cin >> x >> y;       if (x < 0) {         ul id = -x;         ul w = y;         change(id, ull(w), tree);         change(id, scaler(a[id]) * scaler(w), atree);       } else {         ul l = x, r = y;         ull temp = query(l, r, tree);         ul lans = l, rans = r + 1;         while (lans + 1 != rans) {           ul mid = lans + rans >> 1;           if ((query(mid, r, tree) << 1) < temp) {             rans = mid;           } else {             lans = mid;           }         }         std::cout << compute(l, r, lans).v << std::endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int gcd(int x, int y) {     while (x > 0 && y > 0) {       if (x > y) {         x %= y;       } else {         y %= x;       }     }     return x + y;   }   int main() {     int n, k;     cin >> n >> k;     vector<int> a(n + 1);     vector<bool> used(n + 1);     for (int i = 1; i <= n; i++) {       cin >> a[i];     }     int q;     cin >> q;     int tasks = n / k;     int best = -1, worse = 1 << 30;     int ticketsLeft = k;     for (int i = 1; i <= q; i++) {       int curSum = 0;       for (int j = 1; j <= tasks; j++) {         int num;         cin >> num;         if (!used[num] && j == 1) {           ticketsLeft--;         }         used[num] = true;         curSum += a[num];       }       best = max(best, curSum);       worse = min(worse, curSum);     }     vector<int> unUsed;     for (int i = 1; i <= n; i++) {       if (!used[i]) {         unUsed.push_back(a[i]);       }     }     if (unUsed.size() >= tasks && ticketsLeft > 0) {       sort(unUsed.begin(), unUsed.end());       int curSum = 0;       for (int i = 0; i < tasks; i++) {         curSum += unUsed[i];       }       best = max(best, curSum);       worse = min(worse, curSum);       reverse(unUsed.begin(), unUsed.end());       curSum = 0;       for (int i = 0; i < tasks; i++) {         curSum += unUsed[i];       }       best = max(best, curSum);       worse = min(worse, curSum);     }     printf( %.15lf %.15lf n , double(worse) / double(tasks),            double(best) / double(tasks));   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e3 + 10;   char s[N], t[N];   int n;   vector<int> G;   void shift(int x) {     if (x == 0) return;     reverse(s, s + n);     reverse(s + x, s + n);     G.push_back(x);   }   int main() {     scanf( %d%s%s , &n, s, t);     for (int i = 0; i < n; i++) {       int j = i;       while (j < n && s[j] != t[n - i - 1]) j++;       if (j == n) {         puts( -1 );         exit(0);       }       shift(n);       shift(j);       shift(1);     }     printf( %d n , G.size());     for (int i = 0; i < (int)G.size(); ++i) printf( %d  , G[i]);   }


#include <bits/stdc++.h>   using namespace std;   long long n, l;   string s, s1, s2;   int main() {     cin >> n;     getline(cin, s);     while (n--) {       getline(cin, s);       s1 =   ;       s2 =   ;       l = s.length();       for (int i = 0; i <= 4; i++) s1 += s[i];       for (int i = l - 5; i < l; i++) s2 += s[i];       if (s1 ==  miao.  && s2 !=  lala. )         cout <<  Rainbow s  << endl;       else if (s1 !=  miao.  && s2 ==  lala. )         cout <<  Freda s  << endl;       else         cout <<  OMG>.< I don t know!  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, nmax, nrpar, nrimpar, par, impar, i, sol;   int luat[200005];   struct el {     int val, poz;   } a[200005];   bool rearanjare(el x, el y) {     if (x.poz < y.poz)       return 1;     else       return 0;   }   bool comp(el x, el y) {     if (x.val < y.val)       return 1;     else       return 0;   }   int main() {     cin >> n >> nmax;     for (i = 1; i <= n; i++) {       cin >> a[i].val;       a[i].poz = i;       if (a[i].val % 2 == 0)         nrpar++;       else         nrimpar++;       if (a[i].val <= 200000) luat[a[i].val] = 1;     }     sort(a + 1, a + n + 1, comp);     impar = 1;     par = 2;     for (i = 1; i <= n; i++)       if (a[i].val == a[i + 1].val) {         if (nrpar > nrimpar) {           sol++;           if (a[i].val % 2 == 0) {             nrimpar++;             nrpar--;           }           while (luat[impar]) impar += 2;           a[i].val = impar;           luat[impar] = 1;           if (impar > nmax) sol = -1000000;         } else if (nrpar < nrimpar) {           sol++;           if (a[i].val % 2 == 1) {             nrimpar--;             nrpar++;           }           while (luat[par]) par += 2;           a[i].val = par;           luat[par] = 1;           if (par > nmax) sol = -1000000;         } else {           if (a[i].val % 2 == 1) {             sol++;             while (luat[impar]) impar += 2;             a[i].val = impar;             luat[impar] = 1;             if (impar > nmax) sol = -1000000;           } else {             sol++;             while (luat[par]) par += 2;             a[i].val = par;             luat[par] = 1;             if (par > nmax) sol = -1000000;           }         }       }     i = 0;     while (nrpar != nrimpar) {       i++;       if (a[i].val % 2 == 0 and nrpar > nrimpar) {         sol++;         nrimpar++;         nrpar--;         while (luat[impar]) impar += 2;         a[i].val = impar;         luat[impar] = 1;         if (impar > nmax) sol = -1000000;       } else if (a[i].val % 2 == 1 and nrpar < nrimpar) {         sol++;         nrimpar--;         nrpar++;         while (luat[par]) par += 2;         a[i].val = par;         luat[par] = 1;         if (par > nmax) sol = -1000000;       }     }     sort(a + 1, a + n + 1, rearanjare);     if (sol < 0) {       cout << -1;       return 0;     }     cout << sol <<   n ;     for (i = 1; i <= n; i++) cout << a[i].val <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long t;     cin >> t;     while (t--) {       long long n;       cin >> n;       string s, t;       cin >> s >> t;       long long w = 0;       char s1, t1, s2, t2;       int q = 0;       for (long long i = 0; i < n; i++) {         if (s[i] != t[i]) {           w++;         }         if (w == 1 && q == 0) {           s1 = s[i], t1 = t[i];           q++;         }         if (w == 2 && q == 1) {           s2 = s[i], t2 = t[i];           q++;         }       }       if (w != 2) {         cout <<  NO  << endl;       } else {         if (t1 == t2 && s1 == s2)           cout <<  yes  << endl;         else           cout <<  no  << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   int main() {     int a;     scanf( %d , &a);     int m[a];     int p = 1, i;     for (i = 0; i < a; i++) {       scanf( %d , &m[i]);       if (i > 0) {         if (m[i] != m[i - 1]) {           p++;         }       }     }     printf( %d , p);   }


#include <bits/stdc++.h>   using namespace std;   namespace variables {   struct triple {     long long first, second, third;   };   }  // namespace variables   using namespace variables;   void testt();   namespace andu2006 {   void debug(set<long long> _var, string _name =   ) {     cerr <<  Debug #set   << _name <<   = [ ;     for (auto it : _var) cerr << it <<  , ;     cerr <<  END] :            <<  size =   << _var.size() <<   n n ;   }   void light_debug(set<long long> _var, string _name =   ) {     cerr <<  Debug #set   << _name <<   = [ ;     for (auto it : _var) cerr << it <<  , ;     cerr <<  END] n n ;   }   void debug(map<long long, long long> _var, string _name =   ) {     cerr <<  Debug #map (size =   << _var.size() <<  ) n ;     for (auto it : _var)       cerr << _name <<  [  << it.first <<  ] =   << it.second <<   n ;   }   void light_debug(map<long long, long long> _var, string _name =   ) {     cerr <<  Debug #map  n ;     for (auto it : _var)       cerr << _name <<  [  << it.first <<  ] =   << it.second <<   n ;   }   void debug(deque<long long> _var, string _name =   ) {     cerr <<  Debug #deque   << _name <<   = [ ;     for (auto it : _var) cerr << it <<  , ;     cerr <<  END] :            <<  size =   << _var.size() <<   n n ;   }   void light_debug(deque<long long> _var, string _name =   ) {     cerr <<  Debug #deque   << _name <<   = [ ;     for (auto it : _var) cerr << it <<  , ;     cerr <<  END] n n ;   }   void debug(vector<long long> _var, string _name =   ) {     cerr <<  Debug #vector   << _name <<   = [ ;     for (auto it : _var) cerr << it <<  , ;     cerr <<  END] :            <<  size =   << _var.size() <<   n n ;   }   void light_debug(vector<long long> _var, string _name =   ) {     cerr <<  Debug #vector   << _name <<   = [ ;     for (auto it : _var) cerr << it <<  , ;     cerr <<  END] n n ;   }   void debug(string _var, string _name =   ) {     cerr <<  Debug #string   << _name <<   =  ;     cerr <<     << _var <<    ;     cerr <<   :            <<  size =   << _var.size() <<   n n ;   }   void light_debug(string _var, string _name =   ) {     cerr <<  Debug #string :   << _name <<   =   <<     << _var <<     <<   n n ;   }   void debug(long long _var, string _name =   ) {     cerr <<  Debug #int64 :   << _name <<   =   << _var <<   n n ;   }   void debug(unsigned long long _var, string _name =   ) {     cerr <<  Debug #uint64 :   << _name <<   =   << _var <<   n n ;   }   void debug(unsigned int _var, string _name =   ) {     cerr <<  Debug #uint32 :   << _name <<   =   << _var <<   n n ;   }   void debug(int _var, string _name =   ) {     cerr <<  Debug #int32 :   << _name <<   =   << _var <<   n n ;   }   void debug(char _var, string _name =   ) {     cerr <<  Debug #char :   << _name <<   =    << _var <<    n n ;   }   void debug(bool _var, string _name =   ) {     cerr <<  Debug #Boolean :   << _name <<   =   << (_var ?  1 True  :  0 False )          <<   n n ;   }   string emptyString;   vector<long long> emptyVector;   stack<long long> emptyStack;   queue<long long> emptyQueue;   void multipleTests() {     long long __test_count;     cin >> __test_count;     while (__test_count--) testt();   }   void done() { exit(0); }   void fastIO() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);   }   void rseed() { srand(time(NULL)); }   void mreset(void* _pointer, unsigned int _size) { memset(_pointer, 0, _size); }   template <char compArg>   bool compare(long long a, long long b) {     if (compArg ==  < )       return a < b;     else if (compArg ==  > )       return a > b;     return false;   }   template <char compArg1, char compArg2>   bool compair(pair<long long, long long> a, pair<long long, long long> b) {     return compare<compArg1>(a.first, b.first) ||            (a.first == b.first && compare<compArg2>(a.second, b.second));   }   template <char compArg1, char compArg2>   struct objcompair {     bool operator()(pair<long long, long long> a, pair<long long, long long> b) {       return compare<compArg1>(a.first, b.first) ||              (a.first == b.first && compare<compArg2>(a.second, b.second));     }   };   long long trailingZeroes(long long x) {     if (x == 0) return 0;     return (x & 1 ? 0 : 1 + trailingZeroes(x / 2));   }   long long trailingOnes(long long x) {     if (x == 0) return 0;     return (x & 1 ? 1 + trailingZeroes(x / 2) : 0);   }   long long trailingPowerOfTwo(long long x) { return 1ll << trailingZeroes(x); }   long long popCount(long long x) {     if (x == 0) return x;     return 1 + popCount(x & -x);   }   long long log2(long long x) {     if (x == 0) return -1;     return 1 + log2(x / 2);   }   long long getBit(long long x, long long pos) { return (x >> pos) & 1; }   long long cutLastOne(long long x) { return x & -x; }   long long binPow(long long _num, long long _exponent, long long _mod) {     if (_exponent == 0) return 1;     long long _half = binPow(_num, _exponent / 2, _mod);     return _half * _half % _mod * (_exponent & 1 ? _num : 1) % _mod;   }   long long modularInverse(long long _x, long long _mod) {     return binPow(_x, _mod - 2, _mod);   }   long long comb(long long _n, long long _k, long long _mod) {     long long _ans = 1;     for (long long i = _n - _k + 1; i <= _n; i++) _ans = _ans * i % _mod;     for (long long i = 2; i <= _k; i++)       _ans = _ans * modularInverse(i, _mod) % _mod;     return _ans;   }   const long double PI = acos(-1);   const long double rad = 180 / PI;   long double degsin(long long __alpha) { return sin(__alpha / rad); }   long double degcos(long long __alpha) { return cos(__alpha / rad); }   long double degtan(long long __alpha) { return tan(__alpha / rad); }   long double degasin(long long _sine) { return asin(_sine) * rad; }   long double degacos(long long _cosine) { return acos(_cosine) * rad; }   long double degatan(long long _tangent) { return atan(_tangent) * rad; }   long long gcd(long long _num1, long long _num2) {     if (_num2 == 0) return _num1;     return gcd(_num2, _num1 % _num2);   }   long long lcm(long long _num1, long long _num2) {     return _num1 * _num2 / gcd(_num1, _num2);   }   long long divisors(long long _num) {     if (_num == 0) return 0;     long long _cnt = 1, _exp;     while (_num % 2 == 0) {       _cnt++;       _num /= 2;     }     for (long long _divisor = 3; _divisor * _divisor <= _num; _divisor += 2) {       _exp = 0;       while (_num % _divisor == 0) {         _exp++;         _num /= _divisor;       }       _cnt *= (_exp + 1);     }     if (_num > 1) _cnt *= 2;     return _cnt;   }   long long eulerTotient(long long _num) {     if (_num == 0) return 0;     long long _cnt = 1, _divisor = 2;     while (_num % _divisor == 0) {       _cnt *= _divisor;       _num /= _divisor;     }     _cnt /= _divisor;     _cnt *= (_divisor - 1);     for (long long _divisor = 3; _divisor * _divisor <= _num; _divisor += 2) {       if (_num % _divisor == 0) {         while (_num % _divisor == 0) {           _cnt *= _divisor;           _num /= _divisor;         }         _cnt /= _divisor;         _cnt *= (_divisor - 1);       }     }     if (_num > 1) _cnt *= _num - 1;     return _cnt;   }   void sieve(bool* _startpos, bool* _endpos) {     long long _maxnum = _endpos - _startpos;     for (long long i = 4; i < _maxnum; i += 2) *(_startpos + i) = 1;     for (long long i = 3; i * i < _maxnum; i += 2)       if (*(_startpos + i) == 0)         for (long long j = i * i; j < _maxnum; j += i) *(_startpos + j) = 1;   }   }  // namespace andu2006   void testt() {}   set<long long> points;   long long pos[100001], fr[100001], p[5001], sizp;   int main() {     andu2006::fastIO();     long long p1[100], p2[100], n, m;     for (long long i = 0; i < 100001; i++) pos[i] = -1;     cin >> n >> m;     for (long long i = 0; i < n; i++) cin >> p1[i];     for (long long i = 0; i < m; i++) {       cin >> p2[i];       pos[p2[i] + 40000] = i;       fr[p2[i] + 40000]++;       for (long long j = 0; j < n; j++) points.insert(p1[j] + p2[i]);     }     long long ans = 0;     bool b1[61] = {0}, b2[61] = {0};     for (auto it : points) p[sizp++] = it;     for (long long i = 0; i < sizp; i++) {       for (long long j = i; j < sizp; j++) {         for (long long k = 0; k < n; k++) {           if (pos[p[i] - p1[k] + 40000] != -1) {             b2[pos[p[i] - p1[k] + 40000]] = 1;             b1[k] = 1;           }           if (pos[p[j] - p1[k] + 40000] != -1) {             b2[pos[p[j] - p1[k] + 40000]] = 1;             b1[k] = 1;           }         }         long long cnt = 0;         for (long long i = 0; i < max(n, m); i++) {           if (b1[i] == 1) cnt++;           if (b2[i] == 1) cnt += fr[p2[i] + 40000];           b1[i] = b2[i] = 0;         }         ans = max(ans, cnt);       }     }     cout << ans;     andu2006::done();   }


#include <bits/stdc++.h>   using namespace std;   long long power(long long a, long long b, long long mod) {     if (b == 0) return 1;     long long val = power(a, b >> 1, mod);     long long ans = ((val % mod) * (val % mod)) % mod;     if (b % 2 != 0) ans = ((ans % mod) * (a % mod)) % mod;     return ans;   }   int m[1002][1002] = {0};   int m2[1002][1002] = {0};   int main(void) {     int h, w;     cin >> h >> w;     vector<int> R, C;     for (int i = 0; i < h; i++) {       int r;       cin >> r;       for (int j = 0; j < r; j++) m[i][j] = 1;       R.push_back(r);     }     for (int i = 0; i < w; i++) {       int r;       cin >> r;       for (int j = 0; j < r; j++) m[j][i] = 1;       C.push_back(r);     }     for (int i = 0; i < h; i++) {       int c = 0;       for (int j = 0; j < w; j++) {         if (m[i][j] == 0) break;         c++;       }       if (c != R[i]) {         cout << 0 << endl;         return 0;       }     }     for (int i = 0; i < w; i++) {       int c = 0;       for (int j = 0; j < h; j++) {         if (m[j][i] == 0) break;         c++;       }       if (c != C[i]) {         cout << 0 << endl;         return 0;       }     }     long long cnt = 0;     for (int i = 0; i < h; i++) {       for (int j = 0; j < w; j++) {         if (m[i][j] == 0) {           for (int l = j + 1; l < w; l++) {             if (m[i][l] != 1) m2[i][l]++;           }           break;         }       }     }     for (int i = 0; i < w; i++) {       for (int j = 0; j < h; j++) {         if (m[j][i] == 0) {           for (int l = j + 1; l < h; l++) {             if (m[l][i] != 1) m2[l][i]++;           }           break;         }       }     }     for (int i = 0; i < h; i++) {       for (int j = 0; j < w; j++)         if (m2[i][j] == 2) cnt++;     }     cout << power(2, cnt, 1000000007) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   int dx[8] = {1, -1, 0, 0, -1, -1, 1, 1};   int dy[8] = {0, 0, -1, 1, -1, 1, -1, 1};   vector<int> adj[300010], val(300010, 1), vis(300010, 0), dis1(300010, 0),       dis2(300010, 0);   int myrandom(int i) { return std::rand() % i; }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long n, t;     long double p;     cin >> n >> p >> t;     long double dp[t + 2][n + 2];     memset(dp, 0, sizeof(dp));     dp[0][0] = 1;     for (int i = 0; i <= t; i++) {       for (int j = 0; j <= n; j++) {         if (j < n) {           dp[i + 1][j + 1] += dp[i][j] * p;           dp[i + 1][j] += dp[i][j] * (1 - p);         } else {           dp[i + 1][j] += dp[i][j];         }       }     }     long double ans = 0;     for (int i = 1; i <= n; i++) {       ans = ans + i * (dp[t][i]);     }     cout << fixed << setprecision(20) << ans <<   n ;   }


#include <bits/stdc++.h>   int main() {     char a[200];     int n;     bool plat[200];     scanf( %d , &n);     scanf( %s , a);     for (int i = 0; i < n; i++) {       if (a[i] ==  * )         plat[i] = true;       else         plat[i] = false;     }     bool ans = false;     for (int i = 0; i < n; i++) {       if (!plat[i]) continue;       for (int m = 1; i + m * 4 < n; m++) {         if (plat[i + m] && plat[i + 2 * m] && plat[i + 3 * m] &&             plat[i + 4 * m]) {           ans = true;           break;         }       }     }     printf( %s , ans ?  yes n  :  no n );   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n, p;     cin >> n >> p;     vector<int> a(n);     for (auto &i : a) cin >> i;     int m = *max_element((a).begin(), (a).end());     vector<int> freq(m + n + 10);     for (int i = 0; i < n; i++) {       freq[a[i]]++;     }     for (int i = 1; i < m + n + 10; i++) {       freq[i] += freq[i - 1];     }     vector<int> ans;     for (int x = max(1, m - n + 1); x < m; x++) {       int i = 0;       while (i < n) {         int vals = (freq[x + i] - i);         if (vals % p == 0) {           break;         }         i++;       }       if (i == n) ans.push_back(x);     }     cout << ans.size() << endl;     for (auto &x : ans) {       cout << x <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 5;   template <class T>   void read(vector<T> &arr) {     for (auto &x : arr) cin >> x;   }   template <class T>   void read(T &x) {     cin >> x;   }   template <class T>   void write(vector<T> &arr) {     for (auto x : arr) cout << x <<    ;     cout <<   n ;   }   template <class T>   void write(vector<vector<T>> &arr) {     for (auto &x : arr) {       for (auto &y : x) cout << y <<    ;       cout <<   n ;     }   }   template <class T>   void write(T &x) {     cout << x;   }   void solve() {     long long n;     cin >> n;     vector<long long> arr(n);     read(arr);     long long ans = 0;     bool isStarted = false;     for (long long i = 0; i < n; ++i) {       if (arr[i] == 1) {         isStarted = true;       }       if (arr[i] == 0 && isStarted) ans++;     }     for (long long i = n - 1; i > -1; --i) {       if (arr[i] == 1) break;       if (arr[i] == 0) ans--;     }     cout << ans <<   n ;   }   int32_t main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     long long t = 1;     cin >> t;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     int t;     cin >> t;     while (t--) {       long long n, m;       cin >> n >> m;       vector<string> ar(11);       for (int i = 0; i < n; i++) {         cin >> ar[i];       }       string ans;       bool res = false;       for (int i = 0; i < m && !res; i++) {         for (int j = 0; j < 26 && !res; j++) {           string s = ar[0];           s[i] =  a  + j;           bool te = true;           for (int k = 0; k < n; k++) {             long long co = 0;             for (int l = 0; l < m; l++) {               if (ar[k][l] != s[l]) {                 co++;               }             }             if (co > 1) {               te = false;               break;             }           }           if (te) {             cout << s << endl;             res = true;             break;           }         }       }       if (!res) {         cout << -1 << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, i;     cin >> n;     string s;     cin >> s;     map<char, long long int> a;     if (n > 26) {       cout << -1 << endl;       return 0;     }     long long int ans = 0;     for (i = 0; i < n; i++) {       if (a[s[i]] >= 1) ans++;       a[s[i]]++;     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   long long max(long long a, long long b) {     if (a > b) {       return a;     } else {       return b;     }   }   long long min(long long a, long long b) {     if (a < b) {       return a;     } else {       return b;     }   }   struct P {     double x, y;     P() {}     P(double x, double y) : x(x), y(y) {}     P operator+(const P &a) const { return P(x + a.x, y + a.y); }     P operator-(const P &a) const { return P(x - a.x, y - a.y); }     double operator^(const P &a) const { return x * a.x + y * a.y; }     void in() { scanf( %lf%lf , &x, &y); }     void out() { printf( REQUIRED %.7f %.7f n , x, y); }     double dist(P a, P b) {       return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));     }     double sqdist(P a, P b) {       return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y);     }   };   int m, n;   int ma[50001][101];   int fin[50001][101];   int main() {     scanf( %d%d , &m, &n);     for (int i = (1); i <= (m); i++)       for (int j = (1); j <= (n); j++) scanf( %d , &ma[i][j]);     fin[1][1] = ma[1][1];     for (int i = (2); i <= (m); i++) fin[i][1] = fin[i - 1][1] + ma[i][1];     for (int j = (2); j <= (n); j++) {       fin[1][j] = ma[1][j] + fin[1][j - 1];       for (int i = (2); i <= (m); i++)         fin[i][j] = max(fin[i - 1][j] + ma[i][j], fin[i][j - 1] + ma[i][j]);     }     for (int i = (1); i <= (m); i++) printf( %d  , fin[i][n]);     puts(  );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void canhazfast() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);   }   template <typename T>   T gcd(T a, T b) {     return b ? gcd(b, a % b) : a;   }   template <typename T>   T extgcd(T a, T b, T &x, T &y) {     T x0 = 1, y0 = 0, x1 = 0, y1 = 1;     while (b) {       T q = a / b;       a %= b;       swap(a, b);       x0 -= q * x1;       swap(x0, x1);       y0 -= q * y1;       swap(y0, y1);     }     x = x0;     y = y0;     return a;   }   int ctz(unsigned x) { return __builtin_ctz(x); }   int ctzll(unsigned long long x) { return __builtin_ctzll(x); }   int clz(unsigned x) { return __builtin_clz(x); }   int clzll(unsigned long long x) { return __builtin_clzll(x); }   int popcnt(unsigned x) { return __builtin_popcount(x); }   int popcntll(unsigned long long x) { return __builtin_popcountll(x); }   int bsr(unsigned x) { return 31 ^ clz(x); }   int bsrll(unsigned long long x) { return 63 ^ clzll(x); }   map<int, long long> in[100016], out[100016];   void do_vertex(int u) {     for (auto i = in[u].begin(), j = out[u].begin();          i != in[u].end() && j != out[u].end();) {       int s, t;       long long fs, ft;       tie(s, fs) = *i;       tie(t, ft) = *j;       long long z = min(fs, ft);       if (z > 0) {         out[s][u] -= z;         in[t][u] -= z;         i->second -= z;         j->second -= z;         if (s != t) {           out[s][t] += z;           in[t][s] += z;         }       }       if (i->second == 0) i = in[u].erase(i);       if (j->second == 0) j = out[u].erase(j);     }   }   int main() {     canhazfast();     int n, m;     vector<pair<pair<int, int>, long long>> ans;     cin >> n >> m;     for (int i = 0; i < m; ++i) {       int u, v, w;       cin >> u >> v >> w;       out[u][v] += w;       in[v][u] += w;     }     for (int i = 1; i <= n; ++i) do_vertex(i);     for (int i = 1; i <= n; ++i) {       for (const auto &x : out[i]) {         if (!x.second || x.first == i) continue;         ans.emplace_back(pair<int, int>(i, x.first), x.second);       }     }     cout << ans.size() <<   n ;     for (const pair<pair<int, int>, long long> e : ans) {       cout << e.first.first <<     << e.first.second <<     << e.second <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   #include<string>   #define M 10000000000007   using namespace std;   typedef long long int ll;   int gcd(int a,int b)   {       if (a == 0)           return b;       return gcd(b % a, a);   }   int modpow(int x,int n)   {       int result=1;       while(n>0)       {           if(n % 2 ==1)               result=((result%M) * (x%M))%M;           x=((x%M)*(x%M))%M;           n=n/2;       }       return result;   }   int lcm(int a,int b)   {       return (a*b)/(gcd(a,b));   }   bool isprime(int n)   {       if(n<2)           return false;       for(int i=2; i<=sqrt(n); i++)           if(n%i==0)               return false;       return true;   }   int ctoi(char c)   {       return c-48;   }   bool visited[1000000] {false};   void add_edge(vector<int> v[],int x,int y)   {       v[x].push_back(y);       v[y].push_back(x);   }   void dfs(vector<int> v[],int e)   {       visited[e] = true;       for(int i=0; i<v[e].size(); i++)       {           if(!visited[v[e][i]])           {               dfs(v,v[e][i]);           }       }   }   int func(int n)   {       if(isprime(n))       {           return 2*n;       }       else       {           int idx = 0;           for(int i=2; i<=n; i++)           {               if(n%i==0)               {                   idx = i;                   break;               }           }           return (idx+n);       }   }   int maxSubArraySum(ll a[], ll size)   {       int max_so_far = INT_MIN, max_ending_here = 0,l=0;          for (int i = 0; i < size; i++)       {           max_ending_here = max_ending_here + a[i];           if (max_so_far < max_ending_here)           {               max_so_far = max_ending_here;               l++;           }                 if (max_ending_here < 0)           {               max_ending_here = 0;              }          }       if(l==size)max_so_far=INT_MAX;       return max_so_far;   }      int main()   {    int t;    cin>>t;    while(t--)    {        ll a1,b1,a2,b2,a3,b3;     cin>>a1>>b1>>a2>>b2>>a3>>b3;     ll ans=abs(a1-a2)+abs(b1-b2);     if(a1==a2 && a1==a3 )           {               if((b3>b1 && b3<b2) || (b3>b2 && b3<b1))ans+=2;           }           if(b1==b2 && b1==b3 )           {               if((a3>a1 && a3<a2) || (a3>a2 && a3<a1))ans+=2;           }     cout<<ans<<endl;             }    return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, cnt = 0, x, i;     scanf( %d , &n);     while (n--) {       scanf( %d , &x);       if (x == 1) cnt++;     }     if (cnt)       cout << -1 << endl;     else       cout << 1 << endl;     return 0;   }


#include <bits/stdc++.h>   int main() {     double k, b, n, t;     double bacteria = 1;     double time = 0;     scanf( %lf %lf %lf %lf , &k, &b, &n, &t);     while (bacteria <= t) {       bacteria = (k * bacteria + b);       if (bacteria > t) {         break;       } else if (bacteria == t) {         time++;         break;       }       time++;     }     if (time > n) {       n = 0;     } else {       n -= time;     }     printf( %0.0lf n , n);     return 0;   }


#include <bits/stdc++.h>   const static long long INF = 0x3f3f3f3f;   static inline void setio(void);   long long dp[5002][5002];   int main(void) {     setio();     memset(dp, 0, sizeof(dp));     long long n, m;     std::cin >> n >> m;     std::string s;     for (long long i = 0; i < n; ++i) {       std::cin >> s;       for (long long j = 0, k; j < m;) {         if (s[j] !=  1 ) {           ++j;           continue;         }         for (k = j + 1; k < m && s[k] ==  1 ; ++k)           ;         ++dp[j][k - 1];         j = k + 1;       }     }     for (long long j = 0; j < m; ++j) {       for (long long k = m - 2; k >= j; --k) dp[j][k] += dp[j][k + 1];     }     for (long long j = 1; j < m; ++j) {       for (long long k = 0; k < m; ++k) dp[j][k] += dp[j - 1][k];     }     long long best = 0;     for (long long i = 0; i < m; ++i)       for (long long j = 0; j < m; ++j)         best = std::max(best, (j - i + 1) * dp[i][j]);     std::cout << best <<   n ;     return 0;   }   static inline void setio(void) {     std::ios::sync_with_stdio(false);     std::cin.tie(nullptr);     std::cout.precision(10);     std::cout << std::fixed;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long int;   using ull = unsigned long long int;   using ld = long double;   using pii = pair<int, int>;   using pll = pair<ll, ll>;   const int INT_INF = (int)(2e9);   const ll LL_INF = (ll)(2e18);   const ll mod = 1e9 + 7;   const int NIL = -1;   static mt19937 _g(time(nullptr));   inline ll randint(ll a, ll b) {     ll w = (_g() << 31LL) ^ _g();     return a + w % (b - a + 1);   }   inline void fast_io() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);   };   template <typename T>   inline T sign(T x) {     return T(x > 0) - T(x < 0);   }   template <typename T, typename S>   inline ostream& operator<<(ostream& os, const pair<T, S> p) {     cout <<  [  << p.first <<  ;  << p.second <<  ] ;     return os;   }   template <typename T>   inline ostream& operator<<(ostream& os, const vector<T>& v) {     for (auto el : v) cout << el <<    ;     return os;   }   struct edge {     int v, u;     ll weight;     int id;     edge(int _v, int _u, ll _weight, int _id)         : v(_v), u(_u), weight(_weight), id(_id) {}     bool operator<(const edge& other) const { return weight < other.weight; }   };   const int MAX_N = (int)1e5 + 77;   int n, m;   vector<edge> edges;   namespace dsu {   int p[MAX_N], r[MAX_N];   inline void clear() {     for (int i = 0; i < n; ++i) p[i] = i, r[i] = 1;   }   int get(int v) {     if (p[v] == v) return v;     return (p[v] = get(p[v]));   }   inline void merge(int v, int u) {     v = get(v), u = get(u);     if (v != u) {       if (r[v] > r[u]) swap(v, u);       p[v] = u;     }   }   }  // namespace dsu   namespace mst {   inline ll get(int forced_edge) {     dsu::clear();     ll answ = 0;     if (forced_edge != NIL) {       answ += edges[forced_edge].weight;       dsu::merge(edges[forced_edge].v, edges[forced_edge].u);     }     for (auto edge : edges) {       if (dsu::get(edge.v) != dsu::get(edge.u)) {         answ += edge.weight;         dsu::merge(edge.v, edge.u);       }     }     return answ;   }   }  // namespace mst   inline bool check(ll M) {     int forced = NIL;     for (int i = 0; i < m; ++i)       if (edges[i].id == 0) forced = i;     edges[forced].weight = M;     sort(edges.begin(), edges.end());     for (int i = 0; i < m; ++i)       if (edges[i].id == 0) forced = i;     ll mst_cost = mst::get(NIL);     ll forced_cost = mst::get(forced);     return mst_cost == forced_cost;   }   void solve() {     cin >> n >> m;     for (int i = 0; i < m; ++i) {       int v, u;       ll weight;       cin >> v >> u >> weight;       edges.emplace_back(v - 1, u - 1, weight, i);     }     ll L = 0, R = (ll)1e9 + 77;     while (R - L > 1) {       ll M = (L + R) / 2;       if (check(M))         L = M;       else         R = M;     }     cout << min(L, (ll)1e9) <<   n ;   }   int main() {     fast_io();     solve();     return 0;   }


#include <bits/stdc++.h>   const double eps = (1e-10);   using namespace std;   int dcmp(double a, double b) {     return fabs(a - b) <= eps ? 0 : (a > b) ? 1 : -1;   }   int getBit(int num, int idx) { return ((num >> idx) & 1) == 1; }   int setBit1(int num, int idx) { return num | (1 << idx); }   int setBit0(int num, int idx) { return num & ~(1 << idx); }   int flipBit(int num, int idx) { return num ^ (1 << idx); }   int countNumBit1(int mask) {     int ret = 0;     while (mask) {       mask &= (mask - 1);       ++ret;     }     return ret;   }   string str;   vector<string> v1;   vector<pair<string, int> > v;   map<string, int> vis;   int n, num, vs[100];   void put(int vs[]) {     string strr = str;     for (int i = 0; i < n; i++) {       if (!vs[i]) {         strr[i] = (strr[i] ==  0  ?  1  :  0 );       }     }     v1.push_back(strr);   }   void fun(int st, int c) {     if (c == num) {       put(vs);       return;     }     for (int i = st; i < n; i++) {       vs[i] = 1;       fun(i + 1, c + 1);       vs[i] = 0;     }     return;   }   bool check(string s1, string s2, int sam) {     int cnt = 0;     for (int i = 0; i < ((int)(s1).size()); i++) {       if (s1[i] == s2[i]) cnt++;     }     if (cnt == sam) return 1;     return 0;   }   int main() {     int m;     scanf( %d %d , &n, &m);     char stt[39];     string st;     int rig;     for (int i = 0; i < m; i++) {       scanf( %s %d , &stt, &rig);       st = stt;       vis[st] = 1;       v.push_back(make_pair(st, rig));     }     str = v[0].first;     num = v[0].second;     fun(0ll, 0);     long long ans = 0;     for (int i = 0; i < ((int)(v1).size()); i++) {       st = v1[i];       bool ok = 1;       for (int j = 1; j < m && ok; j++) {         if (!check(st, v[j].first, v[j].second)) ok = 0;       }       if (ok) {         if (vis.find(v1[i]) == vis.end()) ans++;       }     }     printf( %I64d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   void fastio() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);   }   void one();   int main() {     fastio();     int t = 1;     for (int i = 0; i < t; ++i) {       one();     }     return 0;   }   void one() {     long long n;     cin >> n;     long long sum = n;     for (long long i = 2; i * i <= n; i++) {       while (n % i == 0) {         n /= i;         sum += n;       }     }     if (n > 1) {       sum++;     }     cout << sum << endl;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e9 + 7;   const long long N = 1e6 + 10;   char s[N];   long long a[N];   long long n, k;   int main() {     long long i, len, j;     long long tmp, flag, len_q = 0;     scanf( %lld%lld , &n, &k);     n++;     for (i = 1; i <= n; i++) {       scanf( %s , s);       len = strlen(s);       if (s[0] ==  ? ) {         a[i] = INF;         len_q++;         continue;       }       flag = 0;       tmp = 0;       for (j = 0; j < len; j++) {         if (s[j] ==  - )           flag = 1;         else {           tmp *= 10;           tmp += s[j] -  0 ;         }       }       if (flag) tmp = -tmp;       a[i] = tmp;     }     if (k == 0) {       if (a[1] == INF) {         if ((n - len_q) % 2) {           printf( YES n );           return 0;         } else {           printf( NO n );           return 0;         }       } else {         if (a[1] == 0) {           printf( YES n );           return 0;         } else {           printf( NO n );           return 0;         }       }     } else {       tmp = 0;       if (len_q == 0) {         for (i = n; abs(tmp) < 1e14 && i >= 1; i--) {           tmp *= k;           tmp += a[i];         }         if (tmp == 0)           printf( YES n );         else           printf( NO n );       } else {         if (n % 2 == 0) {           printf( YES n );           return 0;         } else {           printf( NO n );           return 0;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   T CMP_MIN(T a, T b) {     return a < b;   }   template <class T>   T CMP_MAX(T a, T b) {     return a > b;   }   template <class T>   T MAX(T a, T b) {     return a > b ? a : b;   }   template <class T>   T MIN(T a, T b) {     return a < b ? a : b;   }   template <class T>   T GCD(T a, T b) {     return b ? GCD(b, a % b) : a;   }   template <class T>   T LCM(T a, T b) {     return a / GCD(a, b) * b;   }   const int MAXN = 110000;   const int MAXM = 1000006;   const double eps = 1e-10;   const long long MOD = 1000000007;   int n, k, l, r, sa, sk;   int main() {     while (~scanf( %d %d %d %d %d %d , &n, &k, &l, &r, &sa, &sk)) {       int p = sk % k, v = sk / k;       printf( %d , v + (p ? 1 : 0));       for (int i = 1; i < k; i++) {         printf(  %d , v + (i < p ? 1 : 0));       }       if (k < n) {         p = (sa - sk) % (n - k);         v = (sa - sk) / (n - k);         for (int i = 0; i < n - k; i++) {           printf(  %d , v + (i < p ? 1 : 0));         }       }       printf(  n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     int xs[200000], ys[200000];     cin >> n;     for (int i = 0; i < n; i++) {       cin >> xs[i] >> ys[i];     }     map<int, int> vert, hor;     for (int i = 0; i < n; i++) {       int x, y;       x = xs[i];       y = ys[i];       int v = x - y + 1;       int h = y + x - 1;       int buf;       buf = vert[v];       vert[v] = buf + 1;       buf = hor[h];       hor[h] = buf + 1;     }     long long res = 0;     for (map<int, int>::iterator it = vert.begin(); it != vert.end(); ++it) {       long long buf = (long long)it->second;       buf--;       long long sum = (buf * buf + buf) / 2;       res += sum;     }     for (map<int, int>::iterator it = hor.begin(); it != hor.end(); ++it) {       long long buf = (long long)it->second;       buf--;       long long sum = (buf * buf + buf) / 2;       res += sum;     }     cout << res;   }


#include <bits/stdc++.h>   int main() {     long long int n, m, i, c = 0;     scanf( %lld %lld , &n, &m);     long long int a[m];     for (i = 0; i < m; i++) {       scanf( %lld , &a[i]);     }     for (i = 0; i < m - 1; i++) {       if (a[i + 1] > a[i]) {         c = c + a[i + 1] - a[i];       } else if (a[i] == a[i + 1]) {         c = c;       } else {         c = c + n + a[i + 1] - a[i];       }     }     c = a[0] + c - 1;     printf( %lld , c);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   map<char, char> a;   int main() {     string s1, s2;     cin >> s1 >> s2;     int dl = s1.size();     int k = 0;     for (int i = 0; i < dl; i++) {       char p1 = s1[i];       char p2 = s2[i];       map<char, char>::iterator it = a.find(p1);       if (it == a.end()) {         a[p1] = p2;         if (p1 == p2) k++;       } else if (it->second != p2) {         cout << -1;         exit(0);       }       it = a.find(p2);       if (it == a.end()) {         a[p2] = p1;         if (p1 == p2) k++;       } else if (it->second != p1) {         cout << -1;         exit(0);       }     }     cout << (a.size() - k) / 2 <<   n ;     for (map<char, char>::iterator it = a.begin(); it != a.end(); it++) {       if (it->first >= it->second) continue;       cout << it->first <<     << it->second <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, s;     long long v[100005], a[100005], b[100005];     long long sum = 0;     vector<pair<pair<long long, long long>, pair<long long, long long> > > vvv;     scanf( %lld %lld , &n, &s);     for (int i = 0; i < n; i++) {       scanf( %lld %lld %lld , v + i, a + i, b + i);       vvv.push_back(           make_pair(make_pair(abs(a[i] - b[i]), v[i]), make_pair(a[i], b[i])));       sum += v[i];     }     sort(vvv.begin(), vvv.end());     long long qtd = ceil((sum) / (double)s);     long long ans = 0;     long long qt1 = 0, qt2 = 0, tt = 0;     for (int i = 0; i < n; i++) {       if (vvv[i].second.first > vvv[i].second.second) {         qt1 += vvv[i].first.second;         ans += vvv[i].second.first * vvv[i].first.second;       } else if (vvv[i].second.first < vvv[i].second.second) {         qt2 += vvv[i].first.second;         ans += vvv[i].second.second * vvv[i].first.second;       } else {         tt += vvv[i].first.second;         ans += vvv[i].second.second * vvv[i].first.second;       }     }     long long ans1 = ans, ans2 = ans;     long long qtt1 = qt1 + tt, qtt2 = qt2;     int id = 0;     while (ceil((qtt1) / (double)s) + ceil((qtt2) / (double)s) > qtd) {       if (vvv[id].second.first >= vvv[id].second.second) {         if (vvv[id].first.second >= (qtt1) % s) {           long long aux = (qtt1) % s;           qtt1 -= aux;           ans1 -= vvv[id].second.first * aux;           qtt2 += aux;           ans1 += vvv[id].second.second * aux;           continue;         }         qtt1 -= vvv[id].first.second;         ans1 -= vvv[id].second.first * vvv[id].first.second;         qtt2 += vvv[id].first.second;         ans1 += vvv[id].second.second * vvv[id].first.second;       }       id++;     }     id--;     qtt1 = qt1;     qtt2 = qt2 + tt;     id = 0;     while (ceil((qtt1) / (double)s) + ceil((qtt2) / (double)s) > qtd) {       if (vvv[id].second.first <= vvv[id].second.second) {         if (vvv[id].first.second >= (qtt2) % s) {           long long aux = (qtt2) % s;           qtt2 -= aux;           ans2 -= vvv[id].second.second * aux;           qtt1 += aux;           ans2 += vvv[id].second.first * aux;           continue;         }         qtt2 -= vvv[id].first.second;         ans2 -= vvv[id].second.second * vvv[id].first.second;         qtt1 += vvv[id].first.second;         ans2 += vvv[id].second.first * vvv[id].first.second;       }       id++;     }     id--;     printf( %lld n , max(ans1, ans2));     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:536870912 )   #pragma warning(disable : 4996)   using namespace std;   const int N = 1e5 + 100;   map<int, vector<pair<int, int>>> mp;   pair<pair<int, int>, int> a[N];   pair<pair<int, int>, pair<int, int>> d[N];   int t[N];   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d%d , &a[i].first.first, &a[i].first.second);       a[i].second = i;     }     sort(a, a + n);     int m;     scanf( %d , &m);     for (int i = 0; i < m; i++) {       scanf( %d%d%d , &d[i].first.first, &d[i].first.second, &d[i].second.first);       d[i].second.second = i;     }     sort(d, d + m);     int j = 0;     for (int i = 0; i < n; i++) {       while (j < m && d[j].first.first <= a[i].first.first) {         mp[d[j].first.second].push_back({d[j].second.second, d[j].second.first});         j++;       }       auto it = mp.lower_bound(a[i].first.second);       if (it == mp.end()) {         printf( NO );         return 0;       }       it->second.back().second--;       t[a[i].second] = it->second.back().first + 1;       if (it->second.back().second == 0) {         it->second.pop_back();         if (it->second.empty()) mp.erase(it);       }     }     printf( YES n );     for (int i = 0; i < n; i++) printf( %d  , t[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int m = -2000000000, n = 2000000000;   int main() {     char useless[100];     int t;     cin >> t;     getchar();     while (t--) {       char a, c;       int k;       char o;       bool flag = true;       scanf( %c%c , &a, &c);       if (c ==  = ) flag = false;       scanf( %d , &k);       scanf( %c%c , &o, &o);       gets(useless);       if (o ==  Y ) {         if (a ==  > )           m = max(m, k + flag);         else           n = min(n, k - flag);       } else {         flag = !flag;         if (a ==  < )           m = max(m, k + flag);         else           n = min(n, k - flag);       }     }     if (m > n)       cout <<  Impossible ;     else       cout << m;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     int N, M;     string K;     while (cin >> N >> M >> K) {       K = K.substr(2);       stringstream ss(K);       int k;       ss >> k;       map<string, int> inp;       for (int i = 0; i < (int)(N); i++) {         string name;         int level;         cin >> name >> level;         level = (level * k) / 100;         if (level >= 100) {           inp.insert(make_pair(name, level));         }       }       for (int i = 0; i < (int)(M); i++) {         string name;         cin >> name;         if (inp.count(name) == 0) inp[name] = 0;       }       cout << inp.size() << endl;       for (map<string, int>::iterator it = inp.begin(); it != inp.end(); it++) {         cout << it->first <<     << it->second << endl;       }     }   }   int main() {     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int compare(const void *a, const void *b) {     int *p = (int *)a;     int *q = (int *)b;     if (p[0] == q[0]) return p[1] - q[1];     return p[0] - q[0];   }   int main() {     int n, m, c = 0, t, i, x;     scanf( %d%d , &n, &m);     ;     t = 0;     for (i = 0; i < n; i++) {       scanf( %d , &x);       ;       if (x > t) {         c++;         t = m - x;       } else         t -= x;     }     printf( %d n , c);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double PI = 3.14159265;   int main() {     ios::sync_with_stdio(false);     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       cout << fixed << setprecision(7) << (cos(PI / (4 * n)) / sin(PI / (2 * n)))            << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 100010;   int t, n, cnt = 0, ans = 0, tot = 0, num[maxn] = {}, zz[maxn] = {},             b[maxn] = {};   vector<int> k[maxn];   int powmod(int a, int b) {     int ans = 1;     for (; b; b >>= 1, a = a * a)       if (b & 1) ans = ans * a;     return ans;   }   int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }   void div(int n) {     int m = n;     for (int i = 2; i * i <= n; i++) {       if (m % i == 0) {         zz[++cnt] = i, num[cnt] = 0;         while (m % i == 0) m /= i, num[cnt]++;       }     }     if (m > 1) zz[++cnt] = m, num[cnt] = 1;   }   void dfs(int x, int y, int z) {     if (x > cnt) {       if (y != 1) k[z].push_back(y);       return;     }     dfs(x + 1, y, z);     if (z == 0) z = x;     for (int i = 1; i <= num[x]; i++) dfs(x + 1, y * powmod(zz[x], i), z);   }   void calc() {     for (int i = 1; i < tot; i++)       if (gcd(b[i], b[i + 1]) == 1) ans++;     if (gcd(b[tot], b[1]) == 1) ans++;   }   int main() {     scanf( %d , &t);     while (t--) {       ans = tot = cnt = 0;       scanf( %d , &n);       div(n);       for (int i = 1; i <= cnt; i++) k[i].clear();       dfs(1, 1, 0);       for (int i = 1; i <= cnt; i++) {         int x = -1, y = -1;         for (int j = 0; j < k[i].size(); j++) {           if (k[i][j] % zz[((i + cnt - 2) % cnt + cnt) % cnt + 1] == 0) {             x = k[i][j], k[i].erase(k[i].begin() + j);             break;           }         }         for (int j = 0; j < k[i].size(); j++) {           if (k[i][j] % zz[i % cnt + 1] == 0) {             y = k[i][j], k[i].erase(k[i].begin() + j);             break;           }         }         if (x != -1) b[++tot] = x;         for (int j = 0; j < k[i].size(); j++) b[++tot] = k[i][j];         if (y != -1) b[++tot] = y;       }       for (int i = 1; i <= tot; i++) printf( %d  , b[i]);       calc();       printf(  n%d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline long long read() {     long long x = 0, f = 1;     char ch = getchar();     while (!isdigit(ch)) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (isdigit(ch)) {       x = x * 10 + ch - 48;       ch = getchar();     }     return x * f;   }   long long n, k;   long long st[200001];   struct aa {     long long u, v;     long long next;   } edge[200001 * 4];   long long head[200001];   long long cnt = 0;   void add_edge(long long u, long long v) {     cnt++;     edge[cnt].u = u;     edge[cnt].v = v;     edge[cnt].next = head[u];     head[u] = cnt;   }   long long root = 0;   long long f[200001][29];   long long son[200001];   long long size[200001];   long long depth[200001];   long long ed[200001];   long long tot = 0;   long long id[200001];   long long top[200001];   void dfs1(long long u, long long fa) {     f[u][0] = fa;     for (long long i = 1; i <= 21; i++) {       f[u][i] = f[f[u][i - 1]][i - 1];     }     depth[u] = depth[fa] + 1;     size[u] = 1;     for (long long i = head[u]; i; i = edge[i].next) {       long long v = edge[i].v;       if (v != fa) {         dfs1(v, u);         if (size[son[u]] < size[v]) {           son[u] = v;         }         size[u] += size[v];       }     }   }   void dfs2(long long u, long long tp) {     tot++;     id[u] = tot;     ed[tot] = st[u];     top[u] = tp;     if (son[u]) {       dfs2(son[u], tp);       for (long long i = head[u]; i; i = edge[i].next) {         long long v = edge[i].v;         if (v != son[u] && v != f[u][0]) {           dfs2(v, v);         }       }     }   }   struct qw {     long long l, r, val;     long long add;   } a[1600001];   void up(long long i) { a[i].val = a[i * 2].val + a[i * 2 + 1].val; }   void down(long long i) {     long long x = a[i].add;     a[i * 2].add += x;     a[i * 2 + 1].add += x;     a[i * 2].val += (a[i * 2].r - a[i * 2].l + 1) * x;     a[i * 2 + 1].val += (a[i * 2 + 1].r - a[i * 2 + 1].l + 1) * x;     a[i].add = 0;   }   void build(long long i, long long l, long long r) {     a[i].l = l;     a[i].r = r;     if (l == r) {       a[i].val = ed[a[i].l];       return;     }     long long mid = (l + r) / 2;     build(i * 2, l, mid);     build(i * 2 + 1, mid + 1, r);     up(i);   }   void update(long long i, long long l, long long r, long long k) {     if (a[i].l == l && a[i].r == r) {       a[i].add += k;       a[i].val += (a[i].r - a[i].l + 1) * k;       return;     }     down(i);     long long mid = (a[i].l + a[i].r) / 2;     if (mid >= r) {       update(i * 2, l, r, k);     } else {       if (mid < l) {         update(i * 2 + 1, l, r, k);       } else {         update(i * 2, l, mid, k);         update(i * 2 + 1, mid + 1, r, k);       }     }     up(i);   }   long long query(long long i, long long l, long long r) {     if (a[i].l == l && a[i].r == r) {       return a[i].val;     }     down(i);     long long mid = (a[i].l + a[i].r) / 2;     if (mid >= r) {       return query(i * 2, l, r);     } else {       if (mid < l) {         return query(i * 2 + 1, l, r);       } else {         return (query(i * 2, l, mid) + query(i * 2 + 1, mid + 1, r));       }     }   }   long long find(long long u, long long to) {     for (long long i = 21; i >= 0; i--) {       if (depth[f[u][i]] > depth[to]) {         u = f[u][i];       }     }     return u;   }   long long lca(long long x, long long y) {     if (depth[x] < depth[y]) {       swap(x, y);     }     while (depth[x] > depth[y]) {       x = f[x][(long long)log2(depth[x] - depth[y])];     }     if (x == y) {       return x;     }     for (long long i = 21; i >= 0; i--) {       if (f[x][i] != f[y][i]) {         x = f[x][i];         y = f[y][i];       }     }     return f[x][0];   }   long long lcaq(long long x, long long y) {     long long v1 = lca(x, y);     long long v2 = lca(x, root);     long long v3 = lca(y, root);     if (depth[v1] < depth[v2]) {       v1 = v2;     }     if (depth[v1] < depth[v3]) {       v1 = v3;     }     return v1;   }   signed main() {     cin >> n >> k;     for (long long i = 1; i <= n; i++) {       cin >> st[i];     }     for (long long i = 1; i <= n - 1; i++) {       long long u, v;       cin >> u >> v;       add_edge(u, v);       add_edge(v, u);     }     root = 1;     dfs1(1, 0);     dfs2(1, 1);     build(1, 1, n);     for (long long i = 1; i <= k; i++) {       long long opt;       opt = read();       if (opt == 1) {         long long v;         cin >> v;         root = v;       }       if (opt == 2) {         long long a, b, k;         cin >> a >> b >> k;         long long x = lcaq(a, b);         if (x == root) {           update(1, 1, n, k);         } else {           if (id[root] >= id[x] && id[root] <= id[x] + size[x] - 1) {             long long at = find(root, x);             update(1, 1, n, k);             update(1, id[at], id[at] + size[at] - 1, -k);           } else {             update(1, id[x], id[x] + size[x] - 1, k);           }         }       }       if (opt == 3) {         long long x;         cin >> x;         if (x == root) {           cout << query(1, 1, n) << endl;           ;         } else {           if (id[root] >= id[x] && id[root] <= id[x] + size[x] - 1) {             long long at = find(root, x);             long long val =                 query(1, 1, n) - query(1, id[at], id[at] + size[at] - 1);             cout << val << endl;           } else {             cout << query(1, id[x], id[x] + size[x] - 1) << endl;             ;           }         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     string s;     set<string> st;     while (n--) {       cin >> s;       if (st.count(s)) {         cout <<  YES ;       } else {         cout <<  NO ;         st.insert(s);       }       cout << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   T abs(T x) {     return x > 0 ? x : (-x);   }   template <class T>   T sqr(T x) {     return x * x;   }   const double eps = 1E-8;   struct P {     double x, y;     P(double x = 0.0, double y = 0.0) : x(x), y(y) {}     P operator+(P a) { return P(x + a.x, y + a.y); }     P operator-(P a) { return P(x - a.x, y - a.y); }     P operator*(double k) { return P(x * k, y * k); }     double operator*(P a) { return x * a.y - y * a.x; }     double operator^(P a) { return x * a.x + y * a.y; }     double len() { return sqrt(x * x + y * y); }     P perp() { return P(y, -x); }     P norm() {       double l = len();       return abs(l) < eps ? P(x, y) : P(x / l, y / l);     }     bool operator==(P a) { return abs(x - a.x) < eps && abs(y - a.y) < eps; }     void load() { cin >> x >> y; }   };   int sgn(double x) {     if (x > eps) return 1;     if (x < -eps) return -1;     return 0;   }   bool pointOnSegment(P p, P a, P b) {     if (abs((a - p) * (b - p)) > eps) return false;     return ((a - p) ^ (b - p)) < eps;   }   bool crossSegments1d(double a, double aa, double b, double bb) {     return min(a, aa) < max(b, bb) + eps && min(b, bb) < max(a, aa) + eps;   }   bool crossSegments(P a, P aa, P b, P bb) {     if (sgn((b - a) * (aa - a)) * sgn((aa - a) * (bb - a)) < 0) return false;     if (sgn((a - b) * (bb - b)) * sgn((bb - b) * (aa - b)) < 0) return false;     return crossSegments1d(a.x, aa.x, b.x, bb.x) &&            crossSegments1d(a.y, aa.y, b.y, bb.y);   }   struct L {     double a, b, c;     L(double a = 0.0, double b = 0.0, double c = 0.0) : a(a), b(b), c(c) {}     bool operator||(L l) { return abs(a * l.b - b * l.a) < eps; }   };   L getLine(P p1, P p2) {     double x0 = p1.x, y0 = p1.y;     double al = (p2 - p1).x, be = (p2 - p1).y;     return L(be, -al, al * y0 - be * x0);   }   P getPoint(L l1, L l2) {     double det = l1.a * l2.b - l1.b * l2.a;     double det1 = -(l1.c * l2.b - l1.b * l2.c);     double det2 = -(l1.a * l2.c - l1.c * l2.a);     return P(det1 / det, det2 / det);   }   double h, f;   pair<double, double> calc1(double y, double x1, double x2) {     double l = x1 * (f - y) / (f - h);     double r = x2 * (f - y) / (f - h);     return make_pair(l, r);   }   pair<double, double> calc2(double y, double x1, double x2) {     double l = x1 * (y + f) / (f - h);     double r = x2 * (y + f) / (f - h);     return make_pair(l, r);   }   int main() {     int n;     cin >> n;     cin >> h >> f;     vector<pair<int, int> > v(n);     double res = 0.0;     for (int i = 0; i < n; ++i) {       scanf( %d%d , &v[i].first, &v[i].second);       double l = abs(v[i].second - v[i].first);       res += 2. * h * (l + l * (f + h) / (f - h));     }     for (int i = 0; i < n; ++i) {       for (int j = 0; j < n; ++j) {         vector<P> V;         L l11 = getLine(P(0, f), P(v[i].first, h));         L l12 = getLine(P(0, f), P(v[i].second, h));         L l21 = getLine(P(0, -f), P(v[j].first, -h));         L l22 = getLine(P(0, -f), P(v[j].second, -h));         if (!(l11 || l21)) V.push_back(getPoint(l11, l21));         if (!(l11 || l22)) V.push_back(getPoint(l11, l22));         if (!(l12 || l21)) V.push_back(getPoint(l12, l21));         if (!(l12 || l22)) V.push_back(getPoint(l12, l22));         vector<double> ev;         ev.push_back(-h);         ev.push_back(-h);         ev.push_back(h);         ev.push_back(h);         for (int k = 0; k < ((int)(V).size()); ++k) {           if (abs(V[k].y) < h + eps) ev.push_back(V[k].y);         }         sort((ev).begin(), (ev).end());         double cur = 0;         double st = 0.0;         for (int k = 1; k < ((int)(ev).size()); ++k) {           pair<double, double> p = calc1(ev[k], v[i].first, v[i].second);           pair<double, double> q = calc2(ev[k], v[j].first, v[j].second);           double l = max(p.first, q.first);           double r = min(p.second, q.second);           double t = max(0.0, r - l);           cur += (t + st) * 0.5 * (ev[k] - ev[k - 1]);           st = t;         }         res -= abs(cur);       }     }     printf( %.10lf n , res);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n, x, y;     cin >> n >> x >> y;     long long a = y - n + 1;     long long b = x - n + 1;     for (long long i = a; i >= 1; i--) {       long long c = i * i;       if (c >= b) {         for (int j = 1; j <= n - 1; j++) cout <<  1  << endl;         cout << i << endl;         return 0;       }     }     cout <<  -1  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b;     cin >> a >> b;     if (b == 1 && a == 9) {       cout <<  9 10  << endl;     } else if (b - a == 1) {       cout << a <<     << b << endl;     } else if (a == b) {       cout << a <<  1   << b <<  2  << endl;     } else {       cout <<  -1  << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int L = 1;   int R = 0;   int cnt[300005];   int a[300005];   int big[300005][2];   int is1 = 0;   int ap[300005];   vector<int> st;   void in(int id) {     id = a[id];     if (++cnt[id] == 1)       is1++;     else if (cnt[id] == 2)       is1--;   }   void out(int id) {     id = a[id];     if (--cnt[id] == 1)       is1++;     else if (cnt[id] == 0)       is1--;   }   void update(int l, int r) {     while (R < r) in(++R);     while (L > l) in(--L);     while (L < l) out(L++);     while (R > r) out(R--);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     a[0] = n + 1;     a[n + 1] = n + 1;     int res = 0;     st.push_back(n + 1);     for (int i = 1; i <= n; i++) {       cin >> a[i];       while (st.back() < a[i]) st.pop_back();       big[i][0] = ap[st.back()];       st.push_back(a[i]);       ap[a[i]] = i;     }     st.clear();     st.push_back(n + 1);     ap[n + 1] = n + 1;     for (int i = n; i >= 1; i--) {       while (st.back() < a[i]) st.pop_back();       big[i][1] = ap[st.back()];       st.push_back(a[i]);       ap[a[i]] = i;     }     for (int i = 1; i <= n; i++) {       int l = max(i - a[i] + 1, big[i][0] + 1);       int r = min(l + a[i] - 1, big[i][1] - 1);       if (l + a[i] - 1 != r) continue;       for (; l <= i; l++) {         update(l, r);         if (is1 == a[i]) res++;         if (++r == big[i][1]) break;       }     }     cout << res;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 500005;   int n, a[N], b[N];   vector<int> vec[N];   set<pair<int, int> > S;   struct node {     int cl, cr, mx, vl, vr, v;     node() {}     node(int c) {       cl = cr = c;       mx = vl = vr = v = 1;     }   } t[N * 4];   node operator+(node a, node b) {     node ans;     ans.cl = a.cl;     ans.cr = b.cr;     ans.mx = max(a.mx, b.mx);     ans.vl = a.vl;     ans.vr = b.vr;     ans.v = a.v + b.v;     if (a.cr ^ b.cl) {       ans.mx = max(ans.mx, a.vr + b.vl);       if (a.v == a.vl) ans.vl += b.vl;       if (b.v == b.vr) ans.vr += a.vr;     }     return ans;   }   void build(int k, int l, int r) {     if (l == r) {       t[k] = node(0);       return;     }     int mid = (l + r) / 2;     build(k * 2, l, mid);     build(k * 2 + 1, mid + 1, r);     t[k] = t[k * 2] + t[k * 2 + 1];   }   void change(int k, int l, int r, int p) {     if (l == r) {       t[k] = node(1);       return;     }     int mid = (l + r) / 2;     if (p <= mid)       change(k * 2, l, mid, p);     else       change(k * 2 + 1, mid + 1, r, p);     t[k] = t[k * 2] + t[k * 2 + 1];   }   struct YYN {     int t[N * 4], nn;     void build(int n) {       for (nn = 1; nn <= n; nn <<= 1)         ;       for (int i = (int)(0); i <= (int)(2 * nn - 1); i++) t[i] = 0;     }     void change(int x, int y, int v) {       x += nn - 1;       y += nn + 1;       for (; x ^ y ^ 1; x >>= 1, y >>= 1) {         if (!(x & 1)) t[x ^ 1] = max(t[x ^ 1], v);         if (y & 1) t[y ^ 1] = max(t[y ^ 1], v);       }     }     void output() {       for (int i = (int)(1); i <= (int)(nn - 1); i++) {         t[i * 2] = max(t[i * 2], t[i]);         t[i * 2 + 1] = max(t[i * 2 + 1], t[i]);       }       for (int i = (int)(1); i <= (int)(n); i++) printf( %d  , t[i + nn]);       puts(  );     }   } RE;   void flip(int x) {     assert(a[x] == 0);     if (x == 1 || a[x] == a[x - 1]) S.erase(pair<int, int>(x, a[x]));     if (x == n || a[x] == a[x + 1]) S.erase(pair<int, int>(x + 1, a[x]));     a[x] ^= 1;     change(1, 1, n, x);     if (x == 1 || a[x] == a[x - 1]) S.insert(pair<int, int>(x, a[x]));     if (x == n || a[x] == a[x + 1]) S.insert(pair<int, int>(x + 1, a[x]));   }   void updateee(int x, int v) {     auto it = S.lower_bound(pair<int, int>(x, -1));     auto pre = it, suf = it;     pre--;     if (pre->second == 1 && suf->second == 1)       RE.change(pre->first, suf->first - 1, v);     else if (pre->second == 1 && suf->second == 0)       RE.change(pre->first, (pre->first + suf->first) / 2 - 1, v);     else if (pre->second == 0 && suf->second == 1)       RE.change((pre->first + suf->first) / 2, suf->first - 1, v);   }   void updatee(int x, int v) {     auto it = S.lower_bound(pair<int, int>(x, -1));     auto pre = it, suf = it;     if (x != 1) {       --pre;       if (pre->second == 1)         RE.change(pre->first, it->first - 1, v);       else         RE.change((pre->first + it->first) / 2, it->first - 1, v);     }     if (x != n + 1) {       ++suf;       if (suf->second == 1)         RE.change(it->first, suf->first - 1, v);       else         RE.change(it->first, (it->first + suf->first) / 2 - 1, v);     }   }   void update(int x, int v) {     if (x == 1 || a[x] == a[x - 1])       updatee(x, v);     else       updateee(x, v);     if (x == n || a[x] == a[x + 1])       updatee(x + 1, v);     else       updateee(x + 1, v);   }   int main() {     scanf( %d , &n);     for (int i = (int)(1); i <= (int)(n); i++) scanf( %d , &a[i]);     for (int i = (int)(1); i <= (int)(n); i++) b[i] = a[i];     sort(b + 1, b + n + 1);     *b = unique(b + 1, b + n + 1) - b - 1;     for (int i = (int)(1); i <= (int)(n); i++) {       a[i] = lower_bound(b + 1, b + *b + 1, a[i]) - b;       vec[a[i]].push_back(i);     }     memset(a, 0, sizeof(a));     build(1, 1, n);     RE.build(n);     for (int i = (int)(1); i <= (int)(n + 1); i++) S.insert(pair<int, int>(i, 0));     int ansT = 0;     for (int i = (int)(*b); i >= (int)(1); i--) {       for (auto j : vec[i]) flip(j);       for (auto j : vec[i]) update(j, b[i]);       ansT = max(ansT, t[1].mx);     }     printf( %d n , (ansT - 1) / 2);     RE.output();   }


#include <bits/stdc++.h>   using namespace std;   vector<long long> usedTrains;   vector<vector<pair<long long, long long>>> gNoTrain;   vector<vector<pair<long long, long long>>> gYesTrain;   vector<long long> disNoTrain;   vector<long long> disYesTrain;   unordered_set<long long> tracks;   void no_train_dijkstra(int s) {     priority_queue<pair<long long, long long>, vector<pair<long long, long long>>,                    greater<pair<long long, long long>>>         Q;     Q.push(make_pair(0, s));     disNoTrain[s] = 0;     while (!Q.empty()) {       pair<long long, long long> p = Q.top();       Q.pop();       int currV = (int)p.second;       if (disNoTrain[currV] != p.first) continue;       for (pair<long long, long long>& edge : gNoTrain[currV]) {         int u = (int)edge.first;         long long w = edge.second;         if (disNoTrain[currV] + w < disNoTrain[u]) {           disNoTrain[u] = disNoTrain[currV] + w;           Q.push(make_pair(disNoTrain[u], u));         }       }     }   }   void yes_train_dijkstra(int s) {     priority_queue<pair<long long, long long>, vector<pair<long long, long long>>,                    greater<pair<long long, long long>>>         Q;     Q.push(make_pair(0, s));     disYesTrain[s] = 0;     while (!Q.empty()) {       pair<long long, long long> p = Q.top();       Q.pop();       int currV = (int)p.second;       if (disYesTrain[currV] != p.first) continue;       for (pair<long long, long long>& edge : gYesTrain[currV]) {         int u = (int)edge.first;         long long w = edge.second;         if (currV != 0 && disYesTrain[currV] + w == disYesTrain[u]) {           tracks.erase(u);         }         if (disYesTrain[currV] + w < disYesTrain[u]) {           if (currV != 0) tracks.erase(u);           disYesTrain[u] = disYesTrain[currV] + w;           Q.push(make_pair((long long)disYesTrain[u], u));         }       }     }   }   int n, m, k;   int main() {     cin >> n >> m >> k;     usedTrains = vector<long long>(k, 0);     gNoTrain = vector<vector<pair<long long, long long>>>(         n, vector<pair<long long, long long>>());     gYesTrain = vector<vector<pair<long long, long long>>>(         n, vector<pair<long long, long long>>());     disNoTrain = vector<long long>(n, 100000000000l);     disYesTrain = vector<long long>(n, 100000000000l);     for (int i = 0; i < m; i++) {       int u, v, w;       cin >> u >> v >> w;       gNoTrain[u - 1].push_back({(long long)v - 1, (long long)w});       gNoTrain[v - 1].push_back({(long long)u - 1, (long long)w});       gYesTrain[u - 1].push_back({(long long)v - 1, (long long)w});       gYesTrain[v - 1].push_back({(long long)u - 1, (long long)w});     }     no_train_dijkstra(0);     for (int i = 0; i < k; i++) {       int v, w;       cin >> v >> w;       gYesTrain[0].push_back({(long long)v - 1, (long long)w});       gYesTrain[v - 1].push_back({0, (long long)w});       if (w < disNoTrain[v - 1]) tracks.insert(v - 1);     }     no_train_dijkstra(0);     yes_train_dijkstra(0);     cout << (k - (long long)tracks.size()) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 300000 + 15;   int n;   int a[N];   char c[N];   int flag, st, bb, rr, ll, cc, dd, ee, hh;   int main() {     scanf( %d , &n);     for (int i(1); i <= (n); ++i) scanf( %d %c , a + i, c + i);     long long ans = 0;     for (int i(1); i <= (n); ++i)       if (c[i] ==  B ) {         if (!bb) bb = i;         dd = a[i] - a[ll] > dd ? a[i] - a[ll] : dd;         ll = i;       } else if (c[i] ==  R ) {         if (!rr) rr = i;         ee = a[i] - a[cc] > ee ? a[i] - a[cc] : ee;         cc = i;       } else {         if (flag) {           int tmp1 = a[i] - a[hh];           int tmp2 = (ee ? a[i] - a[hh] - max(a[i] - a[cc], ee) : 0) +                      (dd ? a[i] - a[hh] - max(a[i] - a[ll], dd) : 0);           ans += a[i] - a[hh] + min(tmp1, tmp2);         } else           ans += (bb ? a[i] - a[bb] : 0) + (rr ? a[i] - a[rr] : 0);         flag = 1;         hh = cc = ll = i;         ee = dd = 0;       }     if (!flag)       printf( %lld n , 0ll + a[cc] - a[rr] + a[ll] - a[bb]);     else       printf( %lld n ,              ans + (cc > hh ? a[cc] - a[hh] : 0) + (ll > hh ? a[ll] - a[hh] : 0));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[5005];   int times[5005];   int maxn, val;   int valcnt[5005];   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);     }     for (int i = 1; i <= n; i++) {       memset(times, 0, sizeof(times));       maxn = -1;       val = 0;       for (int j = i; j <= n; j++) {         times[a[j]]++;         if (times[a[j]] == maxn && a[j] < val) {           maxn = times[a[j]];           val = a[j];         } else if (times[a[j]] > maxn) {           maxn = times[a[j]];           val = a[j];         }         valcnt[val]++;       }     }     for (int i = 1; i <= n; i++) printf( %d  , valcnt[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long M = 1e9 + 7;   const long long mod = 998244353;   mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());   int n, m, k;   vector<int> a;   int f(int off) {     int q = 0;     int left = m - 1;     int at_w = k;     for (int i = off; i < n; i++) {       if (at_w - a[i] >= 0) {         at_w -= a[i];         q++;       } else {         if (left == 0) break;         at_w = k - a[i];         q++;         left--;       }     }     return q == (n - off);   }   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> m >> k;     a.resize(n);     {       for (auto &_re : a) cin >> _re;     };     int l = 0, r = n, mid;     int ans = 0;     while (l <= r) {       mid = l + r >> 1;       if (f(mid)) {         ans = mid;         r = mid - 1;       } else         l = mid + 1;     }     cout << n - ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   int main() {     cin >> n >> m;     bool flg = false;     int a;     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) {         cin >> a;         if (a == 1 && (i == 0 || i == n - 1 || j == 0 || j == m - 1)) flg = true;       }     if (flg)       cout << 2 << endl;     else       cout << 4 << endl;     return 0;   }


#include <bits/stdc++.h>   const int inf = 2e9;   using namespace std;   int dp[505][505], change[505][505];   pair<int, int> parent[505][505];   string second;   int calc(int l, int r) {     int ans = 0;     while (l < r) {       if (second[l] != second[r]) ans++;       l++;       r--;     }     return ans;   }   void _try(int l, int r) {     while (l < r) {       if (second[l] != second[r]) second[r] = second[l];       l++;       r--;     }   }   int main() {     ios_base::sync_with_stdio(0);     int k;     cin >> second >> k;     int n = second.length();     for (int i = 0; i < 505; i++)       for (int j = 0; j < 505; j++) {         dp[i][j] = inf;         parent[i][j] = make_pair(i, j);       }     for (int i = 0; i < n; i++)       for (int j = i; j < n; j++) {         change[i][j] = calc(i, j);       }     for (int pos = 0; pos < n; pos++)       for (int cnt = 1; cnt <= k; cnt++) {         if (cnt == 1) {           dp[pos][cnt] = change[0][pos];         } else {           for (int pos1 = 0; pos1 < pos; pos1++) {             int new_v = dp[pos1][cnt - 1] + change[pos1 + 1][pos];             if (dp[pos][cnt] > new_v) {               dp[pos][cnt] = new_v;               parent[pos][cnt] = make_pair(pos1, cnt - 1);             }           }         }       }     int ansi = 1;     for (int i = 2; i <= k; i++) {       if (dp[n - 1][i] < dp[n - 1][ansi]) ansi = i;     }     int pos = n - 1, j = ansi;     vector<pair<int, int> > split;     while (parent[pos][j] != make_pair(pos, j)) {       pair<int, int> next = parent[pos][j];       pos = next.first;       j = next.second;       split.push_back(make_pair(pos, j));     }     reverse(split.begin(), split.end());     cout << dp[n - 1][ansi] << endl;     int l = 0;     if (split.empty()) {       _try(0, n - 1);       cout << second;       return 0;     }     for (int i = 0; i < split.size(); i++) {       _try(l, split[i].first);       for (int j = l; j <= split[i].first; j++) {         cout << second[j];         cout.flush();       }       cout <<  + ;       l = split[i].first + 1;     }     _try(l, n - 1);     for (int i = l; i < n; i++) {       cout << second[i];     }     return 0;   }