#include <bits/stdc++.h>   using namespace std;   const int dir[4][2] = {1, 0, 0, 1, -1, 0, 0, -1};   const int N = 1e6 + 10;   const int mod = 1e9 + 7;   const double pi = acos(-1);   const double eps = 1e-8;   const long long INF = 2e10;   template <class T>   void _print(T arg) {     cout << arg <<    ;   }   template <class... Args>   void log(Args... args) {     int arr[] = {(_print(args), 0)...};     cout << endl;   }   long long a[N], b[N];   int n, m, k;   int main() {     ios::sync_with_stdio(0);     cin >> n >> k;     for (int i = 0; i <= n; ++i) {       cin >> a[i];       b[i] = a[i];     }     for (int i = 0; i < n; ++i) {       a[i + 1] += a[i] / 2;       a[i] %= 2;     }     int pos;     for (int i = 0; i <= n; ++i) {       if (a[i]) {         pos = i;         break;       }     }     int res = 0;     long long tmp = 0;     for (int i = n; i >= 0; --i) {       tmp = tmp * 2 + a[i];       if (abs(tmp) > INF) break;       if (i <= pos) {         long long x = abs(tmp - b[i]);         if (i == n & x == 0) continue;         res += (x <= k);       }     }     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename X>   ostream& operator<<(ostream& x, const vector<X>& v) {     for (long long i = 0; i < v.size(); ++i) x << v[i] <<    ;     return x;   }   template <typename X>   ostream& operator<<(ostream& x, const set<X>& v) {     for (auto it : v) x << it <<    ;     return x;   }   template <typename X, typename Y>   ostream& operator<<(ostream& x, const pair<X, Y>& v) {     x << v.ff <<     << v.ss;     return x;   }   template <typename T, typename S>   ostream& operator<<(ostream& os, const unordered_map<T, S>& v) {     for (auto it : v) os << it.first <<  =>  << it.second << endl;     return os;   }   struct pair_hash {     inline std::size_t operator()(         const std::pair<long long, long long>& v) const {       return v.first * 31 + v.second;     }   };   #pragma comment(linker,  /stack:200000000 )   #pragma GCC optimize( O3 )   #pragma GCC optimize( unroll-loops )   #pragma GCC targett( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   const int N = 100005;   ;   int dis[N];   vector<pair<int, int>> dp[N];   bool vis[N];   int dpp[N];   int pth;   int n;   int xx;   int f(int i, int j) {     if (i == n - 1) {       return 0;     }     if (dis[i] + j != pth) {       return -1000000007;     }     if (dpp[i] != -1) {       return dpp[i];     }     dpp[i] = 0;     for (pair<int, int> k : dp[i]) {       dpp[i] = max(dpp[i], k.second + f(k.first, j + 1));     }     return dpp[i];   }   set<pair<pair<int, int>, int>> ans;   void recover(int i, int j) {     if (i == n - 1) {       return;     }     int mx = -1;     int vr = -1;     int ff;     for (pair<int, int> k : dp[i]) {       if (mx <= f(k.first, j + 1) + k.second) {         mx = f(k.first, j + 1) + k.second;         vr = k.first;         ff = k.second ^ 1;       }     }     if (ff == 1)       ans.insert({{min(i, vr), max(i, vr)}, ff});     else       ans.erase({{min(i, vr), max(i, vr)}, ff});     recover(vr, j + 1);   }   int main() {     int m;     cin >> n >> m;     int on = 0;     pair<pair<int, int>, int> ed[m];     for (long long i = 0; i < m; i++) {       int x, y, z;       cin >> x >> y >> z;       --x;       --y;       ed[i] = {{x, y}, z};       on += z;       dp[x].push_back({y, z});       dp[y].push_back({x, z});     }     queue<pair<int, int>> q;     q.push({n - 1, 0});     vis[n - 1] = true;     while (q.size()) {       int dd = q.front().second;       int curr = q.front().first;       q.pop();       dis[curr] = dd;       for (pair<int, int> i : dp[curr]) {         if (!vis[i.first]) {           vis[i.first] = true;           q.push({i.first, dd + 1});         }       }     }     pth = dis[0];     memset(dpp, -1, sizeof dpp);     int xxp = f(0, 0);     cout << on + pth - 2 * dpp[0] << endl;     for (long long i = 0; i < m; i++) {       if (ed[i].second == 1) {         ans.insert({{min(ed[i].first.first, ed[i].first.second),                      max(ed[i].first.first, ed[i].first.second)},                     ed[i].second ^ 1});       }     }     recover(0, 0);     for (auto it = ans.begin(); it != ans.end(); ++it) {       cout << (*it).first.first + 1 <<     << (*it).first.second + 1 <<                << (*it).second << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   long long int d[200060], cost[200060];   long long int m, tank;   vector<pair<int, int>> temp;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int src;     cin >> src >> tank >> m;     d[0] = 0;     cost[0] = 0;     d[m + 1] = src;     cost[m + 1] = 0;     for (int i = 0; i < m; i++) {       pair<int, int> t;       cin >> t.first >> t.second;       temp.push_back(t);     }     sort(temp.begin(), temp.end());     for (int i = 0; i < m; i++) {       d[i + 1] = temp[i].first;       cost[i + 1] = temp[i].second;     }     int current = 0;     long long int fuel = tank;     int toAdd = 1;     auto srt = [](int i, int j) {       pair<int, int> a = make_pair(cost[i], d[i]);       pair<int, int> b = make_pair(cost[j], d[j]);       return a < b;     };     multiset<int, function<bool(int, int)>> stations(srt);     long long int ans = 0;     while (true) {       while (!stations.empty() && d[*stations.begin()] < d[current]) {         stations.erase(stations.begin());       }       while (toAdd <= m + 1 && (d[current] + tank) >= d[toAdd]) {         stations.insert(toAdd);         toAdd++;       }       auto it = stations.begin();       if (it == stations.end()) {         cout << -1;         return 0;       }       int minPricy = *it;       if (cost[minPricy] >= cost[current]) {         long long int fuelNeeded = d[minPricy] - d[current];         ans += max(0ll, (tank - fuel) * cost[current]);         fuel = tank - fuelNeeded;         current = minPricy;         stations.erase(it);       } else {         int check = current + 1;         while (cost[current] <= cost[check]) {           check++;         }         int minPricy = check;         long long int fuelNeeded = d[minPricy] - d[current];         ans += max(0ll, (fuelNeeded - fuel) * cost[current]);         fuel = max(fuel - fuelNeeded, 0ll);         current = minPricy;       }       if (current == m + 1) break;     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int solveA(vector<int> a, vector<int> b) {     int n = (int)((a).size());     vector<int> m(n);     for (int i = (0); i <= ((n)-1); i++) m[b[i]] = i;     for (int i = (0); i <= ((n)-1); i++) a[i] = m[a[i]];     b[0] = a[0];     for (int i = (1); i <= ((n - 1)); i++) b[i] = max(b[i - 1], a[i]);     int res = 0;     for (int i = (0); i <= ((n)-1); i++) res += (a[i] != b[i]);     return res;   }   int solveB(vector<int> a, vector<int> b) {     int res = 0, n = (int)((a).size());     vector<int> used(n + 1, false);     while (a.size() || b.size()) {       if (a.size() && b.size() && a.back() == b.back())         b.pop_back(), a.pop_back();       else if (b.size() && used[b.back()])         b.pop_back();       else if (a.size() && a.back() != b.back()) {         used[a.back()] = true;         a.pop_back();         res++;       }     }     return res;   }   int solve(vector<int> a, vector<int> b) {     int n = (int)((a).size());     vector<int> m(n);     for (int i = (0); i <= ((n)-1); i++) m[b[i]] = i;     for (int i = (0); i <= ((n)-1); i++) a[i] = m[a[i]];     for (int i = (0); i <= ((n - 1) - 1); i++)       if (a[i] > a[i + 1]) {         return n - 1 - i;       }     return 0;   }   int main() {     int n = 100;     scanf( %d , &n);     vector<int> a(n), b(n);     for (int i = (0); i <= ((n)-1); i++) scanf( %d , &a[i]), a[i]--;     for (int i = (0); i <= ((n)-1); i++) scanf( %d , &b[i]), b[i]--;     cout << solve(a, b) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 2e5 + 10, inf = 1e18;   struct SegTree {     long long l[N << 2], r[N << 2];     long long mn[N << 2], tag[N << 2];     inline void push_up(long long i) { mn[i] = min(mn[i << 1], mn[i << 1 | 1]); }     inline void push_down(long long i) {       mn[i << 1] += tag[i];       mn[i << 1 | 1] += tag[i];       tag[i << 1] += tag[i];       tag[i << 1 | 1] += tag[i];       tag[i] = 0;     }     void build(long long i, long long x, long long y) {       l[i] = x;       r[i] = y;       if (x == y) return;       build(i << 1, x, (x + y) >> 1);       build(i << 1 | 1, ((x + y) >> 1) + 1, y);     }     void update(long long i, long long x, long long y, long long k) {       if (l[i] >= x && r[i] <= y) {         mn[i] += k;         tag[i] += k;         return;       }       push_down(i);       if (r[i << 1] >= x) update(i << 1, x, y, k);       if (l[i << 1 | 1] <= y) update(i << 1 | 1, x, y, k);       push_up(i);     }     long long query(long long i, long long x, long long y) {       if (l[i] >= x && r[i] <= y) return mn[i];       push_down(i);       long long ans = inf;       if (r[i << 1] >= x) ans = min(ans, query(i << 1, x, y));       if (l[i << 1 | 1] <= y) ans = min(ans, query(i << 1 | 1, x, y));       push_up(i);       return ans;     }   };   SegTree dis1, dis2;   long long n, m, cnt, u[N << 2], v[N << 2], c[N << 2], f[N], dfn[N], siz[N],       dep[N];   vector<pair<long long, long long> > edge[N];   long long dfs(long long u, long long sum, long long depth) {     cnt++;     dep[u] = depth;     dfn[u] = cnt;     siz[u] = 1;     dis1.update(1, dfn[u], dfn[u], sum);     dis2.update(1, dfn[u], dfn[u], sum + f[u]);     for (long long i = 0; i < edge[u].size(); i++)       siz[u] += dfs(edge[u][i].first, sum + edge[u][i].second, dep[u] + 1);     return siz[u];   }   int main() {     scanf( %lld%lld , &n, &m);     dis1.build(1, 1, n);     dis2.build(1, 1, n);     for (long long i = 1; i <= n - 1; i++) {       scanf( %lld%lld%lld , &u[i], &v[i], &c[i]);       edge[u[i]].push_back(make_pair(v[i], c[i]));     }     for (long long i = n; i <= 2 * n - 2; i++) {       scanf( %lld%lld%lld , &u[i], &v[i], &c[i]);       f[u[i]] = c[i];     }     dfs(1ll, 0ll, 1ll);     while (m--) {       long long op, x, y;       scanf( %lld%lld%lld , &op, &x, &y);       if (op == 1) {         if (x <= n - 1) {           dis1.update(1ll, dfn[v[x]], dfn[v[x]] + siz[v[x]] - 1, y - c[x]);           dis2.update(1ll, dfn[v[x]], dfn[v[x]] + siz[v[x]] - 1, y - c[x]);           c[x] = y;         } else {           dis2.update(1ll, dfn[u[x]], dfn[u[x]], y - f[u[x]]);           f[u[x]] = y;         }       } else {         if (dfn[x] <= dfn[y] && dfn[x] + siz[x] - 1 >= dfn[y]) {           printf( %lld n , dis1.query(1ll, dfn[y], dfn[y]) -                                dis1.query(1ll, dfn[x], dfn[x]));         } else {           printf( %lld n , dis2.query(1ll, dfn[x], dfn[x] + siz[x] - 1) -                                dis1.query(1ll, dfn[x], dfn[x]) +                                dis1.query(1ll, dfn[y], dfn[y]));         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ii = pair<int, int>;   const int MOD(1e9 + 7);   const int MAXN(1e5 + 11);   int n, first, z, a, l;   int main() {     scanf( %d%d%d%d%d , &n, &first, &z, &a, &l);     int ans = 0;     for (int ptr = 0; ptr < n;) {       if (ptr)         ptr += max(0, first - l);       else         ptr += first;       first += a;       first = min(first, z);       ++ans;     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-7;   const int MX = 1111 * 1111 * 2;   int n, m;   const double pi = acos(-1.0);   int len, res[MX], mx;   struct Complex {     double r, i;     Complex(double r = 0, double i = 0) : r(r), i(i){};     Complex operator+(const Complex &rhs) {       return Complex(r + rhs.r, i + rhs.i);     }     Complex operator-(const Complex &rhs) {       return Complex(r - rhs.r, i - rhs.i);     }     Complex operator*(const Complex &rhs) {       return Complex(r * rhs.r - i * rhs.i, i * rhs.r + r * rhs.i);     }   } va[MX], vb[MX], ve[MX], vc[MX];   void rader(Complex F[], int len) {     int j = len >> 1;     for (int i = 1; i < len - 1; ++i) {       if (i < j) swap(F[i], F[j]);       int k = len >> 1;       while (j >= k) {         j -= k;         k >>= 1;       }       if (j < k) j += k;     }   }   void FFT(Complex F[], int len, int t) {     rader(F, len);     for (int h = 2; h <= len; h <<= 1) {       Complex wn(cos(-t * 2 * pi / h), sin(-t * 2 * pi / h));       for (int j = 0; j < len; j += h) {         Complex E(1, 0);         for (int k = j; k < j + h / 2; ++k) {           Complex u = F[k];           Complex v = E * F[k + h / 2];           F[k] = u + v;           F[k + h / 2] = u - v;           E = E * wn;         }       }     }     if (t == -1)       for (int i = 0; i < len; ++i) F[i].r /= len;   }   void Conv(Complex a[], Complex b[], int len) {     FFT(a, len, 1);     FFT(b, len, 1);     for (int i = 0; i < len; ++i) a[i] = a[i] * b[i];     FFT(a, len, -1);     for (int i = 0; i < len; ++i) a[i].r = (a[i].r > 0.5);   }   void init(Complex *a, Complex *b) {     for (int i = 0; i < len; i++) a[i].i = 0, a[i].r = b[i].r;   }   void _init(Complex *a) {     for (int i = 0; i < len; i++) a[i].i = 0;   }   void Out(int a) {     if (a > 9) Out(a / 10);     putchar(a % 10 +  0 );   }   void print(Complex *a) {     for (int i = 0; i < len; i++) printf( %d  , (int)(a[i].r + 0.5));     cout << endl;   }   void gao() {     len = 1;     while (len < mx) len <<= 1;     ve[0].r = 1;     while (m) {       if (m & 1) {         init(vc, va);         Conv(ve, va, len);         _init(ve);         init(va, vc);         if (m == 1) break;       }       init(vb, va);       Conv(va, vb, len);       _init(va);       m >>= 1;     }     for (int i = 0; i < len; ++i) res[i] = ve[i].r + 0.5;     for (int i = 0; i < len; i++)       if (res[i]) Out(i), putchar(   );     cout << endl;   }   int main() {     while (cin >> n >> m) {       int maxn = 0;       for (int i = 0; i < n; i++) {         int x;         scanf( %d , &x);         maxn = max(maxn, x);         va[x].r = 1;         va[x].i = 0;       }       mx = maxn * m + 1;       gao();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 10009;   const int D = 5001;   int n;   vector<vector<pair<int, int>>> hs(N, vector<pair<int, int>>());   vector<vector<pair<int, int>>> vs(N, vector<pair<int, int>>());   vector<vector<int>> ds(N, vector<int>());   class FenwickTree {    public:     FenwickTree(int n) { arr.assign(n + 1, 0); }     int rsq(int a) {       int res = 0;       for (; a; a -= LSOne(a)) {         res += arr[a];       }       return res;     }     int rsq(int a, int b) { return rsq(b) - (a == 1 ? 0 : rsq(a - 1)); }     void update(int a, int c) {       for (; a < arr.size(); a += LSOne(a)) {         arr[a] += c;       }     }       private:     vector<int> arr;     int LSOne(int a) { return ((a) & (-a)); }   };   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n;     for (int i = 0; i < n; ++i) {       int x1, y1, x2, y2;       cin >> x1 >> y1 >> x2 >> y2;       x1 += D;       x2 += D;       y1 += D;       y2 += D;       if (x1 == x2) {         vs[x1].emplace_back(min(y1, y2), max(y1, y2));       } else {         hs[y1].emplace_back(min(x1, x2), max(x1, x2));       }     }     long long res = 0;     for (int i = 1; i < N; ++i)       for (auto h : hs[i]) {         int l = h.first;         int r = h.second;         for (int j = 0; j < N; ++j) ds[j].clear();         FenwickTree ft(N);         for (int x = l; x <= r; ++x)           for (auto v : vs[x]) {             if (v.first <= i && v.second > i) {               ft.update(x, 1);               ds[v.second].push_back(x);             }           }         for (int y = i + 1; y < N; y++) {           for (auto h : hs[y]) {             int s = ft.rsq(h.first, h.second);             res += (s * (s - 1)) / 2ll;           }           for (int v : ds[y]) {             ft.update(v, -1);           }         }       }     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   stack<int> s;   int a[(int)(1e+6) * 5];   bool b[(int)(1e+6) * 5];   int main() {     ios_base::sync_with_stdio(0);     int n, i, t, x;     cin >> n;     for (i = 1; i <= n; i++) cin >> a[i];     cin >> t;     while (t > 0) cin >> x, b[x] = 1, t--;     for (i = n; i > 0; i--) {       x = -1;       if (!s.empty()) x = s.top();       if (x != -1 && !b[i] && a[i] == a[x])         a[x] *= -1, s.pop();       else         s.push(i);     }     if (!s.empty()) {       cout <<  NO ;       return 0;     }     cout <<  YES n ;     for (i = 1; i <= n; i++) cout << a[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 0x3f3f3f3f;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long test;     test = 1;     while (test--) {       int a, b, c, d;       cin >> a >> b >> c >> d;       int misha = max((3 * a) / 10.0, a - (a * c) / 250.0);       int vasya = max((3 * b) / 10.0, b - (b * d) / 250.0);       if (misha == vasya) {         cout <<  Tie  << endl;       } else if (misha > vasya) {         cout <<  Misha  << endl;       } else if (misha < vasya) {         cout <<  Vasya  << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-8;   const double pi = acos(-1.0);   const int inf = 2147483647;   int n, w;   int a[1005];   bool first;   int MIN;   void output(int x) {     if (first)       first = false;     else       printf(   );     if (x == MIN)       x = 0;     else if (x == 0)       x = MIN;     printf( %d , x + 1);   }   int main() {     scanf( %d%d , &n, &w);     int total = 0;     MIN = 0;     for (int i = 0; i < n; i++) {       scanf( %d , &a[i]);       total += a[i];       if (a[MIN] > a[i]) MIN = i;     }     first = true;     if (w >= a[MIN] && w <= total) {       printf( Yes n );       swap(a[0], a[MIN]);       output(0);       total = total - w;       for (int i = 1; i < n && total; i++) {         while (total && a[i]) {           total--;           a[i]--;           output(i);           output(i);         }       }       output(0);       a[0]--;       for (int i = 0; i < n; i++) {         while (a[i]) {           a[i]--;           output(i);           output(i);         }       }       printf(  n );     } else if (w > total || n == 1) {       printf( No n );     } else if (w <= 1) {       printf( No n );     } else {       printf( Yes n );       swap(a[0], a[MIN]);       output(0);       total = total - w;       for (int i = 1; i < n && total; i++) {         int limit = (i == 1 ? 1 : 0);         while (total && a[i] > limit) {           total--;           a[i]--;           output(i);           output(i);         }       }       output(0);       a[0]--;       output(1);       while (a[0] >= w - 1) {         output(0);         output(0);         a[0]--;       }       output(1);       while (a[0]) {         output(0);         output(0);         a[0]--;       }       printf(  n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int a[n], b[n], c = 0, d = 0, e = 0, i;     for (i = 0; i < n; i++) {       cin >> a[i] >> b[i];       if (a[i] > b[i])         c++;       else if (b[i] > a[i])         d++;       else         e++;     }     if (c > d)       cout <<  Mishka  << endl;     else if (d > c)       cout <<  Chris  << endl;     else       cout <<  Friendship is magic!^^  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MM = 600005;   const long long MOD = 1000000007;   double a[MM], sum[MM];   char s[MM];   int main() {     sum[0] = a[0] = 0;     for (int i = 1; i < MM; i++) {       a[i] = a[i - 1] + 1.0 / i;       sum[i] = sum[i - 1] + a[i];     }     scanf( %s , s + 1);     int L = strlen(s + 1);     double ans = 0;     for (int j = 1; j <= L; j++) {       if (s[j] ==  I  || s[j] ==  E  || s[j] ==  A  || s[j] ==  O  ||           s[j] ==  U  || s[j] ==  Y )         ans += (sum[L] - sum[L - j]) - (sum[j - 1]);     }     printf( %.9lf n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, p, out[1010];   struct node {     int v, c;   };   vector<node> e[1010];   int t1[1010], t2[1010], r[1010], k;   void dfs(int i, int fa, int mi) {     if (e[i].size() == 0) {       t1[k] = fa;       t2[k] = i;       r[k] = mi;       k++;       return;     }     mi = min(e[i][0].c, mi);     dfs(e[i][0].v, fa, mi);   }   int main() {     while (cin >> n >> p) {       int u;       node a;       memset(out, 0, sizeof(out));       for (int i = 0; i <= n; i++) e[i].clear();       for (int i = 0; i < p; i++) {         scanf( %d%d%d , &u, &a.v, &a.c);         e[u].push_back(a);         out[u]++;         out[a.v]--;       }       k = 0;       for (int i = 1; i <= n; i++)         if (out[i] == 1) dfs(i, i, 99999999);       printf( %d n , k);       for (int i = 0; i < k; i++) printf( %d %d %d n , t1[i], t2[i], r[i]);     }   }


