#include <bits/stdc++.h> n using namespace std; n struct E { n   int x, y; n }; n E map1[1010], map2[1010], map3[1010]; n int vis[1010]; n int n, flag; n void dfs(int k) { n   if (k == n + 1) { n     cout << map3[n].x <<     << map3[n].y; n     flag = 1; n     return; n   } else { n     for (int i = 1; i <= n; i++) { n       if (!vis[i]) { n         if (map1[k].x + map2[i].x == map3[k - 1].x && n             map1[k].y + map2[i].y == map3[k - 1].y) { n           vis[i] = 1; n           map3[k].x = map1[k].x + map2[i].x; n           map3[k].y = map1[k].y + map2[i].y; n           dfs(k + 1); n           if (flag) { n             break; n           } n           vis[i] = 0; n         } n       } n     } n   } n } n int main(int argc, char *argv[]) { n   cin >> n; n   for (int i = 1; i <= n; i++) { n     cin >> map1[i].x >> map1[i].y; n   } n   for (int i = 1; i <= n; i++) { n     cin >> map2[i].x >> map2[i].y; n   } n   for (int i = 1; i <= n; i++) { n     map3[1].x = map1[1].x + map2[i].x; n     map3[1].y = map1[1].y + map2[i].y; n     vis[i] = 1; n     dfs(2); n     vis[i] = 0; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char arr[205]; n int main() { n   ios::sync_with_stdio(0); n   int n; n   cin >> n; n   for (int i = (0); i < (n); i++) cin >> arr[i]; n   long long res = 0; n   pair<int, int> udlr; n   for (int i = (0); i < (n); i++) { n     udlr.first = 0; n     udlr.second = 0; n     for (int j = (i); j < (n); j++) { n       if (arr[j] ==  U ) udlr.first += 1; n       if (arr[j] ==  D ) udlr.first -= 1; n       if (arr[j] ==  L ) udlr.second += 1; n       if (arr[j] ==  R ) udlr.second -= 1; n       if (udlr.second == 0 && udlr.first == 0) res++; n     } n   } n   cout << res << endl; n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( O3 ) n using namespace std; n const long double pi = acos(-1.0); n const long double log23 = 1.58496250072115618145373894394781; n const long double eps = 1e-8; n const long long INF = 1e18 + 239; n const long long prost = 239; n const int two = 2; n const int th = 3; n const long long MOD = 998244353; n const long long MOD2 = MOD * MOD; n const int BIG = 1e9 + 239; n const int alf = 26; n const int dx[4] = {-1, 0, 1, 0}; n const int dy[4] = {0, 1, 0, -1}; n const int dxb[4] = {-1, 1, 1, -1}; n const int dyb[4] = {-1, 1, -1, 1}; n const int dxo[8] = {-1, -1, -1, 0, 1, 1, 1, 0}; n const int dyo[8] = {-1, 0, 1, 1, 1, 0, -1, -1}; n const int dig = 10; n const int day[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; n const int digarr[10] = {6, 2, 5, 5, 4, 5, 6, 3, 7, 6}; n const long long bt = 62; n template <typename T> n inline T gcd(T a, T b) { n   while (a) { n     b %= a; n     swap(a, b); n   } n   return b; n } n template <typename T> n inline T lcm(T a, T b) { n   return (a / gcd(a, b)) * b; n } n inline bool is_down(char x) { return ( a  <= x && x <=  z ); } n inline bool is_upper(char x) { return ( A  <= x && x <=  Z ); } n inline bool is_digit(char x) { return ( 0  <= x && x <=  9 ); } n mt19937_64 rnd(239); n const int M = 3e5 + 239; n const int N = 2e3 + 239; n const int L = 103; n const int T = (1 << 18); n const int B = trunc(sqrt(M)) + 1; n const int X = 1e4 + 239; n long long dp[two][M]; n int n, kol; n vector<int> v[M]; n long long pref[M], suf[M], now, fl[M]; n void dfs(int p, int pr) { n   for (int i : v[p]) n     if (i != pr) dfs(i, p); n   dp[0][p] = 1; n   for (int i : v[p]) n     if (i != pr) dp[0][p] = (dp[0][p] * (dp[0][i] + dp[1][i])) % MOD; n   dp[1][p] = 0; n   kol = 0; n   pref[0] = 1; n   for (int i : v[p]) n     if (i != pr) { n       kol++; n       pref[kol] = (pref[kol - 1] * (2LL * dp[1][i] + dp[0][i])) % MOD; n     } n   reverse(v[p].begin(), v[p].end()); n   suf[kol] = 1; n   for (int i : v[p]) n     if (i != pr) { n       kol--; n       suf[kol] = (suf[kol + 1] * (2LL * dp[1][i] + dp[0][i])) % MOD; n     } n   reverse(v[p].begin(), v[p].end()); n   for (int i : v[p]) n     if (i != pr) { n       now = (pref[kol] * suf[kol + 1]) % MOD; n       kol++; n       now = (now * fl[i]) % MOD; n       dp[1][p] = (dp[1][p] + now) % MOD; n     } n   fl[p] = pref[kol]; n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(); n   cout.tie(0); n   cin >> n; n   for (int i = 0; i < n - 1; i++) { n     int s, f; n     cin >> s >> f; n     s--, f--; n     v[s].push_back(f); n     v[f].push_back(s); n   } n   dfs(0, -1); n   cout << (dp[0][0] + dp[1][0]) % MOD; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n ostream& operator<<(ostream& os, const vector<T>& v) { n   os <<  [ ; n   for (auto u : v) { n     os << u; n     os <<  , ; n   } n   os <<  ]  n      <<   n ; n   return os; n } n template <typename T> n ostream& operator<<(ostream& os, const set<T>& s) { n   os <<  { ; n   for (auto u : s) { n     os << u; n     if (u != *s.rbegin()) os <<  , ; n   } n   os <<  }  n      <<   n ; n   return os; n } n template <typename T, typename U> n ostream& operator<<(ostream& os, const pair<T, U>& p) { n   os <<  { ; n   os << p.first <<  ,  << p.second; n   os <<  }  n      <<   n ; n   return os; n } n template <typename T, typename U> n ostream& operator<<(ostream& os, const map<T, U>& mp) { n   for (auto p : mp) os << p.first <<   :   << p.second <<   n ; n   return os; n } n void boost() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   cout << fixed << setprecision(3); n } n int32_t main() { n   boost(); n   long long t = 1; n   while (t--) { n     long long a[3], d; n     cin >> a[0] >> a[1] >> a[2] >> d; n     sort(a, a + 3); n     if (a[1] >= a[0] + d && a[2] >= a[1] + d) n       cout << 0 <<   n ; n     else { n       if (a[1] >= a[0] + d) { n         if (a[2] >= a[0] + 2 * d) { n           long long get = a[2] - d; n           long long ans = a[1] - get; n           cout << ans <<   n ; n         } else { n           long long have = (a[1] + d) - a[2]; n           cout << have <<   n ; n         } n       } else if (a[2] >= a[1] + d) { n         if (a[2] >= a[0] + 2 * d) { n           long long get = a[0] + d; n           long long ans = get - a[1]; n           cout << ans <<   n ; n         } else { n           long long have = abs((a[1] - d) - a[0]); n           cout << have <<   n ; n         } n       } else { n         long long ans = abs(d - (a[1] - a[0])); n         ans = ans + abs(d - (a[2] - a[1])); n         cout << ans <<   n ; n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n inline string tostring(const T &x) { n   ostringstream os; n   os << x; n   return os.str(); n } n inline int toint(const string &s) { n   istringstream is(s); n   int x; n   is >> x; n   return x; n } n inline int todecimal(string s) { n   int a = 0; n   for (int i = 0; i < s.size(); i++) a = 2 * a + (s[i] -  0 ); n   return a; n } n inline string tobinary(int a) { n   string s; n   while (a != 0) { n     s = (char)(a % 2 +  0 ) + s; n     a >>= 1; n   } n   return s; n } n template <typename T> n inline T sqr(T x) { n   return x * x; n } n template <typename T> n T gcd(T a, T b) { n   return (b == 0) ? abs(a) : gcd(b, a % b); n } n inline int isvowel(char c) { n   if (c ==  a  || c ==  e  || c ==  i  || c ==  o  || c ==  u ) return 1; n   return 0; n } n inline int isprime(int a) { n   for (int i = 2; i * i <= a; i++) n     if (!(a % i)) return 0; n   return 1; n } n inline void inp(int &n) { n   n = 0; n   int ch = getchar(); n   int sign = 1; n   while (ch <  0  || ch >  9 ) { n     if (ch ==  - ) sign = -1; n     ch = getchar(); n   } n   while (ch >=  0  && ch <=  9 ) n     n = (n << 3) + (n << 1) + ch -  0 , ch = getchar(); n   n = n * sign; n } n const int dx4[4] = {0, 0, 1, -1}; n const int dy4[4] = {1, -1, 0, 0}; n const int dx8[8] = {0, 0, 1, 1, 1, -1, -1, -1}; n const int dy8[8] = {1, -1, 0, 1, -1, 1, 0, -1}; n class node { n  public: n   int x, y, z; n   node(int a, int b, int c) { n     x = a; n     y = b; n     z = c; n   } n }; n bool operator<(const node &a, const node &b) { return a.x > b.x; } n bool compare(const node &a, const node &b) { return a.x < b.x; } n void solve() {} n void input() { n   int n, k; n   cin >> n >> k; n   int ans = INT_MIN; n   int f, t; n   for (int i = 0; i < n; i++) { n     cin >> f >> t; n     if (t > k) n       ans = max(ans, f - t + k); n     else n       ans = max(ans, f); n   } n   cout << ans << endl; n } n int main() { n   int testcase = 1; n   for (int i = 0; i < testcase; i++) { n     input(); n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, k, a[2005][2005], ans, p; n int main() { n   cin >> n >> m >> k; n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= m; j++) { n       char c; n       c = getchar(); n       while (c !=  .  && c !=  * ) c = getchar(); n       a[i][j] = c; n       if (c ==  . ) p++; n     } n   if (k == 1) { n     cout << p; n     return 0; n   } n   int x = 0; n   for (int i = 1; i <= n; i++) { n     x = 0; n     for (int j = 1; j <= m; j++) { n       if (a[i][j] == a[i][j - 1] && a[i][j] ==  . ) n         x++; n       else if (a[i][j] ==  . ) n         x = 1; n       else { n         if (x >= k) ans += x - k + 1; n         x = 0; n       } n     } n     if (x >= k) ans += x - k + 1; n   } n   for (int j = 1; j <= m; j++) { n     x = 0; n     for (int i = 1; i <= n; i++) { n       if (a[i][j] == a[i - 1][j] && a[i][j] ==  . ) n         x++; n       else if (a[i][j] ==  . ) n         x = 1; n       else { n         if (x >= k) ans += x - k + 1; n         x = 0; n       } n     } n     if (x >= k) ans += x - k + 1; n   } n   cout << endl << ans; n } n


#include <bits/stdc++.h> n using namespace std; n int arr[300], book[300], n, a, b, flag = 0, tun = 0; n int main() { n   cin >> n >> a >> b; n   arr[a] = arr[b] = 2; n   while (!flag) { n     tun++; n     memset(book, 0, sizeof(book)); n     for (int i = 1; i <= n; i++) { n       if (!book[i] && (arr[i] == 0 || arr[i] == 2)) { n         for (int j = i + 1; j <= n; j++) { n           if (!book[j] && (arr[j] == 0 || arr[j] == 2)) { n             if (arr[i] == 2 && arr[j] == 2) { n               flag = 1; n             } else if (arr[i] == 0 && arr[j] == 2) { n               arr[i] = 1; n             } else if (arr[i] == 2 && arr[j] == 0) n               arr[j] = 1; n             else n               arr[i] = 1; n             book[i] = book[j] = 1; n             break; n           } n         } n       } n     } n     if (flag) break; n   } n   int ans = (int)pow(2, tun); n   if (ans == n) n     cout <<  Final!  << endl; n   else n     cout << tun << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, t[1000 * 1000], a[1000 * 1000], b[1000 * 1000], v, ans; n map<long long, long long> w; n long long get(int v, int tl, int tr, int l, int r) { n   if (r < tl || tr < l) return 0; n   if (l <= tl && tr <= r) return t[v]; n   int m = (tl + tr) >> 1; n   return max(get(v + v, tl, m, l, min(r, m)), n              get(v + v + 1, m + 1, tr, max(l, m + 1), r)); n } n void upd(int v, int l, int r, int p, long long x) { n   if (l == r) n     t[v] = x; n   else { n     int m = (l + r) >> 1; n     if (p <= m) n       upd(v + v, l, m, p, x); n     else n       upd(v + v + 1, m + 1, r, p, x); n     t[v] = max(t[v + v], t[v + v + 1]); n   } n } n int main() { n   cin >> n; n   for (int i = 1; i <= n; i++) { n     long long r, h; n     cin >> r >> h; n     b[i] = a[i] = ((r) * (r)) * h; n   } n   sort(b + 1, b + 1 + n); n   for (int i = 1; i <= n; i++) w[b[i]] = i; n   for (int i = 1; i <= n; i++) { n     v = get(1, 1, n, 1, w[a[i]] - 1) + a[i]; n     upd(1, 1, n, w[a[i]], v); n     ans = max(ans, v); n   } n   printf( %.7f , ans * acos(-1)); n } n


