#include <bits/stdc++.h>   using namespace std;   int now, ot, mi, last, cnt, le, d[10010], st[10010][15], len[10010], ans[10010],       trs[10010][26], fa[10010], tot[10010], lev[10010];   char s[10010];   inline int ext(int x) {     for (now = last; s[le - len[now]] ^ x; now = fa[now])       ;     if (trs[now][x]) return last = trs[now][x];     for (ot = fa[now]; s[le - len[ot]] ^ x; ot = fa[ot])       ;     ++d[fa[++cnt] = trs[ot][x]];     len[trs[now][x] = cnt] = len[now] + 2;     return last = cnt;   }   inline void topo() {     int dl[10010], l = 0, r = 0;     for (int i = 0; i <= cnt; ++i)       if (!d[i]) dl[++r] = i;     while (l < r) {       int v = fa[dl[++l]];       tot[v] += tot[dl[l]];       if (!--d[v]) dl[++r] = v;     }   }   int main() {     len[last = cnt = 1] = -1;     fa[1] = fa[0] = 1;     for (s[le + 1] = getchar(); s[le + 1] !=   n ; s[++le + 1] = getchar()) {       ext(s[le + 1] -=  a  - 1);       ++tot[last];       if (!lev[last]) {         st[last][0] = fa[last];         for (int i = 1; i <= 13; ++i) st[st[last][i - 1]][i - 1];         if (len[last] == 1)           lev[last] = 1;         else {           for (mi = 13, now = last; mi >= 0;) {             while (mi >= 0 && len[st[now][mi]] < len[last] >> 1) --mi;             if (mi >= 0) now = st[now][mi];           }           if (len[now] == len[last] >> 1)             lev[last] = lev[now] + 1;           else             lev[last] = 1;         }       }     }     topo();     for (int i = 2; i <= cnt; ++i) ans[lev[i]] += tot[i];     for (int i = le; i; --i) ans[i - 1] += ans[i];     for (int i = 1; i <= le; ++i) printf( %d  , ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       long n;       cin >> n;       long count1 = 0, count2 = 0;       int f = 0;       while (n != 1) {         if (n % 3 == 0) {           n = n / 3;           count1++;         }         if (n % 2 == 0) {           n = n / 2;           count2++;         }         if (n % 3 != 0 and n % 2 != 0 and n != 1) {           f = 1;           break;         }       }       if (f == 1)         cout <<  -1  << endl;       else if (count1 >= count2 and f == 0) {         long ans = count1 - count2;         if (count1 - count2 != 0)           ans += count1;         else           ans = count1;         cout << ans << endl;       } else         cout <<  -1  << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100000 + 10;   struct Edge {     int v;     bool used;     Edge(int v, int used) : v(v), used(used) {}   };   vector<int> adj[MAXN], odd, ans;   vector<Edge> edges;   int p, n, m, deg[MAXN];   int cur[MAXN];   void dfs(int u) {     for (auto &idx = cur[u]; idx < adj[u].size(); ++idx) {       if (!edges[adj[u][idx]].used) {         edges[adj[u][idx]].used = 1;         edges[adj[u][idx] ^ 1].used = 1;         dfs(edges[adj[u][idx]].v);       }     }     ans.push_back(u);   }   int main() {     cin >> n >> m;     for (int i = 0; i < m; ++i) {       int u, v;       cin >> u >> v;       ++deg[u], ++deg[v];       edges.emplace_back(v, 0);       edges.emplace_back(u, 0);       int sz = edges.size();       adj[u].push_back(sz - 2);       adj[v].push_back(sz - 1);     }     for (int i = (1); i < (n + 1); ++i)       if (deg[i] & 1) {         odd.push_back(i);       }     for (int i = 0; i < (int)odd.size(); i += 2) {       int u = odd[i], v = odd[i + 1];       edges.emplace_back(v, 0);       edges.emplace_back(u, 0);       int sz = edges.size();       adj[u].push_back(sz - 2);       adj[v].push_back(sz - 1);     }     p = m + (odd.size() / 2);     dfs(1);     if (ans.size() % 2 == 0) {       ++p;       ans.push_back(1);     }     cout << p <<   n ;     for (int i = 1; i < (int)ans.size(); ++i) {       int u = ans[i - 1], v = ans[i];       if (!(i & 1)) {         swap(u, v);       }       cout << u <<     << v <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long double PI = acos(-1.0);   const long double eps = 1e-6;   const int maxw = 1e6 + 10;   const int maxn = 5e2 + 10;   int n, m, K;   char s[maxn][maxn];   vector<int> res[maxn];   int num[maxn][maxn], dp[maxn][maxn];   void solve() {     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         if (s[i][j] ==  1 ) {           res[i].push_back(j);         }       }     }     int ret, tmp;     for (int i = 1; i <= n; i++) {       if (res[i].empty()) {         for (int j = 0; j <= K; j++) {           num[i][j] = 0;         }         continue;       }       for (int j = 0; j <= m; j++) {         num[i][j] = maxw;       }       for (int j = 0; j < (int)res[i].size(); j++) {         for (int k = j; k < (int)res[i].size(); k++) {           ret = (int)res[i].size() - (k - j + 1);           num[i][ret] = min(num[i][ret], res[i][k] - res[i][j] + 1);         }       }       num[i][(int)res[i].size()] = 0;     }     for (int i = 0; i <= n; i++) {       for (int j = 0; j <= K; j++) {         dp[i][j] = maxw;       }     }     memset(dp[0], 0, sizeof(dp[0]));     for (int i = 1; i <= n; i++) {       for (int j = K; j >= 0; j--) {         for (int k = 0; k <= j; k++) {           dp[i][j] = min(dp[i][j], dp[i - 1][j - k] + num[i][k]);         }       }     }     printf( %d n , dp[n][K]);   }   int main(void) {     scanf( %d %d %d , &n, &m, &K);     for (int i = 1; i <= n; i++) {       scanf( %s , s[i] + 1);     }     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long t, x, y, n;   int main() {     cin.tie(NULL);     ios::sync_with_stdio(false);     cin >> t;     while (t--) {       cin >> n >> x >> y;       vector<int> ans;       int number = y - x;       for (int i = 1; i <= number; i++) {         if (number % i) continue;         if (number / i + 1 > n) continue;         number = i;         break;       }       for (int i = y; i >= 1 && ans.size() < n; i -= number) ans.push_back(i);       for (int i = y + number; i <= (int)1e9 && ans.size() < n; i += number)         ans.push_back(i);       for (auto here : ans) cout << here <<    ;       cout <<   n ;     }   }


