#include <bits/stdc++.h>   using namespace std;   long long int div_floor(const long long int &a, const long long int &b) {     return a / b - (((a ^ b) < 0) and a % b);   }   long long int div_ceil(const long long int &a, const long long int &b) {     return a / b + (((a ^ b) >= 0) and a % b);   }   long long int modpow(long long int a, long long int b,                        long long int m = 998244353) {     a %= m;     long long int res = 1;     while (b) {       if (b & 1) res = (res * a) % m;       a = (a * a) % m;       b >>= 1;     }     return res;   }   long long int modinv(long long int a, long long int m = 998244353) {     return modpow(a, m - 2, m);   }   vector<long long int> f;   vector<long long int> invf;   const int MAXVAL = 2e5 + 7;   void init() {     f.resize(MAXVAL, 1);     invf.resize(MAXVAL, 1);     for (int i = 1; i < MAXVAL; i++) f[i] = (f[i - 1] * i) % 998244353;     for (int i = 1; i < MAXVAL; i++) invf[i] = modinv(f[i]);   }   long long int ncr(long long int n, long long int r) {     if (r > n) return 0;     return invf[n - r] * (f[n] * invf[r] % 998244353) % 998244353;   }   void solve() {     int n, k;     cin >> n >> k;     vector<int> a(n);     for (auto &e : a) cin >> e;     int x = -1, cnt = 0;     for (auto &e : a)       if (e != x) x = e, cnt++;     if (a.back() == a[0]) cnt = max(1, cnt - 1);     if (k == 1 || cnt == 1) {       cout << 0 <<   n ;       return;     }     long long int ans = 0;     for (long long int i = 0; i < cnt; i++) {       long long int add = (modpow(k - 2, i) * ncr(cnt, i)) % 998244353;       long long int rem = cnt - i;       if (rem % 2)         add = (add * modpow(2, rem - 1)) % 998244353;       else         add = (add * (modpow(2, rem) - ncr(rem, rem / 2))) % 998244353,         add = (add + 998244353) % 998244353, add = (add * modinv(2)) % 998244353;       ans += add;     }     ans %= 998244353;     ans = (ans * modpow(k, n - cnt)) % 998244353;     cout << ans <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     init();     int t = 1;     while (t--) solve();   }


#include <bits/stdc++.h>   using namespace std;   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     long long n;     cin >> n;     long long ar[n + 1];     for (long long i = 0; i < n; i++) {       cin >> ar[i];     }     ar[n] = n + 1;     long long ans = 0;     for (long long i = 0; i < n; i++) {       long long x = ar[i];       long long y = ar[i + 1];       if (x > y) {         ans += (x - y) * (n - x + 1);       }       if (x < y) {         ans += x * (y - x);       }     }     cout << ans;   }


#include <bits/stdc++.h>   const int mod = 1000000007;   const int gmod = 3;   const int inf = 1039074182;   const double eps = 1e-9;   const long long llinf = 2LL * inf * inf;   template <typename T1, typename T2>   inline void chmin(T1 &x, T2 b) {     if (b < x) x = b;   }   template <typename T1, typename T2>   inline void chmax(T1 &x, T2 b) {     if (b > x) x = b;   }   inline void chadd(int &x, int b) {     x += b - mod;     x += (x >> 31 & mod);   }   template <typename T1, typename T2>   inline void chadd(T1 &x, T2 b) {     x += b;     if (x >= mod) x -= mod;   }   template <typename T1, typename T2>   inline void chmul(T1 &x, T2 b) {     x = 1LL * x * b % mod;   }   template <typename T1, typename T2>   inline void chmod(T1 &x, T2 b) {     x %= b, x += b;     if (x >= b) x -= b;   }   template <typename T>   inline T mabs(T x) {     return (x < 0 ? -x : x);   }   using namespace std;   using namespace std;   template <typename T>   ostream &operator<<(ostream &cout, vector<T> vec) {     cout <<  { ;     for (int i = 0; i < (int)vec.size(); i++) {       cout << vec[i];       if (i != (int)vec.size() - 1) cout <<  , ;     }     cout <<  } ;     return cout;   }   template <typename T1, typename T2>   ostream &operator<<(ostream &cout, pair<T1, T2> p) {     cout <<  (  << p.first <<  ,  << p.second <<  ) ;     return cout;   }   template <typename T, typename T2>   ostream &operator<<(ostream &cout, set<T, T2> s) {     vector<T> t;     for (auto x : s) t.push_back(x);     cout << t;     return cout;   }   template <typename T, typename T2>   ostream &operator<<(ostream &cout, multiset<T, T2> s) {     vector<T> t;     for (auto x : s) t.push_back(x);     cout << t;     return cout;   }   template <typename T>   ostream &operator<<(ostream &cout, queue<T> q) {     vector<T> t;     while (q.size()) {       t.push_back(q.front());       q.pop();     }     cout << t;     return cout;   }   template <typename T1, typename T2, typename T3>   ostream &operator<<(ostream &cout, map<T1, T2, T3> m) {     for (auto &x : m) {       cout <<  Key:   << x.first <<     <<  Value:   << x.second << endl;     }     return cout;   }   template <typename T1, typename T2>   void operator+=(pair<T1, T2> &x, const pair<T1, T2> y) {     x.first += y.first;     x.second += y.second;   }   template <typename T1, typename T2>   pair<T1, T2> operator+(const pair<T1, T2> &x, const pair<T1, T2> &y) {     return make_pair(x.first + y.first, x.second + y.second);   }   template <typename T1, typename T2>   pair<T1, T2> operator-(const pair<T1, T2> &x, const pair<T1, T2> &y) {     return make_pair(x.first - y.first, x.second - y.second);   }   template <typename T1, typename T2>   pair<T1, T2> operator-(pair<T1, T2> x) {     return make_pair(-x.first, -x.second);   }   template <typename T>   vector<vector<T>> operator~(vector<vector<T>> vec) {     vector<vector<T>> v;     int n = vec.size(), m = vec[0].size();     v.resize(m);     for (int i = 0; i < m; i++) {       v[i].resize(n);     }     for (int i = 0; i < m; i++) {       for (int j = 0; j < n; j++) {         v[i][j] = vec[j][i];       }     }     return v;   }   void print0x(int x) {     std::vector<int> vec;     while (x) {       vec.push_back(x & 1);       x >>= 1;     }     std::reverse(vec.begin(), vec.end());     for (int i = 0; i < (int)vec.size(); i++) {       std::cout << vec[i];     }     std::cout <<    ;   }   template <typename T>   void print0x(T x, int len) {     std::vector<int> vec;     while (x) {       vec.push_back(x & 1);       x >>= 1;     }     reverse(vec.begin(), vec.end());     for (int i = (int)vec.size(); i < len; i++) {       putchar( 0 );     }     for (size_t i = 0; i < vec.size(); i++) {       std::cout << vec[i];     }     std::cout <<    ;   }   vector<string> vec_splitter(string s) {     s +=  , ;     vector<string> res;     while (!s.empty()) {       res.push_back(s.substr(0, s.find( , )));       s = s.substr(s.find( , ) + 1);     }     return res;   }   void debug_out(vector<string> __attribute__((unused)) args,                  __attribute__((unused)) int idx,                  __attribute__((unused)) int LINE_NUM) {     cerr << endl;   }   template <typename Head, typename... Tail>   void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {     if (idx > 0)       cerr <<  ,  ;     else       cerr <<  Line(  << LINE_NUM <<  )  ;     stringstream ss;     ss << H;     cerr << args[idx] <<   =   << ss.str();     debug_out(args, idx + 1, LINE_NUM, T...);   }   struct DSUAE {     int *f;     inline void clear(int n) {       for (int i = 0; i < n; i++) {         f[i] = i;       }     }     inline void init(int n) {       f = new int[n + 5];       clear(n);     }     inline int find(int x) { return (f[x] == x ? x : f[x] = find(f[x])); }     inline void merge(int x, int y) {       x = find(x);       y = find(y);       if (x == y) return;       if (x & 1)         f[x] = y;       else         f[y] = x;     }   };   struct DSU {     int *f;     int *depth;     int *sz;     inline void clear(int n) {       for (int i = 0; i < n; i++) {         f[i] = i;         depth[i] = 1;         sz[i] = 1;       }     }     inline void init(int n) {       f = new int[n + 5];       depth = new int[n + 5];       sz = new int[n + 5];       clear(n);     }     inline int find(int x) { return (f[x] == x ? x : f[x] = find(f[x])); }     inline int getSize(int x) { return sz[find(x)]; }     inline int merge(int x, int y) {       x = find(x);       y = find(y);       if (x == y) return false;       if (depth[x] > depth[y]) {         f[y] = x;         sz[x] += sz[y];       } else if (depth[y] > depth[x]) {         f[x] = y;         sz[y] += sz[x];       } else {         sz[y] += sz[x];         f[x] = y;         depth[y]++;       }       return true;     }     inline int same(int x, int y) { return (find(x) == find(y)); }     ~DSU() {       delete f;       delete depth;       delete sz;     }   };   struct PersistentDSU : public DSU {     int find(int x) { return (x == f[x] ? x : find(f[x])); }     inline int merge(int x, int y) {       x = find(x);       y = find(y);       if (x == y) return false;       if (depth[x] > depth[y]) {         f[y] = x;         sz[x] += sz[y];       } else if (depth[y] > depth[x]) {         f[x] = y;         sz[y] += sz[x];       } else {         sz[y] += sz[x];         f[x] = y;         depth[y]++;       }       return true;     }   };   using namespace std;   int n;   char c[55][55];   DSUAE dsu;   vector<int> scc[55];   vector<vector<int>> a;   int b[55][55];   int p[55];   int main() {     double t = clock();     scanf( %d , &n);     dsu.init(n);     for (int i = 0; i < n; i++) scanf( %s , c[i]);     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         if (c[i][j] ==  A ) dsu.merge(i, j);       }     }     for (int i = 0; i < n; i++) scc[dsu.find(i)].push_back(i);     int now = 0;     for (int i = 0; i < n; i++) {       if (scc[i].empty()) continue;       for (auto x : scc[i]) {         for (auto y : scc[i]) {           if (c[x][y] ==  X ) {             cout <<  -1  << endl;             exit(0);           };         }       }       if (scc[i].size() > 1)         now += scc[i].size();       else         now += 1;       if (scc[i].size() > 1) a.push_back(scc[i]);     }     n = a.size();     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         if (i == j) continue;         bool noXor = true;         for (auto x : a[i]) {           for (auto y : a[j]) {             noXor &= (c[x][y] !=  X );           }         }         if (!noXor)           b[i][j] = 1;         else           b[i][j] = 0;       }     }     for (int i = 0; i < n; i++) p[i] = i;     int res = inf;     while ((clock() - t) / CLOCKS_PER_SEC <= 0.001) {       random_shuffle(p, p + n);       vector<vector<int>> v;       for (int i = 0; i < n; i++) {         int x = p[i];         int found = false;         for (auto &vv : v) {           int ok = true;           for (auto &u : vv) {             ok &= (b[u][x] == 0);           }           if (ok) {             found = true;             vv.push_back(x);             break;           }         }         if (!found) {           v.push_back(vector<int>{x});         }       }       chmin(res, v.size());     }     cout << res + now - 1 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n;     cin >> n;     multiset<long long> v;     vector<pair<string, long long>> ans;     for (int i = 0; i < n; ++i) {       string s;       cin >> s;       if (s ==  insert ) {         long long x;         cin >> x;         ans.push_back({ insert , x});         v.insert(x);       }       if (s ==  removeMin ) {         if (v.size() == 0) {           ans.push_back({ insert , 1});           v.insert(1);         }         ans.push_back({ removeMin , 0});         v.erase(v.begin());       }       if (s ==  getMin ) {         long long x;         cin >> x;         if (v.find(x) == v.end()) {           ans.push_back({ insert , x});           v.insert(x);         }         while (*(v.begin()) != x) {           ans.push_back({ removeMin , 0});           v.erase(v.begin());         }         ans.push_back({ getMin , x});       }     }     cout << ans.size() <<   n ;     for (auto i : ans) {       cout << i.first <<    ;       if (i.first !=  removeMin ) {         cout << i.second;       }       cout <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   using INT = long long;   const int NN = 111;   string tar;   string s[NN];   int n;   void dfs(int len) {     if (!len) {       for (int i = 1; i <= n; i++) {         for (int j = 0; j < s[i].length(); j++) {           int f = 1;           for (int k = j; k < s[i].length(); k++) {             if (k - j == tar.length()) {               puts( YES );               exit(0);             }             if (tar[k - j] != s[i][k]) {               f = 0;               break;             }           }           if (f) dfs(s[i].length() - j);         }       }       return;     }     for (int i = 1; i <= n; i++) {       int j = 0;       for (; j < s[i].length(); j++) {         if (tar[len + j] != s[i][j]) break;       }       if (len + j == tar.length()) {         puts( YES );         exit(0);       }       if (j == s[i].length()) dfs(len + j);     }   }   int main() {     cin >> tar;     cin >> n;     for (int i = 1; i <= n; i++) cin >> s[i];     dfs(0);     puts( NO );   }


