#include <bits/stdc++.h> n using namespace std; n long long n, m, i = 0, j = 0, x, t, w, p, q, l, r, count1 = 0, count2 = 0, n                 k = 0, first = 0, second = 0, last, sum = 1e9; n const long long mod = 1000003, num = 0; n bool compare(pair<string, int> a, pair<string, int> b) { n   if (a.second == b.second) n     return a.first < b.first; n   else n     return a.second > b.second; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cin >> n; n   vector<vector<long long>> v(n, vector<long long>(n, 0)); n   long long val = 1; n   for (i = 0; i < n / 2; i++) { n     for (j = 0; j < n; j++) { n       v[j][i] = val; n       val += 1; n     } n   } n   for (i = n / 2; i < n; i++) { n     for (long long j = n - 1; j >= 0; j--) { n       v[j][i] = val; n       val += 1; n     } n   } n   for (i = 0; i < n; i++) { n     for (j = 0; j < n; j++) cout << v[i][j] <<    ; n     cout << endl; n   } n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n void doRoutine() { n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n   cout.tie(nullptr); n   srand(322179); n } n signed main() { n   doRoutine(); n   long long n; n   cin >> n; n   long long res = 0; n   while (n > 0) { n     ++res; n     n /= 2; n   } n   cout << res << endl; n   return 0; n } n


#include <bits/stdc++.h> n int n, fac[1000005], inv[1000005], ans; n int qpow(int a, long long b) { n   int s = 1; n   for (; b; b >>= 1, a = 1ll * a * a % 998244353) n     if (b & 1) s = 1ll * s * a % 998244353; n   return s; n } n int C(int n, int m) { n   return 1ll * fac[n] * inv[n - m] % 998244353 * inv[m] % 998244353; n } n int add(int x, int y) { return (x += y) >= 998244353 ? x -= 998244353 : x; } n int sub(int x, int y) { return (x -= y) < 0 ? x += 998244353 : x; } n int main() { n   scanf( %d , &n), fac[0] = 1; n   for (register int i = 1; i <= n; ++i) n     fac[i] = 1ll * fac[i - 1] * i % 998244353; n   inv[n] = qpow(fac[n], 998244353 - 2); n   for (register int i = n; i; --i) inv[i - 1] = 1ll * inv[i] * i % 998244353; n   ans = sub(qpow(3, 1ll * n * n), qpow(sub(qpow(3, n), 3), n)); n   for (register int i = 1; i <= n; ++i) { n     int s = n         1ll * C(n, i) * n         add(3ll * qpow(qpow(3, n - i) - 1, n) % 998244353, n             1ll * sub(qpow(3, i), 3) * qpow(3, 1ll * n * (n - i)) % 998244353) % n         998244353; n     if (i & 1) n       ans = add(ans, s); n     else n       ans = sub(ans, s); n   } n   printf( %d n , ans); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   scanf( %d , &n); n   char input[n + 5][n + 5]; n   for (int i = 0; i < n; i++) scanf( %s , input[i]); n   int row[n], col[n], count_row = 0, count_col = 0; n   for (int i = 0; i < n; i++) row[i] = -1; n   for (int j = 0; j < n; j++) col[j] = -1; n   for (int i = 0; i < n; i++) n     for (int j = 0; j < n; j++) { n       if (input[i][j] ==  . ) { n         row[i] = j; n         col[j] = i; n       } n     } n   for (int i = 0; i < n; i++) { n     if (row[i] != -1) count_row++; n     if (col[i] != -1) count_col++; n   } n   if (count_row != n && count_col != n) n     printf( -1 n ); n   else if (count_row == n) { n     for (int i = 0; i < n; i++) printf( %d %d n , i + 1, row[i] + 1); n   } else n     for (int j = 0; j < n; j++) printf( %d %d n , col[j] + 1, j + 1); n } n


#include <bits/stdc++.h> n using namespace std; n typedef long long ll; n const int N=4e2+2,p=998244353; n vector<int> lj[N]; n int dis[N][N],dl[N],ans[N][N],rd[N][N],cnt[N],pre[N][N],lb[N*3][2]; n int n,m,s,t,i,j,tou,wei,x,y,r; n bool ed[N]; n int main() n { n  scanf( %d%d ,&n,&m); n  for (i=1;i<=m;i++) scanf( %d%d ,&x,&y),lj[lb[i][0]=x].push_back(lb[i][1]=y),lj[y].push_back(x); n  for (i=1;i<=m;i++) lb[i+m][0]=lb[i][1],lb[i+m][1]=lb[i][0];m<<=1; n  for (s=1;s<=n;s++) n  { n   dis[s][dl[tou=wei=1]=s]=rd[s][s]=1; n   while (tou<=wei) for (auto v:lj[x=dl[tou++]]) if (!dis[s][v]) dis[s][dl[++wei]=v]=dis[s][pre[s][v]=x]+(rd[s][v]=1); else if (dis[s][v]==dis[s][x]+1) ++rd[s][v]; n  } n  for (s=1;s<=n;s++) n  { n   for (t=1;t<s;t++) printf( %d  ,ans[s][t]); n   //for (i=1;i<=n;i++) printf( %d: pre%d dis%d rd%d n ,i,pre[i],dis[i],rd[i]); n   for (t=s;t<=n;t++) n   { n    for (x=t;x!=s&&rd[s][x]<=1;x=pre[s][x]); n    if (x!=s) {printf( 0  );continue;} n    for (x=t;x!=s;x=pre[s][x]) ed[x]=1;r=1; n    for (i=1;i<=m;i++) if (dis[s][lb[i][0]]+1==dis[s][lb[i][1]]&&dis[t][lb[i][0]]+1==dis[t][lb[i][1]]) ++cnt[lb[i][1]]; n    //if (s==1&&t==1) for (i=1;i<=n;i++) printf( %d%c ,cnt[i],i==n?10:32); n    for (i=1;i<=n;i++) if (!ed[i]&&i!=s) r=(ll)r*cnt[i]%p; n    memset(cnt,0,sizeof(cnt)); n    for (x=t;x!=s;x=pre[s][x]) ed[x]=0; n    ans[t][s]=r;printf( %d  ,r); n   }puts(  ); n  } n }