#include <bits/stdc++.h>   using namespace std;   int read() {     int p = 0, q = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) ch ==  -  ? q = -1 : 0, ch = getchar();     while (ch >=  0  && ch <=  9 ) p = p * 10 + ch -  0 , ch = getchar();     return p * q;   }   long long readll() {     long long p = 0, q = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) ch ==  -  ? q = -1 : 0, ch = getchar();     while (ch >=  0  && ch <=  9 ) p = p * 10 + ch -  0 , ch = getchar();     return p * q;   }   bool cmp(int x, int y) { return x > y; }   int power(long long a, int b) {     long long c = 1;     while (b) {       if (b & 1) c = c * a % 998244353;       a = a * a % 998244353;       b >>= 1;     }     return c;   }   int n, a[300005], pre[300005];   int main() {     n = read();     for (int i = 1; i <= n; i++) a[i] = read();     sort(a + 1, a + 1 + n, cmp);     for (int i = 1; i <= n; i++) pre[i] = (pre[i - 1] + a[i]) % 998244353;     for (int k = 1; k <= n; k++) {       int low = (n - k) / k;       long long ans = 0;       for (int j = 1; j <= low; j++)         ans = (ans + 1ll * (pre[(j + 1) * k] - pre[j * k]) * j) % 998244353;       ans = (ans + 1ll * (pre[n] - pre[low * k + k]) * (low + 1)) % 998244353;       printf( %I64d%s ,              (ans * power(n, 998244353 - 2) % 998244353 + 998244353) % 998244353,              k == n ?   n  :    );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 3e5;   int n, m, head[N], cnt, dep[N], fa[N], pid[N];   long long c[N], val[N];   bool vis[N], use[N];   struct edge {     int to, nxt, id;   } e[N << 1];   void finish() {     cout <<  YES n ;     for (int i = 1; i <= m; ++i) cout << val[i] <<   n ;     exit(0);   }   void dfs(int u) {     vis[u] = 1;     for (int i = head[u]; i; i = e[i].nxt)       if (!vis[e[i].to]) {         fa[e[i].to] = u;         dep[e[i].to] = dep[u] + 1;         pid[e[i].to] = e[i].id;         use[e[i].id] = 1;         dfs(e[i].to);       }     if (u != 1) {       val[pid[u]] = c[u];       c[fa[u]] -= c[u];       c[u] = 0;     }   }   void dfs2(int u) {     for (int i = head[u]; i; i = e[i].nxt)       if (!use[e[i].id] && (dep[e[i].to] - dep[u]) % 2 == 0) {         assert(dep[e[i].to] > dep[u]);         int fh = dep[u] % 2;         long long dlt = c[1] / 2;         if (fh == 1) dlt *= -1;         val[e[i].id] = dlt;         c[u] -= dlt, c[e[i].to] -= dlt;         for (int v = e[i].to; v != 1; v = fa[v]) {           val[pid[v]] += c[v];           c[fa[v]] -= c[v];           c[v] = 0;         }         assert(!c[1]);         finish();       }     for (int i = head[u]; i; i = e[i].nxt)       if (use[e[i].id] && dep[e[i].to] > dep[u]) dfs2(e[i].to);   }   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cin >> n >> m;     for (int i = 1; i <= n; ++i) cin >> c[i];     for (int i = 1; i <= m; ++i) {       int u, v;       cin >> u >> v;       e[++cnt] = (edge){v, head[u], i}, head[u] = cnt;       e[++cnt] = (edge){u, head[v], i}, head[v] = cnt;     }     dfs(1);     if (c[1] % 2 == 0) {       if (c[1])         dfs2(1);       else         finish();     }     cout <<  NO n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void readi(int &x) {     int v = 0, f = 1;     char c = getchar();     while (!isdigit(c) && c !=  - ) c = getchar();     if (c ==  - )       f = -1;     else       v = v * 10 + c -  0 ;     while (isdigit(c = getchar())) v = v * 10 + c -  0 ;     x = v * f;   }   void readll(long long &x) {     long long v = 0ll, f = 1ll;     char c = getchar();     while (!isdigit(c) && c !=  - ) c = getchar();     if (c ==  - )       f = -1;     else       v = v * 10 + c -  0 ;     while (isdigit(c = getchar())) v = v * 10 + c -  0 ;     x = v * f;   }   void readc(char &x) {     char c;     while ((c = getchar()) ==    )       ;     x = c;   }   void writes(string s) { puts(s.c_str()); }   void writeln() { writes(  ); }   void writei(int x) {     if (!x) putchar( 0 );     char a[25];     int top = 0;     while (x) {       a[++top] = (x % 10) +  0 ;       x /= 10;     }     while (top) {       putchar(a[top]);       top--;     }   }   void writell(long long x) {     if (!x) putchar( 0 );     char a[25];     int top = 0;     while (x) {       a[++top] = (x % 10) +  0 ;       x /= 10;     }     while (top) {       putchar(a[top]);       top--;     }   }   inline long long inc(int &x) { return ++x; }   inline long long inc(long long &x) { return ++x; }   inline long long inc(int &x, long long y) { return x += y; }   inline long long inc(long long &x, long long y) { return x += y; }   inline double inc(double &x, double y) { return x += y; }   inline long long dec(int &x) { return --x; }   inline long long dec(long long &x) { return --x; }   inline long long dec(int &x, long long y) { return x -= y; }   inline long long dec(long long &x, long long y) { return x -= y; }   inline double dec(double &x, double y) { return x -= y; }   inline long long mul(int &x) { return x = ((long long)x) * x; }   inline long long mul(long long &x) { return x = x * x; }   inline long long mul(int &x, long long y) { return x *= y; }   inline long long mul(long long &x, long long y) { return x *= y; }   inline double mul(double &x, double y) { return x *= y; }   inline long long divi(int &x) { return x = sqrt(x); }   inline long long divi(long long &x) { return x = sqrt(x); }   inline long long divi(int &x, long long y) { return x /= y; }   inline long long divi(long long &x, long long y) { return x /= y; }   inline double divi(double &x, double y) { return x /= y; }   inline long long mod(int &x, long long y) { return x %= y; }   inline long long mod(long long &x, long long y) { return x %= y; }   int dx[5] = {0, -1, 1, 0, 0}, dy[5] = {0, 0, 0, -1, 1};   string dc =  ^v<> ;   int n, m, i, j, k, dg[2222][2222];   queue<int> qx, qy;   char mp[2222][2222];   vector<pair<int, int> > add(int x, int y, int z) {     int i;     vector<pair<int, int> > ans;     if ((1) <= ((4)))       for (((i)) = (1); ((i)) <= ((4)); ((i))++) {         dg[x + dx[i]][y + dy[i]] += z;         if (dg[x + dx[i]][y + dy[i]] == 1 && mp[x + dx[i]][y + dy[i]] ==  . )           ans.push_back(make_pair(x + dx[i], y + dy[i]));       }     return ans;   }   int main() {     ios_base::sync_with_stdio(false);     ;     cin >> n >> m;     if ((1) <= ((n)))       for (((i)) = (1); ((i)) <= ((n)); ((i))++)         if ((1) <= ((m)))           for (((j)) = (1); ((j)) <= ((m)); ((j))++) cin >> mp[i][j];     if ((1) <= ((n)))       for (((i)) = (1); ((i)) <= ((n)); ((i))++)         if ((1) <= ((m)))           for (((j)) = (1); ((j)) <= ((m)); ((j))++)             if (mp[i][j] ==  . ) add(i, j, 1);     if ((1) <= ((n)))       for (((i)) = (1); ((i)) <= ((n)); ((i))++)         if ((1) <= ((m)))           for (((j)) = (1); ((j)) <= ((m)); ((j))++)             if (mp[i][j] ==  .  && dg[i][j] == 1) {               qx.push(i);               qy.push(j);             }     while (!qx.empty()) {       int x = qx.front(), y = qy.front();       qx.pop();       qy.pop();       if (mp[x][y] !=  . ) continue;       if ((1) <= ((4)))         for (((k)) = (1); ((k)) <= ((4)); ((k))++) {           if (mp[x + dx[k]][y + dy[k]] ==  . ) {             mp[x][y] = dc[(k - 1) ^ 1];             mp[x + dx[k]][y + dy[k]] = dc[(k - 1)];             vector<pair<int, int> > nxt = add(x, y, -1);             for (__typeof((nxt).begin()) it = (nxt).begin(); it != (nxt).end();                  it++) {               if (mp[it->first][it->second] ==  . ) {                 qx.push(it->first);                 qy.push(it->second);               }             }             nxt = add(x + dx[k], y + dy[k], -1);             for (__typeof((nxt).begin()) it = (nxt).begin(); it != (nxt).end();                  it++) {               if (mp[it->first][it->second] ==  . ) {                 qx.push(it->first);                 qy.push(it->second);               }             }             break;           }         }     }     if ((1) <= ((n)))       for (((i)) = (1); ((i)) <= ((n)); ((i))++)         if ((1) <= ((m)))           for (((j)) = (1); ((j)) <= ((m)); ((j))++)             if (mp[i][j] ==  . ) {               cout <<  Not unique ;               return 0;             };     if ((1) <= ((n)))       for (((i)) = (1); ((i)) <= ((n)); ((i))++) {         if ((1) <= ((m)))           for (((j)) = (1); ((j)) <= ((m)); ((j))++) cout << mp[i][j];         cout << endl;       }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<string> split(const string& s, char c) {     vector<string> v;     stringstream ss(s);     string x;     while (getline(ss, x, c)) v.push_back(move(x));     return move(v);   }   void err(vector<string>::iterator it) {}   template <typename T, typename... Args>   void err(vector<string>::iterator it, T a, Args... args) {     cerr << it->substr((*it)[0] ==    , it->length()) <<   =   << a <<   n ;     err(++it, args...);   }   int N, M;   int S[300013];   set<int> flv[300013];   vector<int> adj[300013];   int ans = 1;   int color[300013];   void dfs(int n, int p = 0) {     set<int> s;     int cur = 1;     for (int x : flv[n]) {       if (color[x]) {         s.insert(color[x]);       }     }     for (int x : flv[n]) {       if (!color[x]) {         while (s.count(cur)) cur++;         color[x] = cur++;       }     }     for (int v : adj[n]) {       if (v != p) {         dfs(v, n);       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> N >> M;     for (int i = 1; i <= N; i++) {       cin >> S[i];       ans = max(ans, S[i]);       for (int j = 0; j < S[i]; j++) {         int k;         cin >> k;         flv[i].insert(k);       }     }     for (int i = 1; i < N; i++) {       int u, v;       cin >> u >> v;       adj[u].push_back(v);       adj[v].push_back(u);     }     dfs(1);     cout << ans << endl;     for (int i = 1; i <= M; i++) {       cout << (color[i] ? color[i] : 1) <<    ;     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int q;     unsigned long long int n;     cin >> q;     for (int i = 0; i < q; i++) {       cin >> n;       if (n < 4) {         cout << 4 - n << endl;       } else {         if (n % 2 == 0) {           cout << 0 << endl;         } else {           cout << 1 << endl;         }       }     }   }


