#include <bits/stdc++.h>   using namespace std;   const int inf = 1e9 + 1;   const int N = 100123;   int z, n;   int a[N];   int best[N];   long long ans[N];   long long res;   pair<int, int> tree[N << 2];   void build(int v, int l, int r) {     if (l == r) {       tree[v] = {a[l], l};       return;     }     int mid = (l + r) >> 1;     build(2 * v, l, mid);     build(2 * v + 1, mid + 1, r);     tree[v] = max(tree[2 * v], tree[2 * v + 1]);   }   pair<int, int> query(int v, int l, int r, int ql, int qr) {     if (ql <= l && qr >= r) {       return tree[v];     }     int mid = (l + r) >> 1;     pair<int, int> res = {0, 0};     if (ql <= mid) res = max(res, query(2 * v, l, mid, ql, qr));     if (qr >= mid + 1) res = max(res, query(2 * v + 1, mid + 1, r, ql, qr));     return res;   }   int main() {     ios_base::sync_with_stdio(0);     cin >> n;     for (int i = 1; i <= n - 1; i++) {       cin >> a[i];     }     a[n] = n;     build(1, 1, n);     for (int i = 1; i <= n; i++) {       pair<int, int> b = query(1, 1, n, i, a[i]);       best[i] = b.second;     }     ans[n - 1] = 1;     res++;     for (int i = n - 2; i >= 1; i--) {       ans[i] = ans[best[i]] + (best[i] - i) + (n - a[i]);       res += ans[i];     }     cout << res << endl;   }


#include <bits/stdc++.h>   using namespace std;   const long long md = 1e9 + 7;   const int N = 2e6 + 34;   char s[N];   long long p[N];   int n, k, m;   int lst[100];   int c, cur, mn;   int main() {     scanf( %d %d n , &n, &k);     gets(s);     m = strlen(s);     for (int i = 0; i < k; i++) lst[i] = -1;     p[0] = 0;     p[1] = 1;     for (int i = 0; i < m; i++) {       c = s[i] -  a ;       cur = p[i + 1] - p[lst[c] + 1];       p[i + 2] = (p[i + 1] + cur + md) % md;       lst[c] = i;     }     for (int i = m; i < m + n; i++) {       mn = 0;       for (int j = 1; j < k; j++)         if (lst[j] < lst[mn]) mn = j;       c = mn;       cur = p[i + 1] - p[lst[c] + 1];       p[i + 2] = (p[i + 1] + cur + md) % md;       lst[c] = i;     }     cout << p[n + m + 1];     return 0;   }


#include <bits/stdc++.h>   using namespace std;   map<string, string> mp;   set<string> st;   int n;   char in[30];   string read() {     scanf(  %s , in);     return (string)in;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i += 1) {       string a = read();       string b = read();       if (st.find(b) != st.end()) {         continue;       }       st.insert(a);       if (mp.find(a) != mp.end()) {         mp[b] = mp[a];         mp.erase(a);         continue;       }       mp[b] = a;     }     printf( %d n , mp.size());     for (auto x : mp) {       if (x.second ==  _ ) {         continue;       }       printf( %s %s n , x.second.c_str(), x.first.c_str());     }   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   vector<vector<int>> p;   bool is(int val) {     int c = 0;     vector<bool> pres(n, 0);     bool flag = 0;     for (int i = 0; i < m; i++) {       c = 0;       for (int j = 0; j < n; j++) {         if (p[i][j] >= val) {           pres[j] = true;           c++;         }       }       if (c > 1) flag = 1;     }     if (!flag) return false;     bool ans = 1;     for (bool i : pres)       if (!i) return false;     return true;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int t;     cin >> t;     while (t--) {       cin >> m >> n;       p.assign(m, vector<int>(n));       int minn = INT_MAX, maxx;       for (int i = 0; i < m; i++)         for (int j = 0; j < n; j++) cin >> p[i][j];       for (int i = 0; i < n; i++) {         maxx = -1;         for (int j = 0; j < m; j++) {           maxx = max(maxx, p[j][i]);         }         minn = min(maxx, minn);       }       int l = 1, r = minn + 3;       while (r - l > 1) {         int mid = (l + r) / 2;         if (is(mid))           l = mid;         else           r = mid;       }       cout << l <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 4e5 + 123;   long long n, m, k;   int num[maxn];   int dp[maxn][5];   int presum[maxn];   int tmp[maxn];   int main(int argc, char const *argv[]) {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     std::cin >> n;     for (int i = 1; i <= n; i++) {       long long u;       std::cin >> u;       int one = 0;       while (u) {         if (u % 2 == 1) {           one++;         }         u /= 2;       }       num[i] = one;     }     long long ans = 0;     for (int i = 1; i <= n; i++) {       dp[i][1] = dp[i - 1][1];       dp[i][0] = dp[i - 1][0];       presum[i] = presum[i - 1] + num[i];       if (presum[i] % 2 == 1) {         dp[i][1] += 1;       } else {         dp[i][0] += 1;       }     }     int cur = n + 1;     for (int i = n; i >= 0; --i) {       tmp[i] = cur;       if (num[i] != 0) {         cur = i;       }     }     for (int i = 1; i <= n; i++) {       int k = presum[i - 1] % 2;       int cur = i;       int sum = num[i];       int maxx = num[i];       for (int j = 1; j < 71; j++) {         int kk = tmp[cur];         if (maxx <= sum / 2) {           ans += dp[kk - 1][k] - dp[cur - 1][k];         }         maxx = max(maxx, num[kk]);         sum += num[kk];         cur = kk;         if (cur > n) {           break;         }       }       ans += dp[n][k] - dp[cur - 1][k];     }     std::cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int cnt(long long int x) {     long long int ans = 0;     while (x) {       x /= 2;       ans++;     }     return ans;   }   int main() {     int t;     cin >> t;     while (t--) {       long long int d, m;       cin >> d >> m;       long long int temp = cnt(d) - 1;       long long int ans = d - pow(2, temp) + 2;       for (long long int i = temp - 1; i >= 0; i--) {         ans = ans * (pow(2, i) + 1);         ans %= m;       }       ans = (ans - 1) % m;       if (ans < 0) ans = m + ans;       cout << ans << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   inline int nextint() {     int res = 0;     char c = 0;     while (c <  0  || c >  9 ) c = getchar();     while (c >=  0  && c <=  9 ) {       res = res * 10 + c -  0 ;       c = getchar();     }     return res;   }   int n;   long long a[200000], b[200000];   bool good[200000];   bool ans[200000];   long long diff[200000];   const int maxh = 17;   const int maxn = (1 << maxh);   long long tree[2 * maxn];   void build() {     for (int i = maxn - 1; i; i--) tree[i] = min(tree[i + i], tree[i + i + 1]);   }   long long get(int i, int j) {     long long result = (long long)1e18;     for (i += maxn - 1, j += maxn; i + 1 != j; i >>= 1, j >>= 1) {       if (!(i & 1)) result = min(result, tree[i + 1]);       if (j & 1) result = min(result, tree[j - 1]);     }     return result;   }   long long get_min(int i, int j) {     long long result = (long long)1e18;     if (i <= j) result = get(i + 1, j + 2);     return result;   }   void go() {     memset(tree, 0, sizeof(tree));     for (int i = 0; i < (int)(n); ++i)       tree[maxn + i + 1] = tree[maxn + i] + diff[i];     build();     for (int i = 0; i < (int)(n); ++i) {       long long presum = tree[maxn + i];       long long postsum = tree[maxn + n] - presum;       long long m_main = get_min(i, n - 1);       long long m_oth = get_min(0, i - 1);       bool ok = true;       if (-presum + m_main < 0) ok = false;       if (postsum + m_oth < 0) ok = false;       good[i] = ok;     }   }   int main() {     cin >> n;     for (int i = 0; i < (int)(n); ++i) {       int _a;       scanf( %d , &_a);       a[i] = _a;     }     for (int i = 0; i < (int)(n); ++i) {       int _b;       scanf( %d , &_b);       b[i] = _b;     }     for (int i = 0; i < (int)(n); ++i) diff[i] = a[i] - b[i];     go();     for (int i = 0; i < (int)(n); ++i)       if (good[i]) ans[i] = true;     memset(good, 0, sizeof(good));     reverse(a + 1, a + n);     reverse(b, b + n);     for (int i = 0; i < (int)(n); ++i) diff[i] = a[i] - b[i];     go();     for (int i = 0; i < (int)(n); ++i)       if (good[i]) ans[(n - i) % n] = true;     int ans_size = 0;     for (int i = 0; i < (int)(n); ++i)       if (ans[i]) ans_size++;     cout << ans_size << endl;     for (int i = 0; i < (int)(n); ++i)       if (ans[i]) cout << (i + 1) <<    ;     cout << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> edges[8];   int calc(int a, int b) {     vector<int> cnt(8);     for (auto e : edges[a]) cnt[e]++;     for (auto e : edges[b]) cnt[e]++;     int sol = 0;     for (int i = 1; i <= 7; i++)       if (cnt[i] == 2) sol++;     return sol;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n, m, a, b;     cin >> n >> m;     for (int i = 0; i < m; i++) {       cin >> a >> b;       edges[a].push_back(b);       edges[b].push_back(a);     }     if (n <= 6) {       cout << m <<   n ;       return 0;     }     int mmin = 1e9;     for (int i = 1; i <= n; i++) {       for (int j = i + 1; j <= n; j++) {         mmin = min(mmin, calc(i, j));       }     }     cout << m - mmin <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 300010;   const int M = 1000010;   const int MOD = 1000000007;   const int INF = 2e9;   const double eps = 1e-8;   const double PI = acos(-1.0);   int fx[] = {1, -1, 0, 0};   int fy[] = {0, 0, 1, -1};   int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }   int lcm(int x, int y) {     x /= gcd(x, y);     return x * y;   }   int Min(int a, int b) { return a < b ? a : b; }   int Max(int a, int b) { return a > b ? a : b; }   bool prime[M + 5], isprime[M + 5];   vector<int> v;   int n, m, q, cs, ar[123456];   void sieve() {     v.push_back(2);     prime[1] = 1;     int limit = (int)sqrt(M);     for (int i = 4; i <= M; i += 2) prime[i] = 1;     for (int i = 3; i <= M; i += 2) {       if (!prime[i]) {         v.push_back(i);         if (i <= limit) {           for (int j = i * i; j <= M; j += 2 * i) prime[j] = 1;         }       }     }   }   int br[123456];   int main() {     long long n, tot = 0;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> ar[i];       tot += ar[i];     }     for (int i = 0; i < n; i++) cin >> br[i];     sort(br, br + n);     long long a = br[n - 1], b = br[n - 2];     if (tot <= a + b)       cout <<  YES ;     else       cout <<  NO ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, e = 0, st[100005], d[100005], T[100005], s[100005], Time;   struct Node {     int v, t;     double p;   };   struct {     int v, t, nx;   } edge[200005];   vector<Node> E[100005];   bool cmp(Node a, Node b) { return a.p < b.p; }   void add(int u, int v, int t) {     edge[e].v = v;     edge[e].t = t;     edge[e].nx = st[u];     st[u] = e++;   }   void dfs(int u, int fa, int t) {     s[u] = 1;     d[u] = 2 * t;     for (int i = st[u]; ~i; i = edge[i].nx) {       int v = edge[i].v;       if (v != fa) {         Node tmp;         t = edge[i].t;         tmp.v = v;         tmp.t = t;         E[u].push_back(tmp);         dfs(v, u, t);         s[u] += s[v];         d[u] += d[v];       }     }   }   void Dfs(int u) {     int m = E[u].size();     for (int i = 0; i < m; i++)       E[u][i].p = (double)d[E[u][i].v] / (double)s[E[u][i].v];     sort(E[u].begin(), E[u].end(), cmp);     for (int i = 0; i < m; i++) {       int v = E[u][i].v;       int t = E[u][i].t;       Time += t;       T[v] = Time;       Dfs(v);       Time += t;     }   }   int main() {     while (~scanf( %d , &n)) {       e = 0;       memset(st, -1, sizeof(st));       int a, b, t;       for (int i = 1; i < n; i++) {         scanf( %d%d%d , &a, &b, &t);         add(a, b, t);         add(b, a, t);       }       dfs(1, -1, 0);       Time = 0;       Dfs(1);       double ans = 0;       for (int i = 2; i <= n; i++) ans += 1.0 * T[i];       printf( %.12f n , ans / 1.0 / (n - 1));     }   }


