#include <bits/stdc++.h> n using namespace std; n const int limit = 453; n int n, m, q, i, x, y, col; n vector<pair<int, int> > edges[100011]; n pair<int, int> Q[100011]; n vector<int> cols[100011]; n int sz[100011]; n int id_big[100011], cnt_big; n int dad[100011]; n vector<int> who[100011]; n int big[limit + 11][100011]; n bool us[100011]; n vector<int> appear[100011]; n int groups; n int Find(int x) { n   if (dad[x] == x) return x; n   dad[x] = Find(dad[x]); n   return dad[x]; n } n bool Merge(int x, int y) { n   x = Find(x); n   y = Find(y); n   if (x == y) return false; n   dad[x] = y; n   return true; n } n void pre() { n   int i; n   for (i = 1; i <= n; i++) { n     dad[i] = i; n     sort(cols[i].begin(), cols[i].end()); n     cols[i].resize(unique(cols[i].begin(), cols[i].end()) - cols[i].begin()); n     sz[i] = cols[i].size(); n     if (sz[i] >= limit) id_big[i] = ++cnt_big; n   } n } n void solve_color(int id) { n   for (auto e : edges[id]) Merge(e.first, e.second); n   for (auto e : edges[id]) { n     if (!us[e.first]) who[Find(e.first)].push_back(e.first); n     if (!us[e.second]) who[Find(e.second)].push_back(e.second); n     us[e.first] = us[e.second] = true; n   } n   for (auto e : edges[id]) { n     int node = e.first; n     if (who[e.second].size() > 0) node = e.second; n     if (who[node].size() > 0) { n       groups++; n       for (auto n1 : who[node]) { n         appear[n1].push_back(groups); n         if (sz[n1] < limit) continue; n         for (auto n2 : who[node]) big[id_big[n1]][n2]++; n       } n       who[node].clear(); n     } n   } n   for (auto e : edges[id]) n     dad[e.first] = e.first, dad[e.second] = e.second, n     us[e.first] = us[e.second] = false; n } n int main() { n   scanf( %d%d , &n, &m); n   for (i = 1; i <= m; i++) { n     scanf( %d%d%d , &x, &y, &col); n     edges[col].push_back(make_pair(x, y)); n     cols[x].push_back(col); n     cols[y].push_back(col); n   } n   pre(); n   scanf( %d , &q); n   for (i = 1; i <= q; i++) { n     scanf( %d%d , &x, &y); n     Q[i] = make_pair(x, y); n   } n   for (i = 1; i <= m; i++) { n     if (edges[i].empty()) continue; n     solve_color(i); n   } n   for (i = 1; i <= q; i++) { n     if (sz[Q[i].first] > sz[Q[i].second]) swap(Q[i].first, Q[i].second); n     if (sz[Q[i].second] < limit) { n       int c0 = 0; n       int c1 = 0; n       int n1 = Q[i].first; n       int n2 = Q[i].second; n       int ans = 0; n       while (c0 < appear[n1].size() && c1 < appear[n2].size()) { n         if (appear[n1][c0] == appear[n2][c1]) { n           ans++; n           c0++; n           c1++; n           continue; n         } n         if (appear[n1][c0] < appear[n2][c1]) n           c0++; n         else n           c1++; n       } n       printf( %d n , ans); n       continue; n     } n     printf( %d n , big[id_big[Q[i].second]][Q[i].first]); n   } n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long s; n   scanf( %I64d , &s); n   long long d = s; n   int n = 0; n   while (s > 0) { n     d /= 10; n     d *= 10; n     int a = s - d; n     if (a == 4 || a == 7) { n       n++; n     } n     s /= 10; n     d = s; n   } n   if (n == 0) { n     printf( NO ); n     return 0; n   } n   d = n; n   while (n > 0) { n     d /= 10; n     d *= 10; n     int a = n - d; n     if (a != 4 && a != 7) { n       printf( NO ); n       return 0; n     } n     n /= 10; n     d = n; n   } n   printf( YES ); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int n, a, b, k; n   cin >> n >> a >> b >> k; n   long long int skips_left = k; n   long long int win = 0; n   long long int h[n]; n   long long int skips_req[n]; n   for (long long int m = 0; m < n; m++) { n     skips_req[m] = 0; n   } n   for (long long int j = 0; j < n; j++) { n     cin >> h[j]; n     long long int rem = (h[j] % (a + b)); n     if ((0 < rem) && (rem <= a)) { n       skips_req[j] = 0; n     } else if ((a < rem) && (rem < (a + b))) { n       long long int skips; n       if ((rem - a) % a == 0) { n         skips_req[j] = (rem - a) / a; n       } else { n         skips = (rem - a) / a + 1; n         skips_req[j] = skips; n       } n     } else if (rem == 0) { n       long long int skips; n       if ((b) % a == 0) { n         skips_req[j] = b / a; n       } else { n         skips = (b / a) + 1; n         skips_req[j] = skips; n       } n     } n   } n   sort(skips_req, skips_req + n); n   long long int d; n   d = 0; n   while ((skips_left > 0) && (d < n)) { n     skips_left = skips_left - skips_req[d]; n     if (skips_left >= 0) { n       win++; n     } n     d++; n   } n   cout << win << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long inf = 2147383647; n const double pi = 2 * acos(0.0); n const double eps = 1e-9; n struct debugger { n   template <typename T> n   debugger& operator,(const T& v) { n     cerr << v <<    ; n     return *this; n   } n } dbg; n inline long long gcd(long long a, long long b) { n   a = ((a) < 0 ? -(a) : (a)); n   b = ((b) < 0 ? -(b) : (b)); n   while (b) { n     a = a % b; n     swap(a, b); n   } n   return a; n } n int ext_gcd(int a, int b, int& x, int& y) { n   if (a == 0) { n     x = 0; n     y = 1; n     return b; n   } n   int x1, y1; n   int d = ext_gcd(b % a, a, x1, y1); n   x = y1 - (b / a) * x1; n   y = x1; n   return d; n } n inline long long modInv(int a, int m) { n   int x, y; n   ext_gcd(a, m, x, y); n   if (x < 0) x += m; n   return x; n } n inline long long power(long long a, long long p) { n   long long res = 1, x = a; n   while (p) { n     if (p & 1) res = (res * x); n     x = (x * x); n     p >>= 1; n   } n   return res; n } n inline long long bigmod(long long a, long long p, long long m) { n   long long res = 1, x = a % m; n   while (p) { n     if (p & 1) res = (res * x) % m; n     x = (x * x) % m; n     p >>= 1; n   } n   return res; n } n vector<pair<int, int> > adj[100010]; n pair<int, int> vis[100010]; n int n; n struct road { n   int u, v, w; n } rdd[100010]; n pair<int, int> par[100010]; n void bfs() { n   pair<int, int> xyz = make_pair(inf, inf); n   for (int i = (1); i <= (n); ++i) vis[i] = xyz; n   queue<int> q; n   q.push(1); n   vis[1] = make_pair(0, 0); n   while (!q.empty()) { n     int s = q.front(); n     q.pop(); n     for (int i = (0); i <= (((int)(adj[s]).size()) - 1); ++i) { n       xyz = adj[s][i]; n       int t = xyz.first; n       int w = 1 - xyz.second; n       if (vis[t].first == inf || vis[s].first + 1 < vis[t].first) { n         vis[t] = make_pair(vis[s].first + 1, vis[s].second + w); n         q.push(t); n         par[t] = make_pair(s, i); n       } else if (vis[s].first + 1 == vis[t].first) { n         if (vis[s].second + w < vis[t].second) { n           vis[t].second = vis[s].second + w; n           par[t] = make_pair(s, i); n         } n       } n     } n   } n } n int mark[100010]; n set<pair<int, int> > st; n int main() { n   int m; n   scanf( %d %d , &n, &m); n   int good = 0; n   for (int i = (0); i <= (m - 1); ++i) { n     int u, v, w; n     scanf( %d %d %d , &u, &v, &w); n     rdd[i].u = u; n     rdd[i].v = v; n     rdd[i].w = w; n     adj[u].push_back(make_pair(v, w)); n     adj[v].push_back(make_pair(u, w)); n     if (w == 1) good++; n   } n   bfs(); n   pair<int, int> temp; n   int cur = n; n   while (cur != 1) { n     temp = par[cur]; n     int s = temp.first; n     int t = cur; n     st.insert(make_pair(s, t)); n     st.insert(make_pair(t, s)); n     cur = s; n   } n   int x = vis[n].second; n   int k = 2 * x + good - vis[n].first; n   printf( %d n , k); n   for (int i = (0); i <= (m - 1); ++i) { n     int u = rdd[i].u; n     int v = rdd[i].v; n     int w = rdd[i].w; n     if (w == 1 && st.find(make_pair(u, v)) == st.end()) { n       printf( %d %d %d n , u, v, 1 - w); n     } else if (w == 0 && st.find(make_pair(u, v)) != st.end()) { n       printf( %d %d %d n , u, v, 1 - w); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MaxN = 400007; n const int mod = (int)1e9 + 7; n int a, b, k, t, N; n int ans, f[MaxN], s[MaxN]; n int main() { n   int i, j; n   scanf( %d%d%d%d , &a, &b, &k, &t); n   f[2 * k * t + 1] = 1; n   N = 4 * k * t + 1; n   for (i = 1; i <= t + t; i++) { n     for (j = 1; j <= N; j++) { n       s[j] = (s[j - 1] + f[j]) % mod; n     } n     for (j = 1; j <= N; j++) { n       f[j] = (s[min(N - 1, j + k)] - s[max(1, j - k - 1)]) % mod; n       if (f[j] < 0) f[j] += mod; n     } n   } n   ans = 0; n   for (i = 2 * k * t + b - a + 2; i <= N; i++) ans = (ans + f[i]) % mod; n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool DEB = 0; n void __start__() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n } n mt19937_64 rnd(time(0)); n using ll = long long; n using vi = vector<int>; n using ld = long double; n using pii = pair<int, int>; n void test_case() { n   ll n, k, two, five, c = 1; n   cin >> n >> k; n   two = k; n   five = k; n   while (n % 2 == 0 && two) n /= 2, two--; n   while (n % 5 == 0 && five) n /= 5, five--; n   cout << n << string(k,  0 ); n } n signed main() { n   __start__(); n   int Q = 1; n   while (Q--) test_case(); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   vector<int> c(n); n   for (int i = 0; i < n; ++i) { n     scanf( %d , &c[i]); n   } n   vector<int> ans(n + 1, 0); n   for (int i = 0; i < n; ++i) { n     vector<int> mx(n + 1, 0); n     int p = 0; n     for (int k = i; k < n; ++k) { n       mx[c[k]] += 1; n       if (mx[c[k]] > mx[p]) { n         p = c[k]; n       } else if (mx[c[k]] == mx[p]) { n         p = min(p, c[k]); n       } n       ans[p] += 1; n     } n   } n   for (int i = 1; i <= n; ++i) { n     printf( %d  , ans[i]); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s; n   cin >> s; n   long long res = 1; n   long long mdl = 1000000000 + 7; n   long long s1 = s.size(); n   vector<long long> fibo(s1 + 1); n   fibo[0] = 1; n   fibo[1] = 1; n   for (long long i = 0; i < s1; i++) { n     if (s[i] ==  m  || s[i] ==  w ) { n       cout <<  0 ; n       return 0; n     } n   } n   for (long long j = 1; j < s1; j++) { n     long long z = 1; n     while ((j < s1) && ((s[j] == s[j - 1] && s[j] ==  u ) || n                         (s[j] == s[j - 1] && s[j] ==  n ))) { n       z++; n       j++; n     } n     long long i = 2; n     while (i <= z) { n       fibo[i] = (fibo[i - 1] + fibo[i - 2]) % mdl; n       i++; n     } n     res = (res * fibo[z]) % mdl; n   } n   cout << res; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char a[5005], b[5005]; n int la, lb; n int memo[5005][5005]; n int dp(int x, int y) { n   if (x == la || y == lb) n     return 0; n   else if (memo[x][y] != -1) { n     return memo[x][y]; n   } else { n     int ans1 = dp(x, y + 1) % 1000000007; n     int ans2 = 0; n     if (a[x] == b[y]) { n       ans2 = (dp(x + 1, y + 1) + 1) % 1000000007; n     } n     int ret = (ans1 + ans2) % 1000000007; n     return memo[x][y] = ret; n   } n } n int main() { n   scanf( %s %s , a, b); n   memset(memo, -1, sizeof(memo)); n   int i; n   la = strlen(a); n   lb = strlen(b); n   int ans = 0; n   for (i = 0; i < la; i++) { n     ans = (ans + dp(i, 0)) % 1000000007; n   } n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int a, b, n, s = 0, q = 0; n   cin >> a >> b >> n; n   for (int i = 1;; i++) { n     if (n != 0) { n       if (i % 2 == 1) { n         if (a >= n) { n           for (int j = n; j >= 1; j--) { n             if (a % j == 0 && n % j == 0) { n               n = n - j; n               break; n             } n           } n         } else { n           for (int j = a; j >= 1; j--) { n             if (a % j == 0 && n % j == 0) { n               n = n - j; n               break; n             } n           } n         } n       } else { n         if (n >= b) { n           for (int j = b; j >= 1; j--) { n             if (b % j == 0 && n % j == 0) { n               n = n - j; n               break; n             } n           } n         } else { n           for (int j = n; j >= 1; j--) { n             if (b % j == 0 && n % j == 0) { n               n = n - j; n               break; n             } n           } n         } n       } n     } n     if (n == 0) { n       cout << (i + 1) % 2; n       break; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int MOD = 1e9 + 7; n const int INF = 0x3f3f3f3f; n const int MAXN = 2005; n int n, m; n char maze[MAXN][MAXN]; n void Dfs(int x, int y) { n   if (x >= n - 1 || y >= m - 1 || x < 0 || y < 0) return; n   int xx, yy, s = 0; n   for (int i = 0; i < 2; ++i) n     for (int j = 0; j < 2; ++j) n       if (maze[x + i][y + j] ==  * ) { n         s++; n         xx = x + i; n         yy = y + j; n       } n   if (s == 1) { n     maze[xx][yy] =  . ; n     for (int i = -1; i < 1; ++i) n       for (int j = -1; j < 1; ++j) Dfs(xx + i, yy + j); n   } n } n int main(int argc, char const *argv[]) { n   scanf( %d %d , &n, &m); n   for (int i = 0; i < n; ++i) scanf( %s , maze[i]); n   for (int i = 0; i < n - 1; ++i) n     for (int j = 0; j < m - 1; ++j) Dfs(i, j); n   for (int i = 0; i < n; ++i) printf( %s n , maze[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> adj[200005]; n int visited[200005]; n int dfs(int u) { n   visited[u] = 1; n   int iscycle = ((adj[u].size() == 2) ? (1) : (0)); n   for (int i = 0; i < adj[u].size(); ++i) { n     if (visited[adj[u][i]] == 0 and dfs(adj[u][i]) == 0) iscycle = 0; n   } n   return iscycle; n } n int main() { n   int n, m; n   scanf( %d%d , &n, &m); n   for (int i = 0; i < m; ++i) { n     int u, v; n     scanf( %d%d , &u, &v); n     adj[u].push_back(v); n     adj[v].push_back(u); n   } n   for (int i = 0; i <= n; ++i) visited[i] = 0; n   int ans = 0; n   for (int i = 1; i <= n; ++i) n     if (visited[i] == 0) ans += dfs(i); n   printf( %d n , ans); n } n


