#include <bits/stdc++.h>   using namespace std;   using ll = long long;   template <typename T>   using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;   const ll inf = 1LL << 60;   vector<ll> dv;   void divisor(ll n) {     for (ll i = 1; i * i <= n; i++) {       if (n % i == 0) {         if (i == n / i) {           dv.push_back(i);         } else {           dv.push_back(i);           dv.push_back(n / i);         }       }     }   }   ll gcd(ll a, ll b) {     if (a == 0 || b == 0) return 0;     if (a % b == 0) return b;     return gcd(b, a % b);   }   int main() {     ll l, r, x, y;     cin >> l >> r >> x >> y;     if (y % x != 0)       cout << 0 << endl;     else {       ll tmp = y / x;       divisor(tmp);       ll ans = 0;       for (auto &z : dv) {         ll a = z;         ll b = tmp / z;         if (gcd(a, b) == 1) {           if (l <= x * a && x * a <= r && l <= x * b && x * b <= r) ans++;         }       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /stack:200000000 )   #pragma GCC optimize( Ofast )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   using namespace std;   struct SegmentTree {     vector<multimap<int, int>> T;     SegmentTree(int n) : T(n + 1) {}     set<int> available;     void Insert(int l, int r, int idx) {       for (++l; l > 0; l -= (l & (-l))) T[l].emplace(r, idx);       available.insert(idx);     }     int Query(int l, int r) {       for (++l; l < (int)T.size(); l += (l & (-l))) {         while (true) {           if (T[l].empty() or T[l].begin()->first > r) break;           auto now = (*T[l].begin());           T[l].erase(T[l].begin());           if (available.count(now.second)) {             available.erase(now.second);             return now.second;           }         }       }       return -1;     }   };   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int n, m;     cin >> n >> m;     vector<tuple<int, int, int, int, int>> events;     vector<int> all;     for (int i = 0; i < n; ++i) {       int s, f, t;       cin >> s >> f >> t;       events.emplace_back(t, 1, s, f, i);       all.push_back(s);     }     for (int i = 0; i < m; ++i) {       int l, r, b;       cin >> l >> r >> b;       events.emplace_back(b, 0, l, r, i);       all.push_back(l);     }     sort(events.begin(), events.end());     sort(all.begin(), all.end());     all.erase(unique(all.begin(), all.end()), all.end());     SegmentTree st(all.size());     vector<int> ans(m, -2);     for (auto itr : events) {       int tp, l, r, idx;       tie(ignore, tp, l, r, idx) = itr;       l = distance(all.begin(), lower_bound(all.begin(), all.end(), l));       if (tp == 0) {         st.Insert(l, r, idx);       } else {         while (true) {           int now = st.Query(l, r);           if (now == -1) break;           ans[now] = idx;         }       }     }     for (auto x : ans) cout << x + 1 <<    ;     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using pii = pair<int, int>;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     int n, m;     cin >> n >> m;     vector<int> a(n), b(n);     for (int i = (0); i < (m); i++) {       int x, y;       cin >> x >> y;       --x;       --y;       y = (y - x + n) % n;       b[x] = a[x]++ ? min(b[x], y) : y;     }     for (int i = (0); i < (n); i++)       if (a[i]) {         a[i] = a[i] * n + b[i] + i;         b[i] = a[i] - n;       }     for (int i = (0); i < (n); i++)       if (i) a[i] = max(a[i], a[i - 1]);     for (int i = (n); i-- > (0);)       if (i < n - 1) b[i] = max(b[i], b[i + 1]);     for (int i = (0); i < (n); i++)       cout << max(i ? a[i - 1] : 0, b[i]) - i <<    ;   }


#include <iostream>   #include <vector>   #include <string>   #include <queue>   #include <algorithm>   #include <cmath>   #include <map>   #include <set>   #include <unistd.h>   #define rep(i,a,n) for(int i = a;i < n;i++)   #define fi first   #define se second   typedef long long ll;   using namespace std;   const int INF = 0x3f3f3f3f;   const int N = 1e4 + 3;   const int mod = 1e9 + 7;    ll quick_pow(ll a, ll b){ll ans = 1;while(b){if(b & 1){ans = (ans * a) % mod;}a = (a * a) % mod;b >>= 1;}return ans;}      ll gcd(ll a, ll b){return (b == 0 ? a : gcd(b, a % b));}      struct cmp   {    bool operator() (pair<int,pair<int,int>> a1,pair<int,pair<int,int>> a2){     return a1.first > a2.first;    }   };            int main(){       ios::sync_with_stdio(false);       //freopen( in.txt , r , stdin);    int t;    cin  >> t;    while(t--){     ll n;     cin >> n;     if(n / 2050 * 2050 == n){      ll x = n / 2050;      int cnt = 0;      while(x){       cnt += x % 10;       x /= 10;      }      cout << cnt << endl;     }else{      cout << -1 << endl;     }    }          }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2 * 1e5 + 10, mod = 1e9 + 7;   long long a[maxn], d[maxn];   bool mark[maxn];   long long dfs(int v, int p) {     mark[v] = 1;     if (v == p) return 0;     if (mark[a[v]]) return -1;     int k = dfs(a[v], p);     return (k == -1 ? -1 : k + 1);   }   int main() {     ios::sync_with_stdio(0);     long long n, s, t;     cin >> n >> s >> t;     for (int i = 1; i <= n; i++) cin >> a[i];     cout << dfs(s, t) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     string s, t, p =   ;     cin >> s >> t;     int n = s.size();     int c = 0;     for (int i = 0; i < n; i++)       if (s[i] != t[i]) c++;     if (c % 2) {       cout <<  impossible ;       return 0;     }     for (int i = 0; i < n; i++) {       if (s[i] == t[i]) {         p += s[i];         continue;       }       if (c)         p += s[i], c -= 2;       else         p += t[i];     }     cout << p << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<int> A, B;     for (int i = 1; i <= n; i++) A.push_back(i);     long long sum = 0;     for (int i = 2; i < n; i++) sum += i * (i + 1);     cout << sum <<   n ;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   #pragma GCC target( sse4 )   using namespace std;   template <class T>   using pq = priority_queue<T>;   template <class T>   using pqg = priority_queue<T, vector<T>, greater<T>>;   template <class T>   bool ckmin(T& a, const T& b) {     return b < a ? a = b, 1 : 0;   }   template <class T>   bool ckmax(T& a, const T& b) {     return a < b ? a = b, 1 : 0;   }   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   void __print(int x) { cerr << x; }   void __print(long x) { cerr << x; }   void __print(long long x) { cerr << x; }   void __print(unsigned x) { cerr << x; }   void __print(unsigned long x) { cerr << x; }   void __print(unsigned long long x) { cerr << x; }   void __print(float x) { cerr << x; }   void __print(double x) { cerr << x; }   void __print(long double x) { cerr << x; }   void __print(char x) { cerr <<      << x <<     ; }   void __print(const char* x) { cerr <<     << x <<    ; }   void __print(const string& x) { cerr <<     << x <<    ; }   void __print(bool x) { cerr << (x ?  true  :  false ); }   template <typename T, typename V>   void __print(const pair<T, V>& x) {     cerr <<  { ;     __print(x.first);     cerr <<  ,  ;     __print(x.second);     cerr <<  } ;   }   template <typename T>   void __print(const T& x) {     int first = 0;     cerr <<  { ;     for (auto& i : x) cerr << (first++ ?  ,   :   ), __print(i);     cerr <<  } ;   }   void _print() { cerr <<  ] n ; }   template <typename T, typename... V>   void _print(T t, V... v) {     __print(t);     if (sizeof...(v)) cerr <<  ,  ;     _print(v...);   }   const int MOD = 998244353;   const char nl =   n ;   const int MX = 100001;   struct mi {     long long v;     explicit operator long long() const { return v; }     mi() { v = 0; }     mi(long long _v) {       v = (-MOD < _v && _v < MOD) ? _v : _v % MOD;       if (v < 0) v += MOD;     }     friend bool operator==(const mi& a, const mi& b) { return a.v == b.v; }     friend bool operator!=(const mi& a, const mi& b) { return !(a == b); }     friend bool operator<(const mi& a, const mi& b) { return a.v < b.v; }     mi& operator+=(const mi& m) {       if ((v += m.v) >= MOD) v -= MOD;       return *this;     }     mi& operator-=(const mi& m) {       if ((v -= m.v) < 0) v += MOD;       return *this;     }     mi& operator*=(const mi& m) {       v = v * m.v % MOD;       return *this;     }     mi& operator/=(const mi& m) { return (*this) *= inv(m); }     friend mi pow(mi a, long long p) {       mi ans = 1;       assert(p >= 0);       for (; p; p /= 2, a *= a)         if (p & 1) ans *= a;       return ans;     }     friend mi inv(const mi& a) {       assert(a.v != 0);       return pow(a, MOD - 2);     }     mi operator-() const { return mi(-v); }     mi& operator++() { return *this += 1; }     mi& operator--() { return *this -= 1; }     mi operator++(int) {       mi temp;       temp.v = v++;       return temp;     }     mi operator--(int) {       mi temp;       temp.v = v--;       return temp;     }     friend mi operator+(mi a, const mi& b) { return a += b; }     friend mi operator-(mi a, const mi& b) { return a -= b; }     friend mi operator*(mi a, const mi& b) { return a *= b; }     friend mi operator/(mi a, const mi& b) { return a /= b; }     friend ostream& operator<<(ostream& os, const mi& m) {       os << m.v;       return os;     }     friend istream& operator>>(istream& is, mi& m) {       long long x;       is >> x;       m.v = x;       return is;     }   };   void __print(mi X) { cout << X.v; }   int K;   mi A, H;   mi vals[6];   int places[6];   map<int, map<mi, vector<int>>> get(vector<int> B) {     int nm = (1 << (K - 1)) - 1;     map<int, map<mi, vector<int>>> res;     for (int m = 0; m < (1 << nm); m++) {       int p = 0;       int v = K;       vector<int> cur;       for (int i = 0; i < ((int)(B).size()); i++) cur.push_back(i);       vector<int> place((int)(B).size());       mi value = 0;       while ((int)(cur).size() > 1) {         vector<int> nxt;         for (int i = 0; i < ((int)(cur).size() / 2); i++) {           if (m & (1 << p)) {             nxt.push_back(cur[i * 2]);             place[cur[i * 2 + 1]] = places[v];             value += B[cur[i * 2 + 1]] * vals[v];           } else {             nxt.push_back(cur[i * 2 + 1]);             place[cur[i * 2]] = places[v];             value += B[cur[i * 2]] * vals[v];           }           p++;         }         cur = nxt;         v--;       }       place[cur[0]] = 2;       value += B[cur[0]] * vals[1];       res[B[cur[0]]][value] = (place);     }     return res;   }   void solve() {     cin >> K >> A >> H;     vals[0] = A;     for (int i = 1; i < (6); i++) {       vals[i] = pow(mi(A), (pow(mi(2), i - 1) + 1).v);     }     places[0] = 1;     places[1] = 2;     places[2] = 3;     places[3] = 5;     places[4] = 9;     places[5] = 17;     vector<int> A1, A2;     for (int i = 0; i < (1 << (K - 1)); i++) {       A1.push_back(i + 1);       A2.push_back(i + 1 + (1 << (K - 1)));     }     map<int, map<mi, vector<int>>> res1 = get(A1), res2 = get(A2);     for (auto& a : res1) {       for (auto& b : res2) {         for (auto& x : a.second) {           mi cur1 = x.first + a.first * vals[0] - a.first * vals[1];           if (b.second.count(H - cur1)) {             vector<int> ans1 = x.second, ans2 = b.second[H - cur1];             ans1[a.first - 1] = 1;             for (auto& c : ans1) cout << c <<    ;             for (auto& c : ans2) cout << c <<    ;             return;           }           mi cur2 = x.first + b.first * vals[0] - b.first * vals[1];           if (b.second.count(H - cur2)) {             vector<int> ans1 = x.second, ans2 = b.second[H - cur2];             ans2[b.first - (1 << (K - 1)) - 1] = 1;             for (auto& c : ans1) cout << c <<    ;             for (auto& c : ans2) cout << c <<    ;             return;           }         }       }     }     cout << -1 << nl;   }   int main() {     cin.tie(0)->sync_with_stdio(0);     cin.exceptions(cin.failbit);     int T = 1;     while (T--) {       solve();     }     return 0;   }