#include <bits/stdc++.h>   const int INT_INF = 0x3f3f3f3f;   const int INT_M_INF = 0x7f7f7f7f;   const long long LL_INF = 0x3f3f3f3f3f3f3f3f;   const long long LL_M_INF = 0x7f7f7f7f7f7f7f7f;   const double pi = acos(-1.0);   using namespace std;   inline void debug(char ch) {     for (int __ii = 0; __ii < 20; ++__ii) putchar(ch);     printf(  n );   }   const double eps = 1e-8;   inline int dcmp(double a, double b) {     if (fabs(a - b) < eps) return 0;     return a < b ? -1 : 1;   }   const int dr[] = {0, 0, -1, 1, -1, -1, 1, 1};   const int dc[] = {-1, 1, 0, 0, -1, 1, -1, 1};   const int MAXN = 4000 + 10;   const int MAXT = 10000 + 10;   char s[MAXN], t[MAXN];   int main() {     memset(s, 0, sizeof s);     memset(t, 0, sizeof t);     while (scanf( %s%s , s, t) == 2) {       int slen = strlen(s), tlen = strlen(t), ans = 0;       for (int i = 0; i < slen; ++i) {         int num = 0;         for (int j = 0; j < tlen; ++j)           if (s[i + j] == t[j]) ++num;         ans = max(ans, num);       }       for (int i = 0; i < tlen; ++i) {         int num = 0;         for (int j = 0; j < slen; ++j)           if (t[i + j] == s[j]) ++num;         ans = max(ans, num);       }       printf( %d n , tlen - ans);       memset(s, 0, sizeof s);       memset(t, 0, sizeof t);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int nump;     int arr[7];     scanf( %d , &nump);     scanf( %d , &arr[0]);     for (int i = 1; i < 7; i++) {       scanf( %d , &arr[i]);       arr[i] += arr[i - 1];     }     int tmp = (nump / arr[6]), idx = 0;     if (tmp && arr[6] * tmp >= nump)       tmp = (tmp - 1) * arr[6];     else       tmp *= arr[6];     while (tmp + arr[idx] < nump) idx++;     printf( %d n , idx + 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s, s1, s2;     getline(cin, s);     getline(cin, s1);     getline(cin, s2);     int substr = s.find(s1), substr1;     int forward = 0, backward = 0;     if (substr != -1) {       substr1 = s.find(s2, substr + s1.length());       if (substr1 != -1) forward = 1;     }     string inverted;     for (substr = 0; substr <= s.length() - 1; substr++)       inverted = s[substr] + inverted;     substr = inverted.find(s1);     if (substr != -1) {       substr1 = inverted.find(s2, substr + s1.length());       if (substr1 != -1) backward = 1;     }     if (forward == 1 && backward == 0) cout <<  forward  << endl;     if (forward == 0 && backward == 1) cout <<  backward  << endl;     if (forward == 1 && backward == 1) cout <<  both  << endl;     if (forward == 0 && backward == 0) cout <<  fantasy  << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int Maxn = 50005;   char str[Maxn];   int hs[26];   int main() {     scanf( %s , str);     int len = strlen(str), cCnt = 0;     int xNum = 0, sta = 0;     bool ok = false;     int i;     for (i = 0; i < len; i++) {       if (i - sta >= 26 && cCnt + xNum == 26) {         ok = true;         for (int j = sta; j < sta + 26; j++) {           if (str[j] ==  ? ) {             for (int k = 0; k < 26; k++) {               if (hs[k] == 0) {                 hs[k] = 1;                 str[j] =  A  + k;                 break;               }             }           }         }         break;       }       if (str[i] ==  ? )         xNum++;       else {         if (hs[str[i] -  A ] == 0) {           hs[str[i] -  A ] = 1;           cCnt++;         } else {           hs[str[i] -  A ]++;           cCnt++;           for (int j = sta; j < i; j++) {             if (str[j] == str[i]) {               hs[str[j] -  A ]--;               cCnt--;               sta = j + 1;               break;             } else {               if (str[j] ==  ? )                 xNum--;               else {                 hs[str[j] -  A ]--;                 cCnt--;               }             }           }         }       }     }     if (!ok && i - sta >= 26 && cCnt + xNum == 26) {       ok = true;       for (int j = sta; j < sta + 26; j++) {         if (str[j] ==  ? ) {           for (int k = 0; k < 26; k++) {             if (hs[k] == 0) {               hs[k] = 1;               str[j] =  A  + k;               break;             }           }         }       }     }     if (ok) {       for (int i = 0; i < len; i++) {         if (str[i] ==  ? ) str[i] =  A ;       }       printf( %s n , str);     } else {       puts( -1 );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 30;   int n, a[maxn];   long long k, res;   bool check(long long x) {     long long sum = 0;     for (int i = 0; i < n; ++i) {       sum += min((long long)a[i], x);       if (sum > k) return false;     }     return true;   }   int main() {     scanf( %d%I64d , &n, &k);     long long sum = 0;     for (int i = 0; i < n; ++i) {       scanf( %d , &a[i]);       sum += a[i];     }     if (k > sum) {       printf( -1 n );       return 0;     }     long long l = 0, r = sum;     while (l <= r) {       long long m = l + (r - l) / 2;       if (check(m))         l = m + 1;       else         r = m - 1;     }     sum = 0;     for (int i = 0; i < n; ++i) sum += min((long long)a[i], r);     res = k - sum;     int st = 0, flag = 1;     for (int i = 0; i < n; ++i) {       a[i] -= min((long long)a[i], r);       if (a[i]) {         if (res == 0 && flag) {           flag = 0;           st = i;         } else if (res > 0) {           --res;           --a[i];         }       }     }     for (int i = st; i < n; ++i)       if (a[i]) printf( %d  , i + 1);     for (int i = 0; i < st; ++i)       if (a[i]) printf( %d  , i + 1);     puts(  );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int x[3], y[3], r[3];   double ansx, ansy;   bool bisecting_normal(double x1, double y1, double x2, double y2, double &a,                         double &b, double &c) {     double xm = (x1 + x2) * 0.5;     double ym = (y1 + y2) * 0.5;     double xl = x2 - x1;     double yl = y2 - y1;     if (fabs(xl) < 1.0e-10 && fabs(yl) < 1.0e-10) return false;     a = xl;     b = yl;     c = -xl * xm - yl * ym;     return true;   }   bool dividing_locus(double x1, double y1, double r1, double x2, double y2,                       double r2, double &xa, double &ya, double &ra) {     double a, b, c;     if (fabs(r1 - r2) < 1.0e-10) return false;     a = -r1 * r1;     b = r2 * r2;     c = a + b;     a /= c;     b /= c;     xa = x1 * b + x2 * a;     ya = y1 * b + y2 * a;     ra = fabs(r1 * r2 / c) * sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));     return true;   }   bool line2line() {     double a, b, c, d, e, f, g;     bisecting_normal(x[0], y[0], x[1], y[1], a, b, c);     bisecting_normal(x[0], y[0], x[2], y[2], d, e, f);     g = a * e - b * d;     if (fabs(g) < 1.0e-10) return false;     ansx = (b * f - e * c) / g;     ansy = (d * c - a * f) / g;     return true;   }   bool line2circle(int z) {     int z1, z2;     double a, b, c, d, e, s, t, u, n, xm, ym, xa1, xa2, ya1, ya2, d1, d2;     z1 = (z + 1) % 3;     z2 = (z + 2) % 3;     bisecting_normal(x[z1], y[z1], x[z2], y[z2], a, b, c);     dividing_locus(x[z], y[z], r[z], x[z1], y[z1], r[z1], s, t, u);     n = sqrt(a * a + b * b);     d = (a * s + b * t + c) / n;     if (d > u) return false;     xm = s - d * a / n;     ym = t - d * b / n;     e = sqrt(u * u - d * d);     xa1 = xm + e * b / n;     ya1 = ym - e * a / n;     xa2 = xm - e * b / n;     ya2 = ym + e * a / n;     d1 = (xa1 - x[z]) * (xa1 - x[z]) + (ya1 - y[z]) * (ya1 - y[z]);     d2 = (xa2 - x[z]) * (xa2 - x[z]) + (ya2 - y[z]) * (ya2 - y[z]);     if (d1 < d2) {       ansx = xa1;       ansy = ya1;     } else {       ansx = xa2;       ansy = ya2;     }     return true;   }   bool circle2circle() {     double a, b, c, d, f, e, s1, t1, u1, s2, t2, u2, xm, ym, xv, yv, xa1, xa2,         ya1, ya2, d1, d2;     dividing_locus(x[0], y[0], r[0], x[1], y[1], r[1], s1, t1, u1);     dividing_locus(x[0], y[0], r[0], x[2], y[2], r[2], s2, t2, u2);     xv = t2 - t1;     yv = s1 - s2;     d = xv * xv + yv * yv;     if ((u1 + u2) * (u1 + u2) < d || (u1 - u2) * (u1 - u2) > d) return false;     a = d + u1 * u1 - u2 * u2;     b = d - u1 * u1 + u2 * u2;     c = a + b;     a /= c;     b /= c;     xm = s1 * b + s2 * a;     ym = t1 * b + t2 * a;     d = sqrt(d);     xv /= d;     yv /= d;     f = (d * d + u1 * u1 - u2 * u2) / (2. * d);     e = fabs(sqrt(u1 * u1 - f * f));     xa1 = xm + e * xv;     ya1 = ym + e * yv;     xa2 = xm - e * xv;     ya2 = ym - e * yv;     d1 = (xa1 - x[0]) * (xa1 - x[0]) + (ya1 - y[0]) * (ya1 - y[0]);     d2 = (xa2 - x[0]) * (xa2 - x[0]) + (ya2 - y[0]) * (ya2 - y[0]);     if (d1 < d2) {       ansx = xa1;       ansy = ya1;     } else {       ansx = xa2;       ansy = ya2;     }     return true;   }   int main() {     bool exists;     for (int i = 0; i < 3; i++) {       cin >> x[i] >> y[i] >> r[i];     }     if (r[0] == r[1]) {       if (r[0] == r[2]) {         exists = line2line();       } else {         exists = line2circle(2);       }     } else {       if (r[0] == r[2]) {         exists = line2circle(1);       } else {         exists = circle2circle();       }     }     if (exists) {       cout << fixed << setprecision(5) << ansx <<     << ansy << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long inf = 2000000002;   pair<long long, long long> p[100005];   long long minl[100005], maxl[100005], minr[100005], maxr[100005];   int main() {     int i, j, n, a, b;     while (~scanf( %d , &n)) {       for (i = 0; i < n; i++) {         scanf( %d%d , &a, &b);         p[i] = make_pair(a - b, a + b);       }       sort(p, p + n);       minl[0] = maxl[0] = p[0].second;       for (i = 1; i < n; i++)         minl[i] = min(minl[i - 1], p[i].second),         maxl[i] = max(maxl[i - 1], p[i].second);       minr[n - 1] = maxr[n - 1] = p[n - 1].second;       for (i = n - 2; i >= 0; i--)         minr[i] = min(minr[i + 1], p[i].second),         maxr[i] = max(maxr[i + 1], p[i].second);       long long l = 0, r = 4 * inf;       while (l < r) {         long long s = (l + r) / 2;         bool can = 0;         j = 0;         for (i = 0; i < n; i++) {           while (j < n - 1 && p[j + 1].first - p[i].first <= s) j++;           if (i == 0 && j == n - 1) {             can = true;             break;           }           long long miny = inf, maxy = -inf;           if (i > 0) miny = min(minl[i - 1], miny), maxy = max(maxl[i - 1], maxy);           if (j < n - 1)             miny = min(miny, minr[j + 1]), maxy = max(maxr[j + 1], maxy);           if (maxy - miny <= s) can = true;           if (can) break;         }         if (can)           r = s;         else           l = s + 1;       }       double t = l * 0.5;       printf( %.8lf n , t);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     if (n & 1)       cout << (n - 1) / 2;     else {       int v = 1;       while (v * 2 <= n) v = v * 2;       cout << (n - v) / 2;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   const int N = 1e5 + 7, M = 1e7, OO = 0x3f3f3f3f;   int main() {     int n, m, array1[100][100], mini, maxi = -OO, i, j;     scanf( %d %d , &n, &m);     for (i = 0; i < n; ++i) {       for (j = 0; j < m; ++j) {         scanf(  %d , &array1[i][j]);       }     }     for (i = 0; i < n; ++i) {       mini = OO;       for (j = 0; j < m; ++j) {         mini = min(mini, array1[i][j]);       }       maxi = max(maxi, mini);     }     printf( %d , maxi);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     long long i, j, k, l, n, m;     long long t;     cin >> t;     while (t--) {       cin >> n >> m;       for (i = 1; i <= n; i++) {         for (j = 1; j <= m; j++) {           if (i == 1 && j == 1)             cout <<  B ;           else if (i == 1 && j >= 2)             cout <<  W ;           else             cout <<  B ;         }         cout <<   n ;       }     }   }


