#include <bits/stdc++.h> n using namespace std; n bool deb_mode = 0; n class debugger { n   vector<string> vars; n  n  public: n   template <typename T> n   debugger &operator,(const T v) { n     stringstream ss; n     ss << v, vars.push_back(ss.str()); n     return *this; n   } n   void printall() { n     int j = 0, l = vars.size(); n     for (int i = 0; i < (l - 1); i++) { n       if (i) cout <<  ,  ; n       for (; j < vars[l - 1].size(); j++) { n         if (vars[l - 1][j] ==  , ) { n           j++; n           break; n         } n         cout << vars[l - 1][j]; n       } n       cout <<   =   << vars[i]; n     } n     vars.clear(); n   } n } Dbug; n template <typename T1, typename T2> n inline ostream &operator<<(ostream &os, const pair<T1, T2> &p) { n   return os <<  (  << p.first <<  ,  << p.second <<  ) ; n } n template <typename T> n inline ostream &operator<<(ostream &os, const vector<T> &v) { n   bool first = true; n   os <<  { ; n   for (unsigned int i = 0; i < v.size(); i++) { n     if (!first) os <<  , ; n     os << v[i]; n     first = false; n   } n   return os <<  } ; n } n template <typename T> n inline ostream &operator<<(ostream &os, const set<T> &v) { n   bool first = true; n   os <<  { ; n   for (typename set<T>::const_iterator ii = v.begin(); ii != v.end(); ++ii) { n     if (!first) os <<  , ; n     os << *ii; n     first = false; n   } n   return os <<  } ; n } n template <typename T1, typename T2> n inline ostream &operator<<(ostream &os, const map<T1, T2> &v) { n   bool first = true; n   os <<  { ; n   for (typename map<T1, T2>::const_iterator ii = v.begin(); ii != v.end(); n        ++ii) { n     if (!first) os <<  , ; n     os << *ii; n     first = false; n   } n   return os <<  } ; n } n template <typename T> n void getarray(T a[], int b, int e) { n   for (int i = b; i < e + b; i++) cin >> a[i]; n } n template <typename T> n void printarray(T a[], int b, int e) { n   for (int i = b; i < e - 1 + b; i++) cout << a[i] <<    ; n   if (e - 1 + b >= 0) cout << a[e - 1 + b] <<   n ; n } n template <typename T> n void printV(vector<T> v) { n   int sz = v.size(); n   if (sz) cout << v[0]; n   for (int i = 1; i < sz; i++) cout <<     << v[i]; n   printf(  n ); n } n template <typename T> n T gcd(T a, T b) { n   if (b == 0) return a; n   return gcd(b, a % b); n } n template <typename T> n T BigMod(T b, T p, T m) { n   if (p == 0) return 1; n   if (p % 2 == 0) { n     T s = BigMod(b, p / 2, m); n     return ((s % m) * (s % m)) % m; n   } n   return ((b % m) * (BigMod(b, p - 1, m) % m)) % m; n } n template <typename T> n T ModInv(T b, T m) { n   return BigMod(b, m - 2, m); n } n pair<long long int, pair<long long int, long long int> > ext_gcd( n     long long int a, long long int b) { n   if (b == 0) return make_pair(a, make_pair(1LL, 0LL)); n   pair<long long int, pair<long long int, long long int> > t = n       ext_gcd(b, a % b); n   return make_pair( n       t.first, n       make_pair(t.second.second, t.second.first - a / b * t.second.second)); n } n long long int ModInvNonPrimeM(long long int N, long long int M) { n   pair<long long int, pair<long long int, long long int> > r = ext_gcd(N, M); n   r.second.first %= M; n   if (r.second.first < 0) r.second.first += M; n   return r.second.first; n } n template <class T> n inline void read(T &x) { n   bool Minus = 0; n   char c; n   for (c = getchar(); c <= 32; c = getchar()) n     ; n   if (c ==  - ) Minus = 1, c = getchar(); n   for (x = 0; c > 32; c = getchar()) x = x * 10 + c -  0 ; n   if (Minus) x = -x; n } n char getc() { n   char c; n   for (c = getchar(); c <= 32; c = getchar()) n     ; n   return c; n } n int CI(int &_x) { return scanf( %d , &_x); } n int CI(int &_x, int &_y) { return scanf( %d %d , &_x, &_y); } n int CI(int &_x, int &_y, int &_z) { return scanf( %d %d %d , &_x, &_y, &_z); } n int CI(int &_a, int &_b, int &_c, int &_d) { n   return scanf( %d %d %d %d , &_a, &_b, &_c, &_d); n } n template <class T1, class T2> n inline T1 UMAX(T1 &m, T2 other) { n   if (m < other) m = other; n   return m; n } n template <class T1, class T2> n inline T1 UMIN(T1 &m, T2 other) { n   if (m > other) m = other; n   return m; n } n template <class T> n string toString(T n) { n   ostringstream oss; n   oss << n; n   return oss.str(); n } n int toInt(string s) { n   int r = 0; n   istringstream sin(s); n   sin >> r; n   return r; n } n long long int toLong(string s) { n   long long int r = 0; n   istringstream sin(s); n   sin >> r; n   return r; n } n bool isVowel(char ch) { n   ch = tolower(ch); n   if (ch ==  a  || ch ==  e  || ch ==  i  || ch ==  o  || ch ==  u ) n     return true; n   return false; n } n bool isUpper(char c) { return c >=  A  && c <=  Z ; } n bool isLower(char c) { return c >=  a  && c <=  z ; } n int dr8[8] = {+1, -1, +0, +0, +1, -1, -1, +1}; n int dc8[8] = {+0, +0, -1, +1, +1, +1, -1, -1}; n int dr4[4] = {+0, +0, +1, -1}; n int dc4[4] = {-1, +1, +0, +0}; n int kn8r[8] = {+1, +2, +2, +1, -1, -2, -2, -1}; n int kn8c[8] = {+2, +1, -1, -2, -2, -1, +1, +2}; n const double EPS = 1e-9; n const int INF = (1 << 30) - 1; n const long long int LINF = (1ll << 62) - 1; n const int mod = (int)1e9 + 7; n const int MAX = (int)1e5; n int N, M, X; n int main() { n   if (deb_mode) srand(int(time(NULL))); n   int i, j, k, l, n, m, q, a, b, c; n   cin >> N >> M >> X; n   X--; n   if (N > M) { n     cout <<  0 n ; n     return 0; n   } n   int DP[2][N + 5][N + 5]; n   memset(DP, 0, sizeof(DP)); n   DP[M & 1][N][0] = 1; n   int posNow, posPrev; n   for (int pos = M; pos >= 0; pos--) { n     posNow = pos & 1; n     posPrev = (pos - 1) & 1; n     for (i = 0; i < N + 1; i++) n       for (j = 0; j < N + 1; j++) DP[posPrev][i][j] = 0; n     for (int seg = 0; seg <= N; seg++) { n       for (int open = 0; open <= N; open++) { n         if (open) n           DP[posPrev][seg][open - 1] = n               (DP[posPrev][seg][open - 1] + DP[posNow][seg][open]) % mod; n         if (pos - 1 != X && seg) n           DP[posPrev][seg - 1][open + 1] = n               (DP[posPrev][seg - 1][open + 1] + DP[posNow][seg][open]) % mod; n         if (seg) n           DP[posPrev][seg - 1][open] = n               (DP[posPrev][seg - 1][open] + DP[posNow][seg][open]) % mod; n         if (pos - 1 != X) n           DP[posPrev][seg][open] = n               (DP[posPrev][seg][open] + DP[posNow][seg][open]) % mod; n       } n     } n   } n   long long int ANS = DP[posNow][0][0]; n   for (i = 1; i <= N; i++) ANS = (ANS * i) % mod; n   cout << ANS <<   n ; n   if (deb_mode) n     cerr <<  EXECUTION TIME =   << (1.0 * clock()) / CLOCKS_PER_SEC n          <<   SECONDS n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   while (scanf( %d , &n) != EOF) { n     for (int i = 0; i <= n; i++) { n       int space = (n - i) * 2; n       for (int j = 0; j < space; j++) printf(   ); n       if (!i) n         printf( %d n , 0); n       else { n         for (int j = 0; j <= i; j++) printf( %d  , j); n         for (int j = i - 1; j > 0; j--) printf( %d  , j); n         printf( %d n , 0); n       } n     } n     for (int i = n - 1; i >= 0; i--) { n       int space = (n - i) * 2; n       for (int j = 0; j < space; j++) printf(   ); n       if (!i) n         printf( %d n , 0); n       else { n         for (int j = 0; j <= i; j++) printf( %d  , j); n         for (int j = i - 1; j > 0; j--) printf( %d  , j); n         printf( %d n , 0); n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, l, r, x, y, o, e, w, z, b[50000], aa, bb, ans; n vector<int> vec; n map<int, int> ma; n int main() { n   ios_base ::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   cin >> l >> r >> x >> y; n   if (y % x != 0) { n     cout << 0 << endl; n     return 0; n   } else n     y /= x; n   for (int i = 2; i * i <= y; i++) n     if (y % i == 0) { n       vec.push_back(i); n       while (y % i == 0) { n         y /= i; n         ma[i]++; n       } n     } n   if (y > 1) { n     vec.push_back(y); n     ma[y]++; n   } n   z = vec.size(); n   for (int i = 0; i < (1 << z); i++) { n     w = i; n     for (int j = 0; j < z; j++) b[j] = 0; n     o = 0; n     while (w) { n       b[o] = w & 1; n       w >>= 1; n       o++; n     } n     aa = bb = 1; n     for (int j = 0; j < z; j++) n       if (b[j] == 1) { n         e = ma[vec[j]]; n         for (int h = 1; h <= e; h++) aa *= vec[j]; n       } else { n         e = ma[vec[j]]; n         for (int h = 1; h <= e; h++) bb *= vec[j]; n       } n     if (l <= aa * x && aa * x <= r && l <= bb * x && bb * x <= r) ans++; n   } n   cout << ans << endl; n   return 0; n } n


