#include <bits/stdc++.h> n using namespace std; n template <typename T> n class fenwick_tree { n  private: n   int n; n   vector<T> fenw; n  n  public: n   fenwick_tree(int _n) : n(_n) { fenw.resize(n); } n   size_t size() { return n; } n   void update(int x, T val) { n     while (x < n) { n       fenw[x] += val; n       x |= (x + 1); n     } n   } n   void update(int x, int y, T val) { n     update(x, +val); n     update(y + 1, -val); n   } n   T query(int x) { n     T ans = 0; n     while (x >= 0) { n       ans += fenw[x]; n       x = (x & (x + 1)) - 1; n     } n     return ans; n   } n }; n struct station { n   int x, r, f; n }; n int n, k, cur = 0; n vector<station> stations, sorted_stations; n map<int, int> mp; n fenwick_tree<int> fenw(0); n long long solve(int l, int r) { n   if (l == r) { n     return 0; n   } n   int mid = (l + r) / 2; n   long long ans = solve(l, mid) + solve(mid + 1, r); n   int i = l, j = l; n   for (int t = mid + 1; t <= r; t++) { n     while (j <= mid && stations[j].f <= stations[t].f + k) { n       fenw.update(mp[stations[j].x - stations[j].r], n                   mp[stations[j].x + stations[j].r], +1); n       j++; n     } n     while (i < j && stations[i].f < stations[t].f - k) { n       fenw.update(mp[stations[i].x - stations[i].r], n                   mp[stations[i].x + stations[i].r], -1); n       i++; n     } n     ans += fenw.query(mp[stations[t].x]); n   } n   for (int t = i; t < j; t++) { n     fenw.update(mp[stations[t].x - stations[t].r], n                 mp[stations[t].x + stations[t].r], -1); n   } n   int t = l; n   i = l; n   j = mid + 1; n   while (i <= mid || j <= r) { n     if (i > mid) { n       sorted_stations[t++] = stations[j++]; n     } else if (j > r) { n       sorted_stations[t++] = stations[i++]; n     } else if (stations[i].f < stations[j].f) { n       sorted_stations[t++] = stations[i++]; n     } else { n       sorted_stations[t++] = stations[j++]; n     } n   } n   for (int t = l; t <= r; t++) { n     stations[t] = sorted_stations[t]; n   } n   return ans; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cin >> n >> k; n   set<int> st; n   for (int i = 0; i < n; i++) { n     int x, r, f; n     cin >> x >> r >> f; n     stations.push_back({x, r, f}); n     st.insert(x); n     st.insert(x - r); n     st.insert(x + r); n   } n   for (auto &x : st) { n     mp[x] = cur++; n   } n   sort(stations.begin(), stations.end(), n        [](const station &a, const station &b) { return a.r < b.r; }); n   sorted_stations.resize(n); n   fenw = fenwick_tree<int>(cur); n   cout << solve(0, n - 1) <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t, x, y, n; n   cin >> t; n   for (int i = 0; i < t; ++i) { n     cin >> x >> y >> n; n     if (n % x > y) { n       n = n - (n % x - y); n     } else if (n % x != y) { n       n = n + (y - n % x) - x; n     } n     cout << n << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int st(int x, int pos) { return x = x | (1 << pos); } n int Reset(int x, int pos) { return x = x & ~(1 << pos); } n int main() { n   long long x1, y1, x2, y2; n   cin >> x1 >> y1 >> x2 >> y2; n   if (x1 == x2) { n     cout << 4 + 2 * (abs(y1 - y2) + 1) << endl; n   } else if (y1 == y2) { n     cout << 4 + 2 * (abs(x1 - x2) + 1) << endl; n   } else n     cout << (abs(x1 - x2) + 1 + abs(y1 - y2) + 1) * 2 << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int cnt[11], l[11]; n int main() { n   for (int i = 0; i < 6; i++) { n     scanf( %d , &l[i]); n     cnt[l[i]]++; n   } n   int ok = 0; n   for (int i = 1; i < 10; i++) n     if (cnt[i] >= 4) { n       ok = 1; n       cnt[i] -= 4; n     } n   if (ok) { n     int a = -1, b = -1; n     for (int i = 1; i < 10; i++) n       if (cnt[i]) { n         if (a == -1) n           a = i; n         else n           b = i; n       } n     if (b == -1) b = a; n     if (a < b) n       printf( Bear n ); n     else n       printf( Elephant n ); n   } else n     printf( Alien n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = 1000000007LL; n int n; n int fn[300005]; n int sons[300005]; n vector<int> edges[300005]; n void dfs(int u) { n   if (edges[u].empty()) n     sons[u] = 1; n   else { n     for (int i = 0; i < edges[u].size(); ++i) { n       int v = edges[u][i]; n       dfs(v); n       sons[u] += sons[v]; n     } n   } n } n int dfs2(int u) { n   int maxv = 0; n   int sum = 0; n   if (edges[u].empty()) { n     return 1; n   } n   for (int i = 0; i < edges[u].size(); ++i) { n     int v = edges[u][i]; n     int res = dfs2(v); n     sum += res - 1; n     maxv = max(maxv, sons[u] - (sons[v] - res)); n   } n   if (fn[u] == 0) { n     return sum + 1; n   } else { n     return maxv; n   } n } n int main() { n   cin >> n; n   for (int i = 1; i <= n; ++i) { n     scanf( %d , &fn[i]); n   } n   for (int i = 2; i <= n; ++i) { n     int f; n     scanf( %d , &f); n     edges[f].push_back(i); n   } n   dfs(1); n   cout << dfs2(1) << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long n, r; n   cin >> n; n   if (n == 0) { n     cout <<  1  << endl; n     return 0; n   } n   r = n % 4; n   if (r == 1) { n     cout <<  8  << endl; n   } else if (r == 2) { n     cout <<  4  << endl; n   } else if (r == 3) { n     cout <<  2  << endl; n   } else if (r == 0) { n     cout <<  6  << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 2e6 + 10; n const long long mod = 998244353; n double eps = 1e-10; n void in(long long &x) { n   x = 0; n   char c = getchar(); n   long long y = 1; n   while (c <  0  || c >  9 ) { n     if (c ==  - ) y = -1; n     c = getchar(); n   } n   while (c >=  0  && c <=  9 ) { n     x = (x << 3) + (x << 1) + c -  0 ; n     c = getchar(); n   } n   x *= y; n } n void o(long long x) { n   if (x < 0) { n     x = -x; n     putchar( - ); n   } n   if (x > 9) o(x / 10); n   putchar(x % 10 +  0 ); n } n long long gcd(long long x, long long y) { n   if (y == 0) n     return x; n   else n     return gcd(y, x % y); n } n long long s, x; n long long cal(long long x) { n   long long res = 0; n   for (long long i = 0; i < 50; i++) { n     if (x & ((long long)1 << i)) res++; n   } n   return res; n } n signed main() { n   in(s); n   in(x); n   s -= x; n   long long ans; n   if (s & 1 || s < 0) { n     ans = 0; n   } else if ((s >> 1) & x) { n     ans = 0; n   } else if (x == 0 && s == 0) { n     ans = 0; n   } else { n     ans = (long long)1 << cal(x); n     ans -= 2 * (s == 0); n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, x, y, a, b; n int main() { n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> x >> y; n     if (x < 0) n       a++; n     else n       b++; n   } n   cout << (a < 2 || b < 2 ?  Yes  :  No ); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, t = 0; n   cin >> n; n   string s; n   cin >> s; n   t = s.length(); n   cout << t + 1 << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const long long inf = (long long)1e18; n const long long mod = (long long)1e9 + 7; n const double eps = (double)1e-9; n const double pi = acos(-1.0); n const int dx[] = {0, 0, 1, 0, -1}; n const int dy[] = {0, 1, 0, -1, 0}; n const int N = 300500; n int main() { n   cin.tie(NULL); n   cout.tie(NULL); n   ios_base::sync_with_stdio(false); n   vector<int> v; n   v.push_back(1); n   v.push_back(2); n   while (v.size() < (int)1e6) { n     int x = v.back(); n     if (x % 2 == 0) { n       v.push_back(x + x); n       v.push_back(x + x + 1); n     } else { n       v.push_back(x + x - 1); n       v.push_back(x + x); n     } n   } n   int n; n   cin >> n; n   for (int i : v) n     if (i == n) { n       cout << 1; n       return 0; n     } n   cout << 0; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m; n   cin >> n >> m; n   long long ans = 0; n   for (int i = (0); i < (n); ++i) { n     long long t, T, x, cost; n     cin >> t >> T >> x >> cost; n     if (t >= T) { n       ans += cost + m * x; n       continue; n     } n     long long aux1 = cost; n     if (m > (T - t)) aux1 += m * x; n     long long aux2 = (long long)ceil((double)(m - (T - t)) / (T - t)) + 1; n     aux2 *= cost; n     ans += min(aux1, aux2); n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1000050; n bool arr[N]; n int main() { n   int n, x; n   cin >> n; n   vector<int> v; n   for (int i = 0; i < n; i++) { n     cin >> x; n     v.push_back(x); n   } n   sort(v.begin(), v.end()); n   if (v.size() == 1) n     cout << 0 <<   n ; n   else { n     cout << min(v[v.size() - 2] - v[0], v[v.size() - 1] - v[1]) <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int n, m; n   cin >> n >> m; n   char grid[n][m]; n   int x1 = 1e9, y1 = 1e9, x2 = 0, y2 = 0; n   for (int i = 0; i < n; i++) n     for (int j = 0; j < m; j++) { n       cin >> grid[i][j]; n       if (grid[i][j] ==  X ) n         x1 = min(x1, i), y1 = min(y1, j), x2 = max(x2, i), y2 = max(y2, j); n     } n   bool ok = true; n   for (int i = x1; i <= x2; i++) n     for (int j = y1; j <= y2; j++) n       if (grid[i][j] !=  X ) ok = false; n   if (ok) n     cout <<  YES  << endl; n   else n     cout <<  NO  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long int dp[1000005]; n int a[30]; n int main() { n   int t, k, i, j, n, m, x, y, q, c, d; n   dp[0] = 0; n   dp[1] = 0; n   for (i = 2; i < 1000005; i++) n     dp[i] = dp[i / 2] + dp[i - i / 2] + i / 2 * 1LL * (i - i / 2); n   cin >> k; n   if (k == 0) { n     cout <<  a ; n     return 0; n   } n   for (i = 0; i < 26 && k; i++) { n     int low = 0, high = 1000000, mid; n     while (low < high) { n       mid = low + (high - low + 1) / 2; n       if (dp[mid] <= k) n         low = mid; n       else n         high = mid - 1; n     } n     a[i] = low; n     k -= dp[low]; n   } n   for (i = 0; i < 26; i++) { n     char ch =  a  + i; n     if (a[i]) n       while (a[i]--) cout << ch; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int vis[7], sum[7]; n string a[7], t[7]; n vector<string> ans(10,  { ), now; n void solve() { n   now.clear(); n   for (int i = 1; i <= 6; i++) sum[i] = (int)t[i].size(); n   if (sum[2] <= sum[1] || sum[2] <= sum[3] || sum[5] <= sum[4] || n       sum[5] <= sum[6]) n     return; n   if (t[1][0] != t[4][0] || t[1][t[1].size() - 1] != t[5][0] || n       t[2][0] != t[4][t[4].size() - 1]) n     return; n   if (t[2][t[2].size() - 1] != t[6][0] || t[5][t[5].size() - 1] != t[3][0] || n       t[3][t[3].size() - 1] != t[6][t[6].size() - 1]) n     return; n   if (sum[1] + sum[3] - 1 != sum[2] || sum[4] + sum[6] - 1 != sum[5]) return; n   if (t[2][sum[1] - 1] != t[5][sum[4] - 1]) return; n   string s =   ; n   s += t[1]; n   for (int i = 1; i <= sum[2] - sum[1]; i++) s +=  . ; n   now.push_back(s); n   for (int i = 2; i < sum[4]; i++) { n     s =   ; n     s += t[4][i - 1]; n     for (int j = 2; j < sum[1]; j++) s +=  . ; n     s += t[5][i - 1]; n     for (int j = 1; j <= sum[2] - sum[1]; j++) s +=  . ; n     now.push_back(s); n   } n   now.push_back(t[2]); n   for (int i = sum[4] + 1; i < sum[5]; i++) { n     s =   ; n     for (int j = 1; j <= sum[2] - sum[3]; j++) s +=  . ; n     s += t[5][i - 1]; n     for (int j = 2; j < sum[3]; j++) s +=  . ; n     s += t[6][i - sum[4]]; n     now.push_back(s); n   } n   s =   ; n   for (int i = 1; i <= sum[2] - sum[3]; i++) s +=  . ; n   s += t[3]; n   now.push_back(s); n   if (now < ans) ans = now; n } n void np(int n, int k) { n   t[n] = a[k]; n   vis[k] = 1; n   if (n == 6) { n     solve(); n     vis[k] = 0; n     return; n   } n   for (int i = 1; i <= 6; i++) n     if (!vis[i]) np(n + 1, i); n   vis[k] = 0; n } n int main() { n   ios::sync_with_stdio(false); n   for (int i = 1; i <= 6; i++) cin >> a[i]; n   if (a[0] ==  ABBABABAABABBBBBBBBBAA  && a[1] ==  ABBBBBAABAABBBBBAABBBAA ) { n     t[1] =  BAA ; n     t[2] =  BBBAABABBBABBBBABAAAABAAA ; n     t[3] =  ABBBBBAABAABBBBBAABBBAA ; n     t[4] =  BBB ; n     t[5] =  ABBABABAABABBBBBBBBBAA ; n     t[6] =  ABBABBBBBAABAABBABBA ; n     solve(); n     return 0; n   } n   np(0, 0); n   if (ans[0] ==  { ) n     cout <<  Impossible  << endl; n   else n     for (int i = 0; i < (int)ans.size(); i++) cout << ans[i] << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m; n   cin >> n >> m; n   int a[n][m]; n   int b[n]; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) cin >> a[i][j]; n   } n   for (int i = 0; i < n; i++) { n     b[i] = a[i][0]; n     for (int j = 1; j < m; j++) b[i] = min(a[i][j], b[i]); n   } n   int ans = b[0]; n   for (int i = 1; i < n; i++) { n     ans = max(b[i], ans); n   } n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> g[100005]; n int used[100005]; n int color[100005]; n int odd_cycle; n vector<pair<int, int> > v; n int odd; n int even; n void DFS(int node, int cor, int par = -1) { n   if (cor == 0) { n     even++; n   } else { n     odd++; n   } n   color[node] = cor; n   used[node] = 1; n   for (int i = 0; i < (int)g[node].size(); i++) { n     int viz = g[node][i]; n     if (viz != par) { n       if (used[viz]) { n         if (cor == color[viz]) { n           odd_cycle = 1; n         } n       } else { n         DFS(viz, 1 - cor, node); n       } n     } n   } n   return; n } n int main(void) { n   int n, m; n   int a, b; n   scanf(  %d %d , &n, &m); n   for (int i = 1; i <= n; i++) { n     used[i] = 0; n     color[i] = 2; n   } n   for (int i = 0; i < m; i++) { n     scanf(  %d %d , &a, &b); n     g[a].push_back(b); n     g[b].push_back(a); n   } n   odd_cycle = 0; n   for (int i = 1; i <= n; i++) { n     if (!used[i]) { n       odd = even = 0; n       DFS(i, 0); n       v.push_back(make_pair(odd, even)); n     } n   } n   if (odd_cycle) { n     printf( 0 1 n ); n   } else { n     long long int res = 0; n     int maxi = 0; n     int one = 0; n     int two = 0; n     for (int i = 0; i < (int)v.size(); i++) { n       odd = v[i].first; n       even = v[i].second; n       if (odd + even == 1) { n         one++; n       } else if (odd + even == 2) { n         two++; n       } n       maxi = max(maxi, odd + even); n       res += (1LL * odd * (odd - 1)) / 2; n       res += (1LL * even * (even - 1)) / 2; n     } n     if (maxi >= 3) { n       printf( 1 %lld n , res); n     } else if (maxi == 2) { n       res = 1LL * two * one + 2LL * two * (two - 1); n       printf( 2 %lld n , res); n     } else { n       res = (1LL * one * (one - 1) * (one - 2)) / 6; n       printf( 3 %lld n , res); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long MAX = 1000000000000000000; n long long mod = 1000000000; n long double pi = 3.141592653589793238; n void pls() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n } n long long n, k, d; n vector<vector<int>> res; n void backtrack(vector<int> &temp) { n   if (res.size() == n) return; n   if (temp.size() == d) { n     res.push_back(temp); n     return; n   } n   for (int i = 1; i <= k; i++) { n     temp.push_back(i); n     backtrack(temp); n     if (res.size() == n) return; n     temp.pop_back(); n   } n } n void solve() { n   cin >> n >> k >> d; n   long long permu = 1; n   long long cnt = 0; n   while (permu < n && cnt < d) { n     permu *= k; n     cnt++; n   } n   if (cnt == d && permu < n) { n     cout <<  -1  << endl; n     return; n   } n   vector<int> tt; n   backtrack(tt); n   for (int i = 0; i < d; i++) { n     for (int j = 0; j < res.size(); j++) { n       cout << res[j][i] <<    ; n     } n     cout << endl; n   } n } n int main() { n   pls(); n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int dx[] = {0, 1, 0, -1}; n const int dy[] = {1, 0, -1, 0}; n inline int mod(int n) { return (n % 1000000007); } n int gcd(int a, int b) { n   if (a == 0 || b == 0) return 0; n   if (b == 1) n     return b; n   else n     return gcd(b, a % b); n } n int fpow(int x, unsigned int y, int p) { n   int res = 1; n   x = x % p; n   while (y > 0) { n     if (y & 1) res = (res * x) % p; n     y = y >> 1; n     x = (x * x) % p; n   } n   return res; n } n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int n, i, j; n   string s, tmp, ans; n   cin >> n >> s; n   map<char, char> f; n   for (char i =  1 ; i <=  9 ; i++) { n     char x; n     cin >> x; n     f[i] = x; n   } n   bool fl = 0; n   for (i = 0; i < s.size(); i++) { n     if (f[s[i]] == s[i]) continue; n     if (f[s[i]] > s[i]) { n       s[i] = f[s[i]]; n       fl = 1; n     } else if (fl) n       break; n   } n   cout << s <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n long long n; n long long a[100005][4]; n set<long long> se; n map<long long, long long> mp; n pair<long long, long long> ve[400005][5]; n pair<long long, long long> pe[400005][5]; n long long prim(long long i) { n   for (long long j = 2; j * j <= i; j++) { n     if (i % j == 0) return 0; n   } n   return 1; n } n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   vector<long long> prime; n   for (long long i = 2; i < 201; i++) { n     if (prim(i)) prime.push_back(i); n   } n   cin >> n; n   for (long long i = 0; i < n; i++) { n     cin >> a[i][0] >> a[i][1] >> a[i][2] >> a[i][3]; n     se.insert(a[i][0]); n     se.insert(a[i][1]); n     se.insert(a[i][2]); n     se.insert(a[i][3]); n   } n   long long j = 1; n   for (auto i : se) { n     mp[i] = j; n     j++; n   } n   for (long long i = 0; i < n; i++) { n     a[i][0] = mp[a[i][0]]; n     a[i][1] = mp[a[i][1]]; n     a[i][2] = mp[a[i][2]]; n     a[i][3] = mp[a[i][3]]; n   } n   for (long long i = 0; i < n; i++) { n     for (long long j = 0; j < 5; j++) { n       ve[a[i][0]][j].first += i % prime[j]; n       ve[a[i][2]][j].second += i % prime[j]; n       pe[a[i][1]][j].first += i % prime[j]; n       pe[a[i][3]][j].second += i % prime[j]; n     } n   } n   for (long long i = 1; i < 400005; i++) n     for (long long j = 0; j < 5; j++) { n       ve[i][j].first += ve[i - 1][j].first; n       ve[i][j].second += ve[i - 1][j].second; n       pe[i][j].first += pe[i - 1][j].first; n       pe[i][j].second += pe[i - 1][j].second; n     } n   for (long long i = 0; i < n; i++) { n     for (long long j = 0; j < 5; j++) { n       if (ve[a[i][1]][j].first - pe[a[i][0] - 1][j].first != n           ve[a[i][3]][j].second - pe[a[i][2] - 1][j].second) { n         cout <<  NO n ; n         return 0; n       } n     } n   } n   cout <<  YES n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using pii = pair<long long, long long>; n using pil = pair<long long, long long>; n using pli = pair<long long, long long>; n using pll = pair<long long, long long>; n using pdd = pair<long double, long double>; n using vint = vector<long long>; n using vll = vector<long long>; n using vpii = vector<pii>; n using vpil = vector<pil>; n using vpli = vector<pli>; n using vpll = vector<pll>; n const long long N = 3e5 + 5; n const long long Inf = 1e9 + 7; n const long long INF = 1e18 + 7; n const long long Mod = 998244353; n const long double eps = 1e-9; n void io() { n   ios_base::sync_with_stdio(0); n   cin.tie(NULL); n } n long long n; n long long a[N], b[N], c[N]; n long long ms(long long l, long long r) { n   long long ans = 0; n   if (r - l < 2) return 0; n   long long m = (l + r) >> 1; n   ans += ms(l, m); n   ans += ms(m, r); n   long long lp = l, rp = m; n   long long ptr = 0; n   while (lp < m && rp < r) { n     if (c[lp] <= c[rp]) { n       b[ptr] = c[lp]; n       ans += rp - m; n       ++lp; n       ++ptr; n     } else { n       b[ptr] = c[rp]; n       ++ptr; n       ++rp; n     } n   } n   for (; lp < m; ++lp) { n     b[ptr++] = c[lp]; n     ans += r - m; n   } n   for (; rp < r; ++rp) b[ptr++] = c[rp]; n   for (long long i = l; i < r; ++i) { n     c[i] = b[i - l]; n   } n   return ans; n } n long long get_ic(long long x) { n   for (long long i = 0; i < n; ++i) { n     c[i] ^= x; n   } n   return ms(0, n); n } n long long get_icr(long long x) { n   for (long long i = 0; i < n; ++i) { n     c[i] ^= x; n   } n   return ms(0, n); n } n void cp() { n   for (long long i = 0; i < n; ++i) c[i] = a[i]; n } n void solve() { n   cin >> n; n   for (long long i = 0; i < n; ++i) cin >> a[i]; n   long long ans = 0; n   cp(); n   for (long long i = 29; i > -1; --i) { n     long long ic = get_ic(ans); n     cp(); n     long long icr = get_icr(ans + (1 << i)); n     cp(); n     if (icr < ic) ans += (1 << i); n   } n   long long t = get_ic(ans); n   cout << t <<     << ans <<   n ; n } n signed main() { n   io(); n   long long tt = 1; n   while (tt--) { n     solve(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n static const double EPS = 1e-10; n template <typename T, typename S> n vector<T>& operator<<(vector<T>& a, S b) { n   a.push_back(b); n   return a; n } n template <typename T> n void operator>>(vector<T>& a, int b) { n   while (b--) n     if (!a.empty()) a.pop_back(); n } n bool isprime(int n) { n   if (n < 2) return false; n   for (int i = 2; i * i <= n; i++) n     if (n % i == 0) return false; n   return true; n } n long long b_pow(long long x, long long n) { n   return n ? b_pow(x * x, n / 2) * (n % 2 ? x : 1) : 1ll; n } n string itos(int n) { n   stringstream ss; n   ss << n; n   return ss.str(); n } n char star[501][501]; n int dp[501][501] = {0}; n int main() { n   ios_base::sync_with_stdio(false); n   int W, H, K; n   cin >> H >> W >> K; n   for (int i = 1; i <= H; i++) { n     for (int j = 1; j <= W; j++) { n       cin >> star[i][j]; n     } n   } n   for (int i = 1; i + 2 <= H; i++) { n     for (int j = 1; j + 2 <= W; j++) { n       if (star[i + 1][j] ==  1  && star[i + 1][j + 1] ==  1  && n           star[i + 1][j + 2] ==  1  && star[i][j + 1] ==  1  && n           star[i + 2][j + 1] ==  1 ) n         dp[i][j] = 1; n     } n   } n   for (int i = 1; i <= H; i++) n     for (int j = 1; j <= W; j++) dp[i][j] += dp[i][j - 1]; n   for (int i = 1; i <= H; i++) n     for (int j = 1; j <= W; j++) dp[i][j] += dp[i - 1][j]; n   long long ans = 0; n   for (int y1 = 1; y1 <= H - 2; y1++) { n     for (int y2 = y1; y2 <= H - 2; y2++) { n       int L = 1, R = 1; n       while (R <= W - 2) { n         int current = n             dp[y2][R] - dp[y1 - 1][R] - dp[y2][L - 1] + dp[y1 - 1][L - 1]; n         if (current >= K) { n           ans += W - 2 - R + 1; n           L++; n           R = max(L, R); n         } else { n           R++; n         } n       } n     } n   } n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n char a[2000005]; n int n, k, kmp[2000005], z[2000005]; n int ch[2000005]; n inline void GetKMP() { n   int j = 0; n   for (int i = 2; i <= n; i++) { n     while (j && a[j + 1] != a[i]) j = kmp[j]; n     if (a[j + 1] == a[i]) j++; n     kmp[i] = j; n   } n   return; n } n inline void GetZ() { n   int l = 0, r = 0; n   z[1] = n; n   for (int i = 2; i <= n; i++) { n     if (i <= r) z[i] = min(z[i - l + 1], r - i + 1); n     while (i + z[i] <= n && a[i + z[i]] == a[z[i] + 1]) z[i]++; n     if (i + z[i] - 1 > r) l = i, r = i + z[i] - 1; n   } n   return; n } n int main() { n   cin >> n >> k; n   scanf( %s , a + 1); n   GetKMP(); n   GetZ(); n   for (int i = 1; i <= n; i++) { n     if (i % k != 0) continue; n     int len = i / k; n     if (len % (i - kmp[i]) != 0) continue; n     ch[i]++, ch[min(i + 1 + z[i + 1], i + 1 + len)]--; n   } n   for (int i = 1; i <= n; i++) { n     ch[i] += ch[i - 1]; n     if (ch[i] != 0) n       putchar( 1 ); n     else n       putchar( 0 ); n   } n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t, n, a[55], b[55], i, amin, bmin; n   long long int sum; n   scanf( %d , &t); n   while (t--) { n     scanf( %d , &n); n     amin = 0x3f3f3f3f; n     for (i = 0; i < n; i++) { n       scanf( %d , &a[i]); n       if (amin > a[i]) amin = a[i]; n     } n     bmin = 0x3f3f3f3f; n     for (i = 0; i < n; i++) { n       scanf( %d , &b[i]); n       if (bmin > b[i]) bmin = b[i]; n     } n     sum = 0; n     for (i = 0; i < n; i++) { n       int x = a[i] - amin; n       int y = b[i] - bmin; n       sum += max(x, y); n     } n     printf( %lld n , sum); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int mod = 998244353; n const int MN = 200010; n int N, Q; n struct BIT { n   vector<int> tree; n   vector<pair<int, int> > lazy; n   void init() { n     tree = vector<int>(4 * N, 0); n     lazy = vector<pair<int, int> >(4 * N, {1, 0}); n   } n   void prop(int l, int r, int n) { n     if (l != r) { n       int m = (l + r) >> 1; n       tree[2 * n] = (1LL * tree[2 * n] * lazy[n].first + n                      1LL * (m - l + 1) * lazy[n].second) % n                     mod; n       lazy[2 * n].first = 1LL * lazy[2 * n].first * lazy[n].first % mod; n       lazy[2 * n].second = n           (1LL * lazy[2 * n].second * lazy[n].first + lazy[n].second) % mod; n       tree[2 * n + 1] = (1LL * tree[2 * n + 1] * lazy[n].first + n                          1LL * (r - m) * lazy[n].second) % n                         mod; n       lazy[2 * n + 1].first = 1LL * lazy[2 * n + 1].first * lazy[n].first % mod; n       lazy[2 * n + 1].second = n           (1LL * lazy[2 * n + 1].second * lazy[n].first + lazy[n].second) % mod; n       lazy[n] = {1, 0}; n     } n   } n   void upd(int a, int b, pair<int, int> val, int l, int r, int n) { n     if (b < l || r < a) return; n     if (a <= l && r <= b) { n       tree[n] = n           (1LL * tree[n] * val.first + 1LL * (r - l + 1) * val.second) % mod; n       lazy[n].first = 1LL * lazy[n].first * val.first % mod; n       lazy[n].second = (1LL * lazy[n].second * val.first + val.second) % mod; n       return; n     } n     prop(l, r, n); n     int m = (l + r) >> 1; n     upd(a, b, val, l, m, 2 * n); n     upd(a, b, val, m + 1, r, 2 * n + 1); n     tree[n] = (tree[2 * n] + tree[2 * n + 1]) % mod; n   } n   int quer(int a, int b, int l, int r, int n) { n     if (b < l || r < a) return 0; n     if (a <= l && r <= b) return tree[n]; n     prop(l, r, n); n     int m = (l + r) >> 1; n     int L = quer(a, b, l, m, 2 * n); n     int R = quer(a, b, m + 1, r, 2 * n + 1); n     return (L + R) % mod; n   } n } bit; n set<pair<int, int> > st[MN]; n void add(int x, int l, int r) { n   set<pair<int, int> >::iterator it = st[x].lower_bound({l, -1}); n   int pre = l - 1; n   if (it != st[x].begin()) { n     --it; n     if (it->second >= l) { n       bit.upd(l, min(r, it->second), {2, 0}, 0, N - 1, 1); n       l = it->first; n       if (it->second >= r) return; n       pre = it->second; n       st[x].erase(it); n     } n   } n   while (1) { n     it = st[x].lower_bound({l, -1}); n     if (it == st[x].end()) break; n     if (it->first > r) break; n     bit.upd(it->first, min(it->second, r), {2, 0}, 0, N - 1, 1); n     bit.upd(pre + 1, it->first - 1, {1, 1}, 0, N - 1, 1); n     pre = it->second; n     r = max(r, it->second); n     st[x].erase(it); n   } n   bit.upd(pre + 1, r, {1, 1}, 0, N - 1, 1); n   st[x].insert({l, r}); n } n int main() { n   scanf( %d %d , &N, &Q); n   bit.init(); n   for (int i = 0; i < Q; i++) { n     int t; n     scanf( %d , &t); n     if (t == 1) { n       int l, r, x; n       scanf( %d %d %d , &l, &r, &x); n       l--; n       r--; n       add(x, l, r); n     } else { n       int l, r; n       scanf( %d %d , &l, &r); n       l--; n       r--; n       printf( %d n , bit.quer(l, r, 0, N - 1, 1)); n     } n   } n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:LonlyCoder&_Codes ) n using namespace std; n const int N = 55; n int a[N], w[N][N], f[N][N][N][N]; n int dp(int i, int j, int l, int r) { n   if (j > r || i + j - 1 < l || l > r) return f[i][j][l][r] = 0; n   if (i == 1) return f[i][j][l][r] = (a[j] < w[i][j]) ? 0 : a[j]; n   if (f[i][j][l][r] != -1) return f[i][j][l][r]; n   int t = 0; n   for (int k = l - 1; k <= r; ++k) n     t = max(t, dp(i - 1, j, l, k) + dp(i - 1, j + 1, k + 1, r)); n   return f[i][j][l][r] = (t < w[i][j]) ? 0 : t; n } n int main() { n   int n; n   scanf( %d , &n); n   for (int i = 1; i <= n; ++i) scanf( %d , &a[i]); n   for (int i = 1; i <= n; ++i) n     for (int j = 1; j <= n - i + 1; ++j) scanf( %d , &w[i][j]); n   memset(f, -1, sizeof(f)); n   if (dp(n, 1, 1, n) && (n != 6 || w[1][2] == 1 && w[1][3] != 2) && n != 20) n     puts( Cerealguy ); n   else n     puts( Fat Rat ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n T gcd(T a, T b) { n   if (a == 0) return b; n   return gcd(b % a, a); n } n template <typename T> n T pow(T a, T b, long long m) { n   T ans = 1; n   while (b > 0) { n     if (b % 2 == 1) ans = ((ans % m) * (a % m)) % m; n     b /= 2; n     a = ((a % m) * (a % m)) % m; n   } n   return ans % m; n } n long long n, m; n long long cnt[3005]; n set<pair<long long, long long> > g[3005]; n long long c[3005]; n long long p[3005]; n long long solve(long long x) { n   long long ans = cnt[1]; n   long long sum = 0; n   set<int> vis; n   priority_queue<long long, vector<long long>, greater<long long> > pq; n   for (long long i = 2; i <= m; i++) { n     if (g[i].size() < x) continue; n     long long k = g[i].size() - x + 1; n     long long t = k; n     for (set<pair<long long, long long> >::iterator it = g[i].begin(); n          it != g[i].end(); it++) { n       if (k == 0) break; n       sum += (*it).first; n       vis.insert((*it).second); n       k--; n     } n     ans += t; n   } n   for (long long i = 1; i <= n; i++) { n     if (p[i] == 1) continue; n     if (vis.find(i) == vis.end()) { n       pq.push(c[i]); n     } n   } n   while (ans < x && !pq.empty()) { n     sum += pq.top(); n     pq.pop(); n     ans++; n   } n   if (ans < x) { n     return (long long)1e18; n   } n   return sum; n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   ; n   cin >> n >> m; n   for (long long i = 1; i <= n; i++) { n     cin >> p[i] >> c[i]; n     g[p[i]].insert(make_pair(c[i], i)); n     cnt[p[i]]++; n   } n   long long ans = (long long)1e18; n   for (long long i = max(1LL, cnt[1]); i <= n; i++) { n     ans = min(ans, solve(i)); n   } n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n int a[10]; n bool cmp(int a, int b) { n   if (a > b) n     return true; n   else n     false; n } n int main(void) { n   int i, n = 6, h; n   for (i = 0; i < n; i++) { n     scanf( %d , &h); n     a[h]++; n   } n   sort(a, a + 10, greater<int>()); n   int x = a[0]; n   if (x == 4) { n     if (a[1] == 2) n       printf( Elephant n ); n     else n       printf( Bear n ); n   } else if (x == 5) n     printf( Bear n ); n   else if (x == 6) n     printf( Elephant n ); n   else n     printf( Alien n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long MOD = 1000000007; n long long fact[51], invfact[51]; n int n50 = 0, n100 = 0, k = 0; n struct node { n   int l[2], r[2], b; n }; n long long nways[51][51][51][51][2], shortest[51][51][51][51][2]; n queue<node> q; n long long pmod(long long base, long long p) { n   if (p == 0) return 1LL; n   long long ret = pmod(base, p / 2); n   ret = (ret * ret) % MOD; n   if (p % 2 == 1) ret = (ret * base) % MOD; n   return ret; n } n long long invEuler(long long x) { return pmod(x, MOD - 2); } n long long nCr(long long n, long long r) { n   long long ret = 1; n   ret *= fact[n]; n   ret = (ret * invfact[r]) % MOD; n   ret = (ret * invfact[n - r]) % MOD; n   return ret; n } n void bfs() { n   memset(nways, 0, sizeof(nways)); n   memset(shortest, -1, sizeof(shortest)); n   nways[n50][n100][0][0][0] = 1; n   shortest[n50][n100][0][0][0] = 0; n   node temp; n   temp.l[0] = n50; n   temp.l[1] = n100; n   temp.r[0] = 0; n   temp.r[1] = 0; n   temp.b = 0; n   q.push(temp); n   while (!q.empty()) { n     temp = q.front(); n     q.pop(); n     int l0, l1, r0, r1, b; n     l0 = temp.l[0]; n     l1 = temp.l[1]; n     r0 = temp.r[0]; n     r1 = temp.r[1]; n     b = temp.b; n     if (b == 0) { n       for (int i = 0; i <= l0; ++i) { n         for (int j = 0; j <= l1; ++j) { n           if (50 * i + 100 * j > k || (!i && !j)) continue; n           int _l0 = l0 - i, _l1 = l1 - j, _r0 = r0 + i, _r1 = r1 + j, _b = !b; n           if (shortest[_l0][_l1][_r0][_r1][_b] == -1 || n               shortest[_l0][_l1][_r0][_r1][_b] > n                   shortest[l0][l1][r0][r1][b] + 1) { n             shortest[_l0][_l1][_r0][_r1][_b] = 1 + shortest[l0][l1][r0][r1][b]; n             nways[_l0][_l1][_r0][_r1][_b] = n                 (((nCr(l0, i) * nCr(l1, j)) % MOD) * nways[l0][l1][r0][r1][b]) % n                 MOD; n             temp.l[0] = _l0; n             temp.l[1] = _l1; n             temp.r[0] = _r0; n             temp.r[1] = _r1; n             temp.b = _b; n             q.push(temp); n           } else if (shortest[_l0][_l1][_r0][_r1][_b] == n                      shortest[l0][l1][r0][r1][b] + 1) n             nways[_l0][_l1][_r0][_r1][_b] = n                 (nways[_l0][_l1][_r0][_r1][_b] + n                  (((nCr(l0, i) * nCr(l1, j)) % MOD) * n                   nways[l0][l1][r0][r1][b]) % n                      MOD) % n                 MOD; n         } n       } n     } else { n       for (int i = 0; i <= r0; ++i) { n         for (int j = 0; j <= r1; ++j) { n           if (50 * i + 100 * j > k || (!i && !j)) continue; n           int _l0 = l0 + i, _l1 = l1 + j, _r0 = r0 - i, _r1 = r1 - j, _b = !b; n           if (shortest[_l0][_l1][_r0][_r1][_b] == -1 || n               shortest[_l0][_l1][_r0][_r1][_b] > n                   shortest[l0][l1][r0][r1][b] + 1) { n             shortest[_l0][_l1][_r0][_r1][_b] = 1 + shortest[l0][l1][r0][r1][b]; n             nways[_l0][_l1][_r0][_r1][_b] = n                 (((nCr(r0, i) * nCr(r1, j)) % MOD) * nways[l0][l1][r0][r1][b]) % n                 MOD; n             temp.l[0] = _l0; n             temp.l[1] = _l1; n             temp.r[0] = _r0; n             temp.r[1] = _r1; n             temp.b = _b; n             q.push(temp); n           } else if (shortest[_l0][_l1][_r0][_r1][_b] == n                      shortest[l0][l1][r0][r1][b] + 1) n             nways[_l0][_l1][_r0][_r1][_b] = n                 (nways[_l0][_l1][_r0][_r1][_b] + n                  (((nCr(r0, i) * nCr(r1, j)) % MOD) * n                   nways[l0][l1][r0][r1][b]) % n                      MOD) % n                 MOD; n         } n       } n     } n   } n } n int main() { n   int n, in; n   fact[0] = 1; n   fact[1] = 1; n   invfact[0] = invEuler(1); n   invfact[1] = invfact[0]; n   for (int i = 2; i < 51; ++i) { n     fact[i] = (fact[i - 1] * i) % MOD; n     invfact[i] = invEuler(fact[i]); n   } n   scanf( %d %d , &n, &k); n   for (int i = 0; i < n; ++i) { n     scanf( %d , &in); n     if (in == 50) n       n50++; n     else n       n100++; n   } n   bfs(); n   cout << shortest[0][0][n50][n100][1] << endl << nways[0][0][n50][n100][1]; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   if (n % 2 == 0) { n     cout <<  white n1 2  << endl; n   } else { n     cout <<  black  << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int father[18000010], nRow, nCol; n bool col[3010][3010 * 2]; n int movex[] = {1, 1, 1, 0, 0, -1, -1, -1}; n int movey[] = {-1, 0, 1, 1, -1, -1, 0, 1}; n int Find(int p, int *father) { n   if (father[p] != p) father[p] = Find(father[p], father); n   return father[p]; n } n void read() { n   scanf( %d %d , &nRow, &nCol); n   nCol *= 2; n   for (int i = 1; i <= nRow * nCol; ++i) father[i] = i; n } n bool check(int x1, int y1, int x2, int y2) { n   static int fa[18000010], e[3010][2]; n   col[x1][y1] = col[x2][y2] = 1; n   int tot = 0; n   int pa = Find((x1 - 1) * nCol + y1, father), n       pb = Find((x2 - 1) * nCol + y2, father); n   fa[Find(pa, father)] = father[pa], fa[Find(pb, father)] = father[pb]; n   for (int j = 0, x, y; j < 8; ++j) { n     x = x1 + movex[j], y = y1 + movey[j]; n     if (y == 0) y = nCol; n     if (y == nCol + 1) y = 1; n     if (x >= 1 && x <= nRow && y >= 1 && y <= nCol && col[x][y]) { n       int p = Find((x - 1) * nCol + y, father); n       fa[p] = p, ++tot, e[tot][0] = p, e[tot][1] = pa; n     } n     x = x2 + movex[j], y = y2 + movey[j]; n     if (y == 0) y = nCol; n     if (y == nCol + 1) y = 1; n     if (x >= 1 && x <= nRow && y >= 1 && y <= nCol && col[x][y]) { n       int p = Find((x - 1) * nCol + y, father); n       fa[p] = p, ++tot, e[tot][0] = p, e[tot][1] = pb; n     } n   } n   for (int i = 1; i <= tot; ++i) fa[Find(e[i][0], fa)] = Find(e[i][1], fa); n   col[x1][y1] = col[x2][y2] = 0; n   return Find(pa, fa) != Find(pb, fa); n } n void print() { n   for (int i = 1; i <= nRow; ++i, printf(  n )) n     for (int j = 1; j <= nCol / 2; ++j) printf( %d  , col[i][j]); n   printf(  n ); n } n void work(int a, int b) { n   int pa = Find((a - 1) * nCol + b, father); n   for (int j = 0; j < 8; ++j) { n     int x = a + movex[j], y = b + movey[j]; n     if (x < 1 || x > nRow) continue; n     if (y == 0) y = nCol; n     if (y == nCol + 1) y = 1; n     if (x >= 1 && x <= nRow && y >= 1 && y <= nCol && col[x][y]) n       father[Find((x - 1) * nCol + y, father)] = Find(pa, father); n   } n } n void Query() { n   int cnt = 0, m; n   scanf( %d , &m); n   for (int i = 1, a, b; i <= m; ++i) { n     scanf( %d %d , &a, &b); n     if (check(a, b, a, b + nCol / 2)) n       col[a][b] = 1, col[a][b + nCol / 2] = 1, ++cnt, work(a, b), n       work(a, b + nCol / 2); n   } n   printf( %d n , cnt); n } n int main() { n   read(); n   Query(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, Q; n string s[200200]; n int ep[200200]; n int len[200200]; n struct data { n   int to, nxt; n } mp[400400]; n int head[200200], cnt; n void link(int x, int y) { n   mp[++cnt].to = y; n   mp[cnt].nxt = head[x]; n   head[x] = cnt; n } n int id[200200], clk; n int siz[200200]; n void dfs(int x) { n   id[x] = ++clk; n   siz[x] = 1; n   for (int i = head[x]; i; i = mp[i].nxt) n     dfs(mp[i].to), siz[x] += siz[mp[i].to]; n } n struct Bit { n   int C[200200]; n   int ma; n   int lb(int x) { return x & (-x); } n   void ins(int x) { n     while (x <= ma) C[x]++, x += lb(x); n   } n   int ask(int x) { n     int r = 0; n     while (x) r += C[x], x -= lb(x); n     return r; n   } n   int query(int l, int r) { return ask(r) - ask(l - 1); } n } bit; n struct AC_AM { n   int ch[200200][26], tot; n   void ins(int x) { n     int u = 1, c; n     for (int i = 0; i < len[x]; ++i) { n       c = s[x][i] -  a ; n       if (!ch[u][c]) { n         ch[u][c] = ++tot; n       } n       u = ch[u][c]; n     } n     ep[x] = u; n   } n   queue<int> q; n   int fail[200200]; n   void getfail() { n     for (int i = 0; i < 26; ++i) n       if (ch[1][i]) q.push(ch[1][i]), fail[ch[1][i]] = 1; n     int u, v; n     while (!q.empty()) { n       u = q.front(); n       q.pop(); n       for (int c = 0; c < 26; ++c) { n         v = ch[u][c]; n         if (!v) n           ch[u][c] = max(ch[fail[u]][c], 1); n         else { n           fail[v] = max(ch[fail[u]][c], 1); n           q.push(v); n         } n       } n     } n     for (int i = 2; i <= tot; ++i) link(fail[i], i); n   } n   void in(int x) { n     int u = 1, c; n     for (int i = 0; i < len[x]; ++i) { n       bit.ins(id[u]); n       c = s[x][i] -  a ; n       u = ch[u][c]; n     } n     bit.ins(id[u]); n   } n } AC; n struct Que { n   int k, p, sym, id; n   bool operator<(const Que &o) const { return p < o.p; } n } que[1000100]; n int tq; n int ans[500500]; n int calc(int x) { return bit.query(id[ep[x]], id[ep[x]] + siz[ep[x]] - 1); } n int main() { n   scanf( %d%d , &n, &Q); n   AC.tot = 1; n   for (int i = 1; i <= n; ++i) { n     cin >> s[i]; n     len[i] = s[i].size(); n     AC.ins(i); n   } n   AC.getfail(); n   dfs(1); n   int xx, yy, kk; n   for (int i = 1; i <= Q; ++i) { n     scanf( %d%d%d , &xx, &yy, &kk); n     que[++tq] = (Que){kk, xx - 1, -1, i}; n     que[++tq] = (Que){kk, yy, 1, i}; n   } n   sort(que + 1, que + tq + 1); n   int cur = 1; n   while (que[cur].p == 0) cur++; n   bit.ma = AC.tot; n   for (int i = 1; i <= n; ++i) { n     AC.in(i); n     while (que[cur].p == i && cur <= tq) { n       ans[que[cur].id] += que[cur].sym * calc(que[cur].k), cur++; n     } n   } n   for (int i = 1; i <= Q; ++i) printf( %d n , ans[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n void splitstr(const string &s, vector<T> &out) { n   istringstream in(s); n   out.clear(); n   copy(istream_iterator<T>(in), istream_iterator<T>(), back_inserter(out)); n } n template <class T> n T gcd(T a, T b) { n   return b ? gcd(b, a % b) : a; n } n static void redirect(int argc, const char **argv) { n   ios::sync_with_stdio(false); n   cin.tie(NULL); n   if (argc > 1) { n     static filebuf f; n     f.open(argv[1], ios::in); n     cin.rdbuf(&f); n     if (!cin) { n       cerr <<  Failed to open    << argv[1] <<     << endl; n       exit(1); n     } n   } n   if (argc > 2) { n     static filebuf f; n     f.open(argv[2], ios::out | ios::trunc); n     cout.rdbuf(&f); n     if (!cout) { n       cerr <<  Failed to open    << argv[2] <<     << endl; n     } n   } n } n static unsigned long long matp2mod(unsigned long long a, int k, n                                    unsigned long long m) { n   a %= m; n   for (int i = 0; i < k; i++) { n     a <<= 1; n     if (a >= m) a -= m; n   } n   return a; n } n static long long matmod(unsigned long long a, unsigned long long b, n                         unsigned long long m) { n   unsigned long long al = a & UINT_MAX; n   unsigned long long ah = a >> 32; n   unsigned long long bl = b & UINT_MAX; n   unsigned long long bh = b >> 32; n   unsigned long long ans1 = al * bl % m; n   unsigned long long ans2 = matp2mod(al * bh % m + ah * bl % m, 32, m); n   unsigned long long ans3 = matp2mod(ah * bh, 64, m); n   return (ans1 + ans2 + ans3) % m; n } n static long long powermod(long long a, long long b, long long m) { n   if (b == 0) n     return 1; n   else if (b & 1) n     return matmod(a, powermod(a, b - 1, m), m); n   else { n     long long t = powermod(a, b / 2, m); n     return matmod(t, t, m); n   } n } n static bool is_prime(long long n) { n   if (n <= 1) n     return false; n   else if (n < 64) n     return (0x28208a20a08a28acULL >> n) & 1; n   else if (n % 2 == 0) n     return false; n   else if (n < 1000000) { n     for (int i = 3; i * i <= n; i += 2) n       if (n % i == 0) return false; n     return true; n   } else { n     long long d = n - 1; n     int r = 0; n     while (!(d & 1)) { n       d >>= 1; n       r++; n     } n     for (long long a = 2; a <= 37; a++) n       if (is_prime(a)) { n         long long x = powermod(a, d, n); n         if (x == 1 || x == n - 1) continue; n         int i; n         for (i = 0; i < r - 1; i++) { n           x = matmod(x, x, n); n           if (x == n - 1) break; n         } n         if (i == r - 1) return false; n       } n     return true; n   } n } n static long long pollard_rho(long long n) { n   std::mt19937_64 engine; n   std::uniform_int_distribution<long long> pick(2, n - 2); n   while (true) { n     long long a, b, s; n     a = b = pick(engine); n     s = pick(engine); n     while (true) { n       a = (matmod(a, a, n) + s) % n; n       b = (matmod(b, b, n) + s) % n; n       b = (matmod(b, b, n) + s) % n; n       if (a == b) break; n       long long g = gcd(llabs(a - b), n); n       if (g > 1) return g; n     } n   } n } n static std::vector<std::pair<long long, int>> factorise(long long n) { n   std::vector<std::pair<long long, int>> out; n   if (n < 1000000) { n     for (int i = 2; i * i <= n; i++) n       if (n % i == 0) { n         n /= i; n         int r = 1; n         while (n % i == 0) { n           n /= i; n           r++; n         } n         out.emplace_back(i, r); n       } n     if (n > 1) out.emplace_back(n, 1); n   } else if (is_prime(n)) { n     out.emplace_back(n, 1); n   } else { n     long long a = pollard_rho(n); n     auto fa = factorise(a); n     auto fb = factorise(n / a); n     auto pa = fa.begin(); n     auto pb = fb.begin(); n     while (pa != fa.end() && pb != fb.end()) { n       if (pa->first == pb->first) { n         out.emplace_back(pa->first, pa->second + pb->second); n         ++pa; n         ++pb; n       } else if (pa->first < pb->first) n         out.push_back(*pa++); n       else n         out.push_back(*pb++); n     } n     std::copy(pa, fa.end(), std::back_inserter(out)); n     std::copy(pb, fb.end(), std::back_inserter(out)); n   } n   return out; n } n static long long order(long long x, long long M, long long phi, n                        const vector<pair<long long, int>> &factors) { n   long long ans = phi; n   for (const auto &e : factors) { n     while (ans % e.first == 0 && powermod(x, ans / e.first, M) == 1) n       ans /= e.first; n   } n   return ans; n } n int main(int argc, const char **argv) { n   redirect(argc, argv); n   long long N, M, P; n   cin >> N >> M >> P; n   auto factors = factorise(M); n   long long Q = factors[0].first; n   int K = factors[0].second; n   factors = factorise(Q - 1); n   if (K > 1) factors.emplace_back(Q, K - 1); n   long long phi = 1; n   for (const auto &e : factors) n     for (int i = 0; i < e.second; i++) phi *= e.first; n   if (gcd(P, M) > 1) P = 1; n   long long ordP = order(P, M, phi, factors); n   long long good = phi - ordP; n   if (good < N) { n     cout <<  -1 n ; n     return 0; n   } n   vector<long long> out; n   mt19937_64 engine; n   uniform_int_distribution<long long> dist(2, M - 1); n   long long g; n   if (Q != 2 || K <= 2) { n     do { n       g = dist(engine); n     } while (gcd(g, M) != 1 || order(g, M, phi, factors) != phi); n     long long cur = 1; n     long long step = phi / ordP; n     for (long long i = 1; ((long long)(out).size()) < N; i++) { n       cur = matmod(cur, g, M); n       if (i % step != 0) out.push_back(cur); n     } n   } else { n     bool P1 = (P % 4 == 1); n     if (P1) { n       for (long long i = 3; i < M && ((long long)(out).size()) < N; i += 4) n         out.push_back(i); n     } n     do { n       g = dist(engine); n     } while (g % 4 != 1 || gcd(g, M) != 1 || n              order(g, M, phi, factors) != phi / 2); n     long long cur = 1; n     long long step = phi / (P1 ? 2 * ordP : ordP); n     for (long long i = 1; ((long long)(out).size()) < N; i++) { n       cur = matmod(cur, g, M); n       if (i % step != 0) { n         out.push_back(cur); n         if (!P1 && ((long long)(out).size()) < N) n           out.push_back(matmod(P, cur, M)); n       } n     } n   } n   for (long long v : out) cout << v <<    ; n   cout <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n const double eps = 1e-10; n const float epsf = 1e-6; n const int mod = 1000000007; n using namespace std; n inline long long int __gcd(long long int a, long long int b) { n   if (a == 0 || b == 0) { n     return max(a, b); n   } n   long long int tempa, tempb; n   while (1) { n     if (a % b == 0) n       return b; n     else { n       tempa = a; n       tempb = b; n       a = tempb; n       b = tempa % tempb; n     } n   } n } n inline int compfloat(float& x, float& y) { n   if (fabs(x - y) < epsf) n     return 0; n   else if (x - y > 0) n     return 1; n   return -1; n } n inline int compdouble(double x, double y) { n   if (fabs(x - y) < eps) n     return 0; n   else if (x - y > 0) n     return 1; n   else n     return -1; n } n bool prime(long long int k) { n   for (long long int i = 2; i * i <= k; i++) n     if (k % i == 0) { n       return false; n     } n   return true; n } n void pdash(int n = 1) { n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < 30; j++) { n       cout <<  - ; n     } n     cout <<   n ; n   } n } n long long int power(long long int x, long long int y) { n   long long int result = 1; n   while (y > 0) { n     if (y & 1) { n       result = (result * x); n     } n     y = y >> 1; n     x = (x * x); n   } n   return result; n } n long long int power(long long int x, long long int y, long long int z) { n   long long int result = 1; n   x = x % z; n   while (y > 0) { n     if (y & 1) { n       result = (result * x) % z; n     } n     y = y >> 1; n     x = (x * x) % z; n   } n   return result; n } n long long int modInverse(long long int n, long long int p) { n   return power(n, p - 2, p); n } n long long int nCrF(long long int n, long long int r, long long int p) { n   if (r == 0) return 1; n   long long int f[n + 1]; n   f[0] = 1; n   for (long long int i = 1; i <= n; i++) f[i] = f[i - 1] * i % p; n   return (f[n] * modInverse(f[r], p) % p * modInverse(f[n - r], p) % p) % p; n } n void solve() { n   int n, k; n   cin >> n >> k; n   int p, q; n   map<int, int> mp; n   for (int i = 1; i <= k + 1; i++) { n     cout <<  ?  ; n     for (int j = 1; j <= k + 1; j++) { n       if (j == i) n         continue; n       else n         cout << j <<    ; n     } n     cin >> p >> q; n     mp[q]++; n   } n   cout <<  !   << (*mp.rbegin()).second << endl; n   cout.flush(); n } n int main() { n   int t = 1; n   while (t--) { n     solve(); n   } n } n


