#include <bits/stdc++.h>   using namespace std;   template <typename T1, typename T2>   inline T1 max(T1 a, T2 b) {     return a < b ? b : a;   }   template <typename T1, typename T2>   inline T1 min(T1 a, T2 b) {     return a < b ? a : b;   }   const char lf =   n ;   namespace ae86 {   const int bufl = 1 << 15;   char buf[bufl], *s = buf, *t = buf;   inline int fetch() {     if (s == t) {       t = (s = buf) + fread(buf, 1, bufl, stdin);       if (s == t) return EOF;     }     return *s++;   }   inline int ty() {     int a = 0;     int b = 1, c = fetch();     while (!isdigit(c)) b ^= c ==  - , c = fetch();     while (isdigit(c)) a = a * 10 + c - 48, c = fetch();     return b ? a : -a;   }   }  // namespace ae86   using ae86::ty;   const int _ = 2007, __ = 100007;   const long long linf = 0x3f3f3f3f3f3f3f3f;   vector<pair<int, int>> e[_];   inline void adde(int a, int b, int c) { e[a].emplace_back(b, c); }   inline void addde(int a, int b, int c) { adde(a, b, c), adde(b, a, c); }   int n, m, sa, sb;   long long val[_] = {0};   int ed[_] = {0};   void dijks(int s, long long dis[]) {     for (int i = 1; i <= n; i++) dis[i] = linf, ed[i] = 0;     queue<int> q;     dis[s] = 0, ed[s] = 1, q.emplace(s);     while (!q.empty()) {       int a = q.front();       q.pop(), ed[a] = 0;       for (auto [b, c] : e[a]) {         if (dis[b] <= dis[a] + c) continue;         dis[b] = dis[a] + c;         if (!ed[b]) q.emplace(b), ed[b] = 1;       }     }   }   long long disa[_], disb[_];   long long ha[_] = {0};   int lha = 0, lhb = 0;   struct cxk {     int x, y;     long long v;     cxk(int x_ = 0, int y_ = 0, long long v_ = 0) { x = x_, y = y_, v = v_; }   } ps[_];   int hx[_] = {0}, hy[_] = {0};   long long sval[_][_] = {0}, f[2][_][_] = {0}, sf[2][_] = {0}, fs[_] = {0};   int main() {     ios::sync_with_stdio(0), cout.tie(nullptr);     n = ty(), m = ty();     sa = ty(), sb = ty();     for (int i = 1; i <= n; i++) val[i] = ty();     for (int i = 1, a, b, c; i <= m; i++)       a = ty(), b = ty(), c = ty(), addde(a, b, c);     dijks(sa, disa), dijks(sb, disb);     lha = 0;     for (int i = 1; i <= n; i++) ha[++lha] = disa[i];     sort(ha + 1, ha + lha + 1), lha = unique(ha + 1, ha + lha + 1) - ha - 1;     for (int i = 1; i <= n; i++)       disa[i] = lower_bound(ha + 1, ha + lha + 1, disa[i]) - ha;     lhb = 0;     for (int i = 1; i <= n; i++) ha[++lhb] = disb[i];     sort(ha + 1, ha + lhb + 1), lhb = unique(ha + 1, ha + lhb + 1) - ha - 1;     for (int i = 1; i <= n; i++)       disb[i] = lower_bound(ha + 1, ha + lhb + 1, disb[i]) - ha;     for (int i = 1; i <= n; i++) ps[i] = cxk(disa[i], disb[i], val[i]);     for (int i = 1; i <= n; i++)       hx[ps[i].y] = max(hx[ps[i].y], ps[i].x),       hy[ps[i].x] = max(hy[ps[i].x], ps[i].y);     for (int i = 1; i <= lha; i++) {       for (int j = 1; j <= n; j++)         if (ps[j].x >= i) sval[i][ps[j].y] += ps[j].v;       for (int j = lhb - 1; j >= 1; j--) sval[i][j] += sval[i][j + 1];     }     for (int i = lha; i >= 1; i--)       for (int j = lhb; j >= 1; j--) {         if (hx[j] >= i) f[1][i][j] = sf[1][i] + sval[i][j];         if (hy[i] >= j) f[0][i][j] = sf[0][j] + sval[i][j];         if (hx[j] >= i)           sf[0][j] = max(sf[0][j], -f[1][i][j] - sval[i][j]);         else           sf[0][j] = max(sf[0][j], sf[0][j + 1]);         if (hy[i] >= j)           sf[1][i] = max(sf[1][i], -f[0][i][j] - sval[i][j]);         else           sf[1][i] = max(sf[1][i], fs[j]);         fs[j] = sf[1][i];       }     if (f[0][1][1] > 0)       cout <<  Break a heart  << lf;     else if (f[0][1][1] == 0)       cout <<  Flowers  << lf;     else       cout <<  Cry  << lf;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     char c;     bool ch = false;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         cin >> c;         if (c ==  C  || c ==  M  || c ==  Y ) {           ch = true;           break;         }       }     }     if (ch) {       cout <<  #Color  << endl;     } else {       cout <<  #Black&White  << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n;     while (cin >> n) {       bool flag = false;       int sum = 0;       while (n) {         if (n % 10 == 4 || n % 10 == 7)           n /= 10, sum++;         else           n /= 10;       }       if ((sum == 4 || sum == 7))         cout <<  YES  << endl;       else         cout <<  NO  << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   void fastio() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);   }   const long long int N = 100010;   long long int cnt[N], f[N];   int main() {     fastio();     long long int n, temp;     cin >> n;     long long int ar[n];     memset(cnt, 0, sizeof(cnt));     for (int i = 0; i < n; i++) {       cin >> temp;       cnt[temp]++;     }     f[0] = 0;     f[1] = cnt[1];     for (int i = 2; i < N; i++) {       f[i] = max(f[i - 1], f[i - 2] + cnt[i] * i);     }     cout << f[N - 1];     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     long long n;     cin >> n;     bool a[n][n], fin[n][n], line[n];     for (long long i = (0); i < (n); i++) {       string s;       cin >> s;       for (long long j = (0); j < (n); j++) a[i][j] = s[j] ==  0  ? 0 : 1;     }     for (long long i = (0); i < (n); i++) {       string s;       cin >> s;       for (long long j = (0); j < (n); j++) fin[i][j] = s[j] ==  0  ? 0 : 1;     }     string s;     cin >> s;     for (long long i = (0); i < (n); i++) line[i] = s[i] ==  0  ? 0 : 1;     bool flag = 1;     for (long long i = (0); i < (n); i++) {       for (long long j = (0); j < (n); j++) {         if (a[i][j] != fin[i][j]) {           flag = 0;           break;         }       }     }     if (flag) {       cout << 0;       return;     }     bool row[n], col[n];     memset(row, 0, sizeof(row));     memset(col, 0, sizeof(col));     long long f = -1;     for (long long i = (0); i < (n); i++) {       if (line[i]) {         f = i;         break;       }     }     if (f == -1) {       cout << -1;       return;     }     for (long long i = (0); i < (n); i++) {       if (a[i][f] != fin[i][f]) row[i] = 1;     }     bool temp[n][n];     for (long long i = (0); i < (n); i++) {       for (long long j = (0); j < (n); j++) {         temp[i][j] = a[i][j];         if (row[i]) temp[i][j] ^= line[j];       }     }     for (long long j = (0); j < (n); j++) {       flag = 1;       for (long long i = (0); i < (n); i++) {         if (temp[i][j] != fin[i][j]) {           flag = 0;           break;         }       }       if (flag) continue;       flag = 1;       col[j] = 1;       for (long long i = (0); i < (n); i++) temp[i][j] ^= line[i];       for (long long i = (0); i < (n); i++) {         if (temp[i][j] != fin[i][j]) {           flag = 0;           break;         }       }       if (!flag) break;     }     if (flag) {       long long cnt = 0;       for (long long i = (0); i < (n); i++) {         cnt += row[i];         cnt += col[i];       }       cout << cnt <<   n ;       for (long long i = (0); i < (n); i++) {         if (row[i]) cout <<  row   << i <<   n ;       }       for (long long i = (0); i < (n); i++) {         if (col[i]) cout <<  col   << i <<   n ;       }       return;     }     for (long long i = (0); i < (n); i++) {       if (line[i]) row[i] ^= 1;     }     for (long long i = (0); i < (n); i++) {       for (long long j = (0); j < (n); j++) {         temp[i][j] = a[i][j];         if (row[i]) temp[i][j] ^= line[j];       }     }     for (long long j = (0); j < (n); j++) {       col[j] = 0;       flag = 1;       for (long long i = (0); i < (n); i++) {         if (temp[i][j] != fin[i][j]) {           flag = 0;           break;         }       }       if (flag) continue;       flag = 1;       col[j] = 1;       for (long long i = (0); i < (n); i++) temp[i][j] ^= line[i];       for (long long i = (0); i < (n); i++) {         if (temp[i][j] != fin[i][j]) {           flag = 0;           break;         }       }       if (!flag) break;     }     if (flag) {       long long cnt = 0;       for (long long i = (0); i < (n); i++) {         cnt += row[i];         cnt += col[i];       }       cout << cnt <<   n ;       for (long long i = (0); i < (n); i++) {         if (row[i]) cout <<  row   << i <<   n ;       }       for (long long i = (0); i < (n); i++) {         if (col[i]) cout <<  col   << i <<   n ;       }       return;     }     cout << -1;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long t = 1;     for (long long i = (1); i < (t + 1); i++) {       solve();       cout <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k = 0;     string s, t;     cin >> n;     cin >> s >> t;     vector<int> vect;     for (int i = 0; i < n; i++) {       if (s[i] == t[i])         continue;       else {         int flag = -1;         for (int j = i + 1; j < n; j++) {           if (s[j] == t[i]) {             flag = j;             break;           }         }         if (flag == -1) {           cout <<  -1 ;           return 0;         }         for (int j = flag - 1; j >= i; j--) {           swap(s[j], s[j + 1]);           vect.push_back(j + 1);           k++;         }       }     }     cout << k << endl;     for (int i = 0; i < k; i++) cout << vect[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC target( avx,avx2,fma )   using namespace std;   const int N = 207;   const int K = 1007;   const long long mod = 1e9 + 7;   long long dp[2][N][K];   long long a[N];   int n, k;   int main() {     cin >> n >> k;     for (int i = 1; i <= n; i++) scanf( %lld , &a[i]);     dp[0][0][0] = 1;     sort(a + 1, a + n + 1);     int cur = 0, prv = 0;     for (int i = 1; i <= n; i++) {       int d = a[i] - a[i - 1];       prv = cur;       cur ^= 1;       for (int j = 0; j <= i; j++) {         for (int c = 0; c <= k; c++) {           dp[cur][j][c] = 0;           if (j && c - (j - 1) * d >= 0)             dp[cur][j][c] += dp[prv][j - 1][c - (j - 1) * d];           if (c - (j + 1) * d >= 0)             dp[cur][j][c] += dp[prv][j + 1][c - (j + 1) * d] * (j + 1);           if (c - j * d >= 0) dp[cur][j][c] += dp[prv][j][c - j * d] * (j + 1);           dp[cur][j][c] %= mod;         }       }     }     long long ans = 0;     for (int c = 0; c <= k; c++) ans += dp[cur][0][c];     cout << ans % mod;   }


