#include <bits/stdc++.h> n using namespace std; n const long long INF = 99999999; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   int n; n   cin >> n; n   if (n == 1) { n     cout << 1; n     return 0; n   } n   vector<int> a(n); n   ; n   for (int i = 0; i < (n); ++i) cin >> a[i]; n   ; n   vector<int> c; n   for (int j = 1; j < n; ++j) { n     if (a[j] > a[j - 1]) n       c.push_back(1); n     else if (a[j] < a[j - 1]) n       c.push_back(-1); n     else n       c.push_back(0); n   } n   vector<pair<int, int>> d; n   int p = 1; n   for (int k = 1; k < c.size(); ++k) { n     if (c[k] == c[k - 1]) n       p++; n     else { n       d.push_back({p, c[k - 1]}); n       p = 1; n     } n   } n   d.push_back({p, c[c.size() - 1]}); n   vector<int> answ; n   if (d[0].second == 0) n     answ.push_back(3); n   else if (d[0].second == -1) n     answ.push_back(5); n   else n     answ.push_back(1); n   int last = 0; n   for (int i = 0; i < d.size(); ++i) { n     int cnt = d[i].first; n     int type = d[i].second; n     if (type == 0) { n       bool f = answ[last] == 3; n       for (int j = 0; j < cnt - 1; ++j) { n         if (f) n           answ.push_back(4); n         else n           answ.push_back(3); n         f = !f; n         last++; n       } n       if (i + 1 < d.size() && d[i + 1].second == -1) { n         if (answ[last] == 5) n           answ.push_back(4); n         else n           answ.push_back(5); n         last++; n       } else if (i + 1 < d.size() && d[i + 1].second == 1) { n         if (answ[last] == 1) n           answ.push_back(2); n         else n           answ.push_back(1); n         last++; n       } else { n         if (answ[last] == 4) n           answ.push_back(3); n         else n           answ.push_back(4); n         last++; n       } n     } else { n       for (int j = 0; j < cnt - 1; ++j) { n         answ.push_back(answ[last] + type); n         last++; n       } n       if (answ[last] > 5 || answ[last] < 1) { n         cout << -1; n         return 0; n       } n       if (i + 1 < d.size() && d[i + 1].second == -1) { n         if (answ[last] == 5) { n           cout << -1; n           return 0; n         } n         answ.push_back(5); n         last++; n       } else if (i + 1 < d.size() && d[i + 1].second == 1) { n         if (answ[last] == 1) { n           cout << -1; n           return 0; n         } n         answ.push_back(1); n         last++; n       } else { n         answ.push_back(answ[last] + type); n         last++; n         if (answ[last] > 5 || answ[last] < 1) { n           cout << -1; n           return 0; n         } n       } n     } n   } n   for (int l = 0; l < n; ++l) { n     cout << answ[l] <<    ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int LIM = 3e5 + 7; n int T[LIM][10], n, m, ans1, ans2; n bool spr(int x) { n   vector<int> V[1 << m]; n   for (int i = 0; i < (n); ++i) { n     int l = 0; n     for (int j = 0; j < (m); ++j) { n       if (T[i][j] >= x) l += 1 << j; n     } n     V[l].push_back(i); n   } n   for (int i = 0; i < (1 << m); ++i) { n     if (!V[i].size()) continue; n     for (int j = 0; j < (1 << m); ++j) { n       if (!V[j].size()) continue; n       if ((i | j) == (1 << m) - 1) { n         ans1 = V[i][0]; n         ans2 = V[j][0]; n         return true; n       } n     } n   } n   return false; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cin >> n >> m; n   for (int i = 0; i < (n); ++i) n     for (int j = 0; j < (m); ++j) cin >> T[i][j]; n   int p = 0, k = 1000000000; n   while (p < k) { n     int sr = (p + k) / 2; n     if (spr(sr)) n       p = sr + 1; n     else n       k = sr - 1; n   } n   spr(p); n   cout << ans1 + 1 <<     << ans2 + 1 <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n int minimumStones(string s, int n) { n   int i = 0, counts = 0; n   while (s[i] ==  - ) { n     counts++; n     i++; n   } n   for (int i = 0; i < n; i++) { n     if (s[i] ==  - ) n       counts--; n     else n       counts++; n     if (counts == 0) { n       int j = i + 1; n       while (s[j] ==  - ) { n         counts++; n         j++; n       } n     } n   } n   return counts; n } n int main() { n   int n; n   cin >> n; n   string s; n   cin >> s; n   cout << minimumStones(s, n); n } n


#include <bits/stdc++.h> n using namespace std; n const double EPS = 1e-3; n const int SZ = 4000050, INF = 0x7FFFFFFF; n const double PI = acos(-1); n struct nd { n   double a, b, c, d, e; n   nd(double _a = 0, double _b = 0, double _c = 0, double _d = 0, double _e = 0) n       : a(_a), b(_b), c(_c), d(_d), e(_e) {} n   nd operator-(nd &rbs) { n     return nd(a - rbs.a, b - rbs.b, c - rbs.c, d - rbs.d, e - rbs.e); n   } n }; n double len(nd &x) { n   double res = sqrt(x.a * x.a + x.b * x.b + x.c * x.c + x.d * x.d + x.e * x.e); n   return res; n } n double Dot(nd &x, nd &y) { n   return (x.a * y.a + x.b * y.b + x.c * y.c + x.d * y.d + x.e * y.e) / len(x) / n          len(y); n } n bool test(nd &x, nd &y) { n   double ang = acos(Dot(x, y)); n   return ang < (PI / 2) && fabs(ang - (PI / 2)) > EPS; n } n int main() { n   int pnum; n   cin >> pnum; n   vector<nd> vct; n   if (pnum > 11) { n     cout << 0 << endl; n     return 0; n   } n   for (int i = 0; i < pnum; ++i) { n     nd tmp; n     cin >> tmp.a >> tmp.b >> tmp.c >> tmp.d >> tmp.e; n     vct.push_back(tmp); n   } n   vector<int> res; n   for (int i = 0; i < pnum; ++i) { n     bool ok = 1; n     for (int j = 0; j < pnum; ++j) { n       if (j == i) continue; n       for (int k = 0; k < pnum; ++k) { n         if (k == j) continue; n         nd ac = vct[j] - vct[i]; n         nd bc = vct[k] - vct[i]; n         if (test(ac, bc)) ok = 0; n       } n     } n     if (ok) { n       res.push_back(i + 1); n     } n   } n   cout << res.size() << endl; n   for (int i = 0; i < res.size(); ++i) { n     cout << res[i] << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2e5 + 5, K = 300; n int n, mx, ct, ans, a[N], buc[N], lst[N * 2], tp[N], cnt; n inline void Add(int x, int k) { n   cnt -= (tp[x] == ct), tp[x] += k, cnt += (tp[x] == ct); n } n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; ++i) scanf( %d , a + i), ++buc[a[i]]; n   mx = max_element(buc + 1, buc + n + 1) - buc; n   for (ct = 1; ct <= K; ++ct) { n     memset(tp, 0, sizeof(tp)), cnt = 0; n     for (int l = 1, r = 1; r <= n; ++r) { n       Add(a[r], 1); n       while (tp[a[r]] > ct) Add(a[l++], -1); n       if (cnt > 1) ans = max(ans, r - l + 1); n     } n   } n   for (int i = 1, s; i <= n; ++i) n     if (i != mx && buc[i] > K) { n       memset(lst, -1, sizeof(lst)), lst[s = n] = 0; n       for (int j = 1; j <= n; ++j) { n         s += a[j] == mx ? 1 : (a[j] == i ? -1 : 0); n         if (~lst[s]) n           ans = max(ans, j - lst[s]); n         else n           lst[s] = j; n       } n     } n   printf( %d , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline long long getnum() { n   char c = getchar(); n   long long num, sign = 1; n   for (; c <  0  || c >  9 ; c = getchar()) n     if (c ==  - ) sign = -1; n   for (num = 0; c >=  0  && c <=  9 ;) { n     c -=  0 ; n     num = num * 10 + c; n     c = getchar(); n   } n   return num * sign; n } n int main() { n   int n = getnum(), m = getnum(); n   int ans = 0; n   while (1) { n     if ((ans * n) % 10 == 0 && ans > 0) { n       cout << ans; n       return 0; n     } n     if ((ans * n - m) % 10 == 0) { n       cout << ans; n       return 0; n     } n     ans++; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string a, b; n   cin >> a; n   b = a; n   reverse(b.begin(), b.end()); n   printf( %s%s n , a.c_str(), b.c_str()); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long tree[400005]; n int n; n long long r[100005], h[100005], v[100005]; n pair<long long, int> p[100005]; n int mp[100005]; n void update(int nd, int bb, int ee, int ii, long long vv) { n   if (bb == ee && bb == ii) { n     tree[nd] = vv; n     return; n   } n   if (bb > ii || ee < ii) return; n   int ll = nd << 1, rr = ll | 1, mm = (bb + ee) >> 1; n   update(ll, bb, mm, ii, vv); n   update(rr, mm + 1, ee, ii, vv); n   tree[nd] = max(tree[ll], tree[rr]); n   return; n } n long long query(int nd, int bb, int ee, int ii, int jj) { n   if (jj < ii) return 0; n   if (bb >= ii && ee <= jj) return tree[nd]; n   if (bb > jj || ee < ii) return 0; n   int ll = nd << 1, rr = ll | 1, mm = (bb + ee) >> 1; n   return max(query(ll, bb, mm, ii, jj), query(rr, mm + 1, ee, ii, jj)); n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(nullptr); n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> r[i] >> h[i]; n     p[i] = {r[i] * r[i] * h[i], i}; n   } n   sort(p, p + n); n   for (int i = 0, ii = 0; i < n; i++) { n     if (i > 0 && p[i].first == p[i - 1].first) ii--; n     mp[p[i].second] = ii; n     ii++; n   } n   for (int i = 0; i < n; i++) { n     update(1, 0, n - 1, mp[i], n            r[i] * r[i] * h[i] + query(1, 0, n - 1, 0, mp[i] - 1)); n   } n   cout << fixed << setprecision(9) << double(tree[1]) * acos(-1.0) <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long a[200020]; n long long va[200020]; n long long b[200020]; n long long c[200020]; n char ans[200020]; n char ansstring[200020]; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(NULL); n   long long n, k; n   cin >> n >> k; n   for (int i = 1; i <= n; i++) { n     cin >> a[i]; n     va[a[i]] = i; n   } n   for (int i = 1; i <= n; i++) { n     cin >> b[i]; n     c[i] = va[b[i]]; n   } n   char ch =  a ; n   for (int i = 1; i <= n; i++) { n     long long reach = c[i]; n     if (ch >  z ) { n       ch--; n     } n     for (int j = i; j <= reach; j++) { n       reach = max(reach, c[j]); n       ans[j] = ch; n     } n     i = reach; n     ch++; n   } n   if (ch -  a  < k) { n     cout <<  NO ; n     return 0; n   } n   for (int i = 1; i <= n; i++) { n     ansstring[b[i]] = ans[i]; n   } n   cout <<  YES n ; n   for (int i = 1; i <= n; i++) { n     cout << ansstring[i]; n   } n } n