#include <bits/stdc++.h>   const int dx[4] = {1, 0, -1, 0};   const int dy[4] = {0, -1, 0, 1};   using namespace std;   char str[5001];   class Point {    public:     int Left;     int Right;     int Up;     int Down;   };   Point f1[5001], f2[5001];   int ans1, ans2, n, m;   int dfs(int p, int tot) {     int tmp;     if (str[p] ==  D )       tmp = f2[p].Down;     else if (str[p] ==  U )       tmp = f2[p].Up;     else if (str[p] ==  L )       tmp = f2[p].Left;     else       tmp = f2[p].Right;     if (f2[p].Left != -1) f2[f2[p].Left].Right = f2[p].Right;     if (f2[p].Right != -1) f2[f2[p].Right].Left = f2[p].Left;     if (f2[p].Up != -1) f2[f2[p].Up].Down = f2[p].Down;     if (f2[p].Down != -1) f2[f2[p].Down].Up = f2[p].Up;     if (ans1 == tot) ans2++;     if (ans1 < tot) {       ans1 = tot;       ans2 = 1;     }     if (tmp != -1) dfs(tmp, tot + 1);     return 0;   }   int work() {     scanf( %d%d , &n, &m);     getchar();     for (int i = 0; i < n; ++i) {       for (int j = 0; j < m; ++j) str[i * m + j] = getchar();       getchar();     }     memset(f1, -1, sizeof(f1));     memset(f2, -1, sizeof(f2));     int k;     for (int i = 0; i < n; ++i)       for (int j = 0; j < m; ++j) {         int p = i * m + j;         if (str[p] ==  . ) continue;         {           k = i + 1;           while (str[k * m + j] ==  .  && k < n) k++;           if (k < n) {             f1[p].Down = k * m + j;             f1[k * m + j].Up = p;           }         }         {           k = i - 1;           while (str[k * m + j] ==  .  && k >= 0) k--;           if (k >= 0) {             f1[p].Up = k * m + j;             f1[k * m + j].Down = p;           }         }         {           k = j - 1;           while (str[i * m + k] ==  .  && k >= 0) k--;           if (k >= 0) {             f1[p].Left = i * m + k;             f1[i * m + k].Right = p;           }         }         {           k = j + 1;           while (str[i * m + k] ==  .  && k < m) k++;           if (k < m) {             f1[p].Right = i * m + k;             f1[i * m + k].Left = p;           }         }       }     ans1 = ans2 = 0;     for (int i = 0; i < n; ++i)       for (int j = 0; j < m; ++j)         if (str[i * m + j] !=  . ) {           for (int k = 0; k < 5001; ++k) f2[k] = f1[k];           dfs(i * m + j, 1);         }     printf( %d %d n , ans1, ans2);     return 0;   }   int main() {     work();     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   int a[3003];   double f[3003 * 3003];   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i < n + 1; i++) scanf( %d , &a[i]);     int cnt = 0;     for (int i = 1; i < n + 1; i++) {       for (int j = i + 1; j < n + 1; j++) {         if (a[i] > a[j]) cnt++;       }     }     f[0] = 0;     f[1] = 1;     for (int i = 2; i < cnt + 1; i++) f[i] = f[i - 2] + 4;     printf( %.6f , f[cnt]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   class DSU {    public:     vector<int> parent;     int total_components;     DSU(int n) {       parent.resize(n + 1);       for (int i = 1; i <= n; i++) {         parent[i] = i;       }       total_components = n;     }     int get(int x) {       if (parent[x] == x) {         return x;       }       return parent[x] = get(parent[x]);     }     bool unite(int x, int y) {       int p1 = get(x);       int p2 = get(y);       if (p1 == p2) {         return true;       }       parent[p1] = p2;       total_components--;       return false;     }   };   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int n, m;     cin >> n >> m;     bool cycle = false;     DSU g(n);     while (m--) {       int u, v;       cin >> u >> v;       if (g.unite(u, v)) {         cycle = true;       }     }     if (cycle || g.total_components > 1) {       cout <<  no  << endl;     } else {       cout <<  yes  << endl;     }     cout.flush();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1.0);   const int N = 10003;   const long long oo = 1e18;   int get(int x, int l, int r) {     if (x <= l) return l - x;     if (r <= x) return x - r;     return 0;   }   int l[N], r[N], zn[N];   long long d1[N], d2[N];   vector<int> st;   map<int, int> mp;   int main() {     if (0) {       freopen( input.txt ,  w , stdout);       return 0;     }     int i, u, n, m, x, li, ri, xp;     long long tt, ans;     scanf( %d%d , &n, &x);     st.push_back(x);     for (i = 0; i < n; ++i) {       scanf( %d%d , &li, &ri);       l[i] = li;       r[i] = ri;       st.push_back(li);       st.push_back(ri);     }     sort(st.begin(), st.end());     m = 0;     for (i = 0; i < st.size(); ++i)       if ((i + 1 == st.size()) || (st[i] != st[i + 1])) {         zn[m] = st[i];         mp[st[i]] = m++;       }     xp = mp[x];     for (i = 0; i < m; ++i) d1[i] = oo;     d1[xp] = 0;     for (u = 0; u < n; ++u) {       for (i = 0; i < m; ++i) d2[i] = oo;       li = l[u];       ri = r[u];       tt = oo;       for (i = 0; i < m; ++i) {         if (i) tt += zn[i] - zn[i - 1];         tt = min(tt, d1[i]);         if (tt >= oo) {           tt = oo;           continue;         }         d2[i] = min(d2[i], tt + get(zn[i], li, ri));       }       tt = oo;       for (i = m - 1; i >= 0; --i) {         if (i != m - 1) tt += zn[i + 1] - zn[i];         tt = min(tt, d1[i]);         if (tt >= oo) {           tt = oo;           continue;         }         d2[i] = min(d2[i], tt + get(zn[i], li, ri));       }       for (i = 0; i < m; ++i) d1[i] = d2[i];     }     ans = oo;     for (i = 0; i < m; ++i) ans = min(ans, d1[i]);     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int pows[51];   vector<int> base_3(long long int n) {     vector<int> f(51);     int r = 0;     while (n > 0) {       f[r++] = (int)n % 3;       n /= 3;     }     return f;   }   int main() {     int q;     cin >> q;     pows[1] = 3;     pows[0] = 1;     for (int i = 1; i <= 50; i++) {       pows[i] = pows[i - 1] * 3;     }     while (q--) {       long long int n;       cin >> n;       vector<int> v = base_3(n);       int ind = -1;       for (int j = 50; j >= 0; j--) {         if (v[j] == 2 && ind == -1) {           ind = j;         }       }       if (ind == -1) {         cout << n <<   n ;       } else {         int r = ind + 1;         while (r < 50 && v[r] == 1) {           r++;         }         v[r] = 1;         for (int i = 0; i < r; i++) {           v[i] = 0;         }         long long int ans = 0;         for (int j = 0; j < 51; j++) {           ans += v[j] * pows[j];         }         cout << ans <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int qq = 3e5 + 10;   vector<int> G[qq];   multiset<int, greater<int> > myset;   int num[qq];   void Del(int x) {     auto t = myset.find(x);     myset.erase(t);   }   int main() {     int ans = 2e9 + 10;     int n;     scanf( %d , &n);     int a, b;     for (int i = 1; i <= n; ++i) {       scanf( %d , num + i);       myset.insert(num[i]);     }     for (int i = 1; i <= n - 1; ++i) {       scanf( %d%d , &a, &b);       G[a].push_back(b), G[b].push_back(a);     }     for (int i = 1; i <= n; ++i) {       Del(num[i]);       int ma = num[i];       for (int y : G[i]) {         Del(num[y]);         ma = max(ma, num[y] + 1);       }       if (!myset.empty()) {         ma = max(ma, *myset.begin() + 2);       }       for (int y : G[i]) {         myset.insert(num[y]);       }       myset.insert(num[i]);       ans = min(ans, ma);     }     printf( %d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   void debug_out() { cerr << endl; }   template <class T>   ostream& prnt(ostream& out, T v) {     out << v.size() <<   n ;     for (auto e : v) out << e <<    ;     return out;   }   template <class T>   ostream& operator<<(ostream& out, vector<T> v) {     return prnt(out, v);   }   template <class T>   ostream& operator<<(ostream& out, set<T> v) {     return prnt(out, v);   }   template <class T1, class T2>   ostream& operator<<(ostream& out, map<T1, T2> v) {     return prnt(out, v);   }   template <class T1, class T2>   ostream& operator<<(ostream& out, pair<T1, T2> p) {     return out <<  (  << p.first <<     << p.second <<  ) ;   }   template <typename Head, typename... Tail>   void debug_out(Head H, Tail... T) {     cerr <<     << H;     debug_out(T...);   }   const long double PI = acos(-1);   int n, m, c, st[2 * 20005], dr[2 * 20005], a, b;   bool uz[20005];   vector<int> v[2 * 20005];   bool cup(int nod) {     uz[nod] = 1;     for (auto it : v[nod]) {       if (!dr[it]) {         dr[it] = nod;         st[nod] = it;         return 1;       }     }     for (auto it : v[nod]) {       if (!uz[dr[it]] && cup(dr[it])) {         dr[it] = nod;         st[nod] = it;         return 1;       }     }     return 0;   }   struct edge {     int a, b, c;   };   vector<edge> E2;   int _try(int x) {     for (int i = 0; i <= 2 * n + 1; i++) {       v[i].clear();     }     memset(st, 0, sizeof(st));     memset(dr, 0, sizeof(dr));     for (auto it : E2) {       if (it.c > x) continue;       v[it.a].push_back(it.b);       v[it.b].push_back(it.a);     }     int ok = 1;     while (ok) {       ok = 0;       memset(uz, 0, sizeof(uz));       for (int i = 1; i <= n; i++)         if (!st[i] && !uz[i]) ok |= cup(i);     }     int nr = 0;     for (int i = 1; i <= n; i++)       if (st[i]) nr++;     return nr == n;   }   int main() {     ios::sync_with_stdio(false);     cin >> n >> m;     for (long long i = 1; i <= m; i++) {       int p, q, c;       cin >> p >> q >> c;       q += n;       E2.push_back({p, q, c});     }     int p = 1, st = 0;     for (; p <= 1e9; p <<= 1)       ;     for (; p >= 1; p >>= 1) {       if (st + p < 1e9 && !_try(st + p)) {         st += p;       }     }     st++;     if (!_try(st)) {       cout <<  -1 n ;     } else       cout << st <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, S, T, du[10010];   struct edge {     int u, v, cap, flow;     edge() {}     edge(int u, int v, int c, int f) : u(u), v(v), cap(c), flow(f) {}   };   vector<edge> edges;   vector<int> e[10010];   inline void add_edge(int u, int v, int c) {     edges.push_back(edge(u, v, c, 0));     edges.push_back(edge(v, u, 0, 0));     int m = edges.size();     e[u].push_back(m - 2);     e[v].push_back(m - 1);   }   int vis[10010], dis[10010], cur[10010];   bool bfs(int s, int t) {     memset(vis, 0, sizeof(vis));     queue<int> que;     que.push(s);     vis[s] = 1;     dis[s] = 0;     while (!que.empty()) {       int now = que.front();       que.pop();       for (int i = 0; i < (e[now].size()); i++) {         edge& nxt = edges[e[now][i]];         if (!vis[nxt.v] && nxt.cap > nxt.flow) {           vis[nxt.v] = 1;           dis[nxt.v] = dis[now] + 1;           que.push(nxt.v);         }       }     }     return vis[t];   }   int dfs(int st, int t, int low) {     if (st == t || low == 0) return low;     int flow = 0, f;     for (int& i = cur[st]; i < e[st].size(); i++) {       edge& nxt = edges[e[st][i]];       if (dis[nxt.v] == dis[st] + 1 &&           (f = dfs(nxt.v, t, min(low, nxt.cap - nxt.flow))) > 0) {         nxt.flow += f;         edges[e[st][i] ^ 1].flow -= f;         flow += f;         low -= f;         if (low == 0) break;       }     }     return flow;   }   int Dinic(int s, int t) {     int ans = 0;     while (bfs(s, t)) {       memset(cur, 0, sizeof(cur));       ans += dfs(s, t, 0x3f3f3f3f);     }     return ans;   }   pair<int, int> pp[10010];   bool check(int mid) {     edges.clear();     for (int i = 0; i <= n + m + 1; i++) e[i].clear();     for (int i = 1; i <= m; i++) {       add_edge(S, i, 1);       add_edge(i, m + pp[i].first, 1);       add_edge(i, m + pp[i].second, 1);     }     for (int i = 1; i <= n; i++) add_edge(m + i, T, min(du[i], mid));     int ans = Dinic(S, T);     if (ans < m) return false;     return true;   }   int main() {     scanf( %d %d , &n, &m);     S = 0, T = n + m + 1;     for (int i = 1; i <= m; i++) {       int u, v;       scanf( %d %d , &u, &v);       pp[i] = make_pair(u, v);       du[u]++;       du[v]++;     }     int L = 1, R = min(m, n - 1), ans = min(m, n - 1);     while (L <= R) {       int mid = (L + R) >> 1;       if (check(mid)) {         ans = mid;         R = mid - 1;       } else         L = mid + 1;     }     printf( %d n , ans);     check(ans);     int tmp = 0;     for (int i = 0; i < edges.size(); i += 2) {       if (edges[i].u <= m && edges[i].u >= 1 && edges[i].v >= m + 1 &&           edges[i].v <= n + m && edges[i].cap == edges[i].flow) {         int nxt = pp[edges[i].u].first;         if (nxt == edges[i].v - m) nxt = pp[edges[i].u].second;         printf( %d %d n , edges[i].v - m, nxt);       }     }   }


