#include <bits/stdc++.h> n using namespace std; n long long labs(long long a) { return a < 0 ? (-a) : a; } n long long max(long long a, long long b) { return a > b ? a : b; } n long long min(long long a, long long b) { return a < b ? a : b; } n template <typename T> n struct Point { n   T x, y; n   Point() {} n   Point(T xx, T yy) : x(xx), y(yy) {} n }; n template <typename T> n bool operator<(const Point<T> &p1, const Point<T> &p2) { n   return p1.x < p2.x || p1.x == p2.x && p1.y < p2.y; n } n char c =  a  - 1; n char NextChar() { n   c++; n   if (c >  z ) c =  a ; n   return c; n } n vector<vector<char> > v; n int main() { n   int n; n   cin >> n; n   if (n == 2) { n     cout <<  aa  << endl; n     cout <<  bb  << endl; n     cout <<  cc  << endl; n     cout <<  dd  << endl; n     return 0; n   } n   v.assign(4, vector<char>(n)); n   v[2][0] = v[3][0] = NextChar(); n   for (int(i) = 0; (i) < (n - 1); (i)++) { n     if (i % 2 == 0) { n       v[0][i] = v[0][i + 1] = NextChar(); n       v[1][i] = v[1][i + 1] = NextChar(); n     } else { n       v[2][i] = v[2][i + 1] = NextChar(); n       v[3][i] = v[3][i + 1] = NextChar(); n     } n   } n   if (n % 2 == 0) { n     v[2][n - 1] = v[3][n - 1] = NextChar(); n   } else { n     v[0][n - 1] = v[1][n - 1] = NextChar(); n   } n   for (int(i) = 0; (i) < (4); (i)++) { n     for (int(j) = 0; (j) < (n); (j)++) { n       cout << v[i][j]; n     } n     cout << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n inline int read() { n   int x = 0, f = 1; n   char c = getchar(); n   while (c !=  -  && (c <  0  || c >  9 )) c = getchar(); n   if (c ==  - ) f = -1, c = getchar(); n   while (c >=  0  && c <=  9 ) x = x * 10 + c -  0 , c = getchar(); n   return f * x; n } n const int maxn = 40 + 7; n const int inf = 0x3f3f3f3f; n const int mod = 1e9 + 7; n int n, m, cur, cnt; n bitset<100000> b[41]; n map<string, int> hh; n int g[maxn][maxn]; n int dp1[(1 << 20) + 7], dp2[(1 << 20) + 7]; n inline void max(int &x, int y) { n   if (x < y) x = y; n } n int main() { n   n = read(), m = read(); n   string name; n   for (int i = 1; i <= n; ++i) { n     int op = read(); n     if (op == 1) n       ++cur; n     else { n       cin >> name; n       if (hh.count(name) == 0) hh[name] = ++cnt; n       b[hh[name]][cur] = 1; n     } n   } n   for (int i = 1; i <= m; ++i) { n     for (int j = i + 1; j <= m; ++j) { n       if ((b[i] & b[j]).count()) g[i - 1][j - 1] = g[j - 1][i - 1] = 1; n     } n   } n   int n2 = m / 2, n1 = m - n2; n   for (int i = 0; i < n1; ++i) dp1[1 << i] = 1; n   for (int s = 3; s < 1 << n1; ++s) { n     for (int i = 0; i < n1; ++i) n       if (s >> i & 1) { n         int f = 1; n         for (int j = 0; j < n1; ++j) n           if ((s >> j & 1) && g[i][j]) f = 0; n         max(dp1[s], dp1[s ^ (1 << i)] + f); n       } n   } n   for (int i = 0; i < n2; ++i) dp2[1 << i] = 1; n   for (int s = 3; s < 1 << n2; ++s) { n     for (int i = 0; i < n2; ++i) n       if (s >> i & 1) { n         int f = 1; n         for (int j = 0; j < n2; ++j) n           if ((s >> j & 1) && g[n1 + i][n1 + j]) f = 0; n         max(dp2[s], dp2[s ^ (1 << i)] + f); n       } n   } n   int ans = 0; n   for (int s = 0; s < 1 << n1; ++s) { n     int s2 = (1 << n2) - 1; n     for (int i = 0; i < n1; ++i) n       if (s >> i & 1) { n         for (int j = 0; j < n2; ++j) n           if ((s2 >> j & 1) && g[i][n1 + j]) s2 ^= 1 << j; n       } n     max(ans, dp1[s] + dp2[s2]); n   } n   printf( %d n , ans); n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 0x3f3f3f3f; n int q, n, a[505]; n int main() { n   cin >> q; n   while (q--) { n     cin >> n; n     for (int i = 1; i <= n; i++) cin >> a[i]; n     bool pd = 1; n     for (int i = 1; i < n; i++) { n       int xx = a[i] + 1; n       if (xx > n) xx = 1; n       if (xx != a[i + 1]) { n         pd = 0; n         break; n       } n     } n     if (pd) { n       cout <<  YES  << endl; n       continue; n     } n     pd = 1; n     for (int i = 1; i < n; i++) { n       int xx = a[i] - 1; n       if (xx == 0) xx = n; n       if (xx != a[i + 1]) { n         pd = 0; n         break; n       } n     } n     if (pd) n       cout <<  YES  << endl; n     else n       cout <<  NO  << endl; n   } n   return 0; n } n


#include<bits/stdc++.h> n #define ll long long int n #define mod 1000000007 n using namespace std; n  n int main() n { n     int t; n     cin>>t; n     while(t--) n     { n        int n; n        cin>>n; n        int A[n]; n        for(int i=0;i<n;i++) n        { n            cin>>A[i]; n        } n        bool flag=true; n        for(int i=0;i<n;i++) if(A[i]!=i+1) {flag=false; break;} n        if(flag) cout<< 0 <<endl; n        else if((A[0]==1)||(A[n-1]==n)) cout<< 1 <<endl; n        else if((A[0]==n)&&(A[n-1]==1)) cout<< 3 <<endl; n        else cout<< 2 <<endl; n     } n }


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, k; n   cin >> n; n   cin >> k; n   if (n < k) { n     cout << -1; n     return 0; n   } n   if (k == 1) { n     if (n == 1) n       cout <<  a ; n     else n       cout << -1; n     return 0; n   } n   if (k == 2) { n     for (int i = 0; i < n >> 1; i++) cout <<  ab ; n     if (n & 1) cout <<  a ; n     return 0; n   } else { n     string temp =  cdefghijklmnopqrstuvwxyz ; n     for (int i = 0; i < (n - k + 2) >> 1; i++) cout <<  ab ; n     if ((n - k + 2) & 1) cout <<  a ; n     for (int j = 0; j < (k - 2); j++) cout << temp[j]; n   } n   cout << endl; n   return 0; n } n


