#include <bits/stdc++.h>   using namespace std;   const int maxn = 100010;   int v[maxn], b[maxn];   int n, k;   long long base, sum;   int cmp(const int &i, const int &j) { return i > j; }   int main() {     while (scanf( %d %d , &n, &k) != EOF) {       scanf( %I64d , &base);       sum = 0;       for (int i = 0; i < n; i++) {         scanf( %d , &v[i]);         if (i != n - 1) b[i] = v[i];       }       sort(b, b + n - 1, cmp);       int ans = n;       for (int i = 0; i < k; i++) sum += b[i];       for (int i = 0; i < n; i++) {         int s = lower_bound(b, b + n - 1, v[i], cmp) - b;         long long now = sum;         if (s >= k) {           now += v[i];           now -= b[k - 1];         }         if (now > base) {           ans = i + 1;           break;         }       }       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long pw(long long base, long long e) {     return e ? pw(base * base, e / 2) * (e % 2 ? base : 1) : 1;   }   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   long long to_int(string s) {     long long ret = 0;     for (int i = 0; i <= s.size(); i++) {       ret += pw(10, s.size() - i - 1) * (long long)(s[i] -  0 );     }     return ret;   }   const int maxn = 1e5 + 10, mod = 1e9 + 7;   const long long INF = 1e9;   long long n;   long long f(long long x) { return (n - x) / (2 * x); }   int main() {     cin >> n;     n--;     long long ans = 0;     for (int i = 0; i <= log2(n); i++) {       ans += pw(2, i) * (f(pw(2, i)) + 1);     }     return cout << ans <<   n , 0;   }