#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1.0);   const int N = 1005;   int n, m;   int a[N], ans[N], pre[N];   int main() {     int i, j, k, t, nc = 0;     while (scanf( %d%d , &n, &m) != EOF) {       int tmin = -1, tpre = -1;       for (i = 1; i <= m; i++) {         scanf( %d , &a[i]);         if (tmin < a[i]) {           k = i;           tmin = a[i];         }       }       bool work = true;       ans[1] = k;       a[k]--;       for (i = 1; i <= m; i++) pre[i] = N;       pre[k] = 1;       for (i = 2; i < n; i++) {         tmin = -1;         for (j = 1; j <= m; j++) {           if (a[j] == 0 || j == ans[i - 1]) continue;           if (tmin < a[j] || tmin == a[j] && pre[j] < tpre) {             k = j;             tmin = a[j];             tpre = pre[j];           }         }         if (tmin == N) break;         ans[i] = k;         a[k]--;         pre[k] = i;       }       if (i < n)         work = false;       else {         for (i = 1; i <= m; i++) {           if (a[i] > 0 && i != ans[1] && i != ans[n - 1]) {             ans[n] = i;             break;           }         }         if (i > m) work = false;       }       if (!work)         printf( -1 n );       else {         for (i = 1; i <= n; i++) {           printf( %d , ans[i]);           if (i < n)             printf(   );           else             printf(  n );         }       }     }     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /stack:200000000 )   #pragma GCC optimize( Ofast )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   using namespace std;   class FKuroniAndThePunishment {    public:     vector<long long> primes;     void pre(int n) {       vector<bool> isPrime(n + 1, true);       isPrime[1] = false;       isPrime[0] = false;       for (int i = 2; i <= n; i++) {         if (isPrime[i])           for (int j = 2 * i; j <= n; j += i) isPrime[j] = false;         if (isPrime[i]) primes.push_back(i);       }     }     void solve(std::istream &in, std::ostream &out) {       int n;       in >> n;       vector<long long> ar(n);       for (long long &i : ar) in >> i;       long long mn = LLONG_MIN;       for (long long i : ar) mn = max(mn, i);       pre(1000000);       int idx = primes.size();       for (long long i = max(1ll, mn - n); i <= mn + n; i++) primes.push_back(i);       long long first = primes[idx];       for (int i = 0; i < idx; i++) {         long long index =             idx + (first % primes[i] == 0 ? 0 : primes[i] - (first % primes[i]));         for (long long j = index; j < primes.size(); j += primes[i])           while (primes[j] % primes[i] == 0) primes[j] /= primes[i];       }       long long ans = n;       for (long long &i : primes) {         if (i == 1) continue;         long long res = 0;         for (long long &j : ar) {           if (j < i)             res += (i - j);           else             res += min(j % i, (i - (j % i)));           if (res >= ans) break;         }         ans = min(ans, res);       }       out << ans <<   n ;     }   };   int main() {     FKuroniAndThePunishment solver;     std::ios_base::sync_with_stdio(false);     cin.tie(NULL);     std::istream &in(std::cin);     std::ostream &out(std::cout);     solver.solve(in, out);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 998244353;   int n, k, now, last;   long long dp[2][505][505], sum[505], ans = 0, s;   int main() {     ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);     cin >> n >> k;     memset(dp[1], 0, sizeof dp[1]);     dp[1][1][1] = 1;     for (int i = 2; i <= n; i++) {       now = i & 1;       last = now ^ 1;       memset(dp[now], 0, sizeof dp[now]);       for (int j = 1; j < i; j++) {         for (int k = 1; k < i; k++) {           if (j != k)             dp[now][j][k + 1] = (dp[now][j][k + 1] + dp[last][j][k]) % mod;           else             dp[now][j + 1][k + 1] =                 (dp[now][j + 1][k + 1] + dp[last][j][k]) % mod;           dp[now][j][1] = (dp[now][j][1] + dp[last][j][k]) % mod;         }       }     }     memset(sum, 0, sizeof sum);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= i; j++) sum[i] = (sum[i] + dp[now][i][j]) % mod;     s = 0;     for (int i = 1; i <= n; i++) s = (s + sum[i]) % mod;     int t = n;     for (int i = 1; i <= n; i++) {       while (t * i >= k) {         s = (s - sum[t] + mod) % mod;         t--;       }       ans = (ans + sum[i] * s % mod) % mod;     }     ans = ans * 2 % mod;     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool poss = true;   int n, rt = 0;   vector<int> v, res;   vector<vector<int>> adj;   vector<pair<int, int>> dfs(int second, int p) {     vector<pair<int, int>> cur;     for (auto i : adj[second]) {       if (i != p) {         vector<pair<int, int>> ch = dfs(i, second);         for (auto i : ch) {           cur.push_back(i);         }       }     }     sort(cur.begin(), cur.end());     for (int i = 0; i < cur.size(); ++i) {       if (i < v[second])         cur[i].first = i;       else         cur[i].first = i + 1;     }     if (v[second] > cur.size()) poss = false;     cur.push_back({v[second], second});     return cur;   }   int main() {     cin >> n;     adj.assign(n, vector<int>());     v.assign(n, 0);     res.assign(n, 0);     for (int i = 0; i < n; ++i) {       int x;       cin >> x >> v[i];       x--;       if (x != -1) {         adj[x].push_back(i);         adj[i].push_back(x);       } else         rt = i;     }     vector<pair<int, int>> cur = dfs(rt, rt);     for (auto i : cur) {       res[i.second] = i.first + 1;     }     if (!poss) {       cout <<  NO ;       return 0;     }     cout <<  YES n ;     for (auto i : res) {       cout << i <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, q;   struct matrix {     int val;   } matr[109][109];   matrix* mat[109][109];   int main() {     scanf( %d %d %d , &n, &m, &q);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) {         matr[i][j].val = 0;         mat[i][j] = &matr[i][j];       }     int t1, t2, t3, t4, t5;     matrix* tmp;     for (int i = 0; i < q; i++) {       scanf( %d , &t1);       if (t1 == 1) {         scanf( %d , &t2);         tmp = mat[t2][1];         for (int j = 1; j < m; j++) {           mat[t2][j] = mat[t2][j + 1];         }         mat[t2][m] = tmp;       } else if (t1 == 2) {         scanf( %d , &t2);         tmp = mat[1][t2];         for (int i = 1; i < n; i++) {           mat[i][t2] = mat[i + 1][t2];         }         mat[n][t2] = tmp;       } else if (t1 == 3) {         scanf( %d %d %d , &t3, &t4, &t5);         mat[t3][t4]->val = t5;       }     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         printf( %d  , matr[i][j].val);       }       printf(  n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 100;   const int maxpow = 1 << 17;   const int inf = 1e9 + 7;   long long h[maxn];   int par[maxn];   struct node {     pair<int, int> a;     node(pair<int, int> _a) : a(_a) {}     node() : a(0, -1) {}     void merge(node x, node y) { a = max(x.a, y.a); }   };   node tree[maxpow * 2];   node query(int i, int ns, int ne, int qs, int qe) {     if (qe <= ns || qs >= ne) {       return node();     }     if (ns >= qs && ne <= qe) {       return tree[i];     }     int mid = (ns + ne) / 2;     node res1 = query(2 * i, ns, mid, qs, qe);     node res2 = query(2 * i + 1, mid, ne, qs, qe);     node res;     res.merge(res1, res2);     return res;   }   void update(int i, int ns, int ne, int qs, pair<int, int> v) {     if (qs + 1 <= ns || qs >= ne) {       return;     }     if (ns + 1 == ne) {       tree[i] = node(v);       return;     }     int mid = (ns + ne) / 2;     update(2 * i, ns, mid, qs, v);     update(2 * i + 1, mid, ne, qs, v);     tree[i].merge(tree[2 * i], tree[2 * i + 1]);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n, d;     cin >> n >> d;     vector<long long> a;     for (long long i = 0; i < n; i++) {       cin >> h[i];       a.push_back(h[i]);     }     sort(a.begin(), a.end());     a.erase(unique(a.begin(), a.end()), a.end());     pair<int, int> mx(-1, -1);     for (int i = 0; i < n; i++) {       int left = lower_bound(a.begin(), a.end(), h[i] - d + 1) - a.begin();       int right = lower_bound(a.begin(), a.end(), h[i] + d) - a.begin();       int cur = lower_bound(a.begin(), a.end(), h[i]) - a.begin();       node ans1 = query(1, 0, maxpow, 0, left);       node ans2 = query(1, 0, maxpow, right, n);       pair<int, int> ans = max(ans1.a, ans2.a);       ans.first += 1;       par[i] = ans.second;       ans.second = i;       mx = max(mx, ans);       update(1, 0, maxpow, cur, ans);     }     cout << mx.first << endl;     int ind = mx.second;     vector<int> res;     while (ind != -1) {       res.push_back(ind);       ind = par[ind];     }     reverse(res.begin(), res.end());     for (int i = 0; i < res.size(); i++) {       cout << res[i] + 1 <<    ;     }     cout << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, r = 0, l = 0;     vector<int> d;     cin >> n;     d.resize(n);     for (int i = 0; i < n; ++i) {       int x, y;       cin >> x >> y;       l += x;       r += y;       d[i] = x - y;     }     int maxx = abs(r - l), n_max = -1;     for (int i = 0; i < n; ++i) {       int dl = l - d[i], dr = r + d[i];       if (abs(dr - dl) > maxx) {         maxx = abs(dr - dl);         n_max = i + 1;       }     }     if (n_max == -1)       cout << 0 << endl;     else       cout << n_max;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int TC;     cin >> TC;     while (TC--) {       int p, f, cnts, cntw, s, w;       cin >> p >> f >> cnts >> cntw >> s >> w;       if (s < w) {         swap(s, w);         swap(cnts, cntw);       }       int maxi = 0;       for (int i = 0; i <= min(p / w, cntw); i++) {         int pw = i;         int ps = min((p - i * w) / s, cnts);         int fw, fs;         int cntW = cntw - i;         int cntS = cnts - ps;         fw = min(cntW, f / w);         if (f / w > cntW) {           fs = min(cntS, (f - cntW * w) / s);         } else {           fs = 0;         }         int total = ps + pw + fs + fw;         maxi = max(maxi, total);       }       cout << maxi <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<bool> vis;   vector<vector<long long>> adj;   void dfs(long long node) {     vis[node] = true;     for (long long child : adj[node]) {       if (vis[child]) continue;       dfs(child);     }   }   signed main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long n;     cin >> n;     vector<long long> arr(n - 1);     vector<long long> deg(n + 1, 1);     for (long long i = 0; i < n - 1; ++i) {       cin >> arr[i];       ++deg[arr[i]];     }     set<pair<long long, long long>> st;     for (long long i = 1; i <= n; ++i) {       if (deg[i] == 1) {         st.insert({i, i});       }     }     cout << arr[0] <<   n ;     for (long long i = n - 2; i >= 0; --i) {       const long long node = arr[i];       auto it = st.begin();       long long currMx = it->first;       long long currRoot = it->second;       st.erase(it);       cout << currRoot <<     << node <<   n ;       --deg[node];       if (deg[node] == 1) {         st.insert({max(currMx, node), node});       }     }   }


#include <bits/stdc++.h>   using namespace std;   static const double EPS = 1e-10;   template <typename T, typename S>   vector<T>& operator<<(vector<T>& a, S b) {     a.push_back(b);     return a;   }   template <typename T>   void operator>>(vector<T>& a, int b) {     while (b--)       if (!a.empty()) a.pop_back();   }   bool isprime(int n) {     if (n < 2) return false;     for (int i = 2; i * i <= n; i++)       if (n % i == 0) return false;     return true;   }   long long b_pow(long long x, long long n) {     return n ? b_pow(x * x, n / 2) * (n % 2 ? x : 1) : 1ll;   }   string itos(int n) {     stringstream ss;     ss << n;     return ss.str();   }   string read() {     string s;     char c;     while (cin >> c && c !=  > ) s += c;     if (s.size() == 0) exit(0);     return s.substr(1);   }   int f(string s) { return s[0] ==  / ; }   string get(string s) {     if (s[0] ==  / ) return s.substr(1);     return s;   }   int main() {     ios_base::sync_with_stdio(false);     int n, m, ret = 0;     stack<string> s;     while (1) {       string t = read();       if (t ==   ) return 0;       if (s.size() == 0 || (!f(t) || get(s.top()) != get(t))) {         cout << string(s.size() * 2,    ) <<  <  << t <<  >  << endl;         s.push(t);       } else {         s.pop();         cout << string(s.size() * 2,    ) <<  <  << t <<  >  << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long ti;     cin >> ti;     for (long long io = 0; io < ti; io++) {       long long n, m;       cin >> n >> m;       vector<long long> a, ao, b;       for (long long i = 0; i < m; i++) {         long long x, y;         cin >> x >> y;         a.push_back(x);         ao.push_back(x);         b.push_back(y);       }       sort(a.begin(), a.end());       long long sf[m + 1];       long long sm = 0;       for (long long i = m - 1; i >= 0; i--) {         sm += a[i];         sf[m - i] = sm;       }       long long ans = 0;       if (n <= m) ans = sf[n];       for (long long i = 0; i < m; i++) {         long long v = b[i];         long long idx = upper_bound(a.begin(), a.end(), v) - a.begin() + 1;         long long avl = m - idx + 1;         if (idx > m) {           ans = max(ans, ao[i] + (n - 1) * b[i]);         } else if (avl < n) {           long long as = 0;           as = as + sf[avl];           long long rm = n - avl;           if (ao[i] <= b[i]) {             as += ao[i];             rm--;           }           as += rm * b[i];           ans = max(ans, as);         }       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct ed {     int a, b, w;   } p[600010];   int n, m, fa[600010], d[600010], ans;   bool cmp(ed a, ed b) { return (a.w > b.w); }   int gf(int x) { return (fa[x] != x) ? fa[x] = gf(fa[x]) : x; }   int main() {     cin >> n >> m;     for (int i = 1; i <= m; i++) cin >> p[i].a >> p[i].b >> p[i].w;     sort(p + 1, p + m + 1, cmp);     for (int i = 1; i <= n; i++) fa[i] = i, d[i] = 1;     for (int i = 1; i <= m; i++) {       int x = gf(p[i].a), y = gf(p[i].b);       if (x != y && d[x] + d[y] > 0)         fa[y] = x, ans += p[i].w, d[x] = d[x] & d[y];       else if (x == y && d[x]) {         d[x] = 0, ans += p[i].w;       }     }     cout << ans << endl;   }


