#include <bits/stdc++.h>   using namespace std;   namespace dinic {   using ll = int;   const ll oo = 1e6;   const int N = 202 * 202 * 2;   const int E = 202 * 202 * 6 * 2 * 2;   vector<int> g[N];   int ne;   struct Edge {     int from, to;     ll flow, cap;   } edge[E];   int lvl[N], vis[N], pass, start = N - 2, target = N - 1;   int qu[N], qt, px[N];   ll run(int s, int sink, ll minE) {     if (s == sink) return minE;     ll ans = 0;     for (; px[s] < (int)g[s].size(); px[s]++) {       int e = g[s][px[s]];       auto &v = edge[e], &rev = edge[e ^ 1];       if (lvl[v.to] != lvl[s] + 1 || v.flow >= v.cap) continue;       ll tmp = run(v.to, sink, min(minE, v.cap - v.flow));       v.flow += tmp, rev.flow -= tmp;       ans += tmp, minE -= tmp;       if (minE == 0) break;     }     return ans;   }   bool bfs(int source, int sink) {     qt = 0;     qu[qt++] = source;     lvl[source] = 1;     vis[source] = ++pass;     for (int i = 0; i < qt; i++) {       int u = qu[i];       px[u] = 0;       if (u == sink) return true;       for (auto& ed : g[u]) {         auto v = edge[ed];         if (v.flow >= v.cap || vis[v.to] == pass) continue;         vis[v.to] = pass;         lvl[v.to] = lvl[u] + 1;         qu[qt++] = v.to;       }     }     return false;   }   ll flow(int source = start, int sink = target) {     ll ans = 0;     while (bfs(source, sink)) ans += run(source, sink, oo);     return ans;   }   void addEdge(int u, int v, ll c = 1, ll rc = 0) {     edge[ne] = {u, v, 0, c};     g[u].push_back(ne++);     edge[ne] = {v, u, 0, rc};     g[v].push_back(ne++);   }   };  // namespace dinic   const int N = 205;   int n, m;   char mat[N][N];   int main() {     scanf( %d %d , &n, &m);     for (int i = 0; i < n; i++) scanf( %s , mat[i]);     const int s = dinic::start;     const int t = dinic::target;     const int add = n * m;     int tot = 0;     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) {         if (mat[i][j] !=  # ) continue;         tot++;         if (mat[i + 1][j] !=  # ) continue;         if (j - 1 >= 0 and mat[i][j - 1] ==  # ) {           dinic::addEdge(i * m + j, add + i * m + j - 1);         }         if (mat[i][j + 1] ==  # ) {           dinic::addEdge(i * m + j, add + i * m + j);         }         if (j - 1 >= 0 and mat[i + 1][j - 1] ==  # ) {           dinic::addEdge(i * m + j, add + (i + 1) * m + j - 1);         }         if (mat[i + 1][j + 1] ==  # ) {           dinic::addEdge(i * m + j, add + (i + 1) * m + j);         }       }     int ver = 0;     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) {         if (mat[i][j] !=  # ) continue;         if (mat[i][j + 1] ==  # ) {           ver++;           dinic::addEdge(add + i * m + j, t);         }         if (mat[i + 1][j] ==  # ) {           ver++;           dinic::addEdge(s, i * m + j);         }       }     printf( %d n , tot - (ver - dinic::flow(s, t)));   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ld = long double;   constexpr int MAXN = 100005;   int SQRTN;   int n, k;   int t[MAXN], a[MAXN];   ll p[MAXN];   ll ans[MAXN];   ll cur = 0;   int ind[MAXN], left_ind[MAXN], right_ind[MAXN];   int freq[3 * MAXN];   struct query {     int l, r, i;   } queries[MAXN];   bool cmp(const query& a, const query& b) {     return a.l / SQRTN < b.l / SQRTN ||            (a.l / SQRTN == b.l / SQRTN and a.r < b.r);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     scanf( %d %d , &n, &k);     for (int i = 1; i <= n; ++i) {       scanf( %d , t + i);     }     for (int i = 1; i <= n; ++i) {       scanf( %d , a + i);     }     vector<ll> vals;     vals.push_back(0LL);     vals.push_back(k);     vals.push_back(-k);     p[0] = 0LL;     for (int i = 1; i <= n; ++i) {       if (t[i] == 1)         p[i] = p[i - 1] + a[i];       else         p[i] = p[i - 1] - a[i];       vals.push_back(p[i]);       vals.push_back(p[i] - k);       vals.push_back(p[i] + k);     }     sort(begin(vals), end(vals));     vals.erase(unique(begin(vals), end(vals)), end(vals));     for (int i = 0; i <= n; ++i) {       ind[i] = lower_bound(begin(vals), end(vals), p[i]) - begin(vals);       left_ind[i] = lower_bound(begin(vals), end(vals), p[i] - k) - begin(vals);       right_ind[i] = lower_bound(begin(vals), end(vals), p[i] + k) - begin(vals);     }     SQRTN = sqrt(n);     int q;     int l, r;     scanf( %d , &q);     for (int i = 0; i < q; ++i) {       scanf( %d %d , &l, &r);       --l;       queries[i] = {l, r, i};     }     sort(queries, queries + q, cmp);     int left_ptr = 0;     int right_ptr = -1;     for (int i = 0; i < q; ++i) {       while (right_ptr < queries[i].r) {         ++right_ptr;         cur += freq[left_ind[right_ptr]];         ++freq[ind[right_ptr]];       }       while (right_ptr > queries[i].r) {         --freq[ind[right_ptr]];         cur -= freq[left_ind[right_ptr]];         --right_ptr;       }       while (left_ptr < queries[i].l) {         --freq[ind[left_ptr]];         cur -= freq[right_ind[left_ptr]];         ++left_ptr;       }       while (left_ptr > queries[i].l) {         --left_ptr;         cur += freq[right_ind[left_ptr]];         ++freq[ind[left_ptr]];       }       ans[queries[i].i] = cur;     }     for (int i = 0; i < q; ++i) {       printf( %lld n , ans[i]);     }     return 0;   }


#include<bits/stdc++.h>   using namespace std;   typedef long long ll;   const int maxn=2e5+7;   const int modn = 1e9+7;   int a[maxn],b[maxn];   map<int,int> mp,mp2;   int binaryl(int value,int l,int r){       int res = l-1;       while(r >= l){           int mid = (r+l) >> 1;           if(b[mid] < value){               res = mid;               l = mid+1;           }           else r = mid-1;       }       return res;   }   int binaryr(int value,int l,int r){       int res = r + 1;       while(r >= l){           int mid = (r+l) >> 1;           if(b[mid] > value){               res = mid;               r = mid-1;           }           else l = mid+1;       }       return res;   }   int main(){       int T;       scanf( %d ,&T);       while(T--){           mp.clear();           mp2.clear();           int n,m;           scanf( %d%d ,&n,&m);           int midn = n+1,midm = m+1;           for(int i = 1;i <= n;i++){               scanf( %d ,&a[i]);               mp[a[i]] = 1;               if(midn == n+1 && a[i] > 0)midn = i;           }           for(int j = 1;j <= m;j++){               scanf( %d ,&b[j]);               mp2[b[j]] = 1;               if(midm == m+1 && b[j] > 0)midm = j;           }              int lstart = 0;           for(int i = 1;i < midm;i++){               if(mp[b[i]])lstart++;           }           int ans1 = lstart,ans2 = 0;           int now = midn-1;           int len = 0;           for(int i = midm-1;i >= 1;i--){   //            printf( %d n ,i);               int res = lstart;               int bb = b[i]-len;               while(now && bb <= a[now]){                   if(mp2[a[now]])res--;                   len++;                   bb--;                   now--;               }               if(!len)continue;               int where = b[i] - len+1;               where = binaryl(where,1,i);   //            printf( %d: where==%d res==%d len==%d n ,i,where,res,len);               lstart = res;               res += i - where;               ans1 = max(ans1,res);           }              int rstart = 0;           for(int i = midm;i <= m;i++){               if(mp[b[i]])rstart++;           }           ans2 = rstart;           now = midn;           len = 0;           for(int i = midm;i <= m;i++){               int res = rstart;               int bb = b[i] + len;               while(now <= n && bb >= a[now]){                   if(mp2[a[now]])res--;                   len++;                   bb++;                   now++;               }               if(len == 0)continue;               int where = b[i] + len-1;               where = binaryr(where,i,m);   //            printf( %d: where==%d res==%d len==%d n ,i,where,res,len);               rstart = res;               res += where - i;               ans2 = max(ans2,res);           }   //        printf( %d %d n ,ans1,ans2);           printf( %d n ,ans1+ans2);       }   }   /*   1000   5 5   -5 -3 -1 8 100   -9 -7 -3 1000 1001      1 5   -5   -10 -9 -8 -7 -4      5 5   -5 -4 -3 -2 -1   -100 -99 -96 -95 -94   */


#include <bits/stdc++.h>   using namespace std;   string to_string(string s) { return     + s +    ; }   string to_string(char s) { return string(1, s); }   string to_string(const char* s) { return to_string((string)s); }   string to_string(bool b) { return (b ?  true  :  false ); }   template <typename A>   string to_string(A);   template <typename A, typename B>   string to_string(pair<A, B> p) {     return  (  + to_string(p.first) +  ,   + to_string(p.second) +  ) ;   }   template <typename A>   string to_string(A v) {     bool f = 1;     string r =  { ;     for (const auto& x : v) {       if (!f) r +=  ,  ;       f = 0;       r += to_string(x);     }     return r +  } ;   }   void debug_out() { cout <<   n ; }   template <typename Head, typename... Tail>   void debug_out(Head H, Tail... T) {     cout <<     << to_string(H);     debug_out(T...);   }   const long long MOD = 1000000007;   long long binpow(long long b, long long p) {     long long ans = 1;     while (p > 0) {       if (p & 1) ans = (ans * b) % MOD;       b = (b * b) % MOD;       p >>= 1;     }     return ans;   }   long long modinv(long long x) { return binpow(x, MOD - 2); }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n, m, i, l, r;     cin >> n >> m;     vector<int> a(n), inc(n), dec(n);     for (i = 0; i < n; i++) {       cin >> a[i];       inc[i] = dec[i] = i;     }     for (i = n - 2; i >= 0; i--) {       if (a[i] <= a[i + 1]) inc[i] = inc[i + 1];       if (a[i] >= a[i + 1]) dec[i] = dec[i + 1];     }     while (m--) {       cin >> l >> r;       l--;       r--;       if (dec[inc[l]] >= r)         cout <<  Yes n ;       else         cout <<  No n ;     }   }


