#include <bits/stdc++.h> n using namespace std; n using ll = long long; n template <typename T> n ostream& operator<<(ostream& os, const vector<T>& v) { n   for (T e : v) { n     os << e <<    ; n   } n   return os; n } n constexpr ll mod = 998244353; n constexpr int maxn = 502; n ll lte[maxn]; n ll dp[maxn]; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   ll n, k; n   cin >> n >> k; n   --k; n   for (int i = 1; i <= n; ++i) { n     ll total = 0; n     for (int j = 1; j <= n; ++j) { n       if (j <= i) { n         dp[j] = total + 1; n         total += dp[j]; n         total %= mod; n       } else { n         dp[j] = total; n         total += dp[j]; n         total -= dp[j - i]; n         total %= mod; n       } n     } n     lte[i] = (2 * dp[n] % mod + mod) % mod; n   } n   for (int i = n; i >= 1; --i) { n     lte[i] = (lte[i] - lte[i - 1] + mod) % mod; n   } n   ll ans = 0; n   for (int i = 1; i <= min(n, k); ++i) { n     ll d = k / i; n     for (int j = 1; j <= min(d, n); ++j) { n       ans = (ans + lte[i] * lte[j]) % mod; n     } n   } n   cout << ans * ((mod + 1) / 2) % mod << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int in[2 * 100010], s[2 * 100010]; n int n; n int main() { n   scanf( %d , &n); n   memset(in, 0, sizeof(in)); n   memset(s, 0, sizeof(s)); n   for (int i = 0; i < n; i++) { n     int xx; n     scanf( %d , &xx); n     s[i] = xx; n     in[xx] = i + 1; n   } n   int t = 0; n   for (int i = 0; i < n; i++) { n     int x, j; n     scanf( %d , &x); n     if (in[x]) n       for (j = t; j < n && s[j] != x; j++) in[s[j]] = 0; n     else { n       printf( 0  ); n       continue; n     } n     printf( %d  , j - t + 1); n     t = j + 1; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int N, M; n long long K; n int A[505][505]; n vector<int> goods, bads; n int remap[505]; n double P[505][505]; n typedef double matrix[105][105]; n void mult(matrix A, matrix B, matrix C) { n   matrix temp; n   memset(temp, 0, sizeof(temp)); n   for (int i = 0; i < 105; i++) n     for (int j = 0; j < 105; j++) n       for (int k = 0; k < 105; k++) temp[i][j] += A[i][k] * B[k][j]; n   memcpy(C, temp, sizeof(matrix)); n } n matrix Q, R; n int V[505]; n int main() { n   cin >> N >> M >> K; n   for (int i = 1; i <= N; i++) { n     int x; n     cin >> x; n     if (x || i == 1) n       bads.push_back(i); n     else n       goods.push_back(i); n   } n   for (int i = 0; i < bads.size(); i++) remap[bads[i]] = i; n   for (int i = 0; i < goods.size(); i++) remap[goods[i]] = bads.size() + i; n   for (int i = 0; i < M; i++) { n     int u, v; n     cin >> u >> v; n     u = remap[u], v = remap[v]; n     A[u][v]++; n     A[v][u]++; n   } n   for (int i = 0; i < N; i++) { n     double deg = 0; n     for (int j = 0; j < N; j++) deg += A[i][j]; n     for (int j = 0; j < N; j++) P[i][j] += A[i][j] / deg; n   } n   while (N > bads.size()) { n     N--; n     for (int i = 0; i < N; i++) P[N][i] /= (1.0 - P[N][N]); n     for (int i = 0; i < N; i++) n       for (int j = 0; j < N; j++) P[i][j] += P[i][N] * P[N][j]; n   } n   N--; n   for (int i = 1; i <= N; i++) P[0][i] /= (1.0 - P[0][0]); n   for (int i = 1; i <= N; i++) n     for (int j = 1; j <= N; j++) Q[i][j] = P[i][j] + P[i][0] * P[0][j]; n   for (int i = 1; i <= N; i++) R[i][i] = 1; n   K -= 2; n   for (int b = 0; b <= 63; b++) { n     if (K & (1LL << b)) mult(Q, R, R); n     mult(Q, Q, Q); n   } n   double total = 0; n   for (int i = 1; i <= N; i++) total += P[0][i] * R[i][N]; n   cout << total <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   long long arr[n]; n   int i; n   map<long long, int> mp; n   for (i = 0; i < n; i++) { n     int t; n     cin >> t; n     mp[t]++; n   } n   auto it = mp.begin(); n   int maxe = 0; n   while (it != mp.end()) { n     if (it->second > maxe) maxe = it->second; n     it++; n   } n   cout << n - maxe << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   int count0(0), count5(0); n   for (int i = 1; i <= n; i++) { n     int a; n     cin >> a; n     if (a == 0) count0++; n     if (a == 5) count5++; n   } n   if (count0 == 0) n     cout << -1; n   else if (count5 < 9) n     cout << 0; n   else { n     for (int i = 0; i < floor(count5 / 9); i++) { n       cout << 555555555; n     } n     for (int i = 0; i < count0; i++) cout << 0; n   } n } n


#include <bits/stdc++.h> n using namespace std; n void OUT_TST(string s, istream_iterator<string> it) { cerr << s; } n template <typename T, typename... Args> n void OUT_TST(string s, istream_iterator<string> it, T a, Args... args) { n   cerr << *it <<  =  << a <<    ; n   OUT_TST(s, ++it, args...); n } n template <class T> n void rd(T& ret) { n   ret = 0; n   bool ok = 0, u = 0; n   for (;;) { n     int c = getchar(); n     if (c >=  0  && c <=  9 ) n       ret = (ret << 3) + (ret << 1) + c -  0 , ok = 1; n     else if (c ==  - ) n       u = 1; n     else if (ok) { n       if (u) ret *= -1; n       return; n     } n   } n } n long long powmod(long long p, long long n, long long mod) { n   long long ret = 1; n   for (; n; n >>= 1) { n     if (n & 1) ret = ret * p % mod; n     p = p * p % mod; n   } n   return ret; n } n template <class T> n bool chmin(T& a, const T& b) { n   return b < a ? a = b, 1 : 0; n } n template <class T> n bool chmax(T& a, const T& b) { n   return b > a ? a = b, 1 : 0; n } n int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } n const int INF = (int)1e8; n void input(vector<vector<int>>& son, vector<int>& an, vector<int>& sz, int n) { n   int m; n   cin >> m; n   son.resize(m); n   an.resize(m, -1); n   sz.resize(m, 0); n   for (int i = 0; i < m - 1; ++i) { n     int t; n     cin >> t; n     --t; n     son[t].push_back(i + 1); n   } n   for (int i = 0; i < n; ++i) { n     int t; n     cin >> t; n     --t; n     an[t] = i; n   } n } n pair<int, int> dfs(int first, const vector<vector<int>>& son, n                    const vector<int>& idx, vector<vector<pair<int, int>>>& cost, n                    vector<int>& sz) { n   sz[first] = 1; n   if (idx[first] != -1) { n     cost[idx[first]].emplace_back(idx[first], 1); n     return {idx[first], idx[first]}; n   } n   int mi = INF, mx = -INF; n   pair<int, int> tmp; n   for (int second : son[first]) { n     tmp = dfs(second, son, idx, cost, sz); n     sz[first] += sz[second]; n     chmin(mi, tmp.first); n     chmax(mx, tmp.second); n   } n   int c = sz[first]; n   if (first == 0) --c; n   cost[mi].emplace_back(mx, c); n   return {mi, mx}; n } n int main() { n   ios_base::sync_with_stdio(false), cin.tie(nullptr); n   int n; n   cin >> n; n   vector<int> an, bn, sza, szb; n   vector<vector<int>> sa, sb; n   input(sa, an, sza, n); n   input(sb, bn, szb, n); n   vector<vector<pair<int, int>>> cost(n); n   auto tmp = dfs(0, sa, an, cost, sza); n   assert(tmp.first == 0 && tmp.second == n - 1); n   tmp = dfs(0, sb, bn, cost, szb); n   assert(tmp.first == 0 && tmp.second == n - 1); n   vector<int> dp(n + 1, 0); n   for (auto& i : cost[0]) { n     chmax(dp[i.first], i.second); n   } n   for (int i = 0; i < n - 1; ++i) { n     chmax(dp[i + 1], dp[i]); n     for (auto& j : cost[i + 1]) { n       chmax(dp[j.first], dp[i] + j.second); n     } n   } n   cout << dp[n - 1] << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<pair<char, long long int>> vp(4000005); n void ans(vector<long long int> dp, vector<long long int> star, long long int x, n          vector<pair<char, long long int>> &vp, long long int n, n          long long int &flag) { n   if (x <= 1) { n     return; n   } n   long long int starpos = upper_bound((dp).begin(), (dp).end(), x) - dp.begin(); n   x -= dp[starpos - 1]; n   if (x == 0) { n     for (long long int i = star[starpos - 1]; i < n; i++) { n       if (vp[i].first ==  * ) { n         vp[i].first =  b ; n       } n     } n   } else { n     for (long long int i = star[starpos]; i < n; i++) { n       while (i < n && vp[i].first ==  * ) { n         vp[i].first =  b ; n         i++; n       } n       break; n     } n     ans(dp, star, x, vp, n, flag); n   } n } n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long int T = 1; n   cin >> T; n   while (T--) { n     long long int n, k, x; n     cin >> n >> k >> x; n     string s; n     cin >> s; n     string b =   ; n     for (long long int i = 0; i < k; i++) { n       b +=  b ; n     } n     long long int cnt = 0; n     for (long long int i = 0; i < n; i++) { n       if (s[i] ==  * ) { n         long long int t = cnt; n         for (long long int j = cnt; j < t + k; j++) { n           vp[cnt] = { * , cnt}; n           cnt++; n         } n       } else { n         vp[cnt] = { a , cnt}; n         cnt++; n       } n     } n     s.clear(); n     s =   ; n     for (long long int i = 0; i < cnt; i++) { n       s += vp[i].first; n     } n     vector<long long int> dp; n     vector<long long int> star; n     star.push_back(-1); n     dp.push_back(1); n     long long int prev = 1; n     long long int curr = 1; n     long long int flag1 = 1; n     for (long long int i = cnt - 1; i >= 0 && flag1; i--) { n       long long int flag = 0; n       while (i >= 0 && vp[i].first ==  * ) { n         if (x < (curr + 1) * 1ll * prev) { n           dp.push_back((curr + 1) * 1ll * prev); n           star.push_back(i); n           flag1 = 0; n           break; n         } n         dp.push_back((curr + 1) * 1ll * prev); n         star.push_back(i); n         i--; n         curr++; n         flag = 1; n       } n       if (flag) { n         prev = curr * prev; n         curr = 1; n       } n     } n     long long int flag = 1; n     ans(dp, star, x, vp, cnt, flag); n     for (long long int i = 0; i < cnt; i++) { n       if (vp[i].first ==  * ) continue; n       cout << vp[i].first; n     } n     cout <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 1 << 29; n const double PI = acos(-1); n const double EPS = 1e-8; n void func(vector<pair<int, int> > &v) { n   sort((v).begin(), (v).end()); n   int start = -1; n   int end = -1; n   vector<pair<int, int> > res; n   for (int i = 0; i < (int)v.size(); ++i) { n     if (i == 0) { n       start = v[i].first; n       end = v[i].second; n     } else { n       if (v[i].first <= end) { n         (end < v[i].second ? (end = v[i].second, 1) : 0); n       } else { n         res.push_back(pair<int, int>(start, end)); n         start = v[i].first; n         end = v[i].second; n       } n     } n   } n   if (start != -1) res.push_back(pair<int, int>(start, end)); n   v = res; n } n struct P { n   int v; n   int t, a; n   P(int v, int t, int a) : v(v), t(t), a(a) {} n }; n int maxbit(int a) { n   int r = 0; n   while (a) a >>= 1, r++; n   return r - 1; n } n const int N = 200000; n bool tflag[N]; n bool yflag[N]; n int main() { n   int w, h, k; n   while (cin >> w >> h >> k) { n     for (int i = 0; i < (int)N; ++i) tflag[i] = yflag[i] = 0; n     map<int, vector<pair<int, int> > > tate, yoko; n     for (int i = 0; i < (int)k; ++i) { n       int x1, y1, x2, y2; n       scanf( %d%d%d%d , &x1, &y1, &x2, &y2); n       if (x1 == x2) { n         tate[x1].push_back(pair<int, int>(min(y1, y2), max(y1, y2))); n       } else { n         yoko[y1].push_back(pair<int, int>(min(x1, x2), max(x1, x2))); n       } n     } n     assert(tate.size() <= w - 1 && yoko.size() <= h - 1); n     vector<P> nim; n     for (__typeof((tate).begin()) it = (tate).begin(); it != (tate).end(); n          ++it) { n       if (it->first < N) tflag[it->first] = 1; n       vector<pair<int, int> > &v = it->second; n       func(v); n       int t = h; n       for (__typeof((v).begin()) jt = (v).begin(); jt != (v).end(); ++jt) { n         t -= jt->second - jt->first; n       } n       nim.push_back(P(t, 0, it->first)); n     } n     for (__typeof((yoko).begin()) it = (yoko).begin(); it != (yoko).end(); n          ++it) { n       if (it->first < N) yflag[it->first] = 1; n       vector<pair<int, int> > &v = it->second; n       func(v); n       int t = w; n       for (__typeof((v).begin()) jt = (v).begin(); jt != (v).end(); ++jt) { n         t -= jt->second - jt->first; n       } n       nim.push_back(P(t, 1, it->first)); n     } n     if ((w - 1 - tate.size()) % 2 == 1) { n       for (int i = 1; i < w; ++i) n         if (!tflag[i]) { n           nim.push_back(P(h, 0, i)); n           break; n         } n     } n     if ((h - 1 - yoko.size()) % 2 == 1) { n       for (int i = 1; i < h; ++i) n         if (!yflag[i]) { n           nim.push_back(P(w, 1, i)); n           break; n         } n     } n     int val = 0; n     for (__typeof((nim).begin()) it = (nim).begin(); it != (nim).end(); ++it) { n       val ^= it->v; n     } n     if (val) { n       puts( FIRST ); n       int mb = maxbit(val); n       int x1, y1, x2, y2; n       for (__typeof((nim).begin()) it = (nim).begin(); it != (nim).end(); n            ++it) { n         if ((it->v) >> mb & 1) { n           int num = it->v - (it->v ^ val); n           assert(num >= 1); n           if (it->t == 0) { n             x1 = x2 = it->a; n             y1 = 0; n             vector<pair<int, int> > &v = tate[it->a]; n             int low = 0, high = h; n             while (low + 1 < high) { n               int mid = (low + high) / 2; n               int sum = mid; n               for (__typeof((v).begin()) it = (v).begin(); it != (v).end(); n                    ++it) { n                 if (it->second <= mid) n                   sum -= it->second - it->first; n                 else if (it->first <= mid) n                   sum -= mid - it->first; n               } n               if (sum >= num) n                 high = mid; n               else n                 low = mid; n             } n             y2 = high; n           } else { n             y1 = y2 = it->a; n             x1 = 0; n             vector<pair<int, int> > &v = yoko[it->a]; n             int low = 0, high = w; n             while (low + 1 < high) { n               int mid = (low + high) / 2; n               int sum = mid; n               for (__typeof((v).begin()) it = (v).begin(); it != (v).end(); n                    ++it) { n                 if (it->second <= mid) n                   sum -= it->second - it->first; n                 else if (it->first <= mid) n                   sum -= mid - it->first; n               } n               if (sum >= num) n                 high = mid; n               else n                 low = mid; n             } n             x2 = high; n           } n           break; n         } n       } n       printf( %d %d %d %d n , x1, y1, x2, y2); n     } else { n       puts( SECOND ); n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int mod = 1000000007; n int main() { n   int t; n   cin >> t; n   for (int tc = 0; tc < t; tc++) { n     long long a, b, c, d; n     cin >> a >> b >> c >> d; n     int temp = 1; n     if (a % 2) { n       temp *= -1; n     } n     if (b % 2) { n       temp *= -1; n     } n     if (temp == 1) { n       cout <<  Tidak Tidak  ; n       if (b > 0 || c > 0) { n         cout <<  Ya  ; n       } else { n         cout <<  Tidak  ; n       } n       if (a > 0 || d > 0) { n         cout <<  Ya  << endl; n       } else { n         cout <<  Tidak  << endl; n       } n     } else { n       if (a > 0 || d > 0) { n         cout <<  Ya  ; n       } else { n         cout <<  Tidak  ; n       } n       if (b > 0 || c > 0) { n         cout <<  Ya  ; n       } else { n         cout <<  Tidak  ; n       } n       cout <<  Tidak Tidak  << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX = 5 * (1e5 + 5); n vector<int> e[MAX]; n vector<int> ice[MAX]; n int n, m; n int ans[MAX]; n bool vis[MAX]; n int cnt; n void dfs(int now, int pre) { n   int len = ice[now].size(); n   for (int i = 0; i <= len; i++) vis[i] = 0; n   for (int i = 0; i < len; i++) n     if (ans[ice[now][i]]) vis[ans[ice[now][i]]] = 1; n   int f = 1; n   for (int i = 0; i < len; i++) n     if (!ans[ice[now][i]]) { n       int t = ice[now][i]; n       while (vis[f]) f++; n       ans[t] = f++; n     } n   for (int i = 0; i < e[now].size(); i++) n     if (e[now][i] != pre) dfs(e[now][i], now); n } n int main() { n   cin >> n >> m; n   int mx = 0; n   for (int i = 1; i <= n; i++) { n     int u, g; n     scanf( %d , &u); n     mx = max(mx, u); n     for (int j = 1; j <= u; j++) { n       scanf( %d , &g); n       ice[i].push_back(g); n     } n   } n   for (int i = 1; i <= n - 1; i++) { n     int x, y; n     scanf( %d%d , &x, &y); n     e[x].push_back(y); n     e[y].push_back(x); n   } n   dfs(1, -1); n   if (mx) n     printf( %d n , mx); n   else n     printf( 1 n ); n   if (ans[1]) n     printf( %d , ans[1]); n   else n     printf( 1 ); n   for (int i = 2; i <= m; i++) { n     if (ans[i]) n       printf(  %d , ans[i]); n     else n       printf(  1 ); n   } n   puts(  ); n   return 0; n } n