#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1);   const long long mod = 1e9 + 7;   const long long N = 2e5 + 5, K = 105;   const int si = (1 << 20);   const long long add = 1e4;   const long long M = 100 + 5;   const double INFdb = 1e10;   int t;   int n;   vector<int> a[N];   priority_queue<int, vector<int>, greater<int> > pq;   void reset() {     for (int i = 0; i < n; ++i) a[i].clear();     while (!pq.empty()) pq.pop();   }   void solve() {     cin >> n;     reset();     for (int i = 0; i < n; ++i) {       int m, c;       cin >> m >> c;       a[m].push_back(c);     }     long long sum = 0;     int used = 0;     int smartNum = n;     for (int i = n - 1; i >= 0; --i) {       for (int x : a[i]) pq.push(x);       smartNum -= (int)a[i].size();       while (smartNum + used < i && !pq.empty()) {         sum += pq.top();         pq.pop();         ++used;       }     }     cout << sum <<   n ;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(0);     cin >> t;     while (t--) {       solve();     }     cerr <<   nTime elapsed:   << 1000 * clock() / CLOCKS_PER_SEC <<  ms n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   int l[100500];   int r[100500];   int val[100500];   int t[400500];   int t2[400500];   int mas[100500];   int INF = 0;   void build(int v, int tl, int tr) {     if (tl == tr)       t[v] = 0;     else {       int mid = (tl + tr) >> 1;       build(v << 1, tl, mid);       build((v << 1) + 1, mid + 1, tr);       t[v] = 0;     }   }   void update(int v, int tl, int tr, int ql, int qr, int nval) {     if (ql > qr) return;     if (tl == ql && tr == qr) {       t[v] = t[v] | nval;     } else {       int mid = (tl + tr) >> 1;       update(v << 1, tl, mid, ql, min(qr, mid), nval);       update((v << 1) + 1, mid + 1, tr, max(ql, mid + 1), qr, nval);     }   }   void dfs(int v, int tl, int tr, int curr) {     if (tl == tr) {       mas[tl] = curr | t[v];     } else {       int mid = (tl + tr) >> 1;       dfs(v << 1, tl, mid, curr | t[v]);       dfs((v << 1) + 1, mid + 1, tr, curr | t[v]);     }   }   void build2(int v, int tl, int tr) {     if (tl == tr) {       t[v] = mas[tl];     } else {       int mid = (tl + tr) >> 1;       build2(v << 1, tl, mid);       build2((v << 1) + 1, mid + 1, tr);       t[v] = t[v << 1] & t[(v << 1) + 1];     }   }   int query(int v, int tl, int tr, int ql, int qr) {     if (ql > qr) return INF;     if (tl == ql && tr == qr) {       return t[v];     } else {       int mid = (tl + tr) >> 1;       return query(v << 1, tl, mid, ql, min(qr, mid)) &              query((v << 1) + 1, mid + 1, tr, max(ql, mid + 1), qr);     }   }   int main() {     for (int i = 29; i >= 0; i--) {       INF += (1 << i);     }     cin >> n >> m;     build(1, 1, n);     for (int i = 0; i < m; i++) {       cin >> l[i] >> r[i] >> val[i];       update(1, 1, n, l[i], r[i], val[i]);     }     dfs(1, 1, n, 0);     build2(1, 1, n);     for (int i = 0; i < m; i++) {       if (query(1, 1, n, l[i], r[i]) != val[i]) {         cout <<  NO ;         return 0;       }     }     cout <<  YES n ;     for (int i = 1; i <= n; i++) cout << mas[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, d, f;     cin >> n;     if (n % 3 == 2)       d = n / 3 + 1;     else       d = n / 3;     f = d / 12;     d = d % 12;     cout << f <<     << d << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline void read(T &x) {     x = 0;     char c = getchar(), f = 0;     for (; c <  0  || c >  9 ; c = getchar())       if (c ==  - ) f = 1;     for (; c >=  0  && c <=  9 ; c = getchar())       x = (x << 1) + (x << 3) + (c ^ 48);     if (f) x = -x;   }   int n, m, K, a[2000005][5];   char ch[2000005];   long long N, M;   inline void solve() {     read(n);     if (n % 3 == 0)       printf( %d %d n , n / 3, n / 3);     else if (n % 3 == 1)       printf( %d %d n , n / 3 + 1, n / 3);     else       printf( %d %d n , n / 3, n / 3 + 1);   }   int main() {     int Ca;     for (read(Ca); Ca--;) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2000;   vector<array<int, 2>> que;   int degree[N][N], n, m;   string grid[N];   bool valid(int i, int j) {     return i >= 0 && i < n && j >= 0 && j < m && grid[i][j] ==  . ;   }   void update(int i, int j) {     if (i >= 0 && i < n && j >= 0 && j < m) {       degree[i][j] = 0;     }     if (valid(i - 1, j) && ++degree[i - 1][j] == 3) {       que.push_back({i - 1, j});     }     if (valid(i + 1, j) && ++degree[i + 1][j] == 3) {       que.push_back({i + 1, j});     }     if (valid(i, j - 1) && ++degree[i][j - 1] == 3) {       que.push_back({i, j - 1});     }     if (valid(i, j + 1) && ++degree[i][j + 1] == 3) {       que.push_back({i, j + 1});     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cin >> n >> m;     for (int i = 0; i < n; ++i) {       cin >> grid[i];     }     for (int i = 0; i < n; ++i) {       update(i, -1), update(i, m);     }     for (int i = 0; i < m; ++i) {       update(-1, i), update(n, i);     }     for (int i = 0; i < n; ++i) {       for (int j = 0; j < m; ++j) {         if (grid[i][j] ==  * ) {           update(i, j);         }       }     }     while (!que.empty()) {       auto [i, j] = que.back();       que.pop_back();       if (degree[i][j] == 0) {         continue;       } else if (degree[i][j] == 4) {         cout <<  Not unique n ;         exit(0);       }       if (valid(i - 1, j)) {         grid[i - 1][j] =  ^ , grid[i][j] =  v ;         update(i - 1, j);       } else if (valid(i + 1, j)) {         grid[i][j] =  ^ , grid[i + 1][j] =  v ;         update(i + 1, j);       } else if (valid(i, j - 1)) {         grid[i][j - 1] =  < , grid[i][j] =  > ;         update(i, j - 1);       } else {         grid[i][j] =  < , grid[i][j + 1] =  > ;         update(i, j + 1);       }       update(i, j);     }     for (int i = 0; i < n; ++i) {       if (count(grid[i].begin(), grid[i].end(),  . ) > 0) {         cout <<  Not unique n ;         exit(0);       }     }     for (int i = 0; i < n; ++i) {       cout << grid[i] <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   set<string> st;   set<string>::iterator it1;   vector<int> dp2(20000, 0), dp3(20000, 0);   void solve(string s, int i, string prev) {     if (i < 1) return;     if (i == 1) {       string a = s.substr(i - 1, 2);       if (a != prev)         st.insert(a);       else         return;     } else {       string temp;       string a = s.substr(i - 1, 2);       string b = s.substr(i - 2, 3);       if (a != prev && !dp2[i]) {         dp2[i] = 1;         temp = a;         solve(s, i - 2, temp);       }       if (b != prev && !dp3[i]) {         dp3[i] = 1;         temp = b;         solve(s, i - 3, temp);       }     }     return;   }   int main() {     string str;     cin >> str;     if (str.size() < 7) {       cout << 0;       return 0;     }     string s(str.begin() + 5, str.end());     int n = s.size();     solve(s, n - 1,   );     for (int i = 0; i < n; i++) {       if (dp2[i]) st.insert(s.substr(i - 1, 2));       if (dp3[i]) st.insert(s.substr(i - 2, 3));     }     cout << st.size() << endl;     it1 = st.begin();     for (; it1 != st.end(); it1++) cout << *it1 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, i, X[200005], poz, nr0;   long long A[200005], B[200005], val, t;   int main() {     ios::sync_with_stdio(false);     cin >> n >> t;     for (i = 1; i <= n; i++) cin >> A[i];     for (i = 1; i <= n; i++) {       cin >> X[i];       if (X[i] < X[i - 1]) {         cout <<  No n ;         return 0;       }       if (X[i] < i) {         cout <<  No n ;         return 0;       }       if (X[i - 1] != X[i] && X[i - 1] != (i - 1)) {         cout <<  No n ;         return 0;       }     }     A[n + 1] = A[n] + 1000000001;     for (i = 1; i <= n; i++) B[X[i]] = A[X[i] + 1] + t - 1;     val = B[n] - 1;     for (i = n - 1; i >= 1; i--) {       if (B[i] != 0)         val = B[i];       else {         if (val < A[i + 1] + t) {           cout <<  No n ;           return 0;         }       }       B[i] = val;       val--;     }     cout <<  Yes n ;     for (i = 1; i <= n; i++) cout << B[i] <<    ;     cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = (int)1e5 + 22;   vector<vector<int> > cr;   int N, M;   vector<vector<int> > qq;   int A[MAXN], prv[MAXN], nxt[MAXN], lst[MAXN];   struct Fenwick {     int n;     vector<long long> t, w;     void init(int _n) {       n = _n;       t.resize(n, 0);       w.resize(n, 0);     }     long long sum(int r) {       long long ans = 0;       for (; r >= 0; r = (r & (r + 1)) - 1) ans += t[r];       return ans;     }     void inc(int i, long long d) {       w[i] += d;       for (; i < n; i = (i | (i + 1))) t[i] += d;     }     long long sum(int l, int r) {       if (l > r) return 0;       return sum(r) - sum(l - 1);     }   };   void updateCR(int v, int l, int r, int x) {     cr[v].push_back(prv[x]);     if (r - l == 1) return;     int mid = (l + r) / 2;     if (x < mid)       updateCR(2 * v + 1, l, mid, x);     else       updateCR(2 * v + 2, mid, r, x);   }   vector<Fenwick> T;   void build(int v, int l, int r) {     cr[v].push_back(-1);     sort(cr[v].begin(), cr[v].end());     cr[v].resize(unique(cr[v].begin(), cr[v].end()) - cr[v].begin());     T[v].init((int)cr[v].size());     for (int i = l; i < r; i++) {       int pos = lower_bound(cr[v].begin(), cr[v].end(), prv[i]) - cr[v].begin();       assert(cr[v][pos] == prv[i]);       T[v].inc(pos, i - prv[i]);     }     if (r - l == 1) return;     int mid = (l + r) / 2;     build(2 * v + 1, l, mid);     build(2 * v + 2, mid, r);   }   long long get(int v, int l, int r, int ql, int qr) {     if (ql >= r || qr <= l) return 0;     if (ql <= l && r <= qr) {       int pos = lower_bound(cr[v].begin(), cr[v].end(), ql) - cr[v].begin();       int sz = (int)cr[v].size();       return T[v].sum(pos, sz - 1);     }     int mid = (l + r) / 2;     long long a, b;     a = get(2 * v + 1, l, mid, ql, qr);     b = get(2 * v + 2, mid, r, ql, qr);     return a + b;   }   void update(int v, int l, int r, int x, int d) {     int pos = lower_bound(cr[v].begin(), cr[v].end(), prv[x]) - cr[v].begin();     assert(pos < (int)cr[v].size());     if (cr[v][pos] != prv[x]) cerr << cr[v][pos] <<     << prv[x] << endl;     assert(cr[v][pos] == prv[x]);     T[v].inc(pos, d * (x - prv[x]));     if (r - l == 1) return;     int mid = (l + r) / 2;     if (x < mid)       update(2 * v + 1, l, mid, x, d);     else       update(2 * v + 2, mid, r, x, d);   }   void input() {     cin >> N >> M;     memset(lst, -1, sizeof(lst));     memset(nxt, -1, sizeof(nxt));     cr.resize(4 * N);     vector<set<int> > st;     st.resize(N + 1);     vector<int> B;     for (int i = 0; i < N; i++) {       cin >> A[i];       B.push_back(A[i]);       st[A[i]].insert(i);       prv[i] = lst[A[i]];       if (prv[i] >= 0) nxt[prv[i]] = i;       updateCR(0, 0, N, i);       lst[A[i]] = i;     }     int type, a, b;     for (int i = 0; i < M; i++) {       cin >> type >> a >> b;       --type, --a;       qq.push_back({type, a, b});       if (!type) {         if (prv[a] >= 0) nxt[prv[a]] = nxt[a];         if (nxt[a] >= 0) {           prv[nxt[a]] = prv[a];           updateCR(0, 0, N, nxt[a]);         }         st[B[a]].erase(a);         B[a] = b;         st[B[a]].insert(a);         auto it = st[B[a]].lower_bound(a);         if (it != st[B[a]].begin()) {           --it;           nxt[*it] = a;           prv[a] = *it;           ++it;         } else           prv[a] = -1;         updateCR(0, 0, N, a);         ++it;         if (it != st[B[a]].end()) {           prv[*it] = a;           nxt[a] = *it;           updateCR(0, 0, N, nxt[a]);         } else           nxt[a] = -1;       }     }   }   void solve() {     memset(lst, -1, sizeof(lst));     memset(nxt, -1, sizeof(nxt));     vector<set<int> > st;     st.resize(N + 1);     vector<int> B;     for (int i = 0; i < N; i++) {       B.push_back(A[i]);       st[A[i]].insert(i);       prv[i] = lst[A[i]];       if (prv[i] >= 0) nxt[prv[i]] = i;       lst[A[i]] = i;     }     T.resize(4 * N);     build(0, 0, N);     int type, a, b;     for (int i = 0; i < M; i++) {       type = qq[i][0];       a = qq[i][1];       b = qq[i][2];       if (type)         cout << get(0, 0, N, a, b) <<   n ;       else {         update(0, 0, N, a, -1);         if (prv[a] >= 0) {           nxt[prv[a]] = nxt[a];         }         if (nxt[a] >= 0) {           update(0, 0, N, nxt[a], -1);           prv[nxt[a]] = prv[a];           update(0, 0, N, nxt[a], 1);         }         st[B[a]].erase(a);         B[a] = b;         st[B[a]].insert(a);         auto it = st[B[a]].lower_bound(a);         ++it;         if (it != st[B[a]].end()) {           nxt[a] = *it;           update(0, 0, N, nxt[a], -1);           prv[*it] = a;           update(0, 0, N, nxt[a], 1);         } else           nxt[a] = -1;         --it;         if (it != st[B[a]].begin()) {           --it;           nxt[*it] = a;           prv[a] = *it;           ++it;         } else           prv[a] = -1;         update(0, 0, N, a, 1);       }     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     input();     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int N, A;   vector<int> X;   int main(void) {     cin.sync_with_stdio(0);     cin >> N;     int Curr = 0, __Cnt = 0;     for (int i = 0; i < N; i++) {       cin >> A;       if (A < 0) {         if (__Cnt == 2) {           __Cnt = 0;           X.push_back(Curr);           Curr = 0;         }         __Cnt++;       }       Curr++;     }     if (Curr) X.push_back(Curr);     int Cnt = X.size();     cout << Cnt << endl;     for (int i = 0; i < Cnt; i++) {       if (i) cout <<    ;       cout << X[i];     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, x, p, q, count = 0;     cin >> n;     vector<int> v;     vector<int>::iterator it;     for (int i = 0; i < n; i++) {       cin >> x;       v.push_back(x);     }     for (int i = 0; i < n; i++) {       p = i;       for (int j = i + 1; j < n; j++) {         if (v[p] == v[j]) {           v[p] = 0;           p = j;         }       }     }     for (it = v.begin(); it != v.end(); it++) {       if ((*it) != 0) count++;     }     cout << count << endl;     for (it = v.begin(); it != v.end(); it++) {       if ((*it) != 0) cout << *it <<    ;     }     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<vector<int> > g(7);   vector<int> vis(7);   int cycles = 0;   int nds = 0;   bool allvis() {     for (int i = 1; i <= 5; i++)       if (!vis[i]) return false;     return true;   }   bool dfs(int node, int par, int cnt) {     if (vis[node]) {       cycles++;       nds = cnt;       return true;     }     vis[node] = 1;     for (int i = 0; i < g[node].size(); i++) {       int child = g[node][i];       if (child != par) {         if (dfs(child, node, cnt + 1)) return true;       }     }     return false;   }   int main() {     int m;     while (cin >> m) {       g.clear();       g.resize(7);       vis.clear();       vis.resize(7);       cycles = 0;       nds = 0;       int a, b;       for (int i = 0; i < m; i++) {         cin >> a >> b;         g[a].push_back(b);         g[b].push_back(a);       }       int tmp = 0;       for (int i = 1; i <= 5; i++) {         if (g[i].size() < 2) tmp++;       }       dfs(1, 0, 0);       if (cycles == 1 && nds == 5 && m == 5)         cout <<  FAIL  << endl;       else         cout <<  WIN  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int TESTS = 1;     while (TESTS--) {       vector<pair<int, int>> v;       int i, a, b, index = 0, dp[1000005] = {0}, ans = INT_MIN, n;       cin >> n;       for (long long int i = 0; i < n; i++) {         cin >> a >> b;         v.push_back({a, b});       }       sort((v).begin(), (v).end());       for (i = 0; i < n; i++) {         while (index != v[i].first) {           dp[index] = dp[max(0, index - 1)];           index++;         }         if (index - v[i].second - 1 < 0)           dp[index] = 1;         else           dp[index] = dp[index - v[i].second - 1] + 1;         ans = max(ans, dp[index]);         index++;       }       cout << n - ans;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = INT_MAX / 2, NINF = INT_MIN / 2;   const long double PI = acos(-1.0);   void prepareIO() {     if (strlen(  ) != 0) {       freopen(                         .in ,            r , stdin);       freopen(                         .out ,            w , stdout);     }   }   void debout() {}   template <typename Head, typename... Tail>   void debout(Head H, Tail... T) {}   void stressout() {}   template <typename Head, typename... Tail>   void stressout(Head H, Tail... T) {}   void solve1();   int main() {     prepareIO();     solve1();     fprintf(stderr,  %.6lf n , (double)clock() / CLOCKS_PER_SEC);     return 0;   }   struct T {     int to, cnt, pos;   };   const int N = 1010;   int a[N], mark[N];   void solve1() {     int n;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];     }     int ans = 0, cnt = 0;     int to = 1;     int pos = 0;     while (cnt < n) {       if (a[pos] <= cnt && mark[pos] == false) {         mark[pos] = 1;         cnt++;         continue;       }       if (to == 1) {         if (pos == n - 1) {           ans++;           to ^= 1;           continue;         }         pos++;       } else {         if (pos == 0) {           ans++;           to ^= 1;           continue;         }         pos--;       }     }     printf( %d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   namespace output {   void __(short x) { cout << x; }   void __(unsigned x) { cout << x; }   void __(int x) { cout << x; }   void __(long long x) { cout << x; }   void __(unsigned long long x) { cout << x; }   void __(double x) { cout << x; }   void __(long double x) { cout << x; }   void __(char x) { cout << x; }   void __(const char* x) { cout << x; }   void __(const string& x) { cout << x; }   void __(bool x) { cout << (x ?  true  :  false ); }   template <class S, class T>   void __(const pair<S, T>& x) {     __(1 ?  (  :   ), __(x.first), __(1 ?  ,   :    ), __(x.second),         __(1 ?  )  :   );   }   template <class T>   void __(const vector<T>& x) {     __(1 ?  {  :   );     bool _ = 0;     for (const auto& v : x) __(_ ? 1 ?  ,   :     :   ), __(v), _ = 1;     __(1 ?  }  :   );   }   template <class T>   void __(const set<T>& x) {     __(1 ?  {  :   );     bool _ = 0;     for (const auto& v : x) __(_ ? 1 ?  ,   :     :   ), __(v), _ = 1;     __(1 ?  }  :   );   }   template <class T>   void __(const multiset<T>& x) {     __(1 ?  {  :   );     bool _ = 0;     for (const auto& v : x) __(_ ? 1 ?  ,   :     :   ), __(v), _ = 1;     __(1 ?  }  :   );   }   template <class S, class T>   void __(const map<S, T>& x) {     __(1 ?  {  :   );     bool _ = 0;     for (const auto& v : x) __(_ ? 1 ?  ,   :     :   ), __(v), _ = 1;     __(1 ?  }  :   );   }   void pr() { cout <<   n ; }   template <class S, class... T>   void pr(const S& a, const T&... b) {     __(a);     if (sizeof...(b)) __(   );     pr(b...);   }   }  // namespace output   using namespace output;   const int MN = 2e5 + 5;   int N, i, x, y, w, vs[MN], st[MN], ring[MN];   long long nxt[MN], ans[MN], sz[MN], dis[MN], len, idk[MN];   vector<pair<int, int> > adj[MN];   stack<int> s;   vector<int> cyc;   void detect(int n, int p) {     vs[n] = 1;     st[n] = 1;     s.push(n);     for (auto v : adj[n]) {       if (v.first == p) continue;       if (!vs[v.first]) detect(v.first, n);       if (st[v.first]) {         while (s.size() && s.top() != v.first) {           cyc.push_back(s.top());           s.pop();         }         cyc.push_back(s.top());         s.pop();       }     }     st[n] = 0;     if (s.size() && s.top() == n) s.pop();   }   void dfs(int n, int p) {     sz[n] = 1;     for (auto v : adj[n]) {       if (v.first == p || ring[v.first]) continue;       dfs(v.first, n);       sz[n] += sz[v.first];       ans[n] += 1LL * v.second * sz[v.first];       ans[n] += ans[v.first];     }   }   void dfs2(int n, int p, long long up) {     long long acc = 0;     for (auto v : adj[n]) {       if (v.first == p) {         up += 1LL * v.second * (N - sz[n]);         ans[n] += up;         continue;       }       if (ring[v.first]) continue;       acc += ans[v.first] + 1LL * v.second * sz[v.first];     }     for (auto v : adj[n]) {       if (v.first == p || ring[v.first]) continue;       dfs2(v.first, n, up + acc - ans[v.first] - 1LL * v.second * sz[v.first]);     }   }   void prop(int n, int p, long long val) {     ans[n] += val;     for (auto v : adj[n]) {       if (v.first == p || ring[v.first]) continue;       prop(v.first, n, val);     }   }   int main() {     for (scanf( %d , &N), i = 1; i <= N; i++) {       scanf( %d%d%d , &x, &y, &w);       adj[x].push_back({y, w});       adj[y].push_back({x, w});     }     detect(1, 0);     for (auto v : cyc) ring[v] = 1;     len = 0;     for (i = 1; i < (int)cyc.size(); i++) {       for (auto v : adj[cyc[i]]) {         if (v.first == cyc[i - 1]) {           dis[cyc[i]] = dis[v.first] + v.second;           idk[cyc[i]] = v.second;           nxt[cyc[i - 1]] = v.second;           len += v.second;           break;         }       }     }     for (auto v : adj[cyc[0]]) {       if (v.first == cyc.back()) {         len += v.second;         nxt[cyc.back()] = v.second;         idk[cyc[0]] = v.second;         break;       }     }     long long sigma = 0;     for (auto v : cyc) {       dfs(v, 0);       dfs2(v, 0, 0);       sigma += ans[v];     }     for (auto v : cyc) {       prop(v, 0, sigma - ans[v]);     }     long long ls = sz[cyc[0]], rs = 0, lsm = 0, rsm = 0, j, dist = idk[cyc[0]];     for (i = (int)cyc.size() - 1; i > 0; i--) {       rs += sz[cyc[i]];       rsm += dist * sz[cyc[i]];       dist += idk[cyc[i]];     }     dist = 0;     for (i = j = 0; i < (int)cyc.size(); i++) {       while ((dist + nxt[cyc[j]]) * 2 <= len) {         dist += nxt[cyc[j]];         j = (j + 1) % cyc.size();         long long dis2 = len - dist;         rs -= sz[cyc[j]];         rsm -= 1LL * dis2 * sz[cyc[j]];         ls += sz[cyc[j]];         lsm += 1LL * dist * sz[cyc[j]];       }       ls -= sz[cyc[i]];       rs += sz[cyc[i]];       long long cur = lsm + rsm;       prop(cyc[i], 0, cur);       if (i + 1 != cyc.size()) {         long long nxt = dis[cyc[i + 1]] - dis[cyc[i]];         lsm -= ls * nxt;         rsm += rs * nxt;         dist -= nxt;       }     }     for (i = 1; i <= N; i++) printf( %lld  , ans[i]);     pr();     return 0;   }


