#include <bits/stdc++.h>   using namespace std;   bool flag;   int n, k, vis[10][105];   char s[10][105];   int judge(int x, int y) {     if ((s[x][y] ==  .  || s[x][y] ==  s ) && (x >= 1 && x <= 3))       return 1;     else       return 0;   }   void dfs(int x, int y) {     vis[x][y] = 1;     if (y >= n - 1) {       flag = 1;       return;     }     if (!judge(x, y + 1)) return;     if (flag == 1) return;     if (judge(x, y + 1) && judge(x, y + 2) && judge(x, y + 3) && !vis[x][y + 3])       dfs(x, y + 3);     if (judge(x - 1, y + 1) && judge(x - 1, y + 2) && judge(x - 1, y + 3) &&         !vis[x - 1][y + 3])       dfs(x - 1, y + 3);     if (judge(x + 1, y + 1) && judge(x + 1, y + 2) && judge(x + 1, y + 3) &&         !vis[x + 1][y + 3])       dfs(x + 1, y + 3);   }   int main() {     int t;     cin >> t;     while (t--) {       cin >> n >> k;       flag = 0;       for (int i = 1; i <= 3; i++) {         for (int j = 0; j < n; j++) cin >> s[i][j];       }       int x, y;       for (int i = 1; i <= 3; i++) {         for (int j = 0; j < n; j++) {           if (s[i][j] ==  s ) x = i, y = j;         }       }       for (int i = 1; i <= 3; i++)         for (int j = n; j <= 104; j++) s[i][j] =  . ;       memset(vis, 0, sizeof(vis));       dfs(x, y);       if (flag == 1)         cout <<  YES  << endl;       else         cout <<  NO  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long t;     cin >> t;     while (t--) {       long long n;       cin >> n;       long long a, b, c;       cin >> a >> b >> c;       string s;       cin >> s;       long long x = 0, y = 0, z = 0;       for (long long i = 0; i < n; i++) {         if (s[i] ==  R ) {           x++;         } else if (s[i] ==  P ) {           y++;         } else {           z++;         }       }       long long win = 0;       win = min(a, z) + min(b, x) + min(c, y);       long long r = (n + 1) / 2;       if (win >= r) {         cout <<  YES  << endl;         char ans[n];         for (long long i = 0; i < n; i++) {           if (s[i] ==  S  && a) {             ans[i] =  R ;             a--;             z--;           } else if (s[i] ==  R  && b) {             ans[i] =  P ;             b--;             x--;           } else if (s[i] ==  P  && c) {             ans[i] =  S ;             c--;             y--;           } else if (s[i] ==  S  && b > x) {             ans[i] =  P ;             b--;           } else if (s[i] ==  S  && c > y) {             ans[i] =  S ;             c--;           } else if (s[i] ==  R  && a > z) {             ans[i] =  R ;             a--;           } else if (s[i] ==  R  && c > y) {             ans[i] =  S ;             c--;           } else if (s[i] ==  P  && a > z) {             ans[i] =  R ;             a--;           } else if (s[i] ==  P  && b > x) {             ans[i] =  P ;             b--;           }         }         for (long long i = 0; i < n; i++) {           cout << ans[i];         }         cout << endl;       } else {         cout <<  NO  << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ull = unsigned long long;   using ld = long double;   const ll INF = 1e18;   const ll MOD = 1e9 + 7;   const ld EPS = 1e-10;   const ld PI = acos(-1);   vector<ll> po[2];   ll n, k;   pair<ll, ll> CountHash(ll x, ll ind, ll q) {     ll h1 = 0, h2 = 0;     for (ll i = 2; i * i <= x; ++i) {       if (x % i == 0) {         ll a = 0;         while (x % i == 0) {           ++a;           x /= i;         }         a %= k;         ll b = (k - a) % k;         h1 += a * po[ind][i] % q;         h2 += b * po[ind][i] % q;         h1 %= q;         h2 %= q;       }     }     if (x > 1) {       h1 += 1 * po[ind][x] % q;       h2 += (k - 1) * po[ind][x] % q;       h1 %= q;       h2 %= q;     }     return {h1, h2};   }   void solve() {     cin >> n >> k;     map<pair<ll, ll>, ll> cnt;     ll P1 = 239;     ll Q1 = 1e9 + 7;     ll P2 = 41;     ll Q2 = 1e9 + 9;     po[0].resize(100000);     po[1].resize(100000);     po[0][0] = 1;     po[1][0] = 1;     for (int i = 1; i < 100000; ++i) {       po[0][i] = po[0][i - 1] * P1 % Q1;       po[1][i] = po[1][i - 1] * P2 % Q2;     }     ll ans = 0;     for (int i = 0; i < n; ++i) {       ll x;       cin >> x;       auto h1 = CountHash(x, 0, Q1);       auto h2 = CountHash(x, 1, Q2);       ans += cnt[{h1.second, h2.second}];       ++cnt[{h1.first, h2.first}];     }     cout << ans <<   n ;   }   int main() {     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxN = 2000 + 5;   int s, n, m, a[maxN];   vector<int> p[maxN];   vector<int> f[maxN], g[maxN];   void initialize() {     ios::sync_with_stdio(false);     cin >> n >> s;     s--;     for (int i = 0; i < n; ++i) cin >> a[i];     vector<int> t(a, a + n);     sort(t.begin(), t.end());     t.erase(unique(t.begin(), t.end()), t.end());     for (int i = 0; i < n; ++i)       a[i] = lower_bound(t.begin(), t.end(), a[i]) - t.begin() + 1;     m = t.size();     for (int i = 0; i < n; ++i) p[a[i]].push_back(i);     p[0].push_back(s);     f[0].push_back(0);     g[0].push_back(-1);   }   int cyc(int x, int y) { return y < x ? y + n - x : y - x; }   int cont(int x, int y) { return cyc(y, x); }   int sp(int x, int y) { return min(cyc(x, y), cont(x, y)); }   template <typename T>   bool chmin(T &x, const T &y) {     return y < x ? x = y, true : false;   }   int solve() {     for (int st = 1; st <= m; ++st) {       int sz = p[st].size();       f[st].assign(sz, maxN * maxN);       g[st].assign(sz, -1);       for (int i = 0; i < sz; ++i) {         int pre = i - 1, post = i + 1;         if (pre == -1) pre = sz - 1;         if (post == sz) post = 0;         for (int j = 0; j < (int)p[st - 1].size(); ++j) {           chmin(f[st][i], f[st - 1][j] + sp(p[st - 1][j], p[st][pre]) +                               cont(p[st][pre], p[st][i])) &&               (g[st][i] = j);           chmin(f[st][i], f[st - 1][j] + sp(p[st - 1][j], p[st][post]) +                               cyc(p[st][post], p[st][i])) &&               (g[st][i] = j);         }       }     }     return *min_element(f[m].begin(), f[m].end());   }   void psp(int x, int y) {     if (cyc(x, y) <= cont(x, y))       printf( +%d n , cyc(x, y));     else       printf( -%d n , cont(x, y));   }   void print(int st, int i) {     if (st == 0) return;     int j = g[st][i];     print(st - 1, j);     int sz = p[st].size();     int pre = i - 1, post = i + 1;     if (pre == -1) pre = sz - 1;     if (post == sz) post = 0;     int cpre =         f[st - 1][j] + sp(p[st - 1][j], p[st][pre]) + cont(p[st][pre], p[st][i]);     int cpost =         f[st - 1][j] + sp(p[st - 1][j], p[st][post]) + cyc(p[st][post], p[st][i]);     if (cpre < cpost) {       psp(p[st - 1][j], p[st][pre]);       while (pre != i) {         int pp = pre - 1;         if (pp == -1) pp = sz - 1;         printf( -%d n , cont(p[st][pre], p[st][pp]));         pre = pp;       }     } else {       psp(p[st - 1][j], p[st][post]);       while (post != i) {         int pp = post + 1;         if (pp == sz) pp = 0;         printf( +%d n , cyc(p[st][post], p[st][pp]));         post = pp;       }     }   }   int main() {     initialize();     cout << solve() << endl;     print(m, min_element(f[m].begin(), f[m].end()) - f[m].begin());     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, num, m;   map<long long, bool> isInsert;   priority_queue<long long, vector<long long>, greater<long long> > pq;   vector<string> vs;   vector<long long> vi;   int main() {     m = 0;     cin >> n;     while (n--) {       string s;       cin >> s;       if (s ==  insert ) {         cin >> num;         pq.push(num);         isInsert[num] = true;         vs.push_back(s);         vi.push_back(num);         m++;       } else if (s ==  getMin ) {         cin >> num;         if (!pq.empty() && pq.top() == num) {           vs.push_back(s);           vi.push_back(num);           m++;         } else {           if (!isInsert[num]) {             pq.push(num);             isInsert[num] = true;             vs.push_back( insert );             vi.push_back(num);             m++;           }           while (pq.top() != num) {             isInsert[pq.top()] = false;             vs.push_back( removeMin );             vi.push_back(-10000000000);             m++;             pq.pop();           }           vs.push_back(s);           vi.push_back(num);           m++;         }       } else {         m++;         if (pq.empty()) {           pq.push(2);           isInsert[2] = true;           vs.push_back( insert );           vi.push_back(2);           m++;         }         isInsert[pq.top()] = false;         pq.pop();         vs.push_back(s);         vi.push_back(-10000000000);       }     }     cout << m <<   n ;     int size = vs.size();     for (int i = 0; i < size; ++i) {       cout << vs[i] <<    ;       if (vi[i] != -10000000000)         cout << vi[i] <<   n ;       else         cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T1, typename T2>   inline void chkmin(T1& a, T2 b) {     if (a > b) a = b;   }   template <typename T1, typename T2>   inline void chkmax(T1& a, T2 b) {     if (a < b) a = b;   }   using ll = long long;   using d = double;   using ld = long double;   const string FILENAME =  input ;   const int MAXN = 200228;   const d eps = 1e-15;   __int128 gcd(__int128 a, __int128 b) {     while (b) {       a %= b;       swap(a, b);     }     return a;   }   __int128 mabs(__int128 a) { return (a >= 0 ? a : -a); }   struct Ratio {     __int128 p, q;     Ratio() {}     Ratio(__int128 a, __int128 b) {       p = a;       q = b;       auto d = mabs(gcd(p, q));       if (d != 0) {         p /= d;         q /= d;       }       if (q < 0) {         p = -p;         q = -q;       }     }   };   void norm(Ratio& a) {     auto d = mabs(gcd(a.p, a.q));     if (d != 0) {       a.p /= d;       a.q /= d;     }     if (a.q < 0) {       a.p = -a.p;       a.q = -a.q;     }     if (a.p == 0 && a.q != 0) {       a.q = 1;     }   }   bool operator==(const Ratio& a, const Ratio& b) {     return a.p == b.p && a.q == b.q;   }   bool operator<(const Ratio& a, const Ratio& b) { return a.p * b.q < b.p * a.q; }   Ratio operator+(const Ratio& a, const Ratio& b) {     Ratio c;     c.q = a.q * b.q;     c.p = a.p * b.q + b.p * a.q;     norm(c);     return c;   }   Ratio operator-(const Ratio& a, const Ratio& b) {     Ratio c;     c.q = a.q * b.q;     c.p = a.p * b.q - b.p * a.q;     norm(c);     return c;   }   Ratio operator*(const Ratio& a, const Ratio& b) {     Ratio c;     c.p = a.p * b.p;     c.q = a.q * b.q;     norm(c);     return c;   }   Ratio operator/(const Ratio& a, const Ratio& b) {     Ratio c;     c.p = a.p * b.q;     c.q = a.q * b.p;     norm(c);     return c;   }   struct Point {     Ratio x, y;     Point() {}     Point(Ratio _x, Ratio _y) {       x = _x;       y = _y;     }   };   bool operator==(const Point& a, const Point& b) {     return a.x == b.x && a.y == b.y;   }   bool operator<(const Point& a, const Point& b) {     return make_pair(a.x, a.y) < make_pair(b.x, b.y);   }   Point operator-(const Point& a, const Point& b) {     return Point(a.x - b.x, a.y - b.y);   }   Point createPoint(ll a, ll b, ll c) {     Point res(Ratio(a, a + b + c), Ratio(b, a + b + c));     return res;   }   int n;   Point p[MAXN];   ll cnt1 = 0;   Point target;   map<Point, int> kek;   map<Point, int> cntr;   void print(Point pp) {     cout << (ll)pp.x.p <<  /  << (ll)pp.x.q <<     << (ll)pp.y.p <<  /           << (ll)pp.y.q << endl;   }   Ratio vec(const Point& a, const Point& b) { return a.x * b.y - a.y * b.x; }   int check(Point a, Point b) {     if (a == b) {       return 0;     }     return vec(a, b).p < 0;   }   struct event {     Point a;     event() {}     event(Point _a) { a = _a; }   };   Ratio len(Point a) { return a.x * a.x + a.y * a.y; }   bool operator==(const event& a, const event& b) { return a.a == b.a; }   int getHalf(Point a) { return a.y.p > 0 || (a.y.p == 0 && a.x.p > 0); }   bool operator<(const event& a, const event& b) {     int t = getHalf(a.a);     int t1 = getHalf(b.a);     if (t != t1) {       return t > t1;     }     if (a.a == b.a) {       return false;     }     Ratio s = vec(a.a, b.a);     if (s.p == 0) {       return len(a.a) < len(b.a);     } else {       return s.p > 0;     }   }   multiset<event> st;   int cntk = 0;   Point getRight(Point x) {     auto f = st.upper_bound(event(x));     if (f == st.end()) {       f = st.begin();     }     return (*f).a;   }   Point getLeft(Point x) {     auto f = st.lower_bound(event(x));     if (f == st.begin()) {       f = st.end();     }     f--;     return (*f).a;   }   void norm(Point& a) {     if (a.x.p == 0) {       a.x.p = 0;       a.x.q = 1;       int c = (a.y.p > 0 ? 1 : -1);       a.y.p = c;       a.y.q = 1;     } else if (a.y.p == 0) {       a.y.p = 0;       a.y.q = 1;       int c = (a.x.p > 0 ? 1 : -1);       a.x.p = c;       a.x.q = 1;     } else {       a.x.p *= a.y.q;       a.y.p *= a.x.q;       a.x.q = 1;       a.y.q = 1;       auto d = mabs(gcd(a.x.p, a.y.p));       a.x.p /= d;       a.y.p /= d;     }   }   map<Point, int> cntf;   void add(Point t) {     if (t == target) {       return;     }     t = t - target;     norm(t);     cntf[t]++;     if (cntf[t] == 1) {       auto t1 = event(t);       if ((int)(st).size() == 0) {         st.insert(t1);       } else {         auto f = getLeft(t);         auto f1 = getRight(t);         cntk -= check(f, f1);         cntk += check(f, t);         cntk += check(t, f1);         st.insert(t1);       }     }   }   void del(Point t) {     if (t == target) {       return;     }     t = t - target;     norm(t);     cntf[t]--;     if (cntf[t] == 0) {       auto t1 = event(t);       st.erase(st.find(t1));       if (st.empty()) {         return;       }       auto f = getLeft(t);       auto f1 = getRight(t);       cntk += check(f, f1);       cntk -= check(f, t);       cntk -= check(t, f1);     }   }   void proceedBich(int id) {     Point x = p[id] - target;     norm(x);     Point x1 = x;     x1.x.p *= -1;     x1.y.p *= -1;     cnt1 += cntr[x1];     cntr[x]++;   }   void proceedBich1(int id) {     Point x = p[id] - target;     norm(x);     Point x1 = x;     x1.x.p *= -1;     x1.y.p *= -1;     cntr[x]--;     cnt1 -= cntr[x1];   }   void addPoint(int id) {     kek[p[id]]++;     proceedBich(id);     add(p[id]);   }   void delPoint(int id) {     kek[p[id]]--;     proceedBich1(id);     del(p[id]);   }   int check() {     if (kek[target]) {       return 1;     }     if (cnt1) {       return 2;     }     if (cntk == 0) {       if ((int)(st).size() >= 3) {         return 3;       }     }     return 0;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int ss, pp, gg;     cin >> ss >> pp >> gg;     target = createPoint(ss, pp, gg);     cin >> n;     int uk = 0;     for (int it = 0; it < n; it++) {       char c;       cin >> c;       if (c ==  A ) {         int ph, pg, pd;         cin >> ph >> pg >> pd;         p[uk] = createPoint(ph, pg, pd);         addPoint(uk);         uk++;       } else if (c ==  R ) {         int id;         cin >> id;         id--;         delPoint(id);       }       cout << check() <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const long long LL_INF = (long long)2e18 + 5;   struct point {     long long x, y;     point() : x(0), y(0) {}     point(long long _x, long long _y) : x(_x), y(_y) {}   };   struct reverse_monotonic_dp_hull {     vector<point> points;     int size() const { return (int)points.size(); }     void clear() {       points.clear();       prev_x = LL_INF;     }     static long long floor_div(long long a, long long b) {       return a / b - ((a ^ b) < 0 && a % b != 0);     }     static bool bad_middle(const point &a, const point &b, const point &c) {       return floor_div(a.y - b.y, b.x - a.x) >= floor_div(b.y - c.y, c.x - b.x);     }     void insert(const point &p) {       assert(size() == 0 || p.x >= points.back().x);       if (size() > 0 && p.x == points.back().x) {         if (p.y <= points.back().y) return;         points.pop_back();       }       while (size() >= 2 &&              bad_middle(points[points.size() - 2], points.back(), p))         points.pop_back();       points.push_back(p);     }     void insert(long long a, long long b) { insert(point(a, b)); }     long long prev_x = LL_INF;     long long query(long long x) {       assert(x <= prev_x);       prev_x = x;       while (size() >= 2 && x * (points.back().x - points[size() - 2].x) <=                                 points[size() - 2].y - points.back().y)         points.pop_back();       return points.back().x * x + points.back().y;     }   };   int N, K;   vector<long long> A;   vector<long long> dp, next_dp;   vector<long long> left_max, right_max;   void update(int start, int end) {     if (start >= end) return;     if (end - start == 1) {       next_dp[end] = min(next_dp[end], dp[start] + A[start]);       return;     }     int mid = (start + end) / 2;     update(start, mid);     left_max[mid] = right_max[mid] = -LL_INF;     for (int i = mid - 1; i >= start; i--)       left_max[i] = max(left_max[i + 1], A[i]);     for (int i = mid; i < end; i++) right_max[i + 1] = max(right_max[i], A[i]);     reverse_monotonic_dp_hull hull;     for (int right = mid + 1, left = mid; right <= end; right++) {       while (left >= start && right_max[right] >= left_max[left]) {         hull.insert(-left, -dp[left]);         left--;       }       if (hull.size() > 0)         next_dp[right] = min(next_dp[right], -hull.query(-right_max[right]) +                                                  right * right_max[right]);     }     hull.clear();     for (int right = end, left = start; right > mid; right--) {       while (left <= mid && left_max[left] >= right_max[right]) {         hull.insert(-left_max[left], left * left_max[left] - dp[left]);         left++;       }       if (hull.size() > 0)         next_dp[right] = min(next_dp[right], -hull.query(right));     }     update(mid + 1, end);   }   void update_dp() {     left_max.assign(N + 1, -LL_INF);     right_max.assign(N + 1, -LL_INF);     next_dp.assign(N + 1, LL_INF);     update(0, N);     swap(dp, next_dp);   }   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cin >> N >> K;     A.resize(N);     for (auto &a : A) cin >> a;     dp.assign(N + 1, LL_INF);     dp[0] = 0;     for (int k = 0; k < K; k++) update_dp();     cout << dp[N] <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int judge(int n) {     int flag = 0;     for (int i = 2; i <= n / 2; i++) {       if (n % i == 0) {         flag = 1;         break;       }     }     if (flag)       return 0;     else       return 1;   }   int main() {     int n;     cin >> n;     for (int i = 1; i <= 1000; i++) {       int sum = i * n + 1;       if (judge(sum) == 0) {         printf( %d n , i);         return 0;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long int inf = 1e18;   const int N = 1e5 + 5;   void solve() {     int n;     cin >> n;     set<int> st;     for (int i = 0; i < n; i++) {       int x;       cin >> x;       if (x % 2 == 0) st.insert(x);     }     int ans = 0;     while (!st.empty()) {       int x = *st.rbegin();       st.erase(x);       if (x % 2 == 0) st.insert(x / 2), ans++;     }     cout << ans <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout << fixed << showpoint;     cout << setprecision(9);     int test = 1;     cin >> test;     while (test--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void read(int &n) {     n = 0;     int s = 1;     char c;     for (; (c = getchar()) >  9  || c <  0 ;)       if (c ==  - ) s = -1;     for (; c >=  0  && c <=  9 ; c = getchar()) n = (n << 1) + (n << 3) + c - 48;     n *= s;   }   void write(int n) {     if (!n) putchar(48);     int t = 0, b[20];     for (; n; n /= 10) b[++t] = n % 10;     while (t) putchar(b[t--] + 48);   }   int f[18][200100], nxt[18][200100], m, n, q, deep[200100], fir[200100],       nex[200100], to[200100], top, son[10001001][2], siz[10001001], cnt,       rt[200100], dfl[200100], dfr[200100], mn[200100], opl, opr;   struct dot {     int a, b;   } a[200100 + 200100];   bool cmp(dot a, dot b) { return a.a < b.a; }   void dfs(int x) {     ++deep[x];     dfl[x] = dfr[x] = ++top;     for (int i = fir[x]; i; i = nex[i])       deep[to[i]] = deep[x], dfs(to[i]), dfr[x] = dfr[to[i]];   }   int lca(int x, int y) {     if (deep[x] > deep[y]) return lca(y, x);     for (int i(17), _E_(0); i >= _E_; --i)       if (deep[f[i][y]] >= deep[x]) y = f[i][y];     if (x == y) return x;     for (int i(17), _E_(0); i >= _E_; --i)       if (f[i][y] ^ f[i][x]) x = f[i][x], y = f[i][y];     return f[0][x];   }   void doit(int x) {     for (int i = fir[x]; i; i = nex[i]) {       doit(to[i]);       mn[x] = deep[mn[to[i]]] < deep[mn[x]] ? mn[to[i]] : mn[x];     }     if (x ^ mn[x]) nxt[0][x] = mn[x];   }   void update(int u, int &v, int h, int t) {     v = ++cnt;     siz[v] = siz[u] + 1;     son[v][0] = son[u][0];     son[v][1] = son[u][1];     if (h == t) return;     int m = h + t >> 1;     if (opl <= m)       update(son[u][0], son[v][0], h, m);     else       update(son[u][1], son[v][1], m + 1, t);   }   int query(int w, int h, int t) {     if (opl > t || opr < h || !w) return 0;     if (opl <= h && opr >= t) return siz[w];     int m = h + t >> 1, res = 0;     if (opl <= m) res += query(son[w][0], h, m);     if (opr > m) res += query(son[w][1], m + 1, t);     return res;   }   int exist(int u, int v) {     int sum = 0;     opr = dfr[v];     opl = dfl[v];     sum += query(rt[dfr[u]], 1, n);     opr = dfr[v];     opl = dfl[v];     sum -= query(rt[dfl[u] - 1], 1, n);     return sum > 0;   }   int main() {     scanf( %d , &n);     for (int i(1), _E_(n); i <= _E_; ++i) mn[i] = i;     for (int i(2), _E_(n); i <= _E_; ++i)       scanf( %d , f[0] + i), to[++top] = i, nex[top] = fir[f[0][i]],                              fir[f[0][i]] = top;     top = 0;     dfs(1);     scanf( %d , &m);     for (int j(1), _E_(17); j <= _E_; ++j)       for (int i(1), _E_(n); i <= _E_; ++i) f[j][i] = f[j - 1][f[j - 1][i]];     int t = 0;     for (int i(1), _E_(m); i <= _E_; ++i) {       int x, y, l;       scanf( %d %d , &x, &y);       l = lca(x, y);       a[++t] = (dot){dfl[x], dfl[y]};       a[++t] = (dot){dfl[y], dfl[x]};       mn[x] = deep[mn[x]] > deep[l] ? l : mn[x];       mn[y] = deep[mn[y]] > deep[l] ? l : mn[y];     }     doit(1);     sort(a + 1, a + m + m + 1, cmp);     for (int j(1), _E_(17); j <= _E_; ++j)       for (int i(1), _E_(n); i <= _E_; ++i) nxt[j][i] = nxt[j - 1][nxt[j - 1][i]];     for (int i(1), _E_(m + m); i <= _E_; ++i)       opl = a[i].b, update(rt[a[i - 1].a], rt[a[i].a], 1, n);     for (int i(1), _E_(n); i <= _E_; ++i)       if (!rt[i]) rt[i] = rt[i - 1];     scanf( %d , &q);     for (int i(1), _E_(q); i <= _E_; ++i) {       int u, v;       scanf( %d %d , &u, &v);       if (u == v) {         printf( 0 n );         continue;       }       int L = lca(u, v), ans = 0;       for (int j(17), _E_(0); j >= _E_; --j)         if (deep[nxt[j][u]] > deep[L]) u = nxt[j][u], ans += 1 << j;       for (int j(17), _E_(0); j >= _E_; --j)         if (deep[nxt[j][v]] > deep[L]) v = nxt[j][v], ans += 1 << j;       if (L == u && nxt[0][v])         printf( %d n , ans + 1);       else if (L == v && nxt[0][u])         printf( %d n , ans + 1);       else if (!nxt[0][u] || !nxt[0][v])         printf( -1 n );       else         printf( %d n , ans + 2 - exist(u, v));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long maxN = 1e5 + 13;   long long root, sz[maxN], h[maxN], ans, val[maxN], m, n, pw[maxN], pre[maxN];   map<long long, long long> mp;   vector<long long> vec;   vector<pair<long long, long long>> adj[maxN];   bool mark[maxN], fl;   void dfs(long long v, long long p) {     sz[v] = 1;     for (auto a : adj[v]) {       long long u = a.first, w = a.second;       if (u != p && !mark[u]) {         dfs(u, v);         sz[v] += sz[u];       }     }   }   long long getpw(long long a, long long b) {     long long ret = 1;     for (; b; b >>= 1, a = 1ll * a * a % m)       if (b & 1) ret = 1ll * ret * a % m;     return ret;   }   void precomp() {     pw[0] = 1;     for (long long i = 1; i < n + 5; i++) pw[i] = pw[i - 1] * 10 % m;     long long tmp = m, tot = m;     for (long long p = 2; p * p <= tmp; p++)       if (tmp % p == 0) {         tot = tot / p * (p - 1);         while (tmp % p == 0) tmp /= p;       }     if (tmp > 1) tot = tot / tmp * (tmp - 1);     pre[0] = 1;     pre[1] = getpw(10, tot - 1);     for (long long i = 2; i < n + 5; i++) pre[i] = 1ll * pre[i - 1] * pre[1] % m;   }   void du(long long v, long long p) {     for (auto a : adj[v]) {       long long u = a.first, w = a.second;       if (u != p && !mark[u]) {         h[u] = h[v] + 1;         val[u] = ((val[v]) + w * pw[h[v]]) % m;         if (val[u] == 0) ans++;         du(u, v);       }     }   }   void dd(long long v, long long p, long long cur) {     if (v != root) vec.push_back(v);     reverse(adj[v].begin(), adj[v].end());     for (auto a : adj[v]) {       long long u = a.first, w = a.second;       if (u != p && !mark[u]) {         long long nwcur = (cur * 10 + w) % m;         long long wnt = ((1ll * pre[h[u]] * ((-nwcur) % m + m)) + m) % m;         ans += mp[wnt];         dd(u, v, nwcur);         if (nwcur == 0 && fl) ans++;         if (v == root) {           while (vec.size()) {             long long u = vec.back();             vec.pop_back();             mp[val[u]]++;           }         }       }     }   }   void calc(long long v) {     long long tmp = ans;     h[v] = 0;     val[v] = 0;     du(v, -1);     mp.clear();     fl = 0;     dd(v, -1, 0);     mp.clear();     fl = 1;     dd(v, -1, 0);   }   void solve(long long v) {     dfs(v, -1);     root = v;     long long p = -1;     bool fl = true;     while (fl) {       fl = false;       for (auto a : adj[v]) {         long long u = a.first;         if (!mark[u] && u != p && sz[u] > sz[root] / 2) {           p = v;           v = u;           fl = true;           break;         }       }     }     mark[v] = true;     root = v;     calc(v);     for (auto a : adj[v]) {       long long u = a.first;       if (!mark[u]) solve(u);     }   }   int32_t main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> m;     precomp();     for (long long i = 0; i < n - 1; i++) {       long long a, b, w;       cin >> a >> b >> w;       a++;       b++;       w %= m;       adj[a].push_back({b, w});       adj[b].push_back({a, w});     }     solve(1);     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     int n, M;     cin >> n >> M;     vector<char> s(n);     int m = M;     vector<int> p(m), b(n), yes(n, 0), cnt(26, 0);     for (int i = 0; i < n; i++) {       cin >> s[i];       cnt[s[i] -  a ]++;     }     for (int i = 0; i < m; i++) {       cin >> p[i];       p[i]--;     }     sort(p.begin(), p.end());     int top = 0;     for (int i = 0; i < n; i++) {       if (top >= M) break;       if (p[top] != i)         cnt[s[i] -  a ] += m;       else {         int t = top;         while (top < M - 1 && p[top] == p[top + 1]) top++;         int c = ++top - t;         cnt[s[i] -  a ] += m;         m -= c;       }     }     for (int i = 0; i < 26; i++) cout << cnt[i] <<    ;     cout << endl;     return;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct tree {     tree() : par(NULL), val(0) { next.clear(); };     map<int, tree *> next;     tree *par;     int val;     void setParent(tree *p) { par = p; }   };   tree *moveDown(tree *root, int n) {     tree *ret = NULL;     if (root->next.count(n)) {       ret = root->next[n];     } else {       ret = new tree();       ret->setParent(root);       root->next[n] = ret;     }     ret->val++;     return ret;   }   tree *moveUp(tree *root) { return root->par; }   char line[1000003];   char tmp[5002];   map<string, int> f;   vector<int> v;   int go(tree *root, int what) {     int ans = 0;     for (map<int, tree *>::iterator it = root->next.begin();          it != root->next.end(); ++it) {       if (it->first == what)         ans += it->second->val + go(it->second, what);       else         ans += go(it->second, what);     }     return ans;   }   int calc(tree *root, int ind = 0) {     if (ind + 1 == v.size()) {       return go(root, v[ind]);     }     int ans = 0;     for (map<int, tree *>::iterator it = root->next.begin();          it != root->next.end(); ++it) {       if (it->first == v[ind])         ans += calc(it->second, ind + 1);       else         ans += calc(it->second, ind);     }     return ans;   }   void out(tree *root, int par = -1) {     for (map<int, tree *>::iterator it = root->next.begin();          it != root->next.end(); ++it) {       out(it->second, it->first);     }   }   int main() {     tree *root = new tree(), *root1 = root;     char str[25] = {0};     gets(line);     int l = strlen(line), tot = 0;     map<string, int>::iterator it;     for (int i = 0; i < l; ++i) {       if (line[i] ==  < ) {         int type = 0, len = 0;         if (line[i + 1] ==  / ) type = 1;         for (i = i + 1 + (type == 1); i < l; ++i) {           if (line[i] ==  / )             type = 2;           else if (line[i] ==  > )             break;           else             str[len++] = line[i];         }         int num = 0;         str[len] =   0 ;         it = f.find(string(str));         if (it != f.end())           num = it->second;         else           f[string(str)] = num = tot++;         if (type == 0) {           root = moveDown(root, num);         } else if (type == 1) {           root = moveUp(root);         } else {           moveDown(root, num);         }       }     }     int q;     scanf( %d n , &q);     while (q--) {       gets(tmp);       istringstream ss(tmp);       string s;       bool ok = true;       v.clear();       while (ss >> s) {         it = f.find(s);         if (it != f.end()) {           v.push_back(it->second);         } else {           ok = false;           break;         }       }       if (ok)         printf( %d n , calc(root1));       else         printf( 0 n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long inv(long long a, long long mod) {     long long b = mod, p = 1, q = 0;     while (b) {       long long c = a / b, d = a;       a = b;       b = d % b;       d = p;       p = q;       q = d - c * q;     }     return (p + mod) % mod;   }   map<tuple<long long, long long, long long, long long, int>, long long> mp;   long long sol(long long w0, long long w1, long long w2, long long a, int m) {     long long res = 0;     long long mod = 998244353;     tuple<long long, long long, long long, long long, int> key =         make_tuple(w0, w1, w2, a, m);     if (mp.find(key) != mp.end()) return mp[key];     if (m == 0) {       res = w2;     } else {       long long sum = w0 + w1 + w2;       long long isum = inv(sum, mod);       long long t0 = w0 * isum % mod * sol(w0 - 1, w1, w2, a, m - 1) % mod;       long long t1 = w1 * isum % mod * sol(w0, w1 + 1, w2, a, m - 1) % mod;       long long t2 =           w2 * isum % mod * sol(w0, w1, w2 + (a == 0 ? -1 : 1), a, m - 1) % mod;       res = (t0 + t1 + t2) % mod;     }     mp[key] = res;     return res;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n, m;     cin >> n >> m;     vector<long long> a(n), w(n);     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < n; i++) cin >> w[i];     long long mod = 998244353;     vector<long long> res(n);     for (int i = 0; i < n; i++) {       long long w0 = 0, w1 = 0;       for (int j = 0; j < n; j++) {         if (j == i) continue;         if (a[j] == 0)           w0 = (w0 + w[j]) % mod;         else           w1 = (w1 + w[j]) % mod;       }       long long w2 = w[i];       res[i] = sol(w0, w1, w2, a[i], m);     }     for (int i = 0; i < n; i++) {       cout << res[i] <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   double ans = 1111111111;   int ap[111111], bp[111111], bt[111111], n, m, a, b, l, r, m1, m2, minap, minbp;   double dist(double ax, double ay, double bx, double by) {     return sqrt((bx - ax) * (bx - ax) + (by - ay) * (by - ay));   }   double f(int i, int j) {     return dist(0, 0, a, ap[i]) + dist(a, ap[i], b, bp[j]) + bt[j];   }   int main() {     scanf( %d%d%d%d , &n, &m, &a, &b);     for (int i = 0; i < n; i++) scanf( %d , &ap[i]);     for (int i = 0; i < m; i++) scanf( %d , &bp[i]);     for (int i = 0; i < m; i++) {       scanf( %d , &bt[i]);       l = 0, r = n - 1;       while (r - l >= 3) {         m1 = l + (r - l) / 3;         m2 = r - (r - l) / 3;         if (f(m1, i) < f(m2, i))           r = m2;         else           l = m1;       }       for (int j = l; j <= r; j++) {         if (f(j, i) < ans) ans = f(j, i), minap = j, minbp = i;       }     }     printf( %d %d , minap + 1, minbp + 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, i, sum, sum1, count = 1;     cin >> n;     int arr[4 * n + 1];     arr[0] = 0;     for (i = 1; i <= 4 * n - 3; i = i + 4) {       cin >> arr[i] >> arr[i + 1] >> arr[i + 2] >> arr[i + 3];       if (i == 1)         sum = arr[1] + arr[2] + arr[3] + arr[4];       else {         sum1 = arr[i] + arr[i + 1] + arr[i + 2] + arr[i + 3];         if (sum1 > sum) count++;       }     }     cout << count;   }