#include <bits/stdc++.h> n int n, nxt[100005], fa[100005]; n int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); } n int main(void) { n   scanf( %d , &n); n   if (n % 2) { n     puts( -1 ); n     return 0; n   } n   for (int i = 0; i <= n; i++) fa[i] = i; n   for (int i = 0; i < (n / 2); i++) { n     int j = i + (n / 2); n     nxt[i] = i * 2, nxt[j] = i * 2 + 1; n     fa[find(i)] = find((i * 2) % n); n     fa[find(j)] = find((i * 2 + 1) % n); n   } n   for (int i = 0; i < (n / 2); i++) { n     int j = i + (n / 2); n     if (find(i) != find(j)) { n       nxt[i] ^= nxt[j] ^= nxt[i] ^= nxt[j]; n       fa[find(i)] = find(j); n     } n   } n   int x = 0; n   for (int i = 0; i <= n; i++) printf( %d  , x), x = nxt[x]; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, a; n   cin >> n >> a; n   vector<int> m(n); n   for (int i = 0; i < n; i++) cin >> m[i]; n   n--; n   a--; n   int calc = 0; n   if (m[a]) calc++; n   for (int j = 1; j <= max(n - a, a); j++) { n     if (a - j < 0) { n       if (m[a + j]) calc++; n       continue; n     } n     if (a + j > n) { n       if (m[a - j]) calc++; n       continue; n     } n     if (m[a + j] && m[a - j]) calc += 2; n   } n   cout << calc; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n int arities[100001]; n int legs[100001]; n bool markers[100001]; n list<int> graph[100001]; n void parse() { n   int a, b; n   cin >> n; n   for (int it = 0; it < (100001); it++) { n     (arities)[it] = (0); n   }; n   for (int it = 0; it < (100001); it++) { n     (markers)[it] = (false); n   }; n   for (int it = 0; it < (100001); it++) { n     (legs)[it] = (0); n   }; n   for (int i = 1; i < n; i++) { n     cin >> a >> b; n     graph[a].push_back(b); n     graph[b].push_back(a); n     arities[a]++; n     arities[b]++; n   } n } n void traverse(int i) { n   if (markers[i]) return; n   if (arities[i] >= 3) { n     legs[i]++; n     return; n   } n   markers[i] = true; n   for (list<int>::iterator it = graph[i].begin(); it != graph[i].end(); ++it) { n     traverse(*it); n   } n } n void solve() { n   for (int i = 1; i <= n; i++) { n     if (arities[i] == 1) traverse(i); n   } n   for (int i = 1; i <= n; i++) { n     if (!markers[i]) { n       int r = 0; n       for (list<int>::iterator it = graph[i].begin(); it != graph[i].end(); n            ++it) { n         if (!markers[*it] && arities[*it] - min(legs[*it], 2) > 1) r++; n       } n       if (r > 2) { n         cout <<  No ; n         return; n       } n     } n   } n   cout <<  Yes ; n } n int main() { n   ios::sync_with_stdio(false); n   std::cout.precision(11); n   parse(); n   solve(); n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char stra[110]; n char strb[110]; n int mark[110]; n int g[11000]; n int main() { n   int b, d; n   scanf( %d%d , &b, &d); n   scanf( %s , stra); n   scanf( %s , strb); n   int lena = strlen(stra); n   int lenb = strlen(strb); n   memset(mark, -1, sizeof(mark)); n   mark[0] = 0; n   int pos = 0; n   int key = 0; n   int cnt = 0; n   int num = 0; n   for (int ii = 1; ii <= 1000; ii++) { n     int sum = 0; n     for (int i = 0; i < lena; i++) { n       if (stra[i] == strb[pos]) { n         pos++; n         if (pos == lenb) { n           sum++; n           pos = 0; n         } n       } n     } n     g[ii] = sum; n     if (mark[pos] == -1) n       mark[pos] = ii; n     else { n       key = mark[pos]; n       cnt = ii - key; n       for (int ti = key + 1; ti <= ii; ti++) num += g[ti]; n       break; n     } n   } n   int ans = 0; n   if (b <= key) { n     for (int i = 1; i <= b; i++) ans += g[i]; n   } else { n     int tb = (b - key) / cnt; n     int tt = (b - key) - tb * cnt; n     for (int i = 1; i <= key; i++) ans += g[i]; n     ans += tb * num; n     for (int i = key + 1; i <= key + tt; i++) ans += g[i]; n   } n   printf( %d n , ans / d); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n unordered_map<long long, string> Map; n unordered_map<long long, string>::iterator it; n string Get(long long x) { n   string ans =   ; n   int s[13], cnt = 0; n   while (x) { n     s[++cnt] = x % 10; n     x /= 10; n   } n   for (int i = cnt; i >= 1; i--) ans += char(s[i] +  0 ); n   return ans; n } n int main() { n   long long n; n   scanf( %lld , &n); n   long long len = sqrt(n); n   for (long long i = 2; i <= len; i++) { n     for (long long j = i * i, k = 2; j <= n; j *= i, k++) { n       string gg = Get(i) +  ^  + Get(k); n       if (gg.size() >= Get(j).size()) continue; n       if (Map[j].size() == 0) { n         Map[j] = gg; n       } else if (Map[j].size() > gg.size()) n         Map[j] = gg; n     } n   } n   string ans = Get(n); n   for (it = Map.begin(); it != Map.end(); it++) { n     long long k = (*it).first; n     string gg = (*it).second; n     if (n / k >= 2) { n       gg +=  * ; n       gg += (Map.count(n / k)) ? Map[n / k] : Get(n / k); n     } n     if (n % k) { n       gg +=  + ; n       gg += (Map.count(n % k)) ? Map[n % k] : Get(n % k); n     } n     if (ans.size() > gg.size()) ans = gg; n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 1e3 + 13; n const int INF = 1e6 + 7; n int t[MAXN][MAXN]; n int tab[MAXN * MAXN]; n bool odw[MAXN * MAXN]; n int wyn[MAXN * MAXN]; n bool prze[MAXN * MAXN]; n int xx[4] = {0, 0, -1, 1}; n int yy[4] = {-1, 1, 0, 0}; n vector<int> v[MAXN * MAXN]; n int check(int x) { n   int spr = 0; n   odw[x] = true; n   prze[x] = true; n   for (auto it : v[x]) { n     if (odw[it] && prze[it]) n       spr = 1; n     else if (!odw[it]) n       spr = max(spr, check(it)); n   } n   prze[x] = false; n   return spr; n } n int DFS(int x, int gl) { n   odw[x] = true; n   for (auto it : v[x]) { n     if (odw[it]) n       wyn[x] = max(wyn[x], wyn[it]); n     else n       wyn[x] = max(wyn[x], DFS(it, gl + 1)); n   } n   wyn[x]++; n   return wyn[x]; n } n int main() { n   int n, m; n   int mx = 0; n   char c; n   scanf( %d %d , &n, &m); n   for (int i = 1; i <= n; i++) { n     scanf(   ); n     for (int j = 1; j <= m; j++) { n       scanf( %c , &c); n       if (c ==  I ) t[i][j] = 1; n       if (c ==  M ) t[i][j] = 2; n       if (c ==  A ) t[i][j] = 3; n       tab[(i - 1) * m + j] = t[i][j]; n     } n     t[i][0] = t[i][m + 1] = 5; n   } n   for (int i = 1; i <= m; i++) t[0][i] = t[n + 1][i] = 5; n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= m; j++) { n       for (int l = 0; l < 4; l++) { n         if (t[i + xx[l]][j + yy[l]] == (t[i][j] + 1) % 4) n           v[(i - 1) * m + j].push_back((i + xx[l] - 1) * m + j + yy[l]); n       } n     } n   } n   for (int i = 1; i <= n * m; i++) { n     if (!odw[i] && tab[i] == 0) { n       if (check(i) == 1) { n         printf( Poor Inna! ); n         return 0; n       } n     } n   } n   for (int i = 1; i <= n * m; i++) odw[i] = false; n   for (int i = 1; i <= n * m; i++) { n     if (!odw[i] && tab[i] == 0) mx = max(mx, DFS(i, 1) / 4); n   } n   if (mx == 0) n     printf( Poor Dima! ); n   else n     printf( %d , mx); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n string s; n pair<int, int> a[100003]; n int l = 0; n bool lios(string s) { n   if (s.size() < 4) return false; n   if (s.substr(s.size() - 4, 4) ==  lios ) return true; n   return false; n } n bool liala(string s) { n   if (s.size() < 5) return false; n   if (s.substr(s.size() - 5, 5) ==  liala ) return true; n   return false; n } n bool etr(string s) { n   if (s.size() < 3) return false; n   if (s.substr(s.size() - 3, 3) ==  etr ) return true; n   return false; n } n bool etra(string s) { n   if (s.size() < 4) return false; n   if (s.substr(s.size() - 4, 4) ==  etra ) return true; n   return false; n } n bool initis(string s) { n   if (s.size() < 6) return false; n   if (s.substr(s.size() - 6, 6) ==  initis ) return true; n   return false; n } n bool inites(string s) { n   if (s.size() < 6) return false; n   if (s.substr(s.size() - 6, 6) ==  inites ) return true; n   return false; n } n bool adj, n, v; n int main() { n   while (cin >> s) { n     a[l].first = -1, a[l].second = -1; n     if (lios(s)) { n       a[l++] = pair<int, int>{0, 0}; n       continue; n     } n     if (liala(s)) { n       a[l++] = pair<int, int>{0, 1}; n       continue; n     } n     if (etr(s)) { n       a[l++] = pair<int, int>{1, 0}; n       continue; n     } n     if (etra(s)) { n       a[l++] = pair<int, int>{1, 1}; n       continue; n     } n     if (initis(s)) { n       a[l++] = pair<int, int>{2, 0}; n       continue; n     } n     if (inites(s)) { n       a[l++] = pair<int, int>{2, 1}; n       continue; n     } n     l++; n   } n   if (l == 1 && a[0].first != -1) { n     cout <<  YES ; n     return 0; n   } n   for (int i = 0; i < l; i++) { n     if (a[i].first == -1) { n       cout <<  NO ; n       return 0; n     } n     if (i == 0) n       ; n     else { n       if (a[i].second != a[i - 1].second) { n         cout <<  NO ; n         return 0; n       } n     } n     if (a[i].first == 0) { n       if (n || v) { n         cout <<  NO ; n         return 0; n       } n       adj = 1; n       continue; n     } n     if (a[i].first == 1) { n       if (n || v) { n         cout <<  NO ; n         return 0; n       } n       n = 1; n       continue; n     } n     if (a[i].first == 2) { n       if (!n) { n         cout <<  NO ; n         return 0; n       } n       v = 1; n       continue; n     } n   } n   if (!n) n     cout <<  NO ; n   else n     cout <<  YES ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long INF = 1e15; n long long binpow(long long a, long long b) { n   long long res = 1; n   while (b > 0) { n     if (b & 1) { n       res = res * a; n     } n     a = a * a; n     b >>= 1; n   } n   return res; n } n long long dp[205][205][205]; n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long T; n   T = 1; n   while (T--) { n     long long n, k; n     string s, t; n     cin >> n >> k; n     cin >> s >> t; n     memset(dp, -1, sizeof(dp)); n     dp[0][0][0] = 0; n     long long i, j; n     for (i = 0; i < n; i++) { n       for (j = 0; j <= k; j++) { n         for (long long f0 = 0; f0 <= n; f0++) { n           if (dp[i][j][f0] == -1) { n             continue; n           } n           long long e0 = s[i] == t[0]; n           long long e1 = s[i] == t[1]; n           long long e01 = t[0] == t[1]; n           dp[i + 1][j][f0 + e0] = n               max(dp[i + 1][j][f0 + e0], dp[i][j][f0] + (e1 ? f0 : 0)); n           if (j + 1 <= k) n             dp[i + 1][j + 1][f0 + 1] = n                 max(dp[i + 1][j + 1][f0 + 1], dp[i][j][f0] + (e01 ? f0 : 0)); n           if (j + 1 <= k) n             dp[i + 1][j + 1][f0 + e01] = n                 max(dp[i + 1][j + 1][f0 + e01], dp[i][j][f0] + f0); n         } n       } n     } n     long long ans = 0; n     for (j = 0; j <= k; j++) { n       for (long long f0 = 0; f0 <= n; f0++) { n         ans = max(ans, dp[n][j][f0]); n       } n     } n     cout << ans <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int max_n = 1011, inf = 1000111222; n int n, a[max_n][max_n], x[max_n]; n int main() { n   scanf( %d , &n); n   for (int i = 0; i < n; ++i) { n     for (int j = 0; j < n; ++j) { n       scanf( %d , &a[i][j]); n     } n   } n   long long val = 1LL * a[0][1] * a[0][2] / a[1][2]; n   x[0] = sqrtl(val); n   while (1LL * x[0] * x[0] < val) { n     ++x[0]; n   } n   printf( %d  , x[0]); n   for (int i = 1; i < n; ++i) { n     printf( %d  , a[0][i] / x[0]); n   } n   puts(  ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int di[] = {-1, 0, 1, 0}; n const int dj[] = {0, 1, 0, -1}; n const long long MOD = 1e9 + 7; n const long long INF = 1e9; n const double EPS = 1e-11; n int main() { n   ios::sync_with_stdio(false), cin.tie(0); n   int n, q, c; n   cin >> n >> q >> c; n   vector<pair<int, int> > pos(n); n   vector<int> s(n); n   vector<vector<vector<int> > > cnt( n       101, vector<vector<int> >(101, vector<int>(c + 1))); n   for (int i = 0; i < n; ++i) { n     cin >> pos[i].first >> pos[i].second >> s[i]; n     cnt[pos[i].first][pos[i].second][s[i]]++; n   } n   for (int i = 0; i < 101; ++i) { n     for (int j = 0; j < 101; ++j) { n       for (int k = 0; k < c + 1; ++k) { n         if (i > 0) cnt[i][j][k] += cnt[i - 1][j][k]; n         if (j > 0) cnt[i][j][k] += cnt[i][j - 1][k]; n         if (i > 0 && j > 0) cnt[i][j][k] -= cnt[i - 1][j - 1][k]; n       } n     } n   } n   while (q--) { n     int t, x1, y1, x2, y2; n     cin >> t >> x1 >> y1 >> x2 >> y2; n     vector<vector<int> > cum(4, vector<int>(11)); n     cum[0] = cnt[x2][y2]; n     cum[1] = cnt[x2][y1 - 1]; n     cum[2] = cnt[x1 - 1][y1 - 1]; n     cum[3] = cnt[x1 - 1][y2]; n     vector<int> cur(11), cur2(11); n     for (int i = 0; i < c + 1; ++i) n       cur[i] = cum[0][i] - cum[1][i] - cum[3][i] + cum[2][i]; n     for (int i = 0; i < c + 1; ++i) cur2[(i + t) % (c + 1)] = cur[i]; n     int r = 0; n     for (int i = 0; i < c + 1; ++i) r += i * cur2[i]; n     cout << r << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int t[200005], revt[200005]; n int main() { n   ios::sync_with_stdio(0); n   int n; n   cin >> n; n   for (int i = 1; i <= n; i++) { n     cin >> t[i]; n     revt[t[i]]++; n   } n   int ans = 1; n   for (int i = 0; i <= n; i++) ans += max(0, revt[i] - 1); n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e5 + 10; n int l[maxn]; n int r[maxn]; n int mx[maxn]; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   int n; n   cin >> n; n   long long ans = n; n   for (int i = 1; i <= n; i++) { n     cin >> l[i] >> r[i]; n   } n   sort(l + 1, l + 1 + n); n   sort(r + 1, r + 1 + n); n   for (int i = 1; i <= n; i++) ans += max(r[i], l[i]); n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n bool vowel(char a) { n   a = toupper(a); n   if ((a ==  A ) || (a ==  E ) || (a ==  I ) || (a ==  O ) || (a ==  U )) n     return 1; n   return 0; n } n long long int n, m, q, a, b, c, sum = 0, cnt = 0; n long long int arr[2000005]; n map<long long int, bool> mp; n string s; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> arr[i]; n     arr[i]--; n   } n   cin >> s; n   long long int mn = 20000051, mx = 0; n   for (int i = 0; i < n; i++) { n     if (s[i] ==  0 ) { n       if (arr[i] != i) { n         cout <<  NO  << endl; n         return 0; n       } n     } else if (s[i] ==  1 ) { n       mn = 20000051, mx = 0; n       int st = i; n       mn = min(arr[i], mn); n       mx = max(arr[i], mx); n       while (i < n && s[i] ==  1 ) { n         mn = min(arr[i + 1], mn); n         mx = max(arr[i + 1], mx); n         i++; n       } n       if (mn != st || mx != i) { n         cout <<  NO  << endl; n         return 0; n       } n       arr[i] = mx; n     } n   } n   cout <<  YES  << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string a[6], b[6], c[6]; n   a[0] =  purple ; n   b[0] =  Power ; n   a[1] =  green ; n   b[1] =  Time ; n   a[2] =  blue ; n   b[2] =  Space ; n   a[3] =  orange ; n   b[3] =  Soul ; n   a[4] =  red ; n   b[4] =  Reality ; n   a[5] =  yellow ; n   b[5] =  Mind ; n   int n, i, j, k = 0, flag = 0; n   int arr[6]; n   cin >> n; n   for (i = 0; i < n; i++) cin >> c[i]; n   for (i = 0; i < n; i++) { n     for (j = 0; j < 6; j++) { n       if (c[i] == a[j]) { n         arr[k] = j; n         k++; n       } n     } n   } n   cout << 6 - n << endl; n   for (i = 0; i < 6; i++) { n     flag = 0; n     for (k = 0; k < n; k++) n       if (i == arr[k]) flag = 1; n     if (flag == 0) cout << b[i] << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   long long int cur = 1; n   long long num = 1; n   while (cur != n + 1) { n     if (cur != 1) n       cout << cur * 1ll * cur * 1ll * cur + 2 * cur * cur + 1; n     else n       cout << 2; n     cout << endl; n     cur++; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, m, cnt[100005], root, par[100005], br[100005], st[100005], brcnt; n vector<long long> a[100005]; n pair<long long, long long> vert[100005]; n map<pair<long long, long long>, long long> mm; n set<long long> brcl; n long long tmp = 1; n void dfs(long long v) { n   if (a[v].size() > 0) n     for (long long i = 0; i <= a[v].size() - 1; ++i) { n       if (v == root) { n         brcnt++; n         st[brcnt] = tmp; n       } n       if (a[v][i] != par[v]) { n         br[a[v][i]] = brcnt; n         mm[make_pair(v, a[v][i])] = tmp++; n         par[a[v][i]] = v; n         dfs(a[v][i]); n       } n     } n } n inline long long finddist(long long req1, long long req2) { n   if (brcl.empty()) return req2 - req1 + 1; n   set<long long>::iterator curr = (brcl.lower_bound(req2)); n   if (*curr == req2) return -1; n   if (curr == brcl.begin()) return req2 - req1 + 1; n   curr--; n   if (*curr >= req1 && *curr <= req2) n     return -1; n   else n     return req2 - req1 + 1; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cin >> n; n   for (long long i = 1; i <= n - 1; ++i) { n     long long u, v; n     cin >> u >> v; n     cnt[u]++; n     cnt[v]++; n     if (cnt[u] > 2) n       root = u; n     else if (cnt[v] > 2) n       root = v; n     a[u].push_back(v); n     a[v].push_back(u); n     vert[i] = make_pair(u, v); n   } n   if (root == 0) root = 1; n   par[root] = 0; n   dfs(root); n   for (long long i = 1; i <= n - 1; ++i) n     if (vert[i].second == par[vert[i].first]) n       swap(vert[i].first, vert[i].second); n   cin >> m; n   for (long long loop = 1; loop <= m; ++loop) { n     long long ty, id; n     cin >> ty >> id; n     if (ty == 1) { n       long long edge = mm[vert[id]]; n       set<long long>::iterator it = brcl.find(edge); n       brcl.erase(it); n     } else if (ty == 2) { n       long long edge = mm[vert[id]]; n       brcl.insert(edge); n     } else { n       long long en; n       cin >> en; n       if (en == id) { n         cout << 0 << endl; n         continue; n       } n       if (en == root) swap(en, id); n       if (id == root) { n         long long req1 = st[br[en]], req2 = mm[make_pair(par[en], en)]; n         cout << finddist(req1, req2) << endl; n       } else if (br[id] == br[en]) { n         if (mm[make_pair(par[en], en)] < mm[make_pair(par[id], id)]) n           swap(id, en); n         long long v; n         for (long long i = 0; i <= a[id].size() - 1; ++i) n           if (a[id][i] != par[id]) v = a[id][i]; n         long long req1 = mm[make_pair(id, v)], n                   req2 = mm[make_pair(par[en], en)]; n         cout << finddist(req1, req2) << endl; n       } else { n         long long req1 = st[br[en]], req2 = mm[make_pair(par[en], en)]; n         long long dist = finddist(req1, req2); n         req1 = st[br[id]], req2 = mm[make_pair(par[id], id)]; n         cout << ((dist == -1 || finddist(req1, req2) == -1) n                      ? -1 n                      : (finddist(req1, req2) + dist)) n              << endl; n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   vector<int> A(n + 10, 0); n   for (int i = 0; i < n; i++) cin >> A[i]; n   unordered_map<long long, int> fir, sec; n   fir[A[0]] = 1; n   for (int i = 1; i < n; i++) sec[A[i]]++; n   long long S = 0; n   for (int i = 0; i < n; i++) S += A[i]; n   long long sdash = 0; n   if (S & 1) { n     cout <<  NO  << endl; n     return 0; n   } n   for (int i = 0; i < n; i++) { n     sdash += A[i]; n     if (sdash == S / 2) { n       cout <<  YES ; n       return 0; n     } n     if (sdash < S / 2) { n       long long x = S / 2 - sdash; n       if (sec[x] > 0) { n         cout <<  YES ; n         return 0; n       } n     } else { n       long long y = sdash - S / 2; n       if (fir[y] > 0) { n         cout <<  YES ; n         return 0; n       } n     } n     fir[A[i + 1]]++; n     sec[A[i + 1]]--; n   } n   cout <<  NO ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, a, b, k; n long long q; n long long param = 0; n string ciag; n long long MOD = 1000000009; n long long potega(long long a_1, long long n_1) { n   if (n_1 == 0) return 1; n   if (n_1 == 1) n     return a_1; n   else if (n_1 % 2 == 0) { n     long long s = potega(a_1, n_1 / 2); n     return (s * s) % MOD; n   } else { n     return (potega(a_1, n_1 - 1) * a_1) % MOD; n   } n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cin >> n >> a >> b >> k; n   cin >> ciag; n   q = (potega(b, k) * potega(a, MOD - 1 - k)) % MOD; n   if (q < 0) { n     q %= MOD; n     q += MOD; n     q %= MOD; n   } n   long long krotnosc = ((n + 1) / k); n   if (q != 1) { n     for (int i = 0; i < (k); ++i) { n       if (ciag[i] ==  - ) { n         long long a_1 = (potega(a, n - i) * potega(b, i)) % MOD; n         if (a_1 < 0) { n           a_1 %= MOD; n           a_1 += MOD; n           a_1 %= MOD; n         } n         long long temp_ = n             (((a_1 * ((potega(q, krotnosc) - 1 + MOD) % MOD) % MOD)) * n              (potega(q - 1, MOD - 2))) % n             MOD; n         if (temp_ < 0) { n           temp_ %= MOD; n           temp_ += MOD; n           temp_ %= MOD; n         } n         param = ((param - temp_) % MOD + MOD) % MOD; n         if (param < 0) { n           param %= MOD; n           param += MOD; n           param %= MOD; n         } n       } else { n         long long a_1 = (potega(a, n - i) * potega(b, i)) % MOD; n         if (a_1 < 0) { n           a_1 %= MOD; n           a_1 += MOD; n           a_1 %= MOD; n         } n         long long temp_ = n             (((a_1 * ((potega(q, krotnosc) - 1 + MOD) % MOD) % MOD)) * n              (potega(q - 1, MOD - 2))) % n             MOD; n         if (temp_ < 0) { n           temp_ %= MOD; n           temp_ += MOD; n           temp_ %= MOD; n         } n         param = (param + temp_) % MOD; n         if (param < 0) { n           param %= MOD; n           param += MOD; n           param %= MOD; n         } n       } n     } n   } else { n     for (int i = 0; i < (k); ++i) { n       if (ciag[i] ==  - ) { n         long long a_1 = (potega(a, n - i) * potega(b, i)) % MOD; n         if (a_1 < 0) { n           a_1 %= MOD; n           a_1 += MOD; n           a_1 %= MOD; n         } n         long long temp_ = (a_1 * krotnosc) % MOD; n         if (temp_ < 0) { n           temp_ %= MOD; n           temp_ += MOD; n           temp_ %= MOD; n         } n         param = ((param - temp_) % MOD + MOD) % MOD; n         if (param < 0) { n           param %= MOD; n           param += MOD; n           param %= MOD; n         } n       } else { n         long long a_1 = (potega(a, n - i) * potega(b, i)) % MOD; n         if (a_1 < 0) { n           a_1 %= MOD; n           a_1 += MOD; n           a_1 %= MOD; n         } n         long long temp_ = (a_1 * krotnosc) % MOD; n         if (temp_ < 0) { n           temp_ %= MOD; n           temp_ += MOD; n           temp_ %= MOD; n         } n         param = (param + temp_) % MOD; n         if (param < 0) { n           param %= MOD; n           param += MOD; n           param %= MOD; n         } n       } n     } n   } n   cout << (param + MOD) % MOD <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long double dist(long double x, long double y, long double a, long double b) { n   return sqrt((a - x) * (a - x) + (y - b) * (y - b)); n } n long double distMan(long double x, long double y, long double a, n                     long double b) { n   return abs(x - a) + abs(y - b); n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long tt = 1; n   while (tt--) { n     long double a, b, c; n     cin >> a >> b >> c; n     long double x1, y1, x2, y2; n     cin >> x1 >> y1 >> x2 >> y2; n     if (a == 0 || b == 0) { n       cout <<     << fixed << setprecision(20) <<     n            << abs(x1 - x2) + abs(y1 - y2) <<   n ; n     } else { n       long double ans = abs(x2 - x1) + abs(y2 - y1); n       long double x3, y3, x4, y4; n       x3 = x1, x4 = x2; n       y3 = (-a * x3 - c) / b, y4 = (-a * x4 - c) / b; n       ans = min(ans, distMan(x1, y1, x3, y3) + distMan(x2, y2, x4, y4) + n                          dist(x4, y4, x3, y3)); n       x3 = x1, y4 = y2; n       y3 = (-a * x3 - c) / b, x4 = (-b * y4 - c) / a; n       ans = min(ans, distMan(x1, y1, x3, y3) + distMan(x2, y2, x4, y4) + n                          dist(x4, y4, x3, y3)); n       y3 = y1, x4 = x2; n       x3 = (-b * y3 - c) / a, y4 = (-a * x4 - c) / b; n       ans = min(ans, distMan(x1, y1, x3, y3) + distMan(x2, y2, x4, y4) + n                          dist(x4, y4, x3, y3)); n       y3 = y1, y4 = y2; n       x3 = (-b * y3 - c) / a, x4 = (-b * y4 - c) / a; n       ans = min(ans, distMan(x1, y1, x3, y3) + distMan(x2, y2, x4, y4) + n                          dist(x4, y4, x3, y3)); n       cout <<     << fixed << setprecision(20) <<     << ans <<   n ; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int mod = 1e9 + 7; n long long fp(long long x, long long y) { n   long long res = 1; n   while (y) res = (y & 1) ? res * x % mod : res, x = x * x % mod, y >>= 1; n   return res; n } n int t; n int n, m, rb, cb, rd, cd, lx = 1, ly = 1; n long long p; n void dfs(int x, int y, int dx, int dy, vector<long long>& v) { n   int nx = x + dx, ny = y + dy; n   if (nx > n || nx < 1) dx = -dx; n   if (ny > m || ny < 1) dy = -dy; n   if ((x == rb && y == cb && v.size() != 0 && dx == lx && dy == ly)) return; n   if (x == rd || y == cd) n     v.push_back(p); n   else n     v.push_back(1); n   nx = x + dx, ny = y + dy; n   dfs(nx, ny, dx, dy, v); n } n int main() { n   scanf( %d , &t); n   while (t--) { n     scanf( %d%d%d%d%d%d%lld , &n, &m, &rb, &cb, &rd, &cd, &p); n     vector<long long> v; n     long long fz = 1; n     long long ny = fp(100, mod - 2), xx = 1; n     p = (100ll - p) * ny % mod; n     lx = 1, ly = 1; n     int nx = rb + lx, nn = cb + ly; n     if (nx > n || nx < 1) lx = -lx; n     if (nn > m || nn < 1) ly = -ly; n     dfs(rb, cb, lx, ly, v); n     for (int i = 0; i < (int)v.size(); i++) { n       fz = (fz * v[i]) % mod; n     } n     long long val = 0; n     for (int i = 0; i < (int)v.size(); i++) { n       xx = (v[i] * xx) % mod; n       val += xx; n       val %= mod; n     } n     fz = (1 - fz + mod) % mod; n     val = (val * fp(fz, mod - 2)) % mod; n     printf( %lld n , val); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX = 5005; n int n, T; n int pp[MAX]; n int t[MAX]; n double p[MAX]; n double ps[MAX]; n double pl[MAX]; n double dp[2][MAX]; n int main(void) { n   scanf( %d%d , &n, &T); n   for (int i = (0); i < (n); ++i) scanf( %d%d , pp + i, t + i); n   for (int i = (0); i < (n); ++i) { n     p[i] = 0.01 * pp[i]; n     double cp = 0.0; n     double lp = p[i]; n     for (int j = (0); j < (t[i] - 1); ++j) { n       cp *= (1.0 - p[i]); n       cp += p[i]; n     } n     for (int j = (0); j < (t[i] - 2); ++j) lp *= (1.0 - p[i]); n     ps[i] = 1.0 - cp; n     pl[i] = lp; n   } n   for (int i = n - 1; i >= 0; --i) { n     int I = i % 2; n     dp[I][0] = 0.0; n     for (int tt = 1; tt <= T; ++tt) { n       dp[I][tt] = dp[I][tt - 1]; n       if (t[i] == 1) { n         dp[I][tt] = 1.0 + dp[I ^ 1][tt - 1]; n       } else { n         if (tt - t[i] - 1 >= 0) n           dp[I][tt] -= ps[i] * (1 + dp[I ^ 1][tt - t[i] - 1]); n         if (tt - t[i] >= 0) dp[I][tt] -= pl[i] * (1.0 + dp[I ^ 1][tt - t[i]]); n         dp[I][tt] *= (1.0 - p[i]); n         dp[I][tt] += p[i] * (1.0 + dp[I ^ 1][tt - 1]); n         if (tt - t[i] >= 0) dp[I][tt] += ps[i] * (1.0 + dp[I ^ 1][tt - t[i]]); n       } n     } n   } n   printf( %.10lf n , dp[0][T]); 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   long long int n; n   cin >> n; n   ; n   long long int a[n]; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n   } n   sort(a, a + n); n   long long int dp[n]; n   memset(dp, 0, sizeof(dp)); n   long long int ans = 0; n   int c1 = 0; n   int f = 0; n   while (f == 0) { n     f = 1; n     for (int i = 0; i < n; i++) { n       if (dp[i] == 0 && a[i] >= c1) { n         dp[i] = 1; n         c1++; n       } n     } n     if (c1 > 0) { n       ans++; n       f = 0; n     } n     c1 = 0; n   } n   cout << ans; n   cout <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int x, t, a, b, da, db; n   cin >> x >> t >> a >> b >> da >> db; n   if (x == 0) { n     cout <<  YES  << endl; n     return 0; n   } n   for (int i = 0; i < t; i++) { n     if (a - da * i == x) { n       cout <<  YES  << endl; n       return 0; n     } n     if (b - db * i == x) { n       cout <<  YES  << endl; n       return 0; n     } n   } n   for (int i = 0; i < t; i++) { n     for (int j = 0; j < t; j++) { n       if (a - da * i + b - db * j == x) { n         cout <<  YES  << endl; n         return 0; n       } n     } n   } n   cout <<  NO  << endl; n } n


