#include <bits/stdc++.h>   using namespace std;   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 <<  { ;     typename vector<T>::const_iterator it;     for (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 <<  [ ;     typename set<T>::const_iterator it;     for (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 <<  [ ;     typename map<F, S>::const_iterator it;     for (it = v.begin(); it != v.end(); it++) {       if (it != v.begin()) os <<  ,  ;       os << it->first <<   =   << it->second;     }     return os <<  ] ;   }   int dx[4] = {1, -1, 0, 0};   int dy[4] = {0, 0, 1, -1};   const long long N = 1e6 + 1, M = 1e5 + 5, mod = 1e9 + 7, MOD = 1e9 + 7,                   inf = 5e18, MAX = 2e5;   string alphabet =  abcdefghijklmnopqrstuvwxyz ,          capital =  ABCDEFGHIJKLMNOPQRSTUVWXYZ , dig =  0123456789 ;   vector<bool> taken(N, false);   vector<int> ar;   void solve(int tt) {     int n, i, h, j, k, m, a, b;     cin >> n;     int sm = 0;     for (int i = 1; i <= n; i++) {       cin >> a;       ar.push_back(a);       taken[a] = true;       sm += a - 1;     }     vector<int> ans;     int cnt = 0;     for (int i = 0; i < n; i++) {       int cur = ar[i];       if (!taken[N - cur])         ans.push_back(N - cur);       else         ++cnt;       taken[N - cur] = true;     }     for (int i = 1; i < N && cnt > 0; i++) {       if (taken[i]) continue;       int now = N - i;       if (!taken[now]) {         taken[i] = taken[now] = true;         ans.push_back(i);         ans.push_back(N - i);         cnt -= 2;       }     }     cout << ans.size() <<   n ;     for (auto z : ans) {       sm -= (N - z - 1);       cout << z <<    ;     }   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long i;     long long T = 1, K;     for (auto blockTime = make_pair(chrono::high_resolution_clock::now(), true);          blockTime.second;          fprintf(stderr,  %s: %d ms n ,  Exec Time :  ,                  (int)chrono::duration_cast<chrono::milliseconds>(                      chrono::high_resolution_clock::now() - blockTime.first)                      .count()),               fflush(stderr), blockTime.second = false) {       long long x = 1;       while (x <= T) {         solve(x);         x++;       }     }     return 0;   }


#include<bits/stdc++.h>   using namespace std;   #pragma region atcoder   /*#include <atcoder/all>   using namespace atcoder;   //using mint = modint998244353;   //using mint = modint1000000007;*/   #pragma endregion   #pragma region macros   using ll = long long;   using pii = pair<int, int>;   using pll = pair<ll, ll>;   using vi = vector<int>;   using vs = vector<string>;   using vl = vector<ll>;   using vb = vector<bool>;   using vvi = vector<vector<int>>;   using vvl = vector<vector<ll>>;   #define rep(i, n) for(int i = 0; i < n; i++)   #define REP(i, a, b) for(int i = a; i < b; i++)   #define rrep(i, n) for(int i = n - 1; i >= 0; i--)   #define RREP(i, a, b) for(int i = b - 1; i >= a; i--)   #define all(x) (x).begin(), (x).end()   #define rall(x) (x).rbegin(), (x).rend()   #define sz(x) ((int)(x).size())   #define pb push_back   #define lb lower_bound   #define ub upper_bound   #define fi first   #define se second   #pragma endregion   #pragma region debug for var, v, vv   #define debug(var)  do{std::cout << #var <<   :  ;view(var);}while(0)   template<typename T> void view(T e){std::cout << e << std::endl;}   template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e <<    ; } std::cout << std::endl;}   template<typename T> void view(const std::vector<std::vector<T> >& vv){cout << endl;int cnt = 0;for(const auto& v : vv){cout << cnt <<  th :  ; view(v); cnt++;} cout << endl;}   #pragma endregion   /*#pragma region int128   std::ostream &operator<<(std::ostream &dest, __int128_t value) {     std::ostream::sentry s(dest);     if (s) {       __uint128_t tmp = value < 0 ? -value : value;       char buffer[128];       char *d = std::end(buffer);       do {         --d;         *d =  0123456789 [tmp % 10];         tmp /= 10;       } while (tmp != 0);       if (value < 0) {         --d;         *d =  - ;       }       int len = std::end(buffer) - d;       if (dest.rdbuf()->sputn(d, len) != len) {         dest.setstate(std::ios_base::badbit);       }     }     return dest;   }   #pragma endregion*/   const ll mod = 998244353;   const int inf = 1001001001;   const ll INF = 1001001001001001001;       int dx[]={1,0,-1,0};   int dy[]={0,1,0,-1};   template<class T>bool chmax(T &a, const T b) { if (a<b) { a=b; return 1; } return 0; }   template<class T>bool chmin(T &a, const T b) { if (b<a) { a=b; return 1; } return 0; }   ll rudiv(ll a, ll b) { return a/b+((a^b)>0&&a%b); } //  20 / 3 == 7   ll rddiv(ll a, ll b) { return a/b-((a^b)<0&&a%b); } // -20 / 3 == -7   ll power(ll a, ll p){ll ret = 1; while(p){if(p & 1){ret = ret * a;} a = a * a; p >>= 1;} return ret;}   ll modpow(ll a, ll p){ll ret = 1; while(p){if(p & 1){ret = ret * a % mod;} a = a * a % mod; p >>= 1;} return ret;}   /*--------------------------------------------------------------------------------------------------------------------------------*/   int main() {       cin.tie(nullptr);       ios::sync_with_stdio(false);       //cout << fixed << setprecision(15);       int t; cin >> t;        while(t--){            int x, y; cin >> x >> y;            if(x == y) cout << (x + y) << endl;            else{                cout << min(x, y) * 2 + ((max(x, y) - min(x, y)) - 1) * 2 + 1  << endl;            }        }   }   /*      * review you code when you get WA (typo? index?)      * int overflow, array bounds      * special cases (n=1?)   */


#include <bits/stdc++.h>   using namespace std;   bool isPrime(long long n) {     if (n <= 1) return false;     for (int i = 2; i <= sqrt(n); i++)       if (n % i == 0) return false;     return true;   }   long long factorial(long long n) {     if (n == 0)       return 1;     else       return n * factorial(n - 1);   }   bool primeFactors(int n, int l, int r, bool notFound) {     for (int i = l; i <= r; i++) {       if (i == 1) i++;       if (n % i == 0) {         cout << i <<    ;         notFound = false;       }       while (n % i == 0) {         n = n / i;       }     }     return notFound;   }   bool IsInBinarySequence(long long number) {     long long numbertocheck = 1;     do {       if (number == numbertocheck) return true;       numbertocheck *= 2;     } while (numbertocheck <= number);     return false;   }   long long nextPowerOf2(long long n) {     if (n && !(n & (n - 1))) return n;     long long cnt = 0;     while (n != 0) {       n >>= 1;       cnt++;     }     long long x = 1;     x = x << cnt;     return x;   }   long long highestPowerof2(long long n) {     long long res = 0;     for (long long i = n; i >= 1; i--) {       if ((i & (i - 1)) == 0) {         res = i;         break;       }     }     return res;   }   long long fib(long long n) {     if (n <= 1) return 1;     return fib(n - 1) + fib(n - 2);   }   long long binets_formula(long long n) {     double sqrt5 = sqrt(5);     int F_n = (pow((1 + sqrt5), n) - pow((1 - sqrt5), n)) / (pow(2, n) * sqrt5);     return F_n;   }   void first50fib() {     long long arr[] = {         1,          1,           2,          3,          5,          8,         13,         21,          34,         55,         89,         144,         233,        377,         610,        987,        1597,       2584,         4181,       6765,        10946,      17711,      28657,      46368,         75025,      121393,      196418,     317811,     514229,     832040,         1346269,    2178309,     3524578,    5702887,    9227465,    14930352,         24157817,   39088169,    63245986,   102334155,  165580141,  267914296,         433494437,  701408733,   1134903170, 1836311903, 2971215073, 4807526976,         7778742049, 12586269025, 20365011074};   }   int binarySearch(int a[], int first, int last, int search_num) {     int middle;     if (last >= first) {       middle = (first + last) / 2;       if (a[middle] == search_num) {         return middle + 1;       } else if (a[middle] < search_num) {         return binarySearch(a, middle + 1, last, search_num);       } else {         return binarySearch(a, first, middle - 1, search_num);       }     }     return -1;   }   void factorize(long long n) {     int count = 0;     while (!(n % 2)) {       n /= 2;       count++;     }     if (count) cout << 2 <<  ^  << count << endl;     for (long long i = 3; i <= sqrt(n); i += 2) {       count = 0;       while (n % i == 0) {         count++;         n = n / i;       }       if (count) cout << i <<  ^  << count << endl;     }     if (n > 2) cout << n <<  ^  << 1 << endl;   }   void primeFactors(long long num) {     long long fac = 2;     while (num > 1) {       if (num % fac == 0) {         cout <<  (  << fac <<  ^ ;         num /= fac;         long long pow = 1;         while (num % fac == 0) {           num /= fac;           pow++;         }         cout << pow;         if (num != 1) cout <<  )* ;       } else {         fac++;       }     }   }   bool onePrimeFactor(long long num) {     long long fac = 2;     int cnt = 0;     while (num > 1) {       if (num % fac == 0) {         cnt++;         while (num % fac == 0) num /= fac;       } else {         fac++;       }       if (cnt >= 2) {         return false;       }     }     return true;   }   bool isPerfect(long long d) {     double temp = d;     d = sqrt(d);     temp = sqrt(temp);     if (temp == d) return true;     return false;   }   void sort(string s[], int n) {     for (int i = 1; i < n; i++) {       string temp = s[i];       int j = i - 1;       while (j >= 0 && temp.length() < s[j].length()) {         s[j + 1] = s[j];         j--;       }       s[j + 1] = temp;     }   }   bool IsPowerOfTwo(long long x) { return (x & (x - 1)) == 0; }   int binarySearchCount(int arr[], int n, int key) {     int left = 0, right = n;     int mid;     while (left < right) {       mid = (right + left) >> 1;       if (arr[mid] == key) {         while (mid + 1 < n && arr[mid + 1] == key) mid++;         break;       } else if (arr[mid] > key)         right = mid;       else         left = mid + 1;     }     while (mid > -1 && arr[mid] > key) mid--;     return mid + 1;   }   bool is(int x, int y) {     set<int> s;     if (x < 10000) {       s.insert(0);     }     if (y < 10000) {       s.insert(0);     }     while (x > 0) {       int d = x % 10;       s.insert(d);       x /= 10;     }     while (y > 0) {       int d = y % 10;       s.insert(d);       y /= 10;     }     return s.size() == 10;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long i, n;     set<long long> k;     string s[] = { 47 ,  4477 ,  444777 ,  44447777 ,  4444477777 };     for (i = 0; i < 5; i++) {       do {         k.insert(stoll(s[i]));       } while (next_permutation(s[i].begin(), s[i].end()));     }     cin >> n;     cout << *k.lower_bound(n);   }


#include <bits/stdc++.h>   using namespace std;   long long n, k;   int main() {     cin >> n >> k;     int ans = 1;     while ((k & 1LL) == 0) {       ++ans;       k = k >> 1;     }     printf( %d n , ans);     return 0;   }


#include<bits/stdc++.h>   using namespace std;   long long q,n,c[400005],z,ans,mn=1e14,d,x;   map<long long,long long>las,ll;   vector<long long>v;   struct am{   long long va,ind;   };   am a[400005];   bool cmp(am zz,am y){   return zz.ind<y.ind;   }   set<long long>st;   int main(){   ios::sync_with_stdio(NULL);   cin.tie(0);   cout.tie(0);   cin>>q;      while (q--){   cin>>n;   st.clear();   v.clear();   las.clear();   ll.clear();   mn=1e14;   for (long long i=1;i<=n;i++){       cin>>x;       las[x]++;   }   z=1;   for (auto it=las.begin();it!=las.end();it++){   a[z].va=it->first;   a[z].ind=it->second;   z++;   }      sort (a+1,a+z,cmp);   for (long long i=z-1;i>=1;i--){           x=st.size();       mn=min(mn,n-(a[i].ind + a[i].ind*x));   st.insert(a[i].va);   }         cout<<mn<<  n ;   }         }