#include <iostream> n #include<bits/stdc++.h> n #include<vector> n #define fo(i,n) for(long long i=0;i<n;i++) n #define ll long long int n #define inf 999999999999999999 n #define pb push_back n #define fi first n #define se second n #define vi vector<ll> n #define vii vector<vector<ll>> n #define pi pair<ll,ll> n #define mp make_pair n #define MOD 1000000007 n #define tr(c,it) for(auto it = (c).begin(); it != (c).end(); ++it) n #define fio ios_base::sync_with_stdio(false);cin.tie(0); n using namespace std; n //cerr<<   n  <<  Time elapsed :  << clock() * 1000.0 / CLOCKS_PER_SEC <<   ms n  ; n //freopen( explicit.in ,  r , stdin); n //freopen( explicit.out ,  w , stdout); n   n void SieveOfEratosthenes()  n {  n     bool prime[10000001]; n     memset(prime, true, sizeof(prime));  n    n     for (ll p=2; p*p<=10000000; p++)  n     {  n         if (prime[p] == true)  n         {  n             // Update all multiples of p greater than or   n             // equal to the square of it  n             // numbers which are multiple of p and are  n             // less than p^2 are already been marked.   n             for (ll i=p*p; i<=10000000; i += p) { n                 prime[i] = false;  n             } n         }  n     }   n }  n ll binpow(ll a, ll b) { n     ll res = 1; n     while (b > 0) { n         if (b & 1) n             res = (res * a); n         a = (a * a); n         b >>= 1; n     } n     return res; n } n ll gcd(ll a,ll b) n { n     if(b%a==0) n        return a; n     return gcd(b%a,a); n } n ll power(ll x,ll y,ll p)  n {  n     ll r = 1; n    n     x = x % p; n     while (y > 0) { n         if (y & 1)  n             r = (r * x) % p; n         y = y >> 1;  n         x = (x * x) % p;  n     }  n     return r;  n }   n ll modInverse(ll n, ll p)  n {  n     return power(n, p - 2, p);  n }  n   n ll nCrModP(ll n,ll r, ll p)  n {  n     ll fac[100005]; n     if (r == 0)  n         return 1;  n    n     return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) % p;  n } n int32_t main()  n { n     fio n     ll j,i,n,t,l,s,r,c,h,k,m,maxi,d,a,b,x; n     cin>>t; n     string w; n     for(i=0;i<t;i++) n     { n         cin>>a>>b>>c; n         s=0; n         for(j=0;j<c;j++) n         { n             s=s*10+1; n         } n         l=s; n         while(true) n         { n             x=s; n             d=0; n             while(x!=0) n             { n                 x=x/10; n                 d++; n             } n             if(d==a) n                 break; n             s=s*2; n         } n         m=s; n         s=l; n         while(true) n         { n             x=s; n             d=0; n             while(x!=0) n             { n                 x=x/10; n                 d++; n             } n             if(d==b) n                 break; n             s=s*3; n         } n         cout<<m<<   <<s<<endl; n         // cout<<__gcd(m,s)<<endl; n     } n } n  n  n  n  n  n      n  n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 1e5; n int n, can_win[MAXN + 5], can_lose[MAXN + 5]; n struct game { n   long long s, e; n } a[MAXN + 5]; n bool get_win(long long s, long long e) { n   assert(s <= e); n   if (e % 2 == 1) { n     if (s % 2 == 1) n       return 0; n     else n       return 1; n   } else { n     if (s * 2 > e) { n       if (s % 2 == 1) n         return 1; n       else n         return 0; n     } else if (s * 4 > e) { n       return 1; n     } else { n       return get_win(s, e / 4); n     } n   } n } n bool get_lose(long long s, long long e) { n   if (s * 2 > e) { n     return 1; n   } else { n     return get_win(s, e / 2); n   } n } n int main() { n   cin >> n; n   for (int i = 1; i <= n; ++i) cin >> a[i].s >> a[i].e; n   can_lose[0] = 1; n   for (int i = 1; i <= n; ++i) { n     if (can_lose[i - 1] && can_win[i - 1]) { n       cout << 1 <<     << 1 << endl; n       return 0; n     } n     if (!can_lose[i - 1] && !can_win[i - 1]) { n       cout << 0 <<     << 0 << endl; n       return 0; n     } n     if (can_lose[i - 1]) { n       can_win[i] = get_win(a[i].s, a[i].e); n       can_lose[i] = get_lose(a[i].s, a[i].e); n     } else { n       can_win[i] = (!get_win(a[i].s, a[i].e)); n       can_lose[i] = (!get_lose(a[i].s, a[i].e)); n     } n   } n   cout << can_win[n] <<     << can_lose[n] << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 1e9; n const int maxN = 100000; n int main() { n   cin.tie(0); n   ios_base::sync_with_stdio(0); n   int n, m; n   cin >> n >> m; n   int ok = 1; n   for (int i = 0; i < n; i++) { n     for (int k = 0; k < m; k++) { n       char c; n       cin >> c; n       if (c !=  B  && c !=  W  && c !=  G ) ok = 0; n     } n   } n   cout << (ok ?  #Black&White  :  #Color ) << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct READ { n   int d1, d2, d3; n   READ(int d1 = -1, int d2 = -1, int d3 = -1) : d1(d1), d2(d2), d3(d3) {} n   template <class T> n   operator T() { n     T tmp; n     this->read(tmp); n     return tmp; n   } n   template <class T> n   void read(T& t) { n     cin >> t; n   } n   template <class T> n   void read(vector<T>& cont) { n     assert(d1 != -1); n     cont.resize(d1); n     READ r(d2, d3); n     for (int i = 0; i < d1; ++i) r.read(cont[i]); n   } n   template <class T1, class T2> n   void read(pair<T1, T2>& x) { n     read(x.first); n     read(x.second); n   } n }; n vector<pair<int, int>> solve(int n, int k) { n   int64_t combs = (int64_t)k * (k - 1); n   if (combs < n) return {}; n   vector<pair<int, int>> result; n   for (int diff = 1;; diff += 1) { n     for (int x = 1; x <= k; ++x) { n       result.emplace_back(x, (x + diff - 1) % k + 1); n       if (result.size() >= n) return result; n     } n   } n } n int main(int argc, char* argv[]) { n   int n = READ(); n   int k = READ(); n   vector<pair<int, int>> result = solve(n, k); n   if (result.empty()) { n     cout <<  NO  << endl; n   } else { n     cout <<  YES  << endl; n     for (auto& p : result) { n       cout << p.first <<     << p.second << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n #pragma GCC optimize( Ofast ) n #pragma GCC optimize( unroll-loops ) n #pragma GCC optimize( O0 ) n #pragma GCC optimize( O1 ) n template <typename T> n void vec_SUN(vector<T> &Vec) { n   vector<T> X; n   X = Vec; n   sort(X.begin(), X.end()); n   X.resize(unique(X.begin(), X.end()) - X.begin()); n   for (auto &u : Vec) u = lower_bound(X.begin(), X.end(), u) - X.begin() + 1; n } n template <typename T> n void arr_SUN(T *A, int n) { n   vector<T> B(n); n   for (int i = 0; i < n; i++) B[i] = A[i]; n   sort(B.begin(), B.end()); n   B.resize(unique(B.begin(), B.end()) - B.begin()); n   for (int i = 0; i < n; i++) n     A[i] = lower_bound(B.begin(), B.end(), A[i]) - B.begin() + 1; n } n template <typename T> n void vec_012(vector<T> &A, int n) { n   A.resize(n); n   for (int i = 0; i < n; i++) A[i] = (T)i; n } n template <typename T> n void arr_012(T *A, int n) { n   for (int i = 0; i < n; i++) A[i] = (T)i; n } n template <typename T> n void vec_123(vector<T> &A, int n) { n   A.resize(n); n   for (int i = 0; i < n; i++) A[i] = (T)(i + 1); n } n template <typename T> n void arr_123(T *A, int n) { n   for (int i = 0; i < n; i++) A[i] = (T)(i + 1); n } n template <typename T> n void arr_equal(T *A, T *P, int n) { n   for (int i = 0; i < n; i++) P[i] = A[i]; n } n template <typename T> n void setTOvec(set<T> &S, vector<T> &V) { n   V.resize(S.size()); n   int i = 0; n   for (auto it = S.begin(); it != S.end(); it++) V[i++] = *it; n } n const int N = 1e5 + 5; n struct X { n   int A[N]; n   int s = 0; n   void add(int x) { A[s++] = x; } n   void del() { s--; } n   void print() { n     cout << 0 <<    ; n     for (int i = s - 1; i >= 0; i--) cout << A[i] <<    ; n   } n }; n bitset<N> M; n int n; n bool f(X &ANS, int s) { n   if (s == 0 && ANS.s == n) { n     ANS.print(); n     return true; n   } n   if (M[s]) return false; n   M[s] = true; n   ANS.add(s); n   if (f(ANS, s / 2)) return true; n   if (f(ANS, (s + n) / 2)) return true; n   ANS.del(); n   M[s] = false; n   return false; n } n int main() { n   ios_base ::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   cin >> n; n   X ANS; n   if (n % 2 == 1) n     cout << -1; n   else n     f(ANS, 0); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n mt19937_64 rang( n     chrono::high_resolution_clock::now().time_since_epoch().count()); n const int M = 1e9 + 7; n long long power(long long x, long long y) { n   long long v = 1; n   while (y > 0) { n     if (y & 1) v = v * x; n     y = y >> 1; n     x = x * x; n   } n   return v; n } n bool isPowerOfTwo(long long x) { return x && (!(x & (x - 1))); } n long long ceil(long long a, long long b) { return (a + b - 1) / b; } n void _print(long long t) { cerr << t; } n void _print(int t) { cerr << t; } n void _print(string t) { cerr << t; } n void _print(char t) { cerr << t; } n void _print(long double t) { cerr << t; } n void _print(double t) { cerr << t; } n void _print(unsigned long long t) { cerr << t; } n template <class T, class V> n void _print(pair<T, V> p); n template <class T> n void _print(vector<T> v); n template <class T> n void _print(set<T> v); n template <class T, class V> n void _print(map<T, V> v); n template <class T> n void _print(multiset<T> v); n template <class T, class V> n void _print(pair<T, V> p) { n   cerr <<  { ; n   _print(p.first); n   cerr <<  , ; n   _print(p.second); n   cerr <<  } ; n } n template <class T> n void _print(vector<T> v) { n   cerr <<  [  ; n   for (T i : v) { n     _print(i); n     cerr <<    ; n   } n   cerr <<  ] ; n } n template <class T> n void _print(set<T> v) { n   cerr <<  [  ; n   for (T i : v) { n     _print(i); n     cerr <<    ; n   } n   cerr <<  ] ; n } n template <class T> n void _print(multiset<T> v) { n   cerr <<  [  ; n   for (T i : v) { n     _print(i); n     cerr <<    ; n   } n   cerr <<  ] ; n } n template <class T, class V> n void _print(map<T, V> v) { n   cerr <<  [  ; n   for (auto i : v) { n     _print(i); n     cerr <<    ; n   } n   cerr <<  ] ; n } n void init() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n } n void solve() { n   int n; n   cin >> n; n   vector<int> a(n + 1); n   for (int i = 1; i <= n; i++) cin >> a[i]; n   vector<int> pos(n + 1); n   for (int i = 1; i <= n; i++) { n     int x; n     cin >> x; n     pos[x] = i; n   }; n   ; n   for (int i = 1; i <= n; i++) a[i] = pos[a[i]]; n   ; n   int c = 1; n   for (int i = 2; i <= n; i++) { n     if (a[i] > a[i - 1]) n       c++; n     else n       break; n   } n   cout << n - c; n } n int main() { n   init(); n   long long test = 1; n   while (test--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   int a, b, x, y, ans; n   scanf( %d %d , &a, &b); n   ans = a; n   while (a >= b) { n     x = a / b; n     ans = ans + x; n     y = a % b; n     a = x + y; n   } n   printf( %d , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n char str[102]; n char miao[] =  miao. ; n char lala[] =  lala. ; n int check(char* a) { n   int res = 0; n   int k = strlen(a); n   if (k < 5) return 0; n   if (strncmp(a, miao, 5) == 0) res += 2; n   if (strncmp(a + k - 5, lala, 5) == 0) res += 1; n   return res; n } n int main() { n   int n, i, res; n   cin >> n; n   cin.getline(str, 101); n   for (i = 0; i < n; i++) { n     cin.getline(str, 101); n     res = check(str); n     if (res == 1) n       cout <<  Freda s n ; n     else if (res == 2) n       cout <<  Rainbow s n ; n     else n       cout <<  OMG>.< I don t know! n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long double esp = 1e-11; n const long double PI = acos((long double)-1); n const long long int INF = 0x3f3f3f3fll; n const int MOD = 1000000007ll; n const int maxn = 200001; n int inv[maxn], pin_inv[maxn], pin[maxn]; n void initCab(int N) { n   inv[0] = pin[0] = pin_inv[0] = inv[1] = pin[1] = pin_inv[1] = 1; n   for (int x = 2; x <= N; x++) { n     inv[x] = (long long int)(MOD - MOD / x) * inv[MOD % x] % MOD; n     pin[x] = (long long int)pin[x - 1] * x % MOD; n     pin_inv[x] = (long long int)pin_inv[x - 1] * inv[x] % MOD; n   } n } n long long int Cab(int n, int m) { n   return (long long int)pin[n] * pin_inv[m] % MOD * pin_inv[n - m] % MOD; n } n long long int m[maxn], ans[10]; n int main() { n   initCab(maxn - 1); n   int n; n   scanf( %d , &n); n   for (int x = 1; x <= n; x++) scanf( %d , &m[x]); n   int f = 1; n   if (n % 2 == 0) { n     for (int x = 1; x < n; x++) n       if (x & 1) n         m[x] = (m[x] + m[x + 1]) % MOD; n       else n         m[x] = (m[x] - m[x + 1]) % MOD; n     n--; n     f = 0; n   } n   int time = (n - 1) / 4 * 4; n   for (int x = 1; x <= n - time; x++) { n     ans[x] = 0; n     for (int y = 1; y <= time + 1; y++) n       if (y & 1) { n         ans[x] = (ans[x] + m[x + y - 1] * Cab(time / 2, y / 2)) % MOD; n       } n   } n   n -= time; n   while (n > 1) { n     for (int x = 1; x < n; x++) { n       if (f & 1) n         ans[x] = (ans[x] + ans[x + 1]) % MOD; n       else n         ans[x] = (ans[x] - ans[x + 1]) % MOD; n       f ^= 1; n     } n     n--; n   } n   ans[1] = (ans[1] % MOD + MOD) % MOD; n   printf( %I64d n , ans[1]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long int dx[] = {0, 1, -1, 0, 1, -1, -1, 1}; n const long long int dy[] = {-1, 0, 0, 1, 1, 1, -1, -1}; n long long int gcd(long long int x, long long int y) { n   return (y != 0 ? gcd(y, x % y) : x); n } n long long int lcm(long long int x, long long int y) { n   return (x / gcd(x, y) * y); n } n long long int limak; n long long int pos; n char matei[300010]; n vector<pair<long long int, pair<long long int, long long int> > > v; n long long int n; n bool compare(pair<long long int, pair<long long int, long long int> > a, n              pair<long long int, pair<long long int, long long int> > b) { n   return a.second.first > b.second.first; n } n long long int solve() { n   pos = 1; n   memset(matei, 0, sizeof matei); n   priority_queue<pair<long long int, long long int>, n                  vector<pair<long long int, long long int> >, n                  greater<pair<long long int, long long int> > > n       pq; n   int idx; n   long long int melhorPos = 300000000; n   for (idx = 0; idx < n; idx++) { n     if (v[idx].second.first <= limak || v[idx].first == 0) break; n     pq.push(make_pair(v[idx].second.second - v[idx].second.first + 1, n                       v[idx].first)); n     matei[v[idx].first] = 1; n     pos++; n   } n   melhorPos = pos; n   long long int precisa, id; n   while (!pq.empty()) { n     precisa = pq.top().first; n     id = pq.top().second; n     pq.pop(); n     if (precisa > limak) break; n     limak -= precisa; n     pos--; n     for (idx = idx; idx < n; idx++) { n       if (v[idx].second.first <= limak) break; n       if (!matei[v[idx].first] && v[idx].first != 0) { n         pq.push(make_pair(v[idx].second.second - v[idx].second.first + 1, n                           v[idx].first)); n         matei[v[idx].first] = 1; n         pos++; n       } n     } n     if (pos < melhorPos) melhorPos = pos; n   } n   return melhorPos; n } n int main() { n   cin >> n; n   long long int t, w; n   for (int i = 0; i < n; i++) { n     cin >> t >> w; n     if (i == 0) limak = t; n     v.push_back(make_pair(i, make_pair(t, w))); n   } n   sort(v.begin(), v.end(), compare); n   cout << solve() << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 512; n const int INF = 0x3f3f3f3f; n long long dis[MAXN][MAXN], a[MAXN], ans[MAXN]; n bool in[MAXN]; n int n; n void Floyd() { n   for (int k = n; k >= 1; k--) { n     int t = a[k]; n     in[t] = 1; n     for (int i = 1; i <= n; i++) { n       for (int j = 1; j <= n; j++) { n         dis[i][j] = min(dis[i][j], dis[i][t] + dis[t][j]); n         if (in[i] && in[j]) ans[k] += dis[i][j]; n       } n     } n   } n   for (int i = 1; i <= n; i++) printf( %lld  , ans[i]); n   puts(  ); n } n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= n; j++) { n       scanf( %lld , &dis[i][j]); n     } n   } n   for (int i = 1; i <= n; i++) { n     scanf( %lld , &a[i]); n   } n   Floyd(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long n, m; n vector<int> a[1000000]; n bool yt = 0; n map<int, int> rt; n string t; n long ry = 0; n string p[] = { 1869 ,  6198 ,  1896 ,  9186 ,  9168 ,  6189 ,  8691 }; n void df(int k) { n   for (int i = 1; i <= rt[k]; ++i) { n     ry = (ry * 10 + k) % 7; n     cout << k; n   } n } n int main() { n   cin >> t; n   for (int k = 0; k < t.size(); ++k) { n     rt[t[k] -  0 ]++; n   } n   --rt[1]; n   --rt[6]; n   --rt[8]; n   --rt[9]; n   for (int k = 1; k <= 9; ++k) df(k); n   cout << p[ry]; n   df(0); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int Maxn = 200005; n const int Maxl = 20; n int table[Maxl][Maxn]; n int tableor[Maxl][Maxn]; n int numlog[Maxn]; n int n, a[Maxn]; n void buildTable() { n   numlog[1] = 0; n   for (int i = 2; i <= n; i++) { n     numlog[i] = numlog[i >> 1] + 1; n   } n   for (int i = 0; i <= numlog[n]; i++) { n     int curlen = 1 << i; n     for (int j = 1; (j + curlen - 1) <= n; j++) { n       if (i == 0) { n         table[i][j] = j; n         continue; n       } else { n         if (a[table[i - 1][j]] >= a[table[i - 1][j + (curlen >> 1)]]) { n           table[i][j] = table[i - 1][j]; n         } else { n           table[i][j] = table[i - 1][j + (curlen >> 1)]; n         } n       } n     } n   } n } n void buildTableOr() { n   for (int i = 0; i <= numlog[n]; i++) { n     int curlen = 1 << i; n     for (int j = 1; (j + curlen - 1) <= n; j++) { n       if (i == 0) { n         tableor[i][j] = a[j]; n         continue; n       } else { n         tableor[i][j] = tableor[i - 1][j] | tableor[i - 1][j + (curlen >> 1)]; n       } n     } n   } n } n int getMaxIndex(int l, int r) { n   int curlog = numlog[r - l + 1]; n   if (a[table[curlog][l]] >= a[table[curlog][r - (1 << curlog) + 1]]) { n     return table[curlog][l]; n   } else { n     return table[curlog][r - (1 << curlog) + 1]; n   } n } n int RMQ(int l, int r) { return a[getMaxIndex(l, r)]; } n int getOr(int l, int r) { n   int curlog = numlog[r - l + 1]; n   return (tableor[curlog][l] | tableor[curlog][r - (1 << curlog) + 1]); n } n int binary_search(int gst, int st, int end, int cur_or) { n   while (st + 1 < end) { n     int mid = (st + end) / 2; n     int g = getOr(gst, mid); n     if (g > cur_or) n       end = mid; n     else n       st = mid; n   } n   int g = getOr(gst, end); n   if (g == cur_or) n     return end; n   else { n     return st; n   } n } n int get() { n   int ret = 0; n   for (int i = 1; i <= n; i++) { n     int cur_or = a[i]; n     int M = a[i]; n     for (int j = i; j <= n; j++) { n       cur_or |= a[j]; n       M = max(M, a[j]); n       if (cur_or > M) { n         ret++; n       } n     } n   } n   return ret; n } n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) { n     scanf( %d , &a[i]); n   } n   buildTable(); n   buildTableOr(); n   long long ans = 0; n   for (int i = n; i >= 1; i--) { n     int cur_or = a[i]; n     int st = i; n     int end = binary_search(i, i, n, cur_or); n     int idx = getMaxIndex(st, end); n     if (a[idx] < cur_or) { n       ans += (long long)end - st + 1; n     } else { n       ans += (long long)idx - st; n     } n     while (end <= n) { n       st = end + 1; n       if (st > n) break; n       cur_or = cur_or | a[st]; n       end = binary_search(i, st, n, cur_or); n       idx = getMaxIndex(st, end); n       if (a[idx] < cur_or) n         ans += (long long)end - st + 1; n       else n         ans += (long long)idx - st; n     } n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 1 << 30; n int n, in[100010], cnt, dyn[100010]; n void check() { n   if (cnt < 2) { n     printf( %d n , cnt); n     exit(0); n   } n } n int main() { n   scanf( %d , &n); n   for (int i = 0; i < n; i++) scanf( %d , &in[i]); n   for (int i = n - 1; i >= 0; i--) dyn[i] = dyn[i + 1] + (in[i] == 0 ? 1 : 0); n   if (n == 2) { n     if (in[0] == 0 && in[1] != 0) n       printf( 1 n ); n     else n       printf( 0 n ); n     return 0; n   } n   if (dyn[0] > 1) { n     int ans = INF; n     if (dyn[0] == n) ans = min(ans, 0); n     if (dyn[1] >= n - 2) ans = min(ans, n - 1 - dyn[1]); n     if (dyn[2] == n - 2) ans = min(ans, n - 2); n     if (ans < 2) n       printf( %d n , ans); n     else n       printf( 2 n ); n     return 0; n   } n   bool t = true; n   for (int i = 2; i < n; i++) n     if (in[i] * in[i - 2] != in[i - 1] * in[i - 1]) t = false; n   if (t) { n     printf( 0 n ); n     return 0; n   } n   if (n == 3) { n     if (in[1] == 0) goto l; n   } n   t = true; n   for (int i = 2; i < n; i++) n     if (in[i] * in[1] != in[2] * in[i - 1]) t = false; n   if (t) { n     printf( 1 n ); n     return 0; n   } n l:; n   cnt = 0; n   for (int i = 1; i < n; i++) { n     if (in[i] * in[0] != in[1] * in[i - 1]) { n       cnt++; n       if (i < n - 1 && in[i + 1] * in[0] != in[1] * in[i - 1]) cnt++; n       i++; n     } n   } n   check(); n   cnt = 0; n   for (int i = 1; i < n; i++) { n     if (in[i] * in[1] != in[2] * in[i - 1]) { n       cnt++; n       if (i < n - 1 && in[i + 1] * in[1] != in[2] * in[i - 1]) cnt++; n       i++; n     } n   } n   check(); n   cnt = 0; n   for (int i = 1; i < n; i++) { n     if (in[i] * in[0] != in[2] * in[i - 1]) { n       cnt++; n       if (i < n - 1 && in[i + 1] * in[0] != in[2] * in[i - 1]) cnt++; n       i++; n     } n   } n   check(); n   printf( 2 n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long n, x, y, c = 0, d = 0; n   cin >> n; n   long long m = n; n   while (n--) { n     scanf( %lld %lld , &x, &y); n     if (x > 0) c++; n     if (x < 0) d++; n   } n   if (c == m - 1 || d == m - 1 || c == m || d == m) n     cout <<  YES  << endl; n   else n     cout <<  NO  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = 0x3f3f3f3f; n const int M = 1e5 + 50; n map<int, int> vis, cnt; n int main() { n   int n; n   long long ans = 0; n   scanf( %lld , &n); n   for (int i = 0; i < n; i++) { n     int ch, tmp; n     scanf( %d , &ch); n     if (!vis[ch]) { n       vis[ch] = 1; n       cnt[ch] = vis.size() - 1; n       tmp = vis.size() - 1; n     } else { n       tmp = vis.size() - cnt[ch]; n       cnt[ch] = vis.size(); n     } n     ans += 1ll * tmp; n   } n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m, a = 0, b, c, d, i, j; n   char s[116][116]; n   cin >> n >> m; n   for (i = 1; i <= n; i++) { n     for (j = 1; j <= m; j++) { n       cin >> s[i][j]; n     } n   } n   for (i = 1; i <= n && a == 0; i++) { n     for (j = 1; j <= m; j++) { n       if (s[i][j] ==  B ) { n         a = i; n         break; n       } n     } n   } n   for (i = a, j = 1; j <= m; j++) { n     if (s[i][j] ==  B ) { n       b = j; n       break; n     } n   } n   for (i = a, j = m; j > 0; j--) { n     if (s[i][j] ==  B ) { n       c = j; n       break; n     } n   } n   d = (c - b) / 2; n   cout << a + d <<     << c - d; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 5010; n int f[MAXN]; n string s; n int l; n int ans[MAXN]; n int help[MAXN]; n int nim[MAXN]; n int start[MAXN]; n void init() { n   f[0] = 0; n   f[1] = 1; n   for (int i = 2; i <= l; ++i) { n     memset(nim, 0, sizeof(nim)); n     nim[f[i - 2] ^ f[0]] = 1; n     for (int j = 2; j <= i - 1; ++j) nim[f[i - j - 1] ^ f[j - 2]] = 1; n     for (int j = 0;; ++j) n       if (nim[j] == 0) { n         f[i] = j; n         break; n       } n   } n } n int main() { n   cin >> s; n   l = s.size(); n   init(); n   int top = 0; n   for (int i = 1; i < l - 1; ++i) n     if (s[i - 1] == s[i + 1]) ans[++top] = i; n   int cnt = 0; n   if (top >= 1) { n     help[1] = 1; n     start[1] = ans[1]; n     cnt = 1; n   } n   for (int i = 2; i <= top; ++i) n     if (ans[i] == ans[i - 1] + 1) n       help[cnt]++; n     else { n       cnt++; n       help[cnt] = 1; n       start[cnt] = ans[i]; n     } n   int out = 0; n   for (int i = 1; i <= cnt; ++i) out = out ^ f[help[i]]; n   if (!out) n     cout <<  Second  << endl; n   else { n     cout <<  First  << endl; n     for (int j = 1; j <= cnt; ++j) { n       if (help[j] == 1) { n         if (!out ^ f[help[j]]) { n           cout << start[j] + 1 << endl; n           return 0; n         } n       } n       if (!(out ^ f[help[j]] ^ f[help[j] - 2])) { n         cout << start[j] + 1 << endl; n         return 0; n       } n       for (int k = 2; k <= help[j] - 1; ++k) n         if (!(out ^ f[help[j]] ^ f[help[j] - k - 1] ^ f[k - 2])) { n           cout << start[j] + k << endl; n           return 0; n         } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long int skip_classes[501][501], dp[501][501], N, M, K; n vector<int> timings[501]; n vector<string> grid(501); n void preprocess() { n   for (long long int i = 1; i <= N; i++) { n     int total_classes_on_day_i = timings[i].size(); n     for (int skip = 0; skip <= K; skip++) { n       skip_classes[i][skip] = INT_MAX; n       int to_attend = total_classes_on_day_i - skip; n       if (to_attend <= 0) n         skip_classes[i][skip] = 0; n       else n         for (int j = to_attend - 1; j < timings[i].size(); j++) { n           skip_classes[i][skip] = n               (skip_classes[i][skip] <= n                        timings[i][j] - timings[i][j - to_attend + 1] + 1 n                    ? skip_classes[i][skip] n                    : timings[i][j] - timings[i][j - to_attend + 1] + 1); n         } n     } n   } n   return; n } n long long int solve_for(long long int day, long long int can_skip) { n   if (can_skip < 0) return INT_MAX; n   if (day == 0) return 0; n   if (dp[day][can_skip] != -1) return dp[day][can_skip]; n   long long int ans = INT_MAX, current_ans; n   for (long long int i = 0; i <= can_skip; i++) { n     current_ans = solve_for(day - 1, can_skip - i) + skip_classes[day][i]; n     ans = (ans <= current_ans ? ans : current_ans); n   } n   return dp[day][can_skip] = ans; n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   memset(dp, -1, sizeof dp); n   cin >> N >> M >> K; n   for (long long int i = 1; i <= N; i++) { n     cin >> grid[i]; n     for (int j = 0; j < grid[i].size(); j++) { n       if (grid[i][j] ==  1 ) timings[i].push_back(j + 1); n     } n   } n   preprocess(); n   long long int ans = solve_for(N, K); n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   vector<int> years; n   int curr = 1; n   for (int i = 1; i <= n; ++i) { n     int x; n     cin >> x; n     if (x == curr) { n       ++curr; n       years.push_back(2000 + i); n     } n   } n   cout << years.size() << endl; n   for (int year : years) { n     cout << year <<    ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int n, k, a[100005]; n bool pos(int len) { n   set<pair<int, int> > ms; n   for (int i = 1; i <= n; i++) { n     ms.insert(make_pair(a[i], i)); n     if (i >= len) { n       auto it = ms.begin(); n       int mn = (*it).first; n       it = ms.end(); n       it--; n       int mx = (*it).first; n       if (mx - mn <= k) return 1; n       ms.erase(make_pair(a[i - len + 1], i - len + 1)); n     } n   } n   return 0; n } n int main() { n   cin >> n >> k; n   for (int i = 1; i <= n; i++) cin >> a[i]; n   int hi = n, lo = 1; n   while (hi > lo) { n     int mid = (hi + lo + 1) / 2; n     if (pos(mid)) n       lo = mid; n     else n       hi = mid - 1; n   } n   int len = hi; n   vector<int> ans; n   set<pair<int, int> > ms; n   for (int i = 1; i <= n; i++) { n     ms.insert(make_pair(a[i], i)); n     if (i >= len) { n       auto it = ms.begin(); n       int mn = (*it).first; n       it = ms.end(); n       it--; n       int mx = (*it).first; n       if (mx - mn <= k) ans.push_back(i - len + 1), ans.push_back(i); n       ms.erase(make_pair(a[i - len + 1], i - len + 1)); n     } n   } n   printf( %d %d n , hi, (int)ans.size() / 2); n   for (int i = 0; i < ans.size(); i += 2) printf( %d %d n , ans[i], ans[i + 1]); n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T, typename U> n inline void smin(T &a, U b) { n   if (a > b) a = b; n } n template <typename T, typename U> n inline void smax(T &a, U b) { n   if (a < b) a = b; n } n int power(int a, int b, int m, int ans = 1) { n   for (; b; b >>= 1, a = 1LL * a * a % m) n     if (b & 1) ans = 1LL * ans * a % m; n   return ans; n } n int cnt[10]; n int ans[5], id[5]; n int main() { n   int n, s; n   scanf( %d%d , &n, &s); n   int a; n   for (int i = 0; i < n; i++) { n     scanf( %d , &a); n     cnt[a]++; n   } n   int A, B, C, mx = 0x3f3f3f3f; n   for (int i = s / n; i >= 0; i--) { n     id[0] = i; n     A = cnt[3] * id[0]; n     for (int j = (s - A) / (cnt[4] + cnt[5]); j >= i; j--) { n       id[1] = j; n       B = cnt[4] * id[1]; n       C = s - A - B; n       id[2] = C / cnt[5]; n       if (C % cnt[5]) continue; n       int tmp = abs(A - B) + abs(B - C); n       if (tmp >= mx && B <= C) break; n       if (tmp < mx) { n         ans[0] = id[0]; n         ans[1] = id[1]; n         ans[2] = id[2]; n         mx = tmp; n       } n     } n   } n   if (mx == 0x3f3f3f3f) n     puts( -1 ); n   else n     printf( %d %d %d n , ans[0], ans[1], ans[2]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int n, ans = 0; n   cin >> n; n   string x; n   cin >> x; n   for (long long int i = 0; i < x.length(); i++) { n     if (x[i] ==  0  || x[i] ==  2  || x[i] ==  4  || x[i] ==  6  || n         x[i] ==  8 ) { n       ans += (i + 1); n     } n   } n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n int r, c, d[1020][1020], used[1020][1020]; n string s[1020]; n int dx[] = {0, 0, 1, -1}; n int dy[] = {1, -1, 0, 0}; n long long ans = 0; n bool ok(int x, int y) { n   return x >= 0 && x < r && y >= 0 && y < c && s[x][y] !=  T ; n } n void bfs(int x, int y) { n   used[x][y] = 1; n   queue<pair<int, int> > q; n   q.push(make_pair(x, y)); n   d[x][y] = 0; n   while (q.empty() == false) { n     int xk = q.front().first, yk = q.front().second; n     q.pop(); n     for (int i = 0; i < 4; i++) { n       int xx = xk + dx[i]; n       int yy = yk + dy[i]; n       if (ok(xx, yy) == true && used[xx][yy] == 0) { n         used[xx][yy] = 1; n         d[xx][yy] = d[xk][yk] + 1; n         q.push(make_pair(xx, yy)); n       } n     } n   } n } n int main() { n   scanf( %d %d , &r, &c); n   int sx, sy, ex, ey; n   for (int i = 0; i < r; i++) { n     cin >> s[i]; n     for (int j = 0; j < c; j++) { n       if (s[i][j] ==  S ) { n         sx = i; n         sy = j; n         s[i][j] =  0 ; n       } else if (s[i][j] ==  E ) { n         ex = i; n         ey = j; n         s[i][j] =  0 ; n       } n     } n   } n   bfs(ex, ey); n   int need = d[sx][sy]; n   for (int i = 0; i < r; i++) { n     for (int j = 0; j < c; j++) { n       if (s[i][j] ==  T  && i == sx && j == sy) continue; n       int add = (int)(s[i][j] -  0 ); n       if (d[i][j] <= need && d[i][j] != 0) { n         ans += add; n       } n     } n   } n   printf( %lld , ans); n   return 0; n } n