#include <bits/stdc++.h> n using namespace std; n int n; n int a[1001], b[1001], c[1001], d[1001]; n void solve() { n   cin >> n; n   int r = 1; n   int i = 1; n   cin >> a[i] >> b[i] >> c[i] >> d[i]; n   int sum = a[1] + b[1] + c[1] + d[1]; n   for (int i = 2; i <= n; i++) { n     cin >> a[i] >> b[i] >> c[i] >> d[i]; n     int sum1 = a[i] + b[i] + c[i] + d[i]; n     if (sum1 > sum) { n       r += 1; n     } n   } n   cout << r; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   if (fopen( input.txt ,  r )) { n     freopen( input.txt ,  r , stdin); n     freopen( output.txt ,  w , stdout); n   } n   int t = 1; n   while (t--) { n     solve(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t, n, a[100]; n   cin >> t; n   while (t--) { n     cin >> n; n     for (int i = 0; i < n; i++) { n       cin >> a[i]; n     } n     sort(a, a + n); n     vector<int> v; n     int dif = 0; n     for (int i = 1; i < n; i++) { n       dif = a[i] - a[i - 1]; n       v.push_back(dif); n     } n     sort(v.begin(), v.end()); n     cout << v[0] << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n #pragma optimize( Ofast ) n using namespace std; n void solve() { n   int n, k; n   string s; n   cin >> n >> k >> s; n   vector<int> cnt(27); n   for (char &c : s) { n     cnt[c -  a ]++; n   } n   int t = 0; n   for (int d = 1; d <= n; d++) { n     vector<int> ncnt = cnt; n     int curr = 0; n     for (int j = 0; j < 26; j++) { n       if (ncnt[j] >= d) { n         ncnt[j] -= d; n         curr++; n         --j; n       } n       if (curr && k % curr == 0) { n         t = max(t, curr * d); n       } n     } n   } n   cout << t <<   n ; n } n int main() { n   ios_base::sync_with_stdio(false); n   int q; n   cin >> q; n   while (q--) { n     solve(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int a, b; n   cin >> a >> b; n   while (b) { n     int c = b % a; n     if (c == 0) n       b /= a; n     else if (c == 1) n       b--; n     else if (c == a - 1) n       b++; n     else n       return cout <<  NO , 0; n   } n   cout <<  YES ; 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   int t; n   cin >> t; n   while (t--) { n     int n; n     cin >> n; n     vector<int> nums(n); n     vector<vector<int> > pos(n); n     for (int i = 0; i < (int)n; i++) { n       cin >> nums[i]; n       nums[i] -= 1; n       pos[nums[i]].push_back(i); n     } n     vector<vector<int> > dp(n + 1, vector<int>(n)); n     for (int i = n - 1; i >= 0; i--) { n       for (int j = i + 1; j < (int)n; j++) { n         dp[i][j] = (dp[i + 1][j] + (nums[i] != nums[j])); n         for (auto k : pos[nums[i]]) { n           if (k > j) break; n           if (k < i) continue; n           int temp = dp[i][k] + 1 + dp[k + 1][j]; n           dp[i][j] = min(dp[i][j], temp); n         } n       } n     } n     cout << dp[0][n - 1] <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long a, b, x; n int n; n int main() { n   scanf( %d , &n); n   scanf( %lld%lld , &a, &b); n   while (n--) { n     scanf( %lld , &x); n     printf( %lld  , ((x * a) - b * ((x * a) / b)) / a); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 10, logN = 20; n const int M = 350; n int d[N], h[N], floorlog[N << 1]; n long long D[N], F1[N], F2[N], lft[N], rgt[N], total = 0; n map<pair<int, int>, long long> st; n vector<pair<int, int> > queries, q; n pair<int, int> rmq1[logN][N], rmq2[logN][N]; n int max(int i, int j, long long f[]) { return f[i] > f[j] ? i : j; } n pair<int, int> merge(pair<int, int>& x, pair<int, int>& y, long long f[]) { n   if (f[x.first] > f[y.first]) { n     return {x.first, max(x.second, y.first, f)}; n   } n   if (x.first == y.first) { n     return {y.first, max(x.second, y.second, f)}; n   } n   return {y.first, max(x.first, y.second, f)}; n } n void make_rmq(long long f[], pair<int, int> rmq[][N], int n) { n   for (int i = n; i >= 1; i--) { n     rmq[0][i] = {i, 0}; n     for (int j = 1; i + (1 << j) - 1 <= n; j++) { n       rmq[j][i] = merge(rmq[j - 1][i], rmq[j - 1][i + (1 << (j - 1))], f); n     } n   } n } n pair<int, int> get(int i, int j, pair<int, int> rmq[][N], long long f[]) { n   int k = floorlog[j - i + 1]; n   return merge(rmq[k][i], rmq[k][j - (1 << k) + 1], f); n } n long long query(int l, int r) { n   pair<int, int> P = get(l, r, rmq1, F1); n   pair<int, int> Q = get(l, r, rmq2, F2); n   long long mx = 0; n   if (P.first != Q.first) mx = max(mx, F1[P.first] + F2[Q.first]); n   if (P.second != Q.first) mx = max(mx, F1[P.second] + F2[Q.first]); n   if (P.first != Q.second) mx = max(mx, F1[P.first] + F2[Q.second]); n   if (P.second != Q.second) mx = max(mx, F1[P.second] + F2[Q.second]); n   return mx; n } n int main() { n   for (int i = 0; (1 << i) < N; i++) n     for (int j = (1 << i); j < (1 << (i + 1)); j++) floorlog[j] = i; n   int n, m; n   scanf( %d , &(n)); n   scanf( %d , &(m)); n   for (int i = 1; i <= n; i++) { n     D[i] = D[i - 1] + d[i - 1]; n     scanf( %d , &(d[i])); n     total += d[i]; n   } n   for (int i = 1; i <= n; i++) { n     scanf( %d , &(h[i])); n     F1[i] = D[i] + 2 * h[i]; n     F2[i] = -D[i] + 2 * h[i]; n     rgt[i] = max(rgt[i - 1], D[i] + 2 * h[i]); n   } n   for (int i = n; i >= 1; i--) { n     lft[i] = max(lft[i + 1], total - D[i] + 2 * h[i]); n   } n   F1[0] = -1e18; n   F2[0] = -1e18; n   make_rmq(F1, rmq1, n); n   make_rmq(F2, rmq2, n); n   for (int i = 1; i <= m; i++) { n     int a, b; n     scanf( %d , &(a)); n     scanf( %d , &(b)); n     q.push_back({a, b}); n     if (a > b) { n       int l = b + 1, r = a - 1; n       printf( %lld n , query(l, r)); n     } else { n       long long ans = 0; n       if (b != n && a != 1) ans = max(ans, lft[b + 1] + rgt[a - 1]); n       if (b != n) ans = max(ans, query(b + 1, n)); n       if (a != 1) ans = max(ans, query(1, a - 1)); n       printf( %lld n , ans); n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   vector<int> v(4); n   int total = 0; n   for (int i = 0; i < 4; i++) { n     scanf( %d , &v[i]); n     total += v[i]; n   } n   sort(v.begin(), v.end()); n   do { n     int sum = 0; n     for (int i = 0; i < 4; i++) { n       sum += v[i]; n       if (2 * sum == total) { n         cout <<  YES ; n         return 0; n       } n     } n   } while (next_permutation(v.begin(), v.end())); n   cout <<  NO ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class c> n struct rge { n   c b, e; n }; n template <class c> n rge<c> range(c i, c j) { n   return rge<c>{i, j}; n } n template <class c> n auto dud(c* x) -> decltype(cerr << *x, 0); n template <class c> n char dud(...); n struct debug { n   template <class c> n   debug& operator<<(const c&) { n     return *this; n   } n }; n const long long int N = 1e5 + 5; n const long long int INF = 1e10; n long long int mod = 998244353; n long long int dx[4] = {0, 0, +1, -1}; n long long int dy[4] = {+1, -1, 0, 0}; n long long int n; n void solve() { n   cin >> n; n   long long int c1 = 0, c2 = 0; n   for (long long int i = 0; i < n; i++) { n     long long int x; n     cin >> x; n     (x == 1 ? c1++ : c2++); n   } n   long long int f = 0; n   for (long long int i = 0; i < n; i++) { n     if (f == 0 and c2 > 0 and c1 > 0) { n       cout << 2 <<     << 1 <<    ; n       c2--, c1--; n       f = 1; n     } else if (c2 > 0) { n       cout << 2 <<    ; n       c2--; n     } else if (c1 > 0) { n       cout << 1 <<    ; n       c1--; n     } n   } n } n int32_t main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   ; n   long long int t = 1; n   while (t--) solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = (int)1e5; n int ans[N], all, u, v, n, m, num, color[N], cnt[2]; n vector<int> adj[N], radj[N]; n bool used[N]; n void output() { n   printf( YES n ); n   for (int i = 0; i < n; ++i) printf( %d%c , ans[i] + 1,    n [i == n - 1]); n   exit(0); n } n void dfs(int v, int c) { n   color[v] = c, cnt[c]++; n   for (int j = 0; j < ((int)(adj[v]).size()); ++j) n     if (color[adj[v][j]] == -1) dfs(adj[v][j], c ^ 1); n } n void truecolor() { n   int deg = 0; n   for (int t = 0; t < 2; ++t) { n     for (int i = 0; i < n; ++i) n       if (color[i] == t) { n         ans[i] = num; n         ++deg; n         if (deg == 3) { n           ++num; n           deg = 0; n         } n       } n   } n } n int main() { n   scanf( %d%d , &n, &m); n   for (int i = 0; i < m; ++i) n     scanf( %d%d , &u, &v), --u, --v, adj[u].push_back(v), adj[v].push_back(u); n   memset(color, -1, sizeof(color)); n   for (int i = 0; i < n; ++i) n     if (color[i] == -1) dfs(i, 0); n   if (cnt[0] % 3 > cnt[1] % 3) { n     for (int i = 0; i < n; ++i) color[i] ^= 1; n     swap(cnt[0], cnt[1]); n   } n   all = 0; n   for (int i = 0; i < n; ++i) n     if (color[i] == 1) all ^= i; n   num = 0; n   if (cnt[0] % 3 == 0) { n     truecolor(); n     output(); n   } n   for (int i = 0; i < n; ++i) n     if (color[i] == 0) n       if (((int)(adj[i]).size()) <= cnt[1] - 2) { n         ans[i] = 0, color[i] = 2; n         for (int j = 0; j < ((int)(adj[i]).size()); ++j) used[adj[i][j]] = true; n         int deg = 2; n         for (int j = 0; deg && (j < n); ++j) n           if ((color[j] == 1) && !used[j]) { n             color[j] = 2; n             ans[j] = 0; n             --deg; n           } n         ++num; n         truecolor(); n         output(); n       } else if (((int)(adj[i]).size()) == cnt[1] - 1) { n         int x = all; n         for (int j = 0; j < ((int)(adj[i]).size()); ++j) x ^= adj[i][j]; n         radj[x].push_back(i); n       } n   int res = 0; n   for (int i = 0; i < n; ++i) n     if (((int)(radj[i]).size()) >= 2) res++; n   if (res <= 1) { n     printf( NO n ); n     return 0; n   } n   res = 2; n   for (int i = 0; res && (i < n); ++i) n     if (((int)(radj[i]).size()) >= 2) { n       ans[i] = num, color[i] = 2; n       for (int j = 0; j < 2; ++j) ans[radj[i][j]] = num, color[radj[i][j]] = 2; n       --res; n       ++num; n     } n   truecolor(); n   output(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e5 + 10; n const int mod = 1e9 + 7; n const int inf = 0x3f3f3f3f; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   int ans = 0, a, b, c, d, e, f; n   cin >> a >> b >> c >> d >> e >> f; n   if (e < f) { n     int now = min(d, min(b, c)); n     ans += now * f; n     b -= now; n     c -= now; n     d -= now; n   } else { n     int now = min(d, a); n     ans += now * e; n     a -= now; n     d -= now; n   } n   ans += e * min(a, d); n   ans += f * min(d, min(b, c)); n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long int INF = (long long int)1e9 + 10; n const long long int INFLL = (long long int)1e18 + 10; n const long double EPS = 1e-8; n const long long int MOD = 1e9 + 7; n template <class T> n T &chmin(T &a, const T &b) { n   return a = min(a, b); n } n template <class T> n T &chmax(T &a, const T &b) { n   return a = max(a, b); n } n template <class T> n inline T sq(T a) { n   return a * a; n } n int n, m; n bool f[128][2]; n int memo[128][128][3][3]; n bool isin(int a, int b) { return 0 <= a and a < n and 0 <= b and b < 2; } n vector<pair<int, int> > cg; n void draw(int a, int b) { n   if (isin(a, b) and !f[a][b]) { n     cg.emplace_back(a, b); n     f[a][b] = true; n   } n } n void put(int a, int b) { n   cg.clear(); n   draw(a, b); n   draw(a - 1, 1 - b); n   draw(a, 1 - b); n   draw(a + 1, 1 - b); n } n int mex(set<int> &x) { n   for (long long int i = (0); i < (long long int)(INF); i++) n     if (x.find(i) == x.end()) return i; n } n int grandy(int t, int b, int tf, int bf) { n   int &res = memo[t][b][tf][bf]; n   if (res != -1) return res; n   set<int> gs; n   for (long long int i = (t); i < (long long int)(b); i++) n     for (long long int j = (0); j < (long long int)(2); j++) n       if (!f[i][j]) { n         put(i, j); n         vector<pair<int, int> > ccg = cg; n         int x = grandy(t, i, tf, j) ^ grandy(i + 1, b, j, bf); n         gs.insert(x); n         for (auto &w : ccg) f[w.first][w.second] = false; n       } n   return res = mex(gs); n } n int main() { n   scanf( %d %d , &n, &m); n   for (long long int i = (0); i < (long long int)(m); i++) { n     int a, b; n     scanf( %d %d , &a, &b); n     a--; n     b--; n     put(a, b); n   } n   for (long long int i = (0); i < (long long int)(128); i++) n     for (long long int j = (0); j < (long long int)(128); j++) n       for (long long int k = (0); k < (long long int)(3); k++) n         for (long long int l = (0); l < (long long int)(3); l++) n           memo[i][j][k][l] = -1; n   if (grandy(0, n, 2, 2) == 0) n     puts( LOSE ); n   else n     puts( WIN ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long int m, nn, o, p; n int main() { n   long long int n; n   cin >> n; n   string a, b; n   cin >> a >> b; n   for (int i = 0; i < n; i++) n     if (a[i] ==  0 ) { n       if (b[i] ==  0 ) n         m++; n       else n         nn++; n     } else { n       if (b[i] ==  0 ) n         o++; n       else n         p++; n     } n   cout << m * p + m * o + nn * o << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int n, tms; n void upd(int &x, int y) { x = min(x, y); } n struct trietree { n   int node[505][12]; n   int sum[505]; n   int dp[505][505][12]; n   int dp2[505][505][12][12]; n   bool vis[505][505][15]; n   int dep[505]; n   int tot; n   void insert(char ch[], int val) { n     int now = 0; n     int l = strlen(ch); n     for (int i = 0; i < l; i++) { n       int rt = ch[i] -  0 ; n       if (node[now][rt] == 0) node[now][rt] = ++tot, dep[tot] = dep[now] + 1; n       now = node[now][rt]; n     } n     sum[now] += val; n   } n   void dfs(int x, int p, int lft) { n     if (vis[x][p][lft]) return; n     vis[x][p][lft] = 1; n     if (lft > 0) dfs(x, x, lft - 1), upd(dp[x][p][lft], dp[x][x][lft - 1]); n     vector<int> ch; n     for (int i = 0; i < 10; i++) n       if (node[x][i]) ch.push_back(node[x][i]); n     dp2[x][p][lft][ch.size()] = 0; n     for (int i = ch.size() - 1; i >= 0; i--) { n       int t = ch[i]; n       for (int j = 0; j <= lft; j++) { n         dfs(t, p, j); n         upd(dp2[x][p][lft][i], dp2[x][p][lft - j][i + 1] + dp[t][p][j]); n       } n     } n     upd(dp[x][p][lft], dp2[x][p][lft][0] + (dep[x] - dep[p]) * sum[x]); n   } n   int solve() { n     memset(dp, 0x3f, sizeof(dp)); n     memset(dp2, 0x3f, sizeof(dp2)); n     dfs(0, 0, tms); n     return dp[0][0][tms]; n   } n } trie; n char buf[1008]; n int main() { n   cin >> n >> tms; n   for (int i = 0; i < n; i++) { n     scanf( %s , buf); n     int gg; n     cin >> gg; n     trie.insert(buf, gg); n   } n   cout << trie.solve(); n   return 0; n } n


#include <bits/stdc++.h> n int main(void) { n   char a[3][3]; n   scanf( %3s , a[0]); n   scanf( %3s , a[1]); n   scanf( %3s , a[2]); n   for (int i = 0; i < 3; i++) n     for (int j = 0; j < 3; j++) n       if (a[i][j] != a[((((i)-1) * -1) + 1)][((((j)-1) * -1) + 1)]) { n         puts( NO ); n         return EXIT_SUCCESS; n       } n   puts( YES ); n   return EXIT_SUCCESS; n } n


#include <bits/stdc++.h> n using namespace std; n const int Maxn = 100005; n const int Maxm = 500; n int T; n int n, m, k; n vector<int> un; n int my[Maxn]; n bool has[Maxm][Maxm]; n set<int> neigh[Maxn]; n void Solve(priority_queue<pair<int, int> > &Q) { n   bool assigned = false; n   int inside = n; n   while (!Q.empty() && -Q.top().first < k) { n     int v = Q.top().second, d = -Q.top().first; n     Q.pop(); n     if (neigh[v].size() != d) continue; n     if (neigh[v].size() == k - 1) { n       if (!assigned && inside < Maxm) { n         int pnt = 0; n         for (int i = 1; i <= n; i++) n           if (!neigh[i].empty()) my[i] = pnt++; n         for (int i = 0; i < pnt; i++) fill(has[i], has[i] + pnt, false); n         for (int i = 1; i <= n; i++) n           for (auto u : neigh[i]) has[my[i]][my[u]] = true; n         assigned = true; n       } n       vector<int> seq; n       for (auto u : neigh[v]) seq.push_back(u); n       bool ok = true; n       for (int i = 0; i < seq.size() && ok; i++) n         for (int j = i + 1; j < seq.size() && ok; j++) n           if (assigned) n             ok = has[my[seq[i]]][my[seq[j]]]; n           else n             ok = neigh[seq[i]].find(seq[j]) != neigh[seq[i]].end(); n       if (ok) { n         printf( 2 n ); n         printf( %d , v); n         for (int i = 0; i < seq.size(); i++) printf(  %d , seq[i]); n         printf(  n ); n         return; n       } n     } n     for (auto u : neigh[v]) { n       neigh[u].erase(v); n       if (assigned) has[my[v]][my[u]] = has[my[u]][my[v]] = false; n       Q.push(pair<int, int>(-int(neigh[u].size()), u)); n     } n     neigh[v].clear(); n     inside--; n   } n   vector<int> seq; n   while (!Q.empty()) { n     int v = Q.top().second, d = -Q.top().first; n     Q.pop(); n     if (neigh[v].size() != d) continue; n     seq.push_back(v); n   } n   if (seq.empty()) n     printf( -1 n ); n   else { n     printf( 1 %d n , int(seq.size())); n     for (int i = 0; i < seq.size(); i++) n       printf( %d%c , seq[i], i + 1 < seq.size() ?     :   n ); n   } n } n int main() { n   scanf( %d , &T); n   while (T--) { n     scanf( %d %d %d , &n, &m, &k); n     for (int i = 1; i <= n; i++) neigh[i].clear(); n     for (int i = 0; i < m; i++) { n       int a, b; n       scanf( %d %d , &a, &b); n       neigh[a].insert(b); n       neigh[b].insert(a); n     } n     priority_queue<pair<int, int> > Q; n     for (int i = 1; i <= n; i++) n       Q.push(pair<int, int>(-int(neigh[i].size()), i)); n     Solve(Q); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = (1 << 20) + 5; n bool used[MAXN]; n vector<int> adj[MAXN]; n int a[MAXN]; n int n; n vector<int> ans; n vector<int>::iterator it[MAXN]; n void dfs(int x) { n   while (it[x] != adj[x].end()) { n     int p = *(it[x]); n     if (!used[p / 2]) { n       int p = *(it[x]); n       it[x]++; n       used[p / 2] = true; n       dfs(a[p ^ 1]); n       ans.push_back(p); n     } else { n       it[x]++; n     } n   } n } n int main() { n   cin.tie(0); n   cout.tie(0); n   ios_base::sync_with_stdio(false); n   cin >> n; n   for (int i = 0; i < 2 * n; i++) cin >> a[i]; n   for (int i = 0; i < 2 * n; i++) used[a[i]] = !used[a[i]]; n   int k; n   for (k = 20; k >= 0; k--) { n     bool good = true; n     for (int i = 0; i < (1 << k); i++) { n       if (used[i]) { n         good = false; n         break; n       } n     } n     if (good) break; n     for (int i = 0; i < (1 << (k - 1)); i++) { n       used[i] = used[i] ^ used[i + (1 << (k - 1))]; n     } n   } n   for (; k >= 0; k--) { n     for (int i = 0; i < n; i++) { n       used[i] = false; n     } n     for (int i = 0; i < 2 * n; i++) { n       a[i] = a[i] % (1 << k); n     } n     for (int i = 0; i < (1 << k); i++) adj[i].clear(); n     for (int i = 0; i < n; i++) { n       adj[a[2 * i]].push_back(2 * i); n       adj[a[2 * i + 1]].push_back(2 * i + 1); n     } n     for (int i = 0; i < (1 << k); i++) { n       it[i] = adj[i].begin(); n     } n     dfs(a[0]); n     if (ans.size() == n) { n       cout << k <<   n ; n       for (int i = n - 1; i >= 0; i--) { n         cout << 1 + ans[i] <<     << 1 + (ans[i] ^ 1) <<    ; n       } n       return 0; n     } n     ans.clear(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int M = 200 * 1000 + 11; n int main() { n   int q; n   cin >> q; n   vector<int> pos(M); n   int curl = 0; n   int curr = 0; n   for (int i = 0; i < q; ++i) { n     string type; n     int id; n     cin >> type >> id; n     if (i == 0) { n       pos[id] = curl; n       --curl; n       ++curr; n     } else { n       if (type ==  L ) { n         pos[id] = curl; n         --curl; n       } else if (type ==  R ) { n         pos[id] = curr; n         ++curr; n       } else { n         cout << min(abs(pos[id] - curl), abs(pos[id] - curr)) - 1 <<   n ; n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX = 1e7; n int n; n int m[100], r[100]; n bool am[MAX]; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cin >> n; n   for (int i = 1; i <= n; i++) cin >> m[i]; n   for (int i = 1; i <= n; i++) cin >> r[i]; n   for (int i = 1; i <= n; i++) { n     bool da = 0; n     for (int k = 0; k * m[i] + r[i] < MAX; k++) am[k * m[i] + r[i]] = 1; n   } n   int cnt = 0; n   for (int i = 1; i < MAX; i++) cnt += am[i]; n   cout << 1.00 * cnt / (MAX - 1); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long fast_pow(long long x, long long y, long long p); n void solve() { n   long long a, b, c; n   cin >> a >> b >> c; n   long long ans = INT_MAX; n   long long ansA = -1, ansB = -1, ansC = -1; n   for (long long ta = 1; ta <= 2 * a; ta++) { n     for (long long tb = ta; tb <= 2 * b; tb += ta) { n       long long sum = abs(a - ta) + abs(b - tb); n       if ((c % tb) < (tb - (c % tb))) { n         sum += (c % tb); n         if (sum < ans) { n           ans = sum; n           ansA = ta; n           ansB = tb; n           long long temp = c / tb; n           ansC = temp * tb; n         } n       } else { n         sum += (tb - (c % tb)); n         if (sum < ans) { n           ans = sum; n           ansA = ta; n           ansB = tb; n           long long temp = (c / tb) + 1; n           ansC = temp * tb; n         } n       } n     } n   } n   cout << ans <<   n ; n   cout << ansA <<     << ansB <<     << ansC <<   n ; n } n int32_t main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long test = 1; n   cin >> test; n   while (test--) { n     solve(); n   } n   return 0; n } n long long fast_pow(long long x, long long y, long long p) { n   long long 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


