#include <bits/stdc++.h> n using namespace std; n long long num[200000]; n pair<long long, long long> p[200000]; n int main() { n   long long n, m, k, sum = 0, cnt = 1; n   cin >> n >> m >> k; n   for (int i = 1; i <= n; i++) { n     cin >> p[i].first; n     p[i].second = i; n   } n   sort(p + 1, p + n + 1); n   for (int i = n; i > n - m * k; i--) { n     sum += p[i].first; n     num[cnt++] = p[i].second; n   } n   cout << sum <<   n ; n   sort(num + 1, num + m * k + 1); n   for (int i = m; i < m * k; i += m) cout << num[i] <<    ; n   return 0; n } n


#include <bits/stdc++.h> n using ll = long long; n using ld = long double; n using ull = unsigned long long; n using namespace std; n const int N = 1e5 + 2, SQ = 400; n int n, q, a[N], jump[N], cost[N]; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n   cin >> n >> q; n   for (int i = (0); i <= (n - 1); ++i) cin >> a[i]; n   for (int i = (n - 1); i >= (0); --i) { n     int nxt = min(n, i + a[i]); n     if (nxt == n) { n       jump[i] = i; n       continue; n     } n     if (nxt / SQ > i / SQ) n       jump[i] = nxt, cost[i] = 1; n     else n       jump[i] = jump[nxt], cost[i] = cost[nxt] + 1; n   } n   while (q--) { n     int t; n     cin >> t; n     if (t == 0) { n       int x, y; n       cin >> x >> y; n       x--; n       a[x] = y; n       for (int i = (x); i >= (x / SQ * SQ); --i) { n         int nxt = min(n, i + a[i]); n         if (nxt == n) { n           jump[i] = i; n           cost[i] = 0; n           continue; n         } n         if (nxt / SQ > i / SQ) n           jump[i] = nxt, cost[i] = 1; n         else n           jump[i] = jump[nxt], cost[i] = cost[nxt] + 1; n       } n     } else { n       int x, res = 1; n       cin >> x; n       x--; n       while (cost[x]) res += cost[x], x = jump[x]; n       cout << x + 1 <<     << res <<   n ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:102400000,102400000 ) n #pragma GCC optimize( Ofast ) n #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native ) n using namespace std; n const int maxn = 2e5 + 5; n map<int, int> dp, pos; n int pre[maxn]; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int i, j, k, m, n; n   cin >> n; n   for (int i = 1; i <= n; ++i) { n     cin >> k; n     if (!dp.count(k - 1)) { n       dp[k] = 1; n       pre[i] = -1; n       pos[k] = i; n     } else if (dp[k - 1] + 1 > dp[k]) { n       dp[k] = dp[k - 1] + 1; n       pos[k] = i; n       pre[i] = pos[k - 1]; n     } n   } n   pair<int, int> mst = {0, 0}; n   for (auto it : dp) { n     if (it.second > mst.second) { n       mst.first = it.first; n       mst.second = it.second; n     } n   } n   int npos = pos[mst.first]; n   vector<int> ans; n   while (npos != -1) { n     ans.push_back(npos); n     npos = pre[npos]; n   } n   reverse(ans.begin(), ans.end()); n   cout << ans.size() << endl; n   for (auto it : ans) cout << it <<    ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   vector<vector<char> > v(4); n   for (int i = 0; i < 4; i++) v[i].resize(4); n   for (int i = 0; i < 4; i++) { n     for (int j = 0; j < 4; j++) { n       cin >> v[i][j]; n     } n   } n   for (int i = 0; i < 3; i++) { n     for (int j = 0; j < 3; j++) { n       int cntd = 0, cnth = 0; n       if (v[i][j] ==  # ) n         cnth++; n       else n         cntd++; n       if (v[i][j + 1] ==  # ) n         cnth++; n       else n         cntd++; n       if (v[i + 1][j] ==  # ) n         cnth++; n       else n         cntd++; n       if (v[i + 1][j + 1] ==  # ) n         cnth++; n       else n         cntd++; n       if (cntd >= 3 || cnth >= 3) { n         cout <<  YES n ; n         return 0; n       } n     } n   } n   cout <<  NO n ; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long a[100], b[100], i, n, m, r; n   cin >> n >> m >> r; n   long long ans = r; n   for (i = 0; i < n; ++i) { n     cin >> a[i]; n   } n   for (i = 0; i < m; ++i) { n     cin >> b[i]; n   } n   long long minn = *min_element(a, a + n); n   long long akcia = r / minn; n   r %= minn; n   r += akcia * (*max_element(b, b + m)); n   cout << max(ans, r) << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, x = 0; n   cin >> n; n   string s; n   while (n-- != 0) { n     cin >> s; n     if (s.find( + ) != string::npos) n       x++; n     else n       x--; n   } n   cout << x; n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize(2) n #pragma GCC optimize(3,  Ofast ,  inline ) n using namespace std; n void err(istream_iterator<string> it) { cerr << endl; } n template <typename T, typename... Args> n void err(istream_iterator<string> it, T a, Args... args) {} n namespace fastIO { n bool IOerror = 0; n inline char nc() { n   static char buf[100000], *p1 = buf + 100000, *pend = buf + 100000; n   if (p1 == pend) { n     p1 = buf; n     pend = buf + fread(buf, 1, 100000, stdin); n     if (pend == p1) { n       IOerror = 1; n       return -1; n     } n   } n   return *p1++; n } n inline bool blank(char ch) { n   return ch ==     || ch ==   n  || ch ==   r  || ch ==   t ; n } n inline void read(int &x) { n   char ch; n   while (blank(ch = nc())) n     ; n   if (IOerror) return; n   for (x = ch -  0 ; (ch = nc()) >=  0  && ch <=  9 ; x = x * 10 + ch -  0 ) n     ; n } n }  // namespace fastIO n using namespace fastIO; n const double PI = acos(-1.0); n const double eps = 1e-8; n const int maxn = 3e5 + 5; n int cnt[maxn]; n int main() { n   int t; n   scanf( %d , &t); n   while (t--) { n     string s; n     int n, k; n     cin >> n >> k >> s; n     int ans = 1; n     for (int i = 0; i < k; ++i) cnt[i] = 0; n     for (int i = 0; i < s.size(); ++i) { n       if (s[i] ==  ? ) continue; n       if ((s[i] ==  0  && cnt[i % k] == 1) || n           (s[i] ==  1  && cnt[i % k] == -1)) { n         ans = 0; n         break; n       } n       cnt[i % k] = s[i] ==  0  ? -1 : 1; n     } n     int cnt1 = 0, cnt0 = 0; n     for (int i = 0; i < n; ++i) n       if (cnt[i % k]) s[i] = cnt[i % k] == -1 ?  0  :  1 ; n     for (int i = 0; i < k; ++i) { n       if (s[i] ==  1 ) n         cnt1++; n       else if (s[i] ==  0 ) n         cnt0++; n     } n     if (2 * cnt1 > k || 2 * cnt0 > k) ans = 0; n     puts(ans ?  YES  :  NO ); n   } n } n


#include <bits/stdc++.h> n using namespace std; n struct mat { n   int num[4][4]; n }; n mat m1 = {{{1, 1, 1, 0}, {1, 0, 0, 0}, {0, 0, 1, 0}, {0, 0, 0, 1}}}, n     m2 = {{{1, 1, 0, 1}, {1, 0, 0, 0}, {0, 0, 1, 0}, {0, 0, 0, 1}}}; n mat mult(mat &a, mat &b) { n   mat ret; n   for (int i = 0; i < 4; i++) n     for (int j = 0; j < 4; j++) { n       long long t = 0; n       for (int k = 0; k < 4; k++) t += 1ll * a.num[i][k] * b.num[k][j]; n       ret.num[i][j] = t % 1000000007; n     } n   return ret; n } n int cal(string &s, string &q) { n   int ret = 0; n   for (int i = 0; i + q.size() <= s.size(); i++) n     if (s.substr(i, q.size()) == q) ret++; n   return ret; n } n int query(long long n, string &q) { n   if (n == 1) { n     return q ==  a  ? 1 : 0; n   } n   if (n == 2) { n     return q ==  b  ? 1 : 0; n   } n   string s1 =  a , s2 =  b , s =  b ; n   for (n -= 2; n && s1.size() < q.size(); n--, s1 = s2, s2 = s) s = s2 + s1; n   int f1 = cal(s1, q), f2 = cal(s, q); n   if (!n) return f2; n   s = s2.substr(s2.size() - q.size() + 1, q.size() - 1) + n       s2.substr(0, q.size() - 1); n   int t1 = cal(s, q); n   s = s1.substr(s1.size() - q.size() + 1, q.size() - 1) + n       s1.substr(0, q.size() - 1); n   int t2 = cal(s, q); n   mat res, t = mult(m2, m1); n   bool flag = 0; n   if (n % 2) res = m1, flag = 1; n   for (n /= 2; n; n >>= 1, t = mult(t, t)) n     if (n & 1) { n       if (!flag) n         res = t, flag = 1; n       else n         res = mult(res, t); n     } n   return (1ll * res.num[0][0] * f2 + 1ll * res.num[0][1] * f1 + n           1ll * res.num[0][2] * t1 + 1ll * res.num[0][3] * t2) % n          1000000007; n } n int main() { n   long long n, m; n   cin >> n >> m; n   string s; n   while (m--) cin >> s, cout << query(n, s) << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = 1e9 + 7; n string a, b; n map<pair<string, string>, int> m; n int f(string aa, string bb) { n   if (aa == bb) return 2; n   if (aa.size() % 2) return 1; n   if (m[{aa, bb}] != 0) return m[{aa, bb}]; n   string a1, b1, a2, b2; n   for (int i = 0; i < aa.size(); i++) { n     if (i < aa.size() / 2) { n       a1.push_back(aa[i]); n       b1.push_back(bb[i]); n     } else { n       a2.push_back(aa[i]); n       b2.push_back(bb[i]); n     } n   } n   if (f(a1, b1) == 2 && f(a2, b2) == 2) return m[{aa, bb}] = 2; n   if (f(a1, b2) == 2 && f(a2, b1) == 2) return m[{aa, bb}] = 2; n   return m[{aa, bb}] = 1; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   cin >> a >> b; n   if (f(a, b) == 2) n     cout <<  YES ; n   else n     cout <<  NO ; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 102, M = 102 * 102; n int n, m; n vector<pair<int, int> > g[N]; n char ans[N][N]; n char dp[N][N][28] = {0}; n void input() { n   cin >> n >> m; n   for (int i = (0); i < (m); ++i) { n     int u, v; n     char ch; n     cin >> u >> v >> ch; n     u--, v--; n     g[u].push_back(make_pair(v, ch -  a )); n   } n } n int dfs(int u, int v, char c) { n   if (dp[u][v][c] != 0) return dp[u][v][c]; n   for (auto x : g[u]) { n     int h = x.first; n     char k = x.second; n     int win = 0; n     if (k >= c) { n       win = dfs(v, h, k); n       if (win == 2) { n         dp[u][v][c] = 1; n         return 1; n       } n     } n   } n   dp[u][v][c] = 2; n   return 2; n } n void solve() { n   for (int i = (0); i < (n); ++i) { n     for (int j = (0); j < (n); ++j) { n       ans[i][j] = ((dfs(i, j, 0) == 1) ?  A  :  B ); n     } n   } n } n void output() { n   for (int i = (0); i < (n); ++i) { n     for (int j = (0); j < (n); ++j) { n       cout << ans[i][j]; n     } n     cout <<   n ; n   } n } n int main() { n   input(); n   solve(); n   output(); n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2e3 + 7; n const int inf = 1e9 + 7; n int T, n, dp[N][N], cnt[N], qzs[N][26], qzt[N][26]; n char s[N], t[N]; n void Min(int &x, int y) { n   if (x > y) x = y; n } n void Main() { n   fill(cnt, cnt + 26, 0); n   scanf( %d , &n); n   for (int i = 0, iE = n; i <= iE; i++) n     for (int j = 0, jE = n; j <= jE; j++) dp[i][j] = inf; n   scanf( %s%s , s + 1, t + 1); n   for (int i = 1, iE = n; i <= iE; i++) cnt[s[i] -  a ]++, cnt[t[i] -  a ]--; n   for (int i = 0, iE = 25; i <= iE; i++) n     if (cnt[i]) return puts( -1 ), void(); n   for (int i = 1, iE = n; i <= iE; i++) n     for (int j = 0, jE = 25; j <= jE; j++) n       qzs[i][j] = qzs[i - 1][j] + (s[i] ==  a  + j), n       qzt[i][j] = qzt[i - 1][j] + (t[i] ==  a  + j); n   for (int i = 0, iE = n; i <= iE; i++) dp[0][i] = 0; n   for (int i = 1, iE = n; i <= iE; i++) n     for (int j = i, jE = n; j <= jE; j++) { n       Min(dp[i][j], dp[i - 1][j] + 1); n       if (s[i] == t[j]) Min(dp[i][j], dp[i - 1][j - 1]); n       if (qzs[i][t[j] -  a ] < qzt[j][t[j] -  a ]) Min(dp[i][j], dp[i][j - 1]); n     } n   printf( %d n , dp[n][n]); n } n int main() { n   scanf( %d , &T); n   while (T--) Main(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, s[1000006], top, a[1000006]; n int solve(int n, int mul) { n   if (n == 1) return s[++top] = mul; n   if (n == 2) return s[++top] = mul, s[++top] = mul * 2; n   if (n == 3) return s[++top] = mul, s[++top] = mul, s[++top] = mul * 3; n   for (int i = 1; i <= (n - n / 2); i++) s[++top] = mul; n   for (int i = 1; i <= n / 2; i++) a[i] = a[i * 2] / 2; n   solve(n / 2, mul << 1); n } n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) a[i] = i; n   solve(n, 1); n   for (int i = 1; i <= n; i++) printf( %d  , s[i]); n } n


