#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   long long n, a[N], subtree[N], total, ans, initCost;   vector<int> g[N];   void costfromRoot(int v, int prnt, int d) {     initCost += d * a[v];     subtree[v] += a[v];     for (int u : g[v])       if (u != prnt) {         costfromRoot(u, v, d + 1);         subtree[v] += subtree[u];       }   }   void dfs(int v, int prnt, long long res) {     ans = max(ans, res);     for (int u : g[v])       if (u != prnt) {         dfs(u, v, res + total - 2 * subtree[u]);       }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n;     for (int i = 1; i <= n; ++i) {       cin >> a[i];       total += a[i];     }     for (int i = 0; i < n - 1; ++i) {       int u, v;       cin >> u >> v;       g[u].push_back(v);       g[v].push_back(u);     }     costfromRoot(1, -1, 0);     dfs(1, -1, initCost);     cout << ans <<   n ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct point {     int x, y;   };   struct ConvexHull {     vector<point> hull;     int m;     ConvexHull() : m(0) { hull.clear(); }     bool ccw(point x, point y, point z) {       return ((y.x - x.x) * (z.y - x.y) > (y.y - x.y) * (z.x - x.x));     }     void MakeHull(int n, vector<point> a) {       hull.clear();       if (!n) return;       int x = 0;       for (int i = 0; i < n; i++)         if ((a[i].y == a[x].y) ? a[i].x < a[x].x : a[i].y < a[x].y) x = i;       swap(a[0], a[x]);       hull.push_back({a[0].x, a[0].y + 1});       hull.push_back(a[0]);       sort(a.begin() + 1, a.begin() + n, [=](point x, point y) {         return (((x.y - a[0].y) * (y.x - a[0].x)) <                 (x.x - a[0].x) * (y.y - a[0].y));       });       m = 1;       for (int i = 1; i < n; i++) {         while (!ccw(hull[m - 1], hull[m], a[i]))           if (m > 1)             hull.pop_back(), m--;           else if (i + 1 == n)             break;           else             i++;         hull.push_back(a[i]);         m++;       }       hull.erase(hull.begin());     }   };   int n;   int r;   vector<point> v;   ConvexHull cw;   int ma = 0;   vector<point> rez;   void rec(int l, int rem, int s, point r) {     if (!rem) {       int d = s * n - r.x * r.x - r.y * r.y;       if (d > ma) {         ma = d;         rez = v;       }       return;     }     if (l == cw.m) return;     rec(l + 1, rem, s, r);     v.push_back(cw.hull[l]);     r = {r.x + v.back().x, r.y + v.back().y};     s += v.back().x * v.back().x + v.back().y * v.back().y;     rec(l, rem - 1, s, r);     v.pop_back();   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> n >> r;     for (int i = 0; i * i <= r * r; i++)       for (int j = 0; j * j + i * i <= r * r; j++) {         v.push_back({i, j});         if (i) v.push_back({-i, j});         if (j) v.push_back({i, -j});         if (i - j) v.push_back({j, i});         if (i * j) v.push_back({-i, -j});       }     cw.MakeHull(v.size(), v);     v.clear();     rec(0, n, 0, {0, 0});     cout << ma <<   n ;     for (int i = 0; i < n; i++) cout << rez[i].x <<     << rez[i].y <<   n ;     return 0;   }


#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   const int N = 2e5 + 10;   vector<int> g[N];   int type[N];   bool noleaf = 1;   int cnt = 0;   void dfs(int v, int p) {     for (auto u : g[v]) {       if (u == p) continue;       dfs(u, v);       if (type[u] == 0) {         type[v] = 1;         if (v == 1) noleaf = 0;       }     }     if (v != 1) cnt += type[v];   }   void solve() {     int n;     cin >> n;     for (int i = 1; i <= n; i++) {       g[i].clear();       cnt = 0;       type[i] = 0;       noleaf = 1;     }     for (int i = 1; i < n; i++) {       int a, b;       cin >> a >> b;       g[a].push_back(b);       g[b].push_back(a);     }     dfs(1, 0);     cout << n - 2 * cnt - 1 + noleaf <<   n ;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int t;     cin >> t;     while (t--) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   void ga(int N, int *A) {     for (int i(0); i < N; i++) scanf( %d , A + i);   }   map<int, vector<pair<int, int> > > T[4];   int N, M, a, b, f[10], C[100005];   int main(void) {     scanf( %d%d , &N, &M);     for (int i(0); i < M; i++)       scanf( %d%d , &a, &b), T[0][a].push_back({b, i}), T[1][b].push_back({a, i}),           T[2][a + b].push_back({a, i}), T[3][a - b].push_back({a, i});     for (int i(0); i < 4; i++)       for (auto &h : T[i]) {         sort(h.second.begin(), h.second.end());         a = 0;         for (auto &w : h.second) C[w.second] += a, a = 1;         reverse(h.second.begin(), h.second.end());         a = 0;         for (auto &w : h.second) C[w.second] += a, a = 1;       }     for (int i(0); i < M; i++) ++f[C[i]];     for (int i(0); i < 9; i++) printf( %d  , f[i]);     puts(  );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, i, lki, kills = 0, temp;     long long* L = new long long[1000001];     cin >> n;     for (i = 0; i < n; i++) {       scanf( %ld , &L[i]);     }     lki = (n - 1) - L[n - 1];     kills += min(L[n - 1], n - 1);     for (i = n - 2; i > 0; i--) {       if (lki <= 0) break;       if (L[i] > i) L[i] = i;       temp = i - L[i];       if (temp < lki) {         if (i < lki) {           kills += L[i];         } else {           temp = L[i] - (i - lki);           kills += temp;         }         lki = i - L[i];       }     }     cout << n - kills << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long n, m, k, temp;   int main() {     scanf( %d%d%d , &n, &m, &k);     if (n % 2 == 0 || m < (n / 2 + 1)) {       printf( 0 n );       return 0;     }     long long minA = (m / (n / 2 + 1)) * k;     for (int i = 0; i < n; i++) {       scanf( %d , &temp);       if (i % 2 == 0 && temp < minA) minA = temp;     }     printf( %d n , minA);     return 0;   }


#include <bits/stdc++.h>   const double pi = acos(-1.0);   const double eps = 1e-9;   using namespace std;   const long long MOD = 998244353;   const int N = 2e5 + 10;   long long mult(long long x, long long y) {     x %= MOD;     y %= MOD;     return x * y % MOD;   }   long long bin_pow(long long x, long long n) {     long long res = 1;     while (n) {       if (n & 1) res = mult(res, x);       n >>= 1;       x = mult(x, x);     }     return res;   }   long long inv(long long x) { return bin_pow(x, MOD - 2); }   long long add(long long x, long long y) {     x += y;     if (x >= MOD) x -= MOD;     return x;   }   int n, m;   long long d[N], prefD[N];   long long get(int l, int r) { return (prefD[r] - prefD[l] + MOD) % MOD; }   void solve() {     cin >> n >> m;     for (int i = 0; i < n; i++) {       cin >> d[i];     }     sort(d, d + n);     for (int i = 1; i <= n; i++) {       prefD[i] = prefD[i - 1] + d[i - 1];     }     for (int i = 0; i < m; i++) {       int a, b;       cin >> a >> b;       int cnt = d + n - lower_bound(d, d + n, b);       int res = 0;       if (cnt >= a) {         res = mult(mult(cnt - a, inv(cnt)), get(n - cnt, n));         res = add(res, mult(mult(cnt - a + 1, inv(cnt + 1)), get(0, n - cnt)));       }       cout << res <<   n ;     }   }   int main() {     ios::sync_with_stdio(NULL), cin.tie(0), cout.tie(0);     cout.setf(ios::fixed), cout.precision(9);     int step = 1;     for (int i = 0; i < step; i++) {       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   set<int> s;   int solve(vector<int> v, int k, int n) {     s.clear();     for (int i = 0; i < k; i++) s.insert(v[i]);     if (s.size() == k && *(s.begin()) == 1 && *(s.rbegin()) == k) {       s.clear();       for (int i = k; i < n; i++) s.insert(v[i]);       if (s.size() == n - k && *(s.begin()) == 1 && *(s.rbegin()) == (n - k))         return 1;       else         return -1;     } else       return -1;   }   int main() {     int t, n, m;     cin >> t;     vector<int> ans;     while (t--) {       cin >> n;       vector<int> a(n);       m = 0;       ans.clear();       for (int i = 0; i < n; i++) {         cin >> a[i];         if (a[i] > m) m = a[i];       }       if (m > n - 1) {         cout <<  0 n ;         continue;       } else {         if (solve(a, m, n) != -1) ans.push_back(m);         if (solve(a, n - m, n) != -1 && m != n - m) ans.push_back(n - m);         cout << ans.size() << endl;         if (ans.size()) {           for (auto tl = ans.begin(); tl != ans.end(); tl++)             cout << *tl <<     << n - *tl << endl;         }       }     }   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   bool compare(const pair<int, int>& a, const pair<int, int>& b) {     return a.second < b.second;   }   bool not_fixed(vector<int>& v) {     for (int i = 1; i < v.size() - 1; i++) {       if (v[i] == 0 && v[i - 1] == 1 && v[i + 1] == 1) return true;     }     return false;   }   int main() {     int n;     cin >> n;     vector<int> v(n);     for (int i = 0; i < n; i++) {       cin >> v[i];     }     int ans = 0;     while (not_fixed(v)) {       map<int, int> wo;       for (int i = 1; i < n - 1; i++) {         if (v[i] == 0 && v[i - 1] == 1 && v[i + 1] == 1) {           wo[i - 1]++;           wo[i + 1]++;         }       }       int maxi = max_element(wo.begin(), wo.end(), compare)->first;       v[maxi] = 0;       ans++;     }     cout << ans << endl;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, i, j = 0, r = 0, c = 1;     cin >> n;     long long matrix[n][n];     for (i = 0; i < n - 1; i++) {       for (j = 0; j < n - 1; j++) {         matrix[i][j] = (i + j) % (n - 1) + 1;       }     }     for (i = 0; i < n - 1; i++) {       matrix[i][n - 1] = matrix[n - 1][i] = matrix[i][i];       matrix[i][i] = 0;     }     matrix[n - 1][n - 1] = 0;     for (i = 0; i < n; i++) {       for (j = 0; j < n; j++) {         cout << matrix[i][j] <<    ;       }       cout << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int f(string s) {     int ans = 0;     for (int i = 0; i < s.length(); i++) {       if (s[i] ==  1 ) {         ans++;       }     }     return ans;   }   int main() {     string a, b;     cin >> a >> b;     int c1 = f(a);     if (c1 % 2 != 0) {       c1++;     }     if (c1 >= f(b)) {       cout <<  YES  << endl;     } else {       cout <<  NO  << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   const int N = 200002, SQ = 450;   int n, c, a[N], first[N];   long long sum[SQ];   bool solve() {     int x = c;     for (int i = x; i >= 1; --i) {       i = min(i, x);       if (!sum[i / SQ]) {         i = i / SQ * SQ;         continue;       }       if (sum[i / SQ] <= x)         x -= sum[i / SQ], i = i / SQ * SQ;       else         x -= min(first[i], x / i) * i;       if (!x) break;     }     return x > 0;   }   bool check(int i) {     ++first[i];     sum[i / SQ] += i;     bool fail = solve();     --first[i];     sum[i / SQ] -= i;     return fail;   }   int main() {     scanf( %d%d , &c, &n);     for (int i = 1; i <= n; ++i)       scanf( %d , &a[i]), ++first[a[i]], sum[a[i] / SQ] += a[i];     for (int i = 1; i <= c; ++i)       if (check(i)) return cout << i, 0;     cout <<  Greed is good ;   }


#include<bits/stdc++.h>   using namespace std;   int main(){    ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);    int t;    cin >> t;    while(t--){     int n ; cin >> n;     vector<int> ans(n+1,1);     string str; cin >> str;     int cnt=0;     char now=str[0];     for(int i=0 ; i<n ; ++i){      if(str[i] != now) ++cnt , now = str[i];      else now = str[i] , cnt = 1;      if(now ==  L ) ans[i+1] += cnt;     }     now = str[n-1];     for(int i=n-1 ; i>=0 ; --i){      if(str[i] != now) ++cnt , now = str[i];      else now = str[i] , cnt = 1;      if(now ==  R ) ans[i] += cnt;     }     for(int i=0 ; i<=n ; ++i){      cout << ans[i];      if(i == n) cout <<   n ;      else cout <<    ;     }    }   }