#include <bits/stdc++.h>   using namespace std;   vector<vector<int> > bord(312345);   vector<int> ans;   int main() {     std::ios::sync_with_stdio(false);     int n, a, b, k;     cin >> n >> a >> b >> k;     string s;     cin >> s;     int i, sumi = 0, counter = 0;     for (i = 0; i < n; i++) {       if (s[i] ==  1 ) {         counter++;       } else {         bord[counter].push_back(i + 1);       }     }     for (i = 0; i < counter + 1; i++) {       sumi += bord[i].size() / b;     }     sumi -= a;     sumi++;     cout << sumi << endl;     for (i = 0; i < counter + 1; i++) {       int val = bord[i].size();       int j = b - 1;       while (sumi) {         if (j < val) {           ans.push_back(bord[i][j]);           j += b;           sumi--;         } else {           break;         }       }     }     for (i = 0; i < ans.size(); i++) {       cout << ans[i] <<    ;     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1000000 + 10;   const int INF = 1e9 + 7;   const int MOD = 1e9 + 7;   const double eps = 1e-10;   const double pi = acos(-1);   int T, cases, n, m;   int main() {     ios::sync_with_stdio(false);     ;     cin >> n >> m;     int ans;     if (n == 1 || m == 1)       ans = n * m;     else if (n == 2 || m == 2) {       if (m == 2) swap(n, m);       if (m % 4 == 1)         ans = m / 4 * 4 + 2;       else         ans = (m + 3) / 4 * 4;     } else       ans = max((n * m) / 2, (n * m) - (n * m / 2));     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1610;   typedef int MAP[maxn][maxn];   int n, m;   MAP A, B, flag, used;   int total;   int num[maxn * maxn], que[maxn * maxn * 2];   MAP temp;   int px[] = {0, 0, 1, -1, 0}, py[] = {1, -1, 0, 0, 0};   bool isok(int x, int y) { return x >= 1 && x <= n && y >= 1 && y <= m; }   void zoomin(MAP X) {     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) {         int value = 1;         for (int x = 0; x < 5; x++)           if (isok(i + px[x], j + py[x]) && X[i + px[x]][j + py[x]] == 0)             value = 0;         temp[i][j] = value;       }     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) X[i][j] = temp[i][j];   }   void zoomout(MAP X) {     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) {         int value = 0;         for (int x = 0; x < 5; x++)           if (isok(i + px[x], j + py[x]) && X[i + px[x]][j + py[x]] == 1)             value = 1;         temp[i][j] = value;       }     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) X[i][j] = temp[i][j];   }   void bfs(int x, int y, int& index) {     index++;     int start = 1, tail = 0, sum = 0;     que[++tail] = x;     que[++tail] = y;     used[x][y] = 1;     while (start <= tail) {       x = que[start++];       y = que[start++];       flag[x][y] = index;       sum++;       for (int i = 0; i < 4; i++)         if (isok(x + px[i], y + py[i]) && !used[x + px[i]][y + py[i]] &&             B[x + px[i]][y + py[i]] == 1) {           used[x + px[i]][y + py[i]] = 1;           que[++tail] = x + px[i];           que[++tail] = y + py[i];         }     }     if (sum < 100) index--;   }   void bfs(int x, int y) {     int start = 1, tail = 0, sum = 0, index = 0;     que[++tail] = x;     que[++tail] = y;     used[x][y] = 1;     while (start <= tail) {       x = que[start++];       y = que[start++];       sum++;       for (int i = 0; i < 4; i++)         if (isok(x + px[i], y + py[i]) && !used[x + px[i]][y + py[i]] &&             A[x + px[i]][y + py[i]] == 1) {           if (!flag[x + px[i]][y + py[i]]) {             used[x + px[i]][y + py[i]] = 1;             que[++tail] = x + px[i];             que[++tail] = y + py[i];           } else {             index = flag[x + px[i]][y + py[i]];           }         }     }     if (sum > 2) num[index]++;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) scanf( %d , &A[i][j]);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) B[i][j] = A[i][j];     for (int i = 1; i <= 3; i++) zoomin(B);     for (int i = 1; i <= 4; i++) zoomout(B);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++)         if (!used[i][j] && B[i][j]) bfs(i, j, total);     memset(used, 0, sizeof(used));     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++)         if (!used[i][j] && A[i][j] && !flag[i][j]) bfs(i, j);     sort(num + 1, num + 1 + total);     cout << total << endl;     for (int i = 1; i <= total; i++) cout << num[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   int main(void) {     int n, sum = 0;     scanf( %d , &n);     getchar();     char str[n];     gets(str);     for (int i = 0; i < n; i++) {       if (str[i] ==  + )         sum++;       else if (str[i] ==  -  && sum != 0)         sum--;     }     printf( %d n , sum);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n, m;       cin >> n >> m;       int a[n], s = 0;       for (int i = 0; i < n; i++) {         cin >> a[i];         s += a[i];       }       if (s >= m)         cout << m << endl;       else         cout << s << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 10, inf = 0x3f3f3f3f;   int sa[N];   int rk[N];   int tmp[N];   int lcp[N];   char s[N], t[N];   int n, k;   bool cmp(int i, int j) {     if (rk[i] != rk[j])       return rk[i] < rk[j];     else {       int ri = i + k <= n ? rk[i + k] : -1;       int rj = j + k <= n ? rk[j + k] : -1;       return ri < rj;     }   }   void build(char *s, int *sa) {     n = strlen(s);     for (int i = 0; i <= n; i++) {       sa[i] = i;       rk[i] = i < n ? s[i] : -1;     }     for (k = 1; k <= n; k *= 2) {       sort(sa, sa + n + 1, cmp);       tmp[sa[0]] = 0;       for (int i = 1; i <= n; i++) {         tmp[sa[i]] = tmp[sa[i - 1]] + (cmp(sa[i - 1], sa[i]) ? 1 : 0);       }       for (int i = 0; i <= n; i++) {         rk[i] = tmp[i];       }     }   }   void LCP(char *s, int *sa, int *lcp) {     n = strlen(s);     for (int i = 0; i <= n; i++) rk[sa[i]] = i;     int h = 0;     lcp[0] = 0;     for (int i = 0; i < n; i++) {       int j = sa[rk[i] - 1];       for (h ? h-- : 0; j + h < n && i + h < n && s[j + h] == s[i + h]; h++)         ;       lcp[rk[i] - 1] = h;     }   }   int st[N], pos[N];   int main() {     int T;     scanf( %d , &T);     while (T--) {       scanf( %s , s);       int n = strlen(s);       build(s, sa);       LCP(s, sa, lcp);       for (int i = 0; i < n; i++) {       }       int now = 0;       lcp[n] = 0;       long long ans = 0;       for (int i = 1; i <= n; i++) {         int newpos = i, len = lcp[i];         while (now > 0 && st[now] > len) {           long long v1 = st[now] - max(st[now - 1], len);           long long v2 = i - pos[now] + 1;           ans += v1 * v2 * v2;           newpos = pos[now--];         }         st[++now] = len;         pos[now] = newpos;       }       for (int i = 0; i < n; i++) {         ans += n - i - max(lcp[rk[i] - 1], lcp[rk[i]]);       }       printf( %lld n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 2000;   int n, m, k, t, a[MAX_N + 1], b[MAX_N + 1], p[MAX_N + 1];   vector<int> x;   vector<int> y;   int main() {     int i, j, ans = 0;     scanf( %d , &n);     for (i = 1; i <= n; i++) scanf( %d , a + i);     for (i = 1; i <= n; i++) scanf( %d , b + i), p[b[i]] = i;     for (i = 1; i <= n; i++) {       for (k = i;; k++)         if (p[a[k]] == i) break;       while (k != i) {         for (j = i; j <= k; j++)           if (p[a[j]] >= k) {             x.push_back(k);             y.push_back(j);             ans += k - j;             swap(a[j], a[k]);             k = j;           }       }     }     printf( %d n%d n , ans, x.size());     for (i = 0; i < x.size(); i++) printf( %d %d n , x[i], y[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long a, b;     cin >> a >> b;     cout << fixed << setprecision(7) << a * pow(double(1.000000011), b) << endl;   }


#include <bits/stdc++.h>   using namespace std;   const int inf = 1000000000;   long long mod = 1000000007LL;   long long mod2 = 998244353LL;   int n, m, k;   bool a[1000005];   int main() {     cin >> n >> m >> k;     memset(a, false, sizeof(a));     for (int i = 1; i <= n; ++i) {       int ai;       scanf( %d , &ai);       a[ai] = true;     }     int ans = 0;     deque<int> dq;     for (int i = 1; i <= 1000001; ++i) {       if (a[i]) {         dq.push_back(i);       }       while (!dq.empty() && i - dq.front() >= m) {         dq.pop_front();       }       if (i >= m) {         int det = dq.size() - (k - 1);         if (det > 0) {           for (int j = 1; j <= det; ++j) {             dq.pop_back();             ans++;           }         }       }     }     cout << ans << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int cnt[5005][5005];   int len;   char st[5005];   bool palin[5005][5005];   void updateFreq(int r, int c) {     int cc;     while (r <= len) {       cc = c;       while (cc <= len) {         cnt[r][cc]++;         cc += (cc & (-cc));       }       r += (r & (-r));     }   }   int readFreq(int r, int c) {     int ret = 0;     int cc;     while (r > 0) {       cc = c;       while (cc > 0) {         ret += cnt[r][cc];         cc -= (cc & (-cc));       }       r -= (r & (-r));     }     return ret;   }   int main() {     scanf( %s , st + 1);     len = strlen(st + 1);     int q;     scanf( %d , &q);     for (int d = 0, lets_stop_here = (int)len + 1; d < lets_stop_here; d++) {       for (int i = 1, lets_stop_here = (int)len; i <= lets_stop_here; i++) {         int j = i + d;         if (j > len) break;         if (i == j)           palin[i][j] = true;         else if (j - i == 1)           palin[i][j] = st[i] == st[j] ? true : false;         else if (palin[i + 1][j - 1])           palin[i][j] = st[i] == st[j] ? true : false;         else           palin[i][j] = false;         if (palin[i][j]) updateFreq(i, j);       }     }     while (q--) {       int l, r;       scanf( %d %d , &l, &r);       int ans = readFreq(r, r) - readFreq(r, l - 1) - readFreq(l - 1, r) +                 readFreq(l - 1, l - 1);       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   const int maxn = 1e5 + 51;   const int mod1 = 1e9 + 7;   const int mod2 = 1e9 + 9;   std::vector<std::pair<int, int>> g[maxn];   int dfn[maxn], idx = 0;   int f[maxn], fw[maxn];   int xr;   std::vector<std::vector<int>> V;   void dfs(int u, int fa) {     dfn[u] = ++idx;     for (auto x : g[u]) {       int v = x.first, w = x.second;       if (v == fa) continue;       if (!dfn[v]) {         f[v] = u, fw[v] = w;         dfs(v, u);       } else if (dfn[v] > dfn[u]) {         std::vector<int> vec;         int cur = w;         for (int now = v; now ^ u; now = f[now]) cur ^= fw[now];         vec.push_back(cur ^ w);         for (int now = v; now ^ u; now = f[now]) vec.push_back(cur ^ fw[now]);         xr ^= cur;         V.push_back(vec);       }     }   }   int add(int x, int y, const int& mod) {     x += y;     return (x >= mod) ? x - mod : x;   }   int dec(int x, int y, const int& mod) {     x -= y;     return (x < 0) ? x + mod : x;   }   int n, m;   int main() {     std::ios::sync_with_stdio(false);     std::cin.tie(nullptr);     std::cout.tie(nullptr);     std::cin >> n >> m;     for (int i = 1; i <= m; i++) {       int u, v, w;       std::cin >> u >> v >> w;       g[u].push_back({v, w});       g[v].push_back({u, w});       xr ^= w;     }     dfs(1, 0);     static int a[1 << 17 | 3], b[1 << 17 | 3];     auto fwt = [&](int* f, int lim, const int& inv, const int& mod) {       for (int len = 1; len < lim; len <<= 1) {         for (int i = 0; i < lim; i += len << 1) {           for (int j = 0; j < len; j++) {             int x = f[i + j], y = f[i + j + len];             f[i + j] = add(x, y, mod);             f[i + j + len] = dec(x, y, mod);             if (inv > 1)               f[i + j] = 1ll * f[i + j] * inv % mod,                     f[i + j + len] = 1ll * f[i + j + len] * inv % mod;           }         }       }     };     a[xr] = 1, b[xr] = 1;     fwt(a, 1 << 17, 1, mod1);     fwt(b, 1 << 17, 1, mod2);     static int c[1 << 17 | 3], d[1 << 17 | 3];     for (auto v : V) {       memset(c, 0, sizeof(c));       memset(d, 0, sizeof(d));       for (auto x : v) c[x]++, d[x]++;       fwt(c, 1 << 17, 1, mod1);       fwt(d, 1 << 17, 1, mod2);       for (int i = 0; i < (1 << 17); i++) {         a[i] = 1ll * a[i] * c[i] % mod1;         b[i] = 1ll * b[i] * d[i] % mod2;       }     }     fwt(a, 1 << 17, (mod1 + 1) >> 1, mod1);     fwt(b, 1 << 17, (mod2 + 1) >> 1, mod2);     for (int i = 0; i < (1 << 17); i++)       if (a[i] || b[i]) {         std::cout << i <<     << a[i] <<   n ;         return 0;       }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 9;   const long long mod = 998244353;   long long dp[N][1 << 7];   int s[N][1 << 7], st[N], Log[1 << 7];   struct node {     int v, id;   } a[N];   bool cmp(node a, node b) { return a.v > b.v; }   void upd(long long &a, long long b) {     if (a < b) a = b;   }   int main() {     int n, p, k;     for (int i = (1); i < (N); ++i) st[i] = st[i >> 1] + (i & 1);     for (int i = (0); i < (7); ++i) Log[1 << i] = i;     scanf( %d%d%d , &n, &p, &k);     for (int i = (1); i < (n + 1); ++i) {       scanf( %d , &a[i].v);       a[i].id = i;     }     sort(a + 1, a + 1 + n, cmp);     int op = (1 << p) - 1;     for (int i = (1); i < (n + 1); ++i)       for (int j = (0); j < (p); ++j) scanf( %d , &s[i][j]);     for (int i = (1); i < (p + k + 1); ++i) {       for (int mask = (0); mask < (1 << p); ++mask) {         if (st[mask] > i - 1) continue;         upd(dp[i - st[mask]][mask], dp[i - st[mask] - 1][mask] + a[i].v);         int pos = op ^ mask;         while (pos) {           upd(dp[i - st[mask] - 1][mask | ((pos) & (-pos))],               dp[i - st[mask] - 1][mask] + s[a[i].id][Log[((pos) & (-pos))]]);           pos ^= ((pos) & (-pos));         }       }     }     for (int i = (p + k + 1); i < (n + 1); ++i) {       for (int mask = (1 << p) - 1; mask >= (0); --mask) {         int pos = mask;         while (pos) {           upd(dp[k][mask],               dp[k][mask ^ ((pos) & (-pos))] + s[a[i].id][Log[((pos) & (-pos))]]);           pos ^= ((pos) & (-pos));         }       }     }     printf( %lld , dp[k][op]);   }