#include <bits/stdc++.h> n using namespace std; n const int SCALE = 101; n int g[SCALE * 2][SCALE * 2]; n int tx, ty; n int stepr[4] = {0, -1, 0, 1}; n int stepc[4] = {-1, 0, 1, 0}; n string s; n bool BuildMap(const string& s) { n   int x = 0; n   int y = 0; n   memset(g, 0, sizeof(g)); n   g[(x + SCALE)][(y + SCALE)] = 1; n   for (int i = 0; i < s.size(); ++i) { n     int d = 0; n     switch (s[i]) { n       case  L : n         d = 0; n         break; n       case  U : n         d = 1; n         break; n       case  R : n         d = 2; n         break; n       case  D : n         d = 3; n         break; n     } n     x += stepr[d]; n     y += stepc[d]; n     if (g[(x + SCALE)][(y + SCALE)] == 1) { n       return false; n     } else { n       g[(x + SCALE)][(y + SCALE)] = 1; n     } n   } n   tx = x; n   ty = y; n   return true; n } n int Dfs(int x, int y, int cost) { n   if (x == tx && y == ty) return cost; n   int v = 10000; n   for (int i = 0; i < 4; ++i) { n     int tmpx = x + stepr[i]; n     int tmpy = y + stepc[i]; n     int& tmpg = g[(tmpx + SCALE)][(tmpy + SCALE)]; n     if (tmpg == 1) { n       tmpg = -1; n       int tv = Dfs(tmpx, tmpy, cost + 1); n       v = min(tv, v); n       tmpg = 1; n     } n   } n   return v; n } n bool CheckShort() { n   g[(0 + SCALE)][(0 + SCALE)] = -1; n   int cost = Dfs(0, 0, 0); n   if (cost < s.size() - 1) { n     return false; n   } n   return true; n } n int main() { n   while (cin >> s) { n     bool b = BuildMap(s); n     if (b == false) { n       cout <<  BUG  << endl; n       continue; n     } n     b = CheckShort(); n     if (b == false) { n       cout <<  BUG  << endl; n       continue; n     } n     cout <<  OK  << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n istream& operator>>(istream& is, vector<T>& a) { n   for (T& ai : a) is >> ai; n   return is; n } n template <typename T> n ostream& operator<<(ostream& os, vector<T> const& a) { n   os <<  [  ; n   for (const T& ai : a) os << ai <<    ; n   return os <<  ] ; n } n template <typename T1, typename T2> n istream& operator>>(istream& is, pair<T1, T2>& a) { n   return is >> a.first >> a.second; n } n template <typename T1, typename T2> n ostream& operator<<(ostream& os, pair<T1, T2> const& a) { n   return os <<  (  << a.first <<  ,   << a.second <<  ) ; n } n int f() { n   int n, h, l, r; n   cin >> n >> h >> l >> r; n   vector<int> a(n), b(h, -1); n   cin >> a; n   b[0] = 0; n   for (int ai : a) { n     vector<int> c(h, -1); n     for (int i = 0; i < h; ++i) { n       if (b[i] < 0) continue; n       int j = i + ai - 1; n       if (j >= h) j -= h; n       c[j] = max(c[j], b[i] + (l <= j && j <= r)); n       if (++j >= h) j -= h; n       c[j] = max(c[j], b[i] + (l <= j && j <= r)); n     } n     b.swap(c); n   } n   return *max_element((b).begin(), (b).end()); n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout << f() <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct basis { n   int vis[29 + 1]; n   void ins(int x) { n     for (int i = 29; i >= 0; i--) n       if ((1 << i) & x) { n         if (vis[i]) n           x ^= vis[i]; n         else { n           vis[i] = x; n           break; n         } n       } n   } n   int minimize(int x) { n     for (int i = 29; i >= 0; i--) { n       if ((x ^ vis[i]) < x) x ^= vis[i]; n     } n     return x; n   } n }; n void merge(basis &a, basis b) { n   for (int i = 0; i <= 29; i++) a.ins(b.vis[i]); n } n namespace violet { n int pa[65536 * 4]; n int size[65536 * 4]; n basis bas[65536 * 4]; n int topa[65536 * 4]; n vector<int> dex, desize, depa, detopa; n vector<basis> debas; n void init() { n   for (int i = 0; i < 65536 * 4; i++) pa[i] = i, size[i] = 1; n } n int findpa(int x) { n   if (pa[x] == x) return x; n   return findpa(pa[x]); n } n int findtopa(int x) { n   if (pa[x] == x) return 0; n   return topa[x] ^ findtopa(pa[x]); n } n void save(int x) { n   dex.push_back(x), desize.push_back(size[x]); n   depa.push_back(pa[x]); n   detopa.push_back(topa[x]); n   debas.push_back(bas[x]); n } n void link(int x, int y, int w) { n   int rx = findpa(x); n   int ry = findpa(y); n   if (size[rx] > size[ry]) swap(x, y), swap(rx, ry); n   save(rx); n   save(ry); n   if (rx == ry) { n     bas[rx].ins(w ^ findtopa(x) ^ findtopa(y)); n   } else { n     size[ry] += size[rx]; n     merge(bas[ry], bas[rx]); n     pa[rx] = ry; n     topa[rx] = w ^ findtopa(x) ^ findtopa(y); n   } n } n void deop() { n   int x = dex[dex.size() - 1]; n   size[x] = desize[desize.size() - 1]; n   pa[x] = depa[depa.size() - 1]; n   topa[x] = detopa[detopa.size() - 1]; n   bas[x] = debas[debas.size() - 1]; n   dex.pop_back(); n   desize.pop_back(); n   depa.pop_back(); n   detopa.pop_back(); n   debas.pop_back(); n } n int ask(int x, int y) { n   return bas[findpa(x)].minimize(findtopa(x) ^ findtopa(y)); n } n };  // namespace violet n int n, m, q; n int output[65536 * 4]; n int askx[65536 * 4], asky[65536 * 4]; n vector<int> ow[65536 * 4 * 2], ox[65536 * 4 * 2], oy[65536 * 4 * 2]; n void modi(int a, int b, int l, int r, int id, int &x, int &y, int &w) { n   if (l >= a and r <= b) { n     ox[id].push_back(x); n     oy[id].push_back(y); n     ow[id].push_back(w); n     return; n   } n   int mid = (l + r) / 2; n   if (a <= mid) modi(a, b, l, mid, id << 1, x, y, w); n   if (b > mid) modi(a, b, mid + 1, r, id << 1 | 1, x, y, w); n } n vector<int> newid, oldid; n void ask(int x, int l, int r, int id) { n   newid.push_back(id); n   if (l == r) return; n   int mid = (l + r) / 2; n   if (x <= mid) n     ask(x, l, mid, id << 1); n   else n     ask(x, mid + 1, r, id << 1 | 1); n } n map<pair<int, int>, int> edge, ew; n void redo(int id) { n   for (int i = 0; i < ox[id].size(); i++) violet::deop(), violet::deop(); n } n void doit(int id) { n   for (int i = 0; i < ox[id].size(); i++) n     violet::link(ox[id][i], oy[id][i], ow[id][i]); n } n int main() { n   scanf( %d%d , &n, &m); n   violet::init(); n   while (m--) { n     int x, y, z; n     scanf( %d%d%d , &x, &y, &z); n     if (x > y) swap(x, y); n     edge[make_pair(x, y)] = 1, ew[make_pair(x, y)] = z; n   } n   scanf( %d , &q); n   for (int i = 1; i <= q; i++) { n     int op; n     scanf( %d , &op); n     if (op == 1) { n       int x, y, w; n       scanf( %d%d%d , &x, &y, &w); n       if (x > y) swap(x, y); n       edge[make_pair(x, y)] = i; n       ew[make_pair(x, y)] = w; n     } else if (op == 2) { n       int x, y; n       scanf( %d%d , &x, &y); n       if (x > y) swap(x, y); n       modi(edge[make_pair(x, y)], i, 1, 65536 * 4, 1, x, y, n            ew[make_pair(x, y)]); n       edge[make_pair(x, y)] = 0; n     } else { n       output[i] = 1; n       scanf( %d%d , &askx[i], &asky[i]); n     } n   } n   for (map<pair<int, int>, int>::iterator it = edge.begin(); it != edge.end(); n        it++) { n     if (it->second) { n       pair<int, int> p = it->first; n       modi(it->second, q, 1, 65536 * 4, 1, p.first, p.second, ew[p]); n     } n   } n   for (int i = 1; i <= q; ++i) n     if (output[i]) { n       newid.clear(); n       ask(i, 1, 65536 * 4, 1); n       int st = 0; n       for (int j = 0; j < oldid.size() and j < newid.size(); j++) n         if (oldid[j] == newid[j]) n           st = j + 1; n         else n           break; n       while (oldid.size() > st) redo(oldid[oldid.size() - 1]), oldid.pop_back(); n       for (int i = st; i < newid.size(); i++) { n         doit(newid[i]); n         oldid.push_back(newid[i]); n       } n       printf( %d n , violet::ask(askx[i], asky[i])); n     } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2e5 + 5; n int n, m; n vector<long long> b(N, 0); n void add(int x, int k) { n   while (x < N) { n     b[x] += k; n     x += x & -x; n   } n } n long long sum(int x) { n   long long ret = 0; n   while (x) { n     ret += b[x]; n     x -= x & -x; n   } n   return ret; n } n void add(int l, int r, int k) { n   if (l > r) return; n   add(l, k); n   add(r + 1, -k); n } n int main() { n   scanf( %d%d , &n, &m); n   vector<int> x(m + 1, 0); n   for (int i = 0, y; i < m; i++) { n     scanf( %d , &x[i]); n   } n   for (int i = 1; i < m; i++) { n     long long sum = 0; n     int u = x[i - 1]; n     int v = x[i]; n     if (u == v) continue; n     if (u < v) swap(u, v); n     add(1, v - 1, u - v); n     add(u + 1, n, u - v); n     add(v + 1, u - 1, u - v - 1); n     add(v, v, u - 1); n     add(u, u, v); n   } n   for (int i = 1; i <= n; i++) { n     printf( %lld%c , sum(i),    n [i == n]); n   } n   return 0; n } n