#include <bits/stdc++.h>   int main() {     int a, i, b, k, temp;     while (~scanf( %d , &a) && a >= 0) {       temp = 0;       while (a) {         b = a;         k = 0;         while (b > 0) {           if (k < b % 10) k = b % 10;           b = b / 10;         }         a -= k;         temp++;       }       printf( %d n , temp);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int delta[1000000], cnt[1000000];   int main() {     int n, m, dx, dy;     cin >> n >> m >> dx >> dy;     int x = 0, y = 0;     delta[0] = 0;     for (int i = 1; i < n; ++i) {       x = (x + dx) % n;       y = (y + dy) % n;       delta[x] = y;     }     for (int i = 0; i < n; ++i) cnt[i] = 0;     for (int i = 0; i < m; ++i) {       cin >> x >> y;       ++cnt[(y + n - delta[x]) % n];     }     int ans = 0;     for (int i = 0; i < n; ++i)       if (cnt[ans] < cnt[i]) ans = i;     cout << 0 <<     << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1000000009;   const double PI = acos(-1.0);   const double eps = 1e-8;   const int MAXN = 0;   const int MAXM = 0;   long long n, k, t, b, z;   int main() {     z = 1;     int ans = 0;     cin >> k >> b >> n >> t;     while (z <= t) {       ans++;       z = z * k + b;     }     if (z == t)       ans = n - ans;     else {       ans--;       ans = n - ans;     }     cout << max(0, ans) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long l, i = 0, n, d, t;     cin >> d >> n;     if (d != 1 && n == 0) {       cout <<  No solution n ;       return 0;     }     cout << n;     for (t = 1; t <= d - 1; t++) cout << 0;     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int a, b, c, d;     int n;     cin >> a >> b >> c >> d >> n;     vector<int> v(n);     for (int i = 0; i < n; i++) {       cin >> v[i];     }     cout <<  YES n ;     int row = max(b, d);     int col = a + c;     char ans[row][col];     for (int i = 0; i < row; i++) {       for (int j = 0; j < col; j++) {         ans[i][j] =  . ;       }     }     int x, y, yc;     int dir;     if (d % 2 == 1) {       y = a + c - 1;       yc = a;       x = d - 1;       dir = -1;     } else {       y = a;       yc = a + c - 1;       x = d - 1;       dir = 1;     }     int ind = 0;     for (int i = x; i >= 0; i--) {       for (int j = y; j < a + c and j > a - 1; j += dir) {         if (v[ind]) {           ans[i][j] =  a  + ind;           v[ind]--;         } else {           ind++;           j -= dir;         }       }       dir = (dir == 1) ? -1 : 1;       swap(y, yc);     }     dir = -1;     y = a - 1;     yc = 0;     for (int i = 0; i < b; i++) {       for (int j = y; j < a and j >= 0; j += dir) {         if (v[ind]) {           ans[i][j] =  a  + ind;           v[ind]--;         } else {           ind++;           j -= dir;         }       }       dir = (dir == 1) ? -1 : 1;       swap(y, yc);     }     for (int i = 0; i < row; i++) {       for (int j = 0; j < col; j++) {         cout << ans[i][j];       }       cout << endl;     }   }


#pragma GCC target ( avx2 )   #pragma GCC optimize ( O3 )   #pragma GCC optimize ( unroll-loops )      #include<bits/stdc++.h>   using namespace std;      // mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   // int rnd(int x, int y) {return (rng() % (y-x +1)) + x;};      #define ll long long   #define pb push_back   #define eb emplace_back   #define mp make_pair   #define lb lower_bound   #define ub upper_bound   #define ins insert   #define ull unsigned long long   #define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))   #define ff first   #define ss second   #define fast ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);   #define nl   n    #define sz(a) (int)(a).size()   #define all(a) (a).begin(),(a).end()   #define fl(a,x) memset(a,x,sizeof(a));   #define pt(a,x) cout << get<x>(a) <<     ;   #define mt make_tuple   #define vec vector   #define mxe max_element   #define mne max_element   #define present(c, x) (c.find(x) != c.end())   #define printall(a) for(auto i : a) cout << i <<     ; cout << nl ;      #define int long long      typedef vector<int> vii;   typedef vector<ll> vll;   typedef pair<int,int> pii;   typedef pair<ll,ll> pll;   typedef vector<pii> vpi;   typedef vector<pll> vpl;   typedef vector<vii> vvi;   typedef vector<vll> vvl;      #define error(args...) { string _s = #args; replace(_s.begin(), _s.end(),  , ,    ); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }      void err(istream_iterator<string> it) {}   template<typename T, typename... Args>   void err(istream_iterator<string> it, T a, Args... args) {       cout << *it <<   =   << a << endl;       err(++it, args...);   }      const int mod = (int) 1e9 + 7 ;   const int MOD = (int) 998244353 ;   const ll INF = (ll) 1e18;      inline int add(int a, int b) {return (a + b >= mod ? a + b - mod : a + b);}   inline int mul(int a, int b) {return (ll) a * b % mod ; }      void solve() {          int n; cin >> n ;       string s; cin >> s;        int ans = 0 ;        int id = 0 , cnt = 0 ;        int x = count(all(s),  * ) ;        rep(i,0,n) {           cnt += (s[i] ==  * ) ;            if(cnt == (x+1)/2) {               id = i ;                break ;           }       }       cnt = 0 ;        for(int i = id + 1 ; i < n ; ++i) {           if(s[i] !=  * ) continue ;            ans += i - id - 1 - cnt ;            ++cnt ;        }       cnt = 0 ;        for(int i = id - 1 ; i >= 0 ; --i) {           if(s[i] !=  * ) continue ;            ans += id - i - 1 - cnt ;            ++cnt ;        }       cout << ans << nl ;   }         int32_t main() {          fast;       int t; cin >> t ; rep(i,0,t)            solve() ;       // cout <<  Time elapsed:   << 1.0 * clock() / CLOCKS_PER_SEC <<   s. n ;       return 0;   }


#include <bits/stdc++.h>   const double eps = (1e-9);   using namespace std;   int dcmp(long double a, long double b) {     return fabsl(a - b) <= eps ? 0 : (a > b) ? 1 : -1;   }   int getBit(int num, int idx) { return ((num >> idx) & 1) == 1; }   int setBit1(int num, int idx) { return num | (1 << idx); }   long long setBit0(long long num, int idx) { return num & ~(1ll << idx); }   long long flipBit(int num, int idx) { return num ^ (1 << idx); }   void FS() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   int countNumBit1(int mask) {     int ret = 0;     while (mask) {       mask &= (mask - 1);       ++ret;     }     return ret;   }   const int N = 100009;   int arr[N];   int main() {     int n;     cin >> n;     int mx = -1;     for (int i = 0; i < n; i++) {       cin >> arr[i];       if (arr[i] > mx) {         mx = arr[i];       }     }     int mxlen = 1;     int cnt = 0, str = -1, en = 0;     for (int i = 0; i < n; i++) {       if (arr[i] == mx) {         if (str == -1) str = i;         en = i;       } else {         if (str != -1) mxlen = max(mxlen, en - str + 1);         str = -1;       }     }     if (str != -1) mxlen = max(mxlen, en - str + 1);     cout << mxlen << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   pair<long long, long long> ps[300010];   long long x;   int main() {     cin >> x;     if (x == 1) {       puts( 1 n1 1 );       return 0;     }     ps[0].first = 1, ps[0].second = x;     bool f1 = 0;     long long c = 2, f2 = 0;     int t = 1;     while (1) {       long long re = x - 1ll * c * (c - 1) * (2 * c - 1) / 6;       long long p = 1ll * c * (c - 1) / 2;       re += 1ll * c * p;       long long m1 = re % (1ll * c * c - p);       long long m = re / (1ll * c * c - p);       if (c > m) break;       if (!m1) {         if (c == m)           f2 = c;         else           ps[t++] = make_pair(c, m);       }       c++;     }     if (f2)       cout << (2 * t + 1) << endl;     else       cout << (2 * t) << endl;     for (int i = 0; i < t; i++) {       cout << ps[i].first <<     << ps[i].second << endl;     }     if (f2) cout << f2 <<     << f2 << endl;     for (int i = t - 1; i >= 0; i--) {       cout << ps[i].second <<     << ps[i].first << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long a[20];   long long b[20];   int getbit(long long x) {     int ret = 0;     while (x) {       x /= 10;       ++ret;     }     return ret;   }   int main() {     a[1] = 9;     b[1] = 9;     for (int i = 2; i <= 18; ++i) b[i] = b[i - 1] * 10 + 9;     for (int i = 2; i <= 18; ++i) a[i] = a[i - 1] * 10;     long long w, m, k;     while (cin >> w >> m >> k) {       long long num = getbit(m);       long long cnt = b[num] - m + 1;       long long ans = 0;       if (w <= num * k * cnt || (num * k * cnt) <= 0) {         ans = w / (num * k);       } else {         ans = cnt;         w -= cnt * num * k;         for (int i = num + 1; w > 0; ++i) {           if (w <= a[i] * i * k || a[i] * i * k <= 0) {             ans += w / (i * k);             break;           } else {             ans += a[i];             w -= a[i] * k * i;           }         }       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 514;   int mat[MAX][MAX];   int aib[MAX][MAX];   int n, m;   int dx[] = {1, 0};   int dy[] = {0, 1};   inline int inside(int x, int y) {     return x <= n and y <= m and x >= 1 and y >= 1;   }   int jos[MAX][MAX];   int dreapta[MAX][MAX];   int main() {     ios ::sync_with_stdio(false);     cin >> n >> m;     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= m; ++j) {         char c;         cin >> c;         if (c ==  # ) ++mat[i][j];       }     }     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= m; ++j) {         for (int k = 0; k <= 1; ++k) {           if (inside(i + dx[k], j + dy[k])) {             if (mat[i][j] == 0 and mat[i + dx[k]][j + dy[k]] == 0) {               aib[i][j]++;               if (k == 0) {                 jos[i][j]++;               } else {                 dreapta[i][j]++;               }             }           }         }         aib[i][j] += aib[i - 1][j];         aib[i][j] += aib[i][j - 1];         aib[i][j] -= aib[i - 1][j - 1];         jos[i][j] += jos[i][j - 1];         dreapta[i][j] += dreapta[i - 1][j];       }     }     int q;     cin >> q;     while (q--) {       int a, b, c, d;       cin >> a >> b >> c >> d;       int dr = dreapta[c][d] - dreapta[a - 1][d];       int jj = jos[c][d] - jos[c][b - 1];       cout << aib[c][d] - aib[c][b - 1] - aib[a - 1][d] + aib[a - 1][b - 1] - dr -                   jj            <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<long long> adj[205];   bool vis[205];   long long dp[205];   void dfs(long long v) {     vis[v] = true;     for (long long first : adj[v]) {       if (!vis[first]) {         dfs(first);         dp[v] = max(dp[first] + 1, dp[v]);       }     }   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long n;     cin >> n;     map<string, long long> m;     long long curr = 2;     m[ polycarp ] = 1;     for (long long i = 0; i < n; i++) {       string s1, s2, s3;       cin >> s1 >> s2 >> s3;       for (char &c : s1) c = tolower(c);       for (char &c : s3) c = tolower(c);       if (!m[s1]) m[s1] = curr++;       if (!m[s3]) m[s3] = curr++;       adj[m[s3]].emplace_back(m[s1]);     }     dfs(1);     cout << dp[1] + 1;   }


#include <bits/stdc++.h>   int main() {     long long a, b;     scanf( %I64d %I64d , &a, &b);     printf( %I64d n , (6LL * a - 1LL) * b);     for (long long i = 1; i <= a; i++) {       printf( %I64d %I64d %I64d %I64d n , (6LL * i - 5LL) * b,              (6LL * i - 4LL) * b, (6LL * i - 3LL) * b, (6LL * i - 1LL) * b);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     double x, r1 = 0, p1 = 0, p2 = 999999999999, a, b;     cin >> n;     while (n--) {       cin >> x;       r1 = max(r1, x);     }     cin >> n;     while (n--) {       cin >> x;       p1 = max(p1, x);     }     cin >> n;     while (n--) {       cin >> x;       p2 = min(p2, x);     }     cin >> a >> b;     x = b * p1;     double up = x * r1 * r1, down = a * p2 + x;     cout << setprecision(10) << sqrt(up / down);   }


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


