#include <bits/stdc++.h> n struct node { n   int v; n   node *next; n } edge[400000 * 2 + 10], *adj[200000 + 10], *ecnt = &edge[0]; n struct Edge { n   int u, v; n   Edge() {} n   Edge(int u, int v) : u(u), v(v) {} n } e[400000 + 10], ans[400000 + 10]; n int n, m, s, t, ds, dt, col[200000 + 10], cntcol, cnta, fa[200000 + 10], n     belong[200000 + 10]; n int able[2][200000 + 10], link[2][200000 + 10]; n template <class T> n void Read(T &x) { n   char c; n   while (c = getchar(), c != EOF) n     if (c >=  0  && c <=  9 ) { n       x = c -  0 ; n       while (c = getchar(), c >=  0  && c <=  9 ) x = x * 10 + c -  0 ; n       ungetc(c, stdin); n       return; n     } n } n void read() { n   Read(n), Read(m); n   for (int i = 1; i <= m; i++) Read(e[i].u), Read(e[i].v); n   Read(s), Read(t), Read(ds), Read(dt); n } n void addedge(int u, int v) { n   node *p = ++ecnt; n   p->v = v; n   p->next = adj[u]; n   adj[u] = p; n } n void dfs(int u) { n   col[u] = cntcol; n   for (node *p = adj[u]; p; p = p->next) n     if (!col[p->v]) dfs(p->v); n } n int Find(int x) { return x == fa[x] ? x : fa[x] = Find(fa[x]); } n void solve() { n   for (int i = 1; i <= n; i++) fa[i] = i; n   for (int i = 1; i <= m; i++) { n     if (e[i].u == s || e[i].u == t || e[i].v == s || e[i].v == t) continue; n     if (Find(e[i].u) != Find(e[i].v)) { n       fa[Find(e[i].u)] = Find(e[i].v); n       ans[++cnta] = e[i]; n       addedge(e[i].u, e[i].v), addedge(e[i].v, e[i].u); n     } n   } n   for (int i = 1; i <= n; i++) n     if (!col[i]) { n       ++cntcol; n       dfs(i); n     } n   for (int i = 1; i <= m; i++) n     if (e[i].u == s || e[i].u == t || e[i].v == s || e[i].v == t) n       addedge(e[i].u, e[i].v), addedge(e[i].v, e[i].u); n   int cnts = 0, cntt = 0; n   belong[col[s]]++; n   for (node *p = adj[s]; p; p = p->next) n     if (!belong[col[p->v]]) belong[col[p->v]]++; n   belong[col[t]]++; n   for (node *p = adj[t]; p; p = p->next) n     if (!belong[col[p->v]]) { n       ans[++cnta] = Edge(t, p->v), cntt++; n       belong[col[p->v]] = -1; n     } else if (belong[col[p->v]] == 1) { n       belong[col[p->v]]++; n       able[1][col[p->v]] = p->v; n     } n   for (node *p = adj[s]; p; p = p->next) n     if (belong[col[p->v]] == 1) { n       ans[++cnta] = Edge(s, p->v), cnts++; n       belong[col[p->v]] = -1; n     } else if (belong[col[p->v]] == 2) n       able[0][col[p->v]] = p->v; n   if (cnts > ds || cntt > dt) n     puts( No ); n   else { n     ds -= cnts, dt -= cntt; n     bool f = false; n     for (node *p = adj[s]; p; p = p->next) n       if (belong[col[p->v]] == 2 && ds && p->v != t) { n         ds--; n         ans[++cnta] = Edge(s, p->v); n         link[0][col[p->v]] = p->v; n         belong[col[p->v]] = 0; n       } n     if (ds && dt && belong[col[t]] == 2) { n       f = true; n       ans[++cnta] = Edge(s, t); n       belong[col[s]] = 0; n       dt--; n     } n     for (node *p = adj[t]; p; p = p->next) n       if (belong[col[p->v]] == 2 && p->v != s) { n         if (!dt) { n           puts( No ); n           return; n         } n         dt--; n         ans[++cnta] = Edge(t, p->v); n         link[1][col[p->v]] = p->v; n         belong[col[p->v]] = 0; n       } n     if (!f && dt && ds && belong[col[s]] == 2) { n       f = true; n       ans[++cnta] = Edge(s, t); n       ds--; n     } n     if (!f && (ds || dt)) { n       if (ds) { n         for (int i = 1; i <= cntcol; i++) n           if (able[0][i] && link[1][i]) { n             f = true; n             ans[++cnta] = Edge(s, able[0][i]); n             break; n           } n       } n       if (!f && dt) { n         for (int i = 1; i <= cntcol; i++) n           if (able[1][i] && link[0][i]) { n             f = true; n             ans[++cnta] = Edge(t, able[1][i]); n             break; n           } n       } n     } n     if (f) { n       puts( Yes ); n       for (int i = 1; i <= cnta; i++) printf( %d %d n , ans[i].u, ans[i].v); n     } else n       puts( No ); n   } n } n int main() { n   read(); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n = 0; n   cin >> n; n   int a = (int)sqrt(n); n   if (a * a == n) { n     cout << a * 4 << endl; n   } else if (a * (a + 1) >= n) { n     cout << a * 4 + 2 << endl; n   } else { n     cout << a * 4 + 4 << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long int mod = 1e9 + 7; n void solve() { n   string s; n   cin >> s; n   int cntr1 = 10, cntr2 = 10; n   int wt1 = 0, wt2 = 0; n   for (int i = 0; i < 10; i++) { n     if (i % 2 == 0) { n       if (s[i] ==  1  || s[i] ==  ? ) wt1++; n     } else { n       if (s[i] ==  1 ) wt2++; n     } n     int left_t1 = 0, left_t2 = 0; n     for (int j = i + 1; j < 10; j++) { n       if (j % 2 == 0) { n         left_t1++; n       } else { n         left_t2++; n       } n     } n     if (wt1 > wt2 + left_t2) { n       cntr1 = i + 1; n       break; n     } n     if (wt2 > wt1 + left_t1) { n       cntr1 = i + 1; n       break; n     } n   } n   wt1 = 0, wt2 = 0; n   for (int i = 0; i < 10; i++) { n     if (i % 2 == 0) { n       if (s[i] ==  1 ) wt1++; n     } else { n       if (s[i] ==  1  || s[i] ==  ? ) wt2++; n     } n     int left_t1 = 0, left_t2 = 0; n     for (int j = i + 1; j < 10; j++) { n       if (j % 2 == 0) { n         left_t1++; n       } else { n         left_t2++; n       } n     } n     if (wt1 > wt2 + left_t2) { n       cntr2 = i + 1; n       break; n     } n     if (wt2 > wt1 + left_t1) { n       cntr2 = i + 1; n       break; n     } n   } n   cout << min(cntr1, cntr2); n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int t; n   cin >> t; n   while (t-- > 0) { n     solve(); n     cout <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long int mod = 1e9 + 7; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long int n, a, b; n   cin >> n >> a >> b; n   long long int c = 0; n   vector<long long int> v(n); n   for (long long int i = 0; i < n; i++) cin >> v[i]; n   long long int ans = accumulate(v.begin(), v.end(), 0); n   for (long long int i = 0; i < n; i++) { n     if (v[i] == 1) { n       if (a > 0) n         a--, ans--; n       else if (b > 0) n         b--, c++, ans--; n       else if (c > 0) n         c--, ans--; n     } else { n       if (b >= 1) b--, ans -= 2; n     } n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int oo = (int)2147483647; n const double PI = 2 * acos(0.0); n const long double eps = 1e-11; n int diri[] = {0, 1, 0, -1, 1, 1, -1, -1, 0}; n int dirk[] = {1, 0, -1, 0, 1, -1, 1, -1, 0}; n int main() { n   int n, m; n   double k; n   cin >> n >> m >> k; n   k += eps; n   map<string, int> mp; n   for (int i = ((int)0); i <= ((int)n - 1); i++) { n     string s; n     int l; n     cin >> s >> l; n     if (l * k >= 100) mp[s] = (int)l * k; n   } n   for (int i = ((int)0); i <= ((int)m - 1); i++) { n     string s; n     cin >> s; n     if (!mp[s]) mp[s] = 0; n   } n   cout << mp.size() << endl; n   for (__typeof(mp).begin() it = (mp).begin(); it != (mp).end(); it++) n     cout << it->first <<     << it->second << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1000500; n typedef struct treap *ptreap; n struct treap { n   int v, c, y; n   ptreap l, r; n   treap() {} n   treap(int v) : v(v), c(1), y(rand()), l(0), r(0) {} n }; n int cnt(ptreap t) { return t ? t->c : 0; } n void recalc(ptreap t) { n   if (t) t->c = cnt(t->l) + cnt(t->r) + 1; n } n void split(ptreap t, int key, ptreap &l, ptreap &r) { n   if (!t) { n     l = r = 0; n     return; n   } n   int cur_key = cnt(t->l); n   if (key < cur_key) { n     split(t->l, key, l, t->l); n     r = t; n   } else { n     split(t->r, key - cur_key - 1, t->r, r); n     l = t; n   } n   recalc(t); n } n void merge(ptreap l, ptreap r, ptreap &t) { n   if (!l || !r) { n     t = l ? l : r; n     return; n   } n   if (l->y < r->y) { n     merge(l->r, r, l->r); n     t = l; n   } else { n     merge(l, r->l, r->l); n     t = r; n   } n   recalc(t); n } n void print(ptreap t) { n   if (!t) return; n   print(t->l); n   cout << t->v; n   print(t->r); n } n int n, m, val, r, cur, a[maxn]; n ptreap t; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   srand(time(0)); n   cin >> n >> m; n   for (int i = 0; i < m; ++i) { n     cin >> a[i]; n     --a[i]; n   } n   for (int i = 0; i < n; ++i) { n     cin >> val; n     if (val == -1) { n       for (int j = 0; j < r; ++j) { n         ptreap q, w; n         split(t, a[j] - j, q, t); n         split(q, a[j] - j - 1, w, q); n         merge(w, t, t); n       } n       cur -= r; n       while (r > 0 && a[r - 1] > cur - 1) --r; n     } else { n       ptreap tmp = new treap(val); n       merge(t, tmp, t); n       ++cur; n       if (a[r] == cur - 1) ++r; n     } n   } n   if (!cur) n     cout <<  Poor stack! ; n   else n     print(t); n   return 0; n } n


////#include <iostream> n ////#include <cstdio> n ////#include <cstring> n ////#include <algorithm> n //// n ////#define LL long long n //// n ////LL gcd(LL a,LL b) { n ////    if(b == 0) return a; n ////    else return gcd(b,a % b); n ////} n //// n ////inline LL calc(LL x) { n ////    LL ret = 0; n ////    while(x) { n ////        ret += x % 10; n ////        x /= 10; n ////    } n ////    return ret; n ////} n //// n ////int main() { n ////    int T; scanf( %d ,&T); n ////    LL n,x; n ////    while(T--) { n ////        scanf( %lld ,&n); n ////        x = 0; n ////        for(LL i=n; i; i++) { n ////            if(gcd(i,calc(i)) >= 2) { n ////                printf( %lld n ,i); n ////                break; n ////            } n ////        } n ////    } n ////    return 0; n ////} n // n //#include <iostream> n //#include <cstring> n //#include <cstdio> n //#include <algorithm> n //#include <map> n //#define Maxn 100005 n //using namespace std; n //int a[1005000]; n //map<int,int> mp; n //int main(int argc,char* argv[]) { n //    int T; scanf( %d ,&T); n // n //    while(T--) { n //        mp.clear(); n //        int k = 524288,tmp = k; n //        while (tmp) { n //            a[tmp] = 0; n //            tmp >>= 1; n //        } n //        int n,w,x,ans = 0; n //        cin >> n >> w; n //        for(int i=0; i<n; i++) cin >> x,a[x]++; n //        while(n) { n //            int tmp = k,sum = w; n //            while(tmp) { n //                if(a[tmp]) { n //                    int cnt = sum / tmp; n //                    cnt = min(cnt,a[tmp]); n //                    sum -= cnt * tmp; n //                    a[tmp] -= cnt; n //                    n -= cnt; n //                } n //                tmp >>= 1; n //            } n //            ans++; n //        } n //        cout << ans << endl; n //    } n //    return 0; n //} n  n #include <iostream> n #include <cstring> n #include <cstdio> n #define Maxn 1005 n using namespace std; n int dp[Maxn][Maxn]; n const int Mod = 1e9 + 7; n  n int solve(int n,int k,int total) { n     if(n <= 0 || k <= 1) return 1; n     else { n         if(dp[n][k] == -1) n             dp[n][k] = ((solve(n - 1,k,total) % Mod + solve(total - n,k - 1,total) % Mod)) % Mod; n         return (dp[n][k] % Mod); n     } n } n  n int main(int argc,char* argv[]) { n     int T,n,k; scanf( %d ,&T); n     while(T--) { n         scanf( %d %d ,&n,&k); n         memset(dp,-1,sizeof(dp)); n         cout << solve(n,k,n) << endl; n     } n  n     return 0; n }


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   cin >> t; n   int n; n   int fn[200005] = {}; n   int a, b, c; n   vector<string> st(t); n   for (int j = 0; j < t; j++) { n     cin >> n; n     int rn[n]; n     for (int i = 0; i < n; i++) { n       cin >> rn[i]; n       fn[rn[i]] = i + 1; n     } n     string s =  1 ; n     a = min(fn[1], fn[2]); n     b = max(fn[1], fn[2]); n     for (int i = 2; i <= n; i++) { n       c = fn[i]; n       if (a >= c) n         a = c; n       else if (b <= c) n         b = c; n       if (b - a == i - 1) n         s.insert(i - 1,  1 ); n       else n         s.insert(i - 1,  0 ); n     } n     st[j] = s; n   } n   for (int j = 0; j < t; j++) { n     cout << st[j] << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   int arr[n + 1]; n   for (int i = 0; i < n; i++) { n     int k; n     cin >> k; n     arr[k] = i + 1; n   } n   int m; n   long long int vas = 0, pet = 0; n   cin >> m; n   for (int i = 0; i < m; i++) { n     int k; n     cin >> k; n     vas += arr[k]; n     pet += n + 1 - arr[k]; n   } n   cout << vas <<     << pet; n   return 0; n } n