#include <bits/stdc++.h>   using namespace std;   const double EPS = 1e-10;   const double PI = acos(-1.0);   template <class T>   T gcd(T a, T b) {     for (T c; b; c = a, a = b, b = c % b)       ;     return a;   }   template <class T>   void out(const vector<T> &a) {     for (int i = 0; i < ((int)(a).size()); ++i) cout << a[i] <<    ;     cout << endl;   }   int countbit(int n) { return n == 0 ? 0 : 1 + countbit(n & (n - 1)); }   const int d8[8][2] = {{1, 0}, {-1, 0},  {0, 1},  {0, -1},                         {1, 1}, {-1, -1}, {1, -1}, {-1, 1}};   const int d4[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};   inline long long cross(const complex<long long> &a,                          const complex<long long> &b) {     return (conj(a) * b).imag();   }   inline long long cross(const complex<long long> &a, const complex<long long> &b,                          const complex<long long> &c) {     return cross(b - a, c - a);   }   inline long long dot(const complex<long long> &a, const complex<long long> &b) {     return (conj(a) * b).real();   }   inline bool which_part(const complex<long long> &p) {     return p.imag() > 0 || p.imag() == 0 && p.real() > 0;   }   namespace std {   bool operator<(const complex<long long> &a, const complex<long long> &b) {     int flag_a = which_part(a);     int flag_b = which_part(b);     if (flag_a != flag_b) return flag_a < flag_b;     return cross(a, b) > 0;   }   }  // namespace std   struct node {     complex<long long> p;     int color;   };   struct cmp {     complex<long long> p;     cmp(const complex<long long> &p) : p(p) {}     bool operator()(const node &a, const node &b) { return a.p - p < b.p - p; }   };   node a[1000], b[2000];   int main() {     int n, m;     scanf( %d %d , &n, &m);     for (int i = 0; i < n; ++i) {       long long x, y;       scanf( %I64d %I64d , &x, &y);       a[i].p = complex<long long>(x, y);       a[i].color = 0;     }     for (int i = 0; i < m; ++i) {       long long x, y;       scanf( %I64d %I64d , &x, &y);       a[n + i].p = complex<long long>(x, y);       a[n + i].color = 1;     }     long long ret = 0;     for (int i = 0; i < n; ++i) {       int L = 0;       for (int j = i + 1; j < n + m; ++j) {         if (j == i) continue;         b[L++] = a[j];       }       sort(b, b + L, cmp(a[i].p));       for (int j = 0; j < L; ++j) b[L + j] = b[j];       int u;       for (u = 1; cross(a[i].p, b[0].p, b[u].p) > 0; ++u)         ;       for (int j = 0; j < L; ++j) {         if (b[j].color == 1) continue;         bool found = false;         complex<long long> p;         for (u = max(u, j + 1); cross(a[i].p, b[j].p, b[u].p) > 0; ++u)           ;         for (int k = j + 1; k != u; ++k) {           if (b[k].color == 1) {             if (!found || cross(b[j].p, p, b[k].p) > 0) {               found = true;               p = b[k].p;             }           } else {             if (!found || cross(b[j].p, p, b[k].p) > 0) {               ++ret;             }           }         }       }     }     printf( %I64d n , ret);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline void read(int &x) {     int v = 0, f = 1;     char c = getchar();     while (!isdigit(c) && c !=  - ) c = getchar();     if (c ==  - )       f = -1;     else       v = v * 10 + c -  0 ;     while (isdigit(c = getchar())) v = v * 10 + c -  0 ;     x = v * f;   }   inline void read(long long &x) {     long long v = 0ll, f = 1ll;     char c = getchar();     while (!isdigit(c) && c !=  - ) c = getchar();     if (c ==  - )       f = -1;     else       v = v * 10 + c -  0 ;     while (isdigit(c = getchar())) v = v * 10 + c -  0 ;     x = v * f;   }   inline void readc(char &x) {     char c;     while ((c = getchar()) ==    )       ;     x = c;   }   inline void writes(string s) { puts(s.c_str()); }   inline void writeln() { writes(  ); }   inline void writei(int x) {     if (x < 0) {       putchar( - );       x = abs(x);     }     if (!x) putchar( 0 );     char a[25];     int top = 0;     while (x) {       a[++top] = (x % 10) +  0 ;       x /= 10;     }     while (top) {       putchar(a[top]);       top--;     }   }   inline void writell(long long x) {     if (x < 0) {       putchar( - );       x = abs(x);     }     if (!x) putchar( 0 );     char a[25];     int top = 0;     while (x) {       a[++top] = (x % 10) +  0 ;       x /= 10;     }     while (top) {       putchar(a[top]);       top--;     }   }   int n, m, i, j, v, dis[505], cnt, cst, vis[505];   string st, s;   struct edg {     int y, z, d;   } ee[18005];   vector<int> e[505];   void add(int x, int y, int z, int d) {     cnt++;     e[x].push_back(cnt * 2 - 2);     e[y].push_back(cnt * 2 - 1);     ee[cnt * 2 - 2] = (edg){y, z, d};     ee[cnt * 2 - 1] = (edg){x, 0, -d};   }   bool bfs(int s, int t) {     memset(dis, -18, sizeof(dis));     dis[s] = 0;     queue<int> q;     q.push(s);     while (!q.empty()) {       int x = q.front();       q.pop();       for (__typeof((e[x]).begin()) it = (e[x]).begin(); it != (e[x]).end();            it++) {         if (ee[*it].z == 0) continue;         int y = ee[*it].y, z = dis[x] + ee[*it].d;         if (dis[y] < z) {           dis[y] = z;           q.push(y);         }       }     }     return dis[t] > dis[504];   }   int dfs(int x, int t, int flw) {     if (!flw || (x != t && vis[x])) return 0;     if (x == t) {       vis[x] = 1;       return flw;     }     vis[x] = 1;     int ans = 0;     for (__typeof((e[x]).begin()) it = (e[x]).begin(); it != (e[x]).end(); it++) {       if (ee[*it].z == 0) continue;       int y = ee[*it].y;       if (dis[y] == dis[x] + ee[*it].d) {         int tt = dfs(y, t, min(flw, ee[*it].z));         ans += tt;         flw -= tt;         ee[*it].z -= tt;         ee[(*it) ^ 1].z += tt;         cst += tt * ee[*it].d;       }     }     return ans;   }   int dinic(int s, int t) {     int ans = 0;     while (bfs(s, t)) {       do {         memset(vis, 0, sizeof(vis));         ans += dfs(s, t, 0x3bbbbbbb);       } while (vis[t]);     }     return cst;   }   int main() {     ios_base::sync_with_stdio(false);     ;     cin >> n >> st >> m;     st =     + st;     for (((i)) = (1); ((i)) <= ((n)); ((i))++) add(i, i + 1, 0x3bbbbbbb, 0);     while (m--) {       cin >> s >> v;       for (((i)) = (1); ((i)) <= ((n - ((int)(s.length())) + 1)); ((i))++) {         if (st.substr(i, s.length()) == s) {           add(i, i + s.length(), 1, v);         }       }     }     cin >> v;     add(0, 1, v, 0);     cout << dinic(0, n + 1) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 2 * 1e5 + 100;   long long n, m, k, w, a[N], d[N], p[N], fa[N], vi[N];   long long tot, first[N], nxt[N * 2], point[N * 2], len[N * 2];   priority_queue<pair<long long, long long>, vector<pair<long long, long long> >,                  greater<pair<long long, long long> > >       q;   struct node {     long long u, v, w;   } sh[N];   bool cmp(node a, node b) { return a.w < b.w; }   long long find(long long x) {     return (x == fa[x]) ? fa[x] : fa[x] = find(fa[x]);   }   inline long long read() {     long long f = 1, x = 0;     char s = getchar();     while (s <  0  || s >  9 ) {       if (s ==  - ) f = -1;       s = getchar();     }     while (s >=  0  && s <=  9 ) {       x = x * 10 + s -  0 ;       s = getchar();     }     return x * f;   }   inline void add_edge(long long x, long long y, long long z) {     nxt[++tot] = first[x];     first[x] = tot;     point[tot] = y;     len[tot] = z;   }   inline bool merge(long long a, long long b) {     long long fax = find(a), fay = find(b);     if (fax == fay) return 0;     fa[fax] = fay;     return 1;   }   signed main() {     tot = -1;     memset(first, -1, sizeof(first));     n = read();     m = read();     for (long long i = 1; i <= m; i++) {       long long u = read(), v = read(), w = read();       add_edge(u, v, w);       add_edge(v, u, w);     }     k = read();     for (long long i = 1; i <= k; i++) a[i] = read();     for (long long i = 1; i <= n; i++) d[i] = 1e18;     for (long long i = 1; i <= k; i++)       p[a[i]] = a[i], d[a[i]] = 0, q.push(make_pair(0, a[i]));     while (!q.empty()) {       long long x = q.top().second;       q.pop();       if (vi[x]) continue;       vi[x] = 1;       for (long long i = first[x]; i != -1; i = nxt[i]) {         long long u = point[i];         if (d[u] > d[x] + len[i]) {           d[u] = d[x] + len[i];           p[u] = p[x];           q.push(make_pair(d[u], u));         }       }     }     for (long long i = 0; i <= tot; i += 2) {       long long u = point[i], v = point[i ^ 1];       if (p[u] == p[v]) continue;       sh[++w] = (node){p[u], p[v], d[u] + d[v] + len[i]};     }     sort(sh + 1, sh + 1 + w, cmp);     for (long long i = 1; i <= n; i++) fa[i] = i;     long long ans = d[1];     for (long long i = 1; i <= w; i++)       if (merge(sh[i].u, sh[i].v)) ans += sh[i].w;     printf( %lld n , ans);   }