#include <bits/stdc++.h>   const long long N = 2e5 + 7;   const long long M = 2e4 + 5;   const double eps = 1e-8;   const long long mod = 1e9 + 7;   const long long inf = 0x7fffffff;   const double pi = 3.1415926;   using namespace std;   vector<long long> v[N], num;   long long n;   long long dfs(long long x, long long fa) {     long long sum = 1;     for (long long i = 0; i < v[x].size(); i++) {       if (v[x][i] == fa) continue;       sum += dfs(v[x][i], x);     }     if (x != 1) num.push_back((n - sum) * sum);     return sum;   }   signed main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     long long t;     cin >> t;     while (t--) {       cin >> n;       for (long long i = 0; i <= n; i++) v[i].clear();       num.clear();       for (long long i = 1; i < n; i++) {         long long x, y;         cin >> x >> y;         v[x].push_back(y);         v[y].push_back(x);       }       long long m;       cin >> m;       vector<long long> p;       for (long long i = 0; i < m; i++) {         long long c;         cin >> c;         p.push_back(c);       }       dfs(1, -1);       if (m < n - 1) {         for (long long i = 0; i < n - 1 - m; i++) p.push_back(1);       }       sort(num.begin(), num.end());       sort(p.begin(), p.end());       long long ans = 0;       if (m <= n - 1) {         for (long long i = 0; i < n - 1; i++) {           ans += (num[i] * p[i]) % mod;           ans %= mod;         }       } else {         for (long long i = 0; i < n - 2; i++) {           ans += (num[i] * p[i]) % mod;           ans %= mod;         }         long long add = 1;         for (long long i = n - 2; i < m; i++) {           add = (add * p[i]) % mod;         }         ans += (add * num[n - 2]) % mod;         ans %= mod;       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long nums[100005];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int n;     cin >> n;     long long potL = 1000000000;     long long total = 0;     for (int i = 0; i < n; i++) {       long long num;       cin >> num;       if (num % 2 == 1 && num < potL) potL = num;       total += num;       nums[i] = num;     }     if (total % 2 == 1) total -= potL;     cout << total << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int i, n, x[110], y[110], f[110], j, ans;   bool b[110];   int find(int x) {     if (f[x] == x)       return x;     else       return f[x] = find(f[x]);   }   void Union(int x, int y) { f[find(x)] = find(y); }   int main() {     scanf( %d , &n);     for (i = 1; i <= n; i++) f[i] = i;     for (i = 1; i <= n; i++) {       scanf( %d%d , &x[i], &y[i]);     }     for (i = 1; i <= n; i++)       for (j = 1; j <= n; j++)         if (find(i) != find(j))           if (x[i] == x[j] || y[i] == y[j]) Union(i, j);     memset(b, 0, sizeof(b));     for (i = 1; i <= n; i++)       if (!b[find(i)]) b[find(i)] = 1, ans++;     printf( %d n , ans - 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxN = 2e5 + 7;   int N, M, head[maxN], cnt;   struct Eddge {     int nex, to, id;     Eddge(int a = -1, int b = 0, int c = 0) : nex(a), to(b), id(c) {}   } edge[maxN << 1];   inline void addEddge(int u, int v, int id) {     edge[cnt] = Eddge(head[u], v, id);     head[u] = cnt++;   }   inline void _add(int u, int v, int id) {     addEddge(u, v, id);     addEddge(v, u, id);   }   inline void init() {     cnt = 0;     for (int i = 1; i <= N; i++) head[i] = -1;   }   struct node {     int u, v, op;     node(int a = 0, int b = 0, int c = -1) : u(a), v(b), op(c) {}   } t[maxN];   struct Point {     int id, op;     Point(int a = 0, int b = 0) : id(a), op(b) {}   };   queue<Point> Q;   bool bfs() {     t[1].op = 1;     Q.push(Point(t[1].u, 1));     while (!Q.empty()) {       Point now = Q.front();       Q.pop();       int u = now.id;       for (int i = head[u], v, id; ~i; i = edge[i].nex) {         id = edge[i].id;         if (~t[id].op) {           if (t[id].u == u) {             if (t[id].op == 0 && now.op == 1) return false;             if (t[id].op == 1 && now.op == -1) return false;           } else {             if (t[id].op == 0 && now.op == -1) return false;             if (t[id].op == 1 && now.op == 1) return false;           }           continue;         }         v = edge[i].to;         if (now.op == 1) {           Q.push(Point(v, -1));           if (t[id].u == u)             t[id].op = 1;           else             t[id].op = 0;         } else {           Q.push(Point(v, 1));           if (t[id].u == u)             t[id].op = 0;           else             t[id].op = 1;         }       }     }     Q.push(Point(t[1].v, -1));     while (!Q.empty()) {       Point now = Q.front();       Q.pop();       int u = now.id;       for (int i = head[u], v, id; ~i; i = edge[i].nex) {         id = edge[i].id;         if (~t[id].op) {           if (t[id].u == u) {             if (t[id].op == 0 && now.op == 1) return false;             if (t[id].op == 1 && now.op == -1) return false;           } else {             if (t[id].op == 0 && now.op == -1) return false;             if (t[id].op == 1 && now.op == 1) return false;           }           continue;         }         v = edge[i].to;         if (now.op == 1) {           Q.push(Point(v, -1));           if (t[id].u == u)             t[id].op = 1;           else             t[id].op = 0;         } else {           Q.push(Point(v, 1));           if (t[id].u == u)             t[id].op = 0;           else             t[id].op = 1;         }       }     }     return true;   }   int main() {     scanf( %d%d , &N, &M);     init();     for (int i = 1, u, v; i <= M; i++) {       scanf( %d%d , &u, &v);       t[i] = node(u, v, -1);       _add(u, v, i);     }     if (bfs()) {       printf( YES n );       for (int i = 1; i <= M; i++) printf( %d , t[i].op);       printf(  n );     } else       printf( NO n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n;   map<string, int> mid, pid;   std::vector<string> hostname;   vector<int> a[100000];   char s[1000];   int m_total = 0, p_total = 0;   int b[100000];   std::vector<std::vector<int> > ans;   bool cmp(int i, int j) { return a[i] < a[j]; }   int main(int argc, char const *argv[]) {     scanf( %d , &n);     for (int i = 0; i < n; ++i) {       scanf( %s , s);       int j = 7;       for (; s[j]; ++j)         if (s[j] ==  / ) break;       string host =   , path =   ;       for (int k = 0; k < j; ++k) host += s[k];       for (int k = j; s[k]; ++k) path += s[k];       if (mid.count(host) == 0) {         mid[host] = m_total++;         hostname.push_back(host);       }       if (pid.count(path) == 0) {         pid[path] = p_total++;       }       a[mid[host]].push_back(pid[path]);     }     for (int i = 0; i < m_total; ++i) {       sort(a[i].begin(), a[i].end());       a[i].erase(unique(a[i].begin(), a[i].end()), a[i].end());       b[i] = i;     }     sort(b, b + m_total, cmp);     int l = 0;     for (int i = 1; i < m_total; ++i) {       if (a[b[i]] != a[b[l]]) {         if (i - l > 1) {           std::vector<int> v;           v.clear();           for (int j = l; j < i; ++j) v.push_back(b[j]);           ans.push_back(v);         }         l = i;       }     }     if (m_total - l > 1) {       std::vector<int> v;       v.clear();       for (int j = l; j < m_total; ++j) v.push_back(b[j]);       ans.push_back(v);     }     printf( %d n , ans.size());     for (int i = 0; i < ans.size(); ++i) {       for (int j = 0; j < ans[i].size(); ++j) {         printf( %s%c , hostname[ans[i][j]].c_str(),                j < ans[i].size() - 1 ?     :   n );       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9 + 7;   const int maxn = 1e4 + 5;   int n, b, q;   int a[maxn], c[maxn];   inline int f(int x, int j) { return (x / 5) + (x % 5 >= j); }   inline int calc(int j, int l, int r) { return f(r, j) - f(l - 1, j); }   int main() {     scanf( %d%d%d , &n, &b, &q);     memset(a, -1, sizeof(a));     for (int i = (0); i < (q); ++i) {       int x, k;       scanf( %d%d , &x, &k);       if (~a[x] && a[x] != k) {         puts( unfair );         return 0;       }       a[x] = k;     }     if (~a[b] && a[b] != n) {       puts( unfair );       return 0;     }     a[b] = n;     a[0] = 0;     for (int msk = (0); msk < (1 << 5); ++msk) {       int x, g = 0, lst = 0;       for (int i = (1); i <= (b); ++i)         if (~a[i]) {           int sub = 0, nin = 0;           if (a[i] < a[lst]) {             puts( unfair );             return 0;           }           for (int j = (0); j < (5); ++j) {             if (msk >> j & 1)               sub += calc(j, lst + 1, i);             else               nin += calc(j, lst + 1, i);           }           g += min(a[i] - a[lst], sub);           if (a[i] - a[lst] > i - lst) {             puts( unfair );             return 0;           }           lst = i;         }       x = __builtin_popcount(msk) * n / 5;       if (x > g) {         puts( unfair );         return 0;       }     }     puts( fair );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int ins[300];   struct Rec {     int n, p;     int a[10];   } st[1000000];   void Print(int now) {     int i, j, x, pre, ret;     if (now == 0) return;     pre = st[now].p;     ret = st[now].a[st[now].n - 1];     for (i = 0; i < st[pre].n; i++)       for (x = 2; x <= 8; x <<= 1)         if (st[pre].a[i] * x == ret) {           Print(pre);           printf( lea e%cx, [%d*e%cx] n , st[now].n +  a  - 1, x,  a  + i);           return;         }     for (i = 0; i < st[pre].n; i++)       for (j = 0; j < st[pre].n; j++)         for (x = 1; x <= 8; x <<= 1)           if (st[pre].a[i] + st[pre].a[j] * x == ret) {             Print(pre);             printf( lea e%cx, [e%cx + %d*e%cx] n , st[now].n +  a  - 1, i +  a ,                    x, j +  a );             return;           }   }   int main() {     int i, j, n, x, low, top, lim, ret;     scanf( %d , &n);     if (n == 1) {       puts( 0 );       return 0;     }     st[0].n = 1;     st[0].a[0] = 1;     for (low = top = 0; low <= top; low++) {       memset(ins, 0, sizeof(ins));       lim = st[low].a[st[low].n - 1];       for (i = 0; i < st[low].n; i++)         for (x = 2; x <= 8; x <<= 1) {           ret = st[low].a[i] * x;           if (ret <= lim || ret > n) continue;           ins[ret] = 1;         }       for (i = 0; i < st[low].n; i++)         for (j = 0; j < st[low].n; j++)           for (x = 1; x <= 8; x <<= 1) {             ret = st[low].a[i] + st[low].a[j] * x;             if (ret <= lim || ret > n) continue;             ins[ret] = 1;           }       for (i = lim + 1; i <= n; i++)         if (ins[i]) {           st[++top].n = st[low].n;           for (j = 0; j < st[low].n; j++) st[top].a[j] = st[low].a[j];           st[top].a[st[top].n++] = i;           st[top].p = low;           if (i == n) {             printf( %d n , st[top].n - 1);             Print(top);             return 0;           }         }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   queue<long long> q1;   long long a[20005];   long long l, r;   int main(void) {     int i = 0;     int j;     cin >> l >> r;     q1.push(0);     while (1) {       a[i] = q1.front() * 10 + 4;       i++;       if (a[i - 1] >= r) break;       q1.push(a[i - 1]);       a[i] = q1.front() * 10 + 7;       i++;       if (a[i - 1] >= r) break;       q1.push(a[i - 1]);       q1.pop();     }     long long sum = 0;     for (j = 0; j < i; j++) {       if (l <= a[j] && r > a[j]) {         sum += a[j] * (a[j] + 1 - l);         l = a[j] + 1;       } else if (l <= a[j] && r <= a[j]) {         sum += a[j] * (r + 1 - l);         break;       }     }     cout << sum << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = (long long)1e9 + 7;   const long double PI = 3.141592653589793238462643383279502884197;   long long fac[1] = {1}, inv[1] = {1};   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   long long mp(long long a, long long b) {     long long ret = 1;     while (b) {       if (b & 1) ret = ret * a % MOD;       a = a * a % MOD;       b >>= 1;     }     return ret;   }   long long cmb(long long r, long long c) {     return fac[r] * inv[c] % MOD * inv[r - c] % MOD;   }   vector<int> v[1000000], rv[1000000];   char visit[1000000], mark[1000000];   int main() {     int n, m;     scanf( %d %d , &n, &m);     while (m--) {       int a, b;       scanf( %d %d , &a, &b);       a--;       b--;       v[a].push_back(b);       rv[b].push_back(a);     }     for (int i = 0; i < n; i++) {       if (visit[i] == 0) {         visit[i] = 1;         mark[i] = 1;         for (int j : v[i]) visit[j] = 1;       }     }     int cnt = 0;     for (int i = n - 1; i >= 0; i--) {       if (mark[i]) {         for (int j : rv[i])           if (mark[j]) mark[i] = 0;         cnt += mark[i];       }     }     printf( %d n , cnt);     for (int i = 0; i < n; i++)       if (mark[i]) printf( %d  , i + 1);   }


