#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline void ckmax(T& x, T y) {     x = (y > x ? y : x);   }   template <typename T>   inline void ckmin(T& x, T y) {     x = (y < x ? y : x);   }   namespace Fread {   const int SIZE = 1 << 21;   char buf[SIZE], *S, *T;   inline char getchar() {     if (S == T) {       T = (S = buf) + fread(buf, 1, SIZE, stdin);       if (S == T) return EOF;     }     return *S++;   }   }  // namespace Fread   namespace Fwrite {   const int SIZE = 1 << 21;   char buf[SIZE], *S = buf, *T = buf + SIZE;   inline void flush() {     fwrite(buf, 1, S - buf, stdout);     S = buf;   }   inline void putchar(char c) {     *S++ = c;     if (S == T) flush();   }   struct NTR {     ~NTR() { flush(); }   } ztr;   }  // namespace Fwrite   namespace Fastio {   struct Reader {     template <typename T>     Reader& operator>>(T& x) {       char c = Fread ::getchar();       T f = 1;       while (c <  0  || c >  9 ) {         if (c ==  - ) f = -1;         c = Fread ::getchar();       }       x = 0;       while (c >=  0  && c <=  9 ) {         x = x * 10 + (c -  0 );         c = Fread ::getchar();       }       x *= f;       return *this;     }     Reader& operator>>(char& c) {       c = Fread ::getchar();       while (c ==   n  || c ==    ) c = Fread ::getchar();       return *this;     }     Reader& operator>>(char* str) {       int len = 0;       char c = Fread ::getchar();       while (c ==   n  || c ==    ) c = Fread ::getchar();       while (c !=   n  && c !=    ) {         str[len++] = c;         c = Fread ::getchar();       }       str[len] =   0 ;       return *this;     }     Reader() {}   } cin;   const char endl =   n ;   struct Writer {     template <typename T>     Writer& operator<<(T x) {       if (x == 0) {         Fwrite ::putchar( 0 );         return *this;       }       if (x < 0) {         Fwrite ::putchar( - );         x = -x;       }       static int sta[45];       int top = 0;       while (x) {         sta[++top] = x % 10;         x /= 10;       }       while (top) {         Fwrite ::putchar(sta[top] +  0 );         --top;       }       return *this;     }     Writer& operator<<(char c) {       Fwrite ::putchar(c);       return *this;     }     Writer& operator<<(char* str) {       int cur = 0;       while (str[cur]) Fwrite ::putchar(str[cur++]);       return *this;     }     Writer& operator<<(const char* str) {       int cur = 0;       while (str[cur]) Fwrite ::putchar(str[cur++]);       return *this;     }     Writer() {}   } cout;   }  // namespace Fastio   const int MAXN = 1e5;   const int MOD = 1e9 + 7;   inline int mod1(int x) { return x < MOD ? x : x - MOD; }   inline int mod2(int x) { return x < 0 ? x + MOD : x; }   inline void add(int& x, int y) { x = mod1(x + y); }   inline void sub(int& x, int y) { x = mod2(x - y); }   int n, goal, a[MAXN + 5];   int pw2[MAXN + 5];   int dp[MAXN + 5][2][2][2];   inline int calc0(int i, int have_1) {     if (have_1) assert(i);     return have_1 ? pw2[i - 1] : pw2[i];   }   inline int calc1(int i, int have_1) {     if (have_1) assert(i);     return have_1 ? pw2[i - 1] : 0;   }   int main() {     Fastio ::cin >> n >> goal;     for (int i = 1; i <= n; ++i) {       Fastio ::cin >> a[i];     }     pw2[0] = 1;     for (int i = 1; i <= n; ++i) pw2[i] = pw2[i - 1] * 2 % MOD;     dp[0][0][0][0] = 1;     for (int i = 1; i <= n; ++i) {       for (int have_r1 = 0; have_r1 <= 1; ++have_r1) {         for (int have_b1 = 0; have_b1 <= 1; ++have_b1) {           for (int s = 0; s <= 1; ++s)             if (dp[i - 1][have_r1][have_b1][s]) {               if (a[i] != 1) {                 add(dp[i][have_r1][have_b1][s],                     (long long)dp[i - 1][have_r1][have_b1][s] *                         calc1(i - 1, have_b1) % MOD);                 add(dp[i][have_r1 | 1][have_b1][s ^ 1],                     (long long)dp[i - 1][have_r1][have_b1][s] *                         calc0(i - 1, have_b1) % MOD);               }               if (a[i] != 0) {                 add(dp[i][have_r1][have_b1][s],                     (long long)dp[i - 1][have_r1][have_b1][s] *                         calc1(i - 1, have_r1) % MOD);                 add(dp[i][have_r1][have_b1 | 1][s ^ 1],                     (long long)dp[i - 1][have_r1][have_b1][s] *                         calc0(i - 1, have_r1) % MOD);               }             }         }       }     }     int ans = 0;     for (int have_r1 = 0; have_r1 <= 1; ++have_r1) {       for (int have_b1 = 0; have_b1 <= 1; ++have_b1) {         add(ans, dp[n][have_r1][have_b1][goal]);       }     }     Fastio ::cout << ans << Fastio ::endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool debug = 0;   int n, m, k;   int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};   long long ln, lk, lm;   int x[105], y[105], r[105];   string vs[2];   void add(int id, int i, int x) {     string str =  (((1-abs((t- ;     str += to_string(i);     str +=  )))+abs((abs((t- ;     str += to_string(i);     str +=  ))-1)))* ;     str += to_string(x);     str +=  ) ;     if (vs[id] ==   )       vs[id] = str;     else {       vs[id] =  (  + vs[id] +  +  + str +  ) ;     }   }   void fmain() {     scanf( %d , &n);     for (int(i) = 0; (i) < (int)(2); (i)++) vs[i] =   ;     for (int(i) = 0; (i) < (int)(n); (i)++) {       scanf( %d%d%d , x + i, y + i, r + i);       add(0, i + 1, x[i] / 2);       add(1, i + 1, y[i] / 2);     }     for (int(i) = 0; (i) < (int)(2); (i)++) cout << vs[i] << endl;   }   int main() {     fmain();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int bit(int x, int i) { return (x >> i) & 1; }   inline int two(int x) { return 1 << x; }   int n, s[110], m, team[110], dp[20][1 << 20];   char op[110];   bool vis[20][1 << 20];   int go(int mi, int ban) {     if (mi == m) return 0;     int &ret = dp[mi][ban];     if (vis[mi][ban]) return ret;     vis[mi][ban] = 1;     ret = -514514514;     for (int i = 0; i < (int)(n); i++)       if (!bit(ban, i)) {         int now = go(mi + 1, ban | two(i));         int str = (op[mi] ==  p  ? s[i] : 0);         if (mi + 1 < m && team[mi + 1] != team[mi])           now = str - now;         else           now = str + now;         ret = max(ret, now);       }     return ret;   }   int main() {     scanf( %d , &(n));     for (int i = 0; i < (int)(n); i++) scanf( %d , &(s[i]));     scanf( %d , &(m));     for (int i = 0; i < (int)(m); i++) scanf(  %c %d , op + i, team + i);     sort(s, s + n, greater<int>());     n = m;     int ans = go(0, 0);     if (team[0] == 2) ans *= -1;     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int a[3], ans;     cin >> a[0] >> a[1] >> a[2];     sort(a, a + 3);     ans = (a[1] - a[0]) + (a[2] - a[1]);     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, numero;     cin >> n;     if (n < 10)       cout << n;     else {       n -= 9;       if (n < 181) {         if (n % 2 == 0) {           n /= 2;           n -= 1;           n %= 10;           cout << n;         } else {           n = (n + 1) / 2;           cout << ((n - 1) / 10) + 1;         }       } else {         n -= 180;         numero = ((n - 1) / 3) + 1;         numero += 99;         n = n % 3;         switch (n) {           case 0:             cout << numero % 10;             break;           case 1:             cout << numero / 100;             break;           default:             cout << (numero % 100) / 10;             break;         }       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, p[3000], k, m = 0, c;   int main() {     cin >> n;     for (int i = 1; i <= n; i++) cin >> p[i];     for (int i = 1; i <= n; i++) {       k = p[i];       c = 1;       while (k > 0) {         c++;         k = p[k];       }       m = max(c, m);     }     cout << m;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     char st[200010];     cin >> n >> st;     queue<int> d, r;     for (int i = 0; i < n; i++) {       if (st[i] ==  D )         d.push(i);       else         r.push(i);     }     while (!r.empty() && !d.empty()) {       int R = r.front(), D = d.front();       if (R < D) {         r.pop();         d.pop();         r.push(n + R);       } else {         d.pop();         r.pop();         d.push(n + D);       }     }     if (!r.empty())       cout <<  R  << endl;     else       cout <<  D  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long w, h;     cin >> w >> h;     long long res = 0;     if (w == 1 || h == 1) {       cout <<  0  << endl;       return 0;     }     for (long long i = 1; i < h; i++) {       for (long long j = 1; j < w; j++) res += min(i, h - i) * min(j, w - j);     }     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     ;     long long n, k;     cin >> n >> k;     priority_queue<long long, vector<long long>, greater<long long>> priq;     long long cur = 0, co = 0;     map<long long, long long> ma;     while (n > 0) {       if (n % 2) {         ma[cur]++;         co++;       }       n /= 2;       cur++;     }     if (co > k) {       cout <<  No  << endl;       return 0;     }     for (long long i = 63; i >= -63; i--) {       long long temp = ma[i] + co;       if (temp <= k) {         co += ma[i];         ma[i - 1] += (2 * ma[i]);         ma[i] = 0;       } else {         break;       }     }     for (long long i = 63; i >= -63; i--)       for (long long j = 0; j < ma[i]; j++) {         priq.push(i);       }     while (priq.size() < k) {       long long x = priq.top();       priq.pop();       priq.push(x - 1);       priq.push(x - 1);     }     vector<long long> ans;     cout <<  Yes  << endl;     while (!priq.empty()) {       long long x = priq.top();       ans.push_back(x);       priq.pop();     }     sort(ans.begin(), ans.end(), greater<long long>());     for (long long i = 0; i < ans.size(); i++) cout << ans[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string start[1791791];   string fin[1791791];   pair<int, int> diffs[1791791];   int is_in(string a, string b) {     string s = a +  #  + b;     int n = (int)s.length();     vector<int> pi(n);     for (int i = 1; i < n; ++i) {       int j = pi[i - 1];       while (j > 0 && s[i] != s[j]) j = pi[j - 1];       if (s[i] == s[j]) ++j;       pi[i] = j;     }     for (int i = (int)a.length(); i < pi.size(); ++i) {       if (pi[i] == a.length()) {         return i - 2 * (int)a.length();       }     }     return -1;   }   int main() {     ios_base::sync_with_stdio(0);     int n;     cin >> n;     for (int i = 0; i < n; ++i) {       cin >> start[i];     }     for (int i = 0; i < n; ++i) {       cin >> fin[i];     }     for (int i = 0; i < n; ++i) {       int first_diff = -1;       for (int ii = 0; ii < start[i].length(); ++ii) {         if (start[i][ii] != fin[i][ii]) {           first_diff = ii;           break;         }       }       int last_diff = -1;       for (int ii = 0; ii < start[i].length(); ++ii) {         if (start[i][ii] != fin[i][ii]) {           last_diff = ii;         }       }       diffs[i] = {first_diff, last_diff};     }     int one_with_diff = -1;     for (int i = 0; i < n; ++i) {       if (diffs[i].first != -1) {         one_with_diff = i;         break;       }     }     for (int i = 0; i < n; ++i) {       if (diffs[i].first != -1 && diffs[one_with_diff].first != -1 &&           i != one_with_diff) {         if (diffs[i].second - diffs[i].first !=             diffs[one_with_diff].second - diffs[one_with_diff].first) {           cout <<  NO ;           return 0;         }         for (int ii = 0; ii <= diffs[i].second - diffs[i].first; ++ii) {           if (start[i][diffs[i].first + ii] !=                   start[one_with_diff][diffs[one_with_diff].first + ii] ||               fin[i][diffs[i].first + ii] !=                   fin[one_with_diff][diffs[one_with_diff].first + ii]) {             cout <<  NO ;             return 0;           }         }       }     }     int same_pref_len = 0;     for (int pref_len = 1;; ++pref_len) {       char pref =  # ;       bool ok = 1;       for (int i = 0; i < n; ++i) {         if (diffs[i].first != -1) {           if (diffs[i].first < pref_len) {             ok = 0;             break;           }           if (pref ==  # ) {             pref = start[i][diffs[i].first - pref_len];           } else {             if (pref != start[i][diffs[i].first - pref_len]) {               ok = 0;               break;             }           }         }       }       if (!ok) {         break;       }       same_pref_len += 1;     }     int same_suff_len = 0;     for (int suff_len = 1;; ++suff_len) {       char suff =  # ;       bool ok = 1;       for (int i = 0; i < n; ++i) {         if (diffs[i].first != -1) {           if (diffs[i].second + suff_len >= start[i].length()) {             ok = 0;             break;           }           if (suff ==  # ) {             suff = start[i][diffs[i].second + suff_len];           } else {             if (suff != start[i][diffs[i].second + suff_len]) {               ok = 0;               break;             }           }         }       }       if (!ok) {         break;       }       same_suff_len += 1;     }     string from, to;     for (int i = 0; i < n; ++i) {       if (diffs[i].first != -1) {         from =   ;         for (int j = diffs[i].first - same_pref_len;              j <= diffs[i].second + same_suff_len; ++j) {           from += start[i][j];         }         to =   ;         for (int j = diffs[i].first - same_pref_len;              j <= diffs[i].second + same_suff_len; ++j) {           to += fin[i][j];         }         break;       }     }     for (int i = 0; i < n; ++i) {       if (diffs[i].first == -1) {         if (is_in(from, start[i]) != -1) {           cout <<  NO ;           return 0;         }       } else {         if (is_in(from, start[i]) != diffs[i].first - same_pref_len) {           cout <<  NO ;           return 0;         }       }     }     cout <<  YES  << endl;     cout << from << endl;     cout << to << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   int dist[10010], DD[30][30];   int s[10010];   vector<int> all;   vector<int> a;   queue<int> q;   int dp[1 << 20];   int n;   void calc(int x) {     memset(dist, -1, sizeof(dist));     q.push(x), dist[x] = 0;     while (!q.empty()) {       int x = q.front();       q.pop();       for (int i = 0; i < all.size(); i++) {         int del = all[i];         if (x - del > 0 && dist[x - del] == -1) {           dist[x - del] = dist[x] + 1;           q.push(x - del);         }         if (x + del <= n + 1 && dist[x + del] == -1) {           dist[x + del] = dist[x] + 1;           q.push(x + del);         }       }     }   }   void chmin(int &x, int y) { x = min(x, y); }   int main() {     int k, l;     scanf( %d%d%d , &n, &k, &l);     for (int i = 0; i < k; i++) {       int x;       scanf( %d , &x);       s[x] = 1;     }     while (l--) {       int x;       scanf( %d , &x);       all.push_back(x);     }     for (int i = n + 1; i >= 1; i--) {       s[i] ^= s[i - 1];     }     for (int i = 1; i <= n + 1; i++) {       if (s[i]) a.push_back(i);     }     for (int i = 0; i < a.size(); i++) {       int x = a[i];       calc(x);       for (int j = 0; j < a.size(); j++) {         DD[i][j] = dist[a[j]];       }     }     int N = a.size();     memset(dp, 0x3f, sizeof(dp));     dp[0] = 0;     for (int mask = 0; mask < (1 << N) - 1; mask++) {       if (dp[mask] == INF) continue;       int x = 0;       while (mask >> x & 1) x++;       for (int y = x + 1; y < N; y++) {         if (mask >> y & 1) continue;         if (DD[x][y] == -1) continue;         chmin(dp[mask | 1 << x | 1 << y], dp[mask] + DD[x][y]);       }     }     printf( %d n , dp[(1 << N) - 1] == INF ? -1 : dp[(1 << N) - 1]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct debugger {     template <typename T>     debugger& operator,(const T& v) {       cerr << v <<    ;       return *this;     }   } dbg;   int inf = (1 << 20);   int dp[(1 << 21) + 10];   void F(int x, int y) {     x += inf;     y += inf;     dp[x]++;     if (x == y) return;     dp[y]++;     while (x / 2 != y / 2) {       if (x % 2 == 0) dp[x + 1]++;       if (y % 2 == 1) dp[y - 1]++;       x /= 2;       y /= 2;     }     return;   }   int ar[400010];   int n, k;   int func(int x) {     int sm = 0;     x += inf;     while (x > 1) {       sm += dp[x];       x /= 2;     }     return sm;   }   int chk(int x) {     int sm = 0;     for (int i = x; i <= ar[n - 1]; i += x) sm += func(i);     if (sm == n) return 1;     return 0;   }   int main() {     cin >> n >> k;     for (int i = (0), _n = (n); i < _n; i++) cin >> ar[i];     sort(ar, ar + n);     if (ar[0] <= k) {       cout << ar[0] << endl;       return 0;     }     for (int i = (0), _n = (n); i < _n; i++) F(ar[i] - k, ar[i]);     int rs = k;     for (int i = (2), _n = (ar[0]); i <= _n; i++)       if (chk(i)) rs = i;     cout << rs << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t, n, i, j, k, tmp;     int a, b, c;     cin >> a >> b >> c;     int p;     if ((c - b + a) % 2 != 0) {       printf( Impossible n );       return 0;     }     p = (c - b + a) / 2;     int count1 = 0;     if (p == 0) {       count1++;     }     if (a - p == 0) {       count1++;     }     if (b - (a - p) == 0) {       count1++;     }     if (p >= 0 && a - p >= 0 && b - (a - p) >= 0 && count1 <= 1) {       cout << a - p <<     << b - (a - p) <<     << p << endl;     } else {       printf( Impossible n );     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n, k;     cin >> n >> k;     map<int, int> m;     int c[7000][2];     int a[n + 1];     int b[n + 1];     int mx;     for (int i = 0; i < n; i++) {       cin >> a[i];       m[a[i]]++;       mx = max(mx, m[a[i]]);     }     if (mx > k) {       cout <<  NO  << endl;       return 0;     }     int x = 0;     for (auto i : m) {       c[i.first][0] = x;       x = x + i.second;     }     cout <<  YES  << endl;     for (int i = 0; i < n; i++) {       cout << (c[a[i]][0] % k) + 1 <<    ;       c[a[i]][0]++;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     double n, m, a, b, x = 1000000, y;     cin >> n >> m;     while (n--) {       cin >> a >> b;       y = a / b;       x = min(x, y);     }     printf( %.8lf n , m * x);   }


