//  zukonit14 - Kunal Raut n  n #include<bits/stdc++.h> n using namespace std; n  n // #include  ext/pb_ds/assoc_container.hpp  n // #include  ext/pb_ds/tree_policy.hpp  n // using namespace __gnu_pbds; n  n // template<class T> n // using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update> ; n  n // template<class key, class value, class cmp = std::less<key>> n // using omap = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>; n // find_by_order(k)  returns iterator to kth element starting from 0; n // order_of_key(k) returns count of elements strictly smaller than k; n  n /*/-----------------------------DEFINES----------------------------------/*/ n  n #define ll                  long long n #define ld                  long double n #define pb                  push_back n #define mp                  make_pair n #define fi                  first n #define se                  second n #define pi                  3.1415926535 n #define all(v)              v.begin(), v.end() n #define allr(v)             v.rbegin(), v.rend() n #define ms(s, n)            memset(s, n, sizeof(s)) n #define prec(n)             fixed<<setprecision(n) n #define forci(p,n)          for(ll i=p;i<(ll)n;i++) n #define forcj(p,n)          for(ll j=p;j<(ll)n;j++) n #define forc(i,p,n)            for(ll i=p;i<(ll)n;i++) n #define bolt                ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); n #define bits(a)             __builtin_popcountll(a) n #define djokovic            freopen( input00.txt ,  r , stdin);freopen( output00.txt ,  w , stdout); n #define inrange(i,a,b)      ((i>=min(a,b)) && (i<=max(a,b))) n #define sz(a)               (ll)a.size() n #define sum(a)              ( accumulate ((a).begin(), (a).end(), 0ll)) n #define mine(a)             (*min_element((a).begin(), (a).end())) n #define maxe(a)             (*max_element((a).begin(), (a).end())) n #define mini(a)             ( min_element((a).begin(), (a).end()) - (a).begin()) n #define maxi(a)             ( max_element((a).begin(), (a).end()) - (a).begin()) n #define lowb(a, x)          ( lower_bound((a).begin(), (a).end(), (x)) - (a).begin()) n #define uppb(a, x)          ( upper_bound((a).begin(), (a).end(), (x)) - (a).begin()) n clock_t time_p              = clock(); n void rtime()                {time_p = clock() - time_p; cout <<   nTime Taken :   << fixed << (float)(time_p) / CLOCKS_PER_SEC <<  s n ;} n  n  n /*/-----------------------------INLINE FUNCTIONS----------------------------------/*/ n  n inline ll gcd(ll a, ll b)          {if (b == 0) return a;    return gcd(b, a % b);} n inline ll lcm(ll a, ll b)          {return (a / gcd(a, b) * b);} n inline bool isprime(ll n)            {ll i; for (i = 2; i <= sqrt(n); i++) {if (n % i == 0)return false;} return true;} n inline ll ceil(ll num, ll den)      {return ((num + den - 1) / den);} n  n /*/-----------------------------TRACE FUNCTIONS----------------------------------/*/ n  n template<class T> ostream& operator<<(ostream &os, string V) { n     os <<  [  ; n     for (auto v : V) os << v <<    ; n     return os <<  ] ; n } n template<class T> ostream& operator<<(ostream &os, vector<T> V) { n     os <<  [  ; n     for (auto v : V) os << v <<    ; n     return os <<  ] ; n } n template<class T> ostream& operator<<(ostream &os, set<T> S) { n     os <<  {  ; n     for (auto s : S) os << s <<    ; n     return os <<  } ; n } n template<class T> ostream& operator<<(ostream &os, multiset<T> S) { n     os <<  {  ; n     for (auto s : S) os << s <<    ; n     return os <<  } ; n } n template<class T, class T1> ostream& operator<<(ostream &os, map<T, T1> S) { n     os <<  {  ; n     for (auto s : S) os <<  (  << s.first <<  ,  << s.second <<  )  ; n     return os <<  } ; n } n template<class L, class R> ostream& operator<<(ostream &os, pair<L, R> P) { n     return os <<  (  << P.first <<  ,  << P.second <<  ) ; n } n #define tracearr(a,n)  {cout << #a<<  :  ;cout<< [  ;for (ll i = 0; i < n; i++) cout << a[i] <<    ;cout <<  ] n ;} n #define TRACE n #ifdef TRACE n #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__) n template <typename Arg1> n void __f(const char* name, Arg1&& arg1) { n     cout << name <<   :   << arg1 << endl; n } n template <typename Arg1, typename... Args> n void __f(const char* names, Arg1&& arg1, Args&&... args) { n     const char* comma = strchr(names + 1,  , ); n     cout.write(names, comma - names) <<   :   << arg1 <<   |  ; n     __f(comma + 1, args...); n } n #else n #define trace(...) n #endif n  n /*/-----------------------------MODULAR ARITHMETIC----------------------------------/*/ n  n // const ll modx = 1e9 + 7; n const ll modx = 998244353; n const ll mod = modx; n inline ll add(ll x, ll y, ll mod = modx) { n     x += y; n     if (x >= mod) return x - mod; n     return x % mod; n } n inline ll sub(ll x, ll y, ll mod = modx) { n     x -= y; n     if (x < 0) return x + mod; n     return x; n } n inline ll mul(ll x, ll y, ll mod = modx) { n     return (x * 1ll * y) % mod; n } n inline ll expo(ll x, ll y, ll mod = modx) { n     ll ans = 1; n     while (y) { n         if (y & 1) ans = mul(ans, x, mod); n         x = mul(x, x, mod); n         y >>= 1; n     } n     return ans % mod; n } n inline ll inv(ll x, ll mod = modx) { n     return expo(x, mod - 2, mod); n } n /*/-----------------------------CODE BEGINS----------------------------------/*/ n #define int long long n ll rr[] = {0, 1, 1, 1, 0, -1, -1, -1}; n ll cc[] = {1, 1, 0, -1, -1, -1, 0, 1};  //x-y -> URDL , row-column -> RDLU; 0-based; n  n const ll MAXN = 2e5 + 100, MAX2N = 2e3 + 10, LG = 20, INF = 2e18, base = 33; n const int N = 1e5 + 5; n ll n, m, k, q, x,  y, z, a[MAXN], d[MAXN], p[MAXN], vis[MAXN]; n vector<ll>g[MAXN]; ll dp[MAXN]; n void fill() n { n     for (ll i = 0; i <= n; i++) n         d[i] = -1, p[i] = -1, dp[i] = 0, g[i].clear(), vis[i] = 0; n } n void dijkstra(ll s) { n     d[s] = 0; n     queue<ll>q; n     q.push(s); n     while (!q.empty()) { n         ll v = q.front(); n         q.pop(); n         for (auto u : g[v]) n         { n             if (d[u] == -1) n             { n                 d[u] = d[v] + 1; n                 q.push(u); n             } n         } n     } n } n void dfs(ll s) n { n     vis[s] = 1; n     dp[s] = d[s]; n     for (auto to : g[s]) n     { n         if (!vis[to] && d[s] < d[to]) { n             dfs(to); n         } n         if (d[s] < d[to]) n             dp[s] = min(dp[s], dp[to]); n         else n             dp[s] = min(dp[s], d[to]); n     } n } n void solve() n { n     cin >> n >> m; n     fill(); n     for (ll i = 0; i < m; i++) n     { n         ll u, v; cin >> u >> v; --u, --v; n         g[u].pb(v); n     } n     dijkstra(0); n     dfs(0); n     for (ll i = 0; i < n; i++) n         cout << dp[i] <<    ; n     cout <<   n ; n } n signed main() n { n     bolt; n #ifndef ONLINE_JUDGE n     djokovic; n #endif n     ll t; n     t = 1; n     cin >> t; n     for (ll i = 1; i <= t; i++) n     { n         //cout <<  Case #  << i <<  :  ; n         solve(); n     } n     //rtime(); n } n


#include <bits/stdc++.h> n using namespace std; n string s; n map<string, bool> vis; n void ReadCube(string cube) { n   int _4D[4][6] = {{0, 1, 2, 3, 4, 5}, n                    {0, 3, 2, 1, 5, 4}, n                    {0, 5, 2, 4, 1, 3}, n                    {0, 4, 2, 5, 3, 1}}; n   for (int i = 0; i < 4; ++i) { n     string x(6,    ); n     for (int j = 0; j < 6; ++j) { n       x[j] = cube[_4D[i][j]]; n     } n     vis[x] = true; n   } n } n void rotate90() { n   swap(s[0], s[1]); n   swap(s[1], s[2]); n   swap(s[2], s[3]); n   ReadCube(s); n } n void Left(string c) { n   int p[] = {5, 1, 4, 3, 0, 2}; n   string x(6,    ); n   for (int i = 0; i < 6; ++i) { n     x[i] = c[p[i]]; n   } n   ReadCube(x); n } n void Right(string c) { n   int p[] = {4, 1, 5, 3, 2, 0}; n   string x(6,    ); n   for (int i = 0; i < 6; ++i) { n     x[i] = c[p[i]]; n   } n   ReadCube(x); n } n int main() { n   cin >> s; n   int ans = 0; n   sort(s.begin(), s.end()); n   do { n     if (vis[s]) continue; n     for (int i = 0; i < 4; ++i) { n       rotate90(); n     } n     Left(s); n     Right(s); n     ans++; n   } while (next_permutation(s.begin(), s.end())); n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n   n #define MAXN (int)(1e5 + 5) n #define MAXL 20 n #define F first n #define S second n #define endl   n  n #define MOD (lli)(1e9 + 9) n #define MOD2 (lli)(1e9 + 7) n #define lli long long int n #define sz(a) int(a.size()) n #define DEBUG if (0) cout <<  aqui  << endl; n #define PI 2 * acos(0.0) n typedef pair<int, lli> ii; n int dx[] = {1, -1, 0, 0}; n int dy[] = {0, 0, 1, -1}; n int dddx[] = {1, -1, 0, 0, 1, 1, -1, -1}; n int dddy[] = {0, 0, 1, -1, 1, -1, 1, -1}; n  n int t; n  n int main(){ n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n  n   cin >> t; n  n   while(t--) { n     int k, n, m; n     cin >> k >> n >> m; n     vector<int> vec, vec2; n  n     for(int i=0;i<n;i++) { n       int a; n       cin >> a; n       vec.push_back(a); n     } n  n     for(int i=0;i<m;i++) { n       int a; n       cin >> a; n       vec2.push_back(a); n     } n  n     vector<int> ans; n     int a = 0, b = 0; n     bool nono = false; n     while(a < sz(vec) or b < sz(vec2)) { n       bool at = false; n  n       if(b < sz(vec2)) { n         if(!vec2[b] or (a < sz(vec) && vec2[b] < vec[a])) at = true; n       } n  n       if(!at && a < sz(vec)) { n         ans.push_back(vec[a]); n         a++; n       } else if(b < sz(vec2)) { n         ans.push_back(vec2[b]); n         b++; n       } n     } n  n     int atual = k; n     for(auto i : ans) { n       if(!i) atual++; n       else if(i > atual) nono = true; n     } n  n  n     if(nono) { n       cout << -1 << endl; n       continue; n     } n  n     for(auto i : ans) cout << i <<    ; n     cout << endl; n  n   } n  n  n   return 0; n }