#include <iostream> n using namespace std; n typedef long long ll; n  n int main() { n  int t; cin >> t; while (t--) { n   ll n, m, x; cin >> n >> m >> x; x--; n   ll j = x / n, i = x % n; n   cout << i * m + j + 1 <<   n ; n  } n  cin.ignore(2); return 0; n }


#include <bits/stdc++.h> n using namespace std; n int n, m, mp[5][1000050]; n int sta[20], cnt[20], tot; n char s[1000050]; n int f[1000050][20], ans; n void init() { n   for (int i = 0; i < (1 << n); i++) { n     sta[++tot] = i; n     int u = i; n     while (u) { n       cnt[tot] += ((u % 2) ^ 0); n       u >>= 1; n     } n   } n } n int change(int id, int y) { n   int ans = 0, status = sta[id]; n   for (int i = n; i >= 1; i--, status >>= 1) ans += ((status % 2) ^ mp[i][y]); n   return ans; n } n void dp() { n   init(); n   memset(f, 0x3f, sizeof f); n   for (int i = 1; i <= tot; i++) f[1][i] = change(i, 1); n   for (int i = 2; i <= m; i++) n     for (int j = 1; j <= tot; j++) n       for (int k = 1; k <= tot; k++) { n         int a = sta[j], b = sta[k]; n         int last = a % 2 + b % 2, now, flag = 1; n         a >>= 1; n         b >>= 1; n         for (int l = n - 1; l >= 1; l--) { n           now = a % 2 + b % 2; n           a >>= 1; n           b >>= 1; n           if ((last + now) % 2 == 0) flag = 0; n           last = now; n         } n         if (flag) f[i][j] = min(f[i][j], f[i - 1][k] + change(j, i)); n       } n } n int main() { n   scanf( %d%d , &n, &m); n   if (min(n, m) >= 4) { n     printf( -1 ); n     return 0; n   } n   if (n == 1) { n     printf( 0 ); n     return 0; n   } n   for (int i = 1; i <= n; i++) { n     scanf( %s , s + 1); n     for (int j = 1; j <= m; j++) mp[i][j] = s[j] -  0 ; n   } n   dp(); n   ans = n * m; n   for (int i = 1; i <= tot; i++) ans = min(ans, f[m][i]); n   printf( %d , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MOD = 1e9 + 7; n const long long INF = 1e9; n const int MX = 2e5 + 10; n const int nx[4] = {0, 0, 1, -1}, ny[4] = {1, -1, 0, 0}; n template <class T> n using V = vector<T>; n template <class T> n bool ckmin(T& a, const T& b) { n   return a > b ? a = b, 1 : 0; n } n template <class T> n bool ckmax(T& a, const T& b) { n   return a < b ? a = b, 1 : 0; n } n long long cdiv(long long a, long long b) { n   return a / b + ((a ^ b) > 0 && a % b); n } n mt19937 rng(chrono::system_clock::now().time_since_epoch().count()); n long long random(long long a, long long b) { return a + rng() % (b - a + 1); } n void IO() {} n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   IO(); n   int N; n   cin >> N; n   vector<int> a(N); n   for (int i = (0); i < (N); ++i) cin >> a[i]; n   int cnt[101]; n   fill(cnt, cnt + 101, 0); n   int mx = 0, D; n   for (auto x : a) { n     cnt[x]++; n     if (ckmax(mx, cnt[x])) D = x; n   } n   int ans = 0; n   for (int V = (1); V < (101); ++V) n     if (V != D) { n       vector<int> v(N); n       for (int i = (0); i < (N); ++i) { n         if (a[i] == D) n           v[i] = 1; n         else if (a[i] == V) n           v[i] = -1; n         else n           v[i] = 0; n       } n       unordered_map<int, int> pre; n       int s = 0; n       for (int i = (0); i < (N); ++i) { n         s += v[i]; n         pre[s] = INF; n       } n       pre[0] = -1; n       for (int i = (0); i < (N); ++i) { n         if (i) v[i] += v[i - 1]; n         ckmax(ans, i - pre[v[i]]); n         if (pre[v[i]] == INF) pre[v[i]] = i; n       } n     } n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int i, j, k, m; n int a[100010]; n long long f[110][100010], n; n long long dfs(int n, long long m) { n   if (!n) return m; n   if (m < 100010 && f[n][m] >= 0) return f[n][m]; n   long long A = dfs(n - 1, m) - dfs(n - 1, m / a[n]); n   if (m < 100010) f[n][m] = A; n   return A; n } n int main() { n   scanf( %I64d%d , &n, &m); n   for (i = 1; i <= m; i++) scanf( %d , &a[i]); n   sort(a + 1, a + m + 1); n   memset(f, 255, sizeof(f)); n   printf( %I64d n , dfs(m, n)); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int n; n   cin >> n; n   string s, t; n   cin >> s >> t; n   int sum1 = 0, sum2 = 0, sum3 = 0; n   for (int i = 0; i < 2 * n; i++) { n     if (s[i] ==  1  && t[i] ==  1 ) { n       sum3++; n       continue; n     } n     sum1 += (s[i] ==  1 ); n     sum2 += (t[i] ==  1 ); n   } n   if (sum3 % 2) { n     if (sum1 + 1 == sum2 || sum1 + 2 == sum2) { n       cout <<  Draw n ; n     } else { n       cout << ((sum1 >= sum2) ?  First  :  Second ) <<   n ; n     } n   } else { n     if (sum1 == sum2 || sum1 + 1 == sum2) { n       cout <<  Draw n ; n     } else { n       cout << ((sum1 > sum2) ?  First  :  Second ) <<   n ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int ni() { n   int a; n   scanf( %d , &a); n   return a; n } n double nf() { n   double a; n   scanf( %lf , &a); n   return a; n } n char sbuf[100005]; n string ns() { n   scanf( %s , sbuf); n   return sbuf; n } n long long nll() { n   long long a; n   scanf( %lld , &a); n   return a; n } n template <class T> n void out(T a, T b) { n   bool first = true; n   for (T i = a; i != b; ++i) { n     if (!first) printf(   ); n     first = false; n     cout << *i; n   } n   printf(  n ); n } n template <class T> n void outl(T a, T b) { n   for (T i = a; i != b; ++i) { n     cout << *i <<   n ; n   } n } n int n, m; n int ans[100005]; n int main() { n   int i, j, k; n   vector<pair<pair<int, int>, int> > v; n   n = ni(); n   for (i = (0); i < (((n))); ++i) { n     int a = ni(); n     int b = ni(); n     v.push_back(make_pair(make_pair(a, b), i)); n   } n   sort((v).begin(), (v).end()); n   reverse((v).begin(), (v).end()); n   vector<pair<int, int> > s; n   vector<int> sa; n   for (i = (0); i < (((v.size()))); ++i) { n     pair<int, int> last = make_pair(-1, -1); n     pair<int, int> vv = v[i].first; n     int aa = 1; n     while (s.size()) { n       if (s.back().first >= vv.first + vv.second) n         break; n       else { n         if (last.second == -1 || last.first + last.second <= s.back().first) n           aa += sa.back(); n         if (vv.first + vv.second >= s.back().first + s.back().second) { n           last = s.back(); n           s.pop_back(); n           sa.pop_back(); n         } else n           break; n       } n     } n     s.push_back(vv); n     sa.push_back(aa); n     ans[v[i].second] = aa; n   } n   out(ans, ans + n); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX = 0x3f3f3f3f; n const double EPS = 1e-6; n const double PI = acos(-1.0); n string second; n int ch = 0; n signed main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cin >> second; n   for (int i = 0; second[i]; i++) { n     while (ch != second[i] + 1) { n       ch--; n       cout <<  ... n.X. n... n ; n       if (ch < 0) ch = 255; n     } n     cout <<  .X. n.X. n... n ; n     ch--; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1e5 + 5; n int n, a[N]; n int main() { n   cin >> n; n   for (int i = 1; i <= n; i++) cin >> a[i]; n   sort(a + 1, a + n + 1); n   if (a[n] >= a[n - 1] + a[n - 2]) n     cout <<  NO ; n   else { n     cout <<  YES n ; n     cout << a[n] <<    ; n     for (int i = n - 2; i >= 1; i--) cout << a[i] <<    ; n     cout << a[n - 1]; n   } n   return 0; n } n