#include <bits/stdc++.h>   using namespace std;   const int mod = 7 + 1e9;   const int inf = 1e9 + 5;   const long long INF = (long long)1e18 + 5;   const int N = 100 + 5;   int a[N];   int fr[10000];   int main() {     int n;     string s;     getline(cin, s);     sscanf(s.c_str(),  %d , &n);     for (int i = 0; i < (int)(n); i++) {       getline(cin, s);       int h = 0, m = 0;       char c;       sscanf(s.c_str(),  [%d:%d %c.m.]: , &h, &m, &c);       a[i] = h * 60 + m;       if (h == 12 && c ==  a ) a[i] = m;       if (c ==  p ) {         if (h != 12) a[i] += (12 * 60);       }     }     int ans = 1;     fr[a[0]] = 1;     for (int i = 1; i < n; ++i) {       if (a[i] == a[i - 1]) {         fr[a[i]]++;         if (fr[a[i]] > 10) {           ans++;           fr[a[i]] = 1;         }       } else {         fr[a[i - 1]] = 0;         fr[a[i]] = 1;       }       if (a[i] < a[i - 1] || (a[i] < 60 && a[i - 1] >= 60)) {         ans++;       }     }     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   bool near(long long A, long long B, long long X, long long Y, long long T) {     if ((X - Y * T) < 0) return (0);     if ((A - B * T) * Y != (X - Y * T) * B)       return ((A - B * T) * Y > (X - Y * T) * B);     return (B < Y);   }   int main() {     int t1, t2, x1, x2, t0;     scanf( %d %d %d %d %d , &t1, &t2, &x1, &x2, &t0);     if (t1 == t0 || t2 == t0) {       int a1 = x1 * (t1 == t0);       int a2 = x2 * (t2 == t0);       printf( %d %d n , a1, a2);       return (0);     }     int dmin = t2 - t0;     int ret1 = 0, ret2 = x2;     for (int i = 1; i <= x1; i++) {       long long y = ((long long)(t0 - t1) * i) / (t2 - t0);       int y2 = min(y, (long long)x2);       for (int j = max(0, y2 - 1); j <= min(x2, y2 + 1); j++) {         if (near((long long)t1 * ret1 + (long long)t2 * ret2, ret1 + ret2,                  (long long)t1 * i + (long long)t2 * j, i + j, t0)) {           ret1 = i;           ret2 = j;         }       }     }     printf( %d %d n , ret1, ret2);     return (0);   }


#include <bits/stdc++.h>   using namespace std;   const int N(150010), INF((1 << 30) - 1);   int ty, n, k;   int yy[4 * N], c1[4 * N], c2[4 * N];   int ord[N], dis[N], ans[N];   struct Point {     int x, y;     Point() : x(0), y(0) {}     Point(int _x, int _y) : x(_x), y(_y) {}     void get() { scanf( %d%d , &x, &y); }     void changeIndex() {       int _x(x), _y(y);       x = _x + _y;       y = _x - _y;     }     void rotate() {       swap(x, y);       y = -y;     }     void getIndex() { y = lower_bound(yy + 1, yy + 1 + ty, y) - yy; }     void reflect() { yy[++ty] = y; }   } p1[N], p2[N], sub[N], dwa[N];   struct Line {     int x, l, r, id;     Line() : x(0), l(0), r(0), id(0) {}     Line(int _x, int _l, int _r, int _id) {       x = _x;       l = _l;       r = _r;       id = _id;     }     void reflect() {       yy[++ty] = l;       yy[++ty] = r;     }     void getIndex() {       l = lower_bound(yy + 1, yy + 1 + ty, l) - yy;       r = lower_bound(yy + 1, yy + 1 + ty, r) - yy;     }   } li[2 * N];   void numberY() {     sort(yy + 1, yy + 1 + ty);     int tt = 0;     for (int i = int(1); i < int(ty + 1); ++i)       if (i == 1 || yy[i] != yy[i - 1]) yy[++tt] = yy[i];     ty = tt;   }   int low(int x) { return x & (-x); }   void update1(int x, int v) {     for (; x <= ty; x += low(x)) c1[x] = min(c1[x], v);   }   int getValue1(int x) {     int ret = INF;     for (; x; x -= low(x)) ret = min(ret, c1[x]);     return ret;   }   void update2(int x) {     for (; x <= ty; x += low(x)) ++c2[x];   }   int getValue2(int x) {     int ret = 0;     for (; x; x -= low(x)) ret += c2[x];     return ret;   }   bool cmpOrder1(int a, int b) { return p2[a].x < p2[b].x; }   bool cmpOrder2(int a, int b) { return dis[a] < dis[b]; }   bool cmpPoint(Point a, Point b) { return a.x < b.x; }   bool cmpLine(Line a, Line b) { return a.x < b.x; }   void getMinDistance() {     for (int i = int(0); i < int(n); ++i) dis[i] = INF;     for (int cal_time = int(0); cal_time < int(4); ++cal_time) {       ty = 0;       for (int i = int(0); i < int(k); ++i) {         sub[i].rotate();         sub[i].reflect();         p1[i] = sub[i];       }       for (int i = int(0); i < int(n); ++i) {         dwa[i].rotate();         dwa[i].reflect();         p2[i] = dwa[i];       }       numberY();       for (int i = int(0); i < int(k); ++i) p1[i].getIndex();       for (int i = int(0); i < int(n); ++i) {         p2[i].getIndex();         ord[i] = i;       }       sort(p1, p1 + k, cmpPoint);       sort(ord, ord + n, cmpOrder1);       int p = 0;       for (int i = int(0); i < int(ty + 1); ++i) c1[i] = INF;       for (int i = int(0); i < int(n); ++i) {         for (; p < k && p1[p].x <= p2[ord[i]].x; ++p)           update1(p1[p].y, -p1[p].x - yy[p1[p].y]);         dis[ord[i]] = min(dis[ord[i]], p2[ord[i]].x + yy[p2[ord[i]].y] +                                            getValue1(p2[ord[i]].y));       }     }   }   bool check(int v) {     int x1 = -INF, y1 = -INF, x2 = INF, y2 = INF, e = 0;     for (int i = n - 1; i != -1; --i) {       x1 = max(x1, dwa[ord[i]].x - v);       x2 = min(x2, dwa[ord[i]].x + v);       y1 = max(y1, dwa[ord[i]].y - v);       y2 = min(y2, dwa[ord[i]].y + v);       if (i && dis[ord[i - 1]] > v) continue;       int d = i ? v - dis[ord[i - 1]] : 0;       if (x1 > x2 || y1 > y2) break;       li[e++] = Line(x1 - d - 1, y1 - d - 1, y2 + d, -i - 1);       li[e++] = Line(x2 + d, y1 - d - 1, y2 + d, i + 1);     }     if (x1 <= x2 && y1 <= y2) return true;     ty = 0;     for (int i = int(0); i < int(e); ++i) li[i].reflect();     for (int i = int(0); i < int(k); ++i) {       p1[i] = sub[i];       p1[i].reflect();     }     numberY();     for (int i = int(0); i < int(e); ++i) li[i].getIndex();     for (int i = int(0); i < int(k); ++i) p1[i].getIndex();     sort(li, li + e, cmpLine);     int p = 0;     memset(c2, 0, sizeof(c2));     memset(ans, 0, sizeof(ans));     for (int i = int(0); i < int(e); ++i) {       for (; p < k && p1[p].x <= li[i].x; ++p) update2(p1[p].y);       int t = li[i].id > 0 ? 1 : -1;       ans[t * li[i].id] += t * (getValue2(li[i].r) - getValue2(li[i].l));       if (ans[t * li[i].id] > 0) return true;     }     return false;   }   int main() {     cin >> n >> k;     for (int i = int(0); i < int(n); ++i) dwa[i].get();     for (int i = int(0); i < int(k); ++i) sub[i].get();     getMinDistance();     for (int i = int(0); i < int(n); ++i) dwa[i].changeIndex();     for (int i = int(0); i < int(k); ++i) sub[i].changeIndex();     int l = 0, r = INF;     sort(sub, sub + k, cmpPoint);     sort(ord, ord + n, cmpOrder2);     while (l != r) {       int mid = (l + r) / 2;       if (check(mid))         r = mid;       else         l = mid + 1;     }     cout << l << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, t;     double p;     cin >> n >> p >> t;     vector<vector<double> > dp(2010, vector<double>(2010, 0));     vector<vector<double> > now(2010, vector<double>(2010, 0));     dp[0][0] = 1;     for (int i = 0; i < t; i++) {       for (int j = 0; j < n + 1; j++) {         if (j == n) {           dp[i + 1][j] += dp[i][j];           continue;         }         dp[i + 1][j + 1] += dp[i][j] * p;         dp[i + 1][j] += dp[i][j] * (1 - p);       }     }     double fa = 0;     for (int i = 0; i < n + 1; i++) fa += dp[t][i] * i;     cout << setprecision(20) << fa;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, x;     long long amt = 0;     cin >> n;     vector<pair<int, int> > a;     vector<int> p(n);     vector<long long> count(6, 0);     for (int i(0); i < (n); i++) {       cin >> p[i];     }     for (int i(0); i < (5); i++) {       cin >> x;       a.push_back(make_pair(x, i + 1));     }     sort((a).begin(), (a).end());     for (int i(0); i < (n); i++) {       amt += p[i];       for (int j(4); j >= (0); j--) {         if (a[j].first <= amt) {           count[a[j].second] += amt / a[j].first;           amt -= a[j].first * (amt / a[j].first);         }       }     }     for (int i(1); i < (6); i++) {       cout << count[i] <<    ;     }     cout <<   n  << amt;     return 0;   }


#include <bits/stdc++.h>   const double eps = 1e-15;   const int N = 10000 + 10;   struct node {     double x, y, z;     node() {}     node(double _x, double _y, double _z) {       x = _x;       y = _y;       z = _z;     }   };   node a[N], st;   int n;   double Time[N], len[N], v1, v2;   double sqr(double x) { return x * x; }   bool eq(double x, double y) { return fabs(x - y) <= eps; }   double D(node i, node j) {     return sqrt(sqr(i.x - j.x) + sqr(i.y - j.y) + sqr(i.z - j.z));   }   int main() {     scanf( %d , &n);     for (int i = 0; i <= n; ++i) scanf( %lf%lf%lf , &a[i].x, &a[i].y, &a[i].z);     scanf( %lf%lf , &v1, &v2);     scanf( %lf%lf%lf , &st.x, &st.y, &st.z);     if (eq(st.x, a[0].x) && eq(st.y, a[0].y) && eq(st.z, a[0].z)) {       puts( YES );       puts( 0 );       printf( %.10f %.10f %.10f n , a[0].x, a[0].y, a[0].z);     } else {       Time[0] = 0;       for (int i = 1; i <= n; ++i) {         len[i] = D(a[i - 1], a[i]);         Time[i] = Time[i - 1] + len[i] / v2 + eps;       }       int idx = -1;       for (int i = 1; i <= n; ++i)         if (D(st, a[i]) <= Time[i] * v1 + eps) {           idx = i;           break;         }       if (idx == -1)         puts( NO );       else {         puts( YES );         double L = len[idx] / v2;         double dx = a[idx - 1].x - a[idx].x, dy = a[idx - 1].y - a[idx].y,                dz = a[idx - 1].z - a[idx].z;         double l = 0, r = len[idx] / v2, mid;         for (int i = 0; i < 100; ++i) {           mid = (l + r) / 2;           if (D(node(a[idx].x + dx * mid / L + eps, a[idx].y + dy * mid / L + eps,                      a[idx].z + dz * mid / L + eps),                 st) <= v1 * (Time[idx] - mid) + eps)             l = mid;           else             r = mid;         }         printf( %.10f n , Time[idx] - l);         printf( %.10f %.10f %.10f n , a[idx].x + dx * l / L + eps,                a[idx].y + dy * l / L + eps, a[idx].z + dz * l / L + eps);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     if (s.size() == 1) {       int a = s[0] - 48;       if (a % 4 == 0)         cout << 4;       else         cout << 0;     } else {       int a = (s[s.size() - 2] - 48) * 10 + (s[s.size() - 1] - 48);       if (a % 4 == 0)         cout << 4;       else         cout << 0;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int Maxn = 400000 + 10;   struct Point {     long long x, y;     Point operator+(const Point &A) { return (Point){x + A.x, y + A.y}; }     Point operator-(const Point &A) { return (Point){x - A.x, y - A.y}; }   } P[Maxn];   int n, A[Maxn], cnt;   long long sum[Maxn];   double CalCJ(Point A, Point B) { return A.x * B.y - A.y * B.x; }   bool OnLeft(Point P, Point A, Point B) { return CalCJ(B - A, P - A) > 0; }   bool OnRight(Point P, Point A, Point B) { return CalCJ(B - A, P - A) < 0; }   void solve() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &A[i]);     for (int i = 1; i <= n; i++) sum[i] = sum[i - 1] + (long long)A[i];     long long ans = 0, tot;     for (int i = 1; i <= n; i++) ans += (long long)A[i] * (long long)i;     tot = ans;     P[++cnt] = (Point){1, sum[0]};     for (int i = 2; i <= n; i++) {       Point C = (Point){1ll, (long long)A[i]};       int l = 2, r = cnt + 1;       P[cnt + 1] = (Point){n + 1, (0x3f3f3f3f) * 10ll};       while (l < r) {         int mid = ((l + r) >> 1);         if (!OnRight(C + P[mid - 1], P[mid - 1], P[mid]))           l = mid + 1;         else           r = mid;       }       l--;       long long nans = tot - (long long)A[i] * (long long)i + sum[i - 1] +                        P[l].x * (long long)A[i] - P[l].y;       ans = ((ans) > (nans) ? (ans) : (nans));       Point Q = (Point){(long long)i, sum[i - 1]};       while (cnt > 1 && !OnLeft(Q, P[cnt - 1], P[cnt])) cnt--;       P[++cnt] = Q;     }     P[cnt = 1] = (Point){n, sum[n]};     for (int i = n - 1; i; i--) {       Point C = (Point){1ll, (long long)A[i]};       int l = 2, r = cnt + 1;       P[cnt + 1] = (Point){0, (-0x3f3f3f3f) * 10ll};       while (l < r) {         int mid = ((l + r) >> 1);         if (!OnLeft(P[mid - 1] - C, P[mid - 1], P[mid]))           l = mid + 1;         else           r = mid;       }       l--;       long long nans = tot + sum[i] - (long long)A[i] * (long long)i - P[l].y +                        P[l].x * (long long)A[i];       ans = ((ans) > (nans) ? (ans) : (nans));       Point Q = (Point){(long long)i, sum[i]};       while (cnt > 1 && !OnRight(Q, P[cnt - 1], P[cnt])) cnt--;       P[++cnt] = Q;     }     printf( %I64d n , ans);   }   int main() {     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int M = 1e6 + 6;   const int inf = 0x3f3f3f3f;   long long a[M], sum[M];   int main() {     int t;     scanf( %d , &t);     while (t--) {       int n, p, k;       scanf( %d%d%d , &n, &p, &k);       for (int i = 1; i <= n; i++) scanf( %I64d , &a[i]);       sort(a + 1, a + 1 + n);       for (int i = 1; i <= n; i++) sum[i] = sum[i - 1] + a[i];       int ans = 0;       for (int i = 0; i < k; i++) {         long long now = sum[i];         int num = i;         if (now > p) {           num--;           ans = max(ans, num);           break;         }         for (int j = i + k; j <= n; j += k) {           now += a[j];           num += k;           if (now > p) {             num -= k;             break;           }         }         ans = max(ans, num);       }       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using pii = pair<int, int>;   using vi = vector<int>;   using vll = vector<ll>;   const string ALPHA =  abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ;   string NAME[3] = { Kuro ,  Shiro ,  Katie };   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout << fixed << setprecision(20);     ll N;     while (cin >> N) {       vector<string> S(3);       vll ma(3);       for (int(a) = (0); (a) < (int)(3); ++(a)) {         cin >> S[a];         for (char b : ALPHA) {           ll x = 0;           for (auto &(c) : (S[a])) {             if (b == c) x++;           }           if (N > (int)(S[a]).size() - x) {             ll p = N - (int)(S[a]).size() + x;             if (p == 1 && x == (int)(S[a]).size())               (ma[a]) = max((ma[a]), ((int)(S[a]).size() - p));             else               (ma[a]) = max((ma[a]), ((ll)(int)(S[a]).size()));           } else {             (ma[a]) = max((ma[a]), (N + x));           }         }       }       ll m = -1, cnt = 0, cat = -1;       for (int(a) = (0); (a) < (int)(3); ++(a)) {         if (m < ma[a]) {           cat = a;           m = ma[a];         }       }       for (int(a) = (0); (a) < (int)(3); ++(a))         if (m == ma[a]) cnt++;       if (cnt > 1)         cout <<  Draw  << endl;       else         cout << NAME[cat] << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     long long a, b, sum = 0;     vector<long long> A;     int n;     cin >> n;     A.resize(n);     for (int i = 0; i < n; i++) {       cin >> a;       sum += a;       A[i] = sum;     }     b = sum / 2 + (sum % 2);     a = 0;     while (A[a] < b) a++;     cout << a + 1;   }


