#include <bits/stdc++.h>   using namespace std;   string s;   int num_e = 1e9 + 10, num_m, ans, w, q;   string answer;   void read_input() { cin >> s; }   void solve() {     for (int i = 0; i < s.size(); i++) {       if (s[i] ==  e ) num_e = i;       if (s[i] ==  . ) num_m = i;     }     string s2 =   ;     for (int i = 0; i < num_e; i++)       if (s[i] !=  . ) s2 += s[i];     for (int i = num_e + 1; i < s.size(); i++) {       int q = s[i] -  0 ;       w = w * 10 + q;     }     w -= (num_e - num_m - 1);     if (w >= 0) {       answer += s2;       for (int i = 0; i < w; i++) answer +=  0 ;     } else {       for (int i = 0; i < s2.size(); i++) {         if (s2.size() - i == -w) answer +=  . ;         answer += s2[i];       }     }   }   void write_output() {     bool check = false;     for (int i = 0; i < answer.size(); i++)       if (answer[i] !=  .  && answer[i] !=  0 ) check = true;     if (!check)       cout << 0;     else {       int start;       for (int i = 0; i < answer.size(); i++) {         if (answer[i] ==  . ) {           start = i - 1;           break;         }         if (answer[i] !=  0 ) {           start = i;           break;         }       }       int num_m = -1;       for (int i = 0; i < answer.size(); i++)         if (answer[i] ==  . ) num_m = i;       check = false;       for (int i = num_m + 1; i < answer.size(); i++)         if (answer[i] !=  0 ) check = true;       if (check || num_m == -1)         for (int i = start; i < answer.size(); i++) cout << answer[i];       else         for (int i = start; i < num_m; i++) cout << answer[i];     }   }   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     read_input(), solve(), write_output();   }


#include <bits/stdc++.h>   using namespace std;   const bool online_judge = true;   const long long inf = 1LL << 60;   long long toInt(string s) {     long long res;     stringstream ss;     ss << s;     ss >> res;     return res;   }   string toString(long long n) {     stringstream ss;     ss << n;     return ss.str();   }   long long dx[3] = {1, 0, -1};   long long dy[3] = {1, 0, -1};   vector<pair<long long, long long> > statue;   bool valid(long long x, long long y, long long turn) {     if (!(((x) >= (0) && (x) <= (7)) && ((y) >= (0) && (y) <= (7)))) return false;     for (long long i = 0; i < ((long long)((statue).size())); i++) {       long long sx = statue[i].first + turn;       long long sy = statue[i].second;       if ((sx == x && sy == y) || (sx + 1 == x && sy == y)) return false;     }     return true;   }   bool solve(long long x, long long y, long long turn) {     if (turn == 8) return true;     for (long long i = 0; i < 3; i++) {       for (long long j = 0; j < 3; j++) {         long long nx = x + dx[i];         long long ny = y + dy[j];         if (valid(nx, ny, turn) && solve(nx, ny, turn + 1)) {           return true;         }       }     }     return false;   }   void run() {     statue.clear();     for (long long i = 0; i < 8; i++) {       string s;       cin >> s;       for (long long j = 0; j < 8; j++) {         if (s[j] ==  S ) statue.emplace_back(i, j);       }     }     bool ans = solve(7, 0, 0);     if (ans)       cout <<  WIN  << endl;     else       cout <<  LOSE  << endl;   }   int main(int argc, char *argv[]) {     run();     return 0;   }


#include <bits/stdc++.h>   int const M = 1010000;   int const N = 10100;   int n;   int len[N];   int x[N];   int y[N];   int sq[M];   int perm[N];   double angle[N];   int resx[N];   int resy[N];   void filllens() {     std::fill(sq, sq + M, -1);     for (int i = 0; i * i < M; ++i) {       sq[i * i] = i;     }     int last = 0;     int sum = 0;     for (int i = n - 1; i >= 0; --i) {       while (x[i] == 0 && y[i] == 0) {         len[i] = ++last;         x[i] = 0;         y[i] = 0;         for (int q = 0; q * q <= len[i]; ++q) {           if (sq[len[i] - q * q] != -1) {             x[i] = q;             y[i] = sq[len[i] - q * q];             break;           }         }       }       sum += len[i];     }     if (sum % 2 == 1) {       int xx = 0;       int yy = 0;       while (xx == 0 && yy == 0) {         ++last;         for (int q = 0; q * q <= last; ++q) {           if (sq[last - q * q] != -1) {             xx = q;             yy = sq[last - q * q];             break;           }         }       }       int i = 0;       while (len[i] % 2 == last % 2) ++i;       len[i] = last;       x[i] = xx;       y[i] = yy;       for (; i > 0; --i) {         std::swap(len[i], len[i - 1]);         std::swap(x[i], x[i - 1]);         std::swap(y[i], y[i - 1]);       }     }   }   void solve() {     filllens();     int sumx = 0;     int sumy = 0;     std::function<int(int, int)> len2 = [](int x, int y) {       return x * x + y * y;     };     for (int i = 0; i < n; ++i) {       int ax = x[i];       int ay = y[i];       for (int it = 0; it < 2; ++it) {         for (int px : {-1, 1}) {           for (int py : {-1, 1}) {             if (len2(sumx + ax, sumy + ay) >                 len2(sumx + px * x[i], sumy + py * y[i])) {               ax = px * x[i];               ay = py * y[i];             }           }         }         std::swap(x[i], y[i]);       }       x[i] = ax;       y[i] = ay;       sumx += ax;       sumy += ay;     }     assert(sumx == 0 && sumy == 0);     for (int i = 0; i < n; ++i) {       perm[i] = i;       angle[i] = atan2(x[i], y[i]);     }     std::sort(perm, perm + n, [](int i, int j) { return angle[i] > angle[j]; });     sumx = 0;     sumy = 0;     for (int i = 0; i < n; ++i) {       resx[i] = sumx;       resy[i] = sumy;       sumx += x[perm[i]];       sumy += y[perm[i]];     }   }   void out() {     puts( YES );     for (int i = 0; i < n; ++i) {       printf( %d %d n , resx[i], resy[i]);     }   }   int main() {     scanf( %d , &n);     solve();     out();   }


#include <bits/stdc++.h>   using namespace std;   int _;   long long a1, a2, b1, b2, c1, c2;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> a1 >> a2 >> b1 >> b2 >> c1 >> c2;     if ((c2 - b2) * (c1 - a1) == (c2 - a2) * (c1 - b1)) {       cout <<  No ;     } else if ((a1 - b1) * (a1 - b1) + (a2 - b2) * (a2 - b2) ==                (b1 - c1) * (b1 - c1) + (b2 - c2) * (b2 - c2)) {       cout <<  Yes ;     } else       cout <<  No ;   }


#include <bits/stdc++.h>   using namespace std;   const int oo = ~0u >> 1;   int n, m, a, ans;   int b[100015], p[100015];   bool check(int x) {     int sum = 0;     ans = 0;     for (int i = 0; i < x; i++) {       sum += max(p[x - i - 1] - b[i], 0), ans += p[x - i - 1];       if (sum > a) break;     }     if (sum <= a) return true;     return false;   }   int main() {     scanf( %d %d %d , &n, &m, &a);     for (int i = 0; i < n; i++) scanf( %d , &b[i]);     for (int i = 0; i < m; i++) scanf( %d , &p[i]);     sort(b, b + n, greater<int>());     sort(p, p + m);     int l = 0, r = min(n, m), res = 0, anser = 0;     while (l <= r) {       int mid = l + (r - l) / 2;       if (check(mid)) {         res = mid, anser = ans;         l = mid + 1;       } else         r = mid - 1;     }     printf( %d %d n , res, max(anser - a, 0));     return 0;   }


#if !defined(ONLINE_JUDGE)       #include  prettyprint.hpp         #include  debug.h    #else       #include <bits/stdc++.h>       using namespace std;       #define deb(...) 1729       #define dbg(...) 29       #define cer(x) 13   #endif   const bool testcase = 1;   typedef long long int ll;   const ll mod1 = 1000000007;   const ll mod2 = 998244353;      #define fast ios_base::sync_with_stdio(0);cin.tie(NULL)    #define test int T_T = 1; if(testcase){cin>>T_T;}while(T_T--)   #define all(ve) ve.begin(),ve.end()      const ll N = 1e7 + 7;   std::vector<ll> spf, prime;   std::vector<bool> isp;   void sieve(ll MAXN) {        spf.resize(MAXN);       spf[1] = 1;        for (int i=2; i<MAXN; i++)            spf[i] = i;        for (int i=4; i<MAXN; i+=2)            spf[i] = 2;           for (int i=3; i*i<MAXN; i++)        {            if (spf[i] == i)            {                for (int j=i*i; j<MAXN; j+=i)                {                   if (spf[j]==j)                        spf[j] = i;                }           }        }    }    void linearSieve(ll n) {       spf.resize(n);       isp.resize(n,true);       isp[0] = isp[1] = 0;       isp[2] = 1;       for (int i = 2; i <= n; ++i) {           if(isp[i]) {               prime.push_back(i);               spf[i] = i;           }           for (int j = 0; j < prime.size() && prime[j] <= spf[i] && prime[j] * i <= N; ++j) {               isp[i*prime[j]] = 0;               spf[i*prime[j]] = prime[j];           }       }   }   map<ll,ll> getFactor(ll x) {        map<ll,ll> ret;       while (x != 1) {            ret[spf[x]]++;           x = x / spf[x];        }        return ret;    }    // SOLVE   void solve() {       // cout << N <<   n ;       // dbg(spf);       ll n, k;       cin >> n >> k;       std::vector<ll> a(n);       for (int i = 0; i < n; ++i) {           cin >> a[i];           // dbg(a[i]);           map<ll,ll> pf = getFactor(a[i]);           // dbg(pf);           ll cur = 1;           for(auto [u, v]: pf) {               if(v & 1) {                  cur = cur * u;                }           }           a[i] = cur;       }       set<ll> st;       ll ans = 0;       for (int i = 0; i < n; ++i) {           if(st.find(a[i]) != st.end()) {               ans++;               st.clear();           }           st.insert(a[i]);           // while(!st.count())       }       if(st.size()) {           ans++;       }       cout << ans <<   n ;   }      //MAIN   int main(){          fast;       #ifndef ONLINE_JUDGE           // for getting input from input.txt           freopen( input.txt ,  r , stdin);           // for writing output to output.txt           freopen( output.txt ,  w , stdout);           // for debug in error.txt           freopen( error.txt ,  w , stderr);       #endif          sieve(N);       test {           solve();       }       return 0;   }