#include <bits/stdc++.h>   using namespace ::std;   const long double PI = acos(-1);   const long long MOD = 1000000000 + 7;   long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }   int add(int a, int b, int m = MOD) { return (a + b + m + m) % m; }   int mul(long long a, long long b, int m = MOD) { return (a * b) % m; }   long long pow_mod(long long a, long long b, long long m = MOD) {     long long res = 1LL;     a = a % m;     while (b) {       if (b & 1) res = mul(res, a, m);       b >>= 1;       a = mul(a, a, m);     }     return res;   }   long long fastexp(long long a, long long b) {     long long res = 1LL;     while (b) {       if (b & 1) res = res * a;       b >>= 1;       a *= a;     }     return res;   }   int gcdExtendido(int a, int b, int *x, int *y) {     if (a == 0) {       *x = 0;       *y = 1;       return b;     }     int x1, y1;     int gcd = gcdExtendido(b % a, a, &x1, &y1);     *x = y1 - (b / a) * x1;     *y = x1;     return gcd;   }   int modInverso(int a, int m) {     int x, y;     int g = gcdExtendido(a, m, &x, &y);     if (g != 1)       return -1;     else       return (x % m + m) % m;   }   const int N = 200000 + 5;   const int L = 2;   const unsigned int B[] = {257, 311};   int n;   string minimal(string s) {     if (s.size() & 1) return s;     string s1 = minimal(s.substr(0, s.size() / 2));     string s2 = minimal(s.substr(s.size() / 2, s.size() / 2));     if (s1 < s2) return s1 + s2;     return s2 + s1;   }   int main() {     string a, b;     cin >> a >> b;     if (minimal(a) == minimal(b))       puts( YES );     else       puts( NO );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   int n, k, a, b, q, cnt[N];   struct fenwick {     int fen[N];     void add(int p, int x) {       for (; p < N; p += p & -p) fen[p] += x;     }     int get(int p) {       int ans = 0;       for (; p; p -= p & -p) ans += fen[p];       return ans;     }   } fen1, fen2;   void readInput() { cin >> n >> k >> a >> b >> q; }   void writeOutput() {     for (int i = 0; i < q; i++) {       int t;       cin >> t;       if (t & 1) {         int d, x;         cin >> d >> x;         cnt[d] += x;         fen1.add(d, max(min(b, cnt[d]) - cnt[d] + x, 0));         fen2.add(n - d + 1, max(min(a, cnt[d]) - cnt[d] + x, 0));       } else {         int p;         cin >> p;         cout << fen1.get(p - 1) + fen2.get(n - p - k + 1) << endl;       }     }   }   int main() {     ios_base ::sync_with_stdio(false), cin.tie(0), cout.tie(0);     readInput(), writeOutput();     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   #pragma GCC optimize( Ofast )   using namespace std;   long long int n, k, a[200005], dp[200005];   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     cin >> n >> k;     for (long long int i = 1; i <= n; i++) {       cin >> a[i];     }     sort(a + 1, a + n + 1);     for (long long int i = 1; i <= n; i++) dp[i] = dp[i - 1] + a[i];     long long int i = 1, ans = -1;     while (i <= n) {       long long int j = i;       while (j + 1 <= n && a[j + 1] == a[j]) {         j++;       }       long long int cnt = j - i + 1;       if (cnt >= k) {         ans = 0;         break;       }       long long int cur = 1e18;       long long int s1 = i - 1;       long long int s2 = n - j;       long long int ans1 = 0, ans2 = 0;       ans1 = s1 * (a[i] - 1) - dp[i - 1] + dp[0];       ans2 = dp[n] - dp[j] - s2 * (a[i] + 1);       if (s2 + cnt >= k) {         cur = min(cur, ans2);       }       if (s1 + cnt >= k) {         cur = min(cur, ans1);       }       cur = min(cur, ans1 + ans2);       cur = cur + k - cnt;       if (ans == -1) {         ans = cur;       } else         ans = min(ans, cur);       i = j + 1;     }     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX_BUF_SIZE = 16384;   char BUFOR[MAX_BUF_SIZE];   int BUF_SIZE, BUF_POS;   char ZZZ;   const int MXN = 1000010;   const int C = 262144;   const int INF = 1000000001;   void test() {     int n;     scanf( %d , &n);     cout << ((long long int)(n - 1) * (n - 3) + 1) << endl;   }   int main() {     int te = 1;     while (te--) test();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n, x1, x2, m, c;     cin >> n >> x1 >> x2;     vector<pair<long long, long long>> v;     for (int i = 0; i < n; ++i) {       cin >> m >> c;       v.push_back({m * x1 + c, m * x2 + c});     }     sort(v.begin(), v.end());     long long p = v[0].second;     for (auto i : v) {       if (i.second < p) {         cout <<  YES ;         return 0;       }       p = i.second;     }     cout <<  NO  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, a, b;     cin >> n;     map<int, vector<vector<int> > > m;     vector<int> v, ans;     map<int, int> s;     for (int i = 0; i < n - 2; i++) {       int f, g, h;       cin >> f >> g >> h;       v.push_back(f);       v.push_back(g);       v.push_back(h);       s[f]++;       s[g]++;       s[h]++;       m[f].push_back(v);       m[g].push_back(v);       m[h].push_back(v);       v.clear();     }     for (auto i = s.begin(); i != s.end(); i++) {       if (i->second == 1) {         ans.push_back(i->first);         for (auto p = m[i->first].begin(); p != m[i->first].end(); p++) {           auto j = *p;           for (int u = 0; u < 3; u++) {             if (s[j[u]] == 2) a = j[u];             if (s[j[u]] == 3) b = j[u];           }         }         ans.push_back(a);         ans.push_back(b);         break;       }     }     while (ans.size() < n) {       int x, y, z, t;       t = ans.size();       x = ans[t - 1];       y = ans[t - 2];       z = ans[t - 3];       for (auto p = m[y].begin(); p != m[y].end(); p++) {         auto j = *p;         if (((j[0] == y && j[1] == x) || (j[0] == x && j[1] == y)) && j[2] != z)           ans.push_back(j[2]);         else if (((j[0] == y && j[2] == x) || (j[0] == x && j[2] == y)) &&                  j[1] != z)           ans.push_back(j[1]);         else if (((j[1] == y && j[2] == x) || (j[1] == x && j[2] == y)) &&                  j[0] != z)           ans.push_back(j[0]);       }     }     for (auto c : ans) {       cout << c <<    ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 5;   char s[maxn], t[maxn];   int p[maxn], q[maxn], r[maxn];   int main() {     int n, m, k, d;     scanf( %s%d , s, &m);     n = strlen(s);     while (m--) {       scanf( %d%d , &k, &d);       for (int i = 0; i < n; i++) p[i] = q[i] = i;       int id = 0;       for (int i = 0; i < d; i++) {         for (int j = i; j < k; j += d) p[id++] = j;       }       int last = p[0];       for (int i = 0; i < n - 1; i++) p[i] = p[i + 1];       p[n - 1] = last;       int pw = n - k + 1;       while (pw > 0) {         if (pw & 1) {           for (int i = 0; i < n; i++) r[i] = q[p[i]];           for (int i = 0; i < n; i++) q[i] = r[i];         }         for (int i = 0; i < n; i++) r[i] = p[p[i]];         for (int i = 0; i < n; i++) p[i] = r[i];         pw >>= 1;       }       for (int i = 0; i < n; i++) t[i] = s[q[(k + i - 1) % n]];       for (int i = 0; i < n; i++) s[i] = t[i];       puts(s);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool comp(int& a, int& b) { return b < a; }   int main() {     int n;     cin >> n;     vector<pair<int, int>> source(n), team1, team2;     long long sum_team1 = 0, sum_team2 = 0;     for (int i = 0; i < n; ++i) {       cin >> source[i].first;       source[i].second = i;     }     sort(source.begin(), source.end());     int i = 0, par = 1;     while (!source.empty()) {       if (par) {         team1.push_back(source.back());         source.pop_back();         par = 0;         sum_team1 += team1.back().first;       } else {         team2.push_back(source.back());         source.pop_back();         par = 1;         sum_team2 += team2.back().first;       }     }     cout << team1.size() <<   n ;     for (int i = 0; i < team1.size(); ++i) cout << team1[i].second + 1 <<    ;     cout <<   n ;     cout << team2.size() <<   n ;     for (int i = 0; i < team2.size(); ++i) cout << team2[i].second + 1 <<    ;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize(2)   using namespace std;   const long long INF = 1e18;   const int maxn = 1e6 + 6;   const int mod = 1e9 + 7;   const double eps = 1e-9;   inline bool read(long long &num) {     char in;     bool IsN = false;     in = getchar();     if (in == EOF) return false;     while (in !=  -  && (in <  0  || in >  9 )) in = getchar();     if (in ==  - ) {       IsN = true;       num = 0;     } else       num = in -  0 ;     while (in = getchar(), in >=  0  && in <=  9 ) {       num *= 10, num += in -  0 ;     }     if (IsN) num = -num;     return true;   }   long long n, m;   struct node {     int x, v;     bool friend operator<(node a, node b) { return a.x < b.x; }   } save[maxn];   vector<int> v;   long long a[maxn], b[maxn];   int nn;   void update(long long *p, int pos, long long x) {     while (pos <= nn) {       p[pos] += x;       pos += pos & -pos;     }   }   long long GetSum(long long *p, long long x) {     long long ans = 0;     while (x > 0) {       ans += p[x];       x -= x & -x;     }     return ans;   }   int getid(long long x) {     return lower_bound(v.begin(), v.end(), x) - v.begin() + 1;   }   int main() {     read(n);     for (int i = 1; i <= n; i++) scanf( %d , &save[i].x);     for (int i = 1; i <= n; i++) {       scanf( %d , &save[i].v);       v.push_back(save[i].v);     }     sort(v.begin(), v.end());     v.erase(unique(v.begin(), v.end()), v.end());     nn = v.size();     sort(save + 1, save + 1 + n);     long long ans = 0;     for (int i = 1; i <= n; i++) {       int id = getid(save[i].v);       long long tempx = GetSum(b, id);       long long tempy = GetSum(a, id);       ans += tempx * save[i].x - tempy;       update(b, id, 1);       update(a, id, save[i].x);     }     printf( %lld n , ans);     return 0;   }