#include <bits/stdc++.h>   using namespace std;   int arr[3000];   int main() {     int n, m;     cin >> n >> m;     for (int i = 0; i < n; i++) {       cin >> arr[i];     }     int minn = 99999;     int maxx = -999;     for (int i = 0; i < n - 1; i++) {       minn = min(minn, arr[i]);       if (arr[i] <= arr[i + 1])         maxx = max(maxx, (m / minn) * arr[i + 1] + m % minn);     }     cout << max(maxx, m);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, k;   int d[188];   int par[188];   vector<int> g[188];   int dp[188][188];   int pos[188];   int ans[188];   void build(int x, int pre) {     par[x] = pre;     for (int i = (0); i < (g[x].size()); ++i) {       int to = g[x][i];       if (to == pre) {         g[x].erase(g[x].begin() + i, g[x].begin() + i + 1);         i--;         continue;       }       build(to, x);     }   }   void dfs(int x) {     for (int i = (0); i < (g[x].size()); ++i) {       int to = g[x][i];       dfs(to);     }     for (int y = (0); y < (n); ++y) {       int z = y;       while (z != x && z != -1) z = par[z];       if (z == -1) continue;       z = y;       int cur = 0, lst = -1, dis = 0;       while (1) {         cur += (dis ? d[dis] : k);         dis++;         for (int i = (0); i < (g[z].size()); ++i) {           int to = g[z][i];           if (to == lst) continue;           cur += dp[to][dis];         }         if (z == x) break;         lst = z;         z = par[z];       }       if (cur < dp[x][0]) {         dp[x][0] = cur;         pos[x] = y;       }     }     for (int dis = (1); dis < (n); ++dis) {       dp[x][dis] = dp[x][0];       int cur = d[dis];       for (int i = (0); i < (g[x].size()); ++i) {         int to = g[x][i];         cur += dp[to][dis + 1];       }       if (cur < dp[x][dis]) {         dp[x][dis] = cur;       }     }   }   void getans(int x, int dis, int lst) {     if (dp[x][dis] != dp[x][0]) {       ans[x] = lst;       for (int i = (0); i < (g[x].size()); ++i) {         int to = g[x][i];         getans(to, dis + 1, lst);       }       return;     }     int y = pos[x];     int z = y;     dis = 0;     lst = -1;     while (1) {       ans[z] = y;       dis++;       for (int i = (0); i < (g[z].size()); ++i) {         int to = g[z][i];         if (to == lst) continue;         getans(to, dis, y);       }       if (z == x) break;       lst = z;       z = par[z];     }   }   int main() {     memset(dp, 0x3f, sizeof(dp));     cin >> n >> k;     for (int i = (1); i < (n); ++i) cin >> d[i];     for (int i = (1); i < (n); ++i) {       int a, b;       cin >> a >> b;       a--;       b--;       g[a].push_back(b);       g[b].push_back(a);     }     build(0, -1);     dfs(0);     cout << dp[0][0] << endl;     getans(0, 0, -1);     for (int i = (0); i < (n); ++i) {       cout << ans[i] + 1 << (i == n - 1 ?   n  :    );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 5000 + 10;   int main() {     int n, k;     int a[maxn];     scanf( %d%d , &n, &k);     for (int i = 0; i < n; i++) scanf( %d , &a[i]);     int sum = 0;     int maxs = 0;     double maxa = 0;     for (int i = k; i <= n; i++) {       for (int j = 0; j < i; j++) sum += a[j];       maxs = sum;       for (int j = 1; j < n - i + 1; j++) {         sum = sum - a[j - 1] + a[j + i - 1];         maxs = max(maxs, sum);       }       double a = maxs * 1.0 / i;       maxa = max(maxa, a);       sum = 0;     }     printf( %lf n , maxa);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) {     if (b == 0)       return a;     else {       return (gcd(b, (a % b)));     }   }   int main() {     int t;     long long n;     scanf( %d , &t);     for (int i = 1; i <= t; i++) {       cin >> n;       long long a = (long long)4LL * n;       long long b = (long long)(n + 1LL);       long long res = gcd(a, b);       res = (long long)(a) / res;       cout << (res + 1) << endl;     }     return 0;   }


#include <bits/stdc++.h>   #pragma warning(disable : 4996)   using namespace std;   const int maxn = 100010;   int n, m, k, t, t1, t2, t3, t4;   struct node {     int x, y;     int xd, xx, yd, yx;   } a[maxn];   int main() {     scanf( %d , &t);     while (t--) {       scanf( %d , &n);       for (int i = 0; i < n; i++) {         scanf( %d%d%d%d%d%d , &a[i].x, &a[i].y, &t1, &t2, &t3, &t4);         if (t1 == 1) {           a[i].xx = -100000;         } else if (t1 == 0) {           a[i].xx = a[i].x;         }         if (t2 == 1) {           a[i].yd = 100000;         } else if (t2 == 0) {           a[i].yd = a[i].y;         }         if (t3 == 1) {           a[i].xd = 100000;         } else if (t3 == 0) {           a[i].xd = a[i].x;         }         if (t4 == 1) {           a[i].yx = -100000;         } else if (t4 == 0) {           a[i].yx = a[i].y;         }       }       bool flag = true;       int xmaxn = a[0].xd, xmin = a[0].xx, ymaxn = a[0].yd, ymin = a[0].yx;       for (int i = 1; i < n; i++) {         if (xmaxn < a[i].xx || xmin > a[i].xd || ymaxn < a[i].yx ||             ymin > a[i].yd) {           printf( 0 n );           flag = false;           break;         }         if (xmaxn > a[i].xd) {           xmaxn = a[i].xd;         }         if (xmin < a[i].xx) {           xmin = a[i].xx;         }         if (ymaxn > a[i].yd) {           ymaxn = a[i].yd;         }         if (ymin < a[i].yx) {           ymin = a[i].yx;         }       }       if (flag) {         printf( 1 %d %d n , xmin, ymin);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void solve() {     pair<int, int> A[50007];     int n;     cin >> n;     for (int i = 0; i < (n); i++) cin >> A[i].first >> A[i].second;     sort(A, A + n);     int r1 = A[0].first, r2 = A[0].second;     int r3, r4;     for (int i = 1; i < n; i++) {       if (A[i].first >= r1 || A[i].first >= r2) {         r3 = A[i].first;       } else         r3 = 1000000009;       if (A[i].second >= r1 || A[i].second >= r2) {         r4 = A[i].second;       } else         r4 = 1000000009;       r1 = r3, r2 = r4;     }     printf( %d n , min(r1, r2));   }   int main() {     int T = 1;     for (int i = 1; i <= T; i++) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int x;     cin >> x;     if (x % 4 == 0) {       cout <<  1 A ;     } else if (x % 4 == 1) {       cout <<  0 A ;     } else if (x % 4 == 2) {       cout <<  1 B ;     } else if (x % 4 == 3) {       cout <<  2 A ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9;   const long long INFLL = 1e18 + 1;   const int MAX = 200001;   const long long MOD = 1000000007;   const int SZ = 300100;   const double PI = 3.14159265358979323846264338327;   long long inq(long long k, long long q, long long mod) {     if (q == 0) return 1;     long long l = inq(k, q / 2, mod);     if (q % 2 == 0)       return l * l % mod;     else       return l * l % mod * k % mod;   }   long long gcd(long long a, long long b) {     if (a < b) swap(a, b);     if (b == 0) return a;     return gcd(b, a % b);   }   long long cubr(long long a) {     long long l = -1, r = 1e6 + 2;     while (l < r - 1) {       long long mid = (l + r) / 2;       if (mid * mid * mid > a)         r = mid;       else         l = mid;     }     return l;   }   long long max(long long a, long long b) {     if (a > b) return a;     return b;   }   long long min(long long a, long long b) { return -1 * max(-a, -b); }   long long possible(long long q) {     if (q == INF) return -1;     return q;   }   bool correct(int x, int xx) {     if (x < 0) return 0;     if (x >= xx) return 0;     return 1;   }   long long dsumm(long long x, long long k) {     long long y = 1;     long long z = 0;     for (int i = 0; y < 1e18; i++) {       z += x / y % k;       y *= k;     }     return z;   }   long long dcount(long long x) {     long long y = 1;     long long z = 0;     int c[100];     for (int i = 0; i < 10; i++) c[i] = 0;     for (int i = 0; x > 0; i++) {       if (c[x / y % 10] == 0) z++;       c[x / y % 10] = 1;       x /= 10;     }     return z;   }   long long lg10(long long x) {     if (10000 <= x && x < 100000) return 5;     if (x == 0) return 0;     return lg10(x / 10) + 1;   }   long long g(long long x, long long mod) {     if (x == 0) return 0;     return x / mod + g(x / mod, mod);   }   bool is_digit(char c) { return ( 0  <= c && c <=  9 ); }   string s;   string t;   long long prefAS[500000];   long long prefAT[500000];   long long suffA1[500000];   long long suffA2[500000];   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> s;     cin >> t;     for (long long(i) = 0; (i) != (s.size()); i++) {       if (s[i] ==  C ) s[i] =  B ;       if (i > 0) prefAS[i] = prefAS[i - 1];       prefAS[i] += (s[i] ==  A );     }     for (long long(i) = 0; (i) != (t.size()); i++) {       if (t[i] ==  C ) t[i] =  B ;       if (i > 0) prefAT[i] = prefAT[i - 1];       prefAT[i] += (t[i] ==  A );     }     long long aa = 0;     for (long long(i) = 0; (i) != (s.size()); i++) {       if (s[i] ==  A )         aa++;       else         aa = 0;       suffA1[i] = aa;     }     aa = 0;     for (long long(i) = 0; (i) != (t.size()); i++) {       if (t[i] ==  A )         aa++;       else         aa = 0;       suffA2[i] = aa;     }     long long q;     cin >> q;     while (q--) {       long long l1, r1, l2, r2;       cin >> l1 >> r1 >> l2 >> r2;       l1--;       r1--;       l2--;       r2--;       long long cntA1 = prefAS[r1] - (l1 > 0 ? prefAS[l1 - 1] : 0);       long long cntA2 = prefAT[r2] - (l2 > 0 ? prefAT[l2 - 1] : 0);       long long cntB1 = r1 - l1 + 1 - cntA1;       long long cntB2 = r2 - l2 + 1 - cntA2;       long long suffA1q = min(suffA1[r1], r1 - l1 + 1);       long long suffA2q = min(suffA2[r2], r2 - l2 + 1);       if (suffA1q % 3 != suffA2q % 3 ||           (suffA1q == r1 - l1 + 1 && suffA2q != r2 - l2 + 1)) {         suffA1q--;         cntB1 += 2;       }       if (cntB1 % 2 != cntB2 % 2 || cntB1 > cntB2 || suffA1q < suffA2q) {         cout << 0;       } else {         cout << 1;       }     }   }


