#include <bits/stdc++.h> n #pragma GCC optimize( O3 ) n using namespace std; n template <class c> n struct rge { n   c b, e; n }; n template <class c> n rge<c> range(c h, c n) { n   return {h, n}; n } n template <class c> n auto dud(c* r) -> decltype(cerr << *r); n template <class c> n char dud(...); n struct muu { n   template <class c> n   muu& operator<<(const c&) { n     return *this; n   } n   muu& operator()() { return *this; } n }; n const int N = 1e5 + 7; n long long tab[N]; n int n; n long long inf = 1e18; n void fail() { n   printf( No n ); n   exit(0); n } n int main() { n   scanf( %d , &n); n   for (int i = 2; i <= n; i += 2) scanf( %lld , tab + i); n   long long sum = 0; n   for (int i = 2; i <= n; i += 2) { n     long long nsum = inf; n     for (int d = 1; d * d <= tab[i]; ++d) { n       if (tab[i] % d == 0) { n         long long a = (tab[i] / d) - d; n         long long b = (tab[i] / d) + d; n         if (a % 2 == 0 && b % 2 == 0) { n           if (a * a > 4 * sum) { n             nsum = min(nsum, (b * b) / 4); n           } n         } n       } n     } n     (muu() << __FUNCTION__ <<  #  << 67 <<  :  ) << i <<     << nsum; n     if (nsum == inf) fail(); n     tab[i - 1] = nsum - sum - tab[i]; n     sum = nsum; n   } n   printf( Yes n ); n   for (int i = 1; i <= n; ++i) printf( %lld  , tab[i]); n   printf(  n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 3e5 + 50; n vector<int> e[N]; n int dp[N], res, deg[N]; n void dfs(int u, int pre) { n   dp[u] = deg[u]; n   for (int v : e[u]) { n     if (v == pre) continue; n     dfs(v, u); n     res = max(res, dp[u] + dp[v]); n     dp[u] = max(dp[u], dp[v] + deg[u] - 2 + 1); n   } n } n int main() { n   int t; n   scanf( %d , &t); n   while (t--) { n     int n; n     scanf( %d , &n); n     for (int i = 1; i <= n; i++) e[i].clear(), deg[i] = 0; n     for (int i = 0; i < n - 1; i++) { n       int u, v; n       scanf( %d%d , &u, &v); n       e[u].push_back(v); n       e[v].push_back(u); n       deg[u]++; n       deg[v]++; n     } n     res = 0; n     dfs(1, 0); n     printf( %d n , res); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int n, m; n const int maxN = (int)1e6 + 10; n vector<int> g[maxN]; n int p[maxN]; n int a[maxN]; n long long s = 0; n long long tr[maxN]; n set<long long> all; n void dfs(int v) { n   tr[v] = a[v]; n   for (int to : g[v]) { n     dfs(to); n     tr[v] += tr[to]; n   } n   if (s % tr[v] == 0) { n     all.insert(tr[v]); n   } n } n int val[maxN]; n const int mod = (int)1e9 + 7; n int sum(int a, int b) { n   int s = a + b; n   if (s >= mod) s -= mod; n   return s; n } n set<long long> ok; n long long id[maxN]; n long long sm[maxN]; n map<long long, int> f; n int dp[maxN]; n int main() { n   ios_base::sync_with_stdio(false); n   cin >> n; n   for (int i = 1; i <= n; i++) { n     cin >> a[i]; n     s += a[i]; n   } n   for (int i = 1; i < n; i++) { n     cin >> p[i]; n     g[p[i]].push_back(i + 1); n   } n   dfs(1); n   int sz = 1; n   int oth = 1; n   for (long long t : all) { n     memset(sm, 0, sizeof sm); n     bool can = true; n     for (int i = n; i >= 1; i--) { n       if (sm[i] + a[i] > t) { n         can = false; n         break; n       } n       if (sm[i] + a[i] == t) { n         continue; n       } n       if (i == 1) { n         can = false; n         break; n       } n       sm[p[i - 1]] += (sm[i] + a[i]); n     } n     if (can) { n       f[t] = oth; n       oth++; n       ok.insert(t); n     } n   } n   for (long long x : ok) { n     int id = f[x]; n     dp[id] = 1; n     for (long long y : ok) { n       if (y >= x) continue; n       if (x % y == 0) dp[id] = sum(dp[id], dp[f[y]]); n     } n   } n   cout << dp[f[s]]; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 0x3f3f3f3f; n const long long LINF = 0x3f3f3f3f3f3f3f3f; n const int MOD = (int)1e9 + 7; n const int N = (int)2e5 + 7; n int tree[N << 1]; n void update(int x, int n) { n   x += n; n   if (tree[x]) return; n   while (x) { n     tree[x]++; n     x >>= 1; n   } n } n int query(int l, int r, int n) { n   int re = 0; n   l += n, r += n; n   while (l <= r) { n     if (l & 1) re += tree[l++]; n     if (~r & 1) re += tree[r--]; n     l >>= 1, r >>= 1; n   } n   return re; n } n pair<int, int> p[N]; n vector<int> x; n int l[N]; n int main() { n   int n; n   scanf( %d , &n); n   for (int i = (0); i < (n); ++i) { n     scanf( %d%d , &p[i].first, &p[i].second); n     x.push_back(p[i].first); n   } n   sort((x).begin(), (x).end()); n   sort(p, p + n); n   for (int i = (0); i < (n); ++i) { n     p[i].first = lower_bound((x).begin(), (x).end(), p[i].first) - x.begin(); n     swap(p[i].first, p[i].second); n   } n   sort(p, p + n); n   long long ans = 0; n   for (int i = n - 1, j; i >= 0; i = j) { n     for (j = i; j >= 0 && p[i].first == p[j].first; j--) n       ; n     int z = 0; n     for (int k = (j + 1); k < (i + 1); ++k) { n       l[k] = query(z, p[k].second - 1, n); n       update(p[k].second, n); n       z = p[k].second + 1; n     } n     for (int k = (j + 1); k < (i + 1); ++k) { n       ans += (long long)(l[k] + 1) * (query(p[k].second + 1, n, n) + 1); n     } n   } n   printf( %lld n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   double l, p, q; n   cin >> l >> p >> q; n   double qq = l / (p + q) * p; n   cout << setiosflags(ios::fixed); n   cout << setprecision(4) << qq; n } n


