#include <bits/stdc++.h> n using namespace std; n const int NIL = -1; n template <class T> n inline T mx(T a, T b) { n   return a > b ? a : b; n } n template <class T> n inline T mi(T a, T b) { n   return a < b ? a : b; n } n template <class T> n inline void sw(T &a, T &b) { n   T t = a; n   a = b; n   b = t; n } n template <class T> n inline T mabs(T x) { n   return x < 0 ? -x : x; n } n inline char gc() { n   char ret; n   while ((ret = getchar()) ==     || ret ==   n  || ret ==   t ) n     ; n   return ret; n } n template <class T> n inline T sq(T x) { n   return x * x; n } n const int LIM = 1e5 + 10; n long long n, m, seed, vmax; n map<long long, long long> ct; n inline map<long long, long long>::iterator split(long long p) { n   map<long long, long long>::iterator ret = --ct.upper_bound(p); n   if (ret->first != p) ct[p] = ret->second, ret++; n   return ret; n } n inline void add(long long l, long long r, long long diff) { n   map<long long, long long>::iterator s = split(l), e = split(r + 1); n   while (s != e) (s++)->second += diff; n } n inline void assign(long long l, long long r, long long x) { n   map<long long, long long>::iterator s = split(l), e = split(r + 1); n   while (s != e) ct.erase(s++); n   ct[l] = x; n } n vector<pair<long long, long long> > buff; n inline long long kSmallest(long long l, long long r, long long k) { n   map<long long, long long>::iterator s = split(l), e = split(r + 1); n   buff.clear(); n   while (s != e) { n     r = (e--)->first; n     buff.push_back(make_pair(e->second, r - e->first)); n   } n   sort(buff.begin(), buff.end()); n   for (int i = 0; i < buff.size(); i++) n     if ((k -= buff[i].second) <= 0) return buff[i].first; n   return -1; n } n inline long long fp(long long base, long long p, long long mod) { n   long long ret = 1; n   base %= mod; n   do { n     if (p & 1) ret = ret * base % mod; n     base = base * base % mod; n   } while (p >>= 1); n   return ret; n } n inline long long powSum(long long l, long long r, long long p, long long mod) { n   map<long long, long long>::iterator s = split(l), e = split(r + 1); n   long long ret = 0; n   while (s != e) { n     r = (e--)->first; n     ret = (ret + (r - e->first) * fp(e->second, p, mod)) % mod; n   } n   return ret % mod; n } n inline long long rnd() { n   long long ret = seed; n   seed = (seed * 7 + 13) % 1000000007; n   return ret; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(NULL), cout.tie(NULL); n   cin >> n >> m >> seed >> vmax; n   long long x, y; n   for (int i = 1; i <= n; i++) ct[i] = (rnd() % vmax) + 1; n   for (int i = 1; i <= m; i++) { n     long long op = (rnd() % 4) + 1; n     long long l = (rnd() % n) + 1; n     long long r = (rnd() % n) + 1; n     if (l > r) sw(l, r); n     if (op == 3) n       x = (rnd() % (r - l + 1)) + 1; n     else n       x = (rnd() % vmax) + 1; n     if (op == 4) y = (rnd() % vmax) + 1; n     switch (op) { n       case 1: n         add(l, r, x); n         break; n       case 2: n         assign(l, r, x); n         break; n       case 3: n         cout << kSmallest(l, r, x) <<   n ; n         break; n       case 4: n         cout << powSum(l, r, x, y) <<   n ; n         break; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 105; n const int mod = 1e9 + 7; n int sub[N][N][N]; n int pref[N][N]; n int suff[N][N]; n int ans[N]; n int pw[N]; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   int n, X; n   cin >> n >> X; n   string s; n   cin >> s; n   s =  &  + s; n   for (int i = 1; i <= n; i++) { n     if (s[i] ==  0 ) n       sub[0][i][i] = 1; n     else n       sub[1][i][i] = 1; n   } n   if (s[1] ==  0 ) n     pref[0][1] = 1; n   else n     pref[1][1] = 1; n   if (s[n] ==  0 ) n     suff[0][n] = 1; n   else n     suff[1][n] = 1; n   pw[0] = pw[1] = 2; n   if (s ==  &0 ) ans[0] = 1; n   if (s ==  &1 ) ans[1] = 1; n   for (int i = 2; i <= X; i++) { n     pw[i] = 1ll * pw[i - 1] * pw[i - 2] % mod; n     for (int l = 1; l <= n; l++) { n       for (int r = l; r <= n; r++) { n         sub[i][l][r] = (sub[i - 1][l][r] + sub[i - 2][l][r]) % mod; n         for (int m = l; m < r; m++) { n           sub[i][l][r] += 1ll * sub[i - 1][l][m] * sub[i - 2][m + 1][r] % mod; n           sub[i][l][r] %= mod; n         } n       } n     } n     for (int l = 1; l <= n; l++) { n       pref[i][l] = pref[i - 1][l]; n       pref[i][l] += 1ll * pref[i - 2][l] * pw[i - 1] % mod; n       pref[i][l] %= mod; n       for (int x = 1; x < l; x++) { n         pref[i][l] += 1ll * pref[i - 1][x] * sub[i - 2][x + 1][l] % mod; n         pref[i][l] %= mod; n       } n     } n     for (int r = 1; r <= n; r++) { n       suff[i][r] = suff[i - 2][r]; n       suff[i][r] += 1ll * suff[i - 1][r] * pw[i - 2] % mod; n       suff[i][r] %= mod; n       for (int x = r; x < n; x++) { n         suff[i][r] += 1ll * suff[i - 2][x + 1] * sub[i - 1][r][x] % mod; n         suff[i][r] %= mod; n       } n     } n     for (int m = 1; m < n; m++) { n       ans[i] += 1ll * pref[i - 1][m] * suff[i - 2][m + 1] % mod; n       ans[i] %= mod; n     } n     ans[i] += 1ll * ans[i - 1] * pw[i - 2] % mod; n     ans[i] %= mod; n     ans[i] += 1ll * ans[i - 2] * pw[i - 1] % mod; n     ans[i] %= mod; n   } n   cout << ans[X] << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int memo[2700][2700]; n string S; n int N; n int doit(int lo, int hi) { n   if (lo == hi) { n     return 1; n   } n   if (lo > hi) { n     return 0; n   } n   int &ret = memo[lo][hi]; n   if (ret != -1) return ret; n   ret = 0; n   if (S[lo] == S[hi]) { n     ret = max(ret, doit(lo + 1, hi - 1) + 2); n   } n   ret = max(ret, doit(lo + 1, hi)); n   ret = max(ret, doit(lo, hi - 1)); n   return ret; n } n string prefixStr, suffixStr, middleStr; n void doitG(int lo, int hi) { n   if (lo == hi) { n     middleStr += S[lo]; n     return; n   } n   if (lo > hi) return; n   if (S[lo] == S[hi]) { n     prefixStr += S[lo]; n     suffixStr += S[lo]; n     doitG(lo + 1, hi - 1); n   } else { n     if (doit(lo + 1, hi) > doit(lo, hi - 1)) { n       doitG(lo + 1, hi); n     } else { n       doitG(lo, hi - 1); n     } n   } n } n int main() { n   cin >> S; n   N = S.size(); n   if (N > 2600) { n     for (char c =  a ; c <=  z ; c++) { n       int cnt = 0; n       for (int i = 0; i < S.size(); i++) { n         if (S[i] == c) { n           cnt++; n         } n       } n       if (cnt >= 100) { n         for (int i = 0; i < 100; i++) cout << c; n         cout << endl; n         return 0; n       } n     } n     assert(0); n   } else { n     memset(memo, -1, sizeof(memo)); n     int ret = doit(0, N - 1); n     prefixStr = suffixStr = middleStr =   ; n     doitG(0, N - 1); n     reverse(suffixStr.begin(), suffixStr.end()); n     string res =   ; n     for (int i = 0; i < prefixStr.size(); i++) res += prefixStr[i]; n     for (int i = 0; i < middleStr.size(); i++) res += middleStr[i]; n     for (int i = 0; i < suffixStr.size(); i++) res += suffixStr[i]; n     if (res.size() < 100) { n       int n = res.size(); n       cout << res << endl; n     } else { n       if (res.size() == 100) { n         cout << res << endl; n       } else { n         int n = res.size(); n         for (int i = 0; i < 50; i++) cout << res[i]; n         for (int j = n - 50; j < n; j++) cout << res[j]; n         cout << endl; n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   vector<pair<int, int> > sort_positions; n   int a[n]; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n     sort_positions.push_back(make_pair(a[i], i)); n   } n   sort(a, a + n); n   sort(sort_positions.begin(), sort_positions.end()); n   set<vector<int> > subsets; n   for (int i = 0; i < n; i++) { n     bool isempty = true; n     vector<int> next_subset; n     for (int j = 0; j < i; j++) n       if (a[j] > i) { n         next_subset.push_back(1); n         isempty = false; n       } else n         next_subset.push_back(0); n     int next_num = min(a[i], i + 1); n     set<vector<int> > next_subsets; n     if (isempty) { n       next_subset.push_back(1); n       next_subsets.insert(next_subset); n       next_num--; n       for (set<vector<int> >::iterator it = subsets.begin(); n            it != subsets.end(); it++) { n         vector<int> subset(*it); n         if (next_num > 0) n           subset.push_back(1); n         else n           subset.push_back(0); n         next_subsets.insert(subset); n         next_num--; n       } n     } else { n       for (set<vector<int> >::iterator it = subsets.begin(); n            it != subsets.end(); it++) { n         vector<int> subset(*it); n         if (next_num > 0) n           subset.push_back(1); n         else n           subset.push_back(0); n         next_subsets.insert(subset); n         next_num--; n       } n       next_subset.push_back(0); n       next_subsets.insert(next_subset); n       if (next_num == 1) { n         vector<int> subset(i, 0); n         subset.push_back(1); n         next_subsets.insert(subset); n       } n     } n     subsets = next_subsets; n   } n   vector<int> ox[n]; n   for (int i = 0; i < sort_positions.size(); i++) { n     int idx = sort_positions[i].second; n     ox[idx].resize(0); n     for (set<vector<int> >::iterator it = subsets.begin(); it != subsets.end(); n          it++) n       ox[idx].push_back((*it)[i]); n   } n   cout << subsets.size() << endl; n   for (int i = 0; i < subsets.size(); i++) { n     for (int j = 0; j < n; j++) cout << ox[j][i]; n     cout << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int dx[] = {0, 1, 0, -1}; n const int dy[] = {1, 0, -1, 0}; n int n, m; n char a[1010][1010]; n int d1[1010][1010], d2[1010][1010], d3[1010][1010]; n vector<pair<int, int> > s1, s2, s3; n int ans = 0x3f3f3f3f; n int ax, ay; n void bfs(int d[1010][1010], char id) { n   queue<pair<int, int> > qq; n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= m; j++) n       if (a[i][j] == id) d[i][j] = 0, qq.push(make_pair(i, j)); n   while (!qq.empty()) { n     pair<int, int> from = qq.front(); n     int x = from.first, y = from.second; n     qq.pop(); n     for (int i = 0; i < 4; i++) { n       int tx = x + dx[i], ty = y + dy[i]; n       int dis = d[x][y] + (a[tx][ty] ==  . ); n       if ((d[tx][ty] != 0x3f3f3f3f && d[tx][ty] <= dis) || a[tx][ty] ==  # ) n         continue; n       d[tx][ty] = dis; n       qq.push(make_pair(tx, ty)); n     } n   } n } n int main() { n   cin >> n >> m; n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= m; j++) cin >> a[i][j]; n   for (int i = 0; i <= n + 1; i++) a[i][0] = a[i][m + 1] =  # ; n   for (int j = 1; j <= m; j++) a[0][j] = a[n + 1][j] =  # ; n   memset(d1, 0x3f, sizeof(d1)); n   memset(d2, 0x3f, sizeof(d2)); n   memset(d3, 0x3f, sizeof(d3)); n   bfs(d1,  1 ); n   bfs(d2,  2 ); n   bfs(d3,  3 ); n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= m; j++) n       if (d1[i][j] != 0x3f3f3f3f && d2[i][j] != 0x3f3f3f3f && n           d3[i][j] != 0x3f3f3f3f) { n         int calc; n         if (a[i][j] ==  . ) { n           calc = d1[i][j] + d2[i][j] + d3[i][j] - 2; n           if (ans > calc) ans = calc, ax = i, ay = j; n         } else if (isdigit(a[i][j])) { n           calc = d1[i][j] + d2[i][j] + d3[i][j]; n           if (ans > calc) ans = calc, ax = i, ay = j; n         } n       } n   cout << (ans == 0x3f3f3f3f ? -1 : ans) << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int mod = 998244353; n const int N = 1000010; n int n, cnt[N], ans, val[N]; n long long a[N]; n template <typename T> n void gi(T &x) { n   x = 0; n   register char c = getchar(), pre = 0; n   for (; c <  0  || c >  9 ; pre = c, c = getchar()) n     ; n   for (; c >=  0  && c <=  9 ; c = getchar()) x = x * 10ll + (c ^ 48); n   if (pre ==  - ) x = -x; n } n int main() { n   gi(n); n   for (int i = (1); i <= (n); i++) { n     gi(a[i]); n     long long t = a[i]; n     int w = 0; n     for (; t % 2 == 0; t /= 2, ++w) n       ; n     ++cnt[w], val[i] = w; n   } n   for (int i = (1); i <= (70); i++) n     if (cnt[i] > cnt[ans]) ans = i; n   printf( %d n , n - cnt[ans]); n   for (int i = (1); i <= (n); i++) n     if (val[i] != ans) printf( %lld  , a[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 3e5 + 7, mod = 1e9 + 7, inf = 1e9 + 7; n const long long linf = (long long)1e18 + 7; n const long double eps = 1e-15, pi = 3.141592; n const int dx[] = {-1, 0, 1, 0, 1, -1, -1, 1}, n           dy[] = {0, 1, 0, -1, 1, -1, 1, -1}; n int n, sz; n long long ans; n long long a[N], suff[N]; n int t[N * 20][2]; n inline void add(long long x) { n   int v = 0; n   for (int i = 40; i >= 0; --i) { n     int type = ((x & (1LL << i)) > 0); n     if (!t[v][type]) t[v][type] = ++sz; n     v = t[v][type]; n   } n } n inline long long get(long long x) { n   int v = 0; n   long long res = 0; n   for (int i = 40; i >= 0; --i) { n     int type = 1 - ((x & (1LL << i)) > 0); n     if (t[v][type]) n       res += 1LL << i, v = t[v][type]; n     else n       v = t[v][1 - type]; n   } n   return res; n } n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; ++i) scanf( %I64d , &a[i]); n   for (int i = n; i >= 1; --i) suff[i] = suff[i + 1] ^ a[i]; n   long long pref = 0; n   add(0); n   for (int i = 1; i <= n + 1; ++i) { n     ans = max(ans, get(suff[i])); n     add(pref ^= a[i]); n   } n   cout << ans; n   exit(0); n } n