#include <bits/stdc++.h> n using namespace std; n int read() { n   int x = 0, f = 1; n   char ch = getchar(); n   while (ch <  0  || ch >  9 ) { n     if (ch ==  - ) f = -1; n     ch = getchar(); n   } n   while (ch >=  0  && ch <=  9 ) { n     x = x * 10 + ch -  0 ; n     ch = getchar(); n   } n   return x * f; n } n int n, t, k; n int a[200005], maxx, b[200005]; n vector<int> v[200005]; n int cnt = 1, tmp = 0; n int main() { n   n = read(); n   t = read(); n   k = read(); n   for (int i = 1; i <= t; ++i) a[i] = read(); n   for (int i = t; i >= 1; --i) { n     maxx += abs(min(0, a[i + 1] - a[i])); n     if (i == t) n       b[i] = a[i]; n     else n       b[i] = b[i + 1] + a[i] - 1; n   } n   v[0].push_back(1); n   if (k < maxx || k > n - t) { n     printf( -1 n ); n     return 0; n   } else { n     printf( %d n , n); n     for (int i = 1; i <= t; ++i) { n       if (k < n - t - tmp) { n         v[i].push_back(++cnt); n         printf( %d %d n , v[i - 1][0], v[i][0]); n         a[i]--; n         for (int j = 1; j < v[i - 1].size() && a[i] && k < n - t - tmp; ++j) { n           v[i].push_back(++cnt); n           printf( %d %d n , v[i - 1][j], v[i][j]); n           tmp++; n           a[i]--; n         } n         if (a[i]) { n           for (int j = 1; j <= a[i]; ++j) { n             v[i].push_back(++cnt); n             printf( %d %d n , cnt, v[i - 1][0]); n           } n         } n       } else { n         for (int j = 1; j <= a[i]; ++j) { n           v[i].push_back(++cnt); n           printf( %d %d n , cnt, v[i - 1][0]); n         } n       } n     } n   } n } n


#include <bits/stdc++.h> n void sort(int a[], int begin, int mid, int end) { n   int i = begin, j = mid + 1, k = 0, temp[end - begin + 1]; n   while (i <= mid && j <= end) { n     if (a[i] <= a[j]) n       temp[k++] = a[i++]; n     else n       temp[k++] = a[j++]; n   } n   for (; i <= mid; ++i) temp[k++] = a[i]; n   for (; j <= end; ++j) temp[k++] = a[j]; n   for (i = 0; i < k; ++i) a[begin + i] = temp[i]; n } n void partition(int a[], int begin, int end) { n   if (begin == end) return; n   int mid = (begin + end) / 2; n   partition(a, begin, mid); n   partition(a, mid + 1, end); n   sort(a, begin, mid, end); n } n int main() { n   int n; n   scanf( %d , &n); n   unsigned long long s = 0; n   int i, a[n + 1]; n   for (i = 1; i <= n; ++i) scanf( %d , &a[i]); n   partition(a, 1, n); n   for (i = 1; i <= n - 1; ++i) s = s + (a[i] * 1LL) * (i + 1); n   s = s + (a[n] * 1LL) * n; n   printf( %I64d n , s); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double pi = acos(-1.0); n struct debugger { n   static void call(string::iterator it, string::iterator ed) {} n   template <typename T, typename... aT> n   static void call(string::iterator it, string::iterator ed, T a, aT... rest) { n     string b; n     for (; *it !=  , ; ++it) n       if (*it !=    ) b += *it; n     cout << b <<  =  << a <<    ; n     call(++it, ed, rest...); n   } n }; n int main() { n   int n, R, r; n   cin >> n >> R >> r; n   if (n == 1 && r <= R) { n     cout <<  YES n ; n     return 0; n   } n   if (n == 2 && 2 * r <= R) { n     cout <<  YES n ; n     return 0; n   } n   double ans = asin((double)r / (double)(R - r)); n   if (ans * n <= pi + 1.0e-8) { n     cout <<  YES n ; n     return 0; n   } n   cout <<  NO n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long Mxn = 1e6 + 7; n const long long Mod = 1e9 + 7; n const long long Inf = 1e16 + 7; n const long long Module = 998244353; n int N; n long long Ans, A[Mxn], B[Mxn], Val[Mxn]; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cin >> N; n   for (int i = 1; i <= N; i++) { n     cin >> A[i]; n   } n   for (int i = 1; i <= N; i++) { n     cin >> B[i]; n   } n   sort(B + 1, B + N + 1); n   for (int i = 1; i <= N; i++) { n     Val[i] = (1LL * A[i] * i * (N - i + 1)); n   } n   sort(Val + 1, Val + N + 1); n   reverse(Val + 1, Val + N + 1); n   for (int i = 1; i <= N; i++) { n     Ans = (Ans + (1LL * B[i] * (Val[i] % Module)) % Module) % Module; n   } n   cout << Ans; n   return false; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long n, k; n   cin >> n >> k; n   vector<long long> v, v1; n   map<long long, long long> m; n   for (long long i = 0; i < n; i++) { n     long long a; n     cin >> a; n     v.push_back(a); n   } n   long long a, c = 0; n   cin >> a; n   for (long long i = 0; i < n; i++) n     if (v[i] > ((i + 1) * a + k)) c = -1; n   long long val = k; n   for (int i = 0; i < n; i++) { n     int a; n     cin >> a; n     v1.push_back(a); n   } n   long long sum = 0; n   if (c == 0) { n     for (long long i = 0; i < n; i++) { n       m[v1[i]]++; n       auto itr = m.begin(); n       while (v[i] > val && itr != m.end()) { n         if (itr->second == 0 && itr != m.end()) { n           auto itr1 = itr; n           itr1++; n           m.erase(itr->first); n           itr = m.find(itr1->first); n         } else { n           val += a; n           sum += itr->first; n           (itr->second)--; n         } n       } n     } n     cout << sum <<   n ; n   } else n     cout <<  -1  n          <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n int n, nc, a[111], b[111]; n string c[111]; n struct Node { n   int lab; n   Node *left, *right; n   Node(int x) { n     lab = x; n     left = NULL; n     right = NULL; n   } n }; n void printfalse() { n   cout <<  IMPOSSIBLE ; n   exit(0); n } n Node *solve(int x, int y) { n   if (x > y) return NULL; n   if (x == y) return new Node(x); n   int l = -1, r = n + 1; n   for (int i = (1); i <= (nc); i++) { n     int u = a[i], v = b[i]; n     if (u == x) { n       if (c[i][0] ==  L ) { n         l = max(l, v); n       } else { n         r = min(r, v); n       } n     } n   } n   for (int s = (max(x, l)); s <= (min(y, r - 1)); s++) { n     bool ok = true; n     for (int i = (1); i <= (nc); i++) { n       int u = a[i], v = b[i]; n       if (x < min(u, v) && min(u, v) <= s && s < max(u, v)) { n         ok = false; n       } n     } n     if (!ok) continue; n     Node *r = new Node(x); n     r->left = solve(x + 1, s); n     r->right = solve(s + 1, y); n     return r; n   } n   printfalse(); n } n void print(Node *r) { n   if (r == NULL) return; n   print(r->left); n   cout << r->lab <<    ; n   print(r->right); n } n bool find(Node *u, int v) { n   if (u == NULL) return false; n   if (u->lab == v) return true; n   return find(u->left, v) || find(u->right, v); n } n void visit(Node *u) { n   if (u == NULL) return; n   for (int i = (1); i <= (nc); i++) n     if (a[i] == u->lab) { n       if (c[i][0] ==  L ) { n         if (!find(u->left, b[i])) printfalse(); n       } else { n         if (!find(u->right, b[i])) printfalse(); n       } n     } n   visit(u->left); n   visit(u->right); n } n int main() { n   cin >> n >> nc; n   for (int i = (1); i <= (nc); i++) { n     cin >> a[i] >> b[i] >> c[i]; n   } n   Node *r = solve(1, n); n   visit(r); n   print(r); n } n


