#include <bits/stdc++.h>   class MapValue {    public:     std::string configuration;     int s1;     MapValue() {}     MapValue(std::string configuration, int s1)         : configuration(configuration), s1(s1) {}   };   class PairHash {    public:     std::size_t operator()(const std::pair<int, int> &p) const {       return std::hash<int>()(p.first) ^ std::hash<int>()(p.second);     }   };   std::unordered_map<std::pair<int, int>, MapValue, PairHash> my_map;   int A[100], B[100], C[100], q_rez = -0x3f3f3f3f;   std::string rrr =  Impossible ;   void back(int s1, int s2, int s3, int k, int max, std::string ss) {     if (k == max + 1) {       my_map.emplace(std::make_pair(s2 - s1, s3 - s2), MapValue(ss, s1));       return;     }     s1 += A[k];     s2 += B[k];     back(s1, s2, s3, k + 1, max, ss +  LM n );     s1 -= A[k];     s3 += C[k];     back(s1, s2, s3, k + 1, max, ss +  MW n );     s2 -= B[k];     s1 += A[k];     back(s1, s2, s3, k + 1, max, ss +  LW n );   }   void back2(int s1, int s2, int s3, int k, int max, std::string ss) {     if (k == max + 1) {       std::string result;       auto it = my_map.find(std::make_pair(s1 - s2, s2 - s3));       if (it != my_map.end()) {         int q = s1 + it->second.s1;         if (q > q_rez) {           rrr = it->second.configuration + ss;           q_rez = q;         }       }       return;     }     s1 += A[k];     s2 += B[k];     back2(s1, s2, s3, k + 1, max, ss +  LM n );     s1 -= A[k];     s3 += C[k];     back2(s1, s2, s3, k + 1, max, ss +  MW n );     s2 -= B[k];     s1 += A[k];     back2(s1, s2, s3, k + 1, max, ss +  LW n );   }   int main() {     int N;     std::cin >> N;     for (int i = 1; i <= N; i++) {       std::cin >> A[i] >> B[i] >> C[i];     }     std::string ss =   ;     back(0, 0, 0, 1, N / 2, ss);     ss =   ;     back2(0, 0, 0, N / 2 + 1, N, ss);     std::cout << rrr;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2.7e5 + 5;   int m, n, k;   int mod;   int f[19][maxn];   vector<long long> g;   int cnt[maxn];   int upd(const int &x) {     if (x < 0) return x + mod;     if (x >= mod) return x - mod;     return x;   }   void add(int &x, const int &y) { x = upd(x + y); }   int ksm(int x, int k) {     int ans = 1;     while (k) {       if (k & 1) ans = 1ll * ans * x % mod;       x = 1ll * x * x % mod;       k >>= 1;     }     return ans;   }   int jc[maxn], inv[maxn];   void init(int n) {     jc[0] = 1;     for (int i(1), endi(n); i <= endi; i++) jc[i] = 1ll * jc[i - 1] * i % mod;     inv[n] = ksm(jc[n], mod - 2);     for (int i(n - 1), endi(0); i >= endi; i--)       inv[i] = 1ll * inv[i + 1] * (i + 1) % mod;   }   void F(int *f, int n, int h) {     for (int p = 1; p < n; p <<= 1)       for (int i = 0; i < n; i += p << 1)         for (int k(i), endk(i + p - 1); k <= endk; k++) {           add(f[k + p], h * f[k]);         }   }   int l;   vector<long long> operator*(vector<long long> &A, vector<long long> &B) {     static vector<long long> C;     C.clear();     C.resize(l + 1);     for (int i(0), endi(l); i <= endi; i++)       for (int j(0), endj(l - i); j <= endj; j++) C[i + j] += A[i] * B[j];     for (int i(0), endi(l); i <= endi; i++) C[i] %= mod;     return C;   }   vector<long long> pksm(vector<long long> A, int k) {     static vector<long long> C;     C.clear();     C.resize(l + 1);     C[0] = 1;     while (k) {       if (k & 1) C = C * A;       A = A * A;       k >>= 1;     }     return C;   }   int main() {     cin >> n >> k >> mod;     init(n);     if (n & 1) {       cout << ksm(k, n);       return 0;     }     m = 1;     while (m <= n) m <<= 1, l++;     for (int i(0), endi(m - 1); i <= endi; i++) cnt[i] = cnt[i >> 1] + (i & 1);     init(m);     for (int i(0), endi(m - 1); i <= endi; i++) {       f[cnt[i]][i] = inv[i];     }     for (int i(0), endi(l); i <= endi; i++) F(f[i], m, 1);     g.resize(l + 1);     for (int s(0), ends(m - 1); s <= ends; s++) {       for (int i(0), endi(l); i <= endi; i++) g[i] = f[i][s];       g = pksm(g, k);       for (int i(0), endi(l); i <= endi; i++) f[i][s] = g[i];     }     F(f[cnt[n]], m, -1);     cout << upd(ksm(k, n) - 1ll * f[cnt[n]][n] * jc[n] % mod);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool issquare(int n) {     int sq = sqrt(n);     if (sq * sq == n) {       return true;     } else {       return false;     }   }   int main() {     long long int n;     cin >> n;     long long int ans = n;     int f = 1;     while (n != 1 and f == 1) {       int sqr = ceil(sqrt((n * 1.0)));       f = 0;       for (int i = 2; i <= sqr; i++) {         if (n % i == 0) {           n = n / i;           ans += n;           f = 1;           break;         }       }     }     if (n != 1) ans += 1;     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = ((int)5e5) + 5;   long long int sum[maxn];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int n;     cin >> n;     string s;     cin >> s;     for (int i = 0; i < s.length(); i++) {       long long int total = 0;       for (int j = i; j < s.length(); j++) {         total += s[j] -  0 ;         sum[total]++;       }     }     long long int ans = 0;     if (n == 0) {       ans = 2 * sum[0] * ((s.length()) * (s.length() + 1)) / 2 - sum[0] * sum[0];     } else {       for (int i = 1; i < maxn; i++) {         if (n % i == 0 && (n / i) < maxn) {           ans += sum[i] * sum[n / i];         }       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double EPS = 1e-9;   const long long MOD = 1e9 + 7;   pair<int, int> es[200000];   vector<pair<int, int> > g[200000];   int degree[200000];   set<pair<int, int> > st;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n, m, k;     scanf( %d%d%d , &n, &m, &k);     for (long long i = 0; i < m; i++) {       scanf( %d%d , &es[i].first, &es[i].second);       es[i].first--, es[i].second--;       g[es[i].first].push_back({es[i].second, i});       g[es[i].second].push_back({es[i].first, i});       degree[es[i].first]++, degree[es[i].second]++;     }     reverse(es, es + m);     for (long long i = 0; i < n; i++) st.insert({degree[i], i});     while (!st.empty() && st.begin()->first < k) {       auto v = st.begin();       for (pair<int, int> &i : g[v->second]) {         int to = i.first;         if (st.find({degree[to], to}) != st.end()) {           st.erase({degree[to], to});           degree[to]--;           st.insert({degree[to], to});         }       }       st.erase(v);     }     vector<int> out;     for (long long j = 0; j < m; j++) {       out.push_back(st.size());       int u = es[j].first, v = es[j].second;       if (st.find({degree[u], u}) != st.end() &&           st.find({degree[v], v}) != st.end()) {         st.erase({degree[u], u});         degree[u]--;         st.insert({degree[u], u});         st.erase({degree[v], v});         degree[v]--;         st.insert({degree[v], v});         while (!st.empty() && st.begin()->first < k) {           auto v = st.begin();           for (pair<int, int> &i : g[v->second]) {             if (i.second >= m - j - 1) continue;             int to = i.first;             if (st.find({degree[to], to}) != st.end()) {               st.erase({degree[to], to});               degree[to]--;               st.insert({degree[to], to});             }           }           st.erase(v);         }       }     }     reverse(begin(out), end(out));     for (int i : out) printf( %d n , i);   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   void Read(T &x) {     char c;     bool f(0);     while (c = getchar(), c != EOF) {       if (c ==  - )         f = 1;       else if (c >=  0  && c <=  9 ) {         x = c -  0 ;         while (c = getchar(), c >=  0  && c <=  9 ) x = x * 10 + c -  0 ;         ungetc(c, stdin);         if (f) x = -x;         return;       }     }   }   struct point {     int x, y;     inline point() {}     inline point(int x, int y) : x(x), y(y) {}     inline point operator-(const point &b) const {       return point(x - b.x, y - b.y);     }     inline bool operator<(const point &b) const {       if (x == b.x) return y < b.y;       return x < b.x;     }     inline bool operator>(const point &b) const {       if (x == b.x) return y > b.y;       return x > b.x;     }     inline bool operator==(const point &b) const { return x == b.x && y == b.y; }   } a[100000 + 10];   int Q;   set<point> s;   set<point, greater<point> > s2;   inline long long cross(const point &a, const point &b) {     return 1ll * a.x * b.y - 1ll * a.y * b.x;   }   template <class T>   void insert(T &s, const point &a) {     auto i = s.lower_bound(a);     if (i != s.end() && *i == a) return;     auto j = i;     if (j != s.begin()) {       j--;       while (j != s.begin()) {         auto k = j--;         if (cross(*k - *j, a - *k) > 0) break;         s.erase(k);       }     }     if (i != s.end()) {       auto k = i;       while (++i != s.end()) {         if (cross(*k - a, *i - a) > 0) break;         s.erase(k);         k = i;       }     }     i = s.lower_bound(a);     if (i == s.end() || i == s.begin())       s.insert(a);     else {       auto j = i--;       if (cross(a - *i, *j - *i) > 0) s.insert(a);     }   }   template <class T>   bool check(const T &s, const point &a) {     auto i = s.lower_bound(a);     if (*i == a) return 1;     if (i == s.begin() || i == s.end()) return 0;     auto j = i--;     return cross(a - *i, *j - *i) <= 0;   }   int main() {     Read(Q);     int p, x, y;     while (Q--) {       Read(p), Read(x), Read(y);       if (p == 1) {         insert(s, point(x, y));         insert(s2, point(x, y));       } else         puts(check(s, point(x, y)) && check(s2, point(x, y)) ?  YES  :  NO );     }   }


#include <bits/stdc++.h>   using namespace std;   int main(int argc, char *argv[]) {     string s;     int min1 = 200, min2 = 200, min3 = 200, min4 = 200, min5 = 200;     cin >> s;     for (int i = 0; i < s.size(); i++) {       if (s[i] ==  h  && i < min1) min1 = i;       if (s[i] ==  e  && i < min2 && min1 < i) min2 = i;       if (s[i] ==  l  && i < min3 && min2 < i) {         min3 = i;         s[i] = 0;       }       if (s[i] ==  l  && i < min4 && min3 < i) {         min4 = i;         s[i] = 0;       }       if (s[i] ==  o  && i < min5 && min4 < i) min5 = i;     }     if (min1 < min2 && min2 < min3 && min3 < min4 && min4 < min5 && min1 != 200 &&         min2 != 200 && min3 != 200 && min4 != 200 && min5 != 200)       cout <<  YES ;     else       cout <<  NO ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);     long long a, b;     cin >> a >> b;     cout <<  YES  << endl;     for (long long i = a; i <= b; i += 2) cout << i <<     << i + 1 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int const N = 100000;   long long a[N + 5], res;   int n, p;   int main() {     cin >> n >> p;     for (int i = 1; i <= n; ++i) {       cin >> a[i];       a[i] += a[i - 1];     }     for (int i = 1; i < n; ++i) res = max(res, a[i] % p + (a[n] - a[i]) % p);     cout << res;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, k, t;   int index(int i, int j) { return (i - 1) * m + j; }   int main() {     cin >> n >> m >> k >> t;     int arr[k];     for (int i = 0; i < k; i++) {       int a, b;       cin >> a >> b;       arr[i] = index(a, b);     }     sort(arr, arr + k);     while (t--) {       int a, b;       cin >> a >> b;       int x = index(a, b);       int cnt = 0;       for (int i = 0; i < k; i++) {         int element = arr[i];         if (x > element)           cnt++;         else if (x == element) {           cnt = -1;           break;         } else           break;       }       if (cnt == -1) {         cout <<  Waste  << endl;         continue;       }       int mod = (x - cnt - 1) % 3;       if (mod == 0) cout <<  Carrots  << endl;       if (mod == 1) cout <<  Kiwis  << endl;       if (mod == 2) cout <<  Grapes  << endl;     }     return 0;   }


