#include <bits/stdc++.h>   using namespace std;   #pragma GCC optimize( Ofast )   #pragma GCC target( avx,avx2,fma )   bool iseven(long long int n) {     if ((n & 1) == 0) return true;     return false;   }   void print(long long int t) { cout << t; }   void print(int t) { cout << t; }   void print(string t) { cout << t; }   void print(char t) { cout << t; }   void print(double t) { cout << t; }   void print(long double t) { cout << t; }   template <class T, class V>   void print(pair<T, V> p);   template <class T>   void print(vector<T> v);   template <class T>   void print(set<T> v);   template <class T, class V>   void print(map<T, V> v);   template <class T>   void print(multiset<T> v);   template <class T, class V>   void print(pair<T, V> p) {     cout <<  { ;     print(p.first);     cout <<  , ;     print(p.second);     cout <<  } ;   }   template <class T>   void print(vector<T> v) {     cout <<  [  ;     for (T i : v) {       print(i);       cout <<    ;     }     cout <<  ] ;   }   template <class T>   void print(set<T> v) {     cout <<  [  ;     for (T i : v) {       print(i);       cout <<    ;     }     cout <<  ] ;   }   template <class T>   void print(multiset<T> v) {     cout <<  [  ;     for (T i : v) {       print(i);       cout <<    ;     }     cout <<  ] ;   }   template <class T, class V>   void print(map<T, V> v) {     cout <<  [  ;     for (auto i : v) {       print(i);       cout <<    ;     }     cout <<  ] ;   }   void solve() {     long long int n;     cin >> n;     string s;     cin >> s;     string original = s;     string ans =   ;     for (long long int i = 0; i < n; ++i) {       ans +=  9 ;     }     for (long long int i = 0; i < n; ++i) {       s = original;       long long int toincrease = 10 - (s[i] -  0 );       for (auto &ch : s) {         long long int temp = (ch -  0  + toincrease) % 10;         ch =  0  + temp;       }       string tempans =   ;       tempans += s[i];       long long int ptr = (i + 1) % n;       while (ptr != i) {         tempans += s[ptr];         ptr = (ptr + 1) % n;       }       ans = min(ans, tempans);     }     cout << ans <<   n ;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     solve();     return 0;   }


#include <bits/stdc++.h>   int SequenceValue(char seq[], int *min_val) {     int value = 0;     *min_val = 0;     char *it = seq;     while (*it !=   0  && *it !=   n ) {       value += (*it ==  ( ) ? 1 : -1;       if (value < *min_val) {         *min_val = value;       }       it += 1;     }     return value;   }   char seq[300000 + 5];   int starts[300000];   int ends[300000];   int main() {     int n;     scanf( %d%*c , &n);     long long int pairs = 0;     int i;     for (i = 0; i < n; ++i) {       fgets(seq, 300000 + 1, stdin);       int min_val;       int value = SequenceValue(seq, &min_val);       if (min_val < value && min_val < 0) {         continue;       }       if (value == 0) {         pairs += 1LL * 2 * starts[0] + 1;         starts[0] += 1;         continue;       }       if (value > 0) {         pairs += 1LL * ends[value];         starts[value] += 1;       } else {         pairs += 1LL * starts[-value];         ends[-value] += 1;       }     }     printf( %I64d n , pairs);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long i;     long long n, m, k, l;     cin >> n >> m >> k >> l;     long long no = 0;     long long yes = 0;     long long j = (l + k);     long long ans = ((j - 1) / m) + 1;     if (((ans * m)) > n) no = 1;     if (no)       cout <<  -1 ;     else       cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long MOD(long long, long long);   void doublesetprecision(double, int);   bool isEven(long long);   int gcd(int, int);   int n, m, o, ans, k;   int a[1000000];   void solve() {     string s, t;     cin >> s >> t;     if (s == t) {       cout <<  yes ;       return;     }     if (s.size() != t.size()) {       cout <<  no ;       return;     }     int hs[26] = {0}, ht[26] = {0};     for (long long i = 0; i < s.size(); i++) hs[s[i] -  a ]++;     for (long long i = 0; i < t.size(); i++) ht[t[i] -  a ]++;     for (long long i = 0; i < 26; i++) {       if (ht[i] > 0 && hs[i] > 0) {         cout <<  yes ;         return;       }     }     cout <<  no ;   }   int main() {     int t = 1;     scanf( %d , &t);     while (t--) {       solve();       cout <<   n ;     }     return 0;   }   bool isEven(long long n) {     if (n % 2 == 0) return 1;     return 0;   }   void doublesetprecision(double x, int p) {     cout << fixed << setprecision(p) << x;   }   long long MOD(long long x, long long M) {     x = x % M;     if (x < 0) x += M;     return x;   }   int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }


#include <bits/stdc++.h>   using namespace std;   vector<int> E[1 << 18];   pair<int, int> R[1 << 18];   int dfs(int a, int p, int d) {     int cnt = 1;     for (auto it = (E[a]).begin(); it != (E[a]).end(); ++it) {       int b = *it;       if (b == p) continue;       cnt += dfs(b, a, d + 1);     }     R[a] = pair<int, int>(cnt - 1 - d, a);     return cnt;   }   int main() {     int n, k;     cin >> n >> k;     int i;     for (i = (1); i < (n); ++i) {       int a, b;       cin >> a >> b;       --a;       --b;       E[a].push_back(b);       E[b].push_back(a);     }     dfs(0, -1, 0);     sort(R, R + n);     long long res = 0;     for (i = (k); i < (n); ++i) res += R[i].first;     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int NMAX = 1e5 + 2;   int n, last[NMAX], x, y;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> n;     for (int query = 1; query <= n; query++) {       cin >> x >> y;       int ans = 0, autre;       for (int d = 1; d * d <= x; d++) {         if (x % d == 0) {           autre = x / d;           if (last[d] < query - y || y == 0) {             ans++;           }           if ((last[autre] < query - y || y == 0) && autre != d) {             ans++;           }           last[d] = last[autre] = query;         }       }       cout << ans <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7, LIM = 1e5;   unsigned long long int fact[2 * LIM + 1];   unsigned long long int binpow(long long int x, int y) {     unsigned long long int res = 1;     while (y > 0) {       if (y & 1) res = (res * x) % MOD;       y >>= 1;       x = (x * x) % MOD;     }     return res;   }   unsigned long long int inv_mod(unsigned long long int n) {     return binpow(n, MOD - 2);   }   unsigned long long int com(int n, int r) {     return (((fact[n] * inv_mod(fact[r])) % MOD) * inv_mod(fact[n - r])) % MOD;   }   bool comp(pair<int, int> p, pair<int, int> q) {     if (p.first == q.first) return p.second < q.second;     return p.first < q.first;   }   int main() {     fact[0] = 1;     for (int i = 1; i <= 2 * LIM; i++) {       fact[i] = (i * fact[i - 1]) % MOD;     }     int h, w, n;     cin >> h >> w >> n;     vector<pair<int, int>> pts(n + 1);     for (int i = 0; i < n; i++) {       int r, c;       cin >> r >> c;       pts[i] = {r, c};     }     pts[n] = {h, w};     sort(pts.begin(), pts.end(), comp);     unsigned long long int dp[n + 1];     for (int i = 0; i <= n; i++) {       dp[i] = com(pts[i].first + pts[i].second - 2, pts[i].first - 1);       for (int j = 0; j < i; j++) {         if (pts[j].first <= pts[i].first && pts[j].second <= pts[i].second) {           dp[i] = (dp[i] + MOD -                    (dp[j] * com(pts[i].first - pts[j].first + pts[i].second -                                     pts[j].second,                                 pts[i].first - pts[j].first)) %                        MOD) %                   MOD;         }       }     }     cout << dp[n];   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 10;   int n;   int a[N];   int fa(int x) {     for (int i = 0;; i++)       if ((1 << i) >= x) return (1 << i) - x;   }   int dis(int x, int y) {     int sum = 0;     while (x != y) x > y ? x = fa(x) : y = fa(y), sum++;     return sum;   }   int get(int x) {     int mx = 0, id = 0;     for (int i = 1; i <= n; i++) {       int t = dis(a[x], a[i]);       if (t > mx) mx = t, id = i;     }     return id;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     int t1 = get(1), t2 = get(t1);     printf( %d %d %d , t1, t2, dis(a[t1], a[t2]));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, x;     cin >> n >> x;     int cnt = 0;     for (int j = 1; j * j <= x; j++) {       if (x % j == 0) {         if (j <= n && x / j <= n) {           if (j * j == x)             cnt++;           else             cnt += 2;         }       }     }     cout << cnt << endl;   }


#include <bits/stdc++.h>   void printResult() {}   int main(int argc, const char* argv[]) {     std::ios::sync_with_stdio(false);     int rows;     bool possible = false;     scanf( %d n , &rows);     std::shared_ptr<std::vector<char*>> bus =         std::make_shared<std::vector<char*>>();     if (rows > 0) {       for (auto i = 0; i < rows; i++) {         char* row = new char[4];         scanf( %c%c|%c%c n , &row[0], &row[1], &row[2], &row[3]);         bus->push_back(row);       }       for (auto row : *bus) {         if (row[0] == row[1] && row[0] ==  O ) {           possible = true;           row[0] =  + ;           row[1] =  + ;           break;         } else if (row[2] == row[3] && row[2] ==  O ) {           possible = true;           row[2] =  + ;           row[3] =  + ;           break;         }       }       if (possible == true) {         printf( YES n );         for (auto row : *bus) {           printf( %c%c|%c%c n , row[0], row[1], row[2], row[3]);         }       } else {         printf( NO n );       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     double d, h, v, e;     cin >> d >> h >> v >> e;     double pi = 2 * acos(0.0);     double he = (4 * v) / (pi * d * d);     if (he > e) {       cout <<  YES n ;       cout << setprecision(12) << (h) / (he - e);     } else       cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char s[1000010];   int c[20];   int main() {     int k;     scanf( %d , &k);     scanf( %s , s + 1);     int n = strlen(s + 1);     int sum = 0;     int i;     memset(c, 0, sizeof c);     int ans = 0;     for (i = 1; i <= n; i++) {       c[s[i] -  0 ]++;       sum += s[i] -  0 ;     }     sum = k - sum;     for (i = 0; i <= 9; i++)       while (sum > 0 && c[i]) {         sum -= 9 - i;         ans++;         c[i]--;       }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   const int maxn = 200011;   const int INF = 1 << 25;   const int logN = 18;   int n;   int a[maxn];   bool p[maxn];   int b[maxn];   bool used[maxn];   int main(int argc, char const *argv[]) {     scanf( %d , &(n));     for (int(i) = 0; i < (int)(n); ++(i)) scanf( %d , &(a[i]));     priority_queue<pair<int, int> > pq1, pq2;     for (int(i) = 0; i < (int)(n); ++(i))       pq1.push(make_pair((a[i] - (n - i)), (i)));     for (int i = n - 1; i >= 0; --i) {       while (!pq1.empty() && pq1.top().second > i) pq1.pop();       while (!pq1.empty() && used[pq1.top().second]) pq1.pop();       while (!pq2.empty() && used[pq2.top().second]) pq2.pop();       int id1 = -1, id2 = -1;       if (!pq1.empty()) id1 = pq1.top().second;       if (!pq2.empty()) id2 = pq2.top().second;       int pick;       if (id1 != -1 && id2 != -1) {         if (a[id1] - i + id1 > a[id2] - i + id2) {           pick = id1;           pq1.pop();         } else {           pick = id2;           pq2.pop();         }       } else if (id1 != -1) {         pick = id1;         pq1.pop();       } else {         pick = id2;         pq2.pop();       }       if (pick > i)         b[i] = a[pick] - i + pick;       else         b[i] = a[pick] - i + pick;       used[pick] = 1;       if (!used[i]) pq2.push(make_pair((a[i] + i), (i)));     }     bool f = 1;     for (int(i) = 0; i < (int)(n - 1); ++(i))       if (b[i] > b[i + 1]) f = 0;     if (f)       for (int(i) = 0; i < (int)(n); ++(i))         printf( %d%c , b[i], i == n - 1 ?   n  :    );     else       puts( :( );   }


