#include <bits/stdc++.h>   const int N = 100005;   using namespace std;   int n, a[N], b[N], flag[N];   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]), b[i] = 1;     int now = a[n];     for (int i = n - 1; i >= 1; i--) {       if (now > a[i])         b[i] = -1, flag[i] = 1, now = now - a[i];       else         b[i] = 1, flag[i] = -1, now = a[i] - now;     }     int yh = 1;     for (int i = 1; i <= n; i++) {       if (b[i] * yh == 1)         printf( + );       else         printf( - );       yh *= flag[i];     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 100;   const int LOG = 18;   const int inf = 1e9 + 10;   struct node {     int nex[2], val;     node() {       nex[0] = nex[1] = -1;       val = inf;     }   };   vector<node> v;   vector<int> div2[N];   bool mark[N];   int t[N];   node tmp;   int go(int curr, int t) {     if (v[curr].nex[t] != -1) return v[curr].nex[t];     v[curr].nex[t] = v.size();     v.push_back(tmp);     return v[curr].nex[t];   }   void add(int curr, int x) {     v[curr].val = min(v[curr].val, x);     for (int i = LOG - 1; i >= 0; i--) {       curr = go(curr, (x >> i) % 2);       v[curr].val = min(v[curr].val, x);     }   }   int query(int curr, int x, int maxi, int lev = LOG - 1) {     if (v[curr].val > maxi) return -1;     if (lev == -1) return (v[curr].val != inf) ? v[curr].val : -1;     int R = go(curr, 1);     int L = go(curr, 0);     if (v[R].val > maxi) {       return query(L, x, maxi, lev - 1);     } else if (v[L].val > maxi) {       return query(R, x, maxi, lev - 1);     } else {       if ((v[L].val ^ x) > (v[R].val ^ x)) {         return query(L, x, maxi, lev - 1);       } else {         return query(R, x, maxi, lev - 1);       }     }   }   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     memset(t, -1, sizeof t);     int q;     cin >> q;     for (int i = 1; i < N; i++) {       for (int j = i; j < N; j += i) {         div2[j].push_back(i);       }     }     for (int i = 0, tp, x, k, s, u; i < q; i++) {       cin >> tp;       if (tp == 1) {         cin >> u;         if (mark[u]) continue;         mark[u] = true;         for (auto x : div2[u]) {           if (t[x] == -1) {             t[x] = v.size();             v.push_back(tmp);           }           add(t[x], u);         }       } else {         cin >> x >> k >> s;         if (x % k != 0) {           cout <<  -1 n ;           continue;         }         s -= x;         if (t[k] == -1) {           t[k] = v.size();           v.push_back(tmp);         }         cout << query(t[k], x, s) <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e6 + 7;   const int inf = 0x3f3f3f3f;   const long long INF = 0x3f3f3f3f3f3f3f3f;   const int mod = 1000000007;   const double eps = 1e-6;   const double PI = acos(-1);   int n, k, miu[N], Pown[N], sum[N];   int Power(int a, int b) {     int ans = 1;     while (b) {       if (b & 1) ans = 1LL * ans * a % mod;       a = 1LL * a * a % mod;       b >>= 1;     }     return ans;   }   int main() {     miu[1] = 1;     for (int i = 1; i < N; i++)       for (int j = i + i; j < N; j += i) miu[j] -= miu[i];     scanf( %d%d , &n, &k);     for (int i = 1; i <= k; i++) Pown[i] = Power(i, n);     int ans = 0, tmp = 0;     for (int i = 1; i <= k; i++) {       for (int j = i; j <= k; j += i) {         sum[j] =             ((sum[j] + 1LL * miu[i] * (Pown[j / i] - Pown[j / i - 1])) % mod +              mod) %             mod;       }       tmp = (tmp + sum[i]) % mod;       ans = (ans + (tmp ^ i)) % mod;     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int q;     scanf( %d , &q);     for (int i = 0; i < q; i++) {       int l, r, d;       scanf( %d %d %d , &l, &r, &d);       if ((double)l / d > 1)         printf( %d n , d);       else {         int f = ((double)r / d) + 1;         printf( %d n , f * d);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int _ = 1e5 + 7;   const int __ = 4e5 + 7;   const int L = 11;   int n, Q;   long long a[_], pw[L + 7];   namespace SGT {   long long num[__], minx[__], tag[__];   bool cov[__];   bool flag;   void Build(int k, int l, int r) {     if (l == r) {       int j = 0;       while (pw[j] < a[l]) ++j;       minx[k] = pw[j] - a[l], num[k] = a[l];       return;     }     Build((k << 1), l, ((l + r) >> 1));     Build((k << 1 | 1), ((l + r) >> 1) + 1, r);     minx[k] = min(minx[(k << 1)], minx[(k << 1 | 1)]);     num[k] =         minx[(k << 1)] < minx[(k << 1 | 1)] ? num[(k << 1)] : num[(k << 1 | 1)];   }   void upd(int k, long long w) { minx[k] -= w, num[k] += w, tag[k] += w; }   void Psd(int k) {     if (cov[k]) {       cov[(k << 1)] = 1, num[(k << 1)] = num[k], minx[(k << 1)] = minx[k];       cov[(k << 1 | 1)] = 1, num[(k << 1 | 1)] = num[k],                     minx[(k << 1 | 1)] = minx[k];       cov[k] = 0, tag[k] = 0;     } else if (tag[k]) {       upd((k << 1), tag[k]);       upd((k << 1 | 1), tag[k]);       tag[k] = 0;     }   }   void Modify(int k, int l, int r, int x, int y, int w) {     if (l >= x and r <= y) {       if (minx[k] > w) {         upd(k, w);         return;       } else if (l == r or cov[k]) {         num[k] += w;         int j = 1;         while (pw[j] < num[k]) ++j;         minx[k] = pw[j] - num[k];         if (!minx[k]) flag = 1;         return;       }     }     Psd(k);     if (x <= ((l + r) >> 1)) Modify((k << 1), l, ((l + r) >> 1), x, y, w);     if (y > ((l + r) >> 1)) Modify((k << 1 | 1), ((l + r) >> 1) + 1, r, x, y, w);     minx[k] = min(minx[(k << 1)], minx[(k << 1 | 1)]);     num[k] =         minx[(k << 1)] < minx[(k << 1 | 1)] ? num[(k << 1)] : num[(k << 1 | 1)];   }   void Cover(int k, int l, int r, int x, int y, int w) {     if (l >= x and r <= y) {       tag[k] = 0, num[k] = w, cov[k] = 1;       int j = 1;       while (pw[j] < w) ++j;       minx[k] = pw[j] - w;       return;     }     Psd(k);     if (x <= ((l + r) >> 1)) Cover((k << 1), l, ((l + r) >> 1), x, y, w);     if (y > ((l + r) >> 1)) Cover((k << 1 | 1), ((l + r) >> 1) + 1, r, x, y, w);     minx[k] = min(minx[(k << 1)], minx[(k << 1 | 1)]);     num[k] =         minx[(k << 1)] < minx[(k << 1 | 1)] ? num[(k << 1)] : num[(k << 1 | 1)];   }   long long Query(int k, int l, int r, int x) {     if (l == r) return num[k];     Psd(k);     if (x <= ((l + r) >> 1))       return Query((k << 1), l, ((l + r) >> 1), x);     else       return Query((k << 1 | 1), ((l + r) >> 1) + 1, r, x);   }   void Init() { Build(1, 1, n); }   void Add(int l, int r, int w) {     do {       flag = 0;       Modify(1, 1, n, l, r, w);     } while (flag);   }   void Cover(int l, int r, int w) { Cover(1, 1, n, l, r, w); }   long long Ask(int x) { return Query(1, 1, n, x); }   }  // namespace SGT   int gi() {     int x = 0;     char c = getchar();     while (!isdigit(c)) c = getchar();     while (isdigit(c)) x = (x << 3) + (x << 1) + c -  0 , c = getchar();     return x;   }   void Init() {     n = gi(), Q = gi();     for (int i = 1; i <= n; ++i) a[i] = gi();     pw[0] = 1;     for (int i = 1; i <= L; ++i) pw[i] = (long long)pw[i - 1] * 42;     SGT::Init();   }   void Run() {     int ty, l, r, x;     while (Q--) {       ty = gi();       if (ty == 1)         printf( %lld n , SGT::Ask(gi()));       else {         l = gi(), r = gi(), x = gi();         if (ty == 2)           SGT::Cover(l, r, x);         else           SGT::Add(l, r, x);       }     }   }   int main() {     Init();     Run();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   long long f[15], all[15];   long long n, k;   int solve(int rem) {     if (!rem) return 1;     return solve(rem - 1) * 2;   }   long long solve(int i, string& str) {     if (i == str.size()) return 1;     long long ret = solve(i + 1, str);     if (str[i] ==  1 ) ret += all[str.size() - i - 1];     return ret;   }   bool lucky(long long x) {     while (x) {       if (x % 10 != 4 && x % 10 != 7) return 0;       x /= 10;     }     return 1;   }   int main() {     all[0] = f[0] = 1;     for (int i = 1; i < 15; ++i) {       f[i] = f[i - 1] * i;       all[i] = 2ll * all[i - 1];     }     cin >> n >> k;     if (n < 15 && f[n] < k) return cout << -1, 0;     long long nn = n;     int rem = 0;     for (int i = 0; i < 14; ++i)       if (f[i] < k) rem = i;     long long ans = 0;     set<long long> rem_num;     if (n > rem + 1) {       long long m = n - rem - 1;       string cur =   , s =   ;       stringstream mycin;       mycin << m;       mycin >> cur;       bool ok = 0, is = 0;       int lstseven = -1;       for (int i = 0; i < cur.size(); ++i) {         int ch = cur[i] -  0 ;         if (ok) break;         if (ch < 4) {           is = 1;           break;         } else if (ch > 7)           ok = 1, lstseven = 1e9 + 5;         else if (ch == 7)           lstseven = max(lstseven, i);         else if (ch > 4)           ok = 1;       }       if (is && lstseven == -1) {         int sz = cur.size();         --sz;         while (sz--) s +=  1 ;       } else {         ok = 0;         for (int i = 0; i < cur.size(); ++i) {           int ch = cur[i] -  0 ;           if (ok)             s +=  1 ;           else if (is && lstseven == i)             s +=  0 , ok = 1;           else if (ch > 7)             ok = 1, s +=  1 ;           else if (ch == 7)             s +=  1 ;           else if (ch > 4)             s +=  0 , ok = 1;           else             s +=  0 ;         }       }       if (s.size()) {         ans += solve(0, s);         for (int i = 1; i < s.size(); ++i) ans += all[i];       }       for (int i = n; rem_num.size() <= rem; --i) rem_num.insert(i);       n = rem + 1;     } else       for (int i = 1; i <= n; ++i) rem_num.insert(i);     for (int i = nn - n + 1; i <= nn; ++i) {       vector<int> v;       while (f[nn - i] < k) {         k -= f[nn - i];         v.push_back(*rem_num.begin());         rem_num.erase(rem_num.begin());       }       int x = *rem_num.begin();       rem_num.erase(rem_num.begin());       for (int j : v) rem_num.insert(j);       ans += lucky(i) && lucky(x);     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   const int mod = 1e9 + 7;   const int p_mod = 998244353;   using namespace std;   long long fast_pow(long long a, long long b) {     long long res = 1;     while (b) {       if (b & 1) res = (res * a) % mod;       b >>= 1;       a = (a * a) % mod;     }     return res % mod;   }   const int N = 1e5 + 5;   stack<char> s;   char str[N];   int cnt = 0;   int main() {     std::ios::sync_with_stdio(false);     std::cin.tie(0);     cin >> (str + 1);     int len = strlen(str + 1);     for (int i = 1; i <= len; i++) {       if (!s.empty() && s.top() == str[i]) {         s.pop();         cnt++;       } else         s.push(str[i]);     }     if (cnt % 2) {       cout <<  Yes  << endl;     } else       cout <<  No  << endl;     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   struct item {     string n, c;     int a, s;   };   item make(string n, string c, int a, int s) {     item z;     z.a = a;     z.c = c;     z.n = n;     z.s = s;     return z;   }   struct rez {     string n, t, h;     int b;   };   bool f2(rez a, rez b) { return a.b > b.b; }   struct equip {     string n;     vector<string> r;     int s;   };   int n, k, s, ya[3], yb[3];   item a[3][100];   rez b[3][1000];   equip z[3];   int sum(int h, int l) {     int sss = 0;     for (int i = 0; i < l; i++) sss += b[h][i].b;     return sss;   }   int main() {     string name, clas;     int atk, def, rz, siz;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> name >> clas >> atk >> def >> rz >> siz;       if (clas ==  weapon ) {         a[0][ya[0]] = make(name, clas, atk, siz);         ya[0]++;       }       if (clas ==  armor ) {         a[1][ya[1]] = make(name, clas, def, siz);         ya[1]++;       }       if (clas ==  orb ) {         a[2][ya[2]] = make(name, clas, rz, siz);         ya[2]++;       }       s += siz;     }     cin >> k;     rez y;     for (int i = 0; i < k; i++) {       cin >> y.n >> y.t >> y.b >> y.h;       if (y.t ==  gladiator ) {         b[0][yb[0]] = y;         yb[0]++;       }       if (y.t ==  sentry ) {         b[1][yb[1]] = y;         yb[1]++;       }       if (y.t ==  physician ) {         b[2][yb[2]] = y;         yb[2]++;       }     }     for (int h = 0; h < 3; h++) sort(b[h], b[h] + yb[h], f2);     if (s == k) {       for (int h = 0; h < 3; h++) {         int mx = -1, m;         for (int i = 0; i < ya[h]; i++) {           int ss = 0;           for (int j = 0; j < yb[h]; j++)             if (b[h][j].h == a[h][i].n) ss += b[h][j].b;           if (ss + a[h][i].a > mx) {             mx = ss + a[h][i].a;             m = i;           }         }         z[h].n = a[h][m].n;         for (int i = 0; i < 3; i++)           for (int j = 0; j < yb[i]; j++)             if (b[i][j].h == z[h].n) z[h].r.push_back(b[i][j].n);       }     } else {       int m[3];       for (int h = 0; h < 3; h++) {         int mx = -1, mm, l;         for (int i = 0; i < ya[h]; i++) {           int sm = sum(h, min(a[h][i].s, yb[h]));           if (a[h][i].a + sm > mx) {             mx = a[h][i].a + sm;             mm = i;             l = min(a[h][i].s, yb[h]);           }         }         z[h].n = a[h][mm].n;         z[h].s = a[h][mm].s;         for (int i = 0; i < l; i++) z[h].r.push_back(b[h][i].n);         m[h] = l;       }       for (int h = 0; h < 3; h++)         for (int i = 0; i < 3; i++)           while (m[i] < yb[i] && z[h].r.size() < z[h].s) {             z[h].r.push_back(b[i][m[i]].n);             m[i]++;           }     }     for (int i = 0; i < 3; i++) {       cout << z[i].n <<     << z[i].r.size();       for (int j = 0; j < z[i].r.size(); j++) cout <<     << z[i].r[j];       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int x, y, sum = 0;     vector<pair<int, int>> v(1e5);     map<int, int> ways;     scanf( %d , &x);     for (int i = 0; i < x; i++) {       scanf( %d , &y);       sum += y;       v[i] = pair<int, int>(y, sum);       if (i != x - 1) ways[sum]++;     }     printf( %d n , ((sum % 2) ? 0 : ways[sum / 2]));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   bool ison[100010];   char temp[100];   int q, t;   int isprime[100010];   int prime[100010];   vector<int> pr[100010];   void preprocess() {     fill(isprime, isprime + 100010, 0);     fill(ison, ison + 100010, false);     fill(prime, prime + 100010, -1);     for (int i = 2; i < 100010; i++) {       if (isprime[i]) {         continue;       }       pr[i].push_back(i);       for (int j = i + i; j < 100010; j += i) {         pr[j].push_back(i);         isprime[j] = i;       }     }   }   void solve1(int a) {     if (ison[a]) {       printf( Already on n );       return;     }     int len = pr[a].size();     int i;     for (i = 0; i < len; i++) {       int val = pr[a][i];       if (prime[val] == -1) {         continue;       } else {         printf( Conflict with %d n , prime[val]);         return;       }     }     for (i = 0; i < len; i++) {       int val = pr[a][i];       prime[val] = a;     }     ison[a] = true;     printf( Success n );   }   void solve2(int b) {     if (!ison[b]) {       printf( Already off n );       return;     }     int len = pr[b].size();     int i, val;     for (i = 0; i < len; i++) {       val = pr[b][i];       prime[val] = -1;     }     ison[b] = false;     printf( Success n );   }   int main() {     scanf( %d%d , &n, &q);     preprocess();     for (int i = 0; i < q; i++) {       scanf( %s , temp);       scanf( %d , &t);       if (temp[0] ==  + ) {         solve1(t);       } else {         solve2(t);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int32_t main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     long long t;     cin >> t;     while (t--) {       long long d, m;       cin >> d >> m;       long long j = 1, ans = 1, sum = 0;       while (sum + j <= d) {         ans = ans * (j + 1) % m;         sum += j;         j *= 2;       }       ans = ans * (d - sum + 1) % m;       ans += m - 1;       ans %= m;       cout << ans <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     int ind = s.size() - 1;     for (int i = 0; i < s.size(); ++i) {       if (s[i] ==  0 ) {         ind = i;         break;       }     }     bool flag = 0;     for (int i = 0; i < s.size(); ++i) {       if (!flag && s[i] ==  0 ) continue;       if (s[i] ==  1 ) flag = 1;       if (flag && i != ind) printf( %c , s[i]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long solve(int n) {     int x = n;     long long cnt = 0, ans = 0;     while (x) {       x = x / 10;       cnt++;     }     ans = n * cnt + cnt - 1;     int k = 1;     for (int i = 0; i < cnt - 1; i++) {       k = k * 10;       ans = ans - k;     }     return ans;   }   int main() {     int n;     long long ans;     scanf( %d , &n);     if (n < 10) {       cout << n;     } else {       cout << solve(n);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline T qmin(const T &a, const T &b) {     return a < b ? a : b;   }   template <typename T>   inline T qmax(const T &a, const T &b) {     return a > b ? a : b;   }   template <typename T>   inline void getmin(T &a, const T &b) {     if (a > b) a = b;   }   template <typename T>   inline void getmax(T &a, const T &b) {     if (a < b) a = b;   }   inline void fileio(string s) {     freopen((s +  .in ).c_str(),  r , stdin);     freopen((s +  .out ).c_str(),  w , stdout);   }   const int inf = (int)1e9 + 7;   const long long linf = (long long)1e17 + 7;   const int N = 2e5 + 7;   struct vec {     long long x, y;     inline vec(const long long &_x = 0, const long long &_y = 0) : x(_x), y(_y) {}     inline vec operator+(const vec &b) { return vec(x + b.x, y + b.y); }     inline vec operator-(const vec &b) { return vec(x - b.x, y - b.y); }     inline long long dot(const vec &b) { return x * b.x + y * b.y; }     inline long long det(const vec &b) { return x * b.y - y * b.x; }   } a[N];   long long val[N];   int n;   double ans = 1e18;   inline void calc() {     for (register int i = (n + 1); i <= (n << 1); ++i) a[i] = a[i - n];     for (register int i = (2); i <= (n << 1); ++i) val[i] = a[i].det(a[i - 1]);     for (register int i = (2); i <= (n << 1); ++i) val[i] += val[i - 1];     int lst = 2;     for (register int i = (1); i <= (n); ++i) {       vec v1 = a[i + 1] - a[i];       long long cur = v1.dot(a[lst] - a[i]), tmp;       double len = (double)((a[i + 1].x - a[i].x) * (a[i + 1].x - a[i].x)) +                    (double)((a[i + 1].y - a[i].y) * (a[i + 1].y - a[i].y));       while (lst < (n << 1) && (tmp = v1.dot(a[lst + 1] - a[i])) >= cur)         cur = tmp, ++lst;       getmin(ans, cur / len * fabs(v1.det(a[lst] - a[i])) -                       fabs(val[lst] - val[i] + a[i].det(a[lst])));     }   }   int main() {     scanf( %d , &n);     for (register int i = (1); i <= (n); ++i) scanf( %lld%lld , &a[i].x, &a[i].y);     ans = 1e18;     calc();     reverse(a + 1, a + n + 1);     calc();     printf( %.10lf n , ans / 2);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int k;     vector<int> A;     for (int i = 0; i < 4; ++i) {       cin >> k;       A.push_back(k);     }     sort(A.begin(), A.end());     if (A[0] + A[1] + A[2] == A[3] or A[0] + A[3] == A[1] + A[2]) {       cout <<  YES ;     } else {       cout <<  NO ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   queue<pair<int, int> > q;   int n, s[3][7005], f[3][7005], k[3], dd[3][7005];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n;     for (int i = 1; i <= 2; i++) {       cin >> k[i];       for (int j = 1; j <= k[i]; j++) cin >> s[i][j];     }     memset(f, 0, sizeof f);     q.push(pair<int, int>(1, 0));     q.push(pair<int, int>(2, 0));     f[1][0] = 1;     f[2][0] = 1;     while (!q.empty()) {       int t = q.front().first;       int u = q.front().second;       q.pop();       if (f[t][u] == 1) {         for (int i = 1; i <= k[3 - t]; i++) {           int v = (u + n - s[3 - t][i]) % n;           if (f[3 - t][v] > 0) continue;           f[3 - t][v] = 2;           q.push(pair<int, int>(3 - t, v));         }       } else {         for (int i = 1; i <= k[3 - t]; i++) {           int v = (u + n - s[3 - t][i]) % n;           if (f[3 - t][v] > 0) continue;           ++dd[3 - t][v];           if (dd[3 - t][v] == k[3 - t]) {             f[3 - t][v] = 1;             q.push(pair<int, int>(3 - t, v));           }         }       }     }     for (int i = 1; i <= 2; i++) {       for (int j = 1; j <= n - 1; j++) {         if (f[i][j] < 1) cout <<  Loop  ;         if (f[i][j] == 1) cout <<  Lose  ;         if (f[i][j] > 1) cout <<  Win  ;       }       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 1e9 + 10;   const double pi = acos(-1.0);   const double eps = 1e-8;   struct node1 {     int y, x1, x2;   } a[5050];   int tp1;   struct node2 {     int x, y1, y2;   } b[5050];   int tp2;   bitset<5050> bs[5050];   int main() {     int n;     tp1 = tp2 = 0;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       int x1, y1, x2, y2;       scanf( %d %d %d %d , &x1, &y1, &x2, &y2);       if (x1 == x2) {         b[++tp2].x = x1;         if (y1 > y2) swap(y1, y2);         b[tp2].y1 = y1;         b[tp2].y2 = y2;       } else {         a[++tp1].y = y1;         if (x1 > x2) swap(x1, x2);         a[tp1].x1 = x1;         a[tp1].x2 = x2;       }     }     if (tp1 > tp2) {       int tp = max(tp1, tp2);       for (int i = 1; i <= tp; i++) {         int tmp = a[i].y;         a[i].y = b[i].x;         b[i].x = tmp;         tmp = a[i].x1;         a[i].x1 = b[i].y1;         b[i].y1 = tmp;         tmp = a[i].x2;         a[i].x2 = b[i].y2;         b[i].y2 = tmp;       }       swap(tp1, tp2);     }     for (int i = 1; i <= tp1; i++) {       for (int j = 1; j <= tp2; j++) {         if (a[i].y >= b[j].y1 && a[i].y <= b[j].y2 && b[j].x >= a[i].x1 &&             b[j].x <= a[i].x2) {           bs[i][j] = 1;         }       }     }     long long ans = 0;     for (int i = 1; i < tp1; i++) {       if (bs[i].count() == 0) continue;       for (int j = i + 1; j <= tp1; j++) {         bitset<5050> bb = bs[i] & bs[j];         int tmp = bb.count();         ans += tmp * (tmp - 1) / 2;       }     }     printf( %I64d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> prime;   int isprime[1000005];   void Find() {     for (int i = 2; i < 1000005; i++) {       if (isprime[i] == 0) {         prime.push_back(i);         for (int j = i * 2; j < 1000005; j += i) isprime[j] = 1;       }     }   }   vector<int> v[1000005];   int dis[1000005];   int from[1000005];   int main() {     int n;     scanf( %d , &n);     vector<int> vv;     for (int i = 2; i <= 1000; i++) {       vv.push_back(i * i);     }     vector<int> ok, ok2;     Find();     for (int i = 1; i <= n; i++) {       int first;       scanf( %d , &first);       for (auto it : vv) {         while (first % it == 0) first /= it;       }       if (first == 1) {         printf( 1 n );         return 0;       }       if (isprime[first] == 0)         ok.push_back(first);       else {         for (int j = 2; j < 1000; j++) {           if (first % j == 0) {             v[first / j].push_back(j);             v[j].push_back(first / j);             break;           }         }         ok2.push_back(first);       }     }     sort(ok.begin(), ok.end());     for (int i = 1; i < ok.size(); i++) {       if (ok[i] == ok[i - 1]) {         printf( 2 n );         return 0;       }     }     sort(ok2.begin(), ok2.end());     for (int i = 1; i < ok.size(); i++) {       if (ok[i] == ok[i - 1]) {         printf( 2 n );         return 0;       }     }     queue<int> q;     memset(dis, -1, sizeof(dis));     for (auto it : ok) {       dis[it] = 0;       q.push(it);     }     int ans = 1e9;     while (!q.empty()) {       int first = q.front();       q.pop();       for (auto it : v[first]) {         if (dis[it] == -1) {           dis[it] = dis[first] + 1;           from[it] = first;           q.push(it);         } else {           if (from[first] == it)             ;           else {             ans = min(ans, dis[it] + dis[first] + 1 + 2);           }         }       }     }     for (auto it : prime) {       if (it > 1000) break;       for (auto it2 : prime) dis[it2] = -1;       dis[it] = 0;       queue<int> q;       q.push(it);       while (!q.empty()) {         int first = q.front();         q.pop();         for (auto it2 : v[first]) {           if (dis[it2] == -1) {             dis[it2] = dis[first] + 1;             from[it2] = first;             q.push(it2);           } else {             if (from[first] == it2)               ;             else {               ans = min(ans, dis[first] + dis[it2] + 1);             }           }         }       }     }     if (ans == 1e9) {       printf( -1 n );     } else {       printf( %d n , ans);     }   }


