#include <bits/stdc++.h>   using namespace std;   template <typename T>   void read_to_vector(size_t N, std::vector<T> &v) {     for (size_t i = 0; i < N; i++) {       T tmp;       std::cin >> tmp;       v.push_back(tmp);     }   }   template <typename T>   void print_vector(const std::vector<T> &v) {     for (auto it = v.begin(); it < v.end(); it++) {       if (it != v.begin()) std::cout <<    ;       std::cout << (*it);     }   }   string getpre(string s0, string s1) {     string res;     for (int i = 0; i < s0.size() && i < s1.size(); i++) {       if (s0[i] == s1[i]) {         res += s0[i];       } else {         break;       }     }     return res;   }   string getpre(vector<string> &ss) {     if (ss.size() == 0) {       return   ;     }     string smin = ss[0];     string smax = ss[0];     for (int i = 0; i < ss.size(); i++) {       smin = min(ss[i], smin);       smax = max(ss[i], smax);     }     return getpre(smin, smax);   }   void solve() {     long long n;     cin >> n;     vector<string> w0, w1;     read_to_vector(n, w0);     read_to_vector(n, w1);     vector<int> ch0(n, -1), ch1(n, -1);     string chans0;     string chans1;     for (int i = 0; i < n; i++) {       for (int j = 0; j < w0[i].size(); j++) {         if (w0[i][j] != w1[i][j]) {           if (ch0[i] == -1) {             ch0[i] = j;           }           ch1[i] = j;         }       }       ch1[i]++;       if (ch0[i] != -1) {         chans0 = w0[i].substr(ch0[i], ch1[i] - ch0[i]);         chans1 = w1[i].substr(ch0[i], ch1[i] - ch0[i]);       }     }     vector<string> prefs;     vector<string> posts;     for (int i = 0; i < n; i++) {       if (ch0[i] == -1) {         continue;       }       string pre = w0[i].substr(0, ch0[i]);       reverse(pre.begin(), pre.end());       string post = w0[i].substr(ch1[i], w0[i].size() - ch1[i]);       prefs.push_back(pre);       posts.push_back(post);     }     string pre = getpre(prefs);     reverse(pre.begin(), pre.end());     string post = getpre(posts);     string rep0 = pre + chans0 + post;     string rep1 = pre + chans1 + post;     bool test = true;     for (int i = 0; i < n; i++) {       string w = w0[i];       string wend = w;       int ind = w.find(rep0);       if (ind != string::npos) {         wend = w.substr(0, ind) + rep1 +                w.substr(ind + rep1.size(), w.size() - (ind + rep1.size()));       }       test &= (wend == w1[i]);     }     if (test) {       cout <<  YES n  << rep0 <<   n  << rep1 <<   n ;     } else {       cout <<  NO n ;     }   }   void pre_compute() {}   int main() {     std::cout << std::setprecision(15);     std::ios::sync_with_stdio(false);     std::cin.tie(0);     pre_compute();     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, v = 0, p = 0;     string s, result =   ;     cin >> n >> s;     v = (n - 11) / 2;     p = v;     for (int i = 0; i < n; i++) {       if (s[i] ==  8 ) {         if (v > 0)           v--;         else           result += s[i];       } else {         if (p > 0)           p--;         else           result += s[i];       }     }     if (result[0] ==  8 )       cout <<  YES  << endl;     else       cout <<  NO  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int arr[510];   int dp[510][510];   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i <= n - 1; i++) scanf( %d , &arr[i]);     for (int l = 1; l <= n; l++) {       for (int i = 0; i <= n - 1; i++) {         int j = i + l - 1;         if (j > n - 1) continue;         if (i == j) {           dp[i][j] = 1;           continue;         }         dp[i][j] = dp[i + 1][j] + 1;         for (int k = i + 2; k <= j; k++)           if (arr[k] == arr[i])             dp[i][j] = min(dp[i][j], dp[i + 1][k - 1] + dp[k + 1][j]);         if (i < n - 1 && arr[i + 1] == arr[i])           dp[i][j] = min(dp[i][j], dp[i + 2][j] + 1);       }     }     cout << dp[0][n - 1] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void mego() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   bool isp(long long x) {     for (long long i = 2; i * i <= x; i++)       if (!(x % i)) return false;     return true;   }   long long coun = 0;   int gcd(long long a, long long b) {     if (b == 0) return a;     coun += (a / b);     return gcd(b, a % b);   }   int main() {     mego();     long long n, a, z = 0, b = 0, d = 0, c = 0;     vector<long long> v, v1;     long long t = 0;     cin >> t;     map<int, pair<int, int> > ma;     for (int i = 1; i <= t; i++) {       cin >> a;       if (!ma[a].first) {         ma[a].first = i;       } else if (!ma[a].second)         ma[a].second = i;       else {         if ((i - ma[a].second) != (ma[a].second - ma[a].first)) {           ma[a].first = -1;           ma[a].second = -1;         } else {           ma[a].first = ma[a].second;           ma[a].second = i;         }       }     }     vector<pair<int, int> > vp;     pair<int, int> rej = {-1, -1};     for (auto it : ma) {       if (it.second != rej) {         vp.push_back(make_pair(it.first, it.second.second - it.second.first));       }     }     cout << vp.size() <<   n ;     for (int i = 0; i < vp.size(); i++) {       cout << vp[i].first <<     << (vp[i].second > 0 ? vp[i].second : 0) <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     long long n, k;     cin >> n >> k;     string second;     cin >> second;     vector<long long> cnt(k, 0);     for (long long i = 0; i < n; i++) {       cnt[second[i] -  A ]++;     }     long long ans = cnt[0];     for (long long i = 0; i < k; i++) {       ans = min(ans, cnt[i]);     }     cout << ans * k << endl;   }   signed main() {     long long n = 1;     while (n--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 21;   int cnt, u;   int sz[1 << MAXN], g[1 << MAXN], p[1 << MAXN];   long long int f[1 << MAXN], h[1 << MAXN];   inline long long int read() {     register long long int num = 0, neg = 1;     register char ch = getchar();     while (!isdigit(ch) && ch !=  - ) {       ch = getchar();     }     if (ch ==  - ) {       neg = -1;       ch = getchar();     }     while (isdigit(ch)) {       num = (num << 3) + (num << 1) + (ch -  0 );       ch = getchar();     }     return num * neg;   }   int main() {     cnt = read();     for (register int i = 0; i < cnt; i++) {       if (!(f[i] = read())) {         i--, cnt--;       }     }     for (register int i = 1; i < (1 << cnt); i++) {       sz[i] = sz[i >> 1] + (i & 1);       for (register int j = 0; j < cnt; j++) {         if ((i >> j) & 1) {           h[i] += f[j];         }       }       if ((h[i] + sz[i] & 1)) {         for (register int j = i; (j = ((j - 1) & i)) && !p[i];) {           if (h[i] - sz[i] + 1 <= 2 * h[j] && 2 * h[j] <= h[i] + sz[i] - 1) {             p[i] = 1;           }         }       }     }     for (register int i = 1; i < (1 << cnt); i++) {       if (p[i] && !g[i]) {         g[i] = 1, u = (1 << cnt) - i - 1;         for (register int j = u; j; j = (j - 1) & u) {           g[i | j] = max(g[i | j], g[j] + 1);         }       }     }     printf( %d n , cnt - g[(1 << cnt) - 1]);   }


#include <bits/stdc++.h>   using namespace std;   const long long NMAX = 300000 + 5;   const long long inf = 922337203685477580LL;   vector<vector<pair<long long, long long> > > g(NMAX);   vector<vector<int> > id(NMAX);   long long dis[NMAX];   long long last[NMAX];   long long a[NMAX];   int main() {     int n, m;     cin >> n >> m;     long long ans = 0;     for (int i = 0; i < m; i++) {       int a, b, c;       cin >> a >> b >> c;       g[a].push_back({b, c});       g[b].push_back({a, c});       id[a].push_back(i);       id[b].push_back(i);     }     int s;     cin >> s;     for (int i = 1; i <= n; i++) dis[i] = inf;     dis[s] = 0;     for (int i = 1; i <= n; i++) last[i] = inf;     last[s] = 0;     set<pair<int, int> > q;     q.insert({0, s});     while (!q.empty()) {       int w = q.begin()->second;       q.erase(q.begin());       for (int i = 0; i < g[w].size(); i++) {         int to = g[w][i].first;         int len = g[w][i].second;         if (dis[w] + len < dis[to] ||             (dis[w] + len <= dis[to] && len < last[to])) {           q.erase(make_pair(dis[to], to));           dis[to] = dis[w] + len;           last[to] = len;           a[to] = id[w][i] + 1;           q.insert(make_pair(dis[to], to));         }       }     }     for (int i = 1; i <= n; i++) ans += last[i];     cout << ans << endl;     for (int i = 1; i <= n; i++) {       if (i != s) {         cout << a[i] <<    ;       }     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   long long mod = 1e18;   long long fast_pow(long long b, long long p) {     if (p == 0) return 1;     long long m = fast_pow(b, p / 2);     m = ((m % mod) * (m % mod)) % mod;     if (p % 2 == 1) m = ((m % mod) * (b % mod)) % mod;     return m;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     pair<int, int> arr[N];     for (int i = 0; i < n; i++) {       cin >> arr[i].first;     }     for (int i = 0; i < n; i++) {       cin >> arr[i].second;     }     sort(arr, arr + n);     long long cu = 1;     priority_queue<long long> q;     long long sum = 0;     long long ans = 0;     for (long long i = 0; i < n; i++) {       if (q.empty()) cu = arr[i].first;       if (arr[i].first == cu) {         q.push(arr[i].second);         sum += arr[i].second;       } else {         sum -= q.top();         q.pop();         ans += sum;         while (q.size() && (++cu) < arr[i].first) {           sum -= q.top();           q.pop();           ans += sum;         }         i--;       }     }     while (q.size()) {       sum -= q.top();       q.pop();       ans += sum;     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k, p, x, y;     int a[1010], b[1010];     int i, j;     while (scanf( %d%d%d%d%d , &n, &k, &p, &x, &y) != EOF) {       int sum = 0;       for (i = 0; i < k; i++) {         scanf( %d , &a[i]);         sum += a[i];       }       if (sum > x) {         puts( -1 );         continue;       }       for (i = k; i < n; i++) {         a[i] = 1;         sum += 1;       }       int t = k;       while (t < n && sum + y - 1 <= x) {         a[t++] = y;         sum += y - 1;       }       for (i = 0; i < n; i++) b[i] = a[i];       sort(b, b + n);       int m = b[n / 2];       if (sum <= x && m >= y) {         for (i = k; i < n - 1; i++) printf( %d  , a[i]);         printf( %d n , a[n - 1]);       } else         printf( -1 n );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   map<int, int> mm;   map<int, int>::iterator it;   int x[100005];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     vector<int> v;     for (int i = 1; i <= n; i++) cin >> x[i];     for (int i = n; i >= 1; i--) {       if (mm[x[i]] == 0) {         mm[x[i]]++;         v.push_back(x[i]);       }     }     cout << endl;     cout << v.size() <<   n ;     for (int i = v.size() - 1; i >= 0; i--) {       cout << v[i] <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   pair<long double, long double> st[4 * N];   int n, q;   template <typename T>   pair<T, T> operator+(const pair<T, T> &a, const pair<T, T> &b) {     pair<T, T> res;     res.first = a.first + b.first * a.second;     res.second = a.second * b.second;     return res;   }   void update(int id, int l, int r, int pos, long double val) {     if (l > pos || r < pos) return;     if (l == r) {       st[id] = make_pair(val, val);       return;     }     int mid = (l + r) >> 1;     update(id << 1, l, mid, pos, val);     update(id << 1 | 1, mid + 1, r, pos, val);     st[id] = st[id << 1] + st[id << 1 | 1];   }   pair<long double, long double> getsum(int id, int l, int r, int u, int v) {     if (l > v || r < u) return make_pair(0, 1);     if (l >= u && r <= v) return st[id];     int mid = (l + r) >> 1;     pair<long double, long double> lnode = getsum(id << 1, l, mid, u, v);     pair<long double, long double> rnode = getsum(id << 1 | 1, mid + 1, r, u, v);     return lnode + rnode;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n >> q;     for (int i = 1; i <= n; i++) {       int a, b;       cin >> a >> b;       long double p = (long double)a / b;       update(1, 1, n, i, (1.0L - p) / p);     }     while (q--) {       int op;       cin >> op;       if (op == 1) {         int pos, a, b;         cin >> pos >> a >> b;         long double p = (long double)a / b;         update(1, 1, n, pos, (1.0L - p) / p);       } else {         int l, r;         cin >> l >> r;         long double res = 1 + getsum(1, 1, n, l, r).first;         long double ans = (1.0L / res);         if (ans != ans) ans = 0;         cout << fixed << setprecision(9) << ans <<   n ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 53;   const int MAXM = 53;   char mp_cur[MAXN][MAXM];   char mp_end[MAXN][MAXM];   vector<pair<int, int>> ans;   int n, m;   void podn(int i, int j);   void opus(int i, int j) {     if (mp_cur[i][j + 1] ==  L ) {       podn(i, j + 1);     }     ans.push_back({i + 1, j + 1});     mp_cur[i][j] =  L ;     mp_cur[i][j + 1] =  R ;     mp_cur[i + 1][j] =  L ;     mp_cur[i + 1][j + 1] =  R ;   }   void podn(int i, int j) {     if (mp_cur[i + 1][j] ==  U ) {       opus(i + 1, j);     } else if (mp_cur[i + 1][j] ==  R ) {       podn(i + 1, j - 1);       opus(i + 1, j);     }     ans.push_back({i + 1, j + 1});     mp_cur[i][j] =  U ;     mp_cur[i][j + 1] =  U ;     mp_cur[i + 1][j] =  D ;     mp_cur[i + 1][j + 1] =  D ;   }   bool uh(int i, int j) {     if (0 <= i && i < n && 0 <= j && j < m) {       return false;     } else {       return true;     }   }   bool correct() {     for (int i = 0; i < n; ++i) {       for (int j = 0; j < m; ++j) {         if (mp_cur[i][j] ==  U ) {           if (uh(i + 1, j)) {             return false;           } else {             if (!(mp_cur[i + 1][j] ==  D )) {               return false;             }           }         } else if (mp_cur[i][j] ==  D ) {           if (uh(i - 1, j)) {             return false;           } else {             if (!(mp_cur[i - 1][j] ==  U )) return false;           }         } else if (mp_cur[i][j] ==  L ) {           if (uh(i, j + 1)) {             return false;           } else {             if (!(mp_cur[i][j + 1] ==  R )) return false;           }         } else if (mp_cur[i][j] ==  R ) {           if (uh(i, j - 1)) {             return false;           } else {             if (!(mp_cur[i][j - 1] ==  L )) return false;           }         }       }     }     for (int i = 0; i < n; ++i) {       for (int j = 0; j < m; ++j) {         if (mp_end[i][j] ==  U ) {           if (uh(i + 1, j)) {             return false;           } else {             if (!(mp_end[i + 1][j] ==  D )) return false;           }         } else if (mp_end[i][j] ==  D ) {           if (uh(i - 1, j)) {             return false;           } else {             if (!(mp_end[i - 1][j] ==  U )) return false;           }         } else if (mp_end[i][j] ==  L ) {           if (uh(i, j + 1)) {             return false;           } else {             if (!(mp_end[i][j + 1] ==  R )) return false;           }         } else if (mp_end[i][j] ==  R ) {           if (uh(i, j - 1)) {             return false;           } else {             if (!(mp_end[i][j - 1] ==  L )) return false;           }         }       }     }     return true;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> n >> m;     for (int i = 0; i < n; ++i) {       for (int j = 0; j < m; ++j) {         cin >> mp_cur[i][j];       }     }     for (int i = 0; i < n; ++i) {       for (int j = 0; j < m; ++j) {         cin >> mp_end[i][j];       }     }     if (!correct()) {       cout << -1 << endl;       return 0;     }     for (int i = 0; i < n; ++i) {       for (int j = 0; j < m; ++j) {         if (mp_cur[i][j] != mp_end[i][j]) {           if (mp_cur[i][j] ==  U ) {             opus(i, j);           } else if (mp_cur[i][j] ==  L ) {             podn(i, j);           }         }       }     }     cout << ans.size() << endl;     for (int i = 0; i < ans.size(); ++i) {       cout << ans[i].first <<     << ans[i].second << endl;     }     return 0;   }


