#include <bits/stdc++.h>   using namespace std;   const int inf = 1e9 + 7;   struct Matching {     int n;     vector<int> matchL, matchR, dist;     vector<bool> seen;     vector<vector<int>> ke;     Matching(int n)         : n(n),           matchL(n + 1),           matchR(n + 1),           dist(n + 1),           seen(n + 1, false),           ke(n + 1) {}     void addEdge(int u, int v) { ke[u].push_back(v); }     bool bfs() {       queue<int> qu;       for (int u = 1; u <= n; ++u)         if (!matchL[u]) {           dist[u] = 0;           qu.push(u);         } else           dist[u] = inf;       dist[0] = inf;       while (!qu.empty()) {         int u = qu.front();         qu.pop();         for (__typeof(ke[u].begin()) v = ke[u].begin(); v != ke[u].end(); ++v) {           if (dist[matchR[*v]] == inf) {             dist[matchR[*v]] = dist[u] + 1;             qu.push(matchR[*v]);           }         }       }       return dist[0] != inf;     }     bool dfs(int u) {       if (u) {         for (__typeof(ke[u].begin()) v = ke[u].begin(); v != ke[u].end(); ++v)           if (dist[matchR[*v]] == dist[u] + 1 && dfs(matchR[*v])) {             matchL[u] = *v;             matchR[*v] = u;             return true;           }         dist[u] = inf;         return false;       }       return true;     }     int match() {       int res = 0;       while (bfs()) {         for (int u = 1; u <= n; ++u)           if (!matchL[u])             if (dfs(u)) ++res;       }       return res;     }   };   const int M = 1e5 + 5;   pair<int, pair<int, int>> edge[M];   int m, n;   bool check(int max_weight) {     Matching matching(n);     for (auto e : edge) {       if (e.first > max_weight) break;       matching.addEdge(e.second.first, e.second.second);     }     return matching.match() == n;   }   int solve() {     int edge_num_needed = m;     for (int shift = floor(log2(m)); shift >= 0; --shift) {       if ((1 << shift) > edge_num_needed) continue;       if (check(edge[edge_num_needed - (1 << shift) - 1].first)) {         edge_num_needed -= (1 << shift);       }     }     if (!check(edge[edge_num_needed - 1].first)) {       return -1;     }     return edge[edge_num_needed - 1].first;   }   int main() {     cin >> n >> m;     for (int i = 0; i < m; ++i) {       int u, v, d;       cin >> u >> v >> d;       edge[i] = {d, {u, v}};     }     sort(edge, edge + m);     cout << solve();   }


#include <bits/stdc++.h>   using namespace std;   struct st {     int o;     int e;   } arr[101];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long n, b;     cin >> n >> b;     vector<long long> vec;     int v;     arr[0].o = 0;     arr[0].e = 0;     for (int i = 0; i < n; i++) {       cin >> v;       vec.push_back(v);       arr[i + 1] = arr[i];       if (v & 1) {         arr[i + 1].o++;       } else {         arr[i + 1].e++;       }     }     vector<long long> vv;     for (int i = 1; i < n; i++) {       if (arr[i].o == arr[i].e) {         vv.push_back(abs(vec[i] - vec[i - 1]));       }     }     int t = 0;     int ans = 0;     sort(vv.begin(), vv.end());     for (int i = 0; i < (int)vv.size(); i++) {       t += vv[i];       if (t > b) {         break;       }       ans++;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long ans = 0, now, a[14], b[14];     for (int i = 0; i < 14; i++) cin >> a[i];     for (int i = 0; i < 14; i++) {       if (a[i] != 0) {         for (int j = 0; j < 14; j++) b[j] = a[j];         int r = b[i] % 14, q = b[i] / 14;         b[i] = 0;         for (int j = 0; j < 14; j++) b[j] += q;         for (int j = 1; j <= r; j++) b[(i + j) % 14]++;         now = 0;         for (int j = 0; j < 14; j++)           if (b[j] % 2 == 0) now += b[j];         ans = max(ans, now);       }     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 9;   const long long mod1 = 1000000;   ostringstream convert;   long long n, m, cur, dp[100][300];   long long res;   long long nbb = 0, nss = 0, ncc = 0, wmin, wmax;   long long nb, ns, nc, pb, ps, pc, mx = 0;   string s, s2;   string a[1000];   long long vis[10000] = {0}, wpers[10000];   vector<string> v, vnode;   map<string, long long> mp;   set<long long> st;   stack<double> stk;   long long dx[] = {0, 1, -1, 0};   long long dy[] = {1, 0, 0, -1};   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     long long i, j = 1, k = 0, d, p, q, l, r, pos, idx = -1, nbx, sumf = 0, test;     long long sum2 = 0, lg = 1, op;     long long x, lastx = 0, val1 = 0;     long long y = 1, z = 0;     char c;     cin >> n;     for (i = 1; i <= n; i++) {       cin >> a[i];     }     for (k = 0; k <= 100; k++)       for (i = 1; i <= n; i++) {         s = a[i];         j = 1;         if (!vis[i])           for (j = 1; j <= n; j++) {             s2 = a[j];             if (!vis[i] && !vis[j] && !strstr(s2.c_str(), s.c_str())) break;           }         if (j == n + 1) {           v.push_back(s);           vis[i] = 1;         }       }     if (v.size() == n) {       cout <<  YES n ;       for (i = 0; i < v.size(); i++) cout << v[i] << endl;     } else       cout <<  NO ;   }


#include <bits/stdc++.h>   using namespace std;   const double eps(1e-8);   const double pi(3.14159265358979);   const int K = 33, mod = 1000000007;   struct matrix {     long long a[K][K];   } t[K] = {}, ans = {{}}, pre[K] = {}, suf[K] = {};   long long n;   int k;   inline void multi(const matrix &m1, const matrix &m2, matrix &to) {     static matrix tmp = {{}};     for (int i = 0; i <= k; ++i)       for (int j = 0; j <= k; ++j) {         tmp.a[i][j] = 0;         for (int p = 0; p <= k; ++p)           (tmp.a[i][j] += m1.a[i][p] * m2.a[p][j]) %= mod;       }     to = tmp;   }   void init() {     cin >> n >> k;     for (int i = 0; i <= k; ++i)       for (int j = 0; j <= k; ++j) ans.a[i][j] = i == j;     for (int p = 0; p < k; ++p)       for (int i = 0; i <= k; ++i)         for (int j = 0; j <= k; ++j) t[p].a[i][j] = i == j || i == p;   }   void work() {     vector<int> bit;     for (; n; n /= k) bit.push_back(n % k);     bit.push_back(0);     partial_sum(bit.rbegin(), bit.rend(), bit.rbegin());     for (auto p = 0u; p < bit.size() - 1; ++p) {       for (int i = bit[p] - 1; i >= bit[p + 1]; --i) multi(t[i % k], ans, ans);       pre[0] = t[0];       for (int i = 1; i < k; ++i) multi(pre[i - 1], t[i], pre[i]);       suf[k - 1] = t[k - 1];       for (int i = k - 2; i >= 0; --i) multi(t[i], suf[i + 1], suf[i]);       t[0] = suf[0];       for (int i = 1; i < k; ++i) multi(suf[i], pre[i - 1], t[i]);     }     long long sum = 0;     for (int i = 0; i <= k; ++i) sum += ans.a[i][k];     cout << sum % mod << endl;   }   int main() {     init();     work();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct point {     int tp;     string s1, s2;   } a[200000];   struct node {     int n, next;   } b[200000];   int n, l, st[200000];   map<string, int> p;   int main() {     cin >> n;     scanf(  n );     int m = 0;     for (int i = 0; i < n; i++) {       string s;       getline(cin, s);       bool y = false;       string cd =   ;       for (int j = 0; j < s.length(); j++) {         if (s[j] ==     && !y) continue;         cd += s[j];         if (s[j] ==    ) y = !y;       }       if (cd.length() == 0) {         a[i].tp = -1;         continue;       }       if (cd[1] ==  r ) {         a[i].tp = 0;         st[++m] = i;       } else if (cd[1] ==  h ) {         a[i].tp = 1;         int j = 6;         a[i].s1 =   ;         while (cd[j] !=  ) ) a[i].s1 += cd[j++];       } else {         a[i].tp = 2;         int j = 6;         a[i].s1 =   ;         while (cd[j] !=  , ) a[i].s1 += cd[j++];         j += 2;         a[i].s2 =   ;         while (cd[j] !=    ) a[i].s2 += cd[j++];         a[st[m]].s2 = a[i].s2;         a[st[m--]].s1 = a[i].s1;       }     }     l = 1;     for (int i = 0; i < n; i++)       if (a[i].tp != -1) {         if (a[i].tp == 0) {           l++;           b[l].n = i;           if (p.count(a[i].s1) > 0) {             b[l].next = p[a[i].s1];             p[a[i].s1] = l;           } else {             b[l].next = 0;             p[a[i].s1] = l;           }         } else if (a[i].tp == 1) {           if (p.count(a[i].s1)) {             if (p[a[i].s1] != 0) {               cout << a[b[p[a[i].s1]].n].s2;               return 0;             }           }         } else if (a[i].tp == 2) {           if (p.count(a[i].s1)) {             p[a[i].s1] = b[p[a[i].s1]].next;           }         }       }     cout <<  Unhandled Exception ;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 500;   const int M = 1e6 + 500;   const int INF = 0x3f3f3f3f;   const int MOD = 1e9 + 7;   const int LOG = 20;   const int OFF = (1 << 20);   const double EPS = 1e-9;   const double PI = 3.1415926535;   set<int> st;   int n, x, l, r;   char s[10];   long long sol = 1;   int main() {     st.insert(-INF);     st.insert(INF);     sol = 1;     l = -INF;     r = INF;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %s , s);       scanf( %d , &x);       if (s[1] ==  D ) {         st.insert(x);       } else {         st.erase(x);         if (l <= x && x <= r) {           if (x != l && x != r) sol = (2LL * sol) % (long long)MOD;           l = *(--st.upper_bound(x));           r = *st.upper_bound(x);         } else {           sol = 0;         }       }     }     int cnt = 0;     for (int x : st) {       if (l <= x && x <= r) cnt++;     }     sol = (sol * (cnt - 1)) % (long long)MOD;     printf( %d n , (int)sol);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int cnt[2000006];   int main() {     int n, i, w;     long long ans;     scanf( %d , &n);     for (i = 1; i <= n; i++) scanf( %d , &w), cnt[w]++;     for (i = 0; i < 2000005; i++) {       cnt[i + 1] += cnt[i] / 2;       cnt[i] %= 2;     }     ans = 0;     for (i = 0; i < 2000006; i++) ans += cnt[i];     printf(          %I64d            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 << 1) + (x << 3) + ch -  0 ;       ch = getchar();     }     return x * f;   }   const long long maxn = 4e5 + 1e2;   struct Node {     long long pos, val;   };   long long l[maxn], r[maxn];   long long n, m;   long long a[maxn];   Node s[maxn];   long long top;   long long ans;   long long pos[maxn];   bool in(long long x, long long l, long long r) { return (x >= l) && (x <= r); }   signed main() {     n = read();     for (long long i = 1; i <= n; i++) a[i] = read(), pos[a[i]] = i;     l[1] = 1;     top = 1;     s[1].val = a[1];     s[1].pos = 1;     for (long long i = 2; i <= n; i++) {       while (top >= 1 && s[top].val <= a[i]) top--;       if (!top)         l[i] = 1;       else         l[i] = s[top].pos + 1;       s[++top].val = a[i];       s[top].pos = i;     }     r[n] = n;     top = 1;     s[1].val = a[n];     s[1].pos = n;     for (long long i = n - 1; i >= 1; i--) {       while (top >= 1 && s[top].val < a[i]) top--;       if (!top)         r[i] = n;       else         r[i] = s[top].pos - 1;       s[++top].val = a[i];       s[top].pos = i;     }     for (long long i = 1; i <= n; i++) {       long long mx = a[i];       if (i - l[i] < r[i] - i) {         for (long long j = l[i]; j < i; j++) {           if (in(pos[mx - a[j]], i, r[i])) ans++;         }       } else {         for (long long j = i + 1; j <= r[i]; j++) {           if (in(pos[mx - a[j]], l[i], i)) ans++;         }       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a[105];     int b[105];     int t, flag, flag1, i, n, c, sum1, sum2;     scanf( %d , &n);     for (i = 1; i <= n; i++) {       scanf( %d , &a[i]);       b[a[i]] = 1;     }     int count = 0;     int sum = 0;     flag = 1;     int d = -1;     c = 0;     for (i = 1; i <= 100; i++) {       if (b[i] == 1) {         count++;         sum += i;         if (c == 0)           c = i;         else {           if (d == -1) {             d = i - c;             c = i;           } else {             if (d != i - c) {               flag = 0;               break;             }             c = i;           }         }       }     }     if (flag == 0) {       printf( -1 n );     } else if (count == 1) {       printf( 0 n );     } else if (count == 2) {       if (sum % 2 == 0) {         sum = sum / 2;         printf( %d n , c - sum);       } else {         sum1 = sum - c;         sum1 = c - sum1;         sum2 = 2 * c - sum;         if (sum1 > sum2) {           sum1 = sum2;         }         printf( %d , sum1);       }     } else if (count == 3) {       sum = sum / count;       printf( %d n , c - sum);     } else {       printf( -1 n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct Maxflow {     static const int oo = 100000005;     static const int maxn = 5555 * 2;     static const int maxm = 5555 * 4;     int T, S;     struct node {       int to, nxt, cap;     } ed[maxm * 2];     int head[maxn], cur[maxn], cnt, ans, ndnum;     int h[maxn];     void addedge(int u, int v, int cap) {       ed[cnt].to = v, ed[cnt].cap = cap, ed[cnt].nxt = head[u], head[u] = cnt++;       ed[cnt].to = u, ed[cnt].cap = 0, ed[cnt].nxt = head[v], head[v] = cnt++;     }     bool bfs() {       memset(h, -1, sizeof(h));       queue<int> q;       h[S] = 0, q.push(S);       while (!q.empty()) {         int now = q.front();         q.pop();         for (int i = head[now]; ~i; i = ed[i].nxt) {           if (ed[i].cap && h[ed[i].to] == -1) {             h[ed[i].to] = h[now] + 1;             q.push(ed[i].to);           }         }       }       return h[T] != -1;     }     int dfs(int x, int f) {       if (x == T || f == 0) return f;       int w, used = 0;       for (int i = cur[x]; ~i; i = ed[i].nxt) {         if (h[ed[i].to] == h[x] + 1) {           w = f - used;           w = dfs(ed[i].to, min(w, ed[i].cap));           ed[i].cap -= w;           ed[i ^ 1].cap += w;           if (ed[i].cap) cur[x] = i;           used += w;           if (used == f) return f;         }       }       if (!used) h[x] = -1;       return used;     }     void dinic() {       while (bfs()) {         for (int i = 1; i <= ndnum; i++) {           cur[i] = head[i];         }         ans += dfs(S, oo);       }     }     void init(int s, int t, int num) {       for (int i = 1; i <= num; i++) head[i] = -1;       ans = cnt = 0;       T = t;       S = s;       ndnum = num;     }   } flow;   int n, m;   int a[5111], b[5111];   bool isok(int x) {     flow.init(n + m + 1, n + m + 3, n + m + 3);     int s = n + m + 1, t = n + m + 2, T = n + m + 3;     for (int i = 1; i <= m; i++) {       flow.addedge(i, m + a[i], 1);       flow.addedge(i, m + b[i], 1);     }     for (int i = 1; i <= m; i++) flow.addedge(s, i, 1);     for (int i = 1; i <= n; i++) flow.addedge(m + i, t, x);     flow.addedge(t, T, m);     flow.dinic();     return flow.ans == m;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; i++) scanf( %d%d , &a[i], &b[i]);     int l = 0, r = m, ans = m;     while (l <= r) {       int mid = l + r >> 1;       if (isok(mid)) {         ans = mid;         r = mid - 1;       } else         l = mid + 1;     }     printf( %d n , ans);     isok(ans);     for (int i = 0; i < 4 * m; i += 4) {       if (flow.ed[i].cap == 1)         printf( %d %d n , b[i / 4 + 1], a[i / 4 + 1]);       else         printf( %d %d n , a[i / 4 + 1], b[i / 4 + 1]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline long long valabs(long long x) {     if (x < 0) return -x;     return x;   }   inline long long max2(long long a, long long b) { return (a > b ? a : b); }   int main() {     long long x, y, xx, yy;     cin >> x >> y >> xx >> yy;     cout << max2(valabs(x - xx), valabs(y - yy)) <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 100005;   const int inf = 0x3f3f3f3f;   int deep[maxn], fa[maxn][32];   vector<int> edge[maxn];   int flag[maxn];   void dfs(int u) {     flag[u] = 1;     for (auto i : edge[u]) {       int t = i;       if (flag[t]) continue;       deep[t] = deep[u] + 1;       fa[t][0] = u;       dfs(t);     }   }   int lca(int x, int y) {     if (deep[x] > deep[y]) swap(x, y);     for (int i = 30; i >= 0; i--)       if (deep[fa[y][i]] >= deep[x]) y = fa[y][i];     if (x == y) return x;     for (int i = 30; i >= 0; i--)       if (fa[x][i] != fa[y][i]) {         x = fa[x][i], y = fa[y][i];       }     return fa[x][0];   }   void init(int n) {     deep[1] = 1;     fa[1][0] = 1;     dfs(1);     for (int i = (1); i < (30); i++)       for (int j = (1); j < (n + 1); j++) fa[j][i] = fa[fa[j][i - 1]][i - 1];   }   int dis(int a, int b) { return deep[a] + deep[b] - 2 * deep[lca(a, b)]; }   int main() {     int n, q;     cin >> n >> q;     for (int i = (1); i < (n); i++) {       int p;       cin >> p;       edge[p].push_back(i + 1);       edge[i + 1].push_back(p);     }     init(n);     while (q--) {       int aans = 0;       int ii[3];       cin >> ii[0] >> ii[1] >> ii[2];       for (int i = (0); i < (3); i++)         aans = max(dis(ii[i], ii[(i + 1) % 3]) + dis(ii[i], ii[(i + 2) % 3]) -                            dis(ii[(i + 1) % 3], ii[(i + 2) % 3]) >>                        1,                    aans);       cout << aans + 1 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   int mh, currx = 1, level[110], l = 0;   char sc[110];   char mas[4 * 110][4 * 110];   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> sc[i];       if (sc[i] ==  [ ) {         l++;         level[i] = l;       } else {         level[i] = l;         l--;       }       mh = max(l, mh);     }     mh = 3 + (mh - 1) * 2;     currx = 1;     for (int i = 1; i <= n; i++) {       if (sc[i] ==  ]  && sc[i - 1] ==  [ ) currx += 3;       l = level[i];       for (int j = l; j <= mh - l + 1; j++) {         mas[j][currx] =  | ;       }       mas[l][currx] =  + ;       mas[mh - l + 1][currx] =  + ;       if (sc[i] ==  [ ) {         mas[l][currx + 1] =  - ;         mas[mh - l + 1][currx + 1] =  - ;       }       if (sc[i] ==  ] ) {         mas[l][currx - 1] =  - ;         mas[mh - l + 1][currx - 1] =  - ;       }       currx++;     }     for (int i = 1; i <= mh; i++) {       for (int j = 1; j < currx; j++) {         if (mas[i][j] !=  |  && mas[i][j] !=  -  && mas[i][j] !=  + )           cout <<    ;         else           cout << mas[i][j];       }       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string rep(string s, int x) {     string res;     while (x--) res += s;     return res;   }   int ask(string str) {     cout << str <<   n ;     fflush(stdout);     int x;     cin >> x;     return x;   }   int main() {     int a = ask( a );     if (a == 0) return 0;     int len = a + 1;     if (len > 300) {       ask(rep( b , len - 1));       return 0;     }     string s = rep( a , len);     int curres = ask(s);     if (curres == len) {       ask(rep( b , len - 1));       return 0;     }     for (int i = 0; i < len - 1; i++) {       s[i] =  b ;       int nxt = ask(s);       if (nxt == 0) return 0;       if (nxt < curres) {         curres = nxt;       } else {         s[i] =  a ;       }     }     s[len - 1] =  b ;     ask(s);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string a, b, c;     bool yes = true;     int length, i;     cin >> a >> b;     length = a.length();     for (i = 0; i < length; i++) {       if (a[i] < b[i]) {         yes = false;         break;       }     }     if (yes == false) {       cout << -1 << endl;     } else {       cout << b << endl;     }     return 0;   }