#pragma GCC optimize( Ofast ,  unroll-loops ,  no-stack-protector ) n   n #include <bits/stdc++.h> n   n using namespace std; n  n #define all(a) (a).begin(), (a).end() n #define sz(a) (int)(a).size() n  n using ll = long long; n using ld = long double;  n // using ld = __float128; n using pii = pair<int, int>; n using pll = pair<ll, ll>; n using uint = unsigned int; n using ull = unsigned long long; n  n mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); n default_random_engine generator; n  n void solve(); n  n int main() { n #ifdef LOCAL n     freopen( input.txt ,  r , stdin); n     // freopen( output.txt ,  w , stdout);  n #endif  n  n     ios_base::sync_with_stdio(false); n     cin.tie(0); n     cout.tie(0); n     cout << setprecision(10) << fixed; n     cerr << setprecision(10) << fixed; n  n     int tests = 1; n     // cin >> tests; n  n     for (int test = 1; test <= tests; ++test) { n         // cout <<  Case #  << test <<  :  ; n         solve(); n     } n  n #ifdef LOCAL n     cerr <<  Time:   << double(clock()) / CLOCKS_PER_SEC << endl; n #endif n } n  n // -----------------------------------------------------------------  n  n const int MAXN = 200200; n vector<int> g[MAXN]; n int w[MAXN]; n  n vector<int> arr; n int dfs(int v, int p = -1) { n     arr.push_back(v); n     w[v] = 1; n     for (int u : g[v]) { n         if (u == p) { n             continue; n         } n         w[v] += dfs(u, v); n     } n     return w[v]; n } n  n vector<int> f; n  n bool check(int root, int k) { n     arr.clear(); n     dfs(root); n     if (sz(arr) != f[k]) { n         return false; n     } n     if (k <= 1) { n         return true; n     } n  n     for (int v : arr) { n         if (w[v] == f[k - 1] || w[v] == f[k - 2]) { n             int u; n             for (int uu : g[v]) { n                 if (w[uu] > w[v]) { n                     u = uu; n                 } n             } n  n             for (int i = 0; i < sz(g[u]); ++i) { n                 if (g[u][i] == v) { n                     swap(g[u][i], g[u].back()); n                     g[u].pop_back(); n                     break; n                 } n             } n             for (int i = 0; i < sz(g[v]); ++i) { n                 if (g[v][i] == u) { n                     swap(g[v][i], g[v].back()); n                     g[v].pop_back(); n                     break; n                 } n             } n  n             if (w[v] == f[k - 1]) { n                 if (!check(v, k - 1)) { n                     return false; n                 } n                 if (!check(u, k - 2)) { n                     return false; n                 } n             } else { n                 if (!check(v, k - 2)) { n                     return false; n                 } n                 if (!check(u, k - 1)) { n                     return false; n                 } n             } n             return true; n         } n     } n     return false; n } n  n void solve() {   n     int n; n     cin >> n; n  n     int k = 2; n     f = {1, 1}; n     for (; f.back() < n; ++k) { n         f.push_back(f[k - 2] + f[k - 1]); n     } n  n     for (int i = 1; i < n; ++i) { n         int u, v; n         cin >> u >> v; n         --u; --v; n         g[u].push_back(v); n         g[v].push_back(u); n     } n  n     cout << (check(0, sz(f) - 1) ?  YES n  :  NO n ); n } n  n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int v; n   cin >> v; n   v == 1 || v == 2 ? cout << v : cout << 1; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long t, j; n   cin >> t; n   for (j = 0; j < t; j++) { n     long long a, b, c, p = 0, r = 0; n     cin >> a >> b >> c; n     if (a >= c) n       p = -1; n     else n       p = 1; n     if ((c / b) >= a) n       r = -1; n     else n       r = b; n     cout << p <<     << r << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n using ld = long double; n namespace io { n template <class T> n void re(complex<T>& x); n template <class T1, class T2> n void re(pair<T1, T2>& p); n template <class T> n void re(vector<T>& a); n template <class T, size_t SZ> n void re(array<T, SZ>& a); n template <class T> n void re(T& x) { n   cin >> x; n } n void re(double& x) { n   string t; n   re(t); n   x = stod(t); n } n void re(ld& x) { n   string t; n   re(t); n   x = stold(t); n } n template <class T, class... Ts> n void re(T& t, Ts&... ts) { n   re(t); n   re(ts...); n } n template <class T> n void re(complex<T>& x) { n   T a, b; n   re(a, b); n   x = {a, b}; n } n template <class T1, class T2> n void re(pair<T1, T2>& p) { n   re(p.f, p.s); n } n template <class T> n void re(vector<T>& a) { n   for (int i = (0) - (1 - 2 * (0 > ((int)a.size())) < 0); n        (1 - 2 * (0 > ((int)a.size()))) > 0 ? i < (((int)a.size())) n                                            : i >= (((int)a.size())); n        i += (1 - 2 * (0 > ((int)a.size())))) n     re(a[i]); n } n template <class T, size_t SZ> n void re(array<T, SZ>& a) { n   for (int i = (0) - (1 - 2 * (0 > SZ) < 0); n        (1 - 2 * (0 > SZ)) > 0 ? i < (SZ) : i >= (SZ); i += (1 - 2 * (0 > SZ))) n     re(a[i]); n } n void pr(int x) { cout << x; } n void pr(long x) { cout << x; } n void pr(ll x) { cout << x; } n void pr(unsigned x) { cout << x; } n void pr(unsigned long x) { cout << x; } n void pr(unsigned long long x) { cout << x; } n void pr(float x) { cout << x; } n void pr(double x) { cout << x; } n void pr(ld x) { cout << x; } n void pr(char x) { cout << x; } n void pr(const char* x) { cout << x; } n void pr(const string& x) { cout << x; } n void pr(bool x) { pr(x ?  true  :  false ); } n template <class T> n void pr(const complex<T>& x) { n   cout << x; n } n template <class T1, class T2> n void pr(const pair<T1, T2>& x); n template <class T> n void pr(const T& x); n template <class T, class... Ts> n void pr(const T& t, const Ts&... ts) { n   pr(t); n   pr(ts...); n } n template <class T1, class T2> n void pr(const pair<T1, T2>& x) { n   pr( { , x.f,  ,  , x.s,  } ); n } n template <class T> n void pr(const T& x) { n   pr( { ); n   bool fst = 1; n   for (const auto& a : x) pr(!fst ?  ,   :   , a), fst = 0; n   pr( } ); n } n void ps() { pr(  n ); } n template <class T, class... Ts> n void ps(const T& t, const Ts&... ts) { n   pr(t); n   if (sizeof...(ts)) pr(   ); n   ps(ts...); n } n void pc() { pr( ] n ); } n template <class T, class... Ts> n void pc(const T& t, const Ts&... ts) { n   pr(t); n   if (sizeof...(ts)) pr( ,  ); n   pc(ts...); n } n }  // namespace io n using namespace io; n template <class T> n bool ckmin(T& a, const T& b) { n   return b < a ? a = b, 1 : 0; n } n template <class T> n bool ckmax(T& a, const T& b) { n   return a < b ? a = b, 1 : 0; n } n ll n; n unordered_map<ll, vector<int>> mp; n int find(int u, int v) { n   if (u == v) return mp[v].size(); n   int n = ((int)mp[u].size()), m = ((int)mp[v].size()); n   int i = 0, j = 0, ans = 1, last; n   bool cur = 0; n   if (mp[u][i] < mp[v][j]) { n     cur = 0; n     last = mp[u][i]; n     i++; n   } else { n     cur = 1; n     last = mp[v][j], j++; n   } n   while (i < n or j < m) { n     if (i == n) { n       if (cur == 0 and last < mp[v].back()) n         return ans + 1; n       else n         return ans; n     } else if (j == m) { n       if (cur == 1 and last < mp[u].back()) { n         return ans + 1; n       } else n         return ans; n     } else if (cur == 0) { n       while (j < m and mp[v][j] < last) j++; n       if (j < m) last = mp[v][j], ans++, j++, cur = 1; n     } else { n       while (i < n and mp[u][i] < last) i++; n       if (i < n) last = mp[u][i], ans++, i++, cur = 0; n     } n   } n   return ans; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(NULL); n   cout.tie(NULL); n   re(n); n   int a[n]; n   unordered_set<ll> st; n   for (int i = (0) - (1 - 2 * (0 > n) < 0); n        (1 - 2 * (0 > n)) > 0 ? i < (n) : i >= (n); i += (1 - 2 * (0 > n))) n     re(a[i]), mp[a[i]].push_back(i), st.insert(a[i]); n   int ans = 0; n   vector<int> ss; n   for (auto i : st) ss.push_back(i); n   for (int ii = (0) - (1 - 2 * (0 > ((int)ss.size())) < 0); n        (1 - 2 * (0 > ((int)ss.size()))) > 0 ? ii < (((int)ss.size())) n                                             : ii >= (((int)ss.size())); n        ii += (1 - 2 * (0 > ((int)ss.size())))) { n     for (int jj = (ii) - (1 - 2 * (ii > ((int)ss.size())) < 0); n          (1 - 2 * (ii > ((int)ss.size()))) > 0 ? jj < (((int)ss.size())) n                                                : jj >= (((int)ss.size())); n          jj += (1 - 2 * (ii > ((int)ss.size())))) { n       int i = ss[ii], j = ss[jj]; n       ckmax(ans, find(i, j)); n     } n   } n   ps(ans); n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 200005; n multiset<int> gr[maxn]; n vector<int> order, odd; n int n, m; n void go(int cur) { n   for (auto it = gr[cur].begin(); gr[cur].size() != 0; it = gr[cur].begin()) { n     int v = *it; n     gr[cur].erase(it); n     gr[v].erase(gr[v].find(cur)); n     go(v); n   } n   order.push_back(cur); n } n int main() { n   scanf( %d%d , &n, &m); n   for (int i = 0; i < m; i++) { n     int a, b; n     scanf( %d%d , &a, &b); n     a--, b--; n     gr[a].insert(b); n     gr[b].insert(a); n   } n   for (int i = 0; i < n; i++) n     if (gr[i].size() % 2 != 0) odd.push_back(i); n   for (int i = 0; i < (int)odd.size() / 2; i++) { n     gr[odd[2 * i]].insert(odd[2 * i + 1]); n     gr[odd[2 * i + 1]].insert(odd[2 * i]); n   } n   if ((odd.size() / 2 + m) % 2 == 1) { n     gr[0].insert(0); n     gr[0].insert(0); n   } n   go(0); n   printf( %d n , order.size() - 1); n   for (int i = 0; i < (int)order.size() - 1; i++) { n     if (i % 2 == 0) n       printf( %d %d n , order[i] + 1, order[i + 1] + 1); n     else n       printf( %d %d n , order[i + 1] + 1, order[i] + 1); n   } n   return 0; n } n


#include <iostream> n #include <iomanip> n #include <cstdio> n #include <vector> n #include <algorithm> n #include <cmath> n #include <cstring> n #include <cassert> n #include <string> n #include <set> n #include <map> n #include <random> n #include <bitset> n #include <string> n #include <unordered_set> n #include <unordered_map> n #include <deque> n #include <queue> n #define rep(i, n) for (int i = 0; i < (n); i++) n #define all(x) (x).begin(), (x).end() n #define rall(x) (x).rbegin(), (x).rend() n  n using namespace std; n using ll = long long; n using ul = unsigned long long; n using ld = long double; n  n const int MOD = 998244353, N = 100002; n ll f[N], rf[N]; n  n ll pw(ll x, ll k) { n   ll r = 1; n   while (k) { n     if (k & 1) n       r = r * x % MOD; n     x = x * x % MOD; n     k >>= 1; n   } n   return r; n } n  n ll c(ll n, ll k) { n   return f[n] * rf[k] % MOD * rf[n - k] % MOD; n } n  n int main() { n   ios_base::sync_with_stdio(0); cin.tie(0); n   f[0] = 1; n   for (int i = 1; i < N; ++i) n     f[i] = f[i - 1] * i % MOD; n   rf[N - 1] = pw(f[N - 1], MOD - 2); n   for (int i = N - 1; i > 0; --i) n     rf[i - 1] = rf[i] * i % MOD; n   int t, n; n   cin >> t; n   while (t--) { n     string s; n     cin >> n >> s; n     int l = 1, z = 0, g = 0; n     rep(i, n) n       if (s[i] ==  0 ) { n         z++; n         if (l == i % 2) n           g++; n         l = i % 2; n       } n     cout << c((n - z - g) / 2 + z, z) <<   n ; n   } n } n  n


#include <bits/stdc++.h> n using namespace std; n const int N = 5e6 + 50; n vector<int> v; n int vis[N] = {0}, n; n int flag[N] = {0}, ans = 0; n void dfs(int k) { n   if (vis[k]) return; n   vis[k] = 1; n   if (flag[k]) dfs(k ^ ((1 << n) - 1)); n   for (int i = 0; i < n; i++) n     if ((1 << i) & k) dfs(k ^ (1 << i)); n } n int main() { n   int m; n   scanf( %d %d , &n, &m); n   int temp; n   for (int i = 1; i <= m; i++) { n     scanf( %d , &temp); n     v.push_back(temp); n     flag[temp] = 1; n   } n   for (auto vv : v) { n     if (!vis[vv]) { n       ans++; n       vis[vv] = 1; n       dfs(vv ^ ((1 << n) - 1)); n     } n   } n   printf( %d n , ans); n } n