#include <bits/stdc++.h>   namespace solution {   class ISolution {    public:     virtual void init(){};     virtual bool input() { return false; };     virtual void output(){};     virtual int run() = 0;   };   }  // namespace solution   namespace solution {}   namespace solution {   using namespace std;   const int SIZE = 1011;   const int MAX_TIME = 1000011;   int n;   int T[SIZE];   int C[SIZE];   long long X[MAX_TIME];   class Solution : public ISolution {    public:     bool input() {       if (!(cin >> n)) return false;       for (int i = 0; i < n; ++i) cin >> T[i] >> C[i];       return true;     }     void solve() {       fill(X, X + MAX_TIME, 0);       for (int i = 0; i < n; ++i) X[T[i]] += C[i];       long long t = 0;       long long res = 0;       long long sum = 0;       for (long long i = 0; i < MAX_TIME; ++i) {         if (sum > 0) {           t = max(t, i);           sum--;         }         sum += X[i];         res = max(res, sum);       }       if (sum) {         t += sum;       }       cout << t <<     << res << endl;     }     int run() {       while (init(), input()) {         solve();         output();       }       return 0;     }   };   }  // namespace solution   int main() { return solution::Solution().run(); }


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


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     ;     int bit;     cin >> bit;     ;     int sum = 0;     bool test = false;     for (int i = 1; i < n; i++) {       int h;       cin >> h;       ;       bit -= (h + 1);       if (bit < 0) {         cout <<  NO ;         return 0;       }     }     int h;     cin >> h;     ;     bit -= h;     if (bit != 0)       cout <<  NO ;     else       cout <<  YES ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   T POW(T b, T p) {     T r = 1;     while (p) {       if (p & 1) r = (r * b);       b = (b * b);       p >>= 1;     }     return r;   }   template <typename T>   T BigMod(T b, T p, T m) {     T r = 1;     while (p) {       if (p & 1) r = (r * b) % m;       b = (b * b) % m;       p >>= 1;     }     return r;   }   int main() {     long long n, a, b, c, cnt;     while (cin >> n) {       a = 1;       b = 1;       cnt = 0;       while (1) {         c = a + b;         a = b;         b = c;         if (c <= n)           cnt++;         else           break;       }       cout << cnt << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int arr[n];     int count25 = 0;     int count50 = 0;     int ans = 0;     for (int i = 0; i < n; i++) {       cin >> arr[i];       if (arr[i] == 25) {         count25++;       } else if (arr[i] == 50) {         if (count25 > 0) {           count25--;           count50++;         } else {           ans = -1;         }       } else if (arr[i] == 100) {         if ((count25 > 0 && count50 > 0) || (count25 >= 3 && count50 == 0)) {           if (count50 == 0) {             count25--;             count25--;             count25--;           } else {             count25--;             count50--;           }         } else {           ans = -1;         }       }     }     if (ans == -1) {       cout <<  NO ;     } else {       cout <<  YES ;     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 600005;   const long long mod = 1000000000000000003;   char str[N];   long long f[N];   unordered_set<long long> st;   int main() {     f[0] = 1;     int n, m;     for (int i = 1; i < 600000; i++) f[i] = f[i - 1] * 3 % mod;     cin >> n >> m;     while (n--) {       scanf( %s , str);       long long res = 0;       int len = strlen(str);       for (int i = 0; i < len; i++)         res = (res + f[len - i - 1] * (str[i] -  a )) % mod;       st.insert(res);     }     while (m--) {       scanf( %s , str);       long long sum = 0;       int flag = 0;       int len = strlen(str);       for (int i = 0; i < len; i++)         sum = (sum + f[len - i - 1] * (str[i] -  a )) % mod;       for (int i = 0; i < len; i++) {         long long sum2 = (sum - f[len - i - 1] * (str[i] -  a )) % mod;         if (sum2 < 0) sum2 += mod;         for (int j = 0; j < 3; j++) {           if (str[i] -  a  != j)             if (st.count((sum2 + f[len - i - 1] * j) % mod)) {               flag = 1;               break;             }         }         if (flag) break;       }       if (flag)         puts( YES );       else         puts( NO );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 2e6 + 5;   long long mod = 1e9 + 7, bas = 31;   long long h[2][N], pw[N], cnt[N];   char c[N];   long long n, q;   long long query(long long l, long long r, long long op) {     return ((h[op][r] - h[op][l - 1] * pw[cnt[r] - cnt[l - 1]]) % mod + mod) %            mod;   }   signed main() {     ios::sync_with_stdio(false);     cin >> n >> c + 1;     for (long long i = 1; i <= n; i++) {       h[0][i] = h[0][i - 1];       h[1][i] = h[1][i - 1];       cnt[i] = cnt[i - 1];       if (c[i] ==  0 ) {         h[0][i] = (h[0][i] * bas + i % 2 + 1) % mod;         h[1][i] = (h[1][i] * bas + (i + 1) % 2 + 1) % mod;         ++cnt[i];       }     }     pw[0] = 1;     for (long long i = 1; i <= n; i++) pw[i] = pw[i - 1] * bas % mod;     cin >> q;     for (long long i = 1; i <= q; i++) {       long long t1, t2, len;       cin >> t1 >> t2 >> len;       if (query(t1, t1 + len - 1, t1 & 1) == query(t2, t2 + len - 1, t2 & 1))         puts( Yes );       else         puts( No );     }   }


#include<bits/stdc++.h>   using namespace std;   #define endl   n    int main()    {      ios_base::sync_with_stdio(false);      cin.tie(NULL);      int t;      cin>>t;      while(t--)      {          long long int n,i,j,k,l;          cin>>n>>k;          if(k==1)          {              cout<< 1 <<endl;              continue;          }          if(n&1)          {              if(k*2>n-2)              {                  j=(n-2)/2+1;                  l=(k-1)/j;                  k=k+l;              }          }          if(k%n==0)          cout<<n<<endl;          else          cout<<(k%n)<<endl;      }      return 0;   }


#include <bits/stdc++.h>   using namespace std;   void doRoutine() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);   }   bool isInside(pair<long long int, long long int> p,                 pair<long long int, long long int> a[]) {     return (p.first >= a[0].first) && (p.second >= a[0].second) &&            (p.first <= a[3].first) && (p.second <= a[3].second);   }   signed main() {     doRoutine();     pair<long long int, long long int> a[4], b[4];     for (long long int i = 0; i < 4; i++) cin >> a[i].first >> a[i].second;     for (long long int i = 0; i < 4; i++) cin >> b[i].first >> b[i].second;     sort(a, a + 4);     sort(b, b + 4);     for (long long int i = b[0].first; i <= b[3].first; i++) {       long long int f =           b[0].second - (i <= b[1].first ? (i - b[0].first) : (b[3].first - i));       long long int s = (2 * b[0].second) - f;       for (long long int j = f; j <= s; j++) {         if (isInside({i, j}, a)) return cout <<  Yes  <<   n , 0;       }     }     cout <<  No  <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, k, x;   int bot[100001];   int top[100001];   int mir[101];   int hr, hl;   int uuh, bbh, ubh, buh;   int L = 100000;   double eps = 0.00001;   int mxr;   int sco(int s, bool up) {     int res = 0;     int dh = ((s % 2) ? (up ? uuh : bbh) : (up ? ubh : buh));     double f = ((double)(up ? (100 - hl) : hl)) * L / (100 * (s - 1) + dh);     double T = ((double)L * 100) / (100 * (s - 1) + dh);     int l1 = 0, l2 = 0, l3 = 0;     int* u = (up ? top : bot);     for (int i = 0; i < s; ++i) {       if ((f - floor(f)) > eps) {         l3 = u[(int)floor(f)];       } else {         l3 = max(u[(int)floor(f) - 1], u[(int)floor(f)]);       }       if ((l3 == l1) || (l3 == 0)) {         return 0;       }       l1 = l2;       l2 = l3;       res += mir[l3];       u = (u == top ? bot : top);       f += T;     }     return res;   }   int main(int argc, char** argv) {     cin >> hl >> hr >> n;     uuh = 200 - hl - hr;     bbh = hr + hl;     ubh = 100 + hr - hl;     buh = 100 + hl - hr;     int v, a, b;     char c;     for (int i = 1; i <= n; ++i) {       cin >> v >> c >> a >> b;       mir[i] = v;       if (c ==  T ) {         for (int j = a; j < b; ++j) {           top[j] = i;         }       } else {         for (int j = a; j < b; ++j) {           bot[j] = i;         }       }     }     double T;     int mxr = 0;     for (k = 1; k <= n; ++k) {       int res = sco(k, true);       if (res > mxr) {         mxr = res;       }       res = sco(k, false);       if (res > mxr) {         mxr = res;       }     }     cout << mxr;     return 0;   }


#include <bits/stdc++.h>   int main() {     int n, i, s = 0, m = 0, t;     int a[100001];     scanf( %d , &n);     for (i = 0; i < n; i++) {       scanf( %d , a + i);       s += a[i];     }     t = a[0];     if (t > m) m = t;     for (i = 1; i < n; i++) {       if (t > 0)         t += a[i];       else         t = a[i];       if (t > m) m = t;     }     printf( %d n , 2 * m - s);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 200000;   int a[N], n, m, k;   int check(int x) {     int cnt = 1, space = k;     for (int i = x; i < n; i++) {       if (a[i] <= space)         space -= a[i];       else {         if (cnt == m) return 0;         ++cnt, space = k - a[i];       }     }     return 1;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> n >> m >> k;     for (int i = 0; i < n; i++) cin >> a[i];     int l = 0, r = n - 1, mid;     while (l != r) {       mid = (l + r) / 2;       check(mid) ? r = mid : l = mid + 1;     }     cout << n - l <<   n ;     return 0;   }


#include <bits/stdc++.h>   #define IOS ios::sync_with_stdio(false), cin.tie(0)   #define debug(a) cout << #a  :   << a << endl   using namespace std;   typedef long long ll;   const int N = 1010;   int a[N][N], b[N][N], mov[3], loc[3];   int main(void){       IOS;       int T; cin >> T;       while (T--){           int n, m; cin >> n >> m;           for (int i = 0; i < n; ++i){               for (int j = 0; j < n; ++j){                   cin >> a[i][j];                   a[i][j]--;               }           }           for (int i = 0; i < 3; ++i){               mov[i] = 0;               loc[i] = i;           }           string op; cin >> op;           for (int i = 0; i < m; ++i){               if (op[i] ==  D ){                   mov[0] = (mov[0] + 1) % n;               }else if (op[i] ==  U ){                   mov[0] = (mov[0] - 1 + n) % n;               }else if (op[i] ==  L ){                   mov[1] = (mov[1] - 1 + n) % n;               }else if (op[i] ==  R ){                   mov[1] = (mov[1] + 1) % n;               }else if (op[i] ==  I ){                   swap(loc[1], loc[2]), swap(mov[1], mov[2]);               }else{                   swap(loc[0], loc[2]), swap(mov[0], mov[2]);               }           }           for (int i = 0; i < n; ++i){               for (int j = 0; j < n; ++j){                   int tmp[3] = {i, j, a[i][j]}, tp[3];                   for (int k = 0; k < 3; ++k){                       tp[k] = (tmp[loc[k]] + mov[k]) % n;                   }                   b[tp[0]][tp[1]] = tp[2];                   //b[tmp[loc[0]]][tmp[loc[1]]] = tmp[loc[2]];               }           }           for (int i = 0; i < n; ++i){               for (int j = 0; j < n; ++j){                   cout << b[i][j] + 1 <<    ;               }               cout << endl;           }           cout << endl;       }       return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long int N = 200005;   const long long int mod = 1e9 + 7;   long long int n, i, j, m, k;   long long int a[N];   long long int sz[N], c[N];   long long int vis[N];   vector<long long int> g[N];   long long int ans = 0;   void dfs(long long int v, long long int p) {     vis[v] = c[v];     for (auto x : g[v]) {       if (x != p) {         dfs(x, v);         vis[v] += vis[x];       }     }     ans += min(vis[v], 2 * k - vis[v]);   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> k;     for (i = 1; i <= 2 * k; i++) {       long long int x;       cin >> x;       c[x] = 1;     }     for (i = 1; i < n; i++) {       long long int x, y;       cin >> x >> y;       g[x].push_back(y);       g[y].push_back(x);     }     dfs(1, 0);     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       set<int> s;       for (int i = 0; i < n; i++) {         int a;         cin >> a;         s.insert(a);       }       cout << s.size() <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long Seg[3][1 << 21 + 2], X, Cnt = 1;   pair<long long, int> P[1000001];   int l_q, r_q, Len;   long long RSQ(int l, int r, int root) {     if (l > r_q || l_q > r || l > r) return 0;     if (l >= l_q && r <= r_q) return Seg[Len][root];     int mid = (r + l) / 2;     long long C1 = RSQ(l, mid, root * 2);     long long C2 = RSQ(mid + 1, r, root * 2 + 1);     return C1 + C2;   }   void Update(int l, int r, int root) {     if (l > r_q || l_q > r || l > r) return;     if (l >= l_q && r <= r_q) {       Seg[Len][root] += X;       return;     }     int mid = (r + l) / 2;     Update(l, mid, root * 2);     Update(mid + 1, r, root * 2 + 1);     Seg[Len][root] = Seg[Len][root * 2] + Seg[Len][root * 2 + 1];   }   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) cin >> P[i].first, P[i].second = i;     sort(P, P + n);     for (int i = 0; i < n; i++) {       P[P[i].second].first = Cnt++;     }     reverse(P, P + n);     for (int i = 0; i < n; i++) {       for (int L = 0; L < 3; L++) {         l_q = 1;         r_q = P[i].first - 1;         Len = L - 1;         long long val;         if (L == 0)           val = 1;         else           val = RSQ(1, n, 1);         l_q = r_q = P[i].first;         Len = L;         X = val;         Update(1, n, 1);       }     }     cout << Seg[2][1] << endl;     return 0;   }


#include <bits/stdc++.h>   int main(void) {     int n;     while (scanf( %d , &n) != EOF) {       int k = 0, flag = 0, su;       for (int i = 9; i >= 0; i--) {         if (i == n && i != 1) continue;         if (n % i == 0) {           k = n / i;           su = i;           break;         }       }       if (flag == 0) {         printf( %d n , k);         for (int i = 0; i < k; i++) {           printf( %d , su);           if (i != k - 1) printf(   );         }         printf(  n );       }     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast,unroll-loops )   #pragma GCC target( avx,avx2,fma )   using namespace std;   template <typename T>   using vc = vector<T>;   template <typename T>   using uset = unordered_set<T>;   template <typename A, typename B>   using umap = unordered_map<A, B>;   template <typename T, typename Comp = less<T>>   using pq = priority_queue<T, vc<T>, Comp>;   template <typename T>   using minpq = pq<T, greater<T>>;   using ld = long double;   using ll = long long;   using ull = unsigned long long;   using pii = pair<int, int>;   using ppi = pair<pii, int>;   using pip = pair<int, pii>;   using vi = vc<int>;   using vii = vc<pii>;   constexpr char el =   n ;   constexpr char sp =    ;   constexpr int INF = 0x3f3f3f3f;   constexpr ll LLINF = 0x3f3f3f3f3f3f3f3fLL;   int k;   string s;   vi a{-1};   ll evan(ll x) { return x * (x + 1) / 2; }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout << fixed;     cin >> k >> s;     for (int i = 0; i < s.size(); ++i)       if (s[i] ==  1 ) a.push_back(i);     a.push_back(s.size());     ll ans = 0;     if (k == 0) {       for (int i = 1; i < a.size(); ++i) ans += evan(a[i] - a[i - 1] - 1);       cout << ans;       exit(0);     }     int l = 1, r = k;     while (r + 1 < a.size()) {       ll A = a[l] - a[l - 1];       ll B = a[r + 1] - a[r];       ans += A * B;       ++l, ++r;     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9 + 5;   int n, m;   vector<vector<pair<int, int>>> adj;   vector<int> dist, color;   void bfs(int v) {     queue<int> q;     q.push(v);     while (!q.empty()) {       int u = q.front();       q.pop();       for (auto it : adj[u]) {         int to = it.first;         if (color[to] == -1) {           color[to] = (it.second == 1) ? 0 : 1;         } else {           if (dist[to] == INF && color[to] == it.second) {             dist[to] = dist[u] + 1;             q.push(to);           }         }       }     }   }   int main() {     cin >> n >> m;     dist.assign(n, INF);     adj.resize(n);     color.assign(n, -1);     dist[n - 1] = 0;     for (int i = 0; i < m; ++i) {       int u, v, t;       cin >> u >> v >> t;       u--;       v--;       adj[v].push_back({u, t});     }     bfs(n - 1);     if (dist[0] == INF) {       cout << -1 <<   n ;     } else {       cout << dist[0] <<   n ;     }     for (int i = 0; i < n; ++i) {       if (color[i] == -1)         cout << 0;       else         cout << color[i];     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<long long> a;   vector<long long> dp(2001);   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL), cout.tie(NULL);     int t = 1;     long long n, k, x, temp;     2000000001LL;     while (t--) {       cin >> n >> k;       for (int i = 0; i < n; i++) {         cin >> x, a.push_back(x);       }       long long left = 0, right = 2000000000LL;       long long required = 2000000001LL;       while (left < right) {         x = (left + right) / 2LL;         required = 2000000001LL;         for (int i = 0; i < n; i++) {           dp[i] = i;           for (int j = 0; j < i; j++) {             temp = (abs(a[i] - a[j]) + i - j - 1) / (i - j);             if (temp <= x) dp[i] = min(dp[i], dp[j] + i - j - 1);           }           required = min(required, dp[i] + n - i - 1);         }         if (required > k)           left = x + 1;         else           right = x;       }       cout << left << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string r, s, t, u;   int mini;   int main() {     int i, j, k;     cin >> r >> u;     int n, m = u.size();     mini = INT_MAX;     s =   ;     for (i = 0; i < m; i++) s.append( 0 );     s.append(r);     for (i = 0; i < m; i++) s.append( 0 );     n = s.size();     for (i = 0; i < n - m + 1; i++) {       t = s.substr(i, m);       int cont = 0;       for (k = 0; k < m; k++)         if (t[k] != u[k]) cont++;       if (mini > cont) mini = cont;     }     cout << mini << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     int p = 0, q = 0;     cin >> n;     int ar[n];     for (int i = 0; i < n; i++) {       cin >> ar[i];     }     for (int i = 0; i < n; i++) {       if (ar[i] == 5)         p++;       else         q++;     }     int r = p / 9;     if (q == 0)       cout <<  -1 ;     else if (p < 9 && q != 0)       cout <<  0 ;     else {       for (int i = 1; i <= r; i++) {         cout <<  555555555 ;       }       for (int i = 1; i <= q; i++) {         cout <<  0 ;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int M = 100100;   long long mabs(long long x) { return x < 0 ? -x : x; }   int n, m;   long long a[M], h[M];   long long q[M], c[M], qf, qs, sum;   void read() {     cin >> n >> m;     for (int i = 0; i < n; ++i) {       cin >> h[i];     }     for (int i = 0; i + 1 < n; ++i) {       a[i] = mabs(h[i + 1] - h[i]);     }   }   void ini() {     qf = qs = 0;     sum = 0;   }   void pop() {     --qf;     sum -= q[qf] * c[qf];   }   void push(long long x, long long cnt) {     assert(qs == qf || q[qf - 1] > x);     sum += x * cnt;     q[qf] = x;     c[qf] = cnt;     ++qf;   }   void add(long long x) {     long long cur = 1;     while (qs < qf && q[qf - 1] <= x) {       pop();       cur += c[qf];     }     push(x, cur);   }   long long get(long long l, long long r) {     long long ans = 0;     ini();     for (int i = l; i < r; ++i) {       add(a[i]);       ans += sum;     }     return ans;   }   void kill() {     for (int i = 0; i < m; ++i) {       int l, r;       cin >> l >> r;       --l;       --r;       cout << get(l, r) <<   n ;     }   }   int main() {     ios_base::sync_with_stdio(false);     cout.precision(13);     cout << fixed;     read();     kill();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using namespace rel_ops;   const double PI = acos((double)-1);   int ts, ts2, ts3, ts4;   int n, m;   long long gcd(long long x, long long y) {     long long t;     for (; y != 0;) {       t = x % y;       x = y;       y = t;     }     return x;   }   class point {    public:     double x, y;     point() { x = y = 0; }     point(double a, double b) { x = a, y = b; }     inline friend point operator+(const point &A, const point &B) {       return point(A.x + B.x, A.y + B.y);     }     inline friend point operator-(const point &A, const point &B) {       return point(A.x - B.x, A.y - B.y);     }     inline friend point operator*(const point &A, double p) {       return point(A.x * p, A.y * p);     }     inline friend point operator/(const point &A, double p) {       return point(A.x / p, A.y / p);     }     inline friend void operator+=(point &A, const point &B) { A = A + B; }     inline friend void operator-=(point &A, const point &B) { A = A - B; }     inline friend void operator*=(point &A, double B) { A = A * B; }     inline friend void operator/=(point &A, double B) { A = A / B; }     inline friend bool operator<(const point &A, const point &B) {       return A.x < B.x - 1E-10 || fabs(A.x - B.x) < 1E-10 && A.y + 1E-10 < B.y;     }     inline friend bool operator==(const point &A, const point &B) {       return !(A < B || B < A);     }     inline friend bool operator>(const point &A, const point &B) { return B < A; }   };   class XL {    public:     point a, b;     XL() {}     XL(point x, point y) {       a = x;       b = y;     }     XL(double t1, double t2, double t3, double t4) {       a.x = t1;       a.y = t2;       b.x = t3;       b.y = t4;     }   };   inline double gag(double x) {     if (x < -PI - 1E-10) return gag(x + 2 * PI);     if (x > PI - 1E-10) return gag(x - 2 * PI);     return x;   }   inline double gag2(double x) {     if (x < -1E-10) return gag2(x + 2 * PI);     if (x > 2 * PI - 1E-10) return gag2(x - 2 * PI);     return x;   }   inline double sqr(double x) { return x * x; }   inline double chaji(const point &A, const point &B) {     return A.x * B.y - B.x * A.y;   }   inline double dianji(const point &A, const point &B) {     return A.x * B.x + A.y * B.y;   }   inline double dis(const point &A, const point &B) {     return sqrt(sqr(A.x - B.x) + sqr(A.y - B.y));   }   inline double dis(const XL &A) { return dis(A.a, A.b); }   inline double dis(const point &A) { return sqrt(sqr(A.x) + sqr(A.y)); }   inline double atan2(const point &A) { return gag(atan2(A.y, A.x)); }   inline point shengcheng(double JD, double CD = 1.0) {     return point(cos(JD) * CD, sin(JD) * CD);   }   inline short sgn(double x) {     if (fabs(x) < 1E-10)       return 0;     else if (x < 0)       return -1;     else       return 1;   }   point ref(point a, point b) { return point(b.x * 2 - a.x, b.y * 2 - a.y); }   point s[5];   double sqr(point a) { return sqr(a.x) + sqr(a.y); }   int getcan;   point getwjy(point a, point b, point c) {     double d = 2 * (a.x * (b.y - c.y) + b.x * (c.y - a.y) + c.x * (a.y - b.y));     getcan = 1;     if (d == 0) {       getcan = 0;       return point(0, 0);     }     return point(         (sqr(a) * (b.y - c.y) + sqr(c) * (a.y - b.y) + sqr(b) * (c.y - a.y)) / d,         (sqr(a) * (c.x - b.x) + sqr(b) * (a.x - c.x) + sqr(c) * (b.x - a.x)) / d);   }   bool jud(point a, point b, point c) {     double u1, u2, u3, u4, u5, u6, u7, u8, u9;     s[2] = getwjy(a, ref(c, b), b);     if (getcan == 0) return 0;     s[3] = getwjy(ref(a, b), b, c);     if (getcan == 0) return 0;     s[1] = ref(s[2], a);     s[4] = ref(s[3], c);     int i;     for (i = 1; i <= 4; i++)       if ((u1 = chaji(s[i % 4 + 1] - s[i], s[(i + 1) % 4 + 1] - s[i % 4 + 1])) *               (u2 = chaji(s[(i + 1) % 4 + 1] - s[(i % 4 + 1)],                           s[((i + 1) + 1) % 4 + 1] - s[(i + 1) % 4 + 1])) <=           0)         break;     if (i <= 4) return 0;     cout <<  YES n ;     for (int i = 1; i <= 4; i++)       printf( %.9lf %.9lf%c , s[i].x, s[i].y, i == 4 ?   n  :    );     return 1;   }   int main() {     long long i, j, k, l, t1, t2, t3, t4, t5, t6, t7, t8, t9, t, nw;     int tt1, tt2, tt3, tt4;     double u1, u2, u3, u4, u5, u6, u7, u8, u9;     char c1, c2, c3;     srand((unsigned)time(0));     int _;     point a, b, c;     for (cin >> _; _--;) {       cin >> a.x >> a.y >> b.x >> b.y >> c.x >> c.y;       if (jud(c, a, b)) continue;       if (jud(a, b, c)) continue;       if (jud(b, c, a)) continue;       cout <<  NO n n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct edge {     int src, dst;   };   int const MOD = 1000000007;   long long _MOD = 1000000009;   double EPS = 1e-9;   long long INF = LLONG_MAX / 2;   int main() {     int N, w;     cin >> N >> w;     vector<int> a(N);     for (int i = 0; i < N; i++) cin >> a[i];     vector<int> b(N);     int sum = 0;     for (int i = 0; i < N; i++) {       b[i] = (a[i] + 1) / 2;       sum += b[i];     }     if (sum > w) {       cout << -1 << endl;       return 0;     }     vector<pair<int, int> > ai(N);     for (int i = 0; i < N; i++) ai[i] = pair<int, int>(a[i], i);     sort(ai.rbegin(), ai.rend());     for (int t = 0; t < N; t++) {       int i = ai[t].second;       int d = min(a[i] - b[i], w - sum);       b[i] += d;       sum += d;     }     for (int i = 0; i < N; i++) cout << b[i] <<    ;     cout << endl;   }


#include <bits/stdc++.h>   using namespace std;   long long exp(long long a, long long n) {     if (n == 0) return 1;     long long residue = 1, result = a % 1000000007LL;     while (n > 1LL) {       if (n % 2LL == 1LL) residue = residue * result % 1000000007LL;       result = result * result % 1000000007LL;       n = n >> 1LL;     }     return residue * result % 1000000007LL;   }   void sieve(long long n, vector<bool> &isPrime) {     for (int i = 0; i <= n; i++) isPrime[i] = true;     isPrime[0] = isPrime[1] = false;     for (long long i = 2; i * i <= n; i++) {       if (!isPrime[i]) continue;       for (long long j = i * i; j <= n; j += i) {         isPrime[j] = false;       }     }   }   long long nc2(long long n) { return (n * (n - 1LL) / 2LL) % 1000000007LL; }   bool checkPal(string s) {     string t = s;     reverse(s.begin(), s.end());     if (s == t)       return true;     else       return false;   }   void rev(int i, int k, string &s) {     int last = (i + k) / 2;     for (int t = i; t <= last; t++) {       swap(s[t], s[k - (t - i)]);     }   }   int len(string &s) { return s.size(); }   vector<int> KMP_preprocessing(string test1) {     vector<int> preprocess;     int i = 0, j = 1;     preprocess.push_back(0);     int len1 = len(test1);     while (i < len1 and j < len1) {       if (test1[i] == test1[j]) {         preprocess.push_back(i + 1);         i += 1;         j += 1;       } else {         while (i != 0 and test1[i] != test1[j]) {           i = preprocess[i - 1];         }         if (test1[i] == test1[j]) {           preprocess.push_back(i + 1);           i += 1;           j += 1;         } else           preprocess.push_back(0), j += 1;       }     }     return preprocess;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL), cout.tie(NULL);     int n, k;     vector<int> a(200001);     cin >> n >> k;     for (int i = 0; i < n; i++) cin >> a[i];     priority_queue<pair<int, pair<int, int>>, vector<pair<int, pair<int, int>>>,                    greater<pair<int, pair<int, int>>>>         minq;     int last = -1;     int ans;     for (int i = 0; i < n; i++) {       if (a[i] <= -1) {         if (last != -1)           minq.push(make_pair(i - last - 1, make_pair(last + 1, i - 1)));         last = i;       }     }     if (last != -1 && minq.size() + 1 > k) {       cout << -1 << endl;       return 0;     }     k -= minq.size() + 1;     while (minq.size() > 0 &&            (minq.top().first == 0 || minq.top().second.first == 0)) {       minq.pop();     }     ans = 2 * minq.size();     while (minq.size() > 0 && minq.top().first <= k) {       ans -= 2;       k -= minq.top().first;       minq.pop();     }     if (last != -1) {       ans++;       if (k < n - last - 1) {         ans++;       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC target( avx,tune=native )   using namespace std;   template <class T>   ostream &operator<<(ostream &os, vector<T> V) {     os <<  [ ;     for (auto const &vv : V) os << vv <<  , ;     os <<  ] ;     return os;   }   template <class L, class R>   ostream &operator<<(ostream &os, pair<L, R> P) {     os <<  (  << P.first <<  ,  << P.second <<  ) ;     return os;   }   template <typename T>   inline void print_128(T num) {     if (!num) return;     print_128(num / 10);     cout.put((num % 10) +  0 );   }   inline int fstoi(const string &str) {     auto it = str.begin();     bool neg = 0;     int num = 0;     if (*it ==  - )       neg = 1;     else       num = *it -  0 ;     ++it;     while (it < str.end()) num = num * 10 + (*it++ -  0 );     if (neg) num *= -1;     return num;   }   inline void getch(char &x) {     while (x = getchar_unlocked(), x < 33) {       ;     }   }   inline void getstr(string &str) {     str.clear();     char cur;     while (cur = getchar_unlocked(), cur < 33) {       ;     }     while (cur > 32) {       str += cur;       cur = getchar_unlocked();     }   }   template <typename... Args>   inline void getstr(string &str, Args &...arg) {     str.clear();     char cur;     while (cur = getchar_unlocked(), cur < 33) {       ;     }     while (cur > 32) {       str += cur;       cur = getchar_unlocked();     }     getstr(arg...);   }   template <typename T>   inline bool sc(T &num) {     bool neg = 0;     int c;     num = 0;     while (c = getchar_unlocked(), c < 33) {       if (c == EOF) return false;     }     if (c ==  - ) {       neg = 1;       c = getchar_unlocked();     }     for (; c > 47; c = getchar_unlocked()) num = num * 10 + c - 48;     if (neg) num *= -1;     return true;   }   template <typename T, typename... Args>   inline void sc(T &num, Args &...args) {     bool neg = 0;     int c;     num = 0;     while (c = getchar_unlocked(), c < 33) {       ;     }     if (c ==  - ) {       neg = 1;       c = getchar_unlocked();     }     for (; c > 47; c = getchar_unlocked()) num = num * 10 + c - 48;     if (neg) num *= -1;     sc(args...);   }   template <typename T>   inline T mod(T i, T n) {     return (i % n + n) % n;   }   inline void chkmax(int &a, const int &b) {     if (b > a) a = b;   }   inline void chkmin(int &a, const int &b) {     if (b < a) a = b;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n, l, r, k, t;     int posa[100001];     int posb[100001];     memset(posa, 127, sizeof posa);     memset(posb, 127, sizeof posb);     sc(n);     while (n--) {       sc(t, l, r);       --r;       if (t == 1) {         sc(k);         if (k > 0) {           int count = r - l + 1;           int n = (count + 7) >> 3;           int i = l;           switch (count % 8) {             case 0:               do {                 chkmin(posa[i], k);                 ++i;                 case 7:                   chkmin(posa[i], k);                   ++i;                 case 6:                   chkmin(posa[i], k);                   ++i;                 case 5:                   chkmin(posa[i], k);                   ++i;                 case 4:                   chkmin(posa[i], k);                   ++i;                 case 3:                   chkmin(posa[i], k);                   ++i;                 case 2:                   chkmin(posa[i], k);                   ++i;                 case 1:                   chkmin(posa[i], k);                   ++i;               } while (--n > 0);           }         } else {           k = -k;           int count = r - l + 1;           int n = (count + 7) >> 3;           int i = l;           switch (count % 8) {             case 0:               do {                 chkmin(posb[i], k);                 ++i;                 case 7:                   chkmin(posb[i], k);                   ++i;                 case 6:                   chkmin(posb[i], k);                   ++i;                 case 5:                   chkmin(posb[i], k);                   ++i;                 case 4:                   chkmin(posb[i], k);                   ++i;                 case 3:                   chkmin(posb[i], k);                   ++i;                 case 2:                   chkmin(posb[i], k);                   ++i;                 case 1:                   chkmin(posb[i], k);                   ++i;               } while (--n > 0);           }         }       } else {         long long ans = 0;         int count = r - l + 1;         int i = l;         int n = (count + 7) >> 3;         switch (count % 8) {           case 0:             do {               if (posa[i] < 0x7F7F7F7F && posb[i] < 0x7F7F7F7F)                 ans += posa[i] + posb[i];               ++i;               case 7:                 if (posa[i] < 0x7F7F7F7F && posb[i] < 0x7F7F7F7F)                   ans += posa[i] + posb[i];                 ++i;               case 6:                 if (posa[i] < 0x7F7F7F7F && posb[i] < 0x7F7F7F7F)                   ans += posa[i] + posb[i];                 ++i;               case 5:                 if (posa[i] < 0x7F7F7F7F && posb[i] < 0x7F7F7F7F)                   ans += posa[i] + posb[i];                 ++i;               case 4:                 if (posa[i] < 0x7F7F7F7F && posb[i] < 0x7F7F7F7F)                   ans += posa[i] + posb[i];                 ++i;               case 3:                 if (posa[i] < 0x7F7F7F7F && posb[i] < 0x7F7F7F7F)                   ans += posa[i] + posb[i];                 ++i;               case 2:                 if (posa[i] < 0x7F7F7F7F && posb[i] < 0x7F7F7F7F)                   ans += posa[i] + posb[i];                 ++i;               case 1:                 if (posa[i] < 0x7F7F7F7F && posb[i] < 0x7F7F7F7F)                   ans += posa[i] + posb[i];                 ++i;             } while (--n > 0);         }         cout << ans <<   n ;       }     }   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 ,  unroll-all-loops )   #pragma GCC target( sse4.2 )   using namespace std;   ifstream in;   ofstream out;   const long long kk = 1000;   const long long ml = kk * kk;   const long long mod = ml * kk + 7;   const long long inf = ml * ml * ml + 7;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   struct Tree {     int s = 1;     int n = 0;     long long my_null = -mod;     vector<pair<long long, long long>> t;     vector<pair<long long, long long>> seg;     inline long long res(long long v1, long long v2) { return max(v1, v2); }     void cnt_seg() {       seg.resize(2 * s);       seg[1] = {0, s};       for (int i = 1; i < s; i++) {         int tm = seg[i].first + seg[i].second >> 1;         seg[2 * i] = {seg[i].first, tm};         seg[2 * i + 1] = {tm, seg[i].second};       }     }     void build(long long sz) {       n = sz;       while (s < n) s <<= 1;       t.resize(2 * s, {my_null, 0});       cnt_seg();     }     void build(vector<int> v) {       n = v.size();       while (s < n) s <<= 1;       t.resize(2 * s, {my_null, 0});       for (int i = 0; i < n; i++) t[s + i] = {v[i], 0};       for (int i = s - 1; i > 0; i--) upd(i);       cnt_seg();     }     inline void adder(int v, long long val) {       t[v].first += val;       t[v].second += val;     }     void upd(int v) {       if (v >= s) return;       t[v].first = res(t[2 * v].first, t[2 * v + 1].first);     }     void push(int v) {       if (v >= s) return;       long long psh = t[v].second;       if (psh == 0) return;       t[v].second = 0;       adder(2 * v, psh);       adder(2 * v + 1, psh);     }     long long val(int l, int r, int v, int tl, int tr) {       if (r <= tl || tr <= l) return my_null;       push(v);       if (l <= tl && tr <= r) return t[v].first;       int tm = tl + tr >> 1;       long long v1 = val(l, r, 2 * v, tl, tm);       long long v2 = val(l, r, 2 * v + 1, tm, tr);       upd(v);       return res(v1, v2);     }     long long val(int l, int r) { return val(l, r + 1, 1, 0, s); }     long long val(int pl) { return val(pl, pl + 1, 1, 0, s); }     void add(int l, int r, int v, int tl, int tr, long long val) {       if (r <= tl || tr <= l) return;       push(v);       if (l <= tl && tr <= r) return void(adder(v, val));       int tm = tl + tr >> 1;       add(l, r, 2 * v, tl, tm, val);       add(l, r, 2 * v + 1, tm, tr, val);       upd(v);     }     void add(int v, long long val) {       v += s;       t[v].first += val;       v >>= 1;       while (v) upd(v), v >>= 1;     }     void add(int l, int r, long long t) { add(l, r + 1, 1, 0, s, t); }     void show() {       for (long long i = 1; i < 2 * s; i++) {         cout <<   t  <<  {  << t[i].first <<       << t[i].second <<  }  ;         if ((i & (i + 1)) == 0) cout << endl;       }     }   };   int n, m, q;   vector<int> val;   vector<int> ver_by_val;   vector<vector<int>> e;   vector<pair<int, int>> all;   vector<pair<int, int>> qr;   bool viv = false;   vector<int> p;   vector<vector<int>> kids;   int nxt;   vector<int> spliter;   vector<int> value_st;   Tree st;   set<pair<int, int>> seg;   void read() {     cin >> n >> m >> q;     val.resize(n);     ver_by_val.resize(n);     for (auto &i : val) cin >> i, i--;     for (int i = 0; i < n; i++) ver_by_val[val[i]] = i;     e.resize(n);     for (int i = 0; i < m; i++) {       int a, b;       cin >> a >> b;       a--, b--;       e[a].push_back(b);       e[b].push_back(a);       all.push_back({a, b});     }     qr.resize(q);     set<int> left;     for (int i = 0; i < m; i++) left.insert(i);     for (auto &p : qr) {       cin >> p.first >> p.second;       p.first--;       p.second--;       if (p.first) left.erase(p.second);     }     for (auto ed : left) qr.push_back({1, ed});     q = qr.size();   }   int pr(int v) {     if (p[v] == v) return v;     return p[v] = pr(p[v]);   }   bool unit(int v, int u) {     v = pr(v);     u = pr(u);     if (v == u) return false;     int s = nxt++;     kids[s].push_back(v);     kids[s].push_back(u);     p[v] = s;     p[u] = s;     return true;   }   void prepare() {     p.resize(2 * n - 1);     kids.resize(2 * n - 1);     for (int i = 0; i < p.size(); i++) p[i] = i;     nxt = n;     vector<long long> ord;     for (auto p : qr)       if (p.first) ord.push_back(p.second);     reverse(ord.begin(), ord.end());     for (auto num : ord) {       int v = all[num].first;       int u = all[num].second;       if (unit(v, u))         spliter.push_back(nxt - 1);       else         spliter.push_back(-1);     }     if (viv) {       for (int i = 0; i < nxt; i++) {         cout <<  kids[  << i <<  ] =  ;         for (auto v : kids[i]) cout << v <<    ;         cout << endl;       }       cout <<  Spliter =  ;       for (auto i : spliter) cout << i <<    ;       cout << endl;     }   }   vector<int> tin, tout;   int t = 0;   void DFS(int v) {     int my_val = -mod;     if (v < n) my_val = val[v];     value_st[t] = my_val;     tin[v] = t++;     for (auto u : kids[v])       if (tin[u] == -1) DFS(u);     value_st[t] = my_val;     tout[v] = t++;   }   void build() {     tin.resize(nxt, -1);     tout.resize(nxt, -1);     value_st.resize(2 * nxt);     for (int i = nxt - 1; i >= 0; i--) {       if (tin[i] == -1) {         DFS(i);         seg.insert({tin[i], tout[i]});       }     }     st.build(value_st);     if (viv) {       for (int i = 0; i < nxt; i++) {         cout <<  seg[  << i <<  ] =   << tin[i] <<     << tout[i] << endl;       }     }   }   bool out_seg(int p, pair<int, int> seg) {     if (p < seg.first || seg.second < p) return true;     return false;   }   void work() {     if (viv) st.show();     for (auto p : qr) {       if (p.first) {         int s = spliter.back();         spliter.pop_back();         if (s != -1) {           int v = kids[s][0];           int u = kids[s][1];           if (viv) {             cout <<  split vertex   << s <<   on   << v <<   and   << u << endl;           }           seg.erase({tin[s], tout[s]});           seg.insert({tin[v], tout[v]});           seg.insert({tin[u], tout[u]});           if (viv) {             for (auto p : seg)               cout <<  {  << p.first <<  ,   << p.second <<  },  ;             cout << endl;           }         }       } else {         int v = p.second;         int pl = tin[v];         if (viv) cout <<  find for   << v <<   include   << tin[v] << endl;         auto z = seg.lower_bound({pl, pl});         while (out_seg(pl, *z)) z--;         auto pr = *z;         int l = pr.first;         int r = pr.second;         auto ans = st.val(l, r);         if (ans >= 0) {           cout << ans + 1 <<   n ;           v = ver_by_val[ans];           st.add(tin[v], tin[v], -mod);           st.add(tout[v], tout[v], -mod);           if (viv) st.show();         } else {           cout <<  0 n ;         }       }     }   }   void solve() {     read();     prepare();     build();     work();   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long t = 1;     while (t--) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, x, y;     cin >> n >> m >> x >> y;     vector<vector<int>> chessboard(n, vector<int>(m));     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) chessboard[i][j] = 0;     cout << x <<     << y << endl;     chessboard[x - 1][y - 1] = 1;     if (chessboard[0][y - 1] == 0) cout << 1 <<     << y << endl;     chessboard[0][y - 1] = 1;     if (chessboard[0][0] == 0) cout << 1 <<     << 1 << endl;     chessboard[0][0] = 1;     int j = 0;     for (int i = 0; i < n; i++) {       if (j == m) j--;       if (j < 0) j++;       bool plus = (j == 0);       while (j >= 0 && j < m) {         if (chessboard[i][j] == 0) {           cout << i + 1 <<     << j + 1 << endl;           chessboard[i][j] = 1;         }         (plus) ? j++ : j--;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     vector<string> strs;     int n = 0;     int j = 0;     int count = 0;     cin >> n;     for (int i = 0; i < n; i++) {       if (i != 0) {         string temp =   ;         cin >> temp;       }       string str1 =   ;       string str2 =   ;       string str3 =   ;       string str4 =   ;       string str5 =   ;       string str6 =   ;       cin >> str1 >> str2;       str3 += str1.at(0);       str3 += str1.at(1);       str3 += str2.at(0);       str3 += str2.at(1);       str3 += str3;       str4 += str2.at(0);       str4 += str1.at(0);       str4 += str2.at(1);       str4 += str1.at(1);       str4 += str4;       str5 += str2.at(1);       str5 += str2.at(0);       str5 += str1.at(1);       str5 += str1.at(0);       str5 += str5;       str6 += str1.at(1);       str6 += str2.at(1);       str6 += str1.at(0);       str6 += str2.at(0);       str6 += str6;       if (i == 0) {         strs.push_back(str3);         strs.push_back(str4);         strs.push_back(str5);         strs.push_back(str6);         count++;       } else {         bool check = false;         for (int j = 0; j < strs.size(); j++) {           if (!strs[j].find(str1 + str2)) {             check = true;             break;           }         }         if (!check) {           strs.push_back(str3);           strs.push_back(str4);           strs.push_back(str5);           strs.push_back(str6);           count++;         }       }     }     cout << count << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 3e2 + 5;   int n;   long long hx, hy;   long long ux, uy;   struct line {     long long x1, y1;     long long x2, y2;     line(long long _x1, long long _y1, long long _x2, long long _y2) {       x1 = _x1;       y1 = _y1;       x2 = _x2;       y2 = _y2;     }   };   vector<line> lines;   void get_line(long long a, long long b, long long c) {     long long x1, y1;     long long x2, y2;     if (b == 0) {       x1 = -c / a;       x2 = -c / a;       y1 = -1e7;       y2 = 1e7;     }     if (a == 0) {       y1 = -c / b;       y2 = -c / b;       x1 = -1e7;       x2 = 1e7;     }     if (a != 0 && b != 0) {       x1 = -1e7;       x2 = 1e7;       y1 = (-a * x1 - c) / b;       y2 = (-a * x2 - c) / b;     }     lines.push_back(line(x1, y1, x2, y2));   }   struct point {     long long x;     long long y;     point() {       x = 0;       y = 0;     }     point(long long _x, long long _y) {       x = _x;       y = _y;     }   };   int orientation(point a, point b, point c) {     long long clockwise = (b.y - a.y) * (c.x - b.x) - (c.y - b.y) * (b.x - a.x);     if (clockwise > 0) return 1;     if (clockwise == 0) return 0;     if (clockwise < 0) return -1;   }   bool do_intersect(line a, line b) {     point a1, a2;     point b1, b2;     a1 = point(a.x1, a.y1);     a2 = point(a.x2, a.y2);     b1 = point(b.x1, b.y1);     b2 = point(b.x2, b.y2);     if ((orientation(a1, a2, b1) != orientation(a1, a2, b2)) &&         (orientation(b1, b2, a1) != orientation(b1, b2, a2)))       return true;     return false;   }   int ans;   int main() {     int i;     long long a, b, c;     cin >> hx >> hy;     cin >> ux >> uy;     cin >> n;     for (i = 1; i <= n; i++) {       scanf( %I64d%I64d%I64d , &a, &b, &c);       get_line(a, b, c);     }     line road = line(hx, hy, ux, uy);     for (i = 0; i < lines.size(); i++) {       if (do_intersect(road, lines[i])) ans++;     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL), cout.tie(NULL);     int n, t, num, x;     long long int ans;     cin >> n;     vector<int> vect;     vect.push_back(0);     for (int i = 0; i < n; ++i) {       cin >> x;       vect.push_back(x);     }     long long int dp[n];     dp[1] = vect[1];     t = log2(n - 1);     num = 1 + pow(2, t);     vect[num] += vect[1];     for (int i = 2; i <= n - 1; ++i) {       dp[i] = dp[i - 1] + vect[i];       t = log2(n - i);       num = i + pow(2, t);       vect[num] += vect[i];     }     for (int i = 1; i < n; ++i) cout << dp[i] << endl;     return 0;   }


#include <bits/stdc++.h>   void err() { std::cout << std::endl; }   template <typename T, typename... Args>   void err(T a, Args... args) {     std::cout << a <<    ;     err(args...);   }   template <template <typename...> class T, typename t, typename... A>   void err(const T<t> &arg, const A &...args) {     for (auto &v : arg) std::cout << v <<    ;     err(args...);   }   using namespace std;   const int N = 1e5 + 5;   void run() {     string s, t;     cin >> s >> t;     int n = s.length(), m = t.length();     vector<int> nxt(n, -1);     for (int i = 0; i < n; i++)       if (s[i] !=  . ) {         int t = 0;         for (int j = i; j < n; j++) {           if (s[j] !=  . )             ++t;           else             --t;           if (t == 0) {             nxt[i] = j;             break;           }         }       }     vector<vector<int>> dp(n + 1, vector<int>(m + 1, 0x3f3f3f3f));     dp[0][0] = 0;     for (int i = 0; i < n; i++) {       for (int j = 0; j <= m; j++) {         if (j < m && s[i] == t[j]) {           dp[i + 1][j + 1] = min(dp[i + 1][j + 1], dp[i][j]);         }         dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + 1);         if (s[i] !=  .  && nxt[i] != -1) {           dp[nxt[i] + 1][j] = min(dp[nxt[i] + 1][j], dp[i][j]);         }       }     }     cout << dp[n][m] <<   n ;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cout << fixed << setprecision(20);     run();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, k;     cin >> n >> k;     int cnt = 1;     if (k & 1)       puts( 1 );     else {       do {         k /= 2;         cnt++;       } while (k % 2 != 1);       cout << cnt;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, root;   vector<vector<int> > tree, par, sub;   vector<vector<long long> > dp;   void dfs(int u) {     sub[root][u] = 1;     for (int v : tree[u]) {       if (v == par[root][u]) continue;       par[root][v] = u;       dfs(v);       sub[root][u] += sub[root][v];     }   }   long long getDP(int u, int v) {     if (u == v) return 0;     if (dp[u][v] != -1) return dp[u][v];     long long res =         sub[u][v] * sub[v][u] + max(getDP(par[v][u], v), getDP(u, par[u][v]));     return dp[u][v] = res;   }   void input() {     scanf( %d , &n);     tree.assign(n, vector<int>());     for (int i = 0; i < n - 1; ++i) {       int u, v;       scanf( %d%d , &u, &v);       --u, --v;       tree[u].push_back(v);       tree[v].push_back(u);     }   }   void solve() {     par.assign(n, vector<int>(n, -1));     sub.assign(n, vector<int>(n, -1));     for (int u = 0; u < n; ++u) {       root = u;       dfs(u);     }     dp.assign(n, vector<long long>(n, -1LL));     long long ans = 0;     for (int u = 0; u < n; ++u)       for (int v = 0; v < n; ++v) ans = max(ans, getDP(u, v));     cout << ans << endl;   }   int main() {     input();     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long n, i, j, k, l, m, b, t, sum, sum1, flag, max1, min1, tmp;     cin >> n;     long long a[n + 1];     vector<long long> v;     queue<long long> q;     for (i = 1; i <= n; i++) {       cin >> a[i];       v.push_back(a[i]);       q.push(a[i]);     }     cin >> m >> k;     j = m + k;     sum = 0;     for (i = 1; i <= n; i++) {       l = a[i] / j;       sum1 = a[i] % j;       sum += l;       if (sum1 > m) {         sum++;       }     }     cout << sum * k << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, sum = 0;     cin >> n;     map<string, int> mp;     mp[ Tetrahedron ] = 4;     mp[ Cube ] = 6;     mp[ Octahedron ] = 8;     mp[ Dodecahedron ] = 12;     mp[ Icosahedron ] = 20;     while (n--) {       string s;       cin >> s;       sum += mp[s];     }     cout << sum << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   double A[100], B[100];   int main() {     int n, V;     cin >> n >> V;     double S = 0.0;     for (int i = 0; i < n; i++) {       cin >> A[i];       S += A[i];     }     for (int i = 0; i < n; i++) A[i] *= V / S;     double MIN = 1.0;     for (int i = 0; i < n; i++) {       cin >> B[i];       MIN = min(MIN, B[i] / A[i]);     }     double result = 0.0;     for (int i = 0; i < n; i++) result += A[i] * MIN;     cout.precision(10);     cout << result;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   void mnm(T &a, T b) {     a = min(a, b);   };   template <typename T>   void mxm(T &a, T b) {     a = max(a, b);   };   template <typename T>   int discrete_id(vector<T> &vals, T val, int startId = 1) {     return startId +            (int)(lower_bound(vals.begin(), vals.end(), val) - vals.begin());   }   long long power(long long a, long long n, long long mod) {     long long ans = 1;     while (n) {       if (n & 1) ans = (ans * a) % mod;       a = (a * a) % mod;       n /= 2;     }     return ans;   }   long long modul(long long x, long long mod) {     x %= mod;     if (x < 0) x += mod;     return x;   }   tuple<long long, long long, long long> eea(long long x, long long y) {     if (y == 0) return {1LL, 0LL, x};     long long a, b, d, q = x / y;     tie(a, b, d) = eea(y, x % y);     return {b, a - b * q, d};   }   long long inv(long long x, long long m) {     long long a, b, d;     tie(a, b, d) = eea(x, m);     assert(d == 1);     return modul(a, m);   }   char i2c(int c) { return (char)(c +  0 ); }   int get_subtree_sz(int u, int pa, vector<vector<pair<int, int>>> &adj,                      vector<bool> &deleted, vector<int> &subsz) {     subsz[u] = 1;     for (auto e : adj[u]) {       int v = e.first;       if (v != pa && !deleted[v]) {         subsz[u] += get_subtree_sz(v, u, adj, deleted, subsz);       }     }     return subsz[u];   }   int get_centroid(int u, int pa, int desired,                    vector<vector<pair<int, int>>> &adj, vector<bool> &deleted,                    vector<int> &subsz) {     for (auto e : adj[u]) {       int v = e.first;       if (v != pa && !deleted[v] && subsz[v] > desired) {         return get_centroid(v, u, desired, adj, deleted, subsz);       }     }     return u;   }   int neg(int u, int mod) { return (mod - u) % mod; }   void visit(int u, int pa, vector<vector<pair<int, int>>> &adj,              vector<bool> &deleted, map<int, int> &need_up, map<int, int> &cnt_up,              long long &ans, bool add, int _10pd, int _10pmd, int inv10,              int cur_up, int cur_down, int m, int depth = 1) {     if (add) {       ans += cnt_up[(1LL * neg(cur_down, m) * _10pmd) % m];       ans += need_up[cur_up];     } else {       ++cnt_up[cur_up];       ++need_up[(1LL * neg(cur_down, m) * _10pmd) % m];     }     for (auto e : adj[u]) {       int v, w;       tie(v, w) = e;       if (v != pa && !deleted[v]) {         w %= m;         int new_down = (10LL * cur_down + w) % m;         int new_up = (1LL * w * _10pd + cur_up) % m;         visit(v, u, adj, deleted, need_up, cnt_up, ans, add, (10LL * _10pd) % m,               (1LL * inv10 * _10pmd) % m, inv10, new_up, new_down, m, depth + 1);       }     }   }   long long centroid_decomp(int u, vector<vector<pair<int, int>>> &adj,                             vector<bool> &deleted, vector<int> &subsz,                             map<int, int> &need_up, map<int, int> &cnt_up, int m,                             int inv10) {     u = get_centroid(u, 0, get_subtree_sz(u, 0, adj, deleted, subsz) / 2, adj,                      deleted, subsz);     deleted[u] = true;     cnt_up[0] = 1;     need_up[0] = 1;     long long ans = 0;     for (auto e : adj[u]) {       int v, w;       tie(v, w) = e;       if (!deleted[v]) {         w %= m;         visit(v, u, adj, deleted, need_up, cnt_up, ans, true, 10 % m, inv10,               inv10, w, w, m);         visit(v, u, adj, deleted, need_up, cnt_up, ans, false, 10 % m, inv10,               inv10, w, w, m);       }     }     cnt_up.clear();     need_up.clear();     for (auto e : adj[u]) {       int v = e.first;       if (!deleted[v]) {         long long tmp =             centroid_decomp(v, adj, deleted, subsz, need_up, cnt_up, m, inv10);         ans += tmp;       }     }     return ans;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n, m;     cin >> n >> m;     vector<vector<pair<int, int>>> adj(n + 1);     for (int i = (int)(1); i <= (int)(n - 1); ++i) {       int u, v, w;       cin >> u >> v >> w;       adj[u].emplace_back(v, w);       adj[v].emplace_back(u, w);     }     vector<bool> deleted(n + 1, 0);     vector<int> subsz(n + 1);     map<int, int> need_up, cnt_up;     long long a, b, d;     tie(a, b, d) = eea(10LL, m);     int inv10 = modul(a, m);     cout << centroid_decomp(0, adj, deleted, subsz, need_up, cnt_up, m, inv10)          <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   bool f1(pair<long long, long long> x, pair<long long, long long> y) {     return x.first > y.first;   }   bool f2(pair<long long, long long> x, pair<long long, long long> y) {     return x.second > y.second;   }   bool f3(long long x, long long y) { return x > y; }   bool fa(vector<long long> x, vector<long long> y) { return x[0] < y[0]; }   long long fac(long long a) {     if (a == 1 || a == 0) {       return 1;     } else {       return (a * fac(a - 1));     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     string a;     cin >> a;     vector<long long> b;     if (a.size() == 1) {       cout << a;       exit(0);     }     a = a +  0 ;     for (long long i = 0; i < a.size() - 1; i++) {       if (a[i] == a[i + 1] && a[i] == a[i + 2]) {         a[i] =  0 ;       }     }     for (long long i = 0; i < a.size(); i++) {       if (a[i] !=  0 ) b.push_back(a[i]);     }     vector<long long> c;     long long check = 0;     for (long long i = 0; i < b.size() - 1; i++) {       if (b[i] == b[i + 1]) {         c.push_back(i);         check++;       }     }     if (check > 0) {       for (long long i = 0; i < c.size() - 1; i++) {         if (c[i] == c[i + 1] - 2) {           b[c[i + 1]] = 0;           i++;         }       }     }     for (long long i = 0; i < b.size(); i++) {       if (b[i] != 0) {         char g = b[i];         cout << g;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   long long dx[] = {-1, 0, 1, 0};   long long dy[] = {0, -1, 0, 1};   long long msum(long long a, long long b, long long m) {     return (a % m + b % m) % m;   }   long long msub(long long a, long long b, long long m) {     return (a % m - b % m) % m;   }   long long mpro(long long a, long long b, long long m) {     return ((a % m) * (b % m)) % m;   }   void swap(long long &a, long long &b) {     long long t = a;     a = b;     b = t;   }   long long m_m(long long a, long long b, long long m) {     long long res = 0;     a = a % m;     while (b) {       if (b & 1) {         res += a;         res = res % m;       }       a = (a * 2) % m;       b = b / 2;     }     return res;   }   long long fxp(long long a, long long b, long long m) {     if (b == 0) return 1;     if (b % 2 == 0) return fxp(m_m(a, a, m), b / 2, m);     return m_m(fxp(a, b - 1, m), a, m);   }   bool sortbysecdesc(const pair<long long, long long> &a,                      const pair<long long, long long> &b) {     return a.second > b.second;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n, m;     cin >> n >> m;     char a[n][m];     for (long long i = 0; i < n; i++) {       for (long long j = 0; j < m; j++) {         cin >> a[i][j];       }     }     for (long long i = 0; i < n; i++) {       for (long long j = 0; j < m; j++) {         if (a[i][j] ==  - )           cout << a[i][j];         else {           if ((i + j) % 2 == 0)             cout <<  B ;           else             cout <<  W ;         }       }       cout <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   vector<int> tree[300001];   int cento[300001];   int sub[300001];   int maxCh[300001];   int n, q;   void dfs(int u, int p = -1) {     sub[u] = 1;     maxCh[u] = 0;     for (int j = 0; j < tree[u].size(); ++j) {       int v = tree[u][j];       if (v == p) continue;       dfs(v, u);       sub[u] += sub[v];       maxCh[u] = max(maxCh[u], sub[v]);     }   }   set<pair<pair<int, int>, int> > merge(int u, int p = -1) {     int sz = tree[u].size();     if (sz == 1 && u != 0) {       cento[u] = u;       set<pair<pair<int, int>, int> > s;       s.insert(make_pair(pair<int, int>(sub[u], maxCh[u]), u));       return s;     }     int bigCh = -1;     int maxsz = -1;     for (int j = 0; j < tree[u].size(); ++j) {       int v = tree[u][j];       if (v == p) continue;       if (maxsz < sub[v]) {         maxsz = sub[v];         bigCh = v;       }     }     set<pair<pair<int, int>, int> > s = merge(bigCh, u);     for (int j = 0; j < tree[u].size(); ++j) {       int v = tree[u][j];       if (v == p || v == bigCh) continue;       set<pair<pair<int, int>, int> > tmp = merge(v, u);       for (set<pair<pair<int, int>, int> >::iterator it = tmp.begin();            it != tmp.end(); ++it) {         s.insert(*it);       }     }     s.insert(make_pair(pair<int, int>(sub[u], maxCh[u]), u));     int x = sub[u] >> 1;     ;     if (sub[u] & 1) ++x;     set<pair<pair<int, int>, int> >::iterator it =         s.lower_bound(make_pair(pair<int, int>(x, 0), 0));     cento[u] = it->second;     return s;   }   int main() {     scanf( %d %d , &n, &q);     int v = 0;     for (int i = 1; i < n; ++i) {       scanf( %d , &v);       --v;       tree[i].push_back(v);       tree[v].push_back(i);     }     memset(cento, -1, sizeof(cento));     dfs(0, -1);     for (int i = 0; i < n; ++i) {       --sub[i];     }     merge(0, -1);     while (q--) {       int u;       scanf( %d , &u);       --u;       printf( %d n , cento[u] + 1);     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 400005;   int tr[N << 2], lz[N << 2];   set<int> st[N];   inline void push(int v, int l, int r) {     tr[v] += lz[v];     if (l != r) {       lz[2 * v] += lz[v];       lz[2 * v + 1] += lz[v];     }     lz[v] = 0;   }   void build(int v, int l, int r, int n) {     lz[v] = 0;     if (l == r) {       tr[v] = l - 1;       return;     }     int m = (l + r) / 2;     build(2 * v, l, m, n);     build(2 * v + 1, m + 1, r, n);     tr[v] = max(tr[2 * v], tr[2 * v + 1]);   }   void update(int v, int s, int e, int l, int r, int x) {     push(v, s, e);     if (l <= s && e <= r) {       tr[v] += x;       if (s != e) {         lz[2 * v] += x;         lz[2 * v + 1] += x;       }       return;     }     if (r < s || e < l || l > r) return;     int m = (s + e) / 2;     update(2 * v, s, m, l, r, x);     update(2 * v + 1, m + 1, e, l, r, x);     tr[v] = max(tr[2 * v], tr[2 * v + 1]);   }   int query(int v, int s, int e, int l, int r) {     push(v, s, e);     if (l <= s && e <= r) return tr[v];     int m = (s + e) / 2;     if (r <= m) return query(2 * v, s, m, l, r);     if (m < l) return query(2 * v + 1, m + 1, e, l, r);     return max(query(2 * v, s, m, l, r), query(2 * v + 1, m + 1, e, l, r));   }   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cout << setprecision(32);     int n, k, m;     cin >> n >> k >> m;     int n2 = n << 1;     build(1, 1, n2, n2);     int x, y;     map<int, int> mp;     while (m--) {       cin >> x >> y;       y += abs(k - x);       if (st[y].find(x) != st[y].end()) {         update(1, 1, n2, 1, y, -1);         st[y].erase(x);         mp[y]--;         if (!mp[y]) mp.erase(y);       } else {         update(1, 1, n2, 1, y, 1);         st[y].insert(x);         mp[y]++;       }       if (mp.empty()) {         cout << 0 <<   n ;         continue;       }       int mx = mp.rbegin()->first;       cout << max(0, query(1, 1, n2, 1, mx) - n) <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 3e5 + 5;   const int mod = 998244353;   long long qpow(long long a, long long b) {     long long ans = 1;     a %= mod;     assert(b >= 0);     for (; b; b >>= 1) {       if (b & 1) ans = ans * a % mod;       a = a * a % mod;     }     return ans;   }   long long gcd(long long a, long long b) { return b > 0 ? gcd(b, a % b) : a; }   int a[maxn];   int w[maxn];   int one, zero, num, sum;   long long dp[60][60][60][60];   long long ans[60];   int main() {     int n, m, T;     cin >> n >> m;     for (int i = 1; i <= n; i++) cin >> a[i], num += a[i];     for (int i = 1; i <= n; i++)       cin >> w[i], sum = (sum + w[i]) % mod, one = (one + a[i] * w[i]) % mod;     zero = (sum - one + mod) % mod;     for (int i = 1; i <= n; i++) {       if (a[i] == 0) {         dp[1][i][0][1] = 1ll * qpow(sum, mod - 2) * w[i] % mod;         dp[1][i][0][0] = 1ll * qpow(sum, mod - 2) * (zero - w[i]) % mod;         dp[1][i][1][0] = 1ll * qpow(sum, mod - 2) * (one) % mod;       } else {         dp[1][i][1][1] = 1ll * qpow(sum, mod - 2) * w[i] % mod;         dp[1][i][1][0] = 1ll * qpow(sum, mod - 2) * (one - w[i]) % mod;         dp[1][i][0][0] = 1ll * qpow(sum, mod - 2) * (zero) % mod;       }     }     for (int i = 1; i <= m; i++) {       for (int j = 1; j <= n; j++) {         for (int t = 0; t <= i; t++) {           for (int k = 0; k <= i; k++) {             int state = ((sum + t - (i - t)) % mod + mod) % mod;             int o0 = zero - (i - t);             int o1 = one + t;             if (a[j] == 0) {               dp[i + 1][j][t][k] += 1ll * dp[i][j][t][k] * qpow(state, mod - 2) %                                     mod * (o0 - (w[j] - k)) % mod;               dp[i + 1][j][t][k] %= mod;               dp[i + 1][j][t][k + 1] += 1ll * dp[i][j][t][k] *                                         qpow(state, mod - 2) % mod *                                         ((w[j] - k)) % mod;               dp[i + 1][j][t][k + 1] %= mod;               dp[i + 1][j][t + 1][k] +=                   1ll * dp[i][j][t][k] * qpow(state, mod - 2) % mod * (o1) % mod;               dp[i + 1][j][t + 1][k] %= mod;             } else {               dp[i + 1][j][t + 1][k] += 1ll * dp[i][j][t][k] *                                         qpow(state, mod - 2) % mod *                                         (o1 - (w[j] + k)) % mod;               dp[i + 1][j][t + 1][k] %= mod;               dp[i + 1][j][t + 1][k + 1] += 1ll * dp[i][j][t][k] *                                             qpow(state, mod - 2) % mod *                                             ((w[j] + k)) % mod;               dp[i + 1][j][t + 1][k + 1] %= mod;               dp[i + 1][j][t][k] +=                   1ll * dp[i][j][t][k] * qpow(state, mod - 2) % mod * (o0) % mod;               dp[i + 1][j][t][k] %= mod;             }           }         }       }     }     for (int i = 1; i <= n; i++) {       for (int j = 0; j <= m; j++) {         for (int k = 0; k <= m; k++) {           int temp = a[i] ? 1 : -1;           ans[i] = (ans[i] + (w[i] + k * temp) * dp[m][i][j][k]) % mod;         }       }       cout << (ans[i] + mod) % mod << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   long long n;   long long b[200005];   long long cnt[65];   vector<long long> vec, vec2;   int main(void) {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n;     for (int i = 1; i <= n; i++) cin >> b[i];     for (int i = 1; i <= n; i++) {       long long x = 0;       for (long long t = b[i]; t % 2 == 0; t /= 2) x++;       cnt[x]++;     }     long long mn = -1e9, mn_i;     for (int i = 0; i < 65; i++) {       if (mn < cnt[i]) {         mn = cnt[i];         mn_i = i;       }     }     for (int i = 1; i <= n; i++) {       if (!(b[i] % (1LL << mn_i) == 0 && b[i] % (1LL << (mn_i + 1))))         vec.push_back(b[i]);     }     cout << (int)vec.size() << endl;     for (int i = 0; i < vec.size(); i++) cout << vec[i] <<    ;     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e9;   const long long N = 1e5 + 1;   const long long mod = 1e9 + 7;   const long double eps = 1E-7;   vector<int> a[N];   int n, k, x, ans;   int main() {     ios_base::sync_with_stdio(0);     cin >> n >> k;     for (int i = 1; i <= k; i++) cin >> x, a[x].push_back(i);     for (int i = 1; i <= n; i++) {       if (a[i].size() == 0)         ans += 1 + (i != 1) + (i != n);       else {         x = a[i][0];         if (i != 1)           if (upper_bound(a[i - 1].begin(), a[i - 1].end(), x) == a[i - 1].end())             ans++;         if (i != n)           if (upper_bound(a[i + 1].begin(), a[i + 1].end(), x) == a[i + 1].end())             ans++;       }     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   void fast_io() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);   }   signed main() {     fast_io();     long long x, y, z, t1, t2, t3;     cin >> x >> y >> z >> t1 >> t2 >> t3;     long long time1 = abs(y - x) * t1;     long long time2 = abs(x - z) * t2 + abs(y - x) * t2 + 3 * t3;     if (time2 <= time1) {       cout <<  YES ;     } else {       cout <<  NO ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   pair<int, int> a[1000001];   int b[1000001], ans[1000001];   int main() {     int n, h;     cin >> n >> h;     for (int i = 0; i < n; i++) {       int c;       cin >> c;       a[i] = make_pair(c, i + 1);     }     sort(a, a + n);     for (int i = 0; i < n; i++) b[i] = a[i].first;     int diff = b[n - 1] + b[n - 2] - b[0] - b[1];     int km = 0;     for (int k = 1; k < n; k++) {       int other;       int small = int(1e9);       if (k >= 2) {         other = b[1] + b[2];         if (other < small) small = other;       }       other = b[0] + b[1] + h;       if (other < small) small = other;       if (k < n - 1) {         other = b[0] + b[k + 1];         if (other < small) small = other;       }       int big = b[n - 1] + h;       if (k == n - 1)         big += b[0];       else         big += b[k];       other = b[n - 1] + b[n - 2];       if (other > big) big = other;       if (big - small < diff) {         diff = big - small;         km = k;       }     }     cout << diff << endl;     for (int i = 1; i <= n; i++) ans[i] = 1;     for (int i = 1; i <= km; i++) ans[a[i].second] = 2;     for (int i = 1; i <= n; i++) cout << ans[i] <<    ;     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int power(int x, int y, int p) {     int res = 1;     x = x % p;     if (x == 0) return 0;     while (y > 0) {       if (y & 1) res = (res * x) % p;       y = y >> 1;       x = (x * x) % p;     }     return res;   }   int main() {     {       ios_base::sync_with_stdio(0);       cin.tie(NULL);       cout.tie(NULL);     };     long long k, x = 1;     string s =  codeforces ;     int arr[10] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1};     cin >> k;     while (x < k) {       for (int i = 0; i < 10; i++) {         long long m = 1;         for (int j = 0; j < 10; j++)           if (j != i) m *= arr[j];         x += m;         arr[i]++;         if (x >= k) {           break;         };       }     }     for (int i = 0; i < 10; i++)       for (int j = 0; j < arr[i]; j++) cout << s[i];     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string second;     int ans = 0, a = 1;     cin >> second;     int k = second.length() - 1;     for (int i = 1; i < second.size(); i++) {       ans += (1 << i);     }     for (int i = 0; i < second.length(); i++) {       if (i == k) {         if (second[i] ==  4 )           ans += 1;         else           ans += 2;         continue;       }       if (second[i] ==  4 ) continue;       ans += (1 << (k - i));     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   const double PI = acos(-1.0);   using namespace std;   const int MAXN = 500117;   int n, a[MAXN], ans;   int main() {     scanf( %d , &n);     for (int i = 0; i < n; scanf( %d , &a[i++]))       ;     int j = 0, cur = 0;     for (int i = 1; i < n - 1; i++) {       if (a[i] != a[i - 1] && a[i] != a[i + 1]) {         if (cur == 0) j = i;         cur++;       } else if (cur > 0) {         ans = max(ans, (cur + 1) / 2);         for (int k = j, t = i - 1; k <= t;              a[k] = a[k - 1], a[t] = a[t + 1], k++, t--)           ;         cur = 0;       }     }     if (cur > 0) {       ans = max(ans, (cur + 1) / 2);       for (int k = j, t = n - 2; k <= t;            a[k] = a[k - 1], a[t] = a[t + 1], k++, t--)         ;     }     printf( %d n , ans);     for (int i = 0; i < n; printf( %d  , a[i++]))       ;     putchar(  n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int sum = 0;     bool ne = 0;     for (int i = 0; i < 5; i++) {       int x;       cin >> x;       sum += x;     }     if (sum % 5 != 0 or sum == 0) {       cout <<  -1 ;     } else       cout << sum / 5;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100010;   int n, q;   char s[N];   int t[26][4 * N];   int c[26][4 * N];   int d[26];   void pushDown(int id, int p, int l, int r, int m) {     if (c[id][p] == 0) {       t[id][p << 1] = 0;       t[id][p << 1 | 1] = 0;       c[id][p << 1] = 0;       c[id][p << 1 | 1] = 0;       c[id][p] = -1;     } else if (c[id][p] == 1) {       t[id][p << 1] = m - l + 1;       t[id][p << 1 | 1] = r - m;       c[id][p << 1] = 1;       c[id][p << 1 | 1] = 1;       c[id][p] = -1;     }   }   void update(int id, int p, int l, int r, int u, int v, int add) {     if (v < l || r < u) return;     if (u <= l && r <= v) {       t[id][p] = (r - l + 1) * add;       c[id][p] = add;       return;     }     int m = (l + r) >> 1;     pushDown(id, p, l, r, m);     update(id, p << 1, l, m, u, v, add);     update(id, p << 1 | 1, m + 1, r, u, v, add);     t[id][p] = t[id][p << 1] + t[id][p << 1 | 1];   }   int getSum(int id, int p, int l, int r, int u, int v) {     if (v < l || r < u) return 0;     if (u <= l && r <= v) return t[id][p];     int m = (l + r) >> 1;     pushDown(id, p, l, r, m);     int t1 = getSum(id, p << 1, l, m, u, v);     int t2 = getSum(id, p << 1 | 1, m + 1, r, u, v);     return t1 + t2;   }   int main() {     scanf( %d %d n , &n, &q);     scanf( %s n , s);     memset(t, 0, sizeof t);     memset(c, 0xff, sizeof c);     for (int i = 0; i < n; ++i) update(s[i] -  a , 1, 1, n, i + 1, i + 1, 1);     while (q--) {       int u, v, type;       scanf( %d %d %d n , &u, &v, &type);       for (int i = 0; i < 26; ++i) d[i] = getSum(i, 1, 1, n, u, v);       for (int i = 0; i < 26; ++i) update(i, 1, 1, n, u, v, 0);       if (type == 1) {         int p = u;         for (int i = 0; i < 26; ++i)           if (d[i]) {             update(i, 1, 1, n, p, p + d[i] - 1, 1);             p += d[i];           }       } else {         int p = u;         for (int i = 25; i >= 0; --i)           if (d[i]) {             update(i, 1, 1, n, p, p + d[i] - 1, 1);             p += d[i];           }       }     }     for (int i = 1; i <= n; ++i) {       for (int j = 0; j < 26; ++j) {         int p = getSum(j, 1, 1, n, i, i);         if (p) {           printf( %c ,  a  + j);           break;         }       }     }     printf(  n );     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast,no-stack-protector )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,mmx,tune=native )   #pragma comment(linker,  /STACK:256000000 )   using namespace std;   mt19937 rd(       (unsigned int)chrono::steady_clock::now().time_since_epoch().count());   const int INF = 1000 * 1000 * 1000 + 322;   const long long LLINF =       2LL * 1000LL * 1000LL * 1000LL * 1000LL * 1000LL * 1000LL + 57;   constexpr unsigned int MOD = 1000 * 1000 * 1000 + 7;   constexpr unsigned int FFT_MOD = 998244353;   const int P1E6 = 1336337;   const int P1E3 = 1009;   const long long P1E14 = 100000000000031;   const long long P1E17 = 100000000000000003;   const long double PI = acosl(-1.);   const long double EPS = 1e-9;   template <typename T, typename U>   inline ostream &operator<<(ostream &_out, const pair<T, U> &_p) {     _out << _p.x <<     << _p.y;     return _out;   }   template <typename T, typename U>   inline istream &operator>>(istream &_in, pair<T, U> &_p) {     _in >> _p.x >> _p.y;     return _in;   }   template <typename T>   inline ostream &operator<<(ostream &_out, const vector<T> &_v) {     if (_v.empty()) return _out;     _out << _v.front();     for (auto _it = ++_v.begin(); _it != _v.end(); ++_it) _out <<     << *_it;     return _out;   }   template <typename T>   inline istream &operator>>(istream &_in, vector<T> &_v) {     for (auto &_i : _v) _in >> _i;     return _in;   }   template <typename T>   inline ostream &operator<<(ostream &_out, const set<T> &_s) {     if (_s.empty()) return _out;     _out << *_s.begin();     for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) _out <<     << *_it;     return _out;   }   template <typename T>   inline ostream &operator<<(ostream &_out, const multiset<T> &_s) {     if (_s.empty()) return _out;     _out << *_s.begin();     for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) _out <<     << *_it;     return _out;   }   template <typename T>   inline ostream &operator<<(ostream &_out, const unordered_set<T> &_s) {     if (_s.empty()) return _out;     _out << *_s.begin();     for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) _out <<     << *_it;     return _out;   }   template <typename T>   inline ostream &operator<<(ostream &_out, const unordered_multiset<T> &_s) {     if (_s.empty()) return _out;     _out << *_s.begin();     for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) _out <<     << *_it;     return _out;   }   template <typename T, typename U>   inline ostream &operator<<(ostream &_out, const map<T, U> &_m) {     if (_m.empty()) return _out;     _out <<  (  << _m.begin()->x <<  :   << _m.begin()->y <<  ) ;     for (auto _it = ++_m.begin(); _it != _m.end(); ++_it)       _out <<  , (  << _it->x <<  :   << _it->y <<  ) ;     return _out;   }   template <typename T, typename U>   inline ostream &operator<<(ostream &_out, const unordered_map<T, U> &_m) {     if (_m.empty()) return _out;     _out <<  (  << _m.begin()->x <<  :   << _m.begin()->y <<  ) ;     for (auto _it = ++_m.begin(); _it != _m.end(); ++_it)       _out <<  , (  << _it->x <<  :   << _it->y <<  ) ;     return _out;   }   const char *infile =   ;   const char *outfile =   ;   inline long long gcd(long long a, long long b) {     while (b) {       a %= b;       swap(a, b);     }     return a;   }   inline long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }   inline int pwm(long long xx, long long pow, int MD) {     if (pow < 0) {       pow = pow % (MD - 1) + MD - 1;     }     long long mlt = 1;     while (pow) {       if (pow & 1) {         mlt *= xx;         mlt %= MD;       }       xx *= xx;       pow >>= 1;       xx %= MD;     }     return (int)mlt;   }   inline long long gcdex(long long a, long long b, long long &x, long long &y) {     if (b == 0) {       x = 1;       y = 0;       return a;     }     long long xx, yy;     long long gc = gcdex(b, a % b, yy, xx);     x = xx;     y = yy - (a / b) * xx;     return gc;   }   inline int inv(long long r, int _mod) { return pwm(r % _mod, _mod - 2, _mod); }   const int N = 500 * 1000 + 57;   int mpd[N];   int ans[N];   inline void solve() {     iota(mpd, mpd + N, 0);     for (int i = 2; i * i < N; ++i) {       if (mpd[i] == i) {         for (int j = i * i; j < N; j += i) {           mpd[j] = min(mpd[j], i);         }       }     }     int n;     cin >> n;     vector<int> ans;     for (int i = 1; i <= n; ++i) {       ans.push_back(i / mpd[i]);     }     sort((ans).begin(), (ans).end());     ans.erase(ans.begin());     cout << ans <<   n ;   }   int main() {     if (*infile !=   0 ) (void)freopen(infile,  r , stdin);     if (*outfile !=   0 ) (void)freopen(outfile,  w , stdout);     cout.tie(nullptr);     cin.tie(nullptr);     ios_base::sync_with_stdio(false);     cout << setprecision(20);     cout << fixed;     solve();     return 0;   }


#include <bits/stdc++.h>   int n, a[200010];   int main() {     scanf( %d , &n);     for (int i = 0; i < n * 2; i++) scanf( %d , a + i);     std::sort(a, a + n * 2);     long long ans = (a[n - 1] - a[0]) * 1ll * (a[n * 2 - 1] - a[n]), tmp;     for (int i = 0; i < n; i++)       if ((tmp = (a[n * 2 - 1] - a[0]) * 1ll * (a[i + n] - a[i + 1])) < ans)         ans = tmp;     printf( %lld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, p, c, t, sum = 0, res = 0, m, x = 0, y = 0;   vector<int> v, z;   int main() {     cin >> n >> c;     for (int i = 0; i < n; ++i) {       cin >> p;       v.push_back(p);     }     for (int i = 0; i < n; ++i) {       cin >> t;       z.push_back(t);     }     m = n - 1;     for (int i = 0; i < n; i++) {       x += z[i];       p = v[i] - (c * x);       if (p > 0) sum += p;       y += z[m];       t = v[m] - (c * y);       if (t > 0) res += t;       m--;     }     if (sum > res)       cout <<  Limak  << endl;     else if (res > sum)       cout <<  Radewoosh  << endl;     else       cout <<  Tie  << endl;     return 0;   }