#include <bits/stdc++.h> n using namespace std; n constexpr int inf = 1e9; n int main() { n   int n, q; n   cin >> n >> q; n   vector<int> t(q), l(q), r(q), v(q); n   vector<int> added(n), ub(n, inf); n   for (int j = 0; j < q; ++j) { n     cin >> t[j] >> l[j] >> r[j] >> v[j]; n     l[j]--; n     if (t[j] == 1) { n       for (int i = l[j]; i < r[j]; ++i) { n         added[i] += v[j]; n       } n     } else { n       for (int i = l[j]; i < r[j]; ++i) { n         ub[i] = min(ub[i], v[j] - added[i]); n       } n     } n   } n   vector<int> ans = ub; n   for (int i = 0; i < q; ++i) { n     if (t[i] == 1) { n       for (int j = l[i]; j < r[i]; ++j) { n         ans[j] += v[i]; n       } n     } else { n       int maxi = -inf; n       for (int j = l[i]; j < r[i]; ++j) { n         maxi = max(maxi, ans[j]); n       } n       if (maxi != v[i]) { n         cout <<  NO  << endl; n         return 0; n       } n     } n   } n   cout <<  YES  << endl; n   for (int i = 0; i < n; ++i) { n     cout << ub[i] <<    n [i + 1 == n]; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 5e5 + 5; n vector<long long> g[N]; n map<long long, long long> cnt; n long long n, c, a[N], pref[N]; n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   cin >> n >> c; n   for (long long i = 1; i <= n; i++) { n     cin >> a[i]; n     cnt[a[i]]++; n     g[a[i]].push_back(i); n     pref[i] = pref[i - 1] + (a[i] == c); n   } n   long long ans = cnt[c]; n   for (long long i = 1; i < N; i++) { n     if (!g[i].size() || i == c) continue; n     long long prev = g[i][0]; n     long long cur = 0, max_so_far = 0; n     for (auto it : g[i]) { n       cur = cur + 1 - (pref[it] - pref[prev]); n       prev = it; n       if (cur <= 0) cur = 1; n       max_so_far = max(max_so_far, cur); n     } n     ans = max(ans, pref[n] + max_so_far); n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, q; n char s2[10000006]; n char s[205][205]; n int vis[205][205]; n int dp[205 * 205][20]; n int dx[10]; n int dy[10]; n vector<int> Q; n int id(int x, int y) { return x * m + y; } n void dfs(int x, int y) { n   vis[x][y] = 1; n   int t = (s[x][y] -  0 ), p = id(x, y); n   int xx = x + dx[t], yy = y + dy[t]; n   if (xx < 0 || xx >= n || yy < 0 || yy >= m) n     dp[p][t] = p; n   else { n     int v = id(xx, yy); n     dp[p][t] = id(xx, yy); n     if (vis[xx][yy] == 0) dfs(xx, yy); n     for (int i = 0; i < 10; i++) n       if (i != t) dp[p][i] = dp[v][i]; n   } n } n int check(char s2[]) { n   int len = strlen(s2); n   for (int i = 0; i < Q.size(); i++) { n     int x = Q[i]; n     for (int j = 0; j < len; j++) { n       x = dp[x][s2[j] -  0 ]; n       if (x < 0) break; n     } n     if (x >= 0) return 1; n   } n   return 0; n } n int main() { n   memset(dp, -1, sizeof(dp)); n   scanf( %d%d%d , &n, &m, &q); n   for (int i = 0; i < n; i++) scanf( %s , s[i]); n   for (int i = 0; i < 10; i++) scanf( %d%d , &dx[i], &dy[i]); n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       if (!vis[i][j]) { n         dfs(i, j); n         Q.push_back(id(i, j)); n       } n     } n   } n   for (int i = 0; i < q; i++) { n     scanf( %s , s2); n     if (check(s2)) n       printf( YES n ); n     else n       puts( NO ); n   } n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:66777216 ) n using namespace std; n int RAND() { return (rand() << 16) + rand(); } n const long long MOD = 1000000007; n const int N = 2000007; n int n; n long long f[N]; n long long power(long long a, long long b) { n   if (b == 0) return 1; n   if (b & 1) return a * power(a, b - 1) % MOD; n   long long r = power(a, b >> 1); n   return r * r % MOD; n } n long long inv(long long a) { return power(a, MOD - 2); } n long long C(int n, int k) { return f[n] * inv(f[k] * f[n - k] % MOD) % MOD; } n void solve() { n   f[0] = 1; n   for (int i = 1; i < N; ++i) f[i] = i * f[i - 1] % MOD; n   cin >> n; n   long long ans = ((n + 2) * C(2 * n + 2, n) - n - 1) % MOD * inv(n + 1) % MOD; n   if (ans < 0) ans += MOD; n   cout << ans << endl; n } n void testgen() { n   FILE* f = fopen( input.txt ,  w ); n   fclose(f); n } n int main() { n   cout << fixed; n   cout.precision(16); n   cerr << fixed; n   cerr.precision(3); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long calc(int *a, int n) { n   long long ret = 0, suml = 0; n   stack<pair<int, int> > st; n   for (int i = 2; i <= n; i++) { n     int l = 1; n     while (!st.empty() && abs(a[i] - a[i - 1]) > st.top().first) { n       suml -= st.top().first * (long long)st.top().second; n       l += st.top().second; n       st.pop(); n     } n     st.push(make_pair(abs(a[i] - a[i - 1]), l)); n     suml += abs(a[i] - a[i - 1]) * (long long)l; n     ret += suml; n   } n   return ret; n } n int n, m, a[100010]; n int main() { n   scanf( %d%d , &n, &m); n   for (int i = 1; i <= n; i++) scanf( %d , &a[i]); n   for (int i = 1; i <= m; i++) { n     int l, r; n     scanf( %d%d , &l, &r); n     printf( %I64d n , calc(a + l - 1, r - l + 1)); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, rooms = 0; n   char a, b; n   scanf( %d n , &n); n   int arr[30]; n   for (int i = 0; i < 26; i++) arr[i] = 0; n   for (int i = 0; i < 2 * (n - 1); i += 2) { n     scanf( %c%c , &a, &b); n     arr[(int)(a -  a )]++; n     if (arr[(int)(tolower(b) -  a )] > 0) n       arr[(int)(tolower(b) -  a )]--; n     else n       rooms++; n   } n   cout << rooms << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using namespace std; n int main() { n   string s; n   int t[128]; n   t[ > ] = 8; n   t[ < ] = 9; n   t[ + ] = 10; n   t[ - ] = 11; n   t[ . ] = 12; n   t[ , ] = 13; n   t[ [ ] = 14; n   t[ ] ] = 15; n   cin >> s; n   int ans = 0; n   for (int i = 0; i < (int)(s).size(); ++i) { n     ans = (ans * 16 + t[(int)s[i]]) % 1000003; n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void solve() { n   long long n, x, i, m = 1, second = 0; n   cin >> n >> x; n   long long a[n]; n   for (i = 0; i < n; i++) cin >> a[i]; n   sort(a, a + n); n   for (i = n - 1; i >= 0; i--) { n     second += a[i]; n     if (((second * 1.0) / m) < (x * 1.0)) break; n     m++; n   } n   cout << m - 1 <<   n ; n } n signed main() { n   long long t = 1; n   cin >> t; n   while (t--) solve(); n } n