#include <bits/stdc++.h> n using namespace std; n long long n, m, sum, t; n int main() { n   scanf( %I64d%I64d , &n, &m); n   for (int i = 0; i < n; i++) { n     scanf( %I64d , &t); n     sum += t; n     if (t && sum >= m) { n       printf( %I64d  , sum / m); n       sum %= m; n     } else n       printf( 0  ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e5 + 5; n int s[maxn]; n priority_queue<int, vector<int>, greater<int> > que; n int main() { n   int n; n   scanf( %d , &n); n   for (int i = 0; i < n; i++) { n     scanf( %d , &s[i]); n     que.push(s[i]); n   } n   sort(s, s + n); n   int ans = 0; n   for (int i = 0; i < n; i++) { n     while (!que.empty() && que.top() <= s[i]) { n       que.pop(); n     } n     if (que.empty()) break; n     if (que.top() > s[i]) { n       ans++; n       que.pop(); n     } n   } n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n map<int, bool> childL, childR; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   ; n   int n, a; n   cin >> n; n   cin >> a; n   multiset<int> mulset; n   mulset.insert(a); n   for (int i = 1; i < n; i++) { n     cin >> a; n     auto ite = mulset.lower_bound(a); n     if (childL[*ite] || ite == mulset.end()) { n       ite--; n       childR[*ite] = 1; n     } else n       childL[*ite] = 1; n     if (i > 1) cout <<    ; n     cout << *ite; n     mulset.insert(a); n   } n   cout << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int p = 1000000007; n int pow3[10]; n int main() { n   pow3[0] = 1; n   pow3[1] = 3; n   pow3[2] = pow3[1] * 3; n   pow3[3] = pow3[2] * 3; n   pow3[4] = pow3[3] * 3; n   pow3[5] = pow3[4] * 3; n   pow3[6] = pow3[5] * 3; n   map<char, int> myMap; n   char c; n   long long n, k = 0, cnt = 0, res = 1; n   for (int i = 48; i <= 57; i++) { n     c = i; n     myMap.insert(make_pair(c, k)); n     k++; n   } n   for (int i = 65; i <= 90; i++) { n     c = i; n     myMap.insert(make_pair(c, k)); n     k++; n   } n   for (int i = 97; i <= 122; i++) { n     c = i; n     myMap.insert(make_pair(c, k)); n     k++; n   } n   myMap.insert(make_pair( - , 62)); n   k++; n   myMap.insert(make_pair( _ , 63)); n   k++; n   while (cin >> c) { n     n = myMap[c]; n     cnt = 0; n     for (int i = 0; i < 6; i++) { n       if (n % 2 == 0) cnt++; n       n /= 2; n     } n     res = ((res % p) * pow3[cnt]) % p; n   } n   cout << res; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxm = 1e6 + 5; n int a[maxm]; n int n; n struct BIT { n   int c[maxm]; n   int lowbit(int i) { return i & -i; } n   void add(int i, int t) { n     while (i < maxm) { n       c[i] += t, i += lowbit(i); n     } n   } n   int ask(int i) { n     int ans = 0; n     while (i) { n       ans += c[i], i -= lowbit(i); n     } n     return ans; n   } n } T; n signed main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) { n     scanf( %d , &a[i]); n   } n   long long ans = 0; n   for (int i = 1; i <= n; i++) { n     ans += i - T.ask(a[i]); n     T.add(a[i], 1); n   } n   if (ans % 2 == 0) { n     puts( Petr ); n   } else { n     puts( Um_nik ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   string str; n   cin >> str; n   int L = 0; n   for (int l = n / 2; l >= 1; l--) { n     if (str.substr(0, l) == str.substr(l, l)) { n       L = l; n       break; n     } n   } n   if (L == 0) n     cout << n; n   else n     cout << n - L + 1; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   int t; n   cin >> t; n   while (t--) { n     int n; n     cin >> n; n     string s; n     cin >> s; n     bool flag = false; n     for (int i = 1; i <= n; i++) { n       if (s[i - 1] ==  0 ) { n         if (i <= n / 2) { n           cout << i <<     << n <<     << i + 1 <<     << n << endl; n           flag = true; n           break; n         } else { n           cout << 1 <<     << i <<     << 1 <<     << i - 1 << endl; n           flag = true; n           break; n         } n       } n     } n     int sz = n / 2; n     if (!flag) n       cout << 1 <<     << 1 + sz - 1 <<     << n - sz + 1 <<     << n << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 5; n const int S = 320; n int a[N]; n int dp[S + 1][N]; n int main() { n   int n; n   cin >> n; n   for (int i = 1; i <= n; i++) cin >> a[i]; n   int q, p, k; n   cin >> q; n   for (int j = 1; j <= S; j++) { n     for (int i = n; i >= 1; i--) { n       if (i + a[i] + j > n) n         dp[j][i] = 1; n       else n         dp[j][i] = dp[j][i + a[i] + j] + 1; n     } n   } n   for (int i = 0; i < q; i++) { n     cin >> p >> k; n     int cnt = 0; n     if (k <= S) n       cout << dp[k][p] << endl; n     else { n       while (p <= n) { n         cnt++; n         p += a[p] + k; n       } n       cout << cnt << endl; n     } n   } n   return 0; n } n


#define DEBUG 0 n  n #include <bits/stdc++.h> n using namespace std; n  n #if DEBUG n // basic debugging macros n int __i__,__j__; n #define printLine(l) for(__i__=0;__i__<l;__i__++){cout<< - ;}cout<<endl n #define printLine2(l,c) for(__i__=0;__i__<l;__i__++){cout<<c;}cout<<endl n #define printVar(n) cout<<#n<< :  <<n<<endl n #define printArr(a,l) cout<<#a<< :  ;for(__i__=0;__i__<l;__i__++){cout<<a[__i__]<<   ;}cout<<endl n #define print2dArr(a,r,c) cout<<#a<< : n ;for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<   ;}cout<<endl;} n #define print2dArr2(a,r,c,l) cout<<#a<< : n ;for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<setw(l)<<setfill(   )<<a[__i__][__j__]<<   ;}cout<<endl;} n  n // advanced debugging class n // debug 1,2, A , test ; n class _Debug { n     public: n         template<typename T> n         _Debug& operator,(T val) { n             cout << val << endl; n             return *this; n         } n }; n #define debug _Debug(), n #else n #define printLine(l) n #define printLine2(l,c) n #define printVar(n) n #define printArr(a,l) n #define print2dArr(a,r,c) n #define print2dArr2(a,r,c,l) n #define debug n #endif n  n // define n #define MAX_VAL 999999999 n #define MAX_VAL_2 999999999999999999LL n #define EPS 1e-6 n #define mp make_pair n #define pb push_back n  n // typedef n typedef unsigned int UI; n typedef long long int LLI; n typedef unsigned long long int ULLI; n typedef unsigned short int US; n typedef pair<int,int> pii; n typedef pair<LLI,LLI> plli; n typedef vector<int> vi; n typedef vector<LLI> vlli; n typedef vector<pii> vpii; n typedef vector<plli> vplli; n  n // ---------- END OF TEMPLATE ---------- n  n int p[200001],k[200001],b[200001],w[200001]; n int seed = 0,base = 0; n int rnd() { n     int ret = seed; n     seed = ((LLI) seed*base + 233) % 1000000007; n     return ret; n } n int a[5000000],o[5000000],t[5000000]; n int main() { n     int i,j; n     int n,m; n     scanf( %d %d ,&n,&m); n     for (i = 1; i <= m; i++) { n         scanf( %d %d %d %d ,&p[i],&k[i],&b[i],&w[i]); n         seed = b[i],base = w[i]; n         for (j = p[i-1]; j < p[i]; j++) { n             t[j] = (rnd() % 2) + 1; n             o[j] = a[j] = (rnd() % k[i]) + 1; n         } n     } n  n     LLI s1 = 0,s2 = 0; n     for (i = 0; i < n; i++) { n         if (t[i] == 1) s1 += a[i]; n         else s2 += a[i]; n     } n     if (s1 <= s2) { n         for (i = 0; i < n; i++) t[i] ^= 3; n     } n     if (t[0] == 1) a[0]--; n     LLI s = 0; n     for (i = 0; i < n; i++) { n         if (t[i] == 2) s += a[i],a[i] = 0; n         else { n             LLI x = min((LLI) a[i],s); n             a[i] -= x,s -= x; n         } n     } n     for (i = 0; i < n; i++) { n         if (t[i] == 2) s += a[i],a[i] = 0; n         else { n             LLI x = min((LLI) a[i],s); n             a[i] -= x,s -= x; n         } n     } n     LLI ans = 1; n     for (i = 0; i < n; i++) { n         ans *= (((o[i]-a[i])^((LLI) (i+1)*(i+1)))+1) % 1000000007; n         ans %= 1000000007; n     } n     printf( %I64d n ,ans); n  n     return 0; n } 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 xx = 2e5 + 10; n vector<long long> pos[xx]; n signed main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   long long n, m, k; n   cin >> n >> m >> k; n   vector<long long> v(n); n   vector<pair<long long, long long>> pi; n   for (long long i = 0; i < n; i++) { n     cin >> v[i]; n     pi.emplace_back(v[i], i); n   } n   sort(pi.rbegin(), pi.rend()); n   vector<pair<long long, long long>> vp; n   long long sum = 0; n   for (long long i = 0; i < m * k; i++) { n     sum += pi[i].first; n     vp.emplace_back(pi[i].second, pi[i].first); n   } n   sort(vp.begin(), vp.end()); n   cout << sum <<   n ; n   for (long long i = m - 1; i < vp.size() - m; i += m) { n     long long x = vp[i].first; n     cout << x + 1 <<    ; n   } n   cout <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n int n, a[100010], mx1 = -100010, mx2 = -100010 - 10, ans = 1, cnt[100010]; n int main() { n   cin >> n; n   for (int i = 1; i <= n; i++) cin >> a[i]; n   for (int i = 1; i <= n; i++) { n     if (a[i] > mx1) { n       mx2 = mx1; n       mx1 = a[i]; n       cnt[a[i]]--; n     } else if (a[i] > mx2) { n       mx2 = a[i]; n       cnt[mx1]++; n     } n   } n   for (int i = 1; i <= n; i++) n     if (cnt[i] > cnt[ans]) ans = i; n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool visited[10000]; n int main() { n   ios::sync_with_stdio(false); n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr), cout.tie(nullptr); n   string input; n   int counter; n   while (cin >> input) { n     counter = 0; n     for (int i = 0; i < input.size() - 1; i++) n       if (input[i] ==  V  && input[i + 1] ==  K ) n         counter++, visited[i] = visited[i + 1] = 1, i++; n     for (int i = 0; i < input.size() - 1; i++) n       if (!visited[i] && !visited[i + 1]) n         if ((input[i] ==  V  && input[i + 1] ==  V ) || n             ((input[i] ==  K  && input[i + 1] ==  K ))) { n           counter++; n           break; n         } n   } n   cout << counter << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double PI = acos(-1.0); n template <class T> n inline T SQR(T a) { n   return a * a; n } n int C[100001][3]; n bool can(int *A, int n, int k) { n   int pos = k; n   for (int i = (0), ei = (k); i < ei; i++) C[i][0] = A[i]; n   int cnt = 0; n   while (pos < n && cnt < k) { n     if (A[pos] < C[cnt][0]) C[cnt++][1] = A[pos]; n     pos++; n   } n   if (cnt != k) return false; n   cnt = 0; n   while (pos < n && cnt < k) { n     if (A[pos] < C[cnt][1]) C[cnt++][2] = A[pos]; n     pos++; n   } n   return cnt == k; n } n int main() { n   int n; n   int A[100001]; n   cin >> n; n   for (int i = (0), ei = (n); i < ei; i++) scanf( %d , A + i); n   sort(A, A + n, greater<int>()); n   int l = 0, r = n / 3; n   int ans = 0; n   while (l <= r) { n     int c = (l + r) >> 1; n     if (can(A, n, c)) { n       l = c + 1; n       ans = c; n     } else n       r = c - 1; n   } n   can(A, n, ans); n   printf( %d n , ans); n   for (int i = (0), ei = (ans); i < ei; i++) n     printf( %d %d %d n , C[i][0], C[i][1], C[i][2]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long MAX_N = 4e3 + 10; n const long long MAX_M = 65 + 10; n const long long mod = 1e9 + 7; n const int INF = 1e9; n inline long long bpow(long long t, long long n) { n   long long ans = 1; n   while (n > 0) { n     if (n & 1) ans = (ans * t) % mod; n     t = (t * t) % mod, n >>= 1; n   } n   return ans; n } n int dp[MAX_N][MAX_M][MAX_M][2]; n int a[MAX_N]; n int cdp(int l, int r, int k, int x) { n   if ((r - l + 1) < k) return 0; n   if (dp[l][r - l][k][x] != -1) return dp[l][r - l][k][x]; n   int& ans = dp[l][r - l][k][x]; n   if (x == 0) n     ans = max(cdp(l + k, r, k, 1) + a[l + k - 1] - a[l - 1], n               (r - l >= k) ? (a[l + k] - a[l - 1] + cdp(l + k + 1, r, k + 1, 1)) n                            : (-INF)); n   else n     ans = min(a[r - k] - a[r] + cdp(l, r - k, k, 0), n               (r - l >= k) ? (a[r - k - 1] - a[r] + cdp(l, r - k - 1, k + 1, 0)) n                            : INF); n   return ans; n } n int main() { n   memset(dp, -1, sizeof dp); n   ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); n   cout << fixed << setprecision(0); n   int n; n   cin >> n; n   for (int i = 1; i <= n; i++) cin >> a[i]; n   for (int i = 1; i <= n; i++) a[i] += a[i - 1]; n   cout << cdp(1, n, 1, 0); n } n