#include <bits/stdc++.h>   using namespace std;   long long bigmod(long long p, long long e, long long M) {     long long ret = 1;     for (; e > 0; e >>= 1) {       if (e & 1) ret = (ret * p) % M;       p = (p * p) % M;     }     return ret;   }   long long extended(long long a, long long b, long long &x, long long &y) {     a = abs(a);     b = abs(b);     long long g, x1, y1;     if (!b) {       x = 1;       y = 0;       g = a;       return g;     }     g = extended(b, a % b, x1, y1);     x = y1;     y = x1 - (a / b) * y1;     return g;   }   long long modinverse(long long a, long long M) { return bigmod(a, M - 2, M); }   long long bpow(long long p, long long e) {     long long ret = 1;     for (; e > 0; e >>= 1) {       if (e & 1) ret = (ret * p);       p = (p * p);     }     return ret;   }   int toInt(string s) {     int sm;     stringstream ss(s);     ss >> sm;     return sm;   }   int toLlint(string s) {     long long int sm;     stringstream ss(s);     ss >> sm;     return sm;   }   string convertInt(long long number) {     if (number == 0) return  0 ;     string temp =   ;     string returnvalue =   ;     while (number > 0) {       temp += number % 10 + 48;       number /= 10;     }     for (int i = 0; i < temp.length(); i++)       returnvalue += temp[temp.length() - i - 1];     return returnvalue;   }   long long ncr[1001][1001];   void NCR() {     for (int i = 1; i <= 1000; i++) {       ncr[i][i] = 1;       ncr[i][0] = 1;       for (int r = 1; r < i; r++) {         ncr[i][r] = (ncr[i - 1][r] + ncr[i - 1][r - 1]) % 1000000007;       }     }   }   vector<int> vec[100009];   long long n;   long long dp[100005][2], ar[100009];   void dfs(int V, int pv) {     dp[V][0] = 1 - ar[V];     dp[V][1] = ar[V];     for (int i = 0; i < vec[V].size(); i++) {       long long old[2];       memset(old, 0, sizeof(old));       int v = vec[V][i];       if (v == pv) continue;       old[0] = dp[V][0];       old[1] = dp[V][1];       dp[V][0] = dp[V][1] = 0;       dfs(v, V);       dp[V][0] += (old[0] * dp[v][1]) % 1000000007;       dp[V][1] += (old[1] * dp[v][1]) % 1000000007;       dp[V][1] += (old[1] * dp[v][0]) % 1000000007;       dp[V][1] += (old[0] * dp[v][1]) % 1000000007;       dp[V][0] += (old[0] * dp[v][0]) % 1000000007;     }   }   int main() {     cin >> n;     for (int i = 1; i < n; i++) {       int v;       cin >> v;       vec[i].push_back(v);       vec[v].push_back(i);     }     for (int i = 0; i < n; i++) {       int val;       cin >> val;       ar[i] = val;     }     dfs(0, -1);     cout << dp[0][1] % 1000000007 << endl;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> prim;   const int N = 1e5 + 9;   int n, dp[10000], a[N];   bool v[100000];   int pos[100000];   void pre() {     for (int i = 2; i < 100000; i++)       if (!v[i]) {         prim.push_back(i);         pos[i] = prim.size() - 1;         int k = i << 1;         while (k < 100000) v[k] = 1, k += i;       }   }   int main() {     pre();     int ans = 1;     cin >> n;     for (int i = 1, now; i <= n; i++) {       cin >> now;       int org = now;       int tmp = 0;       for (int j = 0; j < 100; j++)         if (now % prim[j] == 0) {           while (now % prim[j] == 0) now /= prim[j];           tmp = max(tmp, dp[j] + 1);         }       if (now > 1) tmp = max(tmp, dp[pos[now]] + 1);       for (int j = 0; j < 100; j++)         if (org % prim[j] == 0) {           while (org % prim[j] == 0) org /= prim[j];           dp[j] = tmp;         }       if (org > 1) dp[pos[now]] = tmp;       ans = max(ans, tmp);     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int power(long long int a, long long int b) {     long long int res = 1;     a %= 1000000007;     assert(b >= 0);     for (; b; b >>= 1) {       if (b & 1) res = res * a % 1000000007;       a = a * a % 1000000007;     }     return res;   }   long long int modInverse(long long int a) { return power(a, 1000000007 - 2); }   const int N = 500023;   bool vis[N];   vector<int> adj[N];   void solve() {     long long int n, m;     cin >> n >> m;     string s;     cin >> s;     s =  &  + s;     map<long long int, long long int> repeat;     for (long long int i = 0; i < m; i++) {       long long int c;       cin >> c;       repeat[c]++;     }     long long int cnt[28] = {0};     long long int final[28] = {0};     for (int i = 1; i <= n; i++) {       cnt[s[i] -  a ]++;       final[s[i] -  a ]++;       for (int j = 0; j < 26; j++) {         final[j] += (cnt[j] * repeat[i]);       }     }     for (int i = 0; i < 26; i++) {       cout << final[i] <<    ;     }     cout <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int T = 1;     cin >> T;     int t = 0;     while (t++ < T) {       solve();     }     cerr <<  Time :   << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC          <<  ms n ;   }