#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 N = 1000009;   int a[N], t[N];   int gcd(int a, int b) {     if (b == 0) return a;     return gcd(b, a % b);   }   int A, B, n;   long long memo[N][2][2];   long long solve(int i, bool on, bool first) {     if (i == n) return (first && on) ? 100000000000000000ll : 0ll;     if (!on && t[i] == 2) return 100000000000000000ll;     long long &r = memo[i][on][first];     if (r != -1) return r;     if (on)       r = min(solve(i, false, first), solve(i + 1, true, first) + A);     else       r = solve(i + 1, false, first) + (t[i] == 1 ? B : 0ll);     return r;   }   void add_ps(set<int> &p, int x) {     for (int i = 2; i * i <= x; i++) {       if (!(x % i)) p.insert(i);       while (!(x % i)) x /= i;     }     if (x > 1) p.insert(x);   }   int main() {     int i;     scanf( %d %d %d , &n, &A, &B);     for (i = 0; i < n; i++) scanf( %d , &a[i]);     set<int> p;     for (i = -1; i <= 1; i++) add_ps(p, a[0] + i), add_ps(p, a[n - 1] + i);     long long ans = LLONG_MAX;     for (int x : p) {       for (i = 0; i < n; i++)         if ((a[i] % x) == 0)           t[i] = 0;         else if (!((a[i] + 1) % x) || !((a[i] - 1) % x))           t[i] = 1;         else           t[i] = 2;       memset(memo, -1, sizeof memo);       long long cur = 0;       for (i = 0; i < n; i++) {         ans = min(ans, cur + solve(i, true, !i));         if (t[i] == 1)           cur += B;         else if (t[i] == 2)           break;       }     }     printf( %I64d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   string solve(string s) {     if (s.size() & 1) {       return s;     }     string a = solve(s.substr(0, s.size() / 2));     string b = solve(s.substr(s.size() / 2));     if (a < b) {       return a.append(b);     } else {       return b.append(a);     }   }   int main() {     string s, t;     cin >> s >> t;     cout << (solve(s) == solve(t) ?  YES  :  NO ) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int c[500];   int main() {     string s, t;     int n, i, j, k;     cin >> s >> t;     bool ok = 1;     vector<pair<char, char> > ans;     n = s.length();     vector<char> v(500,  0 );     for (i = 0; i < n; i++) {       if (s[i] == t[i]) {         if (c[s[i]] == -2) ok = 0;         c[s[i]] = -1;         continue;       } else if (c[s[i]] == -1 || c[t[i]] == -1) {         ok = 0;       } else if (!c[s[i]] && !c[t[i]]) {         ans.push_back({s[i], t[i]});         c[s[i]] = -2;         v[s[i]] = t[i];         c[t[i]] = -2;         v[t[i]] = s[i];       } else if (c[s[i]] == -2 && c[t[i]] == -2) {         if (v[s[i]] != t[i] || v[t[i]] != s[i]) ok = 0;       } else         ok = 0;     }     if (!ok) return cout << -1, 0;     cout << ans.size() << endl;     for (i = 0; i < ans.size(); i++) {       cout << ans[i].first <<     << ans[i].second << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     string ans;     cin >> s;     int i = 0;     int j = 0;     while (i < s.size() & j < 3) {       if (j == 0) {         if (s[i] ==  f ) {           ans =  ftp:// ;           i = 3;         } else {           ans =  http:// ;           i = 4;         }         j = 1;       }       if (j == 1) {         int temp = i;         while (s[i + 1] !=  r  || s[i + 2] !=  u ) {           i++;         }         ans += s.substr(temp, i + 1 - temp);         ans +=  .ru ;         i = i + 3;         j = 2;       }       if (j == 2) {         if (s.size() - i) {           ans +=  / ;           ans += s.substr(i, s.size() - i);           i = s.size();         }       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 200100;   const long long OO = 1e18;   const int oo = 2e9;   const int md = 998244353;   set<int> st;   set<int>::iterator ite;   int sto, n, p[N], obr = 1, ans = 0, mul[N], q, psm[N];   bool mrk[N];   int mult(int x, int y) { return (1ll * x * y) % md; }   int sum(int x, int y) {     x += y;     if (x >= md) x -= md;     return x;   }   int sub(int x, int y) {     x -= y;     if (x < 0) x += md;     return x;   }   int binpow(int x, int po) {     int res = 1;     while (po > 0) {       if (po & 1) res = mult(res, x);       x = mult(x, x);       po >>= 1;     }     return res;   }   int calc(int l, int r) {     int up = sub(psm[r - 1], (l - 2 < 0 ? 0 : psm[l - 2]));     up = mult(up, binpow(mul[l - 1], md - 2));     int down = mult(mul[r], binpow(mul[l - 1], md - 2));     return mult(up, binpow(down, md - 2));   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n >> q;     sto = binpow(100, md - 2);     mul[0] = 1;     mrk[1] = 1;     psm[0] = 1;     for (int i = 1; i <= n; i++) {       cin >> p[i];       p[i] = mult(p[i], sto);       mul[i] = mult(mul[i - 1], p[i]);       psm[i] = sum(psm[i - 1], mul[i]);     }     ans = calc(1, n);     st.clear();     st.insert(1);     st.insert(n + 1);     for (; q; q--) {       int ps;       cin >> ps;       if (!mrk[ps]) {         st.insert(ps);         ite = st.find(ps);         int lf = *prev(ite);         int rt = (*next(ite)) - 1;         ans = sub(ans, calc(lf, rt));         ans = sum(ans, calc(lf, ps - 1));         ans = sum(ans, calc(ps, rt));       } else {         ite = st.find(ps);         int lf = *prev(ite);         int rt = (*next(ite)) - 1;         ans = sum(ans, calc(lf, rt));         ans = sub(ans, calc(lf, ps - 1));         ans = sub(ans, calc(ps, rt));         st.erase(ite);       }       mrk[ps] ^= 1;       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long t;     cin >> t;     while (t--) {       long long n, k;       cin >> n >> k;       vector<long long> v(n);       for (long long i = 0; i < n; i++) cin >> v[i];       vector<long long> peaks(n, 0);       for (long long i = 1; i < n - 1; i++) {         if (v[i] > v[i - 1] && v[i] > v[i + 1]) {           peaks[i] = 1;         }       }       for (long long i = 1; i < n; i++) {         peaks[i] = peaks[i] + peaks[i - 1];       }       long long ans = 0;       long long pos = 0;       for (long long l = 0, r = k - 1; r < n; l++, r++) {         if (peaks[r - 1] - peaks[l] > ans) {           ans = peaks[r - 1] - peaks[l];           pos = l;         }       }       cout << ans + 1 <<     << pos + 1 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int size = 508;   int num[size];   int Abs(int x) { return x > 0 ? x : -x; }   int main() {     int n, sum, m, i, x, L, R, c, t, v, up;     cin >> n;     sum = m = 0;     up = 1000000;     for (i = 1; i <= 2 * n - 1; i++) {       cin >> num[i];       if (num[i] < 0) m++;       sum += Abs(num[i]);       if (up > Abs(num[i])) up = Abs(num[i]);     }     if (n & 1) {       cout << sum << endl;       return 0;     }     if (m & 1) {       cout << sum - 2 * up << endl;     } else       cout << sum << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     double a, d;     int n;     cin >> a >> d >> n;     scanf( %lf%lf%d , &a, &d, &n);     for (int i = 0; i < n; i++) {       double temp = fmod((i + 1) * d, 4 * a);       if (temp < a)         printf( %lf %lf n , temp, 0.0);       else if (temp < a * 2)         printf( %lf %lf n , a, temp - a);       else if (temp < a * 3)         printf( %lf %lf n , 3 * a - temp, a);       else         printf( %lf %lf n , 0.0, 4 * a - temp);     }     return 0;   }