#include<bits/stdc++.h>  n using namespace std;  n #define ll long long n int main() { n  ll k,l,r,t,x,y; n  cin>>k>>l>>r>>t>>x>>y; n  if(k<l || k>r) { n      cout<< No <<endl; return 0; n  } n  if(x>y) { n      if(k+y>r) k-=x; t--; n      if(k<l) return cout<< No <<endl,0; n      if((k-l)/(x-y) < t ) { n          cout<< No <<endl; return 0; n      } n      cout<< Yes <<endl; return 0; n  } n  else { n      vector<bool> was(x,false); n      while(t>0) { n          if(was[k%x]) return cout<< Yes <<endl,0; n          was[k%x]=true; n          ll remd=min(t,(k-l)/x); n          k-=remd*x; n          t-=remd; n          if(t==0) return cout<< Yes <<endl,0; n          t--; n          if(k+y<=r) k+=y; n          k=k-x; n          if(k<l || k>r) return cout<< No <<endl,0; n      } n      cout<< Yes <<endl; n  } n  return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = (int)3e5 + 99; n const long long INF = (long long)1e18 + 100; n int a[N]; n int b[N]; n long long dp[N][3]; n int n; n long long calc(long long add, long long pos) { n   long long &res = dp[pos][add]; n   if (res != -1) return res; n   res = INF; n   if (pos == n) return res = 0; n   for (long long x = 0; x <= 2; x++) { n     if (pos == 0 || a[pos] + x != a[pos - 1] + add) n       res = min(res, calc(x, pos + 1) + x * (b[pos])); n   } n   return res; n } n void Solve() { n   cin >> n; n   for (int i = 0; i < n; i++) cin >> a[i] >> b[i]; n   for (int i = 0; i <= n; i++) dp[i][0] = dp[i][1] = dp[i][2] = -1; n   cout << calc(0, 0) <<   n ; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(NULL); n   int t = 1; n   cin >> t; n   while (t--) { n     Solve(); 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 s; n   cin >> s; n   int cnt = 0; n   for (int i = 0; i < n; i++) { n     if (s[i] ==  + ) { n       cnt++; n     } else if (s[i] ==  -  && cnt) { n       cnt--; n     } n   } n   cout << cnt << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool judge(int key) { n   for (int i = 2; i * i <= key; i++) { n     if (key % i == 0) return false; n   } n   return true; n } n int main() { n   int n; n   scanf( %d , &n); n   if (n & 1 || n == 2) { n     if (judge(n)) n       printf( 1 n ); n     else if (judge(n - 2)) n       printf( 2 n ); n     else n       printf( 3 n ); n   } else n     printf( 2 n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> v[3001]; n int size1[3001]; n map<vector<int>, int> mm; n long dis[3001][3001]; n void dijkstra(int n) { n   priority_queue<vector<int>> pq; n   vector<int> p(3, 0), p1(3); n   p[0] = 0; n   p[2] = 1; n   pq.push(p); n   long size = 1; n   while (size) { n     p = pq.top(); n     pq.pop(); n     --size; n     if ((dis[p[2]][p[1]] > p[0]) && (dis[p[2]][p[1]] != 0)) { n       continue; n     } n     if (p[2] == n) return; n     for (int i = 0; i < size1[p[2]]; ++i) { n       p1[0] = p[1]; n       p1[1] = p[2]; n       p1[2] = v[p[2]][i]; n       if (mm[p1] == 1) continue; n       if ((dis[p1[2]][p1[1]] < dis[p[2]][p[1]] - 1) || n           (dis[p1[2]][p1[1]] == 0)) { n         dis[p1[2]][p1[1]] = dis[p[2]][p[1]] - 1; n         p1[0] = dis[p1[2]][p1[1]]; n         pq.push(p1); n         ++size; n         if ((p1[2] == n) && (p1[0] == -1)) return; n       } n     } n   } n } n int main() { n   int n, m, a, b, c, k; n   cin >> n >> m >> k; n   vector<int> arr(3); n   for (int i = 0; i < m; ++i) { n     scanf( %d %d , &a, &b); n     v[a].emplace_back(b); n     size1[a]++; n     v[b].emplace_back(a); n     size1[b]++; n   } n   for (int i = 0; i < k; ++i) { n     scanf( %d %d %d , &arr[0], &arr[1], &arr[2]); n     mm[arr] = 1; n   } n   dijkstra(n); n   long maxim = 0; n   int maximindex = 0; n   for (int i = 1; i <= n; ++i) { n     if (dis[n][i] == 0) { n       continue; n     } n     if ((dis[n][i] > maxim) || (maxim == 0)) { n       maxim = dis[n][i]; n       maximindex = i; n     } n   } n   if (maxim == 0) { n     cout <<  -1  << endl; n     return 0; n   } n   int i = n; n   int j = maximindex; n   stack<int> s; n   s.push(i); n   long ans = 1; n   int size2 = 1; n   i = maximindex; n   maxim++; n   while (maxim < 0) { n     for (int j = 1; j <= n; ++j) { n       if (dis[i][j] == 0) continue; n       if (dis[i][j] == maxim) { n         maximindex = j; n         break; n       } n     } n     ++ans; n     s.push(i); n     ++size2; n     maxim++; n     i = maximindex; n   } n   cout << ans << endl; n   cout <<  1  n        <<    ; n   while (size2) { n     printf( %d  , s.top()); n     s.pop(); n     --size2; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int t, a[2000 + 10][2000 + 10], ans[2000 + 10][2000 + 10], viz[30]; n pair<int, int> fs[30], ls[30]; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   cin >> t; n   while (t--) { n     int n, m, l = 0; n     pair<int, int> aux = {0, 0}; n     cin >> n >> m; n     for (int i = 1; i <= 26; i++) viz[i] = 0, fs[i] = {0, 0}, ls[i] = {0, 0}; n     for (int i = 1; i <= n; i++) { n       string s; n       cin >> s; n       for (int j = 0; j < m; j++) { n         if (s[j] >=  a  && s[j] <=  z ) n           a[i][j + 1] = s[j] -  a  + 1; n         else n           a[i][j + 1] = 0; n       } n     } n     for (int ch = 1; ch <= 26; ch++) n       for (int i = 1; i <= n && !viz[ch]; i++) n         for (int j = 1; j <= m && !viz[ch]; j++) n           if (a[i][j] == ch) { n             viz[ch] = 1; n             fs[ch] = {i, j}; n             int j1 = j + 1, i1 = i + 1, ok = 0; n             while (j1 <= m) { n               if (a[i][j1] == ch) ok = 1, ls[ch] = {i, j1}; n               j1++; n             } n             while (i1 <= n) { n               if (a[i1][j] == ch) ok = 1, ls[ch] = {i1, j}; n               i1++; n             } n             if (!ok) ls[ch] = fs[ch]; n             l = ch; n             aux = fs[ch]; n           } n     for (int i = 1; i <= l; i++) { n       if (!fs[i].first) { n         fs[i] = aux; n         ls[i] = aux; n       } n       for (int i1 = fs[i].first; i1 <= ls[i].first; i1++) n         for (int j1 = fs[i].second; j1 <= ls[i].second; j1++) ans[i1][j1] = i; n     } n     int ok = 1; n     for (int i = 1; i <= n; i++) n       for (int j = 1; j <= m; j++) n         if (ans[i][j] != a[i][j]) ok = 0; n     for (int i = 1; i <= n; i++) n       for (int j = 1; j <= m; j++) a[i][j] = ans[i][j] = 0; n     if (!ok) { n       cout <<  NO  <<   n ; n       continue; n     } n     cout <<  YES  <<   n ; n     cout << l <<   n ; n     for (int i = 1; i <= l; i++) n       cout << fs[i].first <<     << fs[i].second <<     << ls[i].first <<     n            << ls[i].second <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n const int N = 35; n int n, m; n int A[N][N], F[N][N]; n int main() { n   scanf( %d , &n); n   m = (n + 1) >> 1; n   int ans = 0; n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= n; j++) { n       scanf( %d , &A[i][j]); n       ans += A[i][j]; n     } n   for (int i = 1; i <= n; i++) n     for (int j = 1; j <= n; j++) F[i][j] = 1; n   for (int stat = 0; stat < 1 << m; stat++) { n     int sum = 0; n     for (int i = 1; i <= m; i++) { n       F[m][i] = (stat >> (i - 1) & 1) ? -1 : 1; n       sum += (A[m][i] * F[m][i]); n     } n     for (int i = m + 1; i <= n; i++) { n       F[m][i] = F[m][i - m] * F[m][m]; n       sum += (A[m][i] * F[m][i]); n     } n     for (int i = 1; i < m; i++) { n       int s, ti = i + m; n       for (int j = 0; j < 2; j++, F[i][m] *= -1) { n         F[i + m][m] = F[i][m] * F[m][m]; n         int t = (A[i][m] * F[i][m]) + (A[i + m][m] * F[i + m][m]); n         for (int k = 1; k < m; k++) { n           int tk = k + m; n           F[i][tk] = F[i][k] * F[i][m]; n           F[ti][k] = F[i][k] * F[m][k]; n           F[ti][tk] = F[i][tk] * F[m][tk]; n           t += fabs((A[i][k] * F[i][k]) + (A[i][tk] * F[i][tk]) + n                     (A[ti][k] * F[ti][k]) + (A[ti][tk] * F[ti][tk])); n         } n         if (!j || t > s) s = t; n       } n       sum += s; n     } n     if (sum > ans) ans = sum; n   } n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 9e2 + 1; n int n, m, g[maxn], G, o1[maxn], o2[maxn], deg[maxn]; n vector<int> e[maxn], e_s[maxn], r_e_s[maxn], topo, ans, wow[maxn]; n vector<pair<int, int> > edge, res; n bool mark[maxn]; n map<int, int> is[maxn]; n void dfs(int v) { n   mark[v] = 1; n   for (auto u : e[v]) { n     if (is[v][u] == 0) { n       e_s[v].push_back(u); n       r_e_s[u].push_back(v); n       is[v][u] = 1; n       is[u][v] = 1; n     } n     if (mark[u] == 0) { n       dfs(u); n     } n   } n } n void topol(int v) { n   mark[v] = 1; n   for (auto u : e_s[v]) { n     if (mark[u] == 0) { n       topol(u); n     } n   } n   topo.push_back(v); n } n void col(int v) { n   mark[v] = 1; n   g[v] = G; n   o2[G] = v; n   for (auto u : r_e_s[v]) { n     if (mark[u] == 0) { n       col(u); n     } n   } n   return; n } n void Last_one(int v) { n   mark[v] = 1; n   for (auto u : wow[v]) { n     if (mark[u] == 0) { n       Last_one(u); n     } n   } n   if (deg[v] == 1) { n     ans.push_back(v); n   } n   return; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cin >> n >> m; n   if (n == 2) { n     cout << -1 << endl; n     return 0; n   } n   for (int i = 0; i < m; i++) { n     int t1, t2; n     cin >> t1 >> t2; n     e[t1].push_back(t2); n     e[t2].push_back(t1); n     edge.push_back({t1, t2}); n   } n   dfs(1); n   for (int i = 1; i <= n; i++) { n     mark[i] = 0; n   } n   topol(1); n   for (int i = 1; i <= n; i++) { n     mark[i] = 0; n   } n   reverse(topo.begin(), topo.end()); n   G = 1; n   for (auto u : topo) { n     if (mark[u] == 0) { n       o1[G] = u; n       col(u); n       G++; n     } n   } n   for (auto tmp : edge) { n     if (g[tmp.first] != g[tmp.second]) { n       deg[g[tmp.first]]++; n       deg[g[tmp.second]]++; n       wow[g[tmp.first]].push_back(g[tmp.second]); n       wow[g[tmp.second]].push_back(g[tmp.first]); n     } n   } n   if (G == 3) { n     ans.push_back(1); n     ans.push_back(2); n   } else { n     for (int i = 1; i <= n; i++) { n       mark[i] = 0; n     } n     for (int i = 1; i < G; i++) { n       if (deg[i] >= 2) { n         Last_one(i); n         break; n       } n     } n   } n   for (int i = 0; i < ((int)ans.size() + 1) / 2; i++) { n     int t1 = ans[i]; n     int t2 = ans[i + (ans.size()) / 2]; n     if (is[o1[t1]][o1[t2]] == 0) { n       res.push_back({o1[t1], o1[t2]}); n     } else { n       res.push_back({o2[t1], o2[t2]}); n     } n   } n   cout << res.size() << endl; n   for (auto u : res) { n     cout << u.first <<      << u.second << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long N, K; n long long num[3000]; n long long OAO[3000]; n bool test(long long c) { n   for (long long Ni = 0; Ni <= N; Ni++) { n     OAO[Ni] = Ni; n     for (long long Nj = 0; Nj < Ni; Nj++) { n       if (Ni != N && abs(num[Ni] - num[Nj]) > (long long)(c) * (Ni - Nj)) n         continue; n       OAO[Ni] = min(OAO[Ni], OAO[Nj] + Ni - Nj - 1); n     } n   } n   if (OAO[N] > K) n     return false; n   else n     return true; n } n int main() { n   scanf( %I64d %I64d , &N, &K); n   long long p = 0; n   for (long long Ni = 0; Ni < N; Ni++) { n     scanf( %I64d , &num[Ni]); n     if (Ni) p = max(p, (long long)abs(num[Ni] - num[Ni - 1])); n   } n   long long l = -1, r = p, mid; n   while (l + 1 != r) { n     mid = (l + r) / 2; n     if (test(mid)) n       r = mid; n     else n       l = mid; n   } n   printf( %I64d n , r); n } n


#include <bits/stdc++.h> n using namespace std; n int regions[100000][4]; n string name[100000][3]; n void compareScore(int regionNo, int score, string str) { n   if (score >= regions[regionNo][0]) { n     string tempName1 = name[regionNo][0]; n     string tempName2 = name[regionNo][1]; n     int tempScore1 = regions[regionNo][0]; n     int tempScore2 = regions[regionNo][1]; n     regions[regionNo][0] = score; n     name[regionNo][0] = str; n     regions[regionNo][1] = tempScore1; n     regions[regionNo][2] = tempScore2; n     name[regionNo][1] = tempName1; n     name[regionNo][2] = tempName2; n   } else if (score >= regions[regionNo][1]) { n     string tempName2 = name[regionNo][1]; n     int tempScore2 = regions[regionNo][1]; n     regions[regionNo][1] = score; n     name[regionNo][1] = str; n     regions[regionNo][2] = tempScore2; n     name[regionNo][2] = tempName2; n   } else if (score >= regions[regionNo][2]) { n     regions[regionNo][2] = score; n     name[regionNo][2] = str; n   } n   if (!name[regionNo][1].empty() && !name[regionNo][2].empty() && n       regions[regionNo][1] == regions[regionNo][2]) { n     regions[regionNo][3] = -1; n   } else { n     regions[regionNo][3] = 1; n   } n } n void solve(int n, int m) { n   for (int i = 0; i < n; i++) { n     string str; n     int regionNo, score; n     cin >> str >> regionNo >> score; n     compareScore(regionNo, score, str); n   } n   for (int i = 1; i <= m; i++) { n     if (regions[i][3] == 1) { n       cout << name[i][0] <<     << name[i][1] << endl; n     } else { n       cout <<  ?  << endl; n     } n   } n } n int main() { n   int n, m; n   cin >> n >> m; n   solve(n, m); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n signed main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   long long t; n   cin >> t; n   while (t--) { n     long long n, sum = 0; n     cin >> n; n     vector<long long> v(n), ans, odd; n     for (long long i = 0; i < n; i++) { n       cin >> v[i]; n       if (v[i] % 2 == 0) { n         ans.push_back(i); n       } else n         odd.push_back(i); n       sum += v[i]; n     } n     long long count = 0; n     for (long long i = 2; i * i <= sum; i++) { n       if (sum % i == 0) count++; n     } n     if (count > 0) { n       cout << n << endl; n       for (long long i = 0; i < n; i++) cout << i + 1 <<    ; n     } else { n       cout << n - 1 << endl; n       odd.pop_back(); n       for (long long i = 0; i < ans.size(); i++) { n         cout << ans[i] + 1 <<    ; n       } n       for (long long i = 0; i < odd.size(); i++) { n         cout << odd[i] + 1 <<    ; n       } n     } n     cout << endl; n   } n } n