#include <bits/stdc++.h>   using namespace std;   const long double EPS = 1e-9;   long double Dis(long long a, long long Y, long long b, long long YY) {     return sqrt((long double)(b - a) * (b - a) + (Y - YY) * (Y - YY));   }   struct PT {     long long ID;     long double len, Y;     PT(long long _ID, long double _Y) {       ID = _ID;       Y = _Y;     }     bool operator<(const PT &a) const { return (Y < a.Y); }   };   vector<PT> A, B;   void BinSearch(vector<PT> &C, long double val, long long &low, long long &up) {     long long i, med;     up = C.size() - 1;     low = 0;     if (val >= C[up].Y) {       low = max(up - 1, low);       return;     }     if (val <= C[low].Y) {       up = min(low + 1, up);       return;     }     while ((up - low) > 1) {       med = (up + low) / 2;       if (C[med].Y < val)         low = med;       else         up = med;     }   }   int main() {     long long i, n, m, a, b, temp;     cin >> n >> m >> a >> b;     for (i = 0; i < n; i++) {       cin >> temp;       A.push_back(PT(i + 1, temp));       A[i].len = Dis(0, 0, a, temp);     }     for (i = 0; i < m; i++) {       cin >> temp;       B.push_back(PT(i + 1, temp));     }     for (i = 0; i < m; i++) {       cin >> temp;       B[i].len = temp;     }     sort(A.begin(), A.end());     sort(B.begin(), B.end());     long long ind1, ind2;     long double ans, tmp1, tmp2, mini, tt;     long long l, u;     ans = 1e18;     for (i = 0; i < m; i++) {       tt = ((long double)a * B[i].Y) / ((long double)(b));       BinSearch(A, tt, l, u);       tmp1 = Dis(a, A[u].Y, b, B[i].Y) + A[u].len;       tmp2 = Dis(a, A[l].Y, b, B[i].Y) + A[l].len;       mini = min(tmp1, tmp2);       if (ans > (B[i].len + mini)) {         if ((tmp1 < tmp2))           ind1 = A[u].ID, ans = B[i].len + tmp1;         else           ind1 = A[l].ID, ans = B[i].len + tmp2;         ind2 = B[i].ID;       }     }     cout << ind1 <<     << ind2 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 4000 + 10, MOD = (int)1e9 + 9;   int n, m, b, w, f[MAXN][MAXN];   int main() {     cin >> n >> w >> b;     m = max(b, w);     f[0][0] = 1;     for (int i = 1; i <= m; ++i) {       for (int j = 1; j <= i; ++j)         f[i][j] = ((long long)f[i - 1][j] * (j + i - 1) +                    (long long)f[i - 1][j - 1] * j) %                   MOD;     }     int Tohka = 0;     for (int i = 1; i <= min(b, n - 2); ++i)       Tohka = ((long long)Tohka +                (long long)f[w][n - i] * f[b][i] % MOD * (n - i - 1)) %               MOD;     cout << Tohka << endl;     fclose(stdin);     fclose(stdout);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline void read(long long &x) {     long long f = 1;     x = 0;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) f = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       x = x * 10 + c -  0 ;       c = getchar();     }     x *= f;   }   long long fa[200005][21], lg[2 * 200005], deep[200005], dis[200005], w[200005],       t[200005], h[200005], head, n, ans[200005];   struct yyy {     long long to, z, w;     inline void add(long long x, long long y, long long W) {       to = y;       z = h[x];       h[x] = head;       w = W;     }   } a[200005 * 2];   inline void dfs2(long long x, long long pre) {     register long long i;     deep[x] = deep[pre] + 1;     fa[x][0] = pre;     for (i = 1; i <= lg[deep[x]]; i++) fa[x][i] = fa[fa[x][i - 1]][i - 1];     for (i = h[x]; i; i = a[i].z)       if (a[i].to != pre) dis[a[i].to] = dis[x] + a[i].w, dfs2(a[i].to, x);   }   inline void dfs(long long x, long long pre) {     register long long i;     for (i = h[x]; i; i = a[i].z)       if (a[i].to ^ pre) {         dfs(a[i].to, x);         t[x] += t[a[i].to];       }   }   inline void init() {     register long long i, j, k;     for (j = 1, k = 1; j <= n; j <<= 1, k++)       for (i = j; i < j * 2; i++) lg[i] = k;     dfs2(1, 0);   }   signed main() {     register long long i, j, x, y;     read(n);     for (i = 1; i <= n; i++) read(w[i]);     for (i = 2; i <= n; i++) {       read(x);       read(y);       a[++head].add(i, x, y);       a[++head].add(x, i, y);     }     init();     for (i = 2; i <= n; i++) {       x = i;       for (j = lg[deep[i]]; j >= 0; j--)         if (fa[x][j] && dis[i] - dis[fa[x][j]] <= w[i]) x = fa[x][j];       t[fa[x][0]]--;       t[fa[i][0]]++;     }     dfs(1, 0);     for (i = 1; i <= n; i++) printf( %lld  , t[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, x, a[200000];   long long bs(long long xx, long long yy, long long k) {     long long m = (xx + yy) / 2;     if (yy - xx <= 1) return xx;     if (a[m] <= k)       return bs(m, yy, k);     else       return bs(xx, m, k);   }   int main() {     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i];     sort(a, a + n);     x = 1;     for (int j = 0; j < 31; j++) {       for (int i = 0; i < n; i++) {         if (a[bs(0, n, a[i] - x)] == a[i] - x &&             a[bs(0, n, a[i] + x)] == a[i] + x) {           return cout << 3 << endl                       << a[i] - x <<     << a[i] <<     << a[i] + x,                  0;         }       }       x *= 2;     }     x = 1;     for (int j = 0; j < 31; j++) {       for (int i = 0; i < n; i++) {         if (a[bs(0, n, a[i] - x)] == a[i] - x) {           return cout << 2 << endl << a[i] - x <<     << a[i], 0;         }       }       x *= 2;     }     cout << 1 << endl << a[0];     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void fastIo() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);   }   int main() {     fastIo();     int q;     cin >> q;     while (q--) {       int n;       cin >> n;       string s;       cin >> s;       if (n == 1) {         cout <<  NO  << endl;       } else if (n == 2) {         if (s[0] >= s[1])           cout <<  NO  << endl;         else {           cout <<  YES  << endl;           cout <<  2  << endl;           cout << s[0] <<     << s[1] << endl;         }       } else {         cout <<  YES  << endl;         cout <<  2  << endl;         cout << s[0] <<    ;         for (int i = 1; i < n; i++) cout << s[i];         cout << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       string s1, s2;       cin >> s1 >> s2;       bool poss = true;       int change[20][20];       memset(change, 0, sizeof(change));       for (int i = 0; i < n; i++) {         if (s1[i] > s2[i])           poss = false;         else {           if (s1[i] != s2[i]) {             change[s1[i] - 97][s2[i] - 97]++;           }         }       }       if (!poss) {         cout << -1 << endl;         continue;       }       int steps = 0;       for (int i = 0; i < 19; i++) {         int x = -1;         for (int j = 1; j < 20; j++) {           if (change[i][j] > 0) {             steps++;             x = j;             break;           }         }         if (x != -1) {           for (int j = x + 1; j <= 20; j++) {             change[x][j] += change[i][j];           }         }       }       cout << steps << endl;     }   }