#include <bits/stdc++.h> n using namespace std; n int n; n vector<char> veq; n void getVeq() { n   string s; n   cin >> s; n   veq.clear(); n   n = s.length(); n   veq.push_back( x ); n   veq.push_back( x ); n   for (int i = 0; i < s.length(); i++) veq.push_back(s[i]); n   veq.push_back( x ); n   veq.push_back( x ); n } n vector<int> ind; n void getRes() { n   char a, b, curr, c, d; n   ind.clear(); n   a = veq[0]; n   b = veq[1]; n   curr = veq[2]; n   c = veq[3]; n   d = veq[4]; n   for (int i = 2; i <= n + 1; i++) { n     curr = veq[i]; n     c = veq[i + 1]; n     d = veq[i + 2]; n     if (curr ==  e  && b ==  n  && a ==  o ) { n       ind.push_back(i - 2); n       b =  e ; n     } else if (curr ==  o  && b ==  w  && a ==  t ) { n       if (c ==  n  && d ==  e ) { n         ind.push_back(i - 1); n       } else { n         ind.push_back(i - 2); n         b =  o ; n       } n     } else { n       a = b; n       b = curr; n     } n   } n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int t; n   cin >> t; n   while (t--) { n     getVeq(); n     getRes(); n     cout << ind.size() <<   n ; n     for (int i = 0; i < ind.size(); i++) cout << ind[i] <<    ; n     cout <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, k, p, x, y, f, kek, all, a[100005]; n int main() { n   cin >> n >> k >> p >> x >> y; n   for (int i = 1; i <= k; i++) cin >> a[i]; n   int kol = (n + 1) / 2; n   for (int i = 1; i <= k; i++) n     if (a[i] >= y) kol--; n   if (n - k < kol) { n     cout << -1; n     return 0; n   } n   if (kol > 0) n     for (int j = k + 1; j <= k + kol; j++) a[j] = y; n   kol = max(0, kol); n   for (int j = k + kol + 1; j <= n; j++) a[j] = 1; n   int all = 0; n   for (int i = 1; i <= n; i++) all += a[i]; n   if (all > x) { n     cout << -1; n     return 0; n   } n   for (int i = k + 1; i <= n; i++) cout << a[i] <<    ; n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = 1e9 + 7; n const long long INF = 9e18; n const int inf = 2147483647; n long long phi(long long n) { n   long long ans = n; n   for (long long i = 2; i * i <= n; i++) { n     if (n % i == 0) { n       ans = ans / i * (i - 1); n       while (n % i == 0) n /= i; n     } n   } n   if (n > 1) ans = ans / n * (n - 1); n   return ans; n } n long long qpow(long long a, long long b, long long mod) { n   long long r = 1; n   for (; b; b >>= 1) { n     if (b & 1) r = (r * a) % mod; n     a = (a * a) % mod; n   } n   return r; n } n long long C(int n, int m) { n   if (m < n - m) m = n - m; n   long long ans = 1; n   for (int i = m + 1; i <= n; i++) ans *= i; n   for (int i = 1; i <= n - m; i++) ans /= i; n   return ans; n } n const int N = 2e5 + 5; n int look(int a, int x) { n   int q = sqrt(x + 0.5); n   int ans = inf; n   for (int i = 2; i <= q; i++) { n     if (x % i == 0) { n       int j = x / i; n       if (abs(i - a) < abs(j - a)) { n         if (abs(ans - a) > abs(i - a)) { n           ans = i; n         } n       } else { n         if (abs(ans - a) > abs(j - a)) { n           ans = j; n         } n       } n     } n   } n   if (ans >= inf) { n     if (abs(1 - a) < abs(x - a)) { n       ans = 1; n     } else { n       ans = x; n     } n   } else { n     if (abs(ans - a) > abs(1 - a)) { n       ans = 1; n     } n     if (abs(ans - a) > abs(x - a)) { n       ans = x; n     } n   } n   return ans; n } n void work() { n   int t; n   scanf( %d , &t); n   while (t--) { n     int a, b, c; n     scanf( %d%d%d , &a, &b, &c); n     int ta, tc; n     int ans = inf; n     int as[5]; n     for (int i = 1; i <= (int)2e4; i++) { n       int tb = i; n       if (tb > a) { n         ta = look(a, tb); n       } else { n         ta = tb; n       } n       if (c > tb) { n         int t1 = c / tb; n         int xc = t1 * tb, dc = (t1 + 1) * tb; n         if (abs(c - xc) < abs(c - dc)) { n           tc = xc; n         } else { n           tc = dc; n         } n       } else { n         tc = tb; n       } n       int cnt1 = abs(a - ta), cnt2 = abs(b - tb), cnt3 = abs(c - tc); n       if (cnt1 + cnt2 + cnt3 < ans) { n         ans = cnt1 + cnt2 + cnt3; n         as[0] = ta, as[1] = tb, as[2] = tc; n       } n     } n     printf( %d n , ans); n     for (int i = 0; i < 3; ++i) { n       printf( %d  , as[i]); n     } n     puts(  ); n   } n } n int main() { n   work(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 3e5 + 5; n vector<int> adj[MAXN]; n vector<pair<int, int>> q[MAXN]; n int n, m; n long long ans[MAXN], depval[MAXN]; n void dfs(int u, int dep, int pre, long long cur) { n   for (auto pr : q[u]) { n     depval[dep] += pr.second; n     if (dep + pr.first + 1 < MAXN) depval[dep + pr.first + 1] -= pr.second; n   } n   long long curr = cur + depval[dep]; n   ans[u] = curr; n   for (auto v : adj[u]) n     if (v != pre) dfs(v, dep + 1, u, curr); n   for (auto pr : q[u]) { n     depval[dep] -= pr.second; n     if (dep + pr.first + 1 < MAXN) depval[dep + pr.first + 1] += pr.second; n   } n } n int main() { n   scanf( %d , &n); n   for (int i = 1; i < n; i++) { n     int u, v; n     scanf( %d%d , &u, &v); n     adj[u].push_back(v); n     adj[v].push_back(u); n   } n   scanf( %d , &m); n   for (int i = 0; i < m; i++) { n     int v, d, x; n     scanf( %d%d%d , &v, &d, &x); n     q[v].emplace_back(d, x); n   } n   dfs(1, 0, 1, 0); n   for (int i = 1; i <= n; i++) printf( %lld  , ans[i]); n   printf(  n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 300 + 5; n const int MBIT = 15 + 5; n const int INF = 0x3f3f3f3f; n int n, m, MT, dp[MBIT][MAXN][MAXN]; n int ans[2][MAXN][MAXN]; n inline void umax(int& a, const int& b) { a = max(a, b); } n void init() { n   MT = (int)floor(log2((long double)n)); n   for (int s = 0; s <= MT; s++) { n     for (int i = 1; i <= n; i++) { n       for (int j = 1; j <= n; j++) { n         dp[s][i][j] = -INF; n       } n       dp[s][i][i] = 0; n     } n   } n } n void clr(int z) { n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= n; j++) { n       ans[z][i][j] = -INF; n     } n     ans[z][i][i] = 0; n   } n } n bool check(int step) { n   int z = 0; n   clr(z); n   for (int s = 0; s <= MT; s++) { n     if (((step >> s) & 1) == 0) continue; n     z ^= 1; n     clr(z); n     for (int k = 1; k <= n; k++) { n       for (int i = 1; i <= n; i++) { n         for (int j = 1; j <= n; j++) { n           umax(ans[z][i][j], ans[z ^ 1][i][k] + dp[s][k][j]); n         } n       } n     } n   } n   for (int i = 1; i <= n; i++) { n     if (ans[z][i][i] > 0) return true; n   } n   return false; n } n int main() { n   int u, v, a, b; n   while (~scanf( %d %d , &n, &m)) { n     init(); n     for (int i = 1; i <= m; i++) { n       scanf( %d %d %d %d , &u, &v, &a, &b); n       dp[0][u][v] = a, dp[0][v][u] = b; n     } n     for (int s = 1; s <= MT; s++) { n       for (int k = 1; k <= n; k++) { n         for (int i = 1; i <= n; i++) { n           if (dp[s - 1][i][k] == -INF) continue; n           for (int j = 1; j <= n; j++) { n             umax(dp[s][i][j], dp[s - 1][i][k] + dp[s - 1][k][j]); n           } n         } n       } n     } n     int lb = 2, ub = n + 1, mid; n     while (lb <= ub) { n       mid = (lb + ub) >> 1; n       if (check(mid)) n         ub = mid - 1; n       else n         lb = mid + 1; n     } n     if (lb >= n + 1) lb = 0; n     printf( %d n , lb); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool matrix[2005][2005]; n int main() { n   ios::sync_with_stdio(false); n   int n, m, k; n   cin >> n >> m >> k; n   string s; n   getline(cin, s); n   for (int y = 0; y < n; y++) { n     getline(cin, s); n     for (int x = 0; x < m; x++) matrix[x][y] = s[x] ==  . ; n   } n   int result = 0; n   for (int x = 0; x < m; x++) { n     int cnt = 0; n     for (int y = 0; y < n; y++) { n       if (matrix[x][y]) n         cnt++; n       else { n         result += max(0, cnt - k + 1); n         cnt = 0; n       } n     } n     result += max(0, cnt - k + 1); n   } n   if (k != 1) { n     for (int y = 0; y < n; y++) { n       int cnt = 0; n       for (int x = 0; x < m; x++) { n         if (matrix[x][y]) n           cnt++; n         else { n           result += max(0, cnt - k + 1); n           cnt = 0; n         } n       } n       result += max(0, cnt - k + 1); n     } n   } n   cout << result << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const long long inf = 1e18; n const long long Mod = 1e9 + 7; n const long double Pi = acos(-1); n long long n, m, k; n struct Weapon { n   long long Pow, Val; n } a[200009], b[200009]; n struct Monster { n   long long Att, Def, Val; n } c[200009]; n bool Cmp1(Weapon x, Weapon y) { return x.Pow < y.Pow; } n bool Cmp2(Monster x, Monster y) { return x.Att < y.Att; } n long long SufMin[200009]; n long long Tree[800009], Lzy[800009]; n void Merge(long long Node) { n   Tree[Node] = max(Tree[Node * 2], Tree[Node * 2 + 1]); n } n void Build(long long Node, long long l, long long r) { n   if (l == r) { n     Tree[Node] = -a[l].Val; n     return; n   } n   Build(Node * 2, l, (l + r) / 2); n   Build(Node * 2 + 1, (l + r) / 2 + 1, r); n   Merge(Node); n } n void LzyUpd(long long Node, long long l, long long r) { n   Tree[Node] += Lzy[Node]; n   if (l != r) { n     Lzy[Node * 2] += Lzy[Node]; n     Lzy[Node * 2 + 1] += Lzy[Node]; n   } n   Lzy[Node] = 0; n } n void Upd(long long Node, long long l, long long r, long long s, long long e, n          long long x) { n   if (l > r || s > e) return; n   LzyUpd(Node, l, r); n   if (s > r || e < l) return; n   if (s <= l && e >= r) { n     Lzy[Node] += x; n     LzyUpd(Node, l, r); n     return; n   } n   Upd(Node * 2, l, (l + r) / 2, s, e, x); n   Upd(Node * 2 + 1, (l + r) / 2 + 1, r, s, e, x); n   Merge(Node); n } n long long Query(long long Node, long long l, long long r) { n   LzyUpd(Node, l, r); n   return Tree[Node]; n } n long long Bin1(long long X) { n   long long l = -1, r = n; n   while (r - l > 1) { n     if (a[(l + r) / 2].Pow > X) n       r = (l + r) / 2; n     else n       l = (l + r) / 2; n   } n   return r; n } n long long Bin2(long long X) { n   long long l = -1, r = m; n   while (r - l > 1) { n     if (b[(l + r) / 2].Pow > X) n       r = (l + r) / 2; n     else n       l = (l + r) / 2; n   } n   return (r == m ? inf : SufMin[r]); n } n int main() { n   ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); n   cin >> n >> m >> k; n   for (int i = 0; i < n; i++) { n     cin >> a[i].Pow >> a[i].Val; n   } n   for (int i = 0; i < m; i++) { n     cin >> b[i].Pow >> b[i].Val; n   } n   for (int i = 0; i < k; i++) { n     cin >> c[i].Def >> c[i].Att >> c[i].Val; n   } n   sort(a, a + n, Cmp1); n   sort(b, b + m, Cmp1); n   sort(c, c + k, Cmp2); n   for (int i = m - 1; i >= 0; i--) { n     SufMin[i] = b[i].Val; n     SufMin[i] = min(SufMin[i], (long long)(i == m - 1 ? inf : SufMin[i + 1])); n   } n   Build(1, 0, n - 1); n   long long Ans = -Bin2(0) + Query(1, 0, n - 1); n   for (int i = 0; i < k; i++) { n     long long Id = Bin1(c[i].Def); n     Upd(1, 0, n - 1, Id, n - 1, c[i].Val); n     long long Best1 = Bin2(c[i].Att); n     long long Best2 = Query(1, 0, n - 1); n     Ans = max(Ans, -Best1 + Best2); n   } n   cout << Ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int n, q = 524288, p, ans = 1, lz; n int s[1048576], r[1048576]; n int getsum(int t) { n   if (t >= q) { n     if (r[t] > lz - q) { n       return 0; n     } else { n       return s[t]; n     } n   } n   if (r[t] <= lz - q) { n     return s[t]; n   } else if (r[t * 2] <= lz - q) { n     return s[t * 2] + getsum(t * 2 + 1); n   } else { n     return getsum(t * 2); n   } n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(NULL); n   cout.tie(NULL); n   cin >> n; n   cout << 1 << endl; n   lz = n - 1 + q; n   for (int i = q; i < 2 * q; i++) { n     r[i] = i - q; n   } n   for (int i = q - 1; i > 0; i--) { n     r[i] = r[i * 2 + 1]; n   } n   for (int i = 0; i < n; i++) { n     cin >> p; n     p--; n     p += q; n     while (p > 0) { n       s[p] += 1; n       p /= 2; n     } n     while (s[lz]) lz--; n     cout << getsum(1) + 1 << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 2147483647; n const long long LLINF = 9223372036854775807LL; n const int maxn = 100010; n const int mod = 1000000007; n int psum[7][maxn]; n int t[7][maxn * 4]; n bool needset[7][maxn * 4]; n int tset[7][maxn * 4]; n int a[maxn]; n inline int calcsum(int ti, int fr, int to) { n   int result = psum[ti][to]; n   if (fr) result = (result + mod - psum[ti][fr - 1]) % mod; n   return result; n } n inline void push(int ti, int v, int L, int R) { n   if (needset[ti][v]) { n     int ls = v + v + 1; n     int rs = v + v + 2; n     needset[ti][v] = false; n     if (L != R) { n       needset[ti][ls] = needset[ti][rs] = true; n       tset[ti][ls] = tset[ti][rs] = tset[ti][v]; n     } n     t[ti][v] = tset[ti][v] * (long long)calcsum(ti, L, R) % mod; n   } n } n inline void recalc(int ti, int v, int L, int R) { n   int ls = v + v + 1; n   int rs = v + v + 2; n   int m = (L + R) >> 1; n   push(ti, ls, L, m); n   push(ti, rs, m + 1, R); n   t[ti][v] = (t[ti][ls] + t[ti][rs]) % mod; n } n void build(int ti, int v, int L, int R) { n   if (L == R) { n     t[ti][v] = a[L]; n     for (int i = 0; i < ti; ++i) t[ti][v] = (long long)L * t[ti][v] % mod; n   } else { n     int m = (L + R) >> 1; n     build(ti, v + v + 1, L, m); n     build(ti, v + v + 2, m + 1, R); n     recalc(ti, v, L, R); n   } n } n void modify(int ti, int v, int l, int r, int val, int L, int R) { n   push(ti, v, L, R); n   if (L > r || l > R) return; n   if (L >= l && R <= r) n     needset[ti][v] = true, tset[ti][v] = val; n   else { n     int m = (L + R) >> 1; n     push(ti, v, L, R); n     modify(ti, v + v + 1, l, r, val, L, m); n     modify(ti, v + v + 2, l, r, val, m + 1, R); n     recalc(ti, v, L, R); n   } n } n int comb[7][7]; n int query(int ti, int v, int l, int r, int L, int R) { n   push(ti, v, L, R); n   if (l > R || L > r) return 0; n   if (l <= L && r >= R) n     return t[ti][v]; n   else { n     int m = (L + R) >> 1; n     int q1 = query(ti, v + v + 1, l, r, L, m); n     int q2 = query(ti, v + v + 2, l, r, m + 1, R); n     return (q1 + q2) % mod; n   } n } n int main() { n   for (int i = 0; i < maxn; ++i) { n     int curval = 1; n     for (int j = 0; j < 7; ++j) { n       psum[j][i] = curval; n       if (i) (psum[j][i] += psum[j][i - 1]) %= mod; n       curval = curval * (long long)i % mod; n     } n   } n   for (int i = 0; i < 7; ++i) comb[i][0] = 1; n   for (int i = 1; i < 7; ++i) n     for (int j = 1; j < 7; ++j) n       comb[i][j] = (comb[i - 1][j] + comb[i - 1][j - 1]) % mod; n   int n, m; n   scanf( %d%d , &n, &m); n   for (int i = 1; i <= n; ++i) scanf( %d , &a[i]); n   for (int i = 0; i < 6; ++i) build(i, 0, 0, n); n   for (int i = 0; i < m; ++i) { n     char c = 0; n     while (c !=  =  && c !=  ? ) c = getchar(); n     if (c ==  = ) { n       int fr, to, val; n       scanf( %d%d%d , &fr, &to, &val); n       for (int j = 0; j < 6; ++j) modify(j, 0, fr, to, val, 0, n); n     } else { n       int fr, to, k; n       scanf( %d%d%d , &fr, &to, &k); n       int shift = fr - 1; n       int answer = 0; n       int sg = 1; n       int st = 1; n       for (int j = k; j >= 0; --j) { n         int r = query(j, 0, fr, to, 0, n); n         r = ((long long)r * st) % mod * (long long)comb[k][j] % mod; n         if (sg == -1) r = (mod - r) % mod; n         (answer += r) %= mod; n         sg *= -1; n         st = st * (long long)shift % mod; n       } n       printf( %d n , answer); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n map<string, int> mp; n int n, m; n int a[110], b[110]; n int main() { n   while (~scanf( %d%d , &n, &m)) { n     mp.clear(); n     for (int i = 0; i < (n); ++i) scanf( %d , a + i); n     for (int i = 0; i < (m); ++i) { n       string s; n       cin >> s; n       mp[s]++; n     } n     int tot = 0; n     for (map<string, int>::iterator it = mp.begin(); it != mp.end(); ++it) n       b[tot++] = it->second; n     sort(a, a + n); n     sort(b, b + tot); n     int mint = 0, maxt = 0; n     for (int i = 0; i < (tot); ++i) n       mint += a[i] * b[tot - 1 - i], maxt += a[n - tot + i] * b[i]; n     printf( %d %d n , mint, maxt); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 250000 + 5; n long long dp[maxn]; n int main() { n   long long n, m; n   scanf( %lld %lld , &n, &m); n   dp[0] = dp[1] = 1; n   for (long long i = 2; i <= n; i++) { n     dp[i] = ((dp[i - 1] % m) * (i % m)) % m; n   } n   long long sum = 0; n   for (long long i = 1; i <= n; i++) { n     sum += (((dp[i] % m) * (dp[n - i + 1] % m) % m) * ((n - i + 1) % m)) % m; n   } n   printf( %lld n , sum % m); n } n