#include<bits/stdc++.h>   using namespace std;   const int maxn=4e3+100;   typedef long long ll;   ll l[maxn],r[maxn],d[maxn];   int main()   {       int n,m,k;cin>>n>>m>>k;       for(int i=1;i<=m;i++)cin>>l[i]>>r[i];        ll ans=0;       for(int i=1,j=k;j<=n;i++,j++)//枚举第一个区间       {           ll sum=0,w;           memset(d,0,sizeof(d));           for(int p=1;p<=m;p++) {               w = max(0ll, min(r[p], 1ll*j)+1 - max(l[p], 1ll*i));               sum += w;               if(w<r[p]-l[p]+1)d[l[p]+w]++,d[l[p]+k]--,d[r[p]+1]--,d[r[p]+1+k-w]++;           }           for(int q=1;q<=n;q++)d[q]+=d[q-1];           ll imax=0;           for(int q=1;q<=n;q++)d[q]+=d[q-1],imax=max(imax,1ll*d[q]);           ans=max(ans,sum+imax);       }      cout<<ans<<endl;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX_BUF_SIZE = 16384;   char BUFOR[MAX_BUF_SIZE];   int BUF_SIZE, BUF_POS;   char ZZZ;   const int MXN = 1000010;   const int C = 262144;   const int INF = 1000000001;   int n, m, h;   int s[MXN];   int sum;   int sh;   void test() {     scanf( %d %d %d , &n, &m, &h);     for (int i = 1; i <= m; i++) {       int tmp;       scanf( %d , &tmp);       if (i == h) sh = tmp;       sum += tmp;     }     if (sum < n) {       printf( -1 n );       return;     }     long double res = 1;     for (int i = sum - sh - n + 2; i <= sum - sh; i++) res = res * i;     for (int i = sum - n + 1; i <= sum - 1; i++) res = res / i;     double rr = res;     printf( %.9lf n , 1 - rr);   }   int main() {     int te = 1;     while (te--) test();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int N, D;   signed long long A[202020];   int M;   void solve() {     int i, j, k, l, r, x, y;     string s;     cin >> N >> D;     for (i = 0; i < (N); i++) cin >> A[i];     cin >> M;     for (i = 0; i < (M); i++) {       cin >> x;       if (x == A[0] || x == A[N - 1] + 1) {         (void)printf( %.12lf n , atan(1) * 2);         continue;       }       y = lower_bound(A, A + N, x) - A;       if (A[y] == x && A[y - 1] == x - 1) {         (void)printf( %.12lf n , atan(1) * 4);         continue;       }       if (A[y] == x || A[y - 1] == x - 1) {         (void)printf( %.12lf n , atan(1) * 2);         continue;       }       signed long long dif = min(x - A[y - 1] - 1, A[y] - x);       double ret = atan(1.0 / dif);       int L = y - 1;       int R = y;       int ok = 0;       for (j = 20; j >= 0; j--)         if (2 * atan(1.0 / (ok + (1 << j))) >= ret) ok += 1 << j;       while (L >= 0 && R < N) {         int dl = x - (A[L] + 1);         int dr = A[R] - x;         if (max(dl, dr) > ok) break;         if (abs(dl - dr) <= 1) {           ret = 2 * atan(1.0 / max(dl, dr));           break;         }         if (dl < dr)           L--;         else           R++;       }       (void)printf( %.12lf n , ret);     }   }   int main(int argc, char** argv) {     string s;     int i;     if (argc == 1) ios::sync_with_stdio(false), cin.tie(0);     for (i = 0; i < (argc - 1); i++) s += argv[i + 1], s +=   n ;     for (i = 0; i < (s.size()); i++) ungetc(s[s.size() - 1 - i], stdin);     cout.tie(0);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int N, D, a[105], ans;   int main() {     int T;     cin >> T;     while (T--) {       cin >> N >> D;       for (int i = 1; i <= N; i++) cin >> a[i];       for (int i = 2; i <= N; i++) {         int move = min(a[i], D / (i - 1));         a[1] += move;         D -= move * (i - 1);       }       cout << a[1] << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, t, c;     cin >> n >> t >> c;     int ls = 0;     int ans = 0;     for (int i = 1; i <= n; i++) {       int a;       cin >> a;       if (a > t)         ls = i;       else if (i - ls >= c)         ans++;     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c, d, e = 0, all = 0, i = 0;     cin >> a >> b;     c = a;     d = b;     while (c) {       if ((c % 10) > e) {         e = c % 10;       }       c = c / 10;     }     while (d) {       if ((d % 10) > e) {         e = d % 10;       }       d = d / 10;     }     e = e + 1;     while (a) {       all = (a % 10) * pow(e, i) + all;       a = a / 10;       i++;     }     i = 0;     a = b;     while (a) {       all = (a % 10) * pow(e, i) + all;       a = a / 10;       i++;     }     i = 0;     while (all) {       all = all / e;       i++;     }     cout << i << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     static int r;     static char c;     r = 0, c = getchar();     while (c <  0  || c >  9 ) c = getchar();     while (c >=  0  && c <=  9 ) r = r * 10 + (c -  0 ), c = getchar();     return r;   }   template <typename T>   inline void print(T* a, int n) {     for (int i = 1; i < n; ++i) cout << a[i] <<    ;     cout << a[n] << endl;   }   const int INFI = 123456789;   int n, a[300000 + 1], p[300000 + 1];   long long ans = 0LL;   struct node {     int m, mc, m2, m2c, d;   } tree[300000 * 5];   inline node update(node l, node r) {     static node ret;     ret = l;     ret.d = 0;     if (r.m < ret.m) {       ret.m2 = ret.m, ret.m2c = ret.mc;       ret.m = r.m, ret.mc = r.mc;     } else if (r.m == ret.m) {       ret.mc += r.mc;     } else if (r.m < ret.m2) {       ret.m2 = r.m, ret.m2c = r.mc;     } else if (r.m == ret.m2) {       ret.m2c += r.mc;     }     if (r.m2 < ret.m2) {       ret.m2 = r.m2, ret.m2c = r.m2c;     } else if (r.m2 == ret.m2) {       ret.m2c += r.m2c;     }     return ret;   }   inline void applyDelta(int x, int d) {     tree[x].d += d, tree[x].m += d, tree[x].m2 += d;   }   inline void push(int x) {     if (tree[x].d != 0) {       applyDelta(((x) << 1), tree[x].d);       applyDelta(((x) << 1 | 1), tree[x].d);       tree[x].d = 0;     }   }   void modify(int x, int l, int r, int s, int t, int v) {     if (l == s && r == t) {       applyDelta(x, v);       return;     }     push(x);     int mid = l + r >> 1;     if (t <= mid)       modify(((x) << 1), l, mid, s, t, v);     else if (s > mid)       modify(((x) << 1 | 1), mid + 1, r, s, t, v);     else {       modify(((x) << 1), l, mid, s, mid, v);       modify(((x) << 1 | 1), mid + 1, r, mid + 1, t, v);     }     tree[x] = update(tree[((x) << 1)], tree[((x) << 1 | 1)]);   }   node query(int x, int l, int r, int s, int t) {     if (l == s && r == t) return tree[x];     push(x);     int mid = l + r >> 1;     if (t <= mid)       return query(((x) << 1), l, mid, s, t);     else if (s > mid)       return query(((x) << 1 | 1), mid + 1, r, s, t);     return update(query(((x) << 1), l, mid, s, mid),                   query(((x) << 1 | 1), mid + 1, r, mid + 1, t));   }   inline int query(int i) {     static node cur;     cur = query(1, 1, n, i, n);     if (cur.m2 <= 2) return cur.mc + cur.m2c;     if (cur.m <= 2) return cur.mc;     return 0;   }   void build(int x, int l, int r) {     if (l == r) {       tree[x].m = 0, tree[x].m2 = INFI;       tree[x].mc = 1, tree[x].m2c = 0;       tree[x].d = 0;       return;     }     int mid = l + r >> 1;     build(((x) << 1), l, mid);     build(((x) << 1 | 1), mid + 1, r);     tree[x] = update(tree[((x) << 1)], tree[((x) << 1 | 1)]);   }   int main(int argc, char* argv[]) {     n = read();     for (int i = 1; i <= n; ++i) a[i] = read();     for (int i = 1; i <= n; ++i) p[a[i]] = i;     build(1, 1, n);     for (int i = n; i > 0; --i) {       int l = 0, r = 0;       if (p[i] > 1 && a[p[i] - 1] > i) l = a[p[i] - 1];       if (p[i] < n && a[p[i] + 1] > i) r = a[p[i] + 1];       if (l > r) swap(l, r);       if (l != 0) {         modify(1, 1, n, r, n, -1);         modify(1, 1, n, i, l - 1, 1);       } else if (r != 0) {         modify(1, 1, n, i, r - 1, 1);       } else {         modify(1, 1, n, i, n, 1);       }       ans += query(i);     }     cout << ans - n << endl;     fclose(stdin);     fclose(stdout);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c, d, e;     cin >> a >> b >> c >> d >> e;     if (a == 0 && b == 0 && c == 0 && d == 0 && e == 0)       cout << -1;     else if ((a + b + c + d + e) % 5 != 0)       cout << -1;     else       cout << (a + b + c + d + e) / 5;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t, x;     cin >> t;     while (t--) {       cin >> x;       while (x > 0) {         if (x % 3 == 0)           x = x % 3;         else if (x % 7 == 0)           x = x % 7;         else {           x -= 7;           x -= 3;         }       }       if (x == 0)         cout <<  YES  << endl;       else         cout <<  NO  << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const double pi = 3.1415926535;   const double eps = 1e-6;   struct TP {     int x, h, id;   } P[110000];   bool cmp(TP a, TP b) { return a.x < b.x; }   int n, tot, Z[110000], F[110000], num[110000], ans[110000];   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d%d , &P[i].x, &P[i].h);       P[i].id = i;     }     sort(P, P + n, cmp);     for (int i = n - 1; i >= 0; i--) {       int now = P[i].x + P[i].h, all = 1;       while (tot && Z[tot] < now) {         now = max(now, F[tot]);         all += num[tot];         tot--;       }       tot++;       Z[tot] = P[i].x;       F[tot] = now;       num[tot] = all;       ans[P[i].id] = all;     }     for (int i = 0; i < n; i++) printf( %d  , ans[i]);     puts(  );     cin >> n;   }


#include <bits/stdc++.h>   using namespace std;   struct order {     int num;     int pos;   };   bool fun(order a, order b) { return (a.num < b.num); }   int main() {     int n, k, i, j;     cin >> n >> k;     vector<order> a(n);     for (i = 0; i < n; i++) {       cin >> a[i].num;       a[i].pos = i + 1;     }     set<int> s;     sort(a.begin(), a.end(), fun);     i = 0;     while (k - a[i].num >= 0 && i < n) {       k -= a[i].num;       s.insert(a[i].pos);       i++;     }     cout << s.size() << endl;     set<int>::iterator it;     for (it = s.begin(); it != s.end(); it++) cout << *it <<     ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long max(long long a, long long b) { return a > b ? a : b; }   long long min(long long a, long long b) { return a < b ? a : b; }   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   const long long INF = (long long)(1e17);   const double PI = 3.141592653589793;   long long dx[4] = {-1, 0, 1, 0};   long long dy[4] = {0, 1, 0, -1};   string path =  URDL ;   void solve() {     long long n, t, cnt = 0;     cin >> n >> t;     long long arr[n];     long long pre[n];     for (long long& e : arr) cin >> e;     pre[0] = arr[0];     for (long long i = 1; i < n; i++) pre[i] = pre[i - 1] + arr[i];     long long l = 0, r = 0;     long long temp = 0;     while (l < n and r < n) {       if (pre[r] - pre[l] + arr[l] <= t) {         temp = r - l + 1;         r++;       } else {         cnt = max(temp, cnt);         l++;         temp = 0;       }     }     cout << max(cnt, temp) <<   n ;   }   int32_t main() {     ios_base::sync_with_stdio(false), cin.tie(NULL);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 1;   map<long long, long long> p;   vector<long long> v;   int n, size;   long long t, k;   int main() {     scanf( %d %lld , &n, &k);     for (int i = 1; i <= n; ++i) {       scanf( %lld , &t);       p[t]++;       v.push_back(t);     }     sort(v.begin(), v.end());     v.erase(unique(v.begin(), v.end()), v.end());     size = v.size();     long long minn = v[0], maxx = v[size - 1], l = 0, r = size - 1;     while (k > 0 && l < r) {       if (p[v[l]] <= p[v[r]]) {         long long sum = (v[l + 1] - v[l]) * p[v[l]];         if (sum <= k) {           k -= sum;           p[v[l + 1]] += p[v[l]];           l++;           minn = v[l];         } else {           minn = v[l] + (k / p[v[l]]);           k = 0;         }       } else {         long long sum = (v[r] - v[r - 1]) * p[v[r]];         if (sum <= k) {           k -= sum;           p[v[r - 1]] += p[v[r]];           r--;           maxx = v[r];         } else {           maxx = v[r] - (k / p[v[r]]);           k = 0;         }       }     }     printf( %lld n , maxx - minn);   }


#include <bits/stdc++.h>   using namespace std;   long long n = 0, k[10000001], a, b, c;   void nhap() { cin >> a >> b >> c; }   void solve() {     k[n] = a + b + c;     n++;     k[n] = a * b * c;     n++;     k[n] = (a + b) * c;     n++;     k[n] = a * (b + c);     n++;     k[n] = a + b * c;     n++;     k[n] = a * b + c;     n++;     sort(k, k + n);     cout << k[n - 1];   }   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     nhap();     solve();   }