#include <bits/stdc++.h> n using namespace std; n long long exp(long long x, long long y) { n   x %= 1000000007; n   long long res = 1; n   while (y) { n     if (y & 1) res = res * x % 1000000007; n     x = x * x % 1000000007; n     y >>= 1; n   } n   return res; n } n long long fact(long long n) { n   long long res = 1; n   for (long long i = 2; i <= n; ++i) (res *= i) %= 1000000007; n   return res; n } n bool isprime(long long n) { n   for (long long i = 2; i * i <= n; ++i) n     if (n % i == 0) return 0; n   return 1; n } n int main() { n   int n, m; n   cin >> n >> m; n   const long long inf = 1e17; n   vector<long long> sum(n), pre(n), s(n); n   vector<long long> t(n); n   for (int i = 0; i < n; ++i) { n     int x; n     cin >> x; n     long long val = -inf; n     long long mx = -inf; n     vector<long long> v1, v2; n     for (int j = 0; j < x; ++j) { n       long long k; n       cin >> k; n       val = max(k, val + k); n       mx = max(mx, val); n       v1.push_back(k); n       v2.push_back(k); n     } n     t[i] = mx; n     for (int j = 1; j < x; ++j) v1[j] += v1[j - 1]; n     for (int j = x - 2; j >= 0; --j) v2[j] += v2[j + 1]; n     sum[i] = v1[x - 1]; n     pre[i] = *max_element(v1.begin(), v1.end()); n     s[i] = *max_element(v2.begin(), v2.end()); n   } n   long long to = -inf; n   vector<int> v(m + 1); n   for (int i = 1; i <= m; ++i) { n     cin >> v[i]; n     to = max(to, t[v[i] - 1]); n   } n   long long dp[m + 1][3]; n   memset(dp, 0, sizeof(dp)); n   for (int i = 1; i <= m; ++i) { n     dp[i][0] = s[v[i] - 1]; n     dp[i][1] = max(dp[i - 1][0] + sum[v[i] - 1], dp[i - 1][1] + sum[v[i] - 1]); n     dp[i][2] = max(dp[i - 1][0] + pre[v[i] - 1], dp[i - 1][1] + pre[v[i] - 1]); n   } n   long long ans = -inf; n   for (int i = 1; i <= m; ++i) ans = max(ans, dp[i][2]); n   cout << max(ans, to); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = -1; n struct disk { n   long long L; n   double p; n   disk(long long L = 0, double p = 0.) : L(L), p(p) {} n }; n bool operator<(disk a, disk b) { n   return (a.L * a.p * (1 - b.p)) > (b.L * b.p * (1 - a.p)); n } n int n; n vector<disk> P; n int main() { n   while (cin >> n) { n     P.resize(n); n     for (int i = (0); i < (int)(n); i++) n       scanf( %lld %lf , &P[i].L, &P[i].p), P[i].p /= 100; n     sort(P.begin(), P.end()); n     double ans = 0., E = 0.; n     for (int i = ((int)n) - 1; i >= 0; i--) { n       disk D = P[i]; n       ans += D.L * (1 + E * D.p); n       E = D.p * E + (1 - D.p) * (E + 1); n     } n     printf( %.6f n , ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long i, n, now, ans, hh, m, p = 1000000009; n int main() { n   scanf( %lld , &n); n   if (n == 2) { n     puts( 10 ); n     return 0; n   } n   m = n / 2; n   now = 4; n   hh = 1; n   for (i = 3; i <= m; i++) { n     now = now * 2 % p; n     hh = hh * (now - 3) % p; n     ans = (ans + hh) % p; n   } n   ans = ans * 4 + 6; n   ans %= p; n   ans = ans * ans % p; n   ans++; n   ans = ans * 2 % p; n   printf( %lld , ans); n } n