#include <bits/stdc++.h> n const int MAXN = 4e5 + 5, MAXLOG = 20, MAXS = MAXN * 50; n template <typename _T> n void read(_T &x) { n   x = 0; n   char s = getchar(); n   int f = 1; n   while (s >  9  || s <  0 ) { n     if (s ==  - ) f = -1; n     s = getchar(); n   } n   while (s >=  0  && s <=  9 ) { n     x = (x << 3) + (x << 1) + (s -  0 ), s = getchar(); n   } n   x *= f; n } n template <typename _T> n void write(_T x) { n   if (x < 0) { n     putchar( - ); n     x = (~x) + 1; n   } n   if (9 < x) { n     write(x / 10); n   } n   putchar(x % 10 +  0 ); n } n template <typename _T> n _T MAX(const _T a, const _T b) { n   return a > b ? a : b; n } n template <typename _T> n _T MIN(const _T a, const _T b) { n   return a < b ? a : b; n } n struct edge { n   int to, nxt; n } Graph[MAXN << 1]; n int f[MAXN][MAXLOG]; n bool s[MAXS]; n int lch[MAXS], rch[MAXS]; n int dp[MAXN], seq[MAXN], ID; n int ch[MAXN][26], fa[MAXN], mx[MAXN], head[MAXN], rot[MAXN], fir[MAXN]; n int N, lg2, rt, lst, tot, cnt, siz; n char S[MAXN]; n void upt(const int x) { s[x] = s[lch[x]] | s[rch[x]]; } n void copy(int a, int b) { n   fa[a] = fa[b], mx[a] = mx[b], memcpy(ch[a], ch[b], sizeof ch[b]); n } n void addEdge(const int from, const int to) { n   Graph[++cnt].to = to, Graph[cnt].nxt = head[from]; n   head[from] = cnt; n } n void expand(const char c) { n   int x = c -  a , p = lst, cur = ++tot; n   mx[cur] = mx[lst] + 1, lst = cur; n   while (p && !ch[p][x]) ch[p][x] = cur, p = fa[p]; n   if (!p) { n     fa[cur] = rt; n     return; n   } n   int q = ch[p][x]; n   if (mx[q] == mx[p] + 1) { n     fa[cur] = q; n     return; n   } n   int nq = ++tot; n   copy(nq, q); n   mx[nq] = mx[p] + 1, fa[q] = fa[cur] = nq; n   while (p && ch[p][x] == q) ch[p][x] = nq, p = fa[p]; n } n void update(int &u, const int l, const int r, const int pos) { n   if (!u) u = ++siz; n   if (l == r) { n     s[u] = true; n     return; n   } n   int mid = l + r >> 1; n   if (pos <= mid) n     update(lch[u], l, mid, pos); n   else n     update(rch[u], mid + 1, r, pos); n   upt(u); n } n bool query(const int u, const int l, const int r, const int segL, n            const int segR) { n   if (!u) return false; n   if (segL <= l && r <= segR) return s[u]; n   int mid = l + r >> 1, ret = false; n   if (segL <= mid) ret |= query(lch[u], l, mid, segL, segR); n   if (mid < segR) ret |= query(rch[u], mid + 1, r, segL, segR); n   return ret; n } n int merg(int u, int v) { n   if (!u || !v) return u + v; n   int cur = ++siz; n   lch[cur] = merg(lch[u], lch[v]); n   rch[cur] = merg(rch[u], rch[v]); n   s[cur] = s[u] | s[v]; n   return cur; n } n void DFS(const int u) { n   seq[++ID] = u; n   for (int i = head[u], v; i; i = Graph[i].nxt) { n     DFS(v = Graph[i].to); n     rot[u] = merg(rot[u], rot[v]); n     fir[u] = MIN(fir[u], fir[v]); n   } n } n int main() { n   rt = lst = ++tot; n   memset(fir, 0x3f, sizeof fir); n   read(N), scanf( %s , S + 1); n   for (int i = 1; i <= N; i++) n     expand(S[i]), update(rot[lst], 1, N, i), fir[lst] = i; n   for (int i = 2; i <= tot; i++) addEdge(fa[i], i); n   DFS(rt); n   lg2 = log2(tot); n   for (int i = 1; i <= tot; i++) f[i][0] = fa[i]; n   for (int j = 1; j <= lg2; j++) n     for (int i = 1; i <= tot; i++) f[i][j] = f[f[i][j - 1]][j - 1]; n   for (int i = tot, u, p; i; i--) { n     u = p = seq[i]; n     for (int k = lg2; ~k; k--) n       if (f[p][k] > rt && n           !query(rot[f[p][k]], 1, N, fir[u] - mx[u] + mx[f[p][k]], fir[u] - 1)) n         p = f[p][k]; n     p = fa[p]; n     dp[p] = MAX(dp[p], dp[u] + 1); n   } n   write(dp[rt]), putchar(  n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, result = 0; n   { n     cin >> n; n     float init = sqrt(n); n     if (init == floor(init)) n       cout << init * 4 << endl; n     else { n       int init2 = floor(init); n       n = n - init2 * init2; n       result = init2 * 4; n       if (n > init2) { n         int temp1 = n / 2; n         result = result + (temp1 + 1) * 2 - temp1 * 2; n         int temp2 = n - n / 2; n         result = result + (temp2 + 1) * 2 - temp2 * 2; n       } else n         result = result + (n + 1) * 2 - n * 2; n       cout << result << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long FASTIO = []() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   return 0; n }(); n long long n; n vector<vector<long long>> ans; n long long ask(long long x1, long long y1, long long x2, long long y2) { n   cout <<  ?   << x1 <<     << y1 <<     << x2 <<     << y2 <<   n ; n   cout.flush(); n   long long c; n   cin >> c; n   if (c == -1) { n     while (1) { n     } n   } n   return c; n } n void bfs(long long x, long long y) { n   vector<vector<long long>> used(n + 5, vector<long long>(n + 5, true)); n   vector<long long> v1 = {2, 1, 0, 0, -1, -2}; n   vector<long long> v2 = {0, 1, 2, -2, -1, 0}; n   for (long long i = 1; i <= n; i++) { n     for (long long j = 1; j <= n; j++) { n       used[i][j] = false; n     } n   } n   queue<pair<long long, long long>> q; n   q.push({x, y}); n   used[x][y] = true; n   while (!q.empty()) { n     long long X = q.front().first; n     long long Y = q.front().second; n     q.pop(); n     for (long long i = 0; i < 6; i++) { n       if (X + v1[i] > 0 && Y + v2[i] > 0 && !used[X + v1[i]][Y + v2[i]]) { n         pair<long long, long long> a = {X, Y}, b = {X + v1[i], Y + v2[i]}; n         if (v1[i] < 0 || v2[i] < 0) { n           swap(a, b); n         } n         if (b != pair<long long, long long>{n, n}) { n           bool t = ask(a.first, a.second, b.first, b.second); n           if (t) { n             ans[X + v1[i]][Y + v2[i]] = ans[X][Y]; n           } else { n             ans[X + v1[i]][Y + v2[i]] = !ans[X][Y]; n           } n         } n         used[X + v1[i]][Y + v2[i]] = true; n         q.push({X + v1[i], Y + v2[i]}); n       } n     } n   } n } n signed main() { n   cin >> n; n   ans.resize(n + 10, vector<long long>(n + 10, -1)); n   ans[1][1] = 1; n   ans[n][n] = 0; n   bfs(1, 1); n   long long p = 1; n   while (ans[p][p] == ans[p + 2][p + 2]) { n     ++p; n   } n   if (ask(p, p, p + 2, p + 1)) { n     ans[p + 2][p + 1] = ans[p][p]; n     bfs(p + 2, p + 1); n   } else if (ask(p + 1, p, p + 2, p + 2)) { n     ans[p + 1][p] = ans[p + 2][p + 2]; n     bfs(p + 1, p); n   } else { n     if (ans[p + 2][p] == 1) { n       ans[p + 2][p + 1] = 0; n       bfs(p + 2, p + 1); n     } else { n       ans[p + 1][p] = 1; n       bfs(p + 1, p); n     } n   } n   cout <<  ! n ; n   for (long long i = 1; i <= n; i++) { n     for (long long j = 1; j <= n; j++) { n       cout << ans[i][j]; n     } n     cout <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, l[2005], r[2005], t, k; n   cin >> t; n   while (t) { n     int q = 0, next = 0; n     cin >> n; n     for (int i = 0; i < n; i++) { n       cin >> l[i] >> r[i]; n       if (i == 0) { n         next = l[i] + 1; n         cout << l[i] <<    ; n         continue; n       } n       if (r[i] < next) { n         cout << 0 <<    ; n       } else if (l[i] <= next) { n         cout << next <<    ; n         next++; n       } else { n         cout << l[i] <<    ; n         next = l[i] + 1; n       } n     } n     cout << endl; n     t--; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, a[500005], b[500005]; n char s[500005]; n int res = 1e9, xx, yy; n int calc2(int x, int y) { n   if (x == 0 && y == 0) return 1000000000; n   int ans = 0; n   for (int i = 1; i <= n; i++) { n     if (x <= a[i] && y <= b[i]) n       ans = max(ans, max(a[i] - x, b[i] - y)); n     else if (x <= a[i] || y <= b[i]) n       ans = max(ans, abs(a[i] - x) + abs(b[i] - y)); n     else n       ans = max(ans, max(x - a[i], y - b[i])); n   } n   if (ans < res) { n     res = ans; n     xx = x, yy = y; n   } n   return ans; n } n int calc1(int x) { n   int l = 0, r = 500000; n   if (x == 0) l = 1; n   while (l <= r) { n     int mid = (l + r) >> 1; n     if (calc2(x, mid) < calc2(x, mid + 1)) n       r = mid - 1; n     else n       l = mid + 1; n   } n   return min(calc2(x, l), calc2(x, r)); n } n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) { n     scanf( %s , s + 1); n     int x = (int)strlen(s + 1); n     for (int j = 1; j <= x; j++) { n       if (s[j] ==  N ) n         a[i]++; n       else n         b[i]++; n     } n   } n   int l = 0, r = 500000; n   while (l <= r) { n     int mid = (l + r) >> 1; n     int v1 = calc1(mid), v2 = calc1(mid + 1); n     if (v1 < v2) n       r = mid - 1; n     else if (v1 > v2) n       l = mid + 1; n     else { n       int v3 = calc1(mid + 2); n       if (v1 < v3) n         r = mid - 1; n       else if (v1 > v3) n         l = mid + 1; n       else n         break; n     } n   } n   printf( %d n , res); n   for (int i = 1; i <= xx; i++) putchar( N ); n   for (int i = 1; i <= yy; i++) putchar( B ); n   printf(  n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int n, num, l, r; n   string str, res; n   cin >> n; n   l = 1e9; n   l = l * (-2); n   r = 1e9; n   r = r * (2); n   while (n--) { n     cin >> str >> num >> res; n     if (str ==  > ) { n       if (res ==  Y ) n         l = max(l, num + 1); n       else n         r = min(r, num); n     } else if (str ==  >= ) { n       if (res ==  Y ) n         l = max(l, num); n       else n         r = min(r, num - 1); n     } else if (str ==  < ) { n       if (res ==  Y ) n         r = min(r, num - 1); n       else n         l = max(l, num); n     } else { n       if (res ==  Y ) n         r = min(r, num); n       else n         l = max(l, num + 1); n     } n   } n   if (l > r) n     cout <<  Impossible ; n   else n     cout << l; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bitset<1005> b[1005]; n int n, m; n bool ok2(int r, int c) { n   if (r + 2 > n || c + 2 > n) return false; n   for (int i = r; i < r + 3; i++) n     for (int j = c; j < c + 3; j++) { n       if (!b[i].test(j)) return false; n     } n   return true; n } n bool ok(int r, int c) { n   if (n < 3) return false; n   for (int i = r - 2; i <= r; i++) { n     if (i <= 0) continue; n     for (int j = c - 2; j <= c; j++) { n       if (j <= 0) continue; n       if (ok2(i, j)) return true; n     } n   } n   return false; n } n int main() { n   int r, c; n   bool bOK = false; n   scanf( %d%d , &n, &m); n   for (int i = 1; i <= m; i++) { n     scanf( %d%d , &r, &c); n     b[r].set(c); n     if (ok(r, c)) { n       bOK = true; n       printf( %d n , i); n       break; n     } n   } n   if (!bOK) printf( -1 n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, q; n vector<int> colors[100013]; n unordered_map<int, vector<int> > adj[100013]; n unordered_map<int, int> p[100013]; n unordered_map<int, int> h[100013]; n pair<int, int> visited[100013]; n unordered_map<int, int> precalc[100013]; n int BIG = 200; n int findSet(int x, int c) { n   return p[x][c] == x ? x : p[x][c] = findSet(p[x][c], c); n } n void mergeSet(int a, int b, int c) { n   int r1 = findSet(a, c), r2 = findSet(b, c); n   if (r1 != r2) { n     if (h[r1][c] < h[r2][c]) n       p[r1][c] = r2; n     else if (h[r1][c] > h[r2][c]) n       p[r2][c] = r1; n     else n       p[r1][c] = r2, h[r2][c] += 1; n   } n } n bool sameSet(int a, int b, int c) { return findSet(a, c) == findSet(b, c); } n void dfs(int x, int c, int start) { n   visited[x] = make_pair(start + 1, c); n   precalc[start][x] += 1; n   for (int i = 0; i < adj[x][c].size(); i++) n     if (visited[adj[x][c][i]] != make_pair(start + 1, c)) n       dfs(adj[x][c][i], c, start); n } n int main() { n   scanf( %d%d , &n, &m); n   for (int i = 0; i < m; i++) { n     int a, b, c; n     scanf( %d%d%d , &a, &b, &c); n     a -= 1; n     b -= 1; n     if (!p[a].count(c)) p[a][c] = a, h[a][c] = 0, colors[a].push_back(c); n     if (!p[b].count(c)) p[b][c] = b, h[b][c] = 0, colors[b].push_back(c); n     mergeSet(a, b, c); n     adj[a][c].push_back(b); n     adj[b][c].push_back(a); n   } n   for (int i = 0; i < n; i++) n     if (colors[i].size() >= BIG) n       for (int j = 0; j < colors[i].size(); j++) dfs(i, colors[i][j], i); n   scanf( %d , &q); n   for (int i = 0; i < q; i++) { n     int u, v; n     scanf( %d%d , &u, &v); n     u -= 1; n     v -= 1; n     if (colors[u].size() >= BIG) n       printf( %d n , precalc[u][v]); n     else if (colors[v].size() >= BIG) n       printf( %d n , precalc[v][u]); n     else { n       int ans = 0; n       if (colors[u].size() < colors[v].size()) { n         for (int i = 0; i < colors[u].size(); i++) n           if (p[v].count(colors[u][i]) && sameSet(u, v, colors[u][i])) ans += 1; n       } else n         for (int i = 0; i < colors[v].size(); i++) n           if (p[u].count(colors[v][i]) && sameSet(u, v, colors[v][i])) ans += 1; n       printf( %d n , ans); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long int n, a, b; n int main() { n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> a >> b; n     cout << a + b << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( Ofast,no-stack-protector,unroll-loops ) n #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native ) n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   long long t; n   cin >> t; n   while (t--) { n     long long n; n     cin >> n; n     long long a[n]; n     for (long long i = 0; i < n; i++) { n       cin >> a[i]; n     } n     long long b[n]; n     for (long long i = 0; i < n; i++) { n       if (i % 2) { n         if (a[i] >= 0) n           b[i] = a[i]; n         else n           b[i] = -a[i]; n       } else { n         if (a[i] <= 0) n           b[i] = a[i]; n         else n           b[i] = -a[i]; n       } n       cout << b[i] <<    ; n     } n     cout <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   int n, i, j; n   int a[110][110]; n   long long ans[150]; n   while (scanf( %d , &n) != EOF) { n     for (i = 1; i <= n; i++) n       for (j = 1; j <= n; j++) scanf( %d , &a[i][j]); n     memset(ans, 0, sizeof(ans)); n     for (i = 1; i <= n; i++) { n       for (j = 1; j <= n; j++) { n         if (i == j) continue; n         if (a[i][j] == -1) continue; n         ans[i] = ans[i] | a[i][j]; n       } n     } n     for (i = 1; i <= n; i++) n       if (i == 1) n         printf( %I64d , ans[i]); n       else n         printf(  %I64d , ans[i]); n     printf(  n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int n, a, i, sum = 0, k, l = 10000000000; n   cin >> n; n   for (i = 1; i <= n; i++) { n     cin >> a; n     sum += a; n     if (a % 2) l = min(l, a); n   } n   if (sum % 2 == 1) sum -= l; n   cout << sum << endl; n } n