#include <bits/stdc++.h>   using namespace std;   struct caca {     long long a, b;   };   caca v[7005];   bool ok[7005];   bool cmp(caca a, caca b) { return a.a < b.a; }   int main() {     cin.tie(0)->sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     int n;     cin >> n;     for (int i = 1; i <= n; i++) cin >> v[i].a;     for (int i = 1; i <= n; i++) cin >> v[i].b;     sort(v + 1, v + n + 1, cmp);     v[0].a = -1;     v[n + 1].a = -1;     for (int i = 1; i <= n; i++) {       if (v[i].a == v[i - 1].a || v[i].a == v[i + 1].a) {         ok[i] = 1;         for (int j = 1; j <= n; j++) {           if ((v[i].a & v[j].a) == v[j].a) {             ok[j] = 1;           }         }       }     }     long long sol = 0;     for (int i = 1; i <= n; i++) {       if (ok[i]) {         sol += v[i].b;       }     }     cout << sol;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100 + 10;   int n, m;   int SG[N << 1];      int main() {       int T;       for(scanf( %d , &T); T--; ) {           scanf( %d%d , &n, &m);           memset(SG, 0, (n + m) << 2);           for(int i = 0; i < n; i++) {               for(int j = 0; j < m; j++) {                   int x;                   scanf( %d , &x);                   SG[i + j] ^= x;               }           }           int flag = 0;           for(int i = 0; i <= n + m - 2; i++) if(SG[i]) flag = 1;           if(flag) printf( Ashish n );           else printf( Jeel n );       }       return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     string s;     cin >> s;     long long int n = s.length(), i;     stack<char> a;     for (i = 0; i < n; i++) {       if (a.empty())         a.push(s[i]);       else {         if (a.top() == s[i])           a.pop();         else           a.push(s[i]);       }     }     if (a.size() != 0)       cout <<  No ;     else       cout <<  Yes ;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9;   const int N = 122231;   int n, k;   vector<int> g[N];   int used[N];   int done[150][150][150];   int memo[150][150][150];   vector<int> sons[N];   int max_dep[N];   void dfs(int v) {     used[v] = 1;     max_dep[v] = 0;     for (int i = 0; i < g[v].size(); i++) {       int to = g[v][i];       if (used[to]) continue;       sons[v].push_back(to);       dfs(to);       max_dep[v] = max(max_dep[v], max_dep[to] + 1);     }   }   int solve(int v, int top1, int covered_pref) {     if (done[v][top1][covered_pref]) return memo[v][top1][covered_pref];     done[v][top1][covered_pref] = 1;     if (top1 == 100) {       memo[v][top1][covered_pref] = (covered_pref > max_dep[v]);       return memo[v][top1][covered_pref];     }     if (top1 > k && covered_pref == 0) {       memo[v][top1][covered_pref] = 0;       return 0;     }     long long ways[2], nways[2];     ways[0] = ways[1] = nways[0] = nways[1] = 0;     if (top1 == 0) {       ways[1] = 1;     } else {       ways[0] = 1;     }     for (int i = 0; i < sons[v].size(); i++) {       int to = sons[v][i];       for (int j = 0; j < 2; j++) nways[j] = 0;       int new_pref = max(covered_pref - 1, k - top1);       if (new_pref < 0) new_pref = 0;       for (int dep_there = 0; dep_there <= 100; dep_there++) {         int is_ok_dep = 1;         if (dep_there + 1 < top1) is_ok_dep = 0;         if (dep_there == 100) {           if (new_pref <= max_dep[to]) is_ok_dep = 0;         } else {           int covered2 = dep_there - k;           if (covered2 > new_pref) is_ok_dep = 0;         }         if (is_ok_dep == 0) continue;         if (solve(to, dep_there, new_pref) == 0) continue;         for (int j = 0; j < 2; j++) {           nways[j | ((dep_there + 1) == top1)] =               1ll * nways[j | ((dep_there + 1) == top1)] +               1ll * ways[j] * solve(to, dep_there, new_pref) % 1000000007;           nways[j | ((dep_there + 1) == top1)] %= 1000000007;         }       }       for (int j = 0; j < 2; j++) {         ways[j] = nways[j];       }     }     memo[v][top1][covered_pref] = ways[1];     return memo[v][top1][covered_pref];   }   int main() {     ios_base::sync_with_stdio(0);     cin >> n >> k;     for (int i = 1; i < n; i++) {       int a, b;       cin >> a >> b;       g[a].push_back(b);       g[b].push_back(a);     }     int root = 1;     dfs(root);     int res = 0;     for (int i = 0; i <= k; i++) {       res += solve(root, i, 0);       res %= 1000000007;     }     cout << res << endl;     cin.get();     cin.get();     return 0;   }


#include <bits/stdc++.h>   const int INF = 1 << 29;   using namespace std;   void put(int i) {     cout << (i == 0 ? 0 : i);     exit(0);   }   int main() {     std::ios_base::sync_with_stdio(false);     std::cin.tie(NULL);     ;     int n, x, y;     cin >> n;     vector<int> v(n), sum(n);     for (int i = 0; i < n; ++i) {       cin >> v[i];       if (!i)         sum[i] = v[i];       else         sum[i] = sum[i - 1] + v[i];     }     cin >> x >> y;     for (int i = 1; i < n; ++i) {       int p1 = sum[i - 1];       int p2 = sum[n - 1] - sum[i - 1];       if (p1 >= x && p1 <= y && p2 >= x && p2 <= y) put(i + 1);     }     put(0);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 200010, M = 400010, mod = 1e9 + 7;   int n, m, k;   int h[N], e[M], ne[M], idx;   int a[N], b[N], ans[N];   int ind[N], oud[N], cnt;   bool stn[N], stm[M];   struct Edge {     int a, b;   } edge[M];   void add(int a, int b) { e[idx] = b, ne[idx] = h[a], h[a] = idx++; }   queue<int> q;   void delet_node() {     while (!q.empty()) {       int t = q.front();       q.pop();       for (int i = h[t]; ~i; i = ne[i]) {         if (stm[i]) continue;         int j = e[i];         ind[j]--;         if (ind[j] < k && !stn[j]) {           q.push(j), stn[j] = 1, cnt--;         }       }     }   }   void topsort() {     for (int i = 1; i <= n; i++) {       if (ind[i] < k) q.push(i), cnt--, stn[i] = 1;     }     delet_node();     for (int i = m; i >= 1; i--) {       ans[i] = cnt;       int a = edge[i].a, b = edge[i].b;       if (!stn[a] && !stn[b]) ind[a]--, ind[b]--;       stm[--idx] = 1, stm[--idx] = 1;       if (ind[a] < k && !stn[a]) q.push(a), stn[a] = 1, cnt--;       if (ind[b] < k && !stn[b]) q.push(b), stn[b] = 1, cnt--;       delet_node();     }     for (int i = 1; i <= m; i++) cout << ans[i] << endl;   }   int main() {     memset(h, -1, sizeof h);     scanf( %d%d%d , &n, &m, &k);     cnt = n;     for (int i = 1; i <= m; i++) {       int a, b;       scanf( %d%d , &a, &b);       edge[i] = {a, b};       add(a, b), add(b, a);       ind[a]++, ind[b]++;     }     topsort();   }


#include <bits/stdc++.h>   using namespace std;   vector<int> g[200009];   int c[200009];   set<int> col[200009];   int main() {     int n, m;     scanf( %d , &n);     scanf( %d , &m);     int fans = 1e6;     for (int i = 1; i <= n; i++) {       scanf( %d , &c[i]);       fans = min(fans, c[i]);     }     for (int i = 0; i < m; i++) {       int x, y;       scanf( %d , &x);       scanf( %d , &y);       g[x].push_back(y);       g[y].push_back(x);     }     for (int i = 1; i <= n; i++) {       int id = c[i];       for (int j = 0; j < g[i].size(); j++) {         if (c[g[i][j]] != id) {           col[id].insert(c[g[i][j]]);         }       }     }     int maxx = -1, maxid = -1;     for (int i = 1; i <= 100000; i++) {       int sz = col[i].size();       if (maxx < sz) {         maxx = sz;         maxid = i;       }     }     if (maxx == 0) {       maxid = fans;     }     printf( %d n , maxid);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using lli = long long int;   using pii = pair<int, int>;   using vi = vector<int>;   using vb = vector<bool>;   using vvi = vector<vector<int>>;   using vlli = vector<long long int>;   using vpii = vector<pair<int, int>>;   const int N = 500005;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   lli n, m, k, u, v, x, ans, curr, T;   vlli c(N);   lli fast_exp(lli base, lli exp) {     lli res = 1;     base = base % 1000000007;     while (exp > 0) {       if (exp % 2) res = (res * base) % 1000000007;       base = (base * base) % 1000000007;       exp /= 2;     }     return res % 1000000007;   }   template <class T>   struct DSU {     map<T, T> par;     T comp_sz = n;     T get(T u) {       if (par.find(u) == par.end()) return u;       return par[u] = get(par[u]);     }     void unite(T x, T y) {       T X = get(x), Y = get(y);       if (X == Y) return;       par[X] = Y;       --comp_sz;     }   };   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> m >> k;     map<lli, DSU<lli>> virus;     for (int i = 1; i <= n; i++) cin >> c[i];     for (int i = 1; i <= m; i++) {       cin >> u >> v;       x = c[u] ^ c[v];       virus[x].unite(u, v);     }     ans = ((fast_exp(2, k) - virus.size() + 1000000007) * fast_exp(2, n)) %           1000000007;     for (auto i : virus) {       curr = (i.second).comp_sz;       ans = (ans + fast_exp(2, curr)) % 1000000007;     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1.0);   const double eps = pi / 180.0;   int main() {     int t;     cin >> t;     while (t--) {       double n;       cin >> n;       double angle = 180.0 / n;       double first = 1.0 / 2.0 / sin(angle / 2.0 * eps);       double a1 = 180.0 / n * round(n / 4.0);       double a2 = 90 - a1;       double ans = first * (sin(a1 * eps) + sin(a2 * eps)) / sin(45.0 * eps);       printf( %.9lf n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     set<char> c;     int mul = 0;     long long ans = 1;     bool f = false;     string s;     cin >> s;     for (int i = 0; i < s.length(); i++) {       if (s[i] ==  ? )         ans *= 10;       else if (s[i] >= 65 && s[i] <= 74)         c.insert(s[i]);     }     if (s[0] >= 65 && s[0] <= 74 || s[0] ==  ? ) f = true;     for (int i = 0; i < c.size(); i++) ans *= (10 - i);     if (f == true) ans *= 0.9;     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool f[1005];   vector<int> x[1005];   vector<int> y[1005];   int dx[4] = {1, 1, -1, -1};   int dy[4] = {1, -1, 1, -1};   int main() {     for (int i = 1; i <= 1000; i++) {       for (int j = 1; j <= 1000; j++) {         int p = i * i + j * j;         int u = (int)(sqrt(p));         if (u * u == p && u <= 1000) {           f[u] = 1;           x[u].push_back(i);           y[u].push_back(j);         }       }     }     int a, b;     scanf( %d%d , &a, &b);     if (f[a] && f[b]) {       for (int r = 0; r < x[a].size(); r++)         for (int s = 0; s < x[b].size(); s++) {           int u = x[a][r], v = y[a][r];           for (int i = 0; i < 4; i++) {             int p = u * dx[i];             int q = v * dy[i];             if (x[b][s] * p + y[b][s] * q == 0 &&                 (x[b][s] != p && y[b][s] != q)) {               printf( YES n );               printf( 0 0 n );               printf( %d %d n , x[b][s], y[b][s]);               printf( %d %d n , p, q);               return 0;             }           }           swap(u, v);           for (int i = 0; i < 4; i++) {             int p = u * dx[i];             int q = v * dy[i];             if (x[b][s] * p + y[b][s] * q == 0 &&                 (x[b][s] != p && y[b][s] != q)) {               printf( YES n );               printf( 0 0 n );               printf( %d %d n , x[b][s], y[b][s]);               printf( %d %d n , p, q);               return 0;             }           }         }       printf( NO n );     } else       printf( NO n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int m, k, n, s;     cin >> m >> k >> n >> s;     int len = m - k * (n - 1);     vector<int> a(m);     for (auto& i : a) {       cin >> i;     }     int bad = 0;     vector<int> cnt(5e5 + 1);     for (int i = 0; i < s; ++i) {       int b;       cin >> b;       bad += !cnt[b];       ++cnt[b];     }     bool ok = false;     vector<int> ans;     for (int i = 0; i < m; ++i) {       --cnt[a[i]];       bad -= !cnt[a[i]];       int j = i - len + 1;       if (j >= 0) {         if (!bad && j % k == 0) {           for (int l = j; len - int(ans.size()) > k; ++l) {             if (cnt[a[l]] < 0) {               ans.push_back(l);               ++cnt[a[l]];             }           }           ok = true;           break;         }         bad += !cnt[a[j]];         ++cnt[a[j]];       }     }     if (!ok) {       cout << -1 <<   n ;     } else {       cout << ans.size() <<   n ;       for (auto i : ans) {         cout << i + 1 <<    ;       }     }   }