#include <bits/stdc++.h>   int read() {     int x = 0, c = getchar();     while (!isdigit(c)) c = getchar();     while (isdigit(c)) x = x * 10 + c -  0 , c = getchar();     return x;   }   const int maxn = 205, mod = 1000000009;   std::vector<int> G[maxn];   int ins[maxn];   int stack[maxn], sp;   int dfn[maxn], low[maxn], ip;   int bl[maxn], bsz[maxn], bp;   bool blin[maxn][maxn];   void dfs(int u, int fa) {     low[u] = dfn[u] = ++ip;     stack[++sp] = u;     ins[u] = 1;     for (size_t i = 0, sz = G[u].size(); i < sz; i++) {       int v = G[u][i];       if (v == fa) continue;       if (!dfn[v]) {         dfs(v, u);         low[u] = std::min(low[u], low[v]);       } else if (ins[v])         low[u] = std::min(low[u], dfn[v]);     }     if (low[u] == dfn[u]) {       ++bp;       while (stack[sp + 1] != u) {         int x = stack[sp--];         ins[x] = 0;         ++bsz[bp];         bl[x] = bp;       }     }   }   bool vis[maxn];   int key[maxn];   std::vector<int> T[maxn];   void get(int u, int fa) {     bool ok = bsz[u] == 1;     for (int v = 1; v <= bp; v++)       if (blin[u][v] and v != fa and v != u) {         get(v, u);         ok &= key[v] == 1;       }     if (ok) {       key[u] = 1;       for (int v = 1; v <= bp; v++)         if (blin[u][v] and v != fa) {           key[v] = -1;           T[u].push_back(v);         }     } else       key[u] = -1;   }   long long C[maxn][maxn];   long long f[maxn][maxn], g[maxn][maxn], h[maxn][maxn];   long long ans[maxn], tmp[maxn];   int size[maxn];   void dp1(int u) {     size[u] = 1;     f[u][0] = 1;     for (size_t i = 0, sz = T[u].size(); i < sz; i++) {       int v = T[u][i];       dp1(v);       for (int i = size[u]; i >= 0; i--)         for (int j = 1; j <= size[v]; j++)           (f[u][i + j] += f[u][i] * f[v][j] % mod * C[i + j][i]) %= mod;       size[u] += size[v];     }     f[u][size[u]] = f[u][size[u] - 1];   }   void dp2(int u, int n) {     for (int i = 0; i < size[u]; i++)       for (int j = 0; j <= n - size[u]; j++)         (h[u][i + j] += f[u][i] * g[u][j] % mod * C[i + j][i]) %= mod;     for (size_t i = 0, sz = T[u].size(); i < sz; i++) {       int v = T[u][i];       for (int i = 0; i < n; i++) g[v][i] = h[u][i];       for (int i = 0; i < n - size[v]; i++)         for (int j = 1; j <= size[v]; j++)           (g[v][i + j] += (mod - g[v][i]) * f[v][j] % mod * C[i + j][i]) %= mod;       g[v][n - size[v]] = g[v][n - size[v] - 1];       dp2(v, n);     }     for (int i = 0; i <= n - size[u]; i++)       (tmp[size[u] + i] +=        f[u][size[u] - 1] * g[u][i] % mod * C[size[u] - 1 + i][i]) %= mod;     for (size_t i = 0, sz = T[u].size(); i < sz; i++) {       int v = T[u][i];       for (int i = 0; i < size[v]; i++)         (tmp[n - size[v] + i] += g[v][n - size[v] - 1] * f[v][i] % mod *                                  C[n - size[v] - 1 + i][i]) %= mod;     }   }   int main() {     int n = read(), m = read();     for (int i = 1; i <= m; i++) {       int u = read(), v = read();       G[u].push_back(v);       G[v].push_back(u);     }     for (int u = 1; u <= n; u++)       if (!dfn[u]) dfs(u, 0);     for (int u = 1; u <= n; u++)       for (size_t i = 0, sz = G[u].size(); i < sz; i++)         blin[bl[u]][bl[G[u][i]]] = 1;     for (int i = 0; i <= n; i++) {       C[i][0] = 1;       for (int j = 1; j <= i; j++)         C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % mod;     }     ans[0] = 1;     for (int i = 1; i <= bp; i++)       if (!key[i] and bsz[i] > 1) get(i, 0);     for (int u = 1; u <= bp; u++)       if (key[u] == 1) {         key[u] = -1;         dp1(u);         for (int i = n; i >= 0; i--)           for (int j = 1; j <= size[u]; j++)             (ans[i + j] += ans[i] * f[u][j] % mod * C[i + j][i]) %= mod;       }     for (int i = 1; i <= bp; i++)       if (!key[i] and bsz[i] == 1) get(i, 0);     for (int u = 1; u <= bp; u++)       if (key[u] == 1) {         key[u] = -1;         dp1(u);         g[u][0] = 1;         tmp[0] = 1;         for (int i = 1; i <= size[u]; i++) tmp[i] = 0;         dp2(u, size[u]);         for (int i = n; i >= 0; i--)           for (int j = 1; j <= size[u]; j++)             (ans[i + j] += ans[i] * tmp[j] % mod * C[i + j][i]) %= mod;       }     for (int i = 0; i <= n; i++) printf( %lld n , ans[i]);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     int n = s.length();     int m;     cin >> m;     int a[m];     for (int i = 0; i < m; i++) {       cin >> a[i];     }     sort(a, a + m);     for (int i = 0; i * 2 < s.size(); i++) {       int pos = upper_bound(a, a + m, i + 1) - a;       if (pos % 2) {         swap(s[i], s[s.size() - 1 - i]);       }     }     for (int i = 0; i < s.size(); i++) {       cout << s[i];     }   }