#include <bits/stdc++.h> n using namespace std; n int cnt[10]; n int main() { n   int n; n   while (scanf( %d , &n) != EOF) { n     int sum = 0; n     memset(cnt, 0, sizeof(cnt)); n     for (int i = 0; i < n; i++) { n       int j; n       scanf( %d , &j); n       cnt[j]++; n       sum += j; n     } n     int ans = -1; n     for (int i = 0; i <= n; i++) n       if (4 * i <= sum && (sum - 4 * i) % 3 == 0 && n           (sum - 4 * i) / 3 <= n - i) { n         int j = (sum - 4 * i) / 3; n         int cost = min(max(cnt[4] - i, 0), j); n         int p = cnt[1] + cnt[2] + cnt[3] + cnt[4]; n         for (int k = 1; k <= 4 && p > i + j; k++) { n           cost += min(p - i - j, cnt[k]) * k; n           p -= min(p - i - j, cnt[k]); n         } n         if (cost < ans || ans == -1) ans = cost; n       } n     printf( %d n , ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 100010; n struct node { n   int v, nxt; n } edge[maxn << 1]; n int first[maxn], tot = 0; n void add(int u, int v) { n   edge[++tot].v = v; n   edge[tot].nxt = first[u]; n   first[u] = tot; n } n int n, m; n double dp[maxn], p[maxn], ans = 0; n int f[maxn]; n void dfs(int u, int fa) { n   ans += (1.0 - p[u]) * p[fa]; n   for (int i = first[u]; i; i = edge[i].nxt) { n     int v = edge[i].v; n     if (v == fa) continue; n     dfs(v, u); n     f[v] = u; n     dp[u] += 1.0 - p[v]; n   } n } n int main() { n   scanf( %d , &n); n   p[0] = 1.0; n   for (int i = 1; i <= n; i++) scanf( %lf , &p[i]); n   for (int i = 1; i < n; i++) { n     int x, y; n     scanf( %d%d , &x, &y); n     x++, y++; n     add(x, y); n     add(y, x); n   } n   dfs(1, 0); n   scanf( %d , &m); n   while (m--) { n     int u; n     double pp; n     scanf( %d%lf , &u, &pp); n     u++; n     ans -= dp[u] * p[u] + (1.0 - p[u]) * p[f[u]]; n     dp[f[u]] -= 1.0 - p[u]; n     p[u] = pp; n     ans += dp[u] * p[u] + (1.0 - p[u]) * p[f[u]]; n     dp[f[u]] += 1.0 - p[u]; n     printf( %.5f n , ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   puts( INTERCAL ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void Ask(int x1, int y1, int x2, int y2, bool rot = false) { n   if (!rot) { n     cout <<  ?   << x1 <<     << y1 <<     << x2 <<     << y2 << endl; n   } else { n     cout <<  ?   << y1 <<     << x1 <<     << y2 <<     << x2 << endl; n   } n } n int Find(int n, bool rot) { n   int l = 1, r = n; n   while (l < r) { n     int m = (l + r) >> 1; n     Ask(1, 1, m, n, rot); n     int res; n     cin >> res; n     if (res == 0) { n       l = m + 1; n     } else { n       r = m; n     } n   } n   Ask(1, 1, l, n, rot); n   int res; n   cin >> res; n   if (res != 1) { n     return -1; n   } n   int v = l; n   ++l; n   r = n; n   while (l < r) { n     int m = (l + r) >> 1; n     Ask(l, 1, m, n, rot); n     int res; n     cin >> res; n     if (res == 0) { n       l = m + 1; n     } else { n       r = m; n     } n   } n   Ask(v + 1, 1, l, n, rot); n   cin >> res; n   if (res != 1) { n     return -1; n   } n   return v; n } n int FindR(int x1, int y1, int x2, int y2, bool rot) { n   int l = x1, r = x2; n   while (l < r) { n     int m = (l + r) >> 1; n     Ask(x1, y1, m, y2, rot); n     int res; n     cin >> res; n     if (res == 0) { n       l = m + 1; n     } else { n       r = m; n     } n   } n   return l; n } n int FindL(int x1, int y1, int x2, int y2, bool rot) { n   int l = x1, r = x2; n   while (l < r) { n     int m = (l + r + 1) >> 1; n     Ask(m, y1, x2, y2, rot); n     int res; n     cin >> res; n     if (res == 0) { n       r = m - 1; n     } else { n       l = m; n     } n   } n   return l; n } n int FindD(int x1, int y1, int x2, int y2, bool rot) { n   int l = y1, r = y2; n   while (l < r) { n     int m = (l + r) >> 1; n     Ask(x1, y1, x2, m, rot); n     int res; n     cin >> res; n     if (res == 0) { n       l = m + 1; n     } else { n       r = m; n     } n   } n   return l; n } n int FindU(int x1, int y1, int x2, int y2, bool rot) { n   int l = y1, r = y2; n   while (l < r) { n     int m = (l + r + 1) >> 1; n     Ask(x1, m, x2, y2, rot); n     int res; n     cin >> res; n     if (res == 0) { n       r = m - 1; n     } else { n       l = m; n     } n   } n   return l; n } n int main() { n   std::ios_base::sync_with_stdio(false); n   int n; n   cin >> n; n   bool rot = false; n   int line = Find(n, rot); n   if (line == -1) { n     rot = true; n     line = Find(n, rot); n   } n   int x11 = FindL(1, 1, line, n, rot); n   int x12 = FindR(1, 1, line, n, rot); n   int y11 = FindU(1, 1, line, n, rot); n   int y12 = FindD(1, 1, line, n, rot); n   int x21 = FindL(line + 1, 1, n, n, rot); n   int x22 = FindR(line + 1, 1, n, n, rot); n   int y21 = FindU(line + 1, 1, n, n, rot); n   int y22 = FindD(line + 1, 1, n, n, rot); n   if (rot) { n     swap(x11, y11); n     swap(x12, y12); n     swap(x21, y21); n     swap(x22, y22); n   } n   cout <<  !   << x11 <<     << y11 <<     << x12 <<     << y12; n   cout <<     << x21 <<     << y21 <<     << x22 <<     << y22 << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void solution() { n   int n, k, i, j, sum = 0; n   cin >> n >> k; n   string s; n   cin >> s; n   if (k == 2) { n     int c1 = 0, c2 = 0; n     for (i = 0; i < n; i++) { n       c1 += abs(s[i] - 65 - (i % 2)); n       c2 += abs(s[i] - 65 - (i + 1) % 2); n     } n     if (c1 < c2) { n       cout << c1 <<   n ; n       for (i = 0; i < n; i++) cout << (char)(65 + i % 2); n     } else { n       cout << c2 <<   n ; n       for (i = 0; i < n; i++) cout << (char)(65 + (i + 1) % 2); n     } n     return; n   } n   for (i = 0; i < n - 1; i++) { n     char c =  A ; n     if (s[i] == s[i + 1]) { n       sum++; n       while (s[i + 2] == c || s[i] == c) { n         c = (char)(c + 1); n       } n       s[i + 1] = c; n     } n   } n   cout << sum <<   n  << s; n } n int main() { n   std::ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   int t = 1; n   while (t--) { n     solution(); n   } n   cerr <<   n  << (float)clock() / CLOCKS_PER_SEC * 1000 <<   ms  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 1100; n const long long M = 260; n const long long mod = 998244353; n const long long MOD = 998244353; n const long double eps = 0.000000001; n const long long P = 1336; n const long long inf = 1e16; n mt19937 gen(chrono::high_resolution_clock::now().time_since_epoch().count()); n long long n, k; n vector<pair<long long, long long> > a; n long long dp[N][N]; n long long solve(long long x) { n   for (long long j = 0; j < k; j++) { n     for (long long i = 0; i < n; i++) { n       dp[j][i] = 0; n       if (j == 0) dp[j][i] = 1; n     } n   } n   long long ans = 0; n   for (long long j = 1; j < k; j++) { n     long long uk = 0, s = 0; n     for (long long i = 0; i < n; i++) { n       while (uk < n && a[uk].first + x <= a[i].first) { n         s += dp[j - 1][uk]; n         s %= mod; n         uk++; n       } n       dp[j][i] = s; n       if (j == k - 1) { n         ans += dp[j][i]; n         ans %= mod; n       } n     } n   } n   return ans; n } n int32_t main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   srand(time(0)); n   cin >> n >> k; n   a.resize(n); n   long long ma = 0; n   for (long long i = 0; i < n; i++) { n     cin >> a[i].first; n     ma = max(ma, a[i].first); n     a[i].second = i; n   } n   sort(a.begin(), a.end()); n   long long ans = 0, s = 0; n   for (long long i = ma / (k - 1); i >= 1; i--) { n     long long c = solve(i); n     c -= s; n     c += mod; n     c %= mod; n     s += c; n     s %= mod; n     c *= i; n     c %= mod; n     ans += c; n     ans %= mod; n   } n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n using ld = long double; n using uint = unsigned int; n using ull = unsigned long long; n template <typename T> n using pair2 = pair<T, T>; n using pii = pair<int, int>; n using pli = pair<ll, int>; n using pll = pair<ll, ll>; n mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); n inline void fmin(ll &x, ll y) { n   if (y < x) x = y; n } n inline void fmax(ll &x, ll y) { n   if (y > x) x = y; n } n double startTime; n double getCurrentTime() { n   return ((double)clock() - startTime) / CLOCKS_PER_SEC; n } n const ll INF = 0x3f3f3f3f3f3f3f3f; n const int N = 100100; n const int M = (1 << 7) + 7; n vector<int> a[N]; n int n, k, p; n int ppc[M]; n ll dp[2][M]; n int main() { n   for (int i = 0; i < M; i++) ppc[i] = ppc[i / 2] + (i & 1); n   scanf( %d%d%d , &n, &p, &k); n   for (int i = 0; i < n; i++) { n     a[i].resize(p + 1); n     scanf( %d , &a[i][0]); n   } n   for (int i = 0; i < n; i++) n     for (int j = 1; j <= p; j++) scanf( %d , &a[i][j]); n   sort(a, a + n); n   reverse(a, a + n); n   for (int mask = 0; mask < 1 << p; mask++) dp[0][mask] = -INF; n   dp[0][0] = 0; n   for (int i = 0; i < n; i++) { n     for (int mask = 0; mask < 1 << p; ++mask) dp[1][mask] = -INF; n     for (int mask = 0; mask < (1 << p); ++mask) { n       for (int j = 0; j < p; j++) { n         if (mask & (1 << j)) continue; n         fmax(dp[1][mask | (1 << j)], dp[0][mask] + a[i][j + 1]); n       } n       ll w = dp[0][mask]; n       if (ppc[mask] + k > i) w += a[i][0]; n       fmax(dp[1][mask], w); n     } n     for (int mask = 0; mask < (1 << p); ++mask) dp[0][mask] = dp[1][mask]; n   } n   printf( %lld n , dp[0][(1 << p) - 1]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> adj[200005]; n int sz[200005]; n int n, k; n long long int ans; n void dfs(int u, int p) { n   for (int v : adj[u]) { n     if (v == p) continue; n     dfs(v, u); n     sz[u] += sz[v]; n     ans += min(sz[v], 2 * k - sz[v]); n   } n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cin >> n >> k; n   for (int i = 0; i < 2 * k; i++) { n     int x; n     cin >> x; n     sz[x] = 1; n   } n   int u, v; n   for (int i = 0; i < n - 1; i++) { n     cin >> u >> v; n     adj[u].push_back(v); n     adj[v].push_back(u); n   } n   dfs(1, 0); n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int spf[5000002]; n int f[5000002]; n void init() { n   spf[0] = spf[1] = 1; n   for (int i = 2; i < 5000002; ++i) { n     if (spf[i] == 0) { n       spf[i] = i; n       long long int start = 1LL * i * i; n       for (long long int j = start; j < 5000002; j += i) { n         if (spf[j] == 0) spf[j] = i; n       } n     } n   } n   f[0] = f[1] = 0; n   for (int i = 2; i < 5000002; ++i) { n     int x = spf[i]; n     int y = i / x; n     long long int val = 1LL * y * x * (x - 1) / 2 + f[y]; n     f[i] = val % 1000000007; n   } n } n int main(void) { n   ios::sync_with_stdio(false); n   cin.tie(NULL); n   init(); n   int t, l, r; n   cin >> t >> l >> r; n   long long int ans = 0, mul = 1; n   for (int i = 0; i <= r - l; ++i) { n     ans = ans + (mul * f[i + l]) % 1000000007; n     mul = (mul * t) % 1000000007; n   } n   cout << ans % 1000000007 <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n map<int, int> mp; n long long mas[1000100]; n long long dmas[1000100]; n int main() { n   ios::sync_with_stdio(0); n   int n; n   cin >> n; n   long long x; n   long long ans = -100000000000000000; n   int ansl, ansr; n   for (int i = 0; i < n; ++i) { n     cin >> x; n     dmas[i] = x; n     if (x >= 0) mas[i] = x; n     if (i > 0) mas[i] += mas[i - 1]; n     if (mp.count(x) == 0) n       mp[x] = i; n     else { n       long long d = 0; n       if (x < 0) d = x * 2; n       ans = max(ans, mas[i] - mas[mp[x] - 1] + d); n       if (ans == mas[i] - mas[mp[x] - 1] + d) { n         ansl = mp[x]; n         ansr = i; n       } n     } n   } n   cout << ans <<    ; n   int c = 0; n   for (int i = 0; i < n; ++i) { n     if (i < ansl) n       ++c; n     else if (i > ansr) n       ++c; n     else if (i < ansr && i > ansl && dmas[i] < 0) n       ++c; n   } n   cout << c <<   n ; n   for (int i = 0; i < n; ++i) { n     if (i < ansl) n       cout << i + 1 <<    ; n     else if (i > ansr) n       cout << i + 1 <<    ; n     else if (i < ansr && i > ansl && dmas[i] < 0) n       cout << i + 1 <<    ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n using ld = long double; n using ull = unsigned long long; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int _; n   for (cin >> _; _--;) { n     int n, q; n     cin >> n >> q; n     string a; n     cin >> a; n     vector<int> p(n); n     p[0] = (a[0] ==  +  ? 1 : -1); n     for (int i = 1; i < n; i++) { n       if (i % 2) n         p[i] = p[i - 1] - (a[i] ==  +  ? 1 : -1); n       else n         p[i] = p[i - 1] + (a[i] ==  +  ? 1 : -1); n     } n     vector<int> s(n); n     s[n - 1] = (a[n - 1] ==  +  ? 1 : -1); n     for (int i = n - 2; i >= 0; i--) { n       if ((n - 1 - i) % 2) n         s[i] = s[i + 1] - (a[i] ==  +  ? 1 : -1); n       else n         s[i] = s[i + 1] + (a[i] ==  +  ? 1 : -1); n     } n     while (q--) { n       int l, r; n       cin >> l >> r; n       l--, r--; n       if (l == 0) { n         if (p[r] == 0) { n           cout <<  0 n ; n           continue; n         } n       } else { n         if (p[r] == p[l - 1]) { n           cout <<  0 n ; n           continue; n         } n       } n       int s1 = 0, s2 = 0; n       if (l == 0) n         s1 = p[r]; n       else { n         if (l % 2 == 0) { n           s1 = p[r] - p[l - 1]; n         } else { n           s1 = p[l - 1] - p[r]; n         } n       } n       if (r == n - 1) n         s2 = s[l]; n       else { n         if ((n - 1 - r) % 2 == 0) { n           s2 = s[l] - s[r + 1]; n         } else { n           s2 = s[r + 1] - s[l]; n         } n       } n       if (s1 == s2) { n         cout <<  1 n ; n       } else { n         cout <<  2 n ; n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MOD = 1000 * 1000 * 1000 + 7; n const int INF = 2000 * 1000 * 1000; n const double EPS = 1e-9; n const double pi = acos(-1.0); n const int maxn = 1010; n const int maxsum = 10010; n template <typename T> n inline T sqr(T n) { n   return (n * n); n } n int n, a[maxn], mem[maxn][2 * maxsum]; n int* dp[maxn]; n long long ans; n int main() { n   scanf( %d , &n); n   dp[0] = mem[0] + maxsum; n   for (int i = 1; i <= n; i++) { n     scanf( %d , &a[i]); n     dp[i] = mem[i] + maxsum; n   } n   dp[0][0] = 1; n   ans = 0; n   for (int i = 1; i <= n; i++) { n     for (int sum = -10000; sum <= 10000; sum++) { n       if (sum + a[i] <= 10000) dp[i][sum] += dp[i - 1][sum + a[i]]; n       if (sum - a[i] >= -10000) dp[i][sum] += dp[i - 1][sum - a[i]]; n       dp[i][sum] %= MOD; n     } n     ans += dp[i][0]; n     ans %= MOD; n     dp[i][0]++; n   } n   printf( %I64d , ans); n   return 0; n } n