#include <bits/stdc++.h>   const int maxn = 5e5 + 5;   const int logn = 21;   const int lim = 2e1;   const int maxq = 5e5 + 5;   struct w {     int l, r, id;     friend bool operator<(w now, w oth) { return now.r < oth.r; }   } qu[maxq];   int b[logn], p[logn];   void insert(int gave, int id) {     for (int i = lim; i >= 0; i--) {       if (!(gave >> i & 1)) continue;       if (!b[i]) {         b[i] = gave;         p[i] = id;         return;       }       if (p[i] < id) {         std::swap(p[i], id);         std::swap(b[i], gave);       }       gave ^= b[i];     }     return;   }   int tian(int lef) {     int r = 0;     for (int i = lim; i >= 0; i--)       if (p[i] >= lef) r = std::max(r, r ^ b[i]);     return r;   }   int o[maxq];   int n, q;   int v[maxn];   signed main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , v + i);     scanf( %d , &q);     for (int i = 1; i <= q; i++) {       scanf( %d%d , &qu[i].l, &qu[i].r);       qu[i].id = i;     }     std::sort(qu + 1, qu + q + 1);     int nr = 0;     for (int i = 1; i <= q; i++) {       while (nr < qu[i].r) {         nr++;         insert(v[nr], nr);       }       o[qu[i].id] = tian(qu[i].l);     }     for (int i = 1; i <= q; i++) printf( %d n , o[i]);     return 0;   }


#include <queue>   #include <vector>   #include <stdio.h>   #include <stdlib.h>      #define DEBUG printf( Passing [%s] in Line %d n  , __FUNCTION__ , __LINE__) ;      const int MAX_N = (1 << 11) + 10 , MAX_M = 10 + 5 , MAX_E = (1 << 22) + 10 , INF = 0x3f3f3f3f ;      struct Link {    int num , cap , cost ;    Link *next , *reg ;   }list[MAX_E] ;      std::queue<int> q ;   std::vector<int> ans ;      char s[MAX_N][MAX_M] ;   Link *head[MAX_N] , *id[MAX_N] ;   bool st[MAX_N] , ud[MAX_M] , vis[MAX_N] ;   int n , m , tot , cur , pt[MAX_N][2] , lt[MAX_N] ;   int S , T , pre[MAX_N] , dis[MAX_N] , flow[MAX_N] ;      void ins(int x , int y , int f , int c) {    list[cur].num = y ;    list[cur].cap = f ;    list[cur].cost = c ;    list[cur].reg = &list[cur + 1] ;    list[cur].next = head[x] ;    head[x] = &list[cur++] ;       list[cur].num = x ;    list[cur].cap = 0 ;    list[cur].cost = -c ;    list[cur].reg = &list[cur - 1] ;    list[cur].next = head[y] ;    head[y] = &list[cur++] ;   }      ///      bool spfa() {    for (int i = 0 ; i <= tot ; ++i) dis[i] = INF , vis[i] = 0 ;    vis[S] = 1 ; dis[S] = 0 ; flow[S] = INF ; q.push(S) ;       while (!q.empty()) {     int x = q.front() ; vis[x] = 0 ; q.pop() ;        for (Link *h = head[x] ; h ; h = h->next) {      int nx = h->num ;      if (dis[nx] <= dis[x] + h->cost || !h->cap) continue ;         flow[nx] = std::min(flow[x] , h->cap) ;      dis[nx] = dis[x] + h->cost ;      pre[nx] = x ; id[nx] = h ;         if (!vis[nx]) {vis[nx] = 1 ; q.push(nx) ;}     }    }       return dis[T] < INF ;   }      void dinic() {    while (spfa()) {     int x = T ;     for (; x != S ; x = pre[x]) {      id[x]->cap -= flow[T] ;      id[x]->reg->cap += flow[T] ;     }    }   }      ///      int main() {    scanf( %d %d  , &m , &n) ;    for (int i = 1 ; i <= n ; ++i) scanf( %s  , s[i]) ;       ///       for (int i = 1 ; i <= n ; ++i) pt[i][0] = ++tot , pt[i][1] = ++tot ;    S = 0 ; T = ++tot ;       for (int i = 1 ; i <= n ; ++i) {     int cnt = 1 ;     for (int j = 0 ; j < m ; ++j) if (s[i][j] ==  1 ) ++cnt ;        for (int j = 1 ; j <= n ; ++j) {      if (i == j) continue ;         bool ok = 1 ;      for (int k = 0 ; k < m ; ++k) if (s[i][k] ==  1  && s[j][k] ==  0 ) ok = 0 ;      if (ok) ins(pt[i][0] , pt[j][1] , 1 , -cnt) ;     }    }       for (int i = 1 ; i <= n ; ++i)     ins(S , pt[i][0] , 1 , 0) , ins(pt[i][1] , T , 1 , 0) ;       ///       dinic() ;    for (int i = 1 ; i <= n ; ++i) {     int x = pt[i][0] ;     for (Link *h = head[x] ; h ; h = h->next) {      int nx = h->num ;      if (h->cap || !nx) continue ;         nx >>= 1 ;      lt[(x + 1) >> 1] = nx ; st[nx] = 1 ;     }    }       ///       for (int i = 1 ; i <= n ; ++i)     if (!st[i]) {      for (int j = 0 ; j < m ; ++j) ud[j] = 0 ;      for (int j = i ; j ; j = lt[j])       for (int k = 0 ; k < m ; ++k)        if (s[j][k] ==  1  && !ud[k]) ans.push_back(k) , ud[k] = 1 ;      ans.push_back(-1) ;     }       int m = ans.size() - 1 ;    printf( %d n  , m) ;    for (int i = 0 ; i < m ; ++i) {     int x = ans[i] ;     if (x == -1) printf( R  ) ;     else printf( %d   , x) ;    }    printf(  n ) ;       return 0 ;   }


#include <bits/stdc++.h>   using namespace std;   template <class t>   t mag(t a) {     return a > 0 ? a : -a;   }   template <class T>   T cdiv(T num, T den) {     return (num / den) + (num % den > 0);   }   std::ifstream term( /dev/tty );   std::string tempstring;   using ll = int_fast64_t;   using ii = pair<ll, ll>;   using vi = vector<int>;   using vl = vector<ll>;   using vii = vector<ii>;   int tc = 1;   const ll sij = 40001000;   const ll mod = 1000000007ll;   ll n, m;   bool vis[1510][1510];   string vec[1510];   int mx[] = {0, 0, -1, 1}, my[] = {-1, 1, 0, 0};   ii st;   ll msk[1510][1510], msy[1510][1510];   int esc(int tcase) {     cin >> n >> m;     for (int i = 0; i < n; i++) {       cin >> vec[i];     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (vec[i][j] ==  S ) {           st = {i, j};         }       }     }     st.first = st.first + n * mod;     st.second = st.second + m * mod;     msk[st.first % n][st.second % m] = st.first;     msy[st.first % n][st.second % m] = st.second;     queue<ii> q;     q.push(st);     while (!q.empty()) {       ii cr = q.front();       q.pop();       for (int i = 0; i < 4; i++) {         ll gx = cr.first + mx[i], gy = cr.second + my[i];         if (vec[gx % n][gy % m] ==  # ) continue;         if (msk[gx % n][gy % m] == 0) {           q.push({gx, gy});           msk[gx % n][gy % m] = gx;           msy[gx % n][gy % m] = gy;           continue;         }         if (msk[gx % n][gy % m] != gx or msy[gx % n][gy % m] != gy) {           cout <<  Yes ;           return 0;         }       }     }     cout <<  No ;     return 0;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     for (int i = 1; i <= tc; i++) esc(i);   }


#include <bits/stdc++.h>   using namespace std;   char ch, B[1 << 20], *S = B, *T = B;   long long aa, bb;   long long rd() {     while (ch = (S == T && (T = (S = B) + fread(B, 1, 1 << 20, stdin), S == T)                      ? 0                      : *S++),            !(ch >=  0  && ch <=  9 ) && ch !=  - )       ;     ch ==  -  ? aa = bb = 0 : (aa = ch -  0 , bb = 1);     while (ch = (S == T && (T = (S = B) + fread(B, 1, 1 << 20, stdin), S == T)                      ? 0                      : *S++),            (ch >=  0  && ch <=  9 ))       aa = aa * 10 + ch -  0 ;     return bb ? aa : -aa;   }   const long long MAXN = 1e5 + 10;   long long n, k, ans, b[MAXN], tr[MAXN];   struct Node {     long long pos, l, r, q, len;   } a[MAXN];   bool cmp1(Node a, Node b) { return a.len > b.len; }   bool cmp2(Node a, Node b) { return a.q < b.q; }   inline void add(long long x, long long c) {     while (x <= n) {       tr[x] += c;       x += (x & (-x));     }   }   long long sum(long long x) {     long long ret = 0;     while (x) {       ret += tr[x];       x -= (x & (-x));     }     return ret;   }   long long query(long long l, long long r) { return sum(r) - sum(l - 1); }   inline void cdq(long long l, long long r) {     if (l == r) return;     long long mid = (l + r) >> 1;     cdq(l, mid);     cdq(mid + 1, r);     long long L = l, R = l - 1;     for (register long long i = mid + 1; i <= r; ++i) {       while (L <= mid && a[i].q - a[L].q > k) {         add(a[L].pos, -1);         ++L;       }       while (R < mid && a[R + 1].q - a[i].q <= k) {         ++R;         add(a[R].pos, 1);       }       ans += query(a[i].l, a[i].r);     }     for (register long long i = L; i <= R; ++i) add(a[i].pos, -1);     sort(a + l, a + r + 1, cmp2);   }   inline void work() {     n = rd();     k = rd();     for (register long long i = 1; i <= n; ++i) {       a[i].pos = rd();       a[i].len = rd();       a[i].q = rd();       b[i] = a[i].pos;     }     sort(b + 1, b + n + 1);     long long cnt = unique(b + 1, b + n + 1) - b - 1;     for (register long long i = 1; i <= n; ++i) {       a[i].l = lower_bound(b + 1, b + cnt + 1, a[i].pos - a[i].len) - b;       a[i].r = upper_bound(b + 1, b + cnt + 1, a[i].pos + a[i].len) - b - 1;       a[i].pos = lower_bound(b + 1, b + cnt + 1, a[i].pos) - b;     }     sort(a + 1, a + n + 1, cmp1);     cdq(1, n);     printf( %lld n , ans);   }   signed main() {     work();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   void splitstr(const string &s, vector<T> &out) {     istringstream in(s);     out.clear();     copy(istream_iterator<T>(in), istream_iterator<T>(), back_inserter(out));   }   template <class T>   T gcd(T a, T b) {     return b ? gcd(b, a % b) : a;   }   static void redirect(int argc, const char **argv) {     ios::sync_with_stdio(false);     cin.tie(NULL);     if (argc > 1) {       static filebuf f;       f.open(argv[1], ios::in);       cin.rdbuf(&f);       if (!cin) {         cerr <<  Failed to open    << argv[1] <<     << endl;         exit(1);       }     }     if (argc > 2) {       static filebuf f;       f.open(argv[2], ios::out | ios::trunc);       cout.rdbuf(&f);       if (!cout) {         cerr <<  Failed to open    << argv[2] <<     << endl;       }     }   }   static void no() {     cout <<  -1 n ;     exit(0);   }   static void check_dist(const vector<int> &dist,                          const vector<vector<int>> &edges, int cur, int parent,                          int depth) {     if (dist[cur] != depth) no();     for (int v : edges[cur])       if (v != parent) check_dist(dist, edges, v, cur, depth + 1);   }   int main(int argc, const char **argv) {     redirect(argc, argv);     int N, K;     cin >> N >> K;     vector<vector<int>> dist(K, vector<int>(N));     vector<int> opos(K, -1);     for (int i = 0; i < K; i++)       for (int j = 0; j < N; j++) {         cin >> dist[i][j];         if (dist[i][j] == 0) opos[i] = j;       }     if (count(begin(opos), end(opos), -1)) no();     int root = opos[0];     vector<int> parent(N, -1);     parent[root] = -2;     vector<vector<int>> order(K);     for (int i = 1; i < K; i++) {       if (dist[i][root] == 0) no();       order[i].resize(dist[i][root] + 1, -1);       for (int j = 0; j < N; j++)         if (dist[i][j] + dist[0][j] == dist[i][root]) order[i][dist[0][j]] = j;       if (order[i][0] != root) no();       for (int j = 1; j < ((long long)(order[i]).size()); j++) {         int v = order[i][j];         if (v == -1) no();         if (parent[v] != -1 && parent[v] != order[i][j - 1]) no();         parent[v] = order[i][j - 1];       }     }     vector<vector<pair<int, int>>> down(N);     for (int i = 0; i < N; i++)       if (parent[i] == -1) {         int hi = -1;         int v = root;         int d = dist[0][i];         pair<int, int> best(0, 0);         for (int j = 1; j < K; j++) {           int a = dist[0][i] + dist[j][root] - dist[j][i];           if (a < 0 || a > 2 * dist[j][root] || (a & 1)) no();           a /= 2;           if (a > hi) {             hi = a;             v = order[j][a];             d = dist[0][i] - a;           }         }         down[v].emplace_back(d, i);       }     vector<int> lvl;     for (int i = 0; i < N; i++) {       if (down[i].empty()) continue;       sort(begin(down[i]), end(down[i]));       lvl.clear();       lvl.push_back(i);       for (const auto &entry : down[i]) {         int d = entry.first;         int v = entry.second;         if (d > ((long long)(lvl).size()))           no();         else {           parent[v] = lvl[d - 1];           if (d == ((long long)(lvl).size())) lvl.push_back(v);         }       }     }     vector<vector<int>> edges(N);     for (int i = 0; i < N; i++) {       if (parent[i] == -1)         no();       else if (parent[i] >= 0) {         edges[parent[i]].push_back(i);         edges[i].push_back(parent[i]);       }     }     for (int i = 0; i < K; i++) check_dist(dist[i], edges, opos[i], -1, 0);     for (int i = 0; i < N; i++)       if (parent[i] >= 0) cout << i + 1 <<     << parent[i] + 1 <<   n ;     return 0;   }