#include<bits/stdc++.h> /*   #include <ext/pb_ds/assoc_container.hpp> // Common file   #include <ext/pb_ds/tree_policy.hpp> // Including */   using namespace std;   //using namespace __gnu_pbds;      //typedefs      typedef long long ll;   typedef vector<int> vi;   typedef vector<ll> vl;   typedef vector<vi> vvi;   typedef vector<vl> vvl;   typedef pair<int,int> pii;   typedef pair<double, double> pdd;   typedef pair<ll, ll> pll;   typedef vector<pii> vii;   typedef vector<pll> vll;   typedef vector<int>::iterator vit;   typedef set<int>::iterator sit;      /*   template<typename T>   using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;   template<typename F, typename S>   using ordered_map = tree<F, S, less<F>, rb_tree_tag, tree_order_statistics_node_update>;   */      //#Defines   #define rep(i,a,b) for(i=a;i<=b;i++)   #define repR(i,a,b) for(i=a;i>=b;i--)   //#define pb push_back   #define pb emplace_back   #define F first   #define S second   #define mp make_pair   #define all(c)  c.begin(),c.end()   #define endl   n    #define pf printf   #define sf scanf   //#define left __left   //#define right __right   //#define tree __tree   #define MOD 1000000007   //#define harmonic(n) 0.57721566490153286l+log(n)      #define RESET(a,b) memset(a,b,sizeof(a))   #define gcd(a,b) __gcd(a,b)   #define lcm(a,b) (a*(b/gcd(a,b)))   #define sqr(a) ((a) * (a))      #define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);   #define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);      const double PI = acos(-1);   const double eps = 1e-9;   const int inf = 2000000000;   const ll infLL = 9000000000000000000;         //Bit Operations   inline bool checkBit(ll n, int i) { return n&(1LL<<i); }   inline ll setBit(ll n, int i) { return n|(1LL<<i);; }   inline ll resetBit(ll n, int i) { return n&(~(1LL<<i)); }      int fx[] = {0, 0, +1, -1};   int fy[] = {+1, -1, 0, 0};   //int dx[] = {+1, 0, -1, 0, +1, +1, -1, -1};   //int dy[] = {0, +1, 0, -1, +1, -1, +1, -1};         //Inline functions      inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }   inline bool isLeapYear(ll year) { return (year%400==0) || (year%4==0 && year%100!=0); }   inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }   inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }   inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }   inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }   inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }   inline ll modInverse(ll a) { return modPow(a, MOD-2); }   inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }   inline bool isInside(pii p,ll n,ll m) { return (p.first>=0&&p.first<n&&p.second>=0&&p.second<m); }   inline bool isInside(pii p,ll n)  { return (p.first>=0&&p.first<n&&p.second>=0&&p.second<n); }   inline bool isSquare(ll x)     { ll s = sqrt(x); return (s*s==x); }   inline bool isFib(ll x)     { return isSquare(5*x*x+4)|| isSquare(5*x*x-4); }   inline bool isPowerOfTwo(ll x)   { return ((1LL<<(ll)log2(x))==x); }         struct func   {    //this is a sample overloading function for sorting stl    bool operator()(pii const &a, pii const &b)     {     if(a.F==b.F)      return (a.S<b.S);     return (a.F<b.F);    }   };      //Prime Number Generator      /*   #define M 100000000   int marked[M/64 + 2];      #define on(x) (marked[x/64] & (1<<((x%64)/2)))   #define mark(x)  marked[x/64] |= (1<<((x%64)/2))      vl prime;      bool isPrime(int num) {     return num > 1 && (num == 2 || ((num & 1) && !on(num)));    }      void sieve(ll n) {    for (ll i = 3; i * i < n; i += 2) {     if (!on(i)) {      for (ll j = i * i; j <= n; j += i + i) {       mark(j);      }     }    }    prime.pb(2);    for(ll i = 3; i <= n; i += 2) {     if(!on(i)) prime.pb(i);     }   }      */      //   //debug   #ifdef tajir   template < typename F, typename S >   ostream& operator << ( ostream& os, const pair< F, S > & p ) {    return os <<  (  << p.first <<  ,   << p.second <<  ) ;   }      template < typename T >   ostream &operator << ( ostream & os, const vector< T > &v ) {    os <<  { ;    for(auto it = v.begin(); it != v.end(); ++it) {     if( it != v.begin() ) os <<  ,  ;      os << *it;    }    return os <<  } ;   }      template < typename T >   ostream &operator << ( ostream & os, const set< T > &v ) {    os <<  [ ;    for(auto it = v.begin(); it != v.end(); ++it) {     if( it != v.begin() ) os <<  ,  ;      os << *it;    }    return os <<  ] ;   }      template < typename T >   ostream &operator << ( ostream & os, const multiset< T > &v ) {    os <<  [ ;    for(auto it = v.begin(); it != v.end(); ++it) {     if( it != v.begin() ) os <<  ,  ;     os << *it;    }    return os <<  ] ;   }      template < typename F, typename S >   ostream &operator << ( ostream & os, const map< F, S > &v ) {    os <<  [ ;    for(auto it = v.begin(); it != v.end(); ++it) {     if( it != v.begin() ) os <<  ,  ;     os << it -> first <<   =   << it -> second ;     }    return os <<  ] ;   }      #define dbg(args...) do {cerr << #args <<   :  ; faltu(args); } while(0)      clock_t tStart = clock();   #define timeStamp dbg( Execution Time:  , (double)(clock() - tStart)/CLOCKS_PER_SEC)      void faltu () {    cerr << endl;   }      template <typename T>   void faltu( T a[], int n ) {    for(int i = 0; i < n; ++i) cerr << a[i] <<    ;    cerr << endl;   }      template <typename T, typename ... hello>   void faltu( T arg, const hello &... rest) {    cerr << arg <<    ;    faltu(rest...);   }   #else   #define dbg(args...)   #endif // tajir      ll n,m,k,x,y;      ll get() {    ll cnt = 0;    cnt += (m-2) + 1ll + (m-2) + 1ll;    return cnt;   }      int main()   {    #ifdef tajir    // freopen( input.txt ,  r , stdin);    #else     // online submission    #endif    optimize();    bool down, right, up, left;    ll mi;    bool pre = true;    down = right = up = left = false;    cin >> n >> m >> k;    x = 1 , y = 1;    down = true;    ll cnt = get();    k = k%(n*m);   // cout << cnt << endl;   // cout << k << endl;    if(down) {     mi = min(k,(n-x));     k -= mi;     x += mi;     down = !down;     right = !right;    }    if(right) {     mi = min(k,(m-y));     k -= mi;     y += mi;     right = !right;     up = !up;    }   // cout << x <<     << y << endl;    x -= 2*(k/cnt);    k = k%cnt;   // cout << x <<     << y << endl;    up = true;    down = right = left = false;    while(k > 0) {     if(down) {      mi = min(k,(n-x));      k -= mi;      x += mi;      down = !down;      right = !right;     }     else if(right) {      mi = min(k,(m-y));      k -= mi;      y += mi;      right = !right;      up = !up;     }     else if(up) {      mi = min(k,1ll);      k -= mi;      x -= mi;      up = !up;      if(pre) {       left = !left;       pre = !pre;      }      else {       right = !right;       pre = !pre;      }        }     else {      mi = min((y-2), k);      k -= mi;      y -= mi;      if(x == 1) {       mi = min(k,1ll);       k -= mi;       y -= mi;       left = !left;       down = !down;      }      else {       left = !left;       up = !up;      }     }    // cout << x <<     << y <<     << k <<  endl;    }     cout << x <<     << y << endl;    return 0;   }                     //?


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const long long LINF = 0x3f3f3f3f3f3f3f3f;   long long tot[200010];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     vector<pair<long long, int> > v;     for (int i = 0; i < n; i++) {       long long l, r;       cin >> l >> r;       v.push_back({l, -1});       v.push_back({r + 1, 1});     }     sort(v.begin(), v.end());     long long open = 0;     long long last = v[0].first;     for (int i = 0; i < v.size();) {       long long pos = v[i].first;       tot[open] += pos - last;       while (i < v.size() && v[i].first == pos) {         open -= v[i].second;         i++;       }       last = pos;     }     for (int i = 1; i <= n; i++) cout << tot[i] <<    ;     cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long fa[2005], fb[2005];   long long mina[2005], minb[2005];   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n, m;     cin >> n >> m;     vector<long long> a(n), b(m);     for (int i = 0; i < n; i++) {       cin >> a[i];       fa[i + 1] = fa[i] + a[i];     }     for (int j = 0; j < m; j++) {       cin >> b[j];       fb[j + 1] = fb[j] + b[j];     }     long long x;     cin >> x;     for (int i = 0; i <= n; i++) {       mina[i] = 2000000000;       for (int k = 0; k + i <= n; k++) {         mina[i] = min(mina[i], fa[k + i] - fa[k]);       }     }     for (int j = 0; j <= m; j++) {       minb[j] = 2000000000;       for (int k = 0; k + j <= m; k++) {         minb[j] = min(minb[j], fb[k + j] - fb[k]);       }     }     long long ans = 0;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         if (mina[i] * minb[j] <= x) ans = max(ans, i * 1ll * j);       }     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, mx = 0;     cin >> n;     map<int, long long int> mp1, mp2;     map<pair<long long int, long long int>, int> mp;     vector<long long int> a(n), b(n);     for (int i = 0; i < n; i++) {       int x, y;       cin >> x >> y;       a[i] = x, b[i] = y;       mp1[x]++, mp2[y]++;       mp[{a[i], b[i]}]++;       mx = max(mx, mp2[y]);     }     long long int operations = INT_MAX;     for (int i = 0; i < n; i++) {       long long int temp = mp1[a[i]] + mp2[a[i]] - mp[{a[i], a[i]}];       if (temp >= (n + 1) / 2) {         operations =             min(operations, max(min(temp, (n + 1) / 2) - mp1[a[i]], 0LL));       }     }     if (operations == INT_MAX && mx < (n + 1) / 2) {       cout <<  -1 n ;       return 0;     }     if (operations == INT_MAX) {       operations = (n + 1) / 2;     }     cout << operations << endl;   }


#include <bits/stdc++.h>   using namespace std;   char ans[2000005];   vector<int> lis[2000005];   string Str[2000005];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     int m = 0;     for (int i = 0; i < n; i++) {       string str;       cin >> str;       Str[i] = str;       int k;       cin >> k;       while (k--) {         int a;         cin >> a;         lis[a].push_back(i);         m = max(m, int(a + str.length() - 1));       }     }     int r = -1, p = 0, ind = 0;     for (int i = 1; i <= m; i++) {       for (int j = 0; j < lis[i].size(); j++) {         int a = Str[lis[i][j]].size();         int b = r - p;         if (a > b) {           r = Str[lis[i][j]].length();           p = 0;           ind = lis[i][j];         }       }       if (p < r) {         ans[i] = Str[ind][p];         p++;       } else {         ans[i] =  a ;       }       cout << ans[i];     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 32;   int n, u, r, a[N][N], b[N], p[N], k[N];   long long ans = -1e18;   void dfs(int x, bool z) {     int i;     if (x % 2 == u % 2) {       long long t = 0;       for (i = 1; i <= n; i = i + 1) t += (long long)a[i][x] * k[i];       ans = max(ans, t);     }     if (x >= u) return;     for (i = 1; i <= n; i = i + 1) a[i][x + 1] = a[p[i]][x] + r;     dfs(x + 1, 1);     if (z) {       for (i = 1; i <= n; i = i + 1) a[i][x + 1] = a[i][x] ^ b[i];       dfs(x + 1, 0);     }   }   int main() {     int i, j;     cin >> n >> u >> r;     for (i = 1; i <= n; i = i + 1) cin >> a[i][0];     for (i = 1; i <= n; i = i + 1) cin >> b[i];     for (i = 1; i <= n; i = i + 1) cin >> k[i];     for (i = 1; i <= n; i = i + 1) cin >> p[i];     dfs(0, 1);     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   map<char, long long> mp;   long long arr[2][1234];   int main() {     string s;     long long idx1, idx2;     char repeating;     cin >> s;     long long i;     for (i = 0; i < s.size(); i++) mp[s[i]]++;     for (auto it : mp)       if (it.second == 2) repeating = it.first;     0;     long long c1 = 0, c2 = 0, c3 = 0, nc1, nc3;     for (i = 0; i < s.size(); i++)       if (s[i] == repeating) {         idx1 = idx2;         idx2 = i;       }     if (idx2 == idx1 + 1) {       cout <<  Impossible ;       return 0;     }     0;     c2 = idx2 - idx1 - 1;     c3 = 26 - idx2;     c1 = idx1;     0;     0;     if (c2 % 2 == 0) {       long long sum = c1 + c3;       nc3 = sum / 2;       nc1 = nc3 + 1;       if (nc1 < c1) {         long long give = c1 - nc1;         string tmp = s.substr(0, give);         s = s.substr(give, 27 - tmp.size());         s += tmp;         0;       } else if (nc1 > c1) {         long long give = nc1 - c1;         string tmp = s.substr(27 - give, give);         s = tmp + s.substr(0, 27 - give);         0;       }     } else if (c2 % 2 == 1) {       long long sum = c1 + c3;       nc3 = sum / 2;       nc1 = nc3;       if (nc1 < c1) {         long long give = c1 - nc1;         string tmp = s.substr(0, give);         s = s.substr(give, 27 - tmp.size());         s += tmp;         0;       } else if (nc1 > c1) {         long long give = nc1 - c1;         string tmp = s.substr(27 - give, give);         s = tmp + s.substr(0, 27 - give);         0;       }     }     0;     for (i = 0; i < s.size(); i++)       if (s[i] == repeating) {         idx1 = idx2;         idx2 = i;       }     long long curr = 0;     if (c2 % 2 == 0) {       for (i = 0; i < idx1; i++) arr[1][curr++] = s[i] -  A ;       curr--;       0;       arr[0][curr] = repeating -  A ;       curr++;       for (i = idx1 + 1; i <= (idx1 + c2 / 2); i++) arr[0][curr++] = s[i] -  A ;       0;       curr--;       for (i = idx1 + c2 / 2 + 1; i <= (idx1 + c2); i++)         arr[1][curr--] = s[i] -  A ;       curr--;       for (i = idx2 + 1; i < 27; i++) arr[0][curr--] = s[i] -  A ;       for (i = 0; i < 2; i++) {         for (long long j = 0; j < 13; j++) {           cout << char(arr[i][j] +  A );         }         cout << endl;       }     } else {       for (i = 0; i < idx1; i++) arr[1][curr++] = s[i] -  A ;       0;       arr[1][curr] = repeating -  A ;       for (i = idx1 + 1; i <= ((idx1 + c2 / 2) + 1); i++)         arr[0][curr++] = s[i] -  A ;       0;       curr--;       for (i = idx1 + c2 / 2 + 2; i <= (idx1 + c2); i++)         arr[1][curr--] = s[i] -  A ;       curr--;       for (i = idx2 + 1; i < 27; i++) arr[0][curr--] = s[i] -  A ;       for (i = 0; i < 2; i++) {         for (long long j = 0; j < 13; j++) {           cout << char(arr[i][j] +  A );         }         cout << endl;       }     }   }


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