#include <bits/stdc++.h> n using namespace std; n int m(int x, int md) { return (((x) % md) + md) % md; } n void solve() { n   int n; n   cin >> n; n   vector<int> a(n); n   for (int i = 0; i < n; i++) cin >> a[i]; n   set<int> st; n   for (int r = 0; r < n; r++) { n     st.insert(m(r + a[r], n)); n   } n   if (st.size() == n) n     cout <<  YES n ; n   else n     cout <<  NO n ; n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   int T; n   cin >> T; n   for (int testcase = 1; testcase <= T; testcase++) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct event { n   int pos, type, p; n   event(int pos = 0, int type = -1, int p = 0) : pos(pos), type(type), p(p) {} n   bool operator<(const event &e) const { n     if (pos == e.pos) return type < e.type; n     return pos < e.pos; n   } n }; n const int maxE = 5e5 + 10; n event E[maxE]; n int cnt[111]; n double fpow(double a, int n) { n   double r = 1; n   for (; n; n = n >> 1) { n     if (n & 1) r *= a; n     a = a * a; n   } n   return r; n } n int main() { n   memset((cnt), (0), sizeof(cnt)); n   int n, m, x, h, l, r, sz = 0, b, z; n   scanf( %d%d , &n, &m); n   for (int _n(n), i(0); i < _n; i++) { n     scanf( %d%d%d%d , &x, &h, &l, &r); n     l = 100 - l; n     r = 100 - r; n     E[sz++] = event(x - h, 0, l); n     E[sz++] = event(x, 0, -1 - l); n     E[sz++] = event(x + 1, 0, r); n     E[sz++] = event(x + h + 1, 0, -1 - r); n   } n   for (int _n(m), i(0); i < _n; i++) { n     scanf( %d%d , &b, &z); n     E[sz++] = event(b, z); n   } n   sort(E, E + sz); n   double expectation = 0, pro = 0; n   for (int _n(sz), i(0); i < _n; i++) { n     if (E[i].type == 0) { n       if (E[i].p >= 0) { n         cnt[E[i].p]++; n       } else n         cnt[-E[i].p - 1]--; n     } else { n       pro = 1; n       for (int _n(101), i(0); i < _n; i++) pro *= fpow(0.01 * i, cnt[i]); n       expectation += pro * E[i].type; n     } n   } n   printf( %.7f n , expectation); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX_N = 100011; n const long long INF = (1 << 29) + 123; n const long long MOD = 1000000007; n const long double PI = 4 * atan((long double)1); n int fenw[2 * MAX_N]; n int n; n void mod(int i, int v) { n   while (i <= n) { n     fenw[i] += v; n     i += i & -i; n   } n } n int query(int i) { n   int sum = 0; n   while (i > 0) { n     sum += fenw[i]; n     i -= i & -i; n   } n   return sum; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   cin >> n; n   vector<pair<int, int> > p; n   int x[n], v[n]; n   for (int i = 0; i < n; i++) cin >> x[i]; n   for (int i = 0; i < n; i++) { n     cin >> v[i]; n     p.push_back(make_pair(v[i], x[i])); n   } n   unordered_map<int, int> m; n   int rev_map[n]; n   sort(x, x + n); n   for (int i = 0; i < n; i++) { n     m[x[i]] = i + 1; n     rev_map[i] = x[i]; n   } n   for (int i = 0; i < n; i++) { n     p[i].second = m[p[i].second]; n   } n   sort(p.begin(), p.end()); n   long long ans = 0; n   for (int i = 0; i < n; i++) { n     int q = query(p[i].second); n     ans += 1LL * q * rev_map[p[i].second - 1]; n     ans -= n         1LL * ((n - i - 1) - (p[i].second - 1 - q)) * rev_map[p[i].second - 1]; n     mod(p[i].second, 1); n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long V[10005], O[10005], F[1005][10005]; n int c[1005], cost[1005]; n int n, W, B, X; n struct Queue { n   int p[1005], q[1005]; n   long long maxp[1005], maxq[1005]; n   void clear() { n     *p = 0; n     *q = 0; n     maxp[0] = maxq[0] = -1; n   } n   void add(int x) { n     q[++*q] = x; n     maxq[*q] = max(maxq[(*q) - 1], V[x]); n   } n   void del() { n     if (*p) n       --*p; n     else { n       for (; *q; --*q) ++*p, maxp[*p] = max(maxp[(*p) - 1], V[p[*p] = q[*q]]); n       --*p; n     } n   } n   long long ask() { return max(maxp[*p], maxq[*q]); } n } G; n int main() { n   scanf( %d%d%d%d , &n, &W, &B, &X); n   for (int i = 1; i <= n; i++) scanf( %d , &c[i]); n   for (int i = 1; i <= n; i++) scanf( %d , &cost[i]); n   memset(F, -1, sizeof(F)); n   F[0][0] = W; n   int sum = 0; n   for (int i = 1; i <= n; i++) { n     sum += c[i]; n     for (int j = 0; j <= sum; j++) { n       for (int k = max(j - c[i], 0); k <= j; k++) n         if (F[i - 1][k] >= 1ll * cost[i] * (j - k)) n           F[i][j] = max(F[i][j], F[i - 1][k] - 1ll * cost[i] * (j - k)); n       if (F[i][j] != -1) { n         F[i][j] += X; n         F[i][j] = min(F[i][j], W + 1ll * j * B); n       } n     } n   } n   for (int k = sum; k >= 0; k--) n     if (F[n][k] >= 0) { n       printf( %d n , k); n       return 0; n     } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, p1 = 0, p2 = 0; n   cin >> n; n   int mid[1000], index = 0; n   for (int i = 0; i < n; i++) { n     int a; n     cin >> a; n     if (a % 2 == 0) { n       for (int j = 1; j <= (a / 2); j++) { n         int t; n         cin >> t; n         p1 += t; n       } n       for (int j = 1; j <= (a / 2); j++) { n         int t; n         cin >> t; n         p2 += t; n       } n     } else { n       for (int j = 1; j <= (a / 2); j++) { n         int t; n         cin >> t; n         p1 += t; n       } n       cin >> mid[index++]; n       for (int j = 1; j <= (a / 2); j++) { n         int t; n         cin >> t; n         p2 += t; n       } n     } n   } n   sort(mid, mid + index); n   for (int i = index - 1; i >= 0; i--) { n     if (((index - 1) % 2 == 0 && i % 2 == 0) || n         ((index - 1) % 2 == 1 && i % 2 == 1)) n       p1 += mid[i]; n     else n       p2 += mid[i]; n   } n   cout << p1 <<     << p2 << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 6010; n vector<int> a[N]; n int L[N], cnt, r[N], n, res = 0; n void Refresh() { n   L[0] = cnt = 0; n   for (int i = 1; i <= n + 1; i++) L[i] = 10000000; n } n void DFS(int u, int p) { n   int Oldval, Oldid, Oldcnt = cnt; n   if (cnt == 0 || r[u] > L[cnt]) n     L[++cnt] = r[u]; n   else { n     Oldid = lower_bound(L, L + n + 1, r[u]) - L; n     Oldval = L[Oldid]; n     L[Oldid] = r[u]; n   } n   res = max(res, cnt); n   for (int i = 0; i < a[u].size(); i++) { n     int v = a[u][i]; n     if (v != p) DFS(v, u); n   } n   if (Oldcnt != cnt) n     L[cnt--] = 10000000; n   else n     L[Oldid] = Oldval; n } n int main() { n   ios_base::sync_with_stdio(0); n   int u, v; n   cin >> n; n   for (int i = 1; i <= n; i++) cin >> r[i]; n   for (int i = 1; i < n; i++) { n     cin >> u >> v; n     a[u].push_back(v); n     a[v].push_back(u); n   } n   for (int i = 1; i <= n; i++) { n     Refresh(); n     DFS(i, 0); n   } n   cout << res; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long pow1(int a, int b) { n   long long res = 1; n   for (int i = 1; i <= b; i++) res *= a; n   return res; n } n int main() { n   int n; n   cin >> n; n   long long sum = 2 * (pow1(2, n) - 1); n   cout << sum <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long int gcd(long long int a, long long int b) { n   if (b == 0) n     return a; n   else n     return gcd(b, a % b); n } n bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) { n   return (a.second < b.second); n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   std::cout.precision(12); n   int t; n   cin >> t; n   while (t--) { n     bool f = 0; n     int n, m; n     cin >> n >> m; n     char a[n][m]; n     char ans[n][m]; n     vector<pair<int, int>> v[26]; n     int ma = -1; n     int r, c; n     for (long long int i = 0; i < n; i++) { n       for (long long int j = 0; j < m; j++) { n         cin >> a[i][j]; n         ans[i][j] =  . ; n         if (a[i][j] >= 97 && a[i][j] <=  z ) { n           v[a[i][j] -  a ].push_back({i + 1, j + 1}); n           if (a[i][j] -  a  > ma) { n             ma = a[i][j] -  a ; n             r = i + 1; n             c = j + 1; n           } n         } n       } n     } n     vector<pair<int, int>> start[ma + 1], end[ma + 1]; n     for (long long int i = 0; i < ma + 1; i++) { n       if (v[i].size() == 0) { n         start[i].push_back({r, c}); n         end[i].push_back({r, c}); n       } else if (v[i].size() == 1) { n         ans[v[i][0].first - 1][v[i][0].second - 1] =  a  + i; n         start[i].push_back({v[i][0].first, v[i][0].second}); n         end[i].push_back({v[i][0].first, v[i][0].second}); n       } else { n         if (v[i][1].first == v[i][0].first) { n           int mi = m + 6, m = 0; n           for (int j = 0; j < v[i].size(); j++) { n             if (v[i][j].first != v[i][0].first) { n               f = 1; n               break; n             } n             mi = min(mi, v[i][j].second); n             m = max(m, v[i][j].second); n           } n           if (f == 1) break; n           for (int j = mi - 1; j < m; j++) { n             ans[v[i][0].first - 1][j] =  a  + i; n           } n           start[i].push_back({v[i][0].first, mi}); n           end[i].push_back({v[i][0].first, m}); n         } else if (v[i][1].second == v[i][0].second) { n           int mi = n + 6, m = 0; n           for (int j = 0; j < v[i].size(); j++) { n             if (v[i][j].second != v[i][0].second) { n               f = 1; n               break; n             } n             mi = min(mi, v[i][j].first); n             m = max(m, v[i][j].first); n           } n           if (f == 1) break; n           for (int j = mi - 1; j < m; j++) { n             ans[j][v[i][0].second - 1] =  a  + i; n           } n           start[i].push_back({mi, v[i][0].second}); n           end[i].push_back({m, v[i][0].second}); n         } else { n           f = 1; n           break; n         } n       } n     } n     for (long long int i = 0; i < n; i++) { n       for (long long int j = 0; j < m; j++) { n         if (a[i][j] != ans[i][j]) { n           f = 1; n           break; n         } n       } n       if (f == 1) break; n     } n     if (f == 0) { n       cout <<  YES n ; n       cout << ma + 1 << endl; n       for (long long int i = 0; i < ma + 1; i++) n         cout << start[i][0].first <<     << start[i][0].second <<     n              << end[i][0].first <<     << end[i][0].second << endl; n     } else { n       cout <<  NO n ; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}; n const long long linf = 4000000000000000000LL; n const long long inf = 998244353; n const long double pi = 3.1415926535; n void pv(vector<int> a) { n   for (auto& x : a) cout << x <<    ; n   cout <<   n ; n } n void pv(vector<long long> a) { n   for (auto& x : a) cout << x <<    ; n   cout <<   n ; n } n void pv(vector<vector<int>> a) { n   for (int i = (0); i < (int(a.size())); ++i) { n     cout << i <<   n ; n     pv(a[i]); n     cout <<   n ; n   } n } n void pv(vector<vector<long long>> a) { n   for (int i = (0); i < (int(a.size())); ++i) { n     cout << i <<   n ; n     pv(a[i]); n   } n   cout <<   n ; n } n void pv(vector<string> a) { n   for (auto& x : a) cout << x <<   n ; n   cout <<   n ; n } n void build_primes(vector<int>& primes, int size) { n   vector<int> visited; n   visited.resize(size, 0); n   for (int i = (2); i < (size); ++i) { n     if (visited[i] == 0) { n       primes.push_back(i); n       int a = i; n       while (a < size) { n         visited[a] = 1; n         a += i; n       } n     } n   } n } n vector<vector<long long>> matrix_mult(vector<vector<long long>>& a, n                                       vector<vector<long long>>& b) { n   int n = a.size(); n   vector<vector<long long>> answer; n   answer.resize(n); n   for (int i = 0; i < n; i++) answer[i].resize(n, 0); n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < n; j++) { n       for (int k = 0; k < n; k++) n         answer[i][j] = (answer[i][j] + a[i][k] * b[k][j]) % inf; n     } n   } n   return answer; n } n int modInverse(int a, int m) { n   int m0 = m; n   int y = 0, x = 1; n   if (m == 1) return 0; n   while (a > 1) { n     int q = a / m; n     int t = m; n     m = a % m, a = t; n     t = y; n     y = x - q * y; n     x = t; n   } n   if (x < 0) x += m0; n   return x; n } n long long power(long long x, long long y) { n   long long k = 1LL << 60; n   long long z = 1; n   while (k != 0) { n     z *= z; n     z %= inf; n     if (y >= k) { n       z *= x; n       z %= inf; n       y -= k; n     } n     k >>= 1; n   } n   return z; n } n struct point { n   long double x, y; n   bool operator<(const point& rhs) const { n     if (x == rhs.x) return y < rhs.y; n     return x < rhs.x; n   } n }; n struct pt { n   long long x, y; n   bool operator<(const point& rhs) const { n     if (x == rhs.x) return y < rhs.y; n     return x < rhs.x; n   } n }; n long double area(point x, point y, point z) { n   return (x.y * y.x + y.y * z.x + z.y * x.x - x.x * y.y - y.x * z.y - n           z.x * x.y) / n          2.0; n } n bool clockwise(point x, point y, point z) { return area(x, y, z) > 0; } n long double area(pt x, pt y, pt z) { n   return (x.y * y.x + y.y * z.x + z.y * x.x - x.x * y.y - y.x * z.y - n           z.x * x.y) / n          2.0; n } n bool clockwise(pt x, pt y, pt z) { return area(x, y, z) > 0; } n long long gcd(long long a, long long b) { n   if (a > b) swap(a, b); n   if (a == 0) return b; n   return gcd(a, b % a); n } n int popcount(long long a) { n   int count = 0; n   while (a) { n     count += (a & 1); n     a >>= 1; n   } n   return count; n } n long long choose(long long n, long long r) { n   long long p = 1, k = 1; n   if (n - r < r) r = n - r; n   if (r != 0) { n     while (r) { n       p *= n; n       k *= r; n       long long m = gcd(p, k); n       p /= m; n       k /= m; n       n--; n       r--; n     } n   } else n     p = 1; n   return p; n } n vector<long long> prefix_hash(string& a, vector<long long>& powers) { n   int n = int(a.size()); n   vector<long long> prefix(n + 1); n   for (int i = (0); i < (n); ++i) n     prefix[i + 1] = (prefix[i] + powers[i] * (a[i] -  a  + 1)) % inf; n   return prefix; n } n struct custom_hash { n   static uint64_t splitmix64(uint64_t x) { n     x += 0x9e3779b97f4a7c15; n     x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; n     x = (x ^ (x >> 27)) * 0x94d049bb133111eb; n     return x ^ (x >> 31); n   } n   uint64_t operator()(uint64_t x) const { n     static const uint64_t FIXED_RANDOM = n         chrono::steady_clock::now().time_since_epoch().count(); n     return splitmix64(x + FIXED_RANDOM); n   } n }; n struct custom_hash_fast { n   uint64_t operator()(uint64_t x) const { n     static const uint64_t FIXED_RANDOM = n         chrono::steady_clock::now().time_since_epoch().count(); n     x ^= FIXED_RANDOM; n     return x ^ (x >> 16); n   } n }; n void setIO(string second) { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n } n int main() { n   setIO(  ); n   int testc; n   cin >> testc; n   while (testc--) { n     int n; n     cin >> n; n     string a; n     cin >> a; n     int i = n - 1; n     for (; i >= 0; i--) n       if ((a[i] -  0 ) & 1) break; n     if (i == -1) { n       cout << -1 <<   n ; n       continue; n     } n     int j = 0; n     for (; j < i; j++) { n       if ((a[j] -  0 ) % 2 == 1) break; n     } n     if (j == i) { n       cout << -1 <<   n ; n       continue; n     } n     cout << a[j] << a[i] <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   cin >> t; n   while (t--) { n     int n, m, k; n     cin >> n >> m >> k; n     int cardsPlayer = n / k; n     double maxCard; n     int jokerMax = min(m, cardsPlayer); n     maxCard = ceil((m - jokerMax) / (k - 1.0)); n     if (jokerMax - maxCard > 0) n       cout << jokerMax - maxCard << endl; n     else n       cout << 0 << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n typedef struct { n   long long j, x1, x2; n } inter; n struct comp1 { n   bool operator()(const inter& a, const inter& b) const { return a.x1 < b.x1; }; n }; n struct comp2 { n   bool operator()(const inter& a, const inter& b) const { n     return (a.x2 == b.x2) ? (a.x1 < b.x1) : (a.x2 < b.x2); n   }; n }; n void solve() { n   long long n; n   cin >> n; n   vector<long long> a(n), b(n), m(n); n   unordered_map<long long, vector<long long>> dsize; n   for (long long i = 0; i < (n); i++) { n     cin >> a[i] >> b[i] >> m[i]; n     dsize[a[i] + b[i] - m[i]].push_back(i); n   } n   long long c = 0; n   vector<long long> ea(n); n   for (auto& x : dsize) { n     multiset<inter, comp1> inter1; n     multiset<inter, comp2> inter2; n     for (auto& i : x.second) { n       long long eamax = min(m[i], a[i]); n       long long eamin = max(m[i] - b[i], 0LL); n       inter1.insert(inter{i, a[i] - eamax, a[i] - eamin}); n       inter2.insert(inter{i, a[i] - eamax, a[i] - eamin}); n     } n     auto p1 = inter1.begin(); n     while (!inter2.empty()) { n       long long targ = inter2.begin()->x2; n       while ((p1 == inter1.end()) ? false : (p1->x1 <= targ)) { n         inter2.erase(*p1); n         ea[p1->j] = a[p1->j] - targ; n         p1++; n       } n       c++; n     } n   } n   cout << c << endl; n   for (long long i = 0; i < (n); i++) n     cout << ea[i] <<     << m[i] - ea[i] << endl; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   ifstream ifs; n   if (  [0]) cin.rdbuf((ifs = ifstream(  )).rdbuf()); n   ; n   ofstream ofs; n   if (  [0]) cout.rdbuf((ofs = ofstream(  )).rdbuf()); n   ; n   ofstream lfs; n   if (  [0]) clog.rdbuf((lfs = ofstream(  )).rdbuf()); n   ; n   int t; n   cin >> t; n   for (int i = 1; i <= t; i++) { n     solve(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = 1e9 + 7; n long long a[2000], dp[2000]; n long long qmod(long long y) { n   long long res = 1, two = (long long)2; n   for (; y; y >>= 1) { n     if (y & 1) res = res * two % mod; n     two = two * two % mod; n   } n   return res; n } n int main() { n   long long x, y; n   int cnt = 0; n   scanf( %lld%lld , &x, &y); n   if (y % x) return 0 * puts( 0 ); n   for (long long i = 1; i <= sqrt(y); ++i) { n     if (y % i == 0) { n       if (i % x == 0) a[++cnt] = i; n       if (i * i != y && y / i % x == 0) a[++cnt] = y / i; n     } n   } n   sort(a + 1, a + 1 + cnt); n   for (int i = cnt; i > 0; --i) { n     dp[i] = qmod(y / a[i] - 1); n     for (int j = i + 1; j <= cnt; ++j) n       if (a[j] % a[i] == 0) dp[i] = ((dp[i] - dp[j]) % mod + mod) % mod; n   } n   printf( %lld n , dp[1]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline void Input_Output() {} n const double eps = 0.000001; n const long double pi = acos(-1); n const int maxn = 1e7 + 9; n const int mod = 1e9 + 7; n const long long MOD = 1e18 + 9; n const long long INF = 1e18 + 123; n const int inf = 2e9 + 11; n const int mxn = 1e6 + 9; n const int N = 6e5 + 123; n const int K = 80; n const int pri = 997; n const int Magic = 2101; n const int dx[] = {-1, 0, 1, 0}; n const int dy[] = {0, -1, 0, 1}; n int n, m, k, x; n vector<int> state; n int ids[(1 << 8)]; n struct Mat { n   long long d[K][K]; n   Mat(long long val = INF) { n     for (int i = 0; i < K; ++i) n       for (int j = 0; j < K; ++j) d[i][j] = INF; n     for (int i = 0; i < K; ++i) d[i][i] = val; n   } n   Mat operator+(Mat &b) { n     Mat res; n     for (int i = 0; i < K; ++i) n       for (int j = 0; j < K; ++j) n         for (int k = 0; k < K; ++k) n           res.d[i][j] = min(res.d[i][j], d[i][k] + b.d[k][j]); n     return res; n   } n   void print() { n     for (int i = 0; i < K; ++i) { n       for (int j = 0; j < K; ++j) { n         if (d[i][j] == INF) { n           cout <<  bd  ; n           continue; n         } n         cout << d[i][j] <<    ; n       } n       cout <<   n ; n     } n   } n }; n Mat make_matrix(vector<long long> &c) { n   assert((int)(c.size()) == k); n   Mat res; n   for (int id = 0; id < (int)(state.size()); ++id) { n     int msk = state[id]; n     if (msk % 2 == 0) { n       int nmsk = msk / 2; n       res.d[id][ids[nmsk]] = 0; n       continue; n     } n     for (int i = 0; i < k; ++i) { n       int nmsk = (msk >> 1); n       if (nmsk & (1 << i)) { n         continue; n       } n       nmsk |= (1 << i); n       res.d[id][ids[nmsk]] = min(res.d[id][ids[nmsk]], c[i]); n     } n   } n   return res; n } n int main() { n   ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); n   cin >> x >> k >> n >> m; n   for (int msk = 0; msk < (1 << k); ++msk) { n     ids[msk] = -1; n     if (__builtin_popcount(msk) != x) { n       continue; n     } n     ids[msk] = (int)(state.size()); n     state.push_back(msk); n   } n   vector<long long> c(k); n   for (auto &e : c) cin >> e; n   vector<int> pos = {0, n - x}; n   vector<pair<int, int> > spec(m); n   for (auto &it : spec) { n     cin >> it.first >> it.second; n     it.first--; n     for (int i = 0; i <= k; ++i) { n       int s = it.first - i; n       s = max(s, 0); n       s = min(s, n - x); n       pos.push_back(s); n     } n   } n   sort(pos.begin(), pos.end()); n   pos.resize(unique(pos.begin(), pos.end()) - pos.begin()); n   vector<Mat> Pw; n   Pw.push_back(make_matrix(c)); n   int bit = 0; n   while ((1 << bit) <= n) { n     ++bit; n     Pw.push_back(Pw.back() + Pw.back()); n   } n   Mat cur = 0; n   for (int it = 0; it + 1 < (int)(pos.size()); ++it) { n     int l = pos[it], r = pos[it + 1]; n     vector<long long> nc = c; n     for (auto s : spec) { n       if (s.first > l && s.first <= l + k) { n         nc[s.first - l - 1] += s.second; n       } n     } n     if (nc != c) { n       Mat cn = make_matrix(nc); n       cur = cur + cn; n     } else { n       int dif = r - l; n       for (int i = 0; i < (int)(Pw.size()); ++i) { n         if (dif & (1 << i)) { n           cur = cur + Pw[i]; n         } n       } n     } n   } n   int fin = (1 << x) - 1; n   fin = ids[fin]; n   assert(fin != -1); n   cout << cur.d[fin][fin] <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool vis[2][100005]; n char c[2][100005]; n int main() { n   queue<pair<int, pair<int, int> > > q; n   bool flag = 0; n   int n, k; n   cin >> n >> k; n   scanf( %s%s , c[0], c[1]); n   q.push(make_pair(0, make_pair(0, 0))); n   while (!q.empty()) { n     int x = q.front().first, y = q.front().second.first, n         de = q.front().second.second; n     q.pop(); n     if (y >= n) { n       flag = 1; n       break; n     } n     if (vis[x][y] || de > y) continue; n     vis[x][y] = 1; n     if (y - 1 >= 0 && c[x][y - 1] !=  X  && y - 1 >= de + 1 && !vis[x][y - 1]) { n       q.push(make_pair(x, make_pair(y - 1, de + 1))); n     } n     if (y + 1 >= n || (c[x][y + 1] !=  X  && !vis[x][y + 1])) { n       q.push(make_pair(x, make_pair(y + 1, de + 1))); n     } n     if (y + k >= n || (c[x ^ 1][y + k] !=  X  && !vis[x ^ 1][y + k])) { n       q.push(make_pair(x ^ 1, make_pair(y + k, de + 1))); n     } n   } n   if (flag) n     cout <<  YES ; n   else n     cout <<  NO ; n } n