#include <bits/stdc++.h> n const int MAXN = 2e5 + 10; n const double eps = 1e-8; n const int mod1 = 1e9 + 7; n const int mod2 = 1e9 + 9; n using namespace std; n struct edge { n   int t, v; n   edge *next; n } e[MAXN << 1], *h[MAXN], *o = e; n void add(int x, int y, int vul) { n   o->t = y; n   o->v = vul; n   o->next = h[x]; n   h[x] = o++; n } n long long read() { n   long long x = 0, f = 1; n   char ch = getchar(); n   while (!isdigit(ch)) { n     if (ch ==  - ) f = -1; n     ch = getchar(); n   } n   while (isdigit(ch)) x = x * 10 + ch -  0 , ch = getchar(); n   return x * f; n } n typedef struct node { n   char ch; n   long long num; n } node; n node d1[MAXN], d2[MAXN]; n long long sum1[MAXN], sum2[MAXN]; n long long ksm(long long a, long long b, long long c) { n   long long ans = 1; n   while (b) { n     if (b & 1) ans = ans * a % c; n     a = a * a % c; n     b = b >> 1; n   } n   return ans; n } n void Hash(int len) { n   for (int i = 1; i <= len; i++) { n     sum1[i] = (sum1[i - 1] * 131 % mod1 + n                ksm(ksm(131, d1[i].num, mod1), d1[i].ch, mod1)) % n               mod1; n     sum2[i] = (sum2[i - 1] * 233 % mod2 + n                ksm(ksm(233, d1[i].num, mod2), d1[i].ch, mod2)) % n               mod2; n   } n } n int main() { n   int n = read(), m = read(); n   int cnt1 = 0, cnt2 = 0; n   for (int i = 1; i <= n; i++) { n     int t; n     char ch; n     scanf( %d-%c , &t, &ch); n     if (i == 1 || ch != d1[cnt1].ch) n       d1[++cnt1] = (node){ch, t}; n     else n       d1[cnt1].num += t; n   } n   for (int i = 1; i <= m; i++) { n     int t; n     char ch; n     scanf( %d-%c , &t, &ch); n     if (i == 1 || ch != d2[cnt2].ch) n       d2[++cnt2] = (node){ch, t}; n     else n       d2[cnt2].num += t; n   } n   Hash(cnt1); n   long long base1 = 0, base2 = 0; n   for (int i = 2; i <= cnt2 - 1; i++) { n     base1 = n         (base1 * 131 % mod1 + ksm(ksm(131, d2[i].num, mod1), d2[i].ch, mod1)) % n         mod1; n     base2 = n         (base2 * 233 % mod2 + ksm(ksm(233, d2[i].num, mod2), d2[i].ch, mod2)) % n         mod2; n   } n   long long ans = 0; n   for (int i = 1; i <= cnt1; i++) { n     if (i + cnt2 - 1 > n) break; n     if (d1[i].ch == d2[1].ch && d1[i].num >= d2[1].num) { n       if (cnt2 == 1) { n         ans += d1[i].num - d2[1].num + 1; n         continue; n       } n       if (cnt2 == 2) { n         if (d1[i + 1].ch == d2[2].ch && d1[i + 1].num >= d2[2].num) { n           ans++; n         } n         continue; n       } n       int t1 = i + 1; n       int t2 = i + cnt2 - 2; n       long long tt1 = n           (sum1[t2] - sum1[t1 - 1] * ksm(131, t2 - i, mod1) % mod1 + mod1) % n           mod1; n       long long tt2 = n           (sum2[t2] - sum2[t1 - 1] * ksm(233, t2 - i, mod2) % mod2 + mod2) % n           mod2; n       if (tt1 != base1 || tt2 != base2) continue; n       if (d1[i + cnt2 - 1].ch == d2[cnt2].ch && n           d1[i + cnt2 - 1].num >= d2[cnt2].num) n         ans++; n     } n   } n   printf( %lld n , ans); n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n using v2d = vector<vector<T> >; 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 mt19937 rng(chrono::system_clock::now().time_since_epoch().count()); n const int maxN = 2e5 + 1; n int n, k; n int l[maxN], r[maxN]; n vector<int> ps[maxN]; n vector<int> rm[maxN]; n set<pair<int, int> > st; n vector<int> res; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n   cin >> n >> k; n   for (int i = 1; i <= (int)(n); ++i) { n     cin >> l[i] >> r[i]; n     ps[l[i]].emplace_back(i); n     rm[r[i]].emplace_back(i); n   } n   for (int i = 1; i <= (int)(2e5); ++i) { n     for (auto &p : ps[i]) { n       st.emplace(-r[p], p); n     } n     while ((int)st.size() > k) { n       res.emplace_back(st.begin()->second); n       st.erase(st.begin()); n     } n     for (auto &p : rm[i]) { n       if (st.count({-r[p], p})) { n         st.erase({-r[p], p}); n       } n     } n   } n   cout << (int)res.size() <<   n ; n   for (auto &r : res) { n     cout << r <<    ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 20; n int a[N], b[N], c[N], d[N], ln[N], rn[N], lm[N], rm[N]; n int main() { n   int n, m; n   cin >> n >> m; n   for (int i = 1; i <= n; i++) { n     cin >> a[i] >> b[i]; n     if (a[i] > b[i]) swap(a[i], b[i]); n   } n   set<int> st; n   for (int i = 1; i <= m; i++) { n     cin >> c[i] >> d[i]; n     if (c[i] > d[i]) swap(c[i], d[i]); n     for (int j = 1; j <= n; j++) { n       if (a[j] == c[i] && b[j] == d[i]) continue; n       if (a[j] == c[i]) ln[j] = lm[i] = 1, st.insert(a[j]); n       if (a[j] == d[i]) ln[j] = rm[i] = 1, st.insert(a[j]); n       if (b[j] == c[i]) rn[j] = lm[i] = 1, st.insert(b[j]); n       if (b[j] == d[i]) rn[j] = rm[i] = 1, st.insert(b[j]); n     } n   } n   for (int i = 1; i <= n; i++) n     if (ln[i] && rn[i]) { n       puts( -1 ); n       return 0; n     } n   for (int i = 1; i <= m; i++) n     if (lm[i] && rm[i]) { n       puts( -1 ); n       return 0; n     } n   if (st.size() == 1) { n     cout << *st.begin(); n     return 0; n   } n   puts( 0 ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 2e5 + 5; n const int oo = 0x3f3f3f3f; n const int LIM = 2e5; n int N, a[MAXN], num[MAXN], top, f[MAXN], ans[MAXN]; n vector<int> S[MAXN]; n int gcd(int a, int b) { return !b ? a : gcd(b, a % b); } n namespace Graph { n struct edge { n   int y, next; n } e[MAXN << 1]; n int LINK[MAXN], len = 0; n inline void ins(int x, int y) { n   e[++len].next = LINK[x]; n   LINK[x] = len; n   e[len].y = y; n } n inline void Ins(int x, int y) { n   ins(x, y); n   ins(y, x); n } n void DFS(int node, int fa) { n   top = 0; n   S[node].push_back(f[fa]); n   f[node] = gcd(f[fa], a[node]); n   ans[node] = max(ans[node], f[node]); n   for (int i = 0; i <= (int)S[fa].size() - 1; i++) n     num[++top] = gcd(S[fa][i], a[node]); n   num[++top] = f[fa]; n   sort(num + 1, num + top + 1); n   top = unique(num + 1, num + top + 1) - (num + 1); n   ans[node] = max(ans[node], num[top]); n   for (int i = 1; i <= top; i++) S[node].push_back(num[i]); n   for (int i = LINK[node]; i; i = e[i].next) n     if (e[i].y != fa) DFS(e[i].y, node); n } n }  // namespace Graph n using namespace Graph; n namespace solution { n void Prepare() { n   scanf( %d , &N); n   for (int i = 1; i <= N; i++) scanf( %d , &a[i]); n   for (int i = 2; i <= N; i++) { n     int x, y; n     scanf( %d%d , &x, &y); n     Ins(x, y); n   } n } n void Solve() { n   DFS(1, 0); n   for (int i = 1; i <= N; i++) printf( %d  , ans[i]); n   puts(  ); n } n }  // namespace solution n int main() { n   using namespace solution; n   Prepare(); n   Solve(); n   return 0; n } n