#include <bits/stdc++.h>   using namespace std;   long long ans[100010];   long long ans2[100010];   int main() {     int n, p;     int l, r;     while (cin >> n >> p) {       for (int i = 0; i < n; i++) {         scanf( %d%d , &l, &r);         ans[i] = r / p - l / p;         ans2[i] = r - l + 1;         if (l % p == 0) ans[i]++;       }       ans[n] = ans[0];       ans2[n] = ans2[0];       double anss = 0;       for (int i = 0; i < n; i++)         anss += ((ans[i] * (ans2[i + 1] - ans[i + 1]) +                   (ans2[i] - ans[i]) * ans[i + 1] + ans[i] * ans[i + 1]) *                  1.0) /                 (ans2[i] * ans2[i + 1] * 1.0) * 2000;       printf( %.10llf , anss);     }     return 0;   }


#include <bits/stdc++.h>   #pragma warning(disable : 4996)   using namespace std;   int IT_MAX = 1 << 17;   const long long MOD = 5000000;   const int INF = 1034567891;   const long long LL_INF = 1234567890123456789ll;   const double PI = 3.141592653589793238;   const double ERR = 1E-11;   int in[200050];   int lr[200050][2];   int v[200050];   int main() {     int N, T, K, i, j;     scanf( %d %d %d , &N, &T, &K);     for (i = 1; i <= T; i++) scanf( %d , &in[i]);     in[0] = 1;     for (i = 1; i < T; i++) {       lr[i][1] = in[i] - 1;       lr[i][0] = max(0, in[i] - in[i + 1]);     }     lr[T][0] = lr[T][1] = in[T];     int mn = 0, mx = 0;     for (i = 1; i <= T; i++) mn += lr[i][0], mx += lr[i][1];     if (K < mn || mx < K) return !printf( -1 n );     int t = K - mn;     for (i = 1; i <= T; i++) {       int t2 = min(t, lr[i][1] - lr[i][0]);       t -= t2;       v[i] = in[i] - (lr[i][0] + t2);     }     v[0] = 1;     printf( %d n , N);     int pst = 1;     for (i = 1; i <= T; i++) {       int st = pst + in[i - 1];       for (j = 0; j < v[i - 1]; j++) printf( %d %d n , pst + j, st + j);       for (j = v[i - 1]; j < in[i]; j++) printf( %d %d n , pst, st + j);       pst = st;     }     return 0;   }


#include<bits/stdc++.h>   #define LL long long   #define dl double   #define P pair<int,int>   using namespace std;      const int N = 2e5 + 10;      int n;   struct ghb{     int a,b;     bool operator < (const ghb &o)const{       return min(a,b) < min(o.a,o.b);     }   }f[N];   LL ans;   int mx;      int main(){     // freopen( in.txt , r ,stdin);     // freopen( o.txt , w ,stdout);     std::ios::sync_with_stdio(false);     std::cin.tie(nullptr);     cin >> n;     for(int i = 1;i <= n;i++)cin >> f[i].a;     for(int i = 1;i <= n;i++)cin >> f[i].b;     for(int i = 1;i <= n;i++)ans += abs(f[i].a - f[i].b);     sort(f + 1,f + n + 1);     int mx_1 = 0,mx_2 = 0;     for(int i = 1;i <= n;i++){       if(f[i].a > f[i].b){         if(mx_1)mx = max(mx,min(mx_1,f[i].a) - f[i].b);         mx_2 = max(mx_2,f[i].a);       }       else {         if(mx_2)mx = max(mx,min(mx_2,f[i].b) - f[i].a);         mx_1 = max(mx_1,f[i].b);       }     }     cout << ans - 2 * mx << endl;     return 0;   }   /**/


#include <bits/stdc++.h>   using namespace std;   long long GCD(long long a, long long b) { return (b == 0) ? a : GCD(b, a % b); }   bool isPrime(int x) {     for (int i = 2; i <= sqrt(x); i++)       if (x % i == 0) return 0;     return 1;   }   bool C[26];   int main() {     int n, a;     cin >> n >> a;     vector<int> v(n);     for (int i = 0; i < n; i++) {       scanf( %d , &v[i]);     }     int ans = 0;     if (a - 1 < n - a) {       reverse(v.begin(), v.end());       a = n - a + 1;     }     a--;     for (int i = 0; i < a + 1; i++) {       if (v[i] == 1 && ((2 * a - i) >= n || i == a))         ans++;       else if (v[i] == 1 && v[2 * a - i] == 1)         ans += 2;     }     cout << ans;     return 0;   }


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


#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int mid, i, j;       string a;       cin >> a;       if ((a.length()) % 2) {         cout <<  NO n ;         continue;       }       mid = (a.length()) / 2;       j = mid;       i = 0;       while (i < mid) {         if (a[i] == a[j]) {           i++;           j++;         } else {           cout <<  NO n ;           break;         }       }       if (i == mid) {         cout <<  YES n ;       }     }   }


#include <bits/stdc++.h>   const int N = 100100;   const long long mod = 1e9 + 7;   using namespace std;   int n, Xa, Ya, Xb, Yb;   int Smallest(int a, int b, int c, int d) {     int min_ = a;     if (min_ > b) min_ = b;     if (min_ > c) min_ = c;     if (min_ > d) min_ = d;     return min_;   }   int main() {     ios_base::sync_with_stdio(0);     cin >> n >> Xa >> Ya >> Xb >> Yb;     if ((Xa == Xb && (Xa == 0 || Xa == n)) || (Ya == Yb && (Ya == 0 || Ya == n)))       cout << abs(Xa - Xb) + abs(Ya - Yb) <<   n ;     else       cout << Smallest(abs(0 - Xa) + abs(0 - Ya) + abs(0 - Xb) + abs(0 - Yb),                        abs(0 - Xa) + abs(n - Ya) + abs(0 - Xb) + abs(n - Yb),                        abs(n - Xa) + abs(0 - Ya) + abs(n - Xb) + abs(0 - Yb),                        abs(n - Xa) + abs(n - Ya) + abs(n - Xb) + abs(n - Yb))            <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     scanf( %d %d , &n, &k);     int a[500005];     map<int, vector<int>> m;     set<int> s;     for (int i = 0; i < n; i++) s.insert(i);     for (int i = 0; i < n; i++) {       scanf( %d , &a[i]);       m[a[i]].push_back(i);     }     int llast = n + k;     int last = n;     int cnt = 0;     for (auto it : m) {       if (!cnt && it.second[0] < last - k) {         auto it = s.lower_bound(llast - k);         if (it != s.end()) last = *it;         cnt = 1;       }       if (it.second[0] < last - k) {         printf( NO n );         return 0;       }       for (auto it2 : it.second) {         s.erase(it2);       }       llast = last;       last = min(it.second[0], last);     }     printf( YES n );   }


#include <bits/stdc++.h>   using namespace std;   map<int, int> glosy;   map<pair<int, int>, int> parki;   int main() {     int n, m;     scanf( %d%d , &n, &m);     for (int i = (0); i < (n); i++) {       int a, b;       scanf( %d%d , &a, &b);       if (a > b) swap(a, b);       if (glosy.find(a) != glosy.end())         glosy[a]++;       else         glosy.insert(make_pair(a, 1));       if (glosy.find(b) != glosy.end())         glosy[b]++;       else         glosy.insert(make_pair(b, 1));       if (parki.find(make_pair(a, b)) != parki.end())         parki[make_pair(a, b)]++;       else         parki.insert(make_pair(make_pair(a, b), 1));     }     if (m == 0) {       cout << (n * 1LL * (n - 1LL)) / 2LL << endl;       return 0;     }     long long int res = 0LL;     vector<int> v;     for (map<int, int>::iterator it = glosy.begin(); it != glosy.end(); it++)       v.push_back(it->second);     int jeszcze = n - v.size();     sort(v.begin(), v.end());     int k = v.size();     for (int i = (0); i < (k); i++) {       vector<int>::iterator it2 = lower_bound(v.begin(), v.end(), m - v[i]);       int ile = (v.end() - it2);       if (v[i] + v[i] >= m) ile--;       if (v[i] >= m) ile += 2 * jeszcze;       res += ile * 1LL;     }     res = res / 2;     for (map<pair<int, int>, int>::iterator it = parki.begin(); it != parki.end();          it++) {       pair<int, int> para = it->first;       int a = para.first;       int b = para.second;       int x = glosy[a] + glosy[b] - it->second;       if (x < m && ((glosy[a] + glosy[b]) >= m)) res--;     }     cout << res << endl;     return 0;   }