#include <bits/stdc++.h>   const int inf = 1e9;   const double eps = 1e-9;   const int mod = 1e9 + 7;   using namespace std;   int mypow(int x, int y) {     int res = 1;     for (; y >= 1; y >>= 1) {       if (y & 1) res = (1ll * res * x) % mod;       x = (1ll * x * x) % mod;     }     return res;   }   int32_t main() {     long long n;     int k;     cin >> n >> k;     vector<long long> p;     vector<int> al;     long long x = n;     for (long long i = 2; i * i <= x; ++i) {       if (!(x % i)) {         p.push_back(i);         al.push_back(0);       }       int c = 0;       while (!(x % i)) {         al[al.size() - 1]++;         x /= i;       }     }     if (x != 1) {       p.push_back(x);       al.push_back(1);     }     int ans = 1;     for (int o = 0; o < p.size(); ++o) {       vector<vector<int>> dp(k + 1, vector<int>(al[o] + 1, 0));       dp[0][al[o]] = 1;       for (int i = 1; i <= k; ++i) {         for (int j = 0; j <= al[o]; ++j) {           int s = (1ll * dp[i - 1][j] * mypow(j + 1, mod - 2)) % mod;           for (int h = 0; h <= j; ++h) {             dp[i][h] = (dp[i][h] + s) % mod;           }         }       }       int l = 0;       int r = 1;       for (int j = 0; j <= al[o]; ++j) {         l = (l + (1ll * dp[k][j] * r) % mod) % mod;         r = (1ll * r * (p[o] % mod)) % mod;       }       ans = (1ll * ans * l) % mod;     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   bool local = false;   using namespace std;   template <class T>   string toString(T x) {     ostringstream sout;     sout << x;     return sout.str();   }   template <class T>   void print(T v) {     cout << ((int)(v).size()) <<   n ;     for (auto x : v) cout << x <<    ;     cout <<   n ;   };   template <class T1, class T2>   ostream &operator<<(ostream &o, pair<T1, T2> x) {     return o << x.first <<     << x.second;   }   template <class T1, class T2>   istream &operator>>(istream &o, pair<T1, T2> &x) {     return o >> x.first >> x.second;   }   template <class T1, class T2>   pair<T1, T2> operator+(pair<T1, T2> a, pair<T1, T2> b) {     a.first += b.first;     a.second += b.second;     return a;   }   template <class T1, class T2>   pair<T1, T2> operator-(pair<T1, T2> a, pair<T1, T2> b) {     a.first -= b.first;     a.second -= b.second;     return a;   }   template <class T1, class T2>   void operator+=(pair<T1, T2> &a, pair<T1, T2> b) {     a.first += b.first;     a.second += b.second;   }   template <class T1, class T2>   void operator-=(pair<T1, T2> &a, pair<T1, T2> b) {     a.first -= b.first;     a.second -= b.second;   }   int nint() {     int x;     cin >> x;     return x;   }   double getTime() { return clock() / (double)CLOCKS_PER_SEC; };   mt19937 rnd(0);   int rand(int n) { return rnd() % n; }   int rand(int l, int r) { return rnd() % (r - l + 1) + l; }   const int mod = 1000000000 + 7;   void initIO() {     if (local) {       freopen( input.txt ,  r , stdin);       srand((int)time(0));       rnd.seed((int)time(0));     } else {     }     {       ios::sync_with_stdio(0);       cin.tie(0);       cout.tie(0);     };   }   int m;   int n;   vector<pair<int, int> > v;   vector<int> v1, v2;   const int K = 19;   bool f(pair<int, int> a, pair<int, int> b) {     if (a.first != b.first) return a.first < b.first;     return a.second > b.second;   }   vector<pair<int, int> > update(vector<pair<int, int> > v) {     vector<pair<int, int> > ans;     ans.emplace_back(v[0]);     for (int i = 1; i < ((int)(v).size()); i++) {       pair<int, int> x = ans.back();       pair<int, int> y = v[i];       if (y.second <= x.second) continue;       ans.emplace_back(y);     }     return ans;   }   int get(int x) {     int p = upper_bound(v1.begin(), v1.end(), x) - v1.begin() - 1;     if (p == -1) return -1;     return p;   }   int ne[K + 1][200500];   void calc() {     for (int i = 0; i < (n); i++) ne[0][i] = i;     for (int t = 1; t < K; t++) {       for (int i = 0; i < (n); i++) {         int x = v2[ne[t - 1][i]];         int id = get(x);         x = ne[t - 1][id];         ne[t][i] = x;       }     }   }   int getans(int x, int y) {     int p = get(x);     if (p == -1) return -1;     int ans = 1;     for (int i = K - 1; i > 0; i--) {       while (1) {         int np = ne[i][p];         if (p == np) break;         if (v2[np] < y) {           p = np;           ans += (1 << i) - 1;         } else           break;       }     }     if (v2[p] < y) {       p = ne[1][p];       ans++;     }     if (v[p].second < y) return -1;     return ans;   }   int main() {     initIO();     cin >> n >> m;     for (int i = 0; i < (n); i++) {       int l, r;       cin >> l >> r;       v.emplace_back(l, r);     }     sort(v.begin(), v.end(), f);     v = update(v);     n = ((int)(v).size());     for (int i = 0; i < (n); i++) {       v1.emplace_back(v[i].first);       v2.emplace_back(v[i].second);     };     ;     ;     ;     calc();     for (int i = 0; i < (m); i++) {       int l, r;       cin >> l >> r;       cout << getans(l, r) <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   map<long long, map<long long, long long, greater<long long>>> comp;   map<long long, long long, greater<long long>> Add(long long x) {     if (x == 0) return {};     if (comp.count(x)) return comp[x];     long long choose = (x - 1) / 2;     long long diff = min(choose + 1, x - choose);     map<long long, long long, greater<long long>> ret = {{diff, 1}};     for (long long xp : {choose, x - choose - 1})       for (auto p : Add(xp)) ret[p.first] += p.second;     return comp[x] = ret;   }   long long Solve(long long x, long long seek, long long& cnt) {     long long choose = (x - 1) / 2;     long long diff = min(choose + 1, x - choose);     if (diff == seek) {       return choose + cnt;     }     long long ret = 0;     for (long long xp : {choose, x - choose - 1}) {       long long now = Add(xp)[seek];       if (now > cnt) {         return ret + Solve(xp, seek, cnt);       }       cnt -= now;       ret += choose + 1;     }     assert(false);   }   int32_t main() {     long long n, k;     cin >> n >> k;     if (k == 1) {       cout << 1 << endl;       return 0;     }     if (k == 2) {       cout << n << endl;       return 0;     }     n -= 2;     k -= 3;     for (auto p : Add(n)) {       if (p.second > k) {         cout << 2 + Solve(n, p.first, k) << endl;         return 0;       }       k -= p.second;     }     assert(false);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   void smax(T &a, T b) {     if (a < b) a = b;   }   const double EPS = 1e-9;   vector<pair<pair<int, int>, int> > adj[100000 + 10];   long long totSum;   pair<pair<int, int>, int> edges[100000 + 10];   int belows[100000 + 10];   int n;   pair<long long, int> f(int u, int jad) {     long long sum = 0;     int cnts = 0;     for (int i = 0; i < ((int)(adj[u]).size()); ++i) {       int v = adj[u][i].first.first;       int cost = adj[u][i].first.second;       int edge = adj[u][i].second;       if (v == jad) {         continue;       }       pair<long long, int> temp = f(v, u);       int cnt = temp.second;       long long belowSum = temp.first + (long long)cost * cnt;       belows[edge] = cnt;       totSum += cnt * sum;       totSum += cnts * belowSum;       sum += belowSum;       cnts += cnt;     }     cnts++;     totSum += sum;     return make_pair(sum, cnts);   }   inline long long getDollarBabe(long long temp) { return temp * (n - temp); }   int main(int argc, char const *argv[]) {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> n;     for (int i = 0; i < n - 1; ++i) {       int u, v, len;       cin >> u >> v >> len;       if (u > v) {         swap(u, v);       }       u--;       v--;       adj[u].push_back(make_pair(make_pair(v, len), i));       adj[v].push_back(make_pair(make_pair(u, len), i));       edges[i] = make_pair(make_pair(u, v), len);     }     totSum = 0;     f(0, -1);     int q;     cin >> q;     while (q--) {       int r, w;       cin >> r >> w;       r--;       int temp = belows[r];       totSum -= (edges[r].second - w) * getDollarBabe(temp);       edges[r].second = w;       cout << fixed << setprecision(8)            << (double)totSum * 6 / ((long long)(n) * (n - 1)) << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007;   int main() {     int n, m;     scanf( %d %d , &n, &m);     string S;     set<int> H[n];     set<int> V[m];     for (int i = 0; i < (n); i++) {       cin >> S;       for (int j = 0; j < (m); j++)         if (S[j] !=  . ) {           int t = S[j] -  0 ;           int h = (t <= 2);           int v = (t == 1 || t == 4);           H[i].insert((h + j) % 2);           V[j].insert((v + i) % 2);         }     }     bool good = true;     int cnt = m + n;     for (int i = 0; i < (n); i++) {       if (H[i].size() > 1)         good = 0;       else if (H[i].size())         --cnt;     }     for (int j = 0; j < (m); j++) {       if (V[j].size() > 1)         good = 0;       else if (V[j].size())         --cnt;     }     if (good) {       int ans = 1;       for (int i = 0; i < (cnt); i++) {         ans += ans;         ans %= 1000003;       }       cout << ans << endl;     } else       cout << 0 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n;     cin >> n;     cin.ignore();     while (n--) {       string str1, str2;       getline(cin, str1);       getline(cin, str2);       bool test = true;       long long j = 0, i = 0;       char last_ch = str1[0];       while (j < str2.size() && i < str1.size()) {         if (str2[j] == str1[i])           last_ch = str1[i], i++, j++;         else if (str2[j] == last_ch) {           while (str2[j] == last_ch) j++;         } else {           test = false;           break;         }       }       while (j < str2.size()) {         if (str2[j] != last_ch) {           test = false;           break;         }         j++;       }       if (!test) {         cout <<  NO  << endl;         continue;       }       if (i < str1.size()) {         cout <<  NO  << endl;         continue;       }       cout <<  YES  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int II() {     int q;     scanf( %d , &q);     return q;   }   void solve() {     long long N, M;     cin >> N >> M;     long long ar[N + 10], br[N + 10], cr[N + 10];     for (long long i = 1; i <= N; i++) {       cin >> ar[i] >> br[i] >> cr[i];     }     long long mi = M, mx = M;     ar[0] = 0;     for (long long i = 1; i <= N; i++) {       long long q = ar[i] - ar[i - 1];       mi = max(mi - q, br[i]);       mx = min(mx + q, cr[i]);       if (mi > cr[i] or mx < br[i]) {         cout <<  NO  << endl;         return;       }     }     cout <<  YES  << endl;   }   int32_t main() {     long long tt;     cin >> tt;     long long cas = 1;     while (tt--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   void winter_is_coming() {     std::ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);   }   int main() {     void winter_is_coming();     long long a, b, dis, dis2, ans = 0;     cin >> a >> b;     dis = abs(a - b);     dis2 = dis / 2;     dis = dis - dis2;     ans = (dis * (dis + 1) / 2) + (dis2 * (dis2 + 1) / 2);     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, fa[100010], siz[100010];   double ans;   int getfa(int w) { return (w == fa[w]) ? w : fa[w] = getfa(fa[w]); }   struct edg {     int nx, ny, val;     bool operator<(const edg& e) const { return val > e.val; }   } a[100010];   int main() {     cin >> n >> m;     int b[100010];     long long tot = 0;     for (int i = 1; i <= n; i++) cin >> b[i];     for (int i = 0; i < m; i++) {       int x, y;       cin >> x >> y;       a[i] = (edg){x, y, min(b[x], b[y])};     }     sort(a, a + m);     for (int i = 1; i <= n; i++) fa[i] = i;     for (int i = 1; i <= n; i++) siz[i] = 1;     for (int i = 0; i < m; i++)       if (getfa(a[i].nx) ^ getfa(a[i].ny)) {         int x = a[i].nx, y = a[i].ny;         tot += (long long)a[i].val * siz[fa[x]] * siz[fa[y]];         siz[fa[x]] += siz[fa[y]];         fa[fa[y]] = fa[x];       }     ans = tot;     tot = (long long)n * (n - 1) / 2;     ans /= tot;     printf( %.06lf , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m, G[1005][1005], ans = 1000000000;   char str[1005][1005];   bool vis[1005][1005];   int dfs(int x, int y, int wx, int wy) {     vis[x][y] = true;     if ((G[x + wx - 1][y + wy] - G[x - 1][y + wy] - G[x + wx - 1][y + 1 - 1] +          G[x - 1][y + 1 - 1]) == wx * wy)       return wx + dfs(x, y + 1, wx, wy);     if ((G[x + wx][y + wy - 1] - G[x + 1 - 1][y + wy - 1] - G[x + wx][y - 1] +          G[x + 1 - 1][y - 1]) == wx * wy)       return wy + dfs(x + 1, y, wx, wy);     return 0;   }   int main() {     memset(vis, false, sizeof(vis));     scanf( %d%d n , &n, &m);     int flag = 0, px, py;     for (int i = 1; i <= n; i++) scanf( %s , str[i] + 1);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) {         if (str[i][j] ==  X ) {           if (!flag) {             flag = 1;             px = i;             py = j;           }           G[i][j] = G[i - 1][j] + G[i][j - 1] - G[i - 1][j - 1] + 1;         } else           G[i][j] = G[i - 1][j] + G[i][j - 1] - G[i - 1][j - 1];       }     int tmp, wx, wy;     for (tmp = px; str[tmp][py] ==  X ; tmp++)       ;     wx = tmp - px;     for (int i = py; str[px][i] ==  X ; i++)       if (dfs(px, py, wx, i - py + 1) + wx * (i - py + 1) == G[n][m])         ans = min(ans, wx * (i - py + 1));     for (tmp = py; str[px][tmp] ==  X ; tmp++)       ;     wy = tmp - py;     for (int i = px; str[i][py] ==  X ; i++)       if (dfs(px, py, i - px + 1, wy) + (i - px + 1) * wy == G[n][m])         ans = min(ans, (i - px + 1) * wy);     if (ans <= n * m)       printf( %d n , ans);     else       printf( -1 n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     unsigned long long n;     unsigned long long a[100050];     unsigned long long b[200050];     scanf( %lld , &n);     for (int i = 0; i < n / 2; i++) scanf( %lld , &a[i]);     b[0] = 0;     b[n - 1] = a[0];     for (int i = 1; i < n / 2; i++) {       b[n - 1 - i] = min(b[n - i], a[i] - b[i - 1]);       b[i] = a[i] - b[n - 1 - i];     }     for (int i = 0; i < n; i++) printf( %lld  , b[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int arr[100] = {0}, con = 0, d = 0;     ;     string x;     cin >> x;     for (int i = 0; i < x.size(); i++) {       if (x[i] ==  + ) {         for (int j = 0; j < con; j++) {           arr[d] += (x[i - j - 1] - 48) * pow(10, j);         }         d++;         con = 0;       } else         con++;     }     for (int j = 0; j < con; j++) {       arr[d] += (x[x.size() - j - 1] - 48) * pow(10, j);     }     sort(arr, arr + d + 1);     for (int j = 0; j <= d; j++) {       if (j == d)         cout << arr[j];       else         cout << arr[j] <<  + ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(nullptr);     cout.tie(nullptr);     long long t;     cin >> t;     while (t--) {       vector<vector<long long> > a(2);       vector<long long> ans;       long long n;       string b;       cin >> n >> b;       long long cou = 1;       for (char c : b) {         long long x = c -  0 ;         if (a[x].size() == 0) a[x].push_back(cou++);         ans.push_back(a[x].back());         a[!x].push_back(a[x].back());         a[x].pop_back();       }       cout << cou - 1 <<   n ;       for (long long i : ans) cout << i <<    ;       cout <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int comp(long long a, long long b) { return a > b; }   long long arr[100000], cdf[100000];   int main() {     int i, m;     long long k, n;     cin >> n;     cin >> arr[0];     for (i = 1; i < n; i++) {       cin >> arr[i];     }     sort(arr, arr + n, comp);     cdf[0] = arr[0];     for (i = 1; i < n; i++) {       cdf[i] = arr[i] + cdf[i - 1];     }     cin >> m;     long long rrr = 0;     for (i = 1; i < n; i++) {       rrr += arr[i] * i;     }     int ll;     for (ll = 0; ll < m; ll++) {       cin >> k;       long long sum = 0LL;       if (k == 1)         cout << rrr <<    ;       else {         int mm;         long long as, t = 1;         for (as = 1, mm = 1; as < n; as = as + t, mm++) {           t *= k;           sum += (cdf[min(as + t - 1, n - 1)] - cdf[as - 1]) * mm;         }         cout << sum <<    ;       }     }     cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   namespace red {   inline long long read() {     long long x = 0;     char ch, f = 1;     for (ch = getchar(); (ch <  0  || ch >  9 ) && ch !=  - ; ch = getchar())       ;     if (ch ==  - ) f = 0, ch = getchar();     while (ch >=  0  && ch <=  9 ) {       x = (x << 1) + (x << 3) + ch -  0 ;       ch = getchar();     }     return f ? x : -x;   }   const long long N = 1e6 + 10, inf = 1e9 + 7, base = 131, mod = 1e9 + 7;   long long n, m, t, ret;   char a[N], b[N], s[N];   long long nxt[N], f[N], g[N];   long long pw[N], ha[N], hs[N];   inline void prepare(char *a, long long *f) {     long long len = max(n, m);     for (long long i = pw[0] = 1; i <= len; ++i) pw[i] = pw[i - 1] * base % mod;     for (long long i = 1; i <= n; ++i) ha[i] = (ha[i - 1] * base + a[i]) % mod;     for (long long i = 1; i <= m; ++i) hs[i] = (hs[i - 1] * base + s[i]) % mod;     for (long long i = 1; i <= n; ++i) {       long long l = i, r = n;       while (l <= r) {         long long t1 = (ha[((l + r) >> 1)] -                         ha[i - 1] * pw[((l + r) >> 1) - i + 1] % mod + mod) %                        mod;         long long t2 = hs[((l + r) >> 1) - i + 1];         if (t1 == t2)           f[i] = ((l + r) >> 1) - i + 1, l = ((l + r) >> 1) + 1;         else           r = ((l + r) >> 1) - 1;       }       f[i] = min(f[i], m - 1);     }   }   struct BIT {     long long tr[N];     BIT() { memset(tr, 0, sizeof(tr)); }     inline void update(long long p, long long k) {       for (p++; p < N; p += p & (-p)) tr[p] += k;     }     inline long long query(long long p) {       long long ret = 0;       for (p++; p; p -= p & (-p)) ret += tr[p];       return ret;     }   } bit[2];   inline void main() {     n = read(), m = read();     scanf( %s%s%s , a + 1, b + 1, s + 1);     prepare(a, f);     reverse(s + 1, s + m + 1);     reverse(b + 1, b + n + 1);     prepare(b, g);     reverse(g + 1, g + n + 1);     for (long long i = n; i; --i) {       bit[0].update(g[i], 1);       bit[1].update(g[i], g[i]);       if (i + m - 1 <= n) {         bit[0].update(g[i + m - 1], -1);         bit[1].update(g[i + m - 1], -g[i + m - 1]);       }       if (!f[i]) continue;       long long v = m - f[i];       ret += bit[1].query(m) - bit[1].query(v - 1);       ret -= (bit[0].query(m) - bit[0].query(v - 1)) * (v - 1);     }     printf( %lld n , ret);   }   }  // namespace red   signed main() {     red::main();     return 0;   }