#include <bits/stdc++.h>   int arr[100005];   int k;   void unsort(int left, int right) {     if (k <= 0 || left >= right - 1) return;     int mid = (left + right) / 2;     std::swap(arr[mid - 1], arr[mid]);     --k;     unsort(left, mid);     unsort(mid, right);   }   int main() {     int n;     scanf( %d%d , &n, &k);     if (k % 2 == 0 || k > 2 * n) {       printf( -1 n );       return 0;     }     for (int i = 0; i < n; ++i) {       arr[i] = i + 1;     }     k /= 2;     unsort(0, n);     for (int i = 0; i < n; ++i) {       printf( %d  , arr[i]);     }     printf(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long n, i, j, res = 0, k, v1, v2;     cin >> n;     vector<long long> v;     for (i = 0; i < n; i++) {       cin >> j;       v.emplace_back(j);     }     if (n == 1) {       cout << v[0] <<   n ;       return 0;     } else if (n == 2) {       cout << (v[0] | v[1]) <<   n ;       return 0;     }     for (i = 0; i < n; i++) {       for (j = i + 1; j < n; j++) {         v2 = v[i] | v[j];         for (k = j + 1; k < n; k++) {           v1 = v2 | v[k];           res = max(res, v1);         }       }     }     cout << res <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 100010;   string nick[MAX];   int ara[MAX], ord[MAX], b[MAX];   int save[MAX];   bool cmp(int a, int b) {     if (ara[a] == ara[b]) return nick[a] < nick[b];     return ara[a] > ara[b];   }   deque<int> D;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int n, m;     cin >> n;     if (n == 0) {       cout << 0 <<     << 0 << endl;       return 0;     }     for (int i = 1; i <= n; i++) {       cin >> nick[i] >> ara[i];       save[i] = ara[i];     }     cin >> m;     for (int i = 1; i <= m; i++) cin >> b[i], D.push_back(b[i]);     sort(D.begin(), D.end());     string s;     cin >> s;     int id = -1;     for (int i = 1; i <= n; i++) {       if (s == nick[i]) {         if (id == -1)           id = i;         else           assert(false);       }     }     for (int i = 1; i <= n; i++) ord[i] = i;     sort(ord + 1, ord + n + 1, cmp);     int ans1, ans2;     if (m == 0) {       for (int i = 1; i <= n; i++)         if (ord[i] == id) {           ans2 = ans1 = i;           break;         }       cout << ans1 <<     << ans2 << endl;       return 0;     }     int cur;     for (int i = 1; i <= n; i++)       if (ord[i] == id) cur = i;     if (n == m) {       ara[id] += D.front();       D.pop_front();     }     int parbo = n - cur;     int bad = D.size() - parbo;     for (int i = cur - 1; i >= 1 and bad > 0; i--, bad--) {       ara[ord[i]] += D.front();       D.pop_front();     }     int need;     for (int i = cur + 1; i <= n; i++) {       need = (ara[id] + 1) - ara[ord[i]];       int paic = 0;       while (D.size() > 0) {         if (D.front() >= need) {           paic = D.front();           D.pop_front();           break;         } else           D.pop_front();       }       ara[ord[i]] += paic;     }     sort(ord + 1, ord + n + 1, cmp);     for (int i = 1; i <= n; i++)       if (ord[i] == id) ans2 = i;     for (int i = 1; i <= n; i++) ara[i] = save[i];     D.clear();     for (int i = 1; i <= m; i++) D.push_back(b[i]);     sort(D.begin(), D.end());     ara[id] += D.back();     D.pop_back();     sort(ord + 1, ord + n + 1, cmp);     for (int i = n; i >= 1 and D.size() > 0; i--) {       if (ord[i] == id) continue;       ara[ord[i]] += D.back();       D.pop_back();     }     sort(ord + 1, ord + n + 1, cmp);     for (int i = 1; i <= n; i++)       if (ord[i] == id) ans1 = i;     cout << ans1 <<     << ans2 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 100;   vector<int> a[N];   int d[N];   void work(int l, int r) {     d[l]++;     d[r + 1]--;   }   int main() {     cin.tie(0);     cin.sync_with_stdio(false);     memset(d, 0, sizeof(d));     int n, c, m, tp, i, j, x, y;     cin >> n >> c;     int sum = 0, flag = 1;     for (i = 1; i <= n; i++) {       cin >> m;       a[i].push_back(m);       for (j = 1; j <= a[i][0]; j++) {         cin >> m;         a[i].push_back(m);       }     }     for (i = 1; i < n; i++) {       tp = min(a[i][0], a[i + 1][0]);       for (j = 1; j <= tp; j++) {         x = a[i][j];         y = a[i + 1][j];         if (x != y) break;       }       if (j > tp && a[i][0] > a[i + 1][0]) {         cout << -1 << endl;         return 0;       }       if (y > x) {         work(0, c - y);         work(c + 1 - x, c - 1);       } else if (x > y) {         work(c + 1 - x, c - y);       } else         work(0, c - 1);     }     for (int i = 0; i < c; i++) {       sum += d[i];       if (sum == n - 1) {         cout << i << endl;         flag = 0;         break;       }     }     if (flag) cout << -1 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     char c;     int ans = 0;     for (int i = 0; i < 8; i++) {       for (int j = 0; j < 8; j++) {         cin >> c;         if (c ==  . ) continue;         if (c ==  Q ) ans += 9;         if (c ==  q ) ans -= 9;         if (c ==  R ) ans += 5;         if (c ==  r ) ans -= 5;         if (c ==  B ) ans += 3;         if (c ==  b ) ans -= 3;         if (c ==  N ) ans += 3;         if (c ==  n ) ans -= 3;         if (c ==  P ) ans += 1;         if (c ==  p ) ans -= 1;       }     }     if (ans == 0) {       cout <<  Draw  << endl;     } else if (ans > 0) {       cout <<  White  << endl;     } else {       cout <<  Black  << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   const long long base = 31;   int xx[4] = {0, 0, 1, -1};   int yy[4] = {-1, 1, 0, 0};   string step =  URDL ;   long long Pow(long long a, long long b) {     long long res = 1;     if (b <= 0) return 1;     while (b > 0) {       if (b % 2) {         res = (res % mod * a % mod);         res %= mod;       }       a = (a % mod * a % mod) % mod;       b /= 2;     }     return res % mod;   }   const int maxn = 1e6 + 1;   long long a[maxn], b[maxn];   string s;   void solve() {     cin >> s;     int n = s.size();     for (int i = 0; i < n; i++) {       a[i + 1] = a[i];       b[i + 1] = b[i];       if (s[i] ==  a )         a[i + 1]++;       else         b[i]++;     }     long long res = 0;     for (int i = 0; i < n; i++) {       if (s[i] ==  b ) {         res = (res % mod + (Pow(2, a[i + 1]) - 1)) % mod;       }     }     cout << res;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int t;     t = 1;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   long long int n, k;   long long int a[100010], max;   long long int print[100010], pc;   int main(void) {     long long int i, j, f, l, mid;     long long int sum, baki = 2147483647;     scanf( %I64d %I64d , &n, &k);     for (i = 1; i <= n; i++) {       scanf( %I64d , &a[i]);       if (max < a[i]) max = a[i];     }     if (k == 0) {       for (i = 1; i <= n; i++) {         printf( %I64d  , i);       }       return false;     }     f = 1, l = max;     for (;;) {       mid = (f + l) / 2;       sum = 0;       for (i = 1; i <= n; i++) {         if (a[i] >= mid)           sum += mid;         else           sum += a[i];       }       if (sum >= k) {         if (baki > mid) baki = mid;         l = mid - 1;       } else {         f = mid + 1;       }       if (f > l) break;     }     if (baki == 2147483647) {       printf( -1 n );       return false;     }     for (i = 1; i <= n; i++) {       if (baki > a[i])         k -= a[i];       else         k -= baki - 1;     }     for (i = 1; i <= n; i++) {       if (baki <= a[i]) k--;       if (k == 0) break;     }     if (k > 0) {       printf( -1 n );       return false;     }     for (j = i + 1; j <= n; j++) {       if (baki <= a[j]) {         print[++pc] = j;       }     }     for (j = 1; j <= i; j++) {       if (baki < a[j]) {         print[++pc] = j;       }     }     for (i = 1; i <= pc; i++) {       printf( %I64d  , print[i]);     }     return false;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   void pr(const string& name, T t) {     cerr << name <<  :   << t << endl;   }   template <typename T, typename... Types>   void pr(const string& names, T t, Types... rest) {     auto comma_pos = names.find( , );     cerr << names.substr(0, comma_pos) <<  :   << t <<  ,  ;     auto next_name_pos = names.find_first_not_of(   t n , comma_pos + 1);     pr(string(names, next_name_pos), rest...);   }   template <class T, class U>   ostream& operator<<(ostream& o, const pair<T, U>& v) {     return o <<  (  << v.first <<  ,   << v.second <<  ) ;   }   template <class T>   ostream& operator<<(ostream& o, const vector<T>& v) {     o <<  { ;     for (int i = 0; i < (int)((int)((v).size())); ++i)       o << (i ?  ,   :   ) << v[i];     return o <<  } ;   }   const int dx[] = {0, 1, 0, -1};   const int dy[] = {-1, 0, 1, 0};   const int MAX_N = 2e5 + 10;   vector<int> G[MAX_N];   vector<int> rG[MAX_N];   int cmp[MAX_N];   bool vis[MAX_N];   int V;   vector<int> vs;   void dfs(int v) {     vis[v] = true;     for (auto e : G[v])       if (!vis[e]) dfs(e);     vs.push_back(v);   }   void rdfs(int v, int k) {     vis[v] = true;     cmp[v] = k;     for (auto e : rG[v])       if (!vis[e]) rdfs(e, k);   }   int scc() {     vs.clear();     memset(vis, 0, sizeof(vis));     for (int i = 0; i < (int)(V); ++i)       if (!vis[i]) dfs(i);     memset(vis, 0, sizeof(vis));     int k = 0;     reverse((vs).begin(), (vs).end());     for (auto e : vs)       if (!vis[e]) rdfs(e, k++);     return k;   }   int un[MAX_N];   int find(int x) {     if (un[x] == x) return x;     return un[x] = find(un[x]);   }   void unit(int a, int b) { un[find(a)] = find(b); }   int main(int argc, char* argv[]) {     ios::sync_with_stdio(0);     cin.tie(0);     memset(un, -1, sizeof(un));     int n, m;     cin >> n >> m;     for (int i = 0; i < (int)(n); ++i) un[i] = i;     for (int i = 0; i < (int)(m); ++i) {       int a, b;       cin >> a >> b;       --a, --b;       G[a].push_back(b);       rG[b].push_back(a);       unit(a, b);     }     V = n;     scc();     map<int, set<int> > app;     for (int i = 0; i < (int)(n); ++i) app[find(i)].insert(i);     int ans = 0;     for (auto& e : app) {       if ((int)((e.second).size()) == 1) continue;       set<int> cnum;       for (auto v : e.second) cnum.insert(cmp[v]);       if ((int)((cnum).size()) != (int)((e.second).size()))         ans += (int)((e.second).size());       else         ans += (int)((e.second).size()) - 1;     }     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     vector<int> a(n);     for (int i = 0; i < n; i++) {       cin >> a[i];     }     for (int i = 0; i < 10; i++) {     }     set<int> s(a.begin(), a.end());     if (s.size() < k) {       cout <<  NO  << endl;     } else {       cout <<  YES  << endl;       int cnt = 0;       for (auto item : s) {         if (cnt == k) {           break;         }         for (int i = 0; i < n; i++) {           if (a[i] == item) {             cout << i + 1 <<    ;             cnt++;             break;           }         }       }       for (int i = 0; i < 10; i++) {       }       cout << endl;     }     for (int i = 0; i < 10; i++) {     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> G[100005];   vector<int> rG[100005];   int f[100005];   int n, m;   bool canUsing[100005];   bool canAss[100005];   void dfs0(int u) {     canUsing[u] = 1;     if (f[u] == 1) return;     for (int i = 0; i < rG[u].size(); i++) {       int v = rG[u][i];       if (canUsing[v]) continue;       dfs0(v);     }   }   void dfs1(int u) {     canAss[u] = 1;     for (int i = 0; i < G[u].size(); i++) {       int v = G[u][i];       if (canAss[v]) continue;       dfs1(v);     }   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) scanf( %d , &f[i]);     for (int i = 1; i <= m; i++) {       int u, v;       scanf( %d%d , &u, &v);       G[u].push_back(v);       rG[v].push_back(u);     }     for (int i = 1; i <= n; i++) {       if (f[i] == 2 && canUsing[i] == 0) dfs0(i);       if (f[i] == 1 && canAss[i] == 0) dfs1(i);     }     for (int i = 1; i <= n; i++) {       int t = canAss[i] & canUsing[i];       printf( %d n , t);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool letras[26];   int main() {     list<char> kbd;     list<char>::iterator i;     int t, j;     bool foundKbd;     string s;     for (cin >> t; t > 0; t--) {       foundKbd = true;       cin >> s;       for (j = 0; j < s.size() && foundKbd; j++) {         if (kbd.size() == 0) {           kbd.push_back(s.at(j));           letras[s.at(j) -  a ] = true;         } else if (letras[s.at(j) -  a ] == false) {           for (i = kbd.begin(); i != kbd.end() && *i != s.at(j - 1); i++)             ;           if (i == kbd.begin()) {             kbd.push_front(s.at(j));             letras[s.at(j) -  a ] = true;           } else if (i == --kbd.end()) {             kbd.push_back(s.at(j));             letras[s.at(j) -  a ] = true;           } else             foundKbd = false;         } else {           for (i = kbd.begin(); i != kbd.end() && *i != s.at(j - 1); i++)             ;           if (*(++i) == s.at(j))             --i;           else if (*(--(--i)) != s.at(j))             foundKbd = false;         }       }       if (foundKbd) {         cout <<  YES  << endl;         for (j = 0; j < 26; j++)           if (letras[j] == false) kbd.push_back( a  + j);         for (i = kbd.begin(); i != kbd.end(); i++) cout << *i;         cout << endl;       } else         cout <<  NO  << endl;       kbd.clear();       for (j = 0; j < 26; j++) letras[j] = false;     }   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     int x = 0, f = 1;     char ch = getchar();     for (; !isdigit(ch); ch = getchar()) {       if (ch ==  - ) f = -1;     }     for (; isdigit(ch); ch = getchar()) {       x = x * 10 + ch - 48;     }     return x * f;   }   const int mxN = 1e5;   const int P = 998244353;   struct Element {     long long x, v, p;   } a[mxN + 3];   struct Event {     int u, x, y;     long long t1, t2;     bool operator<(const Event &arg) const { return t1 * arg.t2 < t2 * arg.t1; }   } ev[mxN * 2 + 3];   int f[mxN + 3][2][2];   int n, m;   long long quickpow(long long x, long long y) {     long long cur = x, ret = 1ll;     for (int i = 0; y; i++) {       if (y & (1ll << i)) {         y -= (1ll << i);         ret = ret * cur % P;       }       cur = cur * cur % P;     }     return ret;   }   long long mulinv(long long x) { return quickpow(x, P - 2); }   struct SgTNode {     long long x[2][2];   } sgt[mxN * 4 + 3];   void pushup(int u, int mid) {     for (int i = 0; i < 2; i++)       for (int j = 0; j < 2; j++) sgt[u].x[i][j] = 0ll;     for (int i = 0; i < 2; i++)       for (int j = 0; j < 2; j++)         if (!f[mid][i][j]) {           for (int ii = 0; ii < 2; ii++)             for (int jj = 0; jj < 2; jj++) {               sgt[u].x[ii][jj] += sgt[u << 1].x[ii][i] * sgt[u << 1 | 1].x[j][jj];             }         }     for (int i = 0; i < 2; i++)       for (int j = 0; j < 2; j++) {         sgt[u].x[i][j] %= P;       }   }   void build(int u, int le, int ri) {     if (le == ri) {       sgt[u].x[0][0] = P + 1 - a[le].p, sgt[u].x[1][1] = a[le].p;       return;     }     int mid = (le + ri) >> 1;     build(u << 1, le, mid);     build(u << 1 | 1, mid + 1, ri);     pushup(u, mid);   }   void update(int u, int le, int ri, int pos) {     if (le == ri) {       return;     }     int mid = (le + ri) >> 1;     if (pos <= mid) {       update(u << 1, le, mid, pos);     } else {       update(u << 1 | 1, mid + 1, ri, pos);     }     pushup(u, mid);   }   long long query() {     return (sgt[1].x[0][0] + sgt[1].x[0][1] + sgt[1].x[1][0] + sgt[1].x[1][1]) %            P;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %I64d%I64d%I64d , &a[i].x, &a[i].v, &a[i].p);       a[i].p = a[i].p * mulinv(100) % P;     }     for (int i = 1; i < n; i++) {       ev[++m].u = i, ev[m].x = 1, ev[m].y = 0, ev[m].t1 = a[i + 1].x - a[i].x,       ev[m].t2 = a[i].v + a[i + 1].v;       if (a[i].v < a[i + 1].v) {         ev[++m].u = i, ev[m].x = 0, ev[m].y = 0, ev[m].t1 = a[i + 1].x - a[i].x,         ev[m].t2 = a[i + 1].v - a[i].v;       } else if (a[i].v > a[i + 1].v) {         ev[++m].u = i, ev[m].x = 1, ev[m].y = 1, ev[m].t1 = a[i + 1].x - a[i].x,         ev[m].t2 = a[i].v - a[i + 1].v;       }     }     sort(ev + 1, ev + m + 1);     long long ans = 0ll, prob = 1ll;     build(1, 1, n);     for (int i = 1; i <= m; i++) {       f[ev[i].u][ev[i].x][ev[i].y] = 1;       update(1, 1, n, ev[i].u);       long long tmp = query(), tim = ev[i].t1 * mulinv(ev[i].t2) % P;       ans = (ans + (prob - tmp + P) * tim) % P;       prob = tmp;     }     printf( %I64d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   T gi() {     T x = 0;     bool f = 0;     char c = getchar();     while (c !=  -  && (c <  0  || c >  9 )) c = getchar();     if (c ==  - ) f = 1, c = getchar();     while (c >=  0  && c <=  9 ) x = x * 10 + c -  0 , c = getchar();     return f ? -x : x;   }   const int N = 2e5 + 10;   struct node {     int to, nxt, w;   } g[N << 1];   int lst[N], gl, w[N];   void add(int z, int y, int x) {     g[++gl] = (node){y, lst[x], z};     lst[x] = gl;     g[++gl] = (node){x, lst[y], z};     lst[y] = gl;   }   int ans1;   double ans2;   int siz[N], mx, rt, sum;   bool vis[N];   void getroot(int u, int ff) {     siz[u] = 1;     int s = 0;     for (int i = lst[u]; i; i = g[i].nxt) {       int v = g[i].to;       if (v == ff || vis[v]) continue;       getroot(v, u);       siz[u] += siz[v];       s = max(s, siz[v]);     }     s = max(s, sum - siz[u]);     if (s < mx) mx = s, rt = u;   }   double sd[N], sumd, ans;   void dfs(int u, int ff, int tp, int dep) {     ans += pow(dep, 1.5) * w[u];     sumd += 1.5 * sqrt(dep) * w[u];     sd[tp] += 1.5 * sqrt(dep) * w[u];     for (int i = lst[u]; i; i = g[i].nxt) {       int v = g[i].to;       if (v == ff) continue;       dfs(v, u, tp, dep + g[i].w);     }   }   void solve(int u) {     vis[u] = 1;     ans = sumd = 0;     for (int i = lst[u]; i; i = g[i].nxt)       sd[g[i].to] = 0, dfs(g[i].to, u, g[i].to, g[i].w);     if (ans2 > ans) ans1 = u, ans2 = ans;     for (int i = lst[u]; i; i = g[i].nxt) {       int v = g[i].to;       if (vis[v]) continue;       if (sumd - sd[v] > sd[v]) continue;       mx = sum = siz[v];       getroot(v, u);       solve(rt);     }   }   int main() {     int n = gi<int>();     for (int i = 1; i <= n; i++) w[i] = gi<int>();     for (int i = 1; i < n; i++) add(gi<int>(), gi<int>(), gi<int>());     ans2 = 1e20;     mx = sum = n;     getroot(1, 0);     solve(rt);     printf( %d %.10lf n , ans1, ans2);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k, i;     double sum = 0, num, av, av1;     cin >> n >> k;     int a[n];     for (i = 0; i < n; i++) {       cin >> a[i];       sum = sum + a[i];     }     av1 = sum / n;     if (av1 >= (k - .5)) {       cout << 0 << endl;       return 0;     } else {       for (i = 1;; i++) {         sum = sum + k;         num = n + i;         av = sum / num;         if (av >= (k - 0.5)) {           cout << i << endl;           return 0;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     int x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x * f;   }   namespace Mymath {   long long qp(long long x, long long p, long long mod) {     long long ans = 1;     while (p) {       if (p & 1) ans = ans * x % mod;       x = x * x % mod;       p >>= 1;     }     return ans;   }   long long inv(long long x, long long mod) { return qp(x, mod - 2, mod); }   long long C(long long N, long long K, long long fact[], long long mod) {     return fact[N] * inv(fact[K], mod) % mod * inv(fact[N - K], mod) % mod;   }   template <typename Tp>   Tp gcd(Tp A, Tp B) {     if (B == 0) return A;     return gcd(B, A % B);   }   template <typename Tp>   Tp lcm(Tp A, Tp B) {     return A * B / gcd(A, B);   }   };  // namespace Mymath   namespace fwt {   using namespace Mymath;   void FWT(int a[], int n, long long mod) {     for (int d = 1; d < n; d <<= 1)       for (int m = d << 1, i = 0; i < n; i += m)         for (int j = 0; j < d; j++) {           int x = a[i + j], y = a[i + j + d];           a[i + j] = (x + y) % mod, a[i + j + d] = (x - y + mod) % mod;         }   }   void UFWT(int a[], int n, long long mod) {     long long rev = inv(2, mod);     for (int d = 1; d < n; d <<= 1)       for (int m = d << 1, i = 0; i < n; i += m)         for (int j = 0; j < d; j++) {           int x = a[i + j], y = a[i + j + d];           a[i + j] = 1LL * (x + y) * rev % mod,                 a[i + j + d] = (1LL * (x - y) * rev % mod + mod) % mod;         }   }   void solve(int a[], int b[], int n, long long mod) {     FWT(a, n, mod);     FWT(b, n, mod);     for (int i = 0; i < n; i++) a[i] = 1LL * a[i] * b[i] % mod;     UFWT(a, n, mod);   }   };  // namespace fwt   namespace Maxflow {   const int Maxn = 1005;   struct edge {     int to, rev, cap;     edge(int _to, int _rev, int _cap) { to = _to, rev = _rev, cap = _cap; }   };   int src = 1002, snk = 1003;   vector<edge> G[Maxn];   int dist[Maxn], seen[Maxn];   int n;   void Clear() {     for (int i = 0; i < Maxn; i++) G[i].clear();   }   void bfs(int s) {     for (int i = 0; i < Maxn; i++) dist[i] = -1;     dist[s] = 0;     queue<int> Q;     Q.push(s);     while (!Q.empty()) {       int x = Q.front();       Q.pop();       for (int i = 0; i < G[x].size(); i++) {         edge &e = G[x][i];         if (e.cap && dist[e.to] == -1) {           dist[e.to] = dist[x] + 1;           Q.push(e.to);         }       }     }   }   int dfs(int now, int dest, int fl) {     if (now == dest) return fl;     for (int &i = seen[now]; i < G[now].size(); i++) {       edge &ed = G[now][i];       if (ed.cap && dist[ed.to] == dist[now] + 1) {         int f = dfs(ed.to, dest, min(fl, ed.cap));         if (f) {           ed.cap -= f;           G[ed.to][ed.rev].cap += f;           return f;         }       }     }     return 0;   }   int dinic(int s = src, int t = snk) {     int ret = 0;     while (1) {       memset(seen, 0, sizeof(seen));       bfs(s);       if (dist[t] == -1) return ret;       int f = dfs(s, t, 2147483647);       while (f) {         ret += f;         f = dfs(s, t, 2147483647);       }     }   }   };  // namespace Maxflow   namespace Geometry {   struct iP {     long long x, y;     iP(long long _x, long long _y) { x = _x, y = _y; }     iP() { x = y = 0; }     iP operator+(iP p) { return iP(x + p.x, y + p.y); }     iP operator-(iP p) { return iP(x - p.x, y - p.y); }     iP operator*(long long k) { return iP(x * k, y * k); }     long long det(iP p) { return x * p.y - y * p.x; }     long long dot(iP p) { return x * p.x + y * p.y; }     long long dist() { return x * x + y * y; }     bool operator<(const iP &p) const {       if (x != p.x) return x < p.x;       return y < p.y;     }   };   struct dP {     double x, y;     dP(double _x, double _y) { x = _x, y = _y; }     dP() { x = y = 0.0; }     dP operator+(dP p) { return dP(x + p.x, y + p.y); }     dP operator-(dP p) { return dP(x - p.x, y - p.y); }     dP operator*(double k) { return dP(x * k, y * k); }     double det(dP p) { return x * p.y - y * p.x; }     double dot(dP p) { return x * p.x + y * p.y; }     double dist() { return x * x + y * y; }     bool operator<(const dP &p) const {       if (x != p.x) return x < p.x;       return y < p.y;     }   };   vector<iP> convex_hull(iP X[], int l) {     vector<iP> ret;     sort(X + 1, X + 1 + l);     ret.push_back(X[1]);     for (int i = 2; i <= l; i++) {       while (ret.size() >= 2 &&              (ret[ret.size() - 2] - X[i]).det(ret[ret.size() - 1] - X[i]) >= 0) {         ret.pop_back();       }       ret.push_back(X[i]);     }     int rs = ret.size() + 1;     for (int i = l - 1; i >= 1; i--) {       while (ret.size() >= rs &&              (ret[ret.size() - 2] - X[i]).det(ret[ret.size() - 1] - X[i]) >= 0) {         ret.pop_back();       }       ret.push_back(X[i]);     }     return ret;   }   };  // namespace Geometry   const int Maxn = 2e5 + 5;   const int Maxm = 5500005;   int n, q;   int a[Maxn];   bool isp[Maxm];   vector<int> P;   vector<int> p[Maxn];   void _init() {     memset(isp, true, sizeof(isp));     isp[0] = isp[1] = false;     for (int i = 2; i < Maxm; i++) {       if (isp[i]) {         P.push_back(i);         for (int j = i + i; j < Maxm; j += i) {           isp[j] = false;         }       }     }   }   long long Ha(vector<int> &V) {     long long ret = 12384722;     for (int i = 0; i < V.size(); i++) {       ret = ret * 94333337 + V[i];     }     return ret;   }   vector<long long> H[Maxn];   struct node {     vector<pair<int, int> > st;     long long hh;     node *nxt;     node(long long _hh) {       hh = _hh;       nxt = NULL;       st.clear();     }   };   const int ss = 5000000;   node *Mp[ss];   void Add(long long HH, int Siz, int Pos) {     long long pp = HH % (long long)ss;     if (pp < 0) pp += ss;     if (Mp[pp] == NULL) {       Mp[pp] = new node(HH);       Mp[pp]->st.push_back(make_pair(Siz, Pos));       return;     }     node *tmp = Mp[pp];     bool Find = false;     while (tmp) {       if (tmp->hh == HH) {         Find = true;         break;       }       if (tmp->nxt == NULL) break;       tmp = tmp->nxt;     }     if (Find) {       while (!tmp->st.empty() && tmp->st.back().first >= Siz) {         tmp->st.pop_back();       }       tmp->st.push_back(make_pair(Siz, Pos));       return;     }     tmp->nxt = new node(HH);     tmp->nxt->st.push_back(make_pair(Siz, Pos));   }   vector<pair<int, int> > Get(long long HH) {     long long pp = HH % ss;     if (pp < 0) pp += ss;     vector<pair<int, int> > ept;     if (!Mp[pp]) return ept;     node *tmp = Mp[pp];     while (tmp) {       if (tmp->hh == HH) return tmp->st;       if (tmp->nxt == NULL) return ept;       tmp = tmp->nxt;     }     return ept;   }   void Ckm(int &x, int y) {     if (y < x) x = y;   }   int imp[Maxn][19];   vector<pair<int, int> > Q[Maxn];   int ans[2000000];   int tree[Maxn * 4], tag[Maxn * 4];   void Push(int p) {     tag[p * 2] = min(tag[p * 2], tag[p]);     tag[p * 2 + 1] = min(tag[p * 2 + 1], tag[p]);     tree[p * 2] = min(tree[p * 2], tag[p]);     tree[p * 2 + 1] = min(tree[p * 2 + 1], tag[p]);     tag[p] = 1e9;   }   void modify(int p, int l, int r, int lo, int hi, int val) {     if (lo > hi) return;     if (hi > r) hi = r;     if (lo <= l && r <= hi) {       tag[p] = min(tag[p], val);       tree[p] = min(tree[p], val);       return;     }     Push(p);     int mid = l + r >> 1;     if (lo <= mid) {       modify(p * 2, l, mid, lo, min(hi, mid), val);     }     if (hi > mid) {       modify(p * 2 + 1, mid + 1, r, max(lo, mid + 1), hi, val);     }     tree[p] = min(tree[p * 2], tree[p * 2 + 1]);   }   int query(int p, int l, int r, int lo, int hi) {     if (lo > hi) return 1e9;     if (lo <= l && r <= hi) {       return tree[p];     }     Push(p);     int mid = l + r >> 1;     int ans = 1e9;     if (lo <= mid) {       ans = min(ans, query(p * 2, l, mid, lo, min(hi, mid)));     }     if (hi > mid) {       ans = min(ans, query(p * 2 + 1, mid + 1, r, max(lo, mid + 1), hi));     }     tree[p] = min(tree[p * 2], tree[p * 2 + 1]);     return ans;   }   int main() {     _init();     n = read();     q = read();     for (int i = 1; i <= n; i++) {       a[i] = read();       int tmp = a[i];       for (int j = 0; j < P.size(); j++) {         if (P[j] * P[j] > tmp) break;         int f = 0;         while (tmp % P[j] == 0) {           tmp /= P[j];           f ^= 1;         }         if (f) p[i].push_back(P[j]);       }       if (tmp != 1) p[i].push_back(tmp);       int s = p[i].size();       vector<int> T;       for (int j = 0; j < (1 << s); j++) {         T.clear();         for (int k = 0; k < s; k++) {           if (j >> k & 1) T.push_back(p[i][k]);         }         H[i].push_back(Ha(T));       }     }     for (int i = n; i >= 1; i--) {       int s = p[i].size();       vector<int> T;       for (int j = 0; j < 16; j++) imp[i][j] = 1e9;       for (int j = 0; j < (1 << s); j++) {         int vv = __builtin_popcount(j);         vector<pair<int, int> > GG = Get(H[i][j]);         for (int k = 0; k < GG.size(); k++) {           Ckm(imp[i][s - vv * 2 + GG[k].first], GG[k].second);         }       }       for (int j = 0; j < H[i].size(); j++) {         Add(H[i][j], s, i);       }       for (int j = 1; j < 16; j++) {         imp[i][j] = min(imp[i][j], imp[i][j - 1]);       }     }     for (int i = 0; i < q; i++) {       int l, r;       l = read();       r = read();       Q[l].push_back(make_pair(r, i));     }     for (int i = 0; i < 4 * Maxn; i++) {       tag[i] = 1e9;       tree[i] = 1e9;     }     for (int i = n; i >= 1; i--) {       if (i != n) {         int lst = i + 1;         for (int j = 14; j >= 0; j--) {           if (imp[i][j] == imp[i][j + 1]) continue;           modify(1, 1, n, lst, imp[i][j] - 1, j + 1);           lst = imp[i][j];         }         modify(1, 1, n, lst, n, 0);       }       for (int j = 0; j < Q[i].size(); j++) {         int id = Q[i][j].second, r = Q[i][j].first;         ans[id] = query(1, 1, n, i + 1, r);       }     }     for (int i = 0; i < q; i++) {       printf( %d n , ans[i]);     }     return ~~(0 ^ 0 ^ 0);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k, sum = 0;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> k;       sum += (int)abs(k);     }     cout << sum << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     bool check = false;     int left, right;     cin >> left >> right;     for (int i = left; i <= right; i++) {       int num = i;       bool ch[10] = {false};       while (num > 0) {         if (ch[num % 10]) break;         ch[num % 10] = true;         num /= 10;       }       if (num == 0) {         cout << i;         check = true;         break;       }     }     if (!check) cout <<  -1 ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename Arg1>   void __f(const char *name, Arg1 &&arg1) {     cerr << name <<   :   << arg1 << endl;   }   template <typename Arg1, typename... Args>   void __f(const char *names, Arg1 &&arg1, Args &&...args) {     const char *comma = strchr(names + 1,  , );     cerr.write(names, comma - names) <<   :   << arg1 <<   |  ;     __f(comma + 1, args...);   }   using ll = long long;   using P = pair<int, int>;   using vi = vector<int>;   const char nl =   n ;   const int inf = 2e9;   const ll INF = (ll)2e18;   const ll mod = 1e9 + 7;   const int N = 2e6 + 15;   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     int n, x;     cin >> n;     vi a(n), pos(n + 1);     vi bucket(n, 0);     for (int i = 0; i < n; ++i) cin >> a[i];     for (int i = 0; i < n; ++i) {       cin >> x;       pos[x] = i;     }     for (int i = 0; i < n; ++i) {       if (pos[a[i]] <= i) {         bucket[i - pos[a[i]]]++;       } else {         bucket[i + n - pos[a[i]]]++;       }     }     int ans = 0;     for (int i = 0; i < n; ++i) {       ans = max(ans, bucket[i]);     }     cout << ans << nl;     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   template <typename T>   using minpq = priority_queue<T, vector<T>, greater<T>>;   long long pl, pr, vl, vr;   int k;   long long inter(long long a, long long b, long long c, long long d) {     return max(0LL, min(b, d) - max(a, c) + 1);   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> pl >> pr >> vl >> vr >> k;     long double ans = 0;     vector<long long> lucky;     for (int len = (0); len < (11); len++) {       for (int x = (0); x < ((1 << len)); x++) {         long long y = 0;         for (int i = (0); i < (len); i++) {           if ((x >> i) & 1) {             y = y * 10 + 4;           } else {             y = y * 10 + 7;           }         }         lucky.push_back(y);       }     }     sort((lucky).begin(), (lucky).end());     int n = ((int)(lucky).size());     for (int i = (1); i < (n - k); i++) {       int j = i + k;       ans += 1.0 * inter(pl, pr, lucky[i - 1] + 1, lucky[i]) *              inter(vl, vr, lucky[j - 1], lucky[j] - 1);       ans += 1.0 * inter(vl, vr, lucky[i - 1] + 1, lucky[i]) *              inter(pl, pr, lucky[j - 1], lucky[j] - 1);       if (k == 1 && pl <= lucky[i] && lucky[i] <= pr && vl <= lucky[i] &&           lucky[i] <= vr)         ans--;     }     ans /= 1.0 * (pr - pl + 1) * (vr - vl + 1);     cout << fixed << setprecision(11) << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int dx[4] = {0, 0, 1, -1};   int dy[4] = {1, -1, 0, 0};   const int maxn = 1e5 + 10;   char dir[4] = { R ,  L ,  D ,  U };   vector<vector<int> > a, ind, nxt;   pair<int, int> rh[maxn];   vector<int> vect[maxn], pos_undo;   int nxt2[maxn], pos[maxn], n, m, mt[maxn], cnt, r;   bool outside(int x, int y) {     if (x > n || x < 1 || y > m || y < 1) return true;     return false;   }   void add_edge(int x, int y) {     vect[x].push_back(y);     vect[y].push_back(x);   }   bool srt(int x, int y) { return nxt2[x] < nxt2[y]; }   int kuhn(int x, int tip) {     if (pos[x]) return 0;     pos[x] = 1;     pos_undo.push_back(x);     for (int i = 0; i < vect[x].size(); i++) {       int id = vect[x][i];       if (tip == 1 && nxt2[id] == 1) break;       if (mt[id] == -1 || kuhn(mt[id], tip)) {         mt[id] = x;         mt[x] = id;         return 1;       }     }     return 0;   }   void random_matching() {     for (int i = 1; i <= cnt; i++) {       if (mt[i] != -1) continue;       if (nxt2[i] != 0) continue;       for (int j = 0; j < vect[i].size(); j++) {         int id = vect[i][j];         if (mt[id] != -1) continue;         if (nxt2[id] != 0) continue;         mt[i] = id;         mt[id] = i;         r -= 2;         break;       }     }   }   int main() {     int t;     scanf( %d , &t);     while (t--) {       scanf( %d %d , &n, &m);       a.clear();       nxt.clear();       ind.clear();       a.resize(n + 2, vector<int>(m + 2));       nxt.resize(n + 2, vector<int>(m + 2));       ind.resize(n + 2, vector<int>(m + 2));       cnt = 0;       for (int i = 1; i <= n; i++)         for (int j = 1; j <= m; j++) {           scanf( %d , &a[i][j]);           nxt[i][j] = -1;           nxt2[cnt] = 0;           ind[i][j] = ++cnt;           rh[cnt] = {i, j};           mt[cnt] = -1;           vect[cnt].clear();         }       int fucked = 0;       r = 0;       for (int i = 1; i <= n; i++)         for (int j = 1; j <= m; j++) {           int e = 0;           for (int k = 0; k < 4; k++) {             int idx = i + dx[k];             int idy = j + dy[k];             if (outside(idx, idy)) continue;             if (a[idx][idy] < a[i][j]) {               nxt[i][j] = k;               nxt2[ind[i][j]] = 1;             } else if (a[idx][idy] == a[i][j]) {               e = 1;               if ((i + j) % 2) add_edge(ind[i][j], ind[idx][idy]);             }           }           if (e == 0 && nxt[i][j] == -1) fucked = 1;           if (nxt[i][j] == -1) r++;         }       if (fucked) {         printf( NO n );         continue;       }       for (int i = 1; i <= cnt; i++) sort(vect[i].begin(), vect[i].end(), srt);       random_matching();       for (int i = 1; i <= cnt; i++) {         if (nxt[rh[i].first][rh[i].second] != -1 || mt[i] != -1) continue;         if (kuhn(i, 1)) r -= 2;         for (int j = 0; j < pos_undo.size(); j++) pos[pos_undo[j]] = 0;         pos_undo.clear();       }       for (int i = 1; i <= cnt; i++) {         if (nxt[rh[i].first][rh[i].second] != -1 || mt[i] != -1) continue;         if (kuhn(i, 0)) r -= 1;         for (int j = 0; j < pos_undo.size(); j++) pos[pos_undo[j]] = 0;         pos_undo.clear();       }       if (r > 0) {         printf( NO n );         continue;       }       printf( YES n );       for (int i = 1; i <= n; i++) {         for (int j = 1; j <= m; j++) {           if (mt[ind[i][j]] != -1) {             if ((i + j) % 2)               printf( %d  , a[i][j] / 2 + (a[i][j] % 2));             else               printf( %d  , a[i][j] / 2);           } else {             printf( %d  , a[i][j] - a[i + dx[nxt[i][j]]][j + dy[nxt[i][j]]]);           }         }         printf(  n );       }       for (int i = 1; i <= n; i++) {         for (int j = 1; j <= m; j++) {           if (mt[ind[i][j]] != -1) {             for (int k = 0; k < 4; k++) {               int idx = i + dx[k];               int idy = j + dy[k];               if (ind[idx][idy] == mt[ind[i][j]]) {                 printf( %c  , dir[k]);                 break;               }             }           } else {             printf( %c  , dir[nxt[i][j]]);           }         }         printf(  n );       }     }     return 0;   }


