#include <bits/stdc++.h> n using namespace std; n auto clk = clock(); n mt19937_64 rang( n     chrono::high_resolution_clock::now().time_since_epoch().count()); n void test_case() { n   long long int n; n   cin >> n; n   long long int a[n + 1]; n   long long int t = -1, b = -1, c = -1; n   for (long long int i = 1; i <= n; i++) { n     cin >> a[i]; n   } n   for (long long int i = 2; i <= n - 1; i++) { n     for (long long int j = i - 1; j >= 1; j--) { n       if (a[j] < a[i]) { n         t = j; n         break; n       } n     } n     for (long long int j = i + 1; j <= n; j++) { n       if (a[j] < a[i]) { n         c = j; n         break; n       } n     } n     if (t != -1 && c != -1) { n       b = i; n       break; n     } n     t = -1, c = -1; n   } n   if (b != -1) { n     cout <<  YES  << endl; n     cout << t <<     << b <<     << c << endl; n   } else n     cout <<  NO  << endl; n } n signed main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   srand(chrono::high_resolution_clock::now().time_since_epoch().count()); n   cout << fixed << setprecision(10); n   long long int t = 1; n   cin >> t; n   while (t--) { n     test_case(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n long long nthRoot(long long A, long long N) { n   float xPre = rand() % 10; n   float eps = 1e-3; n   float delX = LLONG_MAX; n   float xK; n   while (delX > eps) { n     xK = ((N - 1.0) * xPre + (float)A / pow(xPre, N - 1)) / (float)N; n     delX = abs(xK - xPre); n     xPre = xK; n   } n   return ceil(xK); n } n int main() { n   long long n; n   cin >> n; n   char a[] = { c ,  o ,  d ,  e ,  f ,  o ,  r ,  c ,  e ,  s }; n   long long in = 0, num; n   num = nthRoot(n, 10); n   if (pow(num, 10) < n) num++; n   for (int i = 0; i <= 10; i++) { n     if (pow(num - 1, i) * pow(num, 10 - i) >= n) { n       in = i; n     } else n       break; n   } n   if (in * (num - 1) + (10 - in) * num - 10 < n - 1) { n     for (int i = 0; i < in; i++) { n       long long t = num - 1; n       while (t--) cout << a[i]; n     } n     for (int i = in; i < 10; i++) { n       long long t = num; n       while (t--) cout << a[i]; n     } n   } else { n     for (int i = 0; i < 10; i++) cout << a[i]; n     long long t = n - 1; n     while (t--) cout << a[9]; n   } n } n


#include <bits/stdc++.h> n using namespace std; n template <class T> n inline void amin(T& a, const T& b) { n   if (a > b) a = b; n } n template <class T> n inline void amax(T& a, const T& b) { n   if (a < b) a = b; n } n template <class T> n inline void rv(vector<T>& v, int n) { n   vector<T>(n).swap(v); n   for (int i = 0; i < (n); i++) cin >> v[i]; n } n inline void rv(int* v, int n) { n   for (int i = 0; i < (n); i++) scanf( %d , &v[i]); n } n inline void rv(long long* v, int n) { n   for (int i = 0; i < (n); i++) scanf( %lld , &v[i]); n } n inline vector<int> rvi(int n) { n   vector<int> v(n); n   for (int i = 0; i < (n); i++) scanf( %d , &v[i]); n   return v; n } n inline vector<long long> rvl(int n) { n   vector<long long> v(n); n   for (int i = 0; i < (n); i++) scanf( %lld , &v[i]); n   return v; n } n inline vector<string> rvs(int n) { n   vector<string> v(n); n   for (int i = 0; i < (n); i++) scanf( %s , &v[i]); n   return v; n } n template <class T> n inline void readvv(vector<vector<T>>& v, int m, int n) { n   vector<vector<T>>(m).swap(v); n   for (int i = 0; i < (m); i++) readv(v[i], n); n } n inline void pvi(vector<int>& v) { n   for (int i = 0; i < (v.size()); i++) printf( %d  , v[i]); n   printf(  n ); n } n inline void pvl(vector<long long>& v) { n   for (int i = 0; i < (v.size()); i++) { n     printf( %lld  , v[i]); n   } n   printf(  n ); n } n inline void pvs(vector<string>& v) { n   for (int i = 0; i < (v.size()); i++) { n     printf( %s n , v[i].c_str()); n   } n } n int main() { n   long long n; n   long double s; n   cin >> n >> s; n   vector<vector<long long>> g(n); n   for (int i = 0; i < (n - 1); i++) { n     long long u, v; n     cin >> u >> v; n     g[u - 1].push_back(v - 1); n     g[v - 1].push_back(u - 1); n   } n   long double leaves = 0, two = 2; n   for (int i = 0; i < (n); i++) { n     if (g[i].size() == 1) leaves++; n   } n   cout << setprecision(20) << endl; n   cout << ((two * s) / leaves) << endl; n   return 0; n } n


#include  bits/stdc++.h  n using namespace std; n #define all(x) x.begin(),x.end() n #define pb push_back n #define ff first n #define ss second n #define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0) n #define ar array n #define int long long  n #define F(i,a,b) for(i=a;i<b;++i) n #define RF(i,b,a) for(i=b;i>=a;--i)  n #define NL cout<<  n ; n #define INF LONG_LONG_MAX n #define pii pair<int,int> n #define vi vector<int> n  n typedef long long ll; n typedef long double ld; n const ll mod=1e9+7; n bool comp(ll a,ll b) n { n  return a<b; n } n ll fpow(ll a, ll b) { n  n  ll res=1; n  while(b) { n   if(b&1) n    res=(res*a); n   a=(a*a); n   b>>=1; n  } n  return res; n } n  n ll minm(ll a,ll b){ n  if(a<b) return a; n  return b; n } n  n ll maxm(ll a,ll b){ n  if(a>b){ return a;} n  else return b; n } n  n int PHI(int k){ n  // This is Euler s Totient Function. n  //This function returns no. of coprime numbers to N in range [1,2,....,N] n  n    int ans=k; n    for(int i=2;i*i<=k;++i){ n     if(k%i==0){ n      ans-=ans/i; n      while(k%i==0){ n       k/=i; n      } n     } n    } n      if(k>1) ans-=ans/k; n      return ans; n   n  n } n  n void solve(){ n    n    int n,i; n    cin >> n; n     n    vector<pii>ecells; n    vector<pii>ocells; n     n    for(i=1;i<=n;i++){ n     for(int j=1;j<=n;j++){ n      if((i+j)%2){ n       ocells.pb({i,j}); n      } n      else ecells.pb({i,j}); n     } n    } n     n    // 1 even n    // 2,3 odd n    // if not possible ie all odd are filled, fill 2,3 in even n     n    int cnt=0; n     n    while(cnt<n*n){ n     int a; cin >> a; n      n     if(a==1){ n       // try to fill 2 in odd cell  n       // if not possible , fill 3 in even n       if(ocells.empty()){ n        cout<< 3  <<ecells.back().ff<<   <<ecells.back().ss<<endl; n        ecells.pop_back(); n       } n        n       else{ n        cout<< 2  <<ocells.back().ff<<   <<ocells.back().ss<<endl; n        ocells.pop_back(); n       } n       ++cnt; n     } n      n     else if(a==2){ n      // fill 1 in even , if possible n      if(!ecells.empty()){ n       cout<< 1  <<ecells.back().ff<<   <<ecells.back().ss<<endl; n       ecells.pop_back(); n      } n       n      else{ n       // fill 3 in ocells n       cout<< 3  <<ocells.back().ff<<   <<ocells.back().ss<<endl; n       ocells.pop_back(); n      } n      cnt++; n     } n     else{ n      // fill 1 in even if possible n      if(!ecells.empty()){ n       cout<< 1  <<ecells.back().ff<<   <<ecells.back().ss<<endl; n       ecells.pop_back(); n      } n      else{ n       // fill 2 in odd n       cout<< 2  <<ocells.back().ff<<   <<ocells.back().ss<<endl; n       ocells.pop_back(); n      } n      cnt++; n     } n    } n     n     n  n } n  n  n signed main(void)      n { n  n  fast; n  n    n  int _=1; n  //cin>>_; n   n       for(int test_case=1;test_case<=_;++test_case){ n          solve(); n       } n     n   n }


#include <bits/stdc++.h> n int main() { n   char str[3][100]; n   int i; n   for (i = 0; i < 3; i++) { n     scanf( %s  , &str[i][0]); n   } n   int r = 0, p = 0, s = 0; n   for (i = 0; i < 3; i++) { n     if (str[i][0] ==  r ) n       r++; n     else if (str[i][0] ==  p ) n       p++; n     else if (str[i][0] ==  s ) n       s++; n   } n   char m =  a ; n   if (r == 1 && s == 2) n     m =  r ; n   else if (s == 1 && p == 2) n     m =  s ; n   else if (p == 1 && r == 2) n     m =  p ; n   if (m !=  a ) { n     for (i = 0; i < 3; i++) { n       if (str[i][0] == m) break; n     } n     if (i == 0) n       printf( F ); n     else if (i == 1) n       printf( M ); n     else if (i == 2) n       printf( S ); n   } else n     printf( ? ); n } n


#include <bits/stdc++.h> n using namespace std; n long long int powe(long long int d, long long int s) { n   if (s == 1) n     return d; n   else if (s == 0) n     return 1; n   else { n     long long int u, v = d; n     for (u = 1; u < s; u++) { n       d = d * v; n     } n     return d; n   } n } n bool isprime(long long int n) { n   long long int i; n   for (i = 2; i * i <= n; i++) { n     if (n % i == 0) { n       return false; n     } n   } n   return true; n } n long long int a[2000005], c[10000005]; n int main() { n   map<int, int> b; n   long long int i, p, y, mx = -1, j, q; n   cin >> p >> y; n   for (i = y; i > p; i--) { n     q = 1; n     for (j = 2; j * j <= i && j <= p; j++) { n       if (i % j == 0) { n         q = 0; n         break; n       } n     } n     if (q == 1) { n       cout << i; n       return 0; n     } n   } n   cout << -1; n } n


#include <bits/stdc++.h> n using namespace std; n using llint = long long; n using par = pair<int, int>; n const int MAXN = 200100; n llint w[MAXN]; n vector<par> edges[MAXN]; n int p[MAXN], in[MAXN], out[MAXN], idx[MAXN], id; n void dfs(int u) { n   in[u] = ++id; n   for (const auto& edge : edges[u]) { n     if (edge.first == p[u]) continue; n     p[edge.first] = u; n     idx[edge.first] = edge.second; n     dfs(edge.first); n   } n   out[u] = id; n } n int next(int u) { return w[idx[u]] == 1 ? p[u] = next(p[u]) : u; } n void toLCA(int u, int v, llint& c) { n   if (!u || !c) return; n   if (in[u] <= in[v] && out[u] >= out[v]) return; n   c /= w[idx[u]]; n   toLCA(p[u] = next(p[u]), v, c); n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n   llint c; n   int n, m, u, v; n   cin >> n >> m; n   for (int i = 1; i < n; ++i) { n     cin >> u >> v >> w[i]; n     edges[u].emplace_back(v, i); n     edges[v].emplace_back(u, i); n   } n   dfs(1); n   while (m--) { n     cin >> u; n     if (u == 1) { n       cin >> u >> v >> c; n       toLCA(u, v, c); n       toLCA(v, u, c); n       cout << c <<   n ; n     } else { n       cin >> u >> c; n       w[u] = c; n     } n   } n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n ll BASE_NUM = 998244353; n class UnionFindTree { n   map<ll, ll> union_tree_data; n  n  public: n   UnionFindTree() {} n   UnionFindTree(vector<ll> verticals) { n     for (auto v : verticals) { n       union_tree_data[v] = v; n     } n   } n   void add_vertical(ll v) { union_tree_data[v] = v; } n   void reset() { n     for (auto &pair : union_tree_data) { n       pair.second = pair.first; n     } n   } n   long long find(long long N) { n     if (union_tree_data[N] == N) { n       return N; n     } else { n       return union_tree_data[N] = find(union_tree_data[N]); n     } n   } n   bool same(long long x, long long y) { return find(x) == find(y); } n   void union_tree(long long x, long long y) { n     x = find(x); n     y = find(y); n     if (x == y) return; n     union_tree_data[x] = y; n   } n }; n class edge { n  public: n   ll from, to, cost; n   bool operator<(const edge &another) const { return cost < another.cost; }; n   bool operator>(const edge &another) const { return cost > another.cost; }; n }; n class MST { n   UnionFindTree uft; n  n  public: n   priority_queue<edge, vector<edge>, greater<edge>> que; n   vector<edge> result; n   ll cost = 0; n   MST(vector<ll> &nodes, vector<edge> &edges) : uft(nodes) { n     for (auto e : edges) { n       que.push(e); n     } n     while (!que.empty()) { n       edge e; n       e = que.top(); n       if (!uft.same(e.from, e.to)) { n         uft.union_tree(e.from, e.to); n         result.push_back(e); n         cost += e.cost; n       } n       que.pop(); n     } n   } n }; n int main() { n   ll n; n   vector<pair<ll, ll>> towns; n   vector<ll> costs; n   vector<ll> ks; n   vector<edge> edges; n   cin >> n; n   for (int i = 0; i < n; i++) { n     pair<ll, ll> p; n     cin >> p.first >> p.second; n     towns.push_back(p); n   } n   for (int i = 0; i < n; i++) { n     ll c; n     cin >> c; n     costs.push_back(c); n   } n   for (int i = 0; i < n; i++) { n     ll k; n     cin >> k; n     ks.push_back(k); n   } n   for (int i = 0; i < n; i++) { n     for (int j = i + 1; j < n; j++) { n       edges.push_back({i, j, n                        (abs(towns[i].first - towns[j].first) + n                         abs(towns[i].second - towns[j].second)) * n                            (ks[i] + ks[j])}); n     } n   } n   for (int i = 0; i < n; i++) { n     edges.push_back({i, n, costs[i]}); n   } n   vector<ll> nodes(n + 1); n   for (int i = 0; i < n + 1; i++) { n     nodes[i] = i; n   } n   MST mst(nodes, edges); n   vector<ll> stations; n   vector<pair<ll, ll>> connections; n   for (auto e : mst.result) { n     if (e.to == n) { n       stations.push_back(e.from); n     } else { n       connections.push_back(make_pair(e.from, e.to)); n     } n   } n   cout << mst.cost <<   n ; n   cout << stations.size() <<   n ; n   for (int i = 0; i < stations.size(); i++) { n     if (i == 0) { n       cout << stations[i] + 1; n     } else { n       cout <<     << stations[i] + 1; n     } n   } n   cout <<   n ; n   cout << connections.size() <<   n ; n   for (int i = 0; i < connections.size(); i++) { n     cout << connections[i].first + 1 <<     << connections[i].second + 1 n          <<   n ; n   } n   cout << flush; n   return 0; n } n