#include <bits/stdc++.h> n const double PI = n     3.141592653589793238462643383279502884197169399375105820974944; n using namespace std; n long long arr[] = {0,     9,      90,      900,      9000, n                    90000, 900000, 9000000, 90000000, 900000000}; n long long arr1[] = {0,     9,      99,      999,      9999, n                     99999, 999999, 9999999, 99999999, 999999999}; n void solve() { n   long long n; n   cin >> n; n   int digits = 0; n   long long temp = n; n   while (temp != 0) { n     ++digits; n     temp = temp / 10; n   } n   long long ans = 0; n   for (long long i = 0; i < digits; ++i) { n     ans += arr[i] * (i); n   } n   ans += (n - arr1[digits - 1]) * (digits); n   cout << ans <<   n ; n } n int main() { n   bool testing = false; n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   if (testing) { n     freopen( test.txt ,  rt , stdin); n     int start = clock(); n     solve(); n     int end = clock(); n     cout <<  time:   << (end - start) / (double)(CLOCKS_PER_SEC)*1000 n          <<   milliseconds n ; n   } else { n     solve(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int A[500][500]; n int B[500][500]; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(NULL); n   int n, m; n   cin >> n >> m; n   for (int i = 0; i < n; ++i) n     for (int j = 0; j < m; ++j) cin >> A[i][j]; n   int mx = -1e9; n   for (int i = 0; i < n; ++i) n     for (int j = 0; j < m; ++j) n       B[i][j] = A[i][j] - (i && j ? B[i - 1][j - 1] : 0) + n                 (i ? B[i - 1][j] : 0) + (j ? B[i][j - 1] : 0); n   for (int i = 0; i < n; ++i) n     for (int j = 0; j < m; ++j) { n       int rx = A[i][j]; n       for (int k = 1; i + k < n && i - k > -1 && j + k < m && j - k > -1; ++k) { n         rx += A[i - k + 1][j - k]; n         rx = B[i + k][j + k] + (i - k && j - k ? B[i - k - 1][j - k - 1] : 0) - n              (i - k ? B[i - k - 1][j + k] : 0) - n              (j - k ? B[i + k][j - k - 1] : 0) - rx; n         mx = max(mx, rx); n       } n     } n   cout << mx; n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( Ofast ) n #pragma GCC target( avx,avx2,fma ) n #pragma comment(linker,  /stack:200000000 ) n #pragma GCC optimize( unroll-loops ) n using namespace std; n template <typename A> n ostream &operator<<(ostream &cout, vector<A> const &v); n template <typename A, typename B> n ostream &operator<<(ostream &cout, pair<A, B> const &p) { n   return cout <<  (  << p.first <<  ,   << p.second <<  ) ; n } n template <typename A> n ostream &operator<<(ostream &cout, vector<A> const &v) { n   cout <<  [ ; n   for (int i = 0; i < v.size(); i++) { n     if (i) cout <<  ,  ; n     cout << v[i]; n   } n   return cout <<  ] ; n } n template <typename A, typename B> n istream &operator>>(istream &cin, pair<A, B> &p) { n   cin >> p.first; n   return cin >> p.second; n } n const long long MAXN = 1e5 + 7; n void check() { n   long long a[1000] = {0}, b[1000] = {0}, ans = 0; n   string s1, s2; n   cin >> s1 >> s2; n   for (long long i = 0; i < s1.size(); i++) a[s1[i]]++, b[s2[i]]++; n   for (long long i = 0; i < s1.size(); i++) { n     if (s2[i] != s1[i]) { n       if (a[s2[i]] < b[s2[i]]) { n         ans++; n         a[s2[i]]++; n         a[s1[i]]--; n         s1[i] = s2[i]; n       } n     } n   } n   long long cnt = 0; n   for (long long i = 0; i < s1.size(); i++) cnt += (s1[i] != s2[i]); n   cnt /= 2; n   cout << ans + cnt; n } n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int t = 1; n   for (int i = 1; i <= t; i++) { n     check(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T, size_t N> n int SIZE(const T (&t)[N]) { n   return N; n } n template <typename T> n int SIZE(const T &t) { n   return t.size(); n } n string to_string(const string s, int x1 = 0, int x2 = 1e9) { n   return     + ((x1 < s.size()) ? s.substr(x1, x2 - x1 + 1) :   ) +    ; n } n string to_string(const char *s) { return to_string((string)s); } n string to_string(const bool b) { return (b ?  true  :  false ); } n string to_string(const char c) { return string({c}); } n template <size_t N> n string to_string(const bitset<N> &b, int x1 = 0, int x2 = 1e9) { n   string t =   ; n   for (int __iii__ = min(x1, SIZE(b)), __jjj__ = min(x2, SIZE(b) - 1); n        __iii__ <= __jjj__; ++__iii__) { n     t += b[__iii__] +  0 ; n   } n   return     + t +    ; n } n template <typename A, typename... C> n string to_string(const A(&v), int x1 = 0, int x2 = 1e9, C... coords); n int l_v_l_v_l = 0, t_a_b_s = 0; n template <typename A, typename B> n string to_string(const pair<A, B> &p) { n   l_v_l_v_l++; n   string res =  (  + to_string(p.first) +  ,   + to_string(p.second) +  ) ; n   l_v_l_v_l--; n   return res; n } n template <typename A, typename... C> n string to_string(const A(&v), int x1, int x2, C... coords) { n   int rnk = rank<A>::value; n   string tab(t_a_b_s,    ); n   string res =   ; n   bool first = true; n   if (l_v_l_v_l == 0) res +=   n ; n   res += tab +  [ ; n   x1 = min(x1, SIZE(v)), x2 = min(x2, SIZE(v)); n   auto l = begin(v); n   advance(l, x1); n   auto r = l; n   advance(r, (x2 - x1) + (x2 < SIZE(v))); n   for (auto e = l; e != r; e = next(e)) { n     if (!first) { n       res +=  ,  ; n     } n     first = false; n     l_v_l_v_l++; n     if (e != l) { n       if (rnk > 1) { n         res +=   n ; n         t_a_b_s = l_v_l_v_l; n       }; n     } else { n       t_a_b_s = 0; n     } n     res += to_string(*e, coords...); n     l_v_l_v_l--; n   } n   res +=  ] ; n   if (l_v_l_v_l == 0) res +=   n ; n   return res; n } n void dbgm() { ; } n template <typename Heads, typename... Tails> n void dbgm(Heads H, Tails... T) { n   cout << to_string(H) <<   |  ; n   dbgm(T...); n } n const long long INF = 1e9; n struct Dinic { n   int nodes, src, dst; n   vector<int> dist, q, work; n   struct edge { n     int to, rev; n     long long f, cap; n   }; n   vector<vector<edge>> g; n   Dinic(int x) : nodes(x), g(x), dist(x), q(x), work(x) {} n   void add_edge(int s, int t, long long cap) { n     g[s].push_back((edge){t, ((int)g[t].size()), 0, cap}); n     g[t].push_back((edge){s, ((int)g[s].size()) - 1, 0, 0}); n   } n   bool dinic_bfs() { n     fill(dist.begin(), dist.end(), -1); n     dist[src] = 0; n     int qt = 0; n     q[qt++] = src; n     for (int qh = 0; qh < qt; qh++) { n       int u = q[qh]; n       for (int i = 0; i < ((int)g[u].size()); i++) { n         edge &e = g[u][i]; n         int v = g[u][i].to; n         if (dist[v] < 0 && e.f < e.cap) dist[v] = dist[u] + 1, q[qt++] = v; n       } n     } n     return dist[dst] >= 0; n   } n   long long dinic_dfs(int u, long long f) { n     if (u == dst) return f; n     for (int &i = work[u]; i < ((int)g[u].size()); i++) { n       edge &e = g[u][i]; n       if (e.cap <= e.f) continue; n       int v = e.to; n       if (dist[v] == dist[u] + 1) { n         long long df = dinic_dfs(v, min(f, e.cap - e.f)); n         if (df > 0) { n           e.f += df; n           g[v][e.rev].f -= df; n           return df; n         } n       } n     } n     return 0; n   } n   long long max_flow(int _src, int _dst) { n     src = _src; n     dst = _dst; n     long long result = 0; n     while (dinic_bfs()) { n       fill(work.begin(), work.end(), 0); n       while (long long delta = dinic_dfs(src, INF)) result += delta; n     } n     return result; n   } n }; n long long cost(long long a, long long b) { return a * a - b * b; } n int N; n int n, h, m; n int getPos(int i, int j) { n   if (j == 0) return N; n   if (j >= h + 1) return N + 1; n   return i * (h + 1) + j; n } n int getPos(int i) { return n * (h + 1) + i; } n int main() { n   cin >> n >> h >> m; n   N = n * (h + 1) + m; n   Dinic din(N + 2); n   for (int i = 0; i < n; i++) { n     int node = i * (h + 1); n     for (int j = 0; j < h + 1; j++) { n       int left = getPos(i, j); n       int right = getPos(i, j + 1); n       din.add_edge(left, right, cost(h, j)); n     } n   } n   for (int i = 0; i < m; i++) { n     int l, r, x, c; n     cin >> l >> r >> x >> c; n     int node = getPos(i); n     din.add_edge(node, N + 1, c); n     for (int j = l - 1; j < r; j++) { n       din.add_edge(getPos(j, x + 1), node, INF); n     } n   } n   cout << h * h * n - din.max_flow(N, N + 1) <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int t, n; n   cin >> t; n   while (t--) { n     cin >> n; n     if (n % 2) n       cout << (n + 1) / 2 << endl; n     else n       cout << n / 2 << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int ans[2010][2], n; n bool vis[510][510]; n bool query(int x1, int y1, int x2, int y2) { n   printf( ? %d %d %d %d n , x1, y1, x2, y2); n   fflush(stdout); n   char ch[5]; n   scanf( %s , ch); n   if (ch[0] ==  Y ) n     return 1; n   else n     return 0; n } n void out() { n   int x = 1, y = 1; n   printf( !  ); n   while ((x != n) || (y != n)) { n     if ((x != n) && (vis[x + 1][y])) { n       printf( D ); n       x++; n     } else { n       printf( R ); n       y++; n     } n   } n   printf(  n ); n   fflush(stdout); n } n int main() { n   int now = 1; n   scanf( %d , &n); n   int x = 1, y = 1; n   memset(vis, 0, sizeof(vis)); n   vis[0][0] = 1; n   vis[n][n] = 1; n   ans[1][0] = 1; n   ans[1][1] = 1; n   while (x + y <= n) { n     bool flag = query(x + 1, y, n, n); n     if (flag) { n       x++; n       vis[x][y] = 1; n     } else { n       y++; n       vis[x][y] = 1; n     } n     now++; n     ans[now][0] = x; n     ans[now][1] = y; n   } n   x = n; n   y = n; n   now--; n   while (x + y > n + 1) { n     if (query(ans[now][0], ans[now][1], x, y - 1)) n       y--; n     else n       x--; n     vis[x][y] = 1; n     now--; n   } n   out(); 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   int width = 2 * k + 1; n   if (width >= n) { n     printf( 1 n ); n     printf( %d , n / 2 + n % 2); n     return 0; n   } n   if (n % width == 0) { n     printf( %d n , n / width); n     for (int out = k + 1; out <= n; out += width) { n       printf( %d  , out); n     } n     return 0; n   } n   vector<int> v; n   for (int i = 1, rest; i <= k; ++i) { n     rest = n - i - k; n     if (rest % width > k || rest % width == 0) { n       for (int out = i; out <= n; out += width) { n         v.push_back(out); n       } n       break; n     } n   } n   printf( %d n , v.size()); n   for (int i = 0; i < v.size(); ++i) { n     printf( %d  , v[i]); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int n, k; n long long m, f[1005][105][2]; n long long dfs(int Index, int y, int now, int flag) { n   if (Index > n) return (flag == 0); n   if (f[Index][y][flag] != -1) return f[Index][y][flag]; n   int st = Index == n ? 1 : 0, y1; n   long long res = 0; n   for (int i = st; i <= 9; i++) { n     y1 = (y + now * i % k) % k; n     res = n         (res + dfs(Index + 1, y1, now * 10 % k, (flag && (y1 != 0 || !i)))) % m; n   } n   f[Index][y][flag] = res; n   return res; n } n int main() { n   scanf( %d %d %lld , &n, &k, &m); n   memset(f, -1, sizeof f); n   printf( %lld n , dfs(1, 0, 1, 1)); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int arr[100001]; n int a, b, n, best; n int main() { n   bool dima = true; n   scanf( %d , &n); n   for (int i = 0; i < n; ++i) { n     scanf( %d%d , &a, &b); n     arr[a] = b; n   } n   for (int i = 0; i < 100001; ++i) { n     if (arr[i] > 0) n       if (arr[i] > best) n         best = arr[i]; n       else { n         dima = false; n         break; n       } n   } n   if (dima) n     printf( Poor Alex ); n   else n     printf( Happy Alex ); n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 10, INF = 0x3f3f3f3f, MOD = 1e9 + 7; n struct P { n   long long x, y; n   P() {} n   P(long long x, long long y) : x(x), y(y) {} n   P rotate() { return P(-y, x); } n   P operator-(const P& rhs) const { return P(x - rhs.x, y - rhs.y); } n   long long operator*(const P& rhs) const { return x * rhs.x + y * rhs.y; } n   bool operator==(const P& rhs) const { return x == rhs.x && y == rhs.y; } n }; n bool judge(P& u, P& v) { n   if (v == P(0, 0)) return u == P(0, 0); n   long long w = v.x * v.x + v.y * v.y; n   return u * v % w == 0 && u * v.rotate() % w == 0; n } n P a, b, c; n int main() { n   ios_base::sync_with_stdio(0); n   while (cin >> a.x >> a.y >> b.x >> b.y >> c.x >> c.y) { n     bool ok = false; n     for (int i = 0; i < 4; ++i) { n       P d = b - a; n       if (judge(d, c)) { n         ok = true; n         break; n       } n       a = a.rotate(); n     } n     cout << (ok ?  YES  :  NO ) <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int gcd(int x, int y) { n   if (y == 0) return x; n   return gcd(y, x % y); n } n int lcm(int x, int y) { return x * y / gcd(x, y); } n long long int gcd(long long int x, long long int y) { n   if (y == 0) return x; n   return gcd(y, x % y); n } n long long int lcm(long long int x, long long int y) { n   return x * y / gcd(x, y); n } n void swap(long long int& x, long long int& y) { n   long long int temp = x; n   x = y; n   y = temp; n } n long long int binpow(long long int a, long long int b) { n   long long int res = 1; n   while (b > 0) { n     if (b & 1) res = res * a; n     a = a * a; n     b >>= 1; n   } n   return res; n } n long long int binpowM(long long int a, long long int b) { n   a %= 100000007; n   long long int res = 1; n   while (b > 0) { n     if (b & 1) res = res * a % 100000007; n     a = a * a % 100000007; n     b >>= 1; n   } n   return res; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   cout << fixed; n   int n, ans = 0, k; n   cin >> n; n   vector<int> a(3); n   for (int i = 0; i < 3; i++) { n     cin >> a[i]; n   } n   sort(a.begin(), a.end(), greater<int>()); n   int i = 0, j, l = n / a[1], m = n / a[0]; n   while (i <= m) { n     j = 0; n     while (j <= l) { n       k = n - i * a[0] - j * a[1]; n       if (k % a[2] == 0) { n         ans = max(i + j + k / a[2], ans); n       } n       j++; n     } n     i++; n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 100000 + 10; n long long A, B, N; n long long l, t, m; n int main() { n   cin >> A >> B >> N; n   for (int i = 1; i <= N; i++) { n     cin >> l >> t >> m; n     if (t < A + (l - 1) * B) { n       cout << -1 << endl; n       continue; n     } n     long long L = 1, R = 10000000, M; n     while (L <= R) { n       M = (L + R) / 2; n       if ((2 * A + (l + M - 2) * B) * (M - l + 1) > t * m * 2) n         R = M - 1; n       else n         L = M + 1; n     } n     cout << min(R, (t - A + B) / B) << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 265000; n int n, q, a[N]; n double s; n int main() { n   scanf( %d%d , &n, &q); n   for (int i = (0); i <= (int)(1 << n) - 1; i++) scanf( %d , &a[i]), s += a[i]; n   printf( %.10lf n , 1.0 * s / (1 << n)); n   for (int i = (1); i <= (int)q; i++) { n     int x, y; n     scanf( %d%d , &x, &y); n     s += y - a[x]; n     a[x] = y; n     printf( %.10lf n , 1.0 * s / (1 << n)); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int n, p, q, r, now; n int a[500050], b[500050], c[500050], id[500050], mxx[500050], mxy[500050]; n long long ans; n struct seg { n   int mark[500050 << 2], mx[500050 << 2], mn[500050 << 2]; n   long long sum[500050 << 2]; n   void push_up(int id) { n     sum[id] = sum[id << 1] + sum[id << 1 | 1]; n     mx[id] = max(mx[id << 1], mx[id << 1 | 1]); n     mn[id] = min(mn[id << 1], mn[id << 1 | 1]); n   } n   void make_con(int l, int r, int id, int val) { n     mark[id] = val; n     sum[id] = 1ll * val * (r - l + 1); n     mx[id] = mn[id] = val; n   } n   void push_down(int l, int r, int id) { n     if (mark[id]) { n       int m = l + r >> 1; n       make_con(l, m, id << 1, mark[id]); n       make_con(m + 1, r, id << 1 | 1, mark[id]); n       mark[id] = 0; n     } n   } n   void modify(int L, int R, int val, int l, int r, int id) { n     if (r < L || R < l) return; n     if (L <= l && r <= R) { n       make_con(l, r, id, val); n       return; n     } n     push_down(l, r, id); n     int m = l + r >> 1; n     modify(L, R, val, l, m, id << 1); n     modify(L, R, val, m + 1, r, id << 1 | 1); n     push_up(id); n   } n   long long sumquery(int L, int R, int l, int r, int id) { n     if (r < L || R < l) return 0; n     if (L <= l && r <= R) { n       return sum[id]; n     } n     push_down(l, r, id); n     int m = l + r >> 1; n     return sumquery(L, R, l, m, id << 1) + n            sumquery(L, R, m + 1, r, id << 1 | 1); n   } n   int lquery(int val, int l, int r, int id) { n     if (l == r) return l; n     push_down(l, r, id); n     int m = l + r >> 1; n     if (mn[id << 1] < val) return lquery(val, l, m, id << 1); n     return lquery(val, m + 1, r, id << 1 | 1); n   } n   int rquery(int val, int l, int r, int id) { n     if (l == r) return l; n     push_down(l, r, id); n     int m = l + r >> 1; n     if (mx[id << 1 | 1] >= val) return rquery(val, m + 1, r, id << 1 | 1); n     return rquery(val, l, m, id << 1); n   } n } ST; n bool cmp(int x, int y) { return a[x] < a[y]; } n void modify(int x, int y) { n   if (ST.mn[1] >= y) return; n   int l = ST.lquery(y, 1, q, 1); n   if (l <= x) ST.modify(l, x, y, 1, q, 1); n } n long long query(int x, int y) { n   long long rtn = 1ll * (q - x + 1) * (r - y + 1); n   if (ST.mx[1] < y) return rtn; n   int r = ST.rquery(y, 1, q, 1); n   if (x <= r) rtn -= ST.sumquery(x, r, 1, q, 1) - 1ll * (r - x + 1) * (y - 1); n   return rtn; n } n int main() { n   scanf( %d %d %d %d , &n, &p, &q, &r); n   for (int i = 0; i < n; i++) { n     scanf( %d %d %d , &a[i], &b[i], &c[i]); n     id[i] = i; n   } n   sort(id, id + n, cmp); n   mxx[n] = mxy[n] = 1; n   for (int i = n - 1; i >= 0; i--) { n     mxx[i] = max(mxx[i + 1], b[id[i]] + 1); n     mxy[i] = max(mxy[i + 1], c[id[i]] + 1); n   } n   for (int i = 1; i <= p; i++) { n     while (now < n && a[id[now]] < i) modify(b[id[now]], c[id[now]]), now++; n     ans += query(mxx[now], mxy[now]); n   } n   printf( %I64d n , ans); n } n