#include <bits/stdc++.h>   const int N = 1e6 + 10;   using namespace std;   inline int min(int a, int b) { return a < b ? a : b; }   int main() {     int a, b, c;     while (~scanf( %d%d%d , &a, &b, &c)) {       int k = min(min(a / 3, b / 2), c / 2);       a -= 3 * k;       b -= 2 * k;       c -= 2 * k;       if (a == 0 && b == 0 && c == 0) {         printf( %d n , k * 7);       } else {         if (a == 0) {           if (b == 0 || c == 0) {             printf( %d n , k * 7 + 1);           } else {             printf( %d n , k * 7 + 2);           }         } else if (b == 0) {           if (c == 0) {             if (a > 2) {               printf( %d n , k * 7 + 2);             } else {               printf( %d n , k * 7 + 1);             }           } else {             if (c >= 2) {               printf( %d n , k * 7 + 3);             } else {               printf( %d n , k * 7 + 2);             }           }         } else if (c == 0) {           if (a >= 2 && b >= 2) {             printf( %d n , k * 7 + 4);           } else if (b < 2 && a >= 2) {             printf( %d n , k * 7 + 3);           } else if (a < 2) {             printf( %d n , k * 7 + 2);           }         } else {           int kk = min(min(a, b), c), sum = 0;           if (kk == a) {             if (a == 1) {               if (c >= 2) {                 if (b >= 2) {                   b = 2;                 }                 printf( %d n , k * 7 + a + b + 2);               } else {                 printf( %d n , k * 7 + 3);               }             } else {               printf( %d n , k * 7 + 6);             }           } else {             if (b == 1) {               if (c >= 2) {                 if (a >= 3) {                   a = 3;                 }                 printf( %d n , k * 7 + a + 3);               } else if (c == 1) {                 if (a >= 3) {                   a = 3;                 }                 printf( %d n , k * 7 + a + 2);               }             } else if (c == 1) {               if (b >= 2) {                 if (a >= 3) {                   a = 3;                 }                 printf( %d n , k * 7 + a + 3);               } else if (b == 1) {                 if (a >= 3) {                   a = 3;                 }                 printf( %d n , k * 7 + a + 2);               }             }           }         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename Arg1>   void __f(const char* name, Arg1&& arg1) {     cout << name <<   :   << arg1 << std::endl;   }   template <typename Arg1, typename... Args>   void __f(const char* names, Arg1&& arg1, Args&&... args) {     const char* comma = strchr(names + 1,  , );     cout.write(names, comma - names) <<   :   << arg1 <<   |  ;     __f(comma + 1, args...);   }   bool isV(char x) {     if (x ==  a  || x ==  e  || x ==  i  || x ==  o  || x ==  u ) {       return 1;     }     return 0;   }   bool isP(long long n) {     for (long long i = 2; i * i <= n; i++) {       if (n % i == 0) return 0;     }     return 1;   }   void fio() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);   }   void print(long long* a, long long n) {     long long i;     for (i = 0; i < (long long)n; i++) {       cout << a[i] <<    ;     }     cout << endl;   }   void print2d(long long a[][1000], long long m, long long n) {     long long i, j;     for (i = 0; i < (long long)m; i++) {       for (j = 0; j < (long long)n; j++) {         cout << setw(2) << a[i][j];       }       cout << endl;     }   }   int32_t main() {     fio();     long long n;     cin >> n;     long long* a = new long long[n];     long long i;     for (i = 0; i < (long long)n; i++) {       cin >> a[i];     }     long long* suf = new long long[n];     suf[n - 1] = 0;     stack<long long> s;     for (i = n - 1; i >= (long long)0; i--) {       while (s.size() > 0 && a[i] <= a[s.top()]) s.pop();       if (s.size() != 0) {         suf[i] = suf[s.top()] + (s.top() - i - 1) * a[i] + a[s.top()];       } else {         suf[i] = (n - (i + 1)) * a[i];       }       s.push(i);     }     long long* temp = new long long[n];     long long* pref = new long long[n];     pref[0] = 0;     long long m = 0, mi = -1;     stack<long long> x;     for (i = 0; i < (long long)n; i++) {       while (x.size() > 0 && a[x.top()] > a[i]) x.pop();       if (x.size() == 0)         pref[i] = i * a[i];       else         pref[i] = pref[x.top()] + (i - x.top() - 1) * a[i] + a[x.top()];       x.push(i);       if (m < pref[i] + suf[i] + a[i]) {         m = pref[i] + suf[i] + a[i];         mi = i;       }     }     for (i = mi + 1; i < (long long)n; i++) {       if (a[i] > a[i - 1]) a[i] = a[i - 1];     }     for (i = mi - 1; i >= (long long)0; i--) {       if (a[i] > a[i + 1]) a[i] = a[i + 1];     }     for (i = 0; i < (long long)n; i++) cout << a[i] <<    ;   }