#include <bits/stdc++.h> n #define fi first n #define se second n #define gc getchar() //(p1==p2&&(p2=(p1=buf)+fread(buf,1,size,stdin),p1==p2)?EOF:*p1++) n #define mk make_pair n #define pii pair<int, int> n #define pll pair<ll, ll> n #define pb push_back n #define IT iterator n #define V vector n #define TP template <class o> n #define TPP template <typename t1, typename t2> n #define SZ(a) ((int)a.size()) n #define all(a) a.begin(), a.end() n #define rep(i, a, b) for (int i = a; i <= b; i++) n #define REP(i, a, b) for (int i = b; i >= a; i--) n #define FOR(i,n) rep(i,1,n) n #define debug(x) cerr << #x <<   =   << x << endl n using namespace std; n typedef unsigned ui; n typedef long long ll; n typedef unsigned long long ull; n typedef double db; n typedef long double ld; n const int N = 3010, size = 1 << 20, mod = 998244353, inf = 2e9; n const ll INF = 1e15; n  n // char buf[size],*p1=buf,*p2=buf; n TP void qr(o& x) { n     char c = gc; n     x = 0; n     int f = 1; n     while (!isdigit(c)) { n         if (c ==  - ) n             f = -1; n         c = gc; n     } n     while (isdigit(c)) n         x = x * 10 + c -  0 , c = gc; n     x *= f; n } n template<class o,class ... O> void qr(o& x, O& ... y) {qr(x); qr(y...);} n TP void qw(o x) { n     if (x / 10) n         qw(x / 10); n     putchar(x % 10 +  0 ); n } n TP void pr1(o x) { n     if (x < 0) n         x = -x, putchar( - ); n     qw(x); n     putchar(   ); n } n template<class o,class ... O> void pr1(o x, O ... y) { pr1(x); pr1(y...);} n TP void pr2(o x) { n     if (x < 0) n         x = -x, putchar( - ); n     qw(x); n     putchar(  n ); n } n template<class o,class ... O> void pr2(o x, O ... y) { pr2(x); pr2(y...);} n  n // math n ll gcd(ll a, ll b) { return !a ? b : gcd(b % a, a); } n ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } n ll power(ll a, ll b = mod - 2, ll p = mod) { n     ll c = 1; n     while (b) { n         if (b & 1) c = c * a % p; n         b /= 2; n         a = a * a % p; n     } n     return c; n } n ll exgcd(ll a,ll b,ll &x,ll &y) { n  if(!a) {x=0; y=1; return b;} n  ll d=exgcd(b%a,a,y,x); x -= b/a*y; n  return d; n } n ll INV(ll n,ll p=mod) {ll x,y; exgcd(n,p,x,y); return (x%p+p)%p;} n  n TP void cmax(o& x, o y) { n     if (x < y) n         x = y; n } n TP void cmin(o& x, o y) { n     if (x > y) n         x = y; n } n TPP void ad(t1& x, t2 y) { n     x += y; n     if (x >= mod) n         x -= mod; n } n TPP void dl(t1& x, t2 y) { n     x -= y; n     if (x < 0) n         x += mod; n } n   n int n, m, X[N], Y[N]; n V<int> e[N], g[N], E, P; n bool v[N]; n #define DEBUG n  n void dfs(int x) { n  int i, y; n  while(SZ(g[x])) { n   i = g[x].back(); g[x].pop_back(); n   if(v[i]) continue; n   y = x ^ X[i] ^ Y[i]; n   v[i] = 1; dfs(y); n  } n  P.pb(x); n } n  n void check(int s, int w = 0) { n  FOR(i, n) g[i] = e[i]; n  FOR(i, m) v[i] = 0; n  int cnt = 0; n  FOR(i, n) if(i ^ s) cnt += SZ(e[i]) & 1; n  if(cnt > 1) return ; n  P.clear(); dfs(s); n  if(SZ(P) + SZ(E) - 1 - (w > 0) != m) return ; n  P.pb(-1); n  for(int i: E) if(i ^ w) P.pb(X[i] ^ Y[i] ^ s), P.pb(s);  n  pr2(SZ(P)); n  for(int i: P) pr1(i); n  exit(0); n } n  n void solve() { n  qr(n, m); n  FOR(i, m) qr(X[i], Y[i]); n  FOR(s, n) { n   FOR(i, n) e[i].clear(); n   P.clear(); E.clear(); n   FOR(i, m) { n    int x = X[i], y = Y[i]; n    if(x == s || y == s) continue; n    e[x].pb(i); e[y].pb(i); n   } n   FOR(i, m) { n    int x = X[i], y = Y[i]; n    if(x == s || y == s) { n     int v = s ^ x ^ y; n     if(SZ(e[v]) & 1) e[s].pb(i), e[v].pb(i); n     else E.pb(i); n    } n   } n   check(s); n   for(int i: E) { n    e[X[i]].pb(i); e[Y[i]].pb(i); n    check(s, i); n    e[X[i]].pop_back(); e[Y[i]].pop_back(); n   } n  } n  puts( 0 ); n } n  n int main() { n     int T = 1; n //    qr(T); n     while (T--) n         solve(); n     return 0; n } n  n  n


#include <bits/stdc++.h> n using namespace std; n bool found = false; n long long b, A[10000], n, orig_a; n void bfs(long long a, long long k) { n   if (found) return; n   if (a > b) return; n   if (a == b) { n     found = true; n     n = k; n     a = orig_a; n     cout <<  YES  << endl; n     cout << n + 1 << endl; n     cout << a; n     for (int i = 0; i < n; i++) { n       if (A[i] == 1) { n         a = a * 10 + 1; n         cout <<     << a; n       } else if (A[i] == 2) { n         a = a * 2; n         cout <<     << a; n       } n     } n     cout << endl; n     return; n   } n   A[k] = 2; n   bfs(a * 2, k + 1); n   A[k] = 1; n   bfs((a * 10) + 1, k + 1); n } n int main() { n   long long a, c, d, i, j, m; n   string s; n   cin >> a >> b; n   orig_a = a; n   bfs(a, 0); n   if (!found) cout <<  NO  << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n class Compare { n  public: n   bool operator()(pair<long long, long long> a, pair<long long, long long> b) { n     return (a.first + a.second) > (b.first + b.second); n   } n }; n int main() { n   long long test, x, n, m, k, w, d, f, y; n   priority_queue<pair<long long, long long>, n                  vector<pair<long long, long long> >, Compare> n       pqw; n   priority_queue<pair<long long, long long>, n                  vector<pair<long long, long long> >, Compare> n       pqd; n   priority_queue<pair<long long, long long>, n                  vector<pair<long long, long long> >, Compare> n       pqf; n   scanf( %lld%lld%lld%lld%lld%lld%lld , &x, &n, &m, &k, &w, &d, &f); n   for (long long i = 0; i < n; i++) { n     pqw.push(make_pair(0, w)); n   } n   for (long long i = 0; i < m; i++) { n     pqd.push(make_pair(0, d)); n   } n   for (long long i = 0; i < k; i++) { n     pqf.push(make_pair(0, f)); n   } n   long long ans = 0; n   for (long long i = 0; i < x; i++) { n     pair<long long, long long> cur = pqw.top(); n     pqw.pop(); n     pqw.push(make_pair(cur.first + cur.second, cur.second)); n     pair<long long, long long> curd = pqd.top(); n     pqd.pop(); n     curd.first = max(cur.first + cur.second, curd.first) + d; n     pqd.push(curd); n     pair<long long, long long> curf = pqf.top(); n     pqf.pop(); n     curf.first = max(curd.first, curf.first) + f; n     pqf.push(curf); n     ans = curf.first; n   } n   cout << ans; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int P = 1e9 + 7; n vector<int> b[200005]; n int L[200005], R[200005], u[200005], v[200005], opt[200005], size[200005]; n int m, n, ql, qr, upd, tot, now, ans, i, x; n struct data { n   int cnt, sum; n   data() { cnt = 1; } n   void multi(int x) { n     cnt = 1ll * cnt * x % P; n     sum = 1ll * sum * x % P; n   } n   int renew(int x) { n     cnt = 1; n     sum = x; n     return 0; n   } n } a[200005 << 2]; n void DFS(int x, int Fa) { n   L[x] = ++tot; n   for (int i = 0, y; i < b[x].size(); i++) n     if ((y = b[x][i]) != Fa) DFS(y, x); n   R[x] = tot; n } n int INV(int a) { n   int ret = 1, b = P - 2; n   for (; b; b >>= 1, a = 1ll * a * a % P) n     if (b & 1) ret = 1ll * ret * a % P; n   return ret; n } n inline void down(int x) { n   if (a[x].cnt == 1) return; n   a[x << 1].multi(a[x].cnt); n   a[x << 1 | 1].multi(a[x].cnt); n   a[x].cnt = 1; n } n inline void up(int x) { a[x].sum = (a[x << 1].sum + a[x << 1 | 1].sum) % P; } n void Multi(int x, int l, int r) { n   if (ql <= l && r <= qr) { n     a[x].multi(now); n     return; n   } n   int mid = (l + r) >> 1; n   down(x); n   if (ql <= mid) Multi(x << 1, l, mid); n   if (qr > mid) Multi(x << 1 | 1, mid + 1, r); n   up(x); n } n int Update(int x, int l, int r, int pos) { n   if (l == r) return (!upd) ? a[x].sum : a[x].renew(now); n   int mid = (l + r) >> 1; n   down(x); n   int ret = (pos <= mid) ? Update(x << 1, l, mid, pos) n                          : Update(x << 1 | 1, mid + 1, r, pos); n   return up(x), ret; n } n void Query(int x, int l, int r) { n   if (ql <= l && r <= qr) { n     ans = (ans + a[x].sum) % P; n     return; n   } n   int mid = (l + r) >> 1; n   down(x); n   if (ql <= mid) Query(x << 1, l, mid); n   if (qr > mid) Query(x << 1 | 1, mid + 1, r); n } n int main() { n   scanf( %d%d , &v[1], &m); n   n = 1; n   for (i = 1; i <= m; i++) { n     scanf( %d%d , &opt[i], &u[i]); n     if (opt[i] == 1) scanf( %d , &v[++n]), b[u[i]].push_back(n); n   } n   DFS(1, 0); n   size[n = 1] = 1; n   upd = 1; n   now = v[1]; n   Update(1, 1, tot, L[1]); n   for (i = 1; i <= m; i++) n     if (opt[i] == 1) { n       x = u[i]; n       size[++n] = 1; n       ql = L[x]; n       qr = R[x]; n       now = 1ll * (size[x] + 1) * INV(size[x]) % P; n       ++size[x]; n       Multi(1, 1, tot); n       upd = 0; n       now = Update(1, 1, tot, L[x]); n       now = 1ll * now * INV(v[x]) % P; n       now = 1ll * now * v[n] % P; n       upd = 1; n       Update(1, 1, tot, L[n]); n     } else { n       x = u[i]; n       ans = 0; n       ql = L[x]; n       qr = R[x]; n       Query(1, 1, tot); n       upd = 0; n       now = Update(1, 1, tot, L[x]); n       now = 1ll * now * INV(1ll * v[x] * size[x] % P) % P; n       ans = 1ll * ans * INV(now) % P; n       printf( %d n , ans); n     } n } n