#include <bits/stdc++.h> n const int mod = 1000000007; n using namespace std; n long long c[100005]; n int v[100005]; n set<int> s; n int n, k; n long long all, ans; n int main() { n   scanf( %d %d , &n, &k); n   for (int i = 1; i <= n; i++) scanf( %I64d , &c[i]); n   for (int i = 0; i < k; i++) scanf( %d , &v[i]); n   all = 0; n   ans = 0; n   for (int i = 1; i <= n; i++) all += c[i]; n   for (int i = 1; i < n; i++) ans += c[i] * c[i + 1]; n   ans += c[n] * c[1]; n   s.clear(); n   for (int i = 0; i < k; i++) { n     all -= c[v[i]]; n     s.insert(v[i]); n     long long tmp = all; n     if (v[i] < n && s.find(v[i] + 1) == s.end()) tmp -= c[v[i] + 1]; n     if (v[i] == n && s.find(1) == s.end()) tmp -= c[1]; n     if (v[i] > 1 && s.find(v[i] - 1) == s.end()) tmp -= c[v[i] - 1]; n     if (v[i] == 1 && s.find(n) == s.end()) tmp -= c[n]; n     ans += c[v[i]] * tmp; n   } n   printf( %I64d n , ans); n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = 1e9 + 1; n const int N = 200123; n int z, n, s; n deque<int> dq; n int t[N]; n int main() { n   ios_base::sync_with_stdio(0); n   int ans = 0; n   cin >> n >> s; n   for (int i = 0; i < n; i++) { n     cin >> t[i]; n     if (i + 1 == s) { n       ans += (t[i] != 0); n       n--; n       i--; n       s = inf; n     } else if (t[i] == 0) n       t[i] = n + 5; n   } n   sort(t, t + n); n   for (int i = 0; i < n; i++) { n     dq.push_back(t[i]); n   } n   int nxt = 1; n   while (dq.size()) { n     while (dq.size() && nxt < dq.front()) { n       dq.pop_back(); n       nxt++; n       ans++; n     } n     if (dq.size()) { n       nxt = max(nxt, dq.front() + 1); n       dq.pop_front(); n     } n   } n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, s, idx; n   cin >> n >> s; n   s--; n   int a[n], b[n]; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n   } n   for (int i = 0; i < n; i++) { n     cin >> b[i]; n   } n   if (a[0] == 1) { n     for (int i = 0; i < n; i++) { n       if (i == s && a[i] == 1) { n         cout <<  YES ; n         return 0; n       } else if (i > s && a[i] == 1 && b[i] == 1) { n         for (int j = i; j >= 0; j--) { n           if (j == s && b[j] == 1) { n             cout <<  YES ; n             return 0; n           } n         } n       } n     } n   } n   cout <<  NO ; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   int a[n + 1]; n   int ans = 1; n   for (int i = 0; i < n; i++) cin >> a[i]; n   for (int i = 0; i < n; i++) { n     int m = 1; n     for (int j = i; j < n - 1 and a[j] >= a[j + 1]; j++) m++; n     for (int j = i; j > 0 and a[j] >= a[j - 1]; j--) m++; n     ans = max(ans, m); n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int t; n   cin >> t; n   while (t--) { n     int s, n; n     cin >> s >> n; n     int temp = s, p = 1; n     while (temp > 0) { n       temp /= 10; n       p *= 10; n     } n     p /= 10; n     while (n > 1) { n       if (s - p >= n - 1) { n         cout << p <<    ; n         s -= p; n         n--; n       } else n         p /= 10; n     } n     cout << s << endl; n   } n } n


#include <bits/stdc++.h> n const double PI = 3.141592653589793238463; n using namespace std; n inline long long add(long long a, long long b) { n   a += b; n   if (a >= 1000000007) a -= 1000000007; n   return a; n } n inline long long sub(long long a, long long b) { n   a -= b; n   if (a < 0) a += 1000000007; n   return a; n } n inline long long mul(long long a, long long b) { n   return (long long)((long long)a * b % 1000000007); n } n long long fast_power(long long base, long long power) { n   long long result = 1; n   while (power > 0) { n     if (power % 2 == 1) { n       result = (result * base) % 1000000007; n     } n     base = (base * base) % 1000000007; n     power = power / 2; n   } n   return result; n } n long long min(long long a, long long b) { return a > b ? b : a; } n long long max(long long a, long long b) { return a > b ? a : b; } n void dfs(long long s, vector<vector<long long>> &adj, vector<bool> &vis, n          vector<long long> &arr) { n   if (vis[s]) return; n   vis[s] = true; n   arr.push_back(s); n   for (auto x : adj[s]) { n     if (vis[x] == false) { n       dfs(x, adj, vis, arr); n     } n   } n } n void bfs(long long x, vector<bool> &vis, vector<vector<long long>> &adlist, n          vector<long long> &level, vector<long long> &parent) { n   queue<long long> q; n   vis[x] = true; n   q.push(x); n   while (!q.empty()) { n     long long s = q.front(); n     q.pop(); n     for (auto u : adlist[s]) { n       if (vis[u]) continue; n       vis[u] = true; n       parent[u] = s; n       level[u] = level[s] + 1; n       q.push(u); n     } n   } n } n bool bpchk(vector<vector<long long>> &adj, vector<long long> &color) { n   color[1] = 1; n   queue<long long> q; n   q.push(1); n   while (!q.empty()) { n     long long u = q.front(); n     q.pop(); n     for (auto x : adj[u]) { n       if (color[x] == -1) { n         color[x] = color[u] ^ 1; n         q.push(x); n       } n     } n   } n   for (long long i = 1; i < adj.size(); i++) { n     for (auto x : adj[i]) { n       if (color[x] == color[i]) return false; n     } n   } n   return true; n } n void swap(long long *a, long long *b) { n   long long tmp = *a; n   *a = *b; n   *b = tmp; n } n void SieveOfEratosthenes(long long n, set<long long> &s) { n   vector<bool> prime(n + 1, true); n   for (long long p = 2; p * p <= n; p++) { n     if (prime[p] == true) { n       for (long long i = p * p; i <= n; i += p) prime[i] = false; n     } n   } n   for (long long p = 2; p <= n; p++) n     if (prime[p]) s.insert(p); n } n vector<long long> r(1000, 0), c(1000, 0); n vector<long long> rsum(1e6 + 1, 0), csum(1e6 + 1, 0); n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long n, m, k, p; n   cin >> n >> m >> k >> p; n   long long temp; n   for (long long i = 0; i < n; i++) { n     for (long long j = 0; j < m; j++) { n       cin >> temp; n       r[i] += temp; n       c[j] += temp; n     } n   } n   priority_queue<long long> rs, cs; n   for (long long i = 0; i < n; i++) { n     rs.push(r[i]); n   } n   for (long long i = 0; i < m; i++) { n     cs.push(c[i]); n   } n   for (long long i = 1; i <= k; i++) { n     rsum[i] = rs.top() + rsum[i - 1]; n     temp = rs.top(); n     rs.pop(); n     temp -= m * p; n     rs.push(temp); n     csum[i] = cs.top() + csum[i - 1]; n     temp = cs.top(); n     cs.pop(); n     temp -= n * p; n     cs.push(temp); n   } n   long long ans = LLONG_MIN; n   for (long long i = 0; i <= k; i++) { n     ans = max(ans, rsum[i] + csum[k - i] - i * (k - i) * p); n   } n   cout << ans <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 150005; n const int INF = 0x3f3f3f3f, MOD = 1e9 + 7; n const double pi = 3.14159265359; n int n, t[maxn], ans, cnt; n vector<int> v, vp; n inline bool check(const vector<int> &vt) { n   for (const int &i : vt) { n     if (i == 0) { n       if (t[i] >= t[i + 1]) n         return false; n       else n         continue; n     } else if (i == n - 1) { n       if (i % 2 == 0 && t[i] >= t[i - 1]) n         return false; n       else if (i % 2 == 1 && t[i] <= t[i - 1]) n         return false; n       else n         continue; n     } else if (i % 2 == 1 && (t[i] <= t[i - 1] || t[i] <= t[i + 1])) n       return false; n     else if (i % 2 == 0 && (t[i] >= t[i - 1] || t[i] >= t[i + 1])) n       return false; n   } n   return true; n } n int main() { n   scanf( %d , &n); n   for (int i = 0; i < n; i++) scanf( %d , &t[i]); n   if (t[0] < t[1]) n     vp.push_back(0); n   else { n     cnt++; n     v.push_back(0); n   } n   if ((n - 1) % 2 == 0 && t[n - 1] < t[n - 2]) n     vp.push_back(n - 1); n   else if ((n - 1) % 2 == 1 && t[n - 1] > t[n - 2]) n     vp.push_back(n - 1); n   else { n     cnt++; n     v.push_back(n - 1); n   } n   for (int i = int(1); i < int(n - 1); i++) { n     if (i % 2 == 0 && t[i] < t[i - 1] && t[i] < t[i + 1]) n       vp.push_back(i); n     else if (i % 2 == 1 && t[i] > t[i - 1] && t[i] > t[i + 1]) n       vp.push_back(i); n     else { n       cnt++; n       v.push_back(i); n     } n   } n   if (v.size() > 6) { n     printf( %d n , 0); n     exit(0); n   } n   for (int i = 0; i < v.size() - 1; i++) { n     for (int j = int(i + 1); j < int(v.size()); j++) { n       swap(t[v[i]], t[v[j]]); n       if (check(v)) ans++; n       swap(t[v[i]], t[v[j]]); n     } n   } n   for (const int &i : v) { n     for (const int &j : vp) { n       swap(t[i], t[j]); n       vector<int> vt(v); n       vt.push_back(j); n       if (check(vt)) ans++; n       swap(t[i], t[j]); n     } n   } n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   cin >> t; n   while (t--) { n     long long int n, i, j, k, l = 0, s, x, y, z = 0, r = 1000000001, rr = 0; n     cin >> n >> s >> k; n     long long int a[k]; n     for (i = 0; i < k; i++) cin >> a[i]; n     sort(a, a + k); n     for (i = 0; i < k; i++) { n       if (a[i] == s) z = 1; n     } n     if (z == 0) n       cout <<  0  << endl; n     else if (z == 1 && k == 1) n       cout <<  1  << endl; n     else { n       if (a[0] != 1) { n         r = std::min(r, s - (a[0] - 1)); n         r = std::min(r, s - 1); n       } n       if (a[k - 1] != n) { n         r = std::min(r, (a[k - 1] + 1) - s); n         r = std::min(r, n - s); n       } n       for (i = 0; i < k - 1; i++) { n         if ((a[i + 1] - a[i]) > 1) { n           rr = a[i + 1] - 1; n           if (a[i] >= s) { n             rr = a[i] + 1; n             r = std::min(r, (rr - s)); n           } else if (a[i + 1] <= s) { n             rr = a[i + 1] - 1; n             r = std::min(r, (s - rr)); n           } n         } n       } n       cout << r << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T, typename F> n class SegTree { n   int n; n   T uni; n   F f; n   vector<T> dat; n  n  public: n   SegTree(int _n, F f, T uni) : f(f), uni(uni) { n     n = 1; n     while (n < _n) n *= 2; n     dat = vector<T>(2 * n, uni); n   } n   void set(int k, const T x) { dat[k + n] = x; } n   void build() { n     for (int i = n - 1; i >= 0; i--) { n       dat[i] = f(dat[2 * i], dat[2 * i + 1]); n     } n   } n   void update(int k, T x) { n     k += n; n     dat[k] = x; n     while (k >>= 1) { n       dat[k] = f(dat[2 * k], dat[2 * k + 1]); n     } n   } n   T query(int a, int b) { n     T l = uni, r = uni; n     for (a += n, b += n; a < b; a >>= 1, b >>= 1) { n       if (a & 1) l = f(l, dat[a++]); n       if (b & 1) r = f(dat[--b], r); n     } n     return f(l, r); n   } n }; n int main() { n   int n, k, d; n   scanf( %d %d %d , &n, &k, &d); n   int a[n]; n   for (int i = 0; i < (int)n; i++) scanf( %d , &a[i]); n   sort(a, a + n); n   auto f = [](int a, int b) { return a + b; }; n   SegTree<int, decltype(f)> st(n + 1, f, 0); n   st.update(0, 1); n   for (int i = 0; i < (int)n; i++) { n     int l = lower_bound(a, a + n, a[i] - d) - a; n     int r = max(0, i - k + 2); n     if (st.query(l, r) > 0) st.update(i + 1, 1); n   } n   cout << (st.query(n, n + 1) ?  YES  :  NO ) << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, w, s, a[110]; n int in[110], out[110]; n int main() { n   scanf( %d%d , &n, &w); n   for (int i = 0; i < n; i++) { n     scanf( %d , &a[i]); n     s += a[i]; n   } n   if (n == 1 && w == a[0]) { n     puts( Yes ); n     for (int i = 0; i < w * 2; i++) { n       printf( 1  ); n     } n   } else if (n >= 2 && w >= 2 && w <= s) { n     in[0] = a[0] - 1; n     in[1] = a[1] - 1; n     for (int i = 2; i < n; i++) { n       in[i] = a[i]; n     } n     for (int i = 0; i < n; i++) { n       int x = min(w - 2, in[i]); n       in[i] -= x; n       out[i] += x; n       w -= x; n     } n     puts( Yes ); n     for (int i = 0; i < n; i++) { n       for (int j = 0; j < out[i] * 2; j++) { n         printf( %d  , i + 1); n       } n     } n     printf( 1  ); n     for (int i = 1; i < n; i++) { n       for (int j = 0; j < in[i] * 2; j++) { n         printf( %d  , i + 1); n       } n     } n     printf( 1 2  ); n     for (int i = 0; i < in[0] * 2; i++) { n       printf( 1  ); n     } n     puts( 2 ); n   } else if (n >= 2 && w == 1) { n     int k = 0; n     while (k < n && a[k] != 1) { n       k++; n     } n     if (k == n) { n       puts( No ); n     } else { n       puts( Yes ); n       printf( %d  , k + 1); n       for (int i = 0; i < n; i++) { n         if (i == k) { n           continue; n         } n         for (int j = 0; j < a[i] * 2; j++) { n           printf( %d  , i + 1); n         } n       } n       printf( %d n , k + 1); n     } n   } else { n     puts( No ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   char ar[1002][1002]; n   int n, m, i, j, count, ar1[1002]; n   scanf( %d%d , &n, &m); n   for (i = 0; i < n; i++) { n     scanf( %s , ar[i]); n   } n   for (i = 0; i < m; i++) { n     ar1[i] = 1; n   } n   for (i = 1; i < n; i++) { n     for (j = 0; j < m; j++) { n       if (ar1[j] == 1) { n         if (ar[i][j] < ar[i - 1][j]) { n           ar1[j] = 0; n           i = 0; n           break; n         } n         if (ar[i][j] > ar[i - 1][j]) { n           break; n         } n       } n     } n   } n   count = 0; n   for (i = 0; i < m; i++) { n     count += 1 - ar1[i]; n   } n   printf( %d n , count); n   return 0; n } n