#include <bits/stdc++.h> n using namespace std; n bool isPrime(int n) { n   if (n <= 1) return false; n   for (int i = 2; i < n; i++) n     if (n % i == 0) return false; n   return true; n } n int main() { n   ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); n   int n; n   cin >> n; n   vector<int> v; n   if (n == 1) { n     cout <<  0 ; n     return 0; n   } n   int temp; n   for (long long int i = (2); i <= (n); i++) { n     temp = i; n     if (isPrime(i)) { n       while (temp <= n) { n         v.push_back(temp); n         temp *= i; n       } n     } n   } n   cout << v.size() << endl; n   for (auto i = v.begin(); i != v.end(); i++) cout << *i <<    ; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 120; n int a[N][N], n, k; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cin >> n >> k; n   if (k > n * n) { n     cout <<  -1 n ; n   } else { n     for (int i = 0; i < n && k > 0; i++) { n       a[i][i] = 1, k--; n       for (int j = i + 1; j < n && k > 1; j++) { n         a[i][j] = 1, a[j][i] = 1, k -= 2; n       } n     } n     for (int i = 0; i < n; i++) { n       for (int j = 0; j < n; j++) { n         cout << a[i][j] << (j + 1 == n ?   n  :    ); n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int oo = 0x3f3f3f3f; n const int MAXN = 200010; n const double EPS = 1e-7; n inline int read() { n   char c = getchar(); n   int x = 0, f = 1; n   while (c <  0  || c >  9 ) { n     if (c ==  - ) f = -1; n     c = getchar(); n   } n   while (c >=  0  && c <=  9 ) { n     x = x * 10 + (c -  0 ); n     c = getchar(); n   } n   return x * f; n } n char s[55], t[55]; n int cnt[30], vis[55]; n vector<int> pos[30]; n vector<int> ans; n int main() { n   int n = read(); n   scanf( %s , s + 1); n   scanf( %s , t + 1); n   for (int i = 1; i <= n; i++) cnt[s[i] -  a ]++; n   for (int i = 1; i <= n; i++) pos[t[i] -  a ].push_back(i); n   int flag = 1; n   for (int i = 0; i < 26; i++) n     if (cnt[i] != (int)((pos[i]).size())) flag = 0; n   if (flag) { n     for (int i = 1; i <= n; i++) { n       for (int j = i; j <= n; j++) { n         if (s[j] == t[i]) { n           for (int k = j - 1; k >= i; k--) { n             swap(s[k], s[k + 1]); n             ans.push_back(k); n           } n           break; n         } n       } n     } n     cout << (int)((ans).size()) << endl; n     for (int i = 0; i < (int)((ans).size()); i++) cout << ans[i] <<    ; n   } else n     puts( -1 ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long gen(int order) { n   long long sum = 0; n   while (order != 0) { n     sum = (sum * 10) + 9; n     order--; n   } n   return sum; n } n int main() { n   long long l, r; n   cin >> l >> r; n   long long p = l, k = r; n   int order = 0, sorder = 0; n   while (k != 0) { n     k = k / 10; n     order++; n   } n   while (p != 0) { n     p = p / 10; n     sorder++; n   } n   if (sorder == order) { n     long long max = gen(order); n     if ((max - 1) / 2 <= r && l <= (max - 1) / 2) { n       long long ans = ((max + 1) / 2) * ((max - 1) / 2); n       cout << ans; n     } else { n       long long max = gen(order); n       if (r < (max - 1) / 2) { n         long long ans = r * (max - r); n         cout << ans; n       } else { n         long long ans = l * (max - l); n         cout << ans; n       } n     } n   } else { n     long long max = gen(order); n     long long smax = gen(order - 1); n     if (r >= (max - 1) / 2) { n       long long ans = ((max + 1) / 2) * ((max - 1) / 2); n       cout << ans; n     } else { n       if (l <= (smax + 1) / 2) { n         if ((smax + 1) * (smax - 1) / 4 > r * (max - r)) { n           cout << (smax + 1) * (smax - 1) / 4; n         } else { n           cout << r * (max - r); n         } n       } else { n         if (l * (smax - l) > r * (max - r)) { n           cout << l * (smax - l); n         } else { n           cout << r * (max - r); n         } n       } n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n T gcd(T a, T b) { n   return a ? gcd(b % a, a) : b; n } n template <typename T> n T lcm(T a, T b) { n   return (a / gcd(a, b)) * b; n } n string int_to_str_easy(long long n) { n   return n ?    : int_to_str_easy(n / 10) + (char)( 0  + n % 10); n } n template <typename T> n T sum(vector<T> v) { n   T ans = 0; n   for (T i : v) ans += i; n   return ans; n } n bool is_down(char x) { return ( a  <= x && x <=  z ); } n bool is_upper(char x) { return ( A  <= x && x <=  Z ); } n bool is_digit(char x) { return ( 0  <= x && x <=  9 ); } n string follow(string s) { n   for (int i = 0; i < s.length(); i++) n     if (is_upper(s[i])) s[i] +=  a  -  A ; n   return s; n } n const long double pi = 3.141592653589793238462643383279; n const long double log23 = 1.58496250072115618145373894394781; n const long double eps = 1e-8; n const long double zero = 0; n const long long INF = 1e18; n const int COUT = 30; n const int prost = 239; n const long long prost64 = 239; n const int two = 2; n const long long MOD = 1000000007; n const int BIG = 1e9; n const int alf = 26; n const int MAX_M = 2001; n const int MAX_N = 2 * 1e5 + 1; n const int km = (1 << 18) - 1; n const int dxo[8] = {-1, -1, -1, 0, 1, 1, 1, 0}; n const int dyo[8] = {-1, 0, 1, 1, 1, 0, -1, -1}; n const int dx[4] = {-1, 0, 1, 0}; n const int dy[4] = {0, 1, 0, -1}; n const int bit_max = 32; n void solve() { return; } n int n; n string s; n int main() { n   cin.sync_with_stdio(0); n   cin >> n >> s; n   string e =   ; n   int ans = 0; n   for (int i = 0; i < n; i++) { n     if (i % 2 == 0) n       e +=  r ; n     else n       e +=  b ; n   } n   int now = 0; n   string w = s; n   int no1 = 0; n   int no2 = 0; n   for (int i = 0; i < n; i++) { n     if (w[i] != e[i] && (i + 1) % 2 == 0) n       no1++; n     else if (w[i] != e[i]) n       no2++; n   } n   now = min(no1, no2) + abs(no1 - no2); n   ans = now; n   now = 0; n   e =   ; n   for (int i = 0; i < n; i++) { n     if (i % 2 == 0) n       e +=  b ; n     else n       e +=  r ; n   } n   w = s; n   no1 = 0; n   no2 = 0; n   for (int i = 0; i < n; i++) { n     if (w[i] != e[i] && (i + 1) % 2 == 0) n       no1++; n     else if (w[i] != e[i]) n       no2++; n   } n   now = min(no1, no2) + abs(no1 - no2); n   ans = min(ans, now); n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( O2 ) n using namespace std; n const int MAXN = 1e6 + 10; n const long long MOD = 1e9 + 7; n const long long MOD2 = 998244353; n const long long INF = 8e18; n const int LOG = 22; n long long pw(long long a, long long b, long long mod) { n   return (!b ? 1 n              : (b & 1 ? (a * pw(a * a % mod, b / 2, mod)) % mod n                       : pw(a * a % mod, b / 2, mod))); n } n long long dp[2][MAXN]; n int x[MAXN]; n vector<int> G[MAXN]; n void DFS(int v, int par) { n   dp[0][v] = 1; n   dp[1][v] = 0; n   for (auto u : G[v]) { n     if (u == par) { n       continue; n     } n     DFS(u, v); n     dp[1][v] = (dp[1][v] * dp[0][u]) % MOD; n     dp[1][v] = (dp[1][v] + dp[1][u] * dp[0][v]) % MOD; n     dp[0][v] = (dp[0][v] * dp[0][u]) % MOD; n   } n   if (x[v]) { n     dp[1][v] = dp[0][v]; n   } else { n     dp[0][v] = (dp[0][v] + dp[1][v]) % MOD; n   } n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   ; n   int n; n   cin >> n; n   for (int i = 1; i < n; i++) { n     int a; n     cin >> a; n     G[a].push_back(i); n     G[i].push_back(a); n   } n   for (int i = 0; i < n; i++) { n     cin >> x[i]; n   } n   DFS(0, -1); n   cout << dp[1][0] <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long MOD = 998244353; n const int MAXN = 1e5 + 10; n const long long mod = (1ll << 32); n const long long inf = 1e16; n const int N = 1e7 + 1; n struct Query { n   int l, r, id; n }; n Query q[MAXN]; n long long a[MAXN], p[MAXN], cntl[N], cntr[N], res[MAXN], K = 1000, k, n, Q; n long long ans = 0; n bool cmp(Query a, Query b) { n   if (a.l / K != b.l / K) return a.l < b.l; n   return a.r < b.r; n } n void addL(int id) { n   cntr[p[id]]++; n   cntl[p[id - 1]]++; n   ans += cntr[k ^ p[id - 1]]; n } n void addR(int id) { n   cntr[p[id]]++; n   cntl[p[id - 1]]++; n   ans += cntl[k ^ p[id]]; n } n void delL(int id) { n   ans -= cntr[k ^ p[id - 1]]; n   cntr[p[id]]--; n   cntl[p[id - 1]]--; n } n void delR(int id) { n   ans -= cntl[k ^ p[id]]; n   cntr[p[id]]--; n   cntl[p[id - 1]]--; n } n void solve() { n   cin >> n >> Q >> k; n   for (int i = 1; i < n + 1; ++i) { n     cin >> a[i]; n     p[i] = p[i - 1] ^ a[i]; n   } n   for (int i = 0; i < Q; ++i) { n     int l, r; n     cin >> l >> r; n     q[i] = {l, r, i}; n   } n   sort(q, q + Q, cmp); n   int L = 1, R = 0; n   for (int i = 0; i < Q; ++i) { n     int l = q[i].l, r = q[i].r, id = q[i].id; n     while (L > l) addL(--L); n     while (R < r) addR(++R); n     while (L < l) delL(L++); n     while (R > r) delR(R--); n     res[id] = ans; n   } n   for (int i = 0; i < Q; ++i) cout << res[i] <<   n ; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(nullptr); n   cout.tie(nullptr); n   solve(); n } n


#include <bits/stdc++.h> n using namespace std; n int main(void) { n   cin.tie(0); n   ios_base::sync_with_stdio(false); n   int a, ta, b, tb; n   string t; n   cin >> a >> ta >> b >> tb >> t; n   int p = n       600 * (t[0] -  0 ) + 60 * (t[1] -  0 ) + 10 * (t[3] -  0 ) + t[4] -  0 ; n   int q = p + ta; n   int ans = 0, i; n   for (i = 300; i < 1440; i += b) { n     if (p * (ta + tb) < ta * tb + p * tb + i * ta && n         ta * tb + p * tb + i * ta < q * (ta + tb)) n       ans++; n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using namespace std; n long long ara[205]; n long long dp[205][205][205]; n int n, k, x; n long long rec(int pos, int last, int left) { n   if (last > k) return -1e17; n   if (pos == n + 1) { n     if (!left) return 0; n     return (-1e17); n   } n   if (left < 0) return -1e17; n   long long& ret = dp[pos][last][left]; n   if (~ret) return ret; n   ret = -1e17; n   if (rec(pos + 1, 1, left - 1) >= 0) n     ret = max(ret, rec(pos + 1, 1, left - 1) + ara[pos]); n   if (rec(pos + 1, last + 1, left) >= 0) n     ret = max(ret, rec(pos + 1, last + 1, left)); n   return ret; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   scanf( %d %d %d , &n, &k, &x); n   for (int i = 1; i <= n; i++) scanf( %lld , &ara[i]); n   memset(dp, -1, sizeof dp); n   printf( %lld n , (rec(1, 1, x) <= 0 ? -1 : rec(1, 1, x))); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long num[300010]; n long long sum[300010]; n int n; n bool cmp(int a, int b) { return a > b; } n int main() { n   while (~scanf( %d , &n)) { n     for (int i = 0; i < n; i++) cin >> num[i]; n     sort(num, num + n, cmp); n     sum[0] = num[0]; n     for (int i = 1; i < n; i++) { n       sum[i] = sum[i - 1] + num[i]; n     } n     long long ans = sum[n - 1]; n     for (int i = n - 2; i >= 0; i--) ans += sum[i] + num[n - 1 - i]; n     cout << ans << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n double n, m, k, a, b, c; n string s; n vector<double> v; n int main() { n   scanf( %lf %lf %lf , &a, &b, &c); n   if (a == 0 && b == 0 && c == 0) { n     printf( -1 n ); n     return 0; n   } n   if (a == 0 && b == 0 && c != 0) { n     printf( 0 n ); n     return 0; n   } n   if (b * b - 4 * a * c < 0) { n     printf( 0 n ); n     return 0; n   } n   if (a == 0) { n     printf( 1 n ); n     double cev = -c / b; n     printf( %lf , cev); n     return 0; n   } n   if (b * b - 4 * a * c == 0) { n     printf( 1 n ); n     double cev = -b / (2 * a); n     printf( %lf , cev); n     return 0; n   } n   printf( 2 n ); n   double cev = (-b - sqrt(b * b - 4 * a * c)) / (2 * a); n   double cevap = (-b + sqrt(b * b - 4 * a * c)) / (2 * a); n   v.push_back(cev); n   v.push_back(cevap); n   sort(v.begin(), v.end()); n   printf( %lf n , v[0]); n   printf( %lf n , v[1]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double pi = acos(-1.0); n const double eps = 1E-15; n const int inf = int(1e9) + 7; n const int maxN = 1000 + 5; n int in[maxN], to[maxN], cs[maxN]; n int n, m; n int main() { n   scanf( %d%d , &n, &m); n   int a, b, c; n   for (int(i) = 0; (i) < (m); ++(i)) { n     scanf( %d%d%d , &a, &b, &c); n     to[a] = b; n     in[b] = 1; n     cs[a] = c; n   } n   int tot = 0; n   for (int(i) = (1); (i) < (n + 1); ++(i)) n     if (in[i] == 0 && to[i] != 0) tot++; n   printf( %d n , tot); n   for (int(i) = (1); (i) < (n + 1); ++(i)) n     if (in[i] == 0 && to[i] != 0) { n       int x = i, ans = inf; n       while (to[x]) { n         ans = min(ans, cs[x]); n         x = to[x]; n       } n       printf( %d %d %d n , i, x, ans); n     } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 6001; n int n, m, k, a, b, x[N], y[N], z[N]; n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) scanf( %d , &x[i]); n   scanf( %d , &m); n   for (int i = 1; i <= m; i++) scanf( %d , &y[i]); n   scanf( %d , &k); n   for (int i = 1; i <= k; i++) scanf( %d , &z[i]); n   scanf( %d%d , &a, &b); n   sort(x + 1, x + 1 + n); n   sort(y + 1, y + 1 + m); n   sort(z + 1, z + 1 + k); n   double p2 = z[1]; n   double r1 = x[n]; n   double res = 0; n   for (int i = 1; i <= m; i++) { n     double p1 = y[i]; n     double cur = (p1 * b * r1 * r1) / (p1 * b + p2 * a); n     cur = sqrt(cur); n     if (cur - res > 1e-6) res = cur; n   } n   printf( %.7f n , res); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, a[52][52], d[52], dd[52], c[52], b[52][52]; n bool check(int pos) { n   int t[n + 2]; n   for (int i = 1; i <= n; i++) t[i] = d[i]; n   for (int i = 1; i <= n; i++) n     if (t[i] == n && i != pos) t[i] = n - 1; n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= n; j++) { n       if (i == j) n         b[i][j] = 0; n       else { n         b[i][j] = min(t[i], t[j]); n       } n     } n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= n; j++) n       if (a[i][j] != b[i][j]) return 0; n   return 1; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cin >> n; n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= n; j++) cin >> a[i][j]; n   for (int i = 1; i <= n; i++) { n     for (int j = 0; j < n + 1; j++) dd[j] = 0; n     for (int j = 1; j <= n; j++) dd[a[i][j]] = 1; n     if (dd[n - 1] == 1) { n       c[n] = 1; n       d[i] = n; n     } n     if (d[i]) continue; n     for (int j = 0; j < n + 1; j++) { n       if (dd[j] == 0 && c[j - 1] == 0) { n         c[j - 1] = 1; n         d[i] = j - 1; n         break; n       } n     } n   } n   int pos = -1; n   for (int i = 1; i <= n; i++) { n     if (d[i] == n) { n       if (check(i)) { n         pos = i; n         break; n       } n     } n   } n   for (int i = 1; i <= n; i++) n     if (d[i] == n && i != pos) d[i] = n - 1; n   for (int i = 1; i <= n; i++) cout << d[i] <<    ; n } n