#include<bits/stdc++.h>   using namespace std;   typedef long long ll;   int n,m,pre,N;   string s,t;   ll ans;   map<string,vector<string> >S;   map<string,bool>vis;   int main(){    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);    cin>>n;    for(int i=1;i<=n;i++){     cin>>s;t=s;     sort(t.begin(),t.end());     S[t].push_back(s);    }    m=s.size();    for(auto it:S){     vector<string> v=it.second;     N=v.size(),ans+=1337ll*pre*N,pre+=N;     if(N<=200*m){      for(int i=0;i<N;i++)for(int j=i+1;j<N;j++){       int L=0,R=m-1;       while(v[i][L]==v[j][L]&&L<=R)L++;       while(v[i][R]==v[j][R]&&L<=R)R--;       bool f1=1,f2=1;       for(int k=L;k<R;k++)f1&=(v[i][k]<=v[i][k+1]),f2&=(v[j][k]<=v[j][k+1]);       ans+=2;       if(f1||f2)ans--;      }     }else{      ll cur=(ll)N*(N-1);      vis.clear();      for(auto s:v)vis[s]=1;      for(auto s:v)for(int i=0;i<m;i++)for(int j=i+2;j<=m;j++){       t=s,sort(t.begin()+i,t.begin()+j);       if(t[i]!=s[i]&&t[j-1]!=s[j-1]&&vis.count(t))cur--;      }      ans+=cur;     }    }    cout<<ans;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 7;   long long a[maxn];   int main() {     int _;     cin >> _;     while (_--) {       int n, k;       cin >> n >> k;       for (int i = 1; i <= n; i++) cin >> a[i];       sort(a + 1, a + 1 + n, greater<int>());       long long ans = 0;       for (int i = 1; i <= k; i++) ans += a[k + i] / a[i];       for (int i = 2 * k + 1; i <= n; i++) ans += a[i];       cout << ans <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int n, arr[111111];   int main() {     cin >> n;     arr[0] = 0x3f3f3f3f;     for (int i = 1; i <= n; ++i) cin >> arr[i];     int ans = 0;     for (int i = 0; i < n; ++i) {       int ii = n - i;       if (arr[ii] < arr[ii - 1]) {         ans = i;         break;       }     }     ans = n - ans - 1;     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, counter = 0, max = 1, a, b = -1;     cin >> n;     for (int i = 0; i < n; i++) {       a = b;       cin >> b;       if (b >= a) {         counter++;       } else {         if (counter > max) {           max = counter;         }         counter = 1;       }       if (counter > max) {         max = counter;       }     }     cout << max << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct fenwick_tree_1D {     long long n, log_n;     vector<long long> tree;     fenwick_tree_1D(long long _n)         : n(_n), log_n((long long)(log2(_n) + 1.0L)), tree(_n + 5) {}     void update(long long x, long long v) {       while (x <= n) {         tree[x] += v;         x += x & (-x);       }     }     long long prefix_sum(long long x) {       long long r = 0;       while (x) {         r += tree[x];         x -= x & (-x);       }       return r;     }     long long range_sum(long long l, long long r) {       return prefix_sum(r) - prefix_sum(l - 1);     }   };   const long long bs = 300;   fenwick_tree_1D bit(100005);   long long a[100005], nxt[100005], last[100005] = {0}, dl[2 * bs + 5],                                     id[100005], dc = 0, result[100005] = {0};   set<long long> s[100005];   long long qc;   struct query {     long long t, l, r, qno;   } q[bs + 5];   long long q2c;   struct query2 {     long long l, r, qno;   } q2[bs + 5];   vector<long long> ans;   int32_t main() {     ios::sync_with_stdio(false);     cin.tie(0);     long long n, m;     cin >> n >> m;     for (long long i = 1; i <= n; i++) {       cin >> a[i];       s[a[i]].insert(i);     }     for (long long h = 0; h < m; h += bs) {       qc = min(bs, m - h);       for (long long j = 0; j < qc; j++) {         cin >> q[j].t >> q[j].l >> q[j].r;         q[j].qno = h + j;         if (q[j].t == 1) {           if (!id[a[q[j].l]]) dl[dc] = a[q[j].l], id[a[q[j].l]] = 1, dc++;           if (!id[q[j].r]) dl[dc] = q[j].r, id[q[j].r] = 1, dc++;         } else           q2[q2c].l = q[j].l, q2[q2c].r = q[j].r, q2[q2c].qno = q[j].qno,           ans.push_back(q[j].qno), q2c++;       }       for (long long i = n; i >= 1; i--) {         if (id[a[i]]) {           nxt[i] = 0;           continue;         }         nxt[i] = last[a[i]];         if (nxt[i]) bit.update(nxt[i], nxt[i] - i);         last[a[i]] = i;       }       sort(q2, q2 + q2c,            [](const query2 &l, const query2 &r) { return l.l < r.l; });       long long pos = 1;       for (long long i = 0; i < q2c; i++) {         while (pos < q2[i].l) {           if (id[a[pos]] || !nxt[pos]) {             pos++;             continue;           }           bit.update(nxt[pos], pos - nxt[pos]);           pos++;         }         result[q2[i].qno] = bit.prefix_sum(q2[i].r);       }       for (long long i = 0; i < qc; i++) {         if (q[i].t == 1) {           s[a[q[i].l]].erase(q[i].l);           a[q[i].l] = q[i].r;           s[a[q[i].l]].insert(q[i].l);         } else {           for (long long j = 0; j < dc; j++) {             auto it1 = s[dl[j]].lower_bound(q[i].l);             auto it2 = s[dl[j]].upper_bound(q[i].r);             if (it1 != s[dl[j]].end() && it2 != s[dl[j]].begin()) {               it2--;               if (*it2 > *it1) result[q[i].qno] += *it2 - *it1;             }           }         }       }       for (long long i = 0; i < dc; i++) id[dl[i]] = 0;       dc = 0;       q2c = 0;       for (long long i = 1; i <= n; i++) bit.tree[i] = 0, last[i] = 0;     }     for (auto &k : ans) cout << result[k] <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   int main() {     int n;     cin >> n;     int k;     cin >> k;     vector<int> v(n);     for (int i = 0; i < n; i++) cin >> v[i];     int lift;     cin >> lift;     vector<int> c(n);     for (int i = 0; i < n; i++) cin >> c[i];     set<int> second;     ll ans = 0;     int joker;     for (int i = 0; i < n; i++) {       second.insert(c[i]);       if (v[i] <= k)         continue;       else {         joker = (v[i] - k) / lift;         if ((v[i] - k) % lift != 0) joker++;         if (joker > second.size()) {           ans = -1;           break;         }         k += (joker * lift);         int mini;         while (joker--) {           mini = *min_element(second.begin(), second.end());           ans += mini;           second.erase(mini);         }       }     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100004;   int n, m, c = 0;   char s[24][24];   set<unsigned long long> st, ns;   bool fun(int x, int y) {     st.clear();     for (int i = 0; i < n; i += x)       for (int j = 0; j < m; j += y) {         ns.clear();         unsigned long long sum = 0;         for (int u = 0; u < x; u++) {           unsigned long long p = 0;           for (int v = 0; v < y; v++) p = p * 131 + s[i + u][j + v];           sum = sum * 997 + p;         }         ns.insert(sum);         sum = 0;         for (int u = x - 1; u >= 0; u--) {           unsigned long long p = 0;           for (int v = y - 1; v >= 0; v--) p = p * 131 + s[i + u][j + v];           sum = sum * 997 + p;         }         ns.insert(sum);         if (x == y) {           sum = 0;           for (int v = y - 1; v >= 0; v--) {             unsigned long long p = 0;             for (int u = 0; u < x; u++) p = p * 131 + s[i + u][j + v];             sum = sum * 997 + p;           }           ns.insert(sum);           sum = 0;           for (int v = 0; v < y; v++) {             unsigned long long p = 0;             for (int u = x - 1; u >= 0; u--) p = p * 131 + s[i + u][j + v];             sum = sum * 997 + p;           }           ns.insert(sum);         }         for (auto it = ns.begin(); it != ns.end(); it++) {           if (st.count(*it)) return 0;           st.insert(*it);         }       }     return 1;   }   int main() {     scanf( %d %d , &n, &m);     for (int i = 0; i < n; i++) scanf( %s , s[i]);     int x = 100, y = 100, ans = 40000;     for (int i = 1; i <= n; i++)       if (n % i == 0)         for (int j = 1; j <= m; j++)           if (m % j == 0) {             if (fun(i, j)) {               ++c;               if (i * j < ans || i * j == ans && i < x) {                 ans = i * j;                 x = i;                 y = j;               }             }           }     printf( %d n%d %d n , c, x, y);   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 9223372036854775807;   const long long MOD = 1000000007;   const long long FMOD = 998244353;   const long long MAXN = 1e5 + 5;   const long double eps = 1e-9;   const long double PI = acos(-1);   void __print(int x) { cerr << x; }   void __print(long x) { cerr << x; }   void __print(long long x) { cerr << x; }   void __print(unsigned x) { cerr << x; }   void __print(unsigned long x) { cerr << x; }   void __print(unsigned long long x) { cerr << x; }   void __print(float x) { cerr << x; }   void __print(double x) { cerr << x; }   void __print(long double x) { cerr << x; }   void __print(char x) { cerr <<      << x <<     ; }   void __print(const char *x) { cerr <<     << x <<    ; }   void __print(const string &x) { cerr <<     << x <<    ; }   void __print(bool x) { cerr << (x ?  true  :  false ); }   template <typename T, typename V>   void __print(const pair<T, V> &x) {     cerr <<  { ;     __print(x.first);     cerr <<  , ;     __print(x.second);     cerr <<  } ;   }   template <typename T>   void __print(const T &x) {     int f = 0;     cerr <<  { ;     for (auto &i : x) cerr << (f++ ?  ,  :   ), __print(i);     cerr <<  } ;   }   void _print() { cerr <<  ] n ; }   template <typename T, typename... V>   void _print(T t, V... v) {     __print(t);     if (sizeof...(v)) cerr <<  ,  ;     _print(v...);   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n, m;     cin >> n >> m;     vector<pair<int, int>> a(n);     vector<pair<char, int>> arr;     int cnt = 0;     for (long long i = 0; i < n; i++) {       char c;       cin >> c;       int ind;       cin >> ind;       ind--;       if (c ==  + ) {         a[ind].first++;       } else {         a[ind].second++;         cnt++;       }       arr.push_back({c, ind});     }     bool ok = true;     map<int, int> chorhaibc;     for (long long i = 0; i < n; i++) {       if (cnt - a[i].second + a[i].first == m) {         chorhaibc[i] = 1;       }     }     if (chorhaibc.size() == 1) {       int killer = chorhaibc.begin()->first;       for (long long i = 0; i < n; i++) {         if (arr[i].first ==  + ) {           if (arr[i].second == killer)             cout <<  Truth ;           else             cout <<  Lie ;         }         if (arr[i].first ==  - ) {           if (arr[i].second == killer)             cout <<  Lie ;           else             cout <<  Truth ;         }         cout << endl;       }     } else {       for (long long i = 0; i < n; i++) {         if (arr[i].first ==  +  && chorhaibc[arr[i].second] == 0) {           cout <<  Lie ;         } else {           if (arr[i].first ==  -  && chorhaibc[arr[i].second] == 0) {             cout <<  Truth ;           } else {             cout <<  Not defined ;           }         }         cout << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long ex_gcd(long long a, long long b, long long &x, long long &y) {     int d = a;     if (b == 0) {       x = 1;       y = 0;     } else {       d = ex_gcd(b, a % b, y, x);       y -= a / b * x;     }     return d;   }   int main() {     long long a, b, c;     long long x, y;     cin >> a >> b >> c;     int gcd = ex_gcd(a, b, x, y);     if (-c % gcd)       cout << -1;     else {       long long k = (-c) / gcd;       cout << k * x <<     << k * y;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   #pragma GCC optimize( O3 )   bool a[2000][2000], use[2000][2000][6][6];   vector<pair<int, int> > go;   void dfs(int x, int y, int way, int cnt) {     if (cnt == 3) return;     use[x][y][way][cnt] = 1;     for (int i = 1; i <= 4; i++)       if (i == way) {         if (a[x + go[i - 1].first][y + go[i - 1].second] &&             !use[x + go[i - 1].first][y + go[i - 1].second][i][cnt])           dfs(x + go[i - 1].first, y + go[i - 1].second, i, cnt);       } else if (abs(i - way) != 2) {         if (a[x + go[i - 1].first][y + go[i - 1].second] &&             !use[x + go[i - 1].first][y + go[i - 1].second][i][cnt + 1])           dfs(x + go[i - 1].first, y + go[i - 1].second, i, cnt + 1);       }   }   signed main() {     int n = 0, m = 0;     cin >> n >> m;     int si = 0, sj = 0, fi = 0, fj = 0;     for (int i = 1; i <= n; i++) {       string st =   ;       cin >> st;       for (int j = 1; j <= m; j++)         if (st[j - 1] !=  * ) a[i][j] = 1;       for (int j = 1; j <= m; j++)         if (st[j - 1] ==  S ) {           si = i;           sj = j;         } else if (st[j - 1] ==  T ) {           fi = i;           fj = j;         }     }     go.push_back({1, 0});     go.push_back({0, 1});     go.push_back({-1, 0});     go.push_back({0, -1});     dfs(si, sj, 1, 0);     dfs(si, sj, 2, 0);     dfs(si, sj, 3, 0);     dfs(si, sj, 4, 0);     for (int way = 1; way <= 4; way++)       for (int cnt = 0; cnt <= 2; cnt++)         if (use[fi][fj][way][cnt]) {           cout <<  YES ;           return (0);         }     cout <<  NO ;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 5e5 + 50, inf = 1e9;   int n, m, be[N], f[N], cnt, sub[N], SUB[N], vfa[N], q[N * 2], l, r;   bool vis[N], tp[N];   vector<int> e[N], v[N], vv;   void cmax(int &x, int y) { y > x ? x = y : 0; }   void dfs1(int x) {     vis[x] = 1;     if (f[x]) e[x].erase(find(e[x].begin(), e[x].end(), f[x]));     for (int i = 0, y; i < e[x].size(); i++) {       if (!vis[y = e[x][i]])         f[y] = x, dfs1(y);       else if (!be[y]) {         be[y] = ++cnt;         tp[y] = 1;         v[cnt].push_back(y);         for (int z = x; z != y; z = f[z]) be[z] = cnt, v[cnt].push_back(z);       }     }     if (!be[x]) be[x] = ++cnt, tp[x] = 1, v[cnt].push_back(x);   }   void calc1(int x) {     int id = be[x], sz = v[id].size();     for (int i = 0; i < sz; i++) {       int mx0 = 0, mx1 = -inf;       int z = v[id][i];       for (int j = 0, y; j < e[z].size(); j++)         if (be[y = e[z][j]] != id) {           int val = SUB[y] + 1;           if (val > mx0)             mx1 = mx0, mx0 = val;           else if (val > mx1)             mx1 = val;         }       sub[z] = mx0;       cmax(SUB[x], mx0 + min(i, sz - i));       for (int j = 0, y; j < e[z].size(); j++)         if (be[y = e[z][j]] != id)           cmax(vfa[y], SUB[y] + 1 != mx0 ? mx0 + 1 : mx1 + 1);     }   }   void dfs2(int x) {     vis[x] = 1;     for (int i = 0, y; i < e[x].size(); i++)       if (!vis[y = e[x][i]]) dfs2(y);     if (tp[x]) calc1(x);   }   void calc2(int x) {     cmax(sub[x], vfa[x]);     vv.clear();     int id = be[x], sz = v[id].size();     for (int i = 0; i < 2; i++)       for (int j = 0; j < v[id].size(); j++) vv.push_back(v[id][j]);     l = 1;     r = 0;     for (int i = 0; i < vv.size(); i++) {       if (i - q[l] > sz / 2) l++;       if (l <= r) cmax(vfa[vv[i]], i - q[l] + sub[vv[q[l]]]);       while (l <= r && sub[vv[q[r]]] - q[r] < sub[vv[i]] - i) r--;       q[++r] = i;     }     l = 1;     r = 0;     for (int i = vv.size() - 1; ~i; i--) {       if (q[l] - i > sz / 2) l++;       if (l <= r) cmax(vfa[vv[i]], q[l] - i + sub[vv[q[l]]]);       while (l <= r && sub[vv[q[r]]] + q[r] < sub[vv[i]] + i) r--;       q[++r] = i;     }     for (int i = 0; i < v[id].size(); i++)       for (int z = v[id][i], j = 0, y; j < e[z].size(); j++)         if (be[y = e[z][j]] != id) cmax(vfa[y], vfa[z] + 1);   }   void dfs3(int x) {     vis[x] = 1;     if (tp[x]) calc2(x);     for (int i = 0, y; i < e[x].size(); i++)       if (!vis[y = e[x][i]]) dfs3(y);   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1, x, y; i <= m; i++)       scanf( %d%d , &x, &y), e[x].push_back(y), e[y].push_back(x);     dfs1(1);     memset(vis, 0, sizeof(vis));     dfs2(1);     memset(vis, 0, sizeof(vis));     dfs3(1);     for (int i = 1; i <= n; i++) printf( %d  , max(sub[i], vfa[i]));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void out(long long arr[], long long length) {     for (int i = 0; i < length; i++) cout << arr[i] <<    ;   }   int main() {     int tt;     cin >> tt;     while (tt--) {       int x1, y1, z1, x2, y2, z2, ans;       cin >> x1 >> y1 >> z1;       cin >> x2 >> y2 >> z2;       if (y2 >= z1) {         int t1;         ans = (z1 * 2);         int d1 = (y2 - z1);         if ((d1 + x2) >= y1)           cout << ans;         else {           int d2 = y1 - (d1 + x2);           t1 = (min(d2, z2) * 2);           ans = ans - t1;           cout << ans;         }       } else if (y2 < z1) {         int t1;         ans = (y2 * 2);         int d1 = (z1 - y2);         if ((d1 + x1) >= z2)           cout << ans;         else {           int d2 = z2 - (d1 + x1);           t1 = (min(d2, z2) * 2);           ans = ans - t1;           cout << ans;         }       }       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long getint() {     long long _x = 0, _tmp = 1;     char _tc = getchar();     while ((_tc <  0  || _tc >  9 ) && _tc !=  - ) _tc = getchar();     if (_tc ==  - ) _tc = getchar(), _tmp = -1;     while (_tc >=  0  && _tc <=  9 ) _x *= 10, _x += (_tc -  0 ), _tc = getchar();     return _x * _tmp;   }   long long mypow(long long _a, long long _x, long long _mod) {     if (_x == 0) return 1ll;     long long _tmp = mypow(_a, _x / 2, _mod);     _tmp = (_tmp * _tmp) % _mod;     if (_x & 1) _tmp = (_tmp * _a) % _mod;     return _tmp;   }   bool equal(double _x, double _y) { return _x > _y - 1e-7 && _x < _y + 1e-7; }   int __ = 1, cs;   int n, m, deg[100010];   multiset<int> S[100010];   vector<int> odd;   void build() {}   void init() {     n = getint();     m = getint();     while (m--) {       int u, v;       u = getint();       v = getint();       S[u].insert(v);       S[v].insert(u);       deg[u]++;       deg[v]++;     }     for (int i = 1; i <= n; i++)       if (deg[i] % 2) odd.push_back(i);     if ((int)odd.size() % 2) assert(1 == 0);     for (int i = 0, j = (int)odd.size() - 1; i < j; i++, j--) {       S[odd[i]].insert(odd[j]);       S[odd[j]].insert(odd[i]);     }   }   vector<pair<int, int> > ans;   int got;   void DFS(int now) {     while (S[now].size()) {       multiset<int>::iterator it = S[now].begin();       int des = *it;       S[now].erase(S[now].find(des));       S[des].erase(S[des].find(now));       DFS(des);       got++;       if (got % 2)         ans.push_back(make_pair(des, now));       else         ans.push_back(make_pair(now, des));     }   }   void find_circle() {     for (int i = 1; i <= n; i++)       while ((int)S[i].size() > 0) {         got = 0;         DFS(i);         if (got % 2) ans.push_back(make_pair(i, i));       }   }   void solve() {     find_circle();     printf( %d n , (int)ans.size());     for (int i = 0; i < (int)ans.size(); i++)       printf( %d %d n , ans[i].first, ans[i].second);   }   int main() {     build();     while (__--) {       init();       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 10;   const long long MOD = 1e9 + 7;   vector<int> g[N];   bool col[N];   int her[N], p[N];   set<int> s;   queue<int> q;   bool mp[N];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     int n;     cin >> n;     bool bl = false;     for (int i = 0; i < (n); ++i) {       int tv;       cin >> tv;       vector<int> vc;       for (int j = 2; j * j <= tv; j++) {         if (tv % j == 0) {           int qan = 0;           while (tv % j == 0) {             tv /= j;             qan++;           }           if (qan % 2) vc.push_back(j);         }       }       if (tv != 1) vc.push_back(tv);       if (vc.size() == 0) {         cout << 1 << endl;         return 0;       }       if (vc.size() == 1) vc.push_back(1);       int z = vc[0] * vc[1];       if (mp[z]) bl = true;       mp[z] = true;       g[vc[0]].push_back(vc[1]);       g[vc[1]].push_back(vc[0]);       if (vc[0] <= 1000) s.insert(vc[0]);       if (vc[1] <= 1000) s.insert(vc[1]);     }     if (bl) {       cout << 2 << endl;       return 0;     }     int ans = INT_MAX;     for (auto tv : s) {       q.push(tv);       memset(her, 0, sizeof(her));       memset(col, 0, sizeof(col));       memset(p, 0, sizeof(p));       col[tv] = true;       her[tv] = 0;       while (!q.empty()) {         int v = q.front();         q.pop();         for (auto to : g[v]) {           if (col[to]) {             if (to == p[v]) continue;             ans = min(ans, her[to] + her[v] + 1);             continue;           }           q.push(to);           col[to] = true;           her[to] = her[v] + 1;           p[to] = v;         }       }     }     if (ans == INT_MAX)       cout << -1 << endl;     else       cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   bool maximize(T &x, const T &y) {     if (x < y)       x = y;     else       return false;     return true;   }   const int N = 5e5 + 10;   int n, q, md;   int dx[N];   int d[N][21];   int query(int x, int y) {     if (d[x][20] < y) return -1;     int ret = 0;     for (int i = 20; i >= 0; i--)       if (d[x][i] < y) {         x = d[x][i];         ret += 1 << i;       }     return ret + 1;   }   int main() {     if (fopen( exam.inp ,  r ))       freopen( exam.inp ,  r , stdin), freopen( exam.out ,  w , stdout);     scanf( %d%d , &n, &q);     for (int i = 1; i <= n; i++) {       int x, y;       scanf( %d%d , &x, &y);       maximize(dx[x], y);       maximize(md, y);     }     for (int i = 1; i <= md; i++) maximize(dx[i], dx[i - 1]);     for (int i = 0; i <= md; i++) d[i][0] = dx[i];     for (int j = 1; j <= 20; j++)       for (int i = 0; i <= md; i++) d[i][j] = d[d[i][j - 1]][j - 1];     while (q--) {       int x, y;       scanf( %d%d , &x, &y);       printf( %d n , query(x, y));     }   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   const T& max(const T& a, const T& b, const T& c) {     return max(a, max(b, c));   }   template <class T>   const T& min(const T& a, const T& b, const T& c) {     return min(a, min(b, c));   }   long long stoi(string& str) {     istringstream second(str);     long long i;     second >> i;     return i;   }   string itos(long long i) {     stringstream second;     second << i;     return second.str();   }   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); }   long long poww(long long a, long long b) {     if (b == 0) return 1;     long long tmp = poww(a, b / 2);     return (b & 1 ? a * tmp * tmp : tmp * tmp);   }   long long sumOfDigs(string s) {     long long sum = 0;     for (int i = 0; i < s.length(); i++) sum += s[i] -  0 ;     return sum;   }   long long sumOfDigs(long long n) {     return (n < 10 ? n : n % 10 + sumOfDigs(n / 10));   }   long long mod = poww(10, 9) + 7;   int months[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};   using namespace std;   void t() { freopen( test.txt ,  r , stdin); }   long long a[1000 * 100 + 1][20];   pair<long long, long long> aa[1000 * 100 + 1][20];   int main() {     string t1, t2, s, tt, second;     cin >> t1 >> t2;     s += t1;     reverse(t2.begin(), t2.end());     s += t2;     cin >> t1 >> t2;     tt += t1;     reverse(t2.begin(), t2.end());     tt += t2;     second = s;     if (second == tt) {       return cout <<  YES  << endl, 0;     }     int pos = second.find( X );     if (pos < 3) {       swap(second[pos], second[pos + 1]);       pos++;     } else {       swap(second[pos], second[0]);       pos = 0;     }     if (second == tt) {       return cout <<  YES  << endl, 0;     }     while (second != s) {       if (pos < 3) {         swap(second[pos], second[pos + 1]);         pos++;       } else {         swap(second[pos], second[0]);         pos = 0;       }       if (second == tt) {         return cout <<  YES  << endl, 0;       }     }     return cout <<  NO  << endl, 0;     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /stack:200000000 )   #pragma GCC optimize( unroll-loops )   #pragma GCC optimize( O3 )   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long t;     cin >> t;     while (t--) {       long long n, x;       cin >> n >> x;       string s;       cin >> s;       int a[100001] = {0};       int b[100001] = {0};       int f = 0;       for (int i = 0; i < s.length(); i++) {         if (s[i] ==  0 ) {           a[i + 1] = a[i] + 1;           b[i + 1] = b[i];         } else {           a[i + 1] = a[i];           b[i + 1] = b[i] + 1;         }       }       long long ans = 0;       int c0 = 1;       for (int i = 1; i <= n; i++) {         if (a[i] - b[i] == 0) {           c0++;         }         int g = a[i] - b[i];         long double h;         h = (x - g);         h *= 1.0;         if (a[n] - b[n] == 0) {           if (g == x) ans++;           continue;         }         h /= (long double)(a[n] - b[n]);         if (h < 0) continue;         if (ceil(h) == floor(h)) {           ans++;         }       }       if (a[n] - b[n] == 0) {         for (int i = 1; i <= n; i++)           if (a[i] - b[i] == x) {             cout << -1 <<   n ;             f = 1;             break;           }       }       if (x == 0) ans++;       if (f) continue;       cout << ans <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int v[1100][1100];   int main() {     int n, k;     cin >> n >> k;     if (n > k + k) {       cout << n * k << endl;       for (int i = 1; i <= n; i++) {         int t = k;         for (int j = 1; j <= n; j++)           if (i != j && !v[i][j] && !v[j][i] && t) {             t--;             v[i][j] = v[j][i] = 1;             printf( %d %d n , i, j);           }       }     } else       printf( -1 n );   }