#include <bits/stdc++.h>   char input[5001];   int data[1000];   using namespace std;   int main() {     int r = 0;     stack<int> s;     char temp[10];     int b = 0, p, count;     while (scanf( %s , input) != EOF) {       for (int i = 0; i < strlen(input); i++) {         if (input[i] ==  < ) {           count = 0;           i++;           while (i < strlen(input) && input[i] !=  > ) {             temp[count++] = input[i++];           }         }         if (i < strlen(input) && input[i] ==  > ) {           temp[count] =   0 ;           fflush(0);           if (strcmp(temp,  table ) == 0) {             b = 0;             s.push(b);           } else if (strcmp(temp,  td ) == 0) {             p = s.top();             p++;             s.pop();             s.push(p);           } else if (strcmp(temp,  /table ) == 0) {             data[r++] = s.top();             s.pop();           }         } else if (i < strlen(input) && input[i] !=  < )           temp[count++] = input[i];       }     }     sort(data, data + r);     for (int k = 0; k < r; k++) printf( %d  , data[k]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {}   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t = 1;     long long k = 1;     vector<long long> v;     while (1) {       long long tmp = ((1 << k) - 1) * (1 << (k - 1));       if (tmp > 100001) break;       v.push_back(tmp);       k++;     }     while (t--) {       long long n;       cin >> n;       for (int i = (int)v.size() - 1; i > -1; i--) {         if (n % v[i] == 0) {           cout << v[i] <<   n ;           break;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int abs(int x) { return x >= 0 ? x : -x; }   int main() {     int n;     cin >> n;     while (n--) {       vector<int> x;       vector<int> y;       char tmp;       for (int i = 0; i < 8; i++) {         for (int j = 0; j < 8; j++) {           cin >> tmp;           if (tmp ==  K ) {             x.push_back(i);             y.push_back(j);           }         }       }       int tx, ty;       tx = abs(x[0] - x[1]);       ty = abs(y[0] - y[1]);       if ((tx % 4 == 0) && (ty % 4 == 0) && ((tx + ty) % 4 == 0))         cout <<  YES  << endl;       else         cout <<  NO  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string s;   int n, i, j, k, mx = 0, sum = 0, vis[5005], letter[26], check[26][5005][26], ok;   double ans = 0;   int main() {     cin >> s;     n = s.length();     s = s + s;     for (i = 0; i < n; i++) {       letter[s[i] -  a ]++;       for (j = i; j < i + n; j++) {         check[s[i] -  a ][j - i + 1][s[j] -  a ]++;       }     }     for (i = 0; i < 26; i++) {       if (!letter[i]) continue;       mx = -1;       for (j = 2; j <= n; j++) {         sum = 0;         for (k = 0; k < 26; k++)           if (check[i][j][k] == 1) sum += 1;         mx = max(mx, sum);       }       ans += 1.0 * mx / n;     }     printf( %lf , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<pair<int, int>> sms;     int time1, amount1;     for (int i = 0; i < n; i++) {       cin >> time1 >> amount1;       sms.push_back(make_pair(time1, amount1));     }     int time = 0;     int amount = 0;     int maxamount = 0;     for (int i = 0; i < n; i++) {       if (amount <= sms[i].first - time) {         time = sms[i].first;         amount = sms[i].second;       } else {         amount -= sms[i].first - time;         time += sms[i].first - time;         amount += sms[i].second;       }       if (amount > maxamount) maxamount = amount;     }     if (amount) {       if (amount > maxamount) maxamount = amount;       time += amount;     }     cout << time <<     << maxamount << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 100005;   int n, t, cc, flag[maxn], a[maxn];   int main() {     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i];     if (n == 1) {       cout <<  +  << endl;       return 0;     }     for (int i = 1; i <= n; i++) flag[i] = 1;     flag[n] = -1;     flag[n - 1] = -1;     t = a[n] - a[n - 1];     for (int i = n - 2; i >= 1; i--) {       if (t >= a[i]) {         t = t - a[i];         flag[i + 1] *= -1;         flag[i] *= -1;       } else {         t = a[i] - t;         flag[i + 1] *= -1;       }     }     cc = 1;     for (int i = 1; i <= n; i++) {       cc *= flag[i];       if (cc < 0)         cout <<  - ;       else         cout <<  + ;     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   double revs, a, b, c, d, C, totdist;   const double pi = atan(1) * 4;   int n, r, v, s, f;   double distcovered(double t) { return max(r * (t + sin(t)), r * (t - sin(t))); }   int main() {     cout << fixed << setprecision(8);     cin >> n >> r >> v;     for (int c = 0; c < n; c++) {       scanf( %d%d , &s, &f);       a = f - s;       a = a / 2;       double up, low;       low = 0;       up = a / r + 2 * pi;       for (int c = 0; c < 100; c++) {         double mid = (low + up) / 2;         b = distcovered(mid);         if (b == a)           break;         else if (b > a)           up = mid;         else           low = mid;       }       double mid = (low + up) / 2;       double speed = (double)v / r;       double time = mid / speed * 2;       printf( %.8f n , time);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e15;   const int MOD = 1e9 + 7;   const double EPS = 1e-7;   const double PI = acos(-1.0);   const int N = 3e5 + 5;   long long n, a[N];   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL), cout.tie(NULL);     cin >> n;     for (int i = 0; i < n; ++i) {       cin >> a[i];     }     long long ans = 0, left = 0;     for (int i = 0; i < n; ++i) {       if (i) {         ans += min(a[i] / 2, left);         long long tmp = left;         left -= min(a[i] / 2, left);         a[i] -= min(a[i] / 2 * 2, tmp * 2);       }       ans += a[i] / 3;       a[i] -= a[i] / 3 * 3;       left += a[i];     }     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   void make(vector<pair<int, int> > &a, long long int b) {     int last = 0;     int n = a.size();     for (int i = 0; i < a.size() - 1; i++) {       if (b >= pow(2, n - 2 - i)) {         a[i].first = n - last;         last++;         b = b - pow(2, n - 2 - i);       } else {         a[i].first = i + 1 - last;       }     }     a[n - 1].first = n - last;   }   int main() {     long long int n, b;     cin >> n >> b;     vector<pair<int, int> > a;     for (int i = 0; i < n; i++) {       a.push_back(make_pair(0, i + 1));     }     make(a, b - 1);     sort(a.begin(), a.end());     for (int i = 0; i < n; i++) cout << a[i].second <<    ;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1000000007;   const int MAX = 1000005;   int n, k;   int st1[MAX][20];   int st2[MAX][20];   int v[MAX];   int c[MAX];   int ans[MAX];   double factor[MAX];   int log(int x) {     int ct = 0;     int k = 1;     while (k <= x) {       k *= 2;       ct++;     }     return ct - 1;   }   int pow2(int x) {     int ans = 1;     for (int i = 0; i < x; i++) {       ans *= 2;     }     return ans;   }   void process2() {     for (int j = 1; (1 << j) <= n; j++) {       for (int i = 1; i + (1 << j) - 1 <= n; i++) {         if (st2[i][j - 1] < st2[i + (1 << (j - 1))][j - 1]) {           st2[i][j] = st2[i][j - 1];         } else {           st2[i][j] = st2[i + (1 << (j - 1))][j - 1];         }       }     }   }   int rmq2(int i, int j) {     int k = log(j - i + 1);     if (st2[i][k] <= st2[j - pow2(k) + 1][k]) {       return st2[i][k];     }     return st2[j - pow2(k) + 1][k];   }   void process1() {     for (int j = 1; (1 << j) <= n; j++) {       for (int i = 1; i + (1 << j) - 1 <= n; i++) {         if (st1[i][j - 1] > st1[i + (1 << (j - 1))][j - 1]) {           st1[i][j] = st1[i][j - 1];         } else {           st1[i][j] = st1[i + (1 << (j - 1))][j - 1];         }       }     }   }   int rmq1(int i, int j) {     int k = log(j - i + 1);     if (st1[i][k] >= st1[j - pow2(k) + 1][k]) {       return st1[i][k];     }     return st1[j - pow2(k) + 1][k];   }   int first(int l, int r) { return 100 * rmq1(l, r); }   int g(int l, int r) { return rmq2(l, r); }   int p(int l, int r) { return min(g(l, r), first(l, r)); }   int main() {     scanf( %d %d , &n, &k);     for (int i = 0; i < n; i++) {       scanf( %d , &v[i + 1]);       st1[i + 1][0] = v[i + 1];     }     for (int i = 0; i < n; i++) {       scanf( %d , &c[i + 1]);       st2[i + 1][0] = c[i + 1];     }     process1();     process2();     factor[1] = (k + 0.0) / n;     for (int i = 2; i < n + 1; i++) {       factor[i] = factor[i - 1] * (0.0 + n - k - (i - 2)) / (n - i + 1);     }     for (int l = 1; l < n + 1; l++) {       int lo = l;       int hi = n;       while (lo < hi) {         int mid = (lo + hi) / 2;         if (first(l, mid) == g(l, mid)) {           lo = mid;           ans[l] = first(l, mid);           break;         }         if (first(l, mid) < g(l, mid)) {           lo = mid + 1;         } else {           hi = mid;         }       }       if (ans[l] == 0) {         ans[l] = p(l, lo);         if (l <= lo - 1) {           ans[l] = max(ans[l], p(l, lo - 1));         }       }     }     sort(ans + 1, ans + n + 1);     double fin = 0;     for (int i = 1; i < n + 1; i++) {       fin += ans[i] * factor[i];     }     printf( %.10f n , fin);   }