#include <bits/stdc++.h> n int main() { n   int n; n   char a[20]; n   scanf(  %d , &n); n   scanf(  %s , a); n   char num[10]; n   for (int i = 2; i < 10; i++) { n     int c = 0; n     for (int j = 0; a[j]; j++) n       if (a[j] >= i +  0 ) c++; n     num[i] = c; n   } n   if (num[7] > 0) { n     for (int i = 2; i < 7; i++) { n       num[i] -= num[7]; n     } n     while (num[7]--) printf( 7 ); n   } n   if (num[5] > 0) { n     for (int i = 2; i < 5; i++) { n       num[i] -= num[5]; n     } n     while (num[5]--) printf( 5 ); n   } n   num[3] += num[6]; n   num[3] += num[9] * 2; n   num[2] += num[6]; n   num[2] += num[4] * 2; n   num[2] += num[8] * 3; n   num[2] -= num[3]; n   while (num[3]--) printf( 3 ); n   while (num[2]--) printf( 2 ); n   printf(  n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INFINITE = (int)(0xffffffff >> 2); n int n; n int gs[600]; n int dp[600][600]; n int run(int l, int r) { n   if (l > r) return 0; n   if (l == r) return 1; n   if (dp[l][r] != INFINITE) { n     return dp[l][r]; n   } n   dp[l][r] = min(dp[l][r], run(l + 1, r) + 1); n   for (int k = l + 2; k <= r; k++) { n     if (gs[l] == gs[k]) { n       dp[l][r] = min(dp[l][r], run(l + 1, k - 1) + run(k + 1, r)); n     } n   } n   if (gs[l] == gs[l + 1]) { n     dp[l][r] = min(dp[l][r], run(l + 2, r) + 1); n     return dp[l][r]; n   } n   return dp[l][r]; n } n int main() { n   cin >> n; n   for (int i = 1; i <= n; i++) cin >> gs[i]; n   for (int i = 0; i < 600; i++) { n     int *row = dp[i]; n     for (int j = 0; j < 600; j++) { n       row[j] = INFINITE; n     } n   } n   cout << run(1, n) << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void err(istream_iterator<string> it) { cerr << endl; } n template <typename T, typename... Args> n void err(istream_iterator<string> it, T a, Args... args) { n   cerr << *it <<   =   << a <<   ,  ; n   err(++it, args...); n } n namespace fastIO { n bool IOerror = 0; n inline char nc() { n   static char buf[100000], *p1 = buf + 100000, *pend = buf + 100000; n   if (p1 == pend) { n     p1 = buf; n     pend = buf + fread(buf, 1, 100000, stdin); n     if (pend == p1) { n       IOerror = 1; n       return -1; n     } n   } n   return *p1++; n } n inline bool blank(char ch) { n   return ch ==     || ch ==   n  || ch ==   r  || ch ==   t ; n } n inline void read(int &x) { n   char ch; n   while (blank(ch = nc())) n     ; n   if (IOerror) return; n   for (x = ch -  0 ; (ch = nc()) >=  0  && ch <=  9 ; x = x * 10 + ch -  0 ) n     ; n } n }  // namespace fastIO n using namespace fastIO; n const double PI = acos(-1.0); n const double eps = 1e-8; n const int maxn = 3e5 + 7; n const int N = 1e4 + 10; n const int mod = 998244353; n long long qp(long long b, long long n) { n   long long r = 1; n   if (n < 0) n += mod - 1; n   b %= mod; n   for (; n; n >>= 1, b = b * b % mod) n     if (n & 1) r = r * b % mod; n   return r; n } n int sgn(double x) { n   if (x < -eps) return -1; n   return x > eps ? 1 : 0; n } n int n; n long long dp[3][N]; n long long sum[N], suf[N]; n int a[N]; n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; ++i) scanf( %d , &a[i]); n   sort(a + 1, a + 1 + n); n   long long _c2 = (n * (n - 1) / 2); n   for (int i = 1; i <= n; ++i) { n     for (int j = i + 1; j <= n; ++j) { n       dp[0][a[j] - a[i]]++; n     } n   } n   for (int i = 1; i <= n; ++i) { n     for (int j = i + 1; j <= n; ++j) { n       dp[1][a[j] - a[i]]++; n     } n   } n   for (int i = 1; i <= 10000; ++i) { n     for (int j = 1; j < i; ++j) { n       int k = i - j; n       dp[2][i] += dp[0][j] * dp[1][k]; n     } n     sum[i] = sum[i - 1] + dp[2][i]; n   } n   double ans = 0; n   for (int i = 10000; i >= 1; --i) { n     ans += sum[i - 1] * dp[0][i]; n   } n   printf( %.12lf n , 1.0 * ans / _c2 / _c2 / _c2); n } n


#include <bits/stdc++.h> n using namespace std; n const int oo = 2139063143; n const int N = 1010000; n const int P = 1000000007; n const long double eps = 1e-7; n template <typename T> n inline void sc(T &x) { n   x = 0; n   static int p; n   p = 1; n   static char c; n   c = getchar(); n   while (!isdigit(c)) { n     if (c ==  - ) p = -1; n     c = getchar(); n   } n   while (isdigit(c)) { n     x = (x << 1) + (x << 3) + (c - 48); n     c = getchar(); n   } n   x *= p; n } n template <typename T> n inline void print(T x) { n   if (x < 0) putchar( - ), x = -x; n   if (x >= 10) print(x / 10); n   putchar(x % 10 +  0 ); n } n template <typename T> n inline void pr(T x) { n   print(x), putchar(  n ); n } n template <typename T1, typename T2> n void chkmax(T1 &A, T2 B) { n   A = A >= B ? A : B; n } n template <typename T1, typename T2> n void chkmin(T1 &A, T2 B) { n   A = A <= B ? A : B; n } n const long double PI = acos(-1); n int n, m; n struct po { n   long double x, y; n   po(long double xx = 0, long double yy = 0) { x = xx, y = yy; } n } a[N], s[N]; n po operator+(po A, po B) { return po(A.x + B.x, A.y + B.y); } n po operator-(po A, po B) { return po(A.x - B.x, A.y - B.y); } n long double operator*(po A, po B) { return A.x * B.y - A.y * B.x; } n po operator*(po A, long double B) { return po(A.x * B, A.y * B); } n po operator*(long double B, po A) { return po(A.x * B, A.y * B); } n long double triangle(po A, po B, po C) { return abs((B - A) * (C - A)) / 2; } n long double area() { n   long double g = a[n] * a[1]; n   for (int i = 1; i < n; i++) g += a[i] * a[i + 1]; n   return abs(g) / 2; n } n po core(po A, po B, po C) { return (A + B + C) * (1. / 3); } n po O; n void core() { n   long double S = area(); n   for (int i = 2; i < n; i++) n     O = O + (triangle(a[1], a[i], a[i + 1]) / S) * core(a[1], a[i], a[i + 1]); n } n long double S(long double A) { return A * A; } n long double getlen(po A) { return sqrt(S(A.x) + S(A.y)); } n long double len[N], b[N]; n long double atan2(po A) { return atan2(A.y, A.x); } n po rotate(po A, long double x) { n   long double s = sin(x), c = cos(x); n   return po(A.x * c - A.y * s, A.x * s + A.y * c); n } n int ia = 1, ib = 2; n po A, B, p; n po getpos(int i) { return O + rotate(s[i], b[0] - b[ia]); } n int main() { n   sc(n), sc(m); n   for (int i = 1; i <= n; i++) { n     int x, y; n     sc(x), sc(y); n     a[i] = po(x, y); n   } n   core(); n   for (int i = 1; i <= n; i++) n     s[i] = a[i] - O, len[i] = getlen(s[i]), b[i] = atan2(s[i]); n   b[0] = atan2(po(0, 1)); n   A = a[1], B = a[2]; n   bool fg = 0; n   while (m--) { n     int op, x, y; n     sc(op), sc(x); n     if (op == 1) { n       sc(y); n       if (ia == x) swap(ia, ib), swap(A, B); n       O = po(A.x, A.y - len[ia]); n       ib = y, B = getpos(ib); n       fg = 1; n     } else { n       if (fg) n         p = getpos(x), printf( %.9Lf %.9Lf n , p.x, p.y); n       else n         printf( %.9Lf %.9Lf n , a[x].x, a[x].y); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n int n, k, a, b, p, na; n std::vector<int> avg; n long long f(int l, int r) { n   auto it1 = std::upper_bound(avg.begin(), avg.end(), r); n   auto it2 = std::lower_bound(avg.begin(), avg.end(), l); n   if (it2 != avg.end()) n     na = it1 - it2; n   else n     na = 0; n   long long ans; n   if (na) n     ans = 1LL * b * na * (r - l + 1); n   else n     ans = a; n   if (na && r != l) n     ans = std::min(ans, f(l, (l + r) / 2) + f((l + r) / 2 + 1, r)); n   return ans; n } n int main() { n   scanf( %d%d%d%d , &n, &k, &a, &b); n   for (int i = 0; i < k; i++) { n     scanf( %d , &p); n     avg.push_back(p - 1); n   } n   std::sort(avg.begin(), avg.end()); n   printf( %lld n , f(0, (1 << n) - 1)); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void fast() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n } n const long long INFll = 1ll * 1000000000 * 1000000000; n const long double PI = n     3.141592653589793238462643383279502884197169399375105820974944; n int mul(int a, int b, int mod = 1000000007) { return int(a * 1ll * b % mod); } n int norm(int a, int mod = 1000000007) { n   while (a >= mod) a -= mod; n   while (a < 0) a += mod; n   return a; n } n int powmod(int x, int y, int mod = 1000000007) { n   int res = 1; n   while (y > 0) { n     if (y & 1) res = mul(res, x, mod); n     x = mul(x, x, mod); n     y = y >> 1; n   } n   return res; n } n int inv(int a, int mod = 1000000007) { return powmod(a, mod - 2); } n int main() { n   fast(); n   int n; n   cin >> n; n   vector<int> dp((1 << 22), -1), a(n); n   for (int i = 0; i < n; i++) { n     cin >> a[i]; n     dp[a[i]] = a[i]; n   } n   int p = (1 << 22); n   for (int i = 0; i < p; i++) { n     if (dp[i] != -1) n       for (int j = 0; j < 22; j++) { n         if ((i & (1 << j)) == 0) { n           dp[i | (1 << j)] = dp[i]; n         } n       } n   } n   for (int i = 0; i < n; i++) { n     cout << dp[(1 << 22) - 1 - a[i]] <<    ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0}; n const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, n           ddy[8] = {-1, -1, 0, 1, 1, 1, 0, -1}; n const int nx[8] = {1, 2, 2, 1, -1, -2, -2, -1}, n           ny[8] = {-2, -1, 1, 2, 2, 1, -1, -2}; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   ; n   int t = 1; n   cin >> t; n   while (t--) { n     int n, k; n     string s; n     cin >> n >> k >> s; n     bool ans = true; n     for (int i = 0; i < k; i++) { n       bool ze = true, on = true; n       for (int j = i; j < n; j += k) { n         if (s[j] ==  0 ) on = false; n         if (s[j] ==  1 ) ze = false; n       } n       if (ze && !on) { n         for (int j = i; j < n; j += k) s[j] =  0 ; n       } n       if (!ze && on) { n         for (int j = i; j < n; j += k) s[j] =  1 ; n       } n       if (!ze && !on) { n         ans = false; n       } n     } n     int ze = 0, on = 0, qu = 0; n     for (int i = 0; i < k; i++) { n       if (s[i] ==  0 ) ze += 1; n       if (s[i] ==  1 ) on += 1; n       if (s[i] ==  ? ) qu += 1; n     } n     if (ze > k / 2 || on > k / 2) ans = false; n     cout << (ans ?  YES  :  NO ); n   done:; n     cout <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n inline void io() {} n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(); n   cout.tie(); n   cout << fixed << setprecision(8); n   long long int n, a, b, c = 0, k; n   cin >> a >> b >> n; n   for (int i = 0; i < 10; i++) { n     if (((a * 10) + i) % b == 0) { n       c++; n       k = (a * 10) + i; n       break; n     } n   } n   if (c == 1) { n     cout << k; n     for (int i = 1; i < n; i++) { n       cout <<  0 ; n     } n   } else { n     cout <<  -1 ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, pos; n   cin >> n; n   int arr[n + 1]; n   for (int i = 1; i <= n; i++) { n     cin >> pos; n     arr[pos] = i; n   } n   for (int i = 1; i <= n; i++) cout << arr[i] <<    ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   cin >> t; n   while (t--) { n     long long int a, b, n; n     cin >> a >> b >> n; n     long long int cnt = 0; n     while (1) { n       if (b > a) { n         a += b; n         cnt++; n       } else { n         b += a; n         cnt++; n       } n       if (a > n || b > n) break; n     } n     cout << cnt << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, k; n   cin >> n >> k; n   vector<int> joy; n   while (n > 0) { n     int f, t; n     cin >> f >> t; n     if (t > k) f = f - t + k; n     joy.push_back(f); n     n--; n   } n   sort(joy.begin(), joy.end()); n   cout << joy.back(); n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> v; n long long int arr[100001], operation[100001][3], kitnibaar1[100002], n     kitnibaar[100002], update1[100002], update[100002]; n int main() { n   int n, m, k; n   cin >> n >> m >> k; n   for (int i = 1; i <= n; i++) { n     cin >> arr[i]; n   } n   for (int i = 1; i <= m; i++) { n     cin >> operation[i][0]; n     cin >> operation[i][1]; n     cin >> operation[i][2]; n   } n   for (int i = 1; i <= k; i++) { n     int start, end; n     cin >> start >> end; n     kitnibaar1[start]++; n     kitnibaar1[end + 1]--; n   } n   long long int up = 0; n   for (int i = 1; i <= m; i++) { n     up += kitnibaar1[i]; n     kitnibaar[i] += up; n   } n   up = 0; n   for (int i = 1; i <= m; i++) { n     operation[i][2] *= kitnibaar[i]; n     update[operation[i][0]] += operation[i][2]; n     update[operation[i][1] + 1] -= operation[i][2]; n   } n   up = 0; n   for (int i = 1; i <= n; i++) { n     up += update[i]; n     arr[i] += up; n     cout << arr[i] <<    ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 400010; n int n, ans[N], where[N]; n long long sz[N]; n vector<int> v[N]; n bool visit[N]; n void init() { n   scanf( %d , &n); n   int a, b; n   for (int i = 0; i < n - 1; ++i) { n     scanf( %d %d , &a, &b); n     v[a].push_back(b); n     v[b].push_back(a); n   } n } n void dfs(int now) { n   visit[now] = true; n   for (int i = 0; i < v[now].size(); ++i) n     if (!visit[v[now][i]]) { n       dfs(v[now][i]); n       sz[now] += sz[v[now][i]]; n     } n   if (sz[now] == 0) n     sz[now] = 1; n   else n     sz[now] += 1; n } n int find_centroid(int now) { n   visit[now] = true; n   for (int i = 0; i < v[now].size(); ++i) { n     if (visit[v[now][i]]) continue; n     if (sz[v[now][i]] > n / 2) return find_centroid(v[now][i]); n   } n   return now; n } n void sv(int now, int value) { n   if (visit[now]) return; n   visit[now] = true; n   where[now] = value; n   for (int i = 0; i < v[now].size(); ++i) sv(v[now][i], value); n } n void dfs2(int now) { n   visit[now] = true; n   for (int i = 0; i < v[now].size(); ++i) sv(v[now][i], i); n } n void solve() { n   dfs(1); n   for (int i = 1; i <= n; ++i) visit[i] = false; n   int centroid = find_centroid(1); n   for (int i = 1; i <= n; ++i) visit[i] = false; n   dfs2(centroid); n   for (int i = 1; i <= n; ++i) { n     visit[i] = false; n     sz[i] = 0; n   } n   dfs(centroid); n   vector<int> tmp; n   for (int i = 0; i < v[centroid].size(); ++i) n     tmp.push_back(sz[v[centroid][i]]); n   int max1 = -1000000006, idx1, max2 = -1000000006, idx2; n   for (int i = 0; i < tmp.size(); ++i) n     if (tmp[i] > max1) { n       max1 = tmp[i]; n       idx1 = i; n     } n   if ((n % 2 == 0) && max1 == n / 2) n     max2 = n / 2; n   else { n     for (int i = 0; i < tmp.size(); ++i) n       if (tmp[i] > max2 && i != idx1) { n         max2 = tmp[i]; n         idx2 = i; n       } n   } n   for (int i = 1; i <= n; ++i) { n     if (i == centroid) n       ans[i] = 1; n     else if (where[i] == idx1) { n       int tmp = n - sz[i] - max2; n       if (tmp <= n / 2) n         ans[i] = 1; n       else n         ans[i] = 0; n     } else { n       int tmp = n - sz[i] - max1; n       if (tmp <= n / 2) n         ans[i] = 1; n       else n         ans[i] = 0; n     } n   } n   for (int i = 1; i <= n; ++i) printf( %d  , ans[i]); n   printf(  n ); n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   ; n   int __ = 1; n   while (__--) { n     init(); n     solve(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int oo = 0x3f3f3f3f; n const long long ooo = 9223372036854775807ll; n const int _cnt = 1000 * 1000 + 7; n const int _p = 1000 * 1000 * 1000 + 7; n const int N = 1001005; n const double PI = acos(-1.0); n const double eps = 1e-9; n int o(int x) { return x % _p; } n int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } n int lcm(int a, int b) { return a / gcd(a, b) * b; } n void file_put() { n   freopen( filename.in ,  r , stdin); n   freopen( filename.out ,  w , stdout); n } n long long a, b, p, x, r[N], tt = 1, q[N], x0, ans = 0, T = 1, T_rev; n bool v[N]; n long long Pow(long long x, long long k) { n   long long ans = 1; n   for (; k; k >>= 1, (x *= x) %= p) n     if (k & 1) (ans *= x) %= p; n   return ans; n } n int main() { n   scanf( %I64d%I64d%I64d%I64d , &a, &b, &p, &x); n   if (a == 1) n     if (x < b) n       return 0 * printf( 0 n ); n     else n       return 0 * printf( %I64d n , (x - b) / p + 1); n   v[1] = 1; n   while (1) { n     (tt *= a) %= p; n     if (v[tt]) break; n     v[tt] = 1; n     T++; n   } n   r[1] = tt = 1; n   for (int i = (1); i <= (T - 1); ++i) q[(tt *= a) %= p] = i; n   q[1] = 0; n   T_rev = Pow(T, p - 2); n   for (int i = (2); i <= (p - 1); ++i) r[i] = (p - p / i) * r[p % i] % p; n   for (int i = (1); i <= (p - 1); ++i) { n     if (i > 1 && !q[i]) continue; n     long long t = i; n     x0 = (r[t] * b % p * T * T_rev + q[t] * p) % (p * T); n     if (x < x0) continue; n     ans += (x - x0) / (p * T) + 1; n   } n   printf( %I64d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   char str[200]; n   int num, i, j, k; n   int pre = 0; n   char temp[10]; n   cin.getline(str, 200,   n ); n   for (i = 0; str[i] != 0; i++) { n     num = str[i]; n     j = 0; n     while (num != 0) { n       k = num % 2; n       temp[j++] = k +  0 ; n       num = (num - k) / 2; n     } n     while (j < 8) temp[j++] =  0 ; n     temp[j] =   0 ; n     for (j = 0; j < 8; j++) num += (temp[j] -  0 ) << (7 - j); n     k = (pre - num) % 256; n     if (k < 0) k += 256; n     cout << k << endl; n     pre = num; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct triple { n   int first; n   int second; n   int third; n   void set(int a, int b, int c) { n     first = a; n     second = b; n     third = c; n   } n }; n triple t[53][53][8] = {0}; n int table[53][53] = {0}; n void f(int a, int b, int c) { n   if (table[a][b] == 0 || b > 50 || a > 50 || a < 1 || b < 1) return; n   int x = a; n   int y = b; n   if (c == 0) { n     while (table[x - 1][y] == table[a][b]) x--; n     while (table[x][y + 1] == table[a][b]) y++; n     if (table[x][y + 1] != 0) n       t[a][b][c].set(x, y + 1, c); n     else n       t[a][b][c].set(a, b, 1); n   } else if (c == 1) { n     while (table[x + 1][y] == table[a][b]) x++; n     while (table[x][y + 1] == table[a][b]) y++; n     if (table[x][y + 1] != 0) n       t[a][b][c].set(x, y + 1, c); n     else n       t[a][b][c].set(a, b, 2); n   } else if (c == 2) { n     while (table[x + 1][y] == table[a][b]) x++; n     while (table[x][y + 1] == table[a][b]) y++; n     if (table[x + 1][y] != 0) n       t[a][b][c].set(x + 1, y, c); n     else n       t[a][b][c].set(a, b, 3); n   } else if (c == 3) { n     while (table[x + 1][y] == table[a][b]) x++; n     while (table[x][y - 1] == table[a][b]) y--; n     if (table[x + 1][y] != 0) n       t[a][b][c].set(x + 1, y, c); n     else n       t[a][b][c].set(a, b, 4); n   } else if (c == 4) { n     while (table[x + 1][y] == table[a][b]) x++; n     while (table[x][y - 1] == table[a][b]) y--; n     if (table[x][y - 1] != 0) n       t[a][b][c].set(x, y - 1, c); n     else n       t[a][b][c].set(a, b, 5); n   } else if (c == 5) { n     while (table[x - 1][y] == table[a][b]) x--; n     while (table[x][y - 1] == table[a][b]) y--; n     if (table[x][y - 1] != 0) n       t[a][b][c].set(x, y - 1, c); n     else n       t[a][b][c].set(a, b, 6); n   } else if (c == 6) { n     while (table[x - 1][y] == table[a][b]) x--; n     while (table[x][y - 1] == table[a][b]) y--; n     if (table[x - 1][y] != 0) n       t[a][b][c].set(x - 1, y, c); n     else n       t[a][b][c].set(a, b, 7); n   } else if (c == 7) { n     while (table[x - 1][y] == table[a][b]) x--; n     while (table[x][y + 1] == table[a][b]) y++; n     if (table[x - 1][y] != 0) n       t[a][b][c].set(x - 1, y, c); n     else n       t[a][b][c].set(a, b, 0); n   } n } n int main() { n   int n, m; n   cin >> n >> m; n   string s; n   int h = 0; n   cin.ignore(); n   for (int i = 0; i < n; i++) { n     getline(cin, s); n     for (int j = 0; j < s.size(); j++) { n       table[i + 1][j + 1] = s[j] -  0 ; n     } n   } n   h = s.size(); n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= h; j++) { n       for (int k = 0; k < 8; k++) { n         f(i, j, k); n       } n     } n   } n   int q1 = 1, q2 = 1, q3 = 0; n   int w1, w2, w3; n   for (int i = 0; i < m; i++) { n     w1 = t[q1][q2][q3].first; n     w2 = t[q1][q2][q3].second; n     w3 = t[q1][q2][q3].third; n     q1 = w1; n     q2 = w2; n     q3 = w3; n   } n   cout << table[q1][q2] << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const int V = 25; n int n, k, sx, sy; n bool adj[V][V]; n double p[V]; n double mat[V * V][V * V]; n int id[V][V], deg[V]; n double calc_p(int i, int j) { n   return (i == j) ? p[i] : (adj[i][j]) ? (1 - p[i]) / deg[i] : 0.0; n } n void gauss(double a[][V * V], int m, int n) { n   for (int i = 0; i < m; i++) { n     int u = i; n     for (int r = i + 1; r < m; r++) n       if (fabs(a[r][i]) > fabs(a[u][i])) u = r; n     if (u != i) n       for (int j = i; j < m + n; j++) swap(a[i][j], a[u][j]); n     double t = a[i][i]; n     for (int j = i; j < m + n; j++) a[i][j] /= t; n     for (int c = 0; c < m; c++) n       if (c != i) { n         t = a[c][i]; n         for (int j = i; j < m + n; j++) a[c][j] -= t * a[i][j]; n       } n   } n } n int main() { n   int a, b; n   scanf( %d%d%d%d , &n, &k, &sx, &sy); n   sx--; n   sy--; n   memset(deg, 0, sizeof(deg)); n   memset(adj, 0, sizeof(adj)); n   for (int i = 0; i < k; i++) { n     scanf( %d%d , &a, &b); n     a--; n     b--; n     adj[a][b] = adj[b][a] = true; n     deg[a]++; n     deg[b]++; n   } n   int m = 0; n   for (int i = 0; i < n; i++) n     for (int j = i; j < n; j++) id[i][j] = id[j][i] = m++; n   for (int i = 0; i < n; i++) scanf( %lf , &p[i]); n   memset(mat, 0, sizeof(mat)); n   for (int i = 0; i < n; i++) n     for (int j = i + 1; j < n; j++) { n       for (int x = 0; x < n; x++) n         for (int y = 0; y < n; y++) { n           mat[id[i][j]][id[x][y]] += calc_p(i, x) * calc_p(j, y); n         } n     } n   for (int i = 0; i < m; i++) mat[i][i] -= 1; n   for (int i = 0; i < n; i++) mat[id[i][i]][id[i][i]] = 1; n   for (int i = 0; i < n; i++) mat[id[i][i]][m + i] = 1; n   gauss(mat, m, n); n   for (int i = 0; i < n; i++) { n     if (i) printf(   ); n     printf( %.9f , mat[id[sx][sy]][m + i]); n   } n   printf(  n ); n } n