#include <algorithm>   #include <cassert>   #include <iostream>   #include <queue>   #include <vector>   using namespace std;      typedef long long ll;   typedef pair<int, int> Pii;   typedef vector<Pii> VPii;   typedef vector<int> Vi;   typedef vector<Vi> VVi;   typedef vector<ll> Vll;   typedef vector<Vll> VVll;      const ll INF = 1000000000000000000LL;      Vi toposort(const VVi& g) {       int n = g.size();       Vi deg(n);       for (auto& others : g) {           for (int other : others) {               ++deg[other];           }       }          queue<int> q;       for (int i = 0; i < n; ++i) {           if (deg[i] == 0) {               q.push(i);           }       }          Vi result;       while (!q.empty()) {           int x = q.front();           q.pop();              result.push_back(x);              for (int other : g[x]) {               if (--deg[other] == 0) {                   q.push(other);               }           }       }       return result;   }      Vi findPath(int start, const VVi& rg, Vi& target, const VVi& ban) {       int n = rg.size();       VVi prev(2, Vi(n, -1));       prev[0][start] = start;          queue<Pii> q;       q.push(make_pair(0, start));          int finish = -1;          while (!q.empty()) {           int d = q.front().first;           int x = q.front().second;           q.pop();              if (d == 0) {               if (ban[0][x] == 1) {                   continue;               }               for (int y : rg[x]) {                   if (ban[1][y] == 1) {                       continue;                   }                   if (target[y] != x && prev[1][y] == -1) {                       prev[1][y] = x;                       q.push(make_pair(1, y));                   }               }           } else {               int y = target[x];               if (y == -1) {                   finish = x;                   break;               }                  if (prev[0][y] == -1) {                   prev[0][y] = x;                   q.push(make_pair(0, y));               }           }       }              if (finish == -1) {           return Vi();       }          Vi path;       for (int d = 1, x = finish; x != start; x = prev[d][x], d = 1 - d) {           path.push_back(x);       }       path.push_back(start);       reverse(path.begin(), path.end());       return path;   }      int minSeeds(const VVi& g, const VVi& rg, const VVi& ban) {       int n = g.size();       int seeds = 0;       Vi target(n, -1);       Vi order = toposort(g);       for (int x : order) {           auto path = findPath(x, rg, target, ban);           if (path.empty()) {               ++seeds;           }           assert(path.size() % 2 == 0);           for (int i = 0; i + 1 < path.size(); i += 2) {               int a = path[i];               int b = path[i + 1];               target[b] = a;           }       }       return seeds;   }      Pii nextBan(int currentSeeds, const VVi& g, const VVi& rg, VVi ban) {       int n = g.size();       for (int d = 0; d < 2; ++d) {           for (int x = 0; x < n; ++x) {               if (ban[d][x] == 1) {                   continue;               }               ban[d][x] = 1;               int t = minSeeds(g, rg, ban);               if (t == currentSeeds + 1) {                   return make_pair(d, x);               }               ban[d][x] = 0;           }       }       assert(false);   }      VPii optimalSequence(const VVi& g, const VVi& rg) {       int n = g.size();       VVi ban(2, Vi(n, 0));          int m = minSeeds(g, rg, ban);       VPii result;              for (int i = 0; i < n - m; ++i) {           auto t = nextBan(m + i, g, rg, ban);           result.push_back(t);           ban[t.first][t.second] = 1;       }          return result;   }      Vi optimalPattern(int initial, int n, VPii& cost) {       int k = cost.size();       VVll dp(k + 1, Vll(n + 1));       VVi next(k + 1, Vi(n + 1));       for (int r = k - 1; r >= 0; --r) {           for (int s = initial; s <= n; ++s) {               ll bestScore = 0;               int bestT = -1;               for (int t = max(s, r + 2); t <= n; ++t) {                   int c = t - s;                   ll score = max(0LL, cost[r].first - ll(c) * cost[r].second) + dp[r + 1][t];                   if (bestT == -1 || score > bestScore) {                       bestT = t;                       bestScore = score;                   }               }               dp[r][s] = bestScore;               next[r][s] = bestT;           }       }          Vi pattern;       for (int r = 0, s = initial; r < k; s = next[r][s], ++r) {           pattern.push_back(next[r][s] - s);       }       return pattern;   }      int main() {       int n, m, k;       cin >> n >> m >> k;          VVi g(n), rg(n);       for (int i = 0; i < m; ++i) {           int x, y;           cin >> x >> y;           --x; --y;           g[x].push_back(y);           rg[y].push_back(x);       }          VPii cost(k);       for (int i = 0; i < k; ++i) {           cin >> cost[i].first >> cost[i].second;       }          auto seq = optimalSequence(g, rg);       int initial = n - seq.size();          auto patt = optimalPattern(initial, n, cost);          Vi solution;       int used = 0;       for (int p : patt) {           for (int i = 0; i < p; ++i) {               auto s = seq[used++];               int sign = s.first == 0 ? -1 : 1;               solution.push_back(sign * (s.second + 1));           }           solution.push_back(0);       }          cout << solution.size() << endl;       for (int i = 0; i < solution.size(); ++i) {           if (i != 0) {               cout <<    ;           }           cout << solution[i];       }       cout << endl;   }


#include <bits/stdc++.h>   template <typename T>   inline void SWAP(T &a, T &b) {     T tmp = a;     a = b;     b = tmp;   }   template <typename T>   inline T ABS(const T &val) {     return val < 0 ? -val : val;   }   template <typename T>   inline T MAX(const T &a, const T &b) {     return a > b ? a : b;   }   template <typename T>   inline T MIN(const T &a, const T &b) {     return a < b ? a : b;   }   template <typename T>   inline T SQR(const T &a) {     return a * a;   }   const int INTinf = 2147483647;   const int nINTinf = 0 - 2147483648;   using namespace std;   int n;   char A[5005][5005];   bool was[5005];   bool bad[5005];   int CY[5005];   int kon = 0;   int POS = 0;   bool FF = false;   bool G = false;   void rec(const int &x) {     if (bad[x]) return;     if (was[x]) {       POS = x;       FF = true;     } else {       was[x] = true;       for (int i = 0; i != n; i++) {         if (A[x][i]) {           rec(i);           if (FF) {             if (!G) {               CY[kon++] = x;               if (POS == x) G = true;             }             return;           }         }       }       bad[x] = true;     }   }   int main() {     scanf( %d , &n);     for (int i = 0; i != n; i++) {       scanf( %s , A[i]);       for (int j = 0; j != n; j++) {         A[i][j] -=  0 ;       }     }     for (int i = 0; i != n; i++) {       if (!bad[i]) rec(i);       if (FF) break;     }     if (FF) {       reverse(CY, CY + kon);       int ST = CY[0];       for (int i = 2; i != kon; i++) {         if (A[CY[i]][ST]) {           cout << ST + 1 <<     << CY[i - 1] + 1 <<     << CY[i] + 1 << endl;           return 0;         }       }     } else {       cout << -1 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 1e3 + 7;   long long dp[N][N][11][2], n, m, k;   string s, t;   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> m >> k >> s >> t;     for (long long l = 1; l <= k; l++) {       for (long long i = 1; i <= n; i++) {         for (long long j = 1; j <= m; j++) {           if (s[i - 1] == t[j - 1])             dp[i][j][l][0] =                 1 + max(dp[i - 1][j - 1][l - 1][1], dp[i - 1][j - 1][l][0]);           dp[i][j][l][1] =               max(dp[i][j][l][0], max(dp[i - 1][j][l][1], dp[i][j - 1][l][1]));         }       }     }     cout << dp[n][m][k][1];   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long t;     cin >> t;     while (t--) {       long long p, f;       cin >> p >> f;       long long cnt1, cnt2;       cin >> cnt1 >> cnt2;       long long s, w;       cin >> s >> w;       if (s > w) {         swap(s, w);         swap(cnt1, cnt2);       }       long long ans = 0;       for (long long i = 0; i <= min(cnt1, p / s); i++) {         long long cnt = i;         long long tmpp = p - i * s;         cnt += (min(cnt2, tmpp / w));         long long tmpw = cnt2 - min(cnt2, tmpp / w), tmps = cnt1 - i;         cnt += min(tmps, f / s);         long long tmpf = f - min(tmps, f / s) * s;         cnt += min(tmpw, tmpf / w);         ans = max(ans, cnt);       }       cout << ans << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline void in(int &n) {     n = 0;     int ch = getchar();     int sign = 1;     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) sign = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       n = (n << 3) + (n << 1) + ch -  0 , ch = getchar();     }     n = n * sign;   }   pair<int, int> a[100005];   long long int Fsum[100005], Rsum[100005];   long long int solve(long long int val, int low, int up) {     int n = up;     while (low < up) {       int mid = low + (up - low) / 2;       if (a[mid].first >= val) {         low = mid + 1;       } else {         up = mid;       }     }     long long int ans = val * (n - low + 1) - Rsum[low];     return ans;   }   int res[100005];   int main() {     int n;     long long int A;     int Cf, Cm;     in(n);     cin >> A;     in(Cf);     in(Cm);     long long int m;     cin >> m;     for (int i = 1; i <= n; i++) {       in(a[i].first);       a[i].second = i;     }     sort(a + 1, a + 1 + n);     reverse(a + 1, a + 1 + n);     Fsum[0] = 0;     for (int i = 1; i <= n; i++) {       Fsum[i] = Fsum[i - 1] + a[i].first;     }     Rsum[n + 1] = 0;     for (int i = n; i >= 1; i--) {       Rsum[i] = Rsum[i + 1] + a[i].first;     }     long long int ans = 0;     int X, Y;     if (A * n - Fsum[n] <= m) {       ans = n * Cf + A * Cm;       X = n;       Y = A;     }     for (int i = 1; i <= n; i++) {       int low = a[n].first;       int up = A;       while (low < up) {         int mid = low + (up - low + 1) / 2;         long long int total = A * (i - 1) - Fsum[i - 1] + solve(mid, i, n);         if (total <= m) {           low = mid;         } else {           up = mid - 1;         }       }       long long int total = A * (i - 1) - Fsum[i - 1] + solve(low, i, n);       if (total <= m) {         long long int p = low;         p *= Cm;         long long int curr = (i - 1) * Cf + p;         if (curr >= ans) {           ans = curr;           X = i - 1;           Y = low;         }       }     }     for (int i = 1; i <= n; i++) {       if (i <= X) {         res[a[i].second] = A;       } else {         res[a[i].second] = max(a[i].first, Y);       }     }     printf( %I64d n , ans);     for (int i = 1; i <= n; i++) {       printf( %d  , res[i]);     }     printf(  n );   }