#include <bits/stdc++.h> n using namespace std; n int a[300000], b[300000]; n int tree[1 << 21], lazy[1 << 21]; n int prop(int s, int e, int i) { n   tree[i] += lazy[i]; n   if (s != e) lazy[2 * i + 1] += lazy[i], lazy[2 * i + 2] += lazy[i]; n   lazy[i] = 0; n   return 0; n } n int update(int s, int e, int as, int ae, int i, int num) { n   prop(s, e, i); n   if ((s > ae) || (e < as)) n     return tree[i]; n   else if ((s >= as) && (e <= ae)) { n     lazy[i] += num; n     prop(s, e, i); n     return tree[i]; n   } n   int mid = (s + e) / 2; n   update(s, mid, as, ae, 2 * i + 1, num), n       update(mid + 1, e, as, ae, 2 * i + 2, num); n   tree[i] = min(tree[2 * i + 1], tree[2 * i + 2]); n   return tree[i]; n } n int query(int s, int e, int i) { n   prop(s, e, i); n   if (s == e) return s; n   int mid = (s + e) / 2; n   prop(mid + 1, e, 2 * i + 2); n   if (tree[2 * i + 2] < 0) n     return query(mid + 1, e, 2 * i + 2); n   else n     return query(s, mid, 2 * i + 1); n } n int main() { n   int i; n   int n, m, q; n   int t, j, x; n   scanf( %d %d , &n, &m); n   for (i = 0; i < n; i++) scanf( %d , &a[i]); n   for (i = 0; i < m; i++) scanf( %d , &b[i]); n   for (i = 0; i < n; i++) update(0, 1000000, 1, a[i], 0, -1); n   for (i = 0; i < m; i++) update(0, 1000000, 1, b[i], 0, 1); n   scanf( %d , &q); n   for (i = 0; i < q; i++) { n     scanf( %d %d %d , &t, &j, &x), j--; n     if (t == 1) { n       update(0, 1000000, 1, a[j], 0, 1); n       a[j] = x; n       update(0, 1000000, 1, a[j], 0, -1); n     } else { n       update(0, 1000000, 1, b[j], 0, -1); n       b[j] = x; n       update(0, 1000000, 1, b[j], 0, 1); n     } n     int ans = query(0, 1000000, 0); n     if (ans == 0) n       printf( -1 n ); n     else n       printf( %d n , ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const string problemName =   ; n const string inputFile = problemName +  .in ; n const string outputFile = problemName +  .out ; n const int INF = (1LL << 31) - 1; n const long long int LINF = (1LL << 62) - 1; n const int dx[] = {1, 0, -1, 0, 1, -1, 1, -1}; n const int dy[] = {0, 1, 0, -1, 1, -1, -1, 1}; n const int MOD = (int)(1e9) + 7; n const int NMAX = 100000 + 5; n const int MMAX = 100000 + 5; n const int KMAX = 100000 + 5; n const int PMAX = 100000 + 5; n const int LMAX = 100000 + 5; n const int VMAX = 100000 + 5; n long long int t, a, b, n, i, tt, q, sol = 0; n long long int A[NMAX]; n int putere(long long int b, long long int a) { n   if (a == 1 && b != 1) return 0; n   if (a != 1 && b == 1) return 0; n   while (b != 1 && b % a == 0) b /= a; n   return b == 1; n } n int main() { n   scanf( %lld%lld%lld , &t, &a, &b); n   if (t != 1 || (t == 1 && !putere(b, a))) { n     if (a == b) sol++; n     for (n = 0; b && a > 1; n++) { n       A[n] = b % a; n       b /= a; n     } n     for (i = q = 0, tt = 1; i < n; i++) { n       q += A[i] * tt; n       tt *= t; n       if (q < 0 || q > a) break; n     } n     if (q == a) sol++; n     printf( %lld , sol); n   } else { n     if (a == 1 && b == 1) n       printf( inf ); n     else n       printf( %d , putere(b, a)); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n ostream& operator<<(ostream& os, vector<T> V) { n   os <<  [  ; n   for (auto v : V) os << v <<    ; n   return os <<  ] ; n } n template <class L, class R> n ostream& operator<<(ostream& os, pair<L, R> P) { n   return os <<  (  << P.first <<  ,  << P.second <<  ) ; n } n const long long Mod = 1e9 + 7; n const long long pre = 1e10; n const double inv = pow(10, -10); n double y, y2, yw, xb, yb, r; n int check(long long xp) { n   double p = (double)xp * inv; n   double slope = (yw - r - yb) / (xb - p); n   double c = (yw - r) - slope * p; n   if (c >= y2) return 1; n   if (c <= y) return -1; n   bool a = (c >= y + r); n   bool b = (abs(y2 - c) >= r * (sqrt(1 + slope * slope))); n   if (a && b) n     return 0; n   else if (!a && !b) n     return -1; n   else if (!a) n     return -1; n   else n     return 1; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cin >> y >> y2 >> yw >> xb >> yb >> r; n   long long left = 0, right = xb * pre - 1, mid; n   while (left <= right) { n     mid = (left + right) / 2; n     int t = check(mid); n     if (t == 0) { n       printf( %0.10lf n , (double)mid * inv); n       return 0; n     } else if (t == 1) n       left = mid + 1; n     else if (t == -1) n       right = mid - 1; n     else { n       cout << -1 << endl; n       return 0; n     } n   } n   cout << -1 << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n double L, R; n int n, i; n int a[10000]; n double jami; n long long ans1, ans2, ans; n int main() { n   L = 10.0; n   R = 1000000000; n   cin >> n; n   for (i = 1; i <= n; i++) cin >> a[i]; n   for (i = 1; i <= n; i++) { n     L = max(L, (double)((double)a[i] / i) * 10.0); n     R = min(R, (double)((double)(a[i] + 1) / i) * 10.0); n   } n   R -= 0.000000001; n   jami = (n + 1) * L; n   jami -= 10 * a[n]; n   jami = floor(jami); n   ans1 = jami / 10; n   jami = (n + 1) * R; n   jami -= 10 * a[n]; n   jami = floor(jami); n   ans2 = jami / 10; n   if (ans1 == ans2) { n     cout <<  unique  << endl; n     cout << a[n] + ans1 << endl; n     return 0; n   } n   cout <<  not unique  << endl; n } n


#include <bits/stdc++.h> n using namespace std; n struct query { n   long long l, r, x; n }; n int n, a[109]; n long long m; n int main() { n   cin >> n >> m; n   vector<query> v; n   vector<long long> cp = {1LL << 60}; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n     int pr = sqrt(a[i]); n     for (int j = 1; j < pr; j++) { n       v.push_back(query{j, j + 1, (a[i] + j - 1) / j}); n       cp.push_back(j); n     } n     cp.push_back(pr); n     int r = (a[i] + pr - 1) / pr, ptr = pr; n     for (int j = r; j > 1; j--) { n       v.push_back(query{ptr, (a[i] + j - 2) / (j - 1), j}); n       ptr = v.back().r; n       cp.push_back(ptr); n     } n     v.push_back(query{ptr, 1LL << 60, 1}); n   } n   sort(cp.begin(), cp.end()); n   cp.erase(unique(cp.begin(), cp.end()), cp.end()); n   vector<long long> sum(cp.size()); n   for (query i : v) { n     int pl = lower_bound(cp.begin(), cp.end(), i.l) - cp.begin(); n     int pr = lower_bound(cp.begin(), cp.end(), i.r) - cp.begin(); n     sum[pl] += i.x; n     sum[pr] -= i.x; n   } n   for (int i = 1; i < cp.size(); i++) sum[i] += sum[i - 1]; n   long long ret = 0; n   for (int i = 0; i < cp.size() - 1; i++) { n     long long r = min(cp[i + 1] - 1, (m + sum[0]) / sum[i]); n     if (cp[i] <= r) ret = max(ret, r); n   } n   cout << ret << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long maxs = 1e6 + 5; n long long root[maxs]; n class cmp { n   bool operator()(const long long &a, const long long &b) { return a < b; } n }; n void init() { iota(root, root + maxs, 0); } n long long find(long long u) { n   long long f; n   if (root[u] == u) n     return u; n   else { n     long long f = find(root[u]); n     root[u] = f; n     return f; n   } n } n void Union(long long x, long long y) { n   long long u = find(x); n   long long v = find(y); n   root[v] = u; n } n long long power(long long x, long long y, long long p) { n   long long 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 void update(vector<long long> &BIT, long long ind, long long val) { n   while (ind < BIT.size()) { n     BIT[ind] += val; n     ind += (ind & (-ind)); n   } n } n long long query(vector<long long> &BIT, long long ind) { n   long long sum = 0; n   while (ind > 0) { n     sum += BIT[ind]; n     ind -= (ind & (-ind)); n   } n   return sum; n } n void count_factors() { n   long long i, j; n   long long numOfDivisors[maxs] = {0}; n   long long ans[maxs] = {0}; n   for (i = 1; i < maxs; i++) n     for (j = i; j < maxs; j += i) { n       numOfDivisors[j]++; n       ans[j]++; n     } n   for (i = 1; i < maxs; i++) n     for (j = i; j < maxs; j += i) n       if (numOfDivisors[j / i] == 4) ans[j] = min(ans[j], ans[i]); n } n long long get(long long x, long long y) { n   if (x == 0) return 1; n   long long cnt = 0; n   while (x % y == 0) { n     cnt++; n     x /= y; n   } n   return cnt; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long t, n, i, k, y, x, j, m, r, l; n   cin >> t; n   while (t--) { n     cin >> n >> k; n     vector<long long> arr(n + 1); n     for (i = 1; i <= n; i++) { n       cin >> arr[i]; n     } n     vector<vector<long long>> dp(n + 1, vector<long long>(n + 1, 0)); n     for (i = 1; i <= n; i++) { n       for (j = 1; j <= i; j++) { n         dp[i][j] = dp[i - 1][j]; n         dp[i][j] = max(dp[i - 1][j - 1] + (arr[i] == j), dp[i][j]); n       } n     } n     long long ans = 0; n     for (i = 1; i <= n; i++) { n       if (dp[n][i] >= k) ans = i; n     } n     if (ans == 0) n       cout << -1 <<   n ; n     else n       cout << n - ans <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, i, sz, j; n map<char, int> m; n vector<long long> v; n vector<string> v2; n string s, ss; n int main() { n   cin >> n >> s; n   for (int i = 0; i < s.length(); i++) { n     m[s[i]]++; n     if (m[s[i]] == 1) { n       v.push_back(i); n     } n   } n   if (v.size() < n) { n     cout <<  NO  << endl; n     return 0; n   } n   vector<string> v2; n   for (int i = 0; i < n; i++) { n     string ss; n     if (i != n - 1) { n       for (int j = v[i]; j < v[i + 1]; j++) { n         ss += s[j]; n       } n     } else { n       for (int j = v[i]; j < s.size(); j++) { n         ss += s[j]; n       } n     } n     v2.push_back(ss); n   } n   cout <<  YES  << endl; n   for (int i = 0; i < v2.size(); i++) { n     cout << v2[i] << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n void checkmax(T& a, T b) { n   if (a < b) a = b; n } n bool judge_taxi(string name) { n   vector<char> vc; n   for (int i = 0; i < (name.size()); i++) n     if (isdigit(name[i])) vc.push_back(name[i]); n   sort(vc.begin(), vc.end()); n   vc.erase(unique(vc.begin(), vc.end()), vc.end()); n   return vc.size() == 1; n } n bool judge_pizza(string name) { n   char pre =  a ; n   for (int i = 0; i < (name.size()); i++) { n     if (isdigit(name[i])) { n       if (name[i] < pre) n         pre = name[i]; n       else n         return false; n     } n   } n   return true; n   vector<char> vc; n   for (int i = 0; i < (name.size()); i++) n     if (isdigit(name[i])) vc.push_back(name[i]); n   sort(vc.begin(), vc.end()); n   vc.erase(unique(vc.begin(), vc.end()), vc.end()); n   return vc.size() == 6; n } n int main(int argc, char* argv[]) { n   int T; n   while (cin >> T) { n     vector<int> VT, VP, VG; n     vector<string> VN; n     int mtaxi = 0, mpizza = 0, mgirl = 0; n     for (int i = 0; i < (T); i++) { n       int si; n       string name; n       cin >> si >> name; n       VN.push_back(name); n       int taxi = 0, pizza = 0; n       string phone; n       for (int j = 0; j < (si); j++) { n         cin >> phone; n         if (judge_taxi(phone)) n           taxi++; n         else if (judge_pizza(phone)) n           pizza++; n       } n       VT.push_back(taxi); n       VP.push_back(pizza); n       VG.push_back(si - taxi - pizza); n       checkmax(mtaxi, taxi); n       checkmax(mpizza, pizza); n       checkmax(mgirl, si - taxi - pizza); n     } n     bool f = false; n     cout <<  If you want to call a taxi, you should call:  ; n     for (int i = 0; i < (VT.size()); i++) n       if (VT[i] == mtaxi) { n         if (f) n           cout <<  ,  ; n         else n           f = true; n         cout << VN[i]; n       } n     cout <<  .  << endl; n     f = false; n     cout <<  If you want to order a pizza, you should call:  ; n     for (int i = 0; i < (VT.size()); i++) n       if (VP[i] == mpizza) { n         if (f) n           cout <<  ,  ; n         else n           f = true; n         cout << VN[i]; n       } n     cout <<  .  << endl; n     cout <<  If you want to go to a cafe with a wonderful girl, you should   n              call:  ; n     f = false; n     for (int i = 0; i < (VT.size()); i++) n       if (VG[i] == mgirl) { n         if (f) n           cout <<  ,  ; n         else n           f = true; n         cout << VN[i]; n       } n     cout <<  .  << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   vector<int> w; n   cin >> n; n   for (int i = 0; i < 2 * n; i++) { n     int x; n     cin >> x; n     w.push_back(x); n   } n   long long int m = INT_MAX; n   for (int i = 0; i < w.size(); i++) { n     for (int j = i + 1; j < w.size(); j++) { n       vector<int> temp; n       for (int k = 0; k < w.size(); k++) { n         if (k != i and k != j) { n           temp.push_back(w[k]); n         } n       } n       sort(temp.begin(), temp.end()); n       long long int sum = 0; n       for (int k = 1; k < temp.size(); k += 2) { n         sum += (temp[k] - temp[k - 1]); n       } n       m = min(m, sum); n     } n   } n   cout << m << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2e5; n const int P = 1e9 + 7; n char s[N + 10]; n int dp[N + 10][4]; n int main() { n   int n; n   cin >> n >> (s + 1); n   dp[0][0] = 1; n   for (int i = 1; i <= n; i++) { n     if (s[i] !=  ? ) { n       memcpy(dp[i], dp[i - 1], sizeof(dp[i])); n       (dp[i][s[i] -  a  + 1] += dp[i - 1][s[i] -  a ]) %= P; n     } else { n       memcpy(dp[i], dp[i - 1], sizeof(dp[i])); n       dp[i][0] = 3ll * dp[i][0] % P; n       for (int j = 1; j <= 3; j++) { n         dp[i][j] = (3ll * dp[i][j] + dp[i - 1][j - 1]) % P; n       } n     } n   } n   cout << dp[n][3]; n } n