#include <bits/stdc++.h>   int main() {     int n, s, i, sum = 0, max = 0;     scanf( %d %d , &n, &s);     int arr[n];     for (i = 0; i < n; i++) {       scanf( %d , &arr[i]);       sum = sum + arr[i];       if (arr[i] > max) max = arr[i];     }     if (sum - max > s)       printf( NO );     else       printf( YES );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 7;   int n, m, len, cnt1 = 0, cnt2 = 0, cnt3 = 0, fail[maxn];   long long ans = 0;   struct Node {     long long c;     char ch;   } s[maxn], str[maxn], _str[maxn];   bool ok(int i, int j) {     if (_str[i].c != _str[j].c) return false;     if (_str[i].ch != _str[j].ch) return false;     return true;   }   bool _ok(int i, int j) {     if (s[i].c != _str[j].c) return false;     if (s[i].ch != _str[j].ch) return false;     return true;   }   void getfail() {     fail[0] = fail[1] = 0;     for (int i = 1; i < cnt3; i++) {       int j = fail[i];       while (j && !ok(i, j)) j = fail[j];       fail[i + 1] = (ok(i, j)) ? j + 1 : 0;     }   }   void KMP_search() {     for (int i = 0, j = 0; i < cnt1; i++) {       while (j && !_ok(i, j)) j = fail[j];       if (_ok(i, j)) j++;       if (j == cnt3) {         if ((i - j + 1) && i != (cnt1 - 1) && s[i - j].ch == str[0].ch &&             s[i - j].c >= str[0].c && s[i + 1].ch == str[cnt2 - 1].ch &&             s[i + 1].c >= str[cnt2 - 1].c)           ans++;       }     }   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < n; i++) {       scanf( %I64d-%c , &s[cnt1].c, &s[cnt1].ch);       if (i && s[cnt1].ch == s[cnt1 - 1].ch)         s[cnt1 - 1].c += s[cnt1].c;       else         cnt1++;     }     for (int i = 0; i < m; i++) {       scanf( %I64d-%c , &str[cnt2].c, &str[cnt2].ch);       if (i && str[cnt2].ch == str[cnt2 - 1].ch)         str[cnt2 - 1].c += str[cnt2].c;       else         cnt2++;     }     if (cnt2 == 1) {       for (int i = 0; i < cnt1; i++)         if (s[i].ch == str[0].ch && s[i].c >= str[0].c)           ans += s[i].c - str[0].c + 1;     } else if (cnt2 == 2) {       for (int i = 0; i < cnt1; i++)         if (s[i].ch == str[0].ch && s[i].c >= str[0].c && (i != (cnt1 - 1)) &&             s[i + 1].ch == str[1].ch && s[i + 1].c >= str[i + 1].c)           ans++;     } else {       for (int i = 1; i < cnt2 - 1; i++) _str[cnt3++] = str[i];       getfail();       KMP_search();     }     printf( %I64d n , ans);     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize(2)   using namespace std;   const int inf = 0x3f3f3f3f;   const int mod = 998244353;   using ll = long long;   using vi = vector<int>;   using pii = pair<int, int>;   inline int read() {     int x = 0, f = 1, c = getchar();     for (; !isdigit(c); c = getchar())       if (c == 45) f ^= 1;     for (; isdigit(c); c = getchar()) x = x * 10 + c - 48;     return f ? x : -x;   }   int qp(int x, int n) {     return !n ? 1 : 1LL * qp(1LL * x * x % mod, n >> 1) * (n & 1 ? x : 1) % mod;   }   int inv(int x) { return qp(x, mod - 2); }   int n, m;   int a[55], w[55];   int dp[55][55][55][55];   int main() {     n = read(), m = read();     for (int i = 0; i < (int)(n); ++i) a[i] = read();     int sum = 0, like = 0;     for (int i = 0; i < (int)(n); ++i)       w[i] = read(), sum += w[i], like += w[i] * a[i];     for (int i = 0; i < (int)(n); ++i) dp[0][0][i][0] = 1;     for (int i = 0; i < (int)(m); ++i)       for (int j = 0; j < (int)(i + 1); ++j) {         int nwsum = sum + j - (i - j);         int invnwsum = inv(nwsum);         for (int k = 0; k < (int)(n); ++k)           for (int l = 0; l < (int)(i + 1); ++l) {             if (!dp[i][j][k][l]) continue;             int nwlike = like + j;             for (int sel = 0; sel < (int)(2); ++sel) {               int nj = j + sel;               int ful = sel ? nwlike : nwsum - nwlike;               int nwk = l * (a[k] ? 1 : -1) + w[k];               if (nwk <= 0) continue;               if (sel == a[k]) ful -= nwk;               (dp[i + 1][nj][k][l] +=                1LL * dp[i][j][k][l] * ful % mod * invnwsum % mod) %= mod;               if (sel == a[k])                 (dp[i + 1][nj][k][l + 1] +=                  1LL * dp[i][j][k][l] * nwk % mod * invnwsum % mod) %= mod;             }           }       }     for (int i = 0; i < (int)(n); ++i) {       int ans = 0;       for (int j = 0; j < (int)(m + 1); ++j)         for (int l = 0; l < (int)(m + 1); ++l) {           (ans += 1LL * (l * (a[i] ? 1 : -1) + w[i]) * dp[m][j][i][l] % mod) %=               mod;         }       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int d[(1 << 17) + 20][100], par[(1 << 17) + 20][100];   int prime[20] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53};   int sum[70], a[100];   int ret, temp;   int ans = 10000000;   void pre() {     for (int i = 1; i < 59; i++) {       for (int j = 0; j < 17; j++) {         if (prime[j] > 1 && i % prime[j] == 0) sum[i] += (1 << j);       }     }   }   void pp(int mask, int ind) {     if (ind > 0) pp(mask - sum[par[mask][ind]], ind - 1);     cout << par[mask][ind] <<    ;     return;   }   int main() {     ios::sync_with_stdio(false);     int n;     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i];     pre();     for (int mask = 0; mask < (1 << 17); mask++) {       ret = ans;       for (int val = 1; val < 59; val++) {         temp = ret;         if ((sum[val] & mask) == sum[val]) ret = min(ret, abs(val - a[0]));         if (temp > ret) par[mask][0] = val;       }       d[mask][0] = ret;     }     for (int mask = 0; mask < (1 << 17); mask++) {       for (int ind = 0; ind < n; ind++) {         ret = ans;         for (int val = 1; val < 59; val++) {           temp = ret;           if ((sum[val] & mask) == sum[val])             ret = min(d[mask - sum[val]][ind - 1] + abs(val - a[ind]), ret);           if (temp > ret) {             par[mask][ind] = val;           }         }         d[mask][ind] = ret;       }     }     pp((1 << 17) - 1, n - 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n = 1, i, j = 0;     string s, t;     getline(cin, s);     getline(cin, t);     for (i = 0; i < t.length(); i++) {       if (s[j] == t[i]) {         n++;         j++;       }     }     cout << n;   }


#include <bits/stdc++.h>   using namespace std;   int n, ma, a1;   long long ans;   char ch;   struct point {     int a, b;   } s[1000005];   struct node {     int l, r;     long long add, sum, ma;     node *ch[2];   } * nil, *root;   long long gets() {     long long v = 0;     bool f = 0;     char ch;     while (!isdigit(ch)) {       f |= ch ==  - ;       ch = getchar();     }     while (isdigit(ch)) {       v = (v << 3) + (v << 1) + ch - 48;       ch = getchar();     }     return f ? -v : v;   }   void init() {     nil = new node();     nil->ch[0] = nil->ch[1] = nil;     nil->add = nil->ma = nil->sum = 0;   }   void pushup(node *x) {     x->ma = max(x->ch[0]->ma + x->ch[1]->sum, x->ch[1]->ma);     x->sum = x->ch[0]->sum + x->ch[1]->sum;   }   void build(node *&x, int l, int r) {     x = new node();     x->l = l, x->r = r;     x->ma = x->sum = 0;     if (l == r) {       x->ma = x->l;       return;     }     int mid = l + r >> 1;     build(x->ch[0], l, mid);     build(x->ch[1], mid + 1, r);     pushup(x);   }   void insert(node *x, int pos, long long v) {     if (x->r == x->l && x->r == pos) {       x->ma += v, x->sum += v;       return;     }     int mid = x->l + x->r >> 1;     if (pos <= mid)       insert(x->ch[0], pos, v);     else       insert(x->ch[1], pos, v);     pushup(x);   }   void ask(node *x, int l, int r) {     if (l == x->l && r == x->r) {       ans = max(ans + x->sum, x->ma);       return;     }     int mid = x->l + x->r >> 1;     if (r <= mid)       ask(x->ch[0], l, r);     else if (l > mid)       ask(x->ch[1], l, r);     else       ask(x->ch[0], l, mid), ask(x->ch[1], mid + 1, r);   }   int main() {     n = gets();     ma = 1000000;     init();     build(root, 1, ma);     for (int i = 1; i <= n; i++) {       scanf( %c , &ch);       if (ch ==  ? ) {         a1 = gets();         ans = 0;         ask(root, 1, a1);         ans -= a1;         printf( %I64d n , ans);       }       if (ch ==  + ) {         s[i].a = gets(), s[i].b = gets();         insert(root, s[i].a, s[i].b);       }       if (ch ==  - ) {         a1 = gets();         insert(root, s[a1].a, -s[a1].b);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     n--;     k--;     int arr[n];     for (int i = 0; i < n; i++) cin >> arr[i];     int count = 0;     int flag = 0;     while (count <= k) {       if (count == k) {         flag = 1;         break;       }       count += arr[count];     }     if (flag == 1)       cout <<  YES  << endl;     else       cout <<  NO  << endl;     return 0;   }


#include <bits/stdc++.h>   int main() {     int team1, team2;     std::string s;     std::cin >> s;     team1 = s.find( 1111111 );     team2 = s.find( 0000000 );     if (team1 >= 0 || team2 >= 0) {       std::cout <<  YES ;     } else       std::cout <<  NO ;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 7;   const int M = 1 << 18;   int n, m;   string s;   set<int> S[256];   int sub[2 * M];   void insert(int a) {     a += M - 1;     while (a) {       --sub[a];       a /= 2;     }   }   int kth(int k, int v = 1, int l = 1, int r = M) {     if (l == r) return l;     if (sub[2 * v] >= k)       return kth(k, 2 * v, l, (l + r) / 2);     else       return kth(k - sub[2 * v], 2 * v + 1, (l + r) / 2 + 1, r);   }   void build(int v = 1, int l = 1, int r = M) {     sub[v] = r - l + 1;     if (l == r) return;     build(2 * v, l, (l + r) / 2);     build(2 * v + 1, (l + r) / 2 + 1, r);   }   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cin >> n >> m >> s;     s =  #  + s;     for (int i = 1; i <= n; ++i) {       S[s[i]].insert(i);     }     build();     while (m--) {       int l, r;       char c;       cin >> l >> r >> c;       l = kth(l);       r = kth(r);       auto it = S[c].lower_bound(l);       while (it != S[c].end() && *it <= r) {         insert(*it);         S[c].erase(it);         it = S[c].lower_bound(l);       }     }     for (int i = 1; i <= n; ++i) {       if (S[s[i]].find(i) != S[s[i]].end()) cout << s[i];     }     cout <<   n ;   }


#include <bits/stdc++.h>   int main() {     char a[100009], c;     int j = 0, i;     while ((c = getchar()) !=   n ) {       if (j == 0) {         a[j] = c;         j++;       } else {         if (a[j - 1] == c) {           j--;         } else {           a[j] = c;           j++;         }       }     }     if (j == 0) {       printf( Yes n );     } else {       printf( No n );     }   }