#include <bits/stdc++.h>   int main() {     int n, c = 0, i, s = 0, j, k = 0;     scanf( %d , &n);     for (i = 1; i <= n; i++) {       for (j = 1; j <= i; j++) {         s = s + j;         if (s > n) {           k = 1;           break;         }       }       c = c + 1;       if (k == 1) {         c--;         break;       }     }     printf( %d , c);   }


#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 10;   int awsl[maxn];   int main() {     int n;     scanf( %d , &n);     string s;     cin >> s;     vector<int> sum(n);     vector<int> m(n);     for (int i = 0; i < n; ++i) {       if (s[i] ==  ( )         awsl[i] = 1;       else         awsl[i] = -1;     }     sum[0] = awsl[0];     for (int i = 1; i < n; ++i) {       sum[i] = sum[i - 1] + awsl[i];     }     m.back() = sum.back();     for (int i = n - 2; i >= 0; i--) {       m[i] = min(sum[i], m[i + 1]);     }     int cnt = 0;     for (int i = 0; i < n; ++i) {       int v = 2 * awsl[i];       if (m[i] - v >= 0 && sum.back() - v == 0) cnt++;       if (sum[i] < 0) break;     }     cout << cnt <<   n ;   }


#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:256000000 )   using namespace std;   int d[100005];   int pr[100005];   int cnt[100005];   int a[100005];   vector<int> g[100005];   int b[100005];   int main() {     int n, i, j;     scanf( %d , &n);     for (i = 1; i <= n; ++i) {       scanf( %d , &a[i]);       ++cnt[a[i]];     }     for (i = 1; i <= n; ++i) {       int x;       scanf( %d , &x);       d[a[i]] += x;       g[a[i]].push_back(x);     }     for (i = 100000; i > 0; --i) {       pr[i] = pr[i + 1] + d[i];     }     int tot = 0;     int ans = 1000000000;     for (i = 1; i <= 100000; ++i) {       if (cnt[i] == 0) continue;       int cost = pr[i + 1];       int need = tot + cnt[i] - (cnt[i] * 2 - 1);       for (j = 1; j <= 200; ++j) {         if (need <= 0) break;         if (need - b[j] >= 0) {           need -= b[j];           cost += j * b[j];         } else {           cost += need * j;           need = 0;           break;         }       }       if (cost < ans) {         ans = cost;       }       for (j = 0; j < g[i].size(); ++j) {         ++b[g[i][j]];       }       tot += cnt[i];     }     cout << ans;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   int n, m, cnt, a[300002];   int32_t main() {     ios_base ::sync_with_stdio(0);     cin.tie();     cout.tie();     cin >> n >> m;     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = 1; i <= n - 1; i++)       if (a[i] <= a[i + 1]) cnt++;     if (cnt == n - 1) return cout << 0, 0;     int l = 0, r = m;     while (r - l > 1) {       int cur = 0, mid = (l + r) / 2;       bool ctrl = true;       for (int i = 1; i <= n && ctrl; i++) {         int mn = m, mx = 0;         if (a[i] + mid >= m)           mn = 0;         else           mn = a[i];         if (a[i] + mid >= m - 1)           mx = m - 1;         else           mx = a[i] + mid;         if (mx < cur) {           ctrl = false;         } else if (a[i] > cur && mn == 0 && ((a[i] + mid) % m) < cur)           cur = a[i];         else if (a[i] > cur && mn != 0)           cur = a[i];       }       if (ctrl)         r = mid;       else         l = mid;     }     cout << r;   }


#include <bits/stdc++.h>   using namespace std;   long long inf = 1e18 + 42;   const double eps = 1e-8;   const int M = 1e9 + 7;   const int MN = 1e9;   int main() {     vector<int> In;     for (int i = 1; i <= 4; i++) {       cout <<  ?   << i <<     << i + 1 << endl;       int x;       cin >> x;       In.push_back(x);     }     vector<int> v = {4, 8, 15, 16, 23, 42};     do {       vector<int> res;       for (int i = 1; i <= 4; i++) {         res.push_back(v[i - 1] * v[i]);       }       if (res == In) {         cout <<  !  ;         for (int x : v) cout << x <<    ;         cout << endl;         return 0;       }     } while (next_permutation(v.begin(), v.end()));     return 0;   }


#include <bits/stdc++.h>   using namespace std;   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     long long t = 1;     cin >> t;     while (t--) {       long long n, i, j;       string s, a, b;       cin >> n >> s;       a = b =   ;       bool flag = true;       ;       a +=  1 , b +=  1 ;       for (i = 1; i < n; i++) {         if (s[i] ==  0 ) {           a +=  0 , b +=  0 ;         } else if (s[i] ==  1 ) {           if (flag) {             a +=  1 ;             b +=  0 ;             flag = false;           } else {             a +=  0 ;             b +=  1 ;           }         } else if (s[i] ==  2 ) {           if (flag) {             a +=  1 , b +=  1 ;           } else {             a +=  0 , b +=  2 ;           }         }       }       cout << a <<   n  << b <<   n ;     }     return 0;   }


#include<bits/stdc++.h>   #define rep(i,a,b) for(long long i=a;i<b;i++)   #define pb push_back   #define f first   #define s second   #define is insert   #define vector_int vector<int>   #define ll long long   #define pqi priority_queue<int>   #define all(x) x.begin(),x.end()   #define mem(x,y) memset(x,y,sizeof(x))   #define sz(x) (int)x.size()   #define pii pair<int,int>   #define pll pair<ll,ll>   #define INF 1e9   #define INFL 1e18   #define mod 1000000007   #define fast ios::sync_with_stdio(false);cin.tie(0);   using namespace std;      int equalPartition(int n, vector<int> arr)       {           int sum = 0;       int i, j;           // Calculate sum of all elements       for (i = 0; i < n; i++)           sum += arr[i];           if (sum % 2 != 0)           return false;           bool part[sum / 2 + 1][n + 1];           // initialize top row as true       for (i = 0; i <= n; i++)           part[0][i] = true;           // initialize leftmost column,       // except part[0][0], as 0       for (i = 1; i <= sum / 2; i++)           part[i][0] = false;           // Fill the partition table in bottom up manner       for (i = 1; i <= sum / 2; i++) {           for (j = 1; j <= n; j++) {               part[i][j] = part[i][j - 1];               if (i >= arr[j - 1])                   part[i][j] = part[i][j]                                || part[i - arr[j - 1]][j - 1];           }       }           /* // uncomment this part to print table       for (i = 0; i <= sum/2; i++)       {       for (j = 0; j <= n; j++)           cout<<part[i][j];       cout<<endl;       } */           return part[sum / 2][n];       }      void solve(){       ll n=0;cin>>n;       vector<int> arr;       for(int i=0;i<n;i++) {           int x;           cin>>x;           arr.pb(x);       }       if(equalPartition( n,arr)==0) cout<<0<<endl;       else {           for(int i=0;i<n;i++){               int x=arr[i];               arr[i]=0;               if(equalPartition(n,arr)==0) {                   cout<<1<<endl<<i+1<<endl;                   break;               }               else{                   arr[i]=x;               }           }       }   }       int main() {                  solve();              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 int t;     cin >> t;     while (t--) {       long long int n;       cin >> n;       long long int arr[2 * n], maxi[2 * n], c = 1;       vector<long long int> v;       for (int i = 0; i < 2 * n; i++) {         cin >> arr[i];         if (!i)           maxi[i] = arr[i];         else           maxi[i] = max(maxi[i - 1], arr[i]);       }       for (int i = 1; i < 2 * n; i++) {         if (maxi[i] != maxi[i - 1])           v.push_back(c), c = 1;         else           c++;       }       v.push_back(c);       long long int dp[v.size()][n + 1];       for (int i = 0; i < v.size(); i++) {         for (int j = 0; j <= n; j++) dp[i][j] = 0;       }       dp[0][v[0]] = 1;       for (int i = 1; i < v.size(); i++) {         for (int j = 0; j <= n; j++) dp[i][j] = dp[i - 1][j];         for (int j = v[i]; j <= n; j++) {           if (dp[i - 1][j - v[i]]) dp[i][j] = 1;         }       }       if (dp[v.size() - 1][n])         cout <<  YES n ;       else         cout <<  NO n ;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   struct proc {     string name;     string var[10];   };   struct vari {     string name;     string x;   };   string s, t, name, varr[10];   proc a[1005];   vari b[1005];   int res, n, m, k, para[1005], p;   bool check;   int main() {     if (0) {       freopen( a.inp ,  r , stdin);     };     scanf( %d n , &n);     size_t found;     for (int i = 0; i < n; i++) {       getline(cin, s);       found = s.find( void );       s.erase(0, int(found) + 4);       while (s[0] ==    ) s.erase(0, 1);       for (int j = 0; j < s.length(); j++) {         if (s[j] ==     || s[j] ==  ( ) break;         a[i].name += s[j];       }       t =   ;       found = s.find( ( );       for (int j = int(found) + 1; s[j] !=  ) ; j++) {         if (s[j] ==  ,  || s[j] ==    ) continue;         while (s[j] !=  ,  && s[j] !=     && s[j] !=  ) ) t += s[j], j++;         para[i]++;         a[i].var[para[i]] = t;         t =   ;         if (s[j] ==  ) ) break;       }     }     scanf( %d n , &m);     for (int i = 0; i < m; i++) {       getline(cin, s);       int j = 0;       t =   ;       while (s[j] ==    ) j++;       while (s[j] !=    ) t += s[j], j++;       b[i].x = t;       t =   ;       while (s[j] ==    ) j++;       while (j < s.length() && s[j] !=    ) t += s[j], j++;       b[i].name = t;     }     scanf( %d n , &k);     for (int i = 0; i < k; i++) {       getline(cin, s);       int j = 0;       while (s[j] ==    ) j++;       t =   ;       while (s[j] !=     && s[j] !=  ( ) t += s[j], j++;       name = t;       while (s[j] !=  ( ) j++;       j++;       t =   ;       p = 0;       for (; s[j] !=  ) ; j++) {         if (s[j] ==     || s[j] ==  , ) continue;         while (s[j] !=     && s[j] !=  ,  && s[j] !=  ) ) t += s[j], j++;         check = false;         for (int x = 0; x < m; x++)           if (b[x].name == t) {             t = b[x].x;             check = true;             break;           }         if (!check) break;         p++;         varr[p] = t;         t =   ;         if (s[j] ==  ) ) break;       }       if (!check) {         printf( 0 n );         continue;       }       res = 0;       for (int x = 0; x < n; x++) {         if (para[x] != p || a[x].name != name) continue;         check = true;         for (int y = 1; y <= p; y++) {           if (a[x].var[y][0] ==  T ) continue;           if (a[x].var[y][0] != varr[y][0]) {             check = false;             break;           }         }         if (check) res++;       }       printf( %d n , res);     }   }