#include <bits/stdc++.h>   using namespace std;   void fast_in_out() {     std::ios_base::sync_with_stdio(NULL);     cin.tie(NULL);     cout.tie(NULL);   }   int main() {     fast_in_out();     int n, x, y, c = 0;     cin >> n;     for (int(i) = 0; (i) < (n); ++(i)) {       cin >> x >> y;       if (y >= x + 2) c++;     }     cout << c << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int w, h;     cin >> w >> h;     long long int cnt = 0;     for (int i = 2; i <= w; i += 2) {       for (int j = 2; j <= h; j += 2) {         cnt += ((w - i + 1) * (h - j + 1));       }     }     cout << cnt;     return 0;   }


#include <bits/stdc++.h>   const int mxn = 1e5 * 4 + 10, mod = 1e9 + 7;   using namespace std;   long long phi(long long n);   long long gcd(long long a, long long b);   long long lcm(long long a, long long b);   long long n, m, t = 0, l, k, a, tmp, d;   int mn = 1e9, mx = -1;   int main() {     cin >> n >> t >> k >> d;     long long ao, bo, c, g;     c = (n + k - 1) / k;     ao = c * t;     c -= d / t;     g = d / t * t;     c -= (d - g) / t;     g += (d - g) / t * t;     if (c % 2) {       g += (c / 2 + 1) * t;       d += (c / 2) * t;     } else {       g += (c / 2) * t;       d += (c / 2) * t;     }     bo = max(d, g);     cout << ((ao > bo) ?  YES  :  NO );   }   long long phi(long long n) {     long long res = n, i = 2;     for (; i * i <= n; i++)       if (n % i == 0) {         while (n % i == 0) n = n / i;         res -= res / i;       }     if (n > 1) res -= res / n;     return res;   }   long long gcd(long long a, long long b) { return (b == 0) ? a : gcd(b, a % b); }   long long lcm(long long a, long long b) { return a * b / gcd(a, b); }