#include <bits/stdc++.h> n using namespace std; n long n; n vector<long> prec; n int main() { n   ios_base::sync_with_stdio(0); n   prec.push_back(2); n   prec.push_back(7); n   prec.push_back(2); n   prec.push_back(3); n   prec.push_back(3); n   prec.push_back(4); n   prec.push_back(2); n   prec.push_back(5); n   prec.push_back(1); n   prec.push_back(2); n   cin >> n; n   cout << prec[n / 10] * prec[n % 10] << endl; n   cin.get(); n   cin.get(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long MOD = 1e9 + 7; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   string s; n   cin >> s; n   int a[s.length()]; n   int n = s.length(); n   int ans = 0; n   for (int i = 0; i < n; i++) { n     int x = s[i] -  0 ; n     a[i] = x % 3; n     if (a[i] == 0) { n       ans++; n     } n   } n   for (int i = 0; i < n; i++) { n     if (a[i] == 1) { n       if (i < n - 1) { n         if (a[i + 1] == 2) { n           ans++; n           a[i] = 0; n           a[i + 1] = 0; n           continue; n         } n       } n       if (i < n - 2) { n         if (a[i + 1] == 1 and a[i + 2] == 1) { n           ans++; n           a[i] = 0; n           a[i + 1] = 0; n           a[i + 2] = 0; n           continue; n         } n       } n     } n     if (a[i] == 2) { n       if (i < n - 1) { n         if (a[i + 1] == 1) { n           ans++; n           a[i] = 0; n           a[i + 1] = 0; n           continue; n         } n       } n       if (i < n - 2) { n         if (a[i + 1] == 2 and a[i + 2] == 2) { n           ans++; n           a[i] = a[i + 1] = a[i + 2] = 0; n           continue; n         } n       } n     } n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int cnt[1005]; n vector<long long int> csum; n string str; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   int n; n   int m; n   cin >> n >> m; n   long long int x; n   cin >> x; n   csum.push_back(x); n   for (int i = 1; i < n; i++) { n     cin >> x; n     long long int y = x + csum[i - 1]; n     csum.push_back(y); n   } n   for (int i = 0; i < m; i++) { n     long long int y; n     cin >> y; n     int lo = lower_bound(csum.begin(), csum.end(), y) - csum.begin(); n     if (lo + 1 == 1) { n       cout << lo + 1 <<     << y << endl; n       continue; n     } n     cout << lo + 1 <<     << y - csum[lo - 1] << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<vector<int> > init(int n, int v) { n   vector<vector<int> > ret; n   for (int i = 0; i < (n); ++i) { n     vector<int> l; n     l.resize(n); n     for (int j = 0; j < (n); ++j) l[j] = v; n     ret.push_back(l); n   } n   return ret; n } n void dump(const vector<vector<int> >& arr) { n   cout <<   dump: n ; n   int n = arr.size(); n   for (int i = 0; i < (n); ++i) { n     for (int j = 0; j < (n); ++j) { n       cout << arr[i][j] + 1 <<    ; n     } n     cout << endl; n   } n } n bool discover(int n, const vector<string>& ma, vector<vector<int> >& has_p) { n   bool found = false; n   for (int i = 0; i < (n); ++i) { n     for (int j = 0; j < (n); ++j) { n       int points = ma[i][j] -  0 ; n       int has_point = 0; n       int no_point = 0; n       for (int u = 0; u < (2); ++u) { n         for (int v = 0; v < (2); ++v) { n           int i1 = i + u; n           int j1 = j + v; n           has_point += has_p[i1][j1] == 1; n           no_point += has_p[i1][j1] == -1; n         } n       } n       points -= has_point; n       int left_points = 4 - has_point - no_point; n       if ((points == 0 || points == left_points) && left_points > 0) { n         found = true; n         int val = points == 0 ? -1 : 1; n         for (int u = 0; u < (2); ++u) { n           for (int v = 0; v < (2); ++v) { n             int i1 = i + u; n             int j1 = j + v; n             if (has_p[i1][j1] == 0) { n               has_p[i1][j1] = val; n             } n           } n         } n       } n     } n   } n   return found; n } n pair<int, int> del(pair<int, int> a, pair<int, int> b) { n   return make_pair(a.first - b.first, a.second - b.second); n } n int dot(pair<int, int> a, pair<int, int> b) { n   return a.first * b.second - a.second * b.first; n } n int main() { n   int n; n   while (cin >> n) { n     if (n == 0) break; n     vector<string> ma; n     for (int i = 0; i < (n); ++i) { n       string line; n       cin >> line; n       ma.push_back(line); n     } n     vector<vector<int> > has_p = init(n + 1, 0); n     while (discover(n, ma, has_p)) n       ; n     vector<pair<int, int> > points; n     for (int i = 0; i < (n + 1); ++i) { n       for (int j = 0; j < (n + 1); ++j) { n         if (has_p[i][j] == 1) { n           points.push_back(make_pair(j, n - i)); n         } n       } n     } n     sort((points).begin(), points.end()); n     vector<pair<int, int> > conv; n     conv.push_back(points[0]); n     conv.push_back(points[1]); n     for (int i = 2; i < (points.size()); ++i) { n       while (conv.size() > 1 && n              dot(del(points[i], conv[conv.size() - 1]), n                  del(conv[conv.size() - 1], conv[conv.size() - 2])) <= 0) n         conv.pop_back(); n       conv.push_back(points[i]); n     } n     int nl = conv.size(); n     for (int i = points.size() - 2; i >= 0; i--) { n       while (conv.size() > 1 && n              dot(del(points[i], conv[conv.size() - 1]), n                  del(conv[conv.size() - 1], conv[conv.size() - 2])) <= 0 && n              conv.size() > nl) { n         conv.pop_back(); n       } n       conv.push_back(points[i]); n     } n     conv.pop_back(); n     cout << conv.size() << endl; n     for (int i = 0; i < (conv.size()); ++i) n       cout << conv[i].first <<     << conv[i].second << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long n, m, a, b; n   cin >> n >> m >> a >> b; n   if (n % m == 0) { n     cout << 0; n   } else { n     long long j = n % m; n     cout << min(j * b, (m - j) * a); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int a, b, c, n; n   cin >> a >> b >> c >> n; n   int d = n - (a + b - c); n   if ((a - c) >= 0 && (b - c) >= 0 && c >= 0 && d > 0) { n     cout << d << endl; n   } else n     cout << -1 << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e5 + 5; n const int inf = 0x3f3f3f3f; n int b[maxn]; n int a[maxn]; n int ma[maxn]; n int pre[maxn * 10]; n int _find(int x) { return x == pre[x] ? x : pre[x] = _find(pre[x]); } n void _union(int x, int y) { n   x = _find(x), y = _find(y); n   if (x < y) n     pre[x] = y; n   else n     pre[y] = x; n } n int main() { n   int n; n   scanf( %d , &n); n   for (int i = 0; i < maxn * 10; ++i) pre[i] = i; n   for (int i = 1; i <= n; ++i) { n     scanf( %d , &a[i]); n     ma[i] = max(ma[i - 1], a[i]); n   } n   bool flag = true; n   int x = 0; n   for (int i = n; i > 0; --i) { n     if (a[i] > ma[i - 1]) n       b[i] = ma[i - 1]; n     else n       b[i] = a[i] + 1; n     b[i] = _find(b[i]); n     _union(b[i], b[i] + 1); n     _union(a[i], a[i] + 1); n     x = max(x, a[i]); n   } n   if (!flag) n     puts( -1 ); n   else { n     for (int i = 1; i <= n; ++i) printf( %d%c , b[i], i == n ?   n  :    ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int M = 1e9 + 7, N = 1e6 + 5; n char a[51][51]; n int n, m; n int vis[51][51]; n void dfs(int i, int j) { n   vis[i][j] = 1; n   if (i - 1 >= 0 and a[i - 1][j] ==  #  and vis[i - 1][j] == 0) dfs(i - 1, j); n   if (i + 1 < n and a[i + 1][j] ==  #  and vis[i + 1][j] == 0) dfs(i + 1, j); n   if (j - 1 >= 0 and a[i][j - 1] ==  #  and vis[i][j - 1] == 0) dfs(i, j - 1); n   if (j + 1 < m and a[i][j + 1] ==  #  and vis[i][j + 1] == 0) dfs(i, j + 1); n } n int func() { n   for (int i = 0; i < 51; i++) n     for (int j = 0; j < 51; j++) vis[i][j] = 0; n   int check = 0; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       if (a[i][j] ==  # ) check = 1, dfs(i, j); n       if (check) break; n     } n     if (check) break; n   } n   check = 1; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       if (a[i][j] ==  #  and vis[i][j] == 0) { n         check = 0; n         break; n       } n     } n   } n   return check; n } n int main() { n   ios::sync_with_stdio(false), cin.tie(nullptr); n   cin >> n >> m; n   int cnt = 0; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       cin >> a[i][j]; n       if (a[i][j] ==  # ) cnt++; n     } n   } n   if (cnt <= 2) cout << -1, exit(0); n   int ans = 2; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       if (a[i][j] ==  # ) { n         a[i][j] =  . ; n         if (func() == 0) { n           ans = 1; n           break; n         } n         a[i][j] =  # ; n       } n     } n     if (ans == 1) break; n   } n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n struct Tree { n   long long maxv[80005]; n   void pushup(int x) { maxv[x] = max(maxv[x << 1], maxv[x << 1 | 1]); } n   void update(int x, int l, int r, int p, long long v) { n     if (l == r) { n       maxv[x] = v; n       return; n     } n     if (p <= ((l + r) >> 1)) n       update(x << 1, l, ((l + r) >> 1), p, v); n     else n       update(x << 1 | 1, ((l + r) >> 1) + 1, r, p, v); n     pushup(x); n   } n   long long ask(int x, int l, int r, int from, int to) { n     if (from > to) return -1e12; n     if (l >= from && r <= to) return maxv[x]; n     long long ans = -1e12; n     if (from <= ((l + r) >> 1)) n       ans = max(ans, ask(x << 1, l, ((l + r) >> 1), from, to)); n     if (to > ((l + r) >> 1)) n       ans = max(ans, ask(x << 1 | 1, ((l + r) >> 1) + 1, r, from, to)); n     return ans; n   } n }; n Tree t1, t2, t3; n int n, m, l; n long long a[55][20005], s[55][20005], f[20005]; n int main() { n   scanf( %d%d%d , &n, &m, &l); n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= m; j++) scanf( %lld , &a[i][j]); n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= m; j++) s[i][j] = s[i][j - 1] + a[i][j]; n   for (int i = 1; i <= 80000; i++) t1.maxv[i] = t2.maxv[i] = t3.maxv[i] = -1e12; n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j + l - 1 <= m; j++) { n       f[j] = max(t1.ask(1, 1, m, 1, j - l), t1.ask(1, 1, m, j + l, m)); n       f[j] = max(f[j], t2.ask(1, 1, m, j - l + 1, j) + s[i][j - 1]); n       f[j] = max(f[j], t3.ask(1, 1, m, j + 1, j + l) - s[i][j + l - 1]); n       f[j] = max(f[j], 0ll); n     } n     for (int j = 1; j + l - 1 <= m; j++) { n       f[j] = f[j] + s[i][j + l - 1] - s[i][j - 1] + s[i + 1][j + l - 1] - n              s[i + 1][j - 1]; n       t1.update(1, 1, m, j, f[j]); n       t2.update(1, 1, m, j, f[j] - s[i + 1][j + l - 1]); n       t3.update(1, 1, m, j, f[j] + s[i + 1][j - 1]); n     } n   } n   printf( %lld n , t1.ask(1, 1, n, 1, n)); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 5, oo = 0x3f3f3f3f; n const long long M = 1e12 + 105; n int dx[] = {1, 0, -1, 0}; n int dy[] = {0, -1, 0, 1}; n int main() { n   int c, r, ans = 0; n   scanf( %d %d , &r, &c); n   char second[r][c]; n   for (int i = 0; i < r; i++) scanf( %s , second[i]); n   for (int i = 0; i < r; i++) { n     int cc = 0; n     for (int j = 0; j < c; j++) n       if (second[i][j] ==  S ) n         break; n       else if (second[i][j] ==  . ) n         cc++; n     if (cc == c) { n       ans += cc; n       for (int j = 0; j < c; j++) second[i][j] =  X ; n     } n   } n   for (int i = 0; i < c; i++) { n     bool ff = false; n     int cc = 0; n     for (int j = 0; j < r; j++) n       if (second[j][i] ==  S ) { n         ff = true; n         break; n       } else if (second[j][i] ==  . ) n         cc++, second[j][i] =  X ; n     if (!ff) ans += cc; n   } n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 300005; n int sum; n int main() { n   int n, k; n   scanf( %d%d , &n, &k); n   for (int i = 0, x; i < n; ++i) scanf( %d , &x), sum += x; n   for (int i = 0;; ++i) { n     if (2 * sum >= (2 * k - 1) * (n + i)) { n       printf( %d n , i); n       break; n     } n     sum += k; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int64_t pre[200001]; n int64_t dp[200001]; n int n; n int main() { n   cin >> n; n   for (int i = 1; i <= n; ++i) { n     cin >> pre[i]; n     pre[i] += pre[i - 1]; n   } n   int64_t mx = -1e15; n   for (int i = n - 1; i >= 1; --i) { n     dp[i] = max(pre[n], mx); n     mx = max(mx, pre[i] - dp[i]); n   } n   cout << dp[1] <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long int m = 1000000007; n int size = 1000004; n bool mo(long long int n) { n   int t = 0; n   while (n) { n     if (n % 10 == 3) t++; n     n = n / 10; n   } n   if (t >= 3) n     return true; n   else n     return false; n } n int main() { n   long long int n; n   cin >> n; n   if (n == 1) { n     cout << -1 << endl; n     return 0; n   } n   cout << n <<     << n + 1 <<     << n * (n + 1) << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1 << 16; n int n, xa, xb, a[20], b[20], ca[N], cb[N], f[N][140], ans = 0x7fffffff; n int main() { n   ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); n   cin >> n; n   char c; n   for (int i = 1; i <= n; i++) { n     cin >> c >> a[i] >> b[i]; n     xa += a[i], xb += b[i]; n     for (int j = 0; j < (1 << n); j++) n       if (j & (1 << i - 1)) { n         if (c ==  R ) n           ca[j]++; n         else n           cb[j]++; n       } n   } n   memset(f, -1, sizeof(f)); n   f[0][0] = 0; n   for (int i = 0; i < (1 << n); i++) n     for (int j = 0; j <= 130; j++) n       if (f[i][j] != -1) n         for (int k = 1; k <= n; k++) n           if (!(i & (1 << k - 1))) { n             int ti = i | (1 << (k - 1)), sa = min(a[k], ca[i]), n                 sb = min(b[k], cb[i]); n             f[ti][j + sa] = max(f[ti][j + sa], f[i][j] + sb); n           } n   for (int i = 0; i <= 130; i++) n     if (f[(1 << n) - 1][i] != -1) n       ans = min(ans, max(xa - i, xb - f[(1 << n) - 1][i])); n   cout << ans + n; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, k; n string A[505]; n bool a[505][505]; n int star[505][505]; n int col[505][505]; n int main() { n   cin >> n >> m >> k; n   for (int i = 0; i < n; i++) cin >> A[i]; n   for (int i = 0; i < n; i++) n     for (int j = 0; j < m; j++) a[i][j] = A[i][j] ==  1 ; n   for (int i = 1; i < n - 1; i++) n     for (int j = 1; j < m - 1; j++) { n       if (a[i][j] && a[i - 1][j] && a[i + 1][j] && a[i][j - 1] && a[i][j + 1]) n         star[i][j] = 1; n     } n   for (int j = 0; j < m; j++) { n     col[j][0] = 0; n     for (int i = 0; i < n; i++) col[j][i + 1] = col[j][i] + int(star[i][j]); n   } n   long long res = 0; n   for (int i1 = 0; i1 < n; i1++) n     for (int i2 = i1 + 3; i2 < n + 1; i2++) { n       int z[m]; n       for (int j = 1; j < m - 1; j++) z[j] = col[j][i2 - 1] - col[j][i1 + 1]; n       int s = 0, j2 = 1; n       for (int j1 = 1; j1 < m - 1; j1++) { n         while (s < k) s += z[j2++]; n         res += m - j2; n         s -= z[j1]; n       } n     } n   cout << res << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const long long A = 100000000000000LL, N = 300228; n long long t[N * 4], i, j, n, m, a[N], p[N], o, b, l, r; n void modi(long long v, long long l, long long r, long long p, long long g) { n   if (p < l || p > r) return; n   if (l == r) { n     t[v] = g; n     return; n   } n   long long mid = (l + r) / 2; n   if (p <= mid) n     modi(v * 2, l, mid, p, g); n   else n     modi(v * 2 + 1, mid + 1, r, p, g); n   t[v] = t[v * 2] + t[v * 2 + 1]; n } n long long get(long long v, long long l, long long r, long long _l, n               long long _r) { n   if (_l > _r) return 0; n   if (l == _l && r == _r) return t[v]; n   long long mid = (l + r) / 2; n   return get(v * 2, l, mid, _l, min(_r, mid)) + n          get(v * 2 + 1, mid + 1, r, max(mid + 1, _l), _r); n } n int main() { n   cin >> n; n   for (i = 1; i <= n; i++) scanf( %d , &a[i]), p[a[i]] = i; n   for (i = 1; i < n; i++) n     if (p[i] > p[i + 1]) modi(1, 1, n, i + 1, 1); n   cin >> m; n   while (m--) { n     scanf( %d%d%d , &b, &l, &r); n     if (b == 1) n       printf( %d n , get(1, 1, n, l + 1, r) + 1); n     else { n       swap(p[a[l]], p[a[r]]), swap(a[l], a[r]); n       if (p[a[l]] > p[a[l] + 1]) n         modi(1, 1, n, a[l] + 1, 1); n       else n         modi(1, 1, n, a[l] + 1, 0); n       if (p[a[r]] > p[a[r] + 1]) n         modi(1, 1, n, a[r] + 1, 1); n       else n         modi(1, 1, n, a[r] + 1, 0); n       if (p[a[l] - 1] > p[a[l]]) n         modi(1, 1, n, a[l], 1); n       else n         modi(1, 1, n, a[l], 0); n       if (p[a[r] - 1] > p[a[r]]) n         modi(1, 1, n, a[r], 1); n       else n         modi(1, 1, n, a[r], 0); n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n bool desc(pair<long long, long long> a, pair<long long, long long> b) { n   return a.first > b.first; n } n long long counter = 0, countedge = 0; n void addEdge(vector<long long> adj[], long long u, long long v) { n   adj[u].push_back(v); n   adj[v].push_back(u); n } n long long fact(long long x) { n   long long z = 1; n   while (x > 0) { n     z *= x; n     x--; n   } n   return z; n } n long long power(long long x, long long y) { n   long long z = 1; n   while (y-- > 0) { n     z *= 2; n   } n   return z; n } n void dfs(vector<long long> adj[], long long u, bool vis[]) { n   int i, j; n   vis[u] = true; n   counter++; n   countedge += adj[u].size(); n   for (i = 0; i < adj[u].size(); i++) { n     if (!vis[adj[u][i]]) dfs(adj, adj[u][i], vis); n   } n } n pair<pair<long long, long long>, pair<long long, long long> > Intersect( n     pair<long long, long long> a, pair<long long, long long> b, n     pair<long long, long long> c, pair<long long, long long> d) { n   int i, j, z, lf, rg, up, dwn; n   pair<long long, long long> p1, p2; n   lf = max(a.first, c.first); n   rg = min(b.first, d.first); n   dwn = max(a.second, c.second); n   up = min(b.second, d.second); n   p1 = make_pair(lf, dwn); n   p2 = make_pair(rg, up); n   if (rg <= lf || up <= dwn) return {{0, 0}, {0, 0}}; n   return make_pair(p1, p2); n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long int i, j, n, m, cont = 0, p, d, mn, sum = 0, k, a, b, z, w, n                             sum2 = 0, c = 0, first, val, ans, nx, ny, o = 0, mx, n                             s1, s2, l, r; n   string s, t; n   long long flag = 0; n   vector<pair<long long, long long> > pt(7); n   for (i = 1; i <= 6; i++) { n     cin >> pt[i].first >> pt[i].second; n   } n   pair<pair<long long, long long>, pair<long long, long long> > wb1, wb2, inter; n   wb1 = Intersect(pt[1], pt[2], pt[3], pt[4]); n   wb2 = Intersect(pt[1], pt[2], pt[5], pt[6]); n   inter = Intersect(wb1.first, wb1.second, wb2.first, wb2.second); n   long long a1, a2; n   a1 = (abs(wb1.first.first - wb1.second.first) * n         abs(wb1.first.second - wb1.second.second)); n   a2 = (abs(wb2.first.first - wb2.second.first) * n         abs(wb2.first.second - wb2.second.second)); n   c = (abs(inter.first.first - inter.second.first) * n        abs(inter.first.second - inter.second.second)); n   long long area = (pt[1].first - pt[2].first) * (pt[1].second - pt[2].second); n   if (area > (a1 + a2 - c)) n     cout <<  YES ; n   else { n     cout <<  NO ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int n, q, a[2000000], f[2000000], fst[2000000], nx[2000000]; n int main() { n   srand(time(0)); n   scanf( %d %d , &n, &q); n   for (int i = 1; i <= n; i++) scanf( %d , &a[i]); n   for (; q--;) { n     long long b; n     cin >> b; n     int answer = 2e9, j = 1; n     long long sum = 0; n     for (int i = 1; i <= n; i++) { n       sum += a[i]; n       while (sum > b) { n         sum -= a[j]; n         j++; n       } n       nx[i] = j - 1; n     } n     f[0] = 0; n     for (int i = 1; i <= n; i++) f[i] = f[nx[i]] + 1; n     for (int i = 1; i <= n; i++) n       if (f[i] == 1) n         fst[i] = i; n       else n         fst[i] = fst[nx[i]]; n     sum = a[1]; n     if (sum > b) { n       printf( %d n , answer); n       continue; n     } n     int it = 1; n     long long rightpart = a[1]; n     for (int i = 2; i < n; i++) { n       if (sum + a[i] > b) break; n       sum += a[i]; n       rightpart += a[i]; n       it = i; n     } n     for (int i = n; i >= 2; i--) { n       sum += a[i]; n       while (it > 0 && sum > b) { n         sum -= a[it]; n         rightpart -= a[it]; n         it--; n       } n       if (sum > b) break; n       if (fst[i - 1] <= it) n         answer = min(answer, f[i - 1]); n       else n         answer = min(answer, f[i - 1] + 1); n     } n     printf( %d n , answer); n   }; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 100000 + 10; n int n; n int a[N], indexes[N], parent[N], rrank[N], ccount[N]; n bool used[N]; n int get_set(int v) { n   if (v == parent[v]) return v; n   return parent[v] = get_set(parent[v]); n } n void create_set(int v) { n   parent[v] = v; n   rrank[v] = 0; n   ccount[v] = 1; n } n void merge_sets(int v, int u) { n   v = get_set(v); n   u = get_set(u); n   if (v != u) { n     if (rrank[v] > rrank[u]) swap(v, u); n     parent[v] = u; n     if (rrank[v] == rrank[u]) rrank[u]++; n     ccount[u] += ccount[v]; n   } n } n bool comp(int i, int j) { return a[i] < a[j]; } n int solve() { n   int maxSize = 0, maxSets, sets = 0; n   int res = 0, resSets = -1; n   for (int i = 0; i < n; i++) { n     bool isMerged = false; n     int ind = indexes[i]; n     used[ind] = true; n     sets++; n     if (ind > 0 && used[ind - 1]) { n       isMerged = true; n       merge_sets(ind - 1, ind); n       sets--; n     } n     if (ind < n - 1 && used[ind + 1]) { n       isMerged = true; n       merge_sets(ind + 1, ind); n       sets--; n     } n     int sst = get_set(ind); n     if (ccount[sst] > maxSize) { n       maxSize = ccount[sst]; n       maxSets = 1; n     } else if (ccount[sst] == maxSize) { n       maxSets++; n     } n     if (i < n - 1 && a[indexes[i]] == a[indexes[i + 1]]) { n       continue; n     } n     if (maxSets == sets && sets > resSets) { n       resSets = sets; n       res = a[ind] + 1; n     } n   } n   return res; n } n int main() { n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n     indexes[i] = i; n     create_set(i); n     used[i] = false; n   } n   sort(indexes, indexes + n, comp); n   cout << solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long int m; n long long int power(long long int x, long long int y) { n   long long int res = 1; n   while (y > 0) { n     if (y & 1) res = res * x; n     res %= m; n     y = y >> 1; n     x = x * x; n     x %= m; n   } n   return res; n } n long long int inv(long long int x) { return power(x, m - 2); } n long long int prime[100009]; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cin >> m; n   for (long long int i = 2; i <= 100000; i++) { n     if (prime[i] == 0) { n       for (long long int j = (2 * i); j <= 100000; j += i) { n         prime[j] = 1; n       } n     } n   } n   if (m == 1) { n     cout <<  YES  <<   n  << 1; n   } else if (m == 4) { n     cout <<  YES  <<   n ; n     cout << 1 <<   n  << 3 <<   n  << 2 <<   n  << 4; n   } else if (prime[m] == 0) { n     cout <<  YES  <<   n ; n     cout << 1 <<   n ; n     long long int x = 1; n     for (long long int j = 2; j < m; j++) { n       x = inv((j - 1)); n       x *= j; n       x %= m; n       cout << x <<   n ; n     } n     cout << m; n   } else { n     cout <<  NO ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int n, m; n long long u; n long long a[1000]; n long long d[1000]; n long long minn = -1e17; n int main() { n   scanf( %d%d , &n, &m); n   for (int i = 1; i <= n; ++i) { n     scanf( %lld , &a[i]); n     d[i] = minn; n   } n   for (int i = n; i >= 0; --i) { n     for (int j = n; j >= 0; --j) { n       if (j == 0) { n         u = minn; n       } else n         u = d[j - 1]; n       d[j] = max(min(d[j] + a[i], 0LL), u); n     } n   } n   while (m--) { n     scanf( %lld , &u); n     int k = lower_bound(d, d + n + 1, -u) - d; n     cout << k << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long double EPS = 1E-9; n const int INF = (int)1E9; n const long long INF64 = (long long)1E18; n const long double PI = 2 * acos(.0); n int main() { n   bool cumple[1005]; n   for (int i = 0; i < (int)(1005); i++) cumple[i] = false; n   string word; n   cin >> word; n   int n = (word).size(); n   for (int i = 2; i <= n / 2; i++) { n     cumple[i] = 1; n     for (int j = 2; i * j <= n; j++) { n       cumple[i * j] = 1; n     } n   } n   int cont1 = 0; n   for (int i = 1; i < (int)(n + 1); i++) { n     if (cumple[i] == 1) cont1++; n   } n   int numWord[50]; n   memset(numWord, 0, sizeof(numWord)); n   for (int i = 0; i < (int)(n); i++) numWord[word[i] -  a ]++; n   int maxPos = -1, maxi = -1; n   for (int i = 0; i < (int)(50); i++) { n     if (maxi < numWord[i]) { n       maxi = numWord[i]; n       maxPos = i; n     } n   } n   if (maxi < cont1) n     cout <<  NO  << endl; n   else { n     string rege; n     rege.append(n,  ? ); n     for (int i = 1; i < (int)(n + 1); i++) n       if (cumple[i] == 1) rege[i - 1] =  a  + maxPos; n     numWord[maxPos] -= cont1; n     int cont = 0, wpos = 0; n     while (wpos < n) { n       if (rege[wpos] ==  ? ) { n         if (numWord[cont] > 0) { n           rege[wpos] = ( a  + cont); n           numWord[cont]--; n         } else n           cont++; n       } else n         wpos++; n     } n     cout <<  YES  << endl; n     cout << rege << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, a[100][100], f[2000000], p; n char s[30][30]; n int main() { n   scanf( %d%d , &n, &m); n   for (int i = 0; i < n; i++) scanf( %s , s[i]); n   for (int i = 0; i < n; i++) n     for (int j = 0; j < m; j++) scanf( %d , &a[i][j]); n   memset(f, 0x3f, sizeof(f)); n   f[0] = 0; n   for (int i = 0; i <= (1 << n) - 2; i++) { n     for (int j = 0; j < n; j++) n       if (!(i & (1 << j))) { n         p = j; n         break; n       } n     for (int j = 0; j < m; j++) { n       int sum = 0, l = 0, mx = 0; n       f[i | (1 << p)] = min(f[i | (1 << p)], f[i] + a[p][j]); n       for (int k = 0; k < n; k++) n         if (s[k][j] == s[p][j]) { n           sum = sum + a[k][j]; n           mx = max(mx, a[k][j]); n           l = l | (1 << k); n         } n       f[i | l] = min(f[i | l], f[i] + sum - mx); n     } n   } n   return printf( %d , f[(1 << n) - 1]), 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n     ios::sync_with_stdio(false); n     cin.tie(nullptr); n     int t; n     cin >> t; n     while (t--) { n         int n, k; n         cin >> n >> k; n         string s; n         cin >> s; n         vector<int> pos; n         vector<int> v; n         for (int i = 0; i < n; i++) { n             if (s[i] ==  * ) { n                 pos.push_back(i); n             } n         } n         if (pos.size()) { n             v.push_back(pos[0]); n         } n         while (v.size() and v.back() + k < n) { n             int i = upper_bound(pos.begin(), pos.end(), v.back() + k) - pos.begin(); n             if (pos[i - 1] == v.back()) { n                 break; n             } n             v.push_back(pos[i - 1]); n         } n         if (pos.back() != v.back()) { n             v.push_back(pos.back()); n         } n         cout << v.size() <<   n ; n     } n     return 0; n }