#include <bits/stdc++.h> n using namespace std; n int dp[1 << 25]; n int tick[25][25], value[25][25], cost[25][25]; n int n, m; n string s[25]; n int main() { n   cin >> n >> m; n   for (int i = 0; i < n; i++) cin >> s[i]; n   for (int i = 0; i < n; i++) n     for (int j = 0; j < m; j++) cin >> value[i][j]; n   for (int i = 0; i < n; i++) n     for (int j = 0; j < m; j++) { n       int maxi = 0; n       for (int x = 0; x < n; x++) n         if (s[i][j] == s[x][j]) { n           tick[i][j] |= (1 << x); n           maxi = max(maxi, value[x][j]); n           cost[i][j] += value[x][j]; n         } n       cost[i][j] -= maxi; n     } n   memset(dp, 1000000005, sizeof(dp)); n   dp[0] = 0; n   for (int mask = 1; mask < (1 << n); mask++) { n     int t; n     for (int pos = 0; pos < n; pos++) n       if ((mask >> pos) & 1) { n         t = pos; n         break; n       } n     for (int pos = 0; pos < m; pos++) { n       dp[mask] = min(dp[mask], dp[mask & (mask ^ tick[t][pos])] + cost[t][pos]); n       dp[mask] = min(dp[mask], dp[mask - (1 << t)] + value[t][pos]); n     } n   } n   cout << dp[(1 << n) - 1]; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n mt19937_64 rnd(time(NULL)); n const int N = 25; n const int inf = 1e9; n const double MAX_T = 1000; n const double MIN_T = 1e-5; n const int max_mutations = 10; n int n, m; n vector<int> A, B; n vector<vector<int> > best_ans, cur_ans; n int best_cost = 0; n inline void mutation(vector<vector<int> > &a) { n   int cnt = rnd() % max_mutations + 1; n   for (; cnt; cnt--) { n     int x = rnd() % n, y = rnd() % m; n     a[x][y] = rnd() % 2; n   } n } n inline int calc(vector<vector<int> > &a) { n   int x = 0, res = 0; n   for (int i = 0; i < n; i++) { n     x = 0; n     for (int j = 0; j < m; j++) { n       if (a[i][j] == 1 && (j == 0 || a[i][j - 1] == 0)) x++; n     } n     res += (x - A[i]) * (x - A[i]); n   } n   for (int i = 0; i < m; i++) { n     x = 0; n     for (int j = 0; j < n; j++) { n       if (a[j][i] == 1 && (j == 0 || a[j - 1][i] == 0)) x++; n     } n     res += (x - B[i]) * (x - B[i]); n   } n   return res; n } n inline double ok(double E, double t) { return exp(-E / t); } n inline bool valid(double E, double t) { n   if (E < 0) return true; n   double x = ok(E, t); n   x *= inf; n   return (rnd() % inf <= x); n } n int main() { n   ios_base ::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   cin >> n >> m; n   A.resize(n, 0); n   B.resize(m, 0); n   for (int i = 0; i < n; i++) cin >> A[i]; n   for (int j = 0; j < m; j++) cin >> B[j]; n   cur_ans.assign(n, vector<int>(m)); n   for (int i = 0; i < n; i++) n     for (int j = 0; j < m; j++) cur_ans[i][j] = rnd() % 2; n   best_ans = cur_ans; n   best_cost = calc(cur_ans); n   double T = MAX_T; n   int i = 1; n   while (T > MIN_T && best_cost != 0) { n     mutation(cur_ans); n     int cur_cost = calc(cur_ans); n     if (valid(cur_cost - best_cost, T)) { n       best_cost = min(best_cost, cur_cost); n       if (best_cost == cur_cost) best_ans = cur_ans; n     } else n       cur_ans = best_ans; n     T = MAX_T * 0.1 / i; n     i++; n   } n   for (int i = 0; i < n; i++) { n     for (int j = 0; j < m; j++) { n       if (best_ans[i][j]) n         cout <<  * ; n       else n         cout <<  . ; n     } n     cout <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using lint = long long; n using ld = long double; n using pint = pair<int, int>; n using plint = pair<lint, lint>; n lint _pow(lint a, lint n) { n   if (n == 0) n     return 1; n   else { n     lint res = 1; n     lint buf = a; n     while (n > 0) { n       if (n % 2 == 1) { n         res *= buf; n         res %= 998244353LL; n       } n       buf *= buf; n       buf %= 998244353LL; n       n /= 2; n     } n     return res; n   } n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   int n; n   cin >> n; n   vector<int> c(n + 10, 0); n   for (lint i = 0; i < (int)n; i++) { n     int a; n     cin >> a; n     c[a]++; n   } n   lint ans = 0; n   vector<lint> dp(n + 10, 0); n   dp[0] = 1; n   vector<lint> rev(n + 10); n   for (lint i = 0; i < (int)n + 10; i++) rev[i] = _pow(i, 998244353LL - 2); n   for (lint i = 0; i < (int)n + 10; i++) { n     if (c[i] == 0) continue; n     if (c[i] >= 2) { n       for (lint j = 0; j < (int)n + 10; j++) { n         lint p = dp[j]; n         p *= c[i]; n         p %= 998244353LL; n         p *= c[i] - 1; n         p %= 998244353LL; n         p *= rev[n - j]; n         p %= 998244353LL; n         p *= rev[n - j - 1]; n         p %= 998244353LL; n         ans += p; n         ans %= 998244353LL; n       } n     } n     vector<lint> ndp(n + 10, 0); n     for (lint j = 0; j < (int)n + 10; j++) ndp[j] += dp[j]; n     for (lint j = 1; j < (int)n + 10; j++) { n       lint p = dp[j - 1]; n       p *= c[i]; n       p %= 998244353LL; n       p *= rev[n - j + 1]; n       p %= 998244353LL; n       ndp[j] += p; n       ndp[j] %= 998244353LL; n     } n     dp = ndp; n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:104857600 ) n using namespace std; n const int c = 1000100; n int n, m; n int a[c]; n int ans; n int d; n void go(int i, int b) { n   if (a[i]) return; n   a[i] = 1; n   int k = (m - 1) << 1; n   int nb = b; n   int p = i; n   while (k) { n     if (b > 0) n       d = min(k, n - p); n     else n       d = min(k, p - 1); n     p += d * b; n     if (d < k) b = -b; n     k -= d; n   } n   go(p, b); n   k = (m - 1) << 1; n   p = i; n   b = -nb; n   while (k) { n     if (b > 0) n       d = min(k, n - p); n     else n       d = min(k, p - 1); n     p += d * b; n     if (d < k) b = -b; n     k -= d; n   } n   go(p, b); n } n int main() { n   scanf( %d%d , &n, &m); n   ans = 0; n   int i; n   for (i = 1; i <= n; ++i) n     if (!a[i]) { n       ++ans; n       go(i, 1); n     } n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long MOD = 1000000007; n long long small(long long a, long long b) { n   if (a < b) return a; n   return b; n } n long long large(long long a, long long b) { n   if (a > b) return a; n   return b; n } n long long root(long long x, vector<long long>& a) { n   if (a[x] == x) return x; n   a[x] = root(a[x], a); n   return (a[x]); n } n int main() { n   long long t; n   t = 1; n   while (t--) { n     long long n, i, c, m, x, y, a1, h, k = 0; n     cin >> n >> m; n     vector<long long> v(n + 1, 0), a(n + 1, 0); n     for (i = 1; i <= n; i++) { n       cin >> v[i]; n       a[i] = i; n     } n     while (m--) { n       cin >> x >> y; n       x = root(x, a); n       y = root(y, a); n       if (v[x] < v[y]) n         a[y] = x; n       else n         a[x] = y; n     } n     for (i = 1; i <= n; i++) { n       if (a[i] == i) k = k + v[i]; n     } n     cout << k << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int const maxn = 60, maxl = 10010; n int f[maxn * maxl]; n int n, d, c, sum; n int main() { n   cin >> n >> d; n   f[0] = 1; n   for (int i = 0; i < n; i++) { n     cin >> c; n     for (int j = sum; j >= 0; j--) n       if (f[j]) f[j + c] = 1; n     sum += c; n   } n   int last = 0, t = 0; n   while (true) { n     int cur = last; n     for (int i = d; i > 0; i--) { n       if (f[last + i]) { n         cur = last + i; n         break; n       } n     } n     if (cur == last) { n       cout << last <<     << t << endl; n       break; n     } n     last = cur; n     t++; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s; n   cin >> s; n   int n = s.length(); n   int row, col; n   if (n <= 20) { n     int row = 1; n     int col = n; n     cout << row <<     << col << endl; n     cout << s; n   } else if (n >= 21 && n <= 40) { n     int row = 2; n     int stars = 0; n     int col; n     if (n % 2 == 0) { n       col = n / 2; n     } else { n       col = n / 2 + 1; n       stars = col * 2 - n; n     } n     int ctr = 0; n     cout << row <<     << col << endl; n     for (int i = 0; i < row - 1; i++) { n       if (stars > 0) { n         for (int j = 0; j < col - 1; j++) { n           cout << s[ctr]; n           ctr++; n         } n         cout <<  * ; n         stars--; n         cout << endl; n       } else { n         for (int j = 0; j < col; j++) { n           cout << s[ctr]; n           ctr++; n         } n         cout << endl; n       } n     } n     while (ctr <= (n - 1)) { n       cout << s[ctr]; n       ctr++; n     } n     if (stars > 0) cout <<  * ; n   } else if (n >= 41 && n <= 60) { n     int row = 3; n     int stars = 0; n     int col; n     if (n % 3 == 0) { n       col = n / 3; n     } else { n       col = n / 3 + 1; n       stars = col * 3 - n; n     } n     int ctr = 0; n     cout << row <<     << col << endl; n     for (int i = 0; i < row - 1; i++) { n       if (stars > 0) { n         for (int j = 0; j < col - 1; j++) { n           cout << s[ctr]; n           ctr++; n         } n         cout <<  * ; n         stars--; n         cout << endl; n       } else { n         for (int j = 0; j < col; j++) { n           cout << s[ctr]; n           ctr++; n         } n         cout << endl; n       } n     } n     while (ctr <= (n - 1)) { n       cout << s[ctr]; n       ctr++; n     } n     if (stars > 0) cout <<  * ; n   } else if (n >= 61 && n <= 80) { n     int row = 4; n     int stars = 0; n     int col; n     if (n % 4 == 0) { n       col = n / 4; n     } else { n       col = n / 4 + 1; n       stars = col * 4 - n; n     } n     int ctr = 0; n     cout << row <<     << col << endl; n     for (int i = 0; i < row - 1; i++) { n       if (stars > 0) { n         for (int j = 0; j < col - 1; j++) { n           cout << s[ctr]; n           ctr++; n         } n         cout <<  * ; n         stars--; n         cout << endl; n       } else { n         for (int j = 0; j < col; j++) { n           cout << s[ctr]; n           ctr++; n         } n         cout << endl; n       } n     } n     while (ctr <= (n - 1)) { n       cout << s[ctr]; n       ctr++; n     } n     if (stars > 0) cout <<  * ; n   } else { n     int row = 5; n     int stars = 0; n     int col; n     if (n % 5 == 0) { n       col = n / 5; n     } else { n       col = n / 5 + 1; n       stars = col * 5 - n; n     } n     int ctr = 0; n     cout << row <<     << col << endl; n     for (int i = 0; i < row - 1; i++) { n       if (stars > 0) { n         for (int j = 0; j < col - 1; j++) { n           cout << s[ctr]; n           ctr++; n         } n         cout <<  * ; n         stars--; n         cout << endl; n       } else { n         for (int j = 0; j < col; j++) { n           cout << s[ctr]; n           ctr++; n         } n         cout << endl; n       } n     } n     while (ctr <= (n - 1)) { n       cout << s[ctr]; n       ctr++; n     } n     if (stars > 0) cout <<  * ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int a, b; n int noOfDivisors(int n) { n   int till = sqrt(n); n   int c = 0; n   for (int i = 1; i < till + 1; i++) { n     if ((n % i) == 0) { n       if (i > b) c++; n       if ((n / i) > b && (n != i * i)) c++; n     } n   } n   return c; n } n int main() { n   scanf( %d%d , &a, &b); n   int ans = 0; n   if (a == b) { n     printf( infinity ); n     return 0; n   } else { n     printf( %d , noOfDivisors(a - b)); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 200; n const int maxm = maxn * maxn; n const int INF = 0x3f3f3f3f; n int n, k, s, ans, res; n int a[maxn]; n int dp[maxn][maxm]; n inline int read() { n   int x = 0; n   char ch = getchar(); n   while (ch <  0  || ch >  9 ) ch = getchar(); n   while (ch >=  0  && ch <=  9 ) { n     x = x * 10 + ch -  0 ; n     ch = getchar(); n   } n   return x; n } n int main() { n   if (fopen( D.in ,  r ) != NULL) { n     freopen( D.in ,  r , stdin); n     freopen( D.out ,  w , stdout); n   } n   n = read(), k = read(), s = read(); n   s = min(s, n * (n - 1) / 2); n   for (int i = 1; i <= n; i++) a[i] = read(); n   for (int i = 1; i <= k; i++) ans += a[i]; n   memset(dp, INF, sizeof(dp)); n   dp[0][0] = 0; n   for (int p = 1; p <= k; p++) n     for (int i = p - 1; i >= 0; i--) n       for (int j = s - (k + 1 - p); j >= 0; j--) n         dp[i + 1][j + k + 1 - p] = n             min(dp[i + 1][j + k + 1 - p], dp[i][j] - a[p]); n   for (int p = k + 1; p <= n; p++) n     for (int i = 1; i <= k; i++) n       for (int j = s - (p - (k + 1)); j >= 0; j--) n         dp[i - 1][j + p - (k + 1)] = n             min(dp[i - 1][j + p - (k + 1)], dp[i][j] + a[p]); n   for (int i = 0; i <= s; i++) res = min(res, dp[0][i]); n   printf( %d n , ans + res); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = (int)2e9; n const long long INFL = (long long)9e18; n const int MAXINT = ((~0) ^ (1 << 31)); n const long long MAXLL = ((~0) ^ ((long long)1 << 63)); n template <class T> n inline T pow2(T a) { n   return a * a; n } n template <class T> n inline bool mineq(T& a, T b) { n   return (a > b) ? (a = b, true) : false; n } n template <class T> n inline bool maxeq(T& a, T b) { n   return (a < b) ? (a = b, true) : false; n } n const int maxn = 2e5 + 100; n long long n, m, d, lt, a, b, t; n long long dp[2 * maxn]; n long long rmq[2 * maxn]; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cin >> n >> m >> d; n   for (int i = 0; i < (int)(m); i++) { n     cin >> a >> b >> t; n     t = t - lt; n     lt = lt + t; n     long long gap = min(n, t * d); n     deque<int> stk; n     for (int i = 0; i < (int)(2 * n); i++) { n       while (!stk.empty() && dp[stk.back()] <= dp[i]) stk.pop_back(); n       if (!stk.empty() && stk.front() == i - 2 * gap - 1) stk.pop_front(); n       stk.push_back(i); n       rmq[i] = dp[stk.front()]; n     } n     for (int i = 0; i < (int)(n); i++) { n       dp[i] = rmq[i + gap] + b - abs(a - i - 1); n     } n     for (int i = n; i < (int)(2 * n); i++) dp[i] = -INF / 2; n   } n   cout << *max_element(dp, dp + n) << endl; n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod7 = 998244353; n vector<vector<long long> > mul(vector<vector<long long> > &A, n                                vector<vector<long long> > &B, n                                long long mod = mod7) { n   vector<vector<long long> > res(A.size(), vector<long long>(B[0].size())); n   for (size_t i = 0; i < A.size(); ++i) n     for (size_t j = 0; j < B[0].size(); ++j) n       for (size_t k = 0; k < B.size(); ++k) n         res[i][j] = (res[i][j] + A[i][k] * B[k][j]) % mod; n   return res; n } n vector<vector<long long> > pow(vector<vector<long long> > A, long long n, n                                long long mod = mod7) { n   vector<vector<long long> > res(A.size(), vector<long long>(A.size())); n   for (size_t i = 0; i < A.size(); ++i) res[i][i] = 1; n   for (; n; A = mul(A, A, mod), n >>= 1) n     if (n & 1) res = mul(res, A, mod); n   return res; n } n inline long long gcd(long long a, long long b) { n   while (a && b) a > b ? a %= b : b %= a; n   return a + b; n } n inline void exgcd(long long a, long long b, long long &x, long long &y) { n   for (x = 1, y = 0; b;) { n     long long t = a / b; n     swap(a -= t * b, b); n     swap(x -= t * y, y); n   } n } n inline long long mmul(long long a, long long b, long long mod = mod7) { n   a *= b; n   return a >= mod ? a % mod : a; n } n inline long long minv(long long a, long long mod = mod7) { n   if (gcd(a, mod) != 1) return -1; n   long long x, y; n   exgcd(a, mod, x, y); n   return x < 0 ? x + mod : x; n } n inline long long mdiv(long long a, long long b, long long mod = mod7) { n   if (a == 0) return 0; n   long long g = gcd(b, mod); n   if (a % g) return -1; n   a /= g, b /= g, mod /= g; n   return mmul(a, minv(b, mod), mod); n } n inline long long mpow(long long a, long long n, long long mod = mod7) { n   long long res = 1; n   for (; n; n >>= 1, a = mmul(a, a, mod)) n     if (n & 1) res = mmul(res, a, mod); n   return res; n } n inline long long mlog(long long a, long long b, long long mod = mod7) { n   int s = sqrt(mod) + 1; n   long long t = 1; n   unordered_map<long long, long long> m; n   for (int i = 0; i < s; ++i, t = mmul(t, a, mod)) m[t] = i; n   t = minv(t, mod); n   for (int i = 0; i < s; ++i, b = mmul(t, b, mod)) n     if (m.count(b)) return m[b] + i * s; n   throw; n   return -1; n } n long long find_generator(long long order, long long p) { n   vector<int> v; n   long long o = order; n   for (int i = 2; 1ll * i * i <= o; ++i) n     if (o % i == 0) { n       v.push_back(order / i); n       while (o % i == 0) o /= i; n     } n   if (o > 1) v.push_back(order / o); n   for (long long i = 2, t;; ++i) { n     for (int j : v) n       if ((t = mpow(i, j, p)) == 1ll) break; n     if (t != 1ll) return i; n   } n } n inline long long find_order(long long n) { n   long long res = n; n   for (long long i = 2; i * i <= n; ++i) n     if (n % i == 0) { n       while (n % i == 0) n /= i; n       res /= i; n       res *= (i - 1); n     } n   if (n > 1) res /= n, res *= (n - 1); n   return res; n } n inline long long mroot(long long exp, long long b, long long mod = mod7) { n   long long o = find_order(mod); n   long long g = find_generator(o, mod); n   long long o2 = mlog(g, b, mod); n   long long o1 = mdiv(o2, exp, o); n   if (o1 == -1) return -1; n   return mpow(g, o1, mod); n } n long long N, M, K; n long long arr[105]; n void init() { n   cin >> K; n   for (int i = 0; i < K; ++i) cin >> arr[i]; n   cin >> N >> M; n } n void sol() { n   vector<vector<long long> > res(K, vector<long long>(K)); n   for (int i = 0; i < K; ++i) res[i][0] = arr[i]; n   for (int i = 1; i < K; ++i) res[i - 1][i] = 1; n   res = pow(res, N - K, mod7 - 1); n   N = res[0][0]; n   cout << mroot(N, M, mod7) << endl; n } n int main() { n   init(); n   sol(); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int q; n   cin >> q; n   while (q--) { n     int a, b, c, d; n     cin >> a >> b >> c >> d; n     if (a != c) n       cout << a <<     << c << endl; n     else if (a != d) n       cout << a <<     << d << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n void sdvig(char *c, int n) { n   int i; n   char s = c[0]; n   for (i = 0; i < n - 1; i++) { n     c[i] = c[i + 1]; n   } n   c[n - 1] = s; n } n int main() { n   int n; n   scanf( %d n , &n); n   char c[1010], cc[1010]; n   cin >> cc; n   int i, g, f, l = n - 1; n   int mmin = 1000000000, kol; n   bool fl; n   for (f = 0; f < n; f++) { n     kol = 0; n     for (i = 0; i < n; i++) { n       c[i] = cc[i]; n     } n     while (true) { n       i = 0; n       g = l; n       while (c[i] ==  H ) i++; n       while (c[g] ==  T ) g--; n       if (i < g) { n         swap(c[i], c[g]); n         kol++; n       } else { n         break; n       } n     } n     if (kol < mmin) mmin = kol; n     sdvig(cc, n); n   } n   cout << mmin; n   return 0; n } n