#include <bits/stdc++.h> n using namespace std; n const double EPS = 1e-8; n const int mod = 1e9 + 7; n const int N = 1e6 + 10; n const long long INF = 1e18; n long long power(long long x, long long y) { n   long long t = 1; n   while (y > 0) { n     if (y % 2) n       y -= 1, t = t * x % mod; n     else n       y /= 2, x = x * x % mod; n   } n   return t; n } n long long I[100][100], temp[100][100], M[100][100], store[100][100]; n void copyM(long long M1[][100], long long M2[][100], int m) { n   for (int i = 0; i < m; ++i) { n     for (int j = 0; j < m; ++j) { n       M2[i][j] = M1[i][j]; n     } n   } n } n void matmul(long long M1[][100], long long M2[][100], int m) { n   for (int i = 0; i < m; ++i) { n     for (int j = 0; j < m; ++j) { n       temp[i][j] = 0; n       for (int k = 0; k < m; ++k) n         temp[i][j] = (temp[i][j] + (M2[i][k] * M1[k][j]) % mod) % mod; n     } n   } n } n void setI(int m) { n   for (int i = 0; i < m; ++i) { n     for (int j = 0; j < m; ++j) { n       if (i != j) n         I[i][j] = 0; n       else n         I[i][j] = 1; n     } n   } n } n void powerM(long long M1[][100], int m, long long n) { n   setI(m); n   while (n > 0) { n     if (n % 2 == 0) { n       matmul(M1, M1, m); n       copyM(temp, M1, m); n       n /= 2; n     } else { n       matmul(M1, I, m); n       copyM(temp, I, m); n       n -= 1; n     } n   } n } n long long t[105]; n int main() { n   int n, b, k, x; n   scanf( %d%d%d%d , &n, &b, &k, &x); n   memset(M, 0, sizeof(M)); n   for (int i = 0; i < n; ++i) { n     int p; n     scanf( %d , &p); n     p %= x; n     t[p]++; n   } n   for (int i = 0; i < x; ++i) n     for (int j = 0; j < x; ++j) { n       M[i][(i * 10 + j) % x] += t[j]; n     } n   powerM(M, x, b); n   printf( %lld n , I[0][k]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long x1, y1, x2, y2; n   cin >> x1 >> y1 >> x2 >> y2; n   int n; n   cin >> n; n   vector<long long> l(n + 1), t(n + 1); n   l[0] = 0; n   t[0] = 0; n   for (int i = 1; i <= n; i++) { n     char c; n     cin >> c; n     l[i] = l[i - 1]; n     t[i] = t[i - 1]; n     if (c ==  L ) n       l[i]--; n     else if (c ==  R ) n       l[i]++; n     else if (c ==  U ) n       t[i]++; n     else n       t[i]--; n   } n   long long low = 0; n   long long high = 1000000000LL * 1000000000LL * 4; n   long long mid; n   while (low < high) { n     mid = (low + high) / 2; n     long long tempx = (mid / n) * l[n] + l[mid % n]; n     long long tempy = (mid / n) * t[n] + t[mid % n]; n     if (abs(x1 + tempx - x2) + abs(y1 + tempy - y2) <= mid) { n       high = mid; n     } else { n       low = mid + 1; n     } n   } n   mid = low; n   long long tempx = (mid / n) * l[n] + l[mid % n]; n   long long tempy = (mid / n) * t[n] + t[mid % n]; n   if (abs(x1 + tempx - x2) + abs(y1 + tempy - y2) <= mid) n     cout << mid << endl; n   else n     cout << -1 << endl; n } n


#include <bits/stdc++.h> n #pragma GCC optimize( O3 ) n using namespace std; n const int N = 1200031; n int n, ar[N], w[N]; n int gcd(int a, int b) { n   while (a && b) a > b ? a %= b : b %= a; n   return a + b; n } n vector<pair<int, int> > edges; n vector<int> entries[N]; n int sz[N]; n long long ANS[N]; n vector<int> interesting; n long long cur_pairs; n void run_cleanup() { n   for (int i = 0; i < interesting.size(); i++) { n     int id = interesting[i]; n     sz[id] = 1; n     w[id] = id; n   } n } n int get(int x) { n   interesting.push_back(x); n   if (x == w[x]) return x; n   return w[x] = get(w[x]); n } n long long F(int x) { return 1ll * x * (x - 1) / 2; } n void merge(int a, int b) { n   a = get(a); n   b = get(b); n   if (a == b) return; n   cur_pairs -= F(sz[a]); n   cur_pairs -= F(sz[b]); n   w[a] = b; n   sz[b] += sz[a]; n   cur_pairs += F(sz[b]); n } n vector<int> divs[N]; n int main() { n   ios_base::sync_with_stdio(0); n   cin >> n; n   for (int i = 1; i <= n; i++) { n     cin >> ar[i]; n   } n   for (int i = 1; i < n; i++) { n     int a, b; n     cin >> a >> b; n     edges.push_back(make_pair(a, b)); n   } n   for (int i = 0; i < edges.size(); i++) { n     int here = gcd(ar[edges[i].first], ar[edges[i].second]); n     entries[here].push_back(i); n   } n   for (int i = 1; i <= n; i++) { n     w[i] = i; n     sz[i] = 1; n   } n   for (int i = 1; i <= 200000; i++) { n     interesting.clear(); n     cur_pairs = 0; n     for (int j = i; j <= 200000; j += i) { n       for (int q = 0; q < entries[j].size(); q++) { n         int id = entries[j][q]; n         merge(edges[id].first, edges[id].second); n       } n     } n     ANS[i] = cur_pairs; n     run_cleanup(); n   } n   for (int i = 1; i <= 200000; i++) { n     for (int j = i * 2; j <= 200000; j += i) divs[j].push_back(i); n   } n   for (int i = 200000; i; --i) { n     for (int j = 0; j < divs[i].size(); j++) { n       int p = divs[i][j]; n       ANS[p] -= ANS[i]; n     } n   } n   for (int i = 1; i <= n; i++) { n     ANS[ar[i]]++; n   } n   for (int i = 1; i <= 200000; i++) { n     if (ANS[i]) cout << i <<     << ANS[i] << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n int a, n; n int main() { n   scanf( %d %d , &n, &a); n   int res = 0; n   if (a % 2 == 1) n     printf( %d n , a / 2 + a % 2); n   else n     printf( %d n , n / 2 - a / 2 + 1); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int compare(const void* a, const void* b) { return (*(int*)a - *(int*)b); } n int main() { n   int n; n   long long k, sum2, sum3; n   int a[100005], c[100005]; n   long long b[100005]; n   int i, j, count; n   cin >> n; n   cin >> k; n   for (i = 0; i < n; i++) scanf( %d , &a[i]); n   sort(a, a + n); n   count = 0; n   for (i = 0; i < n; i++) { n     j = i; n     while (a[j] == a[i] && j < n) j++; n     b[count] = j - i; n     c[count] = a[i]; n     count++; n     i = j - 1; n   } n   sum2 = 0; n   for (i = 0; i < count; i++) { n     if (sum2 + b[i] * n >= k) { n       sum3 = 0; n       for (j = 0; j < count; j++) { n         sum3 += (b[i] * b[j]); n         if (sum2 + sum3 >= k) { n           printf( %d %d , c[i], c[j]); n           return 0; n         } n       } n     } else n       sum2 += (b[i] * n); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long x, y, z, t1, t2, t3; n int main() { n   scanf( %lld%lld%lld%lld%lld%lld , &x, &y, &z, &t1, &t2, &t3); n   puts(abs(x - y) * t1 >= abs(x - y) * t2 + abs(x - z) * t2 + 3 * t3 ?  YES  n                                                                      :  NO ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, l, r, k, c, i; n string s; n int main() { n   ios_base::sync_with_stdio(0); n   cin >> n; n   if (n == 0) { n     cout <<  a  n          <<   n ; n     return 0; n   } n   while (n > 0) { n     l = 1; n     r = 100000; n     k++; n     while (l < r) { n       c = (l + r) / 2; n       if (c * (c - 1) / 2 > n) n         r = c; n       else n         l = c + 1; n     } n     if (l * (l - 1) / 2 > n) l--; n     n -= (l * (l - 1) / 2); n     for (i = 1; i <= l; i++) s += char(96 + k); n   } n   cout << s <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long MOD = 1000000007; n const long long MAX = 100005; n const long double PI = 3.14159265359; n const long double G = 9.807; n const long long INF = 1e18; n const long double EPS = 1e-6; n long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } n bool isprime(long long a) { n   if (a == 2) return 1; n   if (!(a & 1)) return 0; n   for (long long i = 3; i * i <= a; i += 2) n     if (a % i == 0) return 0; n   return 1; n } n long long mpow(long long base, long long exponent, long long modulus) { n   if (modulus == 1) return 0; n   long long result = 1; n   base = base % modulus; n   while (exponent) { n     if (exponent % 2 == 1) result = (result * base) % modulus; n     exponent = exponent >> 1; n     base = (base * base) % modulus; n   } n   return result; n } n long long minv(long long a, long long mod) { n   long long _gcd = gcd(a, mod); n   assert(_gcd == 1); n   return mpow(a, mod - 2, mod); n } n long long t; n long long dp[35]; n int main() { n   ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); n   cin >> t; n   while (t--) { n     long long d, mod; n     cin >> d >> mod; n     long long temp = d; n     long long mxb = 0; n     memset(dp, 0, sizeof dp); n     for (long long i = 0; i <= 32; ++i) { n       long long p = (1LL << i); n       if (p > temp) { n         mxb = i; n         break; n       } n     } n     long long ans = 1 % mod; n     dp[1] = 1 % mod; n     for (long long i = 2; i <= mxb; ++i) { n       long long nums = mpow(2LL, i - 1, mod); n       if (i == mxb) { n         nums = d - mpow(2LL, i - 1, mod) + 1; n         nums += mod; n         nums %= mod; n       } n       dp[i] += nums; n       dp[i] %= mod; n       for (long long j = i - 1; j >= 1; --j) { n         dp[i] += dp[j] * nums % mod; n         dp[i] %= mod; n       } n       ans += dp[i]; n       ans %= mod; n     } n     cout << ans <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n inline T smin(T &a, const T &b) { n   return a > b ? a = b : a; n } n template <typename T> n inline T smax(T &a, const T &b) { n   return a < b ? a = b : a; n } n inline void add(long long &l, const long long &r) { n   l = (l + r) % (long long)10139; n } n long long gcd(long long v, long long u) { return u ? gcd(u, v % u) : v; } n long long po(long long v, long long u) { n   return u ? (po(v * v % (long long)10139, u >> 1) * (u & 1 ? v : 1) % n               (long long)10139) n            : 1; n } n int n, m; n int p[200010]; n pair<long long, pair<int, int>> ed[200010]; n vector<int> adj[200010]; n const int lca_LG = 20; n int lca_par[lca_LG][200010], lca_level[200010], lca_cost[lca_LG][200010]; n inline int oo(int v, int u) { n   return ed[v].second.second + ed[v].second.first - u; n } n void lca_dfs(int lca_v, int lca_papa = 0) { n   lca_par[0][lca_v] = lca_papa; n   lca_level[lca_v] = lca_level[lca_papa] + 1; n   for (auto lca_e : adj[lca_v]) { n     if (oo(lca_e, lca_v) != lca_papa) { n       lca_cost[0][oo(lca_e, lca_v)] = ed[lca_e].first; n       lca_dfs(oo(lca_e, lca_v), lca_v); n     } n   } n } n int get_lca(int lca_v, int lca_u) { n   int res = 0; n   if (lca_level[lca_v] < lca_level[lca_u]) { n     swap(lca_v, lca_u); n   } n   for (int i = lca_LG - 1; ~i; i--) { n     if (lca_level[lca_par[i][lca_v]] >= lca_level[lca_u]) { n       smax(res, lca_cost[i][lca_v]); n       lca_v = lca_par[i][lca_v]; n     } n   } n   if (lca_v == lca_u) { n     return res; n   } n   for (int i = lca_LG - 1; ~i; i--) { n     if (lca_par[i][lca_v] != lca_par[i][lca_u]) { n       smax(res, lca_cost[i][lca_v]); n       smax(res, lca_cost[i][lca_u]); n       lca_v = lca_par[i][lca_v]; n       lca_u = lca_par[i][lca_u]; n     } n   } n   smax(res, lca_cost[0][lca_v]); n   smax(res, lca_cost[0][lca_u]); n   return res; n } n int get_p(int v) { n   if (p[v]) return p[v] = get_p(p[v]); n   return v; n } n bool merge(int v, int u) { n   v = get_p(v); n   u = get_p(u); n   if (v == u) return false; n   p[v] = u; n   return true; n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cin >> n >> m; n   for (int i = 0; i < m; i++) n     cin >> ed[i].second.first >> ed[i].second.second >> ed[i].first; n   sort(ed, ed + m); n   long long nc = n, cost = 0; n   for (int i = 0; i < m; i++) { n     if (merge(ed[i].second.first, ed[i].second.second)) { n       cost += ed[i].first; n       nc--; n       adj[ed[i].second.first].push_back(i); n       adj[ed[i].second.second].push_back(i); n     } n   } n   if (nc == 1) { n     lca_dfs(1); n     for (int i = 1; i < lca_LG; i++) { n       for (int j = 1; j <= n; j++) { n         lca_par[i][j] = lca_par[i - 1][lca_par[i - 1][j]]; n         lca_cost[i][j] = n             max(lca_cost[i - 1][j], lca_cost[i - 1][lca_par[i - 1][j]]); n       } n     } n   } n   int q; n   cin >> q; n   while (q--) { n     int v, u; n     cin >> v >> u; n     if (nc > 2) { n       cout << -1 <<   n ; n       continue; n     } n     if (nc == 2) { n       if (get_p(v) == get_p(u)) { n         cout << -1 <<   n ; n         continue; n       } n       cout << cost <<   n ; n       continue; n     } n     cout << cost - get_lca(v, u) <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main(int argc, char* argv[]) { n   ios_base::sync_with_stdio(false); n   std::cin.tie(NULL); n   std::cout.tie(NULL); n   ; n   string s; n   getline(cin, s); n   long long int ans = 0, cur = 0; n   int sg = +1; n   for (int i = (0); i < (int((s).size())); i += (1)) { n     if (s[i] ==  +  || s[i] ==  - ) { n       ans += sg * cur; n       cur = 0; n     } n     if (s[i] ==  + ) sg = +1; n     if (s[i] ==  - ) sg = -1; n     cur = (cur * 10) + (s[i] -  0 ); n     if (i == int((s).size()) - 1) { n       ans += sg * cur; n     } n   } n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int M = 2e5 + 5; n int mark[2][M]; n int h[2][M]; n int32_t main() { n   ios_base::sync_with_stdio(false); n   ; n   int n, k; n   cin >> n >> k; n   for (int i = 0; i < 2; i++) { n     string s; n     cin >> s; n     for (int j = 0; j < n; j++) n       if (s[j] ==  X ) mark[i][j] = 1; n   } n   mark[0][0] = 1; n   queue<pair<int, int> > q; n   q.push(make_pair(0, 0)); n   while (q.size()) { n     int x = (q.front()).first; n     int y = (q.front()).second; n     if (y >= n) return cout <<  YES  << endl, 0; n     int t = h[x][y]; n     for (int i = 0; i < 2; i++) n       if (!mark[i][t]) mark[i][t] = 1; n     if (!mark[x][y + 1]) { n       h[x][y + 1] = h[x][y] + 1; n       mark[x][y + 1] = 1; n       q.push(make_pair(x, y + 1)); n     } n     if (y > 0 && !mark[x][y - 1]) { n       h[x][y - 1] = h[x][y] + 1; n       mark[x][y - 1] = h[x][y] + 1; n       q.push(make_pair(x, y - 1)); n     } n     if (!mark[1 - x][y + k]) { n       h[1 - x][y + k] = h[x][y] + 1; n       mark[1 - x][y + k] = 1; n       q.push(make_pair(1 - x, y + k)); n     } n     q.pop(); n   } n   return cout <<  NO  << endl, 0; n } n