#include <bits/stdc++.h>   using namespace std;   int dirx[] = {-1, -1, -1, 0, 0, 1, 1, 1};   int diry[] = {-1, 0, 1, -1, 1, -1, 0, 1};   const int N = 1e2 + 5, M = (1 << 17) + 5, inf = 1e7;   int a[N], dp[N][M], bit[N], n;   bool ip(int i) {     for (int it = 2; it * it <= i; it++) {       if (i % it == 0) return false;     }     return true;   }   int rec(int idx, int mask) {     int &res = dp[idx][mask];     if (idx == n) return res = 0;     if (~res) return res;     res = inf;     for (long long i = (1); i <= (60); ++i) {       if (bit[i] & mask) continue;       res = min(res, rec(idx + 1, mask | bit[i]) + abs(a[idx] - (int)i));     }     return res;   }   void print(int idx, int mask) {     if (idx == n) return;     for (long long i = (1); i <= (60); ++i) {       if ((bit[i] & mask) == 0 &&           dp[idx][mask] == (dp[idx + 1][mask | bit[i]] + abs(a[idx] - i))) {         cout << i <<    ;         print(idx + 1, mask | bit[i]);         break;       }     }   }   int main() {     memset(dp, -1, sizeof dp);     ;     cin >> n;     for (long long i = 0; i < n; i++) cin >> a[i];     int idx = 0;     for (long long i = (2); i <= (60); ++i) {       if (ip(i)) {         for (int j = i; j <= 60; j += i) {           bit[j] |= (1 << idx);         }         idx++;       }     }     rec(0, 0);     print(0, 0);   }


#include <bits/stdc++.h>   using namespace std;   mt19937 rng32(chrono::steady_clock::now().time_since_epoch().count());   long long inf = 1e18, MOD = 1e9 + 7;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int ti = 1;     while (ti--) {       int n;       cin >> n;       vector<long long> in(n + 1), cnt(n + 1, 0);       map<pair<long long, long long>, long long> ma;       for (int i = 1; i <= n; i++) cin >> in[i];       long long ans = accumulate(in.begin(), in.end(), 0ll);       int q;       cin >> q;       while (q--) {         long long s, t, u;         cin >> s >> t >> u;         long long prev = ma[make_pair(s, t)];         if (prev != 0) {           if (cnt[prev] <= in[prev]) ans++;           cnt[prev]--;         }         if (u != 0) {           if (cnt[u] < in[u]) ans--;           cnt[u]++;         }         ma[make_pair(s, t)] = u;         cout << ans << endl;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int N = 5e5 + 100;   int f[N];   struct node {     int u, v, w;     bool operator<(const node& a) const { return w < a.w; }   };   struct qq {     int id, u, v, w;     bool operator<(const qq& a) const {       if (a.w == w) return id < a.id;       return w < a.w;     }   };   vector<pair<int, int> > v;   qq q[N];   node pt[N];   bool vis[N];   int Find(int x, bool tmp) {     if (tmp) v.push_back({x, f[x]});     return x == f[x] ? x : f[x] = Find(f[x], tmp);   }   int main() {     int n, m;     cin >> n >> m;     for (int i = 1; i <= m; i++) {       scanf( %d %d %d , &pt[i].u, &pt[i].v, &pt[i].w);     }     int qs;     cin >> qs;     int tot = 0;     for (int i = 1; i <= qs; i++) {       int k;       scanf( %d , &k);       for (int j = 1; j <= k; j++) {         q[tot].id = i;         int now;         scanf( %d , &now);         q[tot].u = pt[now].u;         q[tot].v = pt[now].v;         q[tot].w = pt[now].w;         tot++;       }     }     sort(q, q + tot);     sort(pt + 1, pt + 1 + m);     int cnt = 0;     for (int i = 1; i <= n; i++) f[i] = i;     for (int i = 1; i <= m; i++) {       while (cnt < tot && q[cnt].w == pt[i].w) {         queue<qq> que;         que.push(q[cnt]);         int tmp = q[cnt].id;         for (int j = cnt + 1; j <= tot; j++) {           if (q[j].w == q[j - 1].w && q[j].id == q[j - 1].id)             que.push(q[j]);           else {             cnt = j;             break;           }         }         bool res = true;         while (!que.empty()) {           qq now = que.front();           que.pop();           int f1 = Find(now.u, true);           int f2 = Find(now.v, true);           if (f1 == f2) {             res = false;             break;           }           f[f1] = f2;           v.push_back({f1, f1});         }         if (res == false) vis[tmp] = true;         for (int i = v.size() - 1; i >= 0; i--) {           f[v[i].first] = v[i].second;         }         v.clear();       }       int f1 = Find(pt[i].u, false);       int f2 = Find(pt[i].v, false);       if (f1 == f2) continue;       f[f1] = f2;     }     int cns = 0;     for (int i = 1; i <= n; i++)       if (Find(i, false) == i) cns++;     if (cns >= 2) {       for (int i = 1; i <= qs; i++) {         puts( NO );       }     } else {       for (int i = 1; i <= qs; i++) {         if (vis[i])           puts( NO );         else           puts( YES );       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[1000005], n;   long long ans = 0;   long long now = 0;   long long solve(long long p) {     ans = 0;     now = 0;     for (int i = 1; i <= n; i++) {       now += a[i];       now %= p;       ans += min(now, p - now);     }     return ans;   }   int main() {     cin >> n;     long long sum = 0;     for (int i = 1; i <= n; i++) {       scanf( %d , a + i);       sum = sum + a[i];     }     if (sum == 1) {       cout <<  -1  << endl;     } else {       long long ans0 = (1ll << 62);       for (int p = 2; p <= 1e6; p++) {         if (sum % p == 0) {           ans0 = min(ans0, solve(p));           while (sum % p == 0) sum /= p;         }       }       if (sum != 1) ans0 = min(ans0, solve(sum));       cout << ans0 << endl;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     scanf( %d %d , &n, &k);     vector<long long int> v;     vector<long long int>::iterator it;     long long int a[k], i, j, c, t, x;     for (i = 0; i < k; i++) scanf( %lld , &a[i]);     for (i = 1; i <= n; i++) v.push_back(i);     c = 0;     for (i = 0; i < k; i++) {       c = (c + a[i]) % (n);       cout << v[c] <<    ;       v.erase(v.begin() + c);       n--;     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline string toString(T a) {     ostringstream os(  );     os << a;     return os.str();   }   template <typename T>   inline long long toLong(T a) {     long long res;     istringstream os(a);     os >> res;     return res;   }   template <typename T>   inline int toInt(T a) {     int res;     istringstream os(a);     os >> res;     return res;   }   template <typename T>   inline double toDouble(T a) {     double res;     istringstream os(a);     os >> res;     return res;   }   template <typename T>   inline T SQ(T a) {     return a * a;   }   template <typename T>   inline T GCD(T a, T b) {     if (b == 0)       return a;     else       return GCD(b, a % b);   }   template <typename T>   inline T LCM(T a, T b) {     long long res = a * b;     res /= GCD(a, b);     return res;   }   template <typename T>   inline unsigned long long BIGMOD(T a, T b, T m) {     if (b == 0)       return 1;     else if (b % 2 == 0)       return SQ(BIGMOD(a, b / 2, m)) % m;     else       return (a % m * BIGMOD(a, b - 1, m)) % m;   }   template <typename T>   inline vector<string> PARSE(T str) {     vector<string> res;     string s;     istringstream os(str);     while (os >> s) res.push_back(s);     return res;   }   template <typename T>   inline unsigned long long DIST(T A, T B) {     unsigned long long res =         (A.x - B.x) * (A.x - B.x) + (A.y - B.y) * (A.y - B.y);     return res;   }   template <typename T>   inline long long CROSS(T A, T B, T C) {     return (B.x - A.x) * (C.y - A.y) - (C.x - A.x) * (B.y - A.y);   }   template <typename T>   inline double cosAngle(T a, T b, T c) {     double res = a * a + b * b - c * c;     res = res / (2 * a * b);     res = acos(res);     return res;   }   template <typename T>   inline T POWER(T base, int po) {     T res = 1;     if (base == 0) return 0;     for (int i = (0); i < (po); i++) res *= base;     return res;   }   template <typename T>   inline bool IS_ON(T mask, T pos) {     return mask & (1 << pos);   }   template <typename T>   inline int OFF(T mask, T pos) {     return mask ^ (1 << pos);   }   template <typename T>   inline int ON(T mask, T pos) {     return mask | (1 << pos);   }   template <typename T>   inline bool INSIDE_GRID(int R, int C, int ro, int clm) {     if (R >= 0 && C >= 0 && R < ro && C < clm) return 1;     return 0;   }   template <typename T>   inline void PRINT_GRID(T GRID, int ro, int clm) {     cout <<  GRID           <<  :   << GRID << endl;     for (int i = (0); i < (ro); i++) {       for (int j = (0); j < (clm); j++) cout << GRID[i][j] <<    ;       puts(  );     }   }   long long arr[500005];   vector<pair<long long, int> > inp;   int main() {     ios_base::sync_with_stdio(0);     cin.tie();     ;     int n;     cin >> n;     for (int i = (0); i < (n); i++) {       cin >> arr[i];       inp.push_back(make_pair(arr[i], i));     }     sort((inp).begin(), (inp).end());     long long hell = 0;     for (int i = (0); i < (n); i++) {       hell = max(inp[i].first, hell + 1);       arr[inp[i].second] = hell;     }     for (int i = (0); i < (n); i++) cout << arr[i] <<    ;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     pair<int, int> u, v;     int n, ans = 0;     long long a, b, c, p, q;     scanf( %d%d%d%d , &u.first, &u.second, &v.first, &v.second);     scanf( %d , &n);     while (n--) {       scanf( %lld%lld%lld , &a, &b, &c);       p = a * u.first + b * u.second + c;       q = a * v.first + b * v.second + c;       if ((p > 0 && q < 0) || (p < 0 && q > 0)) ++ans;     }     printf( %d n , ans);   }


#include <bits/stdc++.h>   using namespace std;   int dp, p[201000], tt[201000], pre[201000], l[201000], vis[201000];   int n, m, i, j, a[1010][1010], g[201000], now[201000], s, t, dis[201000],       z[201000], ans;   void link(int x, int y, int z) {     dp++;     pre[dp] = p[x];     p[x] = dp;     tt[dp] = y;     g[dp] = z;   }   int dfs(int x) {     int i;     i = p[x];     while (i) {       if (vis[tt[i]] == 0) {         vis[tt[i]] = 1;         if ((l[tt[i]] == 0) || (dfs(l[tt[i]]))) {           l[tt[i]] = x;           return 1;         }       }       i = pre[i];     }     return 0;   }   int bfs() {     int i, head, tail;     memcpy(now, p, sizeof(p));     memset(vis, 0, sizeof(vis));     head = 0;     tail = 1;     vis[s] = 1;     dis[s] = 0;     z[tail] = s;     do {       head++;       i = p[z[head]];       while (i) {         if ((vis[tt[i]] == 0) && (g[i] > 0)) {           vis[tt[i]] = 1;           dis[tt[i]] = dis[z[head]] + 1;           tail++;           z[tail] = tt[i];         }         i = pre[i];       }     } while (head != tail);     return vis[t];   }   int dfs(int u, int flow) {     int ans, tmp, i;     if (u == t) return flow;     i = now[u];     ans = 0;     while (i) {       if ((dis[u] + 1 == dis[tt[i]]) && (g[i] > 0)) {         tmp = dfs(tt[i], min(flow - ans, g[i]));         ans += tmp;         g[i] -= tmp;         if (i % 2 == 1)           g[i + 1] += tmp;         else           g[i - 1] += tmp;         if (flow == ans) return flow;       }       i = pre[i];       now[u] = i;     }     if (flow > ans) dis[u] = 1;     return ans;   }   int main() {     cin >> n;     for (i = 1; i <= n; i++) {       cin >> a[i][0];       for (j = 1; j <= a[i][0]; j++) {         cin >> a[i][j];         link(n + i, a[i][j], 0);       }     }     for (i = n + 1; i <= 2 * n; i++) {       memset(vis, 0, sizeof(vis));       dfs(i);     }     dp = 0;     memset(p, 0, sizeof(p));     s = 0;     t = n + 1;     for (i = 1; i <= n; i++) {       cin >> m;       if (m > 0) {         link(s, i, m);         link(i, s, 0);       } else {         ans += m;         link(i, t, -m);         link(t, i, 0);       }     }     for (i = 1; i <= n; i++) {       for (j = 1; j <= a[i][0]; j++)         if (l[a[i][j]] - n != i) {           link(l[a[i][j]] - n, i, 0x37373737);           link(i, l[a[i][j]] - n, 0);         }     }     while (bfs()) ans += dfs(s, 0x37373737);     cout << ans;   }