#include <bits/stdc++.h> n #pragma warning(disable : 4996) n using namespace std; n namespace Xrocks {} n using namespace Xrocks; n namespace Xrocks { n class in { n } user_input; n class out { n } output; n in& operator>>(in& X, int& Y) { n   scanf( %d , &Y); n   return X; n } n in& operator>>(in& X, char* Y) { n   scanf( %s , Y); n   return X; n } n in& operator>>(in& X, float& Y) { n   scanf( %f , &Y); n   return X; n } n in& operator>>(in& X, double& Y) { n   scanf( %lf , &Y); n   return X; n } n in& operator>>(in& X, char& C) { n   scanf( %c , &C); n   return X; n } n in& operator>>(in& X, string& Y) { n   cin >> Y; n   return X; n } n in& operator>>(in& X, long long& Y) { n   scanf( %lld , &Y); n   return X; n } n template <typename T> n in& operator>>(in& X, vector<T>& Y) { n   for (auto& x : Y) user_input >> x; n   return X; n } n template <typename T> n out& operator<<(out& X, const T& Y) { n   cout << Y; n   return X; n } n template <typename T> n out& operator<<(out& X, vector<T>& Y) { n   for (auto& x : Y) output << x <<    ; n   return X; n } n out& operator<<(out& X, const int& Y) { n   printf( %d , Y); n   return X; n } n out& operator<<(out& X, const char& C) { n   printf( %c , C); n   return X; n } n out& operator<<(out& X, const string& Y) { n   printf( %s , Y.c_str()); n   return X; n } n out& operator<<(out& X, const long long& Y) { n   printf( %lld , Y); n   return X; n } n out& operator<<(out& X, const float& Y) { n   printf( %f , Y); n   return X; n } n out& operator<<(out& X, const double& Y) { n   printf( %lf , Y); n   return X; n } n out& operator<<(out& X, const char Y[]) { n   printf( %s , Y); n   return X; n } n template <typename T> n T max(T A) { n   return A; n } n template <typename T, typename... args> n T max(T A, T B, args... S) { n   return max(A > B ? A : B, S...); n } n template <typename T> n T min(T A) { n   return A; n } n template <typename T, typename... args> n T min(T A, T B, args... S) { n   return min(A < B ? A : B, S...); n } n template <typename T> n void vectorize(int y, vector<T>& A) { n   A.resize(y); n } n template <typename T, typename... args> n void vectorize(int y, vector<T>& A, args&&... S) { n   A.resize(y); n   vectorize(y, S...); n } n long long fast(long long a, long long b, long long pr) { n   if (b == 0) return 1 % pr; n   long long ans = 1 % pr; n   while (b) { n     if (b & 1) ans = (ans * a) % pr; n     b >>= 1; n     a = (a * a) % pr; n   } n   return ans; n } n int readInt() { n   int n = 0; n   int ch = getchar_unlocked(); n   int sign = 1; n   while (ch <  0  || ch >  9 ) { n     if (ch ==  - ) sign = -1; n     ch = getchar_unlocked(); n   } n   while (ch >=  0  && ch <=  9 ) n     n = (n << 3) + (n << 1) + ch -  0 , ch = getchar_unlocked(); n   n = n * sign; n   return n; n } n long long readLong() { n   long long n = 0; n   int ch = getchar_unlocked(); n   int sign = 1; n   while (ch <  0  || ch >  9 ) { n     if (ch ==  - ) sign = -1; n     ch = getchar_unlocked(); n   } n   while (ch >=  0  && ch <=  9 ) n     n = (n << 3) + (n << 1) + ch -  0 , ch = getchar_unlocked(); n   n = n * sign; n   return n; n } n long long readBin() { n   long long n = 0; n   int ch = getchar_unlocked(); n   int sign = 1; n   while (ch <  0  || ch >  1 ) { n     if (ch ==  - ) sign = -1; n     ch = getchar_unlocked(); n   } n   while (ch >=  0  && ch <=  1 ) n     n = (n << 1) + (ch -  0 ), ch = getchar_unlocked(); n   return n; n } n long long inv_(long long val, n                long long pr = static_cast<long long>(1000000007)) { n   return fast(val, pr - 2, pr); n } n }  // namespace Xrocks n class solve { n  public: n   solve() { n     set<int> Buy, Sell, Mid; n     int n; n     user_input >> n; n     Buy.insert(-1); n     Sell.insert(1e9); n     char action[10]; n     int num; n     int B1 = 0, B2 = 0; n     long long ans = 1; n     for (int i = 0; i < n; i++) { n       scanf( %s%d , action, &num); n       if (action[1] ==  D ) { n         B1 = *Buy.rbegin(); n         B2 = *Sell.begin(); n         if (B1 < num && B2 > num) { n           Mid.insert(num); n         } else if (B1 > num) { n           Buy.insert(num); n         } else n           Sell.insert(num); n       } else { n         if (Mid.find(num) != Mid.end()) { n           set<int>::iterator it = Mid.find(num); n           ++it; n           while (it != Mid.end()) { n             Sell.insert(*it); n             ++it; n           } n           set<int>::iterator it2 = Mid.begin(); n           while (*it2 < num) { n             Buy.insert(*it2); n             ++it2; n           } n           Mid.clear(); n           ans = (ans * 2) % static_cast<long long>(1000000007); n         } else if (num == (*Buy.rbegin())) { n           Buy.erase(num); n           Sell.insert(Mid.begin(), Mid.end()); n           Mid.clear(); n         } else if (num == (*Sell.begin())) { n           Sell.erase(Sell.begin()); n           Buy.insert(Mid.begin(), Mid.end()); n           Mid.clear(); n         } else { n           output << 0; n           return; n         } n       } n     } n     if (Mid.size()) n       ans = (ans * (Mid.size() + 1)) % static_cast<long long>(1000000007); n     output << ans; n   } n }; n int32_t main() { n   int t = 1, i = 1; n   if (0 || 0) scanf( %d , &t); n   while (t--) { n     if (0) printf( Case #%d:  , i++); n     new solve; n   } n   output <<   n ; n   return 0; n } n