#include <bits/stdc++.h> n using namespace std; n void FAST() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n } n int gcd(int x, int y) { n   if (x == 0) return y; n   return gcd(y % x, x); n } n int powM(int x, int y, int m) { n   int ans = 1, r = 1; n   x %= m; n   while (r > 0 && r <= y) { n     if (r & y) { n       ans *= x; n       ans %= m; n     } n     r <<= 1; n     x *= x; n     x %= m; n   } n   return ans; n } n map<long long, long long> factorize(long long n) { n   map<long long, long long> ans; n   for (long long i = 2; i * i <= n; i++) { n     while (n % i == 0) { n       ans[i]++; n       n /= i; n     } n   } n   if (n > 1) { n     ans[n]++; n     n = 1; n   } n   return ans; n } n const double pi = 3.14159265; n int main() { n   FAST(); n   int n; n   cin >> n; n   string s; n   cin >> s; n   int o = 0, c = 0; n   for (auto x : s) { n     if (x ==  ( ) n       o++; n     else n       c++; n   } n   if (o != c) n     cout << -1; n   else { n     int depth = 0, last = -1, ans = 0; n     for (int i = 0; i < n; i++) { n       if (s[i] ==  ( ) { n         depth++; n       } else { n         depth--; n       } n       if (depth == 0 && s[i] ==  ( ) { n         ans += (i - last); n         last = i; n       } n       if (depth == 0) last = i; n     } n     cout << ans; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using LL = long long int; n struct point { n   LL x, y; n   point(LL x_ = 0, LL y_ = 0) : x(x_), y(y_) {} n   point operator-(const point& b) { return point(x - b.x, y - b.y); } n   point operator+(const point& b) { return point(x + b.x, y + b.y); } n }; n LL cross_abs(const point& a, const point& b) { n   return abs(a.x * b.y - b.x * a.y); n } n bool mult(const point& sp, const point& ep, const point& op) { n   return (sp.x - op.x) * (ep.y - op.y) >= (ep.x - op.x) * (sp.y - op.y); n } n bool operator<(const point& l, const point& r) { n   return (l.y < r.y) || (l.y == r.y && l.x < r.x); n } n int graham(point pnt[], int n, point res[]) { n   int i = 0, len = 0, k = 0, top = 1; n   sort(pnt, pnt + n); n   if (n == 0) return 0; n   res[0] = pnt[0]; n   if (n == 1) return 1; n   res[1] = pnt[1]; n   if (n == 2) return 2; n   res[2] = pnt[2]; n   for (i = 2; i < n; i++) { n     while (top && mult(pnt[i], res[top], res[top - 1])) top--; n     res[++top] = pnt[i]; n   } n   len = top; n   res[++top] = pnt[n - 2]; n   for (i = n - 3; i >= 0; i--) { n     while (top != len && mult(pnt[i], res[top], res[top - 1])) top--; n     res[++top] = pnt[i]; n   } n   return top; n } n int n = 0; n LL ss = 0; n const int maxn = 5e3 + 5; n point p[maxn], cp[maxn]; n LL maxs = 0; n int ansa = 0, ansb = 0, ansc = 0; n int main(void) { n   scanf( %d %lld , &n, &ss); n   for (int i = 0; i < n; ++i) scanf( %lld %lld , &p[i].x, &p[i].y); n   int cnt = graham(p, n, cp); n   for (int i = 0; i < cnt; ++i) { n     for (int j = i + 1, k = (j + 1) % cnt; j < cnt && k != i; ++j) { n       while (cross_abs(cp[i] - cp[k], cp[j] - cp[k]) < n              cross_abs(cp[i] - cp[(k + 1) % cnt], cp[j] - cp[(k + 1) % cnt])) n         k = (k + 1) % cnt; n       if (k == i || k == j) continue; n       LL s = cross_abs(cp[i] - cp[k], cp[j] - cp[k]); n       if (s > maxs) { n         maxs = s; n         ansa = i, ansb = j, ansc = k; n       } n     } n   } n   point a = cp[ansa] - cp[ansb] + cp[ansc]; n   point b = cp[ansa] + cp[ansb] - cp[ansc]; n   point c = cp[ansb] + cp[ansc] - cp[ansa]; n   printf( %lld %lld n , a.x, a.y); n   printf( %lld %lld n , b.x, b.y); n   printf( %lld %lld n , c.x, c.y); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } n void solve() { n   int n; n   cin >> n; n   vector<long long> a(n); n   for (int i = 0; i < n; i++) cin >> a[i]; n   if (n == 1) { n     cout <<  1 n ; n     return; n   } n   vector<long long> difs(n - 1); n   for (int i = 0; i < n - 1; i++) difs[i] = abs(a[i + 1] - a[i]); n   vector<long long> cj(n); n   vector<long long> fj(n); n   cj[n - 1] = 0; n   fj[n - 1] = 1; n   long long res = 0; n   for (int i = n - 2; i >= 0; i--) { n     if (gcd(difs[i], fj[i + 1]) > 1) { n       cj[i] = cj[i + 1] + 1; n       fj[i] = gcd(difs[i], fj[i + 1]); n     } else { n       cj[i] = int(difs[i] > 1ll); n       fj[i] = difs[i]; n       for (int k = 1; k < cj[i + 1]; k++) { n         if (gcd(fj[i], difs[i + k]) > 1) { n           cj[i]++; n           fj[i] = gcd(fj[i], difs[i + k]); n         } else n           break; n       } n     } n     res = max(res, cj[i]); n   } n   cout << res + 1 <<   n ; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int tst; n   cin >> tst; n   while (tst--) solve(); n   return 0; n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /stack:247474112 ) n #pragma GCC optimize( Ofast ) n using namespace std; n const long long maxn = 2e5 + 10; n long long mx[maxn], val[maxn], sum[maxn]; n vector<long long> g[maxn]; n long long pass[maxn]; n bool ok = 0; n long long ans = LLONG_MIN; n void dfs(long long aa = 1, long long aaa = 0) { n   vector<long long> v; n   sum[aa] = val[aa]; n   for (long long a : g[aa]) { n     if (a == aaa) continue; n     dfs(a, aa); n     sum[aa] += sum[a]; n     v.push_back(pass[a]); n   } n   if (!v.empty()) { n     sort(v.begin(), v.end()); n     pass[aa] = max(v.back(), sum[aa]); n     if (v.size() >= 2) { n       ans = max(ans, v[v.size() - 1] + v[v.size() - 2]); n     } n   } else { n     pass[aa] = sum[aa]; n   } n } n int32_t main() { n   ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); n   long long n; n   cin >> n; n   for (long long i = 1; i <= n; ++i) cin >> val[i]; n   for (long long i = 1; i <= n; ++i) mx[i] = LLONG_MIN; n   for (long long i = 1; i < n; ++i) { n     long long u, v; n     cin >> u >> v; n     g[u].push_back(v); n     g[v].push_back(u); n   } n   for (long long i = 1; i <= n; ++i) pass[i] = LLONG_MIN; n   dfs(1); n   if (ans == LLONG_MIN) n     cout <<  Impossible ; n   else n     cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long second; n long long a1[1231], a2[2131]; n long long b[1231]; n long long sum[1231]; n int main() { n   int n; n   cin >> n; n   for (int i = 2; i <= n; i++) cin >> a1[i]; n   for (int i = 1; i <= n - 1; i++) cin >> a2[i]; n   for (int i = 1; i <= n; i++) { n     cin >> b[i]; n     second += a1[i]; n     sum[i] = b[i] + second; n   } n   second = 0; n   for (int i = n; i >= 1; i--) { n     second += a2[i]; n     sum[i] += second; n   } n   sort(sum, sum + n + 1); n   cout << sum[1] + sum[2]; n } n