#include <bits/stdc++.h> n template <class T> n inline bool rd(T &ret) { n   char c; n   int sgn; n   if (c = getchar(), c == EOF) return 0; n   while (c !=  -  && (c <  0  || c >  9 )) c = getchar(); n   sgn = (c ==  - ) ? -1 : 1; n   ret = (c ==  - ) ? 0 : (c -  0 ); n   while (c = getchar(), c >=  0  && c <=  9 ) ret = ret * 10 + (c -  0 ); n   ret *= sgn; n   return 1; n } n template <class T> n inline void pt(T x) { n   if (x < 0) { n     putchar( - ); n     x = -x; n   } n   if (x > 9) pt(x / 10); n   putchar(x % 10 +  0 ); n } n using namespace std; n const long long N = 200050; n long long n, m; n struct node { n   long long op, l, r, num, id; n } a[N * 2]; n bool cmp(node x, node y) { n   if (x.r != y.r) return x.r < y.r; n   if (x.op != y.op) return x.op < y.op; n } n long long top, b[N]; n void input() { n   top = 0; n   for (long long i = 1; i <= n; i++) { n     rd(a[top].l); n     rd(a[top].r); n     a[top].op = 0; n     a[top].id = i; n     top++; n   } n   rd(m); n   for (long long i = 1; i <= m; i++) { n     rd(a[top].l); n     rd(a[top].r); n     rd(a[top].num); n     a[top].op = 1; n     a[top].id = i; n     top++; n   } n   sort(a, a + top, cmp); n } n struct Edge { n   long long id, l; n   bool operator<(const Edge &e) const { n     if (e.l != l) return e.l > l; n     return e.id > id; n   } n   Edge(long long a = 0, long long b = 0) : id(a), l(b) {} n } tmp; n set<Edge> s; n set<Edge>::iterator p; n int main() { n   while (cin >> n) { n     input(); n     long long ans = 0; n     s.clear(); n     for (long long i = 0; i < top; i++) { n       if (a[i].op) { n         while (s.size() && a[i].num--) { n           p = s.lower_bound(Edge(0, a[i].l)); n           if (p == s.end()) break; n           tmp = *p; n           b[tmp.id] = a[i].id; n           s.erase(p); n           ans++; n         } n       } else { n         s.insert(Edge(a[i].id, a[i].l)); n       } n     } n     if (ans == n) { n       puts( YES ); n       for (long long i = 1; i <= n; i++) { n         pt(b[i]); n         putchar(   ); n       } n     } else n       puts( NO ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long mod = 1000000007; n int clean(vector<pair<int, int> > &I) { n   for (int i = 0; i < (int)I.size(); i++) { n     swap(I[i].first, I[i].second); n     I[i].second *= -1; n   } n   sort(begin(I), end(I)); n   for (int i = 0; i < (int)I.size(); i++) { n     I[i].second *= -1; n     swap(I[i].first, I[i].second); n   } n   vector<pair<int, int> > I_nw; n   int lastb = -1; n   for (int i = 0; i < (int)I.size(); i++) { n     if (lastb < I[i].first) I_nw.push_back(I[i]); n     lastb = max(lastb, I[i].first); n   } n   I = I_nw; n   return I_nw.size(); n } n long long pw(long long a, long long e, long long mod) { n   if (e <= 0) return 1; n   long long x = pw(a, e / 2, mod); n   x = (x * x) % mod; n   if (e % 2) x = (x * a) % mod; n   return x; n } n int main() { n   cin.sync_with_stdio(0); n   cin.tie(0); n   cout << fixed << setprecision(10); n   int K, N[2]; n   cin >> K >> N[0] >> N[1]; n   vector<pair<int, int> > I[2]; n   map<int, int> M; n   M[0] = M[K] = 0; n   for (int k = 0; k < 2; k++) { n     I[k].resize(N[k]); n     for (int i = 0; i < N[k]; i++) { n       cin >> I[k][i].first >> I[k][i].second; n       I[k][i].first--; n     } n     N[k] = clean(I[k]); n     for (int i = 0; i < N[k]; i++) M[I[k][i].first] = M[I[k][i].second] = 0; n   } n   int m = 0, last = 0; n   vector<int> len; n   vector<long long> cnt; n   for (auto it = M.begin(); it != M.end(); it++) { n     it->second = m++; n     if (it->first != last) len.push_back(it->first - last); n     last = it->first; n   } n   int L = len.size(); n   cnt.resize(L); n   for (int i = 0; i < L; i++) cnt[i] = (pw(2, len[i], mod) + mod - 2) % mod; n   for (int k = 0; k < 2; k++) n     for (int i = 0; i < N[k]; i++) { n       I[k][i].first = M[I[k][i].first]; n       I[k][i].second = M[I[k][i].second]; n     } n   vector<long long> ans[3]; n   for (int k = 0; k < 3; k++) ans[k].resize(L + 1, 0); n   ans[2][0] = 1; n   vector<long long> sum_ans[3]; n   for (int k = 0; k < 3; k++) sum_ans[k].resize(L + 1, 0); n   int pos[2] = {0, 0}, last_st[2] = {-1, -1}; n   for (int i = 0; i < L; i++) { n     for (int k = 0; k < 3; k++) n       sum_ans[k][i + 1] = (sum_ans[k][i] + ans[k][i]) % mod; n     ans[2][i + 1] = (ans[0][i] + ans[1][i] + ans[2][i]) * cnt[i] % mod; n     for (int k = 0; k < 2; k++) { n       while (pos[1 - k] < N[1 - k] && I[1 - k][pos[1 - k]].second <= i + 1) { n         last_st[1 - k] = I[1 - k][pos[1 - k]].first; n         pos[1 - k]++; n       } n       ans[k][i + 1] = n           (sum_ans[2][i + 1] - sum_ans[2][last_st[1 - k] + 1] + n            sum_ans[1 - k][i + 1] - sum_ans[1 - k][last_st[1 - k] + 1]) % n           mod; n     } n   } n   long long ansF = (ans[0][L] + ans[1][L] + ans[2][L]) % mod; n   if (ansF < 0) ansF += mod; n   cout << ansF <<   n ; n   return 0; n } n


#include<bits/stdc++.h> n using namespace std; n const int maxn = 1e6 + 50; n #define int long long n #define ll long long n #define pb push_back n #define mp make_pair n #define debug(a) cout << #a <<     << a <<   n ; n #define debug2(a , b) cout << #a <<     << a <<   ||   << #b <<     << b <<   n ; n #define ye cout <<  YES n  n #define no cout <<  NO n  n #define cn cout <<   n   n const int mod = 1e9 + 7; n using namespace std; n  n int a[maxn]; n signed main()  n { n  ios::sync_with_stdio(false); n  cin.tie(0); n  cout.tie(0);  n  int t; n  cin >> t; n  while(t --){ n   int n , k; n   cin >> n >> k; n   for(int i = 1 ; i <= n ; i ++) cin >> a[i]; n   if(k == 0){ n    cout << n <<   n ; n    continue; n   } n   sort(a + 1 , a + 1 + n); n   int ok = 1; n   for(int i = 1 ; i <= n ; i ++){ n    if(a[i] != i - 1) { n     ok = 0; n     break; n    } n   } n   if(ok){ n    cout << n + k <<   n ; n    continue; n   } n   int ans = n; n   int one = -1; n   if(a[1] != 0)one = 0; n   else{ n    for(int i = 1 ; i <= n ; i ++){ n     if(a[i] - a[i - 1] > 1){ n      one = a[i - 1] + 1; n      break; n     } n    } n   } n   if(one == -1) one = a[n] + 1; n   //debug(one) n   one = ((one + a[n]) % 2 == 0 ? (one + a[n]) / 2 : (one + a[n] + 1) / 2); n   ans ++; n   //debug(one) n   for(int i = 1 ; i <= n ; i ++){ n    if(a[i] > one) break; n    if(one == a[i]){ n     ans --; n     break;  n    } n   } n   cout << ans <<   n ; n  }  n  return 0;  n } n /* n  n 0 1 2 n 0 1 2 3 n  n */