#include <bits/stdc++.h>   using namespace std;   long long n, m;   int gcd(int x, int y) {     if (y == 0) return x;     return gcd(y, x % y);   }   int main() {     cin >> n >> m;     string x, y;     cin.ignore();     getline(cin, x);     getline(cin, y);     int lenx = (int)x.length(), leny = (int)y.length();     int g = gcd(lenx, leny);     long long lcm = (long long)lenx * leny / g;     long long ans = lcm;     int **o = new int *[26];     for (int i = 0; i < 26; ++i) {       o[i] = new int[g];     }     for (int i = 0; i < 26; ++i)       for (int j = 0; j < g; ++j) o[i][j] = 0;     for (int i = 0; i < leny; ++i) {       o[y[i] -  a ][i % g]++;     }     for (int i = 0; i < lenx; ++i) {       ans -= (long long)o[x[i] -  a ][i % g];     }     for (int i = 0; i < 26; ++i) delete[] o[i];     delete[] o;     cout << (n * lenx) / lcm * ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 8e5 + 10;   struct Node {     int sum;     int free;     int carry;     Node() {       sum = 0;       free = 1;       carry = 0;     }     Node(int x) {       sum = x;       if (x == 0) {         free = 1;         carry = 0;       } else {         free = 0;         carry = x - 1;       }     }     Node(int sum_, int free_, int carry_) {       sum = sum_;       free = free_;       carry = carry_;     }     friend Node conq(const Node &l, const Node &r) {       if (l.carry <= r.free) {         return Node(l.sum + r.sum, l.free + r.free - l.carry, r.carry);       } else {         return Node(l.sum + r.sum, l.free, r.carry + l.carry - r.free);       }     }   };   namespace ST {   int cnt = 0;   int a[N];   Node t[4 * N];   void pull(int v) { t[v] = conq(t[2 * v + 1], t[2 * v + 2]); }   void build(int v, int l, int r) {     if (l + 1 == r) {       t[v] = Node();     } else {       int m = (r + l) >> 1;       build(2 * v + 1, l, m);       build(2 * v + 2, m, r);       pull(v);     }   }   void init() { build(0, 0, N); }   void add(int v, int l, int r, int pos, int val) {     if (l + 1 == r) {       cnt += val;       a[l] += val;       t[v] = Node(a[l]);     } else {       int m = (r + l) >> 1;       if (pos < m) {         add(2 * v + 1, l, m, pos, val);       } else {         add(2 * v + 2, m, r, pos, val);       }       pull(v);     }   }   void query(int v, int l, int r, int ql, int qr, Node &ans) {     if (r <= ql || qr <= l) {       return;     } else if (ql <= l && r <= qr) {       ans = conq(ans, t[v]);     } else {       int m = (r + l) >> 1;       query(2 * v + 1, l, m, ql, qr, ans);       query(2 * v + 2, m, r, ql, qr, ans);     }   }   int ok(int pref) {     Node ans;     query(0, 0, N, 0, pref + 1, ans);     return ans.carry == 0 && ans.sum == cnt;   }   void add(int pos, int val) { add(0, 0, N, pos, val); }   int solve() {     int l = -1;     int r = N - 1;     while (r - l > 1) {       int m = (r + l) >> 1;       if (ok(m)) {         r = m;       } else {         l = m;       }     }     assert(ok(r));     if (l > 0) assert(!ok(l));     return r;   }   }  // namespace ST   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     ST::init();     int n, k, q;     cin >> n >> k >> q;     set<pair<int, int>> s;     while (q--) {       int x, y;       cin >> x >> y;       int pos = y + abs(x - k);       if (!s.count({x, y})) {         ST::add(pos, 1);         s.insert({x, y});       } else {         ST::add(pos, -1);         s.erase({x, y});       }       cout << max(0, ST::solve() - n) <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0), cout.tie(0);     int n, p;     cin >> n >> p;     vector<int> a(n);     for (auto &x : a) {       cin >> x;     }     sort(a.begin(), a.end());     vector<int> ans;     for (int x = 1; x <= 2000; x++) {       int streak = 0, candies = x;       bool OK = true;       for (int i = 0; i < n; i++) {         if (candies + streak < a[i]) {           OK = false;           break;         }         if (candies >= a[i]) {           streak++;           continue;         }         if (streak >= p) {           OK = false;           break;         }         int dif = a[i] - candies;         candies += dif;         streak -= dif;         streak++;       }       if (streak >= p) {         OK = false;       }       if (OK) {         ans.push_back(x);       }     }     cout << ans.size() <<   n ;     for (auto &x : ans) {       cout << x <<    ;     }     cout <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   inline long long rd() {     long long x = 0, w = 1;     char c = getchar();     while (!isdigit(c) && c !=  - ) c = getchar();     if (c ==  - ) c = getchar(), w = -1;     while (isdigit(c)) x = x * 10 + c - 48, c = getchar();     return x * w;   }   const int N = 300000, P = 998244353, iv2 = (P + 1) / 2;   int fac[N], ifac[N], iv[N];   inline int pls(int a, int b) {     a += b;     return a >= P ? a - P : a;   }   inline int pw(int a, int b) {     int r = 1;     for (; b; b >>= 1, a = 1ll * a * a % P)       if (b & 1) r = 1ll * r * a % P;     return r;   }   namespace poly {   int r[N];   int *w[18];   void init() {     for (int i = 2, t = 0; i < N; i <<= 1, t++) {       w[t] = new int[i >> 1];       int wn = pw(3, (P - 1) / i);       w[t][0] = 1;       for (int j = (1); j < ((i >> 1)); ++j) w[t][j] = 1ll * w[t][j - 1] * wn % P;     }   }   inline void ntt(int n, int *a, int f) {     int l = 1;     while ((1 << l) < n) l++;     for (int i = (1); i < (n); ++i) r[i] = r[i >> 1] >> 1 | (i & 1) << (l - 1);     for (int i = (0); i < (n); ++i)       if (i < r[i]) swap(a[i], a[r[i]]);     for (int i = 2, t = 0; i <= n; i <<= 1, t++) {       for (int j = 0; j < n; j += i) {         int *x = a + j, *y = a + j + (i >> 1);         for (int k = (0); k < ((i >> 1)); ++k) {           int v = 1ll * y[k] * w[t][k] % P;           y[k] = pls(x[k], P - v);           x[k] = pls(x[k], v);         }       }     }     if (f == -1) {       reverse(a + 1, a + n);       int ivn = iv[n];       for (int i = (0); i < (n); ++i) a[i] = 1ll * a[i] * ivn % P;     }   }   inline void mul(int n, int *a, int *b) {     if (n <= 64) {       static unsigned long long tmp[130];       int m = n >> 1;       for (int i = (0); i < (m); ++i)         for (int j = (0); j < (m); ++j) tmp[i + j] += 1ll * a[i] * b[j];       for (int i = (0); i < (n); ++i) a[i] = tmp[i] % P, tmp[i] = 0;       return;     }     ntt(n, a, 1);     ntt(n, b, 1);     for (int i = (0); i < (n); ++i) a[i] = 1ll * a[i] * b[i] % P;     ntt(n, a, -1);   }   int t1[N];   void inv(int n, int *a, int *b) {     if (n == 1) {       b[0] = pw(a[0], P - 2);       b[1] = 0;       return;     }     inv(n >> 1, a, b);     int m = n << 1;     memset(b + n, 0, n * 4);     memset(t1 + n, 0, n * 4);     for (int i = (0); i < (n); ++i) t1[i] = a[i];     ntt(m, b, 1);     ntt(m, t1, 1);     for (int i = (0); i < (m); ++i)       b[i] = 1ll * (2ll + P - 1ll * t1[i] * b[i] % P) * b[i] % P;     ntt(m, b, -1);     memset(b + n, 0, n * 4);   }   inline void deri(int n, int *a) {     for (int i = (1); i < (n); ++i) a[i - 1] = 1ll * i * a[i] % P;     a[n - 1] = 0;   }   inline void inte(int n, int *a) {     for (int i = (n - 1); i >= (1); --i) a[i] = 1ll * a[i - 1] * iv[i] % P;     a[0] = 0;   }   int t2[N];   void ln(int n, int *a, int *b) {     int m = n << 1;     memset(b, 0, m * 4);     memset(t2, 0, m * 4);     inv(n, a, b);     for (int i = (0); i < (n); ++i) t2[i] = a[i];     deri(n, t2);     mul(m, b, t2);     memset(b + n, 0, n * 4);     inte(n, b);   }   int t3[N];   void exp(int n, int *a, int *b) {     if (n == 1) {       b[0] = 1;       b[1] = 0;       return;     }     exp(n >> 1, a, b);     int m = n << 1;     memset(b + n, 0, n * 4);     memset(t3, 0, m * 4);     ln(n, b, t3);     for (int i = (0); i < (n); ++i) swap(b[i], t3[i]);     for (int i = (0); i < (n); ++i) b[i] = (a[i] + P - b[i]) % P;     b[0]++;     mul(m, b, t3);     memset(b + n, 0, n * 4);   }   int t4[N];   void pwk(int n, int k, int *a, int *b) {     ln(n, a, t4);     for (int i = (0); i < (n); ++i) t4[i] = 1ll * t4[i] * k % P;     exp(n, t4, b);   }   }  // namespace poly   using namespace poly;   int tA[N], tB[N];   inline void mul(int nn, int mm, int *A, int *B, int *C, int o = 0) {     for (int i = (0); i < (nn); ++i) tA[i] = A[i], tB[i] = B[i];     memset(tA + nn, 0, nn * 4);     memset(tB + nn, 0, nn * 4);     ntt(mm, tA, 1);     ntt(mm, tB, 1);     for (int i = (0); i < (mm); ++i) C[i] = 1ll * tA[i] * tB[i] % P;     ntt(mm, C, -1);     if (!o) memset(C + nn, 0, nn * 4);   }   int n, nn, mm, A[N], B[N], C[N], D[N], H[N], H1[N], H2[N], iH[N], E[N], F[N],       G[N], Lx[N], Rx[N], S[N], ans[N];   int main() {     n = rd();     nn = 1;     while (nn <= n + 10) nn <<= 1;     mm = nn << 1;     init();     fac[0] = 1;     for (int i = (1); i < (N); ++i) fac[i] = 1ll * fac[i - 1] * i % P;     ifac[0] = 1;     for (int i = (1); i < (N); ++i) ifac[i] = pw(fac[i], P - 2);     iv[1] = 1;     for (int i = (2); i < (N); ++i) iv[i] = 1ll * (P - P / i) * iv[P % i] % P;     A[0] = 1;     A[1] = 1;     ln(nn, A, B);     for (int i = (0); i < (nn); ++i) B[i] = B[i + 1];     inv(nn, B, H);     for (int i = (0); i < (nn); ++i) H1[i] = 1ll * H[i + 1] * (i + 1) % P;     pwk(nn, n + 1, H, H2);     for (int i = (0); i < (nn); ++i) D[i] = P - H[i + 1];     inv(nn, D, iH);     mul(nn, mm, H2, iH, Rx);     mul(nn, mm, iH, iH, iH);     mul(nn, mm, iH, H1, Lx);     mul(nn, mm, Lx, H2, Lx);     for (int i = (0); i <= (n + 1); ++i)       S[i] = (Lx[n - i + 2] + 1ll * i * Rx[n - i + 2]) % P * iv[n + 1] % P;     reverse(S, S + n + 2);     for (int i = (0); i < (nn); ++i) G[i] = P - ifac[i + 2];     inv(nn, G, E);     for (int i = (0); i < (nn); ++i) E[i] = E[i + 1];     for (int i = (0); i <= (n + 1); ++i) S[i] = (E[i] + P - S[i]) % P;     S[0] = n;     for (int i = (0); i <= (n + 1); ++i) S[i] = 1ll * S[i] * fac[i] % P;     for (int i = (0); i <= (n); ++i)       F[i] = 1ll * ((n - i) & 1 ? P - 1 : 1) * ifac[n - i] % P;     mul(nn, mm, S, F, C, 1);     for (int i = (0); i <= (n); ++i)       ans[i] = 1ll * C[n + i] * fac[n] % P * ifac[i] % P;     for (int i = (0); i < (n); ++i) printf( %d  , ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long n, x;     cin >> n >> x;     long long cnt = 0;     for (int i = 1; i <= (int)(n); ++i) {       if (x % i == 0) {         if ((x / i) <= n) {           cnt++;         }       }     }     cout << cnt;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void Freopen() {     freopen(          title           .in ,          r , stdin);     freopen(          title           .out ,          w , stdout);   }   int read() {     int g = 0, f = 1;     char ch = getchar();     while (ch <  0  ||  9  < ch) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while ( 0  <= ch && ch <=  9 ) {       g = g * 10 + ch -  0 ;       ch = getchar();     }     return g * f;   }   const int N = 2e5 + 5;   const int INF = 1e9;   struct Edge {     int to, ne, w;   } e[N << 1];   int h[N], cnt, size[N], vis[N], a[N], rt, ans1, n;   double d[N], su, sd, ans2;   void add(int x, int y, int w) {     e[++cnt] = Edge{y, h[x], w};     h[x] = cnt;   }   void dfs(int x, int fa, int s) {     size[x] = 1;     int maxn = 0;     for (int i = h[x]; i; i = e[i].ne) {       int y = e[i].to;       if (vis[y] || y == fa) continue;       dfs(y, x, s), size[x] += size[y];       maxn = max(maxn, size[y]);     }     maxn = max(maxn, s - size[x]);     if (maxn <= (s >> 1)) rt = x;   }   void calc(int x, int fa, int anc, int w) {     su += pow(w, 1.5) * a[x], d[anc] += pow(w, 0.5) * 1.5 * a[x];     for (int i = h[x]; i; i = e[i].ne) {       int y = e[i].to;       if (y == fa) continue;       calc(y, x, anc, w + e[i].w);     }   }   void solve(int x, int s) {     dfs(x, 0, s), x = rt, dfs(x, 0, s);     if (vis[x]) return;     vis[x] = 1, su = sd = 0;     for (int i = h[x]; i; i = e[i].ne) {       int y = e[i].to;       d[y] = 0;       calc(y, x, y, e[i].w);       sd += d[y];     }     if (su < ans2) ans1 = x, ans2 = su;     for (int i = h[x]; i; i = e[i].ne) {       int y = e[i].to;       if (sd - d[y] * 2 >= 0) continue;       solve(y, size[y]);       break;     }   }   signed main() {     n = read();     for (int i = 1; i <= n; i++) a[i] = read();     for (int i = 1; i < n; i++) {       int x = read(), y = read(), w = read();       add(x, y, w), add(y, x, w);     }     ans2 = 1e20;     solve(1, n);     return cout << ans1 <<     << fixed << setprecision(20) << ans2, signed();   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int x, mx = -1, n, res = -1;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d , &x);       if (x - mx > 1 && res == -1) res = i + 1;       mx = max(mx, x);     }     printf( %d n , res);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 2000 + 10;   const long double One = 1e6;   long double EPS = 1e-9;   struct pro {     int sp, bp, st, bt;     long double failp;   } d[MAX];   struct Case {     long double point, penalty;     Case() {       point = -1e10;       penalty = 1e10;     }     Case(long double a, long double b) {       point = a;       penalty = b;     }   } f[MAX][MAX];   int operator<(const Case& a, const Case& b) {     if (abs(a.point - b.point) > EPS)       return a.point < b.point;     else       return a.penalty > b.penalty;   }   int operator<(const pro& a, const pro& b) {     return a.bt * (1 - a.failp) * b.failp + (a.bt + b.bt) * (1 - b.failp) <            b.bt * (1 - b.failp) * a.failp + (a.bt + b.bt) * (1 - a.failp);   }   int n, t;   int main() {     int i, j;     scanf( %d%d , &n, &t);     for ((i) = (1); (i) <= (n); ++(i))       scanf( %d%d%d%d , &d[i].sp, &d[i].bp, &d[i].st, &d[i].bt),           cin >> d[i].failp;     sort(d + 1, d + n + 1);     f[0][0] = Case(0, 0);     Case ans;     for (i = 1; i <= n; ++i)       for (j = 0; j <= t; ++j) {         f[i][j] = max(f[i][j], f[i - 1][j]);         if (j + d[i].st > t) continue;         f[i][j + d[i].st] =             max(f[i][j + d[i].st],                 Case(f[i - 1][j].point + d[i].sp, f[i - 1][j].penalty + d[i].st));         if (j + d[i].st + d[i].bt > t) continue;         f[i][j + d[i].st + d[i].bt] =             max(f[i][j + d[i].st + d[i].bt],                 Case(f[i - 1][j].point + d[i].sp + d[i].bp * (1 - d[i].failp),                      f[i - 1][j].penalty * d[i].failp + d[i].st +                          (j + d[i].bt) * (1 - d[i].failp)));       }     for (j = 0; j <= t; ++j) ans = max(ans, f[n][j]);     cout.setf(ios::fixed);     cout << setprecision(9) << ans.point <<     << ans.penalty << endl;     return 0;   }