///====================== TEMPLATE STARTS HERE =====================///   #include <bits/stdc++.h>   using namespace std;      #define endl   n    #define pb push_back   #define MP make_pair   #define ff first   #define ss second   #define ABS(x) ((x)<0?-(x):(x))   #define FABS(x) ((x)+eps<0?-(x):(x))   #define LCM(x,y) (((x)/gcd((x),(y)))*(y))   #define POPCOUNT __builtin_popcountll   #define Set(N,p) ((N)|((1LL)<<(p)))   #define Reset(N,p) ((N)&(~((1LL)<<(p))))   #define Check(N,p) (!(((N)&((1LL)<<(p)))==(0)))   #define fast_cin ios_base::sync_with_stdio(false);cin.tie(NULL)      #define LL long long   #define LLU long long unsigned int   typedef pair < int, int > pii;   typedef pair < LL, LL > pll;   typedef vector<int> vi;   typedef vector<LL> vl;   typedef vector<pll> vll;      #ifdef s_da_sailor       #define line                    cout <<   n=================== n        #define trace(...)              __f( #__VA_ARGS__ , __VA_ARGS__ )       template <typename Arg1>       void __f(const char* name, Arg1&& arg1){           cerr << name <<   =   << arg1 <<   n ;       }       template <typename Arg1, typename... Args>       void __f(const char* names, Arg1&& arg1, Args&&... args){           const char* comma = strchr(names + 1,  , );           cerr.write(names, comma - names) <<   =   << arg1 <<   ,  ;       __f(comma + 1, args...);       }   #else       #define line       #define trace(...)   #endif // s_da_sailor      inline LL gcd ( LL a, LL b ) {       a = ABS ( a ); b = ABS ( b );       while ( b ) { a = a % b; swap ( a, b ); } return a;   }      LL ext_gcd ( LL A, LL B, LL *X, LL *Y ){       LL x2, y2, x1, y1, x, y, r2, r1, q, r;       x2 = 1; y2 = 0;       x1 = 0; y1 = 1;       for (r2 = A, r1 = B; r1 != 0; r2 = r1, r1 = r, x2 = x1, y2 = y1, x1 = x, y1 = y ) {           q = r2 / r1;           r = r2 % r1;           x = x2 - (q * x1);           y = y2 - (q * y1);       }       *X = x2; *Y = y2;       return r2;   }      inline LL modInv ( LL a, LL m ) {       LL x, y;       ext_gcd( a, m, &x, &y );       x %= m;       if ( x < 0 ) x += m;       return x;   }      inline LL bigmod ( LL a, LL p, LL m ) {       LL res = 1 % m, x = a % m;       while ( p ) {           if ( p & 1 ) res = ( res * x ) % m;           x = ( x * x ) % m; p >>= 1; /// For bigmod2 multiply here using mulmod       }       return res;   }         //int knightDir[8][2] = { {-2,1},{-1,2},{1,2},{2,1},{2,-1},{-1,-2},{1,-2},{-2,-1} };   //int dir4[4][2] = {{-1,0},{0,1},{1,0},{0,-1}};   //int dir8[8][2] = {{-1,0},{0,1},{1,0},{0,-1},{-1,-1},{1,1},{1,-1},{-1,1}};   const LL inf = 2147383647;   const LL mod = 1000000007;   const double pi = 2 * acos ( 0.0 );   const double eps = 1e-11;   //mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); /// For generating random numbers      ///======================  TEMPLATE ENDS HERE  =====================///      #define SIZE 100005      int ks;      string S;   int n, A[SIZE];      void solve() {       cin >> S;          n = S.size();       for(int i=0; i<n; i++) {           A[i] = S[i] -  a ;       }          int curr = 30;          for(int i=0; i<n; i++) {           if(i>=1 && A[i-1]==A[i]) {               A[i] = curr;               curr++;           }           else if(i>=2 && A[i-2]==A[i]) {               A[i] = curr;               curr++;           }       }          cout << curr-30 << endl;   }      int main () {       #ifdef s_da_sailor       freopen (  input.txt ,  r , stdin );       //freopen (  output.txt ,  w , stdout );       #endif // s_da_sailor          fast_cin;          int tc;       cin >> tc;          for(ks=1; ks<=tc; ks++) {           solve();       }          return 0;   }


#include <bits/stdc++.h>   using namespace std;   char s[105], pos[105], p[105], cmp[105];   int main() {     int n = 0, k = 0;     scanf( %d%d , &n, &k);     scanf( %s , p);     scanf( %s , pos);     for (int i = 0; i < n; ++i) {       s[i] =  * ;     }     int lenp = strlen(p);     for (int i = 0; i < n - lenp + 1; ++i) {       if (pos[i] ==  1 ) {         for (int j = 0; j < lenp; ++j) {           s[i + j] = p[j];         }       }     }     for (int i = 0; i < n; ++i) {       bool isSame = true;       for (int j = 0; j < lenp && i + j < n; ++j) {         if (s[i + j] ==  * ) {           s[i + j] = p[j] ==  a  ?  b  :  a ;           isSame = false;           break;         } else if (s[i + j] != p[j]) {           if (pos[i] ==  1 ) {             printf( No solution );             return 0;           } else {             isSame = false;             break;           }         }       }       if (isSame && pos[i] ==  0 ) {         printf( No solution );         return 0;       }     }     for (int i = 0; i < n; ++i) {       printf( %c , s[i]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using namespace std::chrono;   template <typename A>   ostream &operator<<(ostream &cout, vector<A> const &v);   template <typename A, typename B>   ostream &operator<<(ostream &cout, pair<A, B> const &p) {     return cout <<  (  << p.first <<  ,   << p.second <<  ) ;   }   template <typename A>   ostream &operator<<(ostream &cout, vector<A> const &v) {     cout <<  [ ;     for (int i = 0; i < v.size(); i++) {       if (i) cout <<  ,  ;       cout << v[i];     }     return cout <<  ] ;   }   template <typename A, typename B>   istream &operator>>(istream &cin, pair<A, B> &p) {     cin >> p.first;     return cin >> p.second;   }   mt19937 rng(steady_clock::now().time_since_epoch().count());   void usaco(string filename) {     freopen((filename +  .in ).c_str(),  r , stdin);     freopen((filename +  .out ).c_str(),  w , stdout);   }   const long double pi = 3.14159265358979323846;   const long long mod = 1000000007;   long long n, m, k, q, Q, T, l, r, x, y, z;   long long a[1000005];   long long b[1000005];   long double c[1000005];   string second, t;   long long ans = 0;   double shoelace(double X[], double Y[], int n) {     double area = 0.0;     int j = n - 1;     for (int i = 0; i < n; i++) {       area += (X[j] + X[i]) * (Y[j] - Y[i]);       j = i;     }     return abs(area / 2.0);   }   int main() {     {       ios_base::sync_with_stdio(false);       cin.tie(NULL);       cout.tie(NULL);     };     for (int ele = 0; ele < 6; ele++) cin >> a[ele];     ;     double X[6], Y[6];     double ang = 0;     double x = 0, y = 0;     for (long long i = 0; i < (6); i++) {       X[i] = x;       Y[i] = y;       x += a[i] * cos(ang);       y += a[i] * sin(ang);       ang += pi / 3;     }     cout << (long long)(2 * shoelace(X, Y, 6) / 0.86602540378 + 0.5) << endl;   }


#include <bits/stdc++.h>   using namespace std;   void lwr(string& s) {     for (int i = 0; i < s.size(); i++) {       if (s[i] >=  A  and s[i] <=  Z ) s[i] = s[i] -  A  +  a ;     }   }   pair<int, int> _rank(const string& s) {     int ret = 0;     for (int i = 0; i < s.size(); i++) ret += s[i] ==  r ;     return pair<int, int>(ret, (int)s.size());   }   map<string, int> who;   const int N = 300010;   pair<int, int> val[N];   vector<int> g[N], gt[N];   int vis[N];   int c[N];   vector<int> ts;   void dfs(int u) {     vis[u] = 1;     for (int v : g[u])       if (!vis[v]) dfs(v);     ts.push_back(u);   }   pair<int, int> valc[N];   void dfst(int u, int cmp) {     vis[u] = 2;     c[u] = cmp;     valc[cmp] = min(valc[cmp], val[u]);     for (int v : gt[u])       if (vis[v] != 2) dfst(v, cmp);   }   vector<int> gc[N];   pair<int, int> best[N];   pair<int, int> solve(int u) {     if (best[u].first != 0x3f3f3f3f) return best[u];     best[u] = valc[u];     for (int v : gc[u]) best[u] = min(best[u], solve(v));     return best[u];   }   int main() {     ios::sync_with_stdio(0);     int m, cnt = 0;     cin >> m;     vector<int> vv;     for (int i = 0; i < m; i++) {       string s;       cin >> s;       lwr(s);       if (!who.count(s)) {         who[s] = cnt;         val[cnt] = _rank(s);         cnt++;       }       vv.push_back(who[s]);     }     int n;     cin >> n;     for (int i = 0; i < n; i++) {       string u, v;       cin >> u >> v;       lwr(u);       lwr(v);       if (!who.count(u)) {         who[u] = cnt;         val[cnt] = _rank(u);         cnt++;       }       if (!who.count(v)) {         who[v] = cnt;         val[cnt] = _rank(v);         cnt++;       }       int uu = who[u], vv = who[v];       g[uu].push_back(vv);       gt[vv].push_back(uu);     }     for (int i = 0; i < cnt; i++) {       if (!vis[i]) dfs(i);     }     int comp = 0;     fill(valc, valc + N, pair<int, int>(0x3f3f3f3f, 0x3f3f3f3f));     for (int i = cnt - 1; i >= 0; i--) {       if (vis[ts[i]] != 2) dfst(ts[i], comp++);     }     for (int u = 0; u < cnt; u++) {       for (int v : g[u]) {         if (c[u] != c[v]) gc[c[u]].push_back(c[v]);       }     }     fill(best, best + N, pair<int, int>(0x3f3f3f3f, 0x3f3f3f3f));     pair<long long, long long> ans(0LL, 0LL);     for (int i = 0; i < m; i++) {       pair<int, int> ret = solve(c[vv[i]]);       ans.first += ret.first;       ans.second += ret.second;     }     cout << ans.first <<     << ans.second <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int t, n, a[100005];   vector<int> v[100005];   int val[100005];   int k[100005];   int main() {     for (int i = 2; i <= 100000; i++) {       v[i].push_back(1);       for (int j = i + i; j <= 100000; j += i) {         v[j].push_back(i);       }     }     scanf( %d , &t);     while (t--) {       memset(k, 0, sizeof(k));       scanf( %d , &n);       for (int i = 1; i <= n; i++) {         scanf( %d , &a[i]);       }       for (int i = n; i >= 1; i--) {         if (k[i] == 0) k[i] = 1;         int p = v[i].size();         for (int j = 0; j < p; j++) {           if (a[i] > a[v[i][j]]) k[v[i][j]] = max(k[v[i][j]], k[i] + 1);         }       }       int mx = 0;       for (int i = 1; i <= n; i++) {         mx = max(mx, k[i]);       }       printf( %d n , mx);     }     return 0;   }