#include <bits/stdc++.h>   using namespace std;   const int N = 200009;   int n, a[N], cnt[N], mode, fsm[N], tmp[N], ans;   void larg(int x) {     int sm = 0, res = 0;     memset(fsm, 0, sizeof(fsm));     for (int i = 1; i <= n; i++) {       if (a[i] == mode)         sm++;       else if (a[i] == x)         sm--;       if (sm && !fsm[sm]) fsm[sm] = i;       res = max(res, i - fsm[sm]);     }     ans = max(ans, res);   }   void smal(int x) {     int l = 1, p = 0, res = 0;     memset(tmp, 0, sizeof(tmp));     for (int i = 1; i <= n; i++) {       tmp[a[i]]++;       if (tmp[a[i]] == x) p++;       while (l <= i && tmp[a[i]] > x) {         if (tmp[a[l]] == x) --p;         tmp[a[l++]]--;       }       if (p >= 2) res = max(res, i - l + 1);     }     ans = max(ans, res);   }   int main() {     scanf( %d , &n);     if (n == 1) {       puts( 0 );       return 0;     }     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       cnt[a[i]]++;     }     for (int i = 1; i <= n; i++) {       if (cnt[a[i]] > cnt[mode]) mode = a[i];     }     for (int i = 1; i <= 200000; i++) {       if (!cnt[i]) continue;       if (i != mode && cnt[i] == cnt[mode]) {         printf( %d n , n);         return 0;       }       if (cnt[i] > sqrt(n)) larg(i);     }     for (int i = 1; i <= sqrt(n); i++) smal(i);     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 300;   map<int, int> m;   int main() {     ios_base::sync_with_stdio(false);     int i, j, n;     cin >> n;     int p = 0;     int k = 0;     for (i = 1; i <= n; ++i) {       cin >> j;       if (m[j] == 0)         ++k;       else         m[j]--;       m[i]++;     }     cout << k << endl;   }


#include <bits/stdc++.h>   using namespace std;   int N, R;   int result = INT_MAX;   char opt[] =  TB ;   int turns;   int sLast;   char rChar[1000001];   int main() {     int x, y;     cin >> N >> R;     if (N == 1 && R == 1) {       cout << 0 << endl <<  T  << endl;       return 0;     }     for (int i = 1; i < R; i++) {       x = i;       y = R;       int *smaller, *larger;       int mistakes = 0;       int times = 0;       int turn_over = 0;       while (x > 0 && y > 0) {         if (x > y) {           larger = &x;           smaller = &y;         } else {           larger = &y;           smaller = &x;         }         mistakes += *larger / *smaller - 1;         times += *larger / *smaller;         turn_over++;         *larger %= *smaller;       }       if (x + y == 1 && times == N) {         mistakes--;         turn_over++;         if (mistakes < result) {           result = mistakes;           sLast = i;           turns = turn_over;         }       }     }     if (result == INT_MAX) {       cout <<  IMPOSSIBLE  << endl;     } else {       cout << result << endl;       if (turns & 1) {         x = R;         y = sLast;       } else {         x = sLast;         y = R;       }       for (int i = N - 1; i > 0; i--) {         if (x > y) {           rChar[i] =  T ;           x -= y;         } else {           rChar[i] =  B ;           y -= x;         }       }       rChar[0] =  T ;       cout << rChar << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long MOD = 1e9 + 7;   long long PRIME = 999727999;   long long PRIME2 = 999999937;   long long INF = LLONG_MAX / 4;   template <class F1, class F2>   ostream& operator<<(ostream& os, const pair<F1, F2>& p) {     return os << p.first <<     << p.second;   }   template <class F1, class F2>   istream& operator>>(istream& is, pair<F1, F2>& p) {     return is >> p.first >> p.second;   }   template <class F>   ostream& operator<<(ostream& os, const std::vector<F>& v) {     for (int i = 0; i < (int)v.size(); i++) os << v[i] <<    ;     return os;   }   template <class F>   istream& operator>>(istream& is, std::vector<F>& v) {     for (int i = 0; i < (int)v.size(); i++) is >> v[i];     return is;   }   vector<string> split(const std::string& s, char delim) {     vector<string> e;     stringstream ss(s);     string item;     while (getline(ss, item, delim)) e.push_back(item);     return e;   }   long long Pow(long long a, long long b, long long Mo) {     long long ans = 1;     for (; b; b >>= 1, a = a * a % Mo)       if (b & 1) ans = ans * a % Mo;     return ans;   }   long long _div(long long a, long long b) {     return (a * Pow(b, MOD - 2, MOD)) % MOD;   }   long long nCr(long long n, long long r) {     static long long MAXF = 1e6;     static std::vector<long long> fact(MAXF, 1);     for (int i = 1; i < MAXF; ++i) fact[i] = (fact[i - 1] * i) % MOD;     MAXF = 0;     return (fact[n] * Pow((fact[r] * fact[n - r]) % MOD, MOD - 2, MOD)) % MOD;   }   vector<int> Zfunc(string& s) {     int n = s.length();     vector<int> z(n, 0);     for (int i = 1, l = 0, r = 0; i < n; i++) {       if (i <= r) z[i] = min(z[i - l], r - i + 1);       while (i + z[i] < n && s[i + z[i]] == s[z[i]]) z[i]++;       if (r < i + z[i] - 1) l = i, r = i + z[i] - 1;     }     return z;   }   string s;   int l;   std::vector<std::vector<long long> > DP;   long long getWaysAny(int c, int left) {     if (c > left) return 0;     return nCr(left, c);   }   long long getWays(int c, int takencare) {     if (takencare == l) {       if (c == 0) return 1;       return 0;     }     long long& w = DP[c][takencare];     if (w != -1) return w;     w = 0;     if (s[takencare] ==  1 ) {       if (c > 0) w = (w + getWays(c - 1, takencare + 1)) % MOD;       w = (w + getWaysAny(c, l - (takencare + 1))) % MOD;     } else {       w = (w + getWays(c, takencare + 1)) % MOD;     }     return w;   }   long long solve() {     int k;     cin >> s >> k;     l = s.length();     if (k == 0) {       return 1;     }     DP.resize(1002, std::vector<long long>(1002, -1));     if (k == 1) {       return (getWays(1, 0) + MOD - 1) % MOD;     }     long long w = 0;     for (int i = 2; i <= 1000; ++i) {       long long needk = 0;       long long i2 = i;       while (i2 > 1) {         i2 = __builtin_popcount(i2);         needk++;       }       if (needk == k - 1) {         w = (w + getWays(i, 0)) % MOD;       }     }     return w;   }   int main(int argc, char const* argv[]) {     std::ios::sync_with_stdio(false);     cin.tie(0);     cout << solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100002;   int n, m, ok[N], a, b, c, l[N], nr[N];   vector<pair<int, int>> G[N];   int p[20][N];   void parentDFS(int x, int par) {     p[0][x] = par;     l[x] = l[par] + 1;     for (auto it : G[x])       if (it.first != par) parentDFS(it.first, x);   }   int lca(int x, int y) {     if (l[x] < l[y]) swap(x, y);     for (int i = 0; i < 18; i++)       if (((l[x] - l[y]) & (1 << i))) x = p[i][x];     if (x == y) return x;     for (int i = 17; i >= 0; i--)       if (p[i][x] != p[i][y]) {         x = p[i][x];         y = p[i][y];       }     return p[0][x];   }   pair<int, int> dist[N], ans[N];   pair<int, int> maxx(pair<int, int> a, pair<int, int> b, int nod) {     if (a.first < 0) return b;     if (b.first < 0) return a;     if (a.first == b.first)       return {a.first, nod};     else       return max(a, b);   }   void dfs1(int x, int p) {     if (ok[x]) {       dist[x] = {0, x};     } else       dist[x] = {-1e9, -1};     for (auto it : G[x]) {       int u = it.first, c = it.second;       if (u == p) continue;       dfs1(u, x);       dist[x] = maxx(dist[x], {dist[u].first + c, dist[u].second}, x);     }   }   void dfs2(int x, int par, pair<int, int> sus) {     ans[x] = maxx(sus, dist[x], x);     if (ok[x]) {       int t = ans[x].second;       int L = lca(x, t);       nr[x]++;       nr[t]++;       nr[L]--;       if (p[0][L] != 0) nr[p[0][L]]--;     }     pair<int, int> aux;     if (ok[x])       aux = {0, x};     else       aux = {-1e9, -1};     vector<pair<int, int>> child;     vector<pair<int, int>> pr;     int j = 0;     for (auto it : G[x])       if (it.first != par) child.push_back(it);     for (auto it : child) {       int u = it.first, c = it.second;       pr.push_back(aux);       aux = maxx(aux, {dist[u].first + c, dist[u].second}, x);     }     for (int i = child.size() - 1; i >= 0; i--) {       int u = child[i].first;       int c = child[i].second;       pair<int, int> aux1 = maxx(sus, pr[i], x);       aux1.first += c;       dfs2(u, x, aux1);       sus = maxx(sus, {dist[u].first + c, dist[u].second}, x);     }   }   void mars(int x, int p) {     for (auto it : G[x]) {       int u = it.first;       if (u == p) continue;       mars(u, x);     }     nr[p] += nr[x];   }   int main() {     cin >> n >> m;     for (int i = 1; i <= m; i++) {       cin >> a;       ok[a] = 1;     }     for (int i = 1; i < n; i++) {       cin >> a >> b >> c;       G[a].push_back({b, c});       G[b].push_back({a, c});     }     parentDFS(1, 0);     for (int i = 1; i < 18; i++)       for (int j = 1; j <= n; j++) p[i][j] = p[i - 1][p[i - 1][j]];     dfs1(1, 0);     dfs2(1, 0, {-1e9, -1});     mars(1, 0);     int r = 0, sol = 0;     for (int i = 1; i <= n; i++) {       if (!ok[i]) {         if (sol < nr[i]) {           sol = nr[i];           r = 1;         } else if (sol == nr[i])           r++;       }     }     cout << sol <<     << r;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string A[4][102];   string M[202];   int main() {     ios_base::sync_with_stdio(false);     int n;     cin >> n;     for (int p = 0; p < 4; p++) {       for (int i = 0; i < n; i++) {         cin >> A[p][i];       }     }     vector<int> T;     for (int i = 0; i < 4; i++) T.push_back(i);     int ans = int(1e9);     do {       for (int i = 0; i < n; i++) M[i] = A[T[0]][i] + A[T[1]][i];       for (int i = n; i < 2 * n; i++) M[i] = A[T[2]][i - n] + A[T[3]][i - n];       int op1 = 0, op2 = 0;       for (int i = 0; i < 2 * n; i++) {         int sq = (i % 2) ? 1 : 0;         for (int j = 0; j < 2 * n; j++) {           if (M[i][j] -  0  != sq) op1++;           sq ^= 1;         }       }       for (int i = 0; i < 2 * n; i++) {         int sq = (i % 2) ? 0 : 1;         for (int j = 0; j < 2 * n; j++) {           if (M[i][j] -  0  != sq) op2++;           sq ^= 1;         }       }       ans = min(ans, min(op1, op2));     } while (next_permutation(T.begin(), T.end()));     cout << ans << endl;   }