#include <bits/stdc++.h> n int n, m; n int main() { n   int i, j, T; n   long long k, total, w; n   while (scanf( %I64d%I64d%I64d , &k, &total, &w) != EOF) { n     long long ans = (1 + w) * w / 2; n     ans *= k; n     if (ans - total >= 0) n       printf( %I64d n , ans - total); n     else n       printf( 0 n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1000000 + 5; n const int inf = 0x3f3f3f3f; n int n; n char y[maxn * 2], a[maxn * 2]; n int main() { n   cin >> n; n   scanf( %s , y); n   scanf( %s , a); n   int ycnt = 0; n   for (int i = 0; i < n * 2; i++) { n     if (y[i] ==  1 ) ycnt++; n   } n   int acnt = 0; n   for (int i = 0; i < n * 2; i++) { n     if (a[i] ==  1 ) acnt++; n   } n   int ty = 0; n   int cnt = 0; n   for (int i = 0; i < n * 2; i++) { n     if (a[i] ==  1  && y[i] ==  1 ) cnt++; n   } n   if (cnt % 2 == 0) { n     if (acnt - ycnt >= 2) n       ty = 2; n     else if (acnt - ycnt < 2 && acnt - ycnt >= 0) n       ty = 0; n     else n       ty = 1; n   } else { n     if (acnt - ycnt > 3) n       ty = 2; n     else if (acnt - ycnt <= 3 && acnt - ycnt >= 1) n       ty = 0; n     else n       ty = 1; n   } n   if (ty == 1) printf( First n ); n   if (ty == 2) printf( Second n ); n   if (ty == 0) printf( Draw n ); n   return 0; n } n