#include <bits/stdc++.h>   using namespace std;   int read() {     char ch = getchar();     int x = 0, f = 1;     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x * f;   }   const int N = 2e5 + 5;   long long a[N];   long long n, m, k;   bool check(int x) {     long long now = 0, cnt = 1;     for (int i = n - x + 1; i <= n; i++) {       if (now + a[i] > k) {         cnt++, now = a[i];       } else         now += a[i];     }     return cnt <= m;   }   int upp(int l, int r) {     while (l < r) {       int mid = (l + r + 1) >> 1;       if (check(mid))         l = mid;       else         r = mid - 1;     }     return l;   }   int main() {     n = read(), m = read(), k = read();     for (int i = 1; i <= n; i++) a[i] = read();     printf( %d n , upp(1, n));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void setIo(string nom) {     ios_base::sync_with_stdio(0);     cin.tie(0);     freopen((nom +  .in ).c_str(),  r , stdin);     freopen((nom +  .out ).c_str(),  w , stdout);   }   struct Reine {     int x, y, id;     vector<int> tris;     int indTri;     void init(int i) {       cin >> x >> y;       id = i;       tris = {x, y - x, y, -x - y};     }     bool operator<(const Reine& autre) const {       if (indTri != 0)         return x < autre.x;       else         return y < autre.y;     }   };   const int N = 2e5;   int ans[N], comptes[N];   signed main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     int cote, nReines;     cin >> cote >> nReines;     vector<Reine> reines(nReines);     map<int, vector<Reine>> idems;     int ind = 0;     for (Reine& reine : reines) reine.init(ind++);     for (int indTri = 0; indTri < 4; ++indTri) {       for (Reine& reine : reines) {         reine.indTri = indTri;         idems[reine.tris[indTri]].push_back(reine);       }       for (auto& etage : idems) {         sort(etage.second.begin(), etage.second.end());         for (int i = 0; i < (int)etage.second.size(); ++i) {           ans[etage.second[i].id] +=               (i != 0) + (i != ((int)etage.second.size() - 1));         }       }       idems.clear();     }     for (ind = 0; ind < nReines; ++ind) {       comptes[ans[ind]]++;     }     cout << endl;     for (int i = 0; i < 9; ++i) cout << comptes[i] <<    ;     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 998244353;   const int maxN = 131079;   inline int pls(int x, int y) { return (x + y) % mod; }   inline int mns(int x, int y) { return pls(x, mod - y); }   inline int mul(int x, int y) { return 1LL * x * y % mod; }   inline void Add(int &x, int y) { x = pls(x, y); }   inline void Mul(int &x, int y) { x = mul(x, y); }   inline void Minus(int &x, int y) { x = mns(x, y); }   inline int pwr(int x, int tms) {     int res = 1;     for (; tms > 0; tms >>= 1) {       if (tms & 1) Mul(res, x);       Mul(x, x);     }     return res;   }   inline int inv(int x) { return pwr(x, mod - 2); }   template <class T>   inline T rd() {     bool f = 1;     char c = getchar();     for (; !isdigit(c); c = getchar())       if (c ==  - ) f = 0;     T x = 0;     for (; isdigit(c); c = getchar()) x = x * 10 + c - 48;     return f ? x : -x;   }   int n;   int g[maxN];   int f[2][2][maxN];   int h[2][2][maxN];   namespace poly {   int g[2], pwg[2][maxN];   int L, ivL, rev[maxN];   void init() {     g[1] = inv(g[0] = 3);     for (int i = 2; i < maxN; i <<= 1) {       pwg[0][i] = pwr(g[0], (mod - 1) / i);       pwg[1][i] = pwr(g[1], (mod - 1) / i);     }   }   void getL(int len) {     for (L = 2; L <= len; L <<= 1)       ;     ivL = inv(L);     for (int i = (0), _ = (L); i < _; ++i)       rev[i] = (rev[i >> 1] >> 1) | ((i & 1) ? (L >> 1) : 0);   }   inline void cpy(int *a, int *b, int len) {     for (int i = (0), _ = (len); i <= _; ++i) a[i] = b[i];   }   inline void clr(int *a, int l, int r) {     for (int i = (l), _ = (r); i <= _; ++i) a[i] = 0;   }   inline void mov(int *a, int *b, int len) {     for (int i = (0), _ = (L); i < _; ++i) a[i] = (i <= len) ? b[i] : 0;   }   void NTT(int *a, int kd) {     int i, j, k, u, v, W, Wn;     for (int i = (0), _ = (L); i < _; ++i)       if (i < rev[i]) swap(a[i], a[rev[i]]);     for (i = 2; i <= L; i <<= 1)       for (Wn = pwg[kd][i], j = 0; j < L; j += i)         for (W = 1, k = j; k < j + i / 2; ++k, Mul(W, Wn))           u = a[k], v = mul(a[k + i / 2], W), a[k] = pls(u, v),           a[k + i / 2] = mns(u, v);     if (kd)       for (int i = (0), _ = (L); i < _; ++i) Mul(a[i], ivL);   }   void conv(int *A, int *B, int *C, int n, int m, int lim) {     static int a[maxN], b[maxN];     getL(n + m);     mov(a, A, n), mov(b, B, m);     NTT(a, 0), NTT(b, 0);     for (int i = (0), _ = (L); i < _; ++i) Mul(a[i], b[i]);     NTT(a, 1);     cpy(C, a, lim);   }   void conv2(int *A, int *C, int n, int lim) {     static int a[maxN];     getL(n + n);     mov(a, A, n);     NTT(a, 0);     for (int i = (0), _ = (L); i < _; ++i) Mul(a[i], a[i]);     NTT(a, 1);     cpy(C, a, lim);   }   void Inv(int *A, int *X, int n) {     static int a[maxN], b[maxN];     if (n == 0) {       X[0] = inv(A[0]);       return;     }     int mid = n >> 1;     Inv(A, a, mid), clr(a, mid + 1, n);     conv2(a, b, mid, n);     conv(b, A, b, n, n, n);     for (int i = (0), _ = (n); i <= _; ++i) X[i] = mns(pls(a[i], a[i]), b[i]);   }   }  // namespace poly   int calc(int a, int b) {     return pls(pls(pls(mul(f[0][0][a], h[0][0][b]), mul(f[0][1][a], h[1][0][b])),                    mul(f[1][0][a], h[0][1][b])),                mul(f[1][1][a], h[1][1][b]));   }   void calc_h(int L, int R) {     static int a[maxN], b[maxN];     if (L == R) {       for (int l = (0), _ = (1); l <= _; ++l)         for (int r = (0), _ = (1); r <= _; ++r) Add(h[l][r][L], f[l][r][L]);       return;     }     int M = (L + R) >> 1;     calc_h(L, M);     for (int l = (0), _ = (1); l <= _; ++l)       for (int m = (0), _ = (1); m <= _; ++m)         for (int r = (0), _ = (1); r <= _; ++r) {           for (int i = (L), _ = (M); i <= _; ++i) a[i - L] = h[l][m][i];           for (int i = (1), _ = (R - L); i <= _; ++i) b[i] = f[m][r][i - 1];           b[0] = 0;           poly::conv(a, b, a, M - L, R - L, R - L);           for (int i = (M + 1), _ = (R); i <= _; ++i) Add(h[l][r][i], a[i - L]);         }     calc_h(M + 1, R);   }   int main() {     poly::init();     n = rd<int>();     g[0] = 1, g[2] = g[4] = mod - 1;     poly::Inv(g, g, n);     for (int i = (0), _ = (n); i <= _; ++i) {       Add(f[0][0][i], g[i]);       Add(f[0][1][i + 1], g[i]);       Add(f[1][0][i + 1], g[i]);       Add(f[1][1][i + 2], g[i]);     }     for (int i = (0), _ = (n); i <= _; ++i)       for (int l = (0), _ = (1); l <= _; ++l)         for (int r = (0), _ = (1); r <= _; ++r) Mul(f[l][r][i], mul(i, i));     calc_h(0, n);     int res = 0;     for (int i = (2), _ = (n); i <= _; ++i)       Add(res, mul(i - 1, calc(i - 2, n - i)));     Add(res, mul(n, pls(f[0][0][n - 1], f[1][1][n - 1])));     printf( %d n , res);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using pii = pair<int, int>;   const int mx = 2e5 + 9;   int game[2][mx];   int f_occ[2][mx];   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       int x;       scanf( %d , &x);       x--;       game[x][i]++;     }     memset(f_occ, -1, sizeof f_occ);     for (auto x : {0, 1}) {       for (int i = 1; i <= n; i++) {         game[x][i] += game[x][i - 1];         if (f_occ[x][game[x][i]] != -1) continue;         f_occ[x][game[x][i]] = i;       }     }     vector<pii> ans;     for (int t = 1; t <= n; t++) {       int s = 0;       int last[] = {0, 0};       int win[] = {0, 0};       int idx = 0;       int latest = -1;       while (true) {         int next[] = {0, 0};         for (auto x : {0, 1}) next[x] = last[x] + t;         int f[] = {0, 0};         for (auto x : {0, 1}) f[x] = f_occ[x][next[x]];         if (f[0] == -1 and f[1] == -1) break;         if (f[0] == -1) {           last[0] = game[0][f[1]];           last[1] = game[1][f[1]];           idx = f[1];           win[1]++;           latest = 1;           continue;         }         if (f[1] == -1) {           last[0] = game[0][f[0]];           last[1] = game[1][f[0]];           idx = f[0];           win[0]++;           latest = 0;           continue;         }         if (f[0] < f[1]) {           last[0] = game[0][f[0]];           last[1] = game[1][f[0]];           idx = f[0];           win[0]++;           latest = 0;         } else {           last[0] = game[0][f[1]];           last[1] = game[1][f[1]];           idx = f[1];           win[1]++;           latest = 1;         }       }       if (idx != n) continue;       if (win[0] == win[1]) continue;       if (win[latest] < win[1 - latest]) continue;       s = win[latest];       ans.emplace_back(s, t);     }     sort(ans.begin(), ans.end());     printf( %d n , (int)ans.size());     for (auto [s, t] : ans) {       printf( %d %d n , s, t);     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     long long n, k, t;     cin >> n;     string s;     cin >> s;     int a1 = 0, a2 = 0;     int flag1 = 0;     int flag2 = 0;     while (1) {       flag1 = 0;       flag2 = 0;       for (int i = 0; i < n; i++) {         if (s[i] ==  D ) {           flag1 = 1;           if (a2 != 0) {             a2--;             s[i] =  A ;             continue;           }           a1++;         } else if (s[i] ==  R ) {           flag2 = 1;           if (a1 != 0) {             a1--;             s[i] =  A ;             continue;           }           a2++;         } else {           continue;         }       }       if (flag1 == 0 || flag2 == 0) {         break;       }     }     if (flag1 == 1)       cout <<  D  << endl;     else if (flag2 == 1)       cout <<  R  << endl;   }