#include <bits/stdc++.h>   const int mxn = 105;   const int inf = 505;   int n;   int m;   int ans;   int row[mxn];   int col[mxn];   int mat[mxn][mxn];   inline void calcRow() {     for (int i = 1; i <= n; ++i) {       row[i] = inf;       for (int j = 1; j <= m; ++j)         if (row[i] > mat[i][j]) row[i] = mat[i][j];       for (int j = 1; j <= m; ++j) mat[i][j] -= row[i];       ans += row[i];     }   }   inline void calcCol() {     for (int j = 1; j <= m; ++j) {       col[j] = inf;       for (int i = 1; i <= n; ++i)         if (col[j] > mat[i][j]) col[j] = mat[i][j];       for (int i = 1; i <= n; ++i) mat[i][j] -= col[j];       ans += col[j];     }   }   signed main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= m; ++j) scanf( %d , &mat[i][j]);     if (n <= m)       calcRow(), calcCol();     else       calcCol(), calcRow();     bool flag = true;     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= m; ++j)         if (mat[i][j]) flag = false;     if (flag) {       printf( %d n , ans);       for (int i = 1; i <= n; ++i)         for (int j = 1; j <= row[i]; ++j) printf( row %d n , i);       for (int j = 1; j <= m; ++j)         for (int i = 1; i <= col[j]; ++i) printf( col %d n , j);     } else       puts( -1 );   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1;   const long long MOD = 1;   long long _gcd(long long a, long long b) {     if (b == 0) return a;     return _gcd(b, a % b);   }   long long gcd(long long a, long long b) {     a = abs(a), b = abs(b);     if (a < b) swap(a, b);     return _gcd(a, b);   }   long long qpow(long long a, long long n) {     long long rt = 1;     while (n) {       if (n & 1) rt = (rt * a) % MOD;       a = a * a % MOD;       n >>= 1;     }     return rt;   }   long long factor[MAXN];   long long inv[MAXN];   void cal_factor() {     factor[0] = 1;     for (int u = 1; u < MAXN; u++) {       factor[u] = (factor[u - 1] * u) % MOD;     }   }   void cal_factor_inv() {     inv[0] = 1;     inv[MAXN - 1] = qpow(factor[MAXN - 1], MOD - 2);     for (int u = MAXN - 2; u >= 1; u--) {       inv[u] = inv[u + 1] * (u + 1) % MOD;     }   }   void init_factor() {     cal_factor();     cal_factor_inv();   }   long long C(long long n, long long k) {     if (n < k) return 0;     return factor[n] * qpow(factor[n - k], MOD - 2) % MOD *            qpow(factor[k], MOD - 2) % MOD;   }   void solve() {     int a[6];     for (int u = 0; u < 6; u++) cin >> a[u];     int n;     cin >> n;     vector<pair<int, int>> b;     for (int u = 0; u < n; u++) {       int tb;       cin >> tb;       for (int k = 0; k < 6; k++) {         b.push_back({tb - a[k], u});       }     }     sort(b.begin(), b.end());     int ptr1 = 0, ptr2 = 0;     vector<int> vis(n, 0);     int cnt = 0;     int ans = 2e9;     for (; ptr2 < n * 6; ptr2++) {       if (vis[b[ptr2].second] == 0) cnt++;       vis[b[ptr2].second]++;       while (cnt == n && ptr1 <= ptr2 && vis[b[ptr1].second]) {         ans = min(ans, b[ptr2].first - b[ptr1].first);         vis[b[ptr1].second]--;         if (vis[b[ptr1].second] == 0) cnt--;         ptr1++;       }     }     cout << ans <<   n ;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     solve();   }


#include <bits/stdc++.h>   struct point {     double x, y;   } p, q, u;   double v, vp, r, R, k;   double po, qo, pa, qa, angp, angq, angpq;   point rorate(point a, double ang) {     point c;     c.x = a.x * cos(ang) - a.y * sin(ang);     c.y = a.x * sin(ang) + a.y * cos(ang);     return c;   }   double disp2o(point a) { return a.x * a.x + a.y * a.y; }   double cal(double pq) {     if (pq * pq < po || pq * pq < qo) return pq;     angpq = acos((po + qo - (pq * pq)) / (2 * sqrt(po * qo)));     return k + (angpq - angp - angq) * r;   }   int bi(double t) {     double d, dis, ang;     ang = t * vp / R;     q = rorate(u, ang);     dis = sqrt((p.x - q.x) * (p.x - q.x) + (p.y - q.y) * (p.y - q.y));     d = fabs(p.x * q.y - p.y * q.x) / dis;     if (d < r) dis = cal(dis);     if (dis > v * t + 1e-8) return 1;     if (dis < v * t - 1e-8) return -1;     return 0;   }   int main() {     double lt, rt, mid;     int t;     while (~scanf( %lf%lf%lf , &u.x, &u.y, &vp)) {       scanf( %lf%lf%lf%lf , &p.x, &p.y, &v, &r);       qo = disp2o(u);       R = sqrt(qo);       po = disp2o(p);       angp = acos(r / sqrt(po));       angq = acos(r / R);       k = sqrt(po - (r * r)) + sqrt(qo - (r * r));       lt = 0;       rt = 1e4;       while (rt > lt + 1e-8) {         mid = (rt + lt) / 2;         t = bi(mid);         if (t == 1)           lt = mid;         else if (t == -1)           rt = mid;         else           break;       }       printf( %.10lf n , mid);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, m;   void in() { cin >> n >> m; }   void out() {     int s = 0;     if (n > m) {       cout << n - m;       return;     }     while (n < m) {       s++;       n <<= 1;     }     int diff = n - m;     n >>= 1;     long long x = 2;     long long c = 0;     while (x <= diff && c < s) {       c++;       x *= 2;     }     x /= 2;     while (diff > 0) {       diff -= x;       s++;       while (diff < x) {         x /= 2;       }     }     cout << s;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long t = 1;     while (t--) {       in();       out();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = (int)1e6 + 5;   const int K = 20;   vector<int> P[N];   int s[K];   int t[K];   int L[1 << K];   int R[1 << K];   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     int n, m, k;     cin >> n >> m >> k;     char f;     int c0 = 0, c1 = 0;     for (int i = 0; i < k; i++) {       cin >> f;       s[i] = f -  0 ;       c0 += s[i];     }     for (int i = 0; i < k; i++) {       cin >> f;       t[i] = f -  0 ;       c1 += t[i];     }     for (int i = 0; i <= n; i++) {       for (int j = 0; j < k; j++) P[i].push_back(j);     }     int l, r;     for (int i = 1; i <= n; i++) {       cin >> l >> r;       l--;       r--;       P[i][l] = r;       P[i][r] = l;       vector<int> nw;       for (auto x : P[i]) {         nw.push_back(P[i - 1][x]);       }       P[i] = nw;     }     for (int i = 0; i < (1 << k); i++) {       L[i] = (int)1e9;       R[i] = -1;     }     int mask;     for (int i = 0; i <= n - 1; i++) {       mask = 0;       for (int j = 0; j < k; j++) {         if (s[j]) mask |= (1 << P[i][j]);       }       L[mask] = min(L[mask], i);     }     for (int i = 1; i <= n; i++) {       mask = 0;       for (int j = 0; j < k; j++) {         if (t[j]) mask |= (1 << P[i][j]);       }       R[mask] = max(R[mask], i);     }     int nex;     for (int i = (1 << k) - 1; i >= 0; i--) {       for (int j = 0; j < k; j++) {         if ((i & (1 << j))) continue;         nex = (i | (1 << j));         L[i] = min(L[i], L[nex]);         R[i] = max(R[i], R[nex]);       }     }     int mx = 0;     int fl = 0, fr = n;     for (int i = 0; i < (1 << k); i++) {       if (L[i] == (int)1e9 || R[i] == -1) continue;       if (R[i] - L[i] >= m) {         if (__builtin_popcount(i) > mx) {           mx = __builtin_popcount(i);           fl = L[i], fr = R[i];         }       }     }     cout << k + 2 * mx - c0 - c1 <<   n ;     cout << fl + 1 <<     << fr <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 3e5 + 123, INF = 1e9, mod = 1e9 + 7, N = 2e5 + 123;   struct btr {     map<int, long long> dp;     set<pair<long long, int> > st;     long long mn, add;   };   vector<int> g[maxn];   int n, m;   btr a[maxn];   void Merge(btr &a, btr &b) {     if (a.dp.size() < b.dp.size()) swap(a, b);     long long x = a.add, y = b.add;     a.add += b.mn + y;     b.add += a.mn + x;     for (auto x : b.dp) {       int v = x.first;       long long c = x.second + b.add - a.add;       if (!a.dp.count(v) || a.dp[v] > c) {         a.st.erase({a.dp[v], v});         a.dp[v] = c;         a.st.insert({a.dp[v], v});       }     }     if (!a.st.empty()) a.mn = a.st.begin()->first;   }   void dfs(int v, int p) {     if (!a[v].st.empty()) a[v].mn = a[v].st.begin()->first;     btr tmp;     bool flag = 0;     for (auto to : g[v]) {       if (to == p) continue;       dfs(to, v);       if (!flag)         swap(tmp, a[to]);       else         Merge(tmp, a[to]);       flag = 1;       a[to].dp.clear();       a[to].st.clear();     }     if (flag) {       for (auto x : a[v].dp) {         int u = x.first;         long long c = x.second + tmp.mn;         if (!tmp.dp.count(u) || tmp.dp[u] > c) {           tmp.st.erase({tmp.dp[u], u});           tmp.dp[u] = c;           tmp.st.insert({tmp.dp[u], u});         }       }       swap(a[v], tmp);     }     if (v != 1 && a[v].dp.count(v)) {       a[v].st.erase({a[v].dp[v], v});       a[v].dp.erase(v);       if (!a[v].st.empty()) a[v].mn = a[v].st.begin()->first;     }     if (a[v].st.empty()) {       cerr << v << endl;       printf( -1 );       exit(0);     }   }   int main() {     scanf( %d%d , &n, &m);     if (n == 1) {       printf( 0 );       exit(0);     }     for (int i = 1; i < n; i++) {       int v, u;       scanf( %d%d , &v, &u);       g[v].push_back(u);       g[u].push_back(v);     }     for (int i = 0; i < m; i++) {       int u, v, c;       scanf( %d%d%d , &v, &u, &c);       if (!a[v].dp.count(u) || a[v].dp[u] > c) {         a[v].st.erase({a[v].dp[u], u});         a[v].dp[u] = c;         a[v].st.insert({a[v].dp[u], u});       }     }     dfs(1, 1);     printf( %lld , 0ll + a[1].mn + a[1].add);   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   void read(T &x) {     x = 0;     char ch = getchar();     int f = 1;     while (!isdigit(ch)) {       if (ch ==  - ) f *= -1;       ch = getchar();     };     while (isdigit(ch)) {       x = x * 10 + ch - 48;       ch = getchar();     }     x *= f;   }   int n;   vector<int> tv;   int lst[1310000][26];   bool vis[1310000];   int main() {     read(n);     int tsu = 0;     int cu;     for (int i = 0; i < n * 2; i++) {       read(cu);       tsu += cu;       tv.push_back(cu);     }     sort(tv.begin(), tv.end());     int ans = 1e9, rans[30][2];     int csz = 0;     for (int j = n * 2 - 1; j >= n + 1; j--) csz += tv[j];     for (int j = 0; j <= csz; j++) memset(lst[j], 0, sizeof(lst[j]));     memset(vis, 0, sizeof(vis));     lst[0][0] = 99999;     vis[0] = 1;     int used[100] = {0};     for (int i = 1; i >= 1; i--) {       int sua = 0, sub = 0;       for (int j = 0; j < i; j++) sua += tv[j];       sub += tv[i];       for (int j = n * 2 - 1; j >= i + 1; j--) {         if (used[j]) continue;         used[j] = 1;         int cv = tv[j];         for (int k = csz; k >= cv; k--) {           if (!vis[k - cv]) continue;           for (int l = n; l >= 1; l--) {             if (lst[k - cv][l - 1] != 0 && lst[k][l] == 0) {               lst[k][l] = j;               vis[k] = 1;             }           }         }       }       int cans = 1e9, cbst = 0;       ;       for (int j = 0; j <= csz; j++) {         if (lst[j][n - i]) {           if (max(j + sua + sub, tsu - sua - sub - j + sub + tv[0]) < cans) {             cans = max(j + sua + sub, tsu - sua - sub - j + sub + tv[0]);             cbst = j;           }         }       }       if (cans < ans) {         vector<int> ntv = tv;         ans = cans;         for (int j = 0; j < i; j++) {           rans[j][0] = ntv[j];           ntv[j] = -1;         }         int cp = cbst, cn = n - i;         for (int j = i; j < n; j++) {           rans[j][0] = ntv[lst[cp][cn]];           ntv[lst[cp][cn]] = -1;           cp -= rans[j][0];           cn--;         }         int p = n - 1;         for (int j = 0; j < 2 * n; j++) {           if (ntv[j] != -1) {             rans[p][1] = ntv[j];             p--;           }         }       }     }     for (int i = 0; i < n; i++) cout << rans[i][0] <<    ;     cout << endl;     for (int i = 0; i < n; i++) cout << rans[i][1] <<    ;     cout << endl;     return 0;   }