#include <bits/stdc++.h>   const int LG = 21;   const int N = 500005;   const long long MOD = 1e9 + 7;   const long long INF = 1e9;   const long long INFLL = 1e18;   using namespace std;   void dfs(int v, int paint, vector<int> &col,            vector<vector<pair<int, int> > > &graph, vector<int> &need, int &cnt0,            int &cnt1, int &fl) {     col[v] = paint;     if (paint == -1)       cnt0++;     else       cnt1++;     if (need[v] != 0) {       if (paint == need[v])         fl = 1;       else         fl = -1;     }     for (auto p : graph[v]) {       if (col[p.first] == 0) {         dfs(p.first, p.second * paint, col, graph, need, cnt0, cnt1, fl);       }     }   }   int root[N];   vector<int> suns[N];   int cntsame[N];   int sametoroot[N];   int fl[N];   int ans;   int Root(int x) { return root[x] == x ? x : Root(root[x]); }   void complete_data(int v, int FL) {     int x = Root(v);     if (fl[x] != 0) return;     FL *= sametoroot[v];     int took_before = min(cntsame[x], (int)suns[x].size() - cntsame[x]);     ans -= took_before;     fl[x] = FL;     if (FL == 1)       ans += cntsame[x];     else       ans += suns[x].size() - cntsame[x];   }   void Merge(int v, int u, int w) {     int x = Root(v), y = Root(u);     if (x == y) return;     if (suns[x].size() > suns[y].size()) {       swap(v, u);       swap(x, y);     }     w *= sametoroot[v];     w *= sametoroot[u];     if (fl[x] == 0 && fl[y] == 0) {       ans -= min(cntsame[x], (int)suns[x].size() - cntsame[x]);       ans -= min(cntsame[y], (int)suns[y].size() - cntsame[y]);     }     if (fl[x] == 0 && fl[y] != 0) {       complete_data(x, fl[y] * w);     }     if (fl[x] != 0 && fl[y] == 0) {       complete_data(y, fl[x] * w);     }     for (auto u : suns[x]) {       suns[y].push_back(u);       sametoroot[u] *= w;       if (sametoroot[u] == 1) cntsame[y]++;     }     if (fl[x] == 0 && fl[y] == 0) {       ans += min(cntsame[y], (int)suns[y].size() - cntsame[y]);     }     root[x] = y;   }   signed main() {     srand(time(NULL));     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n, k;     cin >> n >> k;     string s;     cin >> s;     vector<vector<int> > contains(n);     for (int i = 0; i < k; i++) {       int c;       cin >> c;       for (int j = 0; j < c; j++) {         int x = 0;         cin >> x;         x--;         contains[x].push_back(i);       }     }     vector<vector<pair<int, int> > > graph(k);     vector<int> need(k, 0);     for (int i = 0; i < k; i++) root[i] = i;     for (int i = 0; i < k; i++) suns[i].push_back(i);     for (int i = 0; i < k; i++) cntsame[i] = 1;     for (int i = 0; i < k; i++) sametoroot[i] = 1;     for (int i = 0; i < n; i++) {       if (contains[i].size() == 1) {         if (s[i] ==  1 ) {           need[contains[i][0]] = -1;           complete_data(contains[i][0], -1);         } else {           need[contains[i][0]] = 1;           complete_data(contains[i][0], 1);         }       }       if (contains[i].size() == 2) {         if (s[i] ==  0 ) {           graph[contains[i][0]].push_back({contains[i][1], -1});           graph[contains[i][1]].push_back({contains[i][0], -1});           Merge(contains[i][0], contains[i][1], -1);         } else {           graph[contains[i][0]].push_back({contains[i][1], 1});           graph[contains[i][1]].push_back({contains[i][0], 1});           Merge(contains[i][0], contains[i][1], 1);         }       }       cout << ans << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 10;   vector<int> v;   set<pair<int, int> > st;   int bfs(int x) {     queue<int> q;     q.push(x);     int cnt = 0;     while (!q.empty()) {       int u = q.front();       q.pop();       cnt++;       int len = v.size();       for (int i = 0; i < len; i++, len = v.size()) {         int p = v[i];         if (st.find(make_pair(u, p)) != st.end())           continue;         else           swap(v[i], v.back()), v.pop_back(), q.push(p), i--;       }     }     return cnt;   }   int main() {     int n, m;     scanf( %d%d , &n, &m);     for (int i = 0; i < m; i++) {       int u, v;       scanf( %d%d , &u, &v);       st.insert(make_pair(u, v));       st.insert(make_pair(v, u));     }     for (int i = 1; i <= n; i++) v.push_back(i);     int ans = 0;     while (!v.empty()) {       int x = v.back();       v.pop_back();       bfs(x);       ans++;     }     printf( %d n , ans - 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool essentiallyEqual(float a, float b) {     return fabs(a - b) <= ((fabs(a) > fabs(b) ? fabs(b) : fabs(a)) * 1e-6);   }   struct TVector {     long long x, y;     TVector operator+(TVector q) const { return {x + q.x, y + q.y}; }     TVector operator-(TVector q) const { return {x - q.x, y - q.y}; }     TVector operator*(int t) const { return {x * t, y * t}; }     long long operator*(TVector q) const { return {x * q.x + y * q.y}; }     long long operator^(TVector q) const { return {x * q.y - q.x * y}; }     long double operator~() const { return {hypot(x, y)}; }     long double disPointLine(TVector p, TVector q) {       TVector r = *this;       if (((r - p) * (q - p) >= 0) && ((r - q) * (p - q) >= 0)) {         return abs((q - p) ^ (r - p)) / ~(p - q);       } else {         return min(~(r - p), ~(r - q));       }     }     bool onLine(TVector p, TVector q) {       TVector r = *this;       long double dis = r.disPointLine(p, q);       return essentiallyEqual(dis, 0);     }     long double sqrdDist(TVector p) {       return (x - p.x) * (x - p.x) + (y - p.y) * (y - p.y);     }     int orientation(TVector b, TVector c) {       TVector a = *this;       int val = (c - a) ^ (b - a);       return val;     }     int orientationV2(TVector b, TVector c) {       TVector a = *this;       int val = (c - a) ^ (b - a);       if (val == 0) return 0;       return (val > 0) ? 1 : 2;     }     void imprimePonto() { printf( %lld %lld , x, y); }   };   vector<TVector> stormtroopers;   vector<int> isShot;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int n, x0, y0;     cin >> n >> x0 >> y0;     TVector gun;     gun.x = x0;     gun.y = y0;     for (int i = 0; i < n; ++i) {       int x, y;       cin >> x >> y;       stormtroopers.push_back({x, y});       isShot.push_back(0);     }     int tiros = 0;     for (int i = 0; i < n; ++i) {       if (!isShot[i]) {         tiros++;         for (int j = i + 1; j < n; ++j) {           if (!isShot[j]) {             if (!gun.orientationV2(stormtroopers[i], stormtroopers[j]))               isShot[j] = 1;           }         }       }     }     cout << tiros << endl;     return 0;   }


#include <vector>   #include <iostream>   #include <algorithm>   #include <string>   #include <cmath>   #include <map>   #define ll long long   using namespace std;         int main()   {       ll t;       cin >> t;       while (t--) {           ll n, m;           cin >> n >> m;           string s;           vector<ll> a(n, 0);           vector<ll> b(n, 0);           vector<ll> c(m, 0);           vector<ll> result(m, 0);           vector<vector<ll>> bucket(n + 1, vector<ll>(0));              for (auto& e : a)cin >> e;           for (auto& e : b)cin >> e;           for (auto& e : c)cin >> e;              for (ll i = 0; i < n; i++)           {               if (b[i] != a[i]) {                   bucket[b[i]].push_back(i);               }           }              ll lastC = -1;           if (bucket[c[m - 1]].size() > 0) {               lastC = bucket[c[m - 1]].back();               bucket[c[m - 1]].pop_back();           }           else {               for (ll i = 0; i < n; i++)               {                   if (b[i] == c[m - 1]) {                       lastC = i;                       break;                   }               }           }              if (lastC == -1) {               cout <<  NO  << endl;           }           else {               result[m - 1] = lastC;               for (ll i = 0; i < m - 1; i++)               {                   if (bucket[c[i]].size() == 0) {                       result[i] = lastC;                   }                   else {                       result[i] = bucket[c[i]].back();                       bucket[c[i]].pop_back();                   }               }                  auto res = true;               for (ll i = 0; i < n + 1; i++)               {                   if (bucket[i].size() > 0) {                       res = false;                   }               }                  if (res == false) {                   cout <<  NO  << endl;               }               else {                   cout <<  YES  << endl;                   for (ll i = 0; i < m; i++)                   {                       cout << result[i] + 1;                       if (i < m - 1) {                           cout <<    ;                       }                       else {                           cout << endl;                       }                   }               }           }       }       return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int nmax = 1010;   const int inf = 1000000007;   int n;   pair<int, int> a[nmax];   int main() {     ios_base::sync_with_stdio(false);     cin >> n;     for (int i = 1; i <= n; ++i) cin >> a[i].first >> a[i].second;     long double ans = 1e15;     a[n + 1] = a[1];     a[n + 2] = a[2];     for (int i = 1; i <= n; ++i) {       pair<int, int> a1 = a[i], a2 = a[i + 1], a3 = a[i + 2];       long double A = a3.second - a1.second, B = a1.first - a3.first,                   C = -A * a3.first - a3.second * B;       long double d =           abs(A * a2.first + B * a2.second + C) / (sqrt((A * A + B * B)));       if (ans > d) ans = d;     }     cout << fixed << setprecision(15) << ans / (long double)2.0 <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long maxn = 1e6 + 666;   long long saveori[maxn];   long long save[maxn];   long long getcnt(long long x) {     long long cnt = 0;     while (x) {       if (x & 1) cnt++;       x = x >> 1;     }     return cnt;   }   long long cnt[maxn][2];   long long pre[maxn];   signed main() {     long long n;     cin >> n;     for (long long i = 1; i <= n; i++) {       scanf( %lld , &saveori[i]);       save[i] = getcnt(saveori[i]);     }     long long sum = 0;     for (long long i = 1; i <= n; i++) {       cnt[i][0] = cnt[i - 1][0];       cnt[i][1] = cnt[i - 1][1];       cnt[i][sum % 2]++;       sum += save[i];       pre[i] = sum;     }     long long ans = 0;     for (long long i = n; i >= 1; i--) {       long long maxval = -1;       sum = 0;       for (long long j = i; j >= i - 64 && j > 0; j--) {         sum += save[j];         maxval = max(maxval, save[j]);         if (maxval * 2 <= sum && sum % 2 == 0) {           ans++;         }       }       if (i - 65 >= 1) {         ans += cnt[i - 65][pre[i] % 2];       }     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   #define int long long int   void next(char &x){       if(x<= b ){           x++;       }else{           x= a ;       }   }   void solve() {       int n,k;       cin>>n>>k;       char cur= a ;       for(int i=0;i<n;i++){           cout<<cur;           next(cur);       }       cout<<endl;   }   signed main() {       ios::sync_with_stdio(false);       cin.tie(nullptr);       cout.tie(nullptr);       int t;       cin >> t;       while (t--){           solve();       }   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC target( avx,avx2,fma )   #pragma GCC optimization( unroll-loops )   const int mod = 1e9 + 7;   using ll = int64_t;   using namespace std;   template <int MOD_>   struct modnum {     static constexpr int MOD = MOD_;     static_assert(MOD_ > 0,  MOD must be positive );     int v;       private:     using ll = long long;     static int minv(int a, int m) {       a %= m;       assert(a);       return a == 1 ? 1 : int(m - ll(minv(m, a)) * ll(m) / a);     }       public:     modnum() : v(0) {}     modnum(ll v_) : v(int(v_ % MOD)) {       if (v < 0) v += MOD;     }     explicit operator int() const { return v; }     friend std::ostream& operator<<(std::ostream& out, const modnum& n) {       return out << int(n);     }     friend std::istream& operator>>(std::istream& in, modnum& n) {       ll v_;       in >> v_;       n = modnum(v_);       return in;     }     friend bool operator==(const modnum& a, const modnum& b) {       return a.v == b.v;     }     friend bool operator!=(const modnum& a, const modnum& b) {       return a.v != b.v;     }     modnum inv() const {       modnum res;       res.v = minv(v, MOD);       return res;     }     friend modnum inv(const modnum& m) { return m.inv(); }     modnum neg() const {       modnum res;       res.v = v ? MOD - v : 0;       return res;     }     friend modnum neg(const modnum& m) { return m.neg(); }     modnum operator-() const { return neg(); }     modnum operator+() const { return modnum(*this); }     modnum& operator++() {       v++;       if (v == MOD) v = 0;       return *this;     }     modnum& operator--() {       if (v == 0) v = MOD;       v--;       return *this;     }     modnum& operator+=(const modnum& o) {       v += o.v;       if (v >= MOD) v -= MOD;       return *this;     }     modnum& operator-=(const modnum& o) {       v -= o.v;       if (v < 0) v += MOD;       return *this;     }     modnum& operator*=(const modnum& o) {       v = int(ll(v) * ll(o.v) % MOD);       return *this;     }     modnum& operator/=(const modnum& o) { return *this *= o.inv(); }     friend modnum operator++(modnum& a, int) {       modnum r = a;       ++a;       return r;     }     friend modnum operator--(modnum& a, int) {       modnum r = a;       --a;       return r;     }     friend modnum operator+(const modnum& a, const modnum& b) {       return modnum(a) += b;     }     friend modnum operator-(const modnum& a, const modnum& b) {       return modnum(a) -= b;     }     friend modnum operator*(const modnum& a, const modnum& b) {       return modnum(a) *= b;     }     friend modnum operator/(const modnum& a, const modnum& b) {       return modnum(a) /= b;     }   };   using mi = modnum<mod>;   void solve() {     int n, m;     cin >> n;     vector<vector<int>> adj(n);     for (int i = 0; i < n - 1; i++) {       int a, b;       cin >> a >> b;       a--, b--;       adj[a].push_back(b);       adj[b].push_back(a);     }     cin >> m;     vector<mi> fac(m);     for (int i = 0; i < m; i++) {       cin >> fac[i];     }     auto comp = [&](mi X, mi Y) -> bool { return X.v < Y.v; };     sort(fac.begin(), fac.end(), comp);     if (int(fac.size()) < n - 1) {       reverse(fac.begin(), fac.end());       while (int(fac.size()) < n - 1) {         if (int(fac.size()) < n - 1) {           fac.push_back(mi(1));         }       }       reverse(fac.begin(), fac.end());     }     if (int(fac.size()) > n - 1) {       mi cur = 1;       while (int(fac.size()) >= n - 1) {         cur *= fac.back();         fac.pop_back();       }       fac.push_back(cur);     }     vector<ll> sz(n, 0), num;     function<void(int, int)> dfs = [&](int node, int par) -> void {       sz[node] = 1;       for (auto i : adj[node]) {         if (i != par) {           dfs(i, node);           sz[node] += sz[i];           num.push_back((ll)sz[i] * (n - sz[i]));         }       }     };     mi answer = 0;     dfs(0, 0);     sort(num.begin(), num.end());     assert(int(num.size()) >= n - 1);     assert(int(fac.size()) == n - 1);     for (int i = 0; i < n - 1; i++) {       mi cur = (fac[i] * num[i]);       answer += cur;     }     cout << answer <<   n ;   }   int main() {     std::ios_base::sync_with_stdio(false);     std::cin.tie(nullptr);     int t(1);     cin >> t;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   int n, a[105], z, x;   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d , a + i);       if (a[i] % 2) x++;       z += a[i];     }     if (z % 2)       printf( %d , x);     else       printf( %d , n - x);   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1000005, mod = 1000000007;   vector<int> pri;   bool vis[80];   int pos[80], a[maxn], n;   long long w[80];   long long dp[1 << 21], dp2[1 << 21], f[maxn];   void prework() {     for (int i = 2; i < (71); ++i) {       if (!vis[i]) {         pri.push_back(i);         pos[i] = (int)pri.size() - 1;         for (int j = i; j <= 70; j += i) vis[j] = 1;       }     }     f[0] = 1;     for (int i = 1; i < (maxn); ++i) f[i] = 2 * f[i - 1] % mod;   }   void init() {     scanf( %d , &n);     for (int i = 0; i < (n); ++i) {       scanf( %d , &a[i]);       w[a[i]]++;     }   }   int gao(int n) {     int tmp[30] = {0};     for (int i = 2; i <= n; ++i) {       while (n % i == 0) {         n /= i;         tmp[pos[i]] ^= 1;       }     }     if (n > 1) tmp[pos[n]] ^= 1;     int res = 0;     for (int i = 0; i < (21); ++i)       if (tmp[i]) res |= (1 << i);     return res;   }   inline int get_nx(int st1, int st2) { return st1 ^ st2; }   void solve() {     dp[0] = 1;     for (int i = 2; i < (71); ++i) {       if (!w[i]) continue;       int st = gao(i);       for (int pre = 0; pre < (1 << 19); ++pre) {         int nx_st = get_nx(st, pre);         dp2[nx_st] += dp[pre] * f[w[i] - 1] % mod;         dp2[pre] += dp[pre] * f[w[i] - 1] % mod;         dp2[nx_st] %= mod;         dp2[pre] %= mod;       }       for (int k = 0; k < (1 << 19); ++k) dp[k] = dp2[k], dp2[k] = 0;     }     long long ans = dp[0] - 1;     if (w[1]) ans = (f[w[1]]) * ans % mod + f[w[1]] - 1;     cout << ans % mod << endl;   }   int main() {     prework();     init();     solve();   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 1000000007;   ;   const int maxn = 410;   unsigned long long powmod(unsigned long long n, unsigned long long k) {     unsigned long long ret = 1;     while (k) {       if (k & 1) ret = ret * n % mod;       n = n * n % mod;       k >>= 1;     }     return ret;   }   int nxt[maxn][26];   int dp[maxn][maxn];   void upd(int& n, int k) {     if (n < 0 || n > k) n = k;   }   bool gao(const string& s, const string& t1, const string& t2) {     memset(dp, -1, sizeof(dp));     for (int i = 0; i <= t1.size(); i++)       for (int j = 0; j <= t2.size(); j++)         if (dp[i][j] >= 0 || i + j == 0) {           int p = dp[i][j] + 1;           if (i < t1.size()) {             int n = nxt[p][t1[i] -  a ];             if (n >= 0) upd(dp[i + 1][j], n);           }           if (j < t2.size()) {             int n = nxt[p][t2[j] -  a ];             if (n >= 0) upd(dp[i][j + 1], n);           }         }     return dp[t1.size()][t2.size()] >= 0;   }   char str[maxn];   char tt[maxn];   int main() {     int t;     cin >> t;     while (t--) {       cin >> str >> tt;       memset(nxt, -1, sizeof(nxt));       for (int i = strlen(str) - 1; i >= 0; i--) {         memcpy(nxt[i], nxt[i + 1], sizeof(nxt[i]));         nxt[i][str[i] -  a ] = i;       }       bool yes = false;       if (strlen(tt) == 1)         yes = (nxt[0][tt[0] -  a ] >= 0);       else {         for (int i = 0; tt[i + 1]; i++) {           char tmp = tt[i + 1];           tt[i + 1] = 0;           string t1 = tt;           tt[i + 1] = tmp;           string t2 = tt + i + 1;           if (gao(str, t1, t2)) {             yes = true;             break;           }         }       }       if (yes)         puts( YES );       else         puts( NO );     }   }