#include <bits/stdc++.h>   using namespace std;   int x[10007], y[10007];   int n, w, v, u;   int main() {     cin >> n >> w >> v >> u;     double maxer = -1;     for (int i = 0; i < n; i++) {       cin >> x[i] >> y[i];     }     double lim = u * 1.0 / v;     bool flag1 = false;     bool flag2 = false;     for (int i = 0; i < n; i++) {       if (y[i] * 1.0 / x[i] > lim || y[i] * 1.0 / x[i] < 0) {         flag1 = true;       }       if (y[i] * 1.0 / x[i] < lim) {         flag2 = true;       }       double tmp = x[i] * 1.0 / v + (w - y[i]) * 1.0 / u;       maxer = max(maxer, tmp);     }     if (flag1 == false || flag2 == false) {       printf( %.10f n , w * 1.0 / u);       return 0;     }     printf( %.10f n , maxer);   }


#include <bits/stdc++.h>   using namespace std;   long long int cnt[22];   int main() {     int n;     cin >> n;     int a;     for (int i = 0; i < n; i++) {       cin >> a;       cnt[a + 10]++;     }     long long int ans = cnt[10] * (cnt[10] - 1) / 2;     for (int i = 1; i <= 10; i++) ans += cnt[-i + 10] * cnt[i + 10];     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 3e5 + 10, size = 1 << 20, mod = 998244353;   template <class o>   void qr(o &x) {     char c = getchar();     x = 0;     int f = 1;     while (!isdigit(c)) {       if (c ==  - ) f = -1;       c = getchar();     }     while (isdigit(c)) x = x * 10 + c -  0 , c = getchar();     x *= f;   }   template <class o>   void qw(o x) {     if (x / 10) qw(x / 10);     putchar(x % 10 +  0 );   }   template <class o>   void pr1(o x) {     if (x < 0) x = -x, putchar( - );     qw(x);     putchar(   );   }   template <class o>   void pr2(o x) {     if (x < 0) x = -x, putchar( - );     qw(x);     puts(  );   }   long long mult(long long a, long long b, long long p) {     a = (a % p + p) % p;     b = (b % p + p) % p;     long long c = (long double)a * b / p;     return a * b - c * p;   }   long long gcd(long long a, long long b) { return !a ? b : gcd(b % a, a); }   long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }   long long power(long long a, long long b = mod - 2) {     long long c = 1;     while (b) {       if (b & 1) c = c * a % mod;       b /= 2;       a = a * a % mod;     }     return c;   }   long long Power(long long a, long long b = mod - 2) {     long long c = 1;     while (b) {       if (b & 1) c = mult(c, a, mod);       b /= 2;       a = mult(a, a, mod);     }     return c;   }   int n;   long long inv, a[N];   int main() {     qr(n);     inv = power(n);     for (int i = 1; i <= n; i++) qr(a[i]);     sort(a + 1, a + n + 1);     for (int i = 1; i <= n; i++) (a[i] += a[i - 1]) %= mod;     for (int i = 1; i <= n; i++) {       int pos = n - i, t = 1;       long long ans = 0;       while (pos >= i) {         ans += (a[pos] - a[pos - i] + mod) * t++ % mod;         pos -= i;       }       (ans += a[pos] * t) %= mod;       pr1(ans * inv % mod);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     while (n--) {       int a;       cin >> a;       string s;       cin >> s;       set<char> st;       for (int i = 0; i < s.size(); i++) {         st.insert(s[i]);       }       if (st.size() == 1) {         cout << -1 <<     << -1 << endl;       } else {         for (int i = 0; i < s.size(); i++) {           if (s[i] ==  a  && s[i + 1] ==  b ) {             cout << i + 1 <<     << i + 2 << endl;             break;           }           if (s[i] ==  b  && s[i + 1] ==  a ) {             cout << i + 1 <<     << i + 2 << endl;             break;           }         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int MOD = 998244353;     long long int n;     cin >> n;     pair<long long int, long long int> arr[n];     for (long long int i = 0; i < n; ++i) cin >> arr[i].first >> arr[i].second;     long long int fact[n + 1];     fact[0] = 1;     for (long long int i = 1; i <= n; ++i) {       fact[i] = (fact[i - 1] * i + MOD) % MOD;     }     map<long long int, long long int> count1;     map<long long int, long long int> count2;     map<pair<long long int, long long int>, long long int> count3;     for (long long int i = 0; i < n; ++i) {       count1[arr[i].first]++;       count2[arr[i].second]++;       count3[make_pair(arr[i].first, arr[i].second)]++;     }     long long int n1 = 1, n2 = 1, n3 = 1;     map<long long int, long long int>::iterator it;     for (it = count1.begin(); it != count1.end(); ++it) {       n1 = (n1 * (fact[it->second]) + MOD) % MOD;     }     for (it = count2.begin(); it != count2.end(); ++it) {       n2 = (n2 * (fact[it->second]) + MOD) % MOD;     }     map<pair<long long int, long long int>, long long int>::iterator itd;     long long int last2 = -1;     for (itd = count3.begin(); itd != count3.end(); ++itd) {       n3 = (n3 * (fact[itd->second]) + MOD) % MOD;       if (itd->first.second < last2) {         n3 = 0;         break;       }       last2 = itd->first.second;     }     long long int ans = (fact[n] - n1 - n2 + n3 + 2 * MOD) % MOD;     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     long long h, w;     cin >> h >> w;     long long pow2max = 1;     while (2 * pow2max <= h && 2 * pow2max <= w) pow2max *= 2;     long long hmax = min(h, (long long)(1.25 * pow2max));     long long wmax = min(w, (long long)(1.25 * pow2max));     if (hmax >= wmax)       cout << hmax <<     << pow2max;     else       cout << pow2max <<     << wmax;     return;   }   signed main() {     ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);     long long t = 1;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   int main() {     long i, n, d = 0;     scanf( %ld , &n);     for (i = 1; i <= n / 2; i++) {       if (n % i == 0) d++;     }     printf( %d , d);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long Ax, Ay, Bx, By, Cx, Cy;   bool solvable(long long A, long long B) {     return (Cx * A + Cy * B) % (Cx * Cx + Cy * Cy) == 0 &&            (-Cy * A + Cx * B) % (Cx * Cx + Cy * Cy) == 0;   }   bool possible() {     cin >> Ax >> Ay >> Bx >> By >> Cx >> Cy;     if (Cx == 0 && Cy == 0) {       if (Bx == Ax && By == Ay) return true;       if (Bx == Ay && By == -Ax) return true;       if (Bx == -Ax && By == -Ay) return true;       if (Bx == -Ay && By == Ax) return true;       return false;     }     if (solvable(Bx - Ax, By - Ay)) return true;     if (solvable(Bx - Ay, By + Ax)) return true;     if (solvable(Bx + Ax, By + Ay)) return true;     if (solvable(Bx + Ay, By - Ax)) return true;     return false;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout << (possible() ?  YES  :  NO ) << endl;     cout << flush;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool a[1000][1000];   int main() {     ios::sync_with_stdio(false);     int n, m, ans = 0;     cin >> n >> m;     bool tmp = 0;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         cin >> a[i][j];       }     }     for (int i = 0; i < n; i++) {       tmp = 0;       for (int j = 0; j < m; j++) {         tmp = max(tmp, a[i][j]);         if (a[i][j] == 0 && tmp) ans++;       }     }     for (int i = 0; i < m; i++) {       tmp = 0;       for (int j = 0; j < n; j++) {         tmp = max(tmp, a[j][i]);         if (a[j][i] == 0 && tmp) ans++;       }     }     for (int i = 0; i < n; i++) {       tmp = 0;       for (int j = m - 1; j >= 0; j--) {         tmp = max(tmp, a[i][j]);         if (a[i][j] == 0 && tmp) ans++;       }     }     for (int i = 0; i < m; i++) {       tmp = 0;       for (int j = n - 1; j >= 0; j--) {         tmp = max(tmp, a[j][i]);         if (a[j][i] == 0 && tmp) ans++;       }     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   char s[6][8], t[10];   int n;   bool match(char* a, char* b) {     for (int i = 0; i < 7; i++)       if (b[i] !=  .  && a[i] != b[i]) return 0;     return 1;   }   int main() {     sprintf(s[0],  jolteon );     sprintf(s[1],  flareon );     sprintf(s[2],  umbreon );     sprintf(s[3],  leafeon );     sprintf(s[4],  glaceon );     sprintf(s[5],  sylveon );     scanf( %d%s , &n, t);     if (n == 6) return 0 * printf( espeon n );     if (n == 8) return 0 * printf( vaporeon n );     for (int i = 0; i < 6; i++)       if (match(s[i], t)) return 0 * printf( %s n , s[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string s, v;   int ans, p, t;   char c;   char tr[1000];   int mypow(int k) {     int c = 1;     for (int i = 1; i <= k; i++) {       c *= 2;     }     return c;   }   int main() {     gets(tr);     s = (string)tr;     p = 0;     for (int i = 0; i < s.length(); i++) {       v =   ;       c = s[i];       int k = 7;       ans = 0;       while ((c > 0) && (k >= 0)) {         if (c % 2 == 1) ans += mypow(k);         k--;         c /= 2;       }       t = (p - ans) % 256;       if (t < 0) t += 256;       cout << t << endl;       p = ans;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct ruchy {     bool kol[55];     bool wiersze[55];   };   int dl, szer, ilosc_ruchow;   int kolumny[55];   int wiersze[55];   ruchy gra[2510];   char palnsza[54][54];   bool dasie = 1;   void wypisgry() {     for (int k = 0; k < ilosc_ruchow; k++) {       cout <<  ruch numer  << k + 1 << endl;       cout <<  kolumny;  << endl;       for (int i = 1; i < 50; i++)         if (gra[k + 1].kol[i]) cout << i <<  , ;       cout << endl;       cout <<  wiersze;  << endl;       for (int i = 1; i < 50; i++)         if (gra[k + 1].wiersze[i]) cout << i <<  , ;       cout << endl;     }   }   int main() {     cin >> dl >> szer;     for (int j = 0; j < dl; j++) {       for (int i = 0; i < szer; i++) {         cin >> palnsza[i + 1][j + 1];       }     }     for (int j = 0; j < dl; j++) {       for (int i = 0; i < szer; i++) {         if (palnsza[i + 1][j + 1] ==  # ) {           if (kolumny[i + 1] != 0) {             if (wiersze[j + 1] != 0 && wiersze[j + 1] != kolumny[i + 1])               dasie = 0;             wiersze[j + 1] = kolumny[i + 1];             gra[kolumny[i + 1]].wiersze[j + 1] = 1;           } else {             if (wiersze[j + 1] != 0) {               if (kolumny[i + 1] != 0 && kolumny[i + 1] != wiersze[j + 1])                 dasie = 0;               kolumny[i + 1] = wiersze[j + 1];               gra[wiersze[j + 1]].kol[i + 1] = 1;             } else {               ilosc_ruchow++;               kolumny[i + 1] = ilosc_ruchow;               wiersze[j + 1] = ilosc_ruchow;               gra[ilosc_ruchow].kol[i + 1] = 1;               gra[ilosc_ruchow].wiersze[j + 1] = 1;             }           }         }       }     }     for (int k = 0; k < ilosc_ruchow; k++) {       for (int j = 0; j < dl; j++) {         for (int i = 0; i < szer; i++) {           if (gra[k + 1].wiersze[j + 1] && gra[k + 1].kol[i + 1] &&               palnsza[i + 1][j + 1] ==  . )             dasie = 0;         }       }     }     if (dasie)       printf( Yes );     else       printf( No );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, c;     cin >> n >> m >> c;     vector<int> a(n);     for (int i = 0; i < n; i++) cin >> a[i];     vector<int> b(n);     for (int i = 0; i < m; i++) cin >> b[i];     int cur = 0;     for (int i = 0; i < a.size(); i++) {       if (i >= 0 && i < m) cur += b[i];       a[i] += cur;       if (i >= (n)-m) cur -= b[i - ((n)-m)];     }     for (int i = 0; i < n; i++) cout << a[i] % c <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long Mo = 1e9 + 7;   int cnt[1 << 6], sz;   void add(long long &x, long long y) {     x += y;     x %= Mo;   }   void gao(int n, int C, int R, vector<vector<long long>> &Ma) {     int loop = 1 << R;     for (int i = 0; i < sz; i++) {       int c = i / loop, r = i % loop;       int a1 = r >> 1, a2 = r >> 1 | (1 << (R - 1));       if ((r & 1) && c != 0) {         Ma[c * loop + a1 - loop][i] += cnt[a1] + 1;         Ma[c * loop + a2 - loop][i] += cnt[a2] + 1;       } else if (!(r & 1)) {         Ma[c * loop + a1][i] += 1;         Ma[c * loop + a2][i] += 1;       }     }   }   void mul(vector<vector<long long>> &a, vector<vector<long long>> b) {     vector<vector<long long>> ret(sz, vector<long long>(sz));     for (int i = 0; i < sz; i++) {       for (int j = 0; j < sz; j++) {         for (int k = 0; k < sz; k++) {           add(ret[i][j], a[i][k] * b[k][j]);         }       }     }     a = ret;   }   void matpw(vector<vector<long long>> &a, long long b) {     vector<vector<long long>> ret(sz, vector<long long>(sz));     for (int i = 0; i < sz; i++) ret[i][i] = 1;     while (b) {       if (b & 1) mul(ret, a);       mul(a, a);       b >>= 1;     }     a = ret;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     for (int i = 0; i < (1 << 6); i++) {       for (int j = 0; j < 6; j++) {         if (i & (1 << j)) cnt[i]++;       }     }     int n, K, m;     cin >> n >> K >> m;     sz = (K + 1) * (1 << m);     vector<vector<long long>> Ma(sz, vector<long long>(sz));     gao(sz, K + 1, m, Ma);     matpw(Ma, n);     vector<vector<long long>> base(sz, vector<long long>(sz));     for (int i = 0; i < sz; ++i) base[i][0] = 1;     mul(base, Ma);     long long ans = 0;     for (int i = 0; i < (1 << m); ++i) add(ans, base[0][sz - i - 1]);     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> cities[100000], T[100000];   bool visited[100000];   int tin[100000], low[100000], tv[100000];   int up[100000][20];   map<pair<int, int>, int> b;   int c = 0, n, l, m, k;   void dfs1(int v, int p = -1) {     visited[v] = true;     tin[v] = low[v] = c++;     for (int dest : cities[v]) {       if (dest == p) continue;       if (visited[dest]) {         low[v] = min(low[v], tin[dest]);       } else {         dfs1(dest, v);         low[v] = min(low[v], low[dest]);         if (low[dest] > tin[v]) {           b[{min(v, dest), max(dest, v)}] = 1;         }       }     }   }   void preprocessbridges() {     memset(visited, false, sizeof visited);     memset(tin, -1, sizeof tin);     memset(low, -1, sizeof low);     for (int i = 0; i < n; ++i) {       if (!visited[i]) {         dfs1(i);       }     }   }   void Tdfs(int u, int d) {     visited[u] = true;     tv[u] = d;     for (int v : cities[u]) {       if (visited[v]) continue;       T[u].push_back(v);       T[v].push_back(u);       Tdfs(v, d + b[{min(u, v), max(u, v)}]);     }   }   void dfs(int v, int p) {     tin[v] = c++;     up[v][0] = p;     for (int i = 1; i <= l; ++i) {       up[v][i] = up[up[v][i - 1]][i - 1];     }     for (int u : T[v]) {       if (u == p) {         continue;       }       dfs(u, v);     }     low[v] = c++;   }   bool is_ancestor(int u, int v) { return tin[u] <= tin[v] && low[u] >= low[v]; }   int lca(int u, int v) {     if (is_ancestor(u, v)) {       return u;     }     if (is_ancestor(v, u)) {       return v;     }     for (int i = l; i >= 0; --i) {       if (!is_ancestor(up[u][i], v)) {         u = up[u][i];       }     }     return up[u][0];   }   void preprocesslca() {     memset(visited, false, sizeof visited);     memset(tv, 0, sizeof tv);     Tdfs(0, -1);     memset(tin, 0, sizeof tin);     memset(low, 0, sizeof low);     c = 0;     l = ceil(log2(n));     memset(up, 0, sizeof up);     dfs(0, 0);   }   void preprocess() {     preprocessbridges();     preprocesslca();   }   int solve(int r, int e) { return tv[r] + tv[e] - 2 * tv[lca(r, e)]; }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> m;     for (int i = 0; i < m; i++) {       int x, y;       cin >> x >> y;       cities[x - 1].push_back(y - 1);       cities[y - 1].push_back(x - 1);     }     preprocess();     cin >> k;     while (k--) {       int root, shop;       cin >> root >> shop;       cout << solve(root - 1, shop - 1) <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long sum[500001], ans;   long long solve(long long a, long long b, long long c, long long hh) {     if (a < b + c) return 0ll;     long long now = min(a - b - c, hh);     return (now + 1) * (now + 2) / 2;   }   int main() {     long long a, b, c, l, i;     scanf( %lld%lld%lld%lld , &a, &b, &c, &l);     sum[0] = 1;     for (i = 1; i <= l; i++) sum[i] = sum[i - 1] + (i + 1) * (i + 2) / 2;     ans = sum[l];     for (i = 0; i <= l; i++)       ans -= solve(a + i, b, c, l - i) + solve(b + i, a, c, l - i) +              solve(c + i, a, b, l - i);     printf( %lld , ans);   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 10005;   long long n, m, a[maxn], b[maxn];   int k;   long long gcd(long long a, long long b) {     if (!b) return a;     return gcd(b, a % b);   }   long long exgcd(long long a, long long b, long long &x, long long &y) {     if (!b) {       x = 1, y = 0;       return a;     }     long long r = exgcd(b, a % b, x, y), x0 = x;     x = y;     y = x0 - (a / b) * y;     return r;   }   long long CRT(long long *m, long long *a) {     long long lcm = 1, X = m[1], Y = a[1];     for (int i = 1; i <= k; i++) lcm = lcm / gcd(lcm, m[i]) * m[i];     for (int i = 2; i <= k; i++) {       long long A = X, B = m[i], d, x, y, c = a[i] - Y;       d = exgcd(A, B, x, y);       if (c % d) return -1;       long long mod = m[i] / d;       long long K = ((x * c / d) % mod + mod) % mod;       Y = X * K + Y;       X = X * m[i] / d;     }     if (Y == 0) return lcm;     return Y;   }   bool check() {     long long I = CRT(a, b), J;     if (I > n || I <= 0) return 0;     for (int i = 1; i <= k; i++) b[i] = 1 - i;     J = CRT(a, b);     if (J + k - 1 > m || J <= 0) return 0;     for (int i = 1; i <= k; i++)       if (gcd(I, J + i - 1) != a[i]) return 0;     return 1;   }   int main() {     cin >> n >> m >> k;     for (int i = 1; i <= k; i++) cin >> a[i];     if (check())       cout <<  YES  << endl;     else       cout <<  NO  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100 * 1000 + 17;   long long n, a[MAXN], ans;   int main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = 1; i < n; i++) {       int t = log2(n - i);       a[i + (1 << t)] += a[i];       ans += a[i];       a[i] = 0;       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, a[101];   void scan() {     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %d , &a[i]);     sort(a, a + n);   }   void out() {     int ans = 0, k = 0, c;     while (1) {       c = 0;       for (int i = 0; i < n; i++) {         if (a[i] != -1) {           if (a[i] >= k) {             ++k;             a[i] = -1;           }         } else if (a[i] == -1)           ++c;       }       if (c == n) break;       ++ans;       k = 0;     }     cout << ans <<   n ;   }   int main() {     scan();     out();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n;   vector<pair<long long, long long> > serv;   bool check(long long x1, long long x2) {     long long pos = 0;     bool found = false;     for (long long i = n - 1; i >= 0; --i) {       if (serv[i].first * (n - i) >= x2) {         found = true;         pos = i;         break;       }     }     if (!found) {       return false;     }     found = false;     for (long long i = pos - 1; i >= 0; --i) {       if (serv[i].first * (pos - i) >= x1) {         found = true;         break;       }     }     return found;   }   pair<vector<long long>, vector<long long> > print(long long x1, long long x2) {     vector<long long> a1, a2;     long long pos = 0;     for (long long i = n - 1; i >= 0; --i) {       a2.push_back(serv[i].second);       if (serv[i].first * (n - i) >= x2) {         pos = i;         break;       }     }     for (long long i = pos - 1; i >= 0; --i) {       a1.push_back(serv[i].second);       if (serv[i].first * (pos - i) >= x1) {         break;       }     }     return {a1, a2};   }   void solve() {     long long x1 = 0, x2 = 0;     cin >> n >> x1 >> x2;     serv.resize(n);     for (long long i = 0; i < n; ++i) {       cin >> serv[i].first;       serv[i].second = i;     }     sort(serv.begin(), serv.end());     if (check(x1, x2)) {       cout <<  Yes  << endl;       auto ans = print(x1, x2);       cout << ans.first.size() <<     << ans.second.size() << endl;       for (long long x : ans.first) cout << x + 1 <<    ;       cout << endl;       for (long long x : ans.second) cout << x + 1 <<    ;       cout << endl;     } else if (check(x2, x1)) {       cout <<  Yes  << endl;       auto ans = print(x2, x1);       cout << ans.second.size() <<     << ans.first.size() << endl;       for (long long x : ans.second) cout << x + 1 <<    ;       cout << endl;       for (long long x : ans.first) cout << x + 1 <<    ;       cout << endl;     } else {       cout <<  No  << endl;     }   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 9, base = 27;   int cnt_list, pos[20200], pa[20100], len[20100], fs[20100], pc[20100],       ls[20100], cnt_ls, tmp[20100], cnt, n, num_q;   struct pp {     int id;     char ch;   };   vector<pp> adj[20201];   pp now;   void dfs(int id, int pr) {     int i, j, s, p, q, ip;     pos[id] = cnt_list++;     pa[pos[id]] = pr;     for (i = 0; i < adj[id].size(); i++) {       ip = adj[id][i].id;       if (pos[ip] >= 0) continue;       pc[cnt_list] = adj[id][i].ch -  a ;       dfs(ip, pos[id]);     }   }   int main() {     int id1, id2, i, j, s, p, q, x, y, fg;     char ch;     scanf( %d%d , &n, &num_q);     for (i = 0; i < n - 1; i++) {       scanf( %d%d , &id1, &id2);       ch = getchar();       while (ch <  a  || ch >  z ) ch = getchar();       id1--;       id2--;       now.id = id2;       now.ch = ch;       adj[id1].push_back(now);       now.id = id1;       now.ch = ch;       adj[id2].push_back(now);     }     memset(pos, -1, sizeof(pos));     dfs(0, -1);     while (num_q--) {       scanf( %d%d , &x, &y);       x--;       y--;       x = pos[x];       y = pos[y];       int u, v;       u = x;       v = y;       cnt_ls = cnt = 0;       while (u != v) {         if (u > v) {           ls[cnt_ls++] = pc[u];           u = pa[u];         } else {           tmp[cnt++] = pc[v];           v = pa[v];         }       }       while (cnt > 0) ls[cnt_ls++] = tmp[--cnt];       for (i = 0; i < n; i++) len[i] = -1;       u = x;       fs[u] = len[u] = 0;       int ans = 0;       while (u != 0) {         len[pa[u]] = len[u] + 1;         if (fs[u] == 0) {           if (len[u] < cnt_ls) {             if (ls[len[u]] > pc[u])               fs[pa[u]] = -1;             else if (ls[len[u]] < pc[u])               fs[pa[u]] = 1;             else               fs[pa[u]] = 0;           } else             fs[pa[u]] = 1;         } else           fs[pa[u]] = fs[u];         if (fs[pa[u]] < 0 || (fs[pa[u]] == 0 && len[pa[u]] != cnt_ls)) ans++;         u = pa[u];       }       for (i = 1; i < n; i++) {         if (len[pa[i]] >= 0 && len[i] < 0) {           len[i] = len[pa[i]] + 1;           if (fs[pa[i]] == 0) {             if (len[pa[i]] < cnt_ls) {               if (ls[len[pa[i]]] > pc[i])                 fs[i] = -1;               else if (ls[len[pa[i]]] < pc[i])                 fs[i] = 1;               else                 fs[i] = 0;             } else               fs[i] = 1;           } else             fs[i] = fs[pa[i]];           if (fs[i] < 0 || (fs[i] == 0 && len[i] != cnt_ls)) ans++;         }       }       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 50 + 7;   int ned[N][N];   string s[N];   void paint(const vector<pair<int, int> > &v) {     set<pair<int, int> > s;     queue<pair<int, int> > que;     map<pair<int, int>, int> cnt;     for (auto e : v) {       que.push(e);       s.insert(e);     }     const int dx[] = {2, 2, 1, 1, -1, -1, -2, -2};     const int dy[] = {1, -1, 2, -2, 2, -2, 1, -1};     int tot = 0;     while (!que.empty()) {       auto p = que.front();       que.pop();       tot++;       for (int i = (0); i < (8); i++) {         int x = p.first + dx[i];         int y = p.second + dy[i];         if (s.find(make_pair(x, y)) != s.end()) continue;         if (++cnt[make_pair(x, y)] == 4) {           s.insert({x, y});           que.push({x, y});         }       }     }     cout <<  sz(s)           <<   =   << (((int)(s).size())) <<   n ;     int des = ((int)(v).size()) * ((int)(v).size()) / 10;     cout <<  des           <<   =   << (des) <<   n ;   }   int main() {     std::ios::sync_with_stdio(false);     std::cin.tie(0);     int n;     cin >> n;     vector<pair<int, int> > v;     for (int i = (0); i < (n); i++) {       if (i & 1) v.push_back({3, i});       v.push_back({0, i});       if (((int)(v).size()) > n) break;     }     v.resize(n);     for (auto e : v) cout << e.first <<     << e.second <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long x, y, p, q;   bool check(long long t) {     return ((p * t >= x) && ((q * t - p * t) >= (y - x)));   }   int main() {     int t;     scanf( %d , &t);     while (t--) {       scanf( %I64d%I64d%I64d%I64d , &x, &y, &p, &q);       long long l = 0, r = 1e9, mid;       long long ans = -1;       while (l <= r) {         mid = (l + r) / 2;         if (check(mid)) {           ans = mid;           r = mid - 1;         } else           l = mid + 1;       }       if (ans == -1)         printf( -1 n );       else         printf( %I64d n , ans * q - y);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 998244353;   inline int add(int a, int b) {     a += b;     if (a >= mod) a -= mod;     return a;   }   inline int sub(int a, int b) {     a -= b;     if (a < 0) a += mod;     return a;   }   inline int mul(int a, int b) { return (a * 1ll * b) % mod; }   inline int power(int a, int b) {     int rt = 1;     while (b > 0) {       if (b & 1) rt = mul(rt, a);       a = mul(a, a);       b >>= 1;     }     return rt;   }   inline int inv(int a) { return power(a, mod - 2); }   const int N = 1e6 + 5;   vector<int> z_function(string s) {     int n = (int)s.length();     vector<int> z(n);     for (int i = 1, l = 0, r = 0; i < n; ++i) {       if (i <= r) z[i] = min(r - i + 1, z[i - l]);       while (i + z[i] < n && s[z[i]] == s[i + z[i]]) ++z[i];       if (i + z[i] - 1 > r) l = i, r = i + z[i] - 1;     }     return z;   }   string a;   int mat[N][2], sum0[N], dp[N], sumdp[N];   void fill(string s, int ind) {     string s1 = s +  $  + a;     vector<int> v = z_function(s1);     int n1 = s.size(), n = a.size();     for (int i = 0; i < n; i++) mat[i][ind] = v[n1 + 1 + i];   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cout << setprecision(25);     string l, r;     cin >> a >> l >> r;     int n = a.size(), l1 = l.size(), r1 = r.size();     fill(l, 0);     fill(r, 1);     for (int i = 0; i < n; i++) {       if (i + 1 < l1) continue;       if (i > 0) sum0[i] = sum0[i - 1], sumdp[i] = sumdp[i - 1];       if (a[i] ==  0 ) sum0[i] = add(sum0[i], i - 1 < 0 ? 1 : dp[i - 1]);       int ind1 = -1, ind2 = -1;       ind1 = i - l1 + 1;       int x = mat[ind1][0];       if (x < l1 && a[ind1 + x] < l[x]) ind1--;       if (ind1 < 0) continue;       ind2 = i - r1 + 1;       if (ind2 < 0)         ind2 = 0;       else {         x = mat[ind2][1];         if (x != r1 && a[ind2 + x] > r[x]) ind2++;       }       if (ind2 > ind1) continue;       if (ind1 == ind2) {         if (ind1 == 0)           dp[i] = 1;         else           dp[i] = dp[ind1 - 1];         if (i - ind1 > 0 && a[ind1] ==  0 ) dp[i] = 0;       } else {         dp[i] = sub(sub(sumdp[ind1 - 1], (ind2 - 2 < 0 ? ind2 == 0 ? mod - 1 : 0                                                        : sumdp[ind2 - 2])),                     sub(sum0[ind1], (ind2 - 1 < 0 ? 0 : sum0[ind2 - 1])));         if (i == ind1 && a[i] ==  0 ) dp[i] = add(dp[i], i == 0 ? 1 : dp[i - 1]);       }       sumdp[i] = add(sumdp[i], dp[i]);     }     cout << dp[n - 1] << endl;   }