#include <bits/stdc++.h> n using namespace std; n long long q, t; n bool f(long long x) { n   for (long long i = 2; i * i <= x; i++) n     if (x % i == 0) return false; n   return true; n } n int main() { n   ios::sync_with_stdio(false); n   cin >> q; n   while (q--) { n     long long ans = 0; n     cin >> t; n     { n       if (t == 2) { n         cout << -1 << endl; n         continue; n       } n       if (t == 9) { n         cout << 1 << endl; n         continue; n       } n       if (t % 2 == 1) { n         t -= 9; n         if (t < 4) { n           cout << -1 << endl; n           continue; n         } else n           ans++; n       } n       if (t % 4 == 0) n         cout << t / 4 + ans << endl; n       else if (t % 4 == 2) n         cout << t / 4 + ans << endl; n       else if (t % 6 == 0) n         cout << t / 6 + ans << endl; n       else if (t % 6 == 4) n         cout << t / 6 + 1 + ans << endl; n       else n         cout << 1 << endl; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n const int maxn = 200005; n int v[maxn], fa[maxn], ans[maxn], num[maxn]; n int n, m; n int findset(int x) { n   if (fa[x] != x) { n     fa[x] = findset(fa[x]); n   } n   return fa[x]; n } n void _union(int x, int y) { n   int p = findset(x); n   int q = findset(y); n   if (p != q) { n     fa[p] = q; n   } n } n int main() { n   int a, x, y; n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) { n     scanf( %d , &v[i]); n     num[i] = v[i]; n     fa[i] = i; n   } n   fa[n + 1] = n + 1; n   scanf( %d , &m); n   while (m--) { n     scanf( %d , &a); n     if (a == 1) { n       scanf( %d%d , &x, &y); n       while (y > 0) { n         x = findset(x); n         if (x == n + 1) break; n         if (num[x] > y) { n           ans[x] += y; n           num[x] -= y; n           y = 0; n         } else { n           y -= num[x]; n           ans[x] = v[x]; n           num[x] = 0; n           _union(x, x + 1); n         } n       } n     } else if (a == 2) { n       scanf( %d , &x); n       printf( %d n , ans[x]); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   string s; n   cin >> s; n   bool f = 0; n   long last = -1, c = 0; n   long ans = 0; n   for (register int i = 0; i < s.length(); i++) { n     if (s[i] ==  F ) { n       if (last == -1) { n         last = i; n       } else { n         last = max(i - c, (last == 0) ? 0 : last + 1); n       } n       ans = max(ans, last); n       c++; n     } n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, ara[100005], i, j, k, ind, mx, sum, ans, ans1; n int main() { n   cin >> n; n   for (i = 0; i < n; i++) { n     cin >> ara[i]; n   } n   for (i = 0; i < n; i++) { n     if (ara[i] >= k) { n       k = ara[i]; n       ind = i; n     } n   } n   for (i = 0; i < n; i++) { n     if (i != ind) { n       sum += ara[i]; n     } n   } n   if (k >= sum) n     ans = k - sum + 1; n   else n     ans = sum - k + 1; n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n signed main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   string s, t; n   cin >> s >> t; n   int64_t n = s.size(); n   int64_t m = t.size(); n   vector<vector<int64_t>> dp(n + 1, vector<int64_t>(n + 1, 0)); n   dp[0] = vector<int64_t>(n + 1, 1); n   for (int64_t i = 1; i <= n; i++) { n     for (int64_t j = 0; j < n; j++) { n       if (j < n && (j >= m || (t[j] == s[i - 1]))) { n         dp[i][j] += dp[i - 1][j + 1]; n       } n       if (j + i <= n && (j + i - 1 >= m || t[j + i - 1] == s[i - 1])) { n         dp[i][j] += dp[i - 1][j]; n       } n       dp[i][j] %= 998244353; n     } n   } n   int64_t res = 0; n   for (int64_t i = m; i <= n; i++) { n     res = (res + dp[i][0]) % 998244353; n   } n   cout << res <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n bool isprime(unsigned long long n) { n   if (n <= 1) return false; n   if (n <= 3) return true; n   if (n % 2 == 0 || n % 3 == 0) return false; n   for (unsigned long long i = 5; i * i <= n; i = i + 6) n     if (n % i == 0 || n % (i + 2) == 0) return false; n   return true; n } n long long int gcd(long long int a, long long int b) { n   if (b == 0) n     return a; n   else n     return gcd(b, a % b); n } n long long int exp(long long int value, long long int power) { n   long long int result = 1; n   while (power > 0) { n     if (power & 1LL) { n       result *= value; n       result %= 1000000007; n     } n     value *= value; n     value %= 1000000007; n     power /= 2LL; n   } n   return result; n } n long long int lcm(long long n1, long long n2) { n   long long max = (n1 > n2) ? n1 : n2; n   do { n     if (max % n1 == 0 && max % n2 == 0) { n       return max; n     } else n       ++max; n   } while (true); n } n int isprime(long long n) { n   if (n <= 3) return 1; n   if (n % 2 == 0 || n % 3 == 0) return 0; n   for (long long i = 5; i * i <= n; i += 6) { n     if (n % i == 0 || n % (i + 2) == 0) return 0; n   } n   return 1; n } n long long a[100005]; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(NULL); n   cout.tie(NULL); n   long long int f, cnt, len, p, q, r, t, i, j, k, l, n, m, x, y, z, b, c, s; n   cin >> n; n   n -= 10; n   x = 0; n   if (n == 1) x = 4; n   if (n == 2) x = 4; n   if (n == 3) x = 4; n   if (n == 4) x = 4; n   if (n == 5) x = 4; n   if (n == 6) x = 4; n   if (n == 7) x = 4; n   if (n == 8) x = 4; n   if (n == 9) x = 4; n   if (n == 10) x = 15; n   if (n == 11) x = 4; n   cout << x; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n map<string, int> m; n int main() { n   int n, ans = 0; n   string str; n   scanf( %d , &n); n   for (int i = 0; i < n; i++) { n     cin >> str; n     m[str]++; n     ans = max(ans, m[str]); n   } n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m; n struct pos { n   long long x, y; n   bool operator<(const pos &p) const { n     if (x != p.x) return x < p.x; n     return y < p.y; n   } n } A[200005], stk[200005]; n bool check(pos a, pos b, pos c) { n   return (c.y - a.y) * (b.x - c.x) <= (b.y - c.y) * (c.x - a.x); n } n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) { n     long long x, y; n     scanf( %lld%lld , &x, &y); n     y -= x * x, A[i] = (pos){x, y}; n   } n   sort(A + 1, A + n + 1); n   int cnt = 0; n   for (int i = 1; i <= n; i++) { n     if (i != n && A[i].x == A[i + 1].x) continue; n     while (cnt > 1 && check(stk[cnt - 1], A[i], stk[cnt])) cnt--; n     stk[++cnt] = A[i]; n   } n   printf( %d n , cnt - 1); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct fast_ios { n   fast_ios() { n     cin.tie(0); n     ios::sync_with_stdio(false); n     cout << fixed << setprecision(20); n   }; n } fast_ios_; n template <typename T> n istream &operator>>(istream &is, vector<T> &v) { n   for (auto &x : v) is >> x; n   return is; n } n template <typename T> n ostream &operator<<(ostream &os, vector<T> &v) { n   for (long long i = 0; i < v.size(); i++) { n     cout << v[i]; n     if (i != v.size() - 1) cout << endl; n   }; n   return os; n } n template <typename T1, typename T2> n ostream &operator<<(ostream &os, pair<T1, T2> p) { n   cout <<  (  << p.first <<  ,  << p.second <<  ) ; n   return os; n } n template <typename T> n void Out(T x) { n   cout << x << endl; n } n template <typename T1, typename T2> n void chOut(bool f, T1 y, T2 n) { n   if (f) n     Out(y); n   else n     Out(n); n } n using vec = vector<long long>; n using mat = vector<vec>; n using Pii = pair<long long, long long>; n using v_bool = vector<bool>; n using v_Pii = vector<Pii>; n long long dx[4] = {1, 0, -1, 0}; n long long dy[4] = {0, 1, 0, -1}; n const long long mod = 1000000007; n void imp() { n   Out( Not unique ); n   exit(0); n } n signed main() { n   long long n, m; n   cin >> n >> m; n   vector<string> s(n); n   cin >> s; n   queue<Pii> que; n   long long S = 0; n   for (long long i = (0); i < (n); i++) n     for (long long j = (0); j < (m); j++) n       if (s[i][j] ==  . ) { n         S++; n         long long cnt = 0; n         for (long long k = (0); k < (4); k++) { n           long long x = i + dx[k], y = j + dy[k]; n           if (x >= 0 && x < n && y >= 0 && y < m && s[x][y] ==  . ) cnt++; n         } n         if (cnt == 1) que.push(Pii(i, j)); n       } n   while (!que.empty()) { n     long long i = que.front().first, j = que.front().second; n     que.pop(); n     if (s[i][j] !=  . ) continue; n     long long k0 = -1; n     for (long long k = (0); k < (4); k++) { n       long long x = i + dx[k], y = j + dy[k]; n       if (x >= 0 && x < n && y >= 0 && y < m && s[x][y] ==  . ) { n         k0 = k; n         break; n       } n     } n     if (k0 == -1) imp(); n     long long i2 = i + dx[k0], j2 = j + dy[k0]; n     if (k0 == 0) n       s[i][j] =  ^ , s[i2][j2] =  v ; n     else if (k0 == 1) n       s[i][j] =  < , s[i2][j2] =  > ; n     else if (k0 == 2) n       s[i][j] =  v , s[i2][j2] =  ^ ; n     else if (k0 == 3) n       s[i][j] =  > , s[i2][j2] =  < ; n     S -= 2; n     for (long long k = (0); k < (4); k++) { n       long long i3 = i2 + dx[k], j3 = j2 + dy[k]; n       if (i3 >= 0 && i3 < n && j3 >= 0 && j3 < m && s[i3][j3] ==  . ) { n         long long cnt = 0; n         for (long long k3 = (0); k3 < (4); k3++) { n           long long x = i3 + dx[k3], y = j3 + dy[k3]; n           if (x >= 0 && x < n && y >= 0 && y < m && s[x][y] ==  . ) cnt++; n         } n         if (cnt == 1) que.push(Pii(i3, j3)); n       } n     } n   } n   if (S != 0) n     imp(); n   else n     Out(s); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int b[101]; n int main() { n   int n, x; n   cin >> n >> x; n   int a[n + 1]; n   for (int i = 1; i <= n; i++) { n     cin >> a[i]; n     b[a[i]]++; n   } n   int t = 0; n   for (int i = 0; i < x; i++) { n     if (b[i] == 0) { n       t++; n     } n   } n   if (b[x] == 1) t++; n   cout << t; n } n