#include <bits/stdc++.h>   using namespace std;   int n, k, p[111], c[111], l[111], bottleneck[111], par[111], cost[111][111];   bitset<200005> prime;   vector<vector<int> > vert;   int edmondskarp(int s, int t) {     int mf = 0;     while (1) {       memset(bottleneck, 0, sizeof(bottleneck));       bottleneck[s] = 1e9;       par[s] = s;       queue<int> q;       q.push(s);       while (!q.empty() && !bottleneck[t]) {         int u = q.front();         q.pop();         for (int i = 0; i < vert[u].size(); i++) {           int v = vert[u][i];           if (cost[u][v] > 0 && !bottleneck[v]) {             q.push(v);             par[v] = u;             bottleneck[v] = min(bottleneck[u], cost[u][v]);           }         }       }       if (!bottleneck[t]) break;       mf += bottleneck[t];       for (int u = t; par[u] != u; u = par[u]) {         cost[par[u]][u] -= bottleneck[t];         cost[u][par[u]] += bottleneck[t];       }     }     return mf;   }   int ok(int x) {     int idx = 0;     p[0] = -1;     for (int i = 1; i <= n; i++) {       if (c[i] == 1 && l[i] <= x && p[i] > p[idx]) {         idx = i;       }     }     vert.assign(111, vector<int>());     memset(cost, 0, sizeof(cost));     for (int i = 1; i <= n; i++) {       if (l[i] > x) continue;       if (c[i] & 1) continue;       if (c[i] == 1) continue;       for (int j = 1; j <= n; j++) {         if (l[j] > x) continue;         if (i == j) continue;         if (c[j] == 1) continue;         if (prime[c[i] + c[j]]) {           vert[i].push_back(j);           vert[j].push_back(i);           cost[i][j] = 1e9;         }       }     }     int s = 101, t = 102;     for (int i = 1; i <= n; i++) {       if (l[i] > x) continue;       if (c[i] & 1) continue;       if (c[i] == 1) continue;       vert[s].push_back(i);       vert[i].push_back(s);       cost[s][i] = p[i];     }     for (int i = 1; i <= n; i++) {       if (l[i] > x) continue;       if (!(c[i] & 1)) continue;       if (c[i] == 1) continue;       vert[i].push_back(t);       vert[t].push_back(i);       cost[i][t] = p[i];     }     if (idx) {       vert[idx].push_back(t);       vert[t].push_back(idx);       cost[idx][t] = p[idx];       for (int i = 1; i <= n; i++) {         if (l[i] > x) continue;         if (c[i] & 1) continue;         if (!prime[1 + c[i]]) continue;         vert[i].push_back(idx);         vert[idx].push_back(i);         cost[i][idx] = 1e9;       }     }     int sum = 0;     for (int i = 1; i <= n; i++) {       if (l[i] > x || c[i] == 1) continue;       sum += p[i];     }     if (idx) sum += p[idx];     int ek = edmondskarp(s, t);     return sum - ek >= k;   }   int main() {     scanf( %d %d , &n, &k);     for (int i = 1; i <= n; i++) {       scanf( %d%d%d , &p[i], &c[i], &l[i]);     }     prime.set();     prime[0] = prime[1] = 0;     for (long long i = 2; i <= 200000; i++) {       if (prime[i]) {         for (long long j = i * i; j <= 200000; j += i) {           prime[j] = 0;         }       }     }     if (!ok(n)) {       printf( %d n , -1);       return 0;     }     int lo = 0, hi = n;     while (hi - lo > 1) {       int m = (lo + hi) / 2;       if (ok(m))         hi = m;       else         lo = m;     }     printf( %d n , hi);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 5;   const int M = 1e7 + 5;   int x[N];   int cnt[M];   bool vis[M + 5];   int f[M + 5];   int sum[M + 5];   void erato() {     for (int i = 2; i <= M; i++) vis[i] = true;     for (int i = 2; i <= M; i++) {       if (vis[i]) {         f[i] += cnt[i];         for (int j = 2; j <= M / i; j++) {           vis[j * i] = false;           f[i] += cnt[j * i];         }       }     }   }   int main() {     int n, m;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &x[i]);       cnt[x[i]]++;     }     erato();     sum[0] = 0;     for (int i = 1; i <= M - 5; i++) sum[i] += (sum[i - 1] + f[i]);     scanf( %d , &m);     while (m--) {       int l, r;       scanf( %d%d , &l, &r);       if (l >= M - 5) {         printf( 0 n );         continue;       }       if (r >= M - 5) r = M - 5;       printf( %d n , sum[r] - sum[l - 1]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MAX = 5005;   vector<long long> arr(MAX);   long long solve(long long l, long long r, long long cur) {     if (l > r) return 0;     long long mn = arr[l], idx = l;     for (int i = l; i <= r; i++) {       if (arr[i] < mn) {         mn = arr[i];         idx = i;       }     }     return min(r - l + 1,                solve(l, idx - 1, mn) + solve(idx + 1, r, mn) + mn - cur);   }   int main() {     ios_base::sync_with_stdio(0);     int n;     cin >> n;     int ans = 0;     for (int i = 0; i < n; i++) cin >> arr[i];     cout << solve(0, n - 1, 0) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t_;     cin >> t_;     while (t_--) {       int n;       cin >> n;       vector<int> a(n);       for (int i = 0; i < n; i++) {         cin >> a[i];       }       int turns = 0;       int alice = 0;       int bob = n - 1;       int alice_candies = 0;       int bob_candies = 0;       int alice_candies_previous = 0;       int bob_candies_previous = 0;       while (alice <= bob) {         turns++;         alice_candies_previous = 0;         while (alice <= bob && alice_candies_previous <= bob_candies_previous) {           alice_candies += a[alice];           alice_candies_previous += a[alice];           alice++;         }         if (alice <= bob) {           turns++;           bob_candies_previous = 0;           while (alice <= bob && bob_candies_previous <= alice_candies_previous) {             bob_candies += a[bob];             bob_candies_previous += a[bob];             bob--;           }         }       }       cout << turns <<     << alice_candies <<     << bob_candies << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct ee {     int x, y, w;   };   vector<int> ke[300010], kq;   int n, m, s, c[300010] = {0}, p[300010], b[300010];   ee e[300010];   priority_queue<pair<long long, int> > Q;   long long d[300010];   void enter() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; ++i) {       scanf( %d%d%d , &e[i].x, &e[i].y, &e[i].w);       ke[e[i].x].push_back(i);       ke[e[i].y].push_back(-i);     }     scanf( %d , &s);   }   void dijkstra() {     for (int i = 1; i <= n; ++i) d[i] = 1e18;     d[s] = 0;     Q.push(pair<long long, int>(0, s));     int u, v;     long long w;     while (!Q.empty()) {       u = Q.top().second;       w = -Q.top().first;       Q.pop();       if (d[u] != w) continue;       for (vector<int>::iterator i = ke[u].begin(); i != ke[u].end(); ++i) {         v = (*i > 0 ? e[*i].y : e[-*i].x);         if (w + e[abs(*i)].w < d[v]) {           d[v] = w + e[abs(*i)].w;           Q.push(pair<long long, int>(-d[v], v));           p[v] = abs(*i);         } else if (w + e[abs(*i)].w == d[v] && e[abs(*i)].w < e[p[v]].w)           p[v] = abs(*i);       }     }   }   bool compare(int i, int j) { return e[i].w < e[j].w; }   int Find(int u) {     if (p[u] < 0) return u;     return p[u] = Find(p[u]);   }   void process() {     long long ans = 0;     int t;     for (int i = 1; i <= m; ++i)       if (abs(d[e[i].x] - d[e[i].y]) != e[i].w)         continue;       else {         t = (d[e[i].x] > d[e[i].y] ? e[i].x : e[i].y);         if (i != p[t]) continue;         ans += e[i].w;         kq.push_back(i);       }     cout << ans <<   n ;     for (vector<int>::iterator i = kq.begin(); i != kq.end(); ++i)       printf( %d  , *i);   }   int main() {     enter();     dijkstra();     process();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 2e3 + 10, INF = 1e9 + 10;   long long dp[N][2], a[N], n, k;   inline bool check(long long x) {     for (long long i = 1; i <= n; i++) dp[i][0] = i - 1;     for (long long i = 1; i <= n; i++)       for (long long j = i - 1; j; --j) {         if (a[i] + (i - j) * x < a[j] || a[i] - (i - j) * x > a[j]) continue;         dp[i][0] = min(dp[i][0], dp[j][0] + i - j - 1);       }     for (long long i = n; i; i--) dp[i][1] = n - i;     for (long long i = n; i; i--)       for (long long j = i + 1; j <= n; ++j) {         if (a[i] + (j - i) * x < a[j] || a[i] - (j - i) * x > a[j]) continue;         dp[i][1] = min(dp[i][1], dp[j][1] + j - i - 1);       }     for (long long i = 1; i <= n; i++)       if (dp[i][0] + dp[i][1] <= k) return 1;     return 0;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> k;     if (k == n) return cout <<  0 , 0;     for (long long i = 1; i <= n; i++) cin >> a[i];     long long lo = 0, hi = 2e9 + 5;     while (hi - lo > 0) {       long long mid = (hi + lo) / 2;       if (check(mid))         hi = mid;       else         lo = mid + 1;     }     cout << lo;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long t;     cin >> t;     while (t--) {       long long n;       cin >> n;       cout << n << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int N, A[100001], BIT[100001], res[100001];   vector<int> v;   map<int, int> m;   int main() {     scanf( %d , &N);     for (int i = 1; i <= N; ++i) scanf( %d , &A[i]), v.push_back(A[i]);     sort(v.begin(), v.end());     v.resize(unique(v.begin(), v.end()) - v.begin());     int n = v.size();     for (int i = 0; i < n; ++i) m[v[i]] = i + 1;     for (int i = N; i >= 1; --i) {       int mx = 0;       for (int x = m[A[i]] - 1; x > 0; x -= x & -x)         if (mx < BIT[x]) mx = BIT[x];       res[i] = ((mx - i - 1 >= 0) ? (mx - i - 1) : -1);       for (int x = m[A[i]]; x <= n; x += x & -x)         if (!BIT[x]) BIT[x] = i;     }     for (int i = 1; i <= N; ++i) printf( %d  , res[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n, k, m;     cin >> n >> k >> m;     map<string, int> mp;     vector<int> cost(n);     for (int i = 0; i < n; ++i) {       string str;       cin >> str;       mp[str] = i;     }     for (int i = 0; i < n; ++i) {       cin >> cost[i];     }     for (int i = 0; i < k; ++i) {       int t, mn = INT_MAX;       cin >> t;       stack<int> st;       while (t--) {         int x;         cin >> x;         --x;         st.push(x);         mn = min(mn, cost[x]);       }       while (!st.empty()) {         cost[st.top()] = mn;         st.pop();       }     }     long long sum = 0;     for (int i = 0; i < m; ++i) {       string str;       cin >> str;       sum += cost[mp[str]];     }     cout << sum;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t, n, i, j, k, mini = INT_MAX, maxi = 0;     cin >> t;     while (t--) {       mini = INT_MAX;       maxi = 0;       cin >> n >> k;       int a[n];       for (i = 0; i < n; i++) {         scanf( %d , &a[i]);         mini = min(mini, a[i]);         maxi = max(maxi, a[i]);       }       if ((maxi - mini) > 2 * k) {         cout << -1 << endl;         continue;       } else {         cout << (mini + k) << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   struct re {     long long x[300300];     long long up[300300];     bool f[300300];   };   int o;   re rmq;   void f_read() {     int i, n, a[100100];     cin >> n;     for (i = 0; i < n; ++i) cin >> a[i];     o = 1;     memset(rmq.x, 0, sizeof(rmq.x));     memset(rmq.up, 0, sizeof(rmq.up));     memset(rmq.f, 0, sizeof(rmq.f));     while (o < n) o *= 2;     for (i = 0; i < n; ++i) rmq.x[i + o] = a[i];     for (i = o - 1; i > 0; --i)       rmq.x[i] = ((rmq.x[i * 2]) < (rmq.x[i * 2 + 1]) ? (rmq.x[i * 2 + 1])                                                       : (rmq.x[i * 2]));   }   void RPUSH(int v) {     if (!rmq.f[v]) return;     rmq.f[v * 2] = 1;     rmq.up[v * 2] = rmq.up[v];     rmq.f[v * 2 + 1] = 1;     rmq.up[v * 2 + 1] = rmq.up[v];     rmq.x[v] = rmq.up[v];     rmq.f[v] = 0;   }   long long RMAX(int l, int r, int v = 1, int cl = 1, int cr = o) {     if (l > r) return 0;     if (l == cl && r == cr) {       if (rmq.f[v])         return rmq.up[v];       else         return rmq.x[v];     }     RPUSH(v);     int t = (cl + cr) >> 1;     long long a = RMAX(l, ((r) > (t) ? (t) : (r)), v * 2, cl, t),               b = RMAX(((t + 1) < (l) ? (l) : (t + 1)), r, v * 2 + 1, t + 1, cr);     return ((a) < (b) ? (b) : (a));   }   long long RADD(int l, int r, long long d, int v = 1, int cl = 1, int cr = o) {     if (l > r)       if (rmq.f[v])         return rmq.up[v];       else         return rmq.x[v];     if (l == cl && r == cr) {       rmq.f[v] = 1;       rmq.up[v] = d;       return d;     }     RPUSH(v);     int t = (cl + cr) >> 1;     long long a = RADD(l, ((t) > (r) ? (r) : (t)), d, v * 2, cl, t),               b = RADD(((t + 1) < (l) ? (l) : (t + 1)), r, d, v * 2 + 1, t + 1,                        cr);     rmq.x[v] = ((a) < (b) ? (b) : (a));     return rmq.x[v];   }   int main() {     f_read();     int i, m, w, h;     cin >> m;     for (i = 0; i < m; ++i) {       cin >> w >> h;       long long t = RMAX(1, w);       cout << t << endl;       RADD(1, w, h + t);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 3e5 + 10;   const long long MOD = 1e9 + 7;   long long n, x[N], ans, pw[N], dp[N], num[N];   inline long long add(long long a, long long b) {     a += b;     while (a >= MOD) a -= MOD;     return a;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.setf(ios::fixed);     cout.precision(20);     cin >> n;     for (int i = 0; i < n; ++i) cin >> x[i];     if (n == 1) {       cout << 0 <<   n ;       return 0;     }     sort(x, x + n);     pw[0] = 1;     for (int i = 1; i <= n; ++i) {       pw[i] = add(pw[i - 1], pw[i - 1]);     }     dp[1] = x[1] - x[0];     num[1] = 1;     for (int i = 2; i < n; ++i) {       long long now = x[i] - x[i - 1];       dp[i] = add(dp[i - 1], num[i - 1] * now);       dp[i] = add(dp[i], dp[i]);       dp[i] = add(dp[i], now);       num[i] = add(num[i - 1], num[i - 1]);       num[i] = add(num[i], 1);     }     for (int i = 0; i < n; ++i) ans = add(ans, dp[i]);     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   template <class A, class B>   A cvt(B x) {     stringstream ss;     ss << x;     A y;     ss >> y;     return y;   }   typedef struct {     string name;     int c;     int p[3];     int size;     int room;   } item;   typedef struct {     string name;     int c;     int bonus;     string home;   } resident;   int n, k;   map<string, item> items;   map<string, vector<string> > itres;   map<string, resident> residents;   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       string name, c;       int a, d, r, s;       cin >> name >> c >> a >> d >> r >> s;       if (c ==  weapon ) items[name] = (item){name, 0, {a, d, r}, s, s};       if (c ==  armor ) items[name] = (item){name, 1, {a, d, r}, s, s};       if (c ==  orb ) items[name] = (item){name, 2, {a, d, r}, s, s};     }     cin >> k;     for (int i = 0; i < k; i++) {       string name, c, home;       int b;       cin >> name >> c >> b >> home;       if (c ==  gladiator ) residents[name] = (resident){name, 0, b, home};       if (c ==  sentry ) residents[name] = (resident){name, 1, b, home};       if (c ==  physician ) residents[name] = (resident){name, 2, b, home};       items[home].room--;       itres[home].push_back(name);     }     int move = 0;     for (typeof(items.begin()) it = items.begin(); it != items.end(); it++)       if (it->second.room > 0) move = 1;     if (!move) {       vector<pair<int, pair<int, string> > > v;       for (typeof(items.begin()) it = items.begin(); it != items.end(); it++) {         string name = it->first;         int cl = it->second.c;         int val = it->second.p[cl];         for (typeof(itres[name].begin()) itr = itres[name].begin();              itr != itres[name].end(); itr++) {           if (residents[*itr].c == cl) val += residents[*itr].bonus;         }         v.push_back(make_pair(cl, make_pair(-val, name)));       }       sort(v.begin(), v.end());       int i = 0;       for (int t = 0; t < 3; t++) {         while (v[i].first != t) i++;         string name = v[i].second.second;         cout << name <<     << itres[name].size();         for (typeof(itres[name].begin()) itr = itres[name].begin();              itr != itres[name].end(); itr++)           cout <<     << *itr;         cout << endl;       }     } else {       vector<pair<int, string> > r[3];       for (typeof(residents.begin()) itr = residents.begin();            itr != residents.end(); itr++) {         r[itr->second.c].push_back(make_pair(itr->second.bonus, itr->first));       }       int sum[3][1005];       for (int t = 0; t < 3; t++) {         sort(r[t].begin(), r[t].end());         reverse(r[t].begin(), r[t].end());         sum[t][0] = 0;         for (int i = 1; i <= r[t].size(); i++) {           sum[t][i] = sum[t][i - 1] + r[t][i - 1].first;         }       }       pair<int, pair<int, int> > best = make_pair(-1, make_pair(-1, -1));       pair<string, vector<string> > out[3];       set<string> used;       for (typeof(items.begin()) it0 = items.begin(); it0 != items.end(); it0++)         if (it0->second.c == 0)           for (typeof(items.begin()) it1 = items.begin(); it1 != items.end();                it1++)             if (it1->second.c == 1)               for (typeof(items.begin()) it2 = items.begin(); it2 != items.end();                    it2++)                 if (it2->second.c == 2) {                   int sz0 = min(it0->second.size, (int)r[0].size());                   int sz1 = min(it1->second.size, (int)r[1].size());                   int sz2 = min(it2->second.size, (int)r[2].size());                   pair<int, pair<int, int> > rez =                       make_pair(it0->second.p[0] + sum[0][sz0],                                 make_pair(it1->second.p[1] + sum[1][sz1],                                           it2->second.p[2] + sum[2][sz2]));                   if (rez > best) {                     best = rez;                     used.clear();                     vector<string> x0, x1, x2;                     for (int i = 0; i < sz0; i++) {                       x0.push_back(r[0][i].second);                       used.insert(r[0][i].second);                     }                     for (int i = 0; i < sz1; i++) {                       x1.push_back(r[1][i].second);                       used.insert(r[1][i].second);                     }                     for (int i = 0; i < sz2; i++) {                       x2.push_back(r[2][i].second);                       used.insert(r[2][i].second);                     }                     out[0] = make_pair(it0->first, x0);                     out[1] = make_pair(it1->first, x1);                     out[2] = make_pair(it2->first, x2);                   }                 }       for (int t = 0; t < 3; t++) {         for (typeof(residents.begin()) itr = residents.begin();              itr != residents.end(); itr++) {           if (out[t].second.size() == items[out[t].first].size) break;           if (used.count(itr->first) == 0) {             out[t].second.push_back(itr->first);             used.insert(itr->first);           }         }         cout << out[t].first <<     << out[t].second.size();         for (int i = 0; i < out[t].second.size(); i++)           cout <<     << out[t].second[i];         cout << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int mxN = 1e5, M = 1e9 + 7, I3 = 333333336;   int n, m, eu[mxN], ev[mxN], ew[mxN], c2, px[mxN];   vector<int> adj[mxN], c;   long long ans = 1, ans2, ca;   bool vis[mxN], vis2[mxN];   void dfs(int u, int p) {     vis[u] = 1;     for (int e : adj[u]) {       int v = eu[e] ^ ev[e] ^ u;       if (v == p) continue;       if (vis[v]) {         if (vis2[e]) continue;         vis2[e] = 1;         if (!v) {           c2 = px[u] ^ ew[e];         } else {           c.push_back(px[u] ^ px[v] ^ ew[e]);         }       } else {         px[v] = px[u] ^ ew[e];         dfs(v, u);       }     }   }   vector<int> gv(vector<int> &c) {     vector<int> a;     for (int i = 0; i < c.size(); ++i) {       int j = 0;       while (j < a.size()) {         c[i] = min(c[i], a[j] ^ c[i]);         ++j;       }       a.push_back(c[i]);     }     sort(a.begin(), a.end());     return a;   }   vector<array<int, 2>> bmv, s2mv, s1mv;   map<int, int> sm;   void iv(vector<int> &c, int d) {     int bm = 0;     for (int ci : c) bm |= 1 << ci;     if (c.size() > 2) {       bmv.push_back({bm, d});     } else {       sm[bm] = (sm[bm] + d) % M;     }   }   vector<int> av(vector<int> a, int b) {     for (int i = 0; i < 32; ++i)       if (b >> i & 1) {         int j = 0, x = i;         while (j < a.size()) {           x = min(x, x ^ a[j]);           ++j;         }         a.push_back(x);         if (!x) swap(a[0], a.back());       }     return a;   }   void dfs2(vector<int> &a, int i, int j) {     ans2 = (ans2 + ca) % M;     if (a.size() < 4) {       for (; i < s2mv.size(); ++i) {         vector<int> b = av(a, s2mv[i][0]);         if (!b[0]) continue;         long long da = ca;         ca = ca * s2mv[i][1] % M;         dfs2(b, i + 1, j);         ca = da;       }     }     if (a.size() < 5) {       for (; j < s1mv.size(); ++j) {         vector<int> b = av(a, s1mv[j][0]);         if (!b[0]) continue;         long long da = ca;         ca = ca * s1mv[j][1] % M;         dfs2(b, i, j + 1);         ca = da;       }     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m;     for (int i = 0; i < m; ++i) {       cin >> eu[i] >> ev[i] >> ew[i], --eu[i], --ev[i];       adj[eu[i]].push_back(i);       adj[ev[i]].push_back(i);     }     vis[0] = 1;     for (int e : adj[0]) {       int u = eu[e] ^ ev[e];       if (vis[u]) continue;       c.clear();       c2 = -1;       px[u] = ew[e];       dfs(u, 0);       if (c2 == -1) {         if (!c.size()) {           ans = ans * 2 % M;         } else {           vector<int> a = gv(c);           if (a[0]) iv(c, 1);         }       } else {         if (c.size()) {           vector<int> a = gv(c);           if (a[0]) {             iv(c, 2);             c.push_back(c2);             a = gv(c);             if (a[0]) iv(c, 1);           }         } else {           ans = ans * 3 % M;           if (c2) {             c.push_back(c2);             iv(c, I3);           }         }       }     }     for (pair<int, int> p : sm) {       if (__builtin_popcount(p.first) == 1)         s1mv.push_back({p.first, p.second});       else         s2mv.push_back({p.first, p.second});     }     for (array<int, 2> a : bmv) {       vector<int> b;       b = av(b, a[0]);       ca = a[1];       dfs2(b, 0, 0);     }     vector<int> b;     ca = 1;     dfs2(b, 0, 0);     cout << ans * ans2 % M;   }