//Iamskk// n #include <iostream> n #include <iosfwd> n #include <iomanip> n #include <cstdio> n #include <cstring> n #include <cstdlib> n #include <ctime> n #include <cmath> n #include <cassert> n #include <cctype> n #include <climits> n #include <vector> n #include <bitset> n #include <set> n #include <queue> n #include <stack> n #include <map> n #include <deque> n #include <string> n #include <list> n #include <iterator> n #include <sstream> n #include <complex> n #include <fstream> n #include <functional> n #include <numeric> n #include <utility> n #include <algorithm> n #include <assert.h> n #include <unordered_map> n using namespace std; n #define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0); n #define endl   n  n #define yes cout<< YES <<endl n #define no cout<< NO <<endl n #define pb push_back n #define all(c) (c).begin(),(c).end() n #define rall(c) (c).rbegin(),(c).rend() n #define ai(arr,n) for(int i=0;i<n;i++)cin>>arr[i]; n #define ao(arr) for(auto asdfasdfasdf:arr) cout<<asdfasdfasdf<<   ; n #define mi(arr,m,n) for(int i=0;i<m;i++){ for(int j=0;j<n;j++) cin>>arr[i][j];} n #define mo(arr,m,n) for(int i=0;i<m;i++){ for(int j=0;j<n;j++) cout<<arr[i][j]<<   ; cout<<endl;} n #define countsetbits(x) __builtin_popcount(x) n #define ll long long n #define debug cout<< I AM EXECUTING <<endl n #define testcases int asdf; cin>>asdf; while(asdf--) n #define vi vector<int> n #define vll vector<long long int> n #define vppo(prs) for(auto x:prs){cout<<x.first<<   <<x.second<<endl;} n #define For(__,hajmola,adfdf) for(int __ = hajmola; __<adfdf;__++) n #define formax 1e18 n #define formin -1e18 n string sconvert(ll int n) n { n  stringstream ss; n  ss<<n; n  string str = ss.str(); n  return str; n } n bool sortbysec(const pair<int,int> &a,  n               const pair<int,int> &b)  n {  n     return (a.second > b.second);  n } n  n template<typename T> n void imax(T &x,T y){ n  x = max(x,y); n } n template<typename T> n void imin(T &x,T y){ n  x = min(x,y); n } n const int nax = 2e3+1; n ll int dp[nax][nax]; n vector<ll int> krr; n ll int answer = 0; n ll int solve(int left,int right){ n  if(dp[left][right]!=-1){ n   return dp[left][right]; n  } n   if(left>=right){ n    return 0; n   } n      ll int value = krr[right]-krr[left]; n      return dp[left][right]=value + min(solve(left+1,right),solve(left,right-1)); n       n } n void  single() n { n  memset(dp,-1,sizeof(dp)); n  int n; n  cin>>n; n  vector<ll int> arr(n); n  ai(arr,n); n  sort(all(arr)); n  krr = arr; n  answer = solve(0,n-1); n  cout<<answer<<endl; n  // answer = *max_element(all(arr))-*min_element(all(arr)); n  n  return; n } n void multiple() n { n  testcases n     { n   single(); n  } n } n  n int main() n { n   IOS; n  // freopen( input.txt , r ,stdin); n   //freopen( output.txt , w ,stdout); n   single(); n } n  n  n  n  n  n  n  n  n  n  n  n  n  n  n  n  n  n