#include <bits/stdc++.h> n using namespace std; n template <typename Arg1> n void __f(const char* name, Arg1&& arg1) { n   cerr << name <<   :   << arg1 << std::endl; n } n template <typename Arg1, typename... Args> n void __f(const char* names, Arg1&& arg1, Args&&... args) { n   const char* comma = strchr(names + 1,  , ); n   cerr.write(names, comma - names) <<   :   << arg1 <<   |  ; n   __f(comma + 1, args...); n } n const int mod = 1e9 + 7; n template <class X> n void print(X a) { n   cout << a << endl; n   exit(0); n } n long long n, k, m; n vector<pair<long long, long long> > reduce( n     vector<pair<long long, long long> >& a) { n   vector<pair<long long, long long> > b; n   pair<long long, long long> last = {-1, -1}; n   for (auto& x : a) { n     if (last.first == x.first) n       b.back().second += x.second; n     else n       b.push_back(x); n     if (b.back().second % k == 0) b.pop_back(); n     if (!b.empty()) n       last = b.back(); n     else n       last = {-1, -1}; n   } n   for (auto& x : b) x.second %= k; n   return b; n } n int main() { n   time_t t1, t2; n   t1 = clock(); n   ios_base::sync_with_stdio(0); n   cin >> n >> k >> m; n   long long faltu[n + 1]; n   for (int i = 1; i <= n; i++) cin >> faltu[i]; n   vector<pair<long long, long long> > a; n   int i = 1; n   while (i <= n) { n     int j = i; n     for (j = i; j <= n; j++) { n       if (faltu[j] != faltu[i]) break; n     } n     a.push_back({faltu[i], j - i}); n     i = j; n   } n   long long sum = 0; n   a = reduce(a); n   for (auto& x : a) sum += x.second; n   long long total = sum * m; n   __f( total , total); n   int finish_idx = -1; n   for (int i = 0, j = a.size() - 1; i < (int)a.size(); i++, j--) { n     if (a[i].first != a[j].first or a[i].second + a[j].second != k) { n       finish_idx = i; n       break; n     } n   } n   if (finish_idx == -1) { n     if (m & 1) n       cout << sum << endl; n     else n       cout << 0 << endl; n   } else { n     long long to_sub = 0; n     long long start_sub = 0, end_sub = 0; n     long long left_over = 0; n     long long c; n     for (int i = 0, j = a.size() - 1; i <= finish_idx; i++, j--) { n       if (i == finish_idx and a[i].first != a[j].first) n         break; n       else if (i == finish_idx and a[i].first == a[j].first and n                a[i].second + a[j].second < k) n         break; n       else if (i == finish_idx) n         left_over = (a[i].second + a[j].second) % k; n       to_sub += (a[i].second + a[j].second); n       start_sub += a[i].second; n       end_sub += a[j].second; n     } n     to_sub *= m; n     long long ans = total - to_sub; n     ans += start_sub + end_sub; n     ans += left_over * (m - 1); n     if ((int)a.size() & 1 and finish_idx == (int)a.size() / 2) { n       vector<pair<long long, long long> > new_a; n       for (int i = 0; i < (int)a.size(); i++) { n         if (i == finish_idx) n           new_a.push_back({a[i].first, a[i].second * m}); n         else n           new_a.push_back(a[i]); n       } n       new_a = reduce(new_a); n       ans = 0; n       for (auto& x : new_a) { n         ans += x.second; n       } n     } n     cout << ans << endl; n   } n   t2 = clock(); n   cerr <<  time taken:   << t2 - t1 << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, sum, dp[1 << 16], arc[16][16], d[16]; n void Floyd() { n   int k, i, j; n   for (k = 0; k < n; k++) n     for (i = 0; i < n; i++) n       for (j = 0; j < n; j++) arc[i][j] = min(arc[i][j], arc[i][k] + arc[k][j]); n } n int getans() { n   int i, j, x, t, totol; n   Floyd(); n   for (i = 1; i < n; i++) n     if (d[i] && arc[0][i] > 1000000007) return -1; n   memset(dp, 0x7f, sizeof(dp)); n   dp[0] = 0; n   totol = (1 << n) - 1; n   for (t = 0; t <= totol; t++) { n     for (i = 0; i < n; i++) n       if (d[i] % 2 && (t & (1 << i))) break; n     if (i == n) dp[t] = 0; n     for (i = 0; i < n; i++) n       if (d[i] % 2 && !(t & (1 << i))) n         for (j = i + 1; j < n; j++) n           if (d[j] % 2 && !(t & (1 << j)) && arc[i][j] < 1000000007) n             dp[t | (1 << i) | (1 << j)] = n                 min(dp[t | (1 << i) | (1 << j)], dp[t] + arc[i][j]); n   } n   if (dp[totol] > 1000000007) return -1; n   return sum + dp[totol]; n } n int main() { n   int m; n   while (~scanf( %d%d , &n, &m)) { n     sum = 0; n     memset(arc, 0x3f, sizeof(arc)); n     memset(d, 0, sizeof(d)); n     for (int i = 1; i <= m; i++) { n       int x, y, l; n       scanf( %d%d%d , &x, &y, &l); n       sum += l; n       x--, y--; n       arc[y][x] = arc[x][y] = min(arc[x][y], l); n       d[x]++, d[y]++; n     } n     printf( %d n , getans()); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct Point { n   double x; n   double y; n   Point(double _x = 0, double _y = 0) : x(_x), y(_y) {} n   double length() const { return sqrt(x * x + y * y); } n   double distance(const Point& other) const { n     return Point(x - other.x, y - other.y).length(); n   } n }; n Point operator+(const Point& first, const Point& second) { n   return Point(first.x + second.x, first.y + second.y); n } n Point operator-(const Point& first, const Point& second) { n   return Point(first.x - second.x, first.y - second.y); n } n double vector_product(const Point& first, const Point& second) { n   return first.x * second.y - first.y * second.x; n } n double scalar_product(const Point& first, const Point& second) { n   return first.x * second.x + first.y * second.y; n } n struct Segment { n   Point A; n   Point B; n   Segment() {} n   Segment(const Point& _A, const Point& _B) : A(_A), B(_B) {} n   double length() const; n   double distance(const Point& C) const; n   double distance(const Segment& S) const; n }; n double Segment::length() const { n   double dx = B.x - A.x; n   double dy = B.y - A.y; n   return sqrt(dx * dx + dy * dy); n } n double Segment::distance(const Point& C) const { n   if (scalar_product(C - A, B - A) < 0 || scalar_product(C - B, A - B) < 0) { n     return min(Segment(A, C).length(), Segment(B, C).length()); n   } else { n     return fabs(vector_product(C - A, B - A)) / length(); n   } n } n double Segment::distance(const Segment& S) const { n   double r = distance(S.A); n   r = min(r, distance(S.B)); n   r = min(r, S.distance(A)); n   r = min(r, S.distance(B)); n   return r; n } n struct Arc { n   int head; n   double weight; n   Arc() : head(-1), weight(0) {} n   Arc(int to, double label) : head(to), weight(label) {} n }; n enum VertexColor { WHITE = 0, GRAY, BLACK }; n const double INF = 1000000000; n void dijkstra_on_array(const std::vector<std::vector<Arc> >& graph, int source, n                        vector<double>& distance) { n   vector<int> color(graph.size(), WHITE); n   color[source] = GRAY; n   distance.assign(graph.size(), INF); n   distance[source] = 0; n   for (int step = 0; step < graph.size(); ++step) { n     int min_gray_vertex = 0; n     double min_distance_to_gray = INF; n     for (int vertex = 0; vertex < graph.size(); ++vertex) { n       if (color[vertex] == GRAY && distance[vertex] < min_distance_to_gray) { n         min_gray_vertex = vertex; n         min_distance_to_gray = distance[vertex]; n       } n     } n     if (min_distance_to_gray == INF) { n       break; n     } n     color[min_gray_vertex] = BLACK; n     for (int arc_index = 0; arc_index < graph[min_gray_vertex].size(); n          ++arc_index) { n       const Arc& arc = graph[min_gray_vertex][arc_index]; n       if (color[arc.head] != BLACK && n           distance[arc.head] > min_distance_to_gray + arc.weight) { n         color[arc.head] = GRAY; n         distance[arc.head] = min_distance_to_gray + arc.weight; n       } n     } n   } n } n int main() { n   double a, b; n   cin >> a >> b; n   Point A, B; n   cin >> A.x >> A.y >> B.x >> B.y; n   int n; n   cin >> n; n   vector<Segment> segments(n); n   for (int i = 0; i < n; ++i) { n     cin >> segments[i].A.x >> segments[i].A.y >> segments[i].B.x >> n         segments[i].B.y; n   } n   std::vector<std::vector<Arc> > g(n + 2); n   for (int i = 0; i < n; ++i) { n     for (int j = i + 1; j < n; ++j) { n       if (segments[i].distance(segments[j]) <= a + 1e-9) { n         g[i].push_back(Arc(j, a + b)); n         g[j].push_back(Arc(i, a + b)); n       } n     } n   } n   for (int i = 0; i < n; ++i) { n     double da = segments[i].distance(A); n     double db = segments[i].distance(B); n     if (da <= a + 1e-9) { n       g[n].push_back(Arc(i, a + b)); n     } n     if (db <= a + 1e-9) { n       g[i].push_back(Arc(n + 1, db)); n     } n   } n   if (A.distance(B) <= a + 1e-9) { n     cout.precision(8); n     cout << fixed << A.distance(B) << endl; n   } else { n     vector<double> d; n     dijkstra_on_array(g, n, d); n     if (d[n + 1] == INF) { n       cout << -1 << endl; n     } else { n       cout.precision(8); n       cout << fixed << d[n + 1] << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n  n typedef long long ll; n const int maxn=1e6+7; n const int inf=2e9; n const ll inff=1e18; n const ll mod=1e9+7; n #define pii pair<int,int> n #define mkp make_pair n #define F first n #define S second n #define pb push_back n #define sz(v) ((int)(v).size()) n #define all(v) (v).begin(),(v).end() n //#define int ll n  n int32_t main(){ n  ios::sync_with_stdio(0); cin.tie(0); n     int t; cin>>t; n     while (t--) { n         int n; cin>>n; n         vector<int> v(n); n         for (int &i:v) cin>>i; n         sort(all(v)); n  n         ll ans=0; n         for (int i=1;i<n;i++) ans+=(v[i]-v[i-1]); n         for (int i=1;i<n;i++) { n             ans-=i*1LL*(n-i)*(v[i]-v[i-1]); n         } n         cout<<ans<<  n ; n     } n } n