#include <bits/stdc++.h> n using namespace std; n int n, m, t; n int data[105][3]; n bitset<50> mark; n set<pair<long long, long long> > ss; n struct Node { n   pair<long long, long long> g; n   void reset() { g.first = g.second = 0; } n   void set(int x) { n     if (x < 50) n       g.first |= 1ll << x; n     else n       g.second |= 1ll << (x - 50); n   } n   void reset(int x) { n     if (x < 50) n       g.first &= (-1ll) ^ (1ll << x); n     else n       g.second |= (-1ll) ^ (1ll << (x - 50)); n   } n   bool test(int x) { n     if (x < 50) n       return (g.first & (1ll << x)); n     else n       return (g.second & (1ll << (x - 50))); n   } n   int key; n   friend bool operator<(const Node &a, const Node &b) { return a.key > b.key; } n } tmp; n priority_queue<Node> que; n int main() { n   scanf( %d%d%d , &n, &m, &t); n   for (int i = 0; i < m; i++) n     scanf( %d%d%d , &data[i][0], &data[i][1], &data[i][2]); n   tmp.reset(); n   tmp.key = 0; n   que.push(tmp); n   int ans, tt = 0; n   while (t--) { n     if (que.empty()) { n       ans = -1; n       break; n     } n     tmp = que.top(); n     que.pop(); n     ans = tmp.key; n     mark.reset(); n     for (int i = 0; i < m; i++) n       if (tmp.test(i)) { n         mark.set(data[i][0]), mark.set(data[i][1] + n); n       } n     for (int i = 0; i < m; i++) n       if (!mark.test(data[i][0]) && !mark.test(data[i][1] + n)) { n         tmp.set(i); n         tmp.key += data[i][2]; n         if (ss.find(tmp.g) == ss.end()) { n           ss.insert(tmp.g); n           que.push(tmp); n         } n         tmp.key -= data[i][2]; n         tmp.reset(i); n       } n   } n   printf( %d n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 200005; n const int z = N * 32; n int n, a[N], f[N], rt; n int pool[z], tp, cnt, ch[z][2]; n long long ans; n int fa(int x) { n   if (x == f[x]) return x; n   return f[x] = fa(f[x]); n } n void uni(int x, int y) { n   x = fa(x), y = fa(y); n   if (x == y) return; n   f[x] = y; n } n int newnode() { n   if (!tp) return ++cnt; n   return pool[tp--]; n } n void ins(int v) { n   int no = rt, x; n   for (register int i = 30; i >= 0; --i) { n     if (v & (1 << i)) n       x = 1; n     else n       x = 0; n     if (!ch[no][x]) ch[no][x] = newnode(); n     no = ch[no][x]; n   } n } n void clr(int x) { n   if (ch[x][0]) clr(ch[x][0]); n   if (ch[x][1]) clr(ch[x][1]); n   pool[++tp] = x; n   ch[x][0] = ch[x][1] = 0; n } n int find_min(int v) { n   int no = rt, ans = 0, x; n   for (register int i = 30; i >= 0; --i) { n     if (v & (1 << i)) n       x = 1; n     else n       x = 0; n     if (!ch[no][x]) n       ans = ans * 2 + 1, no = ch[no][x ^ 1]; n     else n       ans = ans * 2, no = ch[no][x]; n   } n   return ans; n } n void solve(vector<int> x, int d) { n   int s = x.size(); n   if (s <= 1) return; n   if (d == -1) { n     int no = x[0]; n     for (register int i = 1; i < s; ++i) { n       uni(no, x[i]); n       no = x[i]; n     } n     return; n   } n   vector<int> l, r; n   int no; n   for (register int i = 0; i < s; ++i) { n     no = x[i]; n     if (a[no] & (1 << d)) n       l.push_back(no); n     else n       r.push_back(no); n   } n   solve(l, d - 1); n   solve(r, d - 1); n   int sl = l.size(), sr = r.size(); n   if (sl == 0 || sr == 0) return; n   int q = (1 << d) - 1; n   rt = newnode(); n   for (register int i = 0; i < sl; ++i) { n     no = l[i]; n     ins(a[no] & q); n   } n   int f = a[l[0]] ^ a[r[0]]; n   for (register int i = 0; i < sr; ++i) { n     no = r[i]; n     f = min(f, find_min(a[no] & q)); n   } n   uni(l[0], r[0]); n   clr(rt); n   ans += f + (1 << d); n } n int main() { n   scanf( %d , &n); n   vector<int> c; n   for (register int i = 1; i <= n; ++i) { n     scanf( %d , &a[i]); n     c.push_back(i); n   } n   solve(c, 29); n   printf( %lld , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int k, l; n int main() { n   int i, n; n   scanf( %d , &n); n   getchar(); n   char ch[1000]; n   scanf( %s , ch); n   for (i = 0; i < n; ++i) { n     if (ch[i] ==  0 ) n       k++; n     else n       l++; n   } n   if (n % 2 == 1 || k != l) { n     printf( 1 n%s n , ch); n     return 0; n   } n   cout << 2 << endl; n   for (i = 0; i < n; ++i) { n     printf( %c , ch[i]); n     if (ch[i] ==  0 ) n       k--; n     else n       l--; n     if (k == 0 || l == 0) break; n   } n   i++; n   cout <<    ; n   for (int j = i; j < n; ++j) printf( %c , ch[j]); n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, m, A[300005], fix[300005], fix1[300005], B[300005], C[300005]; n long long BITree[900005], BITree1[900005]; n long long getSum(long long index) { n   long long sum = 0; n   index = index + 1; n   while (index > 0) { n     sum += BITree[index]; n     index -= index & (-index); n   } n   return sum; n } n void updateBIT(long long index, long long val) { n   index = index + 1; n   while (index <= n + 10) { n     BITree[index] += val; n     index += index & (-index); n   } n } n long long getSum1(long long index) { n   long long sum = 0; n   index = index + 1; n   while (index > 0) { n     sum += BITree1[index]; n     index -= index & (-index); n   } n   return sum; n } n void updateBIT1(long long index, long long val) { n   index = index + 1; n   while (index <= m + 10) { n     BITree1[index] += val; n     index += index & (-index); n   } n } n int main() { n   cin >> n >> m; n   for (long long i = 1; i <= m; i++) { n     cin >> A[i]; n     if (fix[A[i]] == 0) updateBIT(A[i], 1); n     fix[A[i]] = 1; n     if (C[A[i]] != 0) { n       C[A[i]] = max(C[A[i]], A[i] - fix1[A[i]] - 1 + 1); n       C[A[i]] = max(C[A[i]], getSum1(i - 1) - getSum1(fix1[A[i]]) + 1); n       updateBIT1(fix1[A[i]], -1); n       updateBIT1(i, 1); n     } else { n       C[A[i]] = A[i] + getSum(n) - getSum(A[i]); n       updateBIT1(i, 1); n     } n     fix1[A[i]] = i; n   } n   for (long long i = n; i >= 1; i--) { n     B[i] = B[i + 1] + fix[i]; n   } n   for (long long i = 1; i <= n; i++) { n     if (fix[i] == 0) { n       cout << i <<     << i + B[i]; n     } else { n       cout << 1 <<     << max(C[i], getSum1(m) - getSum1(fix1[i]) + 1); n     } n     cout << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int inv = numeric_limits<int>::max(); n const int minv = numeric_limits<int>::min(); n const int max_n = 500010; n int n; n int a[max_n]; n int b[max_n] = {0}; n int main() { n   scanf( %d , &n); n   for (int i = 0; i < n; ++i) scanf( %d , &a[i]); n   int c = 0; n   for (int i = n - 2; i >= 0; --i) { n     if (i > 0 and a[i - 1] != a[i] and a[i] != a[i + 1]) n       ++c; n     else { n       b[i + 1] = c; n       c = 0; n     } n   } n   int res = 0; n   for (int i = 1; i <= n - 2; ++i) n     if (b[i] > 0) { n       res = max(res, (b[i] + 1) / 2); n       if (b[i] & 1) n         for (int j = i; j < i + b[i]; ++j) a[j] = a[i - 1]; n       else { n         for (int j = i; j < i + b[i] / 2; ++j) a[j] = a[i - 1]; n         for (int j = i + b[i] / 2; j < i + b[i]; ++j) a[j] = a[i + b[i]]; n       } n     } n   printf( %d n , res); n   for (int i = 0; i < n; ++i) printf( %d  , a[i]); n   printf(  n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct edge { n   long long from, to, w; n   edge(int from, int to, long long w) : from(from), to(to), w(w) {} n   bool operator<(const edge& e) const { return ((w > e.w)); } n }; n void O_o() { n   ios::sync_with_stdio(0); n   ios_base::sync_with_stdio(0); n   cin.tie(0), cout.tie(0); n } n bool valid(long long i, long long j, long long n, long long m) { n   return (i >= 0 && i < n && j >= 0 && j < m); n } n long long n, k, a, b; n vector<long long> vec; n bool ok(long long x) { n   long long cnt = 999999999; n   multimap<int, pair<int, int> > mm; n   for (int i = x; i < n + 1; i++) { n     cnt = x - vec[i] + vec[i - x]; n     if (cnt <= k) { n       b = i, a = i - x + 1; n       return 1; n     } n   } n   return 0; n } n int main() { n   O_o(); n   cin >> n >> k; n   int arr[n + 5]; n   vec.push_back(0); n   for (int i = 1; i <= int(n); i++) { n     cin >> arr[i]; n     vec.push_back(arr[i] + vec.back()); n   } n   long long second = 0, e = 1e9, ans = 2e9 + 7, x = 0, y = 0, i = 65; n   while (second < e) { n     long long mid = (second + e) >> 1; n     if (ok(mid)) { n       second = mid + 1; n     } else n       e = mid - 1; n   } n   second -= 3; n   while (ok(second)) ++second; n   second--; n   ok(second); n   cout << second << endl; n   for (int i = 1; i <= int(n); i++) { n     if (i >= a && i <= b) n       cout <<  1  ; n     else n       cout << arr[i] <<    ; n   } n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long mod = (long long)(1e13) + 7LL; n long long osn = 137LL; n long long getHash(string &s) { n   long long res = 0LL, curr = osn; n   for (int i = 0; i < s.size(); i++) { n     if (s[i] >= 65 && s[i] <= 90) s[i] += 32; n     if (s[i] ==  o ) s[i] =  0 ; n     if (s[i] ==  l  || s[i] ==  i ) s[i] =  1 ; n     res += curr * (long long)(s[i]); n     curr *= osn; n   } n   return res; n } n int main() { n   string s, t; n   long long s_hash; n   cin >> s; n   s_hash = getHash(s); n   int n; n   cin >> n; n   for (int i = 0; i < n; i++) { n     cin >> t; n     if (getHash(t) == s_hash) { n       cout <<  No ; n       return 0; n     } n   } n   cout <<  Yes ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 2e5 + 5; n vector<int> circuit; n vector<int> e[MAXN]; n void calc(int v) { n   stack<int> s; n   while (true) { n     if (((int)e[v].size()) == 0) { n       circuit.push_back(v); n       if (!((int)s.size())) { n         break; n       } n       v = s.top(); n       s.pop(); n     } else { n       s.push(v); n       int u = e[v].back(); n       e[v].pop_back(); n       v = u; n     } n   } n } n int a[MAXN]; n int b[MAXN]; n int c[MAXN]; n vector<int> comp; n unordered_map<int, int> act; n unordered_map<long long, vector<int> > pos; n bool bio[MAXN]; n void dfs(int v) { n   if (bio[v]) return; n   bio[v] = true; n   for (auto w : e[v]) { n     dfs(w); n   } n } n vector<vector<int> > ans; n vector<vector<int> > sol; n int s; n void solve(vector<int> &start) { n   int uk = 0; n   for (auto x : start) { n     calc(x); n     uk += ((int)circuit.size()) - 1; n     reverse(circuit.begin(), circuit.end()); n     ans.push_back(circuit); n     circuit.clear(); n   } n   if (uk > s) { n     cout << -1; n     exit(0); n   } n   for (auto v : ans) { n     vector<int> nv; n     for (int i = 0; i < ((int)v.size()) - 1; ++i) { n       int x = v[i]; n       int y = v[i + 1]; n       assert(((int)pos[(long long)x * MAXN + y].size()) > 0); n       nv.push_back(pos[(long long)x * MAXN + y].back()); n       pos[(long long)x * MAXN + y].pop_back(); n     } n     sol.push_back(nv); n   } n } n int main() { n   int n; n   cin >> n >> s; n   for (int i = 0; i < n; ++i) { n     cin >> a[i]; n     comp.push_back(a[i]); n   } n   sort(comp.begin(), comp.end()); n   comp.erase(unique(comp.begin(), comp.end()), comp.end()); n   for (int i = 0; i < ((int)comp.size()); ++i) { n     act[comp[i]] = i; n   } n   for (int i = 0; i < n; ++i) { n     a[i] = act[a[i]]; n     b[i] = a[i]; n   } n   sort(b, b + n); n   for (int i = 0; i < n; ++i) { n     if (a[i] != b[i]) { n       e[b[i]].push_back(a[i]); n       pos[(long long)b[i] * MAXN + a[i]].push_back(i); n     } n   } n   vector<int> start; n   for (int i = 0; i < n; ++i) { n     if (!bio[b[i]] && ((int)e[b[i]].size())) { n       dfs(b[i]); n       start.push_back(b[i]); n     } n   } n   if (((int)start.size()) <= 2) { n     solve(start); n   } else { n     int uk = 0; n     for (auto x : start) { n       calc(x); n       uk += ((int)circuit.size()) - 1; n       circuit.clear(); n     } n     if (uk > s) { n       cout << -1; n       return 0; n     } n     for (int i = 0; i < n; ++i) { n       e[i].clear(); n     } n     for (int i = 0; i < n; ++i) { n       if (a[i] != b[i]) { n         e[b[i]].push_back(a[i]); n       } n     } n     int can = s - uk; n     can = min(((int)start.size()), can); n     vector<int> out; n     for (int i = 0; i < can; ++i) { n       int x = start[((int)start.size()) - i - 1]; n       out.push_back(pos[(long long)x * MAXN + e[x].back()].back()); n     } n     if (((int)out.size()) > 1) { n       sol.push_back(out); n     } n     for (int i = 0; i < can - 1; ++i) start.pop_back(); n     for (int i = 0; i < n; ++i) { n       c[i] = a[i]; n     } n     for (int i = 0; i < n; ++i) e[i].clear(); n     for (int i = 0; i < n; ++i) { n       if (a[i] != b[i]) { n         pos[(long long)b[i] * MAXN + a[i]].pop_back(); n       } n     } n     for (int i = 0; i < ((int)out.size()); ++i) { n       c[out[(i + 1) % ((int)out.size())]] = a[out[i]]; n     } n     for (int i = 0; i < n; ++i) { n       if (c[i] != b[i]) { n         e[b[i]].push_back(c[i]); n         pos[(long long)b[i] * MAXN + c[i]].push_back(i); n       } n     } n     solve(start); n   } n   cout << ((int)sol.size()) << endl; n   for (auto v : sol) { n     cout << ((int)v.size()) <<   n ; n     for (auto x : v) cout << x + 1 <<    ; n     cout <<   n ; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const long long maxn = 5050; n long long a[maxn]; n long long c[maxn]; n long long tag[maxn]; n long long number[maxn]; n int main() { n   long long i, j, k, n, m; n   while (scanf( %lld%lld , &n, &k) != EOF) { n     memset(tag, 0, sizeof(tag)); n     for (i = 1; i <= n; i++) { n       scanf( %lld , &a[i]); n       tag[a[i]]++; n     } n     for (i = 1; i <= 5000; i++) number[i] = 1; n     bool flag = true; n     for (i = 1; i <= 5000; i++) n       if (tag[i] > k) { n         flag = false; n         break; n       } n     if (!flag) n       printf( NO n ); n     else { n       long long cnt = 1; n       for (i = 1; i <= 5000; i++) { n         for (j = 1; j <= 5000; j++) n           if (a[j] == i) { n             c[j] = cnt; n             cnt++; n             if (cnt > k) cnt = 1; n           } n       } n       printf( YES n ); n       for (i = 1; i <= n; i++) printf( %lld  , c[i]); n       printf(  n ); n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, m, piles[100000], q; n   cin >> n; n   cin >> q; n   piles[0] = q; n   for (int i = int(1); i < int(n); i++) { n     cin >> q; n     piles[i] = piles[i - 1] + q; n   } n   cin >> m; n   for (int i = int(0); i < int(m); i++) { n     cin >> q; n     int ans = upper_bound(piles, piles + n, q) - piles; n     if (ans > 0 && piles[ans - 1] == q) ans--; n     ans++; n     cout << ans << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( Ofast,no-stack-protector,unroll-loops,fast-math,O3 ) n #pragma GCC target( sse,sse2,sse3,ssse3,sse4,sse4.2,popcnt,abm,mmx,avx ) n using namespace std; n template <class T> n istream& operator>>(istream& is, vector<T>& v) { n   for (auto& x : v) { n     is >> x; n   } n   return is; n } n template <class T> n ostream& operator<<(ostream& os, vector<T>& v) { n   for (auto& x : v) { n     os << x <<    ; n   } n   return os; n } n const int N = (1 << 20) + 1; n vector<pair<int, int>> eulerWalk(vector<vector<pair<int, int>>>& gr, int nedges, n                                  int src = 0) { n   int n = ((int)(gr.size())); n   static vector<int> D(N), its(N), eu(N); n   D.clear(), D.resize(n); n   its.clear(), its.resize(n); n   eu.clear(), eu.resize(nedges); n   static vector<pair<int, int>> s; n   s = {make_pair(src, -1)}; n   static vector<pair<int, int>> ret; n   ret.clear(); n   D[src]++; n   while (!s.empty()) { n     auto x = s.back(); n     int y, e, &it = its[x.first], end = ((int)(gr[x.first].size())); n     if (it == end) { n       ret.push_back(x); n       s.pop_back(); n       continue; n     } n     tie(y, e) = gr[x.first][it++]; n     if (!eu[e]) { n       D[x.first]--, D[y]++; n       eu[e] = 1; n       s.emplace_back(y, e); n     } n   } n   for (int x : D) n     if (x < 0 || ((int)(ret.size())) != nedges + 1) return {}; n   return {ret.rbegin(), ret.rend()}; n } n vector<vector<pair<int, int>>> graph(N); n vector<pair<int, int>> cycle; n bool valid(int k, const vector<pair<int, int>>& pearls) { n   graph.clear(); n   graph.resize((1 << k)); n   int src; n   for (int i = 0; i < ((int)(pearls.size())); ++i) { n     int u = (pearls[i].first & ((1 << k) - 1)); n     int v = (pearls[i].second & ((1 << k) - 1)); n     graph[u].emplace_back(v, i); n     graph[v].emplace_back(u, i); n     src = u; n   } n   cycle = eulerWalk(graph, pearls.size(), src); n   return !cycle.empty() && cycle.back().first == src; n } n int main() { n   ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); n   int n; n   cin >> n; n   vector<pair<int, int>> pearls(n); n   for (auto& p : pearls) { n     cin >> p.first >> p.second; n   } n   int res = 20; n   while (!valid(res, pearls)) { n     --res; n   } n   cout << res <<   n ; n   for (int i = 0; i < n; ++i) { n     int u = (pearls[i].first & ((1 << res) - 1)); n     int v = (pearls[i].second & ((1 << res) - 1)); n     pearls[i] = make_pair(u, v); n   } n   for (int i = 1; i <= n; ++i) { n     auto curr = cycle[i]; n     int prev_node = cycle[i - 1].first; n     int curr_edge = curr.second; n     if (pearls[curr_edge].first == prev_node && n         pearls[curr_edge].second == curr.first) { n       cout << 2 * curr_edge + 1 <<     << 2 * curr_edge + 2 <<    ; n     } else { n       cout << 2 * curr_edge + 2 <<     << 2 * curr_edge + 1 <<    ; n     } n   } n   cout <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void read_file(bool outToFile = true) {} n int n, m; n int A[1000 + 9][1000 + 9]; n long long K, sum; n int mrk = 0, to; n int vis[1000 + 9][1000 + 9] = {0}; n int di[] = {1, 0, -1, 0}; n int dj[] = {0, 1, 0, -1}; n set<int> usedAs[1000 + 9][1000 + 9]; n bool valid(int i, int j) { return 0 <= i && i < n && 0 <= j && j < m; } n bool flood(int i, int j) { n   if (!valid(i, j) || vis[i][j] == mrk || A[i][j] < to) return false; n   sum -= to; n   vis[i][j] = mrk; n   usedAs[i][j].insert(to); n   if (sum == 0) return true; n   for (int d = 0; d < 4; d++) n     if (flood(i + di[d], j + dj[d])) return true; n   return false; n } n int main() { n   read_file(); n   while (scanf( %d %d n , &n, &m) != EOF) { n     scanf( %lld , &K); n     for (int i = 0; i < n; i++) n       for (int j = 0; j < m; j++) scanf( %d , &A[i][j]), usedAs[i][j].clear(); n     bool done = false; n     memset(vis, 0, sizeof vis); n     for (int i = 0; i < n && !done; i++) { n       for (int j = 0; j < m && !done; j++) { n         if (K % A[i][j] == 0 && K / A[i][j] <= n * m) { n           if (usedAs[i][j].count(A[i][j])) continue; n           mrk++; n           to = A[i][j]; n           sum = K; n           if (flood(i, j)) done = true; n         } n       } n     } n     if (!done) { n       printf( NO n ); n       continue; n     } n     printf( YES n ); n     for (int i = 0; i < n; i++) n       for (int j = 0; j < m; j++) A[i][j] = vis[i][j] == mrk ? to : 0; n     for (int i = 0; i < n; i++) n       for (int j = 0; j < m; j++) printf( %d%c , A[i][j],    n [j == m - 1]); n   } n } n