#include <bits/stdc++.h> n using namespace std; n const long long MX = 1e2 + 5; n vector<long long> g[MX]; n long long vis[2][MX], ways[2][MX], dist[2][MX]; n void bfs(long long x, long long idx) { n   vis[idx][x] = 1; n   queue<long long> q; n   q.push(x); n   ways[idx][x] = 1; n   while (!q.empty()) { n     long long node = q.front(); n     q.pop(); n     for (auto it : g[node]) { n       if (!vis[idx][it]) { n         dist[idx][it] = dist[idx][node] + 1; n         vis[idx][it] = 1; n         ways[idx][it] += ways[idx][node]; n         q.push(it); n       } else { n         if (dist[idx][node] + 1 == dist[idx][it]) n           ways[idx][it] += ways[idx][node]; n       } n     } n   } n } n int32_t main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   ; n   long long n, m; n   cin >> n >> m; n   for (long long i = 0; i < m; i++) { n     long long x, y; n     cin >> x >> y; n     g[x].push_back(y); n     g[y].push_back(x); n   } n   bfs(1, 0); n   bfs(n, 1); n   long long mx = -1; n   for (long long i = 1; i <= n; i++) { n     if (dist[0][i] + dist[1][i] != dist[0][n]) continue; n     long long cur = ways[0][i] * ways[1][i]; n     if (i != 1 and i != n) cur *= 2; n     mx = max(mx, cur); n   } n   long double ans = (long double)mx / ways[0][n]; n   cout << fixed << setprecision(12) << ans <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long x, y, z, t1, t2, t3; n   cin >> x >> y >> z >> t1 >> t2 >> t3; n   if (abs(x - y) * t2 + t3 * 3 + t2 * abs(z - x) <= abs(x - y) * t1) n     cout <<  YES ; n   else n     cout <<  No ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a[156], T, n, k, ans, lw, que[100]; n int main() { n   int T; n   cin >> T; n   while (T--) { n     cin >> k; n     lw = 0; n     for (int i = 1; i <= 7; i++) { n       cin >> a[i]; n       a[i + 7] = a[i]; n       lw += a[i]; n     } n     int n = k / lw; n     if (k % lw == 0) { n       int maxx = 0, ll = 0; n       for (int i = 1; i <= 14; i++) { n         if (a[i] == 0) { n           ll++; n           maxx = max(maxx, ll); n         } else n           ll = 0; n       } n       ans = n * 7 - maxx; n     } else { n       int yu = k % lw, front = 0, ll = 0, minn = 1000; n       queue<int> q; n       while (!q.empty()) q.pop(); n       for (int i = 1; i <= 14; i++) { n         if (a[i] == 0) continue; n         if (a[i] == 1) { n           ll++; n           q.push(i); n           if (ll >= yu) { n             front = q.front(); n             q.pop(); n             minn = min(i - front + 1, minn); n           } n         } n       } n       ans = n * 7 + minn; n     } n     cout << ans << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 1000 * 1000 * 1000; n const double EPS = 1e-9; n const double PI = 2 * acos(0.); n const int N = 10; n const int dx[] = {-2, -1, 1, 2, 2, 1, -1, -2}; n const int dy[] = {-1, -2, -2, -1, 1, 2, 2, 1}; n char a[N][N]; n bool r[N]; n int main() { n   int ans = 0; n   for (int i = 0; i < int(8); ++i) { n     for (int j = 0; j < int(8); ++j) scanf( %c , &a[i][j]); n     scanf(  n ); n   } n   for (int i = 0; i < int(8); ++i) { n     bool flag = true; n     for (int j = 0; j < int(8); ++j) n       if (a[i][j] !=  B ) { n         flag = false; n         break; n       } n     if (flag) { n       r[i] = true; n       ++ans; n     } n   } n   for (int j = 0; j < int(8); ++j) { n     bool flag = false; n     for (int i = 0; i < int(8); ++i) n       if (a[i][j] ==  B  && !r[i]) { n         flag = true; n         break; n       } n     if (flag) ++ans; n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( Ofast,no-stack-protector ) n #pragma GCC optimize( unroll-loops ) n using namespace std; n const int BLK = 320; n const int MXN = 1e5 + 5; n const int MOD = 998244353; n int add(int x, int y) { return (x += y) < MOD ? x : x - MOD; } n int sub(int x, int y) { return (x -= y) >= 00 ? x : x + MOD; } n int b[BLK]; n int q[BLK][2 * BLK + 5]; n int n, k; n int d[MXN]; n int dp[MXN]; n int arr[MXN]; n int last1[MXN]; n int last2[MXN]; n void add(int pos) { n   int id = (pos - 1) / BLK; n   for (int i = BLK; i <= 2 * BLK; ++i) { n     q[id][i] = add(q[id][i], dp[pos - 1]); n   } n } n void update(int pos, int sgn) { n   int id = (pos - 1) / BLK; n   b[id] += sgn; n   for (int i = pos; i > id * BLK; --i) { n     if (sgn == +1) q[id][d[i] + BLK] = sub(q[id][d[i] + BLK], dp[i - 1]); n     d[i] += sgn; n     if (sgn == -2) { n       q[id][d[i] + BLK] = add(q[id][d[i] + BLK], dp[i - 1]), n                    q[id][d[i] + BLK + 1] = n                        add(q[id][d[i] + BLK + 1], dp[i - 1]); n     } n   } n } n int get(int pos) { n   int ret = 0; n   int id = (pos - 1) / BLK; n   for (int i = pos; i > id * BLK; --i) { n     if (d[i] <= k) ret = add(ret, dp[i - 1]); n   } n   int sum = b[id]; n   while (--id >= 0) { n     if (abs(sum - k) <= BLK) { n       ret = add(ret, q[id][k - sum + BLK]); n     } else if (sum < k) { n       ret = add(ret, q[id][BLK + BLK]); n     } n     sum += b[id]; n   } n   return ret; n } n int main() { n   ios::sync_with_stdio(0), cin.tie(0); n   dp[0] = 1; n   cin >> n >> k; n   for (int i = 1; i <= n; ++i) { n     cin >> arr[i]; n     add(i); n     update(i, 1); n     if (last1[arr[i]]) update(last1[arr[i]], -2); n     if (last2[arr[i]]) update(last2[arr[i]], +1); n     dp[i] = get(i); n     last2[arr[i]] = last1[arr[i]]; n     last1[arr[i]] = i; n   } n   cout << dp[n] <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n const int SIGMA_SIZE = 26; n const int MAXNODE = 1000010; n struct AhoCorasickAutomata { n   int ch[MAXNODE][SIGMA_SIZE]; n   int f[MAXNODE]; n   int match[MAXNODE]; n   int mp[MAXNODE]; n   int sz; n   void init() { sz = 1; } n   int idx(char c) { n     if (c <=  z  && c >=  a ) n       return c -  a ; n     else n       return 0; n   } n   void insert(char *s, int v) { n     int u = 0, n = strlen(s); n     for (int i = 0; i < n; i++) { n       int c = idx(s[i]); n       if (!ch[u][c]) { n         ch[u][c] = sz++; n       } n       u = ch[u][c]; n     } n     match[u] = 1; n     mp[v] = u; n   } n   void getFail() { n     queue<int> q; n     f[0] = 0; n     for (int c = 0; c < SIGMA_SIZE; c++) { n       int u = ch[0][c]; n       if (u) { n         f[u] = 0; n         q.push(u); n       } n     } n     while (!q.empty()) { n       int r = q.front(); n       q.pop(); n       for (int c = 0; c < SIGMA_SIZE; c++) { n         int u = ch[r][c]; n         if (!u) { n           ch[r][c] = ch[f[r]][c]; n           continue; n         } n         q.push(u); n         int v = f[r]; n         while (v && !ch[v][c]) v = f[v]; n         f[u] = ch[v][c]; n       } n     } n   } n }; n AhoCorasickAutomata ac; n vector<int> edge[MAXNODE]; n char str[MAXNODE]; n bool flag[MAXNODE]; n int L[MAXNODE]; n int R[MAXNODE]; n int tot; n struct node { n   int l, r; n }; n struct Segtree { n   int add[MAXNODE << 2], sum[MAXNODE << 2]; n   node seg[MAXNODE << 2]; n   void build(int o, int l, int r) { n     seg[o].l = l, seg[o].r = r; n     if (l == r) return; n     int m = (l + r) >> 1; n     build(o << 1, l, m); n     build(o << 1 | 1, m + 1, r); n   } n   void pushdown(int o) { n     if (add[o]) { n       int len = seg[o].r - seg[o].l + 1; n       add[o << 1] += add[o]; n       add[o << 1 | 1] += add[o]; n       sum[o << 1] += add[o] * (seg[o << 1].r - seg[o << 1].l + 1); n       sum[o << 1 | 1] += add[o] * (seg[o << 1 | 1].r - seg[o << 1 | 1].l + 1); n       add[o] = 0; n     } n   } n   void pushup(int o) { sum[o] = sum[o << 1] + sum[o << 1 | 1]; } n   void update(int o, int l, int r, int val) { n     if (l <= seg[o].l && seg[o].r <= r) { n       add[o] += val; n       sum[o] += val; n       return; n     } n     pushdown(o); n     int m = (seg[o].l + seg[o].r) >> 1; n     if (l <= m) update(o << 1, l, r, val); n     if (r > m) update(o << 1 | 1, l, r, val); n     pushup(o); n   } n   int query(int o, int pos) { n     if (seg[o].l == seg[o].r) return sum[o]; n     pushdown(o); n     int m = (seg[o].l + seg[o].r) >> 1; n     if (pos <= m) return query(o << 1, pos); n     if (pos > m) return query(o << 1 | 1, pos); n   } n } tree; n void dfs(int u) { n   L[u] = ++tot; n   for (int i = 0; i < edge[u].size(); i++) { n     int v = edge[u][i]; n     dfs(v); n   } n   R[u] = tot; n } n int main() { n   ios::sync_with_stdio(false); n   int n, k; n   while (cin >> n >> k) { n     ac.init(); n     for (int i = 0; i < k; i++) { n       cin >> str; n       ac.insert(str, i + 1); n     } n     ac.getFail(); n     memset(flag, 1, sizeof(flag)); n     for (int i = 1; i <= ac.sz; i++) edge[ac.f[i]].push_back(i); n     dfs(0); n     tree.build(1, 1, ac.sz); n     for (int i = 1; i <= ac.sz; i++) { n       if (ac.match[i]) { n         tree.update(1, L[i], R[i], 1); n       } n     } n     while (n--) { n       cin >> str; n       int len = strlen(str); n       if (str[0] ==  ? ) { n         int u = 0, ans = 0; n         for (int i = 1; i < len; i++) { n           int c = ac.idx(str[i]); n           u = ac.ch[u][c]; n           ans += tree.query(1, L[u]); n         } n         cout << ans << endl; n       } n       if (str[0] ==  + ) { n         int num = 0; n         for (int i = 1; i < len; i++) { n           num = num * 10 + str[i] -  0 ; n         } n         if (flag[num]) continue; n         flag[num] = 1; n         tree.update(1, L[ac.mp[num]], R[ac.mp[num]], 1); n       } n       if (str[0] ==  - ) { n         int num = 0; n         for (int i = 1; i < len; i++) { n           num = num * 10 + str[i] -  0 ; n         } n         if (!flag[num]) continue; n         flag[num] = 0; n         tree.update(1, L[ac.mp[num]], R[ac.mp[num]], -1); n       } n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long Gcd(long long a, long long b) { n   if (a % b == 0) return b; n   return Gcd(b, a % b); n } n long long Max(long long a, long long b) { n   if (a > b) return a; n   return b; n } n long long Min(long long a, long long b) { n   if (a < b) return a; n   return b; n } n long long gcdExtended(long long a, long long b, long long *x, long long *y) { n   if (a == 0) { n     *x = 0, *y = 1; n     return b; n   } n   long long x1, y1; n   long long gcd = gcdExtended(b % a, a, &x1, &y1); n   *x = y1 - (b / a) * x1; n   *y = x1; n   return gcd; n } n long long power(long long x, long long y, long long p) { n   long long res = 1; n   x = x % p; n   while (y > 0) { n     if (y & 1) res = (res * x) % p; n     y = y >> 1; n     x = (x * x) % p; n   } n   return res; n } n long long modInverse(long long a, long long m) { n   long long x, y; n   long long g = gcdExtended(a, m, &x, &y); n   if (g != 1) n     return -1; n   else { n     long long res = (x % m + m) % m; n     return res; n   } n } n vector<int> primeFactors(int n) { n   vector<int> v; n   while (n % 2 == 0) { n     v.push_back(2); n     n = n / 2; n   } n   for (int i = 3; i <= sqrt(n); i = i + 2) { n     while (n % i == 0) { n       v.push_back(i); n       n = n / i; n     } n   } n   if (n > 2) v.push_back(n); n   return v; n } n long long spf[100001]; n void sieve() { n   spf[1] = 1; n   for (int i = 2; i < 100001; i++) spf[i] = i; n   for (int i = 4; i < 100001; i += 2) spf[i] = 2; n   for (int i = 3; i * i < 100001; i++) { n     if (spf[i] == i) { n       for (int j = i * i; j < 100001; j += i) n         if (spf[j] == j) spf[j] = i; n     } n   } n } n long long binarySearch(long long arr[], long long l, long long r, long long x) { n   if (r >= l) { n     long long mid = l + (r - l) / 2; n     if (arr[mid] == x) return mid; n     if (arr[mid] > x) return binarySearch(arr, l, mid - 1, x); n     return binarySearch(arr, mid + 1, r, x); n   } n   return -1; n } n const long long N = 100000; n long long n; n long long tree[2 * N]; n void build(long long arr[]) { n   for (long long i = 0; i < n; i++) { n     tree[n + i] = arr[i]; n   } n   for (long long i = n - 1; i > 0; --i) { n     tree[i] = tree[i << 1] + tree[i << 1 | 1]; n   } n } n void updateTreeNode(long long p, long long value) { n   tree[p + n] = value; n   p = p + n; n   for (long long i = p; i > 1; i >>= 1) { n     tree[i >> 1] = tree[i] + tree[i ^ 1]; n   } n } n long long query(long long l, long long r) { n   long long res = 0; n   for (l += n, r += n; l < r; l >>= 1, r >>= 1) { n     if (l & 1) { n       res += tree[l++]; n     } n     if (r & 1) { n       res += tree[--r]; n     } n   } n   return res; n } n void dfs(std::vector<long long> v[], long long s, bool visited[]) { n   visited[s] = true; n   for (long long i = 0; i < v[s].size(); ++i) { n     if (!visited[v[s][i]]) { n       dfs(v, v[s][i], visited); n     } n   } n } n long long C[2001][2000]; n void binomialCoeff(long long n, long long k) { n   long long i, j; n   for (i = 0; i <= n; i++) { n     for (j = 0; j <= k; j++) { n       if (j == 0 || j == i) n         C[i][j] = 1; n       else n         C[i][j] = n             (C[i - 1][j - 1] % 998244353 + C[i - 1][j] % 998244353) % 998244353; n     } n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   long long n, m, k; n   cin >> n >> m >> k; n   binomialCoeff(n, k); n   long long mminus1 = power(m - 1, k, 998244353); n   mminus1 %= 998244353; n   long long ans = 1; n   ans *= mminus1 % 998244353; n   ans = ((ans % 998244353) * (m)) % 998244353; n   ans = ((ans % 998244353) * (C[n - 1][k])) % 998244353; n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long cdiv(long long x, long long y) { return x / y + (x % y > 0); } n long long w(long long a, long long b) { n   return cdiv(a, 2) * cdiv(b, 2) + (a / 2) * (b / 2); n } n long long W(long long x1, long long y1, long long x2, long long y2) { n   return w(x2, y2) - w(x2, y1 - 1) - w(x1 - 1, y2) + w(x1 - 1, y1 - 1); n } n long long B(long long x1, long long y1, long long x2, long long y2) { n   return (y2 - y1 + 1) * (x2 - x1 + 1) - W(x1, y1, x2, y2); n } n int main() { n   int t; n   cin >> t; n   while (t--) { n     int x1, x2, x3, x4, y1, y2, y3, y4; n     long long n, m; n     cin >> n >> m; n     cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x4 >> y4; n     long long white = W(1, 1, m, n); n     long long black = B(1, 1, m, n); n     white = white + B(x1, y1, x2, y2); n     black = black - B(x1, y1, x2, y2); n     white = white - W(x3, y3, x4, y4); n     black = black + W(x3, y3, x4, y4); n     if (max(x1, x3) <= min(x2, x4) && max(y1, y3) <= min(y2, y4)) { n       white = white - B(max(x1, x3), max(y1, y3), min(x2, x4), min(y2, y4)); n       black = black + B(max(x1, x3), max(y1, y3), min(x2, x4), min(y2, y4)); n     } n     cout << white <<     << black <<   n ; n   } n } n