#include <bits/stdc++.h>   using namespace std;   struct Node {     int l, r;     long long maxi, lzy, maxiwthpre;   };   struct Line {     int l, r, v;     bool operator<(Line L) const { return l < L.l; }   };   int N, M;   Node seg[800050];   long long pre[200005];   Line arr[200005];   void build(int l, int r, int idx) {     seg[idx].l = l;     seg[idx].r = r;     seg[idx].maxi = seg[idx].maxiwthpre = LLONG_MIN >> 2;     if (l == r) {       return;     }     int mid = (l + r) >> 1;     build(l, mid, 2 * idx);     build(mid + 1, r, 2 * idx + 1);   }   void pd(int idx) {     seg[2 * idx].maxi += seg[idx].lzy;     seg[2 * idx].maxiwthpre += seg[idx].lzy;     seg[2 * idx].lzy += seg[idx].lzy;     seg[2 * idx + 1].maxi += seg[idx].lzy;     seg[2 * idx + 1].maxiwthpre += seg[idx].lzy;     seg[2 * idx + 1].lzy += seg[idx].lzy;     seg[idx].lzy = 0;   }   void pu(int idx) {     seg[idx].maxi = max(seg[2 * idx].maxi, seg[2 * idx + 1].maxi);     seg[idx].maxiwthpre =         max(seg[2 * idx].maxiwthpre, seg[2 * idx + 1].maxiwthpre);   }   void add(int l, int r, long long v, int idx) {     if (seg[idx].l == l && seg[idx].r == r) {       seg[idx].lzy += v;       seg[idx].maxi += v;       seg[idx].maxiwthpre += v;       return;     }     int mid = (seg[idx].l + seg[idx].r) >> 1;     if (seg[idx].lzy) {       pd(idx);     }     if (r <= mid) {       add(l, r, v, 2 * idx);     } else if (l > mid) {       add(l, r, v, 2 * idx + 1);     } else {       add(l, mid, v, 2 * idx);       add(mid + 1, r, v, 2 * idx + 1);     }     pu(idx);   }   void setval(int p, long long v, int idx) {     if (seg[idx].l == seg[idx].r) {       seg[idx].maxi = v;       seg[idx].maxiwthpre = v + pre[p];       return;     }     int mid = (seg[idx].l + seg[idx].r) >> 1;     if (seg[idx].lzy) {       pd(idx);     }     if (p <= mid) {       setval(p, v, 2 * idx);     } else {       setval(p, v, 2 * idx + 1);     }     pu(idx);   }   long long query(int l, int r, int withpre, int idx) {     if (seg[idx].l == l && seg[idx].r == r) {       return withpre ? seg[idx].maxiwthpre : seg[idx].maxi;     }     int mid = (seg[idx].l + seg[idx].r) >> 1;     if (seg[idx].lzy) {       pd(idx);     }     if (r <= mid) {       return query(l, r, withpre, 2 * idx);     } else if (l > mid) {       return query(l, r, withpre, 2 * idx + 1);     } else {       return max(query(l, mid, withpre, 2 * idx),                  query(mid + 1, r, withpre, 2 * idx + 1));     }   }   int main() {     cin >> N >> M;     for (int i = 1; i <= N; i++) {       cin >> pre[i];       pre[i] += pre[i - 1];     }     for (int i = 1; i <= M; i++) {       cin >> arr[i].l >> arr[i].r >> arr[i].v;     }     sort(arr + 1, arr + 1 + M);     build(0, 200000, 1);     setval(0, 0, 1);     for (int i = 1; i <= M; i++) {       add(arr[i].r, 200000, arr[i].v, 1);       long long n = query(arr[i].r, arr[i].r, 0, 1);       if (arr[i].l != arr[i].r) {         n = max(n,                 query(arr[i].l, arr[i].r - 1, 1, 1) - pre[arr[i].r] + arr[i].v);       }       n = max(n, query(0, arr[i].l - 1, 0, 1) - pre[arr[i].r] +                      pre[arr[i].l - 1] + arr[i].v);       setval(arr[i].r, n, 1);     }     cout << seg[1].maxi << endl;   }