#include <bits/stdc++.h> n using namespace std; n int const MAX_N = 1e5 + 10; n int n, p, l[MAX_N], r[MAX_N]; n int get_count(int l, int r) { n   int ans = 0; n   if (l % p == 0) ++ans; n   l -= l % p; n   r -= r % p; n   ans += (r - l) / p; n   return ans; n } n double get_prob(int a, int b) { n   long long count = 0; n   count += n       1LL * get_count(l[a], r[a]) * (r[b] - l[b] + 1 - get_count(l[b], r[b])); n   count += n       1LL * get_count(l[b], r[b]) * (r[a] - l[a] + 1 - get_count(l[a], r[a])); n   count += 1LL * get_count(l[a], r[a]) * get_count(l[b], r[b]); n   return count * 1.0 / (1LL * (r[a] - l[a] + 1) * (r[b] - l[b] + 1)); n } n int main() { n   ios_base::sync_with_stdio(false); n   cout << fixed << setprecision(12); n   cin >> n >> p; n   for (int i = 0; i < n; ++i) cin >> l[i] >> r[i]; n   double ret = 0; n   for (int i = 0; i < n; ++i) { n     int j = (i + 1) % n; n     ret += 2000.0 * get_prob(i, j); n   } n   cout << ret << endl; n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( unroll-loops ) n #pragma GCC optimize( Ofast ) n using namespace std; n signed main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int n; n   long double u; n   cin >> n >> u; n   vector<long double> e(n); n   for (int i = 0; i < n; i++) cin >> e[i]; n   long double ans = 0; n   bool fl = 0; n   for (int i = 2; i < n; i++) { n     if (e[i] - e[i - 2] <= u) fl = 1; n   } n   if (!fl) { n     cout <<  -1  << endl; n     return 0; n   } n   for (int i = 0; i < n; i++) { n     int tmp = upper_bound(e.begin(), e.end(), e[i] + u) - e.begin() - 1; n     if (tmp - i < 2) continue; n     ans = max(ans, (e[tmp] - e[i + 1]) / (e[tmp] - e[i])); n   } n   cout << fixed << setprecision(13) << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int m, e[10][10] = {}, a, b; n   scanf( %d , &m); n   while (m--) { n     scanf( %d%d , &a, &b); n     e[a][b] = e[b][a] = 1; n   } n   for (int i = 1; i <= 5; i++) n     for (int j = i + 1; j <= 5; j++) n       for (int k = j + 1; k <= 5; k++) n         if (e[i][j] == e[j][k] && e[j][k] == e[k][i]) { n           puts( WIN ); n           return 0; n         } n   puts( FAIL ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n; n struct node { n   long long x, y; n } po[100000]; n inline long long dis(node a, node b) { n   return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y); n } n bool cmp(const node &a, const node &b) { n   return (a.y == b.y ? a.x < b.x : a.y < b.y); n } n long long solve(long long ll, long long rr) { n   if (ll == rr) return (long long)2e18; n   if (ll + 1 == rr) return dis(po[ll], po[rr]); n   if (ll + 2 == rr) n     return min(dis(po[ll], po[rr]), n                min(dis(po[ll], po[ll + 1]), dis(po[ll + 1], po[rr]))); n   long long mid = (ll + rr) >> 1; n   long long res = min(solve(ll, mid), solve(mid + 1, rr)); n   sort(po + ll, po + rr + 1, cmp); n   for (long long i = ll; i <= rr; ++i) { n     for (long long j = i + 1; j <= rr && j <= i + 8; ++j) n       res = min(res, dis(po[i], po[j])); n   } n   return res; n } n int main() { n   scanf( %I64d , &n); n   for (long long i = 1; i <= n; ++i) n     scanf( %I64d , &po[i].y), po[i].y += po[i - 1].y, po[i].x = i; n   printf( %I64d n , solve(1, n)); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n inline void read(T &x) { n   x = 0; n   char c = getchar(); n   int f = 1; n   while (!isdigit(c)) { n     if (c ==  - ) f = -1; n     c = getchar(); n   } n   while (isdigit(c)) { n     x = x * 10 + c -  0 ; n     c = getchar(); n   } n   x *= f; n } n template <class T> n T gcd(T a, T b) { n   return !b ? a : gcd(b, a % b); n } n template <class T> n inline void cmin(T &x, T y) { n   x = x < y ? x : y; n } n template <class T> n inline void cmax(T &x, T y) { n   x = x > y ? x : y; n } n const int N = 100010; n int n, q, head[N], nxt[N], v[N], cnt, son[N], top[N], si[N], wp[N], totw, id[N], n     fa[N]; n inline void add(int x, int y) { n   nxt[++cnt] = head[x]; n   head[x] = cnt; n   v[cnt] = y; n } n struct seg { n   int l, r, sum, sufma, al; n } t[N << 2]; n void dfs(int now) { n   int mx = -1; n   si[now] = 1; n   for (register int i = head[now]; i; i = nxt[i]) { n     dfs(v[i]); n     si[now] += si[v[i]]; n     if (si[v[i]] > mx) son[now] = v[i]; n   } n } n void _dfs(int now, int tf) { n   top[now] = tf; n   wp[now] = ++totw; n   id[totw] = now; n   if (!son[now]) return; n   _dfs(son[now], tf); n   for (register int i = head[now]; i; i = nxt[i]) { n     if (son[now] != v[i]) _dfs(v[i], v[i]); n   } n } n void merge(seg &a, seg b, seg c) { n   a.sum = b.sum + c.sum; n   a.sufma = max(c.sufma, c.sum + b.sufma); n } n void build(int p, int l, int r) { n   t[p].l = l; n   t[p].r = r; n   if (l == r) { n     t[p].sum = t[p].sufma = -1; n     return; n   } n   int mid = (l + r) >> 1; n   build(p << 1, l, mid); n   build(p << 1 | 1, mid + 1, r); n   merge(t[p], t[p << 1], t[p << 1 | 1]); n } n void pushdown(int p) { n   if (t[p].al != 0) { n     t[p << 1].al = t[p << 1 | 1].al = t[p].al; n     t[p << 1].sum = (t[p << 1].r - t[p << 1].l + 1) * t[p << 1].al; n     t[p << 1 | 1].sum = n         (t[p << 1 | 1].r - t[p << 1 | 1].l + 1) * t[p << 1 | 1].al; n     t[p << 1].sufma = t[p << 1 | 1].sufma = -1; n     t[p].al = 0; n   } n } n void change(int p, int x, int dt) { n   if (t[p].l == t[p].r) { n     t[p].sufma += dt; n     t[p].sum += dt; n     return; n   } n   pushdown(p); n   int mid = (t[p].l + t[p].r) >> 1; n   if (x <= mid) n     change(p << 1, x, dt); n   else n     change(p << 1 | 1, x, dt); n   merge(t[p], t[p << 1], t[p << 1 | 1]); n } n void modify(int p, int l, int r, int dt) { n   if (t[p].l >= l && t[p].r <= r) { n     t[p].al = dt; n     t[p].sum = (t[p].r - t[p].l + 1) * t[p].al; n     t[p].sufma = -1; n     return; n   } n   pushdown(p); n   int mid = (t[p].l + t[p].r) >> 1; n   if (l <= mid) modify(p << 1, l, r, dt); n   if (r > mid) modify(p << 1 | 1, l, r, dt); n   merge(t[p], t[p << 1], t[p << 1 | 1]); n } n seg maxsuf(int p, int l, int r) { n   if (t[p].l >= l && t[p].r <= r) { n     return t[p]; n   } n   pushdown(p); n   int mid = (t[p].l + t[p].r) >> 1; n   if (r <= mid) return maxsuf(p << 1, l, r); n   if (l > mid) return maxsuf(p << 1 | 1, l, r); n   seg tmp; n   merge(tmp, maxsuf(p << 1, l, r), maxsuf(p << 1 | 1, l, r)); n   return tmp; n } n int query(int x) { n   seg res = maxsuf(1, wp[top[x]], wp[x]); n   x = fa[top[x]]; n   while (x) { n     merge(res, maxsuf(1, wp[top[x]], wp[x]), res); n     x = fa[top[x]]; n   } n   return res.sufma; n } n int main() { n   read(n); n   read(q); n   for (register int i = (2); i <= (n); i++) { n     read(fa[i]); n     add(fa[i], i); n   } n   dfs(1); n   _dfs(1, 1); n   build(1, 1, n); n   for (register int i = (1); i <= (q); i++) { n     int opt, x; n     read(opt); n     read(x); n     if (opt == 1) { n       change(1, wp[x], 1); n     } else if (opt == 2) { n       modify(1, wp[x], wp[x] + si[x] - 1, -1); n       change(1, wp[x], -(query(x) + 1)); n     } else { n       if (query(x) >= 0) { n         printf( black n ); n       } else { n         printf( white n ); n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char c[200010]; n int main() { n   int n; n   while (scanf( %d , &n) != EOF) { n     memset(c, 0, sizeof c); n     scanf( %s , c); n     int ans = 0; n     for (int i = 0; i < n; i++) { n       if (c[i] ==  < ) n         ans++; n       else n         break; n     } n     for (int i = n - 1; i >= 0; i--) { n       if (c[i] ==  > ) n         ans++; n       else n         break; n     } n     printf( %d n , ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 505; n int a[N]; n int z[2][N][N]; n int main() { n   int n, bl, bugs, md; n   scanf( %d %d %d %d , &n, &bl, &bugs, &md); n   for (int i = 0; i < int(n); i++) scanf( %d , &a[i]); n   z[0][0][0] = 1; n   for (int it = 1; it <= n; it++) { n     int i = it & 1; n     for (int j = 0; j <= bl; j++) { n       for (int k = 0; k <= bugs; k++) { n         z[i][j][k] = z[i ^ 1][j][k]; n         if (j > 0 && k >= a[it - 1]) z[i][j][k] += z[i][j - 1][k - a[it - 1]]; n         z[i][j][k] %= md; n       } n     } n   } n   int ans = 0; n   for (int i = 0; i <= bugs; i++) { n     ans += z[n & 1][bl][i]; n     ans %= md; n   } n   printf( %d n , ans); n } n