#include <bits/stdc++.h> n using namespace std; n long long MOD = 1e9 + 7; n long long MOD1 = 1e9 + 123; n long long MOD2 = 1e9 + 321; n vector<int> fun(string &s) { n   int i; n   vector<int> v; n   for (i = 0; i + 1 < s.length(); i++) n     if (s[i] != s[i + 1]) v.push_back(i + 1); n   if (s[s.length() - 1] ==  1 ) v.push_back(s.length()); n   return v; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   ; n   long long t, a, n, q, k, i, l, m, c, u, f, j, p, r, x, y, s, b, d; n   cin >> t; n   while (t--) { n     cin >> n; n     string S, P; n     cin >> S >> P; n     vector<int> v1, v2; n     v1 = fun(S); n     v2 = fun(P); n     reverse(v2.begin(), v2.end()); n     cout << v1.size() + v2.size() <<    ; n     for (auto h : v1) cout << h <<    ; n     for (auto h : v2) cout << h <<    ; n     cout <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void solve() {} n int main() { n   long long a, b, c, d; n   cin >> a >> b >> c >> d; n   long long ans = 0; n   long long l = max(c, a + b); n   long long r = c + d + 1; n   for (long long i = l; i < r; i++) { n     long long che = min(i - c, d - c + 1); n     long long e1 = max(0LL, i - 2 * b); n     long long e2 = max(0LL, i - a - c); n     long long e3 = max(0LL, i - b - c - 1); n     long long e4 = (i - a - b + 1); n     ans += (che * (e4 - e1 - e2 + e3)); n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a[1000006]; n int n, k; n int max_a; n int has[20000007]; n bool judge(int num) { n   if (num == 1) return true; n   int cnt = 0; n   for (int i = 0; i < num * 2; i++) { n     has[i] = i / num; n   } n   for (int i = num * 2; i <= max_a; i++) { n     has[i] = has[i / 2] + has[i - i / 2]; n   } n   for (int i = 0; i < n; i++) { n     cnt += has[a[i]]; n     if (cnt >= k) { n       return true; n     } n   } n   return false; n } n int main() { n   while (scanf( %d%d , &n, &k) != EOF) { n     for (int i = 0; i < n; i++) { n       scanf( %d , &a[i]); n     } n     long long sum = 0; n     max_a = 0; n     for (int i = 0; i < n; i++) { n       sum += a[i]; n       if (a[i] > max_a) { n         max_a = a[i]; n       } n     } n     if (sum < k) { n       printf( -1 n ); n     } else { n       int l = 1, r = max_a + 1; n       while (l < r - 1) { n         int m = (l + r) / 2; n         if (judge(m)) { n           l = m; n         } else { n           r = m; n         } n       } n       while (judge(l)) { n         l++; n       } n       cout << l - 1 << endl; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int n, cnt; n char x[55]; n int main() { n   scanf( %s , x); n   n = strlen(x); n   for (int i = 0; i < n; i++) cnt += x[i] ==  a ; n   printf( %d n , min(n, cnt * 2 - 1)); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   cin >> t; n   while (t--) { n     long long int n; n     cin >> n; n     vector<long long int> arr; n     long long int num; n     for (int i = 0; i < n; i++) { n       cin >> num; n       arr.push_back(num); n     } n     sort(arr.begin(), arr.end()); n     long long int sum = 0; n     for (int i = 0; i < n - 1; i++) { n       if (arr[i] != arr[i + 1]) { n         sum++; n       } n     } n     cout << sum + 1 << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int num[150000]; n void Sum(int i, int op, int n, int &sum) { n   if (i != op && i > 0 && i <= n && op > 0 && op <= n) { n     swap(num[i], num[op]); n     if ((i & 1) && (op & 1)) { n       if ((i > 1 && num[i] < num[i - 1] || i == 1) && n           (i < n && num[i] < num[i + 1] || i == n) && n           (op == 1 || op > 1 && num[op] < num[op - 1]) && n           (op == n || op < n && num[op] < num[op + 1])) n         sum++; n     } else if (!(i & 1) && (op & 1)) { n       if ((i > 1 && num[i] > num[i - 1] || i == 1) && n           (i < n && num[i] > num[i + 1] || i == n) && n           (op == 1 || op > 1 && num[op] < num[op - 1]) && n           (op == n || op < n && num[op] < num[op + 1])) n         sum++; n     } else if ((i & 1) && !(op & 1)) { n       if ((i > 1 && num[i] < num[i - 1] || i == 1) && n           (i < n && num[i] < num[i + 1] || i == n) && n           (op == 1 || op > 1 && num[op] > num[op - 1]) && n           (op == n || op < n && num[op] > num[op + 1])) n         sum++; n     } else { n       if ((i > 1 && num[i] > num[i - 1] || i == 1) && n           (i < n && num[i] > num[i + 1] || i == n) && n           (op == 1 || op > 1 && num[op] > num[op - 1]) && n           (op == n || op < n && num[op] > num[op + 1])) n         sum++; n     } n     swap(num[i], num[op]); n   } n } n void Solve(int n, int minx[], int mins, int &sum) { n   if (mins == 0) { n     int op = minx[0]; n     for (int i = 1; i <= n; i++) Sum(i, op, n, sum); n     op++; n     if (op <= n) { n       for (int i = 1; i <= n; i++) Sum(i, op, n, sum); n     } n     int sum1 = sum; n     Sum(minx[0], minx[0] + 1, n, sum); n     if (sum1 < sum) sum -= 2; n   } else if (mins == 1) { n     if (minx[0] + 1 == minx[1]) { n       Sum(minx[0], minx[1] + 1, n, sum); n       for (int i = 1; i <= n; i++) Sum(i, minx[1], n, sum); n     } else { n       Sum(minx[0], minx[1], n, sum); n       Sum(minx[0], minx[1] + 1, n, sum); n       Sum(minx[0] + 1, minx[1], n, sum); n       Sum(minx[0] + 1, minx[1] + 1, n, sum); n     } n   } else if (mins == 2) { n     if (minx[0] + 1 == minx[1] && minx[1] + 1 == minx[2]) { n       Sum(minx[0], minx[2], n, sum); n       Sum(minx[1], minx[2], n, sum); n       Sum(minx[1], minx[2] + 1, n, sum); n     } else if (minx[0] + 1 == minx[1]) { n       Sum(minx[1], minx[2], n, sum); n       Sum(minx[1], minx[2] + 1, n, sum); n     } else if (minx[1] + 1 == minx[2]) { n       Sum(minx[0], minx[2], n, sum); n       Sum(minx[0] + 1, minx[2], n, sum); n     } n   } else if (minx[0] + 1 == minx[1] && minx[2] + 1 == minx[3]) { n     Sum(minx[1], minx[3], n, sum); n   } n } n int main() { n   int n; n   while (~scanf( %d , &n) && n) { n     int sum = 0; n     for (int i = 1; i <= n; i++) scanf( %d , &num[i]); n     int minx[110], mins = -1; n     for (int i = 1; i <= n - 1; i++) { n       if (i & 1) { n         if (num[i] >= num[i + 1] && mins < 100) minx[++mins] = i; n       } else { n         if (num[i] <= num[i + 1] && mins < 100) minx[++mins] = i; n       } n     } n     if (mins >= 4 || mins < 0) n       printf( 0 n ); n     else { n       Solve(n, minx, mins, sum); n       printf( %d n , sum); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const inline int __GET_INT() { n   int ret; n   scanf( %d , &ret); n   return ret; n } n int main() { n   long long A = __GET_INT(), B = __GET_INT(), n = __GET_INT(); n   for (int i = 0; i < n; ++i) { n     long long l = __GET_INT(), t = __GET_INT(), m = __GET_INT(); n     long long first = B * (l - 1) + A; n     if (first > t) { n       puts( -1 ); n     } else { n       int r = -1; n       long long low = 1, high = 1000000, mid; n       while (low <= high) { n         mid = (low + high) >> 1; n         long long val = ((mid * (mid - 1)) / 2) * B + mid * first; n         long long second = B * (l + mid - 2) + A; n         if (second > t || val > (t * m)) { n           high = mid - 1; n         } else { n           low = mid + 1; n           r = l + mid - 1; n         } n       } n       printf( %d n , r); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a[1005], b[1005]; n char c[1005][1005]; n int main() { n   int n, m; n   cin >> n >> m; n   int cnt = 0; n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= m; j++) { n       cin >> c[i][j]; n       if (c[i][j] ==  * ) { n         a[i]++; n         b[j]++; n         cnt++; n       } n     } n   } n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= m; j++) { n       if (c[i][j] ==  * ) { n         if (a[i] + b[j] - 1 == cnt) return cout <<  YES n  << i <<     << j, 0; n       } else { n         if (a[i] + b[j] == cnt) return cout <<  YES n  << i <<     << j, 0; n       } n     } n   } n   cout <<  NO ; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, A, B, C = 1; n const long long E = 1e9 + 7; n int main() { n   cin >> n; n   if (n <= 1) { n     cout << 0 << endl; n     return 0; n   } n   for (long long i = 2; i < n; i++) { n     A = B; n     B = C; n     C = 2 * B + 3 * A; n     C %= E; n   } n   long long ans = (3 * C) % E; n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int M = 1e9 + 7; n int main() { n   long long int i, t, a = 0, k, b = 0, j = 0, l = 0, n, m, r = 0, c = 0, ct = 0, n                       pos = 0, neg = 0, flag = 0, x, y, space, maxi, n                       ans = 999999, ans2 = -100, avg, sum = 0; n   double d; n   long long int ar1[100005] = {0}, ar2[100005] = {0}; n   ios_base::sync_with_stdio(0); n   cin.tie(NULL); n   cout.tie(NULL); n   long long int ch, temp = 0; n   vector<long long int> v; n   string st, st2, st3; n   stack<char> s; n   vector<pair<string, string> > vp; n   queue<pair<long long int, long long int> > q; n   cin >> n; n   cout << 2 * n - 1 <<     << 2 << endl << 1 <<     << 2; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n set<int> s[300000]; n int ans[300000]; n bool vis[300000]; n int nr[500000]; n int main() { n   int n, m; n   scanf( %d %d , &n, &m); n   priority_queue<pair<int, int> > pq; n   for (int i = 0; i <= 2 * m; i++) nr[i] = -1; n   for (int i = 0; i < n; i++) { n     int k, x; n     scanf( %d , &k); n     while (k--) { n       scanf( %d , &x); n       nr[x + m] = i; n       s[i].insert(x); n     } n     pq.push(make_pair(-s[i].size(), i)); n   } n   while (!pq.empty()) { n     int k = pq.top().second; n     pq.pop(); n     if (vis[k]) continue; n     vis[k] = true; n     if (s[k].empty()) { n       puts( NO ); n       return 0; n     } n     int x = *s[k].begin(); n     if (x > 0) ans[x] = 1; n     if (nr[m - x] != -1) { n       s[nr[m - x]].erase(-x); n       pq.push(make_pair(-s[nr[m - x]].size(), nr[m - x])); n     } n   } n   puts( YES ); n   for (int i = 1; i <= m; i++) printf( %d , ans[i]); n   puts(  ); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m; n   cin >> n >> m; n   if (m == 3 && n >= 5) n     cout << -1 << endl; n   else { n     if (m == 3 && n == 4) n       puts( -1 0 n1 0 n0 2 n0 1 ); n     else { n       for (int i = 1; i <= m; i++) cout << i <<     << i * i + 343231 << endl; n       n -= m; n       for (int i = 1; i <= n; i++) n         cout << i <<     << -(i * i + 343231) << endl; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m; n   cin >> n >> m; n   int s[n]; n   int f[10] = {0}; n   for (int i = 0; i < n; i++) { n     cin >> s[i]; n   } n   int tmp; n   for (int j = 0; j < m; j++) { n     cin >> tmp; n     f[tmp] = 1; n   } n   int emp = 1; n   for (int i = 0; i < n; i++) { n     if (f[s[i]] == 1) { n       emp = 0; n       cout << s[i] <<    ; n     } n   } n   if (emp == 1) cout <<   n ; n } n