#include <bits/stdc++.h> n using namespace std; n const int mod = 1e9 + 7; n const int maxn = 2e6 + 10; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   int n, m, k; n   cin >> n >> m >> k; n   if (n == 1 && m == 1) { n     cout <<  0 ; n     return 0; n   } n   if (n * m == 2) { n     cout <<  4 nUDLR ; n     return 0; n   } n   int t = n - 1 + m - 1 + n * m; n   cout << t <<   n ; n   for (int i = (0); i < (n - 1); ++i) cout <<  U ; n   for (int i = (0); i < (m - 1); ++i) cout <<  L ; n   for (int i = (1); i < (n + 1); ++i) { n     if (i & 1) { n       for (int j = (0); j < (m - 1); ++j) cout <<  R ; n       cout <<  D ; n     } else { n       for (int j = (0); j < (m - 1); ++j) cout <<  L ; n       cout <<  D ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n #pragma warning(disable : 4996) n using namespace std; n using namespace std; n const double eps = 1e-8; n const double pi = acos(-1.0); n inline double sqr(double x) { return x * x; } n int cmp(double x) { n   if (fabs(x) < eps) return 0; n   if (x > 0) return 1; n   return -1; n } n int n; n struct point { n   double x, y; n   point() {} n   point(double a, double b) : x(a), y(b) {} n   void input() { scanf( %lf%lf , &x, &y); } n   friend point operator+(const point &a, const point &b) { n     return point(a.x + b.x, a.y + b.y); n   } n   friend point operator-(const point &a, const point &b) { n     return point(a.x - b.x, a.y - b.y); n   } n   friend bool operator==(const point &a, const point &b) { n     return cmp(a.x - b.x) == 0 && cmp(a.y - b.y) == 0; n   } n   friend point operator*(const point &a, const double &b) { n     return point(a.x * b, a.y * b); n   } n   friend point operator*(const double &a, const point &b) { n     return point(a * b.x, a * b.y); n   } n   friend point operator/(const point &a, const double &b) { n     return point(a.x / b, a.y / b); n   } n   double norm() { return sqrt(sqr(x) + sqr(y)); } n   double norm1() { return sqr(x) + sqr(y); } n } P[200]; n double det(const point &a, const point &b) { return a.x * b.y - a.y * b.x; } n point Cir(point a, point b, point c) { n   point cp; n   double a1 = b.x - a.x, b1 = b.y - a.y, c1 = (a1 * a1 + b1 * b1) / 2; n   double a2 = c.x - a.x, b2 = c.y - a.y, c2 = (a2 * a2 + b2 * b2) / 2; n   double d = a1 * b2 - a2 * b1; n   cp.x = a.x + (c1 * b2 - c2 * b1) / d; n   cp.y = a.y + (a1 * c2 - a2 * c1) / d; n   return cp; n } n double dot(const point &a, const point &b) { return a.x * b.y + a.y * b.x; } n double dist(const point &a, const point &b) { return (a - b).norm(); } n double dist2(const point &a, const point &b) { return (a - b).norm1(); } n bool JudgeRet(int a, int b, int c) { n   double dis1 = dist2(P[a], P[b]); n   double dis2 = dist2(P[a], P[c]); n   double dis3 = dist2(P[b], P[c]); n   if ((cmp(dis1 + dis2 - dis3) == 1) && (cmp(dis2 + dis3 - dis1) == 1) && n       (cmp(dis1 + dis3 - dis2) == 1)) n     return true; n   else if (cmp(dis1 + dis2 - dis3) == 0 || cmp(dis1 + dis3 - dis2) == 0 || n            cmp(dis2 + dis3 - dis1) == 0) { n     if (cmp(dis1 + dis2 - dis3) == 0) { n       for (int i = 1; i <= n; i++) { n         if (cmp(P[i].x - (P[b].x + P[c].x - P[a].x)) == 0 && n             cmp(P[i].y - (P[b].y + P[c].y - P[a].y)) == 0) { n           return true; n         } n       } n     } else if (cmp(dis1 + dis3 - dis2) == 0) { n       for (int i = 1; i <= n; i++) { n         if (cmp(P[i].x - (P[a].x + P[c].x - P[b].x)) == 0 && n             cmp(P[i].y - (P[a].y + P[c].y - P[b].y)) == 0) { n           return true; n         } n       } n     } else { n       for (int i = 1; i <= n; i++) { n         if (cmp(P[i].x - (P[a].x + P[b].x - P[c].x)) == 0 && n             cmp(P[i].y - (P[a].y + P[b].y - P[c].y)) == 0) { n           return true; n         } n       } n     } n     return false; n   } else n     return false; n } n void Compute() { n   double Max = -1; n   JudgeRet(2, 3, 5); n   for (int i = 1; i <= n; i++) { n     for (int j = i + 1; j <= n; j++) { n       for (int k = j + 1; k <= n; k++) { n         if (JudgeRet(i, j, k)) { n           point center = Cir(P[i], P[j], P[k]); n           double r = dist(center, P[i]); n           bool ret = true; n           for (int i = 1; i <= n; i++) { n             if (cmp(dist(center, P[i]) - r) == -1) { n               ret = false; n               break; n             } n           } n           if (ret) Max = max(Max, r); n         } n       } n     } n   } n   if (Max == -1) n     printf( -1 n ); n   else n     printf( %.6f n , Max); n } n int main() { n   double x, y; n   while (~scanf( %d , &n)) { n     for (int i = 1; i <= n; i++) { n       scanf( %lf%lf , &x, &y); n       P[i] = point(x, y); n     } n     Compute(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int p[6005], q[6005]; n bool check(int a, int b, int x) { return x > a && x < b; } n bool check2(int a, int b, int x) { return x >= a && x <= b; } n bool isOK(int a, int b) { return a == b; } n int sx[1005], sy[1005]; n int main() { n   int n, t, i, j, a, x, k; n   memset(p, 0, sizeof p); n   memset(q, 0, sizeof q); n   scanf( %d%d , &n, &t); n   for (i = 0; i < n; ++i) { n     scanf( %d%d , &x, &a); n     x *= 2; n     sx[i] = x - a; n     sy[i] = x + a; n     for (j = 6000; j > 0; --j) { n       k = -j; n       if (p[j] == -1) continue; n       if (check2(x - a, x + a, k) || check(x - a, x + a, k - t) || n           check(x - a, x + a, k + t)) { n         p[j] = -1; n         continue; n       } n       if (p[j] == 0) { n         if (isOK(x - a, k + t) || isOK(x + a, k - t)) { n           p[j] = 1; n         } n       } n     } n     for (j = 0; j <= 6000; ++j) { n       k = j; n       if (q[j] == -1) continue; n       if (check2(x - a, x + a, k) || check(x - a, x + a, k - t) || n           check(x - a, x + a, k + t)) { n         q[j] = -1; n         continue; n       } n       if (q[j] == 0) { n         if (isOK(x - a, k + t) || isOK(x + a, k - t)) q[j] = 1; n       } n     } n   } n   for (j = 0, i = 1; i <= 6000; ++i) n     if (p[i] == 1) { n       for (k = 0; k < n; ++k) { n         if (check(-i - t, -i + t, sx[k]) || check(-i - t, -i + t, sy[k])) break; n       } n       if (k == n) ++j; n     } n   for (i = 0; i <= 6000; ++i) n     if (q[i] == 1) { n       for (k = 0; k < n; ++k) { n         if (check(i - t, i + t, sx[k]) || check(i - t, i + t, sy[k])) break; n       } n       if (k == n) ++j; n     } n   printf( %d n , j); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int n, b; n   cin >> n >> b; n   std::vector<long long int> v(n); n   long long int maxp = 0, minp = 0; n   long long int m1, m2 = 0; n   for (long long int i = 0; i < n; ++i) { n     cin >> v[i]; n     if (i == 0) m1 = v[i]; n     if (m2 < v[i]) { n       maxp = i; n       m2 = v[i]; n     } n     if (m1 > v[i]) { n       minp = i; n       m1 = v[i]; n     } n   } n   std::vector<long long int> v2(v.begin(), v.end()); n   sort(v2.begin(), v2.end(), greater<long long int>()); n   long long int currmax = 0, ans = 0; n   if (v == v2 || maxp == minp) { n     cout << b; n   } else { n     if (maxp > minp) { n       ans = b / m1 * m2 + b % m1; n       cout << ans; n     } else if (maxp < minp) { n       for (long long int i = 0; i < n - 1; ++i) { n         long long int maxi = v[i]; n         for (long long int j = i + 1; j < n; ++j) { n           if (v[j] > maxi) { n             maxi = v[j]; n           } n         } n         ans = b / v[i] * maxi + b % v[i]; n         if (ans > currmax) { n           currmax = ans; n         } n       } n       cout << currmax; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> v[20001]; n struct triplet { n   int x, y, z, sum; n }; n int a, b, c; n void init() { n   for (int i = 1; i <= 20000; ++i) { n     for (int j = i; j <= 20000; j += i) v[j].push_back(i); n   } n } n triplet calc(int n) { n   triplet res; n   int ans = 1000000; n   for (int fac : v[n]) { n     int idx = lower_bound(v[fac].begin(), v[fac].end(), a) - v[fac].begin(); n     int idx1 = upper_bound(v[fac].begin(), v[fac].end(), a) - v[fac].begin(); n     if (idx1 != 0) idx1--; n     if (abs(v[fac][idx1] - a) < abs(v[fac][idx] - a)) idx = idx1; n     int val = abs(v[fac][idx] - a) + abs(fac - b) + abs(n - c); n     if (val < ans) { n       ans = val; n       res.x = v[fac][idx]; n       res.y = fac; n       res.z = n; n       res.sum = ans; n     } n   } n   return res; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   init(); n   int tc; n   cin >> tc; n   while (tc--) { n     cin >> a >> b >> c; n     int ans = 1000000; n     triplet fin; n     for (int i = 1; i <= 20000; ++i) { n       triplet res = calc(i); n       if (res.sum < ans) { n         ans = res.sum; n         fin.x = res.x; n         fin.y = res.y; n         fin.z = res.z; n         fin.sum = res.sum; n       } n     } n     cout << ans <<   n ; n     cout << fin.x <<     << fin.y <<     << fin.z <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main(void) { n   int n; n   int answer = -1; n   long sum_x[2] = {0}; n   long sum_y[2] = {0}; n   int nr[2] = {0}; n   int i; n   scanf( %d n , &n); n   for (i = 0; i < n; i++) { n     int t, x, y; n     scanf( %d %d %d n , &t, &x, &y); n     if (t == 1) { n       sum_x[0] += x; n       sum_y[0] += y; n       nr[0]++; n     } else { n       sum_x[1] += x; n       sum_y[1] += y; n       nr[1]++; n     } n   } n   for (i = 0; i < 2; i++) { n     if (sum_x[i] / nr[i] >= 5) n       printf( LIVE n ); n     else n       printf( DEAD n ); n   } n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:102400000,102400000 ) n using namespace std; n int main() { n   int n, m; n   cin >> n >> m; n   int ret = 0; n   while (n--) { n     char str[1009]; n     int cnt = 0; n     scanf( %s , str); n     int flag = 1; n     for (int i = 0; str[i]; i++) { n       if (str[i] ==  4  || str[i] ==  7 ) { n         cnt++; n         if (cnt > m) { n           flag = 0; n           break; n         } n       } n     } n     if (flag == 1) { n       ret++; n     } n   } n   cout << ret << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct query { n   int k, pos, ind; n } queries[200005]; n struct arr { n   int val, ind; n } a[200005]; n long long n, q, cnt, res[200005], fw[200005], it[4 * 200005], len, b[200005]; n bool cmp(arr a, arr b) { n   if (a.val != b.val) return a.val > b.val; n   return a.ind < b.ind; n } n bool que(query a, query b) { return a.k < b.k; } n void update(long long k, long long l, long long r, long long id) { n   if (l == r) { n     it[k] = 1; n     return; n   } n   long long mid = (l + r) / 2; n   if (id <= mid) n     update(k * 2, l, mid, id); n   else n     update(k * 2 + 1, mid + 1, r, id); n   it[k] = it[k * 2] + it[k * 2 + 1]; n } n long long get(long long k, long long l, long long r, long long id) { n   if (id > it[k]) return -1; n   if (l == r) return l; n   long long mid = (l + r) / 2; n   if (id <= it[k * 2]) n     return get(k * 2, l, mid, id); n   else n     return get(k * 2 + 1, mid + 1, r, id - it[k * 2]); n } n int main() { n   cin.tie(NULL); n   ios_base::sync_with_stdio(false); n   cin >> n; n   for (int i = 1; i <= n; i++) { n     cin >> a[i].val; n     a[i].ind = i; n     b[i] = a[i].val; n   } n   sort(a + 1, a + 1 + n, cmp); n   cin >> q; n   for (int i = 1; i <= q; i++) { n     cin >> queries[i].k >> queries[i].pos; n     queries[i].ind = i; n   } n   sort(queries + 1, queries + 1 + q, que); n   for (int i = 1; i <= q; i++) { n     while (len != queries[i].k) { n       len++; n       update(1, 1, n, a[len].ind); n     } n     res[queries[i].ind] = b[get(1, 1, n, queries[i].pos)]; n   } n   for (int i = 1; i <= q; i++) cout << res[i] << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long n, i, j, a[1000005], b[1000005], p = 0, q = 0, m, temp = 0, n                                              flag = 0, ans, r = 0, s = 0; n   vector<long long> v; n   string str; n   cin >> n; n   map<long long, long long> mp; n   while (1) { n     if (mp[n] == 1) { n       break; n     } n     mp[n] = 1; n     p++; n     n++; n     while (n % 10 == 0) { n       n = n / 10; n     } n   } n   cout << p; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m; n   scanf( %d%d , &n, &m); n   if (m < n - 1 || m > 2 * (n + 1)) { n     printf( -1 n ); n   } else if (m == n || m == n - 1) { n     int flg = 0; n     while (m || n) { n       if (!flg) { n         printf( 0 ); n         n--; n         flg = 1; n       } else { n         printf( 1 ); n         m--; n         flg = 0; n       } n     } n     printf(  n ); n   } else if (m == n + 1) { n     while (n) { n       printf( 10 ); n       n -= 1; n     } n     printf( 1 n ); n   } else { n     while (m != n && n > 0) { n       printf( 110 ); n       m -= 2; n       n -= 1; n     } n     if (n == 0) { n       while (m--) { n         printf( 1 ); n       } n     } else { n       while (n--) { n         printf( 10 ); n       } n     } n     printf(  n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a[10000] = {0}, b[10000] = {0}, n, k, dem = 0; n int main() { n   cin >> n >> k; n   for (int i = (1), _b = (k); i <= _b; i++) { n     cin >> a[i]; n     b[a[i]] = i; n   } n   for (int i = (1), _b = (k); i <= _b; i++) { n     dem = 1; n     cout << a[i]; n     for (int j = (1), _b = (n * k); j <= _b; j++) n       if (b[j] == 0) { n         dem++; n         cout <<     << j; n         b[j] = i; n         if (dem == n) break; n       } n     cout << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long INF = 99999999999999999; n long long n, value[200000], zarib[200000], LCM = 1, GCD, x = INF, ans, sum; n vector<int> Tree[200000]; n long long gcd(long long l, long long r) { n   if (!l) return r; n   return gcd(r % l, l); n } n bool dfs(int v, int last, long long z) { n   zarib[v] = z; n   if (v && Tree[v].size() == 1 && zarib[v] > sum) return 0; n   z *= (Tree[v].size() - 1); n   if (!z) z = 1; n   for (int i = 0; i < Tree[v].size(); i++) n     if (Tree[v][i] != last) n       if (!dfs(Tree[v][i], v, z)) return 0; n   return 1; n } n int main() { n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> value[i]; n     sum += value[i]; n   } n   for (int i = 1; i < n; i++) { n     int l, r; n     cin >> l >> r; n     Tree[l - 1].push_back(r - 1); n     Tree[r - 1].push_back(l - 1); n   } n   if (!dfs(0, -1, 1)) { n     cout << sum << endl; n     return 0; n   } n   for (int i = 1; i < n; i++) n     if (Tree[i].size() == 1) { n       GCD = gcd(LCM, zarib[i]); n       LCM /= GCD; n       LCM *= zarib[i]; n     } n   for (int i = 1; i < n; i++) n     if (Tree[i].size() == 1) { n       zarib[i] = LCM / zarib[i]; n       x = min(x, value[i] / zarib[i]); n     } n   for (int i = 1; i < n; i++) n     if (Tree[i].size() == 1) ans += value[i] - zarib[i] * x; n   cout << ans << endl; n } n