#include <bits/stdc++.h> n using namespace std; n long long n, k; n bool f(long long x, long long y, long long z) { n   if ((k - x - y - z) < 0 || (k - x - y - z) % 3 != 0) return false; n   long long m = max(x, max(y, z)), p = n - (k + 3 * m - (x + y + z)); n   if (p < 0 || p % 3 != 0) return false; n   return true; n } n int main() { n   int t; n   ios_base::sync_with_stdio(0); n   cin >> t; n   for (int i = 0; i < t; i++) { n     long long d1, d2; n     cin >> n >> k >> d1 >> d2; n     long long d = max(d1, d2); n     if (f(0ll, d1, d1 + d2) || f(d1 + d2, d2, 0ll) || f(d1, 0ll, d2) || n         f(d - d1, d, d - d2)) n       cout <<  yes  << endl; n     else n       cout <<  no  << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int N, K, S; n int q[153]; n vector<vector<int> > prev_, next_; n const int INF = 1e9; n int main() { n   scanf( %d%d%d , &N, &K, &S); n   S = min(S, N * (N - 1) / 2); n   for (int i = 1; i <= N; i++) scanf( %d , &q[i]); n   prev_ = vector<vector<int> >(K + 1, vector<int>(S + 1, INF)); n   prev_[0][0] = 0; n   for (int i = 1; i <= N; i++) { n     next_ = prev_; n     for (int j = 1; j <= min(K, i); j++) n       for (int k = 0; k <= S; k++) { n         if (k + abs(i - j) <= S) n           next_[j][k + abs(i - j)] = n               min(next_[j][k + abs(i - j)], prev_[j - 1][k] + q[i]); n       } n     swap(prev_, next_); n   } n   int ans = INF; n   for (int i = 0; i <= S; i++) ans = min(ans, prev_[K][i]); n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = 1e9; n const double eps = 1e-9; n const double INF = inf; n const double EPS = eps; n vector<long long> V; n int cmp(long long b, long double d, long long a) { n   if (d > 2e18) return 1; n   if (b > a) return 1; n   if (b == a) return 0; n   return -1; n } n int calc(long long n, long long p, long long k) { n   long double d = (2.0 * k + 1.0) * (k + p - 1ll); n   long long l = (2ll * k + 1) * (k + p - 1ll); n   return cmp(l, d, n); n } n void solve(long long n, long long p) { n   p = (1ll << p); n   if (p - 1 > n) return; n   long long l = 0, r = n + 1; n   while (r - l > 1) { n     long long m = (l + r) / 2; n     (calc(n, p, m) <= 0) ? (l = m) : (r = m); n   } n   if (calc(n, p, l) == 0) V.push_back(p * (2ll * l + 1ll)); n } n int main() { n   long long n; n   int i; n   scanf( %I64d , &n); n   for (i = 0; i < 60; i++) solve(n, i); n   sort(V.begin(), V.end()); n   if (!V.size()) { n     puts( -1 ); n     return 0; n   } n   for (i = 0; i < (int)V.size(); i++) printf( %I64d n , V[i]); n   ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double sn = 1e-6; n int n; n int arr[35]; n int res; n bool visited[310][310]; n bool notAgain[310][310][35][8]; n pair<int, int> dirs[8] = {{0, 1},  {1, 1},   {1, 0},  {1, -1}, n                           {0, -1}, {-1, -1}, {-1, 0}, {-1, 1}}; n void dfs(int dir, int sx, int sy, int sc) { n   if (notAgain[sx][sy][sc][dir]) return; n   notAgain[sx][sy][sc][dir] = true; n   for (int i = 0; i < arr[sc]; i++) { n     sx += dirs[dir].first; n     sy += dirs[dir].second; n     if (!visited[sx][sy]) { n       visited[sx][sy] = true; n       res++; n     } n   } n   if (sc < n - 1) { n     dfs(dir != 7 ? dir + 1 : 0, sx, sy, sc + 1); n     dfs(dir != 0 ? dir - 1 : 7, sx, sy, sc + 1); n   } n } n int main() { n   scanf( %d , &n); n   for (int i = 0; i < n; i++) scanf( %d , &arr[i]); n   dfs(0, 155, 155, 0); n   printf( %d n , res); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = INT_MAX; n const signed long long int LINF = LLONG_MAX; n const double EPS = 1e-9; n const int MOD = 1000000007; n const int MAXN = 100001; n const int ALPH = 26; n const int DALPH = 52; n int q; n map<string, string> match, rmatch; n set<string> current; n int main() { n   scanf( %d , &q); n   while (q--) { n     string s1, s2; n     cin >> s1 >> s2; n     if (current.find(s1) == current.end()) { n       current.insert(s2); n       match[s1] = s2; n       rmatch[s2] = s1; n     } else { n       current.erase(s1); n       current.insert(s2); n       match[rmatch[s1]] = s2; n       rmatch[s2] = rmatch[s1]; n       rmatch.erase(s1); n     } n   } n   printf( %d n , (int)(match).size()); n   for (pair<string, string> p : match) { n     cout << p.first <<     << p.second <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 2005, maxm = 200005; n vector<int> g[maxn]; n int tmp, vis[maxn], dis[maxn], mp[maxn][maxn]; n int n, m, ans, cnt, tot, res, ecnt, info[maxn], nx[maxm], v[maxm]; n int id, en, dfn[maxn], low[maxn], ori[maxn], sta[maxn], outd[maxn]; n void add(int u1, int v1) { n   nx[++ecnt] = info[u1]; n   info[u1] = ecnt; n   v[ecnt] = v1; n } n void targin(int x, int fa) { n   dfn[x] = low[x] = ++id; n   sta[++en] = x; n   for (int i = info[x]; i; i = nx[i]) { n     if (v[i] == fa) continue; n     if (!dfn[v[i]]) n       targin(v[i], x), low[x] = min(low[x], low[v[i]]); n     else n       low[x] = min(low[x], dfn[v[i]]); n   } n   if (low[x] == dfn[x]) { n     int v; n     cnt++; n     do v = sta[en--], ori[v] = cnt; n     while (v != x); n   } n } n void dfs(int x, int fa) { n   vis[x] = 1; n   dis[x] = dis[fa] + 1; n   if (dis[tmp] < dis[x]) tmp = x; n   for (int i = 0, lim = g[x].size(); i < lim; i++) n     if (g[x][i] != fa) dfs(g[x][i], x); n } n int main() { n   scanf( %d%d , &n, &m); n   for (int i = 1, u1, v1; i <= m; i++) n     scanf( %d%d , &u1, &v1), add(u1, v1), add(v1, u1); n   for (int i = 1; i <= n; i++) n     if (!dfn[i]) targin(i, 0); n   if (cnt == 1) { n     printf( %d n , n - 1); n     return 0; n   } n   for (int x = 1; x <= n; x++) n     for (int i = info[x]; i; i = nx[i]) n       if (!mp[ori[x]][ori[v[i]]] && ori[x] != ori[v[i]]) { n         mp[ori[x]][ori[v[i]]] = 1; n         g[ori[x]].push_back(ori[v[i]]); n         outd[ori[x]]++; n       } n   for (int i = 1; i <= cnt; i++) n     if (outd[i] == 1) res++; n   for (int i = 1, p1, p2; i <= cnt; i++) n     if (!vis[i]) { n       tot++; n       tmp = 0; n       dfs(i, 0); n       p1 = tmp; n       tmp = 0; n       dfs(p1, 0); n       p2 = tmp; n       if (dis[p2] < 2) n         res++; n       else n         res += dis[p2] - 2; n     } n   printf( %d n , n - res + tot - 1); n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e6 + 10; n const int M = 5e3 + 10; n const int mod = 1e9 + 7; n int cnt[M][M]; n void init() { n   for (int i = 1; i < M; i++) { n     int p = i; n     for (int j = 1; j <= i; j++) cnt[i][j] = cnt[i - 1][j]; n     for (int j = 2; j <= p; j++) { n       if (p % j == 0) { n         while (p % j == 0) p /= j, cnt[i][j]++; n       } n     } n   } n } n int n, f[M], v[M], siz[M]; n int main() { n   init(); n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) { n     int x; n     scanf( %d , &x); n     v[x]++; n   } n   long long ans = 0; n   for (int i = 1; i < M; i++) n     for (int j = 1; j <= i; j++) n       if (cnt[i][j]) f[i] = j, ans += 1ll * v[i] * cnt[i][j]; n   while (1) { n     memset(siz, 0, sizeof(siz)); n     for (int i = 1; i < M; i++) siz[f[i]] += v[i]; n     int mx = 0, pl = 1; n     for (int i = 1; i < M; i++) n       if (siz[i] > mx) { n         mx = siz[i]; n         pl = i; n       } n     if (pl == 1) break; n     if (2 * mx <= n) break; n     ans = ans + n - 2 * mx; n     for (int i = 1; i < M; i++) { n       if (f[i] != pl) n         f[i] = 1; n       else { n         cnt[i][f[i]]--; n         while (!cnt[i][f[i]] && f[i] > 1) f[i]--; n       } n     } n   } n   printf( %lld , ans); n } n


#include <bits/stdc++.h> n using namespace std; n template <class T1, class T2> n inline istream& operator>>(istream& fin, pair<T1, T2>& pr) { n   fin >> pr.first >> pr.second; n   return fin; n } n template <class T0, class T1, class T2> n inline istream& operator>>(istream& fin, tuple<T0, T1, T2>& t) { n   fin >> get<0>(t) >> get<1>(t) >> get<2>(t); n   return fin; n } n template <class T> n inline istream& operator>>(istream& fin, vector<T>& a) { n   for (auto& u : a) fin >> u; n   return fin; n } n template <class T, size_t n> n inline istream& operator>>(istream& fin, array<T, n>& a) { n   for (auto& u : a) fin >> u; n   return fin; n } n void f538() { n   size_t n; n   cin >> n; n   vector<int> a(n); n   cin >> a; n   vector<int> acc(n); n   for (size_t j = 1; j < n; ++j) n     if (a[j] < a[0]) ++acc[j]; n   for (size_t i = 1; i < n; ++i) n     for (size_t l = i + 1, r = i + 2, k = 1; r - i - 1 < n; n          l += i, r += i + 1, ++k) n       for (size_t j = max(l, r - i - 1); j < min(r, n); ++j) n         if (a[j] < a[i]) ++acc[k], --acc[(j + i - 1) / i]; n   partial_sum(begin(acc) + 1, end(acc), ostream_iterator<int>(cout,    )); n } n int main(const int argc, char* argv[]) { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   ; n   f538(); n   return EXIT_SUCCESS; n } n


#include <bits/stdc++.h> n using namespace std; n typedef vector<int> vi; n typedef pair<int, int> ii; n using namespace std; n int n, q, len = 0, nxt[100005], nxtb[100005], disb[100005]; n int main() { n   int a, b, c, op; n   scanf( %d%d , &n, &q); n   len = n / 327 + 1; n   for (int i = 1; i <= n; ++i) { n     scanf( %d , &a); n     if (i + a <= n) n       nxt[i] = i + a; n     else n       nxt[i] = n + 1; n   } n   for (int i = 1; i <= n; i += 327) { n     b = min(n, i + 327 - 1); n     for (int j = b; j >= i; --j) { n       if (nxt[j] <= b) { n         nxtb[j] = nxtb[nxt[j]]; n         disb[j] = disb[nxt[j]] + 1; n       } else { n         nxtb[j] = j; n         disb[j] = 1; n       } n     } n   } n   while (q--) { n     scanf( %d , &op); n     if (op == 0) { n       scanf( %d%d , &a, &b); n       if (a + b <= n) n         nxt[a] = a + b; n       else n         nxt[a] = n + 1; n       b = a / 327 * 327; n       c = min(n, b + 327); n       for (int i = a; i > b; --i) { n         if (nxt[i] <= c) { n           nxtb[i] = nxtb[nxt[i]]; n           disb[i] = disb[nxt[i]] + 1; n         } else { n           nxtb[i] = i; n           disb[i] = 1; n         } n       } n     } else if (op == 1) { n       scanf( %d , &a); n       b = disb[a]; n       a = nxtb[a]; n       while (nxt[a] <= n) { n         b += disb[nxt[a]]; n         a = nxtb[nxt[a]]; n       } n       printf( %d %d n , a, b); n     } else n       assert(0); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long INF = (long long)(1e9 + 7); n bool check(pair<int, int> a, pair<int, int> b) { return (a.first < b.first); } n int main() { n   int t; n   cin >> t; n   while (t--) { n     int m, n; n     cin >> m >> n; n     int a[31][31]; n     pair<int, int> x[65]; n     for (int i = 0; i < 65; i++) { n       x[i] = {0, 0}; n     } n     for (int i = 1; i <= m; i++) { n       for (int j = 1; j <= n; j++) { n         cin >> a[i][j]; n       } n     } n     for (int i = 1; i <= m; i++) { n       for (int j = 1; j <= n; j++) { n         x[i + j].first += a[i][j]; n         x[i + j].second++; n       } n     } n     int sum = 0; n     for (int i = 2; 2 * i <= m + n + 1; i++) { n       sum += min(x[i].first + x[m + n + 2 - i].first, n                  x[i].second + x[m + n + 2 - i].second - n                      (x[i].first + x[m + n + 2 - i].first)); n     } n     cout << sum << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int n, a[100010], new_arr[100010], new_arr1[100010], arr[100010]; n int x = 1000000; n int main() { n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n   } n   for (int i = 0; i < n; i++) { n     new_arr[i] = min((i + 1), (n - i)); n     new_arr1[i] = a[i] - new_arr[i]; n     if (new_arr1[i] >= 0) { n       arr[new_arr1[i]]++; n     } n   } n   for (int i = 0; i < 100000; i++) { n     x = min(x, n - arr[i]); n   } n   cout << x; n } n