#include <bits/stdc++.h>   using namespace std;   long long int mod = 1e18;   long long int mul(long long int a, long long int b) {     return ((a % mod) * (b % mod)) % mod;   }   long long int add(long long int a, long long int b) {     return ((a % mod) + (b % mod)) % mod;   }   long long int sub(long long int a, long long int b) {     return ((a % mod) - (b % mod) + mod) % mod;   }   long long int gcdExtended(long long int a, long long int b, long long int *x,                             long long int *y) {     if (a == 0) {       *x = 0, *y = 1;       return b;     }     long long int x1, y1;     long long int gcd = gcdExtended(b % a, a, &x1, &y1);     *x = y1 - (b / a) * x1;     *y = x1;     return gcd;   }   long long int modInverse(long long int b) {     long long int x, y;     long long int g = gcdExtended(b, mod, &x, &y);     if (g != 1) return -1;     return (x % mod + mod) % mod;   }   long long int modDivide(long long int a, long long int b) {     a = a % mod;     long long int inv = modInverse(b);     if (inv == -1)       return -1;     else       return (inv * a) % mod;   }   long long int expFactor2(long long int n, long long int p) {     long long int exponent = 0;     while (n % p == 0) {       exponent++;       n /= p;     }     return exponent;   }   void sieve(long long int n, vector<bool> &prime, vector<long long int> &p) {     prime[1] = 0;     for (long long int i = 2; i <= n; i++) {       if (prime[i]) {         for (long long int j = i; j <= n; j += i) {           if (j > i) prime[j] = 0;           p[j] += expFactor2(j, i);         }       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int i, t, j, inp, n, a, b;     cin >> t;     vector<long long int> p(5000001, 0);     vector<bool> prime(5000001, 1);     sieve(5000001, prime, p);     for (i = 2; i <= 5000000; i++) {       p[i] += p[i - 1];     }     for (i = 0; i < t; i++) {       cin >> a >> b;       long long int ans = 0;       ans = p[a] - p[b];       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 7;   int n, k, m;   int a[N];   int main() {     scanf( %d%d%d , &n, &m, &k);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     sort(a + 1, a + 1 + n);     long long ans = 0;     ans += 1ll * (m / (k + 1)) * (1ll * k * a[n] + a[n - 1]);     ans += 1ll * (m % (k + 1)) * a[n];     printf( %lld n , ans);   }