#include <bits/stdc++.h> n using namespace std; n long long inf; n const double eps = 1e-8; n const double pi = acos(-1.0); n template <class T> n long long chkmin(T &a, T b) { n   return a > b ? a = b, 1 : 0; n } n template <class T> n long long chkmax(T &a, T b) { n   return a < b ? a = b, 1 : 0; n } n template <class T> n T sqr(T a) { n   return a * a; n } n template <class T> n T mmin(T a, T b) { n   return a < b ? a : b; n } n template <class T> n T mmax(T a, T b) { n   return a > b ? a : b; n } n template <class T> n T aabs(T a) { n   return a < 0 ? -a : a; n } n template <class T> n long long dcmp(T a, T b) { n   return a > b; n } n template <long long *a> n long long cmp_a(long long first, long long second) { n   return a[first] < a[second]; n } n struct __INIT__ { n   __INIT__() { memset(&inf, 0x3f, sizeof(inf)); } n } __INIT___; n namespace io { n const long long SIZE = (1 << 21) + 1; n char ibuf[SIZE], *iS, *iT, obuf[SIZE], *oS = obuf, *oT = oS + SIZE - 1, c, n                                        qu[55]; n long long f, qr; n inline void flush() { n   fwrite(obuf, 1, oS - obuf, stdout); n   oS = obuf; n } n inline void putc(char first) { n   *oS++ = first; n   if (oS == oT) flush(); n } n template <typename A> n inline bool read(A &first) { n   for (f = 1, c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin), n                               (iS == iT ? EOF : *iS++)) n                             : *iS++); n        c <  0  || c >  9 ; n        c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin), n                        (iS == iT ? EOF : *iS++)) n                      : *iS++)) n     if (c ==  - ) n       f = -1; n     else if (c == EOF) n       return 0; n   for (first = 0; c <=  9  && c >=  0 ; n        c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin), n                        (iS == iT ? EOF : *iS++)) n                      : *iS++)) n     first = first * 10 + (c & 15); n   first *= f; n   return 1; n } n inline bool read(char &first) { n   while ((first = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin), n                                (iS == iT ? EOF : *iS++)) n                             : *iS++)) ==     || n          first ==   n  || first ==   r ) n     ; n   return first != EOF; n } n inline bool read(char *first) { n   while ((*first = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin), n                                 (iS == iT ? EOF : *iS++)) n                              : *iS++)) ==   n  || n          *first ==     || *first ==   r ) n     ; n   if (*first == EOF) return 0; n   while (!(*first ==   n  || *first ==     || *first ==   r )) n     *(++first) = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin), n                               (iS == iT ? EOF : *iS++)) n                            : *iS++); n   *first = 0; n   return 1; n } n template <typename A, typename... B> n inline bool read(A &first, B &...second) { n   return read(first) && read(second...); n } n template <typename A> n inline bool write(A first) { n   if (!first) putc( 0 ); n   if (first < 0) putc( - ), first = -first; n   while (first) qu[++qr] = first % 10 +  0 , first /= 10; n   while (qr) putc(qu[qr--]); n   return 0; n } n inline bool write(char first) { n   putc(first); n   return 0; n } n inline bool write(const char *first) { n   while (*first) { n     putc(*first); n     ++first; n   } n   return 0; n } n inline bool write(char *first) { n   while (*first) { n     putc(*first); n     ++first; n   } n   return 0; n } n template <typename A, typename... B> n inline bool write(A first, B... second) { n   return write(first) || write(second...); n } n struct Flusher_ { n   ~Flusher_() { flush(); } n } io_flusher_; n }  // namespace io n using io ::putc; n using io ::read; n using io ::write; n long long a[100005], b[100005], f[100005], g[100005]; n long long s[100005], t; n long long n, k; n struct smt { n   long long amn, bmn, atg; n   long long ls, rs; n   smt *l, *r; n   smt(long long la, long long ra) { n     amn = inf; n     bmn = -inf; n     atg = 0; n     ls = la; n     rs = ra; n     if (ls == rs) { n       l = r = 0; n     } else { n       long long mid = (ls + rs) >> 1; n       l = new smt(ls, mid); n       r = new smt(mid + 1, rs); n     } n   } n   void setg(long long first) { n     if (ls == rs) { n       amn = bmn = g[first]; n       return; n     } n     if (first <= l->rs) n       l->setg(first); n     else n       r->setg(first); n     amn = mmin(l->amn, r->amn); n     bmn = mmin(l->bmn, r->bmn); n   } n   void push_down() { n     l->atg += atg; n     l->amn += atg; n     r->atg += atg; n     r->amn += atg; n     atg = 0; n   } n   void add(long long la, long long ra, long long w) { n     if (la <= ls && rs <= ra) { n       atg += w; n       amn += w; n       return; n     } n     push_down(); n     if (la <= l->rs) l->add(la, ra, w); n     if (ra >= r->ls) r->add(la, ra, w); n     amn = mmin(l->amn, r->amn); n   } n   long long query(long long first, long long rm) { n     if (ls > rm) return 0; n     if (bmn - k > first) return 0; n     if (ls == rs) return ls; n     push_down(); n     if (mmin(first, l->amn) >= r->bmn - k) { n       long long ans = r->query(mmin(first, l->amn), rm); n       if (ans) return ans; n     } n     return l->query(first, rm); n   } n }; n smt *rt; n signed main() { n   read(n, k); n   rt = new smt(1, n); n   for (long long i = 1; i < n; ++i) read(b[i]); n   for (long long i = 1; i <= n; ++i) read(a[i]); n   for (long long i = 1; i <= n; ++i) { n     f[i] = f[i - 1] + a[i - 1] - b[i - 1]; n   } n   for (long long i = 1; i <= n; ++i) { n     g[i] = g[i - 1] + b[i - 1] - a[i]; n   } n   long long ans = 0; n   for (long long i = n; i; --i) { n     rt->setg(i); n     while (t && f[s[t]] >= f[i]) { n       if (t > 1) { n         rt->add(s[t - 1] - 1, n, f[s[t]] - f[s[t - 1]]); n       } n       --t; n     } n     s[++t] = i; n     if (t > 1) assert(f[s[t]] >= f[s[t - 1]]); n     if (t > 1) { n       rt->add(s[t - 1] - 1, n, f[s[t - 1]] - f[s[t]]); n     } n     s[0] = n + 1; n     long long l = 1, r = t, mid; n     while (l <= r) { n       mid = (l + r) >> 1; n       if (f[i] - f[s[mid]] <= k) n         r = mid - 1; n       else n         l = mid + 1; n     } n     chkmax(ans, rt->query(inf, s[r] - 1) - i + 1); n   } n   write(ans,   n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T1, typename T2> n istream &operator>>(istream &in, pair<T1, T2> &a) { n   in >> a.first >> a.second; n   return in; n } n template <typename T1, typename T2> n ostream &operator<<(ostream &out, pair<T1, T2> a) { n   out << a.first <<     << a.second; n   return out; n } n template <typename T, typename T1> n T maxs(T &a, T1 b) { n   if (b > a) a = b; n   return a; n } n template <typename T, typename T1> n T mins(T &a, T1 b) { n   if (b < a) a = b; n   return a; n } n const long long MOD = 1000000007; n struct mod_int { n   long long val; n   mod_int(long long v = 0) { n     if (v < 0) v = v % MOD + MOD; n     if (v >= MOD) v %= MOD; n     val = v; n   } n   static long long mod_inv(long long a, long long m = MOD) { n     long long g = m, r = a, first = 0, second = 1; n     while (r != 0) { n       long long q = g / r; n       g %= r; n       swap(g, r); n       first -= q * second; n       swap(first, second); n     } n     return first < 0 ? first + m : first; n   } n   explicit operator long long() const { return val; } n   mod_int &operator+=(const mod_int &other) { n     val += other.val; n     if (val >= MOD) val -= MOD; n     return *this; n   } n   mod_int &operator-=(const mod_int &other) { n     val -= other.val; n     if (val < 0) val += MOD; n     return *this; n   } n   static unsigned fast_mod(uint64_t first, unsigned m = MOD) { n     return first % m; n     unsigned x_high = first >> 32, x_low = (unsigned)first; n     unsigned quot, rem; n     asm( divl %4 n  :  =a (quot),  =d (rem) :  d (x_high),  a (x_low),  r (m)); n     return rem; n   } n   mod_int &operator*=(const mod_int &other) { n     val = fast_mod((uint64_t)val * other.val); n     return *this; n   } n   mod_int &operator/=(const mod_int &other) { return *this *= other.inv(); } n   friend mod_int operator+(const mod_int &a, const mod_int &b) { n     return mod_int(a) += b; n   } n   friend mod_int operator-(const mod_int &a, const mod_int &b) { n     return mod_int(a) -= b; n   } n   friend mod_int operator*(const mod_int &a, const mod_int &b) { n     return mod_int(a) *= b; n   } n   friend mod_int operator/(const mod_int &a, const mod_int &b) { n     return mod_int(a) /= b; n   } n   mod_int &operator++() { n     val = val == MOD - 1 ? 0 : val + 1; n     return *this; n   } n   mod_int &operator--() { n     val = val == 0 ? MOD - 1 : val - 1; n     return *this; n   } n   mod_int operator++(int32_t) { n     mod_int before = *this; n     ++*this; n     return before; n   } n   mod_int operator--(int32_t) { n     mod_int before = *this; n     --*this; n     return before; n   } n   mod_int operator-() const { return val == 0 ? 0 : MOD - val; } n   bool operator==(const mod_int &other) const { return val == other.val; } n   bool operator!=(const mod_int &other) const { return val != other.val; } n   mod_int inv() const { return mod_inv(val); } n   mod_int pow(long long p) const { n     assert(p >= 0); n     mod_int a = *this, result = 1; n     while (p > 0) { n       if (p & 1) result *= a; n       a *= a; n       p >>= 1; n     } n     return result; n   } n   friend ostream &operator<<(ostream &stream, const mod_int &m) { n     return stream << m.val; n   } n   friend istream &operator>>(istream &stream, mod_int &m) { n     return stream >> m.val; n   } n }; n const long long N = 1e5 + 5; n vector<long long> g[N], in[N], out[N]; n mod_int p[N]; n pair<long long, long long> dp[4 * N][22]; n long long te = 0, temp = 0; n long long tin[N], LOG[4 * N], dep[N]; n mod_int last = 1; n void dfs(long long u, long long p) { n   dep[u] = dep[p] + 1; n   te++; n   tin[u] = te; n   dp[te][0] = {dep[u], u}; n   for (auto i : g[u]) { n     if (i != p) { n       dfs(i, u); n       te++; n       dp[te][0] = {dep[u], u}; n     } n   } n } n long long lca(long long u, long long v) { n   long long l = min(tin[u], tin[v]); n   long long r = max(tin[u], tin[v]); n   long long j = LOG[r - l + 1]; n   pair<long long, long long> p = min(dp[l][j], dp[r - (1 << j) + 1][j]); n   return p.second; n } n long long dis(long long u, long long v) { n   return dep[u] + dep[v] - 2 * dep[lca(u, v)]; n } n long long ctree[N]; n long long sz[N]; n long long vis[N]; n mod_int dp1[N], dp2[N]; n mod_int dp3[N], dp4[N]; n void dfs1(long long u, long long par) { n   sz[u] = 1; n   temp++; n   for (auto i : g[u]) { n     if (i != par && !vis[i]) { n       dfs1(i, u); n       sz[u] += sz[i]; n     } n   } n } n long long dfs2(long long u, long long par) { n   for (auto i : g[u]) { n     if (i != par && sz[i] > temp / 2 && !vis[i]) { n       return dfs2(i, u); n     } n   } n   return u; n } n void decompose(long long u, long long par) { n   temp = 0; n   dfs1(u, u); n   long long centroid = dfs2(u, u); n   ctree[centroid] = par; n   vis[centroid] = 1; n   for (auto i : g[centroid]) { n     if (vis[i]) continue; n     decompose(i, centroid); n   } n } n mod_int t = 0; n void insert(long long u) { n   t += p[u] * dp1[u]; n   dp2[u] += p[u]; n   long long i = u; n   while (ctree[i] > 0) { n     long long par = ctree[i]; n     mod_int d = dis(u, par); n     t = t + d * p[u] * (dp2[par] - dp4[i]) + p[u] * (dp1[par] - dp3[i]); n     dp2[par] += p[u], dp4[i] += p[u]; n     dp1[par] += p[u] * d, dp3[i] += p[u] * d; n     i = ctree[i]; n   } n } n void remove(long long u) { n   long long i = u; n   t -= p[u] * dp1[u]; n   dp2[u] -= p[u]; n   while (ctree[i] > 0) { n     long long par = ctree[i]; n     mod_int d = dis(u, par); n     dp2[par] -= p[u]; n     dp4[i] -= p[u]; n     dp1[par] -= p[u] * d; n     dp3[i] -= p[u] * d; n     t = t - d * p[u] * (dp2[par] - dp4[i]) - p[u] * (dp1[par] - dp3[i]); n     i = ctree[i]; n   } n } n long long solve() { n   long long n; n   cin >> n; n   long long mx = 0; n   for (long long i = 1; i < n + 1; i++) { n     long long l; n     long long r; n     cin >> l >> r; n     in[l].push_back(i), out[r].push_back(i); n     mod_int val = r - l + 1; n     p[i] = val.inv(); n     last *= val; n     maxs(mx, r); n   } n   for (long long i = 0; i < n - 1; i++) { n     long long u, v; n     cin >> u >> v; n     g[u].push_back(v); n     g[v].push_back(u); n   } n   dfs(1, 1); n   mod_int ans = 0; n   for (long long j = 1; j <= 20; j++) { n     for (long long i = 1; i + (1 << (j - 1)) <= te; i++) { n       dp[i][j] = min(dp[i][j - 1], dp[i + (1 << (j - 1))][j - 1]); n     } n   } n   decompose(1, 0); n   for (long long i = 1; i <= mx; i++) { n     for (auto j : in[i]) { n       insert(j); n     } n     ans += t; n     for (auto j : out[i]) { n       remove(j); n     } n   } n   cout << ans * last <<   n ; n   return 0; n } n signed main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   for (long long i = 2; i < 4 * N; i++) { n     LOG[i] = 1 + LOG[i / 2]; n   } n   long long t = 1; n   while (t--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s[50]; n   bool ada[256] = {0}; n   double dekat[256]; n   for (int i = 0; i < 256; i++) dekat[i] = 1000000000.0; n   int n, m; n   double x; n   cin >> n >> m >> x; n   for (int i = 0; i < n; i++) cin >> s[i]; n   vector<pair<int, int> > v; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       if (s[i][j] ==  S ) v.push_back(make_pair(i, j)); n     } n   } n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       if (s[i][j] ==  S ) continue; n       ada[s[i][j]] = 1; n       for (int k = 0; k < v.size(); k++) { n         double temp = sqrt((v[k].first - i) * (v[k].first - i) + n                            (v[k].second - j) * (v[k].second - j)); n         dekat[s[i][j]] = min(dekat[s[i][j]], temp); n       } n     } n   } n   int q; n   cin >> q; n   string qw; n   cin >> qw; n   int ans = 0; n   for (int i = 0; i < qw.length(); i++) { n     if (ada[qw[i]] == 1) continue; n     if (qw[i] >=  a  && qw[i] <=  z  && v.size() > 0) { n       if (ada[qw[i] - 32] == 0) { n         ans = -1; n         break; n       } else { n         if (dekat[qw[i] - 32] > x) { n           ans++; n         } n       } n     } else if (qw[i] >=  A  && qw[i] <=  Z  && v.size() > 0) { n       if (ada[qw[i] + 32] == 0) { n         ans = -1; n         break; n       } else { n         if (dekat[qw[i] + 32] > x) { n           ans++; n         } n       } n     } else { n       ans = -1; n       break; n     } n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, a, b, cnt = 1, point = 0; n   vector<int> x; n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> a >> b; n     if (b == 0) n       x.push_back(a); n     else { n       cnt += (b - 1); n       point += a; n     } n   } n   sort(x.begin(), x.end()); n   for (int j = x.size() - 1; j >= 0 && cnt > 0; j--, cnt--) { n     point += x[j]; n   } n   cout << point << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline int read() { n   char ch = getchar(); n   int nega = 1; n   while (!isdigit(ch)) { n     if (ch ==  - ) nega = -1; n     ch = getchar(); n   } n   int ans = 0; n   while (isdigit(ch)) { n     ans = ans * 10 + ch - 48; n     ch = getchar(); n   } n   if (nega == -1) return -ans; n   return ans; n } n int fa[200005 * 2], siz[200005 * 2], n; n int find(int u) { return fa[u] == u ? u : fa[u] = find(fa[u]); } n int a[200005], b[200005]; n vector<int> v[200005]; n void merge(int u, int v) { n   u = find(u), v = find(v); n   if (u == v) return; n   fa[u] = v; n   siz[v] += siz[u]; n } n bool vis[200005 * 2], ch[200005 * 2]; n void work() { n   cin >> n; n   for (int i = 1; i <= n; i++) v[i].clear(); n   for (int i = 1; i <= n; i++) a[i] = read(), v[a[i]].push_back(i); n   for (int i = 1; i <= n; i++) b[i] = read(), v[b[i]].push_back(i + n); n   for (int i = 1; i <= 2 * n; i++) fa[i] = i; n   for (int i = 1; i <= n; i++) siz[i] = 1; n   for (int i = n + 1; i <= 2 * n; i++) siz[i] = 0; n   for (int i = 1; i <= n * 2; i++) vis[i] = ch[i] = 0; n   for (int i = 1; i <= n; i++) { n     if (v[i].size() != 2) { n       cout <<  -1 n ; n       return; n     } n     int a = v[i][0], b = v[i][1]; n     if (a > b) swap(a, b); n     if (a == b - n) continue; n     if (a > n) { n       a -= n, b -= n; n       merge(a, b + n), merge(a + n, b); n     } else if (b <= n) n       merge(a, b + n), merge(a + n, b); n     else { n       b -= n; n       merge(a, b), merge(a + n, b + n); n     } n   } n   for (int i = 1; i <= n; i++) { n     if (find(i) == find(i + n)) { n       cout <<  -1 n ; n       return; n     } n   } n   int ans = 0; n   for (int i = 1; i <= n; i++) { n     int u = find(i), v = find(i + n); n     if (vis[u] || vis[v]) continue; n     ans += min(siz[u], siz[v]); n     vis[u] = vis[v] = 1; n     if (siz[u] < siz[v]) n       ch[u] = 1; n     else n       ch[v] = 1; n   } n   cout << ans << endl; n   for (int i = 1; i <= n; i++) { n     int u = find(i); n     if (ch[u]) printf( %d  , i); n   } n   cout <<   n ; n } n signed main() { n   int T = read(); n   while (T--) work(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, x[101000], y[101000], fa[101000], sz[101000], tot[101000], u, v; n map<int, vector<int> > xx, yy; n map<int, vector<int> >::iterator it; n long long ans = 1, er[202000]; n int GF(int x) { return fa[x] == x ? x : fa[x] = GF(fa[x]); } n void doit(vector<int> &the) { n   for (int i = 1; i < (int)the.size(); i++) n     if ((u = GF(the[i - 1])) != (v = GF(the[i]))) { n       sz[v] += sz[u]; n       tot[v] += tot[u]; n       fa[u] = v; n     } n   tot[GF(the[0])]++; n } n int main() { n   cin >> n; n   for (int i = 1; i <= n; i++) { n     cin >> x[i] >> y[i]; n     xx[x[i]].push_back(i); n     yy[y[i]].push_back(i); n     fa[i] = i; n     sz[i] = 1; n   } n   for (it = xx.begin(); it != xx.end(); it++) doit(it->second); n   for (it = yy.begin(); it != yy.end(); it++) doit(it->second); n   er[0] = 1; n   for (int i = 1; i < 202000; i++) er[i] = er[i - 1] * 2 % 1000000007; n   for (int i = 1; i <= n; i++) n     if (fa[i] == i) ans = ans * (er[tot[i]] - (tot[i] > sz[i])) % 1000000007; n   cout << (ans + 1000000007) % 1000000007; n } n