#include <bits/stdc++.h> n using namespace std; n int n; n int info[200005], sz[200005], Prev[200005 << 1], to[200005 << 1], n     cst[200005 << 1], cnt_e; n void Node(int u, int v, int c) { n   Prev[++cnt_e] = info[u], info[u] = cnt_e, to[cnt_e] = v, cst[cnt_e] = c; n } n long long G, B; n void dfs(int u, int ff) { n   sz[u] = 1; n   for (int i = info[u], v; i; i = Prev[i]) n     if ((v = to[i]) != ff) { n       dfs(v, u), sz[u] += sz[v]; n       G += (sz[v] & 1) * cst[i], B += 1ll * cst[i] * min(sz[v], 2 * n - sz[v]); n     } n } n int main() { n   int T; n   scanf( %d , &T); n   for (; T--;) { n     scanf( %d , &n); n     for (int i = 1, u, v, c; i < 2 * n; i++) n       scanf( %d%d%d , &u, &v, &c), Node(u, v, c), Node(v, u, c); n     B = G = 0, dfs(1, 0); n     for (int i = 1; i <= 2 * n; i++) info[i] = 0; n     cnt_e = 0; n     printf( %lld %lld n , G, B); n   } n } n


#include <bits/stdc++.h> n using namespace std; n signed main() { n   long long n, k; n   scanf( %lld%lld , &n, &k); n   long long coin = 0, sum = 0; n   for (long long i = 1; i <= k; i++) { n     long long a, b; n     scanf( %lld%lld , &a, &b); n     sum = (sum + a * b) % n; n     coin += b; n   } n   if (coin > n) { n     printf( -1 ); n     return 0; n   } n   if (coin < n) { n     printf( 1 ); n     return 0; n   } n   if (sum == n * (n + 1) / 2 % n) { n     printf( 1 ); n     return 0; n   } n   printf( -1 ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int mod = 1000000009, N = 4005; n int cal[N][N], fac[N]; n inline int add(int a, int b) { n   if (a < 0) a += mod; n   if (b < 0) b += mod; n   int ret = a + b; n   if (ret >= mod) n     return ret %= mod; n   else n     return ret; n } n inline int mul(int a, int b) { n   if (a < 0) a += mod; n   if (b < 0) b += mod; n   long long ret = (long long)a * b; n   if (ret >= mod) n     return ret % mod; n   else n     return ret; n } n int main() { n   memset(cal, 0, sizeof(cal)); n   cal[0][0] = 1; n   fac[0] = 1; n   for (int i = 1; i < N; i++) { n     fac[i] = mul(fac[i - 1], i); n     cal[i][0] = cal[i][i] = 1; n     for (int j = 1; j < i; j++) { n       cal[i][j] = add(cal[i - 1][j], cal[i - 1][j - 1]); n     } n   } n   int n, a, b, ans = 0; n   scanf( %d%d%d , &n, &a, &b); n   for (int i = 1; i < n - 1; i++) { n     for (int j = i + 2; j <= n; j++) { n       int cntb = j - i - 1, cnta = n - cntb; n       if (cntb > b) break; n       if (cnta > a) continue; n       ans = add(ans, mul(mul(cal[a - 1][cnta - 1], fac[a]), n                          mul(cal[b - 1][cntb - 1], fac[b]))); n     } n   } n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int mx = 5005; n int type[mx], dp[mx]; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int n, m; n   cin >> n >> m; n   for (int i = 1; i <= n; i++) { n     double x; n     cin >> type[i] >> x; n   } n   for (int i = 1; i <= n; i++) { n     int j = type[i]; n     for (int k = j; k >= 1; k--) dp[j] = max(dp[j], 1 + dp[k]); n   } n   int ret = 0; n   for (int i = 1; i <= n; i++) ret = max(ret, dp[i]); n   cout << n - ret << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n using ull = unsigned long long; n using ld = long double; n using pii = pair<int, int>; n using pll = pair<ll, ll>; n using pci = pair<char, int>; n using vi = vector<int>; n using vll = vector<ll>; n using vpii = vector<pii>; n const ll infll = 1e18 + 3; n const int maxn = 1e6 + 77; n const int nmax = 1e6 + 77; n const ll basell = 1e18 + 3; n const int mod = 1e9 + 7; n const ld eps = 1e-7; n const int inf = 1009000999; n const int nv = 100505; n const int baseint = 1000200013; n const ld PI = acos(-1.0); n inline bool EQ(ld a, ld b) { return fabs(a - b) < 1e-9; } n struct lis { n   int x, y, z; n }; n vector<lis> ans; n int vis[2 * nv]; n int used[2 * nv]; n vi g[2 * nv]; n int h[2 * nv]; n void dfs(int v, int p) { n   vis[v] = 1; n   vector<int> q; n   for (int u : g[v]) { n     if (u == p) continue; n     if (!vis[u]) { n       h[u] = h[v] + 1; n       dfs(u, v); n       if (!used[u]) q.push_back(u); n     } else { n       if (h[u] > h[v]) q.push_back(u); n     } n   } n   for (int i = 0; i + 1 < ((int)(q).size()); i += 2) { n     ans.push_back({q[i], v, q[i + 1]}); n   } n   if (((int)(q).size()) % 2 == 1 && p != -1) { n     ans.push_back({q.back(), v, p}); n     used[v] = 1; n   } n } n int inline solve() { n   ios::sync_with_stdio(NULL), cin.tie(NULL), cout.tie(NULL); n   ; n   int n, m; n   cin >> n >> m; n   for (int i = 0; i < m; ++i) { n     int a, b; n     cin >> a >> b; n     g[a - 1].push_back(b - 1); n     g[b - 1].push_back(a - 1); n   } n   for (int i = 0; i < n; ++i) { n     if (!vis[i]) dfs(i, -1); n   } n   cout << ((int)(ans).size()) <<   n ; n   for (lis u : ans) cout << u.x + 1 <<     << u.y + 1 <<     << u.z + 1 <<   n ; n   return 0; n } n int32_t main() { n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n string s; n vector<string> text; n vector<int> lens; n bool check(int w) { n   int c = 0, lines = 1; n   for (int i = 0; i < (int)(lens).size(); i++) { n     if (lens[i] > w) return false; n     if (c + lens[i] > w) { n       lines++; n       i--; n       c = 0; n     } else n       c += lens[i]; n   } n   return lines <= n; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   cin >> n; n   while (cin >> s) text.push_back(s); n   int c; n   for (int i = 0; i < (int)(text).size(); i++) { n     c = 0; n     for (int j = 0; j < (int)(text[i]).size(); j++) { n       c++; n       if (text[i][j] ==     || text[i][j] ==  - ) { n         lens.push_back(c); n         c = 0; n       } n     } n     if (c) { n       if (i != (int)(text).size() - 1) n         lens.push_back(c + 1); n       else n         lens.push_back(c); n     } n   } n   int s = 0, e = 1e9, mid; n   while (e - s > 1) { n     mid = (s + e) >> 1; n     if (check(mid)) n       e = mid; n     else n       s = mid; n   } n   cout << e <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long ans = 0; n int n; n long long a[200200]; n long long mn = 21000000000; n int main() { n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n     mn = min(mn, a[i]); n   } n   int id; n   for (int i = n - 1; i >= 0; i--) { n     if (a[i] == mn) { n       id = i; n       break; n     } n   } n   for (int i = 0; i < n; i++) { n     ans += mn; n     a[i] -= mn; n   } n   long long s = 0, c = -1; n   for (int i = (id + 1) % n; i != id; i = (i + 1) % n) { n     if (a[i] == 0) { n       c = max(c, s); n       s = 0LL; n       a[i]--; n     } else { n       s++; n     } n   } n   c = max(c, s); n   cout << ans + c << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int v[200003],mMst[200003],mMdr[200003],Mmst[200003],Mmdr[200003]; n int aib[200003]; n int lsb (int x) n { n     return x&-x; n } n void reset () n { n     for(int i=1;i<=200000;++i) n         aib[i]=0; n } n void upd (int pz, int val) n { n     for(int i=pz;i<=200000;i+=lsb(i)) n         aib[i]+=val; n } n int query (int pz) n { n     int rz=0; n     for(int i=pz;i>0;i-=lsb(i)) n         rz+=aib[i]; n     return rz; n } n int main() n { n     ios_base::sync_with_stdio(false); n     #ifdef HOME n     ifstream cin( date.in ); n     ofstream cout( date.out ); n     #endif // HOME n     long long t,a,k,x,b,i,n,j; n     cin>>n; n     for(i=1;i<=n;++i) n         cin>>v[i]; n     /// <= - > la st: n     for(i=1;i<=n;++i) n     { n         mMst[i]=query(v[i]); n         upd(v[i],2); n         int pz=0; n         int pas=(1<<17); n         while(pas) n         { n             if(pz+pas<=200000 && aib[pz+pas]==0) n                 pz+=pas; n             pas>>=1; n         } n         upd(pz+1,-1); n     } n     reset(); n     for(i=n;i>=1;--i) n     { n         mMdr[i]=query(v[i]); n         upd(v[i],2); n         int pz=0; n         int pas=(1<<17); n         while(pas) n         { n             if(pz+pas<=200000 && aib[pz+pas]==0) n                 pz+=pas; n             pas>>=1; n         } n         upd(pz+1,-1); n     } n     reset(); n     for(i=1;i<=n;++i) n         v[i]=n+1-v[i]; n     for(i=1;i<=n;++i) n     { n         Mmst[i]=query(v[i]); n         upd(v[i],2); n         int pz=0; n         int pas=(1<<17); n         while(pas) n         { n             if(pz+pas<=200000 && aib[pz+pas]==0) n                 pz+=pas; n             pas>>=1; n         } n         upd(pz+1,-1); n     } n     reset(); n     for(i=n;i>=1;--i) n     { n         Mmdr[i]=query(v[i]); n         upd(v[i],2); n         int pz=0; n         int pas=(1<<17); n         while(pas) n         { n             if(pz+pas<=200000 && aib[pz+pas]==0) n                 pz+=pas; n             pas>>=1; n         } n         upd(pz+1,-1); n     } n     for(i=1;i<=n;++i) n     { n         int a=mMst[i]+mMdr[i]; n         int rz=a/2; n         a=Mmst[i]+Mmdr[i]; n         rz=max(rz,(a+1)/2); n         cout<<rz<<   ; n     } n     return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 131072 | 5, mod = 998244353; n int add(int x, int y) { return (x += y) >= mod ? x - mod : x; } n void ADD(int &x, int y) { (x += y) >= mod ? x -= mod : 0; } n int qpow(int a, int b) { n   int ans = 1; n   for (; b >= 1; b >>= 1, a = (long long)a * a % mod) n     if (b & 1) ans = (long long)ans * a % mod; n   return ans; n } n int rev[N], W[N]; n int getn(int len) { n   int n = 1; n   while (n < len) n <<= 1; n   return n; n } n void prework(int n) { n   for (int i = 1; i < n; i <<= 1) { n     W[i] = 1; n     int w = qpow(3, (mod - 1) / (i << 1)); n     for (int j = 1; j < i; j++) W[i + j] = (long long)W[i + j - 1] * w % mod; n   } n } n void NTT(vector<int> &a, int n, int op) { n   a.resize(n); n   for (int i = 1; i < n; i++) n     if (i < (rev[i] = (rev[i >> 1] >> 1) | (i & 1 ? n >> 1 : 0))) n       swap(a[i], a[rev[i]]); n   for (int i = 1; i < n; i <<= 1) { n     for (int j = 0; j < n; j += i << 1) { n       for (int k = 0; k < i; k++) { n         int q = (long long)W[i + k] * a[j + k + i] % mod; n         a[j + k + i] = add(a[j + k], mod - q); n         ADD(a[j + k], q); n       } n     } n   } n   if (op == 1) return; n   reverse(a.begin() + 1, a.end()); n   int inv = mod - (mod - 1) / n; n   for (int i = 0; i <= n - 1; ++i) a[i] = (long long)a[i] * inv % mod; n } n vector<int> operator*(vector<int> a, vector<int> b) { n   int t = a.size() + b.size() - 1, n = getn(t); n   NTT(a, n, 1); n   NTT(b, n, 1); n   for (int i = 0; i <= n - 1; ++i) a[i] = (long long)a[i] * b[i] % mod; n   NTT(a, n, -1); n   a.resize(t); n   return a; n } n vector<int> fix(vector<int> a, int n) { n   a.resize(n); n   return a; n } n vector<int> Inv(vector<int> a) { n   int sz = a.size(); n   vector<int> c(1, qpow(a[0], mod - 2)), t; n   for (int i = 1; i < sz; i <<= 1) { n     NTT(t = fix(a, i << 1), i << 2, 1); n     NTT(c, i << 2, 1); n     for (int j = 0; j < (i << 2); j++) n       c[j] = (2 * c[j] - (long long)t[j] * c[j] % mod * c[j] % mod + mod) % mod; n     NTT(c, i << 2, -1); n     c.resize(i << 1); n   } n   c.resize(sz); n   return c; n } n int main() { n   int n; n   scanf( %d , &n); n   const int m = max(n + 1, 32); n   vector<int> a = {0,         0,   0,  24,  4,        144, mod - 4, 348, n                    mod - 128, 240, 28, 188, mod - 68, 16,  0,       4}; n   vector<int> b = {1,        0,       mod - 4, mod - 8, 1,        mod - 16, n                    10,       mod - 4, 12,      48,      mod - 26, 44, n                    mod - 15, 16,      4,       4,       1}; n   a.resize(m); n   b.resize(m); n   prework(2 * m); n   a = a * Inv(b); n   printf( %d n , a[n]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m, h, k; n   cin >> n >> m >> h >> k; n   cout << ((n > m) ?  First  :  Second ) << endl; n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( Ofast ) n using namespace std; n mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); n long long int myRand(long long int B) { return (unsigned long long)rng() % B; } n const int N = 51; n int vld[N][N][N][N]; n int main() { n   cin.tie(nullptr); n   ios::sync_with_stdio(false); n   int h, w, q; n   cin >> h >> w >> q; n   vector<string> s(h); n   for (int i = 0; i < h; i++) { n     cin >> s[i]; n   } n   vector<vector<int>> sum(h + 1, vector<int>(w + 1)); n   for (int i = 0; i < h; i++) { n     for (int j = 0; j < w; j++) { n       sum[i + 1][j + 1] = (s[i][j] ==  0 ); n     } n   } n   for (int i = 0; i < h; i++) { n     for (int j = 0; j <= w; j++) { n       sum[i + 1][j] += sum[i][j]; n     } n   } n   for (int j = 0; j < w; j++) { n     for (int i = 0; i <= h; i++) { n       sum[i][j + 1] += sum[i][j]; n     } n   } n   for (int i = 1; i <= h; i++) { n     for (int j = 1; j <= w; j++) { n       for (int k = i; k <= h; k++) { n         for (int l = j; l <= w; l++) { n           if ((l - j + 1) * (k - i + 1) == n               sum[k][l] - sum[i - 1][l] - sum[k][j - 1] + sum[i - 1][j - 1]) { n             vld[i][j][k][l] = 1; n           } n         } n       } n     } n   } n   for (int i = 0; i < h; i++) { n     for (int j = 0; j <= w; j++) { n       for (int k = 0; k <= h; k++) { n         for (int l = 0; l <= w; l++) { n           vld[i + 1][j][k][l] += vld[i][j][k][l]; n         } n       } n     } n   } n   for (int i = 0; i <= h; i++) { n     for (int j = 0; j < w; j++) { n       for (int k = 0; k <= h; k++) { n         for (int l = 0; l <= w; l++) { n           vld[i][j + 1][k][l] += vld[i][j][k][l]; n         } n       } n     } n   } n   for (int i = 0; i <= h; i++) { n     for (int j = 0; j <= w; j++) { n       for (int k = 0; k < h; k++) { n         for (int l = 0; l <= w; l++) { n           vld[i][j][k + 1][l] += vld[i][j][k][l]; n         } n       } n     } n   } n   for (int i = 0; i <= h; i++) { n     for (int j = 0; j <= w; j++) { n       for (int k = 0; k <= h; k++) { n         for (int l = 0; l < w; l++) { n           vld[i][j][k][l + 1] += vld[i][j][k][l]; n         } n       } n     } n   } n   while (q--) { n     int a, b, c, d; n     cin >> a >> b >> c >> d; n     printf( %d n , vld[c][d][c][d] - vld[a - 1][d][c][d] - vld[c][b - 1][c][d] + n                        vld[a - 1][b - 1][c][d]); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2e5 + 10; n int n, a[N]; n int main() { n   cin >> n; n   for (int i = 1; i <= n; i++) cin >> a[i]; n   int s = 0; n   for (int i = 1; i <= n; i++) s ^= a[i]; n   if (n % 2 == 0) { n     if (s != 0) { n       cout <<  NO n ; n       return 0; n     } n     n--; n   } n   cout <<  YES n ; n   cout << n - 2 <<   n ; n   for (int i = 1; i <= n - 2; i += 2) n     cout << i <<     << i + 1 <<     << i + 2 <<   n ; n   for (int i = 1; i <= n - 4; i += 2) n     cout << i <<     << i + 1 <<     << n <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int nums[105]; n int main() { n   int n, m, mayor; n   cin >> n >> m; n   for (int i = 0; i < n; i++) { n     cin >> nums[i]; n   } n   sort(nums, nums + n); n   reverse(nums, nums + n); n   int maximo = nums[0] + m; n   mayor = nums[0]; n   for (int i = 0; i < n; i++) { n     m -= mayor - nums[i]; n     nums[0] = mayor; n   } n   int i = 0; n   while (m > 0) { n     m--; n     nums[i % n]++; n     i++; n   } n   int minimo = nums[0]; n   cout << minimo <<     << maximo <<   n ; n } n