#include <bits/stdc++.h>   using namespace std;   struct data {     int x, y;   } t[800001];   int n, m, k, x, y, sum, cnt, tot, h[400001], st[400001], f[400001], fa[400001],       p[400001], idfn[400001], dfn[400001], low[400001], son[400001], dep[400001],       sz[400001], tr[1600001];   char ch[11];   vector<int> v[400001];   multiset<int> q[400001];   void add(int a, int b) {     cnt++;     t[cnt].x = b;     t[cnt].y = h[a];     h[a] = cnt;   }   void tarjan(int a) {     cnt++;     dfn[a] = cnt;     low[a] = cnt;     tot++;     st[tot] = a;     for (int i = h[a]; i; i = t[i].y) {       if (!dfn[t[i].x]) {         tarjan(t[i].x);         low[a] = min(low[a], low[t[i].x]);         if (low[t[i].x] >= dfn[a]) {           sum++;           v[sum].push_back(a);           v[a].push_back(sum);           int c;           do {             c = st[tot];             tot--;             v[sum].push_back(c);             v[c].push_back(sum);           } while (c != t[i].x);         }       } else {         low[a] = min(low[a], dfn[t[i].x]);       }     }   }   void dfs1(int a) {     sz[a] = 1;     for (int i = h[a]; i; i = t[i].y) {       if (t[i].x == fa[a]) continue;       fa[t[i].x] = a;       dep[t[i].x] = dep[a] + 1;       dfs1(t[i].x);       if (sz[son[a]] < sz[t[i].x]) son[a] = t[i].x;       sz[a] = sz[a] + sz[t[i].x];     }   }   void dfs2(int a, int c) {     cnt++;     dfn[a] = cnt;     idfn[cnt] = a;     p[a] = c;     if (son[a]) dfs2(son[a], c);     for (int i = h[a]; i; i = t[i].y) {       if (t[i].x == fa[a]) continue;       if (t[i].x == son[a]) continue;       dfs2(t[i].x, t[i].x);     }   }   void build(int a, int l, int r) {     if (l == r) {       tr[a] = f[idfn[l]];       return;     }     int mid = (l + r) / 2;     build(a * 2, l, mid);     build(a * 2 + 1, mid + 1, r);     tr[a] = min(tr[a * 2], tr[a * 2 + 1]);   }   void turn(int a, int l, int r, int u, int v) {     if (l > u || r < u) return;     if (l == r) {       tr[a] = v;       return;     }     int mid = (l + r) / 2;     turn(a * 2, l, mid, u, v);     turn(a * 2 + 1, mid + 1, r, u, v);     tr[a] = min(tr[a * 2], tr[a * 2 + 1]);   }   int find(int a, int l, int r, int ql, int qr) {     if (l > qr || r < ql) return 1000000000;     if (ql <= l && r <= qr) return tr[a];     int mid = (l + r) / 2;     int p1 = find(a * 2, l, mid, ql, qr);     int p2 = find(a * 2 + 1, mid + 1, r, ql, qr);     return min(p1, p2);   }   int solve(int a, int b) {     int s = 1000000000;     while (p[a] != p[b]) {       if (dep[p[a]] > dep[p[b]]) swap(a, b);       s = min(s, find(1, 1, sum, dfn[p[b]], dfn[b]));       b = fa[p[b]];     }     if (dep[a] > dep[b]) swap(a, b);     s = min(s, find(1, 1, sum, dfn[a], dfn[b]));     if (a > n) s = min(s, f[fa[a]]);     return s;   }   int main() {     scanf( %d%d%d , &n, &m, &k);     for (int i = 1; i <= n; i++) scanf( %d , &f[i]);     for (int i = 1; i <= m; i++) {       scanf( %d%d , &x, &y);       add(x, y);       add(y, x);     }     cnt = 0;     sum = n;     tarjan(1);     cnt = 0;     for (int i = 1; i <= n; i++) h[i] = 0;     for (int i = 1; i <= sum; i++) {       for (int j = 0; j < v[i].size(); j++) {         add(i, v[i][j]);       }     }     cnt = 0;     dfs1(1);     dfs2(1, 1);     for (int i = n + 1; i <= sum; i++) {       for (int j = h[i]; j; j = t[j].y) {         if (t[j].x == fa[i]) continue;         q[i].insert(f[t[j].x]);       }       f[i] = *q[i].begin();     }     build(1, 1, sum);     for (int i = 1; i <= k; i++) {       scanf( %s%d%d , ch + 1, &x, &y);       if (ch[1] ==  C ) {         if (fa[x] > n) {           q[fa[x]].erase(q[fa[x]].find(f[x]));           q[fa[x]].insert(y);           turn(1, 1, sum, dfn[fa[x]], *q[fa[x]].begin());         }         f[x] = y;         turn(1, 1, sum, dfn[x], y);       } else {         printf( %d n , solve(x, y));       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) {       if (i % 4 == 0 || i % 4 == 1) {         printf( a );       } else {         printf( b );       }     }   }


#include <bits/stdc++.h>   using namespace std;   inline long long rd() {     long long x = 0;     int ch = getchar(), f = 1;     while (!isdigit(ch) && (ch !=  - ) && (ch != EOF)) ch = getchar();     if (ch ==  - ) {       f = -1;       ch = getchar();     }     while (isdigit(ch)) {       x = (x << 1) + (x << 3) + ch -  0 ;       ch = getchar();     }     return x * f;   }   inline void rt(long long x) {     if (x < 0) putchar( - ), x = -x;     if (x >= 10)       rt(x / 10), putchar(x % 10 +  0 );     else       putchar(x +  0 );   }   const int p = 1000000007;   long long n, k;   long long phi(long long n) {     long long ret = n;     for (long long i = 2; i * i <= n; i++)       if (n % i == 0) {         ret = ret / i * (i - 1);         while (n % i == 0) n /= i;       }     if (n != 1) ret = ret / n * (n - 1);     return ret;   }   int main() {     n = rd(), k = (rd() + 1) / 2;     while (n != 1 && k) n = phi(n), k--;     rt(n % p), putchar(  n );   }


#include <bits/stdc++.h>   using namespace std;   const long long inf = 1000000000000000000;   int c[1001][1001];   int main(void) {     int n, m;     scanf( %d %d , &n, &m);     long long s = 0, sij = 0, si = 0, sj = 0;     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= m; ++j) {         int p = (i - 1) * 4 + 2, q = (j - 1) * 4 + 2;         scanf( %d , &c[i][j]);         s += c[i][j];         sij += (long long)c[i][j] * (p * p + q * q);         si += c[i][j] * p;         sj += c[i][j] * q;       }     }     int x, y;     long long ans = inf;     for (int i = 0; i <= n; ++i) {       for (int j = 0; j <= m; ++j) {         int p = i * 4, q = j * 4;         long long temp = s * (p * p + q * q) - 2 * si * p - 2 * sj * q + sij;         if (temp < ans) {           ans = temp;           x = i;           y = j;         }       }     }     printf( %I64d n%d %d n , ans, x, y);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   inline int read() {     int t = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) f = (ch ==  - ) ? -1 : f, ch = getchar();     while (ch >=  0  && ch <=  9 ) t = t * 10 + ch -  0 , ch = getchar();     return t * f;   }   struct orz {     char s[16];     int x, y;     void in() { scanf( %s , s), x = read(), y = read(); }     friend bool operator<(orz a, orz b) {       return (a.x == b.x) ? a.y > b.y : a.x < b.x;     }   } a[200105];   int main() {     n = read(), m = read();     for (register int i = 1; i <= n; i++) a[i].in();     sort(a + 1, a + n + 1);     int now = 1;     for (register int i = 1; i <= m; i++) {       while (a[now].x != i) now++;       if (now + 2 <= n && a[now + 2].x == a[now + 1].x &&           a[now + 2].y == a[now + 1].y)         puts( ? );       else         printf( %s %s n , a[now].s, a[now + 1].s);       now++;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     string myNumber;     cin >> myNumber;     int temp;     int fhalf = 0, shalf = 0;     for (int i = 0; i < n / 2; ++i) {       temp = myNumber[i] -  0 ;       if (temp != 4 && temp != 7) {         cout <<  NO ;         goto exit;       }       shalf += temp;     }     for (int i = n / 2; i < n; ++i) {       temp = myNumber[i] -  0 ;       if (temp != 4 && temp != 7) {         cout <<  NO ;         goto exit;       }       fhalf += temp;     }     if (fhalf == shalf)       cout <<  YES ;     else       cout <<  NO ;   exit:     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     unordered_map<int, int> ma;     int x, y, z, l;     cin >> x >> y;     vector<int> vec(x);     vector<int> vec1(x);     for (int i = 0; i < x; i++) cin >> vec[i];     vec1 = vec;     for (int i = 0; i < y; i++) {       cin >> z >> l;       if (vec[z - 1] > vec[l - 1])         ma[z - 1]++;       else if (vec[l - 1] > vec[z - 1])         ma[l - 1]++;     }     sort(vec1.begin(), vec1.end());     for (int i = 0; i < x; i++) {       int r = lower_bound(vec1.begin(), vec1.end(), vec[i]) - vec1.begin();       cout << r - ma[i] <<    ;     }   }


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


#include <bits/stdc++.h>   using namespace std;   int n, k;   struct node {     int mn[11], mx[11], sz;     bool operator<(const node &p) const {       for (int i = 1; i <= k; i++)         if (mx[i] > p.mn[i]) return 0;       return 1;     }   } now;   set<node> S;   set<node>::iterator it;   int main() {     scanf( %d%d , &n, &k);     for (int i = 1; i <= n; i++) {       now.sz = 1;       for (int j = 1; j <= k; j++) scanf( %d , &now.mn[j]), now.mx[j] = now.mn[j];       for (; (it = S.find(now)) != S.end(); S.erase(it)) {         now.sz += (*it).sz;         for (int j = 1; j <= k; j++)           now.mn[j] = min(now.mn[j], (*it).mn[j]),           now.mx[j] = max(now.mx[j], (*it).mx[j]);       }       S.insert(now);       printf( %d n , (*S.rbegin()).sz);     }   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 2e5 + 3;   vector<int> adj[MAXN];   int sz[MAXN], rt = -1, ok[MAXN], k;   int dfs1(int u, int p) {     for (int i = 0; i < adj[u].size(); i++)       if (adj[u][i] != p) sz[u] += dfs1(adj[u][i], u);     return sz[u];   }   pair<int, int> dfs2(int u, int p) {     vector<pair<int, int> > ans;     pair<int, int> ret;     ans.push_back(make_pair(sz[u], u));     for (int i = 0; i < adj[u].size(); i++)       if (adj[u][i] != p) {         if (sz[adj[u][i]] >= k) {           ans.push_back(make_pair(sz[adj[u][i]], adj[u][i]));           ans.push_back(dfs2(adj[u][i], u));         }       }     sort(ans.begin(), ans.end());     for (int i = 0; i < ans.size(); i++) {       if (ans[i].first >= k && (rt == -1 || sz[rt] > ans[i].first))         rt = ans[i].second, ret = ans[i];     }     return ret;   }   long long dfs3(int u, int p, int dep) {     long long ret = 0;     if (ok[u]) ret += dep;     for (int i = 0; i < adj[u].size(); i++)       if (adj[u][i] != p) ret += dfs3(adj[u][i], u, dep + 1);     return ret;   }   int main() {     int n, x;     scanf( %d%d , &n, &k);     for (int i = 0; i < 2 * k; i++) scanf( %d , &x), ok[x] = sz[x] = 1;     for (int i = 0; i < n - 1; i++) {       int a, b;       scanf( %d%d , &a, &b);       adj[a].push_back(b);       adj[b].push_back(a);     }     dfs1(1, -1);     dfs2(1, -1);     printf( %I64d n , dfs3(rt, -1, 0));   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     long long int g = 0;     pair<int, int> A[1000], B[1000];     for (int i = 1; i <= n; i++) {       cin >> A[i].first >> A[i].second;       cin >> B[i].first >> B[i].second;       g += (((B[i].first - A[i].first) + 1) * ((B[i].second - A[i].second) + 1));     }     cout << g;     return 0;   }


#include <bits/stdc++.h>   int main() {     int n, m, x, nn, j, mm, y, z, i, tmp, p;     int a, b;     scanf( %d%d%d%d%d%d , &nn, &mm, &x, &y, &z, &p);     for (j = 1; j <= p; j++) {       n = nn;       m = mm;       scanf( %d%d , &a, &b);       x %= 4;       z %= 4;       if (y % 2 == 0) {         for (i = 1; i <= (x + 4 - z) % 4; i++) {           tmp = a;           a = b;           b = n - tmp + 1;           tmp = n;           n = m;           m = tmp;         }         printf( %d %d n , a, b);       } else {         for (i = 1; i <= (x + z) % 4; i++) {           tmp = a;           a = b;           b = n - tmp + 1;           tmp = n;           n = m;           m = tmp;         }         printf( %d %d n , a, m - b + 1);       }     }     return 0;   }