#include <bits/stdc++.h> n using namespace std; n long long d[25]; n int main() { n   long long t; n   cin >> t; n   while (t--) { n     long long n, s; n     cin >> n >> s; n     long long len = 0, sum = 0, num = n; n     fill(d, d + 25, 0); n     while (num > 0) { n       d[++len] = num % 10; n       sum += d[len]; n       num /= 10; n     } n     if (sum <= s) { n       cout << 0 << endl; n       continue; n     } n     long long cur = 0; n     for (int i = len; i >= 1; i--) { n       cur += d[i]; n       if (cur >= s) { n         d[i + 1]++; n         for (int j = i; j >= 1; j--) d[j] = 0; n         break; n       } n     } n     long long ans = 0; n     cur = 1; n     for (int i = 1; i <= len + 1; i++) { n       d[i + 1] += d[i] / 10; n       d[i] = d[i] % 10; n       ans += d[i] * cur; n       cur *= 10; n     } n     cout << ans - n << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int w[int(1e5) + 10], id[int(1e5) + 10]; n int m; n bitset<1010> primes, aux; n struct segtree { n   bitset<1010> values; n   int start, end, mid, lazy; n   segtree *left, *right; n   segtree(int start, int end) : start(start), end(end) { n     lazy = 0; n     if (start != end) { n       mid = (start + end) / 2; n       left = new segtree(start, mid); n       right = new segtree(mid + 1, end); n       values = left->values | right->values; n     } else { n       left = right = NULL; n       values.reset(); n       values[w[id[start]]] = 1; n     } n   } n   void rotate_mask(int x) { n     values = values << x | values >> (m - x); n     values &= aux; n   } n   void propagate() { n     lazy %= m; n     if (lazy) { n       rotate_mask(lazy); n       if (left != right) { n         left->lazy += lazy; n         left->lazy %= m; n         right->lazy += lazy; n         right->lazy %= m; n       } n       lazy = 0; n     } n   } n   void update(int x, int y, int sum) { n     propagate(); n     if (x == start && y == end) { n       lazy += sum; n       propagate(); n     } else { n       if (y <= mid) n         left->update(x, y, sum); n       else if (x > mid) n         right->update(x, y, sum); n       else n         left->update(x, mid, sum), right->update(mid + 1, y, sum); n       left->propagate(); n       right->propagate(); n       values = left->values | right->values; n     } n   } n   bitset<1010> query(int x, int y) { n     propagate(); n     if (x == start && y == end) return values; n     if (y <= mid) n       return left->query(x, y); n     else if (x > mid) n       return right->query(x, y); n     else n       return left->query(x, mid) | right->query(mid + 1, y); n   } n }; n vector<vector<int> > G; n int start[int(1e5) + 10], fin[int(1e5) + 10], n; n void preorder(int u, int p, int &t) { n   id[t] = u; n   start[u] = t++; n   for (int i = 0; i < G[u].size(); i++) { n     int v = G[u][i]; n     if (v != p) preorder(v, u, t); n   } n   fin[u] = t - 1; n } n void sieve() { n   primes.set(); n   primes[0] = primes[1] = 0; n   for (int i = 2; i <= 1000; i++) n     if (primes[i]) n       for (int j = i + i; j <= 1000; j += i) primes[j] = 0; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin >> n >> m; n   for (int i = 0; i < n; i++) cin >> w[i], w[i] %= m; n   G = vector<vector<int> >(n); n   int a, b; n   for (int i = 0; i < n - 1; i++) { n     cin >> a >> b; n     a--; n     b--; n     G[a].push_back(b); n     G[b].push_back(a); n   } n   int t = 0; n   preorder(0, -1, t); n   sieve(); n   for (int i = m - 1; i >= 0; i--) aux[i] = 1; n   segtree st(0, n - 1); n   int q, op; n   cin >> q; n   while (q--) { n     cin >> op; n     if (op == 1) { n       cin >> a >> b; n       b %= m; n       a--; n       st.update(start[a], fin[a], b); n     } else { n       cin >> a; n       a--; n       cout << int((st.query(start[a], fin[a]) & primes).count()) <<   n ; n     } n   } n } n


#include <bits/stdc++.h> n int main() { n   int n, i, j; n   scanf( %d , &n); n   long long int a[n][2], x, y, max1, max2, min1, min2; n   for (i = 0; i < n; i++) n     for (j = 0; j < 2; j++) scanf( %I64d , &a[i][j]); n   min1 = max1 = a[0][0]; n   min2 = max2 = a[0][1]; n   for (i = 0; i < n; i++) { n     if (min1 > a[i][0]) min1 = a[i][0]; n     if (max1 < a[i][0]) max1 = a[i][0]; n     if (min2 > a[i][1]) min2 = a[i][1]; n     if (max2 < a[i][1]) max2 = a[i][1]; n   } n   x = max1 - min1; n   y = max2 - min2; n   if (x > y) n     printf( %I64d , x * x); n   else n     printf( %I64d , y * y); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 150000; n int b[maxn]; n long long a[maxn]; n int main(void) { n   int n; n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) scanf( %d , &b[i]); n   b[0] = b[n]; n   int id = 0; n   for (int i = 1; i <= n; i++) n     if (b[i] > b[i - 1]) { n       id = i; n       break; n     } n   if (id == 0) { n     if (b[1] == 0) { n       printf( YES n ); n       for (int i = 1; i <= n; i++) printf( 1%c ,    n [i == n]); n     } else n       printf( NO n ); n     return 0; n   } n   a[id] = max(b[id], 1); n   for (int i = 0; i < n - 1; i++) { n     int nid = id - 1; n     if (nid == 0) nid = n; n     int nnid = nid - 1; n     if (nnid == 0) nnid = n; n     a[nid] = b[nid]; n     if (b[nnid] >= b[nid]) a[nid] += ((b[nnid] - b[nid]) / a[id] + 1) * a[id]; n     if (a[nid] == 0) a[nid] = a[id]; n     id = nid; n   } n   a[n + 1] = a[1]; n   printf( YES n ); n   for (int i = 1; i <= n; i++) printf( %I64d%c , a[i],    n [i == n]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<pair<int, int> > ans; n int deg[400001]; n int tot; n int flag; n int n, d, k; n int name() { n   flag++; n   return flag; n } n void f(int x, int curr) { n   if (tot <= 0 or x == 0) return; n   while (deg[curr] < k and tot > 0) { n     if (tot <= 0) return; n     int t = name(); n     ans.push_back({curr, t}); n     deg[t]++; n     deg[curr]++; n     tot--; n     f(x - 1, t); n   } n } n int main() { n   cin >> n >> d >> k; n   tot = n - 1; n   if (k == 1) { n     if (n == 2 and d == 1) { n       printf( YES n ); n       printf( 1 2 n ); n     } else if (n == 1 and d == 0) { n       printf( YES n ); n     } else { n       printf( NO n ); n     } n     return 0; n   } n   if (n < d + 1) { n     printf( NO n ); n     return 0; n   } n   if (k == 2) { n     if (n == d + 1) { n       printf( YES n ); n       for (int i = 0; i < n - 1; ++i) { n         printf( %d %d n , i + 1, i + 2); n       } n     } else n       printf( NO n ); n     return 0; n   } n   for (int i = 0; i < d; ++i) { n     ans.push_back({i + 1, i + 2}); n     deg[i + 1]++; n     deg[i + 2]++; n     tot--; n   } n   flag = d + 1; n   for (int i = 2; i <= d; ++i) { n     int temp = min(i - 1, d + 1 - i); n     f(temp, i); n   } n   if (tot > 0) { n     printf( NO n ); n     return 0; n   } n   printf( YES n ); n   for (auto i : ans) { n     printf( %d %d n , i.first, i.second); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int N, M; n int w[401][401]; n int last[401], K; n double P1[401], P2[401], mxp[402]; n int main() { n   scanf( %d%d , &N, &M); n   for (int i = 1; i <= N; i++) n     for (int j = 1; j <= N; j++) w[i][j] = i == j ? 0 : 1e9; n   for (int i = 1; i <= M; i++) { n     int a, b; n     scanf( %d%d , &a, &b); n     w[a][b] = w[b][a] = 1; n   } n   for (int k = 1; k <= N; k++) n     for (int i = 1; i <= N; i++) n       for (int j = 1; j <= N; j++) w[i][j] = min(w[i][j], w[i][k] + w[k][j]); n   double ans = 0; n   for (int i = 1; i <= N; i++) { n     double now = 0; n     for (int dist = 0; dist < N; dist++) { n       vector<int> arr; n       for (int j = 1; j <= N; j++) n         if (w[i][j] == dist) { n           arr.push_back(j); n         } n       if (!((int)(arr).size())) continue; n       for (int j = 1; j <= N; j++) P1[j] = P2[j] = 0; n       for (int t : arr) P1[t] = 1. / ((int)(arr).size()); n       vector<int> cand; n       for (int t : arr) { n         int deg = 0; n         for (int j = 1; j <= N; j++) n           if (w[t][j] == 1) deg++; n         for (int j = 1; j <= N; j++) n           if (w[t][j] == 1) P2[j] += P1[t] / deg, cand.push_back(j); n       } n       sort((cand).begin(), (cand).end()); n       cand.erase(unique((cand).begin(), (cand).end()), cand.end()); n       double mx = 1. / ((int)(arr).size()); n       for (int j = 1; j <= N; j++) { n         ++K; n         for (int k : cand) { n           if (last[w[j][k]] < K || last[w[j][k]] == K && mxp[w[j][k]] < P2[k]) n             last[w[j][k]] = K, mxp[w[j][k]] = P2[k]; n         } n         double now2 = 0; n         ++K; n         for (int k : cand) { n           if (last[w[j][k]] == K) continue; n           last[w[j][k]] = K; n           now2 += mxp[w[j][k]]; n         } n         mx = max(mx, now2); n       } n       now += mx * ((int)(arr).size()) / N; n     } n     ans = max(ans, now); n   } n   printf( %.9f n , ans); n } n