#include <iostream>   #include <vector>      #define int long long      const int DEN = 100000;   const int INF = 100000000000000000;      int ceild(int x) {     if(x%DEN != 0) {       x += DEN-x%DEN;     }     return x/DEN;   }      signed main() {     std::ios::sync_with_stdio(false);     std::cin.tie(0);        int n, m;     std::cin >> n >> m;        std::vector<int> poss[n+1];     for(int i = 0; i <= m; i++)       poss[0].push_back(i==0);        for(int i = 1; i <= n; i++) {       poss[i] = poss[i-1];       int t, x, y;       std::cin >> t >> x >> y;          if(t == 2) {         for(int j = 0; j <= m; j++) {           if(!poss[i-1][j])             continue;           int next = j;           int count = 0;           while(next <= m && count <= y) {             poss[i][next] = 1;             next *= x;             next = ceild(next);             if(next <= m && poss[i-1][next])               break;             count++;           }         }       }       else {         x = ceild(x);         std::vector<int> next(m+1, -INF);         for(int j = 0; j <= m; j++) {           if(j-x >= 0)             next[j] = next[j-x];           if(poss[i-1][j])             next[j] = j;           if(j-next[j] <= y*x)             poss[i][j] = 1;         }       }        }        std::vector<int> answer(m+1, -1);     for(int i = n; i > 0; i--) {       for(int j = 1; j <= m; j++)         if(poss[i][j])           answer[j] = i;     }        for(int j = 1; j <= m; j++)       std::cout << answer[j] <<    ;     std::cout << std::endl;        return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c, r;     int y1, y2, yw, x, y;     scanf( %d%d%d%d%d%d , &a, &b, &c, &x, &y, &r);     y2 = b;     if (b - a < r) {       printf( -1 n );       return 0;     }     y1 = a + r;     yw = c - r;     y = 2 * yw - y;     double k = (1.0) * (y - y1) / x;     double ans = (yw - y1) / k;     double dis = (y2 - y1) / sqrt(k * k + 1);     if (dis < r)       printf( -1 n );     else       printf( %.10f n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     string s;     cin >> n >> s;     int cont = 0;     for (int i = 0; i < n && s[i] ==  < ; i++, cont++)       ;     for (int i = n - 1; i >= 0 && s[i] ==  > ; i--, cont++)       ;     cout << cont << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100005;   int n, m;   int a[MAXN];   int w[MAXN], h[MAXN];   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     scanf( %d , &m);     for (int i = 1; i <= m; i++) {       scanf( %d%d , &w[i], &h[i]);     }     long long lasth = 0;     for (int i = 1; i <= m; i++) {       long long int x = lasth + 1;       if (a[w[i]] > x) x = a[w[i]];       printf( %I64d n , x);       lasth = x + h[i] - 1;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int n, k, m, d;   int main() {     std::ios::sync_with_stdio(false);     long long int best = -1;     cin >> n >> k >> m >> d;     int x;     long long int pre = m;     long long int ans = 0;     for (int cycles = 1; cycles <= d; cycles++) {       long long int peeps = (cycles - 1) * k + 1;       long long int eachCandy = min(m, n / peeps);       if (eachCandy == 0) break;       ans = max(ans, eachCandy * cycles);     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using db = double;   using pii = pair<int, int>;   using pll = pair<ll, ll>;   const int N = 2e5 + 10;   const ll inf = 1e15 + 42;   vector<vector<int> > g(100007);   int flg, root, cnt;   vector<int> ans;   void dfs(int u, int par) {     if (flg) return;     int val = 0;     for (int v : g[u]) {       if (v != par) {         val++;         dfs(v, u);       }     }     if (val == 2 && u == 1) {       return;     }     if (val > 1 && cnt == 0) {       cnt++;       root = u;     } else if (val > 1) {       flg = 1;     }   }   void dfs1(int u, int par) {     int ok = 1;     for (int v : g[u]) {       if (v != par) {         ok = 0;         dfs1(v, u);       }     }     if (ok) ans.push_back(u);   }   void testCase() {     int n;     cin >> n;     for (int i = 1; i < n; i++) {       int u, v;       cin >> u >> v;       g[u].push_back(v);       g[v].push_back(u);     }     dfs(1, -1);     if (flg == 1) {       cout <<  No             <<   n ;       return;     }     if (root == 0) root = 1;     dfs1(root, -1);     cout <<  Yes           <<   n ;     cout << ans.size() <<   n ;     for (int i = 0; i < ans.size(); i++) cout << root <<     << ans[i] <<   n ;   }   int main() {     ios_base ::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     testCase();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int nofQs;     cin >> nofQs;     int minSec = INT_MAX;     vector<int> custs(nofQs);     for (int i = 0; i < nofQs; i++) {       cin >> custs[i];     }     for (int i = 0; i < nofQs; i++) {       int tAmt = 0;       for (int j = 0; j < custs[i]; j++) {         int nofItems;         cin >> nofItems;         tAmt += (nofItems * 5);         tAmt += 15;       }       minSec = min(tAmt, minSec);     }     cout << minSec;   }


#include <bits/stdc++.h>   using namespace std;      #define     F       first   #define     S       second   typedef pair<int, int>  pi;   typedef long long       ll;   const ll big = 1e6 + 9;   ll GCD(ll a,ll b)   {       if(!b)           return a;       return GCD(b, a % b);   }   ll LCM(ll a,ll b)   {       return a*b/GCD(a,b);   }      int main()   {ios_base::sync_with_stdio(0);       cin.tie(0);cout.tie(0);          ll t;       cin >> t;       while(t--)       {           string s, t;           cin >> s >> t;           ll n1 = s.size(), n2 = t.size();           ll lcm = LCM(n1,n2);           ll k1 = lcm/n1, k2 = lcm/n2;           k1--,k2--;              string s1 = s, t1 = t;           while(k1--)               s += s1;           while(k2--)               t += t1;           if(s == t)               cout << s <<   n ;           else               cout <<  -1 n ;       }          return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long int mod = 1e9 + 7;   bool sortbysec(const pair<int, int>& a, const pair<int, int>& b) {     return (a.second < b.second);   }   long long int modpower(long long int a, long long int b, long long int c) {     long long int res = 1;     while (b) {       if (b & 1LL) res = (res * a) % c;       a = (a * a) % c;       b >>= 1;     }     return res;   }   long long int gcd(long long int a, long long int b) {     if (a == 0) return b;     return gcd(b % a, a);   }   template <typename Arg1>   void __f(const char* name, Arg1&& arg1) {     cout << name <<   :   << arg1 <<   n ;   }   using namespace std;   const int INF = 987654321;   const int MOD = 1000000007;   const int N = 1e5 + 5;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int t;     cin >> t;     while (t--) {       int n, m;       cin >> n >> m;       int a[N], b[N];       for (int i = 1; i <= 1000; i++) {         a[i] = 0;       }       for (int i = 0; i < n; i++) {         int x;         cin >> x;         a[x]++;       }       int j = -1;       for (int i = 0; i < m; i++) {         cin >> b[i];         if (a[b[i]]) {           j = b[i];         }       }       if (j > 0)         cout <<  YES  <<   n  <<  1   << j <<   n ;       else         cout <<  NO  <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long power(long long x, long long y) {     if (y == 0)       return 1;     else {       long long result = power(x, y / 2) % 1000000007;       if (y % 2 == 0)         return (result % 1000000007 * result % 1000000007) % 1000000007;       else         return (result % 1000000007 * result % 1000000007 * x % 1000000007) %                1000000007;     }   }   long long gcd(long long a, long long b) {     if (b == 0)       return a;     else       return gcd(b, a % b);   }   long long lcm(long long a, long long b) { return (a / gcd(a, b)) * b; }   void solve() {     long long n, k;     cin >> n >> k;     vector<long long> v(n);     for (long long i = 0; i < n; i++) {       cin >> v[i];     }     long long start = -1;     long long sum = 0;     long long div = n / k;     long long minsum = INT_MAX;     for (long long i = 0; i < k; i++) {       sum = 0;       for (long long j = i; j < n; j = j + k) {         sum = sum + v[j];       }       if (sum < minsum) {         minsum = sum;         start = i + 1;       }     }     cout << start;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long t;     t = 1;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long n, i, count = 0;     cin >> n;     double a[n], j, ans = 0;     for (i = 0; i < n; i++) {       cin >> a[i];     }     sort(a, a + n);     for (i = n - 1; i >= 0; i--) {       if (count % 2 == 0) {         ans += 3.1415926536 * a[i] * a[i];         count++;       } else {         ans -= 3.1415926536 * a[i] * a[i];         count++;       }     }     cout << fixed << setprecision(9) << ans << endl;     return 0;   }