#include <bits/stdc++.h>   using namespace std;   int N, K;   int val[10010], nval[10010], pos[10010], buf[10010];   int main() {     scanf( %d%d , &N, &K);     for (int i = 0; i < N - 1; ++i) val[i] = 1;     int br = 0;     for (;;) {       for (int i = 0; i < N; ++i) pos[i] = -1, nval[i] = val[i];       for (int i = N - 1; i >= 0; --i)         if (pos[val[i]] == -1) pos[val[i]] = i;       if (pos[N - 1] != -1) break;       ++br;       for (int i = N - 1; i >= 0; --i) {         int tar = N - 1 - i;         if (val[i] == tar)           buf[i] = N - 1;         else {           if (pos[tar - val[i]] != -1)             buf[i] = pos[tar - val[i]], nval[i] = tar;           else             buf[i] = buf[i + 1], nval[i] += val[buf[i]];         }       }       for (int i = 0; i < N; ++i)         printf( %d%c , buf[i] + 1, (i + 1 == N ?   n  :    ));       for (int i = 0; i < N; ++i) val[i] = nval[i];     }     while (br < K) {       ++br;       for (int i = 0; i < N; ++i) printf( %d%c , N, (i + 1 == N ?   n  :    ));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using LL = long long;   const double PI = 3.14159265358979323846;   const int INF = 0x3f3f3f3f;   const int MOD = 1e9 + 7;   void solve() {     int n;     cin >> n;     vector<int> bit(64);     LL sum = 0, ans = 0;     for (int i = 0; i < int(n); ++i) {       LL num;       cin >> num;       sum += num;       ans ^= num;     }     cout << 2 << endl;     cout << ans <<     << ans + sum << endl;   }   int main() {     int t;     cin >> t;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int const mxsz = 509;   long long w[mxsz][mxsz];   bool ver[mxsz];   int main() {     vector<int> er;     vector<long long> res;     int n;     scanf( %d , &n);     er.resize(n);     for (int i = 0; i < n; ++i) {       int x;       for (int j = 0; j < n; ++j) {         scanf( %d , &x);         w[i][j] = x;       }     }     for (int i = 0; i < n; ++i) scanf( %d , &er[i]);     reverse(er.begin(), er.end());     for (int k = 0; k < n; ++k) {       er[k]--;       ver[er[k]] = 1;       long long R = 0;       for (int i = 0; i < n; ++i)         for (int j = 0; j < n; ++j)           w[i][j] = min(w[i][j], w[i][er[k]] + w[er[k]][j]);       for (int i = 0; i < n; ++i)         for (int j = 0; j < n; ++j)           if (ver[i] && ver[j]) R += w[i][j];       res.push_back(R);     }     for (int i = n - 1; i >= 0; --i) cout << res[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007;   vector<vector<long long>> g;   vector<long long> a;   vector<long long> ans;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long n;     cin >> n;     g = vector<vector<long long>>(n + 1);     a = vector<long long>(n + 1);     ans = vector<long long>(n + 1, LLONG_MAX);     for (int i = 1; i <= n; i++) {       cin >> a[i];       if (i - a[i] >= 1) {         g[i - a[i]].push_back(i);       }       if (i + a[i] <= n) {         g[i + a[i]].push_back(i);       }     }     set<long long> toUp;     for (int i = 1; i <= n; i++) {       for (auto x : g[i]) {         if (a[x] % 2 != a[i] % 2) {           ans[x] = 1;           toUp.insert(x);         }       }     }     while (!toUp.empty()) {       vector<long long> temp(toUp.begin(), toUp.end());       toUp.clear();       for (auto i : temp) {         for (auto x : g[i]) {           if (ans[x] > ans[i] + 1) {             ans[x] = ans[i] + 1;             toUp.insert(x);           }         }       }     }     for (int i = 1; i <= n; i++) {       if (ans[i] == LLONG_MAX)         cout <<  -1  ;       else         cout << ans[i] <<    ;     }     return 0;   }


#include <bits/stdc++.h>   char map[101][10001];   long long mic[101][10001];   int n, m;   long long max = 1000000000;   int check = 0;   void find(int x) {     int sum = 0;     for (int i = 0; i < n; i++) {       sum += mic[i][x];       if (sum > max) return;     }     max = sum;   }   int main() {     scanf( %d %d  , &n, &m);     for (int i = 0; i < n; i++) {       gets(map[i]);       int temp = 0;       int mul = 0;       for (int j = 0; j < m; j++) mic[i][j] = 1000000000;       for (int j = 0; j <= m * 2; j++) {         if (map[i][j % m] ==  1 ) {           temp = 0;           mul = 1;         }         if ((temp < mic[i][j % m] && mul == 1) || mic[i][j % m] == 0)           mic[i][j % m] = temp;         temp += mul;       }       temp = 0;       mul = 0;       for (int j = (2 * m); j >= 0; j--) {         if (map[i][j % m] ==  1 ) {           temp = 0;           mul = 1;         }         if ((temp < mic[i][j % m] && mul == 1) || mic[i][j % m] == 0)           mic[i][j % m] = temp;         temp += mul;       }     }     for (int i = 0; i < m; i++) find(i);     if (max >= 1000000000)       printf( -1 );     else       printf( %d , max);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1000003;   int a[maxn];   int main() {     ios_base::sync_with_stdio(false);     int n;     cin >> n;     int ans = 0;     int N = 1000000;     while (n--) {       int x;       cin >> x;       a[x]++;       ans = max(ans, a[x]);       for (int i = x * 2; i <= N; i += x) a[i] = max(a[i], a[x]);     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char gc() {     static char buf[100000], *p1 = buf, *p2 = buf;     return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)                ? EOF                : *p1++;   }   inline int read() {     int x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 )       x = (x << 3) + (x << 1) + ch -  0 , ch = getchar();     return x * f;   }   inline long long readll() {     long long x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 )       x = (x << 3) + (x << 1) + ch -  0 , ch = getchar();     return x * f;   }   inline void write(int x) {     if (!x) putchar( 0 );     if (x < 0) x = -x, putchar( - );     static int sta[20];     register int tot = 0;     while (x) sta[tot++] = x % 10, x /= 10;     while (tot) putchar(sta[--tot] + 48);   }   const int maxn = 2007, INF = 0x3f3f3f3f;   const int MOD = 998244353;   const long long LINF = 0x3f3f3f3f3f3f3f3fll;   const long long P = 19260817;   inline int mod1(int x) { return x < MOD ? x : x - MOD; }   inline int mod2(int x) { return x < 0 ? x + MOD : x; }   inline void add(int &x, int y) { x = mod1(x + y); }   inline void sub(int &x, int y) { x = mod2(x - y); }   struct node {     int x, y, dis;     friend bool operator<(const node &a, const node &b) {       if (a.dis != b.dis) return a.dis < b.dis;       if (a.x != b.x) return a.x < b.x;       return a.y < b.y;     }   };   inline void chkmin(node &a, node b) { a = min(a, b); }   int n, m, K;   int fal[maxn][maxn];   int far[maxn][maxn];   int fau[maxn][maxn];   int fad[maxn][maxn];   int find(int x, int *fa) { return x == fa[x] ? x : fa[x] = find(fa[x], fa); }   void solve(int x, int y) {     if (fal[x][y] == y) {       printf( %d %d n , x, y);       fal[x][y] = y - 1;       far[x][y] = y + 1;       fau[y][x] = x - 1;       fad[y][x] = x + 1;       return;     }     node ans = (node){0, 0, INF};     for (int i = x; i <= min(x + (int)sqrt(K), n); i++) {       int t = y;       t = find(t, fal[i]);       if (t) chkmin(ans, (node){i, t, abs(i - x) + abs(t - y)});       t = y;       t = find(t, far[i]);       if (t) chkmin(ans, (node){i, t, abs(i - x) + abs(t - y)});       if (y == fal[i][y]) break;     }     for (int i = x; i >= max(x - (int)sqrt(K), 1); i--) {       int t = y;       t = find(t, fal[i]);       if (t) chkmin(ans, (node){i, t, abs(i - x) + abs(t - y)});       t = y;       t = find(t, far[i]);       if (t) chkmin(ans, (node){i, t, abs(i - x) + abs(t - y)});       if (y == fal[i][y]) break;     }     for (int i = y; i <= min(y + (int)sqrt(K), m); i++) {       int t = x;       t = find(t, fau[i]);       if (t) chkmin(ans, (node){t, i, abs(t - x) + abs(i - y)});       t = x;       t = find(t, fad[i]);       if (t) chkmin(ans, (node){t, i, abs(t - x) + abs(i - y)});       if (x == fau[i][x]) break;     }     for (int i = y; i >= max(y - (int)sqrt(K), 1); i--) {       int t = x;       t = find(t, fau[i]);       if (t) chkmin(ans, (node){t, i, abs(t - x) + abs(i - y)});       t = x;       t = find(t, fad[i]);       if (t) chkmin(ans, (node){t, i, abs(t - x) + abs(i - y)});       if (x == fau[i][x]) break;     }     printf( %d %d n , ans.x, ans.y);     fal[ans.x][ans.y] = ans.y - 1;     far[ans.x][ans.y] = ans.y + 1;     fau[ans.y][ans.x] = ans.x - 1;     fad[ans.y][ans.x] = ans.x + 1;   }   int main() {     scanf( %d%d%d , &n, &m, &K);     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         fal[i][j] = j, far[i][j] = j;         fau[j][i] = i, fad[j][i] = i;       }     }     for (int i = 1, x, y; i <= K; i++) {       scanf( %d%d , &x, &y);       solve(x, y);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int read() {     int x = 0;     bool op = false;     char c = getchar();     while (!isdigit(c)) op |= (c ==  - ), c = getchar();     while (isdigit(c)) x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();     return op ? -x : x;   }   const int N = 2e5 + 10;   int n, m, B;   int dif[N], d[500][500], lst[N];   struct Node {     int x, y;     Node() {}     Node(int x, int y) : x(x), y(y) {}   } a[N];   void update(int t, int x, int v) {     int p = a[x].x + a[x].y;     int l = (t + a[x].x) % p, r = (t - 1) % p;     if (l <= r)       for (int i = l; i <= r; i++) d[p][i] += v;     else {       for (int i = 0; i <= r; i++) d[p][i] += v;       for (int i = l; i < p; i++) d[p][i] += v;     }   }   int main() {     n = read();     m = read();     B = sqrt(m);     for (int i = 1; i <= n; i++) {       int x = read(), y = read();       a[i] = Node(x, y);     }     int ans = 0;     for (int t = 1; t <= m; t++) {       int op = read(), x = read();       if (op == 1) {         if (a[x].x + a[x].y > B) {           for (int i = t + a[x].x; i <= m; i += a[x].x + a[x].y) {             dif[i]++;             if (i + a[x].y <= m) dif[i + a[x].y]--;           }         } else           update(t, x, 1);         lst[x] = t;       } else {         if (a[x].x + a[x].y > B) {           for (int i = lst[x] + a[x].x; i <= m; i += a[x].x + a[x].y) {             dif[i]--;             if (i + a[x].y <= m) dif[i + a[x].y]++;             if (i < t && i + a[x].y >= t) ans--;           }         } else           update(lst[x], x, -1);       }       int res = 0;       ans += dif[t];       for (int i = 1; i <= B; i++) res += d[i][t % i];       printf( %d n , res + ans);     }   }