#include <bits/stdc++.h> n #pragma warning(disable : 4996) n using namespace std; n const int mod = 1000000007; n const int inf = 2012345678; n const long long infl = 9012345678901234567; n const double pi = 3.1415926535897932384626433832795; n struct rat { n   long long a, b; n   rat(long long _a = 0, long long _b = 1) { n     if (_b < 0) _a = -_a, _b = -_b; n     a = _a; n     b = _b; n   } n   bool operator<(const rat& ot) const { return a * ot.b < ot.a * b; } n   rat operator-() const { return rat(-a, b); } n   bool operator==(const rat& ot) const { return a * ot.b == ot.a * b; } n }; n const int N = 100000; n const int LG = 17; n vector<int> adj[N]; n int rnk[N], up[N], anc[N][LG], down[N], hvc[N], cnt[N]; n void dfs0(int u) { n   cnt[u] = 1; n   hvc[u] = -1; n   for (auto& x : adj[u]) { n     if (x == anc[u][0]) continue; n     rnk[x] = rnk[u] + 1; n     anc[x][0] = u; n     dfs0(x); n     cnt[u] += cnt[x]; n     if (hvc[u] == -1 || cnt[x] > cnt[hvc[u]]) hvc[u] = x; n   } n } n void dfs1(int u, bool hv) { n   if (hv) n     up[u] = u; n   else n     up[u] = up[anc[u][0]]; n   if (hvc[u] == -1) { n     down[u] = u; n   } else { n     dfs1(hvc[u], false); n     down[u] = down[hvc[u]]; n   } n   for (auto& x : adj[u]) { n     if (x == anc[u][0] || x == hvc[u]) continue; n     dfs1(x, true); n   } n } n int lca(int u, int v) { n   if (rnk[u] < rnk[v]) swap(u, v); n   int d = rnk[u] - rnk[v]; n   for (int i = 0; i < (LG); i++) n     if (d & (1 << i)) u = anc[u][i]; n   if (u == v) return u; n   for (int i = LG - 1; i >= 0; i--) n     if (anc[u][i] != anc[v][i]) u = anc[u][i], v = anc[v][i]; n   return anc[u][0]; n } n struct Query { n   int X, Y; n   int s, c; n   Query() {} n   Query(int a, int b, int x, int y) : X(a), Y(b), s(x), c(y) {} n }; n vector<Query> qs[N]; n double ans = 1e12; n int chk[N]; n void solve(int u) { n   priority_queue<tuple<rat, int, int, int> > pq; n   auto cmp = [&](int i, int j) -> bool { n     if (rat(qs[u][i].X, qs[u][i].c) < rat(qs[u][j].X, qs[u][j].c)) { n       return rat((long long)qs[u][i].c * qs[u][j].X, qs[u][j].c) < n              qs[u][j].s - qs[u][i].s + qs[u][i].X; n     } else { n       return rat(qs[u][i].s - qs[u][j].s + qs[u][j].X, 1) < n              rat((long long)qs[u][i].X * qs[u][j].c, qs[u][i].c); n     } n   }; n   set<int, decltype(cmp)> st(cmp); n   int sz = qs[u].size(); n   for (int i = 0; i < (sz); i++) { n     pq.push(make_tuple(rat(-qs[u][i].X, qs[u][i].c), 2, i, 0)); n     pq.push(make_tuple(rat(-qs[u][i].Y, qs[u][i].c), 1, i, 0)); n     chk[i] = 0; n   } n   while (!pq.empty()) { n     auto T = pq.top(); n     pq.pop(); n     int tp = get<1>(T); n     rat time = -get<0>(T); n     if (tp == 1) { n       int i = get<2>(T); n       chk[i] = 0; n       auto it = st.find(i); n       it = st.erase(it); n       auto it2 = it; n       if (it != st.begin()) { n         it2--; n         if (it != st.end()) { n           int i = *it; n           int j = *it2; n           if (qs[u][i].c != qs[u][j].c) { n             rat ntime = rat(qs[u][i].X - qs[u][j].X - qs[u][i].s + qs[u][j].s, n                             qs[u][i].c - qs[u][j].c); n             if (!(ntime < time)) { n               pq.push(make_tuple(-ntime, 3, i, j)); n             } n           } n         } n       } n     } else if (tp == 2) { n       int i = get<2>(T); n       chk[i] = 1; n       auto P = st.insert(i); n       if (!P.second) { n         ans = min(ans, (double)time.a / time.b); n         return; n       } n       auto it2 = P.first; n       auto it = it2; n       if (it != st.begin()) { n         it2--; n         int j = *it2; n         if (qs[u][i].c != qs[u][j].c) { n           rat ntime = rat(qs[u][i].X - qs[u][j].X - qs[u][i].s + qs[u][j].s, n                           qs[u][i].c - qs[u][j].c); n           if (!(ntime < time)) { n             pq.push(make_tuple(-ntime, 3, i, j)); n           } n         } n       } n       it2 = it; n       it2++; n       if (it2 != st.end()) { n         int j = *it2; n         if (qs[u][i].c != qs[u][j].c) { n           rat ntime = rat(qs[u][i].X - qs[u][j].X - qs[u][i].s + qs[u][j].s, n                           qs[u][i].c - qs[u][j].c); n           if (!(ntime < time)) { n             pq.push(make_tuple(-ntime, 3, i, j)); n           } n         } n       } n     } else { n       int u = get<2>(T); n       int v = get<3>(T); n       if (!chk[u] || !chk[v]) continue; n       ans = min(ans, (double)time.a / time.b); n       return; n     } n   } n } n int main() { n   freopen( input.txt ,  r , stdin); n   int n, m; n   scanf( %d%d , &(n), &(m)); n   for (int i = 0; i < (n - 1); i++) { n     int a, b; n     scanf( %d%d , &(a), &(b)); n     a--; n     b--; n     adj[a].push_back(b); n     adj[b].push_back(a); n   } n   anc[0][0] = -1; n   dfs0(0); n   dfs1(0, true); n   for (int j = 1; j <= (LG - 1); j++) n     for (int i = 0; i < (n); i++) { n       int a = anc[i][j - 1]; n       if (a == -1) n         anc[i][j] = -1; n       else n         anc[i][j] = anc[a][j - 1]; n     } n   for (int i = 0; i < (m); i++) { n     int t, c, u, v; n     scanf( %d%d , &(t), &(c)); n     scanf( %d%d , &(u), &(v)); n     u--; n     v--; n     bool good = false; n     int L = lca(u, v); n     int ou = u; n     while (up[u] != up[L]) { n       int uu = up[u]; n       qs[uu].emplace_back(-(c * t + rnk[ou] - rnk[u]), n                           -(c * t + rnk[ou] - rnk[uu] + 1), rnk[u], -c); n       u = anc[uu][0]; n     } n     if (u != L) { n       qs[up[u]].emplace_back(-(c * t + rnk[ou] - rnk[u]), n                              -(c * t + rnk[ou] - rnk[L]), rnk[u], -c); n       good = true; n     } n     int d = rnk[ou] - rnk[L]; n     while (up[v] != up[L]) { n       int vv = up[v]; n       qs[vv].emplace_back(t * c + rnk[vv] - 1 - rnk[L] + d, n                           t * c + rnk[v] - rnk[L] + d, rnk[vv] - 1, c); n       v = anc[vv][0]; n     } n     if (v != L) { n       good = true; n       qs[up[v]].emplace_back(t * c + d, t * c + rnk[v] - rnk[L] + d, rnk[L], c); n     } n     if (!good) { n       qs[up[L]].emplace_back(t * c + d, t * c + d, rnk[L], c); n     } n   } n   for (int i = 0; i < (n); i++) { n     if (up[i] == i) { n       solve(i); n     } n   } n   if (ans > 1e11) { n     puts( -1 ); n   } else n     printf( %.15f n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string pixels; n   getline(cin, pixels); n   getline(cin, pixels); n   int len = 0, flen = 0, last = pixels.at(0) -  0 ; n   bool first = false; n   for (int i = (0); i < (pixels.size()); i += (2)) { n     if ((pixels.at(i) ==  0  && last == 0) || n         (pixels.at(i) ==  1  && last == 1)) n       len++; n     else { n       if (!first) { n         flen = len; n         first = true; n       } else if (flen != len) { n         printf( NO ); n         return 0; n       } n       len = 1; n       last = 1 - last; n     } n   } n   if (!flen || flen == len) n     printf( YES ); n   else n     printf( NO ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int cnt[200010]; n long long num[200010]; n struct P { n   int x, y, fl; n   bool operator<(const P &hs) const { n     if (x != hs.x) n       return x < hs.x; n     else n       return y < hs.y; n   } n } p[200010]; n int row[200010]; n int pre[200010]; n int n, k; n int main() { n   scanf( %d %d , &n, &k); n   for (int i = 0; i < n; i++) { n     scanf( %d %d , &p[i].x, &p[i].y); n     p[i].fl = 1; n     p[i + n].x = p[i].x + k; n     p[i + n].y = p[i].y; n     p[i + n].fl = -1; n     row[i] = p[i].y; n     row[i + n] = row[i] + k; n   } n   sort(row, row + 2 * n); n   int ro = 0; n   for (int i = 1; i < 2 * n; i++) n     if (row[i] != row[ro]) row[++ro] = row[i]; n   sort(p, p + 2 * n); n   for (int i = 0; i < 2 * n; i++) { n     int y = lower_bound(row, row + ro, p[i].y) - row; n     for (int j = y; row[j] < row[y] + k; j++) { n       if (cnt[j] > 0) n         num[cnt[j]] += (long long)(row[j + 1] - row[j]) * (p[i].x - pre[j]); n       cnt[j] += p[i].fl; n       pre[j] = p[i].x; n     } n   } n   for (int i = 1; i <= n; i++) printf( %I64d%c , num[i], i == n ?   n  :    ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long MM = 10000000000000001; n int n; n long long a[200005]; n int rs[200005]; n long long lazy[4 * 200005]; n pair<long long, int> it[4 * 200005]; n pair<long long, int> minp(pair<long long, int> A, pair<long long, int> B) { n   if (A.first < B.first) return A; n   if (A.first > B.first) return B; n   if (A.second > B.second) return A; n   return B; n } n void build(int x, int l, int r) { n   if (l == r) { n     it[x] = make_pair(a[l], l); n     return; n   } n   int mid = (l + r) / 2; n   build(2 * x, l, mid); n   build(2 * x + 1, mid + 1, r); n   it[x] = minp(it[2 * x], it[2 * x + 1]); n } n void lazy_upd(int x, int l, int r) { n   it[x].first += lazy[x]; n   if (l != r) { n     lazy[2 * x] += lazy[x]; n     lazy[2 * x + 1] += lazy[x]; n   } n   lazy[x] = 0; n } n void update(int x, int l, int r, int u, int v, long long val) { n   lazy_upd(x, l, r); n   if ((r < u) || (v < l)) return; n   if ((u <= l) && (r <= v)) { n     lazy[x] += val; n     lazy_upd(x, l, r); n     return; n   } n   int mid = (l + r) / 2; n   update(2 * x, l, mid, u, v, val); n   update(2 * x + 1, mid + 1, r, u, v, val); n   it[x] = minp(it[2 * x], it[2 * x + 1]); n } n int main() { n   ios::sync_with_stdio(0); n   cin >> n; n   for (int i = 1; i <= n; i++) cin >> a[i]; n   build(1, 1, n); n   for (int i = 1; i <= n; i++) { n     pair<long long, int> p = it[1]; n     int id = p.second; n     rs[id] = i; n     update(1, 1, n, id, id, MM); n     update(1, 1, n, id + 1, n, -i); n   } n   for (int i = 1; i <= n; i++) cout << rs[i] <<    ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   int n; n   cin >> n; n   vector<int> v(n); n   for (int i = 0; i < n; i++) { n     cin >> v[i]; n   } n   int mx = *max_element(v.begin(), v.end()); n   int mn = *min_element(v.begin(), v.end()); n   int ind1 = 0, ind2 = 0; n   for (int i = 0; i < n; i++) { n     if (v[i] == mx && ind1 == 0) n       ind1 = i + 1; n     else if (v[i] == mn) n       ind2 = i + 1; n   } n   ind2--; n   ind1--; n   if (ind1 > ind2) ind2++; n   long long result = ind1 + n - ind2 - 1; n   cout << result; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, k, l, i, j = 0, s = 0, a, b, x, y; n   cin >> n >> a >> x >> b >> y; n   while (a != x && b != y) { n     a++; n     b--; n     if (b == 0 && b != y) b = n; n     if (a == n + 1 && a != x) a = 1; n     if (a == b) { n       cout <<  yes ; n       j = 1; n       break; n     } n     if (a == x || b == y) break; n   } n   if (j != 1) cout <<  no ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1e5 + 5; n int n; n long long k; n long long a[maxn]; n long long b[maxn], c[maxn], d[maxn]; n int main() { n   scanf( %d%lld , &n, &k); n   for (int i = 1; i <= n; i++) scanf( %lld , a + i); n   sort(a + 1, a + n + 1); n   int m = 0; n   for (int i = 1; i <= n; i++) { n     if (a[i] == a[m]) { n       ++b[m]; n     } else { n       a[++m] = a[i]; n       b[m] = 1; n     } n   } n   n = m; n   for (int i = 1; i <= n; i++) { n     c[i] = c[i - 1] + b[i]; n   } n   for (int i = n; i; i--) { n     d[i] = d[i + 1] + b[i]; n   } n   int l = 1, r = n; n   long long L = a[l], R = a[r]; n   while (l != r) { n     if (c[l] <= d[r]) { n       if (c[l] * (a[l + 1] - a[l]) > k) { n         L = a[l] + k / c[l]; n         break; n       } else { n         k -= c[l] * (a[l + 1] - a[l]); n         L = a[++l]; n       } n     } else { n       if (d[r] * (a[r] - a[r - 1]) > k) { n         R = a[r] - k / d[r]; n         break; n       } else { n         k -= d[r] * (a[r] - a[r - 1]); n         R = a[--r]; n       } n     } n   } n   printf( %lld n , R - L); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int dx[] = {1, -1, 0, 0}; n int dy[] = {0, 0, 1, -1}; n double PI = 3.1415926535897932384626433832795; n const long long oo = (long long)1e9 + 1; n const double eps = 1e-9; n const long long mod = 1000000007; n string s; n long long nb, ns, nc, pb, ps, pc, R; n int main() { n   cin >> s; n   cin >> nb >> ns >> nc; n   cin >> pb >> ps >> pc; n   cin >> R; n   int cb = 0, cs = 0, cc = 0; n   for (int i = 0; s[i]; i++) n     if (s[i] ==  B ) n       cb++; n     else if (s[i] ==  S ) n       cs++; n     else n       cc++; n   long long l = 0, r = 1e15, ret = 0; n   while (l <= r) { n     long long mid = (l + r) >> 1; n     if (max(cb * mid - nb, 0ll) * pb + max(cs * mid - ns, 0ll) * ps + n             max(cc * mid - nc, 0ll) * pc <= n         R) n       ret = mid, l = mid + 1; n     else n       r = mid - 1; n   } n   cout << ret << endl; n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   long long palite, primeite; n   std::cin >> palite >> primeite; n   long long primes = 0, palindromes = 0, max; n   static bool prime[12000001]; n   for (long long i = 0; i <= 12000000; i++) { n     prime[i] = true; n   } n   prime[1] = false; n   std::string str =  0 ; n   for (long long i = 1; i <= 12000000; i++) { n     if (prime[i]) { n       primes += primeite; n       for (long long j = i * i; j <= 12000000; j += i) { n         prime[j] = false; n       } n     } n     long long pos; n     for (pos = str.length() - 1; pos >= 0; pos--) { n       if (str[pos] ==  9 ) { n         str[pos] =  0 ; n       } else { n         str[pos]++; n         break; n       } n     } n     if (pos == -1) { n       str.insert(str.begin(),  1 ); n     } n     palindromes += palite; n     for (long long j = 0, back = str.length() - 1; back > j; j++, back--) { n       if (str[j] != str[back]) { n         palindromes -= palite; n         break; n       } n     } n     if (primes <= palindromes) { n       max = i; n     } n   } n   if (max == 12000000) { n     std::cout <<  Palindromic tree is better than splay tree ; n   } else { n     std::cout << max; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, i, j; n   string s; n   cin >> n; n   cin >> s; n   n = s.size(); n   for (i = 0; i < n - 1; i++) { n     if (s[i] > s[i + 1]) break; n   } n   if (i != n - 1) { n     cout <<  YES  n          <<   n ; n     cout << i + 1 <<     << i + 2 <<   n ; n   } else { n     cout <<  NO  n          <<   n ; n   } n } n