#include <bits/stdc++.h>   const int maxn = 400000 + 5;   int f[maxn];   int n, m, q;   int ans;   inline int Read() {     register int ret;     register char r;     register bool f = false;     while (r = getchar(), r <  0  || r >  9 )       if (r ==  - ) f = true;     ret = r - 48;     while (r = getchar(), r >=  0  && r <=  9 )       ret = (ret << 3) + (ret << 1) + r - 48;     return f ? ~ret + 1 : ret;   }   inline int Find(int x) { return x == f[x] ? x : f[x] = Find(f[x]); }   int main() {     n = Read();     m = Read();     q = Read();     for (register int i = n + m; i; i--) f[i] = i;     for (register int i = 1; i <= q; i++) {       int x = Find(Read()), y = Find(Read() + n);       if (x != y) f[x] = y;     }     for (register int i = n + m; i; i--) ans += (Find(i) == i);     printf( %d n , ans - 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using P = pair<int, int>;   int main() {     int q;     cin >> q;     vector<P> v(q);     for (int qi = 0; qi < q; qi++) {       int t;       cin >> t;       if (t == 1) {         int x;         cin >> x;         v[qi] = {x, 0};       } else {         int x, y;         cin >> x >> y;         v[qi] = {-x, y};       }     }     reverse(v.begin(), v.end());     map<int, int> to;     vector<int> ans;     for (auto now : v) {       if (now.first >= 0) {         if (to.count(now.first)) {           now.first = to[now.first];         }         ans.push_back(now.first);       } else {         now.first *= -1;         if (to.count(now.second)) {           to[now.first] = to[now.second];         } else {           to[now.first] = now.second;         }       }     }     reverse(ans.begin(), ans.end());     cout << ans[0];     for (int i = 1; i < (int)ans.size(); i++) {       cout <<     << ans[i];     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 12e4 + 5;   struct node {     int minn, cnt, lazy, time;     long long sum;   } tree[maxn << 2];   int n, q;   int p[maxn], stk_min[maxn], stk_max[maxn], top_min, top_max;   long long ans[maxn];   pair<pair<int, int>, int> querys[maxn];   inline void add(int rt, int val) {     tree[rt].minn += val;     tree[rt].lazy += val;   }   inline void add_time(int rt, int val) {     tree[rt].time += val;     tree[rt].sum += 1ll * tree[rt].cnt * val;   }   void build(int rt, int l, int r) {     tree[rt].minn = l, tree[rt].cnt = 1;     if (l != r) {       int mid = l + r >> 1;       build(rt << 1, l, mid), build(rt << 1 | 1, mid + 1, r);     }   }   inline void pushup(int rt) {     int ls = rt << 1, rs = rt << 1 | 1;     tree[rt].minn = min(tree[ls].minn, tree[rs].minn);     tree[rt].sum = tree[ls].sum + tree[rs].sum;     tree[rt].cnt = 0;     if (tree[rt].minn == tree[ls].minn) tree[rt].cnt += tree[ls].cnt;     if (tree[rt].minn == tree[rs].minn) tree[rt].cnt += tree[rs].cnt;   }   inline void pushdown(int rt) {     int ls = rt << 1, rs = rt << 1 | 1;     if (tree[rt].lazy) {       add(ls, tree[rt].lazy);       add(rs, tree[rt].lazy);       tree[rt].lazy = 0;     }     if (tree[rt].time) {       if (tree[rt].minn == tree[ls].minn) add_time(ls, tree[rt].time);       if (tree[rt].minn == tree[rs].minn) add_time(rs, tree[rt].time);       tree[rt].time = 0;     }   }   void update(int rt, int l, int r, int ql, int qr, int val) {     if (ql <= l && r <= qr) {       add(rt, val);     } else {       int mid = l + r >> 1;       pushdown(rt);       if (qr <= mid)         update(rt << 1, l, mid, ql, qr, val);       else if (ql > mid)         update(rt << 1 | 1, mid + 1, r, ql, qr, val);       else {         update(rt << 1, l, mid, ql, mid, val);         update(rt << 1 | 1, mid + 1, r, mid + 1, qr, val);       }       pushup(rt);     }   }   long long query(int rt, int l, int r, int ql, int qr) {     if (ql <= l && r <= qr) {       return tree[rt].sum;     } else {       int mid = l + r >> 1;       pushdown(rt);       if (qr <= mid)         return query(rt << 1, l, mid, ql, qr);       else if (ql > mid)         return query(rt << 1 | 1, mid + 1, r, ql, qr);       else         return query(rt << 1, l, mid, ql, mid) +                query(rt << 1 | 1, mid + 1, r, mid + 1, qr);     }   }   int main() {     ios::sync_with_stdio(false), cin.tie(nullptr);     cin >> n;     for (int i = 1; i <= n; i++) cin >> p[i];     cin >> q;     for (int i = 1; i <= q; i++) {       int l, r;       cin >> l >> r;       querys[i] = {{l, r}, i};     }     sort(querys + 1, querys + q + 1,          [](const pair<pair<int, int>, int> &a,             const pair<pair<int, int>, int> &b) {            return a.first.second < b.first.second;          });     build(1, 1, n);     for (int i = 1, j = 1; i <= n; i++) {       update(1, 1, n, 1, n, -1);       while (top_min && p[i] < p[stk_min[top_min]]) {         update(1, 1, n, stk_min[top_min - 1] + 1, stk_min[top_min],                p[stk_min[top_min]] - p[i]);         --top_min;       }       while (top_max && p[i] > p[stk_max[top_max]]) {         update(1, 1, n, stk_max[top_max - 1] + 1, stk_max[top_max],                p[i] - p[stk_max[top_max]]);         --top_max;       }       stk_min[++top_min] = i;       stk_max[++top_max] = i;       add_time(1, 1);       while (j <= q && querys[j].first.second == i) {         ans[querys[j].second] =             query(1, 1, n, querys[j].first.first, querys[j].first.second);         ++j;       }     }     for (int i = 1; i <= q; i++) cout << ans[i] <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1000000007;   const int MAXN = 305;   const int MAXT = 100005;   int a[MAXN], e[MAXN], d[MAXN];   long long dp[MAXT];   long long t, cnt;   void dfs(int u, int acc) {     if (t < 0) {       return;     }     ++cnt;     a[u] += acc;     if (e[u] != 0) {       dfs(e[u], a[u]);       t -= a[u];       if (t < 0) {         return;       }     }   }   int main() {     int n, q;     int u, v;     scanf( %d%d%d , &n, &q, &t);     for (int i = 1; i <= n; ++i) {       scanf( %d , a + i);     }     while (q--) {       scanf( %d%d , &u, &v);       e[u] = v;       d[v] = 1;     }     for (int i = 1; i <= n && t >= 0; ++i) {       if (d[i] == 0) {         dfs(i, 0);       }     }     if (t < 0 || cnt < n) {       printf( 0 n );       return 0;     }     dp[0] = 1;     for (int i = 1; i <= n; ++i) {       for (int j = a[i]; j <= t; ++j) {         dp[j] = (dp[j] + dp[j - a[i]]) % MOD;       }     }     printf( %d n , dp[t]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   queue<int> q[300005];   set<int> all;   int main() {     int n, quer;     scanf( %d%d , &n, &quer);     int t, x, v;     int in = 1;     for (int i = 1; i <= quer; i++) {       scanf( %d%d , &t, &x);       if (t == 1) {         q[x].push(in);         all.insert(in);         in++;       } else if (t == 2) {         while (!q[x].empty()) {           all.erase(q[x].front());           q[x].pop();         }       } else {         while (all.size() >= 1) {           v = *all.begin();           if (v <= x)             all.erase(v);           else             break;         }       }       printf( %d n , all.size());     }   }