#include <bits/stdc++.h> n using namespace std; n const double pi = acos(-1); n int ans, pos[120000], fa[21][120000], tim, dep[120000], K, n, x, y; n vector<int> E[120000]; n struct wph { n   bool operator()(const int x, const int y) { return pos[x] < pos[y]; } n }; n set<int, wph> S; n void prep(int x, int ff) { n   fa[0][x] = ff; n   for (int i = 1; i <= 20; ++i) fa[i][x] = fa[i - 1][fa[i - 1][x]]; n } n void dfs(int x, int ff) { n   pos[x] = ++tim; n   prep(x, ff); n   for (int i = 0; i < E[x].size(); ++i) n     if (E[x][i] != ff) { n       dep[E[x][i]] = dep[x] + 1; n       dfs(E[x][i], x); n     } n } n int pathlen(int x, int y) { n   int ans = dep[x] + dep[y]; n   if (dep[x] < dep[y]) swap(x, y); n   for (int i = 20; i >= 0; --i) n     if ((dep[x] - dep[y]) >= 1 << i) x = fa[i][x]; n   if (x == y) return ans - 2 * dep[x]; n   for (int i = 20; i >= 0; --i) n     if (fa[i][x] != fa[i][y]) x = fa[i][x], y = fa[i][y]; n   return ans - 2 * dep[fa[0][x]]; n } n int calc(set<int>::iterator it) { n   int len = 0; n   auto p1 = it, p2 = it; n   if (p1 == S.begin()) p1 = S.end(); n   p1--; n   len += pathlen(*p1, *it); n   p2++; n   if (p2 == S.end()) p2 = S.begin(); n   len += pathlen(*p2, *it); n   len -= pathlen(*p2, *p1); n   return len; n } n int main() { n   scanf( %d%d , &n, &K); n   for (int i = 1; i <= n - 1; ++i) { n     scanf( %d%d , &x, &y); n     E[x].push_back(y); n     E[y].push_back(x); n   } n   dfs(1, 0); n   ans = 1; n   S.insert(1); n   int j = 1, size = 0; n   for (int i = 2; i <= n; ++i) { n     auto p = S.insert(i).first; n     size += calc(p); n     while (size / 2 + 1 > K) { n       p = S.find(j); n       size -= calc(p); n       S.erase(p); n       j++; n     } n     ans = max(ans, i - j + 1); n   } n   printf( %d n , ans); n } n