#include <bits/stdc++.h> n using namespace std; n const long long mod = 1000000007; n const long double PI = 3.141592653589793; n const long long maxn = 100005; n long long x, y, z, n, k; n void _print(long long 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 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 solve() { n   string s, t; n   cin >> s >> t; n   long long f[26]; n   memset(f, 0, sizeof(f)); n   long long n = (long long)s.size(), m = (long long)t.size(); n   vector<vector<long long>> v(26); n   for (long long i = 0; i <= n - 1; i++) { n     f[s[i] -  a ]++; n     v[s[i] -  a ].push_back(i); n   } n   for (long long i = 0; i <= m - 1; i++) { n     if (f[t[i] -  a ] == 0) { n       cout << -1 <<   n ; n       return; n     } n   } n   long long ans = 1, last = -1; n   for (long long i = 0; i <= m - 1; i++) { n     long long prev = last; n     long long val = t[i] -  a ; n     long long pos = n         lower_bound(v[val].begin(), v[val].end(), last + 1) - v[val].begin(); n     if (pos == v[val].size()) { n       ans++; n       last = v[val][0]; n     } else { n       last = v[val][pos]; n     } n   } n   cout << ans <<   n ; n } n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   cout.tie(NULL); n   cout << setprecision(15) << fixed; n   long long t; n   t = 1; n   cin >> t; n   while (t--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n const double eps = 1e-8; n const long long INF = 0x3f3f3f3f; n const int mod = 20000311; n const int maxn = 1e5 + 5; n const int N = 1005; n using namespace std; n int a[maxn] = {0}; n int dp[maxn][305] = {0}; n int n; n int dfs(int p, int k) { n   if (p > n) return 0; n   if (dp[p][k] != -1) return dp[p][k]; n   int num = p + a[p] + k; n   return dp[p][k] = dfs(num, k) + 1; n } n int main() { n   scanf( %d , &n); n   for (int i = 1; i <= n; i++) scanf( %d , &a[i]); n   for (int j = 1; j <= 300; j++) { n     for (int i = n; i >= 1; i--) { n       int num = i + a[i] + j; n       if (num > n) n         dp[i][j] = 1; n       else n         dp[i][j] = dp[num][j] + 1; n     } n   } n   int q; n   scanf( %d , &q); n   while (q--) { n     int p, k; n     scanf( %d %d , &p, &k); n     if (k >= 300) { n       int res = 0; n       while (p <= n) { n         p = a[p] + k + p; n         res++; n       } n       cout << res <<   n ; n     } else n       cout << dp[p][k] <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n string Max(int n, int s) { n   string str =   ; n   while (s >= 9 && n > 0) { n     str +=  9 ; n     s -= 9; n     n--; n   } n   if (n == 0 && s > 0) return  -1 ; n   if (n > 0) { n     str += char(s + 48); n     for (int i = 1; i < n; i++) str +=  0 ; n   } n   return str; n } n int main() { n   int n, s; n   string str =   ; n   cin >> n >> s; n   if (n * 9 < s) n     cout <<  -1 -1 ; n   else if (n > 1 and s == 0) n     cout <<  -1 -1 ; n   else if (s == 1) { n     cout << 1; n     for (int i = 1; i < n; i++) cout << 0; n     cout <<   1 ; n     for (int i = 1; i < n; i++) cout << 0; n   } else { n     for (int i = Max(n, s).size() - 1; i >= 0; i--) str += Max(n, s)[i]; n     if (str[0] ==  0  and str.size() > 1) { n       str[0] =  1 ; n       for (int i = 1; i < str.size(); i++) n         if (str[i] >  0 ) { n           str[i] = char(int(str[i]) - 1); n           break; n         } n     } n     cout << str <<     << Max(n, s); n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int M = 1e9 + 7; n const int MAX_N = 1002; n int dp_end[MAX_N][MAX_N]; n int dp_not[MAX_N][MAX_N]; n int main() { n   int n; n   cin >> n; n   for (int i = 1; i <= n; i++) { n     dp_end[0][i] = (i + 1) / 2; n     dp_not[0][i] = i / 2; n   } n   for (int i = 1; i <= n; i++) { n     for (int j = i; j <= n; j++) { n       dp_end[i][j] = 1 + dp_not[i - 1][j] + dp_end[i][j - 1]; n       if (i - 1 >= j) { n         dp_end[i][j] = n             max(dp_end[i][j], 1 + dp_not[i][j - 1] + dp_end[i - 1][j]); n       } n       dp_end[i][j] %= M; n       dp_not[i][j] = dp_end[i][j - 1] + dp_end[i - 1][j]; n       dp_not[i][j] %= M; n     } n   } n   cout << dp_end[n][n] << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void c_p_c() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n } n int32_t main() { n   c_p_c(); n   long long n; n   string s[222222]; n   map<string, bool> check; n   cin >> n; n   for (long long i = 1; i <= n; i++) { n     cin >> ws; n     getline(cin, s[i]); n   } n   for (long long i = n; i >= 1; i--) { n     if (!check[s[i]]) { n       check[s[i]] = 1; n       cout << s[i] <<   n ; n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using std::max; n using std::min; n const int inf = 0x3f3f3f3f, Inf = 0x7fffffff; n const long long INF = 0x3f3f3f3f3f3f3f3f; n __inline__ __attribute__((always_inline)) unsigned int rnd() { n   static unsigned int seed = 416; n   return seed ^= seed >> 5, seed ^= seed << 17, seed ^= seed >> 13; n } n template <typename _Tp> n _Tp gcd(const _Tp &a, const _Tp &b) { n   return (!b) ? a : gcd(b, a % b); n } n template <typename _Tp> n __inline__ __attribute__((always_inline)) _Tp abs(const _Tp &a) { n   return a >= 0 ? a : -a; n } n template <typename _Tp> n __inline__ __attribute__((always_inline)) void chmax(_Tp &a, const _Tp &b) { n   (a < b) && (a = b); n } n template <typename _Tp> n __inline__ __attribute__((always_inline)) void chmin(_Tp &a, const _Tp &b) { n   (b < a) && (a = b); n } n template <typename _Tp> n __inline__ __attribute__((always_inline)) void read(_Tp &x) { n   char ch(getchar()); n   bool f(false); n   while (!isdigit(ch)) f |= ch == 45, ch = getchar(); n   x = ch & 15, ch = getchar(); n   while (isdigit(ch)) x = (((x << 2) + x) << 1) + (ch & 15), ch = getchar(); n   f && (x = -x); n } n template <typename _Tp, typename... Args> n __inline__ __attribute__((always_inline)) void read(_Tp &t, Args &...args) { n   read(t); n   read(args...); n } n template <typename _Tp, typename... Args> n __inline__ __attribute__((always_inline)) _Tp min(const _Tp &a, const _Tp &b, n                                                   const Args &...args) { n   return a < b ? min(a, args...) : min(b, args...); n } n template <typename _Tp, typename... Args> n __inline__ __attribute__((always_inline)) _Tp max(const _Tp &a, const _Tp &b, n                                                   const Args &...args) { n   return a < b ? max(b, args...) : max(a, args...); n } n __inline__ __attribute__((always_inline)) int read_str(char *s) { n   char ch(getchar()); n   while (ch ==     || ch ==   r  || ch ==   n ) ch = getchar(); n   char *tar = s; n   *tar = ch, ch = getchar(); n   while (ch !=     && ch !=   r  && ch !=   n  && ch != EOF) n     *(++tar) = ch, ch = getchar(); n   return tar - s + 1; n } n const int N = 100005; n const int MAXN = 10000005; n bool pr[MAXN]; n int _p[MAXN >> 3], _pos; n int md[MAXN]; n void sieve() { n   for (int i = 2; i < MAXN; ++i) { n     if (!pr[i]) { n       _p[++_pos] = i; n       md[i] = i; n     } n     for (int j = 1; j <= _pos && i * _p[j] < MAXN; ++j) { n       pr[i * _p[j]] = true; n       md[i * _p[j]] = _p[j]; n       if (!(i % _p[j])) break; n     } n   } n } n std::vector<int> p[N], d[N]; n int c[MAXN], cnt[1 << 8], mul[1 << 8]; n int calc(int id) { n   int siz = ((int)p[id].size()), ans = 0; n   for (int i = 0; i < siz; ++i) mul[1 << i] = p[id][i]; n   for (int i = 1; i < 1 << siz; ++i) { n     cnt[i] = cnt[i >> 1] + (i & 1); n     mul[i] = mul[i ^ ((i) & (-(i)))] * mul[((i) & (-(i)))]; n     if (cnt[i] & 1) n       ans += c[mul[i]]; n     else n       ans -= c[mul[i]]; n   } n   return ans; n } n int a[N]; n int _val[11], _cnt[11], pos, cur_id; n void dfs(int dep, int val) { n   if (dep == pos + 1) { n     d[cur_id].push_back(val); n     return; n   } n   for (int i = 0; i <= _cnt[dep]; ++i) { n     dfs(dep + 1, val); n     if (i < _cnt[dep]) val *= _val[dep]; n   } n } n bool ban[N], vis[N]; n int deg[N]; n int f(int mid) { n   while (ban[mid]) --mid; n   if (!mid) return false; n   int qwq = 0; n   for (int i = 1; i <= mid; ++i) n     if (!ban[i]) { n       ++qwq; n       for (auto it : d[i]) ++c[it]; n     } n   int ans = 0; n   for (int i = 1; i <= mid; ++i) n     if (!ban[i] && calc(i) != qwq) ++ans; n   for (int i = 1; i <= mid; ++i) n     if (!ban[i]) n       for (auto it : d[i]) --c[it]; n   return ans; n } n std::vector<int> getnodes(int mid) { n   while (ban[mid]) --mid; n   std::vector<int> nd; n   int qwq = 0; n   for (int i = 1; i <= mid; ++i) n     if (!ban[i]) { n       ++qwq; n       for (auto it : d[i]) ++c[it]; n     } n   for (int i = 1; i <= mid; ++i) n     if (!ban[i] && calc(i) != qwq) nd.push_back(i); n   for (int i = 1; i <= mid; ++i) n     if (!ban[i]) n       for (auto it : d[i]) --c[it]; n   return nd; n } n int main() { n   mul[0] = 1; n   sieve(); n   int n, k; n   read(n, k); n   for (int i = 1; i <= n; ++i) { n     read(a[i]); n     ++c[a[i]]; n     int cur = a[i], last = 0; n     pos = 0; n     while (cur > 1) { n       if (md[cur] != last) n         p[i].push_back(md[cur]), _val[++pos] = md[cur], _cnt[pos] = 1; n       else n         ++_cnt[pos]; n       last = md[cur]; n       cur /= last; n     } n     cur_id = i; n     dfs(1, 1); n   } n   for (int j = 1; j <= _pos; ++j) n     for (int i = (MAXN - 1) / _p[j]; i >= 1; --i) c[i] += c[i * _p[j]]; n   std::vector<int> nd; n   for (int i = 1; i <= n; ++i) { n     if ((deg[i] = calc(i)) <= n - 2) { n       nd.push_back(i); n       for (int j = 1; j <= n && ((int)nd.size()) < 3; ++j) n         if (i != j && gcd(a[i], a[j]) == 1) nd.push_back(j); n       break; n     } n   } n   if (nd.empty()) { n     std::vector<int> clique, rest; n     for (int i = 1; i <= n; ++i) n       if (deg[i] == n) n         clique.push_back(i); n       else n         rest.push_back(i); n     if (((int)clique.size()) > k) clique.resize(k); n     for (int i = 1; i <= n && ((int)clique.size()) < k; ++i) { n       if (!vis[i] && deg[i] == n - 1) { n         clique.push_back(i); n         for (auto it : rest) n           if (gcd(a[it], a[i]) == 1) vis[it] = true; n       } n     } n     for (auto it : clique) printf( %d  , it); n     printf(  n ); n     return 0; n   } n   if (k == 3) { n     for (auto it : nd) printf( %d  , it); n     printf(  n ); n     return 0; n   } n   for (auto it : nd) ban[it] = true; n   for (auto id : nd) n     for (auto it : d[id]) --c[it]; n   std::vector<int> clique; n   for (int i = 1; i <= n; ++i) n     if (!ban[i] && ((deg[i] = calc(i)) == n - 3)) clique.push_back(i); n   if (((int)clique.size()) >= k) { n     clique.resize(k); n     for (auto it : clique) printf( %d  , it); n     printf(  n ); n     return 0; n   } n   memset(c, 0, sizeof(c)); n   int l = 1, r = n; n   while (l < r) { n     int mid = (l + r) >> 1; n     if (f(mid) + 3 >= k) n       r = mid; n     else n       l = mid + 1; n   } n   std::vector<int> v1 = getnodes(l - 1); n   std::vector<int> v2 = getnodes(l); n   std::sort(v1.begin(), v1.end()); n   std::vector<int> qwq; n   for (auto it : v2) { n     auto _ = std::lower_bound(v1.begin(), v1.end(), it); n     if (_ == v1.end() || *_ != it) qwq.push_back(it); n   } n   std::sort(qwq.begin(), qwq.end()); n   if (((int)v1.size()) + 3 + 1 == k && ((int)qwq.size()) != 1) n     v1.push_back(nd[0]), v1.push_back(nd[1]); n   else n     v1.push_back(nd[0]), v1.push_back(nd[1]), v1.push_back(nd[2]); n   while (((int)v1.size()) < k) { n     v1.push_back(qwq.back()); n     qwq.pop_back(); n   } n   for (auto it : v1) printf( %d  , it); n   printf(  n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n void fact(int n) { n   const int N = 1e5; n   vector<int> arr(N, 0); n   int q = 2; n   arr[0] = 1; n   int len = 1; n   int x = 0; n   int carry = 0; n   while (q <= n) { n     x = 0; n     carry = 0; n     while (x < len) { n       arr[x] = arr[x] * q + carry; n       carry = arr[x] / 10; n       arr[x] = arr[x] % 10; n       x++; n     } n     while (carry) { n       arr[len] = carry % 10; n       carry = carry / 10; n       len++; n     } n     q++; n   } n   len--; n   for (int i = len; i >= 0; i--) { n     cout << arr[i]; n   } n   return; n } n long long int binary_exp(long long int x, long long int n) { n   if (n == 0) { n     return 1; n   } else if (n == 1) { n     return x % 1000000007; n   } else { n     long long int temp = binary_exp(x, n / 2); n     temp = (temp * temp) % 1000000007; n     if (n % 2 == 0) { n       return temp; n     } else { n       return ((x % 1000000007) * temp) % 1000000007; n     } n   } n } n int main() { n   int k, r; n   cin >> k >> r; n   int i = 1; n   while (i * k % 10 != r and i * k % 10 != 0) { n     i++; n   } n   cout << i; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool vis[100006]; n int main() { n   int n, k; n   while (cin >> n >> k) { n     memset(vis, false, sizeof(vis)); n     int st = 1, ed = 1 + k; n     int cnt = 0; n     while (cnt < k && st <= ed) { n       if (st != ed) n         vis[st] = vis[ed] = true, cout << st <<     << ed <<    ; n       else n         vis[st] = true, cout << st <<    ; n       st++, ed--; n       cnt++; n     } n     for (int i = 1; i <= n; i++) { n       if (!vis[i]) cout << i <<    ; n     } n     puts(  ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 500023; n bool vis[N]; n vector<int> adj[N]; n void solve() { n   long long int n, m; n   cin >> n >> m; n   map<long long int, long long int> cntA; n   map<long long int, long long int> cntB; n   map<long long int, long long int> cntC; n   map<long long int, long long int> cntD; n   map<long long int, long long int> cntE; n   for (long long int i = 0; i < n; i++) { n     string s; n     cin >> s; n     for (int i = 0; i < s.length(); i++) { n       if (s[i] ==  A ) n         cntA[i]++; n       else if (s[i] ==  B ) n         cntB[i]++; n       else if (s[i] ==  C ) n         cntC[i]++; n       else if (s[i] ==  D ) n         cntD[i]++; n       else if (s[i] ==  E ) n         cntE[i]++; n     } n   } n   long long int ans = 0; n   for (int i = 0; i < m; i++) { n     long long int c; n     cin >> c; n     long long int maxi = 0; n     maxi = max(max(cntA[i], cntB[i]), cntC[i]); n     maxi = max(max(maxi, cntD[i]), cntE[i]); n     long long int temp = maxi * c; n     ans += temp; n   } n   cout << ans; n } n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   int T = 1; n   int t = 0; n   while (t++ < T) { n     solve(); n   } n } n