#include <bits/stdc++.h>   int main() {     int n, i, sum1, sum2, sum3;     scanf( %d , &n);     sum1 = 0;     for (i = 0; i < n; i++) {       int a;       scanf( %d , &a);       sum1 ^= a;     }     sum2 = 0;     for (i = 0; i < n - 1; i++) {       int b;       scanf( %d , &b);       sum2 ^= b;     }     sum3 = 0;     for (i = 0; i < n - 2; i++) {       int c;       scanf( %d , &c);       sum3 ^= c;     }     printf( %d n%d n , sum1 ^ sum2, sum2 ^ sum3);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = ~0U >> 1;   const long long INF = ~0ULL >> 1;   template <class T>   inline void read(T &n) {     char c;     int flag = 1;     for (c = getchar(); !(c >=  0  && c <=  9  || c ==  - ); c = getchar())       ;     if (c ==  - )       flag = -1, n = 0;     else       n = c -  0 ;     for (c = getchar(); c >=  0  && c <=  9 ; c = getchar()) n = n * 10 + c -  0 ;     n *= flag;   }   int v[100][100], d[100][100];   char str[10000];   int n;   void p0() {     for (int j = 1; j <= 4; j += 3)       for (int i = 1; i <= 4; i += 2)         if (!v[i][j] && !v[i + 1][j]) {           v[i][j] = v[i + 1][j] = 1;           printf( %d %d n , i, j);           return;         }     assert(0);   }   void p1() {     for (int i = 1; i <= 4; i++)       if (!v[i][2] && !v[i][3]) {         v[i][2] = v[i][3] = 1;         printf( %d %d n , i, 2);         return;       }     assert(0);   }   int main(int argc, char *argv[]) {     scanf( %s , str);     n = strlen(str);     for (int i = (0); i < (n); ++i) {       if (str[i] ==  0 ) {         p0();       } else {         p1();       }       for (int x = (1); x <= (4); ++x)         for (int y = (1); y <= (4); ++y) {           d[x][y] = false;           bool ok = true;           for (int z = (1); z <= (4); ++z)             if (!v[x][z]) ok = false;           if (ok) d[x][y] = true;           ok = true;           for (int z = (1); z <= (4); ++z)             if (!v[z][y]) ok = false;           if (ok) d[x][y] = true;         }       for (int x = (1); x <= (4); ++x)         for (int y = (1); y <= (4); ++y)           if (d[x][y]) v[x][y] = 0;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string s;   int main() {     cin >> s;     s =     + s;     int dem = 0;     for (int i = 1; i <= s.size() - 1; i++) {       if (s[i] < 97 && (s[i] -  0 ) % 2 != 0)         dem++;       else if (s[i] ==  a  || s[i] ==  e  || s[i] ==  i  || s[i] ==  o  ||                s[i] ==  u )         dem++;     }     cout << dem;   }


#include <bits/stdc++.h>   using namespace std;   long long n, m, i, j, k, l;   long long p[10004], ans;   int main() {     cin >> n >> m >> k;     for (int i_ = 0; i_ < n; ++i_) cin >> p[i_];     ;     ans = 0;     if (n & 1) {       if (m >= n / 2 + 1) {         int mn = 2e9;         for (i = 0; i < n; i += 2) mn = ((mn) < (p[i]) ? (mn) : (p[i]));         l = m / (n / 2 + 1);         ans = ((mn) < (l * k) ? (mn) : (l * k));       }     }     cout << ans << endl;     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1001010;   int a[maxn];   void solve() {     int n;     cin >> n;     for (int i = 0; i < n; ++i) {       cin >> a[i];     }     int cnt = 0;     for (int i = 0; i < n and a[i] >= i; ++i, ++cnt) {     }     for (int i = n - 1; i >= 0 and a[i] >= n - 1 - i; --i, ++cnt) {     }     cout << (cnt > n ?  Yes  :  No ) << endl;   }   int main() {     int t;     cin >> t;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   int mark[201000 << 2];   int A[201000], n, m;   struct ST {     int val[2], las, len;     void update(ST a, ST b) {       b.val[1] -= a.las;       b.val[0] += a.las;       if (b.len & 1)         b.las -= a.las;       else         b.las += a.las;       val[0] = min(a.val[0], b.val[a.len & 1]);       val[1] = min(a.val[1], b.val[(a.len & 1) ^ 1]);       las = b.las;       len = a.len + b.len;       return;     }   } node[201000 << 2];   void build(int u, int L, int R) {     if (L == R) {       node[u].val[0] = 0;       node[u].val[1] = node[u].las = A[L];       node[u].len = 1;       return;     }     build((u << 1), L, ((L + R) >> 1));     build(((u << 1) | 1), (((L + R) >> 1) + 1), R);     node[u].update(node[(u << 1)], node[((u << 1) | 1)]);   }   void down(int u, int L, int R) {     if (!mark[u]) return;     node[u].val[1] += mark[u];     if (node[u].len & 1) node[u].las += mark[u];     if (L < R) mark[(u << 1)] += mark[u], mark[((u << 1) | 1)] += mark[u];     mark[u] = 0;     return;   }   void change(int u, int L, int R, int l, int r, int k) {     down(u, L, R);     if (L == l && R == r) {       mark[u] += k;       down(u, L, R);       return;     }     if (r < (((L + R) >> 1) + 1))       down(((u << 1) | 1), (((L + R) >> 1) + 1), R),           change((u << 1), L, ((L + R) >> 1), l, r, k);     else if (l > ((L + R) >> 1))       down((u << 1), L, ((L + R) >> 1)),           change(((u << 1) | 1), (((L + R) >> 1) + 1), R, l, r, k);     else {       change((u << 1), L, ((L + R) >> 1), l, ((L + R) >> 1), k);       change(((u << 1) | 1), (((L + R) >> 1) + 1), R, (((L + R) >> 1) + 1), r, k);     }     node[u].update(node[(u << 1)], node[((u << 1) | 1)]);   }   ST query(int u, int L, int R, int l, int r) {     down(u, L, R);     if (L == l && R == r) return node[u];     if (r < (((L + R) >> 1) + 1))       return query((u << 1), L, ((L + R) >> 1), l, r);     else if (l > ((L + R) >> 1))       return query(((u << 1) | 1), (((L + R) >> 1) + 1), R, l, r);     else {       ST a = query((u << 1), L, ((L + R) >> 1), l, ((L + R) >> 1));       ST b =           query(((u << 1) | 1), (((L + R) >> 1) + 1), R, (((L + R) >> 1) + 1), r);       a.update(a, b);       return a;     }   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &A[i]);     build(1, 1, n);     for (scanf( %d , &m); m; m--) {       int t, L, R, k;       scanf( %d %d %d , &t, &L, &R);       L++, R++;       if (t == 1) {         scanf( %d , &k);         change(1, 1, n, L, R, k);       } else {         ST ans = query(1, 1, n, L, R);         if (ans.val[0] >= 0 && ans.val[1] >= 1 && ans.las - (ans.len & 1) == 0)           printf( 1 n );         else           printf( 0 n );       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, a[101];     bool f = 1;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];       if (a[i] == 1) f = 0;     }     if (f)       puts( EASY );     else       puts( HARD );   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 7;   const int inf = INT_MAX;   const long long inff = 1e18;   const long long mod = 1e9 + 7;   long long n, p, k;   long long a[maxn];   set<long long> s;   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> p >> k;     for (long long i = 1; i <= n; i++) {       cin >> a[i];       long long now = a[i];       a[i] = a[i] * a[i] % p * a[i] % p * a[i] % p;       a[i] = (a[i] + p - k * now % p) % p;       s.insert(a[i]);     }     sort(a + 1, a + n + 1);     long long ans = 0;     for (long long i : s) {       long long now =           upper_bound(a + 1, a + n + 1, i) - lower_bound(a + 1, a + n + 1, i);       ans = (ans + now * (now - 1) / 2);     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   long long mod = 1000 * 1000 * 1000 + 7;   struct suffix_array {     vector<int> sa;     vector<int> lcp;     vector<vector<int>> st;     vector<int> log2;     vector<int> c;     string str;     int n;     void sort_pairs(vector<pair<pair<int, int>, int>>& a) {       vector<int> beg(n + 20);       for (int i = 0; i < n; i++) {         beg[a[i].first.second + 1]++;       }       for (int i = 0; i < beg.size() - 1; i++) {         beg[i + 1] += beg[i];       }       vector<pair<pair<int, int>, int>> sorted(n);       for (int i = 0; i < n; i++) {         sorted[beg[a[i].first.second]] = a[i];         beg[a[i].first.second]++;       }       beg.assign(beg.size(), 0);       for (int i = 0; i < n; i++) {         beg[sorted[i].first.first + 1]++;       }       for (int i = 0; i < beg.size() - 1; i++) {         beg[i + 1] += beg[i];       }       for (int i = 0; i < n; i++) {         a[beg[sorted[i].first.first]] = sorted[i];         beg[sorted[i].first.first]++;       }     }     suffix_array(string s) {       s +=  $ ;       n = s.length();       str = s;       c.assign(n, 0);       for (int i = 0; i < n; i++) {         if (s[i] >=  0  && s[i] <=  9 ) {           c[i] = (int)(s[i] -  0  + 1);         } else {           c[i] = 0;         }       }       vector<pair<pair<int, int>, int>> pairs(n);       for (int j = 0; (1 << (j - 1)) < n; j++) {         for (int i = 0; i < n; i++) {           pairs[i] = {{c[i], c[(i + (1 << j)) % n]}, i};         }         sort_pairs(pairs);         int cc = 0;         c[pairs[0].second] = cc;         for (int i = 1; i < n; i++) {           if (pairs[i].first != pairs[i - 1].first) cc++;           c[pairs[i].second] = cc;         }       }       sa.assign(n, 0);       for (int i = 0; i < n; i++) {         sa[c[i]] = i;       }       lcp.assign(n, 0);       int k = 0;       for (int i = 0; i < n; i++) {         int a = i;         if (c[i] == n - 1) {           k = 0;           continue;         }         int b = sa[c[i] + 1];         if (k > 0) k--;         while (max(a + k, b + k) < n && s[a + k] == s[b + k]) {           k++;         }         lcp[c[i]] = k;       }       log2.assign(n + 1, 0);       log2[1] = 0;       for (int i = 2; i <= n; i++) {         log2[i] = log2[i / 2] + 1;       }       st.assign(log2[n] + 1, vector<int>(n));       for (int i = 0; i < n; i++) {         st[0][i] = lcp[i];       }       for (int j = 1; j < st.size(); j++) {         for (int i = 0; i + (1 << j) <= n; i++) {           st[j][i] = min(st[j - 1][i], st[j - 1][i + (1 << (j - 1))]);         }       }     }     int compare(int i, int len_i, int j, int len_j) {       if (i == j && len_i == len_j) return 0;       int pos_i = i;       int pos_j = j;       i = c[i];       j = c[j];       if (i > j) swap(i, j);       j--;       int l = log2[j - i + 1];       int lcp_ans = min(st[l][i], st[l][j - (1 << l) + 1]);       int len = min(len_i, len_j);       lcp_ans = min(lcp_ans, len);       if (lcp_ans == len) {         if (len_i == len_j) {           return 0;         } else if (len_i > len_j) {           return 1;         } else {           return -1;         }       } else if (str[pos_i + lcp_ans] > str[pos_j + lcp_ans]) {         return 1;       } else {         return -1;       }     }   };   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     string s;     cin >> s;     suffix_array sa(s);     vector<vector<int>> dp(n + 1, vector<int>(n + 1));     vector<vector<int>> sums(n + 1, vector<int>(n + 1));     dp[0][0] = 1;     dp[1][1] = 1;     sums[0].assign(n + 1, 1);     for (int i = 1; i <= n; i++) {       sums[1][i] = 1;     }     for (int i = 2; i <= n; i++) {       for (int j = 1; j <= i; j++) {         if (s[i - j] ==  0 ) {           dp[i][j] = 0;           sums[i][j] = sums[i][j - 1];           continue;         }         if (j <= i - j && sa.compare(i - j, j, i - j - j, j) > 0) {           dp[i][j] += dp[i - j][j];           dp[i][j] %= mod;         }         dp[i][j] += sums[i - j][j - 1];         dp[i][j] %= mod;       }       for (int j = 1; j <= n; j++) {         sums[i][j] = sums[i][j - 1] + dp[i][j];         sums[i][j] %= mod;       }     }     long long ans = 0;     for (int i = 0; i <= n; i++) {       ans += dp[n][i];       ans %= mod;     }     cout << ans;   }