#include <bits/stdc++.h> n using namespace std; n int ToInt(string& s, int len) { n   int r = 0; n   for (int i = 0, max_ = (len); i < max_; ++i) { n     r *= 10; n     r += s[i] -  0 ; n   } n   return r; n } n int GCD(int a, int b) { return b != 0 ? GCD(b, a % b) : a; } n int LCM(int a, int b) { return a * (b / GCD(a, b)); } n long long Pow(long long n, long long e) { n   if (e == 0) return 1; n   if (e == 1) n     return n; n   else if (e & 1) { n     long long t = Pow(n, e / 2); n     return n * t * t; n   } else { n     long long t = Pow(n, e / 2); n     return t * t; n   } n } n int SolvePile(long long n) { n   if (n < 4) n     return 0; n   else if (n < 16) n     return 1; n   else if (n < 82) n     return 2; n   else if (n < 6724) n     return 0; n   else if (n < 50626) n     return 3; n   else if (n < 2562991876LL) n     return 1; n   else n     return 2; n } n int main() { n   long long n; n   int N, res = 0; n   scanf( %d , &N); n   for (int i = 0, max_ = (N); i < max_; ++i) { n     scanf( %I64d , &n); n     res ^= SolvePile(n); n   } n   if (res > 0) n     printf( Furlo n ); n   else n     printf( Rublo n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   bool flag = true; n   int n, m; n   cin >> n; n   cin >> m; n   char prev; n   for (int i = 0; i < n; i++) { n     string row; n     cin >> row; n     if (i != 0 && row[0] == prev) { n       flag = false; n     } n     for (int j = 1; j < m; j++) { n       if (row[j] != row[0]) { n         flag = false; n         break; n       } n     } n     prev = row[0]; n   } n   if (flag) { n     cout <<  Yes  << endl; n   } else { n     cout <<  No  << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> v[100010], ans; n int idx = 1; n void dfs(int cur, int prev) { n   if ((int)v[cur].size() == 1 && cur != idx) n     ans.push_back(cur); n   else { n     for (int i = 0; i < (int)v[cur].size(); i++) { n       int j = v[cur][i]; n       if (j != prev) dfs(j, cur); n     } n   } n   return; n } n int main() { n   int n; n   scanf( %d , &n); n   for (int i = 1; i < n; i++) { n     int x, y; n     scanf( %d %d , &x, &y); n     v[x].push_back(y); n     v[y].push_back(x); n   } n   int cnt = 0; n   for (int i = 1; i <= n; i++) n     if ((int)v[i].size() > 2) cnt++, idx = i; n   if (cnt > 1) { n     printf( No n ); n     return 0; n   } n   printf( Yes n ); n   dfs(idx, -1); n   printf( %d n , (int)ans.size()); n   for (int i = 0; i < (int)ans.size(); i++) printf( %d %d n , idx, ans[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = 0x3f3f3f3f, mod = 1000000007; n const double pi = 3.1415926535897932, eps = 1e-6; n void chmax(int &x, int y) { n   if (x < y) x = y; n } n void chmin(int &x, int y) { n   if (x > y) x = y; n } n int B = 333; n int n, top = 101000, cnt; n string s[100005]; n int val[300005], ex[300005]; n long long sum[444][5]; n int num[444], rea[100005]; n map<int, int> mp; n void calc(int x) { n   int lb = x * B, rb = (x + 1) * B; n   int now_cnt = 0; n   for (int(i) = (0); (i) <= (4); (i)++) sum[x][i] = 0; n   num[x] = 0; n   for (int(i) = (lb); (i) < (rb); (i)++) { n     if (ex[i]) { n       sum[x][now_cnt % 5] += rea[i]; n       now_cnt++; n     } n   } n   num[x] = now_cnt; n } n int main() { n   ios::sync_with_stdio(false); n   cin >> n; n   for (int(i) = (1); (i) <= (n); (i)++) { n     cin >> s[i]; n     if (s[i] !=  sum ) { n       cin >> val[i]; n       mp[val[i]] = 0; n     } n   } n   for (map<int, int>::iterator it = mp.begin(); it != mp.end(); it++) { n     rea[cnt] = it->first; n     it->second = cnt++; n   } n   for (int(i) = (1); (i) <= (n); (i)++) { n     if (s[i] ==  sum ) { n       int Top = top / B + 1; n       int now_cnt = 0; n       long long ans = 0; n       for (int(i) = (0); (i) <= (Top); (i)++) { n         ans += sum[i][(2 - now_cnt + 555555555) % 5]; n         now_cnt += num[i]; n       } n       cout << ans <<   n ; n     } else { n       val[i] = mp[val[i]]; n       if (s[i] ==  add ) { n         int v = val[i]; n         ex[v] = 1; n         int at = v / B; n         calc(at); n       } else { n         int v = val[i]; n         ex[v] = 0; n         int at = v / B; n         calc(at); n       } n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXn = 100 + 13; n int n, k, t[MAXn]; n int main() { n   cin >> n; n   for (int i = 0; i < n; i++) cin >> t[i]; n   cin >> k; n   sort(t, t + n); n   int i = 0, j = 0, d = 0, num = 0, ans = 0; n   while (j < n) { n     d = t[j++] - t[i]; n     while (d > k) d -= t[i++]; n     num = j - i; n     ans = max(ans, num); n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int ans[200010]; n int main() { n   int n; n   cin >> n; n   if (n & 1) { n     puts( YES ); n     bool f = true; n     for (int i = 0; i < n; i++) { n       if (f) n         ans[i + n] = (i + 1) * 2, ans[i] = (i + 1) * 2 - 1; n       else n         ans[i] = (i + 1) * 2, ans[i + n] = (i + 1) * 2 - 1; n       f = !f; n     } n     for (int i = 0; i < (n * 2); i++) { n       cout << ans[i] <<    ; n     } n   } else n     puts( NO ); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long q; n   cin >> q; n   while (q--) { n     long long a, b, m; n     cin >> a >> b >> m; n     if (a == b) { n       cout << 1 <<     << a <<   n ; n       continue; n     } n     bool ok = 0; n     long long dif = 0; n     long long p = a, i = 1ll; n     while (p <= b) { n       if (b - p <= ((1ll << (i - 1ll)) * m) && b - p >= (1ll << (i - 1ll))) { n         ok = 1; n         dif = b - p - (1ll << (i - 1ll)); n         break; n       } n       i++; n       p = (p * 2ll); n     } n     if (!ok) { n       cout << (-1) <<   n ; n       continue; n     } n     long long s1 = min(dif, m - 1); n     dif -= s1; n     cout << i + 1 <<    ; n     long long res[55]; n     res[0] = a; n     for (long long j = 1ll; j < i; j++) { n       long long sss = 0; n       for (long long u = 0; u < j; u++) sss += res[u]; n       sss += min((dif / (1ll << (i - j - 1ll))), m - 1ll); n       dif -= min((dif / (1ll << (i - j - 1ll))), m - 1ll) * n              (long long)((1ll << (i - j - 1ll))); n       sss++; n       res[j] = sss; n     } n     long long sss = 0; n     for (long long u = 0; u < i; u++) sss += res[u]; n     sss += s1; n     sss++; n     res[i] = sss; n     for (long long j = 0; j <= i; j++) cout << res[j] <<    ; n     cout <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, m, p, d[100005], sum[100005], f[105][100005], s[100005], a[100005], n     q[100005], head, tail, g[100005]; n inline long long getint() { n   long long x = 0, f = 1; n   char ch = getchar(); n   while (ch <  0  || ch >  9 ) { n     if (ch ==  - ) f = -1; n     ch = getchar(); n   } n   while (ch >=  0  && ch <=  9 ) x = x * 10 + ch -  0 , ch = getchar(); n   return x * f; n } n void work() { n   n = getint(), m = getint(), p = getint(); n   for (int i = 2; i <= n; ++i) d[i] = getint(), sum[i] = sum[i - 1] + d[i]; n   for (int i = 1; i <= m; ++i) { n     int x, y; n     x = getint(), y = getint(); n     a[i] = y - sum[x]; n   } n   sort(a + 1, a + 1 + m); n   for (int i = 1; i <= m; ++i) s[i] = s[i - 1] + a[i]; n   memset(f, 0x3f, sizeof(f)); n   f[0][0] = 0; n   for (int i = 1; i <= p; ++i) { n     for (int j = 1; j <= m; ++j) g[j] = f[i - 1][j] + s[j]; n     head = 1, tail = 1; n     q[1] = 0; n     for (int j = 1; j <= m; ++j) { n       while (head < tail && n              g[q[head + 1]] - g[q[head]] <= a[j] * (q[head + 1] - q[head])) n         ++head; n       f[i][j] = min(f[i - 1][j], g[q[head]] + a[j] * (j - q[head]) - s[j]); n       if (g[j] >= 0x3f3f3f3f3f3f3f3fll) continue; n       while (head < tail && (g[j] - g[q[tail]]) * (q[tail] - q[tail - 1]) <= n                                 (g[q[tail]] - g[q[tail - 1]]) * (j - q[tail])) n         --tail; n       q[++tail] = j; n     } n   } n   cout << f[p][m] << endl; n } n int main() { n   work(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   bool c5 = true; n   string s; n   cin >> s; n   int d = s.length(); n   for (int i = 0; i <= d; i++) { n     for (char a =  a ; a <=  z ; a++) { n       c5 = true; n       s.insert(i, 1, a); n       int d1 = s.length(); n       for (int j = 0; j < d1 / 2; j++) { n         if (s[j] != s[d1 - 1 - j]) { n           c5 = false; n         } n       } n       if (c5 == true) { n         break; n       } n       s.erase(i, 1); n     } n     if (c5 == true) { n       break; n     } n   } n   if (c5 == true) { n     cout << s << endl; n   } else n     cout <<  NA  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   int n; n   cin >> n; n   vector<pair<int, int> > j(n); n   for (int i = 0; i < n; i++) { n     cin >> j[i].first; n     j[i].second = i; n   } n   sort(j.begin(), j.end()); n   if (n == 1) n     cout <<  Exemplary pages. n ; n   else if (n == 2) { n     if (j[0].first == j[1].first) n       cout <<  Exemplary pages. n ; n     else if ((j[1].first - j[0].first) % 2 == 0) n       cout << (j[1].first - j[0].first) / 2 <<   ml. from cup #  n            << j[0].second + 1 <<   to cup #  << j[1].second + 1 <<  . n ; n     else n       cout <<  Unrecoverable configuration. n ; n   } else { n     if (j[0].first == j[n - 1].first) n       cout <<  Exemplary pages. n ; n     else if (j[1].first == j[n - 2].first && n              j[0].first + j[n - 1].first == j[1].first * 2) n       cout << (j[n - 1].first - j[0].first) / 2 <<   ml. from cup #  n            << j[0].second + 1 <<   to cup #  << j[n - 1].second + 1 <<  . n ; n     else n       cout <<  Unrecoverable configuration. 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 vas = min(n, m); n   int pet = n + m - 1 - vas; n   cout << pet <<     << vas; n } n