#include <bits/stdc++.h> n const int oo = 0x3f3f3f3f; n template <typename T> n inline bool chkmax(T &a, T b) { n   return a < b ? a = b, true : false; n } n template <typename T> n inline bool chkmin(T &a, T b) { n   return a > b ? a = b, true : false; n } n template <typename T> n T read(T &first) { n   int f = 1; n   char ch = getchar(); n   for (; !isdigit(ch); ch = getchar()) n     if (ch ==  - ) f = -1; n   for (first = 0; isdigit(ch); ch = getchar()) first = 10 * first + ch -  0 ; n   return first *= f; n } n template <typename T> n void write(T first) { n   if (first == 0) { n     putchar( 0 ); n     return; n   } n   if (first < 0) { n     putchar( - ); n     first = -first; n   } n   static char s[20]; n   int top = 0; n   for (; first; first /= 10) s[++top] = first % 10 +  0 ; n   while (top) putchar(s[top--]); n } n const int MAXN = 2e5 + 5; n const int CNT = 60; n int N; n std::pair<int, int> A[MAXN]; n int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } n inline int count(int i, int j) { n   return gcd(std::abs(A[j].first - A[i].first), n              std::abs(A[j].second - A[i].second)); n } n inline long long cross(const std::pair<int, int> &a, n                        const std::pair<int, int> &b) { n   return (long long)a.first * b.second - (long long)a.second * b.first; n } n void input() { n   read(N); n   for (int i = 0; i < N; ++i) { n     read(A[i].first); n     read(A[i].second); n   } n } n void solve() { n   memcpy(A + N, A, sizeof(*A) * N); n   long long a = 0, b = 0; n   for (int i = 0; i < N; ++i) { n     a += cross(A[i], A[i + 1]); n     b += count(i, i + 1); n   } n   long double coef[MAXN]; n   long double tnn = pow((long double)2, -N); n   for (int i = 2; i <= CNT && i < N - 1; ++i) { n     coef[i] = pow((long double)2, -i - 1) - tnn; n   } n   long double ans = 0.5 * a - 0.5 * b + 1; n   long double contrib = 0; n   for (int i = 0; i < N; ++i) { n     a = cross(A[i], A[i + 1]); n     b = count(i, i + 1); n     for (int k = 2; k <= CNT && k < N - 1; ++k) { n       int j = i + k; n       a += cross(A[j - 1], A[j]); n       b += count(j - 1, j); n       long long a0 = cross(A[j], A[i]); n       long long b0 = count(j, i); n       contrib += (0.5 * (a + a0) - 0.5 * (b + b0) + b0) * coef[k]; n     } n   } n   ans -= contrib / (1 - tnn - N * tnn - (long long)N * (N - 1) / 2 * tnn); n   printf( %.15f n , (double)ans); n } n int main() { n   input(); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a[107], b[107]; n int main() { n   int m, s; n   cin >> m >> s; n   int ss = s; n   if (s >= 2 and s <= m * 9) { n     s--; n     a[m] = 1; n     for (int i = 1; i <= m; i++) { n       if (s > 9) { n         a[i] += 9; n         s -= 9; n       } else { n         a[i] += s; n         break; n       } n     } n     for (int i = m; i > 0; i--) { n       cout << a[i]; n     } n     cout <<    ; n     for (int i = m; i > 0; i--) { n       if (ss > 9) { n         b[i] = 9; n         ss -= 9; n       } else { n         b[i] += ss; n         break; n       } n     } n     for (int i = m; i > 0; i--) { n       cout << b[i]; n     } n   } else { n     if (s == 1) { n       cout << 1; n       for (int i = 1; i < m; i++) { n         cout << 0; n       } n       cout <<    ; n       cout << 1; n       for (int i = 1; i < m; i++) { n         cout << 0; n       } n     } else { n       if (m == 1 and s == 0) { n         cout << 0 <<     << 0; n       } else { n         cout << -1 <<     << -1; n       } n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long F[401000], Mod = 998244353, InvF[401000]; n long long Pow(long long a, long long b) { n   long long r = 1; n   while (b) { n     if (b & 1) r = r * a % Mod; n     a = a * a % Mod; n     b >>= 1; n   } n   return r; n } n int A[201000], n, K; n long long S[201000], res; n long long Comb(int a, int b) { n   return F[a] * InvF[b] % Mod * InvF[a - b] % Mod; n } n int main() { n   int i; n   F[0] = 1; n   for (i = 1; i <= 400000; i++) F[i] = F[i - 1] * i % Mod; n   InvF[i - 1] = Pow(F[i - 1], Mod - 2); n   for (i = i - 1; i >= 1; i--) InvF[i - 1] = InvF[i] * i % Mod; n   scanf( %d%d , &n, &K); n   for (i = 0; i < n; i++) { n     scanf( %d , &A[i]); n   } n   int c2 = 0, c1 = 0; n   for (i = 0; i < n; i++) { n     if (A[i] == A[(i + 1) % n]) n       c2++; n     else n       c1++; n   } n   for (i = 0; i <= c1; i++) { n     if (i % 2 == 1) { n       S[i] = Pow(2, i - 1) % Mod; n     } else { n       S[i] = (Pow(2, i) - Comb(i, i / 2) + Mod) * (Mod / 2 + 1) % Mod; n     } n   } n   for (i = 0; i <= c1; i++) { n     if (K >= 2 || i == c1) { n       res = (res + Pow(K - 2, c1 - i) * S[i] % Mod * Comb(c1, i)) % Mod; n     } n   } n   res = res * Pow(K, c2) % Mod; n   printf( %lld n , res); n } n


#include <bits/stdc++.h> n int n, p[110], i, j, cnt; n char s[110]; n int main() { n   scanf( %d , &n); n   for (i = 0; i < n; i++) scanf( %d , &p[i]); n   gets(s); n   for (i = 0; i < n; i++) { n     gets(s); n     cnt = 0; n     for (j = 0; s[j]; j++) n       if (s[j] ==  a  || s[j] ==  e  || s[j] ==  i  || s[j] ==  o  || n           s[j] ==  u  || s[j] ==  y ) n         cnt++; n     if (cnt != p[i]) goto fuck; n   } n   puts( YES ); n   return 0; n fuck: n   puts( NO ); n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 1e6 + 7; n long long n, q; n long long a[N]; n long long l[N], r[N]; n void read() { n   cin >> n >> q; n   for (long long i = 0; i < n; ++i) cin >> a[i]; n   for (long long i = 0; i < q; ++i) cin >> l[i]; n   for (long long i = 0; i < q; ++i) cin >> r[i]; n   for (long long i = 0; i < q; ++i) { n     --l[i]; n     --r[i]; n   } n } n long long ans[N]; n long long link[N]; n vector<long long> add[N], del[N]; n long long f[N], fcnt[N]; n void addf(long long i) { n   long long t = i; n   for (; i < N; i |= (i + 1)) { n     f[i] += t; n   } n } n void addfcnt(long long i) { n   for (; i < N; i |= (i + 1)) { n     fcnt[i]++; n   } n } n void add_(long long i) { n   addf(i); n   addfcnt(i); n } n long long getsum(long long i) { n   long long ans = 0; n   for (; i >= 0; i = (i & (i + 1)) - 1) { n     ans += f[i]; n   } n   return ans; n } n long long getcnt(long long i) { n   long long ans = 0; n   for (; i >= 0; i = (i & (i + 1)) - 1) { n     ans += fcnt[i]; n   } n   return ans; n } n long long getmax(long long x) { n   return getcnt(x) * x + getsum(N - 1) - getsum(x); n } n long long pref[N]; n void kek() { n   for (long long i = 0; i < N; ++i) { n     f[i] = fcnt[i] = 0; n   } n   for (long long i = 0; i < q; ++i) { n     ans[i] += pref[r[i] + 1] - pref[l[i]]; n   } n   for (long long i = 0; i < N; ++i) f[i] = fcnt[i] = 0; n   for (long long i = 0; i < n; ++i) { n     add[i].clear(); n     del[i].clear(); n   } n   for (long long i = 0; i < n; ++i) link[i] = -1; n   vector<long long> st; n   for (long long i = n - 1; i >= 0; --i) { n     while (st.size() && a[i] > a[st.back()]) { n       link[st.back()] = i; n       st.pop_back(); n     } n     st.push_back(i); n   } n   for (long long i = 0; i < q; ++i) { n     add[r[i]].push_back(i); n     if (l[i]) del[l[i] - 1].push_back(i); n   } n   for (long long i = 0; i < n; ++i) { n     add_(link[i] + 1); n     for (long long e : add[i]) { n       ans[e] -= getmax(l[e]); n     } n     for (long long e : del[i]) { n       ans[e] += getmax(l[e]); n     } n   } n } n void solve() { n   for (long long i = 0; i < n; ++i) { n     pref[i + 1] = pref[i] + i; n   } n   for (long long i = 0; i < q; ++i) { n     ans[i] = r[i] - l[i] + 1; n   } n   kek(); n   reverse(a, a + n); n   for (long long i = 0; i < q; ++i) { n     l[i] = n - 1 - l[i]; n     r[i] = n - 1 - r[i]; n     swap(l[i], r[i]); n   } n   kek(); n } n void print() { n   for (long long i = 0; i < q; ++i) cout << ans[i] <<    ; n   cout <<   n ; n } n signed main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.precision(20); n   read(); n   solve(); n   print(); n } n