#include <bits/stdc++.h> n #pragma GCC optimize( Ofast ) n #pragma GCC optimize( inline ) n #pragma GCC optimize( omit-frame-pointer ) n #pragma GCC optimize( unroll-loops ) n using namespace std; n template <class T> n void debug(vector<T> vec) { n   for (int i = 0; i < vec.size(); i++) cerr << vec[i] <<    ; n   cerr <<   n ; n } n template <class T> n void debug(vector<vector<T> > vec) { n   for (int i = 0; i < vec.size(); i++) { n     for (int ii = 0; ii < vec[i].size(); ii++) cerr << vec[i][ii] <<    ; n     cerr <<   n ; n   } n } n void solve() { n   int T; n   int i; n   cin >> T; n   for (int i = 0; i < T; i++) { n     int n; n     string s; n     cin >> n; n     cin >> s; n     if (s.size() == 1) { n       cout <<  YES  n            <<   n ; n       continue; n     } else if (s.size() == 2) { n       if (abs(s[0] - s[1]) > 2 || abs(s[0] - s[1]) == 1) n         cout <<  NO  n              <<   n ; n       else n         cout <<  YES  n              <<   n ; n       continue; n     } n     int x; n     bool possible = true; n     for (int x = 0; x < n / 2; x++) { n       if (abs(s[x] - s[n - x - 1]) > 2 || abs(s[x] - s[n - x - 1]) == 1) { n         possible = false; n         cout <<  NO  n              <<   n ; n         break; n       } n     } n     if (possible == true) n       cout <<  YES  n            <<   n ; n   } n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(NULL); n   ; n   cin.tie(NULL); n   int testcases = 1; n   while (testcases-- != 0) { n     solve(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const double eps = 1E-9; n int cnt; n double a, b, m, vx, vy, vz, t, f; n double ansx, ansz; n int main() { n   scanf( %lf%lf%lf , &a, &b, &m); n   scanf( %lf%lf%lf , &vx, &vy, &vz); n   t = -m / vy; n   ansx = a / 2 + t * vx; n   ansz = t * vz; n   while (ansx < 0) ansx += a; n   while (ansz < 0) ansz += b; n   while (ansx + eps > a) ansx -= a; n   while (ansz + eps > b) ansz -= b; n   cnt = (int)(fabs(t / (b / vz)) + eps); n   if (cnt % 2) ansz = b - ansz; n   cnt = 0; n   if (t + eps > fabs((a / 2) / vx)) { n     cnt = 1; n     t -= fabs(a / 2 / vx); n   } n   cnt += (int)(fabs(t / (a / vx)) + eps); n   if (cnt % 2) ansx = a - ansx; n   printf( %.10lf %.10lf n , ansx, ansz); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class _T> n inline _T sqr(const _T& first) { n   return first * first; n } n template <class _T> n inline string tostr(const _T& a) { n   ostringstream os(  ); n   os << a; n   return os.str(); n } n const long double PI = 3.1415926535897932384626433832795L; n const long double EPS = 5e-12; n char TEMPORARY_CHAR; n const int INF = 1e9; n inline void input(int& a) { n   a = 0; n   while (((TEMPORARY_CHAR = getchar()) >  9  || TEMPORARY_CHAR <  0 ) && n          (TEMPORARY_CHAR !=  - )) { n   } n   char neg = 0; n   if (TEMPORARY_CHAR ==  - ) { n     neg = 1; n     TEMPORARY_CHAR = getchar(); n   } n   while (TEMPORARY_CHAR <=  9  && TEMPORARY_CHAR >=  0 ) { n     a = 10 * a + TEMPORARY_CHAR -  0 ; n     TEMPORARY_CHAR = getchar(); n   } n   if (neg) a = -a; n } n inline void out(int a) { n   if (!a) putchar( 0 ); n   if (a < 0) { n     putchar( - ); n     a = -a; n   } n   char s[10]; n   int i; n   for (i = 0; a; ++i) { n     s[i] =  0  + a % 10; n     a /= 10; n   } n   for (int j = (i)-1; j >= 0; j--) putchar(s[j]); n } n inline int nxt() { n   int(ret); n   input((ret)); n   ; n   return ret; n } n char can[8][8]; n bool check(const vector<int>& a) { n   for (int i : a) n     for (int j : a) n       if (!can[i][j]) return false; n   return true; n } n int main() { n   long long n; n   cin >> n; n   long long tri = 1; n   while (n % tri == 0) tri *= 3; n   cout << (n + tri - 1) / tri << endl; 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 double eps = 1e-12; n const double PI = acos(-1.0); n const int mod = 998244353; n int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } n long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } n int ar[100050]; n void solve() { n   int n, k; n   cin >> n >> k; n   bool exi = false, gp = false; n   for (int i = 1; i <= n; i++) { n     cin >> ar[i]; n     if (ar[i] == k) exi = true; n   } n   for (int i = 1; i < n; i++) { n     if (ar[i] >= k && (ar[i + 1] >= k || i < n - 1 && ar[i + 2] >= k)) { n       gp = true; n       break; n     } n   } n   if (n == 1 && ar[1] == k || exi && gp) 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   cout.tie(0); n   int T; n   cin >> T; n   for (int t = 1; t <= T; t++) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool isprime(long long int n) { n   if (n <= 1) return false; n   if (n <= 3) return true; n   if (n % 2 == 0 || n % 3 == 0) return false; n   for (int i = 5; i * i <= n; i = i + 6) n     if (n % i == 0 || n % (i + 2) == 0) return false; n   return true; n } n vector<long long int> prime; n void sieve(long long int n) { n   bool bakh[n + 1]; n   memset(bakh, true, sizeof(bakh)); n   for (long long int p = 2; p * p <= n; p++) { n     if (bakh[p] == true) { n       for (long long int i = p * p; i <= n; i += p) bakh[i] = false; n     } n   } n   for (long long int p = 2; p <= n; p++) n     if (bakh[p]) prime.push_back(p); n } n long long int eulertotient(long long int z) { n   long long int fac = z; n   for (long long int i = 0; prime[i] * prime[i] <= z; i++) { n     if (z % prime[i] == 0) { n       fac -= (fac / prime[i]); n       while (z % prime[i] == 0) z /= prime[i]; n     } n   } n   if (z > 1) fac -= (fac / z); n   return fac; n } n long long int power(long long int x, long long int y, long long int p) { n   long long int res = 1; n   x = x % p; n   while (y > 0) { n     if (y & 1) res = (res * x) % p; n     y = y >> 1; n     x = (x * x) % p; n   } n   return res; n } n long long int gcd(long long int a, long long int b) { n   if (a == 0) return b; n   return gcd(b % a, a); n } n long long int lcm(long long int a, long long int b) { n   long long int g = gcd(a, b); n   long long int ans = (a * b) / g; n   return ans; n } n long long int modInverse(long long int a, long long int m) { n   long long int hvf = gcd(a, m); n   if (hvf == 1) return power(a, m - 2, m); n   return -1; n } n void multiply(long long int F[2][2], long long int M[2][2]) { n   long long int x = F[0][0] * M[0][0] + F[0][1] * M[1][0]; n   long long int y = F[0][0] * M[0][1] + F[0][1] * M[1][1]; n   long long int z = F[1][0] * M[0][0] + F[1][1] * M[1][0]; n   long long int w = F[1][0] * M[0][1] + F[1][1] * M[1][1]; n   F[0][0] = x; n   F[0][1] = y; n   F[1][0] = z; n   F[1][1] = w; n } n void powermat(long long int F[2][2], long long int n) { n   if (n == 0 || n == 1) return; n   long long int M[2][2] = {{1, 1}, {1, 0}}; n   powermat(F, n / 2); n   multiply(F, F); n   if (n % 2 != 0) multiply(F, M); n } n long long int fib(long long int n) { n   long long int F[2][2] = {{1, 1}, {1, 0}}; n   if (n == 0) return 0; n   powermat(F, n - 1); n   return F[0][0]; n } n vector<long long int> merge(vector<long long int> v1, n                             vector<long long int> v2) { n   vector<long long int> temp; n   long long int i = 0, j = 0; n   while (i < v1.size() && j < v2.size()) { n     if (v1[i] < v2[j]) n       temp.push_back(v1[i]), i++; n     else n       temp.push_back(v2[j]), j++; n   } n   while (i < v1.size()) temp.push_back(v1[i]), i++; n   while (j < v2.size()) temp.push_back(v2[j]), j++; n   return temp; n } n long long int mp[2][300005], n; n long long int ar[2][300005], dp[2][300005], pre[2][300005]; n long long int fun(long long int id, long long int curr) { n   if (id == n + 1) return 0; n   if (mp[curr][id] != -1) return mp[curr][id]; n   long long int t = 2 * (id - 1), a = 0; n   if (id % 2 == 1) { n     if (curr == 0) n       a = max(ar[curr][id] * t + fun(id, 1), dp[curr][id] + t * pre[curr][id]); n     else n       a = ((t + 1) * ar[curr][id]) + fun(id + 1, curr); n   } else { n     if (curr == 1) n       a = max(ar[curr][id] * t + fun(id, 0), n               dp[curr][id] + t * (pre[curr][id])); n     else n       a = (ar[curr][id] * (t + 1)) + fun(id + 1, curr); n   } n   return mp[curr][id] = a; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   ; n   cin >> n; n   for (long long int i = 1; i <= n; i++) cin >> ar[0][i]; n   for (long long int i = 1; i <= n; i++) cin >> ar[1][i]; n   memset(dp, 0, sizeof(dp)); n   memset(pre, 0, sizeof(pre)); n   for (long long int i = n; i >= 1; i--) { n     dp[0][i] = dp[0][i + 1] + pre[0][i + 1] + ar[1][i] * (2 * (n - i + 1) - 1); n     dp[1][i] = dp[1][i + 1] + pre[1][i + 1] + ar[0][i] * (2 * (n - i + 1) - 1); n     pre[0][i] = pre[0][i + 1] + ar[0][i] + ar[1][i]; n     pre[1][i] = pre[1][i + 1] + ar[0][i] + ar[1][i]; n   } n   memset(mp, -1, sizeof(mp)); n   long long int ans = fun(1, 0); n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 5255; n long long n, m; n long long a[N], b[N]; n long long ans[N], rec[N]; n inline long long gt(long long u) { n   long long flg = u < 0 ? -1 : 1; n   u = u * flg; n   for (long long i = 2; i * i <= u; ++i) { n     while (u % (i * i) == 0) u = u / (i * i); n   } n   return u * flg; n } n signed main() { n   cin >> n; n   for (long long i = 1; i <= n; ++i) { n     scanf( %lld , &a[i]); n     a[i] = b[i] = gt(a[i]); n   } n   sort(b + 1, b + n + 1); n   m = unique(b + 1, b + n + 1) - b - 1; n   for (long long i = 1; i <= n; ++i) { n     if (a[i] != 0) a[i] = lower_bound(b + 1, b + m + 1, a[i]) - b + 1; n   } n   for (long long i = 1; i <= n; ++i) { n     long long cnt = 0; n     bool flag = 1; n     memset(rec, 0, sizeof(rec)); n     for (long long j = i; j <= n; ++j) { n       if (flag == 0) { n         if (a[j] == 0) n           ; n         else { n           if (rec[a[j]] == 0) cnt++; n         } n       } else { n         if (i == j) { n           if (a[j] != 0) n             flag = 0, cnt++; n           else n             cnt++; n         } else { n           if (a[j] != 0) n             flag = 0; n           else n             ; n         } n       } n       rec[a[j]] = 1; n       ans[cnt]++; n     } n   } n   for (long long i = 1; i <= n; ++i) { n     printf( %lld  , ans[i]); n   } n   puts(  ); n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 200000 + 10; n const long long M = 1000000 + 10; n const long long INF = (long long)1e9 + 10; n long long n, m; n long long tl[N], tr[N]; n map<long long, long long> toX; n pair<long long, long long> a[N]; n pair<pair<long long, long long>, pair<long long, int> > b[N]; n long long preMax[M], sufMin[M], midMax[M]; n long long queryMax(long long *c, long long p) { n   long long ret = 0; n   for (p++; p; p -= p & -p) { n     ret = max(ret, c[p]); n   } n   return ret; n } n long long queryMin(long long p) { n   long long ret = INF; n   for (p++; p; p -= p & -p) { n     ret = min(ret, sufMin[p]); n   } n   return ret; n } n void addMax(long long *c, long long p, long long value) { n   for (p++; p < M; p += p & -p) { n     c[p] = max(c[p], value); n   } n } n void addMin(long long p, long long value) { n   for (p++; p < M; p += p & -p) { n     sufMin[p] = min(sufMin[p], value); n   } n } n void solve() { n   cin >> n >> m; n   vector<long long> values; n   for (long long i = 0; i < n; ++i) { n     int x, y; n     scanf( %d%d , &x, &y); n     tl[i] = x; n     tr[i] = y; n     a[i].first = x; n     a[i].second = y; n     values.push_back(a[i].first); n     values.push_back(a[i].second); n   } n   for (long long i = 0; i < m; ++i) { n     int x, y, d; n     scanf( %d%d%d , &x, &y, &d); n     b[i].first.first = x; n     b[i].first.second = y; n     b[i].second.first = d; n     b[i].second.second = i; n     values.push_back(b[i].first.first); n     values.push_back(b[i].first.second); n   } n   sort(values.begin(), values.end()); n   values.erase(unique(values.begin(), values.end()), values.end()); n   for (long long i = 0; i < values.size(); ++i) { n     toX[values[i]] = i; n   } n   fill(preMax, preMax + M, -1); n   fill(sufMin, sufMin + M, INF); n   fill(midMax, midMax + M, 0); n   for (long long i = 0; i < n; ++i) { n     long long l = toX[a[i].first]; n     long long r = toX[a[i].second]; n     addMax(preMax, l, a[i].second); n     addMin(M - r - 100, a[i].first); n   } n   sort(a, a + n); n   sort(b, b + m); n   long long ret = 0; n   long long ptr = n - 1; n   int rc = -1, rcc; n   for (long long i = m - 1; i >= 0; --i) { n     for (; ptr >= 0 && a[ptr].first >= b[i].first.first; ptr--) { n       addMax(midMax, toX[a[ptr].second], a[ptr].second - a[ptr].first); n     } n     long long maxLen = 0; n     maxLen = queryMax(midMax, toX[b[i].first.second]); n     maxLen = n         max(maxLen, queryMax(preMax, toX[b[i].first.first]) - b[i].first.first); n     maxLen = max( n         maxLen, b[i].first.second - queryMin(M - toX[b[i].first.second] - 100)); n     maxLen = min(maxLen, b[i].first.second - b[i].first.first); n     if (ret < maxLen * b[i].second.first) { n       ret = maxLen * b[i].second.first; n       rc = b[i].second.second; n       rcc = i; n     } n   } n   cout << ret << endl; n   if (ret == 0) { n     return; n   } n   for (int i = 0; i < n; ++i) { n     long long nl = max(tl[i], b[rcc].first.first); n     long long nr = min(tr[i], b[rcc].first.second); n     if (nl > nr) continue; n     if ((nr - nl) * b[rcc].second.first == ret) { n       cout << i + 1 <<     << rc + 1 << endl; n       return; n     } n   } n } n int main() { n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, d; n   cin >> n >> d; n   int m; n   cin >> m; n   for (int i = 0; i < m; i++) { n     int x, y; n     cin >> x >> y; n     if (x + y - d >= 0 && x - y - d <= 0 && x - y + d >= 0 && n         x + y - 2 * n + d <= 0) { n       cout <<  YES n ; n     } else { n       cout <<  NO n ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int T = 1; n   while (T--) { n     long long a, b, s; n     cin >> a >> b >> s; n     s = s - abs(a) - abs(b); n     if (s % 2 == 0 && s >= 0) n       cout <<  Yes ; n     else n       cout <<  No ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long n, k; n long long quickpow(long long x, long long y) { n   long long res = 1; n   for (; y; y >>= 1, x *= x, x %= 1000003) n     if (y & 1) res *= x, res %= 1000003; n   return res; n } n int main() { n   scanf( %I64d %I64d , &n, &k); n   if (n < 62 && k > (1LL << n)) n     printf(  1 1 n ); n   else { n     long long A = 1, t = quickpow(2, n), cnt = n; n     for (int y = 1; y < 62; y++) cnt += (k - 1) / (1LL << y); n     if (k < 1000003) { n       for (long long i = 1; i <= k; i++) n         A = A * (t - i + 1000003 + 1) % 1000003; n       A = A * quickpow(quickpow(2, 1000003 - 2), cnt) % 1000003; n     } else n       A = 0; n     long long B = quickpow(quickpow(2, n), k) * n                   quickpow(quickpow(2, 1000003 - 2), cnt) % 1000003; n     printf( %I64d %I64d n , (B - A + 1000003) % 1000003, B); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n; n int x[100005], y[100005], num_, num; n int main() { n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> x[i] >> y[i]; n     if (x[i] > 0) { n       num++; n     } else { n       num_++; n     } n   } n   if (num == 1 || num_ == 1 || num == 0 || num_ == 0) { n     cout <<  Yes  << endl; n     return 0; n   } else { n     cout <<  No  << endl; n     return 0; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long power(long long b, long long e, long long m) { n   if (e == 0) return 1; n   if (e & 1) return b * power(b * b % m, e / 2, m) % m; n   return power(b * b % m, e / 2, m); n } n long long power(long long b, long long e) { n   if (e == 0) return 1; n   if (e & 1) return b * power(b * b, e / 2); n   return power(b * b, e / 2); n } n int _runtimeTerror_() { n   long long n; n   cin >> n; n   long long i, a[n], b[n]; n   for (i = 0; i < n; ++i) cin >> a[i]; n   for (i = 0; i < n; ++i) cin >> b[i]; n   long long ans = 0; n   long long arr[n]; n   for (i = 0; i < n; ++i) { n     arr[i] = a[i] * (i + 1) * (n - i); n   } n   sort(arr, arr + n, greater<long long>()); n   sort(b, b + n); n   for (i = 0; i < n; ++i) { n     ans += (b[i] * (arr[i] % 998244353)) % 998244353; n     ans %= 998244353; n   } n   cout << ans <<   n ; n   return 0; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int TESTS = 1; n   while (TESTS--) _runtimeTerror_(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long f(long long n) { n   long long t = n; n   for (long long i = 2; i * i <= n; i++) n     if (n % i == 0) { n       t = t / i * (i - 1); n       while (n % i == 0) n /= i; n     } n   if (n > 1) t = t / n * (n - 1); n   return t; n } n int main() { n   long long n, k; n   cin >> n >> k; n   for (long long i = 1; i <= k && n > 1; i += 2) n = f(n); n   printf( %I64d n , n % 1000000007); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n string parse(string str) { n   string returnme; n   for (int i = 0; i < str.length(); i++) { n     if (str[i] ==  _  || str[i] ==  ;  || str[i] ==  - ) { n     } else { n       returnme.push_back(tolower(str[i])); n     } n   } n   return returnme; n } n int main() { n   string con1, con2, con3; n   cin >> con1 >> con2 >> con3; n   con1 = parse(con1); n   con2 = parse(con2); n   con3 = parse(con3); n   int n; n   cin >> n; n   vector<string> con; n   con.push_back(con1 + con2 + con3); n   con.push_back(con1 + con3 + con2); n   con.push_back(con3 + con2 + con1); n   con.push_back(con2 + con3 + con1); n   con.push_back(con2 + con1 + con3); n   con.push_back(con3 + con1 + con2); n   for (int i = 0; i < n; i++) { n     string str; n     cin >> str; n     str = parse(str); n     bool acc = false; n     for (int j = 0; j < 6; j++) { n       if (str == con[j]) { n         cout <<  ACC  << endl; n         acc = true; n         break; n       } n     } n     if (acc == false) { n       cout <<  WA  << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   int foot = 0; n   int inch = 0; n   int q, o; n   if (n < 35) { n     if (n == 2) { n       inch++; n     } else n       for (int e = 1; e < n; e = e + 3) { n         inch++; n       } n   } else if (n == 35 || n == 36) { n     foot++; n   } else if (n > 36) { n     if (n == 37) { n       inch = 0; n     } else if (n == 38) { n       inch++; n     } else if (n > 38) { n       for (int z = 36; z <= n; z = z + 36) { n         foot++; n         if (z - n == 2 || z - n == 1) { n           ; n         } n         q = z; n         o = n - q; n       } n       for (int i = 3; i <= o; i = i + 3) { n         inch++; n         if (o - i == 2) { n           inch++; n         } n       } n     } n   } n   if (inch == 12) { n     inch = 0; n     foot++; n   } n   cout << foot <<     << inch; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MOD = (int)1e9 + 7; n const int FFTMOD = 1007681537; n const int INF = (int)1e9; n const long long LINF = (long long)1e18; n const long double PI = acos((long double)-1); n const long double EPS = 1e-9; n inline long long gcd(long long a, long long b) { n   long long r; n   while (b) { n     r = a % b; n     a = b; n     b = r; n   } n   return a; n } n inline long long lcm(long long a, long long b) { return a / gcd(a, b) * b; } n inline long long fpow(long long n, long long k, int p = MOD) { n   long long r = 1; n   for (; k; k >>= 1) { n     if (k & 1) r = r * n % p; n     n = n * n % p; n   } n   return r; n } n template <class T> n inline int chkmin(T& a, const T& val) { n   return val < a ? a = val, 1 : 0; n } n template <class T> n inline int chkmax(T& a, const T& val) { n   return a < val ? a = val, 1 : 0; n } n inline long long isqrt(long long k) { n   long long r = sqrt(k) + 1; n   while (r * r > k) r--; n   return r; n } n inline long long icbrt(long long k) { n   long long r = cbrt(k) + 1; n   while (r * r * r > k) r--; n   return r; n } n inline void addmod(int& a, int val, int p = MOD) { n   if ((a = (a + val)) >= p) a -= p; n } n inline void submod(int& a, int val, int p = MOD) { n   if ((a = (a - val)) < 0) a += p; n } n inline int mult(int a, int b, int p = MOD) { return (long long)a * b % p; } n inline int inv(int a, int p = MOD) { return fpow(a, p - 2, p); } n inline int sign(long double x) { return x < -EPS ? -1 : x > +EPS; } n inline int sign(long double x, long double y) { return sign(x - y); } n const int maxn = 50 + 5; n int n, p; n int c[maxn]; n int f[maxn][maxn]; n int p2[maxn]; n int dp[maxn][maxn][maxn][2]; n int calc(int pos, int u, int v, int fa) { n   if (pos == n) return fa == p; n   int& res = dp[pos][u][v][fa]; n   if (~res) return res; n   res = 0; n   for (int i = (0); i < (2); ++i) { n     int num = c[pos] == -1 || c[pos] == i; n     if (!num) continue; n     int ar[] = {u, v}; n     for (int j = (0); j < (ar[i ^ 1] + 1); ++j) { n       int add = j + 1 & 1; n       ar[i] += add; n       int nfa = fa + j + 1 & 1; n       addmod(res, n              mult(p2[pos - ar[i ^ 1]], n                   mult(f[j][ar[i ^ 1]], calc(pos + 1, ar[0], ar[1], nfa)))); n       ar[i] -= add; n     } n   } n   return res; n } n void chemthan() { n   for (int i = (0); i < (maxn); ++i) f[0][i] = 1; n   for (int i = (1); i < (maxn); ++i) n     for (int j = (1); j < (maxn); ++j) n       f[i][j] = (f[i][j - 1] + f[i - 1][j - 1]) % MOD; n   for (int i = (0); i < (maxn); ++i) p2[i] = fpow(2, i); n   cin >> n >> p; n   for (int i = (0); i < (n); ++i) cin >> c[i]; n   memset(dp, -1, sizeof(dp)); n   cout << calc(0, 0, 0, 0) <<   n ; n } n int main(int argc, char* argv[]) { n   ios_base::sync_with_stdio(0), cin.tie(0); n   if (argc > 1) { n     assert(freopen(argv[1],  r , stdin)); n   } n   if (argc > 2) { n     assert(freopen(argv[2],  wb , stdout)); n   } n   chemthan(); n   cerr <<   nTime elapsed:   << 1000 * clock() / CLOCKS_PER_SEC <<  ms n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long mx = 3e5 + 66; n const long long mod = 1e9 + 7; n const long long inf = 8e18 + 66; n const int llg = 25; n const long long mxk = 31700000; n long long power(long long a, long long b, long long md) { n   if (b == 0) return 1; n   long long c = power(a, b / 2, md); n   if (b % 2) n     return c * c % md * a % md; n   else n     return c * c % md; n } n int n, a[mx], la[mx], ra[mx], rmq[2][llg][mx], val[2][mx], lga[mx], l[llg][mx], n     r[llg][mx]; n int cmx(int x, int y, int b) { n   if (val[b][x] < val[b][y]) return y; n   return x; n } n void build(int b) { n   for (int i = 1; i < 3 * n + 1; i++) { n     rmq[b][0][i] = i; n     if (b == 0) n       val[b][i] = -la[i]; n     else n       val[b][i] = ra[i]; n   } n   for (int i = 1; i < lga[3 * n] + 1; i++) n     for (int j = 1; j + (1 << i) - 1 <= 3 * n; j++) { n       rmq[b][i][j] = n           cmx(rmq[b][i - 1][j], rmq[b][i - 1][j + (1 << (i - 1))], b); n     } n } n int maxq(int x, int y, int b) { n   int k = lga[y - x + 1]; n   return cmx(rmq[b][k][x], rmq[b][k][y - (1 << k) + 1], b); n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   for (int i = 2; i < mx; i++) { n     lga[i] = lga[i / 2] + 1; n   } n   cin >> n; n   if (n == 1) { n     cout << 0; n     return 0; n   } n   for (int i = 1; i < n + 1; i++) { n     cin >> a[i]; n     a[i + n * 2] = a[i + n] = a[i]; n   } n   for (int i = 1; i < 3 * n + 1; i++) { n     la[i] = max(1, i - a[i]); n     ra[i] = min(3 * n, a[i] + i); n   } n   for (int i = 0; i < lga[3 * n] + 1; i++) { n     l[i][1] = 1; n     r[i][3 * n] = 3 * n; n   } n   for (int i = 1; i < 3 * n + 1; i++) { n     l[0][i] = la[i]; n     r[0][i] = ra[i]; n   } n   build(0); n   build(1); n   for (int i = 1; i < lga[n * 3] + 1; i++) { n     for (int j = 1; j < 3 * n + 1; j++) { n       int al = maxq(l[i - 1][j], r[i - 1][j], 0); n       int ar = maxq(l[i - 1][j], r[i - 1][j], 1); n       l[i][j] = min(l[i - 1][al], l[i - 1][ar]); n       r[i][j] = max(r[i - 1][al], r[i - 1][ar]); n     } n   } n   for (int i = n + 1; i < 2 * n + 1; i++) { n     int ans = 1, u = i, v = i; n     for (int j = lga[3 * n]; j >= 0; j--) { n       if (max(r[j][u], r[j][v]) - min(l[j][u], l[j][v]) < n - 1) { n         int al = maxq(l[j][u], r[j][v], 0); n         int ar = maxq(l[j][u], r[j][v], 1); n         u = al, v = ar, ans += (1 << j); n       } n     } n     cout << ans <<    ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int sizes = 200001; n int main() { n   long long int i, j, k, l, m, n, o, p, q, r, s, t, a[sizes], b[sizes], n       booked[1001]; n   cin >> n; n   o = 0; n   for (i = 0; i < n; i++) { n     cin >> a[i]; n     o = max(o, a[i]); n   } n   sort(a, a + n); n   memset(b, -1, sizeof(b)); n   for (i = 0; i < n; i++) { n     b[a[i]] = i; n   } n   long long int ans = 1; n   for (i = 2 * 1; i <= 2 * o; i++) { n     memset(booked, 0, sizeof(booked)); n     p = 0; n     for (j = 0; j < n; j++) { n       if (booked[j] == 0) { n         if ((i - a[j] > 0) && b[i - a[j]] != -1) { n           if (booked[b[i - a[j]]] == 0 && j != b[i - a[j]]) { n             booked[j] = 1; n             booked[b[i - a[j]]] = 1; n             p++; n           } n         } n       } n     } n     ans = max(ans, p); n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e3 + 10; n long long inf = 1e18; n set<pair<long long, pair<int, int> > > s; n vector<pair<pair<int, int>, long long> > vec; n long long dp[2][maxn][maxn], arr[maxn][maxn]; n long long ps[maxn][maxn]; n int n, m, a, b; n bool mark[maxn][maxn]; n void input() { n   ios::sync_with_stdio(0), cin.tie(0); n   cin >> n >> m >> a >> b; n   for (int i = 0; i < n; i++) n     for (int j = 0; j < m; j++) cin >> arr[i][j]; n } n void cal_ps() { n   for (int i = 0; i < n; i++) n     for (int j = 0; j < m; j++) n       ps[i + 1][j + 1] = ps[i][j + 1] + ps[i + 1][j] - ps[i][j] + arr[i][j]; n } n void cal_dp() { n   for (int i = 0; i < n; i++) n     for (int j = 0; j < m; j++) dp[0][i][j] = dp[1][i][j] = inf; n   for (int j = 0; j < m; j++) { n     deque<int> dq; n     for (int i = 0; i < a; i++) { n       while (!dq.empty() && arr[dq.back()][j] >= arr[i][j]) dq.pop_back(); n       dq.push_back(i); n     } n     dp[0][a - 1][j] = arr[dq.front()][j]; n     for (int i = a; i < n; i++) { n       while (!dq.empty() && arr[dq.back()][j] >= arr[i][j]) dq.pop_back(); n       dq.push_back(i); n       if (dq.front() == i - a) dq.pop_front(); n       dp[0][i][j] = arr[dq.front()][j]; n     } n   } n   for (int i = 0; i < n; i++) { n     deque<int> dq; n     for (int j = 0; j < b; j++) { n       while (!dq.empty() && dp[0][i][dq.back()] >= dp[0][i][j]) dq.pop_back(); n       dq.push_back(j); n     } n     dp[1][i][b - 1] = dp[0][i][dq.front()]; n     for (int j = b; j < m; j++) { n       while (!dq.empty() && dp[0][i][dq.back()] >= dp[0][i][j]) dq.pop_back(); n       dq.push_back(j); n       if (dq.front() == j - b) dq.pop_front(); n       dp[1][i][j] = dp[0][i][dq.front()]; n     } n   } n } n void init() { n   for (int i = a - 1; i < n; i++) n     for (int j = b - 1; j < m; j++) { n       long long sum = ps[i + 1][j + 1] - ps[i + 1][j + 1 - b] - n                       ps[i + 1 - a][j + 1] + ps[i + 1 - a][j + 1 - b] - n                       a * b * dp[1][i][j]; n       s.insert({sum, {i - a + 1, j - b + 1}}); n     } n } n bool valid(int x, int y) { n   if (mark[x][y]) return false; n   int xx = max(0, x - a + 1), yy = max(0, y - b + 1); n   for (int i = x + a - 1; i >= xx; i--) n     for (int j = y + b - 1; j >= yy; j--) mark[i][j] = true; n   return true; n } n int main() { n   input(); n   cal_ps(); n   cal_dp(); n   init(); n   while (!s.empty()) { n     auto tmp = *s.begin(); n     int x = tmp.second.first, y = tmp.second.second; n     long long p = tmp.first; n     if (valid(x, y)) vec.push_back({{x, y}, p}); n     s.erase(tmp); n   } n   cout << vec.size() <<   n ; n   for (auto tmp : vec) { n     cout << tmp.first.first + 1 <<     << tmp.first.second + 1 <<     n          << tmp.second <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 200010, X = 2000010, P = 1000000007; n int n, pc, ind; n bool vis[X], chose[N]; n int a[N], l[X], pr[N], fc[X]; n int tag[X]; n void apply(int x) { n   int lst = 0, cnt = 0; n   while (x != 1) { n     int pp = fc[x]; n     x /= pp; n     if (pp == lst) { n       ++cnt; n     } else { n       if (cnt >= l[lst]) { n         l[lst] = cnt; n         tag[lst] = ind; n       } n       cnt = 1; n       lst = pp; n     } n   } n   if (cnt >= l[lst]) { n     l[lst] = cnt; n     tag[lst] = ind; n   } n } n int main() { n   for (int x = 2; x < X; ++x) { n     if (!vis[x]) { n       fc[x] = x; n       pr[++pc] = x; n     } n     for (int i = 1; x * pr[i] < X; ++i) { n       vis[x * pr[i]] = true; n       fc[x * pr[i]] = pr[i]; n       if (x % pr[i] == 0) break; n     } n   } n   scanf( %d , &n); n   for (int i = 1; i <= n; ++i) scanf( %d , &a[i]); n   sort(a + 1, a + n + 1, greater<int>()); n   for (int i = 1; i <= n; ++i) { n     ind = i; n     if (!l[a[i]]) n       apply(a[i]); n     else n       apply(a[i] - 1); n   } n   int ans = 1; n   for (int i = 1; i <= pc; ++i) n     while (l[pr[i]]--) ans = ans * (long long)pr[i] % P; n   for (int x = 1; x < X; ++x) chose[tag[x]] = true; n   ans = (ans + (count(chose + 1, chose + n + 1, true) != n)) % P; n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long int T = 1; n   while (T--) { n     long long int m, n, k, t, i; n     cin >> m >> n >> k >> t; n     vector<long long int> sol(m); n     for (i = 0; i < m; i++) cin >> sol[i]; n     sort((sol).begin(), (sol).end()); n     vector<pair<long long int, pair<long long int, long long int>>> traps(k); n     for (i = 0; i < k; i++) { n       cin >> traps[i].first >> traps[i].second.first >> traps[i].second.second; n     } n     sort((traps).begin(), (traps).end()); n     long long int l, r, mid; n     l = 0; n     r = 200005; n     long long int ans = r; n     while (l <= r) { n       mid = (l + r) / 2; n       long long int tm = n + 1; n       long long int donest = -1; n       long long int doneend = -1; n       for (auto x : traps) { n         if (x.second.second > mid) { n           if (donest == -1) { n             donest = x.first; n             doneend = x.second.first; n           } else if (x.first <= doneend) { n             doneend = max(doneend, x.second.first); n           } else { n             tm += 2 * (doneend - donest + 1); n             donest = x.first; n             doneend = x.second.first; n           } n         } n       } n       if (donest != -1) { n         tm += 2 * (doneend - donest + 1); n       } n       if (tm <= t) { n         r = mid - 1; n         ans = min(ans, mid); n       } else n         l = mid + 1; n     } n     ans = lower_bound((sol).begin(), (sol).end(), ans) - sol.begin(); n     cout << m - ans <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, c, d, a, b, i; n   cin >> n >> a >> b; n   c = b, d = c; n   for (i = 2; i <= n; i++) { n     cin >> a >> b; n     c = max(c, d - a + b); n     d = d - a + b; n   } n   cout << c; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1000, MD = 1000000007; n char aa[N + 1], bb[N + 1], cc[N * 3]; n int zz[N * 3]; n void mult(int aa[][2], int bb[][2], int cc[][2]) { n   for (int i = 0; i < 2; i++) n     for (int j = 0; j < 2; j++) { n       long long c = 0; n       for (int k = 0; k < 2; k++) c += (long long)aa[i][k] * bb[k][j]; n       cc[i][j] = c % MD; n     } n } n void power(int aa[][2], int pp[][2], int tt[][2], int k) { n   if (k == 0) { n     pp[0][0] = 1, pp[0][1] = 0; n     pp[1][0] = 0, pp[1][1] = 1; n     return; n   } n   if (k & 1) { n     power(aa, pp, tt, k >> 1); n     mult(pp, pp, tt); n     mult(tt, aa, pp); n   } else { n     power(aa, tt, pp, k >> 1); n     mult(tt, tt, pp); n   } n } n int main() { n   int k; n   cin >> aa >> bb >> k; n   int n = strlen(aa); n   for (int i = 0; i < n; i++) { n     cc[i] = bb[i]; n     cc[n + i] = cc[n + n + i] = aa[i]; n   } n   for (int l = 0, r = 0, i = 1; i < n * 3; i++) n     if (i + zz[i - l] < r) n       zz[i] = zz[i - l]; n     else { n       l = i; n       if (r < l) r = l; n       while (r < n * 3 && cc[r] == cc[r - l]) r++; n       zz[i] = r - l; n     } n   int a = 0; n   for (int i = n; i < n + n; i++) n     if (zz[i] >= n) a++; n   int b = n - a; n   int aa[2][2], pp[2][2], tt[2][2]; n   aa[0][0] = a - 1, aa[0][1] = a; n   aa[1][0] = b, aa[1][1] = b - 1; n   power(aa, pp, tt, k); n   int ans = zz[n] >= n ? pp[0][0] : pp[0][1]; n   if (ans < 0) ans += MD; n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int M = 1e5 + 5; n const int inf = 1e9 + 5; n const int mod = 1e9 + 7; n vector<int> v[M]; n int hx2[2 * M]; n int hx[M]; n int nxt[M]; n int n, m; n int KMP() { n   memset(nxt, 0, sizeof(nxt)); n   int la, lb; n   la = n; n   lb = m; n   int j, k; n   j = 0; n   k = -1; n   nxt[0] = -1; n   while (j < la) { n     if (k == -1 || hx[j] == hx[k]) { n       j++; n       k++; n       nxt[j] = k; n     } else { n       k = nxt[k]; n     } n   } n   int ans = 0; n   j = 0; n   k = 0; n   while (k < lb) { n     if (j == -1 || hx[j] == hx2[k]) { n       j++; n       k++; n     } else { n       j = nxt[j]; n     } n     if (j == la) { n       j = nxt[j]; n       ans++; n     } n   } n   return ans; n } n int main() { n   int k; n   scanf( %d%d , &n, &k); n   m = 2 * n; n   for (int i = 0; i < k; i++) { n     int a, b; n     scanf( %d%d , &a, &b); n     if (a > b) swap(a, b); n     v[a].push_back(min(b - a, n - b + a)); n     v[b].push_back(min(b - a, n - b + a)); n   } n   for (int i = 0; i < n; i++) { n     sort(v[i + 1].begin(), v[i + 1].end()); n     for (int j = 0; j < v[i + 1].size(); j++) { n       hx[i] = hx[i] * n + v[i + 1][j]; n     } n   } n   for (int i = 0; i < n; i++) { n     hx2[i] = hx[i]; n     hx2[i + n] = hx[i]; n   } n   if (KMP() <= 2) { n     printf( No n ); n   } else { n     printf( Yes n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int N, B, Q; n int a[200005]; n vector<int> adj[200005]; n void init() { n   B = sqrt(N); n   for (int i = 1; i <= N; i++) { n     a[i] = i; n     adj[i / B].push_back(i); n   } n } n long long work(int l, int r) { n   if (l == r) return 0; n   int idx, idy, x, y, k; n   x = a[l]; n   y = a[r]; n   idx = l / B; n   k = find(adj[idx].begin(), adj[idx].end(), x) - adj[idx].begin(); n   adj[idx][k] = y; n   sort(adj[idx].begin(), adj[idx].end()); n   idy = r / B; n   k = find(adj[idy].begin(), adj[idy].end(), y) - adj[idy].begin(); n   adj[idy][k] = x; n   sort(adj[idy].begin(), adj[idy].end()); n   int ans = 0, f; n   if (x > y) n     f = -1, swap(x, y); n   else n     f = 1; n   if (idx == idy) { n     for (int i = l + 1; i <= r - 1; i++) { n       if (x < a[i] && a[i] < y) ++ans; n     } n   } else { n     for (int i = l + 1; i < (idx + 1) * B; i++) { n       if (x < a[i] && a[i] < y) ++ans; n     } n     for (int id = idx + 1; id < idy; id++) { n       ans += upper_bound(adj[id].begin(), adj[id].end(), y) - n              lower_bound(adj[id].begin(), adj[id].end(), x); n     } n     for (int i = idy * B; i < r; i++) { n       if (x < a[i] && a[i] < y) ++ans; n     } n   } n   swap(a[l], a[r]); n   return (2 * ans + 1) * f; n } n int main() { n   scanf( %d%d , &N, &Q); n   init(); n   int l, r; n   long long ans = 0; n   while (Q--) { n     scanf( %d%d , &l, &r); n     if (l > r) swap(l, r); n     ans += work(l, r); n     printf( %lld n , ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2e5 + 5; n long long a[N], pre[N]; n int n; n long long check(int p, int len) { n   return pre[p] - pre[p - len - 1] + pre[n] - pre[n - len]; n } n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) scanf( %lld , &a[i]); n   sort(a + 1, a + 1 + n); n   for (int i = 1; i <= n; i++) pre[i] = pre[i - 1] + a[i]; n   int p = 1, len = 0; n   long long ans = 0; n   for (int i = 1; i <= n; i++) { n     int l = 1, r = min(i - 1, n - i), mid; n     while (r >= l) { n       mid = l + r >> 1; n       if ((long long)check(i, mid) * (mid * 2 - 1) >= n           (long long)check(i, mid - 1) * (mid * 2 + 1)) { n         l = mid + 1; n         if ((long long)check(i, mid) * (len * 2 + 1) - n                 a[i] * (len * 2 + 1) * (mid * 2 + 1) > n             (long long)ans * (mid * 2 + 1) - n                 a[p] * (len * 2 + 1) * (mid * 2 + 1)) n           ans = check(i, mid), p = i, len = mid; n       } else n         r = mid - 1; n     } n   } n   printf( %d n , len * 2 + 1); n   for (int i = p - len; i <= p; i++) printf( %d  , pre[i] - pre[i - 1]); n   for (int i = n - len + 1; i <= n; i++) printf( %d  , pre[i] - pre[i - 1]); n   printf(  n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a[110], b[110], n; n int main() { n   int t; n   cin >> t; n   while (t--) { n     cin >> n; n     for (register int i = 1; i <= n; i++) cin >> a[i]; n     for (register int i = 1; i <= n; i++) cin >> b[i]; n     sort(a + 1, a + n + 1); n     sort(b + 1, b + n + 1); n     for (register int i = 1; i <= n; i++) cout << a[i] <<    ; n     puts(  ); n     for (register int i = 1; i <= n; i++) cout << b[i] <<    ; n     puts(  ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n double EPS = 1e-9; n int INF = 2000000000; n long long INFF = 8000000000000000000LL; n double PI = acos(-1); n string IntToString(int a) { n   char x[100]; n   sprintf(x,  %d , a); n   string s = x; n   return s; n } n int StringToInt(string a) { n   char x[100]; n   strcpy(x, a.c_str()); n   int res; n   sscanf(x,  %d , &res); n   return res; n } n int spaces = 0; n char c[5]; n int main() { n   while (scanf( %c , &c[0]) != EOF && c[0] !=   n ) { n     scanf( %c%c , &c[1], &c[2]); n     if (c[2] ==  > ) { n       spaces += 2; n       for (int(i) = (1); (i) <= (spaces - 2); (i)++) printf(   ); n       for (int(i) = (0); (i) <= (2); (i)++) printf( %c , c[i]); n       puts(  ); n     } else { n       scanf( %c , &c[3]); n       spaces -= 2; n       for (int(i) = (1); (i) <= (spaces); (i)++) printf(   ); n       for (int(i) = (0); (i) <= (3); (i)++) printf( %c , c[i]); n       puts(  ); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1000 + 100; n const int maxk = 45; n const int mod = 1000000007; n int dp[maxk][maxn]; n int cnt[maxk][maxn]; n void input_output() { n   int t; n   cin >> t; n   for (int i = 0; i < t; i++) { n     int n, k; n     cin >> n >> k; n     if (k < maxk) n       cout << dp[k][n] << endl; n     else n       cout << 0 << endl; n   } n } n void dpp() { n   for (int i = 0; i < maxn; i++) dp[0][i] = 1, cnt[0][i] = i + 1; n   for (int i = 1; i < 45; i++) { n     for (int j = i; j < maxn; j++) { n       dp[i][j] = (dp[i][j - i] + (long long)i * cnt[i - 1][j - i]) % mod; n       cnt[i][j] = (cnt[i][j - 1] + dp[i][j]) % mod; n     } n   } n } n int main() { n   dpp(); n   input_output(); n } n