#include <iostream> n  n  n using namespace std; n  n  n int main() n { n  int n, q; n  n  cin >> n >> q; n  n  char s[n+1]; n  int x[n+1]; n  n  for (int i = 1; i < n+1; i++) n  { n   cin >> s[i]; n   x[i] = x[i-1] + s[i] -  ` ; n  n  } n   n  int l, r; n  n  for (int i = 0; i < q; i++) n  { n   cin >> l >> r; n   cout << (x[r]-x[l-1]) << endl; n  n  } n   n   n   n  n  n  return 0; n }


#include <bits/stdc++.h> n using namespace std; n long long f[61 + 1], g[61 + 1], x, k; n int Q, op, pos; n int main() { n   scanf( %d , &Q); n   f[0] = 1; n   for (int i = 1; i < 61; i++) f[i] = f[i - 1] * 2; n   while (Q--) { n     scanf( %d , &op); n     if (op == 1) { n       scanf( %I64d%I64d , &x, &k); n       for (int i = 0; i < 61; i++) n         if (f[i] >= x) { n           pos = i; n           break; n         } else n           x -= f[i]; n       g[pos] = (g[pos] + k) % f[pos]; n     } n     if (op == 2) { n       scanf( %I64d%I64d , &x, &k); n       for (int i = 0; i < 61; i++) n         if (f[i] >= x) { n           pos = i; n           break; n         } else n           x -= f[i]; n       k %= f[pos]; n       for (int i = pos; i < 61; i++) { n         g[i] = (g[i] + k) % f[i]; n         k *= 2; n       } n     } n     if (op == 3) { n       scanf( %I64d , &x); n       printf( %I64d , x); n       long long tmp = x; n       for (int i = 0; i < 61; i++) n         if (f[i] >= x) { n           pos = i; n           break; n         } else n           x -= f[i]; n       x = tmp; n       while (x != 1) { n         long long xx = x, fa; n         xx += g[pos]; n         if (xx < f[pos]) xx += f[pos]; n         if (xx >= f[pos + 1]) xx -= f[pos]; n         fa = xx / 2; n         pos--; n         fa -= g[pos]; n         if (fa < f[pos]) fa += f[pos]; n         if (fa >= f[pos + 1]) fa -= f[pos]; n         x = fa; n         printf(  %I64d , fa); n       } n       printf(  n ); n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2e5 + 5, SQ = 5555; n unordered_map<int, int> ed[N]; n set<pair<int, int>> edge, bad; n int n, m, k, last, par[N]; n struct Query { n   int t, u, v; n } qu[SQ]; n bool mark[N]; n queue<int> q; n int gg(int u) { return ~par[u] ? par[u] = gg(par[u]) : u; } n void merge(int u, int v) { n   u = gg(u); n   v = gg(v); n   if (u == v) return; n   par[v] = u; n } n void upd(int u, int v) { n   if (u > v) swap(u, v); n   int a = gg(u), b = gg(v); n   if (edge.erase({u, v})) { n     if (!--ed[a][b]) ed[a].erase(b); n     if (!--ed[b][a]) ed[b].erase(a); n   } else { n     edge.insert({u, v}); n     ed[a][b]++, ed[b][a]++; n   } n } n void bfs(int root, bool st) { n   q.push(root); n   mark[root] = st; n   while (!q.empty()) { n     int u = q.front(); n     for (auto v : ed[u]) n       if (mark[v.first] ^ st) { n         mark[v.first] = st; n         q.push(v.first); n       } n     q.pop(); n   } n } n bool get(int u, int v) { n   bfs(u = gg(u), true); n   bool ans = mark[gg(v)]; n   return bfs(u, false), ans; n } n int main() { n   scanf( %d%d , &n, &m); n   while (m) { n     bad.clear(); n     m -= (k = min(m, SQ)); n     for (int i = 0; i < k; i++) { n       int t, u, v; n       scanf( %d%d%d , &t, &u, &v); n       if (u % n > v % n) swap(u, v); n       bad.insert({u % n, v % n}); n       if (u-- > v--) swap(u, v); n       qu[i] = {t, u, v}, bad.insert({u, v}); n     } n     memset(par, -1, sizeof par); n     for (int i = 0; i < n; i++) ed[i].clear(); n     for (auto x : edge) n       if (!bad.count(x)) merge(x.first, x.second); n     for (auto x : edge) n       if (bad.count(x)) { n         ed[gg(x.first)][gg(x.second)]++; n         ed[gg(x.second)][gg(x.first)]++; n       } n     for (int i = 0; i < k; i++) { n       (qu[i].u += last) %= n; n       (qu[i].v += last) %= n; n       if (qu[i].t & 1) n         upd(qu[i].u, qu[i].v); n       else n         printf( %d , last = get(qu[i].u, qu[i].v)); n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n double a, b, m; n double vx, vy, vz; n double x0, z0; n int main() { n   scanf( %lf %lf %lf , &a, &b, &m); n   { n     scanf( %lf %lf %lf , &vx, &vy, &vz); n     double t = -(m / vy); n     double sx = vx * t; n     double sz = vz * t; n     int d = (int)(sz / b); n     if (d % 2 == 0) { n       z0 = sz - d * b; n     } else { n       z0 = b - (sz - d * b); n     } n     if (sx < -a / 2) { n       sx = -(sx + a / 2); n     } else { n       sx = sx + a / 2; n     } n     d = (int)(sx / a); n     if (d % 2 == 0) { n       x0 = sx - d * a; n     } else { n       x0 = a - (sx - d * a); n     } n     printf( %.10lf %.10lf n , x0, z0); n   } n   return 0; n } n