#include <bits/stdc++.h>   typedef struct {     int dollar;     int cent;   } money;   money q[110];   int w[110];   int main() {     int i, j, n, m, k = 0, l = 0;     scanf( %d%d , &n, &m);     for (i = 1; i <= n; i++) scanf( %d%d , &q[i].dollar, &q[i].cent);     for (i = 1; i <= n; i++) {       if (q[i].dollar < m || (q[i].dollar == m && q[i].cent == 0)) {         if (!k) k = 1;         if (q[i].cent == 0)           continue;         else           l = (l > 100 - q[i].cent) ? l : 100 - q[i].cent;       }     }     if (!k)       printf( -1 n );     else       printf( %d n , l);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 10;   int a[maxn];   set<int> S;   long long qpow(long long a, long long b, long long mod) {     long long ret = 1LL;     while (b) {       if (b & 1) ret = ret * a % mod;       a = a * a % mod;       b >>= 1;     }     return ret;   }   long long inv(long long x, long long mod) { return qpow(x, mod - 2, mod); }   int main(void) {     int n, m;     scanf( %d %d , &m, &n);     if (n + n < m) {       for (int i = 1; i <= n; i++) scanf( %d , a + i), S.insert(a[i]);       if (n == 1) {         printf( %d 0 n , a[1]);         return 0;       }       int kd = (a[2] - a[1] + m) % m;       int cnt = 0;       for (int i = 1; i <= n; i++) {         int nxt = (a[i] + kd) % m;         if (S.find(nxt) != S.end()) cnt++;       }       int k = n - cnt;       if (!k) {         printf( %d %d n , a[1], kd);         return 0;       }       int d = (long long)kd * inv(k, m) % m;       cnt = 0;       for (int i = 0; i < n; i++)         if (S.find((a[1] - (long long)i * d % m + m) % m) != S.end()) cnt++;       if (cnt == n) {         printf( %I64d %d n , (a[1] - (long long)(n - 1) * d % m + m) % m, d);         return 0;       }       for (int i = 1; i < n; i++) {         if (S.find((a[1] + (long long)(i - n) * d % m + m) % m) != S.end()) cnt--;         if (S.find((a[1] + (long long)i * d % m + m) % m) != S.end()) cnt++;         if (cnt == n) {           printf( %I64d %d n , (a[1] + (long long)(i - n + 1) * d % m + m) % m,                  d);           return 0;         }       }       puts( -1 );     } else {       for (int i = 0; i < m; i++) S.insert(i);       for (int i = 1; i <= n; i++) scanf( %d , a + i), S.erase(a[i]);       n = m - n;       set<int>::iterator it = S.begin();       for (int i = 1; i <= n; i++) a[i] = *(it++);       if (n == 0) {         printf( 0 1 n );         return 0;       }       if (n == 1) {         printf( %d 1 n , (a[1] + n) % m);         return 0;       }       int kd = (a[2] - a[1] + m) % m;       int cnt = 0;       for (int i = 1; i <= n; i++) {         int nxt = (a[i] + kd) % m;         if (S.find(nxt) != S.end()) cnt++;       }       int k = n - cnt;       if (!k) {         printf( %d %d n , (a[1] + (long long)n * kd) % m, kd);         return 0;       }       int d = (long long)kd * inv(k, m) % m;       cnt = 0;       for (int i = 0; i < n; i++)         if (S.find((a[1] - (long long)i * d % m + m) % m) != S.end()) cnt++;       if (cnt == n) {         printf( %I64d %d n ,                (a[1] - (long long)(n - 1) * d % m + m + (long long)n * d) % m, d);         return 0;       }       for (int i = 1; i < n; i++) {         if (S.find((a[1] + (long long)(i - n) * d % m + m) % m) != S.end()) cnt--;         if (S.find((a[1] + (long long)i * d % m + m) % m) != S.end()) cnt++;         if (cnt == n) {           printf(                %I64d %d n ,               (a[1] + (long long)(i - n + 1) * d % m + m + (long long)n * d) % m,               d);           return 0;         }       }       puts( -1 );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int x, y, z;     cin >> x >> y >> z;     int t = x * y / z;     t = (int)sqrt(t);     x = x / t;     z = y / t;     y = t;     cout << 4 * x + 4 * z + 4 * y <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e17;   const long long MOD = 1000000007;   const long long MAX = 4000001;   const long double eps = 1E-14;   long long max(long long a, long long b) {     if (a > b) {       return a;     }     return b;   }   long long min(long long a, long long b) {     if (a > b) {       return b;     }     return a;   }   long long gcd(long long a, long long b) {     if (b == 0) {       return a;     }     if (a < b) {       return gcd(b, a);     }     return gcd(b, a % b);   }   long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }   struct edge {     long long ind;     long long fr;     long long to;     long long d;   };   class mint {     long long x;       public:     mint(long long x = 0) : x((x % MOD + MOD) % MOD) {}     mint operator-() const { return mint(-x); }     mint& operator+=(const mint& a) {       if ((x += a.x) >= MOD) x -= MOD;       return *this;     }     mint& operator-=(const mint& a) {       if ((x += MOD - a.x) >= MOD) x -= MOD;       return *this;     }     mint& operator*=(const mint& a) {       (x *= a.x) %= MOD;       return *this;     }     mint operator+(const mint& a) const {       mint res(*this);       return res += a;     }     mint operator-(const mint& a) const {       mint res(*this);       return res -= a;     }     mint operator*(const mint& a) const {       mint res(*this);       return res *= a;     }     mint pow(long long t) const {       if (!t) return 1;       mint a = pow(t >> 1);       a *= a;       if (t & 1) a *= *this;       return a;     }     mint inv() const { return pow(MOD - 2); }     mint& operator/=(const mint& a) { return (*this) *= a.inv(); }     mint operator/(const mint& a) const {       mint res(*this);       return res /= a;     }     friend ostream& operator<<(ostream& os, const mint& m) {       os << m.x;       return os;     }   };   mint pw(mint a, long long b) {     if (b == 0) {       return 1;     }     mint ret = pw(a, b >> 1);     ret *= ret;     if (b & 1) {       ret *= a;     }     return ret;   }   int main() {     long long T;     cin >> T;     for (long long t = 1; t <= T; t++) {       long long N;       cin >> N;       vector<long long> a(N + 1);       for (long long i = 1; i <= N; i++) cin >> a[i];       long long S = 0;       for (long long i = 1; i <= N; i++) S += a[i];       if (S % N != 0) {         cout << -1 << endl;       } else {         S = S / N;         vector<pair<long long, long long>> rem;         for (long long i = 2; i <= N; i++) {           long long x = 0;           if (a[i] % i != 0) {             x = i - a[i] % i;           }           rem.push_back({x, i});         }         sort(rem.begin(), rem.end());         vector<pair<pair<long long, long long>, long long>> ans;         for (long long k = 0; k < N - 1; k++) {           auto p = rem[k];           if (p.first > a[1]) {             break;           }           ans.push_back({{1, p.second}, p.first});           a[1] -= p.first;           a[p.second] += p.first;           ans.push_back({{p.second, 1}, a[p.second] / p.second});           a[1] += a[p.second];           a[p.second] = 0;         }         for (long long i = 2; i <= N; i++) {           if (a[i] == 0) {             continue;           }           ans.push_back({{i, 1}, a[i] / i});           a[1] += a[i] / i * i;           a[i] %= i;         }         bool b = 1;         for (long long i = 2; i <= N; i++) {           if (a[i] > S) {             cout << -1 << endl;             b = 0;             break;           }           ans.push_back({{1, i}, S - a[i]});         }         if (b) {           cout << ans.size() << endl;           for (auto p : ans) {             cout << p.first.first <<     << p.first.second <<     << p.second                  << endl;           }         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     map<char, long long> mp1, mp2;     mp1[ v ] = 1;     mp1[ < ] = 2;     mp1[ ^ ] = 3;     mp1[ > ] = 4;     mp2[ v ] = 1;     mp2[ > ] = 2;     mp2[ ^ ] = 3;     mp2[ < ] = 4;     char a, b;     long long n;     cin >> a >> b;     cin >> n;     n = n % 4;     long long one, two;     one = (mp1[a] + n) % 4;     if (one == 0) one = 4;     two = (mp2[a] + n) % 4;     if (two == 0) two = 4;     long long f1 = 0, f2 = 0;     if (one == mp1[b]) f1 = 1;     if (two == mp2[b]) f2 = 1;     if (f1 == 1 && f2 == 0) {       cout <<  cw  << endl;       return 0;     } else if (f1 == 0 && f2 == 1) {       cout <<  ccw  << endl;       return 0;     }     cout <<  undefined  << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX = 2e5 + 10;   int inf = (int)3e15;   int mod = (int)1e9 + 7;   int sz = 500, timer = 0;   vector<int> gr[MAX];   int n, q, odd[MAX], even[MAX], h[MAX], tin[MAX], tout[MAX], mus[MAX], o[MAX];   vector<pair<int, int>> tmp;   void calc(int v, int p) {     tin[v] = ++timer;     h[v] = h[p] + 1;     for (auto u : gr[v]) {       if (u != p) calc(u, v);     }     tout[v] = ++timer;   }   void dfs_rebuild(int v, int p) {     odd[v] += even[p];     even[v] += odd[p];     for (auto u : gr[v]) {       if (u != p) dfs_rebuild(u, v);     }   }   void rebuild() {     for (int i = 1; i <= n; i++) {       even[i] = 0;       odd[i] = 0;     }     for (int i = 0; i < tmp.size(); i++) mus[tmp[i].first] += tmp[i].second;     for (int i = 1; i <= n; i++) even[i] = mus[i];     tmp.clear();     dfs_rebuild(1, 0);   }   void out_val(int v) {     int ans = even[v] - odd[v] + o[v];     for (int i = 0; i < tmp.size(); i++) {       int u = tmp[i].first;       int val = tmp[i].second;       if (tin[u] <= tin[v] && tout[u] >= tout[v]) {         if ((h[v] - h[u]) % 2 == 1)           ans -= val;         else           ans += val;       }     }     cout << ans <<   n ;   }   void solve() {     cin >> n >> q;     for (int i = 1; i <= n; i++) {       cin >> o[i];     }     for (int i = 0; i < n - 1; i++) {       int a, b;       cin >> a >> b;       gr[a].push_back(b);       gr[b].push_back(a);     }     calc(1, 0);     for (int i = 0; i < q; i++) {       int a;       cin >> a;       if (a == 1) {         int b, c;         cin >> b >> c;         tmp.push_back({b, c});         if (tmp.size() == 2000) rebuild();       } else {         int c;         cin >> c;         out_val(c);       }     }   }   int main() {     ios::sync_with_stdio(0);     int q;     q = 1;     while (q--) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T1, typename T2>   istream &operator>>(istream &is, vector<pair<T1, T2>> &v) {     for (pair<T1, T2> &t : v) is >> t.first >> t.second;     return is;   }   template <typename T>   istream &operator>>(istream &is, vector<T> &v) {     for (T &t : v) is >> t;     return is;   }   template <typename T>   ostream &operator<<(ostream &os, const vector<T> &v) {     for (const T &t : v) {       os << t <<    ;     }     os <<   n ;     return os;   }   double pi = acos(-1.0);   long long md = 1000000007;   long long abst(long long a) { return a < 0 ? -a : a; }   struct HASH {     size_t operator()(const pair<long long, long long> &x) const {       return (size_t)x.first * 37U + (size_t)x.second;     }   };   struct custom_hash {     static uint64_t splitmix64(uint64_t x) {       x += 0x9e3779b97f4a7c15;       x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;       x = (x ^ (x >> 27)) * 0x94d049bb133111eb;       return x ^ (x >> 31);     }     size_t operator()(uint64_t x) const {       static const uint64_t FIXED_RANDOM =           chrono::steady_clock::now().time_since_epoch().count();       return splitmix64(x + FIXED_RANDOM);     }   };   long long Pow(long long n, long long x) {     long long ans = 1;     while (x > 0) {       if (x & 1) ans = (ans * n) % md;       n = (n * n) % md;       x = x >> 1;     }     return ans;   }   vector<long long> fact, inv;   void inverse(long long n) {     inv.resize(n + 1);     inv[0] = 1;     for (long long i = 1; i <= n; i++) inv[i] = Pow(fact[i], md - 2);   }   void factorial(long long n) {     fact.resize(n + 1);     fact[0] = 1;     for (long long i = 1; i <= n; i++) fact[i] = (fact[i - 1] * i) % md;   }   long long max(long long a, long long b) { return a > b ? a : b; }   long long min(long long a, long long b) { return a < b ? a : b; }   void solve() {     long long n;     cin >> n;     vector<long long> v(n);     cin >> v;     vector<long long> ans(2 * n);     vector<long long> vis(2 * n + 1, -1);     for (long long i = 0; i < n; i++) {       ans[2 * i] = v[i];       vis[v[i]] = 1;     }     long long ptr;     for (long long i = 1; i < 2 * n; i += 2) {       ptr = -1;       for (long long j = 1; j <= 2 * n; j++)         if (vis[j] == -1 && j > ans[i - 1]) {           ptr = j;           break;         }       if (ptr == -1) {         cout << -1 <<   n ;         return;       }       ans[i] = ptr;       vis[ptr] = 1;     }     cout << ans;   }   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     long long t = 1;     cin >> t;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long int;   const int N = 2e5 + 10;   int n, k, a[N], b[N], idx[N], kp = -1;   char lc =  a  - 1, res[N];   int main() {     ios_base::sync_with_stdio(false), cout.tie(nullptr), cin.tie(nullptr);     cin >> n >> k;     for (int i = 0; i < n; i++) {       cin >> a[i];       idx[a[i]] = i;     }     for (int i = 0; i < n; i++) {       cin >> b[i];     }     for (int i = 0; i < n; i++) {       if (kp < i && k > 0) {         lc++;         k--;       }       res[b[i]] = lc;       kp = max(kp, idx[b[i]]);     }     if (k == 0) {       cout <<  YES n  << (res + 1);     } else {       cout <<  NO n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int k, n, root, par[100005];   vector<int> v[100005];   bool vis[100005], fr;   void findroot(int u, int l) {     int i;     if (v[u].size() == 1 && l == 2 * k) {       fr = true;       root = u;     }     for (i = 0; i < v[u].size(); i++) {       if (fr) break;       if (!vis[v[u][i]]) {         vis[v[u][i]] = true;         par[v[u][i]] = u;         findroot(v[u][i], l + 1);       }     }   }   void dfs(int u, int l) {     int i;     if (v[u].size() == 1 && l != k) fr = true;     if (u != root && l != k && v[u].size() < 4) fr = true;     for (i = 0; i < v[u].size(); i++) {       if (fr) break;       if (!vis[v[u][i]]) {         vis[v[u][i]] = true;         dfs(v[u][i], l + 1);       }     }   }   int main() {     int i, x, y, leaf, cnt = 0;     cin >> n >> k;     for (i = 0; i < n - 1; i++) {       cin >> x >> y;       v[x].push_back(y);       v[y].push_back(x);     }     if (n == 1) {       cout <<  No n ;       return 0;     }     for (i = 1; i <= n; i++)       if (v[i].size() == 1) {         leaf = i;         break;       }     memset(vis, false, sizeof(vis));     vis[leaf] = true;     fr = false;     findroot(leaf, 0);     if (!fr) {       cout <<  No n ;       return 0;     }     while (cnt != k) {       root = par[root];       cnt++;     }     if (v[root].size() < 3) {       cout <<  No n ;       return 0;     }     memset(vis, false, sizeof(vis));     vis[root] = true;     fr = false;     dfs(root, 0);     if (fr) {       cout <<  No n ;     } else       cout <<  Yes n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct T {     int lz, sz;     int v[2], t[2], f1[2], f2[2];     T(int x = 1) {       lz = 0, sz = x;       for (int i = 0; i < 2; i++) {         v[i] = f1[i] = x;         t[i] = f2[i] = 0;       }     }     void upd() {       for (int i = 0; i < 2; i++) t[i] ^= 1;       swap(v[0], v[1]);       lz ^= 1;     }     friend T operator+(T l, T r) {       T ret(0);       T c[2] = {l, r};       int first = 0, g = 0;       for (int i = 0; i < 2; i++) ret.v[i] = 0;       for (int i = 0; i < 2; i++) {         first += c[i].f1[!i];         g ^= c[i].t[!i];         ret.sz += c[i].sz;         ret.t[i] = c[i].t[i];         if (c[i].f1[i] == c[i].sz) {           if (c[i].t[i] == c[!i].t[i]) {             ret.f1[i] = c[i].f1[i] + c[!i].f1[i];             ret.f2[i] = c[!i].f2[i];           } else {             ret.f1[i] = c[i].f1[i];             ret.f2[i] = c[!i].f1[i];           }         } else {           ret.f1[i] = c[i].f1[i];           ret.f2[i] = c[i].f2[i];           ret.f2[i] +=               (ret.f1[i] + ret.f2[i] == c[i].sz && c[i].t[i] != c[!i].t[i]) *               c[!i].f1[i];         }         for (int j = 0; j < 2; j++)           ret.v[j] = max({ret.v[j], ret.f1[i], ret.f2[i], c[i].v[j]});       }       if (g) {         ret.v[c[0].t[1]] = max(ret.v[c[0].t[1]], first);       } else {         for (int i = 0; i < 2; i++) {           int j = !i ^ c[i].t[!i];           ret.v[j] = max(ret.v[j], first + c[i].f2[!i]);         }       }       return ret;     }   };   struct segTree {     int l, r;     segTree *c[2];     T val;     segTree(int a, int b) {       l = a, r = b;       val.sz = r - l + 1;       if (l != r) {         int mid = (l + r) / 2;         c[0] = new segTree(l, mid);         c[1] = new segTree(mid + 1, r);         val = c[0]->val + c[1]->val;       }     }     T add(int a, int b) {       if (b < l || r < a) return T(0);       if (a <= l && r <= b) {         val.upd();         return val;       }       T ret[2];       for (int i = 0; i < 2; i++) {         if (val.lz) c[i]->val.upd();         ret[i] = c[i]->add(a, b);       }       val = c[0]->val + c[1]->val;       return ret[0] + ret[1];     }   };   const int mxn = 500000;   int n, q;   segTree tre(1, mxn);   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n >> q;     for (int i = 1; i <= n; i++) {       char c;       cin >> c;       if (c ==  < ) tre.add(i, i);     }     while (q--) {       int l, r;       cin >> l >> r;       cout << tre.add(l, r).v[0] <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int N, M, Q, Sum, op[100005], X[100005], Y[100005], Ans[100005], Mp[1005][1005],       Lh[1005], Ln[1005];   int lnk[100005], nxt[100005], son[100005], tot;   bool vis[100005], Num[1005];   inline int read() {     int N = 0;     char ch = getchar();     while (ch >  9  || ch <  0 ) ch = getchar();     while (ch >=  0  && ch <=  9 ) N = N * 10 + ch -  0 , ch = getchar();     return N;   }   inline void add(int x, int y) {     son[++tot] = y;     nxt[tot] = lnk[x];     lnk[x] = tot;   }   inline void fz(int x) {     Sum += Ln[X[x]] - Lh[X[x]];     Num[X[x]] ^= 1;     swap(Ln[X[x]], Lh[X[x]]);   }   inline void work(int x) {     if (op[x] == 1 && !(Mp[X[x]][Y[x]] ^ Num[X[x]]))       Mp[X[x]][Y[x]] ^= 1, Lh[X[x]]++, Ln[X[x]]--, Sum++, vis[x] = 1;     if (op[x] == 2 && Mp[X[x]][Y[x]] ^ Num[X[x]])       Mp[X[x]][Y[x]] ^= 1, Lh[X[x]]--, Ln[X[x]]++, Sum--, vis[x] = 1;     if (op[x] == 3) fz(x);   }   inline void rework(int x) {     if (op[x] == 1 && vis[x]) Mp[X[x]][Y[x]] ^= 1, Lh[X[x]]--, Ln[X[x]]++, Sum--;     if (op[x] == 2 && vis[x]) Mp[X[x]][Y[x]] ^= 1, Lh[X[x]]++, Ln[X[x]]--, Sum++;     if (op[x] == 3) fz(x);   }   void DFS(int x) {     work(x);     Ans[x] = Sum;     for (int i = lnk[x]; i; i = nxt[i]) DFS(son[i]);     rework(x);   }   int main() {     N = read();     M = read();     Q = read();     for (int i = 1; i <= Q; i++) {       op[i] = read();       X[i] = read();       if (op[i] <= 2) Y[i] = read();       if (op[i] == 4)         add(X[i], i);       else         add(i - 1, i);     }     for (int i = 1; i <= N; i++) Ln[i] = M;     DFS(0);     for (int i = 1; i <= Q; i++) printf( %d n , Ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int K;   long long p[21], a[21], aLeft[21];   long long N, Nq3;   long long minArea = 3000000000000000000LL;   long long ansA, ansB, ansC;   long long curA;   long long leftMul[21];   long long BCq, BC, nowBest;   void dfs2(int cur, long long carry) {     if (carry * leftMul[cur] < BCq) return;     if (carry > nowBest) return;     if (carry >= BCq) {       nowBest = carry;       return;     }     if (cur == K + 1) return;     dfs2(cur + 1, carry);     for (int i = 1; i <= aLeft[cur]; i++) {       carry *= p[cur];       dfs2(cur + 1, carry);     }   }   void calc(long long _curA) {     nowBest = 3000000000000000000LL;     curA = _curA;     BC = N / curA;     double each = sqrt(double(BC));     if (curA * 2 * each + BC > minArea + 10) return;     leftMul[K + 1] = 1;     for (int i = K; i >= 1; i--) {       leftMul[i] = leftMul[i + 1];       for (int j = 1; j <= aLeft[i]; j++) leftMul[i] *= p[i];     }     BCq = sqrt(double(BC - 1));     while (BCq * BCq < BC) BCq++;     dfs2(1, 1);     long long curB = nowBest, curC = BC / curB;     if (curA * (curB + curC) + BC < minArea) {       minArea = curA * (curB + curC) + BC;       ansA = curA;       ansB = curB;       ansC = curC;     }   }   void dfs(int cur, long long carry) {     if (cur == K + 1)       calc(carry);     else {       aLeft[cur] = a[cur];       dfs(cur + 1, carry);       for (int i = 1; i <= a[cur]; i++) {         carry *= p[cur];         if (carry > Nq3) return;         aLeft[cur] = a[cur] - i;         dfs(cur + 1, carry);       }     }   }   void solve() {     minArea = 3000000000000000000LL;     for (int iteration = 1; iteration <= K; iteration++)       for (int i = 1; i < K; i++)         if (p[i] < p[i + 1]) {           swap(p[i], p[i + 1]);           swap(a[i], a[i + 1]);         }     N = 1;     for (int i = 1; i <= K; i++)       for (int j = 1; j <= a[i]; j++) N *= p[i];     Nq3 = pow(double(N - 1), 1 / 3.0);     while (Nq3 * Nq3 * Nq3 < N) Nq3++;     dfs(1, 1);     cout << 2 * minArea <<     << ansA <<     << ansB <<     << ansC << endl;   }   int main() {     ios ::sync_with_stdio(false);     int TestCase;     cin >> TestCase;     for (int CaseID = 1; CaseID <= TestCase; CaseID++) {       cin >> K;       for (int i = 1; i <= K; i++) cin >> p[i] >> a[i];       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<pair<int, string> > vc[100010];   vector<string> vc1[100010];   bool comp(pair<int, string> a, pair<int, string> b) {     return a.first > b.first;   }   int main() {     int n, m;     cin >> n >> m;     for (int i = 0; i < n; i++) {       string s;       int a, b;       cin >> s >> a >> b;       vc[a].push_back(make_pair(b, s));     }     for (int i = 1; i <= m; i++) {       sort(vc[i].begin(), vc[i].end(), comp);     }     for (int i = 1; i <= m; i++) {       if (vc[i].size() == 2) {         for (int j = 0; j < vc[i].size(); j++) {           vc1[i].push_back(vc[i][j].second);         }       } else if (vc[i].size() == 1) {         for (int j = 0; j < vc[i].size(); j++) {           vc1[i].push_back(vc[i][j].second);         }       } else if (vc[i].size() > 2) {         if (vc[i][1].first == vc[i][2].first) {           vc1[i].push_back( ? );         } else {           for (int j = 0; j < 2; j++) {             vc1[i].push_back(vc[i][j].second);           }         }       }     }     for (int i = 1; i <= m; i++) {       for (int j = 0; j < vc1[i].size(); j++) {         cout << vc1[i][j];         if (j < vc1[i].size() - 1) cout <<    ;       }       cout << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const long long int maxn = 1e6 + 1;   const long long int modn = 1e9 + 7;   long long int T, len, num, gav, ver, x, maxi, sum, fir, sec, out, th;   vector<long long int> vec[maxn];   bool is_use[maxn];   long long int all[maxn];   void dfs(long long int x) {     is_use[x] = true;     sum++;     for (int i = 0; i < vec[x].size(); i++) {       ver = vec[x][i];       if (is_use[ver] == false) dfs(ver);     }     return;   }   int main() {     std::ios_base::sync_with_stdio(false);     cin >> len >> num >> gav;     for (int i = 1; i <= gav; i++) cin >> all[i];     for (int i = 1; i <= num; i++) {       cin >> fir >> sec;       vec[fir].push_back(sec);       vec[sec].push_back(fir);     }     for (int i = 1; i <= gav; i++) {       sum = 0;       dfs(all[i]);       out += (sum * (sum - 1)) / 2;       maxi = max(maxi, sum);     }     sum = 0;     for (int i = 1; i <= len; i++) {       if (is_use[i] == false) sum++;     }     out += (sum * (sum - 1)) / 2 + sum * maxi;     cout << out - num;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, x = 0, y = 0;     cin >> n >> m;     x = max(m, n);     for (int a = 0; a <= x; a++) {       for (int b = 0; b <= x; b++) {         if ((a * a) + b == n && (b * b) + a == m) {           y++;         }       }     }     cout << y << endl;   }