#include <bits/stdc++.h> n const int maxn = 3e5 + 3; n int n, a[maxn], b[maxn], m, l[maxn], r[maxn]; n void solve() { n   scanf( %d , &n); n   m = 0; n   for (int i = 0; i < n; ++i) { n     scanf( %d , a + i); n     b[m++] = a[i]; n   } n   std::sort(b, b + m); n   m = std::unique(b, b + m) - b; n   for (int i = 0; i < n; ++i) { n     a[i] = std::lower_bound(b, b + m, a[i]) - b; n   } n   std::fill(l, l + m, 0x7fffffff); n   std::fill(r, r + m, 0x80000000); n   for (int i = 0; i < n; ++i) { n     l[a[i]] = std::min(l[a[i]], i); n     r[a[i]] = std::max(r[a[i]], i); n   } n   int ans = m - 1; n   for (int i = 0, j; i < m; i = j) { n     for (j = i + 1; j < m && r[j - 1] < l[j]; ++j) n       ; n     ans = std::min(ans, i + (m - j)); n   } n   printf( %d n , ans); n } n int main() { n   int t; n   scanf( %d , &t); n   while (t--) solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int Q = 9, R = 5, B = 3, N = 3, P = 1, q = 9, r = 5, b = 3, n = 3, p = 1; n   int sum2 = 0, Sum2 = 0; n   char c[64]; n   for (int i = 0; i < 64; i++) { n     cin >> c[i]; n   } n   for (int i = 0; i < 64; i++) { n     switch (c[i]) { n       case  q : n         sum2 += q; n         break; n       case  r : n         sum2 += r; n         break; n       case  b : n         sum2 += b; n         break; n       case  n : n         sum2 += n; n         break; n       case  p : n         sum2 += p; n         break; n       case  Q : n         Sum2 += Q; n         break; n       case  R : n         Sum2 += R; n         break; n       case  B : n         Sum2 += B; n         break; n       case  N : n         Sum2 += N; n         break; n       case  P : n         Sum2 += P; n         break; n     } n   } n   if (sum2 > Sum2) n     cout <<  Black ; n   else if (sum2 < Sum2) n     cout <<  White ; n   else n     cout <<  Draw ; n } n


#include <bits/stdc++.h> n using namespace std; n const long long INF = 1e9 + 10; n const long long MN = 5e2 + 10; n long long n, m, a[MN], b[MN]; n vector<pair<long long, char> > ans; n long long lz = 0; n bool fl = false; n void fail() { n   cout <<  NO n ; n   exit(0); n } n long long get(long long l, long long r) { n   long long mx = *max_element(a + l, a + r + 1); n   if (a[l] == mx) { n     fl = true; n     long long ret = l; n     for (; a[ret] == mx; ++ret) n       ; n     return ret - 1; n   } n   long long ret = l; n   for (; a[ret] != mx; ++ret) n     ; n   return ret; n } n int32_t main() { n   ios_base ::sync_with_stdio(false), cin.tie(0), cout.tie(0); n   cin >> n; n   for (long long i = 0; i < n; ++i) cin >> a[i]; n   cin >> m; n   for (long long i = 0; i < m; ++i) cin >> b[i]; n   long long cur = 0; n   long long p = 0; n   long long lst = 0; n   for (long long i = 0; i < n; ++i) { n     cur += a[i]; n     if (cur == b[p] && p < m) { n       if (i == lst) { n         ++p, cur = 0, lst = i + 1; n         continue; n       } n       if (*max_element(a + lst, a + i + 1) == *min_element(a + lst, a + i + 1)) n         fail(); n       ++p; n       fl = false; n       long long ind = get(lst, i); n       if (fl) { n         for (long long j = 0; j < (i - ind); ++j) n           ans.push_back(make_pair(ind - lz,  R )); n         for (long long j = ind - 1; j >= lst; --j) { n           ans.push_back(make_pair(ind - lz,  L )); n           ++lz; n         } n         lz += (i - ind); n       } else { n         for (long long j = ind - 1; j >= lst; --j) { n           ans.push_back(make_pair(ind - lz,  L )); n           ++lz; n         } n         for (long long j = 0; j < (i - ind); ++j) n           ans.push_back(make_pair(ind - lz,  R )); n         lz += i - ind; n       } n       cur = 0; n       lst = i + 1; n     } n   } n   if (cur || p < m) fail(); n   cout <<  YES n ; n   for (auto v : ans) cout << v.first + 1 <<     << v.second << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long int gcd(long long int a, long long int b) { n   if (b == 0) return a; n   return gcd(b, a % b); n } n long long int lcm(long long int a, long long int b) { n   return a * b / gcd(a, b); n } n long long int fexp(long long int a, long long int b) { n   long long int ans = 1; n   while (b) { n     if (b & 1) ans = ans * a % 998244353; n     b /= 2; n     a = a * a % 998244353; n   } n   return ans; n } n long long int inverse(long long int a, long long int p) { n   return fexp(a, p - 2); n } n void solve() { n   string s; n   cin >> s; n   long long int n = (long long int)s.size(); n   long long int ans = 1e9 + 5; n   set<long long int> st; n   long long int cnt = 0; n   vector<long long int> vec(4, 0); n   long long int fir = s[0] -  0 , num = 0; n   for (long long int i = 0; i < n; i++) { n     cnt = 0; n     long long int idx = s[i] -  0 ; n     if (idx == fir && i != num) { n       vec[fir] = 1; n       st.insert(idx); n       fir = s[i - 1] -  0 ; n       continue; n     } n     st.insert(idx); n     vec[idx]++; n     if ((long long int)st.size() == 3) { n       cnt = vec[s[i - 1] -  0 ] + 2; n       ans = min(ans, cnt); n       st.erase(fir); n       vec[fir] = 0; n       vec[s[i - 1] -  0 ] = 1; n       fir = s[i - 1] -  0 ; n       num = i - 1; n     } n   } n   if (ans == 1e9 + 5) { n     cout << 0 <<   n ; n     return; n   } n   cout << ans <<   n ; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long int t; n   cin >> t; n   while (t--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2005; n vector<pair<int, int> > v[N * N]; n bool flag[N * N], a[N][N], vis[N][N]; n pair<int, int> dis[N * N]; n int id[N][N], q[N * N], ID, n, m, r, c, sx, sy, ans; n char s[N]; n void bfs(int r, int c) { n   int L = 0, R = 0; n   q[R++] = id[r][c]; n   flag[id[r][c]] = true; n   dis[id[r][c]] = make_pair(0, 0); n   while (L < R) { n     int u = q[L++], sz = v[u].size(); n     for (int i = 0; i < sz; i++) { n       int x = v[u][i].first, y = v[u][i].second; n       if (y > 1 && a[x][y - 1] && !flag[id[x][y - 1]]) { n         q[R++] = id[x][y - 1]; n         flag[id[x][y - 1]] = true; n         dis[id[x][y - 1]] = make_pair(dis[u].first + 1, dis[u].second); n       } n       if (y < m && a[x][y + 1] && !flag[id[x][y + 1]]) { n         q[R++] = id[x][y + 1]; n         flag[id[x][y + 1]] = true; n         dis[id[x][y + 1]] = make_pair(dis[u].first, dis[u].second + 1); n       } n     } n   } n } n void dfs(int x, int y, int z) { n   vis[x][y] = true; n   id[x][y] = z; n   v[z].push_back(make_pair(x, y)); n   if (x > 1 && a[x - 1][y] && !vis[x - 1][y]) dfs(x - 1, y, z); n   if (x < n && a[x + 1][y] && !vis[x + 1][y]) dfs(x + 1, y, z); n } n int main() { n   memset(dis, 0x3f, sizeof(dis)); n   scanf( %d%d%d%d%d%d , &n, &m, &r, &c, &sx, &sy); n   for (int i = 1; i <= n; i++) { n     scanf( %s , s + 1); n     for (int j = 1; j <= m; j++) a[i][j] = (s[j] ==  . ); n   } n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= m; j++) n       if (a[i][j] && !vis[i][j]) ID++, dfs(i, j, ID); n   bfs(r, c); n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= m; j++) n       if (a[i][j]) { n         int u = id[i][j]; n         if (dis[u].first <= sx && dis[u].second <= sy) ans++; n       } n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n using P = pair<int, int>; n const long long MOD = 1000000007; n const long long INF = 1LL << 60; n const int INT_INF = 1000000000; n int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}; n void solve() { n   int n; n   cin >> n; n   vector<ll> a(n); n   for (auto &ai : a) cin >> ai; n   bool positive; n   if (a[0] < 0) n     positive = false; n   else n     positive = true; n   ll sum = 0; n   ll tmp = a[0]; n   for (int i = 1; i < n; i++) { n     if (positive) { n       if (a[i] > 0) { n         tmp = max(tmp, a[i]); n       } else { n         sum += tmp; n         tmp = a[i]; n         positive = false; n       } n     } else { n       if (a[i] > 0) { n         sum += tmp; n         tmp = a[i]; n         positive = true; n       } else { n         tmp = max(tmp, a[i]); n       } n     } n   } n   sum += tmp; n   cout << sum << endl; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(nullptr); n   int t; n   cin >> t; n   for (int i = 0; i < t; i++) solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int gcd(int a, int b) { n   if (a == 0) { n     return b; n   } n   return gcd(b % a, a); n } n int idx[200001] = {0}; n vector<int> g[160]; n int dp[160][100001] = {0}; n int len[160][200001] = {0}; n int nless(vector<int>& v, int val) { n   if (!(int)v.size()) return 0; n   if (v[0] > val) return 0; n   int l = 0, r = (int)v.size() - 1; n   while (r - l + 1 > 2) { n     int x = (l + r) / 2; n     if (v[x] > val) { n       r = x; n     } else { n       l = x; n     } n   } n   if (r - l + 1 == 2) { n     if (v[r] <= val) { n       return r + 1; n     } else { n       return l + 1; n     } n   } n   if (r - l + 1 == 1) { n     return l + 1; n   } n } n void solve() { n   int n; n   cin >> n; n   vector<int> v(n); n   for (int j = 0; j < n; j++) cin >> v[j]; n   int num = 1; n   vector<int> factors; n   factors.push_back(1); n   for (int j = 2; j <= sqrt(n); j++) { n     if (n % j == 0) { n       factors.push_back(j); n       num++; n       if (j * j != n) { n         factors.push_back(n / j); n         num++; n       } n     } n   } n   sort(factors.begin(), factors.end()); n   for (int j = 0; j < (int)factors.size(); j++) { n     idx[factors[j]] = j; n   } n   for (int j = 1; j < n; j++) { n     g[idx[gcd(j, n)]].push_back(j); n   } n   for (int j = n - 1; j >= 0; j--) { n     for (int i = 0; i < num; i++) { n       dp[i][j % factors[i]] = max(dp[i][j % factors[i]], v[j]); n     } n   } n   for (int j = n - 1; j >= 0; j--) { n     for (int i = 0; i < num; i++) { n       len[i][j] = (v[j] == dp[i][j % factors[i]]) * (1 + len[i][j + 1]); n     } n   } n   for (int j = n - 1; j >= 0; j--) { n     for (int i = 0; i < num; i++) { n       len[i][j] = min( n           n - 1, (v[j] == dp[i][j % factors[i]]) * (1 + len[i][(j + 1) % n])); n     } n   } n   long long int ans = 0; n   for (int j = 0; j < n; j++) { n     for (int i = 0; i < num; i++) { n       int cnt = nless(g[i], len[i][j]); n       ans += cnt; n     } n   } n   cout << ans <<   n ; n   return; n } n signed main() { n   ios::sync_with_stdio(0); n   cin.tie(NULL); n   cout.tie(NULL); n   int t; n   t = 1; n   while (t--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 2 * 1000 + 5; n const long long INF = 1000ll * 1000 * 1000 * 1000 * 1000 * 1000; n int n, k, dp[maxn], a[maxn]; n bool check(long long x) { n   for (int i = 1; i <= n; i++) { n     dp[i] = i - 1; n     for (int j = 1; j < i; j++) { n       if (abs(a[i] - a[j]) <= (i - j) * x) n         dp[i] = min(dp[i], dp[j] + i - j - 1); n       if (dp[i] + n - i <= k) return true; n     } n   } n   return false; n } n int main() { n   cin >> n >> k; n   for (int i = 1; i <= n; i++) cin >> a[i]; n   if (n == 1) { n     cout << 0 << endl; n     return 0; n   } n   long long l = -1, r = INF + 1, mid; n   while (r - l > 1) { n     mid = (l + r) >> 1; n     if (check(mid)) n       r = mid; n     else n       l = mid; n   } n   cout << r << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   int arr[n]; n   int i = 0; n   int cnt[101] = {0}; n   for (int i = 0; i < n; i++) { n     cin >> arr[i]; n     cnt[arr[i]]++; n   } n   int a = -1, b = -1; n   for (int i = 0; i <= 100; i++) { n     if (cnt[i] == n / 2) { n       if (a == -1) n         a = i; n       else n         b = i; n     } n   } n   if (a != -1 && b != -1) { n     cout <<  YES n ; n     cout << a <<     << b; n   } else n     cout <<  NO n ; n   return 0; n } n