#include <bits/stdc++.h>   using namespace std;   struct arr {     int l, r, add, cnt, sum[50];   } a[110005 * 4];   int data[110005], i, n, m, opt, L, R;   const int P = 95542721;   inline int calc(int x) {     while (x > 47) x -= 48;     return x;   }   inline void down(int k) {     if (!a[k].cnt || a[k].l == a[k].r) return;     int W = a[k].cnt;     a[k].cnt = 0;     a[(k << 1)].add = calc(a[(k << 1)].add + W);     a[(k << 1)].cnt = calc(a[(k << 1)].cnt + W);     a[(k << 1 | 1)].add = calc(a[(k << 1 | 1)].add + W);     a[(k << 1 | 1)].cnt = calc(a[(k << 1 | 1)].cnt + W);   }   inline void up(int k) {     for (int i = 0; i < 48; i++)       a[k].sum[i] = (a[(k << 1)].sum[calc(a[(k << 1)].add + i)] +                      a[(k << 1 | 1)].sum[calc(a[(k << 1 | 1)].add + i)]) %                     P;   }   void build(int k, int l, int r) {     a[k].l = l;     a[k].r = r;     a[k].add = a[k].cnt = 0;     if (l == r) {       a[k].sum[0] = data[l];       for (int i = 1; i <= 47; i++)         a[k].sum[i] = (a[k].sum[i - 1] * 1ll * a[k].sum[i - 1] % P * 1ll *                        a[k].sum[i - 1] % P);       return;     }     int mid = (l + r) >> 1;     if (l <= mid) build((k << 1), l, mid);     if (r > mid) build((k << 1 | 1), mid + 1, r);     for (int i = 0; i < 48; i++)       a[k].sum[i] = (a[(k << 1)].sum[i] + a[(k << 1 | 1)].sum[i]) % P;   }   void update(int k) {     if (L <= a[k].l && a[k].r <= R) {       a[k].cnt = calc(a[k].cnt + 1);       a[k].add = calc(a[k].add + 1);       return;     }     down(k);     int mid = (a[k].l + a[k].r) >> 1;     if (L <= mid) update((k << 1));     if (R > mid) update((k << 1 | 1));     a[k].add = 0;     up(k);   }   int Query(int k) {     if (L <= a[k].l && a[k].r <= R) return a[k].sum[calc(a[k].add)];     down(k);     int res = 0;     int mid = (a[k].l + a[k].r) >> 1;     if (L <= mid) res = Query((k << 1));     if (R > mid) (res += Query((k << 1 | 1))) %= P;     return res;   }   int main() {     scanf( %d , &n);     for (i = 1; i <= n; i++) scanf( %d , &data[i]);     build(1, 1, n);     scanf( %d , &m);     while (m--) {       scanf( %d%d%d , &opt, &L, &R);       if (opt == 1)         printf( %d n , Query(1));       else         update(1);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   const int _inf = 0xc0c0c0c0;   const long long INF = 0x3f3f3f3f3f3f3f3f;   const long long _INF = 0xc0c0c0c0c0c0c0c0;   const long long mod = (int)1e9 + 7;   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   long long ksm(long long a, long long b, long long mod) {     int ans = 1;     while (b) {       if (b & 1) ans = (ans * a) % mod;       a = (a * a) % mod;       b >>= 1;     }     return ans;   }   long long inv2(long long a, long long mod) { return ksm(a, mod - 2, mod); }   void exgcd(long long a, long long b, long long &x, long long &y, long long &d) {     if (!b) {       d = a;       x = 1;       y = 0;     } else {       exgcd(b, a % b, y, x, d);       y -= x * (a / b);     }   }   int dp[10025];   int main() {     int c, d, n, m, k, V, ans = inf;     scanf( %d%d , &c, &d);     scanf( %d%d , &n, &m);     scanf( %d , &k);     memset(dp, 0x3f, sizeof(dp));     dp[0] = 0;     for (int j = n; j <= n * m; ++j) {       dp[j] = min(dp[j], dp[j - n] + c);     }     for (int j = 1; j <= n * m; ++j) {       dp[j] = min(dp[j], dp[j - 1] + d);     }     for (int i = n * m - k; i <= n * m; ++i) {       ans = min(ans, dp[i]);     }     printf( %d n , ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const string str =  VC ;   const int maxn = 300;   char s[2];   int l, n, m;   char buf[maxn];   int alpha[26];   vector<int> G[maxn * 2];   bool mark[maxn * 2];   int stk[maxn * 2], top;   bool dfs(int u) {     if (s[u & 1] == 0) return false;     if (mark[u ^ 1]) return false;     if (mark[u]) return true;     while (top == 2 * maxn)       ;     mark[stk[top++] = u] = true;     for (int v : G[u])       if (!dfs(v)) return false;     return true;   }   string ans;   void check(string tmp) {     if (ans ==    || tmp < ans) ans = tmp;   }   void solve(int st) {     for (int i = 0; i < 2 * n; i++) mark[i] = 0;     for (int i = 0; i < st; i++) {       top = 0;       if (!dfs(i << 1 | alpha[buf[i] -  a ])) return;     }     for (int i = 2 * st; i < 2 * n; i += 2) {       if (mark[i] || mark[i ^ 1]) continue;       top = 0;       if (s[0] < s[1]) {         if (!dfs(i)) {           while (top) mark[stk[--top]] = false;           if (!dfs(i ^ 1)) return;         }       } else {         if (!dfs(i ^ 1)) {           while (top) mark[stk[--top]] = false;           if (!dfs(i)) return;         }       }     }     string tmp(buf, buf + st);     for (int i = st; i < n; i++) tmp += s[mark[i << 1 | 1]];     check(tmp);   }   int main() {     scanf( %s , buf);     l = strlen(buf);     for (int i = l - 1; i >= 0; i--) s[alpha[i] = str.find(buf[i])] =  a  + i;     scanf( %d %d , &n, &m);     for (int i = 0; i < m; i++) {       int x, y;       scanf( %d %s , &x, buf);       x--;       x = x << 1 | str.find(buf[0]);       scanf( %d %s , &y, buf);       y--;       y = y << 1 | str.find(buf[0]);       G[x].push_back(y);       G[y ^ 1].push_back(x ^ 1);     }     scanf( %s , buf);     for (int i = 0; i <= n; i++) {       if (i < n) {         char ch = buf[i];         for (buf[i]++; buf[i] <  a  + l; buf[i]++) solve(i + 1);         buf[i] = ch;       } else         solve(n);     }     if (ans !=   )       puts(ans.c_str());     else       puts( -1 );   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   int n, k, x, sum, a[24], BadPoint[2], dp[(1 << 24)];   int32_t main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i];     cin >> k;     for (int i = 0; i < k; i++) cin >> BadPoint[i];     dp[0] = 1;     for (int mask = 1; mask < (1 << n); mask++) {       sum = 0;       for (int i = 0; i < n; i++) {         if ((mask >> i) & 1) {           dp[mask] += dp[(mask ^ (1 << i))];           if (dp[mask] >= MOD) dp[mask] -= MOD;           sum += a[i];         }       }       for (int i = 0; i < k; i++)         if (sum == BadPoint[i]) dp[mask] = 0;     }     cout << dp[(1 << n) - 1];   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n;     cin >> n;     int a = 2, b = 3, c = 5, d = 7;     int ab = 6, ac = 10, ad = 14, bc = 15, bd = 21, cd = 35;     int abc = 30, bcd = 105, abd = 42, acd = 70;     int abcd = 210;     cout << n - (n / a + n / b + n / c + n / d) +                 (n / ab + n / ac + n / ad + n / bc + n / bd + n / cd) -                 (n / abc + n / bcd + n / abd + n / acd) + n / abcd;   }


#include <bits/stdc++.h>   using namespace std;   pair<int, int> ar[110];   set<int> se;   int findstart(int k) {     while (ar[k].first != 0) k = ar[k].first;     return k;   }   int findend(int k) {     while (ar[k].second != 0) k = ar[k].second;     return k;   }   void addalltoend(int i) {     se.insert(ar[i].second);     while (ar[i].second != 0) {       i = ar[i].second;       se.insert(ar[i].second);     }   }   int main() {     int n, en, nen;     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> ar[i].first >> ar[i].second;     }     int i = 0;     while (ar[i].first == 0 && ar[i].second == 0 && i != n + 1) {       i++;     }     if (n == 1) {       cout << 0 <<     << 0;       return 0;     }     if (n != 1 && i == n + 1) {       for (i = 1; i < n; i++) {         cout << i - 1 <<     << i + 1 <<   n ;       }       cout << i - 1 <<     << 0 <<   n ;       return 0;     }     i = findstart(i);     en = findend(i);     se.insert(i);     addalltoend(i);     se.erase(0);     for (set<int>::const_iterator it = se.begin(); it != se.end(); it++)       for (int i = 1; i <= n; i++) {         if (ar[i].first == 0 && ar[i].second != 0 &&             se.find(ar[i].second) == se.end()) {           ar[en].second = i;           ar[i].first = en;           i = findstart(i);           addalltoend(i);           en = findend(i);         }       }     for (int i = 1; i <= n; i++) {       if (ar[i].first == 0 && ar[i].second == 0) {         ar[en].second = i;         ar[i].first = en;         en = i;       }     }     for (int i = 1; i <= n; i++)       cout << ar[i].first <<     << ar[i].second <<   n ;     for (set<int>::const_iterator it = se.begin(); it != se.end(); it++) return 0;   }