#include <bits/stdc++.h>   #include <chrono>      using namespace std;      using ll           = long long;   using ld           = long double;   using pii          = pair<int, int>;   using pll          = pair<long, long>;   using vi           = vector<int>;   using vl           = vector<long long>;   using vb           = vector<bool>;   using vs           = vector<string>;   using vld          = vector<long double>;      #define pb             push_back   #define f              first   #define s              second   #define sz(a)          int((a).size())   #define all(a)         (a).begin(), (a).end()   #define rall(a)        (a).rbegin(), (a).rend()   #define sum(a)         ( accumulate((a).begin(), (a).end(), 0LL))   #define mine(a)        (*min_element((a).begin(), (a).end()))   #define maxe(a)        (*max_element((a).begin(), (a).end()))   #define mini(a)        ( min_element((a).begin(), (a).end()) - (a).begin())   #define maxi(a)        ( max_element((a).begin(), (a).end()) - (a).begin())   #define lowb(a, x)     ( lower_bound((a).begin(), (a).end(), (x)) - (a).begin())   #define uppb(a, x)     ( upper_bound((a).begin(), (a).end(), (x)) - (a).begin())   #define each(a, b)     for (auto &a: b)   #define yes            cout <<  YES  << endl   #define no             cout <<  NO   << endl      mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());      const ll mod = 1e9 + 7;      ll n, m, k, p, q, l, r, u, v, x, y, z;   // ll ans = 0;      void solve(int t = 1) {       cin >> n >> m;          vi a(n), b(n), c(m);       each(u, a) cin >> u;       each(u, b) cin >> u;       each(u, c) cin >> u;          vi ans(m, 0);          map<int, vi> mp;       for (int i = 0; i < m; i++) {           mp[c[i]].push_back(i);       }          for (int i = 0; i < n; i++) {           if (a[i] != b[i]) {               if (!mp[b[i]].empty()) {                   a[i] = b[i];                   ans[mp[b[i]].back()] = i + 1;                   mp[b[i]].pop_back();               } else {                   no;                   return;               }           }       }          if (a != b) {           no;           return;       }          if (ans[m - 1] == 0) {           bool flag = true;              for (int i = 0; i < n; i++) {               if (c[m - 1] == b[i]) {                   ans[m - 1] = i + 1;                   flag = false;                   break;               }           }              if (flag) {               no;               return;           }       }          each(u, ans) {           if (u == 0) u = ans[m - 1];       }          yes;       each(u, ans) cout << u <<    ;       cout << endl;   }      int main() {       ios_base::sync_with_stdio(false);       cin.tie(NULL);          int tc = 1;       cin >> tc;          for (int t = 1; t <= tc; t++) solve(t);          return 0;   }