#include <bits/stdc++.h>   using namespace std;   int n;   string s;   bool ok1 = 1, ok2 = 1;   int a[220], b[220], l[110], r[110];   void qs(int u[], int L, int R) {     int i = L;     int j = R;     int m = u[(L + R) >> 1];     while (i < j) {       while (u[i] < m) i++;       while (u[j] > m) j--;       if (i <= j) {         swap(u[i], u[j]);         i++;         j--;       }     }     if (L < j) qs(u, L, j);     if (i < R) qs(u, i, R);   }   int main() {     cin >> n;     cin >> s;     for (size_t i = 0; (int)i < s.size(); ++i) a[i] = s[i] -  0 ;     for (int i = 0; i < n; i++) {       l[i] = a[i];     }     for (int i = 0; i < n; i++) {       r[i] = a[i + n];     }     qs(r, 0, n - 1);     qs(l, 0, n - 1);     for (size_t i = 0; (int)i < n; ++i) {       if (!(l[i] > r[i])) {         ok1 = 0;       }       if (!(l[i] < r[i])) {         ok2 = 0;       }     }     if (ok1 || ok2) {       printf( YES );       return 0;     }     printf( NO );     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, k;   int arr[1000008];   int l[1000008];   int mx[1000008 << 2], lazy[1000008 << 2];   void pushup(int rt) { mx[rt] = max(mx[rt << 1], mx[rt << 1 | 1]); }   void build(int rt, int l, int r) {     if (l > r) return;     if (l == r) {       mx[l] = arr[l];       return;     }     int mid = (l + r) >> 1;     build(rt << 1, l, mid);     build(rt << 1 | 1, mid + 1, r);     pushup(rt);   }   void pushdown(int rt) {     mx[rt << 1] += lazy[rt];     mx[rt << 1 | 1] += lazy[rt];     lazy[rt << 1] += lazy[rt];     lazy[rt << 1 | 1] += lazy[rt];     lazy[rt] = 0;   }   void update(int rt, int l, int r, int L, int R, int C) {     if (L <= l && r <= R) {       lazy[rt] += C;       mx[rt] += C;       return;     }     pushdown(rt);     int mid = (l + r) >> 1;     if (L <= mid) update(rt << 1, l, mid, L, R, C);     if (mid < R) update(rt << 1 | 1, mid + 1, r, L, R, C);     pushup(rt);   }   int query(int rt, int l, int r, int L, int R) {     if (L <= l && r <= R) return mx[rt];     int mid = (l + r) >> 1;     pushdown(rt);     int ret = -1;     if (L <= mid) ret = max(ret, query(rt << 1, l, mid, L, R));     if (mid < R) ret = max(ret, query(rt << 1 | 1, mid + 1, r, L, R));     return ret;   }   stack<int> sta;   int main() {     scanf( %d %d , &n, &k);     for (int i = 1; i <= n; ++i) scanf( %d , &arr[i]);     for (int i = n; i >= 1; --i) {       while (!sta.empty() && arr[sta.top()] <= arr[i]) {         l[sta.top()] = i + 1;         sta.pop();       }       sta.push(i);     }     while (!sta.empty()) {       l[sta.top()] = 1;       sta.pop();     }     for (int i = 1; i <= n; ++i) {       update(1, 1, n, l[i], i, 1);       if (i >= k) {         printf( %d  , query(1, 1, n, i - k + 1, i));         update(1, 1, n, l[i - k + 1], i - k + 1, -1);       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int c[100005], n, m;   map<int, int> f;   int lowbit(int x) { return x & (-x); }   void add(int x, int j) {     while (x < 100005) {       c[x] += j;       x += lowbit(x);     }   }   int sum(int x) {     int s = 0;     while (x > 0) {       s += c[x];       x -= lowbit(x);     }     return s;   }   struct node {     int id;     int num;   } a[100005];   bool cmp_id(node A, node B) { return A.id < B.id; }   bool cmp_num(node A, node B) { return A.num < B.num; }   int main() {     int i, j, k, m, cnt, ans, tem;     while (scanf( %d , &n) != EOF) {       f.clear();       cnt = 1;       ans = 0;       for (i = 1; i <= n; i++) {         scanf( %d , &a[i].num);         a[i].id = i;       }       sort(a + 1, a + 1 + n, cmp_num);       for (i = 1; i <= n; i++)         if (f[a[i].num] == 0) f[a[i].num] = cnt++;       sort(a + 1, a + 1 + n, cmp_id);       for (i = 1; i <= n; i++) a[i].num = f[a[i].num];       for (i = 1; i <= n; i++) add(a[i].num, 1);       for (i = n; i >= 1; i--) {         tem = sum(a[i].num);         add(a[i].num, -1);         if (tem == i)           ans++;         else {           int ant = a[i].num;           while (i--) {             ant = min(a[i].num, ant);             int tp = sum(ant);             add(a[i].num, -1);             if (sum(ant) == i - 1) break;           }           ans++;         }       }       printf( %d n , ans);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     cin.tie(nullptr);     ios::sync_with_stdio(false);     int n, q;     cin >> n >> q;     deque<int> deq;     for (int i = 0; i < n; i++) {       int a;       cin >> a;       deq.push_back(a);     }     vector<pair<int, int>> ans;     for (int i = 0; i < 2 * n + 7; i++) {       int a = deq.front();       deq.pop_front();       int b = deq.front();       deq.pop_front();       ans.push_back(make_pair(a, b));       if (b > a) {         swap(b, a);       }       deq.push_front(a);       deq.push_back(b);     }     while (q--) {       long long int x;       cin >> x;       x--;       if (x < 2 * n) {         cout << ans[x].first <<     << ans[x].second << endl;       } else {         x -= n;         x %= (n - 1);         x += n;         cout << ans[x].first <<     << ans[x].second << endl;       }     }   }


#include <bits/stdc++.h>   using namespace std;   struct BIT {     int N;     vector<int> B;     BIT(int n = 0) {       N = n;       B.resize(n + 2, 0);     }     void add(int x, int v) {       x++;       while (x <= N) {         B[x] += v;         x += x & -x;       }     }     int sum(int x) {       int s = 0;       x++;       while (x > 0) {         s += B[x];         x -= x & -x;       }       return s;     }     int sum(int a, int b) { return sum(b) - sum(a - 1); }   };   int main() {     int h, m, n;     scanf( %d%d%d , &h, &m, &n);     long long sol = 0;     map<int, pair<int, int> > pos;     vector<BIT> X;     vector<bool> visited(h, false);     vector<int> ai(h), bi(h);     for (int i = 0; i < h; ++i) {       if (!visited[i]) {         int cnt = 0;         for (int j = i; !visited[j]; j = (j + m) % h) {           visited[j] = true;           ai[j] = X.size();           bi[j] = cnt;           cnt++;         }         X.push_back(BIT(cnt));       }     }     for (int i = 0; i < n; ++i) {       char op[8];       scanf( %s , op);       int id, hs;       if (op[0] ==  - ) {         scanf( %d , &id);         X[pos[id].first].add(pos[id].second, -1);       } else {         scanf( %d%d , &id, &hs);         int xi = ai[hs], ti = bi[hs];         assert(X[xi].sum(0, X[xi].N - 1) < X[xi].N);         if (X[xi].sum(ti, X[xi].N - 1) == X[xi].N - ti) {           int lo = -1, hi = ti - 1;           sol += X[xi].N - ti;           while (hi - lo > 1) {             int mid = (hi + lo) / 2;             if (X[xi].sum(0, mid) == mid + 1)               lo = mid;             else               hi = mid;           }           sol += hi;           X[xi].add(hi, 1);           pos[id] = make_pair(xi, hi);         } else {           int lo = ti - 1, hi = X[xi].N - 1;           while (hi - lo > 1) {             int mid = (hi + lo) / 2;             if (X[xi].sum(ti, mid) == mid - ti + 1)               lo = mid;             else               hi = mid;           }           sol += hi - ti;           X[xi].add(hi, 1);           pos[id] = make_pair(xi, hi);         }       }     }     printf( %I64d n , sol);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int const N = 70;   int dx[] = {0, 0, 1, -1};   int dy[] = {1, -1, 0, 0};   char s[N][N];   int vis[N][N];   int n, m;   int dfs(int x, int y) {     if (s[x][y] !=  #  || vis[x][y]) return 0;     vis[x][y] = 1;     for (int i = 0; i < (4); i++) dfs(x + dx[i], y + dy[i]);     return 1;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < (n); i++) scanf( %s , s[i]);     int cnt = 0;     for (int i = 0; i < (n); i++)       for (int j = 0; j < (m); j++) {         if (s[i][j] ==  . ) continue;         cnt++;         s[i][j] =  . ;         int k = 0;         memset(vis, 0, sizeof(vis));         for (int d = 0; d < (4); d++) k += dfs(i + dx[d], j + dy[d]);         if (k > 1) {           puts( 1 );           return 0;         }         s[i][j] =  # ;       }     printf( %d n , cnt > 2 ? 2 : -1);   }


#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-10;   const long long mod = 1e6 + 3;   const int INF = 1e9 + 1;   const int N = 105;   long long H[N], c, h, w;   struct Matrix {     long long arr[N][N];     Matrix() { memset(arr, 0, sizeof arr); }     Matrix(int x) {       memset(arr, 0, sizeof arr);       for (int i = 0; i < w + 1; i++) arr[i][i] = x;     }     Matrix operator*(Matrix a) {       Matrix ret;       for (int i = 0; i < w + 1; i++) {         for (int j = 0; j < w + 1; j++) {           for (int k = 0; k < w + 1; k++) {             ret.arr[i][j] += this->arr[i][k] * a.arr[k][j];             ret.arr[i][j] %= mod;           }         }       }       return ret;     }   };   Matrix poww(Matrix a, int p) {     if (!p) return Matrix(1);     Matrix ret = poww(a, p >> 1);     ret = ret * ret;     if (p & 1) ret = ret * a;     return ret;   }   void print(Matrix a) {     for (int i = 0; i < w + 1; i++) {       for (int j = 0; j < w + 1; j++) {         cout << a.arr[i][j] <<    ;       }       cout <<   n ;     }     cout <<   n ;   }   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     H[0] = 1;     cin >> c >> w >> h;     for (int i = 1; i < N; i++) H[i] = (H[i - 1] * h) % mod;     Matrix A = Matrix(), B = Matrix();     for (int i = 0; i < w + 1; i++) {       B.arr[i][0] = H[i];     }     for (int i = 0; i < w; i++) {       B.arr[i][i + 1] = 1;     }     A.arr[0][0] = A.arr[0][1] = 1;     B = poww(B, c + 1);     cout << B.arr[0][0];   }