#include <bits/stdc++.h>   using namespace std;   void calc(int n, int p) {     int j = 1, k = 1;     int cnt = 0;     int here = 1;     for (int i = 0; i < 2 * n + p; i++) {       cout << j <<    ;       j += k;       if (j > n) j -= n;       cout << j << endl;       cnt++;       int tmp = j + k;       if (tmp > n) tmp -= n;       tmp += k;       if (tmp > n) tmp -= n;       if (j == here || tmp == j) {         if (cnt == n) {           cnt = 0;           k++;           j = 1;           here = 1;         } else {           j++;           here++;         }       }     }   }   int main() {     int t;     cin >> t;     vector<pair<int, int> > out;     for (int i = 0; i < t; i++) {       int n, p;       cin >> n >> p;       calc(n, p);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int32_t main() {     long long t;     cin >> t;     while (t--) {       long long n;       cin >> n;       long long a[n];       set<long long> s;       for (long long i = 0; i < n; i++) {         cin >> a[i];         s.insert(a[i]);       }       cout << s.size() <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   int_fast64_t viz[100001], ans;   vector<int_fast64_t> v(100001);   void dfs(int_fast64_t node) {     ans++;     viz[node] = 1;     if (!viz[v[node]]) dfs(v[node]);   }   void solve() {     int_fast64_t n;     cin >> n;     for (int_fast64_t i = 1; i <= n; i++) cin >> v[i];     vector<int_fast64_t> res;     for (int_fast64_t i = 1; i <= n; i++) {       ans = 0;       if (!viz[i]) dfs(i);       res.push_back(ans);     }     sort(res.begin(), res.end());     if (res.size() > 1) {       int_fast64_t maxi = res[res.size() - 1] + res[res.size() - 2];       res.pop_back();       res.pop_back();       res.push_back(maxi);       ans = 0;       for (int_fast64_t i = 0; i < res.size(); i++) ans += res[i] * res[i];       cout << ans;     } else       cout << n * n;   }   signed main() {     cin.tie(0);     cout.tie(0);     ios_base::sync_with_stdio(0);     ;     solve();     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O2 )   using namespace std;   void solve() {     int n;     cin >> n;     set<int> s;     for (int i = 0; i < n; i++) {       int a;       cin >> a;       s.insert(a);     }     for (int cnt = 1; cnt <= 1023; cnt++) {       bool vis[1025];       memset(vis, 0, sizeof(vis));       bool h = 1;       for (auto x : s) {         if (vis[x ^ cnt] || s.count(x ^ cnt) == 0) {           h = 0;           break;         }         vis[x ^ cnt] = 1;       }       if (h) {         cout << cnt;         return;       }     }     cout << -1;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) {       solve();       cout <<   n ;     }   }


#include <bits/stdc++.h>   using namespace std;   ifstream fin( A.in );   ofstream fout( A.out );   int n, m, a, b, v[100001], viz[100001];   vector<int> G[100001];   long long sum;   struct sor {     int x, i;   } s[100001];   bool cmp(sor a, sor b) { return a.x > b.x; }   int main() {     cin >> n >> m;     for (int i = 1; i <= n; ++i) {       cin >> v[i];       s[i].x = v[i];       s[i].i = i;     }     for (int i = 1; i <= m; ++i) {       cin >> a >> b;       G[a].push_back(b);       G[b].push_back(a);     }     sort(s + 1, s + n + 1, cmp);     for (int i = 1; i <= n; ++i) {       viz[s[i].i] = 1;       for (vector<int>::iterator it = G[s[i].i].begin(); it != G[s[i].i].end();            ++it) {         if (!viz[*it]) sum += v[*it];       }     }     cout << sum;   }


#include <bits/stdc++.h>   using namespace std;   const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};   const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};   const int INF = 1000000000;   const long long LINF = 1000000000000000000;   const long long MOD = 1000000007;   const double PI = acos(-1.0);   const double EPS = 1e-10;   template <class T>   inline bool chmax(T& a, T b) {     if (a < b) {       a = b;       return true;     }     return false;   }   template <class T>   inline bool chmin(T& a, T b) {     if (a > b) {       a = b;       return true;     }     return false;   }   template <class T>   inline void add(T& a, T b) {     a = ((a + b) % MOD + MOD) % MOD;   };   int main() {     cin.tie(0);     ios::sync_with_stdio(false);     int N;     cin >> N;     vector<int> a(N);     stack<int> st;     for (int i = 0; i < N; i++) {       cin >> a[i];     }     int ma = *max_element(a.begin(), a.end());     for (int i = 0; i < N; i++) {       if (a[i] == ma) continue;       int j = i;       while (j < N && a[j] != ma) {         if (st.empty() || st.top() > a[j])           st.push(a[j]);         else if (!st.empty() && a[j] == st.top())           st.pop();         else {           cout <<  NO  << endl;           return 0;         }         j++;       }       if (!st.empty()) {         cout <<  NO  << endl;         return 0;       }       i = j;     }     cout <<  YES  << endl;   }


#include <bits/stdc++.h>   using namespace std;   template <typename... As>   struct tpl : public std::tuple<As...> {     using std::tuple<As...>::tuple;     tpl() {}     tpl(std::tuple<As...> const& b) { std::tuple<As...>::operator=(b); }     template <typename T = tuple<As...> >     typename tuple_element<0, T>::type const& x() const {       return get<0>(*this);     }     template <typename T = tuple<As...> >     typename tuple_element<0, T>::type& x() {       return get<0>(*this);     }     template <typename T = tuple<As...> >     typename tuple_element<1, T>::type const& y() const {       return get<1>(*this);     }     template <typename T = tuple<As...> >     typename tuple_element<1, T>::type& y() {       return get<1>(*this);     }     template <typename T = tuple<As...> >     typename tuple_element<2, T>::type const& z() const {       return get<2>(*this);     }     template <typename T = tuple<As...> >     typename tuple_element<2, T>::type& z() {       return get<2>(*this);     }     template <typename T = tuple<As...> >     typename tuple_element<3, T>::type const& w() const {       return get<3>(*this);     }     template <typename T = tuple<As...> >     typename tuple_element<3, T>::type& w() {       return get<3>(*this);     }   };   using lli = long long int;   using llu = long long unsigned;   using pii = tpl<lli, lli>;   using piii = tpl<lli, lli, lli>;   using piiii = tpl<lli, lli, lli, lli>;   using vi = vector<lli>;   using vii = vector<pii>;   using viii = vector<piii>;   using vvi = vector<vi>;   using vvii = vector<vii>;   using vviii = vector<viii>;   template <class T>   using min_queue = priority_queue<T, vector<T>, greater<T> >;   template <class T>   using max_queue = priority_queue<T>;   template <size_t... I>   struct my_index_sequence {     using type = my_index_sequence;     static constexpr array<size_t, sizeof...(I)> value = {{I...}};   };   namespace my_index_sequence_detail {   template <typename I, typename J>   struct concat;   template <size_t... I, size_t... J>   struct concat<my_index_sequence<I...>, my_index_sequence<J...> >       : my_index_sequence<I..., (sizeof...(I) + J)...> {};   template <size_t N>   struct make_index_sequence       : concat<typename make_index_sequence<N / 2>::type,                typename make_index_sequence<N - N / 2>::type>::type {};   template <>   struct make_index_sequence<0> : my_index_sequence<> {};   template <>   struct make_index_sequence<1> : my_index_sequence<0> {};   }  // namespace my_index_sequence_detail   template <class... A>   using my_index_sequence_for =       typename my_index_sequence_detail::make_index_sequence<sizeof...(A)>::type;   template <class T, size_t... I>   void print_tuple(ostream& s, T const& a, my_index_sequence<I...>) {     using swallow = int[];     (void)swallow{0, (void(s << (I == 0 ?    :  ,  ) << get<I>(a)), 0)...};   }   template <class T>   ostream& print_collection(ostream& s, T const& a);   template <class... A>   ostream& operator<<(ostream& s, tpl<A...> const& a);   template <class... A>   ostream& operator<<(ostream& s, tuple<A...> const& a);   template <class A, class B>   ostream& operator<<(ostream& s, pair<A, B> const& a);   template <class T, size_t I>   ostream& operator<<(ostream& s, array<T, I> const& a) {     return print_collection(s, a);   }   template <class T>   ostream& operator<<(ostream& s, vector<T> const& a) {     return print_collection(s, a);   }   template <class T, class U>   ostream& operator<<(ostream& s, multimap<T, U> const& a) {     return print_collection(s, a);   }   template <class T>   ostream& operator<<(ostream& s, multiset<T> const& a) {     return print_collection(s, a);   }   template <class T, class U>   ostream& operator<<(ostream& s, map<T, U> const& a) {     return print_collection(s, a);   }   template <class T>   ostream& operator<<(ostream& s, set<T> const& a) {     return print_collection(s, a);   }   template <class T>   ostream& print_collection(ostream& s, T const& a) {     s <<  [ ;     for (auto it = begin(a); it != end(a); ++it) {       s << *it;       if (it != prev(end(a))) s <<    ;     }     return s <<  ] ;   }   template <class... A>   ostream& operator<<(ostream& s, tpl<A...> const& a) {     s <<  ( ;     print_tuple(s, a, my_index_sequence_for<A...>{});     return s <<  ) ;   }   template <class... A>   ostream& operator<<(ostream& s, tuple<A...> const& a) {     s <<  ( ;     print_tuple(s, a, my_index_sequence_for<A...>{});     return s <<  ) ;   }   template <class A, class B>   ostream& operator<<(ostream& s, pair<A, B> const& a) {     return s <<  (  << get<0>(a) <<  ,   << get<1>(a) <<  ) ;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     lli m, n;     cin >> n >> m;     vi A(m);     for (lli i = 0; i < (lli)(m); ++i) cin >> A[i];     lli left = n;     vi B = A;     vi cs;     for (lli i = 0; i < (lli)(m); ++i) {       if (left < B[i]) {         B[i] -= left;         B[i] %= n;         left = n;       }       left -= B[i];       if (i != m - 1) cs.emplace_back(n - left);     }     cs.push_back(0);     cs.push_back(n);     sort(begin(cs), end(cs));     vi S;     for (lli i = 0; i < (lli)(m); ++i) S.push_back(cs[i + 1] - cs[i]);     int j = 0;     vvi ans;     ans.emplace_back(m);     for (lli i = 0; i < (lli)(m); ++i) {       while (A[i] > 0) {         if (j == m) {           j = 0;           ans.emplace_back(m);         }         A[i] -= S[j];         ans.back()[j] = i;         j++;       }     }     cout << ans.size() <<   n ;     for (lli i = 0; i < (lli)(m); ++i) cout << S[i] <<    ;     cout <<   n ;     for (lli t = 0; t < (lli)(ans.size()); ++t) {       for (lli j = 0; j < (lli)(m); ++j) cout << ans[t][j] + 1 <<    ;       cout <<   n ;     }     cout << flush;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   typedef int matrix[130][130];   long long n;   vector<int> v[130];   int k, q[30], d, f[30], h[130], len[30], r[30], ans;   matrix a, b, t;   char c;   int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }   void mul(matrix a, matrix b) {     for (int i = 0; i < len[0]; i++)       for (int j = 0; j < len[0]; j++) {         t[i][j] = 0;         for (int k = 0; k < len[0]; k++)           t[i][j] = (t[i][j] + a[i][k] * b[k][j]) % 12345;       }     for (int i = 0; i < len[0]; i++)       for (int j = 0; j < len[0]; j++) a[i][j] = t[i][j];   }   void pow(long long n) {     for (int i = 0; i < len[0]; i++) a[i][i] = 1;     for (int i = 0; n >> i; i++) {       if ((n >> i) & 1) mul(a, b);       mul(b, b);     }   }   int main() {     scanf( %I64d%d , &n, &k);     for (int i = 0; i < 26; i++) q[i] = 1;     for (int i = 0; i < k; i++)       scanf(  %c%d , &c, &d), c -=  A , q[c] *= d / gcd(d, q[c]),           f[c] = 1, v[c].push_back(d);     len[26] = 1;     for (int j = 25; j >= 0; j--) len[j] = len[j + 1] * q[j];     for (int j = 0; j < len[0]; j++) {       for (int i = 0; i < 26; i++) r[i] = j / len[i + 1] % q[i];       h[j] = 1;       for (int i = 0; i < 26; i++)         if (v[i].size()) {           bool fg = 0;           for (int d : v[i]) fg |= (r[i] % d == 0);           h[j] &= fg;         }       for (int i = 0; i < 26; i++)         if (f[i])           b[j][(r[i] + 1 == q[i]) ? j + len[i + 1] - len[i] : j + len[i + 1]]++;     }     pow(n);     for (int i = 0; i < len[0]; i++) ans += h[i] * a[0][i];     printf( %d n , ans % 12345);   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 7;   int n;   int cnt;   int sum;   int head[maxn];   int size[maxn];   int T[maxn];   int top;   int temp[2];   struct edge {     int u, v, w, next;   } e[maxn * 2];   void addedge(int u, int v, int w) {     e[cnt].u = u;     e[cnt].v = v;     e[cnt].w = w;     e[cnt].next = head[u];     head[u] = cnt++;   }   void add_edge(int u, int v, int w) {     addedge(u, v, w);     addedge(v, u, w);   }   void dfs(int u, int f) {     size[u] = T[u];     for (int i = head[u]; ~i; i = e[i].next) {       int v = e[i].v;       if (v != f) {         dfs(v, u);         size[u] += size[v];       }     }     if (size[u] * 3 == sum && u != e[head[0]].v) {       temp[top++] = u;       size[u] = 0;     }   }   int main() {     cnt = 0;     memset(head, -1, sizeof(head));     scanf( %d , &n);     int a, b;     sum = 0;     for (int i = 1; i <= n; i++) {       scanf( %d%d , &a, &b);       add_edge(a, i, 1);       T[i] = b;       sum += b;     }     if (sum % 3) {       cout << -1 << endl;     } else {       top = 0;       temp[0] = -1;       temp[1] = -1;       dfs(e[head[0]].v, 0);       if (temp[0] != -1 && temp[1] != -1) {         cout << temp[0] <<     << temp[1] << endl;       } else {         cout << -1 << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2000 + 10;   int a[maxn][maxn];   vector<int> G[maxn], R[maxn], topo;   bool v[maxn];   void rdfs(int now) {     v[now] = true;     for (int u : R[now])       if (!v[u]) rdfs(u);     topo.push_back(now);   }   void dfs(int now) {     v[now] = true;     for (int u : G[now])       if (!v[u]) dfs(u);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int n;     cin >> n;     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= n; ++j) {         cin >> a[i][j];         if (a[i][j]) G[i].push_back(j), R[j].push_back(i);       }     for (int i = 1; i <= n; ++i)       if (!v[i]) rdfs(i);     reverse(topo.begin(), topo.end());     memset(v, false, sizeof(v));     dfs(topo[0]);     for (int i = 1; i <= n; ++i)       if (!v[i]) return cout <<  NO  << endl, 0;     cout <<  YES  << endl;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   #pragma GCC target( sse4 )   using namespace std;   int n;   int arr[8005];   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) {       cin >> n;       multiset<int> ms;       for (int i = 0; i < n; i++) {         cin >> arr[i];         ms.insert(arr[i]);       }       int ans = 0;       for (int i = 0; i < n; i++) {         int sum = arr[i];         for (int j = i + 1; j < n; j++) {           sum += arr[j];           while (ms.find(sum) != ms.end()) {             ans++;             ms.erase(ms.find(sum));           }         }       }       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<long long> v[2];   long long get(long long a, long long b) { return (a + b != 0); }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     string s;     long long ans, x, y, a, b, c, d;     long long minx, maxx, miny, maxy, maxl, maxr, maxu, maxd;     while (t--) {       cin >> s;       x = 0;       y = 0;       minx = 0;       maxx = 0;       miny = 0;       maxy = 0;       maxl = 0;       maxr = 0;       maxu = 0;       maxd = 0;       for (auto it : s) {         if (it ==  W ) y++;         if (it ==  S ) y--;         if (it ==  A ) x--;         if (it ==  D ) x++;         maxx = max(maxx, x);         minx = min(minx, x);         maxy = max(maxy, y);         miny = min(miny, y);         maxu = max(maxu, y - miny);         maxd = max(maxd, maxy - y);         maxr = max(maxr, x - minx);         maxl = max(maxl, maxx - x);       }       a = max(maxl, maxr);       b = max(get(maxl, maxr), a - (maxl != maxr));       c = max(maxu, maxd);       d = max(get(maxu, maxd), c - (maxu != maxd));       a++;       b++;       c++;       d++;       ans = min(a * d, b * c);       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 1020;   int n, m, d, tmp;   int h[maxn], dis1[maxn], dis2[maxn];   bool mark[maxn], isaffected[maxn];   vector<int> adj[maxn];   pair<int, int> temp;   void dfsa(int v) {     for (int i = 0; i < adj[v].size(); i++) {       int u = adj[v][i];       if (!mark[u]) {         mark[u] = true;         h[u] = h[v] + 1;         dfsa(u);         if (h[u] > tmp && isaffected[u]) {           tmp = h[u];           temp.first = u;         }       }     }   }   void dfsb(int v) {     for (int i = 0; i < adj[v].size(); i++) {       int u = adj[v][i];       if (!mark[u]) {         mark[u] = true;         h[u] = h[v] + 1;         dfsb(u);         if (h[u] > tmp && isaffected[u]) {           tmp = h[u];           temp.second = u;         }       }     }   }   void dfs1(int v) {     for (int i = 0; i < adj[v].size(); i++) {       int u = adj[v][i];       if (!mark[u]) {         mark[u] = true;         dis1[u] = dis1[v] + 1;         dfs1(u);       }     }   }   void dfs2(int v) {     for (int i = 0; i < adj[v].size(); i++) {       int u = adj[v][i];       if (!mark[u]) {         mark[u] = true;         dis2[u] = dis2[v] + 1;         dfs2(u);       }     }   }   int main() {     cin >> n >> m >> d;     for (int i = 1; i <= m; i++) {       int x;       cin >> x;       isaffected[x] = true;     }     for (int i = 1; i < n; i++) {       int a, b;       cin >> a >> b;       adj[a].push_back(b);       adj[b].push_back(a);     }     mark[1] = true;     dfsa(1);     for (int i = 1; i <= n; i++) {       h[i] = 0;       mark[i] = false;     }     h[temp.first] = 0;     tmp = 0;     mark[temp.first] = true;     dfsb(temp.first);     for (int i = 1; i <= n; i++) {       mark[i] = false;     }     dis1[temp.first] = 0;     mark[temp.first] = true;     dfs1(temp.first);     for (int i = 1; i <= n; i++) {       mark[i] = false;     }     dis2[temp.second] = 0;     mark[temp.second] = true;     dfs2(temp.second);     for (int i = 1; i <= n; i++) {       mark[i] = false;     }     int ans = 0;     for (int i = 1; i <= n; i++) {       if (max(dis1[i], dis2[i]) <= d) {         ans++;       }     }     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   int c, v0, v1, a, l;   int main() {     scanf( %d %d %d %d %d , &c, &v0, &v1, &a, &l);     int s = 0, d = v0 - a;     for (int i = 1;; i++) {       d += a;       if (d >= v1) d = v1;       if (i == 1)         s += d;       else         s += d - l;       if (s >= c) {         printf( %d n , i);         return 0;       }     }   }