#include <bits/stdc++.h>   using namespace std;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   long long Query(long long L, long long R) {     cout << L <<     << R << endl;     fflush(stdout);     string s;     cin >> s;     if (L == R && s ==  Yes ) exit(0);     return s ==  Yes ;   }   int32_t main() {     long long n, k;     cin >> n >> k;     long long L = 1, R = n;     while (true) {       if (R - L + 1 <= 4 * k + 7) {         long long M = L + rng() % (R - L + 1);         if (Query(M, M)) {           return 0;         } else {           L = max(1LL, L - k);           R = min(n, R + k);         }       } else {         long long M = L + ((R - L) >> 1);         if (Query(L, M)) {           L = max(1LL, L - k);           R = min(n, M + k);         } else {           L = max(1LL, M - k);           R = min(n, R + k);         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   const long long MOD = (1e9 + 7);   const long long INF = (1e9 + 123456789);   const long long INFL = (INF * INF);   inline long long addm(long long a, long long b, long long m = MOD) {     return ((a + b) % m);   }   inline long long subm(long long a, long long b, long long m = MOD) {     return (((a - b) % m + m) % m);   }   inline long long mulm(long long a, long long b, long long m = MOD) {     return ((a * b) % m);   }   long long powm(long long a, long long b, long long m = MOD) {     long long ret = (!b) ? 1 : powm(a, b / 2, m);     return (!b) ? 1 : mulm(mulm(ret, ret, m), b % 2 ? a : 1, m);   }   long long gcd(long long a, long long b) { return (!b) ? a : gcd(b, a % b); }   long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }   long long inv(long long x, long long m = MOD) { return powm(x, m - 2, m); }   const int N = 1000500;   int a[N], lft[N], nxt[N];   vector<int> nodes, g[N];   struct SegmentTree {     int f, t;     SegmentTree *lc, *rc;     bool has_child, has_lazy = false;     int upd = 0;     int vmax = 0;     SegmentTree(int l, int r) {       if (l == r) {         f = t = l;         lc = rc = NULL;         has_child = false;       } else {         f = l;         t = r;         int mid = (l + r) / 2;         lc = new SegmentTree(l, mid);         rc = new SegmentTree(mid + 1, r);         has_child = true;       }     }     void change(int v) {       vmax += v;       upd += v;       has_lazy = true;     }     void push() {       if (!has_lazy) return;       lc->change(upd);       rc->change(upd);       upd = 0;       has_lazy = false;     }     void update(int l, int r, int x) {       if (r < f || l > t) return;       if (l <= f && t <= r) {         change(x);         return;       }       push();       lc->update(l, r, x);       rc->update(l, r, x);       vmax = max(lc->vmax, rc->vmax);     }     int query(int l, int r) {       if (r < f || l > t) return 0;       if (l <= f && t <= r) return vmax;       return vmax = max(lc->query(l, r), rc->query(l, r));     }   };   void solve() {     int n, k;     cin >> n >> k;     for (int i = 0; i < n; i++) cin >> a[i];     stack<int> st;     for (int i = n - 1; i >= 0; i--) {       while (!st.empty() && a[st.top()] <= a[i]) st.pop();       if (!st.empty())         nxt[i] = st.top();       else         nxt[i] = n;       st.push(i);     }     for (int i = 0; i < n; i++) g[nxt[i]].push_back(i);     function<void(int)> post = [&](int v) {       int l = (int)(nodes).size();       for (int u : g[v]) post(u);       lft[(int)(nodes).size()] = l;       nodes.push_back(v);     };     post(n);     SegmentTree root(0, n);     for (int i = 0; i < k; i++) root.update(lft[i], i, 1);     vector<int> ans;     ans.push_back(root.query(0, n));     for (int i = k; i < n; i++) {       root.update(lft[i - k], i - k, -1);       root.update(lft[i], i, 1);       ans.push_back(root.query(0, n));     }     for (int i = 0; i < (int)(ans).size(); i++) {       if (i) cout <<    ;       cout << ans[i];     }     cout <<   n ;   }   int main(int argc, char *argv[]) {     cin.sync_with_stdio(0);     cin.tie(NULL);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long N = 2e5 + 100;   long long a[N];   pair<long long, long long> ask(long long l, long long r) {     cout <<  ?   << l <<     << r << endl;     long long first;     cin >> first;     if (first == -1) exit(0);     long long f;     cin >> f;     return {first, f};   }   void solve(long long l, long long r) {     if (l > r) return;     long long first, f;     tie(first, f) = ask(l, r);     long long l1 = r + 1 - f, r1 = l - 1 + f;     if (l1 <= r1) {       for (long long i = l1; i <= r1; i++) a[i] = first;       solve(l, l1 - 1);       solve(r1 + 1, r);     } else {       long long m = (l + r) / 2;       solve(l, m);       solve(m + 1, r);     }   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n;     cin >> n;     solve(1, n);     cout <<  !  ;     for (long long i = 1; i <= n; i++) cout << a[i] <<    ;     cout << endl;   }


#include <bits/stdc++.h>   #pragma GCC optimize( Ofast,unroll-loops,fast-math )   using namespace std;   const int MAXN = 102, K = 900;   int n, m, k, u, v, x, y, t, a, b;   int A[MAXN];   short F1[MAXN][MAXN][2 * MAXN];   short F2[MAXN][MAXN][2 * MAXN];   short F3[MAXN][MAXN][2 * MAXN];   double dp[2][MAXN][MAXN];   int C(int x) { return x * (x + 1) / 2; }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> k;     k = min(k, K);     for (int i = 0; i < n; i++) cin >> A[i];     for (int l = 0; l < n; l++)       for (int r = l; r < n; r++) {         for (int i = 0; i < n; i++)           for (int j = i + 1; j < n; j++) {             bool ii = (l <= i && i <= r);             bool jj = (l <= j && j <= r);             if (ii && !jj) F1[i][j][l + r]++;             if (!ii && jj) F2[i][j][l + r]++;             if (ii && jj) F3[i][j][l + r]++;           }       }     int prev = 0, curr = 1;     for (int i = 0; i < n; i++)       for (int j = 0; j < i; j++) dp[0][i][j] = 1;     for (int x = 1; x <= k; x++) {       for (int i = 0; i < n; i++)         for (int j = i + 1; j < n; j++) {           dp[curr][i][j] = (C(i) + C(j - i - 1) + C(n - j - 1)) * dp[prev][i][j];           for (int cent = i; cent < n + i; cent++)             dp[curr][i][j] += F1[i][j][cent] * dp[prev][cent - i][j];           for (int cent = j; cent < n + j; cent++)             dp[curr][i][j] += F2[i][j][cent] * dp[prev][i][cent - j];           for (int cent = j; cent < n + i; cent++)             dp[curr][i][j] += F3[i][j][cent] * dp[prev][cent - i][cent - j];           dp[curr][i][j] /= C(n);           dp[curr][j][i] = 1. - dp[curr][i][j];         }       swap(prev, curr);     }     double ans = 0;     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++)         if (A[i] < A[j]) ans += dp[prev][i][j];     cout << setprecision(12) << fixed << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int tab[n];     long long s = 0;     for (int i = 0; i < n; i++) {       cin >> tab[i];       if (i == tab[i]) {         s++;         tab[i] = -1;       }     }     bool bo = false;     for (int i = 0; i < n; i++) {       if (tab[i] != -1) {         if (tab[tab[i]] == i) {           s += 2;           bo = false;           break;         }         bo = true;       }     }     if (bo) s++;     cout << s;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O2 )   using namespace std;   string conv(int n) {     string kq =   ;     while (n != 0) {       int r = n % 26;       if (r == 0) r = 26;       kq = char(r - 1 +  A ) + kq;       n = (n - r) / 26;     }     return kq;   }   int conv(string s) {     int kq = 0;     int n = s.size();     int tmp = 1;     for (int i = n - 1; i >= 0; i--) {       int k = int(s[i] -  A ) + 1;       kq += tmp * k;       tmp *= 26;     }     return kq;   }   int type(string s) {     if (s[0] !=  R ) return 1;     if (s[1] >=  A  && s[1] <=  Z ) return 1;     bool kt = false;     int n = s.size();     for (int i = 0; i <= n - 1; i++)       if (s[i] ==  C ) {         kt = true;         break;       }     if (!kt) return 1;     return 2;   }   void chuyen(string s) {     if (type(s) == 1) {       int n = s.size();       string x1 =   ;       int j = 0;       while (s[j] >=  A  && s[j] <=  Z ) {         x1 += s[j];         j++;       }       cout <<  R ;       for (int i = j; i <= n - 1; i++) cout << s[i];       cout <<  C  << conv(x1) <<   n ;     }     if (type(s) == 2) {       int kq = 0;       int tmp = 1;       int j = s.size() - 1;       while (s[j] >=  0  && s[j] <=  9 ) {         kq += (s[j] -  0 ) * tmp;         tmp *= 10;         j--;       }       cout << conv(kq);       for (int i = 1; i <= j - 1; i++) cout << s[i];       cout <<   n ;     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     while (n--) {       string s;       cin >> s;       chuyen(s);     }   }