#include <bits/stdc++.h>   using namespace std;   struct SegmentTree {    private:     int n;     vector<pair<int, int>> a;     vector<pair<int, int>> tree;       public:     SegmentTree(vector<pair<int, int>> &a) {       this->a = a;       this->n = (int)a.size();       tree.resize(4 * n);       build(1, 1, n);     }     void update(int l, int r, pair<int, int> x) { update(1, 1, n, l, r, x); }     pair<int, int> query(int i) { return query(1, 1, n, i); }       private:     void build(int i, int l, int r) {       if (l == r)         tree[i] = a[l - 1];       else {         int m = (l + r) / 2;         build(2 * i, l, m);         build(2 * i + 1, m + 1, r);         tree[i] = make_pair(0, 0);       }     }     void update(int i, int l, int r, int ul, int ur, pair<int, int> x) {       if (ul <= l && r <= ur)         tree[i] = x;       else {         if (tree[i] != make_pair(0, 0)) {           tree[2 * i] = tree[2 * i + 1] = tree[i];         }         int m = (l + r) / 2;         if (ul <= m) update(2 * i, l, m, ul, ur, x);         if (ur > m) update(2 * i + 1, m + 1, r, ul, ur, x);         tree[i] = tree[2 * i] == tree[2 * i + 1] ? tree[2 * i] : make_pair(0, 0);       }     }     pair<int, int> query(int i, int l, int r, int qi) {       if (tree[i] != make_pair(0, 0)) return tree[i];       int m = (l + r) / 2;       if (qi <= m)         return query(2 * i, l, m, qi);       else         return query(2 * i + 1, m + 1, r, qi);     }   };   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n, m;     cin >> n >> m;     vector<int> a(2 * n);     for (auto &ai : a) cin >> ai;     vector<pair<int, int>> b(n);     for (int i = 0; i < n; i++) b[i] = make_pair(i + n + 1, i + 1);     SegmentTree tree(b);     while (m--) {       int t;       cin >> t;       if (t == 1) {         int x, y, k;         cin >> x >> y >> k;         tree.update(y, y + k - 1, make_pair(x, y));       } else {         int x;         cin >> x;         auto aux = tree.query(x);         int diff = x - aux.second;         int ans = a[aux.first + diff - 1];         cout << ans <<   n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int n, m, a[101], s[101], ans, l, r;   int main() {     ios::sync_with_stdio(false);     cin >> n >> m;     for (int i = 1; i < n + 1; i++) cin >> a[i];     for (int i = 1; i < n + 1; i++) s[i] = s[i - 1] + a[i];     ans = 0;     for (int i = 0; i < m; i++) {       cin >> l >> r;       if (s[r] - s[l - 1] > 0) ans += s[r] - s[l - 1];     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5;   int n;   struct node {     int op;     long long l;     long long r;   } q[N + 5];   int cnt;   long long Hash[3 * N + 5];   int len;   struct T {     int sum;     int lazy;   } tree[12 * N + 5];   void pushup(int k) { tree[k].sum = tree[k << 1].sum + tree[k << 1 | 1].sum; }   void pushdown(int k, int l, int r) {     if (tree[k].lazy == 0) return;     int mid = (l + r) >> 1;     if (tree[k].lazy == 1) {       tree[k << 1].sum = mid - l + 1;       tree[k << 1 | 1].sum = r - (mid + 1) + 1;       tree[k << 1].lazy = tree[k << 1 | 1].lazy = tree[k].lazy;     } else if (tree[k].lazy == 2) {       tree[k << 1].sum = tree[k << 1 | 1].sum = 0;       tree[k << 1].lazy = tree[k << 1 | 1].lazy = tree[k].lazy;     } else {       tree[k << 1].sum = mid - l + 1 - tree[k << 1].sum;       tree[k << 1 | 1].sum = r - (mid + 1) + 1 - tree[k << 1 | 1].sum;       if (tree[k << 1].lazy == 0)         tree[k << 1].lazy = 3;       else if (tree[k << 1].lazy == 1)         tree[k << 1].lazy = 2;       else if (tree[k << 1].lazy == 2)         tree[k << 1].lazy = 1;       else if (tree[k << 1].lazy == 3)         tree[k << 1].lazy = 0;       if (tree[k << 1 | 1].lazy == 0)         tree[k << 1 | 1].lazy = 3;       else if (tree[k << 1 | 1].lazy == 1)         tree[k << 1 | 1].lazy = 2;       else if (tree[k << 1 | 1].lazy == 2)         tree[k << 1 | 1].lazy = 1;       else if (tree[k << 1 | 1].lazy == 3)         tree[k << 1 | 1].lazy = 0;     }     tree[k].lazy = 0;   }   void build(int k, int l, int r) {     if (l == r) {       tree[k].sum = tree[k].lazy = 0;       return;     }     int mid = (l + r) >> 1;     build(k << 1, l, mid);     build(k << 1 | 1, mid + 1, r);     pushup(k);   }   void update(int k, int l, int r, int flag, int x, int y) {     if (l >= x && r <= y) {       if (flag == 1) {         tree[k].sum = r - l + 1;         tree[k].lazy = 1;         return;       } else if (flag == 2) {         tree[k].sum = 0;         tree[k].lazy = 2;         return;       } else {         tree[k].sum = (r - l + 1) - tree[k].sum;         if (tree[k].lazy == 0)           tree[k].lazy = 3;         else if (tree[k].lazy == 1)           tree[k].lazy = 2;         else if (tree[k].lazy == 2)           tree[k].lazy = 1;         else if (tree[k].lazy == 3)           tree[k].lazy = 0;         return;       }     }     int mid = (l + r) >> 1;     pushdown(k, l, r);     if (x <= mid) update(k << 1, l, mid, flag, x, y);     if (mid < y) update(k << 1 | 1, mid + 1, r, flag, x, y);     pushup(k);   }   int query(int k, int l, int r) {     if (l == r) return l;     int mid = (l + r) >> 1;     pushdown(k, l, r);     if (tree[k << 1].sum < mid - l + 1) return query(k << 1, l, mid);     return query(k << 1 | 1, mid + 1, r);   }   int main() {     scanf( %d , &n);     Hash[++cnt] = 1;     for (int i = 1; i <= n; i++) {       scanf( %d%lld%lld , &q[i].op, &q[i].l, &q[i].r);       Hash[++cnt] = q[i].l;       Hash[++cnt] = q[i].r;       Hash[++cnt] = q[i].r + 1;     }     sort(Hash + 1, Hash + cnt + 1);     len = unique(Hash + 1, Hash + cnt + 1) - (Hash + 1);     for (int i = 1; i <= n; i++) {       q[i].l = lower_bound(Hash + 1, Hash + len + 1, q[i].l) - Hash;       q[i].r = lower_bound(Hash + 1, Hash + len + 1, q[i].r) - Hash;     }     build(1, 1, len);     for (int i = 1; i <= n; i++) {       update(1, 1, len, q[i].op, q[i].l, q[i].r);       printf( %lld n , Hash[query(1, 1, len)]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long double pi = acos(-1.0), eps = 1e-10;   long double det(long double a11, long double a12, long double a21,                   long double a22) {     return a11 * a22 - a12 * a21;   }   struct pt {     long double x, y;     pt(long double x, long double y) : x(x), y(y) {}   };   struct line {     long double a, b, c;     line(long double x1, long double y1, long double x2, long double y2) {       a = y1 - y2;       b = x2 - x1;       c = a * x1 + b * y1;     }     line(long double a, long double b, long double c) : a(a), b(b), c(c) {}     void transpose(pt p) { c += a * p.x + b * p.y; }   };   struct circle {     long double x, y, r;     circle(long double x, long double y, long double r) : x(x), y(y), r(r) {}   };   long double dist(long double x1, long double y1, long double x2,                    long double y2) {     long double dx = x1 - x2, dy = y1 - y2;     return sqrt(dx * dx + dy * dy);   }   vector<pt> lineCircleIntersection(line l, pt center, long double r) {     line t(l);     t.transpose(pt(-center.x, -center.y));     long double a = t.a, b = t.b, c = -t.c;     long double x0 = -a * c / (a * a + b * b), y0 = -b * c / (a * a + b * b);     vector<pt> res;     if (c * c > r * r * (a * a + b * b) + eps) {     } else if (fabs(c * c - r * r * (a * a + b * b)) < eps) {       res.push_back(pt(x0 + center.x, y0 + center.y));     } else {       long double d = r * r - c * c / (a * a + b * b);       long double mult = sqrt(d / (a * a + b * b));       long double ax, ay, bx, by;       ax = x0 + b * mult;       bx = x0 - b * mult;       ay = y0 - a * mult;       by = y0 + a * mult;       res.push_back(pt(ax + center.x, ay + center.y));       res.push_back(pt(bx + center.x, by + center.y));     }     return res;   }   vector<pt> circleCircleIntersection(circle c1, circle c2) {     long double x = c1.x - c2.x, y = c1.y - c2.y;     vector<pt> res = lineCircleIntersection(         line(2 * x, 2 * y, x * x + y * y + c2.r * c2.r - c1.r * c1.r), pt(0, 0),         c2.r);     for (int i = 0; i < (int)res.size(); i++) {       res[i].x += c2.x;       res[i].y += c2.y;     }     return res;   }   bool inside(pt p, circle c) { return dist(p.x, p.y, c.x, c.y) <= c.r + eps; }   bool intersects(circle c1, circle c2, circle c3) {     c1.r += eps;     c2.r += eps;     c3.r += eps;     vector<pt> p[3];     p[0] = circleCircleIntersection(c1, c2);     p[1] = circleCircleIntersection(c2, c3);     p[2] = circleCircleIntersection(c3, c1);     p[0].push_back(pt(c1.x, c1.y));     p[1].push_back(pt(c2.x, c2.y));     p[2].push_back(pt(c3.x, c3.y));     for (int i = 0; i < 3; i++) {       for (size_t j = 0; j < p[i].size(); j++) {         if (inside(p[i][j], c1) && inside(p[i][j], c2) && inside(p[i][j], c3)) {           return true;         }       }     }     return false;   }   long double t1, t2, cx, cy, hx, hy, sx, sy;   void solve() {     long double d1 = dist(hx, hy, sx, sy), d2 = dist(sx, sy, cx, cy),                 d3 = dist(cx, cy, hx, hy);     long double l1 = d1 + d2 + t1, l2 = d3 + t2;     cout << fixed << setprecision(10);     if (l2 >= d1 + d2) {       cout << min(l1, l2) << endl;     } else {       long double L = 0, R = min(l1, l2);       while (fabs(L - R) > eps) {         long double r1 = (L + R) / 2, r2 = max(0. * l1, l1 - d1 - r1),                     r3 = max(0. * l2, l2 - r1);         if (intersects(circle(cx, cy, r1), circle(sx, sy, r2),                        circle(hx, hy, r3))) {           L = r1;         } else {           R = r1;         }       }       cout << L + eps << endl;     }   }   int main() {     while (cin >> t1 >> t2 >> cx >> cy >> hx >> hy >> sx >> sy) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   int n;   long long sum = 0, m1 = 0;   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) {       int x;       scanf( %d , &x);       sum += x;       m1 = max(m1, (long long)x);     }     if (m1 <= sum / 2 && sum % 2 == 0)       printf( YES n );     else       printf( NO n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 200004 * 4 + 11;   long long k[N], add[N];   int a[200004];   int n, m;   int x, y;   long long z;   long long ans;   int build(int l, int r, int o) {     add[o] = 0;     if (l == r) return k[o] = a[l];     int mid = ((l + r) >> 1);     return k[o] = build(l, mid, (o << 1)) + build(mid + 1, r, ((o << 1) | 1));   }   void pushdown(int l, int r, int o) {     add[(o << 1)] += add[o];     add[((o << 1) | 1)] += add[o];     add[o] = 0;   }   void maintain(int l, int r, int o) {     int mid = ((l + r) >> 1);     if (r > l)       k[o] = k[(o << 1)] + add[(o << 1)] * (mid - l + 1) + k[((o << 1) | 1)] +              add[((o << 1) | 1)] * (r - mid);     else       k[o] = a[l];   }   void update(int l, int r, int o) {     if (x <= l && r <= y) {       add[o] += z;     } else {       pushdown(l, r, o);       int mid = ((l + r) >> 1);       if (x <= mid)         update(l, mid, (o << 1));       else         maintain(l, mid, (o << 1));       if (y > mid)         update(mid + 1, r, ((o << 1) | 1));       else         maintain(mid + 1, r, ((o << 1) | 1));     }     maintain(l, r, o);   }   void query(int l, int r, int o) {     if (x <= l && r <= y)       ans += k[o] + add[o] * (r - l + 1);     else {       pushdown(l, r, o);       int mid = ((l + r) >> 1);       if (x <= mid) query(l, mid, (o << 1));       if (y > mid) query(mid + 1, r, ((o << 1) | 1));     }     maintain(l, r, o);   }   int main() {     long long lst = 0.0;     while (~scanf( %d , &n)) {       int i, c, e, f;       int d;       int tot = 1;       int tp = 0;       build(1, 200004, 1);       while (n--) {         scanf( %d , &c);         if (c == 1) {           scanf( %d%d , &e, &d);           z = d;           x = 1;           y = min(e, tot);           update(1, 200004, 1);           lst += e * d;         } else if (c == 2) {           scanf( %d , &d);           tot++;           x = y = tot;           z = d;           update(1, 200004, 1);           lst += d;         } else {           ans = 0;           x = y = tot;           query(1, 200004, 1);           z = -ans;           update(1, 200004, 1);           tot--;           lst += z;         }         ans = 0;         x = 1;         y = 200004;         query(1, n, 1);         printf( %.9lf n , ans * 1.0 / tot);       }     }     return 0;   }


#include <bits/stdc++.h>   int main() {     int n, q;     scanf( %d , &n);     scanf( %d , &q);     int i;     long ans[q + 1];     long val;     std::set<long> valores;     for (i = 0; i < n; i++) {       scanf( %ld , &val);       valores.insert(val);     }     std::set<long>::iterator ite;     std::multiset<long> dife;     for (ite = valores.begin(); ite != --valores.end(); ite++) {       dife.insert(*valores.upper_bound(*ite) - *ite);     }     int acc;     std::set<long>::iterator low, up;     for (i = 0; i < q; i++) {       if (valores.size() > 1)         ans[i] = *valores.rbegin() - *valores.begin() - *dife.rbegin();       else         ans[i] = 0;       scanf( %d , &acc);       scanf( %ld , &val);       if (acc == 0) {         up = valores.upper_bound(val);         low = valores.lower_bound(val);         if (up != valores.end()) {           dife.erase(dife.lower_bound(*up - val));         }         if (low != valores.begin()) {           low--;           dife.erase(dife.lower_bound(val - *low));           low++;         }         if ((up != valores.end()) && (low != valores.begin())) {           low--;           dife.insert(*up - *low);         }         valores.erase(val);       } else {         up = valores.upper_bound(val);         low = valores.lower_bound(val);         if (up != valores.end()) {           dife.insert(*up - val);         }         if (low != valores.begin()) {           low--;           dife.insert(val - *low);           low++;         }         if ((up != valores.end()) && (low != valores.begin())) {           low--;           dife.erase(dife.lower_bound(*up - *low));         }         valores.insert(val);       }     }     if (valores.size() > 1)       ans[q] = *valores.rbegin() - *valores.begin() - *dife.rbegin();     else       ans[q] = 0;     for (i = 0; i < q + 1; i++) {       printf( %d  n , ans[i]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   int n, m;   struct Query {     int l, r, x;     Query() {}     Query(int ll, int rr, int xx) { l = ll, r = rr, x = xx; }   };   vector<Query> q[N];   int lson[N], rson[N];   void init() {     int cnt = 0, p = 1;     for (int i = 1; i < N; ++i) {       if ((1 << cnt) == i) {         cnt++;         lson[i] = p++;       } else {         lson[i] = -1;       }       rson[i] = p++;     }   }   bool ok(int x1, int y1, int x2, int y2) {     if (x1 > y2 || x2 > y1) return false;     return true;   }   void solve(int k, int x) {     set<int> s;     int l = x, r = x;     for (int i = k; i < n + 1; ++i) {       for (int j = 0; j < (int)q[i].size(); ++j) {         if (ok(l, r, q[i][j].l, q[i][j].r)) {           s.insert(q[i][j].x);         }       }       if (lson[l] != -1)         l = lson[l];       else         l = rson[l];       r = rson[r];     }     printf( %d n , (int)s.size());   }   int main() {     init();     int op, k, l, r, x;     scanf( %d%d , &n, &m);     for (int i = 1; i < m + 1; ++i) {       scanf( %d , &op);       if (op == 1) {         scanf( %d%d%d%d , &k, &l, &r, &x);         q[k].push_back(Query(l, r, x));       } else {         scanf( %d%d , &k, &x);         solve(k, x);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int q;     scanf( %d , &q);     while (q--) {       int n;       scanf( %d , &n);       int sum = 0, a;       for (int i = 0; i < n; ++i) {         scanf( %d , &a);         sum += a;       }       printf( %d n , (int)ceil(sum * 1.0 / n));     }     return 0;   }