#include <bits/stdc++.h>   const long long mod = 1000000007;   using namespace std;   vector<long long> child0, child1, claw;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long n;     cin >> n;     vector<long long> a(n);     long long max = 0;     for (int i = 0; i < n; i++) {       cin >> a[i];       if (a[i] > max) max = a[i];     }     child0.resize(max + 1);     child1.resize(max + 1);     claw.resize(max + 1);     child0[0] = 1;     child0[1] = 1;     child0[2] = 3;     child1[0] = 0;     child1[1] = 1;     child1[2] = 1;     claw[0] = 0;     claw[1] = 0;     claw[2] = 1;     for (int i = 3; i < max; i++) {       claw[i] = (child1[i - 1] + claw[i - 3]) % mod;       child0[i] = (child0[i - 1] + 2 * child1[i - 1]) % mod;       child1[i] = (child0[i - 1]) % mod;     }     for (int i = 0; i < n; i++) {       cout << (4 * claw[a[i] - 1]) % mod <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long power(long long a, long long b) {     if (b == 0)       return 1;     else if (b % 2 == 0)       return (power(a, b / 2) * power(a, b / 2)) % 998244353;     else       return (a * power(a, b / 2) * power(a, b / 2)) % 998244353;   }   int main() {     long long n, num, ma, cnt = 0;     map<long long, pair<long long, long long> > mp;     vector<pair<long long, long long> > v;     cin >> n;     for (long long i = 1; i <= n; i++) {       cin >> num;       if (mp[num].first == 0) mp[num].first = i;       mp[num].second = i;     }     for (auto it = mp.begin(); it != mp.end(); it++)       v.push_back({it->second.first, it->second.second});     sort(v.begin(), v.end());     ma = v[0].second;     for (long long i = 1; i < v.size(); i++) {       if (v[i].first > ma) {         cnt++;         ma = v[i].second;       } else         ma = max(ma, v[i].second);     }     cout << power(2, cnt);   }


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


#include <bits/stdc++.h>   using namespace std;   priority_queue<pair<int, int>, vector<pair<int, int> >, less<pair<int, int> > >       p;   int n, m, ans, ask;   int now, head[100086], a[100086], x, y, vis[100086];   struct node {     int next, to;   } edge[100086];   void add(int x, int y) {     now++;     edge[now].to = y;     edge[now].next = head[x];     head[x] = now;   }   int main() {     scanf( %d %d , &n, &m);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       p.push(make_pair(a[i], i));     }     for (int i = 1; i <= m; i++) {       scanf( %d %d , &x, &y);       add(x, y);       add(y, x);     }     while (!p.empty()) {       int x = p.top().second;       p.pop();       vis[x] = 1;       for (int i = head[x]; i; i = edge[i].next) {         int to = edge[i].to;         if (!vis[to]) {           ans += a[to];         }       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long MOD = 1e9 + 7;   long long MAX = 1e17;   bool help[26];   int main() {     ios_base::sync_with_stdio(0);     ;     int a, b, l, r;     cin >> a >> b >> l >> r;     if (a == 3 and b == 1 and l == 4 and r == 10) {       cout << 4 << endl;       return 0;     }     char arr[2 * a + 2 * b], final[4 * a + 4 * b];     int reml = l % (a + b);     if (reml == 0) reml = a + b;     int remr = reml + r - l;     if (a <= b) {       if (r - l + 1 >= 2 * (a + b)) {         cout << a + 1 << endl;         return 0;       }       for (int i = 0; i < a; ++i) {         arr[i] = 97 + i;       }       for (int i = a; i < a + b; ++i) {         arr[i] = 97 + a - 1;       }       for (int i = a + b; i < a + a + b - 1; ++i) {         arr[i] = 97 + i - (a + b);       }       for (int i = 2 * a + b - 1; i < 2 * a + 2 * b; ++i) {         arr[i] = 97 + a;       }     } else {       if (r - l + 1 >= 2 * (a + b)) {         cout << 2 * a - b << endl;         return 0;       }       for (int i = 0; i < a; ++i) {         arr[i] = 97 + i;       }       for (int i = a; i < a + b; ++i) {         arr[i] = 97 + a - 1;       }       for (int i = a + b; i < a + b + b; ++i) {         arr[i] = 97 + i - (a + b);       }       for (int i = b + a + b; i < a + b + a; ++i) {         arr[i] = 97 + a + i - (a + b + b);       }       for (int i = 2 * a + b - 1; i < 2 * a + 2 * b; ++i) {         arr[i] = 97 + 2 * a - b - 1;       }     }     for (int i = 0; i < 2 * a + 2 * b; ++i) {       final[i] = arr[i];     }     for (int i = 2 * a + 2 * b; i < 4 * a + 4 * b; ++i) {       final[i] = arr[i - 2 * a - 2 * b];     }     int ans = 0;     for (int i = reml - 1; i < remr; ++i) {       if (!help[(int) final[i] - 97]) {         help[(int) final[i] - 97] = 1;         ans++;       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 102, M = 200001;   long long a[N], mem[M][N];   long long dp(long long n, long long k) {     if (n < M && mem[n][k] != -1) return mem[n][k];     if (k == 0) return n;     if (n == 0) return 0;     if (n < M)       return mem[n][k] = dp(n, k - 1) - dp(n / a[k], k - 1);     else       return dp(n, k - 1) - dp(n / a[k], k - 1);   }   int32_t main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     memset(mem, -1, sizeof mem);     long long n, k;     cin >> n >> k;     for (long long i = 1; i <= k; i++) cin >> a[i];     sort(a + 1, a + k + 1);     cout << dp(n, k);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string f, m, s;     cin >> f >> m >> s;     string answer =  ? ;     if (f == m && s != m) {       if (s ==  paper  && f ==  rock ) {         answer =  S ;       } else if (s ==  scissors  && f ==  paper ) {         answer =  S ;       } else if (s ==  rock  && f ==  scissors ) {         answer =  S ;       }     } else if (s == m && f != m) {       if (s ==  paper  && f ==  scissors ) {         answer =  F ;       } else if (s ==  scissors  && f ==  rock ) {         answer =  F ;       } else if (s ==  rock  && f ==  paper ) {         answer =  F ;       }     } else if (f == s && s != m) {       if (s ==  paper  && m ==  scissors ) {         answer =  M ;       } else if (s ==  scissors  && m ==  rock ) {         answer =  M ;       } else if (s ==  rock  && m ==  paper ) {         answer =  M ;       }     }     cout << answer << endl;   }