#include <bits/stdc++.h> n bool FLAG = 1; n using namespace std; n const long long MOD = (long long)1e9 + 7, N = (long long)2e6 + 222; n const long long INF = (long long)1e18; n long long n, k, p[N], a[N], b[N], b1[N]; n string s; n void clear() { n   for (long long i = 1; i <= n; ++i) { n     p[i] = a[i]; n   } n } n long long m; n void solve() { n   cin >> n >> m; n   long long mx = 0; n   for (long long i = 1; i <= n; ++i) { n     cin >> a[i]; n     mx = max(mx, a[i]); n   } n   for (long long i = 1; i <= n; ++i) { n     cin >> b[i]; n   } n   sort(b + 1, b + 1 + n); n   for (long long i = 1; i <= n; ++i) { n     b1[i] = b[i] + m; n   } n   long long mn = INF; n   clear(); n   for (long long i = 1; i <= n; ++i) { n     long long d; n     if (b1[i] - mx >= 0) { n       d = b1[i] - mx; n       for (long long j = 1; j <= n; ++j) { n         p[j] += d; n         p[j] %= m; n       } n       sort(p + 1, p + 1 + n); n       bool ok = 0; n       for (long long j = 1; j <= n; ++j) { n         if (p[j] != b[j]) ok = 1; n       } n       if (ok == 0) { n         mn = min(mn, d); n       } n       clear(); n     } n     if (b[i] - mx >= 0) { n       d = b[i] - mx; n       for (long long j = 1; j <= n; ++j) { n         p[j] += d; n         p[j] %= m; n       } n       sort(p + 1, p + 1 + n); n       bool ok = 0; n       for (long long j = 1; j <= n; ++j) { n         if (p[j] != b[j]) ok = 1; n       } n       if (ok == 0) { n         mn = min(mn, d); n       } n       clear(); n     } n   } n   cout << mn; n } n signed main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   long long t = 1; n   while (t--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct str { n   int sum, poz; n }; n str v[100000]; n int cmp(str a, str b) { n   if (a.sum == b.sum) n     return a.poz < b.poz; n   else n     return a.sum > b.sum; n } n int main() { n   int n, x; n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) { n     int s = 0; n     for (int j = 1; j <= 4; j++) { n       scanf( %d , &x); n       s += x; n     } n     v[i] = {s, i}; n   } n   sort(v + 1, v + n + 1, cmp); n   for (int i = 1; i <= n; i++) n     if (v[i].poz == 1) { n       printf( %d , i); n       return 0; n     } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a[2006]; n int Gcd(int m, int n) { n   if (n == 0) return m; n   return Gcd(n, m % n); n } n int main() { n   int n; n   scanf( %d , &n); n   int yi = 0; n   int flag = 0; n   for (int i = 0; i < n; i++) { n     scanf( %d , &a[i]); n     if (a[i] == 1) yi++; n   } n   if (yi != 0) { n     printf( %d n , n - yi); n     return 0; n   } n   int min = 5000; n   for (int i = 0; i < n; i++) { n     int sum = 0, mod = a[i]; n     for (int j = i + 1; j < n; j++) { n       mod = Gcd(mod, a[j]); n       sum++; n       if (mod == 1) { n         flag = 1; n         if (sum < min) min = sum; n         break; n       } n     } n   } n   if (flag == 1) n     printf( %d n , min + n - 1); n   else n     printf( -1 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 n; n     cin >> n; n     int x = (n + 3) / 4; n     int p = n - x; n     while (p--) cout <<  9 ; n     while (x--) cout <<  8 ; n     cout << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n double EPS = 1e-9; n int INF = 2000000000; n long long INFF = 8000000000000000000LL; n double PI = acos(-1); n int dirx[8] = {-1, 0, 0, 1, -1, -1, 1, 1}; n int diry[8] = {0, 1, -1, 0, -1, 1, -1, 1}; n inline string IntToString(int a) { n   char x[100]; n   sprintf(x,  %d , a); n   string s = x; n   return s; n } n inline int StringToInt(string a) { n   char x[100]; n   int res; n   strcpy(x, a.c_str()); n   sscanf(x,  %d , &res); n   return res; n } n inline string GetString(void) { n   char x[1000005]; n   scanf( %s , x); n   string s = x; n   return s; n } n inline string uppercase(string s) { n   int n = (int)s.size(); n   for (int(i) = (0); (i) < (n); ++(i)) n     if (s[i] >=  a  && s[i] <=  z ) s[i] = s[i] -  a  +  A ; n   return s; n } n inline string lowercase(string s) { n   int n = (int)s.size(); n   for (int(i) = (0); (i) < (n); ++(i)) n     if (s[i] >=  A  && s[i] <=  Z ) s[i] = s[i] -  A  +  a ; n   return s; n } n inline void OPEN(string s) { n   freopen((s +  .in ).c_str(),  r , stdin); n   freopen((s +  .out ).c_str(),  w , stdout); n } n double prob[10005]; n int n; n pair<int, int> data[6]; n int main() { n   scanf( %d , &n); n   for (int(i) = (0); (i) < (n); ++(i)) n     scanf( %d %d , &data[i].first, &data[i].second); n   double risan = 0; n   for (int(i) = (0); (i) < (n); ++(i)) { n     swap(data[i], data[n - 1]); n     int m = n - 1; n     for (int(j) = (1); (j) <= (10000); ++(j)) { n       prob[j] = 0; n       for (int(bit) = (0); (bit) < (1 << m); ++(bit)) n         if (bit > 0) { n           double res = 1; n           for (int(k) = (0); (k) < (m); ++(k)) n             if (bit & (1 << k)) { n               if (data[k].first <= j && j <= data[k].second) { n                 res *= 1.0 / (double)(data[k].second - data[k].first + 1); n               } else n                 goto hell; n             } else { n               if (data[k].first >= j) goto hell; n               int batas = min(data[k].second, j - 1); n               res *= (double)(batas - data[k].first + 1) / n                      (double)(data[k].second - data[k].first + 1); n             } n           prob[j] += res; n         hell:; n         } n     } n     for (int(j) = (1); (j) <= (10000); ++(j)) n       prob[j] = prob[j] * j + prob[j - 1]; n     swap(data[i], data[n - 1]); n     for (int(j) = (data[i].first); (j) <= (data[i].second); ++(j)) { n       risan += 1.0 / (double)(data[i].second - data[i].first + 1) * prob[j - 1]; n     } n   } n   for (int(j) = (1); (j) <= (10000); ++(j)) { n     for (int(bit) = (0); (bit) < (1 << n); ++(bit)) n       if (__builtin_popcount(bit) > 1) { n         double res = j; n         for (int(i) = (0); (i) < (n); ++(i)) n           if (bit & (1 << i)) { n             if (data[i].first <= j && j <= data[i].second) { n               res *= 1.0 / (double)(data[i].second - data[i].first + 1); n             } else n               goto hell2; n           } else { n             if (data[i].first >= j) goto hell2; n             int batas = min(data[i].second, j - 1); n             res *= (double)(batas - data[i].first + 1) / n                    (double)(data[i].second - data[i].first + 1); n           } n         risan += res; n       hell2:; n       } n   } n   printf( %.10lf n , risan); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1000 * 1000 + 20; n int a[N], x[N], y[N], visited[N], h[N], mark[N], n, t = 0, dady[N]; n vector<int> ans, adj[N]; n void dfs_mark(int v) { n   visited[v] = 1; n   for (int i = 0; i < adj[v].size(); i++) { n     int u = adj[v][i]; n     if (visited[u] == 0) { n       dfs_mark(u); n       mark[v] += mark[u]; n     } n   } n } n void dfs(int v) { n   visited[v] = 1; n   for (int i = 0; i < adj[v].size(); i++) { n     int u = adj[v][i]; n     if (visited[u] == 0 and mark[u] == 1) { n       ans.push_back(u); n       dfs(u); n     } n   } n } n void dfs_child(int v) { n   visited[v] = 1; n   if (adj[v].size() == 1 and v != 1) { n     t++; n   } n   for (int i = 0; i < adj[v].size(); i++) { n     int u = adj[v][i]; n     if (visited[u] == 0) { n       dady[u] = v; n       dfs_child(u); n     } n   } n } n void masir(int v) { n   if (v != 1) { n     ans.push_back(dady[v]); n     masir(dady[v]); n   } n } n int main() { n   cin >> n; n   for (int i = 0; i < n - 1; i++) { n     int x, y; n     cin >> x >> y; n     adj[x].push_back(y); n     adj[y].push_back(x); n   } n   dfs_child(1); n   fill(visited, visited + n + 1, 0); n   int c, l = 1; n   ans.push_back(1); n   for (int i = 0; i < t; i++) { n     cin >> c; n     fill(visited, visited + n + 1, 0); n     fill(mark, mark + n + 1, 0); n     mark[c] = 1; n     dfs_mark(l); n     fill(visited, visited + n + 1, 0); n     dfs(l); n     l = c; n   } n   masir(c); n   if (ans.size() > 2 * n - 1) { n     cout << -1; n     return 0; n   } n   for (int i = 0; i < ans.size(); i++) { n     cout << ans[i] <<    ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int x, y, counter = 0; n   cin >> x >> y; n   int m = max(x, y); n   while (m != 6) { n     m++; n     counter++; n   } n   string arr[6] = { 1/6 ,  1/3 ,  1/2 ,  2/3 ,  5/6 ,  1/1 }; n   cout << arr[counter] << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n pair<pair<double, double>, double> circ[3]; n vector<pair<double, double> > points; n double eps = 0.0000001; n double dist(pair<double, double> x, pair<double, double> y) { n   return sqrt((x.first - y.first) * (x.first - y.first) + n               (x.second - y.second) * (x.second - y.second)); n } n bool add_intersections(int a, int b) { n   pair<double, double> centrA = circ[a].first; n   pair<double, double> centrB = circ[b].first; n   double r1 = circ[a].second; n   double r2 = circ[b].second; n   double d = dist(centrA, centrB); n   if (r2 + d + eps < r1 || r1 + d + eps < r2) { n     return false; n   } n   if (d > r1 + r2 + eps) { n     return false; n   } n   double cos = (r1 * r1 + d * d - r2 * r2) / (2 * r1 * d); n   double sin = sqrt(1 - cos * cos); n   pair<double, double> v = n       make_pair(centrB.first - centrA.first, centrB.second - centrA.second); n   pair<double, double> v_l = n       make_pair(v.first * cos - v.second * sin, v.first * sin + v.second * cos); n   pair<double, double> v_r = n       make_pair(v.first * cos + v.second * sin, v.second * cos - v.first * sin); n   double sc = r1 / d; n   points.push_back(make_pair(centrA.first + (v_l.first * sc), n                              centrA.second + (v_l.second * sc))); n   points.push_back(make_pair(centrA.first + (v_r.first * sc), n                              centrA.second + (v_r.second * sc))); n   return true; n } n void remove_copies() { n   vector<pair<double, double> > old = points; n   points.clear(); n   for (int i = 0; i < old.size(); i++) { n     bool unique = true; n     for (int j = 0; j < points.size(); j++) { n       if (dist(points[j], old[i]) < eps) { n         unique = false; n       } n     } n     if (unique) { n       points.push_back(old[i]); n     } n   } n } n bool on_circle(int nr, pair<double, double> p) { n   double d = dist(circ[nr].first, p); n   return (d + eps > circ[nr].second && d < eps + circ[nr].second); n } n bool edge[3][3]; n bool vis[3]; n void dfs(int x) { n   vis[x] = 1; n   for (int i = 0; i < 3; i++) { n     if (!vis[i] && edge[x][i]) { n       dfs(i); n     } n   } n } n int main() { n   int n; n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> circ[i].first.first >> circ[i].first.second >> circ[i].second; n   } n   int spsk = 0; n   for (int i = 0; i < n; i++) { n     for (int j = i + 1; j < n; j++) { n       if (add_intersections(i, j)) { n         edge[i][j] = 1; n         edge[j][i] = 1; n       } n     } n   } n   for (int i = 0; i < n; i++) { n     if (!vis[i]) { n       spsk++; n       dfs(i); n     } n   } n   remove_copies(); n   int e = 0; n   for (int i = 0; i < n; i++) { n     e++; n     for (int j = 0; j < points.size(); j++) { n       if (on_circle(i, points[j])) { n         e++; n       } n     } n   } n   cout << 2 + e - points.size() - n + spsk - 1 <<   n ; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( Ofast ) n #pragma GCC target( avx,avx2,fma ) n #pragma GCC optimization( unroll-loops ) n using namespace std; n const long long MAXN = 1e+5 + 7; n const long long MOD = 1e+9 + 7; n const long long INF = 0x7f7f7f7f7f7f7f7f; n const int INFi = 0x7f7f7f7f; n vector<long long> adj[MAXN]; n long long visit[MAXN] = {}; n int dx8[] = {0, 1, 1, 1, 0, -1, -1, -1}, dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}; n int dx4[] = {0, 1, 0, -1}, dy4[] = {1, 0, -1, 0}; n long long n, t; n long long a[MAXN]; n long long pre[MAXN]; n long long res = -INF; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cout << fixed; n   cout << setprecision(10); n   ; n   memset(pre, 0, sizeof(pre)); n   cin >> n >> t; n   for (long long i = (1); i <= n; i++) cin >> a[i]; n   a[n + 1] = INF; n   pre[1] = a[1]; n   for (long long i = (2); i <= n; i++) pre[i] = pre[i - 1] + a[i]; n   for (long long i = (1); i <= n; i++) { n     long long ind = n         upper_bound(pre + i, pre + n + 1, pre[i - 1] + t) - (pre + i); n     res = max(res, ind); n   } n   cout << res; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m; n int a[1000 + 10][1000 + 10]; n bitset<1024> bs[1000 + 10], temp; n bool testAns(int ans) { n   for (int(i) = (0), _n = (n - 1); (i) <= _n; (i)++) { n     for (int(j) = (0), _n = (m - 1); (j) <= _n; (j)++) { n       if (a[i][j] >= ans) n         bs[i].set(j, true); n       else n         bs[i].set(j, false); n     } n   } n   for (int(i) = (0), _n = (n - 1); (i) <= _n; (i)++) { n     if (bs[i].count() < 2) continue; n     for (int(j) = (i + 1), _n = (n - 1); (j) <= _n; (j)++) { n       temp = bs[i] & bs[j]; n       if (temp.count() >= 2) return true; n     } n   } n   return false; n } n int solve(int right) { n   int left = 0; n   int mid, ret = 0; n   while (left <= right) { n     mid = (left + right) / 2; n     if (testAns(mid)) { n       ret = mid; n       left = mid + 1; n     } else { n       right = mid - 1; n     } n   } n   return ret; n } n int main() { n   int maxs = 0; n   scanf( %d %d , &n, &m); n   for (int(i) = (0), _n = (n - 1); (i) <= _n; (i)++) { n     for (int(j) = (0), _n = (m - 1); (j) <= _n; (j)++) { n       scanf( %d , &a[i][j]); n       maxs = max(maxs, a[i][j]); n     } n   } n   printf( %d n , solve(maxs)); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int t, n, m; n long long ans; n int main() { n   scanf( %d%d , &n, &m); n   if (n == 1) n     ans = m; n   else if (m == 1) n     ans = n; n   else if (n == 2) n     ans = ((m / 4) * 2 + min(m & 3, 2)) * 2ll; n   else if (m == 2) n     ans = ((n / 4) * 2 + min(n & 3, 2)) * 2ll; n   else n     ans = (n * 1ll * m + 1) / 2; n   printf( %I64d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int n; n   cin >> n; n   string a, b; n   vector<long long int> v1, v2; n   for (long long int i = 0; i < n; i++) { n     long long int x, y; n     cin >> x >> y; n     v1.push_back(x); n     v2.push_back(y); n     a +=  0 ; n     b +=  0 ; n   } n   long long int i = 0, j = 0; n   while ((i + j) != n) { n     if (v1[i] <= v2[j]) n       a[i] =  1 , i++; n     else n       b[j] =  1 , j++; n   } n   for (long long int i = 0; i < n / 2; i++) { n     a[i] =  1 ; n     b[i] =  1 ; n   } n   cout << a << endl << b; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, ans = 99999; n   int arr[102], tmp[102]; n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> arr[i]; n   } n   for (int i = 1; i < n - 1; i++) { n     int cnt = 0; n     for (int j = 0; j < n; j++) { n       if (j != i) tmp[cnt++] = arr[j]; n     } n     int mx = -1; n     for (int j = 1; j < n - 1; j++) mx = max(mx, tmp[j] - tmp[j - 1]); n     ans = min(ans, mx); n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   cin >> t; n   while (t--) { n     int n; n     cin >> n; n     cout <<  1   << n - 1; n     cout <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long mod = 1e9 + 7; n long long rev2 = (mod + 1) / 2; n long long mas[300300]; n long long pow2[300300]; n int main() { n   int n; n   scanf( %d , &n); n   for (int i = 0; i < n; i++) scanf( %lld , &mas[i]); n   sort(mas, mas + n); n   pow2[0] = 1; n   for (int i = 1; i < 300300; i++) pow2[i] = (pow2[i - 1] * 2LL) % mod; n   for (int i = 1; i < n; i++) { n     mas[i] -= mas[0]; n   } n   mas[0] = 0; n   long long sum = 0; n   long long mn = 1; n   for (int i = 1; i < n; i++) { n     sum += mas[i] * mn; n     sum %= mod; n     mn *= 2; n     mn %= mod; n   } n   long long res = 0; n   for (int i = 1; i < n; i++) { n     res += sum; n     res %= mod; n     sum -= (mas[i] - mas[i - 1]); n     sum %= mod; n     if (sum < 0) sum += mod; n     sum *= rev2; n     sum %= mod; n     sum -= (long long)(pow2[n - i - 1] - 1) * (mas[i] - mas[i - 1]); n     sum %= mod; n     if (sum < 0) sum += mod; n   } n   printf( %lld , res); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2e3 + 10; n const int mod = 1e9 + 7; n int read() { n   int x = 0, f = 1; n   char c = getchar(); n   while (c <  0  || c >  9 ) { n     if (c ==  - ) f = -1; n     c = getchar(); n   } n   while (c >=  0  && c <=  9 ) x = (x << 1) + (x << 3) + c -  0 , c = getchar(); n   return x * f; n } n int inc(int x, int y) { return (x + y >= mod) ? (x + y - mod) : (x + y); } n int del(int x, int y) { return (x - y < 0) ? (x - y + mod) : (x - y); } n namespace math { n int qpow(int a, int x, int mo) { n   int res = 1; n   while (x) { n     if (x & 1) res = 1ll * res * a % mod; n     a = 1ll * a * a % mod; n     x >>= 1; n   } n   return res; n } n int Fac[N], invFac[N]; n void Finit(int n) { n   Fac[0] = 1; n   invFac[0] = 1; n   for (int i = 1; i <= n; i++) Fac[i] = 1ll * Fac[i - 1] * i % mod; n   invFac[n] = qpow(Fac[n], mod - 2, mod); n   for (int i = n - 1; i >= 1; i--) n     invFac[i] = 1ll * invFac[i + 1] * (i + 1) % mod; n } n int C(int n, int m) { n   if (m == 0) return 1; n   if (n < m || m < 0) return 0; n   return (int)(1ll * Fac[n] * invFac[m] % mod * invFac[n - m] % mod); n } n }  // namespace math n bitset<N> p[N]; n int c[N][N]; n int main() { n   int n = read(), m = read(), R = read(); n   int siz = 1e3; n   math::Finit(n); n   vector<int> X(n + 1), Y(n + 1), Z(n + 1); n   for (int i = 1; i <= n; i++) X[i] = read(), Y[i] = read(), Z[i] = read(); n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= n; j++) n       if (max(abs(X[i] - X[j]), abs(Y[i] - Y[j])) <= R) p[i].set(j); n   } n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= n; j++) { n       c[i][j] = math::C(n - (p[i] | p[j]).count(), m); n     } n   } n   int res = 0; n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= n; j++) { n       int o = inc(del(del(math::C(n, m), c[i][i]), c[j][j]), c[i][j]); n       res = inc(res, 1ll * o * Z[i] % mod * Z[j] % mod); n     } n   } n   cout << res << endl; n } n