#include <bits/stdc++.h>   using std::map;   using std::max;   using std::min;   using std::set;   using std::string;   using std::vector;   constexpr long long magic_mod = 1000000007;   constexpr long long big = 1ll << 60;   struct Matrix {     long long size;     vector<long long> f;     Matrix(long long size, long long start_value = big)         : size(size), f(size * size, start_value) {}     Matrix(const Matrix& o) { *this = o; };     static vector<Matrix> cache;     inline long long& m(long long a, long long b) { return f[a * size + b]; }     inline const long long& m(long long a, long long b) const {       return f[a * size + b];     }     void print() {       for (long long i = 0; i < size; ++i) {         for (long long j = 0; j < size; ++j) {           std::cout << m(j, i) <<    ;         }         std::cout << std::endl;       }     }     void operator=(const Matrix& o) {       this->size = o.size;       this->f = o.f;     }     Matrix operator*(const Matrix& o) const {       Matrix res(size);       for (long long i = 0; i < size; ++i) {         for (long long j = 0; j < size; ++j) {           for (long long k = 0; k < size; ++k) {             res.m(i, j) = min(res.m(i, j), m(k, j) + o.m(i, k));           }         }       }       return res;     }     Matrix get_pow(long long p) {       Matrix res(*this);       bool inited = false;       for (long long i = 1;; ++i) {         if (!p) {           break;         }         if (p % 2) {           if (!inited) {             res = cache[i];             inited = true;           } else {             res = res * cache[i];           }         }         p /= 2;       }       return res;     }     void fill_cache();   };   const long long xxxx = 40;   vector<Matrix> Matrix::cache;   void Matrix::fill_cache() {     cache = vector<Matrix>(xxxx, Matrix(size));     Matrix res(*this);     for (long long i = 1; i < xxxx; ++i) {       cache[i] = res;       res = res * res;     }   }   vector<long long> standings;   vector<long long> jw;   long long sn;   map<long long, long long> magic_stones;   inline long long btc(long long x) {     long long res = 0;     while (x) {       if (x % 2) ++res;       x /= 2;     }     return res;   }   long long get_index(long long standing) {     for (long long i = 0; i < standings.size(); ++i) {       if (standings[i] == standing) return i;     }     std::cerr <<  WTF, INVALID STANDING   << standing << std::endl;     return -1;   }   void CalcJmpMatrix(Matrix& jumpm, long long pos = -1) {     for (long long i = 0; i < standings.size(); ++i) {       long long ss = standings[i];       long long smallest = 1;       while ((ss & smallest) == 0) smallest *= 2;       for (long long j = 0; j < jw.size(); ++j) {         long long ns = ss;         ns &= ~smallest;         if (ns & (smallest << j)) continue;         ns |= smallest << j;         if ((ns & 1) == 0 && ns < (1 << jw.size())) {           auto& x = jumpm.m(i, get_index(ns >> 1));           long long aw = 0;           if (pos >= 0 && j != 0) {             long long pos2 = pos;             long long sm2 = smallest >> 1;             while (sm2) {               ++pos2;               sm2 /= 2;             }             pos2 += j;             if (magic_stones.find(pos2) != magic_stones.end()) {               aw = magic_stones[pos2];             }           }           x = min(x, (long long)jw[j] + aw);         }       }     }   }   vector<long long> mul(const vector<long long>& x, const Matrix& m) {     vector<long long> res(sn, big);     for (long long i = 0; i < sn; ++i) {       for (long long j = 0; j < sn; ++j) {         res[i] = min(res[i], x[j] + m.m(j, i));       }     }     return res;   }   void print_state(long long pos, vector<long long>& res) {}   int main() {     long long x, k, n, q;     scanf( %lld%lld%lld%lld , &x, &k, &n, &q);     jw = vector<long long>(k + 1, 0);     for (long long i = 1; i <= k; ++i) scanf( %lld , &(jw[i]));     for (long long i = 0; i < q; ++i) {       long long p, pw;       scanf( %lld%lld , &p, &pw);       magic_stones[p - 1] = pw;     }     for (long long i = 0; i < (1 << k); ++i) {       if (btc(i) == x) {         standings.push_back(i);       }     }     sn = standings.size();     Matrix jumpm(sn);     CalcJmpMatrix(jumpm);     jumpm.fill_cache();     vector<long long> res(sn, big);     res[0] = 0;     long long cp = 0;     long long des_pos = n - x;     print_state(cp, res);     for (auto ms : magic_stones) {       if (ms.first == cp) continue;       if (ms.first - k > cp) {         res = mul(res, jumpm.get_pow(ms.first - k - cp));         cp = ms.first - k;         print_state(cp, res);       }       for (; cp < ms.first && cp < des_pos;) {         Matrix msm(sn);         CalcJmpMatrix(msm, cp);         res = mul(res, msm);         ++cp;         print_state(cp, res);       }     }     if (cp < des_pos) {       res = mul(res, jumpm.get_pow(des_pos - cp));       cp = des_pos;       print_state(cp, res);     }     print_state(cp, res);     std::cout << res[0] << std::endl;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 20;   const int INF = 1e9;   struct Edge {     int to, next, w;   } e[2 * N];   int n, head[N], M, num;   map<int, int> mp, sp;   long long ans;   void add(int u, int v, int w) {     e[num].next = head[u];     e[num].to = v, e[num].w = w;     head[u] = num++;   }   bool ban[N];   int sz[N], f[N];   int root, siz;   void get_root(int u, int fa) {     sz[u] = 1, f[u] = 0;     for (int i = head[u]; i != -1; i = e[i].next) {       int v = e[i].to;       if (v == fa || ban[v]) continue;       get_root(v, u);       sz[u] += sz[v];       f[u] = max(sz[v], f[u]);     }     f[u] = max(f[u], siz - sz[u]);     if (f[u] < f[root]) root = u;   }   int dis[N], seq[N], tol, pos[N];   long long inv[N], path[N], ten[N], gao[N];   void dfs(int u, int fa) {     pos[u] = tol;     seq[tol++] = u;     sz[u] = 1;     for (int i = head[u]; i != -1; i = e[i].next) {       int v = e[i].to;       if (v == fa || ban[v]) continue;       dis[v] = dis[u] + 1;       path[v] = ((1LL * path[u]) * 10 + e[i].w) % M;       gao[v] = (gao[u] + ten[dis[v] - 1] * e[i].w) % M;       if (gao[v] == 0) ans++;       if (path[v] == 0) ans++;       dfs(v, u);       sz[u] += sz[v];     }   }   void sovle(int u, int ssz) {     root = 0, siz = ssz, f[0] = INF;     get_root(u, 0);     int rt = root;     dis[rt] = 0, path[rt] = 0, tol = 0;     gao[rt] = 0;     long long pre = ans;     dfs(rt, 0);     mp.clear(), sp.clear();     for (int i = head[rt]; i != -1; i = e[i].next) {       int v = e[i].to;       if (ban[v]) continue;       for (int j = pos[v]; j < pos[v] + sz[v]; j++) {         int u = seq[j];         int tmp = ((M - path[u]) * inv[dis[u]]) % M;         ans += mp[tmp] + sp[gao[u]];       }       for (int j = pos[v]; j < pos[v] + sz[v]; j++) {         int u = seq[j];         int tmp = ((M - path[u]) * inv[dis[u]]) % M;         mp[gao[u]]++, sp[tmp]++;       }     }     ban[rt] = true;     for (int i = head[rt]; i != -1; i = e[i].next) {       int v = e[i].to;       if (ban[v]) continue;       sovle(v, sz[v]);     }   }   long long extend_gcd(long long a, long long b, long long &x, long long &y) {     if (b == 0) {       x = 1;       y = 0;       return a;     } else {       long long gcd = extend_gcd(b, a % b, x, y);       long long t = x;       x = y;       y = t - a / b * x;       return gcd;     }   }   void init() {     memset(head, -1, sizeof(head));     memset(ban, 0, sizeof(ban));     num = 0;     inv[0] = 1, ten[0] = 1;     long long x, y;     extend_gcd(10, M, x, y);     x = (x % M + M) % M;     for (int i = 1; i <= n; i++) {       inv[i] = (inv[i - 1] * x) % M;       ten[i] = (ten[i - 1] * 10) % M;     }   }   int main() {     while (scanf( %d%d , &n, &M) != EOF) {       init();       for (int i = 0; i < n - 1; i++) {         int u, v, w;         scanf( %d%d%d , &u, &v, &w);         u++, v++;         add(u, v, w);         add(v, u, w);       }       ans = 0;       sovle(1, n);       printf( %I64d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) {     long long r;     while (b) {       r = a % b;       a = b;       b = r;     }     return a;   }   long long power(long long x, long long y) {     if (y == 0)       return 1;     else if (y % 2 == 0)       return power(x, y / 2) * power(x, y / 2);     else       return x * power(x, y / 2) * power(x, y / 2);   }   long long fpow(long long n, long long k, long long p = 1000000007) {     long long r = 1;     for (; k; k >>= 1) {       if (k & 1) r = r * n % p;       n = n * n % p;     }     return r;   }   long long inv(long long a, long long p = 1000000007) {     return fpow(a, p - 2, p);   }   bool pr[1000007];   void sieve() {     pr[0] = 1;     pr[1] = 1;     for (int i = 2; i < sqrt(1000007); i++) {       for (int j = 2 * i; j <= 1000007; j += i) {         pr[j] = 1;       }     }   }   long long differ(long long a, long long b) {     a = a - 65;     b = b - 65;     long long d = min(abs(a - b), min(a, b) + (25 - max(a, b)) + 1);     return d;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long t, a, b, c;     string q, r, s;     vector<long long> m, p;     cin >> t;     char d;     int arr[4];     arr[0] = (int)( A );     arr[1] = (int)( C );     arr[2] = (int)( T );     arr[3] = (int)( G );     vector<char> v;     a = 1000000007;     long long n = t;     while (n--) {       cin >> d;       v.push_back(d);     }     for (long long i = 0; (i + 3) < t; i++) {       b = 0;       for (int j = int(0); j <= int(3); j++) {         b += differ((int)(arr[j]), (int)v[i + j]);       }       a = min(a, b);     }     cout << a;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cout << fixed;     int a, b, c, d, e, f;     cin >> a >> b >> c >> d >> e >> f;     int cost = 0;     if (e > f) {       int suits = min(a, d);       cost += e * suits;       a -= suits;       d -= suits;       if (d != 0) {         suits = min({b, c, d});         cost += f * suits;       }     } else {       int suits = min({b, c, d});       cost += f * suits;       b -= suits;       c -= suits;       d -= suits;       if (d != 0) {         suits = min(a, d);         cost += e * suits;       }     }     cout << cost <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   char a;   int r, c;   bool side(int x) {     if (x == 1 or x == 8) return true;     return false;   }   int type(int x, int y) {     if (side(x) and side(y)) return 1;     if (side(x) or side(y)) return 2;     return 3;   }   int main() {     scanf(  %c%d , &a, &r);     c = a -  a  + 1;     int ty = type(r, c);     if (ty == 1)       printf( 3 );     else if (ty == 2)       printf( 5 );     else       printf( 8 );     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:251700000 )   using namespace std;   const int INF = 2e9;   const double eps = 1e-6;   const int M = 1e5 + 5;   int n;   string s[M];   bool us[M];   char SS[M];   string get_s() {     scanf(  %s , &SS);     return string(SS);   }   int main() {     scanf( %d , &n);     vector<int> c(27);     vector<int> dd(27, -1);     for (int q = 0; q < n; ++q) {       s[q] = get_s();       for (int i = 0; i < 27; ++i) c[i] = 0;       for (int j = 0; j < s[q].size(); ++j) ++c[s[q][j] -  a ];       for (int i = 0; i < 27; ++i)         if (c[i] > 1) cout <<  NO , exit(0);       for (int i = 0; i < 27; ++i) {         if (dd[i] == -1 || !c[i] || us[dd[i]]) continue;         int l, r, l1, r1;         for (int j = 0; j < s[q].size(); ++j)           if (s[q][j] -  a  == i) l = j;         for (int j = 0; j < s[dd[i]].size(); ++j)           if (s[dd[i]][j] -  a  == i) r = j;         l1 = l, r1 = r;         while (l >= 0 && r >= 0) {           if (s[q][l] != s[dd[i]][r]) cout <<  NO , exit(0);           --l, --r;         }         if (r >= 0) s[q] = s[dd[i]].substr(0, r + 1) + s[q], l1 += r + 1;         l = l1, r = r1;         while (l < s[q].size() && r < s[dd[i]].size()) {           if (s[q][l] != s[dd[i]][r]) cout <<  NO , exit(0);           ++l, ++r;         }         while (r < s[dd[i]].size()) {           s[q] += s[dd[i]][r];           ++r;         }         us[dd[i]] = 1;       }       for (int i = 0; i < 27; ++i) c[i] = 0;       for (int j = 0; j < s[q].size(); ++j)         ++c[s[q][j] -  a ], dd[s[q][j] -  a ] = q;       for (int i = 0; i < 27; ++i)         if (c[i] > 1) cout <<  NO , exit(0);     }     vector<string> ab;     for (int i = 0; i < n; ++i)       if (!us[i]) ab.push_back(s[i]);     sort((ab).begin(), (ab).end());     for (int i = 0; i < ab.size(); ++i) cout << ab[i];   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int c, d, n, m, k, needed;     cin >> c >> d >> n >> m >> k;     needed = n * m - k;     cout << ((needed <= 0)                  ? 0                  : min(needed * d, min(needed / n * c + needed % n * d,                                        (int)(ceil((double)needed / n) * c))));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long MOD = 1e9 + 7;   const int N = 1e5 + 5;   int n;   long long x, y, ans;   bool comp[N];   vector<long long> primes;   long long add(long long a, long long b) { return (a + b) % MOD; }   long long mul(long long a, long long b) { return (a * b) % MOD; }   long long fastexp(long long a, long long b) {     if (b == 0) return 1;     long long x = fastexp(a, b >> 1);     x = mul(x, x);     if (b & 1) x = mul(x, a);     return x;   }   int main() {     scanf( %lld%lld , &x, &y);     if (y % x != 0) {       printf( 0 n );       return 0;     }     y /= x;     comp[1] = 1;     for (int i = 2; i * i <= N; i++) {       if (comp[i]) continue;       for (int j = i * i; j < N; j += i) {         comp[j] = i;       }     }     long long z = y;     for (int i = 2; i < N; i++) {       if (comp[i]) continue;       if (z % i) continue;       while (z % i == 0) {         z /= i;       }       primes.push_back(i);     }     if (z > 1) primes.push_back(z);     z = primes.size();     for (int i = 0; i < (1 << z); i++) {       long long a = 1, b = 0;       for (int j = 0; j < z; j++) {         if ((i >> j) & 1) {           b++;           a *= primes[j];         }       }       a = y / a;       if (b & 1) {         ans = add(ans, MOD - fastexp(2, a - 1));       } else {         ans = add(ans, fastexp(2, a - 1));       }     }     printf( %lld n , ans);   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 300010;   pair<pair<int, int>, pair<int, int> > allNums[MAXN * 2];   set<pair<int, int> > startTimes;   pair<int, int> v[MAXN];   int main() {     int N;     scanf( %d , &N);     for (int i = 0; i < N; ++i) {       scanf( %d%d , &v[i].first, &v[i].second);       int L = v[i].second - v[i].first;       allNums[2 * i] = make_pair(make_pair(v[i].first, 0), make_pair(L, i));       allNums[2 * i + 1] = make_pair(make_pair(v[i].second, 1), make_pair(L, i));     }     sort(allNums, allNums + 2 * N);     for (int i = 0; i < 2 * N; ++i) {       if (allNums[i].first.second == 0) {         startTimes.insert(             make_pair(allNums[i].first.first, allNums[i].second.second));         continue;       }       int idx = allNums[i].second.second;       int st = v[idx].first;       set<pair<int, int> >::iterator it = startTimes.find(make_pair(st, idx));       set<pair<int, int> >::iterator snd = startTimes.begin();       if (it == snd) ++snd;       if (snd != startTimes.end() && snd->first <= it->first) {         printf( %d %d n , idx + 1, snd->second + 1);         return 0;       }       startTimes.erase(it);     }     puts( -1 -1 );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MaxN = 5e5;   const int Inf = 1 << 30;   int mpx[MaxN + 5];   vector<int> s, t[MaxN + 5];   bool cmp(int x, int y) { return x > y; }   int main() {     int n, m, x, u, v, ans, S, p;     while (~scanf( %d %d , &n, &m)) {       ans = 0;       for (int i = 1; i <= n; i++) {         scanf( %d , &x);         mpx[x] = i;         t[i].clear();       }       for (int i = 1; i <= m; i++) {         scanf( %d %d , &u, &v);         t[mpx[u]].push_back(mpx[v]);       }       for (int i = 1; i <= n; i++) sort(t[i].begin(), t[i].end(), cmp);       s.clear();       s.push_back(n);       p = 1;       for (int i = n - 1; i >= 1; i--) {         x = 0;         S = t[i].size();         for (int j = 0; j < S; j++) {           if (s[x] == t[i][j]) {             if (++x == p) {               ans++;               break;             }           } else if (s[x] > t[i][j])             break;         }         if (x != p) {           p++;           s.push_back(i);         }       }       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   int N, K;   int use[8];   int per[8];   int level[8];   int A;   double res;   void dfs(int depth, int st) {     int i, j, sum, all, dame;     double p, ok, tmp;     if (depth == K) {       tmp = 0;       for (i = 0; i < 1 << N; i++) {         p = 1;         sum = all = dame = 0;         for (j = 0; j < N; j++) {           all += 1;           if (i & 1 << j)             sum += 1;           else             dame += level[j];           ok = (per[j] + use[j] * 10) / 100.0;           if (ok > 1) ok = 1;           if (i & 1 << j)             p *= ok;           else             p *= 1 - ok;         }         if (all < 2 * sum)           tmp += p;         else           tmp += p * A / (A + dame);       }       if (res < tmp) res = tmp;       return;     }     for (i = st; i < N; i++) {       use[i]++;       dfs(depth + 1, i);       use[i]--;     }   }   int main() {     int i, j, l, m;     int sum;     while (scanf( %d%d%d , &N, &K, &A) == 3) {       for (i = 0; i < N; i++) scanf( %d%d , level + i, per + i);       res = 0;       dfs(0, 0);       printf( %.10lf n , res);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void jizz() {     cout << -1 << endl;     exit(0);   }   int s[200005], l[200005], r[200005];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     for (int i = 1; i <= n; ++i) {       cin >> s[i] >> l[i];       r[i] = s[i] + l[i];       l[i] = s[i];     }     int nl = -9, nr = 3000006;     for (int i = 1; i <= n; ++i) {       --nl, ++nr;       nl = l[i] = max(l[i], nl);       nr = r[i] = min(r[i], nr);       if (l[i] > r[i]) jizz();     }     nl = -9, nr = 3000006;     for (int i = n; i >= 1; --i) {       --nl, ++nr;       nl = l[i] = max(l[i], nl);       nr = r[i] = min(r[i], nr);       if (l[i] > r[i]) jizz();     }     long long tot = 0;     for (int i = 1; i <= n; ++i) {       tot += r[i] - s[i];     }     cout << tot << endl;     for (int i = 1; i <= n; ++i) cout << r[i] <<    ;     cout << endl;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ld = long double;   template <class T, class U>   void mod_partial_sum(const T& v, U* out, ll mod) {     auto it = begin(v);     ll val = 0;     for (auto& x : *out) x = (val += *(it++)) %= mod;   }   int main() {     cout << fixed << setprecision(10);     int a, b;     int rest;     cin >> a >> b;     if (a > b) {       cout << b;       rest = a - b;     } else {       cout << a;       rest = b - a;     }     cout <<    ;     cout << rest / 2 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 110;   int a, b, c, ar[maxn], al[maxn];   bool gg = false;   int main() {     cin >> a >> b >> c;     for (int i = 0; i < b; i++) cin >> ar[i];     for (int j = 0; j < c; j++) cin >> al[j];     for (int i = 1; i <= a; i++) {       for (int j = 0; j < b; j++) {         if (ar[j] == i) gg = true;       }       gg ? cout << 1 <<     : cout << 2 <<    ;       gg = false;     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main(void) {     long double a, b, c, p, q, r;     cin >> a >> b >> c;     p = b * b - 4 * a * c;     if (a == 0 && b == 0 && c == 0)       cout << -1 << endl;     else if (a == 0 && b == 0 && c != 0)       cout << 0 << endl;     else if (p < 0)       cout << 0 << endl;     else if (a == 0) {       q = -c / b;       cout << 1 << endl;       cout << fixed << setprecision(6) << q;     } else if (p == 0) {       q = -b / (2 * a);       cout << 1 << endl;       cout << fixed << setprecision(6) << q;     } else {       q = (-b - sqrt(p)) / (2 * a);       r = (-b + sqrt(p)) / (2 * a);       if (q < r) {         cout << 2 <<   n  << fixed << setprecision(6) << q << endl;         cout << fixed << setprecision(6) << r << endl;       } else {         cout << 2 <<   n  << fixed << setprecision(6) << r << endl;         cout << fixed << setprecision(6) << q << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   int main() {     long long int t, i = 0;     long long ans = 0;     scanf( %lld , &t);     for (i = 0; i < t; i++) {       long long int n;       scanf( %lld , &n);       ans = ans + i * (n - 1) + n;     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int x, k, ans = 0;     cin >> x >> k;     while (x--) {       int a, b;       cin >> a >> b;       ans += abs(a - b) + 1;     }     int ans2 = 0;     while (true) {       if (ans % k == 0) {         cout << ans2;         break;       } else {         ans2++;         ans++;       }     }   }