#include <bits/stdc++.h> n using std::cin; n using std::cout; n using std::endl; n using std::ifstream; n using std::max; n using std::min; n using std::ofstream; n using std::string; n int dp[2204][2204]; n int vec[21][2]; n int x, y, vec_num_n, max_dist_d; n int dfs(int ori_x, int ori_y, int off_x, int off_y) { n   if (dp[off_x][off_y] >= 0) { n     return dp[off_x][off_y]; n   } n   int cur_x = ori_x + off_x; n   int cur_y = ori_y + off_y; n   if (cur_x * cur_x + cur_y * cur_y > max_dist_d * max_dist_d) { n     return dp[off_x][off_y] = 0; n   } n   for (int vec_i = 0; vec_i < vec_num_n; ++vec_i) { n     int next_x = vec[vec_i][0] + off_x; n     int next_y = vec[vec_i][1] + off_y; n     if (dfs(ori_x, ori_y, next_x, next_y)) { n       return dp[off_x][off_y] = 0; n     } n   } n   return dp[off_x][off_y] = 1; n } n int main() { n   cin >> x >> y >> vec_num_n >> max_dist_d; n   for (int vec_i = 0; vec_i < vec_num_n; ++vec_i) { n     cin >> vec[vec_i][0] >> vec[vec_i][1]; n   } n   memset(dp, -1, sizeof(dp)); n   if (!dfs(x, y, 0, 0)) { n     cout <<  Anton  << endl; n   } else { n     cout <<  Dasha  << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2e5 + 10; n const int mod = 998244353; n int read() { n   int x = 0, f = 1; n   char c = getchar(); n   while (c <  0  || c >  9 ) { n     if (c ==  - ) f = -1; n     c = getchar(); n   } n   while (c >=  0  && c <=  9 ) x = (x << 1) + (x << 3) + c -  0 , c = getchar(); n   return x * f; n } n int qpow(int a, int p, int mod) { n   int res = 1; n   while (p) { n     if (p & 1) res = 1ll * res * a % mod; n     a = 1ll * a * a % mod; n     p >>= 1; n   } n   return res; n } n int inc(int x, int y, int mo) { n   if (y < 0) y += mo; n   if (x + y >= mo) x -= mo; n   return x + y; n } n const int P = 998244353, gi = 3; n const double pi = acos(-1.0); n int rev[N]; n void NTT(int *A, int n, int inv) { n   for (int i = 0; i < n; i++) n     if (i < rev[i]) swap(A[i], A[rev[i]]); n   for (int l = 1; l < n; l <<= 1) { n     int tt = qpow(gi, (P - 1) / (l << 1), P); n     int temp = (inv == 1 ? tt : qpow(tt, P - 2, P)); n     for (int i = 0; i < n; i += (l << 1)) { n       int omega = 1; n       for (int j = 0; j < l; j++, omega = 1ll * omega * temp % P) { n         int x = A[i + j], y = 1ll * omega * A[i + j + l] % P; n         A[i + j] = inc(x, y, P); n         A[i + j + l] = inc(x, -y, P); n       } n     } n   } n   int invv = qpow(n, P - 2, P); n   if (inv == -1) n     for (int i = 0; i < n; i++) A[i] = 1ll * A[i] * invv % P; n } n int NTTinit(int n, int m) { n   int ML = 1, bit = 0; n   while (ML <= n + m) ML <<= 1, bit++; n   for (int i = 0; i < ML; i++) n     rev[i] = (rev[i >> 1] >> 1) | ((i & 1) << (bit - 1)); n   return ML; n } n void NTTX(int *a, int n, int *b, int m) { n   int ML = NTTinit(n, m); n   NTT(a, ML, 1); n   NTT(b, ML, 1); n   for (int i = 0; i < ML; i++) a[i] = 1ll * a[i] * b[i] % P; n   NTT(a, ML, -1); n } n int b[N]; n void solve(int l, int r, int *res) { n   if (l == r) { n     res[0] = 1; n     res[1] = b[l]; n     return; n   } n   int mid = (l + r) >> 1; n   int n = (mid - l + 1), m = (r - mid + 1); n   int ML = NTTinit(n, m); n   int L[ML], R[ML]; n   memset(L, 0, sizeof(L)); n   memset(R, 0, sizeof(R)); n   solve(l, mid, L); n   solve(mid + 1, r, R); n   NTTX(L, n, R, m); n   for (int i = 0; i <= r - l + 1; i++) res[i] = L[i]; n } n int a[N], C[N]; n int main() { n   int n = read(), k = read(); n   for (int i = 1; i <= n; i++) a[i] = read(); n   int Q = read(); n   while (Q--) { n     int op = read(); n     memset(C, 0, sizeof(C)); n     if (op == 1) { n       int q = read(), ii = read(), d = read(); n       for (int i = 1; i <= n; i++) n         b[i] = (q - (i == ii ? d : a[i]) + mod) % mod; n     } else { n       int q = read(), l = read(), r = read(), d = read(); n       for (int i = 1; i <= n; i++) n         b[i] = (q - ((i <= r && i >= l) ? (d + a[i]) : a[i]) + mod) % mod; n     } n     solve(1, n, C); n     printf( %d n , C[k]); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long n, d, m; n   cin >> n >> d >> m; n   long long ans = 0; n   long long a[n]; n   vector<long long> big, small; n   for (long long i = 0; i < n; i++) cin >> a[i]; n   for (long long i = 0; i < n; i++) { n     if (a[i] > m) n       big.push_back(a[i]); n     else n       small.push_back(a[i]); n   } n   sort(big.rbegin(), big.rend()); n   sort(small.rbegin(), small.rend()); n   long long p = big.size(), q = small.size(); n   for (long long i = 1; i < p; i++) big[i] += big[i - 1]; n   for (long long i = 1; i < q; i++) small[i] += small[i - 1]; n   if (q > 0) ans = small[q - 1]; n   for (long long i = 0; i < p; i++) { n     if (i * (d + 1) + 1 <= n) { n       ans = max(ans, big[i]); n       long long rem = n - (i * (d + 1) + 1); n       long long ind = -1; n       if (q > 0 and rem > 0) { n         ind = max(0LL, min(rem - 1LL, q - 1)); n         ans = max(ans, big[i] + small[ind]); n       } n     } n   } n   cout << ans <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n using ld = long double; n using D = double; n using uint = unsigned int; n template <typename T> n using pair2 = pair<T, T>; n using pii = pair<int, int>; n using pli = pair<ll, int>; n using pll = pair<ll, ll>; n mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); n const int MOD = 1000000007; n inline int sum(int a, int b, int mod = MOD) { n   a += b; n   if (a >= mod) a -= mod; n   return a; n } n inline int sub(int a, int b, int mod = MOD) { n   a -= b; n   if (a < 0) a += mod; n   return a; n } n inline int mul(int a, int b, int mod = MOD) { return ((long long)a * b) % mod; } n inline int powmod(int a, int b, int mod = MOD) { n   int tmp = a; n   int ans = 1; n   while (b) { n     if (b & 1) ans = mul(ans, tmp, mod); n     tmp = mul(tmp, tmp, mod); n     b >>= 1; n   } n   return ans; n } n inline int inv(int a, int mod = MOD) { return powmod(a, mod - 2, mod); } n const int maxn = 5000006; n int sm[maxn]; n int ans[maxn]; n int t, l, r; n int main() { n   scanf( %d%d%d , &t, &l, &r); n   for (int i = 1; i < maxn; i++) sm[i] = -1; n   for (int i = 2; i < maxn; i++) { n     for (int j = i; j < maxn; j += i) n       if (sm[j] == -1) { n         sm[j] = i; n       } n   } n   ans[1] = 0; n   for (int i = 2; i < maxn; i++) { n     int d = sm[i]; n     int g = i / d; n     ans[i] = sum(ans[i / d], mul(g, ((ll)d * (d - 1) / 2) % MOD)); n   } n   int ml = 1; n   int answer = 0; n   for (int i = l; i <= r; i++) { n     answer = sum(answer, mul(ml, ans[i])); n     ml = mul(ml, t); n   } n   printf( %d n , answer); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ull = unsigned long long; n using ll = long long; n using ld = long double; n using vi = vector<ll>; n using vvi = vector<vi>; n using vb = vector<bool>; n using ii = pair<ll, ll>; n constexpr bool LOG = false; n void Log() { n   if (LOG) cerr <<   n ; n } n template <class T, class... S> n void Log(T t, S... s) { n   if (LOG) cerr << t <<   t , Log(s...); n } n ll SIZE; n vector<bool> bs; n vector<ll> primes, mf; n void sieve(ll size = 3e5) { n   SIZE = size; n   bs.assign(SIZE + 1, 1); n   bs[0] = bs[1] = 0; n   for (ll i = 2; i <= SIZE; i++) n     if (bs[i]) { n       for (ll j = i * i; j <= SIZE; j += i) bs[j] = 0; n       primes.push_back(i); n     } n } n bool is_prime(ll n) { n   if (n <= SIZE) return bs[n]; n   for (const auto &prime : primes) n     if (n % prime == 0) return false; n   return true; n } n struct Factor { n   ll p; n   ll exp; n }; n using FS = vector<Factor>; n FS factor(ll n) { n   FS fs; n   for (const auto &p : primes) { n     ll exp = 0; n     if (n == 1 || p * p > n) break; n     while (n % p == 0) n /= p, exp++; n     if (exp > 0) fs.push_back({p, exp}); n   } n   if (n != 1) fs.push_back({n, 1}); n   return fs; n } n vector<ll> divisors(const FS &fs) { n   vector<ll> ds{1}; n   ll s = 1; n   for (auto &f : fs) s *= f.exp + 1; n   ds.reserve(s); n   for (auto f : fs) n     for (auto d : ds) n       for (ll i = 0; i < f.exp; ++i) ds.push_back(d *= f.p); n   return ds; n } n ll n; n using T = ll; n struct FenwickTree { n   int n; n   vector<T> tree; n   FenwickTree(int n) : n(n) { tree.assign(n + 1, 0); } n   T query(int l, int r) { return query(r) - query(l - 1); } n   T query(int r) { n     T s = 0; n     for (; r > 0; r -= (r & (-r))) s += tree[r]; n     return s; n   } n   void update(int i, T v) { n     Log( FT update , i, v); n     for (; i <= n; i += (i & (-i))) tree[i] += v; n   } n }; n struct S { n   FenwickTree ft; n   map<ll, ll> m; n   S(ll n, vi &init) : ft(n) { n     Log( init , n); n     m[0] = 0; n     m[n] = 1e9; n     for (ll i = 0; i < n; ++i) update(i, init[i]); n     Log( done init ); n   } n   void update(ll i, ll u) { n     Log( update , i, u); n     auto it = m.lower_bound(i + 1); n     auto p = prev(it); n     if (u <= p->second) { n       Log( return; no increment ); n       return; n     } n     Log( shrink , p->first + 1,  remove , (it->first - i) * p->second); n     ft.update(p->first + 1, (i - it->first) * p->second); n     while (it->second <= u) { n       auto nxt = next(it); n       if (nxt == m.end()) break; n       ft.update(it->first + 1, -(nxt->first - it->first) * it->second); n       it = m.erase(it); n     } n     m[i] = u; n     ft.update(i + 1, (it->first - i) * u); n     Log( done update ); n     Log( Map: ); n   } n   ll query(ll i) { n     Log( query , i); n     auto it = prev(m.lower_bound(i + 1)); n     ll part = (i - it->first + 1) * it->second; n     ll c = ft.query(1, it->first); n     Log( query ans: , c, part, c + part); n     return c + part; n   } n }; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n   sieve(); n   cin >> n; n   vi v(n); n   for (auto &x : v) cin >> x; n   vi init(n); n   vi count(200001, 0); n   vi first(200001, -1); n   ll best = 0; n   for (ll i = 0; i < n; ++i) { n     ll x = v[i]; n     for (auto div : divisors(factor(x))) { n       if (first[div] < 0) first[div] = i; n       ++count[div]; n       if (count[div] >= 2) best = max(best, div); n     } n     init[i] = best; n     Log( init: , i, init[i]); n   } n   S s(n, init); n   ll ans = 0; n   ans += s.query(n - 2); n   Log(  t t t t t t0..n-2 , ans); n   s.update(0, 1); n   count.assign(200001, 0); n   best = 0; n   for (ll i = n - 1; i >= 1; --i) { n     Log( suffix from  , i); n     ll x = v[i]; n     for (auto div : divisors(factor(x))) { n       ++count[div]; n       if (count[div] >= 2) { n         best = max(best, div); n       } n       if (first[div] >= 0) s.update(first[div], div); n     } n     ans += best; n     s.update(0, best); n     Log(  t t t t t , i,  ..n-1 , best); n     if (i - 2 >= 0) { n       ll a = s.query(i - 2); n       Log(  t t t t tprefix ,  0.. , i - 2, a); n       ans += a; n     } n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n void _R(T &x) { n   cin >> x; n } n void _R(int &x) { scanf( %d , &x); } n void _R(long long &x) { scanf( %lld , &x); } n void _R(double &x) { scanf( %lf , &x); } n void _R(char &x) { scanf(  %c , &x); } n void _R(char *x) { scanf( %s , x); } n void R() {} n template <class T, class... U> n void R(T &head, U &...tail) { n   _R(head); n   R(tail...); n } n template <class T> n void _W(const T &x) { n   cout << x; n } n void _W(const int &x) { printf( %d , x); } n void _W(const long long &x) { printf( %lld , x); } n void _W(const double &x) { printf( %.16f , x); } n void _W(const char &x) { putchar(x); } n void _W(const char *x) { printf( %s , x); } n template <class T, class U> n void _W(const pair<T, U> &x) { n   _W(x.first); n   putchar(   ); n   _W(x.second); n } n template <class T> n void _W(const vector<T> &x) { n   for (auto i = x.begin(); i != x.end(); _W(*i++)) n     if (i != x.cbegin()) putchar(   ); n } n void W() {} n template <class T, class... U> n void W(const T &head, const U &...tail) { n   _W(head); n   putchar(sizeof...(tail) ?     :   n ); n   W(tail...); n } n int MOD = 1e9 + 7; n void ADD(long long &x, long long v) { n   x = (x + v) % MOD; n   if (x < 0) x += MOD; n } n const int SIZE = 1e6 + 10; n string s[SIZE]; n int row[SIZE], col[SIZE]; n int main() { n   int ___T; n   scanf( %d , &___T); n   for (int cs = 1; cs <= ___T; cs++) { n     int n, m; n     R(n, m); n     for (int i = 0; i < (n); ++i) row[i] = 0; n     for (int i = 0; i < (m); ++i) col[i] = 0; n     for (int i = 0; i < (n); ++i) { n       R(s[i]); n       for (int j = 0; j < (m); ++j) n         if (s[i][j] ==  * ) row[i]++, col[j]++; n     } n     int an = n + m; n     for (int i = 0; i < (n); ++i) n       for (int j = 0; j < (m); ++j) { n         int me = row[i] + col[j] - (s[i][j] ==  * ); n         an = min(an, n + m - 1 - me); n       } n     W(an); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long d1, d2, d3; n   cin >> d1 >> d2 >> d3; n   long long x1 = d1 + d2 + d3; n   long long x2 = d1 + d1 + d2 + d2; n   long long x3 = d1 + d1 + d3 + d3; n   long long x4 = d2 + d2 + d3 + d3; n   x1 = min(x1, min(x2, min(x3, x4))); n   cout << x1 << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 4e3 + 7; n const int mod = 1e9 + 7; n const int INF = 1e9 + 7; n const int maxl = 20; n const int SQ = 70; n int n; n int a[maxn], ps[maxn]; n int dp[maxn][SQ][SQ]; n int32_t main() { n   ios_base::sync_with_stdio(false), cin.tie(), cout.tie(); n   ; n   cin >> n; n   for (int i = 1; i <= n; i++) cin >> a[i]; n   for (int i = 1; i <= n; i++) ps[i] = ps[i - 1] + a[i]; n   for (int i = n - 1; i >= 0; i--) { n     for (int j = 0; j < SQ; j++) { n       for (int k = 1; k < SQ; k++) { n         int l = i; n         int r = n - i - j; n         if (l >= r) break; n         dp[i][j][k] = -INF; n         for (int Amove : {k, k + 1}) { n           if (r - l >= Amove) { n             int p1 = 0, p2 = 0; n             for (int Bmove : {Amove, Amove + 1}) { n               if (l + Amove <= r - Bmove) n                 p1 = dp[l + Amove][n - l - Amove - r + Bmove][Bmove] + n                      ps[l + Amove] - ps[l] - ps[r] + ps[r - Bmove]; n               else n                 p1 = +INF; n               swap(p1, p2); n             } n             dp[i][j][k] = max( n                 dp[i][j][k], n                 (min(p1, p2) == +INF ? ps[l + Amove] - ps[l] : min(p1, p2))); n           } n         } n         dp[i][j][k] = (dp[i][j][k] != -INF ? dp[i][j][k] : 0); n       } n     } n   } n   cout << dp[0][0][1] <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = (int)(1e6 + 7); n const long long oo = (long long)(1e18); n const double esp = (double)1e-6; n const long long MOD = (long long)(1e9 + 7); n int n, x, y, fre[MAXN]; n vector<int> adj[MAXN]; n void dfs(int u, int t) { n   if (u == t) return; n   fre[u] = 0; n   for (int i = 0; i < (int)adj[u].size(); i++) { n     int v = adj[u][i]; n     if (fre[v]) { n       dfs(v, t); n     } n   } n } n int main() { n   while (cin >> n >> x >> y) { n     for (int i = 1; i <= n; i++) adj[i].clear(); n     int a, b; n     for (int i = 0; i < n - 1; i++) { n       cin >> a >> b; n       adj[a].push_back(b); n       adj[b].push_back(a); n     } n     long long res = 1LL * n * (n - 1) / 2; n     for (int i = 1; i <= n; i++) fre[i] = 1; n     dfs(x, y); n     long long cnt2 = 0, cnt1 = 0; n     for (int i = 1; i <= n; i++) { n       if (fre[i]) { n         ++cnt1; n       } n       fre[i] = 1; n     } n     dfs(y, x); n     for (int i = 1; i <= n; i++) { n       if (fre[i]) { n         ++cnt2; n       } n       fre[i] = 1; n     } n     long long z = cnt2 * cnt1; n     cout << res + res - z << endl; n   } n   return 0; n } n


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