#include <bits/stdc++.h>   using namespace std;   int question, r, speed, st, en, len, did;   double lft, rht, middle, dist, p;   inline double euclid_dist(double a, double b) { return sqrt(a * a + b * b); }   inline bool check(double dis) {     p = 1.0 * dis / r;     return r * euclid_dist(1 - cos(p), sin(p)) >= len - dis;   }   int main() {     scanf( %d%d%d , &question, &r, &speed);     for (register int i = 1; i <= question; i++) {       scanf( %d%d , &st, &en);       len = en - st;       lft = 0;       rht = len;       did = 0;       while (lft < rht && did <= 50) {         middle = (lft + rht) / 2.0;         switch (check(middle)) {           case true:             dist = middle;             rht = middle;             break;           case false:             lft = middle;             break;         }         did++;       }       dist /= speed;       printf( %0.12lf n , dist);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXP = 18;   const int MAXN = 1000001;   int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }   int n, p;   string cad;   int freq[MAXP];   int val[1 << MAXP];   int vis[1 << MAXP];   vector<pair<int, int> > lista[1 << MAXP];   bool mat[MAXP][MAXP];   bool invalid[1 << MAXP];   bool marked[MAXP][MAXP][1 << MAXP];   int mapea(int i) { return cad[i] -  a ; }   int dfs(int u) {     if (vis[u]) return val[u];     vis[u] = 1;     int ans = 0;     for (int j = 0; j < p; j++) {       if (u & 1 << j) continue;       int v = u | 1 << j;       if (!invalid[v]) ans = max(ans, dfs(v) + freq[j]);     }     return val[u] = ans;   }   void compute(int a, int b) {     int id = 0, last = -1, mask;     while (id < n) {       if (mapea(id) == b && last != -1 && mask) {         lista[mask].push_back(pair<int, int>(a, b));         mask = 0;         last = -1;       }       if (mapea(id) == a) {         last = id;         mask = 0;       }       if (mapea(id) != a && mapea(id) != b) mask |= 1 << mapea(id);       id++;     }   }   void bfs(int mask, int a, int b) {     queue<int> q;     q.push(mask);     invalid[mask] = 1;     marked[a][b][mask] = 1;     while (!q.empty()) {       int u = q.front();       q.pop();       for (int i = 0; i < p; i++) {         if (i == a || i == b) continue;         int v = u | 1 << i;         if (!marked[a][b][v]) {           invalid[v] = 1;           marked[a][b][v] = 1;           q.push(v);         }       }     }     invalid[(1 << p) - 1] = 0;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n >> p;     cin >> cad;     for (int i = 0; i < n; i++) freq[mapea(i)]++;     for (int i = 0; i < p; i++)       for (int j = 0; j < p; j++) {         cin >> mat[i][j];         if (!mat[i][j]) compute(i, j);       }     for (int i = 0; i < 1 << p; i++)       for (int j = 0; j < lista[i].size(); j++)         bfs(i, lista[i][j].first, lista[i][j].second);     cout << n - dfs(0) <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int ch[101];   int main() {     int n, pos;     cin >> n;     for (int i = 0; i < n / 2; i++) {       cin >> ch[i];     }     sort(ch, ch + (n / 2));     int black = 0;     pos = 1;     for (int i = 0; i < n / 2; i++) {       black += abs(ch[i] - pos);       pos += 2;     }     int white = 0;     pos = 2;     for (int i = 0; i < n / 2; i++) {       white += abs(ch[i] - pos);       pos += 2;     }     cout << min(white, black) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     char s[200000], c[200000];     cin >> s;     int x = k / 2, r = k / 2;     if (k == n) {       cout << s;       return 0;     }     for (int i = 0, j = 0; i < n; ++i) {       if (s[i] ==  ( ) {         if (x > 0) c[j++] =  ( ;         --x;       } else {         if (r > 0) c[j++] =  ) ;         --r;       }     }     cout << c << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long re() {     long long x;     scanf( %lld , &x);     return x;   }   int main() {     long long y1 = re(), x1 = re(), y2 = re(), x2 = re();     long long h = (x2 - x1) / 2 + 1;     cout << h * (((y2 - y1 + 1) + 1) / 2) + (h - 1) * ((y2 - y1 + 1) / 2) << endl;   }


#include <bits/stdc++.h>   using namespace std;   using li = long long;   int get_num(string s) {     istringstream is(s);     int x;     if ((is >> x) && to_string(x) == s) return x;     return -1;   }   void solve(bool read) {     int n;     cin >> n;     vector<pair<string, int>> s(n);     int n_e = 0;     for (int i = 0; i < n; i++) {       cin >> s[i].first >> s[i].second;       if (s[i].second) n_e++;     }     set<string> non_e, non_t, non_num_e, non_num_t;     set<int> e_slots, t_slots;     for (int i = 1; i <= n_e; i++) e_slots.insert(i);     for (int i = n_e + 1; i <= n; i++) t_slots.insert(i);     set<string> all_s;     for (int i = 0; i < n; i++) {       int num = get_num(s[i].first);       all_s.insert(s[i].first);       if (s[i].second == 1) {         if (num >= 1 && num <= n_e) {           e_slots.erase(num);           continue;         }         if (num > n_e && num <= n) {           non_e.insert(s[i].first);           t_slots.erase(num);         } else           non_num_e.insert(s[i].first);       } else {         if (num > n_e && num <= n) {           t_slots.erase(num);           continue;         }         if (num >= 1 && num <= n_e) {           non_t.insert(s[i].first);           e_slots.erase(num);         } else           non_num_t.insert(s[i].first);       }     }     string rnd =   ;     while (true) {       rnd =   ;       for (int i = 0; i < 6; i++) rnd +=  a  + rand() % 26;       if (!all_s.count(rnd)) break;     }     vector<string> answer;     if (e_slots.empty() && t_slots.empty()) {       assert(non_num_t.empty() && non_num_e.empty());       if (!non_t.empty()) {         assert(!non_e.empty());         string test = *non_t.begin();         non_t.erase(non_t.begin());         e_slots.insert(get_num(test));         answer.push_back( move   + test +     + rnd);         non_num_t.insert(rnd);       }     }     if (!e_slots.empty() || !t_slots.empty()) {       while (!e_slots.empty() || !t_slots.empty()) {         if (!e_slots.empty()) {           if (!non_e.empty()) {             answer.push_back( move   + *non_e.begin() +     +                              to_string(*e_slots.begin()));             t_slots.insert(get_num(*non_e.begin()));             non_e.erase(non_e.begin());             e_slots.erase(e_slots.begin());             continue;           }           if (!non_num_e.empty()) {             answer.push_back( move   + *non_num_e.begin() +     +                              to_string(*e_slots.begin()));             non_num_e.erase(non_num_e.begin());             e_slots.erase(e_slots.begin());             continue;           }         }         if (!t_slots.empty()) {           if (!non_t.empty()) {             answer.push_back( move   + *non_t.begin() +     +                              to_string(*t_slots.begin()));             e_slots.insert(get_num(*non_t.begin()));             non_t.erase(non_t.begin());             t_slots.erase(t_slots.begin());             continue;           }           if (!non_num_t.empty()) {             answer.push_back( move   + *non_num_t.begin() +     +                              to_string(*t_slots.begin()));             non_num_t.erase(non_num_t.begin());             t_slots.erase(t_slots.begin());             continue;           }         }       }       assert(non_num_e.empty() && non_num_t.empty() && non_t.empty() &&              non_e.empty());     }     printf( %d n , (int)answer.size());     for (string s : answer) printf( %s n , s.c_str());   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int nt = 1;     for (int i = 0; i < nt; i++) solve(true);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long tot, n, q, u, v, z, a, b, c, p, k;   long long dep[200005], f[200005][25], fa[200005], va[200005];   struct edge {     long long from, head, nxt, val, go;   } e[200005 * 4];   long long find(long long x) {     long long o = x;     while (x != fa[x]) x = fa[x] = fa[fa[x]];     while (o != x) {       long long j = fa[o];       fa[o] = x;       o = j;     }     return x;   }   void add(long long u, long long v, long long z) {     e[++tot].nxt = e[u].head;     e[u].head = tot;     e[tot].from = u;     e[tot].go = v;     e[tot].val = z;   }   void deal_first(long long u, long long father) {     dep[u] = dep[father] + 1;     for (int i = 0; i <= 19; i++) f[u][i + 1] = f[f[u][i]][i];     for (long long i = e[u].head; i; i = e[i].nxt) {       long long v = e[i].go, w = e[i].val;       if (v == father) continue;       if (w == 1) fa[v] = find(u);       va[v] = w;       f[v][0] = u;       deal_first(v, u);     }   }   long long lca(long long u, long long v) {     if (dep[u] < dep[v]) swap(u, v);     for (long long i = 17; i >= 0; i--) {       if (dep[f[u][i]] >= dep[v]) u = f[u][i];       if (u == v) return u;     }     for (long long i = 17; i >= 0; i--) {       if (f[u][i] != f[v][i]) {         u = f[u][i];         v = f[v][i];       }     }     return f[u][0];   }   int main() {     scanf( %lld%lld , &n, &q);     for (int i = 1; i < n; i++) {       scanf( %lld%lld%lld , &u, &v, &z);       add(u, v, z);       add(v, u, z);     }     for (int i = 1; i <= n; i++) fa[i] = i;     deal_first(1, 0);     while (q--) {       scanf( %lld , &k);       if (k == 1) {         scanf( %lld%lld%lld , &a, &b, &c);         long long finish = lca(a, b);         while (dep[a] > dep[finish] && c) {           c = c / va[a];           a = find(f[a][0]);         }         while (dep[b] > dep[finish] && c) {           c = c / va[b];           b = find(f[b][0]);         }         printf( %lld n , c);       } else {         scanf( %lld%lld , &p, &c);         long long u = e[p << 1].from, v = e[p << 1].go;         if (f[u][0] == v)           z = u;         else           z = v;         va[z] = c;         if (va[z] == 1) fa[z] = find(f[z][0]);       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k, p, c = 0;     cin >> n >> k;     vector<int> v;     map<int, int> m;     for (int i = 1; i <= n; i++) {       cin >> p;       v.push_back(p);       m[p]++;     }     if (m[k] == 0) v.push_back(k), c++, n++;     sort(v.begin(), v.end());     while (1) {       int x = (n + 1) / 2;       if (v[x - 1] == k) {         cout << c;         return 0;       } else if (v[x - 1] < k) {         v.push_back(100000);         n++;         c++;       } else         v.push_back(1), n++, c++;       sort(v.begin(), v.end());     }   }