#include<bits/stdc++.h> n #define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL); n #define int long long n #define ull unsigned long long n #define FOR(i,a,b) for(int i=a;i<b;i++) n #define all(x) (x).begin(), (x).end() n #define pb push_back n #define mp make_pair n #define in insert n #define ff first n #define ss second n #define endl   n  n #define pi pair<int,int> n #define  deb1(a)         cout<<a<<  n ; n #define  deb2(a,b)       cout<<a<<   <<b<<  n ; n #define  deb3(a,b,c)     cout<<a<<   <<b<<   <<c<<  n ; n #define  debp(a)         cout<<a.ff<<   <<a.ss<<  n ; n #define  debvec(a)      for(auto it: a)cout<<it<<   ;cout<<   ; cout<<endl; n #define  debvp(a)      for(auto it: a)cout<<it.ff<<   <<it.ss<<endl; n #define  debmap(a)      for(auto it: a)cout<< { <<it.ff<< , <<it.ss<< },  ;newl; n #define  debarr(a,n)    FOR(i,0,n)cout<<a[i]<<   ;cout<<endl; n #define inf ((int)1<<60) n #define mod 1000000007 n using namespace std; n //int,char,float,double,bool,string,break,continue,endl,if,else,set,multiset,multimap,unordered_map,unordered_set,cout,cin,printf,scanf n //strlen,strcmp,compar e,auto,while,return,true,false,sizeof,size,abs,INT_MAX,INT_MIN,itr,it,sort,YES,NO n  n signed main() { n #ifndef ONLINE_JUDGE n  freopen( input.txt ,  r , stdin); n  freopen( output.txt ,  w , stdout); n #endif n  fast_io n  int test, i, j; n //  cin >> test; n  test = 1; n  while (test--) { n   int n, m; n   cin >> n >> m; n   string s, t; n   cin >> s >> t; n   int a[m], b[m]; n   j = 0; n   for (int i = 0; i < n; ++i) { n    if (s[i] == t[j]) { n     a[j] = i; n     j++; n    } n   } n   j = m - 1; n   for (int i = n - 1; i >= 0 ; i--) { n    if (s[i] == t[j]) { n     b[j] = i; n     j--; n    } n   } n   int ans = 0; n   for (int i = 0; i < m - 1; ++i) { n    ans = max(ans, b[i + 1] - a[i]); n   } n   cout << ans << endl; n  } n  n }


#include <bits/stdc++.h> n using namespace std; n const int N = 110; n const int mo = 1e9 + 7; n int n, k, a[N], num[3], nn, f = 0; n long long ans, now[N][N], dp[N][N], aa[N]; n long long po(long long a, long long b) { n   if (b == 0) return 1; n   if (b == 1) return a; n   long long c = po(a, b / 2); n   if (b & 1) n     return c * c % mo * a % mo; n   else n     return c * c % mo; n } n long long tmp[N][N]; n void multi(long long a[][N], long long b[][N], int n) { n   memset(tmp, 0, sizeof tmp); n   for (int i = 0; i < n; i++) n     for (int j = 0; j < n; j++) n       for (int k = 0; k < n; k++) n         tmp[i][j] = (tmp[i][j] + a[i][k] * b[k][j] % mo) % mo; n   for (int i = 0; i < n; i++) n     for (int j = 0; j < n; j++) a[i][j] = tmp[i][j]; n } n long long res[N][N]; n void Pow(long long a[][N], long long n) { n   memset(res, 0, sizeof res); n   for (int i = 0; i < num[0] + 1; i++) res[i][i] = 1; n   while (n) { n     if (n & 1) multi(res, a, num[0] + 1); n     multi(a, a, num[0] + 1); n     n >>= 1; n   } n } n int main() { n   scanf( %d%d , &n, &k); n   for (int i = 1; i <= n; i++) scanf( %d , &a[i]), num[a[i]]++; n   if (num[0] < num[1]) { n     for (int i = 1; i <= num[0]; i++) n       if (!a[i]) nn++; n   } else { n     swap(num[0], num[1]); n     for (int i = n; i >= n - num[0] + 1; i--) n       if (a[i]) nn++; n   } n   for (int j = 0; j <= num[0]; j++) { n     now[j][j] += j * (num[0] - j); n     now[j][j] += (num[0] - j) * (num[1] - num[0] + j); n     now[j][j] += num[0] * (num[0] - 1) / 2ll; n     now[j][j] += num[1] * (num[1] - 1) / 2ll; n     if (j + 1 <= num[0]) now[j][j + 1] = (j + 1) * (num[1] - (num[0] - j - 1)); n     if (j) now[j][j - 1] = (num[0] - j + 1) * (num[0] - j + 1); n   } n   Pow(now, k); n   for (int i = 0; i <= num[0]; i++) ans = (ans + res[i][nn]) % mo; n   printf( %lld n , res[num[0]][nn] * po(ans, mo - 2) % mo); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MX = 1000000000; n int n, m, x, i, j, a[5050], f[5050]; n int main() { n   scanf( %d%d , &n, &m); n   for (i = 3; i <= n; i++) f[i] = f[i - 1] + (i - 1) / 2; n   if (f[n] < m) { n     puts( -1 ); n     return 0; n   } n   for (i = 3; i <= n; i++) n     if (f[i] > m) break; n   m -= f[--i]; n   for (j = 1; j <= i; j++) a[j] = j; n   if (m > 0) { n     for (j = 1; j < i; j++) { n       x = (i + j - 1) / 2 - j + 1; n       if (x == m) { n         a[i + 1] = i + j; n         break; n       } n     } n     if (j >= i) { n       puts( -1~ ); n       return 0; n     } n     ++i; n   } n   x = a[i] + 1; n   for (j = 2; j <= i; j++) n     if (a[j] != a[j - 1] + 1) { n       x = a[j - 1] + 1; n       break; n     } n   for (++i; i <= n; ++i) { n     a[i] = a[i - 1] + x; n     if (a[i] > MX) break; n   } n   if (i <= n) { n     puts( -1# ); n     return 0; n   } n   for (i = 1; i <= n; i++) printf( %d  , a[i]); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const double eps = 1e-9; n const int INF = (int)1e9 + 7; n const long long linf = (long long)1e16 + 7; n struct pnt { n   double x, y; n   pnt(double x, double y) : y(y), x(x) {} n   pnt() = default; n }; n int cmp(double a, double b) { n   if (abs(a - b) < eps) return 0; n   if (a > b) return 1; n   return -1; n } n int main() { n   int n; n   cin >> n; n   int ans = 0; n   vector<int> a(n); n   for (int i = 0; i < n; ++i) cin >> a[i]; n   vector<int> cnt0(n + 1); n   vector<int> cnt1(n + 1); n   for (int i = 0; i < n; ++i) { n     if (a[i] == 0) cnt0[i]++; n     if (i) cnt0[i] += cnt0[i - 1]; n   } n   for (int i = n - 1; i >= 0; --i) { n     if (a[i] == 1) cnt1[i]++; n     if (i != n - 1) cnt1[i] += cnt1[i + 1]; n   } n   for (int i = 0; i < n; ++i) { n     ans = max(ans, cnt0[i] + cnt1[i + 1]); n     ans = max(ans, cnt1[i]); n   } n   cout << ans; n   return 0; n } n