#include <bits/stdc++.h> n using namespace std; n const long long int mod = 1e9 + 7; n const long long int lim = 1e17; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long int T = clock(); n   long long int n, k; n   cin >> n >> k; n   map<long long int, long long int> mpp; n   vector<long long int> a(n); n   for (long long int i = 0; i < n; i++) cin >> a[i]; n   long long int tot = 0; n   mpp[0] = 1; n   long long int ans = 0; n   for (long long int i = 0; i < n; i++) { n     tot += a[i]; n     long long int r = 1; n     if (k == -1) { n       ans += mpp[tot - 1]; n       ans += mpp[tot + 1]; n     } else if (k == 1) n       ans += mpp[tot - 1]; n     else { n       while (r < lim) { n         if (mpp.find(tot - r) != mpp.end()) ans += mpp[tot - r]; n         r *= k; n       } n     } n     mpp[tot]++; n   } n   cout << ans; n   cerr <<   n nTIME:   << (double)(clock() - T) / CLOCKS_PER_SEC <<   sec n ; n   T = clock(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char a[103], b[103], c[103]; n char aa[103], bb[103], cc[103]; n char temp[103]; n int temp2; n char ss[602]; n char s[602]; n int n; n int main() { n   scanf( %s%s%s , aa, bb, cc); n   scanf( %d , &n); n   int i, j, jj; n   int coun1 = 0, coun2 = 0, coun3 = 0; n   for (i = 0; aa[i]; i++) n     if (aa[i] !=  _  && aa[i] !=  ;  && aa[i] !=  - ) a[coun1++] = aa[i]; n   for (i = 0; bb[i]; i++) n     if (bb[i] !=  _  && bb[i] !=  ;  && bb[i] !=  - ) b[coun2++] = bb[i]; n   for (i = 0; cc[i]; i++) n     if (cc[i] !=  _  && cc[i] !=  ;  && cc[i] !=  - ) c[coun3++] = cc[i]; n   for (i = 0; a[i]; i++) n     if (a[i] > 96) a[i] -= 32; n   for (i = 0; b[i]; i++) n     if (b[i] > 96) b[i] -= 32; n   for (i = 0; c[i]; i++) n     if (c[i] > 96) c[i] -= 32; n   if (coun1 < coun3) { n     for (i = 0; i < coun1; i++) temp[i] = a[i]; n     for (i = 0; i < coun3; i++) a[i] = c[i]; n     for (i = 0; i < coun1; i++) c[i] = temp[i]; n     temp2 = coun1; n     coun1 = coun3; n     coun3 = temp2; n   } n   if (coun1 < coun2) { n     for (i = 0; i < coun1; i++) temp[i] = a[i]; n     for (i = 0; i < coun2; i++) a[i] = b[i]; n     for (i = 0; i < coun1; i++) b[i] = temp[i]; n     temp2 = coun1; n     coun1 = coun2; n     coun2 = temp2; n   } n   if (coun2 < coun3) { n     for (i = 0; i < coun2; i++) temp[i] = b[i]; n     for (i = 0; i < coun3; i++) b[i] = c[i]; n     for (i = 0; i < coun2; i++) c[i] = temp[i]; n     temp2 = coun2; n     coun2 = coun3; n     coun3 = temp2; n   } n   a[coun1] =   0 ; n   b[coun2] =   0 ; n   c[coun3] =   0 ; n   int coun; n   bool flag; n   bool flag2; n   bool flagi[5]; n   for (i = 0; i < n; i++) { n     coun = 0; n     scanf( %s , ss); n     for (j = 0; j < 5; j++) flagi[j] = false; n     for (j = 0; ss[j]; j++) n       if (ss[j] !=  ;  && ss[j] !=  _  && ss[j] !=  - ) s[coun++] = ss[j]; n     for (j = 0; j < coun; j++) n       if (s[j] > 96) s[j] -= 32; n     for (j = 0; j < coun; j++) { n       flag = false; n       flag2 = true; n       for (jj = 0; a[jj]; jj++) n         if (a[jj] != s[j + jj] || j + jj == coun) flag2 = false; n       if (flag2 && !flagi[0]) { n         flag = true; n         flagi[0] = true; n         j = j + jj - 1; n         continue; n       } n       flag2 = true; n       for (jj = 0; b[jj]; jj++) n         if (b[jj] != s[j + jj] || j + jj == coun) flag2 = false; n       if (flag2 && !flagi[1]) { n         flag = true; n         flagi[1] = true; n         j = j + jj - 1; n         continue; n       } n       flag2 = true; n       for (jj = 0; c[jj]; jj++) n         if (c[jj] != s[j + jj] || j + jj == coun) flag2 = false; n       if (flag2 && !flagi[2]) { n         flag = true; n         flagi[2] = true; n         j = j + jj - 1; n         continue; n       } n       if (!flag) break; n       if (j == coun - 1) break; n     } n     if (flag) { n       for (j = 0; j < 3; j++) n         if (!flagi[j]) flag = false; n     } n     if (flag) n       printf( ACC n ); n     else n       printf( WA n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n vector<int> arr; n int dp[101][101][101][2]; n int solve(int index, int even, int odd, int pre) { n   if (index == n + 1) return 0; n   if (dp[index][even][odd][pre] != -1) return dp[index][even][odd][pre]; n   if (arr[index] != 0) { n     int ans = solve(index + 1, even, odd, arr[index] % 2); n     if (pre != -1) { n       if ((arr[index] % 2) != pre) ans++; n     } n     return ans; n   } n   int ans = INT_MAX; n   if (even > 0) { n     ans = min(ans, solve(index + 1, even - 1, odd, 0) + (pre == 1)); n   } n   if (odd > 0) { n     ans = min(ans, solve(index + 1, even, odd - 1, 1) + (pre == 0)); n   } n   dp[index][even][odd][pre] = ans; n   return ans; n } n int main() { n   ios_base::sync_with_stdio(false); n   cout.tie(0); n   cin.tie(NULL); n   cin >> n; n   for (int i = 0; i < 101; i++) { n     for (int j = 0; j < 101; j++) { n       for (int k = 0; k < 101; k++) { n         dp[i][j][k][0] = dp[i][j][k][1] = -1; n       } n     } n   } n   arr.resize(n + 1); n   int even = n / 2; n   int odd = (n + 1) / 2; n   for (int i = 1; i <= n; i++) { n     cin >> arr[i]; n     if (arr[i] % 2) n       odd--; n     else if (arr[i]) n       even--; n   } n   int ans = solve(1, even, odd, -1); n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX = 2e5 + 5; n int parent[MAX]; n int depth[MAX]; n int get(int a) { n   while (a != parent[a]) a = parent[a]; n   return a; n } n void join(int a, int b) { n   a = get(a); n   b = get(b); n   if (a == b) return; n   if (depth[a] > depth[b]) swap(a, b); n   parent[a] = b; n   depth[b] += depth[a]; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int n, q, a, b, w; n   cin >> n >> q; n   for (int i = 1; i <= n + 1; i++) { n     parent[i] = i; n     depth[i] = 1; n   } n   vector<pair<int, pair<int, int>>> vp; n   vector<long long> sol(MAX); n   long long cnt = 0; n   for (int i = 0; i < n - 1; i++) { n     cin >> a >> b >> w; n     vp.push_back({w, {a, b}}); n   } n   sort(vp.begin(), vp.end()); n   reverse(vp.begin(), vp.end()); n   for (int j = 1; j < MAX; j++) { n     while (!vp.empty() && vp.back().first <= j) { n       a = vp.back().second.first; n       b = vp.back().second.second; n       vp.pop_back(); n       a = get(a); n       b = get(b); n       if (a == b) continue; n       cnt -= 1ll * depth[a] * (depth[a] - 1) / 2; n       cnt -= 1ll * depth[b] * (depth[b] - 1) / 2; n       join(a, b); n       a = get(a); n       cnt += 1ll * depth[a] * (depth[a] - 1) / 2; n     } n     sol[j] = cnt; n   } n   while (q--) { n     cin >> w; n     cout << sol[w] <<    ; n   } n   cout <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s; n   getline(cin, s); n   long long n = s.length(), i = n - 1; n   while (1) { n     if ((s[i] >= 65 && s[i] <= 91) || (s[i] >= 97 && s[i] <= 122)) { n       if (s[i] ==  a  || s[i] ==  y  || s[i] ==  e  || s[i] ==  i  || n           s[i] ==  o  || s[i] ==  u ) { n         cout <<  YES  << endl; n         break; n       } else if (s[i] ==  A  || s[i] ==  Y  || s[i] ==  E  || s[i] ==  I  || n                  s[i] ==  O  || s[i] ==  U ) { n         cout <<  YES  << endl; n         break; n       } else { n         cout <<  NO  << endl; n         break; n       } n     } n     i--; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 1 << 30; n const long long inf = 1LL << 60; n const int N = 200010; n struct Edge { n   int to, next; n } e1[N], e2[N]; n int list1[N], list2[N], d1, d2; n priority_queue<pair<int, int> > Q; n queue<int> S; n bool vis[N]; n vector<int> v[N]; n void add(int x, int y, int *list, int &d, Edge *e) { n   e[d].to = y, e[d].next = list[x], list[x] = d++; n } n int n, m, k; n int ans[N], Min[N], din[N], dout[N], d[N]; n int read() { n   int w(0), f(0); n   char c = getchar(); n   while ((c <  0  || c >  9 ) && c !=  - ) c = getchar(); n   if (c ==  - ) f = 1, c = getchar(); n   while (c >=  0  && c <=  9 ) w = w * 10 + c -  0 , c = getchar(); n   return f ? -w : w; n } n void Imps() { n   puts( -1 ); n   exit(0); n } n void Delete(int x) { n   int y; n   for (int i = list2[x]; i >= 0; i = e2[i].next) { n     y = e2[i].to; n     d[y]--; n     if (!d[y] && !ans[y]) Q.push(make_pair(Min[y], y)); n   } n } n int main() { n   n = read(), m = read(), k = read(); n   memset(list1, -1, 4 * (n + 1)), memset(list2, -1, 4 * (n + 1)); n   for (int i = 1; i <= n; ++i) n     ans[i] = read(), vis[ans[i]] = 1, v[ans[i]].push_back(i); n   int x, y; n   pair<int, int> tmp; n   for (int i = 1; i <= m; ++i) { n     x = read(), y = read(); n     add(y, x, list1, d1, e1); n     add(x, y, list2, d2, e2); n     din[x]++, dout[y]++; n   } n   for (int i = 1; i <= n; ++i) { n     d[i] = din[i]; n     if (!d[i]) S.push(i); n   } n   while (!S.empty()) { n     x = S.front(), S.pop(); n     if (ans[x]) { n       if (ans[x] < Min[x]) n         Imps(); n       else n         Min[x] = ans[x]; n     } else if (!Min[x]) n       Min[x] = 1; n     for (int i = list1[x]; i >= 0; i = e1[i].next) { n       y = e1[i].to; n       Min[y] = max(Min[y], Min[x] + 1); n       d[y]--; n       if (!d[y]) S.push(y); n     } n   } n   for (int i = 1; i <= n; ++i) { n     d[i] = dout[i]; n     if (!d[i] && !ans[i]) Q.push(make_pair(Min[i], i)); n   } n   for (int i = k; i >= 1; --i) { n     for (int j = 0; j < v[i].size(); ++j) { n       x = v[i][j]; n       Delete(x); n     } n     while (!Q.empty()) { n       tmp = Q.top(); n       if (tmp.first > i) n         Imps(); n       else if (tmp.first == i) n         ans[tmp.second] = i, vis[i] = 1, Q.pop(), Delete(tmp.second); n       else n         break; n     } n     if (!vis[i]) { n       if (!Q.empty()) { n         tmp = Q.top(); n         ans[tmp.second] = i, vis[i] = 1, Q.pop(), Delete(tmp.second); n       } else n         Imps(); n     } n   } n   for (x = 1; x <= n; ++x) n     for (int i = list1[x]; i >= 0; i = e1[i].next) n       if (ans[x] >= ans[e1[i].to]) Imps(); n   for (int i = 1; i <= n; ++i) printf( %d  , ans[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   int t; n   cin >> t; n   while (t--) { n     int n; n     cin >> n; n     long long move = 0; n     for (int i = 1; i <= n / 2; ++i) { n       move += i * 1ll * i; n     } n     cout << move * 8 << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int x, t, a, b, da, db; n   while (cin >> x >> t >> a >> b >> da >> db) { n     bool f = 0; n     for (int i = 0; i <= t; i++) { n       for (int j = 0; j <= t; j++) { n         int t1, t2; n         if (i == t) n           t1 = 0; n         else n           t1 = a - i * da; n         if (j == t) n           t2 = 0; n         else n           t2 = b - j * db; n         if (t1 + t2 == x) { n           f = 1; n           break; n         } n       } n     } n     if (f) n       cout <<  YES  << endl; n     else n       cout <<  NO  << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n void func(void) { n   freopen( input.c ,  r , stdin); n   freopen( output.c ,  w , stdout); n } n void print(vector<long long> &v) { n   cout << v.size() << endl; n   for (int i = 0; i < v.size(); i++) { n     printf( %lld  , v[i]); n   } n   printf(  n ); n } n void print(vector<pair<long long, long long> > &v) { n   cout << v.size() << endl; n   for (int i = 0; i < v.size(); i++) { n     printf( %lld %lld n , v[i].first, v[i].second); n   } n } n void print(double d) { cout << fixed << setprecision(10) << d << endl; } n void print(string s, double d) { n   cout << s <<    ; n   cout << fixed << setprecision(10) << d << endl; n } n const int N = 1e5 + 100; n struct info { n   long long day, cost, place; n   bool operator<(info k1) const { return day < k1.day; } n }; n vector<info> in; n vector<info> out; n set<pair<long long, long long> > outFlight[N]; n long long inFlight[N]; n int main() { n   long long n, q, i, j = 0, temp, t, k, ans = 0, sum = 0, x, y, z, cnt = 0, m, n                      fg = 0, mx = 0, mx1 = 0, mn = 8e18, n                      mn1 = 8000000000000000000; n   scanf( %lld %lld %lld , &n, &m, &k); n   for (int i = 0; i < m; i++) { n     scanf( %lld %lld , &x, &y); n     scanf( %lld %lld , &z, &t); n     info xx; n     xx.day = x; n     xx.place = y; n     if (y == 0) xx.place = z; n     xx.cost = t; n     if (y) n       in.push_back(xx); n     else n       out.push_back(xx); n   } n   sort(in.begin(), in.end()); n   sort(out.begin(), out.end()); n   for (int i = 0; i < N; i++) inFlight[i] = 1e10; n   int ok = 0; n   for (int i = 0; i < out.size(); i++) { n     outFlight[out[i].place].insert({out[i].cost, i}); n   } n   long long outSum = 0; n   long long inSum = 0; n   for (int i = 1; i <= n; i++) { n     if (outFlight[i].size() == 0) { n       printf( -1 n ); n       return 0; n     } n     auto it = outFlight[i].begin(); n     pair<long long, long long> p = *it; n     outSum += p.first; n   } n   cnt = 0; n   for (int i = 0; i < in.size(); i++) { n     long long now = in[i].day; n     long long place = in[i].place; n     long long cost = in[i].cost; n     if (inFlight[place] == 1e10) { n       inFlight[place] = cost; n       inSum += cost; n       cnt++; n     } else { n       inSum -= inFlight[place]; n       inFlight[place] = min(inFlight[place], cost); n       inSum += inFlight[place]; n     } n     now += k + 1; n     fg = 0; n     for (; ok < out.size(); ok++) { n       if (out[ok].day >= now) break; n       auto it = outFlight[out[ok].place].begin(); n       pair<long long, long long> p = *it; n       outSum -= p.first; n       p = {out[ok].cost, ok}; n       outFlight[out[ok].place].erase(p); n       if (outFlight[out[ok].place].size() == 0) { n         fg = 1; n         break; n       } n       it = outFlight[out[ok].place].begin(); n       p = *it; n       outSum += p.first; n     } n     if (fg) break; n     if (cnt == n) { n       mn = min(mn, inSum + outSum); n     } n   } n   if (mn == 8e18) mn = -1; n   cout << mn << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int flag = 0, ans, n; n int r[10], d[12], l[12], u[12]; n int print(int x1, int y1, int x2, int y2) { n   cout <<  ?   << x1 <<     << y1 <<     << x2 <<     << y2 << endl; n   int val; n   cin >> val; n   if (flag) { n     if (x1 <= l[0] && r[0] <= x2 && y1 <= d[0] && u[0] <= y2) return val - 1; n   } n   return val; n } n int findright(int l, int r) { n   if (l > r) return 0; n   int mid = (l + r) / 2; n   int val = print(1, 1, mid, n); n   if (val > 0) { n     ans = mid; n     findright(l, mid - 1); n   } else { n     findright(mid + 1, r); n   } n   return 0; n } n int findleft(int l, int r, int r1) { n   if (l > r) return 0; n   int mid = (l + r) / 2; n   int val = print(mid, 1, r1, n); n   if (val > 0) { n     ans = mid; n     findleft(mid + 1, r, r1); n   } else { n     findleft(l, mid - 1, r1); n   } n   return 0; n } n int findup(int l, int r, int l1, int r1) { n   if (l > r) return 0; n   int mid = (l + r) / 2; n   int val = print(l1, 1, r1, mid); n   if (val > 0) { n     ans = mid; n     findup(l, mid - 1, l1, r1); n   } else { n     findup(mid + 1, r, l1, r1); n   } n   return 0; n } n int finddown(int l, int r, int l1, int r1, int u1) { n   if (l > r) return 0; n   int mid = (l + r) / 2; n   int val = print(l1, mid, r1, u1); n   if (val > 0) { n     ans = mid; n     finddown(mid + 1, r, l1, r1, u1); n   } else { n     finddown(l, mid - 1, l1, r1, u1); n   } n   return 0; n } n int main() { n   std::ios::sync_with_stdio(false); n   int i; n   cin >> n; n   int r1, l1, u1, d1; n   findright(1, n); n   r1 = ans; n   findleft(1, r1, r1); n   l1 = ans; n   l[0] = l1; n   r[0] = r1; n   findup(1, n, l1, r1); n   u1 = ans; n   finddown(1, u1, l1, r1, u1); n   d1 = ans; n   u[0] = u1; n   d[0] = d1; n   flag = 1; n   findright(1, n); n   r1 = ans; n   findleft(1, r1, r1); n   l1 = ans; n   l[1] = l1; n   r[1] = r1; n   findup(1, n, l1, r1); n   u1 = ans; n   finddown(1, u1, l1, r1, u1); n   d1 = ans; n   u[1] = u1; n   d[1] = d1; n   cout <<  !  ; n   for (i = 0; i < 1; i++) { n     cout << l[i] <<     << d[i] <<     << r[i] <<     << u[i] <<    ; n   } n   i = 1; n   cout << l[i] <<     << d[i] <<     << r[i] <<     << u[i]; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = (int)2e5 + 88; n char tu[maxn]; n int lu[maxn]; n int main() { n   int n, a, b, k; n   cin >> n >> a >> b >> k; n   scanf( %s , tu); n   for (int i = 0; i < maxn; i++) { n     lu[i] = 0; n   } n   int ans = 0; n   int ant = 0; n   int ttt = 0; n   for (int i = 0; i < n; i++) { n     if (tu[i] ==  0 ) { n       ant++; n     } else n       ant = 0; n     if (ant != 0 && ant % b == 0) { n       ans++; n       if (ans >= a) { n         lu[ttt++] = i; n       } n     } n   } n   cout << ttt << endl; n   for (int i = 0; i < ttt; i++) { n     cout << lu[i] + 1 <<    ; n   } n } n