#include <bits/stdc++.h>   using namespace std;   int grid[500][500];   int srow[500][500];   int scircle[500][500];   int rmaxcircle[500][500 + 1];   int cmaxcircle[500][500 + 1];   int width[((500 - 1) / 2) + 1];   int separation[2 * ((500 - 1) / 2) + 1];   int skip_whitespace() {     int ch;     while (true) {       ch = getchar_unlocked();       if (ch !=     && ch !=   n ) break;     }     return ch;   }   template <typename T>   T read_unsigned_integer() {     T result = (T)0;     int ch = skip_whitespace();     while (ch >=  0  && ch <=  9 ) {       result = 10 * result + (ch -  0 );       ch = getchar_unlocked();     }     return result;   }   template <typename T>   T read_signed_integer() {     T result = (T)0;     bool flip = false;     int ch = skip_whitespace();     if (ch ==  - ) {       flip = true;       ch = skip_whitespace();     }     while (ch >=  0  && ch <=  9 ) {       result = 10 * result + (ch -  0 );       ch = getchar_unlocked();     }     return flip ? -result : result;   }   int partial_row_sum(int row, int left, int right) {     return srow[row][right + 1] - srow[row][left];   }   long long mul_ll(long long x, long long y) { return x * y; }   int solve_problem() {     int n, m, r;     n = read_unsigned_integer<int>();     m = read_unsigned_integer<int>();     r = read_unsigned_integer<int>();     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) grid[i][j] = read_unsigned_integer<int>();     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) srow[i][j + 1] = srow[i][j] + grid[i][j];     width[0] = r;     for (int i = 1; i <= r; i++) {       int w = width[i - 1];       while (i * i + w * w > r * r) --w;       width[i] = w;     }     for (int i = 0; i <= 2 * r; i++) {       int limit = min(i / 2, r);       for (int j = max(0, i - r); j <= limit; j++) {         int cand = width[j] + width[i - j] + 1;         if (cand > separation[i]) separation[i] = cand;       }     }     for (int i = r; i < n - r; i++)       for (int j = r; j < m - r; j++)         for (int k = 0; k <= r; k++) {           scircle[i][j] += partial_row_sum(i + k, j - width[k], j + width[k]);           if (k > 0)             scircle[i][j] += partial_row_sum(i - k, j - width[k], j + width[k]);         }     for (int i = r; i < n - r; i++)       for (int j = m - r - 1; j >= r; j--)         if (scircle[i][j] <= rmaxcircle[i][j + 1]) {           rmaxcircle[i][j] = rmaxcircle[i][j + 1];           cmaxcircle[i][j] = cmaxcircle[i][j + 1];           if (rmaxcircle[i][j] == scircle[i][j]) ++cmaxcircle[i][j];         } else {           rmaxcircle[i][j] = scircle[i][j];           cmaxcircle[i][j] = 1;         }     int result = 0;     long long mult = 0;     for (int i = r; i < n - r; i++)       for (int j = i + 2 * r + 1; j < n - r; j++) {         int cand = rmaxcircle[i][r] + rmaxcircle[j][r];         if (cand > result) {           result = cand;           mult = mul_ll(cmaxcircle[i][r], cmaxcircle[j][r]);         } else if (cand == result) {           mult += mul_ll(cmaxcircle[i][r], cmaxcircle[j][r]);         }       }     for (int i = r; i < n - r; i++)       for (int j = r; j < m - r; j++) {         int limit = min(i + 2 * r + 1, n - r);         for (int k = max(i - 2 * r, r); k < limit; k++) {           int delta = k - i;           if (delta < 0) delta = -delta;           int l = j + separation[delta];           if (l < m - r) {             int cand = scircle[i][j] + rmaxcircle[k][l];             if (cand > result) {               result = cand;               mult = cmaxcircle[k][l];             } else if (cand == result) {               mult += cmaxcircle[k][l];             }           }         }       }     cout << result <<     << mult << endl;     return 0;   }   int main() {     solve_problem();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 300010;   int n, l[N], t[N];   long long r, dv, res, tcur;   vector<long long> ans;   void solve(int l, int t) {     if (2 * l <= t) {       tcur += 2 * l;       return;     }     long long x = t - l;     long long tmp = (1ll * l - x + r - 1) / r;     res += tmp;     dv = x + tmp * r - l;     tcur += 2 * x;     long long t1 = tcur;     while (ans.size() < 1e5 + 10 && tmp) {       ans.push_back(t1);       tmp--;       t1 += r;     }     tcur += l - x;   }   int main() {     cin >> n >> r;     for (int i = 1; i <= n; i++) cin >> l[i];     for (int i = 1; i <= n; i++) cin >> t[i];     res = 0;     dv = 0;     tcur = 0;     for (int i = 1; i <= n; i++) {       if (l[i] > t[i]) {         res = -1;         break;       }       if (l[i] <= dv) {         dv -= l[i];         tcur += l[i];         continue;       }       l[i] -= dv;       t[i] -= dv;       tcur += dv;       dv = 0;       solve(l[i], t[i]);     }     cout << res << endl;     if (res != -1 && ans.size() <= 1e5) {       assert(res == ans.size());       for (int i = 0; i < ans.size(); i++) cout << ans[i] <<    ;       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 228;   const int big = 2e9;   const int md = 1e9 + 7;   struct node {     int l, r, s;   };   int n, m, a[N], pr[N], root[N], k, tex, jj;   node t[N * 40];   bool ok;   void build(int v, int l, int r) {     if (l == r) return;     t[v].l = ++k;     t[v].r = ++k;     int d = (l + r) >> 1;     build(t[v].l, l, d);     build(t[v].r, d + 1, r);   }   void update(int v, int l, int r, int ps, int vl) {     if (l == r) {       t[++k].s = vl;       return;     }     int d = (l + r) >> 1;     if (ps <= d) {       update(t[v].l, l, d, ps, vl);       t[++k].l = k - 1;       t[k].r = t[v].r;     } else {       update(t[v].r, d + 1, r, ps, vl);       t[++k].r = k - 1;       t[k].l = t[v].l;     }     t[k].s = t[t[k].l].s + t[t[k].r].s;   }   void mod(int v, int l, int r, int ps, int vl) {     if (l == r) {       t[v].s = vl;       return;     }     int d = (l + r) >> 1;     if (ps <= d)       mod(t[v].l, l, d, ps, vl);     else       mod(t[v].r, d + 1, r, ps, vl);     t[v].s = t[t[v].l].s + t[t[v].r].s;   }   int go(int v, int l, int r) {     if (l == r) return l;     int d = (l + r) >> 1;     if (t[t[v].l].s >= tex)       return go(t[v].l, l, d);     else {       tex -= t[t[v].l].s;       return go(t[v].r, d + 1, r);     }   }   void nx(int v, int tl, int tr, int l, int r) {     if (l > r || ok) return;     if (tl == l && tr == r) {       if (tex <= t[v].s) {         ok = 1;         jj = go(v, l, r);       } else         tex -= t[v].s;       return;     }     int d = (tl + tr) >> 1;     nx(t[v].l, tl, d, l, min(r, d));     nx(t[v].r, d + 1, tr, max(l, d + 1), r);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i];     k = 1;     root[n + 1] = 1;     build(1, 1, n);     for (int i = n; i >= 1; i--) {       update(root[i + 1], 1, n, i, 1);       if (pr[a[i]] != 0) update(k, 1, n, pr[a[i]], 0);       root[i] = k;       pr[a[i]] = i;     }     for (int i = 1; i <= n; i++) {       int j = 1, ans = 0;       ok = 1;       while (j <= n && ok) {         ans++;         tex = i + 1;         ok = 0;         nx(root[j], 1, n, j, n);         j = jj;       }       cout << ans <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int test;     cin >> test;     while (test--) {       int n;       cin >> n;       for (int i = 2 * n, j = 0; j < n; i += 2, ++j) {         cout << i <<    ;       }       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 5e5 + 10;   int le[MAXN], ri[MAXN];   int a[MAXN];   struct num {     int val, pos;   };   num data[MAXN];   bool cmp(num a, num b) { return a.val < b.val; }   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];       data[i].val = a[i];       data[i].pos = i;       le[i] = i - 1;       ri[i] = i + 1;     }     sort(data, data + n, cmp);     long long ans = 0;     int low = 0;     int hi = n - 1;     for (int i = 0; i < n - 2; i++) {       int pos = data[i].pos;       if (low == pos) {         ans += a[pos];         low = ri[pos];       } else if (hi == pos) {         ans += a[pos];         hi = le[pos];       } else {         ans += min(a[le[pos]], a[ri[pos]]);         ri[le[pos]] = ri[pos];         le[ri[pos]] = le[pos];       }     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int SZ = 1000010;   const long long INF = 1e18 + 10;   const int mod = 1e9 + 7;   const long double eps = 1e-12;   long long read() {     long long n = 0;     char a = getchar();     bool flag = 0;     while (a >  9  || a <  0 ) {       if (a ==  - ) flag = 1;       a = getchar();     }     while (a <=  9  && a >=  0 ) {       n = n * 10 + a -  0 , a = getchar();     }     if (flag) n = -n;     return n;   }   int a[SZ], s[SZ], b[SZ];   int main() {     int n = read(), m = read(), sum = 0;     for (int i = 1; i <= m; i++) a[i] = read(), b[i] = (sum += a[i]) % n;     printf( %d n , (sum + n - 1) / n);     b[m] = n;     sort(b + 1, b + 1 + m);     for (int i = 1; i <= m; i++) s[i] = b[i] - b[i - 1];     for (int i = 1; i <= m; i++) printf( %d  , s[i]);     puts(  );     int k = 1;     for (int i = 1, j = 1; i <= m; i++)       while (a[i] > 0) {         a[i] -= s[j];         printf( %d  , i);         if (k % m == 0) puts(  );         k++;         j++, j = (j - 1) % m + 1;       }     while ((k - 1) % m) k++, printf( 1  );   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = (int)1e9 + 7;   const int INF = (int)1e9;   const long long LINF = (long long)1e18;   const long double PI = acos((long double)-1);   const long double EPS = 1e-9;   inline long long gcd(long long a, long long b) {     long long r;     while (b) {       r = a % b;       a = b;       b = r;     }     return a;   }   inline long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }   inline long long fpow(long long n, long long k, int p = MOD) {     long long r = 1;     for (; k; k >>= 1) {       if (k & 1) r = r * n % p;       n = n * n % p;     }     return r;   }   template <class T>   inline int chkmin(T& a, const T& val) {     return a > val ? a = val, 1 : 0;   }   template <class T>   inline int chkmax(T& a, const T& val) {     return a < val ? a = val, 1 : 0;   }   inline long long isqrt(long long k) {     long long r = sqrt(k) + 1;     while (r * r > k) r--;     return r;   }   inline long long icbrt(long long k) {     long long r = cbrt(k) + 1;     while (r * r * r > k) r--;     return r;   }   inline void addmod(int& a, int val, int p = MOD) {     if ((a = (a + val)) >= p) a -= p;   }   inline void submod(int& a, int val, int p = MOD) {     if ((a = (a - val)) < 0) a += p;   }   inline int mult(int a, int b, int p = MOD) { return (long long)a * b % p; }   inline int inv(int a, int p = MOD) { return fpow(a, p - 2, p); }   const int maxn = 100010;   const int magic = 320;   int fac[maxn];   int rfac[maxn];   int f[maxn];   int p25[maxn];   int binomial(int a, int b) {     if (!a || a == b) {       return 1;     }     return mult(fac[b], mult(rfac[a], rfac[b - a]));   }   void solve() {     fac[0] = 1;     for (int i = (1); i < (maxn); i++) fac[i] = mult(fac[i - 1], i);     for (int i = (0); i < (maxn); i++) rfac[i] = inv(fac[i]);     p25[0] = 1;     for (int i = (1); i < (maxn); i++) p25[i] = mult(p25[i - 1], 25);     int m, k;     cin >> m;     string s;     cin >> s;     if ((k = int((s).size())) > magic) memset(f, -1, sizeof(f));     while (m--) {       int op;       cin >> op;       if (op == 1) {         string s;         cin >> s;         if ((k = int((s).size())) > magic) memset(f, -1, sizeof(f));       } else {         int n;         cin >> n;         if (n < k) {           cout << 0 <<   n ;           continue;         }         if (k > magic && ~f[n]) {           cout << f[n] <<   n ;           continue;         }         int res = fpow(26, n);         for (int i = (0); i < (k); i++) {           submod(res, mult(binomial(i, n), p25[n - i]));         }         if (k > magic) f[n] = res;         cout << res <<   n ;       }     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     solve();     return 0;   }


#include <bits/stdc++.h>   const int MXN = 100010;   bool alive[MXN * 5];   int L[MXN], R[MXN], T[MXN];   struct heap_t {     int idx;     heap_t(int nidx) : idx(nidx) {}     bool operator<(const heap_t& cmp) const { return T[idx] > T[cmp.idx]; }   };   struct ele_t {     int idx, val;     bool operator<(const ele_t& cmp) const { return val < cmp.val; }   } ele[MXN * 2], ele2[MXN * 5];   int ans[MXN];   int main() {     int n, m;     scanf( %d %d , &m, &n);     for (int i = 1; i <= n; i++) {       scanf( %d %d %d , &L[i], &R[i], &T[i]);       ele[i].idx = i, ele[i].val = L[i];       ele[i + n].idx = i, ele[i + n].val = R[i];     }     int cele2 = m;     for (int i = 1; i <= m; i++) {       ele2[i].idx = i;       scanf( %d , &ele2[i].val);     }     int lstPos = -1;     std::priority_queue<heap_t> heap;     std::sort(ele + 1, ele + n * 2 + 1);     for (int i = 1; i <= n * 2; i++) {       while (!heap.empty() && !alive[heap.top().idx]) heap.pop();       if (!heap.empty()) {         ++cele2;         ele2[cele2].idx = cele2;         ele2[cele2 + 1].idx = cele2;         ele2[cele2].val = T[heap.top().idx] - lstPos;         ele2[cele2 + 1].val = T[heap.top().idx] - ele[i].val;         ++cele2;       }       lstPos = ele[i].val;       alive[ele[i].idx] = !alive[ele[i].idx];       if (alive[ele[i].idx]) heap.push(ele[i].idx);     }     int sum = 0, cnt = 0;     std::sort(ele2 + 1, ele2 + cele2 + 1);     for (int i = 1; i <= cele2; i++) {       sum += cnt * (ele2[i].val - lstPos);       lstPos = ele2[i].val;       if (ele2[i].idx <= m)         ans[ele2[i].idx] = sum;       else {         alive[ele2[i].idx] = !alive[ele2[i].idx];         cnt += (alive[ele2[i].idx]) ? 1 : -1;       }     }     for (int i = 1; i <= m; i++) printf( %d%c , ans[i], i == m ?   n  :    );   }