#include <bits/stdc++.h> n const int MAXN = 2020; n int n, m; n int mp[MAXN][MAXN], realx[MAXN], realy[MAXN], cntx, cnty; n char dir[MAXN]; n int len[MAXN]; n void unique(int *real, int &cnt) { n   std::sort(real, real + cnt); n   int t2 = 1; n   for (int t1 = 1; t1 < cnt; t1++) n     if (real[t1] ^ real[t1 - 1]) real[t2++] = real[t1]; n   cnt = t2; n } n inline bool legal(int x, int y) { n   return x >= 0 && x <= cntx && y >= 0 && y <= cnty; n } n void dfs(int x, int y) { n   mp[x][y] = -1; n   if (legal(x + 1, y) && !mp[x + 1][y]) dfs(x + 1, y); n   if (legal(x - 1, y) && !mp[x - 1][y]) dfs(x - 1, y); n   if (legal(x, y + 1) && !mp[x][y + 1]) dfs(x, y + 1); n   if (legal(x, y - 1) && !mp[x][y - 1]) dfs(x, y - 1); n } n int main() { n   scanf( %d , &n); n   register int nowx = 0, nowy = 0; n   for (int i = 1; i <= n; i++) { n     scanf( %s%d , dir + i, len + i); n     switch (dir[i]) { n       case  L : n         realx[cntx++] = nowx + 1; n         realx[cntx++] = nowx -= len[i]; n         realy[cnty++] = nowy; n         realy[cnty++] = nowy + 1; n         break; n       case  R : n         realx[cntx++] = nowx; n         realx[cntx++] = (nowx += len[i]) + 1; n         realy[cnty++] = nowy; n         realy[cnty++] = nowy + 1; n         break; n       case  U : n         realy[cnty++] = nowy; n         realy[cnty++] = (nowy += len[i]) + 1; n         realx[cntx++] = nowx; n         realx[cntx++] = nowx + 1; n         break; n       case  D : n         realy[cnty++] = nowy + 1; n         realy[cnty++] = nowy -= len[i]; n         realx[cntx++] = nowx; n         realx[cntx++] = nowx + 1; n         break; n     } n   } n   unique(realx, cntx); n   unique(realy, cnty); n   int curx = std::upper_bound(realx, realx + cntx, nowx = 0) - realx, n       cury = std::upper_bound(realy, realy + cnty, nowy = 0) - realy, nxt; n   for (int i = 1; i <= n; i++) { n     switch (dir[i]) { n       case  L : n         nxt = std::upper_bound(realx, realx + cntx, nowx -= len[i]) - realx; n         while (curx > nxt) mp[curx--][cury] = 1; n         break; n       case  R : n         nxt = std::upper_bound(realx, realx + cntx, nowx += len[i]) - realx; n         while (curx < nxt) mp[curx++][cury] = 1; n         break; n       case  U : n         nxt = std::upper_bound(realy, realy + cnty, nowy += len[i]) - realy; n         while (cury < nxt) mp[curx][cury++] = 1; n         break; n       case  D : n         nxt = std::upper_bound(realy, realy + cnty, nowy -= len[i]) - realy; n         while (cury > nxt) mp[curx][cury--] = 1; n         break; n     } n   } n   mp[curx][cury] = 1; n   for (int i = 0; i <= cntx; i++) { n     if (!mp[i][cnty]) dfs(i, cnty); n     if (!mp[i][0]) dfs(i, 0); n   } n   for (int i = 1; i < cnty; i++) { n     if (!mp[cntx][i]) dfs(cntx, i); n     if (!mp[0][i]) dfs(0, i); n   } n   long long ans = 0; n   for (int i = 1; i <= cntx; i++) n     for (int j = 1; j <= cnty; j++) n       if (~mp[i][j]) n         ans += 1ll * (realx[i] - realx[i - 1]) * (realy[j] - realy[j - 1]); n   printf( %lld n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char func(char c) { n   if (c >=  A  && c <=  Z ) c = tolower(c); n   if (c ==  o ) n     c =  0 ; n   else if (c ==  l  || c ==  i ) n     c =  1 ; n   return c; n } n int main() { n   string s; n   int n; n   cin >> s >> n; n   for (int i = 0; i < n; i++) { n     string str; n     cin >> str; n     if (str.size() != s.size()) continue; n     bool ok = true; n     for (int j = 0; j < s.size(); j++) { n       if (func(s[j]) != func(str[j])) { n         ok = false; n         break; n       } n     } n     if (ok) { n       cout <<  No ; n       return 0; n     } n   } n   cout <<  Yes ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long P = (long long)1e9 + 7; n int n, k; n int a[2]; n long long c[60][60]; n long long cnt[60][60]; n int dp[60][60]; n struct rmdr { n   int i, j; n   bool operator<(const rmdr& a) const { n     if (50 * i + 100 * j != 50 * a.i + 100 * a.j) n       return 50 * i + 100 * j < 50 * a.i + 100 * a.j; n     return i > a.i; n   } n }; n rmdr r[100010]; n int sz = 0; n int main() { n   cin >> n >> k; n   a[0] = a[1] = 0; n   for (int i = 0; i < int(n); ++i) { n     int tmp; n     cin >> tmp; n     if (tmp == 50) n       a[0]++; n     else n       a[1]++; n   } n   memset(c, 0, sizeof(c)); n   c[0][0] = 1; n   for (int i = int(1); i < int(n + 1); ++i) { n     c[i][0] = 1; n     for (int j = int(1); j < int(i + 1); ++j) n       c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % P; n   } n   memset(cnt, 0, sizeof(cnt)); n   for (int i = 0; i < int(a[0] + 1); ++i) n     for (int j = 0; j < int(a[1] + 1); ++j) dp[i][j] = 100500; n   dp[0][0] = 0; n   cnt[0][0] = 1; n   for (int i = 0; i < int(a[0] + 1); ++i) n     for (int j = 0; j < int(a[1] + 1); ++j) { n       if (i == 0 && j == 0) continue; n       r[sz].i = i, r[sz].j = j; n       sz++; n     } n   sort(r, r + sz); n   for (int z = 0; z < int(sz); ++z) { n     int i = r[z].i, j = r[z].j; n     if (50 * i + 100 * j <= k) { n       dp[i][j] = 1; n       cnt[i][j] = 1; n       continue; n     } n     for (int i1 = 0; i1 < int(i + 1); ++i1) n       for (int j1 = 0; j1 < int(j + 1); ++j1) { n         if (i1 == 0 && j1 == 0) continue; n         if (50 * i1 + 100 * j1 > k) break; n         for (int i2 = 0; i2 < int(a[0] - i + i1 + 1); ++i2) n           for (int j2 = 0; j2 < int(a[1] - j + j1 + 1); ++j2) { n             if (i2 == 0 && j2 == 0) continue; n             if (50 * i2 + 100 * j2 > k) break; n             if (dp[i][j] >= dp[i - i1 + i2][j - j1 + j2] + 2) { n               long long tmp = (cnt[i - i1 + i2][j - j1 + j2] * c[i][i1]) % P; n               tmp = (tmp * c[j][j1]) % P; n               tmp = (tmp * c[a[0] - i + i1][i2]) % P; n               tmp = (tmp * c[a[1] - j + j1][j2]) % P; n               if (dp[i][j] > dp[i - i1 + i2][j - j1 + j2] + 2) { n                 dp[i][j] = dp[i - i1 + i2][j - j1 + j2] + 2; n                 cnt[i][j] = tmp; n               } else n                 cnt[i][j] = (cnt[i][j] + tmp) % P; n             } n           } n       } n   } n   if (dp[a[0]][a[1]] == 100500) { n     printf( -1 n0 n ); n   } else { n     printf( %d n%d n , dp[a[0]][a[1]], int(cnt[a[0]][a[1]])); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = 1e5 + 5; n const long long inf = -1; n const long long m = 1e6; n vector<long long> prime; n bool sieve[m + 2]; n void primeSieve() { n   memset(sieve, true, sizeof(sieve)); n   sieve[0] = sieve[1] = false; n   prime.push_back(2); n   for (long long i = 4; i <= m; i += 2) sieve[i] = false; n   long long sqrtn = sqrt(m); n   for (long long i = 3; i <= sqrtn; i += 2) { n     if (sieve[i]) { n       for (long long j = i * i; j <= m; j += 2 * i) sieve[j] = false; n     } n   } n   for (long long i = 3; i <= m; i += 2) n     if (sieve[i]) prime.push_back(i); n } n map<pair<long long, long long>, long long> use; n signed main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   primeSieve(); n   long long n, m, i; n   cin >> n >> m; n   long long pos = n       upper_bound(prime.begin(), prime.end(), n - 2) - prime.begin(); n   long long need = prime[pos] - (n - 2); n   vector<pair<long long, pair<long long, long long>>> v; n   long long x = 1; n   for (i = 1; i < n; i++) { n     if (i + 1 == n) x = need; n     v.push_back(make_pair(i, make_pair(i + 1, x))); n     use[make_pair(i, i + 1)] = 1; n   } n   long long sum = (n - 2) + need; n   m -= (n - 1); n   for (i = 1; i < n; i++) { n     if (m == 0) break; n     for (long long j = i + 1; j <= n; j++) { n       if (m == 0) break; n       if (!use[make_pair(i, j)] and m) { n         v.push_back(make_pair(i, make_pair(j, mod))); n         m--; n         use[make_pair(i, j)] = 1; n       } n     } n   } n   cout << sum <<     << sum << endl; n   for (auto p : v) { n     cout << p.first <<     << (p.second).first <<     << (p.second).second n          << endl; n   } n } n