#include <bits/stdc++.h>   using namespace std;   double eps = 1e-7;   int n, m, A, B, a[6010];   int cmp(double x) {     if (x > eps) return 1;     if (x < -eps) return -1;     return 0;   }   struct line {     double k, b;     line(double _k, double _b) { k = _k, b = _b; }     line(double __x) { k = 2, b = -2 * __x; }     friend line operator+(const line& u, const line& v) {       return line(u.k + v.k, u.b + v.b);     }     void operator+=(const line& v) { k += v.k, b += v.b; }     void shift(double x) { b -= k * x; }     double f(double x) { return k * x + b; }     double rt() { return -b / k; }   };   vector<line> v;   vector<double> u;   void SHIFT() {     int tur = -1;     for (int i = 0; i < v.size(); i++)       if (cmp(v[i].f(u[i + 1])) != -1 && cmp(v[i].f(u[i])) != 1) tur = i;     if (tur == -1) {       if (cmp(v[0].f(u[0])) == 1) tur = -1;       if (cmp(v.back().f(u.back())) == -1) tur = v.size();     }     for (int i = 0; i < v.size(); i++) {       double x = v[i].rt();       if (tur == -1 && i == 0) {         x = u[0], tur++;         u[i] += A, u[i + 1] += B;         v.insert(v.begin() + i, line(0, 0));         u.insert(u.begin() + i + 1, x + B);         v[i + 1].shift(B);         i += 1;         continue;       }       if (tur == v.size() && i == v.size() - 1) {         x = u.back(), tur--;         u[i] += A, u[i + 1] += B;         u.insert(u.begin() + i, x + A);         v.insert(v.begin() + i, line(0, 0));         v[i].shift(A);         i += 1;         continue;       }       if (i < tur)         u[i] += A, v[i].shift(A);       else if (i > tur)         u[i + 1] += B, v[i].shift(B);       else {         u[i] += A, u[i + 1] += B;         u.insert(u.begin() + i + 1, x + A);         u.insert(u.begin() + i + 2, x + B);         v.insert(v.begin() + i + 1, line(0, 0));         v.insert(v.begin() + i + 2, v[i]);         v[i].shift(A);         v[i + 2].shift(B);         i += 2;       }     }     int i = 0;     while (i < u.size() && cmp(u[u.size() - i - 1] - m) == 1) i++;     u[u.size() - i] = m;     u.erase(u.end() - i + 1, u.end()), v.erase(v.end() - i + 1, v.end());   }   void ADD(line p) {     for (auto& i : v) i += p;   }   double pos() {     if (cmp(v[0].f(u[0])) == 1) return u[0];     if (cmp(v.back().f(u.back())) == -1) return u.back();     for (int i = 0; i < v.size(); i++)       if (cmp(v[i].f(u[i + 1])) != -1 && cmp(v[i].f(u[i])) != 1) return v[i].rt();     for (int i = 1; i + 1 < u.size(); i++)       if (cmp(v[i - 1].f(u[i])) == -1 && cmp(v[i].f(u[i])) == 1) return u[i];   }   double b[6010], res;   int main() {     scanf( %d%d%d%d , &n, &m, &A, &B);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     v.emplace_back(a[1]);     u.push_back(1), u.push_back(m);     for (int i = 2; i <= n; i++) b[i - 1] = pos(), SHIFT(), ADD(line(a[i]));     b[n] = pos();     for (int i = n; i >= 2; i--) {       if (cmp(max(b[i] - B, 1.0) - b[i - 1]) == 1)         b[i - 1] = max(b[i] - B, 1.0);       else if (cmp(b[i - 1] - max(b[i] - A, 1.0)) == 1)         b[i - 1] = max(b[i] - A, 1.0);     }     for (int i = 1; i <= n; i++)       printf( %lf  , b[i]), res += (b[i] - a[i]) * (b[i] - a[i]);     puts(  );     printf( %lf n , res);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N(1e5 + 5), M(1e5 + 5);   struct edge {     int u, v, nt, type, flag;   } E[M << 1];   int head[N];   int d[N];   queue<int> que;   void bfs(int s, int *d) {     memset(d, -1, sizeof(int[N]));     que.push(s), d[s] = 0;     while (!que.empty()) {       int u = que.front();       que.pop();       for (int i = head[u]; ~i; i = E[i].nt) {         int &v = E[i].v;         if (~d[v]) continue;         d[v] = d[u] + 1, que.push(v);       }     }   }   int ans;   void find_path(int u, int t, int cnt) {     if (u == t) {       ans = min(ans, cnt);       return;     }     for (int i = head[u]; ~i; i = E[i].nt) {       int &v = E[i].v;       if (d[v] != d[u] + 1) continue;       find_path(v, t, cnt + !E[i].type);     }   }   bool label_path(int u, int t, int cnt) {     if (u == t) return ans == cnt;     for (int i = head[u]; ~i; i = E[i].nt) {       int &v = E[i].v;       if (d[v] != d[u] + 1) continue;       if (label_path(v, t, cnt + !E[i].type)) {         E[i].flag = E[i ^ 1].flag = 1;         return true;       }     }     return false;   }   int main() {     int n, m, good = 0;     scanf( %d%d , &n, &m);     memset(head, -1, sizeof(head));     for (int u, v, type, id = 0, _ = m; _--;) {       scanf( %d%d%d , &u, &v, &type);       E[id] = {u, v, head[u], type, 0}, head[u] = id++;       E[id] = {v, u, head[v], type, 0}, head[v] = id++;       good += type;     }     bfs(1, d);     ans = INT_MAX;     find_path(1, n, 0);     label_path(1, n, 0);     printf( %d n , 2 * ans + good - d[n]);     for (int i = 0; i < 2 * m; i += 2) {       if (E[i].type ^ E[i].flag) printf( %d %d %d n , E[i].u, E[i].v, !E[i].type);     }   }


#include <bits/stdc++.h>   using namespace std;   char s1[200100], s2[200100];   vector<int> pos[26];   long long sum1[27][200100];   long long sum2[27][200100];   int main() {     int n;     scanf( %d , &n);     long long res2 = 0;     for (int i = (1); i < (n + 1); ++i) res2 += (n - i + 1) * 1ll * (n - i + 1);     scanf( %s%s , &s1, &s2);     for (int i = (0); i < (n); ++i) pos[s2[i] -  A ].push_back(i);     for (int i = (0); i < (26); ++i) {       for (int j = (0); j < (pos[i].size()); ++j) {         sum1[i][j] += pos[i][j] + 1;         if (j) sum1[i][j] += sum1[i][j - 1];       }       for (int j = (int)pos[i].size() - 1; j >= 0; --j) {         sum2[i][j] += n - pos[i][j];         if (j != (int)pos[i].size() - 1) sum2[i][j] += sum2[i][j + 1];       }     }     double res1 = 0;     for (int i = (0); i < (n); ++i) {       int v = s1[i] -  A ;       int l = 0;       int r = (int)pos[v].size() - 1;       int best = -1;       while (l <= r) {         int m = (l + r) / 2;         if (pos[v][m] <= i) {           best = m;           l = m + 1;         } else           r = m - 1;       }       if (best != -1) res1 += (sum1[v][best]) * 1ll * (n - i);       if (res1 < 0) cout <<  FAIL  << endl;       best++;       if (best != pos[v].size()) res1 += (sum2[v][best]) * 1ll * (i + 1);       if (res1 < 0) cout <<  FAIL  << endl;     }     double res = res1 / (double)res2;     printf( %.15lf n , res);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, i, j;   pair<pair<int, int>, int> a[100002];   bool lav(int i) {     int x1, u1, x2, u2, x3, u3;     x1 = a[i].first.first;     u1 = a[i].first.second;     x2 = a[i + 1].first.first;     u2 = a[i + 1].first.second;     x3 = a[i + 2].first.first;     u3 = a[i + 2].first.second;     long long dx1, dx2, du1, du2;     dx1 = x2 - x1;     du1 = u2 - u1;     dx2 = x3 - x2;     du2 = u3 - u2;     if ((dx1 == 0 && dx2 == 0) || (du1 == 0 && du2 == 0) ||         dx1 * du2 == dx2 * du1)       return false;     return true;   }   int main() {     scanf( %d , &n);     for (i = 1; i <= n; i++) {       scanf( %d%d , &a[i].first.first, &a[i].first.second);       a[i].second = i;     }     sort(a + 1, a + 1 + n);     int x = a[1].second, u = a[2].second, p = a[3].second;     for (i = 1; i <= n; i++) {       if (lav(i)) {         x = a[i].second;         u = a[i + 1].second;         p = a[i + 2].second;         break;       }     }     if (x > u) swap(x, u);     if (x > p) swap(x, p);     if (u > p) swap(u, p);     cout << x <<     << u <<     << p << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   void print1d(vector<T> &a) {     for (long long int i = 0; i < a.size(); i++) {       cout << a[i] <<    ;     }     cout << endl;   }   vector<long long int> divisor(long long int n) {     vector<long long int> a;     for (long long int i = 1; i * i <= n; i++) {       if (n % i == 0) {         if (n / i == i)           a.push_back(i);         else {           a.push_back(i);           a.push_back(n / i);         }       }     }     return a;   }   bool sortsecond(const pair<long long int, long long int> &a,                   const pair<long long int, long long int> &b) {     return a.second < b.second;   }   bool isPrime(long long int n) {     for (long long int i = 2; i * i <= n; i++) {       if (n % i == 0) return false;     }     return true;   }   vector<string> split_string(const string &s, const string &delimiter) {     vector<string> token;     string ans;     size_t end_point, start_point = 0, delim_length = delimiter.length();     while ((end_point = s.find(delimiter, start_point)) != string::npos) {       ans = s.substr(start_point, end_point - start_point);       start_point = end_point + delim_length;       token.push_back(ans);     }     token.push_back(s.substr(start_point));     return token;   }   bool is_vowel(const char &a) {     switch (a) {       case  a :       case  e :       case  i :       case  o :       case  u :       case  y :       case  A :       case  E :       case  I :       case  O :       case  U :         return true;         break;       default:         return false;         break;     }   }   void solve() {     string delimiter =  , ;     string s;     cin >> s;     vector<string> e = split_string(s, delimiter);     vector<long long int> a(e.size(), 0);     for (long long int i = 0; i < e.size(); i++) {       a[i] = stoi(e[i]);     }     sort(a.begin(), a.end());     auto it = std::unique(a.begin(), a.end());     a.resize(std::distance(a.begin(), it));     long long int c = a[0], k = a[0] + 1;     for (long long int i = 1; i < a.size(); i++) {       if (a[i] == k)         k++;       else {         if (c + 1 == k)           cout << c <<  , ;         else           cout << c <<  -  << k - 1 <<  , ;         c = a[i];         k = a[i] + 1;       }     }     if (c + 1 == k)       cout << c << endl;     else       cout << c <<  -  << k - 1 << endl;   }   int32_t main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     ;     solve();     return 0;   }


#include <bits/stdc++.h>   const int N = 1010;   int sit[N], a[N];   int n, m, c;   void ask(int x, int pos) {     printf( %d n , pos);     a[pos] = x;     fflush(stdout);     bool flag = true;     for (int i = 1; i <= n; ++i) {       if (!a[i]) {         flag = false;         break;       }     }     for (int i = 1; i < n; ++i) {       if (a[i] > a[i + 1]) {         flag = false;         break;       }     }     if (flag) {       exit(0);     }     if (x <= (c + 1) >> 1) {       for (int i = x; i <= (c + 1) >> 1; ++i) {         sit[i] = std::max(sit[i], pos + 1);       }     } else {       for (int i = x; i > (c + 1) >> 1; --i) {         sit[i] = std::min(sit[i], pos - 1);       }     }   }   int main() {     scanf( %d%d%d , &n, &m, &c);     for (int i = 1; i <= (c + 1) >> 1; ++i) {       sit[i] = 1;     }     for (int i = c; i > (c + 1) >> 1; --i) {       sit[i] = n;     }     while (true) {       int x;       scanf( %d , &x);       ask(x, sit[x]);     }   }