#include <bits/stdc++.h>   using namespace std;   template <class T1>   void deb(T1 e) {     cout << e << endl;   }   template <class T1, class T2>   void deb(T1 e1, T2 e2) {     cout << e1 <<     << e2 << endl;   }   template <class T1, class T2, class T3>   void deb(T1 e1, T2 e2, T3 e3) {     cout << e1 <<     << e2 <<     << e3 << endl;   }   template <class T1, class T2, class T3, class T4>   void deb(T1 e1, T2 e2, T3 e3, T4 e4) {     cout << e1 <<     << e2 <<     << e3 <<     << e4 << endl;   }   template <class T1, class T2, class T3, class T4, class T5>   void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5) {     cout << e1 <<     << e2 <<     << e3 <<     << e4 <<     << e5 << endl;   }   template <class T1, class T2, class T3, class T4, class T5, class T6>   void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5, T6 e6) {     cout << e1 <<     << e2 <<     << e3 <<     << e4 <<     << e5 <<     << e6          << endl;   }   long long sqr(long long n) { return n * n; }   double LOG(long long a, long long b) { return (log(a) / log(b)); }   long long GCD(long long a, long long b) {     if (a < 0) return GCD(-a, b);     if (b < 0) return GCD(a, -b);     return (!b) ? a : GCD(b, a % b);   }   long long LCM(long long a, long long b) {     if (a < 0) return LCM(-a, b);     if (b < 0) return LCM(a, -b);     return (a * (b / GCD(a, b)));   }   long long BigMod(long long B, long long P, long long M) {     if (!P) return 1;     if (!(P % 2)) return sqr(BigMod(B, P / 2, M)) % M;     return (B % M) * (BigMod(B, P - 1, M)) % M;   }   int par[205];   int dp[105][105][105];   string s1, s2, vir;   string ans;   int rec(int x, int y, int z) {     if (z == (int)vir.size()) return -(1 << 30);     if (x == (int)s1.size() || y == (int)s2.size()) return 0;     int &ret = dp[x][y][z];     if (ret != -1) return ret;     ret = rec(x + 1, y, z);     ret = max(ret, rec(x, y + 1, z));     if (s1[x] == s2[y]) {       int k = z;       while (k > 0 && s1[x] != vir[k]) k = par[k - 1];       if (s1[x] == vir[k]) k++;       ret = max(ret, rec(x + 1, y + 1, k) + 1);     }     return ret;   }   void prec(int x, int y, int z) {     if (z == (int)vir.size()) return;     if (x == (int)s1.size() || y == (int)s2.size()) return;     int &ret = dp[x][y][z];     if (ret == rec(x + 1, y, z)) return prec(x + 1, y, z);     if (ret == rec(x, y + 1, z)) return prec(x, y + 1, z);     if (s1[x] == s2[y]) {       int k = z;       while (k > 0 && s1[x] != vir[k]) k = par[k - 1];       if (s1[x] == vir[k]) k++;       if (ret == rec(x + 1, y + 1, k) + 1) {         ans += s1[x];         return prec(x + 1, y + 1, k);       }     }     return;   }   int main(void) {     cin >> s1 >> s2 >> vir;     memset(par, 0, sizeof(par));     int k = 0;     string cur = vir;     for (int i = 1; i < (int)cur.size(); i++) {       while (k > 0 && cur[i] != cur[k]) k = par[k - 1];       if (cur[i] == cur[k]) k++;       par[i] = k;     }     memset(dp, -1, sizeof(dp));     int res = rec(0, 0, 0);     if (!res) {       deb(res);       return 0;     }     ans =   ;     prec(0, 0, 0);     deb(ans);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int is_prime[5000010 + 10], primes[5000010 + 10], firstp[5000010 + 10],       prime_cnt;   void get_primes() {     memset(is_prime, -1, sizeof(is_prime));     for (int i = 2; i <= 5000010; i++) {       if (is_prime[i]) {         primes[prime_cnt++] = i;         firstp[i] = i;       }       for (int j = 0; j < prime_cnt && primes[j] * i <= 5000010; j++) {         firstp[i * primes[j]] = primes[j];         is_prime[i * primes[j]] = 0;         if (i % primes[j] == 0) break;       }     }   }   long long bin[5000010], f[5000010], t, l, r;   int main() {     get_primes();     scanf( %I64d %I64d %I64d , &t, &l, &r);     long long ans = 0, pre = 1;     for (int i = 2; i < (5000001); i++)       f[i] = (f[i / firstp[i]] + (1LL * i * (firstp[i] - 1)) / 2 % 1000000007) %              1000000007;     for (int i = l; i < (r + 1); i++) {       ans = (ans + pre * f[i] % 1000000007) % 1000000007;       pre = pre * t % 1000000007;     }     printf( %I64d n , ans);   }


#include <bits/stdc++.h>   int main() {     int a;     scanf( %d , &a);     if (a == 5)       printf( 1 n );     else       printf( %d n , a % 3 + 1);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     cin.tie(nullptr);     cout.tie(NULL);     ios_base::sync_with_stdio(false);     int t;     cin >> t;     while (t--) {       string s;       cin >> s;       int ans = 0;       int one;       bool turn = true;       while (s.size() != 0) {         one = 0;         vector<pair<int, int>> len;         bool go = false;         int start;         for (int i = 0; i < s.size(); i++) {           if (s[i] ==  1 ) {             if (!go) {               start = i;               go = true;             }             if (i == s.size() - 1) {               len.push_back({start, i});             }             one++;           } else {             if (go) {               len.push_back({start, i - 1});               go = false;             }           }         }         if (!one) {           cout <<  0 n ;           break;         }         int length = len[0].second - len[0].first;         pair<int, int> se = {len[0].first, len[0].second};         for (int i = 1; i < len.size(); i++) {           if (length < len[i].second - len[i].first) {             length = len[i].second - len[i].first;             se = {len[i].first, len[i].second};           }         }         if (turn) ans += length + 1;         s.erase(se.first, length + 1);         if (one - (length + 1) == 0) {           cout << ans <<   n ;           break;         }         if (turn)           turn = false;         else           turn = true;       }     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int arr[100000];   int main() {     int n, i, mi = 1e9 + 1, ans, last;     cin >> n, ans = n;     for (i = 0; i < n; i++) cin >> arr[i], mi = min(mi, arr[i]);     for (last = 0; arr[last] != mi; last++)       ;     for (i = last + 1; i < n; i++)       if (arr[i] == mi) ans = min(i - last, ans), last = i;     cout << ans <<   n ;   }


#include <bits/stdc++.h>   using namespace std;   int stak1[200010], tot1, stak0[200010], tot0;   int pre[200010], nex[200010];   char s[200010];   int a[200010];   int n, ans;   int stak_ans[200010], tot_ans;   int main() {     int i, j, k;     scanf( %s , s);     n = strlen(s);     for (i = 0; i < n; i++) a[i + 1] = s[i] ==  1  ? 1 : 0;     for (i = 1; i <= n; i++)       if (a[i]) {         if (!tot0) {           printf( -1 n );           return 0;         }         nex[stak0[tot0]] = i;         pre[i] = stak0[tot0];         tot0--;         stak1[++tot1] = i;       } else {         if (tot1) {           nex[stak1[tot1]] = i;           pre[i] = stak1[tot1];           tot1--;         }         stak0[++tot0] = i;       }     if (tot1) {       printf( -1 n );       return 0;     }     for (i = 1; i <= n; i++)       if (!pre[i]) ans++;     printf( %d n , ans);     for (i = 1; i <= n; i++)       if (!pre[i]) {         j = i, tot_ans = 0;         while (j) {           stak_ans[++tot_ans] = j;           j = nex[j];         }         printf( %d  , tot_ans);         for (j = 1; j <= tot_ans; j++) printf( %d  , stak_ans[j]);         printf(  n );       }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   bool isprime(long long n) {     if (n == 2) return true;     if (n < 2 || n % 2 == 0) return false;     for (long long i = 3; i * i <= n; i += 2) {       if (n % i == 0) return false;     }     return true;   }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     ;     int n;     cin >> n;     if (isprime(n))       cout << 1 << endl;     else if (n % 2 == 0)       cout << 2 << endl;     else if (isprime(n - 2))       cout << 2 << endl;     else       cout << 3 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, x, i;   int reachable[1000000];   int need_to_convert[1000000];   int main(int argc, char **argv) {     scanf( %d , &n);     for (i = 0; i < n; ++i) {       scanf( %d , &x);       int trans_op_num = 0;       while (x) {         ++reachable[x];         need_to_convert[x] += trans_op_num;         ++trans_op_num;         x >>= 1;       }     }     for (i = 1e5; i > 1 && reachable[i] != n; --i)       ;     x = need_to_convert[i];     while (true) {       int y = reachable[i + i];       if (n > y + y) break;       i = i + i;       x = x - y + n - y;     }     printf( %d n , x);     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int x = 0, y = 0, z = 0;     for (int i = 0; i < n; i++) {       int a, b, c;       cin >> a >> b >> c;       x += a;       y += b;       c += z;     }     if (!x && !y && !z)       cout <<  YES ;     else       cout <<  NO ;   }


#include <bits/stdc++.h>   using namespace std;   const long long int INF = 1e18;   const int inf = 1e9;   const int MOD = 1e9 + 7;   const int nax = 1000000 + 10;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int n, s;     cin >> n >> s;     int a, b, c, d;     cin >> a >> b;     if (a * 60 + b >= s + 1) {       cout << 0 <<     << 0;       return 0;     }     for (int i = 1; i < n; i++) {       cin >> c >> d;       if (a == c) {         int m = d - b;         if (m >= 2 * s + 2) {           int k = b + s + 1;           int j = k / 60;           int f = k % 60;           cout << a + j <<     << f;           return 0;         }       } else {         int m = c - a - 1;         m *= 60;         m += 60 - b;         m += d;         if (m >= 2 * s + 2) {           int k = b + s + 1;           int j = k / 60;           int f = k % 60;           cout << a + j <<     << f;           return 0;         }       }       a = c, b = d;     }     int k = b + s + 1;     int j = k / 60;     int f = k % 60;     cout << a + j <<     << f;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   long long int ff[15][40000][15];   int maskk[15];   bool ok[15][40000][15];   int need[15], n;   vector<int> forbit[15];   long long int f(int x, int mask, int pre) {     if (ok[x][mask][pre]++) return ff[x][mask][pre];     long long int &ans = ff[x][mask][pre];     if (mask == 0) return ans = 1;     for (int submask = mask; submask > 0; submask--) {       submask &= mask;       bool ch = false;       if (submask == 0) break;       if (__builtin_popcount(submask & maskk[x]) > 1) continue;       for (int i = 0; i < forbit[x].size(); i++) {         if ((forbit[x][i] & submask) == forbit[x][i]) {           ch = true;           break;         }       }       if (ch) continue;       for (int i = pre + 1; i < n; i++) {         if (submask & (1 << i) && ((maskk[i] & (submask | (1 << x))) == maskk[i]))           if (__builtin_popcount((submask ^ (1 << i)) & maskk[x]) == 0 &&               (need[i] & submask) == need[i]) {             ans = (ans +                    1LL * f(i, submask ^ (1 << i), 0) * f(x, mask ^ submask, i));           }       }     }     return ans;   }   void read() {     int i, q, m, x, y;     scanf( %d %d %d , &n, &m, &q);     for (i = 1; i <= m; i++) {       scanf( %d %d , &x, &y);       x--;       y--;       maskk[x] |= (1 << y);       maskk[y] |= (1 << x);     }     for (i = 1; i <= q; i++) {       scanf( %d %d %d , &x, &y, &m);       x--;       y--;       m--;       forbit[m].push_back((1 << x) | (1 << y));       need[m] |= (1 << x) | (1 << y);     }     printf( %lld n , f(0, (1 << n) - 2, 0));   }   int main() { read(); }


#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   int cnt, curk;   int pos[N], fa[N];   struct Wall {     int z, pos;     int xmin, xmax, ymin, ymax;     Wall() {}     bool operator<(const Wall &x) const { return z < x.z; }   } w[N];   struct Queries {     int x, y;     int pos;     Queries() {}     bool operator<(const Queries &xx) const { return curk ? x < xx.x : y < xx.y; }   } ask[N];   struct K_Dimensional_Tree {     struct KDT {       int id, minval, x, y, xmin, xmax, ymin, ymax;       int lson, rson;       KDT() { minval = id = xmin = xmax = ymin = ymax = lson = rson = x = y = 0; }     } t[N];     void pushup(int u) {       t[u].minval = t[u].id;       if (t[u].lson) {         t[u].minval = min(t[u].minval, t[t[u].lson].minval);         t[u].xmin = min(t[u].xmin, t[t[u].lson].xmin);         t[u].xmax = max(t[u].xmax, t[t[u].lson].xmax);         t[u].ymin = min(t[u].ymin, t[t[u].lson].ymin);         t[u].ymax = max(t[u].ymax, t[t[u].lson].ymax);       }       if (t[u].rson) {         t[u].minval = min(t[u].minval, t[t[u].rson].minval);         t[u].xmin = min(t[u].xmin, t[t[u].rson].xmin);         t[u].xmax = max(t[u].xmax, t[t[u].rson].xmax);         t[u].ymin = min(t[u].ymin, t[t[u].rson].ymin);         t[u].ymax = max(t[u].ymax, t[t[u].rson].ymax);       }     }     int BuildTree(int d, int l, int r) {       int p = ++cnt, u = (l + r) / 2;       curk = d;       nth_element(ask + l, ask + u, ask + r + 1);       t[p].minval = t[p].id = ask[u].pos;       pos[ask[u].pos] = p;       t[p].xmin = t[p].xmax = t[p].x = ask[u].x;       t[p].ymin = t[p].ymax = t[p].y = ask[u].y;       if (l < u) t[p].lson = BuildTree(d ^ 1, l, u - 1), fa[t[p].lson] = p;       if (r > u) t[p].rson = BuildTree(d ^ 1, u + 1, r), fa[t[p].rson] = p;       pushup(p);       return p;     }     int Query(int p, int xl, int xr, int yl, int yr) {       if (t[p].xmin > xr || t[p].xmax < xl || t[p].ymin > yr || t[p].ymax < yl)         return 0x3f3f3f3f;       if (xl <= t[p].xmin && t[p].xmax <= xr && yl <= t[p].ymin &&           t[p].ymax <= yr)         return t[p].minval;       int ans = 0x3f3f3f3f;       if (t[p].id != 0x3f3f3f3f && xl <= t[p].x && t[p].x <= xr && yl <= t[p].y &&           t[p].y <= yr)         ans = min(ans, t[p].id);       if (t[p].lson) ans = min(ans, Query(t[p].lson, xl, xr, yl, yr));       if (t[p].rson) ans = min(ans, Query(t[p].rson, xl, xr, yl, yr));       return ans;     }     void Del(int p) {       t[p].id = 0x3f3f3f3f;       while (p) {         pushup(p);         p = fa[p];       }     }   } KD;   int n, ANS[N], q;   int read() {     int x = 0, f = 1;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) f = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       x = (x << 1) + (x << 3) + (c ^ 48);       c = getchar();     }     return x * f;   }   int main() {     n = read();     for (int i = 1; i <= n; i++)       w[i].xmin = read(), w[i].xmax = read(), w[i].ymin = read(),       w[i].ymax = read(), w[i].z = read(), w[i].pos = i;     sort(w + 1, w + n + 1);     q = read();     for (int i = 1; i <= q; i++)       ask[i].x = read(), ask[i].y = read(), ask[i].pos = i;     KD.BuildTree(0, 1, q);     for (int i = 1; i <= n; i++) {       int ans = KD.Query(1, w[i].xmin, w[i].xmax, w[i].ymin, w[i].ymax);       if (ans == 0x3f3f3f3f) continue;       ANS[ans] = w[i].pos;       KD.Del(pos[ans]);     }     for (int i = 1; i <= q; i++) cout << ANS[i] << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   int a[2020];   void solve() {     int n, x, y;     cin >> n >> x >> y;     for (int i = 0; i < n; i++) cin >> a[i];     sort(a, a + n);     reverse(a, a + n);     int c = 0;     cout << a[x - 1] - a[x];   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int T = 1;     while (T--) solve();   }