#include <bits/stdc++.h> n #pragma GCC optimize( O3 ) n using namespace std; n using ll = long long; n using ld = long double; n using pi = pair<int, int>; n using pl = pair<ll, ll>; n using vi = vector<int>; n using vl = vector<ll>; n using vpi = vector<pi>; n using si = set<int>; n using sl = set<ll>; n using qi = queue<int>; n using ql = queue<ll>; n template <class T> n bool uin(T& a, T b) { n   return a > b ? (a = b, true) : false; n } n template <class T> n bool uax(T& a, T b) { n   return a < b ? (a = b, true) : false; n } n template <class T> n bool uin(T& u, T& v, T a, T b) { n   return v - u > b - a ? (u = a, v = b, true) : false; n } n template <class T> n bool uax(T& u, T& v, T a, T b) { n   return v - u < b - a ? (u = a, v = b, true) : false; n } n namespace input { n template <class T> n void re(complex<T>& x); n template <class T1, class T2> n void re(pair<T1, T2>& p); n template <class T> n void re(vector<T>& a); n template <class T, size_t SZ> n void re(array<T, SZ>& a); n template <class T> n void re(T& x) { n   cin >> x; n } n void re(double& x) { n   string t; n   re(t); n   x = stod(t); n } n void re(ld& x) { n   string t; n   re(t); n   x = stold(t); n } n template <class T, class... Ts> n void re(T& t, Ts&... ts) { n   re(t); n   re(ts...); n } n template <class T> n void re(complex<T>& x) { n   T a, b; n   re(a, b); n   x = cd(a, b); n } n template <class T1, class T2> n void re(pair<T1, T2>& p) { n   re(p.f, p.s); n } n template <class T> n void re(vector<T>& a) { n   for (int i = 0; i < (((int)(a).size())); ++i) re(a[i]); n } n template <class T, size_t SZ> n void re(array<T, SZ>& a) { n   for (int i = 0; i < (SZ); ++i) re(a[i]); n } n }  // namespace input n using namespace input; n namespace output { n void pr(int x) { cout << x; } n void pr(long x) { cout << x; } n void pr(ll x) { cout << x; } n void pr(unsigned x) { cout << x; } n void pr(unsigned long x) { cout << x; } n void pr(unsigned long long x) { cout << x; } n void pr(float x) { cout << x; } n void pr(double x) { cout << x; } n void pr(ld x) { cout << x; } n void pr(char x) { cout << x; } n void pr(const char* x) { cout << x; } n void pr(const string& x) { cout << x; } n void pr(bool x) { pr(x ?  true  :  false ); } n template <class T> n void pr(const complex<T>& x) { n   cout << x; n } n template <class T1, class T2> n void pr(const pair<T1, T2>& x); n template <class T> n void pr(const T& x); n template <class T, class... Ts> n void pr(const T& t, const Ts&... ts) { n   pr(t); n   pr(ts...); n } n template <class T1, class T2> n void pr(const pair<T1, T2>& x) { n   pr( { , x.f,  ,  , x.s,  } ); n } n template <class T> n void pr(const T& x) { n   pr( { ); n   bool fst = 1; n   for (const auto& a : x) pr(!fst ?  ,   :   , a), fst = 0; n   pr( } ); n } n void ps() { pr(  n ); } n template <class T, class... Ts> n void ps(const T& t, const Ts&... ts) { n   pr(t); n   if (sizeof...(ts)) pr(   ); n   ps(ts...); n } n void pc() { pr( ] n ); } n template <class T, class... Ts> n void pc(const T& t, const Ts&... ts) { n   pr(t); n   if (sizeof...(ts)) pr( ,  ); n   pc(ts...); n } n }  // namespace output n using namespace output; n inline int bs(bool (*valid)(int), int l, int r, bool order) { n   l--, r++; n   if (!order) swap(l, r); n   while (abs(r - l) > 1) { n     int mid = (l + r) >> 1; n     if (valid(mid)) n       r = mid; n     else n       l = mid; n   } n   valid(r); n   return r; n } n struct dsu { n   vector<int> p; n   dsu(int n) { p.resize(n + 1); } n   inline int get(int x) { return p[x] ? p[x] = get(p[x]) : x; } n   inline bool mrg(int x, int y) { n     return get(x) == get(y) ? false : p[get(x)] = get(y); n   } n }; n const int M = 1e9 + 7; n const ll lnf = 1e18 + 3; n const int inf = 1e9 + 3; n const int nax = 1e6 + 5; n typedef decay<decltype(M)>::type T; n struct mi { n   T val; n   explicit operator T() const { return val; } n   mi() { val = 0; } n   mi(const ll& v) { n     val = (-M <= v && v <= M) ? v : v % M; n     if (val < 0) val += M; n   } n   friend void pr(const mi& a) { pr(a.val); } n   friend void re(mi& a) { n     ll x; n     re(x); n     a = mi(x); n   } n   friend bool operator==(const mi& a, const mi& b) { return a.val == b.val; } n   friend bool operator!=(const mi& a, const mi& b) { return !(a == b); } n   friend bool operator<(const mi& a, const mi& b) { return a.val < b.val; } n   mi operator-() const { return mi(-val); } n   mi& operator+=(const mi& m) { n     if ((val += m.val) >= M) val -= M; n     return *this; n   } n   mi& operator-=(const mi& m) { n     if ((val -= m.val) < 0) val += M; n     return *this; n   } n   mi& operator*=(const mi& m) { n     val = (ll)val * m.val % M; n     return *this; n   } n   friend mi pow(mi a, ll p) { n     mi ans = 1; n     assert(p >= 0); n     for (; p; p /= 2, a *= a) n       if (p & 1) ans *= a; n     return ans; n   } n   friend mi inv(const mi& a) { n     assert(a != 0); n     return pow(a, M - 2); n   } n   mi& operator/=(const mi& m) { return (*this) *= inv(m); } n   friend mi operator+(mi a, const mi& b) { return a += b; } n   friend mi operator-(mi a, const mi& b) { return a -= b; } n   friend mi operator*(mi a, const mi& b) { return a *= b; } n   friend mi operator/(mi a, const mi& b) { return a /= b; } n }; n vi invs, fac, ifac; n void genFac(int SZ) { n   invs.resize(SZ), fac.resize(SZ), ifac.resize(SZ); n   invs[1] = fac[0] = ifac[0] = 1; n   for (int i = (2); i <= (SZ - 1); ++i) n     invs[i] = M - (ll)M / i * invs[M % i] % M; n   for (int i = (1); i <= (SZ - 1); ++i) { n     fac[i] = (ll)fac[i - 1] * i % M; n     ifac[i] = (ll)ifac[i - 1] * invs[i] % M; n   } n } n ll comb(int a, int b) { n   if (a < b || b < 0) return 0; n   return (ll)fac[a] * ifac[b] % M * ifac[a - b] % M; n } n ll p[nax], s, c; n int t, n, q[nax]; n int main() { n   ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); n   re(n); n   vl a(n); n   re(a); n   for (int i = 0; i < (n); ++i) { n     s = a[i], c = 1; n     while (t && p[t] * c >= s * q[t]) s += p[t], c += q[t--]; n     p[++t] = s, q[t] = c; n   } n   for (int i = (1); i <= (t); ++i) n     for (int j = 0; j < (q[i]); ++j) printf( %.9f n , (double)p[i] / q[i]); n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = 2000000005; n const int maxt = (1 << 20) + 5; n int all[maxt], dp[2][maxt]; n int best[30], a[30][30]; n int mask[30][30], cost[30][30]; n char str[30][30]; n int n, m; n int main() { n   scanf( %d%d , &n, &m); n   for (int i = 0; i < n; i++) scanf( %s , str[i]), best[i] = inf; n   for (int i = 0; i < n; i++) n     for (int j = 0; j < m; j++) n       scanf( %d , &a[i][j]), best[i] = min(best[i], a[i][j]); n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       bool ok = true; n       for (int k = 0; k < n; k++) n         if (k != i && str[i][j] == str[k][j]) ok = false; n       if (ok) best[i] = 0; n     } n   } n   for (int j = 0; j < m; j++) { n     for (int c = 0; c < 26; c++) { n       mask[j][c] = 0; n       cost[j][c] = 0; n       int maxc = 0, cnt = 0; n       for (int i = 0; i < n; i++) n         if (str[i][j] -  a  == c) { n           mask[j][c] |= 1 << i; n           cost[j][c] += a[i][j]; n           maxc = max(maxc, a[i][j]); n           cnt++; n         } n       cost[j][c] -= maxc; n       if (cnt < 2) mask[j][c] = -1; n     } n   } n   for (int i = 0; i < 1 << n; i++) dp[0][i] = dp[1][i] = inf; n   int nw = 0, ls = 1; n   dp[nw][0] = 0; n   for (int j = 0; j < m; j++) n     for (int c = 0; c < 26; c++) n       if (mask[j][c] != -1) { n         swap(nw, ls); n         memcpy(dp[nw], dp[ls], sizeof dp[ls]); n         for (int i = 0; i < 1 << n; i++) { n           dp[nw][i | mask[j][c]] = n               min(dp[nw][i | mask[j][c]], dp[ls][i] + cost[j][c]); n         } n       } n   for (int i = 0; i < 1 << n; i++) { n     all[i] = 0; n     for (int j = 0; j < n; j++) n       if ((i >> j) & 1) n         ; n       else n         all[i] += best[j]; n   } n   int ans = inf; n   for (int i = 0; i < 1 << n; i++) ans = min(ans, all[i] + dp[nw][i]); n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, a[111], maxx; n int main() { n   cin >> n >> m; n   for (int i = 0; i < n; ++i) cin >> a[i]; n   maxx = a[0]; n   for (int i = 1; i < n; ++i) maxx = max(maxx, a[i]); n   int tot = 0; n   for (int i = 0; i < n; ++i) tot += maxx - a[i]; n   int res2 = maxx + m; n   m -= tot; n   if (m < 0) m = 0; n   int res1 = maxx + m / n; n   if (m % n) ++res1; n   cout << res1 <<     << res2; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long int N = 1e5 + 5; n const long long int M = 1e9 + 7; n queue<pair<long long int, long long int> > pq; n vector<long long int> v; n map<long long int, long long int> mpp; n set<pair<long long int, long long int> > st; n long long int a[N], h[N], indx[N][2]; n long long int val[N]; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   long long int n, l; n   cin >> n; n   string s; n   cin >> s; n   long long int a = 0; n   long long int b = 0; n   for (int i = int(0); i <= int(n - 1); i++) { n     if (s[i] ==  8 ) a++; n   } n   long long int x = n / 11; n   if (a < x) n     cout << a; n   else n     cout << x; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( Ofast,no-stack-protector,unroll-loops ) n #pragma GCC optimize( no-stack-protector,fast-math ) n using namespace std; n const long long N = 2e5 + 100, OO = 1e9 + 7, T = 1e6 + 10, M = 1e9 + 7, n                 P = 6151, SQ = 280, lg = 20; n long long n; n long long pw(long long x, long long y) { n   if (y == 0) return 1; n   long long cnt = pw(x, y / 2); n   cnt = (cnt * cnt) % n; n   cnt = (cnt * (y % 2 == 1 ? x : 1)) % n; n   return cnt; n } n int32_t main() { n   ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); n   cin >> n; n   if (n == 1) return cout <<  YES n1 , 0; n   if (n == 4) return cout <<  YES n1 n3 n2 n4 n , 0; n   for (long long i = 2; i * i <= n; i++) n     if (n % i == 0) return cout <<  NO , 0; n   cout <<  YES n ; n   long long zr = 1; n   for (long long i = 1; i < n; i++) { n     long long cnt = i * pw(zr, n - 2) % n; n     cout << cnt <<   n ; n     zr = (zr * cnt) % n; n   } n   cout << n <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, q = 0, s = 0, t = 0; n   cin >> n; n   for (int k = 1; k <= n; k++) { n     cin >> q; n     if (q == 1) { n       if (t == 1) n         s++; n       else { n         t++; n         s++; n       } n     } else { n       if (t == 1) { n         t--; n         s++; n       } n     } n   } n   if (t == 0 && s != 0) s--; n   cout << s; n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( Ofast ) n #pragma GCC target( avx,avx2,fma ) n using namespace std; n const int mod1 = 1000000007; n long long gcd(long long a, long long b) { n   long long c = a % b; n   while (c != 0) { n     a = b; n     b = c; n     c = a % b; n   } n   return b; n } n long long issub(string a, string b) { n   if (a.find(b) != string::npos) n     return 1; n   else n     return 0; n } n long long expo(long long a, long long b) { n   long long res = 1; n   while (b > 0) { n     if (b & 1) res = res * a % mod1; n     a = a * a % mod1; n     b >>= 1; n   } n   return res; n } n int32_t lcm(long long n1, long long n2) { n   long long max = (n1 > n2) ? n1 : n2; n   do { n     if (max % n1 == 0 && max % n2 == 0) { n       return max; n     } else n       ++max; n   } while (true); n } n string operator*(string a, unsigned long long b) { n   string output =   ; n   while (b--) output += a; n   return output; n } n bool isPerfectSquare(long long n) { n   for (long long i = 1; i * i <= n; i++) { n     if ((n % i == 0) && (n / i == i)) { n       return true; n     } n   } n   return false; n } n int32_t main() { n   ios_base::sync_with_stdio(false), cin.tie(NULL); n   ; n   long long t, a = 0, x; n   cin >> t; n   map<long long, long long> m; n   for (long long i = 0; i < t; i++) { n     cin >> x; n     m[x]++; n     a = max(a, m[x]); n   } n   cout << a; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = 1e9 + 9; n const int Mod = 1e9 + 7; n inline int dcmp(double x) { n   if (fabs(x) <= 1e-9) return 0; n   return x < 0 ? -1 : 1; n } n inline int scan() { n   int x = 0, f = 1; n   char ch = getchar(); n   while (ch <  0  || ch >  9 ) { n     if (ch ==  - ) f = -1; n     ch = getchar(); n   } n   while (ch >=  0  && ch <=  9 ) { n     x = x * 10 + ch -  0 ; n     ch = getchar(); n   } n   return x * f; n } n inline long long scan(long long x) { n   int f = 1; n   char ch = getchar(); n   x = 0; n   while (ch <  0  || ch >  9 ) { n     if (ch ==  - ) f = -1; n     ch = getchar(); n   } n   while (ch >=  0  && ch <=  9 ) { n     x = x * 10 + ch -  0 ; n     ch = getchar(); n   } n   return x * f; n } n struct Point { n   int x, y, id; n   Point(int x = 0, int y = 0) : x(x), y(y) {} n   Point operator-(const Point &a) const { return Point(x - a.x, y - a.y); } n   Point operator*(const long long &a) const { return Point(x * a, y * a); } n   Point operator+(const Point &a) const { return Point(x + a.x, y + a.y); } n   bool operator==(const Point &a) const { n     return dcmp(x - a.x) == 0 && dcmp(y - a.y) == 0; n   } n   bool operator<(const Point &a) const { n     if (x == a.x) return y < a.y; n     return x < a.x; n   } n   void read() { scanf( %d%d , &x, &y); } n   void out() { cout << x <<     << y << endl; } n }; n double Dot(Point a, Point b) { return a.x * b.x + a.y * b.y; } n double dis(Point a) { return sqrt(Dot(a, a)); } n long long Cross(Point a, Point b) { return a.x * 1LL * b.y - a.y * 1LL * b.x; } n bool chk(Point p1, Point p2, Point p3, Point p) { n   return abs(Cross(p2 - p, p1 - p)) + abs(Cross(p3 - p, p2 - p)) + n              abs(Cross(p1 - p, p3 - p)) == n          abs(Cross(p2 - p1, p3 - p1)); n } n int n, k, ti; n int a[200005], vis[200005]; n void solve() { n   n = scan(); n   k = scan(); n   for (int i = 1; i <= n; i++) a[i] = scan(); n   memset(vis, 0, sizeof(vis)); n   sort(a + 1, a + 1 + n); n   for (int i = 1; i <= n; i++) { n     ti = i; n     while (ti - 1) { n       ti--; n       if (vis[ti]) break; n       if (a[ti] + k < a[i]) break; n       if (a[ti] < a[i]) n         vis[ti] = 1; n       else n         break; n     } n   } n   ti = 0; n   for (int i = 1; i <= n; i++) { n     if (!vis[i]) ti++; n   } n   cout << ti << endl; n } n int main() { n   int t = 1; n   for (int i = 1; i <= t; i++) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n #pragma GCC optimize( O2,no-stack-protector,unroll-loops,fast-math ) n const long long maxn = 1e5 + 10, maxm = 5e2 + 10, lg = 21, mod = 1e9 + 7, n                 inf = 1e18; n long long n, m, s; n long double dp[101][maxn], ps[maxn]; n int main() { n   ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); n   cin >> n >> m; n   if (m == 1) return cout << 1, 0; n   dp[0][0] = m - 1; n   fill(ps, ps + maxn, m - 1); n   for (int i = 1; i <= n; i++) { n     long long x; n     cin >> x; n     s += x; n     for (int j = 1; j <= n * m; j++) n       dp[i][j] = (ps[j - 1] - (j - m - 1 >= 0 ? ps[j - m - 1] : 0) - n                   (j - x >= 0 ? dp[i - 1][j - x] : 0)) / n                  (m - 1); n     ps[0] = 0; n     for (int j = 1; j <= n * m; j++) ps[j] = ps[j - 1] + dp[i][j]; n   } n   cout << fixed << setprecision(18) << ps[s - 1] + 1; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int32_t main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   ; n   long long n, p; n   cin >> n >> p; n   long long ans = 5 * 5000000; n   for (long long i = 1; i <= 5000000; i++) { n     long long left = n - p * i; n     if (left < 1) n       continue; n     else { n       long long k = __builtin_popcount(left); n       if (k <= i and left >= i) { n         cout << i; n         return 0; n       } n     } n   } n   cout << -1; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 1e5 + 7; n long long n, a[N], cnt[N]; n int32_t main() { n   cin >> n; n   for (long long i = 0; i < n; i++) cin >> a[i], cnt[a[i]]++; n   for (long long i = 1; i < N; i++) n     if (cnt[i] > 0) { n       if (cnt[i] > n / 2) n         cout <<  Bob ; n       else n         cout <<  Alice ; n       return 0; n     } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int mod = 1e9 + 7; n const int N = 410; n int cnt[N]; n int temp[N]; n long long cost[N][N]; n long long dp[N][N]; n long long n, m, k; n const long long INF = (1LL) << 60; n vector<int> v[200]; n int main() { n   while (cin >> n >> m >> k) { n     memset(dp, 0, sizeof(dp)); n     for (int i = 0; i < N; i++) n       for (int j = 0; j < N; j++) { n         cost[i][j] = INF; n         dp[i][j] = INF; n       } n     for (long long i = 0; i < m; i++) { n       long long l, r, c; n       cin >> l >> r >> c; n       cost[l - 1][r] = min(cost[l - 1][r], c); n     } n     for (long long i = 0; i <= n; i++) n       for (long long j = n; j >= i; j--) { n         cost[i][j - 1] = min(cost[i][j - 1], cost[i][j]); n         cost[i + 1][j] = min(cost[i + 1][j], cost[i][j]); n       } n     dp[0][0] = 0; n     for (long long i = 1; i <= n; i++) { n       for (long long j = 0; j <= i; j++) { n         dp[i][j] = dp[i - 1][j]; n         for (long long k = 0; k < i; k++) { n           if (j - i + k >= 0) n             dp[i][j] = min(dp[i][j], dp[k][j - i + k] + cost[k][i]); n         } n       } n     } n     long long ans = INF; n     for (long long i = k; i <= n; i++) ans = min(ans, dp[n][i]); n     if (ans == INF) n       cout << -1 << endl; n     else n       cout << ans << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n void print(T& x) { n   cout << x; n } n template <class T, class U> n void print(pair<T, U>& p) { n   cout <<  ( ; n   print(p.first); n   cout <<  ,  ; n   print(p.second); n   cout <<  ) ; n } n template <class T> n void print(vector<T>& v) { n   cout <<  { ; n   if (((int)(v).size())) print(v[0]); n   for (int i = 1; i < ((int)(v).size()); i++) cout <<  ,  , print(v[i]); n   cout <<  } n ; n } n const int n = 1e6 + 10; n int N, Q; n vector<vector<pair<int, int>>> T; n int X[n]; n int Par[n]; n pair<int, int> intv[n]; n int newNum[n]; n int cmp[n]; n struct fenwick_tree { n   int n; n   vector<int> a, f; n   fenwick_tree(int n = 0) : n(n), a(n), f(n + 1) {} n   fenwick_tree(vector<int>& a) : fenwick_tree(a.size()) { n     for (int i = 0; i < n; i++) setValue(i, a[i]); n   } n   void changeValue(int i, int d) { n     for (a[i++] += d; i <= n; i += i & -i) f[i] += d; n   } n   void setValue(int i, int v) { changeValue(i, v - a[i]); } n   int getSum(int i) { n     int s = 0; n     for (i++; i; i -= i & -i) s += f[i]; n     return s; n   } n   int getSum(int l, int r) { return getSum(r - 1) - getSum(l - 1); } n }; n struct sparse_table { n   int n; n   vector<int> a; n   vector<vector<int>> st; n   int combine(int dl, int dr) { return a[dl] > a[dr] ? dl : dr; } n   sparse_table() {} n   sparse_table(vector<int>& a) n       : n(a.size()), a(a), st((31 - __builtin_clz(n)) + 1, vector<int>(n)) { n     for (int i = 0; i < n; i++) st[0][i] = i; n     for (int j = 1; 1 << j <= n; j++) n       for (int i = 0; i + (1 << j) <= n; i++) n         st[j][i] = combine(st[j - 1][i], st[j - 1][i + (1 << (j - 1))]); n   } n   int query(int l, int r) { n     int s = (31 - __builtin_clz(r - l)); n     return combine(st[s][l], st[s][r - (1 << s)]); n   } n }; n struct lowest_common_ancestor { n   int n, m = 0; n   vector<int> a, v, h; n   vector<vector<int>>& e; n   sparse_table st; n   lowest_common_ancestor(vector<vector<int>>& e, int r) n       : n(e.size()), a(n), v(2 * n - 1), h(2 * n - 1), e(e) { n     dfs(r); n     st = sparse_table(h); n   } n   void dfs(int i, int p = -1, int d = 0) { n     a[i] = m; n     v[m] = i; n     h[m++] = d; n     for (int j : e[i]) { n       if (j == p) continue; n       dfs(j, i, d - 1); n       v[m] = i; n       h[m++] = d; n     } n   } n   int lca(int x, int y) { n     return v[st.query(min(a[x], a[y]), max(a[x], a[y]) + 1)]; n   } n }; n fenwick_tree BIT(n); n void initDSU() { n   for (int i = 0; i < N; i++) { n     cmp[i] = i; n   } n } n int find(int x) { n   if (cmp[x] != x) cmp[x] = find(cmp[x]); n   return cmp[x]; n } n void combine(int a, int b) { cmp[find(a)] = find(b); } n int newN = 0; n void dfs(int cur, int par) { n   newNum[cur] = newN; n   int l = newN++; n   for (auto [x, w] : T[cur]) { n     if (x == par) continue; n     Par[x] = cur; n     X[x] = X[cur] ^ w; n     dfs(x, cur); n   } n   intv[cur] = make_pair(l, newN - 1); n } n void mark(int x) { n   auto [l, r] = intv[x]; n   BIT.changeValue(l, 1); n   BIT.changeValue(r + 1, -1); n } n void markPath(int x, int to) { n   while (x != to) { n     mark(x); n     x = Par[x]; n   } n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cin >> N >> Q; n   T.resize(N); n   vector<tuple<int, int, int>> A; n   initDSU(); n   for (int i = 0; i < Q; i++) { n     int u, v, x; n     cin >> u >> v >> x; n     u--; n     v--; n     A.emplace_back(u, v, x); n     if (find(u) != find(v)) { n       T[u].emplace_back(v, x); n       T[v].emplace_back(u, x); n       combine(u, v); n     } n   } n   for (int i = 1; i < N; i++) { n     if (find(i) != find(0)) { n       combine(0, i); n       T[0].emplace_back(i, 0); n       T[i].emplace_back(0, 0); n     } n   } n   initDSU(); n   dfs(0, -1); n   vector<vector<int>> e(N); n   for (int i = 0; i < N; i++) { n     for (int j = 0; j < ((int)(T[i]).size()); j++) n       e[i].push_back(T[i][j].first); n   } n   lowest_common_ancestor LCA(e, 0); n   for (auto [u, v, x] : A) { n     if (find(u) != find(v)) { n       combine(u, v); n       cout <<  YES n ; n     } else if ((X[u] ^ X[v] ^ x) == 1) { n       int lca = LCA.lca(u, v); n       int sum = BIT.getSum(newNum[u]) + BIT.getSum(newNum[v]) - n                 2 * BIT.getSum(newNum[lca]); n       if (sum == 0) { n         cout <<  YES n ; n         markPath(v, lca); n         markPath(u, lca); n       } else n         cout <<  NO n ; n     } else n       cout <<  NO n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int dp[1005]; n long long ncr[1005][1005]; n int ones(int n); n void calc_ncr(); n int main() { n   string n; n   int k; n   cin >> n; n   cin >> k; n   calc_ncr(); n   dp[1] = 0; n   for (int i(2); i < (1001); i++) { n     dp[i] = dp[ones(i)] + 1; n   } n   long long res = 0, num_ones = 0; n   int len = n.length(); n   if (k == 0) { n     cout <<  1 n ; n     return 0; n   } n   for (int i(0); i < (len); i++) { n     if (n[i] ==  0 ) { n       continue; n     } n     int j = max(num_ones, 1LL); n     while (j < 1000) { n       if (dp[j] == k - 1) { n         res = (res + ncr[len - i - 1][j - num_ones]) % 1000000007; n         if (i == 0 && k == 1) { n           res = (res + 1000000007 - 1) % 1000000007; n         } n       } n       j++; n     } n     num_ones++; n   } n   int count = 0; n   for (int i(0); i < (len); i++) { n     if (n[i] ==  1 ) { n       count++; n     } n   } n   if (dp[count] == k - 1) { n     res = (res + 1) % 1000000007; n   } n   cout << res <<   n ; n   return 0; n } n int ones(int n) { n   int count = 0; n   while (n) { n     if (n % 2 == 1) { n       count++; n     } n     n /= 2; n   } n   return count; n } n void calc_ncr() { n   for (int i(0); i < (1001); i++) { n     ncr[i][0] = 1; n   } n   for (int i(1); i < (1001); i++) { n     for (int j(1); j < (i + 1); j++) { n       ncr[i][j] = (ncr[i - 1][j - 1] + ncr[i - 1][j]) % 1000000007; n     } n   } n } n