#include <bits/stdc++.h> n int main() { n   char s[512]; n   scanf( %s , s); n   int length = strlen(s); n   int i; n   int alpha_cnt = 0; n   for (i = 0; i < length; i++) { n     if (s[i] -  a  > alpha_cnt) { n       puts( NO ); n       return 0; n     } n     if (s[i] -  a  == alpha_cnt) { n       alpha_cnt++; n     } n   } n   puts( YES ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n using ld = double; n using pll = pair<ll, ll>; n using vll = vector<ll>; n using vpll = vector<pll>; n using vvll = vector<vll>; n vector<vector<ll>> g; n vector<bool> v; n ll res; n pair<bool, bool> dfs(int u, int depth) { n   v[u] = true; n   if (depth > 2 && g[u].size() == 1) return make_pair(false, false); n   bool inSet = false; n   bool isDominated = false; n   for (ll i = 0; i < (ll)g[u].size(); ++i) { n     if (v[g[u][i]]) continue; n     auto t = dfs(g[u][i], depth + 1); n     inSet |= !t.first; n     isDominated |= t.second; n   } n   if (depth <= 1) return make_pair(true, true); n   if (inSet) res++; n   return make_pair(isDominated || inSet, inSet); n } n int main() { n   ios::sync_with_stdio(0); n   cout.tie(0); n   cin.tie(0); n   ll n; n   cin >> n; n   g = vector<vector<ll>>(n); n   v = vector<bool>(n); n   for (ll i = 0; i < (ll)n - 1; ++i) { n     ll u, v; n     cin >> u >> v; n     u--; n     v--; n     g[u].push_back(v); n     g[v].push_back(u); n   } n   dfs(0, 0); n   cout << res << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); n void solve() { n   long long n; n   cin >> n; n   vector<long long> a(n), b; n   for (long long i = 0; i < n; i++) { n     cin >> a[i]; n   } n   b = a; n   sort(b.begin(), b.end()); n   b.resize(unique(b.begin(), b.end()) - b.begin()); n   for (long long i = 0; i < n; i++) { n     a[i] = lower_bound(b.begin(), b.end(), a[i]) - b.begin(); n   } n   vector<long long> dp(n, -1e9); n   dp[a[0]] = 1; n   for (long long i = 1; i < n; i++) { n     dp[a[i]] = 1; n     if (a[i]) dp[a[i]] = max(dp[a[i]], dp[a[i] - 1] + 1); n   } n   long long ans = n - *max_element(dp.begin(), dp.end()); n   cout << ans <<   n ; n } n signed main() { n   ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); n   long long q; n   cin >> q; n   while (q--) { n     solve(); n   } n } n


#include <bits/stdc++.h> n int n, up, s; n int a[20], ans[5][5], s1[5], s2[5], s3, s4, idx[1 << 16], cnt[1 << 16]; n bool ans_u, vis[1 << 16]; n void dfs(int sta) { n   if (sta == up) { n     if (ans_u) return; n     printf( %d n , s); n     for (int i = 0, j; i < n; ++i) { n       for (j = 0; j < n; ++j) { n         if (j) putchar(   ); n         printf( %d , ans[i][j]); n       } n       puts(  ); n     } n     ans_u = 1; n     return; n   } n   int x = cnt[sta] / n, y = cnt[sta] % n; n   for (int ts = up ^ sta, t, u; ts && !ans_u; ts ^= ts & (-ts)) { n     t = a[idx[ts & (-ts)]]; n     s1[x] += t; n     s2[y] += t; n     if (x == y) s3 += t; n     if (x + y == n - 1) s4 += t; n     u = 1; n     if (y == n - 1 && s1[x] != s) u = 0; n     if (x == n - 1 && s2[y] != s) u = 0; n     if (x == n - 1 && y == n - 1 && s3 != s) u = 0; n     if (x == n - 1 && y == 0 && s4 != s) u = 0; n     if (u) { n       ans[x][y] = t, dfs(sta ^ ((ts & (-ts)))); n     } n     s1[x] -= t; n     s2[y] -= t; n     if (x == y) s3 -= t; n     if (x + y == n - 1) s4 -= t; n   } n } n int main() { n   scanf( %d , &n); n   for (int i = 0; i < n * n; ++i) { n     scanf( %d , &a[i]); n     s += a[i]; n   } n   s /= n; n   up = (1 << (n * n)) - 1; n   idx[1] = 0; n   for (int i = 1, j = 1; i < up; idx[i <<= 1] = j++) n     ; n   cnt[0] = 0; n   for (int i = 1; i <= up; ++i) cnt[i] = cnt[i >> 1] + (i & 1); n   dfs(0); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(0), cin.tie(0); n   int n, j = 0; n   cin >> n; n   int a[n], b[n]; n   pair<int, int> s[n]; n   for (auto &i : s) cin >> i.first, i.second = j++; n   sort(s, s + n); n   map<int, int> mp; n   for (int i = 0; i < n; i++) mp[s[i].second] = i; n   for (int i = 0; i < (n + 2) / 3; i++) a[i] = i; n   for (int i = (n + 2) / 3; i < (2 * n + 2) / 3; i++) b[i] = i; n   for (int i = n - 1; i >= (2 * n + 2) / 3; i--) b[i] = n - 1 - i; n   for (int i = (n + 2) / 3; i < n; i++) a[i] = s[i].first - b[i]; n   for (int i = 0; i < (n + 2) / 3; i++) b[i] = s[i].first - a[i]; n   cout <<  YES  <<   n ; n   for (int i = 0; i < n; i++) cout << a[mp[i]] <<    ; n   cout <<   n ; n   for (int i = 0; i < n; i++) cout << b[mp[i]] <<    ; n } n