#include <bits/stdc++.h>   const long long INF = (long long)1e18 + 18;   const long long maxn = (long long)1e6 + 6;   using namespace std;   long long n;   signed main() {     cin >> n;     long long a[n], c[n], b[maxn];     for (long long i = 0; i < n; i++) {       cin >> a[i];     }     for (long long i = 0; i < n; i++) {       long long inp;       cin >> inp;       b[inp] = i + 1;     }     for (long long i = 0; i < n; i++) {       c[i] = b[a[i]];     }     long long fine = 0, maxx = c[0];     for (long long i = 0; i < n; i++) {       if (c[i] < maxx) {         fine++;       }       maxx = max(maxx, c[i]);     }     cout << fine;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   using minheap = priority_queue<T, vector<T>, greater<T>>;   template <typename T>   using maxheap = priority_queue<T>;   template <typename T>   using dpair = pair<T, T>;   template <class T1, class T2>   istream &operator>>(istream &is, pair<T1, T2> &p) {     return is >> p.first >> p.second;   }   template <class T1, class T2>   void operator+=(vector<T1> &v, const T2 &obj) {     v.push_back(obj);   }   template <class T1>   void operator+=(vector<T1> &v, const T1 &obj) {     v.push_back(obj);   }   long long get_millis() {     using namespace std::chrono;     return duration_cast<milliseconds>(system_clock::now().time_since_epoch())         .count();   }   const int INF = 0x3f3f3f3f;   const long long mod = 1e9 + 7;   class xrange {    public:     xrange(int end) : _start(0), _end(end), _step(1) {}     xrange(int start, int end) : _start(start), _end(end), _step(1) {}     xrange(int start, int end, int step)         : _start(start), _end(end), _step(step) {}     class iterator {      public:       iterator(int v, xrange &par) : val(v), parent(par){};       int operator*() const { return val; }       int operator++() { return (val += parent._step); }       bool operator==(const xrange::iterator &iter) const {         if (&parent != &iter.parent) return false;         if (val == iter.val) return true;         if (parent._step > 0)           return val >= parent._end && iter.val >= parent._end;         else           return val <= parent._end && iter.val <= parent._end;       }       bool operator!=(const xrange::iterator &iter) const {         return !(this->operator==(iter));       }         private:       int val;       xrange &parent;     };     xrange::iterator begin() { return {_start, *this}; }     xrange::iterator end() { return {_end, *this}; }       protected:     int _start, _end, _step;       private:   };   struct irange : public xrange {     irange(int i) : xrange(1, i + 1) {}     irange(int i, int j) : xrange(i, j + 1) {}   };   const int MAXN = 1e4 + 5;   namespace std {   template <>   struct hash<dpair<int>> {     size_t operator()(dpair<int> p) const {       return p.first * 123456789 + p.second;     }   };   }  // namespace std   unordered_map<dpair<int>, int> ump;   int N, M, K;   struct dir {     bool lit;     int r, c;     int dist;     dir(int _l, int _r, int _c, int _d) {       lit = _l;       r = _r;       c = _c;       dist = _d;     }     bool operator>(const dir &d) const { return dist > d.dist; }   };   minheap<dir> pq;   set<int> availR[MAXN], availC[MAXN];   int best[MAXN];   int main() {     cin.tie(0);     cin.sync_with_stdio(0);     cin >> N >> M >> K;     for (int a = 0; a < K; a++) {       int r, c;       cin >> r >> c;       availR[r].insert(c);       availC[c].insert(r);       ump[{r, c}] = a;     }     pq.push({false, 1, 1, 0});     pq.push({true, 1, 1, 1});     availR[1].erase(1);     availC[1].erase(1);     memset(best, 0x3f, sizeof(best));     best[ump[{1, 1}]] = 0;     while (!pq.empty()) {       dir top = pq.top();       pq.pop();       if (top.lit) {         for (int r = max(1, top.r - 2); r <= top.r + 2; r++) {           for (int i : availR[r]) {             int id = ump[{r, i}];             best[id] = min(best[id], top.dist);             pq.push(dir{false, r, i, top.dist});             pq.push(dir{true, r, i, top.dist + 1});           }           availR[r].clear();         }         for (int c = max(1, top.c - 2); c <= top.c + 2; c++) {           for (int i : availC[c]) {             int id = ump[{i, c}];             best[id] = min(best[id], top.dist);             pq.push(dir{false, i, c, top.dist});             pq.push(dir{true, i, c, top.dist + 1});           }           availC[c].clear();         }       } else {         int dr = 1, dc = 0;         if (ump.count({top.r + dr, top.c + dc}) &&             best[ump[{top.r + dr, top.c + dc}]] > top.dist) {           best[ump[{top.r + dr, top.c + dc}]] = top.dist;           pq.push(dir{false, top.r + dr, top.c + dc, top.dist});           pq.push(dir{true, top.r + dr, top.c + dc, top.dist + 1});           availR[top.r + dr].erase(top.c + dc);           availC[top.c + dc].erase(top.r + dr);         }         dr = -1;         dc = 0;         if (ump.count({top.r + dr, top.c + dc}) &&             best[ump[{top.r + dr, top.c + dc}]] > top.dist) {           best[ump[{top.r + dr, top.c + dc}]] = top.dist;           pq.push(dir{false, top.r + dr, top.c + dc, top.dist});           pq.push(dir{true, top.r + dr, top.c + dc, top.dist + 1});           availR[top.r + dr].erase(top.c + dc);           availC[top.c + dc].erase(top.r + dr);         }         dr = 0;         dc = 1;         if (ump.count({top.r + dr, top.c + dc}) &&             best[ump[{top.r + dr, top.c + dc}]] > top.dist) {           best[ump[{top.r + dr, top.c + dc}]] = top.dist;           pq.push(dir{false, top.r + dr, top.c + dc, top.dist});           pq.push(dir{true, top.r + dr, top.c + dc, top.dist + 1});           availR[top.r + dr].erase(top.c + dc);           availC[top.c + dc].erase(top.r + dr);         }         dr = 0;         dc = -1;         if (ump.count({top.r + dr, top.c + dc}) &&             best[ump[{top.r + dr, top.c + dc}]] > top.dist) {           best[ump[{top.r + dr, top.c + dc}]] = top.dist;           pq.push(dir{false, top.r + dr, top.c + dc, top.dist});           pq.push(dir{true, top.r + dr, top.c + dc, top.dist + 1});           availR[top.r + dr].erase(top.c + dc);           availC[top.c + dc].erase(top.r + dr);         }       }     }     int ans = INF;     for (auto au : ump) {       if (au.first == dpair<int>{N, M}) {         ans = min(ans, best[au.second]);       }       if (abs(au.first.first - N) <= 1 || abs(au.first.second - M) <= 1) {         ans = min(ans, best[au.second] + 1);       }     }     if (ans > 10000000) {       cout << -1;     } else {       cout << ans;     }   }


#include <bits/stdc++.h>   const int INF = 1e9 + 1;   const int MOD = 1e9 + 7;   const int N = 1e6 + 1;   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     int n, m;     cin >> n >> m;     if (m == 1) {       cout <<  100003 100003  << endl;       cout <<  1 2 100003  << endl;       return 0;     }     cout <<  100003 100003  << endl;     for (int i = 1; i < n - 1; i++) {       cout << i <<     << i + 1 <<   1  << endl;       m--;     }     cout << n - 1 <<     << n <<     << 100003 - n + 2 << endl;     m--;     long long int z = 1000000000;     for (int i = 1; i < n && m > 0; i++) {       for (int j = i + 2; j <= n && m > 0; j++) {         cout << i <<     << j <<     << z << endl;         m--;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   double memo[2002][2002];   double p;   int main() {     int n, t;     cin >> n >> p >> t;     double ans = 0;     memo[0][0] = 1.0;     for (int per = 1; per <= n; per++)       for (int s = 1; s <= t; s++)         memo[per][s] = memo[per - 1][s - 1] * p + memo[per][s - 1] * (1.0 - p);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= t; j++) ans += memo[i][j];     printf( %lf , ans);     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   using namespace std;   void *wmem;   char memarr[10485760];   template <class T>   inline void walloc1d(T **arr, int x, void **mem = &wmem) {     static int skip[16] = {0, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1};     (*mem) = (void *)(((char *)(*mem)) + skip[((unsigned long long)(*mem)) & 15]);     (*arr) = (T *)(*mem);     (*mem) = ((*arr) + x);   }   inline void rd(int &x) {     int k;     int m = 0;     x = 0;     for (;;) {       k = getchar();       if (k ==  - ) {         m = 1;         break;       }       if ( 0  <= k && k <=  9 ) {         x = k -  0 ;         break;       }     }     for (;;) {       k = getchar();       if (k <  0  || k >  9 ) {         break;       }       x = x * 10 + k -  0 ;     }     if (m) {       x = -x;     }   }   inline void wt_L(char a) { putchar(a); }   inline void wt_L(int x) {     int s = 0;     int m = 0;     char f[10];     if (x < 0) {       m = 1;       x = -x;     }     while (x) {       f[s++] = x % 10;       x /= 10;     }     if (!s) {       f[s++] = 0;     }     if (m) {       putchar( - );     }     while (s--) {       putchar(f[s] +  0 );     }   }   struct unionFind {     int *d;     int N;     int M;     inline void malloc(const int n) {       d = (int *)std::malloc(n * sizeof(int));       M = n;     }     inline void free(void) { std::free(d); }     inline void walloc(const int n, void **mem = &wmem) {       walloc1d(&d, n, mem);       M = n;     }     inline void init(const int n) {       int i;       N = n;       for (i = (0); i < (n); i++) {         d[i] = -1;       }     }     inline void init(void) { init(M); }     inline int get(int a) {       int t = a;       int k;       while (d[t] >= 0) {         t = d[t];       }       while (d[a] >= 0) {         k = d[a];         d[a] = t;         a = k;       }       return a;     }     inline int connect(int a, int b) {       if (d[a] >= 0) {         a = get(a);       }       if (d[b] >= 0) {         b = get(b);       }       if (a == b) {         return 0;       }       if (d[a] < d[b]) {         d[a] += d[b];         d[b] = a;       } else {         d[b] += d[a];         d[a] = b;       }       return 1;     }     inline int operator()(int a) { return get(a); }     inline int operator()(int a, int b) { return connect(a, b); }     inline int &operator[](const int a) { return d[a]; }     inline int size(int a) {       a = get(a);       return -d[a];     }     inline int sizeList(int res[]) {       int i;       int sz = 0;       for (i = (0); i < (N); i++) {         if (d[i] < 0) {           res[sz++] = -d[i];         }       }       return sz;     }   };   int N;   int M;   int Q;   int X;   int Y;   int C;   int res[2000000 + 2];   int mp[300][300];   vector<int> tmm[2000000 + 1];   vector<int> type[2000000 + 1];   vector<int> place[2000000 + 1];   int main() {     wmem = memarr;     int i;     int j;     int k;     int c;     int t;     int x;     int y;     int nx;     int ny;     int d;     int dx[4] = {-1, 1, 0, 0};     int dy[4] = {0, 0, -1, 1};     unionFind uf;     rd(N);     rd(M);     rd(Q);     for (i = (0); i < (N * M); i++) {       tmm[0].push_back(0);       type[0].push_back(1);       place[0].push_back(i);     }     for (i = (0); i < (Q); i++) {       rd(X);       X += (-1);       rd(Y);       Y += (-1);       rd(C);       if (mp[X][Y] == C) {         continue;       }       k = mp[X][Y];       tmm[k].push_back(i + 1);       type[k].push_back(-1);       place[k].push_back(X * M + Y);       k = mp[X][Y] = C;       tmm[k].push_back(i + 1);       type[k].push_back(1);       place[k].push_back(X * M + Y);     }     for (i = (0); i < (N * M); i++) {       k = mp[i / M][i % M];       tmm[k].push_back(Q + 1);       type[k].push_back(-1);       place[k].push_back(i);     }     uf.walloc(N * M);     for (k = (0); k < (2000000 + 1); k++) {       if (tmm[k].size()) {         for (i = (0); i < (N); i++) {           for (j = (0); j < (M); j++) {             mp[i][j] = 0;           }         }         uf.init(N * M);         t = c = 0;         for (i = (0); i < (tmm[k].size()); i++) {           if (tmm[k][i] != t) {             res[t] += c;             t = tmm[k][i];             res[t] -= c;           }           if (type[k][i] == -1) {             break;           }           x = place[k][i] / M;           y = place[k][i] % M;           mp[x][y] = 1;           c++;           for (d = (0); d < (4); d++) {             nx = x + dx[d];             ny = y + dy[d];             if (nx < 0 || ny < 0 || nx >= N || ny >= M) {               continue;             }             if (mp[nx][ny] == 1) {               c -= uf(x * M + y, nx * M + ny);             }           }         }         for (i = (0); i < (N); i++) {           for (j = (0); j < (M); j++) {             mp[i][j] = 0;           }         }         uf.init(N * M);         t = Q + 1;         c = 0;         for (i = (tmm[k].size()) - 1; i >= (0); i--) {           if (type[k][i] == 1) {             break;           }           if (tmm[k][i] != t) {             res[t] -= c;             t = tmm[k][i];             res[t] += c;           }           x = place[k][i] / M;           y = place[k][i] % M;           mp[x][y] = 1;           c++;           for (d = (0); d < (4); d++) {             nx = x + dx[d];             ny = y + dy[d];             if (nx < 0 || ny < 0 || nx >= N || ny >= M) {               continue;             }             if (mp[nx][ny] == 1) {               c -= uf(x * M + y, nx * M + ny);             }           }         }       }     }     for (i = (1); i < (Q + 1); i++) {       res[i] += res[i - 1];       wt_L(res[i]);       wt_L(  n );     }     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       set<int> se;       for (int i = 0; i < n; i++) {         int va;         cin >> va;         se.insert(va & 1);       }       if (se.size() == 1) {         cout <<  YES n ;       } else {         cout <<  NO n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 100010, mod = 998244353;   inline long long read() {     char ch = getchar();     long long x = 0, f = 0;     while (ch <  0  || ch >  9 ) f |= ch ==  - , ch = getchar();     while (ch >=  0  && ch <=  9 ) x = x * 10 + ch -  0 , ch = getchar();     return f ? -x : x;   }   int n, m, dfn[maxn], low[maxn], stk[maxn], tp, cnt, id[maxn], deg[maxn], scnt,       el, head[maxn], to[maxn], nxt[maxn], ans, q[maxn], h = 1, r;   bool ins[maxn];   vector<int> vec[maxn];   inline int ask(int u, int v) {     printf( ? %d %d n , u, v);     fflush(stdout);     return read();   }   inline void add(int u, int v) {     to[++el] = v;     nxt[el] = head[u];     head[u] = el;   }   void dfs(int u) {     dfn[u] = low[u] = ++cnt;     stk[++tp] = u;     ins[u] = true;     for (int i = head[u]; i; i = nxt[i]) {       int v = to[i];       if (!dfn[v])         dfs(v), low[u] = min(low[u], low[v]);       else if (ins[v])         low[u] = min(low[u], dfn[v]);     }     if (low[u] == dfn[u]) {       scnt++;       do {         int v = stk[tp];         ins[v] = false;         id[v] = scnt;         vec[scnt].push_back(v);       } while (stk[tp--] != u);     }   }   int main() {     n = read();     m = read();     for (int i = (1); i <= (m); i++) {       int u = read(), v = read();       add(u, v);     }     for (int i = (1); i <= (n); i++)       if (!dfn[i]) dfs(i);     for (int u = (1); u <= (n); u++)       for (int i = head[u]; i; i = nxt[i])         if (id[u] != id[to[i]]) deg[id[to[i]]]++;     for (int i = (1); i <= (scnt); i++)       if (!deg[i]) q[++r] = i;     ans = vec[q[h]].back();     while (h != r) {       int &at = q[h + 1];       int u = vec[at].back();       if (!ask(ans, u)) swap(u, ans), swap(q[h], q[h + 1]);       for (int i = head[u]; i; i = nxt[i])         if (id[u] != id[to[i]] && !--deg[id[to[i]]]) q[++r] = id[to[i]];       vec[at].pop_back();       if (vec[at].empty()) swap(q[h], q[h + 1]), h++;     }     printf( ! %d n , ans);     fflush(stdout);   }