/* n    author : Piyush Singh n */ n #include <bits/stdc++.h> n #define IOS ios::sync_with_stdio(false), cin.tie(0) n #undef _GLIBCXX_DEBUG n using namespace std; n  n int main(){ n  IOS; n  int tt; n  cin >> tt; n  while (tt--) { n   int a, b, k; n   cin >> a >> b >> k; n   vector<int> A(k); n   for (int i = 0; i<k; i++) { n    cin >> A[i]; n   } n   vector<int> B(k); n   for (int i = 0; i<k; i++) { n    cin >> B[i]; n   } n   map<int, int> ma; n   map<int, int> mb; n   for (int i = 0; i<k; i++) { n    ma[A[i]] += 1; n    mb[B[i]] += 1; n   } n   long long ans = 0; n   for (int i = 0; i<k; i++) { n    ans += (k-1) - (ma[A[i]] - 1) - (mb[B[i]] - 1); n   } n   cout << ans / 2 <<   n ; n  } n  return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long m; n inline long long Nr(long long n) { n   long long cnt = 0, k, lim, put; n   for (k = 2; 1LL * k * k * k <= n; ++k) { n     put = 1LL * k * k * k; n     lim = n / put; n     if (1LL * lim * put > n) --lim; n     if (1LL * (lim + 1) * put <= n) ++lim; n     cnt += lim; n   } n   return cnt; n } n int main() { n   int i, j, x, y; n   cin >> m; n   long long st = 0, dr = 100000000000000000LL, mij, sol = -1; n   while (st <= dr) { n     mij = (st + dr) / 2; n     long long x = Nr(mij); n     if (x > m) n       dr = mij - 1; n     else if (x < m) n       st = mij + 1; n     else { n       sol = mij; n       dr = mij - 1; n     } n   } n   cout << sol; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int N, K, M; n int main() { n   scanf( %d%d , &N, &K); n   if (K <= 1) n     printf( -1 n ); n   else if (K >= 2 * N) n     printf( 1 n ); n   else if (K > N) n     printf( 3 n ); n   else if (N == K) n     printf( 5 n ); n   else if (K == 2) { n     if (N == 3) n       printf( 11 n ); n     else n       printf( -1 n ); n   } else if (K == 3) { n     if (N == 4) n       printf( 9 n ); n     else if (N == 5) n       printf( 11 n ); n     else n       printf( -1 n ); n   } else { n     N -= (K - 2); n     M = 4; n     if (K >= 2 * N) n       ++M; n     else if (K > N) n       M += 3; n     else if (K == N) n       M += 5; n     else { n       N -= K; n       M += 2 * (N / (K / 2 - 1)); n       N %= (K / 2 - 1); n       N += K; n       if (N > K) { n         N -= (K / 2 - 1); n         M += 2; n       } n       if (K >= 2 * N) n         ++M; n       else if (K > N) n         M += 3; n       else n         M += 5; n     } n     printf( %d n , M); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int x, y; n   int cnt = 0; n   cin >> x >> y; n   if (x != y) n     cout << min(x, y) <<    ; n   else n     cout << x <<    ; n   if (x > y) { n     x = x - y; n     for (int i = 2; i <= x; i += 2) { n       cnt++; n     } n     cout << cnt; n   } else if (y > x) { n     y = y - x; n     for (int i = 2; i <= y; i += 2) { n       cnt++; n     } n     cout << cnt; n   } else n     cout << 0; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m, ans, final = 0, play = 0, study = 0, big, small, i, j; n   cin >> n >> m; n   int a[n + 1]; n   for (i = 1; i <= n; i++) { n     cin >> a[i]; n     if (a[i] == 1) { n       study++; n     } else { n       play++; n     } n   } n   for (i = 1; i <= m; i++) { n     j = i; n     big = study; n     small = play; n     while (j <= n) { n       if (a[j] == 1) { n         big--; n       } else { n         small--; n       } n       j += m; n     } n     ans = abs(big - small); n     if (ans > final) { n       final = ans; n     } n   } n   cout << final; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int amin = 10, bmin = 10; n   char mat[8][8]; n   map<int, int> mapping; n   for (int i = 0; i < 8; i++) { n     for (int j = 0; j < 8; j++) { n       cin >> mat[i][j]; n     } n     getchar(); n   } n   for (int i = 0; i < 8; i++) { n     for (int j = 0; j < 8; j++) { n       if (mat[i][j] ==  B ) mapping[j] = 1; n       if (mat[i][j] ==  W  && mapping.find(j) == mapping.end()) { n         if (i < amin) amin = i; n         mapping[j] = 1; n         break; n       } n     } n   } n   mapping.clear(); n   for (int i = 7; i >= 0; i--) { n     for (int j = 7; j >= 0; j--) { n       if (mat[i][j] ==  W ) mapping[j] = 1; n       if (mat[i][j] ==  B  && mapping.find(j) == mapping.end()) { n         if (7 - i < bmin) bmin = 7 - i; n         mapping[j] = 1; n         break; n       } n     } n   } n   if (amin <= bmin) { n     cout <<  A  << endl; n   } else n     cout <<  B  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int dp[1 << 20], w[25][25]; n string s[25]; n pair<int, int> alph[25][26]; n int ma[25][26]; n int cost[1 << 20]; n vector<pair<int, int> > rco; n int main() { n   int n, m; n   cin >> n >> m; n   for (int i = 0; i < n; i++) cin >> s[i]; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) cin >> w[i][j]; n   } n   fill(cost, cost + (1 << 20), (int)1e9); n   cost[0] = 0; n   for (int i = 0; i < m; i++) { n     for (int j = 0; j < n; j++) { n       cost[1 << j] = min(cost[1 << j], w[j][i]); n       alph[i][(s[j][i] -  a )].first |= (1 << j); n       alph[i][(s[j][i] -  a )].second += w[j][i]; n       ma[i][s[j][i] -  a ] = max(ma[i][s[j][i] -  a ], w[j][i]); n     } n     for (int j = 0; j < 26; j++) { n       alph[i][j].second -= ma[i][j]; n       cost[alph[i][j].first] = min(cost[alph[i][j].first], alph[i][j].second); n     } n   } n   for (int i = 1; i < (1 << 20); i++) { n     if (cost[i] != (int)1e9) rco.push_back(make_pair(i, cost[i])); n   } n   fill(dp, dp + (1 << n), (int)1e9); n   dp[0] = 0; n   for (int i = 0; i < rco.size(); i++) { n     const int mask = rco[i].first, co = rco[i].second; n     for (int j = 0; j < (1 << n); j++) { n       dp[j | mask] = min(dp[j | mask], dp[j] + co); n     } n   } n   cout << dp[(1 << n) - 1]; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, a, b; n   cin >> n >> a >> b; n   if (b) b = (b / abs(b)) * (abs(b) % n); n   if (!b) { n     cout << a; n     return 0; n   } n   if (b > 0) { n     int i, cnt = 0; n     for (i = a; cnt != b; (i != n) ? (i++) : i = 1) { n       cnt++; n     } n     cout << i; n     return 0; n   } n   if (b < 0) { n     b = abs(b); n     int i, cnt = 0; n     for (i = a; cnt != b; (i != 1) ? (i--) : i = n) { n       cnt++; n     } n     cout << i; n     return 0; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int ret[1001]; n int main() { n   int N; n   scanf( %d n , &N); n   char s[1000]; n   scanf( %s , s); n   fill(ret, ret + N, 1); n   for (int i = 0; i < N; i++) { n     int t = 1; n     for (int j = i; j < N; j++) n       if (s[j] ==  R ) n         break; n       else if (s[j] ==  L ) n         t++; n     ret[i] = max(ret[i], t); n     t = 1; n     for (int j = i - 1; j >= 0; j--) n       if (s[j] ==  L ) n         break; n       else if (s[j] ==  R ) n         t++; n     ret[i] = max(ret[i], t); n   } n   printf( %d , ret[0]); n   for (int i = 1; i < N; i++) printf(  %d , ret[i]); n   printf(  n ); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   { n     ios_base::sync_with_stdio(false); n     cin.tie(NULL); n     cout.tie(NULL); n   }; n   long long t; n   cin >> t; n   while (t--) { n     long long a, b, n, s; n     cin >> a >> b >> n >> s; n     bool ans = false; n     long long f = s / n; n     s -= min(f, a) * n; n     if (s <= b) { n       cout <<  YES n ; n     } else { n       cout <<  NO n ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s; n   cin >> s; n   int sign = 1, tmp = 0, ans = 0; n   for (int i = 0; i < s.size(); i++) { n     if (!(s[i] >=  0  && s[i] <=  9 )) { n       ans += tmp * sign; n       if (s[i] ==  - ) n         sign = -1; n       else n         sign = 1; n       tmp = 0; n     } n     tmp = (s[i] -  0 ) + tmp * 10; n   } n   ans += tmp * sign; n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 0x3f3f3f3f; n const long double pi = acos(-1); n const int MOD = 1e9 + 7; n const long long int LINF = 0x3f3f3f3f3f3f3f3f; n bitset<4096> bs[100050]; n pair<int, int> carac[100005][15]; n int c[15][100005]; n int n, k, q; n int type[100050]; n int a[100050]; n int b[100050]; n int qte; n int pega(int x, int y) { n   int mask = 0; n   for (int i = k - 1; i >= 0; i--) { n     mask ^= (1 << carac[y][i].second); n     if (bs[x][mask]) { n       return carac[y][i].first; n     } n   } n } n int main() { n   scanf( %d%d%d , &n, &k, &q); n   for (int i = 0; i < k; i++) { n     for (int j = 0; j < n; j++) { n       scanf( %d , &c[i][j]); n       carac[j][i] = make_pair(c[i][j], i); n     } n   } n   for (int i = 0; i < k; i++) { n     for (int j = 0; j < (1 << k); j++) { n       if ((1 << i) & j) bs[i][j] = 1; n     } n   } n   for (int i = 0; i < n; i++) { n     sort(carac[i], carac[i] + k); n   } n   qte = k; n   for (int i = 0; i < q; i++) { n     int t, x, y; n     cin >> t >> x >> y; n     if (t == 1) { n       type[qte] = 1; n       x--, y--; n       bs[qte] = bs[x] | bs[y]; n       qte++; n     } else if (t == 2) { n       x--, y--; n       type[qte] = 2; n       bs[qte] = bs[x] & bs[y]; n       qte++; n     } else if (t == 3) { n       x--; n       y--; n       cout << pega(x, y) <<   n ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 203; n const int MOD = 1e9 + 7; n int n, ssz; n string s; n int len[N][2]; n int dp[N][N][N][2]; n int calc(const string &t) { n   int tsz = t.size(); n   for (int i = tsz; i > 0; --i) { n     if (s.substr(0, i) == t.substr(tsz - i, i)) return i; n   } n   return 0; n } n void add(int &a, int b) { n   a += b; n   if (a >= MOD) a -= MOD; n } n int main() { n   cin >> n >> s; n   ssz = s.size(); n   if (s[0] ==  ( ) n     len[0][0] = 1; n   else n     len[0][1] = 1; n   string pref; n   for (int i = 0; i < ssz; ++i) { n     pref += s[i]; n     pref +=  ( ; n     len[i + 1][0] = calc(pref); n     pref.pop_back(); n     pref +=  ) ; n     len[i + 1][1] = calc(pref); n     pref.pop_back(); n   } n   dp[0][0][0][0] = 1; n   for (int i = 0; i < 2 * n; ++i) { n     for (int j = 0; j <= n; ++j) { n       for (int pos = 0; pos <= ssz; ++pos) { n         for (int f = 0; f < 2; ++f) { n           if (dp[i][j][pos][f] == 0) continue; n           if (j + 1 <= n && (2 * n - i - 1) >= (j + 1)) n             add(dp[i + 1][j + 1][len[pos][0]][f | (len[pos][0] == ssz)], n                 dp[i][j][pos][f]); n           if (j > 0) n             add(dp[i + 1][j - 1][len[pos][1]][f | (len[pos][1] == ssz)], n                 dp[i][j][pos][f]); n         } n       } n     } n   } n   int ans = 0; n   for (int i = 0; i <= ssz; ++i) add(ans, dp[2 * n][0][i][1]); n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = (int)2e5 + 7; n const int mod = 998244353; n int n, m, l; n int a[maxn << 2], b[maxn << 2], rev[maxn << 2]; n int num[maxn << 2]; n const int pr = 3; n const int phi = mod - 1; n int qpow(int x, int y) { n   int t = 1; n   while (y) { n     if (y & 1) t = 1ll * t * x % mod; n     x = 1ll * x * x % mod; n     y >>= 1; n   } n   return t; n } n void NTT(int *P, int n, int opt) { n   for (int i = 0; i < n; i++) { n     if (i < rev[i]) { n       swap(P[i], P[rev[i]]); n     } n   } n   for (int i = 1; i < n; i <<= 1) { n     int W = qpow(pr, phi / (i << 1)); n     for (int p = i << 1, j = 0; j < n; j += p) { n       int w = 1; n       for (int k = 0; k < i; k++, w = 1ll * w * W % mod) { n         int X = P[j + k], Y = 1ll * w * P[i + j + k] % mod; n         P[j + k] = (X + Y) % mod; n         P[i + j + k] = (X - Y + mod) % mod; n       } n     } n   } n   if (opt == -1) reverse(P + 1, P + n); n } n vector<int> solve(int l, int r) { n   if (l == r) { n     vector<int> res; n     for (int i = 0; i <= num[l]; i++) { n       res.push_back(1); n     } n     return res; n   } n   vector<int> v1 = solve(l, (l + r >> 1)); n   vector<int> v2 = solve((l + r >> 1) + 1, r); n   int siz1 = v1.size(), siz2 = v2.size(); n   int k = 0, s = 2; n   while ((1 << k) < max(siz1, siz2) + 1) k++, s <<= 1; n   for (int i = 1; i < s; i++) rev[i] = (rev[i >> 1] >> 1) | ((i & 1) << (k)); n   for (int i = 0; i < s; i++) { n     if (i < siz1) { n       a[i] = v1[i]; n     } n     if (i < siz2) { n       b[i] = v2[i]; n     } n   } n   NTT(a, s, 1); n   NTT(b, s, 1); n   int inv = qpow(s, mod - 2); n   for (int i = 0; i < s; i++) { n     a[i] = 1ll * a[i] * b[i] % mod; n   } n   NTT(a, s, -1); n   for (int i = 0; i < s; i++) { n     a[i] = 1ll * a[i] * inv % mod; n   } n   vector<int> v3; n   for (int i = 0, tt = siz1 + siz2 - 1; i < tt; i++) { n     v3.push_back(a[i]); n   } n   for (int i = 0; i < s; i++) { n     a[i] = b[i] = 0; n   } n   return v3; n } n int vis[maxn * 30]; n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) { n     int t; n     scanf( %d , &t); n     vis[t]++; n   } n   int nn = 0; n   for (int i = 1; i <= 3000000; i++) { n     if (vis[i]) { n       num[++nn] = vis[i]; n     } n   } n   vector<int> res = solve(1, nn); n   int maxx = 0; n   maxx = res[n / 2]; n   printf( %d n , maxx); n   return 0; n } n