#include <bits/stdc++.h>   using namespace std;   #define endl   n    typedef long long ll;   typedef pair<int, int> pii;   typedef pair<ll, ll> pll;   typedef tuple<int, int, int> tiii;   typedef tuple<ll, ll, ll> tlll;   const int INF = 100000000;   const ll INFINITE = 4500000000000000000;      int main(void) {    int t;    cin >> t;    while (t--) {     int s1, s2, s3, s4;     cin >> s1 >> s2 >> s3 >> s4;     if (min(s1, s2) < max(s3, s4) &&min(s3, s4) <max(s1, s2))      cout <<  YES  << endl;     else      cout <<  NO  << endl;       }   }


#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1);   int main() {     int n;     double R, r;     double st;     while (scanf( %d %lf , &n, &R) != EOF) {       st = pi / (1.0 * n);       r = sin(st) * R / (1 - sin(st));       printf( %.7lf n , r);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, m;     cin >> n >> m;     if (m == 0) {       cout << n <<     << n << endl;       return 0;     }     long long min = 0;     if (m * 2ll <= n) {       min = n - m * 2;     }     long long e = 1;     long long g = 2;     long long max = 0;     for (long long i = 2; i <= n; i++) {       if (e >= m) {         max = n - i;         break;       }       e += g;       g++;     }     cout << min <<     << max << endl;     return 0;   }