#include <bits/stdc++.h>   const int N = 100001, M = 998244353, mod = 1000000007;   const long long MX = INT64_MAX, MN = INT64_MIN, oo = 1e18;   using namespace std;   vector<string> tokenizer(string str, char ch) {     std::istringstream var((str));     vector<string> v;     string t;     while (getline((var), t, (ch))) {       v.emplace_back(t);     }     return v;   }   template <typename T1, typename T2>   istream& operator>>(istream& in, pair<T1, T2>& a) {     in >> a.first >> a.second;     return in;   }   template <typename T1, typename T2>   ostream& operator<<(ostream& out, pair<T1, T2> a) {     out << a.first <<     << a.second;     return out;   }   void err(istream_iterator<string> it) {}   template <typename T, typename... Args>   void err(istream_iterator<string> it, T a, Args... args) {     cerr << *it <<   =   << a <<   n ;     err(++it, args...);   }   template <typename... T>   void read(T&... args) {     ((cin >> args), ...);   }   template <typename... T>   void put(T&&... args) {     ((cout << args <<    ), ...);   }   void file_i_o() {     freopen( ./tests/test01.txt ,  r , stdin);     freopen( ./tests/output01.txt ,  w , stdout);   }   void solve(int T) {     int n, m, k;     read(n, m, k);     vector<vector<int>> grid(n, vector<int>(m));     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) cin >> grid[i][j];     while (k--) {       int c;       read(c);       c--;       int r = 0;       while (r < n) {         if (grid[r][c] == 2)           r++;         else {           int nc = c;           if (grid[r][c] == 1)             nc++;           else             nc--;           grid[r][c] = 2;           c = nc;         }       }       put(c + 1);     }   }   int main(int argc, char const* argv[]) {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int t = 1;     for (int i = 1; i < t + 1; i++) {       solve(t);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   template <class T>   void cmax(T &a, T b) {     a = (a > b ? a : b);   }   template <class T>   void cmin(T &a, T b) {     a = (a > b ? b : a);   }   const long long maxn = 270000, base = 31, kcz = 1e9 + 7;   long long inv;   long long ksm(long long ds, long long zs = kcz - 2, long long mod = kcz) {     long long res = 1;     for (; zs; zs >>= 1, ds = ds * ds % mod)       if (zs & 1) res = res * ds % kcz;     return res;   }   struct node {     long long len, l, r, val;   } tr[maxn << 1];   long long p[maxn];   node merge(node a, node b) {     node res;     if (!a.len) return b;     if (!b.len) return a;     if (a.r && b.l) {       a.val = (a.val + kcz - 1 - 1) * inv % kcz;       b.val = (b.val + (kcz - p[b.len - 1]) * 2) % kcz;       --b.len;       --a.len;       if (!a.len) {         b.l = 0;         return b;       }       if (!b.len) {         a.r = 0;         return a;       }     }     res.l = a.l;     res.r = b.r;     res.len = a.len + b.len;     res.val = (a.val * p[b.len] + b.val) % kcz;     return res;   }   char s[maxn];   void build(long long l, long long r, long long now) {     if (l == r) {       tr[now].l = tr[now].r = s[l] -  0 ;       tr[now].val = (s[l] -  0  + 1) * p[0];       tr[now].len = 1;       return;     }     build(l, ((l + r) >> 1), (now << 1));     build(((l + r) >> 1) + 1, r, (now << 1 | 1));     tr[now] = merge(tr[(now << 1)], tr[(now << 1 | 1)]);   }   node get(long long l, long long r, long long now, long long x, long long y) {     if (x <= l && r <= y) return tr[now];     if (y <= ((l + r) >> 1)) return get(l, ((l + r) >> 1), (now << 1), x, y);     if (x > ((l + r) >> 1))       return get(((l + r) >> 1) + 1, r, (now << 1 | 1), x, y);     return merge(get(l, ((l + r) >> 1), (now << 1), x, y),                  get(((l + r) >> 1) + 1, r, (now << 1 | 1), x, y));   }   long long n, m;   int main() {     scanf( %lld , &n);     inv = ksm(base);     p[0] = 1;     for (long long i = (1); i <= (n); ++i) p[i] = (p[i - 1] * base) % kcz;     scanf( %s , s + 1);     build(1, n, 1);     scanf( %lld , &m);     for (long long i = (1); i <= (m); ++i) {       if (i == 28) {         ++i;         --i;       }       long long x, y, L;       scanf( %lld%lld%lld , &x, &y, &L);       node na = get(1, n, 1, x, x + L - 1), nb = get(1, n, 1, y, y + L - 1);       if (na.val == nb.val)         puts( YES );       else         puts( NO );     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const long long MAX = 1000000000;   const int N = 100005;   struct Edge {     int to, next, w, vis;   };   struct Edge e[N << 1];   int head[N], E, f[N];   struct P {     long long val;     int idx;     P(long long val, int idx) : val(val), idx(idx) {}     bool operator<(const P &h) const { return val > h.val; }   };   priority_queue<P> Q;   long long dfs(int u) {     f[u] = 1;     long long ret = 0;     for (int i = head[u]; i != -1; i = e[i].next) {       if (e[i].vis) continue;       e[i].vis = e[i ^ 1].vis = 1;       ret += e[i].w;       if (!f[e[i].to]) ret += dfs(e[i].to);     }     return ret;   }   void addedge(int u, int to, int w) {     e[E].to = to;     e[E].w = w;     e[E].vis = 0;     e[E].next = head[u];     head[u] = E++;   }   int main() {     memset(head, -1, sizeof head);     E = 0;     int n, m, p, q;     scanf( %d%d%d%d , &n, &m, &p, &q);     int uu, vv;     for (int i = 0; i < m; i++) {       int u, v, w;       scanf( %d%d%d , &u, &v, &w);       addedge(u, v, w);       addedge(v, u, w);       uu = u, vv = v;     }     int tot = 0;     for (int i = 1; i <= n; i++) {       if (!f[i]) {         long long val = dfs(i);         Q.push(P(val, i));         tot++;       }     }     if (p + q < tot || tot < q) {       puts( NO );       return 0;     }     if (m == 0) {       if (p > 0 && q == n) {         puts( NO );         return 0;       }     }     puts( YES );     tot -= q;     int sum = 0;     while (sum < tot) {       P c1 = Q.top();       Q.pop();       P c2 = Q.top();       Q.pop();       printf( %d %d n , c1.idx, c2.idx);       uu = c1.idx, vv = c2.idx;       long long add = min(MAX, c1.val + c2.val + 1);       c1.val += add + c2.val;       Q.push(c1);       sum++;     }     for (int i = 0; i < p - tot; i++) {       printf( %d %d n , uu, vv);     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const int MAXN = 2e5 + 1;   vector<long long> arr(2e5 + 2, 0);   vector<long long> dp(2e5 + 2, 0);   vector<long long> left1(2e5 + 2, 0);   void solve() {     int n, k;     string s;     cin >> n >> k >> s;     for (int i = 0; i < n; i++) {       arr[i] = (s[i] -  0 ) * k;     }     long long last = n;     for (int i = n; i >= 0; i--) {       left1[i] = last;       if (i - 1 >= 0 && arr[i - 1] != 0) last = i - 1;     }     dp[0] = 1;     for (int i = 1; i < n; i++) {       long long firstcost =           (i - 1 - arr[i] >= 0) ? (dp[i - 1 - arr[i]] + i + 1) : (i + 1);       firstcost = min(firstcost, dp[i - 1] + i + 1);       long long rr = left1[i + 1];       if (rr < n && rr - i <= k) {         firstcost = min(firstcost,                         (rr - k - 1 >= 0) ? (dp[rr - k - 1] + rr + 1) : (rr + 1));       }       long long l = max(i - k - 1, -1);       long long r = left1[l + 1];       if (r < i) {         firstcost =             min(firstcost, ((r - k - 1 >= 0) ? dp[r - k - 1] + r + 1 : (r + 1)));       }       dp[i] = firstcost;     }     cout << dp[n - 1];   }   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     solve();     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int a[105];   bool judge(int x)   {       for(int i=1;i<=100;i++)       {           if(i*i==x)               return true;       }       return false;   }   int main()   {       int t;       cin>>t;       while(t--)       {           int n;           cin>>n;           for(int i=1; i<=n; i++)           {               cin>>a[i];           }           int loop=0;           for(int i=1; i<=n; i++)           {               if(judge(a[i]))               {                   continue;               }               else               {                   cout<< YES <<endl;                   loop=1;                   break;               }           }           if(loop==0)               cout<< NO <<endl;       }   }


#include <bits/stdc++.h>   using namespace std;   int main() {     string s, provera;     int p = -1, d = -1, brojac = 0;     bool flag = false;     cin >> s >> provera;     for (int i = 0; i < provera.length(); ++i) {       if (provera[i] == s[brojac]) {         brojac++;       }       if (brojac == s.length()) {         p = i;         brojac--;         break;       }     }     for (int i = provera.length() - 1; i >= 0; --i) {       if (provera[i] == s[brojac]) brojac--;       if (brojac < 0) {         d = i;         break;       }     }     if ((d - p) > 0)       cout << d - p << endl;     else       cout << 0 << endl;     return 0;   }


#include <bits/stdc++.h>   using namespace std;   int n, m;   int lace[110][110];   int main() {     int x, y, i, j;     while (cin >> n >> m) {       memset(lace, 0, sizeof(lace));       for (i = 1; i <= m; i++) {         cin >> x >> y;         lace[x][y] = lace[y][x] = 1;       }       int xx, ans = 0;       while (1) {         int g[110], num = 0;         for (i = 1; i <= n; i++) {           xx = 0;           for (j = 1; j <= n; j++)             if (lace[i][j]) xx++;           if (xx == 1) g[++num] = i;         }         for (j = 1; j <= num; j++) {           for (i = 1; i <= n; i++) lace[g[j]][i] = lace[i][g[j]] = 0;         }         if (!num) break;         ans++;       }       cout << ans << endl;     }   }


#include <bits/stdc++.h>   using namespace std;   long long power(long long x, long long y) {     long long res = 1;     x = x % 1000000007;     while (y > 0) {       if (y & 1) res = (res * x) % 1000000007;       y = y >> 1;       x = (x * x) % 1000000007;     }     return res % 1000000007;   }   long long inv(long long n) { return power(n, 1000000007 - 2) % 1000000007; }   long long isprime(long long n) {     if (n < 2) return 0;     long long i;     for (i = 2; i * i <= n; i++)       if (n % i == 0) return 0;     return 1;   }   void solve() {     long long ans = 1e18;     string s;     long long n;     cin >> n >> s;     for (char ch =  a ; ch <=  z ; ch++) {       long long i = 0, j = n - 1;       long long moves = 0;       long long ok = 1;       while (i < j) {         if (s[i] == s[j]) {           i++, j--;         } else if (s[i] == ch) {           i++;           moves++;         } else if (s[j] == ch) {           j--;           moves++;         } else {           ok = 0;           break;         }       }       if (ok) {         ans = min(ans, moves);       }     }     if (ans > n) ans = -1;     cout << ans <<   n ;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long t = 1;     long long tc = 0;     cin >> t;     while (t--) {       tc++;       solve();     }   }


#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const int N = 3e6 + 44;   const int X[] = {1, 0, -1, 0, 1, -1, 1, -1};   const int Y[] = {0, 1, 0, -1, 1, 1, -1, -1};   const int mod = 998244353;   const int INF = 1e9;   ll ans[N], add[N];   vector<int> g[N];   vector<pair<int, int> > query[N];   void dfs(int v = 0, int p = -1, int h = 0, ll sum = 0) {     for (auto pairr : query[v]) {       int d = pairr.first, x = pairr.second;       add[h] += x;       if (h + d + 1 < N) add[h + d + 1] -= x;     }     sum += add[h];     ans[v] = sum;     for (int to : g[v])       if (to != p) {         dfs(to, v, h + 1, sum);       }     for (auto pairr : query[v]) {       int d = pairr.first, x = pairr.second;       add[h] -= x;       if (h + d + 1 < N) add[h + d + 1] += x;     }   }   int main() {     ios_base::sync_with_stdio(false), cin.tie(NULL);     ;     int n;     cin >> n;     for (int i = 1; i < n; ++i) {       int u, v;       cin >> u >> v;       u--, v--;       g[u].push_back(v);       g[v].push_back(u);     }     int m;     cin >> m;     for (int i = 0; i < m; ++i) {       int v, d, x;       cin >> v >> d >> x;       v--;       query[v].push_back({d, x});     }     dfs();     for (int i = 0; i < n; ++i) cout << ans[i] <<    ;   }