#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1.0);   const int N = 1234567;   int x[N], y[N];   int n;   double areas[N];   void line(int i, int j, double &a, double &b, double &c) {     i %= n;     j %= n;     a = y[j] - y[i];     b = x[i] - x[j];     c = -a * x[i] - b * y[i];   }   void intersect(double a, double b, double c, double aa, double bb, double cc,                  double &dx, double &dy) {     double d = a * bb - b * aa;     dx = (b * cc - c * bb) / d;     dy = (c * aa - a * cc) / d;   }   int main() {     int q;     scanf( %d %d , &n, &q);     for (int i = 0; i < n; i++) scanf( %d %d , x + i, y + i);     reverse(x, x + n);     reverse(y, y + n);     areas[0] = 0;     for (int i = 0; i < 4 * n; i++)       areas[i + 1] = areas[i] + (x[i % n] - x[(i + 1) % n]) * 1.0 *                                     (y[i % n] + y[(i + 1) % n]);     double total_area = 0.0;     for (int i = 0; i < n; i++)       total_area += (x[i] - x[(i + 1) % n]) * 1.0 * (y[i] + y[(i + 1) % n]);     for (int i = 0; i < q; i++) {       int qx, qy;       scanf( %d %d , &qx, &qy);       double low = 0, high = pi;       double zero = -1.0;       bool found = false;       double ans = -1.0;       for (int it = 0; it < 120; it++) {         double mid = 0.5 * (low + high);         if (mid == low || mid == high) break;         if (it == 0) mid = low;         double dx = cos(mid);         double dy = sin(mid);         double a = dy;         double b = -dx;         double c = -a * qx - b * qy;         double u0 = a * x[0] + b * y[0] + c;         double u1 = a * x[1] + b * y[1] + c;         bool flag = false;         if (u0 > u1) {           flag = true;           u0 = -u0;           u1 = -u1;           a = -a;           b = -b;           c = -c;         }         int ll = 0, rr = n - 1;         while (ll < rr) {           int i = (ll + rr + 1) >> 1;           int j = (i + 1) % n;           double ui = a * x[i] + b * y[i] + c;           double uj = a * x[j] + b * y[j] + c;           if (ui <= uj && ui >= 0.5 * (u0 + u1))             ll = i;           else             rr = i - 1;         }         int id_max = (ll + 1) % n;         ll = id_max + 1, rr = id_max + n - 1;         while (ll < rr) {           int i = (ll + rr) >> 1;           int j = i + 1;           double ui = a * x[i % n] + b * y[i % n] + c;           double uj = a * x[j % n] + b * y[j % n] + c;           if (ui > uj)             ll = i + 1;           else             rr = i;         }         int id_min = ll;         int last, first;         {           ll = id_max, rr = id_min;           while (ll < rr) {             int i = (ll + rr + 1) >> 1;             double ui = a * x[i % n] + b * y[i % n] + c;             if (ui > 0)               ll = i;             else               rr = i - 1;           }           last = ll + n;         }         {           ll = id_min, rr = id_max + n;           while (ll < rr) {             int i = (ll + rr) >> 1;             double ui = a * x[i % n] + b * y[i % n] + c;             if (ui < 0)               ll = i + 1;             else               rr = i;           }           first = ll;         }         double xf, yf, xl, yl;         double aa, bb, cc;         line(first - 1, first, aa, bb, cc);         intersect(a, b, c, aa, bb, cc, xf, yf);         line(last, last + 1, aa, bb, cc);         intersect(a, b, c, aa, bb, cc, xl, yl);         double res = 0.0;         res += (xf - x[first % n]) * (yf + y[first % n]);         res += areas[last] - areas[first];         res += (x[last % n] - xl) * (y[last % n] + yl);         res += (xl - xf) * (yl + yf);         if (flag) res = total_area - res;         if (it == 0) {           zero = res;           continue;         }         {           double res1 = 0.5 * res;           double res2 = 0.5 * (total_area - res);           double diff = fabs(res1 - res2);           double sum = 0.5 * total_area;           if (diff / sum < 1e-6) {             found = true;             ans = mid;             break;           }         }         if ((res > 0.5 * total_area) == (zero > 0.5 * total_area))           low = mid;         else           high = mid;       }       printf( %.17f n , found ? ans : (0.5 * (low + high)));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 200005;   queue<int> q;   priority_queue<pair<int, int> > Q;   vector<pair<int, int> > V[maxn];   struct edge {     int obj, last;   } e[maxn];   int n, N, m, p, top, cnt, point[maxn], in[maxn], ord[maxn], L[maxn], H[maxn],       ans[maxn];   bool vis[maxn];   void add(int x, int y) {     cnt++;     e[cnt].obj = y;     e[cnt].last = point[x];     point[x] = cnt;   }   void Bye() {     puts( -1 );     exit(0);   }   int main() {     scanf( %d%d%d , &n, &m, &p);     for (int i = 1, x; i <= n; i++) {       scanf( %d , &x);       if (x)         L[i] = x, H[i] = x;       else         L[i] = 1, H[i] = p;     }     for (int i = 1, x, y; i <= m; i++) {       scanf( %d%d , &x, &y);       add(x, y);       in[y]++;     }     for (int i = 1; i <= n; i++)       if (!in[i]) q.push(i), ord[++N] = i, vis[i] = true;     while (!q.empty()) {       int u = q.front();       q.pop();       for (int i = point[u], v; i; i = e[i].last) {         v = e[i].obj;         in[v]--;         if (!in[v]) q.push(v), ord[++N] = v, vis[v] = true;       }     }     for (int i = 1; i <= n; i++)       if (!vis[i]) Bye();     for (int i = 1, u; i <= n; i++) {       u = ord[i];       for (int j = point[u], v; j; j = e[j].last) {         v = e[j].obj;         H[v] = min(H[v], H[u] - 1);       }     }     for (int i = n, u; i >= 1; i--) {       u = ord[i];       for (int j = point[u], v; j; j = e[j].last) {         v = e[j].obj;         L[u] = max(L[u], L[v] + 1);       }     }     for (int i = 1; i <= n; i++)       if (L[i] > H[i]) Bye();     for (int i = 1; i <= n; i++) V[H[i]].push_back(pair<int, int>(L[i], i));     top = p;     while (top) {       for (int i = 0, I = V[top].size(); i < I; i++) Q.push(V[top][i]);       if (Q.empty()) Bye();       ans[Q.top().second] = top;       Q.pop();       while (!Q.empty() && Q.top().first == top) {         ans[Q.top().second] = top;         Q.pop();       }       top--;     }     for (int i = 1; i < n; i++) printf( %d  , ans[i]);     printf( %d n , ans[n]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int dx[8] = {0, 0, -1, -1, -1, 1, 1, 1};   const int dy[8] = {-1, 1, -1, 0, 1, -1, 0, 1};   int r, c, n, res, a, b, f[18000005];   bool vis[3001][6001], g[3001][6001];   stack<pair<int, int> > stk;   void init() {     for (int i = 0; i < r * c; ++i) f[i] = i;   }   int F(int x) {     if (f[x] == x) return x;     stk.push(pair<int, int>(x, f[x]));     return f[x] = F(f[x]);   }   void U(int a, int b) {     int fa = F(a), fb = F(b);     stk.push(pair<int, int>(fa, f[fa]));     f[fa] = fb;   }   int main() {     scanf( %d%d%d , &r, &c, &n);     c <<= 1;     init();     for (int i = 0; i < n; ++i) {       scanf( %d%d , &a, &b);       --a;       --b;       while (!stk.empty()) stk.pop();       vis[a][b] = vis[a][b + c / 2] = true;       for (int i = 0; i < 8; ++i) {         int tx = a + dx[i], ty = b + dy[i];         if (ty == -1) ty = c - 1;         if (ty == c) ty = 0;         if (tx < 0 || tx >= r || !vis[tx][ty]) continue;         U(tx * c + ty, a * c + b);       }       b += c / 2;       for (int i = 0; i < 8; ++i) {         int tx = a + dx[i], ty = b + dy[i];         if (ty == -1) ty = c - 1;         if (ty == c) ty = 0;         if (tx < 0 || tx >= r || !vis[tx][ty]) continue;         U(tx * c + ty, a * c + b);       }       b -= c / 2;       if (F(a * c + b) == F(a * c + b + c / 2)) {         vis[a][b] = vis[a][b + c / 2] = false;         while (!stk.empty()) {           f[stk.top().first] = stk.top().second;           stk.pop();         }       } else {         vis[a][b] = vis[a][b + c / 2] = true;         ++res;       }     }     printf( %d n , res);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline bool check_diags(int x0, int y0, int x, int y) {     return abs(x0 - x) == abs(y0 - y);   }   inline bool check_lines(int x0, int y0, int x, int y) {     return x - x0 == 0 || y - y0 == 0;   }   vector<int> a, b, c, d;   int n, x, s, m, k;   void read() {     for (int i = 0; i < m; ++i) {       int t;       scanf(  %d , &t);       a.push_back(t);     }     for (int i = 0; i < m; ++i) {       int t;       scanf(  %d , &t);       b.push_back(t);     }     a.push_back(x);     b.push_back(0);     c.push_back(0);     d.push_back(0);     for (int i = 0; i < k; ++i) {       int t;       scanf(  %d , &t);       c.push_back(t);     }     for (int i = 0; i < k; ++i) {       int t;       scanf(  %d , &t);       d.push_back(t);     }   }   int main() {     scanf( %d %d %d %d %d , &n, &m, &k, &x, &s);     read();     int64_t ans = numeric_limits<int64_t>::max();     for (int i = 0; i < m + 1; ++i) {       int avail = s - b[i];       if (avail < 0) continue;       auto pos = upper_bound(d.begin(), d.end(), avail);       if (pos != d.begin()) {         int j = distance(d.begin(), pos - 1);         int64_t val = ((int64_t)a[i]) * (n - c[j]);         ans = min(ans, val);       }     }     printf( %lld n , ans);     return EXIT_SUCCESS;   }