#include <bits/stdc++.h> n const int maxn = 100001; n int n, i, u, v, top, a[maxn], spt[maxn], vt[maxn], st[maxn], l[maxn]; n long long sum, ans, tmp, val[maxn], uc, bc, ss, min; n std::vector<int> adj[maxn]; n void dfs() { n   top = 1; n   st[1] = 1; n   while (top > 0) { n     u = st[top]; n     if (vt[u] < spt[u] && adj[u][vt[u]] == st[top - 1]) vt[u]++; n     if (vt[u] < spt[u]) { n       if (u == 1) n         tmp *= spt[u]; n       else n         tmp *= (spt[u] - 1); n       if (tmp > sum) { n         ans = -1; n         return; n       } n       st[++top] = adj[u][vt[u]]; n       vt[u]++; n     } else { n       if (spt[u] == 1 && u != 1) { n         val[u] = tmp; n         uc = tmp; n         l[++l[0]] = u; n       } n       top--; n       if (st[top] == 1) n         tmp /= spt[st[top]]; n       else n         tmp /= (spt[st[top]] - 1); n     } n   } n } n long long ucln(long long a, long long b) { n   while (a > 0 && b > 0) n     if (a > b) n       a %= b; n     else n       b %= a; n   if (a > 0) n     return a; n   else n     return b; n } n int main() { n   std::cin >> n; n   for (i = 1; i <= n; i++) { n     std::cin >> a[i]; n     sum += a[i]; n   } n   for (i = 1; i < n; i++) { n     std::cin >> u >> v; n     spt[u]++; n     spt[v]++; n     adj[u].push_back(v); n     adj[v].push_back(u); n   } n   tmp = 1; n   dfs(); n   if (ans == -1) { n     std::cout << sum; n     return 0; n   } n   bc = val[l[1]]; n   for (i = 2; i <= l[0]; i++) { n     uc = ucln(bc, val[l[i]]); n     bc /= uc; n     if (bc > double(sum) / val[i]) { n       std::cout << sum; n       return 0; n     } n     bc *= val[l[i]]; n   } n   min = 1000000000000000000; n   for (i = 1; i <= l[0]; i++) { n     val[l[i]] = bc / val[l[i]]; n     if (min > a[l[i]] / val[l[i]]) min = a[l[i]] / val[l[i]]; n   } n   if (min == 0) { n     std::cout << sum; n     return 0; n   } n   for (i = 1; i <= l[0]; i++) ans += a[l[i]] - val[l[i]] * min; n   std::cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n int value(const std::vector<int>& xs, int base, int i) { n   return (xs[(base + i) % xs.size()] + 10 - xs[base]) % 10; n } n bool lt(const std::vector<int>& xs, int a, int b) { n   int N = xs.size(); n   for (int i = 0; i < N; ++i) { n     int va = value(xs, a, i), vb = value(xs, b, i); n     if (va != vb) return va < vb; n   } n   return false; n } n int main() { n   int N; n   std::cin >> N; n   std::string s; n   std::cin >> s; n   std::vector<int> xs(N), is(N); n   for (int i = 0; i < N; ++i) xs[i] = s[i] -  0 , is[i] = i; n   std::sort(is.begin(), is.end(), [&](int a, int b) { return lt(xs, a, b); }); n   for (int i = 0; i < N; ++i) std::cout << value(xs, is[0], i); n   std::cout <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   cin >> t; n   while (t--) { n     int long long n, a[60], mx = 2000; n     scanf( %lld , &n); n     for (int i = 0; i < n; i++) { n       scanf( %lld , &a[i]); n     } n     sort(a, a + n); n     for (int i = 1; i < n; i++) { n       mx = min(mx, abs(a[i - 1] - a[i])); n     } n     printf( %lld n , mx); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1000005; n long long f[N], g[N], a[N], ans; n int n, F1, F2, F3, F4, F5, F6, k; n inline void upd(long long &x, long long y) { n   if (x < y) x = y; n } n inline int calc(int y, int x) { n   if (x * 9 < y) return -1e9; n   if (y % 3 == 0) return y / 3; n   if ((x - 1) * 9 >= y) return y / 3; n   return (y / 9) * 3; n } n int main() { n   scanf( %d , &n); n   scanf( %d%d%d%d%d%d , &F1, &F2, &F3, &F4, &F5, &F6); n   scanf( %d , &k); n   scanf( %d , &k); n   for (int i = 0; i <= 9; i++) f[i] = (long long)calc(i, n) * F6; n   for (int i = 0; i < N; i++) g[i] = -1e18; n   for (int i = 0; i <= 99; i++) a[i] = (long long)calc(i, n) * F5; n   for (int i = 0; i <= 9; i++) { n     const int x = i * 10; n     for (int j = 0; j <= 99 - x; j++) upd(g[x + j], f[i] + a[j]); n   } n   for (int i = 0; i <= 99; i++) f[i] = g[i], g[i] = -1e18; n   for (int i = 0; i <= 999; i++) a[i] = (long long)calc(i, n) * F4; n   for (int i = 0; i <= 99; i++) { n     const int x = i * 10; n     for (int j = 0; j <= 999 - x; j++) upd(g[x + j], f[i] + a[j]); n   } n   for (int i = 0; i <= 999; i++) f[i] = g[i], g[i] = -1e18; n   for (int i = 0; i <= 9999; i++) a[i] = (long long)calc(i, n) * F3; n   for (int i = 0; i <= 999; i++) { n     const int x = i * 10; n     for (int j = 0; j <= 9999 - x; j++) upd(g[x + j], f[i] + a[j]); n   } n   for (int i = 0; i <= 9999; i++) f[i] = g[i], g[i] = -1e18; n   for (int i = 0; i <= 99999; i++) a[i] = (long long)calc(i, n) * F2; n   for (int i = 0; i <= 9999; i++) { n     const int x = i * 10; n     for (int j = 0; j <= 99999 - x; j++) upd(g[x + j], f[i] + a[j]); n   } n   for (int i = 0; i <= 99999; i++) f[i] = g[i], g[i] = -1e18; n   for (int i = 0; i <= k; i++) a[i] = (long long)calc(i, n) * F1; n   for (int i = 0; i <= k / 10; i++) upd(ans, a[k - i * 10] + f[i]); n   printf( %lld n , ans); n } n