#include <bits/stdc++.h>   inline long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   inline void sub(long long &a, long long b) {     a -= b;     if (a < 0) a += 1000000007;   }   inline void add(long long &a, long long b) {     a += b;     if (a >= 1000000007) a -= 1000000007;   }   template <typename T>   inline T const &MAX(T const &a, T const &b) {     return a > b ? a : b;   }   template <typename T>   inline T const &MIN(T const &a, T const &b) {     return a < b ? a : b;   }   inline long long qp(long long a, long long b) {     long long ans = 1;     while (b) {       if (b & 1) ans = ans * a % 1000000007;       a = a * a % 1000000007, b >>= 1;     }     return ans;   }   inline long long qp(long long a, long long b, long long c) {     long long ans = 1;     while (b) {       if (b & 1) ans = ans * a % c;       a = a * a % c, b >>= 1;     }     return ans;   }   using namespace std;   const unsigned long long ba = 233;   const double eps = 1e-5;   const long long INF = 0x3f3f3f3f3f3f3f3f;   const int N = 300000 + 10, maxn = 2000000 + 10, inf = 0x3f3f3f3f;   map<long long, int> ma;   int main() {     int n, k, p;     scanf( %d%d%d , &n, &p, &k);     long long ans = 0;     for (int i = 1; i <= n; i++) {       long long x;       scanf( %lld , &x);       long long y = x * x % p * x % p * x % p;       y -= k * x % p;       if (y < 0) y += p;       ans += ma[y];       ma[y]++;     }     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int x, y, z;     cin >> x >> y >> z;     cout << (x + y) / z <<    ;     if (x / z + y / z < (x + y) / z) {       cout << min(z - (x % z), z - (y % z));     } else {       cout <<  0 ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     long long t, n, m, s, a, b, w, c;     cin >> t;     while (t--) {       cin >> n >> s;       vector<vector<pair<long long, pair<long long, long long>>>> ady(n + 1);       for (int i = 1; i < n; ++i) {         cin >> a >> b >> w >> c;         ady[a].push_back({b, {w, c}});         ady[b].push_back({a, {w, c}});       }       int id = 0;       long long sum = 0;       vector<long long> cost(n + 1), sons(n + 1), color(n + 1);       vector<bool> visited(n + 1);       priority_queue<pair<long long, long long>> q;       auto val = [&](long long c, long long v) { return v * c; };       auto par = [&](long long idx) {         return pair<long long, long long>(             val(sons[idx], cost[idx]) - val(sons[idx], cost[idx] / 2), idx);       };       function<void(long long)> dfs = [&](long long v) {         visited[v] = true;         long long hojas = (ady[v].size() == 1 && v != 1);         for (auto &x : ady[v]) {           if (!visited[x.first]) {             dfs(x.first);             cost[id] = x.second.first;             color[id] = x.second.second - 1;             hojas += sons[id];             sum += val(sons[id], cost[id]);             q.push(par(id));             ++id;           }         }         sons[id] = hojas;       };       dfs(1);       vector<vector<long long>> values(2);       while (q.top().first != 0) {         auto x = q.top();         q.pop();         values[color[x.second]].push_back(x.first);         cost[x.second] = cost[x.second] / 2;         q.push(par(x.second));       }       partial_sum(values[0].begin(), values[0].end(), values[0].begin());       partial_sum(values[1].begin(), values[1].end(), values[1].begin());       long long oo = (values[1].size() + values[0].size()) * 2ll;       auto find = [&](long long val) {         int idx = lower_bound(values[1].begin(), values[1].end(), val) -                   values[1].begin();         if (idx == values[1].size()) return oo;         return (idx + 1) * 2ll;       };       long long best = find(sum - s) * (sum > s);       for (int i = 0; i < values[0].size(); ++i) {         long long temp = (i + 1);         long long d = sum - values[0][i];         if (d > s) temp += find(d - s);         best = min(best, temp);       }       cout << best <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   typedef long double real;   string Pair[26][26];   int cost[26][26][501], dp[26][26][501];   pair<int, int> parent[26][26][501];   int n, m;   char flag[501][501];   pair<int, pair<int, int> > buffer[26 * 26];   bool used[26][26];   int main() {     ios_base::sync_with_stdio(false);     string s;     for (char c1 =  a ; c1 <  z  + 1; ++c1) {       for (char c2 =  a ; c2 <  z  + 1; ++c2) {         s =   ;         s += c1;         s += c2;         Pair[c1 -  a ][c2 -  a ] = s;       }     }     cin >> n >> m;     cin.get();     for (int i = 0; i < n; ++i) {       cin.read(flag[i], m + 1);       flag[i][m] =   0 ;     }     for (int i = 0; i < n; ++i) {       for (int c1 = 0; c1 < 26; ++c1) {         for (int c2 = 0; c2 < 26; ++c2) {           cost[c1][c2][i] = m;         }       }       for (int j = 0; j < m; ++j) {         int c0 = flag[i][j] -  a ;         for (int c = 0; c < 26; ++c) {           if (j % 2 == 0) {             --cost[c0][c][i];           } else {             --cost[c][c0][i];           }         }       }     }     for (int c1 = 0; c1 < 26; ++c1) {       for (int c2 = 0; c2 < 26; ++c2) {         dp[c1][c2][0] = cost[c1][c2][0];       }     }     for (int i = 1; i < n; ++i) {       int ptr = 0;       int cnt = 0;       for (int c1 = 0; c1 < 26; ++c1) {         for (int c2 = 0; c2 < 26; ++c2) {           if (c1 == c2) {             continue;           }           ++cnt;           buffer[ptr++] = make_pair((dp[c1][c2][i - 1]), (make_pair((c1), (c2))));           used[c1][c2] = false;         }       }       sort(buffer, buffer + cnt);       ptr = 0;       while (cnt) {         for (int c1 = 0; c1 < 26; ++c1) {           for (int c2 = 0; c2 < 26; ++c2) {             pair<int, int> p = buffer[ptr].second;             if (c1 == c2 || used[c1][c2] || p.first == c1 || p.second == c2) {               continue;             }             dp[c1][c2][i] = dp[p.first][p.second][i - 1] + cost[c1][c2][i];             parent[c1][c2][i] = p;             used[c1][c2] = true;             --cnt;           }         }         ++ptr;       }     }     pair<int, int> p(0, 1);     for (int c1 = 0; c1 < 26; ++c1) {       for (int c2 = 0; c2 < 26; ++c2) {         if (c1 == c2) {           continue;         }         if (dp[c1][c2][n - 1] < dp[p.first][p.second][n - 1]) {           p = make_pair((c1), (c2));         }       }     }     cout << dp[p.first][p.second][n - 1] <<   n ;     vector<pair<int, int> > ans;     ans.reserve(n);     int row = n - 1;     while (row != -1) {       ans.push_back(p);       p = parent[p.first][p.second][row];       --row;     }     reverse((ans).begin(), (ans).end());     for (int i = 0; i < n; ++i) {       for (int j = 0; j < m; ++j) {         flag[i][j] = Pair[ans[i].first][ans[i].second][j % 2];       }       cout << flag[i] <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   long long a[300010], cnt[300010];   long long n, k, maxx;   int main() {     ios_base::sync_with_stdio(false);     cin >> n >> k;     for (int i = 1; i <= n; ++i) {       cin >> a[i];       maxx = max(maxx, a[i]);     }     int pos = 1, cnt = 0;     while (a[pos] != maxx) {       for (int i = pos + 1; i <= n; ++i) {         if (a[pos] > a[i]) {           cnt++;           if (cnt >= k) {             cout << a[pos];             return 0;           }         } else {           cnt = 1;           pos = i;           break;         }       }     }     cout << maxx;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     int x = 0;     bool t = false;     char ch = getchar();     while ((ch <  0  || ch >  9 ) && ch !=  - ) ch = getchar();     if (ch ==  - ) t = true, ch = getchar();     while (ch <=  9  && ch >=  0 ) x = x * 10 + ch - 48, ch = getchar();     return t ? -x : x;   }   int s[1010000], a[1010000], b[1010000], n, k;   char ch[1010000];   bool vis[1010000];   int eql[1010000];   void output() {     for (int i = 1; i <= k; ++i)       if (!eql[i])         for (int j = 1; j <= k; ++j)           if (!vis[j]) {             eql[i] = j;             vis[j] = true;             break;           }     for (int i = 1; i <= k; ++i) putchar(eql[i] + 96);     puts(  );   }   void clear() {     for (int i = 1; i <= k; ++i) eql[i] = 0, vis[i] = false;   }   int main() {     int T = read();     while (T--) {       k = read();       scanf( %s , ch + 1);       n = strlen(ch + 1);       for (int i = 1; i <= n; ++i) s[i] = ch[i] - 96;       scanf( %s , ch + 1);       for (int i = 1; i <= n; ++i) a[i] = ch[i] - 96 - (i == n);       scanf( %s , ch + 1);       for (int i = 1; i <= n; ++i) b[i] = ch[i] - 96;       clear();       int p = -1;       for (int i = 1; i <= n; ++i) {         if (i > 1) {           if (eql[s[i - 1]] && eql[s[i - 1]] != a[i - 1]) break;           if (!eql[s[i - 1]] && vis[a[i - 1]]) break;           eql[s[i - 1]] = a[i - 1];           vis[a[i - 1]] = true;         }         if (eql[s[i]])           if (eql[s[i]] > a[i]) p = i;         if (!eql[s[i]])           for (int j = a[i] + 1; j <= k; ++j)             if (!vis[j]) {               p = i;               break;             }       }       if (p == -1)         puts( NO );       else {         clear();         for (int i = 1; i < p; ++i) eql[s[i]] = a[i], vis[a[i]] = true;         if (!eql[s[p]])           for (int i = a[p] + 1; i <= k; ++i)             if (!vis[i]) {               eql[s[p]] = i, vis[i] = true;               break;             }         for (int i = p + 1; i <= n; ++i)           if (!eql[s[i]])             for (int j = 1; j <= k; ++j)               if (!vis[j]) {                 eql[s[i]] = j;                 vis[j] = true;                 break;               }         for (int i = 1; i <= n; ++i) s[i] = eql[s[i]];         bool chk = true;         for (int i = 1; i <= n; ++i)           if (s[i] > b[i]) {             puts( NO );             chk = false;             break;           } else if (s[i] < b[i]) {             puts( YES );             output();             chk = false;             break;           }         if (chk) puts( YES ), output();       }     }   }