#include <bits/stdc++.h> n #pragma GCC target( avx,tune=native ) n using namespace std; n bitset<300000013> unprime; n int main() { n   if (fopen( FILENAME.in ,  r )) { n     freopen( FILENAME.in ,  r , stdin); n     freopen( FILENAME.out ,  w , stdout); n   } n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   long long l, r; n   cin >> l >> r; n   unprime[0] = 1; n   unprime[1] = 1; n   for (int i = 2; i <= r; i++) { n     if (unprime[i]) continue; n     if (i < 20000) { n       for (int j = i * i; j <= r; j += i) { n         unprime[j] = 1; n       } n     } n   } n   int answer = (l <= 2 && 2 <= r ? 1 : 0); n   int temp = l % 4; n   for (int i = l; i <= r; i++) { n     if (!unprime[i] && temp == 1) answer++; n     temp++; n     if (temp == 4) temp = 0; n   } n   cout << answer << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n int main() { n   scanf( %d , &n); n   if (n == 1) { n     puts( white ); n     cout << 1 <<     << 2 << endl; n     return 0; n   } n   if (n & 1) { n     puts( black ); n     return 0; n   } n   puts( white ); n   cout << 1 <<     << 2 << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 200005; n long long dp[N][5]; n long long DP[N]; n int head[N], nex[N * 2], to[N * 2], tot = 0; n int n, k; n long long ans = 0; n void add(int u, int v) { n   to[++tot] = v; n   nex[tot] = head[u]; n   head[u] = tot; n } n void dfs(int u, int fa, int d) { n   DP[u] = dp[u][d % k] = 1; n   for (int i = head[u]; i > 0; i = nex[i]) { n     int v = to[i]; n     if (v == fa) continue; n     dfs(v, u, d + 1); n     for (int j = 0; j < k; j++) { n       for (int l = 0; l < k; l++) { n         ans += (k - (j - d + l - d) % k) % k * dp[u][j] * dp[v][l]; n       } n     } n     for (int i = 0; i < k; i++) dp[u][i] += dp[v][i]; n     ans += ((long long)n - DP[v]) * DP[v]; n     DP[u] += DP[v]; n   } n } n int main() { n   while (~scanf( %d%d , &n, &k)) { n     memset(head, 0, sizeof(head)); n     memset(dp, 0, sizeof(dp)); n     memset(DP, 0, sizeof(DP)); n     tot = 0; n     for (int i = 1; i < n; i++) { n       int u, v; n       scanf( %d%d , &u, &v); n       add(u, v); n       add(v, u); n     } n     ans = 0; n     dfs(1, 0, 0); n     printf( %lld n , ans / k); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MOD = 998244353, MAXn = 2e5 + 2; n long long arr[MAXn]; n long long qp(long long a, long long e) { n   if (e == 0) return 1; n   if (e == 1) return a; n   if (!(e & 1)) { n     a = qp(a, e / 2); n     return a * a % MOD; n   } n   return a * qp(a, e - 1) % MOD; n } n long long r[MAXn]; n long long p[MAXn]; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long n, m, A; n   cin >> n >> m >> A; n   r[0] = p[0] = 1; n   for (int i = 1; i <= m; i++) { n     long long b; n     cin >> b; n     p[i] = (p[i - 1] + (r[i - 1] * qp(qp(A, b), MOD - 2) % MOD)) % MOD; n     r[i] = (r[i - 1] + (p[i - 1] * qp(A, b) % MOD)) % MOD; n   } n   cout << (p[m] * qp(A, n) % MOD * qp(qp(2, m), MOD - 2) % MOD); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n namespace SHENZHEBEI { n inline char gc() { return getchar(); } n inline long long read() { n   long long x = 0, f = 1; n   char ch = gc(); n   for (; !isdigit(ch); ch = gc()) n     if (ch ==  - ) f = -1; n   for (; isdigit(ch); ch = gc()) x = x * 10 - 48 + ch; n   return x * f; n } n inline void write(long long x) { n   if (x < 0) putchar( - ), x = -x; n   if (x >= 10) write(x / 10); n   putchar(x % 10 +  0 ); n } n inline char readchar() { n   char ch = gc(); n   for (; isspace(ch); ch = gc()) n     ; n   return ch; n } n inline long long readstr(char *s) { n   char ch = gc(); n   int cur = 0; n   for (; isspace(ch); ch = gc()) n     ; n   for (; !isspace(ch); ch = gc()) s[cur++] = ch; n   s[cur] =   0 ; n   return cur; n } n inline void writeln(long long x) { n   write(x); n   puts(  ); n } n inline double getreal() { n   static double lbc; n   scanf( %lf , &lbc); n   return lbc; n } n }  // namespace SHENZHEBEI n using namespace SHENZHEBEI; n const long long mod = 1e9 + 7, N = 200010; n map<long long, long long> g; n vector<long long> a[1010]; n long long ans, n, m, vis[1010], SIZE[1010]; n long long id(long long x) { n   if (g.find(x) == g.end()) { n     long long u = g.size(); n     g[x] = u; n   } n   return g[x]; n } n void gao(long long x) { n   for (; x; x >>= 1) id(x); n } n long long Size(long long x) { n   long long L = x, R = x, ans = 0; n   for (; L <= n; L = L << 1, R = R << 1 | 1) n     ans += ((n) < (R) ? (n) : (R)) - L + 1; n   return ans; n } n void dfs(long long x, long long bb) { n   vis[x] = 1; n   (ans = (ans + (bb * SIZE[x])) % mod); n   for (long long i : a[x]) n     if (!vis[i]) dfs(i, bb); n   vis[x] = 0; n } n int main() { n   n = read(), m = read(); n   for (long long i = 1; i <= m; ++i) { n     long long x = read(), y = read(); n     gao(x), gao(y); n     a[g[x]].push_back(g[y]); n     a[g[y]].push_back(g[x]); n   } n   gao(1); n   for (pair<long long, long long> I : g) { n     SIZE[I.second] = Size(I.first); n     if (g.count(I.first * 2)) SIZE[I.second] -= Size(I.first * 2); n     if (g.count(I.first * 2 + 1)) SIZE[I.second] -= Size(I.first * 2 + 1); n     if (I.first > 1) n       a[g[I.first / 2]].push_back(g[I.first]), n           a[g[I.first]].push_back(g[I.first / 2]); n   } n   for (long long i = 0; i < g.size(); ++i) dfs(i, SIZE[i]); n   writeln(ans); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long int t; n   cin >> (t); n   while (t--) { n     long long int n, k; n     cin >> n >> k; n     long long int a[n + 2]; n     memset(a, -1, sizeof a); n     bool ok = false; n     for (long long int i = 0; i < n; ++i) { n       cin >> a[i]; n       if (a[i] == k) ok = true; n     } n     if (n == 1 && ok) { n       cout <<  yes  n            <<   n ; n       continue; n     } n     if (!ok) { n       cout <<  no   n            <<   n ; n       continue; n     } n     ok = false; n     for (long long int i = 0; i < n; i++) { n       if ((a[i] >= k && a[i + 1] >= k) || (a[i] >= k && a[i + 2] >= k)) n         ok = true; n     } n     if (ok) n       cout <<  yes  n            <<   n ; n     else n       cout <<  no  n            <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 110; n const int memsize = 20000; n struct Node { n   char val; n   int kill = 0; n   Node *failed = NULL; n   Node *pre = NULL; n   vector<Node *> child; n   Node() {} n   Node(char _val, Node *_pre) : val(_val), pre(_pre) {} n   int find_char(char c) { n     int i = 0; n     for (auto it = child.begin(); it != child.end(); it++) { n       if ((*it)->val == c) break; n       i++; n     } n     return i; n   } n }; n Node mem[memsize]; n Node *root = mem; n Node *pmem = mem; n void str_insert(char *s) { n   int lenS = strlen(s); n   Node *cur = root; n   for (int i = 0; i < lenS; i++) { n     char c = s[i]; n     if (cur->find_char(c) == cur->child.size()) { n       Node *a = new (++pmem) Node(s[i], cur); n       if (i == lenS - 1) a->kill = lenS; n       (cur->child).push_back(a); n       cur = a; n     } else { n       cur = cur->child[cur->find_char(c)]; n       if (i == lenS - 1) cur->kill = lenS; n     } n   } n } n void build_fail() { n   queue<Node *> que; n   que.push(root); n   root->failed = root; n   while (!que.empty()) { n     Node *cur = que.front(); n     que.pop(); n     for (auto it = cur->child.begin(); it != cur->child.end(); it++) { n       Node *ptr = cur->failed; n       char c = (*it)->val; n       while (ptr != root && ptr->find_char(c) == ptr->child.size()) { n         ptr = ptr->failed; n       } n       (*it)->failed = ptr; n       if (ptr->find_char(c) != ptr->child.size()) { n         (*it)->failed = ptr->child[ptr->find_char(c)]; n       } n       if (cur == root) (*it)->failed = root; n       if (cur->kill == 0) cur->kill = cur->failed->kill; n       que.push(*it); n     } n   } n } n int change[N]; n int cap[N]; n void match(char *name) { n   int lenN = strlen(name); n   Node *cur = root; n   for (int i = 0; i < lenN; i++) { n     char c = name[i]; n     while (cur != root && cur->find_char(c) == cur->child.size()) { n       cur = cur->failed; n     } n     if (cur->find_char(c) != cur->child.size()) { n       cur = cur->child[cur->find_char(c)]; n     } n     change[i] = cur->kill; n   } n } n int main() { n   int n; n   scanf( %d , &n); n   char s[N]; n   while (n--) { n     scanf( %s , s); n     for (int i = 0; i < strlen(s); i++) { n       s[i] = tolower(s[i]); n     } n     str_insert(s); n   } n   build_fail(); n   char name[N]; n   scanf( %s , name); n   memset(change, 0, sizeof(change)); n   memset(cap, 0, sizeof(change)); n   for (int i = 0; i < strlen(name); i++) { n     if (name[i] == toupper(name[i])) cap[i] = 1; n     name[i] = tolower(name[i]); n   } n   char letter; n   scanf(  %c , &letter); n   match(name); n   int rc[N]; n   memset(rc, 0, sizeof(rc)); n   for (int i = 0; i < strlen(name); i++) { n     int num = change[i]; n     while (num--) { n       rc[i - num] = 1; n     } n   } n   for (int i = 0; i < strlen(name); i++) { n     if (rc[i] == 1) { n       if (name[i] == letter) { n         name[i] = (letter ==  a ) ?  b  :  a ; n       } else { n         name[i] = letter; n       } n     } n   } n   for (int i = 0; i < strlen(name); i++) { n     if (cap[i] == 1) { n       printf( %c , toupper(name[i])); n     } else { n       printf( %c , tolower(name[i])); n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s; n   cin >> s; n   int len = s.length(); n   for (int i = 0; i < len; i = i + 1) { n     if (s[i] !=  a  && s[i] !=  y  && s[i] !=  e  && s[i] !=  i  && n         s[i] !=  o  && s[i] !=  u  && s[i] !=  A  && s[i] !=  Y  && n         s[i] !=  E  && s[i] !=  I  && s[i] !=  O  && s[i] !=  U ) { n       if (s[i] >=  A  && s[i] <=  Z ) { n         s[i] = s[i] + 32; n       } n       cout <<  .  << s[i]; n     } n   } n   cout << endl; n   return 0; n } n