#include <bits/stdc++.h> n double arr[1005][4]; n int main() { n   int n, k; n   scanf( %d%d , &n, &k); n   int i; n   long long population = k; n   double maxRadius = -1, minRadius = 1e6; n   for (i = 0; i < n; i++) { n     scanf( %lf%lf%lf , &arr[i][0], &arr[i][1], &arr[i][2]); n     population += arr[i][2]; n     arr[i][3] = sqrt((arr[i][0] * arr[i][0]) + (arr[i][1] * arr[i][1])); n   } n   if (population < 1000000) n     printf( -1 n ); n   else { n     int i, j; n     for (i = 0; i < n; i++) { n       for (j = 0; j < n - 1; j++) { n         if (arr[j][3] > arr[j + 1][3]) { n           double temp = arr[j][3]; n           arr[j][3] = arr[j + 1][3]; n           arr[j + 1][3] = temp; n           temp = arr[j][0]; n           arr[j][0] = arr[j + 1][0]; n           arr[j + 1][0] = temp; n           temp = arr[j][1]; n           arr[j][1] = arr[j + 1][1]; n           arr[j + 1][1] = temp; n           temp = arr[j][2]; n           arr[j][2] = arr[j + 1][2]; n           arr[j + 1][2] = temp; n         } n       } n     } n     double radius = 0; n     population = k; n     for (i = 0; i < n; i++) { n       if (population >= 1000000) n         break; n       else { n         radius = arr[i][3]; n         population += arr[i][2]; n         for (j = i + 1; arr[j][3] == arr[i][3] && population < 1000000; j++) { n           population += arr[j][2]; n         } n         i = j - 1; n       } n     } n     printf( %lf n , radius); n   } n   return 0; n } n


#include <bits/stdc++.h> n const int MOD = int(1e9) + 7; n inline int add(int a, int b) { n   return (a + b >= MOD) ? (a + b - MOD) : (a + b); n } n inline void inc(int &a, int b) { a = add(a, b); } n inline int sub(int a, int b) { return (a - b < 0) ? (a - b + MOD) : (a - b); } n inline void dec(int &a, int b) { a = sub(a, b); } n inline int mul(int a, int b) { return (a * 1ll * b) % MOD; } n using namespace std; n const int N = 100000; n vector<pair<int, int> > vet; n vector<int> aux; n vector<vector<int> > cycles[N + 1]; n int P[N]; n bool vis[N]; n void dfs(int u) { n   vis[u] = true; n   aux.push_back(u); n   u = P[u]; n   if (!vis[u]) dfs(u); n } n void debug() { n   for (int i = 0; i <= N; i++) n     if (!cycles[i].empty()) { n       printf( %d:  , i); n       for (__typeof((cycles[i]).begin()) it = (cycles[i]).begin(); n            it != (cycles[i]).end(); ++it) { n         printf( ( ); n         for (__typeof((*it).begin()) it2 = (*it).begin(); it2 != (*it).end(); n              ++it2) n           printf( %d  , *it2); n         printf( )  ); n       } n       puts(  ); n     } n } n bool solve(int testNumber) { n   int n; n   if (scanf( %d , &n) == EOF) return false; n   for (int i = 0; i < n; i++) { n     scanf( %d , &P[i]); n     P[i]--; n   } n   for (int i = 0; i <= N; i++) cycles[i].clear(); n   vet.clear(); n   for (int i = 0; i < N; i++) vis[i] = false; n   for (int i = 0; i < n; i++) n     if (!vis[i]) { n       aux.clear(); n       dfs(i); n       cycles[((int)(aux).size())].push_back(aux); n     } n   for (int i = 0; i <= N; i++) n     for (int j = 1; j < ((int)(cycles[i]).size()); j++) n       for (int k = 0; k < i; k++) n         vet.push_back(make_pair((cycles[i][0][k]), (cycles[i][j][k]))); n   for (int i = 0; i <= N; i++) n     if (!cycles[i].empty()) n       for (int j = 1; j * j <= i; j++) n         if (i % j == 0) { n           if (j != i && !cycles[j].empty()) { n             for (int k = 0; k < i; k++) n               vet.push_back( n                   make_pair((cycles[j][0][k % j]), (cycles[i][0][k]))); n             break; n           } n           int x = i / j; n           if (x != i && !cycles[x].empty()) { n             for (int k = 0; k < i; k++) n               vet.push_back( n                   make_pair((cycles[x][0][k % x]), (cycles[i][0][k]))); n             break; n           } n         } n   if (cycles[1].empty() && !cycles[2].empty()) n     vet.push_back(make_pair((cycles[2][0][0]), (cycles[2][0][1]))); n   if (((int)(vet).size()) < n - 1) n     puts( NO ); n   else { n     puts( YES ); n     for (__typeof((vet).begin()) it = (vet).begin(); it != (vet).end(); ++it) n       printf( %d %d n , it->first + 1, it->second + 1); n   } n   return true; n } n int main() { n   for (int i = 1; solve(i); i++) n     ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, i, j, k, l, a[1000009], b[1000009], f[1000009], ans, cn, t, x, y, z, n     mx, mn, s; n char c[1000009], d[1000009], ch; n map<int, int> mp, mm; n int main() { n   while (scanf( %d %d , &n, &m) != EOF) { n     ans = 1; n     mp.clear(); n     mm.clear(); n     for (i = 1; i <= n; i++) { n       scanf( %d , &f[i]); n       mm[f[i]] = 1; n     } n     for (i = 1; i <= m; i++) { n       scanf( %d , &b[i]); n       if (mm[b[i]] == 0) { n         ans = 0; n       } n     } n     if (ans == 0) { n       printf( Impossible n ); n     } else { n       ans = 1; n       mp.clear(); n       mm.clear(); n       for (i = 1; i <= m; i++) { n         mp[b[i]] = 1; n       } n       for (i = 1; i <= n; i++) { n         if (mp[f[i]] == 1) { n           mm[f[i]]++; n           if (mm[f[i]] == 2) { n             ans = 0; n             break; n           } n         } n       } n       if (ans == 0) { n         printf( Ambiguity n ); n       } else { n         printf( Possible n ); n         mp.clear(); n         for (i = 1; i <= n; i++) { n           mp[f[i]] = i; n         } n         for (i = 1; i <= m; i++) { n           a[i] = mp[b[i]]; n           if (i > 1) { n             printf(   ); n           } n           printf( %d , a[i]); n         } n         printf(  n ); n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int dr1[] = {1, 1, 0, -1, -1, -1, 0, 1}; n int dc1[] = {0, 1, 1, 1, 0, -1, -1, -1}; n int dr[] = {1, -1, 0, 0}; n int dc[] = {0, 0, 1, -1}; n const int fx[] = {+1, -1, +0, +0}; n const int fy[] = {+0, +0, +1, -1}; n const int fx8[] = {+0, +0, +1, -1, -1, +1, -1, +1}; n const int fy8[] = {-1, +1, +0, +0, +1, +1, -1, -1}; n const int kx[] = {-2, -2, -1, -1, 1, 1, 2, 2}; n const int ky[] = {-1, 1, -2, 2, -2, 2, -1, 1}; n int Set(int N, int pos) { return N = N | (1 << pos); } n int reset(int N, int pos) { return N = N & ~(1 << pos); } n bool check(int N, int pos) { return (bool)(N & (1 << pos)); } n int x[10005]; n int y[10005]; n char d[10005][10005]; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   long long a, b, c = 0, i, j, k, n, m, ans = 0; n   string s[10005]; n   cin >> n >> m; n   for (__typeof(n - 1) i = (0); i <= (n - 1); i++) { n     cin >> s[i]; n   } n   for (__typeof(n - 1) i = (0); i <= (n - 1); i++) { n     bool wasbest = false; n     for (__typeof(m - 1) j = (0); j <= (m - 1); j++) { n       bool isbest = true; n       a = s[i][j] -  0 ; n       for (__typeof(n - 1) k = (0); k <= (n - 1); k++) n         if (s[k][j] -  0  > a) isbest = false; n       if (isbest) wasbest = true; n     } n     if (wasbest) ans++; n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int OO = (int)2e9 + 5; n const int MOD = (int)1e9 + 7; n const long double Pi = 3.141592653589793238; n const int N = (int)2e5 + 5; n long long qqaGJJ[N], ss[2][N], vRI[2][N], n, uVyh = 0; n int main() { n   cin >> n; n   for (int i = (int)(1); i <= (int)(n); i++) cin >> qqaGJJ[i]; n   reverse(qqaGJJ + 1, qqaGJJ + n + 1); n   for (int i = (int)(1); i <= (int)(n); i++) { n     if (i == 1) { n       ss[0][i] = ss[1][0] = 0; n       vRI[0][i] = vRI[1][i] = 0; n     } else { n       for (int k = (int)(0); k <= (int)(1); k++) { n         ss[k][i] = ss[k][i - 1] + n                    abs(qqaGJJ[i] - qqaGJJ[i - 1]) * (((i + k) % 2) ? 1 : -1); n         vRI[k][i] = min(vRI[k][i - 1], ss[k][i]); n       } n     } n   } n   uVyh = ss[1][2]; n   for (int i = (int)(2); i <= (int)(n); i++) { n     uVyh = max(uVyh, ss[(i + 1) % 2][i] - vRI[(i + 1) % 2][i - 1]); n   } n   cout << uVyh; n } n


# include <bits/stdc++.h> n # define int long long n using namespace std; n const int N=505; n const int mo=998244353; n int a[2*N][N],b[N][N]; n bool f[2*N]; n int Pow(int x,int n) { n     int ans=1; n     while (n) { n         if (n&1) ans=ans*x%mo; n         x=x*x%mo; n         n>>=1; n     } n     return ans; n } n vector<int>an; n signed main() { n     int t; scanf( %lld ,&t); n     while (t--) { n         an.clear(); n         long long ans=1ll; n         int n; scanf( %lld ,&n); n         for (int i=1;i<=2*n;i++) n             for (int j=1;j<=n;j++) n                 scanf( %lld ,&a[i][j]); n         int tot=0; n         for (int i=1;i<=2*n;i++) f[i]=false; n  n  n         while (true) { n             for (int i=1;i<=n;i++) n                 for (int j=1;j<=n;j++) n                     b[i][j]=0; n             for (int i=1;i<=2*n;i++) if (!f[i]) { n                     for (int j=1;j<=n;j++) n                         b[j][a[i][j]]++; n                 } n  n  n  n             bool cc; int uniq; n             for (int i=1;i<=2*n;i++) if (!f[i]) { n                     cc=false; n                     for (int j=1;j<=n;j++) if (b[j][a[i][j]]==1) { n                             cc=true; uniq=i; break; n                         } n                     if (cc) break; n                 } n  n             if (cc) n             { n                 an.push_back(uniq); n             } n             else { n                 for (int i=1;i<=2*n;i++) if (!f[i]) { n                         uniq=i; break; n                     } n                 an.push_back(uniq); n                 ans=ans*2ll%mo; n             } n             for (int i=1;i<=2*n;i++) if (!f[i]) { n                     bool flag=true; n                     for (int j=1;j<=n;j++) if (a[i][j]==a[uniq][j]) { n                             flag=false; break; n                         } n                     if (!flag) f[i]=true; n                 } n             if (an.size()==n) break; n         } n         printf( %lld n ,ans); n         for (int i=0;i<an.size();i++) printf( %lld  ,an[i]); n         puts(  ); n     } n     return 0; n }


#include <bits/stdc++.h> n using namespace std; n signed main() { n   std::vector<std::vector<long long>> f(151, std::vector<long long>(151, 0)); n   f[0][0] = 1; n   f[1][0] = 1; n   f[1][1] = 1; n   for (long long i = 2; i <= 150; ++i) { n     for (long long j = 0; j <= i; ++j) { n       f[i][j] = ((f[i - 2][j]) + ((j != 0) ? (f[i - 1][j - 1]) : 0)); n       f[i][j] %= 2; n     } n   } n   long long n; n   cin >> n; n   cout << n <<   n ; n   for (long long i = 0; i <= n; ++i) { n     cout << f[n][i] <<    ; n   } n   cout <<   n ; n   cout << n - 1 <<   n ; n   for (long long i = 0; i <= n - 1; ++i) { n     cout << f[n - 1][i] <<    ; n   } n   cout <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long n, sum = 1e6; n   cin >> n; n   long a[n]; n   for (long i = 0; i < n; cin >> a[i++]) n     ; n   long opt; n   for (long i = 1; i <= 1000; ++i) { n     long s = 0; n     for (long j = 0; j < n; ++j) { n       if (i != a[j]) s += abs(i - a[j]) - 1; n     } n     if (s < sum) { n       sum = s; n       opt = i; n     } n   } n   cout << opt <<     << sum << endl; n } n