#include <bits/stdc++.h> n int n, k, ans; n long long s[200005], a[200005], b[200005]; n void neg() { n   for (int i = 0; i <= n; i++) { n     a[i] = -a[i]; n     b[i] = -b[i]; n   } n } n void trans() { n   b[n]--; n   b[0] += 2; n   for (int i = 1; i < n; i++) b[i]++; n   for (int i = 0; i < n; i++) { n     b[i + 1] += b[i] / 2; n     b[i] %= 2; n   } n } n void print(long long x[]) { n   for (int i = 0; i <= n; i++) printf( %I64d  , x[i]); n   printf(  n ); n } n int main() { n   scanf( %d %d , &n, &k); n   for (int i = 0; i <= n; i++) scanf( %I64d , &a[i]); n   for (int i = 0; i < n; i++) { n     b[i] += a[i]; n     b[i + 1] += b[i] / 2; n     b[i] %= 2; n     if (b[i] < 0) { n       b[i + 1]--; n       b[i] += 2; n     } n   } n   b[n] += a[n]; n   if (b[n] < 0) neg(); n   trans(); n   for (int i = n; i >= 0; i--) { n     if (s[i + 1] == 10ll * k + 1) n       s[i] = 10ll * k + 1; n     else n       s[i] = s[i + 1] * 2 + b[i]; n     if (s[i] > 10ll * k) s[i] = 10ll * k + 1; n   } n   for (int i = 0; i <= n; i++) { n     if (i == n && llabs(s[i] - a[i]) <= k && s[i] != a[i]) ans++; n     if (i != n && llabs(s[i] - a[i]) <= k) ans++; n     if (b[i]) break; n   } n   printf( %d n , ans); n   scanf(  n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   ; n   long long int n, k, sum = 0; n   cin >> n >> k; n   long long int a[n]; n   for (long long int i = 0; i < n; i++) cin >> a[i]; n   string s; n   cin >> s; n   vector<long long int> v; n   v.push_back(a[0]); n   for (long long int i = 1; s[i]; i++) { n     if (s[i] == s[i - 1]) n       v.push_back(a[i]); n     else { n       sort(v.rbegin(), v.rend()); n       for (long long int i = 0; i < k && i < v.size(); i++) { n         sum += v[i]; n       } n       v.clear(); n       v.push_back(a[i]); n     } n   } n   sort(v.rbegin(), v.rend()); n   for (long long int i = 0; i < k && i < v.size(); i++) sum += v[i]; n   cout << sum; n } n