#include<bits/stdc++.h> n using namespace std; n vector<int> vec[200001]; n int ans[200001],arr[200001]; n struct data n { n  int l,r,mini,maxi,d; n }; n data tree[1000001]; n void pushup(int x) n { n     tree[x].maxi=max(tree[x<<1].maxi,tree[(x<<1)+1].maxi); n     tree[x].mini=min(tree[x<<1].mini,tree[(x<<1)+1].mini); n     return; n } n void pushdown(int x) n { n  int mid=(tree[x].l+tree[x].r)>>1; n  int d=tree[x].d; n  tree[x<<1].d+=d; n  tree[(x<<1)+1].d+=d; n  tree[x<<1].maxi+=d; n  tree[(x<<1)+1].maxi+=d; n  tree[x<<1].mini+=d; n  tree[(x<<1)+1].mini+=d; n  tree[x].d=0; n  pushup(x); n  return;  n } n void revise(int i,int l,int r,int d) n { n   n  if(l<=tree[i].l&&r>=tree[i].r) n  { n   tree[i].d+=d; n   tree[i].maxi+=d; n   tree[i].mini+=d; n   return ; n  } n  int mid=(tree[i].l+tree[i].r)>>1; n  if(tree[i].d!=0) n  { n   pushdown(i); n  } n  if(mid>=l) n  { n   revise(i<<1,l,r,d); n  } n  if(mid<r) n  { n   revise((i<<1)+1,l,r,d); n  } n  pushup(i); n   n } n int query_max(int i,int l,int r) n { n  if(r==0) n  { n   return 0; n  } n  int mid=(tree[i].l+tree[i].r)>>1; n   n  if(l<=tree[i].l&&r>=tree[i].r) n  { n   return tree[i].maxi; n  } n  if(tree[i].d!=0) n  { n   pushdown(i); n  } n  pushup(i); n  int ans=-1e9; n  if(mid>=l) n  { n   ans=max(ans,query_max((i<<1),l,r)); n  } n  if(mid<r) n  { n   ans=max(ans,query_max(((i<<1)+1),l,r)); n  } n  pushup(i); n  return ans; n } n int query_min(int i,int l,int r) n { n  if(r==0) n  { n   return 0; n  } n  int mid=(tree[i].l+tree[i].r)>>1; n   n  if(l<=tree[i].l&&r>=tree[i].r) n  { n   return tree[i].mini; n  } n  if(tree[i].d!=0) n  { n   pushdown(i); n  } n  pushup(i); n  int ans=1e9; n  if(mid>=l) n  { n   ans=min(ans,query_min((i<<1),l,r)); n  } n  if(mid<r) n  { n   ans=min(ans,query_min(((i<<1)+1),l,r)); n  } n  pushup(i); n  return ans; n } n void init(int i,int l,int r) n { n  tree[i].l=l; n  tree[i].r=r; n  tree[i].maxi=0; n  tree[i].d=0; n  tree[i].mini=0; n  if(l==r) n  { n   return; n  } n  int mid=(l+r)>>1; n  init((i<<1),l,mid); n  init((i<<1)+1,mid+1,r); n  return; n } n int main() n { n  int n; n  cin>>n; n  for(int i=1 ; i<=n ; i++) n  { n   cin>>arr[i]; n   vec[arr[i]].push_back(i); n  } n  init(1,1,n); n  for(int i=1;  i<=n ; i++) n  { n   revise(1,i,n,-1); n  } n  for(int i=1 ; i<=n ; i++) n  { n   ans[i]=0; n  } n  for(int i=1;  i<=n ; i++) n  { n   for(int j=0 ; j<vec[i].size() ; j++) n   { n    revise(1,vec[i][j],n,2); n    int k=vec[i][j]; n    int a=query_max(1,1,k-1); n    int b=query_min(1,k,n); n    a=max(a,0); n    int c=b-a; n    int tmp=(floor)((double)(c-1)/(double)2); n    //cout<<vec[i][j]<<   <<a<<   <<b<<  n ; n    ans[k]=max(ans[k],abs(tmp)); n    revise(1,vec[i][j],n,-2); n   } n    n   for(int j=0 ; j<vec[i].size() ; j++) n   { n    int k=vec[i][j]; n    revise(1,k,n,2); n   } n   for(int j=0 ; j<vec[i].size() ; j++) n   { n    int k=vec[i][j]; n    int a=query_min(1,1,k-1); n    int b=query_max(1,k,n); n    a=min(0,a); n    int c=b-a; n    //cout<<c<<  n ; n    int tmp=(floor)((double)(c-1)/(double)2); n    //cout<<vec[i][j]<<   <<tmp<<   <<b<<  n ; n    ans[k]=max(ans[k],abs(tmp)); n   } n  } n  for(int i=1;  i<=n ; i++) n  { n   cout<<ans[i]<<   ; n  } n  cout<<  n ; n }