#include <bits/stdc++.h>   using namespace std;   int ans = 123422412;   int n, a, b, x, y;   void dfs(int r, int x, int y, int ret) {     if (x < 0 || y < 0) return;     if (r < 0) return;     if (x == 0 && y == 0) {       ans = min(ans, ret);       return;     }     dfs(r - a, x - 1, y, ret);     dfs(n - a, x - 1, y, ret + 1);     dfs(r - b, x, y - 1, ret);     dfs(n - b, x, y - 1, ret + 1);   }   int main() {     cin >> n >> a >> b;     dfs(n, 4, 2, 1);     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 200005;   const int mod = 1e9 + 7;   struct Node {     int x, y, z;     Node() {}     Node(int _x, int _y, int _z) {       x = _x;       y = _y;       z = _z;       if (x < y) swap(x, y);       if (x < z) swap(x, z);       if (y < z) swap(y, z);     }     bool operator<(const Node& a) const {       if (x != a.x) return x < a.x;       if (y != a.y) return y < a.y;       return z < a.z;     }   };   Node a[10];   int A, B, C;   set<pair<int, int> > s;   set<pair<int, int> >::iterator it;   int v[MAXN];   int vis[MAXN];   int n;   void solve() {     s.clear();     memset(vis, 0, sizeof vis);     scanf( %d%d%d , &A, &B, &C);     for (int i = 1; i <= n; ++i) {       scanf( %d , &v[i]);     }     sort(v + 1, v + n + 1);     for (int i = 1; i <= n; ++i) {       s.insert(make_pair(v[i], i));     }     a[0] = Node(A, B, C);     a[1] = Node(A + B, C, 0);     a[2] = Node(A + C, B, 0);     a[3] = Node(B + C, A, 0);     a[4] = Node(A + B + C, 0, 0);     sort(a, a + 5);     int ans = 0;     for (int i = n; i >= 1; --i)       if (!vis[i]) {         int ok = 0;         ++ans;         for (int j = 0; j < 5; ++j) {           if (a[j].x >= v[i]) {             ok = 1;             vis[i] = 1;             s.erase(make_pair(v[i], i));             int t = 0;             if (s.begin() == s.end()) break;             it = s.lower_bound(make_pair(a[j].y, 0x3f3f3f3f));             if (it != s.begin()) {               --it;               vis[it->second] = 1;               s.erase(*it);               ++t;             }             if (s.begin() == s.end()) break;             it = s.lower_bound(make_pair(a[j].z, 0x3f3f3f3f));             if (it != s.begin()) {               --it;               vis[it->second] = 1;               s.erase(*it);               ++t;             }             if (t == 0) {               it = s.lower_bound(make_pair(a[j].y + a[j].z, 0x3f3f3f3f));               if (it != s.begin()) {                 --it;                 vis[it->second] = 1;                 s.erase(*it);                 ++t;               }             }             break;           }         }         if (!ok) {           printf( -1 n );           return;         }       }     printf( %d n , ans);   }   int main() {     while (~scanf( %d , &n)) solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     long long n, p, w, d;     cin >> n >> p >> w >> d;     bool been[int(1e5)] = {}, can = 0;     long long cnt = p / w, dif = 0;     while (cnt >= 0) {       dif = p - cnt * w;       if (been[dif % d]) break;       if (dif % d == 0) {         if (cnt + dif / d <= n) {           can = 1;           break;         }       }       been[dif % d] = 1;       cnt--;     }     if (can)       cout << cnt <<     << dif / d <<     << n - cnt - dif / d <<   n ;     else       cout <<  -1 n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long a[100001];   long long b[100001];   int main() {     ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);     int n;     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i];     map<int, int> cnt;     vector<int> q;     int loc = 0;     for (int i = n - 1; i >= 0; i--) {       cnt[a[i]]++;       if (cnt[a[i]] == 1) loc++;       b[i] = loc;     }     cnt.clear();     long long ans = 0;     for (int i = 0; i < n - 1; i++) {       cnt[a[i]]++;       if (cnt[a[i]] == 1) ans += b[i + 1];     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int cal(int a, int b, int ba) {     int x[100], xl, y[100], yl, i, z[100];     memset(x, 0, sizeof x);     memset(y, 0, sizeof y);     memset(z, 0, sizeof z);     xl = yl = 0;     while (a > 0) {       x[xl++] = a % 10;       a /= 10;     }     while (b > 0) {       y[yl++] = b % 10;       b /= 10;     }     for (i = 0; i < max(xl, yl); i++) {       z[i] += x[i] + y[i];       if (z[i] >= ba) {         z[i + 1] += z[i] / ba;         z[i] %= ba;       }     }     i = max(xl, yl) + 10;     while (z[i] == 0) i--;     return i + 1;   }   int main() {     int a, b, i, t, m, ans;     while (scanf( %d %d , &a, &b) != EOF) {       m = 0;       t = a;       while (t > 0) {         if (t % 10 > m) m = t % 10;         t /= 10;       }       t = b;       while (t > 0) {         if (t % 10 > m) m = t % 10;         t /= 10;       }       ans = 0;       for (i = m + 1; i <= 1000; i++) {         t = cal(a, b, i);         if (t > ans) ans = t;       }       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 50;   const long long oo = 1e18;   const long long mod = 1e9 + 7;   int a[N], sum[2 * N];   int main() {     int n, m;     cin >> n >> m;     for (int i = 0; i < n; i++) cin >> a[i];     int cur = n;     long long ans = 0;     sum[cur] = 1;     long long q = 0;     for (int i = 0; i < n; i++) {       if (a[i] < m) {         cur--;         q -= sum[cur];       } else {         q += sum[cur];         cur++;       }       ans += q;       sum[cur]++;     }     memset(sum, 0, sizeof(sum));     cur = n;     sum[cur] = 1;     q = 0;     for (int i = 0; i < n; i++) {       if (a[i] < m + 1) {         cur--;         q -= sum[cur];       } else {         q += sum[cur];         cur++;       }       ans -= q;       sum[cur]++;     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   bool umin(T& a, T b) {     if (a > b) {       a = b;       return 1;     }     return 0;   }   template <class T>   bool umax(T& a, T b) {     if (a < b) {       a = b;       return 1;     }     return 0;   }   int arr[300009], b[300009];   vector<pair<int, int> > adj[300009], query[300009];   const int N = 500;   long long ans[300009], par[300009];   int main() {     int n, q, k;     scanf( %d%d%d , &n, &q, &k);     deque<pair<int, int> > deq;     for (int i = 1; i <= n; i++) {       scanf( %d , arr + i);       while (!deq.empty() and deq.back().first >= arr[i]) deq.pop_back();       while (!deq.empty() and i - deq.front().second > k) deq.pop_front();       deq.push_back(make_pair(arr[i], i));       b[i] = deq.front().first;     }     for (int i = 1; i <= n; i++) adj[i % k].push_back(make_pair(i, b[i]));     if (k > N) {       while (q--) {         int l, r;         scanf( %d%d , &l, &r);         int mn = 1000000007;         long long res = arr[l];         int pos = upper_bound(adj[l % k].begin(), adj[l % k].end(),                               make_pair(l, 1000000007)) -                   adj[l % k].begin();         while (pos < (int)adj[l % k].size() and adj[l % k][pos].first <= r)           umin(mn, adj[l % k][pos++].second), res += mn;         printf( %lld n , res);       }       return 0;     }     for (int i = 1; i <= q; i++) {       int l, r;       scanf( %d%d , &l, &r);       query[l].push_back(make_pair(r, i));       ans[i] = arr[l];     }     for (int i = 0; i < k; i++) {       memset(par, 0, sizeof par);       int sz = adj[i].size();       vector<pair<int, int> > v;       for (int j = sz - 1; j >= 0; j--) {         int l = adj[i][j].first, val = adj[i][j].second;         if (!v.empty()) {           for (int h = 0; h < int(query[l].size()); h++) {             int r = query[l][h].first;             int idx = query[l][h].second;             int R = upper_bound(adj[i].begin(), adj[i].end(),                                 make_pair(r, 1000000007)) -                     adj[i].begin();             int st = 0, en = v.size() - 1;             while (st + 1 < en) {               int mid = (st + en) >> 1;               if (v[mid].second < R)                 en = mid;               else                 st = mid;             }             if (v[st].second < R) en = st;             int who = v[en].second;             int me = v[en].first;             if (who < R)               ans[idx] += par[v.back().second] - par[who] + (R - who) * 1LL * me;           }         }         while (!v.empty() and v.back().first >= val) v.pop_back();         if (!v.empty()) {           int next_ind = v.back().second;           par[j] = par[next_ind] + (next_ind - j) * 1LL * val;         }         v.push_back(make_pair(val, j));       }     }     for (int i = 1; i <= q; i++) printf( %lld n , ans[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 998244353;   int main() {     int n, k, sol = 0;     cin >> n >> k;     vector<int> a(n);     for (int i = 0; i < n; i++) cin >> a[i];     sort(a.begin(), a.end());     int maxB = (a[n - 1] - a[0]) / (k - 1);     vector<int> ble(maxB + 2);     vector<vector<int>> b(n + 1);     for (int i = 1; i <= maxB; i++) {       b[0] = vector<int>(k + 1);       b[0][0] = 1;       int p = 0;       for (int j = 1; j <= n; j++) {         while (a[p] <= a[j - 1] - i) p++;         b[j] = b[j - 1];         for (int l = 0; l < k; l++) {           b[j][l + 1] = (b[j][l + 1] + b[p][l]) % mod;           if (b[j][l + 1] == 0) break;         }       }       ble[i] = b[n][k];     }     for (int i = 0; i <= maxB; i++)       sol = (sol + i * (long long)(ble[i] - ble[i + 1]) + mod) % mod;     cout << sol << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long ans;   long long arr[300005][8];   long long a, b;   bool ok(long long mid, long long n, long long m) {     long long mx = (1LL << m) - 1;     long long cnt[mx + 1];     for (int i = 0; i <= mx; i++) cnt[i] = 0;     for (int i = 0; i < n; i++) {       long long tem = 0;       for (int j = 0; j < m; j++) {         if (arr[i][j] >= mid) {           tem = tem | (1LL << j);         }       }       cnt[tem] = i + 1;     }     for (int i = 0; i <= mx; i++) {       for (int j = i; j <= mx; j++) {         if (cnt[i] && cnt[j]) {           long long tem = i | j;           if (tem == mx) {             a = cnt[i];             b = cnt[j];             return true;           }         }       }     }     return false;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(nullptr);     ;     int n, m;     cin >> n >> m;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) cin >> arr[i][j];     }     long long lo = 0;     long long hi = 1e9;     a = 1;     b = 1;     while (lo <= hi) {       long long mid = (lo + hi) / 2;       if (ok(mid, n, m)) {         ans = mid;         lo = mid + 1;       } else {         hi = mid - 1;       }     }     cout << a <<     << b << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long best;   int n, m, k;   int main() {     cin >> n >> m >> k;     if (k > n + m - 2)       cout << -1 << endl;     else {       for (int area = 1; area <= (int)sqrt(n); area++) {         int x = n / area;         if (n / x == area) {           int cut = min(k, x - 1);           int remainCut = k - cut;           if (remainCut + 1 != 0)             best = max(best, (long long)area * (long long)(m / (remainCut + 1)));         }         int _area = n / area;         x = n / _area;         if (n / x == _area) {           int cut = min(k, x - 1);           int remainCut = k - cut;           if (remainCut + 1 != 0)             best = max(best, (long long)_area * (long long)(m / (remainCut + 1)));         }       }       cout << best << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   const int MAX = 1e9 + 5;   long long i, j, k, n, m, RIGHT[N], LEFT[N], ans, a[N];   long long _RIGHT[N], _LEFT[N];   int main() {     scanf( %lld , &n);     for (int i = 1; i <= n - 1; i++) scanf( %lld , &a[i]);     for (int i = n; i >= 1; i--) {       if (a[i] != 1) RIGHT[i] = RIGHT[i + 1] + a[i] - (a[i] & 1);       _RIGHT[i] = max(RIGHT[i + 1], _RIGHT[i + 1]) + a[i] - (!(a[i] & 1));     }     for (int i = 1; i <= n; i++) {       if (a[i - 1] != 1) LEFT[i] = LEFT[i - 1] + a[i - 1] - (a[i - 1] & 1);       _LEFT[i] = max((a[i] != 1) * LEFT[i - 1], (_LEFT[i - 1])) + a[i - 1] -                  (!(a[i - 1] & 1));     }     for (int i = 1; i <= n; i++) {       ans = max(ans, max(_LEFT[i], LEFT[i]) + RIGHT[i]);       ans = max(ans, max(_RIGHT[i], RIGHT[i]) + LEFT[i]);     }     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, m, c0, d0;     cin >> n >> m >> c0 >> d0;     long long a[m + 4], b[m + 5], c[m + 5], d[m + 5];     for (int i = 1; i <= m; i++) {       cin >> a[i] >> b[i] >> c[i] >> d[i];       a[i] /= b[i];     }     c[0] = c0;     a[0] = 1005;     long long dp[n + 4][m + 4];     memset(dp, 0, sizeof(dp));     for (long long i = 1; i <= n; i++) {       for (long long j = 0; j <= m; j++) {         for (long long k = 0; k <= a[j]; k++) {           if (i - c[j] * k < 0) break;           if (j == 0) {             dp[i][j] = k * d0;           } else {             dp[i][j] = max(dp[i - c[j] * k][j - 1] + k * d[j], dp[i][j]);           }         }       }     }     cout << dp[n][m] << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int mohin, a, b, c;     cin >> a >> b >> c;     mohin = 0;     for (int i = 1; i <= c; i++) {       mohin += 2 * ((a - 4 * (i - 1)) + (b - 4 * (i - 1))) - 4;     }     cout << mohin << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a, b, c, l;   long long Ans;   int main() {     cin >> a >> b >> c >> l;     for (int i = 0; i <= l; i++) {       long long lim = (a + b + c + i - 1) / 2;       if (a <= lim && b <= lim && c <= lim) {         Ans += (long long)(i + 2) * (i + 1) / 2;         if (a + i > lim) {           Ans -= (long long)(i + a - lim + 1) * (i + a - lim) / 2;         }         if (b + i > lim) {           Ans -= (long long)(i + b - lim + 1) * (i + b - lim) / 2;         }         if (c + i > lim) {           Ans -= (long long)(i + c - lim + 1) * (i + c - lim) / 2;         }       }     }     cout << Ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   char n[1000100];   char b[1000100];   int main() {     long long result, last, i, B, c, BB[10];     int re, C;     while (scanf( %s %s %d , b, n, &C) != EOF) {       c = C;       B = 0;       for (i = 0; b[i]; i++) B = (B * 10 + b[i] -  0 ) % c;       if (B == 0) B = c;       BB[0] = 1;       for (i = 1; i < 10; i++) BB[i] = (BB[i - 1] * B) % c;       for (i = strlen(n) - 1; i >= 0; i--)         if (n[i] !=  0 ) break;       n[i]--;       for (i++; n[i]; i++) n[i] =  9 ;       result = 1;       for (i = 0; n[i]; i++) {         last = result;         result = (result * result) % c;         result = (result * result) % c;         result = (result * result) % c;         result = (result * last) % c;         result = (result * last) % c;         result = (result * BB[n[i] -  0 ]) % c;       }       result = (result * (B - 1)) % c;       if (result == 0) result = c;       re = result;       printf( %d n , re);     }     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   using namespace std;   const int N = 100005;   int i, n, k, x, y, lvl[N];   vector<int> g[N];   queue<int> q;   int main() {     ios_base::sync_with_stdio(0);     memset(lvl, -1, sizeof(lvl));     cin >> n >> k;     for (i = 1; i < n; ++i) {       cin >> x >> y;       g[x].push_back(y);       g[y].push_back(x);     }     for (i = 1; i <= n; ++i)       if (g[i].size() == 1) q.push(i), lvl[i] = 0;     for (; !q.empty(); q.pop()) {       x = q.front();       if (lvl[x] == k) continue;       vector<int> now;       for (int to : g[x])         if (lvl[to] == -1 || lvl[to] == lvl[x] + 1) now.push_back(to);       if (now.size() > 1) return cout <<  No n , 0;       if (!now.size()) return cout <<  No n , 0;       if (g[now[0]].size() < 4 - (lvl[x] + 1 == k)) return cout <<  No n , 0;       if (lvl[now[0]] == -1) lvl[now[0]] = lvl[x] + 1, q.push(now[0]);     }     int cnt = 0;     for (i = 1; i <= n; ++i) {       if (lvl[i] > k) return cout <<  No n , 0;       if (lvl[i] == k) ++cnt;       if (cnt > 1) return cout <<  No n , 0;     }     cout << (!cnt ?  No  :  Yes ) <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   double ans = 0.0F;   int n, d, m[101] = {0}, r[101] = {0};   int tmp = 0;   int main(int argc, char** argv, char** env) {     cin >> n;     for (int i = 1; i <= n; ++i) {       cin >> m[i];     }     for (int i = 1; i <= n; ++i) {       cin >> r[i];     }     for (int i = 0; i < (int)1e6; ++i) {       for (int j = 1; j <= n; ++j) {         if (i % m[j] == r[j]) {           tmp++;           break;         }       }     }     ans = tmp * 1.0F / 1e6;     cout << fixed << setprecision(6) << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, x[200001], y[200001], tag[200001], fi[200001 << 1], nt[200001 << 1],       go[200001 << 1], root;   int cnt, top, low[200001], dfn[200001], id[200001], deg[200001], st[200001],       ans, cntx, sum, maxx;   void add(int u, int v) {     nt[++cnt] = fi[u];     fi[u] = cnt;     go[cnt] = v;   }   void tarjan(int u, int fa) {     dfn[u] = ++cnt;     low[u] = dfn[u];     st[++top] = u;     int t = 0;     for (int i = fi[u]; i; i = nt[i]) {       int v = go[i];       if (v == fa && !t) {         t++;         continue;       }       if (dfn[v]) {         low[u] = min(low[u], low[v]);         continue;       }       tarjan(v, u);       low[u] = min(low[u], low[v]);     }     if (low[u] == dfn[u]) {       int y;       while (y = st[top--]) {         tag[y] = u;         if (y == u) break;       }     }   }   void dfs1(int u, int dep) {     dfn[u] = 1;     for (int i = fi[u]; i; i = nt[i]) {       int v = go[i];       if (dfn[v]) continue;       dfs1(v, dep + 1);     }     if (dep > maxx) root = u, maxx = dep;   }   void dfs2(int u, int dep, int fa) {     for (int i = fi[u]; i; i = nt[i]) {       int v = go[i];       if (v == fa) continue;       dfs2(v, dep + 1, u);     }     if (dep >= maxx) maxx = dep;   }   int main() {     scanf( %d %d , &n, &m);     for (int i = 1; i <= m; i++) {       scanf( %d %d , &x[i], &y[i]);       add(x[i], y[i]);       add(y[i], x[i]);     }     for (int i = 1; i <= n; i++) {       top = 0;       cnt = 0;       if (!dfn[i]) tarjan(i, 0);     }     memset(fi, 0, sizeof fi);     cnt = 0;     top = 0;     for (int i = 1; i <= n; i++)       if (tag[i] == i) id[i] = ++top;     for (int i = 1; i <= m; i++) {       if (tag[x[i]] != tag[y[i]]) {         add(id[tag[x[i]]], id[tag[y[i]]]), add(id[tag[y[i]]], id[tag[x[i]]]);         deg[id[tag[x[i]]]]++;         deg[id[tag[y[i]]]]++;       }     }     for (int i = 1; i <= top; i++) {       if (deg[i] == 1) ans++;     }     memset(dfn, 0, sizeof dfn);     for (int i = 1; i <= top; i++) {       if (!dfn[i] && deg[i] == 0) sum++, ans++;       if (!dfn[i] && deg[i] != 0) {         sum++;         dfs1(i, 1), dfs2(root, 1, 0);         root = 0;         ans += maxx - 2;         maxx = 0;       }     }     sum--;     ans = sum + n - ans;     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline bool cmin(T& a, const T& b) {     return a > b ? a = b, 1 : 0;   }   template <typename T>   inline bool cmax(T& a, const T& b) {     return a < b ? a = b, 1 : 0;   }   const int MaxN = 205;   unsigned int n, d, M, c[MaxN][MaxN], f[MaxN][MaxN], g[MaxN];   int main() {     cin >> n >> d >> M;     c[0][0] = 1;     for (int i = 1; i <= n; i++) {       c[i][0] = 1;       for (int j = 1; j <= i; j++) c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % M;     }     f[1][0] = 1;     for (int i = 2; i <= n; i++) {       for (int k = 0; k < d; k++) (g[i - 1] += f[i - 1][k]) %= M;       for (int j = 1; j < i; j++)         for (int k = 0; k < d; k++)           f[i][k + 1] = (f[i][k + 1] +                          (long long)f[i - j][k] * g[j] % M * c[i - 2][j - 1]) %                         M;     }     int ans = 0;     for (int i = 0; i < n; i++)       for (int j = 0; j <= d; j++)         for (int k = 0; j + k <= d; k++) {           if (k == 1) continue;           ans = (ans + (long long)f[i + 1][j] * f[n - i][k]) % M;         }     ans = (long long)ans * 2 * n * (n - 1) % M;     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, a, b, i, j;     cin >> n >> a >> b;     for (i = 0; i <= 10000000; i++) {       if (n - a * i >= 0) {         if ((n - a * i) % b == 0) {           cout <<  YES                 <<   n ;           cout << i <<     << (n - a * i) / b;           return 0;         }       }     }     cout <<  NO ;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 3e5 + 5;   int N, M, K;   int A[MAXN];   long long P, H;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> N;     for (int i = 1; i <= N; i++) {       cin >> P;       A[i] = A[i - 1] + __builtin_popcountll(P);       M = 0;       for (int j = i - 1; j >= 0; j--) {         if (A[i] - A[j] >= 118) {           break;         }         M = max(M, A[j + 1] - A[j]);         if ((A[i] - A[j]) & 1) {           continue;         }         if (A[i] - A[j] < 2 * M) {           H--;         }       }       if (A[i] & 1) {         H += K;         K++;       } else {         H += i - K;       }     }     cout << H <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool exceed(long long x, long long y, long long m) { return x >= m / y + 1; }   long long n, k;   string s;   long long dp[1005][2005];   int zero = 1002;   int main(void) {     ios::sync_with_stdio(0);     cin >> n >> k >> s;     s =  #  + s;     for (long long(i) = (0); (i) <= (n); (i)++)       for (long long(j) = (-k); (j) <= (k); (j)++) dp[i][zero + j] = -1e18;     dp[0][zero + 0] = 0;     for (long long(i) = (0); (i) <= (n - 1); (i)++) {       for (long long(j) = (-k); (j) <= (k); (j)++) {         for (long long(l) = (-1); (l) <= (1); (l)++) {           if (dp[i][zero + j] < -1e18 / 2) continue;           if (s[i + 1] !=  ? ) {             if (s[i + 1] !=  W  && l == 1) continue;             if (s[i + 1] !=  L  && l == -1) continue;             if (s[i + 1] !=  D  && l == 0) continue;           }           long long nj = j + l;           if (abs(nj) > k) continue;           if (i + 1 != n && abs(nj) == k) continue;           dp[i + 1][zero + nj] = j;         }       }     }     long long p = -1e18;     if (dp[n][zero + k] > -1e18 / 2) p = k;     if (dp[n][zero - k] > -1e18 / 2) p = -k;     if (p < -1e18 / 2) {       cout <<  NO  << endl;       return 0;     }     for (int i = n; i >= 1; i--) {       if (dp[i][zero + p] == p) s[i] =  D ;       if (dp[i][zero + p] < p) s[i] =  W ;       if (dp[i][zero + p] > p) s[i] =  L ;       p = dp[i][zero + p];     }     cout << s.substr(1) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 200005;   int n, log2n, q, C[N], L[N], R[N], tot = 0, f[N][25], up[N], de2[N];   long long de[N];   struct node {     long long min, sign;   } a[N * 4];   pair<int, int> E[2 * N];   vector<pair<int, int> > e[N];   void add1(int x, int k) {     for (; x <= n; x += x & (-x)) de[x] += k;   }   long long ask1(int x) {     long long res = 0;     for (; x; x -= x & (-x)) res += de[x];     return res;   }   void build(int l, int r, int now) {     if (l == r) {       a[now].min = ask1(l) + up[C[l]];       return;     }     int mid = (l + r) >> 1;     build(l, mid, now << 1);     build(mid + 1, r, now << 1 | 1);     a[now].min = min(a[now << 1].min, a[now << 1 | 1].min);   }   void update(int l, int r, int now, int k) {     a[now].min += k;     a[now].sign += k;   }   void down(int l, int r, int now) {     int mid = (l + r) >> 1;     update(l, mid, now << 1, a[now].sign);     update(mid + 1, r, now << 1 | 1, a[now].sign);     a[now].sign = 0;   }   void add2(int l, int r, int now, int s, int t, int k) {     if (s <= l && r <= t) {       update(l, r, now, k);       return;     }     down(l, r, now);     int mid = (l + r) >> 1;     if (s <= mid) add2(l, mid, now << 1, s, t, k);     if (t > mid) add2(mid + 1, r, now << 1 | 1, s, t, k);     a[now].min = min(a[now << 1].min, a[now << 1 | 1].min);   }   long long ask2(int l, int r, int now, int s, int t) {     if (s <= l && r <= t) return a[now].min;     down(l, r, now);     int mid = (l + r) >> 1;     long long res = 0x3f3f3f3f3f3f3f3f;     if (s <= mid) res = min(ask2(l, mid, now << 1, s, t), res);     if (t > mid) res = min(ask2(mid + 1, r, now << 1 | 1, s, t), res);     return res;   }   void dfs1(int u, int fa) {     f[u][0] = fa;     C[++tot] = u;     L[u] = tot;     for (int i = 0; i < e[u].size(); i++) {       int v = e[u][i].first;       if (v == fa) continue;       dfs1(v, u);     }     R[u] = tot;   }   void dfs2(int u, int fa) {     for (int i = 0; i < e[u].size(); i++) {       int v = e[u][i].first, w = e[u][i].second;       if (v == fa) continue;       de2[v] = de2[u] + 1;       add1(L[v], w);       add1(R[v] + 1, -w);       dfs2(v, u);     }   }   bool on(int u, int v) {     swap(u, v);     long long k = de2[u] - de2[v];     if (k < 0) return false;     for (int i = 0; k; i++, k >>= 1)       if (k & 1) u = f[u][i];     return (u == v);   }   int main() {     std::ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> q;     log2n = log2(n);     for (int i = 1; i <= 2 * n - 2; i++) {       int u, v, w;       cin >> u >> v >> w;       if (i < n)         E[i] = {w, v};       else         E[i] = {w, u}, up[u] = w;       if (i >= n) continue;       e[u].push_back({v, w});       e[v].push_back({u, w});     }     dfs1(1, 0);     dfs2(1, 0);     for (int j = 1; j <= log2n; j++)       for (int i = 1; i <= n; i++) f[i][j] = f[f[i][j - 1]][j - 1];     build(1, n, 1);     for (int i = 0; i < q; i++) {       int c, x, y;       cin >> c >> x >> y;       if (c == 1) {         if (x < n) {           add1(L[E[x].second], -E[x].first + y);           add1(R[E[x].second] + 1, E[x].first - y);           add2(1, n, 1, L[E[x].second], R[E[x].second], -E[x].first + y);         } else           add2(1, n, 1, L[E[x].second], L[E[x].second], -E[x].first + y);         E[x].first = y;       } else {         if (on(x, y))           cout << ask1(L[y]) - ask1(L[x]) << endl;         else           cout << ask2(1, n, 1, L[x], R[x]) - ask1(L[x]) + ask1(L[y]) << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   const long long pinf = ((long long)2e18);   const long long ninf = ((long long)-2e18);   const long long mod = 1000000007;   using namespace std;   long long power(long long x, long long n, long long M) {     if (n == 0)       return 1;     else if (n % 2 == 0)       return power((x * x) % M, n / 2, M);     else       return (x * power((x * x) % M, (n - 1) / 2, M)) % M;   }   bool vowel(char c) {     return (c ==  a  or c ==  e  or c ==  i  or c ==  o  or c ==  u  or             c ==  A  or c ==  E  or c ==  I  or c ==  U  or c ==  O );   }   int32_t main() {     ;     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long t;     cin >> t;     while (t--) {       long long n;       cin >> n;       vector<long long> a(n), b(n);       map<long long, long long> make_pair;       for (long long i = 0; i < n; i++) {         cin >> a[i];         make_pair[a[i]]++;         b[i] = a[i];       }       sort(b.begin(), b.end());       long long p = 0;       long long ans = 0;       long long l = 0, r = n - 1;       while (l < r) {         if (make_pair[b[p]]) {           if (a[l] == b[p]) {             make_pair[a[l]]--;             p++;             l++;           } else if (a[r] == b[p]) {             make_pair[a[r]]--;             r--;             p++;           } else {             make_pair[a[l]]--;             l++;             ans = l;           }         } else {           p++;         }       }       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /stack:256000000 )   #pragma gcc optimize( O3 )   #pragma gcc target( sse4 )   using namespace std;   mt19937 rng(2391);   mt19937 gnr(chrono::high_resolution_clock::now().time_since_epoch().count());   template <typename A>   istream& operator>>(istream& fin, vector<A>& v) {     for (auto it = v.begin(); it != v.end(); ++it) fin >> *it;     return fin;   }   template <typename A, typename B>   istream& operator>>(istream& fin, pair<A, B>& p) {     fin >> p.first >> p.second;     return fin;   }   template <typename A, typename B>   pair<A, B> operator+(const pair<A, B>& a, const pair<A, B>& b) {     return make_pair(a.first + b.first, a.second + b.second);   }   template <typename A, typename B>   pair<A, B> operator+=(pair<A, B>& a, const pair<A, B>& b) {     a.first += b.first;     a.second += b.second;     return a;   }   template <typename A, typename B>   pair<A, B> operator-(const pair<A, B>& a, const pair<A, B>& b) {     return make_pair(a.first - b.first, a.second - b.second);   }   template <typename A, typename B>   pair<A, B> operator-(const pair<A, B>& a) {     return make_pair(-a.first, -a.second);   }   template <typename A, typename B>   pair<A, B>& operator++(pair<A, B>& a) {     ++a.first;     ++a.second;     return a;   }   template <typename A, typename B>   pair<A, B>& operator--(pair<A, B>& a) {     --a.first;     --a.second;     return a;   }   template <typename A>   vector<A>& operator++(vector<A>& a) {     for (auto it = a.begin(); it != a.end(); ++it) ++*it;     return a;   }   template <typename A>   vector<A>& operator--(vector<A>& a) {     for (auto it = a.begin(); it != a.end(); ++it) --*it;     return a;   }   template <typename A, typename B>   pair<A, B> operator++(pair<A, B>& a, int) {     pair<A, B> b = a;     ++a;     return b;   }   template <typename A, typename B>   pair<A, B> operator--(pair<A, B>& a, int) {     pair<A, B> b = a;     --a;     return b;   }   template <typename A>   vector<A>& operator++(vector<A>& a, int) {     vector<A> b = a;     ++a;     return b;   }   template <typename A>   vector<A>& operator--(vector<A>& a, int) {     vector<A> b = a;     --a;     return b;   }   vector<vector<int>> adjlist_from_edgelist(const vector<pair<int, int>>& e,                                             const int& n) {     vector<vector<int>> g(n);     for (auto it = e.begin(); it != e.end(); ++it) {       g[it->first].push_back(it->second);       g[it->second].push_back(it->first);     }     return g;   }   template <typename A, typename B>   pair<A, B> operator-=(pair<A, B>& a, const pair<A, B>& b) {     a.first -= b.first;     a.second -= b.second;     return a;   }   template <typename A>   A operator*(const pair<A, A>& p, const pair<A, A>& q) {     return p.first * q.first + p.second * q.second;   }   template <typename A>   pair<A, A> operator*(const pair<A, A>& p, const A& q) {     return make_pair(p.first * q, p.second * q);   }   template <typename A>   A operator%(const pair<A, A>& p, const pair<A, A>& q) {     return p.first * q.second - p.second * q.first;   }   template <typename A>   A sq_len(const pair<A, A>& p) {     return p * p;   }   template <typename A>   A sq_dist(const pair<A, A>& p, const pair<A, A>& q) {     return sq_len(p - q);   }   template <typename A>   double len(const pair<A, A>& p) {     return sqrt(sq_len(p));   }   template <typename A>   double dist(const pair<A, A>& p, const pair<A, A>& q) {     return len(p - q);   }   template <typename A>   bool is_rhombus(const pair<A, A>& a, const pair<A, A>& b, const pair<A, A>& c,                   const pair<A, A>& d) {     A x = sq_dist(a, b);     A y = sq_dist(b, c);     A z = sq_dist(c, d);     A t = sq_dist(d, a);     return ((x == y) && (y == z) && (z == t));   }   template <typename A>   bool is_rectangle(const pair<A, A>& a, const pair<A, A>& b, const pair<A, A>& c,                     const pair<A, A>& d) {     pair<A, A> x = a - b, y = b - c, z = c - d, t = d - a;     return ((x * y == 0) && (y * z == 0) && (z * t == 0) && (t * x == 0));   }   template <typename A>   bool are_parallel(const pair<A, A>& a, const pair<A, A>& b) {     return (a % b == 0);   }   template <typename A>   bool are_orthogonal(const pair<A, A>& a, const pair<A, A>& b) {     return (a * b == 0);   }   template <typename A>   bool are_codirected(const pair<A, A>& a, const pair<A, A>& b) {     return (are_parallel(a, b) && (a * b >= 0));   }   template <typename A>   bool is_parallelogram(const pair<A, A>& a, const pair<A, A>& b,                         const pair<A, A>& c, const pair<A, A>& d) {     return ((a - b) == (d - c));   }   template <typename A>   bool is_trapezoid(const pair<A, A>& a, const pair<A, A>& b, const pair<A, A>& c,                     const pair<A, A>& d) {     pair<A, A> x = a - b, z = d - c;     return are_codirected(x, z);   }   template <typename A>   bool is_convex_polygon(const pair<A, A>& a, const pair<A, A>& b,                          const pair<A, A>& c, const pair<A, A>& d) {     pair<A, A> x = a - b, y = b - c, z = c - d, t = d - a;     A p = x % y, q = y % z, r = z % t, s = t % x;     return (((p >= 0) && (q >= 0) && (r >= 0) && (s >= 0)) ||             ((p <= 0) && (q <= 0) && (r <= 0) && (s <= 0)));   }   template <typename A>   bool nprcs(const pair<A, A>& a, const pair<A, A>& c) {     return ((a % c) >= 0);   }   template <typename A>   bool nprcs(const pair<A, A>& a, const pair<A, A>& b, const pair<A, A>& c) {     return nprcs(a - b, a - c);   }   template <typename A>   bool npocs(const pair<A, A>& a, const pair<A, A>& c) {     return ((a % c) <= 0);   }   template <typename A>   bool npocs(const pair<A, A>& a, const pair<A, A>& b, const pair<A, A>& c) {     return npocs(a - b, a - c);   }   template <typename A>   bool prcs(const pair<A, A>& a, const pair<A, A>& c) {     return ((a % c) > 0);   }   template <typename A>   bool prcs(const pair<A, A>& a, const pair<A, A>& b, const pair<A, A>& c) {     return prcs(a - b, a - c);   }   template <typename A>   bool pocs(const pair<A, A>& a, const pair<A, A>& c) {     return ((a % c) < 0);   }   template <typename A>   bool pocs(const pair<A, A>& a, const pair<A, A>& b, const pair<A, A>& c) {     return pocs(a - b, a - c);   }   template <typename A>   bool different_sides(const pair<A, A>& a, const pair<A, A>& b,                        const pair<A, A>& c, const pair<A, A>& d) {     pair<A, A> x = b - a;     A p = x % (c - b), q = x % (d - b);     return (((p >= 0) && (q <= 0)) || ((p <= 0) && (q >= 0)));   }   template <typename A>   bool sharply_different_sides(const pair<A, A>& a, const pair<A, A>& b,                                const pair<A, A>& c, const pair<A, A>& d) {     pair<A, A> x = b - a;     A p = x % (c - b), q = x % (d - b);     return (((p > 0) && (q < 0)) || ((p < 0) && (q > 0)));   }   template <typename A>   pair<A, A> rot_90(const pair<A, A>& p) {     return make_pair(-p.second, p.first);   }   template <typename A>   pair<A, A> rot_90(const pair<A, A>& p, const pair<A, A>& c) {     return c + rot_90(p - c);   }   template <typename A>   bool intersecting_segments(const pair<A, A>& a, const pair<A, A>& b,                              const pair<A, A>& c, const pair<A, A>& d) {     return different_sides(a, b, c, d) && different_sides(c, d, a, b);   }   template <typename A>   bool sharply_intersecting_segments(const pair<A, A>& a, const pair<A, A>& b,                                      const pair<A, A>& c, const pair<A, A>& d) {     return sharply_different_sides(a, b, c, d) &&            sharply_different_sides(c, d, a, b);   }   template <typename A>   pair<pair<A, A>, A> line_with_normal_vector_through_point(       const pair<A, A>& normal, const pair<A, A>& point) {     return make_pair(normal, -(normal * point));   }   template <typename A>   pair<pair<A, A>, A> serper(const pair<A, A>& a, const pair<A, A>& b) {     pair<A, A> p = b - a;     return make_pair(p + p, -(p * (a + b)));   }   pair<double, double> ints(const pair<double, double>& p, const double& a,                             const pair<double, double>& q, const double& b) {     double D = p % q;     double E =         pair<double, double>(-a, p.second) % pair<double, double>(-b, q.second);     double F =         pair<double, double>(p.first, -a) % pair<double, double>(q.first, -b);     return pair<double, double>(E / D, F / D);   }   pair<double, double> circumcenter(const pair<double, double>& x,                                     const pair<double, double>& y,                                     const pair<double, double>& z) {     auto p1 = serper(x, y), p2 = serper(x, z);     return ints(p1.first, p1.second, p2.first, p2.second);   }   template <typename A>   pair<pair<A, A>, A> l_th_2(const pair<A, A>& p, const pair<A, A>& q) {     return make_pair(make_pair(q.second - p.second, p.first - q.first), -p % q);   }   template <typename A>   vector<pair<double, double>> circle_intersection(const pair<pair<A, A>, A>& a,                                                    const pair<pair<A, A>, A>& b) {     pair<A, A> c = b.first - a.first;     A rr1 = a.second * a.second, rr2 = b.second * b.second, cc = c * c,       rrrr1 = rr1 * rr1, rrrr2 = rr2 * rr2, cccc = cc * cc,       D = 2 * (rr1 * rr2 + rr2 * cc + cc * rr1) - (rrrr1 + rrrr2 + cccc);     if (D >= 0) {       double E = (((double)(rr1 - rr2)) / cc + 1) / 2;       pair<double, double> baza =           pair<double, double>(a.first.first, a.first.second) +           pair<double, double>(c.first, c.second) * E;       if (D) {         double lll = sqrt((double)(D)) / (2 * cc);         pair<A, A> cr = rot_90(c);         pair<double, double> pmm =             pair<double, double>(cr.first, cr.second) * lll;         return {baza + pmm, baza - pmm};       } else         return vector<pair<double, double>>(1, baza);     } else       return vector<pair<double, double>>();   }   template <typename A, typename B>   pair<A, B> sopr(const pair<A, B>& p) {     return make_pair(p.first, -p.second);   }   template <typename A>   bool on_segment(const pair<A, A>& a, const pair<A, A>& b, const pair<A, A>& c) {     return are_codirected(b - a, c - b);   }   template <typename A>   pair<pair<A, A>, A> perpendicular(const pair<A, A>& line,                                     const pair<A, A>& point) {     return line_with_normal_vector_through_point(rot_90(line), point);   }   pair<double, double> projection(const pair<pair<double, double>, double>& line,                                   const pair<double, double>& point) {     pair<pair<double, double>, double> temp = perpendicular(line.first, point);     return ints(line.first, line.second, temp.first, temp.second);   }   pair<double, double> height(const pair<double, double>& a,                               const pair<double, double>& b,                               const pair<double, double>& c) {     return projection(l_th_2(a, c), b);   }   pair<double, double> unitvector(const pair<double, double>& a) {     return a * (1 / len(a));   }   template <typename T>   vector<int> z_function(const vector<T>& s) {     int n = ((int)(s.size()));     vector<int> z(n);     int l = 0, r = 1;     for (int i = 1; i < n; ++i) {       z[i] = max(0, min(r - i, z[i - l]));       while (i + z[i] < n && (s[i + z[i]] == s[z[i]])) ++z[i];       if (r < i + z[i]) {         l = i;         r = i + z[i];       }     }     return z;   }   pair<int, int> euc(const int& m, const int& n) {     if (n == 0) return pair<int, int>((m >= 0) ? 1 : -1, 0);     int t = m / n;     pair<int, int> ans1 = euc(n, m - t * n);     return pair<int, int>(ans1.second, ans1.first - ans1.second * t);   }   int prod(const int& a, const int& b, const int& M) {     return ((long long)(a)) * b % M;   }   int sum(const int& a, const int& b, const int& M) {     int c = a + b;     return c >= M ? c - M : c;   }   int raz(const int& a, const int& b, const int& M) {     int c = a - b;     return c < 0 ? c + M : c;   }   const int LITTLE_BORDER = 400;   struct factorizator {     int N;     vector<int> pr;     vector<int> md;     vector<int> pw;     vector<int> without_md;     factorizator(const int& n) : N(n), md(n), pw(n), without_md(n, 1) {       for (int i = 2; i < N; ++i) md[i] = i;       for (int i = 2; i < N; ++i) {         if (md[i] == i) pr.push_back(i);         bool worth = true;         for (int j = 0; worth && (j < ((int)(pr.size()))) && (pr[j] <= md[i]);              ++j) {           long long temp = ((long long)(pr[j])) * i;           if (temp < N)             md[((int)temp)] = pr[j];           else             worth = false;         }       }       for (int i = 2; i < N; ++i) {         int t = md[i], s = i / t;         if (md[s] == t) {           pw[i] = 1 + pw[s];           without_md[i] = without_md[s];         } else {           pw[i] = 1;           without_md[i] = s;         }       }     }     void known_factorization(int n, vector<pair<unsigned long long, int>>& v) {       while (n > 1) {         v.emplace_back(md[n], pw[n]);         n = without_md[n];       }     }     vector<pair<unsigned long long, int>> pollardRho(const unsigned long long& n);     vector<pair<unsigned long long, int>> factor(unsigned long long n);     template <typename T>     vector<pair<T, int>> merge(const vector<pair<T, int>>& p1,                                const vector<pair<T, int>>& p2) {       vector<pair<T, int>> ans;       int m = ((int)(p1.size()));       int n = ((int)(p2.size()));       int i = 0;       int j = 0;       while ((i < m) || (j < n)) {         if (i < m) {           if (j < n) {             if (p1[i].first < p2[j].first)               ans.push_back(p1[i++]);             else if (p1[i].first > p2[j].first)               ans.push_back(p2[j++]);             else {               ans.emplace_back(p1[i].first, p1[i].second + p2[j].second);               ++i;               ++j;             }           } else             ans.push_back(p1[i++]);         } else           ans.push_back(p2[j++]);       }       return ans;     }   };   factorizator fac(LITTLE_BORDER);   unsigned long long experimental_prodll(const unsigned long long& a,                                          const unsigned long long& b,                                          const unsigned long long& M,                                          const int& helper) {     if (M == 0) return 0;     unsigned long long q = ((long double)a) * b / M;     unsigned long long a1 = a * b - q * M;     unsigned long long a2 = a1;     int rm = M % helper;     int ra = a % helper;     int rb = b % helper;     int rq = q % helper;     int r1 = raz(prod(ra, rb, helper), prod(rq, rm, helper), helper);     int r2 = r1;     while (true) {       if (a1 % helper == r1 && a1 < M) return a1;       a1 -= M;       r1 = raz(r1, rm, helper);       a2 += M;       r2 = sum(r2, rm, helper);       if (a2 % helper == r2 && a2 < M) return a2;     }   }   inline int find_helper(const unsigned long long& M) {     int i = 30;     while (M % fac.pr[i] == 0) ++i;     return fac.pr[i];   }   unsigned long long prodll(const unsigned long long& a,                             const unsigned long long& b,                             const unsigned long long& M) {     if (M == 0) return 0;     unsigned long long helper = find_helper(M);     return experimental_prodll(a, b, M, helper);   }   unsigned long long sumll(const unsigned long long& a,                            const unsigned long long& b,                            const unsigned long long& M) {     if (a < M - b)       return a + b;     else       return a + b - M;   }   unsigned long long razll(const unsigned long long& a,                            const unsigned long long& b,                            const unsigned long long& M) {     if (a >= b)       return a - b;     else       return a + M - b;   }   template <typename T>   T diff(const T& a, const T& b) {     return (a > b) ? (a - b) : (b - a);   }   template <typename A>   bool angdis_cmp(const pair<A, A>& a, const pair<A, A>& b) {     A p;     if (p = a % b)       return (p > 0);     else       return sq_len(a) < sq_len(b);   }   template <typename T>   int find_min_idx(const vector<T>& v) {     int ans = 0, n = ((int)(v.size()));     for (int i = 1; i < n; ++i)       if (v[i] < v[ans]) ans = i;     return ans;   }   template <typename T>   vector<int> convex_hull(vector<pair<T, T>>& a) {     int n = ((int)(a.size()));     if (n) {       int mt = find_min_idx(a);       pair<T, T> d = a[mt];       for (int i = 0; i < n; ++i) a[i] -= d;       vector<int> idx(n);       for (int i = 0; i < n; ++i) idx[i] = i;       sort(idx.begin(), idx.end(),            [&](const int& l, const int& r) { return angdis_cmp(a[l], a[r]); });       vector<int> h(1, idx.front());       for (auto it = idx.begin() + 1; it != idx.end(); ++it) {         auto temp = a.begin() + *it;         if (((int)(h.size())) >= 2) {           if (are_parallel(a[h.back()], *temp)) h.pop_back();           while ((((int)(h.size())) >= 3) &&                  npocs(a[h[((int)(h.size())) - 2]], a[h.back()], *temp))             h.pop_back();         }         h.push_back(*it);       }       for (int i = 0; i < n; ++i) a[i] += d;       return h;     } else       return vector<int>();   }   pair<int, int> cool_gcd(const int& a, const int& b) {     if (b) {       int c = a / b;       pair<int, int> ans1 = cool_gcd(b, a - b * c);       return pair<long long, long long>(ans1.second,                                         ans1.first - ans1.second * c);     } else       return pair<int, int>(1, 0);   }   pair<long long, long long> cool_gcdll(const long long& a, const long long& b) {     if (b) {       long long c = a / b;       pair<long long, long long> ans1 = cool_gcdll(b, a - b * c);       return pair<long long, long long>(ans1.second,                                         ans1.first - ans1.second * c);     } else       return pair<long long, long long>(1ll, 0ll);   }   template <typename T>   T gcd(T a, T b) {     while (b) {       a %= b;       swap(a, b);     }     return a;   }   long long pr_p(const long long& a, const long long& b, const long long& p) {     if (b < 1000000) return (a * b) % p;     long long temp = pr_p(a, b >> 1ll, p);     temp = sumll(temp, temp, p);     if (b & 1ll)       return sumll(temp, a, p);     else       return temp;   }   long long po_p(const long long& a, const long long& b, const long long& p) {     if (b < 2) {       if (b == 0)         return 1;       else         return a;     }     long long temp = po_p(a, b >> 1ll, p);     temp = pr_p(temp, temp, p);     if (b & 1ll)       return pr_p(temp, a, p);     else       return temp;   }   int pow_mod(const int& a, const int& b, const int& p) {     if (b < 2) {       if (b == 0)         return 1;       else         return a;     }     int temp = pow_mod(a, b >> 1, p);     temp = prod(temp, temp, p);     if (b & 1)       return prod(temp, a, p);     else       return temp;   }   long long pow_modll(const long long& a, const long long& b,                       const long long& p) {     if (b < 2) {       if (b == 0)         return 1;       else         return a;     }     long long temp = pow_modll(a, b >> 1ll, p);     temp = prodll(temp, temp, p);     if (b & 1ll)       return prodll(temp, a, p);     else       return temp;   }   int inverse(int a, int n) {     int c = cool_gcd(a, n).first;     if (c < 0) c += n;     return c;   }   long long inversell(long long a, long long n) {     long long c = cool_gcdll(a, n).first;     if (c < 0) c += n;     return c;   }   template <typename A>   pair<int, int> equal_elements(const vector<A>& u, const vector<A>& v) {     pair<int, int> ans(INT_MAX, INT_MAX);     int m = ((int)(u.size())), n = ((int)(v.size()));     vector<int> id_u(m);     for (int i = 1; i < m; ++i) id_u[i] = i;     vector<int> id_v(n);     for (int i = 1; i < n; ++i) id_v[i] = i;     sort(id_u.begin(), id_u.end(),          [&](const int& x, const int& y) { return u[x] < u[y]; });     sort(id_v.begin(), id_v.end(),          [&](const int& x, const int& y) { return v[x] < v[y]; });     int i = 0;     int j = 0;     while ((i < m) && (j < n)) {       if (u[id_u[i]] < v[id_v[j]])         ++i;       else if (v[id_v[j]] < u[id_u[i]])         ++j;       else {         ans = min(ans, pair<int, int>(id_v[j], id_u[i]));         ++j;       }     }     if (ans.first == INT_MAX)       return pair<int, int>(-1, -1);     else       return pair<int, int>(ans.second, ans.first);   }   long long discr_log(long long a, long long b, long long n) {     int k = ((int)(sqrt((long double)n)));     long long a1 = inversell(a, n);     int l = k + 20;     long long a2 = po_p(a1, k, n);     vector<long long> seq1(k), seq2(l);     seq1.front() = 1;     for (int i = 1; i < k; ++i) seq1[i] = pr_p(seq1[i - 1], a, n);     seq2.front() = b;     for (int i = 1; i < l; ++i) seq2[i] = pr_p(seq2[i - 1], a2, n);     pair<long long, long long> e = equal_elements(seq1, seq2);     if (e.first == -1)       return -1;     else       return e.first + e.second * k;   }   long long common_discr_log(long long a, long long b, long long n) {     const int C = 70;     a %= n;     b %= n;     if (gcd(n, a) != 1) {       for (int i = 0; i < C; ++i) {         if (po_p(a, i, n) == b) {           return i;         }       }       long long multp = po_p(a, C, n);       long long g = gcd(multp, n);       if (b % g) {         return -1;       } else {         b /= g;         n /= g;         multp /= g;         long long pop_back = inversell(multp, n);         b = pr_p(b, pop_back, n);         long long ans = discr_log(a, b, n);         if (ans == -1)           return -1;         else           return ans + C;       }     } else       return discr_log(a, b, n);   }   const unsigned long long minimum_composites[] = {1ull,                                                    2046ull,                                                    1373652ull,                                                    25326000ull,                                                    3215031750ull,                                                    2152302898746ull,                                                    3474749660382ull,                                                    341550071728320ull,                                                    341550071728320ull,                                                    3825123056546413050ull,                                                    3825123056546413050ull,                                                    18446744073709551615ull};   const int little_primes[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37};   bool miller_rabin_check(const unsigned long long& n,                           const unsigned long long& prime,                           const unsigned long long& odd,                           const unsigned long long& pot,                           const unsigned long long& nmo) {     long long x = pow_modll(prime, odd, n);     if ((x == nmo) || (x == 1)) return true;     for (int i = 1; i < pot; ++i) {       x = prodll(x, x, n);       if (x == nmo) return true;       if (x == 1) return false;     }     return false;   }   bool is_prime(const unsigned long long& n) {     if (n <= 2) return (n == 2);     unsigned long long odd, pot, nmo;     nmo = n - 1;     odd = nmo;     pot = 0;     while ((odd & 1ll) == 0) {       odd >>= 1ll;       ++pot;     }     int i = 0;     while (n > minimum_composites[i]) {       if (miller_rabin_check(n, little_primes[i], odd, pot, nmo) == false)         return false;       ++i;     }     return true;   }   vector<pair<unsigned long long, int>> factorizator::pollardRho(       const unsigned long long& n) {     if (is_prime(n))       return vector<pair<unsigned long long, int>>(           1, pair<unsigned long long, int>(n, 1));     int step = 1;     while (true) {       step <<= 1;       unsigned long long a = rng();       unsigned long long b = a;       unsigned long long d = 1;       for (int j = 0; j < step; ++j) {         a = sumll(1, prodll(a, a, n), n);         b = sumll(1, prodll(b, b, n), n);         b = sumll(1, prodll(b, b, n), n);         d = gcd(diff(a, b), n);         if (d > 1) {           break;         }       }       if (1 < d && d < n) return merge(pollardRho(d), pollardRho(n / d));     }     return vector<pair<unsigned long long, int>>();   }   vector<pair<unsigned long long, int>> factorizator::factor(       unsigned long long n) {     vector<pair<unsigned long long, int>> ans;     for (int i = 0; n >= N && i < ((int)(pr.size())) && pr[i] < LITTLE_BORDER;          ++i)       while (n % pr[i] == 0) {         if (((int)(ans.size())) && ans.back().first == pr[i])           ++ans.back().second;         else           ans.emplace_back(pr[i], 1);         n /= pr[i];       }     if (n < N) {       known_factorization(n, ans);       return ans;     } else       return merge(ans, pollardRho(n));   }   template <typename T>   T phi(const vector<pair<T, int>>& v) {     T ans = 1;     for (int i = 0; i < ((int)(v.size())); ++i) {       ans *= v[i].first - 1;       for (int j = 1; j < v[i].second; ++j) ans *= v[i].first;     }     return ans;   }   unsigned long long phi(const unsigned long long& n) {     return phi(fac.factor(n));   }   bool check_primitive_root(const int& ph, const vector<int>& to_check,                             const int& r, const int& n) {     for (int i = 0; i < ((int)(to_check.size())); ++i)       if (pow_mod(r, to_check[i], n) == 1) return false;     return (pow_mod(r, ph, n) == 1);   }   int primitive_root(const int& n) {     if (n < 3) return n - 1;     int p = phi(n);     vector<pair<unsigned long long, int>> f = fac.factor(p);     vector<int> to_check(((int)(f.size())));     for (int i = 0; i < ((int)(f.size())); ++i) to_check[i] = p / f[i].first;     for (int i = 2; i < n; ++i)       if (check_primitive_root(p, to_check, i, n)) return i;     return -1;   }   int unite_mod(const int& a, const int& p, const int& b, const int& q) {     pair<int, int> c = cool_gcd(p, q);     int pr = p * q;     int ans = ((a * c.second * q + b * c.first * p) % pr + pr) % pr;     return ans;   }   long long unite_modll(const long long& a, const long long& p,                         const long long& b, const long long& q) {     pair<long long, long long> c = cool_gcdll(p, q);     long long pr = p * q;     long long ans = ((a * c.second * q + b * c.first * p) % pr + pr) % pr;     return ans;   }   pair<int, int> power_v(int n, const int& p) {     int ans = 0;     while (n % p == 0) {       n /= p;       ++ans;     }     return pair<int, int>(ans, n);   }   int square_root_prime_modulo(int c, int n, const int& pr, const int& k) {     c %= n;     if (c) {       pair<int, int> kek = power_v(c, pr);       int l = kek.first;       if (l & 1) return -1;       if (l > 0) {         int pwl = 1;         for (int i = 0; i < l; ++i) pwl *= pr;         n /= pwl;         c /= pwl;         int ans1 = square_root_prime_modulo(c, n, pr, k - l);         if (ans1 == -1) return -1;         for (int i = 0; i < (l >> 1); ++i) ans1 *= pr;         return ans1;       } else {         int primitive;         if (n & 1)           primitive = primitive_root(n);         else           primitive = 5;         int u = ((int)discr_log(primitive, c, n));         if (u == -1) return -1;         if (u & 1) return -1;         return pow_mod(primitive, u >> 1, n);       }     } else       return 0;   }   int square_root_modulo(const int& c, const int& n) {     vector<pair<unsigned long long, int>> f = fac.factor(n);     int a = 0, p = 1;     for (int i = 0; i < ((int)(f.size())); ++i) {       int q = 1;       for (int j = 0; j < f[i].second; ++j) q *= f[i].first;       int b = square_root_prime_modulo(c, q, f[i].first, f[i].second);       if (b == -1) return -1;       a = unite_mod(a, p, b, q);       p *= q;     }     return a;   }   namespace BGF {   inline int cntd(unsigned x) {     int ans = 0;     while (x) {       if (x & 1) ++ans;       x >>= 1;     }     return ans;   }   inline long long cntdll(unsigned long long x) {     long long ans = 0;     while (x) {       if (x & 1) ++ans;       x >>= 1;     }     return ans;   }   inline int clzd(unsigned x) {     int ans = 32;     while (x) {       --ans;       x >>= 1;     }     return ans;   }   inline long long clzdll(unsigned long long x) {     long long ans = 64;     while (x) {       --ans;       x >>= 1;     }     return ans;   }   inline int ctzd(unsigned x) {     if (x == 0) return 32;     int ans = 0;     while ((x & 1) == 0) {       ++ans;       x >>= 1;     }     return ans;   }   inline long long ctzdll(unsigned long long x) {     if (x == 0) return 64;     long long ans = 0;     while ((x & 1) == 0) {       ++ans;       x >>= 1;     }     return ans;   }   }  // namespace BGF   namespace BGF {   const unsigned BHC = 65535u;   const unsigned long long BHCL = 65535ull;   const unsigned BHN = 65536u;   const unsigned BHL = 16u;   const unsigned LH = 4294901760u;   const unsigned RH = 65535u;   const unsigned long long BHLL1 = 16ull;   const unsigned long long BHLL2 = 32ull;   const unsigned long long BHLL3 = 48ull;   const unsigned long long LHL = 18446744069414584320ull;   const unsigned long long RHL = 4294967295ull;   int CNT[BHN];   int CLZ[BHN];   int CTZ[BHN];   inline void initialize() {     CNT[0] = 0;     CLZ[0] = BHL + BHL;     CTZ[0] = BHL;     for (unsigned i = 1; i < BHN; ++i) {       CNT[i] = cntd(i);       CLZ[i] = clzd(i);       CTZ[i] = ctzd(i);     }   }   inline int cntc(const unsigned& x) {     return CNT[x & BHC] + CNT[(x >> BHL) & BHC];   }   inline long long cntcll(const unsigned long long& x) {     return CNT[x & BHCL] + CNT[(x >> BHLL1) & BHCL] + CNT[(x >> BHLL2) & BHCL] +            CNT[(x >> BHLL3) & BHCL];   }   inline int clzc(const unsigned& x) {     if (x & LH)       return CLZ[x >> BHL] - BHL;     else       return CLZ[x];   }   inline long long clzcll(const unsigned long long& x) {     if (x & LHL)       return clzc(x >> BHLL2);     else       return clzc(x) + BHLL2;   }   inline int ctzc(const unsigned& x) {     if (x & RH)       return CTZ[x & RH];     else       return CTZ[x >> BHL] + BHL;   }   inline long long ctzcll(const unsigned long long& x) {     if (x & RHL)       return ctzc(x);     else       return ctzc(x >> BHLL2) + BHLL2;   }   }  // namespace BGF   const string INPUT_FILE =  input.txt ;   const string OUTPUT_FILE =  output.txt ;   void rel(long long& a, const long long& b) {     if (a > b) a = b;   }   int another_main() {     const int INF = 1e9 + 1;     const long long SINF = 1e12 + 2;     const long long SSINF = 1e18 + 2;     const int MINF = -INF;     int t;     cin >> t;     for (int I = 0; I < t; ++I) {       int n, m;       cin >> n >> m;       vector<pair<int, int>> u;       for (int i = 0; i < n; ++i) {         int x;         cin >> x;         u.emplace_back(x, -MINF);       }       for (int i = 0; i < m; ++i) {         pair<int, int> p;         cin >> p;         u.push_back(pair<int, int>(p.first, -p.second));       }       sort(u.begin(), u.end());       vector<pair<int, int>> w;       for (pair<int, int> p : u) {         p.second = -p.second;         while (((int)(w.size())) &&                (w.back().second >= p.first && w.back().second >= p.second))           w.pop_back();         w.push_back(p);       }       int q = 0;       int mxp = MINF;       vector<long long> L, R;       vector<int> into(1);       vector<pair<int, int>> z;       for (pair<int, int> p : w)         if (p.second == MINF) {           mxp = max(mxp, p.first);           ++into[q];         } else {           z.push_back(p);           if (mxp != MINF)             L.push_back(p.first - mxp);           else             L.push_back(SINF);           ++q;           into.emplace_back();         }       R.resize(q);       int mnp = INF;       for (int i = ((int)(w.size())) - 1; i >= 0; --i) {         pair<int, int> p = w[i];         if (p.second == MINF)           mnp = min(mnp, p.first);         else {           --q;           if (mnp != INF)             R[q] = mnp - p.second;           else             R[q] = SINF;         }       }       q = ((int)(L.size()));       vector<vector<long long>> dp(4, vector<long long>(q + 1, SSINF));       for (int j = 0; j < 4; ++j) dp[j][0] = 0;       for (int i = 0; i < q; ++i) {         if (into[i] == 0) {           if (i) {             rel(dp[0][i + 1],                 ((long long)z[i].first - z[i - 1].first) + dp[0][i]);             rel(dp[1][i + 1],                 2ll * ((long long)z[i].first - z[i - 1].first) + dp[1][i]);             rel(dp[2][i + 1], dp[2][i]);             rel(dp[3][i + 1], dp[3][i]);           }         }         rel(dp[2][i + 1], 2 * R[i] + dp[0][i]);         rel(dp[2][i + 1], 2 * R[i] + dp[1][i]);         rel(dp[3][i + 1], R[i] + dp[0][i]);         rel(dp[3][i + 1], R[i] + dp[1][i]);         if (into[i]) {           rel(dp[1][i + 1], 2 * L[i] + dp[0][i]);           rel(dp[1][i + 1], 2 * L[i] + dp[1][i]);           rel(dp[0][i + 1], L[i] + dp[0][i]);           rel(dp[0][i + 1], L[i] + dp[1][i]);           rel(dp[2][i + 1], 2 * R[i] + dp[0][i]);           rel(dp[2][i + 1], 2 * R[i] + dp[1][i]);           rel(dp[2][i + 1], 2 * R[i] + dp[2][i]);           rel(dp[2][i + 1], 2 * R[i] + dp[3][i]);           rel(dp[3][i + 1], R[i] + dp[0][i]);           rel(dp[3][i + 1], R[i] + dp[1][i]);           rel(dp[3][i + 1], R[i] + dp[2][i]);           rel(dp[3][i + 1], R[i] + dp[3][i]);           if (into[i] == 1) {             rel(dp[0][i + 1], L[i] + dp[2][i]);             rel(dp[1][i + 1], 2 * L[i] + dp[3][i]);           } else {             rel(dp[0][i + 1], L[i] + dp[3][i]);           }         }         i = i;       }       long long ans = SSINF;       for (int i = 0; i < 4; ++i) ans = min(ans, dp[i][q]);       cout << ans <<   n ;     }     return 0;   }   int main() {     BGF::initialize();     int AMR = another_main();     return AMR;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, Magic, md, pd;   int a[99], b[99], cnt[99], row[99], col[99];   int t[99][99];   void giveans() {     printf( %d n , Magic);     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++) printf( %d%c , t[i][j],    n [j + 1 == n]);     exit(0);   }   void dfs2(int, int);   void dfs(int x, int y) {     if (x == n) {       if (row[n - 1] == Magic && md == Magic && pd == Magic) giveans();     } else if (x == 2 && y == 0)       dfs(x, y + 1);     else if (x == 2 && y == 3)       dfs(x + 1, 0);     else if (x == n - 1) {       int tmp, tmp1, tmp2;       if (y == 0)         tmp = lower_bound(b, b + m, Magic - pd) - b;       else         tmp = lower_bound(b, b + m, Magic - col[y]) - b;       if ((y == 0 && b[tmp] != Magic - pd) ||           (y != 0 && b[tmp] != Magic - col[y]))         return;       if (!cnt[tmp]) return;       cnt[tmp]--;       t[x][y] = b[tmp];       if (y == n - 1) md += b[tmp];       if (!y) pd += b[tmp];       row[x] += b[tmp];       col[y] += b[tmp];       bool ok = 1, need = 0;       if (y == 0 && ok) {         tmp1 = lower_bound(b, b + m, Magic - col[0]) - b;         if (b[tmp1] != Magic - col[0] || !cnt[tmp1])           ok = 0;         else {           cnt[tmp1]--;           col[0] += b[tmp1];           row[2] += b[tmp1];           t[2][0] = b[tmp1];           tmp2 = lower_bound(b, b + m, Magic - row[2]) - b;           if (b[tmp2] != Magic - row[2] || !cnt[tmp2]) {             ok = 0;             col[0] -= b[tmp1];             row[2] -= b[tmp1];             cnt[tmp1]++;           } else {             cnt[tmp2]--;             t[2][3] = b[tmp2];             col[3] += b[tmp2];             row[2] += b[tmp2];             need = 1;           }         }       }       if (ok) {         if (y == n - 1)           dfs(x + 1, 0);         else           dfs(x, y + 1);       }       if (need) {         cnt[tmp1]++;         col[0] -= b[tmp1];         row[2] -= b[tmp1];         cnt[tmp2]++;         col[3] -= b[tmp2];         row[2] -= b[tmp2];       }       if (!y) pd -= b[tmp];       if (y == n - 1) md -= b[tmp];       col[y] -= b[tmp];       row[x] -= b[tmp];       cnt[tmp]++;     } else if (y == n - 1) {       int tmp = lower_bound(b, b + m, Magic - row[x]) - b;       if (b[tmp] != Magic - row[x]) return;       if (!cnt[tmp]) return;       cnt[tmp]--;       t[x][y] = b[tmp];       if (!x) pd += b[tmp];       col[y] += b[tmp];       row[x] += b[tmp];       dfs(x + 1, 0);       col[y] -= b[tmp];       row[x] -= b[tmp];       if (!x) pd -= b[tmp];       cnt[tmp]++;     } else {       for (int i = 0; i < m; i++)         if (cnt[i]) {           cnt[i]--;           t[x][y] = b[i];           row[x] += b[i];           col[y] += b[i];           if (x == y) md += b[i];           if (x + y == n - 1) pd += b[i];           dfs(x, y + 1);           if (x + y == n - 1) pd -= b[i];           if (x == y) md -= b[i];           col[y] -= b[i];           row[x] -= b[i];           cnt[i]++;         }     }   }   int main() {     srand(13451);     scanf( %d , &n);     srand(rand() * 10 + rand() + n);     for (int i = 0; i < n * n; i++)       scanf( %d , a + i), Magic += a[i], b[i] = a[i];     if (n == 1) {       printf( %d n%d n , a[0], a[0]);       return 0;     }     sort(b, b + n * n);     m = unique(b, b + n * n) - b;     b[m] = 1000000000;     for (int i = 0; i < n * n; i++) cnt[lower_bound(b, b + m, a[i]) - b]++;     Magic /= n;     if (n < 4) dfs2(0, 0);     int p[200];     for (int i = 0; i < m; i++) p[i] = i;     random_shuffle(p, p + m);     for (int i = 0; i < m; i++) {       cnt[i]--;       t[0][0] = b[i];       row[0] += b[i];       col[0] += b[i];       md += b[i];       dfs(0, 1);       row[0] -= b[i];       col[0] -= b[i];       md -= b[i];       cnt[i]++;     }     return 0;   }   void dfs2(int x, int y) {     if (x == n) {       if (row[n - 1] == Magic && md == Magic && pd == Magic) giveans();     } else if (x == n - 1) {       int tmp = lower_bound(b, b + m, Magic - col[y]) - b;       if (b[tmp] != Magic - col[y]) return;       if (!cnt[tmp]) return;       cnt[tmp]--;       t[x][y] = b[tmp];       if (y == n - 1) md += b[tmp];       if (!y) pd += b[tmp];       row[x] += b[tmp];       if (pd == Magic) {         if (y == n - 1)           dfs2(x + 1, 0);         else           dfs2(x, y + 1);       }       if (!y) pd -= b[tmp];       if (y == n - 1) md -= b[tmp];       row[x] -= b[tmp];       cnt[tmp]++;     } else if (y == n - 1) {       int tmp = lower_bound(b, b + m, Magic - row[x]) - b;       if (b[tmp] != Magic - row[x]) return;       if (!cnt[tmp]) return;       cnt[tmp]--;       t[x][y] = b[tmp];       if (!x) pd += b[tmp];       col[y] += b[tmp];       dfs2(x + 1, 0);       col[y] -= b[tmp];       if (!x) pd -= b[tmp];       cnt[tmp]++;     } else {       for (int i = 0; i < m; i++)         if (cnt[i]) {           cnt[i]--;           t[x][y] = b[i];           row[x] += b[i];           col[y] += b[i];           if (x == y) md += b[i];           if (x + y == n - 1) pd += b[i];           dfs2(x, y + 1);           if (x + y == n - 1) pd -= b[i];           if (x == y) md -= b[i];           col[y] -= b[i];           row[x] -= b[i];           cnt[i]++;         }     }   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x0FFFFFFF;   const long long INFLL = 0x0FFFFFFFFFFFFFFFll;   const int MAXN = 300005;   int n, m, x, y;   vector<int> g[MAXN];   int ans[MAXN];   int getenemies(int i) {     int c = 0;     for (size_t j = 0; j < g[i].size(); j++)       if (ans[g[i][j]] == ans[i]) c++;     return c;   }   void solve(int p) {     if (getenemies(p) > 1) {       ans[p] = 1 - ans[p];       for (size_t j = 0; j < g[p].size(); j++) solve(g[p][j]);     }   }   int main() {     cin >> n >> m;     while (m--) {       cin >> x >> y;       g[x].push_back(y);       g[y].push_back(x);     }     for (int i = 1; i <= n; i++) solve(i);     for (int i = 1; i <= n; i++) cout << ans[i];     cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 300010;   map<pair<int, int>, int> mp;   struct point {     int first, second;     int l, r;     point() {}     point(int first, int second, int l, int r)         : first(first), second(second), l(l), r(r) {}   };   long long ans[N << 1];   long long sum;   int cnt;   int cx[N << 1], cy[N << 1];   int pre[N << 1];   int sz[N << 1];   int find(int first) {     if (!pre[first]) return first;     return find(pre[first]);   }   struct store {     int first;     int cx, cy;     int sz;     int pre;     store() {}     store(int first, int cx, int cy, int sz, int pre)         : first(first), cx(cx), cy(cy), sz(sz), pre(pre) {}   };   stack<store> stk;   void recovery(store a) {     sz[a.first] = a.sz;     cx[a.first] = a.cx;     cy[a.first] = a.cy;     pre[a.first] = a.pre;     sum += 1LL * a.cx * a.cy;   }   void unions(int first, int second) {     first = find(first);     second = find(second);     if (first == second) return;     if (sz[first] > sz[second]) swap(first, second);     cnt += 2;     stk.push(store(first, cx[first], cy[first], sz[first], pre[first]));     stk.push(store(second, cx[second], cy[second], sz[second], pre[second]));     sum -= 1LL * cx[first] * cy[first];     sum -= 1LL * cx[second] * cy[second];     sz[second] += sz[first];     cx[second] += cx[first];     cy[second] += cy[first];     sz[second] += sz[first];     pre[first] = second;     sum += 1LL * cx[second] * cy[second];   }   void rollback() {     cnt -= 2;     store second = stk.top();     stk.pop();     store first = stk.top();     stk.pop();     sum -= 1LL * cx[second.first] * cy[second.first];     recovery(second);     recovery(first);   }   void solve(int l, int r, vector<point> &v) {     if (l == r) {       int tmp = cnt;       for (int i = 0; i < v.size(); i++) {         int first = v[i].first, second = v[i].second;         unions(first, second);       }       ans[l] = sum;       while (cnt > tmp) rollback();       return;     }     int tmp = cnt;     vector<point> vl, vr;     int mid = (l + r) >> 1;     for (int i = 0; i < v.size(); i++) {       if (v[i].l == l && v[i].r == r) {         int first = v[i].first, second = v[i].second;         unions(first, second);       } else if (v[i].r <= mid)         vl.push_back(v[i]);       else if (v[i].l > mid)         vr.push_back(v[i]);       else {         vl.push_back(point(v[i].first, v[i].second, v[i].l, mid));         vr.push_back(point(v[i].first, v[i].second, mid + 1, v[i].r));       }     }     solve(l, mid, vl);     solve(mid + 1, r, vr);     while (cnt > tmp) {       rollback();     }   }   int main() {     ios::sync_with_stdio(false);     vector<point> v;     int n;     cin >> n;     for (int i = 1; i <= 300000; i++) {       cx[i] = 1;       cy[i + 300000] = 1;     }     for (int i = 1; i <= 600000; i++) sz[i] = 1;     for (int i = 1; i <= n; i++) {       int first, second;       cin >> first >> second;       second += 300000;       if (mp.count(make_pair(first, second))) {         int st = mp[make_pair(first, second)];         int ed = i - 1;         v.push_back(point(first, second, st, ed));         mp.erase(make_pair(first, second));       } else {         mp[make_pair(first, second)] = i;       }     }     for (map<pair<int, int>, int>::iterator it = mp.begin(); it != mp.end();          it++) {       int first = it->first.first;       int second = it->first.second;       int st = it->second;       int ed = n;       v.push_back(point(first, second, st, ed));     }     solve(1, n, v);     for (int i = 1; i <= n; i++) cout << ans[i] <<    ;     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const int maxn = 10105;   int n, b, q, st, ed;   int First[maxn], cnt, dis[maxn];   struct edge {     int to, Next, flow, c;   } Tree[maxn * 100];   void init() {     cnt = 0;     memset(First, -1, sizeof(First));   }   void addedge(int from, int to, int flow) {     Tree[cnt].to = to;     Tree[cnt].Next = First[from];     Tree[cnt].flow = flow;     First[from] = cnt++;     Tree[cnt].to = from;     Tree[cnt].Next = First[to];     Tree[cnt].flow = 0;     First[to] = cnt++;   }   bool bfs(int st, int ed) {     memset(dis, 0, sizeof(dis));     queue<int> Q;     dis[st] = 1;     Q.push(st);     while (!Q.empty()) {       int u = Q.front();       Q.pop();       for (int i = First[u]; i != -1; i = Tree[i].Next) {         int v = Tree[i].to;         int flow = Tree[i].flow;         if (flow && !dis[v]) {           dis[v] = dis[u] + 1;           if (v == ed) return true;           Q.push(v);         }       }     }     return false;   }   int dfs(int u, int minf) {     if (u == ed) {       return minf;     }     if (minf == 0) return minf;     int f = 0;     for (int i = First[u]; i != -1; i = Tree[i].Next) {       int v = Tree[i].to;       if (Tree[i].flow && dis[v] == dis[u] + 1) {         int tmp = dfs(v, min(Tree[i].flow, minf));         Tree[i].flow -= tmp;         Tree[i ^ 1].flow += tmp;         f += tmp;         minf -= tmp;         if (minf == 0) return f;       }     }     return f;   }   int dinic(int st, int ed) {     int res = 0;     while (bfs(st, ed)) res += dfs(st, INF);     return res;   }   struct node {     int up, num;     bool operator<(const node& A) const {       if (A.up != up) return A.up > up;       return A.num > num;     }   } ax[10005];   int sum[10];   int main() {     init();     scanf( %d%d%d , &n, &b, &q);     st = 0, ed = q + 5 + 10;     for (int i = 1; i <= q; i++) scanf( %d%d , &ax[i].up, &ax[i].num);     sort(ax + 1, ax + 1 + q);     ax[q + 1].up = b, ax[q + 1].num = n;     for (int i = 1; i <= q + 1; i++) {       int nowv = ax[i].up - ax[i - 1].up;       int nowb = ax[i].num - ax[i - 1].num;       if (ax[i].num > n || nowb > nowv || nowb < 0) {         puts( unfair );         return 0;       }       for (int j = ax[i - 1].up + 1; j <= ax[i].up; j++) {         sum[j % 5]++;       }       for (int j = 0; j < 5; j++) addedge(i, q + j + 2, sum[j]);       addedge(st, i, nowb);       memset(sum, 0, sizeof(sum));     }     for (int i = 1; i <= 5; i++) addedge(q + i + 1, ed, n / 5);     int max1 = dinic(st, ed);     if (max1 == n)       puts( fair );     else       puts( unfair );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long arr[10000001];   int main() {     long long d = 1;     arr[0] = 0;     for (int i = 1; i < 10000001; i++) {       arr[i] = arr[i - 1] + d;       d += 2;     }     int t;     cin >> t;     for (int i = 0; i < t; i++) {       int n, k;       cin >> n >> k;       if (n % 2 == 0 && k % 2 != 0) {         cout <<  NO  << endl;         continue;       }       if (n % 2 != 0 && k % 2 == 0) {         cout <<  NO  << endl;         continue;       }       long long x = arr[k];       if (n >= x)         cout <<  YES  << endl;       else         cout <<  NO  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     long long i;     long long n;     cin >> n;     cin >> s;     long long arr[27];     for (i = 0; i < 26; i++) {       arr[i] = 0;     }     for (i = 0; i < s.length(); i++) {       arr[s[i] -  a ]++;     }     long long cnt = 0;     if (n == 1) {       cout <<  YES ;       return 0;     }     for (i = 0; i < 26; i++) {       if (arr[i] > 1) {         cout <<  YES ;         return 0;       }     }     cout <<  NO ;     return 0;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 998244353;   long long dp[511][511];   long long tol[511];   int main() {     int n, k, i, j, p;     scanf( %d%d , &n, &k);     for (i = 1; i <= n; ++i) dp[0][i] = 1;     for (i = 1; i <= n; ++i) {       for (j = 1; j <= n; ++j) {         for (p = max(i - j, 0); p <= i - 1; ++p) {           dp[i][j] = dp[i][j] + dp[p][j];           dp[i][j] %= mod;         }       }     }     for (i = 1; i <= n; ++i) {       tol[i] = dp[n][i] - dp[n][i - 1];     }     long long ans = 0;     for (i = 1; i <= n; ++i) {       for (j = 1; j <= n; ++j) {         if (i * j < k) {           ans += tol[i] * tol[j];           ans %= mod;         }       }     }     ans *= 2;     cout << (ans % mod + mod) % mod << endl;     return 0;   }