#include <bits/stdc++.h>   using namespace std;   long long LLINF = (long long)1000000000 * 1000000010;   const int MAXN = 410;   int g[MAXN], g1[MAXN];   int c[MAXN];   int M, m;   int solve(int x, int *a) {     int ans = 0;     for (int i = 0; i < m; i++) {       a[i] = x / c[i];       x %= c[i];       ans += a[i];     }     return ans;   }   int main() {     int t, good;     while (scanf( %d , &m) != EOF) {       for (int i = 0; i < m; i++) scanf( %d , &c[i]);       sort(c, c + m, greater<int>());       good = 1;       long long best = LLINF;       for (int i = 1; i < m; i++) {         solve(c[i - 1] - 1, g);         for (int j = i; j < m; j++) {           long long w = 0, v = 0;           for (int k = 0; k < j; k++) {             w += (long long)g[k] * c[k];             v += g[k];           }           w += (long long)(g[j] + 1) * c[j];           v += g[j] + 1;           if (solve(w, g1) > v) {             good = 0;             if (w < best) best = w;           }         }       }       if (good)         cout << -1 << endl;       else         cout << best << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     int n, h, x, r = 0;     cin >> n >> h;     for (int i = 0; i < n; i++) {       cin >> x;       if (x > h) {         r += 2;       } else {         r += 1;       }     }     cout << r << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1E3 + 5;   int n;   struct line {     int x, y, w, num;     line(int a = 0, int b = 0, int c = 0, int d = 0) : x(a), y(b), w(c), num(d) {}     bool operator<(const line& A) const { return w > A.w; }   } a[maxn], b[maxn];   vector<line> ans;   inline bool inter(line x, line y) {     int l1 = min(x.x, x.y), r1 = max(x.x, x.y);     int l2 = min(y.x, y.y), r2 = max(y.x, y.y);     return (l1 < l2 && l2 < r1 && r1 < r2) || (l2 < l1 && l1 < r2 && r2 < r1);   }   inline int dis(line A, int x) {     int l = min(A.x, A.y), r = max(A.x, A.y);     if (l <= x && x <= r) return n - (r - l);     return r - l;   }   inline void solve(int x, int y) {     vector<line> wait;     for (int i = 1; i <= n - 3; ++i)       if (inter(a[i], line(x, y)))         wait.push_back(line(a[i].x, a[i].y, dis(a[i], x), i));     if (wait.size() == 0) return;     sort(wait.begin(), wait.end());     for (int i = 0; i < wait.size() - 1; ++i) {       ans.push_back(wait[i]);       int p = wait[i].num;       if (wait[i].x == wait[i + 1].x) {         a[p].x = wait[i + 1].y;         a[p].y = x;       } else if (wait[i].y == wait[i + 1].x) {         a[p].y = wait[i + 1].y;         a[p].x = x;       } else if (wait[i].x == wait[i + 1].y) {         a[p].x = wait[i + 1].x;         a[p].y = x;       } else {         a[p].y = wait[i + 1].x;         a[p].x = x;       }     }     ans.push_back(wait[wait.size() - 1]);     int p = wait[wait.size() - 1].num;     a[p].x = x, a[p].y = y;   }   int main() {     ios::sync_with_stdio(false);     cin >> n;     for (int i = 1; i <= n - 3; ++i) cin >> a[i].x >> a[i].y;     for (int i = 1; i <= n - 3; ++i) cin >> b[i].x >> b[i].y;     random_shuffle(b + 1, b + n - 3 + 1);     for (int i = 1; i <= n - 3; ++i) solve(b[i].x, b[i].y);     cout << ans.size() << endl;     for (int i = 0; i < ans.size(); ++i)       cout << ans[i].x <<     << ans[i].y <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 3e5 + 100;   const long long INF = 1e13;   int u, v, c, b, laz[MAXN], C[MAXN], n, m, st[MAXN];   bool vis[MAXN];   multiset<pair<int, int> > Q[MAXN];   multiset<pair<int, int> >::iterator it;   vector<pair<int, int> > W[MAXN];   vector<int> G[MAXN];   pair<int, int> k;   void merg(int v, int u) {     if (Q[v].size() >= Q[u].size()) {       while (!(Q[u].empty())) {         it = Q[u].begin();         int i = (*(it)).second;         C[i] += laz[u] - laz[v];         c = (*it).first;         Q[v].insert({c + laz[u] - laz[v], i});         Q[u].erase(it);       }       return;     }     merg(u, v);     Q[v].swap(Q[u]);     laz[v] = laz[u];     return;   }   long long ans = 0;   int TIM = 0;   bool dfs(int v, int f = -1) {     st[v] = TIM;     TIM++;     for (auto u : G[v]) {       if (u == f) {         continue;       }       bool r = dfs(u, v);       if (!r) {         return 0;       }       merg(v, u);     }     for (auto k : W[v]) {       if (st[k.first] < st[v]) {         C[k.second] -= laz[v];         Q[v].insert({C[k.second], k.second});       } else {         Q[v].erase({C[k.second], k.second});       }     }     if (!v) {       return 1;     }     if (!(Q[v].size())) {       return 0;     }     int h = (*(Q[v].begin())).first;     ans += (h + laz[v]);     laz[v] -= (h + laz[v]);     return 1;   }   int main() {     cin >> n >> m;     for (int i = 0; i < n - 1; i++) {       cin >> u >> v;       u--;       v--;       G[u].push_back(v);       G[v].push_back(u);     }     for (int i = 0; i < m; i++) {       cin >> u >> v >> C[i];       u--;       v--;       W[u].push_back({v, i});       W[v].push_back({u, i});     }     bool r = dfs(0);     if (!r) {       cout << -1 << endl;       return 0;     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   struct node {     int v, d;     bool operator<(const node &a) const {       if (d == a.d) return v < a.v;       return a.d < d;     }   };   set<node> s;   vector<int> adj[200005];   int d[200005], p[200005];   bool vis[200005];   void dfs(int u) {     int l = adj[u].size();     node nd;     vis[u] = true;     for (int a = 0; a < l; a++) {       int v = adj[u][a];       if (!vis[v] && v != p[u]) dfs(v);     }     nd.v = u, nd.d = d[u];     s.erase(nd);   }   int main() {     int n, ans = 0;     cin >> n;     for (int a = 1; a < n; a++) {       int u, v;       cin >> u >> v;       adj[u].push_back(v);       adj[v].push_back(u);     }     queue<int> q;     node nd;     q.push(1);     d[1] = p[1] = 0, vis[1] = true;     while (!q.empty()) {       int u = q.front();       q.pop();       nd.v = u, nd.d = d[u];       s.insert(nd);       int l = adj[u].size();       for (int a = 0; a < l; a++) {         int v = adj[u][a];         if (vis[v]) continue;         d[v] = 1 + d[u], p[v] = u;         q.push(v), vis[v] = true;       }     }     memset(vis, false, sizeof(vis));     while (!s.empty()) {       nd = *(s.begin());       if (nd.d > 2) {         dfs(p[nd.v]), ans++;         nd.v = p[p[nd.v]];         nd.d = d[nd.v];         s.erase(nd);       } else         break;     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> G[1000005];   int n, L[1000005], R[1000005], ind;   void dfs(int u, int pre) {     for (int i = G[u].size() - 1; i >= 0; i--) {       int v = G[u][i];       if (v != pre) L[v] = ++ind;     }     R[u] = ++ind;     for (auto v : G[u])       if (v != pre) dfs(v, u);   }   int main() {     cin >> n;     for (int i = 1; i < n; i++) {       int u, v;       scanf( %d%d , &u, &v);       G[u].push_back(v);       G[v].push_back(u);     }     L[1] = ++ind;     dfs(1, 1);     for (int i = 1; i <= n; i++) cout << L[i] <<     << R[i] <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int t;     cin >> t;     while (t--) {       long long A, B;       cin >> A >> B;       long long hb = (floor(log10(B + 1)) == log10(B + 1)) ? (floor(log10(B)) + 1)                                                            : floor(log10(B));       cout << hb * A << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using LL = long long;   int main() {     cin.tie(nullptr)->sync_with_stdio(false);     int T;     vector<int> f(3e5 + 5);     f[0] = 0;     for (int i = 1; i < 3e5 + 5; i++) f[i] = f[i - 1] ^ i;     for (cin >> T; T; T--) {       int a, b;       cin >> a >> b;       int ans = a;       if (f[a - 1] == 0) {         if (f[a - 1] == b)           ans = ans;         else if (a == b)           ans += 2;         else           ans++;       } else {         if (f[a - 1] == b)           ans = ans;         else if ((f[a - 1] ^ b) != a)           ans++;         else           ans += 2;       }       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   set<string> S;   string line[1010], a[1010], s;   int n = 0, ans = 0, file = 0;   int main() {     while (getline(cin, s)) line[++n] = s;     for (int i = 1; i <= n; i++) {       int cur = 0;       a[i] =   ;       for (int j = 0; j < line[i].size(); j++) {         a[i] += line[i][j];         if (line[i][j] ==     ) cur++;         if (cur == 2) break;       }     }     for (int i = 1; i <= n; i++) {       string fd = a[i];       S.clear();       int files = 0, F = 0;       for (int j = 1; j <= n; j++)         if (a[j] == fd) {           files++;           string v =   ;           int cur = 0;           for (int k = 0; k < line[j].size(); k++) {             v += line[j][k];             if (line[j][k] ==     ) cur++;             if (line[j][k] ==      && cur > 2)               if (!S.count(v)) S.insert(v), F++;           }         }       ans = max(ans, F);       file = max(file, files);     }     cout << ans <<     << file << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     stack<pair<int, int> > S;     S.push(make_pair(0, -1));     vector<pair<int, int> > ans;     for (int i = 0; i <= n; i++) {       int a;       if (i < n)         cin >> a;       else         a = 0;       while (S.top().first > a) {         pair<int, int> last = S.top();         S.pop();         ans.push_back(make_pair(last.second, i - 1));         last.first--;         if (last.first > S.top().first) S.push(last);       }       if (S.top().first != a) S.push(make_pair(a, i));     }     cout << ans.size() << endl;     for (int i = 0; i < ans.size(); i++)       cout << ans[i].first + 1 <<     << ans[i].second + 1 << endl;   }


#include <bits/stdc++.h>   using namespace std;   bool ok[10];   bool judge(char str[], int k) {     int len = strlen(str);     memset(ok, false, sizeof(ok));     for (int i = 0; i < len; i++) {       ok[(str[i] -  0 )] = true;     }     for (int i = 0; i <= k; i++) {       if (!ok[i]) {         return false;       }     }     return true;   }   int main() {     int n, k;     char str[50];     ios::sync_with_stdio(false);     while (cin >> n >> k) {       int res = 0;       for (int i = 0; i < n; i++) {         cin >> str;         if (judge(str, k)) {           res++;         }       }       cout << res << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     int n;     cin >> n;     long long sum = 0;     for (int i = 0; i < n; ++i) {       int t1;       cin >> t1;       sum += t1;     }     if (sum % n)       cout << n - 1 << endl;     else       cout << n << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     long long n;     cin >> n;     vector<long long> a(n);     for (long long& i : a) cin >> i;     vector<long long> pre(n), suf(n);     long long cnt{1};     pre[0] = 1;     for (long long i = 1; i < n; i++) {       if (a[i] > a[i - 1]) {         cnt++;       } else {         cnt = 1;       }       pre[i] = cnt;     }     suf[n - 1] = 1;     cnt = 1;     for (long long i = n - 2; i >= 0; i--) {       if (a[i] < a[i + 1]) {         cnt++;       } else {         cnt = 1;       }       suf[i] = cnt;     }     long long mx{1};     for (long long i = 0; i < n - 2; i++) {       long long x = pre[i];       long long y = suf[i + 2];       if (a[i] + 1 < a[i + 2]) {         mx = max(mx, x + y + 1);       } else {         mx = max(mx, max(pre[i] + 1, suf[i + 2] + 1));       }     }     if (n >= 2) {       mx = max(mx, suf[1] + 1);       mx = max(mx, pre[n - 2] + 1);     }     cout << mx;   }   int32_t main() {     ios::sync_with_stdio(false);     cin.tie(0);     solve();   }