#include <bits/stdc++.h>   using namespace std;   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     long long ct;     cin >> ct;     while (ct--) {       long long n, k;       cin >> n >> k;       vector<long long> a(n), was(n + 1), s;       long long tmp = 0;       for (long long i = 0; i < (n); ++i) {         cin >> a[i];         if (!was[a[i]]) {           tmp++;           was[a[i]]++;         }       }       if (tmp > k) {         cout <<  -1 n ;       } else {         for (long long i = 1; i < (n + 1); ++i) {           if (tmp < k and !was[i]) {             s.push_back(i);             tmp++;           }           if (was[i]) s.push_back(i);         }         cout << n * s.size() <<   n ;         for (long long i = 0; i < (n); ++i) {           for (long long j = 0; j < (s.size()); ++j) {             cout << s[j] <<    ;           }         }         cout <<   n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   template <typename T, typename U>   ostream& operator<<(ostream& os, const pair<T, U>& _p) {     return os <<  (  << _p.first <<  ,  << _p.second <<  ) ;   }   template <typename T>   ostream& operator<<(ostream& os, const vector<T>& _V) {     bool f = true;     os <<  [ ;     for (auto v : _V) {       os << (f ?    :  , ) << v;       f = false;     }     return os <<  ] ;   }   template <typename T>   ostream& operator<<(ostream& os, const set<T>& _S) {     bool f = true;     os <<  ( ;     for (auto s : _S) {       os << (f ?    :  , ) << s;       f = false;     }     return os <<  ) ;   }   template <typename T, typename U>   ostream& operator<<(ostream& os, const map<T, U>& _M) {     return os << set<pair<T, U>>(_M.begin(), _M.end());   }   const signed long long INF = 1000000100;   const long double EPS = 1e-9;   namespace MCMF {   const int MAXN = 10005;   const int MAXM = 500500;   int nodes, nedge, src, dest;   int point[MAXM], nex[MAXM], flow[MAXM], capa[MAXM], cost[MAXM];   int head[MAXN], dist[MAXN], expand[MAXN], pre[MAXN], edge[MAXN];   bool changed[MAXN];   void init(int n, int s, int t) {     nodes = n;     src = s;     dest = t;     nedge = 0;     for (int(i) = (0); (i) < (nodes); (i)++) head[i] = -1;   }   int add_edge(int u, int v, int c, int w) {     point[nedge] = v, capa[nedge] = c, cost[nedge] = w, flow[nedge] = 0,     nex[nedge] = head[u], head[u] = (nedge++);     point[nedge] = u, capa[nedge] = 0, cost[nedge] = -w, flow[nedge] = 0,     nex[nedge] = head[v], head[v] = (nedge++);     return nedge - 2;   }   pair<int, int> run() {     int mflow = 0, mcost = 0;     while (true) {       for (int(i) = (0); (i) < (nodes); (i)++)         dist[i] = INF, pre[i] = -1, changed[i] = 0;       dist[src] = 0;       changed[src] = 1;       expand[src] = INF;       while (true) {         bool ok = 1;         for (int(i) = (0); (i) < (nodes); (i)++)           if (changed[i]) {             changed[i] = 0;             for (int k = head[i]; k >= 0; k = nex[k]) {               if (flow[k] < capa[k] && dist[i] + cost[k] < dist[point[k]]) {                 dist[point[k]] = dist[i] + cost[k];                 changed[point[k]] = 1;                 pre[point[k]] = i;                 edge[point[k]] = k;                 expand[point[k]] = min(expand[i], capa[k] - flow[k]);                 ok = 0;               }             }           }         if (ok) break;       }       if (pre[dest] < 0) break;       int d = expand[dest];       mflow += d;       mcost += d * dist[dest];       for (int k = dest; k != src; k = pre[k]) {         flow[edge[k]] += d;         flow[edge[k] ^ 1] -= d;       }     }     return make_pair(mflow, mcost);   }   };  // namespace MCMF   int M, N;   const int MAXN = 88;   int A[MAXN][MAXN];   void read_data() {     scanf( %d %d , &M, &N);     for (int(i) = (1); (i) <= (M); (i)++)       for (int(j) = (1); (j) <= (N); (j)++) scanf( %d , &A[i][j]);   }   int encode(int x, int y) { return x + M * (y - 1); }   bool ok(int x, int y) { return 1 <= x and x <= M and 1 <= y and y <= N; }   int dx[] = {-1, 1, 0, 0};   int dy[] = {0, 0, -1, 1};   void solve() {     int S = M * N + 1;     int T = M * N + 2;     MCMF::init(T + 1, S, T);     for (int(x) = (1); (x) <= (M); (x)++)       for (int(y) = (1); (y) <= (N); (y)++) {         if ((x + y) % 2 == 1) {           MCMF::add_edge(S, encode(x, y), 1, 0);           for (int(d) = (0); (d) <= (3); (d)++) {             int nx = x + dx[d];             int ny = y + dy[d];             if (!ok(nx, ny)) continue;             int w = (A[x][y] != A[nx][ny]);             MCMF::add_edge(encode(x, y), encode(nx, ny), 1, w);           }         } else {           MCMF::add_edge(encode(x, y), T, 1, 0);         }       }     cout << MCMF::run().second << endl;   }   int main() {     read_data();     solve();   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, k, ans;     int a[105];     while (cin >> n >> m >> k) {       ans = 1000000;       for (int i = 0; i < n; i++) {         cin >> a[i];       }       m--;       for (int i = 1; m - i >= 0; i++) {         if (a[m - i] <= k && a[m - i]) {           ans = min(ans, i * 10);           break;         }       }       for (int i = 1; m + i < n; i++) {         if (a[m + i] && k >= a[m + i]) {           ans = min(ans, i * 10);           break;         }       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     int x, y, n;     cin >> x >> y >> n;     int k = (n / x) * x + y;     if (k <= n) {       cout << k;     } else {       cout << k - x;     }     cout << endl;   }   int main() {     int test_cases;     cin >> test_cases;     while (test_cases--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   long long pw(long long a, long long b, long long md) {     return (!b ? 1                : (b & 1 ? a * pw(a * a % md, b / 2, md) % md                         : pw(a * a % md, b / 2, md) % md));   }   const long long MOD = 1e9 + 7, MAXN = 1e6 + 10;   bool prime[MAXN];   long long n, ans, p;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     cin >> n;     for (long long i = 0; i < MAXN; i++) prime[i] = true;     for (int p = 2; p * p <= n; p++) {       if (prime[p] == true) {         for (int i = p * 2; i <= n; i += p) prime[i] = false;       }     }     for (long long i = 1; i <= n; i++) {       p = 0;       for (long long j = 2; j <= i; j++) {         if (i % j == 0 && prime[j]) p++;       }       if (p == 2) ans++;     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1000000007;   const int MAX = 1000005;   int SetBit(int n, int x) { return n | (1 << x); }   int ClearBit(int n, int x) { return n & ~(1 << x); }   int ToggleBit(int n, int x) { return n ^ (1 << x); }   bool CheckBit(int n, int x) { return (bool)(n & (1 << x)); }   long long gcd(long long a, long long b) {     if (b == 0)       return a;     else       return gcd(b, a % b);   }   int main(void) {     long long l, r, a, b, x, y, G, L, i, j;     while (scanf( %lld %lld %lld %lld , &l, &r, &a, &b) != EOF) {       vector<int> v;       for (i = 1; i * i <= b; i++) {         if (b % i == 0) {           v.push_back(i);           if (i != b / i) v.push_back(b / i);         }       }       sort(v.begin(), v.end());       int len = v.size();       int ans = 0;       for (i = 0; i < len; i++) {         for (j = 0; j < len; j++) {           x = v[i], y = v[j];           G = gcd(x, y);           L = (x * y) / G;           if (G == a && L == b && x >= l && x <= r && y >= l && y <= r) ++ans;         }       }       printf( %d n , ans);       v.clear();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   static inline void canhazfast() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);   }   template <typename T>   T gcd(T a, T b) {     return b == 0 ? a : gcd(b, a % b);   }   template <typename T>   T extgcd(T a, T b, T &x, T &y) {     T x0 = 1, y0 = 0, x1 = 0, y1 = 1;     while (b) {       T q = a / b;       a %= b;       swap(a, b);       x0 -= q * x1;       swap(x0, x1);       y0 -= q * y1;       swap(y0, y1);     }     x = x0;     y = y0;     return a;   }   static inline int ctz(unsigned x) { return __builtin_ctz(x); }   static inline int ctzll(unsigned long long x) { return __builtin_ctzll(x); }   static inline int clz(unsigned x) { return __builtin_clz(x); }   static inline int clzll(unsigned long long x) { return __builtin_clzll(x); }   static inline int popcnt(unsigned x) { return __builtin_popcount(x); }   static inline int popcntll(unsigned long long x) {     return __builtin_popcountll(x);   }   static inline int bsr(unsigned x) { return 31 ^ clz(x); }   static inline int bsrll(unsigned long long x) { return 63 ^ clzll(x); }   int main() {     canhazfast();     static long long a[200016], x[200016], b[200016];     int n;     long long t, lb;     cin >> n >> t;     for (int i = 1; i <= n; ++i) cin >> a[i];     for (int i = 1; i <= n; ++i) cin >> x[i];     if (x[n] != n) return cout <<  No , 0;     lb = a[n];     b[n] = a[n] + n;     for (int i = n - 1; i > 0; --i) {       b[i] = b[i + 1] - 1;       if (x[i] == i)         b[i] = lb - 1;       else if (x[i] != x[i + 1] || b[i] < lb)         return cout <<  No , 0;       lb = a[i];     }     cout <<  Yes n ;     for (int i = 1; i <= n; ++i) cout << b[i] + t <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) {     if (a % b == 0)       return b;     else       return gcd(b, a % b);   }   void palindrome(string s) {     int i = 0;     int j = s.size() - 1;     while (i < j) {       if (s[i] != s[j]) return;       i++;       j--;     }     cout << s;     exit(0);   }   int recursive(int n, int a[]) {     int x = 1;     if (a[n] != 0) return a[n];     if (n < 10) return n;     while (n != 0) {       if (n % 10 != 0) x = x * (n % 10);       n = n / 10;     }     return recursive(x, a);   }   int myXOR(int x, int y) { return (x | y) & (~x | ~y); }   int main() {     string s;     cin >> s;     int a, b;     if (s.size() >= 2) {       a = s[s.size() - 2] -  0 ;       b = s[s.size() - 1] -  0 ;       a = 10 * a + b;       if (a % 4 == 0)         cout << 4;       else         cout << 0;     }     if (s.size() == 1) {       int x = s[0] -  0 ;       if (x % 4 == 0)         cout << 4;       else         cout << 0;     }   }