#include <bits/stdc++.h>   int gi() {     int x = 0;     char ch = getchar();     while (!isdigit(ch)) {       if (ch ==  ? ) return -1;       ch = getchar();     }     while (isdigit(ch)) x = x * 10 + ch -  0 , ch = getchar();     return x;   }   bool eq(int a, int b) {     if (b == -1) return 1;     return a == b;   }   int n, D[310], L[310], Cnt[310], CNT[310], exist[310], maxdep[310];   int p[310];   int fir[610], dep[610], head[610], dis[10000010], nxt[10000010], w[10000010],       id, cnt;   int S, T, numl[310], numr[310], chain[310][310], chlen[310];   void link(int a, int b, int c) {     nxt[++id] = fir[a], fir[a] = id, dis[id] = b, w[id] = c;     nxt[++id] = fir[b], fir[b] = id, dis[id] = a, w[id] = 0;   }   int edger[310], edgelr[310][310], edgelc[310][310][310];   bool BFS() {     static int que[610], hd, tl;     hd = tl = 0;     que[tl++] = S;     memset(dep, 0, sizeof dep);     dep[S] = 1;     while (hd ^ tl) {       int x = que[hd++];       for (int i = fir[x]; i; i = nxt[i])         if (w[i] && !dep[dis[i]]) dep[dis[i]] = dep[x] + 1, que[tl++] = dis[i];     }     return dep[T];   }   int Dinic(int x, int maxflow) {     if (x == T) return maxflow;     int ret = 0;     for (int& i = head[x]; i; i = nxt[i])       if (dep[dis[i]] == dep[x] + 1 && w[i]) {         int d = Dinic(dis[i], std::min(w[i], maxflow - ret));         w[i] -= d, w[i ^ 1] += d;         ret += d;         if (ret == maxflow) break;       }     return ret;   }   std::vector<int> V[310][310];   int Get(int i, int j) {     int r = V[i][j].back();     V[i][j].pop_back();     return r;   }   int main() {     n = gi();     int maxl = 0;     for (int i = 1; i <= n; ++i) {       D[i] = gi(), L[i] = gi();       if (~L[i]) {         if (~D[i]) maxdep[L[i]] = std::max(maxdep[L[i]], D[i]);         if (D[i] == 0)           ++Cnt[L[i]];         else           exist[L[i]] = 1;       } else         maxl = std::max(maxl, D[i]);     }     for (int i = 1; i <= n; ++i) {       CNT[i] = (Cnt[i] + i - 1) / i;       if (exist[i]) CNT[i] = std::max(CNT[i], 1);     }     bool FLG = 0;     for (int o = 1; o <= n; ++o) {       cnt = 2;       S = 1, T = 2;       memset(fir, 0, sizeof fir);       id = 1;       int tot = 0;       bool flg = !CNT[o];       if (flg)         if (!FLG)           FLG = 1, CNT[o] = 1;         else           continue;       for (int i = 1; i <= n; ++i) {         int c = CNT[i] * i - Cnt[i];         if (c)           edger[i] = id + 1, link(numr[i] = ++cnt, T, c), tot += c;         else           edger[i] = -1;       }       int sum = tot;       for (int i = 1; i <= n; ++i) {         chlen[i] = std::max(o == i ? maxl : 0, maxdep[i]);         sum += chlen[i];       }       if (sum > n) {         if (flg) CNT[o] = 0;         continue;       }       for (int i = 1; i <= n; ++i) {         for (int j = 1; j <= chlen[i]; ++j)           link(chain[i][j] = ++cnt, T, 1), ++tot;       }       for (int i = 1; i <= n; ++i) {         memset(edgelr[i], -1, sizeof edgelr[i]);         memset(edgelc[i], -1, sizeof edgelc[i]);         if (D[i] == 0 && ~L[i]) continue;         link(S, numl[i] = ++cnt, 1);         if (D[i] <= 0)           for (int j = 1; j <= n; ++j)             if (numr[j] && eq(j, L[i]))               edgelr[i][j] = id + 1, link(numl[i], numr[j], 1);         if (D[i] != 0) {           for (int j = 1; j <= n; ++j)             if (eq(j, L[i]))               for (int k = 1; k <= chlen[j]; ++k)                 if (k == D[i] || D[i] == -1)                   edgelc[i][j][k] = id + 1, link(numl[i], chain[j][k], 1);         }       }       while (BFS()) memcpy(head, fir, sizeof head), tot -= Dinic(S, 1e9);       if (tot) {         if (flg) CNT[o] = 0;         continue;       }       for (int i = 1; i <= n; ++i) p[i] = -1;       for (int i = 1; i <= n; ++i) {         for (int j = 1; j <= n; ++j)           if (~edgelr[i][j] && !w[edgelr[i][j]]) L[i] = j, D[i] = 0;         for (int j = 1; j <= n; ++j)           for (int k = 1; k <= chlen[j]; ++k)             if (~edgelc[i][j][k] && !w[edgelc[i][j][k]]) L[i] = j, D[i] = k;         if (~L[i] && ~D[i]) V[D[i]][L[i]].push_back(i);       }       for (int i = 1; i <= n; ++i) {         if (!CNT[i]) continue;         static int seq[82];         while (CNT[i]--) {           for (int j = 1; j <= i; ++j) seq[j] = Get(0, i);           seq[0] = seq[i];           for (int j = 1; j <= i; ++j) p[seq[j - 1]] = seq[j];         }         for (int j = 1; j <= chlen[i]; ++j) seq[j] = Get(j, i);         for (int j = 1; j <= chlen[i]; ++j) p[seq[j]] = seq[j - 1];         for (int j = 1; j <= n; ++j)           if (p[j] == -1 && D[j] && eq(i, L[j]) && chlen[i] >= D[j] - 1)             p[j] = seq[std::max(0, D[j] - 1)];       }       for (int i = 1; i <= n; ++i) printf( %d  , ~p[i] ? p[i] : i);       exit(0);     }     puts( -1 );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     while (n--) {       string s, t;       cin >> s >> t;       std::map<char, bool> ms, mt;       for (int i = 0; i < s.size(); i++) {         ms[s[i]] = true;         mt[t[i]] = true;       }       for (char x =  a ; x <=  z ; x++)         if (ms[x] && mt[x]) {           cout <<  YES ;           goto flag;         }       cout <<  NO ;     flag:       cout << endl;       ;     }   }


#include<bits/stdc++.h>   using namespace std;   #define ll long long   #define endl   n    #define pb push_back   const ll INF=1e18+10;      void solve()   {       ll n,m;       cin>>n>>m;       string s;       cin>>s;       string p=s;       while(m--)       {           s=p;           for(ll i=0;i<n;i++)           {               if(p[i]== 1 ) continue;               else{               if(i==0)               {                  // cout<< YES <<endl;                   if(s[i+1]== 1 ) p[i]= 1 ;                   else p[i]= 0 ;                   //cout<<p[i]<<endl;               }              else if(i==n-1)               {                   if(s[i-1]== 1 ) p[i]= 1 ;                   else p[i]= 0 ;               }               else               {                   if((s[i-1]== 1 &&s[i+1]== 0 )||(s[i+1]== 1 &&s[i-1]== 0 )) p[i]= 1 ;                   else p[i]= 0 ;               }           }           }           if(p==s) break;       }          cout<<p<<endl;      // cout<<p[0]<<endl;      }   int main()   {       ios::sync_with_stdio(0);       cin.tie(0);       ll t;       t=1;      cin>>t;       while(t--)       {           solve();       }   }


#include <bits/stdc++.h>   using namespace std;   const int MX = 200005;   const int MD = 998244353;   void add(int& a, int b) {     a += b;     if (a >= MD) a -= MD;   }   void sub(int& a, int b) {     a -= b;     if (a < 0) a += MD;   }   int mod_sum(int a, int b) {     a += b;     if (a >= MD) a -= MD;     return a;   }   int mod_mult(long long a, long long b) { return (a * b) % MD; }   int exp(int a, int b) {     int res = 1;     while (b) {       if (b & 1) res = mod_mult(res, a);       a = mod_mult(a, a);       b /= 2;     }     return res;   }   int inv(int a) { return exp(a, MD - 2); }   int p[MX];   struct DATA {     int s, m;   };   DATA recalc(DATA L, DATA R) {     DATA res;     res.m = mod_mult(L.m, R.m);     res.s = mod_sum(mod_mult(L.s, R.m), R.s);     return res;   }   struct {     int L, R;     int pl, pr;     DATA d;   } T[2 * MX];   int tsz = 0;   int buildTree(int L, int R) {     int cur = tsz++;     T[cur].L = L;     T[cur].R = R;     if (L < R) {       T[cur].pl = buildTree(L, (L + R) / 2);       T[cur].pr = buildTree((L + R) / 2 + 1, R);       T[cur].d = recalc(T[T[cur].pl].d, T[T[cur].pr].d);     } else {       T[cur].d.m = inv(p[L]);       T[cur].d.s = inv(p[L]);     }     return cur;   }   DATA get(int L, int R, int cur) {     if (L <= T[cur].L && R >= T[cur].R) return T[cur].d;     DATA d;     bool any = false;     if (L <= T[T[cur].pl].R) {       d = get(L, R, T[cur].pl);       any = true;     }     if (R >= T[T[cur].pr].L) {       DATA tmp = get(L, R, T[cur].pr);       if (any)         d = recalc(d, tmp);       else         d = tmp;     }     return d;   }   int main() {     int n, q;     ignore = scanf( %d %d , &n, &q);     int inv_100 = inv(100);     for (int i = 1; i <= n; i++) {       ignore = scanf( %d , p + i);       p[i] = mod_mult(p[i], inv_100);     }     int rt = buildTree(1, n);     int res = T[rt].d.s;     set<int> toggled;     toggled.insert(1);     toggled.insert(n + 1);     while (q--) {       int i;       ignore = scanf( %d , &i);       if (!toggled.count(i)) {         int L = *prev(toggled.lower_bound(i));         int R = *toggled.lower_bound(i) - 1;         DATA LL = get(L, i - 1, rt);         DATA RR = get(i, R, rt);         sub(res, recalc(LL, RR).s);         add(res, LL.s);         add(res, RR.s);         toggled.insert(i);       } else {         toggled.erase(i);         int L = *prev(toggled.lower_bound(i));         int R = *toggled.lower_bound(i) - 1;         DATA LL = get(L, i - 1, rt);         DATA RR = get(i, R, rt);         add(res, recalc(LL, RR).s);         sub(res, LL.s);         sub(res, RR.s);       }       printf( %d n , res);     }   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 200100;   const long long INF = 0x3f3f3f3f3f3f3f3f;   long long d[MAXN], h[MAXN];   long long sd[MAXN];   struct str {     long long pfx, sfx, rnode, l, r;   };   struct st {     st *fe, *fd;     long long l, r, meio, pfx, sfx, rnode;     st(long long x, long long y) {       meio = (x + y) / 2;       pfx = sfx = rnode = 0;       l = x, r = y;       if (x == y) return;       fe = new st(x, meio);       fd = new st(meio + 1, y);     }     st(st *node) {       fe = node->fe;       fd = node->fd;       rnode = node->rnode;       pfx = node->pfx;       sfx = node->sfx;       l = node->l;       r = node->r;     }     void update(long long pos, long long novo) {       if (l == r) {         pfx = sfx = rnode = 2 * novo;         return;       }       if (pos <= meio)         fe->update(pos, novo);       else         fd->update(pos, novo);       pfx = max(fe->pfx, sd[fe->r] - sd[fe->l - 1] + fd->pfx);       sfx = max(fd->sfx, sd[fd->r - 1] - sd[fd->l - 1] + d[fe->r] + fe->sfx);       rnode = max(fe->rnode, max(fd->rnode, fe->sfx + fd->pfx + d[fe->r]));     }     str get(long long a, long long b) {       if (l >= a && r <= b) {         str resp;         resp.pfx = pfx;         resp.sfx = sfx;         resp.rnode = rnode;         resp.l = l;         resp.r = r;         return resp;       }       if (l > b || r < a) {         str at;         at.rnode = -INF;         at.pfx = -INF;         at.sfx = -INF;         return at;       }       str left = fe->get(a, b), right = fd->get(a, b);       str resp;       bool flag = false;       if (left.rnode < 0)         resp = right, flag = true;       else if (right.rnode < 0)         resp = left, flag = true;       if (flag == true) {         return resp;       }       resp.pfx = max(left.pfx, sd[left.r] - sd[left.l - 1] + right.pfx);       resp.sfx = max(right.sfx,                      sd[right.r - 1] - sd[right.l - 1] + d[left.r] + left.sfx);       resp.rnode =           max(left.rnode, max(right.rnode, left.sfx + right.pfx + d[left.r]));       resp.l = left.l, resp.r = right.r;       return resp;     }   };   st arvore(1, MAXN);   signed main() {     memset(sd, 0, sizeof sd);     long long n, q;     cin >> n >> q;     for (long long i = 1; i <= n; i++) cin >> d[i];     for (long long i = 1; i <= n; i++) cin >> h[i];     sd[0] = 0;     for (long long i = n + 1; i <= 2 * n; i++) d[i] = d[i - n], h[i] = h[i - n];     for (long long i = 1; i <= 2 * n; i++) sd[i] = sd[i - 1] + d[i];     for (long long i = 1; i <= 2 * n; i++) arvore.update(i, h[i]);     for (long long i = 1; i <= q; i++) {       long long x, y;       cin >> x >> y;       if (x > y)         cout << arvore.get(y + 1, x - 1).rnode << endl;       else         cout << arvore.get(y + 1, x + n - 1).rnode << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int n;   map<int, int, greater<int> > g;   int a;   int gcd(int a, int b) {     while (b != 0) {       a %= b;       swap(a, b);     }     return a;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     ;     cin >> n;     for (int(i) = (0); (i) < int(n * n); ++(i)) {       cin >> a;       g[a]++;     }     vector<int> ans;     while (1) {       bool done = 0;       for (auto& x : g) {         if (x.second <= 0) continue;         x.second--;         done = 1;         for (auto every : ans) {           g[gcd(every, x.first)] -= 2;         }         ans.push_back(x.first);         g[x.first]--;         break;       }       if (!done) break;     }     for (auto y : ans) cout << y <<    ;     cin.sync();     cin.get();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<pair<int, int> > ans;   int a[305], b[305], n;   int cur[305];   map<int, vector<int> > m;   int main() {     ios_base::sync_with_stdio(0);     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < n; i++) cin >> b[i];     for (int i = 0; i < n; i++) {       m[a[i]].push_back(i);     }     for (auto &x : m) reverse(x.second.begin(), x.second.end());     for (int i = 0; i < n; i++) {       cur[i] = m[b[i]].back();       m[b[i]].pop_back();     }     for (int i = 0; i < n; i++)       if (1) cerr << cur[i] <<    ;     if (1) cerr <<   n ;     for (int i = 0; i < n; i++)       for (int j = 0; j < n - 1; j++) {         if (cur[j] > cur[j + 1]) {           ans.push_back({j + 1, j + 2});           swap(cur[j], cur[j + 1]);         }       }     cout << ans.size() <<   n ;     for (auto x : ans) cout << x.first <<     << x.second <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   long long a, b;   long long remove(long long a) {     long long temp = 0L;     int tens = 1;     while (a) {       if (a % 10) {         temp += tens * (a % 10);         tens *= 10;       }       a /= 10;     }     return temp;   }   int main() {     cin >> a >> b;     long long c = a + b;     a = remove(a);     b = remove(b);     c = remove(c);     if (a + b == c)       cout <<  YES ;     else       cout <<  NO ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     int lens = s.length();     s =     + s;     s = s +    ;     int minn = -1;     int a[10000] = {0};     a[0] = 0;     int p = 1;     for (int i = 0; i <= lens + 1; i++) {       if (s[i] ==  A  || s[i] ==  E  || s[i] ==  I  || s[i] ==  O  ||           s[i] ==  U  || s[i] ==  Y ) {         a[p++] = i;       }     }     a[p++] = lens + 1;     for (int i = 0; i < p; i++) {       a[i] = a[i + 1] - a[i];       minn = max(a[i], minn);     }     cout << minn << endl;   }