#include<bits/stdc++.h> n using namespace std; n int a[10]; n int main() { n     int T;scanf( %d ,&T); n     while(T--) { n         int sum = 0; n         for(int i = 1;i <= 3;i++) { n             scanf( %d ,&a[i]); n             sum += a[i]; n         } n         if(sum % 9 == 0) { n             if(a[1] >= sum / 9 && a[2] >= sum / 9 && a[3] >= sum / 9) { n                 printf( YES n ); n             } else { n                 printf( NO n ); n             } n         } else { n             printf( NO n ); n         } n     } n     return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long int; n using ld = long double; n using vi = vector<int>; n using vll = vector<ll>; n using vd = vector<double>; n using vvi = vector<vi>; n int ctoi(char c) { return c -  0 ; } n int slen(string s) { return s.length(); } n int vsize(vi a) { return (int)a.size(); } n int in() { n   int x; n   cin >> x; n   return x; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(nullptr); n   int N; n   cin >> N; n   vi d(N); n   for (auto& x : d) cin >> x; n   int mn = abs(d[N - 1] - d[0]); n   int a = N - 1, b = 0; n   for (int i = 1; i < N; i++) { n     if (abs(d[i] - d[i - 1]) < mn) { n       mn = abs(d[i] - d[i - 1]); n       a = i; n       b = i - 1; n     } n   } n   cout << a + 1 <<     << b + 1 << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   int result = 0; n   for (int i = 0; i < n; i++) { n     int k, a; n     cin >> k >> a; n     long x = k * a; n     int c = 0; n     if (a % 4 == 0) a--; n     while (a) { n       a /= 4; n       c++; n     } n     result = (((result) < (k + c)) ? (k + c) : (result)); n   } n   cout << result; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long n, m; n   cin >> n >> m; n   long long x; n   for (int i = 0; i < m; i++) { n     cin >> x; n     if (x > n) n       cout << 0 << endl; n     else { n       if (x % 2 == 1) n         cout << x / 2 + 1 << endl; n       else { n         long long a = x, b, c = n; n         while (1) { n           if (a % 2 == 1) break; n           b = a + (c - a / 2); n           a = b; n         } n         cout << a / 2 + 1 << endl; n       } n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = 0x3f3f3f3f; n const int maxn = 100010; n int x0[maxn], x1[maxn], d[maxn], c[maxn]; n int main() { n   int n, m, y0, y1; n   scanf( %d %d %d %d , &n, &m, &y0, &y1); n   for (int i = 0; i < n; ++i) { n     scanf( %d , &x0[i]); n   } n   memset(d, -1, sizeof(d)); n   for (int i = 0; i < m; ++i) { n     scanf( %d , &x1[i]); n   } n   int p = 0, k = 0, last = -1; n   for (int i = 0; i < n; ++i) { n     while (p < m && abs(x0[i] - x1[p]) > abs(x0[i] - x1[p + 1])) ++p; n     if (last < p || abs(x0[i - 1] - x1[p]) == abs(x0[i] - x1[p])) n       ++k, last = p; n     else if (p < m && abs(x0[i] - x1[p]) == abs(x0[i] - x1[p + 1])) n       ++k, last = ++p; n     else n       last = p; n   } n   printf( %d n , n - k); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string a; n   cin >> a; n   long long int x = a.length(); n   std::vector<long long int> v; n   long long int c = 0; n   long long int d = 0; n   for (long long int i = 0; i < x; i++) { n     if (a[i] ==  b ) { n       d++; n     } n     if (a[i] ==  a ) { n       if (d > 0 && c > 0) { n         v.push_back(c); n         d = 0; n         c = 0; n       } n       c++; n       d = 0; n     } n   } n   if (c > 0) v.push_back(c); n   long long int res = 1; n   for (long long int i = 0; i < v.size(); i++) { n     res = (res * (v[i] + 1)) % 1000000007; n   } n   cout << res - 1; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, a[16], b[16]; n int main() { n   double cnt = 0; n   ios::sync_with_stdio(false); n   cin >> n; n   for (register int i = 0; i < n; i++) cin >> a[i]; n   for (register int i = 0; i < n; i++) cin >> b[i]; n   for (register int i = 0; i < 1e6; ++i) { n     register bool f = false; n     for (register int j = 0; !f && j < n; ++j) f |= i % a[j] == b[j]; n     cnt += f; n   } n   cout.setf(ios::fixed, ios::floatfield); n   return (cout << setprecision(7) << cnt / 1e6 << endl) && 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, k1, k2; n long long a[1005]; n long long b[1005]; n void ReadData() { n   cin >> n >> k1 >> k2; n   for (long long i = 1; i <= n; i++) cin >> a[i]; n   for (long long i = 1; i <= n; i++) cin >> b[i]; n } n long long c[1005]; n void process() { n   long long k = k1 + k2; n   priority_queue<long long> heap; n   for (long long i = 1; i <= n; i++) { n     c[i] = abs(a[i] - b[i]); n     heap.push(c[i]); n   } n   while (k--) { n     long long tmp = heap.top(); n     heap.pop(); n     tmp--; n     heap.push(abs(tmp)); n   } n   long long res = 0; n   while (!heap.empty()) { n     long long tmp = heap.top(); n     heap.pop(); n     res += tmp * tmp; n   } n   cout << res; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   ReadData(); n   process(); n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1002, M = 10002; n pair<int, long long> dp[N][M]; n map<long long, int> di; n bool vis[N][M]; n int nxt[N][M]; n long long a[N], b[N], k; n int T[M][N]; n int n; n long long gcd(long long a, long long b) { n   if (b == 0) return a; n   return gcd(b, a % b); n } n int main() { n   scanf( %d %lld , &n, &k); n   for (int i = 0; i < n; ++i) { n     scanf( %lld , b + i); n     a[i] = gcd(b[i], k); n   } n   if (k == 1) return printf( %d n%ld n , 1, min_element(b, b + n) - b + 1), 0; n   vector<long long> divisor; n   for (long long i = 1; i * i <= k; ++i) n     if (k % i == 0) { n       divisor.push_back(i); n       divisor.push_back(k / i); n     } n   sort(divisor.begin(), divisor.end()); n   divisor.resize(unique(divisor.begin(), divisor.end()) - divisor.begin()); n   int m = divisor.size(); n   for (int i = 0; i < m; ++i) di[divisor[i]] = i; n   for (int i = 0; i < m; ++i) n     for (int j = 0; j < n; ++j) n       T[i][j] = di[divisor[i] / gcd(divisor[i], a[j])]; n   nxt[n][0] = -1; n   dp[n][0] = {0, 0}; n   for (int i = 1; i < m; ++i) dp[n][i] = {n + 1, 0}; n   for (int i = 0; i < m; ++i) n     for (int j = n - 1; j >= 0; --j) { n       pair<int, long long> ans1 = dp[j + 1][i]; n       pair<int, long long> ans2 = dp[j + 1][T[i][j]]; n       ans2.first += 1; n       ans2.second += b[j]; n       if (ans1 <= ans2) { n         nxt[j][i] = nxt[j + 1][i]; n         dp[j][i] = ans1; n       } else { n         nxt[j][i] = j; n         dp[j][i] = ans2; n       } n     } n   pair<int, long long> ans = dp[0][m - 1]; n   if (ans.first > n) return puts( -1 ), 0; n   printf( %d n , ans.first); n   int pos = 0; n   int nx = m - 1; n   while (pos != -1) { n     if (nxt[pos][nx] != pos) n       pos = nxt[pos][nx]; n     else { n       nx = T[nx][pos]; n       printf( %d  , pos + 1); n       pos += 1; n     } n   } n   puts(  ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(0); n   int n; n   cin >> n; n   int a[100005]; n   for (int i = 0; i < n; i++) cin >> a[i]; n   sort(a, a + n); n   if (n == 1) { n     cout << -1 << endl; n     return 0; n   } n   bool flag = true; n   for (int i = 1; i < n; i++) flag = flag && (a[0] == a[i]); n   if (flag) { n     cout << 1 << endl; n     cout << a[0] << endl; n     return 0; n   } n   if (n == 2) { n     if ((a[0] + a[1]) % 2 == 0) n       cout << 3 << endl; n     else n       cout << 2 << endl; n     cout << 2 * a[0] - a[1] <<    ; n     if ((a[0] + a[1]) % 2 == 0) cout << (a[1] + a[0]) / 2 <<    ; n     cout << 2 * a[1] - a[0] <<    ; n     return 0; n   } n   flag = true; n   for (int i = 2; i < n; i++) flag = flag && (a[1] - a[0] == a[i] - a[i - 1]); n   if (flag) { n     cout << 2 << endl; n     cout << 2 * a[0] - a[1] <<    ; n     cout << 2 * a[n - 1] - a[n - 2] << endl; n     return 0; n   } n   vector<int> diff; n   set<int> di; n   for (int i = 1; i < n; i++) { n     diff.push_back(a[i] - a[i - 1]); n     di.insert(a[i] - a[i - 1]); n   } n   if (di.size() != 2) { n     cout << 0 << endl; n     return 0; n   } n   sort(diff.begin(), diff.end()); n   int chan = diff[n - 2]; n   if (chan != 2 * diff[0]) { n     cout << 0 << endl; n     return 0; n   } n   for (int i = n - 3; i >= 0; i--) { n     if (diff[i] == chan || diff[i] != diff[0]) { n       cout << 0 << endl; n       return 0; n     } n   } n   for (int i = 1; i < n; i++) { n     if (a[i] - a[i - 1] == chan) { n       if ((a[i] + a[i - 1]) % 2 == 0) { n         cout << 1 << endl; n         cout << (a[i] + a[i - 1]) / 2 << endl; n         return 0; n       } else { n         cout << 0 << endl; n         return 0; n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<long int> fib(46, -1); n int adv_fib(int n) { n   if (n == 0 || n == 1) { n     return 1; n   } else if (fib[n] == -1) { n     return fib[n] = adv_fib(n - 1) + adv_fib(n - 2); n   } else { n     return fib[n]; n   } n } n int main() { n   int n, curr = 1; n   cin >> n; n   for (int i = 1; i <= n; i++) { n     if (adv_fib(curr) == i) { n       cout <<  O ; n       curr++; n     } else { n       cout <<  o ; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long i, j, k, l, m, n, t, a[211111], b[211111], c[111111], d, s; n string p[111111], q[111111]; n int main() { n   cin >> n; n   for (i = 1; i <= n; i++) scanf( %I64d , &a[i]); n   for (i = 1; i <= n; i++) scanf( %I64d , &b[i]); n   i = 1; n   j = 1; n   while (i <= n) { n     while (a[i] != b[j] && j <= n) j++; n     if (j <= n) n       i++; n     else n       break; n   } n   if (i > n) { n     cout << 0; n     return 0; n   } n   cout << n - i + 1; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   vector<int> v(n); n   for (auto &x : v) cin >> x; n   int mine = *min_element(v.begin(), v.end()); n   vector<int> temp; n   for (int i = 0; i < n; i++) { n     if (v[i] == mine) temp.push_back(i); n   } n   for (int i = 0; i < temp.size() - 1; i++) temp[i] = temp[i + 1] - temp[i]; n   cout << *min_element(temp.begin(), temp.end() - 1) << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e5 + 50; n int n, a[maxn], ans, maxx = 0; n int main() { n   cin >> n; n   for (int i = 1; i <= n; i++) { n     cin >> a[i]; n     maxx = max(maxx, a[i]); n   } n   cout << maxx; n   return 0; n } n