#include<bits/stdc++.h> n  n using namespace std; n  n #define    pf               printf n #define    PF(a)            printf( %d n ,(a)) n #define    PF2(a,b)         printf( %d %d n ,(a), (b)) n #define    PF3(a,b,c)       printf( %d %d %d n ,(a), (b), (c)) n #define    PFL(a)           printf( %lld n ,(a)) n #define    PFL2(a,b)        printf( %lld %lld n ,(a), (b)) n #define    PFL3(a,b,c)      printf( %lld %lld %lld n ,(a), (b), (c)) n #define    get(a)           cin>>a n #define    sf               scanf n #define    SF(a)            scanf( %d ,&a) n #define    SF2(a,b)         scanf( %d %d ,&a, &b) n #define    SF3(a,b,c)       scanf( %d %d %d ,&a, &b, &c) n #define    SFL(a)           scanf( %lld ,&a) n #define    SFL2(a,b)        scanf( %lld %lld ,&a, &b) n #define    SFL3(a,b,c)      scanf( %lld %lld %lld ,&a, &b, &c) n #define    gl(a)            getline(cin,(a)) n #define    gc()             getchar() n #define    pb               push_back n #define    m_p              make_pair n #define    pc()             printf( Case %d:  ,tt++) n #define    tc()             cout<< Case  <<tt++<< :   n #define    dbg(x)           cout << #x <<   ->   << x << endl; n #define    SZ(a)            (int)(a).size() n #define    all(a)           a.begin(),a.end() n #define    FF               first n #define    SS               second n #define    MAX              2134567891 n #define    MOD              1000000007 n #define    MM               200005 n #define    PI               2*acos(0.0) n #define    cond(n,m)        (xx>=0 && xx<(n) && yy>=0 && yy<(m)) n  n #define    mem(a)           memset((a),0,sizeof (a)) n #define    SET(a)           memset((a),-1,sizeof (a)) n #define    output           freopen( output.txt , w ,stdout); n #define    input            freopen( input.txt , r ,stdin); n #define    I_O              ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0) n #define    rep(a)           for(int i=0;i<(a);i++) n #define    FOR(a,b)         for(int i=(a);i<(b);i++) n #define    REP(a)           for(int j=0;j<(a);j++) n #define    rev(a)           for(int i=(a);i>=0;i--) n #define    fr(i,n)          for(i=0;i<n;i++) n #define    fr1(i,n,m)       for(i=n;i<m;i++) n mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); n int dx[]  = {0, 0, 1, -1}; n int dy[]  = {1, -1, 0, 0}; n int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1}; n int dy8[] = {1, -1, -1, 0, 1, -1, 0, 1}; n int kx8[] = {1, 1, 2, 2, -1, -1, -2, -2}; n int ky8[] = {2, -2, 1, -1, 2, -2, 1, -1}; n  n typedef long long ll; n typedef unsigned long long llu; n typedef priority_queue < int > PQ; n typedef pair < ll , ll > pi; n typedef pair <  ll, pi > pii; n typedef vector < int > vi; n typedef vector < ll > vl; n typedef vector < string > vs; n  n /* n //FUNCTION// n ll bigmod(ll a, ll b, ll c) n { n     if(b==0)return 1%c;ll x=bigmod(a,b/2,c);x=(x*x)%c; n     if(b%2==1)x=(x*a)%c;return x; n } n ll mod_inverse(ll a, ll mod){return bigmod(a,mod-2,mod);} n ll poww(ll a, ll b) n { n     if(b==0)return 1;ll x=poww(a,b/2);x=x*x;if(b%2==1)x=(x*a);return x; n } n  n  n  n ll LCM(ll a, ll b){ return a*b/ __gcd(a,b);} n  n int pr = 100005; n vi primelist; n bool a[MM]; n void seive( ) n { n     int i,j,k=sqrt(pr); n     a[1]=1; n     primelist.pb(2); n     for(i=4;i<=pr;i+=2)a[i]=1; n     for(i=3;i<=k;i+=2)if(!a[i])for(j=i*i;j<=pr;j+=2*i)a[j]=1; n     for(i=3;i<=pr;i+=2)if(!a[i])primelist.pb(i); n } n int phi[MM]; n void calculatePhi() { n   for (int i = 1; i < MM; i++) { n     phi[i] = i; n   } n   for (int p = 2; p < M; p++) { n     if (phi[p] == p) { // p is a prime n       for (int k = p; k < M; k += p) { n         phi[k] -= phi[k] / p; n       } n     } n   } n } n  n ll fact_divs( ll n, ll p) n { n     ll cnt=0;while(p<=n){cnt += n/p;n /= p;}return cnt; n } n struct point{double x, y;}; n double area( point A, point B, point C){ n return 0.5*(A.x*(B.y-C.y) - A.y*(B.x-C.x) + B.x*C.y - C.x*B.y); n } n  n int Set(int N,int pos){return N=N | (1<<pos);} n int reset(int N,int pos){return N= N & ~(1<<pos);} n bool check(int N,int pos){return (bool)(N & (1<<pos));} n  n //*/ n int a[MM]; n int main(){ n     I_O; n     int t, tt = 1; n     cin>>t; n     while(t--){ n         int n; cin>>n; n         int id = 0, mn = MAX; n         for(int i=1; i<=n; i++){ n             cin>>a[i]; n             if(a[i] < mn){ n                 mn = a[i]; n                 id = i; n             } n         } n         cout<<n-1<<endl; n         for(int i=id+1, cnt=1; i<=n; i++, cnt++){ n             cout<<id<<   <<i<<   <<a[id]<<   <<a[id]+cnt<<endl; n         } n         for(int i=id-1, cnt=1; i >=1; i--, cnt++){ n             cout<<id<<   <<i<<   <<a[id]<<   <<a[id]+cnt<<endl; n         } n  n  n     } n  n  n  n  n     return 0; n } n /* n 2 n 5 n 9 6 3 11 15 n 3 n 7 5 13 n  n  n  n  n */ n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, i; n   cin >> n; n   string s; n   map<char, int> m; n   for (i = 0; i < n; i++) { n     cin >> s; n     m[s[0]]++; n   } n   int ans = 0, f1, f2; n   for (auto it = m.begin(); it != m.end(); it++) { n     f1 = it->second / 2; n     f2 = it->second - f1; n     ans += f1 * (f1 - 1) / 2 + f2 * (f2 - 1) / 2; n   } n   cout << ans <<   n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int Read() { n   int x = 0; n   char ch = getchar(); n   while (!isdigit(ch)) ch = getchar(); n   while (isdigit(ch)) x = (x << 3) + (x << 1) + ch -  0 , ch = getchar(); n   return x; n } n void Write(int x) { n   if (x < 0) putchar( - ), x = -x; n   if (x == 0) putchar( 0 ); n   int stk[55], tp = 0; n   while (x) stk[++tp] = x % 10, x /= 10; n   for (int i = tp; i; i--) putchar(stk[i] +  0 ); n } n int Add(int a, int b) { n   return (a + b >= 998244353) ? a + b - 998244353 : a + b; n } n int Dec(int a, int b) { return (a - b < 0) ? a - b + 998244353 : a - b; } n int mul(int a, int b) { return 1ll * a * b % 998244353; } n unsigned int qpow(unsigned int a, int b) { n   unsigned int res = 1; n   for (; b; b >>= 1, a = mul(a, a)) n     if (b & 1) res = mul(res, a); n   return res; n } n namespace NTT { n int sz; n unsigned int w[2500005], w_mf[2500005]; n int mf(int x) { return (1ll * x << 32) / 998244353; } n void init(int n) { n   for (sz = 2; sz < n; sz <<= 1) n     ; n   unsigned int pr = qpow(3, (998244353 - 1) / sz); n   w[sz / 2] = 1; n   w_mf[sz / 2] = mf(1); n   for (int i = 1; i <= sz / 2; i++) n     w[sz / 2 + i] = mul(w[sz / 2 + i - 1], pr), n                w_mf[sz / 2 + i] = mf(w[sz / 2 + i]); n   for (int i = sz / 2 - 1; i; i--) w[i] = w[i << 1], w_mf[i] = w_mf[i << 1]; n } n void ntt(vector<unsigned int>& A, int L) { n   for (int d = L >> 1; d; d >>= 1) n     for (int i = 0; i < L; i += (d << 1)) n       for (int j = 0; j < d; j++) { n         unsigned int x = A[i + j] + A[i + d + j]; n         if (x >= 998244353 * 2) x -= 998244353 * 2; n         long long t = A[i + j] + 998244353 * 2 - A[i + d + j], n                   q = t * w_mf[d + j] >> 32, y = t * w[d + j] - q * 998244353; n         A[i + j] = x; n         A[i + d + j] = y; n       } n   for (int i = 0; i < L; i++) n     if (A[i] >= 998244353) A[i] -= 998244353; n } n void intt(vector<unsigned int>& A, int L) { n   for (int d = 1; d < L; d <<= 1) n     for (int i = 0; i < L; i += (d << 1)) n       for (int j = 0; j < d; j++) { n         unsigned int x = A[i + j]; n         if (x >= 998244353 * 2) x -= 998244353 * 2; n         long long t = A[i + d + j], q = t * w_mf[d + j] >> 32, n                   y = t * w[d + j] - q * 998244353; n         A[i + j] = x + y, A[i + d + j] = x + 2 * 998244353 - y; n       } n   int k = __builtin_ctz(L); n   reverse(A.begin() + 1, A.end()); n   for (int i = 0; i < L; i++) { n     long long m = -A[i] & (L - 1); n     A[i] = (A[i] + m * 998244353) >> k; n     if (A[i] >= 998244353) A[i] -= 998244353; n   } n } n }  // namespace NTT n struct poly { n   vector<unsigned int> a; n   poly(int d = 0, int t = 0) { n     a.resize(d + 1); n     a[d] = t; n   } n   int deg() { return a.size() - 1; } n   unsigned int& operator[](const int& b) { return a[b]; } n   poly extend(int x) { n     poly c = *this; n     c.a.resize(x + 1); n     return c; n   } n   void resize(int x) { a.resize(x); } n   int size() { return a.size(); } n   void Get(int n) { n     a.resize(n + 1); n     for (int i = 0; i <= n; i++) a[i] = Read(); n   } n   void Print(int n) { n     for (int i = 0; i <= n; i++) Write(a[i]), putchar(   ); n     puts(  ); n   } n   friend poly operator*(poly A, poly B) { n     int n = A.deg() + B.deg() + 1, lim = 2; n     for (; lim < n; lim <<= 1) n       ; n     NTT::init(lim); n     A.resize(lim); n     B.resize(lim); n     NTT::ntt(A.a, lim); n     NTT::ntt(B.a, lim); n     for (int i = 0; i < lim; i++) A[i] = mul(A[i], B[i]); n     NTT::intt(A.a, lim); n     return A.extend(n - 1); n   } n   poly inv(poly A) { n     int n = A.a.size(), lim = 2; n     if (n == 1) return A[0] = qpow(A[0], 998244353 - 2), A; n     poly B = A; n     B.resize((n + 1) >> 1); n     B = inv(B); n     for (; lim < (n << 1); lim <<= 1) n       ; n     NTT::init(lim); n     A.resize(lim), B.resize(lim), NTT::ntt(A.a, lim); n     NTT::ntt(B.a, lim); n     for (int i = 0; i < lim; i++) A[i] = mul(Dec(2, mul(A[i], B[i])), B[i]); n     NTT::intt(A.a, lim); n     return A.extend(n - 1); n   } n   poly getinv() { return inv(*this); } n   poly getdao() { n     poly A = *this, B; n     int n = A.a.size(); n     B.resize(n); n     for (int i = 1; i < n; i++) B[i - 1] = mul(A[i], i); n     B[n - 1] = 0; n     return B; n   } n   poly getjf() { n     poly A = *this, B; n     int n = A.a.size(); n     B.resize(n); n     for (int i = 1; i < n; i++) B[i] = mul(A[i - 1], qpow(i, 998244353 - 2)); n     B[0] = 0; n     return B; n   } n   poly getln() { n     poly A = *this; n     return (A.getdao() * A.getinv()).extend(A.deg()).getjf(); n   } n   poly exp(poly A) { n     int n = A.a.size(); n     if (n == 1) return A[0] = 1, A; n     poly B = A; n     B.resize((n + 1) >> 1); n     B = exp(B); n     poly C = B.getln(); n     C.resize(n); n     for (int i = 0; i < n; i++) C[i] = Dec(A[i], C[i]); n     ++C[0]; n     return (B * C).extend(n - 1); n   } n   poly getexp() { return exp(*this); } n   poly getmi(int k) { n     poly A = *this; n     int n = A.a.size(); n     poly B = A.getln(); n     for (int i = 0; i < n; i++) B[i] = mul(B[i], k); n     return B.getexp(); n   } n   poly sqrt(poly A) { n     int n = A.size(), lim = 2; n     if (n == 1) return A[0] = 1, A; n     poly B = A; n     B.resize((n + 1) >> 1); n     B = sqrt(B); n     poly C = A.extend(n - 1), D = B.getinv(); n     for (; lim < (n << 1); lim <<= 1) n       ; n     NTT::init(lim); n     B.resize(lim), C.resize(lim), D.resize(lim), NTT::ntt(B.a, lim); n     NTT::ntt(C.a, lim); n     NTT::ntt(D.a, lim); n     for (int i = 0; i < lim; i++) n       B[i] = mul(Add(B[i], mul(C[i], D[i])), 499122177); n     NTT::intt(B.a, lim); n     return B.extend(n - 1); n   } n   poly getsqrt() { return sqrt(*this); } n }; n signed main() { n   int n = Read(), k = Read(); n   poly A, B; n   A.resize(k * 3), B.resize(k * 3); n   A[0] = 1; n   A[1] = 6; n   A[2] = 1; n   A = A.getsqrt(); n   B = A.getinv(); n   ++A[1]; n   ++A[0]; n   for (int i = 0; i <= k; i++) A[i] = 1ll * A[i] * 499122177 % 998244353; n   A = A.getmi(n + 1); n   A = (A * B).extend(k * 3); n   for (int i = 1; i <= k; i++) { n     if (i <= n) n       printf( %d  , A[i]); n     else n       printf( %d  , 0); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long n, d, a, b; n   cin >> n >> d >> a >> b; n   vector<pair<long long, int> > v(n); n   for (int i = 0; i < n; i++) { n     long long x, y; n     cin >> x >> y; n     v[i].first = x * a + y * b; n     v[i].second = i + 1; n   } n   sort(v.begin(), v.end()); n   int ans = 0, sum = 0, pos = 0; n   for (int i = 0; i < n; i++) { n     if (sum + v[i].first <= d) { n       sum += v[i].first; n       ans++; n       pos = i; n     } n   } n   cout << ans << endl; n   if (ans) n     for (int i = 0; i <= pos; i++) cout << v[i].second <<    ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int t; n   long long x, y, p, q; n   cin >> t; n   while (t--) { n     cin >> x >> y >> p >> q; n     long long l = 0, h = 1e9, ans = -1, mid, a, b; n     while (l <= h) { n       mid = (l + h) / 2; n       a = p * mid; n       b = q * mid; n       if (b >= y && a >= x && b - a >= y - x) { n         ans = b - y; n         h = mid - 1; n       } else n         l = mid + 1; n     } n     cout << ans << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long int mod = 1e9 + 7; n const long long int N = 2 * (1e5); n const long long int maxo = 1e14; n const long long int inf = 1e17; n int main(int argc, char const *argv[]) { n   ios_base::sync_with_stdio(false); n   cin.tie(NULL); n   long long int x0, y0, ax, ay, bx, by; n   cin >> x0 >> y0 >> ax >> ay >> bx >> by; n   long long int xs, ys, t; n   cin >> xs >> ys >> t; n   vector<pair<long long int, long long int> > v; n   v.push_back({x0, y0}); n   for (long long int i = 0; i < 100; i++) { n     if (v.back().first > (inf - bx) / (ax)) break; n     if (v.back().second > (inf - by) / ay) break; n     long long int x1 = v.back().first * ax + bx; n     long long int y1 = v.back().second * ay + by; n     v.push_back({x1, y1}); n   } n   long long int n = v.size(); n   long long int ans = 0; n   for (long long int l = 0; l < n; l++) { n     for (long long int r = l; r < n; r++) { n       long long int d1 = abs(xs - v[l].first) + abs(ys - v[l].second); n       long long int d2 = abs(xs - v[r].first) + abs(v[r].second - ys); n       long long int len = n           abs(v[l].first - v[r].first) + abs(v[l].second - v[r].second); n       if (d1 + len <= t) { n         ans = max(ans, r - l + 1); n       } n       if (d2 + len <= t) { n         ans = max(ans, r - l + 1); n       } n     } n   } n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n void setIO(string name =   ) { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   if (int((name).size())) { n     freopen((name +  .in ).c_str(),  r , stdin); n     freopen((name +  .out ).c_str(),  w , stdout); n   } n } n long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } n long long mcm(long long a, long long b) { return (a * b) / gcd(a, b); } n bool prime(long long n, long long i) { n   if (i > sqrt(n)) return true; n   if (n % i == 0) n     return false; n   else n     return prime(n, i + 1); n } n struct compii { n   bool operator()(const pair<int, int> &a, const pair<int, int> &b) { n     if (a.first == a.second) return a.second < b.second; n     return a.first > b.first; n   } n }; n bool comp(int a, int b) { return a > b; } n int dx[] = {1, 0, -1, 0}; n int dy[] = {0, 1, 0, -1}; n const int mod = 1e9 + 7; n const long long inf = 1e18; n bool check(string a, string b) { n   if (a ==  rock  and b ==  scissors ) return true; n   if (a ==  paper  and b ==  rock ) return true; n   if (a ==  scissors  and b ==  paper ) return true; n   return false; n } n void solve() { n   string first, m, second; n   cin >> first >> m >> second; n   if (check(first, m) and check(first, second)) n     cout <<  F ; n   else if (check(m, second) and check(m, first)) n     cout <<  M ; n   else if (check(second, first) and check(second, m)) n     cout <<  S ; n   else n     cout <<  ? ; n } n int main() { n   setIO(  ); n   int t = 1; n   while (t-- > 0) solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s =   ; n   for (int i = 1; i < 1000; i++) { n     s += to_string(i); n   } n   int n; n   cin >> n; n   cout << s[n - 1]; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int adj[8][2] = {{-1, 0},  {0, -1}, {1, 0}, {0, 1}, n                        {-1, -1}, {-1, 1}, {1, 1}, {1, -1}}; n const long long int LLINF = 9e18; n const int INF = 2e9; n const int MOD = 1e9 + 7; n const double EPS = 1e-10; n const double PI = acos(-1); n const int SIZE = 100011; n int N; n int cnt[SIZE]; n map<string, int> Mp; n string ts[8] = { S ,  M ,  L ,  XL ,  XXL ,  XXXL }; n string s; n struct edge { n   int v, f, c, u; n }; n vector<edge> E[SIZE]; n int st[SIZE], lvl[SIZE]; n void init() { n   for (int i = 0; i < SIZE; i++) { n     cnt[i] = 0; n     E[i].clear(); n   } n } n void addedge(int a, int b, int ca, int cb) { n   edge A = {a, 0, ca, (int)E[a].size()}; n   edge B = {b, 0, cb, (int)E[b].size()}; n   E[a].push_back(B); n   E[b].push_back(A); n } n bool BFS(int S, int T) { n   memset(lvl, -1, sizeof(lvl)); n   queue<int> q; n   q.push(S); n   lvl[S] = 0; n   while (!q.empty()) { n     int indx = q.front(); n     q.pop(); n     for (unsigned int i = 0; i < E[indx].size(); i++) { n       edge &t = E[indx][i]; n       int idx = t.v; n       if (lvl[idx] < 0 && t.c > t.f) { n         lvl[idx] = lvl[indx] + 1; n         q.push(idx); n       } n     } n   } n   return lvl[T] >= 0; n } n int DFS(int indx, int T, int flow) { n   if (indx == T) return flow; n   for (int &i = st[indx]; i < (int)E[indx].size(); i++) { n     edge &t = E[indx][i]; n     int idx = t.v; n     if (lvl[idx] == lvl[indx] + 1 && t.c > t.f) { n       int cur = min(flow, t.c - t.f); n       int ret = DFS(idx, T, cur); n       if (ret > 0) { n         t.f += ret; n         E[t.v][t.u].f -= ret; n         return ret; n       } n     } n   } n   return 0; n } n int Dinic(int S, int T) { n   int ret = 0; n   while (BFS(S, T)) { n     memset(st, 0, sizeof(st)); n     while (int flow = DFS(S, T, INF)) { n       ret += flow; n     } n   } n   return ret; n } n int main() { n   ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); n   int S = 0, T = SIZE - 1, a; n   init(); n   for (int i = 1; i <= 6; i++) { n     cin >> a; n     Mp[ts[i - 1]] = i; n     addedge(i, T, 0, a); n   } n   cin >> N; n   for (int i = 1; i <= N; i++) { n     cin >> s; n     s +=  , ; n     string temp =   ; n     for (unsigned int j = 0; j < s.size(); j++) { n       if (s[j] ==  , ) { n         addedge(i + 6, Mp[temp], 0, 1); n         temp.clear(); n         cnt[i + 6]++; n       } else n         temp.push_back(s[j]); n     } n     addedge(S, i + 6, 0, 1); n   } n   int ans = Dinic(S, T); n   if (ans != N) n     cout <<  NO  << endl; n   else { n     cout <<  YES  << endl; n     for (int i = 1; i <= N; i++) { n       edge t1, t2; n       if (cnt[i + 6] == 1) { n         t1 = E[i + 6][0]; n         cout << ts[t1.v - 1] << endl; n       } else { n         t1 = E[i + 6][0]; n         t2 = E[i + 6][1]; n         if (t1.f == 1) n           cout << ts[t1.v - 1] << endl; n         else if (t2.f == 1) n           cout << ts[t2.v - 1] << endl; n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int a[101]; n int b[101]; n int storage[200001]; n int storage2[200001]; n int* value = storage + 100000; n int* prevalue = storage2 + 100000; n int n, k; n int main() { n   scanf( %d%d , &n, &k); n   int gtzero = 0, lezero = 0; n   for (int i = 0; i < n; i++) scanf( %d , &a[i]); n   for (int i = 0; i < n; i++) scanf( %d , &b[i]), b[i] *= k; n   for (int i = 0; i < n; i++) { n     b[i] = a[i] - b[i]; n     if (b[i] > 0) n       gtzero += b[i]; n     else n       lezero += b[i]; n   } n   for (int i = 0; i < sizeof(storage) / sizeof(int); i++) { n     storage[i] = -19200000; n     storage2[i] = -19200000; n   } n   value[0] = prevalue[0] = 0; n   for (int i = 0; i < n; i++) { n     int C = b[i]; n     for (int j = -10000; j <= 10000; j++) { n       value[j] = max(prevalue[j], prevalue[j - b[i]] + a[i]); n     } n     memcpy(storage2, storage, sizeof(storage)); n   } n   if (value[0] > 0) n     printf( %d n , value[0]); n   else n     printf( -1 n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int num, a1, a2, b1, b2, c1, c2, d, a, b, c; n   cin >> num >> a1 >> a2 >> b1 >> b2 >> c1 >> c2; n   a = a2; n   b = b2; n   c = c2; n   if (a + b + c == num) n     cout << a <<     << b <<     << c; n   else { n     d = a + b + c - num; n     if (c - d >= c1) { n       c = c - d; n       d = 0; n     } else { n       d = d - c + c1; n       c = c1; n     } n     if (d > 0) n       if (b - d >= b1) { n         b = b - d; n         d = 0; n       } else { n         d = d - b + b1; n         b = b1; n       } n     if (d > 0) n       if (a - d >= a1) { n         a = a - d; n         d = 0; n       } else { n         d = d - a + a1; n         a = a1; n       } n     cout << a <<     << b <<     << c; n   } n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 500005; n const int maxx = 1000005; n int n, x, y, q, l, r; n int a[N]; n struct Tree { n   int ans, m, tag; n } tr[maxx * 6]; n void pushdown(int rt) { n   int lson = rt << 1; n   int rson = rt << 1 | 1; n   tr[lson].m += tr[rt].tag; n   tr[rson].m += tr[rt].tag; n   tr[lson].tag += tr[rt].tag; n   tr[rson].tag += tr[rt].tag; n   tr[rt].tag = 0; n } n void updata(int rt) { n   int lson = rt << 1; n   int rson = rt << 1 | 1; n   if (tr[lson].m == tr[rson].m) { n     tr[rt].m = tr[lson].m; n     tr[rt].ans = tr[lson].ans + tr[rson].ans; n   } else if (tr[lson].m < tr[rson].m) { n     tr[rt].m = tr[lson].m; n     tr[rt].ans = tr[lson].ans; n   } else { n     tr[rt].m = tr[rson].m; n     tr[rt].ans = tr[rson].ans; n   } n } n void change(int rt, int l, int r, int cl, int cr, int C) { n   if (cl <= l && r <= cr) { n     tr[rt].m += C; n     tr[rt].tag += C; n     return; n   } n   pushdown(rt); n   int mid = (l + r) >> 1; n   if (cl <= mid) change(rt << 1, l, mid, cl, cr, C); n   if (cr > mid) change(rt << 1 | 1, mid + 1, r, cl, cr, C); n   updata(rt); n } n void change2(int rt, int l, int r, int x, int C) { n   if (l == r) { n     tr[rt].ans += C; n     return; n   } n   pushdown(rt); n   int mid = (l + r) >> 1; n   if (x <= mid) change2(rt << 1, l, mid, x, C); n   if (x > mid) change2(rt << 1 | 1, mid + 1, r, x, C); n   updata(rt); n } n int query(int rt, int l, int r, int ql, int qr) { n   if (ql <= l && r <= qr) { n     if (tr[rt].m == 1) return tr[rt].ans; n     return 0; n   } n   pushdown(rt); n   int mid = (l + r) >> 1, summ = 0; n   if (ql <= mid) summ += query(rt << 1, l, mid, ql, qr); n   if (qr > mid) summ += query(rt << 1 | 1, mid + 1, r, ql, qr); n   updata(rt); n   return summ; n } n int main() { n   scanf( %d %d , &n, &q); n   for (int i = 1; i <= n; ++i) scanf( %d , &a[i]); n   a[0] = maxx; n   a[n + 1] = 0; n   for (int i = 1; i <= n; ++i) change2(1, 0, maxx, a[i], 1); n   for (int i = 1; i <= n + 1; ++i) { n     int l = a[i - 1]; n     int r = a[i]; n     if (l == r) continue; n     if (l > r) swap(l, r); n     change(1, 0, maxx, l, r - 1, 1); n   } n   for (int i = 1; i <= q; ++i) { n     scanf( %d %d , &x, &y); n     l = a[x]; n     r = a[x + 1]; n     if (l != r) { n       if (l > r) swap(l, r); n       change(1, 0, maxx, l, r - 1, -1); n     } n     l = a[x - 1]; n     r = a[x]; n     if (l != r) { n       if (l > r) swap(l, r); n       change(1, 0, maxx, l, r - 1, -1); n     } n     change2(1, 0, maxx, a[x], -1); n     change2(1, 0, maxx, y, 1); n     a[x] = y; n     l = a[x]; n     r = a[x + 1]; n     if (l != r) { n       if (l > r) swap(l, r); n       change(1, 0, maxx, l, r - 1, 1); n     } n     l = a[x - 1]; n     r = a[x]; n     if (l != r) { n       if (l > r) swap(l, r); n       change(1, 0, maxx, l, r - 1, 1); n     } n     printf( %d n , query(1, 0, maxx, 1, maxx - 1)); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using ll = long long; n const int inf = 1e9 + 7; n const ll longinf = 1LL << 60; n const ll mod = 1e9 + 7; n int main() { n   int h, w, n, q; n   cin >> h >> w >> n >> q; n   vector<int> v[h]; n   for (int i = (int)(0); i < (int)(n); ++i) { n     int x, y; n     cin >> x >> y; n     --x; n     --y; n     v[x].push_back(y); n   } n   for (int i = (int)(0); i < (int)(h); ++i) sort(v[i].begin(), v[i].end()); n   vector<ll> ok; n   ok.push_back(-longinf); n   ok.push_back(longinf); n   for (int i = (int)(0); i < (int)(q); ++i) { n     int x; n     cin >> x; n     --x; n     ok.push_back(x); n   } n   sort(ok.begin(), ok.end()); n   ll pl = 0, pr = 0; n   ll dp[2][202020]; n   for (int i = (int)(0); i < (int)(2); ++i) n     for (int j = (int)(0); j < (int)(202020); ++j) dp[i][j] = longinf; n   dp[0][1] = dp[1][1] = 0; n   if (v[0].size()) { n     pl = v[0][0]; n     pr = v[0].back(); n     dp[0][1] = 2 * pr - pl; n     dp[1][1] = pr; n   } n   int maxh = 1; n   for (int i = (int)(1); i < (int)(h); ++i) { n     if (v[i].empty()) { n       dp[0][i + 1] = dp[0][i] + 1; n       dp[1][i + 1] = dp[1][i] + 1; n       continue; n     } n     int nl = v[i][0], nr = v[i].back(); n     auto itr = lower_bound(ok.begin(), ok.end(), pl); n     dp[0][i + 1] = min(dp[0][i + 1], dp[0][i] + abs(*itr - pl) + n                                          abs(nr - *itr) + abs(nr - nl) + 1); n     dp[1][i + 1] = min(dp[1][i + 1], dp[0][i] + abs(*itr - pl) + n                                          abs(nl - *itr) + abs(nr - nl) + 1); n     --itr; n     dp[0][i + 1] = min(dp[0][i + 1], dp[0][i] + abs(*itr - pl) + n                                          abs(nr - *itr) + abs(nr - nl) + 1); n     dp[1][i + 1] = min(dp[1][i + 1], dp[0][i] + abs(*itr - pl) + n                                          abs(nl - *itr) + abs(nr - nl) + 1); n     itr = lower_bound(ok.begin(), ok.end(), pr); n     dp[0][i + 1] = min(dp[0][i + 1], dp[1][i] + abs(*itr - pr) + n                                          abs(nr - *itr) + abs(nr - nl) + 1); n     dp[1][i + 1] = min(dp[1][i + 1], dp[1][i] + abs(*itr - pr) + n                                          abs(nl - *itr) + abs(nr - nl) + 1); n     --itr; n     dp[0][i + 1] = min(dp[0][i + 1], dp[1][i] + abs(*itr - pr) + n                                          abs(nr - *itr) + abs(nr - nl) + 1); n     dp[1][i + 1] = min(dp[1][i + 1], dp[1][i] + abs(*itr - pr) + n                                          abs(nl - *itr) + abs(nr - nl) + 1); n     pl = nl; n     pr = nr; n     maxh = max(i + 1, maxh); n   } n   cout << min(dp[0][maxh], dp[1][maxh]) << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   int cnt = 0; n   cin >> n; n   string a; n   for (int i = 0; i < n; i++) { n     cin >> a; n     if (a ==  Tetrahedron ) n       cnt += 4; n     else if (a ==  Cube ) n       cnt += 6; n     else if (a ==  Octahedron ) n       cnt += 8; n     else if (a ==  Dodecahedron ) n       cnt += 12; n     else n       cnt += 20; n   } n   cout << cnt; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n #pragma comment(linker,  /STACK:20000000 ) n string problem_name =  a ; n void init() { freopen((problem_name +  .in ).c_str(),  rt , stdin); } n long long res = 0; n int ms[300100]; n int len; n void mul(int val) { n   int p = 0; n   for (int i = 0; i < 300000; i++) { n     p += ms[i] *= val; n     ms[i] = p % 10; n     p /= 10; n   } n } n int main() { n   string s; n   cin >> s; n   vector<int> u(255, 0); n   res = 1; n   int zero = 0; n   long long col = 10; n   int c = 0; n   int c2 = 0; n   for (int i = 0; i < int((s).size()); i++) { n     if (s[i] ==  ? ) { n       c++; n     } else if (isalpha(s[i])) { n       if (u[s[i]]) continue; n       u[s[i]] = 1; n       if (col <= 0) { n         res = 0; n         zero = 1; n         break; n       } n       c2++; n       col--; n     } n   } n   if (zero) { n     cout << 0; n     return 0; n   } n   if (c) { n     if (s[0] ==  ? ) n       ms[c - 1] = 9; n     else n       ms[c] = 1; n   } else n     ms[0] = 1; n   if (c2) { n     for (int i = 10; i > 10 - c2; i--) { n       if (i == 10 && isalpha(s[0])) n         mul(9); n       else n         mul(i); n     } n   } n   int len = 300000; n   while (!ms[len]) len--; n   for (int i = len; i >= 0; i--) printf( %d , ms[i]); n   return 0; n } n