#include <bits/stdc++.h> n using namespace std; n template <class T1, class T2> n ostream &operator<<(ostream &os, const pair<T1, T2> &p) { n   os <<  {  << p.first <<  ,  << p.second <<  } ; n   return os; n } n const int N = 3e5 + 5; n const int oo = 1e9 + 7; n vector<pair<pair<int, int>, int> > X, Y; n pair<int, int> operator+(pair<int, int> x, pair<int, int> y) { n   return {x.first + y.first, x.second + y.second}; n } n bool pos() { n   for (int i = 0; i < 4; i++) { n     pair<int, int> a, b; n     cin >> a.first >> a.second; n     cin >> b.first >> b.second; n     if (a == b) return 0; n     if (a.first == b.first) { n       if (b < a) swap(a, b); n       Y.push_back({a, b.second - a.second}); n     } else if (a.second == b.second) { n       if (b < a) swap(a, b); n       X.push_back({a, b.first - a.first}); n     } else n       return 0; n   } n   if (X.size() != 2) return 0; n   if (Y.size() != 2) return 0; n   sort(X.begin(), X.end()); n   sort(Y.begin(), Y.end()); n   if (X[0].second != X[1].second or X[0].first.first != X[1].first.first) n     return 0; n   if (Y[0].second != Y[1].second or Y[0].first.second != Y[1].first.second) n     return 0; n   if (X[0].first != Y[0].first) return 0; n   if (X[0].first + make_pair(0, Y[0].second) != X[1].first) return 0; n   if (Y[0].first + make_pair(X[0].second, 0) != Y[1].first) return 0; n   return 1; n } n int32_t main() { n   ios::sync_with_stdio(false); n   cin.tie(nullptr); n   cout.tie(nullptr); n   cout << (pos() ?  YES n  :  NO n ); n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 2e6 + 10; n int z[MAXN]; n void Zvalue(const string &s) { n   z[0] = s.size(); n   int l = 0, r = 0, x; n   for (int i = 1; i < s.size(); i++) { n     if (r < i || z[i - l] >= r - i + 1) { n       r < i ? x = i : x = r + 1; n       while (x < s.size() && s[x] == s[x - i]) x++; n       z[i] = x - i; n       if (i < x) { n         l = i; n         r = x - 1; n       }; n     } else n       z[i] = z[i - l]; n   } n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   int T; n   cin >> T; n   while (T--) { n     string s; n     cin >> s; n     int p; n     for (p = 0; p < s.size() - 1 - p; p++) n       if (s[p] != s[s.size() - 1 - p]) break; n     string smid = s.substr(p, s.size() - p * 2); n     string revsmid = smid; n     reverse(revsmid.begin(), revsmid.end()); n     Zvalue(smid +  $  + revsmid); n     int ls = 0, rs = 0; n     for (int i = 1; i <= smid.size(); i++) n       if (i == z[smid.size() * 2 + 1 - i]) ls = i; n     Zvalue(revsmid +  $  + smid); n     for (int i = 1; i <= smid.size(); i++) n       if (i == z[smid.size() * 2 + 1 - i]) rs = i; n     if (ls > rs) n       cout << s.substr(0, p + ls) + s.substr(s.size() - p, p) <<   n ; n     else n       cout << s.substr(0, p) + s.substr(s.size() - p - rs, p + rs) <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int t, n; n long long a[100005]; n int get_bit(long long x) { n   int ans = 0; n   while (x) { n     ans++; n     x >>= 1; n   } n   return ans; n } n int main() { n   int i, j; n   scanf( %d , &t); n   while (t--) { n     scanf( %d , &n); n     for (i = 1; i <= n; i++) scanf( %lld , &a[i]); n     int ans = 0, last = a[1]; n     for (i = 2; i <= n; i++) { n       if (a[i] >= last) { n         last = a[i]; n         continue; n       } n       ans = max(ans, get_bit(last - a[i])); n     } n     printf( %d n , ans); n   } n   return 0; n } n