#include <bits/stdc++.h>   template <typename T>   void read(T& x) {     x = 0;     int flag = 1;     char c = getchar();     for (; !isdigit(c); c = getchar())       if (c ==  - ) flag = -1;     for (; isdigit(c); c = getchar()) x = x * 10 + c -  0 ;     x *= flag;   }   using namespace std;   const int maxn = 200010;   int n, q, f[maxn], sz[maxn], tp;   pair<int, int> sta[maxn], a[maxn];   bool ok[maxn];   struct info {     int l, r, u, v;     info() {}     info(int a, int b, int c, int d) { l = a, r = b, u = c, v = d; }   };   vector<info> seg;   int find(int x) { return f[x] == x ? f[x] : find(f[x]); }   bool check(int x) { return find(x) == find(x + n); }   void link(int u, int v) {     int r1 = find(u), r2 = find(v);     if (r1 == r2) return;     if (sz[r1] > sz[r2]) swap(r1, r2);     f[r1] = r2, sz[r2] += sz[r1], sta[++tp] = make_pair(r1, r2);   }   void cut(pair<int, int> t) {     int u = t.first, v = t.second;     if (f[v] == u) swap(u, v);     f[u] = u;     while (f[v] != v) sz[v] -= sz[u], v = f[v];     sz[v] -= sz[u];   }   map<pair<int, int>, int> mp;   vector<pair<int, int> > edge[maxn << 2];   void modify(int p, int l, int r, int ql, int qr, int u, int v) {     if (ql <= l && r <= qr) {       edge[p].push_back(make_pair(u, v));       return;     }     int mid = (l + r) >> 1;     if (ql <= mid) modify(p << 1, l, mid, ql, qr, u, v);     if (qr > mid) modify(p << 1 | 1, mid + 1, r, ql, qr, u, v);   }   void dfs(int p, int l, int r, bool flag) {     int mid = (l + r) >> 1, cur = tp;     for (int i = 0; i <= (int)edge[p].size() - 1; i++) {       if (!flag) continue;       int u = edge[p][i].first, v = edge[p][i].second;       link(u, v + n), link(v, u + n);       if (check(u) || check(v)) flag = 0;     }     if (l == r) {       puts(flag ?  YES  :  NO );       while (tp > cur) cut(sta[tp--]);       return;     }     dfs(p << 1, l, mid, flag), dfs(p << 1 | 1, mid + 1, r, flag);     while (tp > cur) cut(sta[tp--]);   }   int main() {     scanf( %d %d , &n, &q);     for (int i = 1; i <= (int)2 * n; i++) f[i] = i, sz[i] = 1;     for (int i = 1; i <= (int)q; i++) {       scanf( %d %d , &a[i].first, &a[i].second);       int tmp = mp[a[i]];       if (!tmp)         mp[a[i]] = i;       else {         ok[tmp] = ok[i] = 1, mp[a[i]] = 0;         seg.push_back(info(tmp, i - 1, a[i].first, a[i].second));       }     }     for (int i = 1; i <= (int)q; i++)       if (!ok[i]) seg.push_back(info(mp[a[i]], q, a[i].first, a[i].second));     for (int i = 0; i <= (int)seg.size() - 1; i++)       modify(1, 1, q, seg[i].l, seg[i].r, seg[i].u, seg[i].v);     dfs(1, 1, q, 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int IINF = INT_MAX;   const long long LLINF = LLONG_MAX;   inline bool LT(double a, double b) {     return !(fabs((a) - (b)) < (1e-8)) && a < b;   }   inline bool LTE(double a, double b) {     return (fabs((a) - (b)) < (1e-8)) || a < b;   }   void compute() {}   int main() {     string s;     cin >> s;     deque<char> deq;     int cnt = 0;     int n = s.size();     for (int i = 0; i < n; ++i) {       if (deq.empty()) {         deq.push_back(s[i]);       } else {         if (deq.back() == s[i]) {           deq.pop_back();           ++cnt;         } else {           deq.push_back(s[i]);         }       }     }     if (cnt % 2 == 0)       puts( No );     else       puts( Yes );     compute();     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   const int M = 500 + 5;   int board[M][M], dp[M][M];   int main() {     int n, m, k;     cin >> n >> m >> k;     for (int i = 0; i < n; i++) {       string s;       cin >> s;       for (int j = 0; j < m; j++) {         board[i + 1][j + 1] = s[j] -  0  + 0;       }     }     for (int row = 1; row <= n; row++) {       for (int col = 1; col <= m; col++) {         int num = 0;         num = num + (board[row][col] == 1);         num = num + (col - 1 >= 1 && col - 1 <= m && board[row][col - 1] == 1);         num = num + (col + 1 >= 1 && col + 1 <= m && board[row][col + 1] == 1);         num = num + (row + 1 >= 1 && row + 1 <= n && board[row + 1][col] == 1);         num = num + (row - 1 >= 1 && row - 1 <= n && board[row - 1][col] == 1);         dp[row][col] = dp[row][col - 1] + (num == 5);       }     }     long long int ans = 0;     for (int col1 = 1; col1 <= m; col1++) {       for (int col2 = col1 + 2; col2 <= m; col2++) {         int p1 = 1;         int p2 = 3;         int numstar = dp[p2 - 1][col2 - 1] - dp[p2 - 1][col1];         while (p2 <= n) {           while (p2 <= n && numstar < k) {             p2++;             numstar = numstar + dp[p2 - 1][col2 - 1] - dp[p2 - 1][col1];           }           if (p2 <= n && numstar >= k) {             ans = ans + n - p2 + 1;             numstar = numstar - (dp[p1 + 1][col2 - 1] - dp[p1 + 1][col1]);             p1++;             while (p1 + 2 <= p2 && numstar >= k) {               numstar = numstar - (dp[p1 + 1][col2 - 1] - dp[p1 + 1][col1]);               p1++;               ans = ans + n - p2 + 1;               if (p1 + 2 > p2) {                 break;               }             }           }         }       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   T abs(T x) {     return x > 0 ? x : -x;   }   template <typename T>   T sqr(T x) {     return x * x;   }   template <typename T>   ostream &operator<<(ostream &s, const vector<T> &x) {     s <<  [ ;     for (auto it : x) {       s <<  it          <<  ,  ;     }     s <<  ] ;     return s;   }   template <typename T>   ostream &operator<<(ostream &s, const set<T> &x) {     s <<  { ;     for (auto it : x) {       s <<  it          <<  ,  ;     }     s <<  } ;     return s;   }   vector<pair<long long, long long> > a[5];   int main() {     int n, k, b, c;     cin >> n >> k >> b >> c;     if (b > c * 5) b = c * 5;     for (int i = 1; i <= n; i++) {       int x;       cin >> x;       for (int i = 0; i < 5; i++)         a[((x + i) % 5 + 5) % 5].push_back(make_pair(x + i, i * c));     }     long long ans = 1e18;     for (int i = 0; i < 5; i++) {       sort(a[i].begin(), a[i].end());       auto v = a[i];       bool flag = false;       long long firstpos = -1;       multiset<long long> setic;       long long allsum = 0;       for (auto f : v) {         long long pos = f.first, w = f.second;         if (!flag) {           flag = true;           firstpos = pos;         }         w -= (pos - firstpos) / 5 * b;         allsum += w;         setic.insert(w);         if ((int)setic.size() > k) {           auto it = setic.end();           it--;           allsum -= *it;           setic.erase(it);         }         if ((int)setic.size() == k) {           ans = min(ans, allsum + (long long)k * (pos - firstpos) / 5 * b);         }       }     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   inline int read() {     int data = 0, w = 1;     char ch = getchar();     while (ch !=  -  && !std::isdigit(ch)) ch = getchar();     if (ch ==  - ) w = -1, ch = getchar();     while (std::isdigit(ch)) data = data * 10 + (ch ^ 48), ch = getchar();     return data * w;   }   const int N(1e5 + 10);   std::vector<int> G[N];   int n, m, val[N], fa[N], size[N], heavy[N];   int dfn[N], pos[N], bel[N], bot[N], cnt, ans;   void dfs(int x) {     size[x] = 1;     for (auto i : G[x]) {       dfs(i), size[x] += size[i];       if (size[heavy[x]] < size[i]) heavy[x] = i;     }   }   void dfs(int x, int c) {     pos[dfn[x] = ++cnt] = x, bel[x] = c, bot[bel[x]] = x;     if (heavy[x]) dfs(heavy[x], c);     for (auto i : G[x])       if (i != heavy[x]) dfs(i, i);   }   struct Chain {     int L, B, cnt;     std::vector<int> tag, bel, v, bl, br, vis;     std::vector<std::vector<int>> t;     void build(int l, int r) {       L = r - l + 1, B = std::sqrt(L), cnt = (L - 1) / B + 1;       tag.resize(cnt + 1), bel.resize(L + 1), vis.resize(L + 1);       bl.resize(cnt + 1), br.resize(cnt + 1), v.resize(L + 1);       for (int i = 1; i <= L; i++) bel[i] = (i - 1) / B + 1;       for (int i = 1; i <= L; i++) br[bel[i]] = i;       for (int i = L; i >= 1; i--) bl[bel[i]] = i;       t.assign(cnt + 1, std::vector<int>(B << 1 | 1));       for (int i = 1; i <= L; i++) v[i] = val[pos[i + l - 1]];       for (int i = 1; i <= L; i++)         if ((-B <= (v[i]) && (v[i]) <= B)) ++t[bel[i]][v[i] + B];     }     void rebuild(int x) {       for (int i = bl[x]; i <= br[x]; i++) v[i] -= tag[x];       tag[x] = 0, t[x].assign(B << 1 | 1, 0);       for (int i = bl[x]; i <= br[x]; i++)         if (!vis[i]) {           if ((-B <= (v[i]) && (v[i]) <= B)) ++t[x][v[i] + B];           if (v[i] <= tag[x]) ++ans;         }     }     void Brute_Modify(int x, int l, int r, int d) {       for (int i = l; i <= r; i++)         if (!vis[i]) {           if ((-B <= (v[i]) && (v[i]) <= B)) --t[x][v[i] + B];           if (v[i] <= tag[x]) --ans;         }       for (int i = l; i <= r; i++) v[i] += d;       for (int i = l; i <= r; i++)         if (!vis[i]) {           if ((-B <= (v[i]) && (v[i]) <= B)) ++t[x][v[i] + B];           if (v[i] <= tag[x]) ++ans;         }     }     void Modify(int l, int r, int d) {       if (bel[l] == bel[r]) return Brute_Modify(bel[l], l, r, -d);       for (int i = bel[l] + 1; i < bel[r]; i++) {         tag[i] += d;         if (!(-B <= (tag[i]) && (tag[i]) <= B)) {           for (int j = bl[i]; j <= br[i]; j++)             if (!vis[j] && v[j] <= tag[i] - d) --ans;           rebuild(i);         } else if (d == 1)           ans += t[i][tag[i] + B];         else           ans -= t[i][tag[i] + B + 1];       }       Brute_Modify(bel[l], l, br[bel[l]], -d);       Brute_Modify(bel[r], bl[bel[r]], r, -d);     }     void recol(int x, int d) {       int b = bel[x];       vis[x] = (d == 1);       if ((-B <= (v[x]) && (v[x]) <= B)) t[b][v[x] + B] -= d;       if (v[x] <= tag[b]) ans -= d;     }   } b[N];   int main() {     n = read(), m = read();     for (int i = 2; i <= n; i++) G[fa[i] = read()].push_back(i);     for (int i = 1; i <= n; i++) val[i] = read() + 1;     dfs(1), dfs(1, 1);     for (int i = 1; i <= n; i++)       if (bel[i] == i) b[i].build(dfn[i], dfn[bot[i]]);     for (int i = 1, x, o; i <= m; printf( %d  , ans), i++) {       x = read(), o = 1;       if (x < 0) o = -1, x = -x;       b[bel[x]].recol(dfn[x] - dfn[bel[x]] + 1, o);       for (; x; b[bel[x]].Modify(1, dfn[x] - dfn[bel[x]] + 1, o), x = fa[bel[x]])         ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxLog = 10;   const int maxN = 1 << maxLog;   const int INF = 0x3c3c3c3c;   int f[333];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     string s;     cin >> s;     vector<int> a(n);     f[ > ] = 1;     f[ < ] = -1;     for (auto &x : a) {       cin >> x;     }     int v = 0;     for (int i = 0; i < n * 2 + 2; i++) {       int j = f[s[v]] * a[v];       v += j;       if (!(0 <= v && v < n)) {         cout <<  FINITE  << endl;         return 0;       }     }     cout <<  INFINITE  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long a, b, ans;     scanf( %lld%lld , &b, &a);     ans = (b + 1) % 10;     if (a == b) ans = 1;     for (long long i = b + 2; i <= a; i++) {       if (i % 10 == 0) {         ans = 0;         break;       }       ans *= i % 10;     }     printf( %lld n , ans % 10);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k, q;     cin >> n >> k >> q;     vector<int> A(n);     set<int> S;     for (int i = 0; i < n; ++i) cin >> A[i];     int ty, id;     for (int i = 0; i < q; ++i) {       cin >> ty >> id;       if (ty == 1) {         S.insert(A[id - 1]);         if (S.size() > k) {           S.erase(S.begin());         }       } else {         if (S.find(A[id - 1]) != S.end())           cout <<  YES  << endl;         else           cout <<  NO  << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using uint = unsigned int;   using pii = pair<int, int>;   using vi = vector<int>;   int main() {     int t;     cin >> t;     while (t--) {       int a, b;       cin >> a >> b;       if (a % b == 0)         cout <<  YES n ;       else         cout <<  NO n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, a, odd = 0, even = 0;     cin >> n;     while (n--) {       cin >> a;       if (a % 2 == 0) {         even += 1;       } else {         odd += 1;       }     }     cout << (odd % 2 == 1 ? odd : even) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     double n, m, a[1001], b[1001], litri = 0, ok = 1;     cin >> n >> m;     double copie = m;     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = 1; i <= n; i++) cin >> b[i];     litri = m / (b[1] - 1);     for (int i = n; i >= 1; i--) {       m = m + litri;       litri = m / (a[i] - 1);       m = m + litri;       litri = m / (b[i] - 1);       if (a[i] == 1 || b[i] == 1) ok = 0;     }     double diferenta;     diferenta = m - copie;     if (ok == 0)       cout << -1;     else       cout << fixed << setprecision(10) << diferenta;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   ifstream fin( test.in );   double i, j, sens, k, o, ta, tb, pasi, p, d, pl, haur, n;   int a, b, t, f, c;   int main() {     cin >> a >> b >> t >> f >> c;     k = 1000;     ta = a / k;     tb = b / k;     p = a * t;     sens = 1;     while (p < c) {       n = 0;       while (p + a > d + b && p < c) {         p += a;         d += b;         n += a;       }       while (p > d && p < c) {         p += ta;         d += tb;         n += ta;       }       if (p < c && p != c) ++haur;       d = 0;       p += n + a * f;     }     cout << haur;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   signed main() {     char opr[40];     while ((~scanf( %s , opr)) && opr[0] ==  s ) {       int x = 0, y = 1;       while (1) {         printf( ? %d %d n , x, y);         fflush(stdout);         char ans[20];         scanf( %s , ans);         if (ans[0] ==  x ) break;         x = y, y = y * 2 + 1;       }       int mid;       int l = x, r = y;       while (l + 1 < r) {         mid = (l + r) >> 1;         printf( ? %d %d n , l, mid);         fflush(stdout);         char ans[20];         scanf( %s , ans);         if (ans[0] ==  y )           l = mid;         else           r = mid;       }       if (l == 0) {         printf( ! 1 n );         fflush(stdout);         continue;       }       printf( ? %d %d n , r, r + 1);       fflush(stdout);       char ans[20];       scanf( %s , ans);       if (ans[0] ==  x ) r--;       printf( ! %d n , r);       fflush(stdout);     }   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using pii = pair<int, int>;   using pll = pair<ll, ll>;   using pil = pair<int, ll>;   using pli = pair<ll, int>;   using vs = vector<string>;   using vvs = vector<vs>;   using vvvs = vector<vvs>;   using vb = vector<bool>;   using vvb = vector<vb>;   using vvvb = vector<vvb>;   using vi = vector<int>;   using vvi = vector<vi>;   using vvvi = vector<vvi>;   using vl = vector<ll>;   using vvl = vector<vl>;   using vvvl = vector<vvl>;   using vd = vector<double>;   using vvd = vector<vd>;   using vvvd = vector<vvd>;   using vpii = vector<pii>;   using vvpii = vector<vpii>;   using vvvpii = vector<vvpii>;   template <class T>   bool amax(T &a, const T &b) {     if (a < b) {       a = b;       return 1;     }     return 0;   }   template <class T>   bool amin(T &a, const T &b) {     if (b < a) {       a = b;       return 1;     }     return 0;   }   ll ri() {     ll l;     cin >> l;     return l;   }   string rs() {     string s;     cin >> s;     return s;   }   template <class T>   T read() {     T t;     cin >> t;     return t;   }   template <class T, class U>   ostream &operator<<(ostream &o, const pair<T, U> &p) {     return o <<  (  << p.first <<  ,   << p.second <<  ) ;   }   ostream &operator<<(ostream &o, const vb &t) {     for (auto &&e : t) o <<  #. [e];     return o;   }   template <class T>   ostream &operator<<(ostream &o, const vector<T> &t) {     o <<  { ;     for (auto &&e : t) o << e <<  , ;     o <<  }  << endl;     return o;   }   void panic() {     cout <<  NO  << endl;     exit(0);   }   string solve() {     int n = ri();     int k = ri();     auto s = rs();     int w = 0, l = 0, d = 0, u = 0;     for (auto &&c : s) {       if (c ==  W )         w++;       else if (c ==  L )         l++;       else if (c ==  D )         d++;       else if (c ==  ? )         u++;     }     vvi dp(n + 1, vi(2 * k + 1));     vvi fp(n + 1, vi(2 * k + 1));     if (s[n - 1] ==  D ) {       panic();     }     if (s[n - 1] ==  W  || s[n - 1] ==  ? ) {       dp[n][k + k] = 1;     }     if (s[n - 1] ==  L  || s[n - 1] ==  ? ) {       dp[n][0] = 1;     }     for (int i = int(n) - 1; i >= int(0); i--)       for (int j = int(1); j < int(2 * k); ++j) {         char r = s[i];         if (r ==  W  || r ==  ? ) {           if (amax(dp[i][j], dp[i + 1][j + 1])) {             fp[i][j] = j + 1;           }         }         if (r ==  L  || r ==  ? ) {           if (amax(dp[i][j], dp[i + 1][j - 1])) {             fp[i][j] = j - 1;           }         }         if (r ==  D  || r ==  ? ) {           if (amax(dp[i][j], dp[i + 1][j])) {             fp[i][j] = j;           }         }       };     ;     if (dp[0][k] == 0) panic();     vi A;     {       int x = k;       for (int i = int(0); i < int(n + 1); ++i) {         A.emplace_back(x);         x = fp[i][x];       }     };     string ans;     for (int i = int(0); i < int(n); ++i) {       if (A[i] == A[i + 1])         ans +=  D ;       else if (A[i] > A[i + 1])         ans +=  L ;       else if (A[i] < A[i + 1])         ans +=  W ;     };     ;     for (int i = int(0); i < int(n); ++i) {       assert(s[i] ==  ?  || ans[i] == s[i]);     }     return ans;   }   void Main() { cout << solve() << endl; }   int main() {     cin.tie(nullptr);     ios::sync_with_stdio(false);     Main();     return 0;   }