#include <bits/stdc++.h> n using namespace std; n using pii = pair<int, int>; n int n; n vector<int> a[200]; n int main() { n   ios_base::sync_with_stdio(false), cin.tie(0), cout << fixed; n   cin >> n; n   int k = (1 + sqrt(1 + 8 * n)) / 2, x = 1; n   cout << k << endl; n   for (int i = 1; i <= k; i++) { n     for (int j = i + 1; j <= k; j++) { n       a[i].push_back(x); n       a[j].push_back(x); n       x++; n     } n   } n   for (int i = 1; i <= k; i++) { n     int m = a[i].size(); n     for (int j = 0; j < m; j++) { n       cout << a[i][j] << (j == m - 1 ?   n  :    ); n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> adj[100000]; n vector<int> hs; n bool possible(int wantvalue, int maxcost) { n   const int nhs = hs.size(); n   long long cost = 0; n   int i = 0; n   for (int j = 0; j <= nhs; j++) { n     while (j - i > wantvalue) { n       cost -= (hs[j - 1] - hs[i]); n       i++; n     } n     if (j - i >= wantvalue && cost <= (long long)maxcost) return true; n     if (j - i > 0 && j < nhs) { n       cost += (long long)(hs[j] - hs[j - 1]) * (j - i); n     } n   } n   return false; n } n void dfs(int v, int parent, int height) { n   if (parent != -1) hs.push_back(height); n   for (int i = 0; i < (int)adj[v].size(); i++) { n     int v2 = adj[v][i]; n     if (v2 == parent) continue; n     dfs(v2, v, height + 1); n   } n } n int main(int argc, char** argv) { n   int m, k, p; n   scanf( %d %d %d , &m, &k, &p); n   for (int i = 0; i < m - 1; i++) { n     int a, b; n     scanf( %d %d , &a, &b); n     a--, b--; n     adj[a].push_back(b); n     adj[b].push_back(a); n   } n   dfs(0, -1, 0); n   sort(hs.begin(), hs.end()); n   int l = 0, r = k; n   while (l < r) { n     int mid = (l + r + 1) / 2; n     if (possible(mid, p)) n       l = mid; n     else n       r = mid - 1; n   } n   printf( %d n , l); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long double Ax, Ay, Bx, By, Cx, Cy, a11, a12, a21, a22, det; n bool flag; n void f(double x, double y) { n   double tx, ty; n   tx = a11 * x + a12 * y; n   ty = a21 * x + a22 * y; n   cerr << tx <<     << ty <<   n ; n   tx = fabs(tx); n   ty = fabs(ty); n   tx += 1e-11; n   ty += 1e-11; n   tx -= (long long)tx; n   ty -= (long long)ty; n   if (flag) { n     tx = x; n     ty = y; n   } n   if (fabs(tx) < 1e-10 && fabs(ty) < 1e-10) { n     cout <<  YES n ; n     exit(0); n   } n } n int main() { n   cin >> Ax >> Ay >> Bx >> By >> Cx >> Cy; n   det = Cx * Cx + Cy * Cy; n   flag = fabs(det) < 1e-10; n   a11 = Cx / det; n   a12 = Cy / det; n   a21 = -Cy / det; n   a22 = Cx / det; n   f(Bx - Ax, By - Ay); n   f(Bx - Ay, By + Ax); n   f(Bx + Ax, By + Ay); n   f(Bx + Ay, By - Ax); n   cout <<  NO n ; n } n