// Jai Shree Ram n  n #include<bits/stdc++.h> n typedef long long int ll; n #define pb push_back n #define max2(a,b) (a>b)?a:b n #define mi2(a,b) (a<=b)?a:b n #define fori(i,n) for(ll i=0;i<(ll)n;i++) n #define ford(i,n) for(ll i=n;i>=0;i--) n #define pll pair<ll,ll> n #define mod 1000000007 n #define ff first n #define ss second n using namespace std; n #define MAXI 1e15 n #define MAX_LIMIT 500001 n  n  n void solve() n { n      n     ll n; n     cin>>n; n     vector<ll> v(n),neg; n     ll pos=MAXI; n     bool fl=0; n     fori(i,n) n     { n         cin>>v[i]; n         if(v[i]<=0) n         { n             neg.pb(v[i]); n         } n         else if(v[i]>0) n         { n             fl=1; n             pos=min(pos,v[i]); n         } n     } n     sort(neg.begin(),neg.end(),greater<ll>()); n     ll ans=neg.size(); n     if(fl==0) n     { n          n         cout<<ans<<  n ; n         return; n     } n     else n     { n  n         ll mini=MAXI; n         for(int i=1;i<neg.size();i++) n         { n             ll val=abs(neg[i]-neg[i-1]); n             mini=min(mini,val); n         } n         n              n             if(mini>=pos) n             { n                 ans++; n             } n  n          n          n         n         cout<<ans<<  n ; n         return; n          n  n     } n  n  n      n  n  n  n  n  n  n } n   n  n   n int main() n { n       n  n   n     ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); n  n  n  n  n      n     ll T; n     T=1; n     cin>>T; n      n     fori(_,T) n     { n          n         solve(); n          n     } n      n     n   n   n      n   n } n