#include <bits/stdc++.h> n const long long mod = 1e9 + 7; n using namespace std; n const long long N = 102; n const long long M = 1e4 + 2; n long long dp[N][M], c[N][N], cnt[N]; n signed main() { n   long long n, i, j, k, l, ans = 0, type = 0; n   cin >> n; n   dp[0][0] = 1; n   c[0][0] = 1; n   for (i = 1; i <= n; i++) { n     cin >> j; n     if (!cnt[j]) { n       type++; n     } n     cnt[j]++; n     for (l = i; l >= 1; l--) { n       for (k = 10000; k >= j; k--) { n         dp[l][k] += dp[l - 1][k - j]; n         if (dp[l][k] > mod) { n           dp[l][k] -= mod; n         } n       } n     } n   } n   if (type <= 2) { n     cout << n; n     return 0; n   } n   for (i = 1; i <= 100; i++) { n     for (j = 0; j <= i; j++) { n       c[j][i] = c[j][i - 1]; n       if (j) { n         c[j][i] += c[j - 1][i - 1]; n       } n       c[j][i] %= mod; n     } n   } n   for (i = 1; i <= 100; i++) { n     for (j = 1; j <= cnt[i]; j++) { n       if (c[j][cnt[i]] == dp[j][i * j]) { n         ans = max(ans, j); n       } n     } n   } n   cout << ans; n } n