#include <bits/stdc++.h>   #pragma GCC optimize  03    using namespace std;   const long long int inf = 1e15;   const long long int MOD = 1e9 + 7;   const long long int N = 2e5 + 5;   struct SegTree {     struct data {       long long int val;       data() : val(0){};       template <typename T>       void apply(T v) {         val = v;       }     };     long long int N;     vector<data> st;     SegTree() {}     SegTree(long long int _N) : N(_N) { st.resize(4 * N + 5); }     inline void merge(data &cur, const data &l, const data &r,                       long long int flag) {       if (flag == 1)         cur.val = l.val | r.val;       else         cur.val = l.val ^ r.val;     }     template <typename T>     long long int build(long long int node, long long int l, long long int r,                         vector<T> &v) {       if (l == r) {         if (l < (long long int)v.size())           st[node].apply(v[l]);         else           st[node].apply(0);         return 1;       }       long long int mid = (l + r) / 2;       long long int f = build(node * 2, l, mid, v);       build(node * 2 + 1, mid + 1, r, v);       merge(st[node], st[node * 2], st[node * 2 + 1], f);       return !f;     }     long long int pupdate(long long int node, long long int l, long long int r,                           long long int pos, long long int val) {       if (l == r) {         st[node].val = val;         return 1;       }       long long int mid = (l + r) / 2;       long long int f;       if (pos <= mid)         f = pupdate(node * 2, l, mid, pos, val);       else         f = pupdate(node * 2 + 1, mid + 1, r, pos, val);       merge(st[node], st[node * 2], st[node * 2 + 1], f);       return !f;     }     template <typename T>     void build(vector<T> &v) {       build(1, 1, N, v);     }     void update(long long int pos, long long int val) {       pupdate(1, 1, N, pos, val);     }   };   signed main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     ;     long long int n, q;     cin >> n >> q;     vector<long long int> v((1 << n) + 1);     for (long long int i = 1; i <= (1 << n); i++) {       cin >> v[i];     }     SegTree st(1 << 17);     st.build(v);     ;     while (q--) {       long long int a, b;       cin >> a >> b;       st.update(a, b);       cout << st.st[1].val <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, l;     cin >> n >> l;     deque<int> v;     while (n--) {       int m;       cin >> m;       v.push_back(m);     }     sort(v.begin(), v.end());     int a = v[0];     int b = v[v.size() - 1];     v.push_front(a * (-1));     v.push_back(2 * l - b);     int maxi = 0;     for (int i = 1; i < v.size(); i++) {       maxi = max(maxi, v[i] - v[i - 1]);     }     float maxi2 = maxi;     cout << fixed << setprecision(10) << maxi2 / 2;   }


#include <bits/stdc++.h>   using namespace std;   int n = 8;   struct point {     int x;     int y;   };   bool f(point a, point b) {     if (a.x != b.x) return a.x > b.x;     return a.y > b.y;   }   int main() {     point a[8];     for (int i = 0; i < n; i++) cin >> a[i].x >> a[i].y;     int t1 = 0, t2 = 0;     for (int i = 0; i < n; i += 2) {       if (a[i].x == a[i + 1].x) {         t1++;       } else if (a[i].y == a[i + 1].y)         t2++;       else {         cout <<  NO  << endl;         return 0;       }     }     if (t1 != 2 || t2 != 2) {       cout <<  NO  << endl;       return 0;     }     int t = 0;     sort(a, a + n, f);     if (a[1].x == a[2].x && a[1].y == a[2].y ||         a[3].x == a[4].x && a[3].y == a[4].y ||         a[5].x == a[6].x && a[5].y == a[6].y) {       cout <<  NO  << endl;       return 0;     }     for (int i = 0; i < n; i += 2) {       if (a[i].x == a[i + 1].x && a[i].y == a[i + 1].y)         t++;       else {         cout <<  NO  << endl;         return 0;       }     }     if (t == 4)       cout <<  YES  << endl;     else       cout <<  NO  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long md = 1e9 + 7;   long long fe(long long e) {     if (e == 0) return 1;     long long ans = fe(e / 2);     ans = (ans * ans) % md;     if (e % 2) ans *= 2;     return (ans % md);   }   int main() {     long long x, y;     cin >> x >> y;     if (y % x) {       cout << 0 << endl;       return 0;     }     long long k = y / x;     vector<int> pp;     long long kk = k;     for (long long p = 2; p < 1e5; p++) {       if (kk % p == 0) {         pp.push_back(p);         while (kk % p == 0) kk /= p;       }     }     if (kk > 1) pp.push_back(kk);     long long ans = fe(k - 1);     int mx = 1 << (int)pp.size();     for (int i = 1; i < mx; i++) {       long long p = 1, sgn = 1;       for (int j = 0; 1 << j <= i; j++) {         if (1 << j & i) {           p *= pp[j];           sgn *= -1;         }       }       ans += sgn * fe(k / p - 1);       ans %= md;       while (ans < 0) ans += md;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   signed main() {     std::ios::sync_with_stdio(false);     string str;     cin >> str;     long long int n = str.size();     string prf =   ;     vector<long long int> v(n, 0);     for (long long int i = 0; i < n - 1; i++)       if (str[i] != str[i + 1]) v[i] = 1;     if (str[n - 1] ==  a ) v[n - 1] = 1;     for (long long int i = 0; i < n; i++) cout << v[i] <<    ;   }