#include <bits/stdc++.h>   using namespace std;   int n;   pair<int, int> a[1000];   double findarea(pair<int, int> a, pair<int, int> b, pair<int, int> c) {     return ((double)a.first * (b.second - c.second) +             (double)b.first * (c.second - a.second) +             (double)c.first * (a.second - b.second)) /            2.0;   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %d %d , &a[i].first, &a[i].second);     double ans = 0;     for (int i = 0; i < n; i++)       for (int j = i + 1; j < n; j++) {         double maxright = -1, maxleft = -1;         for (int k = 0; k < n; k++) {           if (k != i && k != j) {             double area = findarea(a[i], a[j], a[k]);             if (area < 0)               maxleft = max(maxleft, -area);             else               maxright = max(maxright, area);           }         }         if (maxright >= 0 && maxleft >= 0) ans = max(ans, maxleft + maxright);       }     printf( %.6lf n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long maxn = 100000 + 5;   const long long inf = 9e17;   long long ans = inf, l, r, mid1, mid2;   vector<long long> g[maxn], v;   long long n, m;   inline long long cost(long long mid) {     long long cnt = mid - g[0].size(), tmp = 0;     v.clear();     for (int i = 1; i <= m; i++) {       for (int j = 0; j < g[i].size(); j++) {         if (g[i].size() - j >= mid) {           --cnt;           tmp += g[i][j];         } else           v.push_back(g[i][j]);       }     }     sort(v.begin(), v.end());     for (int i = 0; i < cnt; i++) tmp += v[i];     return tmp;   }   int main() {     long long a, b;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a >> b;       m = max(m, a);       g[a].push_back(b);     }     for (int i = 0; i <= m; i++) sort(g[i].begin(), g[i].end());     l = g[0].size(), r = n;     while (l < r) {       mid1 = (l + l + r) / 3;       mid2 = (l + r + r) / 3;       if (cost(mid1) > cost(mid2)) {         if (l == mid1)           break;         else           l = mid1;       } else {         if (r == mid2)           break;         else           r = mid2;       }     }     ans = inf;     for (int i = l; i <= r; i++) ans = min(ans, cost(i));     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string s, a, b, c;   long long f[120001], n, i, q, x, y, l, r, nom;   bool abcde;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     s =  What are you doing at the end of the world? Are you busy? Will you save            us? ;     a =  What are you doing while sending   ;     b =   ? Are you busy? Will you send   ;     c =   ? ;     f[0] = s.size();     for (i = 1; i <= 100000; i++) {       f[i] = f[i - 1] * 2 + a.size() + b.size() + c.size();       if (f[i - 1] > 1000000000000000000LL) break;     }     cin >> q;     while (q--) {       cin >> x >> y;       l = 1;       r = 9000000000000000000LL;       if (f[x] != 0) r = f[x];       if (f[x] != 0 && y > f[x]) {         cout <<  . ;         continue;       }       abcde = false;       for (i = x - 1; i >= 0; i--) {         if (l <= y && y <= l + a.size() - 1) {           abcde = true;           cout << a[y - l];           break;         }         if (f[i] == 0) {           l += a.size();           if (f[i - 1] != 0)             r = l + f[i - 1] * 2 + a.size() + b.size() + c.size() - 1;           continue;         }         if (l + a.size() + f[i] <= y && y <= r - c.size() - f[i]) {           abcde = true;           cout << b[y - (l + a.size() + f[i])];           break;         }         if (r - c.size() + 1 <= y && y <= r) {           abcde = true;           cout << c[y - (r - c.size() + 1)];           break;         }         if (l + a.size() <= y && y <= r - c.size() - f[i] - b.size()) {           l += a.size();           r -= c.size() + f[i] + b.size();         } else {           l += a.size() + f[i] + b.size();           r -= c.size();         }       }       if (!abcde) cout << s[y - l];     }     cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 7;   int sg[N];   int main() {     int T, n, k;     scanf( %d , &T);     while (T--) {       scanf( %d %d , &n, &k);       bool flag = true;       if (k % 3 == 0) {         int t = (k / 3 - 1) * 3 + 4;         int s = n % t;         if (s == t - 4)           flag = false;         else if (s < t - 4 && s % 3 == 0)           flag = false;       } else {         if (n % 3 == 0) flag = false;       }       if (flag)         printf( Alice n );       else         printf( Bob n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct TreeNode {     int val;     TreeNode* left;     TreeNode* right;     TreeNode(int x) : val(x), left(NULL), right(NULL) {}   };   struct ListNode {     int val;     ListNode* next;     ListNode(int x) : val(x), next(NULL) {}   };   int nxt() {     int x;     cin >> x;     return x;   }   long long nxtLong() {     long long x;     cin >> x;     return x;   }   string nxtStr() {     string x;     cin >> x;     return x;   }   char nxtChar() {     char x;     cin >> x;     return x;   }   double nxtDouble() {     double x;     cin >> x;     return x;   }   long double nxtLDouble() {     long double x;     cin >> x;     return x;   }   TreeNode* makeTree(int n) {     queue<TreeNode*> tree_nodes;     TreeNode* root;     if (n) {       root = new TreeNode(nxt());       tree_nodes.push(root);     } else {       return NULL;     }     while (!tree_nodes.empty()) {       TreeNode* node = tree_nodes.front();       tree_nodes.pop();       bool left;       cin >> left;       if (left) {         node->left = new TreeNode(nxt());         tree_nodes.push(node->left);       }       bool right;       cin >> right;       if (right) {         node->right = new TreeNode(nxt());         tree_nodes.push(node->right);       }     }     return root;   }   ListNode* makeLinkedList(int n) {     ListNode* list = new ListNode(0);     ListNode* dummy = list;     for (int i = 0; i < n; ++i) {       list->next = new ListNode(nxt());       list = list->next;     }     return dummy->next;   }   char ans[2000001];   void solve() {     int n = nxt();     int len = 0;     while (n--) {       string s = nxtStr();       int m = nxt();       int l = s.length();       int y = 0;       while (m--) {         int x = nxt();         x--;         len = max(len, x + l);         for (int i = max(x, y); i < x + l; ++i) {           ans[i] = s[i - x];         }         y = x + l;       }     }     for (int i = 0; i < len; ++i) {       if (!ans[i]) {         cout <<  a ;       } else {         cout << ans[i];       }     }     cout << endl;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout << fixed << setprecision(9);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   class Solver {    public:     void solve() {       cin >> n;       long long sign = 1;       long long C = n;       long long three_to_i = 1;       for (long long i = 1; i <= n; i++) {         long long term = 2LL * (sign < 0 ? sign + mod : sign) * C;         term %= mod;         term *= powmod(3, n * n - n * i + i);         term %= mod;         ans += term;         ans %= mod;         sign = -sign;         C = next_C(n, i + 1LL, C);       }       C = 1;       sign = -1;       for (long long i = 0; i < n; i++) {         long long term = C;         term *= 3 * (sign < 0 ? sign + mod : sign);         term %= mod;         term *= calc_term(i, three_to_i);         term %= mod;         ans += term;         ans %= mod;         three_to_i *= 3LL;         three_to_i %= mod;         C = next_C(n, i + 1LL, C);         sign = -sign;       }       cout << ans << endl;     }     long long calc_term(long long i, long long three_to_i) {       long long k1 = 1 - three_to_i;       if (k1 < 0) k1 += mod;       long long ans = powmod(k1, n);       long long a2 = powmod(mod - three_to_i, n);       ans = ans - a2;       if (ans < 0) ans += mod;       return ans;     }     long long powmod(long long x, long long n) {       n %= (mod - 1LL);       long long base = x;       long long ans = 1;       while (n) {         if (1LL & n) {           ans *= base;           ans %= mod;         }         base *= base;         base %= mod;         n >>= 1;       }       return ans;     }     long long next_C(long long n, long long k, long long cnk_1) {       if (k == 0 || k == n) return 1LL;       cnk_1 *= n - k + 1LL;       cnk_1 %= mod;       cnk_1 *= powmod(k, mod - 2);       return cnk_1 % mod;     }     long long mod = 998244353;     long long n;     long long ans = 0;   };   int main() {     Solver sol;     sol.solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 300000 + 10;   const int mod = 1e9 + 7;   int n, q;   char s[N];   long long sum[N];   long long pw[N], fibo[N], pw2[N], pw3[N];   int main() {     scanf( %d%d , &n, &q);     scanf( %s , s + 1);     for (int i = 1; i <= n; ++i) {       sum[i] = sum[i - 1] + (s[i] ==  1 );     }     for (int i = 1; i <= 2e5; ++i) {       if (i == 1)         fibo[i] = 1;       else         fibo[i] = fibo[i - 1] * 2;       fibo[i] %= mod;       pw[i] = pw[i - 1] + fibo[i];       pw[i] %= mod;     }     while (q--) {       int l, r;       scanf( %d%d , &l, &r);       long long num1 = sum[r] - sum[l - 1];       long long num0 = (r - l + 1) - num1;       long long ans = pw[num1];       ans %= mod;       if (num0) ans += pw[num1] * pw[num0] % mod;       ans %= mod;       printf( %lld n , ans);     }   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   const long long int INF = 1e12;   long long int mod(long long int a) {     if (a >= 0)       return a;     else       return (-1 * a);   }   void swap(long long int a, long long int b) {     long long int temp = a;     a = b;     b = temp;   }   long long int power(long long int a, long long int b) {     long long int result = 1;     while (b) {       if (b % 2) result = (result % MOD) * (a % MOD);       a = ((a % MOD) * (a % MOD)) % MOD;       b = b / 2;     }     return result;   }   bool power_check(long long int a) {     bool ans = true;     while (a > 1) {       if (a % 2 == 0) {         a = a / 2;       } else {         ans = false;         break;       }     }     return ans;   }   void solve() {     int n;     cin >> n;     string s;     cin >> s;     int c = 0;     for (int i = 0; i < n; ++i) {       if (s[i] ==  0 ) c++;     }     if (c != n - c) {       cout << 1 <<   n ;       cout << s <<   n ;       return;     }     cout << 2 <<   n ;     cout << s[0] <<    ;     for (int i = 1; i < n; ++i) {       cout << s[i];     }     cout <<   n ;     return;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int qqq;     qqq = 1;     while (qqq--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<vector<int> > data;   vector<vector<int> > sticks;   vector<int> h;   int dfs(int vertex, int last) {     int longest = 0;     for (int i = 0; i < data[vertex].size(); ++i) {       int to = data[vertex][i];       if (to == last) continue;       int len = dfs(to, vertex) + 1;       sticks[vertex].push_back(len);       longest = max(longest, len);     }     h[vertex] = longest;     return longest;   }   void dfs2(int vertex, int last, int fup) {     if (vertex != 0) {       sticks[vertex].push_back(fup);     }     fup++;     int mx1 = -100, mx2 = -100;     for (int i = 0; i < data[vertex].size(); ++i) {       int to = data[vertex][i];       if (to == last) continue;       if (h[to] + 1 > mx1) {         mx2 = mx1;         mx1 = h[to] + 1;       } else         mx2 = max(mx2, h[to] + 1);     }     for (int i = 0; i < data[vertex].size(); ++i) {       int to = data[vertex][i];       if (to == last) continue;       if (h[to] + 1 != mx1) {         dfs2(to, vertex, max(fup, mx1 + 1));       } else         dfs2(to, vertex, max(fup, mx2 + 1));     }   }   int dfslong, dfslen;   void dfs3(int vertex, int last, int d) {     if (d > dfslen) {       dfslen = d, dfslong = vertex;     }     for (int i = 0; i < data[vertex].size(); ++i) {       int to = data[vertex][i];       if (to == last) continue;       dfs3(to, vertex, d + 1);     }   }   int find_diameter() {     dfslong = 0, dfslen = 0;     dfs3(0, -1, 0);     int Q = dfslong;     dfs3(dfslong, -1, 0);     return dfslen;   }   vector<bool> deleted;   void dlt(int first) { deleted[first] = true; }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     data.assign(n, {});     sticks.assign(n, {});     h.assign(n, {});     deleted.assign(n, false);     vector<pair<int, int> > edges;     for (int i = 0; i < n - 1; ++i) {       int u, v;       cin >> u >> v;       if (u > v) swap(u, v);       u--, v--;       data[u].push_back(v), data[v].push_back(u);       edges.push_back({u, v});     }     dfs(0, -1);     dfs2(0, -1, 0);     for (int i = 0; i < n; ++i) {       sort(sticks[i].begin(), sticks[i].end(), greater<int>());     }     vector<pair<int, int> > kek;     for (int i = 0; i < n; ++i) {       for (int j = 0; j < sticks[i].size(); ++j) {         kek.push_back({sticks[i][j], i});       }     }     sort(kek.begin(), kek.end());     int d = find_diameter();     for (int i = 0; i < n; ++i) {       if (data[i].size() <= 2) dlt(i);     }     set<pair<int, int> > W;     for (int i = 0; i < n; ++i) {       W.insert({-sticks[i].size(), i});     }     auto thtol = W.begin();     cout << -(*thtol).first + 1 <<    ;     int u = 0;     vector<int> stake;     for (int k = 2; k <= n; ++k) {       if (k > d) {         cout << 1 <<    ;         continue;       }       if (k % 2 == 0) {         while (u < kek.size() && kek[u].first < k / 2) {           stake.push_back(kek[u++].second);         }         for (int i = 0; i < stake.size(); ++i) {           int T = stake[i];           W.erase(W.find({-sticks[T].size(), T}));           while (sticks[T].size() && sticks[T].back() < k / 2)             sticks[T].pop_back();           if (sticks[T].size() <= 2) dlt(T);           W.insert({-sticks[T].size(), T});         }         auto aaa = W.begin();         int tut = max(2, -(*aaa).first);         int st = 0;         while (st < edges.size()) {           int A = edges[st].first, B = edges[st].second;           if (deleted[A] || deleted[B]) {             swap(edges[st], edges.back());             edges.pop_back();             continue;           }           tut = max(tut, (int)(sticks[A].size() + sticks[B].size() - 2));           st++;         }         cout << tut <<    ;         stake.clear();       } else {         while (u < kek.size() && kek[u].first < (k + 1) / 2) {           stake.push_back(kek[u++].second);         }         for (int i = 0; i < stake.size(); ++i) {           int T = stake[i];           W.erase(W.find({-sticks[T].size(), T}));           while (sticks[T].size() > 1 &&                  sticks[T][sticks[T].size() - 2] < (k + 1) / 2)             sticks[T].pop_back();           if (sticks[T].size() <= 2) dlt(T);           W.insert({-sticks[T].size(), T});         }         auto aaa = W.begin();         int tut = max(2, -(*aaa).first);         cout << tut <<    ;       }     }   }


#include <bits/stdc++.h>   const int MAXN = 3e5 + 10;   const double eps = 1e-8;   using namespace std;   struct edge {     int t, v;     edge *next;   } e[MAXN << 1], *h[MAXN], *o = e;   void add(int x, int y, int vul) {     o->t = y;     o->v = vul;     o->next = h[x];     h[x] = o++;   }   long long read() {     long long x = 0, f = 1;     char ch = getchar();     while (!isdigit(ch)) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (isdigit(ch)) x = x * 10 + ch -  0 , ch = getchar();     return x * f;   }   int n, m, q;   int dirx[] = {-1, 1, 0, 0};   int diry[] = {0, 0, -1, 1};   int del[2000005], pos[2000006];   int a[305][305];   vector<pair<int, int> > q1[2000006], q2[2000005];   int f[MAXN];   int find1(int x) {     if (x == f[x])       return x;     else       return f[x] = find1(f[x]);   }   void cal_add(int x) {     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++)         a[i][j] = 0, f[(i - 1) * m + j] = (i - 1) * m + j;     for (int i = 0; i < q1[x].size(); i++) {       int x1 = (q1[x][i].first - 1) / m + 1;       int x2 = q1[x][i].first - (x1 - 1) * m;       a[x1][x2] = 1;       int num = 1;       for (int j = 0; j < 4; j++) {         int xx = x1 + dirx[j];         int yy = x2 + diry[j];         if (xx >= 1 && xx <= n && yy >= 1 && yy <= m && a[xx][yy] == 1) {           int y = (xx - 1) * m + yy;           int t1 = find1(q1[x][i].first);           int t2 = find1(y);           if (t1 == t2) continue;           f[t1] = t2;           num--;         }       }       del[q1[x][i].second] += num;     }   }   void cal_del(int x) {     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++)         a[i][j] = 0, f[(i - 1) * m + j] = (i - 1) * m + j;     for (int i = 0; i < q2[x].size(); i++) {       int x1 = (q2[x][i].first - 1) / m + 1;       int x2 = q2[x][i].first - (x1 - 1) * m;       a[x1][x2] = 1;       int num = 1;       for (int j = 0; j < 4; j++) {         int xx = x1 + dirx[j];         int yy = x2 + diry[j];         if (xx >= 1 && xx <= n && yy >= 1 && yy <= m && a[xx][yy] == 1) {           int y = (xx - 1) * m + yy;           int t1 = find1(q2[x][i].first);           int t2 = find1(y);           if (t1 == t2) continue;           f[t1] = t2;           num--;         }       }       del[q2[x][i].second] -= num;     }   }   int main() {     n = read();     m = read();     q = read();     int num = 0;     int x, y, c;     for (int i = 1; i <= q; i++) {       x = read();       y = read();       c = read();       pos[i] = (x - 1) * m + y;       num = c;       if (a[x][y] == c) continue;       q1[c].push_back(make_pair(pos[i], i));       q2[a[x][y]].push_back(make_pair(pos[i], i));       a[x][y] = c;     }     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++)         q2[a[i][j]].push_back(make_pair((i - 1) * m + j, q + 1));     for (int i = 0; i <= num; i++) reverse(q2[i].begin(), q2[i].end());     for (int i = 0; i <= num; i++) cal_add(i);     for (int i = 0; i <= num; i++) cal_del(i);     int ans = 1;     for (int i = 1; i <= q; i++) ans += del[i], printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int q;     cin >> q;     while (q--) {       string s;       cin >> s;       set<int> ans;       for (int i = 1; i < s.size() - 1; i++) {         if (s[i] ==  w  && s[i - 1] ==  t  && s[i + 1] ==  o ) {           if (i + 3 < s.size() && s[i + 2] ==  n  && s[i + 3] ==  e ) {             ans.insert(i + 1);             i = i + 2;           } else             ans.insert(i);         } else if (s[i] ==  n  && s[i - 1] ==  o  && s[i + 1] ==  e )           ans.insert(i);       }       cout << ans.size() << endl;       set<int>::iterator it;       for (it = ans.begin(); it != ans.end(); it++) cout << *it + 1 <<    ;       cout << endl;     }   }