#include <bits/stdc++.h>   int a[500005][9] = {0};   int nnf[500005] = {0};   int pn[200005] = {0};   int val[200005];   int x, in;   void print(int *a, int n) {     int i;     for (i = 0; i < n; i++) printf( %d  , a[i]);     printf(  n );   }   long long int check(int cnt, int val, int d) {     if (in == -1) nnf[val] += in;     long long int q = d * nnf[val], i;     for (i = cnt + 1; i <= a[x][0]; i++) q += check(i, val * a[x][i], -d);     if (in == 1) nnf[val] += in;     return q;   }   int main() {     a[1][0] = 1;     a[1][1] = 1;     int i, j;     for (i = 1; i < 500001; i++) {       if (a[i][0] == 1) {         for (j = i; j < 500001; j += i) {           a[j][0] += 1;           a[j][a[j][0]] = i;         }       }     }     a[1][0] = 1;     int n, q;     long long int ans = 0;     scanf( %d %d , &n, &q);     for (i = 1; i <= n; i++) scanf( %d , &val[i]);     for (i = 0; i < q; i++) {       scanf( %d , &j);       if (pn[j] == 1)         in = -1;       else         in = 1;       pn[j] = pn[j] ^ 1;       x = val[j];       ans += check(1, 1, in);       printf( %lld n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int N, K, L;   int pre[1000005];   long long dp[1000005];   int cnt[1000005];   string s;   pair<int, int> chk(long long C) {     fill(dp + 1, dp + 1 + N, 0);     fill(cnt + 1, cnt + 1 + N, 0);     for (int i = 1; i <= N; i++) {       dp[i] = dp[i - 1];       cnt[i] = cnt[i - 1];       if (i >= L) {         long long v = dp[i - L] + pre[i] - pre[i - L] - C;         if ((dp[i] == v && cnt[i - L] + 1 < cnt[i]) || (dp[i] < v)) {           dp[i] = v;           cnt[i] = cnt[i - L] + 1;         }       } else {         long long v = pre[i] - C;         if ((dp[i] < v)) {           dp[i] = v;           cnt[i] = 1;         }       }     }     return {dp[N], cnt[N]};   }   int solve(char lb, char ub) {     for (int i = 1; i <= N; i++) {       pre[i] = (s[i - 1] >= lb && s[i - 1] <= ub);       pre[i] += pre[i - 1];     }     long long l = 0, r = N + 1;     int ret = 0;     while (l <= r) {       long long mid = (l + r) / 2;       auto res = chk(mid);       if (res.second <= K) {         ret = mid;         r = mid - 1;       } else {         l = mid + 1;       }     }     return pre[N] - (chk(ret).first + 1LL * K * ret);   }   int main() {     cin.sync_with_stdio(0);     cin.tie(0);     cin >> N >> K >> L >> s;     int ret = min(solve( a ,  z ), solve( A ,  Z ));     cout << ret << endl;   }


#include <bits/stdc++.h>   const int N = 1010;   int n, k, a[N], a2[N], used[N], m, d, ans;   std::list<int> list;   int t;   void spendTimeUntil(int setSz) {     while (list.size() > setSz) {       d = round(100 * (double)m / (double)n);       for (int x : list) {         if (a2[x] + 1 == d && !used[x]) {           used[x] = 1;           ans++;         }       }       for (auto it = list.begin(); it != list.end();) {         if (++a2[*it] != a[*it])           it++;         else {           it = list.erase(it);           m++;         }       }     }   }   int main() {     scanf( %d%d , &n, &k);     for (int i = 0; i < n; i++) {       scanf( %d , a + i);       if (list.size() < k)         list.push_back(i);       else {         spendTimeUntil(k - 1);         list.push_back(i);       }     }     spendTimeUntil(0);     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void fun() {}   const long long int inf = 1e18;   const long long int md = 1e9 + 7;   const long long int N = 300050;   long long int __gcd(long long int a, long long int b) {     if (b == 0) return a;     return __gcd(b, a % b);   }   long long int poww(long long int a, long long int b, long long int md) {     if (b < 0) return 0;     if (a == 0) return 0;     long long int res = 1;     while (b) {       if (b & 1) {         res = (1ll * res * a) % md;       }       a = (1ll * a * a) % md;       b >>= 1;     }     return res;   }   long long int poww(long long int a, long long int b) {     if (b < 0) return 0;     if (a == 0) return 0;     long long int res = 1;     while (b) {       if (b & 1) {         res = (1ll * res * a);       }       a = (1ll * a * a);       b >>= 1;     }     return res;   }   long long int divide(long long int a, long long int b, long long int md) {     long long int rr = a * (poww(b, md - 2, md));     rr %= md;     return rr;   }   long long int lcm(long long int a, long long int b) {     return (a * b) / __gcd(a, b);   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     long long int t;     cin >> t;     while (t--) {       long long int l, r;       cin >> l >> r;       if (2 * l > r)         cout <<  YES  << endl;       else         cout <<  NO  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> v[27];   bool vis[27];   vector<pair<int, int> > pr;   int cnt, flag;   void dfs(int nod, int dest) {     int i;     vis[nod] = 1;     if (nod == dest) {       flag = 1;       return;     }     for (i = 0; i < v[nod].size(); i++) {       int curr = v[nod][i];       if (vis[curr] == 0) {         dfs(curr, dest);       }     }     return;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n, i;     cin >> n;     string s1, s2;     cin >> s1 >> s2;     for (i = 0; i < n; i++) {       flag = 0;       memset(vis, 0, sizeof(vis));       int nod = s1[i] -  a  + 1;       int dest = s2[i] -  a  + 1;       dfs(nod, dest);       if (flag == 0) {         cnt++;         pr.push_back(make_pair(nod, dest));         v[nod].push_back(dest);         v[dest].push_back(nod);       }     }     cout << cnt << endl;     for (i = 0; i < pr.size(); i++) {       char ch1 = pr[i].first +  a  - 1, ch2 = pr[i].second +  a  - 1;       cout << ch1 <<     << ch2 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int t;     cin >> t;     string s;     vector<int> a;     while (t--) {       int x;       cin >> x >> s;       a.resize(x);       int sz = s.size();       for (int i = 0; i < sz && i < x; ++i) {         a[i] = s[i] -  0 ;       }       long long sol = s.size();       for (int i = 1; i <= x; ++i) {         int r = sz;         for (int j = 1; j < a[i - 1] && sz < x; ++j) {           for (int k = i; k < r && sz < x; ++k) {             a[sz] = a[k];             ++sz;           }         }         sol = ((sol - i + MOD) % MOD * a[i - 1] + i) % MOD;       }       cout << sol <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   const int N = 1e6 + 7;   long long p[N];   int main() {     int a, b, c, d;     scanf( %d , &a), scanf( %d , &b), scanf( %d , &c), scanf( %d , &d);     for (int i = a; i < (int)b + 1; i++) {       p[i + b] += 1;       p[i + c + 1] -= 1;     }     for (int i = 1; i < (int)N; i++) p[i] += p[i - 1];     for (int i = 1; i < (int)N; i++) p[i] += p[i - 1];     long long val = 0;     for (int i = c; i < (int)d + 1; i++) val += p[N - 1] - p[i];     printf( %lld n , val);   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast ,  unroll-loops ,  no-stack-protector )   using namespace std;   int32_t main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long test = 1;     while (test--) {       long long x, y;       cin >> x >> y;       long long n;       cin >> n;       long long hash[7];       hash[0] = 0;       hash[1] = x;       hash[2] = y;       hash[3] = (y - x + 1000000007) % 1000000007;       hash[4] = (-1 * x + 1000000007) % 1000000007;       hash[5] = (-1 * y + 1000000007) % 1000000007;       hash[6] = (x - y + 1000000007) % 1000000007;       long long rem = (n) % 6;       if (rem == 0) rem = 6;       long long ans = hash[rem];       cout << (ans + 1000000007) % 1000000007;     }     cerr << endl          <<  Time:   << (clock() * 1000. / CLOCKS_PER_SEC) <<   ms  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long leftBinarySearch(long long* color, long long size, long long target) {     int l = 0;     int r = size - 1;     int idx = -1;     while (l <= r) {       int m = l + (r - l) / 2;       if (color[m] <= target) {         l = m + 1;         idx = m;       } else {         r = m - 1;       }     }     return idx;   }   long long rightBinarySearch(long long* color, long long size,                               long long target) {     int l = 0;     int r = size - 1;     int idx = -1;     while (l <= r) {       int m = l + (r - l) / 2;       if (color[m] >= target) {         r = m - 1;         idx = m;       } else {         l = m + 1;       }     }     return idx;   }   int main() {     int t;     cin >> t;     while (t--) {       long long r, g, b;       cin >> r >> g >> b;       long long red[r], green[g], blue[b];       for (int i = 0; i < r; i++) cin >> red[i];       for (int i = 0; i < g; i++) cin >> green[i];       for (int i = 0; i < b; i++) cin >> blue[i];       sort(red, red + r);       sort(green, green + g);       sort(blue, blue + b);       long long ans = LLONG_MAX;       long long left, right;       for (int i = 0; i < r; i++) {         left = leftBinarySearch(green, g, red[i]);         right = rightBinarySearch(blue, b, red[i]);         if (left != -1 and right != -1)           ans =               min(ans, (green[left] - blue[right]) * (green[left] - blue[right]) +                            (red[i] - green[left]) * (red[i] - green[left]) +                            (red[i] - blue[right]) * (red[i] - blue[right]));         left = leftBinarySearch(blue, b, red[i]);         right = rightBinarySearch(green, g, red[i]);         if (left != -1 and right != -1)           ans =               min(ans, (blue[left] - green[right]) * (blue[left] - green[right]) +                            (red[i] - blue[left]) * (red[i] - blue[left]) +                            (red[i] - green[right]) * (red[i] - green[right]));       }       for (int i = 0; i < g; i++) {         left = leftBinarySearch(red, r, green[i]);         right = rightBinarySearch(blue, b, green[i]);         if (left != -1 and right != -1)           ans = min(ans, (red[left] - blue[right]) * (red[left] - blue[right]) +                              (green[i] - red[left]) * (green[i] - red[left]) +                              (green[i] - blue[right]) * (green[i] - blue[right]));         left = leftBinarySearch(blue, b, green[i]);         right = rightBinarySearch(red, r, green[i]);         if (left != -1 and right != -1)           ans = min(ans, (blue[left] - red[right]) * (blue[left] - red[right]) +                              (green[i] - blue[left]) * (green[i] - blue[left]) +                              (green[i] - red[right]) * (green[i] - red[right]));       }       for (int i = 0; i < b; i++) {         left = leftBinarySearch(red, r, blue[i]);         right = rightBinarySearch(green, g, blue[i]);         if (left != -1 and right != -1)           ans = min(ans, (red[left] - green[right]) * (red[left] - green[right]) +                              (blue[i] - red[left]) * (blue[i] - red[left]) +                              (blue[i] - green[right]) * (blue[i] - green[right]));         left = leftBinarySearch(green, g, blue[i]);         right = rightBinarySearch(red, r, blue[i]);         if (left != -1 and right != -1)           ans = min(ans, (green[left] - red[right]) * (green[left] - red[right]) +                              (blue[i] - green[left]) * (blue[i] - green[left]) +                              (blue[i] - red[right]) * (blue[i] - red[right]));       }       cout << ans << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n, k, i, tt = 1, a, b;     cin >> n >> k;     vector<pair<int, int> > p;     for (i = 0; i < n; i++) {       cin >> a >> b;       p.push_back(make_pair(-a, b));     }     sort(p.begin(), p.end());     for (i = k - 1; i < n - 1; i++) {       if (p[i].first == p[i + 1].first && p[i].second == p[i + 1].second)         tt += 1;       else         break;     }     for (i = k - 1; i > 0; i--) {       if (p[i].first == p[i - 1].first && p[i].second == p[i - 1].second)         tt += 1;       else         break;     }     cout << tt;   }