#include <bits/stdc++.h> n using namespace std; n template <class t> n inline t read(t &x) { n   x = 0; n   char c = getchar(); n   bool f = 0; n   while (!isdigit(c)) f |= c ==  - , c = getchar(); n   while (isdigit(c)) x = (x << 1) + (x << 3) + (c ^ 48), c = getchar(); n   if (f) x = -x; n   return x; n } n template <class t> n inline void write(t x) { n   if (x < 0) { n     putchar( - ), write(-x); n   } else { n     if (x > 9) write(x / 10); n     putchar( 0  + x % 10); n   } n } n const int N = 1e5 + 5; n int n, x[N], y[N], px, py; n signed main() { n   read(n); n   if (n & 1) { n     puts( NO ); n     return 0; n   } n   for (int i = 1; i <= n; i++) read(x[i]), read(y[i]); n   px = x[1] + x[n / 2 + 1]; n   py = y[1] + y[n / 2 + 1]; n   for (int i = 1, j = n / 2 + 1; j <= n; i++, j++) n     if (x[i] + x[j] != px || y[i] + y[j] != py) { n       puts( NO ); n       return 0; n     } n   puts( YES ); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int a, b, s; n   scanf( %d%d%d , &a, &b, &s); n   int req = abs(a) + abs(b); n   if (req > s) { n     printf( No n ); n   } else { n     int cur = s - req; n     if (cur & 1) { n       printf( No n ); n     } else { n       printf( Yes n ); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int dx[] = {0, 0, 1, -1}; n int dy[] = {1, -1, 0, 0}; n int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1}; n int dy8[] = {1, -1, -1, 0, 1, -1, 0, 1}; n int kx8[] = {1, 1, 2, 2, -1, -1, -2, -2}; n int ky8[] = {2, -2, 1, -1, 2, -2, 1, -1}; n long long poww(long long a, long long b) { n   if (b == 0) return 1; n   long long x = poww(a, b / 2); n   x = x * x; n   if (b % 2 == 1) x = x * a; n   return x; n } n long long bigmod(long long a, long long b, long long c) { n   if (b == 0) return 1 % c; n   long long x = bigmod(a, b / 2, c); n   x = x * x % c; n   if (b % 2 == 1) x = x * a % c; n   return x; n } n long long mod_inverse(long long a, long long mod) { n   return bigmod(a, mod - 2, mod); n } n int a[100005 * 3], sp[20][100005 * 3], lg[100005 * 3], n; n int spp[20][100005 * 3]; n void logcal() { n   int cnt = 0; n   int p = 2; n   while (p <= 300000) { n     lg[p] = 1; n     p *= 2; n   } n   for (int i = 0; i <= 300000; i++) { n     if (lg[i]) { n       cnt++; n     } n     lg[i] = cnt; n   } n } n long long query1(int l, int r) { n   int ln = lg[r - l + 1]; n   int k = 1 << ln; n   int df = r - l + 1 - k; n   return (min(sp[ln][l], sp[ln][l + df])); n } n long long query2(int l, int r) { n   int ln = lg[r - l + 1]; n   int k = 1 << ln; n   int df = r - l + 1 - k; n   return (max(spp[ln][l], spp[ln][l + df])); n } n long long dp[100005 * 3]; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   logcal(); n   cin >> n; n   for (int i = 1; i <= n; i++) { n     cin >> a[i]; n   } n   for (int i = 1; i <= n; i++) { n     sp[0][i] = a[i]; n     spp[0][i] = a[i]; n   } n   for (int i = 1; 1 << i <= n; i++) { n     for (int j = 1; j + (1 << i) <= n + 1; j++) { n       sp[i][j] = min(sp[i - 1][j], sp[i - 1][j + (1 << (i - 1))]); n       spp[i][j] = max(spp[i - 1][j], spp[i - 1][j + (1 << (i - 1))]); n     } n   } n   for (int i = 1; i <= n; i++) dp[i] = 2134567891; n   int N = n; n   for (int i = 1; i <= N; i++) { n     dp[i] = min(dp[i - 1] + 1, dp[i]); n     int lw = 1, hi = i - 1, ans = 0, mid; n     while (lw <= hi) { n       int mid = (lw + hi) / 2; n       int mx = query2(mid, i - 1); n       if (mx >= a[i]) { n         lw = mid + 1; n         ans = mid; n       } else { n         hi = mid - 1; n       } n     } n     if (ans > 0) { n       dp[i] = min(dp[ans] + 1, dp[i]); n     } n     lw = i + 1, hi = n, ans = 0, mid; n     while (lw <= hi) { n       int mid = (lw + hi) / 2; n       int mx = query2(i + 1, mid); n       if (mx >= a[i]) { n         ans = mid; n         hi = mid - 1; n       } else { n         lw = mid + 1; n       } n     } n     if (ans <= n && ans > 0) { n       dp[ans] = min(dp[ans], dp[i] + 1); n     } n     lw = 1, hi = i - 1, ans = 0, mid; n     while (lw <= hi) { n       int mid = (lw + hi) / 2; n       int mn = query1(mid, i - 1); n       if (mn > a[i]) { n         hi = mid - 1; n       } else { n         lw = mid + 1; n         ans = mid; n       } n     } n     if (ans > 0) { n       dp[i] = min(dp[ans] + 1, dp[i]); n     } n     lw = i + 1, hi = n, ans = 0, mid; n     while (lw <= hi) { n       int mid = (lw + hi) / 2; n       int mn = query1(i + 1, mid); n       if (mn > a[i]) { n         lw = mid + 1; n       } else { n         hi = mid - 1; n         ans = mid; n       } n     } n     if (ans <= n && ans > 0) { n       dp[ans] = min(dp[ans], dp[i] + 1); n     } n   } n   cout << dp[n] - 1 << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct node { n   int x, y; n   int num; n }; n node point[303]; n char str[5][105]; n int t, n, k; n int flag = 0; n int Flag[5][105]; n queue<node> Q; n void bfs() { n   while (!Q.empty()) { n     node D = Q.front(), R; n     Q.pop(); n     if (D.x >= n) { n       flag = 1; n     } n     if (D.num == 1 && str[D.y][D.x + 1] ==  . ) { n       for (int j = D.y - 1; j <= D.y + 1; j++) { n         if (str[j][D.x + 1] ==  .  && Flag[j][D.x + 1] == 0) { n           R.num = 2; n           R.x = D.x + 1; n           R.y = j; n           Q.push(R); n           Flag[j][D.x + 1] = 1; n         } n       } n     } else if (D.num == 2 && str[D.y][D.x + 1] ==  .  && n                str[D.y][D.x + 2] ==  . ) { n       R.num = 1; n       R.x = D.x + 2; n       R.y = D.y; n       Q.push(R); n     } n   } n } n int main() { n   int u, v; n   scanf( %d , &t); n   while (t--) { n     memset(Flag, 0, sizeof(Flag)); n     flag = 0; n     scanf( %d%d , &n, &k); n     for (int j = 1; j <= 3; j++) scanf( %s , str[j] + 1); n     for (int i = 1; i <= 3; i++) { n       if (str[i][1] ==  s ) u = i; n     } n     for (int i = 1; i <= n + 1; i++) { n       str[0][i] =  A ; n       str[4][i] =  A ; n     } n     for (int i = 0; i <= 4; i++) str[i][n + 1] =  . ; n     node W; n     W.x = 1; n     W.y = u; n     W.num = 1; n     Q.push(W); n     bfs(); n     if (flag) n       printf( YES n ); n     else n       printf( NO n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m; n   cin >> n >> m; n   int arr[100]; n   for (int counter = 0; counter < n; counter++) { n     cin >> arr[counter]; n   } n   sort(arr, arr + n); n   int sum = 0; n   for (int counter = n - 1; counter >= 0; counter--) { n     sum += arr[counter]; n     if (sum >= m) { n       cout << n - counter; n       break; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n inline T bigmod(T p, T e, T M) { n   long long ret = 1; n   for (; e > 0; e >>= 1) { n     if (e & 1) ret = (ret * p) % M; n     p = (p * p) % M; n   } n   return (T)ret; n } n template <class T> n inline T gcd(T a, T b) { n   if (b == 0) return a; n   return gcd(b, a % b); n } n template <class T> n inline T modinverse(T a, T M) { n   return bigmod(a, M - 2, M); n } n template <class T> n inline T lcm(T a, T b) { n   a = abs(a); n   b = abs(b); n   return (a / gcd(a, b)) * b; n } n template <class T, class X> n inline bool getbit(T a, X i) { n   T t = 1; n   return ((a & (t << i)) > 0); n } n template <class T, class X> n inline T setbit(T a, X i) { n   T t = 1; n   return (a | (t << i)); n } n template <class T, class X> n inline T resetbit(T a, X i) { n   T t = 1; n   return (a & (~(t << i))); n } 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 inline long long power(long long a, long long b) { n   long long multiply = 1; n   for (int i = (0); i < (b); i++) { n     multiply *= a; n   } n   return multiply; n } n int n, q, type, l, r, k, a[100002], blockSZ; n vector<int> v[318]; n int sz, cnt[100002][318]; n void Shift(int to, int from) { n   int b1 = -1, b2 = -1; n   int s = 0, idx1, idx2; n   if (to == from) return; n   for (int i = (0); i < (sz + 1); i++) { n     if (b1 == -1 && s + (int)v[i].size() > from) { n       b1 = from - s; n       idx1 = i; n     } n     if (b2 == -1 && s + (int)v[i].size() > to) { n       b2 = to - s; n       idx2 = i; n     } n     s += v[i].size(); n   } n   int val = v[idx1][b1]; n   v[idx1].erase(v[idx1].begin() + b1); n   v[idx2].insert(v[idx2].begin() + b2, val); n   cnt[val][idx1]--; n   cnt[val][idx2]++; n } n int Query(int from, int to, int x) { n   int s = 0, idx1 = -1, idx2 = -1, b1 = -1, b2 = -1; n   for (int i = (0); i < (sz + 1); i++) { n     if (idx1 == -1 && s + (int)v[i].size() > from) { n       idx1 = i; n       b1 = from - s; n     } n     if (idx2 == -1 && s + (int)v[i].size() > to) { n       idx2 = i; n       b2 = to - s; n     } n     s += v[i].size(); n   } n   int ret = 0; n   for (int i = (idx1 + 1); i < (idx2); i++) { n     ret += cnt[x][i]; n   } n   if (idx1 != idx2) { n     for (int i = (b1); i < (v[idx1].size()); i++) { n       if (v[idx1][i] == x) ret++; n     } n     for (int i = (0); i < (b2 + 1); i++) { n       if (v[idx2][i] == x) ret++; n     } n   } else { n     for (int i = (b1); i < (b2 + 1); i++) { n       if (v[idx1][i] == x) ret++; n     } n   } n   return ret; n } n void Rebuild() { n   vector<int> temp; n   for (int i = (0); i < (sz + 1); i++) { n     for (int j = (0); j < (v[i].size()); j++) { n       temp.push_back(v[i][j]); n       cnt[v[i][j]][i]--; n     } n     v[i].clear(); n   } n   sz = 0; n   for (int i = (0); i < (n); i++) { n     v[sz].push_back(temp[i]); n     cnt[temp[i]][sz]++; n     if (i + 1 < n && (i + 1) % blockSZ == 0) sz++; n   } n } n void Print() { n   cout <<  All numbers:  ; n   for (int i = (0); i < (sz + 1); i++) { n     for (int j = (0); j < (v[i].size()); j++) cout << v[i][j] <<    ; n   } n   cout <<   n ; n   cout <<  All vectors:   n        <<   n ; n   for (int i = (0); i < (sz + 1); i++) { n     for (int J = (0); J < (v[i].size()); J++) cout << v[i][J] <<    ; n     cout <<   n ; n   } n } n int main() { n   int test, cases = 1; n   scanf( %d , &n); n   blockSZ = 700; n   for (int i = (0); i < (n); i++) { n     scanf( %d , &a[i]); n   } n   for (int i = (0); i < (n); i++) { n     v[sz].push_back(a[i]); n     cnt[a[i]][sz]++; n     if (i + 1 < n && (i + 1) % blockSZ == 0) sz++; n   } n   scanf( %d , &q); n   int last = 0, shift = 0; n   while (q--) { n     scanf( %d , &type); n     if (type == 1) { n       scanf( %d%d , &l, &r); n       l = ((l + last - 1) % n) + 1; n       r = ((r + last - 1) % n) + 1; n       l--, r--; n       if (l > r) swap(l, r); n       Shift(l, r); n       shift++; n     } else { n       scanf( %d%d%d , &l, &r, &k); n       l = ((l + last - 1) % n) + 1; n       r = ((r + last - 1) % n) + 1; n       k = ((k + last - 1) % n) + 1; n       l--, r--; n       if (l > r) swap(l, r); n       last = Query(l, r, k); n       printf( %d n , last); n     } n     if (shift == 1200) { n       Rebuild(); n       shift = 0; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 32768 - 1; n int ans[100500]; n bool use[100500]; n int res; n string s =   ; n int eval_num(int n, int &i); n int eval_product(int n, int &i); n int eval_sum(int n, int &i); n bool eval_logick(int n, int &i); n int eval_op(int n, int &i); n int eval_opseq(int n, int &i); n int eval_func(int n, int &i); n int run(int n); n const string dels =     n ; n const string ops =  (){}+-*/;<> ; n bool has(string t, char c) { n   for (int i = 0; i < t.length(); ++i) n     if (t[i] == c) return true; n   return false; n } n string getlex(int &i) { n   string t =   ; n   while (has(dels, s[i])) ++i; n   if (has(ops, s[i])) { n     t += s[i++]; n     return t; n   } n   if (s[i] ==  =  && s[i + 1] ==  = ) { n     t +=  == ; n     i += 2; n     return t; n   } n   while (!((has(dels, s[i]) || has(ops, s[i]) || s[i] ==  = ))) t += s[i++]; n   return t; n } n int norm(int x) { n   while (x < 0) x += MAXN + 1; n   return x % (MAXN + 1); n } n int eval_num(int n, int &i) { n   string sw = getlex(i); n   if (sw ==  n ) return n; n   if (sw ==  f ) { n     getlex(i); n     int t = eval_sum(n, i); n     getlex(i); n     return run(t); n   } n   return atoi(sw.c_str()); n } n int eval_product(int n, int &i) { n   int sum = eval_num(n, i); n   int j = i; n   string op = getlex(j); n   while (op ==  *  || op ==  / ) { n     int t = eval_num(n, j); n     i = j; n     if (op ==  * ) n       sum *= t; n     else n       sum /= t; n     sum = norm(sum); n     op = getlex(j); n   } n   return sum; n } n int eval_sum(int n, int &i) { n   int sum = eval_product(n, i); n   int j = i; n   string op = getlex(j); n   while (op ==  +  || op ==  - ) { n     int t = eval_product(n, j); n     i = j; n     if (op ==  + ) n       sum += t; n     else n       sum -= t; n     sum = norm(sum); n     op = getlex(j); n   } n   return sum; n } n bool eval_logick(int n, int &i) { n   int e1 = eval_sum(n, i); n   string op = getlex(i); n   int e2 = eval_sum(n, i); n   if (op ==  > ) return (e1 > e2); n   if (op ==  < ) return (e1 < e2); n   if (op ==  == ) return (e1 == e2); n   exit(0); n   return false; n } n int eval_op(int n, int &i) { n   string sw = getlex(i); n   if (sw ==  if ) { n     string t = getlex(i); n     if (t !=  ( ) exit(0); n     bool b = eval_logick(n, i); n     t = getlex(i); n     if (b) { n       getlex(i); n     } else { n       while (s[i] !=  ; ) ++i; n       ++i; n       return -1; n     } n   } n   int ret = eval_sum(n, i); n   getlex(i); n   return ret; n } n int eval_func(int n, int &i) { n   while (s[i] !=  { ) ++i; n   ++i; n   int ret = -1; n   while (ret < 0) { n     ret = eval_op(n, i); n   } n   return ret; n } n int run(int n) { n   int j = 0; n   if (use[n]) return ans[n]; n   use[n] = true; n   ans[n] = eval_func(n, j); n   return ans[n]; n } n int main() { n   cin >> res; n   string t; n   while (!feof(stdin)) { n     getline(cin, t); n     s += t +    ; n   } n   s +=    ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; n   for (int i = 0; i <= MAXN; ++i) run(i); n   int mx = -1; n   for (int i = 0; i <= MAXN; ++i) n     if (ans[i] == res) mx = i; n   cout << mx; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double pi = acos(-1.0); n const int mod = 1000 * 1000 * 1000 + 7; n const long long inf = 1e18; n void rd(int &x) { scanf( %d , &x); } n void rd(long long &x) { scanf( %lld , &x); } n void rd(double &x) { scanf( %lf , &x); } n void rd(int &x, int &y) { scanf( %d%d , &x, &y); } n void rd(long long &x, long long &y) { scanf( %lld%lld , &x, &y); } n void rd(int &x, int &y, int &z) { scanf( %d%d%d , &x, &y, &z); } n void rd(long long &x, long long &y, long long &z) { n   scanf( %lld%lld%lld , &x, &y, &z); n } n void rd(double &x, double &y) { scanf( %lf%lf , &x, &y); } n void rd(double &x, double &y, double &z) { scanf( %lf%lf%lf , &x, &y, &z); } n void rd(char *s) { scanf( %s , s); } n void rd(char &s) { scanf( %c , &s); } n void rd(string &s) { getline(cin, s); } n void pf(int x) { printf( %d n , x); } n void pf(int x, int y) { printf( %d %d n , x, y); } n void pf(long long x) { printf( %lld n , x); } n void pf(char x) { printf( %c n , x); } n void pf(char *x) { printf( %s n , x); } n void pf(string x) { cout << x << endl; } n int main() { n   int n, m, k, x = 0, y = 0, f = 1, p, q, ans = 0; n   cin >> n >> m >> k; n   if (k == 1) { n     cout << m * n <<    ; n     for (int i = 1; i <= (n); i++) n       for (int j = 1; j <= (m); j++) { n         if (i % 2 == 1) { n           cout << i <<     << j <<    ; n         } else { n           cout << i <<     << m - j + 1 <<    ; n         } n       } n     return 0; n   } n   cout <<  2  ; n   for (int i = 1; i <= (n); i++) n     for (int j = 1; j <= (m); j++) { n       if (i % 2 == 1) { n         cout << i <<     << j <<    ; n         x++; n         ans++; n       } else { n         cout << i <<     << m - j + 1 <<    ; n         x++; n         ans++; n       } n       if (x == 2 && f) { n         x = 0; n         y++; n         if (y != k - 1) cout <<   n2  ; n       } n       if (y == k - 1 && f != 0) { n         f = 0; n         cout <<   n  << m * n - ans <<    ; n       } n     } n } n