#include<bits/stdc++.h>   #define rep(i, n) for(int i = 0; i < n; i++)   using namespace std;   typedef long long ll;   const ll Mod = 1000000007;      int t;   int n;   ll x[500500];   ll sum_bit[70];      int main(){    ios::sync_with_stdio(false);    cin >> t;    while(t--){     cin >> n;     rep(i, n) cin >> x[i];     memset(sum_bit, 0, sizeof(sum_bit));     rep(b, 60) rep(i, n) sum_bit[b] = (sum_bit[b] + (x[i] & (1LL << b))) % Mod;     ll ans = 0;     rep(j, n){      ll sum_and = 0, sum_or = 0;      rep(b, 60){       if(x[j] & (1LL << b)) sum_and = (sum_and + sum_bit[b]) % Mod, sum_or = (sum_or + (1LL << b) % Mod * n % Mod) % Mod;       else sum_or = (sum_or + sum_bit[b]) % Mod;      }      ans = (ans + sum_and * sum_or) % Mod;     }     cout << ans << endl;    }    return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct ant {     int id;     int novo_id;     long long int p;     int dir;   };   struct rotate_edges {     int id_ini;     int id_fim;   };   int compara_p(ant a, ant b) {     return a.p < b.p || (a.p == b.p && a.dir < b.dir);   }   int compara_p_reverso(ant a, ant b) { return a.p > b.p; }   int compara_id(ant a, ant b) { return a.id < b.id; }   int cont_pos, cont_neg;   long long int N, M, T;   ant v[400000];   ant v_final[400000];   ant v_pos[400000];   ant v_neg[400000];   char c;   rotate_edges calcula_rotate_edges(long long int t, int pivot) {     long long int p_pivot = v[pivot].p;     int cont_neg = 0;     int cont_pos = 0;     for (int i = 0; i < N; i++) {       if (v[i].dir < 0) {         v_neg[cont_neg] = v[i];         if (v_neg[cont_neg].p < p_pivot) v_neg[cont_neg].p += M;         cont_neg++;       } else {         v_pos[cont_pos] = v[i];         if (v_pos[cont_pos].p > p_pivot) v_pos[cont_pos].p -= M;         cont_pos++;       }     }     sort(v_neg, v_neg + cont_neg, compara_p);     sort(v_pos, v_pos + cont_pos, compara_p_reverso);     rotate_edges resp;     if (cont_neg == 0) {       resp.id_ini = v_pos[0].id;       resp.id_fim = v_pos[0].id;     } else if (cont_pos == 0) {       resp.id_ini = v_neg[0].id;       resp.id_fim = v_neg[0].id;     } else {       resp.id_ini = v_pos[0].id;       resp.id_fim = v_pos[0].id;       int id_pos;       int id_neg;       long long int p_pos;       long long int p_neg;       for (int i = 0;; i++) {         id_pos = (i + 1) / 2;         id_neg = i / 2;         p_pos = v_pos[id_pos % cont_pos].p - M * (id_pos / cont_pos);         p_neg = v_neg[id_neg % cont_neg].p + M * (id_neg / cont_neg);         if (p_neg - p_pos <= 2 * t) {           resp.id_fim = (i % 2 == 0) ? v_neg[id_neg % cont_neg].id                                      : v_pos[id_pos % cont_pos].id;         } else {           break;         }       }     }     return resp;   }   long long int calcula_delta(rotate_edges re) {     int vi_ini, vi_fim;     for (int i = 0; i < N; i++) {       if (v[i].id == re.id_ini) vi_ini = i;       if (v[i].id == re.id_fim) vi_fim = i;     }     return (vi_fim + N - vi_ini) % N;   }   void rotate(long long int delta) {     for (int i = 0; i < N; i++) {       v[i].novo_id = v[(i + N - delta) % N].id;     }     for (int i = 0; i < N; i++) {       v[i].id = v[i].novo_id;     }   }   void rotate_final(rotate_edges re) {     int id, id_final;     for (int i = 0; i < N; i++) {       if (v[i].id == re.id_ini) id = i;       if (v_final[i].id == re.id_fim) id_final = i;     }     for (int i = 0; i < N; i++) {       v_final[(id_final + i) % N].id = v[(id + i) % N].id;     }   }   int main() {     scanf(  %lld %lld %lld , &N, &M, &T);     for (int i = 0; i < N; i++) {       v[i].id = i;       scanf(  %lld %c , &v[i].p, &c);       v[i].p = v[i].p % M;       if (c ==  L ) {         v[i].dir = -1;       } else {         v[i].dir = 1;       }     }     sort(v, v + N, compara_p);     int pivot = 0;     for (int i = 0; i < N; i++) {       if (v[i].dir > 0 && v[(i + 1) % N].dir < 0) {         pivot = i;         break;       }     }     long long int delta_por_ciclo = calcula_delta(calcula_rotate_edges(M, pivot));     rotate((delta_por_ciclo * (T / M)) % N);     T = T % M;     rotate_edges re = calcula_rotate_edges(T, pivot);     for (int i = 0; i < N; i++) {       v_final[i] = v[i];       v_final[i].p = (((v[i].p + v[i].dir * T) % M) + M) % M;     }     sort(v_final, v_final + N, compara_p);     rotate_final(re);     sort(v_final, v_final + N, compara_id);     printf( %d , v_final[0].p == 0 ? M : v_final[0].p);     for (int i = 1; i < N; i++) {       printf(  %d , v_final[i].p == 0 ? M : v_final[i].p);     }     printf(  n );     return 0;   }


#include <bits/stdc++.h>   int max(int a, int b) { return a > b ? a : b; }   int a[510][510], num[510], n, m, Q, ans, x, y;   void work(int pos) {     num[pos] = 0;     int f = 0;     for (int i = 1; i <= m; i++)       if (a[pos][i])         f++;       else         num[pos] = max(num[pos], f), f = 0;     num[pos] = max(num[pos], f);   }   int main() {     scanf( %d%d%d , &n, &m, &Q);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) scanf( %d , &a[i][j]);     for (int i = 1; i <= n; i++) work(i), ans = max(ans, num[i]);     for (int t = 1; t <= Q; t++) {       scanf( %d%d , &x, &y);       a[x][y] = a[x][y] ^ 1;       work(x);       ans = 0;       for (int i = 1; i <= n; i++) ans = max(ans, num[i]);       printf( %d n , ans);     }   }


#include <bits/stdc++.h>   int main() {     int n, start;     char str[60];     scanf( %s , str);     n = strlen(str);     n = n % 2 ? n / 2 : n / 2 - 1;     printf( %c , str[n]);     for (int i = 1; i <= n; i++) printf( %c%c , str[n + i], str[n - i]);     if (strlen(str) % 2 == 0 && strlen(str) > 1)       printf( %c , str[strlen(str) - 1]);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, cntx = 0, cntX = 0, c = 0;     cin >> n;     string s;     cin >> s;     for (int i = 0; i < n; i++) {       if (s[i] ==  x )         cntx++;       else         cntX++;     }     int i = 0;     if (cntx > cntX) {       while (cntx != cntX) {         if (s[i] ==  x ) {           s[i] =  X ;           cntx--;           c++;           cntX++;         }         i++;       }     } else {       while (cntx != cntX) {         if (s[i] ==  X ) {           s[i] =  x ;           cntX--;           cntx++;           c++;         }         i++;       }     }     cout << c << endl << s << endl;     return 0;   }


#include <bits/stdc++.h>   const double EPS = 1e-9;   const int INT_INF = 1 << 31 - 1;   const long long I64_INF = 1ll << 63 - 1ll;   const double PI = acos(-1.0);   using namespace std;   vector<int> r;   string second;   void ReadTable(int id, int& FinalId);   string GetTag(int id) {     string res =   ;     id++;     while (second[id] !=  > ) res += second[id], id++;     return res;   }   void ReadTd(int id, int& FinalId) {     string tag = GetTag(id);     while (tag !=  /td ) {       int NewId;       ReadTable(id + 7, NewId);       id = NewId;       tag = GetTag(id);     }     FinalId = id + 5;   }   int ReadTr(int id, int& FinalId) {     int res = 0;     string tag = GetTag(id);     while (tag !=  /tr ) {       int NewId;       ReadTd(id + 4, NewId);       id = NewId;       res++;       tag = GetTag(id);     }     FinalId = id + 5;     return res;   }   void ReadTable(int id, int& FinalId) {     int res = 0;     string tag = GetTag(id);     while (tag !=  /table ) {       int NewId;       res += ReadTr(id + 4, NewId);       id = NewId;       tag = GetTag(id);     }     FinalId = id + 8;     r.push_back(res);   }   int main() {     char c;     second.clear();     while (scanf( %c , &c) >= 1)       if (c !=     && c !=   n ) second += c;     int loose;     ReadTable(7, loose);     sort(r.begin(), r.end());     for (int i = 0; i < (int)r.size(); i++) printf( %d  , r[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, T, cnt, top;   char s[5100][5100];   struct poi {     int x, y;     poi() {}     poi(int x, int y) : x(x), y(y) {}     void trs() {       swap(x, y);       x--;       y = n - y;     }     friend bool operator<(const poi &r1, const poi &r2) {       if (r1.x == r2.x) return r1.y < r2.y;       return r1.x < r2.x;     }     friend int operator^(const poi &r1, const poi &r2) {       return r1.x * r2.y - r2.x * r1.y;     };     friend poi operator-(const poi &r1, const poi &r2) {       return poi(r1.x - r2.x, r1.y - r2.y);     };   } a[5100 << 5], st[5100 << 5];   int onleft(poi p1, poi p2, poi p3) { return ((p1 - p2) ^ (p3 - p2)) >= 0; }   int main() {     while (scanf( %d , &n) != EOF && n) {       top = 0;       cnt = 0;       for (int i = 1; i <= n; i++) scanf( %s , s[i] + 1);       for (int i = 1; i <= n; i++)         for (int j = 1; j <= n; j++)           if (s[i][j] >  0  && s[i][j + 1] >  0  && s[i + 1][j] >  0  &&               s[i + 1][j + 1] >  0  &&               (s[i][j] ==  1  || s[i][j + 1] ==  1  || s[i + 1][j] ==  1  ||                s[i + 1][j + 1] ==  1 ))             a[++cnt] = poi(i, j + 1);       for (int i = 1; i <= cnt; i++) a[i].trs();       sort(a + 1, a + 1 + cnt);       for (int i = 1; i <= cnt; i++) {         while (top >= 2 && onleft(st[top], st[top - 1], a[i])) top--;         st[++top] = a[i];       }       int t = top;       for (int i = cnt - 1; i >= 1; i--) {         while (top > t && onleft(st[top], st[top - 1], a[i])) top--;         st[++top] = a[i];       }       printf( %d n , top - 1);       for (int i = 1; i < top; i++) printf( %d %d n , st[i].x, st[i].y);     }     return 0;   }


#pragma GCC optimize(3, Ofast , inline )   #include <cstdio>   #include <iostream>   #include <cstring>   #include <algorithm>   #include <cmath>   #include <set>   #include <map>   #include <vector>   #include <stack>   #include <queue>   using namespace std;   typedef long long ll;      typedef pair<int, int> pii;   const int maxn = 1e6 + 10;   const ll mod = 1e9 + 7;   const double pi = acos(-1.0);   const double eps = 1e-8;      int t;   int n, k;   string s1, s2;   int cnt[27];      void solve()   {     int f = 0;     memset(cnt, 0, sizeof(cnt));     sort(s1.begin(), s1.end());     sort(s2.begin(), s2.end());     if(s1 == s2)  puts( Yes );     else{       for(int i = 0; i < n; i ++) cnt[s1[i] -  a ] ++;       for(int i = 0; i < n; i ++) cnt[s2[i] -  a ] --;       for(int i = 0; i < 26; i ++){         if(cnt[i] < 0 || cnt[i] % k){             f = 1;             break;           }         cnt[i + 1] += cnt[i];       }       puts(!f ?  Yes  :  No );     }   }      int main(){     std::ios::sync_with_stdio(false);     cin >> t;     while(t --){       cin >> n >> k;       cin >> s1 >> s2;       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, x, a, s;   vector<pair<int, long long> > v, u;   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       cin >> x >> a;       if (x < 0)         v.push_back(make_pair(-x, a));       else         u.push_back(make_pair(x, a));       s += a;     }     sort(v.begin(), v.end());     sort(u.begin(), u.end());     if ((int)v.size() - (int)u.size() <= 1 &&         (int)u.size() - (int)v.size() <= 1) {       cout << s << endl;       return 0;     }     if (v.size() > u.size()) {       for (int i = u.size() + 1; i < v.size(); i++) s -= v[i].second;       cout << s << endl;       return 0;     }     for (int i = v.size() + 1; i < u.size(); i++) s -= u[i].second;     cout << s << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string i_str(int n) {     char buff[10];     sprintf(buff,  %d , n);     return string(buff);   }   int main() {     int a, b;     cin >> a >> b;     if (a < b) {       cout << b;       return 0;     }     string sa, sb, t, r =   , si =   ;     sb = i_str(b);     for (int j = a + 1; j <= 1000000; j++) {       r =   ;       si = i_str(j);       int ni = si.length();       for (int i = 0; i < ni; i++) {         if (si[i] ==  4 ) r = r + si[i];         if (si[i] ==  7 ) r = r + si[i];       };       if (r == sb) {         cout << j;         return 0;       }     }     return 0;   }