#include <bits/stdc++.h>   char s[128];   bool ce(char r, char a, char b, char c) { return r == a || r == b || r == c; }   bool spcmp(char a, char b, char c) {     return ce( A , a, b, c) && ce( B , a, b, c) && ce( C , a, b, c);   }   int main() {     int n, i;     scanf( %s , s);     for (i = 1; s[i + 1] !=   0 ; i++) {       if (spcmp(s[i - 1], s[i], s[i + 1])) {         printf( Yes n );         return 0;       }     }     printf( No n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n, k, x, y, res = 0;       cin >> n >> k;       vector<vector<int>> gr(n + 1);       vector<int> deg(n + 1, 0), ch(n + 1, 0), nxt;       for (int i = 0; i < n - 1; i++) {         cin >> x >> y;         gr[x].push_back(y);         gr[y].push_back(x);         deg[x]++;         deg[y]++;       }       for (int i = 1; i <= n; i++) {         if (deg[i] == 1) {           int par = gr[i].front();           ch[par]++;           if (ch[par] >= k) {             nxt.push_back(par);           }         }       }       while (!nxt.empty()) {         int a = nxt.back();         nxt.pop_back();         if (ch[a] < k) {           continue;         }         vector<int> del;         for (int i = 0; i < gr[a].size(); i++) {           if (deg[gr[a][i]] == 1) {             del.push_back(i);           }         }         res += del.size() / k;         while (del.size() % k != 0) {           del.pop_back();         }         ch[a] -= del.size();         for (int i = del.size() - 1; i >= 0; i--) {           gr[a].erase(gr[a].begin() + del[i]);         }         deg[a] -= del.size();         if (deg[a] == 1) {           int par = gr[a].front();           ch[par]++;           if (ch[par] >= k) {             nxt.push_back(par);           }         }       }       cout << res << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int oo = (int)1e9;   const double PI = 2 * acos(0.0);   const double eps = 1e-9;   int main() {     int a, b, c, d;     cin >> a >> b >> c >> d;     int foo = max(3 * a / 10, a - a / 250 * c);     int bar = max(3 * b / 10, b - b / 250 * d);     if (foo == bar)       cout <<  Tie  << endl;     else if (foo > bar)       cout <<  Misha  << endl;     else       cout <<  Vasya  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int a[n + 1];     for (int i = 1; i < n + 1; i++) {       cin >> a[i];     }     int s = 0;     int arr[n + 1], max;     max = INT_MIN;     memset(arr, 0, sizeof(arr));     for (int i = 1; i < n + 1; i++) {       if (a[i] == 1) {         arr[i] = arr[i - 1] + 1;       } else {         arr[i] = 0;       }       if (arr[i] > max) {         max = arr[i];       }     }     if (arr[n] != 0) {       int j = 1;       while (arr[j] != 0) {         arr[n]++;         j++;       }       if (arr[n] > max) {         max = arr[n];       }     }     cout << max;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double inf = 1e7;   const double eps = 1e-7;   int main() {     int n, width, height, begin0, begin1;     cin >> n >> width >> height >> begin0 >> begin1;     vector<pair<int, pair<double, double>>> a(n + 1);     a[0] = make_pair(0, make_pair(1, begin1 - begin0));     for (int i = 1; i <= n; ++i) {       int x, y;       cin >> a[i].first >> x >> y;       a[i].second = make_pair(1 - (double)height / y, (double)x * height / y);     }     auto check = [&](double v) {       double l = begin0, r = begin0;       for (int i = 1; i <= n; ++i) {         double delta = v * (a[i].first - a[i - 1].first);         double k0 = a[i - 1].second.first, b0 = a[i - 1].second.second;         double k1 = a[i].second.first, b1 = a[i].second.second;         double k = k0 / k1, tl, tr;         if (k1 > 0) {           tl = (b0 - delta - b1) / k1;           tr = (b0 + delta - b1) / k1;         } else {           tl = (b0 + delta - b1) / k1;           tr = (b0 - delta - b1) / k1;         }         if (fabs(k0 - k1) < eps) {           tl = max(tl, -delta);           tr = min(tr, delta);           if (tl > tr + eps) {             return false;           }           l += tl;           r += tr;         } else {           double ml = (tl + delta) / (1 - k), mr = (tr - delta) / (1 - k);           double nl = inf, nr = -inf;           if (k > 1) {             {               double left = max(l, mr), right = min(r, ml);               if (right >= left - eps) {                 nl = min(nl, left - delta);                 nr = max(nr, right + delta);               }             }             {               double left = max(l, max(ml, mr)), right = r;               if (right >= left - eps) {                 right = min(right, (delta - tl) / (k - 1));                 if (right >= left - eps) {                   nl = min(nl, k * left + tl);                   nr = max(nr, right + delta);                 }               }             }             {               double left = l, right = min(r, min(ml, mr));               if (right >= left - eps) {                 left = max(left, -(delta + tr) / (k - 1));                 if (right >= left - eps) {                   nl = min(nl, left - delta);                   nr = max(nr, k * right + tr);                 }               }             }             {               double left = max(l, ml), right = min(r, mr);               if (right >= left - eps) {                 nl = min(nl, k * left + tl);                 nr = max(nr, k * right + tr);               }             }           } else {             {               double left = max(l, ml), right = min(r, mr);               if (right >= left - eps) {                 if (k > 0) {                   nl = min(nl, k * left + tl);                   nr = max(nr, k * right + tr);                 } else {                   nl = min(nl, k * right + tl);                   nr = max(nr, k * left + tr);                 }               }             }             {               double left = l, right = min(r, min(ml, mr));               if (right >= left - eps) {                 left = max(left, (tl - delta) / (1 - k));                 if (right >= left - eps) {                   if (k > 0) {                     nl = min(nl, k * left + tl);                   } else {                     nl = min(nl, k * right + tl);                   }                   nr = max(nr, right + delta);                 }               }             }             {               double left = max(l, max(ml, mr)), right = r;               if (right >= left - eps) {                 right = min(right, (tr + delta) / (1 - k));                 if (right >= left - eps) {                   nl = min(nl, left - delta);                   if (k > 0) {                     nr = max(nr, k * right + tr);                   } else {                     nr = max(nr, k * left + tr);                   }                 }               }             }             {               double left = max(l, mr), right = min(r, ml);               if (right >= left - eps) {                 nl = min(nl, left - delta);                 nr = max(nr, right + delta);               }             }           }           if (nl > nr + eps) {             return false;           }           l = nl;           r = nr;         }         l = max(l, (double)0);         r = min(r, (double)width);         if (k1 > 0) {           l = max(l, -b1 / k1);           r = min(r, (width - b1) / k1);         } else {           l = max(l, (width - b1) / k1);           r = min(r, -b1 / k1);         }         if (l > r + eps) {           return false;         }       }       return true;     };     if (!check(width + 1)) {       cout << -1 << endl;     } else {       double l = 0, r = width;       for (int t = 0; t < 50; ++t) {         double m = (l + r) / 2;         if (check(m)) {           r = m;         } else {           l = m;         }       }       cout << fixed << setprecision(6) << r << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long p[10], n, res;   int main() {     std::ios::sync_with_stdio(0);     cin.tie(0);     cin >> n;     p[1] = 2;     p[2] = 3;     p[3] = 5;     p[4] = 7;     res = 0;     for (int a = 1; a <= 4; a++) res += n / p[a];     for (int a = 1; a <= 4; a++)       for (int b = a + 1; b <= 4; b++) res -= n / (p[a] * p[b]);     for (int a = 1; a <= 4; a++)       for (int b = a + 1; b <= 4; b++)         for (int c = b + 1; c <= 4; c++) res += n / (p[a] * p[b] * p[c]);     for (int a = 1; a <= 4; a++)       for (int b = a + 1; b <= 4; b++)         for (int c = b + 1; c <= 4; c++)           for (int d = c + 1; d <= 4; d++) res -= n / (p[a] * p[b] * p[c] * p[d]);     res = n - res;     cout << res <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n, x, a, b;       cin >> n >> x >> a >> b;       int ans = abs(b - a) + x;       ans = min(ans, n - 1);       cout << ans << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   bool isPal(string s, long long l, long long r) {     while (l < r) {       if (s[l] != s[r]) return false;       l++;       r--;     }     return true;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     string s;     cin >> s;     long long ans = 0;     for (long long i = 0; i < s.size(); i++) {       for (long long j = i; j < s.size(); j++) {         if (!isPal(s, i, j)) {           if (ans < j - i + 1) ans = j - i + 1;         }       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void test() { cerr <<   n ; }   template <typename T, typename... Args>   void test(T x, Args... args) {     cerr << x <<    ;     test(args...);   }   const int MAXN = (int)1e6 + 5;   const int MOD = (int)1e9 + 7;   void solve() {     int n;     cin >> n;     vector<int> a(n);     for (int i = 0; i < n; i++) cin >> a[i];     long long sum = 0, ma = a[0], mi = 0;     for (int i = 0; i < n; i++) {       sum += a[i];       if (i == 0) {         mi = sum;       } else {         ma = max(ma, sum - mi);         mi = min(mi, sum);       }       if (i != n - 1) ma = max(ma, sum);     }     cout << (sum > ma ?  YES  :  NO ) <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int T;     cin >> T;     while (T--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MSIZE = 1e3 + 5;   const int MOD = 1e9 + 7;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     cin >> t;     while (t--) {       int n, k;       cin >> n >> k;       string s;       cin >> s;       int cnt[26] = {0};       for (char c : s) cnt[c -  a ]++;       int os = 0;       for (int i = 0; i <= 25; i++) {         if (cnt[i] >= k - os) {           cnt[i] -= (k - os);           cout << (char)( a  + i);           break;         }         os += cnt[i];         cnt[i] = 0;       }       if (os) {         cout << endl;         continue;       }       bool pr = 0;       for (int i = 0; i <= 25; i++) {         if (cnt[i] and cnt[i] == n - k) {           int val = cnt[i] / k + (cnt[i] % k != 0);           while (val--) cout << (char)( a  + i);           break;         }         while (cnt[i]--) cout << (char)( a  + i);       }       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:16777216 )   const int INF = (int)1e9;   using namespace std;   template <class T>   T abs(T x) {     return x < 0 ? -x : x;   }   template <class T>   T sqr(T x) {     return x * x;   }   int n;   int x[1000], y[1000];   bool used[1000];   void dfs(int v) {     used[v] = true;     for (int i = 0; i < n; ++i) {       if ((!used[i]) && (x[v] == x[i] || y[v] == y[i])) {         dfs(i);       }     }   }   int main() {     cin >> n;     for (int i = 0; i < n; ++i) cin >> x[i] >> y[i];     memset(used, false, sizeof(used));     int ans = -1;     for (int j = 0; j < n; ++j) {       if (!used[j]) {         ans++;         dfs(j);       }     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct node {     int v, c;     node *opp, *next;   } Map[500];   node *List[110];   int d[110], vd[110];   int e, n;   int a[110], p1[110], p2[110], N, M;   bool b[100000 + 10];   int prime[100000 + 10], Nprime = 0;   void addedge(int i, int j, int c) {     Map[++e].v = j;     Map[e].c = c;     Map[e].opp = &Map[e + 1];     Map[e].next = List[i];     List[i] = &Map[e];     Map[++e].v = i;     Map[e].c = 0;     Map[e].opp = &Map[e - 1];     Map[e].next = List[j];     List[j] = &Map[e];   }   int dfs(int i, int flow) {     int j, temp, ff = 0;     node *u;     if (i == n) return (flow);     u = List[i];     while (u != NULL) {       j = u->v;       if (u->c > 0 && d[i] == d[j] + 1) {         temp = dfs(j, min(u->c, flow - ff));         u->c = u->c - temp;         u->opp->c = u->opp->c + temp;         ff += temp;         if (ff == flow) return (flow);       }       u = u->next;     }     if (d[1] >= n) return (ff);     vd[d[i]]--;     if (vd[d[i]] == 0) d[1] = n;     d[i]++;     vd[d[i]]++;     return (ff);   }   void getprime() {     for (int i = 2; i <= 100000; i++) {       if (!b[i]) {         prime[++Nprime] = i;         for (int j = i + i; j <= 100000; j += i) b[j] = true;       }     }   }   int solve(int k) {     e = 0;     for (int i = 0; i < 110; i++) List[i] = NULL;     for (int i = (1); i <= (M); ++i) {       int t1 = a[p1[i]], t2 = a[p2[i]];       int count = 0;       while (t1 % k == 0 && t2 % k == 0) {         t1 /= k;         t2 /= k;         count++;       }       if (p1[i] % 2 == 1)         addedge(p1[i] + 1, p2[i] + 1, count);       else         addedge(p2[i] + 1, p1[i] + 1, count);     }     for (int i = (1); i <= (N); ++i) {       int count = 0;       while (a[i] % k == 0) {         a[i] /= k;         count++;       }       if (i % 2 == 1)         addedge(1, i + 1, count);       else         addedge(i + 1, N + 2, count);     }     n = N + 2;     memset(d, 0, sizeof(d));     memset(vd, 0, sizeof(vd));     vd[0] = n;     int maxflow = 0;     while (d[1] <= n - 1) maxflow = maxflow + dfs(1, 100000000);     return maxflow;   }   int main() {     getprime();     scanf( %d%d , &N, &M);     for (int i = (1); i <= (N); ++i) scanf( %d , a + i);     for (int i = (1); i <= (M); ++i) scanf( %d%d , p1 + i, p2 + i);     int ans = 0;     for (int i = (1); i <= (Nprime); ++i) ans += solve(prime[i]);     for (int i = (1); i <= (N); ++i)       if (a[i] > 1) ans += solve(a[i]);     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long nC2(int n) {     if (n == 0) return 0;     return ((long long)n * (n - 1)) / 2;   }   void solve() {     int n, m;     scanf( %d %d , &n, &m);     long long Kmin, Kmax;     int r = n % m;     Kmin = nC2((n + m - 1) / m) * r + nC2(n / m) * (m - r);     Kmax = nC2(n - m + 1);     printf( %lld %lld n , Kmin, Kmax);   }   int main() {     int tt;     tt = 1;     for (int i = 0; i < tt; ++i) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int oo = 1e9;   const int mx = 1e3 + 10;   const int mxd = (1 << 13) + 10;   long long int a[mx], b[mx];   vector<long long int> divs;   pair<int, long long int> f[mx][mxd];   long long int gcd(long long int a, long long int b) {     if (b == 0) return a;     return gcd(b, a % b);   }   int main() {     int n;     long long int k;     scanf( %d %lld , &n, &k);     long long int g = k;     for (int i = 1; i <= n; i++) {       scanf( %lld , a + i);       b[i] = gcd(k, a[i]);       g /= gcd(g, a[i]);     }     if (g != 1) {       puts( -1 );       return 0;     }     if (k == 1) {       puts( 1 );       int idx = min_element(a + 1, a + 1 + n) - a;       printf( %d n , idx);       return 0;     }     for (long long int d = 1; d * d <= k; d++) {       if (k % d == 0) {         divs.push_back(d);         if (d != k / d) divs.push_back(k / d);       }     }     sort(divs.begin(), divs.end());     divs.resize(unique(divs.begin(), divs.end()) - divs.begin());     int nd = divs.size();     unordered_map<long long int, int> mp;     for (int i = 0; i < int(divs.size()); i++) mp[divs[i]] = i;     for (int d = 1; d < nd; d++) f[0][d] = pair<int, long long int>(oo, 0ll);     for (int i = 1; i <= n; i++) {       for (int d = 1; d < nd; d++) {         f[i][d] = f[i - 1][d];         long long int x = divs[d] / gcd(divs[d], b[i]);         int idx = mp[x];         pair<int, long long int> bet(f[i - 1][idx].first + 1,                                      a[i] + f[i - 1][idx].second);         f[i][d] = min(f[i][d], bet);       }     }     int pos = n, x = nd - 1;     printf( %d n , f[n][nd - 1].first);     int c = 0;     while (c < f[n][nd - 1].first) {       if (f[pos][x] == f[pos - 1][x])         pos--;       else {         printf( %d  , pos);         long long int nx = divs[x] / gcd(divs[x], b[pos]);         x = mp[nx];         pos--;         c++;       }     }     puts(  );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     long long q;     long long m;     cin >> q >> m;     long long j = 0;     vector<pair<long long, long long>> spells;     spells.push_back({0, 0});     for (int i = 0; i < q; i++) {       long long k, a, b;       cin >> k >> a >> b;       if (k == 1) {         long long x = 1 + (a + j) % 1000000;         long long y = 1 + (b + j) % 1000000;         long long l = -1;         long long r = spells.size();         while (l + 1 != r) {           long long mid = (r + l) / 2;           if (spells[mid].first < x)             l = mid;           else             r = mid;         }         if (r == spells.size() ||             (spells[r].second - spells[r - 1].second) *                     (x - spells[r - 1].first) >                 (y - spells[r - 1].second) *                     (spells[r].first - spells[r - 1].first)) {           spells.insert(spells.begin() + r, {x, y});           long long shift = 0;           while (r - shift > 1) {             if ((spells[r].second - spells[r - shift - 2].second) *                     (spells[r - shift - 1].first - spells[r - shift - 2].first) >                 (spells[r - shift - 1].second - spells[r - shift - 2].second) *                     (spells[r].first - spells[r - shift - 2].first))               break;             shift++;           }           if (shift > 0)             spells.erase(spells.begin() + r - shift, spells.begin() + r);         }       } else {         long long t = 1 + (a + j) % 1000000;         long long h = 1 + (b + j) % 1000000;         long long l = -1;         long long r = spells.size();         if (h > spells[r - 1].first * t) {           cout <<  NO n ;           continue;         }         while (l + 1 != r) {           long long mid = (r + l) / 2;           if (spells[mid].first * t < h)             l = mid;           else             r = mid;         }         if (spells[r - 1].second * (t * spells[r].first - h) +                 spells[r].second * (h - t * spells[r - 1].first) <=             m * (spells[r].first - spells[r - 1].first)) {           cout <<  YES n ;           j = i + 1;         } else           cout <<  NO n ;       }     }   }