#include <bits/stdc++.h> n using namespace std; n const int dx[] = {0, 1, -1, 0, 1, -1, -1, 1}; n const int dy[] = {-1, 0, 0, 1, 1, 1, -1, -1}; n const int N = 0; n const int MOD = 0; n const int INF = 1e9 + 10; n const long long int LLINF = 1e18 + 10; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   int n, m; n   cin >> n >> m; n   int v[10010]; n   int l, r, x; n   for (int i = 1; i <= n; i++) { n     cin >> v[i]; n   } n   int aux; n   bool mudou; n   int cnt = 0; n   while (m--) { n     cin >> l >> r >> x; n     aux = x - l; n     cnt = 0; n     for (int i = l; i <= r; i++) { n       if (v[i] < v[x]) cnt++; n     } n     if (cnt == aux) n       cout <<  Yes n ; n     else n       cout <<  No n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   int suma = 0, sumg = 0, a, g; n   char *arr = new char[n]; n   for (int i = 0; i < n; i++) { n     scanf( %d %d , &a, &g); n     if (abs(suma + a - sumg) < abs(sumg + g - suma)) { n       suma += a; n       arr[i] =  A ; n     } else { n       sumg += g; n       arr[i] =  G ; n     } n   } n   if (abs(suma - sumg) > 500) n     cout <<  -1 ; n   else n     for (int i = 0; i < n; i++) cout << arr[i]; n   cout << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n bool isPowerOfTwo(int x) { return (x && !(x & (x - 1))); } n bool is_prime(int n) { n   if (n == 1) return false; n   for (int i = 2; i <= sqrt(n); i++) { n     if (n % i == 0) { n       return false; n     } n   } n   return true; n } n void solve() { n   int n; n   cin >> n; n   long long int a, b; n   cin >> a >> b; n   set<long long int> st; n   st.insert(a); n   st.insert(b); n   for (int i = 2; i * i <= a; i++) { n     if (a % i == 0) { n       st.insert(i); n       st.insert(a / i); n     } n   } n   for (int i = 2; i * i <= b; i++) { n     if (b % i == 0) { n       st.insert(i); n       st.insert(b / i); n     } n   } n   map<pair<long long int, long long int>, long long int> ch; n   ch[{a, b}]++; n   for (int i = 1; i < n; i++) { n     cin >> a >> b; n     if (ch[{a, b}] >= 1) continue; n     ch[{a, b}]++; n     for (auto it = st.begin(); it != st.end();) { n       long long int k = *it; n       if (a % k == 0 || b % k == 0) { n         it++; n       } else { n         it = st.erase(it++); n       } n     } n   } n   if (st.empty()) n     cout <<  -1 ; n   else n     cout << (*st.begin()); n } n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   int t = 1; n   while (t--) { n     solve(); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n using int64 = long long; n int64 bit_count(int64 n) { n   int64 a{}; n   while (n) { n     a += 1; n     n >>= 1; n   } n   return a; n } n int main() { n   ios::sync_with_stdio(false); n   cin.tie(nullptr); n   int T; n   cin >> T; n   while (T--) { n     int64 n, m; n     cin >> n >> m; n     vector<int64> P(m); n     for (auto &p : P) cin >> p; n     auto s = accumulate(begin(P), end(P), 0ll); n     if (s < n) { n       cout << -1 <<   n ; n       continue; n     } n     vector<int64> F(65); n     for (auto p : P) F[bit_count(p) - 1]++; n     int64 ans{}; n     for (int i = 0, j = -1; i < 64; i++) { n       if (j >= 0 and F[i]) { n         ans += i - j; n         j = -1; n         F[i]--; n       } n       if (n & (1 << i)) { n         if (F[i]) { n           F[i]--; n         } else { n           if (j == -1) j = i; n         } n       } n       F[i + 1] += F[i] / 2; n     } n     cout << ans <<   n ; n   } n } n


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


#include <bits/stdc++.h> n #pragma GCC optimize( Ofast,no-stack-protector ) n #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx ) n #pragma GCC target( avx,tune=native ) n using namespace std; n const int inf = 0x3f3f3f3f; n const double eps = 1e-6; n const int mod = 1000000007; n inline string getstr(string &s, int l, int r) { n   string ret =   ; n   for (int i = l; i <= r; i++) ret.push_back(s[i]); n   return ret; n } n int modpow(int x, int y, int md = mod) { n   if (y == 0) return 1; n   int ret = modpow(x, y >> 1, md); n   ret = (long long)ret * ret % md; n   if (y & 1) ret = (long long)ret * x % md; n   return ret; n } n int n, m, t, ans; n int a[10001]; n int cnt[10005]; n int in[11]; n inline int calc(int use) { n   int ret = 1; n   for (int i = 1; i <= use; i++) { n     ret = (long long)ret * cnt[in[i]] % mod; n   } n   return ret; n } n void dfs(int use, int last, bitset<128> now) { n   ans += calc(use); n   if (ans >= mod) ans -= mod; n   for (int i = last + 1; i <= m / 2; i++) { n     if (cnt[i]) { n       if (now[i] || now[m - i]) continue; n       bitset<128> bs = n           now | (now >> i) | (now << i) | (now >> (m - i)) | (now << (m - i)); n       in[use + 1] = i; n       dfs(use + 1, i, bs); n     } n   } n } n bitset<128> bs; n int main() { n   bs.reset(); n   bs.set(0); n   cin >> n >> m >> t; n   for (int i = 0; i < t; i++) cin >> a[i], cnt[min(m - a[i] % m, a[i] % m)]++; n   dfs(0, 0, bs); n   cout << ans << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   ; n   long long t; n   cin >> t; n   while (t--) { n     int n; n     string a, b; n     cin >> n >> a >> b; n     vector<int> res; n     for (int i = 0; i < n; i++) { n       if (a[i] != b[i]) { n         if (i != 0) res.push_back(i + 1); n         res.push_back(1); n         if (i != 0) res.push_back(i + 1); n       } n     } n     cout << res.size() <<    ; n     for (int x : res) { n       cout << x <<    ; n     } n     cout << endl; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int MAX = 2 * 1e5 + 5; n const int INF = 1e9; n const int MOD = 1e9 + 7; n int N, K, A[MAX], table[20][MAX]; n int main() { n   cin >> N >> K; n   for (int i = 0; i < (N); ++i) cin >> A[i]; n   for (int i = 0; i < (N); ++i) table[0][i] = A[i]; n   vector<int> b(N, 0); n   for (int i = 0; i < (N); ++i) { n     for (int j = 0; j < (19); ++j) { n       table[j + 1][i] = table[j][i] / 2; n       b[i]++; n       if (table[j + 1][i] == 0) break; n     } n   } n   map<int, int> m, cost; n   int ans = INF; n   for (int i = 0; i < (20); ++i) { n     for (int j = 0; j < (N); ++j) { n       if (b[j] < i) continue; n       int num = table[i][j]; n       m[num]++; n       cost[num] += i; n       if (m[num] >= K) ans = min(ans, cost[num]); n     } n   } n   cout << ans << endl; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int r, g, b, ck, maximum = 0, temp; n   scanf( %d %d %d , &r, &g, &b); n   if (r % 2 == 1) r++; n   r = r / 2; n   if (g % 2 == 1) g++; n   g = g / 2; n   if (b % 2 == 1) b++; n   b = b / 2; n   temp = 27 + r * 3; n   if (temp > maximum) maximum = temp; n   temp = 28 + g * 3; n   if (temp > maximum) maximum = temp; n   temp = 29 + b * 3; n   if (temp > maximum) maximum = temp; n   printf( %d n , maximum); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s; n   cin >> s; n   for (int i = 0; i < s.size(); i++) { n     for (char a =  a ; a <=  z ; a++) { n       string t =   ; n       for (int j = 0; j < i; j++) { n         t += s[j]; n       } n       t += a; n       for (int j = i; j < s.size(); j++) { n         t += s[j]; n       } n       string r = t; n       reverse(t.begin(), t.end()); n       if (r == t) { n         cout << r; n         return 0; n       } n     } n   } n   for (char a =  a ; a <=  z ; a++) { n     string t = s; n     t += a; n     string r = t; n     reverse(t.begin(), t.end()); n     if (r == t) { n       cout << r; n       return 0; n     } n   } n   cout <<  NA ; n } n


#include <bits/stdc++.h> n using namespace std; n inline void output(long long int x) { n   if (x % 2) n     cout << x / 2 <<   n ; n   else n     cout << x / 2 - 1 <<   n ; n   return; n } n long long int N, K; n int main() { n   cin >> N >> K; n   if (N >= K) n     output(K); n   else { n     if ((N << 1) - 1 < K) n       cout << 0 <<   n ; n     else n       output(N - (K - N) + 2); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 5005; n const int mod = 1000000007; n int n, a, b, k; n int dp[N][N]; n int main() { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   cin >> n >> a >> b >> k; n   for (long long i = 1; i <= n; ++i) { n     dp[0][i] = i; n   } n   for (int trip = 1; trip <= k; trip++) { n     for (int floor = 1; floor <= n; floor++) { n       int d = abs(b - floor); n       dp[trip][floor] = dp[trip - 1][min(n, floor + d - 1)] - n                         dp[trip - 1][max(0, floor - d)] - dp[trip - 1][floor] + n                         dp[trip - 1][floor - 1]; n       while (dp[trip][floor] < 0) dp[trip][floor] += mod; n       dp[trip][floor] %= mod; n       dp[trip][floor] = (dp[trip][floor] + dp[trip][floor - 1]) % mod; n     } n   } n   cout << (dp[k][a] - dp[k][a - 1] + mod) % mod; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int mdc(int a, int b) { return !b ? a : mdc(b, a % b); } n int main() { n   int n, m, x, y, a, b, p, d, x1, y1, x2, y2; n   cin >> n >> m >> x >> y >> a >> b; n   d = mdc(a, b); n   a /= d; n   b /= d; n   p = min(n / a, m / b); n   a *= p; n   b *= p; n   if (x + a / 2 > n) { n     x2 = n; n     x1 = n - a; n   } else if (x - a / 2 < 0) { n     x1 = 0; n     x2 = a; n   } else { n     x2 = x + a / 2; n     x1 = x2 - a; n   } n   if (y + b / 2 > m) { n     y2 = m; n     y1 = m - b; n   } else if (y - b / 2 < 0) { n     y1 = 0; n     y2 = b; n   } else { n     y2 = y + b / 2; n     y1 = y2 - b; n   } n   cout << x1 <<     << y1 <<     << x2 <<     << y2 << endl; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const long long MOD = 1e9 + 7; n const long long N = 3e5 + 10; n long long pow(long long a, long long b, long long m) { n   long long ans = 1; n   while (b) { n     if (b & 1) ans = (ans * a) % m; n     b /= 2; n     a = (a * a) % m; n   } n   return ans; n } n long long y[5], m[5]; n long long h, a, d; n int32_t main() { n   ios_base::sync_with_stdio(false); n   cin.tie(0); n   for (long long i = 1; i <= 3; i++) { n     cin >> y[i]; n   } n   for (long long i = 1; i <= 3; i++) { n     cin >> m[i]; n   } n   cin >> h >> a >> d; n   long long mn = 1e18; n   for (long long i = y[1]; i <= 1000; i++) { n     for (long long j = y[2]; j <= 201; j++) { n       for (long long k = y[3]; k <= 201; k++) { n         long long z = (i - y[1]) * h + (j - y[2]) * a + (k - y[3]) * d; n         if (j <= m[3]) { n           continue; n         } else if (k >= m[2]) { n           mn = min(mn, z); n         } else { n           long long sec_to_take_yong = n               (m[1] / (j - m[3])) + (m[1] % (j - m[3]) != 0); n           long long sec_to_take_m = (i / (m[2] - k)) + (i % (m[2] - k) != 0); n           if (sec_to_take_yong < sec_to_take_m) mn = min(mn, z); n         } n       } n     } n   } n   cout << mn << endl; n } n


#include <bits/stdc++.h> n using namespace std; n float distance(long long x, long long y, long long a, long long b) { n   return sqrt((x - y) * (x - y) + (a - b) * (a - b)); n } n int32_t main() { n   float n, x1, y1, x2, y2; n   cin >> n >> x1 >> y1 >> x2 >> y2; n   if ((x1 == x2 && (x1 == n || x1 == 0)) || n       (y1 == y2 && (y1 == 0 || y2 == n))) { n     cout << abs(x1 - x2) + abs(y1 - y2); n     return 0; n   } n   long long path1 = 0, path2 = 0; n   if (abs(x1 - x2) == n) { n     path1 = 2 * n - (y1 + y2); n     path2 = y1 + y2; n     cout << (path1 > path2 ? path2 : path1) + n; n     return 0; n   } n   if (abs(y1 - y2) == n) { n     path1 = 2 * n - (x1 + x2); n     path2 = x1 + x2; n     cout << (path1 > path2 ? path2 : path1) + n; n     return 0; n   } n   cout << abs(x1 - x2) + abs(y2 - y1); n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   long long a, b, l, r, c, ans; n   cin >> a >> b >> l >> r; n   c = l % (a + b); n   if (c > a) { n     ans = 1; n     l += (a + b - c + 1); n     if (l <= r) ans += min(a, r - l + 1); n     if (a > b) { n       l += (2 * b); n       if (l <= r) ans += min(a - b, r - l + 1); n     } n   } else { n     ans = min(a - c + 1, r - l + 1); n     l += (a - c + 1); n     if (l <= r) { n       ans++; n       l += b; n       if ((a <= b && a >= r - l + 1) || a > b) ans--; n     } n     if (l <= r) ans += min(c - 1, r - l + 1); n     l += (c - 1); n     if (a > b) { n       if ((a - c + 1) > (a - b)) { n         l += (b - c + 1); n         if (l <= r) ans += min(a - b, r - l + 1); n       } else { n         if (l <= r) ans += min(a - c + 1, r - l + 1); n         l += (a - c + 1); n         l += (b + b); n         if (l <= r) ans += min(c - b - 1, r - l + 1); n       } n     } n   } n   printf( %lld n , ans); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int mod = 998244353; n const int maxn = 1e3 + 10; n int n, m, mp[maxn][maxn], cnt, dx[] = {0, 1, 0, -1}, dy[] = {-1, 0, 1, 0}; n bool vis[maxn][maxn]; n vector<int> ans; n void dfs(int x, int y) { n   if (vis[x][y] || x <= 0 || x > n || y <= 0 || y > m) return; n   vis[x][y] = 1, ++cnt; n   for (int i = 0; i < 4; ++i) n     if (!(mp[x][y] & (1 << i))) dfs(x + dx[i], y + dy[i]); n } n void solve() { n   scanf( %d%d , &n, &m); n   for (int i = 1; i <= n; ++i) n     for (int j = 1; j <= m; ++j) scanf( %d , &mp[i][j]); n   for (int i = 1; i <= n; ++i) n     for (int j = 1; j <= m; ++j) n       if (!vis[i][j]) cnt = 0, dfs(i, j), ans.push_back(cnt); n   sort(ans.begin(), ans.end()); n   for (int i = ans.size() - 1; ~i; --i) printf( %d  , ans[i]); n } n int main() { n   solve(); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int n, t; n char v[500010]; n vector<pair<int, int> > inter; n int memo[500010]; n int calcula(int ind) { n   int res = 0; n   int x = ind; n   int ini = 0; n   int fim = 0; n   bool erro = false; n   int lh = -1; n   inter.clear(); n   for (int i = 0; i < (n); i++) { n     if (v[i] ==  H ) { n       x--; n       lh = i; n     } else if (v[i] ==  S ) { n       x++; n     } n     if (x == -1 && !erro) { n       ini = i; n       erro = true; n     } n     if (x == 0 && erro) { n       if (i < n && v[i + 1] ==  H ) continue; n       inter.push_back(make_pair(ini, i)); n       erro = false; n     } n   } n   if (x < 0) return false; n   if ((int)inter.size() == 0) { n     if (lh < t) return true; n     return false; n   } n   int i = 0; n   res = inter[0].first; n   fim = max(lh, inter[(int)inter.size() - 1].second); n   memo[inter.size()] = 0; n   int next; n   for (int i = (int)inter.size() - 1; i >= 0; i--) { n     if (i + 1 < (int)inter.size()) { n       next = inter[i + 1].first - 1; n     } else { n       next = fim; n     } n     memo[i] = min((inter[i].second - inter[i].first + 1) * 3 - 2 + memo[i + 1] + n                       (next - inter[i].second), n                   (fim - inter[i].first + 1) * 2 - 1); n   } n   res += memo[0]; n   if (res <= t) return true; n   return false; n } n int main() { n   scanf( %d %d , &n, &t); n   for (int i = 0; i < (n); i++) { n     scanf(  %c , &v[i]); n   } n   int inicio = 0; n   int fim = n; n   int res = -1; n   while (1) { n     if (inicio > fim) break; n     int meio = (inicio + fim) / 2; n     if (calcula(meio)) { n       res = meio; n       fim = meio - 1; n     } else { n       inicio = meio + 1; n     } n   } n   printf( %d n , res); n   return 0; n } n