#include <bits/stdc++.h>   using namespace std;   int sum(int[][3], int, int);   bool valid(int);   int main() {     int A[3][3];     for (int i = 0; i < 3; ++i)       for (int j = 0; j < 3; ++j) cin >> A[i][j];     for (int i = 0; i < 3; ++i) {       for (int j = 0; j < 3; ++j) cout << !(sum(A, i, j) % 2);       cout <<   n ;     }     return 0;   }   bool valid(int x) { return (x > -1 && x < 3); }   int sum(int A[][3], int i, int j) {     int s = 0, k;     for (k = -1; k < 2; ++k) {       int I = i + k;       if (valid(I)) s += A[I][j];       if (k) {         int J = j + k;         if (valid(J)) s += A[i][J];       }     }     return s;   }


#include <bits/stdc++.h>   using namespace std;   int const mod = 1e9 + 7;   inline void SAFE_ADD(int& a, int b) {     a += b;     if (a >= mod) a -= mod;   }   struct Matr {     vector<vector<int> > _data;     Matr(int sz) : _data(sz, vector<int>(sz, 0)) {}     void ones() {       for (int i = 0; i < _data.size(); ++i) _data[i][i] = 1;     }   };   Matr operator*(Matr const& a, Matr const& b) {     int n = a._data.size();     Matr ans(n);     for (int i = 0; i < n; ++i)       for (int j = 0; j < n; ++j)         for (int k = 0; k < n; ++k) {           SAFE_ADD(ans._data[i][k], a._data[i][j] * 1LL * b._data[j][k] % mod);         }     return ans;   }   inline int getnum(char c) {     if (c >=  a  && c <=  z )       return c -  a ;     else       return 26 + c -  A ;   }   Matr pow(Matr const& a, long long b) {     Matr ans(a._data.size());     ans.ones();     Matr tmp(a);     while (b) {       if (b & 1) ans = ans * tmp;       tmp = tmp * tmp;       b >>= 1;     }     return ans;   }   int main() {     ios_base::sync_with_stdio(false);     long long n;     int m, k;     cin >> n >> m >> k;     if (n == 1) {       cout << m <<   n ;       return 0;     };     Matr a(m);     for (int i = 0; i < m; ++i)       for (int j = 0; j < m; ++j) a._data[i][j] = 1;     for (int i = 0; i < k; ++i) {       string tmp;       cin >> tmp;       a._data[getnum(tmp[0])][getnum(tmp[1])] = 0;     }     a = pow(a, n - 1);     int ans = 0;     for (int i = 0; i < m; ++i)       for (int j = 0; j < m; ++j) SAFE_ADD(ans, a._data[i][j]);     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 100 + 10;   int a[MAX_N];   int main() {     int n, count = 0, f = 0, h = 0, b;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> b;       if (b < 0) count++;       if (count == 3) {         f++;         a[f] = i - h;         h += a[f];         count = 1;       }       if (count < 3 && i == n - 1) {         f++;         a[f] = i + 1 - h;         h += a[f];       }     }     cout << f << endl;     for (int i = 1; i <= f; i++) cout << a[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 100005;   const int maxm = 300005;   int n, m, cnt1, cnt2, ans;   int head[maxn], Head[maxn];   int dis1[maxn], vis1[maxn];   int use1[maxn], use2[maxn];   int num[maxn], ok[maxn];   struct nood {     int nex, to, w;     int fr;   };   nood e[maxm], E[maxm];   inline void jia(int u, int v, int c) {     e[++cnt1].nex = head[u];     e[cnt1].fr = u;     head[u] = cnt1;     e[cnt1].to = v;     e[cnt1].w = c;   }   inline void Jia(int u, int v, int c) {     E[++cnt2].nex = Head[u];     Head[u] = cnt2;     E[cnt2].to = v;     E[cnt2].w = c;   }   inline void dfs(int u) {     use1[u] = 1;     for (int i = head[u]; i; i = e[i].nex) {       int v = e[i].to;       if (use1[v]) continue;       dfs(v);     }   }   inline void Dfs(int u) {     use2[u] = 1;     for (int i = Head[u]; i; i = E[i].nex) {       int v = E[i].to;       if (use2[v]) continue;       Dfs(v);     }   }   inline void spfa(int s) {     queue<int> q;     memset(dis1, 127 / 3, sizeof(dis1));     memset(vis1, 0, sizeof(vis1));     q.push(s), dis1[s] = 0;     num[s] = 1, vis1[s] = 1;     while (!q.empty()) {       int u = q.front();       q.pop();       vis1[u] = 0;       for (int i = Head[u]; i; i = E[i].nex) {         int v = E[i].to;         if (dis1[v] > dis1[u] + E[i].w) {           dis1[v] = dis1[u] + E[i].w;           if (!vis1[v]) {             vis1[v] = 1;             q.push(v);             num[v]++;           }           if (num[v] > n) {             printf( No n );             exit(0);           }         }       }     }   }   inline int read() {     int sum = 0;     char ch = getchar();     while (!isdigit(ch)) ch = getchar();     while (isdigit(ch)) sum = sum * 10 + (ch ^ 48), ch = getchar();     return sum;   }   int main() {     n = read();     m = read();     for (int i = 1; i <= m; i++) {       int u = read();       int v = read();       jia(u, v, 0);       Jia(v, u, 0);     }     dfs(1);     Dfs(n);     for (int i = 1; i <= n; i++)       if (use1[i] && use2[i]) ok[i] = 1;     if (!use1[n]) return printf( No n ), 0;     memset(E, 0, sizeof(E));     memset(Head, 0, sizeof(Head));     cnt2 = 0;     ok[1] = 1, ok[n] = 1;     for (int i = 1; i <= m; i++) {       int u = e[i].fr;       int v = e[i].to;       if (ok[u] && ok[v]) {         Jia(u, v, -1);         Jia(v, u, 2);       }     }     spfa(1);     printf( Yes n );     for (int i = 1; i <= m; i++) {       int u = e[i].fr;       int v = e[i].to;       if (ok[u] && ok[v])         printf( %d n , abs(dis1[u] - dis1[v]));       else         printf( 1 n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 2e5;   vector<int> gr[MAX_N];   int indx(int h, int t) { return h * 450 + t; }   int win = 1e9;   int lose = 0;   bool draw = false;   int used[MAX_N] = {0};   void bfs(int st_indx) {     queue<pair<int, int>> q;     q.push({0, st_indx});     used[st_indx] = 1;     while (!q.empty()) {       auto [d, v] = q.front();       q.pop();       if (v == 0) {         win = min(win, d);       }       for (auto e : gr[v]) {         if (!used[e]) {           used[e] = 1;           q.push({d + 1, e});         }       }     }   }   void dfs(int v) {     used[v] = 1;     for (auto e : gr[v]) {       if (used[e] == 1) {         draw = true;       } else if (!used[e]) {         dfs(e);       }     }     used[v] = 2;   }   int d[MAX_N];   void dij(int st) {     fill(d, d + MAX_N, 1e9);     set<pair<int, int>> s;     d[st] = 0;     s.insert({0, st});     while (!s.empty()) {       int v = s.begin()->second;       if (gr[v].empty()) {         lose = max(lose, -d[v]);       }       s.erase(s.begin());       for (auto e : gr[v]) {         if (d[e] > d[v] - 1) {           s.erase({d[e], e});           d[e] = d[v] - 1;           s.insert({d[e], e});         }       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     int h, t, r, n;     cin >> h >> t >> r >> n;     vector<pair<int, int>> a(n + 1);     for (int i = 1; i <= n; ++i) {       cin >> a[i].first >> a[i].second;     }     int m;     cin >> m;     vector<pair<int, int>> b(m + 1);     for (int i = 1; i <= m; ++i) {       cin >> b[i].first >> b[i].second;     }     for (int h1 = 0; h1 <= r; ++h1) {       for (int t1 = 0; t1 <= r; ++t1) {         if (h1 + t1 > r || !(h1 + t1)) {           continue;         }         for (int chop_h = 1; chop_h <= min(h1, n); ++chop_h) {           int h2 = h1 - chop_h + a[chop_h].first;           int t2 = t1 + a[chop_h].second;           gr[indx(h1, t1)].push_back(indx(h2, t2));         }         for (int chop_t = 1; chop_t <= min(t1, m); ++chop_t) {           int h2 = h1 + b[chop_t].first;           int t2 = t1 - chop_t + b[chop_t].second;           gr[indx(h1, t1)].push_back(indx(h2, t2));         }       }     }     bfs(indx(h, t));     memset(used, 0, sizeof(used));     dfs(indx(h, t));     if (win != 1e9) {       cout <<  Ivan n  << win;     } else if (draw) {       cout <<  Draw ;     } else {       dij(indx(h, t));       cout <<  Zmey n  << lose;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     int a[n];     for (int i = 0; i < n; ++i) cin >> a[i];     m--;     int cnt = 0;     for (int i = 0; i < n; ++i)       if (1) {         bool ok = 0;         for (int j = i + m; j >= 0 && j >= i - m; --j)           if (j >= n)             continue;           else if (a[j] == 1) {             cnt++;             i = j + m;             ok = 1;             break;           }         if (!ok) return cout << -1, 0;       }     cout << cnt;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 250;   int a[N + 5], ans;   double fac[20005];   double POI(int P) {     double ans = 0;     double v = log(P);     for (int i = (int)(1); i <= (int)(N); i++)       if (a[i] < 0)         return -1e300;       else         ans += v * a[i] - P - fac[a[i]];     return ans;   }   double UNI(int P) {     double ans = 0;     double v = log(2 * P + 1);     for (int i = (int)(1); i <= (int)(N); i++)       if (a[i] < 0 || a[i] > 2 * P)         return -1e300;       else         ans -= v;     return ans;   }   void solve() {     double pos = -1e300;     for (int i = (int)(1); i <= (int)(N); i++) scanf( %d , &a[i]);     for (int i = (int)(1); i <= (int)(1000); i++) {       for (int j = (int)(1); j <= (int)(N); j++) ++a[j];       double v1 = POI(i), v2 = UNI(i);       if (v1 > pos) pos = v1, ans = 0;       if (v2 > pos) pos = v2, ans = 1;     }     puts(ans ?  uniform  :  poisson );   }   int main() {     for (int i = (int)(1); i <= (int)(10000); i++) fac[i] = fac[i - 1] + log(i);     int T;     scanf( %d , &T);     while (T--) solve();   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   void gi(T &x) {     int f;     char c;     for (f = 1, c = getchar(); c <  0  || c >  9 ; c = getchar())       if (c ==  - ) f = -1;     for (x = 0; c <=  9  && c >=  0 ; c = getchar()) x = x * 10 + (c & 15);     x *= f;   }   const int N = 4e5 + 10, mod = 998244353;   inline int qm(int x, int k) {     int sum = 1;     for (; k; k >>= 1, x = 1ll * x * x % mod)       if (k & 1) sum = 1ll * sum * x % mod;     return sum;   }   int n, a[20][N], R[N], L = 0;   inline int C(int n, int m) {     if (n < m || n < 0 || m < 0) return 0;     int ret = 1, I = 1;     for (int i = 1; i <= m; i++)       ret = 1ll * ret * (n - i + 1) % mod, I = 1ll * I * i % mod;     return 1ll * ret * qm(I, mod - 2) % mod;   }   inline void NTT(int *A) {     for (int i = 0; i < n; i++)       if (i < R[i]) swap(A[i], A[R[i]]);     for (int i = 1; i < n; i <<= 1) {       int t0 = qm(3, (mod - 1) / (i << 1)), x, y;       for (int j = 0; j < n; j += i << 1) {         int t = 1;         for (int k = 0; k < i; k++, t = 1ll * t * t0 % mod) {           x = A[j + k];           y = 1ll * A[j + k + i] * t % mod;           A[j + k] = (x + y) % mod;           A[j + k + i] = (x - y + mod) % mod;         }       }     }   }   inline void mul(int *A, int *B) {     NTT(A);     NTT(B);     for (int i = 0; i < n; i++) A[i] = 1ll * A[i] * B[i] % mod;     NTT(A);     reverse(A + 1, A + n);     for (int i = 0, t = qm(n, mod - 2); i < n; i++) A[i] = 1ll * A[i] * t % mod;   }   inline void solve(int l, int r, int d) {     if (l == r) {       a[d][0] = l;       a[d][1] = 1;       return;     }     int mid = (l + r) >> 1, m = r - l + 1;     solve(l, mid, d + 1);     for (int i = 0; i <= m; i++) a[d][i] = a[d + 1][i];     solve(mid + 1, r, d + 1);     for (n = 1, L = 0; n <= m; n <<= 1) L++;     for (int i = mid - l + 2; i < n; i++) a[d][i] = 0;     for (int i = r - mid + 1; i < n; i++) a[d + 1][i] = 0;     for (int i = 0; i < n; i++) R[i] = (R[i >> 1] >> 1) | ((i & 1) << (L - 1));     mul(a[d], a[d + 1]);   }   int A, B;   int main() {     cin >> n >> A >> B;     if (n == 1) {       if (A + B - 2 >= 0)         puts( 1 );       else         puts( 0 );       exit(0);     }     solve(0, n - 2, 0);     cout << 1ll * a[0][A + B - 2] * C(A + B - 2, A - 1) % mod;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n, ans = 0, pot;     long long a, b, c, e;     cin >> n;     if (n <= 2) {       cout << n;       return 0;     }     for (long long i = n - 1e3; i <= n; i++) {       a = i;       b = i - 1;       e = a * b;       for (long long j = max(1LL, i - 50); j <= i - 2; j++) {         c = j;         pot = (e * c) / gcd(e, c);         ans = max(ans, pot);       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 100000;   const long long INFLL = 1e15;   int N, Q;   long long a[MAX_N + 1], b[MAX_N + 1];   long long S = 0;   long long zero(long long x) { return (x > 0) ? x : -x; }   struct SEG1 {     struct NODE {       int l, r;       bool b;     };     vector<NODE> seg;     int SZ;     void add() { seg.push_back({-1, -1, false}); }     void Init(int x) {       SZ = x;       add();       init(0, 1, SZ);     }     void init(int idx, int s, int e) {       if (s == e) return;       seg[idx].l = seg.size();       add();       seg[idx].r = seg.size();       add();       init(seg[idx].l, s, (s + e) / 2);       init(seg[idx].r, (s + e) / 2 + 1, e);     }     void Update(int x, bool y) { update(0, 1, SZ, x, y); }     void update(int idx, int s, int e, int x, bool y) {       if (s == e) {         seg[idx].b = y;         return;       }       if (x <= (s + e) / 2) {         update(seg[idx].l, s, (s + e) / 2, x, y);       } else {         update(seg[idx].r, (s + e) / 2 + 1, e, x, y);       }       seg[idx].b = (seg[seg[idx].l].b | seg[seg[idx].r].b);     }     bool Ret(int x, int y) { return ret(0, 1, SZ, x, y); }     bool ret(int idx, int s, int e, int x, int y) {       if (x <= s && e <= y) {         return seg[idx].b;       }       if (x > e || y < s) return false;       return (ret(seg[idx].l, s, (s + e) / 2, x, y) |               ret(seg[idx].r, (s + e) / 2 + 1, e, x, y));     }   } Seg1;   struct SEG2 {     struct NODE {       int l, r;       long long mn;     };     int SZ;     vector<NODE> seg;     void add() { seg.push_back({-1, -1, INFLL}); }     void Init(int x) {       SZ = x;       add();       init(0, 1, SZ);     }     void init(int idx, int s, int e) {       if (s == e) return;       seg[idx].l = seg.size();       add();       seg[idx].r = seg.size();       add();       init(seg[idx].l, s, (s + e) / 2);       init(seg[idx].r, (s + e) / 2 + 1, e);     }     void Update(int x, long long y) { update(0, 1, SZ, x, y); }     void update(int idx, int s, int e, int x, long long y) {       if (s == e) {         seg[idx].mn = y;         return;       }       if (x <= (s + e) / 2) {         update(seg[idx].l, s, (s + e) / 2, x, y);       } else {         update(seg[idx].r, (s + e) / 2 + 1, e, x, y);       }       seg[idx].mn = min(seg[seg[idx].l].mn, seg[seg[idx].r].mn);     }     long long Mn(int x, int y) { return mn(0, 1, SZ, x, y); }     long long mn(int idx, int s, int e, int x, int y) {       if (x <= s && e <= y) return seg[idx].mn;       if (x > e || y < s) return INFLL;       return min(mn(seg[idx].l, s, (s + e) / 2, x, y),                  mn(seg[idx].r, (s + e) / 2 + 1, e, x, y));     }   } Seg2;   void make(int x) {     if (b[x - 1] >= 0 && b[x] <= 0) {       Seg2.Update(x, INFLL);       Seg1.Update(x, true);       return;     }     Seg1.Update(x, false);     if (b[x - 1] < 0 && b[x] > 0) {       Seg2.Update(x, 2LL * b[x] - 2LL * b[x - 1]);       return;     }     if (b[x - 1] >= 0) {       Seg2.Update(x, 2LL * b[x]);     } else {       Seg2.Update(x, -2LL * b[x - 1]);     }   }   int main() {     scanf( %d , &N);     Seg1.Init(N);     Seg2.Init(N);     for (int i = 1; i <= N; i++) {       scanf( %lld , &a[i]);       if (i >= 2) {         b[i - 1] = a[i] - a[i - 1];         S += zero(b[i - 1]);       }     }     for (int i = 2; i < N; i++) {       make(i);     }     scanf( %d , &Q);     for (int i = 1; i <= Q; i++) {       int t, l, r;       long long x;       scanf( %d%d%d%lld , &t, &l, &r, &x);       if (t == 1) {         if (l == r) {           if (l == 1) {             printf( %lld n , S - zero(b[1]) + zero(b[1] - x));           } else if (l == N) {             printf( %lld n , S - zero(b[N - 1]) + zero(b[N - 1] + x));           } else {             printf( %lld n , S - zero(b[l]) - zero(b[l - 1]) + zero(b[l] - x) +                                  zero(b[l - 1] + x));           }         } else if (Seg1.Ret(l, r)) {           printf( %lld n , S + x * 2LL);         } else {           long long mx = 0LL;           long long t = Seg2.Mn(l, r);           mx = max(mx, 2LL * x - t);           if (l == 1) {             mx = max(mx, zero(b[1] - x) - zero(b[1]));           }           if (r == N) {             mx = max(mx, zero(x + b[N - 1]) - zero(b[N - 1]));           }           printf( %lld n , S + mx);         }       } else {         if (l != 1) {           S -= zero(b[l - 1]);           b[l - 1] += x;           S += zero(b[l - 1]);           make(l);           if (l != 2) make(l - 1);         }         if (r != N) {           S -= zero(b[r]);           b[r] -= x;           S += zero(b[r]);           make(r);           if (r != N - 1) make(r + 1);         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int intmax = 0x3f3f3f3f;   const long long lldmax = 0x3f3f3f3f3f3f3f3fll;   double eps = 1e-8;   template <class T>   inline void checkmin(T &a, T b) {     if (b < a) a = b;   }   template <class T>   inline void checkmax(T &a, T b) {     if (b > a) a = b;   }   template <class T>   inline T sqr(T x) {     return x * x;   }   template <class T>   inline T lowbit(T n) {     return (n ^ (n - 1)) & n;   }   template <class T>   inline int countbit(T n) {     return (n == 0) ? 0 : (1 + countbit(n & (n - 1)));   }   template <class T>   inline T checkmod(T n, T m) {     return (n % m + m) % m;   }   template <class T>   inline T gcd(T a, T b) {     if (a < 0) return gcd(-a, b);     if (b < 0) return gcd(a, -b);     return (b == 0) ? a : gcd(b, a % b);   }   template <class T>   inline T euclid(T a, T b, T &x, T &y) {     if (a < 0) {       T d = euclid(-a, b, x, y);       x = -x;       return d;     }     if (b < 0) {       T d = euclid(a, -b, x, y);       y = -y;       return d;     }     if (b == 0) {       x = 1;       y = 0;       return a;     } else {       T d = euclid(b, a % b, x, y);       T t = x;       x = y;       y = t - (a / b) * y;       return d;     }   }   template <class T>   inline int dblcmp(T a, const T b) {     a -= b;     return a > eps ? 1 : (a < -eps ? -1 : 0);   }   template <class T>   inline int sgn(T a) {     return a > eps ? 1 : (a < -eps ? -1 : 0);   }   long long ans[4];   long long x, y;   long long n, m, a, b;   long long dis(long long x1, long long y1, long long x2, long long y2) {     return sqr(x * 2 - x1 - x2) + sqr(y * 2 - y1 - y2);   }   void update(long long x1, long long y1, long long x2, long long y2) {     bool copy = false;     long long tmp[4];     tmp[0] = x1, tmp[1] = y1, tmp[2] = x2, tmp[3] = y2;     if (x1 < 0 || x1 > n) return;     if (x2 < 0 || x2 > n) return;     if (y1 < 0 || y1 > m) return;     if (y2 < 0 || y2 > m) return;     if (x1 > x || x2 < x) return;     if (y1 > y || y2 < y) return;     if (x1 == x2 || y1 == y2) return;     long long dy = y2 - y1, dx = x2 - x1;     long long g = gcd(dy, dx);     dy /= g, dx /= g;     if (dy * a != dx * b) {       return;     }     if (ans[0] == -1) {       copy = true;     } else {       long long da = dis(ans[0], ans[1], ans[2], ans[3]);       long long db = dis(x1, y1, x2, y2);       if (db < da) {         copy = true;       } else if (db == da) {         for (long long i = 0; i < 4; ++i) {           if (tmp[i] < ans[i]) {             copy = true;           }           if (tmp[i] != ans[i]) break;         }       }     }     if (copy) {       for (long long i = 0; i < 4; ++i) ans[i] = tmp[i];     }   }   int main() {     memset(ans, 0xff, sizeof(ans));     cin >> n >> m >> x >> y >> a >> b;     long long g = gcd(a, b);     a /= g;     b /= g;     long long mul = lldmax;     checkmin(mul, n / a);     checkmin(mul, m / b);     a *= mul, b *= mul;     update(0, 0, a, b);     update(0, m - b, a, m);     update(n - a, 0, n, b);     update(n - a, m - b, n, m);     int ta = a / 2, tb = b / 2;     update(x - ta, y - tb, x + a - ta, y + b - tb);     update(0, y - tb, a, y + b - tb);     update(n - a, y - tb, n, y + b - tb);     update(x - ta, 0, x + a - ta, b);     update(x - ta, m - b, x + a - ta, m);     ta++;     update(x - ta, y - tb, x + a - ta, y + b - tb);     update(0, y - tb, a, y + b - tb);     update(n - a, y - tb, n, y + b - tb);     update(x - ta, 0, x + a - ta, b);     update(x - ta, m - b, x + a - ta, m);     tb++;     update(x - ta, y - tb, x + a - ta, y + b - tb);     update(0, y - tb, a, y + b - tb);     update(n - a, y - tb, n, y + b - tb);     update(x - ta, 0, x + a - ta, b);     update(x - ta, m - b, x + a - ta, m);     ta--;     update(x - ta, y - tb, x + a - ta, y + b - tb);     update(0, y - tb, a, y + b - tb);     update(n - a, y - tb, n, y + b - tb);     update(x - ta, 0, x + a - ta, b);     update(x - ta, m - b, x + a - ta, m);     for (int i = 0; i < 4; ++i) {       cout << ans[i] <<    ;     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long fast_expo(long long base, long long exp, long long module) {     long long ans = 1;     while (exp) {       if (exp & 1) ans = (ans * base) % module;       base = (base * base) % module;       exp >>= 1;     }     return ans;   }   bool primes[100001];   void seive() {     memset(primes, true, sizeof(primes));     primes[0] = false;     primes[1] = false;     for (int i = 2; i * i <= 100000; i++) {       if (primes[i]) {         for (int j = i * i; j <= 100000; j += i) primes[j] = false;       }     }   }   bool isprime(int n) {     if (n == 1) return false;     if (n == 2) return true;     if (n % 2 == 0) return false;     for (int i = 3; i * i <= n; i += 2)       if (n % i == 0) return false;     return true;   }   long long gcd(long long a, long long b) {     if (b == 0)       return a;     else       return gcd(b, a % b);   }   long long f[100001];   long long fib(long long n) {     if (n == 0) return 0;     if (n == 1 || n == 2) return (f[n] = 1);     if (f[n]) return f[n];     long long k = (n & 1) ? (n + 1) / 2 : n / 2;     f[n] = (n & 1) ? (fib(k) * fib(k) + fib(k - 1) * fib(k - 1))                    : (2 * fib(k - 1) + fib(k)) * fib(k);     return f[n];   }   int main() {     ios_base::sync_with_stdio(false);     int n;     cin >> n;     int t1 = n % 10;     int t2 = t1;     int cnt1 = 0, cnt2 = 0;     if (t1 == 0) {       cout << n << endl;       return 0;     }     while (t1 <= 10) {       cnt1++;       t1++;     }     while (t2 > 0) {       t2--;       cnt2++;     }     if (cnt1 <= cnt2)       cout << (n + cnt1 - 1) << endl;     else       cout << (n - cnt2) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int MOD = 1000000007;   long long int gcd(long long int a, long long int b) {     if (b == 0)       return a;     else       return gcd(b, a % b);   }   long long int lcm(long long int a, long long int b) {     return a / gcd(a, b) * b;   }   long long int power(long long int a, long long int n) {     if (n == 0) return 1;     long long int p = power(a, n / 2);     p = (p * p) % MOD;     if (n % 2)       return (p * a) % MOD;     else       return p % MOD;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     long long int test = 1;     while (test--) {       long long int n, m, q;       cin >> n >> m >> q;       long long int c = gcd(n, m);       long long int q1 = n / c;       long long int q2 = m / c;       while (q--) {         long long int x1, y1, x2, y2;         cin >> x1 >> y1 >> x2 >> y2;         y1--;         y2--;         long long int secno1, secno2;         if (x1 == 1) {           secno1 = y1 / q1;         } else {           secno1 = y1 / q2;         }         if (x2 == 1) {           secno2 = y2 / q1;         } else {           secno2 = y2 / q2;         }         if (secno1 != secno2) {           cout <<  NO ;         } else {           cout <<  YES ;         }         cout <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     scanf( %d%d , &m, &n);     vector<int> a(n, 0);     for (int i = 0; m > 0; i = (i + 1) % n) {       a[i]++;       m--;     }     for (int i = 0; i < n; i++) printf( %d  , a[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long a, b;   bool used[1000005];   int main() {     cin >> a >> b;     long long max_num = 0, s = 0, max_id;     for (;; max_num++) {       if (s + max_num + 1 > a + b) break;       s += max_num + 1;       max_id = max_num;     }     s = 0;     int cnt = 0;     for (long long i = max_num + 1; i > 1; i--) {       if (s + i - 1 > a) {         used[a - s] = 1;         if (a - s) cnt++;         break;       }       used[i - 1] = 1;       cnt++;       s += i - 1;     }     cout << cnt <<   n ;     for (int i = 1; i <= max_num; i++) {       if (used[i]) {         cout << i <<    ;       }     }     cout <<   n  << max_num - cnt <<   n ;     for (int i = 1; i <= max_num; i++) {       if (!used[i]) {         cout << i <<    ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   char BUF[500010];   int n, m;   int up[500010], down[500010], L[500010], R[500010];   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < n; ++i) {       scanf( %s , &BUF);       for (int j = 0; j < m; ++j) switch (BUF[j]) {           case  1 :             if (j & 1)               R[i] = 1;             else               L[i] = 1;             if (i & 1)               down[j] = 1;             else               up[j] = 1;             break;           case  2 :             if (j & 1)               R[i] = 1;             else               L[i] = 1;             if (i & 1)               up[j] = 1;             else               down[j] = 1;             break;           case  3 :             if (j & 1)               L[i] = 1;             else               R[i] = 1;             if (i & 1)               up[j] = 1;             else               down[j] = 1;             break;           case  4 :             if (j & 1)               L[i] = 1;             else               R[i] = 1;             if (i & 1)               down[j] = 1;             else               up[j] = 1;             break;         }     }     int ans = 1;     for (int i = 0; i < n; ++i) ans = (ans * (2 - L[i] - R[i])) % 1000003;     for (int i = 0; i < m; ++i) ans = (ans * (2 - up[i] - down[i])) % 1000003;     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 11, mod = 1e9 + 7;   const double EPS = 1e-7;   const int INF = 2e9;   const int base = 500;   const int dx[] = {1, -1, 0, 0};   const int dy[] = {0, 0, 1, -1};   int m, t, r, w[333], ans;   bool ct[333 + base + 11];   int main() {     if (fopen( string                 .in ,                r ))       freopen(            string             .in ,            r , stdin),           freopen(                string                 .out ,                w , stdout);     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> m >> t >> r;     for (int i = 1; i <= m; ++i) {       cin >> w[i];     }     for (int i = 1; i <= m; ++i) {       int candles = 0;       for (int j = w[i] - 1; j >= w[i] - t; --j) {         candles += ct[j + base];       }       if (candles < r) {         for (int j = w[i] - 1; j >= w[i] - t; --j) {           if (!ct[j + base] && candles < r) {             ct[j + base] = 1;             ++ans;             ++candles;           }         }         if (candles < r) {           return cout << -1, 0;         }       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   const int MX = 2e5 + 5;   const long long INF = 1e18;   const long double PI = 4 * atan((long double)1);   template <class T>   bool ckmin(T& a, const T& b) {     return a > b ? a = b, 1 : 0;   }   template <class T>   bool ckmax(T& a, const T& b) {     return a < b ? a = b, 1 : 0;   }   set<int> v[26];   string ans;   int visited[26] = {0};   void dfs(int s) {     visited[s] = true;     ans += s +  a ;     for (auto& i : v[s]) {       if (visited[i] == false) dfs(i);     }   }   int main() {     int test;     cin >> test;     while (test--) {       string str;       cin >> str;       for (int i = 0; i < 26; i++) {         visited[i] = 0;         v[i].clear();       }       ans.clear();       int num1 = str.size();       for (int i = 1; i < num1; i++) {         v[str[i] -  a ].insert(str[i - 1] -  a );         v[str[i - 1] -  a ].insert(str[i] -  a );       }       int ok = 0;       for (int i = 0; i < 26; i++) {         if (v[i].size() > 2) {           ok = 1;           break;         }       }       if (ok == 1) {         cout <<  NO  << endl;       } else {         for (int i = 0; i < 26; i++) {           if (visited[i] == 0 && v[i].size() < 2) {             dfs(i);           }         }         bool ok = true;         for (int i = 0; i < 26; i++) {           if (visited[i] == 0) {             ok = false;           }         }         if (ok == false) {           cout <<  NO  << endl;         } else {           cout <<  YES  << endl;           cout << ans << endl;         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   bool win(long long a, long long b) {     if (a < b) swap(a, b);     if (!b) return (false);     if (!win(b, a % b)) return (true);     long long p = a / b;     return (p % (b + 1) % 2 == 0);   }   int main() {     int T;     scanf( %d , &T);     while (T--) {       long long a, b;       scanf( %I64d%I64d , &a, &b);       printf( %s n , win(a, b) ?  First  :  Second );     }     return (0);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     if (n == 1)       cout << 5;     else       cout << 25;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     long long n, m;     cin >> n >> m;     long long on[n + 2];     long long is[n + 1];     int inst[n + 2];     is[0] = 1;     int pval = m;     inst[0] = 0;     for (int i(1); i <= n; i++) {       cin >> inst[i];       if (is[i - 1] == 0) {         is[i] = 1;       } else         is[i] = 0;     }     inst[n + 1] = m;     if (is[n] == 1) {       on[n] = m - inst[n];       pval = inst[n];     } else {       on[n] = 0;       pval = inst[n];     }     for (int i(n - 1); i >= 1; --i) {       if (is[i] == 1) {         on[i] = on[i + 1] + (pval - inst[i]);         pval = inst[i];       } else {         on[i] = on[i + 1];         pval = inst[i];       }     }     on[0] = on[1] + inst[1] - 0;     pval = 0;     on[n + 1] = 0;     long long ans = on[0];     for (int i(0); i <= n; i++) {       if (inst[i + 1] - inst[i] < 2) {         continue;       } else {         long long l, m1, r;         l = on[0] - on[i];         m1 = inst[i + 1] - inst[i] - 1;         r = m - inst[i + 1] - on[i + 1];         ans = max(ans, l + m1 + r);       }     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   long long read() {     long long a = 0, b = getchar(), c = 1;     while (!isdigit(b)) c = b ==  -  ? -1 : 1, b = getchar();     while (isdigit(b)) a = a * 10 + b -  0 , b = getchar();     return a * c;   }   long long n, ans, p[200005];   pair<long long, long long> a[200005];   int main() {     n = read();     for (int i = 1; i <= n; i++) {       a[i].second = read();       p[i] = a[i].second;     }     for (int i = 1; i <= n; i++) a[i].first = read();     sort(a + 1, a + n + 1);     sort(p + 1, p + n + 1);     for (int i = 1; i <= n; i++)       ans += (lower_bound(p + 1, p + n + 1, a[i].second) - p - n + i - 1) *              a[i].second;     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline T abs(T t) {     return t < 0 ? -t : t;   }   const long long modn = 1000000007;   inline long long mod(long long x) { return x % modn; }   const int MAXN = 212345;   int n, m, k;   pair<long long, long long> s[MAXN];   long long d, v, V;   set<pair<long long, long long> > q;   void fail() {     puts( -1 );     exit(0);   }   int main() {     long long res = 0;     scanf( %lld %lld %d , &d, &v, &n);     V = v;     for (int a = 0; a < n; a++) scanf( %lld %lld , &s[a].first, &s[a].second);     sort(s, s + n);     s[n].first = d;     s[n].second = INT_MAX;     int i = 0, j = 0;     long long up = v;     while (i <= n && s[i].first <= v) {       q.insert(pair<long long, long long>(s[i].second, s[i].first));       i++;       ;     }     long long ult = 0;     while (j <= n) {       ;       v -= s[j].first - ult;       if (v < 0) {         ;         fail();       }       if (j == n) break;       pair<long long, long long> top = *q.begin();       swap(top.first, top.second);       while (i <= n && v < V && top == s[j]) {         ;         if (i <= n && v + s[i].first - up <= V) {           res += s[j].second * (s[i].first - up);           v += s[i].first - up;           up = s[i].first;           q.insert(pair<long long, long long>(s[i].second, s[i].first));           i++;         } else if (i <= n) {           res += s[j].second * (V - v);           up += V - v;           v = V;         }         top = *q.begin();         swap(top.first, top.second);       }       ult = s[j].first;       q.erase(pair<long long, long long>(s[j].second, s[j].first));       j++;     }     printf( %lld n , res);   }