#include <bits/stdc++.h>   using namespace std;   const int N = 111111;   int size[3];   int colour[N];   bool ok = false;   bool used[N];   long long ans = 0;   vector<int> edge[N];   void dfs(int u) {     used[u] = true;     ans += size[colour[u]];     size[colour[u]]++;     for (int i = 0; i < edge[u].size(); i++) {       int temp = edge[u][i];       if (used[temp] == false) {         colour[temp] = colour[u] ^ 1;         dfs(temp);       } else if (colour[temp] != (colour[u] ^ 1)) {         ok = true;       }     }   }   int main() {     int n, m;     cin >> n >> m;     for (int i = 0; i < m; i++) {       int u, v;       cin >> u >> v;       u--;       v--;       edge[u].push_back(v);       edge[v].push_back(u);     }     for (int i = 0; i < n; i++) {       if (used[i] == false) {         size[0] = size[1] = 0;         dfs(i);       }     }     if (ok == true) {       cout <<  0 1  << endl;     } else if (ans == 0) {       if (m == 0) {         ans = (long long)n * (n - 1) * (n - 2);         ans /= 6;         cout <<  3   << ans << endl;       } else {         cout <<  2   << (long long)m * (n - 2) << endl;       }     } else {       cout <<  1   << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<int> a(n);     for (int i = 0; i < n; ++i) {       cin >> a[i];     }     vector<int> d(5000, 0);     for (int i = 0; i < n; ++i) {       for (int j = i + 1; j < n; ++j) {         ++d[abs(a[i] - a[j])];       }     }     vector<int> c(5000);     c[4999] = 0;     for (int i = 4998; i >= 0; --i) {       c[i] = c[i + 1] + d[i + 1];     }     long long good = 0;     for (int d1 = 1; d1 < 5000; ++d1) {       for (int d2 = 1; d2 < 5000 - d1; ++d2) {         good += static_cast<long long>(d[d1]) * d[d2] * c[d1 + d2];       }     }     long long all = n * (n - 1) / 2;     all = all * all * all;     cout.precision(10);     cout << fixed          << static_cast<long double>(good) / static_cast<long double>(all);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int M = 1e5 + 5;   const int mod = 1e9 + 7;   const double esp = 1e-10;   const long double pi = 4 * atan((long double)1);   int n;   long long d;   struct mido {     long long l, r, val;   } a[M];   vector<pair<long long, int> > v;   pair<int, int> f[12 * M];   int trace[M];   set<long long> s;   void upd(int id, int l, int r, int i, int k, int vt) {     if (l > r) return;     if (r < i || i < l) return;     if (l == r) {       if (f[id].first < k) f[id] = pair<int, int>(k, vt);       return;     }     int mid = (l + r) / 2;     upd(id * 2, l, mid, i, k, vt);     upd(id * 2 + 1, mid + 1, r, i, k, vt);     if (f[id * 2].first > f[id * 2 + 1].first) {       f[id] = f[id * 2];     } else       f[id] = f[id * 2 + 1];   }   pair<int, int> get(int id, int l, int r, int u, int v) {     if (l > r) return pair<int, int>(0, 0);     if (r < u || v < l) return pair<int, int>(0, 0);     if (u <= l && r <= v) {       return f[id];     }     int mid = (l + r) / 2;     pair<int, int> k1 = get(id * 2, l, mid, u, v);     pair<int, int> k2 = get(id * 2 + 1, mid + 1, r, u, v);     if (k1.first > k2.first) return k1;     return k2;   }   int main() {     ios_base::sync_with_stdio(false);     cin >> n >> d;     for (int i = 1; i <= n; i++) {       cin >> a[i].val;       v.push_back(pair<long long, int>(a[i].val, i));       v.push_back(pair<long long, int>(a[i].val - d, i + n));       v.push_back(pair<long long, int>(a[i].val + d, i + 2 * n));     }     sort(v.begin(), v.end());     for (int i = 0; i < 3 * n; i++) {       s.insert(v[i].first);       int vt = v[i].second;       if (vt <= n)         a[vt].val = s.size();       else if (vt <= 2 * n)         a[vt - n].l = s.size();       else         a[vt - 2 * n].r = s.size();     }     int ans = 0, last;     for (int i = 1; i <= n; i++) {       pair<int, int> k1 = get(1, 1, 3 * n, 1, a[i].l);       pair<int, int> k2 = get(1, 1, 3 * n, a[i].r, 3 * n);       if (k1.first > k2.first) {         upd(1, 1, 3 * n, a[i].val, k1.first + 1, i);         trace[i] = k1.second;         if (ans < k1.first + 1) {           ans = k1.first + 1;           last = i;         }       } else {         upd(1, 1, 3 * n, a[i].val, k2.first + 1, i);         trace[i] = k2.second;         if (ans < k2.first + 1) {           ans = k2.first + 1;           last = i;         }       }     }     cout << ans << endl;     vector<int> res;     while (last > 0) {       res.push_back(last);       last = trace[last];     }     for (int i = res.size() - 1; i >= 0; i--) cout << res[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 200000;   bool active[MAXN + 10];   int v[MAXN + 10];   vector<int> factors[MAXN + 10];   int cantidad[5000001];   int main() {     int n, q;     scanf( %d %d , &n, &q);     for (int i = 0; i < n; i++) {       scanf( %d , &v[i]);       int aux = v[i];       for (int j = 2; j * j <= aux; j++) {         if (aux % j == 0) {           factors[i].push_back(j);           while (aux % j == 0) aux /= j;         }       }       if (aux > 1) factors[i].push_back(aux);     }     long long bad = 0;     int cnt = 0, ones = 0;     for (int i = 0; i < q; i++) {       int x;       scanf( %d , &x);       x--;       if (active[x]) {         if (v[x] == 1) {           ones--;         } else {           cnt--;           int sz = factors[x].size();           for (int j = 1; j < (1 << sz); j++) {             int counter = 0;             int product = 1;             for (int k = 0; k < sz; k++) {               if (j & (1 << k)) {                 counter++;                 product = product * factors[x][k];               }             }             cantidad[product]--;             if (counter & 1)               bad -= cantidad[product];             else               bad += cantidad[product];           }         }       } else {         if (v[x] == 1)           ones++;         else {           cnt++;           int sz = (int)factors[x].size();           for (int j = 1; j < (1 << sz); j++) {             int counter = 0;             int product = 1;             for (int k = 0; k < sz; k++) {               if (j & (1 << k)) {                 counter++;                 product = product * factors[x][k];               }             }             if (counter & 1)               bad += cantidad[product];             else               bad -= cantidad[product];             cantidad[product]++;           }         }       }       active[x] = !active[x];       printf( %lld n , (1LL * cnt * (cnt - 1) / 2) - bad + (1LL * cnt * ones) +                            1LL * ones * (ones - 1) / 2);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main(int argc, char **argv) {     int n, k, value = 0;     vector<pair<int, int>> set;     cin >> n >> k;     for (int i = 0; i < n; ++i) {       int x, y;       cin >> x >> y;       set.push_back({x, y});     }     for (int i = 0; i < n; ++i) {       value += set[i].second - set[i].first + 1;     }     if (value % k == 0) {       cout << 0;       return 0;     }     cout << k - (value % k);   }


#include <bits/stdc++.h>   using namespace std;   char s[1000100];   int n;   int d[1000100];   int dp(int x) {     if (d[x] != -1) return d[x];     int ret = 0;     int ind = x + 1;     while (s[ind] ==  M ) {       ret += 1;       ind++;     }     int w = 0;     while (s[ind] ==  F  && ind < n) ind++, w++;     if (ind == n)       return d[x] = ret;     else {       int rety = dp(ind);       if (w > rety)         return d[x] = ret;       else         return d[x] = dp(ind) + 1 - w + ret;     }   }   int main() {     while (scanf( %s , s) != EOF) {       n = strlen(s);       memset(d, -1, sizeof(d));       int cntm = 0;       for (int i = 0; i < n; i++)         if (s[i] ==  M ) cntm++;       for (int i = n - 1; i >= 0; i--) {         if (s[i] ==  M )           d[i] = 0;         else           break;       }       int st = -1;       for (int i = 0; i < n; i++)         if (s[i] ==  M ) {           st = i;           break;         }       if (st == -1) {         puts( 0 );         continue;       }       dp(st);       printf( %d n , d[st] + (n - 1 - cntm + 1) - st);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long ctos, modd = 1000000007, dos = 2;   long long P[4005], B[4005][4005], res;   long long bi(int n, int k) {     if (n == k) return 1;     if (k == 0) return 1;     if (k > n) return 0;     if (k == 1) return n;     if (B[n][k] > 0) return B[n][k];     B[n][k] = (bi(n - 1, k - 1) + bi(n - 1, k)) % modd;     return B[n][k];   }   int main() {     cin >> ctos;     P[0] = 1;     for (int i = 1; i <= ctos; i++) {       for (int e = 0; e < i; e++) {         P[i] += 1LL * P[i - e - 1] * bi(i - 1, e) % modd;         P[i] %= modd;       }     }     for (int i = 1; i <= ctos; i++) {       res += P[ctos - i] * bi(ctos, i) % modd;       res %= modd;     }     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   const int MaxN = 1000;   using namespace std;   char s[MaxN + 5];   int n;   int vis[200 + 5];   int main() {     while (~scanf( %d , &n)) {       scanf( %s , s + 1);       int Max = 0;       for (int i = 1; i <= n; i++) {         for (int j = i; j <= n; j++) {           memset(vis, 0, sizeof(vis));           int ans = 0;           bool ok = 1;           for (int k = i; k <= j; k++) {             if (s[k] >=  A  && s[k] <=  Z )               ok = 0;             else {               if (!vis[s[k]]) ans++, vis[s[k]] = 1;             }           }           if (ok) Max = max(Max, ans);         }       }       printf( %d n , Max);     }   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007;   const int maxn = 2000000;   int l, lsub;   char str[maxn + 1];   long long dpw[maxn + 1], dpb[maxn + 1], now, nob, ans0, ansb, ans, ranansb,       ranans0;   int main() {     scanf( %d%d , &l, &lsub);     scanf( %s , str);     now = -1;     nob = -1;     for (long long i = 0; i < l; i++) ans0 = 1;     for (long long i = 0; i < l; i++) {       if (str[i] ==  X ) {         long long temp = 0;         if (i - now >= lsub) {           temp = 1;           if (i >= lsub) temp = dpw[i - lsub];         }         ranans0 = ans0 * 2 - temp;         while (ranans0 < 0) ranans0 += mod;         long long temp1 = 0;         if (i - nob >= lsub) {           if (i >= lsub) temp1 = dpb[i - lsub];         }         ranansb = ansb * 2 + temp - temp1;         while (ranansb < 0) ranansb += mod;         ans *= 2;         ans %= mod;         ans += temp1;         ans %= mod;         dpw[i] = ans0 % mod;         dpb[i] = (ansb + temp) % mod;         ans0 = ranans0 % mod;         ansb = ranansb % mod;       }       if (str[i] ==  B ) {         long long temp = 0;         if (i - now >= lsub) {           temp = 1;           if (i >= lsub) temp = dpw[i - lsub];         }         nob = i;         ranans0 = ans0 - temp;         while (ranans0 < 0) ranans0 += mod;         ranansb = ansb + temp;         dpw[i] = 0;         dpb[i] = (ansb + temp) % mod;         ans0 = ranans0 % mod;         ansb = ranansb % mod;       }       if (str[i] ==  W ) {         long long temp1 = 0;         if (i - nob >= lsub) {           if (i >= lsub) temp1 = dpb[i - lsub];         }         now = i;         ranans0 = ans0;         ranansb = ansb - temp1;         while (ranansb < 0) ranansb += mod;         ans += temp1;         ans %= mod;         dpw[i] = ans0 % mod;         dpb[i] = 0;         ans0 = ranans0 % mod;         ansb = ranansb % mod;       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, max = 0;     cin >> n;     int arr[n];     long long ans = 0;     for (int i = 0; i < n; i++) {       cin >> arr[i];       if (arr[i] > max) {         max = arr[i];       }     }     for (int i = 0; i < n; i++) {       ans += max - arr[i];     }     cout << ans << endl;     return 0;   }