#include <stdio.h>   #include <iostream>   #include <vector>   #include <unordered_set>   #include <math.h>   #include <time.h>   #include <algorithm>   #include <string.h>   #include <string>   #include <deque>   #include <ctype.h>   #include <limits.h>   #include <map>   #include <set>   #include <unordered_map>   #include <stack>   #include <queue>   #include <functional>   #include <limits.h>   #include <random>      using namespace std;   typedef long long ll;      void solve();      mt19937 rng(time(0));      ll qpow(ll x, ll p, ll MOD) {       ll res = 1, v = x;       while (p) {           if(p & 1) {               res *= v;               res %= MOD;           }           v *= v;           v %= MOD;           p >>= 1;       }       return res;   }      ll inv(ll x, ll MOD) {       return qpow(x, MOD - 2, MOD);   }      void init() {   #ifdef _LOCAL_        if(!freopen( case.txt ,  r , stdin)) {           perror( open file failed!: );           exit(1);       }       if(!freopen( main.ans ,  w , stdout)) {           perror( open file failed!: );           exit(1);       }   #endif   }       #ifdef _LOCAL_   void dbg_out() { cerr << endl; }   template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr <<     << H; dbg_out(T...); }   #   define dbg(...) cerr <<  (  << #__VA_ARGS__ <<  ): , dbg_out(__VA_ARGS__)   #else   #   define dbg(...)   #endif      ll read() {       int ch = getchar();       if(ch == EOF) {           return INT_MIN;       }       while(!isdigit(ch) && ch !=  - ) {           ch = getchar();           if(ch == EOF) {               return INT_MIN;           }       }       ll res = 0, sign = 1;       if(ch ==  - ) {           ch = getchar();           sign = -1;       }       while(isdigit(ch)) {           res = res * 10 + ch -  0 ;           ch = getchar();       }       return res * sign;   }      int main() {       init();       solve();       return 0;   }   /** 写之前 :     *  1. MAXN 是否定义正确？    */   /*********************code start here*********************/   int a[505][505];   int sa[1100] = {0}, fa[1100];   void solve() {       int n = read();       for(int i = 0; i < n; ++i) {           for(int j = 0; j < n; ++j) {               a[i][j] = read();           }       }       memset(fa, -1, sizeof(fa));       int sz = n;       for(int i = 0; i < n; ++i) {           sa[i] = a[i][i];           for(int j = i+1; j < n; ++j) {               if(fa[j] == -1) {                   int p = i;                   while(fa[p] != -1 && sa[fa[p]] < a[i][j]) {                       p = fa[p];                   }                   if(fa[p] == -1) {                       fa[p] = sz++;                       sa[fa[p]] = a[i][j];                   }                   if(sa[fa[p]] == a[i][j]) {                       fa[j] = fa[p];                   } else {                       int up = fa[p];                       fa[j] = fa[p] = sz++;                       fa[fa[p]] = up;                       sa[fa[p]] = a[i][j];                   }               } else {                   int ti = i, tj = j;                   while(sa[fa[ti]] < a[i][j]) {                       ti = fa[ti];                   }                   while(sa[fa[tj]] < a[i][j]) {                       tj = fa[tj];                   }                   if(sa[fa[ti]] == a[i][j]) {                       fa[tj] = fa[ti];                   } else if(sa[fa[tj]] == a[i][j]) {                       fa[ti] = fa[tj];                   } else {                       int up = fa[ti];                       fa[ti] = fa[tj] = sz++;                       fa[fa[ti]] = up;                       sa[fa[ti]] = a[i][j];                   }               }           }       }       printf( %d n , sz);       for(int i = 0; i < sz; ++i) {           printf( %d  , sa[i]);       }       printf(  n );       for(int i = 0; i < sz; ++i) {           if(fa[i] == -1) {               printf( %d n , i + 1);               break;           }       }       for(int i = 0; i < sz; ++i) {           if(fa[i] != -1) {               printf( %d %d n , i + 1, fa[i] + 1);           }       }   }      /** 提交前检查 :     *  1. 答案和中间结果是否应该是 ll?    *  2. 是否还有没有读入的数据？    *  3. 是否有 n = 1 的情况？    */