#include<bits/stdc++.h>   using namespace std;   const int N=1e5+5;   int tot;   int head[N],to[N*2],next1[N*2];   void lian(int x,int y)   {       to[++tot]=y;       next1[tot]=head[x];       head[x]=tot;   }   int d[N],k;   struct qw{       int a,b,c,d;   }e[N];   struct er{       int a,b;   }jie[N];   void dfs(int x,int fa)   {       jie[x].a=x,jie[x].b=0;       for(int i=head[x];i;i=next1[i])       {           int v=to[i];           if(v==fa) continue;           d[x]++;           dfs(v,x);       }       if(d[x]==0) return;       int v1=-1;       for(int i=head[x];i;i=next1[i])       {           int v=to[i];           if(v==fa) continue;           if(jie[v].b==0)           {               if(v1==-1) jie[x].a=jie[v].a;               else if(jie[x].b==0) jie[x].b=jie[v].a;               else e[++k]=(qw){v,x,v,jie[x].a},jie[x].a=jie[v].a;               v1=0;                          }       }       if(v1==-1)       {           for(int i=head[x];i;i=next1[i])           {               int v=to[i];               if(v==fa) continue;               v1=v;               e[++k]=(qw){v,x,x,jie[v].a};               jie[x].a=jie[v].b;               break;           }       }       for(int i=head[x];i;i=next1[i])       {           int v=to[i];           if(v==fa||jie[v].b==0||v==v1) continue;           if(jie[v].a&&jie[v].b) e[++k]=(qw){v,x,jie[v].a,jie[x].a},jie[x].a=jie[v].b;           else e[++k]=(qw){v,x,jie[x].a,v},jie[x].a=jie[v].a;       }   }   int main()   {       int T;       cin>>T;       while(T--)       {           int n;           cin>>n;           int x,y;           for(int i=1;i<=n-1;i++)           {               scanf( %d %d ,&x,&y);               lian(x,y),lian(y,x);           }           k=0;           dfs(1,0);           printf( %d n ,k);           for(int i=1;i<=k;i++)           printf( %d %d %d %d n ,e[i].a,e[i].b,e[i].c,e[i].d);           tot=0;           for(int i=1;i<=n;i++) head[i]=d[i]=0;       }       return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, k, a[100100];   int main() {     scanf( %lld %lld , &n, &k);     int temp = 0, t = 0;     vector<int> v;     for (int i = 1; i <= n; i++) {       long long x;       scanf( %lld , &x);       if (temp + (i - n) * x * 1ll * (i - t - 1) < k) {         v.push_back(i);         t++;       } else         temp = temp + x * 1ll * (i - t - 1);     }     for (int i = 0; i < v.size(); i++) printf( %d n , v[i]);     return 0;   }


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


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   using namespace std;   const long double eps = 1e-7;   const int inf = 1000000010;   const long long INF = 10000000000000010LL;   const int mod = 1000000007;   const int MAXN = 100010;   int n, m, k, u, v, x, y, t, a, b, ans;   string A[5];   string s;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> s;     for (int i = 0; i < 5; i++) {       cin >> A[i];       if (A[i][0] == s[0] || A[i][1] == s[1]) return cout <<  YES  <<   n , 0;     }     return cout <<  NO  <<   n , 0;     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:16777216 )   using namespace std;   int n, a, b, c, ans = 0;   int main() {     cin >> n >> a >> b >> c;     for (int i = 0; i <= a; i += 2)       for (int j = 0; j < (int)(b + 1); j++) {         int k = n - (i * 0.5 + j);         if (k < 0) break;         if (!k) {           ans++;           continue;         }         if (k % 2 == 0) {           int l = k / 2;           if (l <= c) ans++;         }       }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 10;   const int M = 1e6 + 10;   const long long INF = 0x3f3f3f3f3f3f3f;   const int inf = 0x3f3f3f;   const double esp = 1e-6;   long long read() {     long long x = 0;     long long k = 1;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) k = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       x = x * 10 + (c -  0 );       c = getchar();     }     return x * k;   }   int n;   int a[N];   int main() {     int t;     cin >> t;     while (t--) {       int a, b;       cin >> a >> b;       if (a == 1) {         if (b <= 1) {           cout <<  YES  << endl;         } else           cout <<  NO  << endl;       } else if (a == 2) {         if (b <= 3) {           cout <<  YES  << endl;         } else           cout <<  NO  << endl;       } else if (a == 3) {         if (b <= 3) {           cout <<  YES  << endl;         } else           cout <<  NO  << endl;       } else         cout <<  YES  << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int Ask(int x, int y) {     printf( ? %d %d n , x, y);     fflush(stdout);     int t;     scanf( %d , &t);     return t;   }   int vis[105], t[105], n;   struct bt {     bitset<105> A;     int id;     int operator[](int x) { return A[x]; }     friend bool operator<(bt x, bt y) {       for (int i = n; ~i; i--)         if (x[i] ^ y[i]) return x[i] < y[i];       return 0;     }     int mx() {       for (int i = n; ~i; i--)         if (A[i]) return i;       return -1;     }   } dp[105];   map<pair<int, int>, int> val;   priority_queue<bt> q;   vector<int> e[105];   bool chk(vector<bt> f) {     for (auto x : f) q.push(x);     if (q.empty()) return 1;     for (int i = n; ~i; i--)       if (t[i]) {         bt x = q.top();         q.pop();         int v = x.mx();         if (v > i)           break;         else if (v == i)           x.A[v] = 0, q.emplace(x);         if (!q.size()) return 1;       }     while (q.size()) q.pop();     return 0;   }   void produce(int u, vector<bt> f) {     for (auto x : f) q.push(x);     if (q.empty()) return;     for (int i = n; ~i; i--)       if (t[i]) {         bt x = q.top();         q.pop();         int v = x.mx();         if (v == i)           x.A[v] = 0, q.emplace(x);         else           val[pair<int, int>(x.id, u)] = val[pair<int, int>(u, x.id)] = i;         if (!q.size()) break;       }     while (q.size()) q.pop();   }   void dfs1(int u, int fa) {     vector<bt> g;     dp[u].id = u;     for (int v : e[u])       if (v != fa) dfs1(v, u), g.push_back(dp[v]);     fill(t, t + n, 1);     t[n] = 0;     for (int i = n; ~i; i--, t[i] = 0)       if (!chk(g)) t[i] = 1;     for (int i = 0; i <= n; i++) dp[u].A[i] = t[i];     produce(u, g);   }   pair<int, int> id;   void dfs2(int u, int fa, int &mx) {     for (int v : e[u])       if (!vis[v] && v != fa) {         int k = val[pair<int, int>(u, v)];         if (k > mx) mx = k, id = pair<int, int>(u, v);         dfs2(v, u, mx);       }   }   void solve(int u, int fa) {     int mx = -1;     dfs2(u, fa, mx);     if (mx == -1) printf( ! %d n , u), fflush(stdout), exit(0);     int res = Ask(id.first, id.second);     if (res == id.first)       vis[id.second] = 1, solve(id.first, id.second);     else       vis[id.first] = 1, solve(id.second, id.first);   }   int main() {     scanf( %d , &n);     for (int i = 1, u, v; i < n; i++)       scanf( %d%d , &u, &v), e[u].emplace_back(v), e[v].emplace_back(u);     dfs1(1, 0);     solve(1, 0);   }


#include <bits/stdc++.h>   using namespace std;   template <typename... T>   inline void inp(T &...args) {     ((cin >> args), ...);   }   template <typename T>   inline istream &operator>>(istream &in, vector<T> &a) {     for (auto &x : a) in >> x;     return in;   }   template <typename T, typename U>   inline istream &operator>>(istream &in, pair<T, U> &a) {     in >> a.first >> a.second;     return in;   }   const long long int MX = 1e6 + 10;   const long long int Mod = 998244353;   inline long long int md(long long int x, long long int M = Mod) {     x %= M;     return ((x < 0) ? (x + M) : x);   }   vector<long long int> fact(MX), invfact(MX), inv(MX);   void init_fact(long long int m = Mod) {     inv[0] = 0;     inv[1] = fact[0] = fact[1] = invfact[0] = invfact[1] = 1;     for (long long int i = 2; i < MX; i++) {       fact[i] = md(fact[i - 1] * i, m);       inv[i] = m - (m / i) * inv[m % i] % m;       invfact[i] = md(inv[i] * invfact[i - 1], m);     }   }   long long int NPR(long long int n, long long int r) {     if (0 <= r and r <= n) {       return md(fact[n] * invfact[n - r]);     }     return 0;   }   long long int NCR(long long int n, long long int r) {     if (0 <= r and r <= n) {       return md(fact[n] * md(invfact[r] * invfact[n - r]));     }     return 0;   }   void solve(int &T) {     long long int n, k;     cin >> n >> k;     vector<pair<long long int, long long int>> a;     for (long long int i = (0); ((1) > 0 ? i < (n) : i > (n)); i += (1)) {       long long int x, y;       cin >> x >> y;       a.push_back({x, 1});       a.push_back({y + 1, -1});     }     sort((a).begin(), (a).end());     long long int cnt = 0, ans = 0;     for (long long int i = (0); ((1) > 0 ? i < (2 * n) : i > (2 * n)); i += (1)) {       if (a[i].second == 1) {         if (cnt >= k - 1) {           ans = md(ans + NCR(cnt, k - 1));         }         cnt++;       } else {         cnt--;       }     }     cout << ans <<   n ;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     init_fact();     int t = 1;     for (int i = 1; i <= t; i++) {       if (0) cerr <<  Case #  << i <<   n ;       solve(i);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   long long a[100005];   long long sum1[100005], sum2[100005];   int main() {     memset(sum1, 0, sizeof(sum1));     memset(sum2, 0, sizeof(sum2));     cin >> n;     for (int i = 1; i <= n; ++i) {       cin >> a[i];       sum1[i] = sum1[i - 1] + a[i];     }     sort(a + 1, a + n + 1);     for (int i = 1; i <= n; ++i) {       sum2[i] = sum2[i - 1] + a[i];     }     cin >> m;     for (int i = 0; i < m; ++i) {       int q, l, r;       cin >> q >> l >> r;       if (q == 1) {         cout << sum1[r] - sum1[l - 1] << endl;       } else {         cout << sum2[r] - sum2[l - 1] << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   bool fun(long long a);   using namespace std;   int main() {     long long num, num1, num2;     cin >> num;     if (num % 2 == 0) {       num1 = num / 2;       num2 = num / 2;       while (!fun(num1) || !fun(num2)) {         num1 -= 1;         num2 += 1;       }     } else {       num1 = num / 2;       num2 = num / 2 + 1;       while (!fun(num1) || !fun(num2)) {         num1 -= 1;         num2 += 1;       }     }     cout << num1 <<     << num2;   }   bool fun(long long a) {     int c = 0;     for (int i = 2; i < a; i++) {       if (a % i == 0) {         c = 1;         break;       }     }     return c == 1;   }


#include <bits/stdc++.h>   using namespace std;   int n, tab[1000001];   void draw() {     for (int i = 0; i < n; i++) {       cout << tab[i] <<    ;     }     cout << endl;   }   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       cin >> tab[i];     }     sort(tab, tab + n);     if (n % 2 == 1) {       cout << tab[n / 2] << endl;     } else {       cout << tab[n / 2 - 1] << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline T read(T& x) {     x = 0;     int f = 0;     char ch = getchar();     while (ch <  0  || ch >  9 ) f |= (ch ==  - ), ch = getchar();     while (ch >=  0  && ch <=  9 ) x = x * 10 + ch -  0 , ch = getchar();     return x = f ? -x : x;   }   const int N = 3e5 + 10;   const int INF = 2000000000;   int n, k, i, ans, minx, maxx, miny, maxy, x[N], y[N];   int main() {     read(n);     minx = miny = INF, maxx = maxy = -INF;     for (i = 0; i < n; ++i) {       read(x[i]), read(y[i]);       minx = min(minx, x[i]);       miny = min(miny, y[i]);       maxx = max(maxx, x[i]);       maxy = max(maxy, y[i]);     }     for (ans = -INF, i = 0; i < n; ++i) {       ans = max(ans, 2 * (maxx - x[i]) + 2 * (maxy - y[i]));       ans = max(ans, 2 * (maxx - x[i]) + 2 * (y[i] - miny));       ans = max(ans, 2 * (x[i] - minx) + 2 * (maxy - y[i]));       ans = max(ans, 2 * (x[i] - minx) + 2 * (y[i] - miny));     }     printf( %d%c , ans, n == 3 ?   n  :    );     for (i = 4; i <= n; ++i)       printf( %d%c , 2 * (maxx - minx + maxy - miny), i == n ?   n  :    );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   namespace fio {   streambuf* in = cin.rdbuf();   char bb[1000000], *s = bb, *t = bb;   inline long long read() {     long long x = 0;     char ch =         (s == t && (t = (s = bb) + in->sgetn(bb, 1000000), s == t) ? EOF : *s++);     while (ch < 48)       ch = (s == t && (t = (s = bb) + in->sgetn(bb, 1000000), s == t) ? EOF                                                                       : *s++);     while (ch >= 48)       x = x * 10 + ch - 48,       ch = (s == t && (t = (s = bb) + in->sgetn(bb, 1000000), s == t) ? EOF                                                                       : *s++);     return x;   }   }  // namespace fio   using fio::read;   long long n;   int m, llm;   int lim[26];   vector<int> road[26];   map<array<int, 26>, int> huaji;   array<int, 26> pm;   class mat {    public:     int val[125][125];     int* operator[](int x) { return val[x]; }     mat operator*(mat _) {       mat ans;       for (int i = 1; i <= llm; i++)         for (int u = 1; u <= llm; u++) {           ans[i][u] = 0;           for (int j = 1; j <= llm; j++)             ans[i][u] = (ans[i][u] + val[i][j] * _[j][u]) % 12345;         }       return ans;     }   };   mat ksm(mat x, long long y) {     mat ans = x;     y--;     for (; y; y >>= 1, x = x * x)       if (y & 1) ans = ans * x;     return ans;   }   mat base;   int ans;   int main() {     n = read(), m = read();     if (!n) return cout << 1, 0;     if (!m) return cout << 0, 0;     for (int i = 1, x, y; i <= m; i++)       x = read() +  0  -  A , road[x].emplace_back(y = read()),       lim[x] = max(lim[x], 1) * road[x].back();     while (pm[25] < max(lim[25], 1)) {       huaji[pm] = ++llm, pm[0]++;       for (int i = 0; i < 25; i++)         if (lim[i])           pm[i + 1] += pm[i] / lim[i], pm[i] %= lim[i];         else           pm[i + 1] += pm[i], pm[i] = 0;     }     for (pair<array<int, 26>, int> it : huaji)       for (int i = 0; i < 26; i++)         if (lim[i])           it.first[i] = (it.first[i] + 1) % lim[i],           base[it.second][huaji[it.first]]++,           it.first[i] = (it.first[i] - 1 + lim[i]) % lim[i];     base = ksm(base, n);     for (pair<array<int, 26>, int> it : huaji) {       bool flag = 1;       for (int i = 0, fx = 0; flag && i < 26; i++, flag &= fx, fx = 0)         if (!lim[i])           fx = 1;         else           for (int p : road[i]) fx |= !(it.first[i] % p);       flag ? ans = (ans + base[1][it.second]) % 12345 : ans;     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   vector<vector<set<int> > > setgrid;   vector<string> grid;   int k;   int ro[4] = {1, -1, 0, 0};   int co[4] = {0, 0, -1, 1};   struct s {     s() : r(-1), c(-1), set(-1), path(  ), let( A ), d(0) {}     s(int nr, int nc, unsigned int nset, string npath, char nlet, int nd)         : r(nr), c(nc), set(nset), path(npath), let(nlet), d(nd) {}     int r, c, d;     unsigned int set;     string path;     char let;   };   bool operator<(const s &lhs, const s &rhs) {     if (lhs.d == rhs.d)       if (lhs.path == rhs.path)         return lhs.let >= rhs.let;       else         return lhs.path >= rhs.path;     else       return lhs.d >= rhs.d;   }   bool visited(int r, int c, unsigned int set) {     unsigned int subset = set;     do {       subset = (subset - 1) & set;       if (setgrid[r][c].find(subset) != setgrid[r][c].end()) {         return true;       }     } while (subset != set);     return false;   }   int main(void) {     s qf;     int rs, cs, nr, nc;     unsigned int nset, one = 0x00000001;     priority_queue<s> q;     vector<s> pv, tv;     cin >> rs >> cs >> k;     grid.resize(rs);     for (int i = 0; i < rs; i++) cin >> grid[i];     setgrid.resize(rs);     for (int i = 0; i < rs; i++) setgrid[i].resize(cs);     int sr, sc;     for (int i = 0; i < rs; i++)       for (int j = 0; j < cs; j++)         if (grid[i][j] ==  S ) {           sr = i;           sc = j;           break;         }     q.push(s(sr, sc, 0,   ,  a , 0));     setgrid[sr][sc].insert(0);     while (!q.empty()) {       pv.clear();       qf = q.top();       for (int i = 0; i < 4; i++) {         nr = qf.r + ro[i];         nc = qf.c + co[i];         if (nr < 0 || nr >= rs || nc < 0 || nc >= cs) continue;         if (grid[nr][nc] ==  T ) goto success;         nset = qf.set | (one << int(grid[nr][nc] -  a ));         if ((__builtin_popcount(nset) > k) || visited(nr, nc, nset)) continue;         pv.push_back(             s(nr, nc, nset, qf.path + grid[nr][nc], grid[nr][nc], qf.d + 1));         setgrid[nr][nc].insert(nset);       }       sort(pv.begin(), pv.end());       for (int i = 0; i < pv.size(); i++) q.push(pv[i]);       q.pop();     }     cout << -1 <<   n ;     return 0;   success:     if (qf.path !=   ) cout << qf.path <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, x, y;   bool a[401][401];   bool viz[401];   int dist[401];   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cerr.tie(0);     cout.tie(0);     cin >> n >> m;     while (m--) {       cin >> x >> y;       a[x][y] = a[y][x] = 1;     }     queue<int> q;     q.push(1);     viz[1] = 1;     while (!q.empty()) {       int u = q.front();       q.pop();       for (int i = 1; i <= n; i++)         if (!viz[i] && (a[u][i] ^ a[1][n])) {           q.push(i);           viz[i] = 1;           dist[i] = dist[u] + 1;         }     }     return cout << ((!viz[n]) ? -1 : max(1, dist[n])), 0;   }


#include <bits/stdc++.h>   using namespace std;   int main(int argc, char** argv) {     char s[3][3];     bool is = false;     for (int i = 0; i < 3; i++) {       for (int j = 0; j < 3; j++) {         cin >> s[i][j];         if (s[i][j] ==  X ) is = true;       }     }     int i = 0, j = 0;     bool isY = true;     for (int i = 0; i < 3; i++) {       for (int j = 0; j < 3; j++)         if (s[i][j] != s[2 - i][2 - j]) isY = false;     }     if (isY)       cout <<  YES ;     else       cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   double p1, p2;   double fastPow(double b, int n) {     if (n == 0) return 1.0;     double po = fastPow(b, n / 2);     po = po * po;     if (n & 1) return po * b;     return po;   }   double proba(int turno) {     double ans = 1;     ans = ans * fastPow(1 - p1, turno / 2);     ans = ans * fastPow(1 - p2, turno / 2);     return ans * p1;     return ans * p1;   }   int main() {     double a, b, c, d;     while (cin >> a >> b >> c >> d) {       double prob = 0;       p1 = a / b;       p2 = c / d;       for (int i = 1; i < 100000; i += 2) prob = prob + proba(i);       cout << prob << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxN = 3e5 + 5;   map<pair<int, int>, int> mp;   int counts[maxN];   set<int> s[maxN];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int N, P;     cin >> N >> P;     for (int i = 0; i < N; i++) {       pair<int, int> xy;       cin >> xy.first >> xy.second;       xy = {min(xy.first, xy.second), max(xy.first, xy.second)};       if (mp.count(xy) > 0)         mp[xy]++;       else         mp[xy] = 1;       counts[xy.first]++;       counts[xy.second]++;       s[xy.first].insert(xy.second);       s[xy.second].insert(xy.first);     }     vector<int> ordered;     for (int i = 1; i <= N; i++) {       ordered.push_back(counts[i]);     }     sort(ordered.begin(), ordered.end());     long long ans = 0;     for (int i = 1; i <= N; i++) {       int rem = P - counts[i];       int k = lower_bound(ordered.begin(), ordered.end(), rem) - ordered.begin();       int tot = N - k;       if (counts[i] >= rem) tot--;       for (auto it = s[i].begin(); it != s[i].end(); it++) {         pair<int, int> ordp = {min(i, *it), max(i, *it)};         if (counts[i] + counts[*it] >= P &&             counts[i] + counts[*it] - mp[ordp] < P) {           tot--;         }       }       ans += tot;     }     cout << ans / 2;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     string second, a =  1968 ;     string rem[10];     cin >> second;     int zero = 0;     bool one = 0, six = 0, eight = 0, nine = 0;     string alt =   ;     for (int i = 0; i < second.size(); i++) {       if (second[i] ==  0 ) zero++;       if (second[i] ==  1  && one) alt += second[i];       if (second[i] ==  6  && six) alt += second[i];       if (second[i] ==  8  && eight) alt += second[i];       if (second[i] ==  9  && nine) alt += second[i];       if (second[i] ==  1 )         one = 1;       else if (second[i] ==  6 )         six = 1;       else if (second[i] ==  8 )         eight = 1;       else if (second[i] ==  9 )         nine = 1;       else if (second[i] !=  0 )         alt += second[i];     }     int t = 1, mo = 0;     for (int i = 0; i < zero; i++) {       t = (t * 10) % 7;     }     int ft = t;     do {       int m = 0;       t = ft;       for (int i = 4 - 1; i >= 0; i--) {         m = (m + t * (a[i] -  0 )) % 7;         t = (t * 10) % 7;       }       rem[m] = a;     } while (next_permutation(a.begin(), a.end()));     for (int i = alt.size() - 1; i >= 0; i--) {       mo = (mo + (alt[i] -  0 ) * t) % 7;       t = (t * 10) % 7;     }     rem[7] = rem[0];     cout << alt << rem[7 - mo];     for (int i = 0; i < zero; i++) cout << 0;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 1e5, OO = 1e14;   const int di[] = {1, -1, 0, 0};   const int dj[] = {0, 0, 1, -1};   long long TC, n, m, k, a, b, c, cnt, u, mx, mn, ans, arr[N];   bool f, vis[N], mark[N];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> TC;     while (TC--) {       cin >> n >> m;       cnt = f = 0;       m += (2 * n);       for (int i = 1; i <= n && !f; i++) {         for (int j = i + 1; j <= n; j++) {           cout << i <<     << j <<   n ;           if (++cnt == m) {             f = 1;             break;           }         }       }     }     return 0;   }


#pragma GCC optimize( O3 )   #pragma GCC target( avx2 )   #include<bits/stdc++.h>      using namespace std;      #define int long long      signed main() {       int t;       cin >> t;       for (int u = 0; u < t; ++u) {           string s;           cin >> s;           int b1 = 0, b2 = 0;           int ans = 0;           for (char c : s) {               if (c ==  ( ) {                   ++b1;               } else if (c ==  [ ) {                   ++b2;               } else if (c ==  )  && b1) {                   --b1;                   ++ans;               } else if (c ==  ]  && b2) {                   --b2;                   ++ans;               }           }           cout << ans <<   n ;       }   }


#include <bits/stdc++.h>   using namespace std;   string toString(long long n) {     string str =   ;     while (n) {       str += n % 10 +  0 ;       n /= 10;     }     reverse(str.begin(), str.end());     return str;   }   int main() {     string s =   ;     for (auto i = (1); i <= (10000); ++i) {       string t = toString(i);       s += t;     }     long long n;     scanf( %lld , &n);     if (n <= (int)s.size())       printf( %c n , s[n - 1]);     else {       n -= 9;       long long cur = 180LL;       int digit = 2;       long long power = 10;       while (n > cur) {         n -= cur;         power *= 10LL;         ++digit;         cur = 9LL * digit * power;       }       power += n / digit - 1;       n %= digit;       if (n) ++power;       string str = toString(power);       if (n == 0)         cout << str[(int)str.size() - 1] << endl;       else         cout << str[n - 1] << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, b;     cin >> n >> b;     long long int a[n], i, j, k, l, t1, t2, sum = 0, ad[n];     for (i = 0; i < n; i++) {       cin >> a[i];       ad[i] = a[i];     }     vector<pair<long long int, long long int>> v;     map<long long int, long long int> mp;     for (i = 0; i < b; i++) {       cin >> t1 >> t2;       v.push_back(make_pair(t1, t2));     }     sort(v.begin(), v.end());     sort(a, a + n);     i = j = sum = 0;     for (i = 0; i < n; i++) {       while (a[i] >= v[j].first && j < b) {         sum = sum + v[j].second;         j++;       }       mp[a[i]] = sum;     }     for (i = 0; i < n; i++) {       cout << mp[ad[i]] <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 5;   int n;   double p[maxn], dp[maxn];   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %lf , &p[i]);     double sol = 0.;     dp[0] = 0;     for (int i = 1; i < n; i++) {       dp[i] = (dp[i - 1] + p[i - 1]) * p[i];       sol += 2. * dp[i];     }     for (int i = 0; i < n; i++) sol += p[i];     printf( %.9lf n , sol);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int numTest;     cin >> numTest;     for (int num = 0; num < numTest; ++num) {       int n;       cin >> n;       int arr[n];       for (int i = 0; i < n; ++i) {         cin >> arr[i];       }       sort(arr, arr + n);       int temp = arr[0], temp2 = 0;       for (int i = 1; i < n; ++i) {         temp2 += arr[i - 1];         arr[i] -= temp;         temp += arr[i];         if (arr[0] < arr[i]) arr[0] = arr[i];       }       cout << arr[0] << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int getInt() {     int x;     scanf( %d , &x);     return x;   }   long long getLongLong() {     long long x;     scanf( %I64d , &x);     return x;   }   double getDouble() {     double x;     scanf( %lf , &x);     return x;   }   char getChar() {     char x;     scanf( %c , &x);     return x;   }   template <typename t>   t abs(t a) {     if (a >= 0) return a;     return -a;   }   struct dual {     int a, b;     bool const operator<(const dual &x) const {       if (a == x.a) return b > x.b;       return a < x.a;     }   };   struct triple {     int a, b, c;     bool const operator<(const triple &x) const {       if (c == x.c) {         if (a == x.a) return b > x.b;         return a < x.a;       }       return c < x.c;     }   };   void FastIO() {     ios::sync_with_stdio(0);     cin.tie(0);   }   int a[512345];   char s[512345];   long long ssb[512345] = {0}, psb[512345] = {0};   long long ssa[512345] = {0}, psa[512345] = {0};   int main() {     int n = getInt();     for (int i = 0; i < n; i++) a[i] = getInt();     scanf( %s , s);     if (s[0] ==  B )       psb[0] = a[0];     else       psa[0] = a[0];     for (int i = 1; i < n; i++) {       psa[i] = psa[i - 1];       psb[i] = psb[i - 1];       if (s[i] ==  A )         psa[i] += a[i];       else         psb[i] += a[i];     }     for (int i = n - 1; i >= 0; i--) {       ssa[i] = ssa[i + 1];       ssb[i] = ssb[i + 1];       if (s[i] ==  A )         ssa[i] += a[i];       else         ssb[i] += a[i];     }     long long ans = max(ssa[0], ssb[0]);     for (int i = 0; i < n; i++) {       ans = max(ans, max(psa[i] + ssb[i + 1], psb[i] + ssa[i + 1]));     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 10;   int a[N];   int n;   int res[N];   int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }   int lcm(int a, int b) { return a * b / gcd(a, b); }   void solve() {     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];     }     if (n % 2 == 0) {       for (int i = 0; i < n / 2; i++) {         int j = n - 1 - i;         int t = lcm(a[i], a[j]);         res[i] = t / a[i];         res[j] = t / a[j];         if (1) {           res[i] *= -1;         }       }       for (int i = 0; i < n; i++) cout << res[i] <<    ;       cout << endl;     } else {       for (int i = 0; i < n / 2 - 1; i++) {         int j = n - 1 - i;         int t = lcm(a[i], a[j]);         res[i] = t / a[i];         res[j] = t / a[j];         if (1) {           res[i] *= -1;         }       }       res[n / 2 - 1] = 1;       res[n / 2 + 1] = -1;       int t = 1 * a[n / 2 - 1] + -1 * a[n / 2 + 1];       if (t == 0) {         t += a[n / 2 - 1];         res[n / 2 - 1]++;       }       int t2 = lcm(t, a[n / 2]);       res[n / 2] = t2 / a[n / 2];       res[n / 2 - 1] *= t2 / t;       res[n / 2 + 1] *= t2 / t;       if (1) {         res[n / 2] *= -1;       }       for (int i = 0; i < n; i++) cout << res[i] <<    ;       cout << endl;     }   }   int main() {     int K;     scanf( %d , &K);     while (K--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 5e5 + 9;   struct Node {     double st, ed, dir;   } p[N];   struct flag {     double num, id;   } q[N];   bool cmp(flag a, flag b) { return a.num < b.num; }   int main() {     int n, m, i, j, k;     while (~scanf( %d , &n)) {       for (i = 0; i < n; ++i) {         scanf( %lf%lf , &p[i].st, &p[i].dir);       }       double L = 0, R = 1e9 + 10, mid, ans = -1;       for (j = 0; j < 100; ++j) {         mid = (L + R) / 2;         bool ok = false;         double Max = -1e50;         for (i = 0; i < n; ++i) {           p[i].ed = p[i].st + p[i].dir * mid;           if (p[i].dir >= 0) {             Max = max(Max, p[i].ed);           } else {             if (p[i].ed <= Max) {               ok = true;               break;             }           }         }         if (ok) {           ans = mid;           R = mid;         } else {           L = mid;         }       }       printf( %.20f n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 200020;   long long a;   int main() {     cin >> a;     long long l = 1, r = 1e18;     long long ans =         (((9 * (5 * (9 * (2 * (long long)1e17) % a) % a) % a) % a) + 1) % a;     cout << l + (a - ans) <<     << r + (a - ans) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int task;     scanf( %d , &task);     while (task--) {       int n, p;       scanf( %d%d , &n, &p);       int rest(2 * n + p);       for (int i = 1; (i <= n) && rest; i++)         for (int j = i + 1; (j <= n) && rest; j++)           printf( %d %d n , i, j), rest--;     }     return 0;   }


#include <bits/stdc++.h>   const long long max9 = 10 + 1e9, max6 = 10 + 1e6, max12 = 10 + 1e12,                   max15 = 10 + 1e15;   const long long min6 = -1 * max6, min9 = -1 * max9, min12 = -1 * max12,                   min15 = -1 * max15;   const long long R = 7 + 1e9, NN = 10 + 1e5;   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long n;     long long k;     cin >> n >> k;     long long mn = n * (n + 1);     mn /= 2;     long long nn = n / 2 - 1, mx = 2 * (nn + 1) * n - nn * (nn + 1);     if (n % 2) mx += nn + 2;     if (k < mn) {       cout << -1;       return 0;     }     if (k >= mx) {       cout << mx << endl;       for (int i = (0); i < (n); ++i) cout << i + 1 <<    ;       cout << endl;       for (int i = (0); i < (n); ++i) cout << n - i <<    ;       return 0;     }     vector<int> a(n);     long long l = 0, last = n;     for (int i = (0); i < (n); ++i) a[i] = i + 1;     long long ben = k - mn;     for (int i = (0); i < (n / 2); ++i) {       if (ben == 0) break;       long long test = a[i] + ben;       if (test > last) {         a[i] = last;         a[last - 1] = i + 1;         ben -= last - i - 1;         last--;       } else {         a[i] = test;         a[test - 1] = i + 1;         break;       }     }     long long sum = 0;     for (int i = (0); i < (n); ++i) sum += max(i + 1, a[i]);     cout << sum << endl;     for (int i = (0); i < (n); ++i) cout << i + 1 <<    ;     cout << endl;     for (int i = (0); i < (n); ++i) cout << a[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   #pragma comment(linker,  /STACK:167772160 )   int comp(const void* a, const void* b) {     return (*(long long*)a) - (*(long long*)b);   }   int main() {     int n;     long long mas[300000], ans(0);     scanf( %d , &n);     for (int i(0); i < n; ++i) scanf( %I64d , &mas[i]);     qsort(mas, n, sizeof(long long), comp);     for (int i(0); i < n; ++i) ans += mas[i] * (2 + i);     ans -= mas[n - 1];     printf( %I64d , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char s[105];   int main() {     int n, m, i, l, r;     char ch1, ch2;     cin >> n >> m;     cin >> (s + 1);     while (m--) {       cin >> l >> r >> ch1 >> ch2;       for (i = l; i <= r; i++)         if (s[i] == ch1) s[i] = ch2;     }     cout << (s + 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string a[100], b[100];   map<string, int> m;   int n, s;   int main(void) {     scanf( %d , &n);     for (int i = 0; i < n; i++) {       cin >> a[i];       m[a[i]]++;     }     for (int i = 0; i < n; i++) {       cin >> b[i];       m[b[i]]--;     }     s += abs(m[ S ]);     s += abs(m[ M ]);     s += abs(m[ L ]);     s += abs(m[ XS ]);     s += abs(m[ XXS ]);     s += abs(m[ XXXS ]);     s += abs(m[ XL ]);     s += abs(m[ XXL ]);     s += abs(m[ XXXL ]);     cout << s / 2;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     cin.tie(0);     ios::sync_with_stdio(0);     cout << fixed;     cout << setprecision(12);     long long n1, n2;     cin >> n1 >> n2;     long long a[n1], b[n2], cnt1[10] = {0}, cnt2[10] = {0};     for (long long i = 0; i < n1; i++) {       cin >> a[i];       cnt1[a[i]]++;     }     for (long long i = 0; i < n2; i++) {       cin >> b[i];       cnt2[b[i]]++;     }     for (long long i = 0; i < 10; i++)       if (cnt1[i] != 0 && cnt2[i] != 0) {         cout << i;         return 0;       }     sort(a, a + n1);     sort(b, b + n2);     cout << min(a[0] * 10 + b[0], b[0] * 10 + a[0]);     return 0;   }   void setprime(bool isprime[], long long n) {     for (long long i = 0; i < n; i++) isprime[i] = true;     isprime[0] = false;     isprime[1] = false;     for (long long i = 2; i < n; i++) {       for (long long j = 2; i * j < n; j++) isprime[i * j] = false;     }   }   long long BinarySearch(long long arr[], long long first, long long last,                          long long search) {     long long middle = (first + last) / 2;     while (first <= last) {       if (arr[middle] < search) {         first = middle + 1;       } else if (arr[middle] == search) {         return middle;       } else {         last = middle - 1;       }       middle = (first + last) / 2;     }     if (first > last) {       return -1;     }   }   long long choose(long long n, long long k) {     if (k == 0) return 1;     return (n * choose(n - 1, k - 1)) / k;   }   void showArray(long long a[], long long n) {     for (long long i = 0; i < n; i++) {       cout << a[i] <<    ;     }     cout << endl;   }   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }


#include <bits/stdc++.h>   using namespace std;   long long N;   long long x, y, x2, y2;   pair<int, int> v[100010];   bool Can(long long n) {     long long Rem = n % N;     long long Count = n / N;     long long X = v[Rem].first + (v[N].first * Count);     long long Y = v[Rem].second + (v[N].second * Count);     return ((abs(x2 - (X + x)) + abs(y2 - (Y + y))) <= n);   }   void Solve() {     cin >> x >> y;     cin >> x2 >> y2;     cin >> N;     string s;     cin >> s;     long long X = 0, Y = 0;     for (long long i = 0; i < N; ++i) {       if (s[i] ==  U ) {         Y++;       } else if (s[i] ==  D ) {         Y--;       } else if (s[i] ==  L ) {         X--;       } else if (s[i] ==  R ) {         X++;       }       v[i + 1] = make_pair(X, Y);     }     long long ans = -1;     long long low = 0, high = (1100000000000000000ll);     while (low <= high) {       long long mid = (low + high) / 2;       if (Can(mid)) {         high = mid - 1;         ans = mid;       } else {         low = mid + 1;       }     }     cout << ans << endl;   }   int main() {     ios::sync_with_stdio(NULL);     cin.tie(NULL);     cout.tie(NULL);     int t = 1;     while (t--) Solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 500;   bool vis[3][MAXN];   char g[3][MAXN];   pair<int, int> que[MAXN * 3];   int n, k;   inline void init() {     memset(g, 0, sizeof(g));     memset(vis, false, sizeof(vis));     scanf( %d%d , &n, &k);     for (int i = 0; i < 3; i++) scanf( %s , g[i]);   }   inline bool BFS() {     int begin = 0, end = 0;     for (int i = 0; i < 3; i++)       if (g[i][0] ==  s ) que[end++] = pair<int, int>(i, 0);     while (begin != end) {       int ux = que[begin].first, uy = que[begin].second;       begin++;       if (uy >= n) return true;       if (!isupper(g[ux][uy + 1])) {         if (ux + 1 < 3 && !vis[ux + 1][uy + 3] && !isupper(g[ux + 1][uy + 1]) &&             !isupper(g[ux + 1][uy + 2]) && !isupper(g[ux + 1][uy + 3]))           que[end++] = pair<int, int>(ux + 1, uy + 3), vis[ux + 1][uy + 3] = true;         if (ux - 1 >= 0 && !vis[ux - 1][uy + 3] && !isupper(g[ux - 1][uy + 1]) &&             !isupper(g[ux - 1][uy + 2]) && !isupper(g[ux - 1][uy + 3]))           que[end++] = pair<int, int>(ux - 1, uy + 3), vis[ux - 1][uy + 3] = true;         if (!vis[ux][uy + 3] && !isupper(g[ux][uy + 2]) &&             !isupper(g[ux][uy + 3]))           que[end++] = pair<int, int>(ux, uy + 3), vis[ux][uy + 3] = true;       }     }     return false;   }   int main(void) {     int t;     scanf( %d , &t);     while (t--) {       init();       printf( %s n , BFS() ?  YES  :  NO );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int t = 1;     while (t--) {       long long int i, j, k = 0, n, m;       cin >> n >> m;       vector<long long int> a(n);       for (i = 0; i < n; i++) {         long long int x, y;         cin >> x >> y;         k += x * y;         a[i] = k;       }       while (m--) {         cin >> k;         cout << (lower_bound(a.begin(), a.end(), k) - a.begin() + 1) <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long f(long long x) {     long long res;     res = x * x;     return res;   }   void solve() {     long long a[3];     cin >> a[0] >> a[1] >> a[2];     sort(a, a + 3);     long long d;     d = (long long)(sqrt(f(a[2]) + f(a[1] - a[0])));     d = d + 1;     cout << d <<   n ;   }   int main() {     long long t;     cin >> t;     while (t--) solve();   }


#include <bits/stdc++.h>   using namespace std;      #define Int long long      const int mxN = 2e5 + 5;      int main()   {       ios_base::sync_with_stdio(false);       cin.tie(0);       int t = 1;       cin >> t;       while(t--){           Int n;           cin >> n;           while(n % 11 != 0 && n > 10)n -= 111;           if(n >= 0 && n % 11 == 0)cout <<  YES  << endl;           else cout <<  NO  << endl;          }   }


#include <bits/stdc++.h>   using namespace std;   long long exp(long long a, long long b, long long p) {     if (b == 0) return 1;     if (b % 2) return a * exp(a, b - 1, p) % p;     return exp(a * a % p, b / 2, p);   }   long long inv[1000009], E[1000009];   int main() {     long long a, b, p, x;     cin >> a >> b >> p >> x;     vector<long long> v;     for (int i = 1; i <= p; i++) {       if ((p - 1) % i == 0) v.push_back(i);     }     long long on;     for (int j = 0; j < v.size(); j++) {       if (exp(a, v[j], p) == 1) {         on = v[j];         break;       }     }     for (int i = 1; i <= p; i++) {       inv[i] = exp(i, p - 2, p);     }     long long ans = 0;     for (int i = 1; i <= on; i++) {       long long E = exp(a, i, p);       long long N = inv[E] * b % p;       long long y = (N - i + p) * inv[on] % p;       long long m = i + y * on;       long long M = p * on;       if (x % M >= m)         ans += x / M + 1;       else         ans += x / M;     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 1000000;   int f[35][35][55];   int gao(int x, int y, int z) {     if (f[x][y][z] > 0) return f[x][y][z];     if (z == 0) return f[x][y][z] = 0;     if (x * y < z) return f[x][y][z] = inf;     if (x * y == z) return f[x][y][z] = 0;     int now = inf;     for (int i = 1; i <= z; i++) {       int cnt = inf;       for (int j = 1; j < x; j++)         cnt = min(cnt, gao(j, y, i) + gao(x - j, y, z - i) + y * y);       for (int j = 1; j < y; j++)         cnt = min(cnt, gao(x, j, i) + gao(x, y - j, z - i) + x * x);       now = min(now, cnt);     }     return f[x][y][z] = now;   }   int main() {     int T;     scanf( %d , &T);     while (T--) {       int n, m, k;       scanf( %d%d%d , &n, &m, &k);       printf( %d n , gao(n, m, k));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     int m;     cin >> n >> m;     bool ans[m + 1];     for (int i = 0; i <= m; i++) {       ans[i] = false;     }     int a[n];     vector<pair<int, int> > v;     for (int i = 0; i < n; i++) {       int a;       int b;       cin >> a;       cin >> b;       v.push_back(make_pair(a, b));     }     for (int i = 0; i < n; i++) {       int start = v[i].first;       int end = v[i].second;       for (int j = start; j <= end; j++) {         if (ans[j] == false) ans[j] = true;       }     }     vector<int> final;     int result = 0;     for (int i = 1; i <= m; i++) {       if (ans[i] == false) {         final.push_back(i);         result++;       }     }     cout << result << endl;     for (int i = 0; i < final.size(); i++) {       cout << final[i] <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   char buf[2000];   int dx[4] = {0, 0, -1, 1};   int dy[4] = {-1, 1, 0, 0};   int n, m;   pair<int, int> tbl1[1 << 23];   pair<int, int> tbl2[1 << 23];   const int Prime1 = 262139, Prime2 = 40999999;   const int Prime3 = 100003, Prime4 = 40999799;   const pair<int, int> ZERO = make_pair(0, 0);   bool ex(int x, int y) {     int t1 = x * Prime1 + y * Prime2;     int t2 = x * Prime3 + y * Prime4;     t1 = abs(t1);     t1 %= ((1 << 23) - 1);     t2 = abs(t2);     t2 %= ((1 << 23) - 1);     while (tbl1[t1] != ZERO && tbl1[t1] != make_pair(x, y))       t1 = (t1 + 1) % (1 << 23);     if (tbl1[t1] == make_pair(x, y)) return false;     tbl2[t2] = tbl1[t1] = make_pair(x, y);     return true;   }   int main() {     cin >> n >> m;     vector<string> a;     for (int i = (0); i < (n); ++i) {       string s;       scanf( %s , buf);       s = buf;       a.push_back(s);     }     pair<int, int> start;     for (int i = (0); i < (n); ++i) {       for (int j = (0); j < (m); ++j)         if (a[i][j] ==  S ) start = make_pair(i, j);     }     queue<pair<int, int> > q;     q.push(start);     ex(start.first, start.second);     int k = 0;     while (!q.empty()) {       if (k > n * m) {         cout <<  Yes n ;         return 0;       }       pair<int, int> v = q.front();       q.pop();       for (int i = (0); i < (4); ++i) {         int x = v.first + dx[i];         int y = v.second + dy[i];         int _x = (x % n + n) % n;         int _y = (y % m + m) % m;         if (a[_x][_y] !=  #  && ex(x, y)) {           k++;           q.push(make_pair(x, y));         }       }     }     cout <<  No n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int a;     cin >> a;     while (1) {       long long int t = a;       long long int su = 0;       while (t > 0) {         su += t % 10;         t /= 10;       }       if (su % 4 == 0) {         cout << a;         return 0;       }       a++;     }   }


#include <bits/stdc++.h>   using namespace std;   struct MinTreeNode {     int min;     int count;   };   int n;   MinTreeNode tmin[200000];   int tgcd[200000];   int gcd(int a, int b) {     if (a == 0) {       return b;     }     if (b == 0) {       return a;     }     if (a == 1 || b == 1) {       return 1;     }     if (a % 2 == 0) {       if (b % 2 == 0) {         return 2 * gcd(a / 2, b / 2);       } else {         return gcd(a / 2, b);       }     } else {       if (b % 2 == 0) {         return gcd(a, b / 2);       } else {         return gcd(min(a, b), max(a, b) - min(a, b));       }     }   }   void buildGcdTree() {     for (int i = n - 1; i >= 1; --i) {       tgcd[i] = gcd(tgcd[i << 1], tgcd[i << 1 | 1]);     }   }   void buildMinTree() {     for (int i = n - 1; i >= 1; --i) {       if (tmin[i << 1].min < tmin[i << 1 | 1].min) {         tmin[i] = tmin[i << 1];       } else {         if (tmin[i << 1].min > tmin[i << 1 | 1].min) {           tmin[i] = tmin[i << 1 | 1];         } else {           tmin[i].min = tmin[i << 1].min;           tmin[i].count = tmin[i << 1].count + tmin[i << 1 | 1].count;         }       }     }   }   MinTreeNode minAndCount(int l, int r) {     MinTreeNode result;     result.min = 2000000000;     result.count = 0;     for (l += n, r += n; l < r; l >>= 1, r >>= 1) {       if (l & 1) {         if (result.min == tmin[l].min) {           result.count += tmin[l].count;         } else {           if (result.min > tmin[l].min) {             result = tmin[l];           }         }         ++l;       }       if (r & 1) {         --r;         if (result.min == tmin[r].min) {           result.count += tmin[r].count;         } else {           if (result.min > tmin[r].min) {             result = tmin[r];           }         }       }     }     return result;   }   int gcdOfInterval(int l, int r) {     int result = 0;     for (l += n, r += n; l < r; l >>= 1, r >>= 1) {       if (l & 1) {         result = gcd(result, tgcd[l++]);       }       if (r & 1) {         result = gcd(result, tgcd[--r]);       }     }     return result;   }   int elementsThatDivideIntervalCount(int l, int r) {     int g = gcdOfInterval(l, r);     MinTreeNode m = minAndCount(l, r);     if (m.min == g) {       return m.count;     } else {       return 0;     }   }   int main(int argc, char** argv) {     ios::sync_with_stdio(0);     cin >> n;     for (int i = n; i < 2 * n; ++i) {       int s;       cin >> s;       tgcd[i] = s;       tmin[i].min = s;       tmin[i].count = 1;     }     buildMinTree();     buildGcdTree();     int t;     cin >> t;     for (int i = 0; i < t; ++i) {       int l, r;       cin >> l >> r;       --l;       cout << r - l - elementsThatDivideIntervalCount(l, r) <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<long long int> v;   vector<long long int> v1;   vector<long long int> v2;   const long long int inf = 100000000000005;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n;     cin >> n;     for (int i = 1; i < n; i++) cout << i + 1 <<    ;     cout << 1 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int p[] = {0, 5, 7, 5};   int main() {     for (int k = 1; k <= 3; k++) {       string s;       getline(cin, s);       int tot = 0;       for (int i = 0; i < s.size(); i++)         if (s[i] ==  a  || s[i] ==  e  || s[i] ==  i  || s[i] ==  o  ||             s[i] ==  u )           tot++;       if (tot != p[k]) {         cout <<  NO  << endl;         return 0;       }     }     cout <<  YES  << endl;     return 0;   }