#include <bits/stdc++.h>   using namespace std;   namespace std {   template <>   struct hash<pair<int, int> > {     size_t operator()(const pair<int, int>& x) const {       long long P = 38923, Q = 109797901;       return (size_t)((x.first * P + x.second) % Q);     }   };   };  // namespace std   template <class T>   using pqg = priority_queue<T, vector<T>, greater<T> >;   template <typename T, typename second>   ostream& operator<<(ostream& os, const pair<T, second>& v) {     os <<  (  << v.first <<  ,   << v.second <<  ) ;     return os;   }   template <typename T>   void print(T t) {     cout << t << endl << flush;   }   template <typename T, typename... Args>   void print(T t, Args... args) {     cout << t <<    ;     print(args...);   }   int main() {     int T;     cin >> T;     for (auto t = 0; t < T; t += 1) {       int n;       cin >> n;       vector<int> a(n);       long long A, B;       A = 0;       B = 0;       for (auto i = 0; i < n; i += 1) {         cin >> a[i];         A += a[i];         B ^= a[i];       }       print(2);       print(B, A + B);     }   }


#include <bits/stdc++.h>   int main() {     std::string first, last, create =  fffffffffffff ;     int let = 1;     std::cin >> first >> last;     create[0] = first[0];     int size = first.size();     for (int i = 1; i < size; i++) {       if (first[i] < last[0]) {         create[let] = first[i];         let++;       } else         break;     }     create[let] = last[0];     create = create.substr(0, let + 1);     std::cout << create;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, x, y, z, a[200005], o, X, Y, Z, XY, XZ, YZ;   bool ok(int t) {     X = Y = Z = XY = XZ = YZ = 0;     for (int i = o; i; i--) {       if (X + XY + XZ < t && a[i] <= x)         X++;       else if (Y + XY + YZ < t && a[i] <= y)         Y++;       else if (Z + XZ + YZ < t && a[i] <= z)         Z++;       else if (X + Y + XY + XZ + YZ < t && a[i] <= x + y)         XY++;       else if (X + Z + XY + XZ + YZ < t && a[i] <= x + z)         XZ++;       else if (Y + Z + XY + XZ + YZ < t && a[i] <= y + z)         YZ++;       else         return 0;     }     return 1;   }   int main() {     scanf( %d%d%d%d , &n, &x, &y, &z);     for (int i = 1; i <= n; i++) scanf( %d , a + i);     sort(a + 1, a + n + 1);     if (a[n] > x + y + z) {       printf( -1 n );       return 0;     }     if (x > y) swap(x, y);     if (x > z) swap(x, z);     if (y > z) swap(y, z);     o = n;     while (a[o] > y + z && o) o--;     int l = 0, r = o + 5;     while (r - l > 1) {       int m = (l + r) >> 1;       if (ok(m))         r = m;       else         l = m;     }     l -= 3;     while (!ok(l)) l++;     printf( %d n , n - o + l);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1510;   int n, arr[N], m;   int main() {     scanf( %d , &n);     int ans = 0;     for (int i = 0; i < n; i++) {       scanf( %d , &arr[i]);       for (int j = 0; j < i; j++) {         if (arr[i] < arr[j]) ans ^= 1;       }     }     scanf( %d , &m);     while (m--) {       int l, r;       scanf( %d%d , &l, &r);       int cur = (r - l) * (r - l + 1) / 2;       ans ^= (cur & 1);       if (!ans)         puts( even );       else         puts( odd );     }     return 0;   }


#include  bits/stdc++.h    using namespace std;   #define pb                push_back   #define ppb               pop_back   #define pf                push_front   #define ppf               pop_front   #define all(x)            (x).begin(),(x).end()   #define uniq(v)           (v).erase(unique(all(v)),(v).end())   #define sz(x)             (int)((x).size())   #define fr                first   #define sc                second   #define pii               pair<int,int>   #define rep(i,a,b)        for(int i=a;i<b;i++)   #define mem1(a)           memset(a,-1,sizeof(a))   #define mem0(a)           memset(a,0,sizeof(a))   #define ppc               __builtin_popcount   #define ppcll             __builtin_popcountll      template<typename T1,typename T2>istream& operator>>(istream& in,pair<T1,T2> &a){in>>a.fr>>a.sc;return in;}   template<typename T1,typename T2>ostream& operator<<(ostream& out,pair<T1,T2> a){out<<a.fr<<   <<a.sc;return out;}   template<typename T,typename T1>T amax(T &a,T1 b){if(b>a)a=b;return a;}   template<typename T,typename T1>T amin(T &a,T1 b){if(b<a)a=b;return a;}      const long long INF=1e18;   const int32_t M=998244353;      const int N=1005;      string x,y;   int dp[N][N][3][4];      int calc(int a,int b,int last,int started){    if(dp[a][b][last][started] != -1){     return dp[a][b][last][started];    }    int ans = (started == 3);    char pc;    if(last == 2){     pc =  z  + 1;    }    else{     pc = ((last == 0)?x[a-1]:y[b-1]);    }        if(a < sz(x) && x[a] != pc){     ans = (ans + calc(a+1,b,0,started | 1)) % M;    }        if(b < sz(y) && y[b] != pc){     ans = (ans + calc(a,b+1,1,started | 2)) % M;    }    return dp[a][b][last][started] = ans;   }      void solve(){    mem1(dp);    cin >> x >> y;        int ans = 0;    rep(i,0,sz(x)){     rep(j,0,sz(y)){            ans = (ans + calc(i,j,2,0)) % M;     }    }    cout << ans <<   n ;   }   signed main(){    ios_base::sync_with_stdio(false);    cin.tie(0);cout.tie(0);    //freopen( input.txt ,  r , stdin);    //freopen( output.txt ,  w , stdout);    #ifdef SIEVE     sieve();    #endif    #ifdef NCR     init();    #endif    int t=1;    //cin>>t;    while(t--) solve();    return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n, t;       cin >> n >> t;       vector<int> arr(n);       for (int i = 0; i < n; i++) {         cin >> arr[i];         if (arr[i] == 0 || arr[i] == t) continue;         arr[i] %= t;       }       set<int> s;       set<int>::iterator it;       bool selected = false;       vector<int> color(n);       for (int i = 0; i < n; i++) {         if (t % 2 == 0 && arr[i] == t / 2) {           color[i] = selected;           selected = !selected;         } else {           int opp = t - arr[i];           if (s.find(opp) == s.end()) {             color[i] = 0;             s.insert(arr[i]);           } else {             color[i] = 1;           }         }       }       for (int i = 0; i < n; i++) cout << color[i] <<    ;       cout <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long i, T, n;     cin >> T;     while (T--) {       double h, c, t, ans;       cin >> h >> c >> t;       double res = h, freq = 1.0, diff = fabs(((h + c) / 2) - t);       if (h == t) {         cout << 1 <<   n ;         continue;       }       if ((h + c) / 2 >= t) {         cout << 2 <<   n ;         continue;       }       freq = 1 + 2 * ceil((t - h) / (h + c - 2 * t));       double freq2 = freq - 2;       if (fabs((h + (h + c) * ((freq - 1) / 2)) / (freq)-t) <           fabs((h + (h + c) * ((freq2 - 1) / 2)) / (freq2)-t)) {         if (diff < fabs((h + (h + c) * (freq / 2)) / (1 + freq) - t)) {           cout << 2 <<   n ;         } else {           cout << freq <<   n ;         }       } else {         if (diff < fabs((h + (h + c) * (freq2 / 2)) / (1 + freq2) - t)) {           cout << 2 <<   n ;         } else {           cout << freq2 <<   n ;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int compare(const void* a, const void* b) {     return ((*(pair<long long, long long>*)a).first -             (*(pair<long long, long long>*)b).first);   }   string alfabet =  abcdefghijklmnopqrstuvwxyz ;   int main() {     long long n, x1, x2, k, b;     cin >> n;     cin >> x1 >> x2;     vector<pair<double, double> > lines;     pair<double, double> line;     for (int i = 0; i < n; ++i) {       cin >> k >> b;       line.first = k * x1 + b;       line.second = k * x2 + b;       lines.push_back(line);     }     sort(lines.begin(), lines.end());     for (int i = 0; i < n - 1; ++i) {       if (lines[i].second > lines[i + 1].second &&           lines[i].first != lines[i + 1].first) {         cout <<  YES ;         return 0;       }     }     cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /stack:200000000 )   #pragma GCC optimize( unroll-loops )   using namespace std;   template <class T>   inline T bigmod(T p, T e, T M) {     long long ret = 1;     for (; e > 0; e >>= 1) {       if (e & 1) ret = (ret * p) % M;       p = (p * p) % M;     }     return (T)ret;   }   template <class T>   inline T gcd(T a, T b) {     if (b == 0) return a;     return gcd(b, a % b);   }   template <class T>   inline T modinverse(T a, T M) {     return bigmod(a, M - 2, M);   }   template <class T>   inline T lcm(T a, T b) {     a = abs(a);     b = abs(b);     return (a / gcd(a, b)) * b;   }   template <class T, class X>   inline bool getbit(T a, X i) {     T t = 1;     return ((a & (t << i)) > 0);   }   template <class T, class X>   inline T setbit(T a, X i) {     T t = 1;     return (a | (t << i));   }   template <class T, class X>   inline T resetbit(T a, X i) {     T t = 1;     return (a & (~(t << i)));   }   inline long long getnum() {     char c = getchar();     long long num, sign = 1;     for (; c <  0  || c >  9 ; c = getchar())       if (c ==  - ) sign = -1;     for (num = 0; c >=  0  && c <=  9 ;) {       c -=  0 ;       num = num * 10 + c;       c = getchar();     }     return num * sign;   }   inline long long power(long long a, long long b) {     long long multiply = 1;     for (int i = (0); i < (b); i++) {       multiply *= a;     }     return multiply;   }   struct MagicComponents {     struct edge {       long long u, v, id;     };     long long num, n, edges;     vector<long long> dfs_num, low, vis;     vector<long long> cuts;     vector<edge> bridges;     vector<vector<edge>> adj;     vector<vector<edge>> bccs;     deque<edge> e_stack;     MagicComponents(const long long& _n) : n(_n) {       adj.assign(n, vector<edge>());       edges = 0;     }     void add_edge(const long long& u, const long long& v) {       adj[u].push_back({u, v, edges});       adj[v].push_back({v, u, edges++});     }     void run(void) {       vis.assign(n, 0);       dfs_num.assign(n, 0);       low.assign(n, 0);       bridges.clear();       cuts.clear();       bccs.clear();       e_stack = deque<edge>();       num = 0;       for (long long i = 0; i < n; ++i) {         if (vis[i]) continue;         dfs(i, -1);       }     }     void dfs(const long long& node, const long long& par) {       dfs_num[node] = low[node] = num++;       vis[node] = 1;       long long n_child = 0;       for (edge& e : adj[node]) {         if (e.v == par) continue;         if (vis[e.v] == 0) {           ++n_child;           e_stack.push_back(e);           dfs(e.v, node);           low[node] = min(low[node], low[e.v]);           if (low[e.v] >= dfs_num[node]) {             if (dfs_num[node] > 0 || n_child > 1) cuts.push_back(node);             if (low[e.v] > dfs_num[node]) {               bridges.push_back(e);               pop(node);             } else               pop(node);           }         } else if (vis[e.v] == 1) {           low[node] = min(low[node], dfs_num[e.v]);           e_stack.push_back(e);         }       }       vis[node] = 2;     }     void pop(const long long& u) {       vector<edge> list;       for (;;) {         edge e = e_stack.back();         e_stack.pop_back();         list.push_back(e);         if (e.u == u) break;       }       bccs.push_back(list);     }   };   int n, m, q;   vector<int> bcc_nodes[100005], tree[100005 * 2];   int L[2 * 100005], table[2 * 100005][19];   void buildTree(int sz, int& _n) {     for (int i = (0); i < (sz); i++) {       _n++;       for (auto it : bcc_nodes[i]) {         tree[_n].push_back(it);         tree[it].push_back(_n);       }     }   }   int query(int p, int q) {     if (L[p] < L[q]) swap(p, q);     int x = 1;     while (true) {       if ((1 << (x + 1)) > L[p]) break;       x++;     }     for (int i = (x); i >= (0); i--) {       if (L[p] - (1 << i) >= L[q]) p = table[p][i];     }     if (p == q) return p;     for (int i = (x); i >= (0); i--) {       if (table[p][i] != -1 && table[p][i] != table[q][i]) {         p = table[p][i];         q = table[q][i];       }     }     return table[p][0];   }   void dfs2(int u, int p = -1, int d = 0) {     L[u] = d;     table[u][0] = p;     for (auto v : tree[u]) {       if (v == p) continue;       dfs2(v, u, d + 1);     }   }   void build(int _n) {     memset(table, -1, sizeof(table));     dfs2(1);     for (int j = 1; 1 << j < _n; j++) {       for (int i = 1; i <= _n; i++) {         if (table[i][j - 1] != -1) table[i][j] = table[table[i][j - 1]][j - 1];       }     }   }   int getdist(int u, int v) {     int lca = query(u, v);     int ret = L[u] + L[v] - 2 * L[lca];     return ret;   }   int main() {     int test, cases = 1;     scanf( %d%d%d , &n, &m, &q);     MagicComponents magic(n + 2);     int u, v;     for (int i = (0); i < (m); i++) {       scanf( %d%d , &u, &v);       magic.add_edge(u, v);     }     magic.run();     int sz = magic.bccs.size();     for (int i = (0); i < (sz); i++) {       for (auto it : magic.bccs[i]) {         bcc_nodes[i].push_back(it.u);         bcc_nodes[i].push_back(it.v);       }       sort(bcc_nodes[i].begin(), bcc_nodes[i].end());       bcc_nodes[i].erase(unique(bcc_nodes[i].begin(), bcc_nodes[i].end()),                          bcc_nodes[i].end());     }     int _n = n;     buildTree(sz, _n);     build(_n);     while (q--) {       scanf( %d%d , &u, &v);       int out = getdist(u, v);       printf( %d n , out / 2);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct BIT {     int bit[200005];     void init() { memset(bit, 0, sizeof(bit)); }     void add(int k, int x) {       k++;       while (k < 200005) {         bit[k] += x;         k += k & -k;       }     }     int get(int k) {       k++;       int ret = 0;       while (k > 0) {         ret += bit[k];         k -= k & -k;       }       return ret;     }     int get(int s, int t) { return get(t) - get(s - 1); }   };   BIT bit[3];   set<int> st[3];   set<int>::iterator it;   int A[200005];   char str[200005];   int n;   int ctoi(char c) {     if (c ==  R ) return 0;     if (c ==  P ) return 1;     if (c ==  S ) return 2;     return -1;   }   int get(int l, int r, int c) {     l = max(l, 0);     r = min(r, n - 1);     if (l > r) return 0;     return bit[c].get(l, r);   }   void rm(int v) {     st[A[v]].erase(v);     bit[A[v]].add(v, -1);   }   void ins(int v) {     st[A[v]].insert(v);     bit[A[v]].add(v, 1);   }   int query() {     int ret = 0;     for (int i = 0; i < 3; i++) {       int x = i, y = i + 1, z = i - 1;       if (z < 0) z += 3;       if (y >= 3) y -= 3;       int my = n, mz = n;       it = st[y].begin();       if (it != st[y].end()) my = *it;       it = st[z].begin();       if (it != st[z].end()) mz = *it;       int My = -1, Mz = -1;       it = st[y].end();       if (it != st[y].begin()) {         it--;         My = *it;       }       it = st[z].end();       if (it != st[z].begin()) {         it--;         Mz = *it;       }       ret += st[x].size();       if (my < mz) {         if (Mz < My) {           if (mz < Mz) {             ret -= get(my, mz, x);             ret -= get(Mz, My, x);           } else {             ret -= get(min(my, Mz), max(mz, My), x);           }         } else {           ret -= get(my, mz, x);         }       } else if (Mz < My) {         ret -= get(Mz, My, x);       }     }     return ret;   }   int main() {     int Q;     scanf( %d %d , &n, &Q);     scanf( %s , &str);     for (int i = 0; i < 3; i++) bit[i].init();     for (int i = 0; i < n; i++) {       A[i] = ctoi(str[i]);       ins(i);     }     printf( %d n , query());     while (Q--) {       int t;       scanf( %d %s , &t, &str);       t--;       rm(t);       A[t] = ctoi(str[0]);       ins(t);       printf( %d n , query());     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e3 + 5;   struct edge {     int to, w, next;   } G[maxn * maxn];   struct node {     int x1, y1, x2, y2, id;   } nd[maxn];   long long bit[maxn][maxn], ans[maxn];   int n, m, k, q, head[maxn], tot;   vector<int> vec[maxn];   char s[10];   void init(int n) {     memset(head, -1, sizeof(head));     memset(bit, 0, sizeof(bit));     for (int i = 1; i <= n; ++i) vec[i].clear();     tot = 0;   }   void addedge(int u, int v, int w) {     G[tot].to = v;     G[tot].w = w;     G[tot].next = head[u];     head[u] = tot++;   }   void update(int x, int y, int v) {     while (x <= n) {       for (int i = y; i <= m; i += i & -i) {         bit[x][i] += v;       }       x += x & -x;     }   }   long long query(int x, int y) {     long long ret = 0;     while (x) {       for (int i = y; i; i -= i & -i) {         ret += bit[x][i];       }       x -= x & -x;     }     return ret;   }   int myhash(int x, int y) { return x * (m + 1) + y; }   int main() {     scanf( %d%d%d , &n, &m, &k);     init(n);     for (int i = 1; i <= k; ++i) {       int l;       scanf( %d , &l);       for (int j = 0; j < l; ++j) {         int x, y, w;         scanf( %d%d%d , &x, &y, &w);         addedge(i, myhash(x, y), w);       }     }     scanf( %d , &q);     int cnt = 0;     for (int i = 0; i < q; ++i) {       scanf( %s , s);       if (*s ==  S ) {         int o;         scanf( %d , &o);         vec[o].push_back(i);       } else {         scanf( %d%d%d%d , &nd[cnt].x1, &nd[cnt].y1, &nd[cnt].x2, &nd[cnt].y2);         nd[cnt].id = i;         ans[cnt++] = 0;       }     }     for (int i = 1; i <= k; ++i) {       int on = 1;       for (int j = head[i]; ~j; j = G[j].next) {         edge e = G[j];         int x = e.to / (m + 1), y = e.to % (m + 1);         update(x, y, e.w);       }       for (int j = 0, l = 0; j < cnt; ++j) {         while (l < vec[i].size() && vec[i][l] < nd[j].id) {           on ^= 1;           ++l;         }         if (on)           ans[j] += query(nd[j].x2, nd[j].y2) - query(nd[j].x1 - 1, nd[j].y2) -                     query(nd[j].x2, nd[j].y1 - 1) +                     query(nd[j].x1 - 1, nd[j].y1 - 1);       }       for (int j = head[i]; ~j; j = G[j].next) {         edge e = G[j];         int x = e.to / (m + 1), y = e.to % (m + 1);         update(x, y, -e.w);       }     }     for (int i = 0; i < cnt; ++i) printf( %I64d n , ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char s[200005], c;   int a[200005];   int ans[26];   int main() {     int n, k;     int maxn = 0;     cin >> n >> k;     for (int i = 0; i < n; i++) cin >> s[i];     for (int i = 0; i < n; i++) {       if (s[i] == s[i - 1])         a[i] = a[i - 1] + 1;       else         a[i] = 1;     }     for (int i = 0; i < n; i++) {       if (a[i] != 0 && a[i] % k == 0) ans[(int)s[i] -  a ]++;     }     for (int i = 0; i <= 25; i++) maxn = max(maxn, ans[i]);     printf( %d , maxn);     return 0;   }