#include <bits/stdc++.h>   int n;   double p;   double C2(double x) {     if (x < 1) return 0;     return x * (x - 1) / 2;   }   double C3(double x) {     if (x < 2) return 0;     return x * (x - 1) * (x - 2) / 6;   }   int main() {     std::cin >> n >> p;     for (int i = 0; i <= n; i++)       if ([&](int x) {             double an = (double)C2(n - x) * x / C3(n) * (1.0 / 3 + 1.0 / 6) +                         (double)(n - x) * C2(x) / C3(n) + (double)C3(x) / C3(n);             return an >= p;           }(i))         return std::cout << i, 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, st, ed, i, j, ep = 1, h[1005];   long long d[1005][1005], dis[1005];   queue<int> q;   struct node {     int y, ne, v;   } e[1000005];   void add(int a, int b, int v) {     e[ep].y = b;     e[ep].v = v;     e[ep].ne = h[a];     h[a] = ep;     ep++;   }   int main() {     scanf( %d%d , &n, &m);     scanf( %d%d , &st, &ed);     for (i = 1; i <= m; i++) {       int a, b, c;       scanf( %d%d%d , &a, &b, &c);       add(a, b, c);       add(b, a, c);     }     memset(d, 0x3f, sizeof(d));     for (i = 1; i <= n; i++) {       d[i][i] = 0;       q.push(i);       while (!q.empty()) {         int s = q.front();         q.pop();         for (j = h[s]; j; j = e[j].ne) {           if (d[i][s] + e[j].v < d[i][e[j].y]) {             d[i][e[j].y] = d[i][s] + e[j].v;             q.push(e[j].y);           }         }       }     }     memset(h, 0, sizeof(h));     ep = 1;     for (i = 1; i <= n; i++) {       int a, b;       scanf( %d%d , &a, &b);       for (j = 1; j <= n; j++)         if (d[i][j] <= a && i != j) add(i, j, b);     }     memset(dis, 0x3f, sizeof(dis));     dis[st] = 0;     q.push(st);     while (!q.empty()) {       int s = q.front();       q.pop();       for (i = h[s]; i; i = e[i].ne) {         if (dis[s] + e[i].v < dis[e[i].y]) {           dis[e[i].y] = dis[s] + e[i].v;           q.push(e[i].y);         }       }     }     if (dis[ed] < (1LL << 60))       printf( %I64d n , dis[ed]);     else       puts( -1 );   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     int x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x * f;   }   int flag1 = 0, flag2 = 0, flag3 = 0, ff3, flag4 = 0;   int n, a[200000 + 5], x, y;   map<int, bool> mp;   int main() {     n = read();     read();     x = read();     y = read();     for (int i = 1; i <= n; ++i) mp[a[i] = read()] = 1;     for (int i = 1; i <= n; ++i) {       if (mp[a[i] - x]) flag1 = i;       if (mp[a[i] - y]) flag2 = i;       if (mp[a[i] - y + x] && (a[i] - y >= 0 || a[i] + x <= a[n]))         flag3 = i, ff3 = (a[i] - y >= 0) ? a[i] - y : a[i] + x;       ;       if (mp[a[i] - y - x]) flag4 = i;     }     if (flag1 && flag2)       puts( 0 );     else if (flag1 | flag2)       printf( 1 n%d , flag1 ? y : x);     else if (flag3)       printf( 1 n%d , ff3);     else if (flag4)       printf( 1 n%d , a[flag4] - x);     else       printf( 2 n%d %d , x, y);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int r, d;     cin >> r >> d;     int n;     cin >> n;     d = r - d;     int ans = 0;     for (int i = 0; i < n; i++) {       int x, y, rx;       cin >> x >> y >> rx;       long double distance = sqrt(x * x + y * y);       long double temp = (rx);       if (distance - d - temp >= 0) {         if (r - distance - temp >= 0) ans++;       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using lint = long long int;   lint liters(int l, vector<int> &arr) {     lint sum = 0;     for (int k : arr) sum += (lint)(k - l);     return sum;   }   int main() {     int n, m = 1000000010;     lint s;     vector<int> arr;     cin >> n >> s;     arr.resize(n);     for (int i = 0; i < n; i++) {       cin >> arr[i];       m = min(m, arr[i]);     }     if (s > liters(0, arr))       cout << -1 << endl;     else {       int start = 0, end = m;       while (start < end) {         int mid = (start + end) / 2 + 1;         if (s <= liters(mid, arr))           start = mid;         else           end = mid - 1;       }       cout << start << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct node {     int val, lazy, child;     node() {       val = child = 0;       lazy = 1e9 + 7;     }     node(int vval, int llazy, int cchild) {       val = vval;       lazy = llazy;       child = cchild;     }   };   int N, K, Q;   int w, x, y, z;   int arr[100100];   int stree[4 * 100100];   vector<node> tree;   int counter, c1, c2;   int squery(int n, int l, int r, int ql, int qr) {     if (l > qr || r < ql) {       return 1e9 + 7;     } else if (ql <= l && r <= qr) {       return stree[n];     } else {       return min(squery(2 * n, l, (l + r) / 2, ql, qr),                  squery(2 * n + 1, (l + r) / 2 + 1, r, ql, qr));     }   }   void propogate(int n) {     tree[tree[n].child].val = tree[n].lazy;     tree[tree[n].child + 1].val = tree[n].lazy;     tree[tree[n].child].lazy = tree[n].lazy;     tree[tree[n].child + 1].lazy = tree[n].lazy;     tree[n].lazy = 1e9 + 7;   }   void update(int n, int l, int r, int ql, int qr, int q) {     if (tree[n].child == 0) {       tree[n].child = counter;       counter += 2;       tree.push_back(node());       tree.push_back(node());     }     if (tree[n].lazy != 1e9 + 7 && l != r) {       propogate(n);     }     if (l > qr || r < ql) {       if (tree[n].val == 0) {         if ((r - l + 1) >= N) {           tree[n].val = squery(1, 1, N, 1, N);         } else {           c1 = l % N;           c2 = r % N;           if (c1 == 0) {             c1 = N;           }           if (c2 == 0) {             c2 = N;           }           if (c1 <= c2) {             tree[n].val = squery(1, 1, N, c1, c2);           } else {             tree[n].val = min(squery(1, 1, N, c1, N), squery(1, 1, N, 1, c2));           }         }       }       return;     } else if (ql <= l && r <= qr) {       tree[n].val = tree[n].lazy = q;       return;     } else {       update(tree[n].child, l, (l + r) / 2, ql, qr, q);       update(tree[n].child + 1, (l + r) / 2 + 1, r, ql, qr, q);       tree[n].val = min(tree[tree[n].child].val, tree[tree[n].child + 1].val);     }   }   int query(int n, int l, int r, int ql, int qr) {     if (tree[n].child == 0) {       tree[n].child = counter;       counter += 2;       tree.push_back(node());       tree.push_back(node());     }     if (tree[n].val == 0) {       if ((r - l + 1) >= N) {         tree[n].val = squery(1, 1, N, 1, N);       } else {         c1 = l % N;         c2 = r % N;         if (c1 == 0) {           c1 = N;         }         if (c2 == 0) {           c2 = N;         }         if (c1 <= c2) {           tree[n].val = squery(1, 1, N, c1, c2);         } else {           tree[n].val = min(squery(1, 1, N, c1, N), squery(1, 1, N, 1, c2));         }       }     }     if (tree[n].lazy != 1e9 + 7 && l != r) {       propogate(n);     }     if (l > qr || r < ql) {       return 1e9 + 7;     } else if (ql <= l && r <= qr) {       return tree[n].val;     } else {       return min(query(tree[n].child, l, (l + r) / 2, ql, qr),                  query(tree[n].child + 1, (l + r) / 2 + 1, r, ql, qr));     }   }   void buildtree(int n, int l, int r) {     if (l == r) {       stree[n] = arr[l];       return;     } else {       buildtree(2 * n, l, (l + r) / 2);       buildtree(2 * n + 1, (l + r) / 2 + 1, r);       stree[n] = min(stree[2 * n], stree[2 * n + 1]);     }   }   int main() {     cin >> N >> K;     for (int i = 1; i <= N; i++) {       cin >> arr[i];     }     buildtree(1, 1, N);     counter = 1;     tree.push_back(node());     cin >> Q;     for (int i = 0; i < Q; i++) {       cin >> w;       if (w == 1) {         cin >> x >> y >> z;         update(0, 1, N * K, x, y, z);       } else {         cin >> x >> y;         cout << query(0, 1, N * K, x, y) << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   long long bin_pow(long long a, long long b) {     if (b == 0) return 1;     if (b % 2 == 0) {       long long t = bin_pow(a, b / 2);       return t * t % 1000000007;     } else       return a * bin_pow(a, b - 1) % 1000000007;   }   long long t = 1, n, m, k = 0, sum = 0, l = 0, r = 0, x = 0, y = 0, z = 0,             ans = 0, mn = LLONG_MAX, mx = LLONG_MIN;   struct cat {     long long a, b, c;   };   vector<cat> edges;   vector<long long> graph[100000];   long long z1 = 1, color[100000];   void dfs(long long v) {     color[v] = 1;     for (auto u : graph[v]) {       if (color[u] == 1) {         z1 = 0;         return;       }       if (color[u] == 0) dfs(u);     }     color[v] = 2;   }   bool tr(long long x) {     z1 = 1;     for (int i = 0; i < n; i++) graph[i].clear(), color[i] = 0;     for (int i = 0; i < m; i++) {       if (edges[i].c <= x) break;       long long x1 = edges[i].a, y1 = edges[i].b;       graph[x1].push_back(y1);     }     for (int i = 0; i < n; i++) {       if (color[i] == 0) dfs(i);     }     return z1;   }   bool cmp(cat a, cat b) { return a.c > b.c; }   vector<long long> order;   bool used[100000];   void dfs1(long long v) {     used[v] = true;     for (auto u : graph[v]) {       if (used[u]) continue;       dfs1(u);     }     order.push_back(v);   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     string s, s1;     cin >> n >> m;     for (int i = 0; i < m; i++) {       cin >> x >> y >> z;       x--, y--;       cat f;       f.a = x, f.b = y, f.c = z;       edges.push_back(f);     }     vector<cat> c = edges;     ans = -1;     sort(edges.begin(), edges.end(), cmp);     for (long long b = 1e9; b >= 1; b /= 2) {       while (!tr(ans + b)) ans += b;     }     ans++;     cout << ans <<    ;     vector<long long> d;     for (int i = 0; i < n; i++) {       graph[i].clear();     }     for (int i = 0; i < m; i++) {       if (c[i].c <= ans) continue;       graph[c[i].a].push_back(c[i].b);     }     for (int i = 0; i < n; i++) {       if (used[i]) continue;       dfs1(i);     }     reverse(order.begin(), order.end());     vector<long long> pos(n);     for (int i = 0; i < n; i++) {       pos[order[i]] = i;     }     for (int i = 0; i < m; i++) {       if (c[i].c <= ans) {         if (pos[c[i].a] <= pos[c[i].b])           ;         else           d.push_back(i);       }     }     cout << d.size() <<   n ;     for (auto u : d) cout << u + 1 <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 3e5 + 1;   int n, x[N];   char c[N];   vector<pair<int, int>> segs;   long long ans;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> n;     int last = -1;     for (int i = 0; i < n; i++) {       cin >> x[i] >> c[i];       if (c[i] ==  G ) {         segs.emplace_back(last, i);         last = i;       }     }     segs.emplace_back(last, n);     for (auto p : segs) {       int l, r;       tie(l, r) = p;       int res = 0;       vector<int> rs, bs;       for (int i = l + 1; i < r; i++) {         if (c[i] ==  R )           rs.push_back(i);         else           bs.push_back(i);       }       if (l != -1 && r != n) {         res = x[r] - x[l];         if (!rs.empty()) {           int rsub = max(x[rs.front()] - x[l], x[r] - x[rs.back()]);           for (int i = 1; i < rs.size(); i++)             rsub = max(x[rs[i]] - x[rs[i - 1]], rsub);           res += x[r] - x[l] - rsub;         }         if (!bs.empty()) {           int bsub = max(x[bs.front()] - x[l], x[r] - x[bs.back()]);           for (int i = 1; i < bs.size(); i++)             bsub = max(x[bs[i]] - x[bs[i - 1]], bsub);           res += x[r] - x[l] - bsub;         }         if (!rs.empty() && !bs.empty()) res = min(2 * (x[r] - x[l]), res);       } else {         if (l != -1) {           if (!rs.empty()) res += x[rs.front()] - x[l];           if (!bs.empty()) res += x[bs.front()] - x[l];         }         if (r != n) {           if (!rs.empty()) res += x[r] - x[rs.back()];           if (!bs.empty()) res += x[r] - x[bs.back()];         }         res += (!rs.empty() ? x[rs.back()] - x[rs.front()] : 0) +                (!bs.empty() ? x[bs.back()] - x[bs.front()] : 0);       }       ans += res;     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 3000000 + 7;   const int M = 1500 + 7;   const int inf = 1e9 + 7;   const long long linf = 1ll * inf * (inf - 1);   const double pi = acos(-1);   const double eps = 1e-6;   const bool multipleTest = false;   const int mod[2] = {inf, 984723593 + 7};   const int gen[2] = {(rand() % inf) + 1, (rand() % 92473247) + 1};   long long f[2][N];   void init() {     f[0][0] = f[1][0] = 1;     for (int i = 1; i < N; ++i) {       for (int t = 0; t < 2; ++t)         f[t][i] = (long long)f[t][i - 1] * gen[t] % mod[t];     }   }   pair<int, int> val[N];   pair<int, int> getNext(pair<int, int> cur, pair<int, int> nxt, int len) {     int fir = (cur.first * f[0][len] + nxt.first) % mod[0];     int sec = (cur.second * f[1][len] + nxt.second) % mod[1];     return make_pair(fir, sec);   }   pair<int, int> getVal(int u, int v) {     ++u;     ++v;     long long fir = (val[v].first - val[u - 1].first * f[0][v - u + 1]) % mod[0];     if (fir < 0) fir += mod[0];     long long sec =         (val[v].second - val[u - 1].second * f[1][v - u + 1]) % mod[1];     if (sec < 0) sec += mod[1];     return make_pair(fir, sec);   }   int n, k;   string s;   map<pair<int, int>, int> all;   int ans[N];   set<int> has;   void solve() {     init();     cin >> n >> k;     cin >> s;     int m;     cin >> m;     for (int i = 0; i < m; ++i) {       string x;       cin >> x;       pair<int, int> cur = make_pair(0, 0);       for (int j = 0, len = (int)(x).size(); j < len; ++j) {         cur = getNext(cur, make_pair(x[j], x[j] + 2), 1);       }       all[cur] = i + 1;     }     for (int t = 0; t < k; ++t) s += s[t];     val[0] = make_pair(0, 0);     for (int i = 1, len = (int)(s).size(); i <= len; ++i) {       val[i] = getNext(val[i - 1], make_pair(s[i - 1], s[i - 1] + 2), 1);     }     for (int i = 0; i < k; ++i) {       bool ok = true;       int t = 0;       has.clear();       for (int j = i; t < n; j += k) {         pair<int, int> cur = getVal(j, j + k - 1);         if (!all.count(cur) || has.count(all[cur])) {           ok = false;           break;         } else {           ans[t++] = all[cur];           has.insert(ans[t - 1]);         }       }       if (ok) {         puts( YES );         for (int j = 0; j < n; ++j) {           printf( %d  , ans[j]);         }         return;       }     }     puts( NO );   }   int main() {     int Test = 1;     if (multipleTest) {       cin >> Test;     }     for (int i = 0; i < Test; ++i) {       solve();     }   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:512000000 )   using namespace std;   void solve();   void precalc();   clock_t start;   int testNumber = 1;   bool todo = true;   int main() {     start = clock();     int t = 1;     cout.sync_with_stdio(0);     cin.tie(0);     precalc();     cout.precision(10);     cout << fixed;     int testNum = 1;     while (t--) {       solve();       ++testNumber;     }     return 0;   }   template <typename T>   T binpow(T q, T w, T mod) {     if (!w) return 1 % mod;     if (w & 1) return q * 1LL * binpow(q, w - 1, mod) % mod;     return binpow(q * 1LL * q % mod, w / 2, mod);   }   void precalc() {}   template <typename T>   T gcd(T q, T w) {     while (w) {       q %= w;       swap(q, w);     }     return q;   }   template <typename T>   T lcm(T q, T w) {     return q / gcd(q, w) * w;   }   struct SegTree {     const int shift = 1 << 18;     vector<int> tree;     SegTree() { tree.assign(2 * shift, 0); }     int rmq(int l, int r) {       if (l >= r) {         return 0;       }       if (l & 1) {         return tree[l] + rmq(l + 1, r);       }       if (r & 1) {         return tree[r - 1] + rmq(l, r - 1);       }       return rmq(l / 2, r / 2);     }     int get_sum(int l, int r) { return rmq(l + shift, r + shift); }     void update(int v, int val) {       v += shift;       tree[v] = val;       v /= 2;       while (v) {         tree[v] = tree[2 * v] + tree[2 * v + 1];         v /= 2;       }     }   };   void solve() {     int n, k, Q;     vector<int> a(2);     cin >> n >> k >> a[0] >> a[1] >> Q;     vector<int> sums(n, 0);     vector<SegTree> tree(2);     for (int w = 0; w < Q; ++w) {       int type;       cin >> type;       if (type == 1) {         int day, num;         cin >> day >> num;         --day;         sums[day] += num;         for (int i = 0; i < 2; ++i) {           tree[i].update(day, min(sums[day], a[i]));         }       } else {         int l;         cin >> l;         --l;         long long res = (long long)tree[1].get_sum(0, l) +                         (long long)tree[0].get_sum(l + k, n);         cout << res <<   n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const long double eps = 1e-10;   const int maxn = 1000 * 1000 * 1000 + 2;   int n;   int a[3][5 * 100 * 1000 + 2];   long double s, e = maxn;   bool check(long double x) {     long double maxr = -1000000001;     for (int i = 0; i < n; i++) {       if (a[2][i] > 0 &&           (long double)(a[1][i] + (long double)(((long double)x) *                                                 ((long double)a[2][i]))) > maxr)         maxr = (long double)(a[1][i] + (long double)(((long double)x) *                                                      ((long double)a[2][i])));       if (a[2][i] < 0 && maxr != -1000000001 &&           maxr >= (long double)(a[1][i] + (long double)(((long double)x) *                                                         ((long double)a[2][i]))))         return 1;     }     return 0;   }   long double bs(long double x, long double y) {     if (y - x < eps) return x;     long double min = (long double)((x + y) / (long double)2.0);     if (check(min))       return bs(x, min);     else       return bs(min, y);   }   int main() {     cout << fixed << setprecision(12);     cin >> n;     for (int i = 0; i < n; i++) cin >> a[1][i] >> a[2][i];     if (!check(1000 * 1000 * 1000 + 1.0)) {       cout << -1 <<  .00000000000000000000  << endl;       return 0;     }     cout << bs(s, e) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int M = 1000001;   int n, m, k, a[M], ver[M], nex[M], head[M], cnt, fa[M], dp[M], tmp[M], sz[M];   vector<int> v[M];   long long d[M];   void add(int x, int y) {     ver[++cnt] = y, nex[cnt] = head[x], head[x] = cnt;     ver[++cnt] = x, nex[cnt] = head[y], head[y] = cnt;   }   void dfs(int x, int f) {     fa[x] = f;     dp[x] = dp[f] + 1;     for (int i = head[x]; i; i = nex[i]) {       if (ver[i] == f) continue;       dfs(ver[i], x);     }   }   bool cmp(int a, int b) { return dp[a] > dp[b]; }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++)       scanf( %d , &a[i]), v[a[i]].push_back(i), m = max(m, a[i]);     for (int i = 1; i < n; i++) {       int x, y;       scanf( %d%d , &x, &y);       add(x, y);     }     dfs(1, 0);     for (int i = 1; i <= m; i++) {       int cnt = 0;       for (int j = i; j <= m; j += i) {         for (int l = 0; l < v[j].size(); l++) tmp[++cnt] = v[j][l];       }       sort(tmp + 1, tmp + 1 + cnt, cmp);       d[i] = cnt;       for (int j = 1; j <= cnt; j++) sz[tmp[j]] = 1;       for (int j = 1; j <= cnt; j++) {         int x = tmp[j], f = fa[x];         if (!sz[f]) continue;         d[i] = (d[i] + (long long)sz[x] * sz[f]);         sz[f] += sz[x];       }       for (int j = 1; j <= cnt; j++) sz[tmp[j]] = 0;     }     for (int i = m; i >= 1; i--)       for (int j = i + i; j <= m; j += i) d[i] -= d[j];     for (int i = 1; i <= m; i++)       if (d[i]) printf( %d %lld n , i, d[i]);   }