#include <bits/stdc++.h>   using namespace std;   void __print(int x) { cerr << x; }   void __print(long x) { cerr << x; }   void __print(long long x) { cerr << x; }   void __print(unsigned x) { cerr << x; }   void __print(unsigned long x) { cerr << x; }   void __print(unsigned long long x) { cerr << x; }   void __print(float x) { cerr << x; }   void __print(double x) { cerr << x; }   void __print(long double x) { cerr << x; }   void __print(char x) { cerr <<      << x <<     ; }   void __print(const char *x) { cerr <<     << x <<    ; }   void __print(const string &x) { cerr <<     << x <<    ; }   void __print(bool x) { cerr << (x ?  true  :  false ); }   template <typename T, typename V>   void __print(const pair<T, V> &x) {     cerr <<  { ;     __print(x.first);     cerr <<  , ;     __print(x.second);     cerr <<  } ;   }   template <typename T>   void __print(const T &x) {     int f = 0;     cerr <<  { ;     for (auto &i : x) cerr << (f++ ?  ,  :   ), __print(i);     cerr <<  } ;   }   void _print() { cerr <<  ] n ; }   template <typename T, typename... V>   void _print(T t, V... v) {     __print(t);     if (sizeof...(v)) cerr <<  ,  ;     _print(v...);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int t = 1;     while (t--) {       long long int n = 0, m = 0, k = 0, i = 0, j = 0, p = 0, q = 0, x = 0, y = 0,                     z = 0, cnt = 0, l = 0, r = 0, mid = 0, lo = 0, hi = 0;       string s;       bool flag = false;       cin >> n;       long long int a[n];       for (i = 0; i <= n - 1; i++) cin >> a[i];       long long int dpl[n];       long long int dpr[n];       pair<long long int, long long int> pr;       stack<pair<long long int, long long int>> st;       st.push(make_pair(a[0], 0));       for (i = 1; i < n; i++) {         while (!st.empty() && (st.top()).first > a[i]) {           pr = st.top();           st.pop();           dpr[pr.second] = i;         }         st.push(make_pair(a[i], i));       }       while (!st.empty()) {         pr = st.top();         st.pop();         dpr[pr.second] = n;       }       st.push(make_pair(a[n - 1], n - 1));       for (i = n - 2; i >= 0; i--) {         while (!st.empty() && (st.top()).first > a[i]) {           pr = st.top();           st.pop();           dpl[pr.second] = i;         }         st.push(make_pair(a[i], i));       }       while (!st.empty()) {         pr = st.top();         st.pop();         dpl[pr.second] = -1;       }       long long int ans[n + 1];       vector<pair<long long int, long long int>> vec;       for (i = 0; i < n; i++) vec.push_back(make_pair(a[i], i));       sort(vec.rbegin(), vec.rend());       j = 1;       for (i = 0; i < n; i++) {         pr = vec[i];         z = 0;         z = pr.second - dpl[pr.second] - 1;         z += dpr[pr.second] - pr.second - 1;         z++;         while (j <= z) ans[j] = pr.first, j++;       }       for (i = 1; i <= n; i++) cout << ans[i] <<    ;       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int Lower[1000000 + 1], Higher[1000000 + 1];   char Used[1000000 + 1];   long long SumNat(long long n) {     long long p = n, q = n + 1;     if (p % 2)       q /= 2;     else       p /= 2;     return (p) * (q);   }   long long PrimePi(long long n) {     long long v = sqrt(n + 1e-9), p, temp, q, j, end, i, d, t;     for (int i = 0; i <= 1000000; i++) Used[i] = 0;     Higher[1] = n - 1;     for (p = 2; p <= v; p++) {       Lower[p] = p - 1;       Higher[p] = (n / p) - 1;     }     for (p = 2; p <= v; p++) {       if (Lower[p] == Lower[p - 1]) continue;       temp = Lower[p - 1];       q = p * p;       Higher[1] -= Higher[p] - temp;       j = 1 + (p & 1);       end = (v <= n / q) ? v : n / q;       for (i = p + j; i <= 1 + end; i += j) {         if (Used[i]) continue;         d = i * p;         if (d <= v)           Higher[i] -= Higher[d] - temp;         else {           t = n / d;           Higher[i] -= Lower[t] - temp;         }       }       if (q <= v)         for (i = q; i <= end; i += p * j) Used[i] = 1;       for (i = v; i >= q; i--) {         t = i / p;         Lower[i] -= Lower[t] - temp;       }     }     return Higher[1];   }   bool prime[10000000 + 1];   long long piii[10000000 + 1];   long long Prim(long long n) {     if (n <= 10000000) return piii[n];     return PrimePi(n);   }   int main() {     long long n, i, j;     long long answer;     for (i = 2; i * i <= 10000000; i++)       if (!prime[i])         for (j = i * i; j <= 10000000; j += i) prime[j] = true;     for (i = 2; i <= 10000000; i++) {       piii[i] = piii[i - 1];       if (!prime[i]) piii[i]++;     }     cin >> n;     for (i = 1;; i++) {       if (i * i * i > n) break;     }     answer = Prim(i - 1);     for (i = 2; i < (n / i); i++)       if (!prime[i]) answer += (Prim(n / i) - Prim(i));     cout << answer;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, ans, seq[4], d[3005][3005], MaxT[3005][3005], Max[3005][3005], row;   vector<vector<int>> g;   bool comp(int a, int b) { return d[row][a] > d[row][b]; }   bool compT(int a, int b) { return d[a][row] > d[b][row]; }   void Dijkstra(int s) {     priority_queue<pair<int, int>> pq;     pq.push({0, s});     while (!pq.empty()) {       int dist = -pq.top().first, x = pq.top().second;       pq.pop();       if (d[s][x] != -1) continue;       d[s][x] = dist;       for (int adj : g[x]) {         if (d[s][adj] != -1) continue;         pq.push({-dist - 1, adj});       }     }   }   void sol(int A, int B, int C, int D) {     if (d[A][B] == -1 || d[B][C] == -1 || d[C][D] == -1) return;     if (d[A][B] + d[B][C] + d[C][D] > ans) {       ans = d[A][B] + d[B][C] + d[C][D];       seq[0] = A;       seq[1] = B;       seq[2] = C;       seq[3] = D;     }   }   int main() {     cin >> n >> m;     g.resize(n + 1);     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         d[i][j] = -1;       }     }     for (int i = 0; i < m; i++) {       int a, b;       cin >> a >> b;       g[a].push_back(b);     }     for (int i = 1; i <= n; i++) Dijkstra(i);     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         MaxT[i][j] = j;         Max[i][j] = j;       }     }     for (row = 1; row <= n; row++) {       sort(Max[row] + 1, Max[row] + n + 1, comp);       sort(MaxT[row] + 1, MaxT[row] + n + 1, compT);     }     for (int B = 1; B <= n; B++) {       for (int C = 1; C <= n; C++) {         if (B == C) continue;         for (int i = 1; i < 3; i++) {           for (int j = 1; j < 3; j++) {             int A = MaxT[B][i], D = Max[C][j];             if (A == B || A == C || A == D || D == B || D == C) continue;             sol(A, B, C, D);           }         }       }     }     for (int i = 0; i < 4; i++) cout << seq[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   priority_queue<long long int, vector<long long int>, greater<long long int> > q;   int main() {     int n;     scanf( %d , &n);     long long int x, sum = 0, ans = 0;     for (int i = 1; i <= n; i++) {       scanf( %lld , &x);       q.push(x);     }     while (q.size()) {       x = q.top();       q.pop();       if (sum > x)         ans++;       else         sum += x;     }     cout << n - ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 1e5 + 23;   const int INF = 1e9 + 23;   const int MOD = 1e9 + 7;   struct Mada {     long long x, h, p;   };   Mada mada[MAX_N];   stack<Mada> Dane;   int dp[MAX_N];   int n;   bool cmp(Mada a, Mada b) { return a.x < b.x; }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> mada[i].x >> mada[i].h;       mada[i].p = i;     }     sort(mada + 1, mada + 1 + n, cmp);     dp[mada[n].p] = 1;     Dane.push(mada[n]);     for (int i = n - 1; i >= 1; i--) {       long long res = 0;       while (!Dane.empty()) {         if (Dane.top().x > mada[i].h + mada[i].x - 1) {           break;         }         res += dp[Dane.top().p];         Dane.pop();       }       dp[mada[i].p] = res + 1;       Dane.push(mada[i]);     }     for (int i = 1; i <= n; i++) {       cout << dp[i] <<    ;     }     cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char rep;   void query(long long x, long long y) {     cout <<  ?   << x <<     << y << endl;     cin >> rep;     return;   }   void solve() {     long long x = 0;     long long y = 1;     while (true) {       query(x, y);       if (rep ==  x ) {         break;       }       x = y;       y = y * 2;     }     long long l = x + 1;     long long r = y;     while (l != r) {       long long med = (l + r) / 2;       query(med, y);       if (rep ==  x ) {         l = med + 1;       } else {         r = med;       }     }     cout <<  !   << l << endl;     return;   }   int main() {     string s;     while (true) {       cin >> s;       if (s[0] ==  s ) {         solve();       } else {         break;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline void checkMin(T& a, T b) {     if (b < a) a = b;   }   template <class T>   inline void checkMax(T& a, T b) {     if (b > a) a = b;   }   const int N = 22;   const long long INF = 1LL << 60;   int n, m, a[N], b[N];   long long dp[N][N], tmp[N][N], f[N][N], ans[N][N];   void DP(int n) {     for (int t = 0; t <= n; t++) {       for (int i = 0; i <= n; i++) dp[0][i] = INF;       dp[0][t] = 0;       for (int i = 1; i <= n; i++)         for (int j = 0; j <= n; j++) {           dp[i][j] = INF;           if (j > 0) checkMin(dp[i][j], dp[i - 1][j - 1] + a[i]);           if (j < n) checkMin(dp[i][j], dp[i - 1][j + 1] + b[i]);         }       for (int i = 0; i <= n; i++) f[t][i] = dp[n][i];     }   }   void fast_mult(int n, int m) {     for (int i = 0; i <= n; i++)       for (int j = 0; j <= n; j++) ans[i][j] = INF;     for (int i = 0; i <= n; i++) ans[i][i] = 0;     while (m > 0) {       if (m & 1) {         for (int i = 0; i <= n; i++)           for (int j = 0; j <= n; j++) tmp[i][j] = ans[i][j], ans[i][j] = INF;         for (int k = 0; k <= n; k++)           for (int i = 0; i <= n; i++)             for (int j = 0; j <= n; j++) checkMin(ans[i][j], tmp[i][k] + f[k][j]);       }       for (int i = 0; i <= n; i++)         for (int j = 0; j <= n; j++) tmp[i][j] = f[i][j], f[i][j] = INF;       for (int k = 0; k <= n; k++)         for (int i = 0; i <= n; i++)           for (int j = 0; j <= n; j++) checkMin(f[i][j], tmp[i][k] + tmp[k][j]);       m >>= 1;     }   }   int main() {     cin >> n >> m;     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = 1; i <= n; i++) cin >> b[i];     DP(n);     fast_mult(n, m);     cout << ans[0][0] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e6 + 69, INF = 1e9 + 85, MOD = 1e9 + 7;   int n, k, a, b, q, arr[MAXN], seg[2][MAXN << 2];   void update(int indx, int val, int type, int l = 0, int r = n, int id = 1) {     if (indx < l or indx >= r) return;     if (r - l == 1) {       seg[type][id] = val;       return;     }     int mid = (l + r) >> 1;     update(indx, val, type, l, mid, id << 1 | 0);     update(indx, val, type, mid, r, id << 1 | 1);     seg[type][id] = seg[type][id << 1 | 0] + seg[type][id << 1 | 1];   }   int get(int st, int en, int type, int l = 0, int r = n, int id = 1) {     if (l >= en or r <= st) return 0;     if (l >= st and r <= en) return seg[type][id];     int mid = (l + r) >> 1;     return get(st, en, type, l, mid, id << 1 | 0) +            get(st, en, type, mid, r, id << 1 | 1);   }   int32_t main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> k >> a >> b >> q;     while (q--) {       int type, day, order;       cin >> type;       if (type == 1) {         cin >> day >> order;         arr[day] += order;         update(day - 1, min(arr[day], a), 0);         update(day - 1, min(arr[day], b), 1);       } else {         cin >> day;         cout << get(0, day - 1, 1) + get(day + k - 1, n, 0) <<   n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int t{};     cin >> t;     while (t--) {       long long int n{};       cin >> n;       long long int a[n];       for (long long int i = 0; i < n; i++) cin >> a[i];       bool visit[n];       memset(visit, 0, sizeof(visit));       vector<pair<long long int, long long int>> vec{};       for (long long int i = 0; i < n; i++) {         for (long long int j = 0; j < n; j++) {           if (i != j && a[i] != a[j] && (!visit[i] || !visit[j])) {             visit[i] = 1;             visit[j] = 1;             vec.push_back({i + 1, j + 1});           }         }       }       if (vec.size() == n - 1) {         cout <<  YES  <<   n ;         for (long long int i = 0; i < n - 1; i++) {           cout << vec[i].first <<     << vec[i].second <<   n ;         }       } else {         cout <<  NO  <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   int main() {     int n, p, q;     scanf( %d %d %d , &n, &p, &q);     char word[n + 1];     scanf( %s , word);     if (n == p + q) {       printf( 2 n );       for (int i = 0; i < p; ++i) {         printf( %c , word[i]);       }       printf(  n );       for (int i = p; i < n; ++i) {         printf( %c , word[i]);       }       printf(  n );       return 0;     } else if (n % p != 0 && n % q != 0) {       int z = 0, i;       for (i = 0; i < n; ++i) {         int x = n - (p * i);         if (x % q == 0 && x > 0) {           z = i;           break;         }       }       if (z == 0) {         printf( -1 n );         return 0;       }       int y = (n - (z * p)) / q;       printf( %d n , z + y);       for (i = 0; i < z; ++i) {         for (int j = 0; j < p; ++j) {           int f = p * i + j;           printf( %c , word[f]);         }         printf(  n );       }       for (i = 0; i < y; ++i) {         int f = z * p;         for (int j = 0; j < q; ++j) {           int g = f + q * i + j;           printf( %c , word[g]);         }         printf(  n );       }       return 0;     } else {       int s;       if (n % p == 0) {         s = p;       } else {         s = q;       }       printf( %d n , n / s);       for (int i = 0; i < n / s; ++i) {         for (int j = 0; j < s; ++j) {           int x = i * s + j;           printf( %c , word[x]);         }         printf(  n );       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int a, b, c, ans, x[4];   int main() {     cin >> a >> b >> c;     x[0] = a + b + c;     x[1] = a + c + c + a;     x[2] = b + c + c + b;     x[3] = b + b + a + a;     ans = x[0];     for (int i = 1; i < 4; i++) {       if (ans > x[i]) ans = x[i];     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   const int maxn = 100 + 5;   using namespace std;   int val[maxn][maxn];   void doit(int x1, int y1, int x2, int y2) {     for (int i = x1; i <= x2; i++) {       for (int j = y1; j <= y2; j++) {         val[i][j]++;       }     }   }   int main() {     memset(val, 0, sizeof(val));     int n;     cin >> n;     while (n--) {       int x, y, u, v;       cin >> x >> y >> u >> v;       doit(x, y, u, v);     }     int sum = 0;     for (int i = 1; i <= 100; i++)       for (int j = 1; j <= 100; j++) sum += val[i][j];     cout << sum << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class A, class B>   inline bool mina(A &first, B second) {     return (first > second) ? (first = second, 1) : 0;   }   template <class A, class B>   inline bool maxa(A &first, B second) {     return (first < second) ? (first = second, 1) : 0;   }   const int MAXN = 1e5 + 5;   int N, K;   int ans[MAXN];   long long minimum(long long prev, long long num) {     long long start = prev + 1;     long long end = start + num - 1;     return (start + end) * num / 2;   }   int main() {     cin >> N >> K;     int ll = 1, rr = N;     while (ll <= rr) {       int mid = (ll + rr) / 2;       if (mid + minimum(mid, K - 1) > N) {         rr = mid - 1;       } else {         ll = mid + 1;       }     }     if (rr == 0) {       cout <<  NO  << endl;       return 0;     }     ans[0] = rr;     int left = N - rr;     int now = 1;     while (left) {       if (now >= K) {         cout <<  NO  << endl;         return 0;       } else if (now + 1 == K) {         ans[now] = left;         if (left > ans[now - 1] && left <= 2 * ans[now - 1]) {           break;         } else {           cout <<  NO  << endl;           return 0;         }       } else {         if (2LL * ans[now - 1] + minimum(ans[now - 1] * 2, K - now - 1) > left) {           int ll = ans[now - 1] + 1;           int rr = 2LL * ans[now - 1];           while (ll <= rr) {             int mid = (ll + rr) / 2;             if (mid + minimum(mid, K - now - 1) > left) {               rr = mid - 1;             } else {               ll = mid + 1;             }           }           if (rr < ans[now - 1] + 1) {             cout <<  NO  << endl;             return 0;           }           ans[now] = rr;           left -= ans[now];           now++;         } else {           ans[now] = ans[now - 1] * 2;           left -= ans[now];           now++;         }       }     }     cout <<  YES  << endl;     for (int i = 0; (i) < (K); ++(i)) {       cout << ans[i] <<    ;     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   const int MX = 10010896;   const int lmt = 3164;   const int N = 10000001;   using namespace std;   long long int extgcd(long long int a, long long int b, long long int& x,                        long long int& y) {     if (b == 0) {       x = 1;       y = 0;       return a;     } else {       int g = extgcd(b, a % b, y, x);       y -= a / b * x;       return g;     }   }   long long int modpow(long long int a, long long int b) {     long long int res = 1;     a %= 1000000007;     for (; b; b >>= 1) {       if (b & 1) res = res * a % 1000000007;       a = a * a % 1000000007;     }     return res;   }   inline void solve() {     long long int n, m;     cin >> n >> m;     long long int a[n], b[m];     for (long long int i = 0; i < n; i++) {       cin >> a[i];     }     for (long long int i = 0; i < m; i++) {       cin >> b[i];     }     long long int ans = 0;     bool flag2 = false;     for (ans = 0; ans <= 512; ans++) {       long long int ci = ans;       for (long long int i = 0; i < n; i++) {         flag2 = false;         for (long long int j = 0; j < m; j++) {           if (((a[i] & b[j]) | ci) <= ans) {             flag2 = true;             ci = (a[i] & b[j]) | ci;             break;           }         }         if (!flag2) break;       }       if (flag2) {         cout << ans <<   n ;         return;       }     }   }   int main() {     cout << fixed << setprecision(12);     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int t = 1, tc = 1;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int max_height(long long n) { return (long long)(sqrt(24 * n + 1) - 1) / 6; }   int main() {     int t;     cin >> t;     while (t--) {       long long n;       cin >> n;       int pyramids = 0;       while (1) {         long long height = max_height(n);         if (!height) break;         long long int cards = (3 * height + 1) * height / 2;         pyramids += n / cards;         n -= n / cards * cards;       }       cout << pyramids << endl;     }     return 0;   }