#include <bits/stdc++.h>   using namespace std;   long long int GC(long long int a, long long int b) {     if (b == 0)       return a;     else       return GC(b, a % b);   }   long long int inv_gc(long long int a, long long int b) {     return a / GC(a, b) * b;   }   long long int Ceil(long long int a, long long int b) {     return a / b + (a % b != 0);   }   long long int fastModExp(long long int a, long long int b) {     long long int res = 1;     while (b > 0) {       if (b & 1) res = (res * a) % 1000000007;       a = (a * a) % 1000000007;       b = b >> 1;     }     return res;   }   map<int, int> par, rk;   void make_set() {     for (char i =  a ; i <=  z ; i++) {       par[i] = i;       rk[i] = 1;     }   }   int find(char x) {     if (x == par[x]) return x;     char p = find(par[x]);     par[x] = p;     return p;   }   int uni(char x, char y) {     char p1 = find(x);     char p2 = find(y);     if (p1 == p2) return 0;     if (rk[p1] > rk[p2]) {       par[p2] = p1;       rk[p1] += rk[p2];     } else {       par[p1] = p2;       rk[p2] += rk[p1];     }     return 1;   }   map<char, int> mpx;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     make_set();     int n;     vector<string> v;     cin >> n;     string s;     for (int i = 0; i < n; i++) {       cin >> s;       v.push_back(s);       if (s.length() > 1) {         for (int i = 0; i < s.length() - 1; i++) int r = uni(s[i], s[i + 1]);       }     }     for (int i = 0; i < v.size(); i++) {       mpx[find(v[i][0])] = 1;     }     long long int count = 0;     for (auto it = mpx.begin(); it != mpx.end(); it++)       if (it->second == 1) {         count++;       }     cout << count << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 10;   const int P = 998244353;   int T, n;   int ans[N];   vector<int> e[N];   int f[N];   bool dfs(int x, int fa, int y) {     for (auto v : e[x])       if (v != fa && !dfs(v, x, y)) return 0;     if (f[x] % y == 0) {       f[fa]--;       return 1;     }     f[x]--;     if (f[x] % y == 0) return 1;     return 0;   }   int main() {     std::ios::sync_with_stdio(false);     std::cin.tie(nullptr);     cin >> T;     while (T--) {       cin >> n;       for (int i = 1; i <= n; i++) e[i].clear();       for (int i = 1; i < n; i++) {         int u, v;         cin >> u >> v;         e[u].push_back(v);         e[v].push_back(u);       }       if (n == 2) {         cout << 2 <<     << 0 <<   n ;       } else {         int rt = 0;         for (int i = 1; i <= n; i++)           if (((int)e[i].size()) > 1) rt = i;         for (int i = 1; i <= n; i++) ans[i] = 0;         for (int i = 1; i * i <= (n - 1); i++) {           if ((n - 1) % i) continue;           for (int j = 1; j <= n; j++) f[j] = ((int)e[j].size());           if (dfs(rt, 0, i)) ans[i] = 1;           for (int j = 1; j <= n; j++) f[j] = ((int)e[j].size());           if (dfs(rt, 0, (n - 1) / i)) ans[(n - 1) / i] = 1;         }         for (int i = 2; i <= n; i++)           for (int j = i + i; j <= n; j += i)             if (ans[j]) ans[i] = 0;         for (int i = 1; i < n; i++) ans[1] = 2 * ans[1] % P;         for (int i = 2; i <= n; i++) ans[1] = (ans[1] - ans[i] + P) % P;         for (int i = 1; i <= n; i++) cout << ans[i] <<    n [i == n];       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c, d, e, f;     cin >> a >> b >> c >> d >> e >> f;     cout << (a + b + f) * (a + b + f) - b * b - d * d - f * f << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int __gcd(long long int a, long long int b) {     return (a % b) ? __gcd(b, a % b) : b;   }   bool prime(long long int k) {     for (long long int i = 2; i * i <= k; i++)       if (k % i == 0) {         return false;       }     return true;   }   void pdash(int n = 1) {     for (int i = 0; i < n; i++) {       for (int j = 0; j < 30; j++) {         cout <<  - ;       }       cout <<   n ;     }   }   long long int cube_root(long long int a) {     long long int r = 1000000, l = 1;     long long int mid;     while (r - l > 1) {       mid = (r + l) >> 1;       if (mid * mid * mid == a) {         return mid;       } else if (mid * mid * mid > a) {         r = mid;       } else         l = mid;     }     if (l * l * l == a) return l;     if (r * r * r == a) return r;     return -1;   }   void solve() {     int n;     cin >> n;     long long int a, b;     while (n--) {       cin >> a >> b;       long long int c = cube_root(a * b);       if (c != -1 && a % c == 0 && b % c == 0) {         cout <<  Yes n ;       } else         cout <<  No n ;     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t = 1;     while (t--) solve();   }