#include <bits/stdc++.h> n using namespace std; n #pragma comment(linker,  /stack:247474112 ) n #pragma GCC optimize( O3 ) n #pragma GCC optimize( Ofast ) n #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native ) n #pragma GCC optimize( unroll-loops ) n long long mod = 1e9 + 7; n void time() {} n const long long N = 3100300; n const long long maxn = 1e5 + 5; n const long long despacito = 1e9 + 7; n long long n, m; n long long a[N], p[N], cnt[N], z[N]; n int32_t main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   ; n   cin >> n; n   for (long long i = 1; i <= n; i++) { n     cin >> a[i]; n   } n   cin >> m; n   for (long long i = 1; i <= m; i++) { n     cin >> p[i]; n   } n   for (long long i = 1; i <= n; i++) { n     cnt[a[i]]++; n   } n   for (long long a = 1; a <= N; a++) { n     if (!cnt[a]) continue; n     for (long long b = a; b < N; b += a) { n       if (b / a != a) { n         z[b] += (long long)(cnt[a] * cnt[b / a]); n       } else n         z[b] += (long long)(cnt[a] * (cnt[a] - 1)); n     } n   } n   for (long long i = 1; i <= N; ++i) { n     z[i] += z[i - 1]; n   } n   for (long long i = 1; i <= m; ++i) { n     long long ans = (long long)(n) * (n - 1) - z[p[i] - 1]; n     cout << ans <<   n ; n   } n   time(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 2e5 + 5; n char a[maxn], b[maxn]; n int pre[maxn], suf[maxn]; n int main() { n   scanf( %s%s , a + 1, b + 1); n   int n = strlen(a + 1); n   int m = strlen(b + 1); n   int pos = 0; n   for (int i = 1; b[i]; i++, pos++) { n     while (pos <= n && a[pos] != b[i]) pos++; n     pre[i] = pos; n   } n   pos = n + 1; n   for (int i = m; b[i]; i--, pos--) { n     while (pos > 0 && b[i] != a[pos]) { n       pos--; n     } n     suf[i] = pos; n   } n   suf[m + 1] = n + 1; n   int ans1, ans2, l = 0, r = m; n   while (l <= r) { n     int mid = l + r >> 1, i; n     for (i = 0; i + mid <= m; ++i) n       if (pre[i] < suf[i + mid + 1]) break; n     if (i + mid <= m) { n       ans1 = i, ans2 = i + mid + 1, r = mid - 1; n     } else n       l = mid + 1; n   } n   if (ans2 - ans1 > m) n     putchar( - ); n   else { n     for (int i = 1; i <= ans1; ++i) putchar(b[i]); n     for (int i = ans2; b[i]; ++i) putchar(b[i]); n   } n   getchar(); n   getchar(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   cin >> t; n   for (int i = 0; i < t; i++) { n     string s; n     cin >> s; n     int cnt[26]; n     fill(cnt, cnt + 26, 0); n     set<int> st; n     int u = s.size(); n     for (int j = 0; j < u; j++) { n       int y = s[j] -  a ; n       cnt[y]++; n       st.insert(y); n     } n     u /= 2; n     vector<int> ans; n     vector<int> v; n     for (auto itr = st.begin(); itr != st.end(); itr++) { n       v.push_back(*itr); n     } n     if (v.size() == 1) { n       cout << s << endl; n       continue; n     } n     if (v.size() == 2) { n       if (v[0] - v[1] == -1) n         cout <<  No answer  << endl; n       else { n         cout << s << endl; n       } n       continue; n     } n     if (v.size() == 3) { n       if (v[0] == v[1] - 1 && v[1] == v[2] - 1) n         cout <<  No answer  << endl; n       else if (v[0] == v[1] - 1) { n         for (int j = 0; j < cnt[v[0]]; j++) cout << (char)(v[0] +  a ); n         for (int j = 0; j < cnt[v[2]]; j++) cout << (char)(v[2] +  a ); n         for (int j = 0; j < cnt[v[1]]; j++) cout << (char)(v[1] +  a ); n         cout << endl; n       } else if (v[1] == v[2] - 1) { n         for (int j = 0; j < cnt[v[2]]; j++) cout << (char)(v[2] +  a ); n         for (int j = 0; j < cnt[v[0]]; j++) cout << (char)(v[0] +  a ); n         for (int j = 0; j < cnt[v[1]]; j++) cout << (char)(v[1] +  a ); n         cout << endl; n       } else { n         for (int j = 0; j < cnt[v[0]]; j++) cout << (char)(v[0] +  a ); n         for (int j = 0; j < cnt[v[2]]; j++) cout << (char)(v[2] +  a ); n         for (int j = 0; j < cnt[v[1]]; j++) cout << (char)(v[1] +  a ); n         cout << endl; n       } n       continue; n     } n     for (int j = 1; j < v.size(); j += 2) { n       for (int k = 0; k < cnt[v[j]]; k++) cout << (char)(v[j] +  a ); n     } n     for (int j = 0; j < v.size(); j += 2) { n       for (int k = 0; k < cnt[v[j]]; k++) cout << (char)(v[j] +  a ); n     } n     cout << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 1e6 + 5; n constexpr int SQRT = 1000; n struct query { n   int x, y, pos; n   short sqrt; n   bool operator<(const query &b) const { n     if (sqrt == b.sqrt) { n       return ((sqrt & 1) ^ y < b.y); n     } n     return sqrt < b.sqrt; n   } n }; n query que[MAXN]; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   int n; n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> que[i].x >> que[i].y; n     que[i].pos = i + 1, que[i].sqrt = que[i].x / SQRT; n   } n   sort(que, que + n); n   for (int i = 0; i < n; i++) { n     cout << que[i].pos <<    ; n   } n   cout <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } n int lcm(int a, int b) { return a / gcd(a, b) * b; } n const int mod = 1e9 + 7; n long long binpow(long long a, long long b) { n   long long res = 1; n   while (b > 0) n     if (b & 1) { n       res = (long long)(res * 1ll * a); n       --b; n     } else { n       a = (long long)(a * 1ll * a); n       b >>= 1; n     } n   return (long long)res; n } n vector<vector<int>> g; n vector<bool> used; n vector<long double> ver; n void dfs(int v, int prev) { n   used[v] = true; n   double cnt = 0, sum = 0; n   for (int i = 0; i < g[v].size(); i++) { n     int to = g[v][i]; n     if (to == prev) continue; n     dfs(to, v); n     sum += ver[to]; n     cnt++; n   } n   if (cnt == 0) n     ver[v] = 0; n   else n     ver[v] = 1 + sum / cnt; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   int q; n   cin >> q; n   while (q--) { n     int n; n     cin >> n; n     if (n % 4 == 0) { n       cout <<  YES  << endl; n     } else n       cout <<  NO  << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct S { n   int l, r, x; n }; n vector<S> tree[8000]; n int mk[1000100], step, ans; n int n; n pair<int, int> expand(int v) { n   int inc = 0; n   if (v > 1) { n     while ((1 << inc) < v) ++inc; n   } n   int bef = (v - 1) + inc; n   pair<int, int> at = make_pair(bef + 1, bef + 1); n   if (!(v & (v - 1))) at.second = (bef + 2); n   return at; n } n void answer(int lvl, int v) { n   pair<int, int> at = make_pair(v, v); n   while (lvl <= n) { n     pair<int, int> next = n         make_pair(expand(at.first).first, expand(at.second).second); n     for (int i = 0; i < tree[lvl].size(); ++i) { n       int l = tree[lvl][i].l, r = tree[lvl][i].r, x = tree[lvl][i].x; n       if (at.first > r || at.second < l) continue; n       if (mk[x] != step) ++ans, mk[x] = step; n     } n     at = next; n     ++lvl; n   } n } n void process() { n   int m; n   scanf( %d%d , &n, &m); n   step = 0; n   for (int i = 0; i < m; ++i) { n     int type, t, l, r, c, v, x; n     scanf( %d , &type); n     if (type == 1) n       scanf( %d %d %d %d , &t, &l, &r, &x), tree[t].push_back((S){l, r, x}); n     else n       scanf( %d %d , &t, &v), ans = 0, ++step, answer(t, v), n                               printf( %d n , ans); n   } n } n int main() { process(); } n


#include <bits/stdc++.h> n using namespace std; n const int N = 75010; n struct edge { n   int y, next; n } s[N]; n struct loop { n   vector<int> V; n   int S; n } P[N]; n struct node { n   int x, y, d; n   bool operator<(const node q) const { return x < q.x; } n }; n vector<node> A; n vector<int> F[32768]; n int first[N], len = 0, d[N], op[N], low[N], dfn[N], T = 0; n int sta[N], top = 0, totl; n int n, num, D; n map<long long, int> mp; n map<long long, int>::iterator it; n long long sum[20], tot = 0; n void ins(int x, int y) { n   s[++len] = (edge){y, first[x]}; n   first[x] = len; n } n void Tarjan(int x) { n   dfn[x] = ++T; n   low[x] = T; n   sta[++top] = x; n   for (int i = first[x]; i != 0; i = s[i].next) { n     if (!dfn[s[i].y]) { n       Tarjan(s[i].y); n       low[x] = min(low[x], low[s[i].y]); n     } else n       low[x] = min(low[x], dfn[s[i].y]); n   } n   if (low[x] == dfn[x]) { n     bool tf = true; n     totl++; n     while (1) { n       int now = sta[top]; n       top--; n       P[totl].V.push_back(now); n       if (P[totl].S & (1 << (d[now] - 1))) tf = false; n       P[totl].S |= (1 << (d[now] - 1)); n       if (now == x) break; n     } n     if (first[x] == 0 || P[totl].V.size() == 1 && s[first[x]].y != x || !tf) n       return; n     if (!F[P[totl].S].size()) F[P[totl].S].push_back(totl); n   } n } n int main() { n   scanf( %d , &n); n   D = (1 << n) - 1; n   int size = 0, x, y; n   mp.clear(); n   for (int i = 1; i <= n; i++) { n     scanf( %d , &size); n     while (size--) { n       num++; n       scanf( %d , &op[num]); n       mp[1ll * op[num]] = num; n       d[num] = i; n       sum[i] += op[num]; n     } n     tot += sum[i]; n   } n   if (tot % n != 0) { n     printf( No n ); n     return 0; n   } n   tot /= n; n   for (int i = 1; i <= num; i++) n     if (mp[tot - sum[d[i]] + op[i]]) ins(i, mp[tot - sum[d[i]] + op[i]]); n   for (int i = 1; i <= num; i++) n     if (!dfn[i]) Tarjan(i); n   for (int i = 1; i <= D; i++) n     for (int j = i & (i - 1); j; j = (j - 1) & i) { n       if (F[j].size() && F[i ^ j].size()) { n         F[i] = F[i ^ j]; n         for (int k = 0; k < F[j].size(); k++) F[i].push_back(F[j][k]); n         break; n       } n     } n   if (!F[D].size()) n     printf( No n ); n   else { n     printf( Yes n ); n     for (int i = 0; i < F[D].size(); i++) { n       x = F[D][i]; n       for (int j = 0; j < P[x].V.size() - 1; j++) n         A.push_back((node){d[P[x].V[j]], op[P[x].V[j]], d[P[x].V[j + 1]]}); n       A.push_back((node){d[P[x].V[P[x].V.size() - 1]], n                          op[P[x].V[P[x].V.size() - 1]], d[P[x].V[0]]}); n     } n     sort(A.begin(), A.end()); n     for (int i = 0; i < A.size(); i++) printf( %d %d n , A[i].y, A[i].d); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   int mas[n]; n   for (int i = 0; i < n; i++) { n     cin >> mas[i]; n   } n   int d = 0; n   int t = 0; n   for (int i = 0; i < n; i++) { n     if (mas[i] - d == 1) { n       t++; n       d = mas[i]; n     } n   } n   if (!d) { n     cout <<  0 ; n     return 0; n   } n   cout << t << endl; n   d = 0; n   for (int i = 0; i < n; i++) { n     if (mas[i] - d == 1) { n       d = mas[i]; n       cout << 2000 + i + 1 <<    ; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   string s = to_string(n); n   int m = s.size(); n   vector<int> v; n   for (int i = 9 * m; i >= 0; i--) { n     int j = n - i; n     int sum = 0; n     for (sum = 0; j > 0; j /= 10) sum += j % 10; n     if (sum == i) v.push_back(n - i); n   } n   cout << v.size() << endl; n   for (auto i : v) cout << i << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   const long long MOD = 1000003; n   int n; n   cin >> n; n   long long g = 1; n   for (int i = 1; i < n; i++) { n     g = (g * 3) % MOD; n   } n   cout << g; n } n


#include <bits/stdc++.h> n using namespace std; n const long long N = 2e5 + 1303; n long long solve() { n   long long n; n   string s; n   cin >> s; n   map<char, string> mp; n   mp[ > ] =  1000 ; n   mp[ < ] =  1001 ; n   mp[ + ] =  1010 ; n   mp[ - ] =  1011 ; n   mp[ . ] =  1100 ; n   mp[ , ] =  1101 ; n   mp[ [ ] =  1110 ; n   mp[ ] ] =  1111 ; n   n = s.size(); n   string tmp =   ; n   for (long long i = 0; i < n; ++i) tmp += mp[s[i]]; n   reverse((tmp).begin(), (tmp).end()); n   long long ans = 0; n   long long p = 1; n   for (auto x : tmp) n     ans = (ans + ((x -  0 ) % 1000003 * (p % 1000003)) % 1000003) % 1000003, n     p <<= 1, p %= 1000003; n   cout << ans; n   return 0; n } n signed main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   solve(), cout << endl; n   cerr << (float)clock() / CLOCKS_PER_SEC <<   secs n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   char s[100005] = {0}; n   int i, j; n   int panjang; n   int banyak[27] = {0}; n   gets(s); n   scanf( %d , &n); n   panjang = strlen(s); n   if (panjang <= n) { n     printf( 0 n ); n     return 0; n   } n   for (i = 0; i < panjang; i++) { n     ++banyak[s[i] -  a ]; n   } n   int hasil = 0; n   for (i = 0; i < 26; i++) n     if (banyak[i] > 0) ++hasil; n   int min = 100005; n   int indeks; n   while (1) { n     min = 100005; n     for (i = 0; i < 26; i++) { n       if (banyak[i] > 0 && banyak[i] < min) { n         min = banyak[i]; n         indeks = i; n       } n     } n     if (banyak[indeks] > n) break; n     --hasil; n     n -= banyak[indeks]; n     banyak[indeks] = 0; n   } n   printf( %d n , hasil); n   for (i = 0; i < panjang; i++) { n     if (banyak[s[i] -  a ] > 0) printf( %c , s[i]); n   } n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n using LL = long long; n constexpr int N = 1e5 + 5; n int main() { n   ios::sync_with_stdio(false); n   cin.tie(nullptr); n   int n; n   cin >> n; n   string x; n   cin >> x; n   int H = 0; n   for (char &c : x) n     if (c ==  H ) H++; n   int result = n; n   for (int i = 0; i < n; i++) { n     int now = 0; n     for (int j = 0; j < H; j++) { n       if (x[(i + j) % n] !=  H ) now++; n     } n     result = min(result, now); n   } n   cout << result << endl; n } n