#include <bits/stdc++.h>   using namespace std;   using LL = long long;   int a[25];   LL dp[25][5], l, r;   LL dfs(int pos, int cnt, bool zero, bool limit) {     if (pos == -1) return 1;     if (!limit && !zero && dp[pos][cnt] != -1) return dp[pos][cnt];     int up = limit ? a[pos] : 9;     if (cnt == 3) up = 0;     LL ans = 0;     for (int i = 0; i <= up; ++i)       ans += dfs(pos - 1, cnt + (i == 0 ? 0 : 1), zero && i == 0,                  limit && i == a[pos]);     if (!limit && !zero) dp[pos][cnt] = ans;     return ans;   }   LL solve(LL x) {     int pos = 0;     while (x) {       a[pos++] = x % 10;       x /= 10;     }     return dfs(pos - 1, 0, true, true);   }   int main() {     int T;     LL l, r;     scanf( %d , &T);     while (T--) {       memset(dp, -1, sizeof dp);       scanf( %I64d%I64d , &l, &r);       printf( %I64d n , solve(r) - solve(l - 1));     }     return 0;   }


#include <bits/stdc++.h>   using namespace std;   const double pi = acos(0.0) * 2.0;   const long double eps = 1e-10;   const int step[8][2] = {{-1, 0}, {0, 1}, {1, 0},  {0, -1},                           {-1, 1}, {1, 1}, {1, -1}, {-1, -1}};   template <class T>   inline T abs1(T a) {     return a < 0 ? -a : a;   }   template <typename t, typename t1>   t min1(t a, t1 b) {     return a < b ? a : b;   }   template <typename t, typename... arg>   t min1(t a, arg... arr) {     return min1(a, min1(arr...));   }   template <typename t, typename t1>   t max1(t a, t1 b) {     return a > b ? a : b;   }   template <typename t, typename... arg>   t max1(t a, arg... arr) {     return max1(a, max1(arr...));   }   inline int jud(double a, double b) {     if (abs(a) < eps && abs(b) < eps)       return 0;     else if (abs1(a - b) / abs1(a) < eps)       return 0;     if (a < b) return -1;     return 1;   }   template <typename t>   inline int jud(t a, t b) {     if (a < b) return -1;     if (a == b) return 0;     return 1;   }   template <typename it, typename t1>   inline int find(t1 val, it a, int na, bool f_small = 1, bool f_lb = 1) {     int be = 0, en = na - 1;     if (*a <= *(a + na - 1)) {       if (f_lb == 0)         while (be < en) {           int mid = (be + en + 1) / 2;           if (jud(*(a + mid), val) != 1)             be = mid;           else             en = mid - 1;         }       else         while (be < en) {           int mid = (be + en) / 2;           if (jud(*(a + mid), val) != -1)             en = mid;           else             be = mid + 1;         }       if (f_small && jud(*(a + be), val) == 1) be--;       if (!f_small && jud(*(a + be), val) == -1) be++;     } else {       if (f_lb)         while (be < en) {           int mid = (be + en + 1) / 2;           if (jud(*(a + mid), val) != -1)             be = mid;           else             en = mid - 1;         }       else         while (be < en) {           int mid = (be + en) / 2;           if (jud(*(a + mid), val) != 1)             en = mid;           else             be = mid + 1;         }       if (!f_small && jud(*(a + be), val) == -1) be--;       if (f_small && jud(*(a + be), val) == 1) be++;     }     return be;   }   template <class T>   inline T lowb(T num) {     return num & (-num);   }   inline int bitnum(unsigned int nValue) { return __builtin_popcount(nValue); }   inline int bitnum(int nValue) { return __builtin_popcount(nValue); }   inline int bitnum(unsigned long long nValue) {     return __builtin_popcount(nValue) + __builtin_popcount(nValue >> 32);   }   inline int bitnum(long long nValue) {     return __builtin_popcount(nValue) + __builtin_popcount(nValue >> 32);   }   inline int bitmaxl(unsigned int a) {     if (a == 0) return 0;     return 32 - __builtin_clz(a);   }   inline int bitmaxl(int a) {     if (a == 0) return 0;     return 32 - __builtin_clz(a);   }   inline int bitmaxl(unsigned long long a) {     int temp = a >> 32;     if (temp) return 32 - __builtin_clz(temp) + 32;     return bitmaxl(int(a));   }   inline int bitmaxl(long long a) {     int temp = a >> 32;     if (temp) return 32 - __builtin_clz(temp) + 32;     return bitmaxl(int(a));   }   long long pow(long long n, long long m, long long mod = 0) {     if (m < 0) return 0;     long long ans = 1;     long long k = n;     while (m) {       if (m & 1) {         ans *= k;         if (mod) ans %= mod;       }       k *= k;       if (mod) k %= mod;       m >>= 1;     }     return ans;   }   template <class t1, class t2>   inline void add(t1 &a, t2 b, int mod = -1) {     if (mod == -1) mod = 1000000007;     a += b;     while (a >= mod) a -= mod;     while (a < 0) a += mod;   }   template <class t>   void output1(t arr) {     for (int i = 0; i < (int)arr.size(); i++) cerr << arr[i] <<    ;     cerr << endl;   }   template <class t>   void output2(t arr) {     for (int i = 0; i < (int)arr.size(); i++) output1(arr[i]);   }   const int maxn = 100100;   struct edge {     int to, nxt, val;   } e[maxn * 2];   int head[maxn], le;   int fa[maxn], anc[maxn], sz[maxn], hv[maxn], deep[maxn], loc[maxn];   int orig[maxn], lorig;   int n, nq;   int f[maxn];   pair<int, int> st[2][maxn];   int lst[2];   int ans[maxn];   struct node {     int a, b, cate;     int yul;     bool operator<(const node &a) const {       if (yul == a.yul) return cate < a.cate;       return yul < a.yul;     }   } arr[maxn * 2];   int larr;   struct segment_node {     int be, en;     int sumv, lef, rig;     bool flag;   };   struct segment_tree {     int l;     segment_node tree[maxn * 4];     inline int gleft(int no) { return no << 1; }     inline int gright(int no) { return (no << 1) + 1; }     inline int gfa(int no) { return no >> 1; }     inline segment_tree() { l = 0; }     void build(int no, int l, int r, int orig = 0, int *a = NULL) {       if (l > r) r = l;       if (l == r) {         tree[no].be = tree[no].en = l;         tree[no].sumv = 0;         tree[no].lef = tree[no].rig = 0;         tree[no].flag = 0;         return;       }       tree[no].be = l;       tree[no].en = r;       int mid = (l + r) / 2;       build(gleft(no), l, mid, orig, a);       build(gright(no), mid + 1, r, orig, a);       tree[no].sumv = 0;       tree[no].lef = tree[no].rig = 0;     }     inline void pushup(segment_node *no, segment_node *nl, segment_node *nr) {       if (nl->flag && nr->flag) {         no->lef = no->rig = nr->lef + nl->rig;         no->sumv = 0;         no->flag = 1;         return;       }       if (nl->flag && nl->lef == 0) {         memcpy(no, nr, sizeof(segment_node));         return;       }       if (nr->flag && nr->lef == 0) {         memcpy(no, nl, sizeof(segment_node));         return;       }       no->flag = 0;       if (nl->flag) {         no->lef = nr->lef + nl->rig;         no->rig = nr->rig;         no->sumv = nr->sumv;         return;       }       if (nr->flag) {         no->lef = nl->lef;         no->rig = nl->rig + nr->lef;         no->sumv = nl->sumv;         return;       }       no->lef = nl->lef;       no->rig = nr->rig;       no->sumv = nl->sumv + nr->sumv + f[nl->rig + nr->lef];     }     void down(int loc, int no) {       if (loc <= tree[no].be && loc >= tree[no].en) {         tree[no].rig = tree[no].lef = 1;         tree[no].flag = 1;         tree[no].sumv = 0;         return;       }       int mid = (tree[no].be + tree[no].en) >> 1;       if (loc <= mid)         down(loc, gleft(no));       else         down(loc, gright(no));       pushup(tree + no, tree + gleft(no), tree + gright(no));     }     void getsum(int l, int r, int no, int pp1) {       if (l > r) return;       int pp2 = pp1 + 100;       if (l <= tree[no].be && r >= tree[no].en) {         pushup(tree + pp2, tree + pp1, tree + no);         tree[pp1] = tree[pp2];         return;       }       int mid = (tree[no].be + tree[no].en) >> 1;       if (r >= tree[no].be && l <= mid) getsum(l, r, gleft(no), pp1);       if (r >= mid + 1 && l <= tree[no].en) getsum(l, r, gright(no), pp1);     }   } sgt;   void dfs(int no) {     sz[no] = 1;     hv[no] = -1;     for (int i = head[no]; i != -1; i = e[i].nxt)       if (e[i].to != fa[no]) {         fa[e[i].to] = no;         deep[e[i].to] = deep[no] + 1;         dfs(e[i].to);         sz[no] += sz[e[i].to];         if (hv[no] == -1 || sz[hv[no]] < sz[e[i].to]) hv[no] = e[i].to;       }   }   void dfs1(int no) {     orig[lorig] = no;     loc[no] = lorig++;     if (hv[no] != -1) {       anc[hv[no]] = anc[no];       dfs1(hv[no]);     }     for (int i = head[no]; i != -1; i = e[i].nxt)       if (e[i].to != fa[no] && e[i].to != hv[no]) {         anc[e[i].to] = e[i].to;         dfs1(e[i].to);       }   }   void addedge(int a, int b, int c) {     e[le].to = b;     e[le].nxt = head[a];     e[le].val = c;     head[a] = le++;   }   int main() {     ios_base::sync_with_stdio(0);     memset(head, -1, sizeof(head));     scanf( %d%d , &n, &nq);     for (int i = 1; i < n; i++) scanf( %d , f + i);     for (int i = 0; i < n - 1; i++) {       int a, b, c;       scanf( %d%d%d , &a, &b, &c);       a--;       b--;       addedge(a, b, c);       addedge(b, a, c);       arr[i].a = a;       arr[i].b = b;       arr[i].yul = -c;       arr[i].cate = -(i + 1);     }     sgt.build(1, 0, n);     dfs(0);     dfs1(0);     for (int i = 0; i < nq; i++) {       scanf( %d%d%d , &arr[i + n - 1].a, &arr[i + n - 1].b, &arr[i + n - 1].yul);       arr[i + n - 1].cate = i;       arr[i + n - 1].a--;       arr[i + n - 1].b--;       arr[i + n - 1].yul = -arr[i + n - 1].yul;     }     sort(arr, arr + nq + n - 1);     for (int i = 0; i < nq + n - 1; i++) {       if (arr[i].cate < 0) {         int no = arr[i].a;         if (deep[arr[i].b] > deep[no]) no = arr[i].b;         sgt.down(loc[no], 1);       } else {         int a = arr[i].a, b = arr[i].b;         int l = 0;         lst[0] = lst[1] = 0;         while (anc[a] != anc[b]) {           int no = a, cate = 0;           if (deep[anc[a]] < deep[anc[b]]) {             no = b;             cate = 1;           }           st[cate][lst[cate]++] = make_pair(loc[anc[no]], loc[no]);           l += abs(loc[anc[no]] - loc[no]) + 1;           if (deep[anc[a]] < deep[anc[b]])             b = fa[anc[no]];           else             a = fa[anc[no]];         }         if (a != b) {           if (deep[a] > deep[b])             st[0][lst[0]++] = make_pair(loc[b] + 1, loc[a]);           else             st[1][lst[1]++] = make_pair(loc[a] + 1, loc[b]);           l += abs(deep[a] - deep[b]);         }         int ff1 = 400000, ff2 = ff1 + 1, ff3 = ff1 + 2;         sgt.tree[ff1].rig = sgt.tree[ff1].lef = sgt.tree[ff1].sumv = 0;         sgt.tree[ff1].flag = 1;         sgt.tree[ff2].rig = sgt.tree[ff2].lef = sgt.tree[ff2].sumv = 0;         sgt.tree[ff2].flag = 1;         for (int i = lst[0] - 1; i >= 0; i--)           sgt.getsum(st[0][i].first, st[0][i].second, 1, ff1);         for (int i = lst[1] - 1; i >= 0; i--)           sgt.getsum(st[1][i].first, st[1][i].second, 1, ff2);         swap(sgt.tree[ff1].lef, sgt.tree[ff1].rig);         sgt.pushup(sgt.tree + ff3, sgt.tree + ff1, sgt.tree + ff2);         int rans = sgt.tree[ff3].sumv + f[sgt.tree[ff3].lef];         if (!sgt.tree[ff3].flag) rans += f[sgt.tree[ff3].rig];         ans[arr[i].cate] = rans;       }     }     for (int i = 0; i < nq; i++) printf( %d n , ans[i]);     return 0;   }


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