#include <bits/stdc++.h>   typedef struct {     int u, v, w;   } Edge;   int n;   int e;   Edge edges[100 * 99];   int d[100];   void bf(int s) {     int i, j;     for (i = 0; i < n; ++i) d[i] = 1000000000;     d[s] = 0;     for (i = 0; i < n - 1; ++i)       for (j = 0; j < e; ++j)         if (d[edges[j].u] + edges[j].w < d[edges[j].v])           d[edges[j].v] = d[edges[j].u] + edges[j].w;   }   int abs(int v) { return v < 0 ? -v : v; }   int a[100];   int cord[100][2];   int main() {     int c;     scanf( %d %d , &n, &c);     for (int i = 1; i <= n - 2; ++i) {       scanf( %d , &a[i]);     }     for (int i = 0; i < n; ++i) {       scanf( %d %d , &cord[i][0], &cord[i][1]);     }     int ei = 0;     for (int i = 0; i < n; ++i) {       for (int j = 0; j < n; ++j) {         if (i == j) continue;         Edge ed;         ed.u = i;         ed.v = j;         ed.w = abs(cord[i][0] - cord[j][0]) + abs(cord[i][1] - cord[j][1]);         ed.w *= c;         ed.w -= a[j];         edges[ei++] = ed;       }     }     e = n * (n - 1);     bf(0);     printf( %d n , d[n - 1]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t, s, q, rel_dist, time;     cin >> t >> s >> q;     int starts = 1;     rel_dist = s;     while (rel_dist * q < t) {       rel_dist = rel_dist * q;       starts++;     }     cout << starts << endl;     return 0;   }


#include <bits/stdc++.h>   const int inf = INT_MAX;   const int MAX = 1e5 + 8;   const long long MOD = 1e9 + 7;   const int TOT_PRIMES = 1e6 + 9;   const int MAX_A = 71;   const int LN = 20;   using namespace std;   bool prime[MAX];   void precompute() {     memset(prime, false, sizeof(prime));     for (int i = 2; i < MAX; i++) {       if (!prime[i]) {         for (int j = 2 * i; j < MAX; j += i) prime[j] = true;       }     }   }   int a[60][60], b[60][60];   int main() {     int n;     vector<long long> dif;     cin >> n;     long long ans = 0;     for (int i = 0; i < n; i++) {       long long x, y;       cin >> x >> y;       dif.push_back(x - y);       ans = ans + (n * y - x);     }     sort(dif.begin(), dif.end());     for (int i = n - 1; i >= 0; i--) {       ans = ans + (dif[n - i - 1] * (i + 1));     }     cout << ans;   }


#include <bits/stdc++.h>   char str[100010], out[100010], visited[100010];   int n, m, len, ar[100010], counter[256], tree[100010];   void update(int p, int v) {     p++;     while (p <= n) {       tree[p] += v;       p += (p & (-p));     }   }   int query(int p) {     int res = 0;     while (p) {       res += tree[p];       p ^= (p & (-p));     }     return res;   }   int range_query(int l, int r) {     l++, r++;     if (l > r) return 0;     return (query(r) - query(--l));   }   int main() {     int i, j, k, l, c, res, flag;     while (scanf( %d , &m) != EOF) {       scanf( %s , str);       n = strlen(str);       memset(counter, 0, sizeof(counter));       memset(tree, 0, sizeof(tree));       for (i = 0; i < n; i++) counter[str[i]]++;       for (c =  a ; c <=  z ; c++) {         for (i = 0; i < n; i++) {           if (str[i] == c) update(i, 1);         }         flag = 1;         for (i = 0; (i + m) <= n; i++) {           if (range_query(i, i + m - 1) == 0) {             flag = 0;             break;           }         }         if (flag) break;       }       for (i = 0, len = 0; i < n; i++) {         if (str[i] == c) {           update(i, -1);           ar[len++] = i;         }       }       res = 0;       memset(visited, 0, sizeof(visited));       for (i = 0, j = 0; (i + m) <= n; i++) {         if (range_query(i, i + m - 1) == 0) {           k = -1;           while (j < len) {             if ((ar[j] + m - 1) < i)               j++;             else {               if (ar[j] > (i + m - 1)) break;               k = j++;             }           }           assert(k != -1);           visited[k] = 1;           update(ar[k], 1);         }       }       for (i = 0; i < 100010; i++) res += visited[i];       len = 0;       for (i =  a ; i < c; i++) {         for (j = 0; j < counter[i]; j++) {           out[len++] = i;         }       }       for (i = 0; i < res; i++) out[len++] = c;       out[len] = 0;       puts(out);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> g[201010];   int tin[201010], tout[201010];   int n, a[201010], m, timer;   int is[201010], lvl[201010];   void dfs(int v) {     tin[v] = ++timer;     for (auto to : g[v])       if (!tin[to]) {         lvl[to] = lvl[v] ^ 1;         dfs(to);       }     tout[v] = timer;   }   int t[2][801010];   void upd(int l, int r, int x, bool tp, int v = 1, int tl = 1, int tr = n) {     if (tl > r || tr < l) return;     if (tl >= l && tr <= r) {       t[tp][v] += x;       t[tp ^ 1][v] -= x;       return;     }     int tm = (tl + tr) / 2;     upd(l, r, x, tp, v * 2, tl, tm);     upd(l, r, x, tp, v * 2 + 1, tm + 1, tr);   }   int get(int x, bool tp, int v = 1, int tl = 1, int tr = n) {     if (tl == tr) return t[tp][v];     int tm = (tl + tr) / 2;     if (x <= tm)       return t[tp][v] + get(x, tp, v * 2, tl, tm);     else       return t[tp][v] + get(x, tp, v * 2 + 1, tm + 1, tr);   }   int main() {     cin >> n >> m;     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = 1, u, v; i < n; i++) {       cin >> u >> v;       g[v].push_back(u);       g[u].push_back(v);     }     dfs(1);     for (int i = 1, x, val, tt; i <= m; i++) {       cin >> tt >> x;       if (tt == 2) {         cout << a[x] + get(tin[x], lvl[x]) <<   n ;         continue;       }       cin >> val;       upd(tin[x], tout[x], val, lvl[x]);     }   }