#include <bits/stdc++.h>   using namespace std;   template <typename T, typename U>   std::pair<T, U> operator+(const std::pair<T, U>& l, const std::pair<T, U>& r) {     return {l.first + r.first, l.second + r.second};   }   typedef void (*callback_function)(void);   const long long ZERO = 0LL;   const long long INF64 = 1e18;   const long long INF32 = 1e9;   const long long MOD = 1e9 + 7;   const long double PI = acos(-1.0L);   const long double EPS = static_cast<long double>(1e-9);   inline long long Pow(long long a, long long k) {     long long s = 1;     for (; k; k >>= 1) {       k& 1 ? s = 1LL * s * a % MOD : 0;       a = 1LL * a * a % MOD;     }     return s;   }   const long long N = 1e6 + 7;   void input() {}   void preprocess() {}   void debug() {     if (true) {     }   }   void solve() {     preprocess();     long long n, m;     cin >> n >> m;     long long a[n];     for (long long i = (0); i < (n); i++) {       cin >> a[i];     }     for (long long i = (0); i < (m); i++) {       long long L, R, x;       cin >> L >> R >> x;       L--;       x--;       long long y = L;       for (long long j = (L); j < (R); j++) {         if (a[j] < a[x]) {           y++;         }       }       cout << (y == x ?  Yes  :  No ) << endl;     }   }   void output() {}   int main() {     ios_base::sync_with_stdio(false);     cin.tie();     {       input();       solve();       output();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<long long> adj[500005];   vector<pair<long long, long long>> vc[500005];   string s;   bool ans[500005], hv[500005];   long long level[500005], sz[500005], heavy[500005], cnt[500005], col[500005];   void dfs(long long u, long long p, long long l = 1) {     sz[u] = 1, heavy[u] = -1, level[u] = l;     for (long long i = 0; i < adj[u].size(); i++) {       long long v = adj[u][i];       if (v == p) continue;       dfs(v, u, l + 1);       sz[u] += sz[v];       if (heavy[u] == -1 || sz[v] > sz[heavy[u]]) heavy[u] = v;     }   }   void Add(long long u, long long p) {     cnt[level[u]] ^= (1 << col[u]);     for (long long i = 0; i < adj[u].size(); i++) {       long long v = adj[u][i];       if (v == p || hv[v]) continue;       Add(v, u);     }   }   void dsu(long long u, long long p, bool flg) {     for (long long i = 0; i < adj[u].size(); i++) {       long long v = adj[u][i];       if (v == p || v == heavy[u]) continue;       dsu(v, u, 0);     }     if (~heavy[u]) dsu(heavy[u], u, 1), hv[heavy[u]] = 1;     Add(u, p);     for (auto v : vc[u]) {       long long ht = v.first;       long long id = v.second;       if (__builtin_popcountll(cnt[ht]) <= 1) ans[id] = 1;     }     if (~heavy[u]) hv[heavy[u]] = 0;     if (flg == 0) Add(u, p);   }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     long long i, j, k, p, q, m, n;     cin >> n >> m;     for (i = 2; i <= n; i++) {       cin >> p;       adj[p].push_back(i);       adj[i].push_back(p);     }     cin >> s;     for (i = 0; i < s.size(); i++) {       col[i + 1] = s[i] -  a ;     }     for (i = 1; i <= m; i++) {       cin >> p >> q;       vc[p].push_back({q, i});     }     dfs(1, -1);     dsu(1, -1, 0);     for (i = 1; i <= m; i++) {       if (ans[i])         cout <<  Yes               <<   n ;       else         cout <<  No               <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using llu = unsigned long long;   using ld = long double;   const double PI = acos(-1.0), g = 9.80665;   const int unseen = -1;   const ll inf = 1e18 + 505, ninf = -1e18 - 505;   const int MOD = 1000000007;   void solve(void) {     int n, p;     cin >> n >> p;     int vrtc = 0;     for (int i = 1; i <= n; i++) {       for (int j = i + 1; j <= n; j++) {         cout << i <<     << j <<   n ;         vrtc++;         if (vrtc == (2 * n + p)) return;       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     int testcase = 1;     cin >> testcase;     for (int tc = 1; tc <= testcase; tc++) {       solve();     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   void read(int &x) {     x = 0;     int f = 1;     char ch = getchar();     for (; !isdigit(ch); ch = getchar())       if (ch ==  - ) f = -f;     for (; isdigit(ch); ch = getchar()) x = x * 10 + ch -  0 ;     x *= f;   }   void print(int x) {     if (x < 0) putchar( - ), x = -x;     if (!x) return;     print(x / 10), putchar(x % 10 + 48);   }   void write(int x) {     if (!x)       putchar( 0 );     else       print(x);     putchar(  n );   }   const int maxn = 1e6 + 10;   const int inf = 1e9;   const double eps = 1e-8;   const int mod = 1e9 + 7;   char s[maxn];   vector<vector<int> > v;   stack<int> a, b;   int n;   int main() {     scanf( %s , s + 1);     n = strlen(s + 1);     for (int i = 1; i <= n; i++)       if (s[i] ==  1 ) {         if (a.empty()) return puts( -1 ), 0;         int x = a.top();         a.pop();         v[x].push_back(i);         b.push(x);       } else {         if (b.empty())           v.push_back(vector<int>{i}), a.push(v.size() - 1);         else {           int x = b.top();           b.pop();           v[x].push_back(i);           a.push(x);         }       }     if (b.size()) return puts( -1 ), 0;     write(v.size());     for (auto x : v) {       printf( %d  , x.size());       for (auto a : x) printf( %d  , a);       puts(  );     }     return 0;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:640000000 )   using namespace std;   const long long INF = (1e15) + 4;   const int N = 1e6 + 5;   const int K = 26;   int a[N];   int t[N];   int n;   int nxt[N];   int c[N];   int sum(int r) {     int result = 0;     for (; r >= 0; r = (r & (r + 1)) - 1) result ^= t[r];     return result;   }   void inc(int i, int d) {     for (; i < n; i = (i | (i + 1))) t[i] ^= d;   }   vector<pair<int, int>> z[N];   int answer[N];   int get_ans(int l, int r) {     int answer1 = c[r];     if (l > 0) answer1 ^= c[l - 1];     int answer2 = sum(r);     return (answer1 ^ answer2);   }   int main() {     scanf( %d , &n);     map<int, int> b;     for (int i = 0; i < n; i++) {       scanf( %d , &a[i]);       nxt[i] = -1;       c[i] = a[i];       if (i) c[i] ^= c[i - 1];     }     for (int i = n - 1; i >= 0; i--) {       if (b.count(a[i])) nxt[i] = b[a[i]];       b[a[i]] = i;     }     int m;     scanf( %d , &m);     for (int i = 0; i < m; i++) {       int l, r;       scanf( %d %d , &l, &r);       l--;       r--;       z[l].push_back(make_pair(r, i));     }     set<int> s;     for (int i = 0; i < n; i++) {       if (s.count(a[i]) == 0) inc(i, a[i]);       s.insert(a[i]);     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < z[i].size(); j++) {         answer[z[i][j].second] = get_ans(i, z[i][j].first);       }       inc(i, a[i]);       if (nxt[i] != -1) inc(nxt[i], a[i]);     }     for (int i = 0; i < m; i++) {       printf( %d n , answer[i]);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   namespace Flandle_Scarlet {   int n;   int a[51][51];   char tmp[51];   int s[51][51];   void Input() {     cin >> n;     for (int i = 1; i <= n; ++i) {       scanf( %s , tmp);       for (int j = 1; j <= n; ++j) {         if (tmp[j - 1] ==  # )           a[i][j] = 1;         else           a[i][j] = 0;       }     }     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= n; ++j) {         s[i][j] = s[i][j - 1] + s[i - 1][j] - s[i - 1][j - 1] + a[i][j];       }     }   }   int RSum(int a1, int b1, int a2, int b2) {     return s[a2][b2] - s[a1 - 1][b2] - s[a2][b1 - 1] + s[a1 - 1][b1 - 1];   }   int dp[51][51][51][51];   int DFS(int a1, int b1, int a2, int b2) {     if (dp[a1][b1][a2][b2]) {       return dp[a1][b1][a2][b2];     }     if (a1 == a2 and b1 == b2) {       dp[a1][b1][a2][b2] = a[a1][b1];       return dp[a1][b1][a2][b2];     }     if (RSum(a1, b1, a2, b2) == 0) {       return (dp[a1][b1][a2][b2] = 0);     }     dp[a1][b1][a2][b2] = max(a2 - a1 + 1, b2 - b1 + 1);     for (int i = a1; i < a2; ++i) {       int newans = DFS(a1, b1, i, b2) + DFS(i + 1, b1, a2, b2);       dp[a1][b1][a2][b2] = min(dp[a1][b1][a2][b2], newans);     }     for (int i = b1; i < b2; ++i) {       int newans = DFS(a1, b1, a2, i) + DFS(a1, i + 1, a2, b2);       dp[a1][b1][a2][b2] = min(dp[a1][b1][a2][b2], newans);     }     return dp[a1][b1][a2][b2];   }   void Soviet() {     DFS(1, 1, n, n);     printf( %d n , dp[1][1][n][n]);   }   void IsMyWife() {     if (0) {       freopen(  ,  r , stdin);       freopen(  ,  w , stdout);     }     Input();     Soviet();   }   };  // namespace Flandle_Scarlet   int main() {     Flandle_Scarlet::IsMyWife();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 2005;   const long long inf = 1e18 + 5;   long long n, m, x;   long long a[maxn], b[maxn];   long long ma[maxn * maxn], mb[maxn * maxn];   void input() {     cin >> n >> m;     for (long long i = 1; i <= n; ++i) {       cin >> a[i];       a[i] += a[i - 1];       ma[i] = inf;     }     for (long long i = 1; i <= m; ++i) {       cin >> b[i];       b[i] += b[i - 1];       mb[i] = inf;     }     cin >> x;   }   void slove() {     for (long long i = 1; i <= n; ++i) {       for (long long j = 0; j < i; ++j) {         ma[i - j] = min(ma[i - j], a[i] - a[j]);       }     }     for (long long i = 1; i <= m; ++i) {       for (long long j = 0; j < i; ++j) {         mb[i - j] = min(mb[i - j], b[i] - b[j]);       }     }     long long ans = 0;     for (long long i = 1; i <= n; ++i) {       for (long long j = 1; j <= m; ++j) {         if (ma[i] * mb[j] <= x) {           ans = max(ans, i * j);         }       }     }     cout << ans << endl;   }   signed main() {     ios::sync_with_stdio(false);     cin.tie(0);     input();     slove();     return 0;   }