#include <bits/stdc++.h>   using namespace std;   const int M = 3333;   const int mod = 998244353;   long long dp[M][M];   char s[M], t[M];   int main() {     scanf( %s%s , s + 1, t + 1);     int n = strlen(s + 1), m = strlen(t + 1);     for (int i = 1; i <= n + 1; i++) dp[i][i - 1] = 1;     for (int i = 1; i <= n; i++) {       for (int l = 1, r = l + i - 1; r <= n; l++, r++) {         if (l > m || s[i] == t[l]) dp[l][r] += dp[l + 1][r] % mod;         if (r > m || s[i] == t[r]) dp[l][r] += dp[l][r - 1] % mod;       }     }     long long ans = 0;     for (int i = m; i <= n; i++) ans += dp[1][i], ans %= mod;     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   #pragma warning(disable : 4996)   struct Edge {     int to, w;   };   const int N = 3e5 + 5, L = 20;   vector<Edge> v[N];   int a[N], tin[N], tout[N], p[N][L];   long long maxPath[N], maxUpPath[N], sum[N], pt[N], ancw[N];   int timer = 0;   bool upper(int a, int b) { return tin[a] <= tin[b] && tout[a] >= tout[b]; }   int getBeforeLca(int a, int b) {     if (upper(a, b)) return -1;     for (int i = L - 1; i >= 0; i--) {       if (!upper(p[a][i], b)) a = p[a][i];     }     return a;   }   void dfs(int node, int anc) {     p[node][0] = anc;     for (int i = 1; i < L; i++) {       p[node][i] = p[p[node][i - 1]][i - 1];     }     tin[node] = timer++;     sum[node] = maxPath[node] = a[node];     for (auto e : v[node]) {       if (e.to != anc) {         ancw[e.to] = e.w;         dfs(e.to, node);         maxPath[e.to] = max(0ll, maxPath[e.to] - e.w * 2);         maxPath[node] += maxPath[e.to];         sum[node] += maxPath[e.to];       }     }     tout[node] = timer;   }   void deep(int node, long long x, long long y, int anc) {     maxUpPath[node] = x - y;     x += sum[node];     for (auto e : v[node]) {       if (e.to != anc) {         pt[e.to] = pt[node] - e.w + sum[node] - maxPath[e.to];         long long nx = x - e.w * 2 - maxPath[e.to];         deep(e.to, nx, min(y, nx), node);       }     }   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n, q;     cin >> n >> q;     for (int i = 0; i < n; i++) {       cin >> a[i];     }     for (int i = 0; i < n - 1; i++) {       int a, b, w;       cin >> a >> b >> w;       a--, b--;       v[a].push_back({b, w});       v[b].push_back({a, w});     }     dfs(0, 0);     deep(0, 0, 0, -1);     for (int i = 0; i < q; i++) {       int x, y, xx, yy, lca;       cin >> x >> y;       x--, y--;       xx = getBeforeLca(x, y);       yy = getBeforeLca(y, x);       lca = xx == -1 ? x : p[xx][0];       long long ans = maxUpPath[lca] + sum[lca];       if (x != lca) {         ans += sum[x] - maxPath[xx] + pt[x] - pt[xx] - ancw[xx];       }       if (y != lca) {         ans += sum[y] - maxPath[yy] + pt[y] - pt[yy] - ancw[yy];       }       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long i, sum, a, b, c;   int main() {     for (i = 0; i < 4; i++) {       cin >> a;       if (i == 0) {         b = a;         c = a;       }       if (a < b) {         b = a;       }       if (a > c) {         c = a;       }       sum += a;     }     if (sum % 2 == 1) {       cout <<  NO ;     } else if (c + b == sum / 2 || c == sum / 2) {       cout <<  YES ;     } else       cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int l;     cin >> l;     string s;     cin >> s;     if (l < 26) {       cout <<  NO n ;       return 0;     }     int f[26] = {};     for (int i = 0; i < l; i++) f[tolower(s[i]) -  a ]++;     for (int i = 0; i < 26; i++)       if (f[i] == 0) {         cout <<  NO n ;         return 0;       }     cout <<  YES n ;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O2 )   #pragma GCC optimize( unroll-loops )   using namespace std;   const long double eps = 1e-7;   const int inf = 1000000010;   const long long INF = 10000000000000010LL;   const int mod = 1000000007;   const int MAXN = 100010, LOG = 20;   int n, m, k, q, u, v, x, y, t, a, b, ans;   int stt[MAXN], fnt[MAXN], ras[MAXN], timer = 1;   int sz[MAXN], par[MAXN], head[MAXN], h[MAXN];   long long fen[MAXN];   pair<long long, int> seg[MAXN << 2];   long long lazy[MAXN << 2];   set<int> st[MAXN];   vector<int> G[MAXN];   void add(int pos, long long val) {     for (; pos < MAXN; pos += pos & -pos) fen[pos] += val;   }   long long get(int pos) {     long long res = 0;     for (; pos; pos -= pos & -pos) res += fen[pos];     return res;   }   int dfs1(int node) {     h[node] = h[par[node]] + 1;     for (int v : G[node])       if (v != par[node]) {         par[v] = node;         sz[node] += dfs1(v);       }     return ++sz[node];   }   void dfs2(int node, int hd) {     head[node] = hd;     stt[node] = timer++;     ras[stt[node]] = node;     int big = 0;     for (int v : G[node])       if (v != par[node] && sz[v] > sz[big]) big = v;     if (big) dfs2(big, hd);     for (int v : G[node])       if (v != par[node] && v != big) dfs2(v, v);     fnt[node] = timer;   }   pair<long long, int> Build(int id, int tl, int tr) {     if (tr - tl == 1) return seg[id] = {INF, ras[tl]};     int mid = (tl + tr) >> 1;     return seg[id] = min(Build(id << 1, tl, mid), Build(id << 1 | 1, mid, tr));   }   void add_lazy(int id, long long val) {     seg[id].first += val;     lazy[id] += val;   }   void shift(int id) {     if (!lazy[id]) return;     add_lazy(id << 1, lazy[id]);     add_lazy(id << 1 | 1, lazy[id]);     lazy[id] = 0;   }   void Add(int id, int tl, int tr, int l, int r, long long val) {     if (r <= tl || tr <= l) return;     if (l <= tl && tr <= r) {       add_lazy(id, val);       return;     }     shift(id);     int mid = (tl + tr) >> 1;     Add(id << 1, tl, mid, l, r, val);     Add(id << 1 | 1, mid, tr, l, r, val);     seg[id] = min(seg[id << 1], seg[id << 1 | 1]);   }   pair<long long, int> Get(int id, int tl, int tr, int l, int r) {     if (r <= tl || tr <= l) return seg[0];     if (l <= tl && tr <= r) return seg[id];     shift(id);     int mid = (tl + tr) >> 1;     return min(Get(id << 1, tl, mid, l, r), Get(id << 1 | 1, mid, tr, l, r));   }   void Set(int id, int tl, int tr, int pos, long long val) {     if (pos < tl || tr <= pos) return;     if (tr - tl == 1) {       seg[id].first = val;       return;     }     shift(id);     int mid = (tl + tr) >> 1;     Set(id << 1, tl, mid, pos, val);     Set(id << 1 | 1, mid, tr, pos, val);     seg[id] = min(seg[id << 1], seg[id << 1 | 1]);   }   pair<long long, int> GetPath(int u, int v) {     pair<long long, int> res = {INF, -1};     while (head[u] != head[v]) {       if (h[head[u]] > h[head[v]]) swap(u, v);       res = min(res, Get(1, 1, n + 1, stt[head[v]], stt[v] + 1));       v = par[head[v]];     }     if (h[u] > h[v]) swap(u, v);     res = min(res, Get(1, 1, n + 1, stt[u], stt[v] + 1));     return res;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> m >> q;     for (int i = 1; i < n; i++) {       cin >> u >> v;       G[u].push_back(v);       G[v].push_back(u);     }     for (int i = 1; i <= m; i++) cin >> x, st[x].insert(i);     dfs1(1);     dfs2(1, 1);     Build(1, 1, n + 1);     seg[0] = {INF, 0};     for (int i = 1; i <= n; i++)       if (st[i].size()) Set(1, 1, n + 1, stt[i], *st[i].begin());     while (q--) {       cin >> t;       if (t == 2) {         cin >> v >> x;         Add(1, 1, n + 1, stt[v], fnt[v], x);         add(stt[v], +x);         add(fnt[v], -x);         continue;       }       vector<int> out;       cin >> u >> v >> k;       while (k--) {         pair<long long, int> p = GetPath(u, v);         if (p.first >= INF) break;         int v = p.second, id = *st[v].begin();         out.push_back(id);         st[v].erase(id);         if (st[v].empty())           Set(1, 1, n + 1, stt[v], INF);         else           Set(1, 1, n + 1, stt[v], *st[v].begin() + get(stt[v]));       }       cout << out.size() <<    ;       for (int i : out) cout << i <<    ;       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline long long sqr(int a) { return a * 1ll * a; }   int main() {     int k;     cin >> k;     int len = k;     int cnt = 0;     int x = 0;     long long res = 0;     while (x <= 2 * k) {       if (!(cnt & 1)) {         int best = 0;         int l = 1, r = k;         while (l <= r) {           int m = (l + r) / 2;           if ((sqr(x + 2) + sqr(m - 1) * 12 <= sqr(k) * 4) &&               (sqr(x + 1) + sqr(2 * m - 1) * 3 <= sqr(k) * 4)) {             best = m;             l = m + 1;           } else             r = m - 1;         }         if (best) {           if (x) res += best * 2 - 1;           res += best * 2 - 1;         }       } else {         int best = 0;         int l = 1, r = k;         while (l <= r) {           int m = (l + r) / 2;           if ((sqr(x + 2) + sqr(2 * m - 1) * 3 <= sqr(k) * 4) &&               (sqr(x + 1) + sqr(m) * 12 <= sqr(k) * 4)) {             best = m;             l = m + 1;           } else             r = m - 1;         }         if (x) res += best * 2;         res += best * 2;       }       x += 3;       cnt++;     }     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool comp(string a, string b) { return a.size() < b.size(); }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n;     cin >> n;     string arr[n];     for (int i = 0; i < n; ++i) cin >> arr[i];     sort(arr, arr + n, comp);     string st = arr[0];     vector<string> ans;     set<int> chosen;     chosen.insert(0);     while (ans.size() < n) {       if (ans.size() > 0) {         int mini = INT_MAX;         for (int j = 0; j < n; ++j) {           if (arr[j].find(st) != string::npos) {             if (arr[j].size() < mini && chosen.find(j) == chosen.end()) {               chosen.insert(j);               mini = arr[j].size();               st = arr[j];             }           }         }         if (mini == INT_MAX) {           return cout <<  NO n , 0;         }       }       ans.push_back(st);     }     cout <<  YES  << endl;     for (int i = 0; i < ans.size(); ++i) {       cout << ans[i] << endl;     }   }