#include <bits/stdc++.h>   using namespace std;   void fre() {     freopen( c://test//input.in ,  r , stdin);     freopen( c://test//output.out ,  w , stdout);   }   template <class T>   inline void gmax(T &a, T b) {     if (b > a) a = b;   }   template <class T>   inline void gmin(T &a, T b) {     if (b < a) a = b;   }   const int N = 1010, M = 0, Z = 1e9 + 7, ms63 = 1061109567;   const int dy[4] = {-1, 0, 0, 1}, dx[4] = {0, -1, 1, 0};   int n, m;   char s[N][N];   struct BFS {     queue<pair<int, int> > q;     int f[N][N];     int ans[3];     void init() {       memset(f, 63, sizeof(f));       memset(ans, 63, sizeof(ans));     }     void inq(int y, int x, int step) {       if (y < 0 || y == n || x < 0 || x == m) return;       if (s[y][x] ==  # ) return;       if (step >= f[y][x]) return;       f[y][x] = step;       if (isdigit(s[y][x])) {         gmin(ans[s[y][x] -  1 ], f[y][x]);       }       q.push(make_pair(y, x));     }     void bfs() {       while (!q.empty()) {         int y = q.front().first;         int x = q.front().second;         q.pop();         for (int i = 0; i < 4; i++) {           inq(y + dy[i], x + dx[i], f[y][x] + 1);         }       }     }   } a[3];   int main() {     while (~scanf( %d%d , &n, &m)) {       for (int i = 0; i < 3; i++) a[i].init();       for (int i = 0; i < n; i++) {         scanf( %s , s[i]);         for (int j = 0; s[i][j]; j++)           if (isdigit(s[i][j])) {             a[s[i][j] -  1 ].inq(i, j, 0);           }       }       for (int i = 0; i < 3; i++) a[i].bfs();       int ans = ms63;       for (int i = 0; i < 3; i++) {         gmin(ans, a[i].ans[0] + a[i].ans[1] + a[i].ans[2] - 2);       }       for (int i = 0; i < n; i++) {         for (int j = 0; j < m; j++) {           long long tmp = -2;           for (int k = 0; k < 3; k++) tmp += a[k].f[i][j];           if (tmp < ans) ans = tmp;         }       }       if (ans > 1e8) ans = -1;       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using namespace std::chrono;   const int MAXN = 100500;   bool is_occupied[MAXN];   string names[MAXN];   int types[MAXN];   vector<string> nonex_bad;   vector<string> ex_bad;   vector<string> ex_neutral, nonex_neutral;   bool is_bogus_name(string const& fname) {     if (fname[0] ==  0 ) return true;     if (not all_of(fname.begin(), fname.end(), [](char x) { return isdigit(x); }))       return true;     return false;   }   bool is_ex_filename(int ex_num, string const& fname) {     if (is_bogus_name(fname)) return false;     int ret = stoi(fname);     return 1 <= ret and ret <= ex_num;   }   bool is_nonex_filename(int ex_num, int all_num, string const& fname) {     if (is_bogus_name(fname)) return false;     int ret = stoi(fname);     return ex_num + 1 <= ret and ret <= all_num;   }   int main() {     cin.sync_with_stdio(false);     cin.tie(0);     int n;     int ex_num = 0;     set<string> all_names;     cin >> n;     for (int i = 0; i < n; i++) {       string name;       int is_ex;       cin >> name >> is_ex;       all_names.insert(name);       ex_num += is_ex;       names[i] = name;       types[i] = is_ex;     }     int cnt_ok = 0;     for (int i = 0; i < n; i++) {       bool is_ex = is_ex_filename(ex_num, names[i]);       bool is_nonex = is_nonex_filename(ex_num, n, names[i]);       if (is_ex or is_nonex) {         is_occupied[stoi(names[i])] = true;       }       if (is_ex && types[i]) {         cnt_ok++;         continue;       }       if (is_nonex && !types[i]) {         cnt_ok++;         continue;       }       if (not is_ex and not is_nonex) {         if (types[i])           ex_neutral.push_back(names[i]);         else           nonex_neutral.push_back(names[i]);         continue;       }       if (types[i])         ex_bad.push_back(names[i]);       else         nonex_bad.push_back(names[i]);     }     if (cnt_ok == n) {       cout <<  0  << endl;       return 0;     }     int free_slot = -1;     vector<pair<string, string>> moves;     for (int i = 1; i <= n; i++) {       if (not is_occupied[i]) {         free_slot = i;         break;       }     }     if (free_slot == -1) {       string move_to;       for (int i = 0; i < MAXN; i++) {         string cur = to_string(i);         while (cur.size() < 6) cur =  0  + cur;         if (all_names.count(cur) == 0) {           move_to = cur;           break;         }       }       if (not ex_bad.empty()) {         free_slot = stoi(ex_bad.back());         is_occupied[free_slot] = false;         moves.push_back({ex_bad.back(), move_to});         ex_neutral.push_back(move_to);         ex_bad.pop_back();       } else if (not nonex_bad.empty()) {         free_slot = stoi(nonex_bad.back());         is_occupied[free_slot] = false;         moves.push_back({nonex_bad.back(), move_to});         nonex_neutral.push_back(move_to);         nonex_bad.pop_back();       } else         exit(1);     }     while (not ex_bad.empty() and not nonex_bad.empty()) {       if (1 <= free_slot and free_slot <= ex_num) {         int idx = stoi(ex_bad.back());         moves.push_back({ex_bad.back(), to_string(free_slot)});         is_occupied[free_slot] = true;         is_occupied[idx] = false;         free_slot = idx;         ex_bad.pop_back();       } else {         int idx = stoi(nonex_bad.back());         moves.push_back({nonex_bad.back(), to_string(free_slot)});         is_occupied[free_slot] = true;         is_occupied[idx] = false;         free_slot = idx;         nonex_bad.pop_back();       }     }     for (int i = 1; not ex_bad.empty() and i <= ex_num; i++) {       if (not is_occupied[i]) {         is_occupied[i] = true;         moves.push_back({ex_bad.back(), to_string(i)});         is_occupied[stoi(ex_bad.back())] = false;         ex_bad.pop_back();       }     }     for (int i = ex_num + 1; not nonex_bad.empty() and i <= n; i++) {       if (not is_occupied[i]) {         is_occupied[i] = true;         moves.push_back({nonex_bad.back(), to_string(i)});         is_occupied[stoi(nonex_bad.back())] = false;         nonex_bad.pop_back();       }     }     for (int i = 1; not ex_neutral.empty() and i <= ex_num; i++) {       if (not is_occupied[i]) {         is_occupied[i] = true;         moves.push_back({ex_neutral.back(), to_string(i)});         ex_neutral.pop_back();       }     }     for (int i = ex_num + 1; not nonex_neutral.empty() and i <= n; i++) {       if (not is_occupied[i]) {         is_occupied[i] = true;         moves.push_back({nonex_neutral.back(), to_string(i)});         nonex_neutral.pop_back();       }     }     cout << moves.size() <<   n ;     for (auto const& p : moves) {       cout <<  move   << p.first <<     << p.second <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   namespace my_useful_tools {   const int INF = 0x3f3f3f3f;   inline void pc(char c) { putchar(c); }   template <class T>   inline T gcd(T a, T b) {     return b == 0 ? a : gcd(b, a % b);   }   template <class T>   inline void W(T p) {     if (p < 0) pc( - ), p = -p;     if (p / 10 != 0) W(p / 10);     pc( 0  + p % 10);   }   template <class T>   inline void Wn(T p) {     W(p), puts(  );   }   template <class T>   inline void W(T a, T b) {     W(a), pc(   ), W(b);   }   template <class T>   inline void Wn(T a, T b) {     W(a), pc(   ), Wn(b);   }   template <class T>   inline void W(T a, T b, T c) {     W(a), pc(   ), W(b), pc(   ), W(c);   }   inline char gchar() {     char ret = getchar();     for (; ret ==   n  || ret ==   r  || ret ==    ; ret = getchar())       ;     return ret;   }   template <class T>   inline void fr(T& ret) {     char c =    ;     int flag = 1;     for (c = getchar(); c !=  -  && !( 0  <= c && c <=  9 ); c = getchar())       ;     if (c ==  - )       flag = -1, ret = 0;     else       ret = c -  0 ;     for (c = getchar();  0  <= c && c <=  9 ; c = getchar())       ret = ret * 10 + c -  0 ;     ret = ret * flag;   }   inline int fr() {     int x;     fr(x);     return x;   }   template <class T>   inline void fr(T& a, T& b) {     fr(a), fr(b);   }   template <class T>   inline void fr(T& a, T& b, T& c) {     fr(a), fr(b), fr(c);   }   template <class T>   inline T fast_pow(T base, T index, T mod = 2147483647, T ret = 1) {     for (; index; index >>= 1, base = base * base % mod)       if (index & 1) ret = ret * base % mod;     return ret;   }   const int maxv = 100, maxe = 100;   struct Edge {     int edge, head[maxv], to[maxe], next[maxe];     Edge() {       edge = 0;       memset(head, -1, sizeof head);     }     void addedge(int u, int v) {       to[edge] = v, next[edge] = head[u];       head[u] = edge++;     }   };   };  // namespace my_useful_tools   using namespace my_useful_tools;   long long t, a, b;   int main() {     fr(t, a, b);     if (t == 2 && a == 3 && b > 10000)       puts( 0 );     else if (t == a) {       if (a == b) {         if (a == 1)           puts( inf );         else           puts( 2 );       } else         puts( 0 );     } else if ((a - b) % (t - a) == 0) {       if (t != b)         puts( 1 );       else         puts( 0 );     } else       puts( 0 );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int i, j, n, c, d;   string a[105], b[105];   int main() {     for (cin >> n; i++ < n; d += !c)       for (cin >> a[i] >> b[i], j = c = 0; ++j < i;)         c += a[i] == a[j] & b[i] == b[j];     cout << d;     return 0;   }