#include <bits/stdc++.h> n using namespace std; n const int __ = 1000000; n bool pri[__ + 5]; n int num[__ + 5]; n void era() { n   int x = (int)sqrt(__ + 0.01); n   for (int i = 2; i <= x; i++) n     if (!pri[i]) { n       num[++num[0]] = i; n       for (int j = i * i; j <= __; j += i) pri[j] = true; n     } n   for (int i = x + 1; i <= __; i++) n     if (!pri[i]) num[++num[0]] = i; n } n int main() { n   era(); n   int n; n   scanf( %d , &n); n   int m = n, maxx = 0; n   for (int i = 2; i * i <= m; i++) n     if (m % i == 0) n       for (maxx = i; m % i == 0; m /= i) n         ; n   if (m != 1) maxx = m; n   int x1 = n - maxx + 1, ans = INT_MAX; n   for (int i = (1); i <= (num[0]); i++) { n     int p = num[i]; n     int x0 = (x1 + p - 1) / p * p - (p - 1); n     int x = (x0 + p - 1) / p * p; n     if (x0 > p && x0 >= 3 && x <= n) ans = min(ans, x0); n   } n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s1; n   while (cin >> s1) { n     string s2 =   ; n     for (int i = 0; i < s1.size(); i++) { n       if (s1[i] !=  + ) s2 += s1[i]; n     } n     sort(s2.begin(), s2.end()); n     for (int i = 0; i < s2.size(); i++) { n       if (i) cout <<  + ; n       cout << s2[i]; n     } n     cout <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long ara[200005]; n long long aray[200005]; n int main() { n   long long a, b, c, d, t, i, j, k, n, m; n   cin >> t; n   while (t--) { n     long long ans = 0; n     cin >> n >> m >> k; n     a = n / k; n     if (m > a) { n       m -= a; n       if (m % (k - 1) == 0) { n         ans = a - ((m / (k - 1))); n       } else { n         ans = a - ((m / (k - 1))) - 1; n       } n     } else { n       ans = m; n     } n     cout << ans << endl; n   } n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n const double error = 1e-7; n double v, r; n bool puede(double t, double dist) { n   dist -= v * t; n   if (dist <= 0) return true; n   double tvuelta = r * 2 * M_PI / v; n   t -= int(t / tvuelta) * tvuelta; n   double a = t * v / r; n   return dist <= 2 * r * sin(a / 2.0); n } n int main() { n   cout.setf(ios::fixed); n   cout.precision(10); n   int n; n   cin >> n >> r >> v; n   for (int cas = 0; cas < n; cas++) { n     int s, f; n     cin >> s >> f; n     double inf = 0; n     double sup = 2000000000; n     double d = f - s; n     while (inf + error < sup) { n       double med = (inf + sup) / 2.0; n       if (puede(med, d)) n         sup = med; n       else n         inf = med; n     } n     cout << inf << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long n, l, v1, v2, k; n int main() { n   cin >> n >> l >> v1 >> v2 >> k; n   long long g = (n + k - 1) / k; n   double le = 0, ri = l / (double)v1; n   while ((ri - le) >= 5e-7) { n     double mid = (le + ri) / 2; n     double t = 0; n     for (int i = 1; i <= g; i++) { n       double x = ((double)l - v1 * mid) / (v2 - v1); n       t += x; n       if (i != g) { n         double y = x * (v2 - v1) / (v1 + v2); n         t += y; n       } n     } n     if (mid > t) n       ri = mid; n     else n       le = mid; n   } n   cout << setprecision(9) << le << endl; n   return 0; n } n