#include <bits/stdc++.h>   using namespace std;      const int N = (int) 1e7 + 100;      long long s[N];   int d[N];   int ans[N];      int main() {     fill(d, d + N, -1);     d[1] = 1;     for (int i = 2; i * i < N; i++) {       if (d[i] == -1) {         d[i] = i;         for (int j = i * i; j < N; j += i) {           if (d[j] == -1) {             d[j] = i;           }         }       }     }     s[1] = 1;     for (int i = 2; i < N; i++) {       if (d[i] == -1) {         d[i] = i;         s[i] = i + 1;       } else {         int j = i;         s[i] = 1;         while (j % d[i] == 0) {           j /= d[i];           s[i] = s[i] * d[i] + 1;         }         s[i] *= s[j];       }     }     fill(ans, ans + N, -1);     for (int i = N - 1; i > 0; i--) {       if(s[i]<N){  // avoiding overflow.       ans[s[i]] = i;      }                     }     int tests;     cin >> tests;     while (tests-- > 0) {       int c;       cin >> c;       cout << ans[c] << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int const N = 2e5 + 5;   vector<vector<int> > adj(N);   long long a[N];   pair<pair<long long, long long>, long long> dfs(int u, int prt = 0) {     if (adj[u].empty()) return {{1, a[u]}, a[u]};     pair<pair<long long, long long>, long long> ret = {{0, 0}, 0};     for (int v : adj[u]) {       if (v == prt) continue;       auto ch = dfs(v, u);       ret.first.first += ch.first.first, ret.first.second += ch.first.second;       ret.second = max(ret.second, ch.second);     }     long long k = ret.second * ret.first.first - ret.first.second;     long long rem = a[u] - min(a[u], k);     ret.second += rem / ret.first.first + (rem % ret.first.first != 0);     ret.first.second += a[u];     return ret;   }   int main() {     ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);     int n;     cin >> n;     for (int i = 2; i <= n; i++) {       int p;       cin >> p;       adj[p].push_back(i);     }     for (int i = 1; i <= n; i++) cin >> a[i];     cout << dfs(1).second << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   int n;   char cmd[1000001];   bool sym(int p) {     int rm = 0, cur = 0;     for (int i = 0; i < n - 1; ++i) {       if (cur > p + 1 && cmd[i] ==  L )         cur--;       else if (cmd[i] ==  R )         rm = max(rm, ++cur);     }     return cur + 1 > rm;   }   int main() {     scanf( %s , cmd);     n = strlen(cmd);     if (cmd[n - 1] ==  L )       for (int i = 0; i < n; ++i) cmd[i] = cmd[i] ==  R  ?  L  :  R ;     if (sym(-mod))       puts( 1 );     else {       int a = -mod, b = 0;       while (b - a > 1) {         int m = (a + b) >> 1;         if (sym(m))           b = m;         else           a = m;       }       printf( %d n , -b);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long int t;     cin >> t;     while (t--) {       long long int n, k;       cin >> n >> k;       vector<long long int> a(n);       for (int i = 0; i < n; i++) cin >> a[i];       vector<long long int> pks;       for (int i = 1; i < n - 1; i++) {         if (a[i] > a[i - 1] && a[i] > a[i + 1]) pks.push_back(i);       }       long long int maxi = 0, l = 0;       for (long long int i = 0; i <= n - k; i++) {         long long int tmp1 = upper_bound(pks.begin(), pks.end(), i) - pks.begin();         long long int tmp2 =             lower_bound(pks.begin(), pks.end(), i + k - 1LL) - pks.begin();         long long int cnt = tmp2 - tmp1;         if (cnt > maxi) {           maxi = cnt;           l = i;         }       }       cout << maxi + 1 <<     << l + 1 << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, x;     scanf( %d %d %d , &a, &b, &x);     if (a != 0 && a >= b) {       a = a - (a / b) * b;     }     a *= 10;     int cont = 0;     vector<int> v;     while (cont <= b && a != 0) {       if (a < b) {         v.push_back(0);       } else {         v.push_back(a / b);         a = a - (a / b) * b;       }       a *= 10;       cont++;     }     if (a == 0) v.push_back(0);     if (find(v.begin(), v.end(), x) != v.end()) {       printf( %d n , (find(v.begin(), v.end(), x) - v.begin()) + 1);     } else       puts( -1 );   }