#include <bits/stdc++.h> n using std::cerr; n using std::cin; n using std::cout; n using std::endl; n using std::list; n using std::map; n using std::max; n using std::min; n using std::pair; n using std::set; n using std::sort; n using std::string; n using std::swap; n using std::vector; n const int MAXN = 100005; n const long long INF = 100000000009; n const long long MOD = (long long)1e9 + 7; n bool used[MAXN]; n bool cnt[MAXN][50]; n int main() { n   std::ios_base::sync_with_stdio(false); n   std::cin.tie(nullptr); n   int n; n   cin >> n; n   string sec; n   cin >> sec; n   for (int i = 0; i < n; ++i) { n     if (sec[i] !=  * ) { n       used[(int)sec[i]] = true; n     } n   } n   int m; n   cin >> m; n   vector<string> needed; n   for (int i = 0; i < m; ++i) { n     string s; n     cin >> s; n     bool flag = true; n     for (int j = 0; j < n; ++j) { n       if (sec[j] ==  * ) { n         if (used[(int)s[j]]) { n           flag = false; n           break; n         } n       } else if (sec[j] != s[j]) { n         flag = false; n         break; n       } n     } n     if (flag) { n       needed.push_back(s); n     } n   } n   for (int j = 0; j < needed.size(); ++j) { n     for (int i = 0; i < n; ++i) { n       if (sec[i] ==  * ) { n         cnt[j][(int)needed[j][i] -  a ] = true; n       } n     } n   } n   int ans = 0; n   for (int i = 0; i <= (int) z  - (int) a ; ++i) { n     bool flag = true; n     for (int j = 0; j < needed.size(); ++j) { n       if (!cnt[j][i]) { n         flag = false; n       } n     } n     if (flag) { n       ++ans; n     } n   } n   cout << ans; n   return 0; n } n