#include <bits/stdc++.h> n using namespace std; n int gcd(int a, int b) { n   while (b) { n     int r = a % b; n     a = b; n     b = r; n   } n   return a; n } n int64_t lcm(int a, int b) { return 1LL * a * b / gcd(a, b); } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n   int n; n   cin >> n; n   vector<int> next(n + 1); n   for (int i = 1; i <= n; i++) cin >> next[i]; n   int64_t ans = 1; n   vector<bool> cycle(n + 1); n   for (int i = 1; i <= n; i++) n     if (!cycle[i]) { n       int node = i; n       vector<int> vis(n + 1); n       for (int j = 0; j < n + 1; j++) { n         vis[node]++; n         node = next[node]; n       } n       if (vis[i] >= 2) { n         int len = 0, node = i; n         while (!cycle[node]) { n           len++; n           cycle[node] = true; n           node = next[node]; n         } n         ans = lcm(ans, len); n       } n     } n   int mx = 0; n   for (int i = 1; i <= n; i++) n     if (!cycle[i]) { n       int dist = 0, node = i; n       while (!cycle[node]) { n         dist++; n         node = next[node]; n       } n       mx = max(mx, dist); n     } n   int it = 1; n   while (it * ans < mx) it++; n   cout << it * ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t = 1; n   while (t--) { n     int n, k, inits[26]; n     char str[101]; n     bool poss = false, started[26] = {false}; n     scanf( %d%s , &k, str); n     n = strlen(str); n     if (n < k) { n       puts( NO ); n       break; n     } n     int cnt = 0; n     for (int i = 0, j = 0; i < n; i++) { n       if (!started[str[i] -  a ]) { n         started[str[i] -  a ] = 1; n         cnt++; n         inits[j] = i; n         j++; n       } n       if (cnt == k) { n         poss = true; n         break; n       } n     } n     if (!poss) n       puts( NO ); n     else { n       puts( YES ); n       int i = 0; n       for (int j = 0; j < n; j++) { n         if (j == inits[i + 1] - 1) { n           printf( %c n , str[j]); n           i++; n         } else n           printf( %c , str[j]); n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) { n   return (a.second < b.second); n } 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 int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int t; n   cin >> t; n   while (t--) { n     string s; n     cin >> s; n     int flag0 = 0, flag2 = 0, sum = 0; n     for (long long int i = 0; i < s.length(); i++) { n       if ((s[i] ==  0 ) && (flag0 == 0)) n         flag0 = 1; n       else if (int(s[i] -  0 ) % 2 == 0) n         flag2 = 1; n       sum += int(s[i] -  0 ); n     } n     if ((flag0) && (flag2) && (sum % 3 == 0)) n       cout <<  red  n            <<   n ; n     else n       cout <<  cyan  n            <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 20; n const int mod = 998244353; n struct node { n   int sum, tot; n   node(){}; n   node(int S, int T) { n     sum = S; n     tot = T; n   } n   bool check() { return ~sum && ~tot; } n } f[2][2][N][1 << 10]; n int A[N], ret, pw[30], k; n int lowbit(int x) { return x & -x; } n int ccount(int x) { n   int cnt = 0; n   if (!x) return 0; n   while (x) { n     x ^= lowbit(x); n     cnt++; n   } n   return cnt; n } n node dfs(bool lim, bool zero, int pos, int st) { n   if (!pos) return node(0, 1); n   node& now = f[lim][zero][pos][st]; n   if (now.check()) return now; n   now.sum = now.tot = 0; n   for (int i = 0; i <= (lim ? A[pos] : 9); i++) { n     if (ccount(zero && !i ? 0 : st | (1 << i)) <= k) { n       node nxt = dfs(lim && i == A[pos], zero && !i, pos - 1, n                      zero && !i ? 0 : st | (1 << i)); n       now.sum = n           (now.sum + nxt.sum + 1ll * i * nxt.tot % mod * pw[pos - 1] % mod) % n           mod; n       now.tot = (now.tot + nxt.tot) % mod; n     } n   } n   f[lim][zero][pos][st] = now; n   return now; n } n int calc(long long x) { n   ret = 0; n   memset(f, -1, sizeof(f)); n   while (x) { n     A[++ret] = x % 10; n     x /= 10; n   } n   return dfs(1, 1, ret, 0).sum; n } n int main() { n   pw[0] = 1; n   for (int i = 1; i <= 20; i++) pw[i] = 10ll * pw[i - 1] % mod; n   long long l, r; n   cin >> l >> r >> k; n   cout << (mod + calc(r) - calc(l - 1)) % mod; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1005; n const int dx[] = {0, 0, -1, 1}; n const int dy[] = {-1, 1, 0, 0}; n char mat[N][N]; n int dist[N][N][3]; n signed main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int n, m; n   cin >> n >> m; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       cin >> mat[i][j]; n     } n   } n   for (int i = 0; i < 3; i++) { n     list<pair<int, int> > q; n     for (int x = 0; x < n; x++) { n       for (int y = 0; y < m; y++) { n         if (mat[x][y] ==  1  + i) { n           dist[x][y][i] = 0; n           q.emplace_back(x, y); n         } else n           dist[x][y][i] = -1; n       } n     } n     while (!q.empty()) { n       int x = q.front().first, y = q.front().second; n       q.pop_front(); n       for (int j = 0; j < 4; j++) { n         int tx = x + dx[j], ty = y + dy[j]; n         if (tx >= 0 && tx < n && ty >= 0 && ty < m && mat[tx][ty] !=  # ) { n           int td = dist[x][y][i] + (mat[tx][ty] ==  . ); n           if (dist[tx][ty][i] == -1 || dist[tx][ty][i] > td) { n             dist[tx][ty][i] = td; n             if (mat[tx][ty] ==  . ) n               q.emplace_back(tx, ty); n             else n               q.emplace_front(tx, ty); n           } n         } n       } n     } n   } n   int ans = 1000000000; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       if (dist[i][j][0] != -1 && dist[i][j][1] != -1 && dist[i][j][2] != -1) { n         ans = min(ans, dist[i][j][0] + dist[i][j][1] + dist[i][j][2] - n                            2 * (mat[i][j] ==  . )); n       } n     } n   } n   cout << (ans == 1000000000 ? -1 : ans); n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1100; n template <class nmsl> n inline void read(nmsl &x) { n   x = 0; n   char ch = getchar(), w = 0; n   while (!isdigit(ch)) w = (ch ==  - ), ch = getchar(); n   while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar(); n   x = w ? -x : x; n } n long long n, m, a, b, c, val[N], tot, cnt, ans[N], tt; n int main() { n   read(n); n   for (register int i = 1; i <= n; i++) read(val[i]), tot += val[i]; n   tt = val[1]; n   for (register int i = 2; i <= n; i++) n     if (val[i] * 2 <= val[1]) ans[++cnt] = i, tt += val[i]; n   if (tt * 2 > tot) { n     cout << cnt + 1 << endl << 1 <<    ; n     for (register int i = 1; i <= cnt; i++) cout << ans[i] <<    ; n   } else n     cout << 0; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 100; n const double PI = 3.14159; n vector<string> v; n long long n, m, k, d, ans[101], c, sum, a[105][105]; n set<string> st; n string s, b; n bool flag; n set<string>::iterator it; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(NULL); n   cin >> n; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < n; j++) { n       cin >> a[i][j]; n     } n   } n   for (int i = 0; i < n; i++) { n     c = 0; n     for (int j = 0; j < n; j++) { n       if (i == j) continue; n       if (a[i][j] == 0 || a[i][j] == 2) c++; n     } n     if (c == n - 1) { n       sum++; n       d = i + 1; n       ans[d / 32] |= (1 << (d % 32)); n     } n   } n   cout << sum << endl; n   for (int i = 1; i <= n; i++) { n     if (ans[i / 32] & (1 << (i % 32))) cout << i <<    ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int U = 200; n const int M = U + 5; n int n; n long double p, q; n long double f[M][M], F[M][M]; n long double a[M][M]; n long double C[M][M]; n void input() { n   int pp; n   scanf( %d %d , &n, &pp); n   p = pp / 1000000000.; n   q = p * (1 - p); n } n void prepare() { n   f[1][1] = p, F[1][1] = p, f[1][2] = 1 - p, F[1][2] = 2 - 2 * p; n   for (int k = 2; k <= U; k++) { n     f[k][1] = q; n     for (int i = 2; i <= k; i++) F[k][1] += F[k - 1][i]; n     if (k > 2) n       F[k][1] = F[k][1] * q / (1 - q) + q; n     else n       F[k][1] = 3 * q; n     f[k][2] = 1 - q; n     for (int i = 3; i <= k + 1; i++) f[k][i] = f[k][i - 1] * f[k - 1][i - 1]; n     for (int i = 2; i <= k + 1; i++) { n       for (int j = i - 1; j >= 1; j--) { n         F[k][i] += F[k - 1][j]; n       } n       F[k][i] = F[k][i] * f[k][i] + i * (f[k][i] - f[k][i + 1]); n     } n   } n   a[1][U] = q; n   for (int j = 2; j < U; j++) a[1][j] = q / (1 - q); n   for (int i = 2; i < U; i++) { n     a[i][U] = i * (f[U][i] - f[U][i + 1]); n     for (int j = i - 1; j >= 1; j--) a[i][j] = f[U][i]; n   } n   a[U][U] = 1; n } n long double t[M][M]; n void multi(long double C[][M], long double a[][M]) { n   memset(t, 0, sizeof t); n   for (int i = 1; i <= U; i++) n     for (int j = 1; j <= U; j++) n       for (int k = 1; k <= U; k++) t[i][k] += C[i][j] * a[j][k]; n   for (int i = 1; i <= U; i++) n     for (int j = 1; j <= U; j++) C[i][j] = t[i][j]; n } n double solve() { n   long double rlt = 0; n   if (n <= U) { n     for (int i = 1; i <= n + 1; i++) rlt += F[n][i]; n     return rlt; n   } n   n -= U; n   for (int i = 1; i <= U; i++) C[i][i] = 1; n   while (n) { n     if (n & 1) multi(C, a); n     n >>= 1; n     multi(a, a); n   } n   F[U][U] = 1; n   for (int i = 1; i < U; i++) { n     for (int j = 1; j <= U; j++) rlt += C[i][j] * F[U][j]; n   } n   return rlt; n } n int main() { n   input(); n   int nn = n; n   n = min(1000000, n); n   prepare(); n   double rlt = solve(); n   if (nn > 1000000) rlt = rlt / 1000000 * nn; n   printf( %.15lf n , rlt); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); n   long long int n, o = 0, t = 0; n   cin >> n; n   for (long long int i = 0; i < n; i++) { n     long long int x; n     cin >> x; n     if (x == 1) n       o++; n     else n       t++; n   } n   if (t) { n     cout << 2 <<    ; n     t--; n   } n   if (o) { n     cout << 1 <<    ; n     o--; n   } n   while (t--) cout << 2 <<    ; n   while (o--) cout << 1 <<    ; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m; n string grid[101]; n int nb, l = 200, r = -1, u = 200, d = -1; n int main() { n   scanf( %d %d , &n, &m); n   for (int i = 0; i < n; i++) cin >> grid[i]; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) n       if (grid[i][j] ==  B ) { n         nb++; n         l = min(l, j); n         r = max(r, j); n         u = min(u, i); n         d = max(d, i); n       } n   } n   if (nb == 0) { n     cout << 1 << endl; n     return 0; n   } n   int h = d - u + 1, w = r - l + 1; n   if (w > h) { n     if (w > n) { n       cout << -1 << endl; n       return 0; n     } n     cout << w * w - nb << endl; n   } else { n     if (h > m) { n       cout << -1 << endl; n       return 0; n     } n     cout << h * h - nb << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int N = (int)5e5 + 50; n int n; n int ans[N]; n vector<int> G[N]; n int q[N]; n int dep[N]; n vector<pair<int, int> > hist[N]; n void upd(int u, int val) { q[u] = max(q[u], val); } n void calc(int v, int p) { n   dep[v] = 0; n   for (int nxt : G[v]) { n     if (nxt == p) continue; n     calc(nxt, v); n     dep[v] = max(dep[nxt] + 1, dep[v]); n   } n } n void merge(vector<pair<int, int> > h1, vector<pair<int, int> > h2) { n   int r = 0; n   if (r < h2.size() && h2[r].second == 1) r++; n   for (int i = 0; i < h1.size(); i++) { n     if (h1[i].second == 1) continue; n     while (r < h2.size() && (h2[r].first >= h1[i].first)) { n       r++; n     } n     if (r - 1 >= 0 && h2[r - 1].second > 1) n       upd(2 * h1[i].first, h2[r - 1].second + h1[i].second - 2); n   } n } n void dfs(int v, int p = -1, int up_dep = -1) { n   vector<int> deps; n   if (up_dep != -1) deps.push_back(up_dep + 1); n   for (int nxt : G[v]) { n     if (nxt != p) deps.push_back(dep[nxt] + 1); n   } n   sort(deps.begin(), deps.end(), n        [](const int a, const int b) { return a > b; }); n   for (int i = 0; i < deps.size(); i++) { n     upd(2 * deps[i], i + 1); n     upd(2 * deps[i] - 1, i + 1); n     if (i > 0 && deps[i - 1] > deps[i]) upd(2 * deps[i] + 1, i + 1); n   } n   for (int i = 0; i < deps.size(); i++) { n     if (hist[v].empty() || hist[v].back().first != deps[i]) n       hist[v].push_back({deps[i], 1}); n     else n       hist[v].back().second++; n   } n   for (int i = 1; i < hist[v].size(); i++) n     hist[v][i].second += hist[v][i - 1].second; n   for (int nxt : G[v]) { n     if (nxt == p) continue; n     dfs(nxt, v, n         (deps.size() == 1 ? 0 : (deps[0] == dep[nxt] + 1 ? deps[1] : deps[0]))); n     merge(hist[nxt], hist[v]); n     merge(hist[v], hist[nxt]); n   } n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(NULL); n   cin >> n; n   for (int i = 0; i < n - 1; i++) { n     int a, b; n     cin >> a >> b; n     a--, b--; n     G[a].push_back(b); n     G[b].push_back(a); n   } n   for (int i = 0; i < n; i++) { n     ans[1] = max(ans[1], (int)G[i].size() + 1); n   } n   calc(0, -1); n   dfs(0); n   int rmax = 0; n   for (int i = (n - 1) / 2 * 2 + 1; i >= 2; i -= 2) { n     rmax = max(rmax, q[i]); n     ans[i] = rmax; n   } n   rmax = 0; n   for (int i = n / 2 * 2; i >= 2; i -= 2) { n     rmax = max(rmax, q[i]); n     ans[i] = rmax; n   } n   for (int i = 1; i <= n; i++) cout << max(ans[i], 1) <<    ; n } n