#include <bits/stdc++.h> n int main() { n   int t = 1, i, n; n   scanf( %d , &n); n   for (i = 1; i <= n - 1; i++) { n     t = (t + i - 1) % n + 1; n     printf( %d  , t); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct Point { n   int x, y; n   Point(int x = 0, int y = 0) : x(x), y(y) {} n   Point operator-(const Point z) const { return Point(x - z.x, y - z.y); } n   friend long long Cross(Point a, Point b) { n     return 1ll * a.x * b.y - 1ll * a.y * b.x; n   } n } a[2010], b[2010]; n bool f[2010]; n char ch[2010]; n int main(int argc, char const *argv[]) { n   int n; n   cin >> n; n   for (int i = 0; i < n; i++) cin >> a[i].x >> a[i].y; n   cin >> ch; n   int p = 0; n   for (int i = 1; i < n; i++) n     if (a[i].y < a[p].y || a[i].y == a[p].y && a[i].x < a[p].x) p = i; n   f[p] = 1; n   cout << p + 1 <<    ; n   for (int i = 0; !i || ch[i - 1]; i++) { n     int x = -1; n     for (int j = 0; j < n; j++) n       if (!f[j]) { n         if (x == -1) n           x = j; n         else if (ch[i] ==  L ) n           if (Cross(a[j] - a[p], a[x] - a[p]) > 0) n             x = j; n           else n             ; n         else if (Cross(a[j] - a[p], a[x] - a[p]) < 0) n           x = j; n       } n     cout << x + 1 <<    ; n     f[x] = 1; n     p = x; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n typedef pair<int, int> pii; n typedef long long ll; n typedef unsigned long long ull; n template <typename T> n bool umax(T& a, const T& b) { n   return b <= a ? false : (a = b, true); n } n template <typename T> n bool umin(T& a, const T& b) { n   return b >= a ? false : (a = b, true); n } n template <typename T> n void V2A(T a[], const vector<T>& b) { n   for (int i = 0; i < b.size(); i++) a[i] = b[i]; n } n template <typename T> n void A2V(vector<T>& a, const T b[]) { n   for (int i = 0; i < a.size(); i++) a[i] = b[i]; n } n const double PI = acos(-1.0); n const int INF = 1e9 + 7; n const int maxn = 2e3 + 7; n bool plot[maxn][maxn]; n int r[maxn][maxn]; n int n, m, k; n int check(int row, int col) { n   if (col >= 0 && col < m) return true; n   return false; n } n int main() { n   cin >> n >> m >> k; n   for (int i = 0; i < k; i++) { n     int x, y; n     scanf( %d%d , &x, &y); n     x--; n     y--; n     if (!plot[x][y]) { n       printf( %d %d n , x + 1, y + 1); n       plot[x][y] = true; n       continue; n     } n     for (int d = 1; d <= 3; d++) { n       int Max = min(n, x + d + 1); n       for (int row = max(0, x - d); row < Max; row++) { n         int t = d - abs(x - row), col1 = y - t, col2 = y + t; n         if (check(row, col1)) umax(r[x][y], r[row][col1] - d); n         if (check(row, col2)) umax(r[x][y], r[row][col2] - d); n       } n     } n     for (int d = r[x][y] + 1;; d++) { n       int Max = min(n, x + d + 1); n       bool ok = false; n       for (int row = max(0, x - d); row < Max; row++) { n         int t = d - abs(x - row), col1 = y - t, col2 = y + t; n         if (check(row, col1) && !plot[row][col1]) { n           ok = true; n           printf( %d %d n , row + 1, col1 + 1); n           plot[row][col1] = true; n           break; n         } n         if (check(row, col2) && !plot[row][col2]) { n           ok = true; n           printf( %d %d n , row + 1, col2 + 1); n           plot[row][col2] = true; n           break; n         } n       } n       if (ok) { n         r[x][y] = d - 1; n         break; n       } n     } n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n struct node { n   int p, q; n } a[1009]; n bool cmp(node a, node b) { n   if (a.p != b.p) return a.p < b.p; n   if (a.p == b.p) return a.q > b.q; n } n int main() { n   int m, n, i; n   scanf( %d%d , &m, &n); n   for (i = 1; i <= n; i++) { n     scanf( %d%d , &a[i].p, &a[i].q); n   } n   sort(a + 1, a + 1 + n, cmp); n   int sum = m; n   for (i = 1; i <= n; i++) { n     if (sum > a[i].p) n       sum += a[i].q; n     else n       break; n   } n   if (i == n + 1) n     printf( YES n ); n   else n     printf( NO n ); n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   string s; n   cin >> s; n   int len = s.size(); n   cout << s[0]; n   int flag = 0; n   for (int i = 1; i < len; i++) { n     if (s[i] ==  d  && s[i + 1] ==  o  && s[i + 2] ==  t  && n         (i + 2 != len - 1)) { n       cout <<  . ; n       i += 2; n     } else if (s[i] ==  a  && s[i + 1] ==  t  && flag == 0) { n       cout <<  @ ; n       i++; n       flag = 1; n     } else n       cout << s[i]; n   } n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   ios_base::sync_with_stdio(false); n   cin.tie(nullptr); n   cout.tie(nullptr); n   cerr.tie(nullptr); n   long long n, k, a, z = 0; n   cin >> n >> k; n   vector<int> x(n), c(n); n   for (int i = 0; i < n; i++) cin >> x[i]; n   cin >> a; n   for (int i = 0; i < n; i++) cin >> c[i]; n   multiset<int> ms; n   for (int i = 0; i < n; i++) { n     ms.insert(c[i]); n     while (k < x[i]) { n       if (ms.size() == 0) { n         cout <<  -1 n ; n         return 0; n       } else { n         k += a; n         z += *ms.begin(); n         ms.erase(ms.begin()); n       } n     } n   } n   cout << z <<   n ; n } n


#include <bits/stdc++.h> n using namespace std; n const int INF = 1e9 * 2; n int main() { n   ios::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   int t; n   cin >> t; n   while (t--) { n     int n; n     cin >> n; n     string s; n     cin >> s; n     int l = 0, r = n - 1; n     while (l <= n && s[l] ==  0 ) l++; n     while (r >= 0 && s[r] ==  0 ) r--; n     int ans; n     if (l > r) n       ans = n; n     else n       ans = max(r + 1, n - l) * 2; n     cout << ans <<   n ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n #pragma comment(linker,  /stack:200000000 ) n #pragma GCC optimize( Ofast ) n #pragma GCC target(   n      sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native ) n #pragma GCC optimize( -ffloat-store ) n const long long INF = 0xFFFFFFFFFFFFFFFL; n const long long N = 1e9 + 7; n vector<long long> pri; n void yo(int n) { n   bool prime[n + 1]; n   memset(prime, true, sizeof(prime)); n   for (int p = 2; p * p <= n; p++) { n     if (prime[p] == true) { n       for (int i = p * p; i <= n; i += p) prime[i] = false; n     } n   } n   for (int p = 2; p <= n; p++) n     if (prime[p]) pri.push_back(p); n } n void solve() { n   long long n; n   cin >> n; n   for (long long i = 1; i < 1001; i++) { n     if (!binary_search((pri).begin(), (pri).end(), n * i + 1)) { n       cout << i; n       return; n     } n   } n } n int32_t main(int32_t argc, char **argv) { n   ios_base::sync_with_stdio(0); n   cin.tie(0); n   cout.tie(0); n   yo(1000003); n   long long t; n   t = 1; n   while (t--) solve(); n   cerr <<   n  n        <<  Time :   << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC n        <<  ms n ; n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n, k; n   scanf( %d%d , &n, &k); n   int mat[n + 1][n + 1]; n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= n; j++) mat[i][j] = 0; n   } n   int br = 0; n   for (int i = 1; i <= n; i += 2) { n     for (int j = 1, x = i; j <= n && x <= n; j++, x++) { n       mat[x][j] = 1; n       br++; n     } n   } n   for (int i = 3; i <= n; i += 2) { n     for (int h = 1, j = i; h <= n && j <= n; h++, j++) { n       mat[h][j] = 1; n       br++; n     } n   } n   if (br < k) { n     printf( NO ); n     return 0; n   } n   printf( YES n ); n   for (int i = 1; i <= n; i++) { n     for (int j = 1; j <= n; j++) { n       if (k > 0) { n         if (mat[i][j]) { n           printf( L ); n           k--; n         } else n           printf( S ); n       } else n         printf( S ); n     } n     printf(  n ); n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n int main() { n   int n; n   cin >> n; n   int a = 1; n   int b = 2; n   bool ok = true; n   int k; n   for (int i = 0; i < n; i++) { n     cin >> k; n     if (k != a && k != b) { n       ok = false; n     } else { n       if (b == 3 && a == 1) { n         a = min(2, k); n         b = max(2, k); n       } else if (b == 2 && a == 1) { n         a = min(3, k); n         b = max(3, k); n       } else if (b == 3 && a == 2) { n         a = min(1, k); n         b = max(1, k); n       } n     } n   } n   if (ok) { n     cout <<  YES ; n   } else { n     cout <<  NO ; n   } n   return 0; n } n


#include <bits/stdc++.h> n using namespace std; n const int N = 5, M = 20; n int n, m, a[N], b[M], ans[M]; n set<vector<int> > use[M + 1]; n void find(int y, vector<int>& current) { n   if (y == m) { n     for (int i = 0; i < n; i++) n       if (a[i] != current[i]) return; n     for (int i = 0; i < n; i++) { n       for (int j = 0; j < m; j++) cout <<  .* [(bool)(ans[j] & (1 << i))]; n       cout << endl; n     } n     exit(0); n   } n   if (use[y].find(current) != use[y].end()) return; n   for (int i = 0; i < (1 << n); i++) { n     if ((((((((i << 1) | i) ^ i) >> 1) >> 0)) & 1) + n             (((((((i << 1) | i) ^ i) >> 1) >> 1)) & 1) + n             (((((((i << 1) | i) ^ i) >> 1) >> 2)) & 1) + n             (((((((i << 1) | i) ^ i) >> 1) >> 3)) & 1) + n             (((((((i << 1) | i) ^ i) >> 1) >> 4)) & 1) != n         b[y]) n       continue; n     ans[y] = i; n     vector<int> newCur = current; n     bool flag = true; n     for (int j = 0; j < n; j++) { n       if (ans[y] & (1 << j) && (!y || !(ans[y - 1] & (1 << j)))) newCur[j]++; n       if (newCur[j] > a[j] || newCur[j] < a[j] - ((m - y) / 2)) { n         flag = false; n         break; n       } n     } n     if (flag) find(y + 1, newCur); n   } n   use[y].insert(current); n } n int main() { n   cin >> n >> m; n   for (int i = 0; i < n; i++) cin >> a[i]; n   for (int i = 0; i < m; i++) cin >> b[i]; n   vector<int> c(n + 1, 0); n   find(0, c); n } n


#include <bits/stdc++.h> n using namespace std; n const int maxn = 1100; n int n; n char s[maxn + 10]; n int data[maxn + 10]; n int dp[maxn + 10][2]; n int main() { n   cin >> n; n   getchar(); n   gets(s); n   int i; n   for (i = 0; s[i]; i++) data[i] = s[i] -  0 ; n   if (i == 1) n     printf( 0 n ); n   else { n     int ans1 = 0, ans2 = 0; n     for (int j = 0; j < i; j++) { n       if ((j & 1) != data[j]) ans1++; n     } n     for (int j = 0; j < i; j++) { n       if ((j & 1) == data[j]) ans2++; n     } n     printf( %d n , min(ans1, ans2)); n   } n   return 0; n } n