#include <bits/stdc++.h> n int a[100005]; n inline int max(int x, int y) { return x > y ? x : y; } n int main() { n   int ans = 0, n, Max, Min, Maxpos, Minpos; n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) scanf( %d , &a[i]); n   int l = 1, r = 1; n   while (r <= n && a[r] == a[1]) r++; n   if (r == n + 1) return !printf( %d , n); n   if (a[r] > a[1]) n     Max = a[r], Maxpos = r, Min = a[1], Minpos = r - 1; n   else n     Max = a[1], Maxpos = r - 1, Min = a[r], Minpos = r; n   while (l <= r && r <= n) { n     while (r < n && a[r + 1] >= Min && a[r + 1] <= Max) { n       r++; n       if (a[r] == Max) n         Maxpos = r; n       else n         Minpos = r; n     } n     r++; n     ans = max(ans, r - l); n     if (r > n) break; n     if (a[r] > Max) { n       l = Minpos + 1; n       Min = Max, Minpos = Maxpos; n       Max = a[r], Maxpos = r; n     } n     if (a[r] < Min) { n       l = Maxpos + 1; n       Max = Min, Maxpos = Minpos; n       Min = a[r], Minpos = r; n     } n   } n   printf( %d , ans); n } n


#include <bits/stdc++.h> n using namespace std; n long long int n, m, sol = 1; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cin >> n >> m; n   if (n > m) swap(n, m); n   if (((n % 10) + 1 <= 2 && n % 10 >= 1 && m % 10 >= 5) || (abs(n - m) > 10)) n     return cout << 0, 0; n   else { n     for (long long int i = n + 1; i <= m; i++) sol = (sol * (i % 10)) % 10; n   } n   cout << sol; n   return 0; n } n