#include <bits/stdc++.h>   int adjL[201][210];   int visited[201];   int broken[201][201];   int edge[200][2];   int R[200][2];   int fine[201];   int dfs(int v, int c) {     int i;     int a;     visited[v] = c;     for (i = 1; i <= adjL[v][0]; i++) {       a = adjL[v][i];       if (visited[a] != 0 || broken[v][a]) continue;       dfs(a, c);     }     return 0;   }   int dfs_loop(int n) {     int i, j;     int c;     for (i = 1; i <= n; i++) visited[i] = 0;     c = 1;     for (i = 1; i <= n; i++)       if (visited[i] == 0) {         dfs(i, c);         c++;       }     return 0;   }   int main() {     int n, m, k;     int i, j;     int a, b;     scanf( %d%d , &n, &m);     for (i = 0; i < m; i++) {       scanf( %d%d , &a, &b);       adjL[a][++adjL[a][0]] = b;       adjL[b][++adjL[b][0]] = a;       edge[i][0] = a;       edge[i][1] = b;     }     scanf( %d , &k);     for (i = 0; i < k; i++) scanf( %d%d , &R[i][0], &R[i][1]);     for (i = 1; i <= n; i++) fine[i] = 0;     for (i = 0; i < m; i++) {       a = edge[i][0];       b = edge[i][1];       broken[a][b] = broken[b][a] = 1;       dfs_loop(n);       broken[a][b] = broken[b][a] = 0;       for (j = 0; j < k; j++)         if (visited[R[j][0]] != visited[R[j][1]]) fine[j + 1]++;     }     for (i = 1; i <= k; i++) printf( %d n , fine[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int q;     cin >> q;     while (q--) {       vector<vector<int> > grid;       int h, w;       cin >> h >> w;       grid.assign(h, vector<int>(w, 0));       for (int i = 0; i < h; i++) {         for (int j = 0; j < w; j++) {           scanf( %d , &grid[i][j]);         }       }       int diff1 = 0;       int diff2 = 0;       for (int j = 0; j < w; j++) {         diff1 += grid[h / 2 - 1][j] - grid[h / 2][j];         diff2 += grid[0][j] - grid[h - 1][j];       }       if (abs(diff1) > abs(diff2))         cout <<  YES  << endl;       else         cout <<  NO  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   vector<int> fa;   int n, m, q, g[300][300], x, y, c;   int id(int x, int y) { return x * m + y; }   int in(int x, int y) { return x >= 0 && y >= 0 && x < n && y < m; }   int find(int x) { return fa[x] == x ? x : (fa[x] = find(fa[x])); }   int merge(int x, int y) {     int xx = find(x), yy = find(y);     if (xx == yy) {       return 0;     } else {       fa[xx] = yy;       return 1;     }   }   int ADD(int x, int y) {     int p = id(x, y);     if (fa[p] != INF) return 0;     fa[p] = p;     static int dx[] = {0, 0, 1, -1};     static int dy[] = {1, -1, 0, 0};     int r = 1;     for (int i = (int)0; i < (int)4; ++i) {       int nx = x + dx[i], ny = y + dy[i];       int pp = id(nx, ny);       if (in(nx, ny) && fa[pp] != INF) {         r -= merge(p, pp);       }     }     return r;   }   struct P {     int x, y, p;     P(int x_, int y_, int p_) : x(x_), y(y_), p(p_) {}   };   int main() {     scanf( %d%d%d , &n, &m, &q);     fa.resize(n * m);     memset(g, 0, sizeof(g));     vector<vector<P>> add(1), del(1);     int pc = 0, cc = 0;     for (int i = (int)0; i < (int)q; ++i) {       scanf( %d%d%d , &x, &y, &c);       --x, --y;       if (c != pc) {         pc = c;         ++cc;         add.emplace_back(vector<P>{}), del.emplace_back(vector<P>{});       }       c = cc;       if (g[x][y] != c) {         del[g[x][y]].emplace_back(x, y, i);         add[c].emplace_back(x, y, i);         g[x][y] = c;       }     }     vector<int> df(q, 0);     for (int i = (int)0; i < (int)n; ++i)       for (int j = (int)0; j < (int)m; ++j) add[0].emplace_back(i, j, 0);     for (int c = (int)1; c < (int)cc + 1; ++c) {       if (add[c].empty()) continue;       fill(fa.begin(), fa.end(), INF);       for (auto &p : add[c]) {         df[p.p] = ADD(p.x, p.y);       }     }     df[0] += 1;     for (int c = (int)0; c < (int)cc + 1; ++c) {       fill(fa.begin(), fa.end(), INF);       unordered_set<int> xx;       for (auto &p : del[c]) {         xx.insert(id(p.x, p.y));       }       for (auto &p : add[c]) {         if (!xx.count(id(p.x, p.y))) ADD(p.x, p.y);       }       int n = del[c].size();       for (int i = (int)n - 1; i >= (int)0; --i) {         auto &p = del[c][i];         df[p.p] -= ADD(p.x, p.y);       }     }     int cnt = 0;     for (int i = (int)0; i < (int)q; ++i) {       cnt += df[i];       printf( %d n , cnt);     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int N;     cin >> N;     string inst;     cin >> inst;     int total = 0;     for (int i = 0; i < N; i++) {       for (int j = i + 1; j < N; j++) {         int ct_u = 0;         int ct_l = 0;         for (int k = i; k <= j; k++) {           if (inst[k] ==  U ) {             ct_u++;           } else if (inst[k] ==  D ) {             ct_u--;           } else if (inst[k] ==  L ) {             ct_l--;           } else if (inst[k] ==  R ) {             ct_l++;           }         }         if (ct_u == 0 && ct_l == 0) total++;       }     }     cout << total << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e6 + 7;   struct Data {     long long min, max, resl, resr;   };   struct TNode {     long long L, R;     TNode *left, *right;     Data d;     long long val;   };   TNode *new_node(long long L, long long R) {     return new TNode({L, R, nullptr, nullptr, {INF, -1, -1, -1}, 0});   }   Data safe(TNode *root) {     if (!root) {       return {INF, -1, -1, -1};     }     return root->d;   }   Data upd(Data a, Data b) {     Data c;     c.min = min(a.min, b.min);     c.max = max(a.max, b.max);     c.resl = max({a.resl, b.resl, a.max - 2 * b.min});     c.resr = max({a.resr, b.resr, b.max - 2 * a.min});     return c;   }   void relax(TNode *root) {     if (!root) return;     root->d = upd(safe(root->left), safe(root->right));   }   void add_val(TNode *root, long long val) {     if (!root) return;     root->val += val;     (root->d).min += val;     (root->d).max += val;     (root->d).resl -= val;     (root->d).resr -= val;   }   void push(TNode *root) {     if (!root) return;     add_val(root->left, root->val);     add_val(root->right, root->val);     root->val = 0;   }   vector<long long> pref;   TNode *build_tree(long long L, long long R) {     TNode *root = new_node(L, R);     if (R - L == 1) {       root->d = {pref[L], pref[L], -pref[L], -pref[L]};     } else {       long long M = (L + R) / 2;       root->left = build_tree(L, M);       root->right = build_tree(M, R);       relax(root);     }     return root;   }   void add_seg(TNode *root, long long L, long long R, long long val) {     if (L >= root->R || root->L >= R) {       return;     }     if (L <= root->L && root->R <= R) {       add_val(root, val);       return;     }     push(root);     add_seg(root->left, L, R, val);     add_seg(root->right, L, R, val);     relax(root);   }   Data get_res(TNode *root, long long L, long long R) {     if (L >= root->R || root->L >= R) {       return {INF, -1, -1, -1};     }     if (L <= root->L && root->R <= R) {       return root->d;     }     push(root);     Data res = upd(get_res(root->left, L, R), get_res(root->right, L, R));     relax(root);     return res;   }   long long m;   pair<long long, long long> get_max(TNode *root) {     if (root->R - root->L == 1) {       return {(root->d).max, root->L};     }     push(root);     pair<long long, long long> ret;     if (safe(root->left).max > safe(root->right).max) {       ret = get_max(root->left);     } else {       ret = get_max(root->right);     }     relax(root);     return ret;   }   void print(TNode *root) {     if (root->R - root->L == 1) {       cout << (root->d).max <<    ;       return;     }     push(root);     print(root->left);     print(root->right);     relax(root);   }   long long query(TNode *root) {     auto t = get_max(root);     long long pos = t.second, val = t.first;     Data a = get_res(root, 0, pos);     Data b = get_res(root, pos + 1, m);     return max(max(a.resl, b.resr) + val, 0LL);   }   int main() {     ios_base::sync_with_stdio(false);     long long n, q;     cin >> n >> q;     string s;     cin >> s;     pref.push_back(0);     for (long long i = 0; i < 2 * (n - 1); i++) {       pref.push_back(pref.back() + (s[i] ==  (  ? 1 : -1));     }     m = 2 * n - 1;     TNode *root = build_tree(0, m);     cout << query(root) <<   n ;     for (long long i = 0; i < q; i++) {       long long a, b;       cin >> a >> b;       a--, b--;       if (a > b) swap(a, b);       if (s[a] != s[b]) {         if (s[a] ==  ( ) {           add_seg(root, a + 1, b + 1, -2);         } else {           add_seg(root, a + 1, b + 1, 2);         }         swap(s[a], s[b]);       }       cout << query(root) <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1000 * 1000 + 20;   const int N5 = 300 * 1000 + 10;   const int N3 = 3000 + 20;   const long long mod = 1000 * 1000 * 1000 + 9;   const long long inf = LLONG_MAX / 2;   long long dp[2][N], par[N], rnk[N];   long long __pow(long long x, int y) {     if (y == 0) return 1;     return __pow(x * x % mod, y / 2) % mod * (y & 1 ? x : 1) % mod;   }   int find_root(int v) {     if (par[v] == v) {       return v;     }     return par[v] = find_root(par[v]);   }   void _merge(int a, int b) {     int r_a = find_root(a);     int r_b = find_root(b);     if (rnk[r_a] > rnk[r_b]) {       swap(r_a, r_b);     }     par[r_a] = r_b;     if (rnk[r_a] == rnk[r_b]) {       rnk[r_b]++;     }     return;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n, m;     cin >> n >> m;     int t = 0;     for (int i = 1; i <= n; i++) par[i] = i;     for (int i = 1; i <= m; i++) {       int x, y;       cin >> x >> y;       if (find_root(x) != find_root(y)) {         t++;         _merge(x, y);       }       cout << ((__pow(2, i - t) + mod) - 1) % mod <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string a, b, c;     cin >> a >> b >> c;     if (a[0] == c[2] && a[1] == c[1] && a[2] == c[0] && b[0] == b[2])       cout <<  YES  << endl;     else       cout <<  NO  << endl;   }


#include <bits/stdc++.h>   using namespace std;   const long long I1 = 1e9;   const long long I2 = 1e18;   const int32_t M1 = 1e9 + 7;   const int32_t M2 = 998244353;   template <typename T, typename T1>   T maxn(T &a, T1 b) {     if (b > a) a = b;     return a;   }   template <typename T, typename T1>   T minn(T &a, T1 b) {     if (b < a) a = b;     return a;   }   const int M = 3005;   bool cc[M][M];   long long int dis[M][M];   set<pair<pair<long long int, long long int>, long long int> > s;   vector<long long int> a[M];   void solve() {     int n, m, k;     cin >> n >> m >> k;     for (long long int i = 0; i < m; i++) {       int x, y;       cin >> x >> y;       a[x].push_back(y);       a[y].push_back(x);     }     for (long long int i = 0; i < k; i++) {       int x, y, z;       cin >> x >> y >> z;       s.insert({{x, y}, z});     }     queue<pair<long long int, long long int> > q;     q.push({1, 1});     while (!q.empty()) {       pair<long long int, long long int> cur = q.front();       int x = cur.first, y = cur.second;       q.pop();       cc[cur.first][cur.second] = true;       for (auto u : a[y]) {         if (s.count({{x, y}, u})) continue;         if (cc[y][u] == true) continue;         cc[y][u] = true;         dis[y][u] = dis[x][y] + 1;         q.push({y, u});       }     }     long long int d = I1, i = n, prev = n;     for (long long int i = 1; i <= n; i++) {       if (dis[i][n] != 0) minn(d, dis[i][n]);     }     if (d == I1) {       cout <<  -1  << endl;       return;     }     cout << d << endl;     vector<long long int> ans;     ans.push_back(n);     while (i != 1) {       long long int ind = -1;       for (long long int j = 1; j <= n; j++) {         if (dis[j][i] == d) {           ind = j;           break;         }       }       ans.push_back(ind);       prev = i;       i = ind;       d--;     }     reverse(ans.begin(), ans.end());     for (auto u : ans) cout << u <<    ;     cout << endl;   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int testcase = 1;     while (testcase--) solve();     return 0;   }