#include <bits/stdc++.h> n using namespace std; n const long long INF(0x3f3f3f3f3f3f3f3fll); n const long long inf(0x3f3f3f3f); n template <typename T> n void read(T &res) { n   bool flag = false; n   char ch; n   while (!isdigit(ch = getchar())) (ch ==  - ) && (flag = true); n   for (res = ch - 48; isdigit(ch = getchar()); n        res = (res << 1) + (res << 3) + ch - 48) n     ; n   flag && (res = -res); n } n template <typename T> n void Out(T x) { n   if (x < 0) putchar( - ), x = -x; n   if (x > 9) Out(x / 10); n   putchar(x % 10 +  0 ); n } n long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } n long long lcm(long long a, long long b) { return a * b / gcd(a, b); } n long long pow_mod(long long x, long long n, long long mod) { n   long long res = 1; n   while (n) { n     if (n & 1) res = res * x % mod; n     x = x * x % mod; n     n >>= 1; n   } n   return res; n } n long long fact_pow(long long n, long long p) { n   long long res = 0; n   while (n) { n     n /= p; n     res += n; n   } n   return res; n } n long long mult(long long a, long long b, long long p) { n   a %= p; n   b %= p; n   long long r = 0, v = a; n   while (b) { n     if (b & 1) { n       r += v; n       if (r > p) r -= p; n     } n     v <<= 1; n     if (v > p) v -= p; n     b >>= 1; n   } n   return r; n } n long long quick_pow(long long a, long long b, long long p) { n   long long r = 1, v = a % p; n   while (b) { n     if (b & 1) r = mult(r, v, p); n     v = mult(v, v, p); n     b >>= 1; n   } n   return r; n } n bool CH(long long a, long long n, long long x, long long t) { n   long long r = quick_pow(a, x, n); n   long long z = r; n   for (long long i = 1; i <= t; i++) { n     r = mult(r, r, n); n     if (r == 1 && z != 1 && z != n - 1) return true; n     z = r; n   } n   return r != 1; n } n bool Miller_Rabin(long long n) { n   if (n < 2) return false; n   if (n == 2) return true; n   if (!(n & 1)) return false; n   long long x = n - 1, t = 0; n   while (!(x & 1)) { n     x >>= 1; n     t++; n   } n   srand(time(NULL)); n   long long o = 8; n   for (long long i = 0; i < o; i++) { n     long long a = rand() % (n - 1) + 1; n     if (CH(a, n, x, t)) return false; n   } n   return true; n } n void exgcd(long long a, long long b, long long &x, long long &y) { n   if (!b) { n     x = 1, y = 0; n     return; n   } n   exgcd(b, a % b, x, y); n   long long t = x; n   x = y, y = t - (a / b) * y; n } n long long inv(long long a, long long b) { n   long long x, y; n   return exgcd(a, b, x, y), (x % b + b) % b; n } n long long crt(long long x, long long p, long long mod) { n   return inv(p / mod, mod) * (p / mod) * x; n } n long long fac(long long x, long long a, long long b) { n   if (!x) return 1; n   long long ans = 1; n   for (long long i = 1; i <= b; i++) n     if (i % a) ans *= i, ans %= b; n   ans = pow_mod(ans, x / b, b); n   for (long long i = 1; i <= x % b; i++) n     if (i % a) ans *= i, ans %= b; n   return ans * fac(x / a, a, b) % b; n } n long long C(long long n, long long m, long long a, long long b) { n   long long N = fac(n, a, b), M = fac(m, a, b), Z = fac(n - m, a, b), sum = 0, n             i; n   for (i = n; i; i = i / a) sum += i / a; n   for (i = m; i; i = i / a) sum -= i / a; n   for (i = n - m; i; i = i / a) sum -= i / a; n   return N * pow_mod(a, sum, b) % b * inv(M, b) % b * inv(Z, b) % b; n } n long long exlucas(long long n, long long m, long long p) { n   long long t = p, ans = 0, i; n   for (i = 2; i * i <= p; i++) { n     long long k = 1; n     while (t % i == 0) { n       k *= i, t /= i; n     } n     ans += crt(C(n, m, i, k), p, k), ans %= p; n   } n   if (t > 1) ans += crt(C(n, m, t, t), p, t), ans %= p; n   return ans % p; n } n const long long N = 3e5 + 10; n signed main() { n   std::ios::sync_with_stdio(false); n   long long t; n   cin >> t; n   while (t--) { n     long long n; n     cin >> n; n     cout << n <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:1024000000,1024000000 ) n using namespace std; n int const maxn = 3000005; n string st[maxn]; n int ab[200], ac[200], ad[200]; n char b[maxn], c[maxn], d[maxn]; n int main() { n   cin >> b >> c; n   int lenc = strlen(c); n   for (int i = 0; i < lenc; i++) { n     ac[c[i] -  a ]++; n   } n   int tw = 0, t = 0; n   int lenb = strlen(b); n   for (int i = 0; i < lenb; i++) { n     if (b[i] ==  ? ) n       tw++; n     else n       ab[b[i] -  a ]++; n   } n   while (tw > 0) { n     for (int i = 0; i < 26; i++) { n       if (tw == 0) break; n       if (ab[i] >= ac[i]) { n         ab[i] -= ac[i]; n       } else { n         if (tw >= ac[i] - ab[i]) { n           tw -= ac[i] - ab[i]; n           ad[i] += ac[i] - ab[i]; n           ab[i] = 0; n         } else { n           ad[0] += tw; n           tw = 0; n         } n       } n     } n   } n   for (int i = 0; i < 26; i++) { n     for (int j = 0; j < ad[i]; j++) { n       d[t++] = (char)(i +  a ); n     } n   } n   t = 0; n   for (int i = 0; i < lenb; i++) { n     if (b[i] ==  ? ) { n       cout << d[t++]; n     } else n       cout << b[i]; n   } n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2e5 + 7; n int a[N], n; n double f(double x) { n   double sum = 0, mn = 0, mx = 0, ans = 0; n   for (int i = 0; i < n; i++) { n     mn = min(mn, sum); n     mx = max(mx, sum); n     sum += a[i] - x; n     ans = max(ans, abs(sum - mn)); n     ans = max(ans, abs(sum - mx)); n   } n   return ans; n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cin >> n; n   for (int i = 0; i < n; i++) cin >> a[i]; n   double l = -1e4 - 7, r = 1e4 + 7; n   int t = 230; n   while (t--) { n     double mid1 = (2 * r + l) / 3; n     double mid2 = (2 * l + r) / 3; n     if (f(mid1) < f(mid2)) n       l = mid2; n     else n       r = mid1; n   } n   cout << setprecision(9) << fixed << f(l) << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, ans; n int a[6][6]; n int convert(char c) { n   if (c ==  R ) return 1; n   if (c ==  G ) return 2; n   if (c ==  B ) return 3; n   if (c ==  Y ) return 4; n   if (c ==  W ) return 5; n } n void xuly(int state) { n   int i, j, dem, c1, c2; n   bool val[10], col[10]; n   int temp[15]; n   dem = 0; n   for (i = 0; i < 5; i++) n     if (state & (1 << i)) { n       dem++; n       val[i + 1] = true; n     } else n       val[i + 1] = false; n   for (i = 5; i < 10; i++) n     if (state & (1 << i)) { n       dem++; n       col[i - 4] = true; n     } else n       col[i - 4] = false; n   memset(temp, 0, sizeof(temp)); n   for (i = 1; i <= 5; i++) n     for (j = 1; j <= 5; j++) n       if (a[i][j]) { n         if (val[i] && col[j]) continue; n         if (val[i]) n           temp[i]++; n         else if (col[j]) n           temp[j + 5]++; n         else n           temp[11]++; n       } n   for (i = 1; i <= 11; i++) n     if (temp[i] > 1) return; n   ans = min(ans, dem); n } n void solve() { n   int i, j; n   ans = 10; n   for (i = 0; i < (1 << 11); i++) xuly(i); n   cout << ans << endl; n } n void input() { n   int i; n   char s[10]; n   scanf( %d , &n); n   memset(a, 0, sizeof(a)); n   for (i = 0; i < n; i++) { n     scanf( %s , &s); n     a[convert(s[0])][s[1] -  0 ]++; n   } n   solve(); n } n int main() { n   input(); n   fclose(stdin); n   fclose(stdout); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main(int argc, char const *argv[]) { n   int a; n   int b; n   int dado[] = {1, 2, 3, 4, 5, 6}; n   cin >> a >> b; n   int r1, r2, r3; n   r1 = r2 = r3 = 0; n   for (int i = 0; i < 6; ++i) n     abs(dado[i] - a)<abs(dado[i] - b) ? r1++ : abs(dado[i] - a)> abs(dado[i] - n                                                                      b) n         ? r2++ n         : r3++; n   cout << r1 <<     << r3 <<     << r2 << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long unsigned int combi(long unsigned int a) { n   if (a == 0 || a == 1) return 0; n   return ((a * (a - 1)) / 2); n } n int main() { n   int n = 0; n   cin >> n; n   char arr[n]; n   int letras[26]; n   char temp = 0; n   long unsigned int res = 0; n   for (int i = 0; i < 26; i++) { n     letras[i] = 0; n   } n   for (int i = 0; i < n; i++) { n     cin >> temp; n     cin.ignore(256,   n ); n     letras[temp - 97]++; n   } n   for (int i = 0; i < 26; i++) { n     res += (combi(letras[i] - (letras[i] / 2)) + (combi(letras[i] / 2))); n   } n   printf( %lu , res); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T, typename U> n bool ckmin(T &a, U b) { n   return b < a ? a = b, true : false; n } n template <typename T, typename U> n bool ckmax(T &a, U b) { n   return b > a ? a = b, true : false; n } n int tt; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cin >> tt; n   while (tt--) { n     int n, x, y, un = -1; n     cin >> n >> x >> y; n     set<int> second; n     vector<int> v(n, 0), res(n, -1); n     map<int, vector<int>> m; n     vector<pair<int, vector<int>>> a, b; n     for (int i = 0; i < n; ++i) { n       cin >> v[i]; n       v[i]--; n       m[v[i]].push_back(i); n     } n     for (int i = 0; i <= n; ++i) second.insert(i); n     for (auto i : v) { n       if (second.find(i) != second.end()) second.erase(i); n     } n     un = (*second.begin()); n     for (auto i : m) a.push_back(i); n     sort(a.begin(), a.end(), n          [](const pair<int, vector<int>> &a, const pair<int, vector<int>> &b) { n            return (int)(a.second).size() < (int)(b.second).size(); n          }); n     int cnt = 0, pp = 0; n     map<int, vector<int>> tmp; n     while (cnt < n - x) { n       if ((int)(a[pp].second).size()) { n         tmp[a[pp].first].push_back(a[pp].second.back()); n         a[pp].second.pop_back(); n         cnt++; n       } n       pp++; n       if (pp >= (int)(a).size()) pp -= (int)(a).size(); n     } n     for (auto i : tmp) { n       b.push_back(i); n     } n     for (auto i : a) { n       for (auto j : i.second) { n         res[j] = i.first; n       } n     } n     vector<pair<int, int>> xx, yy; n     for (auto i : b) { n       for (auto j : i.second) { n         xx.push_back(make_pair(i.first, j)); n         yy.push_back(make_pair(i.first, j)); n       } n     } n     rotate(yy.begin(), yy.begin() + ((int)(yy).size() / 2), yy.end()); n     vector<int> store; n     for (int i = 0; i < (int)(yy).size(); ++i) { n       if (xx[i].first == yy[i].first) store.push_back(i); n     } n     if ((int)(store).size() > n - y) { n       cout <<  NO n ; n       continue; n     } n     for (auto i : store) { n       xx[i].first = un; n       res[yy[i].second] = un; n     } n     int rem = n - y - (int)(store).size(); n     for (int i = 0; i < (int)(yy).size(); ++i) { n       if (rem && xx[i].first != un) { n         rem--; n         xx[i].first = un; n         res[yy[i].second] = un; n       } else { n         res[yy[i].second] = xx[i].first; n       } n     } n     cout <<  YES n ; n     for (auto i : res) cout << i + 1 <<    ; n     cout <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = (int)1e9 * 2; n int n, m, ind; n long long L[55], M[55], R[55], A[55], ans = -inf, un; n bool all = 1; n vector<int> a[55]; n void calc() { n   for (int i = 0; i < n; i++) { n     R[i] = M[i] = L[i] = -inf; n     for (int j = 0; j < a[i].size(); j++) { n       A[i] += (long long)a[i][j]; n       if (A[i] > L[i]) L[i] = A[i]; n     } n     long long sum = 0; n     for (int j = a[i].size() - 1; j >= 0; j--) { n       sum += (long long)a[i][j]; n       if (sum > R[i]) R[i] = sum; n     } n     sum = 0; n     for (int j = 0; j < a[i].size(); j++) { n       sum = max(sum + (long long)a[i][j], (long long)a[i][j]); n       M[i] = max(M[i], sum); n     } n   } n } n int main() { n   scanf( %d%d , &n, &m); n   for (int i = 0; i < n; i++) { n     int l; n     scanf( %d , &l); n     for (int j = 0; j < l; j++) { n       int x; n       scanf( %d , &x); n       a[i].push_back(x); n     } n   } n   calc(); n   for (int i = 0; i < m; i++) { n     scanf( %d , &ind), ind--; n     ans = max(un + L[ind], ans); n     un = max(un + A[ind], R[ind]); n     ans = max(ans, M[ind]); n   } n   printf( %I64d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n double calc(pair<double, double> v1, pair<double, double> v2) { n   double dx = v1.first - v2.first; n   double dy = v1.second - v2.second; n   return sqrt(dx * dx + dy * dy); n } n int main() { n   int a, b, c; n   scanf( %d%d%d , &a, &b, &c); n   double x1, y1, x2, y2; n   scanf( %lf%lf%lf%lf , &x1, &y1, &x2, &y2); n   double dist = fabs(x1 - x2) + fabs(y1 - y2); n   if (a == 0 || b == 0) { n     printf( %.10f n , dist); n     return 0; n   } n   vector<pair<double, double>> v1, v2; n   double xl1 = (-1.0 * c - 1.0 * b * y1) / a; n   double yl1 = (-1.0 * c - 1.0 * a * x1) / b; n   v1.push_back({xl1, y1}); n   v1.push_back({x1, yl1}); n   double xl2 = (-1.0 * c - 1.0 * b * y2) / a; n   double yl2 = (-1.0 * c - 1.0 * a * x2) / b; n   v2.push_back({xl2, y2}); n   v2.push_back({x2, yl2}); n   for (auto p1 : v1) n     for (auto p2 : v2) n       dist = n           min(dist, calc(p1, p2) + fabs(x1 - p1.first) + fabs(y1 - p1.second) + n                         fabs(x2 - p2.first) + fabs(y2 - p2.second)); n   printf( %.10f n , dist); n } n