#include <bits/stdc++.h>   using namespace std;   long long u[11];   int main() {     long long x, y, n, i, j, k = 0, l, arr[200009];     cin >> n;     for (i = 0; i < n; i++) {       cin >> arr[i];     }     sort(arr, arr + n);     for (i = 0, j = 1; i < n; i++) {       if (arr[i] >= j) {         k++;         j++;       }     }     cout << k << endl;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:64000000 )   using namespace std;   const int inf32 = 1e9 + 9;   const long long inf64 = 1e18 + 18;   const int N = 6e5 + 5;   const long long mod = 1e9 + 7;   map<int, int> mp;   vector<int> primes = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31};   int n, mx;   void go(int &f, int a, int b, int mn) {     if (a * b > mx) {       if (a % b) return;       mp[a] += mn;       f -= mn;       return;     }     go(f, a * b, b, (mn + 1) / 2);     if (a % b) return;     int t = min(f, mn);     mp[a] += t;     f -= t;   }   bool show() {     int rez = 0;     for (auto &x : mp) rez += x.second;     return rez == n;   }   bool check(int j) {     mp.clear();     mp[1] = n;     int half = (n + 1) / 2;     half += n / 100;     for (int i = 0; i < j; ++i) {       int x = primes[i];       int cnt = 0;       bool flag = true;       while (flag) {         flag = false;         for (auto &y : mp) {           if (!y.second || !(y.first % x)) continue;           int t = cnt;           cnt += y.second;           go(y.second, y.first, x, (y.second + 1) / 2);           cnt -= y.second;           flag |= t != cnt;           if (cnt >= half) break;         }         if (cnt >= (n + 1) / 2) break;       }       if (!flag) {         for (auto &y : mp) {           if (y.second > 1 && y.first * x < mx) {             mp[y.first * x] += 1;             --y.second;             ++cnt;           }           if (cnt >= (n + 1) / 2) break;         }         if (cnt < (n + 1) / 2) return false;       }     }     for (auto &y : mp) {       if (y.second > 1) {         for (int i = 0; i < j; ++i) {           int x = primes[i];           for (int i = x; y.second && i * y.first < mx; i *= x) {             if (!mp[y.first * i]) {               mp[y.first * i] = 1;               --y.second;             }           }         }       }     }     if (n > 1000) {       queue<int> lil;       for (int i = 0; i < j; ++i) {         for (int k = i + 1; k < j; ++k) {           int x = primes[i], y = primes[k];           if (!mp[x * y]) lil.push(x * y);           if (!mp[x]) lil.push(x);           if (!mp[y]) lil.push(y);           if (!mp[y * y]) lil.push(y * y);           if (!mp[x * x]) lil.push(x * x);           if (!mp[x * x * y]) lil.push(x * x * y);           if (!mp[x * y * y]) lil.push(x * y * y);           if (!mp[x * x * y * y]) lil.push(x * x * y * y);         }       }       for (auto &x : mp) {         while (x.second > 1) {           while (!lil.empty() && mp[lil.front()]) lil.pop();           if (lil.empty()) return false;           --x.second;           mp[lil.front()] = 1;           lil.pop();         }       }     }     for (auto &x : mp) {       if (x.second > 1) return false;     }     return true;   }   void solve() {     cin >> n;     mx = 2 * n * n;     for (int j = 1; !check(j); ++j)       ;     int cnt = 0;     for (auto &x : mp) {       if (x.second) cout << x.first <<    ;     }   }   int main() {     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   static const int INF = 500000000;   template <class T>   void debug(T a, T b) {     for (; a != b; ++a) cerr << *a <<    ;     cerr << endl;   }   int n, len;   char s[1000005];   int var[1000005][4];   int cnt, ind;   int parse() {     if (s[ind] ==  0 ) var[cnt][0] = 1;     if (s[ind] ==  1 ) var[cnt][3] = 1;     if (s[ind] ==  ? ) var[cnt][1] = var[cnt][2] = 1;     ++cnt;     int v = cnt - 1;     if (s[ind] ==  ( ) {       ++ind;       int p = parse(), p2;       char ope = s[ind];       ++ind;       p2 = parse();       for (int i = 0; i < 4; ++i)         if (var[p][i])           for (int j = 0; j < 4; ++j)             if (var[p2][j]) {               int x1 = i & 1, x2 = i >> 1 & 1, y1 = j & 1, y2 = j >> 1 & 1;               int bit;               if (ope ==  & ) bit = (x1 & y1) + (x2 & y2) * 2;               if (ope ==  | ) bit = (x1 | y1) + (x2 | y2) * 2;               if (ope ==  ^ ) bit = (x1 ^ y1) + (x2 ^ y2) * 2;               var[v][bit] = 1;             }     }     ++ind;     return v;   }   int main() {     scanf( %d%s , &n, s);     len = strlen(s);     int root = parse();     if (var[0][2] || var[0][1])       puts( YES );     else       puts( NO );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, t, d, k;     cin >> n >> t >> k >> d;     int a;     a = (d + t) / t;     if (a * k < n) cout <<  YES ;     if (a * k >= n) cout <<  NO ;   }


#include <bits/stdc++.h>   using namespace std;   int fact[100005];   void criba() {     for (int i = 2; i * i < 100005; i++)       if (fact[i] == 0)         for (int j = i * i; j < 100005; j += i) fact[j] = i;     for (int i = 2; i < 100005; i++)       if (fact[i] == 0) fact[i] = i;   }   bool vis[100005];   set<pair<int, int> > S;   int process(int n, int id) {     int m = n;     set<pair<int, int> >::iterator it;     while (n > 1) {       int f = fact[n];       while (n % f == 0) n /= f;       if (id == 2) {         it = S.lower_bound(make_pair(f, -1));         if (it != S.end() && (*it).first == f) return (*it).second;       } else {         if (id == 0)           S.erase(make_pair(f, m));         else           S.insert(make_pair(f, m));       }     }     return -1;   }   int main() {     criba();     int n, m;     while (cin >> n >> m) {       char op[2];       int x;       for (int i = 0; i < m; i++) {         scanf( %s%d , op, &x);         if (op[0] ==  - ) {           if (vis[x])             process(x, 0), puts( Success ), vis[x] = false;           else             puts( Already off );         } else {           if (vis[x])             puts( Already on );           else {             int num = process(x, 2);             if (num == -1)               puts( Success ), process(x, 1), vis[x] = true;             else               printf( Conflict with %d n , num);           }         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   ifstream in( pairs.in );   ofstream out( pairs.out );   const int DIM = 1e5 + 5;   int nxt[DIM], val[DIM], pos[DIM];   pair<int, int> tdp[DIM][2], cdp[DIM], arr[2][DIM];   deque<int> chn;   bitset<DIM> oki, mrk, ist;   vector<pair<int, int>> sol;   vector<int> edg[DIM];   pair<int, int> operator+(const pair<int, int> &p1, const pair<int, int> &p2) {     return pair<int, int>(p1.first + p2.first, p1.second + p2.second);   }   pair<int, int> operator-(const pair<int, int> &p1, const pair<int, int> &p2) {     return pair<int, int>(p1.first - p2.first, p1.second - p2.second);   }   void calcdp(int x) {     mrk[x] = true;     pos[x] = 0;     tdp[x][0] = tdp[x][1] = pair<int, int>(0, 0);     for (int y : edg[x]) {       calcdp(y);       tdp[x][0] = tdp[x][0] + max(tdp[y][0], tdp[y][1]);       pair<int, int> aux = tdp[y][0] - max(tdp[y][0], tdp[y][1]) +                            pair<int, int>(1, val[x] != val[y]);       if (tdp[x][1] < aux) tdp[x][1] = aux, pos[x] = y;     }     tdp[x][1] = tdp[x][1] + tdp[x][0];   }   int _nr[2];   void solvedp(int x, bool ok, int nr) {     if (ok and pos[x]) arr[nr][++_nr[nr]] = make_pair(x, pos[x]);     for (int y : edg[x]) solvedp(y, (ok and y == pos[x]) ? false : true, nr);   }   int main(void) {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; ++i) {       scanf( %d %d , &nxt[i], &val[i]);       edg[nxt[i]].push_back(i);     }     pair<int, int> ans;     for (int i = 1; i <= n; ++i)       if (!mrk[i]) {         chn.clear();         for (int x = i; true; x = nxt[x]) {           chn.push_back(x);           if (!oki[x])             oki[x] = true;           else {             while (chn.front() != chn.back())               oki[chn.front()] = false, chn.pop_front();             break;           }         }         pair<int, int> pr1, pr2;         edg[chn[1]].erase(find(edg[chn[1]].begin(), edg[chn[1]].end(), chn[0]));         calcdp(chn[0]);         _nr[0] = 0;         solvedp(chn[0], true, 0);         edg[chn[1]].push_back(chn[0]);         pr1 = max(tdp[chn[0]][0], tdp[chn[0]][1]);         edg[chn[2]].erase(find(edg[chn[2]].begin(), edg[chn[2]].end(), chn[1]));         calcdp(chn[1]);         _nr[1] = 0;         solvedp(chn[1], true, 1);         edg[chn[2]].push_back(chn[1]);         pr2 = max(tdp[chn[1]][0], tdp[chn[1]][1]);         if (pr1 > pr2) {           ans = ans + pr1;           for (int i = 1; i <= pr1.first; ++i) sol.push_back(arr[0][i]);         } else {           ans = ans + pr2;           for (int i = 1; i <= pr2.first; ++i) sol.push_back(arr[1][i]);         }       }     printf( %d %d n , ans.first, ans.second);     for (pair<int, int> pr : sol) printf( %d %d n , pr.first, pr.second);     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   const int N = 1e6 + 7;   const int INF = 1e9 + 7;   int n, m;   int mid = 0;   int ile[70];   long long mnoz = 1;   long long ans = 0;   bitset<128> maska;   void backtrack(int poz = 1) {     ans += mnoz;     if (poz > mid) return;     for (int i = poz; i <= mid; i++) {       if (!ile[i]) continue;       bitset<128> old_mask = maska;       bitset<128> pom = (maska >> i) | (maska << (m - i));       if ((pom & maska).count() == 0) {         int old_mnoz = mnoz;         maska = maska | pom;         mnoz = mnoz * ile[i];         if (mnoz > INF) mnoz %= INF;         backtrack(i + 1);         maska = old_mask;         mnoz = old_mnoz;       }     }   }   void solve() {     cin >> m >> m >> n;     mid = (m + 1) / 2;     for (int i = 0; i < n; i++) {       int temp;       cin >> temp;       temp = temp % m;       temp = min(temp, m - temp);       ile[temp]++;     }     maska[0] = 1;     backtrack();     cout << ans % INF <<   n ;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int t = 1;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   vector<pair<int, bool> > v[300100];   set<pair<int, int> > Bridges;   vector<pair<pair<int, int>, int> > All;   bool vis[300100], F = 0;   int cnt = 0, num[300100], low[300100], Size[300100], par[300100], a, b;   bool Ok[300100];   void init() {     for (int i = 1; i <= n; i++) par[i] = i, Size[i] = 1;   }   int getparent(int x) {     if (x == par[x]) return x;     return par[x] = getparent(par[x]);   }   void Merge(int x, int y) {     x = getparent(x);     y = getparent(y);     if (Size[x] < Size[y]) swap(x, y);     Size[x] += Size[y];     par[y] = x;   }   void BridgeDFS(int u) {     num[u] = low[u] = cnt++;     for (int i = 0; i < v[u].size(); i++) {       int nxt = v[u][i].first;       if (num[nxt] == -1) {         par[nxt] = u;         BridgeDFS(nxt);         if (num[u] < low[nxt]) Bridges.insert({u, nxt}), Bridges.insert({nxt, u});         low[u] = min(low[u], low[nxt]);       } else if (par[u] != nxt)         low[u] = min(low[u], num[nxt]);     }   }   void DFS(int x, bool f) {     vis[x] = true;     if (x == getparent(b)) F = f;     for (int i = 0; i < v[x].size(); i++) {       int y = getparent(v[x][i].first);       if (!vis[y]) {         DFS(y, f || Ok[y] || v[x][i].second);       }     }   }   int main() {     memset(num, -1, sizeof(num));     memset(par, -1, sizeof(par));     int x, y, w;     cin >> n >> m;     while (m--) {       scanf( %d%d%d , &x, &y, &w);       v[x].push_back({y, w});       v[y].push_back({x, w});       All.push_back({{x, y}, w});     }     cin >> a >> b;     BridgeDFS(1);     init();     for (auto it : All) {       if (Bridges.find(it.first) == Bridges.end()) {         int val = max(it.second, max((int)Ok[getparent(it.first.first)],                                      (int)Ok[getparent(it.first.second)]));         Merge(it.first.first, it.first.second);         Ok[getparent(it.first.first)] =             max((int)Ok[getparent(it.first.first)], val);       }     }     for (auto it : All) {       int x = getparent(it.first.first);       int y = getparent(it.first.second);       if (x != y) {         v[x].push_back({y, it.second});         v[y].push_back({x, it.second});       }     }     if (getparent(a) == getparent(b)) {       int u = getparent(a);       if (Ok[u])         return cout <<  YES , 0;       else         return cout <<  NO , 0;     }     DFS(getparent(a), Ok[getparent(a)]);     if (F)       return cout <<  YES , 0;     else       return cout <<  NO , 0;     return 0;   }