#include <bits/stdc++.h> n using namespace std; n vector<int> a, b, d1, d2; n int main() { n   int n, l; n   cin >> n >> l; n   a.resize(n); n   b.resize(n); n   for (int i = 0; i < n; ++i) { n     cin >> a[i]; n   } n   for (int i = 0; i < n; ++i) { n     cin >> b[i]; n   } n   a.push_back(l + a[0]); n   b.push_back(l + b[0]); n   for (int i = 1; i <= n; ++i) { n     d1.push_back(a[i] - a[i - 1]); n     d2.push_back(b[i] - b[i - 1]); n   } n   for (int i = 0; i < n; i++) { n     bool flag = 1; n     for (int j = 0; j < n; j++) { n       if (d1[j] != d2[(j + i) % n]) { n         flag = 0; n         break; n       } n     } n     if (flag) { n       cout <<  YES ; n       return 0; n     } n   } n   cout <<  NO ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = 1000000007; n long long dp[11][2][1010][1010]; n string s, t; n long long bt(int K, bool f, int a, int b) { n   if (K == 0) return 0; n   long long& ref = dp[K][f][a][b]; n   if (ref != -1) return ref; n   ref = INT_MIN; n   if (f) { n     ref = bt(K - 1, 0, a, b); n     if (a < s.size() && b < t.size() && s[a] == t[b]) n       ref = max(ref, 1 + bt(K, 1, a + 1, b + 1)); n   } else { n     if (a < s.size()) ref = bt(K, 0, a + 1, b); n     if (b < t.size()) ref = max(ref, bt(K, 0, a, b + 1)); n     if (a < s.size() && b < t.size() && s[a] == t[b]) n       ref = max(ref, 1 + bt(K, 1, a + 1, b + 1)); n   } n   return ref; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n   int N, M, K; n   cin >> N >> M >> K; n   cin >> s >> t; n   memset(dp, -1, sizeof dp); n   assert(bt(K, 0, 0, 0) >= K); n   cout << bt(K, 0, 0, 0) <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void model(vector<int>& a, const vector<pair<int, int> >& v) { n   for (pair<int, int> p : v) swap(a[p.first], a[p.second]); n } n bool check(int n, const vector<pair<int, int> >& v) { n   vector<int> a(n); n   for (int i = 0; i < n; ++i) a[i] = i; n   model(a, v); n   for (int i = 0; i < n; ++i) n     if (a[i] != i) return false; n   return true; n } n vector<pair<int, int> > sol0, sol1; n void solve(int n, vector<pair<int, int> >& res) { n   if (n < 4) return; n   solve(n - 4, res); n   for (int i = 0; i + 1 < n - 4; i += 2) { n     res.push_back(pair<int, int>(i, n - 4)); n     res.push_back(pair<int, int>(i + 1, n - 3)); n     res.push_back(pair<int, int>(i + 1, n - 4)); n     res.push_back(pair<int, int>(i, n - 3)); n     res.push_back(pair<int, int>(i, n - 2)); n     res.push_back(pair<int, int>(i + 1, n - 1)); n     res.push_back(pair<int, int>(i + 1, n - 2)); n     res.push_back(pair<int, int>(i, n - 1)); n   } n   if (n % 2) { n     res.push_back(pair<int, int>(n - 5, n - 4)); n     res.push_back(pair<int, int>(n - 5, n - 3)); n     res.push_back(pair<int, int>(n - 5, n - 2)); n     res.push_back(pair<int, int>(n - 4, n - 1)); n     res.push_back(pair<int, int>(n - 5, n - 1)); n     for (pair<int, int> p : sol1) { n       res.push_back(pair<int, int>(p.first + n - 4, p.second + n - 4)); n     } n   } else { n     for (pair<int, int> p : sol0) { n       res.push_back(pair<int, int>(p.first + n - 4, p.second + n - 4)); n     } n   } n   assert(res.size() == n * (n - 1) / 2); n } n void solve0() { n   vector<pair<int, int> > v; n   for (int i = 0; i < 4; ++i) n     for (int j = i + 1; j < 4; ++j) v.push_back(pair<int, int>(i, j)); n   do { n     if (check(4, v)) { n       sol0 = v; n       break; n     } n   } while (next_permutation(v.begin(), v.end())); n   assert(!sol0.empty()); n } n void solve1() { n   vector<pair<int, int> > v; n   for (int i = 0; i < 4; ++i) n     for (int j = i + 1; j < 4; ++j) n       if (pair<int, int>(i, j) != pair<int, int>(0, 3)) n         v.push_back(pair<int, int>(i, j)); n   do { n     vector<int> st = {3, 0, 1, 2}; n     vector<int> en = {0, 1, 2, 3}; n     model(st, v); n     if (st == en) { n       sol1 = v; n       break; n     } n   } while (next_permutation(v.begin(), v.end())); n   assert(!sol1.empty()); n } n int main() { n   std::ios::sync_with_stdio(false); n   solve0(); n   solve1(); n   int n; n   cin >> n; n   if (n * (n - 1) / 2 % 2) { n     cout <<  NO n ; n     return 0; n   } n   cout <<  YES n ; n   vector<pair<int, int> > res; n   solve(n, res); n   for (int i = 0; i < res.size(); ++i) { n     cout << min(res[i].first, res[i].second) + 1 <<     n          << max(res[i].first, res[i].second) + 1 << endl; n   } n   return 0; n } n


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


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int q; n   cin >> q; n   for (long long int l = 0; l < q; l++) { n     long long int n; n     cin >> n; n     long long int ans = 0; n     while (n != 1) { n       long long int track = ans; n       while (n % 2 == 0) { n         n = n / 2; n         ans++; n       } n       while (n % 3 == 0) { n         n = 2 * n / 3; n         ans++; n       } n       while (n % 5 == 0) { n         n = 4 * n / 5; n         ans++; n       } n       if (track == ans) break; n     } n     if (n != 1) n       cout << -1 << endl; n     else n       cout << ans << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long int t, n, i, j; n   cin >> t; n   while (t--) { n     cin >> n; n     if (n % 2 == 0) { n       cout << n / 2 <<     << n / 2; n     } else { n       for (i = 3, j = 0; i * i <= n; i++) { n         if (n % i == 0) { n           cout << n / i <<     << n - (n / i); n           j = 1; n           break; n         } n       } n       if (j == 0) cout << 1 <<     << n - 1; n     } n     printf(  n ); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int MAXN = 2E5 + 10; n const int P = 1E9 + 7; n int n, q; n struct node { n   int l, r, id; n } qu[MAXN]; n int a[MAXN], pri[1100], cnt; n int num[1000001]; n long long ans[MAXN]; n long long bin[MAXN]; n vector<int> dir[1000001]; n vector<int> rec[MAXN]; n int pow(int a, int n) { n   long long b = a; n   long long ret = 1; n   while (n) { n     if (n & 1) ret = ret * b % P; n     b = b * b % P; n     n >>= 1; n   } n   return ret; n } n bool cmp(node n1, node n2) { n   if (n1.l != n2.l) n     return n1.l < n2.l; n   else n     return n1.r < n2.r; n } n bool prime(int p) { n   for (int i = 0; pri[i] * pri[i] <= p; i++) n     if (!(p % pri[i])) return false; n   return true; n } n void init() { n   pri[cnt = 0] = 2; n   for (int i = 3; i < 100000; i++) n     if (prime(i)) pri[++cnt] = i; n   cnt++; n   for (int i = 0; i < MAXN; i++) rec[i].clear(); n   for (int i = 0; i < MAXN; i++) bin[i] = 1; n   for (int i = 0; i < 1000001; i++) dir[i].clear(); n   memset(num, 0, sizeof(num)); n } n int exgcd(long long a, long long b, long long &x, long long &y) { n   if (a == 0) { n     x = 0; n     y = 1; n     return b; n   } else { n     long long tx, ty; n     long long d = exgcd(b % a, a, tx, ty); n     x = ty - (b / a) * tx; n     y = tx; n     return d; n   } n } n int inverse(int k) { n   long long a = k, b = P, x, y; n   exgcd(a, b, x, y); n   return (x % P + P) % P; n } n int main() { n   int temp, l, u, v; n   init(); n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) scanf( %d , &a[i]); n   scanf( %d , &q); n   for (int i = 0; i < q; i++) { n     scanf( %d%d , &qu[i].l, &qu[i].r); n     qu[i].id = i; n   } n   sort(qu, qu + q, cmp); n   for (int i = 1; i <= n; i++) { n     for (int j = 0; pri[j] * pri[j] <= a[i]; j++) { n       while (a[i] % pri[j] == 0) { n         a[i] /= pri[j]; n         if (dir[pri[j]].empty()) n           temp = pri[j] - 1; n         else n           temp = pri[j]; n         dir[pri[j]].push_back(i); n         rec[i].push_back(pri[j]); n         for (int k = i; k <= n; k += k & -k) bin[k] = bin[k] * temp % P; n       } n     } n     if (a[i] != 1) { n       if (dir[a[i]].empty()) n         temp = a[i] - 1; n       else n         temp = a[i]; n       dir[a[i]].push_back(i); n       rec[i].push_back(a[i]); n       for (int k = i; k <= n; k += k & -k) bin[k] = bin[k] * temp % P; n     } n   } n   l = 1; n   for (int i = 0; i < q; i++) { n     for (; l < qu[i].l; l++) { n       for (int j = 0; j < rec[l].size(); j++) { n         u = rec[l][j]; n         if (num[u] < dir[u].size() - 1) n           v = dir[u][++num[u]]; n         else n           v = n + 1; n         temp = (long long)(u - 1) * inverse(u) % P; n         for (int k = v; k <= n; k += k & -k) bin[k] = bin[k] * temp % P; n       } n     } n     temp = qu[i].id; n     ans[temp] = 1; n     for (int k = qu[i].l - 1; k > 0; k -= k & -k) n       ans[temp] = ans[temp] * bin[k] % P; n     ans[temp] = inverse(ans[temp]); n     for (int k = qu[i].r; k > 0; k -= k & -k) { n       ans[temp] = ans[temp] * bin[k] % P; n     } n   } n   for (int i = 0; i < q; i++) printf( %lld n , ans[i]); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int i; n   string a[3]; n   cin >> a[0] >> a[1] >> a[2]; n   for (i = 0; i < 3; i++) { n     if ((a[i] ==  rock ) && (a[(i + 1) % 3] ==  scissors ) && n         (a[(i + 2) % 3] ==  scissors )) { n       break; n     } n     if ((a[i] ==  scissors ) && (a[(i + 1) % 3] ==  paper ) && n         (a[(i + 2) % 3] ==  paper )) { n       break; n     } n     if ((a[i] ==  paper ) && (a[(i + 1) % 3] ==  rock ) && n         (a[(i + 2) % 3] ==  rock )) { n       break; n     } n   } n   if (i == 0) { n     cout <<  F  << endl; n   } else if (i == 1) { n     cout <<  M  << endl; n   } else if (i == 2) { n     cout <<  S  << endl; n   } else { n     cout <<  ?  << endl; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, pos, lo, hi; n   while (cin >> n >> pos >> lo >> hi) { n     int cnt = 0; n     if (lo == 1 && hi == n) { n       cout <<  0  << endl; n       continue; n     } n     int xlo = abs(pos - lo); n     int xhi = abs(pos - hi); n     if (lo - 1 >= 1 && hi + 1 <= n) { n       cnt += 2; n       if (xlo < xhi) { n         cnt += xlo; n       } else n         cnt += xhi; n       cnt += hi - lo; n     } else if (lo - 1 >= 1) { n       cnt += xlo; n       cnt++; n     } else { n       cnt += xhi; n       cnt++; n     } n     cout << cnt << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 2e5 + 5; n const int M = 1e5 + 5; n int main() { n   ios_base::sync_with_stdio(false); n   int tt; n   cin >> tt; n   while (tt--) { n     int n, i, j; n     cin >> n; n     vector<long long> v[N]; n     for (i = 0; i < n; i++) { n       int m; n       long long p; n       cin >> m >> p; n       v[m].push_back(p); n     } n     int want[N]; n     int cnt = 0; n     for (i = 0; i < n; i++) { n       int lu = v[i].size(); n       if (lu == 0) continue; n       want[i] = max(0, i - cnt); n       cnt += lu; n     } n     multiset<long long> st; n     long long ans = 0; n     int taken = 0; n     for (i = n - 1; i >= 0; i--) { n       int lu = v[i].size(); n       if (lu == 0) continue; n       for (j = 0; j < lu; j++) { n         st.insert(v[i][j]); n       } n       int fu = st.size(); n       int req = min(max(0, want[i] - taken), fu); n       for (j = 0; j < req; j++) { n         ans += *(st.begin()); n         taken++; n         st.erase(st.begin()); n       } n     } n     cout << ans << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 300010; n const int MOD = 1000000007; n int n, m; n int a[N], b[N]; n char mm[10010]; n vector<int> f[N]; n long long w[2010]; n int RM(int a) { n   if (!m) return 0; n   int t; n   for (int i = m - 1; i >= 0; i--) { n     t = w[i] % a; n     w[i] /= a; n     if (i) w[i - 1] += t * 1000000000ll; n   } n   while (m && !w[m - 1]) m--; n   return t; n } n int main() { n   scanf( %d , &n); n   for (int i = 2; i <= n; i++) scanf( %d , &a[i]); n   a[1] = 1; n   a[n + 1] = 1000000000; n   for (int i = 1; i <= n; i++) scanf( %d , &b[i]); n   scanf( %s , mm); n   for (int i = strlen(mm) - 1; i >= 0; i -= 9, m++) n     for (int j = max(0, i - 8); j <= i; w[m] = w[m] * 10 + mm[j++] -  0 ) n       ; n   f[1].push_back(1); n   for (int i = 1; i <= n; i++) { n     int s = f[i].size(), sum = 0, md = 0; n     if (a[i + 1] != 1) md = RM(a[i + 1]); n     for (int j = 0; j < s + b[i]; j++) { n       if (j < s) (sum += f[i][j]) %= MOD; n       if (j > b[i]) (sum += MOD - f[i][j - b[i] - 1]) %= MOD; n       if (j % a[i + 1] == md) f[i + 1].push_back(sum); n     } n   } n   printf( %d n , m ? 0 : f[n + 1].size() == 0 ? 0 : f[n + 1][0]); n } n


#include <bits/stdc++.h> n using namespace std; n char s[500005], t[500005]; n long long ans; n int n, k, now, tmp; n int main() { n   scanf( %d %d n , &n, &k); n   fread(s + 1, 1, n, stdin); n   getchar(); n   fread(t + 1, 1, n, stdin); n   s[n + 1] =  # ; n   if (k == 1) return printf( %d n , n), 0; n   for (now = 1; s[now] == t[now]; now++) n     ; n   if (now > n) return printf( %d n , n), 0; n   ans = now + 1; n   for (int i = now + 1; i <= n; i++) { n     tmp = tmp << 1; n     if (s[i] ==  a ) tmp++; n     if (t[i] ==  b ) tmp++; n     tmp = min(k - 2, tmp); n     ans += tmp + 2; n   } n   printf( %lld n , ans); n } n


#include <bits/stdc++.h> n using namespace std; n template <typename TF> n void write_debug_output(ostream &out, TF const &f) { n   out << f << std::endl; n } n template <typename TF, typename... TR> n void write_debug_output(ostream &out, TF const &f, TR const &...rest) { n   out << f <<    ; n   write_debug_output(out, rest...); n } n using ll = long long; n using ull = unsigned long long; n using ld = long double; n using pii = pair<int, int>; n using pll = pair<ll, ll>; n using pdd = pair<double, double>; n using vi = vector<int>; n using vii = vector<pii>; n using vll = vector<ll>; n using vs = vector<string>; n const int DR[] = {-1, 0, 1, 0, -1, 1, 1, -1}; n const int DC[] = {0, -1, 0, 1, -1, -1, 1, 1}; n const double PI = acos(-1.0); n const double EPS = 1e-9; n const int MOD = 1e9 + 7; n const int INF = 1073741823; n const ll INFLL = 4e18; n const int MAX = 100; n int N, M, aa[MAX + 5], bb[MAX + 5]; n void read() { n   cin >> N >> M; n   for (int i = 0; i < (int)N; i++) cin >> aa[i]; n   for (int i = 0; i < (int)M; i++) cin >> bb[i]; n } n void solve() { n   int xorA = 0, xorB = 0; n   for (int i = 0; i < (int)N; i++) xorA ^= aa[i]; n   for (int i = 0; i < (int)M; i++) xorB ^= bb[i]; n   if (xorA != xorB) { n     cout <<  NO n ; n     return; n   } n   cout <<  YES n ; n   int b = bb[1]; n   int c = aa[1]; n   int a = aa[0] ^ bb[1] ^ (xorB ^ bb[0] ^ bb[1]); n   for (int i = 0; i < (int)N; i++) { n     for (int j = 0; j < (int)M; j++) { n       if (i == 0 && j == 0) n         cout << a <<    ; n       else if (i == 0 && j == 1) n         cout << b <<    ; n       else if (i == 1 && j == 0) n         cout << c <<    ; n       else if (i == 0) n         cout << bb[j] <<    ; n       else if (j == 0) n         cout << aa[i] <<    ; n       else n         cout <<  0  ; n     } n     cout <<   n ; n   } n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int TC = 1; n   for (int tc = (int)1; tc <= (int)TC; tc++) { n     read(); n     solve(); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 1000007, M = 5000007; n const long long INF = 1e14; n inline void read(int &first) { n   char c = getchar(); n   while ((c < 48) || (c > 57)) c = getchar(); n   first = c ^ 48; n   c = getchar(); n   while ((c >= 48) && (c <= 57)) { n     first = first * 10 + (c ^ 48); n     c = getchar(); n   } n } n struct node { n   int l, r; n   int maxx; n } tr[N << 2]; n int n, m, t, k; n int first[N], second; n int a[N]; n int num[N]; n int s[N]; n int pre[N]; n void build(int p, int l, int r) { n   tr[p] = {l, r, 0}; n   if (l == r) { n     tr[p].maxx = s[r]; n     return; n   } n   int mid = l + r >> 1; n   build(p << 1, l, mid); n   build(p << 1 | 1, mid + 1, r); n   tr[p].maxx = max(tr[p << 1].maxx, tr[p << 1 | 1].maxx); n } n int query(int p, int l, int r) { n   if (tr[p].l >= l && tr[p].r <= r) { n     return tr[p].maxx; n   } n   int mid = tr[p].l + tr[p].r >> 1; n   int res = 0; n   if (l <= mid) res = max(res, query(p << 1, l, r)); n   if (r > mid) res = max(res, query(p << 1 | 1, l, r)); n   return res; n } n int main() { n   scanf( %d , &t); n   while (t--) { n     for (int i = 0; i <= n; ++i) s[i] = pre[i] = num[i] = 0; n     scanf( %d%d , &n, &m); n     for (int i = 1; i <= n; ++i) scanf( %d , &first[i]), a[i] = first[i]; n     for (int i = 1; i <= n; ++i) scanf( %d , &second); n     sort(a + 1, a + 1 + n); n     int tot = unique(a + 1, a + 1 + n) - a - 1; n     for (int i = 1; i <= n; ++i) n       num[lower_bound(a + 1, a + 1 + tot, first[i]) - a]++; n     for (int i = 1; i <= n; ++i) pre[i] = pre[i - 1] + num[i]; n     for (int i = 1; i <= n; ++i) n       s[i] = pre[upper_bound(a + i + 1, a + 1 + tot, a[i] + m) - a - 1] - n              pre[i - 1]; n     build(1, 1, tot); n     int ans = 0; n     for (int i = 1; i <= tot; ++i) { n       ans = n           max(ans, n               s[i] + query(1, upper_bound(a + i + 1, a + 1 + tot, a[i] + m) - a, n                            tot)); n     } n     printf( %d n , ans); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n template <typename Arg1> n void __f(const char* name, Arg1&& arg1) { n   cerr << name <<  :   << arg1 << std::endl; n } n template <typename Arg1, typename... Args> n void __f(const char* names, Arg1&& arg1, Args&&... args) { n   const char* comma = strchr(names + 1,  , ); n   cerr.write(names, comma - names) <<  :   << arg1 <<   | ; n   __f(comma + 1, args...); n } n int main() { n   int k; n   scanf( %d , &k); n   int x[10]; n   memset(x, 0, sizeof(x)); n   char s[5]; n   for (auto i = 0; i < 4; i++) { n     scanf( %s , s); n     for (auto j = 0; j < 4; j++) { n       if (s[j] ==  . ) { n         continue; n       } n       x[s[j] -  0 ]++; n     } n   } n   for (auto i = 1; i < 10; i++) { n     if (x[i] > 2 * k) { n       printf( NO n ); n       return 0; n     } n   } n   printf( YES n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n; n int ara[200010]; n string res; n string str; n void func(int le, int ri, int chk, int past) { n   if (res.size() < str.size()) { n     res = str; n   } n   if (le > ri) { n     return; n   } n   if (chk == 0) { n     if ((past < ara[le]) && (ara[le] < ara[ri])) { n       str +=  L ; n       func(le + 1, ri, chk, ara[le]); n       str.pop_back(); n     } else if ((past < ara[ri]) && (ara[ri] < ara[le])) { n       str +=  R ; n       func(le, ri - 1, chk, ara[ri]); n       str.pop_back(); n     } else if ((past < ara[ri]) && (ara[ri] == ara[le])) { n       str +=  L ; n       func(le + 1, ri, 1, ara[le]); n       str.pop_back(); n       str +=  R ; n       func(le, ri - 1, 2, ara[ri]); n       str.pop_back(); n     } else if (past < ara[le]) { n       str +=  L ; n       func(le + 1, ri, chk, ara[le]); n       str.pop_back(); n     } else if (past < ara[ri]) { n       str +=  R ; n       func(le, ri - 1, chk, ara[ri]); n       str.pop_back(); n     } n   } else if (chk == 1) { n     if (past < ara[le]) { n       str +=  L ; n       func(le + 1, ri, chk, ara[le]); n       str.pop_back(); n     } n   } else { n     if (past < ara[ri]) { n       str +=  R ; n       func(le, ri - 1, chk, ara[ri]); n       str.pop_back(); n     } n   } n } n int main() { n   cin >> n; n   for (int i = 0; i <= n - 1; i++) { n     cin >> ara[i]; n   } n   str =   ; n   res =   ; n   func(0, n - 1, 0, 0); n   cout << res.size() <<   n ; n   cout << res <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n const int N = 300300; n using namespace std; n struct edge { n   int ul, ur, dl, dr, a, al, ar; n   long long xl, xr; n }; n edge comb(edge a, edge b, int sa, int sb) { n   edge g; n   g.a = max(a.a, b.a); n   g.al = a.al; n   g.xl = a.xl; n   g.ul = a.ul; n   g.dl = a.dl; n   g.ar = b.ar; n   g.xr = b.xr; n   g.ur = b.ur; n   g.dr = b.dr; n   if (a.xr == b.xl) { n     return g; n   } else if (a.xr > b.xl) { n     g.a = max(g.a, a.ar + b.dl); n     if (sb == b.dl) g.ar = a.ar + b.dl; n     if (sa == a.a) g.al = a.a + b.dl; n     if (sa == a.dl) g.dl += b.dl; n     if (sb == b.ur) g.ur += a.ur; n     g.a = max(g.a, max(g.al, g.ar)); n     return g; n   } else { n     g.a = max(g.a, a.dr + b.al); n     if (sb == b.a) g.ar = a.dr + b.a; n     if (sa == a.dr) g.al = a.dr + b.al; n     if (sb == b.dr) g.dr += a.dr; n     if (sa == a.ul) g.ul += b.ul; n     g.a = max(g.a, max(g.al, g.ar)); n     return g; n   } n } n edge t[4 * N]; n int n; n int a[N]; n long long lz[4 * N]; n void push(int x) { n   if (lz[x] == 0) return; n   t[x * 2].xl += lz[x]; n   t[x * 2].xr += lz[x]; n   t[x * 2 + 1].xl += lz[x]; n   t[x * 2 + 1].xr += lz[x]; n   lz[x * 2] += lz[x]; n   lz[x * 2 + 1] += lz[x]; n   lz[x] = 0; n } n void build(int x, int l, int r) { n   if (l == r) { n     t[x].xl = t[x].xr = a[l]; n     t[x].a = t[x].al = t[x].ar = t[x].dl = t[x].dr = t[x].ul = t[x].ur = 1; n     return; n   } n   int m = (l + r) / 2; n   build(x * 2, l, m); n   build(x * 2 + 1, m + 1, r); n   t[x] = comb(t[x * 2], t[x * 2 + 1], m - l + 1, r - m); n } n void upd(int x, int l, int r, int tl, int tr, long long d) { n   if (tl > tr) return; n   if (l == tl && r == tr) { n     lz[x] += d; n     t[x].xl += d; n     t[x].xr += d; n     return; n   } n   push(x); n   int m = (l + r) / 2; n   upd(x * 2, l, m, tl, min(m, tr), d); n   upd(x * 2 + 1, m + 1, r, max(m + 1, tl), tr, d); n   t[x] = comb(t[x * 2], t[x * 2 + 1], m - l + 1, r - m); n } n int main() { n   ios_base::sync_with_stdio(0); n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) scanf( %d , &a[i]); n   build(1, 1, n); n   int m; n   scanf( %d , &m); n   for (int i = 1; i <= m; i++) { n     int l, r, d; n     scanf( %d%d%d , &l, &r, &d); n     upd(1, 1, n, l, r, d); n     printf( %d n , t[1].a); n   } n } n


#include <bits/stdc++.h> n using namespace std; n int c[100010]; n long long ans; n int main() { n   int n, x; n   scanf( %d%d , &n, &x); n   for (int i = 1; i <= n; i++) scanf( %d , &c[i]); n   sort(c + 1, c + n + 1); n   if (n < x) { n     ans = 0; n     for (int i = 1; i <= n; i++) ans += (long long)c[i] * (x - i + 1); n     printf( %I64d , ans); n     return 0; n   } n   if (n >= x) { n     ans = 0; n     for (int i = 1; i <= x; i++) ans += (long long)i * c[x + 1 - i]; n     for (int i = x + 1; i <= n; i++) ans += c[i]; n   } n   printf( %I64d , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n #define IOS ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0) n #define INP(arr,n) for(int a=0;a<n;a++)cin>>arr[a] n #define OTP(arr,n) for(int a=0;a<n;a++)cout<<arr[a]<<    n #define ll long long int n #define pb(v,a) v.push_back(a) n int main() { n IOS;int t = 0;cin >> t; n while (t--) { n     ll n = 0;cin >> n; n     ll arr[n];INP(arr,n); n     cout <<  0  ; n     for (ll a = 1;a < n;a++) { n         ll x = 0,y = 1; n         bitset <64> bs(arr[a - 1]); n         bitset <64> bs2(arr[a]); n         for (int b = 0;b < 64;b++,y *= 2) n             bs2[b] == 0 && bs[b] == 1 ? x += y,arr[a] += y: x = x; n         cout << x <<    ; n     } n     cout <<   n ; n } n }


#include <bits/stdc++.h> n using namespace std; n string p[3][2] = {{ lios ,  liala }, { etr ,  etra }, { initis ,  inites }}, s; n pair<int, int> kind(string q) { n   int l = q.length(); n   if (l >= 4 && q.substr(l - 4, 4) == p[0][0]) return pair<int, int>(0, 0); n   if (l >= 5 && q.substr(l - 5, 5) == p[0][1]) return pair<int, int>(0, 1); n   if (l >= 3 && q.substr(l - 3, 3) == p[1][0]) return pair<int, int>(1, 0); n   if (l >= 4 && q.substr(l - 4, 4) == p[1][1]) return pair<int, int>(1, 1); n   if (l >= 6 && q.substr(l - 6, 6) == p[2][0]) return pair<int, int>(2, 0); n   if (l >= 6 && q.substr(l - 6, 6) == p[2][1]) return pair<int, int>(2, 1); n   return pair<int, int>(-1, -1); n } n int tran[2][3] = {{0, 1, -1}, {-1, -1, 1}}; n int main() { n   int g = -1, st = -1, ok = true, tow = false; n   cin >> s; n   g = kind(s).second; n   if (g != -1) st = tran[0][kind(s).first]; n   while (cin >> s && ok) { n     tow = true; n     pair<int, int> t = kind(s); n     if (t.second != g) ok = false; n     if (st == -1) break; n     st = tran[st][t.first]; n   } n   if ((tow && ok && st == 1) || (!tow && g != -1)) n     cout <<  YES  << endl; n   else n     cout <<  NO  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long n, sb, a[4], data1[100001], num[100001]; n void merge(int l, int r) { n   int mid = (l + r) / 2; n   int i = l, j = mid + 1, k = 0; n   while (i <= mid && j <= r) { n     if (data1[i] < data1[j]) n       num[k++] = data1[i++]; n     else n       num[k++] = data1[j++]; n   } n   while (i <= mid) num[k++] = data1[i++]; n   while (j <= r) num[k++] = data1[j++]; n   for (int p = 0; p < k; p++) data1[p + l] = num[p]; n } n void sort(int l, int r) { n   if (l >= r) return; n   int mid = (l + r) / 2; n   sort(l, mid); n   sort(mid + 1, r); n   merge(l, r); n } n int main() { n   cin >> n; n   for (int j = 0; j < n; j++) cin >> data1[j]; n   sort(0, n - 1); n   for (int i = 1; i <= 3; i++) { n     a[i] = 1; n     while (data1[sb] == data1[sb + 1] && sb < n - 1) { n       a[i]++; n       sb++; n     } n     sb++; n   } n   if (data1[0] == data1[1]) { n     if (data1[1] == data1[2]) n       cout << a[1] * (a[1] - 1) * (a[1] - 2) / 6; n     else n       cout << a[2]; n   } else { n     if (data1[1] == data1[2]) n       cout << a[2] * (a[2] - 1) / 2; n     else n       cout << a[3]; n   } n } n


#include <bits/stdc++.h> n using namespace std; n #pragma warning(disable : 4996) n #pragma comment(linker,  /STACK:336777216 ) n const int sqrtn = 300; n const int inf = 987654321; n const int sz = 1e5 + 5; n const int mod = 1e9 + 7; n int n, vis[sz]; n string str; n int main() { n   scanf( %d , &n); n   cin >> str; n   int ret = 0, x = 0, y = 0, last = 0; n   if (str[0] ==  U ) { n     y++; n     last = 1; n   } else n     x++, last = 0; n   for (int i = 1; i < n; i++) { n     if (str[i] ==  U ) n       y++; n     else n       x++; n     if (vis[i - 1]) { n       if (y > x && last == 0) { n         ret++, last = 1; n       } else if (x > y && last == 1) { n         ret++, last = 0; n       } n     } n     if (y == x) vis[i] = 1; n   } n   printf( %d , ret); n } n


#include <bits/stdc++.h> n using namespace std; n namespace IO { n const int maxn(1 << 21 | 1); n char *iS, *iT, ibuf[maxn], obuf[maxn], *oS = obuf, *oT = obuf + maxn - 1, c, n                                        st[20]; n int f, tp, len; n inline char getc() { n   return iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, maxn, stdin), n                      iS == iT ? EOF : *iS++) n                   : *iS++; n } n template <class T> n inline void read(T &x) { n   for (c = getc(), f = 1; c <  0  || c >  9 ; c = getc()) f = c ==  -  ? -1 : 1; n   for (x = 0; c >=  0  && c <=  9 ; c = getc()) x = x * 10 + (c ^ 48); n   x *= f; n } n template <class T, class... Other> n inline void read(T &x, Other &...y) { n   read(x), read(y...); n } n inline void flush() { fwrite(obuf, 1, oS - obuf, stdout), oS = obuf; } n inline void putc(char ch) { n   *oS++ = ch; n   if (oS == oT) flush(); n } n template <class T> n inline void print(T x, char ch =   n ) { n   if (!x) putc( 0 ); n   if (x < 0) putc( - ), x = -x; n   while (x) st[++tp] = x % 10 +  0 , x /= 10; n   while (tp) putc(st[tp--]); n   putc(ch); n } n template <class T, class... Other> n inline void print(T x, Other... y) { n   print(x), print(y...); n } n inline void print_str(char *s) { n   for (len = strlen(s), f = 0; f < len; ++f) putc(s[f]); n } n inline void read_str(char *s, int &l) { n   for (l = 0, c = getc(); (c <  a  || c >  z ) && (c <  A  || c >  Z ); n        c = getc()) n     ; n   for (; (c >=  a  && c <=  z ) || (c >=  A  && c <=  Z ); c = getc()) n     s[l++] = c; n   s[l] =   0 ; n } n }  // namespace IO n using IO ::flush; n using IO ::print; n using IO ::print_str; n using IO ::read; n using IO ::read_str; n template <class T> n inline void cmax(T &x, T y) { n   x = x >= y ? x : y; n } n template <class T, class... Other> n inline void cmax(T &x, T y, Other... z) { n   Cmax(x, y), Cmax(x, z...); n } n template <class T> n inline void cmin(T &x, T y) { n   x = x <= y ? x : y; n } n template <class T, class... Other> n inline void cmin(T &x, T y, Other... z) { n   Cmin(x, y), Cmin(x, z...); n } n inline int gcd(int x, int y) { return y ? gcd(y, x % y) : x; } n const int mod(1e9 + 7); n inline void inc(int &x, const int y) { x = x + y >= mod ? x + y - mod : x + y; } n inline void dec(int &x, const int y) { x = x - y < 0 ? x - y + mod : x - y; } n inline int add(const int x, const int y) { n   return x + y >= mod ? x + y - mod : x + y; n } n inline int sub(const int x, const int y) { n   return x - y < 0 ? x - y + mod : x - y; n } n inline int fpow(long long x, int y) { n   long long ret = 1; n   for (; y; y >>= 1, x = x * x % mod) n     if (y & 1) ret = ret * x % mod; n   return ret; n } n const int maxn(1e5 + 5); n int k, lg[23], ans = 1, f[55][10005], num, inv[55]; n long long n, d[23]; n inline int solve(int p, int lim) { n   int i, j, l, ret = 0; n   memset(f, 0, sizeof(f)), f[lim][0] = 1; n   for (i = 1; i <= k; ++i) n     for (j = 0; j <= lim; ++j) n       for (l = j; l <= lim; ++l) n         inc(f[j][i], (long long)f[l][i - 1] * inv[l + 1] % mod); n   for (ret = 0, i = 0; i <= lim; ++i) n     inc(ret, (long long)f[i][k] * fpow(p, i) % mod); n   return ret; n } n int main() { n   long long i; n   read(n, k), ans = 1; n   for (i = 1; i <= 50; ++i) inv[i] = fpow(i, mod - 2); n   for (i = 2; i * i <= n; ++i) n     if (n % i == 0) { n       d[++num] = i; n       while (n % i == 0) n /= i, ++lg[num]; n     } n   if (n > 1) d[++num] = n, lg[num] = 1; n   for (i = 1; i <= num; ++i) n     ans = (long long)ans * solve(d[i] % mod, lg[i]) % mod; n   print(ans); n   return flush(), 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct Query { n   int p, s, id; n   bool operator<(const Query &b) const { return (s < b.s); } n }; n int main() { n   int n; n   scanf( %d , &n); n   vector<int> a(n); n   for (int i = 0; i < n; ++i) scanf( %d , &a[i]); n   int m; n   scanf( %d , &m); n   vector<Query> q(m); n   for (int i = 0; i < m; ++i) { n     scanf( %d%d , &q[i].p, &q[i].s); n     --q[i].p; n     q[i].id = i; n   } n   sort(q.begin(), q.end()); n   vector<long long> ans(m, 0); n   int lim = sqrt(n); n   for (int i = 0; i < q.size(); ++i) { n     if (q[i].s > lim) { n       for (int j = q[i].p; j < n; j += q[i].s) ans[q[i].id] += a[j]; n     } else { n       int cs = q[i].s; n       vector<long long> sums(n, 0); n       for (int j = n - 1; j >= 0; --j) n         sums[j] = a[j] + ((j + cs < n) ? sums[j + cs] : 0); n       int j; n       for (j = i; j < q.size() && q[j].s == cs; ++j) n         ans[q[j].id] = sums[q[j].p]; n       i = j - 1; n     } n   } n   for (int i = 0; i < ans.size(); ++i) printf( %I64d n , ans[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double eps = 1e-8; n const int mod = 1e9 + 7; n const int N = 4e5 + 10; n const int inf = 1e9; n int n, k, m; n map<pair<int, int>, int> vis; n int mx[N << 2], tag[N << 2]; n int a[N]; n void pd(int p, int k) { n   mx[p << 1] += k; n   tag[p << 1] += k; n   mx[p << 1 | 1] += k; n   tag[p << 1 | 1] += k; n   tag[p] = 0; n } n void up(int dl, int dr, int l, int r, int p, int k) { n   if (l == dl && r == dr) { n     mx[p] += k; n     tag[p] += k; n     return; n   } n   int mid = l + r >> 1; n   pd(p, tag[p]); n   if (dr <= mid) n     up(dl, dr, l, mid, p << 1, k); n   else if (dl > mid) n     up(dl, dr, mid + 1, r, p << 1 | 1, k); n   else n     up(dl, mid, l, mid, p << 1, k), up(mid + 1, dr, mid + 1, r, p << 1 | 1, k); n   mx[p] = max(mx[p << 1], mx[p << 1 | 1]); n } n int main() { n   ios::sync_with_stdio(false); n   cin >> n >> k >> m; n   for (int i = 1; i <= m; i++) { n     int x, y; n     cin >> x >> y; n     int p = abs(x - k) + y; n     if (vis[make_pair(x, y)]) { n       up(1, p, 1, 2 * n, 1, -1); n       a[p]--; n       if (a[p] == 0) up(p, p, 1, 2 * n, 1, -p + 1); n       vis[make_pair(x, y)] = 0; n     } else { n       up(1, p, 1, 2 * n, 1, 1); n       if (a[p] == 0) up(p, p, 1, 2 * n, 1, p - 1); n       ++a[p]; n       vis[make_pair(x, y)] = 1; n     } n     cout << max(0, mx[1] - n) <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int inf = (int)1e9; n const long long linf = (long long)1e18; n const double eps = (double)1e-8; n const int mod = (int)1e9 + 7; n const int maxn = (int)1e5 + 5; n const int MX = (int)1e5; n const int PRIME = 31; n string s, t; n int n, m, first; n long long hs[maxn], ht[maxn], st[maxn]; n int d[maxn][33]; n int subs(int l, int r) { n   return 1ll * (hs[r] - hs[l - 1] + mod) % mod * st[max(n, m) - r] % mod; n } n int subt(int l, int r) { n   return 1ll * (ht[r] - ht[l - 1] + mod) % mod * st[max(n, m) - r] % mod; n } n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cin >> n; n   cin >> s; n   s =  _  + s; n   cin >> m; n   cin >> t; n   t =  _  + t; n   cin >> first; n   st[0] = 1; n   for (int i = (1); i <= (int)(MX); ++i) { n     st[i] = 1ll * st[i - 1] * PRIME % mod; n   } n   hs[0] = 0; n   for (int i = (1); i <= (int)(n); ++i) { n     hs[i] = (hs[i - 1] + st[i - 1] * (s[i] -  a  + 1)) % mod; n   } n   ht[0] = 0; n   for (int i = (1); i <= (int)(m); ++i) { n     ht[i] = (ht[i - 1] + st[i - 1] * (t[i] -  a  + 1)) % mod; n   } n   memset((d), 0, sizeof(d)); n   for (int i = (0); i <= (int)(n - 1); ++i) { n     for (int j = (0); j <= (int)(first); ++j) { n       d[i + 1][j] = max(d[i + 1][j], d[i][j]); n       if (j == first) continue; n       int l = 0; n       int r = min(n - i, m - d[i][j]); n       while (l < r) { n         int mid = (l + r + 1) / 2; n         if (subs(i + 1, i + mid) == subt(d[i][j] + 1, d[i][j] + mid)) n           l = mid; n         else n           r = mid - 1; n       } n       d[i + l][j + 1] = max(d[i + l][j + 1], d[i][j] + l); n     } n   } n   for (int i = (1); i <= (int)(first); ++i) { n     if (d[n][i] == m) { n       cout <<  YES  n            <<   n ; n       return 0; n     } n   } n   cout <<  NO  n        <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long int a[123456], b[123456]; n vector<long long int> v1, v2, v3; n map<long long int, long long int> mp; n map<string, long long int> mps; n map<char, long long int> mpc; n int main() { n   long long int f = 0, x = 0, l = 0, r = 0, n, i; n   cin >> n; n   for (i = 0; i < n; i++) { n     cin >> a[i]; n     b[i] = a[i]; n   } n   sort(b, b + i); n   for (i = 0; i < n; i++) { n     if (a[i] != b[i]) { n       l = i + 1; n       break; n     } n   } n   for (i = n - 1; i >= 0; i--) { n     if (a[i] != b[i]) { n       r = i + 1; n       break; n     } n   } n   if (l == 0 && r == 0) { n     l = 1; n     r = 1; n     cout <<  yes  << endl; n     cout << l <<     << r << endl; n     return 0; n   } n   long long int k = r - 1; n   for (i = l - 1; i <= r - 1; i++) { n     long long int aa = i; n     long long int bb = k; n     if (mp[bb] == 0 && mp[aa] == 0) { n       swap(a[i], a[k]); n       mp[aa] = 1; n       mp[bb] = 1; n       k--; n     } n   } n   for (i = 0; i < n; i++) { n     if (a[i] != b[i]) { n       cout <<  no  << endl; n       return 0; n     } n   } n   cout <<  yes  << endl; n   cout << l <<     << r << endl; n } n


#include <bits/stdc++.h> n using namespace std; n mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count()); n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   map<string, vector<int> > mda; n   int n, k; n   cin >> n >> k; n   for (int i = 0; i < n; i++) { n     string s; n     cin >> s; n     int cost; n     cin >> cost; n     mda[s].push_back(cost); n   } n   for (auto &c : mda) { n     sort(c.second.rbegin(), c.second.rend()); n   } n   long long ans = 0; n   long long odd = 0; n   for (auto &c : mda) { n     string t = c.first; n     reverse(t.begin(), t.end()); n     if (t < c.first) { n       long long best = 0; n       long long s = 0; n       for (int i = 0; i < (int)c.second.size() && i < mda[t].size(); i++) { n         s += c.second[i]; n         s += mda[t][i]; n         best = max(best, s); n       } n       ans += best; n     } else if (t == c.first) { n       long long s = 0; n       int mda = 0; n       long long last = 0; n       long long fir = -1e18; n       for (int i = 0; i < (int)c.second.size(); i++) { n         if (c.second[i] > 0) { n           last = c.second[i]; n           s += c.second[i]; n           mda++; n         } else { n           fir = c.second[i]; n           break; n         } n       } n       if (mda % 2 == 0) { n         ans += s; n       } else { n         long long me = max(s - last, s + fir); n         long long delta_odd = s - me; n         ans += me; n         odd = max(odd, delta_odd); n       } n     } n   } n   cout << ans + odd << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long tc, n, arr1[100005], m, arr2[100005], count = 0, even = 0, n                                                   even2 = 0, odd = 0, odd2 = 0; n   cin >> tc; n   while (tc--) { n     cin >> n; n     for (int i = 0; i < n; i++) { n       cin >> arr1[i]; n       if (arr1[i] % 2 == 0) n         even++; n       else n         odd++; n     } n     cin >> m; n     for (int i = 0; i < m; i++) { n       cin >> arr2[i]; n       if (arr2[i] % 2 == 0) n         even2++; n       else n         odd2++; n     } n     count += even * even2; n     count += odd * odd2; n     cout << count << endl; n     count = 0; n     even = 0; n     even2 = 0; n     odd = 0; n     odd2 = 0; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 1e9; n bool adj[4005][4005]; n int edges[4005]; n int main() { n   int n, m, res = INF; n   cin >> n >> m; n   while (m--) { n     int a, b; n     cin >> a >> b; n     adj[a][b] = adj[b][a] = 1; n     edges[a]++; n     edges[b]++; n   } n   for (int i = 1; i <= n; i++) n     for (int j = i + 1; j <= n; j++) { n       if (adj[i][j] == 1) { n         for (int k = j + 1; k <= n; k++) n           if (adj[j][k] == 1 && adj[k][i] == 1) n             res = min(res, edges[i] + edges[j] + edges[k] - 6); n       } n     } n   if (res == INF) n     puts( -1 ); n   else n     cout << res << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long maxn = -1e18; n long long minn = 1e18; n long long mod = 1000000007; n long long ans = 0; n long long cur = 0; n long long tong = 0, tong2 = 0; n long long cnt = 0; n long long k, l; n string s; n long long n, m, x, y; n long long b[100005]; n long long was[200005]; n bool flag = true; n vector<long long> node[200005]; n long long dp[105][105]; n long long a[55]; n long long c[55]; n map<string, int> ok; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   cout.tie(0); n   cin >> a[2] >> a[3] >> a[5] >> a[6]; n   cout << min(a[2], min(a[5], a[6])) * 256 + n               min(a[2] - min(a[2], min(a[5], a[6])), a[3]) * 32; n } n


#include <bits/stdc++.h> n using namespace std; n namespace scanfuck { n const int L = (1 << 21) + 1; n struct io { n   char ibuf[L], *iS, *iT, obuf[L], *oS, *oT, c, st[55]; n   int f, tp; n   void flush() { n     fwrite(obuf, 1, oS - obuf, stdout); n     oS = obuf; n   } n   void putc(char x) { n     *oS++ = x; n     if (oS == oT) flush(); n   } n   template <class T> n   T rd() { n     register T x = 0; n     for (f = 1, c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, L, stdin), n                                 (iS == iT ? EOF : *iS++)) n                               : *iS++); n          !isdigit(c); n          c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, L, stdin), n                          (iS == iT ? EOF : *iS++)) n                        : *iS++)) n       if (c ==  - ) f = -1; n     for (x = 0; isdigit(c); n          c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, L, stdin), n                          (iS == iT ? EOF : *iS++)) n                        : *iS++)) n       x = x * 10 + (c & 15); n     return x * f; n   } n   template <class T> n   void print(T x) { n     if (!x) n       putc( 0 ); n     else { n       if (x < 0) putc( - ), x = -x; n       for (tp = 0; x; st[tp++] = x % 10 + 48, x /= 10) n         ; n       for (tp--; ~tp; putc(st[tp--])) n         ; n     } n   } n   void gs(char* s, int& l) { n     for (c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, L, stdin), n                          (iS == iT ? EOF : *iS++)) n                        : *iS++); n          !isalpha(c); n          c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, L, stdin), n                          (iS == iT ? EOF : *iS++)) n                        : *iS++)) n       ; n     for (l = 0; isalpha(c); n          c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, L, stdin), n                          (iS == iT ? EOF : *iS++)) n                        : *iS++)) n       s[l++] = c; n   } n   void ps(const char* s) { n     for (tp = 0; tp < strlen(s); ++tp) putc(s[tp]); n   } n   io() : oS(obuf), oT(obuf + L - 1) {} n   ~io() { flush(); } n } ip; n }  // namespace scanfuck n int n = scanfuck::ip.rd<int>(), m = scanfuck::ip.rd<int>(), n     k = scanfuck::ip.rd<int>(); n inline bool judge() { n   if (!(n & 1)) return 1; n   int t = sqrt(m); n   for (register int i = 1; i <= t; ++i) n     if (m % i == 0 && (i >= k && m / i > 1 || i > 1 && m / i >= k)) return 0; n   return 1; n } n int main() { scanfuck::ip.ps(judge() ?  Marsel  :  Timur ); } n


#include <bits/stdc++.h> n using namespace std; n template <typename T> n vector<T>& operator--(vector<T>& v) { n   for (auto& i : v) --i; n   return v; n } n template <typename T> n vector<T>& operator++(vector<T>& v) { n   for (auto& i : v) ++i; n   return v; n } n template <typename T> n istream& operator>>(istream& is, vector<T>& v) { n   for (auto& i : v) is >> i; n   return is; n } n template <typename T> n ostream& operator<<(ostream& os, vector<T>& v) { n   for (auto& i : v) os << i <<    ; n   return os; n } n template <typename T, typename U> n istream& operator>>(istream& is, pair<T, U>& p) { n   is >> p.first >> p.second; n   return is; n } n template <typename T, typename U> n ostream& operator<<(ostream& os, pair<T, U>& p) { n   os << p.first <<     << p.second; n   return os; n } n template <typename T, typename U> n pair<T, U> operator-(pair<T, U> a, pair<T, U> b) { n   return make_pair(a.first - b.first, a.second - b.second); n } n template <typename T, typename U> n pair<T, U> operator+(pair<T, U> a, pair<T, U> b) { n   return make_pair(a.first + b.first, a.second + b.second); n } n template <typename T, typename U> n void umin(T& a, U b) { n   if (a > b) a = b; n } n template <typename T, typename U> n void umax(T& a, U b) { n   if (a < b) a = b; n } n const int K = 15; n array<array<bool, 1 << K>, K> dp; n int main() { n   int k; n   cin >> k; n   vector<vector<int>> v(k); n   map<int, int> where; n   vector<long long> sms(k, 0); n   long long need = 0; n   for (int i = 0; i < k; ++i) { n     int n; n     cin >> n; n     v[i].resize(n); n     cin >> v[i]; n     for (auto u : v[i]) { n       where[u] = i; n       sms[i] += u; n       need += u; n     } n   } n   if (need % k != 0) { n     cout <<  No n ; n     return 0; n   } n   need /= k; n   vector<map<int, pair<int, int>>> from(k); n   for (int i = 0; i < k; ++i) { n     for (int j = 0; j < v[i].size(); ++j) { n       int next = need - (sms[i] - v[i][j]); n       if (where.count(next)) { n         from[i][v[i][j]] = make_pair(next, where[next]); n       } else { n         from[i][v[i][j]] = make_pair(0, -1); n       } n     } n   } n   set<int> used; n   vector<pair<int, int>> sth; n   for (int i = 0; i < k; ++i) { n     for (int j = 0; j < v[i].size(); ++j) { n       int start = v[i][j]; n       if (used.count(start)) continue; n       int start_i = i; n       int now = start; n       int visited = 1 << i; n       bool ok = true; n       vector<int> was = {start}; n       while (true) { n         auto [next, next_i] = from[start_i][start]; n         if (next_i == -1) { n           ok = false; n           break; n         } n         if (visited & (1 << next_i)) { n           if (next != now) { n             ok = false; n           } n           break; n         } n         visited |= (1 << next_i); n         start = next; n         start_i = next_i; n         if (used.count(start)) { n           ok = false; n           break; n         } n         was.push_back(start); n       } n       if (ok) { n         for (auto y : was) { n           used.insert(y); n         } n         sth.emplace_back(visited, now); n       } n     } n   } n   dp[0].fill(false); n   for (auto [mask, s] : sth) { n     dp[0][mask] = true; n   } n   dp[0][0] = true; n   for (int i = 1; i < k; ++i) { n     for (int j = 0; j < (1 << k); ++j) { n       int mask = j; n       int submask = mask; n       if (j == 0) { n         dp[i][mask] = true; n       } else { n         dp[i][mask] = false; n       } n       while (submask != 0) { n         if (dp[i - 1][submask] && dp[i - 1][mask ^ submask]) { n           dp[i][mask] = true; n           break; n         } n         submask = (submask - 1) & mask; n       } n     } n   } n   if (!dp[k - 1][(1 << k) - 1]) { n     cout <<  No n ; n     return 0; n   } n   cout <<  Yes n ; n   vector<int> masks = {(1 << k) - 1}; n   for (int i = k - 1; i > 0; --i) { n     vector<int> new_masks; n     for (auto mask : masks) { n       int submask = mask; n       while (submask != 0) { n         if (dp[i - 1][submask] && dp[i - 1][mask ^ submask]) { n           if (submask) new_masks.push_back(submask); n           if (mask ^ submask) new_masks.push_back(mask ^ submask); n           break; n         } n         submask = (submask - 1) & mask; n       } n     } n     swap(new_masks, masks); n   } n   sort(sth.begin(), sth.end()); n   42; n   ; n   vector<int> starts; n   vector<pair<pair<int, int>, int>> ans; n   for (auto mask : masks) { n     auto it = n         lower_bound(sth.begin(), sth.end(), make_pair(mask, (int)(-1e9 - 10))); n     assert(it->first == mask); n     int start = it->second; n     int now = start; n     int now_i = where[start]; n     int visited = 1 << now_i; n     vector<pair<int, int>> path; n     path.emplace_back(now_i, now); n     while (true) { n       auto [next, next_i] = from[now_i][now]; n       if (visited & (1 << next_i)) { n         break; n       } n       now = next; n       now_i = next_i; n       path.emplace_back(now_i, now); n       visited |= 1 << next_i; n     } n     for (int i = 0; i < path.size(); ++i) { n       ans.emplace_back(path[i], n                        path[(i - 1 + path.size()) % path.size()].first); n     } n   } n   sort(ans.begin(), ans.end()); n   for (auto [p, y] : ans) { n     cout << p.second <<     << y + 1 << endl; n   } n   return 0; n } n