#include <bits/stdc++.h> n using namespace std; n void solve() { n   int k, a, b; n   cin >> k >> a >> b; n   string s; n   cin >> s; n   int l = s.length(); n   double c = (double)l / k; n   int c1 = floor(c); n   int c2 = ceil(c); n   int flag1 = 0, flag2 = 0; n   if ((l - (c1 * (k - 1))) > b || (l - (c1 * (k - 1))) < a) { n     flag1 = 1; n   } n   if ((l - (c2 * (k - 1))) > b || (l - (c2 * (k - 1))) < a) { n     flag2 = 1; n   } n   if ((flag1 == 1 || c1 < a || c1 > b) && (flag2 == 1 || c2 < a || c2 > b)) { n     cout <<  No solution ; n     return; n   } n   if (flag1 == 0) { n     int i1 = 0; n     int kk = 0; n     while (i1 <= l) { n       kk++; n       for (long long int i = i1; i < min(i1 + c1, l); i++) { n         cout << s[i]; n       } n       i1 += c1; n       if (kk == k) { n         for (long long int i = i1; i < l; i++) { n           cout << s[i]; n         } n         return; n       } n       printf(  n ); n     } n   } else { n     int i1 = 0; n     int kk = 0; n     while (i1 <= l) { n       kk++; n       for (long long int i = i1; i < min(i1 + c2, l); i++) { n         cout << s[i]; n       } n       i1 += c2; n       if (kk == k) { n         for (long long int i = i1; i < l; i++) { n           cout << s[i]; n         } n       } n       printf(  n ); n     } n   } n } n int main() { solve(); } n


#include <bits/stdc++.h> n using namespace std; n long long rt(long long a) { n   long long p = 0, q = a; n   while (p < q) { n     long long s = (p + q + 1) / 2; n     long long sv = s * (s + 1) / 2; n     if (sv < a) p = s; n     if (sv > a) q = s - 1; n     if (sv == a) return s; n   } n   if (p * (p + 1) / 2 == a) return p; n   return -1; n } n long long a, b, c, d; n bool possible(long long z, long long j) { n   long long n = z + j; n   if (a + b + c + d != n * (n - 1) / 2) { n     return 0; n   } n   return 1; n } n bool solve(long long z, long long j) { n   if (!possible(z, j)) { n     return 0; n   } n   long long n = z + j; n   if (j == 0) { n     for (int i = 0; i < n; i++) cout <<  0 ; n     return 1; n   } n   if (z == 0) { n     for (int i = 0; i < n; i++) cout <<  1 ; n     return 1; n   } n   long long ord[5]; n   ord[0] = b / j; n   ord[2] = (ord[0] * j != b); n   ord[3] = b - ord[0] * j; n   ord[4] = z - ord[0] - ord[2]; n   ord[1] = j - ord[3]; n   for (int i = 0; i < 5; i++) { n     for (int k = 0; k < ord[i]; k++) { n       cout << (i % 2); n     } n   } n   return 1; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin >> a >> b >> c >> d; n   if (a + b + c + d == 0) { n     cout <<  1 n ; n     return 0; n   } n   long long z = rt(a); n   long long j = rt(d); n   if (z == -1 || j == -1) { n     cout <<  Impossible n ; n     return 0; n   } n   ++z; n   ++j; n   if (z == 1 && j == 1) { n     if (solve(0, 0)) return 0; n     if (solve(0, 1)) return 0; n     if (solve(1, 0)) return 0; n     if (solve(1, 1)) return 0; n     cout <<  Impossible n ; n     return 0; n   } n   if (z == 1) { n     if (solve(0, j)) return 0; n     if (solve(1, j)) return 0; n     cout <<  Impossible n ; n     return 0; n   } n   if (j == 1) { n     if (solve(z, 0)) return 0; n     if (solve(z, 1)) return 0; n     cout <<  Impossible n ; n     return 0; n   } n   if (solve(z, j)) return 0; n   cout <<  Impossible n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long INF = 1e15; n long long arr[100003]; n int main() { n   int n; n   scanf( %d , &n); n   for (int i = 0; i < n; i++) scanf( %lld , &arr[i]); n   if (n == 1 || n == 2) n     printf( 0 n ); n   else { n     long long res = INF; n     for (int i = -1; i <= 1; i++) { n       for (int j = -1; j <= 1; j++) { n         long long a = arr[0] + i; n         long long b = (arr[1] + j) - (arr[0] + i); n         long long cnt = abs(i) + abs(j); n         for (int k = 2; k < n; k++) { n           if (abs(a + (k * b) - arr[k]) > 1) n             cnt = INF; n           else n             cnt += abs(a + (k * b) - arr[k]); n         } n         res = min(res, cnt); n       } n     } n     if (res <= 1e9) n       printf( %lld n , res); n     else n       printf( -1 n ); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string x, y; n   cin >> x >> y; n   for (long long int i = 0; i < x.size(); i++) { n     if (x[i] == y[i]) n       cout << 0; n     else n       cout << 1; n   } n } n