#include <bits/stdc++.h>   using namespace std;   const int N = 200200;   int n, s[N] = {}, d[N] = {}, top = 0;   long long sum = 0;   int main() {     scanf( %d , &n);     s[++top] = 0;     for (int i = 1, t, x, y; i <= n; ++i) {       scanf( %d , &t);       if (t == 1)         scanf( %d%d , &x, &y), sum += x * y, d[x] += y;       else if (t == 2)         scanf( %d , &x), s[++top] = x, sum += x;       else         d[top - 1] += d[top], sum -= s[top] + d[top], d[top] = 0, --top;       printf( %.12f n , sum * 1.0 / top);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c, n;     cin >> a >> b >> c >> n;     int tot = n - a - b + c;     if (tot <= 0 || a < c || b < c) return 0 * puts( -1 );     cout << tot << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       vector<int> visited(n);       vector<int> a(n);       vector<int> ans(n);       for (int i = 0; i < n; i++) {         cin >> a[i];         a[i]--;       }       for (int i = 0; i < n; i++) {         if (visited[i] == 0) {           vector<int> v;           while (!visited[i]) {             v.push_back(i);             visited[i] = 1;             i = a[i];           }           for (auto x : v) ans[x] = v.size();         }       }       for (int i = 0; i < n; i++) cout << ans[i] <<    ;       cout << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1.0);   const double eps = 1e-8;   const int T = 23;   inline double sqr(double x) { return x * x; }   inline int dcmp(double x) { return fabs(x) <= eps ? 0 : (x > 0 ? 1 : -1); }   int n;   double r, v, s, t;   bool check(double x) {     double len = x;     int tmp = (int)(x / (2.0 * pi * r));     x -= 2.0 * pi * r * tmp;     double delta = x / r;     len -= (t - s);     len /= r;     double y = sqrt(sqr(1 - cos(delta)) + sqr(sin(delta)));     len /= y;     double a = acos(len) - acos((1 - cos(delta)) / y);     if (a - 2.0 * pi >= 0) a -= 2 * pi;     if (a < 0) a += 2.0 * pi;     return dcmp(pi - a) >= 0;   }   int main() {     scanf( %d %lf %lf , &n, &r, &v);     for (int i = 1; i <= n; i++) {       scanf( %lf %lf , &s, &t);       double l = 0.0, r = t - s - eps;       for (int j = 1; j <= T; j++) {         double mid = (l + r) / 2.0;         if (check(mid))           r = mid;         else           l = mid;       }       printf( %.9f n , l / v);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T, typename U>   inline void smin(T &a, const U &b) {     if (a > b) a = b;   }   template <typename T, typename U>   inline void smax(T &a, const U &b) {     if (a < b) a = b;   }   template <class T>   inline void gn(T &first) {     char c, sg = 0;     while (c = getchar(), (c >  9  || c <  0 ) && c !=  - )       ;     for ((c ==  -  ? sg = 1, c = getchar() : 0), first = 0; c >=  0  && c <=  9 ;          c = getchar())       first = (first << 1) + (first << 3) + c -  0 ;     if (sg) first = -first;   }   template <class T1, class T2>   inline void gn(T1 &x1, T2 &x2) {     gn(x1), gn(x2);   }   int power(int a, int b, int m, int ans = 1) {     for (; b; b >>= 1, a = 1LL * a * a % m)       if (b & 1) ans = 1LL * ans * a % m;     return ans;   }   const int mod = 1000000007;   vector<int> adj[111];   int dp[111][50], k;   int tmp[50];   inline void add(int &a, long long b) { a = (a + b) % mod; }   void dfs(int u, int f = 0) {     dp[u][25 + k] = 1;     dp[u][25 - 1] = 1;     for (int v : adj[u]) {       if (v == f) continue;       dfs(v, u);       for (int i = -k; i <= k; i++)         tmp[25 + i] = dp[u][25 + i], dp[u][25 + i] = 0;       for (int i = -k; i <= k; i++)         for (int j = -k; j <= k; j++) {           if (i + j >= 0)             add(dp[u][25 + max(i, j - 1)],                 (long long)tmp[25 + i] * dp[v][25 + j]);           else             add(dp[u][25 + min(i, j - 1)],                 (long long)tmp[25 + i] * dp[v][25 + j]);         }     }   }   int main() {     int n;     cin >> n >> k;     for (int i = 1; i < n; i++) {       int u, v;       gn(u, v);       adj[u].push_back(v);       adj[v].push_back(u);     }     dfs(1);     int ans = 0;     for (int i = 0; i <= k; i++) add(ans, dp[1][25 + i]);     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string c =  abacaba ;   int f(string str) {     int cnt = 0;     for (int i = 0; i < str.size(); i++) {       if (c.size() > str.size() - i) {         break;       }       if (c == str.substr(i, c.size())) cnt++;     }     return cnt;   }   bool f1(string str) {     for (int i = 0; i < str.size(); i++) {       if (str[i] != c[i] && str[i] !=  ? ) return 0;     }     return 1;   }   int main() {     int t;     cin >> t;     while (t--) {       int n;       string s;       cin >> n >> s;       if (f(s) > 1) {         cout <<  No n ;         continue;       }       int cnt = 0;       string ans =   ;       for (int i = 0; i < s.size(); i++) {         if (c.size() > s.size() - i) {           break;         }         if (f1(s.substr(i, c.size()))) {           string temp = s.substr(0, i) + c + s.substr(i + c.size());           if (f(temp) == 1) {             ans = s.substr(0, i) + c + s.substr(i + c.size());             break;           }         }       }       if (ans ==   ) {         cout <<  No n ;       } else {         cout <<  Yes n ;         for (int i = 0; i < ans.size(); i++) {           if (ans[i] ==  ? ) ans[i] =  z ;           cout << ans[i];         }         cout <<   n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   template <typename T, typename U>   std::pair<T, U> operator+(const std::pair<T, U>& l, const std::pair<T, U>& r) {     return {l.first + r.first, l.second + r.second};   }   typedef void (*callback_function)(void);   const long long ZERO = 0LL;   const long long INF64 = 1e18;   const long long INF32 = 1e9;   const long long MOD = 1e9 + 7;   const long double PI = acos(-1.0L);   const long double EPS = static_cast<long double>(1e-9);   inline long long Pow(long long a, long long k) {     long long s = 1;     for (; k; k >>= 1) {       k& 1 ? s = 1LL * s * a % MOD : 0;       a = 1LL * a * a % MOD;     }     return s;   }   const long long N = 1e6 + 7;   void input() {}   void output() {}   void preprocess() {}   void debug() {     if (true) {     }   }   void solve() {     preprocess();     long long n;     cin >> n;     long long a[n];     for (long long i = (0); i < (n); i++) {       cin >> a[i];     }     long long L = 0, R = n - 1, res = 0;     while (L < R) {       while (L < R and a[L] < a[L + 1]) {         L++;       }       while (L < R and a[R] < a[R - 1]) {         R--;       }       if (L == R) {         break;       }       if (a[L] < a[R]) {         long long b = a[L] + 1;         res += b - a[L + 1];         a[L + 1] = b;       } else {         long long b = a[R] + 1;         res += b - a[R - 1];         a[R - 1] = b;       }     }     cout << res << endl;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie();     {       input();       solve();       output();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 998244353;   const int N = 505;   int fac[N], inv_fac[N];   int mod_pow(int b, int p) {     int ans = 1;     while (p) {       if (p & 1) {         ans = (1ll * ans * b) % mod;         p--;       }       b = (1ll * b * b) % mod;       p /= 2;     }     return ans;   }   void calc_fac() {     fac[0] = 1;     inv_fac[0] = 1;     for (int i = 1; i < N; i++) {       fac[i] = (1ll * fac[i - 1] * i) % mod;       inv_fac[i] = mod_pow(fac[i], mod - 2);     }   }   int nCr(int n, int r) {     if (r > n) {       return 0;     }     return 1ll * fac[n] * inv_fac[n - r] % mod * inv_fac[r] % mod;   }   void solve() {     int n, k;     cin >> n >> k;     vector<vector<int>> POW(k + 5, vector<int>(n + 5));     for (int i = 1; i < k + 5; i++) {       POW[i][0] = 1;       for (int j = 1; j < n + 5; j++) {         POW[i][j] = 1ll * POW[i][j - 1] * i % mod;       }     }     vector<vector<int>> dp(n + 5, vector<int>(k + 5));     for (int initial_alive = 2; initial_alive < n + 5; initial_alive++) {       for (int limit = 1; limit < k + 5; limit++) {         if (limit < initial_alive) {           dp[initial_alive][limit] = POW[limit][initial_alive];         } else {           dp[initial_alive][limit] = POW[initial_alive - 1][initial_alive];           for (int alive = 1; alive <= initial_alive; alive++) {             int killed = initial_alive - alive;             dp[initial_alive][limit] =                 (0ll + dp[initial_alive][limit] +                  1ll * dp[alive][limit - (initial_alive - 1)] *                      nCr(initial_alive, killed) % mod *                      POW[initial_alive - 1][killed] % mod) %                 mod;           }         }       }     }     cout << dp[n][k] <<   n ;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     calc_fac();     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1100;   long long x, y;   int n;   int main() {     std::ios::sync_with_stdio(false);     while (cin >> n) {       long long x1, x2, y1, y2;       x1 = y1 = 1000000000;       x2 = y2 = -1000000000;       for (int i = 0; i < n; ++i) {         cin >> x >> y;         if (x < x1) x1 = x;         if (y < y1) y1 = y;         if (x > x2) x2 = x;         if (y > y2) y2 = y;       }       unsigned long long s = max(abs(x2 - x1), abs(y2 - y1));       cout << s * s << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 40;   const int inf = 0x3fffffff;   void read(int &x) {     char ch;     bool flag = 0;     for (ch = getchar(); !isdigit(ch) && ((flag |= (ch ==  - )) || 1);          ch = getchar())       ;     for (x = 0; isdigit(ch); x = (x << 1) + (x << 3) + ch - 48, ch = getchar())       ;     x *= 1 - 2 * flag;   }   char mp[4][105];   int n, m;   bool ans = 1;   bool check(int time, int x, int y) {     y += 2 * time;     if (y >= n || mp[x][y] ==  . ) return true;     return false;   }   int vis[5][105];   void dfs(int x, int y) {     if (vis[x][y]) return;     vis[x][y] = 1;     if (y == n - 1) {       ans = 0;       return;     }     if (!check(y, x, y + 1)) return;     for (int i = x - 1; i <= x + 1; i++) {       if (i < 0 || i >= 3) continue;       if (check(y, i, y + 1) && check(y + 1, i, y + 1)) dfs(i, y + 1);     }   }   int main() {     int t;     read(t);     while (t--) {       ans = 1;       memset(vis, 0, sizeof(vis));       read(n), read(m);       int st = -1;       ans = 1;       for (int i = 0; i < 3; i++) {         cin >> mp[i];         for (int j = 0; j < m; j++) {           if (mp[i][j] ==  s ) {             st = i;           }         }       }       mp[st][0] =  . ;       dfs(st, 0);       if (ans)         puts( NO );       else         puts( YES );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, d, h;   struct edge {     int n1;     int n2;   };   edge vertices[100000];   int main() {     cin >> n >> d >> h;     if (d > 2 * h || (h == 1 && d == 1 && n > 2))       cout <<  -1  << endl;     else {       int idx = 0;       int usedNode = 1;       for (int i = 0; i < h; i++) {         vertices[idx++] = edge{usedNode - 1, usedNode++};       }       if (d > h) {         vertices[idx++] = edge{0, usedNode++};         for (int i = 1; i < (d - h); i++) {           vertices[idx++] = edge{usedNode - 1, usedNode++};         }       }       int start = (h > 1) ? 1 : 0;       for (int i = h + (d - h); i < n - 1; i++) {         vertices[idx++] = edge{start, usedNode++};       }       for (int i = 0; i < n - 1; i++) {         cout << vertices[i].n1 + 1 <<     << vertices[i].n2 + 1 << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   stack<char> st;   string s, ans =   ;   char mn[111111];   long long n;   int main() {     cin >> s;     n = s.size();     mn[n - 1] = s[n - 1];     for (int i = n - 2; i >= 0; i--) {       mn[i] = min(mn[i + 1], s[i]);     }     for (int i = 0; i < n;) {       if (st.empty()) {         st.push(s[i]);         i++;       } else if (st.top() <= mn[i]) {         ans += st.top();         st.pop();       } else {         st.push(s[i]);         i++;       }     }     while (!st.empty()) {       ans += st.top();       st.pop();     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long full, n, k, x, i, ans, a[100001], b[100001];   void f(long long l, long long r, long long d) {     if (l > r) return;     if (l == 0)       ans += r / d + 1;     else       ans += (r / d) - (l - 1) / d;   }   int main() {     cin >> n >> k;     for (i = 1; i <= n / k; i++) {       cin >> a[i];     }     x = 1;     for (i = 1; i < k; i++) x *= 10;     for (i = 1; i <= n / k; i++) {       cin >> b[i];     }     full = 1;     for (i = 1; i <= n / k; i++) {       ans = 0;       f(0, b[i] * x - 1, a[i]);       f((b[i] + 1) * x, 10 * x - 1, a[i]);       full = ans * full % 1000000007;     }     cout << full;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     int n, m;     cin >> n >> m;     bool aOk = true, bOk = true;     vector<vector<int>> a(n, vector<int>(m)), b(n, vector<int>(m));     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         cin >> a[i][j];       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         cin >> b[i][j];         int t1 = a[i][j], t2 = b[i][j];         a[i][j] = min(t1, t2);         b[i][j] = max(t1, t2);         if ((i - 1) >= 0) {           if (b[i][j] <= b[i - 1][j]) bOk = false;           if (a[i][j] <= a[i - 1][j]) aOk = false;         }         if ((j - 1) >= 0) {           if (b[i][j] <= b[i][j - 1]) bOk = false;           if (a[i][j] <= a[i][j - 1]) aOk = false;         }       }     }     if (aOk and bOk)       cout <<  Possible n ;     else       cout <<  Impossible n ;   }