#include <bits/stdc++.h>   int d[1005], vis[1005];   int main() {     int flag = 0;     int n;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d , &d[i]);       vis[d[i]]++;     }     int ans = 0;     for (int i = 1; i <= 100; i++) {       if (vis[i] == 1) {         ans++;       }       if (vis[i] >= 3) {         flag = 1;       }     }     if (!(ans & 1)) {       puts( YES );       int g = 0;       for (int i = 0; i < n; i++) {         if (vis[d[i]] == 1 && g) {           putchar( A );         } else {           putchar( B );         }         if (vis[d[i]] == 1) {           g ^= 1;         }       }       puts(  );       return 0;     }     if (flag == 0) {       puts( NO );       return 0;     }     puts( YES );     int cnt = 0, f = 0;     for (int i = 0; i < n; i++) {       if (cnt < (ans >> 1) && vis[d[i]] == 1) {         putchar( B );         cnt++;       } else if (vis[d[i]] >= 3 && f == 0) {         putchar( B );         f = 1;       } else {         putchar( A );       }     }     puts(  );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int len = 6020;   int SIZE;   const int inf = (int)1e9;   int n;   vector<int> in;   vector<vector<int>> g;   int flow[len][len], cost[len][len], pot[len];   int get_p(int u, int v) { return cost[u][v] + pot[u] - pot[v]; }   int add_path(int from, int to) {     vector<int> dist(SIZE, (int)1e9), prv(SIZE);     vector<bool> check(SIZE, false);     dist[from] = 0;     check[from] = true;     priority_queue<pair<int, int>> q;     q.push(make_pair(0, from));     while (!q.empty()) {       auto tmp = q.top();       tmp.first *= -1;       q.pop();       if (dist[tmp.second] != tmp.first) {         continue;       }       check[tmp.second] = true;       for (auto i : g[tmp.second]) {         if (flow[tmp.second][i] > 0 &&             dist[i] > dist[tmp.second] + get_p(tmp.second, i)) {           dist[i] = dist[tmp.second] + get_p(tmp.second, i);           prv[i] = tmp.second;           q.push(make_pair(-dist[i], i));         }       }     }     for (int i = 0; i < SIZE; i++) {       pot[i] += dist[i];     }     if (!check[to]) {       return inf;     }     int ptr = to, cap = inf, sum = 0;     while (ptr != from) {       cap = min(cap, flow[prv[ptr]][ptr]);       ptr = prv[ptr];     }     ptr = to;     while (ptr != from) {       flow[prv[ptr]][ptr] -= cap;       flow[ptr][prv[ptr]] += cap;       sum += cost[prv[ptr]][ptr];       ptr = prv[ptr];     }     return sum;   }   int solve(int from, int to) {     int sum = 0, tmp;     while ((tmp = add_path(from, to)) != inf) {       sum -= tmp;     }     return sum;   }   void add(int from, int to, int in_flow, int in_cost) {     g[from].push_back(to);     g[to].push_back(from);     flow[from][to] = in_flow;     cost[from][to] = in_cost;     cost[to][from] = -in_cost;   }   vector<int> super_cnt[100001];   vector<int> cnt[7];   int main() {     cin >> n;     SIZE = 2 * n + 3;     in.resize(SIZE);     for (int i = 0; i < n; i++) {       cin >> in[i];     }     g.resize(SIZE, vector<int>());     add(0, 1, 4, 0);     for (int i = 0; i < n; i++) {       add(2 * i + 3, 2 * i + 4, 1, -1);       add(1, 2 * i + 3, 1, 0);       add(2 * i + 4, 2, 1, 0);       for (int j : cnt[in[i] % 7]) {         add(2 * j + 4, 2 * i + 3, 1, 0);       }       for (int j : super_cnt[in[i] - 1]) {         add(2 * j + 4, 2 * i + 3, 1, 0);       }       for (int j : super_cnt[in[i] + 1]) {         add(2 * j + 4, 2 * i + 3, 1, 0);       }       cnt[in[i] % 7].push_back(i);       super_cnt[in[i]].push_back(i);     }     for (int i = 0; i < SIZE; i++) {       for (int j = 0; j < i; j++) {         if (flow[j][i] && pot[j] + cost[j][i] < pot[i]) {           pot[i] = pot[j] + cost[j][i];         }       }     }     cout << solve(0, 2);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int t[111];   int main() {     int n, k, m;     cin >> n >> k >> m;     int sum = 0;     for (int i = 0; i < k; i++) {       cin >> t[i];       sum += t[i];     }     sort(t, t + k);     int ans = 0;     for (int i = 0; i <= n; i++) {       int time = m - sum * i;       if (time < 0) break;       int cnt = (k + 1) * i;       for (int j = 0; j < k; j++) {         for (int q = 0; q < (n - i); q++) {           if (time - t[j] >= 0) {             cnt++;             time -= t[j];           }         }       }       ans = max(ans, cnt);     }     cout << ans << endl;   }


#include  bits/stdc++.h       using namespace std;      const int MAXN = 3e5+10;   int cores[MAXN];   int pos[51];   int n, m;      int solve(int cor){       int ans = pos[cor];       for(int i = 1; i <= 50; i++){           if(pos[i] < pos[cor] && pos[i]) pos[i]++;       }       pos[cor] = 1;       return ans;   }      int main(){          cin>>n>>m;          for(int i = 0; i < n; i++){           cin>>cores[i];           if(!pos[cores[i]]) pos[cores[i]] = i+1;       }          for(int i = 0; i < m; i++){           int query;           cin>>query;           cout<<solve(query)<<  n ;       }       return 0;   }