#include <bits/stdc++.h>   using namespace std;   template <typename T1, typename T2>   inline void chkmin(T1 &x, T2 y) {     if (x > y) x = y;   }   template <typename T1, typename T2>   inline void chkmax(T1 &x, T2 y) {     if (x < y) x = y;   }   inline int readChar();   template <class T = int>   inline T readInt();   template <class T>   inline void writeInt(T x, char end = 0);   inline void writeChar(int x);   inline void writeWord(const char *s);   static const int buf_size = 4096;   inline int getChar() {     static char buf[buf_size];     static int len = 0, pos = 0;     if (pos == len) {       pos = 0, len = fread(buf, 1, buf_size, stdin);     }     if (pos == len) {       return -1;     }     return buf[pos++];   }   inline int readChar() {     int c = getChar();     while (c <= 32) {       c = getChar();     }     return c;   }   template <class T>   inline T readInt() {     int s = 1, c = readChar();     T x = 0;     if (c ==  - ) s = -1, c = getChar();     while ( 0  <= c && c <=  9 ) x = x * 10 + c -  0 , c = getChar();     return s == 1 ? x : -x;   }   static int write_pos = 0;   static char write_buf[buf_size];   inline void writeChar(int x) {     if (write_pos == buf_size)       fwrite(write_buf, 1, buf_size, stdout), write_pos = 0;     write_buf[write_pos++] = x;   }   template <class T>   inline void writeInt(T x, char end) {     if (x < 0) writeChar( - ), x = -x;     char s[24];     int n = 0;     while (x || !n) s[n++] =  0  + x % 10, x /= 10;     while (n--) writeChar(s[n]);     if (end) writeChar(end);   }   inline void writeWord(const char *s) {     while (*s) writeChar(*s++);   }   struct Flusher {     ~Flusher() {       if (write_pos) fwrite(write_buf, 1, write_pos, stdout), write_pos = 0;     }   } flusher;   const string FILENAME =  input ;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     if (n & 1) {       cout << (n / 2 + 1) * (n / 2 + 1) << endl;     } else {       cout << (n / 2 + 1) * (n / 2) << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int read(int &x) { return scanf( %d , &x); }   int read(long long &x) { return scanf( %lld , &x); }   int read(double &x) { return scanf( %lf , &x); }   int read(int &x, int &y) { return scanf( %d%d , &x, &y); }   int read(long long &x, long long &y) { return scanf( %lld%lld , &x, &y); }   int read(double &x, double &y) { return scanf( %lf%lf , &x, &y); }   int read(int &x, int &y, int &z) { return scanf( %d%d%d , &x, &y, &z); }   int read(long long &x, long long &y, long long &z) {     return scanf( %lld%lld%lld , &x, &y, &z);   }   int read(double &x, double &y, double &z) {     return scanf( %lf%lf%lf , &x, &y, &z);   }   long long qpow(long long a, long long b, long long mod) {     if (a == 0) return 0;     long long ans = 1;     a %= mod;     while (b) {       if (b & 1) ans = ans * a % mod;       a = a * a % mod;       b >>= 1;     }     return ans % mod;   }   long long inv(long long x, long long mod) { return qpow(x, mod - 2, mod); }   int dir[4][2] = {0, 1, 0, -1, 1, 0, -1, 0};   int mon[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};   const int INF = 0x3f3f3f3f;   const int mod = 1e9 + 7;   const int N = 5e5 + 5;   struct DSU {     int f[N];     void init(int n) {       for (int i = 0; i <= n; i++) f[i] = i;     }     int fa(int x) { return f[x] == x ? x : f[x] = fa(f[x]); }     void join(int x, int y) {       x = fa(x);       y = fa(y);       if (x != y) f[x] = y;     }   };   struct CombMath {     long long C[2005][2005];     void init(int n) {       for (int i = 0; i <= n; i++) C[i][0] = 1;       for (int i = 1; i <= n; i++)         for (int j = 1; j <= n; j++)           C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % mod;     }   };   struct _2sat {     vector<int> G[N << 1];     int dfn[N << 1], low[N << 1], stk[N << 1], color[N << 1];     int t, tp, scc;     bool vis[N << 1];     void init(int n) {       for (int i = 0; i <= 2 * n; i++) G[i].clear();       for (int i = 0; i <= n * 2; i++) dfn[i] = low[i] = color[i] = vis[i] = 0;       t = tp = scc = 0;     }     void add(int x, int xv, int y, int yv) {       x = x * 2 + xv;       y = y * 2 + yv;       G[x ^ 1].push_back(y);       G[y ^ 1].push_back(x);     }     void addmaodun(int x, int xv, int y, int yv) {       x = x * 2 + (xv ^ 1);       y = y * 2 + (yv ^ 1);       G[x ^ 1].push_back(y);       G[y ^ 1].push_back(x);     }     void tarjan(int x) {       dfn[x] = low[x] = ++t;       stk[++tp] = x;       vis[x] = 1;       for (auto v : G[x]) {         if (!dfn[v]) {           tarjan(v);           low[x] = min(low[x], low[v]);         } else if (vis[v])           low[x] = min(low[x], dfn[v]);       }       if (low[x] == dfn[x]) {         color[x] = ++scc;         vis[x] = 0;         while (stk[tp] != x) {           color[stk[tp]] = scc;           vis[stk[tp--]] = 0;         }         tp--;       }     }     void work(int n) {       for (int i = 0; i < 2 * n; i++)         if (!dfn[i]) tarjan(i);       for (int i = 0; i < n; i++)         if (color[i * 2] == color[i * 2 + 1]) {           puts( -1 );           return;         }       vector<int> row, col;       for (int i = 0; i < n / 2; i++) {         if (color[i * 2] < color[i * 2 + 1]) {           continue;         } else {           row.push_back(i);         }       }       for (int i = n / 2; i < n; i++) {         if (color[i * 2] < color[i * 2 + 1]) {           continue;         } else {           col.push_back(i - n / 2);         }       }       int sz = row.size() + col.size();       printf( %d n , sz);       for (auto it : row) printf( row %d n , it);       for (auto it : col) printf( col %d n , it);     }   } twosat;   char s[N];   int a[2005];   int g[2005][2005];   signed main() {     int n;     read(n);     getchar();     for (int k = 1; k <= 2; k++) {       for (int i = 1; i <= n; i++) {         gets(s + 1);         for (int j = 1; j <= n; j++) {           g[i][j] ^= (s[j] -  0 );         }       }     }     twosat.init(2 * n);     gets(s + 1);     for (int i = 1; i <= n; i++) a[i] = s[i] -  0 ;     bool ok = 1;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         int n1 = a[i], n2 = a[j];         int ii = i - 1, jj = j + n - 1;         if (g[i][j] == 1) {           if (n1 == 1 and n2 == 1) {             twosat.G[ii * 2].push_back(jj * 2 + 1);             twosat.G[jj * 2].push_back(ii * 2 + 1);             twosat.G[ii * 2 + 1].push_back(jj * 2);             twosat.G[jj * 2 + 1].push_back(ii * 2);           } else if (n2 == 1) {             twosat.G[ii * 2].push_back(ii * 2 + 1);           } else if (n1 == 1) {             twosat.G[jj * 2].push_back(jj * 2 + 1);           } else {             ok = 0;           }         } else {           if (n1 == 1 and n2 == 1) {             twosat.G[ii * 2].push_back(jj * 2);             twosat.G[ii * 2 + 1].push_back(jj * 2 + 1);             twosat.G[jj * 2].push_back(ii * 2);             twosat.G[jj * 2 + 1].push_back(ii * 2 + 1);           } else if (n2 == 1) {             twosat.G[ii * 2 + 1].push_back(ii * 2);           } else if (n1 == 1) {             twosat.G[jj * 2 + 1].push_back(jj * 2);           } else {             continue;           }         }       }     }     if (!ok)       puts( -1 );     else {       twosat.work(n * 2);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   FILE *in;   FILE *out;   int n, m, k;   char a[64][64];   int blocks[64][64];   int cell[64 * 64][2];   int dyn[64 * 64][4][2];   int dir[4][2] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}};   void fill(int row, int col, int color) {     blocks[row][col] = color;     for (int i = 0; i < 4; i++) {       int nrow = row + dir[i][0];       if (nrow < 0 || nrow >= n) continue;       int ncol = col + dir[i][1];       if (ncol < 0 || ncol >= m) continue;       if (a[row][col] == a[nrow][ncol] && blocks[nrow][ncol] == -1)         fill(nrow, ncol, color);     }   }   void getBlocks() {     int nextColor = 0;     memset(blocks, -1, sizeof(blocks));     for (int i = 0; i < n; i++) {       for (int c = 0; c < m; c++) {         if (a[i][c] !=  0  && blocks[i][c] == -1) {           fill(i, c, nextColor);           cell[nextColor][0] = i;           cell[nextColor][1] = c;           nextColor++;         }       }     }   }   int main(void) {     in = stdin;     out = stdout;     fscanf(in,  %d %d , &n, &k);     for (int i = 0; i < n; i++) fscanf(in,  %s , a[i]);     m = (int)strlen(a[0]);     getBlocks();     memset(dyn, -1, sizeof(dyn));     int rem = k, cur = 0;     int bp = 0, dp = 1, cp = 0;     int foundCycle = 0;     while (rem) {       rem--;       cur++;       if (!foundCycle && dyn[bp][dp][cp] != -1) {         foundCycle = 1;         rem %= (cur - dyn[bp][dp][cp]);       }       dyn[bp][dp][cp] = cur;       int row = cell[bp][0], col = cell[bp][1];       while (1) {         int nrow = row + dir[dp][0];         if (nrow < 0 || nrow >= n) break;         int ncol = col + dir[dp][1];         if (ncol < 0 || ncol >= m) break;         if (a[nrow][ncol] != a[row][col]) break;         row = nrow;         col = ncol;       }       int dd = (cp ? ((dp + 1) % 4) : ((dp + 3) % 4));       while (1) {         int nrow = row + dir[dd][0];         if (nrow < 0 || nrow >= n) break;         int ncol = col + dir[dd][1];         if (ncol < 0 || ncol >= m) break;         if (a[nrow][ncol] != a[row][col]) break;         row = nrow;         col = ncol;       }       int nrow = row + dir[dp][0];       int ncol = col + dir[dp][1];       if (nrow >= 0 && nrow < n && ncol >= 0 && ncol < m &&           a[nrow][ncol] !=  0 ) {         bp = blocks[nrow][ncol];         continue;       }       if (cp == 0)         cp = 1;       else {         cp = 0;         dp = (dp + 1) % 4;       }     }     fprintf(out,  %c n , a[cell[bp][0]][cell[bp][1]]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 55, M = 105, T = 20005, K = 20;   const double S = 1e5, inf = 1e9, PI = acos(-1);   template <class T>   void read(T &x) {     int sgn = 1;     char ch;     x = 0;     for (ch = getchar(); (ch <  0  || ch >  9 ) && ch !=  - ; ch = getchar())       ;     if (ch ==  - ) ch = getchar(), sgn = -1;     for (;  0  <= ch && ch <=  9 ; ch = getchar()) x = x * 10 + ch -  0 ;     x *= sgn;   }   template <class T>   void write(T x) {     if (x < 0)       putchar( - ), write(-x);     else if (x < 10)       putchar(x +  0 );     else       write(x / 10), putchar(x % 10 +  0 );   }   int n, m, t;   double c, cost[M], dist[N], f[N][T], val[M][T];   complex<double> w[K][T << 3];   struct node {     int id, to;     vector<double> vec;   };   vector<node> g[N];   vector<int> h[N];   queue<int> q;   bool vis[N];   void spfa() {     for (int i = 1; i <= n; i++) dist[i] = inf, vis[i] = false;     dist[n] = true, q.push(n), dist[n] = 0.0;     while (!q.empty()) {       int u = q.front();       for (int i = 0; i < g[u].size(); i++) {         int v = g[u][i].to;         if (dist[v] > dist[u] + cost[g[u][i].id]) {           dist[v] = dist[u] + cost[g[u][i].id];           if (!vis[v]) vis[v] = true, q.push(v);         }       }       q.pop(), vis[u] = false;     }   }   void init() {     for (int i = 1, j = 0; i <= (t + 2 << 3); i <<= 1, j++) {       for (int k = 0; k <= i; k++)         w[j][k] = complex<double>(cos(2.0 * k * PI / i), sin(2.0 * k * PI / i));     }   }   int bitrev[T << 3];   void dft(complex<double> *x, int len, int ty) {     bitrev[0] = 0;     for (int i = 1; i < len; i++) {       bitrev[i] = bitrev[i >> 1] >> 1;       if (i & 1) bitrev[i] |= (len >> 1);     }     for (int i = 0; i < len; i++) {       if (bitrev[i] < i) swap(x[bitrev[i]], x[i]);     }     for (int i = 1, label = 1; i < len; i <<= 1, label++) {       for (int j = 0; j < len; j += (i << 1)) {         for (int k = 0; k < i; k++) {           complex<double> u = x[j + k], v = x[j + k + i];           complex<double> r = ty > 0 ? w[label][k] : w[label][(i << 1) - k];           x[j + k] = u + r * v, x[j + k + i] = u - r * v;         }       }     }     if (ty < 0) {       for (int i = 0; i < len; i++) x[i] /= len;     }   }   complex<double> tmp1[T << 3], tmp2[T << 3], tmp[T << 3];   void solve(int l, int r) {     int mid = l + r >> 1;     if (l < r) {       solve(mid + 1, r);       int l1 = r - mid, l2 = r - l, len = 1;       while (len <= l1 + l2) len <<= 1;       for (int i = 1; i <= n; i++) {         if (r - l <= 1000) {           for (int j = 0; j < g[i].size(); j++) {             for (int k = l; k <= mid; k++) {               for (int T = mid + 1 - k; T <= r - k; T++)                 val[g[i][j].id][k] += g[i][j].vec[T] * f[i][k + T];             }           }           continue;         }         for (int j = 0; j < len; j++) tmp1[j] = complex<double>(0.0, 0.0);         for (int j = 0; j < r - mid; j++)           tmp1[j] = complex<double>(f[i][mid + 1 + j], 0.0);         dft(tmp1, len, 1);         for (int j = 0; j < g[i].size(); j++) {           for (int k = 0; k < len; k++) tmp2[k] = complex<double>(0.0, 0.0);           for (int k = 0; k <= l2; k++)             tmp2[k] = complex<double>(g[i][j].vec[l2 - k], 0.0);           dft(tmp2, len, 1);           for (int k = 0; k < len; k++) tmp[k] = tmp1[k] * tmp2[k];           dft(tmp, len, -1);           for (int k = l; k <= mid; k++)             val[g[i][j].id][k] += tmp[k + l2 - mid - 1].real();         }       }       solve(l, mid);     } else {       for (int i = 1; i <= n; i++) {         for (int j = 0; j < h[i].size(); j++)           f[i][mid] = min(f[i][mid], val[h[i][j]][mid] + cost[h[i][j]]);       }     }   }   int main() {     read(n), read(m), read(t);     scanf( %lf , &c);     for (int i = 1; i <= m; i++) {       int u, v;       vector<double> vec(t + 1);       read(u), read(v);       scanf( %lf , &cost[i]);       for (int j = 1; j <= t; j++) {         int x;         read(x);         vec[j] = x / S;       }       node x = {i, u, vec};       g[v].push_back(x), h[u].push_back(i);     }     spfa();     for (int i = 1; i <= n; i++) f[i][t + 1] = dist[i] + c;     for (int i = 1; i <= n; i++) {       for (int j = 0; j <= t; j++) f[i][j] = (i == n) ? 0.0 : inf;     }     for (int i = 1; i <= m; i++) {       for (int j = 0; j <= t; j++) val[i][j] = 0.0;     }     for (int i = 1; i <= n; i++) {       for (int j = 0; j < g[i].size(); j++) {         double x = 0.0;         for (int k = 0; k <= t; k++)           val[g[i][j].id][k] += x * f[i][t + 1], x += g[i][j].vec[t - k];       }     }     init();     solve(0, t);     printf( %lf n , f[1][0]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   mt19937 prng(chrono::steady_clock::now().time_since_epoch().count());   void testCase(int caseno) {     int n, k, a, b;     cin >> n >> k;     multiset<int> aa;     multiset<int> bb;     int sum = 0;     for (int i = 0; i < n; i++) {       cin >> a;       sum += a;       aa.insert(a);     }     for (int i = 0; i < n; i++) {       cin >> b;       bb.insert(b);     }     for (int i : aa) {     }     for (int i : bb) {     }     int it = 0;     while (*(aa.begin()) < *(--bb.end()) && it < k) {       it++;       sum -= *(aa.begin());       sum += *(--bb.end());       aa.insert(*(--bb.end()));       bb.insert(*(aa.begin()));       auto ita = aa.begin();       auto itb = --bb.end();       aa.erase(ita);       bb.erase(itb);     }     cout << sum << endl;   }   int main() {     int t;     cin >> t;     for (int i = 0; i < t; i++) {       testCase(i + 1);     }     return 0;   }