#include <bits/stdc++.h>   const double eps = 1e-7, PI = 3.1415926;   const int N = 2e5 + 10;   using namespace std;   long long n, q, m, k, x, y, a[N], mx = -1, mem[N][3], vis[N][3], mn = 1e9, sum,                                     t;   char c[N];   string s, s1, s2;   map<int, int> mp;   vector<int> vec;   long long dp(long long i, int cur) {     if (i <= 0 || i > n) return 0;     if (vis[i][cur] == x) return -1e17;     if (mem[i][cur] != -1) return mem[i][cur];     vis[i][cur] = x;     long long p1 = 0, p2 = 0;     if (cur == 0)       p1 += a[i] + dp(i + a[i], cur ^ 1);     else       p1 += a[i] + dp(i - a[i], cur ^ 1);     return mem[i][cur] = p1;   }   int main() {     cin >> n;     memset(mem, -1, sizeof mem);     for (int i = 2; i <= n; i++) cin >> a[i];     for (int i = 1; i < n; i++) {       a[1] = i;       mem[1][0] = -1;       x++;       long long ans = dp(1, 0);       if (ans >= 0)         cout << ans << endl;       else         cout << -1 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 10;   int ph[N];   int main() {     string s;     cin >> s;     int n = s.size();     for (int i = 1; i <= n; i++)       ph[i] = ph[i - 1] + (s[i - 1] >=  A  && s[i - 1] <=  Z  ? 1 : 0);     int ans = 1e5;     for (int i = 0; i <= n; i++) {       ans = min(ans, i - ph[i] + ph[n] - ph[i]);     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     int x;     cin >> x;     vector<int> a(n);     for (int i = 0; i < n; i++) {       cin >> a[i];     }     if (n == 1) {       cout << 0 <<   n ;       return 0;     }     sort(a.begin(), a.end());     if (x < a[0]) {       cout << a[0] - x + a[n - 2] - a[0] <<   n ;       return 0;     }     if (x > a[n - 1]) {       cout << x - a[n - 1] + a[n - 1] - a[1] <<   n ;       return 0;     }     int ans1 = a[n - 2] - a[0] + min((int)abs(x - a[0]), (int)abs(x - a[n - 2]));     int ans2 = a[n - 1] - a[1] + min((int)abs(x - a[1]), (int)abs(x - a[n - 1]));     cout << min(ans1, ans2) <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cout.precision(15);     long long int t;     cin >> t;     while (t--) {       string s;       cin >> s;       long long int x;       cin >> x;       long long int n = (long long int)s.length();       vector<int> v(n, 2);       for (long long int i = x; i < n - x; i++) {         if (s[i - x] ==  1  && s[i + x] ==  1 )           v[i] = 1;         else           v[i] = 0;       }       for (long long int i = 0; i < x; i++) {         if ((i + x) < n && s[i + x] ==  0 )           v[i] = 0;         else           v[i] = 1;       }       for (long long int i = n - x; i < n; i++) {         if ((i - x) >= 0 && s[i - x] ==  0 )           v[i] = 0;         else           v[i] = 1;       }       string ans;       for (long long int i = 0; i < n; i++) {         if (i - x >= 0 && v[i - x] == 1)           ans +=  1 ;         else if (i + x < n && v[i + x] == 1)           ans +=  1 ;         else           ans +=  0 ;       }       if (ans != s)         cout <<  -1 n ;       else {         string a;         for (long long int i = 0; i < n; i++) a += ( 0  + v[i]);         cout << a <<   n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   char buf[1 << 21], *p1 = buf, *p2 = buf;   template <class T>   void read(T &x) {     x = 0;     int c = getchar();     int flag = 0;     while (c <  0  || c >  9 ) flag |= (c ==  - ), c = getchar();     while (c >=  0  && c <=  9 )       x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();     if (flag) x = -x;   }   template <class T>   T _max(T a, T b) {     return b < a ? a : b;   }   template <class T>   T _min(T a, T b) {     return a < b ? a : b;   }   template <class T>   bool checkmax(T &a, T b) {     return a < b ? a = b, 1 : 0;   }   template <class T>   bool checkmin(T &a, T b) {     return b < a ? a = b, 1 : 0;   }   const int N = 82;   int n;   int l[N], r[N], foo[N];   int arr[N << 1], top = 0;   int L, R;   double f[N][N], g[N][N];   double ans[N][N];   void init() {     read(n);     for (int i = 1; i <= n; ++i) {       read(l[i]);       read(r[i]);       arr[++top] = l[i];       arr[++top] = r[i];       foo[i] = r[i] - l[i];     }     sort(arr + 1, arr + top + 1);     top = unique(arr + 1, arr + top + 1) - arr - 1;   }   double calcl(int idx) {     return 1.0 * _min(_max(0, L - l[idx]), foo[idx]) / foo[idx];   }   double calcr(int idx) {     return 1.0 * _min(_max(0, r[idx] - R), foo[idx]) / foo[idx];   }   double calcmid(int idx) { return 1 - calcl(idx) - calcr(idx); }   void run(int idx, int bar) {     L = arr[bar], R = arr[bar + 1];     if (L < l[idx] || R > r[idx]) return;     memset(f, 0, sizeof f);     f[0][0] = 1;     int tot = 0;     for (int i = 1; i <= n; ++i) {       if (i == idx) continue;       ++tot;       double cl = calcl(i), cr = calcr(i), cm = calcmid(i);       for (int j = tot; j >= 0; --j) {         for (int k = tot - j; k >= 0; --k) {           if (j + k < tot)             f[j][k] *= cm;           else             f[j][k] = 0;           if (j) f[j][k] += f[j - 1][k] * cl;           if (k) f[j][k] += f[j][k - 1] * cr;         }       }     }     double co = 1.0 * (R - L) / foo[idx];     for (int i = 0; i <= tot; ++i) {       for (int j = 0; i + j <= tot; ++j) {         int num = tot - i - j + 1;         double res = f[i][j] / num * co;         ans[idx][i + 1] += res;         ans[idx][n - j + 1] -= res;       }     }   }   void solve() {     for (int i = 1; i <= n; ++i) {       for (int j = 1; j < top; ++j) {         run(i, j);       }     }     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= n; ++j) {         ans[i][j] += ans[i][j - 1];         printf( %.8lf%c , ans[i][j],    n [j == n]);       }     }   }   int main() {     init();     solve();     return 0;   }