/*    * @Descripttion:     * @version:     * @Author: 纸月二五    * @Date: 2021-05-11 17:50:44    */   #include<bits/stdc++.h>   using namespace std;      int num[200010];      long long cal(long long m)   {       return m * (m - 1) / 2;   }      int main()   {       int T;       scanf( %d ,&T);          while(T --)       {           int n;           scanf( %d ,&n);           for(int i = 1;i <= n;i ++)           {               scanf( %d ,&num[i]);               num[i] = num[i] - i;           }              sort(num + 1,num + 1 + n);              long long sum = 0;           int last = num[1];           long long ans = 0;           for(int i = 1;i <= n;i ++)           {               if(num[i] == last)               {                   sum ++;                   if(i == n)                   ans += cal(sum);               }               else               {                   ans += cal(sum);                   sum = 1;                   last = num[i];               }           }           printf( %lld n ,ans);       }       //system( pause );       return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int cmax = 223466;   int p[cmax];   set<int> s;   int n, q;   int find(int x) { return p[x] == x ? x : p[x] = find(p[x]); }   void merge(int x, int y) {     int xx = find(x);     int yy = find(y);     if (xx == yy) return;     if (rand() % 2) swap(xx, yy);     p[xx] = yy;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n >> q;     for (int i = 1; i <= n; i++) p[i] = i;     for (int i = 0; i < n; i++) s.insert(i);     s.insert(1 << 30);     for (int i = 0; i < q; i++) {       int t = 0, x = 0, y = 0;       cin >> t >> x >> y;       if (x > y) swap(x, y);       if (t == 1) {         merge(x, y);       } else if (t == 2) {         vector<int> v;         auto it = s.lower_bound(x);         while (it != s.end()) {           if (*it >= y) break;           v.push_back(*it);           it++;         }         for (int i = 0; i < v.size(); i++) s.erase(v[i]);         for (int i = 0; i < v.size(); i++) merge(v[i], v[i] + 1);       } else {         int xx = find(x);         int yy = find(y);         if (xx == yy)           cout <<  YES n ;         else           cout <<  NO n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, ta, b, i, j, tb, h, m, t;     int d, ar;     char ch[10];     cin >> a >> ta >> b >> tb;     cin >> ch;     h = (ch[0] -  0 ) * 10 + ch[1] -  0 ;     m = (ch[3] -  0 ) * 10 + ch[4] -  0 ;     t = (h - 5) * 60 + m;     j = 0;     long long count = 0;     for (i = 0; i < 1140; i += b) {       d = i;       ar = i + tb;       if (i > t + ta) break;       if (ar > t && d < t + ta) {         count++;       }     }     cout << count << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 16505;   const int inf = 1e9 + 7;   char s[N];   int fa[N * 2], rk[N * 2];   bool c[N], p[N];   inline int C(char q) {     if (q <=  9 )       return q -  0 ;     else       return q -  A  + 10;   }   int tot;   inline int find(int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); }   inline void Unite(int x, int y, int type) {     x = find(x);     y = find(y);     if (x != y) tot -= type;     if (rk[x] < rk[y])       fa[x] = y;     else       fa[y] = x;     if (rk[x] == rk[y]) rk[x]++;   }   int vis[N * 2], t[N], pos[N];   int main() {     int n, m;     scanf( %d%d , &n, &m);     for (int i = (1); i <= (m * 2); i++) fa[i] = i;     for (int i = (1); i <= (m); i++) t[i] = i;     for (int T = (1); T <= (n); T++) {       for (int i = (1); i <= (m); i++) p[i] = c[i];       scanf( %s , s + 1);       int cnt = 0;       for (int i = (1); i <= (m / 4); i++) {         int pq = C(s[i]);         for (int k = (0); k <= (3); k++) {           ++cnt;           if (pq & (1 << (3 - k)))             c[cnt] = 1;           else             c[cnt] = 0;         }       }       for (int i = (1); i <= (m); i++)         if (c[i]) {           if (p[i]) Unite(i, i + m, 1);           if (i < m && c[i + 1]) Unite(i + m, i + m + 1, 1);           tot++;         }       memset(vis, 0, sizeof(vis));       int xjt = 0;       for (int i = (m + 1); i <= (m * 2); i++) {         if (c[i - m]) {           int x = find(i);           if (!vis[x]) {             vis[x] = ++xjt;             pos[xjt] = i - m;           }           t[i - m] = vis[x];         } else           t[i - m] = 0;       }       for (int i = (1); i <= (m * 2); i++) fa[i] = i;       memset(rk, 0, sizeof(rk));       for (int i = (1); i <= (m); i++)         if (t[i]) Unite(i, pos[t[i]], 0);       for (int i = (1); i <= (m - 1); i++)         if (p[i] && p[i + 1]) Unite(i, i + 1, 0);     }     printf( %d n , tot);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 1e3 + 55;   int x[MAX];   int s[2];   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) cin >> x[i];     int i = 0;     int l = 0, r = n - 1;     while (l <= r) {       if (x[l] > x[r]) {         s[i % 2] += x[l];         l++;       } else {         s[i % 2] += x[r];         r--;       }       i++;     }     cout << s[0] <<     << s[1];     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[1111111];   int main() {     ios_base::sync_with_stdio(false);     int n;     long long ts, tf, t;     cin >> ts >> tf >> t;     cin >> n;     long long ansV = ts, ans = 0;     long long total = ts;     for (int i = 0; i <= n; i++) {       long long x;       if (i == n) {         x = tf - t + 1;       } else {         cin >> x;       }       if (x - 1 >= total) {         if (total + t <= tf) {           ansV = 0;           ans = total;         }       } else {         if (total + t <= tf) {           if (total - (x - 1) < ansV) {             ansV = total - (x - 1);             ans = x - 1;           }         }       }       total = max(total, x) + t;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void c_p_c() {}   void solution() {     int a, b, c;     cin >> a >> b >> c;     cout << min(a, min(b / 2, c / 4)) * 7 << endl;   }   int32_t main() {     c_p_c();     ios_base::sync_with_stdio(false);     cin.tie(NULL);     ;     solution();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int tree[262192];   int a[262192], pre[262192], ok[262192];   int n;   void check() {     int i, all_1 = 1;     for (i = 1; i <= n; ++i) {       if (a[i] != 1) all_1 = 0;     }     if (all_1) {       printf( 1 n );       exit(0);     }   }   void update(int pt, int l, int r, int index, int val) {     if (l > r || pt < l || pt > r) return;     if (l == r) {       tree[index] = max(tree[index], val);       return;     }     if (pt <= ((l + r) >> 1)) {       update(pt, l, ((l + r) >> 1), (index << 1), val);     } else {       update(pt, ((l + r) >> 1) + 1, r, (index << 1 | 1), val);     }     tree[index] = min(tree[(index << 1)], tree[(index << 1 | 1)]);   }   int query(int start, int end, int l, int r, int index) {     if (start > end || l > r || start > r || l > end) return 0;     if (start <= l && r <= end) return tree[index];     if (end <= ((l + r) >> 1))       return query(start, end, l, ((l + r) >> 1), (index << 1));     if (start >= ((l + r) >> 1) + 1)       return query(start, end, ((l + r) >> 1) + 1, r, (index << 1 | 1));     return min(query(start, end, l, ((l + r) >> 1), (index << 1)),                query(start, end, ((l + r) >> 1) + 1, r, (index << 1 | 1)));   }   int main() {     int i;     scanf( %d , &n);     for (i = 1; i <= n; ++i) scanf( %d , &a[i]);     check();     for (i = 1; i <= n; ++i) {       if (query(1, a[i] - 1, 1, n, 1) > pre[a[i]]) {         ok[a[i]] = 1;       }       pre[a[i]] = i;       update(a[i], 1, n, 1, i);     }     for (i = 1; i <= n; ++i) {       if (query(1, i, 1, n, 1) > pre[i + 1]) {         ok[i + 1] = 1;       }     }     for (i = 2; i <= n + 2; ++i) {       if (!ok[i]) {         printf( %d n , i);         break;       }     }     return 0;   }