#include <bits/stdc++.h>   using namespace std;   int dp[111111];   int main() {     int n, m;     cin >> n >> m;     vector<int> a;     for (int i = 0; i < n; i++) {       int x;       cin >> x;       a.push_back(x);     }     reverse(a.begin(), a.end());     set<int> b;     for (int i = 0; i < n; i++) {       if (b.find(a[i]) == b.end()) dp[n - i - 1]++;       if (i == n - 1) break;       dp[n - i - 2] = dp[n - i - 1];       b.insert(a[i]);     }     for (int i = 0; i < m; i++) {       int x;       cin >> x;       cout << dp[x - 1] <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long n;     while (scanf( %ld , &n) != EOF) {       int a, b, c1 = 0, c2 = 0, s1 = 0, s2 = 0, i, r;       long x = 100000000;       for (i = 0; i < n; i++) {         scanf( %d%d , &a, &b);         if (a == 0)           c1++;         else           c2++;         if (b == 0)           s1++;         else           s2++;       }       r = c2;       r = r + s1;       if (r < x) x = r;       r = c1;       r = r + s2;       if (r < x) x = r;       r = c2 + s2;       if (r < x) x = r;       r = c1 + s1;       if (r < x) x = r;       printf( %ld n , x);     }     return 0;   }


#include <bits/stdc++.h>   #pragma warning(disable : 4996 4018)   using namespace std;   int n, mod = 1000000007;   long long arr[1001], cost[1001];   int main() {     cin.tie(0);     ios_base::sync_with_stdio(0);     cin >> n;     for (int i = 1; i <= n; i++) cin >> arr[i];     long long ans = 0;     for (int i = 1; i <= n; i++) {       for (int e = arr[i]; e != i; e++) cost[i] = (cost[i] + cost[e]) % mod;       cost[i] = (cost[i] + 2) % mod;       ans = (ans + cost[i]) % mod;     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   pair<double, double> p[100100];   double d[100100];   double dist(pair<double, double> x, pair<double, double> y) {     double val = pow((x.first - y.first) * (x.first - y.first) +                          (x.second - y.second) * (x.second - y.second),                      0.5);     return val;   }   int main() {     pair<double, double> a, b, t;     cin >> a.first >> a.second >> b.first >> b.second >> t.first >> t.second;     int n;     cin >> n;     for (int i = 0; i < n; i++) cin >> p[i].first >> p[i].second;     double ans = 0.0;     for (int i = 0; i < n; i++) {       d[i] = dist(t, p[i]);       ans += d[i];     }     double val = 100000000000000000;     double ma1 = 0, ma2 = 0, mb1 = 0, mb2 = 0;     int ia1 = -1, ia2 = -1, ib1 = -1, ib2 = -1;     for (int i = 0; i < n; i++) {       val = min(val, 2 * ans + dist(a, p[i]) - d[i]);       if (ma2 < d[i] - dist(a, p[i])) ma2 = d[i] - dist(a, p[i]), ia2 = i;       if (ma1 < ma2) swap(ma1, ma2), swap(ia1, ia2);     }     for (int i = 0; i < n; i++) {       val = min(val, 2 * ans + dist(b, p[i]) - d[i]);       if (mb2 < d[i] - dist(b, p[i])) mb2 = d[i] - dist(b, p[i]), ib2 = i;       if (mb1 < mb2) swap(mb1, mb2), swap(ib1, ib2);     }     if (ia1 != ib1 && ia1 != -1 && ib1 != -1) val = min(val, 2 * ans - ma1 - mb1);     if (ia1 != ib2 && ia1 != -1 && ib2 != -1) val = min(val, 2 * ans - ma1 - mb2);     if (ia2 != ib1 && ia2 != -1 && ib1 != -1) val = min(val, 2 * ans - ma2 - mb1);     if (ia2 != ib2 && ia2 != -1 && ib2 != -1) val = min(val, 2 * ans - ma2 - mb2);     printf( %0.14lf , val);   }