#include <bits/stdc++.h>   using namespace std;   int ans;   void solve(long long n, long long l1, long long r1, long long l, long long r) {     if (n == 0 || l1 > r || r1 < l) return;     long long mid = (l1 + r1) >> 1;     if (mid >= l && mid <= r) ans += (n % 2);     solve(n / 2, l1, mid - 1, l, r);     solve(n / 2, mid + 1, r1, l, r);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long n, l, r;     cin >> n, cin >> l, cin >> r;     long long tmp = n, var = 0;     while (tmp > 0) {       tmp /= 2;       var++;     }     long long num = (1LL << var) - 1;     solve(n, 1, num, l, r);     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     int n;     cin >> n;     cout << (n % 4 == 0 ?  YES  :  NO ) <<   n ;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int t;     cin >> t;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long arr[300000];   int main() {     long long n, m;     scanf( %lld %lld , &n, &m);     for (long long i = 1; i <= n; i++) {       scanf( %lld , &arr[i]);     }     string s;     cin >> s;     long long len = s.size();     long long ans = 0;     for (long long i = 0; i < len; i++) {       char c = s[i];       priority_queue<long long> q;       long long j = i;       while (s[j] == c && j < len) {         q.push(arr[j + 1]);         i = j;         j++;       }       long long temp = m;       while (temp > 0 && !q.empty()) {         long long keep = q.top();         ans += keep;         q.pop();         temp--;       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int mod(long long int x) {     return (((x) % 1000000007) + 1000000007) % 1000000007;   }   long long int mod1(long long int x, long long int m) {     return (((x) % m) + m) % m;   }   long long int solve() {     long long int n, k;     cin >> n >> k;     long long int s[n + 1];     for (long long int i = 1; i < n + 1; i++) {       long long int p;       cin >> p;       if (p == 0)         s[i] = (k < i - 1 ? k : i - 1) + 1;       else         s[i] = s[p] + (2 * k < i - p - 1 ? 2 * k : i - p - 1) + 1;       cout << s[i] + (k < n - i ? k : n - i) <<   n ;     }     return 0;   }   signed main() {     ios::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     long long int t;     t = 1;     while (t--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, len;   char str[55][25];   long long f[(1 << 20) + 10], bin[55];   double ans[(1 << 20) + 10];   double res;   int main() {     int i, j, k, c;     bin[0] = 1;     for (i = 1; i < 55; i++) bin[i] = (bin[i - 1] << 1);     scanf( %d , &n);     for (i = 0; i < n; i++) scanf( %s , str[i]);     len = strlen(str[1]);     for (i = 0; i < n; i++) {       for (j = 0; j < n; j++) {         if (i != j) {           int same = 0;           for (k = 0; k < len; k++) {             if (str[i][k] == str[j][k]) same |= bin[k];           }           f[same] |= bin[j];         }       }     }     for (i = bin[len] - 1; i >= 0; i--) {       for (j = 0; j < len; j++) {         if (i & bin[j]) {           f[i ^ bin[j]] |= f[i];         }       }     }     ans[0] = 1;     for (i = 0; i < bin[len]; i++) {       for (c = j = 0; j < len; j++) {         if (i & bin[j]) c++;       }       for (j = 0; j < len; j++) {         if (!(i & bin[j])) ans[i | bin[j]] += ans[i] / (len - c);       }       for (j = 0; j < n; j++) {         if (f[i] & bin[j]) res += ans[i];       }     }     printf( %.10f n , res / n);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     ;     long long int n, k;     cin >> n >> k;     int a[n + 1];     for (int i = (1); i <= (n); i++) cin >> a[i];     long long int d = 1 + 8 * k;     long long int x = (long long int)floor(((sqrt(d) - 1) / 2));     if (n == 1)       cout << a[1] << endl;     else {       if ((x * (x + 1)) / 2 == k)         cout << a[x] << endl;       else         cout << a[k - (x * (x + 1)) / 2] << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool check_prime(long long n) {     long long flag = 0;     for (long long i = 2; i * i <= n; i++) {       if (n % i == 0) {         flag = 1;         break;       }     }     if (n == 1)       return false;     else if (flag == 0 || n == 2 || n == 3) {       return true;     } else {       return false;     }   }   long long BE(long long x, long long n, long long m) {     long long result = 1;     while (n > 0) {       if (n % 2 == 1) result = result * x % m;       x = x * x % m;       n = n / 2;     }     return result;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(0);     long long n;     cin >> n;     long long x[n], h[n];     long long cnt = 2;     for (long long i = 0; i < n; i++) {       cin >> x[i] >> h[i];     }     for (long long i = 1; i < n - 1; i++) {       if (x[i] - x[i - 1] - 1 >= h[i]) {         cnt++;       } else if (x[i] + h[i] < x[i + 1]) {         cnt++;         x[i] += h[i];       }     }     if (n == 1) {       cout << 1 <<   n ;     } else       cout << cnt <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct data {     int val;     int col;     vector<int> vec;   } arr[100005];   void connect(int a, int b) {     arr[a].vec.push_back(b);     arr[b].vec.push_back(a);   }   int goal[100005];   vector<int> ans;   void dfs(int n, int fl, int flip, int flip1) {     arr[n].col = 1;     if (fl % 2 == 0) {       if (flip % 2 == 0) {         if (arr[n].val != goal[n]) {           if (arr[n].val == 0)             arr[n].val = 1;           else             arr[n].val = 0;           ans.push_back(n);           flip++;         } else {         }       } else {         if (arr[n].val == 0)           arr[n].val = 1;         else           arr[n].val = 0;         if (arr[n].val != goal[n]) {           if (arr[n].val == 0)             arr[n].val = 1;           else             arr[n].val = 0;           ans.push_back(n);           flip++;         }       }     } else {       if (flip1 % 2 == 0) {         if (arr[n].val != goal[n]) {           if (arr[n].val == 0)             arr[n].val = 1;           else             arr[n].val = 0;           ans.push_back(n);           flip1++;         }       } else {         if (arr[n].val == 0)           arr[n].val = 1;         else           arr[n].val = 0;         if (arr[n].val != goal[n]) {           if (arr[n].val == 0)             arr[n].val = 1;           else             arr[n].val = 0;           ans.push_back(n);           flip1++;         }       }     }     fl++;     for (int i = 0; i < arr[n].vec.size(); i++) {       if (arr[arr[n].vec[i]].col == 0) dfs(arr[n].vec[i], fl, flip, flip1);     }     return;   }   int main() {     ios_base::sync_with_stdio(0);     int n;     cin >> n;     for (int i = 1; i < n; i++) {       int aa, bb;       cin >> aa >> bb;       connect(aa, bb);     }     for (int i = 1; i <= n; i++) {       int v;       cin >> v;       arr[i].val = v;       arr[i].col = 0;     }     for (int i = 1; i <= n; i++) {       cin >> goal[i];     }     dfs(1, 0, 0, 0);     int si = ans.size();     cout << si << endl;     for (int i = 0; i < si; i++) {       cout << ans[i] << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     double p, d, t, f, c;     scanf( %lf %lf %lf %lf %lf , &p, &d, &t, &f, &c);     if (p >= d) return puts( 0 ), 0;     double now = t * p, bizo = 0;     while (now <= c) {       double step = now / (d - p);       if (now + p * step >= c) break;       bizo++;       now = now + (p * step) * 2;       now += p * f;       if (now >= c) break;     }     printf( %.0f n , bizo);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool arr[1000][1000];   void change(int n) {     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         arr[i][j] = !arr[i][j];       }     }   }   int main() {     int n, x, y;     int orig_x;     cin >> n >> x >> y;     orig_x = x;     if (x == 1 && y == 1) {       if (n == 2 || n == 3) {         cout <<  NO  << endl;         return 0;       }       cout <<  YES  << endl;       for (int i = 0; i < n; i++) {         arr[i][(i + 1) % n] = arr[(i + 1) % n][i] = 1;       }       arr[n - 1][0] = arr[0][n - 1] = 0;       for (int i = 0; i < n; i++) {         for (int j = 0; j < n; j++) {           cout << arr[i][j];         }         cout << endl;       }       return 0;     }     if (x == 1 || y == 1) {       if (x + y > n + 1) {         cout <<  NO  << endl;         return 0;       }       cout <<  YES  << endl;     } else {       cout <<  NO  << endl;       return 0;     }     if (x == 1 && y == 1) {       for (int i = 0; i < n; i++) {         arr[i][(i + 1) % n] = 1;         arr[(i + 1) % n][i] = 1;       }       for (int i = 0; i < n; i++) {         for (int j = 0; j < n; j++) {           cout << arr[i][j];         }         cout << endl;       }       return 0;     }     int temp1 = min(x, y);     int temp2 = max(x, y);     x = temp1;     y = temp2;     int cycL = n - y + 1;     for (int i = 0; i < cycL; i++) {       arr[i][(i + 1) % cycL] = 1;       arr[(i + 1) % cycL][i] = 1;     }     if (orig_x == 1) change(n);     for (int i = 0; i < n; i++) {       arr[i][i] = 0;     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         cout << arr[i][j];       }       cout << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int a[100005], b[100005];   long long int n, m, k;   long long int judge(long long int x) {     long long int sum = 0;     for (int t = 0; t < x; t++) {       if (a[n - x + t] < b[t]) {         sum = sum + b[t] - a[n - x + t];       }     }     return sum;   }   int main() {     cin >> n >> m >> k;     for (int t = 0; t < n; t++) {       scanf( %d , &a[t]);     }     sort(a, a + n);     for (int t = 0; t < m; t++) {       scanf( %d , &b[t]);     }     sort(b, b + m);     long long int s1 = 0;     long long int left = 0;     long long int right = min(n, m);     while (left <= right) {       long long int mid = (left + right) >> 1;       if (judge(mid) <= k) {         left = mid + 1;         s1 = mid;       } else         right = mid - 1;     }     long long int ans = 0;     for (int t = 0; t < s1; t++) {       ans += b[t];     }     if (ans - k > 0)       ans = ans - k;     else       ans = 0;     printf( %lld %lld n , s1, ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 10;   vector<int> G[N];   vector<pair<int, pair<int, int> > > query;   int color[N], Ecolor[2 * N], f[N], s[2 * N], start[N], finish[N], ans[N];   int n, m, u, v, cnt;   int block_size;   void dfs(int u) {     start[u] = ++cnt;     Ecolor[cnt] = color[u];     for (int i = 0; i < G[u].size(); ++i) {       int v = G[u][i];       if (!start[v]) dfs(v);     }     finish[u] = ++cnt;     Ecolor[cnt] = color[u];   }   bool mo_cmp(pair<int, pair<int, int> > p, pair<int, pair<int, int> > q) {     u = p.second.first, v = q.second.first;     if (start[u] / block_size == start[v] / block_size)       return finish[u] < finish[v];     return start[u] / block_size < start[v] / block_size;   }   void add(int pos) {     f[Ecolor[pos]]++;     s[f[Ecolor[pos]]]++;   }   void rem(int pos) {     s[f[Ecolor[pos]]]--;     f[Ecolor[pos]]--;   }   int main() {     ios::sync_with_stdio(false);     cin >> n >> m;     block_size = sqrt(n);     for (int i = 1; i <= n; ++i) cin >> color[i];     for (int i = 1; i < n; ++i) {       cin >> u >> v;       G[u].push_back(v);       G[v].push_back(u);     }     dfs(1);     for (int i = 0; i < m; ++i) {       cin >> u >> v;       query.push_back(pair<int, pair<int, int> >(i, pair<int, int>(u, v)));     }     sort(query.begin(), query.end(), mo_cmp);     int curL = 1, curR = 1;     add(1);     for (int i = 0; i < query.size(); ++i) {       int p = query[i].second.first;       while (curL < start[p]) {         rem(curL);         curL++;       }       while (curL > start[p]) {         curL--;         add(curL);       }       while (curR < finish[p]) {         curR++;         add(curR);       }       while (curR > finish[p]) {         rem(curR);         curR--;       }       ans[query[i].first] = s[query[i].second.second * 2];     }     for (int i = 0; i < m; ++i) cout << ans[i] <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int test;     cin >> test;     for (int i = 0; i < test; i++) {       int n, k;       cin >> n >> k;       if ((n % 2 != 0 && k % 2 == 0) || k > n)         cout <<  NO  << endl;       else {         if (n % 2 == 0) {           if (k % 2 != 0) {             if (k * 2 > n)               cout <<  NO  << endl;             else {               cout <<  YES  << endl;               for (int j = 0; j < k - 1; j++)                 cout <<  2                       <<    ;               cout << n - (2 * (k - 1)) << endl;             }           } else {             cout <<  YES  << endl;             for (int j = 0; j < k - 1; j++)               cout <<  1                     <<    ;             cout << n - (k - 1) << endl;           }         } else {           cout <<  YES  << endl;           for (int j = 0; j < k - 1; j++)             cout <<  1                   <<    ;           cout << n - (k - 1) << endl;         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, t;     cin >> n >> t;     if (t <= 203) {       int dp[n * t + 1][301];       memset(dp, 0, sizeof(dp));       int ar[n * t];       int N = n * t;       for (int ctr1 = 0; ctr1 < N; ctr1++) {         if (ctr1 < n)           cin >> ar[ctr1];         else           ar[ctr1] = ar[ctr1 - n];       }       for (int ctr1 = 1; ctr1 <= N; ctr1++) {         for (int ctr2 = 0; ctr2 <= ar[ctr1 - 1]; ctr2++) {           dp[ctr1][ar[ctr1 - 1]] =               max(dp[ctr1][ar[ctr1 - 1]], 1 + dp[ctr1 - 1][ctr2]);         }         for (int ctr2 = 0; ctr2 <= 300; ctr2++)           dp[ctr1][ctr2] = max(dp[ctr1][ctr2], dp[ctr1 - 1][ctr2]);       }       int r = 0;       for (int ctr1 = 0; ctr1 <= 300; ctr1++) r = max(r, dp[N][ctr1]);       cout << r << endl;       return 0;     } else {       int dp[n * 101 + 1][301];       memset(dp, 0, sizeof(dp));       int ar[n * 101];       int N = n * 101;       int poj[301];       memset(poj, 0, sizeof(poj));       for (int ctr1 = 0; ctr1 < N; ctr1++) {         if (ctr1 < n) {           cin >> ar[ctr1];           poj[ar[ctr1]]++;         } else           ar[ctr1] = ar[ctr1 - n];       }       for (int ctr1 = 1; ctr1 <= N; ctr1++) {         for (int ctr2 = 0; ctr2 <= ar[ctr1 - 1]; ctr2++) {           dp[ctr1][ar[ctr1 - 1]] =               max(dp[ctr1][ar[ctr1 - 1]], 1 + dp[ctr1 - 1][ctr2]);         }         for (int ctr2 = 0; ctr2 <= 300; ctr2++)           dp[ctr1][ctr2] = max(dp[ctr1][ctr2], dp[ctr1 - 1][ctr2]);       }       int dp2[n * 101 + 1][301];       memset(dp2, 0, sizeof(dp2));       for (int ctr1 = N - 1; ctr1 >= 0; ctr1--) {         for (int ctr2 = 300; ctr2 >= ar[ctr1]; ctr2--) {           dp2[ctr1][ar[ctr1]] = max(dp2[ctr1][ar[ctr1]], 1 + dp2[ctr1 + 1][ctr2]);         }         for (int ctr2 = 1; ctr2 <= 300; ctr2++)           dp2[ctr1][ctr2] = max(dp2[ctr1][ctr2], dp2[ctr1 + 1][ctr2]);       }       int r = 0;       int nt = t - 202;       for (int ctr1 = 1; ctr1 <= 300; ctr1++)         r = max(r, dp[N][ctr1] + dp2[0][ctr1] + nt * poj[ctr1]);       cout << r << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, ans = 0;   string s;   void go(vector<char> k, pair<int, int> start, vector<string> a) {     for (int i = 0; i < s.size(); i++) {       if (s[i] == k[0]) {         start.first--;       }       if (s[i] == k[1]) {         start.first++;       }       if (s[i] == k[2]) {         start.second--;       }       if (s[i] == k[3]) {         start.second++;       }       if (start.first >= n || start.first < 0) {         return;       }       if (start.second >= m || start.second < 0) {         return;       }       if (a[start.first][start.second] ==  # ) {         return;       }       if (a[start.first][start.second] ==  E ) {         ans++;         return;       }     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m;     pair<int, int> start;     vector<string> a(n);     for (int i = 0; i < n; i++) {       cin >> a[i];       for (int j = 0; j < m; j++) {         if (a[i][j] ==  S ) {           start.first = i;           start.second = j;         }       }     }     cin >> s;     vector<char> k = { 0 ,  1 ,  2 ,  3 };     do {       go(k, start, a);     } while (next_permutation(k.begin(), k.end()));     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1 << 17;   pair<int, int> v[MAXN];   set<pair<int, int> > ans;   queue<int> Q;   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> v[i].first >> v[i].second;       if (v[i].first == 1) Q.push(i);     }     while (!Q.empty()) {       int k = Q.front();       Q.pop();       if (v[k].first == 0) continue;       int id = v[k].second;       v[id].first--, v[id].second ^= k;       ans.insert(make_pair(k, id));       if (v[id].first == 1) Q.push(id);     }     cout << ans.size() << endl;     for (auto it = ans.begin(); it != ans.end(); it++) {       pair<int, int> a = *it;       cout << a.first <<     << a.second << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   template <class T>   void print(vector<T>& v, bool spaced = true) {     int n = v.size();     string space = (spaced ?     :   );     for (int i = 0; i < n; ++i) {       cout << v[i] << space;     }     cout <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     int n;     cin >> n;     string s, t;     cin >> s >> t;     map<char, int> m1;     map<char, int> m2;     for (int i = 0; i < n; ++i) {       m1[s[i]]++;       m2[t[i]]++;     }     for (int i = 0; i < n; ++i) {       if (find((t).begin(), (t).end(), s[i]) == t.end()) {         cout << -1 <<   n ;         return 0;       }     }     for (int i = 0; i < n; ++i) {       if (m1[s[i]] != m2[s[i]]) {         cout << -1 <<   n ;         return 0;       }     }     vector<int> moves;     for (int i = 0; i < n; ++i) {       for (int j = i; j < n; ++j) {         if (t[i] == s[j]) {           for (int k = j - 1; k > i - 1; --k) {             swap(s[k], s[k + 1]);             moves.push_back(k + 1);           }           break;         }       }     }     cout << moves.size() <<   n ;     print(moves);     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:66777216 )   using namespace std;   map<char, int> mp;   vector<pair<string, int>> lex;   vector<string> lvl[1000001];   int lex_p = -1;   int max_l = 0;   void rec(int l, int cnt) {     if (l > max_l) max_l = l;     lvl[l].push_back(lex[lex_p].first);     for (int i = 0; i < cnt; i++) {       lex_p++;       rec(l + 1, lex[lex_p].second);     }   }   int main() {     string s;     cin >> s;     int lex_cnt = 0;     string cur_lex =   ;     string str =   ;     for (int i = 0; i < s.length(); i++) {       if (s[i] ==  ,  || i == s.length() - 1) {         lex_cnt++;         if (lex_cnt % 2 == 0) {           int val = 0;           int mn = 1;           for (int j = cur_lex.length() - 1; j >= 0; j--) {             val += (cur_lex[j] -  0 ) * mn;             mn *= 10;           }           lex.push_back(make_pair(str, val));           str =   ;           cur_lex =   ;         } else {           str = cur_lex;           cur_lex =   ;         }       } else         cur_lex += s[i];     }     while (lex_p < int(lex.size()) - 1) {       lex_p++;       rec(0, lex[lex_p].second);     }     cout << max_l + 1 << endl;     for (int i = 0; i < 1000001; i++) {       for (int j = 0; j < lvl[i].size(); j++) cout << lvl[i][j] <<    ;       if (lvl[i].size() > 0) cout << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 10;   const int mx = 999999;   int n, k, q;   long long f[6], dp[N];   int main() {     scanf( %d , &k);     for (int i = 0; i < 6; ++i) scanf( %d , &f[i]);     for (int i = 1; i <= mx; ++i) {       int tmp = i, ct = 0;       while (tmp) {         int x = tmp % 10;         if (x % 3 == 0) dp[i] += f[ct] * (x / 3);         ct++;         tmp /= 10;       }     }     for (int i = 0, x = 3; i < 6; ++i, x = x * 10) {       int tmp = min(3 * (k - 1), mx / x);       for (int j = 1; j <= tmp; tmp -= j, j <<= 1)         for (int w = mx; w >= j * x; --w)           dp[w] = max(dp[w], dp[w - j * x] + j * f[i]);       if (tmp) {         for (int w = mx; w >= tmp * x; --w)           dp[w] = max(dp[w], dp[w - tmp * x] + tmp * f[i]);       }     }     scanf( %d , &q);     while (q--) {       int x;       scanf( %d , &x);       printf( %lld n , dp[x]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long i, n, lns, t = 0, pos = -1, posl = 0;     string s, ot;     cin >> s;     lns = s.length();     ot.clear();     for (i = 0; i < lns; ++i) {       if (s[i] ==  a )         t++;       else         posl++;     }     if (t == lns) {       cout << s;       return 0;     }     if (posl & 1) {       cout <<  :( ;       return 0;     }     t = 0;     for (i = 0; i < lns; ++i) {       if (s[i] !=  a ) t++;       if (t * 2 > posl) {         pos = i;         break;       }     }     for (i = pos; i < lns; ++i) {       if (s[i] ==  a ) {         cout <<  :( ;         return 0;       }     }     i = 0;     t = pos;     while (i < pos) {       if (s[i] ==  a )         i++;       else if (s[i] != s[t]) {         cout <<  :( ;         return 0;       } else         i++, t++;     }     for (i = 0; i < pos; ++i) {       cout << s[i];     }     cout << ot;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct camel {     int pos;     int tof;   };   int main() {     cout << setprecision(8) << fixed;     double l, d, v, g, r;     cin >> l >> d >> v >> g >> r;     double temp;     double T;     temp = d / v;     double q;     bool yer = 1;     while (temp >= 0) {       if (yer) {         temp -= g;         T = 0;         yer = !yer;       } else {         T = r - temp;         temp -= r;         yer = !yer;       }     }     cout << ((l / v) + T);   }