#include <bits/stdc++.h>   #pragma comment(linker,  /stack:200000000 )   #pragma GCC optimize( Ofast )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   using namespace std;   struct Hash {     const long long int mod = 1791791791;     const long long int base = 255;     vector<long long int> h, p;     Hash(const string& s) {       long long int n = s.size();       h.resize(n + 1);       p.resize(n + 1, 1);       for (long long int i = 1; i <= n; i++) {         h[i] = (h[i - 1] * base + s[i - 1]) % mod;         p[i] = (p[i - 1] * base) % mod;       }     }     long long int getSub(long long int l, long long int r) {       return (h[r] - (h[l - 1] * p[r - l + 1]) % mod + mod) % mod;     }     ~Hash(){};   };   void rev(string& s) {     for (auto& i : s) {       if (i ==  0 )         i =  1 ;       else         i =  0 ;     }   }   signed main() {     string s, t;     cin >> s >> t;     long long int n = t.size();     Hash h(t);     long long int cnt0 = 0, cnt1 = 0;     for (auto i : s) {       cnt0 += (i ==  0 );       cnt1 += (i ==  1 );     }     if (cnt0 < cnt1) {       swap(cnt0, cnt1);       rev(s);     }     long long int ans = 0;     for (long long int len0 = 1; len0 < t.size() / cnt0; len0++) {       if (cnt1 == 0 || (n - len0 * cnt0) % cnt1 == 0) {         long long int len1 = 0;         if (cnt1 > 0) len1 = (n - len0 * cnt0) / cnt1;         long long int last = 1;         unordered_set<long long int> se0, se1;         for (long long int j = 0; j < s.size(); j++) {           if (s[j] ==  0 ) {             se0.insert(h.getSub(last, last + len0 - 1));             last += len0;           } else {             se1.insert(h.getSub(last, last + len1 - 1));             last += len1;           }         }         if (se0.size() <= 1 && se1.size() <= 1) ans++;         if (se0.size() == 1 && se1.size() == 1 &&             (*se1.begin()) == (*se0.begin()))           ans--;       }     }     cout << ans;     return 0;   }