#include <bits/stdc++.h>   const double g = 9.8;   using namespace std;   const long long mod = 998244353;   long long quick(long long prea, long long bbb) {     long long res = 1;     while (bbb) {       if (bbb & 1) res = res * prea % mod;       prea = prea * prea % mod;       bbb >>= 1;     }     return res;   }   long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }   pair<int, int> pp;   const int w = 2e5 + 5;   long long a[w];   stack<long long> s;   int main() {     long long k, m, n, t, i, j;     cin >> n;     for (i = 0; i < n; i++) {       cin >> m;       if (s.empty())         s.push(m);       else {         if (abs(m - s.top()) % 2 == 0)           s.pop();         else           s.push(m);       }     }     if (s.size() > 1)       cout <<  NO  << endl;     else       cout <<  YES  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int a, b, r;     cin >> a >> b >> r;     if (2 * r <= min(a, b))       cout <<  First ;     else       cout <<  Second ;   }


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


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5, mod = 998244353;   int inv[N], fac[N];   int ksm(int b, int n) {     int res = 1;     while (n) {       if (n & 1) res = 1ll * res * b % mod;       b = 1ll * b * b % mod;       n >>= 1;     }     return res;   }   void init(int n) {     fac[0] = 1;     for (int i = 1; i <= n; ++i) fac[i] = 1ll * fac[i - 1] * i % mod;     inv[n] = ksm(fac[n], mod - 2);     for (int i = n - 1; i >= 0; --i) inv[i] = 1ll * (i + 1) * inv[i + 1] % mod;   }   int C(int n, int m) {     if (n < m || n < 0 || m < 0) return 0;     return 1ll * fac[n] * inv[m] % mod * inv[n - m] % mod;   }   int calc(int n, int m, int lim) {     if (n == 0) return 1;     if (n < 0) return 0;     int ans = 0;     for (int i = 0; i <= m; ++i) {       int tmp = 1ll * C(n - lim * i + m - 1, m - 1) * C(m, i) % mod;       if (i & 1)         ans = (ans + mod - tmp) % mod;       else         ans = (ans + tmp) % mod;     }     return ans;   }   signed main() {     int p, s, r, ans = 0;     cin >> p >> s >> r;     init(1e5);     for (int i = r; i <= s; ++i)       for (int j = 1; j <= p; ++j) {         if (i * j + (p - j) * (i - 1) < s) continue;         int tmp = 1ll * calc(s - j * i, p - j, i) * C(p - 1, j - 1) % mod;         ans = (ans + 1ll * tmp * ksm(j, mod - 2)) % mod;       }     cout << 1ll * ans * ksm(C(s - r + p - 1, p - 1), mod - 2) % mod;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const int MOD = 1e9 + 7;   int main() {     cin.tie(0)->sync_with_stdio(0);     int t;     cin >> t;     while (t--) {       string s;       cin >> s;       vector<int> r;       for (string t : { twone ,  one ,  two }) {         for (size_t pos = 0; (pos = s.find(t, pos)) != string::npos;) {           s[pos + t.length() / 2] =  ? ;           r.push_back(pos + t.length() / 2);         }       }       cout << r.size() << endl;       for (auto rr : r) cout << rr + 1 <<    ;       cout << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int n;   int x[2001], y[2001];   int p[2001], mn[2001];   int k[2001], c[2001];   bool used[2001][2001];   unsigned long long dst[2001][2001];   unsigned long long dist(int i, int j) {     return (unsigned long long)(k[i] + k[j]) *            (unsigned long long)(abs(x[i] - x[j]) + abs(y[i] - y[j]));   }   void init() {     for (int i = 0; i < n; i++) {       p[i] = i;       mn[i] = c[i];     }     for (int i = 0; i < n; i++) {       for (int j = i + 1; j < n; j++) {         dst[i][j] = dist(i, j);         dst[j][i] = dst[i][j];       }     }   }   struct vertex {     unsigned long long len;     int x, y;     vertex(){};     vertex(unsigned long long _len, int _x, int _y) {       len = _len;       x = _x;       y = _y;     }     bool operator<(vertex b) { return len < b.len; }   };   bool operator<(const vertex& a, const vertex& b) { return a.len < b.len; }   multiset<vertex> s;   int get_anc(int x) {     if (x == p[x]) return x;     return p[x] = get_anc(p[x]);   }   void unite(int x, int y) {     x = get_anc(x);     y = get_anc(y);     if (x == y) return;     if (x < y) swap(x, y);     p[x] = y;     mn[y] = min(mn[x], mn[y]);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n;     for (int i = 0; i < n; i++) {       cin >> x[i] >> y[i];     }     for (int i = 0; i < n; i++) cin >> c[i];     for (int i = 0; i < n; i++) cin >> k[i];     init();     for (int i = 0; i < n; i++) {       for (int j = i + 1; j < n; j++) {         s.insert(vertex(dst[i][j], i, j));       }     }     unsigned long long ans = 0;     int conn = 0;     while (!s.empty()) {       vertex cur = *s.begin();       s.erase(s.begin());       unsigned long long curlen = cur.len;       int curx = cur.x, cury = cur.y;       if (get_anc(curx) == get_anc(cury)) continue;       if (curlen + min(mn[get_anc(curx)], mn[get_anc(cury)]) >           mn[get_anc(curx)] + mn[get_anc(cury)])         continue;       unite(curx, cury);       ans += curlen;       used[curx][cury] = used[cury][curx] = 1;       conn++;     }     vector<int> way;     for (int i = 0; i < n; i++) {       int x = get_anc(i);       if (c[i] == mn[x]) {         ans += c[i];         mn[i] = -1;         way.push_back(i + 1);       }     }     cout << ans << endl;     cout << way.size() << endl;     for (int i = 0; i < way.size(); i++) cout << way[i] <<    ;     cout << endl;     cout << conn << endl;     for (int i = 0; i < n; i++) {       for (int j = i + 1; j < n; j++) {         if (used[i][j]) cout << i + 1 <<     << j + 1 << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 100007;   int n, k;   int s[N];   int main() {     scanf( %d %d , &n, &k);     for (int i = 0; i < n; i++) scanf( %d , s + i);     if (k >= n) {       printf( %d n , s[n - 1]);       return 0;     }     int maxi = 0;     while (n < 2 * k) {       maxi = max(s[--n], maxi);       k--;     }     for (int i = 0; i < k; i++) {       maxi = max(s[i] + s[n - i - 1], maxi);     }     printf( %d n , maxi);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     scanf( %d , &n);     printf( %d n , n / 2 - (n % 2 ? 0 : 1));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string s, s1;   int main() {     cin >> s;     cin >> s1;     reverse(s.begin(), s.end());     reverse(s1.begin(), s1.end());     while (!s.empty() && s[s.size() - 1] ==  0 ) s.pop_back();     while (!s1.empty() && s1[s1.size() - 1] ==  0 ) s1.pop_back();     if (s.size() > s1.size())       cout <<  > ;     else if (s1.size() > s.size())       cout <<  < ;     else {       int z = 0;       for (int i = s.size() - 1; i >= 0 && z == 0; i--)         if (s[i] > s1[i])           z = 1;         else if (s1[i] > s[i])           z = 2;       if (z == 1)         cout <<  > ;       else if (z == 2)         cout <<  < ;       else         cout <<  = ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 105, mod = 1e9 + 7;   int dp[N][N * N];   bool done[N][N * N];   int fact[N], inv[N];   int arr1[N];   int arr2[N];   int n, k;   long long m;   inline int add(int a, int b) {     int res = a + b;     if (res >= mod) res -= mod;     return res;   }   inline int mult(int a, int b) {     long long res = a * 1LL * b;     return res % mod;   }   int powmod(int a, long long b) {     int res = 1;     while (b) {       if (b & 1) {         res = mult(res, a);       }       a = mult(a, a);       b >>= 1;     }     return res;   }   int ncr(int n, int r) {     int res = fact[n];     res = mult(res, inv[r]);     res = mult(res, inv[n - r]);     return res;   }   int solve(int pos, int cnt) {     if (cnt < 0) return 0;     if (pos == n + 1) return (cnt == 0);     if (done[pos][cnt]) return dp[pos][cnt];     if ((n + 1 - pos) * n < cnt) return 0;     long long p = m / n;     bool b = (pos <= m % n);     if (b) {       for (int i = 0; i <= n; i++) {         dp[pos][cnt] = add(mult(solve(pos + 1, cnt - i), arr2[i]), dp[pos][cnt]);       }     } else {       for (int i = 0; i <= n; i++) {         dp[pos][cnt] = add(mult(solve(pos + 1, cnt - i), arr1[i]), dp[pos][cnt]);       }     }     done[pos][cnt] = true;     return dp[pos][cnt];   }   int main() {     scanf( %d %I64d %d , &n, &m, &k);     fact[0] = 1, inv[0] = 1;     long long p = m / n;     for (int i = 1; i < N; i++) {       fact[i] = mult(fact[i - 1], i);       inv[i] = powmod(fact[i], mod - 2);     }     for (int i = 0; i <= n; i++) {       arr1[i] = powmod(ncr(n, i), p);       arr2[i] = powmod(ncr(n, i), p + 1);     }     memset(dp, 0, sizeof(dp));     int ans = solve(1, k);     printf( %d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     int a[11], b[11];     scanf( %d %d , &n, &m);     for (int i = 0; i < n; i++) {       scanf( %d , a + i);     }     for (int i = 0; i < m; i++) {       scanf( %d , b + i);     }     sort(a, a + n);     sort(b, b + m);     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (a[i] == b[j]) {           printf( %d n , a[i]);           return 0;         }       }     }     if (a[0] > b[0])       printf( %d%d n , b[0], a[0]);     else       printf( %d%d n , a[0], b[0]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int in() {     int a;     scanf( %d , &a);     return a;   }   double din() {     double a;     scanf( %lf , &a);     return a;   }   int gcd(int a, int b) {     while (b) {       a %= b;       swap(a, b);     }     return a;   }   int lcm(int a, int b) { return a / gcd(a, b) * b; }   const double eps = 1e-6;   int logbin(int a) {     a--;     int res = 1;     while (a) a >>= 1, res <<= 1;     return res;   }   int binpow(int a, int n) {     int res = 1;     while (n) {       if (n & 1) res *= a;       a *= a;       n >>= 1;     }     return res;   }   vector<vector<int> > g;   vector<char> u;   vector<int> p;   void dfs(int v) {     u[v] = 1;     for (int i = 0; i < g[v].size(); ++i) {       int to = g[v][i];       if (!u[to]) {         p[to] = v;         dfs(to);       } else {         if (u[to] == 1) {           int vv = v;           while (p[vv] != to) {             u[vv] = 3;             vv = p[vv];           }         }       }     }     if (u[v] == 1) u[v] = 2;   }   int main() {     int n = in();     int m = in(), k = in();     vector<vector<pair<int, pair<int, int> > > > g(         n, vector<pair<int, pair<int, int> > >());     for (int i = 0; i < n; ++i) {       string s;       cin >> s;       for (int j = 0; j < m; ++j) {         int u = in(), e = in(), h = in();         g[i].push_back(make_pair(u, make_pair(e, h)));       }     }     long long res = 0;     for (int i = 0; i < n; ++i) {       for (int j = 0; j < n; ++j) {         if (i == j) continue;         vector<pair<int, pair<int, int> > > s, t;         s = g[i];         t = g[j];         vector<int> c;         long long r = 0;         for (int y = 0; y < m; ++y) {           int nn = s[y].second.second;           for (int h = 0; h < nn; ++h) {             int buf = t[y].second.first - s[y].first;             if (buf > 0)               c.push_back(buf);             else               break;           }         }         sort((c).rbegin(), (c).rend());         for (int i = 0; i < min((int)c.size(), k); ++i) {           r += c[i];         }         res = max(res, r);       }     }     cout << res;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool sortinrev(const pair<long long, long long> &a,                  const pair<long long, long long> &b) {     return (a.first > b.first);   }   void solve() {     long long n;     cin >> n;     long long a[n];     map<long long, long long> mp;     for (long long i = 0; i < n; i++) {       cin >> a[i];       mp[a[i]] = i;     }     long long p = 1;     long long end = n;     while (end != 0) {       long long k = mp[p];       for (long long i = k; i < end; i++) {         if (a[i] != p) {           cout <<  No                 <<   n ;           return;         }         p++;       }       end = k;     }     cout <<  Yes           <<   n ;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long t = 1;     cin >> t;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   vector<pair<int, int>> q;   int n;   void op(int i, int j) { q.push_back({i, j}); }   void f(int l, int r) {     if (l >= r) return;     int len = (r - l + 1);     if (len % 2 == 0) {       int m = (l + r) / 2;       f(l, m);       f(m + 1, r);       for (int j = 0; j < len / 2; j++) op(l + j, l + len / 2 + j);     } else {       r--;       int m = (l + r) / 2;       f(l, m);       f(m + 1, r);       for (int j = 0; j < len / 2; j++) op(l + j, l + len / 2 + j);       r++;       for (int j = l; j < r; j++) op(j, r);     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n;     int k = log2(n);     k = (1 << k);     f(1, k);     f(n - k + 1, n);     cout << (int)q.size() <<   n ;     for (auto &it : q) cout << it.first <<     << it.second <<   n ;   }


#include <bits/stdc++.h>   long long n, i, k, j, t, b;   char a[2500];   bool s;   using namespace std;   int main() {     k = 0;     cin >> n;     for (i = 1; i <= n; i++) {       cin >> a[i];       if (a[i] ==  H ) k++;     }     b = n - k;     for (i = n + 1; i <= 2 * n; i++) a[i] = a[i - n];     for (i = 1; i <= 2 * n; i++)       if (i + k <= 2 * n) {         t = 0;         for (j = i; j < i + k; j++)           if (a[j] !=  H ) t++;         if (t < b) b = t;       }     cout << b << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n;     cin >> n;     cout << ((n % 2) ?  black  :  white n1 2 n ) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int i, n, m, ans, x, l, r, tot, a[1000005], b[1000005], last[1000005],       to[1000005], Next[1000005], q[1000005], y;   inline void add(int x, int y) {     Next[++tot] = last[x];     last[x] = tot;     to[tot] = y;   }   inline bool check(int x) {     for (int i = 1; i <= n; i++) a[i] = b[i];     a[x]--;     int rr = r, ll = l;     q[++r] = x;     while (l < r) {       int k = q[++l];       for (int i = last[k]; i; i = Next[i]) {         a[to[i]]--;         if (!a[to[i]]) q[++r] = to[i];       }     }     if (r == n) return true;     r = rr, l = ll;     return false;   }   int main() {     scanf( %d%d , &n, &m);     for (i = 1; i <= m; i++) scanf( %d%d , &x, &y), b[y]++, add(x, y);     for (i = 1; i <= n; i++)       if (b[i] == 0) q[++r] = i;     while (l < r) {       int k = q[++l];       for (int i = last[k]; i; i = Next[i]) {         b[to[i]]--;         if (!b[to[i]]) q[++r] = to[i];       }     }     if (r == n) return puts( YES ), 0;     for (i = 1; i <= n; i++) {       if (b[i] == 1) {         if (check(i)) return puts( YES ), 0;       }     }     puts( NO );   }


#include <bits/stdc++.h>   using namespace std;   vector<long long> v, ext;   long long f[20];   bool vis[20];   bool chck(long long j) {     while (j) {       if (j % 10 != 4 && j % 10 != 7) break;       j /= 10;     }     return j == 0;   }   int main() {     long long i, n, k, st, sum, j, pre, sz, ans;     f[0] = 1;     for (i = 1; i <= 13; i++) f[i] = f[i - 1] * i;     cin >> n >> k;     if (n <= 13 && k > f[n]) {       cout << -1 << endl;       return 0;     }     for (i = 1; f[i] < k; i++)       ;     st = n - i + 1;     sum = k;     for (j = 1; j <= i; j++) {       for (k = st; k <= n; k++) {         if (!vis[k - st]) {           if (sum - f[i - j] > 0) {             sum -= f[i - j];           } else {             ext.push_back(k);             vis[k - st] = 1;             break;           }         }       }     }     queue<long long> q;     q.push(4);     q.push(7);     v.push_back(4);     v.push_back(7);     while (!q.empty()) {       pre = q.front();       q.pop();       if (pre * 10 + 4 <= 5000000000LL) {         q.push(pre * 10 + 4);         q.push(pre * 10 + 7);         v.push_back(pre * 10 + 4);         v.push_back(pre * 10 + 7);       }     }     sz = v.size();     ans = 0;     for (i = 0; i < sz && v[i] < st; i++) ans++;     for (i = st; i <= n; i++) {       if (chck(i)) {         if (chck(ext[i - st])) ans++;       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   typedef struct val {     long int val, ind;   } va;   int cmp(const void *a, const void *b) {     va ka = *(va *)a;     va kb = *(va *)b;     if (ka.val > kb.val)       return -1;     else       return 1;   }   int a[2009][2009];   int main() {     va v[2009], ba[2009];     long int n, m, t1, t2, i, j, ans = 0;     scanf( %ld %ld , &n, &m);     for (i = 0; i < n; i++) {       scanf( %ld , &v[i].val);       v[i].ind = i + 1;       ba[i] = v[i];     }     for (i = 0; i < m; i++) {       scanf( %ld %ld , &t1, &t2);       a[t1][t2] = 1;       a[t2][t1] = 1;     }     qsort(v, n, sizeof(va), cmp);     for (i = 0; i < n; i++)       for (j = 1; j <= n; j++)         if (a[v[i].ind][j]) {           a[v[i].ind][j] = 0;           a[j][v[i].ind] = 0;           ans += ba[j - 1].val;         }     printf( %ld n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int A[1000];   void quicksort(int l, int r) {     int b = l;     if (r - l < 1) {       return;     }     for (int i = l; i < r; ++i) {       if (A[i] < A[r]) {         swap(A[i], A[b]);         b = b + 1;       }     }     swap(A[r], A[b]);     quicksort(l, b - 1);     quicksort(b + 1, r);   }   int main() {     int r;     cin >> r;     for (int i = 0; i < r; ++i) {       cin >> A[i];     }     quicksort(0, r - 1);     if (r % 2 > 0) {       cout << A[(r / 2)];     } else {       cout << min(A[r / 2], A[r / 2 - 1]);     }     return 0;   }


#include <bits/stdc++.h>   int inp() {     char c = getchar();     while (c <  0  || c >  9 ) c = getchar();     int sum = 0;     while (c >=  0  && c <=  9 ) {       sum = sum * 10 + c -  0 ;       c = getchar();     }     return sum;   }   struct SEG_Tree {     struct SEG {       int l;       int r;       int min;       long long sum;       long long ans;       int lazy;       long long lazy2;     } t[5000010];     void push_up(int cur) {       t[cur].min = std::min(t[((cur) << 1)].min, t[((cur) << 1 | 1)].min);       t[cur].sum = 0;       if (t[cur].min == t[((cur) << 1)].min) t[cur].sum += t[((cur) << 1)].sum;       if (t[cur].min == t[((cur) << 1 | 1)].min)         t[cur].sum += t[((cur) << 1 | 1)].sum;     }     void push_down(int cur) {       t[((cur) << 1)].min += t[cur].lazy;       t[((cur) << 1 | 1)].min += t[cur].lazy;       t[((cur) << 1)].lazy += t[cur].lazy;       t[((cur) << 1 | 1)].lazy += t[cur].lazy;       t[cur].lazy = 0;       if (t[cur].min == t[((cur) << 1)].min) {         t[((cur) << 1)].ans += t[((cur) << 1)].sum * t[cur].lazy2;         t[((cur) << 1)].lazy2 += t[cur].lazy2;       }       if (t[cur].min == t[((cur) << 1 | 1)].min) {         t[((cur) << 1 | 1)].ans += t[((cur) << 1 | 1)].sum * t[cur].lazy2;         t[((cur) << 1 | 1)].lazy2 += t[cur].lazy2;       }       t[cur].lazy2 = 0;     }     void build(int cur, int l, int r) {       t[cur].l = l;       t[cur].r = r;       if (l == r) {         t[cur].min = l;         t[cur].sum = 1;         return;       }       int mid = (l + r) >> 1;       build(((cur) << 1), l, mid);       build(((cur) << 1 | 1), mid + 1, r);       push_up(cur);     }     void modify(int cur, int l, int r, int c) {       if (t[cur].l > r || t[cur].r < l) return;       if (t[cur].l >= l && t[cur].r <= r) {         t[cur].min += c;         t[cur].lazy += c;         return;       }       push_down(cur);       modify(((cur) << 1), l, r, c);       modify(((cur) << 1 | 1), l, r, c);       push_up(cur);     }     long long query(int cur, int l, int r) {       if (t[cur].l > r || t[cur].r < l) return 0;       if (t[cur].l >= l && t[cur].r <= r) return t[cur].ans;       push_down(cur);       return query(((cur) << 1), l, r) + query(((cur) << 1 | 1), l, r);     }   } t;   std::vector<std::pair<int, int> > vec[1200010];   long long ans[1200010];   int a[1200010], s1[1200010], s2[1200000];   signed main() {     int n = inp();     for (int i = 1; i <= n; i++) a[i] = inp();     int q = inp();     for (int i = 1; i <= q; i++) {       int l = inp();       int r = inp();       vec[r].push_back(std::make_pair(l, i));     }     int top1 = 0, top2 = 0;     t.build(1, 1, n);     for (int i = 1; i <= n; i++) {       t.modify(1, 1, n, -1);       while (top1 && a[s1[top1]] > a[i]) {         t.modify(1, s1[top1 - 1] + 1, s1[top1], a[s1[top1]] - a[i]);         top1--;       }       s1[++top1] = i;       while (top2 && a[s2[top2]] < a[i]) {         t.modify(1, s2[top2 - 1] + 1, s2[top2], a[i] - a[s2[top2]]);         top2--;       }       s2[++top2] = i;       t.t[1].ans += t.t[1].sum;       t.t[1].lazy2++;       for (int j = 0; j < vec[i].size(); j++)         ans[vec[i][j].second] = t.query(1, vec[i][j].first, i);     }     for (int i = 1; i <= q; i++) printf( %lld n , ans[i]);   }


#include <bits/stdc++.h>   using namespace std;   int dp[105][200005];   int main() {     int n, k;     cin >> n >> k;     int a[n + 1], b[n + 1];     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = 1; i <= n; i++) cin >> b[i];     int off = 1000 * n;     for (int i = 0; i < 105; i++)       for (int j = 0; j < 200005; j++) dp[i][j] = -INT_MAX;     dp[0][off] = 0;     for (int curr = 1; curr <= n; curr++) {       int bl = a[curr] - b[curr] * k;       for (int bal = off; bal >= -off; bal--) {         dp[curr][bal + off] =             max(dp[curr - 1][bal + off], dp[curr - 1][bal - bl + off] + a[curr]);       }     }     cout << (dp[n][off] ? dp[n][off] : -1) << endl;     return 0;   }