#include <bits/stdc++.h>   using namespace std;   void solution() {     long long n;     cin >> n;     vector<vector<long long>> v(n, vector<long long>(n, 0));     if (n % 2 != 0) {       v[n - 1][(n - 1) / 2] = 1;       v[(n - 1) / 2][n - 1] = 1;     }     for (long long i = 0; i < n; i++) {       for (long long j = 0; j < n; j++) {         if (i == j || i == n - j - 1) v[i][j] = 1;         cout << v[i][j] <<    ;       }       cout <<   n ;     }   }   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long t;     cin >> t;     while (t--) solution();   }


#include <bits/stdc++.h>   std::vector<int> V[200010], V2[200010];   int check[200010];   std::stack<int> St;   void init(int k) {     if (check[k] == 1) return;     check[k] = 1;     for (int i = 0; i < V[k].size(); i++) init(V[k][i]);     St.push(k);   }   int color[200010];   void makeSCC(int k, int c) {     if (color[k] > 0) return;     color[k] = c;     for (int i = 0; i < V2[k].size(); i++) makeSCC(V2[k][i], c);   }   int x[200010], cost[200010];   std::vector<int> V3[200010];   int main() {     int a;     scanf( %d , &a);     for (int i = 1; i <= a; i++) scanf( %d , &x[i]);     for (int i = 1; i <= a; i++) {       int b;       scanf( %d , &b);       V[i].push_back(b);       V2[b].push_back(i);     }     for (int i = 1; i <= a; i++) init(i);     int c = 1;     while (!St.empty()) {       int k = St.top();       St.pop();       if (color[k] == 0) makeSCC(k, c++);     }     for (int i = 1; i <= a; i++) cost[i] = 123456789;     for (int i = 1; i <= a; i++)       cost[color[i]] = cost[color[i]] < x[i] ? cost[color[i]] : x[i];     for (int i = 1; i <= a; i++)       if (color[i] != color[V[i][0]]) V3[color[i]].push_back(color[V[i][0]]);     long long int ans = 0;     for (int i = 1; i <= a; i++)       if (V3[i].size() == 0 && cost[i] < 123456789) ans += cost[i];     printf( %lld , ans);   }


#include <bits/stdc++.h>   int n, ust, x, y, mark[10];   int main() {     scanf( %d , &n);     scanf( %d , &ust);     for (int i = 0; i < n; i++) {       scanf( %d %d , &x, &y);       mark[x] = 1;       mark[y] = 1;       mark[7 - x] = 1;       mark[7 - y] = 1;       if (!mark[7 - ust])         for (int j = 0; j < 7; j++) mark[j] = 0;       else {         printf( NO n );         return 0;       }     }     printf( YES n );   }


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


#include <bits/stdc++.h>   using namespace std;   const int N = 1000001;   int n, kt[N], a[N], cnt, x[N];   long long k, s;   long long cal(int i) {     long long res = i;     return res * (res + 1) / 2;   }   int main() {     scanf( %d%lld , &n, &k);     if (k < cal(n)) {       printf( -1 );       return 0;     }     for (int i = n; i > 0; i--) {       int h = n - (n - i) / 2;       if (k - h < cal(i - 1)) h = k - cal(i - 1);       k -= h;       kt[h]++;       if (kt[h] == 2) a[++cnt] = h;     }     for (int i = 1; i <= n; i++) s += kt[i] * i;     printf( %lld n , s);     for (int i = 1; i <= n; i++) {       if (kt[i] == 1)         x[i] = i;       else if (kt[i] == 0) {         x[a[cnt]] = i;         x[i] = a[cnt];         cnt--;       }     }     for (int i = 1; i <= n; i++) printf( %d  , i);     printf(  n );     for (int i = 1; i <= n; i++) printf( %d  , x[i]);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     int n, m, q;     cin >> n >> m >> q;     vector<vector<int>> r(n), c(m);     for (int i = 0; i < q; ++i) {       int x, y;       cin >> x >> y;       --x;       --y;       r[x].push_back(y);       c[y].push_back(x);     }     if (n == 1) {       cout << m - q;       return 0;     }     if (m == 1) {       cout << n - q;       return 0;     }     vector<char> used_row(n, false);     vector<char> used_col(m, false);     int ans = 0;     vector<int> cols_to_add(r[0]), next_cols_to_add;     used_row[0] = true;     for (int i = 0; i < m; ++i) {       if (used_col[i]) continue;       while (!cols_to_add.empty()) {         next_cols_to_add.clear();         for (int col : cols_to_add) {           if (used_col[col]) continue;           used_col[col] = true;           for (int row : c[col]) {             if (used_row[row]) continue;             used_row[row] = true;             for (int new_col : r[row]) {               next_cols_to_add.push_back(new_col);             }           }         }         cols_to_add = next_cols_to_add;       }       if (!used_col[i]) {         ++ans;         cols_to_add.push_back(i);       }     }     while (!cols_to_add.empty()) {       next_cols_to_add.clear();       for (int col : cols_to_add) {         if (used_col[col]) continue;         used_col[col] = true;         for (int row : c[col]) {           if (used_row[row]) continue;           used_row[row] = true;           for (int new_col : r[row]) {             next_cols_to_add.push_back(new_col);           }         }       }       cols_to_add = next_cols_to_add;     }     for (int i = 1; i < n; ++i) {       if (!used_row[i]) {         ++ans;       }     }     cout << ans;   }


#include <bits/stdc++.h>   bool canWin(long long b, long long e) {     if (e % 2 == 1) {       return b % 2 == 0;     } else if (e < 2 * b) {       return b % 2 == 1;     } else if (e < 4 * b) {       return 1;     } else {       return canWin(b, e / 4);     }   }   bool canLose(long long b, long long e) {     if (e < 2 * b) {       return 1;     } else if (e / 2 % 2 == 1) {       return b % 2 == 0;     } else if (e < 4 * b) {       return b % 2 == 1;     } else {       return canLose(b, e / 4);     }   }   int main() {     int t;     scanf( %d , &t);     bool canBeWinner, canBeLoser;     bool canBeFirst = true;     bool canBeSecond = false;     for (int i = 0; i < t; i++) {       long long b, e;       scanf( %lld%lld , &b, &e);       bool cWin = canWin(b, e);       bool cLose = canLose(b, e);       canBeWinner = (canBeFirst && cWin) || (canBeSecond && !cWin);       canBeLoser = (canBeFirst && cLose) || (canBeSecond && !cLose);       canBeFirst = canBeLoser;       canBeSecond = canBeWinner;     }     printf( %d %d n , canBeWinner, canBeLoser);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using namespace std;   const long long N = 4e7 + 5, N_ = 4e6 + 5;   int cnt = 0, prime[N_];   bitset<N> vis;   void pre() {     for (int i = 2; i < N; ++i) {       if (!vis[i]) prime[cnt++] = i;       for (int j = 0; i * prime[j] < N; ++j) {         vis[i * prime[j]] = 1;         if (i % prime[j] == 0) break;       }     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n, m;     cin >> n;     if (n == 2) {       cout <<  1 1  << endl;       return 0;     }     if (n == 3) {       cout <<  1 1 2  << endl;       return 0;     }     if (n == 4) {       cout <<  1 1 2 1  << endl;       return 0;     }     if (n == 5) {       cout <<  1 2 1 1 1  << endl;       return 0;     }     if (n == 6) {       cout <<  1 2 1 1 1 1  << endl;       return 0;     }     pre();     m = n * (n + 1) / 2;     bool sign = 0;     vector<int> res(n + 1, 0);     int flag = 0;     if (m & 1) {       if (!vis[m - 2]) {         ++res[2];         res.erase(res.begin());         for (auto i : res) cout << i + 1 <<    ;         cout << endl;         return 0;       }       m -= 3;       flag = 3;       res[3] = 2;     }     for (auto i : prime) {       int t = m - i;       if (!i || t < 0) break;       if (!vis[t]) {         for (int i = n; t && i > flag; --i) {           if (i == flag) continue;           if (i <= t) {             t -= i;             ++res[i];           }         }         if (t) {           res = vector<int>(n + 1, 0);           res[flag] = 2;         } else {           sign = 1;           break;         }       }     }     if (!sign) {       cout << -1 << endl;       return 0;     }     res.erase(res.begin());     for (auto i : res) cout << i + 1 <<    ;     cout << endl;   }


#include <bits/stdc++.h>   using namespace std;   long long n, m;   inline long long read() {     long long x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = (x << 3) + (x << 1) + ch -  0 ;       ch = getchar();     }     return x * f;   }   long long qpow(long long a, long long b) {     long long ans = 1;     while (b) {       if (b & 1) ans = 1ll * ans * a % 1000000007;       a = 1ll * a * a % 1000000007;       b >>= 1;     }     return ans % 1000000007;   }   signed main() {     cin >> n >> m;     long long c = n - m + 1;     c *= 2;     n++;     n *= 2;     m--;     long long tot = qpow(n, m);     long long amo = (c * tot) % 1000000007;     amo %= 1000000007;     cout << amo;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, k;   int pr(int i) { return (i - 1 + n) % n; }   int nx(int i) { return (i + 1) % n; }   int get(int i, int j) {     if (i > j) swap(i, j);     return min(j - i, n - j + i);   }   char no(char el) {     if (el ==  B )       return  W ;     else       return  B ;   }   int gg(string s) {     int b = 1;     for (char i : s) {       if (i !=  B ) b = 0;     }     int w = 1;     for (char i : s) {       if (i !=  W ) w = 0;     }     return max(w, b);   }   signed main() {     string s;     cin >> n >> k >> s;     if (gg(s)) {       cout << s;       return 0;     }     vector<int> used(n, 0);     int l = 0, r = 0, op = 1e6;     bool ch = false;     while (l < n && op > 0) {       --op;       if (used[l]) {         ++l;       } else if (s[l] == s[pr(l)]) {         ch = true;         while (s[l] == s[nx(l)]) used[l] = 1, l = nx(l);         r = nx(l);         while (s[r] != s[nx(r)]) used[r] = 1, r = nx(r);         int cr = r;         while (s[nx(cr)] == s[cr]) used[cr] = 1, cr = nx(cr);         char last = s[l];         for (int i = nx(l); i != r; i = nx(i)) {           if (get(l, i) > k && get(r, i) > k)             s[i] = no(last), last = no(last);           else if (get(l, i) < get(r, i))             s[i] = s[l], last = s[l];           else if (get(l, i) >= get(r, i))             s[i] = s[r], last = s[r];         }         ++l;       } else {         ++l;       }     }     if (!ch) {       if (k % 2 == 0)         cout << s;       else         for (char i : s) cout << no(i);       return 0;     }     cout << s;   }