#include <bits/stdc++.h> n const int oo = 0x3f3f3f3f; n const double PI = acos(-1.0); n const double EPS = 1e-8; n using namespace std; n int read() { n   int d, f = 1; n   char c; n   while (!isdigit(c = getchar())) n     if (c ==  - ) f = -1; n   d = c ^  0 ; n   while (isdigit(c = getchar())) d = (d * 10) + (c ^  0 ); n   return d * f; n } n void rekt() { n   puts( YES ); n   exit(0); n } n int main() { n   int n; n   while (cin >> n) { n     int x0 = read(), y0 = read(); n     pair<long long, char> dir[8]; n     for (int i = 0; i < 8; ++i) dir[i].first = 1000000000000000000ll; n     for (int i = 0; i < n; ++i) { n       char c[2]; n       scanf( %s , c); n       int x = read(), y = read(); n       if (y == y0) { n         if (x < x0 && x0 - x < dir[0].first) n           dir[0].first = x0 - x, dir[0].second = c[0]; n         else if (x > x0 && x - x0 < dir[1].first) n           dir[1].first = x - x0, dir[1].second = c[0]; n       } else if (x == x0) { n         if (y < y0 && y0 - y < dir[2].first) n           dir[2].first = y0 - y, dir[2].second = c[0]; n         else if (y > y0 && y - y0 < dir[3].first) n           dir[3].first = y - y0, dir[3].second = c[0]; n       } else if (abs(x - x0) == abs(y - y0)) { n         if (x < x0 && y < y0 && x0 - x < dir[4].first) n           dir[4].first = x0 - x, dir[4].second = c[0]; n         else if (x > x0 && y < y0 && x - x0 < dir[5].first) n           dir[5].first = x - x0, dir[5].second = c[0]; n         else if (x < x0 && y > y0 && x0 - x < dir[6].first) n           dir[6].first = x0 - x, dir[6].second = c[0]; n         else if (x > x0 && y > y0 && x - x0 < dir[7].first) n           dir[7].first = x - x0, dir[7].second = c[0]; n       } n     } n     for (int i = 0; i < 4; ++i) n       if (dir[i].second ==  R  || dir[i].second ==  Q ) rekt(); n     for (int i = 4; i < 8; ++i) n       if (dir[i].second ==  B  || dir[i].second ==  Q ) rekt(); n     puts( NO ); n   } n   return 0; n } n


#include <bits/stdc++.h> n #pragma GCC optimize(2) n using namespace std; n inline int read() { n   char c = getchar(); n   int x = 0; n   bool f = 0; n   for (; !isdigit(c); c = getchar()) f ^= !(c ^ 45); n   for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48); n   if (f) x = -x; n   return x; n } n int n, m, a[205], b[205], res; n vector<int> v[205], tmp[205]; n signed main() { n   n = read(), m = read(); n   for (register int i = (1); i <= (n); ++i) a[i] = read(); n   for (register int i = (1); i <= (m); ++i) b[i] = read(); n   for (register int i = (1); i <= (n); ++i) n     for (register int j = (1); j <= (m); ++j) v[i].push_back(j); n   for (register int p = (9); p >= (0); --p) { n     bool ok = 1; n     for (register int i = (1); i <= (n); ++i) { n       int x = a[i]; n       if (!(x >> p & 1)) continue; n       tmp[i].clear(); n       for (int j = 0; j < v[i].size(); ++j) { n         int y = b[v[i][j]]; n         if (!(y >> p & 1)) tmp[i].push_back(v[i][j]); n       } n       if (tmp[i].size() == 0) { n         ok = 0; n         break; n       } n     } n     if (!ok) n       res += (1 << p); n     else n       for (register int i = (1); i <= (n); ++i) n         if (a[i] >> p & 1) v[i] = tmp[i]; n   } n   cout << res; n   return 0; n } n


#include <bits/stdc++.h> n #pragma comment(linker,  /STACK:16777216 ) n using namespace std; n const int M = 1000000007; n int t; n int n, k; n string s; n int dp[1001][1002][2]; n int get(int it, int d, bool complete, bool zero) { n   if (it == 0) return complete; n   if (zero && dp[it][d][complete] != -1) return dp[it][d][complete]; n   long long ret = 0; n   int to = zero ? 9 : s[n - it] -  0 ; n   for (int i = 0; i <= to; i++) { n     bool nxtZero = zero || (i < to); n     bool nxtComplete = complete || ((i == 4 || i == 7) && (d <= k)); n     int nxtD = min((i == 4 || i == 7) ? 1 : d + 1, 1001); n     ret += get(it - 1, nxtD, nxtComplete, nxtZero); n   } n   ret %= M; n   if (zero) dp[it][d][complete] = ret; n   return ret; n } n bool correct() { n   int prev = -1; n   for (int i = 0, _n = (n); i < _n; ++i) n     if (s[i] ==  4  || s[i] ==  7 ) { n       if (prev != -1 && i - prev <= k) return true; n       prev = i; n     } n   return false; n } n void solution() { n   cin >> t >> k; n   memset((dp), (-1), sizeof((dp))); n   while (t--) { n     cin >> s, n = (int)((s).size()); n     int ret = get(n, 1001, 0, 0); n     ret -= correct(); n     cin >> s, n = (int)((s).size()); n     ret = get(n, 1001, 0, 0) - ret; n     if (ret >= M) ret %= M; n     if (ret < 0) ret += M; n     cout << ret << endl; n   } n } n int main() { n   solution(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int aray[100002]; n int main() { n   int i, j, k, a, b, x, n, y, p, q, len, mx = 0, s = 1; n   scanf( %d , &n); n   for (i = 0; i < n; i++) { n     scanf( %d , &aray[i]); n   } n   p = 0; n   q = 0; n   s = 0; n   for (i = 1; i < n; i++) { n     a = aray[i] - aray[i - 1]; n     if (a) { n       if (p == a) { n         s = q; n       } n       q = i; n       p = a; n     } n     len = i - s + 1; n     if (len > mx) mx = len; n   } n   cout << mx; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a[30010], n; n bool vis[30010]; n void print(vector<int> v) { n   for (int i = 0; i < v.size(); i++) printf( %d  , v[i]); n   printf(  n ); n } n bool check(vector<int> v) { n   if (!v.size()) return false; n   if (v.size() == 1 || v.size() == 2) return true; n   int d = v[1] - v[0]; n   for (int i = 2; i < v.size(); i++) n     if (v[i] - v[i - 1] != d) return false; n   return true; n } n bool solve(int l, int r) { n   vector<int> v1, v2; n   for (int i = 1; i <= n; i++) vis[i] = 0; n   int d = a[r] - a[l]; n   int last = -1, get = a[l]; n   for (int i = 1; i <= n; i++) n     if (a[i] == get) n       get += d, v1.push_back(a[i]), last = i; n     else n       vis[i] = 1; n   for (int i = 1; i <= n; i++) n     if (vis[i]) v2.push_back(a[i]); n   if (check(v2)) { n     print(v1), print(v2); n     return true; n   } n   vis[last] = 1, v1.pop_back(), v2.clear(); n   for (int i = 1; i <= n; i++) n     if (vis[i]) v2.push_back(a[i]); n   if (check(v2)) { n     print(v1), print(v2); n     return true; n   } n   return false; n } n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) scanf( %d , &a[i]); n   if (n == 2) n     printf( %d n%d , a[1], a[2]); n   else if (!solve(1, 2) && !solve(2, 3) && !solve(1, 3)) n     printf( No solution ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, w; n long long ans; n double a[100010], b[100010]; n struct node { n   int f, x, v; n   double a, b; n } sh[100010]; n double m_abs(double x) { n   if (x < 0) n     return -x; n   else n     return x; n } n bool cmp(node x, node y) { return (x.a < y.a || (x.a == y.a && x.b > y.b)); } n void m_sort(int l, int r) { n   if (l == r) return; n   int mid; n   mid = (l + r) / 2; n   m_sort(l, mid); n   m_sort(mid + 1, r); n   int ll, rr, now; n   now = 0; n   ll = l; n   rr = mid + 1; n   while (ll <= mid && rr <= r) { n     if (a[ll] < a[rr]) { n       now++; n       b[now] = a[ll]; n       ll++; n     } else { n       now++; n       b[now] = a[rr]; n       rr++; n       ans += (long long)mid - ll + 1; n     } n   } n   for (int i = ll; i <= mid; i++) { n     now++; n     b[now] = a[i]; n   } n   for (int i = rr; i <= r; i++) { n     now++; n     b[now] = a[i]; n   } n   for (int i = 1; i <= now; i++) { n     a[l + i - 1] = b[i]; n   } n } n int main() { n   scanf( %d%d , &n, &w); n   for (int i = 1; i <= n; i++) { n     scanf( %d%d , &sh[i].x, &sh[i].v); n     if (sh[i].x > 0) sh[i].f = 1; n   } n   for (int i = 1; i <= n; i++) { n     if (sh[i].f == 0) { n       sh[i].a = m_abs((sh[i].x * 1.0) / ((sh[i].v + w) * 1.0)); n       sh[i].b = m_abs((sh[i].x * 1.0) / ((sh[i].v - w) * 1.0)); n     } else { n       sh[i].b = m_abs((sh[i].x * 1.0) / ((sh[i].v - w) * 1.0)); n       sh[i].a = m_abs((sh[i].x * 1.0) / ((sh[i].v + w) * 1.0)); n     } n   } n   sort(sh + 1, sh + 1 + n, cmp); n   for (int i = 1; i <= n; i++) a[i] = sh[i].b; n   m_sort(1, n); n   printf( %lld n , ans); n } n


#include <bits/stdc++.h> n using namespace std; n const int nm = 100010; n const long long inf = 1000000000000000ll; n int n; n long long a[nm], b[nm]; n pair<long long, int> dau[nm], cuoi[nm]; n int main() { n   scanf( %d , &n); n   long long x1, x2; n   scanf( %I64d%I64d , &x1, &x2); n   for (int i = 1; i <= n; ++i) { n     scanf( %I64d%I64d , &a[i], &b[i]); n     dau[i] = make_pair(a[i] * x1 + b[i], i); n     cuoi[i] = make_pair(a[i] * x2 + b[i], i); n   } n   sort(dau + 1, dau + n + 1); n   sort(cuoi + 1, cuoi + n + 1); n   int j = 0; n   long long xxx = -inf; n   for (int i = 1; i <= n; ++i) { n     while (j + 1 < i && cuoi[j + 1].first < cuoi[i].first) { n       j++; n       xxx = max(xxx, a[cuoi[j].second] * x1 + b[cuoi[j].second]); n     } n     if (xxx > a[cuoi[i].second] * x1 + b[cuoi[i].second]) { n       printf( YES n ); n       return 0; n     } n   } n   printf( NO n ); n } n