#include <bits/stdc++.h> n int b[100005], a[100005], n, x, A, k; n int main() { n   while (~scanf( %d %d , &n, &k)) { n     memset(b, 0, sizeof(b)); n     scanf( %d , &a[1]); n     x = 2; n     for (int i = 2; i <= n; i++) { n       scanf( %d , &A); n       if (A != a[x - 1]) a[x++] = A; n     } n     for (int i = 1; i < x; i++) { n       b[a[i]]++; n       if (i < x - 1 && i > 0) { n         if (a[i - 1] == a[i + 1]) b[a[i]]++; n       } n     } n     int y = 1; n     if (x == k + 1) n       printf( 1 n ); n     else { n       for (int i = 2; i <= k; i++) { n         if (b[i] > b[y]) y = i; n       } n       printf( %d n , y); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long INF = (1e9) + 7; n const long long C = (1 << (17)); n vector<vector<long long> > up, sum; n vector<long long> cost, maxw, d; n long long LOG = 20; n void push(long long v, long long x) { n   cost.push_back(x); n   maxw.push_back(x); n   d.push_back(0); n   for (int i = 0; i < LOG; ++i) { n     sum[i].push_back(x); n     up[i].push_back(v); n   } n } n void init() { n   up.resize(20); n   sum.resize(20); n   push(0, 0); n } n void add(long long pr, long long w) { n   long long v = up[0].size(); n   if (maxw[pr] < w) { n     push(v, w); n     return; n   } n   for (int i = LOG - 1; i >= 0; --i) { n     if (cost[up[i][pr]] < w) pr = up[i][pr]; n   } n   if (cost[pr] < w) { n     pr = up[0][pr]; n     assert(cost[pr] >= w); n   } n   cost.push_back(w); n   maxw.push_back(maxw[pr]); n   d.push_back(d[pr] + 1); n   up[0].push_back(pr); n   sum[0].push_back(cost[pr]); n   for (int i = 1; i < LOG; ++i) { n     long long pp = up[i - 1][v]; n     up[i].push_back(up[i - 1][pp]); n     if (pp != up[i - 1][pp]) { n       sum[i].push_back(sum[i - 1][v] + sum[i - 1][pp]); n     } else { n       sum[i].push_back(sum[i - 1][v]); n     } n   } n } n long long req(long long v, long long first) { n   if (cost[v] > first) return 0; n   first -= cost[v]; n   long long ans = 1; n   for (int i = LOG - 1; i >= 0; --i) { n     if (sum[i][v] <= first) { n       ans += d[v] - d[up[i][v]]; n       first -= sum[i][v]; n       v = up[i][v]; n     } n   } n   return ans; n } n int source() { n   init(); n   long long Q; n   cin >> Q; n   long long last = 0; n   for (long long q1 = 0; q1 < Q; ++q1) { n     long long type, p, q; n     cin >> type >> p >> q; n     long long R = p ^ last; n     --R; n     long long W = q ^ last; n     if (type == 1) { n       add(R, W); n     } else { n       last = req(R, W); n       cout << last <<   n ; n     } n   } n   return 0; n } n int main() { n   ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); n   source(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = INT_MAX / 2; n int main() { n   int n, k, q; n   scanf( %d%d%d , &n, &k, &q); n   vector<int> vec(n); n   for (int i = 0; i < n; i++) { n     scanf( %d , &vec[i]); n   } n   set<pair<int, int> > st; n   map<int, int> mp; n   for (int i = 0; i < q; i++) { n     int type, id; n     scanf( %d%d , &type, &id); n     id--; n     if (type == 1) { n       if (st.size() < k) { n         st.insert(make_pair(vec[id], id)); n         mp[id] = 1; n       } else { n         set<pair<int, int> >::iterator it = st.begin(); n         if ((*it).first < vec[id]) { n           mp.erase((*it).second); n           st.erase(it); n           st.insert(make_pair(vec[id], id)); n           mp[id] = 1; n         } n       } n     } else { n       if (mp.count(id)) n         printf( YES n ); n       else n         printf( NO n ); n     } n   } n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n const int MAX = 100009; n int n, m, k, a[MAX], b[MAX], pos[MAX]; n int main() { n   cin >> n >> m >> k; n   for (int i = 1; i <= n; i++) { n     cin >> a[i]; n     pos[a[i]] = i; n   } n   long long ans = 0; n   for (int i = 1; i <= m; i++) { n     cin >> b[i]; n     int current = pos[b[i]]; n     ans += (current + k - 1) / k; n     if (current > 1) { n       swap(pos[a[current]], pos[a[current - 1]]); n       swap(a[current], a[current - 1]); n     } n   } n   printf( %I64d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a[200001]; n bool b[200001]; n int main() { n   string s1, s2; n   int n, i; n   cin >> s1 >> s2; n   n = s1.size(); n   for (i = 1; i <= n; i++) cin >> a[i]; n   int l, r, mid, pr = 0, j; n   l = 0; n   r = n; n   while (l != r) { n     mid = (l + r + 1) / 2; n     for (i = 0; i <= n; i++) b[i] = 1; n     for (i = 1; i <= mid; i++) b[a[i] - 1] = 0; n     j = 0; n     for (i = 0; i < n && j < s2.size(); i++) { n       if (b[i]) { n         if (s1[i] == s2[j]) j++; n       } n     } n     if (j == s2.size()) n       l = mid; n     else n       r = mid - 1; n   } n   cout << l << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   cin >> t; n   while (t--) { n     int n, k; n     cin >> n >> k; n     k++; n     vector<int> v; n     for (int i = 0, x; i < n; i++) { n       cin >> x; n       v.push_back(x); n     } n     int lo = 1; n     int hi = 1000000000; n     while (lo < hi) { n       int me = (lo + hi) / 2; n       bool can = 0; n       for (int i = 0; i + k - 1 < n; i++) { n         if (v[i + k - 1] - v[i] <= me) can = 1; n       } n       if (!can) n         lo = me + 1; n       else n         hi = me; n     } n     int x = -10; n     for (int i = 0; i + k - 1 < n; i++) { n       if (v[i + k - 1] - v[i] <= lo) x = (v[i] + v[i + k - 1]) / 2; n     } n     cout << x <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 12; n unsigned long long ans; n unsigned long long n; n unsigned long long data[maxn]; n void init() { n   scanf( %I64d , &n); n   memset(data, 0, sizeof(data)); n   ans = 0; n } n void solve() { n   for (int i = 1; i <= n; ++i) { n     ++data[i % 9]; n     ans -= n / i; n   } n   for (int i = 0; i < 9; ++i) n     for (int j = 0; j < 9; ++j) ans += data[i] * data[j] * data[i * j % 9]; n } n void write() { printf( %I64d n , ans); } n int main() { n   init(); n   solve(); n   write(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, m, k; n long long x[1000005], r, cur[1000005]; n long long len; n bool check(long long cnt) { n   long long res = 0, s = 0; n   for (int i = (1); i < (n + 1); i++) cur[i] = 0; n   for (int i = (1); i < (r + 1); i++) s += x[i]; n   for (int i = 1; i <= n; i++) { n     s += x[i + r]; n     if (i > r) { n       s = s - x[i - r - 1] - cur[i - r - 1]; n     } n     if (s < cnt) { n       long long d = cnt - s; n       res += d; n       cur[i + r] += d; n       s += d; n       if (res > k) return 0; n     } n   } n   return 1; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   ; n   cin >> n >> r >> k; n   for (int i = 1; i <= n; i++) { n     cin >> x[i]; n   } n   long long l = 0, r = 2e18, mid, ans = 0; n   while (l <= r) { n     mid = (l + r) >> 1ll; n     if (check(mid)) { n       l = mid + 1; n       ans = max(ans, mid); n     } else { n       r = mid - 1; n     } n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int M = 6 * 1e5; n const long long Q = 1e9 + 7; n int ans; n int a[10]; n bool used[10]; n void dfs(int i) { n   used[i] = true; n   if (!used[a[i]]) dfs(a[i]); n } n void gen(int i, int n) { n   if (i == n + 1) { n     bool ok = true; n     for (int j = 1; j <= n; j++) { n       for (int f = 1; f <= n; f++) used[f] = false; n       dfs(j); n       if (!used[1]) { n         ok = false; n         break; n       } n     } n     if (ok) ans++; n     return; n   } n   for (int j = 1; j <= n; j++) { n     a[i] = j; n     gen(i + 1, n); n   } n } n int cnt(int n) { n   ans = 0; n   gen(1, n); n   int tmp = ans; n   return tmp; n } n int main() { n   srand(time(NULL)); n   int n, k; n   scanf( %d%d , &n, &k); n   long long x = 1; n   for (int i = 0; i < (n - k); i++) x = (x * (n - k)) % Q; n   long long y = cnt(k); n   cout << (x * y) % Q; n   cerr << clock() / (CLOCKS_PER_SEC + 0.); n   return 0; n } n


#include <bits/stdc++.h> n int ans = 2, n, t; n double m; n struct T { n   int x, t; n } a[1111]; n bool my(T a, T b) { return (a.x < b.x); } n int main() { n   scanf( %d%d , &n, &t); n   for (int i = 1; i <= n; i++) scanf( %d%d , &a[i].x, &a[i].t); n   std::sort(a + 1, a + n + 1, &my); n   for (int i = 2; i <= n; i++) { n     m = a[i].x - a[i - 1].x - (double)a[i].t / 2 - (double)a[i - 1].t / 2; n     if (m > t) n       ans += 2; n     else if (m == t) n       ++ans; n   } n   printf( %d n , ans); n   return 0; n } n