#include <bits/stdc++.h>   using namespace std;   const long long o = 1e4 + 1;   long long n, m, q, a[o], b[o];   long long qwq(long long x) {     long long s = 0;     for (long long i = 1; i <= n; i++) {       if (1.0 * x * a[i] > b[i] * (m + 100)) return m + 1000;       s += 1 + x * a[i] / b[i];     }     return s;   }   signed main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> n >> m;     bool q = 1;     long long x, y;     for (long long i = 1; i <= n; i++) cin >> a[i] >> b[i], q &= !a[i];     if (q) return cout << (n == m ? -1 : 0), 0;     long long l = 1, r = 1e18;     while (l < r) {       long long mid = (l + r + 1) >> 1;       if (qwq(mid) > m)         r = mid - 1;       else         l = mid;     }     if (qwq(l) != m) return cout << 0, 0;     x = l, l = 1, r = 1e18;     while (l < r) {       long long mid = (l + r) >> 1;       if (qwq(mid) < m)         l = mid + 1;       else         r = mid;     }     y = l;     cout << max(0ll, x - y + 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     pair<int, int> a[n], b[m];     for (int i = 0; i < n; i++) {       cin >> a[i].first >> a[i].second;     }     for (int i = 0; i < m; i++) {       cin >> b[i].first >> b[i].second;     }     set<int> s;     for (int i = 0; i < n; i++) {       int f = 0;       for (int j = 0; j < m; j++) {         if (((a[i].first == b[j].first) || (a[i].first == b[j].second)) &&             ((a[i].second == b[j].first) || (a[i].second == b[j].second))) {           continue;         } else if ((a[i].first == b[j].first) || (a[i].first == b[j].second)) {           f = 1;         }       }       int tr = 1;       if (f) {         s.insert(a[i].first);         tr = 0;       }       for (int j = 0; j < m; j++) {         if (((a[i].first == b[j].first) || (a[i].first == b[j].second)) &&             ((a[i].second == b[j].first) || (a[i].second == b[j].second))) {           continue;         } else if ((a[i].second == b[j].first) || (a[i].second == b[j].second)) {           f += 1;           break;         }       }       if (f > 1) {         cout <<  -1 n ;         exit(0);       }       if (f && tr) {         s.insert(a[i].second);       }     }     for (int j = 0; j < m; j++) {       int f = 0;       int tr = 1;       for (int i = 0; i < n; i++) {         if (((a[i].first == b[j].first) || (a[i].first == b[j].second)) &&             ((a[i].second == b[j].first) || (a[i].second == b[j].second))) {           continue;         } else if ((b[j].first == a[i].first) || (b[j].first == a[i].second)) {           f = 1;         }       }       if (f) {         s.insert(b[j].first);         tr = 0;       }       for (int i = 0; i < n; i++) {         if (((a[i].first == b[j].first) || (a[i].first == b[j].second)) &&             ((a[i].second == b[j].first) || (a[i].second == b[j].second))) {           continue;         } else if ((b[j].second == a[i].first) || (b[j].second == a[i].second)) {           f += 1;           break;         }       }       if (f > 1) {         cout <<  -1 n ;         exit(0);       }       if (f && tr) {         s.insert(b[j].second);       }     }     if (s.size() == 1) {       auto it = s.begin();       cout << (*it);     } else {       cout <<  0 ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve();   int main() {     solve();     return 0;   }   void solve() {     long long int n, x, y;     cin >> n >> x >> y;     if (n > y) {       cout << -1;       return;     }     if ((y - n + 1) * (y - n + 1) + n - 1 >= x) {       for (int i = 1; i < n; ++i) {         cout << 1 <<    ;       }       cout << y - n + 1;     } else       cout << -1;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 210;   int n, m, ans[maxn];   string s[maxn];   int solve(string s) {     for (int i = 10; i >= 0; i--) {       bool flag = 0;       for (int j = 0; j < (1 << i); j++) {         string t;         for (int k = 0; k < i; k++)           if (j & (1 << k))             t +=  1 ;           else             t +=  0 ;         if (s.find(t) == s.npos) {           flag = 1;           break;         }       }       if (!flag) return i;     }     return 0;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) cin >> s[i];     scanf( %d , &m);     for (int i = n + 1; i <= n + m; i++) {       int a, b;       scanf( %d%d , &a, &b);       s[i] = s[a] + s[b];       if (s[i].length() > 1000)         s[i] = s[i].substr(0, 500) + s[i].substr(s[i].length() - 500, 500);       ans[i] = max(solve(s[i]), max(ans[a], ans[b]));       printf( %d n , ans[i]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 10;   int A[N];   long long sum = 0, ans = 0;   bool state;   map<int, int> cnt;   int main() {     cnt[0] = 1;     int n, m;     cin >> n >> m;     for (int i = 0; i < n; i++) {       cin >> A[i];     }     for (int i = 0; i < n; i++) {       if (A[i] > m)         sum++;       else if (A[i] < m)         sum--;       state = state | (A[i] == m);       if (state) {         ans += (cnt[sum] + cnt[sum - 1]);         continue;       }       cnt[sum]++;     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 10;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       vector<int> a(n);       for (auto& i : a) {         cin >> i;       }       vector<int> ops;       for (int i = 0; i < n - 2; ++i) {         if (a[i] == 0) {           continue;         }         int j = i + 1;         while (j < n and a[j] == 1) {           ++j;         }         int sz = j - i;         if (sz % 2 == 0 or j + 1 >= n) {           i = j;         } else if (a[j + 1] == 0) {           ops.push_back(j - 1);           a[j] = a[j + 1] = 1;           i = j;         } else {           ops.push_back(j - 1);           a[j - 1] = a[j + 1] = 0;           i = j;         }       }       for (int i = 0; i < n - 2; ++i) {         if (a[i] + a[i + 1] + a[i + 2] == 2) {           ops.push_back(i);           a[i] = a[i + 1] = a[i + 2] = 0;         }       }       for (int i = n - 1; i >= 2; --i) {         if (a[i] + a[i - 1] + a[i - 2] == 2) {           ops.push_back(i - 2);           a[i] = a[i - 1] = a[i - 2] = 0;         }       }       if (count(a.begin(), a.end(), 1)) {         cout <<  NO n ;       } else {         cout <<  YES n ;         cout << ops.size() <<   n ;         for (auto& i : ops) {           cout << i + 1 <<    ;         }         cout <<   n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   namespace IO {   char buf_[1 << 21], *p1_ = buf_, *p2_ = buf_;   inline long long in() {     long long s = 0, f = 1;     char x = (p1_ == p2_ && (p2_ = (p1_ = buf_) + fread(buf_, 1, 1 << 21, stdin),                              p1_ == p2_)                   ? EOF                   : *p1_++);     for (; x <  0  || x >  9 ;          x = (p1_ == p2_ && (p2_ = (p1_ = buf_) + fread(buf_, 1, 1 << 21, stdin),                             p1_ == p2_)                   ? EOF                   : *p1_++))       if (x ==  - ) f = -1;     for (; x >=  0  && x <=  9 ;          x = (p1_ == p2_ && (p2_ = (p1_ = buf_) + fread(buf_, 1, 1 << 21, stdin),                             p1_ == p2_)                   ? EOF                   : *p1_++))       s = (s * 10) + (x & 15);     return f == 1 ? s : -s;   }   char _buf[1 << 21];   long long _pos = -1;   inline void flush() { fwrite(_buf, 1, _pos + 1, stdout), _pos = -1; }   inline void pc(char x) {     if (_pos == (1 << 21) - 1) flush();     _buf[++_pos] = x;   }   inline void out(long long x) {     char k[30];     long long pos = 0;     if (!x) return pc( 0 );     if (x < 0) pc( - ), x = -x;     while (x) k[++pos] = (x % 10) | 48, x /= 10;     for (long long i = pos; i; i--) pc(k[i]);   }   inline void out(string x) {     long long len = x.size();     for (long long i = 0; i < len; i++) pc(x[i]);   }   }  // namespace IO   using namespace IO;   const long long A = 5e5 + 5;   long long n;   long long head[A], tot_road;   struct Road {     long long nex, to;   } road[2 * A];   inline void edge(long long x, long long y) {     road[++tot_road] = (Road){head[x], y}, head[x] = tot_road;   }   long long sz[A], res[A];   inline void prepare(long long fa, long long x) {     sz[x] = 1;     for (long long y = head[x]; y; y = road[y].nex) {       long long z = road[y].to;       if (z == fa) continue;       prepare(x, z);       sz[x] += sz[z];     }     return;   }   inline void DFS(long long fa, long long x) {     for (long long y = head[x]; y; y = road[y].nex) {       long long z = road[y].to;       if (z == fa) continue;       res[z] = res[x] + (sz[x] - sz[z]) * sz[z];       DFS(x, z);     }     return;   }   signed main() {     n = in();     for (long long i = 1; i < n; i++) {       long long u = in(), v = in();       edge(u, v), edge(v, u);     }     prepare(0, 1);     res[1] = n * (n - 1) / 2;     DFS(0, 1);     long long rt = 0;     for (long long i = 1; i <= n; i++)       if (res[i] > res[rt]) rt = i;     prepare(0, rt);     res[rt] = n * (n - 1) / 2;     DFS(0, rt);     long long ans = 0;     for (long long i = 1; i <= n; i++) ans = max(ans, res[i]);     out(ans), pc(  n );     flush();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   pair<int, int> tt[1005], kk[1005];   int n1, n2, top;   vector<int> vv[1005];   int main() {     int k, i, j, n, a, tmp;     long long ans = 0, sum = 0;     scanf( %d %d , &n, &k);     for (i = 0; i < n; i++) {       scanf( %d %d , &a, &tmp);       if (tmp == 1)         tt[n1++] = make_pair(a, i + 1);       else         kk[n2++] = make_pair(a, i + 1);       sum += (long long)a;     }     sort(tt, tt + n1);     sort(kk, kk + n2);     if (n1 < k) {       for (i = n1 - 1; i >= 0; i--) {         vv[top++].push_back(tt[i].second);         ans += (long long)tt[i].first;       }       for (i = 0; top < k; i++) vv[top++].push_back(kk[i].second);       for (; i < n2; i++) vv[top - 1].push_back(kk[i].second);     } else {       for (i = n1 - 1; top < k - 1; i--) {         vv[top++].push_back(tt[i].second);         ans += (long long)tt[i].first;       }       if (n1 > 0 && n2 > 0)         ans += (long long)min(tt[0].first, kk[0].first);       else if (n1 > 0)         ans += (long long)tt[0].first;       else         ans += (long long)kk[0].first;       for (; i >= 0; i--) vv[top].push_back(tt[i].second);       for (i = 0; i < n2; i++) vv[top].push_back(kk[i].second);     }     printf( %I64d. , sum - (ans + 1) / 2);     if (ans & 1)       printf( 5 );     else       printf( 0 );     putchar(  n );     for (i = 0; i < k; i++) {       printf( %d  , (int)vv[i].size());       for (j = 0; j < (int)vv[i].size(); j++) printf( %d  , vv[i][j]);       putchar(  n );     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1000005;   struct Node {     int left, right;     long long sum;   } L[N << 2];   void bulid(int step, int l, int r) {     L[step].left = l;     L[step].right = r;     L[step].sum = 0;     if (l == r) return;     int m = (l + r) >> 1;     bulid(step << 1, l, m);     bulid(step << 1 | 1, m + 1, r);   }   void update(int step, int pos, long long val) {     if (L[step].left == L[step].right) {       L[step].sum = (val) % 1000000007;       return;     }     int m = (L[step].left + L[step].right) >> 1;     if (pos <= m)       update(step << 1, pos, val);     else       update(step << 1 | 1, pos, val);     L[step].sum = (L[step << 1].sum + L[step << 1 | 1].sum) % 1000000007;   }   long long query(int step, int l, int r) {     if (L[step].left == l && L[step].right == r) return L[step].sum;     int m = (L[step].left + L[step].right) >> 1;     if (r <= m)       return query(step << 1, l, r);     else if (l > m)       return query(step << 1 | 1, l, r);     else       return (query(step << 1, l, m) + query(step << 1 | 1, m + 1, r)) %              1000000007;   }   long long a[N];   int main() {     int n;     scanf( %d , &n);     bulid(1, 1, 1000000);     long long ans = 0;     for (int i = 0; i < n; i++) {       scanf( %I64d , &a[i]);       long long sub = query(1, a[i], a[i]);       long long sum = (a[i] + a[i] * query(1, 1, a[i])) % 1000000007;       ans = ((ans + sum - sub) % 1000000007 + 1000000007) % 1000000007;       update(1, a[i], sum);     }     printf( %I64d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[1000][1000];   int main() {     int n, ans = 0;     cin >> n;     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= n; ++j) cin >> a[i][j];     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= n; ++j) {         int sum1 = 0, sum2 = 0;         for (int k = 1; k <= n; ++k) sum1 += a[k][j];         for (int k = 1; k <= n; ++k) sum2 += a[i][k];         if (sum1 > sum2) ans++;       }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   vector<pair<int, int> > a[5001];   int n, t;   int main() {     int m, u, v, w;     cin >> n >> m >> t;     vector<vector<int> > f(n + 1, vector<int>(2, 0));     vector<vector<int> > p(n + 1, vector<int>(2, 2e9 + 1));     vector<vector<int> > track(n + 1, vector<int>(n + 1, 0));     for (int i = 1; i <= m; i++) {       cin >> u >> v >> w;       a[v].push_back(make_pair(u, w));     }     f[1][0] = 1;     p[1][0] = 0;     int id = 1;     int res = 0;     for (int j = 2; j <= n; j++) {       for (int i = 2; i <= n; i++)         for (int k = 0; k < a[i].size(); k++) {           v = a[i][k].first;           w = a[i][k].second;           if (f[v][1 - id] &&               ((f[i][id] < f[v][1 - id] + 1 && p[v][1 - id] + w <= t) ||                (f[i][id] == f[v][1 - id] + 1 && p[v][1 - id] + w < p[i][id]))) {             f[i][id] = f[v][1 - id] + 1;             p[i][id] = p[v][1 - id] + w;             track[i][j] = v;             if (i == n) res = max(res, j);           }         }       id ^= 1;     }     vector<int> road;     cout << res << endl;     u = n;     do {       u = track[u][res--];       road.push_back(u);     } while (u > 1);     for (int i = road.size() - 1; i >= 0; i--) cout << road[i] <<    ;     cout << n;   }