#include <bits/stdc++.h> n template <class T> n T _diff(T a, T b) { n   return (a < b ? b - a : a - b); n } n template <class T> n T _abs(T a) { n   return (a < 0 ? -a : a); n } n template <class T> n T _max(T a, T b) { n   return (a > b ? a : b); n } n template <class T> n T _min(T a, T b) { n   return (a < b ? a : b); n } n template <class T> n T max3(T a, T b, T c) { n   return (_max(a, b) > c ? _max(a, b) : c); n } n template <class T> n T min3(T a, T b, T c) { n   return (_min(a, b) < c ? _min(a, b) : c); n } n template <class T> n T GCD(T a, T b) { n   a = _abs(a); n   b = _abs(b); n   T tmp; n   while (a % b) { n     tmp = a % b; n     a = b; n     b = tmp; n   } n   return b; n } n template <class T> n T LCM(T a, T b) { n   a = _abs(a); n   b = _abs(b); n   return (a / GCD(a, b)) * b; n } n using namespace std; n long long n, k, mul; n int main() { n   cin >> n >> k; n   mul = (n * (n - 1)) / 2; n   if (mul <= k) n     cout <<  no solution n ; n   else { n     for (int i = 0; i < n; i++) { n       cout << 0 <<     << i << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n static inline void canhazfast() { n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n   cout.tie(nullptr); n } n template <typename T> n T gcd(T a, T b) { n   return b == 0 ? a : gcd(b, a % b); n } n template <typename T> n T extgcd(T a, T b, T &x, T &y) { n   T x0 = 1, y0 = 0, x1 = 0, y1 = 1; n   while (b) { n     T q = a / b; n     a %= b; n     swap(a, b); n     x0 -= q * x1; n     swap(x0, x1); n     y0 -= q * y1; n     swap(y0, y1); n   } n   x = x0; n   y = y0; n   return a; n } n static inline int ctz(unsigned x) { return __builtin_ctz(x); } n static inline int ctzll(unsigned long long x) { return __builtin_ctzll(x); } n static inline int clz(unsigned x) { return __builtin_clz(x); } n static inline int clzll(unsigned long long x) { return __builtin_clzll(x); } n static inline int popcnt(unsigned x) { return __builtin_popcount(x); } n static inline int popcntll(unsigned long long x) { n   return __builtin_popcountll(x); n } n static inline int bsr(unsigned x) { return 31 ^ clz(x); } n static inline int bsrll(unsigned long long x) { return 63 ^ clzll(x); } n vector<int> adj[300016]; n int id[300016], lo[300016]; n int par[300016], rnk[300016], dist[300016]; n vector<int> tadj[300016]; n vector<pair<int, int> > br; n int nxt = 0; n int fin(int x) { return par[x] == x ? x : par[x] = fin(par[x]); } n void uni(int x, int y) { n   if (rnk[x] < rnk[y]) { n     par[x] = y; n   } else { n     par[y] = x; n     rnk[x] = max(rnk[x], rnk[y] + 1); n   } n } n void dfs(int u, int p = 0) { n   id[u] = lo[u] = ++nxt; n   for (int v : adj[u]) { n     if (!id[v]) { n       dfs(v, u); n       lo[u] = min(lo[u], lo[v]); n       if (lo[v] > id[u]) { n         br.emplace_back(u, v); n       } else { n         int ru = fin(u), rv = fin(v); n         if (ru != rv) uni(ru, rv); n       } n     } else if (v != p) { n       lo[u] = min(lo[u], lo[v]); n     } n   } n } n int bfs(int s, int n) { n   queue<int> q; n   int r = 0; n   fill_n(dist + 1, n, 1010101); n   dist[s] = 0; n   q.push(s); n   while (!q.empty()) { n     int u = q.front(); n     q.pop(); n     r = u; n     for (int v : tadj[u]) { n       if (dist[u] + 1 < dist[v]) { n         dist[v] = dist[u] + 1; n         q.push(v); n       } n     } n   } n   return r; n } n int main() { n   canhazfast(); n   int n, m, t; n   cin >> n >> m; n   for (int i = 1; i <= n; ++i) par[i] = i; n   for (int i = 0; i < m; ++i) { n     int a, b; n     cin >> a >> b; n     adj[a].push_back(b); n     adj[b].push_back(a); n   } n   dfs(1); n   for (pair<int, int> e : br) { n     int a = fin(e.first), b = fin(e.second); n     tadj[a].push_back(b); n     tadj[b].push_back(a); n   } n   t = bfs(fin(1), n); n   t = bfs(t, n); n   cout << dist[t]; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long INFLL = 1e18; n const int MAXN = 1e6 + 100; n const long long INF = 1e9; n const long long mod1 = 1e9 + 7; n const long long mod2 = 2e9 + 11; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   int t; n   cin >> t; n   while (t--) { n     long long a, b; n     cin >> a >> b; n     if (a == b) n       cout << 0 <<   n ; n     else { n       if (b < a) { n         if ((a - b) % 2 == 0) n           cout << 1 <<   n ; n         else n           cout << 2 <<   n ; n       } else { n         if ((a - b) % 2 == 0) n           cout << 2 <<   n ; n         else n           cout << 1 <<   n ; n       } n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n const double long EPS = 1e-10; n struct wor { n   double long x = 0, y = 0; n }; n double long dist(wor a, wor b) { n   double long answer = n       sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y)); n   return answer; n } n pair<vector<double long>, vector<long long>> djkstra( n     long long from, long long n, n     vector<vector<pair<double long, long long>>> &adj) { n   vector<bool> used(n); n   vector<double long> d(n, 1e15); n   vector<long long> f(n); n   d[from] = 0; n   f[from] = from; n   for (int i = 0; i < n; i++) { n     long long mi = -1; n     for (int i = 0; i < n; i++) { n       if (!used[i]) { n         mi = i; n         break; n       } n     } n     for (int j = 0; j < n; j++) { n       if (!used[j] && d[j] < d[mi]) { n         mi = j; n       } n     } n     used[mi] = true; n     for (auto e : adj[mi]) { n       if (!used[e.second] && d[mi] + e.first < d[e.second]) { n         d[e.second] = d[mi] + e.first; n         f[e.second] = mi; n       } n     } n   } n   return {d, f}; n } n struct Kun1 { n   long long n; n   vector<vector<long long>> adj; n   vector<long long> used; n   vector<bool> is_l; n   vector<long long> mt; n   Kun1(long long n) { n     this->n = n; n     adj.resize(n); n     used.resize(n); n     mt.resize(n); n     is_l.resize(n); n   } n   void add_edge(long long u, long long v) { n     adj[u].push_back(v); n     adj[v].push_back(u); n   } n   void make_left(long long v) { is_l[v] = true; } n   bool try_kun(long long v, long long cur) { n     if (used[v] == cur) return false; n     used[v] = cur; n     for (auto e : adj[v]) { n       if (mt[e] == -1 || try_kun(mt[e], cur)) { n         mt[e] = v; n         return true; n       } n     } n     return false; n   } n   long long max_matching() { n     vector<bool> usel(n); n     for (int i = 0; i < n; i++) { n       if (!is_l[i]) mt[i] = -1; n     } n     long long answer = 0; n     for (int i = 0; i < n; i++) { n       if (is_l[i]) { n         for (auto e : adj[i]) { n           if (mt[e] == -1) { n             mt[e] = i; n             answer++; n             usel[i] = true; n             break; n           } n         } n       } n     } n     long long z = 1; n     for (int i = 0; i < n; i++) { n       if (is_l[i] && !usel[i] && try_kun(i, z++)) answer++; n     } n     return answer; n   } n }; n struct MCMF { n   struct edge { n     long long from, to, flow, cap, cost; n   }; n   vector<edge> edges; n   vector<vector<long long>> adj; n   vector<long long> d; n   vector<long long> p; n   deque<long long> q; n   vector<long long> state; n   const long long levit_inf = 2e9; n   long long n, s, t; n   MCMF(long long _n, long long _s, long long _t) { n     n = _n; n     s = _s; n     t = _t; n     adj.resize(n); n     d.resize(n); n     p.resize(n); n     state.resize(n); n   } n   void add_edge(long long from, long long to, long long cap, long long cost) { n     edge e1 = {from, to, 0, cap, cost}; n     edge e2 = {to, from, 0, 0, -cost}; n     adj[from].push_back(edges.size()); n     edges.push_back(e1); n     adj[to].push_back(edges.size()); n     edges.push_back(e2); n   } n   void relax(long long v, long long dist, long long from) { n     if (d[v] <= dist) { n       return; n     } n     d[v] = dist; n     p[v] = from; n     if (state[v] == 0 || (!q.empty() && d[q.front()] > d[v])) { n       q.push_front(v); n       state[v] = 1; n     } else if (state[v] == 2) { n       q.push_back(v); n       state[v] = 1; n     } n   } n   bool levit() { n     fill(d.begin(), d.end(), levit_inf); n     fill(p.begin(), p.end(), -1); n     fill(state.begin(), state.end(), 0); n     relax(s, 0, 0); n     while (!q.empty()) { n       long long v = q.front(); n       q.pop_front(); n       state[v] = 2; n       for (auto i = 0; i < adj[v].size(); i++) { n         auto e = adj[v][i]; n         if (edges[e].flow < edges[e].cap) { n           relax(edges[e].to, d[v] + edges[e].cost, e); n         } n       } n     } n     return d[t] < levit_inf; n   } n   pair<long long, long long> max_flow() { n     long long flow = 0; n     long long cost = 0; n     while (levit()) { n       long long ed = p[t]; n       long long mi_fl = edges[ed].cap - edges[ed].flow; n       while (edges[ed].from != s) { n         mi_fl = min(mi_fl, edges[ed].cap - edges[ed].flow); n         ed = p[edges[ed].from]; n       } n       mi_fl = min(mi_fl, edges[ed].cap - edges[ed].flow); n       ed = p[t]; n       while (edges[ed].from != s) { n         edges[ed].flow += mi_fl; n         edges[ed ^ 1].flow -= mi_fl; n         cost += edges[ed].cost * mi_fl; n         ed = p[edges[ed].from]; n       } n       edges[ed].flow += mi_fl; n       edges[ed ^ 1].flow -= mi_fl; n       cost += edges[ed].cost * mi_fl; n       flow += mi_fl; n     } n     return {cost, flow}; n   } n }; n struct MCMF1 { n   struct edge { n     long long from, to, cap, flow, cost; n   }; n   vector<edge> edges; n   vector<vector<long long>> adj; n   vector<long long> p; n   vector<long long> d; n   vector<long long> state; n   const long long lenin_inf = 2e9; n   long long n, s, t; n   MCMF1(long long _n, long long _s, long long _t) { n     n = _n; n     s = _s; n     t = _t; n     p.resize(n); n     d.resize(n); n     state.resize(n); n     adj.resize(n); n   } n   void add_edge(long long from, long long to, long long cap, long long cost) { n     edge e1 = {from, to, cap, 0, cost}; n     edge e2 = {to, from, 0, 0, -cost}; n     adj[from].push_back(edges.size()); n     edges.push_back(e1); n     adj[to].push_back(edges.size()); n     edges.push_back(e2); n   } n   deque<long long> q; n   void relax(long long v, long long dist, long long from) { n     if (d[v] <= dist) return; n     d[v] = dist; n     p[v] = from; n     if (state[v] == 0 || (!q.empty() && d[v] < d[q.front()])) { n       q.push_front(v); n       state[v] = 1; n     } else if (state[v] == 2) { n       q.push_back(v); n       state[v] = 1; n     } n   } n   bool lenin() { n     fill(p.begin(), p.end(), -1); n     fill(d.begin(), d.end(), lenin_inf); n     fill(state.begin(), state.end(), 0); n     relax(s, 0, 0); n     while (!q.empty()) { n       long long v = q.front(); n       q.pop_front(); n       state[v] = 2; n       for (auto e : adj[v]) { n         if (edges[e].cap - edges[e].flow == 0) continue; n         relax(edges[e].to, d[v] + edges[e].cost, e); n       } n     } n     return d[t] < lenin_inf; n   } n   pair<long long, long long> max_flow() { n     long long cost = 0; n     long long flow = 0; n     while (lenin()) { n       long long ed = p[t]; n       long long ma = edges[ed].cap - edges[ed].flow; n       while (edges[ed].from != s) { n         ma = min(ma, edges[ed].cap - edges[ed].flow); n         ed = p[edges[ed].from]; n       } n       ma = min(ma, edges[ed].cap - edges[ed].flow); n       flow += ma; n       ed = p[t]; n       while (edges[ed].from != s) { n         edges[ed].flow += ma; n         edges[ed ^ 1].flow -= ma; n         cost += ma * edges[ed].cost; n         ed = p[edges[ed].from]; n       } n       edges[ed].flow += ma; n       edges[ed ^ 1].flow -= ma; n       cost += ma * edges[ed].cost; n     } n     return {cost, flow}; n   } n }; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   string t; n   cin >> t; n   long long n; n   cin >> n; n   vector<pair<string, long long>> arr(n); n   vector<vector<long long>> num(n); n   long long sum = 0; n   long long z = n + 1; n   for (int i = 0; i < n; i++) { n     cin >> arr[i].first >> arr[i].second; n     for (int j = 0; j < arr[i].first.length(); j++) { n       num[i].push_back(z++); n     } n     sum += arr[i].first.length(); n   } n   MCMF1 mcmf(2 + t.length() + n + sum, 0, 2 + t.length() + n + sum - 1); n   for (int i = 0; i < n; i++) { n     mcmf.add_edge(0, i + 1, arr[i].second, 0); n   } n   for (int i = 1; i <= n; i++) { n     for (auto e : num[i - 1]) { n       mcmf.add_edge(i, e, 1, 0); n     } n   } n   vector<long long> tn; n   for (int i = 0; i < t.length(); i++) { n     tn.push_back(z++); n   } n   for (int i = 1; i <= n; i++) { n     for (int j = 0; j < arr[i - 1].first.length(); j++) { n       for (int z = 0; z < t.length(); z++) { n         if (t[z] == arr[i - 1].first[j]) { n           mcmf.add_edge(num[i - 1][j], tn[z], 1, i); n         } n       } n     } n   } n   for (auto e : tn) { n     mcmf.add_edge(e, 2 + t.length() + n + sum - 1, 1, 0); n   } n   auto e = mcmf.max_flow(); n   if (e.second != t.length()) { n     cout << -1; n   } else { n     cout << e.first; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, k; n   scanf( %d %d , &n, &k); n   for (int i = 0; i < k; i++) { n     if (n % 10 == 0) { n       n /= 10; n     } else { n       n--; n     } n   } n   printf( %d n , n); n } n


#include <bits/stdc++.h> n using namespace std; n template <class U, class V> n ostream& operator<<(ostream& os, const pair<U, V>& p) { n   os <<  (  << p.first <<  ,   << p.second <<  ) ; n   return os; n } n template <class U, class V> n istream& operator>>(istream& in, pair<U, V>& p) { n   in >> p.first >> p.second; n   return in; n } n vector<vector<long long> > al; n long long n; n bool bfs(long long s, long long fr, long long* col) { n   bool mark[n]; n   memset(mark, 0, sizeof(mark)); n   ; n   mark[s] = 1; n   queue<long long> q; n   for (long long v : al[s]) { n     if (v != fr) { n       q.push(v); n     } n   } n   while (!q.empty()) { n     long long u = q.front(); n     q.pop(); n     if (col[u] != col[s]) { n       return false; n     } n     mark[u] = 1; n     for (long long v : al[u]) { n       if (!mark[v]) { n         q.push(v); n         mark[v] = 1; n       } n     } n   } n   return true; n } n int main() { n   scanf( %lld , &n); n   ; n   al = vector<vector<long long> >(n); n   long long c[n]; n   vector<pair<long long, long long> > inp; n   for (long long i = 0; i < n - 1; i++) { n     long long u, v; n     scanf( %lld %lld , &u, &v); n     ; n     u--, v--; n     al[u].push_back(v); n     al[v].push_back(u); n     inp.push_back(make_pair(u, v)); n   } n   for (long long i = 0; i < n; i++) { n     scanf( %lld , &c[i]); n     ; n   } n   for (auto& e : inp) { n     if (c[e.first] != c[e.second]) { n       bool f = 0; n       for (long long v : al[e.first]) { n         if (!bfs(v, e.first, c)) { n           f = 1; n           break; n         } n       } n       if (!f) { n         puts( YES ); n         printf( %lld n , e.first + 1); n         ; n         return 0; n       } n       for (long long v : al[e.second]) { n         if (!bfs(v, e.second, c)) { n           puts( NO ); n           return 0; n         } n       } n       puts( YES ); n       printf( %lld n , e.second + 1); n       ; n       return 0; n     } n   } n   puts( YES ); n   printf( %lld n , (long long)1); n   ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long k, l; n int main() { n   cin >> k >> l; n   long long K = k; n   int res = 0; n   while (K < l) { n     K *= k; n     res++; n   } n   if (K == l) { n     cout <<  YES  << endl; n     cout << res << endl; n   } else { n     cout <<  NO  << endl; n   } n   return 0; n } n