#include <bits/stdc++.h> n  n using namespace std; n  n #define ll long long n typedef pair<ll, ll> pll; n typedef pair<ll, int> pli; n typedef pair<int, ll> pil; n typedef pair<int, int> pii; n typedef vector<int> vi; n typedef vector<vi> vvi; n typedef vector<bool> vb; n typedef vector<vb> vvb; n typedef vector<char> vc; n typedef vector<vc> vvc; n typedef vector<string> vs; n typedef vector<vs> vvs; n typedef vector<ll> vll; n typedef vector<vll> vvll; n typedef vector<pii> vpii; n typedef vector<vpii> vvpii; n typedef vector<pll> vpll; n typedef vector<vpll> vvpll; n typedef set<int> si; n typedef set<vi> svi; n typedef set<ll> sll; n typedef set<vll> svll; n typedef set<pii> spii; n typedef set<vpii> svpii; n typedef set<pll> spll; n typedef set<vpll> svpll; n typedef vector<si> vsi; n typedef vector<sll> vsll; n typedef vector<spii> vspii; n typedef vector<spll> vspll; n #define ft first n #define sc second n #define pb push_back n #define ins insert n #define io                              n  ios_base::sync_with_stdio(false);   n  cin.tie(NULL);                      n  cout.tie(NULL) n #define all(v) v.begin(), v.end() n #define Sort(v) sort(all(v)) n #define sortarr(a, n) sort(a, a + n) n #define tt       n  ll tc;       n  cin >> tc;   n  while (tc--) n #define rep(var, start, end, interval) for (ll var = start; (interval > 0 and var < end) or (interval < 0 and var > end); var += interval) n #define each(x, v) for (auto x : v) n #define takearr0(a, n) rep(z, 0, n, 1) cin >> a[z]; n #define takearr1(a, n) rep(z, 1, n + 1, 1) cin >> a[z]; n  n const ll max_n = 2e3 + 5; n const ll inf = 1e16; n  n ll n, m, w; n vvll a; n  n vpll neighbours(pll p) n { n  vpll vec; n  if (p.ft > 0 and a[p.ft - 1][p.sc] >= 0) n   vec.pb({p.ft - 1, p.sc}); n  if (p.ft < n - 1 and a[p.ft + 1][p.sc] >= 0) n   vec.pb({p.ft + 1, p.sc}); n  if (p.sc > 0 and a[p.ft][p.sc - 1] >= 0) n   vec.pb({p.ft, p.sc - 1}); n  if (p.sc < m - 1 and a[p.ft][p.sc + 1] >= 0) n   vec.pb({p.ft, p.sc + 1}); n  return vec; n } n  n int main() n { n  io; n  cin >> n >> m >> w; n  a.resize(n); n  a.assign(n, vll(m)); n  rep(i, 0, n, 1) takearr0(a[i], m); n  // each(vec, a) n  // { n  //  each(x, vec) cout << setw(18) << x <<    ; n  //  cout << endl; n  // } n  // cout << endl; n  vvb v(n, vb(m, false)); n  vvll dists(n, vll(m, inf)); n  queue<pll> q; n  q.push({0, 0}); n  v[0][0] = true; n  dists[0][0] = 0; n  while (!q.empty()) n  { n   pll p = q.front(); n   q.pop(); n   vpll nb = neighbours(p); n   each(pr, nb) if (!v[pr.ft][pr.sc]) n   { n    dists[pr.ft][pr.sc] = dists[p.ft][p.sc] + w; n    v[pr.ft][pr.sc] = true; n    q.push(pr); n   } n  } n  rep(i, 0, n, 1) rep(j, 0, m, 1) v[i][j] = false; n  vvll distt(n, vll(m, inf)); n  q.push({n - 1, m - 1}); n  v[n - 1][m - 1] = true; n  distt[n - 1][m - 1] = 0; n  while (!q.empty()) n  { n   pll p = q.front(); n   q.pop(); n   vpll nb = neighbours(p); n   each(pr, nb) if (!v[pr.ft][pr.sc]) n   { n    distt[pr.ft][pr.sc] = distt[p.ft][p.sc] + w; n    v[pr.ft][pr.sc] = true; n    q.push(pr); n   } n  } n  ll pors = inf, port = inf; n  rep(i, 0, n, 1) rep(j, 0, m, 1) if (a[i][j] > 0) n  { n   pors = min(pors, dists[i][j] + a[i][j]); n   port = min(port, distt[i][j] + a[i][j]); n  } n  ll ans = min(dists[n - 1][m - 1], pors + port); n  if (ans >= inf) n   cout << -1 << endl; n  else n   cout << ans << endl; n  return 0; n }


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   cin >> t; n   while (t--) { n     int n, o; n     string s; n     cin >> n >> s; n     o = s[n - 1] -  0 ; n     for (int i = 0; i < n - 1; i++) o += (s[i] ==  0  ? 0 : s[i] - 47); n     cout << o << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long MAX = 9999999999999999; n int t, n; n vector<long long> ans; n vector<long long> graphSize; n vector<long long> aToFirst, aToLast, bToFirst, bToLast; n void countLength(vector<long long> &toFirst, vector<long long> &toLast, n                  long long v, int n) { n   if (n == 0) { n     toFirst[0] = 0; n     toLast[0] = 0; n     return; n   } n   if (n == 1) { n     toFirst[1] = v == 2; n     toLast[1] = v == 1; n     return; n   } n   if (v <= graphSize[n - 1]) { n     countLength(toFirst, toLast, v, n - 1); n     toFirst[n] = min(toFirst[n - 1], toLast[n - 1] + 2); n     toLast[n] = min(toFirst[n - 1], toLast[n - 1]) + (n - 1) / 2 + 1; n   } else { n     countLength(toFirst, toLast, v - graphSize[n - 1], n - 2); n     toFirst[n] = toFirst[n - 2] + 1; n     toLast[n] = toLast[n - 2]; n   } n } n long long findMinLength(long long a, long long b, int n) { n   if (a == b) return 0; n   if (n <= 2) return 1; n   if (a <= graphSize[n - 1]) { n     if (b >= graphSize[n - 1] + 1) { n       return min(aToFirst[n - 1], aToLast[n - 1]) + bToFirst[n - 2] + 1; n     } else { n       long long d1 = min(aToFirst[n - 1] + bToLast[n - 1] + 2, n                          aToLast[n - 1] + bToFirst[n - 1] + 2); n       return min(d1, findMinLength(a, b, n - 1)); n     } n   } else { n     return findMinLength(a - graphSize[n - 1], b - graphSize[n - 1], n - 2); n   } n } n int main() { n   cin >> t >> n; n   graphSize.push_back(1); n   graphSize.push_back(2); n   int iMax = 2; n   for (; graphSize.back() < MAX; ++iMax) { n     graphSize.push_back(graphSize[iMax - 1] + graphSize[iMax - 2]); n   } n   for (int i = 1; i <= t; ++i) { n     long long a, b; n     cin >> a >> b; n     if (a > b) swap(a, b); n     aToFirst.resize(min(n, iMax) + 1); n     aToLast.resize(min(n, iMax) + 1); n     bToFirst.resize(min(n, iMax) + 1); n     bToLast.resize(min(n, iMax) + 1); n     countLength(aToFirst, aToLast, a, min(n, iMax)); n     countLength(bToFirst, bToLast, b, min(n, iMax)); n     ans.push_back(findMinLength(a, b, min(n, iMax))); n   } n   for (int i = 0; i < ans.size(); ++i) { n     cout << ans[i] << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n class Reduced_Indexs { n   vector<int> idxs; n   int n; n  n  public: n   Reduced_Indexs() = default; n   template <typename InputIterator> n   Reduced_Indexs(InputIterator first, InputIterator last) { n     idxs = vector<int>(first, last); n     sort(idxs.begin(), idxs.end()); n     n = unique(idxs.begin(), idxs.end()) - idxs.begin(); n     idxs.resize(n); n   } n   int size(); n   int get_idx(int); n   int get_value(int); n }; n int Reduced_Indexs::size() { return n; } n int Reduced_Indexs::get_idx(int x) { n   auto p = lower_bound(idxs.begin(), idxs.end(), x); n   return (p != idxs.end() && *p == x) ? (p - idxs.begin()) : -1; n } n int Reduced_Indexs::get_value(int i) { return idxs[i]; } n const int N = 100000; n const long long MOD = 1000000007LL; n long long pow2[N + 2]; n int xs[N], ys[N]; n Reduced_Indexs xidxs, yidxs; n vector<int> xeq[N], yeq[N]; n bool checked[N]; n set<int> xused, yused; n int cnt; n void check(int); n int main() { n   pow2[0] = 1LL; n   for (int i = 1; i <= N + 1; ++i) { n     pow2[i] = (pow2[i - 1] * 2) % MOD; n   } n   int n; n   scanf( %d , &n); n   for (int i = 0; i < n; ++i) { n     scanf( %d%d , &xs[i], &ys[i]); n   } n   xidxs = Reduced_Indexs(xs, xs + n); n   yidxs = Reduced_Indexs(ys, ys + n); n   for (int i = 0; i < n; ++i) { n     xeq[xidxs.get_idx(xs[i])].push_back(i); n     yeq[yidxs.get_idx(ys[i])].push_back(i); n   } n   long long ans = 1LL; n   for (int i = 0; i < n; ++i) { n     xused.clear(); n     yused.clear(); n     cnt = 0; n     check(i); n     int total = xused.size() + yused.size(); n     ans = (ans * (pow2[total] - (cnt < total))) % MOD; n   } n   printf( %lld n , ans); n   exit(EXIT_SUCCESS); n } n void check(int u) { n   if (checked[u]) { n     return; n   } n   checked[u] = true; n   ++cnt; n   int x = xs[u], y = ys[u]; n   if (!xused.count(x)) { n     xused.insert(x); n     for (int v : xeq[xidxs.get_idx(x)]) { n       check(v); n     } n   } n   if (!yused.count(y)) { n     yused.insert(y); n     for (int v : yeq[yidxs.get_idx(y)]) { n       check(v); n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int n, ar[3100], cur; n vector<int> v; n bool valid, used[10000]; n pair<int, string> tab[3100]; n int main() { n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> tab[i].second >> tab[i].first; n   } n   sort(tab, tab + n); n   valid = true; n   for (int i = 0; i < n; i++) { n     if (tab[i].first > i) valid = false; n   } n   if (valid) { n     cur = tab[0].first; n     for (int i = 0; i < n; i++) { n       ar[i] = 10; n       if (tab[i].first > cur) { n         for (int j = 0; j < v.size(); j++) { n           ar[v[j]]++; n         } n         int bil = tab[i].first - cur; n         int j = i; n         while (bil > 0) { n           j--; n           if (used[j]) continue; n           used[j] = true; n           v.push_back(j); n           bil--; n         } n         cur = tab[i].first; n       } n     } n     for (int j = 0; j < v.size(); j++) { n       ar[v[j]]++; n     } n     for (int i = 0; i < n; i++) { n       cout << tab[i].second <<     << ar[i] << endl; n     } n   } else { n     cout << -1 << endl; n   } n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n void readInput() {} n void solve() {} n priority_queue<pair<int, int>> pq; n int n, x, y, res, a[100004], b[100004], T, cnt, vitri[100004]; n vector<int> pos[100004], ans; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   readInput(); n   solve(); n   cin >> T; n   while (T--) { n     cin >> n >> x >> y; n     for (int i = 1; i <= n + 1; i++) { n       pos[i].clear(); n       b[i] = 0; n       vitri[i] = 0; n     } n     ans.clear(); n     while (!pq.empty()) pq.pop(); n     for (int i = 1; i <= n; i++) cin >> a[i], pos[a[i]].push_back(i); n     cnt = 1; n     for (int i = 1; i <= n + 1; i++) { n       pq.push({pos[i].size(), i}); n       if (pos[i].size() == 0) res = i; n     } n     while (cnt <= x) { n       pair<int, int> u = pq.top(); n       pq.pop(); n       b[pos[u.second].back()] = u.second; n       vitri[pos[u.second].back()] = 1; n       pos[u.second].pop_back(); n       cnt++; n       pq.push({pos[u.second].size(), u.second}); n     } n     pair<int, int> u = pq.top(); n     if (2 * u.first > n - x + n - y) { n       cout <<  NO  <<   n ; n       continue; n     } else { n       cout <<  YES  <<   n ; n       for (int i = 1; i <= n + 1; i++) { n         for (auto v : pos[i]) ans.push_back(v); n       } n       cnt = 1; n       for (int i = 0; i < ans.size(); i++) { n         b[ans[i]] = a[ans[(i + ans.size() / 2) % (ans.size())]]; n       } n       cnt = 1; n       for (int i = 1; i <= n; i++) { n         if (vitri[i] == 0 && b[i] == a[i]) { n           vitri[i] = 1; n           cnt++; n           b[i] = res; n         } n       } n       for (int i = 1; i <= n; i++) { n         if (vitri[i] == 0 && cnt <= n - y) b[i] = res, cnt++; n       } n       for (int i = 1; i <= n; i++) cout << b[i] <<    ; n       cout <<   n ; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } n const int MAXLEN = 200; n char s[MAXLEN + 1]; n int n; n void run() { n   scanf( %d%s , &n, s); n   n = strlen(s); n   int ret = 0; n   for (int at = 0, to = at; at < n; at = to) { n     if (isupper(s[to])) { n       ++to; n       continue; n     } n     while (to < n && islower(s[to])) ++to; n     int mask = 0, cnt = 0; n     for (int i = (at); i < (to); ++i) { n       int x = s[i] -  a ; n       if (((mask >> x) & 1) == 0) mask |= 1 << x, ++cnt; n     } n     ret = max(ret, cnt); n   } n   printf( %d n , ret); n } n int main() { n   run(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, m, c, l, r, i, j, x1, x2, x3, x, r_y, r_y1, r_y2, r_y3, k, g, sum, n     maxy, maxx, qy, qx; n long long kk; n long long fact(long long a) { n   unsigned long long k = 1, i; n   for (i = 1; i <= a; i++) k *= i; n   return k; n } n int main() { n   cin >> x1 >> r_y1 >> x2 >> r_y2; n   x = x2 - x1; n   r_y = r_y2 - r_y1; n   maxy = (2 + r_y) / 2; n   qy = (2 + r_y) % 2; n   maxx = x + 1; n   qx = maxx % 2; n   if (qy == 1) n     cout << maxx * maxy; n   else { n     cout << (maxx / 2 + qx) * maxy + (maxx / 2) * (maxy - 1); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m; n   cin >> n >> m; n   int cor[n], wro[m]; n   for (int i = 0; i < n; i++) cin >> cor[i]; n   for (int i = 0; i < m; i++) cin >> wro[i]; n   int tl; n   sort(cor, cor + n); n   sort(wro, wro + m); n   int v = max(2 * cor[0], cor[n - 1]); n   if (v < wro[0]) n     cout << v; n   else n     cout <<  -1 ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 500; n const int maxm = 500000 + 10; n struct Edge { n   int next, v; n   Edge() {} n   Edge(int next, int v) : next(next), v(v) {} n } e[maxm << 1]; n int n, m, timer, num, len; n int head[maxm], cnt; n int dfn[maxn], low[maxn], belo[maxn]; n bool inst[maxn], used[maxn]; n int st[maxm], top, q[maxm], front, tail; n char org[27], s[maxn], ans[maxn], res[maxn]; n int val[128]; n inline int read() { n   int x = 0; n   char ch = getchar(); n   while (ch <  0  || ch >  9 ) ch = getchar(); n   while (ch >=  0  && ch <=  9 ) { n     x = x * 10 + ch -  0 ; n     ch = getchar(); n   } n   return x; n } n inline void AddEdge(int u, int v) { n   e[++cnt] = Edge(head[u], v); n   head[u] = cnt; n } n void tarjan(int u) { n   dfn[u] = low[u] = ++timer; n   st[++top] = u; n   inst[u] = 1; n   for (int i = head[u]; i; i = e[i].next) { n     int v = e[i].v; n     if (!dfn[v]) { n       tarjan(v); n       low[u] = min(low[u], low[v]); n     } else if (inst[v]) n       low[u] = min(low[u], dfn[v]); n   } n   if (dfn[u] == low[u]) { n     num++; n     int v; n     do { n       v = st[top--]; n       belo[v] = num; n       inst[v] = 0; n     } while (u != v); n   } n } n inline bool judge(int tot) { n   for (int i = 2; i <= tot; i++) n     if (!dfn[i]) tarjan(i); n   for (int i = 2; i < tot; i += 2) n     if (belo[i] == belo[i + 1]) return 0; n   return 1; n } n inline char find(int pos, char ch) { n   for (int i = pos + 1; i < len; i++) n     if (org[i] == ch) return  a  + i; n   return -1; n } n int main() { n   scanf( %s , org); n   len = strlen(org); n   for (int i = 0; i < len; i++) n     if (org[i] ==  C ) val[ a  + i] = 1; n   n = read(), m = read(); n   char op1[10], op2[10]; n   int x, y; n   while (m--) { n     x = read(), scanf( %s , op1); n     y = read(), scanf( %s , op2); n     x = x << 1 | (op1[0] ==  C ); n     y = y << 1 | (op2[0] ==  C ); n     AddEdge(x, y); n     AddEdge(y ^ 1, x ^ 1); n   } n   scanf( %s , s + 1); n   if (!judge(n << 1 | 1)) { n     puts( -1 ); n     return 0; n   } n   bool exis = 0; n   res[1] = -1; n   for (int pos = n + 1; pos >= 1; pos--) { n     for (int a = pos << 1; a <= (pos << 1 | 1); a++) { n       strcpy(ans + 1, s + 1); n       if (pos <= n) { n         char tp = find(s[pos] -  a , a & 1 ?  V  :  C ); n         if (tp == -1) continue; n         ans[pos] = tp; n       } n       for (int i = pos + 1; i <= n; i++) ans[i] =  a ; n       bool flag = 1; n       memset(used, 0, sizeof(used)); n       for (int i = 1; i <= n && flag; i++) { n         x = i << 1 | val[ans[i]]; n         if (used[x]) continue; n         used[x] = 1; n         front = tail = 0; n         q[++tail] = x; n         while (front != tail) { n           x = q[++front]; n           used[x] = 1; n           if (used[x ^ 1]) { n             flag = 0; n             break; n           } n           if ((x >> 1) <= pos && val[ans[x >> 1]] != (x & 1)) { n             flag = 0; n             break; n           } n           if ((x >> 1) > pos) { n             char tp = find(-1, x & 1 ?  C  :  V ); n             if (tp == -1) { n               flag = 0; n               break; n             } n             ans[x >> 1] = tp; n           } n           for (int j = head[x]; j; j = e[j].next) { n             int v = e[j].v; n             if (!used[v]) q[++tail] = v; n           } n         } n       } n       if (!flag) continue; n       exis = 1; n       if (res[1] == -1) n         strcpy(res + 1, ans + 1); n       else if (strcmp(res + 1, ans + 1) > 0) n         strcpy(res + 1, ans + 1); n     } n     if (exis) break; n   } n   if (exis) n     puts(res + 1); n   else n     puts( -1 ); n   return 0; n } n