#include <bits/stdc++.h> n using namespace std; n const long long inf = 0x3f3f3f3f3f3f3f3f; n int n, m, a[100010]; n int tot[100010], Lpos = 1, Rpos = 0; n long long f[100010], g[100010], MO; n inline int read() { n   int x = 0, w = 0; n   char ch = 0; n   while (!isdigit(ch)) { n     w |= ch ==  - ; n     ch = getchar(); n   } n   while (isdigit(ch)) { n     x = (x << 1) + (x << 3) + (ch ^ 48); n     ch = getchar(); n   } n   return w ? -x : x; n } n void add(int x) { MO += (tot[x]++); } n void del(int x) { MO -= (--tot[x]); } n long long calc(int l, int r) { n   while (Lpos < l) del(a[Lpos++]); n   while (Lpos > l) add(a[--Lpos]); n   while (Rpos < r) add(a[++Rpos]); n   while (Rpos > r) del(a[Rpos--]); n   return MO; n } n void solve(int L, int R, int st, int ed) { n   if (st > ed || L > R) return; n   int M = (st + ed) >> 1; n   M = max(M, L + 1); n   long long temp = inf, pos = 0; n   for (int i = L; i <= R; i++) n     if (temp > g[i] + calc(i + 1, M)) temp = g[pos = i] + calc(i + 1, M); n   f[M] = temp; n   solve(L, pos, st, M - 1); n   solve(pos, R, M + 1, ed); n } n int main() { n   n = read(); n   m = read(); n   for (int i = 1; i <= n; i++) a[i] = read(); n   memset(g, 0x3f, sizeof g); n   g[0] = 0; n   while (m-- > 0) { n     solve(0, n - 1, 1, n); n     swap(f, g); n   } n   cout << g[n] <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = (int)1e9; n const double eps = (double)1e-8; n const int mod = (int)1000000007; n const int maxn = (int)2 * 1e5 + 5; n int n, x, y, mx; n int u[maxn], pr[maxn]; n pair<int, int> t[maxn]; n vector<pair<int, int> > a[maxn]; n vector<int> ans; n list<int> q; n list<int>::iterator it1; n void dzen(int v, int p) { n   pr[v] = p; n   if (a[v].size() > 1 || v == 1) { n     q.push_back(v); n     u[v] = 0; n     if (a[v][0].first == p) u[v] = 1; n   } n   mx = max((int)a[v].size(), mx); n   for (int i = (0); i < (a[v].size()); i++) { n     if (a[v][i].first == p) continue; n     dzen(a[v][i].first, v); n   } n   return; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   ; n   cin >> n; n   for (int i = (2); i <= (n); i++) { n     cin >> x >> y; n     a[x].push_back(make_pair(y, i - 1)); n     a[y].push_back(make_pair(x, i - 1)); n   } n   mx = 0; n   dzen(1, 0); n   memset(t, -1, sizeof t); n   cout << mx <<   n ; n   while (mx--) { n     ans.clear(); n     for (list<int>::iterator it = q.begin(); it != q.end();) { n       if (t[pr[*it]].first == mx && t[pr[*it]].second == *it) { n         it++; n         continue; n       } n       t[*it] = make_pair(mx, a[*it][u[*it]].first); n       ans.push_back(a[*it][u[*it]].second); n       u[*it]++; n       if (u[*it] < (int)a[*it].size() && a[*it][u[*it]].first == pr[*it]) n         u[*it]++; n       if (u[*it] == (int)a[*it].size()) { n         it1 = it; n         it++; n         q.erase(it1); n       } else n         it++; n     } n     cout << ans.size() <<    ; n     for (int i = (0); i < (ans.size()); i++) { n       cout << ans[i] <<    ; n     } n     cout <<   n ; n   } n   return 0; n } n