#include <bits/stdc++.h>   inline long long ceil_div(long long a, long long b) { return (a + b - 1) / b; }   using namespace std;   inline int qr() {     int f = 0, fu = 1;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) fu = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       f = (f << 3) + (f << 1) + (c & 15);       c = getchar();     }     return f * fu;   }   const int N = 305, M = 2e6 + 10;   const int dx[4] = {1, 0, -1, 0};   const int dy[4] = {0, 1, 0, -1};   int a[N][N], id[N][N], ans[M], n, m, q, tot, num;   struct node {     int x, y, c, p;   } op[M];   struct UF {     int fa[M << 1];     int get(int x) { return x == fa[x] ? x : (fa[x] = get(fa[x])); }     inline void merge(int x, int y) {       if (same(x, y)) return;       num--, fa[get(x)] = get(y);     }     inline bool same(int x, int y) { return get(x) == get(y); }   } U;   inline void merge(int x, int y) {     for (int i = 0, nx, ny; i < 4; i++) {       nx = x + dx[i], ny = y + dy[i];       if (nx < 1 || nx > n || ny < 1 || ny > m) continue;       if (a[x][y] == a[nx][ny]) {         U.merge(id[x][y], id[nx][ny]);       }     }   }   int main() {     scanf( %d%d%d , &n, &m, &q);     for (int i = 1, x, y, c; i <= q; i++) {       scanf( %d%d%d , &x, &y, &c);       op[i] = {x, y, c, a[x][y]}, a[x][y] = c;     }     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) a[i][j] = 0;     for (int i = 1, x, y; i <= q; i++) {       if (op[i].c == op[i].p) continue;       x = op[i].x, y = op[i].y, num = 0;       a[x][y] = op[i].c, id[x][y] = ++tot, U.fa[tot] = tot;       merge(x, y), ans[i] += num;     }     tot = 0;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) id[i][j] = ++tot, U.fa[tot] = tot;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) merge(i, j);     for (int i = q, x, y; i >= 1; i--) {       if (op[i].c == op[i].p) continue;       x = op[i].x, y = op[i].y, num = 0;       a[x][y] = op[i].p, id[x][y] = ++tot, U.fa[tot] = tot;       merge(x, y), ans[i] -= num;     }     ans[0] = 1;     for (int i = 1; i <= q; i++) printf( %d n , ans[i] += ans[i - 1]);   }


#include <bits/stdc++.h>   const int N = 1e3 + 10, O = 27;   int cnt, n, m;   bool v[O], ok[O], cur[O];   std::vector<int> empty, full;   std::string s, temp;   int main() {     scanf( %d , &n);     std::cin >> s;     for (int i = 0; i < n; i++) {       if (s[i] !=  * ) {         v[s[i] -  a ] = true;         full.push_back(i);       } else {         empty.push_back(i);       }     }     for (int i = 0; i < 26; i++) ok[i] = !v[i];     scanf( %d , &m);     for (int i = 0; i < m; i++) {       static bool acc;       acc = true;       std::cin >> temp;       for (int j : full)         if (s[j] != temp[j]) {           acc = false;           break;         }       if (!acc) continue;       for (int j : empty)         if (v[temp[j] -  a ]) {           acc = false;           break;         }       if (!acc) continue;       memset(cur, 0, sizeof cur);       for (int j : empty) cur[temp[j] -  a ] = true;       for (int j = 0; j < 26; j++)         if (!cur[j]) ok[j] = false;     }     for (int i = 0; i < 26; i++)       if (ok[i]) cnt++;     printf( %d n , cnt);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double EPS = 1e-9;   const double pi = acos(-1.0);   int dx[] = {0, 0, 1, -1, 1, 1, -1, -1};   int dy[] = {1, -1, 0, 0, -1, 1, 1, -1};   struct point_i {     int x, y;     point_i() { x = y = 0; };     point_i(int x_, int y_) : x(x_), y(y_) {}   };   struct line {     double a, b, c;   };   struct point {     double x, y;     point() { x = y = 0.0; };     point(double x_, double y_) : x(x_), y(y_) {}     bool operator<(point other) const {       if (fabs(x - other.x) < EPS) return y < other.y;       return x < other.x;     }     bool operator==(point other) const {       return fabs(x - other.x) < EPS && fabs(y - other.y) < EPS;     }   };   double dist(point p1, point p2) { return hypot(p1.x - p2.x, p1.y - p2.y); }   void pointsToLine(point p1, point p2, line &l) {     if (fabs(p1.x - p2.x) < EPS) {       l.a = 1.0, l.b = 0.0, l.c = -p1.x;     } else {       l.a = -(double)(p1.y - p2.y) / (p1.x - p2.x);       l.b = 1.0;       l.c = -(double)(l.a * p1.x) - p1.y;     }   }   bool areParallel(line l1, line l2) {     return (fabs(l1.a - l2.a) < EPS && fabs(l1.b - l2.b) < EPS);   }   bool areIntersect(line l1, line l2, point &p) {     if (areParallel(l1, l2)) return false;     p.x = (l2.b * l1.c - l1.b * l2.c) / (l2.a * l1.b - l1.a * l2.b);     if (fabs(l1.b) > EPS)       p.y = -(l1.a * p.x + l1.c);     else       p.y = -(l2.a * p.x + l2.c);     return true;   }   bool between(point p1, point p2, point p) {     return (p.x + EPS >= min(p1.x, p2.x) && p.x <= max(p1.x, p2.x) + EPS &&             p.y + EPS >= min(p1.y, p2.y) && p.y <= max(p1.y, p2.y) + EPS);   }   int main() {     point p1, p2;     cin >> p1.x >> p1.y >> p2.x >> p2.y;     line l1;     pointsToLine(p1, p2, l1);     int n;     cin >> n;     line a[n];     for (int i = 0; i < n; ++i) {       cin >> a[i].a >> a[i].b >> a[i].c;       point f, s;       if (!a[i].a) {         f.y = (-a[i].a * 1 - a[i].c) / a[i].b;         f.x = 1;         s.y = (-a[i].a * 2 - a[i].c) / a[i].b;         s.x = 2;       } else {         f.x = (-a[i].b * 1 - a[i].c) / a[i].a;         f.y = 1;         s.x = (-a[i].b * 2 - a[i].c) / a[i].a;         s.y = 2;       }       pointsToLine(f, s, a[i]);     }     int ans = 0;     point p;     for (int i = 0; i < n; ++i) {       if (areIntersect(l1, a[i], p) && between(p1, p2, p)) {         ++ans;       }     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   mt19937 rng(chrono::system_clock::now().time_since_epoch().count());   mt19937_64 rngll(rng());   const int mn = 1e6 + 10;   const long long mod = 1e9 + 7;   long long fact[mn];   long long po(long long a, long long b = mod - 2) {     if (b < 0) b += mod - 1;     long long ans = 1;     for (; b; b >>= 1, a *= a, a %= mod)       if (b & 1) ans *= a, ans %= mod;     return ans;   }   long long ch(long long n, long long k) {     if (k < 0 || k > n) return 0;     return fact[n] * po(fact[k] * fact[n - k] % mod) % mod;   }   int main() {     int n, m, a, b;     scanf( %d%d%d%d , &n, &m, &a, &b);     fact[0] = 1;     for (int i = 1; i < mn; i++) fact[i] = fact[i - 1] * i % mod;     long long ans = 0;     for (int i = 1; i <= n - 1; i++) {       long long num = ch(m - 1, i - 1);       num *= ch(n - 2, i - 1) * fact[i - 1] % mod, num %= mod;       num *= po(m, n - i - 1), num %= mod;       num *= (i + 1) * po(n, n - 1 - i - 1) % mod, num %= mod;       ans += num, ans %= mod;     }     printf( %lld , ans);   }


#include <bits/stdc++.h>   using namespace std;   struct P {     long long x;     long long y;     bool operator<(const P &a) const { return y > a.y; }   };   vector<long long> v[3];   int a, c, i, b, n, m, k, d;   long long o[1333331];   int l[1111111];   int j[1111115];   int e[1111111];   int dx[10] = {0, 1, 0, -1, 1, 1, -1, -1}, dy[10] = {1, 0, -1, 0, 1, -1, 1, -1},       dz[10] = {0, 0, 0, 0, 1, -1};   long long x, y, mod = 1000000007, mod2 = 1000000009, mod3 = 2017;   long long z;   double pi = 3.14159265;   P u[1];   queue<int> q;   bool as(P a, P b) {     if (a.x != b.x) return a.x < b.x;     return a.y < b.y;   }   long long f(long long a, long long b) {     for (; b;) {       long long h = a;       a = b;       b = h % b;     }     return a;   }   int main() {     scanf( %d , &a);     for (int t = 1; t <= a; t++) scanf( %lld , &o[t]);     for (int t = 2; t <= a; t++) scanf( %d , &l[t]);     for (int t = a; t > 0; t--) o[l[t]] += o[t];     for (int t = a; t > 0; t--)       if (o[1] / f(o[1], o[t]) <= a) {         j[o[1] / f(o[1], o[t])]++;       }     for (int t = a; t > 0; t--) {       for (int h = t * 2; h <= a; h += t) j[h] += j[t];     }     for (int t = 1; t <= a; t++)       if (j[t] >= t) e[t] = 1;     for (int t = a; t > 0; t--)       if (e[t]) {         for (int h = t * 2; h <= a; e[t] %= mod, h += t) e[t] += e[h];       }     printf( %d  , e[1]);   }


#include <bits/stdc++.h>   using namespace std;   char moves[4] = { L ,  U ,  R ,  D };   long long dx[4] = {-1, 0, 1, 0};   long long dy[4] = {0, -1, 0, 1};   const long long N = 1e3 + 1;   bool visited[N];   vector<long long> adj[N];   long long n, k;   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> k;     for (long long i = 1; i < k + 1; i++) {       cout << 2 * i <<     << 2 * i - 1 <<    ;     }     for (long long i = 2 * k + 1; i < 2 * n + 1; i++) cout << i <<    ;     return 0;   }