#include <bits/stdc++.h> n using namespace std; n bool isPrime(int n) { n   for (int i = 2; i < int(sqrt(n) + 1); i++) n     if (n % i == 0) return 0; n   return 1; n } n int main() { n   int n; n   cin >> n; n   if (isPrime(n)) return !(cout << 1 <<   n ); n   if (n & 1) { n     if (isPrime(n - 2)) n       cout << 2 <<   n ; n     else n       cout << 3 <<   n ; n   } else n     cout << 2 <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n const int MAXN = 1000000007; n const int z = 0; n using namespace std; n int main() { n   int k, l, m, n, d, ans = 0; n   cin >> k >> l >> m >> n >> d; n   for (int i = 1; i <= d; i++) { n     if (i % k == 0 or i % l == 0 or i % m == 0 or i % n == 0) { n       ans++; n     } n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   int tt, c = 0; n   cin >> tt; n   while (tt) { n     int n = tt; n     set<int> data; n     while (n % 2 == 0) { n       data.insert(2); n       n = n / 2; n     } n     for (int i = 3; i <= sqrt(n); i = i + 2) { n       while (n % i == 0) { n         data.insert(i); n         n = n / i; n       } n     } n     if (n > 2) data.insert(n); n     if (data.size() == 2) { n       c++; n     } n     tt--; n   } n   cout << c << endl; n   cerr <<  Time :   << (float)clock() / CLOCKS_PER_SEC <<   s  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n using P = pair<int, int>; n constexpr int INF = 1001001001; n constexpr int mod = 1000000007; n template <class T> n inline bool chmax(T& x, T y) { n   if (x < y) { n     x = y; n     return true; n   } n   return false; n } n template <class T> n inline bool chmin(T& x, T y) { n   if (x > y) { n     x = y; n     return true; n   } n   return false; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(nullptr); n   int n, k; n   cin >> n >> k; n   vector<int> a(n + 2), ban(k + 2); n   a[0] = -1e+7, a[n + 1] = INF; n   ban[0] = 0, ban[k + 1] = n + 1; n   for (int i = 1; i <= n; ++i) { n     cin >> a[i]; n     a[i] -= i; n   } n   for (int i = 1; i <= k; ++i) cin >> ban[i]; n   int ans = 0; n   for (int i = 0; i <= k; ++i) { n     int lb = a[ban[i]], ub = a[ban[i + 1]]; n     if (ub - lb < 0) { n       cout << -1 << endl; n       return 0; n     } n     vector<int> vals; n     int cnt = 0; n     int s = ban[i] + 1, t = ban[i + 1]; n     for (int j = s; j < t; ++j) { n       if (a[j] < lb || a[j] > ub) n         ++cnt; n       else n         vals.emplace_back(a[j]); n     } n     int m = vals.size(); n     vector<int> dp(m, INF); n     for (int j = 0; j < m; ++j) { n       *upper_bound(dp.begin(), dp.end(), vals[j]) = vals[j]; n     } n     cnt += dp.end() - lower_bound(dp.begin(), dp.end(), INF); n     ans += cnt; n   } n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, a[1000]; n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n   } n   long int answer = 0; n   for (int i = 0; i < (n - 1); i++) { n     if (a[i] == 1 && a[i + 1] == 2) { n       answer += 3; n     } else if (a[i] == 1 && a[i + 1] == 3) { n       answer += 4; n     } else if (a[i] == 2 && a[i + 1] == 1) { n       answer += 3; n     } else if (a[i] == 2 && a[i + 1] == 3) { n       cout <<  Infinite ; n       return 0; n     } else if (a[i] == 3 && a[i + 1] == 1) { n       answer += 4; n       if (i < n - 2 && a[i + 2] == 2) { n         answer -= 1; n       } n     } else if (a[i] == 3 && a[i + 1] == 2) { n       cout <<  Infinite ; n       return 0; n     } n   } n   cout <<  Finite  << endl; n   cout << answer; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s; n   cin >> s; n   int a = (s.size() + 1) / 2 - 1; n   int b = s.size() / 2 - 1; n   bool f00 = false, f01 = false, f10 = false, f11 = false; n   int cq = 0, c0 = 0, c1 = 0; n   for (int i = 0; i < s.size(); i++) { n     if (s[i] ==  0 ) n       c0++; n     else if (s[i] ==  1 ) n       c1++; n     else n       cq++; n   } n   if (cq + c1 >= a + 2) f11 = true; n   if (c1 <= a) f00 = true; n   if (c1 <= a + 1 and c1 + cq >= a + 1) { n     int q1 = (a + 1) - c1; n     int q0 = cq - q1; n     if (s.back() ==  ? ) { n       if (q1) f01 = true; n       if (q0) f10 = true; n     } else if (s.back() ==  0 ) n       f10 = true; n     else n       f01 = true; n   } n   if (f00) printf( 00 n ); n   if (f01) printf( 01 n ); n   if (f10) printf( 10 n ); n   if (f11) printf( 11 n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   double a, b, Zero = 0.5, One = 1.0; n   scanf( %d , &t); n   while (t--) { n     scanf( %lf%lf , &a, &b); n     if (a == 0 && b == 0) n       printf( %.10lf n , One); n     else if (a == 0) n       printf( %.10lf n , Zero); n     else if (b == 0) n       printf( %.10lf n , One); n     else if (a >= 4 * b) { n       float area = 0.5 * 4 * b * b; n       area = 2 * a * b - area; n       area /= 2 * a * b; n       printf( %.10lf n , area); n     } else { n       float area = 0.5 * a * a * 0.25 + a * b; n       area /= 2 * a * b; n       printf( %.10lf n , area); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( O3 ) n using namespace std; n const int N = 1e5 + 5, M = 100 + 5, OO = 0x3f3f3f3f, mod = 1e9 + 7, base = 131, n           MOD2 = 1000136437; n const double EPS = 1e-9; n long double w, h, theta; n complex<double> rotate(complex<double> &p, double a) { n   return p * polar(1.0, a); n } n int doubleComp(const double &a, const double &b) { n   return fabs(a - b) < EPS ? 0 : a < b ? -1 : 1; n } n bool lineInter(const complex<double> &A, const complex<double> &B, n                const complex<double> &P, const complex<double> &Q, n                complex<double> &R, bool isSegA = false, bool isSegB = false) { n   double d1 = ((conj(P - A) * (B - A)).imag()); n   double d2 = ((conj(Q - A) * (B - A)).imag()); n   if (fabs(d1 - d2) < EPS) return false; n   R = (d1 * Q - d2 * P) / (d1 - d2); n   if (isSegA && n       doubleComp(hypot(A.real() - B.real(), A.imag() - B.imag()), n                  hypot(A.real() - R.real(), A.imag() - R.imag()) + n                      hypot(B.real() - R.real(), B.imag() - R.imag())) != 0) n     return false; n   if (isSegB && n       doubleComp(hypot(P.real() - Q.real(), P.imag() - Q.imag()), n                  hypot(P.real() - R.real(), P.imag() - R.imag()) + n                      hypot(Q.real() - R.real(), Q.imag() - R.imag())) != 0) n     return false; n   return true; n } n void polygonCut(const complex<double> &a, const complex<double> &b, n                 const vector<complex<double> > &v, n                 vector<complex<double> > &ret) { n   ret.clear(); n   for (int i = 0; i < (int)(v).size(); i++) { n     int j = (i + 1) % (int)(v).size(); n     if (((conj(((b) - (a))) * (((v[i]) - (a)))).imag()) >= 0) n       ret.push_back(v[i]); n     complex<double> r; n     if (lineInter(a, b, v[i], v[j], r, 0, 1)) ret.push_back(r); n   } n } n void polygonIntersection(const vector<complex<double> > &poly1, n                          const vector<complex<double> > &poly2, n                          vector<complex<double> > &ret) { n   vector<complex<double> > r2; n   ret = poly1; n   for (int i = 0; i < (int)(poly2).size(); i++) { n     int j = (i + 1) % (int)(poly2).size(); n     polygonCut(poly2[i], poly2[j], ret, r2); n     ret = r2; n   } n } n double areaPolygon(vector<complex<double> > p) { n   double area = 0.0; n   for (int i = 0, n = (int)(p).size(); i < n; i++) n     area += ((conj(p[i]) * (p[(i + 1) % n])).imag()); n   return abs(area) / 2.0; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cin >> w >> h >> theta; n   vector<complex<double> > p, p2, ans; n   w /= 2; n   h /= 2; n   p.push_back(complex<double>(w, h)); n   p.push_back(complex<double>(-w, h)); n   p.push_back(complex<double>(-w, -h)); n   p.push_back(complex<double>(w, -h)); n   p2 = p; n   theta = (theta / 180.0) * (2 * acos(0)); n   for (auto &i : p2) i = rotate(i, theta); n   polygonIntersection(p, p2, ans); n   cout << fixed << setprecision(6) << areaPolygon(ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char buf[1 << 21], *p1 = buf, *p2 = buf; n int read() { n   int w = 0, f = 1; n   char c =    ; n   while (c <  0  || c >  9 ) n     c = (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) n              ? EOF n              : *p1++), n     f = c ==  -  ? -1 : f; n   while (c >=  0  && c <=  9 ) n     w = w * 10 + c - 48, n     c = (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) n              ? EOF n              : *p1++); n   return w * f; n } n int n, m, a[1000005]; n long long val[1000005 << 2], mod; n vector<long long> minn[1000005 << 2]; n const long long inf = 1e18; n void pushup(int p, int l, int r, int mid) { n   int ls = p << 1, rs = p << 1 | 1, it1 = 0, it2 = 0; n   while (it1 <= mid - l + 1) { n     while (it2 <= r - mid) { n       long long L = max(minn[ls][it1], minn[rs][it2] - val[ls] + mod * it1), n                 R = it1 == mid - l + 1 ? inf : minn[ls][it1 + 1] - 1; n       if (L > R) break; n       minn[p][it1 + it2] = min(minn[p][it1 + it2], L), it2++; n     } n     it2 = max(it2 - 1, 0), it1++; n   } n   val[p] = val[ls] + val[rs]; n } n void build(int p, int l, int r) { n   minn[p].resize(r - l + 2); n   minn[p][0] = -inf; n   for (int i = 1; i <= r - l + 1; i++) minn[p][i] = inf; n   if (l == r) { n     minn[p][1] = mod - a[l]; n     val[p] = a[l]; n     return; n   } n   int mid = (l + r) >> 1; n   build(p << 1, l, mid); n   build(p << 1 | 1, mid + 1, r); n   pushup(p, l, r, mid); n } n long long query(int p, int x, int y, long long v, int l, int r) { n   if (x <= l && r <= y) { n     int L = 0, R = r - l + 1, res = 0; n     while (L <= R) { n       int mid = (L + R) >> 1; n       if (minn[p][mid] <= v) n         res = mid, L = mid + 1; n       else n         R = mid - 1; n     } n     return v + val[p] - mod * res; n   } n   int mid = (l + r) >> 1; n   if (y <= mid) return query(p << 1, x, y, v, l, mid); n   if (x > mid) return query(p << 1 | 1, x, y, v, mid + 1, r); n   return query(p << 1 | 1, x, y, query(p << 1, x, y, v, l, mid), mid + 1, r); n } n signed main() { n   n = read(), m = read(), mod = read(); n   for (int i = 1; i <= n; i++) a[i] = read(); n   build(1, 1, n); n   int l, r; n   while (m--) { n     l = read(), r = read(); n     printf( %lld n , query(1, l, r, 0, 1, n)); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char s[601000]; n long long m; n long long ans = 0; n long long len; n long long ll; n long long mod = 1; n long long reget(long long x) { n   long long reans = (10 * (ll - ((long long)(s[x] -  0 ) * mod) % m + m) % m + n                      (long long)(s[x] -  0 ) + m) % n                     m; n   return reans; n } n long long get(long long l, long long r) { n   long long t = l; n   long long temp = 0; n   while (t <= r) { n     if (temp >= m) temp = (temp % m + m) % m; n     while (temp < m && t <= r) { n       temp = temp * 10 + (long long)(s[t] -  0 ); n       t++; n     } n   } n   temp = (temp + m) % m; n   return temp; n } n int main() { n   cin >> s; n   len = strlen(s); n   cin >> m; n   ans = get(0, len - 1); n   for (long long i = 1; i < len; i++) mod = (mod * 10 + m) % m; n   ll = ans; n   for (long long i = 0; i < len - 1; i++) { n     ll = reget(i); n     if (s[i + 1] ==  0 ) continue; n     ans = min(ll, ans); n   } n   printf( %I64d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n const long long int N = 2e5 + 10; n using namespace std; n int main() { n   ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); n   long long int n; n   cin >> n; n   string second; n   cin >> second; n   set<char> x; n   if (n > 26) { n     cout << -1 << endl; n     return 0; n   } n   for (int i = 0; i < n; i++) { n     x.insert(second[i]); n   } n   cout << n - x.size() << endl; n } n


#include <bits/stdc++.h> n using namespace std; n string s; n struct substring { n   int f, b; n   bool operator>(const substring &o) const { n     int cmp = s.compare(f, b - f + 1, s, o.f, o.b - o.f + 1); n     return cmp != 0 ? cmp > 0 : f > o.f; n   } n }; n string kthSubstring(int k) { n   priority_queue<substring, vector<substring>, greater<substring>> pq; n   int len = s.length(); n   for (int i = 0; i < len; i++) { n     pq.push({i, i}); n   } n   while (!pq.empty()) { n     int f = pq.top().f, b = pq.top().b; n     pq.pop(); n     if (--k == 0) return s.substr(f, b - f + 1); n     if (++b < len) { n       pq.push({f, b}); n     } n   } n   return   ; n } n int main() { n   int k; n   cin >> s >> k; n   int len = s.length(); n   long long possible = ((long long)len * (len + 1)) / 2; n   if (k > possible) n     cout <<  No such line.  <<   n ; n   else n     cout << kthSubstring(k) <<   n ; n   return 0; n } n