#include <bits/stdc++.h>   using LL = long long;   const int N = 100000 + 5;   LL D[N], H[N];   int n, m;   struct Unit {     int l, r;     LL Lmax, Rmax, Mmax, sum;     void show() {       printf( l = %d,r = %d n , l, r);       printf( Lmax = %I64d,Rmax = %I64d,Mmax = %I64d,sum = %I64d n , Lmax, Rmax,              Mmax, sum);     }     Unit operator+(const Unit &rhs) const {       Unit ret;       ret.l = l;       ret.r = rhs.r;       ret.Lmax = std::max(Lmax + D[r] + rhs.sum, rhs.Lmax);       ret.Rmax = std::max(Rmax, sum + D[r] + rhs.Rmax);       ret.Mmax = std::max(Mmax, rhs.Mmax);       ret.Mmax = std::max(ret.Mmax, Lmax + D[r] + rhs.Rmax);       ret.sum = sum + D[r] + rhs.sum;       return ret;     }   };   struct SegmentTree {     Unit t[N << 2];     void build(int l, int r, int rt) {       if (l == r) {         t[rt].l = t[rt].r = l;         t[rt].Lmax = t[rt].Rmax = 2 * H[l];         t[rt].sum = 0;         t[rt].Mmax = -1;         return;       }       int mid = l + r >> 1;       build(l, mid, rt << 1);       build(mid + 1, r, rt << 1 | 1);       t[rt] = t[rt << 1] + t[rt << 1 | 1];     }     Unit query(int L, int R, int l, int r, int rt) {       if (L <= l && r <= R) {         return t[rt];       }       int mid = l + r >> 1;       if (L <= mid && mid < R)         return query(L, R, l, mid, rt << 1) +                query(L, R, mid + 1, r, rt << 1 | 1);       if (L <= mid) return query(L, R, l, mid, rt << 1);       return query(L, R, mid + 1, r, rt << 1 | 1);     }   } sgt;   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; ++i) {       scanf( %I64d , D + i);     }     for (int i = 1; i <= n; ++i) {       scanf( %I64d , H + i);     }     sgt.build(1, n, 1);     while (m--) {       int a, b;       scanf( %d%d , &a, &b);       if (a > b) {         printf( %I64d n , sgt.query(b + 1, a - 1, 1, n, 1).Mmax);       } else {         if (a == 1) {           printf( %I64d n , sgt.query(b + 1, n, 1, n, 1).Mmax);         } else if (b == n) {           printf( %I64d n , sgt.query(1, a - 1, 1, n, 1).Mmax);         } else {           printf(                %I64d n ,               (sgt.query(b + 1, n, 1, n, 1) + sgt.query(1, a - 1, 1, n, 1)).Mmax);         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void main0();   int main() {     clock_t start, end;     ios::sync_with_stdio(false);     cin.tie(0);     main0();     return 0;   }   const int dx[8] = {0, 1, -1, 0, 1, 1, -1, -1};   const int dy[8] = {1, 0, 0, -1, 1, -1, -1, 1};   const int N = 5e5 + 5;   const int M = 1e5;   const int INF = 0x3f3f3f3f;   const long long INFF = 0x3f3f3f3f3f3f3f3f;   const int mod = 998244353;   const int G = 3;   const int Gi = 332748118;   const double eps = 1e-6;   mt19937 rnd(       (unsigned int)chrono::steady_clock::now().time_since_epoch().count());   template <typename T>   bool chkmin(T &x, T y) {     return y < x ? x = y, 1 : 0;   }   template <typename T>   bool chkmax(T &x, T y) {     return y > x ? x = y, 1 : 0;   }   long long qpow(long long n, long long m) {     long long ret = 1;     while (m) {       if (m & 1) ret = ret * n % mod;       n = n * n % mod;       m >>= 1;     }     return ret;   }   long long getinv(long long a) { return qpow(a, mod - 2); }   int n;   vector<int> e[N];   long long fac[N];   void init() {     fac[0] = 1;     for (int i = 1; i <= N - 1; ++i) {       fac[i] = fac[i - 1] * i % mod;     }   }   int r[N], lim;   void ntt(vector<long long> &A, int type) {     for (int i = 0; i <= lim - 1; ++i) {       if (i < r[i]) swap(A[i], A[r[i]]);     }     for (int mid = 1; mid <= lim - 1; mid <<= 1) {       long long Wn = qpow(type == 1 ? G : Gi, (mod - 1) / (mid << 1));       for (int j = 0; j <= lim - 1; j += (mid << 1)) {         long long w = 1;         for (int k = 0; k <= mid - 1; ++k, w = (w * Wn) % mod) {           int x = A[j + k];           int y = w * A[j + mid + k] % mod;           A[j + k] = (x + y) % mod;           A[j + mid + k] = (x - y + mod) % mod;         }       }     }     if (type == -1) {       long long tmp = getinv(lim);       for (int i = 0; i <= lim - 1; ++i) {         A[i] = A[i] * tmp % mod;       }     }   }   vector<long long> operator*(vector<long long> A, vector<long long> B) {     int len = A.size() + B.size() - 1;     lim = 1;     while (lim <= len) lim <<= 1;     for (int i = 0; i <= lim - 1; ++i) {       r[i] = (r[i >> 1] >> 1) | ((i & 1) * (lim >> 1));     }     A.resize(lim);     B.resize(lim);     ntt(A, 1);     ntt(B, 1);     for (int i = 0; i <= lim - 1; ++i) {       A[i] = A[i] * B[i] % mod;     }     ntt(A, -1);     A.resize(len);     return A;   }   vector<long long> solve(int l, int r) {     if (l == r) {       vector<long long> tmp({1, (int)e[l].size() - (l != 1)});       return tmp;     }     int mid = (l + r) / 2;     return solve(l, mid) * solve(mid + 1, r);   }   void main0() {     init();     cin >> n;     for (int i = 1; i <= n - 1; ++i) {       int u, v;       cin >> u >> v;       e[u].push_back(v);       e[v].push_back(u);     }     vector<long long> v = solve(1, n);     long long ans = 0;     for (int i = 0; i <= n - 1; ++i) {       ans += (i & 1 ? -1 : 1) * v[i] * fac[n - i] % mod;       ans %= mod;     }     ans += mod;     ans %= mod;     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T, typename U>   inline void smin(T &a, U b) {     if (a > b) a = b;   }   template <typename T, typename U>   inline void smax(T &a, U b) {     if (a < b) a = b;   }   template <class T>   inline void gn(T &first) {     char c, sg = 0;     while (c = getchar(), (c >  9  || c <  0 ) && c !=  - )       ;     for ((c ==  -  ? sg = 1, c = getchar() : 0), first = 0; c >=  0  && c <=  9 ;          c = getchar())       first = (first << 1) + (first << 3) + c -  0 ;     if (sg) first = -first;   }   template <class T>   inline void print(T first) {     if (first < 0) {       putchar( - );       return print(-first);     }     if (first < 10) {       putchar( 0  + first);       return;     }     print(first / 10);     putchar(first % 10 +  0 );   }   template <class T, class T1>   inline void gn(T &first, T1 &second) {     gn(first);     gn(second);   }   template <class T, class T1, class T2>   inline void gn(T &first, T1 &second, T2 &z) {     gn(first);     gn(second);     gn(z);   }   template <class T>   inline void println(T first) {     print(first);     putchar(  n );   }   template <class T>   inline void printsp(T first) {     print(first);     putchar(   );   }   template <class T1, class T2>   inline void print(T1 x1, T2 x2) {     printsp(x1), println(x2);   }   template <class T1, class T2, class T3>   inline void print(T1 x1, T2 x2, T3 x3) {     printsp(x1), printsp(x2), println(x3);   }   template <class T1, class T2, class T3, class T4>   inline void print(T1 x1, T2 x2, T3 x3, T4 x4) {     printsp(x1), printsp(x2), printsp(x3), println(x4);   }   int power(int a, int b, int m, int ans = 1) {     for (; b; b >>= 1, a = 1LL * a * a % m)       if (b & 1) ans = 1LL * ans * a % m;     return ans;   }   int a[211][211];   int dp[211][211][211];   int dst[211][211];   int id[211][211];   int di[] = {1, -1, 0, 0};   int dj[] = {0, 0, 1, -1};   char res[211][211];   int vst[1011];   int main() {     int n, m, k;     cin >> n >> m >> k;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) {         gn(a[i][j]);         vst[a[i][j]]++;         a[i][j] = a[i][j] * 10000 + vst[a[i][j]];       }     int nn = 0;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) id[i][j] = ++nn;     memset(dst, 0x3f3f3f3f, sizeof dst);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) {         for (int k = 0; k < 4; k++) {           int ii = i + di[k], jj = j + dj[k];           if (ii < 1 or jj < 1 or ii > n or jj > m) continue;           dst[id[i][j]][id[ii][jj]] = a[ii][jj];           dst[id[ii][jj]][id[i][j]] = a[i][j];         }       }     for (int k = 1; k <= nn; k++) {       for (int i = 1; i <= nn; i++) {         for (int j = 1; j <= nn; j++) {           smin(dst[i][j], dst[i][k] + dst[k][j]);         }       }     }     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) {         for (int ii = 1; ii <= n; ii++)           for (int jj = 1; jj <= m; jj++) {             dst[id[i][j]][id[ii][jj]] += a[i][j];           }       }     memset(dp, 0x3f3f3f3f, sizeof dp);     for (int i = 0; i < k; i++) {       int first, second;       gn(first, second);       dp[1 << i][first][second] = a[first][second];     }     for (int i = 1; i < 1 << k; i++) {       for (int p = 1; p <= n; p++) {         for (int q = 1; q <= m; q++) {           int b = 0;           while (b = (b - i) & i) {             if (b < i) smin(dp[i][p][q], dp[b][p][q] + dp[i ^ b][p][q] - a[p][q]);           }         }       }       for (int r = 1; r <= n; r++) {         for (int w = 1; w <= m; w++) {           for (int p = 1; p <= n; p++) {             for (int q = 1; q <= m; q++) {               smin(dp[i][p][q], dp[i][r][w] + dst[id[p][q]][id[r][w]] - a[r][w]);             }           }         }       }     }     int ans = 0x3f3f3f3f;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) smin(ans, dp[(1 << k) - 1][i][j]);     }     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) res[i][j] =  . ;     cout << ans / 10000 << endl;     int tmp = 0;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         if (dp[(1 << k) - 1][i][j] == ans)           res[i][j] =  X , tmp += a[i][j] / 10000;       }     }     if (ans / 10000 != tmp)       while (1)         ;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) printf( %c , res[i][j]);       puts(  );     }     return 0;   }