#include <bits/stdc++.h>   using namespace std;   int n, p, p1, p2;   char s[201];   int pd(char c) {     if ((c >=  0  && c <=  9 ) || (c >=  A  && c <=  Z ) ||         (c >=  a  && c <=  z ) || (c ==  _ ))       return 1;     return 0;   }   int main() {     cin >> s;     n = strlen(s);     if (n > 70) {       cout <<  NO  << endl;       return 0;     }     while (p < n && s[p] !=  @ ) p++;     if (p == n) {       cout <<  NO  << endl;       return 0;     }     if (p < 1 || p > 16) {       cout <<  NO  << endl;       return 0;     }     for (int i = 0; i < p; i++) {       if (!pd(s[i])) {         cout <<  NO  << endl;         return 0;       }     }     p1 = p + 1;     while (p < n && s[p] !=  / ) p++;     if (p - p1 < 1 || p - p1 > 32) {       cout <<  NO  << endl;       return 0;     }     for (int i = p1; i < p; i++) {       if (s[i] ==  . ) {         if (p2 < 1 || p2 > 16) {           cout <<  NO  << endl;           return 0;         }         p2 = 0;       } else {         if (!pd(s[i])) {           cout <<  NO  << endl;           return 0;         }         p2++;       }     }     if (p2 < 1 || p2 > 16) {       cout <<  NO  << endl;       return 0;     }     if (p < n) {       p2 = 0;       for (int i = p + 1; i < n; i++) {         if (s[i] ==  / ) {           if (p2 < 1 || p2 > 16) {             cout <<  NO  << endl;             return 0;           }           p2 = 0;         } else {           if (!pd(s[i])) {             cout <<  NO  << endl;             return 0;           }           p2++;         }       }       if (p2 < 1 || p2 > 16) {         cout <<  NO  << endl;         return 0;       }     }     cout <<  YES  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long first[60];   void do_it(long long n2, long long k2, long long x) {     if (n2 == 1) {       cout << x + 1;       return;     }     if (n2 == 2) {       if (k2 == 1)         cout << x + 2 <<     << x + 1;       else         cout << x + 1 <<     << x + 2;       return;     }     if (k2 < first[n2 - 1]) {       cout << x + 1 <<    ;       do_it(n2 - 1, k2, x + 1);     } else {       k2 -= first[n2 - 1];       cout << x + 2 <<     << x + 1 <<    ;       do_it(n2 - 2, k2, x + 2);     }   }   long long n, k;   int main() {     first[0] = 1, first[1] = 1;     for (long long i = (2); i < (60); i++) first[i] = first[i - 1] + first[i - 2];     cin >> n >> k;     k--;     do_it(n, k, 0);   }