#include <bits/stdc++.h>   using namespace std;   vector<int> g[100100];   int aa[100100];   long long dfs(int u, int fa) {     vector<long long> tmp;     for (int i = 0; i < g[u].size(); i++) {       int v = g[u][i];       if (v != fa && aa[v] - 1 >= 0) {         aa[v] -= 1;         tmp.push_back(dfs(v, u));       }     }     sort(tmp.begin(), tmp.end());     int cc = tmp.size();     long long ans = 0;     for (int i = aa[u]; i >= 1; i--) {       if (cc > 0) {         ans += tmp[--cc] + 2;         aa[u]--;       } else {         break;       }     }     for (int i = 0; i < g[u].size(); i++) {       int v = g[u][i];       if (v != fa) {         int tmp = min(aa[u], aa[v]);         ans += tmp * 2;         aa[u] -= tmp;         aa[v] -= tmp;       }     }     return ans;   }   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &aa[i]);     }     for (int i = 0; i < n - 1; i++) {       int u, v;       scanf( %d%d , &u, &v);       g[u].push_back(v);       g[v].push_back(u);     }     int s;     scanf( %d , &s);     printf( %I64d n , dfs(s, -1));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   string s;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     long long int TESTS, k, a, n, b, c, d, m, x, i, y, z;     cin >> TESTS;     while (TESTS--) {       cin >> n;       cin >> s;       long long int ans = n;       for (long long int i = 0; i <= n - 1; i++) {         if (s[i] ==  1 ) {           a = max(i + 1, n - i);           ans = max(ans, 2 * a);         }       }       cout << ans <<   n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     if (n == 1)       cout << -1;     else       cout << (n % 2 == 0 ? n : n - 1) <<   2  ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int limit = 10000;   int query(vector<long long> &v) {     int n = (int)v.size();     cout << n <<    ;     for (int i = 0; i < n; i++) {       cout << v[i] << (i == n - 1 ?   n  :    );     }     int k;     cin >> k;     if (k == -1) {       exit(0);     } else if (k == -2) {       assert(false);     }     return k;   }   int main() {     vector<vector<long long>> dp(6, vector<long long>(10010));     for (int q = 1; q <= 5; q++) {       for (long long p = 1; p <= limit; p++) {         if (q == 5 && p == 2) {           break;         }         long long x = p;         for (int i = 0; i < p; i++) {           x += dp[q - 1][min(10000LL, x)];           x++;         }         x += dp[q - 1][min(10000LL, x)];         dp[q][p] = x - p;       }     }     long long lb = 1, ub = 10004205361450474LL;     for (int q = 5; q >= 1; q--) {       vector<long long> hoge;       long long x = lb;       for (int i = 0; i < min(10000LL, lb); i++) {         x += dp[q - 1][min((long long)10000, x)];         hoge.push_back(x);         x++;       }       x += dp[q - 1][min(10000LL, x)];       int k = query(hoge);       if (k == 0) {         ub = hoge[0] - 1;       } else if (k == (int)hoge.size()) {         lb = hoge.back() + 1;       } else {         lb = hoge[k - 1] + 1;         ub = hoge[k] - 1;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = (int)1e5 + 10;   int sx[MAXN], sy[MAXN], sz[MAXN];   char s[MAXN];   void solve(int x, int y, int z) {     if (x + y + z < 3) {       printf( YES n );       return;     }     int e = (x + y + z) / 3;     vector<int> v;     v.push_back(x);     v.push_back(y);     v.push_back(z);     sort(v.begin(), v.end());     if ((x + y + z) % 3 == 0) {       if (x == e && y == e && z == e)         printf( YES n );       else         printf( NO n );       return;     } else if ((x + y + z) % 3 == 1) {       if (v[2] == e + 1 && v[1] == e)         printf( YES n );       else         printf( NO n );       return;     } else {       if (v[2] == e + 1 && v[1] == e + 1)         printf( YES n );       else         printf( NO n );       return;     }   }   int main() {     scanf( %s , s);     int n = strlen(s);     for (int i = 1; i <= n; i++) {       sx[i] = sx[i - 1] + (s[i - 1] ==  x );       sy[i] = sy[i - 1] + (s[i - 1] ==  y );       sz[i] = sz[i - 1] + (s[i - 1] ==  z );     }     int m;     scanf( %d , &m);     for (int i = 1; i <= m; i++) {       int l, r;       scanf( %d%d , &l, &r);       int x = sx[r] - sx[l - 1], y = sy[r] - sy[l - 1], z = sz[r] - sz[l - 1];       solve(x, y, z);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long int siz = 3e5 + 5;   map<int, vector<int>> adjList;   long long int ans[siz] = {0};   long long int cum[siz] = {0};   map<long long int, long long int> q[siz];   void dfs(int cur, int parent, int level, long long int val) {     for (pair<long long int, long long int> temp : q[cur]) {       cum[level] += temp.second;       cum[min(level + temp.first + 1, siz - 1)] -= temp.second;     }     val += cum[level];     ans[cur] = val;     for (int child : adjList[cur]) {       if (child != parent) {         dfs(child, cur, level + 1, val);       }     }     for (pair<long long int, long long int> temp : q[cur]) {       cum[level] -= temp.second;       cum[min(level + temp.first + 1, siz - 1)] += temp.second;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     ;     int n;     cin >> n;     int y;     long long int x;     for (int i = 0; i < (int)(n - 1); i++) {       cin >> x >> y;       adjList[x].push_back(y);       adjList[y].push_back(x);     }     int m;     cin >> m;     int d, v;     for (int i = 0; i < (int)(m); i++) {       cin >> v >> d >> x;       q[v][d] += x;     }     dfs(1, -1, 1, 0);     for (int i = 1; i <= (int)(n); i++) {       cout << ans[i] <<    ;     }     cout << endl;   }


#include <bits/stdc++.h>   using namespace std;   unsigned long long n, a[130], i, b = 1, f[10002];   int main() {     cin >> n;     for (i = 1; i <= n; i++) {       cin >> a[i];       f[a[i]]++;     }     sort(a + 1, a + n + 1);     cout << a[n] <<    ;     for (i = 1; i < n; i++) {       if (f[a[i]] == 1 && a[n] % a[i] != 0) {         b = a[i];       } else if (f[a[i]] == 2) {         b = a[i];       }     }     cout << b;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long MOD = 998244353;   inline long long Msum(long long x) { return x; }   template <typename... Rest>   inline long long Msum(long long x, Rest... rest) {     return (x + Msum(rest...)) % MOD;   }   inline long long Mprod(long long x) { return x; }   template <typename... Rest>   inline long long Mprod(long long x, Rest... rest) {     return x * Mprod(rest...) % MOD;   }   inline long long Mnorm(long long x) { return (x % MOD + MOD) % MOD; }   long long Msq(long long x) { return x * x % MOD; }   long long Mpow(long long b, long long e) {     return e ? Mprod(Msq(Mpow(b, e >> 1)), (e & 1 ? b : 1)) : 1;   }   long long Minv(long long x) { return Mpow(x, MOD - 2); }   const int MAXN = 51;   int sns[MAXN], w[MAXN];   int wi, sn;   int sl, sd, S;   long long dp[MAXN][MAXN][MAXN];   long long f(int h, int hl, int hd, int t) {     if (!t) return 0;     long long &ret = dp[h][hl][hd];     if (ret != -1) return ret;     ret = 0;     long long cS = S + hl - hd + sn * h;     ret += Mprod(wi + sn * h, Minv(cS), 1 + f(h + 1, hl, hd, t - 1));     ret = Mnorm(ret);     ret += Mprod(sl + hl, Minv(cS), f(h, hl + 1, hd, t - 1));     ret = Mnorm(ret);     ret += Mprod(sd - hd, Minv(cS), f(h, hl, hd + 1, t - 1));     ret = Mnorm(ret);     assert(sd - hd + sl + hl + wi + sn * h == cS);     return ret;   }   int main() {     int n, m;     scanf( %d %d , &n, &m);     for (int i = 0; i < n; i++) {       scanf( %d , &sns[i]);       sns[i] = sns[i] * 2 - 1;     }     for (int i = 0; i < n; i++) {       scanf( %d , &w[i]);     }     for (int i = 0; i < n; i++) {       S = sl = sd = 0;       wi = w[i];       sn = sns[i];       for (int j = 0; j < (int)n; j++) {         S += w[j];         if (j != i) {           if (sns[j] == 1)             sl += w[j];           else             sd += w[j];         }       }       memset(dp, -1, sizeof(dp));       printf( %lld n , Mnorm(wi + sn * f(0, 0, 0, m)));     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 1111111;   int a[N];   int n, k;   vector<int> prime, p;   void Getprime() {     for (int i = 2; i <= 1000; i++) {       bool bo = 1;       for (int j = 2; j * j <= i; j++) {         if (i % j == 0) {           bo = 0;           break;         }       }       if (bo) {         prime.push_back(i);       }     }   }   int main() {     Getprime();     scanf( %d%d , &n, &k);     for (int i = 1; i <= n; ++i) {       scanf( %d , &a[i]);     }     int K = k;     for (int i = 0; i < prime.size() && prime[i] * prime[i] <= k; ++i) {       int t = prime[i];       if (k % t == 0) {         int m = 1;         while (K % t == 0 && K) {           m *= t;           K /= t;         }         p.push_back(m);       }     }     if (K != 1) {       p.push_back(K);     }     for (int i = 0; i < p.size(); ++i) {       int pr = p[i];       bool flag = false;       for (int j = 1; j <= n; ++j) {         if (a[j] % pr == 0) {           flag = true;           break;         }       }       if (!flag) {         puts( No );         return 0;       }     }     puts( Yes );   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   inline void smn(T &a, const T &b) {     if (b < a) a = b;   }   template <class T>   inline void smx(T &a, const T &b) {     if (b > a) a = b;   }   template <class T>   inline T gcd(T x, T y) {     return y ? gcd(y, x % y) : x;   }   namespace std {   template <class T, class U>   struct hash<pair<T, U>> {     inline size_t operator()(const pair<T, U> &p) const {       return hash<T>()(p.first) * 701 + hash<U>()(p.second);     }   };   }  // namespace std   const double eps = 1e-8;   const int key = 701;   const int MN = 1000 * 1000 + 1000;   string s;   long long h1[MN], pw1[MN], h2[MN], pw2[MN];   const int MOD = 1000 * 1000 * 1000 + 7;   long long add[MN];   int n, k;   pair<long long, long long> get(int s, int e) {     long long res1 = h1[e];     if (s != 0) res1 -= pw1[e - s + 1] * h1[s - 1];     long long res2 = h2[e];     if (s != 0) res2 -= pw2[e - s + 1] * h2[s - 1], res2 %= MOD;     if (res2 < 0) res2 += MOD;     return make_pair(res1, res2);   }   bool check(int l) {     auto v = get(0, l - 1);     int now = l;     for (int i = 1; i < k; i++) {       if (get(now, now + l - 1) != v) return 0;       now += l;     }     return 1;   }   int fnd(int p) {     int s = 1, e = n - p, res = 0;     while (s <= e) {       int m = (s + e) / 2;       if (get(0, m - 1) == get(p, p + m - 1))         res = m, s = m + 1;       else         e = m - 1;     }     return res;   }   int main() {     ios_base::sync_with_stdio(false);     cin >> n >> k >> s;     long long now = 0;     for (int i = 0; i < n; i++) now = now * 701 + s[i], h1[i] = now;     pw1[0] = 1;     for (int i = 1; i <= n; i++) pw1[i] = 701 * pw1[i - 1];     now = 0;     for (int i = 0; i < n; i++) now = (now * 701 + s[i]) % MOD, h2[i] = now;     pw2[0] = 1;     for (int i = 1; i <= n; i++) pw2[i] = (701 * pw2[i - 1]) % MOD;     for (int i = 1; i <= n; i++)       if (n / i >= k && check(i)) {         int t = i * k;         int b = fnd(t);         smn(b, i);         add[t - 1] += 1;         add[t + b] += -1;       }     now = 0;     for (int i = 0; i < n; i++) {       now += add[i];       cout << (now ? 1 : 0);     }     cout <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   inline int upd(int& a, int b) { return a = min(a, b); }   inline int _abs(int x) { return x > 0 ? x : -x; }   char c;   int n, cnt[3], type[80];   int pos[3][80], leq[3][80];   int dp[80][80][80][80];   void getpos(void) {     for (int p = 0; p <= 2; p++) {       cnt[p] = 0;       for (int y = 1; y <= n; y++) {         while (y <= n && type[y] != p) y++;         if (y <= n) pos[p][++cnt[p]] = y;       }       leq[p][0] = 0;       for (int i = 1; i <= n; i++) leq[p][i] = leq[p][i - 1] + (type[i] == p);     }     return;   }   void trans(int i, int j, int k, int lst) {     int p0 = pos[0][i], p1 = pos[1][j], p2 = pos[2][k];     if (i > 0)       upd(dp[0][i][j][k],           dp[lst][i - 1][j][k] + _abs(j - leq[1][p0]) + _abs(k - leq[2][p0]));     if (j > 0)       upd(dp[1][i][j][k],           dp[lst][i][j - 1][k] + _abs(i - leq[0][p1]) + _abs(k - leq[2][p1]));     if (k > 0 && lst != 1)       upd(dp[2][i][j][k],           dp[lst][i][j][k - 1] + _abs(i - leq[0][p2]) + _abs(j - leq[1][p2]));     return;   }   int main(void) {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf(  %c , &c);       type[i] = (c ==  V  ? 1 : (c ==  K  ? 2 : 0));     }     getpos();     memset(dp, 0x1f, sizeof(dp));     dp[0][0][0][0] = 0;     for (int i = 0; i <= cnt[0]; i++)       for (int j = 0; j <= cnt[1]; j++)         for (int k = 0; k <= cnt[2]; k++)           for (int lst = 0; lst <= 2; lst++) trans(i, j, k, lst);     int ans = n * n;     for (int i = 0; i <= 2; i++) upd(ans, dp[i][cnt[0]][cnt[1]][cnt[2]]);     printf( %d n , ans >> 1);     return 0;   }