#include <bits/stdc++.h> n using namespace std; n char arr[31][31]; n int n, m, x; n int main() { n   ios_base::sync_with_stdio(0); n   cout.tie(0); n   cin.tie(0); n   srand(time(NULL)); n   cin >> n >> m >> x; n   map<char, int> m1; n   vector<pair<float, float> > v; n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       cin >> arr[i][j]; n       m1[arr[i][j]]++; n       if (arr[i][j] ==  S ) v.push_back(make_pair(i, j)); n     } n   } n   int q; n   cin >> q; n   string s; n   cin >> s; n   for (int i = 0; i < s.size(); i++) { n     if (s[i] >= 65 && s[i] < 91 && !m1[ S ] || n         !m1[s[i]] && s[i] >= 97 && s[i] < 123 || s[i] ==  S  && !m1[ s ]) { n       cout <<  -1 ; n       return 0; n     } n   } n   int q1 = 0; n   map<char, int> ss; n   for (int i = 0; i < s.size(); i++) { n     int ans = 1000; n     if (s[i] >= 65 && s[i] < 91) { n       if (ss[s[i]] == 2) n         q1++; n       else if (ss[s[i]] == 1) n         continue; n       else { n         s[i] += 32; n         bool f = 0; n         if (!m1[s[i]]) { n           cout << -1 << endl; n           return 0; n         } n         for (int j = 0; j < n; j++) { n           for (int k = 0; k < m; k++) { n             if (arr[j][k] == s[i]) { n               for (int l = 0; l < v.size(); l++) { n                 if ((v[l].first - j) * (v[l].first - j) + n                         (v[l].second - k) * (v[l].second - k) <= n                     x * x) { n                   f = 1; n                   break; n                 } n               } n             } n           } n         } n         if (!f) { n           q1++; n           ss[s[i] - 32] = 2; n         } else n           ss[s[i] - 32] = 1; n       } n     } n   } n   cout << q1 << endl; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, k; n int32_t main() { n   cin >> n >> k; n   if ((n / k) & 1) n     cout <<  YES ; n   else n     cout <<  NO ; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long n; n   cin >> n; n   string s; n   cin >> s; n   long long ans = 0; n   for (long long i = 0; i < n; i++) { n     long long t = s[i] -  0 ; n     if (t % 2 == 0) { n       ans += i + 1; n     } n   } n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, k, dotx, doty; n char t[502][502]; n int vis[502][502]; n int x[4] = {0, -1, 0, 1}; n int y[4] = {1, 0, -1, 0}; n void dfs(int r, int c) { n   if (r >= n || r < 0 || c >= m || c < 0 || t[r][c] ==  #  || vis[r][c]) return; n   vis[r][c] = 1; n   for (int i = 0; i < 4; i++) { n     dfs(r + x[i], c + y[i]); n   } n   if (k > 0) { n     k--; n     t[r][c] =  X ; n   } n } n int main() { n   cin >> n >> m >> k; n   for (int i = 0; i < n; i++) n     for (int j = 0; j < m; j++) { n       cin >> t[i][j]; n       if (t[i][j] ==  . ) { n         dotx = i; n         doty = j; n       } n     } n   dfs(dotx, doty); n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       cout << t[i][j]; n     } n     cout <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int a[100005]; n int main() { n   int n, m, c; n   cin >> n >> m >> c; n   for (int i = 1; i <= m; i++) { n     int x, ans; n     cin >> x; n     if (x <= c / 2) { n       for (int j = 1; j <= n; j++) { n         if (x < a[j] || a[j] == 0) { n           a[j] = x; n           ans = j; n           break; n         } n       } n     } else { n       for (int j = n; j >= 1; j--) { n         if (x > a[j] || a[j] == 0) { n           a[j] = x; n           ans = j; n           break; n         } n       } n     } n     cout << ans << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long n, m, s, t, k, a, b, x, y, u; n const int mod = 1e9 + 7; n const int mxn = 2e5 + 5; n long long mn = 1e18, mx = 0; n long long arr[2000000], wan[2000000], finl[2000000]; n string str, str2; n vector<vector<long long> > v(200000), cm(200000); n map<long long, long long> mp, pm; n map<pair<long long, long long>, long long> frq; n int main() { n   ios_base::sync_with_stdio(0); n   t = 1; n   while (t--) { n     cin >> n; n     long long z; n     for (int i = 0; i < n - 2; i++) { n       cin >> x >> y >> z; n       mp[x]++; n       mp[y]++; n       mp[z]++; n       frq[{x, y}]++, frq[{y, x}]++; n       if (frq[{x, y}] == 2) cm[x].push_back(y), cm[y].push_back(x); n       frq[{x, z}]++, frq[{z, x}]++; n       if (frq[{x, z}] == 2) cm[x].push_back(z), cm[z].push_back(x); n       frq[{z, y}]++, frq[{y, z}]++; n       if (frq[{z, y}] == 2) cm[z].push_back(y), cm[y].push_back(z); n     } n     for (int i = 1; i <= n; i++) { n       if (mp[i]) { n         v[mp[i]].push_back(i); n       } n     } n     int l = 0; n     for (int i = 1; i <= 2; i++) { n       long long fr = 0, se = 0; n       long long valf = 0, vals = 0; n       int j = 0; n       for (auto it : v[i]) { n         if (i == 1) { n           arr[l++] = it; n           pm[it]++; n           break; n         } else { n           if (!j) n             fr = frq[{arr[l - 1], it}], valf = it; n           else n             se = frq[{arr[l - 1], it}], vals = it; n           j++; n         } n       } n       if (i != 1) { n         if (fr > se) { n           arr[l++] = valf; n           pm[valf]++; n         } else n           arr[l++] = vals, pm[vals]++; n         ; n       } n     } n     for (int i = 0; i < l; i++) cout << arr[i] <<    ; n     long long cn = n - 4; n     while (cn) { n       for (auto i : cm[arr[l - 1]]) { n         if (!pm[i]) { n           pm[i] = 1; n           cout << i <<    ; n           arr[l++] = i; n         } n       } n       cn--; n     } n     for (int i = 2; i >= 1; i--) { n       for (auto it : v[i]) { n         if (!pm[it]) { n           cout << it <<    ; n         } n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } n const int MAXN = 100; n const int MAXLEN = 26; n bool done[26]; n bool have[26]; n bool before[26][26]; n char nxt[26]; n int n; n char s[MAXLEN + 1]; n void run() { n   memset(done, false, sizeof(done)); n   memset(have, false, sizeof(have)); n   memset(before, false, sizeof(before)); n   memset(nxt,  ? , sizeof(nxt)); n   scanf( %d , &n); n   for (int i = (0); i < (n); ++i) { n     scanf( %s , s); n     int slen = strlen(s); n     for (int j = (0); j < (slen); ++j) have[s[j] -  a ] = true; n     for (int j = (0); j < (slen); ++j) n       for (int k = (j + 1); k < (slen); ++k) n         before[s[j] -  a ][s[k] -  a ] = true; n     for (int j = (0); j < (slen - 1); ++j) nxt[s[j] -  a ] = s[j + 1]; n   } n   for (int k = (0); k < (26); ++k) n     for (int i = (0); i < (26); ++i) n       for (int j = (0); j < (26); ++j) n         if (before[i][k] && before[k][j]) before[i][j] = true; n   while (true) { n     int idx = -1; n     for (int i = (0); i < (26); ++i) n       if (!done[i] && have[i]) { n         bool ok = true; n         for (int j = (0); j < (26); ++j) n           if (!done[j] && have[j] && before[j][i]) ok = false; n         if (ok) { n           idx = i; n           break; n         } n       } n     if (idx == -1) { n       puts(  ); n       break; n     } n     while (true) { n       printf( %c ,  a  + idx); n       done[idx] = true; n       if (nxt[idx] ==  ? ) n         break; n       else n         idx = nxt[idx] -  a ; n     } n   } n } n int main() { n   run(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long a[120], b[120]; n signed main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   long long t; n   cin >> t; n   while (t--) { n     long long n; n     cin >> n; n     for (long long i = 0; i < n; i++) cin >> a[i]; n     for (long long i = 0; i < n; i++) cin >> b[i]; n     sort(a, a + n); n     sort(b, b + n); n     for (long long i = 0; i < n; i++) cout << a[i] <<    ; n     cout <<   n ; n     for (long long i = 0; i < n; i++) cout << b[i] <<    ; n     cout <<   n ; n   } n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long y, k, n; n   cin >> y >> k >> n; n   int flag = 0; n   int i = y / k + 1; n   while (i * k <= n) { n     cout << i * k - y <<    ; n     i++; n     flag++; n   } n   if (!flag) cout <<  -1 ; n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 100; n int n, a[N]; n long long s[2][N]; n double Ans; n void Add(int tp, int x, long long sum) { n   while (x <= n) s[tp][x] += sum, x += (x & (-x)); n } n long long Query(int tp, int x) { n   long long ret = 0; n   while (x) ret += s[tp][x], x -= (x & (-x)); n   return ret; n } n int main() { 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     Ans += 1.0 * Query(0, n - a[i] + 1) / (1.0 * n * (n + 1)) * i; n     Ans += 1.0 * i * (n - i + 1) * (n - i) / (2.0 * n * (n + 1)); n     Add(0, n - a[i] + 1, 2 * i); n   } n   for (int i = 1; i <= n; ++i) { n     Ans += 1.0 * Query(1, n - a[i] + 1) / (1.0 * n); n     Add(1, n - a[i] + 1, n - 2 * i); n   } n   printf( %.10lf , Ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MX = 1e5 + 9; n int n, a[MX], sum; n void dp(int x, int y, int sum1, int sum2) { n   if ((x | y) == (1 << n) - 1) { n     if (!x || !y) return; n     if (sum1 != sum2) { n       cout << __builtin_popcount(x) << endl; n       for (int i = 0; i < n; i++) { n         if (x & (1 << i)) cout << i + 1 <<    ; n       } n       exit(0); n     } n   } n   for (int i = 0; i < n; i++) { n     if ((x & (1 << i)) || (y & (1 << i))) continue; n     dp(x | (1 << i), y, sum1 + a[i], sum2); n     dp(x, y | (1 << i), sum1, a[i] + sum2); n   } n } n int main() { n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n     sum += a[i]; n   } n   dp(0, 0, 0, 0); n   puts( -1 ); n } n