#include <bits/stdc++.h>   using namespace std;   namespace jumpmelon {   const int MAXN = 52;   int A[MAXN + 1], B[MAXN + 1];   bool F[MAXN + 1];   void work() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &A[i]);     vector<vector<int>> Ans;     while (1) {       memset(F + 1, 0, sizeof(bool[n]));       for (int i = 1; i < n; i++)         if (A[i] + 1 == A[i + 1]) F[i] = 1;       int x = 0, y = 0;       for (int i = 1; i <= n; i++)         if (!F[i])           for (int j = 1; j < i; j++)             if (A[j] == A[i] + 1) {               x = i;               y = j;             }       if (x == 0 && y == 0) break;       int p = x;       while (p > 1 && F[p - 1]) p--;       vector<int> D;       if (y > 1) D.push_back(y - 1);       D.push_back(p - y);       D.push_back(x - p + 1);       if (x < n) D.push_back(n - x);       Ans.push_back(D);       int l = 1, r = n;       for (int v : D) {         r -= v;         for (int i = 1; i <= v; i++) B[r + i] = A[l + i - 1];         l += v;       }       memcpy(A + 1, B + 1, sizeof(int[n]));     }     printf( %d n , (int)Ans.size());     for (auto &&D : Ans) {       printf( %d , (int)D.size());       for (int v : D) printf(  %d , v);       putchar(  n );     }   }   }  // namespace jumpmelon   int main() {     jumpmelon::work();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     int n, m, cnt = 0;     cin >> n >> m;     char mat[n][m];     for (int i = 0; i < (int)(n); i++) {       for (int j = 0; j < (int)(m); j++) {         cin >> mat[i][j];       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         int f = 0;         char x = mat[i][j];         for (int k = 0; k < n; k++) {           if (x >= mat[k][j])             continue;           else {             f = 1;             break;           }         }         if (f == 0) {           cnt++;           break;         }       }     }     cout << cnt << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1000000007;   const int N = 1000005;   const double PI = 4 * atan(1);   long long m, x, y, n, p, z, k;   long long h1, m1, h2, m2;   char c, cc;   int main() {     ios::sync_with_stdio(0);     cin >> h1 >> c >> m1 >> h2 >> cc >> m2;     x = (h2 - h1) * 60 + m2 - m1;     x /= 2;     x += m1;     if ((h1 + x / 60) < 10) cout << 0;     cout << h1 + x / 60 <<  : ;     if (((x) % 60 < 10)) cout << 0;     cout << x % 60;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     for (int i = 1; i <= 500; i++) putchar( 9 );     for (int i = 1; i <= 500; i++) putchar( 0 );     putchar( 1 );     putchar(  n );     for (int i = 1; i <= 501; i++) putchar( 9 );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 100005;   const int oo = 1e9 + 7;   const long long mod = 1e9 + 7;   const double eps = 1e-11;   long long n;   int main() {     cin.sync_with_stdio(false);     cin.tie(0);     cin >> n;     cout << (n - 2LL) * (n - 2LL) << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int y, b, r;     int l, m, n;     int ans;     cin >> y >> b >> r;     l = y;     m = b;     n = r;     int mins = min(min(y, b), r);     if (mins == r) {       ans = r + (r - 1) + (r - 2);     } else if (mins == b) {       y = b - 1;       r = b + 1;       ans = y + b + r;     } else if (mins == y) {       b = y + 1;       r = y + 2;       if (r > n) {         y--;         ans = y + (y + 1) + (y + 2);       } else {         ans = y + b + r;       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 10;   int win(long long s, long long e) {     if (e % 2 == 1) {       if (s % 2 == 1)         return 0;       else         return 1;     } else {       if (2 * s > e) {         if (s % 2 == 1)           return 1;         else           return 0;       } else if (2 * s <= e && 4 * s > e) {         return 1;       } else         return win(s, e / 4);     }   }   int lose(long long s, long long e) {     if (2 * s > e)       return 1;     else       return win(s, e / 2);   }   int Win[N], Lose[N];   int get_lose(int x);   int get_win(int x);   int get_win(int x) {     if (x == 1) return Win[1];     return Win[x] ? get_lose(x - 1) : get_win(x - 1);   }   int get_lose(int x) {     if (x == 1) return Lose[1];     return Lose[x] ? get_lose(x - 1) : get_win(x - 1);   }   void io() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);   }   int main(int argc, char const *argv[]) {     io();     int t;     cin >> t;     long long s, e;     for (int i = 1; i <= t; i++) {       cin >> s >> e;       Win[i] = win(s, e);       Lose[i] = lose(s, e);     }     cout << get_win(t) <<     << get_lose(t) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     int c, v0, v1, a, l;     cin >> c >> v0 >> v1 >> a >> l;     int ans = 1;     c -= min(v0, v1);     int p = 0;     while (c > 0) {       v0 = v0 + a;       p = min(v0, v1);       p -= l;       c -= p;       ans++;     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 3005;   vector<int> flist[maxn], rlist[maxn], clist[maxn];   int n, m, q;   int component[maxn], cptr = 0;   int visited[maxn];   stack<int> etime;   void fdfs(int cur, vector<int> adj[]) {     visited[cur] = 1;     for (auto u : adj[cur]) {       if (visited[u] != 1) fdfs(u, adj);     }     etime.push(cur);   }   void rdfs(int cur, vector<int> adj[]) {     visited[cur] = 1;     component[cur] = cptr;     for (auto u : adj[cur]) {       if (visited[u] != 1) rdfs(u, adj);     }   }   void kosaraju() {     for (int i = 1; i < maxn; i++) {       if (visited[i] != 1) fdfs(i, flist);     }     memset(visited, 0, sizeof(visited));     while (!etime.empty()) {       int cur = etime.top();       etime.pop();       if (visited[cur] == 1) continue;       cptr++;       rdfs(cur, rlist);     }   }   struct query {     int u, v, k, id, ans;   };   bool ucomp(query a, query b) { return a.u < b.u; }   bool idcomp(query a, query b) { return a.id < b.id; }   int done[maxn];   const int logN = 13;   int parent[maxn][logN], depth[maxn];   void buildLCA() {     for (long long j = 1; j < logN; j++) {       for (long long i = 1; i <= n; i++) {         if (parent[i][j - 1] != 0) {           parent[i][j] = parent[parent[i][j - 1]][j - 1];         }       }     }   }   int getNode(int u, int p) {     if (p < 0 || parent[u][0] == 0 || visited[u] == 0) return -1;     for (int i = logN - 1; i >= 0; i--) {       int shift = 1 << i;       if (shift <= p) {         p -= shift;         u = parent[u][i];       }     }     return (u == 0 ? -1 : u);   }   void remove(int cur) {     visited[cur] = 1;     for (auto u : flist[cur]) {       if (visited[u]) continue;       remove(u);     }   }   void ddffss(int cur) {     visited[cur] = 1;     for (int i = 0; i < flist[cur].size(); i++) {       int u = flist[cur][i];       if (visited[u]) continue;       if (i >= clist[cur].size()) {         remove(u);         continue;       }       parent[u][0] = cur;       depth[u] = 1 + depth[cur];       ddffss(u);     }   }   void prep(int cur) {     memset(visited, 0, sizeof(visited));     memset(parent, 0, sizeof(parent));     memset(depth, 0, sizeof(depth));     ddffss(cur);     buildLCA();   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     cin >> n >> m >> q;     for (int i = 0; i < m; i++) {       int u, v;       cin >> u >> v;       flist[u].push_back(v);       rlist[v].push_back(u);     }     kosaraju();     for (int i = 1; i <= n; i++) sort(flist[i].begin(), flist[i].end());     for (int i = 1; i <= n; i++) {       for (auto u : flist[i]) {         clist[i].push_back(u);         if (component[i] == component[u]) {           break;         }       }     }     query Q[q];     for (int i = 0; i < q; i++) {       cin >> Q[i].u >> Q[i].v >> Q[i].k;       Q[i].id = i;     }     sort(Q, Q + q, ucomp);     for (int i = 0; i < q; i++) {       if (done[Q[i].u] == 0) prep(Q[i].u);       done[Q[i].u] = 1;       Q[i].ans = getNode(Q[i].v, depth[Q[i].v] + 1 - Q[i].k);     }     sort(Q, Q + q, idcomp);     for (int i = 0; i < q; i++) {       cout << Q[i].ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long a[105];   int32_t main() {     ios::sync_with_stdio(false);     cin.tie(0), cout.tie(0);     long long n, m;     cin >> n >> m;     long long maxi = 0, mini = 107;     for (long long i = 0; i < n; i++) {       cin >> a[i];       maxi = max(maxi, a[i]);     }     long long temp = m;     for (long long i = 0; i < n; i++) {       if (m > 0) {         m -= (maxi - a[i]);         a[i] = maxi;         if (m <= 0) {           mini = maxi;           break;         }       }     }     if (m > 0) mini = maxi + ceil(m / (n + 0.0));     cout << mini <<     << maxi + temp <<   n ;     return 0;   }