#include <bits/stdc++.h>   using namespace std;   string s1, s2;   int k, ans;   double eps = 0.01;   bool ok(int l) {     if (s1.compare(0, l, s2, 0, l) != 0) {       return false;     }     for (int i = 0; i < s1.size(); i += l) {       if (s1.compare(0, l, s1, i, l) != 0) {         return false;       }     }     for (int i = 0; i < s2.size(); i += l) {       if (s2.compare(0, l, s2, i, l) != 0) {         return false;       }     }     return true;   }   int main() {     cin >> s1 >> s2;     k = min(s1.size(), s2.size());     for (int i = 1; i <= sqrt(k + eps); i++) {       if (s1.size() % i == 0 && s2.size() % i == 0 && ok(i)) {         ans++;       }       if (s1.size() % (k / i) == 0 && s2.size() % (k / i) == 0 && i != k / i &&           ok(k / i)) {         ans++;       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 15;   int dis[maxn][maxn];   char str[2000100];   void cal(int p, int q) {     memset(dis, 0x3f3f3f3f, sizeof dis);     for (int i = 0; i <= 9; i++) {       dis[i][(i + p) % 10] = min(dis[i][(i + p) % 10], 1);       dis[i][(i + q) % 10] = min(dis[i][(i + q) % 10], 1);     }     for (int k = 0; k <= 9; k++)       for (int i = 0; i <= 9; i++)         for (int j = 0; j <= 9; j++) {           dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]);         }   }   int main() {     cal(0, 1);     scanf( %s , str);     int len = strlen(str);     int ans[15][15];     memset(ans, -1, sizeof ans);     for (int i = 0; i < 10; i++)       for (int j = i; j < 10; j++) {         cal(i, j);         int sm = 0;         for (int k = 1; k < len; k++) {           int ti = str[k - 1] -  0 , tj = str[k] -  0 ;           if (dis[ti][tj] == 0x3f3f3f3f || dis[ti][tj] == 0) {             sm = -1;             break;           } else             sm += dis[ti][tj] - 1;         }         ans[i][j] = ans[j][i] = sm;       }     for (int i = 0; i < 10; i++)       for (int j = 0; j < 10; j++) {         printf(j == 9 ?  %d n  :  %d  , ans[i][j]);       }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool isprime(long long int n) {     if (n < 2) return false;     for (long long int i = 2; i <= sqrt(n); i++)       if (n % i == 0) return false;     return true;   }   long long gcd(long long int a, long long int b) {     if (a == 0 || b == 0)       return a + b;     else       return gcd(b, a % b);   }   const int mx = 100000;   long long int b[mx], w[mx], dp[10][mx];   char c[1100][1100];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     long long int n, m, x, y;     cin >> n >> m >> x >> y;     for (long long int i = 1; i <= n; i++)       for (long long int j = 1; j <= m; j++) cin >> c[i][j];     for (long long int i = 1; i <= m; i++) {       long long int wt = 0, bl = 0;       for (long long int j = 1; j <= n; j++) {         if (c[j][i] ==  . )           wt++;         else           bl++;       }       w[i] = w[i - 1] + wt;       b[i] = b[i - 1] + bl;     }     for (long long int i = 1; i <= m; i++) {       dp[1][i] = 100000000;       dp[0][i] = 100000000;       for (long long int a = x; a <= y; a++) {         if (i - a >= 0) {           dp[1][i] = min(dp[0][i - a] + w[i] - w[i - a], dp[1][i]);           dp[0][i] = min(dp[1][i - a] + b[i] - b[i - a], dp[0][i]);         }       }     }     cout << min(dp[0][m], dp[1][m]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void __print(int x) { cerr << x; }   void __print(long x) { cerr << x; }   void __print(long long x) { cerr << x; }   void __print(unsigned x) { cerr << x; }   void __print(unsigned long x) { cerr << x; }   void __print(unsigned long long x) { cerr << x; }   void __print(float x) { cerr << x; }   void __print(double x) { cerr << x; }   void __print(long double x) { cerr << x; }   void __print(char x) { cerr <<      << x <<     ; }   void __print(const char *x) { cerr <<     << x <<    ; }   void __print(const string &x) { cerr <<     << x <<    ; }   void __print(bool x) { cerr << (x ?  true  :  false ); }   template <typename T, typename V>   void __print(const pair<T, V> &x) {     cerr <<  { ;     __print(x.first);     cerr <<  , ;     __print(x.second);     cerr <<  } ;   }   template <typename T>   void __print(const T &x) {     int f = 0;     cerr <<  { ;     for (auto &i : x) cerr << (f++ ?  ,  :   ), __print(i);     cerr <<  } ;   }   void _print() { cerr <<  ] n ; }   template <typename T, typename... V>   void _print(T t, V... v) {     __print(t);     if (sizeof...(v)) cerr <<  ,  ;     _print(v...);   }   inline int GCD(int x, int y) {     if (x < y) swap(x, y);     if (x == 0) return y;     if (y == 0) return x;     return GCD(x % y, y);   }   int phi(int n) {     int result = n;     for (int i = 2; i * i <= n; i++) {       if (n % i == 0) {         while (n % i == 0) n /= i;         result -= result / i;       }     }     if (n > 1) result -= result / n;     return result;   }   int power(int x, int n, int mod) {     int res = 1;     x %= mod;     while (n) {       if (n & 1) {         res = ((res * x) % mod + mod) % mod;       }       x = ((x * x) % mod + mod) % mod;       n >>= 1;     }     return res;   }   inline bool func(const pair<int, int> &a, const pair<int, int> &b) {     if (a.second < b.second) return true;     if (a.second == b.second) {       if (a.first >= b.first) return true;       return false;     }     return false;   }   const int MAXN = 6e3 + 5;   int dp[MAXN][MAXN];   int SIZ, N;   vector<int> Rs[MAXN];   void clear() {     for (int i = 0; i <= SIZ; i++) {       for (int j = 0; j <= SIZ; j++) dp[i][j] = -1;       Rs[i].clear();     }   }   int solve(int l, int r) {     if (l > r) return 0;     if (dp[l][r] != -1) return dp[l][r];     int kitne = count(Rs[l].begin(), Rs[l].end(), r);     dp[l][r] = max(dp[l][r], kitne + (l + 1 > r ? 0 : solve(l + 1, r)));     for (int i = 0; i < Rs[l].size(); i++) {       int R = Rs[l][i];       if (R >= r) continue;       dp[l][r] = max(dp[l][r], kitne + solve(l, R) + solve(R + 1, r));     }     return dp[l][r];   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     int test;     cin >> test;     while (test--) {       cin >> N;       vector<int> v;       vector<int> L(N + 1), R(N + 1);       for (int i = 1; i <= N; i++) {         cin >> L[i] >> R[i];         v.push_back(L[i]);         v.push_back(R[i]);       }       sort(v.begin(), v.end());       v.resize(unique(v.begin(), v.end()) - v.begin());       for (int i = 1; i <= N; i++) {         L[i] = lower_bound(v.begin(), v.end(), L[i]) - v.begin();         R[i] = lower_bound(v.begin(), v.end(), R[i]) - v.begin();       }       SIZ = v.size() + 1;       clear();       for (int i = 1; i <= N; i++) {         Rs[L[i]].push_back(R[i]);       }       int ans = solve(0, SIZ);       cout << ans << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   int L[36000], R[36000];   int D[36000], U[36000];   int C[36000];   int S[185], H[185], mark[36000], OK[185], tans[36000];   int ak, size;   void Link(int r, int c) {     S[c]++;     C[size] = c;     U[size] = U[c];     D[U[c]] = size;     D[size] = c;     U[c] = size;     if (H[r] == -1)       H[r] = L[size] = R[size] = size;     else {       L[size] = L[H[r]];       R[L[H[r]]] = size;       R[size] = H[r];       L[H[r]] = size;     }     mark[size] = r;     size++;   }   void remove(int c) {     int i;     for (i = D[c]; i != c; i = D[i]) L[R[i]] = L[i], R[L[i]] = R[i];   }   void resume(int c) {     int i;     for (i = U[c]; i != c; i = U[i]) L[R[i]] = R[L[i]] = i;   }   int h() {     int i, j, k, count = 0;     bool visit[185];     memset(visit, 0, sizeof(visit));     for (i = R[0]; i; i = R[i]) {       if (visit[i]) continue;       count++;       visit[i] = 1;       for (j = D[i]; j != i; j = D[j]) {         for (k = R[j]; k != j; k = R[k]) visit[C[k]] = 1;       }     }     return count;   }   void Dance(int k) {     int i, j, c, Min, ans;     ans = h();     if (k + ans >= ak) return;     if (!R[0]) {       if (k < ak) {         ak = k;         for (int i = 0; i < k; i++) {           tans[i] = mark[OK[i]];         }       }       return;     }     for (Min = 185, i = R[0]; i; i = R[i])       if (S[i] < Min) Min = S[i], c = i;     for (i = D[c]; i != c; i = D[i]) {       OK[k] = i;       remove(i);       for (j = R[i]; j != i; j = R[j]) remove(j);       Dance(k + 1);       for (j = L[i]; j != i; j = L[j]) resume(j);       resume(i);     }     return;   }   int xx[5] = {0, 0, 0, 1, -1};   int yy[5] = {0, 1, -1, 0, 0};   int mat[400][400];   int main() {     int tn, tm;     while (scanf( %d%d , &tn, &tm) == 2) {       memset(mat, 0, sizeof(mat));       for (int i = 1; i <= tn; i++) {         for (int j = 1; j <= tm; j++) {           for (int k = 0; k < 5; k++) {             int x = i + xx[k], y = j + yy[k];             if (x >= 1 && x <= tn && y >= 1 && y <= tm) {               mat[(i - 1) * tm + j][(x - 1) * tm + y] = 1;             }           }         }       }       n = tn * tm, m = tn * tm;       for (int i = 0; i <= m; i++) {         S[i] = 0;         U[i] = D[i] = i;         L[i + 1] = i;         R[i] = i + 1;       }       R[m] = 0;       memset(H, -1, sizeof(H));       memset(mark, 0, sizeof(mark));       memset(tans, 0, sizeof(tans));       size = m + 1;       for (int i = 1; i <= n; i++) {         for (int j = 1; j <= m; j++) {           if (mat[i][j]) Link(i, j);         }       }       ak = 185;       Dance(0);       printf( %d n , n - ak);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main(void) {     unsigned long num_bottles = 0;     cin >> num_bottles;     map<unsigned long, pair<unsigned long, unsigned long> > links;     map<unsigned long, unsigned long> counts;     for (unsigned long n = 0; n < num_bottles; n++) {       unsigned long a = 0, b = 0;       cin >> a >> b;       counts[a]++;       links[a];       if (a == b) {         links[b].second++;       } else {         links[b].first++;       }     }     unsigned long unopened = 0;     for (map<unsigned long, pair<unsigned long, unsigned long> >::iterator              links_it = links.begin();          links_it != links.end(); ++links_it) {       unsigned long bottle = links_it->first;       unsigned long from_outside = links_it->second.first;       unsigned long from_within = links_it->second.second;       if (from_outside > 0) continue;       if (from_within > 1) continue;       if (from_within == 1) {         unopened++;         continue;       }       unopened += counts[bottle];     }     cout << unopened;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     int t;     cin >> t;     while (t--) {       long long n;       cin >> n;       vector<long long> arr(n);       int neg = 0;       int pos = 0;       for (long long i = 0; i < n; i++) {         cin >> arr[i];         if (arr[i] < 0)           neg++;         else           pos++;       }       sort(arr.begin(), arr.end());       long long ans = 1;       ans = arr[n - 1] * arr[n - 2] * arr[n - 3] * arr[n - 4] * arr[n - 5];       ans = max(ans, arr[0] * arr[1] * arr[n - 1] * arr[n - 2] * arr[n - 3]);       ans = max(ans, arr[0] * arr[1] * arr[2] * arr[3] * arr[n - 1]);       cout << ans << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<int> arr[n];     map<long long, int> mp;     vector<long long> summer(n);     for (int i = 0; i < n; i++) {       int m;       cin >> m;       int tmp;       long long sum = 0;       for (int j = 0; j < m; j++) {         cin >> tmp;         arr[i].push_back(tmp);         sum += tmp;       }       summer[i] = sum;       for (int j = 0; j < m; j++) {         long long key = sum - arr[i][j];         if (mp.find(key) != mp.end()) {           if (mp[key] != i) {             cout <<  YES n  << i + 1 <<     << j + 1 <<   n ;             int cur = mp[key];             cout << cur + 1 <<    ;             int check = summer[cur] - key;             for (int k = 0; k < arr[cur].size(); k++) {               if (arr[cur][k] == check) {                 cout << k + 1;                 return 0;               }             }           }         } else {           mp[key] = i;         }       }     }     cout <<  NO ;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> f[100005];   int n, m, temp, flag = 0;   int main() {     cin >> n >> m;     for (int i = 0; i < n; i++) {       cin >> temp;       f[temp].push_back(i + 1);     }     int j = 0, ans[100005];     for (int i = 0; i < m; i++) {       cin >> temp;       if (f[temp].size() == 0) {         flag = 2;         break;       } else if (f[temp].size() > 1 && flag != 2) {         flag = 1;       } else if (flag == 0) {         ans[j++] = f[temp][0];       }     }     if (flag == 0) {       cout <<  Possible n ;       for (int i = 0; i < m; i++) cout << ans[i] <<    ;       cout << endl;     } else if (flag == 1) {       cout <<  Ambiguity n ;     } else {       cout <<  Impossible n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int get_set(int v, vector<int>& parent) {     if (v != parent[v]) {       parent[v] = get_set(parent[v], parent);     }     return parent[v];   }   void union_set(int a, int b, vector<int>& parent, vector<int>& rang) {     a = get_set(a, parent);     b = get_set(b, parent);     if (a != b) {       if (rang[a] < rang[b]) {         swap(a, b);       }       parent[b] = a;       rang[a] += rang[b];     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     int n, m, a, s = 0, k, p, l, r;     cin >> n >> m;     vector<map<int, int>> x(n), y(m);     vector<int> parent(n * m), rang(n * m, 0);     vector<pair<int, int>> q(n * m);     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) {         cin >> a;         q[s] = make_pair(a, s);         parent[s] = s;         rang[s] = 1;         if (x[i].count(a) != 0) {           union_set(s, i * m + x[i][a], parent, rang);         }         if (y[j].count(a) != 0) {           union_set(s, y[j][a] * m + j, parent, rang);         }         x[i][a] = j;         y[j][a] = i;         s++;       }     for (int i = 0; i < n * m; i++) rang[i] = 0;     sort(begin(q), end(q));     for (int i = 0; i < n * m; i++) {       a = q[i].first;       s = q[i].second;       l = s / m;       r = s % m;       swap(q[i].first, q[i].second);       k = get_set(s, parent);       k = rang[k];       auto j = x[l].find(a);       j++;       if (j != end(x[l])) {         p = get_set(l * m + j->second, parent);         rang[p] = max(k + 1, rang[p]);       }       j = y[r].find(a);       j++;       if (j != end(y[r])) {         p = get_set(j->second * m + r, parent);         rang[p] = max(k + 1, rang[p]);       }     }     sort(begin(q), end(q));     for (int i = 0; i < n * m; i++) {       k = get_set(q[i].first, parent);       k = rang[k];       cout << k + 1 <<    ;       if ((q[i].first + 1) % m == 0) cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, tmp;     bool b;     cin >> n >> m;     vector<int> t(n, -1);     while (m--) {       cin >> tmp;       t[tmp - 1]++;     }     m = 1000;     for (int i = 0; i < n; i++) {       m = min(m, t[i]);     }     cout << m + 1;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T1>   void print_list(const T1& a) {     cerr << a << endl;   }   template <typename T1, typename T2>   void print_list(const T1& a, const T2& b) {     cerr << a <<     << b << endl;   }   template <typename T1, typename T2, typename T3>   void print_list(const T1& a, const T2& b, const T3& c) {     cerr << a <<     << b <<     << c << endl;   }   template <typename T1, typename T2, typename T3, typename T4>   void print_list(const T1& a, const T2& b, const T3& c, const T4& d) {     cerr << a <<     << b <<     << c <<     << d << endl;   }   template <typename T1, typename T2, typename T3, typename T4, typename T5>   void print_list(const T1& a, const T2& b, const T3& c, const T4& d,                   const T5& e) {     cerr << a <<     << b <<     << c <<     << d <<     << e << endl;   }   template <typename T1, typename T2, typename T3, typename T4, typename T5,             typename T6>   void print_list(const T1& a, const T2& b, const T3& c, const T4& d, const T5& e,                   const T6& f) {     cerr << a <<     << b <<     << c <<     << d <<     << e <<     << f << endl;   }   template <typename T1, typename T2, typename T3, typename T4, typename T5,             typename T6, typename T7>   void print_list(const T1& a, const T2& b, const T3& c, const T4& d, const T5& e,                   const T6& f, const T7& g) {     cerr << a <<     << b <<     << c <<     << d <<     << e <<     << f <<              << g << endl;   }   template <typename A, typename B>   ostream& operator<<(ostream& out, const pair<A, B>& pp) {     out <<  (  << pp.first <<  ,  << pp.second <<  ) ;     return out;   }   template <typename A, typename B>   istream& operator<<(istream& in, pair<A, B>& pp) {     cerr <<  A pair wanted  << endl;     in >> pp.first >> pp.second;     return in;   }   template <typename T>   ostream& operator<<(ostream& out, const vector<T>& vect) {     out <<  length =   << vect.size() << endl;     for (int i = 0; i < vect.size(); i++) out << vect[i] <<    ;     out << endl;     return out;   }   template <typename T>   istream& operator>>(istream& in, vector<T>& vect) {     vect.clear();     int n;     cerr <<  A integer of length wanted  << endl;     in >> n;     vect.resize(n);     cerr << n <<   elements wanted  << endl;     for (int i = 0; i < n; i++) in >> vect[i];     return in;   }   template <typename T>   ostream& operator<<(ostream& out, const vector<vector<T> >& vect) {     out <<  row number=  << vect.size() << endl;     for (int i = 0; i < vect.size(); i++) {       out <<  row #  << i <<  : ;       for (int j = 0; j < vect[i].size(); j++) out <<     << vect[i][j];       out << endl;     }     return out;   }   template <typename T>   istream& operator>>(istream& in, vector<vector<T> >& vect) {     vect.clear();     int n, m;     cerr <<  Two integers wnated  << endl;     in >> n >> m;     vect.resize(n);     cerr <<  A matrix   << n <<   X   << m <<   wanted  << endl;     for (int i = 0; i < n; i++) {       vect[i].resize(m);       for (int j = 0; j < m; j++) in >> vect[i][j];     }     return in;   }   template <typename T>   inline void updateMax(T& a, const T& b) {     a = max(a, b);   }   template <typename T>   inline void updateMin(T& a, const T& b) {     a = min(a, b);   }   template <typename T>   inline vector<T> erase(vector<T> table, int ind) {     assert(ind < table.size());     table.erase(table.begin() + ind);     return table;   }   template <typename T>   vector<T> unique(vector<T> table) {     sort(table.begin(), table.end());     return vector<T>(table.begin(), unique(table.begin(), table.end()));   }   template <class T>   vector<T> parse(const string& ss, const char* cut =    ) {     vector<T> re;     for (int j = 0; j < ss.size(); j++) {       string s;       while (j < ss.size() && NULL == strchr(cut, ss[j])) s += ss[j++];       if (!s.empty()) {         T tmp;         istringstream is(s);         is >> tmp;         re.push_back(tmp);       }     }     return re;   }   int countBit(int n) {     int re = 0;     while (n) re++, n ^= ((((n) ^ ((n)-1)) & n));     return re;   }   int MSB(int n) {     if (n == 0) return 0;     while (((((n) ^ ((n)-1)) & n)) != n) n ^= ((((n) ^ ((n)-1)) & n));     return n;   }   void initHash(int n, int hash[]) {     for (int i = 0; i < n; i++) hash[((1) << (i))] = i;   }   void initBcnt(int n, int bcnt[]) {     bcnt[0] = 0;     for (int i = 1; i < ((1) << (n)); i++)       bcnt[i] = bcnt[i ^ ((((i) ^ ((i)-1)) & i))] + 1;   }   template <typename T>   T __gcd(T n, T m, T& a, T& b) {     T a1 = 0, b1 = 1;     a = 1, b = 0;     while (m) {       T c = n / m;       T r = n - m * c;       T t;       t = a;       a = a1;       a1 = t - c * a1;       t = b;       b = b1;       b1 = t - c * b1;       n = m;       m = r;     }     return n;   }   struct Node {     int r, c, d;     int v;     Node(int x, int y, int z, int v1) : r(x), c(y), d(z), v(v1){};     bool operator<(const Node& other) const { return v > other.v; };   };   priority_queue<Node> heap;   const int dir[][2] = {{-1, 0}, {0, 1},  {1, 0},  {0, -1},                         {1, 1},  {1, -1}, {-1, 1}, {-1, -1}};   const char dname[] =  NWSE ;   int get_inter(int r, int x, int n) {     x = abs(x);     int res = 0;     if (x > r) {       if (n >= x - r) res++;       if (n > x - r) res += (min(x + r - 1, n) - (x - r)) * 2;       if (n >= x + r) res++;     } else if (x == r) {       res += min(n, 2 * r - 1) * 2;       if (n >= 2 * r) res++;     } else {       if (n >= r - x) res++;       if (n > r - x) res += 2 * (min(x + r - 1, n) - (r - x));       if (n >= x + r) res++;     }     return res;   }   int main() {     int x1, x2, n1, n2;     cin >> n1 >> x1 >> n2 >> x2;     long long int v = 0, e = 0, iso = 0;     for (int i = 1; i <= n1; i++) {       int t = get_inter(i, x2 - x1, n2);       if (t) {         v += t + 1;         e += t + 1;       } else         iso++;     }     for (int i = 1; i <= n2; i++) {       int t = get_inter(i, x1 - x2, n1);       if (t) {         v++;         e += t + 1;       } else         iso++;     }     long long int ans = iso;     if (v)       ans += e + 2 - v;     else       ans++;     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int32_t main() {     long long t;     cin >> t;     for (long long q = 0; q < t; q++) {       long long a, b, k;       cin >> a >> b >> k;       vector<long long> x(a * b);       for (long long i = 0; i < a * b; i++) {         x[i] = (i % a % b != i % b % a);       }       long long all = 0;       for (long long i = 0; i < a * b; i++) {         all += x[i];       }       vector<long long> sum_pref(a * b + 1, 0);       for (long long i = 0; i < a * b; i++) {         sum_pref[i + 1] = sum_pref[i] + x[i];       }       for (long long i = 0; i < k; i++) {         long long l, r;         cin >> l >> r;         r++;         long long ans = (r / (a * b) - l / (a * b)) * all;         ans += sum_pref[r % (a * b)];         ans -= sum_pref[l % (a * b)];         cout << ans <<    ;       }       cout << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct zfc {     char a[101];     int la;   } a[101];   bool cmp(zfc a, zfc b) { return a.la < b.la; }   bool cha(zfc a, zfc b) {     int flag;     for (int i = 0; i <= b.la - a.la; i++) {       flag = 0;       for (int j = 0; j < a.la; j++)         if (a.a[j] != b.a[j + i]) {           flag = 1;           break;         }       if (flag == 0) return 1;     }     return 0;   }   int n, flag1;   int main() {     scanf( %d , &n);     gets(a[0].a);     for (int i = 1; i <= n; i++) {       gets(a[i].a);       a[i].la = strlen(a[i].a);     }     sort(a + 1, a + 1 + n, cmp);     for (int i = 1; i <= n; ++i) {       flag1 = 0;       for (int j = 1; j < i; ++j)         if (cha(a[j], a[i]) == 0) {           flag1 = 1;           break;         }       if (flag1 == 1) {         printf( NO );         return 0;       }     }     printf( YES n );     for (int i = 1; i <= n; i++) puts(a[i].a);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int winner[300005];   int ans[300005];   int range[300005];   int find_winner(int v) {     if (v == winner[v]) return v;     return winner[v] = find_winner(winner[v]);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n, m;     cin >> n >> m;     for (int i = 1; i <= n; i++) {       winner[i] = i;       range[i] = i;       ans[i] = i;     }     while (m--) {       int l, r, x;       cin >> l >> r >> x;       int i = 0;       for (i = l; i <= r; i++) {         int w = find_winner(i);         ans[w] = x;         winner[w] = x;         i = range[w];       }       range[x] = i - 1;     }     for (int i = 1; i <= n; i++) {       if (i == ans[i])         cout <<  0  ;       else         cout << ans[i] <<    ;     }     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   int n, m;   const int sz = 1 << 13;   vector<int> gos[5001];   int rev[5001];   template <class T>   class Dinic {     struct _edge {       int x, y;       T c, rc;       _edge(int x, int y, T c, T rc) : x(x), y(y), c(c), rc(rc) {}     };     int s, e;     int n;     vector<T> nowFlow;     vector<vector<int>> edge;     vector<_edge> es;     vector<int> dist;     vector<int> it;     T inf;     int bfs() {       for (int i = 0; i < n; ++i) dist[i] = -1;       queue<int> q;       dist[s] = 0;       q.push(s);       while (!q.empty()) {         int x = q.front();         q.pop();         for (int i : edge[x]) {           if (i < 0) {             i = ~i;             if (dist[es[i].x] != -1) continue;             if (es[i].rc > 0) {               dist[es[i].x] = dist[x] + 1;               q.push(es[i].x);             }           } else {             if (dist[es[i].y] != -1) continue;             if (es[i].c > 0) {               dist[es[i].y] = dist[x] + 1;               q.push(es[i].y);             }           }         }       }       return dist[e] != -1;     }     T dfs(int x, T f) {       if (x == e) return f;       for (int &i = it[x]; i < edge[x].size(); ++i) {         int y;         T c;         if (edge[x][i] < 0)           y = es[~edge[x][i]].x, c = es[~edge[x][i]].rc;         else           y = es[edge[x][i]].y, c = es[edge[x][i]].c;         if (dist[x] + 1 != dist[y]) continue;         if (c == 0) continue;         c = dfs(y, min(f, c));         if (c > 0) {           if (edge[x][i] < 0) {             es[~edge[x][i]].c += c;             es[~edge[x][i]].rc -= c;             nowFlow[~edge[x][i]] -= c;           } else {             es[edge[x][i]].c -= c;             es[edge[x][i]].rc += c;             nowFlow[edge[x][i]] += c;           }           return c;         }       }       return 0;     }     int matchdfs(int x) {       if (::n + ::sz <= x && x < ::n + ::sz + ::m) return x - ::n - sz + 1;       for (int &i = it[x]; i < edge[x].size(); ++i) {         int y;         T c;         if (edge[x][i] < 0)           y = es[~edge[x][i]].x, c = -nowFlow[~edge[x][i]];         else           y = es[edge[x][i]].y, c = nowFlow[edge[x][i]];         if (c <= 0) continue;         if (edge[x][i] < 0)           ++nowFlow[~edge[x][i]];         else           --nowFlow[edge[x][i]];         return matchdfs(y);       }       return 0;     }       public:     void init(int N) {       n = N;       inf = 0;       edge.clear();       edge.resize(n);       dist.resize(n);       it.resize(n);       nowFlow.clear();       es.clear();     }     int addEdge(int x, int y, T C, T RC) {       inf = max(inf, C + RC);       int idx = es.size();       es.emplace_back(x, y, C, RC);       nowFlow.push_back(0);       edge[x].push_back(idx);       edge[y].push_back(~idx);       return idx;     }     T findMaximumFlow(int source, int sink) {       s = source;       e = sink;       T flow = 0;       while (bfs()) {         for (int i = 0; i < n; ++i) it[i] = 0;         while (1) {           T ret = dfs(s, inf);           if (ret == 0) break;           flow += ret;         }       }       return flow;     }     T getFlow(int idx) { return nowFlow[idx]; }     void findMatching() {       for (int i = 0; i < n; ++i) it[i] = 0;       for (int i = 1; i <= ::n; ++i) {         int r = matchdfs(i);         if (r) {           gos[i].push_back(r);           rev[r] = i;           --i;         }       }     }   };   struct weapon {     int type;     int l, r;     vector<int> ps;     void scan() {       cin >> type;       if (type == 0) {         int k, x;         cin >> k;         for (int i = 0; i < k; ++i) {           cin >> x;           ps.push_back(x);         }       } else if (type == 1) {         cin >> l >> r;       } else {         for (int i = 0; i < 3; ++i) {           int x;           cin >> x;           ps.push_back(x);         }       }     }   } wps[5001];   Dinic<int> dinic;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m;     for (int i = 1; i <= n; ++i) {       wps[i].scan();     }     dinic.init(n + sz + m + 10);     int S = 0, E = n + sz + m + 9;     for (int i = sz + m - 1; i > 1; --i) {       dinic.addEdge(n + (i >> 1), n + i, m, 0);     }     for (int i = 1; i <= n; ++i) {       dinic.addEdge(S, i, wps[i].type == 2 ? 2 : 1, 0);       if (wps[i].type == 1) {         int s = sz + wps[i].l - 1, e = sz + wps[i].r - 1;         while (s <= e) {           if ((s & 1) == 1) dinic.addEdge(i, n + (s++), 1, 0);           if ((e & 1) == 0) dinic.addEdge(i, n + (e--), 1, 0);           s >>= 1;           e >>= 1;         }       } else {         for (int j : wps[i].ps) dinic.addEdge(i, n + sz + j - 1, 1, 0);       }     }     for (int i = 0; i < m; ++i) {       dinic.addEdge(n + sz + i, E, 1, 0);     }     int ans = dinic.findMaximumFlow(S, E);     printf( %d n , ans);     dinic.findMatching();     for (int i = 1; i <= n; ++i) {       if (wps[i].type != 2) continue;       if (gos[i].size() != 1) continue;       for (int j = 0; j < 3; ++j) {         if (gos[i][0] == wps[i].ps[j]) continue;         gos[rev[wps[i].ps[j]]].clear();         rev[wps[i].ps[j]] = i;         gos[i].push_back(wps[i].ps[j]);         break;       }     }     for (int i = 1; i <= n; ++i) {       for (int j : gos[i]) {         printf( %d %d n , i, j);       }     }   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ld = long double;   using ull = unsigned long long;   const double PI = acos(-1.0);   const long long EPS = (1e-10);   const long long N = 1e5 * 2 + 10;   const long long inf = 1e9 * 2 + 10;   const ll INF = 1e18 * 2 + 10;   const long long MOD = 1e9 + 7;   long long nxt() {     long long x;     cin >> x;     return x;   }   long long fcmp(double a, double b) {     return (fabs(a - b) < EPS ? 0 : a > b ? 1 : -1);   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     long long k, b, n, t;     cin >> k >> b >> n >> t;     long long z = 1, res = n;     while (k * z + b <= t) {       z = k * z + b;       res--;     }     cout << (res > 0 ? (res) : (0));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long mult(long long a, long long b, long long p = 1000000007) {     long long ans = ((a % p) * (b % p)) % p;     return (ans + p) % p;   }   long long add(long long a, long long b, long long p = 1000000007) {     long long ans = (a % p + b % p) % p;     return (ans + p) % p;   }   long long fpow(long long n, long long k, long long p = 1000000007) {     long long r = 1;     for (; k; k >>= 1) {       if (k & 1) r = r * n % p;       n = n * n % p;     }     return r;   }   long long inv(long long a, long long p = 1000000007) {     return fpow(a, p - 2, p);   }   long long n, m, k;   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     cin >> n >> m >> k;     vector<pair<long long, long long> > arr(n);     vector<long long> orig(n);     for (long long i = 0; i < n; i++) {       cin >> arr[i].first;       arr[i].second = i;       orig[i] = arr[i].first;     }     sort(arr.begin(), arr.end(), greater<pair<long long, long long> >());     vector<bool> has(n, 0);     long long s = 0;     for (long long i = 0; i < m * k; i++) {       s += arr[i].first;       has[arr[i].second] = 1;     }     cout << s << endl;     vector<long long> ans;     long long ov = 0;     for (long long i = 0; i < n;) {       long long cnt = 0, j = i;       while (cnt < m) {         if (has[j] == 1) {           cnt++;         }         j++;       }       ov++;       i = j;       if (ov == k) break;       cout << i <<    ;       ans.push_back(i);     }     cout << endl;     return 0;   }