#include <bits/stdc++.h>   const int mod = 1000000007;   const int inf = 1000000009;   const long long INF = 1000000000000000009;   const long long big = 1000000000000000;   const long double eps = 1e-9;   using namespace std;   struct odcinek {     int l, x, r, nr;   };   int suma = 1;   odcinek T[100005];   int D[1100005], M[1100005], S[1100005];   bool cmp(odcinek a, odcinek b) { return a.x < b.x; }   void lazy(int u) {     if (2 * u + 1 <= suma) {       D[2 * u] += D[u];       D[2 * u + 1] += D[u];     }     M[u] += D[u];     D[u] = 0;   }   void dodaj(int a, int b, int lo, int hi, int u, int c) {     if (b <= a) return;     lazy(u);     if (a == lo && b == hi) {       D[u] += c;       return;     }     int mid = (lo + hi) / 2;     dodaj(a, min(b, mid), lo, mid, 2 * u, c);     dodaj(max(a, mid), b, mid, hi, 2 * u + 1, c);     if (M[2 * u] + D[2 * u] >= M[2 * u + 1] + D[2 * u + 1]) {       M[u] = M[2 * u] + D[2 * u];       S[u] = S[2 * u];     } else {       M[u] = M[2 * u + 1] + D[2 * u + 1];       S[u] = S[2 * u + 1];     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie();     cout.tie();     int n;     cin >> n;     while (suma < 300000) suma *= 2;     suma *= 2;     suma--;     for (int i = suma / 2 + 1; i <= suma; i++) S[i] = i - suma / 2;     for (int i = suma / 2; i >= 1; i--) S[i] = S[2 * i];     for (int i = 1; i <= n; i++) {       int a, b, c;       cin >> a >> b >> c;       T[i] = {a, b, c, i};     }     sort(T + 1, T + n + 1, cmp);     priority_queue<pair<int, int> > Q;     int wynik = 0;     pair<int, int> skad;     for (int i = 1; i <= n; i++) {       while (!Q.empty() && -Q.top().first < T[i].x) {         pair<int, int> x = Q.top();         dodaj(T[x.second].l, T[x.second].x + 1, 1, suma / 2 + 2, 1, -1);         Q.pop();       }       dodaj(T[i].l, T[i].x + 1, 1, suma / 2 + 2, 1, 1);       lazy(1);       if (M[1] > wynik) {         wynik = M[1];         skad = make_pair(S[1], T[i].x);       }       Q.push(make_pair(-T[i].r, i));     }     cout << wynik <<   n ;     for (int i = 1; i <= n; i++) {       if (T[i].l <= skad.first && T[i].r >= skad.second && T[i].x >= skad.first &&           T[i].x <= skad.second)         cout << T[i].nr <<    ;     }     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n = 0, ans = 0, mod = 1000000009LL;     scanf( %I64d , &n);     if (n >= 5) {       vector<long long> lev(n + 1, 0);       if (n >= 3) lev[3] = 1;       if (n >= 4) lev[4] = 1;       if (n >= 5) lev[5] = 5;       for (int i = 6; i <= n; i++)         if (i % 2 == 0)           lev[i] = 1;         else           lev[i] = (2 * lev[i - 2] + 3) % mod;       long long dob = 1;       for (int i = 5; i <= n; i++)         if (lev[i] > 1) {           dob = (dob * lev[i]) % mod;           ans = (ans + 4 * dob) % mod;         }       ans = (ans + 6) % mod;       ans = (ans * ans) % mod;       ans = (ans + mod - 4) % mod;       ans = (2 * ans) % mod;       ans = (ans + 10) % mod;       printf( %I64d n , ans);     }     if (n == 1) printf( 2 n );     if (n == 2) printf( 10 n );     if (n == 3) printf( 34 n );     if (n == 4) printf( 74 n );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long gcd(long long b, long long y) { return b > 0 ? gcd(y % b, b) : y; }   long long lcm(long long b, long long y) { return b * y / gcd(b, y); }   double dis(double x1, double x2, double y1, double y2) {     double ans = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);     return sqrt(ans);   }   double random(double start, double en) {     return start + (en - start) * rand() / (RAND_MAX + 1.0);   }   map<int, vector<int> > a;   map<int, int> b;   map<int, vector<int> >::iterator it;   void dfs(int x) {     if (b[x]) return;     b[x] = 1;     cout << x <<    ;     for (int i = 0; i < a[x].size(); i++) {       dfs(a[x][i]);     }     return;   }   int main() {     int n;     while (cin >> n) {       for (int i = 1; i <= n; i++) {         int x, y;         cin >> x >> y;         a[x].push_back(y);         a[y].push_back(x);       }       int t;       for (it = a.begin(); it != a.end(); it++) {         if (it->second.size() == 1) {           t = it->first;           break;         }       }       dfs(t);     }   }


#include <bits/stdc++.h>   using namespace std;   vector<string> split(const string& s, char c) {     vector<string> v;     stringstream ss(s);     string first;     while (getline(ss, first, c)) v.emplace_back(first);     return move(v);   }   void err(vector<string>::iterator it) {}   template <typename T, typename... Args>   void err(vector<string>::iterator it, T a, Args... args) {     cerr << a <<    ;     err(++it, args...);   }   const int M = 5000100, mod = 1000000007;   struct segment_tree {     pair<int, int> T[M];     segment_tree() {}     pair<int, int> find_min(pair<int, int> a, pair<int, int> b) {       return a.first < b.first ? a : b;     }     void build(int* A, int i, int l, int r) {       if (l == r)         T[i] = make_pair(A[l], l);       else {         int m = (l + r) / 2;         build(A, 2 * i, l, m);         build(A, 2 * i + 1, m + 1, r);         T[i] = find_min(T[2 * i], T[2 * i + 1]);       }     }     void update(int i, int l, int r, int first) {       if (l == r && r == first)         T[i] = make_pair(1111111111, l);       else if (first >= l && first <= r) {         int m = (l + r) / 2;         update(2 * i, l, m, first);         update(2 * i + 1, m + 1, r, first);         T[i] = find_min(T[2 * i], T[2 * i + 1]);       }     }     pair<int, int> query(int i, int l, int r, int st, int ed) {       if (l >= st && r <= ed)         return T[i];       else if (l > ed || r < st)         return make_pair(1111111111, -1);       else {         int m = (l + r) / 2;         return find_min(query(2 * i, l, m, st, ed),                         query(2 * i + 1, m + 1, r, st, ed));       }     }   };   struct BIT {     vector<int> tree;     BIT(int n) { tree.resize(n); }     void update(int idx, int val) {       while (idx < tree.size()) {         tree[idx] += val;         idx += idx & (-idx);       }     }     int query(int idx) {       int sum = 0;       while (idx > 0) {         sum += tree[idx];         idx -= idx & (-idx);       }       return sum;     }   };   int A[M], spec[M], n;   segment_tree tree;   BIT bit(M);   long long solve(int l, int r) {     long long sum = 0;     while (l <= r) {       pair<int, int> temp = tree.query(1, 1, n, l, r);       if (temp.first == 1111111111)         break;       else if (spec[temp.first]) {         tree.update(1, 1, n, temp.second);         bit.update(temp.second, -1);         sum += solve(l, temp.second - 1);         sum += solve(temp.second + 1, r);         break;       } else {         sum += bit.query(r) - bit.query(l - 1);         tree.update(1, 1, n, temp.second);         bit.update(temp.second, -1);       }     }     return sum;   }   int main() {     ios_base::sync_with_stdio(false);     int i, j, k, m;     memset((spec), (false), sizeof(spec));     scanf( %d%d , &n, &m);     for (i = 1; i <= n; i++) scanf( %d , &A[i]);     for (j = 1; j <= m; j++) scanf( %d , &k), spec[k] = true;     tree.build(A, 1, 1, n);     for (i = 1; i <= n; i++) bit.update(i, 1);     cout << solve(1, n) << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long solve(long long h, long long n, bool left) {     if (h == 1) return left ? n : 3 - n;     long long p = 1ll << (h - 1);     if (left) {       if (n > p)         return ((long long)1 << h) + solve(h - 1, n - p, left);       else         return 1 + solve(h - 1, n, false);     } else {       if (n > p)         return 1 + solve(h - 1, n - p, true);       else         return ((long long)1 << h) + solve(h - 1, n, false);     }     return -1;   }   int main() {     int h;     cin >> h;     long long n;     cin >> n;     cout << solve(h, n, true) << endl;   }