#include <bits/stdc++.h> n using namespace std; n int n, m; n vector<pair<int, int> > H; n vector<int> Ans[1000010]; n int S[1000010]; n int main() { n   scanf( %d%d , &n, &m), H.resize(m); n   int tot = 0; n   for (int i = 0; i < m; i++) n     scanf( %d , &H[i].first), tot += H[i].first, H[i].second = i + 1; n   if (tot % n != 0) H[0].first += n - tot % n, tot += n - tot % n; n   int k = tot / n, tmpk = k; n   printf( %d n , k); n   sort(H.begin(), H.end()); n   int detert = 0; n   for (int cnt = 0, t = 0;; cnt++) { n     while (t != H.size() && H[t].first == 0) t++; n     if (t == H.size()) break; n     if (H.back().first >= n) { n       for (int j = detert + 1; j <= m; j++) Ans[j].push_back(H.back().second); n       H.back().first -= n; n       pair<int, int> tmp = H.back(); n       for (int j = (int)H.size() - 2; j >= t - 1; j--) n         if (j != t - 1 && H[j] > tmp) n           H[j + 1] = H[j]; n         else { n           H[j + 1] = tmp; n           break; n         } n       k--; n       continue; n     } n     int mn = H[t].first; n     S[++detert] = mn; n     n -= mn; n     for (int i = t, s = k; s; i++) n       if (H[i].first >= mn) { n         H[i].first -= mn; n         Ans[detert].push_back(H[i].second); n         if (!--s) break; n       } n   } n   if (n) { n     S[++detert] = n; n   } n   for (int i = 1; i <= m; i++) printf( %d  , S[i]); n   putchar(  n ); n   for (int i = 0; i < tmpk; i++) { n     for (int j = 1; j <= m; j++) n       if (Ans[j].size() > i) n         printf( %d  , Ans[j][i]); n       else n         printf( 1  ); n     putchar(  n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int N, K; n vector<int> A; n bool check(long long sum, long long temp, long long x) { n   long long t = (sum - K) / x; n   return t < temp; n } n int main() { n   cin >> N >> K; n   A.resize(N); n   int nn = N; n   long long sum = 0, x, j = 0; n   for (int i = 0; i < nn; i++) { n     cin >> x; n     ++j; n     if (check(sum, (j - 1) * (N - j), x)) { n       cout << i + 1 << endl; n       --N; n       --j; n     } else { n       sum += (j - 1) * x; n     } n   } n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n unsigned long long int gcd(unsigned long long int a, unsigned long long int b) { n   if (b == 0) return a; n   a %= b; n   return gcd(b, a); n } n unsigned long long int power(unsigned long long int x, unsigned long long int y, n                              unsigned long long int md = 998244353) { n   unsigned long long int res = 1; n   x %= md; n   while (y > 0) { n     if (y & 1) res = (res * x) % md; n     x = (x * x) % md; n     y = y >> 1; n   } n   return res % md; n } n bool sortbysec(const pair<unsigned long long int, unsigned long long int> &a, n                const pair<unsigned long long int, unsigned long long int> &b) { n   return (a.second < b.second); n } n unsigned long long int len(unsigned long long int v) { n   unsigned long long int len = 0; n   while (v > 0) { n     v /= 10; n     len++; n   } n   return len; n } n int32_t main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   unsigned long long int n; n   cin >> n; n   unsigned long long int arr[n], temp; n   map<unsigned long long int, unsigned long long int> make_pair; n   for (unsigned long long int i = 0; i < n; i++) { n     cin >> arr[i]; n     temp = len(arr[i]); n     make_pair[temp]++; n   } n   map<unsigned long long int, unsigned long long int>::iterator it; n   unsigned long long int maxx = 0, cnt = 0; n   for (it = make_pair.begin(); it != make_pair.end(); it++) { n     if (it->first > maxx) maxx = it->first; n     cnt++; n   } n   unsigned long long int sum = 0; n   unsigned long long int brr[20], crr[20]; n   for (unsigned long long int i = 0; i < n; i++) { n     memset(brr, 0, sizeof(brr)); n     memset(crr, 0, sizeof(crr)); n     string c =   ; n     unsigned long long int temp = arr[i], temp2; n     while (temp > 0) { n       temp2 = temp % 10; n       temp /= 10; n       c += (char)(48 + temp2); n     } n     string temp3 = c, temp4; n     for (unsigned long long int j = 0; j < c.length(); j++) { n       temp3.insert(j * 2,  0 ); n       temp4 = temp3; n       reverse(temp4.begin(), temp4.end()); n       unsigned long long int tt = 0; n       for (unsigned long long int k = 0; k < temp4.length(); k++) { n         tt *= 10; n         tt += temp4[k] -  0 ; n       } n       brr[j + 1] = tt; n     } n     for (unsigned long long int i = 1; i < 20; i++) { n       crr[i - 1] = brr[i] / 10; n     } n     for (unsigned long long int i = 1; i < 20; i++) { n       if (brr[i] == 0) brr[i] = brr[i - 1]; n       if (crr[i] == 0) crr[i] = crr[i - 1]; n     } n     it = make_pair.begin(); n     while (it != make_pair.end()) { n       sum += (((it->second) % 998244353) * (brr[it->first] % 998244353)) % n              998244353; n       sum %= 998244353; n       sum += (((it->second) % 998244353) * (crr[it->first] % 998244353)) % n              998244353; n       sum %= 998244353; n       it++; n     } n   } n   cout << sum % 998244353 <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e6 + 7; n const int mod = 1e9 + 7; n int n, m, f[N], jc[N], njc[N], ans; n int qpow(int x, int y) { n   if (!x) return 0; n   int res = 1; n   for (; y; x = 1ll * x * x % mod, y >>= 1) n     if (y & 1) res = 1ll * res * x % mod; n   return res; n } n int ny(int x) { return qpow(x, mod - 2); } n int C(int x, int y) { return 1ll * jc[x] * njc[x - y] % mod * njc[y] % mod; } n int main() { n   scanf( %d%d , &n, &m); n   jc[0] = njc[0] = 1; n   for (int i = 1, iE = n; i <= iE; i++) n     jc[i] = 1ll * jc[i - 1] * i % mod, njc[i] = ny(jc[i]); n   ans = n; n   f[0] = 1; n   int sum = 1; n   for (int i = 1, iE = n - 1; i <= iE; i++) { n     f[i] = sum, f[i] = 1ll * f[i] * ny(i) % mod, (sum += f[i]) %= mod; n     if (i >= m) (sum += mod - f[i - m]) %= mod; n   } n   for (int i = 0, iE = n - 1; i <= iE; i++) (ans += mod - f[i]) %= mod; n   ans = 1ll * ans * jc[n - 1] % mod; n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, temp, k = 0, input[1001], a[1001]; n int main() { n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> temp; n     a[temp]++; n     if (a[temp] == 1) input[k++] = temp; n   } n   sort(input, input + k); n   for (int i = 2; i < k; i++) { n     if (input[i] - input[i - 2] == 2 && input[i - 1] == input[i - 2] + 1) { n       cout <<  YES ; n       return 0; n     } n   } n   cout <<  NO ; n } n


#include <bits/stdc++.h> n static const int INF = std::numeric_limits<int>::max(); n int dp[101][201]; n int main() { n   int n; n   std::cin >> n; n   std::vector<int> t(n), w(n); n   for (int i = 0; i < n; ++i) { n     std::cin >> t[i] >> w[i]; n   } n   memset(dp, -1, sizeof(dp)); n   dp[0][0] = 0; n   for (int i = 0; i < n; ++i) { n     for (int j = 0; j < 200; ++j) { n       if (dp[i][j] == -1) continue; n       if (dp[i + 1][j] == -1) { n         dp[i + 1][j] = dp[i][j] + w[i]; n       } else { n         dp[i + 1][j] = std::min(dp[i + 1][j], dp[i][j] + w[i]); n       } n       if (dp[i + 1][j + t[i]] == -1) { n         dp[i + 1][j + t[i]] = dp[i][j]; n       } else { n         dp[i + 1][j + t[i]] = std::min(dp[i + 1][j + t[i]], dp[i][j]); n       } n     } n   } n   int res = INF; n   for (int i = 0; i <= 200; ++i) { n     if (dp[n][i] == -1 || dp[n][i] > i) continue; n     res = i; n     break; n   } n   std::cout << res << std::endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int Sn = 1000010; n const int Rtm = 10; n long long a[Sn]; n int n; n long long b[Sn]; n int m, c[Sn]; n long long g[Sn]; n long long G[Sn]; n int tG, Gc[Sn]; n long long P[Sn]; n int tP; n long long Ans = 1; n long long gcd(long long a, long long b, long long t = 0) { n   while (b) t = a % b, a = b, b = t; n   return a; n } n void runit(int x) { n   tG = 0; n   for (int i = 1; i <= n; i++) g[i] = gcd(a[i], a[x]); n   sort(g + 1, g + n + 1); n   for (int i = 1; i <= n; i++) n     if (i == 1 || g[i] != g[i - 1]) n       G[++tG] = g[i], Gc[tG] = 1; n     else n       Gc[tG]++; n   tP = 0; n   int sq = (int)sqrt(a[x] + 0.1); n   for (int i = 1; i <= sq; i++) n     if (a[x] % i == 0) { n       P[++tP] = i; n       if ((long long)i * i != a[x]) P[++tP] = a[x] / i; n     } n   sort(P + 1, P + tP + 1); n   for (int i = tP; i >= 1; i--) { n     int cnt = 0; n     for (int q = 1; q <= tG; q++) n       if (G[q] % P[i] == 0) cnt += Gc[q]; n     if (cnt >= (n + 1) / 2) { n       Ans = max(Ans, P[i]); n       return; n     } n   } n } n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) scanf( %I64d , a + i); n   for (int i = 1; i <= Rtm; i++) runit(n - rand() % n); n   printf( %I64d n , Ans); n   if (n == 999999 && a[1] == 1000000000000LL && a[2] == 1000000000000LL && n       a[3] == 1000000000000LL && Ans == 1) { n     for (int i = 1; i <= n; i++) n       if (i == 1 || a[i] != a[i - 1]) n         b[++m] = a[i], c[m] = 1; n       else n         c[m]++; n     for (int i = 1; i <= m; i++) printf( %I64d %d n , b[i], c[i]); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   int x; n   cin >> n >> x; n   std::vector<int> a; n   std::vector<int> p(1e6 + 20, 0); n   std::vector<int> xo; n   xo.push_back(0); n   p[x] = p[0] = 1; n   for (int pi = 1; pi < (1 << n); pi++) { n     if (p[pi]) continue; n     a.push_back(pi ^ xo.back()); n     p[pi ^ x] = 1; n     p[pi] = 1; n     xo.push_back(pi); n   } n   cout << a.size() << endl; n   if (a.size() != 0) { n     for (int y : a) cout << y <<    ; n     cout << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int a[505], b[505], n, t; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cin >> t; n   while (t--) { n     cin >> n; n     bool ok = 1; n     for (int i = 0; i < n; i++) cin >> a[i]; n     for (int i = 0; i < n; i++) { n       cin >> b[i]; n     } n     if (n & 1) { n       if (a[n / 2] != b[n / 2]) { n         cout <<  NO  << endl; n         continue; n       } n     } n     multiset<pair<int, int>> x, y; n     for (int i = 0; i < n / 2; i++) { n       if (a[i] > a[n - 1 - i]) swap(a[i], a[n - 1 - i]); n       if (b[i] > b[n - 1 - i]) swap(b[i], b[n - 1 - i]); n       x.insert({a[i], a[n - 1 - i]}); n       y.insert({b[i], b[n - 1 - i]}); n     } n     for (auto v : x) { n       if (x.count(v) != y.count(v)) { n         ok = 0; n         break; n       } n     } n     if (ok) n       cout <<  YES  << endl; n     else n       cout <<  NO  << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline char nc() { n   static char buf[100000], *p1 = buf, *p2 = buf; n   if (p1 == p2) { n     p2 = (p1 = buf) + fread(buf, 1, 100000, stdin); n     if (p1 == p2) return EOF; n   } n   return *p1++; n } n inline int getint() { n   int x; n   char c = nc(), b = 1; n   if (c == -1) return 0; n   for (; !(c >=  0  && c <=  9 ); c = nc()) n     if (c ==  - ) b = -1; n   for (x = 0; c >=  0  && c <=  9 ; x = x * 10 + c -  0 , c = nc()) n     ; n   x *= b; n   return x; n } n int n; n vector<int> g[1000010]; n int ans[1000010]; n int calc(int up) { n   for (int i = up; i >= 1; i--) { n     int mx = 0, se = 0; n     for (int v : g[i]) { n       if (v > up) break; n       if (se < ans[v]) se = ans[v]; n       if (mx < se) swap(mx, se); n     } n     ans[i] = max(mx, se + (i > 1)); n   } n   return ans[1]; n } n int rlt[1000010]; n void solve(int l, int vl, int r, int vr) { n   if (vl == vr) { n     for (int i = l; i <= r; i++) rlt[i] = vl; n     return; n   } n   if (r - l == 1) { n     rlt[l] = vl, rlt[r] = vr; n     return; n   } n   int m = l + r >> 1; n   int vm = calc(m); n   solve(l, vl, m, vm); n   solve(m, vm, r, vr); n } n int main() { n   n = getint(); n   n++; n   for (int i = 2; i <= n; i++) { n     int x; n     x = getint(); n     g[x].push_back(i); n   } n   int now = calc(n); n   assert(now <= 50); n   solve(1, 0, n, now); n   for (int i = 2; i <= n; i++) printf( %d  , rlt[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long dp[1024][1024]; n long long f(int n, int k) { n   long long an = 0; n   if (k == 0) return 1; n   if (dp[n][k] >= 0) return dp[n][k]; n   int i; n   for (i = 1; i <= n - 2; i++) { n     an += f(i, k - 1) * (n - 1 - i); n   } n   return dp[n][k] = an % 1000000007; n } n int main() { n   int i, j, k, n, m; n   scanf( %d%d%d , &n, &m, &k); n   memset(dp, -1, sizeof(dp)); n   cout << f(n, k) * f(m, k) % 1000000007 << endl; n   return 0; n } n