#include <bits/stdc++.h> n using namespace std; n void populate(string& s, char c, int n) { n   for (int i = 0; i < n; ++i) s[s.find_first_of( ? )] = c; n } n int main() { n   ios::sync_with_stdio(0); n   int n; n   cin >> n; n   string s; n   cin >> s; n   auto na = count(s.begin(), s.end(),  A ); n   auto nc = count(s.begin(), s.end(),  C ); n   auto ng = count(s.begin(), s.end(),  G ); n   auto nt = count(s.begin(), s.end(),  T ); n   auto nq = count(s.begin(), s.end(),  ? ); n   auto m = max(na, max(nc, (max(ng, nt)))); n   auto da = m - na; n   auto dc = m - nc; n   auto dg = m - ng; n   auto dt = m - nt; n   if (nq < da + dc + dg + dt) { n     cout <<  ===  << endl; n   } else if ((nq - (da + dc + dg + dt)) % 4 != 0) { n     cout <<  ===  << endl; n   } else { n     populate(s,  A , da); n     populate(s,  C , dc); n     populate(s,  G , dg); n     populate(s,  T , dt); n     for (int i = 0; i < (nq - (da + dc + dg + dt)); i += 4) { n       populate(s,  A , 1); n       populate(s,  C , 1); n       populate(s,  G , 1); n       populate(s,  T , 1); n     } n     cout << s << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n using Real = long double; n Real g_err = 1e-9; n bool r_eq(Real x, Real y, Real err = g_err) { n   return abs(x - y) <= err || abs(x - y) <= abs(x) * err; n } n bool r_le(Real x, Real y, Real err = g_err) { n   return x - y <= err || x - y <= abs(x) * err; n } n bool r_ge(Real x, Real y, Real err = g_err) { return r_le(y, x, err); } n bool r_gt(Real x, Real y, Real err = g_err) { return !r_le(x, y, err); } n bool r_lt(Real x, Real y, Real err = g_err) { return !r_le(y, x, err); } n bool r_ne(Real x, Real y, Real err = g_err) { return !r_eq(x, y, err); } n bool rp_eq(Real x, Real y, Real err = g_err) { return abs(x - y) <= err; } n bool rp_le(Real x, Real y, Real err = g_err) { return x - y <= err; } n bool rp_ge(Real x, Real y, Real err = g_err) { return rp_le(y, x, err); } n bool rp_gt(Real x, Real y, Real err = g_err) { return !rp_le(x, y, err); } n bool rp_lt(Real x, Real y, Real err = g_err) { return !rp_le(y, x, err); } n bool rp_ne(Real x, Real y, Real err = g_err) { return !rp_eq(x, y, err); } n template <typename T> n bool updMax(T& tmax, const T& x) { n   if (x > tmax) { n     tmax = x; n     return true; n   } else { n     return false; n   } n } n template <typename T> n bool updMin(T& tmin, const T& x) { n   if (x < tmin) { n     tmin = x; n     return true; n   } else { n     return false; n   } n } n struct Point { n   Real x; n   Real y; n   Point() : x(0), y(0) {} n   Point(Real x_, Real y_) : x(x_), y(y_) {} n   bool operator==(const Point& p) const { return x == p.x && y == p.y; } n   bool operator!=(const Point& p) const { return !(*this == p); } n   bool sim(const Point& p, Real err = g_err) const { n     return r_eq(x, p.x, err) && r_eq(y, p.y, err); n   } n   static bool sim(const Point& p1, const Point& p2, Real err = g_err) { n     return p1.sim(p2, err); n   } n   Point& operator+=(const Point& p) { n     x += p.x; n     y += p.y; n     return *this; n   } n   Point& operator-=(const Point& p) { n     x -= p.x; n     y -= p.y; n     return *this; n   } n   Point& operator*=(Real k) { n     x *= k; n     y *= k; n     return *this; n   } n   Point& operator/=(Real k) { n     x /= k; n     y /= k; n     return *this; n   } n   Point operator+(const Point& p) const { return Point(*this) += p; } n   Point operator-(const Point& p) const { return Point(*this) -= p; } n   Point operator*(Real k) const { return Point(*this) *= k; } n   Point operator/(Real k) const { return Point(*this) /= k; } n   Point operator-() const { return (*this) * (-1); } n   Real len() const { return hypot(x, y); } n   static Point polar(Real r, Real th) { n     return Point(r * cos(th), r * sin(th)); n   } n   Point rotate(Real th) const { return polar(len(), atan2(y, x) + th); } n   Point rotateQ() const { return Point(-y, x); } n   bool parallel(const Point& p, Real err = g_err) const { n     return r_eq(x * p.y, y * p.x, err); n   } n   Real innerProd(const Point& p) const { return x * p.x + y * p.y; } n   Real outerProd(const Point& p) const { return x * p.y - y * p.x; } n   Real arg() const { return atan2(y, x); } n   Real angle(const Point& p) const { n     Real th = atan2(p.y, p.x) - atan2(y, x); n     return th > 3.141592653589793238462643383279502884L n                ? th - 2 * 3.141592653589793238462643383279502884L n            : th <= -3.141592653589793238462643383279502884L n                ? th + 2 * 3.141592653589793238462643383279502884L n                : th; n   } n }; n Point operator*(Real k, const Point& p) { return p * k; } n ostream& operator<<(ostream& os, const Point& p) { n   return os <<  (  << p.x <<  ,   << p.y <<  ) ; n } n struct Line; n ostream& operator<<(ostream& os, const Line& l); n struct Line { n   Point dir; n   Point base; n   static Line x_axis; n   static Line y_axis; n   static constexpr int SIDE_ON = 1; n   static constexpr int SIDE_P = 2; n   static constexpr int SIDE_N = 4; n   static constexpr int IST_NONE = -1; n   static constexpr int IST_ALL = -2; n   static constexpr int IST_ONE = 0; n   Line() : dir(0, 0), base(0, 0) {} n   Line(const Point& d, const Point& b) : dir(d), base(b) {} n   bool operator==(const Line& l) const { n     return dir == l.dir && base == l.base; n   } n   bool operator!=(const Line& l) const { return !(*this == l); } n   bool sim(const Line& l1, Real err = g_err) const { n     return dir.sim(l1.dir, err) && dir.sim(l1.base - base, err); n   } n   static bool sim(const Line& l1, const Line& l2, Real err = g_err) { n     return l1.sim(l2, err); n   } n   static Line connect(const Point& p1, const Point& p2) { n     return Line(p2 - p1, p1); n   } n   bool parallel(const Line& l, Real err = g_err) const { n     return dir.parallel(l.dir, err); n   } n   int ptSide(const Point& p, Real err = g_err) const { n     Real t1 = dir.y * (p.x - base.x); n     Real t2 = dir.x * (p.y - base.y); n     if (r_eq(t1, t2, err)) return SIDE_ON; n     if (r_lt(t1, t2, err)) return SIDE_P; n     return SIDE_N; n   } n   bool ptOn(const Point& p, Real err = g_err) const { n     return ptSide(p, err) == SIDE_ON; n   } n   tuple<int, Real, Real> intersect_coeff(const Line& l) const { n     if (dir.parallel(l.dir)) { n       if (ptOn(l.base)) n         return make_tuple(IST_ALL, 0, 0); n       else n         return make_tuple(IST_NONE, 0, 0); n     } else { n       Real d = dir.x * (-l.dir.y) - (-l.dir.x) * dir.y; n       Point z = l.base - base; n       Real t1 = ((-l.dir.y) * z.x + l.dir.x * z.y) / d; n       Real t2 = ((-dir.y) * z.x + dir.x * z.y) / d; n       return {IST_ONE, t1, t2}; n     } n   } n   Point unsafe_intersect(const Line& l) const { n     auto [rc, t1, t2] = intersect_coeff(l); n     assert(rc == IST_ONE); n     return base + t1 * dir; n   } n   Point perpend_foot(const Point& p) const { n     Real t1 = perpend_foot_coeff(p); n     return base + t1 * dir; n   } n   Real perpend_foot_coeff(const Point& p) const { n     auto [rc, t1, t2] = intersect_coeff(Line(dir.rotateQ(), p)); n     return t1; n   } n   Real len(const Point& p) const { return (p - perpend_foot(p)).len(); } n }; n ostream& operator<<(ostream& os, const Line& l) { n   return os <<  [d   << l.dir <<  , b   << l.base <<  ) ; n } n Line Line::x_axis(Point(1, 0), Point(0, 0)); n Line Line::y_axis(Point(0, 1), Point(0, 0)); n struct Circle { n   Point c; n   Real r; n   Circle() : c(0, 0), r(0) {} n   Circle(const Point& c_, Real r_) : c(c_), r(r_) {} n   bool operator==(const Circle& o) const { return c == o.c && r == o.r; } n   bool operator!=(const Circle& o) const { return !(*this == o); } n   bool sim(const Circle& o, Real err = g_err) const { n     return c.sim(o.c, err) && r_eq(r, o.r, err); n   } n   static bool sim(const Circle& c1, const Circle& c2, Real err = g_err) { n     return c1.sim(c2, err); n   } n   bool ptOn(const Point& p, Real err = g_err) const { n     return r_eq((p - c).len(), r, err); n   } n   tuple<bool, Point, Point> intersect(const Line& o) const { n     Point f = o.perpend_foot(c); n     Real d = (f - c).len(); n     if (d > r) return make_tuple(false, Point(), Point()); n     Real t = sqrt(r * r - d * d); n     Point e = o.dir / o.dir.len(); n     return make_tuple(true, f + t * e, f - t * e); n   } n   tuple<bool, Point, Point> intersect(const Circle& o) const { n     Real d = (o.c - c).len(); n     if (d + r < o.r || d + o.r < r || r + o.r < d) { n       return make_tuple(false, Point(), Point()); n     } n     Point v = (o.c - c) / d; n     Real t = (r * r - o.r * o.r + d * d) / (2 * d); n     Line l(v.rotateQ(), c + t * v); n     return intersect(l); n   } n }; n ostream& operator<<(ostream& os, const Circle& circ) { n   return os <<  [c   << circ.c <<  ,   << circ.r <<  ] ; n } n Point circumcenter(const Point& z1, const Point& z2, const Point& z3) { n   Line l12((z2 - z1).rotateQ(), (z1 + z2) / 2); n   Line l23((z3 - z2).rotateQ(), (z2 + z3) / 2); n   return l12.unsafe_intersect(l23); n } n vector<Point> convex_hull(const vector<Point>& pts) { n   vector<Point> spts(pts); n   int n = pts.size(); n   if (n == 0) return vector<Point>(); n   auto sub = [&]() -> vector<Point> { n     vector<Point> ret; n     for (int i = 0; i < n; i++) { n       Point pt = spts.at(i); n       if (i > 0 && spts.at(i - 1).sim(spts.at(i))) continue; n       while (true) { n         int rs = ret.size(); n         if (rs - 2 < 0) break; n         Point q0 = ret.at(rs - 2); n         Point q1 = ret.at(rs - 1); n         if ((q0 - q1).outerProd(pt - q1) < 0) break; n         ret.pop_back(); n       } n       ret.push_back(pt); n     } n     ret.pop_back(); n     return ret; n   }; n   sort(spts.begin(), spts.end(), [](const Point& a, const Point& b) -> bool { n     if (a.x != b.x) return a.x < b.x; n     return a.y < b.y; n   }); n   auto vec1 = sub(); n   reverse(spts.begin(), spts.end()); n   auto vec2 = sub(); n   vec1.insert(vec1.end(), vec2.begin(), vec2.end()); n   if (vec1.empty()) return vector<Point>({pts.at(0)}); n   return vec1; n } n tuple<Real, int, int> convex_diameter(const vector<Point>& pts) { n   int n = pts.size(); n   if (n <= 1) { n     cerr <<  diameter is called with <=1 points. n ; n     exit(1); n   } n   auto conn = [&](long long int i, long long int j) -> Point { n     return pts.at(j % n) - pts.at(i % n); n   }; n   auto edge = [&](long long int i) -> Point { return conn(i, i + 1); }; n   if (n == 2) return make_tuple(conn(0, 1).len(), 0, 1); n   int k = -1; n   int m = -1; n   for (int i = 0, cnt = 0; cnt < 2; i++) { n     if (edge(i).y <= 0 && edge(i + 1).y > 0) { n       m = i + 1; n       cnt++; n     } n     if (edge(i).y >= 0 && edge(i + 1).y < 0) { n       k = i + 1; n       cnt++; n     } n   } n   Real vmax = 0; n   int k0 = -1, m0 = -1; n   bool run_k = true; n   bool run_m = true; n   while (run_k || run_m) { n     if (!run_m || n         (run_k && edge(k).arg() - (-3.141592653589793238462643383279502884L) <= n                       edge(m).arg())) { n       if (updMax(vmax, conn(k + 1, m).len())) { n         k0 = k + 1, m0 = m; n       } n       k++; n       if (edge(k).y > 0) run_k = false; n     } else { n       if (updMax(vmax, conn(k, m + 1).len())) { n         k0 = k, m0 = m + 1; n       } n       m++; n       if (edge(m).y < 0) run_m = false; n     } n   } n   return make_tuple(vmax, k0 % n, m0 % n); n } n int in_triangle(const Point& pt, const Point& tr0, const Point& tr1, n                 const Point& tr2) { n   auto chk = [&](const Point& b, const Point& e, const Point& p) -> bool { n     Point be = e - b; n     Point bp = p - b; n     Real r = r_eq(be.x, 0.0) ? bp.y / be.y : bp.x / be.x; n     return 0.0 <= r && r <= 1.0; n   }; n   Line l01 = Line::connect(tr0, tr1); n   Line l12 = Line::connect(tr1, tr2); n   Line l20 = Line::connect(tr2, tr0); n   int side = l01.ptSide(tr2); n   if (side == Line::SIDE_ON) { n     if (!l01.ptOn(pt)) return Line::SIDE_N; n     return chk(tr0, tr1, pt) || chk(tr1, tr2, pt) || chk(tr2, tr0, pt) n                ? Line::SIDE_ON n                : Line::SIDE_N; n   } n   int other = side ^ (Line::SIDE_P | Line::SIDE_N); n   if (l01.ptSide(pt) == other || l12.ptSide(pt) == other || n       l20.ptSide(pt) == other) n     return Line::SIDE_N; n   if (l01.ptSide(pt) == Line::SIDE_ON || l12.ptSide(pt) == Line::SIDE_ON || n       l20.ptSide(pt) == Line::SIDE_ON) n     return Line::SIDE_ON; n   return Line::SIDE_P; n } n template <typename T1, typename T2> n ostream& operator<<(ostream& os, const pair<T1, T2>& p) { n   os <<  (  << p.first <<  ,   << p.second <<  ) ; n   return os; n } n template <typename T1, typename T2, typename T3> n ostream& operator<<(ostream& os, const tuple<T1, T2, T3>& t) { n   os <<  (  << get<0>(t) <<  ,   << get<1>(t) <<  ,   << get<2>(t) <<  ) ; n   return os; n } n template <typename T1, typename T2, typename T3, typename T4> n ostream& operator<<(ostream& os, const tuple<T1, T2, T3, T4>& t) { n   os <<  (  << get<0>(t) <<  ,   << get<1>(t) <<  ,   << get<2>(t) <<  ,   n      << get<3>(t) <<  ) ; n   return os; n } n template <typename T> n ostream& operator<<(ostream& os, const vector<T>& v) { n   os <<  [ ; n   for (auto it = v.begin(); it != v.end(); it++) { n     if (it != v.begin()) os <<  ,  ; n     os << *it; n   } n   os <<  ] ; n   return os; n } n template <typename T, typename C> n ostream& operator<<(ostream& os, const set<T, C>& v) { n   os <<  { ; n   for (auto it = v.begin(); it != v.end(); it++) { n     if (it != v.begin()) os <<  ,  ; n     os << *it; n   } n   os <<  } ; n   return os; n } n template <typename T, typename C> n ostream& operator<<(ostream& os, const unordered_set<T, C>& v) { n   os <<  { ; n   for (auto it = v.begin(); it != v.end(); it++) { n     if (it != v.begin()) os <<  ,  ; n     os << *it; n   } n   os <<  } ; n   return os; n } n template <typename T, typename C> n ostream& operator<<(ostream& os, const multiset<T, C>& v) { n   os <<  { ; n   for (auto it = v.begin(); it != v.end(); it++) { n     if (it != v.begin()) os <<  ,  ; n     os << *it; n   } n   os <<  } ; n   return os; n } n template <typename T1, typename T2, typename C> n ostream& operator<<(ostream& os, const map<T1, T2, C>& mp) { n   os <<  [ ; n   for (auto it = mp.begin(); it != mp.end(); it++) { n     if (it != mp.begin()) os <<  ,  ; n     os << it->first <<  :   << it->second; n   } n   os <<  ] ; n   return os; n } n template <typename T1, typename T2, typename C> n ostream& operator<<(ostream& os, const unordered_map<T1, T2, C>& mp) { n   os <<  [ ; n   for (auto it = mp.begin(); it != mp.end(); it++) { n     if (it != mp.begin()) os <<  ,  ; n     os << it->first <<  :   << it->second; n   } n   os <<  ] ; n   return os; n } n template <typename T, typename T2> n ostream& operator<<(ostream& os, const queue<T, T2>& orig) { n   queue<T, T2> que(orig); n   bool first = true; n   os <<  [ ; n   while (!que.empty()) { n     T x = que.front(); n     que.pop(); n     if (!first) os <<  ,  ; n     os << x; n     first = false; n   } n   return os <<  ] ; n } n template <typename T, typename T2> n ostream& operator<<(ostream& os, const deque<T, T2>& orig) { n   deque<T, T2> que(orig); n   bool first = true; n   os <<  [ ; n   while (!que.empty()) { n     T x = que.front(); n     que.pop_front(); n     if (!first) os <<  ,  ; n     os << x; n     first = false; n   } n   return os <<  ] ; n } n template <typename T, typename T2, typename T3> n ostream& operator<<(ostream& os, const priority_queue<T, T2, T3>& orig) { n   priority_queue<T, T2, T3> pq(orig); n   bool first = true; n   os <<  [ ; n   while (!pq.empty()) { n     T x = pq.top(); n     pq.pop(); n     if (!first) os <<  ,  ; n     os << x; n     first = false; n   } n   return os <<  ] ; n } n template <typename T> n ostream& operator<<(ostream& os, const stack<T>& st) { n   stack<T> tmp(st); n   os <<  [ ; n   bool first = true; n   while (!tmp.empty()) { n     T& t = tmp.top(); n     if (first) n       first = false; n     else n       os <<  ,  ; n     os << t; n     tmp.pop(); n   } n   os <<  ] ; n   return os; n } n ostream& operator<<(ostream& os, int8_t x) { n   os << (int32_t)x; n   return os; n } n template <class... Args> n string dbgFormat(const char* fmt, Args... args) { n   size_t len = snprintf(nullptr, 0, fmt, args...); n   char buf[len + 1]; n   snprintf(buf, len + 1, fmt, args...); n   return string(buf); n } n template <class Head> n void dbgLog(bool with_nl, Head&& head) { n   cerr << head; n   if (with_nl) cerr << endl; n } n template <class Head, class... Tail> n void dbgLog(bool with_nl, Head&& head, Tail&&... tail) { n   cerr << head <<    ; n   dbgLog(with_nl, forward<Tail>(tail)...); n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n   cout << setprecision(20); n   long long int n, q; n   cin >> n >> q; n   vector<Point> P(n); n   for (long long int i = 0; i < n; i++) { n     long long int x, y; n     cin >> x >> y; n     P[i] = Point(x, y); n   } n   Point g(0, 0); n   Real tots = 0; n   for (long long int i = 1; i < n - 1; i++) { n     Point lg = (P[0] + P[i] + P[i + 1]) / 3.0; n     Point v0i = P[i] - P[0]; n     Point v0j = P[i + 1] - P[0]; n     Real s = abs(v0i.x * v0j.y - v0i.y * v0j.x); n     tots += s; n     g += s * lg; n   } n   g = g / tots; n   vector<Real> L(n), Th(n); n   for (long long int i = 0; i < n; i++) { n     L[i] = (P[i] - g).len(); n     Th[i] = (P[0] - g).angle(P[i] - g); n   }; n   ; n   ; n   Real th0 = (P[0] - g).arg(); n   ; n   long long int pinA = 0, pinB = 1; n   for (long long int _q = 0; _q < q; _q++) { n     long long int tp; n     cin >> tp; n     if (tp == 1) { n       long long int f, t; n       cin >> f >> t; n       f--; n       t--; n       if (f == pinA) { n         pinA = pinB; n         pinB = t; n       } else { n         pinB = t; n       }; n       Point e(L[pinA], 0); n       Point pa = g + e.rotate(th0 + Th[pinA]); n       g = pa + e.rotate(3 * 3.141592653589793238462643383279502884L / 2); n       ; n       th0 += 3.141592653589793238462643383279502884L / 2.0 - (th0 + Th[pinA]); n       ; n     } else if (tp == 2) { n       long long int v; n       cin >> v; n       v--; n       Point e(L[v], 0); n       Point pv = g + e.rotate(th0 + Th[v]); n       cout << pv.x <<     << pv.y <<   n ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n signed main() { n   long long t; n   cin >> t; n   while (t--) { n     long long n; n     cin >> n; n     long long k; n     vector<long long> ans; n     if (n > 3) { n       if (n % 2 == 1) n         k = n - 1; n       else n         k = n; n       while (k > 0) { n         if (k == 4) ans.push_back(2); n         if (k == 2) ans.push_back(4); n         if (k != 4 && k != 2) ans.push_back(k); n         k -= 2; n       } n       k = 1; n       while (k <= n) { n         ans.push_back(k); n         k += 2; n       } n       for (auto u : ans) cout << u <<    ; n       cout << endl; n     } else { n       cout <<  -1  << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(false); n   int n, r; n   cin >> n >> r; n   double alpha = 90.0 - 180.0 / n; n   double val = cos(alpha * 3.14159265 / 180.0); n   double ans = val * (double)r / (1 - val); n   cout << fixed << setprecision(6) << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n int d[3000], g[3000], q[3000]; n int i, j, k, m, n, r, t; n int main() { n   scanf( %d%d , &n, &m); n   for (i = 1; i <= n; i++) { n     scanf( %d , &g[i]); n     if (g[i] <= m) n       d[g[i]]++; n     else n       r++; n   } n   for (k = 0;; k++) { n     t = 1; n     for (i = 2; i <= m; i++) n       if (d[i] < d[t]) t = i; n     if (d[t] == n / m) break; n     d[t]++; n     if (r) n       r--; n     else { n       t = 1; n       for (i = 2; i <= m; i++) n         if (d[i] > d[t]) t = i; n       d[t]--; n     } n   } n   printf( %d %d n , n / m, k); n   for (i = 1; i <= n; i++) n     if ((g[i] <= m) && (d[g[i]])) { n       q[i] = g[i]; n       d[g[i]]--; n     } else if ((g[i] > m) && (r)) { n       q[i] = g[i]; n       r--; n     } n   for (i = 1; i <= n; i++) n     if (q[i]) n       printf( %d  , q[i]); n     else n       for (j = 1; j <= m; j++) n         if (d[j]) { n           printf( %d  , j); n           d[j]--; n           break; n         } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 100009; n int acc[MAXN], sav[MAXN]; n int extr(string &s) { n   int num = 0; n   for (int i = 1; i < s.length(); i++) { n     num *= 10; n     num += (s[i] -  0 ); n   } n   return num; n } n int main() { n   int n, m; n   scanf( %d , &n); n   scanf( %d , &m); n   int pl = 0, mn = 0; n   vector<string> statements; n   for (int i = 0; i < n; i++) { n     string s; n     cin >> s; n     statements.push_back(s); n     int z = extr(s); n     if (s[0] ==  + ) n       acc[z]++, pl++; n     else n       sav[z]++, mn++; n   } n   set<int> Suspects; n   for (int i = 1; i < n + 1; i++) { n     int tr = acc[i] + mn - sav[i]; n     if (tr == m) { n       Suspects.insert(i); n     } n   } n   for (int i = 0; i < n; i++) { n     string s = statements[i]; n     int z = extr(s); n     if (s[0] ==  + ) { n       if (Suspects.find(z) == Suspects.end()) { n         cout <<  Lie  <<   n ; n         continue; n       } n       if (Suspects.size() == 1) { n         cout <<  Truth  <<   n ; n       } else { n         cout <<  Not defined  <<   n ; n       } n     } else { n       if (Suspects.size() == 1 && Suspects.find(z) != Suspects.end()) { n         cout <<  Lie  <<   n ; n         continue; n       } n       if (Suspects.find(z) == Suspects.end()) { n         cout <<  Truth  <<   n ; n         continue; n       } else n         cout <<  Not defined  <<   n ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxN = 1e6 + 1e5 + 5; n struct Node { n   int len, pa; n   int trans[26]; n } st[maxN + 1]; n int n, m, last, cnt; n int L[11], R[11]; n int sum[11][maxN + 1]; n char s[maxN + 1]; n vector<int> son[maxN + 1]; n inline int insert(int c) { n   if (st[last].trans[c] && st[st[last].trans[c]].len == st[last].len + 1) n     return st[last].trans[c]; n   int np = ++cnt, p = last, f = np; n   st[np].len = st[p].len + 1; n   while (p && !st[p].trans[c]) st[p].trans[c] = np, p = st[p].pa; n   if (!p) n     st[np].pa = 1; n   else { n     int q = st[p].trans[c]; n     if (st[q].len == st[p].len + 1) n       st[np].pa = q; n     else { n       int nq = ++cnt; n       if (p == last) f = nq; n       st[nq] = st[q]; n       st[nq].len = st[p].len + 1; n       st[np].pa = st[q].pa = nq; n       while (p && st[p].trans[c] == q) st[p].trans[c] = nq, p = st[p].pa; n     } n   } n   return f; n } n inline void calc(int u) { n   for (int i = 0; i < son[u].size(); i++) { n     int v = son[u][i]; n     calc(v); n     for (int j = 0; j <= m; j++) sum[j][u] += sum[j][v]; n   } n } n int main() { n   scanf( %s , s + 1); n   n = strlen(s + 1); n   last = cnt = 1; n   for (int i = 1; i <= n; i++) last = insert(s[i] -  a ), sum[0][last]++; n   scanf( %d , &m); n   for (int i = 1; i <= m; i++) { n     scanf( %s %d %d , s + 1, &L[i], &R[i]); n     int len = strlen(s + 1); n     last = 1; n     for (int j = 1; j <= len; j++) last = insert(s[j] -  a ), sum[i][last]++; n   } n   for (int i = 1; i <= cnt; i++) son[st[i].pa].push_back(i); n   calc(1); n   long long ans = 0; n   for (int i = 2; i <= cnt; i++) { n     if (!sum[0][i]) continue; n     bool flag = true; n     for (int j = 1; j <= m; j++) n       if (sum[j][i] < L[j] || sum[j][i] > R[j]) { n         flag = false; n         break; n       } n     if (flag) ans += st[i].len - st[st[i].pa].len; n   } n   printf( %lld , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long linf = 4000000000000000000LL; n const long long inf = 1000000007; n void pv(vector<int> a) { n   for (auto& x : a) cout << x <<    ; n   cout << endl; n } n void pv(vector<long long> a) { n   for (auto& x : a) cout << x <<    ; n   cout << endl; n } n void pv(vector<vector<int>> a) { n   for (int i = (0); i < (int(a.size())); ++i) { n     cout << i << endl; n     pv(a[i]); n     cout << endl; n   } n } n void pv(vector<vector<long long>> a) { n   for (int i = (0); i < (int(a.size())); ++i) { n     cout << i << endl; n     pv(a[i]); n   } n   cout << endl; n } n void pv(vector<string> a) { n   for (auto& x : a) cout << x << endl; n   cout << endl; n } n void setIO(string second) { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n } n int n, k; n vector<pair<long long, long long>> a; n void init() { n   vector<pair<long long, long long>> t; n   for (auto& x : a) n     if (x.first == 0 && x.second == 0) n       k--, n--; n     else n       t.push_back(x); n   a = t; n } n bool check(long double r) { n   long double pi = acos(-1); n   vector<pair<long double, int>> ranges; n   for (int i = (0); i < (n); ++i) { n     long double d = sqrt(a[i].first * a[i].first + a[i].second * a[i].second); n     if (d > 2 * r) continue; n     long double theta = acos(d / (2 * r)); n     long double theta1 = atan((long double)a[i].second / a[i].first); n     if (theta1 < 0 || (theta1 == 0 && a[i].first < 0)) theta1 += pi; n     if (a[i].second < 0) theta1 += pi; n     long double x = theta1 - theta, y = theta1 + theta; n     if (x < 0 && y >= 0) { n       ranges.push_back({x + 2 * pi, 1}); n       ranges.push_back({2 * pi, -1}); n       ranges.push_back({0, 1}); n       ranges.push_back({y, -1}); n     } else if (x < 2 * pi && y >= 2 * pi) { n       ranges.push_back({x, 1}); n       ranges.push_back({2 * pi, -1}); n       ranges.push_back({0, 1}); n       ranges.push_back({y - 2 * pi, -1}); n     } else { n       ranges.push_back({x, 1}); n       ranges.push_back({y, -1}); n     } n   } n   sort(ranges.begin(), ranges.end(), n        [](pair<long double, int> x, pair<long double, int> y) { n          if (x.first == y.first) return x.second > y.second; n          return x.first < y.first; n        }); n   int m = 0; n   int cur = 0; n   for (auto& x : ranges) { n     cur += x.second; n     m = max(m, cur); n   } n   return m >= k; n } n int main() { n   setIO( test1 ); n   cin >> n >> k; n   a.resize(n); n   for (auto& x : a) cin >> x.first >> x.second; n   init(); n   long double l = 0, r = 222222; n   for (int i = (0); i < (31); ++i) { n     long double m = (l + r) / 2; n     if (check(m)) n       r = m; n     else n       l = m; n   } n   cout << setprecision(20) << l << endl; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( Ofast ) n using namespace std; n mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); n const long long G = 300005, BASE = 666667, M1 = 2e9 + 11, M2 = 1e9 + 9; n long long IB1, IB2; n long long a, o; n long long m[G], pwb1[G], pwb2[G]; n long long binpow(long long x, long long k, long long mod) { n   long long res = 1; n   for (; k; k >>= 1) { n     if (k & 1) res = res * x % mod; n     x = x * x % mod; n   } n   return res; n } n long long modInv(long long x, long long mod) { return binpow(x, mod - 2, mod); } n void rec(long long l, long long r) { n   long long d = r - l + 1; n   if (d < 2) return; n   long long md = (l + r) / 2; n   vector<pair<long long, long long> > hl, hr; n   vector<long long> stq; n   for (long long q = md, hs1 = 0, hs2 = 0; q >= l; q--) { n     if (stq.size() && stq.back() == m[q]) { n       hs1 = (hs1 - m[q] + M1) % M1; n       hs1 = hs1 * IB1 % M1; n       hs2 = (hs2 - m[q] + M2) % M2; n       hs2 = hs2 * IB2 % M2; n       stq.pop_back(); n     } else { n       stq.push_back(m[q]); n       hs1 = (hs1 * BASE + m[q]) % M1; n       hs2 = (hs2 * BASE + m[q]) % M2; n     } n     hl.push_back({hs1, hs2}); n   } n   stq.clear(); n   for (long long q = md + 1, hs1 = 0, hs2 = 0; q <= r; q++) { n     if (stq.size() && stq.back() == m[q]) { n       hs1 = (hs1 - m[q] + M1) % M1; n       hs1 = hs1 * IB1 % M1; n       hs2 = (hs2 - m[q] + M2) % M2; n       hs2 = hs2 * IB2 % M2; n       stq.pop_back(); n     } else { n       stq.push_back(m[q]); n       hs1 = (hs1 * BASE + m[q]) % M1; n       hs2 = (hs2 * BASE + m[q]) % M2; n     } n     hr.push_back({hs1, hs2}); n   } n   sort(hl.begin(), hl.end()); n   sort(hr.begin(), hr.end()); n   for (pair<long long, long long> i : hl) { n     o += upper_bound(hr.begin(), hr.end(), i) - n          lower_bound(hr.begin(), hr.end(), i); n   } n   rec(l, md); n   rec(md + 1, r); n } n long long solve() { n   cin >> a; n   for (int q = 0; q < a; q++) cin >> m[q]; n   o = 0; n   rec(0, a - 1); n   return o; n } n int main() { n   cin.tie(0); n   cout.tie(0); n   cin.sync_with_stdio(0); n   cout.sync_with_stdio(0); n   ; n   IB1 = modInv(BASE, M1); n   IB2 = modInv(BASE, M2); n   pwb1[0] = 1; n   pwb2[0] = 1; n   for (int q = 1; q < G; q++) pwb1[q] = pwb1[q - 1] * BASE % M1; n   for (int q = 1; q < G; q++) pwb2[q] = pwb2[q - 1] * BASE % M2; n   int z; n   cin >> z; n   for (; z--;) { n     cout << solve() <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n long long unorder(int n) { n   if (n == 0) return 1; n   if (n == 1) return 0; n   bool good; n   long long ans = 0; n   vector<int> V(n); n   for (int i = 0; i < n; i++) V[i] = i; n   do { n     good = true; n     for (int i = 0; i < n && good; i++) good = (V[i] != i); n     if (good) ans++; n   } while (next_permutation(V.begin(), V.end())); n   return ans; n } n long long newton(int n, int k) { n   if (k > n) return 0; n   if (2 * k > n) k = n - k; n   long long ans = 1; n   for (int i = n - k + 1; i <= n; i++) ans *= i; n   for (int i = 1; i <= k; i++) ans /= i; n   return ans; n } n int main() { n   int n, k; n   long long ans = 0; n   cin >> n >> k; n   for (int i = 0; i <= k; i++) { n     long long unorders = unorder(i), combinations = newton(n, n - i); n     ans += combinations * unorders; n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int dist[100010], n; n vector<pair<int, int> > gr[100010]; n void dfs() { n   memset(dist, -1, sizeof(dist)); n   dist[1] = 0; n   queue<int> q; n   q.push(1); n   while (!q.empty()) { n     int u = q.front(); n     q.pop(); n     for (int i = 0; i < gr[u].size(); i++) { n       int next = gr[u][i].first; n       if (dist[next] == -1) { n         dist[next] = dist[u] + 1; n         q.push(next); n       } n     } n   } n } n vector<pair<int, pair<int, int> > > ans; n int v_ans = 0; n int dp[100010]; n map<pair<int, int>, int> mark; n int calc_dp(int u) { n   if (dp[u] != -1) return dp[u]; n   if (u == 1) return dp[u] = 0; n   for (int i = 0; i < gr[u].size(); i++) { n     int next = gr[u][i].first; n     if (dist[next] == dist[u] - 1) n       dp[u] = max(dp[u], calc_dp(next) + gr[u][i].second); n   } n   return dp[u]; n } n void calc_ans(int u) { n   if (u == 1) { n     return; n   } n   for (int i = 0; i < gr[u].size(); i++) { n     int next = gr[u][i].first; n     if (dist[next] == dist[u] - 1 && dp[next] == dp[u] - gr[u][i].second) { n       calc_ans(next); n       mark[{min(next, u), max(next, u)}] = 1; n       break; n     } n   } n } n int main() { n   ios::sync_with_stdio(false); n   memset(dp, -1, sizeof(dp)); n   int m; n   cin >> n >> m; n   int cont = 0; n   vector<pair<int, pair<int, int> > > edges; n   for (int i = 0; i < m; i++) { n     int a, b, z; n     cin >> a >> b >> z; n     cont += z; n     gr[a].push_back({b, z}); n     gr[b].push_back({a, z}); n     edges.push_back({z, {min(a, b), max(a, b)}}); n   } n   dfs(); n   int v = calc_dp(n); n   cout << (cont - v) + (dist[n] - v) << endl; n   calc_ans(n); n   for (int i = 0; i < m; i++) { n     if (edges[i].first == 1 && !mark[edges[i].second]) n       cout << edges[i].second.first <<     << edges[i].second.second <<   0 n ; n     if (edges[i].first == 0 && mark[edges[i].second]) n       cout << edges[i].second.first <<     << edges[i].second.second <<   1 n ; n   } n   return 0; n } n